TimeSlice_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TimeSlice
3 // Module Type: producer
4 // File: TimeSlice_module.cc
5 //
6 // Generated at Fri Oct 5 15:21:42 2012 by Evan Niner using artmod
7 // from art v1_01_01.
8 ////////////////////////////////////////////////////////////////////////
9 
15 
20 
21 #include <string>
22 #include <algorithm>
23 
24 namespace novaddt {
25  class TimeSlice;
26 }
27 
29 public:
30  explicit TimeSlice(fhicl::ParameterSet const & p);
31  virtual ~TimeSlice();
33  virtual bool filter(art::Event & e);
34 
35 
36 private:
39  double fTimeWindow;
40  unsigned int fMinHits;
41  // Declare member data here.
42 
43 };
44 
45 
47 :
48 _hitslabel (p.get< std::string >("hits_label")),
49 _instance (p.get< std::string >("instance" )),
50 fTimeWindow(p.get< double >("TimeWindow")),
51 fMinHits( p.get< int >("MinHits" ))
52 // Initialize member data here.
53 {
54  // Call appropriate Produces<>() functions here.
55  produces<GroupedHitList<TDC>>("TDCSlice");
56 }
57 
59 {
60  // Clean up dynamic memory and other resources here.
61 }
62 
64 {
67 
68  //make a grouped hitlist out of hits after time slicing
69  std::unique_ptr< GroupedHitList<TDC> >product(new GroupedHitList<TDC>);
70 
71  if(hits->size() > 0) *product = MakeSlice(hits);
72 
73  //put the hits into the event for later use
74  e.put(std::move(product),"TDCSlice");
75 
76  return true;
77 }
78 
79 // it is assumed that a valid HitList (ie one with entries) is passed to this method
81 {
82  std::vector<size_t> boundaries; //list of boundary points for timeslices
83 
84  //must have a boundary at start of list
85  boundaries.push_back(0);
86 
87  //range of hits to put into slice
88  auto itStart = hits->begin();
89  auto itEnd = hits->begin();
90  //testpoint to expand slice
91  auto itTest = hits->begin();
92 
93  while(true){
94  //grow slice till its size of fTimeWindow
95  while(itEnd->TDC().val - itStart->TDC().val < fTimeWindow){
96  ++itEnd;
97  if(itEnd == hits->end()) break; //out of hits
98  }
99  if(itEnd == hits->end()) break; //break all the way out
100 
101  //not enough hits in window, drop first and try again;
102  if(itEnd - itStart < fMinHits){
103  ++itStart;
104  assert(itStart <= itEnd);
105  //add boundary to partition off this hit
106  boundaries.push_back(std::distance(hits->begin(),itStart));
107  continue;
108  }
109 
110  //windown is long enough and has enough change, catch itTest up
111  //until it defines the start of a fTimeWindow-sized window ending
112  //on itEnd
113  while(itEnd->TDC().val - itTest->TDC().val > fTimeWindow) ++itTest;
114 
115  //if growing the window would cause itTest-itEnd window to
116  //not have enough hits, write out
117  if(itEnd+1 - itTest < fMinHits){
118  boundaries.push_back(std::distance(hits->begin(), itEnd));
119  itStart = itEnd;
120  continue;
121  }
122 
123  //can still legally grow window,do that
124  ++itEnd;
125  if(itEnd == hits->end()) break;
126  }
127 
128  //now add boundary for end of hitlist
129  boundaries.push_back(std::distance(hits->begin(),hits->end()));
130 
131 
132  return GroupedHitList<TDC>(hits->begin(), hits->end(), boundaries);
133 }
134 
const char * p
Definition: xmltok.h:285
DEFINE_ART_MODULE(TestTMapFile)
unsigned distance(const T &t1, const T &t2)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void hits()
Definition: readHits.C:15
void TimeSlice(const std::vector< art::Ptr< rawdata::RawDigit > > &d, unsigned int dt_tdc, unsigned int nhit, unsigned int nhitx, unsigned int nhity, std::vector< RawSlice > &slice)
Find windows in time that have significant activity in the detector.
Definition: RawUtil.cxx:111
GroupedHitList< TDC > MakeSlice(art::Handle< novaddt::HitList > &hits)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
T product(std::vector< T > dims)
TimeSlice(fhicl::ParameterSet const &p)
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
assert(nhit_max >=nhit_nbins)
virtual bool filter(art::Event &e)
Float_t e
Definition: plot.C:35