FEBFlashFilter_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: FEBFlashFilter
3 // Module Type: filter
4 // File: FEBFlashFilter_module.cc
5 //
6 // Generated at Tue Feb 3 09:00:52 2015 by Jan Zirnstein using artmod
7 // from cetpkgsupport v1_07_01.
8 ////////////////////////////////////////////////////////////////////////
9 
17 #include "fhiclcpp/ParameterSet.h"
19 
22 
23 #include <memory>
24 #include <cstdint>
25 
26 namespace novaddt {
27  class FEBFlashFilter;
28 }
29 
31 public:
32  explicit FEBFlashFilter(fhicl::ParameterSet const & p);
33  // The destructor generated by the compiler is fine for classes
34  // without bare pointers or other resource use.
35 
36  // Plugins should not be copied or assigned.
37  FEBFlashFilter(FEBFlashFilter const &) = delete;
38  FEBFlashFilter(FEBFlashFilter &&) = delete;
39  FEBFlashFilter & operator = (FEBFlashFilter const &) = delete;
41 
42  // Required functions.
43  bool filter(art::Event & event) override;
44 
45 
46 private:
47 
48  // Declare member data here.
51  unsigned int _saturatedADC;
52  unsigned int _flasherADC;
53  unsigned int _FEBDeadTime;
54  unsigned int _numFlasherHits;
55  std::map<unsigned int, std::vector<uint64_t>> _saturatedFEBMap;
56 
57  void _addToMap(const novaddt::DAQHit& Hit);
58  bool _isItAFlasher(const novaddt::DAQHit& Hit);
59  unsigned int _febNum(const novaddt::DAQHit& Hit);
60 };
61 
62 
64 // Initialize member data here.
65 _sortedListLabel (p.get< std::string >("hits_label")),
66 _sortedListInstance (p.get< std::string >("instance")),
67 _saturatedADC (p.get< unsigned int >("saturated_ADC")),
68 _flasherADC (p.get< unsigned int >("flasher_ADC")),
69 _FEBDeadTime (p.get< unsigned int >("FEB_dead_time"))
70 {
71  std::cout << "--- novaddt::FEBFlashFilter Runtime Configuration" << std::endl;
72  std::cout << "\t Input hitlists label: " << _sortedListLabel << std::endl;
73  std::cout << "\t Input hitlists instance: " << _sortedListInstance << std::endl;
74  std::cout << "\t ADC Saturation Threshold: " << _saturatedADC << std::endl;
75  std::cout << "\t Flasher ADC Threshold: " << _flasherADC << std::endl;
76  std::cout << "\t FEB Masked off time: " << _FEBDeadTime << std::endl;
77 
78  // Call appropriate produces<>() functions here.
79  produces<HitList>("FEBFlashFiltered");
80 }
81 
83 {
84  // Implementation of required member function here.
85  // Start by reading in the hit list
87  event.getByLabel(_sortedListLabel, _sortedListInstance, hits);
88 
89  // Make a hitlist out of hits that survive the FEBFlashFilter
90  std::unique_ptr<novaddt::HitList>product(new novaddt::HitList);
91 
92  // If the hitlist is empty, bail at this point
93  if(hits->empty()) {
94  event.put(std::move(product),"FEBFlashFiltered");
95  return false;
96  }
97 
98  // initialize number of flashers to be updated
99  _numFlasherHits = 0;
100 
101  // Now do the actual heavy lifting
102  // If there is a saturated hit, add the FEB to a list/map
103  // Add the time of the hit so we can reject subsequent hits
104  for(auto ihit = hits->begin(); ihit < hits->end(); ++ihit){
105 
106  unsigned int hitADC = ihit->ADC().val;
107 
108  // If it's a saturated hit, add the info to the map
109  if(hitADC >= _saturatedADC) {
110  _addToMap(*ihit);
111 // std::cout << "FEB hit: " << _febNum(*ihit) << " with Charge: " << hitADC << " at time: " << ihit->TDC().val << std::endl;
112  }
113 
114  // If it's a flasher, don't add it to the product, just continue
115  else if(_isItAFlasher(*ihit)) continue;
116 
117  // At this point we have saturated hits, and non flashers, so add them to the product
118  product->push_back(*ihit);
119  }
120 
121  // Put the filtered list into the event and we're done
122  event.put(std::move(product),"FEBFlashFiltered");
123 
124 /* Uncomment this block if you'd like some debug output about the Flasher Map
125 
126  for(auto it= _saturatedFEBMap.cbegin(); it != _saturatedFEBMap.cend(); ++it){
127  std::cout << "Key: " << it->first << std::endl << "Values: " << std::endl;
128  for(auto vit = it->second.begin(); vit != it->second.end(); ++vit) {
129  std::cout << " " << *vit << std::endl;
130  }
131  }
132 
133  std::cout << "Removed " << _numFlasherHits << " from the event" << std::endl;
134 */
135 
136  return true;
137 }
138 
140 {
141  // Need FEB and TDC of hit
142  auto hitTDC = Hit.TDC().val;
143  //double hitTDC = Hit.TDC().val;
144  unsigned int hitFEB = _febNum(Hit);
145  // OK will have to compute FEB from Plane and Cell
146  // Efficient inserting into maps (with hint position)
147  if(_saturatedFEBMap.count(hitFEB) > 0) _saturatedFEBMap.at(hitFEB).push_back(hitTDC);
148  else {
149  auto it = _saturatedFEBMap.begin();
150  std::vector<uint64_t> temp_insert (1,hitTDC);
151  _saturatedFEBMap.insert(it, std::pair<unsigned int, std::vector<uint64_t>>(hitFEB,temp_insert));
152  }
153 
154 }
155 
157 {
158  unsigned int febnum = _febNum(Hit);
159  unsigned int hitADC = Hit.ADC().val;
160 
161  // If the ADC of the hit are above flasher threshold, it's not a flasher
162  if(hitADC >= _flasherADC) return false;
163 
164  // if the hit doesn't have it's FEB in the map yet, it's not a flasher
165  else if(_saturatedFEBMap.count(febnum) < 1) return false;
166 
167  // if the FEB is in the map, have to check timestamps to determine flasher status
168  auto hitTDC = Hit.TDC().val;
169  uint64_t conv = 15625; //15.625 ns per TDC tick
170 
171  for(auto& elem: _saturatedFEBMap.at(febnum)){
172  if((hitTDC >= elem) && (hitTDC <= (elem + (conv*_FEBDeadTime)))) {
173  _numFlasherHits++;
174  return true;
175  }
176  }
177 
178  // If we got to this point it's not a flasher
179  return false;
180 }
181 
183 {
184  // Let's define the FEB number as:
185  // Cell number div 32 plus plane number * 12
186  unsigned int febnum;
187  unsigned int hitCell = Hit.Cell().val;
188  unsigned int hitPlane = Hit.Plane().val;
189 
190  febnum = hitPlane*100 + hitCell/32;
191 
192  return febnum;
193 }
194 
set< int >::iterator it
value_type val
Definition: BaseProducts.h:34
novaddt::Plane const & Plane() const
Definition: DAQHit.h:70
novaddt::TDC const & TDC() const
Definition: DAQHit.h:74
std::vector< DAQHit > HitList
Definition: HitList.h:15
const char * p
Definition: xmltok.h:285
std::map< unsigned int, std::vector< uint64_t > > _saturatedFEBMap
value_type val
Definition: BaseProducts.h:109
bool filter(art::Event &event) override
DEFINE_ART_MODULE(TestTMapFile)
void _addToMap(const novaddt::DAQHit &Hit)
FEBFlashFilter(fhicl::ParameterSet const &p)
bool _isItAFlasher(const novaddt::DAQHit &Hit)
void hits()
Definition: readHits.C:15
novaddt::ADC const & ADC() const
Definition: DAQHit.h:73
value_type val
Definition: BaseProducts.h:84
FEBFlashFilter & operator=(FEBFlashFilter const &)=delete
unsigned int _febNum(const novaddt::DAQHit &Hit)
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T product(std::vector< T > dims)
novaddt::Cell const & Cell() const
Definition: DAQHit.h:71
value_type val
Definition: BaseProducts.h:65