19 #include <TSQLServer.h>
20 #include <TSQLResult.h>
25 #include <TRotation.h>
135 double dpos[3] = {x0_track -
xc, y0_track -
yc, -
zc};
143 return -(vcp[0]*dpos[0] + vcp[1]*dpos[1] + vcp[2]*dpos[2])/det +
wc;
154 TVectorD detCenter(3);
166 ep = detCenter + ((elementID - (
nElements+1.)/2.)*hspacing + hoffset)*
xVec + 0.5*sign*cellLength*
vVec;
174 ep = detCenter + ((elementID - (
nElements+1.)/2.)*vspacing + voffset)*
yVec + 0.5*sign*cellLength*
vVec;
182 os << std::setw(6) << std::setiosflags(std::ios::right) << plane.
detectorID
183 << std::setw(6) << std::setiosflags(std::ios::right) << plane.
detectorName
184 << std::setw(6) << std::setiosflags(std::ios::right) << plane.
planeType
185 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
spacing
186 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
cellWidth
187 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
xoffset
188 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
overlap
189 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
x2 - plane.
x1
190 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
y2 - plane.
y1
191 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
z2 - plane.
z1
192 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
nElements
193 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
angleFromVert
194 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
xc
195 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
yc
196 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
zc
197 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
deltaW <<
"\n"
198 <<
", nVec: {" << plane.
nVec[0] <<
", " << plane.
nVec[1] <<
", " << plane.
nVec[2] <<
"} "
199 <<
", uVec: {" << plane.
uVec[0] <<
", " << plane.
uVec[1] <<
", " << plane.
uVec[2] <<
"} "
200 <<
", vVec: {" << plane.
vVec[0] <<
", " << plane.
vVec[1] <<
", " << plane.
vVec[2] <<
"} ";
203 for(
int i=0; i<9; ++i) os << std::setw(10) << std::setiosflags(std::ios::right) << plane.
deltaW_module[i];
210 bool GeomSvc::use_dbsvc =
true;
214 if(p_geometrySvc ==
NULL)
217 p_geometrySvc->
init();
220 return p_geometrySvc;
232 delete p_geometrySvc;
236 std::cout <<
"Error: no instance of geometry service found! " << std::endl;
246 typedef std::map<std::string, int>::value_type nameToID;
249 map_detectorID.insert(nameToID(
"D0U" , ++idx));
250 map_detectorID.insert(nameToID(
"D0Up" , ++idx));
251 map_detectorID.insert(nameToID(
"D0X" , ++idx));
252 map_detectorID.insert(nameToID(
"D0Xp" , ++idx));
253 map_detectorID.insert(nameToID(
"D0V" , ++idx));
254 map_detectorID.insert(nameToID(
"D0Vp" , ++idx));
255 map_detectorID.insert(nameToID(
"D1V" , ++idx));
256 map_detectorID.insert(nameToID(
"D1Vp" , ++idx));
257 map_detectorID.insert(nameToID(
"D1X" , ++idx));
258 map_detectorID.insert(nameToID(
"D1Xp" , ++idx));
259 map_detectorID.insert(nameToID(
"D1U" , ++idx));
260 map_detectorID.insert(nameToID(
"D1Up" , ++idx));
261 map_detectorID.insert(nameToID(
"D2V" , ++idx));
262 map_detectorID.insert(nameToID(
"D2Vp" , ++idx));
263 map_detectorID.insert(nameToID(
"D2Xp" , ++idx));
264 map_detectorID.insert(nameToID(
"D2X" , ++idx));
265 map_detectorID.insert(nameToID(
"D2U" , ++idx));
266 map_detectorID.insert(nameToID(
"D2Up" , ++idx));
267 map_detectorID.insert(nameToID(
"D3pVp", ++idx));
268 map_detectorID.insert(nameToID(
"D3pV" , ++idx));
269 map_detectorID.insert(nameToID(
"D3pXp", ++idx));
270 map_detectorID.insert(nameToID(
"D3pX" , ++idx));
271 map_detectorID.insert(nameToID(
"D3pUp", ++idx));
272 map_detectorID.insert(nameToID(
"D3pU" , ++idx));
273 map_detectorID.insert(nameToID(
"D3mVp", ++idx));
274 map_detectorID.insert(nameToID(
"D3mV" , ++idx));
275 map_detectorID.insert(nameToID(
"D3mXp", ++idx));
276 map_detectorID.insert(nameToID(
"D3mX" , ++idx));
277 map_detectorID.insert(nameToID(
"D3mUp", ++idx));
278 map_detectorID.insert(nameToID(
"D3mU" , ++idx));
281 map_detectorID.insert(nameToID(
"H1B" , ++idx));
282 map_detectorID.insert(nameToID(
"H1T" , ++idx));
283 map_detectorID.insert(nameToID(
"H1L" , ++idx));
284 map_detectorID.insert(nameToID(
"H1R" , ++idx));
285 map_detectorID.insert(nameToID(
"H2L" , ++idx));
286 map_detectorID.insert(nameToID(
"H2R" , ++idx));
287 map_detectorID.insert(nameToID(
"H2B" , ++idx));
288 map_detectorID.insert(nameToID(
"H2T" , ++idx));
289 map_detectorID.insert(nameToID(
"H3B" , ++idx));
290 map_detectorID.insert(nameToID(
"H3T" , ++idx));
291 map_detectorID.insert(nameToID(
"H4Y1L", ++idx));
292 map_detectorID.insert(nameToID(
"H4Y1R", ++idx));
293 map_detectorID.insert(nameToID(
"H4Y2L", ++idx));
294 map_detectorID.insert(nameToID(
"H4Y2R", ++idx));
295 map_detectorID.insert(nameToID(
"H4B" , ++idx));
296 map_detectorID.insert(nameToID(
"H4T" , ++idx));
299 map_detectorID.insert(nameToID(
"P1Y1", ++idx));
300 map_detectorID.insert(nameToID(
"P1Y2", ++idx));
301 map_detectorID.insert(nameToID(
"P1X1", ++idx));
302 map_detectorID.insert(nameToID(
"P1X2", ++idx));
303 map_detectorID.insert(nameToID(
"P2X1", ++idx));
304 map_detectorID.insert(nameToID(
"P2X2", ++idx));
305 map_detectorID.insert(nameToID(
"P2Y1", ++idx));
306 map_detectorID.insert(nameToID(
"P2Y2", ++idx));
309 map_detectorID.insert(nameToID(
"DP1TL", ++idx));
310 map_detectorID.insert(nameToID(
"DP1TR", ++idx));
311 map_detectorID.insert(nameToID(
"DP1BL", ++idx));
312 map_detectorID.insert(nameToID(
"DP1BR", ++idx));
313 map_detectorID.insert(nameToID(
"DP2TL", ++idx));
314 map_detectorID.insert(nameToID(
"DP2TR", ++idx));
315 map_detectorID.insert(nameToID(
"DP2BL", ++idx));
316 map_detectorID.insert(nameToID(
"DP2BR", ++idx));
319 map_detectorID.insert(nameToID(
"BeforeInhNIM" , ++idx));
320 map_detectorID.insert(nameToID(
"BeforeInhMatrix", ++idx));
321 map_detectorID.insert(nameToID(
"AfterInhNIM" , ++idx));
322 map_detectorID.insert(nameToID(
"AfterInhMatrix" , ++idx));
323 map_detectorID.insert(nameToID(
"BOS" , ++idx));
324 map_detectorID.insert(nameToID(
"EOS" , ++idx));
325 map_detectorID.insert(nameToID(
"L1" , ++idx));
326 map_detectorID.insert(nameToID(
"RF" , ++idx));
327 map_detectorID.insert(nameToID(
"STOP" , ++idx));
328 map_detectorID.insert(nameToID(
"L1PXtp" , ++idx));
329 map_detectorID.insert(nameToID(
"L1PXtn" , ++idx));
330 map_detectorID.insert(nameToID(
"L1PXbp" , ++idx));
331 map_detectorID.insert(nameToID(
"L1PXbn" , ++idx));
332 map_detectorID.insert(nameToID(
"L1NIMxt" , ++idx));
333 map_detectorID.insert(nameToID(
"L1NIMxb" , ++idx));
334 map_detectorID.insert(nameToID(
"L1NIMyt" , ++idx));
335 map_detectorID.insert(nameToID(
"L1NIMyb" , ++idx));
338 map_detectorID.insert(nameToID(
"H4Y1Ll", ++idx));
339 map_detectorID.insert(nameToID(
"H4Y1Lr", ++idx));
340 map_detectorID.insert(nameToID(
"H4Y1Rl", ++idx));
341 map_detectorID.insert(nameToID(
"H4Y1Rr", ++idx));
342 map_detectorID.insert(nameToID(
"H4Y2Ll", ++idx));
343 map_detectorID.insert(nameToID(
"H4Y2Lr", ++idx));
344 map_detectorID.insert(nameToID(
"H4Y2Rl", ++idx));
345 map_detectorID.insert(nameToID(
"H4Y2Rr", ++idx));
346 map_detectorID.insert(nameToID(
"H4Tu" , ++idx));
347 map_detectorID.insert(nameToID(
"H4Td" , ++idx));
348 map_detectorID.insert(nameToID(
"H4Bu" , ++idx));
349 map_detectorID.insert(nameToID(
"H4Bd" , ++idx));
354 map_detid_triggerlv[i] = -1;
357 map_detid_triggerlv[i] = 0;
360 map_detid_triggerlv[i] = 1;
363 map_detid_triggerlv[i] = 2;
366 map_detid_triggerlv[i] = 3;
369 typedef std::map<int, std::string>::value_type idToName;
370 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
372 map_detectorName.insert(idToName(iter->second, iter->first));
380 calibration_loaded =
false;
381 if(rc->get_BoolFlag(
"OnlineAlignment"))
385 else if(!rc->get_BoolFlag(
"IdealGeom"))
387 loadAlignment(
"NULL", rc->get_CharFlag(
"AlignmentHodo"), rc->get_CharFlag(
"AlignmentProp"));
395 xmin_kmag = -57.*2.54;
396 xmax_kmag = 57.*2.54;
397 ymin_kmag = -40.*2.54;
398 ymax_kmag = 40.*2.54;
400 zmin_kmag = 1064.26 - 120.*2.54;
401 zmax_kmag = 1064.26 + 120.*2.54;
406 cout << planes[i] << endl;
412 std::cerr <<
"!! ERROR !!\n"
413 <<
"!! GeomSvc::initPlaneDirect() is called but no longer available.\n"
414 <<
"!! Probably you have 'GeomSvc::UseDbSvc(false)' in your macro.\n"
415 <<
"!! Please delete it. Abort for now." << std::endl;
426 cout <<
"GeomSvc: Load the plane geometry info for map_id = " << map_id <<
"." << endl;
430 cout <<
"GeomSvc: Load the plane geometry info for run_id = " << run_id <<
"." << endl;
443 int detectorID = map_detectorID[detectorName];
445 planes[detectorID].detectorID = detectorID;
446 planes[detectorID].detectorName = detectorName;
448 planes[detectorID].cellWidth = pl->
cell_width;
451 planes[detectorID].xoffset = pl->
xoffset;
452 planes[detectorID].thetaX = pl->
theta_x;
453 planes[detectorID].thetaY = pl->
theta_y;
454 planes[detectorID].thetaZ = pl->
theta_z;
457 planes[detectorID].nElements += pl->
n_ele;
458 double x0_i = pl->
x0;
459 double y0_i = pl->
y0;
460 double z0_i = pl->
z0;
461 double width_i = pl->
width;
462 double height_i = pl->
height;
464 double x1_i = x0_i - 0.5*width_i;
465 double x2_i = x0_i + 0.5*width_i;
466 double y1_i = y0_i - 0.5*height_i;
467 double y2_i = y0_i + 0.5*height_i;
469 planes[detectorID].x0 += x0_i;
470 planes[detectorID].y0 += y0_i;
471 planes[detectorID].z0 += z0_i;
472 if(planes[detectorID].x1 > x1_i) planes[detectorID].x1 = x1_i;
473 if(planes[detectorID].x2 < x2_i) planes[detectorID].x2 = x2_i;
474 if(planes[detectorID].y1 > y1_i) planes[detectorID].y1 = y1_i;
475 if(planes[detectorID].y2 < y2_i) planes[detectorID].y2 = y2_i;
478 planes[detectorID].resolution = planes[detectorID].cellWidth/sqrt(12.);
479 planes[detectorID].update();
482 if(detectorName.find(
"X") != string::npos || detectorName.find(
"T") != string::npos || detectorName.find(
"B") != string::npos)
484 planes[detectorID].planeType = 1;
486 else if((detectorName.find(
"U") != string::npos || detectorName.find(
"V") != string::npos) && planes[detectorID].angleFromVert > 0)
488 planes[detectorID].planeType = 2;
490 else if((detectorName.find(
"U") != string::npos || detectorName.find(
"V") != string::npos) && planes[detectorID].angleFromVert < 0)
492 planes[detectorID].planeType = 3;
494 else if(detectorName.find(
"Y") != string::npos || detectorName.find(
"L") != string::npos || detectorName.find(
"R") != string::npos)
496 planes[detectorID].planeType = 4;
503 planes[i].x0 = planes[i].x0/9.;
504 planes[i].y0 = planes[i].y0/9.;
505 planes[i].z0 = planes[i].z0/9.;
515 planes[i].z1 = planes[i].z0 - planes[i].cellWidth/2.;
516 planes[i].z2 = planes[i].z0 + planes[i].cellWidth/2.;
520 planes[i].z1 = planes[i].z0 - 0.635/2.;
521 planes[i].z2 = planes[i].z0 + 0.635/2.;
525 planes[i].z1 = planes[i].z0 - planes[i].cellWidth*TMath::Pi()/8.;
526 planes[i].z2 = planes[i].z0 + planes[i].cellWidth*TMath::Pi()/8.;
530 planes[i].z1 = planes[i].z0 - planes[i].cellWidth/2.;
531 planes[i].z2 = planes[i].z0 + planes[i].cellWidth/2.;
540 typedef std::unordered_map<int, double>::value_type posType;
541 typedef std::unordered_map<int, TVectorD>::value_type epType;
544 map_wirePosition[i].clear();
545 map_endPoint1 [i].clear();
546 map_endPoint2 [i].clear();
548 for(
int j = 1; j <= planes[i].
nElements; ++j)
551 map_wirePosition[i].insert(posType(j, pos));
553 map_endPoint1[i].insert(epType(j, planes[i].getEndPoint(j, -1)));
554 map_endPoint2[i].insert(epType(j, planes[i].getEndPoint(j, 1)));
558 std::sort(planes[i].elementPos.begin(), planes[i].
elementPos.end());
564 map_wirePosition[i].clear();
565 map_endPoint1 [i].clear();
566 map_endPoint2 [i].clear();
568 for(
int j = 1; j <= planes[i].
nElements; ++j)
577 int moduleID = 8 - int((j - 1)/8);
582 int elementID = ((i-55) & 2) > 0 ? planes[i].
nElements + 1 - j : j;
585 map_wirePosition[i].insert(posType(j, pos));
586 map_endPoint1[i].insert(epType(j, planes[i].getEndPoint(j, -1)));
587 map_endPoint2[i].insert(epType(j, planes[i].getEndPoint(j, 1)));
590 std::sort(planes[i].elementPos.begin(), planes[i].
elementPos.end());
596 TPRegexp pattern_re(pattern.c_str());
598 std::vector<int> detectorIDs;
601 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
603 TString detectorName((*iter).first.c_str());
604 if(detectorName(pattern_re) !=
"")
606 detectorIDs.push_back((*iter).second);
609 std::sort(detectorIDs.begin(), detectorIDs.end());
616 TPRegexp pattern_re(pattern.c_str());
617 TString detectorName(map_detectorName[detectorID]);
619 return detectorName(pattern_re) !=
"";
624 if(x < planes[detectorID].x1 || x > planes[detectorID].x2)
return false;
625 if(y < planes[detectorID].y1 || y > planes[detectorID].y2)
return false;
632 double x_min, x_max, y_min, y_max;
633 get2DBoxSize(detectorID, elementID, x_min, x_max, y_min, y_max);
635 x_min -= (tolr*(x_max - x_min));
636 x_max += (tolr*(x_max - x_min));
637 y_min -= (tolr*(y_max - y_min));
638 y_max += (tolr*(y_max - y_min));
640 return x > x_min && x < x_max && y > y_min && y < y_max;
645 if(x < xmin_kmag || x > xmax_kmag)
return false;
646 if(y < ymin_kmag || y > ymax_kmag)
return false;
653 measurement = map_wirePosition[detectorID][elementID];
659 return map_wirePosition[detectorID][elementID];
664 ep1 = map_endPoint1[detectorID][elementID];
665 ep2 = map_endPoint2[detectorID][elementID];
670 TVectorD vp1(map_endPoint1[detectorID][elementID]);
671 TVectorD vp2(map_endPoint2[detectorID][elementID]);
673 ep1.SetXYZ(vp1[0], vp1[1], vp1[2]);
674 ep2.SetXYZ(vp2[0], vp2[1], vp2[2]);
680 double pos_min = planes[detectorID].
elementPos.front();
681 double pos_max = planes[detectorID].
elementPos.back();
682 pos_min -= (0.5*planes[detectorID].
cellWidth);
683 pos_max += (0.5*planes[detectorID].
cellWidth);
685 if(pos_exp > pos_max)
return planes[detectorID].
nElements+1;
686 if(pos_exp < pos_min)
return 0;
688 int index = std::lower_bound(planes[detectorID].elementPos.begin(), planes[detectorID].
elementPos.end(), pos_exp) - planes[detectorID].
elementPos.begin();
689 int elementID = index + 1 + (planes[detectorID].
elementPos[index] - pos_exp > 0.5*planes[detectorID].
spacing ? -1 : 0);
693 bool bottom = ((detectorID-55) & 2) > 0;
694 if(bottom) elementID = planes[detectorID].
nElements+1-elementID;
700 void GeomSvc::get2DBoxSize(
int detectorID,
int elementID,
double& x_min,
double& x_max,
double& y_min,
double& y_max)
703 if(planes[detectorID].planeType == 1)
705 double x_center = map_wirePosition[detectorID][elementID];
706 double x_width = 0.5*planes[detectorID].
cellWidth;
707 x_min = x_center - x_width;
708 x_max = x_center + x_width;
710 y_min = planes[detectorID].
y1;
711 y_max = planes[detectorID].
y2;
715 double y_center = map_wirePosition[detectorID][elementID];
716 double y_width = 0.5*planes[detectorID].
cellWidth;
717 y_min = y_center - y_width;
718 y_max = y_center + y_width;
720 x_min = planes[detectorID].
x1;
721 x_max = planes[detectorID].
x2;
727 y_min = planes[detectorID].
y1;
728 y_max = planes[detectorID].
y2;
730 double dw = planes[detectorID].
xoffset + planes[detectorID].
spacing*(elementID - (planes[detectorID].
nElements + 1.)/2.);
731 x_min = planes[detectorID].
xc + dw*cos(planes[detectorID].rZ) - fabs(0.5*planes[detectorID].tantheta*(y_max - y_min));
732 x_max = planes[detectorID].
xc + dw*cos(planes[detectorID].rZ) + fabs(0.5*planes[detectorID].tantheta*(y_max - y_min));
744 if(detectorName[0] ==
'P' && (detectorName[2] ==
'H' || detectorName[2] ==
'V'))
746 string XY = detectorName[2] ==
'H' ?
"Y" :
"X";
747 string FB = (detectorName[3] ==
'f' || detectorName[4] ==
'f') ?
"1" :
"2";
748 int moduleID = std::isdigit(detectorName[3]) == 1 ? atoi(&detectorName[3]) : atoi(&detectorName[4]);
750 detectorName.replace(2, detectorName.length(),
"");
756 eID = (9 - moduleID)*8 + eID;
779 return detectorName[0] ==
'D' &&
'0' <= detectorName[1] && detectorName[1] <=
'3';
789 return detectorName[0] ==
'H' &&
'1' <= detectorName[1] && detectorName[1] <=
'4';
799 return detectorName[0] ==
'P' &&
'1' <= detectorName[1] && detectorName[1] <=
'2';
809 return detectorName.substr(0, 2) ==
"DP";
819 return detectorName.substr(0, 6) ==
"Before" || detectorName.substr(0, 5) ==
"After";
829 if (detectorName.size() == 0 || detectorName[0] !=
'H')
return 0;
830 int num = detectorName[1] -
'0';
831 return 1 <= num && num <= 4 ? num : 0;
836 if(!calibration_loaded)
840 else if(planes[detectorID].rtprofile ==
NULL)
844 else if(tdcTime < planes[detectorID].tmin)
848 else if(tdcTime > planes[detectorID].tmax)
854 return planes[detectorID].
rtprofile->Eval(tdcTime);
862 return (tx*planes[detectorID].zc + x0)*planes[detectorID].
costheta + (ty*planes[detectorID].
zc + y0)*planes[detectorID].sintheta;
865 double GeomSvc::getDCA(
int detectorID,
int elementID,
double tx,
double ty,
double x0,
double y0)
867 TVector3 trkp0(x0, y0, 0.);
868 TVector3 trkdir(tx, ty, 1.);
872 TVector3 wiredir = ep2 - ep1;
874 TVector3 norm = trkdir.Cross(wiredir);
876 return (ep1 - trkp0).Dot(norm);
924 void GeomSvc::loadAlignment(
const std::string& alignmentFile_chamber,
const std::string& alignmentFile_hodo,
const std::string& alignmentFile_prop)
929 fstream _align_chamber;
930 _align_chamber.open(alignmentFile_chamber.c_str(), ios::in);
937 _align_chamber.getline(buf, 100);
938 istringstream stringBuf(buf);
940 stringBuf >> planes[i].deltaW >> planes[i].resolution;
943 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
944 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
950 double resol = planes[i].resolution > planes[i+1].resolution ? planes[i].resolution : planes[i+1].resolution;
951 planes[i ].resolution = resol;
952 planes[i+1].resolution = resol;
955 cout <<
"GeomSvc: loaded chamber alignment parameters from " << alignmentFile_chamber << endl;
957 _align_chamber.close();
961 _align_hodo.open(alignmentFile_hodo.c_str(), ios::in);
967 _align_hodo.getline(buf, 100);
968 istringstream stringBuf(buf);
970 stringBuf >> planes[i].deltaW;
971 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
972 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
975 cout <<
"GeomSvc: loaded hodoscope alignment parameters from " << alignmentFile_hodo << endl;
979 cout <<
"GeomSvc: failed to load hodoscope alignment parameters from " << alignmentFile_hodo << endl;
985 _align_prop.open(alignmentFile_prop.c_str(), ios::in);
991 planes[i].deltaW = 0.;
992 planes[i+1].deltaW = 0.;
993 for(
int j = 0; j < 9; j++)
995 _align_prop.getline(buf, 100);
996 istringstream stringBuf(buf);
998 stringBuf >> planes[i].deltaW_module[j];
999 planes[i+1].deltaW_module[j] = planes[i].deltaW_module[j];
1001 planes[i].deltaW += planes[i].deltaW_module[j];
1002 planes[i+1].deltaW += planes[i+1].deltaW_module[j];
1005 planes[i].deltaW /= 9.;
1006 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
1007 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
1009 planes[i+1].deltaW /= 9.;
1010 planes[i+1].deltaX = planes[i+1].deltaW*planes[i+1].costheta;
1011 planes[i+1].deltaY = planes[i+1].deltaW*planes[i+1].sintheta;
1013 cout <<
"GeomSvc: loaded prop. tube alignment parameters from " << alignmentFile_prop << endl;
1017 cout <<
"GeomSvc: failed to load prop. tube alignment parameters from " << alignmentFile_prop << endl;
1024 using namespace std;
1027 fstream _align_mille;
1028 _align_mille.open(alignmentFile_mille.c_str(), ios::in);
1035 _align_mille.getline(buf, 100);
1036 istringstream stringBuf(buf);
1038 stringBuf >> planes[i].deltaZ >> planes[i].rotZ >> planes[i].deltaW >> planes[i].resolution;
1039 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
1040 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
1045 cout <<
"GeomSvc: loaded millepede-based alignment parameters from " << alignmentFile_mille << endl;
1049 planes[i].resolution = rc->get_DoubleFlag(
"RESOLUTION_FACTOR")*0.5*(planes[i].resolution + planes[i+1].resolution);
1050 planes[i+1].resolution = planes[i].resolution;
1055 cout <<
"GeomSvc: failed to load mullepede-based alignment parameters from " << alignmentFile_mille << endl;
1058 _align_mille.close();
1063 using namespace std;
1066 _cali_file.open(calibrationFile.c_str(), ios::in);
1069 int iBin, nBin, detectorID;
1070 double tmin_temp, tmax_temp;
1071 double R[500], T[500];
1074 calibration_loaded =
true;
1076 while(_cali_file.getline(buf, 100))
1078 istringstream detector_info(buf);
1079 detector_info >> detectorID >> nBin >> tmin_temp >> tmax_temp;
1080 planes[detectorID].tmax = tmax_temp;
1081 planes[detectorID].tmin = tmin_temp;
1083 for(
int i = 0; i < nBin; i++)
1085 _cali_file.getline(buf, 100);
1086 istringstream cali_line(buf);
1088 cali_line >> iBin >> T[i] >> R[i];
1091 if(planes[detectorID].rtprofile !=
NULL)
delete planes[detectorID].rtprofile;
1092 if(nBin > 0) planes[detectorID].rtprofile =
new TSpline3(
getDetectorName(detectorID).c_str(), T, R, nBin,
"b1e1");
1094 cout <<
"GeomSvc: loaded calibration parameters from " << calibrationFile << endl;
1101 return tdcTime > planes[detectorID].
tmin && tdcTime < planes[detectorID].
tmax;
1106 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
1109 int detectorID = (*iter).second;
1110 std::cout <<
" ====================== " << (*iter).first <<
" ==================== " << std::endl;
1111 for(
int i = 1; i <= planes[detectorID].
nElements; ++i)
1113 std::cout << std::setw(6) << std::setiosflags(std::ios::right) << detectorID;
1114 std::cout << std::setw(6) << std::setiosflags(std::ios::right) << (*iter).first;
1115 std::cout << std::setw(6) << std::setiosflags(std::ios::right) << i;
1116 std::cout << std::setw(10) << std::setiosflags(std::ios::right) << map_wirePosition[detectorID][i];
1117 std::cout << std::setw(10) << std::setiosflags(std::ios::right) << map_wirePosition[detectorID][i] - 0.5*planes[detectorID].
cellWidth;
1118 std::cout << std::setw(10) << std::setiosflags(std::ios::right) << map_wirePosition[detectorID][i] + 0.5*planes[detectorID].
cellWidth;
1119 std::cout << std::endl;
1126 std::cout <<
"detectorID DetectorName offset_pos offset_z offset_phi" << std::endl;
1127 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
1130 std::cout << iter->second <<
" " << iter->first <<
" " << planes[(*iter).second].
deltaW <<
" " << planes[(*iter).second].
deltaZ <<
" " << planes[(*iter).second].
rotZ << std::endl;
1136 std::cout <<
"detectorID detectorName planeType Spacing Xoffset overlap width height nElement angleFromVertical z0 x0 y0 deltaW" << std::endl;
1137 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
1140 std::cout << planes[iter->second] << std::endl;
std::ostream & operator<<(std::ostream &os, const Plane &plane)
#define nDarkPhotonPlanes
Plane * GetPlane(const int idx)
User interface class about the geometry of detector planes.
bool findPatternInDetector(int detectorID, std::string pattern)
double getDriftDistance(int detectorID, double tdcTime)
bool isInElement(int detectorID, int elementID, double x, double y, double tolr=0.)
bool isPropTube(const int detectorID) const
Return "true" for prop tube planes.
bool isHodo(const int detectorID) const
Return "true" for hodo planes.
void getWireEndPoints(int detectorID, int elementID, double &x_min, double &x_max, double &y_min, double &y_max)
void printAlignPar()
Debugging print of the content.
static GeomSvc * instance()
singlton instance
void toLocalDetectorName(std::string &detectorName, int &eID)
Convert the official detectorName to local detectorName.
void loadMilleAlignment(const std::string &alignmentFile_mille)
void getMeasurement(int detectorID, int elementID, double &measurement, double &dmeasurement)
Convert the detectorID and elementID to the actual hit position.
void loadOnlineAlignment(const std::string &alignmentFile_mille)
Load parameters used in the online-alignment mode.
void getEndPoints(int detectorID, int elementID, TVectorD &ep1, TVectorD &ep2)
bool isInKMAG(double x, double y)
bool isInh(const int detectorID) const
Return "true" for BeforeInh and AfterInh signals.
void init()
Initialization, either from MySQL or from ascii file.
int getHodoStation(const int detectorID) const
Return a station number (1-4) for hodo planes or "0" for others.
int getExpElementID(int detectorID, double pos_exp)
bool isInTime(int detectorID, double tdcTime)
double getInterceptionFast(int detectorID, double tx, double ty, double x0, double y0) const
void loadAlignment(const std::string &alignmentFile_chamber, const std::string &alignmentFile_hodo, const std::string &alignmentFile_prop)
void loadCalibration(const std::string &calibrateFile)
std::string getDetectorName(const int &detectorID) const
bool isChamber(const int detectorID) const
Return "true" for chamber planes.
double getDCA(int detectorID, int elementID, double tx, double ty, double x0, double y0)
bool isInPlane(int detectorID, double x, double y)
See if a point is in a plane.
void close()
Close the geometry service before exit or starting a new one.
void get2DBoxSize(int detectorID, int elementID, double &x_min, double &x_max, double &y_min, double &y_max)
bool isDPHodo(const int detectorID) const
Return "true" for DP hodo planes.
std::vector< int > getDetectorIDs(std::string pattern)
virtual int FlagExist(const std::string &name) const
virtual int get_IntFlag(const std::string &name) const
virtual const std::string get_CharFlag(const std::string &flag) const
std::vector< double > elementPos
double getWirePosition(int elementID) const
TVectorD getEndPoint(int elementID, int sign=-1) const
double intercept(double tx, double ty, double x0_track, double y0_track) const
double getW(double x, double y) const
void SetMapID(const std::string map_id)
void SetMapIDbyDB(const std::string map_id)
static recoConsts * instance()
virtual void set_CharFlag(const std::string &name, const std::string &flag)
overide the virtual function to expand the environmental variables