SingletonRejection_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////
2 // Class: SingletonRejection
3 // Module Type: producer
4 // File: SingletonRejection_module.cc
5 //
6 // Generated at Tues June 25 2013 by Will Henderson
7 // Documentation at DOCDB 9475
8 // Modified by Matthew Tamsett Wed May 28 2014
9 // This should run after time sorting and before anything else
10 // if input hits are not time sorted then the output will be rubbish
11 //////////////////////////////////////////////////////////////////////
12 
17 
23 
24 #include "DAQChannelMap/DAQChannelMap.h"
25 
26 //////////////////////////////////////////////////////////////////////
27 namespace novaddt {
28  class SingletonRejection;
29 }
30 //////////////////////////////////////////////////////////////////////
32 public:
33  explicit SingletonRejection(fhicl::ParameterSet const & p);
34  virtual ~SingletonRejection();
35  virtual bool filter(art::Event & event);
36  void endJob() override;
37 private:
38  // Declare member data
44  // Functions
45  void filterNoise(art::Handle<novaddt::HitList> & hits, std::unique_ptr< novaddt::HitList > & product); // Use virtual and pointers for efficiency (unimplemented)
46  // Counters
47  int _nEvents = 0;
48  int _nHitsIn = 0;
49  int _nHitsOut = 0;
50 };
51 //////////////////////////////////////////////////////////////////////
53 :
54 fInputLabel (p.get< std::string >("InputLabel" )),
55 fInputInstance (p.get< std::string >("InputInstance")),
56 fMinCellSep (p.get< int >("MinCellSep" )),
57 fMinPlaneSep (p.get< int >("MinPlaneSep" )),
58 fMinTDCSep (p.get< int >("MinTDCSep" ))
59 // Initialize member data
60 {
61  std::cout << "--- novaddt::SingletonRejection begin" << std::endl;
62  std::cout << "\t Input hitlists label: " << fInputLabel << std::endl;
63  std::cout << "\t Input hitlists instance " << fInputInstance << std::endl;
64  std::cout << "\t Min X or Y separation: " << fMinCellSep << std::endl;
65  std::cout << "\t Min Z separation: " << fMinPlaneSep << std::endl;
66  std::cout << "\t Min time separation: " << fMinTDCSep << std::endl;
67 
68  // Call appropriate Produces<>() functions
69  produces<novaddt::HitList>("SingletonRejected");
70 }
71 //////////////////////////////////////////////////////////////////////
73 {
74  // Clean up dynamic memory and other resources here.
75 }
76 //////////////////////////////////////////////////////////////////////
78 {
79  _nEvents++;
80 
81  // Array of hitlist from event (input)
83  event.getByLabel(fInputLabel, fInputInstance, hits);
84  _nHitsIn+=hits->size();
85 
86  // Array of filtered hits (output)
87  std::unique_ptr< novaddt::HitList >final_product(new novaddt::HitList);
88 
89  // Remove noise
90  filterNoise(hits, final_product);
91 
92 
93  // Add filtered hitlists to event
94  _nHitsOut+=final_product->size();
95  event.put(std::move(final_product),"SingletonRejected");
96 
97  return true;
98 }
99 //////////////////////////////////////////////////////////////////////
101 {
102  unsigned int n_hits = hits->size(); // # of hits in this hitlist
103 
104  unsigned int lower_limit = 0; // the lower index to start checking for a correlated hit at
105 
106  for (unsigned int i=0; i<n_hits; ++i){
107  //std::cout << "\thit[" << i
108  //<< "], TDC: " << hits->at(i).TDC().val
109  //<< ", View: " << hits->at(i).View().val
110  //<< ", Plane: " << hits->at(i).Plane().val
111  //<< ", Cell: " << hits->at(i).Cell().val
112  //<< std::endl;
113  for (unsigned int j=lower_limit; j<n_hits; ++j){
114  if (i == j) continue;
115  // check if hits are causally correlated
116  if (fabs((int)hits->at(i).TDC().val - (int)hits->at(j).TDC().val) > fMinTDCSep){
117  // if they aren't & j is lower than i
118  // then we ignore this hit
119  // & next time we start the inner loop at this point
120  if (j < i){
121  lower_limit = j;
122  continue;
123  // similarly if j is the next hit in the list
124  // then j can also not be correlated with i
125  // so we advance the lower limit now
126  // and break the inner loop
127  } else if (j == i+1){
128  lower_limit = j;
129  break;
130  // else break inner loop here
131  } else {
132  break;
133  }
134  } // end of check on causal correlation
135  // check view correlation
136  if (hits->at(i).View().val != hits->at(j).View().val) continue;
137  // check plane correlation
138  // have to cast these to ints so we can handle negative values
139  if (fabs((int)hits->at(i).Plane().val - (int)hits->at(j).Plane().val) > fMinPlaneSep) continue;
140  // check cell correlation
141  if (fabs((int)hits->at(i).Cell().val - (int)hits->at(j).Cell().val) > fMinCellSep) continue;
142  product->push_back(hits->at(i));
143  break;
144  } // end of inner loop on hits
145  } // end of outer loop on hits
146 
147 
148  return;
149 }
150 //////////////////////////////////////////////////////////////////////
152 {
153  std::cout << "--- novaddt::SingletonRejection end " << std::endl;
154  std::cout << "\t# of events: " << _nEvents << std::endl;
155  std::cout << "\t# of hits input: " << _nHitsIn << std::endl;
156  std::cout << "\t# of hits output: " << _nHitsOut << std::endl;
157 }
158 //////////////////////////////////////////////////////////////////////
void filterNoise(art::Handle< novaddt::HitList > &hits, std::unique_ptr< novaddt::HitList > &product)
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
std::vector< DAQHit > HitList
Definition: HitList.h:15
const char * p
Definition: xmltok.h:285
DEFINE_ART_MODULE(TestTMapFile)
virtual bool filter(art::Event &event)
void hits()
Definition: readHits.C:15
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6
SingletonRejection(fhicl::ParameterSet const &p)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T product(std::vector< T > dims)