All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Histograms.cc
Go to the documentation of this file.
1 #include <TH1D.h>
2 #include <TH2D.h>
3 
4 #include "nusimdata/SimulationBase/MCTruth.h"
5 
6 #include "Histograms.h"
7 #include "../Histograms/Derived.h"
8 #include "../RecoUtils/GeoUtil.h"
9 #include "../NumuReco/TruthMatch.h"
10 
11 namespace ana {
12  namespace SBNOsc {
13 
14 void Histograms::Fill( const numu::RecoEvent &event,
15  const event::Event &core,
16  const Cuts &cutmaker,
17  const std::vector<numu::TrackSelector> &selectors,
18  const std::vector<numu::TrackFunction> &xfunctions,
19  bool fill_all_tracks) {
20 
21  if (event.type == numu::fOverlay) {
22  fCosmic[0].Fill(event.particles);
23  if (cutmaker.PassFlashTrigger(event)) {
24  fCosmic[1].Fill(event.particles);
25  }
26  }
27  else {
28  std::cout << "Filling Cosmic!\n";
29  fCosmic[2].Fill(event.particles);
30  if (cutmaker.PassFlashTrigger(event)) {
31  fCosmic[3].Fill(event.particles);
32  }
33  }
34 
36 
37  if (fill_all_tracks) {
38  for (const auto &track_pair: event.tracks) {
39  const numu::RecoTrack &track = track_pair.second;
40  for (unsigned i = 0; i < fAllTracks.size(); i++) {
41  const numu::TrueParticle &part = (track.match.has_match) ? event.particles.at(track.match.mcparticle_id) : bad;
42  bool select = selectors[i](track, part, event.type);
43  if (select) {
44  fAllTracks[i].Fill(track, event.particles);
45  }
46  }
47  }
48  }
49 
50  for (unsigned i = 0; i < event.reco.size(); i++) {
51  std::array<bool, Cuts::nCuts> cuts = cutmaker.ProcessRecoCuts(event, i);
52  const numu::RecoInteraction &interaction = event.reco[i];
53 
54 
55  if (event.tracks.size() > (unsigned)interaction.slice.primary_track_index) {
56  const numu::RecoTrack &track = event.tracks.at(interaction.slice.primary_track_index);
57 
58  for (unsigned cut_i = 0; cut_i < Cuts::nCuts; cut_i++) {
59  if (cuts[cut_i] && cutmaker.HasCRTHitMatch(track)) {
60  std::cout << "Filling CRT Histo!\n";
61  fCRTs[cut_i].Fill(track.crt_match.hit);
62  }
63  }
64 
65  for (unsigned j = 0; j < fPrimaryTracks.size(); j++) {
66  const numu::TrueParticle &part = (track.match.has_match) ? event.particles.at(track.match.mcparticle_id) : bad;
67  bool select = selectors[i](track, part, event.type);
68  if (select) {
69  for (unsigned cut_i = 0; cut_i < Cuts::nCuts; cut_i++) {
70  if (cuts[cut_i]) {
71  fPrimaryTracks[j][cut_i].Fill(track, event.particles);
72  for (unsigned k = 0; k < xfunctions.size(); k++) {
73  const numu::TrueParticle &part = (track.match.has_match) ? event.particles.at(track.match.mcparticle_id) : bad;
74  uscript::Value x = xfunctions[k](&track, &part, (unsigned*)&event.type);
75  assert(IS_NUMBER(x));
76  fPrimaryTrackProfiles[j][k][cut_i].Fill(AS_NUMBER(x),
77  track, event);
78  }
79  }
80  }
81  }
82  }
83  }
84 
85  // fill histos
86  for (size_t cut_i=0; cut_i < Cuts::nCuts; cut_i++) {
87  int mode = interaction.match.mode;
88  if (cuts[cut_i]) {
89  fInteraction[cut_i+Cuts::nTruthCuts][mode].Fill(event.reco[i],
90  event,
91  core.truth);
93  event,
94  core.truth);
95  }
96  }
97  }
98 
99  for (unsigned i = 0; i < core.truth.size(); i++) {
100  std::array<bool, Cuts::nTruthCuts> cuts = cutmaker.ProcessTruthCuts(event, core, i);
101  for (int cut_i = 0; cut_i < Cuts::nTruthCuts; cut_i++) {
102  int mode = numu::GetMode(core.truth[i]);
103  if (cuts[cut_i]) {
104  fInteraction[cut_i][mode].Fill(core.truth[i], i, event);
105  fInteraction[cut_i][numu::mAll].Fill(core.truth[i], i, event);
106  }
107  }
108  }
109 }
110 
113  const sbnd::CRTGeoAlg &crt_geo,
114  const Cuts &cuts,
115  const std::string &prefix,
116  const std::vector<std::string> &track_histo_types,
117  const std::vector<std::string> &track_profile_types,
118  const std::vector<std::tuple<unsigned, float, float>> &track_profile_xranges) {
119 
120  double max_length = SBNRecoUtils::MaxLength(geometry);
122  std::vector<double> tagger_volume = crt_geo.CRTLimits();
123 
124  std::cout << "Limits: " << tagger_volume[0] << " " << tagger_volume[3] << " " << tagger_volume[1] << " " << tagger_volume[4] << " " << tagger_volume[2] << " " << tagger_volume[5] << std::endl;
125 
126  // make new directory for histograms
127  TDirectory *d_top = gDirectory->mkdir("histograms");
128 
129  if (prefix.size() != 0) {
130  d_top = d_top->mkdir(prefix.c_str());
131  d_top->cd();
132  }
133 
134  d_top->mkdir("cosmic");
135 
136  d_top->mkdir("cosmic/outtime");
137  d_top->cd("cosmic/outtime");
138  fCosmic[0].Initialize("", detector);
139  d_top->cd();
140 
141  d_top->mkdir("cosmic/outtime_trig");
142  d_top->cd("cosmic/outtime_trig");
143  fCosmic[1].Initialize("", detector);
144  d_top->cd();
145 
146  d_top->mkdir("cosmic/intime");
147  d_top->cd("cosmic/intime");
148  fCosmic[2].Initialize("", detector);
149  d_top->cd();
150 
151  d_top->mkdir("cosmic/intime_trig");
152  d_top->cd("cosmic/intime_trig");
153  fCosmic[3].Initialize("", detector);
154  d_top->cd();
155 
156  std::vector<std::string> cut_order = cuts.CutOrder();
157  std::vector<std::string> truth_cut_order = cuts.TruthCutOrder();
158 
159  d_top->mkdir("interaction");
160  for (unsigned i = 0; i < Histograms::nHistos; i++) {
161  for (const auto mode: Histograms::allModes) {
162  std::string cut_name = (i < truth_cut_order.size()) ? truth_cut_order[i] : cut_order[i - truth_cut_order.size()];
163  std::string postfix = mode2Str(mode) + prefix + cut_name;
164  std::string dirname = "interaction/" + mode2Str(mode) + "/" + cut_name;
165  d_top->mkdir(dirname.c_str());
166  d_top->cd(dirname.c_str());
167  fInteraction[i][mode].Initialize("", detector, tagger_volume);
168  d_top->cd();
169  }
170  }
171 
172  d_top->mkdir("crt");
173  for (unsigned cut_i = 0; cut_i < Cuts::nCuts; cut_i++) {
174  std::string dirname = "crt/" + cut_order[cut_i];
175  d_top->mkdir(dirname.c_str());
176  d_top->cd(dirname.c_str());
177  fCRTs[cut_i].Initialize("", tagger_volume);
178  d_top->cd();
179  }
180 
181  fAllTracks.reserve(track_histo_types.size());
182  fPrimaryTracks.reserve(track_histo_types.size());
183 
184  d_top->mkdir("ptrack");
185  d_top->mkdir("alltrack");
186  for (unsigned i = 0; i < track_histo_types.size(); i++) {
187  fAllTracks.emplace_back();
188  fPrimaryTracks.emplace_back();
189  fPrimaryTrackProfiles.emplace_back();
190 
191  std::string dirname = track_histo_types[i];
192  std::string all_dirname = "alltrack/" + dirname;
193 
194  d_top->mkdir(all_dirname.c_str());
195  d_top->cd(all_dirname.c_str());
196  fAllTracks[i].Initialize("", detector, max_length);
197  d_top->cd();
198  for (unsigned j = 0; j < Cuts::nCuts; j++) {
199  std::string p_dirname = "ptrack/" + dirname + cut_order[j];
200  d_top->mkdir(p_dirname.c_str());
201  d_top->cd(p_dirname.c_str());
202  fPrimaryTracks[i][j].Initialize("", detector, max_length);
203  d_top->cd();
204 
205  for (unsigned k = 0; k < track_profile_types.size(); k++) {
206  if (j == 0) fPrimaryTrackProfiles[i].emplace_back();
207  unsigned n_bin;
208  float xlo, xhi;
209  std::tie(n_bin, xlo, xhi) = track_profile_xranges[k];
210  std::string p_profile_dirname = "ptrack/" + dirname + cut_order[j] + "/profile_" + track_profile_types[k];
211  d_top->mkdir(p_profile_dirname.c_str());
212  d_top->cd(p_profile_dirname.c_str());
213  fPrimaryTrackProfiles[i][k][j].Initialize("", n_bin, xlo, xhi);
214  d_top->cd();
215  }
216 
217  }
218  }
219 
220 
221  for (unsigned i = 0; i < 4; i++) {
222  Merge(fCosmic[i]);
223  }
224  for (unsigned i = 0; i < Histograms::nHistos; i++) {
225  for (const auto mode: Histograms::allModes) {
226  Merge(fInteraction[i][mode]);
227  }
228  }
229 
230  for (unsigned i = 0; i < Cuts::nCuts; i++) {
231  Merge(fCRTs[i]);
232  }
233 
234  for (unsigned i = 0; i < fAllTracks.size(); i++) {
235  Merge(fAllTracks[i]);
236  for (unsigned j = 0; j < Cuts::nCuts; j++) {
237  Merge(fPrimaryTracks[i][j]);
238  for (unsigned k = 0; k < track_profile_types.size(); k++) {
239  Merge(fPrimaryTrackProfiles[i][k][j]);
240  }
241  }
242  }
243 
244 }
245 
246  } // namespace SBNOsc
247 } // namespace ana
InteractionMode mode
Mode of the interaction.
bool HasCRTHitMatch(const numu::RecoTrack &track) const
Definition: Cuts.cc:205
InteractionMode GetMode(const event::Interaction &truth)
Definition: TruthMatch.cc:5
std::array< bool, nTruthCuts > ProcessTruthCuts(const numu::RecoEvent &event, const event::Event &core, unsigned truth_vertex_index, bool SequentialCuts=true) const
Definition: Cuts.cc:86
const geo::GeometryCore * geometry
process_name opflash particleana ie x
static std::string mode2Str(const numu::InteractionMode &mode)
Definition: Histograms.h:78
CRTMatch crt_match
CRTMatch.
Definition: RecoTrack.h:59
std::vector< std::vector< std::array< TrackProfiles, Cuts::nCuts > > > fPrimaryTrackProfiles
Profile histograms for primary tracks.
Definition: Histograms.h:107
std::array< CosmicHistos, 4 > fCosmic
Definition: Histograms.h:108
TruthMatch match
Info for mathing to truth.
Definition: RecoEvent.h:42
timings intime T_reco cut_order
Definition: selectors.fcl:126
std::array< CRTHistos, Cuts::nCuts > fCRTs
Definition: Histograms.h:110
int mcparticle_id
MCParticle ID of the particle this track matches to (same as the ID of the RecoTrack of that particle...
int primary_track_index
Index of the primary track.
Definition: RecoEvent.h:27
InteractionHistos fInteraction[nHistos][nModes]
all the interaction histograms
Definition: Histograms.h:104
geo::BoxBoundedGeo DetectorVolume(const geo::GeometryCore *geometry)
Definition: GeoUtil.cc:35
std::array< bool, nCuts > ProcessRecoCuts(const numu::RecoEvent &event, unsigned reco_vertex_index, bool fSequentialCuts=true) const
Definition: Cuts.cc:125
process_name use argoneut_mc_hitfinder track
static const unsigned nHistos
Definition: Histograms.h:91
std::map< size_t, TrueParticle > particles
Map of indices to True particle information.
Definition: RecoEvent.h:49
double MaxLength(const geo::GeometryCore *geometry)
Definition: GeoUtil.cc:22
process_name opflashCryoW ana
std::vector< RecoInteraction > reco
List of reconstructed vertices.
Definition: RecoEvent.h:50
timings intime truth_cut_order
Definition: selectors.fcl:126
const std::vector< std::string > & TruthCutOrder() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
static const unsigned nCuts
total number of cuts
std::map< size_t, RecoTrack > tracks
Map of track indices to Track information.
Definition: RecoEvent.h:48
#define AS_NUMBER(value)
Definition: value.h:53
void Fill(const numu::RecoEvent &event, const event::Event &core, const Cuts &cutmaker, const std::vector< numu::TrackSelector > &selectors, const std::vector< numu::TrackFunction > &xfunctions, bool fill_all_tracks=true)
Definition: Histograms.cc:14
#define IS_NUMBER(value)
Definition: value.h:61
void Initialize(const std::string &prefix, const geo::BoxBoundedGeo &detector_volume, const std::vector< double > &tagger_volume)
static constexpr numu::InteractionMode allModes[nModes]
List of all interaction modes.
Definition: Histograms.h:93
const char mode
Definition: noise_ana.cxx:20
void Merge(const HistoList &merge)
Definition: HistoList.cc:31
Description of geometry of one entire detector.
bool PassFlashTrigger(const numu::RecoEvent &event) const
Definition: Cuts.cc:121
void Initialize(const geo::GeometryCore *geometry, const sbnd::CRTGeoAlg &crt_geo, const Cuts &cuts, const std::string &prefix, const std::vector< std::string > &track_histo_types, const std::vector< std::string > &track_profile_types, const std::vector< std::tuple< unsigned, float, float >> &track_profile_xranges)
Definition: Histograms.cc:111
bool has_match
Whether a track match exists.
std::vector< std::array< TrackHistos, Cuts::nCuts > > fPrimaryTracks
Track histograms for priamry tracks in a candidate neutrino interaction.
Definition: Histograms.h:106
std::vector< TrackHistos > fAllTracks
Track histograms for all tracks.
Definition: Histograms.h:105
The standard event data definition.
Definition: Event.hh:228
TrackTruthMatch match
Truth matching information.
Definition: RecoTrack.h:57
static const unsigned nTruthCuts
Total number of truth cuts.
RecoSlice slice
Particle content of the interaction.
Definition: RecoEvent.h:39
A base class aware of world box coordinatesAn object describing a simple shape can inherit from this ...
Definition: BoxBoundedGeo.h:33
CRTHit hit
Definition: CRTMatch.h:32
pdgs k
Definition: selectors.fcl:22
void Fill(const numu::RecoInteraction &vertex, const numu::RecoEvent &event, const std::vector< event::Interaction > &core_truth)
BEGIN_PROLOG could also be cout
const std::vector< std::string > & CutOrder() const
std::vector< Interaction > truth
All truth interactions.
Definition: Event.hh:232