15 std::vector<std::string> usedTaggers;
16 std::vector<std::string> usedModules;
17 std::vector<std::string> usedStrips;
24 for(
auto const& auxDet : auxDets){
28 for(
size_t i = 0; i < auxDet.NSensitiveVolume(); i++){
32 std::set<std::string> volNames = {auxDetSensitive.
TotalVolume()->GetName()};
36 std::string
path =
"";
37 for (
size_t inode = 0; inode < paths.at(0).size(); inode++){
38 path += paths.at(0).at(inode)->GetName();
39 if(inode < paths.at(0).size() - 1){
46 manager->cd(path.c_str());
49 TGeoNode* nodeStrip = manager->GetCurrentNode();
50 TGeoNode* nodeModule = manager->GetMother(2);
51 TGeoNode* nodeTagger = manager->GetMother(3);
52 TGeoNode* nodeDet = manager->GetMother(4);
55 std::string taggerName = nodeTagger->GetName();
56 if(std::find(usedTaggers.begin(), usedTaggers.end(), taggerName) == usedTaggers.end()){
57 usedTaggers.push_back(taggerName);
60 double halfWidth = ((TGeoBBox*)nodeTagger->GetVolume()->GetShape())->GetDX();
61 double halfHeight = ((TGeoBBox*)nodeTagger->GetVolume()->GetShape())->GetDY();
62 double halfLength = ((TGeoBBox*)nodeTagger->GetVolume()->GetShape())->GetDZ()/2;
65 double limits[3] = {halfWidth, halfHeight, halfLength};
67 nodeTagger->LocalToMaster(limits, limitsDet);
68 double limitsWorld[3];
69 nodeDet->LocalToMaster(limitsDet, limitsWorld);
71 double limits2[3] = {-halfWidth, -halfHeight, -halfLength};
73 nodeTagger->LocalToMaster(limits2, limitsDet2);
74 double limitsWorld2[3];
75 nodeDet->LocalToMaster(limitsDet2, limitsWorld2);
79 tagger.
name = taggerName;
80 tagger.
minX = std::min(limitsWorld[0], limitsWorld2[0]);
81 tagger.
maxX = std::max(limitsWorld[0], limitsWorld2[0]);
82 tagger.
minY = std::min(limitsWorld[1], limitsWorld2[1]);
83 tagger.
maxY = std::max(limitsWorld[1], limitsWorld2[1]);
84 tagger.
minZ = std::min(limitsWorld[2], limitsWorld2[2]);
85 tagger.
maxZ = std::max(limitsWorld[2], limitsWorld2[2]);
91 std::string moduleName = nodeModule->GetName();
92 if(std::find(usedModules.begin(), usedModules.end(), moduleName) == usedModules.end()){
93 usedModules.push_back(moduleName);
97 double halfWidth = auxDet.HalfWidth1();
98 double halfHeight = auxDet.HalfHeight();
99 double halfLength = auxDet.Length()/2;
102 double limits[3] = {halfWidth, halfHeight, halfLength};
103 double limitsWorld[3];
104 auxDet.LocalToWorld(limits, limitsWorld);
106 double limits2[3] = {-halfWidth, -halfHeight, -halfLength};
107 double limitsWorld2[3];
108 auxDet.LocalToWorld(limits2, limitsWorld2);
111 double origin[3] = {0, 0, 0};
112 double modulePosMother[3];
113 nodeModule->LocalToMaster(origin, modulePosMother);
114 size_t planeID = (modulePosMother[2] > 0);
116 bool top = (planeID == 1) ? (modulePosMother[1] > 0) : (modulePosMother[0] < 0);
120 module.
name = moduleName;
122 module.
minX = std::min(limitsWorld[0], limitsWorld2[0]);
123 module.
maxX = std::max(limitsWorld[0], limitsWorld2[0]);
124 module.
minY = std::min(limitsWorld[1], limitsWorld2[1]);
125 module.
maxY = std::max(limitsWorld[1], limitsWorld2[1]);
126 module.
minZ = std::min(limitsWorld[2], limitsWorld2[2]);
127 module.
maxZ = std::max(limitsWorld[2], limitsWorld2[2]);
128 module.
normal = auxDet.GetNormalVector();
132 module.
tagger = taggerName;
137 std::string stripName = nodeStrip->GetName();
138 if(std::find(usedStrips.begin(), usedStrips.end(), stripName) == usedStrips.end()){
139 usedStrips.push_back(stripName);
142 double halfWidth = auxDetSensitive.
HalfWidth1();
143 double halfHeight = auxDetSensitive.
HalfHeight();
144 double halfLength = auxDetSensitive.
Length()/2;
147 double limits[3] = {halfWidth, halfHeight, halfLength};
148 double limitsWorld[3];
151 double limits2[3] = {-halfWidth, -halfHeight, -halfLength};
152 double limitsWorld2[3];
157 strip.
name = stripName;
159 strip.
minX = std::min(limitsWorld[0], limitsWorld2[0]);
160 strip.
maxX = std::max(limitsWorld[0], limitsWorld2[0]);
161 strip.
minY = std::min(limitsWorld[1], limitsWorld2[1]);
162 strip.
maxY = std::max(limitsWorld[1], limitsWorld2[1]);
163 strip.
minZ = std::min(limitsWorld[2], limitsWorld2[2]);
164 strip.
maxZ = std::max(limitsWorld[2], limitsWorld2[2]);
166 strip.
width = halfWidth * 2.;
168 strip.
module = moduleName;
171 uint32_t channel0 = 32 * ad_i + 2 * sv_i + 0;
172 uint32_t channel1 = 32 * ad_i + 2 * sv_i + 1;
174 double sipm0X = -halfWidth;
175 double sipm1X = halfWidth;
177 double sipmY = halfHeight;
178 if(!
fModules[moduleName].
top) sipmY = - halfHeight;
179 double sipm0XYZ[3] = {sipm0X, sipmY, 0};
180 double sipm0XYZWorld[3];
185 sipm0.
x = sipm0XYZWorld[0];
186 sipm0.
y = sipm0XYZWorld[1];
187 sipm0.
z = sipm0XYZWorld[2];
188 sipm0.
strip = stripName;
192 double sipm1XYZ[3] = {sipm1X, sipmY, 0};
193 double sipm1XYZWorld[3];
198 sipm1.
x = sipm1XYZWorld[0];
199 sipm1.
y = sipm1XYZWorld[1];
200 sipm1.
z = sipm1XYZWorld[2];
201 sipm1.
strip = stripName;
205 strip.
sipms = std::make_pair(channel0, channel1);
219 std::string taggerName =
module.second.tagger;
220 std::string moduleName =
module.second.name;
234 std::vector<double>
limits;
236 std::vector<double> minXs;
237 std::vector<double> minYs;
238 std::vector<double> minZs;
239 std::vector<double> maxXs;
240 std::vector<double> maxYs;
241 std::vector<double> maxZs;
243 minXs.push_back(
tagger.second.minX);
244 minYs.push_back(
tagger.second.minY);
245 minZs.push_back(
tagger.second.minZ);
246 maxXs.push_back(
tagger.second.maxX);
247 maxYs.push_back(
tagger.second.maxY);
248 maxZs.push_back(
tagger.second.maxZ);
250 limits.push_back(*std::min_element(minXs.begin(), minXs.end()));
251 limits.push_back(*std::min_element(minYs.begin(), minYs.end()));
252 limits.push_back(*std::min_element(minZs.begin(), minZs.end()));
253 limits.push_back(*std::max_element(maxXs.begin(), maxXs.end()));
254 limits.push_back(*std::max_element(maxYs.begin(), maxYs.end()));
255 limits.push_back(*std::max_element(maxZs.begin(), maxZs.end()));
322 nullTagger.
null =
true;
330 if(tagger_i == index)
return tagger.second;
334 nullTagger.
null =
true;
346 nullModule.
null =
true;
354 if(module_i == index)
return module.second;
358 nullModule.
null =
true;
365 nullModule.
null =
true;
368 if(tagger.
null)
return nullModule;
372 if(module_i == index)
return module.second;
383 if(stripName ==
strip.first)
return strip.second;
386 nullStrip.
null =
true;
394 if(strip_i == index)
return strip.second;
398 nullStrip.
null =
true;
405 nullStrip.
null =
true;
408 if(module.
null)
return nullStrip;
412 if(strip_i == index)
return strip.second;
421 nullStrip.
null =
true;
424 if(module.
null)
return nullStrip;
428 if(strip_i == index)
return strip.second;
448 for(
auto const& sipm :
fSipms){
449 if(sipm.second.channel == channel){
450 return sipm.second.strip;
462 2*
fStrips.at(stripName).sensitiveVolumeID);
465 double halfHeight = sensitiveGeo.HalfHeight();
466 double halfLength = sensitiveGeo.HalfLength();
469 double l1[3] = {-halfWidth + x + ex, halfHeight, halfLength};
471 sensitiveGeo.LocalToWorld(l1, w1);
474 double l2[3] = {-halfWidth + x - ex, -halfHeight, -halfLength};
476 sensitiveGeo.LocalToWorld(l2, w2);
479 std::vector<double>
limits = {std::min(w1[0],w2[0]), std::max(w1[0],w2[0]),
480 std::min(w1[1],w2[1]), std::max(w1[1],w2[1]),
481 std::min(w1[2],w2[2]), std::max(w1[2],w2[2])};
487 for(
auto const& sipm :
fSipms){
488 if(sipm.second.channel == channel){
489 geo::Point_t position {sipm.second.x, sipm.second.y, sipm.second.z};
500 if(stripName ==
strip.first)
return strip.second.sipms;
502 return std::make_pair(-99999, -99999);
509 for(
auto const& sipm :
fSipms){
510 if(sipm.second.channel == channel){
511 geo::Point_t pos {sipm.second.x, sipm.second.y, sipm.second.z};
513 int otherChannel = channel + 1;
514 if(channel % 2) otherChannel = channel - 1;
516 if(fSipms.at(otherChannel).x != pos.X()) distance = position.X() - pos.X();
517 if(fSipms.at(otherChannel).y != pos.Y()) distance = position.Y() - pos.Y();
518 if(fSipms.at(otherChannel).z != pos.Z()) distance = position.Z() - pos.Z();
537 if(stripName ==
strip.first){
543 if(xdiff > ydiff && xdiff > zdiff) distance = position.X() - pos.X();
544 if(ydiff > xdiff && ydiff > zdiff) distance = position.Y() - pos.Y();
545 if(zdiff > xdiff && zdiff > ydiff) distance = position.Z() - pos.Z();
561 if(point.X() > limits[0] && point.Y() > limits[1] && point.Z() > limits[2]
562 && point.X() < limits[3] && point.Y() < limits[4] && point.Z() < limits[5]){
576 if(tagger.
null)
return false;
577 double x = point.X();
578 double y = point.Y();
579 double z = point.Z();
581 double ymin = tagger.
minY;
582 double zmin = tagger.
minZ;
583 double xmax = tagger.
maxX;
584 double ymax = tagger.
maxY;
585 double zmax = tagger.
maxZ;
586 if(x > xmin && x < xmax && y > ymin && y < ymax && z > zmin && z < zmax)
return true;
598 if(module.
null)
return false;
599 double x = point.X();
600 double y = point.Y();
601 double z = point.Z();
603 double ymin = module.
minY;
604 double zmin = module.
minZ;
605 double xmax = module.
maxX;
606 double ymax = module.
maxY;
607 double zmax = module.
maxZ;
612 if(x > xmin && x < xmax && y > ymin && y < ymax && z > zmin && z < zmax)
return true;
624 if(strip.
null)
return false;
625 double x = point.X();
626 double y = point.Y();
627 double z = point.Z();
629 double ymin = strip.
minY;
630 double zmin = strip.
minZ;
631 double xmax = strip.
maxX;
632 double ymax = strip.
maxY;
633 double zmax = strip.
maxZ;
638 if(x > xmin && x < xmax && y > ymin && y < ymax && z > zmin && z < zmax)
return true;
646 double minX = std::max(module1.
minX, module2.
minX);
647 double maxX = std::min(module1.
maxX, module2.
maxX);
648 double minY = std::max(module1.
minY, module2.
minY);
649 double maxY = std::min(module1.
maxY, module2.
maxY);
650 double minZ = std::max(module1.
minZ, module2.
minZ);
651 double maxZ = std::min(module1.
maxZ, module2.
maxZ);
654 if ((minX<maxX && minY<maxY) || (minX<maxX && minZ<maxZ) || (minY<maxY && minZ<maxZ))
return true;
663 size_t planeID = module.
planeID;
665 std::string taggerName = module.
tagger;
667 for(
auto const& module2 :
fTaggers[taggerName].modules){
669 if(module2.second.planeID == planeID)
continue;
681 auto const& strip1 =
fStrips.at(strip1Name);
682 auto const& strip2 =
fStrips.at(strip2Name);
684 double minX = std::max(strip1.minX, strip2.minX);
685 double maxX = std::min(strip1.maxX, strip2.maxY);
686 double minY = std::max(strip1.minY, strip2.minY);
687 double maxY = std::min(strip1.maxY, strip2.maxY);
688 double minZ = std::max(strip1.minZ, strip2.minZ);
689 double maxZ = std::min(strip1.maxZ, strip2.maxZ);
691 std::vector<double> null = {-99999, -99999, -99999, -99999, -99999, -99999};
692 std::vector<double>
overlap = {minX, maxX, minY, maxY, minZ, maxZ};
695 if ((minX<maxX && minY<maxY) || (minX<maxX && minZ<maxZ) || (minY<maxY && minZ<maxZ))
return overlap;
712 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
713 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
727 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
728 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
746 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
747 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
750 if(i == particle.NumberTrajectoryPoints()-1)
continue;
751 geo::Point_t next {particle.Vx(i+1), particle.Vy(i+1), particle.Vz(i+1)};
752 geo::Point_t mid {(point.X()+next.X())/2, (point.Y()+next.Y())/2, (point.Z()+next.Z())/2};
762 if(i == particle.NumberTrajectoryPoints()-1)
continue;
763 geo::Point_t next {particle.Vx(i+1), particle.Vy(i+1), particle.Vz(i+1)};
764 geo::Point_t mid {(point.X()+next.X())/2, (point.Y()+next.Y())/2, (point.Z()+next.Z())/2};
774 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
775 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
779 if(i == particle.NumberTrajectoryPoints()-1)
continue;
780 geo::Point_t next {particle.Vx(i+1), particle.Vy(i+1), particle.Vz(i+1)};
781 geo::Point_t mid {(point.X()+next.X())/2, (point.Y()+next.Y())/2, (point.Z()+next.Z())/2};
799 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
800 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
802 if(i == particle.NumberTrajectoryPoints()-1)
continue;
803 geo::Point_t next {particle.Vx(i+1), particle.Vy(i+1), particle.Vz(i+1)};
804 geo::Point_t mid {(point.X()+next.X())/2, (point.Y()+next.Y())/2, (point.Z()+next.Z())/2};
813 if(i == particle.NumberTrajectoryPoints()-1)
continue;
814 geo::Point_t next {particle.Vx(i+1), particle.Vy(i+1), particle.Vz(i+1)};
815 geo::Point_t mid {(point.X()+next.X())/2, (point.Y()+next.Y())/2, (point.Z()+next.Z())/2};
825 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
826 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
830 if(i == particle.NumberTrajectoryPoints()-1)
continue;
831 geo::Point_t next {particle.Vx(i+1), particle.Vy(i+1), particle.Vz(i+1)};
832 geo::Point_t mid {(point.X()+next.X())/2, (point.Y()+next.Y())/2, (point.Z()+next.Z())/2};
842 std::vector<std::string> stripNames;
845 for(
auto const& module : tagger.second.
modules){
847 for(
auto const& strip : module.second.
strips){
849 if(std::find(stripNames.begin(), stripNames.end(), strip.first) != stripNames.end())
continue;
850 stripNames.push_back(strip.first);
862 TVector3 normal (0,0,0);
863 for(
auto const& module :
GetTagger(taggerName).modules){
864 normal.SetXYZ(module.second.
normal.X(), module.second.
normal.Y(), module.second.
normal.Z());
868 if(normal.X()<0.5 && normal.X()>-0.5) normal.SetX(0);
869 if(normal.Y()<0.5 && normal.Y()>-0.5) normal.SetY(0);
870 if(normal.Z()<0.5 && normal.Z()>-0.5) normal.SetZ(0);
879 TVector3 start (particle.Vx(), particle.Vy(), particle.Vz());
880 TVector3
end (particle.EndX(), particle.EndY(), particle.EndZ());
881 TVector3 diff =
end - start;
883 if(normal.X() == 1 && start.X() >
end.X()) diff = start -
end;
884 if(normal.X() == -1 && start.X() <
end.X()) diff = start -
end;
885 if(normal.Y() == 1 && start.Y() >
end.Y()) diff = start -
end;
886 if(normal.Y() == -1 && start.Y() <
end.Y()) diff = start -
end;
887 if(normal.Z() == 1 && start.Z() >
end.Z()) diff = start -
end;
888 if(normal.Z() == -1 && start.Z() <
end.Z()) diff = start -
end;
890 return normal.Angle(diff);
898 bool startOutside =
false;
899 bool endOutside =
false;
901 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
902 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
906 else if(i == 0) startOutside =
true;
907 else if(i == particle.NumberTrajectoryPoints()-1) endOutside =
true;
909 if(enters && (startOutside || endOutside))
return true;
917 bool startOutside =
false;
918 bool endOutside =
false;
920 for(
size_t i = 0; i < particle.NumberTrajectoryPoints(); i++){
921 geo::Point_t point {particle.Vx(i), particle.Vy(i), particle.Vz(i)};
925 else if(i == 0) startOutside =
true;
926 else if(i == particle.NumberTrajectoryPoints()-1) endOutside =
true;
928 if(startOutside && enters && endOutside)
return true;
938 std::vector<std::string> crossedModules;
939 for(
auto const& module :
fTaggers[taggerName].modules){
941 if(crossPoint.X() != -99999) crossedModules.push_back(module.second.
name);
945 for(
size_t i = 0; i < crossedModules.size(); i++){
948 for(
size_t j = i; j < crossedModules.size(); j++){
geo::Point_t ModuleCrossingPoint(std::string moduleName, const simb::MCParticle &particle)
process_name opflash particleana ie ie ie z
bool CrossesStrip(const CRTStripGeo &strip, const simb::MCParticle &particle)
std::map< std::string, CRTModuleGeo > fModules
geo::Point_t ChannelToSipmPosition(size_t channel) const
finds tracks best matching by with limits
size_t NumTaggers() const
bool StripHasOverlap(std::string stripName)
const geo::GeometryCore * geometry
process_name opflash particleana ie x
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
bool CrossesVolume(const simb::MCParticle &particle)
bool IsInsideModule(std::string moduleName, geo::Point_t point)
double AngleToTagger(std::string taggerName, const simb::MCParticle &particle)
bool HasOverlap(const CRTModuleGeo &module)
std::map< std::string, CRTTaggerGeo > fTaggers
std::string GetTaggerName(std::string name) const
bool IsInsideStrip(std::string stripName, geo::Point_t point)
double HalfWidth1() const
Description of geometry of one set of auxiliary detectors.
TGeoManager * ROOTGeoManager() const
Access to the ROOT geometry description manager.
std::map< std::string, CRTModuleGeo > modules
std::map< std::string, CRTStripGeo > fStrips
std::map< int, CRTSipmGeo > fSipms
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
geo::Point_t TaggerCrossingPoint(std::string taggerName, const simb::MCParticle &particle)
double HalfHeight() const
std::pair< int, int > sipms
process_name opflash particleana ie ie y
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
bool IsInsideTagger(std::string taggerName, geo::Point_t point)
const AuxDetSensitiveGeo & ChannelToAuxDetSensitive(std::string const &auxDetName, uint32_t const &channel) const
bool IsInsideCRT(TVector3 point)
const TGeoVolume * TotalVolume() const
auto end(FixedBins< T, C > const &) noexcept
CRTModuleGeo GetModule(std::string moduleName) const
std::string ChannelToStripName(size_t channel) const
std::vector< double > StripLimitsWithChargeSharing(std::string stripName, double x, double ex)
Description of geometry of one entire detector.
bool EntersVolume(const simb::MCParticle &particle)
std::map< std::string, CRTStripGeo > strips
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
double DistanceDownStrip(geo::Point_t position, std::string stripName) const
double DistanceBetweenSipms(geo::Point_t position, size_t channel) const
bool CrossesTagger(const CRTTaggerGeo &tagger, const simb::MCParticle &particle)
geo::GeometryCore const * fGeometryService
CRTTaggerGeo GetTagger(std::string taggerName) const
std::pair< int, int > GetStripSipmChannels(std::string stripName) const
std::vector< AuxDetGeo > const & AuxDetGeoVec() const
Returns the full list of pointer to the auxiliary detectors.
geo::Point_t StripCrossingPoint(std::string stripName, const simb::MCParticle &particle)
const geo::AuxDetGeometryCore * fAuxDetGeoCore
const TGeoVolume * TotalVolume() const
bool CheckOverlap(const CRTModuleGeo &module1, const CRTModuleGeo &module2)
CRTStripGeo GetStrip(std::string stripName) const
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.
std::vector< double > StripOverlap(std::string strip1Name, std::string strip2Name)
Vector cross(Vector const &a, Vector const &b)
Return cross product of two vectors.
void LocalToWorld(const double *auxdet, double *world) const
Transform point from local auxiliary detector frame to world frame.
bool ValidCrossingPoint(std::string taggerName, const simb::MCParticle &particle)
std::vector< double > CRTLimits() const
std::vector< std::string > CrossesStrips(const simb::MCParticle &particle)
bool CrossesModule(const CRTModuleGeo &module, const simb::MCParticle &particle)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
size_t NumModules() const
constexpr Point origin()
Returns a origin position with a point of the specified type.