SNAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: SNAna
3 // Module Type: analyzer
4 // File: SNAna_module.cc
5 //
6 // Generated at Mon Sep 1 04:46:09 2014 by Alec Habig using artmod
7 // from cetpkgsupport v1_07_00.
8 ////////////////////////////////////////////////////////////////////////
9 
18 #include "fhiclcpp/ParameterSet.h"
20 
21 // Added after artmod creation
25 
26 #include <TH1.h>
27 #include <TH2.h>
28 #include <tuple>
29 // end new includes
30 
31 namespace novaddt {
32  class SNAna;
33 }
34 
36 public:
37  explicit SNAna(fhicl::ParameterSet const & p);
38  // The destructor generated by the compiler is fine for classes
39  // without bare pointers or other resource use.
40 
41  // Plugins should not be copied or assigned.
42  SNAna(SNAna const &) = delete;
43  SNAna(SNAna &&) = delete;
44  SNAna & operator = (SNAna const &) = delete;
45  SNAna & operator = (SNAna &&) = delete;
46 
47  // Required functions.
48  void analyze(art::Event const & e) override;
49 
50  // Selected optional functions.
51  void beginJob() override;
52  void endJob() override;
53 
54 private:
55 
56  // Declare member data here.
57  typedef std::tuple<unsigned, double, double> Binning;
58 
59  void make_histo(std::string const name, std::string const title,
60  Binning const& bin);
61 
67 
68  std::map<std::string, TH1*> h_;
69  std::map<std::string, TH2*> h2_;
71 
72 };
73 
74 
76  :
77  EDAnalyzer(p),
78  // More initializers here.
79  slice_label_ (p.get<std::string >("slice_label")),
80  slice_instance_ (p.get<std::string >("slice_instance")),
81  fMaxPlaneSep (p.get< int >("MaxPlaneSep" )),
82  fMaxTDCSep (p.get< int >("MaxTDCSep" )),
83  fMinSliceSize (p.get< int >("MinSliceSize" )),
84  fMaxSliceSize (p.get< int >("MaxSliceSize" ))
85 {
86  std::cout << "--- novaddt::SNAna begin" << std::endl;
87  std::cout << "\t Input slices label: " << slice_label_ << std::endl;
88  std::cout << "\t Input slices instance: " << slice_instance_<< std::endl;
89  std::cout << "\t Max Z separation: " << fMaxPlaneSep << std::endl;
90  std::cout << "\t Max time separation: " << fMaxTDCSep << std::endl;
91  std::cout << "\t Min slice size: " << fMinSliceSize << std::endl;
92  std::cout << "\t Max slice size: " << fMaxSliceSize << std::endl;
93 }
94 
96 {
97  // THis Ana module digests slices in the form of vectors of hitlists
98  // probably generated by HitSlicers/Multiplet
101 
102  // record number of events (we're simulating 200)
103  h_["counter"]->Fill(0);
104  h_["counter_precut"]->Fill(0);
105 
106  for (auto const& slice : *slices)
107  {
108  // skip noise slice, the last one
109  if (slice == slices->back()) continue;
110  // record initial number of slices
111  h_["counter_precut"]->Fill(1);
112  // int llasttdc = 0;
113  // int llastplane = 0;
114  // for (auto const& hit : slice) {
115  // if (slice.size()>=40) {
116  // if (llasttdc!=0) {
117  // int tdcdelta = abs((int)hit.TDC().val-llasttdc);
118  // std::cout << "next hit: tdc delta:"<< tdcdelta;
119  // int planedelta = abs((int)hit.Plane().val-llastplane);
120  // std::cout << " plane delta:" << planedelta<< std::endl;
121  // }
122  // // record the last values of things we're differencing
123  // llasttdc = (int)hit.TDC().val;
124  // llastplane = (int)hit.Plane().val;
125  // }
126  // }
127  double adc_sum = 0.0;
128 
129  int lasttdc = 0;
130  int lastplane = 0;
131  unsigned int slicehits = 0;
132  unsigned int slicehits_precut = 0;
133 
134  // loop over hits in slice, decide to keep it or not
135  bool keepit = true;
136  for (auto const& hit : slice) {
137  // record all-hits stats
138  auto adc = hit.ADC().val;
139  h_["adc_all_hits"]->Fill(adc);
140  adc_sum += adc;
141  slicehits_precut++;
142  h_["counter_precut"]->Fill(2);
143  h_["plane_all_hits"]->Fill(hit.Plane().val);
144  h_["cell_all_hits"]->Fill(hit.Cell().val);
145 
146  // if this isn't the first hit in a slice, do stuff
147  if (lasttdc !=0 ) {
148  int tdcdelta = abs((int)hit.TDC().val-lasttdc);
149  // std::cout << "next hit: tdc delta:"<< tdcdelta;
150  int planedelta = abs((int)hit.Plane().val-lastplane);
151  // std::cout << " plane delta:" << planedelta<< std::endl;
152  h_["plane_delta_precut"]->Fill((double)planedelta);
153  h_["tdc_delta_precut"]->Fill((double)tdcdelta);
154  if ((planedelta <= fMaxPlaneSep) && (tdcdelta <= fMaxTDCSep))
155  slicehits++;
156  else
157  keepit = false;; // to big a gap in this slice, bail
158  }// else std::cout << "first hit"<<std::endl;
159 
160  // record the last values of things we're differencing
161  lasttdc = (int)hit.TDC().val;
162  lastplane = (int)hit.Plane().val;
163  }
164  // plus-1 because we only started counting on hit 2, to get deltas
165  if (keepit
166  && (((slicehits+1)>=fMinSliceSize) && ((slicehits+1)<=fMaxSliceSize)))
167  h_["counter"]->Fill(1); // record we're keeping a slice
168  else
169  keepit = false;
170 
171  // now go do some stats on the slice if we're keeping it
172  slicehits = 0;
173  lasttdc = 0;
174  lastplane = 0;
175  if (keepit) {
176  for (auto const& hit : slice) {
177  slicehits++;
178  h_["counter"]->Fill(2);
179 
180  // if this isn't the first hit in a slice, do stuff
181  if (lasttdc !=0 ) {
182  int tdcdelta = abs((int)hit.TDC().val-lasttdc);
183  // std::cout << "next hit: tdc delta:"<< tdcdelta;
184  int planedelta = abs((int)hit.Plane().val-lastplane);
185  // std::cout << " plane delta:" << planedelta<< std::endl;
186  h_["plane_delta"]->Fill((double)planedelta);
187  h_["tdc_delta"]->Fill((double)tdcdelta);
188  }// else std::cout << "first hit"<<std::endl;
189 
190  // record the last values of things we're differencing
191  lasttdc = (int)hit.TDC().val;
192  lastplane = (int)hit.Plane().val;
193  }
194  h_["n_hits_per_slice"]->Fill(double(slicehits));
195  }
196 
197  double adc_mean;
198 
199  if (slice.size() > 0)
200  {
201  adc_mean = adc_sum / double(slice.size());
202  } else {
203  adc_mean = 0.0;
204  }
205 
206  h_["adc_mean"]->Fill(adc_mean);
207  h_["adc_sum"]->Fill(adc_sum);
208 
209  h_["n_hits_per_slice_precut"]->Fill(double(slicehits_precut));
210  }
211 }
212 
214 {
215  // Implementation of optional member function here.
216  Binning adc_bin(4096, 0.0, 4096.0);
217  Binning nbin(101, 0.0, 100.0);
218  Binning plane_bin(1000, 0.0, 1000.0);
219  Binning cell_bin(400, -0.0, 400.0);
220 
221  make_histo("counter_precut", "Counter (0 = Event, 1 = Slice, 2 = Hit)",
222  Binning (3,0.0,3.0));
223  make_histo("counter", "Counter (0 = Event, 1 = Slice, 2 = Hit)",
224  Binning (3,0.0,3.0));
225 
226  make_histo("adc_all_hits", "ADC Distribution of All Hits", adc_bin);
227  make_histo("adc_mean", "Mean ADC per Slice", adc_bin);
228  make_histo("adc_sum", "Summed ADC per Slice", adc_bin);
229 
230  make_histo("n_hits_per_slice_precut", "Number of Hits per Slice", nbin);
231  make_histo("n_hits_per_slice", "Number of Hits per Slice", nbin);
232 
233  make_histo("plane_all_hits", "Plane of All Hits", plane_bin);
234  make_histo("cell_all_hits", "Cell of All Hits", cell_bin);
235 
236  make_histo("tdc_delta_precut","TDC Difference Between Hits", nbin);
237  make_histo("plane_delta_precut","Plane Difference Between Hits", nbin);
238  make_histo("tdc_delta","TDC Difference Between Hits", nbin);
239  make_histo("plane_delta","Plane Difference Between Hits", nbin);
240 }
241 
243 (std::string const name, std::string const title, Binning const& bin)
244 {
245  h_[name] = tfs_->make<TH1F>
246  (name.c_str(), title.c_str(),
247  std::get<0>(bin), std::get<1>(bin), std::get<2>(bin));
248 }
249 
251 {
252  // Implementation of optional member function here.
253 
254  // hmm - we want to write out those histos, yes?
255 
256  // blurt out stats
257  std::cout << h_["counter_precut"]->GetBinContent(1) << " Pre-cut Events "
258  << h_["counter_precut"]->GetBinContent(2) << " Slices "
259  << h_["counter_precut"]->GetBinContent(3) << " Hits"
260  << std::endl;
261  std::cout << h_["counter"]->GetBinContent(1) << " Events "
262  << h_["counter"]->GetBinContent(2) << " Slices "
263  << h_["counter"]->GetBinContent(3) << " Hits"
264  << std::endl;
265 }
266 
const XML_Char * name
Definition: expat.h:151
std::string slice_instance_
Definition: SNAna_module.cc:62
std::map< std::string, TH2 * > h2_
Definition: SNAna_module.cc:69
const char * p
Definition: xmltok.h:285
void abs(TH1 *hist)
DEFINE_ART_MODULE(TestTMapFile)
std::string slice_label_
Definition: SNAna_module.cc:62
art::ServiceHandle< art::TFileService > tfs_
Definition: SNAna_module.cc:70
void endJob() override
SNAna & operator=(SNAna const &)=delete
SNAna(fhicl::ParameterSet const &p)
Definition: SNAna_module.cc:75
std::map< std::string, TH1 * > h_
Definition: SNAna_module.cc:68
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
void make_histo(std::string const name, std::string const title, Binning const &bin)
float bin[41]
Definition: plottest35.C:14
OStream cout
Definition: OStream.cxx:6
std::tuple< unsigned, double, double > Binning
Definition: SNAna_module.cc:57
T * make(ARGS...args) const
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
Definition: structs.h:12
void beginJob() override
Float_t e
Definition: plot.C:35
void analyze(art::Event const &e) override
Definition: SNAna_module.cc:95
enum BeamMode string
unsigned int uint