19 #include <TSQLServer.h>
20 #include <TSQLResult.h>
25 #include <TRotation.h>
122 nVec[0] = uVec[1]*vVec[2] - vVec[1]*uVec[2];
123 nVec[1] = uVec[2]*vVec[0] - vVec[2]*uVec[0];
124 nVec[2] = uVec[0]*vVec[1] - vVec[0]*uVec[1];
133 double dpos[3] = {x0_track -
xc, y0_track -
yc, -
zc};
138 vcp[2] = vVec[0]*ty - vVec[1]*tx;
141 return -(vcp[0]*dpos[0] + vcp[1]*dpos[1] + vcp[2]*dpos[2])/det +
wc;
152 TVectorD detCenter(3);
164 ep = detCenter + ((elementID - (
nElements+1.)/2.)*hspacing + hoffset)*
xVec + 0.5*sign*cellLength*
vVec;
172 ep = detCenter + ((elementID - (
nElements+1.)/2.)*vspacing + voffset)*
yVec + 0.5*sign*cellLength*
vVec;
180 os << std::setw(6) << std::setiosflags(std::ios::right) << plane.
detectorID
181 << std::setw(6) << std::setiosflags(std::ios::right) << plane.
detectorName
182 << std::setw(6) << std::setiosflags(std::ios::right) << plane.
planeType
183 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
spacing
184 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
cellWidth
185 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
xoffset
186 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
overlap
187 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
x2 - plane.
x1
188 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
y2 - plane.
y1
189 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
z2 - plane.
z1
190 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
nElements
191 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
angleFromVert
192 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
xc
193 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
yc
194 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
zc
195 << std::setw(10) << std::setiosflags(std::ios::right) << plane.
deltaW <<
"\n"
196 <<
", nVec: {" << plane.
nVec[0] <<
", " << plane.
nVec[1] <<
", " << plane.
nVec[2] <<
"} "
197 <<
", uVec: {" << plane.
uVec[0] <<
", " << plane.
uVec[1] <<
", " << plane.
uVec[2] <<
"} "
198 <<
", vVec: {" << plane.
vVec[0] <<
", " << plane.
vVec[1] <<
", " << plane.
vVec[2] <<
"} ";
201 for(
int i=0; i<9; ++i)
202 os << std::setw(10) << std::setiosflags(std::ios::right) << plane.
deltaW_module[i];
209 bool GeomSvc::use_dbsvc =
true;
213 if(p_geometrySvc ==
NULL)
216 p_geometrySvc->
init();
219 return p_geometrySvc;
231 delete p_geometrySvc;
235 std::cout <<
"Error: no instance of geometry service found! " << std::endl;
245 typedef std::map<std::string, int>::value_type nameToID;
248 map_detectorID.insert(nameToID(
"D0U" , ++idx));
249 map_detectorID.insert(nameToID(
"D0Up" , ++idx));
250 map_detectorID.insert(nameToID(
"D0X" , ++idx));
251 map_detectorID.insert(nameToID(
"D0Xp" , ++idx));
252 map_detectorID.insert(nameToID(
"D0V" , ++idx));
253 map_detectorID.insert(nameToID(
"D0Vp" , ++idx));
254 map_detectorID.insert(nameToID(
"D1V" , ++idx));
255 map_detectorID.insert(nameToID(
"D1Vp" , ++idx));
256 map_detectorID.insert(nameToID(
"D1X" , ++idx));
257 map_detectorID.insert(nameToID(
"D1Xp" , ++idx));
258 map_detectorID.insert(nameToID(
"D1U" , ++idx));
259 map_detectorID.insert(nameToID(
"D1Up" , ++idx));
260 map_detectorID.insert(nameToID(
"D2V" , ++idx));
261 map_detectorID.insert(nameToID(
"D2Vp" , ++idx));
262 map_detectorID.insert(nameToID(
"D2Xp" , ++idx));
263 map_detectorID.insert(nameToID(
"D2X" , ++idx));
264 map_detectorID.insert(nameToID(
"D2U" , ++idx));
265 map_detectorID.insert(nameToID(
"D2Up" , ++idx));
266 map_detectorID.insert(nameToID(
"D3pVp", ++idx));
267 map_detectorID.insert(nameToID(
"D3pV" , ++idx));
268 map_detectorID.insert(nameToID(
"D3pXp", ++idx));
269 map_detectorID.insert(nameToID(
"D3pX" , ++idx));
270 map_detectorID.insert(nameToID(
"D3pUp", ++idx));
271 map_detectorID.insert(nameToID(
"D3pU" , ++idx));
272 map_detectorID.insert(nameToID(
"D3mVp", ++idx));
273 map_detectorID.insert(nameToID(
"D3mV" , ++idx));
274 map_detectorID.insert(nameToID(
"D3mXp", ++idx));
275 map_detectorID.insert(nameToID(
"D3mX" , ++idx));
276 map_detectorID.insert(nameToID(
"D3mUp", ++idx));
277 map_detectorID.insert(nameToID(
"D3mU" , ++idx));
280 map_detectorID.insert(nameToID(
"H1B" , ++idx));
281 map_detectorID.insert(nameToID(
"H1T" , ++idx));
282 map_detectorID.insert(nameToID(
"H1L" , ++idx));
283 map_detectorID.insert(nameToID(
"H1R" , ++idx));
284 map_detectorID.insert(nameToID(
"H2L" , ++idx));
285 map_detectorID.insert(nameToID(
"H2R" , ++idx));
286 map_detectorID.insert(nameToID(
"H2B" , ++idx));
287 map_detectorID.insert(nameToID(
"H2T" , ++idx));
288 map_detectorID.insert(nameToID(
"H3B" , ++idx));
289 map_detectorID.insert(nameToID(
"H3T" , ++idx));
290 map_detectorID.insert(nameToID(
"H4Y1L", ++idx));
291 map_detectorID.insert(nameToID(
"H4Y1R", ++idx));
292 map_detectorID.insert(nameToID(
"H4Y2L", ++idx));
293 map_detectorID.insert(nameToID(
"H4Y2R", ++idx));
294 map_detectorID.insert(nameToID(
"H4B" , ++idx));
295 map_detectorID.insert(nameToID(
"H4T" , ++idx));
298 map_detectorID.insert(nameToID(
"P1Y1", ++idx));
299 map_detectorID.insert(nameToID(
"P1Y2", ++idx));
300 map_detectorID.insert(nameToID(
"P1X1", ++idx));
301 map_detectorID.insert(nameToID(
"P1X2", ++idx));
302 map_detectorID.insert(nameToID(
"P2X1", ++idx));
303 map_detectorID.insert(nameToID(
"P2X2", ++idx));
304 map_detectorID.insert(nameToID(
"P2Y1", ++idx));
305 map_detectorID.insert(nameToID(
"P2Y2", ++idx));
308 map_detectorID.insert(nameToID(
"DP1TL", ++idx));
309 map_detectorID.insert(nameToID(
"DP1TR", ++idx));
310 map_detectorID.insert(nameToID(
"DP1BL", ++idx));
311 map_detectorID.insert(nameToID(
"DP1BR", ++idx));
312 map_detectorID.insert(nameToID(
"DP2TL", ++idx));
313 map_detectorID.insert(nameToID(
"DP2TR", ++idx));
314 map_detectorID.insert(nameToID(
"DP2BL", ++idx));
315 map_detectorID.insert(nameToID(
"DP2BR", ++idx));
318 map_detectorID.insert(nameToID(
"BeforeInhNIM" , ++idx));
319 map_detectorID.insert(nameToID(
"BeforeInhMatrix", ++idx));
320 map_detectorID.insert(nameToID(
"AfterInhNIM" , ++idx));
321 map_detectorID.insert(nameToID(
"AfterInhMatrix" , ++idx));
322 map_detectorID.insert(nameToID(
"BOS" , ++idx));
323 map_detectorID.insert(nameToID(
"EOS" , ++idx));
324 map_detectorID.insert(nameToID(
"L1" , ++idx));
325 map_detectorID.insert(nameToID(
"RF" , ++idx));
326 map_detectorID.insert(nameToID(
"STOP" , ++idx));
327 map_detectorID.insert(nameToID(
"L1PXtp" , ++idx));
328 map_detectorID.insert(nameToID(
"L1PXtn" , ++idx));
329 map_detectorID.insert(nameToID(
"L1PXbp" , ++idx));
330 map_detectorID.insert(nameToID(
"L1PXbn" , ++idx));
331 map_detectorID.insert(nameToID(
"L1NIMxt" , ++idx));
332 map_detectorID.insert(nameToID(
"L1NIMxb" , ++idx));
333 map_detectorID.insert(nameToID(
"L1NIMyt" , ++idx));
334 map_detectorID.insert(nameToID(
"L1NIMyb" , ++idx));
337 map_detectorID.insert(nameToID(
"H4Y1Ll", ++idx));
338 map_detectorID.insert(nameToID(
"H4Y1Lr", ++idx));
339 map_detectorID.insert(nameToID(
"H4Y1Rl", ++idx));
340 map_detectorID.insert(nameToID(
"H4Y1Rr", ++idx));
341 map_detectorID.insert(nameToID(
"H4Y2Ll", ++idx));
342 map_detectorID.insert(nameToID(
"H4Y2Lr", ++idx));
343 map_detectorID.insert(nameToID(
"H4Y2Rl", ++idx));
344 map_detectorID.insert(nameToID(
"H4Y2Rr", ++idx));
345 map_detectorID.insert(nameToID(
"H4Tu" , ++idx));
346 map_detectorID.insert(nameToID(
"H4Td" , ++idx));
347 map_detectorID.insert(nameToID(
"H4Bu" , ++idx));
348 map_detectorID.insert(nameToID(
"H4Bd" , ++idx));
353 map_detid_triggerlv[i] = -1;
356 map_detid_triggerlv[i] = 0;
359 map_detid_triggerlv[i] = 1;
362 map_detid_triggerlv[i] = 2;
365 map_detid_triggerlv[i] = 3;
368 typedef std::map<int, std::string>::value_type idToName;
369 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
371 map_detectorName.insert(idToName(iter->second, iter->first));
380 calibration_loaded =
false;
381 if(!rc->get_BoolFlag(
"OnlineAlignment") && (!rc->get_BoolFlag(
"IdealGeom")))
383 loadAlignment(
"NULL", rc->get_CharFlag(
"AlignmentHodo"), rc->get_CharFlag(
"AlignmentProp"));
391 xmin_kmag = -57.*2.54;
392 xmax_kmag = 57.*2.54;
393 ymin_kmag = -40.*2.54;
394 ymax_kmag = 40.*2.54;
396 zmin_kmag = 1064.26 - 120.*2.54;
397 zmax_kmag = 1064.26 + 120.*2.54;
402 cout << planes[i] << endl;
412 TSQLServer* con = TSQLServer::Connect(rc->get_CharFlag(
"MySQLURL").c_str(),
"seaguest",
"qqbar2mu+mu-");
416 const char* buf_planes =
"SELECT detectorName,spacing,cellWidth,overlap,numElements,angleFromVert,"
417 "xPrimeOffset,x0,y0,z0,planeWidth,planeHeight,theta_x,theta_y,theta_z from %s.Planes WHERE"
418 " detectorName LIKE 'D%%' OR detectorName LIKE 'H__' OR detectorName LIKE 'H____' OR "
419 "detectorName LIKE 'P____'";
420 sprintf(query, buf_planes, rc->get_CharFlag(
"Geometry").c_str());
421 TSQLResult* res = con->Query(query);
423 unsigned int nRows = res->GetRowCount();
425 for(
unsigned int i = 0; i < nRows; ++i)
427 TSQLRow* row = res->Next();
428 std::string detectorName(row->GetField(0));
431 int detectorID = map_detectorID[detectorName];
432 planes[detectorID].detectorID = detectorID;
433 planes[detectorID].detectorName = detectorName;
434 planes[detectorID].spacing = atof(row->GetField(1));
435 planes[detectorID].cellWidth = atof(row->GetField(2));
436 planes[detectorID].overlap = atof(row->GetField(3));
437 planes[detectorID].angleFromVert = atof(row->GetField(5));
438 planes[detectorID].xoffset = atof(row->GetField(6));
439 planes[detectorID].thetaX = atof(row->GetField(12));
440 planes[detectorID].thetaY = atof(row->GetField(13));
441 planes[detectorID].thetaZ = atof(row->GetField(14));
444 planes[detectorID].nElements += atoi(row->GetField(4));
445 double x0_i = atof(row->GetField(7));
446 double y0_i = atof(row->GetField(8));
447 double z0_i = atof(row->GetField(9));
448 double width_i = atof(row->GetField(10));
449 double height_i = atof(row->GetField(11));
451 double x1_i = x0_i - 0.5*width_i;
452 double x2_i = x0_i + 0.5*width_i;
453 double y1_i = y0_i - 0.5*height_i;
454 double y2_i = y0_i + 0.5*height_i;
456 planes[detectorID].x0 += x0_i;
457 planes[detectorID].y0 += y0_i;
458 planes[detectorID].z0 += z0_i;
459 if(planes[detectorID].x1 > x1_i) planes[detectorID].x1 = x1_i;
460 if(planes[detectorID].x2 < x2_i) planes[detectorID].x2 = x2_i;
461 if(planes[detectorID].y1 > y1_i) planes[detectorID].y1 = y1_i;
462 if(planes[detectorID].y2 < y2_i) planes[detectorID].y2 = y2_i;
465 planes[detectorID].resolution = planes[detectorID].cellWidth/sqrt(12.);
466 planes[detectorID].update();
469 if(detectorName.find(
"X") != string::npos || detectorName.find(
"T") != string::npos || detectorName.find(
"B") != string::npos)
471 planes[detectorID].planeType = 1;
473 else if((detectorName.find(
"U") != string::npos || detectorName.find(
"V") != string::npos) && planes[detectorID].angleFromVert > 0)
475 planes[detectorID].planeType = 2;
477 else if((detectorName.find(
"U") != string::npos || detectorName.find(
"V") != string::npos) && planes[detectorID].angleFromVert < 0)
479 planes[detectorID].planeType = 3;
481 else if(detectorName.find(
"Y") != string::npos || detectorName.find(
"L") != string::npos || detectorName.find(
"R") != string::npos)
483 planes[detectorID].planeType = 4;
493 planes[i].x0 = planes[i].x0/9.;
494 planes[i].y0 = planes[i].y0/9.;
495 planes[i].z0 = planes[i].z0/9.;
505 planes[i].z1 = planes[i].z0 - planes[i].cellWidth/2.;
506 planes[i].z2 = planes[i].z0 + planes[i].cellWidth/2.;
510 planes[i].z1 = planes[i].z0 - 0.635/2.;
511 planes[i].z2 = planes[i].z0 + 0.635/2.;
515 planes[i].z1 = planes[i].z0 - planes[i].cellWidth*TMath::Pi()/8.;
516 planes[i].z2 = planes[i].z0 + planes[i].cellWidth*TMath::Pi()/8.;
520 planes[i].z1 = planes[i].z0 - planes[i].cellWidth/2.;
521 planes[i].z2 = planes[i].z0 + planes[i].cellWidth/2.;
524 cout <<
"GeomSvc: loaded basic spectrometer setup from geometry schema " << rc->get_CharFlag(
"Geometry") << endl;
527 if(rc->get_BoolFlag(
"OnlineAlignment"))
530 const char* buf_offsets =
"SELECT detectorName,deltaX,deltaY,deltaZ,rotateAboutZ FROM %s.PlaneOffsets WHERE"
531 " detectorName LIKE 'D%%' OR detectorName LIKE 'H__' OR detectorName LIKE 'H____' OR detectorName LIKE 'P____'";
532 sprintf(query, buf_offsets, rc->get_CharFlag(
"Geometry").c_str());
533 res = con->Query(query);
535 nRows = res->GetRowCount();
536 if(nRows >=
nChamberPlanes) cout <<
"GeomSvc: loaded chamber alignment parameters from database: " << rc->get_CharFlag(
"Geometry") << endl;
537 for(
unsigned int i = 0; i < nRows; ++i)
539 TSQLRow* row = res->Next();
540 string detectorName(row->GetField(0));
543 int detectorID = map_detectorID[detectorName];
550 planes[detectorID].deltaX = atof(row->GetField(1));
551 planes[detectorID].deltaY = atof(row->GetField(2));
552 planes[detectorID].deltaZ = atof(row->GetField(3));
553 planes[detectorID].rotZ = atof(row->GetField(4));
555 planes[detectorID].update();
556 planes[detectorID].deltaW = planes[detectorID].getW(planes[detectorID].deltaX, planes[detectorID].deltaY);
569 cout <<
"GeomSvc: Load the plane geometry info via DbSvc for run = " <<
run <<
"." << endl;
572 geom->SetMapIDbyDB(
run);
575 for (
int ii = 0; ii < geom->GetNumPlanes(); ii++) {
581 int detectorID = map_detectorID[detectorName];
583 planes[detectorID].detectorID = detectorID;
584 planes[detectorID].detectorName = detectorName;
586 planes[detectorID].cellWidth = pl->
cell_width;
589 planes[detectorID].xoffset = pl->
xoffset;
590 planes[detectorID].thetaX = pl->
theta_x;
591 planes[detectorID].thetaY = pl->
theta_y;
592 planes[detectorID].thetaZ = pl->
theta_z;
595 planes[detectorID].nElements += pl->
n_ele;
596 double x0_i = pl->
x0;
597 double y0_i = pl->
y0;
598 double z0_i = pl->
z0;
599 double width_i = pl->
width;
600 double height_i = pl->
height;
602 double x1_i = x0_i - 0.5*width_i;
603 double x2_i = x0_i + 0.5*width_i;
604 double y1_i = y0_i - 0.5*height_i;
605 double y2_i = y0_i + 0.5*height_i;
607 planes[detectorID].x0 += x0_i;
608 planes[detectorID].y0 += y0_i;
609 planes[detectorID].z0 += z0_i;
610 if(planes[detectorID].x1 > x1_i) planes[detectorID].x1 = x1_i;
611 if(planes[detectorID].x2 < x2_i) planes[detectorID].x2 = x2_i;
612 if(planes[detectorID].y1 > y1_i) planes[detectorID].y1 = y1_i;
613 if(planes[detectorID].y2 < y2_i) planes[detectorID].y2 = y2_i;
616 planes[detectorID].resolution = planes[detectorID].cellWidth/sqrt(12.);
617 planes[detectorID].update();
620 if(detectorName.find(
"X") != string::npos || detectorName.find(
"T") != string::npos || detectorName.find(
"B") != string::npos)
622 planes[detectorID].planeType = 1;
624 else if((detectorName.find(
"U") != string::npos || detectorName.find(
"V") != string::npos) && planes[detectorID].angleFromVert > 0)
626 planes[detectorID].planeType = 2;
628 else if((detectorName.find(
"U") != string::npos || detectorName.find(
"V") != string::npos) && planes[detectorID].angleFromVert < 0)
630 planes[detectorID].planeType = 3;
632 else if(detectorName.find(
"Y") != string::npos || detectorName.find(
"L") != string::npos || detectorName.find(
"R") != string::npos)
634 planes[detectorID].planeType = 4;
641 planes[i].x0 = planes[i].x0/9.;
642 planes[i].y0 = planes[i].y0/9.;
643 planes[i].z0 = planes[i].z0/9.;
653 planes[i].z1 = planes[i].z0 - planes[i].cellWidth/2.;
654 planes[i].z2 = planes[i].z0 + planes[i].cellWidth/2.;
658 planes[i].z1 = planes[i].z0 - 0.635/2.;
659 planes[i].z2 = planes[i].z0 + 0.635/2.;
663 planes[i].z1 = planes[i].z0 - planes[i].cellWidth*TMath::Pi()/8.;
664 planes[i].z2 = planes[i].z0 + planes[i].cellWidth*TMath::Pi()/8.;
668 planes[i].z1 = planes[i].z0 - planes[i].cellWidth/2.;
669 planes[i].z2 = planes[i].z0 + planes[i].cellWidth/2.;
678 typedef std::map<std::pair<int, int>,
double>::value_type posType;
679 typedef std::map<std::pair<int, int>, TVectorD>::value_type epType;
682 for(
int j = 1; j <= planes[i].
nElements; ++j)
685 map_wirePosition.insert(posType(std::make_pair(i, j), pos));
687 map_endPoint1.insert(epType(std::make_pair(i, j), planes[i].getEndPoint(j, -1)));
688 map_endPoint2.insert(epType(std::make_pair(i, j), planes[i].getEndPoint(j, 1)));
692 std::sort(planes[i].elementPos.begin(), planes[i].
elementPos.end());
698 for(
int j = 1; j <= planes[i].
nElements; ++j)
707 int moduleID = 8 - int((j - 1)/8);
712 int elementID = ((i-55) & 2) > 0 ? planes[i].
nElements + 1 - j : j;
715 map_wirePosition.insert(posType(std::make_pair(i, j), pos));
716 map_endPoint1.insert(epType(std::make_pair(i, j), planes[i].getEndPoint(j, -1)));
717 map_endPoint2.insert(epType(std::make_pair(i, j), planes[i].getEndPoint(j, 1)));
720 std::sort(planes[i].elementPos.begin(), planes[i].
elementPos.end());
726 TPRegexp pattern_re(pattern.c_str());
728 std::vector<int> detectorIDs;
731 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
733 TString detectorName((*iter).first.c_str());
734 if(detectorName(pattern_re) !=
"")
736 detectorIDs.push_back((*iter).second);
739 std::sort(detectorIDs.begin(), detectorIDs.end());
746 TPRegexp pattern_re(pattern.c_str());
747 TString detectorName(map_detectorName[detectorID]);
749 return detectorName(pattern_re) !=
"";
754 if(x < planes[detectorID].x1 || x > planes[detectorID].x2)
return false;
755 if(y < planes[detectorID].y1 || y > planes[detectorID].y2)
return false;
762 double x_min, x_max, y_min, y_max;
763 get2DBoxSize(detectorID, elementID, x_min, x_max, y_min, y_max);
765 x_min -= (tolr*(x_max - x_min));
766 x_max += (tolr*(x_max - x_min));
767 y_min -= (tolr*(y_max - y_min));
768 y_max += (tolr*(y_max - y_min));
770 return x > x_min && x < x_max && y > y_min && y < y_max;
775 if(x < xmin_kmag || x > xmax_kmag)
return false;
776 if(y < ymin_kmag || y > ymax_kmag)
return false;
783 measurement = map_wirePosition[std::make_pair(detectorID, elementID)];
789 return map_wirePosition[std::make_pair(detectorID, elementID)];
794 ep1 = map_endPoint1[std::make_pair(detectorID, elementID)];
795 ep2 = map_endPoint2[std::make_pair(detectorID, elementID)];
800 TVectorD vp1(map_endPoint1[std::make_pair(detectorID, elementID)]);
801 TVectorD vp2(map_endPoint2[std::make_pair(detectorID, elementID)]);
803 ep1.SetXYZ(vp1[0], vp1[1], vp1[2]);
804 ep2.SetXYZ(vp2[0], vp2[1], vp2[2]);
810 double pos_min = planes[detectorID].
elementPos.front();
811 double pos_max = planes[detectorID].
elementPos.back();
812 pos_min -= (0.5*planes[detectorID].
cellWidth);
813 pos_max += (0.5*planes[detectorID].
cellWidth);
815 if(pos_exp > pos_max)
return planes[detectorID].
nElements+1;
816 if(pos_exp < pos_min)
return 0;
818 int index = std::lower_bound(planes[detectorID].elementPos.begin(), planes[detectorID].
elementPos.end(), pos_exp) - planes[detectorID].elementPos.begin();
819 int elementID = index + 1 + (planes[detectorID].
elementPos[index] - pos_exp > 0.5*planes[detectorID].
spacing ? -1 : 0);
823 bool bottom = ((detectorID-55) & 2) > 0;
824 if(bottom) elementID = planes[detectorID].
nElements+1-elementID;
830 void GeomSvc::get2DBoxSize(
int detectorID,
int elementID,
double& x_min,
double& x_max,
double& y_min,
double& y_max)
833 if(planes[detectorID].planeType == 1)
835 double x_center = map_wirePosition[std::make_pair(detectorID, elementID)];
836 double x_width = 0.5*planes[detectorID].
cellWidth;
837 x_min = x_center - x_width;
838 x_max = x_center + x_width;
840 y_min = planes[detectorID].
y1;
841 y_max = planes[detectorID].
y2;
845 double y_center = map_wirePosition[std::make_pair(detectorID, elementID)];
846 double y_width = 0.5*planes[detectorID].
cellWidth;
847 y_min = y_center - y_width;
848 y_max = y_center + y_width;
850 x_min = planes[detectorID].
x1;
851 x_max = planes[detectorID].
x2;
857 y_min = planes[detectorID].
y1;
858 y_max = planes[detectorID].
y2;
860 double dw = planes[detectorID].
xoffset + planes[detectorID].
spacing*(elementID - (planes[detectorID].
nElements + 1.)/2.);
861 x_min = planes[detectorID].
xc + dw*cos(planes[detectorID].rZ) - fabs(0.5*planes[detectorID].tantheta*(y_max - y_min));
862 x_max = planes[detectorID].
xc + dw*cos(planes[detectorID].rZ) + fabs(0.5*planes[detectorID].tantheta*(y_max - y_min));
869 if(detectorName[0] ==
'P')
871 string XY = detectorName[2] ==
'H' ?
"Y" :
"X";
872 string FB = (detectorName[3] ==
'f' || detectorName[4] ==
'f') ?
"1" :
"2";
873 int moduleID = std::isdigit(detectorName[3]) == 1 ? atoi(&detectorName[3]) : atoi(&detectorName[4]);
875 detectorName.replace(2, detectorName.length(),
"");
881 eID = (9 - moduleID)*8 + eID;
904 if (detectorName.size() == 0 || detectorName[0] !=
'H')
return 0;
905 int num = detectorName[1] -
'0';
906 return 1 <= num && num <= 4 ? num : 0;
911 if(!calibration_loaded)
915 else if(planes[detectorID].rtprofile ==
NULL)
919 else if(tdcTime < planes[detectorID].tmin)
923 else if(tdcTime > planes[detectorID].tmax)
929 return planes[detectorID].
rtprofile->Eval(tdcTime);
937 return (tx*planes[detectorID].zc + x0)*planes[detectorID].
costheta + (ty*planes[detectorID].
zc + y0)*planes[detectorID].sintheta;
940 double GeomSvc::getDCA(
int detectorID,
int elementID,
double tx,
double ty,
double x0,
double y0)
942 TVector3 trkp0(x0, y0, 0.);
943 TVector3 trkdir(tx, ty, 1.);
947 TVector3 wiredir = ep2 - ep1;
949 TVector3 norm = trkdir.Cross(wiredir);
951 return (ep1 - trkp0).Dot(norm);
954 void GeomSvc::loadAlignment(
const std::string& alignmentFile_chamber,
const std::string& alignmentFile_hodo,
const std::string& alignmentFile_prop)
959 fstream _align_chamber;
960 _align_chamber.open(alignmentFile_chamber.c_str(), ios::in);
967 _align_chamber.getline(buf, 100);
968 istringstream stringBuf(buf);
970 stringBuf >> planes[i].deltaW >> planes[i].resolution;
973 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
974 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
980 double resol = planes[i].resolution > planes[i+1].resolution ? planes[i].resolution : planes[i+1].resolution;
981 planes[i].resolution = resol;
982 planes[i].resolution = resol;
985 cout <<
"GeomSvc: loaded chamber alignment parameters from " << alignmentFile_chamber << endl;
987 _align_chamber.close();
991 _align_hodo.open(alignmentFile_hodo.c_str(), ios::in);
997 _align_hodo.getline(buf, 100);
998 istringstream stringBuf(buf);
1000 stringBuf >> planes[i].deltaW;
1001 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
1002 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
1005 cout <<
"GeomSvc: loaded hodoscope alignment parameters from " << alignmentFile_hodo << endl;
1009 cout <<
"GeomSvc: failed to load hodoscope alignment parameters from " << alignmentFile_hodo << endl;
1011 _align_hodo.close();
1014 fstream _align_prop;
1015 _align_prop.open(alignmentFile_prop.c_str(), ios::in);
1021 planes[i].deltaW = 0.;
1022 planes[i+1].deltaW = 0.;
1023 for(
int j = 0; j < 9; j++)
1025 _align_prop.getline(buf, 100);
1026 istringstream stringBuf(buf);
1028 stringBuf >> planes[i].deltaW_module[j];
1029 planes[i+1].deltaW_module[j] = planes[i].deltaW_module[j];
1031 planes[i].deltaW += planes[i].deltaW_module[j];
1032 planes[i+1].deltaW += planes[i+1].deltaW_module[j];
1035 planes[i].deltaW /= 9.;
1036 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
1037 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
1039 planes[i+1].deltaW /= 9.;
1040 planes[i+1].deltaX = planes[i+1].deltaW*planes[i+1].costheta;
1041 planes[i+1].deltaY = planes[i+1].deltaW*planes[i+1].sintheta;
1043 cout <<
"GeomSvc: loaded prop. tube alignment parameters from " << alignmentFile_prop << endl;
1047 cout <<
"GeomSvc: failed to load prop. tube alignment parameters from " << alignmentFile_prop << endl;
1054 using namespace std;
1057 fstream _align_mille;
1058 _align_mille.open(alignmentFile_mille.c_str(), ios::in);
1065 _align_mille.getline(buf, 100);
1066 istringstream stringBuf(buf);
1068 stringBuf >> planes[i].deltaZ >> planes[i].rotZ >> planes[i].deltaW >> planes[i].resolution;
1069 planes[i].deltaX = planes[i].deltaW*planes[i].costheta;
1070 planes[i].deltaY = planes[i].deltaW*planes[i].sintheta;
1075 cout <<
"GeomSvc: loaded millepede-based alignment parameters from " << alignmentFile_mille << endl;
1079 planes[i].resolution = rc->get_DoubleFlag(
"RESOLUTION_FACTOR")*0.5*(planes[i].resolution + planes[i+1].resolution);
1080 planes[i+1].resolution = planes[i].resolution;
1085 cout <<
"GeomSvc: failed to load mullepede-based alignment parameters from " << alignmentFile_mille << endl;
1088 _align_mille.close();
1093 using namespace std;
1096 _cali_file.open(calibrationFile.c_str(), ios::in);
1099 int iBin, nBin, detectorID;
1100 double tmin_temp, tmax_temp;
1101 double R[500], T[500];
1104 calibration_loaded =
true;
1106 while(_cali_file.getline(buf, 100))
1108 istringstream detector_info(buf);
1109 detector_info >> detectorID >> nBin >> tmin_temp >> tmax_temp;
1110 planes[detectorID].tmax = tmax_temp;
1111 planes[detectorID].tmin = tmin_temp;
1113 for(
int i = 0; i < nBin; i++)
1115 _cali_file.getline(buf, 100);
1116 istringstream cali_line(buf);
1118 cali_line >> iBin >> T[i] >> R[i];
1121 if(planes[detectorID].rtprofile !=
NULL)
delete planes[detectorID].rtprofile;
1122 if(nBin > 0) planes[detectorID].rtprofile =
new TSpline3(
getDetectorName(detectorID).c_str(), T, R, nBin,
"b1e1");
1124 cout <<
"GeomSvc: loaded calibration parameters from " << calibrationFile << endl;
1131 return tdcTime > planes[detectorID].
tmin && tdcTime < planes[detectorID].
tmax;
1136 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
1139 int detectorID = (*iter).second;
1140 std::cout <<
" ====================== " << (*iter).first <<
" ==================== " << std::endl;
1141 for(
int i = 1; i <= planes[detectorID].
nElements; ++i)
1143 std::cout << std::setw(6) << std::setiosflags(std::ios::right) << detectorID;
1144 std::cout << std::setw(6) << std::setiosflags(std::ios::right) << (*iter).first;
1145 std::cout << std::setw(6) << std::setiosflags(std::ios::right) << i;
1146 std::cout << std::setw(10) << std::setiosflags(std::ios::right) << map_wirePosition[std::make_pair(detectorID, i)];
1147 std::cout << std::setw(10) << std::setiosflags(std::ios::right) << map_wirePosition[std::make_pair(detectorID, i)] - 0.5*planes[detectorID].
cellWidth;
1148 std::cout << std::setw(10) << std::setiosflags(std::ios::right) << map_wirePosition[std::make_pair(detectorID, i)] + 0.5*planes[detectorID].
cellWidth;
1149 std::cout << std::endl;
1156 std::cout <<
"detectorID DetectorName offset_pos offset_z offset_phi" << std::endl;
1157 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
1160 std::cout << iter->second <<
" " << iter->first <<
" " << planes[(*iter).second].
deltaW <<
" " << planes[(*iter).second].
deltaZ <<
" " << planes[(*iter).second].
rotZ << std::endl;
1166 std::cout <<
"detectorID detectorName planeType Spacing Xoffset overlap width height nElement angleFromVertical z0 x0 y0 deltaW" << std::endl;
1167 for(std::map<std::string, int>::iterator iter = map_detectorID.begin(); iter != map_detectorID.end(); ++iter)
1170 std::cout << planes[iter->second] << std::endl;
void loadMilleAlignment(const std::string &alignmentFile_mille)
std::string getDetectorName(const int &detectorID) const
void printAlignPar()
Debugging print of the content.
double getWirePosition(int elementID) const
void init()
Initialization, either from MySQL or from ascii file.
double intercept(double tx, double ty, double x0_track, double y0_track) const
std::vector< double > elementPos
double getW(double x, double y) const
TVectorD getEndPoint(int elementID, int sign=-1) const
void get2DBoxSize(int detectorID, int elementID, double &x_min, double &x_max, double &y_min, double &y_max)
int run(const int nEvents=1)
static recoConsts * instance()
bool isInTime(int detectorID, double tdcTime)
bool isInElement(int detectorID, int elementID, double x, double y, double tolr=0.)
std::basic_ostream< E, T > & operator<<(std::basic_ostream< E, T > &os, shared_ptr< Y > const &p)
void close()
Close the geometry service before exit or starting a new one.
void loadCalibration(const std::string &calibrateFile)
bool findPatternInDetector(int detectorID, std::string pattern)
double getDCA(int detectorID, int elementID, double tx, double ty, double x0, double y0)
bool isInKMAG(double x, double y)
double getInterceptionFast(int detectorID, double tx, double ty, double x0, double y0) const
std::vector< int > getDetectorIDs(std::string pattern)
static GeomSvc * instance()
singlton instance
void toLocalDetectorName(std::string &detectorName, int &eID)
Convert the official detectorName to local detectorName.
int getExpElementID(int detectorID, double pos_exp)
void getEndPoints(int detectorID, int elementID, TVectorD &ep1, TVectorD &ep2)
void getMeasurement(int detectorID, int elementID, double &measurement, double &dmeasurement)
Convert the detectorID and elementID to the actual hit position.
#define nDarkPhotonPlanes
bool isInPlane(int detectorID, double x, double y)
See if a point is in a plane.
void getWireEndPoints(int detectorID, int elementID, double &x_min, double &x_max, double &y_min, double &y_max)
double getDriftDistance(int detectorID, double tdcTime)
void loadAlignment(const std::string &alignmentFile_chamber, const std::string &alignmentFile_hodo, const std::string &alignmentFile_prop)
int getHodoStation(const int detectorID) const