All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CosmicArrivalTimes.cc
Go to the documentation of this file.
1 /**
2  * \file CosmicArrivalTimes.cc
3  *
4  *
5  * Author:
6  */
7 
8 #include <iostream>
9 #include <array>
10 
11 #include "canvas/Utilities/InputTag.h"
12 #include "core/SelectionBase.hh"
13 #include "core/Event.hh"
14 #include "core/Experiment.hh"
15 #include "core/ProviderManager.hh"
16 
21 #include "fhiclcpp/ParameterSet.h"
23 #include "nusimdata/SimulationBase/MCParticle.h"
25 #include "canvas/Persistency/Common/FindManyP.h"
26 #include "nusimdata/SimulationBase/MCTruth.h"
28 #include "TH1D.h"
29 #include "TH2D.h"
30 #include "TGraph.h"
31 
32 namespace ana {
33  namespace SBNOsc {
34 
35 /**
36  * \class CosmicArrivalTimes
37  * \brief Electron neutrino event selection
38  */
40 public:
41  /** Constructor. */
43 
44  /**
45  * Initialization.
46  *
47  * \param config A configuration, as a FHiCL ParameterSet object
48  */
49  void Initialize(fhicl::ParameterSet* config=NULL) {
50  fMCParticleTag = config ? config->get<std::string>("MCParticleTag", "largeant") : "largeant";
51  fCosmicEnterTimes = new TH1D("cosmic_enter", "cosmic_enter", 700, -60., 10.);
52  fCosmicEnterTimesPE = new TH2D("cosmic_enter_v_pe", "cosmic_enter_v_pe", 700, -60., 10., 100, 0, 10000);
53  event_ind = 0;
54  }
55 
56  /** Finalize and write objects to the output file. */
57  void Finalize() {
58  fOutputFile->cd();
59  fCosmicEnterTimes->Write();
60  fCosmicEnterTimesPE->Write();
61  }
62 
63  /**
64  * Process one event.
65  *
66  * \param ev A single event, as a gallery::Event
67  * \param Reconstructed interactions
68  * \return True to keep event
69  */
70  bool ProcessEvent(const gallery::Event& event, const std::vector<event::Interaction> &truth, std::vector<event::RecoInteraction>& reco) {
71  std::cout << "New Event!\n";
72  auto const &intime = event.getValidHandle<std::vector<simb::MCTruth>>({"GenInTimeSorter", "intime"});
73  //auto const &outtime = event.getValidHandle<std::vector<simb::MCTruth>>({"GenInTimeSorter", "outtime"});
74 
75  art::FindManyP<simb::MCParticle, sim::GeneratedParticleInfo> intime_to_particles(intime, event, fMCParticleTag);
76  //art::FindManyP<simb::MCParticle, sim::GeneratedParticleInfo> outtime_to_particles(outtime, event, fMCParticleTag);
77 
78  double in_time_photon_energy = 0.;
79  unsigned in_time_photons = 0;
80  const std::vector<sim::SimPhotons> &photon_list = *event.getValidHandle<std::vector<sim::SimPhotons>>("larg4intime");
81  for (const sim::SimPhotons &photons: photon_list) {
82  for (const sim::OnePhoton &photon: photons) {
83  if (photon.Time > -200. && photon.Time < 1800.) {
84  in_time_photon_energy += photon.Energy;
85  in_time_photons ++;
86  }
87  }
88  }
89  gallery::Handle<std::vector<sim::SimPhotons>> reflected;
90  event.getByLabel({"larg4intime", "Reflected"}, reflected);
91  if (reflected.isValid()) {
92  std::cout << "Reflected!\n";
93  const std::vector<sim::SimPhotons> &photon_list = *event.getValidHandle<std::vector<sim::SimPhotons>>({"larg4intime", "Reflected"});
94  for (const sim::SimPhotons &photons: photon_list) {
95  for (const sim::OnePhoton &photon: photons) {
96  if (photon.Time > -200. && photon.Time < 1800.) {
97  in_time_photon_energy += photon.Energy;
98  in_time_photons ++;
99  }
100  }
101  }
102  }
103 
104  for (const art::Ptr<simb::MCParticle> part: intime_to_particles.at(0)) {
105  if (abs(part->PdgCode()) != 13) continue;
106  unsigned n_traj = part->NumberTrajectoryPoints();
107  bool next = false;
108  for (unsigned i = 0; i < n_traj; i++) {
109  for (const geo::BoxBoundedGeo &vol: fActiveVolumes) {
110  if (vol.ContainsPosition(part->Position(i).Vect())) {
111  fCosmicEnterTimes->Fill(part->Position(i).T() / 1000.) /* ns -> us*/;
112  fCosmicEnterTimesPE->Fill(part->Position(i).T() / 1000., in_time_photons);
113  next = true;
114  break;
115  }
116  }
117  if (next) break;
118  }
119  }
120 
121  /*
122  for (const art::Ptr<simb::MCParticle> part: outtime_to_particles.at(0)) {
123  unsigned n_traj = part->NumberTrajectoryPoints();
124  bool next = false;
125  for (unsigned i = 0; i < n_traj; i++) {
126  for (const geo::BoxBoundedGeo &vol: fActiveVolumes) {
127  if (vol.ContainsPosition(part->Position(i).Vect())) {
128  fCosmicEnterTimes->Fill(part->Position(i).T() / 1000.);
129  next = true;
130  break;
131  }
132  }
133  if (next) break;
134  }
135  }*/
136 
137  return false;
138  }
139 
140 protected:
141  std::string fMCParticleTag;
142  unsigned event_ind;
145 };
146 
147  } // namespace SBNOsc
148 } // namespace ana
150 
process_name can override from command line with o or output photon
Definition: runPID.fcl:28
All information of a photon entering the sensitive optical detector volume.
Definition: SimPhotons.h:64
TFile * fOutputFile
The output ROOT file.
Contains data associated to particles from detector simulation.
std::vector< geo::BoxBoundedGeo > fActiveVolumes
List of active volumes in configured detector.
process_name opflashCryoW ana
T abs(T value)
Simulation objects for optical detectors.
process_name standard_reco_uboone reco
#define DECLARE_SBN_PROCESSOR(classname)
Base class for event selections.
Provides a base class aware of world box coordinates.
bool ProcessEvent(const gallery::Event &event, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)
Collection of photons which recorded on one channel.
Definition: SimPhotons.h:136
Electron neutrino event selection.
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
BEGIN_PROLOG could also be cout
void Initialize(fhicl::ParameterSet *config=NULL)