TriCellTrigger_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TriCellTrigger
3 // Module Type: filter
4 // File: TriCellTrigger_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 <string>
25 #include <algorithm>
26 
27 namespace novaddt {
28  class TriCellTrigger;
29 }
30 
32 
33 public:
34  explicit TriCellTrigger(fhicl::ParameterSet const & p);
35  virtual ~TriCellTrigger();
36 
37  virtual bool filter(art::Event & e);
38 
39 private:
40 
41  std::string _trackModuleLabel; ///< label of module making the HitList
42  std::string _trackInstanceLabel; ///< instance label making the HitList
43  float _minFraction; ///< minimum fraction of usable hits in
44  ///< a slice for the trigger to be written out
45  unsigned int _minPlanesCrossed; ///< minimum planes crossed in a slice to be used
46  unsigned _triggerCounts; ///< prescaling variable
47  unsigned _prescale; ///< holds prescaling variable from fcl file
48  unsigned _event_prescale; ///< holds event prescaling variable from fcl file
49 };
50 
51 //---------------------------------------------------------------------
53  : _trackModuleLabel (p.get<std::string >("TrackModuleLabel" ))
54  , _trackInstanceLabel(p.get<std::string >("TrackInstanceLabel", ""))
55  , _minFraction (p.get<float >("MinFraction" ))
56  , _minPlanesCrossed (p.get<unsigned int>("MinPlanesCrossed" ))
57  , _triggerCounts (0)
58  , _prescale (p.get<unsigned >("prescale" ))
59  , _event_prescale (p.get<unsigned >("EventPrescale" ))
60 {
61  produces< std::vector<novaddt::TriggerDecision> >();
62  produces< art::Assns<novaddt::TriggerDecision, novaddt::HitList> >();
63 }
64 
65 //---------------------------------------------------------------------
67 {
68  // Clean up dynamic memory and other resources here.
69 }
70 
71 //---------------------------------------------------------------------
73 {
74  // get the hit lists for this slice
77 
78  // make the vector we are going to write out to the event
79  std::unique_ptr<std::vector<novaddt::TriggerDecision>> td(new std::vector<novaddt::TriggerDecision>);
80  std::unique_ptr<art::Assns<novaddt::TriggerDecision, novaddt::HitList> > assn(new art::Assns<novaddt::TriggerDecision, novaddt::HitList >);
81 
82  std::map<unsigned short, std::set<unsigned short>> planesAndCells;
83 
84  // get the hit list for each track
86  for(size_t t = 0; t < th->size(); ++t){
87 
88  planesAndCells.clear();
89 
90  art::Ptr<novaddt::HitList> hl = fohl.at(t);
91  // first fill the map of planes and cells
92  for(auto const& i : *hl){
93  planesAndCells[i.Plane().val].insert(i.Cell().val);
94 
95  LOG_DEBUG("TriCellTrigger") << "plane: " << i.Plane().val
96  << " cell: " << i.Cell().val;
97  }
98 
99  // if this track doesn't cross enough planes,
100  // or have enough hits continue to the next one and try that
101  if(std::abs(th->at(t).EndZ() - th->at(t).StartZ()) < _minPlanesCrossed ||
102  hl->size() < _minPlanesCrossed) continue;
103 
104  // now loop over the planes and cells to determine
105  // the fraction in this list that have both neighbors also hit
106  float totalCells = 0.;
107  float goodCells = 0.;
108 
109  for(auto const& pcitr : planesAndCells){
110  // get the set for the current plane
111  // sets are presorted, go c++
112  std::set<unsigned short> cellSet = pcitr.second;
113 
114  // put the iterator over the set to the second entry
115  auto citr = cellSet.cbegin();
116  totalCells += 1.;
117  ++citr;
118 
119  // loop over the cells and look to see if there is
120  // a cell in this plane that has both its neighbors also
121  // hit on this track
122  // is it faster to sort the set first and then search?
123  while( citr != cellSet.cend() ){
124  if( cellSet.find(*citr - 1) != cellSet.end() &&
125  cellSet.find(*citr + 1) != cellSet.end() ){
126  goodCells += 1.;
127  }
128  totalCells += 1.;
129 
130  ++citr;
131  }// end iterator over cells for this plane
132 
133  }// end loop to count the tri-cell groupings
134 
135  if(goodCells > _minFraction*totalCells)
136  {
137  ++_triggerCounts;
138  if (_triggerCounts % _prescale == _prescale - 1)
139  {
140  td->emplace_back(hl->front().TDC().val,
141  hl->back().TDC().val - hl->front().TDC().val,
144 
145  util::CreateAssn(*this, e, *td, hl, *assn);
146 
147  LOG_DEBUG("TriCellTrigger") << "make the trigger decision "
148  << td->back().start()
149  << " " << td->back().duration()
150  << " " << goodCells
151  << " " << totalCells
152  << " " << hl->size();
153  }
154 
155  }// end if we have a good trigger with this GHL
156 
157  } // end loop over grouped hit list
158 
159  bool goodTrigger = (td->size() > 0);
160 
161  e.put(std::move(td));
162  e.put(std::move(assn));
163 
164  return goodTrigger;
165 }
166 
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
virtual bool filter(art::Event &e)
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
const char * p
Definition: xmltok.h:285
DEFINE_ART_MODULE(TestTMapFile)
float abs(float number)
Definition: d0nt_math.hpp:39
std::string _trackInstanceLabel
instance label making the HitList
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
unsigned _prescale
holds prescaling variable from fcl file
TriCellTrigger(fhicl::ParameterSet const &p)
std::string _trackModuleLabel
label of module making the HitList
unsigned _event_prescale
holds event prescaling variable from fcl file
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
unsigned _triggerCounts
prescaling variable
Float_t e
Definition: plot.C:35
Definition: fwd.h:28
unsigned int _minPlanesCrossed
minimum planes crossed in a slice to be used