-
Notifications
You must be signed in to change notification settings - Fork 1
/
TSPDFGen.cxx
112 lines (82 loc) · 2.7 KB
/
TSPDFGen.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include "canvas/Utilities/InputTag.h"
#include "nusimdata/SimulationBase/MCTruth.h"
#include "lardataobj/MCBase/MCShower.h"
#include "lardataobj/MCBase/MCTrack.h"
#include "gallery/Event.h"
#include <TH2F.h>
#include <TH1F.h>
#include "TSUtil.h"
#include "TSPDFGen.h"
#include "TSSelection.h"
namespace galleryfmwk {
bool TSPDFGen::initialize() {
return true;
}
bool TSPDFGen::analyze(gallery::Event* ev) {
// Get handles for event data
art::InputTag mctruth_tag(_mct_producer);
auto const& mctruth_list = (*ev->getValidHandle<std::vector<simb::MCTruth> >(mctruth_tag));
art::InputTag mcshower_tag(_mcshw_producer);
auto const& mcshower_list = (*ev->getValidHandle<std::vector<sim::MCShower> >(mcshower_tag));
art::InputTag mctrack_tag(_mctrk_producer);
auto const& mctrack_list = (*ev->getValidHandle<std::vector<sim::MCTrack> >(mctrack_tag));
_fout->cd();
// Loop over MCTruth interactions
for(size_t i=0; i<mctruth_list.size(); i++) {
auto const& mctruth = mctruth_list.at(i);
// Get vertex-associated contained tracks
for (size_t j=0; j<mctrack_list.size(); j++) {
const sim::MCTrack& mct = mctrack_list.at(j);
if (!TSSelection::goodTrack(mct, mctruth)) {
continue;
}
int pdg = mct.PdgCode();
// Create dE/dx distribution for this PDG code
if (_trackdedxs.find(pdg) == _trackdedxs.end()) {
char hname[50];
snprintf(hname, 50, "htrackdedx_%i", pdg);
_trackdedxs[pdg] = new TH2F(hname, ";Residual range;dE/dx (MeV/cm?)", 100, 0, 200, 100, 0, 10);
}
assert(!mct.dEdx().empty());
// Build up the track distribution
TH2F* h = tsutil::HistDEdx(mct);
_trackdedxs[pdg]->Add(h);
}
// Get vertex-associated contained showers
for (size_t j=0; j<mcshower_list.size(); j++) {
const sim::MCShower& mcs = mcshower_list.at(j);
if (!TSSelection::goodShower(mcs, mctruth)) {
continue;
}
int pdg = mcs.PdgCode();
// Create dE/dx distribution
if (_showerdedxs.find(pdg) == _showerdedxs.end()) {
char hname[50];
snprintf(hname, 50, "hshowerdedx_%i", pdg);
_showerdedxs[pdg] = new TH1F(hname, ";dE/dx (MeV/cm?);Entries", 100, 0, 10);
}
// Build up the shower distribution
double dedx = mcs.dEdx();
_showerdedxs.at(mcs.PdgCode())->Fill(dedx);
}
}
return true;
}
bool TSPDFGen::finalize() {
// Write ROOT file output
if (_fout) {
_fout->cd();
for (auto& it : _trackdedxs) {
it.second->Write();
}
for (auto& it : _showerdedxs) {
it.second->Write();
}
}
return true;
}
} // namespace gallery_fmwk