7 #include "art/Framework/Core/EDFilter.h"
8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Framework/Principal/Event.h"
10 #include "art/Framework/Services/Registry/ServiceHandle.h"
15 #include "nusimdata/SimulationBase/MCParticle.h"
18 #include "TLorentzVector.h"
26 virtual bool filter(art::Event&
e);
30 bool IsInterestingParticle(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
31 bool PDGCheck(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
32 bool IsPrimaryCheck(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
33 bool MinMomentumCheck(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
34 bool MaxMomentumCheck(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
35 bool StartInTPCCheck(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
36 bool StopInTPCCheck(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
37 bool TPCTrajLengthCheck(
const art::Ptr<simb::MCParticle> &particle,
const unsigned int index)
const;
39 double CalculateLength(
const std::vector<TVector3> &position_segment)
const;
44 art::ServiceHandle<geo::Geometry const>
fGeom;
60 LArG4ParticleFilter::LArG4ParticleFilter::LArG4ParticleFilter(fhicl::ParameterSet
const & pset) :
62 fLArG4ModuleLabel(pset.get<std::string>(
"LArG4ModuleLabel")),
63 fInterestingPDGs(pset.get<std::vector<int> >(
"InterestingPDGs")),
64 fIsPrimary(pset.get<std::vector<int> >(
"IsPrimary")),
65 fParticleMinMomentum(pset.get<std::vector<double> >(
"ParticleMinMomentum")),
66 fParticleMaxMomentum(pset.get<std::vector<double> >(
"ParticleMaxMomentum")),
67 fStartInTPC(pset.get<std::vector<int> >(
"StartInTPC")),
68 fStopInTPC(pset.get<std::vector<int> >(
"StopInTPC")),
69 fParticleMinTPCLength(pset.get<std::vector<double> >(
"ParticleMinTPCLength")),
70 fRequireAllInterestingParticles(pset.get<
bool>(
"RequireAllInterestingParticles")),
71 fFoundInterestingParticles(fInterestingPDGs.size(),
false)
84 art::Handle<std::vector<simb::MCParticle> > particles;
87 for (
unsigned int part_i = 0; part_i < particles->size(); part_i++){
89 const art::Ptr<simb::MCParticle> particle(particles,part_i);
91 for (
unsigned int interest_i = 0; interest_i <
fInterestingPDGs.size(); interest_i++){
95 bool foundThemAll =
true;
116 if (!
PDGCheck(particle,index))
return false;
130 if (pdg == 0)
return true;
131 if (particle->PdgCode() !=
pdg)
return false;
137 const int isPrimaryCondition(
fIsPrimary[index]);
138 if (isPrimaryCondition==-1)
return true;
139 bool particlePrimaryStatus(particle->Mother() > 0 ?
false:
true);
140 if (particlePrimaryStatus != isPrimaryCondition)
return false;
160 if (demand == 0)
return true;
162 TLorentzVector starting_position_4vect = particle->Position(0);
163 double starting_position[3];
164 starting_position[0] = starting_position_4vect.X();
165 starting_position[1] = starting_position_4vect.Y();
166 starting_position[2] = starting_position_4vect.Z();
173 if (demand == 1)
return true;
178 if (demand == 2)
return true;
191 if (demand == 0)
return true;
193 TLorentzVector final_position_4vect = particle->Position(particle->NumberTrajectoryPoints()-1);
194 double final_position[3];
195 final_position[0] = final_position_4vect.X();
196 final_position[1] = final_position_4vect.Y();
197 final_position[2] = final_position_4vect.Z();
204 if (demand == 1)
return true;
209 if (demand == 2)
return true;
222 if (min_traj_length < 0)
return true;
228 std::vector< std::vector<TVector3> > position_segments;
230 std::vector<TVector3> position_segment;
232 for (
unsigned int i = 0; i < particle->NumberTrajectoryPoints(); i++){
235 curr_pos[0] = particle->Position(i).X();
236 curr_pos[1] = particle->Position(i).Y();
237 curr_pos[2] = particle->Position(i).Z();
241 if (curr_tpcid.
isValid) position_segment.push_back(particle->Position(i).Vect());
243 else if (position_segment.size() > 0){
245 position_segments.push_back(position_segment);
247 position_segment.clear();
252 if (position_segment.size() > 0){
253 position_segments.push_back(position_segment);
254 position_segment.clear();
258 if (position_segments.size() == 0)
return false;
260 for (
unsigned int i = 0; i < position_segments.size(); i++){
262 if (segment_length > min_traj_length){
268 if (!OK)
return false;
277 if (position_segment.size() <= 1)
return length;
280 for (
unsigned int i = 1; i < position_segment.size(); i++){
281 length += (position_segment[i] - position_segment[i-1]).Mag();
290 throw art::Exception(art::errors::Configuration) <<
"Config error: InterestingPDGs and IsPrimary FCL vectors are different sizes\n";
292 throw art::Exception(art::errors::Configuration) <<
"Config error: InterestingPDGs and ParticleMinMomentum FCL vectors are different sizes\n";
294 throw art::Exception(art::errors::Configuration) <<
"Config error: InterestingPDGs and ParticleMaxMomentum FCL vectors are different sizes\n";
296 throw art::Exception(art::errors::Configuration) <<
"Config error: InterestingPDGs and StartInTPC FCL vectors are different sizes\n";
298 throw art::Exception(art::errors::Configuration) <<
"Config error: InterestingPDGs and StopInTPC FCL vectors are different sizes\n";
300 throw art::Exception(art::errors::Configuration) <<
"Config error: InterestingPDGs and ParticleMinTPCLength FCL vectors are different sizes\n";
302 for (
unsigned int iIsPrimary = 0; iIsPrimary <
fIsPrimary.size(); iIsPrimary++)
304 throw art::Exception(art::errors::Configuration) <<
"Config error: Element " << iIsPrimary <<
" of the IsPrimary vector equals "
305 <<
fIsPrimary[iIsPrimary] <<
". Valid options are -1 (not set), 0 (not primary) or 1 (is primary)" << std::endl;
307 for (
unsigned int iStartInTPC = 0; iStartInTPC <
fStartInTPC.size(); iStartInTPC++)
309 throw art::Exception(art::errors::Configuration) <<
"Config error: Element " << iStartInTPC <<
" of the StartInTPC vector equals "
310 <<
fStartInTPC[iStartInTPC] <<
". Valid options are 0 (not set), 1 (start in TPC) or 2 (do not start in TPC)" << std::endl;
312 for (
unsigned int iStopInTPC = 0; iStopInTPC <
fStopInTPC.size(); iStopInTPC++)
314 throw art::Exception(art::errors::Configuration) <<
"Config error: Element " << iStopInTPC <<
" of the StopInTPC vector equals "
315 <<
fStopInTPC[iStopInTPC] <<
". Valid options are 0 (not set), 1 (stop in TPC) or 2 (do not stop in TPC)" << std::endl;
323 throw art::Exception(art::errors::InvalidNumber) <<
"Bounds error: Requested element " << index <<
" from InterestingPDGs vector which is size "
326 throw art::Exception(art::errors::InvalidNumber) <<
"Bounds error: Requested element " << index <<
" from IsPrimary vector which is size "
329 throw art::Exception(art::errors::InvalidNumber) <<
"Bounds error: Requested element " << index <<
" from ParticleMinMomentum vector which is size "
332 throw art::Exception(art::errors::InvalidNumber) <<
"Bounds error: Requested element " << index <<
" from ParticleMaxMomentum vector which is size "
335 throw art::Exception(art::errors::InvalidNumber) <<
"Bounds error: Requested element " << index <<
" from StartInTPC vector which is size "
338 throw art::Exception(art::errors::InvalidNumber) <<
"Bounds error: Requested element " << index <<
" from StopInTPC vector which is size "
341 throw art::Exception(art::errors::InvalidNumber) <<
"Bounds error: Requested element " << index <<
" from ParticleMinTPCLength vector which is size "
std::vector< bool > fFoundInterestingParticles
bool IsInterestingParticle(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
art::ServiceHandle< geo::Geometry const > fGeom
void VerifyDataMembers() const
bool isValid
Whether this ID points to a valid element.
double CalculateLength(const std::vector< TVector3 > &position_segment) const
const std::vector< int > fInterestingPDGs
bool IsPrimaryCheck(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
const std::vector< double > fParticleMaxMomentum
bool MaxMomentumCheck(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
void VerifyElementRequest(const unsigned int index) const
bool StartInTPCCheck(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
bool MinMomentumCheck(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
const std::string fLArG4ModuleLabel
bool TPCTrajLengthCheck(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
The data type to uniquely identify a TPC.
const std::vector< int > fStopInTPC
Definition of data types for geometry description.
const std::vector< double > fParticleMinMomentum
const std::vector< int > fIsPrimary
const bool fRequireAllInterestingParticles
const std::vector< double > fParticleMinTPCLength
virtual bool filter(art::Event &e)
const std::vector< int > fStartInTPC
art framework interface to geometry description
bool PDGCheck(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
bool StopInTPCCheck(const art::Ptr< simb::MCParticle > &particle, const unsigned int index) const
LArG4ParticleFilter(fhicl::ParameterSet const &pset)