CheckRecoEnergy_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // \file CheckRecoEnergy_module.cc
4 //
5 // n.grant.3@warwick.ac.uk
6 //
7 ///////////////////////////////////////////////////////////////////////
8 
9 #ifndef CheckRecoEnergy_H
10 #define CheckRecoEnergy_H
11 
12 // Generic C++ includes
13 #include <iostream>
14 #include <vector>
15 
16 // Framework includes
21 #include "fhiclcpp/ParameterSet.h"
23 #include "art_root_io/TFileService.h"
24 
25 #include "nugen/NuReweight/art/NuReweight.h"
29 
30 #include "TH1D.h"
31 #include "TF1.h"
32 #include "TGraphErrors.h"
33 
37 
40 
41 namespace dune {
42 
44 
45  public:
46 
47  explicit CheckRecoEnergy(fhicl::ParameterSet const& pset);
48  virtual ~CheckRecoEnergy();
49  void beginJob() override;
50  void endJob() override;
51  void beginSubRun(const art::SubRun& sr) override;
52  void endSubRun(const art::SubRun& sr) override;
53  void reconfigure(fhicl::ParameterSet const& pset) ;
54  void analyze(art::Event const & evt) override;
55 
56 
57  private:
58 
61 
62  unsigned int fRun,fSubrun,fEvent;
63 
64  double fFidVolXMax;
65  double fFidVolYMax;
66  double fFidVolZMin;
67  double fFidVolZMax;
68 
69  double fEtrue;
70 
71  double fErecoNue;
72  double fRecoLepEnNue;
73  double fRecoHadEnNue;
74  int fRecoMethodNue; // 1 = longest reco track + hadronic, 2 = reco shower with highest charge + hadronic, 3 = all hit charges, -1 = not set
75  double fErecoNumu;
78  int fRecoMethodNumu; // 1 = longest reco track + hadronic, 2 = reco shower with highest charge + hadronic, 3 = all hit charges, -1 = not set
79  int fLongestTrackContNumu; // 1 = contained, 0 = exiting, -1 = not set
80  int fTrackMomMethodNumu; // 1 = range, 0 = MCS, -1 = not set
81 
82  double fNuVtxX;
83  double fNuVtxY;
84  double fNuVtxZ;
85  int fNuPDG;
86  int fMode; // 0=QE/El, 1=RES, 2=DIS, 3=Coherent production
87  int fCCNC; // 0=CC, 1=NC
88  double fNuMomX;
89  double fNuMomY;
90  double fNuMomZ;
91  double fNuMomT;
92 
93  int fLepPDG;
94  double fLepMomX;
95  double fLepMomY;
96  double fLepMomZ;
97  double fLepMomT;
98  double fLepNuAngle;
99 
109 
110  std::vector<double> fNumuContBinEdge;
111  std::vector<double> fNumuExitBinEdge;
112  std::vector<double> fNueBinEdge;
113 
114  std::vector<TH1D*> fEnResEnNumuCont;
115  std::vector<TH1D*> fEnResEnNumuExit;
116  std::vector<TH1D*> fEnResEnNue;
117 
118  std::vector<TF1*> fFitEnResNumuCont;
119  std::vector<TF1*> fFitEnResNumuExit;
120  std::vector<TF1*> fFitEnResNue;
121 
122  TGraphErrors* fGrResEnNumuCont;
123  TGraphErrors* fGrSigEnNumuCont;
124  TGraphErrors* fGrResEnNumuExit;
125  TGraphErrors* fGrSigEnNumuExit;
126  TGraphErrors* fGrResEnNue;
127  TGraphErrors* fGrSigEnNue;
128 
129  }; // class CheckRecoEnergy
130 
131  //------------------------------------------------------------------------------
133  : EDAnalyzer(pset)
134  {
135  this->reconfigure(pset);
136  }
137 
139 
140  //------------------------------------------------------------------------------
142  {
143  fEnergyRecoNueLabel = pset.get<std::string>("EnergyRecoNueLabel");
144  fEnergyRecoNumuLabel = pset.get<std::string>("EnergyRecoNumuLabel");
145 
146  fFidVolXMax = pset.get<double>("FidVolXMax");
147  fFidVolYMax = pset.get<double>("FidVolYMax");
148  fFidVolZMin = pset.get<double>("FidVolZMin");
149  fFidVolZMax = pset.get<double>("FidVolZMax");
150 
151  fNumuContBinEdge = pset.get<std::vector<double>>("NumuContBinEdge");
152  fNumuExitBinEdge = pset.get<std::vector<double>>("NumuExitBinEdge");
153  fNueBinEdge = pset.get<std::vector<double>>("NueBinEdge");
154 
155  return;
156  }
157 
158  //------------------------------------------------------------------------------
160  {
162 
163  fLepMomResNumuCont = tfs->make<TH1D>("LepMomResNumuCont", "", 80, -2.0, 2.0);
164  fHadEnResNumuCont = tfs->make<TH1D>("HadEnResNumuCont", "", 40, -2.0, 2.0);
165  fEnergyResNumuCont = tfs->make<TH1D>("EnergyResNumuCont", "", 40, -2.0, 2.0);
166  fLepMomResNumuExit = tfs->make<TH1D>("LepMomResNumuExit", "", 80, -2.0, 2.0);
167  fHadEnResNumuExit = tfs->make<TH1D>("HadEnResNumuExit", "", 40, -2.0, 2.0);
168  fEnergyResNumuExit = tfs->make<TH1D>("EnergyResNumuExit", "", 40, -2.0, 2.0);
169  fLepEnResNue = tfs->make<TH1D>("LepEnResNue", "", 80, -2.0, 2.0);
170  fHadEnResNue = tfs->make<TH1D>("HadEnResNue", "", 40, -2.0, 2.0);
171  fEnergyResNue = tfs->make<TH1D>("EnergyResNue", "", 40, -2.0, 2.0);
172 
173  for(unsigned int h=0; h<fNumuContBinEdge.size()-1;h++)
174  {
175  TH1D *hEnResEnNumuCont = tfs->make<TH1D>(Form("hEnResEnNumuCont%d",h), "", 40, -2.0, 2.0);
176  fEnResEnNumuCont.push_back(hEnResEnNumuCont);
177  TF1 *gausEnResNumuCont = tfs->make<TF1>(Form("gausEnResNumuCont%d",h), "gaus", -1.0, 1.0);
178  fFitEnResNumuCont.push_back(gausEnResNumuCont);
179  }
180 
181  for(unsigned int h=0; h<fNumuExitBinEdge.size()-1;h++)
182  {
183  TH1D *hEnResEnNumuExit = tfs->make<TH1D>(Form("hEnResEnNumuExit%d",h), "", 40, -2.0, 2.0);
184  fEnResEnNumuExit.push_back(hEnResEnNumuExit);
185  TF1 *gausEnResNumuExit = tfs->make<TF1>(Form("gausEnResNumuExit%d",h), "gaus", -1.0, 1.0);
186  fFitEnResNumuExit.push_back(gausEnResNumuExit);
187  }
188 
189  for(unsigned int h=0; h<fNueBinEdge.size()-1;h++)
190  {
191  TH1D *hEnResEnNue = tfs->make<TH1D>(Form("hEnResEnNue%d",h), "", 40, -2.0, 2.0);
192  fEnResEnNue.push_back(hEnResEnNue);
193  TF1 *gausEnResNue = tfs->make<TF1>(Form("gausEnResNue%d",h), "gaus", -1.0, 1.0);
194  fFitEnResNue.push_back(gausEnResNue);
195  }
196 
197  fGrResEnNumuCont = tfs->makeAndRegister<TGraphErrors>("fGrResEnNumuCont", "fGrResEnNumuCont", (int)(fNumuContBinEdge.size())-1);
198  fGrSigEnNumuCont = tfs->makeAndRegister<TGraphErrors>("fGrSigEnNumuCont", "fGrSigEnNumuCont", (int)(fNumuContBinEdge.size())-1);
199 
200  fGrResEnNumuExit = tfs->makeAndRegister<TGraphErrors>("fGrResEnNumuExit", "fGrResEnNumuExit", (int)(fNumuExitBinEdge.size())-1);
201  fGrSigEnNumuExit = tfs->makeAndRegister<TGraphErrors>("fGrSigEnNumuExit", "fGrSigEnNumuExit", (int)(fNumuExitBinEdge.size())-1);
202 
203  fGrResEnNue = tfs->makeAndRegister<TGraphErrors>("fGrResEnNue", "fGrResEnNue", (int)(fNueBinEdge.size())-1);
204  fGrSigEnNue = tfs->makeAndRegister<TGraphErrors>("fGrSigEnNue", "fGrSigEnNue", (int)(fNueBinEdge.size())-1);
205 
206  return;
207  }
208 
209  //------------------------------------------------------------------------------
211  }
212 
213  //------------------------------------------------------------------------------
215  {
216  auto ereconuein = evt.getHandle<dune::EnergyRecoOutput>(fEnergyRecoNueLabel);
217  if (!ereconuein) return;
218 
219  auto ereconumuin = evt.getHandle<dune::EnergyRecoOutput>(fEnergyRecoNumuLabel);
220  if (!ereconumuin) return;
221 
222  fRun = evt.id().run();
223  fSubrun = evt.id().subRun();
224  fEvent = evt.id().event();
225 
226  fErecoNue = ereconuein->fNuLorentzVector.E();
227  fRecoLepEnNue = ereconuein->fLepLorentzVector.E();
228  fRecoHadEnNue = ereconuein->fHadLorentzVector.E();
229  fRecoMethodNue = ereconuein->recoMethodUsed;
230  fErecoNumu = ereconumuin->fNuLorentzVector.E();
231  fRecoLepEnNumu = ereconumuin->fLepLorentzVector.E();
232  fRecoHadEnNumu = ereconumuin->fHadLorentzVector.E();
233  fRecoMethodNumu = ereconumuin->recoMethodUsed;
234  fLongestTrackContNumu = ereconumuin->longestTrackContained;
235  fTrackMomMethodNumu = ereconumuin->trackMomMethod;
236 
237  std::vector< art::Ptr<simb::MCTruth> > truth;
238  auto mct = evt.getHandle< std::vector<simb::MCTruth> >("generator");
239  if( mct )
240  art::fill_ptr_vector(truth, mct);
241  else
242  mf::LogWarning("CheckRecoEnergy") << "No MCTruth.";
243 
244  for(size_t i=0; i<truth.size(); i++){
245 
246  if(i>1){
247  mf::LogWarning("CheckRecoEnergy") << "Skipping MC truth index " << i;
248  continue;
249  }
250 
251  fCCNC = truth[i]->GetNeutrino().CCNC(); //0=CC 1=NC
252  fNuPDG = truth[i]->GetNeutrino().Nu().PdgCode();
253  fMode = truth[i]->GetNeutrino().Mode(); //0=QE/El, 1=RES, 2=DIS, 3=Coherent production
254  fNuVtxX = truth[i]->GetNeutrino().Nu().Vx();
255  fNuVtxY = truth[i]->GetNeutrino().Nu().Vy();
256  fNuVtxZ = truth[i]->GetNeutrino().Nu().Vz();
257  fEtrue = truth[i]->GetNeutrino().Nu().E();
258  fNuMomX = truth[i]->GetNeutrino().Nu().Momentum().X();
259  fNuMomY = truth[i]->GetNeutrino().Nu().Momentum().Y();
260  fNuMomZ = truth[i]->GetNeutrino().Nu().Momentum().Z();
261  fNuMomT = truth[i]->GetNeutrino().Nu().Momentum().T();
262  fLepPDG = truth[i]->GetNeutrino().Lepton().PdgCode();
263  fLepMomX = truth[i]->GetNeutrino().Lepton().Momentum().X();
264  fLepMomY = truth[i]->GetNeutrino().Lepton().Momentum().Y();
265  fLepMomZ = truth[i]->GetNeutrino().Lepton().Momentum().Z();
266  fLepMomT = truth[i]->GetNeutrino().Lepton().Momentum().T();
267  fLepNuAngle = truth[i]->GetNeutrino().Nu().Momentum().Vect().Angle(truth[i]->GetNeutrino().Lepton().Momentum().Vect());
268 
269  //true CC event with true vertex in fiducial volume
270  if(fCCNC == 0 && fabs(fNuVtxX) < fFidVolXMax && fabs(fNuVtxY) < fFidVolYMax && fabs(fNuVtxZ) > fFidVolZMin && fabs(fNuVtxZ) < fFidVolZMax)
271  {
272  if(fNuPDG == 14) //true numu
273  {
274  if(fLongestTrackContNumu == 1) //longest reco track contained
275  {
279  for(unsigned int e=0; e<fNumuContBinEdge.size()-1; e++)
280  {
281  if(fEtrue > fNumuContBinEdge.at(e) && fEtrue <= fNumuContBinEdge.at(e+1))
282  fEnResEnNumuCont.at(e)->Fill((fErecoNumu - fEtrue) / fEtrue);
283  }
284  }
285  else if(fLongestTrackContNumu == 0) //longest reco track exiting
286  {
290  for(unsigned int e=0; e<fNumuExitBinEdge.size()-1; e++)
291  {
292  if(fEtrue > fNumuExitBinEdge.at(e) && fEtrue <= fNumuExitBinEdge.at(e+1))
293  fEnResEnNumuExit.at(e)->Fill((fErecoNumu - fEtrue) / fEtrue);
294  }
295  }
296  }
297  else if(fNuPDG == 12) //true nue
298  {
299  if(fRecoMethodNue == 2) //at least one reco shower
300  {
303  fEnergyResNue->Fill((fErecoNue - fEtrue) / fEtrue);
304  for(unsigned int e=0; e<fNueBinEdge.size()-1; e++)
305  {
306  if(fEtrue > fNueBinEdge.at(e) && fEtrue <= fNueBinEdge.at(e+1))
307  fEnResEnNue.at(e)->Fill((fErecoNue - fEtrue) / fEtrue);
308  }
309  }
310  }
311  }
312  } //end of for(size_t i=0; i<truth.size(); i++)
313 
314  return;
315  }
316 
318  {
319  for(unsigned int h=0; h<fNumuContBinEdge.size()-1; h++)
320  fEnResEnNumuCont.at(h)->Fit(fFitEnResNumuCont.at(h));
321 
322  for(unsigned int h=0; h<fNumuExitBinEdge.size()-1; h++)
323  fEnResEnNumuExit.at(h)->Fit(fFitEnResNumuExit.at(h));
324 
325  for(unsigned int h=0; h<fNueBinEdge.size()-1; h++)
326  fEnResEnNue.at(h)->Fit(fFitEnResNue.at(h));
327 
328  for(unsigned int h=0; h<fNumuContBinEdge.size()-1; h++)
329  {
330  fGrResEnNumuCont->SetPoint(h, 0.5 * (fNumuContBinEdge.at(h) + fNumuContBinEdge.at(h+1)), fFitEnResNumuCont.at(h)->GetParameter(1));
331  fGrResEnNumuCont->SetPointError(h, 0.5 * (fNumuContBinEdge.at(h+1) - fNumuContBinEdge.at(h)), 0.0);
332  fGrSigEnNumuCont->SetPoint(h, 0.5 * (fNumuContBinEdge.at(h) + fNumuContBinEdge.at(h+1)), fFitEnResNumuCont.at(h)->GetParameter(2));
333  fGrSigEnNumuCont->SetPointError(h, 0.5 * (fNumuContBinEdge.at(h+1) - fNumuContBinEdge.at(h)), 0.0);
334  }
335 
336  for(unsigned int h=0; h<fNumuExitBinEdge.size()-1; h++)
337  {
338  fGrResEnNumuExit->SetPoint(h, 0.5 * (fNumuExitBinEdge.at(h) + fNumuExitBinEdge.at(h+1)), fFitEnResNumuExit.at(h)->GetParameter(1));
339  fGrResEnNumuExit->SetPointError(h, 0.5 * (fNumuExitBinEdge.at(h+1) - fNumuExitBinEdge.at(h)), 0.0);
340  fGrSigEnNumuExit->SetPoint(h, 0.5 * (fNumuExitBinEdge.at(h) + fNumuExitBinEdge.at(h+1)), fFitEnResNumuExit.at(h)->GetParameter(2));
341  fGrSigEnNumuExit->SetPointError(h, 0.5 * (fNumuExitBinEdge.at(h+1) - fNumuExitBinEdge.at(h)), 0.0);
342  }
343 
344  for(unsigned int h=0; h<fNueBinEdge.size()-1; h++)
345  {
346  fGrResEnNue->SetPoint(h, 0.5 * (fNueBinEdge.at(h) + fNueBinEdge.at(h+1)), fFitEnResNue.at(h)->GetParameter(1));
347  fGrResEnNue->SetPointError(h, 0.5 * (fNueBinEdge.at(h+1) - fNueBinEdge.at(h)), 0.0);
348  fGrSigEnNue->SetPoint(h, 0.5 * (fNueBinEdge.at(h) + fNueBinEdge.at(h+1)), fFitEnResNue.at(h)->GetParameter(2));
349  fGrSigEnNue->SetPointError(h, 0.5 * (fNueBinEdge.at(h+1) - fNueBinEdge.at(h)), 0.0);
350  }
351  }
352 
353  //------------------------------------------------------------------------------
355  }
356 
358 
359 } // namespace dune
360 
361 #endif // CheckRecoEnergy_H
std::vector< TF1 * > fFitEnResNumuExit
std::vector< double > fNumuExitBinEdge
void endSubRun(const art::SubRun &sr) override
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
RunNumber_t run() const
Definition: EventID.h:98
CheckRecoEnergy(fhicl::ParameterSet const &pset)
std::vector< TF1 * > fFitEnResNue
const double e
std::vector< TH1D * > fEnResEnNue
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::vector< double > fNumuContBinEdge
void analyze(art::Event const &evt) override
T get(std::string const &key) const
Definition: ParameterSet.h:271
void beginSubRun(const art::SubRun &sr) override
std::vector< TH1D * > fEnResEnNumuExit
void reconfigure(fhicl::ParameterSet const &pset)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::vector< TH1D * > fEnResEnNumuCont
std::vector< double > fNueBinEdge
EventNumber_t event() const
Definition: EventID.h:116
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
static constexpr double sr
Definition: Units.h:166
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
SubRunNumber_t subRun() const
Definition: EventID.h:110
EventID id() const
Definition: Event.cc:34
std::vector< TF1 * > fFitEnResNumuCont