13 #include "FairRootManager.h"
15 #include "TClonesArray.h"
20 #include "TObjArray.h"
69 TFile* histFile =
new TFile(
fFileName,
"READ");
70 if (!histFile || !histFile->IsOpen()) {
71 Error(
"ReadData",
"Could not open input file: %s",
fFileName.Data());
74 Info(
"ReadData",
"input file %s opened",
fFileName.Data());
80 TObjArray* inArr = NULL;
84 std::vector<TString> histnames {
"MC_electron_p_eloss",
89 inArr =
new TObjArray(histnames.size());
90 for (
size_t i = 0;
i < histnames.size();
i++) {
91 h[
i] = (TH2D*) histFile->Get(histnames[
i]);
95 h[
i]->SetNameTitle(histnames[
i], histnames[
i]);
98 for (Int_t
x = 1;
x <=
h[
i]->GetNbinsX();
x++) {
100 for (Int_t
y = 1;
y <=
h[
i]->GetNbinsY();
y++)
101 sum +=
h[
i]->GetBinContent(
x,
y);
102 for (Int_t
y = 1;
y <=
h[
i]->GetNbinsY();
y++)
104 h[
i]->SetBinContent(
x,
y,
h[
i]->GetBinContent(
x,
y) / sum);
111 std::vector<TString> histnames {
"MC_electron_eloss",
116 inArr =
new TObjArray(histnames.size());
117 for (
size_t i = 0;
i < histnames.size();
i++) {
118 h[
i] = (TH2D*) histFile->Get(histnames[
i]);
122 h[
i]->SetNameTitle(histnames[
i], histnames[
i]);
125 h[
i]->Scale(1. /
h[
i]->Integral());
132 std::vector<TString> histnames {
"ELE_electron_p_eloss",
135 "ELE_proton_p_eloss",
137 inArr =
new TObjArray(histnames.size());
138 for (
size_t i = 0;
i < histnames.size();
i++) {
139 h[
i] = (TH2D*) histFile->Get(histnames[
i]);
140 h[
i]->SetNameTitle(histnames[
i], histnames[
i]);
144 h[
i]->SetNameTitle(histnames[
i], histnames[
i]);
147 for (Int_t
x = 1;
x <=
h[
i]->GetNbinsX();
x++) {
149 for (Int_t
y = 1;
y <=
h[
i]->GetNbinsY();
y++)
150 sum +=
h[
i]->GetBinContent(
x,
y);
151 for (Int_t
y = 1;
y <=
h[
i]->GetNbinsY();
y++)
153 h[
i]->SetBinContent(
x,
y,
h[
i]->GetBinContent(
x,
y) / sum);
160 std::vector<TString> histnames {
"ELE_electron_eloss",
165 inArr =
new TObjArray(histnames.size());
166 for (
size_t i = 0;
i < histnames.size();
i++) {
167 h[
i] = (TH2D*) histFile->Get(histnames[
i]);
171 h[
i]->SetNameTitle(histnames[
i], histnames[
i]);
174 h[
i]->Scale(1. /
h[
i]->Integral());
182 for (Int_t
i = 0;
i < inArr->GetEntriesFast();
i++) {
184 TH1* hist = (TH1*) inArr->At(
i)->Clone();
185 TString name = hist->GetTitle();
188 if (name.Contains(
"electron"))
190 else if (name.Contains(
"pion"))
192 else if (name.Contains(
"kaon"))
194 else if (name.Contains(
"proton"))
196 else if (name.Contains(
"muon"))
203 "particle histogram %s added to array at %d",
233 FairRootManager* ioman = FairRootManager::Instance();
235 Error(
"Init",
"RootManager not instantised!");
242 Error(
"Init",
"No GlobalTack array!");
247 fTrackArray = (TClonesArray*) ioman->GetObject(
"TrdTrack");
249 Error(
"Init",
"No TrdTrack array!");
254 fTrdHitArray = (TClonesArray*) ioman->GetObject(
"TrdHit");
256 Error(
"Init",
"No TrdHit array!");
277 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
282 if (trdTrackIndex == -1) {
290 Warning(
"Exec",
"No Trd track pointer");
302 for (Int_t iSpecies = 0; iSpecies <
fgkNParts; iSpecies++) {
303 prob[iSpecies] = 1.0;
308 momentum = TMath::Abs(1. / (pTrack->
GetParamFirst()->GetQp()));
309 }
else if (TMath::Abs(pTrack->
GetParamLast()->GetQp()) > 0.) {
310 momentum = TMath::Abs(1. / (pTrack->
GetParamLast()->GetQp()));
312 Warning(
"Exec",
"Could not assign any momentum to the track, use p=0.");
321 for (Int_t iTRD = 0; iTRD < pTrack->
GetNofHits(); iTRD++) {
326 dEsum += trdHit->
GetELoss() * 1.e+6;
328 for (Int_t iSpecies = 0; iSpecies <
fgkNParts; iSpecies++) {
336 for (Int_t iSpecies = 0; iSpecies <
fgkNParts; iSpecies++) {
337 if (prob[iSpecies] >= 0. && prob[iSpecies] <= 1.)
338 probTotal += prob[iSpecies];
342 for (Int_t iSpecies = 0; iSpecies <
fgkNParts; iSpecies++) {
345 prob[iSpecies] /= probTotal;
347 prob[iSpecies] = -1.5;
366 Double_t dedx)
const {
373 if (k < 0 || k >
fgkNParts) {
return -999.; }
378 Info(
"GetProbability",
"no input histogram");
383 if (hist->GetEntries() < 1000.) {
384 Info(
"GetProbability",
"input histogram is almost empty");
388 Int_t ndim = hist->GetDimension();
390 Float_t maxY = hist->GetYaxis()->GetXmax();
391 Float_t maxX = hist->GetXaxis()->GetXmax();
394 Bool_t overflowY = (dedx > maxY);
395 Bool_t overflowX = (ndim == 1 ? (dedx > maxX) : (mom > maxX));
399 (ndim == 1 ? 0. : hist->GetYaxis()->GetBinWidth(hist->GetNbinsY()));
400 Float_t binwidthX = hist->GetXaxis()->GetBinWidth(hist->GetNbinsX());
405 hist->FindBin((overflowX ? maxX - binwidthX : dedx));
407 hist->FindBin((overflowX ? maxX - binwidthX : mom),
408 (overflowY ? maxY - binwidthY : dedx));
412 if (TMath::Abs(hist->GetBinContent(bin)) < 1.e-15) {
413 Double_t con = -999.;
415 con = hist->Interpolate((overflowX ? maxX - binwidthX : dedx));
418 ->Interpolate((overflowX ? maxX - binwidthX : mom),
419 (overflowY ? maxY - binwidthY : dedx));
423 return hist->GetBinContent(bin);