Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
filt::GenFilter Class Reference
Inheritance diagram for filt::GenFilter:
art::EDFilter art::detail::Filter art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Classes

struct  CounterSetPair
 

Public Member Functions

 GenFilter (fhicl::ParameterSet const &pset)
 
virtual ~GenFilter ()
 
virtual bool filter (art::Event &e)
 
void reconfigure (fhicl::ParameterSet const &pset)
 
void beginJob ()
 
- Public Member Functions inherited from art::EDFilter
 EDFilter (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDFilter (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Filter
virtual ~Filter () noexcept
 
 Filter (fhicl::ParameterSet const &)
 
 Filter (Filter const &)=delete
 
 Filter (Filter &&)=delete
 
Filteroperator= (Filter const &)=delete
 
Filteroperator= (Filter &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

bool IsInterestingParticle (const simb::MCParticle &particle)
 
bool ParticleHitsCounterSetPairs (const simb::MCParticle &particle, const CounterSetPair &CSP)
 
bool ParticleHitsCounterSet (const simb::MCParticle &particle, const std::vector< geo::AuxDetGeo const * > &counters, const TVector3 &counter_norm)
 

Private Attributes

std::vector< CounterSetPairfCounterSetPairs
 
bool fUseEWCounterPair
 
bool fUseNupSdownCounterPair
 
bool fUseNdownSupCounterPair
 
std::vector< int > fInterestingPDGs
 
double fParticleMinEnergy
 
double fParticleMaxEnergy
 
double fCounterSizeScaleFactor
 

Additional Inherited Members

- Public Types inherited from art::EDFilter
using ModuleType = EDFilter
 
using WorkerType = WorkerT< EDFilter >
 
- Public Types inherited from art::detail::Filter
template<typename UserConfig >
using Table = Modifier::Table< UserConfig >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Attributes inherited from art::detail::Filter
static constexpr bool Pass {true}
 
static constexpr bool Fail {false}
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 18 of file GenExtCounterFilter_module.cc.

Constructor & Destructor Documentation

filt::GenFilter::GenFilter ( fhicl::ParameterSet const &  pset)
explicit
virtual filt::GenFilter::~GenFilter ( )
inlinevirtual

Definition at line 21 of file GenExtCounterFilter_module.cc.

21 {};

Member Function Documentation

void filt::GenFilter::beginJob ( )
virtual

Reimplemented from art::EDFilter.

Definition at line 126 of file GenExtCounterFilter_module.cc.

126  {
128 
129  CounterSetPair EWCounterSetPair;
130  CounterSetPair NupSdownCounterSetPair;
131  CounterSetPair NdownSupCounterSetPair;
132 
133  for (unsigned int i = 0; i < geom->NAuxDets(); i++){
134  //The WE counter pairs
135  geo::AuxDetGeo const* counter = &(geom->AuxDet(i));
136  if (i >=6 && i <= 15) EWCounterSetPair.setA.push_back(counter);
137  else if (i >= 28 && i <=37) EWCounterSetPair.setB.push_back(counter);
138  //The N (up) S (down) counter pairs
139  else if (i >= 22 && i <= 27) NupSdownCounterSetPair.setA.push_back(counter);
140  else if (i <= 5) NupSdownCounterSetPair.setB.push_back(counter);
141  //The N (down) S (up) counter pairs
142  else if (i >= 16 && i <= 21) NdownSupCounterSetPair.setA.push_back(counter);
143  else if (i >= 38 && i <= 43) NdownSupCounterSetPair.setB.push_back(counter);
144  }
145 
146  EWCounterSetPair.normalVec[0] = 0.;
147  EWCounterSetPair.normalVec[1] = 0.;
148  EWCounterSetPair.normalVec[2] = 1.;
149  EWCounterSetPair.isRequested = fUseEWCounterPair;
150  fCounterSetPairs.push_back(EWCounterSetPair);
151 
152  NupSdownCounterSetPair.normalVec[0] = 1.;
153  NupSdownCounterSetPair.normalVec[1] = 0.;
154  NupSdownCounterSetPair.normalVec[2] = 0.;
155  NupSdownCounterSetPair.isRequested = fUseNupSdownCounterPair;
156  fCounterSetPairs.push_back(NupSdownCounterSetPair);
157 
158  NdownSupCounterSetPair.normalVec[0] = 1.;
159  NdownSupCounterSetPair.normalVec[1] = 0.;
160  NdownSupCounterSetPair.normalVec[2] = 0.;
161  NdownSupCounterSetPair.isRequested = fUseNdownSupCounterPair;
162  fCounterSetPairs.push_back(NdownSupCounterSetPair);
163 
164  for (unsigned int i = 0; i < fCounterSetPairs.size(); i++){
165  std::cout<<"Counter set pair: "<<i<<std::endl;
166  std::cout<<"--setA size: " << fCounterSetPairs[i].setA.size() << std::endl;
167  std::cout<<"--setB size: " << fCounterSetPairs[i].setB.size() << std::endl;
168 
169  }
170 
171 
172  }
AuxDetGeo const & AuxDet(unsigned int const ad=0) const
Returns the specified auxiliary detector.
std::vector< CounterSetPair > fCounterSetPairs
QTextStream & endl(QTextStream &s)
unsigned int NAuxDets() const
Returns the number of auxiliary detectors.
bool filt::GenFilter::filter ( art::Event e)
virtual

Implements art::EDFilter.

Definition at line 81 of file GenExtCounterFilter_module.cc.

81  {
82 
83  auto const mclists = e.getMany<std::vector<simb::MCTruth>>();
84  for (unsigned int i = 0; i < mclists.size() ; i++){
85  for (unsigned int j = 0; j < mclists[i]->size(); j++){
86  //Should have the truth record for the event now
87  const art::Ptr<simb::MCTruth> mc_truth(mclists[i],j);
88  for (int part = 0; part < mc_truth->NParticles(); part++){
89  const simb::MCParticle particle = mc_truth->GetParticle(part);
90  if (!IsInterestingParticle(particle)) continue;
91  TVector3 particle_pos = particle.Position().Vect();
92  TVector3 particle_dir = particle.Momentum().Vect().Unit();
93  for (unsigned CSP_i = 0; CSP_i < fCounterSetPairs.size(); CSP_i++){
94  if (!fCounterSetPairs[CSP_i].isRequested) continue;
96  std::cout<<"HIT COUNTER SET"<<std::endl;
97  return true;
98  }
99  /*
100  TVector3 counter_norm(fCounterSetPairs[i].normalVec[0],fCounterSetPairs[i].normalVec[1],fCounterSetPairs[i].normalVec[2]);
101  double counter_pos_array[3];
102  fCounterSetPairs[CSP_i].setA.front()->GetCenter(counter_pos_array);
103  TVector3 counter_pos(counter_pos_array[0], counter_pos_array[1], counter_pos_array[2]);
104  double scale_factor = counter_norm.Dot(counter_pos - particle_pos)/(counter_norm.Dot(particle_dir));
105  TVector3 particle_pos_in_plane = particle_pos + scale_factor * particle_dir;
106  std::cout<<"Particle pos: " << "("<<particle_pos_in_plane.X()<<","<<particle_pos_in_plane.Y()<<","<<particle_pos_in_plane.Z()<<")"<<std::endl;
107  std::cout<<"Counter pos: " << "("<<counter_pos.X()<<","<<counter_pos.Y()<<","<<counter_pos.Z()<<")"<<std::endl;
108  */
109 
110  }
111  /*
112  geo::AuxDetGeo const*counter = fCounterSetPairs.front().setA.front();
113  std::cout<<"Length: " << counter->Length() << std::endl;
114  std::cout<<"HalfWidth1: " << counter->HalfWidth1() << std::endl;
115  std::cout<<"HalfWidth2: " << counter->HalfWidth2() << std::endl;
116 
117  std::cout<<"HalfHeight: " << counter->HalfHeight() << std::endl;
118  */
119  }
120  }
121  }
122 
123  return false;
124  }
bool IsInterestingParticle(const simb::MCParticle &particle)
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
bool ParticleHitsCounterSetPairs(const simb::MCParticle &particle, const CounterSetPair &CSP)
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:479
std::vector< CounterSetPair > fCounterSetPairs
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
QTextStream & endl(QTextStream &s)
bool filt::GenFilter::IsInterestingParticle ( const simb::MCParticle particle)
private

Definition at line 174 of file GenExtCounterFilter_module.cc.

174  {
175 
176  for (unsigned int i = 0; i < fInterestingPDGs.size(); i++){
177  //Check if the particle under consideration has a requested PDG
178  if (particle.PdgCode() == fInterestingPDGs[i]){
179  //Got a requested PDG, now check that the energy matches the requested range
180  TLorentzVector mom4 = particle.Momentum();
181  if (mom4.T() > fParticleMinEnergy && mom4.T() < fParticleMaxEnergy){
182  //std::cout<<"FOUND INTERESTING PARTICLE"<<std::endl;
183  return true;
184  }
185  }
186  }
187 
188  return false;
189  }
int PdgCode() const
Definition: MCParticle.h:212
std::vector< int > fInterestingPDGs
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
bool filt::GenFilter::ParticleHitsCounterSet ( const simb::MCParticle particle,
const std::vector< geo::AuxDetGeo const * > &  counters,
const TVector3 &  counter_norm 
)
private

Definition at line 204 of file GenExtCounterFilter_module.cc.

204  {
205 
206  //Loop through the counters
207  for (unsigned int i = 0; i < counters.size(); i++){
208  //First step is to push the particle to the counter plane
209  geo::AuxDetGeo const*counter = counters[i];
210 
211  double counter_pos_array[3];
212  //fCounterSetPairs[CSP_i].setA.front()->GetCenter(counter_pos_array);
213  counter->GetCenter(counter_pos_array);
214  TVector3 counter_pos(counter_pos_array[0], counter_pos_array[1], counter_pos_array[2]);
215  TVector3 particle_pos = particle.Position().Vect();
216  TVector3 particle_dir = particle.Momentum().Vect().Unit();
217 
218  /*
219  Length: 62.992
220  HalfWidth1: 16.2814
221  HalfWidth2: 13.5255
222  HalfHeight: 0.475
223  */
224 
225  double scale_factor = counter_norm.Dot(counter_pos - particle_pos)/(counter_norm.Dot(particle_dir));
226 
227  TVector3 particle_pos_in_plane = particle_pos + scale_factor * particle_dir;
228 
229  //We now have the particle position in the plane of the counter. We now just need to calculate whether it sits inside the box
230  //Create two TVector3s, each will hold the coordinates of opposing corners of the counter in question
231  //We need to use the normals associated with the counter. We already have two, one is a member of the C++ object and the other was passed to this function
232  //Create the two TVector3s
233  TVector3 pos_corner, neg_corner;
234  //Lets start with the one passed to this function
235  //The thin dimension of the counter is the one associated with normal passed to this function
236  pos_corner += counter->HalfHeight()*counter_norm*fCounterSizeScaleFactor;
237  neg_corner += -1.*counter->HalfHeight()*counter_norm*fCounterSizeScaleFactor;
238 
239  //Now lets to the same for the normal stored in the C++ object (this "normal" actually points out the top of a counter)
240  double counter_top_norm_array[3];
241  counter->GetNormalVector(counter_top_norm_array);
242  //Now package this up a TVector
243  TVector3 counter_top_norm;
244  counter_top_norm.SetX(counter_top_norm_array[0]);
245  counter_top_norm.SetY(counter_top_norm_array[1]);
246  counter_top_norm.SetZ(counter_top_norm_array[2]);
247  //OK now we can add the dimension to the corner vectors. The relevant dimension this time is Length/2
248  pos_corner += counter->Length()*counter_top_norm*0.5*fCounterSizeScaleFactor;
249  neg_corner += -1.*counter->Length()*counter_top_norm*0.5*fCounterSizeScaleFactor;
250  //Now we need to the same for the vector pointing along the counter.
251  //The relevant dimension in this case in HalfWidth1 (going to assume the counter is a square and take the bigger width)
252  //Because we have the other two vectors already, we can very easily get the final one by taking the cross product of them
253  TVector3 counter_side_norm = counter_norm.Cross(counter_top_norm);
254  //now add the dimenions onto the corner vectors
255  pos_corner += counter->HalfWidth1()*counter_side_norm*fCounterSizeScaleFactor;
256  neg_corner += -1.*counter->HalfWidth1()*counter_side_norm*fCounterSizeScaleFactor;
257 
258  //Almost ready
259  //We have calculated the corners assuming the centre of the counter is the origin. Two choices, either translate the corners OR translate the propagated particle position
260  //The latter is less lines of code so lets to that
261  particle_pos_in_plane += -1.*counter_pos;
262 
263  //We are now ready to check if the particle sits in the counter
264  //We don't know by default which way round the corners are oriented, but that doesn't matter as we can take abs, max and min
265  //We are going to take abs of the particle position, the pos corner and the neg corner first
266  /*
267  pos_corner.SetXYZ(std::abs(pos_corner.X()),std::abs(pos_corner.Y()),std::abs(pos_corner.Z()));
268  neg_corner.SetXYZ(std::abs(neg_corner.X()),std::abs(neg_corner.Y()),std::abs(neg_corner.Z()));
269  particle_pos_in_plane.SetXYZ(std::abs(particle_pos_in_plane.X()),std::abs(particle_pos_in_plane.Y()),std::abs(particle_pos_in_plane.Z()));
270  */
271 
272  /*
273  //Dump the corners and particle pos
274  std::cout<<"pos_corner: " << pos_corner.X()<<","<<pos_corner.Y()<<","<<pos_corner.Z()<<std::endl;
275  std::cout<<"neg_corner: " << neg_corner.X()<<","<<neg_corner.Y()<<","<<neg_corner.Z()<<std::endl;
276  std::cout<<"particle_pos_in_plane: " << particle_pos_in_plane.X()<<","<<particle_pos_in_plane.Y()<<","<<particle_pos_in_plane.Z()<<std::endl;
277  */
278 
279 
280 
281  //Now we can check
282  //This is going to be one huge if statement...
283  if (particle_pos_in_plane.X() > std::min(pos_corner.X(), neg_corner.X()) && particle_pos_in_plane.X() < std::max(pos_corner.X(),neg_corner.X()) && particle_pos_in_plane.Y() > std::min(pos_corner.Y(), neg_corner.Y()) && particle_pos_in_plane.Y() < std::max(pos_corner.Y(),neg_corner.Y()) && particle_pos_in_plane.Z() > std::min(pos_corner.Z(), neg_corner.Z()) && particle_pos_in_plane.Z() < std::max(pos_corner.Z(),neg_corner.Z())){
284  std::cout<<"Particle uses counter in set"<<std::endl;
285  return true;
286  }
287 
288  }
289 
290  return false;
291  }
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
double HalfHeight() const
Definition: AuxDetGeo.h:105
geo::Vector_t GetNormalVector() const
Returns the unit normal vector to the detector.
Definition: AuxDetGeo.cxx:72
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
double Length() const
Definition: AuxDetGeo.h:102
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
double HalfWidth1() const
Definition: AuxDetGeo.h:103
QTextStream & endl(QTextStream &s)
void GetCenter(double *xyz, double localz=0.0) const
Return the center position of an AuxDet.
Definition: AuxDetGeo.cxx:62
bool filt::GenFilter::ParticleHitsCounterSetPairs ( const simb::MCParticle particle,
const CounterSetPair CSP 
)
private

Definition at line 191 of file GenExtCounterFilter_module.cc.

191  {
192  //Need the normal to the counters
193  TVector3 counter_norm(CSP.normalVec[0],CSP.normalVec[1],CSP.normalVec[2]);
194 
195  //Loop through one of the counter sets
196  if (ParticleHitsCounterSet(particle, CSP.setA, counter_norm)){
197  if (ParticleHitsCounterSet(particle, CSP.setB, counter_norm)){
198  return true;
199  }
200  }
201  return false;
202  }
bool ParticleHitsCounterSet(const simb::MCParticle &particle, const std::vector< geo::AuxDetGeo const * > &counters, const TVector3 &counter_norm)
void filt::GenFilter::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 59 of file GenExtCounterFilter_module.cc.

59  {
60  fUseEWCounterPair = pset.get<bool>("UseEWCounterPair",1);
61  std::cout<<"Use EW counter pair: " << fUseEWCounterPair<<std::endl;
62  fUseNupSdownCounterPair = pset.get<bool>("UseNupSdownCounterPair",1);
63  std::cout<<"Use N (up) S (down) counter pair: " << fUseNupSdownCounterPair << std::endl;
64  fUseNdownSupCounterPair = pset.get<bool>("UseNdownSupCounterPair",1);
65  std::cout<<"Use N (down) S (up) counter pair: " << fUseNdownSupCounterPair << std::endl;
66  fInterestingPDGs = pset.get<std::vector<int> >("InterestingPDGs");
67  std::cout<<"NInteresting PDGs: " << fInterestingPDGs.size() << std::endl;
68  for (unsigned int i = 0; i < fInterestingPDGs.size(); i++){
69  std::cout<<"-- PDG: " << fInterestingPDGs[i] << std::endl;
70  }
71  fParticleMinEnergy = pset.get<double>("ParticleMinEnergy",0);
72  std::cout<<"Particle min energy: " << fParticleMinEnergy << std::endl;
73  fParticleMaxEnergy = pset.get<double>("ParticleMaxEnergy",999999999);
74  std::cout<<"Particle max energy: " << fParticleMaxEnergy << std::endl;
75 
76  fCounterSizeScaleFactor = pset.get<double>("CounterSizeScaleFactor",1.);
77  std::cout<<"Counter size scale factor: " << fCounterSizeScaleFactor << std::endl;
78  }
std::vector< int > fInterestingPDGs
QTextStream & endl(QTextStream &s)

Member Data Documentation

std::vector<CounterSetPair> filt::GenFilter::fCounterSetPairs
private

Definition at line 35 of file GenExtCounterFilter_module.cc.

double filt::GenFilter::fCounterSizeScaleFactor
private

Definition at line 44 of file GenExtCounterFilter_module.cc.

std::vector<int> filt::GenFilter::fInterestingPDGs
private

Definition at line 41 of file GenExtCounterFilter_module.cc.

double filt::GenFilter::fParticleMaxEnergy
private

Definition at line 43 of file GenExtCounterFilter_module.cc.

double filt::GenFilter::fParticleMinEnergy
private

Definition at line 42 of file GenExtCounterFilter_module.cc.

bool filt::GenFilter::fUseEWCounterPair
private

Definition at line 38 of file GenExtCounterFilter_module.cc.

bool filt::GenFilter::fUseNdownSupCounterPair
private

Definition at line 40 of file GenExtCounterFilter_module.cc.

bool filt::GenFilter::fUseNupSdownCounterPair
private

Definition at line 39 of file GenExtCounterFilter_module.cc.


The documentation for this class was generated from the following file: