ActivityTriggerAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ActivityTrigger
3 // Module Type: filter
4 // File: ActivityTrigger_module.cc
5 //
6 // Generated at Wed Sep 12 16:15:01 2012 by Nova DDT using artmod
7 // from art v1_01_01.
8 ////////////////////////////////////////////////////////////////////////
9 
16 
23 
24 #include "DAQDataFormats/DAQDataFormats.h"
25 
26 #include <string>
27 #include <algorithm>
28 #include <unordered_set>
29 
30 // ROOT includes
31 #include <TTree.h>
32 #include <TH1I.h>
33 
34 namespace novaddt {
35  class ActivityTriggerAna;
36 }
37 
39 
40 public:
41  explicit ActivityTriggerAna(fhicl::ParameterSet const & p);
42  virtual ~ActivityTriggerAna();
43 
44  virtual bool filter(art::Event & e);
45 
46  void beginJob() override;
47 
48 private:
49 
50  std::string _hitsModuleLabel; ///< label of module making the HitList
51  std::string _hitsInstanceLabel; ///< instance label making the HitList
52  unsigned int _minHits; ///< Minimum number of hits in the slice
53  unsigned int _minPlanesView; ///< Minimum planes (unique) on each view
54  unsigned int _minPlanes; ///< Minimum planes (unique) the hits are spread in any view
55  unsigned int _maxNearWindow; ///< Maximum window where to look for near planes
56  unsigned int _minNearPlanes; ///< Minimum number of near planes
57  unsigned int _prescale; ///< holds prescaling variable from fcl file
58 
59  unsigned int _triggerCounts = 0;
60  unsigned int _sliceCounts = 0;
61  unsigned int _evtCounts = 0;
62 
64  TTree *fTree;
65  TH1I *fHisto;
66  unsigned int fHits;
67  unsigned int fXPlanes;
68  unsigned int fYPlanes;
69  unsigned int fPlanes;
71 };
72 
73 //---------------------------------------------------------------------
75  : _hitsModuleLabel (p.get<std::string >("HitModuleLabel" ))
76  , _hitsInstanceLabel(p.get<std::string >("HitInstanceLabel"))
77  , _minHits (p.get<unsigned int>("MinHits" ))
78  , _minPlanesView (p.get<unsigned int>("MinPlanesView" ))
79  , _minPlanes (p.get<unsigned int>("MinPlanes" ))
80  , _maxNearWindow (p.get<unsigned int>("MaxNearWindow" ))
81  , _minNearPlanes (p.get<unsigned int>("MinNearPlanes" ))
82  , _prescale (p.get<unsigned int>("prescale" ))
83 {
84  produces< std::vector<novaddt::TriggerDecision> >();
85  //produces< art::Assns<novaddt::TriggerDecision, novaddt::HitList> >();
86 }
87 
88 //---------------------------------------------------------------------
90 {
91  // Clean up dynamic memory and other resources here.
92 }
93 
95 {
96  // Output Histogram
97  fHisto = tfs->make<TH1I>("fHisto","Histogram;ADCs;Entries",400,0,4000);
98  fTree = tfs->make<TTree>("fTree","Output tree");
99  fTree->Branch("Hits",&fHits);
100  fTree->Branch("XPlanes",&fXPlanes);
101  fTree->Branch("YPlanes",&fYPlanes);
102  fTree->Branch("Planes",&fPlanes);
103  fTree->Branch("Continuity",&fContinuity);
104 }
105 
106 //---------------------------------------------------------------------
108 {
109  //std::cout << "--- ActivityTriggerAna filter\n";
110  ++_evtCounts;
111 
112  // Retrieve the (grouped) hit list for this event
115  //std::cout << "\tgot " << hits->n_groups()
116  // << " groups.\n";
117 
118  // Allocate the vector for the trigger decisions that we may make (and write to the event)
119  std::unique_ptr<std::vector<novaddt::TriggerDecision>> td(new std::vector<novaddt::TriggerDecision>);
120 
121  std::unordered_set<int> XplaneList;
122  std::unordered_set<int> YplaneList;
123  std::unordered_set<int> planeList;
124 
125  // Loop over the slices in the event
126  for(unsigned int i=0; i<hits->n_groups(); ++i){
127 
128  // Get the hits for the current slice
129  novaddt::HitList theSliceHits = hits->get(i);
130 
131  XplaneList.clear();
132  YplaneList.clear();
133  planeList.clear();
134  fContinuity = false;
135  // Safety checks in case we mess up the fickle file
137  if(!(_maxNearWindow * _minNearPlanes)) fContinuity = true;
138 
139  ++_sliceCounts;
140 
141  fHits = theSliceHits.size();
142  for(unsigned int j=0; j < theSliceHits.size(); ++j){
143  auto thePlane = theSliceHits.at(j).Plane().val;
144  // Push the plane into the list of unique planes
145  auto theView = theSliceHits.at(j).View().val;
146  if(theView == daqchannelmap::X_VIEW) XplaneList.insert(thePlane);
147  else if(theView == daqchannelmap::Y_VIEW) YplaneList.insert(thePlane);
148  planeList.insert(thePlane);
149 
150  fHisto->Fill(theSliceHits.at(j).ADC().val);
151  } // endfor j
152 
153  fXPlanes = XplaneList.size();
154  fYPlanes = YplaneList.size();
156 
157  for(auto iPlane=planeList.begin(); iPlane!=planeList.end(); ++iPlane)
158  {
159  if(!fContinuity)
160  {
161  unsigned int fNearPlanes = 0;
162  for(unsigned int j=1; j<=_maxNearWindow; ++j)
163  fNearPlanes += planeList.count(*iPlane+j);
164 
165  if(fNearPlanes >= _minNearPlanes)
166  fContinuity = true;
167  }
168  } // end of continuity check
169 
170  // Now the trigger requirements
171  if(fHits >= _minHits)
172  if(fPlanes >= _minPlanes)
173  if(fXPlanes >= _minPlanesView)
174  if(fYPlanes >= _minPlanesView)
175  if(fContinuity)
176  ++_triggerCounts;
177 
178  fTree->Fill();
179  } // end loop on hit groups
180 
181  bool goodTrigger = (td->size() > 0);
182 
183  e.put(std::move(td));
184 
185  std::cout << "Frequency: " << _triggerCounts*1./(_evtCounts*5.e-3) << " pm "
186  << sqrt(_triggerCounts*(_evtCounts-_triggerCounts)*1./_evtCounts)/(_evtCounts*5.e-3) << " Hz" << std::endl; // Binomial Error
187 
188  return goodTrigger;
189 }
190 
unsigned int _minPlanesView
Minimum planes (unique) on each view.
unsigned int _minHits
Minimum number of hits in the slice.
std::vector< DAQHit > HitList
Definition: HitList.h:15
unsigned int _prescale
holds prescaling variable from fcl file
const char * p
Definition: xmltok.h:285
T sqrt(T number)
Definition: d0nt_math.hpp:156
virtual bool filter(art::Event &e)
DEFINE_ART_MODULE(TestTMapFile)
unsigned int _minPlanes
Minimum planes (unique) the hits are spread in any view.
std::string _hitsInstanceLabel
instance label making the HitList
Identifier for the Y measuring view of the detector (side)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void hits()
Definition: readHits.C:15
Identifier for the X measuring view of the detector (top)
const double j
Definition: BetheBloch.cxx:29
OStream cout
Definition: OStream.cxx:6
art::ServiceHandle< art::TFileService > tfs
std::string _hitsModuleLabel
label of module making the HitList
T * make(ARGS...args) const
unsigned int _maxNearWindow
Maximum window where to look for near planes.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
void clear()
Definition: Handle.h:236
Float_t e
Definition: plot.C:35
ActivityTriggerAna(fhicl::ParameterSet const &p)
unsigned int _minNearPlanes
Minimum number of near planes.
enum BeamMode string