All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArG4FakeTriggerFilter_module.cc
Go to the documentation of this file.
1 #include <algorithm>
2 
3 #include "art/Framework/Core/EDFilter.h"
4 #include "art/Framework/Core/ModuleMacros.h"
5 #include "art/Framework/Principal/Event.h"
6 
8 #include "larcore/CoreUtils/ServiceUtil.h" // lar::providerFrom()
10 #include "nusimdata/SimulationBase/MCParticle.h"
11 
12 namespace filt{
13 
14  class LArG4FakeTriggerFilter : public art::EDFilter {
15  public:
16 
17  explicit LArG4FakeTriggerFilter(fhicl::ParameterSet const & pset);
18  virtual bool filter(art::Event& e) override;
19  void reconfigure(fhicl::ParameterSet const& pset);
20  virtual void beginJob() override;
21 
22  private:
23 
24  double fBeamTimeMin; // Minimum time of beam window [us]
25  double fBeamTimeMax; // Maximum time of beam window [us]
26  double fEnergyDeposit;// Minimum energy deposit in TPC for trigger [MeV]
27 
28  std::string fLArG4ModuleName;
29 
31 
32  bool IsInterestingParticle(const art::Ptr<simb::MCParticle> particle);
33  double EnergyInTPC(const art::Ptr<simb::MCParticle> particle);
34  };
35 
36 
37  LArG4FakeTriggerFilter::LArG4FakeTriggerFilter(fhicl::ParameterSet const & pset)
38  : EDFilter(pset)
39  {
40  this->reconfigure(pset);
41 
42  fGeometryService = lar::providerFrom<geo::Geometry>();
43  }
44 
45 
46  void LArG4FakeTriggerFilter::reconfigure(fhicl::ParameterSet const& pset){
47 
48  fBeamTimeMin = pset.get<double>("BeamTimeMin");
49  fBeamTimeMax = pset.get<double>("BeamTimeMax");
50  fEnergyDeposit = pset.get<double>("EnergyDeposit");
51 
52  fLArG4ModuleName = pset.get<std::string>("LArG4ModuleName");
53 
54  }
55 
56 
57  bool LArG4FakeTriggerFilter::filter(art::Event & e){
58 
59  art::Handle<std::vector<simb::MCParticle> > particles;
60  e.getByLabel(fLArG4ModuleName, particles);
61 
62  double e_dep = 0;
63 
64  for (unsigned int part_i = 0; part_i < particles->size(); part_i++){
65 
66  const art::Ptr<simb::MCParticle> particle(particles, part_i);
67 
68  // Check particle time is within the beam time
69  double time = particle->T() * 1e-3; // [us]
70  if(time < fBeamTimeMin || time > fBeamTimeMax) continue;
71 
72  // Check particle is stable and charged
73  if (!IsInterestingParticle(particle)) continue;
74 
75  // Add up the energy deposit inside the TPC
76  e_dep += EnergyInTPC(particle); // [GeV]
77  }
78 
79  // If the energy deposit within the beam time is greater than some limit then trigger the event
80  if(e_dep > fEnergyDeposit/1000.) return true;
81  return false;
82 
83  }
84 
85 
87  }
88 
89 
90  // Check if particle is stable and charged
91  bool LArG4FakeTriggerFilter::IsInterestingParticle(const art::Ptr<simb::MCParticle> particle){
92 
93  // Stable final state
94  if(particle->StatusCode() != 1) return false;
95 
96  // Charged: e, mu, pi, K, p
97  int pdg = particle->PdgCode();
98  if(!(pdg==11 || pdg==13 || pdg==211 || pdg==321 || pdg==2212)) return false;
99 
100  return true;
101 
102  }
103 
104  // Add up energy deposit in TPC
105  double LArG4FakeTriggerFilter::EnergyInTPC(const art::Ptr<simb::MCParticle> particle){
106 
107  double xmin = -2.0 * fGeometryService->DetHalfWidth();
108  double xmax = 2.0 * fGeometryService->DetHalfWidth();
109  double ymin = -fGeometryService->DetHalfHeight();
110  double ymax = fGeometryService->DetHalfHeight();
111  double zmin = 0.;
112  double zmax = fGeometryService->DetLength();
113 
114  double e_dep = 0;
115 
116  int npts = particle->NumberTrajectoryPoints();
117  for (int i = 1; i < npts; i++){
118  TVector3 pos(particle->Vx(i), particle->Vy(i), particle->Vz(i));
119  // Check if point is within the TPC
120  if (pos[0] >= xmin && pos[0] <= xmax && pos[1] >= ymin && pos[1] <= ymax && pos[2] >= zmin && pos[2] <= zmax){
121  e_dep += particle->E(i-1) - particle->E(i);
122  }
123  }
124 
125  return e_dep;
126  }
127 
128 
129  DEFINE_ART_MODULE(LArG4FakeTriggerFilter)
130 
131 }
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.
var pdg
Definition: selectors.fcl:14
void reconfigure(fhicl::ParameterSet const &pset)
bool IsInterestingParticle(const art::Ptr< simb::MCParticle > particle)
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
Access the description of detector geometry.
geo::Length_t DetHalfHeight(geo::TPCID const &tpcid) const
Returns the half height of the active volume of the specified TPC.
geo::Length_t DetLength(geo::TPCID const &tpcid) const
Returns the length of the active volume of the specified TPC.
Description of geometry of one entire detector.
geo::GeometryCore const * fGeometryService
then filt
do i e
LArG4FakeTriggerFilter(fhicl::ParameterSet const &pset)
double EnergyInTPC(const art::Ptr< simb::MCParticle > particle)
art framework interface to geometry description
virtual bool filter(art::Event &e) override