ElectronNeutrinoSelection
 All Classes Functions Variables Groups
PandoraLEEAnalyzer.h
1 
25 #ifndef PANDORA_LEE_H
26 #define PANDORA_LEE_H
27 
28 #include <math.h>
29 #include <fstream>
30 #include <algorithm>
31 #include <functional>
32 
33 #include "art/Framework/Core/EDAnalyzer.h"
34 #include "art/Framework/Core/ModuleMacros.h"
35 #include "art/Framework/Principal/Event.h"
36 #include "art/Framework/Principal/Handle.h"
37 #include "art/Framework/Principal/Run.h"
38 #include "art/Framework/Principal/SubRun.h"
39 #include "fhiclcpp/ParameterSet.h"
40 #include "messagefacility/MessageLogger/MessageLogger.h"
41 
42 // uncomment the lines below as you use these objects
43 
44 #include "TFile.h"
45 #include "TH1F.h"
46 #include "TTree.h"
47 #include "TVector3.h"
48 #include "TLorentzVector.h"
49 #include "canvas/Persistency/Common/FindManyP.h"
50 #include "canvas/Persistency/Common/FindMany.h"
51 #include "canvas/Persistency/Common/FindOneP.h"
52 #include "canvas/Utilities/InputTag.h"
53 #include "larcore/Geometry/Geometry.h"
54 #include "larcoreobj/SummaryData/POTSummary.h"
55 #include "lardataobj/AnalysisBase/Calorimetry.h"
56 #include "lardataobj/AnalysisBase/CosmicTag.h"
57 #include "lardataobj/MCBase/MCShower.h"
58 #include "lardataobj/RecoBase/Cluster.h"
59 #include "lardataobj/RecoBase/Hit.h"
60 #include "lardataobj/RecoBase/PFParticle.h"
61 #include "lardataobj/RecoBase/Shower.h"
62 #include "lardataobj/RecoBase/Track.h"
63 #include "lardataobj/RecoBase/Vertex.h"
64 #include "nusimdata/SimulationBase/MCParticle.h"
65 #include "nusimdata/SimulationBase/MCTruth.h"
66 #include "uboone/EventWeight/MCEventWeight.h"
67 #include "larevt/SpaceChargeServices/SpaceChargeService.h"
68 #include "uboone/UBXSec/DataTypes/SelectionResult.h"
69 #include "lardataobj/AnalysisBase/ParticleID.h"
70 #include "TEfficiency.h"
71 #include "art/Framework/Services/Optional/TFileService.h"
72 
73 #include "ElectronEventSelectionAlg.h"
74 #include "PandoraInterfaceHelper.h"
75 
76 #include "EnergyHelper.h"
77 #include "GeometryHelper.h"
78 
79 #include "larcore/Geometry/WireGeo.h"
80 #include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
81 #include "lardata/DetectorInfoServices/DetectorClocksService.h"
82 #include "lardata/DetectorInfo/DetectorProperties.h"
83 #include "larreco/RecoAlg/TrackMomentumCalculator.h"
84 
85 #include "uboone/EventWeight/EventWeightTreeUtility.h"
86 
87 namespace lee {
88 
89 class PandoraLEEAnalyzer : public art::EDAnalyzer {
90 public:
91  explicit PandoraLEEAnalyzer(fhicl::ParameterSet const &pset);
92  // The destructor generated by the compiler is fine for classes
93  // without bare pointers or other resource use.
94  virtual ~PandoraLEEAnalyzer();
95 
96  // Plugins should not be copied or assigned.
97  PandoraLEEAnalyzer(PandoraLEEAnalyzer const &) = delete;
99  PandoraLEEAnalyzer &operator=(PandoraLEEAnalyzer const &) = delete;
100  PandoraLEEAnalyzer &operator=(PandoraLEEAnalyzer &&) = delete;
101 
107  void analyze(art::Event const &e) override;
108 
114  void endSubRun(const art::SubRun &sr);
115 
121  void reconfigure(fhicl::ParameterSet const &pset) override;
122 
126  void clear();
127 
136  size_t choose_candidate(
137  std::vector<size_t> &candidates,
138  const art::Event &evt);
139 
147  art::Ptr<recob::Track> get_longest_track(
148  std::vector<art::Ptr<recob::Track>> &tracks);
149 
150  /*
151  * @brief Return the most energetic reconstructed shower
152  *
153  * @param[in] showers vector of reconstructed showers
154  *
155  * @return most energetic reconstructed shower object
156  */
157  art::Ptr<recob::Shower> get_most_energetic_shower(
158  std::vector<art::Ptr<recob::Shower>> &showers);
159 
175  art::Event const &evt,
176 
177  std::vector<int> &neutrino_pdg,
178  std::vector<std::string> &neutrino_process,
179  std::vector<double> &neutrino_energy,
180  std::vector<art::Ptr<recob::PFParticle>> &neutrino_pf,
181 
182  std::vector<int> &cosmic_pdg,
183  std::vector<std::string> &cosmic_process,
184  std::vector<double> &cosmic_energy,
185  std::vector<art::Ptr<recob::PFParticle>> &cosmic_pf);
186 
187  void fillTrackFields(size_t pf_id,
188  recob::PFParticle const *pfparticle,
189  art::FindManyP<recob::Cluster> *clusters_per_pfpart,
190  art::FindManyP<recob::SpacePoint> *spcpnts_per_pfpart,
191  art::FindOneP<recob::Track> *track_per_pfpart,
192  art::FindManyP<anab::Calorimetry> *calos_per_track,
193  art::FindManyP<simb::MCParticle, anab::BackTrackerHitMatchingData> *mcps_per_hit,
194  art::FindManyP<recob::Hit> *hits_per_spcpnts,
195  art::FindManyP<anab::ParticleID> *pid_per_track,
196  art::FindManyP<recob::Hit> *hits_per_cluster);
197 
198 private:
199  std::string m_hitfinderLabel;
200  std::string _geantModuleLabel = "largeant";
201  std::string m_pfp_producer;
202  std::string m_pid_producer;
203  std::string m_calorimetry_producer;
204 
205  std::string m_spacepointLabel;
206  std::string _mctruthLabel = "generator";
207  std::string m_hitmatching_producer;
208 
209  lee::ElectronEventSelectionAlg fElectronEventSelectionAlg;
210  EnergyHelper energyHelper;
211  GeometryHelper geoHelper;
212  PandoraInterfaceHelper pandoraHelper;
213  uboone::EWTreeUtil ewutil;
214  trkf::TrackMomentumCalculator _trkmom;
215 
216  float _lee_bins[12] = {200, 300, 375, 475, 550, 675, 800, 950, 1100, 1300, 1500, 3000};
217  float _lee_scaling[13] = {0, 3.88549, 3.05421, 1.59615, 0.383725, 0, 0, 0, 0, 0, 0, 0, 0};
218 
219  TH1F *_h_lee_scaling = new TH1F("h_lee_scaling", "", 11, _lee_bins);
220 
221  TFile *myTFile;
222  TTree *myTTree;
223  TTree *mySBNTTree;
224  TTree *myPOTTTree;
225 
226  double _reco_nu_energy;
227  bool m_showersAsTracks;
228  bool m_isLEE;
229  int _interaction_type;
230 
231  double m_fidvolXstart;
232  double m_fidvolXend;
233 
234  double m_fidvolYstart;
235  double m_fidvolYend;
236 
237  double m_fidvolZstart;
238  double m_fidvolZend;
239  bool m_useParticleID;
240  bool m_isData;
241  bool m_isCosmicInTime;
242  bool m_printDebug;
243  bool m_isOverlaidSample;
244  bool m_save_flux_info;
245  const int k_cosmic = 1;
246  const int k_nu_e = 2;
247  const int k_nu_mu = 3;
248  const int k_nc = 4;
249  const int k_dirt = 5;
250  const int k_data = 6;
251  const int k_other = 0;
252  const int k_mixed = 7;
253  const int k_nu_e_other = 8;
254  std::vector<double> _energy;
255  int _true_nu_is_fiducial;
256  double _nu_energy;
257 
258  int _n_tracks;
259  int _n_showers;
260  int _n_showers_as_tracks;
261  double _vx;
262  double _vy;
263  double _vz;
264  double _interaction_length;
265  double _true_vx;
266  double _true_vy;
267  double _true_vz;
268 
269  double _true_vx_sce;
270  double _true_vy_sce;
271  double _true_vz_sce;
272  std::vector< std::vector<double> > _genie_weights;
273  std::vector< std::string > _genie_names;
274 
275  std::vector< std::vector<double> > _flux_weights;
276  std::vector< std::string > _flux_names;
277 
278  std::vector<double> _true_shower_x_sce;
279  std::vector<double> _true_shower_y_sce;
280  std::vector<double> _true_shower_z_sce;
281  std::vector<int> _true_shower_pdg;
282  std::vector<double> _true_shower_depE;
283 
284  int _nu_matched_tracks;
285  int _nu_matched_showers;
286 
287  int _nu_pdg;
288  int _ccnc;
289  int _category;
290  int _run;
291  int _subrun;
292  int _event;
293  int _n_candidates;
294  int _n_true_nu;
295  int _run_sr;
296  int _subrun_sr;
297  int _n_matched;
298  double _pot;
299  int _event_passed;
300  int _numu_passed;
301  int _numu_cuts;
302  double _distance;
303  double _cosmic_fraction;
304 
305  std::vector<int> _flash_passed;
306  std::vector<int> _track_passed;
307  std::vector<int> _shower_passed;
308  std::vector<int> _primary_indexes;
309  std::vector<int> _number_tracks;
310  std::vector<int> _number_showers;
311 
312  std::vector<int> _matched_showers;
313  std::vector<int> _matched_tracks;
314 
315  std::vector<std::string> _matched_tracks_process;
316  std::vector<double> _matched_tracks_energy;
317 
318  std::vector<std::string> _matched_showers_process;
319  std::vector<double> _matched_showers_energy;
320 
321  std::map<std::string, std::vector<double>> _weights;
322 
323  int _n_primaries;
324  int _chosen_candidate;
325 
326  float _leeweight;
327  double _bnbweight;
328 
329  std::vector<std::vector<double>> _shower_dQdx_hits;
330  std::vector<std::vector<double>> _shower_dEdx_hits;
331 
332  std::vector<std::vector<double>> _shower_dQdx;
333  std::vector<std::vector<double>> _shower_dEdx;
334  std::vector<std::vector<double>> _shower_dQdx_cali;
335  std::vector<std::vector<double>> _shower_dEdx_cali;
336  std::vector<std::vector<double>> _shower_pitches;
337  std::vector<std::vector<int>> _shower_dQdx_hits_in_the_box;
338 
339  std::vector<std::vector<double>> _track_dQdx_hits;
340  std::vector<std::vector<double>> _track_dEdx_hits;
341 
342  std::vector<std::vector<double>> _track_dQdx;
343  std::vector<std::vector<double>> _track_dQdx_cali;
344 
345  std::vector<std::vector<double>> _track_dEdx;
346  std::vector<double> _track_energy_length;
347 
348  std::vector<size_t> _nu_track_ids;
349  std::vector<size_t> _nu_shower_as_track_ids;
350 
351  std::vector<size_t> _nu_shower_ids;
352 
353  std::vector< std::vector<size_t> > _nu_track_daughters;
354  std::vector< std::vector<size_t> > _nu_shower_daughters;
355 
356  std::vector<double> _shower_open_angle;
357  std::vector<double> _shower_length;
358  std::vector<double> _shower_dir_x;
359  std::vector<double> _shower_dir_y;
360  std::vector<double> _shower_dir_z;
361 
362  std::vector<double> _shower_start_x;
363  std::vector<double> _shower_start_y;
364  std::vector<double> _shower_start_z;
365 
366  std::vector<double> _shower_theta;
367  std::vector<double> _shower_phi;
368 
369  std::vector<std::vector<double>> _shower_energy;
370  std::vector<std::vector<double>> _shower_energy_cali;
371  std::vector<std::vector<double>> _track_energy_cali;
372 
373  std::vector<double> _track_dir_x;
374  std::vector<double> _track_dir_y;
375  std::vector<double> _track_dir_z;
376  std::vector<int> _track_is_fiducial;
377  std::vector<int> _shower_is_fiducial;
378 
379  std::vector<double> _track_res_mean;
380  std::vector<double> _track_res_std;
381 
382  std::vector<double> _shower_res_mean;
383  std::vector<double> _shower_res_std;
384 
385  std::vector<double> _track_start_x;
386  std::vector<double> _track_start_y;
387  std::vector<double> _track_start_z;
388 
389  std::vector<double> _track_end_x;
390  std::vector<double> _track_end_y;
391  std::vector<double> _track_end_z;
392 
393  std::vector<double> _track_theta;
394  std::vector<double> _track_phi;
395 
396  std::vector<double> _track_length;
397  std::vector<double> _track_id;
398 
399  std::vector<double> _track_bragg_p;
400  std::vector<double> _track_bragg_mu;
401  std::vector<double> _track_bragg_mip;
402 
403  std::vector<double> _track_pidchi;
404  std::vector<double> _track_pidchipr;
405  std::vector<double> _track_pidchika;
406  std::vector<double> _track_pidchipi;
407  std::vector<double> _track_pidchimu;
408  std::vector<double> _track_pida;
409 
410  std::vector<double> _track_energy_dedx;
411  std::vector<std::vector<double>> _track_energy_hits;
412 
413  std::vector<int> _nu_daughters_pdg;
414  std::vector<double> _nu_daughters_E;
415 
416  std::vector<double> _nu_daughters_px;
417  std::vector<double> _nu_daughters_py;
418  std::vector<double> _nu_daughters_pz;
419 
420  std::vector<double> _nu_daughters_vx;
421  std::vector<double> _nu_daughters_vy;
422  std::vector<double> _nu_daughters_vz;
423 
424  std::vector<double> _nu_daughters_endx;
425  std::vector<double> _nu_daughters_endy;
426  std::vector<double> _nu_daughters_endz;
427 
428  std::vector<double> _flash_PE;
429  std::vector<double> _flash_time;
430 
431  double _TPC_x;
432  double _flash_x;
433 
434  std::vector<std::vector<double>> _shower_pca;
435  std::vector<std::vector<double>> _track_pca;
436 
437  std::vector<std::vector<int>> _shower_nhits;
438  std::vector<std::vector<int>> _track_nhits;
439 
440 };
441 
442 }
443 
444 #endif // PANDORA_LEE_H
Definition: PandoraLEEAnalyzer.h:89
art::Ptr< recob::Track > get_longest_track(std::vector< art::Ptr< recob::Track >> &tracks)
Return the longest reconstructed track.
Definition: PandoraLEEAnalyzer_module.cc:293
Definition: PandoraInterfaceHelper.h:55
Definition: ElectronEventSelectionAlg.h:61
void reconfigure(fhicl::ParameterSet const &pset) override
Assigns the values of the FHICL file.
Definition: PandoraLEEAnalyzer_module.cc:1539
void endSubRun(const art::SubRun &sr)
Method called at the end of each subrun, it stores the number of POT.
Definition: PandoraLEEAnalyzer_module.cc:360
Definition: EnergyHelper.h:51
size_t choose_candidate(std::vector< size_t > &candidates, const art::Event &evt)
Return the longest reconstructed track.
Definition: PandoraLEEAnalyzer_module.cc:322
void categorizePFParticles(art::Event const &evt, std::vector< int > &neutrino_pdg, std::vector< std::string > &neutrino_process, std::vector< double > &neutrino_energy, std::vector< art::Ptr< recob::PFParticle >> &neutrino_pf, std::vector< int > &cosmic_pdg, std::vector< std::string > &cosmic_process, std::vector< double > &cosmic_energy, std::vector< art::Ptr< recob::PFParticle >> &cosmic_pf)
Determines if a PFParticle is matched with a MCParticle coming from a neutrino interaction or a cosmi...
Definition: PandoraLEEAnalyzer_module.cc:690
void clear()
Clears filled variables.
Definition: PandoraLEEAnalyzer_module.cc:384
void analyze(art::Event const &e) override
Main analyzer method, runs for every event in the file.
Definition: PandoraLEEAnalyzer_module.cc:745
Definition: GeometryHelper.h:40