CbmRoot
CbmAnaLmvmDrawStudy.cxx
Go to the documentation of this file.
1 
7 #include "CbmAnaLmvmDrawStudy.h"
8 
9 #include "CbmDrawHist.h"
10 #include "CbmHistManager.h"
11 #include "CbmUtils.h"
12 
13 #include <iomanip>
14 #include <iostream>
15 #include <string>
16 
17 #include <boost/assign/list_of.hpp>
18 
19 #include "TCanvas.h"
20 #include "TClass.h"
21 #include "TEllipse.h"
22 #include "TF1.h"
23 #include "TFile.h"
24 #include "TH1.h"
25 #include "TH1D.h"
26 #include "TH2D.h"
27 #include "TKey.h"
28 #include "TMath.h"
29 #include "TStyle.h"
30 #include "TSystem.h"
31 #include "TText.h"
32 #include <TLegend.h>
33 
34 using namespace std;
35 using namespace Cbm;
36 using boost::assign::list_of;
37 
38 
39 void CbmAnaLmvmDrawStudy::DrawFromFile(const vector<string>& fileNames,
40  const vector<string>& fileNamesMean,
41  const vector<string>& studyNames,
42  const string& outputDir) {
43  fOutputDir = outputDir;
44 
46 
47  fNofStudies = fileNames.size();
48  fHM.resize(fNofStudies);
49  for (int i = 0; i < fNofStudies; i++) {
50  fHM[i] = new CbmHistManager();
51  TFile* file = new TFile(fileNames[i].c_str());
52  fHM[i]->ReadFromFile(file);
53  Int_t fNofEvents = (int) H1(i, "fh_event_number")->GetEntries();
54  fHM[i]->ScaleByPattern(".*", 1. / fNofEvents);
55  }
56 
57  // files with mean histograms
58  //fMeanFiles.resize(fileNamesMean.size());
59  //for (int i = 0; i < fileNamesMean.size(); i++){
60  //fMeanFiles[i] = new TFile(fileNamesMean[i].c_str(), "READ");
61  //}
62  fMeanFiles = fileNamesMean;
63  fStudyNames = studyNames;
64 
65  DrawMinv();
66  DrawNofBgTracks();
67  DrawBgSourceTracks();
68  DrawBgSourcePairs();
69  DrawBgSourceMinv();
70  DrawDistributions("lmvm_study_source_mom_", "fh_source_mom_", kTtCut, kPi0);
71  DrawDistributions("lmvm_study_source_mom_", "fh_source_mom_", kTtCut, kGamma);
72 
73  DrawDistributions("lmvm_study_source_pt_", "fh_source_pt_", kTtCut, kPi0);
74  DrawDistributions("lmvm_study_source_pt_", "fh_source_pt_", kTtCut, kGamma);
75 
76  SaveCanvasToImage();
77 }
78 
79 TCanvas* CbmAnaLmvmDrawStudy::CreateCanvas(const string& name,
80  const string& title,
81  int width,
82  int height) {
83  TCanvas* c = new TCanvas(name.c_str(), title.c_str(), width, height);
84  fCanvas.push_back(c);
85  return c;
86 }
87 
88 void CbmAnaLmvmDrawStudy::DrawTextOnHist(const string& text,
89  Double_t x1,
90  Double_t y1,
91  Double_t x2,
92  Double_t y2) {
93  TLegend* leg = new TLegend(x1, y1, x2, y2);
94  leg->AddEntry(new TH2D(), text.c_str(), "");
95  leg->SetFillColor(kWhite);
96  leg->SetFillStyle(0);
97  leg->SetBorderSize(0);
98  leg->Draw();
99 }
100 
101 TH1D* CbmAnaLmvmDrawStudy::H1(int studyNum, const string& name) {
102  return (TH1D*) fHM[studyNum]->H1(name);
103 }
104 
105 TH2D* CbmAnaLmvmDrawStudy::H2(int studyNum, const string& name) {
106  return (TH2D*) fHM[studyNum]->H1(name);
107 }
108 
110  for (unsigned int i = 0; i < fCanvas.size(); i++) {
111  Cbm::SaveCanvasAsImage(fCanvas[i], fOutputDir);
112  }
113 }
114 
116  h->GetXaxis()->SetLabelSize(0.06);
117  for (Int_t step = 0; step < CbmLmvmHist::fNofAnaSteps; step++) {
118  h->GetXaxis()->SetBinLabel(step + 1,
119  CbmLmvmHist::fAnaStepsLatex[step].c_str());
120  }
121 }
122 
124  vector<TH1*> hPtCut, hTtCut;
125  hPtCut.resize(fMeanFiles.size());
126  hTtCut.resize(fMeanFiles.size());
127  int nRebin = 20;
128  for (unsigned int i = 0; i < fMeanFiles.size(); i++) {
129  TFile* f = new TFile(fMeanFiles[i].c_str(), "READ");
130 
131  hPtCut[i] = (TH1D*) f->Get("fh_bg_minv_ptcut")->Clone();
132  hPtCut[i]->Rebin(nRebin);
133  hPtCut[i]->SetMinimum(1e-6);
134  hTtCut[i] = (TH1D*) f->Get("fh_bg_minv_ttcut")->Clone();
135  hTtCut[i]->Rebin(nRebin);
136  hPtCut[i]->SetMinimum(1e-6);
137  //f->Close();
138  }
139  CreateCanvas(
140  "lmvm_study_minv_bg_ttcut", "lmvm_study_minv_bg_ttcut", 600, 600);
141  DrawH1(hTtCut, fStudyNames, kLinear, kLog, true, 0.70, 0.55, 0.99, 0.99, "");
142 
143  CreateCanvas(
144  "lmvm_study_minv_bg_ptcut", "lmvm_study_minv_bg_ptcut", 600, 600);
145  DrawH1(hPtCut, fStudyNames, kLinear, kLog, true, 0.70, 0.55, 0.99, 0.99, "");
146 
147 
148  /* TCanvas *c1 = CreateCanvas("lmvm_study_minv_urqmd", "lmvm_study_minv_urqmd", 900, 900);
149  vector<TH1*> hbg;
150  hbg.resize(fNofStudies);
151  for (int i = 0; i < fNofStudies; i++){
152  hbg[i] = (TH1D*)H1(i, "fh_bg_minv_ptcut")->Clone();
153  hbg[i]->Rebin(20);
154  // hbg[i]->GetYaxis()->SetTitle("Tracks/event x10^{-1}");
155  //hbg[i]->GetXaxis()->SetRange(kElId + 1, kPtCut + 1);
156  hbg[i]->SetMinimum(1e-6);
157  }
158  //SetAnalysisStepLabels(hbg[0]);
159  DrawH1(hbg, fStudyNames, kLinear, kLog, true, 0.70, 0.75, 0.99, 0.99, "");
160  for (int i = 0; i < fNofStudies; i++){
161  hbg[i]->SetLineWidth(3.);
162  */
163 }
164 
166  CreateCanvas(
167  "lmvm_study_nof_bg_tracks", "lmvm_study_nof_bg_tracks", 600, 600);
168  vector<TH1*> hbg;
169  hbg.resize(fNofStudies);
170  for (int i = 0; i < fNofStudies; i++) {
171  hbg[i] = (TH1D*) H1(i, "fh_nof_bg_tracks")->Clone();
172  hbg[i]->Scale(10);
173  hbg[i]->GetYaxis()->SetTitle("Tracks/event x10^{-1}");
174  hbg[i]->GetXaxis()->SetRange(kElId + 1, kPtCut + 1);
175  hbg[i]->SetMinimum(0.0);
176  }
177  SetAnalysisStepLabels(hbg[0]);
178  DrawH1(hbg, fStudyNames, kLinear, kLinear, true, 0.70, 0.75, 0.99, 0.99, "");
179  for (int i = 0; i < fNofStudies; i++) {
180  hbg[i]->SetLineWidth(3.);
181  }
182 }
183 
185  TCanvas* c = CreateCanvas(
186  "lmvm_study_source_tracks_abs", "lmvm_study_source_tracks_abs", 1200, 400);
187  c->Divide(3, 1);
188  for (int iP = 0; iP < 3; iP++) {
189  c->cd(iP + 1);
190  vector<TH1*> habsPx;
191  habsPx.resize(fNofStudies);
192  for (int i = 0; i < fNofStudies; i++) {
193  TH2D* habs = (TH2D*) H2(i, "fh_source_tracks")->Clone();
194  int min = iP + 1;
195  int max = iP + 1;
196  if (iP == 2) max = 9;
197  stringstream ss;
198  ss << "fh_source_tracks_" << i << "_" << min << "_" << max;
199  habsPx[i] = habs->ProjectionX(ss.str().c_str(), min, max);
200  habsPx[i]->GetXaxis()->SetRange(kElId + 1, kPtCut + 1);
201  habsPx[i]->GetYaxis()->SetTitle("Tracks per event x10^{-2}");
202  habsPx[i]->Scale(100);
203  }
204  DrawH1(
205  habsPx, fStudyNames, kLinear, kLinear, true, 0.70, 0.75, 0.99, 0.99, "");
206  SetAnalysisStepLabels(habsPx[0]);
207  for (int i = 0; i < fNofStudies; i++) {
208  habsPx[i]->SetMinimum(0.);
209  habsPx[i]->SetLineWidth(3.);
210  }
211  string txt = "#gamma";
212  if (iP == 1) txt = "#pi^{0}";
213  if (iP == 2) txt = "oth.";
214  DrawTextOnHist(txt, 0.5, 0.9, 0.6, 0.99);
215  }
216 }
217 
219  TCanvas* c = CreateCanvas(
220  "lmvm_study_source_pairs_abs", "lmvm_study_source_pairs_abs", 1200, 800);
221  c->Divide(3, 2);
222  for (int iP = 0; iP < 6; iP++) {
223  c->cd(iP + 1);
224  vector<TH1*> habsPx;
225  habsPx.resize(fNofStudies);
226  for (int i = 0; i < fNofStudies; i++) {
227  TH2D* habs = (TH2D*) H2(i, "fh_source_pairs")->Clone();
228  int min = iP + 1;
229  int max = iP + 1;
230  stringstream ss;
231  ss << "fh_source_pairs_" << i << "_" << min << "_" << max;
232  habsPx[i] = habs->ProjectionX(ss.str().c_str(), min, max);
233  habsPx[i]->GetXaxis()->SetRange(kElId + 1, kPtCut + 1);
234  habsPx[i]->GetYaxis()->SetTitle("Pairs per event x10^{-3}");
235  habsPx[i]->Scale(1000);
236  }
237  DrawH1(
238  habsPx, fStudyNames, kLinear, kLinear, true, 0.70, 0.75, 0.99, 0.99, "");
239  SetAnalysisStepLabels(habsPx[0]);
240  for (int i = 0; i < fNofStudies; i++) {
241  habsPx[i]->SetMinimum(0.);
242  habsPx[i]->SetLineWidth(3.);
243  }
244  DrawTextOnHist(CbmLmvmHist::fBgPairSourceLatex[iP], 0.4, 0.9, 0.6, 0.99);
245  }
246 
247  DrawBgSourcePairsStep(kPtCut);
248  DrawBgSourcePairsStep(kTtCut);
249 }
250 
252  stringstream ssC;
253  ssC << "lmvm_study_source_pairs_" << CbmLmvmHist::fAnaSteps[step];
254  CreateCanvas(ssC.str().c_str(), ssC.str().c_str(), 600, 600);
255  vector<TH1*> habsPx;
256  habsPx.resize(fNofStudies);
257  for (int i = 0; i < fNofStudies; i++) {
258  TH2D* habs = (TH2D*) H2(i, "fh_source_pairs")->Clone();
259  stringstream ss;
260  ss << "fh_source_pairs_" << i << "_" << CbmLmvmHist::fAnaSteps[step];
261  habsPx[i] = habs->ProjectionY(ss.str().c_str(), step + 1, step + 1);
262  habsPx[i]->GetYaxis()->SetTitle("Pairs per event x10^{-3}");
263  habsPx[i]->Scale(1000);
264  }
265  DrawH1(
266  habsPx, fStudyNames, kLinear, kLinear, true, 0.70, 0.75, 0.99, 0.99, "");
267  for (int i = 0; i < fNofStudies; i++) {
268  habsPx[i]->SetMinimum(0.);
269  habsPx[i]->SetLineWidth(3.);
270  for (UInt_t y = 1; y <= CbmLmvmHist::fBgPairSourceLatex.size(); y++) {
271  habsPx[i]->GetXaxis()->SetBinLabel(
272  y, CbmLmvmHist::fBgPairSourceLatex[y - 1].c_str());
273  }
274  }
275 }
276 
277 void CbmAnaLmvmDrawStudy::DrawDistributions(const string& canvasName,
278  const string& histName,
279  int step,
280  int sourceType) {
281  stringstream ssC;
282  ssC << canvasName << CbmLmvmHist::fAnaSteps[step] << "_"
283  << CbmLmvmHist::fSourceTypes[sourceType];
284  CreateCanvas(ssC.str().c_str(), ssC.str().c_str(), 900, 900);
285 
286  string s = histName + CbmLmvmHist::fAnaSteps[step] + "_"
287  + CbmLmvmHist::fSourceTypes[sourceType];
288  vector<TH1*> h;
289  h.resize(fNofStudies);
290  for (int i = 0; i < fNofStudies; i++) {
291  h[i] = (TH1D*) H1(i, s)->Clone();
292  h[i]->GetXaxis()->SetRangeUser(0., 3.);
293  }
294  DrawH1(h, fStudyNames, kLinear, kLinear, true, 0.70, 0.75, 0.99, 0.99, "");
295 }
296 
298  TCanvas* c = CreateCanvas(
299  "lmvm_study_source_minv_ptcut", "lmvm_study_source_minv_ptcut", 1200, 800);
300  c->Divide(3, 2);
301  for (int iP = 0; iP < CbmLmvmHist::fNofBgPairSources; iP++) {
302  stringstream ss;
303  ss << "fh_source_bg_minv_" << iP << "_" << CbmLmvmHist::fAnaSteps[kPtCut];
304  c->cd(iP + 1);
305  vector<TH1*> habs;
306  habs.resize(fNofStudies);
307  for (int i = 0; i < fNofStudies; i++) {
308  habs[i] = (TH1D*) H1(i, ss.str())->Clone();
309  habs[i]->Rebin(40);
310  }
311  DrawH1(
312  habs, fStudyNames, kLinear, kLinear, true, 0.70, 0.75, 0.99, 0.99, "");
313  for (int i = 0; i < fNofStudies; i++) {
314  habs[i]->SetMinimum(0.);
315  habs[i]->SetLineWidth(3.);
316  }
317  DrawTextOnHist(CbmLmvmHist::fBgPairSourceLatex[iP], 0.4, 0.9, 0.6, 0.99);
318  }
319 }
320 
h
Generates beam ions for transport simulation.
Definition: CbmBeamGenerator.h:17
f
float f
Definition: L1/vectors/P4_F32vec4.h:24
kElId
@ kElId
Definition: CbmLmvmHist.h:20
CbmAnaLmvmDrawStudy::H1
TH1D * H1(int studyNum, const std::string &name)
Definition: CbmAnaLmvmDrawStudy.cxx:101
CbmLmvmHist::fBgPairSourceLatex
static const std::vector< std::string > fBgPairSourceLatex
Definition: CbmLmvmHist.h:57
kTtCut
@ kTtCut
Definition: CbmLmvmHist.h:26
CbmAnaLmvmDrawStudy::DrawBgSourcePairs
void DrawBgSourcePairs()
Definition: CbmAnaLmvmDrawStudy.cxx:218
CbmAnaLmvmDrawStudy::DrawBgSourcePairsStep
void DrawBgSourcePairsStep(int step)
Definition: CbmAnaLmvmDrawStudy.cxx:251
CbmLmvmHist::fNofAnaSteps
static const int fNofAnaSteps
Definition: CbmLmvmHist.h:49
kPtCut
@ kPtCut
Definition: CbmLmvmHist.h:27
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmAnaLmvmDrawStudy::DrawBgSourceMinv
void DrawBgSourceMinv()
Definition: CbmAnaLmvmDrawStudy.cxx:297
CbmAnaLmvmDrawStudy.h
CbmAnaLmvmDrawStudy::CreateCanvas
TCanvas * CreateCanvas(const std::string &name, const std::string &title, int width, int height)
Definition: CbmAnaLmvmDrawStudy.cxx:79
CbmDrawHist.h
Helper functions for drawing 1D and 2D histograms and graphs.
CbmAnaLmvmDrawStudy::DrawNofBgTracks
void DrawNofBgTracks()
Definition: CbmAnaLmvmDrawStudy.cxx:165
CbmHistManager.h
Histogram manager.
CbmAnaLmvmDrawStudy::H2
TH2D * H2(int studyNum, const std::string &name)
Definition: CbmAnaLmvmDrawStudy.cxx:105
CbmLmvmHist::fNofBgPairSources
static const int fNofBgPairSources
Definition: CbmLmvmHist.h:56
CbmAnaLmvmDrawStudy
Definition: CbmAnaLmvmDrawStudy.h:25
min
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:33
CbmAnaLmvmDrawStudy::DrawFromFile
void DrawFromFile(const std::vector< std::string > &fileNames, const std::vector< std::string > &fileNamesMean, const std::vector< std::string > &studyNames, const std::string &outputDir="")
Implement functionality of drawing histograms in the macro from the specified files,...
Definition: CbmAnaLmvmDrawStudy.cxx:39
CbmLmvmHist::fAnaSteps
static const std::vector< std::string > fAnaSteps
Definition: CbmLmvmHist.h:50
DrawH1
void DrawH1(TH1 *hist, HistScale logx, HistScale logy, const string &drawOpt, Int_t color, Int_t lineWidth, Int_t lineStyle, Int_t markerSize, Int_t markerStyle)
Definition: CbmDrawHist.cxx:49
CbmLmvmHist::fAnaStepsLatex
static const std::vector< std::string > fAnaStepsLatex
Definition: CbmLmvmHist.h:51
CbmHistManager
Histogram manager.
Definition: CbmHistManager.h:41
kLinear
@ kLinear
Definition: CbmDrawHist.h:79
CbmLmvmHist::fSourceTypes
static const std::vector< std::string > fSourceTypes
Definition: CbmLmvmHist.h:45
kGamma
@ kGamma
Definition: CbmLmvmHist.h:10
CbmUtils.h
CbmAnaLmvmDrawStudy::DrawTextOnHist
void DrawTextOnHist(const std::string &text, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: CbmAnaLmvmDrawStudy.cxx:88
CbmAnaLmvmDrawStudy::DrawDistributions
void DrawDistributions(const std::string &canvasName, const std::string &histName, int step, int sourceType)
Definition: CbmAnaLmvmDrawStudy.cxx:277
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
ClassImp
ClassImp(CbmAnaLmvmDrawStudy)
SetDefaultDrawStyle
void SetDefaultDrawStyle()
Definition: CbmDrawHist.cxx:33
Cbm::SaveCanvasAsImage
void SaveCanvasAsImage(TCanvas *c, const std::string &dir, const std::string &option)
Definition: CbmUtils.cxx:20
CbmAnaLmvmDrawStudy::DrawBgSourceTracks
void DrawBgSourceTracks()
Definition: CbmAnaLmvmDrawStudy.cxx:184
CbmAnaLmvmDrawStudy::SetAnalysisStepLabels
void SetAnalysisStepLabels(TH1 *h)
Definition: CbmAnaLmvmDrawStudy.cxx:115
CbmAnaLmvmDrawStudy::SaveCanvasToImage
void SaveCanvasToImage()
Definition: CbmAnaLmvmDrawStudy.cxx:109
CbmAnaLmvmDrawStudy::DrawMinv
void DrawMinv()
Definition: CbmAnaLmvmDrawStudy.cxx:123
max
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:36
kLog
@ kLog
Definition: CbmDrawHist.h:78
kPi0
@ kPi0
Definition: CbmLmvmHist.h:10
Cbm
Definition: CbmGeometryUtils.cxx:31