SupernovaAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: SupernovaAna
3 // Module Type: analyzer
4 // File: SupernovaAna_module.cc
5 //
6 // Generated at Fri Oct 11 08:06:27 2013 by Matthew Tamsett using artmod
7 // from cetpkgsupport v1_02_01.
8 ////////////////////////////////////////////////////////////////////////
9 
10 // ART includes
19 #include "fhiclcpp/ParameterSet.h"
20 
21 // NOvASoft includes
23 #include "DAQChannelMap/DAQChannelMap.h"
24 #include "RawData/RawTrigger.h"
25 #include "RecoBase/Cluster.h"
26 #include "RecoBase/CellHit.h"
27 #include "Utilities/func/MathUtil.h"
28 
29 // Root includes
30 #include "TH1.h"
31 #include "TH2.h"
32 //----------------------------------------------------------------------------
33 namespace sn
34 {
35  class SupernovaAna;
36 }
37 //----------------------------------------------------------------------------
39 {
40  public:
41  explicit SupernovaAna(fhicl::ParameterSet const & p);
42 
43  SupernovaAna(SupernovaAna const &) = delete;
44  SupernovaAna(SupernovaAna &&) = delete;
45  SupernovaAna & operator = (SupernovaAna const &) = delete;
46  SupernovaAna & operator = (SupernovaAna &&) = delete;
47 
48  void analyze(art::Event const & e) override;
49 
50  void beginJob();
51  void endJob();
52 
53  void FillPlaneSeperations(art::Ptr<rb::Cluster>& aSlice, int & min_cell_sep, double & min_plane_sep, double & min_sep);
54 
55  private:
56  std::string fCellHitsLabel; ///< Label of module making the cell hits
57  std::string fSlicerLabel; ///< Instance label making the slices
58  bool fVerbose; ///< Verbose output
59 
60  // counters
61  int nEvent = 0;
62 
63  // Histograms
64  TH1F* hNSlices;
65  TH1F* hSlicesNHits;
78 
79  // (time dependent 1D)
80  TH1F* h_t_SumADC;
81  TH1F* h_t_Nhits;
82  TH1F* h_t_MeanADC;
83  TH1F* h_t_NSlices;
89 
90  // (2D)
91  TH2F* hADC_vs_mb;
96 };
97 
98 //----------------------------------------------------------------------------
100  fCellHitsLabel (p.get<std::string >("CellHitsLabel")),
101  fSlicerLabel (p.get<std::string >("SlicerLabel")),
102  fVerbose (p.get<bool >("verbose"))
103 {
104  std::cout << "--- sn::SupernovaAna instantiate" << std::endl;
105  std::cout << "\t CellHitModuleLabel: " << fCellHitsLabel << std::endl;
106  std::cout << "\t SlicerLabel: " << fSlicerLabel << std::endl;
107  std::cout << "\t verbose: " << fVerbose << std::endl;
108 
110  hNSlices= tfs->make<TH1F>("NSlices", ";NSlices;Entries",200,0,7000);
111  hSlicesNHits= tfs->make<TH1F>("SlicesNHits", ";SlicesNHits;Entries",500,0,500);
112  hSlicesSumADC= tfs->make<TH1F>("SlicesSumADC", ";SlicesSumADC;Entries",400,0,20000);
113  hSlicesMeanADC= tfs->make<TH1F>("SlicesMeanADC", ";SlicesMeanADC;Entries",410,0.5,4100.5);
114  hSlicesMinInPlaneSeperation= tfs->make<TH1F>("SlicesMinInPlaneSeperation", ";hSlicesMinInPlaneSeperation;;Entries",22,-0.5,20.5);
115  hSlicesMinCrossPlaneSeperation= tfs->make<TH1F>("SlicesMinCrossPlaneSeperation", ";hSlicesMinCrossPlaneSeperation;Entries",200,-0.5,20.5);
116  hSlicesMinSeperation= tfs->make<TH1F>("SlicesMinSeperation", ";hSlicesMinSeperation;Entries",200,-0.5,20.5);
117 
118  hNNoiseSlices= tfs->make<TH1F>("NNoiseSlices", ";NSlices;Entries",200,0,7000);
119  hNoiseSlicesNHits= tfs->make<TH1F>("NoiseSlicesNHits", ";SlicesNHits;Entries",200,0,200);
120  hNoiseSlicesSumADC= tfs->make<TH1F>("NoiseSlicesSumADC", ";SlicesSumADC;Entries",200,0,10000);
121  hNoiseSlicesMeanADC= tfs->make<TH1F>("NoiseSlicesMeanADC", ";SlicesMeanADC;Entries",410,0.5,4100.5);
122  hNoiseSlicesMinInPlaneSeperation= tfs->make<TH1F>("NoiseSlicesMinInPlaneSeperation", ";hSlicesMinInPlaneSeperation;;Entries",11,-0.5,10.5);
123  hNoiseSlicesMinCrossPlaneSeperation= tfs->make<TH1F>("NoiseSlicesMinCrossPlaneSeperation", ";hSlicesMinCrossPlaneSeperation;Entries",100,-0.5,10.5);
124  hNoiseSlicesMinSeperation= tfs->make<TH1F>("NoiseSlicesMinSeperation", ";hSlicesMinSeperation;Entries",100,-0.5,10.5);
125 
126  // time dependent
127  h_t_SumADC = tfs->make<TH1F>("t_SumADC", "SumADC;Event;SumADC", 400,-.5,399.5);
128  h_t_Nhits = tfs->make<TH1F>("t_Nhits", "Nhits;Event;Nhits", 400,-.5,399.5);
129  h_t_MeanADC= tfs->make<TH1F>("t_MeanADC", "MeanADC;Event;MeanADC",400,-.5,399.5);
130  h_t_NSlices= tfs->make<TH1F>("t_NSlices", "NSlices;Event;NSlices",400,-.5,399.5);
131  h_t_SliceNHits= tfs->make<TH1F>("t_SliceNHits", "SliceNHits;Event;NSliceHits",400,-.5,399.5);
132  h_t_SliceMeanHits= tfs->make<TH1F>("t_SliceMeanHits", "SliceMeanHits;Event;SliceMeanHits",400,-.5,399.5);
133  h_t_NNoiseSlices= tfs->make<TH1F>("t_NNoiseSlices", "NNoiseSlices;Event;NNoiseSlices",400,-.5,399.5);
134  h_t_NoiseNHits= tfs->make<TH1F>("t_NoiseNHits", "NoiseNHits;Event;NoiseNHits",400,-.5,399.5);
135  h_t_NoiseMeanHits= tfs->make<TH1F>("t_NoiseMeanHits", "NoiseMeanHits;Event;NoiseMeanHits",400,-.5,399.5);
136 
137  hADC_vs_mb = tfs->make<TH2F>("ADC_vs_mb", "ADC_vs_mb;mb;ADC;entries",400,-.5,399.5,410,0.5,4100.5);
138 
139  hSlice_hits_vs_mb = tfs->make<TH2F>("Slice_hits_vs_mb", "Slice_hits_vs_mb;mb;Slice Hits;entries",400,-.5,399.5,101,-0.5,100.5);
140  hMeanADC_vs_Slice_hits = tfs->make<TH2F>("MeanADC_vs_Slice_hits", "MeanADC_vs_Slice_hits;MeanADC;Slice Hits;entries",410,0.5,4100.5,101,-0.5,100.5);
141 
142  hNoiseSlice_hits_vs_mb = tfs->make<TH2F>("NoiseSlice_hits_vs_mb", "NoiseSlice_hits_vs_mb;mb;Noise Slice Hits;entries",200,-.5,199.5,101,-0.5,100.5);
143  hNoiseMeanADC_vs_Slice_hits = tfs->make<TH2F>("NoiseMeanADC_vs_Slice_hits", "NoiseMeanADC_vs_Slice_hits;MeanADC;Slice Hits;entries",410,0.5,4100.5,101,-0.5,100.5);
144 }
145 
146 //---------------------------------------------------------------------
148 {
149  std::cout << "--- sn::SupernovaAna begin job" << std::endl;
150 }
151 
152 //---------------------------------------------------------------------
154 {
155  std::cout << "--- sn::SupernovaAna end job" << std::endl;
156  std::cout << "\tevents: " << nEvent << std::endl;
157 }
158 
159 //----------------------------------------------------------------------------
161 {
162  std::cout << "--- sn::SupernovaAna analyzer. Event: "
163  << e.id().event()
164  << ", event counter: " << nEvent
165  << std::endl;
166 
167  ++nEvent;
168 
170 
171  // Get Cell Hits
173  e.getByLabel(fCellHitsLabel, hits);
174 
175  const unsigned int nHits = hits->size();
176 
177  if (fVerbose) std::cout << "\tgot " << nHits << " cell hits" << std::endl;
178 
179  int sum_adc = 0;
180  int min_TDC = 0;
181  int max_TDC = 0;
182 
183  if (nHits > 0){
184  min_TDC = hits->at(0).TDC();
185  max_TDC = hits->at(0).TDC();
186  }
187 
188  int min_x = 999;
189  int max_x = 0;
190  int min_y = 999;
191  int max_y = 0;
192  int min_z = 999;
193  int max_z = 0;
194 
195  // Loop over Cell Hits
196  for(unsigned int hitIdx = 0; hitIdx < nHits; ++hitIdx){
197  const rb::CellHit* aHit = &(*hits)[hitIdx];
198 
199  if (aHit->TDC() < min_TDC) min_TDC = aHit->TDC();
200  if (aHit->TDC() > max_TDC) max_TDC = aHit->TDC();
201 
202  // Get plane/cell from cmap
203  const int plane = cmap->GetPlane(aHit);
204  const int cell = cmap->GetCell(aHit);
205 
206  // Set max/min plane
207  if (plane < min_z) min_z = plane;
208  if (plane > max_z) max_z = plane;
209 
210  // Set max/min cell
211  std::string view = "y";
212  if (cmap->Map()->getView(aHit->Channel()) == daqchannelmap::X_VIEW){
213  view = "x";
214  if (cell < min_x) min_x = cell;
215  if (cell > max_x) max_x = cell;
216  } else {
217  if (cell < min_y) min_y = cell;
218  if (cell > max_y) max_y = cell;
219  }
220 
221  sum_adc = sum_adc + int(aHit->ADC());
222  hADC_vs_mb->Fill(nEvent,aHit->ADC());
223  } // End of loop on cell hits
224 
225  if (fVerbose){
226  std::cout << "\tTDC: " << min_TDC
227  << " -> " << max_TDC
228  << ", dTDC: "<< max_TDC - min_TDC
229  << std::endl;
230  std::cout << "\tX: " << min_x
231  << " -> " << max_x
232  << ", Y: " << min_y
233  << " -> " << max_y
234  << ", Z: " << min_z
235  << " -> " << max_z
236  <<std::endl;
237  std::cout << "\tADC sum: " << sum_adc << std::endl;
238  } // End of if on verbose
239 
240  h_t_SumADC->SetBinContent(nEvent,sum_adc);
241  h_t_Nhits->SetBinContent(nEvent,nHits);
242 
243  if (nHits > 0){
244  h_t_MeanADC->SetBinContent(nEvent, (float(sum_adc) / nHits));
245  } else {
246  h_t_MeanADC->SetBinContent(nEvent, 0);
247  }
248 
249 
250  // Slices
252  e.getByLabel(fSlicerLabel, slices);
253 
254  double nNoiseSlices = 0.;
255  double nNoiseHits = 0.;
256  double nHitsInSlices = 0.;
257 
258  const unsigned int nSlices = slices->size();
259 
260  for(unsigned int sliceIdx = 0; sliceIdx < nSlices; ++sliceIdx){
261  art::Ptr<rb::Cluster> aSlice(slices, sliceIdx);
262 
263  int min_cell_sep = 999;
264  double min_plane_sep = 999;
265  double min_sep = 999;
266 
267  if(aSlice->IsNoise()){
268  ++nNoiseSlices;
269  nNoiseHits += aSlice->NCell();
270 
271  hNoiseSlice_hits_vs_mb->Fill(nEvent, aSlice->NCell());
272  hNoiseMeanADC_vs_Slice_hits->Fill((aSlice->TotalADC() / (double)aSlice->NCell()), aSlice->NCell());
273  hNoiseSlicesNHits->Fill(aSlice->NCell());
274  hNoiseSlicesSumADC->Fill(aSlice->TotalADC());
275  hNoiseSlicesMeanADC->Fill((aSlice->TotalADC() / (double)aSlice->NCell()));
276  //FillPlaneSeperations(aSlice, min_cell_sep, min_plane_sep, min_sep);
277  hNoiseSlicesMinInPlaneSeperation->Fill(min_cell_sep);
278  hNoiseSlicesMinCrossPlaneSeperation->Fill(min_plane_sep);
279  hNoiseSlicesMinSeperation->Fill(min_sep);
280  } else {
281  nHitsInSlices += aSlice->NCell();
282 
283  hSlice_hits_vs_mb->Fill(nEvent, aSlice->NCell());
284  hMeanADC_vs_Slice_hits->Fill((aSlice->TotalADC() / (double)aSlice->NCell()), aSlice->NCell());
285  hSlicesNHits->Fill(aSlice->NCell());
286  hSlicesSumADC->Fill(aSlice->TotalADC());
287  hSlicesMeanADC->Fill((aSlice->TotalADC() / (double)aSlice->NCell()));
288  FillPlaneSeperations(aSlice, min_cell_sep, min_plane_sep, min_sep);
289  hSlicesMinInPlaneSeperation->Fill(min_cell_sep);
290  hSlicesMinCrossPlaneSeperation->Fill(min_plane_sep);
291  hSlicesMinSeperation->Fill(min_sep);
292  }
293  } // End loop on slices
294 
295  if (fVerbose){
296  std::cout << "\tSlices: " << nSlices << std::endl;
297  std::cout << "\tNoise slices: " << nNoiseSlices << std::endl;
298  std::cout << "\tMean hits: " << nNoiseHits / nNoiseSlices << std::endl;
299  std::cout << "\tNon-noise slices: " << nSlices - nNoiseSlices << std::endl;
300  std::cout << "\tMean hits: " << nHitsInSlices / (nSlices - nNoiseSlices) << std::endl;
301  } // End of if on verbose
302 
303  // Slices
304  hNSlices->Fill(nSlices - nNoiseSlices);
305  h_t_NSlices->SetBinContent(nEvent, nSlices - nNoiseSlices);
306  h_t_SliceNHits->SetBinContent(nEvent, nHitsInSlices);
307  if( (nSlices - nNoiseSlices) > 0 ){
308  h_t_SliceMeanHits->SetBinContent(nEvent, nHitsInSlices/(nSlices - nNoiseSlices));
309  } else {
310  h_t_SliceMeanHits->SetBinContent(nEvent, 0);
311  }
312 
313  // Noise slice
314  hNNoiseSlices->Fill(nNoiseSlices);
315  h_t_NNoiseSlices->SetBinContent(nEvent, nNoiseSlices);
316  h_t_NoiseNHits->SetBinContent(nEvent, nNoiseHits);
317  if (nNoiseSlices > 0){
318  h_t_NoiseMeanHits->SetBinContent(nEvent, nNoiseHits / nNoiseSlices);
319  } else {
320  h_t_NoiseMeanHits->SetBinContent(nEvent, 0);
321  }
322 
323 }
324 
325 //----------------------------------------------------------------------------
327  int & min_cell_sep, double & min_plane_sep, double & min_sep)
328 {
329  // Loop over the hits and find the minimum seperation for each
330  for(unsigned int i = 0; i < aSlice->NCell(); ++i){
331  const art::Ptr<rb::CellHit>& ihit = aSlice->Cell(i);
332  for (unsigned int j = (i + 1); j < (aSlice->NCell() - 1); ++j){
333  const art::Ptr<rb::CellHit>& jhit = aSlice->Cell(j);
334  if (ihit->Plane() == jhit->Plane()){
335  int sep = fabs(ihit->Cell() - jhit->Cell());
336  if (sep < min_cell_sep){
337  min_cell_sep = sep;
338  //min_cell_index = j;
339  }
340  if (sep < min_sep){
341  min_sep = sep;
342  //min_index = j;
343  }
344  } else {
345  if (ihit->View() == jhit->View()){
346  double p_s = ihit->Plane() - jhit->Plane();
347  double c_s = ihit->Cell() - jhit->Cell();
348  double sep = util::pythag(p_s, c_s);
349  if (sep < min_plane_sep){
350  min_plane_sep = sep;
351  //min_plane_index = j;
352  }
353  if (sep < min_sep){
354  min_sep = sep;
355  //min_index = j;
356  }
357  }
358  }
359  } // End of inner loop
360  } // End of outer loop
361 }
362 
363 //----------------------------------------------------------------------------
unsigned int NCell(geo::View_t view) const
Number of cells in view view.
Definition: Cluster.cxx:134
int32_t TDC() const
The time of the last baseline sample.
Definition: RawDigit.h:94
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
unsigned short Plane() const
Definition: CellHit.h:39
void analyze(art::Event const &e) override
geo::View_t View() const
Definition: CellHit.h:41
virtual DetView_TYPE getView(dchan daqchan) const =0
Which view (X or Y) does this daq channel readout?
const char * p
Definition: xmltok.h:285
std::string fSlicerLabel
Instance label making the slices.
TH1F * hNoiseSlicesMinInPlaneSeperation
const daqchannelmap::DAQChannelMap * Map() const
Definition: CMap.h:57
TH1F * hSlicesMinCrossPlaneSeperation
DEFINE_ART_MODULE(TestTMapFile)
bool fVerbose
Verbose output.
unsigned short Cell() const
Definition: CellHit.h:40
double TotalADC() const
Sum of the ADC of all the contained hits.
Definition: Cluster.cxx:360
void hits()
Definition: readHits.C:15
Identifier for the X measuring view of the detector (top)
unsigned short GetPlane(const rawdata::RawDigit *dig)
Definition: CMap.cxx:285
Remove hits from hot and cold channels.
const double j
Definition: BetheBloch.cxx:29
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
const char sep
OStream cout
Definition: OStream.cxx:6
EventNumber_t event() const
Definition: EventID.h:116
art::Ptr< rb::CellHit > Cell(geo::View_t view, unsigned int viewIdx) const
Get the ith cell from view view.
Definition: Cluster.cxx:145
A rawdata::RawDigit with channel information decoded.
Definition: CellHit.h:27
T * make(ARGS...args) const
int16_t ADC(uint32_t i) const
Definition: RawDigit.cxx:58
TH1F * hNoiseSlicesMinCrossPlaneSeperation
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
double pythag(double x, double y)
2D Euclidean distance
Definition: MathUtil.h:29
uint32_t Channel() const
Definition: RawDigit.h:84
unsigned short GetCell(const rawdata::RawDigit *dig)
Definition: CMap.cxx:327
SupernovaAna(fhicl::ParameterSet const &p)
bool IsNoise() const
Is the noise flag set?
Definition: Cluster.h:163
void FillPlaneSeperations(art::Ptr< rb::Cluster > &aSlice, int &min_cell_sep, double &min_plane_sep, double &min_sep)
Float_t e
Definition: plot.C:35
std::string fCellHitsLabel
Label of module making the cell hits.
EventID id() const
Definition: Event.h:56
SupernovaAna & operator=(SupernovaAna const &)=delete
enum BeamMode string