]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG1/AliPerformanceDEdx.cxx
Changes required by adding of perfomrance tasks (Jacek)
[u/mrichter/AliRoot.git] / PWG1 / AliPerformanceDEdx.cxx
CommitLineData
777a0ba6 1//------------------------------------------------------------------------------
2// Implementation of AliPerformanceDEdx class. It keeps information from
3// comparison of reconstructed and MC particle tracks. In addtion,
4// it keeps selection cuts used during comparison. The comparison
5// information is stored in the ROOT histograms. Analysis of these
6// histograms can be done by using Analyse() class function. The result of
7// the analysis (histograms/graphs) are stored in the folder which is
8// a data of AliPerformanceDEdx.
9//
10// Author: J.Otwinowski 04/02/2008
11//------------------------------------------------------------------------------
12
13/*
14
15 // after running comparison task, read the file, and get component
16 gROOT->LoadMacro("$ALICE_ROOT/PWG1/Macros/LoadMyLibs.C");
17 LoadMyLibs();
18 TFile f("Output.root");
19 //AliPerformanceDEdx * compObj = (AliPerformanceDEdx*)f.Get("AliPerformanceDEdx");
20 AliPerformanceDEdx * compObj = (AliPerformanceDEdx*)coutput->FindObject("AliPerformanceDEdx");
21
22 // Analyse comparison data
23 compObj->Analyse();
24
25 // the output histograms/graphs will be stored in the folder "folderDEdx"
26 compObj->GetAnalysisFolder()->ls("*");
27
28 // user can save whole comparison object (or only folder with anlysed histograms)
29 // in the seperate output file (e.g.)
30 TFile fout("Analysed_DEdx.root"."recreate");
31 compObj->Write(); // compObj->GetAnalysisFolder()->Write();
32 fout.Close();
33
34*/
35
36#include <TDirectory.h>
37#include <TAxis.h>
38#include <TCanvas.h>
39#include <TH1.h>
40#include <TH2.h>
41#include <TF1.h>
42
43#include "AliPerformanceDEdx.h"
44#include "AliESDEvent.h"
45#include "AliMCEvent.h"
46#include "AliESDtrack.h"
47#include "AliStack.h"
48#include "AliLog.h"
49#include "AliMCInfoCuts.h"
50#include "AliMathBase.h"
51#include "AliRecInfoCuts.h"
52#include "AliTreeDraw.h"
53#include "AliHeader.h"
54#include "AliGenEventHeader.h"
55
56using namespace std;
57
58ClassImp(AliPerformanceDEdx)
59
60//_____________________________________________________________________________
61AliPerformanceDEdx::AliPerformanceDEdx():
62 AliPerformanceObject("AliPerformanceDEdx"),
63
64 // dEdx
65 fDeDxHisto(0),
66
67 // Cuts
68 fCutsRC(0),
69 fCutsMC(0),
70
71 // histogram folder
72 fAnalysisFolder(0)
73{
74 // default constructor
75 Init();
76}
77
78//_____________________________________________________________________________
79AliPerformanceDEdx::AliPerformanceDEdx(Char_t* name="AliPerformanceDEdx", Char_t* title="AliPerformanceDEdx",Int_t analysisMode=0, Bool_t hptGenerator=kFALSE):
80 AliPerformanceObject(name,title),
81
82 // dEdx
83 fDeDxHisto(0),
84
85 // Cuts
86 fCutsRC(0),
87 fCutsMC(0),
88
89 // histogram folder
90 fAnalysisFolder(0)
91{
92 // named constructor
93
94 SetAnalysisMode(analysisMode);
95 SetHptGenerator(hptGenerator);
96 Init();
97}
98
99
100//_____________________________________________________________________________
101AliPerformanceDEdx::~AliPerformanceDEdx()
102{
103 // destructor
104 if(fDeDxHisto) delete fDeDxHisto; fDeDxHisto=0;
105 if(fAnalysisFolder) delete fAnalysisFolder; fAnalysisFolder=0;
106}
107
108//_____________________________________________________________________________
109void AliPerformanceDEdx::Init()
110{
111 // Init histograms
112
113 // TPC dEdx
114 // set pt bins
115 Int_t nPBins = 50;
116 Double_t pMin = 1.e-2, pMax = 10.;
117
118 Double_t *binsP = 0;
119 if (IsHptGenerator()) {
120 nPBins = 100; pMax = 100.;
121 binsP = CreateLogAxis(nPBins,pMin,pMax);
122 } else {
123 binsP = CreateLogAxis(nPBins,pMin,pMax);
124 }
125
126
127 /*
128 Int_t nPBins = 31;
129 Double_t binsP[32] = {0.,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.7,0.8,0.9,1.0,1.2,1.4,1.6,1.8,2.0,2.25,2.5,2.75,3.,3.5,4.,5.,6.,8.,10.};
130 Double_t pMin = 0., pMax = 10.;
131
132 if(IsHptGenerator() == kTRUE) {
133 nPBins = 100;
134 pMin = 0.; pMax = 100.;
135 }
136 */
137
138 //dedx:alpha:y:z:snp:tgl:ncls:p
139 //dedx:phi:y:z:snp:tgl:ncls:p
140 //Int_t binsQA[8] = {300, 50, 50, 50, 50, 50, 80, nPBins};
141 //Double_t xminQA[8] = {0, -4,-20,-250, -1, -2, 0, pMin};
142 //Double_t xmaxQA[8] = {300, 4, 20, 250, 1, 2, 160, pMax};
143 Int_t binsQA[8] = {300, 144, 50, 50, 50, 50, 80, nPBins};
144 Double_t xminQA[8] = {0, -TMath::Pi(),-20,-250, -1, -2, 0, pMin};
145 Double_t xmaxQA[8] = {300, TMath::Pi(), 20, 250, 1, 2, 160, pMax};
146
147 //fDeDxHisto = new THnSparseF("fDeDxHisto","dedx:alpha:y:z:snp:tgl:ncls:momentum",8,binsQA,xminQA,xmaxQA);
148 fDeDxHisto = new THnSparseF("fDeDxHisto","dedx:phi:y:z:snp:tgl:ncls:momentum",8,binsQA,xminQA,xmaxQA);
149 fDeDxHisto->SetBinEdges(7,binsP);
150
151 fDeDxHisto->GetAxis(0)->SetTitle("dedx (a.u.)");
152 fDeDxHisto->GetAxis(1)->SetTitle("#phi (rad)");
153 fDeDxHisto->GetAxis(2)->SetTitle("y (cm)");
154 fDeDxHisto->GetAxis(3)->SetTitle("z (cm)");
155 fDeDxHisto->GetAxis(4)->SetTitle("snp");
156 fDeDxHisto->GetAxis(5)->SetTitle("tgl");
157 fDeDxHisto->GetAxis(6)->SetTitle("ncls");
158 fDeDxHisto->GetAxis(7)->SetTitle("p (GeV/c)");
159 fDeDxHisto->Sumw2();
160
161 // Init cuts
162 if(!fCutsMC)
163 AliDebug(AliLog::kError, "ERROR: Cannot find AliMCInfoCuts object");
164 if(!fCutsRC)
165 AliDebug(AliLog::kError, "ERROR: Cannot find AliRecInfoCuts object");
166
167 // init folder
168 fAnalysisFolder = CreateFolder("folderDEdx","Analysis de/dx Folder");
169}
170
171//_____________________________________________________________________________
172void AliPerformanceDEdx::ProcessTPC(AliStack* const stack, AliESDtrack *const esdTrack)
173{
174 if(!esdTrack) return;
175
176 const AliExternalTrackParam *innerParam = esdTrack->GetInnerParam();
177 if(!innerParam) return;
178
179 Float_t dca[2], cov[3]; // dca_xy, dca_z, sigma_xy, sigma_xy_z, sigma_z
180 esdTrack->GetImpactParametersTPC(dca,cov);
181
182 if((esdTrack->GetStatus()&AliESDtrack::kTPCrefit)==0) return; // TPC refit
183 if(TMath::Abs(dca[0])<fCutsRC->GetMaxDCAToVertexXY() && TMath::Abs(dca[1])<fCutsRC->GetMaxDCAToVertexZ())
184 {
185 Float_t dedx = esdTrack->GetTPCsignal();
186 Int_t ncls = esdTrack->GetTPCNcls();
187
188 Double_t pt = innerParam->Pt();
189 Double_t lam = TMath::ATan2(innerParam->Pz(),innerParam->Pt());
190 Double_t p = pt/TMath::Cos(lam);
191 //Double_t alpha = innerParam->GetAlpha();
192 Double_t phi = TMath::ATan2(innerParam->Py(),innerParam->Px());
193 //if(phi<0.) phi += 2.*TMath::Phi();
194 Double_t y = innerParam->GetY();
195 Double_t z = innerParam->GetZ();
196 Double_t snp = innerParam->GetSnp();
197 Double_t tgl = innerParam->GetTgl();
198
199 //Double_t vDeDxHisto[8] = {dedx,alpha,y,z,snp,tgl,ncls,p};
200 Double_t vDeDxHisto[8] = {dedx,phi,y,z,snp,tgl,ncls,p};
201 fDeDxHisto->Fill(vDeDxHisto);
202 }
203
204 if(!stack) return;
205}
206
207//_____________________________________________________________________________
208void AliPerformanceDEdx::ProcessTPCITS(AliStack* const /*stack*/, AliESDtrack *const /*esdTrack*/)
209{
210 // Fill dE/dx comparison information
211
212 AliDebug(AliLog::kWarning, "Warning: Not implemented");
213}
214
215//_____________________________________________________________________________
216void AliPerformanceDEdx::ProcessConstrained(AliStack* const /*stack*/, AliESDtrack *const /*esdTrack*/)
217{
218 // Fill dE/dx comparison information
219
220 AliDebug(AliLog::kWarning, "Warning: Not implemented");
221}
222
223//_____________________________________________________________________________
224Long64_t AliPerformanceDEdx::Merge(TCollection* const list)
225{
226 // Merge list of objects (needed by PROOF)
227
228 if (!list)
229 return 0;
230
231 if (list->IsEmpty())
232 return 1;
233
234 TIterator* iter = list->MakeIterator();
235 TObject* obj = 0;
236
237 // collection of generated histograms
238 Int_t count=0;
239 while((obj = iter->Next()) != 0)
240 {
241 AliPerformanceDEdx* entry = dynamic_cast<AliPerformanceDEdx*>(obj);
242 if (entry == 0) continue;
243
244 fDeDxHisto->Add(entry->fDeDxHisto);
245 count++;
246 }
247
248return count;
249}
250
251//_____________________________________________________________________________
252void AliPerformanceDEdx::Exec(AliMCEvent* const mcEvent, AliESDEvent* const esdEvent, const Bool_t bUseMC)
253{
254 // Process comparison information
255 //
256 if(!esdEvent)
257 {
258 AliDebug(AliLog::kError, "esdEvent not available");
259 return;
260 }
261 AliHeader* header = 0;
262 AliGenEventHeader* genHeader = 0;
263 AliStack* stack = 0;
264 TArrayF vtxMC(3);
265
266 if(bUseMC)
267 {
268 if(!mcEvent) {
269 AliDebug(AliLog::kError, "mcEvent not available");
270 return;
271 }
272
273 // get MC event header
274 header = mcEvent->Header();
275 if (!header) {
276 AliDebug(AliLog::kError, "Header not available");
277 return;
278 }
279 // MC particle stack
280 stack = mcEvent->Stack();
281 if (!stack) {
282 AliDebug(AliLog::kError, "Stack not available");
283 return;
284 }
285
286 // get MC vertex
287 genHeader = header->GenEventHeader();
288 if (!genHeader) {
289 AliDebug(AliLog::kError, "Could not retrieve genHeader from Header");
290 return;
291 }
292 genHeader->PrimaryVertex(vtxMC);
293
294 } // end bUseMC
295
296 // Process events
297 for (Int_t iTrack = 0; iTrack < esdEvent->GetNumberOfTracks(); iTrack++)
298 {
299 AliESDtrack *track = esdEvent->GetTrack(iTrack);
300 if(!track) continue;
301
302 if(GetAnalysisMode() == 0) ProcessTPC(stack,track);
303 else if(GetAnalysisMode() == 1) ProcessTPCITS(stack,track);
304 else if(GetAnalysisMode() == 2) ProcessConstrained(stack,track);
305 else {
306 printf("ERROR: AnalysisMode %d \n",fAnalysisMode);
307 return;
308 }
309 }
310}
311
312//_____________________________________________________________________________
313void AliPerformanceDEdx::Analyse()
314{
315 // Analyze comparison information and store output histograms
316 // in the folder "folderDEdx"
317 //
318 TH1::AddDirectory(kFALSE);
319 TH1F *h1D=0;
320 TH2F *h2D=0;
321 TObjArray *aFolderObj = new TObjArray;
322
323 char name[256];
324 char title[256];
325
326 for(Int_t i=1; i<8; i++) {
327 //
328 h2D = (TH2F*)fDeDxHisto->Projection(0,i);
329
330 sprintf(name,"h_dedx_%d_vs_%d",0,i);
331 h2D->SetName(name);
332 sprintf(title,"%s vs %s",fDeDxHisto->GetAxis(0)->GetTitle(),fDeDxHisto->GetAxis(i)->GetTitle());
333 h2D->SetTitle(title);
334 h2D->GetXaxis()->SetTitle(fDeDxHisto->GetAxis(i)->GetTitle());
335 h2D->GetYaxis()->SetTitle(fDeDxHisto->GetAxis(0)->GetTitle());
336
337 if(i==7) h2D->SetBit(TH1::kLogX);
338 aFolderObj->Add(h2D);
339 }
340
341 // resolution histograms for mips
342 fDeDxHisto->GetAxis(2)->SetRangeUser(-15.,14.999);
343 fDeDxHisto->GetAxis(3)->SetRangeUser(-120.,119.999);
344 fDeDxHisto->GetAxis(4)->SetRangeUser(-0.4, 0.399);
345 fDeDxHisto->GetAxis(5)->SetRangeUser(-1.,0.999);
346 fDeDxHisto->GetAxis(6)->SetRangeUser(60.,140.);
347 fDeDxHisto->GetAxis(7)->SetRangeUser(0.4,0.499);
348
349 h1D=(TH1F*)fDeDxHisto->Projection(0);
350 h1D->SetName("dedx_mips");
351
352 h1D->SetTitle("dedx_mips");
353 h1D->GetXaxis()->SetTitle(fDeDxHisto->GetAxis(0)->GetTitle());
354 aFolderObj->Add(h1D);
355
356 //
357 TObjArray *arr[7] = {0};
358 TF1 *f1[7] = {0};
359
360 for(Int_t i=1; i<8; i++)
361 {
362 arr[i] = new TObjArray;
363 f1[i] = new TF1("gaus","gaus");
364 //printf("i %d \n",i);
365
366 h2D = (TH2F*)fDeDxHisto->Projection(0,i);
367
368 f1[i]->SetRange(40,60); // should be pion peak
369 h2D->FitSlicesY(f1[i],0,-1,10,"QNR",arr[i]); // gaus fit of pion peak
370
371 h1D = (TH1F*)arr[i]->At(1);
372 sprintf(name,"mean_dedx_mips_vs_%d",i);
373 h1D->SetName(name);
374 sprintf(title,"%s vs %s","mean_dedx_mips (a.u.)",fDeDxHisto->GetAxis(i)->GetTitle());
375 h1D->SetTitle(title);
376 h1D->GetXaxis()->SetTitle(fDeDxHisto->GetAxis(i)->GetTitle());
377 h1D->GetYaxis()->SetTitle("mean_dedx_mips (a.u.)");
378 //h1D->SetMinimum(40);
379 //h1D->SetMaximum(60);
380
381 aFolderObj->Add(h1D);
382
383 h1D = (TH1F*)arr[i]->At(2);
384 sprintf(name,"res_dedx_mips_vs_%d",i);
385 h1D->SetName(name);
386 sprintf(title,"%s vs %s","res_dedx_mips (a.u)",fDeDxHisto->GetAxis(i)->GetTitle());
387 h1D->SetTitle(title);
388 h1D->GetXaxis()->SetTitle(fDeDxHisto->GetAxis(i)->GetTitle());
389 h1D->GetYaxis()->SetTitle("res_dedx_mips (a.u.)");
390 //h1D->SetMinimum(0);
391 //h1D->SetMaximum(6);
392
393 aFolderObj->Add(h1D);
394 }
395
396 // export objects to analysis folder
397 fAnalysisFolder = ExportToFolder(aFolderObj);
398
399 // delete only TObjrArray
400 if(aFolderObj) delete aFolderObj;
401}
402
403//_____________________________________________________________________________
404TFolder* AliPerformanceDEdx::ExportToFolder(TObjArray * array)
405{
406 // recreate folder avery time and export objects to new one
407 //
408 AliPerformanceDEdx * comp=this;
409 TFolder *folder = comp->GetAnalysisFolder();
410
411 TString name, title;
412 TFolder *newFolder = 0;
413 Int_t i = 0;
414 Int_t size = array->GetSize();
415
416 if(folder) {
417 // get name and title from old folder
418 name = folder->GetName();
419 title = folder->GetTitle();
420
421 // delete old one
422 delete folder;
423
424 // create new one
425 newFolder = CreateFolder(name.Data(),title.Data());
426 newFolder->SetOwner();
427
428 // add objects to folder
429 while(i < size) {
430 newFolder->Add(array->At(i));
431 i++;
432 }
433 }
434
435return newFolder;
436}
437
438
439//_____________________________________________________________________________
440TFolder* AliPerformanceDEdx::CreateFolder(TString name,TString title) {
441// create folder for analysed histograms
442TFolder *folder = 0;
443 folder = new TFolder(name.Data(),title.Data());
444
445 return folder;
446}
447