9#include <framework/gearbox/Const.h>
10#include <reconstruction/dataobjects/DedxConstants.h>
16#include <TApplication.h>
26const int num_dedx_bins = 100;
34int main(
int argc,
char* argv[])
38 if (argc < 2 or argc > 3) {
39 std::cerr <<
"Usage: " << argv[0] <<
" INPUT_FILE [OUTPUT_FILE]\n\n";
41 "Generates PDFs for the DedxPID module, requires an input .root file created by running DedxPID with enableDebug=True.\n";
42 std::cerr <<
"If OUTPUT_FILE is not given, histograms will be drawn instead of being saved.\n";
46 const TString input_filename(argv[1]);
47 TString output_filename;
49 output_filename = TString(argv[2]);
52 TApplication app(
"noname", &argc, argv);
53 gROOT->SetStyle(
"Plain");
54 gStyle->SetPalette(1);
56 TFile* file =
new TFile(input_filename,
"READ");
57 TTree* tree =
dynamic_cast<TTree*
>(file->Get(
"tree"));
59 std::cerr <<
"'tree' not found, aborting.\n";
66 const bool save_graphs = !output_filename.IsNull();
69 pdffile =
new TFile(output_filename,
"RECREATE");
71 c1 =
new TCanvas(
"c1", input_filename, 600, 900);
72 c1->Divide(num_pdg_codes, Dedx::c_num_detectors);
76 const int num_p_bins = 69;
77 double pbins[num_p_bins + 1];
78 pbins[0] = 0.0; pbins[1] = 0.05;
79 std::cout <<
": " << pbins[0] <<
"\n";
80 std::cout <<
": " << pbins[1] <<
"\n";
81 for (
int bin = 2; bin <= num_p_bins; bin++) {
83 pbins[bin] = 0.025 + 0.025 * bin;
85 pbins[bin] = pbins[19] + 0.05 * (bin - 19);
87 pbins[bin] = pbins[59] + 0.3 * (bin - 59);
88 std::cout <<
": " << pbins[bin] <<
"\n";
91 for (
int i = 0; i < 2; i++) {
92 const bool use_truncated_mean = (i == 1);
93 const char* suffix = use_truncated_mean ?
"_trunc" :
"";
95 for (
int iPart = 0; iPart < num_pdg_codes; iPart++) {
96 TH2F* hists[Dedx::c_num_detectors];
101 for (
int detector = 0; detector <= Dedx::c_SVD; detector++) {
102 std::cout <<
"i " << i <<
", d" << detector <<
"\n";
103 const char* flayer_var =
"VXDDedxTracks.dedxLayer";
104 TString flayer_selection;
105 double dedx_cutoff = 0;
106 switch (Dedx::Detector(detector)) {
108 flayer_selection = TString::Format(
"%s < 0 && %s >= -2", flayer_var, flayer_var);
112 flayer_selection = TString::Format(
"%s < -2", flayer_var);
119 const TString histname = TString::Format(
"hist_d%i_%i%s", detector, pdg_code, suffix);
120 const char* varname = use_truncated_mean ?
"VXDDedxTracks.m_dedxAvgTruncated" :
"VXDDedxTracks.dedx";
122 hists[detector] =
new TH2F(histname.Data(), histname.Data(),
124 num_dedx_bins, 0, dedx_cutoff);
125 hists[detector]->Sumw2();
126 if (use_truncated_mean)
127 tree->Project(histname.Data(),
128 TString::Format(
"%s[][%i]:VXDDedxTracks.m_p", varname, detector),
129 TString::Format(
"%s < %g && abs(VXDDedxTracks.m_pdg) == %i && %s", varname, dedx_cutoff, pdg_code, flayer_selection.Data()));
131 tree->Project(histname.Data(),
132 TString::Format(
"%s:VXDDedxTracks.m_p", varname),
133 TString::Format(
"%s < %g && abs(VXDDedxTracks.m_pdg) == %i && %s", varname, dedx_cutoff, pdg_code, flayer_selection.Data()));
137 int detector = (int)Dedx::c_CDC;
138 std::cout <<
"i " << i <<
", d" << detector <<
"\n";
139 double dedx_cutoff = 0;
142 const TString histname = TString::Format(
"hist_d%i_%i%s", detector, pdg_code, suffix);
143 const char* varname = use_truncated_mean ?
"CDCDedxTracks.m_dedxAvgTruncated" :
"CDCDedxTracks.m_lDedx";
145 hists[detector] =
new TH2F(histname.Data(), histname.Data(),
147 num_dedx_bins, 0, dedx_cutoff);
148 hists[detector]->Sumw2();
149 if (use_truncated_mean)
150 tree->Project(histname.Data(),
151 TString::Format(
"%s[][%i]:CDCDedxTracks.m_pCDC", varname, detector),
152 TString::Format(
"CDCDedxTracks.m_lNHitsUsed > 15 && %s < %g && abs(CDCDedxTracks.m_pdg) == %i", varname, dedx_cutoff, pdg_code));
154 tree->Project(histname.Data(),
155 TString::Format(
"%s:CDCDedxTracks.m_pCDC", varname),
156 TString::Format(
"CDCDedxTracks.m_lNHitsUsed > 15 && %s < %g && abs(CDCDedxTracks.m_pdg) == %i", varname, dedx_cutoff, pdg_code));
160 for (
int d = 0; d < Dedx::c_num_detectors; d++) {
161 for (
int pbin = 0; pbin <= num_p_bins + 1; pbin++) {
164 for (
int dedxbin = 0; dedxbin <= num_dedx_bins + 1; dedxbin++) {
165 integral += hists[d]->GetBinContent(pbin, dedxbin);
172 const double normal_width = -(hists[d]->GetYaxis()->GetBinLowEdge(1) - hists[d]->GetYaxis()->GetBinUpEdge(
173 num_dedx_bins)) / num_dedx_bins;
174 for (
int dedxbin = 0; dedxbin <= num_dedx_bins + 1; dedxbin++) {
175 hists[d]->SetBinContent(pbin, dedxbin, hists[d]->GetBinContent(pbin,
176 dedxbin) / integral * hists[d]->GetYaxis()->GetBinWidth(dedxbin) / normal_width);
184 for (
int d = 0; d < Dedx::c_num_detectors; d++) {
188 TPad* pad =
static_cast<TPad*
>(c1->cd(num_pdg_codes * d + iPart + 1));
190 hists[d]->Draw(
"colz");
201 std::cout <<
"Saved histograms into '" << output_filename.Data() <<
"'.\n";
static const unsigned int c_SetSize
Number of elements (for use in array bounds etc.)
const ParticleType & at(unsigned int index) const
Return particle at given index, or end() if out of range.
int getPDGCode() const
PDG code.
static const ParticleSet chargedStableSet
set of charged stable particles
Abstract base class for different kinds of events.