4 #include "TGeoManager.h"
6 #include "art/Framework/Core/EDFilter.h"
7 #include "art/Framework/Core/ModuleMacros.h"
8 #include "art/Framework/Principal/Event.h"
9 #include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"
15 #include "nusimdata/SimulationBase/MCTruth.h"
21 explicit GenFilter(fhicl::ParameterSet
const & pset);
22 virtual bool filter(art::Event&
e)
override;
56 bool UsesCRTAuxDets(
const simb::MCParticle &particle,
const std::vector<unsigned int> &crt_auxdet_vector);
58 bool RayIntersectsBox(TVector3 ray_origin, TVector3 ray_direction, TVector3 box_min_extent, TVector3 box_max_extent);
59 std::pair<double, double>
XLimitsTPC(
const simb::MCParticle &particle);
60 std::pair<TVector3, TVector3>
CubeIntersection(TVector3 min, TVector3 max, TVector3 start, TVector3
end);
70 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
71 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
72 double rw_ticks =
detProp.ReadOutWindowSize();
73 double inv_samp_freq = clockData.TPCClock().Frequency();
91 fPDGs = pset.get<std::vector<int> >(
"PDGs");
92 fMinMomentums = pset.get<std::vector<double> >(
"MinMomentums");
93 fMaxMomentums = pset.get<std::vector<double> >(
"MaxMomentums");
103 auto mclists = e.getMany< std::vector<simb::MCTruth> >();
105 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e);
107 for (
unsigned int i = 0; i < mclists.size() ; i++){
108 for (
unsigned int j = 0; j < mclists[i]->size(); j++){
110 const art::Ptr<simb::MCTruth> mc_truth(mclists[i],j);
112 for (
int part = 0; part < mc_truth->NParticles(); part++){
113 const simb::MCParticle particle = mc_truth->GetParticle(part);
117 double time = particle.T() * 1e-3;
122 std::pair<double, double> xLimits =
XLimitsTPC(particle);
128 if((minTime < 0 && maxTime < 0) || (minTime > readoutWindow && maxTime > readoutWindow))
continue;
186 double mom = particle.Momentum().Vect().Mag();
187 int pdg = particle.PdgCode();
189 for (
unsigned int particle_i = 0; particle_i <
fPDGs.size(); particle_i++){
196 if (
fPDGs[particle_i]!=0 && pdg!=
fPDGs[particle_i]) matched =
false;
197 if(matched)
return true;
204 art::ServiceHandle<geo::Geometry> geom;
206 for (
unsigned int auxdet_i = 0; auxdet_i < geom->NAuxDets(); auxdet_i++){
209 std::set<std::string> volNames = { volModule->GetName() };
210 std::vector<std::vector<TGeoNode const*> > paths = geom->FindAllVolumePaths(volNames);
212 std::string
path =
"";
213 for (
size_t inode=0; inode<paths.at(0).size(); inode++) {
214 path += paths.at(0).at(inode)->GetName();
215 if (inode < paths.at(0).size() - 1) {
220 TGeoManager* manager = geom->ROOTGeoManager();
221 manager->cd(path.c_str());
223 manager->GetCurrentNode();
224 manager->GetMother(1);
225 TGeoNode* nodeTagger = manager->GetMother(2);
227 std::string taggerName = nodeTagger->GetName();
231 if (taggerName.find(
"TopHigh")!=std::string::npos){
234 else if (taggerName.find(
"TopLow")!=std::string::npos){
237 else if (taggerName.find(
"Bot")!=std::string::npos){
240 else if (taggerName.find(
"South")!=std::string::npos){
243 else if (taggerName.find(
"North")!=std::string::npos){
246 else if (taggerName.find(
"West")!=std::string::npos){
249 else if (taggerName.find(
"East")!=std::string::npos){
253 std::cout <<
"Tagger with name: " << taggerName
254 <<
" does not fit the logic. This should not happen!!!!!!" << std::endl;
271 art::ServiceHandle<geo::Geometry> geom;
273 for (
unsigned int i = 0; i < crt_auxdet_vector.size(); i++){
274 unsigned int auxdet_index = crt_auxdet_vector[i];
287 double particle_position_array[3], particle_direction_array[3], particle_local_position_array[3], particle_local_direction_array[3];
288 particle_position_array[0] = particle.Position(0).X();
289 particle_position_array[1] = particle.Position(0).Y();
290 particle_position_array[2] = particle.Position(0).Z();
291 particle_direction_array[0] = particle.Momentum(0).X()/particle.Momentum(0).Vect().Mag();
292 particle_direction_array[1] = particle.Momentum(0).Y()/particle.Momentum(0).Vect().Mag();
293 particle_direction_array[2] = particle.Momentum(0).Z()/particle.Momentum(0).Vect().Mag();
294 crt.
WorldToLocal(particle_position_array,particle_local_position_array);
295 crt.
WorldToLocalVect(particle_direction_array,particle_local_direction_array);
296 TVector3 particle_local_position(particle_local_position_array[0],particle_local_position_array[1],particle_local_position_array[2]);
297 TVector3 particle_local_direction(particle_local_direction_array[0],particle_local_direction_array[1],particle_local_direction_array[2]);
298 double norm[3], lnorm[3];
312 TVector3 crt_max_extent = crt_min_extent*-1.;
315 return RayIntersectsBox(particle_local_position,particle_local_direction,crt_min_extent,crt_max_extent);
320 double t1 = (box_min_extent.X() - ray_origin.X())/ray_direction.X();
321 double t2 = (box_max_extent.X() - ray_origin.X())/ray_direction.X();
322 double t3 = (box_min_extent.Y() - ray_origin.Y())/ray_direction.Y();
323 double t4 = (box_max_extent.Y() - ray_origin.Y())/ray_direction.Y();
324 double t5 = (box_min_extent.Z() - ray_origin.Z())/ray_direction.Z();
325 double t6 = (box_max_extent.Z() - ray_origin.Z())/ray_direction.Z();
327 double tmin = std::max(std::max(std::min(t1, t2), std::min(t3, t4)), std::min(t5, t6));
328 double tmax = std::min(std::min(std::max(t1, t2), std::max(t3, t4)), std::max(t5, t6));
346 TVector3 start (particle.Position().X(), particle.Position().Y(), particle.Position().Z());
347 TVector3 direction (particle.Momentum().X()/particle.Momentum().Vect().Mag(),
348 particle.Momentum().Y()/particle.Momentum().Vect().Mag(),
349 particle.Momentum().Z()/particle.Momentum().Vect().Mag());
350 TVector3
end = start + direction;
352 double minimum = 99999;
353 double maximum = -99999;
356 for(
size_t t = 0; t < cryostat.
NTPC(); t++){
359 TVector3 min (tpcGeo.
MinX(), tpcGeo.
MinY(), tpcGeo.
MinZ());
360 TVector3 max (tpcGeo.
MaxX(), tpcGeo.
MaxY(), tpcGeo.
MaxZ());
362 std::pair<TVector3, TVector3> intersection =
CubeIntersection(min, max, start, end);
363 double x1 =
std::abs(intersection.first.X());
364 double x2 =
std::abs(intersection.second.X());
365 if(x1 != -99999 && x1 > maximum) maximum = x1;
366 if(x1 != -99999 && x1 < minimum) minimum = x1;
367 if(x2 != -99999 && x2 > maximum) maximum = x2;
368 if(x2 != -99999 && x2 < minimum) minimum = x2;
372 return std::make_pair(minimum, maximum);
377 TVector3
dir = (end - start);
378 TVector3 invDir (1./dir.X(), 1./dir.Y(), 1/dir.Z());
380 double tmin, tmax, tymin, tymax, tzmin, tzmax;
382 TVector3 enter (-99999, -99999, -99999);
383 TVector3
exit (-99999, -99999, -99999);
387 tmin = (min.X() - start.X()) * invDir.X();
388 tmax = (max.X() - start.X()) * invDir.X();
391 tmin = (max.X() - start.X()) * invDir.X();
392 tmax = (min.X() - start.X()) * invDir.X();
397 tymin = (min.Y() - start.Y()) * invDir.Y();
398 tymax = (max.Y() - start.Y()) * invDir.Y();
401 tymin = (max.Y() - start.Y()) * invDir.Y();
402 tymax = (min.Y() - start.Y()) * invDir.Y();
406 if((tmin > tymax) || (tymin > tmax))
return std::make_pair(enter, exit);
409 if(tymin > tmin) tmin = tymin;
412 if(tymax < tmax) tmax = tymax;
416 tzmin = (min.Z() - start.Z()) * invDir.Z();
417 tzmax = (max.Z() - start.Z()) * invDir.Z();
420 tzmin = (max.Z() - start.Z()) * invDir.Z();
421 tzmax = (min.Z() - start.Z()) * invDir.Z();
425 if((tmin > tzmax) || (tzmin > tmax))
return std::make_pair(enter, exit);
428 if(tzmin > tmin) tmin = tzmin;
431 if(tzmax < tmax) tmax = tzmax;
434 double xmin = start.X() + tmin * dir.X();
435 double xmax = start.X() + tmax * dir.X();
436 double ymin = start.Y() + tmin * dir.Y();
437 double ymax = start.Y() + tmax * dir.Y();
438 double zmin = start.Z() + tmin * dir.Z();
439 double zmax = start.Z() + tmax * dir.Z();
442 enter.SetXYZ(xmin, ymin, zmin);
443 exit.SetXYZ(xmax, ymax, zmax);
444 return std::make_pair(enter, exit);
bool IsInterestingParticle(const simb::MCParticle &particle)
std::vector< unsigned int > fBackCRTAuxDetIDs
Utilities related to art service access.
geo::Length_t DetHalfWidth(geo::TPCID const &tpcid) const
Returns the half width of the active volume of the specified TPC.
void WorldToLocal(const double *world, double *auxdet) const
Transform point from world frame to local auxiliary detector frame.
double MinX() const
Returns the world x coordinate of the start of the box.
Geometry information for a single TPC.
void WorldToLocalVect(const double *world, double *auxdet) const
Transform direction vector from world to local.
double MaxX() const
Returns the world x coordinate of the end of the box.
Geometry information for a single cryostat.
std::vector< double > fMaxMomentums
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
std::vector< unsigned int > fLeftCRTAuxDetIDs
std::vector< unsigned int > fTopLowCRTAuxDetIDs
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
Access the description of detector geometry.
GenFilter(fhicl::ParameterSet const &pset)
std::vector< double > fMinMomentums
std::vector< unsigned int > fRightCRTAuxDetIDs
double HalfHeight() const
std::vector< unsigned int > fFrontCRTAuxDetIDs
auto end(FixedBins< T, C > const &) noexcept
bool fUseTightReadoutWindow
double MinZ() const
Returns the world z coordinate of the start of the box.
unsigned int NTPC() const
Number of TPCs in this cryostat.
CryostatGeo const & Cryostat(geo::CryostatID const &cryoid) const
Returns the specified cryostat.
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
Description of geometry of one entire detector.
bool UsesCRTAuxDet(const simb::MCParticle &particle, geo::AuxDetGeo const &crt)
bool RayIntersectsBox(TVector3 ray_origin, TVector3 ray_direction, TVector3 box_min_extent, TVector3 box_max_extent)
auto norm(Vector const &v)
Return norm of the specified vector.
double MaxY() const
Returns the world y coordinate of the end of the box.
std::pair< TVector3, TVector3 > CubeIntersection(TVector3 min, TVector3 max, TVector3 start, TVector3 end)
const TGeoVolume * TotalVolume() const
const TPCGeo & TPC(unsigned int itpc) const
Return the itpc'th TPC in the cryostat.
std::vector< unsigned int > fBottomCRTAuxDetIDs
double MaxZ() const
Returns the world z coordinate of the end of the box.
std::vector< unsigned int > fTopHighCRTAuxDetIDs
geo::GeometryCore const * fGeometryService
double HalfWidth1() const
virtual void beginJob() override
double MinY() const
Returns the world y coordinate of the start of the box.
void reconfigure(fhicl::ParameterSet const &pset)
std::pair< double, double > XLimitsTPC(const simb::MCParticle &particle)
virtual bool filter(art::Event &e) override
double fCRTDimensionScaling
art framework interface to geometry description
BEGIN_PROLOG could also be cout
void GetCenter(double *xyz, double localz=0.0) const
Return the center position of an AuxDet.
bool UsesCRTAuxDets(const simb::MCParticle &particle, const std::vector< unsigned int > &crt_auxdet_vector)