Slicer3D_module.cc
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////
2 // Class: Slicer3D
3 // Module Type: producer
4 // File: Slicer3D_module.cc
5 //
6 //////////////////////////////////////////////////////////////////////
7 
12 
18 
19 #include "DAQChannelMap/DAQChannelMap.h"
20 
21 //////////////////////////////////////////////////////////////////////
22 namespace novaddt {
23  class Slicer3D;
24 }
25 //////////////////////////////////////////////////////////////////////
27 public:
28  explicit Slicer3D(fhicl::ParameterSet const & p);
29  virtual ~Slicer3D();
30  virtual bool filter(art::Event & event);
31  void endJob() override;
32 private:
33  // Declare member data
36  unsigned fMaxCellGap;
37  unsigned fMinHit;
38 
39  // Functions
40  void makeSlice(HitList & hits, std::vector<HitList> & hitlistcol);
41  // Counters
42  int _nEvents = 0;
43  int _nInputSlices = 0;
44  int _nOutputSlices = 0;
45  int _nHitsIn = 0;
46  int _nHitsOut = 0;
47 };
48 //////////////////////////////////////////////////////////////////////
50 :
51 _InputLabel (p.get< std::string >("InputLabel" )),
52 _InputInstance (p.get< std::string >("InputInstance")),
53 fMaxCellGap (p.get< int >("MaxCellGap" )),
54 fMinHit (p.get< int >("MinHit" ))
55 
56 // Initialize member data
57 {
58  // Call appropriate Produces<>() functions
59  produces<std::vector<HitList> >("Zuk3DSlicer");
60 }
61 //////////////////////////////////////////////////////////////////////
63 {
64  // Clean up dynamic memory and other resources here.
65 }
66 //////////////////////////////////////////////////////////////////////
68 {
69  _nEvents++;
70 
71  // Array of hitlists from event (input)
72  art::Handle<std::vector<HitList> > hit_lists; // from HitList
73  event.getByLabel(_InputLabel, _InputInstance, hit_lists);
74 
75  // Array of filtered hitlists (output)
76  std::unique_ptr< std::vector<HitList> >hitList_col(new std::vector<HitList>);
77 
78  // Loop over grouped hitlists (slices) to extract hitlists
79  for(unsigned int i=0; i < hit_lists->size(); ++i){
80  HitList xHits,yHits;
81 
82  _nInputSlices++;
83  HitList const &hits = hit_lists->at(i);
84  _nHitsIn += hits.size(); // # of hits in input .root file
85 
86  for (auto hit = hits.begin(); hit != hits.end(); ++hit) {
87 
88  //Check View:
89  if (hit->View().val == daqchannelmap::X_VIEW)
90  xHits.emplace_back(*hit);
91  else yHits.emplace_back(*hit);
92  }
93 
94  if (xHits.size()>=fMinHit) makeSlice(xHits,*hitList_col);
95  if (yHits.size()>=fMinHit) makeSlice(yHits,*hitList_col);
96 
97  } // End of hitlists loop
98 
99  // Add filtered hitlists to event
100  _nOutputSlices+=hitList_col->size();
101  event.put(std::move(hitList_col),"Zuk3DSlicer");
102 
103  return true;
104 }
105 //////////////////////////////////////////////////////////////////////
106 void novaddt::Slicer3D::makeSlice(HitList & hits, std::vector<HitList> & hitlistcol)
107 {
108  //Sort this hitlist by cell (it is already sliced by plane and time)
109  std::sort(hits.begin(),hits.end(),CompareDAQHit<Cell>());
110 
111  auto itStart = hits.begin();
112  auto itEnd = hits.begin();
113 
114  while (itEnd != hits.end()) {
115  const unsigned endCell = (*itEnd).Cell().val;
116  ++itEnd;
117  const unsigned nextCell = (*itEnd).Cell().val;
118 
119  if (nextCell - endCell > fMaxCellGap) {
120  if (itEnd - itStart > fMinHit-2) {
121  HitList frag(itStart, itEnd);
122  _nHitsOut+=frag.size();
123  hitlistcol.push_back(frag);
124  }
125  itStart = itEnd;
126  }
127  }
128 
129  if (itEnd-itStart > fMinHit-2) {
130  HitList frag(itStart, itEnd);
131  _nHitsOut+=frag.size();
132  hitlistcol.push_back(frag);
133  }
134 
135 
136  return;
137 }
138 //////////////////////////////////////////////////////////////////////
140 {
141  std::cout << "=== novaddt::Slicer3D end ===" << std::endl;
142  std::cout << "\t# of events: " << _nEvents << std::endl;
143  std::cout << "\t# of slices input: " << _nInputSlices << std::endl;
144  std::cout << "\t# of slices output: " << _nOutputSlices << std::endl;
145  std::cout << "\t# of hits input: " << _nHitsIn << std::endl;
146  std::cout << "\t# of hits output: " << _nHitsOut << std::endl;
147 }
148 //////////////////////////////////////////////////////////////////////
std::vector< DAQHit > HitList
Definition: HitList.h:15
const char * p
Definition: xmltok.h:285
std::string _InputLabel
DEFINE_ART_MODULE(TestTMapFile)
std::string _InputInstance
void makeSlice(HitList &hits, std::vector< HitList > &hitlistcol)
void hits()
Definition: readHits.C:15
void endJob() override
Identifier for the X measuring view of the detector (top)
virtual bool filter(art::Event &event)
OStream cout
Definition: OStream.cxx:6
Definition: structs.h:12
Slicer3D(fhicl::ParameterSet const &p)
enum BeamMode string