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

Public Member Functions

 FilterGenInTime (fhicl::ParameterSet const &pset)
 
bool filter (art::Event &)
 
virtual 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 KeepParticle (simb::MCParticle const &part) const
 

Private Attributes

std::vector< std::array< double, 6 > > fCryostatBoundaries
 boundaries of each cryostat More...
 
double fMinKE
 
bool fKeepOnlyMuons
 
double fMinT
 
double fMaxT
 
bool fSortParticles
 
bool fAlwaysPass
 

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 38 of file FilterGenInTime_module.cc.

Constructor & Destructor Documentation

simfilter::FilterGenInTime::FilterGenInTime ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 64 of file FilterGenInTime_module.cc.

64  :
65  EDFilter{pset},
66  fMinKE (pset.get< double > ("MinEnergy" , 0.0) )
67  , fKeepOnlyMuons (pset.get< bool > ("KeepOnlyMuons", false) )
68  , fMinT (pset.get< double > ("MinT",0.0) )
69  , fMaxT (pset.get< double > ("MaxT") )
70  , fSortParticles ( pset.get< bool > ("SortParticles",false) )
71  , fAlwaysPass (pset.get<bool>("AlwaysPass",false))
72  {
73  if(fSortParticles) {
74  produces< std::vector<simb::MCTruth> >("intime");
75  produces< std::vector<simb::MCTruth> >("outtime");
76  }
77  std::cout << "New Filter!\n";
78 
79  }
EDFilter(fhicl::ParameterSet const &pset)
Definition: EDFilter.h:21

Member Function Documentation

void simfilter::FilterGenInTime::beginJob ( )
virtual

Reimplemented from art::EDFilter.

Definition at line 81 of file FilterGenInTime_module.cc.

81  {
82  auto const& geom = *art::ServiceHandle<geo::Geometry const>();
83  for (auto const &cryo: geom.IterateCryostats()) {
84  std::array<double, 6> this_cryo_boundaries {};
85  cryo.Boundaries(&this_cryo_boundaries[0]);
86  fCryostatBoundaries.push_back(this_cryo_boundaries);
87  }
88  }
std::vector< std::array< double, 6 > > fCryostatBoundaries
boundaries of each cryostat
bool simfilter::FilterGenInTime::filter ( art::Event evt)
virtual

Implements art::EDFilter.

Definition at line 222 of file FilterGenInTime_module.cc.

222  {
223 
224  std::unique_ptr< std::vector<simb::MCTruth> > truthInTimePtr(new std::vector<simb::MCTruth>(1));
225  std::unique_ptr< std::vector<simb::MCTruth> > truthOutOfTimePtr(new std::vector<simb::MCTruth>(1));
226 
227  simb::MCTruth & truthInTime = truthInTimePtr->at(0);
228  simb::MCTruth & truthOutOfTime = truthOutOfTimePtr->at(0);
229 
230 
231  //get the list of particles from this event
233 
234  //std::vector< art::Handle< std::vector<simb::MCTruth> > > allmclists;
235  //evt.getManyByType(allmclists);
236  auto allmclists = evt.getMany< std::vector<simb::MCTruth> >();
237  bool keepEvent=false;
238  for(size_t mcl = 0; mcl < allmclists.size(); ++mcl){
239  art::Handle< std::vector<simb::MCTruth> > mclistHandle = allmclists[mcl];
240  for(size_t m = 0; m < mclistHandle->size(); ++m){
241  art::Ptr<simb::MCTruth> mct(mclistHandle, m);
242 
243  for(int ipart=0;ipart<mct->NParticles();ipart++){
244  bool kp=KeepParticle(mct->GetParticle(ipart));
245 
246  if(kp
247  && (!fKeepOnlyMuons || abs(mct->GetParticle(ipart).PdgCode())==13 )
248  && mct->GetParticle(ipart).E()-mct->GetParticle(ipart).Mass()>fMinKE){
249  keepEvent = true;
250  if(!fSortParticles) break;
251  }
252 
253  if(fSortParticles){
254  simb::MCParticle particle = mct->GetParticle(ipart);
255  if(kp) truthInTime.Add(particle);
256  if(!kp) truthOutOfTime.Add(particle);
257  }
258 
259  }//end loop over particles
260 
261  if(!fSortParticles && keepEvent) break;
262 
263  }//end loop over mctruth col
264 
265  if(!fSortParticles && keepEvent) break;
266 
267  }//end loop over all mctruth lists
268 
269  if(fSortParticles){
270  evt.put(std::move(truthInTimePtr),"intime");
271  evt.put(std::move(truthOutOfTimePtr),"outtime");
272  }
273 
274  return (keepEvent || fAlwaysPass);
275  }
T abs(T value)
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:479
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
bool KeepParticle(simb::MCParticle const &part) const
Event generator information.
Definition: MCTruth.h:32
bool simfilter::FilterGenInTime::KeepParticle ( simb::MCParticle const &  part) const
private

Definition at line 91 of file FilterGenInTime_module.cc.

