1 #ifndef IC_CRTCOMMONUTILS_CC
2 #define IC_CRTCOMMONUTILS_CC
20 throw cet::exception(
"CRTCommonUtils::GetAuxDetType")
21 <<
"unknown AuxDetID passed to function";
41 throw cet::exception(
"CRTCommonUtils::GetAuxDetRegion")
42 <<
"unknown AuxDetID passed to function";
50 if(reg ==
"Top")
return 30;
51 if(reg ==
"RimWest")
return 31;
52 if(reg ==
"RimEast")
return 32;
53 if(reg ==
"RimSouth")
return 33;
54 if(reg ==
"RimNorth")
return 34;
55 if(reg ==
"WestSouth")
return 40;
56 if(reg ==
"WestCenter")
return 41;
57 if(reg ==
"WestNorth")
return 42;
58 if(reg ==
"EastSouth")
return 43;
59 if(reg ==
"EastCenter")
return 44;
60 if(reg ==
"EastNorth")
return 45;
61 if(reg ==
"South")
return 46;
62 if(reg ==
"North")
return 47;
63 if(reg ==
"Bottom")
return 50;
64 mf::LogError(
"CRT") <<
"region not found!" <<
'\n';
101 return "Region not found!";
108 if(name==
"Top"||name==
"RimWest"||name==
"RimEast"||name==
"RimSouth"||name==
"RimNorth")
111 if(name==
"WestSouth"||name==
"WestCenter"||name==
"WestNorth"||
112 name==
"EastSouth"||name==
"EastCenter"||name==
"EastNorth"||
113 name==
"North"||name==
"South")
120 throw cet::exception(
"CRTCommonUtils::GetRegTypeFromRegName")
121 <<
"passed region name not recognized!" <<
'\n';
145 throw cet::exception(
"CRTCommonUtils::ADToMac")
146 <<
"unknown AuxDetID passed to function";
150 return std::make_pair(febs[0].
first,febs[1].first);
152 return std::make_pair(febs[0].first,febs[0].first);
158 throw cet::exception(
"CRTCommonUtils::ADMacToChanGroup")
159 <<
"unknown AuxDetID passed to function";
167 throw cet::exception(
"CRTCommonUtils::NFeb")
168 <<
"unknown AuxDetID passed to function";
176 throw cet::exception(
"CRTCommonUtils::MacToRegion")
177 <<
"unknown mac passed to function";
186 throw cet::exception(
"CRTCommonUtils::MacToType")
187 <<
"unknown mac passed to function";
196 throw cet::exception(
"CRTCommonUtils::MacToType")
197 <<
"unknown mac passed to function";
213 if (type==
'd')
return chan;
214 if (type==
'c')
return chan/2;
215 if (type==
'm')
return (chan % 10)*2;
236 if(type==
'm') pos = chan/10 + 1;
241 throw cet::exception(
"CRTCommonUtils::MacToAuxDetID")
242 <<
"unknown mac passed to function";
249 throw cet::exception(
"CRTCommonUtils::ADMacToChanGroup")
250 <<
"unknown AuxDetID passed to function";
279 throw cet::exception(
"CRTCommonUtils::MacToAuxDetID")
280 <<
"AuxDetID not found!";
293 TLorentzVector v(x,y,z,t);
301 double dx=0., dy=0., dz=0.;
305 return sqrt(dx*dx+dy*dy+dz*dz);
317 std::set<string> volNames = { adsGeo.TotalVolume()->GetName() };
320 std::string
path =
"";
321 for (
size_t inode=0; inode<paths.at(0).size(); inode++) {
322 path += paths.at(0).at(inode)->GetName();
323 if (inode < paths.at(0).size() - 1) {
328 manager->cd(path.c_str());
329 TGeoNode* nodeStrip = manager->GetCurrentNode();
330 TGeoNode* nodeInner = manager->GetMother(1);
331 TGeoNode* nodeModule = manager->GetMother(2);
332 double origin[3] = {0, 0, 0};
333 double modulePosMother[3];
334 double stripPosMother[3];
335 double stripPosModule[3];
337 nodeModule->LocalToMaster(origin, modulePosMother);
338 nodeStrip->LocalToMaster(origin, stripPosMother);
339 nodeInner->LocalToMaster(stripPosMother,stripPosModule);
342 if ( type ==
'c' || type ==
'd' )
343 layer = (stripPosModule[1] > 0);
348 if ( region >=40 && region <=45 ) {
349 layer = ( modulePosMother[0]>0 );
353 layer = ( modulePosMother[2]> 0 );
357 auto const& adsGeo = adGeo.SensitiveVolume(0);
359 if(adsGeo.Length() == 400 || adsGeo.Length() == 485.15)
379 std::set<string> volNames = { adsGeo.TotalVolume()->GetName() };
382 std::string
path =
"";
383 for (
size_t inode=0; inode<paths.at(0).size(); inode++) {
384 path += paths.at(0).at(inode)->GetName();
385 if (inode < paths.at(0).size() - 1) {
390 manager->cd(path.c_str());
391 TGeoNode* nodeStrip = manager->GetCurrentNode();
392 TGeoNode* nodeInner = manager->GetMother(1);
393 TGeoNode* nodeModule = manager->GetMother(2);
394 double origin[3] = {0, 0, 0};
395 double modulePosMother[3];
396 double stripPosMother[3];
397 double stripPosModule[3];
399 nodeModule->LocalToMaster(origin, modulePosMother);
400 nodeStrip->LocalToMaster(origin, stripPosMother);
401 nodeInner->LocalToMaster(stripPosMother,stripPosModule);
404 if ( type ==
'c' || type ==
'd' )
405 layer = (stripPosModule[1] > 0);
410 if ( region >=40 && region <=45 ) {
411 layer = ( modulePosMother[0]>0 );
415 layer = ( modulePosMother[2]> 0 );
420 if(adsGeo.Length() == 400 || adsGeo.Length() == 485.15)
439 mf::LogError(
"CRTCommonUtils") <<
"non-MINOS module provided to GetMINOSLayerID";
443 std::set<string> volNames = { adGeo.TotalVolume()->GetName() };
446 std::string
path =
"";
447 for (
size_t inode=0; inode<paths.at(0).size(); inode++) {
448 path += paths.at(0).at(inode)->GetName();
449 if (inode < paths.at(0).size() - 1) {
454 manager->cd(path.c_str());
455 TGeoNode* nodeModule = manager->GetCurrentNode();
456 double origin[3] = {0, 0, 0};
457 double modulePosMother[3];
458 nodeModule->LocalToMaster(origin, modulePosMother);
461 if ( region >=40 && region <=45 ) {
462 layer = ( modulePosMother[0]>0 );
466 layer = ( modulePosMother[2]> 0 );
470 auto const& adsGeo = adGeo.SensitiveVolume(0);
471 if(adsGeo.Length() == 400 || adsGeo.Length() == 485.15)
479 mf::LogError(
"CRTCommonUtils::GetMINOSLayerID")
480 <<
"layer ID not set!";
491 TVector3 coords(0.,0.,0.);
495 auto const& adsGeo = adGeo.SensitiveVolume(adsid);
497 double origin[3] = {0,0,0};
498 double stripPosWorld[3], modPos[3];
500 adsGeo.LocalToWorld(origin,stripPosWorld);
501 adGeo.WorldToLocal(stripPosWorld,modPos);
503 coords.SetXYZ(modPos[0],modPos[1],modPos[2]);
511 TVector3 coords(0.,0.,0.);
515 auto const& adsGeo = adGeo.SensitiveVolume(adsid);
517 double origin[3] = {0,0,0};
518 double stripPosWorld[3];
520 adsGeo.LocalToWorld(origin,stripPosWorld);
522 coords.SetXYZ(stripPosWorld[0],stripPosWorld[1],stripPosWorld[2]);
533 cet::search_path searchPath(
"FW_SEARCH_PATH");
534 searchPath.find_file(
"feb_map.txt",fullFileName);
541 throw cet::exception(
"CRTDetSim::FillFebMap")
542 <<
"Unable to find/open file 'feb_map.txt'" << std::endl;
549 while(getline(fin,line)) {
551 std::stringstream
s(line);
552 while (std::getline(s, word,
',')) {
555 int mod = (size_t)std::stoi(row[0]);
556 uint8_t mac5 = (uint8_t)std::stoi(row[1]);
557 int pos = std::stoi(row[2]);
563 mac5 = (uint8_t)std::stoi(row[3]);
583 switch(adGeo.NSensitiveVolume()) {
596 string name = adGeo.TotalVolume()->GetName();
606 string base(
"volAuxDet_");
610 case 'c' : base+=
"CERN";
break;
611 case 'd' : base+=
"DC";
break;
612 case 'm' : base+=
"MINOS";
break;
614 throw cet::exception(
"CRTCommonUtils::Constructor::AuxDetNameToRegion")
615 <<
"AuxDet type not set!";
617 base+=
"_module_###_";
622 string region(name.substr(base.length(),name.length()));
623 if( region.find(
"_")==string::npos)
627 return region.substr(region.find(
"_")+1,region.length());
635 double world[3],
local[3];
636 world[0] = point.X();
637 world[1] = point.Y();
638 world[2] = point.Z();
640 adGeo.WorldToLocal(world,local);
641 TVector3 localpoint(local[0],local[1],local[2]);
644 localpoint.SetX( 8.*(localpoint.X()/adGeo.HalfWidth1()+1.));
646 localpoint.SetZ( 8.*(localpoint.Z()/adGeo.HalfWidth1()+1.));
651 localpoint.SetY(
ADToChanGroup(adid)*10.*(localpoint.Y()/adGeo.HalfHeight()+1.));
652 localpoint.SetZ(localpoint.Z());
656 localpoint.SetX(32.5*(localpoint.X()/adGeo.HalfWidth1()+1.));
658 localpoint.SetZ(localpoint.Z());
669 TVector3
end = start + direction;
670 double denominator = direction.Mag();
671 double numerator = (pos - start).Cross(pos - end).Mag();
672 return numerator/denominator;
708 return std::min(std::min(dist1, dist2), std::min(dist3, dist4));
717 double smallNum = 0.00001;
720 TVector3 direction1 = end1 - start1;
722 TVector3 direction2 = end2 - start2;
724 TVector3 u = direction1;
725 TVector3 v = direction2;
726 TVector3
w = start1 - start2;
733 double D = a * c - b * b;
734 double sc, sN, sD = D;
735 double tc, tN, tD = D;
745 sN = (b * e - c * d)/D;
746 tN = (a * e - b * d)/D;
759 sc = (
std::abs(sN) < smallNum ? 0.0 : sN / sD);
760 tc = (
std::abs(tN) < smallNum ? 0.0 : tN / tD);
762 TVector3 dP = w + (sc * u) - (tc * v);
772 TVector3
dir = (end - start);
773 TVector3 invDir (1./dir.X(), 1./dir.Y(), 1/dir.Z());
775 double tmin, tmax, tymin, tymax, tzmin, tzmax;
777 TVector3 enter (-99999, -99999, -99999);
778 TVector3
exit (-99999, -99999, -99999);
782 tmin = (min.X() - start.X()) * invDir.X();
783 tmax = (max.X() - start.X()) * invDir.X();
786 tmin = (max.X() - start.X()) * invDir.X();
787 tmax = (min.X() - start.X()) * invDir.X();
792 tymin = (min.Y() - start.Y()) * invDir.Y();
793 tymax = (max.Y() - start.Y()) * invDir.Y();
796 tymin = (max.Y() - start.Y()) * invDir.Y();
797 tymax = (min.Y() - start.Y()) * invDir.Y();
801 if((tmin > tymax) || (tymin > tmax))
return std::make_pair(enter, exit);
804 if(tymin > tmin) tmin = tymin;
807 if(tymax < tmax) tmax = tymax;
811 tzmin = (min.Z() - start.Z()) * invDir.Z();
812 tzmax = (max.Z() - start.Z()) * invDir.Z();
815 tzmin = (max.Z() - start.Z()) * invDir.Z();
816 tzmax = (min.Z() - start.Z()) * invDir.Z();
820 if((tmin > tzmax) || (tzmin > tmax))
return std::make_pair(enter, exit);
823 if(tzmin > tmin) tmin = tzmin;
826 if(tzmax < tmax) tmax = tzmax;
829 double xmin = start.X() + tmin * dir.X();
830 double xmax = start.X() + tmax * dir.X();
831 double ymin = start.Y() + tmin * dir.Y();
832 double ymax = start.Y() + tmax * dir.Y();
833 double zmin = start.Z() + tmin * dir.Z();
834 double zmax = start.Z() + tmax * dir.Z();
837 enter.SetXYZ(xmin, ymin, zmin);
838 exit.SetXYZ(xmax, ymax, zmax);
839 return std::make_pair(enter, exit);
string MacToRegion(uint8_t mac)
float z_err
position uncertainty in z-direction (cm).
std::pair< TVector3, TVector3 > CubeIntersection(TVector3 min, TVector3 max, TVector3 start, TVector3 end)
int ADToChanGroup(size_t adid)
process_name opflash particleana ie ie ie z
float x_err
position uncertainty in x-direction (cm).
int GetMINOSLayerID(size_t adid)
double LengthIDE(sim::AuxDetIDE ide)
Utilities related to art service access.
int GetTypeCodeFromRegion(string name)
TLorentzVector AvgIDEPoint(sim::AuxDetIDE ide)
process_name opflash particleana ie x
AuxDetSensitiveGeo const & SensitiveVolume(size_t sv) const
float y_err
position uncertainty in y-direction (cm).
int GetAuxDetTypeCode(size_t adid)
map< size_t, int > fAuxDetIdToChanGroup
size_t MacToAuxDetID(uint8_t mac, int chan)
TGeoManager * ROOTGeoManager() const
Access to the ROOT geometry description manager.
map< size_t, char > fAuxDetIdToType
int AuxDetRegionNameToNum(string reg)
double SimpleDCA(sbn::crt::CRTHit hit, TVector3 start, TVector3 direction)
float exitY
Exit position Y of particle.
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
Collection of particles crossing one auxiliary detector cell.
float z_pos
position in z-direction (cm).
string GetRegionNameFromNum(int num)
process_name opflash particleana ie ie y
uint32_t AuxDetID() const
float entryT
Entry time of particle.
float exitT
Exit time of particle.
auto end(FixedBins< T, C > const &) noexcept
TVector3 ChanToLocalCoords(const uint8_t mac, const int chan)
pair< uint8_t, uint8_t > ADToMac(size_t adid)
char MacToType(uint8_t mac)
float exitZ
Exit position Z of particle.
char GetRegTypeFromRegName(string name)
char GetAuxDetType(size_t adid)
float entryZ
Entry position Z of particle.
float exitX
Exit position X of particle.
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
map< string, size_t > fNameToAuxDetId
float y_pos
position in y-direction (cm).
int GetLayerID(sim::AuxDetSimChannel const &adsc)
string GetAuxDetRegion(size_t adid)
float entryX
Entry position X of particle.
double LineSegmentDistance(TVector3 start1, TVector3 end1, TVector3 start2, TVector3 end2)
float entryY
Entry position Y of particle.
if &&[-z"$BASH_VERSION"] then echo Attempting to switch to bash bash shellSwitch exit fi &&["$1"= 'shellSwitch'] shift declare a IncludeDirectives for Dir in
uint32_t AuxDetSensitiveID() const
float x_pos
position in x-direction (cm).
TVector3 ChanToWorldCoords(const uint8_t mac, const int chan)
then echo File list $list not found else cat $list while read file do echo $file sed s
MC truth information to make RawDigits and do back tracking.
int MacToTypeCode(uint8_t mac)
int ChannelToAuxDetSensitiveID(uint8_t mac, int chan)
string AuxDetNameToRegion(string name)
map< uint8_t, vector< size_t > > fFebToAuxDetId
std::vector< std::vector< TGeoNode const * > > FindAllVolumePaths(std::set< std::string > const &vol_names) const
Returns paths of all nodes with volumes with the specified names.
double DistToCrtHit(sbn::crt::CRTHit hit, TVector3 start, TVector3 end)
TVector3 WorldToModuleCoords(TVector3 point, size_t adid)
map< size_t, vector< pair< uint8_t, int > > > fAuxDetIdToFeb
map< size_t, string > fAuxDetIdToRegion
geo::GeometryCore const * fGeoService
constexpr Point origin()
Returns a origin position with a point of the specified type.