11 #include <framework/gearbox/Const.h>
12 #include <reconstruction/dataobjects/DedxConstants.h>
18 #include <TApplication.h>
28 const int num_dedx_bins = 100;
36 int main(
int argc,
char* argv[])
40 if (argc < 2 or argc > 3) {
41 std::cerr <<
"Usage: " << argv[0] <<
" INPUT_FILE [OUTPUT_FILE]\n\n";
43 "Generates PDFs for the DedxPID module, requires an input .root file created by running DedxPID with enableDebug=True.\n";
44 std::cerr <<
"If OUTPUT_FILE is not given, histograms will be drawn instead of being saved.\n";
48 const TString input_filename(argv[1]);
49 TString output_filename;
51 output_filename = TString(argv[2]);
54 TApplication app(
"noname", &argc, argv);
55 gROOT->SetStyle(
"Plain");
56 gStyle->SetPalette(1);
58 TFile* file =
new TFile(input_filename,
"READ");
59 TTree* tree =
dynamic_cast<TTree*
>(file->Get(
"tree"));
61 std::cerr <<
"'tree' not found, aborting.\n";
68 const bool save_graphs = !output_filename.IsNull();
71 pdffile =
new TFile(output_filename,
"RECREATE");
73 c1 =
new TCanvas(
"c1", input_filename, 600, 900);
74 c1->Divide(num_pdg_codes, Dedx::c_num_detectors);
78 const int num_p_bins = 69;
79 double pbins[num_p_bins + 1];
80 pbins[0] = 0.0; pbins[1] = 0.05;
81 std::cout <<
": " << pbins[0] <<
"\n";
82 std::cout <<
": " << pbins[1] <<
"\n";
83 for (
int bin = 2; bin <= num_p_bins; bin++) {
85 pbins[bin] = 0.025 + 0.025 * bin;
87 pbins[bin] = pbins[19] + 0.05 * (bin - 19);
89 pbins[bin] = pbins[59] + 0.3 * (bin - 59);
90 std::cout <<
": " << pbins[bin] <<
"\n";
93 for (
int i = 0; i < 2; i++) {
94 const bool use_truncated_mean = (i == 1);
95 const char* suffix = use_truncated_mean ?
"_trunc" :
"";
97 for (
int iPart = 0; iPart < num_pdg_codes; iPart++) {
98 TH2F* hists[Dedx::c_num_detectors];
103 for (
int detector = 0; detector <= Dedx::c_SVD; detector++) {
104 std::cout <<
"i " << i <<
", d" << detector <<
"\n";
105 const char* flayer_var =
"VXDDedxTracks.dedxLayer";
106 TString flayer_selection;
107 double dedx_cutoff = 0;
108 switch (Dedx::Detector(detector)) {
110 flayer_selection = TString::Format(
"%s < 0 && %s >= -2", flayer_var, flayer_var);
114 flayer_selection = TString::Format(
"%s < -2", flayer_var);
121 const TString histname = TString::Format(
"hist_d%i_%i%s", detector, pdg_code, suffix);
122 const char* varname = use_truncated_mean ?
"VXDDedxTracks.m_dedxAvgTruncated" :
"VXDDedxTracks.dedx";
124 hists[detector] =
new TH2F(histname.Data(), histname.Data(),
126 num_dedx_bins, 0, dedx_cutoff);
127 hists[detector]->Sumw2();
128 if (use_truncated_mean)
129 tree->Project(histname.Data(),
130 TString::Format(
"%s[][%i]:VXDDedxTracks.m_p", varname, detector),
131 TString::Format(
"%s < %g && abs(VXDDedxTracks.m_pdg) == %i && %s", varname, dedx_cutoff, pdg_code, flayer_selection.Data()));
133 tree->Project(histname.Data(),
134 TString::Format(
"%s:VXDDedxTracks.m_p", varname),
135 TString::Format(
"%s < %g && abs(VXDDedxTracks.m_pdg) == %i && %s", varname, dedx_cutoff, pdg_code, flayer_selection.Data()));
139 int detector = (int)Dedx::c_CDC;
140 std::cout <<
"i " << i <<
", d" << detector <<
"\n";
141 double dedx_cutoff = 0;
144 const TString histname = TString::Format(
"hist_d%i_%i%s", detector, pdg_code, suffix);
145 const char* varname = use_truncated_mean ?
"CDCDedxTracks.m_dedxAvgTruncated" :
"CDCDedxTracks.m_lDedx";
147 hists[detector] =
new TH2F(histname.Data(), histname.Data(),
149 num_dedx_bins, 0, dedx_cutoff);
150 hists[detector]->Sumw2();
151 if (use_truncated_mean)
152 tree->Project(histname.Data(),
153 TString::Format(
"%s[][%i]:CDCDedxTracks.m_pCDC", varname, detector),
154 TString::Format(
"CDCDedxTracks.m_lNHitsUsed > 15 && %s < %g && abs(CDCDedxTracks.m_pdg) == %i", varname, dedx_cutoff, pdg_code));
156 tree->Project(histname.Data(),
157 TString::Format(
"%s:CDCDedxTracks.m_pCDC", varname),
158 TString::Format(
"CDCDedxTracks.m_lNHitsUsed > 15 && %s < %g && abs(CDCDedxTracks.m_pdg) == %i", varname, dedx_cutoff, pdg_code));
162 for (
int d = 0; d < Dedx::c_num_detectors; d++) {
163 for (
int pbin = 0; pbin <= num_p_bins + 1; pbin++) {
166 for (
int dedxbin = 0; dedxbin <= num_dedx_bins + 1; dedxbin++) {
167 integral += hists[d]->GetBinContent(pbin, dedxbin);
174 const double normal_width = -(hists[d]->GetYaxis()->GetBinLowEdge(1) - hists[d]->GetYaxis()->GetBinUpEdge(
175 num_dedx_bins)) / num_dedx_bins;
176 for (
int dedxbin = 0; dedxbin <= num_dedx_bins + 1; dedxbin++) {
177 hists[d]->SetBinContent(pbin, dedxbin, hists[d]->GetBinContent(pbin,
178 dedxbin) / integral * hists[d]->GetYaxis()->GetBinWidth(dedxbin) / normal_width);
186 for (
int d = 0; d < Dedx::c_num_detectors; d++) {
190 TPad* pad =
static_cast<TPad*
>(c1->cd(num_pdg_codes * d + iPart + 1));
192 hists[d]->Draw(
"colz");
203 std::cout <<
"Saved histograms into '" << output_filename.Data() <<
"'.\n";