FairRoot/PandaRoot
Functions
AnalyseSimFile.C File Reference
#include <vector>

Go to the source code of this file.

Functions

std::map< int, double > GetFilledBins (TH1 *histo)
 
void Draw2DHisto (TTree *tree, TString xValue, TString yValue, TString histoName, TCut cut)
 
void FillPdgSelectHisto (std::map< int, double > &pdgValues, TH1 *pdgHisto)
 
int AnalyseSimFile (TString prefix)
 

Function Documentation

int AnalyseSimFile ( TString  prefix)

Definition at line 46 of file AnalyseSimFile.C.

References creator, Draw2DHisto(), FillPdgSelectHisto(), GetFilledBins(), outfile, p, pt(), simFile, simtree, theta, and TString.

47 {
48 
49  PndFileNameCreator creator(prefix.Data());
50  TString extension;
51  TString simFile = creator.GetSimFileName();
52  TString outputFile = creator.GetCustomFileName("sim_histos");
53  TFile outfile(outputFile.Data(),"RECREATE");
54 
55  std::cout << "InFileName: " << simFile.Data() << std::endl;
56  std::cout << "OutputFileName: " << outputFile.Data() << std::endl;
57 
58  TFile fileqa(simFile.Data());
59  TTree *simtree = (TTree*) fileqa.Get("pndsim");
60  std::cout << "SimTree: " << simtree << std::endl;
61  std::cout << "SimTree.GetEntries() " << simtree->GetEntries() << std::endl;
62 
63  TString theta = "TMath::RadToDeg()*TMath::ATan2(TMath::Sqrt(MCTrack.fPx^2+MCTrack.fPy^2),MCTrack.fPz)";
64  TString p = "TMath::Sqrt(MCTrack.fPx^2+MCTrack.fPy^2+MCTrack.fPz^2)";
65  TString pt = "TMath::Sqrt(MCTrack.fPx^2+MCTrack.fPy^2)";
66  TCut primCut = "MCTrack.GetMotherID()<0";
67  TCut secCut = "MCTrack.GetMotherID()>0";
68 
69  TH1I* pdgHistoPrim = new TH1I("pdgHistoPrim", "pdgHistoPrim", 20001, -10000.5, 10000.5);
70  TH1I* pdgHistoSec = new TH1I("pdgHistoSec", "pdgHistoSec", 20001, -10000.5, 10000.5);
71 
72  simtree->Draw("MCTrack.fPdgCode>>pdgHistoPrim", primCut, "goff");
73  simtree->Draw("MCTrack.fPdgCode>>pdgHistoSec", secCut, "goff");
74 
75  std::map<int, double> pdgValues = GetFilledBins(pdgHistoPrim);
76  TH1D* pdgHistoSelectPrim = new TH1D("pdgHistoSelectPrim","pdgHistoSelectPrim", pdgValues.size(),-0.5,pdgValues.size() -0.5);
77  FillPdgSelectHisto(pdgValues, pdgHistoSelectPrim);
78 
79  std::map<int, double> pdgValuesSec = GetFilledBins(pdgHistoSec);
80  TH1D* pdgHistoSelectSec = new TH1D("pdgHistoSelectSec","pdgHistoSelectSec", pdgValuesSec.size(),-0.5,pdgValuesSec.size() -0.5);
81  FillPdgSelectHisto(pdgValuesSec, pdgHistoSelectSec);
82 
83  outfile.cd();
84  pdgHistoSelectPrim->Write();
85  pdgHistoSelectSec->Write();
86 
87 
88  std::map<int, TH2*> ThetaPHistosPdg;
89  std::map<int, TH2*> PtPzHistosPdg;
90  TString histosNameThetaP = "histoThetaPforPdg_";
91  TString histosNamePtPz = "histoPtPzforPdg_";
92  TString pdgCut = "MCTrack.fPdgCode==";
93  TString myHistoName = histosNameThetaP;
94  myHistoName += "all";
95  ThetaPHistosPdg[0] = new TH2I(myHistoName.Data(),myHistoName.Data(),180,0,180,150,0,15);
96  Draw2DHisto(simtree, theta, p, myHistoName,primCut);
97 
98  myHistoName = histosNamePtPz;
99  myHistoName += "all";
100  PtPzHistosPdg[0] = new TH2I(myHistoName.Data(), myHistoName.Data(), 300, -15, 15, 150, 0, 15);
101  Draw2DHisto(simtree, "MCTrack.fPz", pt, myHistoName, primCut);
102 
103  outfile.cd();
104  ThetaPHistosPdg[0]->Write();
105  PtPzHistosPdg[0]->Write();
106 
107  for (auto pdg : pdgValues){
108  myHistoName = histosNameThetaP;
109  myHistoName += pdg.first;
110  TString myPdgString = pdgCut;
111  myPdgString += pdg.first;
112  TCut myPdgCut = myPdgString.Data();
113 
114  ThetaPHistosPdg[pdg.first] = new TH2I(myHistoName.Data(),myHistoName.Data(),180,0,180,150,0,15);
115  Draw2DHisto(simtree, theta, p, myHistoName, myPdgCut&&primCut);
116 
117  myHistoName = histosNamePtPz;
118  myHistoName += pdg.first;
119 
120  PtPzHistosPdg[pdg.first] = new TH2I(myHistoName.Data(),myHistoName.Data(),300,-15,15,150,0,15);
121  Draw2DHisto(simtree, "MCTrack.fPz", pt, myHistoName, myPdgCut&&primCut);
122 
123  outfile.cd();
124  ThetaPHistosPdg[pdg.first]->Write();
125  PtPzHistosPdg[pdg.first]->Write();
126  }
127 
128  cout << " Test passed" << endl;
129  cout << " All ok " << endl;
130  outfile.Close();
131  return 0;
132 }
void Draw2DHisto(TTree *tree, TString xValue, TString yValue, TString histoName, TCut cut)
Double_t p
Definition: anasim.C:58
void FillPdgSelectHisto(std::map< int, double > &pdgValues, TH1 *pdgHisto)
TTree * simtree
Definition: runPULL1.C:21
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
TString simFile
Definition: bump_emc.C:11
A simple class which adds the corresponding file extensions to a given base class.
PndMvdCreateDefaultApvMap * creator
std::map< int, double > GetFilledBins(TH1 *histo)
TString outfile
void Draw2DHisto ( TTree *  tree,
TString  xValue,
TString  yValue,
TString  histoName,
TCut  cut 
)