91  {
92  const TLorentzVector& v4 = part.Position();
93  const TLorentzVector& p4 = part.Momentum();
94  // origin of particle
95  double x0[3] = {v4.X(), v4.Y(), v4.Z() };
96  // normalized direction of particle
97  double dx[3] = {p4.Px() / p4.Vect().Mag(), p4.Py() / p4.Vect().Mag(), p4.Pz() / p4.Vect().Mag()};
98 
99  // tolernace for treating number as "zero"
100  double eps = 1e-5;
101 
102  //check to see if particle crosses boundary of any cryostat within appropriate time window
103  std::vector<bool> intersects_cryo(fCryostatBoundaries.size(), false);
104  std::vector<bool> inside_cryo(fCryostatBoundaries.size(), false);
105  std::vector<double> distance_to_cryo(fCryostatBoundaries.size(), 0.);
106 
107  // Check to see if particle intersects any cryostat
108  //
109  // Algorithmically, this is looking for ray-box intersection. This is a common problem in
110  // computer graphics. The algorithm below is taken from "Graphics Gems", Academic Press, 1990
111  for (size_t i_cryo = 0; i_cryo < fCryostatBoundaries.size(); i_cryo++) {
112  auto const &bound = fCryostatBoundaries[i_cryo];
113  std::array<int, 3> quadrant {}; // 0 == RIGHT, 1 == LEFT, 2 == MIDDLE
114  std::array<double, 3> candidatePlane {};
115  std::array<double, 3> coord {};
116 
117  std::array<double, 3> bound_lo = {{bound[0], bound[2], bound[4]}};
118  std::array<double, 3> bound_hi = {{bound[1], bound[3], bound[5]}};
119 
120  // First check if origin is inside box
121  // Also check which of the two planes in each dimmension is the
122  // "candidate" for the ray to hit
123  bool inside = true;
124  for (int i = 0; i < 3; i++) {
125  if (x0[i] < bound_lo[i]) {
126  quadrant[i] = 1; // LEFT
127  candidatePlane[i] = bound_lo[i];
128  inside = false;
129  }
130  else if (x0[i] > bound_hi[i]) {
131  quadrant[i] = 0; // RIGHT
132  candidatePlane[i] = bound_hi[i];
133  inside = false;
134  }
135  else {
136  quadrant[i] = 2; // MIDDLE
137  }
138  }
139 
140  if (inside) {
141  inside_cryo[i_cryo] = true;
142  // if we're inside the cryostat, then we do intersect it
143  intersects_cryo[i_cryo] = true;
144  continue;
145  }
146 
147  // ray origin is outside the box -- calculate the distance to the cryostat and see if it intersects
148 
149  // calculate distances to candidate planes
150  std::array<double, 3> maxT {};
151  for (int i = 0; i < 3; i++) {
152  if (quadrant[i] != 2 /* MIDDLE */ && abs(dx[i]) > eps) {
153  maxT[i] = (candidatePlane[i] - x0[i]) / dx[i];
154  }
155  // if a ray origin is between two the two planes in a dimmension, it would never hit that plane first
156  else {
157  maxT[i] = -1;
158  }
159  }
160 
161  // The plane on the box that the ray hits is the one with the largest distance
162  int whichPlane = 0;
163  for (int i = 1; i < 3; i++) {
164  if (maxT[whichPlane] < maxT[i]) whichPlane = i;
165  }
166 
167  // check if the candidate intersection point is inside the box
168 
169  // no intersection
170  if (maxT[whichPlane] < 0.) {
171  intersects_cryo[i_cryo] = false;
172  continue;
173  }
174 
175  for (int i = 0; i < 3; i++) {
176  if (whichPlane != i) {
177  coord[i] = x0[i] + maxT[whichPlane] * dx[i];
178  }
179  else {
180  coord[i] = candidatePlane[i];
181  }
182  }
183 
184 
185  // check if intersection is in box
186  intersects_cryo[i_cryo] = true;
187  for (int i = 0; i < 3; i++) {
188  if (coord[i] < bound_lo[i] || coord[i] > bound_hi[i]) {
189  intersects_cryo[i_cryo] = false;
190  }
191  }
192 
193  if (intersects_cryo[i_cryo]) {
194  distance_to_cryo[i_cryo] = maxT[whichPlane];
195  }
196  }
197 
198  // check if any cryostats are intersected in-time
199  for (size_t i_cryo = 0; i_cryo < fCryostatBoundaries.size(); i_cryo++) {
200 
201  // If the particle originates inside the cryostat, then
202  // we can't really say when it will leave. Thus, accept
203  // the particle
204  if (inside_cryo[i_cryo]) {
205  return true;
206  }
207  // otherwise check arrival time at boundary of cryostat
208  if (intersects_cryo[i_cryo]){
209  double ptime = (distance_to_cryo[i_cryo] * 1e-2 /* cm -> m */) / (TMath::C()*sqrt(1-pow(part.Mass()/part.E(),2))) /* velocity */;
210  double totT=part.T()+ptime*1e9 /* s -> ns */;
211  if(totT>fMinT && totT<fMaxT){
212  return true;
213  }
214  }
215  }
216 
217 
218 
219  return false;
220  }
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
constexpr T pow(T x)
Definition: pow.h:72
std::vector< std::array< double, 6 > > fCryostatBoundaries
boundaries of each cryostat
T abs(T value)
const double e

Member Data Documentation

bool simfilter::FilterGenInTime::fAlwaysPass
private

Definition at line 57 of file FilterGenInTime_module.cc.

std::vector<std::array<double, 6> > simfilter::FilterGenInTime::fCryostatBoundaries
private

boundaries of each cryostat

Definition at line 52 of file FilterGenInTime_module.cc.

bool simfilter::FilterGenInTime::fKeepOnlyMuons
private

Definition at line 54 of file FilterGenInTime_module.cc.

double simfilter::FilterGenInTime::fMaxT
private

Definition at line 55 of file FilterGenInTime_module.cc.

double simfilter::FilterGenInTime::fMinKE
private

Definition at line 53 of file FilterGenInTime_module.cc.

double simfilter::FilterGenInTime::fMinT
private

Definition at line 55 of file FilterGenInTime_module.cc.

bool simfilter::FilterGenInTime::fSortParticles
private

Definition at line 56 of file FilterGenInTime_module.cc.


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