MakeSNeTProfileHistos_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: MakeSNeTProfileHistos
3 // Module Type: analyzer
4 // File: MakeSNeTProfileHistos_module.cc
5 //
6 // Generated at Mon Jan 09 2017 by Michael Baird using the old
7 // copy and paste method...
8 //
9 // Purpose: The purpose of this module is to generate the input histos
10 // for my time-profile, stand alone macro.
11 //
12 ////////////////////////////////////////////////////////////////////////
13 
14 // C++ includes
15 
16 // ROOT includes
17 #include "TTree.h"
18 #include "TH1F.h"
19 #include "TH2F.h"
20 
21 // Framework includes
28 #include "art_root_io/TFileDirectory.h"
29 #include "art_root_io/TFileService.h"
32 #include "fhiclcpp/ParameterSet.h"
34 
35 // DUNETPC specific includes
40 
42 
44 
45 public:
46 
48 
49  // Plugins should not be copied or assigned.
54 
55  // The main guts...
56  void analyze(art::Event const & e) override;
57 
58  void reconfigure(fhicl::ParameterSet const & p);
59 
60  void beginJob() override;
61 
62  void endJob() override;
63 
64 
65 
66 private:
67 
68  // labels for the processes that made the data products
69  std::string fTruthLabel; ///< label for process that made the MCTruth info
70  std::string fHitLabel; ///< label for process that made the reco hits
71 
72 
73 
74  // required histograms for the Time-Profile simulator:
75  TH1F *fEnergySpec; ///< 1D event energy spectrum (used only for backgrounds)
76  TH1F *fTrigEff_numerator; ///< how many times a trigger was issued per true event energy
77  TH1F *fTrigEff; ///< trigger efficiency per true event energy (fTrigEff_numerator/fEnergySpec)
78  TH2F *fNHitsVsEnergy; ///< number of reconstructed hits per true event energy
79  TH2F *fSumADCVsEnergy; ///< summed ADC for all reco hits per true event energy
80  TH1F *fTPSplitProb; ///< probability of splitting a trigger primitive into two (or more) TPs per true event energy
81 
82 
83 
84  // a few extra check histos for double checking general performance:
85  TH1F *fNMCTruths; ///< number of MCTruths per art::event
86  TH1F *fCCNC; ///< CCNC for each MCTruth
87  TH1F *fOrigin; ///< mctruth->Origin()
88  TH1F *fNuPDG; ///< mc_neutrino->Nu()->PdgCode()
89 
90 };
91 
92 
93 
94 //......................................................
96  :
97  EDAnalyzer(p)
98 {
99  this->reconfigure(p);
100 }
101 
102 
103 
104 //......................................................
106 {
107  fTruthLabel = p.get<std::string>("TruthLabel");
108  fHitLabel = p.get<std::string>("HitLabel");
109 }
110 
111 
112 
113 //......................................................
115 {
116 
118 
119  // binning for the energy axes:
120  int NbinsE = 200;
121  float minE = 0.0; // in MeV
122  float maxE = 100.0; // in MeV
123 
124  // binning for the NHits axes:
125  int NbinsNH = 5000;
126  float minNH = 0.0;
127  float maxNH = 5000.0; // a reasonable number determined from running over single nue events
128 
129  // binning for the ADC axes:
130  int NbinsADC = 500;
131  float minADC = 0.0;
132  float maxADC = 500.0e3; // a reasonable number determined from running over single nue events
133 
134 
135 
136  //
137  // Book required histograms for the Time-Profile simulator:
138  //
139 
140  // 2D neutrino energy spectrum as a function of time:
141  // (Note: generated separately by Kate Schol.)
142 
143  // 1D event energy spectrum: (used only for backgrounds)
144  fEnergySpec = tfs->make<TH1F>("EnergySpec",
145  "True energy spectra;true energy [MeV];",
146  NbinsE, minE, maxE);
147 
148  // Overall efficency for triggering as a function of true event energy:
149  fTrigEff_numerator = tfs->make<TH1F>("TrigEff_numerator",
150  "Total number of triggers issued;true energy [MeV];",
151  NbinsE, minE, maxE);
152  fTrigEff = tfs->make<TH1F>("TrigEff",
153  "Trigger efficiency;true energy [MeV];",
154  NbinsE, minE, maxE);
155 
156  // Number of reco hits vs. true event energy:
157  fNHitsVsEnergy = tfs->make<TH2F>("NHitsVsEnergy",
158  "Number of reco hits per true energy;true energy [MeV];NHits",
159  NbinsE, minE, maxE,
160  NbinsNH, minNH, maxNH);
161 
162  // Summed ADC vs. true event energy:
163  fSumADCVsEnergy = tfs->make<TH2F>("SumADCVsEnergy",
164  "Summed ADC over all reco hits per true energy;true energy [MeV];Summed ADC",
165  NbinsE, minE, maxE,
166  NbinsADC, minADC, maxADC);
167 
168  // Probability of splitting a TP into 2 TPs as a function of true event energy:
169  fTPSplitProb = tfs->make<TH1F>("TPSplitProb",
170  "Probability of spliting a TP into 2 or more per true energy;true energy [MeV];",
171  NbinsE, minE, maxE);
172 
173 
174 
175  //
176  // Book a few extra check histos:
177  //
178 
179  // Number of MCTruths per art::event:
180  fNMCTruths = tfs->make<TH1F>("NMCTruths",
181  "Number of MCTruths per art::event;# of MCTruths;",
182  101,-0.5,100.5);
183 
184  // CCNC:
185  fCCNC = tfs->make<TH1F>("CCNC",
186  "CCNC;CCNC;",
187  11,-5.5,5.5);
188 
189  // Origin:
190  fOrigin = tfs->make<TH1F>("Origin",
191  "Neutrino origin;origin type;",
192  16,-5.5,10.5);
193 
194  // Neutrino pdg code:
195  fNuPDG = tfs->make<TH1F>("NuPDG",
196  "Neutrino PDG code;pdg code;",
197  41,-20.5,20.5);
198 
199 }
200 
201 
202 
203 //......................................................
205 {
206 
207 }
208 
209 
210 
211 //......................................................
213 {
214 
215  // TODO:
216  //
217  // 1. implement dividing the TrigEff histos in the endJob function
218  // 2. implement anything that has anything to do with the trigger data products
219  // (including the TrigEff histos, TP splitting histos, etc...???)
220  // 3. figure out a good way to generalize this for multiple MCTruths...
221 
222 
223 
224 
225  // ===== Notes and Assumptions ===== //
226  //
227  // This module assumes the following:
228  //
229  // 1. There is only one neutrino interaction per art::event. This is
230  // important because it assumes that all reco hits go with that one
231  // neutrino.
232 
233 
234 
235 
236 
237  //
238  // Lift out the desired data products:
239  //
240 
241  // Get the hits out of the event
242  auto hits_list = e.getHandle< std::vector< recob::Hit > >(fHitLabel);
243 
244  // Get the MCTruths out of the event
245  auto truths_list = e.getHandle< std::vector< simb::MCTruth > >(fTruthLabel);
246 
247  fNMCTruths->Fill(truths_list->size());
248 
249  // Assert assumption that there is one and only one MCTruth in the event
250  // (note: this needs to be fixed later so that it can handle multiple MCTruths.
251  // This only works for single generated SNe neutrinos for now...)
252  if(truths_list->size() == 1) {
253 
254  // calculate Summed ADC
255  float SummedADC = 0.0; // ...I know... this number is a float?! Who would have guessed that...
256  for(unsigned int i = 0; i < hits_list->size();i++){
257  recob::Hit const& hit = hits_list->at(i);
258  SummedADC += hit.SummedADC();
259  }
260 
261 
262  simb::MCTruth const& truth = truths_list->at(0);
263 
264  fOrigin->Fill(truth.Origin());
265 
266  if (truth.NeutrinoSet()){
267  simb::MCNeutrino const& mc_nu = truth.GetNeutrino();
268  double NuE = 1000.0*mc_nu.Nu().E(); // convert to MeV
269 
270  fEnergySpec->Fill(NuE);
271  fNHitsVsEnergy->Fill(NuE,hits_list->size());
272  fSumADCVsEnergy->Fill(NuE,SummedADC);
273 
274  fCCNC->Fill(mc_nu.CCNC());
275  fNuPDG->Fill(mc_nu.Nu().PdgCode());
276 
277  }
278 
279  }
280  else {
281  std::cerr << "\n\n\nWARNING: Number of MCTruths != 1\n\n\n\n";
282  }
283 
284 
285 
286 }
287 
double E(const int i=0) const
Definition: MCParticle.h:233
int PdgCode() const
Definition: MCParticle.h:212
int CCNC() const
Definition: MCNeutrino.h:148
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
const simb::MCParticle & Nu() const
Definition: MCNeutrino.h:146
simb::Origin_t Origin() const
Definition: MCTruth.h:74
void reconfigure(fhicl::ParameterSet const &p)
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
const double e
MakeSNeTProfileHistos(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
TH1F * fNuPDG
mc_neutrino->Nu()->PdgCode()
p
Definition: test.py:223
TH1F * fTrigEff_numerator
how many times a trigger was issued per true event energy
TH1F * fTrigEff
trigger efficiency per true event energy (fTrigEff_numerator/fEnergySpec)
Detector simulation of raw signals on wires.
Declaration of signal hit object.
TH1F * fNMCTruths
number of MCTruths per art::event
TH2F * fSumADCVsEnergy
summed ADC for all reco hits per true event energy
MakeSNeTProfileHistos & operator=(MakeSNeTProfileHistos const &)=delete
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
Definition: Hit.h:223
TH1F * fTPSplitProb
probability of splitting a trigger primitive into two (or more) TPs per true event energy ...
std::string fTruthLabel
label for process that made the MCTruth info
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
bool NeutrinoSet() const
Definition: MCTruth.h:78
TH2F * fNHitsVsEnergy
number of reconstructed hits per true event energy
Event generator information.
Definition: MCTruth.h:32
TH1F * fEnergySpec
1D event energy spectrum (used only for backgrounds)
Event generator information.
Definition: MCNeutrino.h:18
TH1F * fCCNC
CCNC for each MCTruth.
std::string fHitLabel
label for process that made the reco hits
void analyze(art::Event const &e) override
TH1F * fOrigin
mctruth->Origin()