Definition at line 24 of file AnalyseSimFile.C.

References TString.

Referenced by AnalyseSimFile().

25 {
26  TString dataSelector = yValue;
27  dataSelector += ":";
28  dataSelector += xValue;
29  dataSelector += ">>";
30  dataSelector += histoName;
31  tree->Draw(dataSelector, cut, "goff");
32 }
TTree * tree
Definition: plot_dirc.C:12
double cut[MAX]
Definition: autocutx.C:36
void FillPdgSelectHisto ( std::map< int, double > &  pdgValues,
TH1 *  pdgHisto 
)

Definition at line 34 of file AnalyseSimFile.C.

References i, and TString.

Referenced by AnalyseSimFile().

35 {
36  int i = 0;
37  for (auto pdg : pdgValues){
38  pdgHisto->Fill(i,pdg.second);
39  TString pdgName = "";
40  pdgName += pdg.first;
41  pdgHisto->GetXaxis()->SetBinLabel(i+1, pdgName.Data());
42  i++;
43  }
44 }
Int_t i
Definition: run_full.C:25
std::map<int, double> GetFilledBins ( TH1 *  histo)

Definition at line 10 of file AnalyseSimFile.C.

Referenced by AnalyseSimFile().

11 {
12  std::map<int, double> result;
13  for (int ibin = 0; ibin < histo->GetNbinsX(); ibin++)
14  {
15  if (histo->GetBinContent(ibin) > 0)
16  {
17  std::cout << histo->GetBinCenter(ibin) << " : " << histo->GetBinContent(ibin) << std::endl;
18  result[histo->GetBinCenter(ibin)]=histo->GetBinContent(ibin);
19  }
20  }
21  return result;
22 }