]>
Commit | Line | Data |
---|---|---|
c04c80e6 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | // | |
16 | // QA class for TRD PID | |
17 | // Plot Pion Efficiency at x electron efficiency | |
18 | // Calculate the threshold parametrisation and save | |
19 | // them in a root file | |
20 | // | |
21 | // Author: | |
22 | // Markus Fasel <M.Fasel@gsi.de> | |
23 | // | |
24 | #include <TAxis.h> | |
bf892a6a | 25 | #include <TBrowser.h> |
c04c80e6 | 26 | #include <TClass.h> |
27 | #include <TCanvas.h> | |
28 | #include <TF1.h> | |
29 | #include <TFile.h> | |
30 | #include <TGraph.h> | |
31 | #include <TGraphErrors.h> | |
32 | #include <THnSparse.h> | |
33 | #include <TH1.h> | |
34 | #include <TH2.h> | |
35 | #include <TIterator.h> | |
36 | #include <TLegend.h> | |
37 | #include <TList.h> | |
38 | #include <TMath.h> | |
39 | #include <TObjArray.h> | |
40 | #include <TString.h> | |
41 | ||
42 | #include "AliAODTrack.h" | |
43 | #include "AliAODPid.h" | |
44 | #include "AliESDtrack.h" | |
45 | #include "AliHFEtrdPIDqa.h" | |
46 | #include "AliHFEtools.h" | |
47 | #include "AliHFEpidTRD.h" | |
48 | #include "AliLog.h" | |
49 | ||
50 | ClassImp(AliHFEtrdPIDqa) | |
51 | ||
52 | const Double_t AliHFEtrdPIDqa::fgkElectronEff[kNElectronEffs] = {0.7,0.75, 0.8, 0.85, 0.9, 0.95}; | |
53 | //_______________________________________________________________ | |
54 | // Definition of the common binning | |
55 | const Int_t AliHFEtrdPIDqa::fgkNBinsCommon[kQuantitiesCommon] = { | |
56 | AliPID::kSPECIES + 1, // species | |
57 | 40, // p-bins | |
58 | AliESDtrack::kTRDnPlanes + 1 // tracklets including 0 | |
59 | }; | |
60 | const Double_t AliHFEtrdPIDqa::fgkMinBinCommon[kQuantitiesCommon] = { | |
61 | -1, // species | |
8c1c76e9 | 62 | 0.1, // p-bins: |
c04c80e6 | 63 | 0 // tracklets including 0 |
64 | }; | |
65 | ||
66 | const Double_t AliHFEtrdPIDqa::fgkMaxBinCommon[kQuantitiesCommon] = { | |
67 | AliPID::kSPECIES, // species | |
68 | 10., // p-bins | |
69 | AliESDtrack::kTRDnPlanes + 1 // tracklets including 0 | |
70 | }; | |
71 | //_______________________________________________________________ | |
72 | ||
73 | //__________________________________________________________________ | |
74 | AliHFEtrdPIDqa::AliHFEtrdPIDqa(): | |
75 | TNamed("trdPIDqa", ""), | |
76 | fTRDpid(NULL), | |
bf892a6a | 77 | fHistos(NULL), |
c04c80e6 | 78 | fPionEfficiencies(NULL), |
79 | fProtonEfficiencies(NULL), | |
80 | fKaonEfficiencies(NULL), | |
e3ae862b | 81 | fThresholds(NULL), |
e156c3bb | 82 | fShowMessage(kFALSE), |
e17c1f86 | 83 | fTotalChargeInSlice0(kFALSE), |
84 | fCentralityBin(-1) | |
c04c80e6 | 85 | { |
86 | // | |
87 | // Default Constructor | |
88 | // | |
89 | } | |
90 | ||
91 | //__________________________________________________________________ | |
92 | AliHFEtrdPIDqa::AliHFEtrdPIDqa(const Char_t *name): | |
93 | TNamed(name, ""), | |
94 | fTRDpid(NULL), | |
bf892a6a | 95 | fHistos(NULL), |
c04c80e6 | 96 | fPionEfficiencies(NULL), |
97 | fProtonEfficiencies(NULL), | |
98 | fKaonEfficiencies(NULL), | |
e3ae862b | 99 | fThresholds(NULL), |
e156c3bb | 100 | fShowMessage(kFALSE), |
e17c1f86 | 101 | fTotalChargeInSlice0(kFALSE), |
102 | fCentralityBin(-1) | |
c04c80e6 | 103 | { |
104 | // | |
105 | // Main Constructor | |
106 | // | |
107 | } | |
108 | ||
109 | //__________________________________________________________________ | |
110 | AliHFEtrdPIDqa::AliHFEtrdPIDqa(const AliHFEtrdPIDqa &ref): | |
111 | TNamed(ref), | |
112 | fTRDpid(NULL), | |
bf892a6a | 113 | fHistos(NULL), |
c04c80e6 | 114 | fPionEfficiencies(NULL), |
115 | fProtonEfficiencies(NULL), | |
116 | fKaonEfficiencies(NULL), | |
e3ae862b | 117 | fThresholds(NULL), |
e156c3bb | 118 | fShowMessage(kFALSE), |
e17c1f86 | 119 | fTotalChargeInSlice0(ref.fTotalChargeInSlice0), |
120 | fCentralityBin(ref.fCentralityBin) | |
c04c80e6 | 121 | { |
122 | // | |
123 | // Copy constructor | |
124 | // | |
125 | ref.Copy(*this); | |
126 | } | |
127 | ||
128 | //__________________________________________________________________ | |
129 | AliHFEtrdPIDqa &AliHFEtrdPIDqa::operator=(const AliHFEtrdPIDqa &ref){ | |
130 | // | |
131 | // Assignment operator | |
132 | // | |
133 | if(this != &ref) | |
134 | ref.Copy(*this); | |
135 | return *this; | |
136 | } | |
137 | ||
138 | //__________________________________________________________________ | |
139 | AliHFEtrdPIDqa::~AliHFEtrdPIDqa(){ | |
140 | // | |
141 | // Destructor | |
142 | // | |
143 | if(fTRDpid) delete fTRDpid; | |
bf892a6a | 144 | if(fHistos) delete fHistos; |
c04c80e6 | 145 | if(fPionEfficiencies) delete fPionEfficiencies; |
146 | if(fProtonEfficiencies) delete fProtonEfficiencies; | |
147 | if(fKaonEfficiencies) delete fKaonEfficiencies; | |
148 | } | |
149 | ||
150 | //__________________________________________________________________ | |
151 | void AliHFEtrdPIDqa::Copy(TObject &ref) const{ | |
152 | // | |
153 | // Copies content of this object into object ref | |
154 | // | |
155 | TNamed::Copy(ref); | |
156 | ||
157 | AliHFEtrdPIDqa &target = dynamic_cast<AliHFEtrdPIDqa &>(ref); | |
158 | target.fTRDpid = fTRDpid; | |
e156c3bb | 159 | target.fHistos = dynamic_cast<AliHFEcollection *>(fHistos->Clone()); |
160 | target.fTotalChargeInSlice0 = fTotalChargeInSlice0; | |
e17c1f86 | 161 | target.fCentralityBin = fCentralityBin; |
c04c80e6 | 162 | } |
163 | ||
164 | //__________________________________________________________________ | |
165 | Long64_t AliHFEtrdPIDqa::Merge(TCollection *coll){ | |
166 | // | |
167 | // Merge objects | |
168 | // | |
169 | if(!coll) return 0; | |
170 | if(coll->IsEmpty()) return 1; | |
171 | ||
bf892a6a | 172 | AliHFEtrdPIDqa *refQA = NULL; |
173 | TIter it(coll); | |
c04c80e6 | 174 | TObject *o = NULL; |
175 | Long64_t count = 0; | |
bf892a6a | 176 | TList listHistos; |
177 | while((o = it())){ | |
178 | refQA = dynamic_cast<AliHFEtrdPIDqa *>(o); | |
c04c80e6 | 179 | if(!refQA) continue; |
180 | ||
bf892a6a | 181 | listHistos.Add(refQA->fHistos); |
182 | count++; | |
c04c80e6 | 183 | } |
bf892a6a | 184 | fHistos->Merge(&listHistos); |
c04c80e6 | 185 | return count+1; |
186 | } | |
187 | ||
bf892a6a | 188 | //__________________________________________________________________ |
189 | void AliHFEtrdPIDqa::Browse(TBrowser *b){ | |
190 | // | |
191 | // Enable Browser functionality | |
192 | // | |
193 | if(b){ | |
194 | // Add objects to the browser | |
195 | if(fHistos) b->Add(fHistos, fHistos->GetName()); | |
196 | if(fPionEfficiencies) b->Add(fPionEfficiencies, "Pion Efficiencies"); | |
197 | if(fProtonEfficiencies) b->Add(fProtonEfficiencies, "Proton Efficiencies"); | |
198 | if(fKaonEfficiencies) b->Add(fKaonEfficiencies, "Kaon Efficiencies"); | |
199 | if(fThresholds) b->Add(fThresholds, "Thresholds"); | |
200 | } | |
201 | } | |
202 | ||
c04c80e6 | 203 | //__________________________________________________________________ |
204 | void AliHFEtrdPIDqa::Init(){ | |
205 | // | |
206 | // Initialize Object | |
207 | // | |
bf892a6a | 208 | |
209 | fHistos = new AliHFEcollection("TRDqa", "Histos for TRD QA"); | |
c04c80e6 | 210 | |
211 | CreateLikelihoodHistogram(); | |
212 | CreateQAHistogram(); | |
213 | CreatedEdxHistogram(); | |
214 | CreateHistoTruncatedMean(); | |
215 | ||
216 | fTRDpid = new AliHFEpidTRD("QAtrdPID"); | |
217 | } | |
218 | ||
219 | //__________________________________________________________________ | |
220 | void AliHFEtrdPIDqa::CreateLikelihoodHistogram(){ | |
221 | // | |
222 | // Create Histogram for TRD Likelihood Studies | |
223 | // | |
224 | Int_t nbins[kQuantitiesLike]; memcpy(nbins, fgkNBinsCommon, sizeof(Int_t) * kQuantitiesCommon); | |
225 | nbins[kElectronLike] = 100; | |
8c1c76e9 | 226 | nbins[kNClustersLike] = 200; |
e17c1f86 | 227 | nbins[kCentralityBin] = 12; |
c04c80e6 | 228 | Double_t binMin[kQuantitiesLike]; memcpy(binMin, fgkMinBinCommon, sizeof(Double_t) * kQuantitiesCommon); |
229 | Double_t binMax[kQuantitiesLike]; memcpy(binMax, fgkMaxBinCommon, sizeof(Double_t) * kQuantitiesCommon); | |
230 | binMin[kElectronLike] = 0.; | |
8c1c76e9 | 231 | binMin[kNClustersLike] = 0.; |
e17c1f86 | 232 | binMin[kCentralityBin] = -1.; |
c04c80e6 | 233 | binMax[kElectronLike] = 1.; |
8c1c76e9 | 234 | binMax[kNClustersLike] = 200.; |
e17c1f86 | 235 | binMax[kCentralityBin] = 11.; |
c04c80e6 | 236 | |
bf892a6a | 237 | fHistos->CreateTHnSparse("fLikeTRD","TRD Likelihood Studies", kQuantitiesLike, nbins, binMin, binMax); |
238 | fHistos->BinLogAxis("fLikeTRD", kP); | |
c04c80e6 | 239 | } |
240 | ||
241 | //__________________________________________________________________ | |
242 | void AliHFEtrdPIDqa::CreateQAHistogram(){ | |
243 | // | |
244 | // Create Histogram for Basic TRD PID QA | |
245 | // | |
246 | AliDebug(1, "Called"); | |
247 | Int_t nbins[kQuantitiesQA]; memcpy(nbins, fgkNBinsCommon, sizeof(Int_t) * kQuantitiesCommon); | |
248 | nbins[kNonZeroTrackletCharge] = AliESDtrack::kTRDnPlanes + 1; | |
249 | nbins[kNClusters] = 200; | |
250 | Double_t binMin[kQuantitiesQA]; memcpy(binMin, fgkMinBinCommon, sizeof(Double_t) * kQuantitiesCommon); | |
251 | binMin[kNonZeroTrackletCharge] = 0.; | |
252 | binMin[kNClusters] = 0.; | |
253 | Double_t binMax[kQuantitiesQA]; memcpy(binMax, fgkMaxBinCommon, sizeof(Double_t) * kQuantitiesCommon); | |
254 | binMax[kNonZeroTrackletCharge] = AliESDtrack::kTRDnPlanes + 1.; | |
255 | binMax[kNClusters] = 200.; | |
256 | ||
bf892a6a | 257 | fHistos->CreateTHnSparse("fQAtrack","TRD QA Histogram", kQuantitiesQA, nbins, binMin, binMax); |
258 | fHistos->BinLogAxis("fQAtrack", kP); | |
c04c80e6 | 259 | } |
260 | ||
261 | //__________________________________________________________________ | |
262 | void AliHFEtrdPIDqa::CreatedEdxHistogram(){ | |
263 | // | |
264 | // Create QA histogram for dEdx investigations | |
265 | // | |
266 | AliDebug(1, "Called"); | |
267 | Int_t nbins[kQuantitiesdEdx]; memcpy(nbins, fgkNBinsCommon, sizeof(Int_t) * kQuantitiesCommon); | |
268 | nbins[kdEdx] = 100; | |
3a72645a | 269 | nbins[kNclusters] = 261; |
270 | nbins[kNonZeroSlices] = 9; | |
c04c80e6 | 271 | Double_t binMin[kQuantitiesdEdx]; memcpy(binMin, fgkMinBinCommon, sizeof(Double_t) * kQuantitiesCommon); |
3a72645a | 272 | binMin[kdEdx] = 0.; |
273 | binMin[kNclusters] = 0; | |
6555e2ad | 274 | binMin[kNonZeroSlices] = 0.; |
c04c80e6 | 275 | Double_t binMax[kQuantitiesdEdx]; memcpy(binMax, fgkMaxBinCommon, sizeof(Double_t) * kQuantitiesCommon); |
8c1c76e9 | 276 | binMax[kdEdx] = 10000.; |
3a72645a | 277 | binMax[kNclusters] = 260.; |
278 | binMax[kNonZeroSlices] = 8.; | |
c04c80e6 | 279 | |
bf892a6a | 280 | fHistos->CreateTHnSparse("fQAdEdx","TRD summed dEdx", kQuantitiesdEdx, nbins, binMin, binMax); |
281 | fHistos->BinLogAxis("fQAdEdx", kP); | |
282 | fHistos->Sumw2("fQAdEdx"); | |
c04c80e6 | 283 | } |
284 | ||
285 | //__________________________________________________________________ | |
286 | void AliHFEtrdPIDqa::CreateHistoTruncatedMean(){ | |
287 | // | |
8c1c76e9 | 288 | // Create Histogram for Basic TRD PID QA: |
c04c80e6 | 289 | // |
290 | AliDebug(1, "Called"); | |
291 | Int_t nbins[kQuantitiesTruncMean]; memcpy(nbins, fgkNBinsCommon, sizeof(Int_t) * kQuantitiesCommon); | |
292 | nbins[kTPCdEdx] = 600; | |
293 | nbins[kTRDdEdxMethod1] = 1000; | |
294 | nbins[kTRDdEdxMethod2] = 1000; | |
295 | Double_t binMin[kQuantitiesTruncMean]; memcpy(binMin, fgkMinBinCommon, sizeof(Double_t) * kQuantitiesCommon); | |
296 | binMin[kTPCdEdx] = 0.; | |
297 | binMin[kTRDdEdxMethod1] = 0.; | |
298 | binMin[kTRDdEdxMethod2] = 0.; | |
299 | Double_t binMax[kQuantitiesTruncMean]; memcpy(binMax, fgkMaxBinCommon, sizeof(Double_t) * kQuantitiesCommon); | |
300 | binMax[kTPCdEdx] = 600; | |
301 | binMax[kTRDdEdxMethod1] = 20000.; | |
302 | binMax[kTRDdEdxMethod2] = 20000.; | |
303 | ||
bf892a6a | 304 | fHistos->CreateTHnSparse("fTRDtruncMean","TRD TruncatedMean studies", kQuantitiesTruncMean, nbins, binMin, binMax); |
305 | fHistos->BinLogAxis("fTRDtruncMean", kP); | |
e156c3bb | 306 | fHistos->CreateTH2F("fTRDslicesPions","TRD dEdx per slice for Pions", 8, 0, 8, 2000, 0, 8000); |
307 | fHistos->CreateTH2F("fTRDslicesElectrons","TRD dEdx per slice for Electrons", 8, 0, 8, 2000, 0, 8000); | |
c04c80e6 | 308 | } |
309 | ||
310 | ||
311 | //__________________________________________________________________ | |
c2690925 | 312 | void AliHFEtrdPIDqa::ProcessTracks(const TObjArray * const tracks, Int_t species){ |
c04c80e6 | 313 | // |
314 | // Process Electron Tracks | |
315 | // | |
316 | if(species < -1 || species >= AliPID::kSPECIES) return; | |
c2690925 | 317 | TIter it(tracks); |
318 | const AliVTrack *track = NULL; | |
319 | while((track = dynamic_cast<const AliVTrack *>(it()))){ | |
c04c80e6 | 320 | if(track) ProcessTrack(track, species); |
321 | } | |
c04c80e6 | 322 | } |
323 | ||
324 | //__________________________________________________________________ | |
c2690925 | 325 | void AliHFEtrdPIDqa::ProcessTrack(const AliVTrack * const track, Int_t species){ |
c04c80e6 | 326 | // |
327 | // Process Single Track | |
328 | // | |
329 | if(TString(track->IsA()->GetName()).CompareTo("AliESDtrack") == 0) | |
c2690925 | 330 | ProcessTrackESD(dynamic_cast<const AliESDtrack *>(track), species); |
c04c80e6 | 331 | else if(TString(track->IsA()->GetName()).CompareTo("AliAODTrack") == 0) |
c2690925 | 332 | ProcessTrackAOD(dynamic_cast<const AliAODTrack *>(track), species); |
c04c80e6 | 333 | } |
334 | ||
335 | ||
336 | //__________________________________________________________________ | |
c2690925 | 337 | void AliHFEtrdPIDqa::ProcessTrackESD(const AliESDtrack *track, Int_t species){ |
c04c80e6 | 338 | // |
339 | // Process single ESD track | |
340 | // | |
bf892a6a | 341 | if(!track) return; |
c04c80e6 | 342 | if((track->GetStatus() & AliESDtrack::kTRDout) == 0) return; // require TRD track |
343 | FillTRDLikelihoods(track, species); | |
344 | FillTRDQAplots(track, species); | |
345 | } | |
346 | ||
347 | //__________________________________________________________________ | |
c2690925 | 348 | void AliHFEtrdPIDqa::ProcessTrackAOD(const AliAODTrack * const track, Int_t /*species*/){ |
c04c80e6 | 349 | // |
350 | // Process single AOD track | |
351 | // AOD PID object required | |
352 | // | |
bf892a6a | 353 | if(!track) return; |
c04c80e6 | 354 | AliAODPid *trackPID = track->GetDetPid(); |
355 | if(!trackPID) return; | |
356 | ||
357 | } | |
358 | ||
359 | //__________________________________________________________________ | |
c2690925 | 360 | void AliHFEtrdPIDqa::FillTRDLikelihoods(const AliESDtrack * const track, Int_t species){ |
c04c80e6 | 361 | // |
362 | // Fill TRD Likelihood Histogram | |
363 | // | |
364 | Double_t trdLike[AliPID::kSPECIES]; | |
365 | track->GetTRDpid(trdLike); | |
c2690925 | 366 | // Renormalize |
367 | Double_t norm =trdLike[AliPID::kElectron]+trdLike[AliPID::kPion]; | |
368 | Double_t likeEle = norm == 0. ? 0. : trdLike[AliPID::kElectron]/norm; | |
c04c80e6 | 369 | const AliExternalTrackParam *outerPars = track->GetOuterParam(); |
370 | ||
e17c1f86 | 371 | //Int_t kQuantitiesLike; |
c04c80e6 | 372 | Double_t quantities[kQuantitiesLike]; memset(quantities, 0, sizeof(Double_t) * kQuantitiesLike); |
373 | // we store: | |
374 | // species | |
375 | // p | |
376 | // ntracklets | |
377 | // Electron Likelihood | |
378 | quantities[kSpecies] = species; | |
379 | quantities[kP] = outerPars ? outerPars->P() : track->P(); | |
380 | quantities[kNTracklets] = track->GetTRDntrackletsPID(); | |
c2690925 | 381 | quantities[kElectronLike] = likeEle; |
8c1c76e9 | 382 | quantities[kNClustersLike] = track->GetTRDncls(); |
e17c1f86 | 383 | quantities[kCentralityBin] = fCentralityBin; |
bf892a6a | 384 | fHistos->Fill("fLikeTRD", quantities); |
e17c1f86 | 385 | |
c04c80e6 | 386 | } |
387 | ||
388 | //__________________________________________________________________ | |
c2690925 | 389 | void AliHFEtrdPIDqa::FillTRDQAplots(const AliESDtrack * const track, Int_t species){ |
c04c80e6 | 390 | // |
391 | // Fill QA Plots containing further information | |
392 | // | |
393 | const AliExternalTrackParam *outerPars = track->GetOuterParam(); | |
394 | ||
395 | Double_t quantitiesQA[kQuantitiesQA], quantitiesdEdx[kQuantitiesdEdx], quantitiesTruncMean[kQuantitiesTruncMean]; | |
396 | // we store: | |
397 | // 1. QA | |
398 | // species | |
399 | // p | |
400 | // ntracklets | |
401 | // Non-zero tracklet charges | |
402 | // Number of clusters / full track | |
403 | // 2. dEdx | |
404 | // species | |
405 | // p | |
406 | // ntracklets | |
407 | // dEdx | |
408 | // 3. Truncated Mean | |
409 | // ... | |
410 | // TPC dEdx | |
411 | // TRD dEdx Method 1 | |
412 | // TRD dEdx Method 2 | |
413 | quantitiesQA[kSpecies] = quantitiesdEdx[kSpecies] | |
414 | = quantitiesTruncMean[kSpecies] | |
415 | = species; | |
bf892a6a | 416 | quantitiesQA[kP] = quantitiesTruncMean[kP] |
c04c80e6 | 417 | = outerPars ? outerPars->P() : track->P(); |
418 | quantitiesQA[kNTracklets] = quantitiesdEdx[kNTracklets] | |
419 | = quantitiesTruncMean[kNTracklets] | |
420 | = track->GetTRDntrackletsPID(); | |
3a72645a | 421 | quantitiesQA[kNClusters] = quantitiesdEdx[kNclusters] = track->GetTRDncls(); |
422 | ||
c04c80e6 | 423 | |
3a72645a | 424 | Double_t dEdxSum = 0., qSlice = 0.; |
425 | // remove the last slice from the histogram | |
bf892a6a | 426 | Int_t ntrackletsNonZero = 0, nSlices = track->GetNumberOfTRDslices(), nSlicesNonZero = 0; |
427 | TString speciesname = "pions"; | |
428 | Bool_t selectedForSlicemon = kFALSE; | |
429 | ||
430 | switch(species){ | |
431 | case AliPID::kElectron: speciesname = "Electrons"; selectedForSlicemon = kTRUE; break; | |
432 | case AliPID::kPion: speciesname = "Pions"; selectedForSlicemon = kTRUE; break; | |
433 | default: speciesname = "undefined"; selectedForSlicemon = kFALSE; break; | |
434 | }; | |
435 | AliDebug(1, Form("species %d, speciesname %s, momentum %f, selected %s", species, speciesname.Data(), track->P(), selectedForSlicemon ? "yes" : "no")); | |
c04c80e6 | 436 | for(Int_t iplane = 0; iplane < AliESDtrack::kTRDnPlanes; iplane++){ |
bf892a6a | 437 | quantitiesdEdx[kP] = track->GetTRDmomentum(iplane); |
c04c80e6 | 438 | dEdxSum = 0.; |
3a72645a | 439 | for(Int_t islice = 0; islice < nSlices; islice++){ |
e156c3bb | 440 | if(fTotalChargeInSlice0 && islice >= 7) break; |
441 | qSlice = track->GetTRDslice(iplane, fTotalChargeInSlice0 ? islice + 1 : islice); // hack by mfasel: For data with the new reconstruction, slice 0 is used to store the total charge, the total number of slices is 7 instead of 8 | |
3a72645a | 442 | if(qSlice > 1e-1){ |
443 | // cut out 0 slices | |
444 | nSlicesNonZero++; | |
445 | dEdxSum += qSlice; | |
bf892a6a | 446 | // Reweighting of the slices for the truncated mean: select all pion tracks above |
447 | // 1.5 GeV and monitor the dEdx as function of slice | |
448 | if(selectedForSlicemon && track->P() > 1.5){ | |
449 | AliDebug(2, Form("Filling Histogram fTRDslices%s", speciesname.Data())); | |
450 | fHistos->Fill(Form("fTRDslices%s", speciesname.Data()), static_cast<Double_t>(islice), qSlice); | |
451 | } | |
3a72645a | 452 | } |
453 | } | |
454 | quantitiesdEdx[kNonZeroSlices] = nSlicesNonZero; | |
e156c3bb | 455 | quantitiesdEdx[kdEdx] = fTotalChargeInSlice0 ? track->GetTRDslice(iplane, 0) : dEdxSum; // hack by mfasel: In the new reconstruction, the total charge is stored in the first slice, in the old reconstruction it has to be calculated from the slice charges. |
c04c80e6 | 456 | if(dEdxSum) ntrackletsNonZero++; |
457 | // Fill dEdx histogram | |
bf892a6a | 458 | if(dEdxSum > 1e-1) fHistos->Fill("fQAdEdx", quantitiesdEdx); // Cut out 0 entries |
c04c80e6 | 459 | } |
460 | quantitiesQA[kNonZeroTrackletCharge] = ntrackletsNonZero; | |
bf892a6a | 461 | fHistos->Fill("fQAtrack", quantitiesQA); |
c04c80e6 | 462 | |
463 | quantitiesTruncMean[kTPCdEdx] = track->GetTPCsignal(); | |
bf892a6a | 464 | quantitiesTruncMean[kTRDdEdxMethod1] = fTRDpid->GetTRDSignalV1(track, 0.6); |
465 | quantitiesTruncMean[kTRDdEdxMethod2] = fTRDpid->GetTRDSignalV2(track, 0.6); | |
466 | fHistos->Fill("fTRDtruncMean", quantitiesTruncMean); | |
c04c80e6 | 467 | } |
468 | ||
469 | ///////////////////////////////////////////////////////// | |
470 | // | |
471 | // Code for Post Processing | |
472 | // | |
473 | // ////////////////////////////////////////////////////// | |
474 | ||
475 | //__________________________________________________________________ | |
e17c1f86 | 476 | void AliHFEtrdPIDqa::FinishAnalysis(Int_t fCentrality, Bool_t isGreaterEqual){ |
c04c80e6 | 477 | // |
478 | // Finish Analysis: | |
479 | // Calculate Electron Efficiency for ntracklets = 4...6 | |
480 | // Calculate thresholds for ntracklets = 4...6 | |
481 | // | |
482 | ||
8c1c76e9 | 483 | if(!fPionEfficiencies){ |
c04c80e6 | 484 | fPionEfficiencies = new TList; |
485 | fPionEfficiencies->SetName("pionEfficiencies"); | |
e156c3bb | 486 | fPionEfficiencies->SetOwner(); |
c04c80e6 | 487 | } |
488 | if(!fProtonEfficiencies){ | |
489 | fProtonEfficiencies = new TList; | |
490 | fProtonEfficiencies->SetName("protonEfficiencies"); | |
e156c3bb | 491 | fProtonEfficiencies->SetOwner(); |
c04c80e6 | 492 | } |
493 | if(!fThresholds){ | |
494 | fThresholds = new TList; | |
495 | fThresholds->SetName("thresholds"); | |
e156c3bb | 496 | fThresholds->SetOwner(); |
c04c80e6 | 497 | } |
498 | ||
499 | for(Int_t itr = 4; itr <= 6; itr++){ | |
e3ae862b | 500 | if(fShowMessage){ |
501 | printf("========================================\n"); | |
e17c1f86 | 502 | printf("Analysing %d trackltes centrality %i \n", itr, fCentrality); |
e3ae862b | 503 | printf("========================================\n"); |
504 | } | |
e17c1f86 | 505 | AnalyseNTracklets(itr, fCentrality, isGreaterEqual); |
c04c80e6 | 506 | } |
507 | } | |
508 | ||
509 | //__________________________________________________________________ | |
510 | void AliHFEtrdPIDqa::StoreResults(const Char_t *filename){ | |
511 | // | |
512 | // Store histos into a root file | |
513 | // | |
514 | TFile *outfile = new TFile(filename, "RECREATE"); | |
515 | outfile->cd(); | |
516 | fPionEfficiencies->Clone()->Write(fPionEfficiencies->GetName(), kSingleKey); | |
517 | fProtonEfficiencies->Clone()->Write(fProtonEfficiencies->GetName(), kSingleKey); | |
518 | fThresholds->Clone()->Write(fThresholds->GetName(), kSingleKey); | |
519 | outfile->Close(); | |
520 | delete outfile; | |
521 | } | |
522 | ||
523 | //__________________________________________________________________ | |
e17c1f86 | 524 | void AliHFEtrdPIDqa::SaveThresholdParameters(const Char_t *name, Double_t lowerLimit, Double_t upperLimit, Int_t icentrality){ |
c04c80e6 | 525 | // |
526 | // Fit the threshold histograms with the given parametrisation | |
527 | // and store the TF1 in the file | |
528 | // | |
529 | ||
530 | if(!fThresholds){ | |
531 | AliError("Threshold histograms have to be created first"); | |
532 | return; | |
533 | } | |
534 | ||
e3ae862b | 535 | if(fShowMessage){ |
536 | printf("========================================\n"); | |
537 | printf("Calculating threshold parameters\n"); | |
538 | printf("========================================\n"); | |
539 | } | |
c04c80e6 | 540 | |
541 | TList *outlist = new TList; | |
542 | outlist->SetName("thresholdTRD"); | |
543 | ||
544 | TGraph *threshhist = NULL; | |
545 | TF1 *threshparam = NULL; | |
546 | TList *lHistos = NULL, *lFormulas = NULL; | |
547 | for(Int_t itracklet = 4; itracklet <= 6; itracklet++){ | |
548 | ||
e3ae862b | 549 | if(fShowMessage){ |
550 | printf("-------------------------------\n"); | |
551 | printf("Processing %d tracklets\n", itracklet); | |
552 | printf("-------------------------------\n"); | |
553 | } | |
c04c80e6 | 554 | |
e17c1f86 | 555 | Char_t *listname=Form("%dTracklets", itracklet); |
556 | if(icentrality!=-1) listname=Form("%dTracklets%dCentrality", itracklet, icentrality); | |
557 | lHistos = dynamic_cast<TList *>(fThresholds->FindObject(listname)); | |
c04c80e6 | 558 | if(!lHistos){ |
e17c1f86 | 559 | AliError(Form("Threshold histograms for the case %s not found", listname)); |
c04c80e6 | 560 | continue; |
561 | } | |
562 | lFormulas = new TList; | |
e17c1f86 | 563 | lFormulas->SetName(listname); |
c04c80e6 | 564 | outlist->Add(lFormulas); |
565 | ||
566 | for(Int_t ieff = 0; ieff < kNElectronEffs; ieff++){ | |
567 | ||
e3ae862b | 568 | if(fShowMessage){ |
569 | printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); | |
570 | printf("Processing Electron Efficiency %f\n", fgkElectronEff[ieff]); | |
571 | printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); | |
572 | } | |
c04c80e6 | 573 | |
574 | threshhist = dynamic_cast<TGraph *>(lHistos->FindObject(Form("eff%d", static_cast<Int_t>(fgkElectronEff[ieff] * 100)))); | |
bf892a6a | 575 | if(!threshhist) continue; |
e156c3bb | 576 | threshparam = MakeThresholds(threshhist, lowerLimit, upperLimit); |
c04c80e6 | 577 | threshparam->SetName(Form("thresh_%d_%d", itracklet, static_cast<Int_t>(fgkElectronEff[ieff] * 100))); |
e17c1f86 | 578 | if(icentrality!=-1) threshparam->SetName(Form("thresh_%d_%d_%d", itracklet, icentrality, static_cast<Int_t>(fgkElectronEff[ieff] * 100))); |
bf892a6a | 579 | lFormulas->Add(threshparam); |
c04c80e6 | 580 | } |
581 | } | |
582 | ||
583 | // store the output | |
584 | TFile *outfile = new TFile(name, "RECREATE"); | |
585 | outfile->cd(); | |
586 | outlist->Write(outlist->GetName(), kSingleKey); | |
587 | outfile->Close(); | |
588 | delete outfile; | |
589 | } | |
590 | ||
591 | //__________________________________________________________________ | |
e17c1f86 | 592 | void AliHFEtrdPIDqa::AnalyseNTracklets(Int_t nTracklets, Int_t nCentrality, Bool_t isGreaterEqual){ |
c04c80e6 | 593 | // |
594 | // Calculate Pion Efficiency, Proton Efficiency and Kaon Efficiency at discrete | |
595 | // elPion Efficiency, Proton Efficiency and Kaon Efficiency at discrete | |
596 | // electron efficiencies | |
597 | // | |
bf892a6a | 598 | THnSparse *hLikeTRD = dynamic_cast<THnSparseF *>(fHistos->Get("fLikeTRD")); |
599 | if(!hLikeTRD){ | |
600 | AliError("Likelihood Histogram not available"); | |
601 | return; | |
602 | } | |
e17c1f86 | 603 | |
604 | Bool_t isPbPb = kFALSE; | |
605 | if(nCentrality==-1) isPbPb = kFALSE; | |
606 | if(nCentrality!=-1) isPbPb = kTRUE; | |
607 | ||
bf892a6a | 608 | Int_t binTracklets = hLikeTRD->GetAxis(kNTracklets)->FindBin(nTracklets); |
e17c1f86 | 609 | hLikeTRD->GetAxis(kNTracklets)->SetRange(binTracklets, isGreaterEqual ? 7 : binTracklets); |
610 | ||
611 | if(isPbPb){ | |
612 | Int_t binCentrality = hLikeTRD->GetAxis(kCentralityBin)->FindBin(nCentrality); | |
613 | hLikeTRD->GetAxis(kCentralityBin)->SetRange(binCentrality, isGreaterEqual ? 11 : binCentrality); | |
614 | /* | |
615 | new TCanvas; | |
616 | TH2 *test = hLikeTRD->Projection(kCentralityBin, kP); | |
617 | test->Draw("colz"); | |
618 | */ | |
619 | } | |
620 | ||
bf892a6a | 621 | Int_t binElectrons = hLikeTRD->GetAxis(kSpecies)->FindBin(AliPID::kElectron); |
c04c80e6 | 622 | AliDebug(1, Form("BinElectrons %d", binElectrons)); |
bf892a6a | 623 | Int_t binPions = hLikeTRD->GetAxis(kSpecies)->FindBin(AliPID::kPion); |
c04c80e6 | 624 | AliDebug(1, Form("BinPions %d", binPions)); |
bf892a6a | 625 | Int_t binProtons = hLikeTRD->GetAxis(kSpecies)->FindBin(AliPID::kProton); |
c04c80e6 | 626 | AliDebug(1, Form("BinProtons %d", binProtons)); |
bf892a6a | 627 | hLikeTRD->GetAxis(kSpecies)->SetRange(binElectrons, binElectrons); |
628 | TH2 *likeElectron = hLikeTRD->Projection(kElectronLike, kP); | |
c04c80e6 | 629 | likeElectron->SetName("likeElectron"); |
bf892a6a | 630 | hLikeTRD->GetAxis(kSpecies)->SetRange(binPions, binPions); |
631 | TH2 *likePion = hLikeTRD->Projection(kElectronLike, kP); | |
c04c80e6 | 632 | likePion->SetName("likePion"); |
bf892a6a | 633 | hLikeTRD->GetAxis(kSpecies)->SetRange(binProtons, binProtons); |
634 | TH2 *likeProton = hLikeTRD->Projection(kElectronLike, kP); | |
c04c80e6 | 635 | likeProton->SetName("likeProton"); |
636 | ||
637 | // Undo ranges | |
bf892a6a | 638 | hLikeTRD->GetAxis(kSpecies)->SetRange(0, hLikeTRD->GetAxis(kSpecies)->GetNbins()); |
639 | hLikeTRD->GetAxis(kNTracklets)->SetRange(0, hLikeTRD->GetAxis(kNTracklets)->GetNbins()); | |
e17c1f86 | 640 | hLikeTRD->GetAxis(kNTracklets)->SetRange(0, hLikeTRD->GetAxis(kCentralityBin)->GetNbins()); |
c04c80e6 | 641 | |
642 | // Prepare List for output | |
e17c1f86 | 643 | Char_t *listname=Form("%dTracklets", nTracklets); |
644 | if(isPbPb) listname=Form("%dTracklets%dCentrality", nTracklets, nCentrality); | |
645 | ||
646 | ||
647 | TList *listPions = new TList; listPions->SetName(listname); listPions->SetOwner(); | |
648 | TList *listProtons = new TList; listProtons->SetName(listname); listProtons->SetOwner(); | |
649 | TList *listThresholds = new TList; listThresholds->SetName(listname); listThresholds->SetOwner(); | |
c04c80e6 | 650 | fPionEfficiencies->Add(listPions); |
651 | fProtonEfficiencies->Add(listProtons); | |
652 | fThresholds->Add(listThresholds); | |
653 | ||
654 | TH1 *probsEl = NULL, *probsPi = NULL, *probsPr = NULL; | |
e17c1f86 | 655 | TGraphErrors *effPi = NULL, *effPr = NULL, *thresholds = NULL; |
c04c80e6 | 656 | Double_t p = 0, dp = 0; |
657 | Int_t threshbin = 0; | |
8c1c76e9 | 658 | Double_t eff, error; // value and error |
c04c80e6 | 659 | for(Int_t ieff = 0; ieff < kNElectronEffs; ieff++){ |
e3ae862b | 660 | |
661 | if(fShowMessage){ | |
662 | printf("-----------------------------------------\n"); | |
663 | printf("Doing Electron Efficiency %f\n", fgkElectronEff[ieff]); | |
664 | printf("-----------------------------------------\n"); | |
665 | } | |
c04c80e6 | 666 | effPi = new TGraphErrors(likeElectron->GetXaxis()->GetNbins()); |
667 | effPi->SetName(Form("eff%d", static_cast<Int_t >(fgkElectronEff[ieff] * 100))); | |
668 | effPr = new TGraphErrors(likeElectron->GetXaxis()->GetNbins()); | |
669 | effPr->SetName(Form("eff%d", static_cast<Int_t >(fgkElectronEff[ieff] * 100))); | |
e17c1f86 | 670 | thresholds = new TGraphErrors(likeElectron->GetXaxis()->GetNbins()); |
c04c80e6 | 671 | thresholds->SetName(Form("eff%d", static_cast<Int_t >(fgkElectronEff[ieff] * 100))); |
672 | ||
673 | // Add to lists | |
674 | listPions->Add(effPi); | |
675 | listProtons->Add(effPr); | |
676 | listThresholds->Add(thresholds); | |
677 | ||
678 | for(Int_t imom = 1; imom <= likeElectron->GetXaxis()->GetLast(); imom++){ | |
679 | p = likeElectron->GetXaxis()->GetBinCenter(imom); | |
680 | dp = likeElectron->GetXaxis()->GetBinWidth(imom)/2; | |
681 | ||
8c1c76e9 | 682 | probsEl = likeElectron->ProjectionY("el", imom, imom); |
c04c80e6 | 683 | if(!probsEl->GetEntries()) continue; |
8c1c76e9 | 684 | probsPi = likePion->ProjectionY("pi", imom, imom); |
c04c80e6 | 685 | if(!probsPi->GetEntries()) continue; |
8c1c76e9 | 686 | probsPr = likeProton->ProjectionY("pr", imom, imom); |
c04c80e6 | 687 | if(!probsPr->GetEntries()) continue; |
c04c80e6 | 688 | AliDebug(1, Form("Calculating Values for p = %f", p)); |
689 | ||
8c1c76e9 | 690 | // Calculate non-electronEfficiency and error |
691 | eff = CalculateHadronEfficiency(probsPi, probsEl, fgkElectronEff[ieff], threshbin, error); | |
c04c80e6 | 692 | thresholds->SetPoint(imom - 1, p, probsEl->GetXaxis()->GetBinCenter(threshbin)); |
e17c1f86 | 693 | thresholds->SetPointError(imom - 1, dp, EstimateThresholdError(probsEl, threshbin)); |
c04c80e6 | 694 | AliDebug(1, Form("threshold %d|%f", threshbin, probsEl->GetXaxis()->GetBinCenter(threshbin))); |
8c1c76e9 | 695 | AliDebug(1, Form("Pion Efficiency %f +- %f", eff, error)); |
696 | effPi->SetPoint(imom - 1, p, eff); | |
697 | effPi->SetPointError(imom - 1, dp, error); | |
698 | eff = CalculateHadronEfficiency(probsPr, probsEl, fgkElectronEff[ieff] , threshbin, error); | |
699 | AliDebug(1, Form("Proton Efficiency %f", eff)); | |
700 | effPr->SetPoint(imom - 1, p, eff); | |
701 | effPr->SetPointError(imom - 1, dp, error); | |
c04c80e6 | 702 | |
703 | // cleanup | |
704 | delete probsEl; | |
705 | delete probsPi; | |
706 | delete probsPr; | |
707 | } | |
708 | } | |
709 | ||
710 | // remove temporary histograms | |
711 | delete likeElectron; | |
712 | delete likePion; | |
713 | delete likeProton; | |
714 | } | |
715 | ||
716 | //__________________________________________________________________ | |
8c1c76e9 | 717 | Double_t AliHFEtrdPIDqa::CalculateHadronEfficiency(const TH1 * const hadron, const TH1 *const electron, Double_t eff, Int_t &threshbin, Double_t &error){ |
718 | // | |
719 | // Calculate non-electron efficiency | |
720 | // optionally returns sums as second parameter | |
c04c80e6 | 721 | // |
8c1c76e9 | 722 | |
e17c1f86 | 723 | TH1D eleWorking(*((const TH1D *)electron)), hadronWorking(*((const TH1D *)hadron)); // Leave the original histograms untouched and do calculation including scale on copy |
724 | eleWorking.Scale(1./eleWorking.Integral()); | |
725 | hadronWorking.Scale(1./hadronWorking.Integral()); | |
726 | ||
727 | TArrayD sumsEl(eleWorking.GetNbinsX()), sumsHd(eleWorking.GetNbinsX()); | |
8c1c76e9 | 728 | |
729 | // calculate threshold and estimated electron efficiency the threshold was taken | |
730 | Double_t elEff = 0.; // estimated electron efficiency at the end | |
731 | Int_t currentBin = 0, nbins = 0; | |
e17c1f86 | 732 | for(Int_t ibin = eleWorking.GetXaxis()->GetLast(); ibin >= eleWorking.GetXaxis()->GetFirst(); ibin--){ |
c04c80e6 | 733 | currentBin = ibin; |
8c1c76e9 | 734 | nbins++; |
e17c1f86 | 735 | elEff += eleWorking.GetBinContent(ibin); |
736 | sumsEl[eleWorking.GetXaxis()->GetLast() - ibin] = elEff; | |
8c1c76e9 | 737 | if(elEff >= eff){ |
c04c80e6 | 738 | // we found the matching bin, break the loop |
739 | break; | |
740 | } | |
741 | } | |
8c1c76e9 | 742 | threshbin = currentBin; |
743 | ||
744 | Double_t hdEff = 0; | |
e17c1f86 | 745 | for(Int_t ibin = hadronWorking.GetXaxis()->GetLast(); ibin >= threshbin; ibin--) { |
746 | hdEff += hadronWorking.GetBinContent(ibin); | |
747 | sumsHd[hadronWorking.GetXaxis()->GetLast() - ibin] = hdEff; | |
8c1c76e9 | 748 | } |
749 | ||
750 | // search sums of electron efficiency for double counts, eliminate in electron and hadron array | |
751 | TArrayD newsumsEl(100), newsumsHd(100); | |
752 | Int_t nusable = 0; | |
753 | for(Int_t ien = 0; ien < nbins; ien++){ | |
754 | if(ien==0){ | |
755 | newsumsEl[0] = sumsEl[0]; | |
756 | nusable++; | |
757 | continue; | |
758 | } | |
759 | Int_t index = TMath::BinarySearch(nusable, newsumsEl.GetArray(), sumsEl[ien]); | |
760 | if(TMath::Abs(sumsEl[ien] - newsumsEl[index]) < 1e-13){ | |
761 | // element already counted, don't add to the new arrays | |
762 | continue; | |
763 | } | |
764 | newsumsEl[nusable] = sumsEl[ien]; | |
765 | newsumsHd[nusable] = sumsHd[ien]; | |
766 | nusable++; | |
767 | } | |
768 | ||
769 | //printf("New array\n"); | |
770 | //for(Int_t ib = 0; ib < nusable; ib++){ | |
771 | // printf("Electron Efficiency %f, Pion Efficiency %f\n", newsumsEl[ib], newsumsHd[ib]); | |
772 | //} | |
773 | //printf("Do Fit\n"); | |
774 | ||
775 | // Calculate error | |
776 | error = 0; | |
e17c1f86 | 777 | if(hadronWorking.GetEntries() > 0 && eleWorking.GetEntries() > 0 && nusable > 2){ |
8c1c76e9 | 778 | // Do error calculation in case the bins have enough statistics |
779 | TGraph gevh(nusable, newsumsEl.GetArray(), newsumsHd.GetArray()); | |
780 | TF1 evh("evh","pol2", eff-.05, eff+.05); | |
781 | gevh.Fit(&evh, "Q", "", eff-.05, eff+.05); | |
782 | ||
783 | // return the error of the pion efficiency | |
784 | if(((1.-hdEff) < 0) || ((1.- elEff) < 0)){ | |
785 | AliError(" ElEffi or HdEffi > 1. Error can not be calculated. Please increase statistics!"); | |
786 | } else { | |
e17c1f86 | 787 | error = TMath::Sqrt(hdEff*(1-hdEff)/hadronWorking.GetEntries()+TMath::Power(evh.Derivative(eff), 2)*elEff*(1-elEff)/eleWorking.GetEntries()); |
8c1c76e9 | 788 | } |
e17c1f86 | 789 | AliDebug(2, Form("Pion Effi at [%f] : [%f +/- %f], Threshold[%f]", elEff, hdEff, error, eleWorking.GetBinCenter(threshbin))); |
8c1c76e9 | 790 | AliDebug(2, Form("Derivative at %4.2f : %f\n", eff, evh.Derivative(eff))); |
791 | } | |
792 | ||
793 | return hdEff; | |
c04c80e6 | 794 | } |
795 | ||
796 | //__________________________________________________________________ | |
e17c1f86 | 797 | Double_t AliHFEtrdPIDqa::EstimateThresholdError(const TH1 * const electron, Int_t threshbin){ |
798 | // | |
799 | // Estimate threshold error as sqrt(N_int)/N_ent | |
800 | // where N_int are the counts integrated under the electron selection band | |
801 | // and N_ent are all entries in the histogram | |
802 | // | |
803 | Int_t nInt = 0; | |
804 | for(Int_t ibin = threshbin; ibin <= electron->GetXaxis()->GetNbins(); ibin++){ | |
805 | nInt += (Int_t) electron->GetBinContent(ibin); | |
806 | } | |
807 | Int_t nEnt = (Int_t) electron->Integral(); | |
808 | if(nEnt == 0) return 1.; | |
809 | return TMath::Sqrt(static_cast<Double_t>(nInt))/static_cast<Double_t>(nEnt); | |
810 | } | |
811 | ||
812 | //__________________________________________________________________ | |
813 | Double_t AliHFEtrdPIDqa::CalculateIntegratedPionEfficiency(UInt_t nTracklets, Double_t electronEff, Double_t pmin, Double_t pmax, Int_t icentrality, Double_t *error){ | |
c04c80e6 | 814 | // |
8c1c76e9 | 815 | // Calculate Pion Efficiency for a given electron efficiency in the specified momentum range |
816 | // | |
817 | if(nTracklets < 4 || nTracklets > 6){ | |
818 | AliError("Pion Efficiency calculation only available for 4, 5, and 6 tracklets"); | |
819 | return 0.; | |
820 | } | |
821 | if(electronEff < 0.6 || electronEff > 1.){ | |
822 | AliError("Pion Efficiency calculation only available in the electron efficiency range 0.6 to 1"); | |
823 | return 0.; | |
824 | } | |
825 | if(pmin < 0.1 || pmin > 10 || pmax < 0.1 || pmax > 10.){ | |
826 | AliError("Pion Efficiency calculation only available in the momentum range 0.1 to 10 GeV/c"); | |
827 | return 0.; | |
828 | } | |
829 | if(pmax < pmin){ | |
830 | AliError("pmin is expected to be >= pmax"); | |
831 | return 0.; | |
832 | } | |
c04c80e6 | 833 | |
8c1c76e9 | 834 | // prerequierements fullfiled |
835 | // prepare histos | |
836 | THnSparse *hLikeTRD = dynamic_cast<THnSparseF *>(fHistos->Get("fLikeTRD")); | |
837 | if(!hLikeTRD){ | |
838 | AliError("Likelihood Histogram not available"); | |
839 | return 0; | |
840 | } | |
841 | Int_t binTracklets = hLikeTRD->GetAxis(kNTracklets)->FindBin(nTracklets); | |
842 | hLikeTRD->GetAxis(kNTracklets)->SetRange(binTracklets, binTracklets); | |
e17c1f86 | 843 | |
844 | if(icentrality!=1){ | |
845 | Int_t binCentrality = hLikeTRD->GetAxis(kCentralityBin)->FindBin(icentrality); | |
846 | hLikeTRD->GetAxis(kCentralityBin)->SetRange(binCentrality, binCentrality); | |
847 | } | |
848 | ||
8c1c76e9 | 849 | Int_t pbinMin = hLikeTRD->GetAxis(kP)->FindBin(pmax), |
850 | pbinMax = hLikeTRD->GetAxis(kP)->FindBin(pmax); | |
851 | hLikeTRD->GetAxis(kP)->SetRange(pbinMin, pbinMax); | |
852 | Int_t binElectrons = hLikeTRD->GetAxis(kSpecies)->FindBin(AliPID::kElectron); | |
853 | Int_t binPions = hLikeTRD->GetAxis(kSpecies)->FindBin(AliPID::kPion); | |
854 | hLikeTRD->GetAxis(kSpecies)->SetRange(binElectrons, binElectrons); | |
855 | TH1 *likeElectron = hLikeTRD->Projection(kElectronLike); | |
856 | likeElectron->Scale(1./likeElectron->Integral()); | |
857 | likeElectron->SetName("likeElectron"); | |
858 | hLikeTRD->GetAxis(kSpecies)->SetRange(binPions, binPions); | |
859 | TH1 *likePion = hLikeTRD->Projection(kElectronLike); | |
860 | likePion->Scale(1./likePion->Integral()); | |
861 | likePion->SetName("likePion"); | |
862 | ||
863 | // Undo ranges | |
864 | hLikeTRD->GetAxis(kSpecies)->SetRange(0, hLikeTRD->GetAxis(kSpecies)->GetNbins()); | |
865 | hLikeTRD->GetAxis(kNTracklets)->SetRange(0, hLikeTRD->GetAxis(kNTracklets)->GetNbins()); | |
866 | hLikeTRD->GetAxis(kP)->SetRange(0, hLikeTRD->GetAxis(kP)->GetNbins()); | |
867 | ||
868 | // Do Calculation | |
869 | Int_t thresh; Double_t err; | |
870 | Double_t effpi = CalculateHadronEfficiency(likePion, likeElectron, electronEff, thresh, err); | |
871 | delete likePion; delete likeElectron; | |
872 | if(error) *error = err; | |
873 | return effpi; | |
c04c80e6 | 874 | } |
875 | ||
876 | //__________________________________________________________________ | |
e17c1f86 | 877 | void AliHFEtrdPIDqa::DrawTracklet(Int_t itracklet, Double_t pmin, Double_t pmax, Int_t icentrality, Bool_t doFit){ |
c04c80e6 | 878 | // |
879 | // Draw efficiencies and threshold as function of p | |
880 | // | |
881 | if(!(fPionEfficiencies && fProtonEfficiencies && fThresholds)){ | |
882 | AliError("No graphs to draw available"); | |
883 | return; | |
884 | } | |
885 | ||
e17c1f86 | 886 | Char_t *listname=Form("%dTracklets", itracklet); |
887 | if(icentrality!=-1) listname=Form("%dTracklets%dCentrality", itracklet, icentrality); | |
888 | ||
889 | TList *lpions = dynamic_cast<TList *>(fPionEfficiencies->FindObject(listname)); | |
890 | TList *lprotons = dynamic_cast<TList *>(fProtonEfficiencies->FindObject(listname)); | |
c04c80e6 | 891 | |
e17c1f86 | 892 | TList *lthresholds = dynamic_cast<TList *>(fThresholds->FindObject(listname)); |
bf892a6a | 893 | if(!(lpions && lprotons && lthresholds)){ |
894 | AliDebug(1, "Relevant lists not found. Did you forget to run FinishAnalysis()?"); | |
895 | return; | |
896 | } | |
c04c80e6 | 897 | |
898 | TGraphErrors *pi, *pr; | |
899 | TGraph *tr; | |
900 | TLegend *leg; | |
e17c1f86 | 901 | Char_t *canvasname=Form("tracklet%d", itracklet); |
902 | if(icentrality!=-1) canvasname=Form("tracklet%dcentrality%d", itracklet, icentrality); | |
903 | TCanvas *c1 = new TCanvas(canvasname, canvasname, 1024, 768); | |
c04c80e6 | 904 | c1->Divide(3,2); |
bf892a6a | 905 | TF1 *threshfit = NULL; |
c04c80e6 | 906 | for(Int_t ieff = 0; ieff < kNElectronEffs; ieff++){ |
907 | c1->cd(ieff + 1); | |
8c1c76e9 | 908 | gPad->SetGrid(0,0); |
909 | gPad->SetLeftMargin(0.12); | |
910 | gPad->SetRightMargin(0.08); | |
c04c80e6 | 911 | pi = dynamic_cast<TGraphErrors *>(lpions->FindObject(Form("eff%d", static_cast<Int_t>(fgkElectronEff[ieff] * 100)))); |
912 | pr = dynamic_cast<TGraphErrors *>(lprotons->FindObject(Form("eff%d", static_cast<Int_t>(fgkElectronEff[ieff] * 100)))); | |
913 | tr = dynamic_cast<TGraph *>(lthresholds->FindObject(Form("eff%d", static_cast<Int_t>(fgkElectronEff[ieff] * 100)))); | |
bf892a6a | 914 | if(!(pi && pr && tr)) continue; |
c04c80e6 | 915 | |
916 | // Define nice plot, draw | |
917 | // Axis Title | |
918 | pi->GetXaxis()->SetTitle("p / GeV/c"); | |
c1bd5735 | 919 | pi->GetYaxis()->SetTitle("Efficiency"); |
c04c80e6 | 920 | pr->GetXaxis()->SetTitle("p / GeV/c"); |
c1bd5735 | 921 | pr->GetYaxis()->SetTitle("Efficiency"); |
c04c80e6 | 922 | tr->GetXaxis()->SetTitle("p / GeV/c"); |
c1bd5735 | 923 | tr->GetYaxis()->SetTitle("Efficiency"); |
8c1c76e9 | 924 | pi->GetYaxis()->SetTitleOffset(1.2); |
925 | pr->GetYaxis()->SetTitleOffset(1.2); | |
926 | tr->GetYaxis()->SetTitleOffset(1.2); | |
927 | pi->GetXaxis()->SetTitleSize(0.045); | |
928 | pi->GetYaxis()->SetTitleSize(0.045); | |
929 | pr->GetXaxis()->SetTitleSize(0.045); | |
930 | pr->GetYaxis()->SetTitleSize(0.045); | |
931 | tr->GetXaxis()->SetTitleSize(0.045); | |
932 | tr->GetYaxis()->SetTitleSize(0.045); | |
c04c80e6 | 933 | // Axis Range |
e3ae862b | 934 | pi->GetYaxis()->SetRangeUser(1e-3, 1.); |
935 | pr->GetYaxis()->SetRangeUser(1e-3, 1.); | |
936 | tr->GetYaxis()->SetRangeUser(1e-3, 1.); | |
8c1c76e9 | 937 | if(pmin >= 0 && pmax >= 0.){ |
e3ae862b | 938 | pi->GetXaxis()->SetRangeUser(pmin, pmax); |
939 | pr->GetXaxis()->SetRangeUser(pmin, pmax); | |
940 | tr->GetXaxis()->SetRangeUser(pmin, pmax); | |
941 | } | |
c04c80e6 | 942 | // Marker |
943 | pi->SetMarkerColor(kRed); | |
944 | pi->SetMarkerStyle(20); | |
945 | pr->SetMarkerColor(kBlue); | |
946 | pr->SetMarkerStyle(21); | |
947 | tr->SetMarkerColor(kBlack); | |
948 | tr->SetMarkerStyle(22); | |
949 | // Title | |
950 | pi->SetTitle(Form ("%.2f Electron Efficiency", fgkElectronEff[ieff])); | |
951 | pr->SetTitle(Form ("%.2f Electron Efficiency", fgkElectronEff[ieff])); | |
952 | tr->SetTitle(Form ("%.2f Electron Efficiency", fgkElectronEff[ieff])); | |
953 | // Draw | |
e17c1f86 | 954 | pi->Draw("ape"); pr->Draw("pesame"); tr->Draw("pesame"); |
c04c80e6 | 955 | |
bf892a6a | 956 | // Optionally do Fit |
957 | if(doFit){ | |
e156c3bb | 958 | threshfit = MakeThresholds(tr, pmin, pmax); |
bf892a6a | 959 | threshfit->SetLineColor(kBlack); |
960 | threshfit->Draw("same"); | |
961 | } | |
962 | ||
c04c80e6 | 963 | // Add entries to legend |
8c1c76e9 | 964 | if(ieff==0){ |
965 | leg = new TLegend(0.5, 0.65, 0.89, 0.85); | |
966 | leg->SetBorderSize(0); | |
967 | leg->SetFillStyle(0); | |
968 | leg->AddEntry(pi, "Pion Efficiency", "lp"); | |
969 | leg->AddEntry(pr, "Proton Efficiency", "lp"); | |
970 | leg->AddEntry(tr, "Thresholds", "lp"); | |
971 | leg->Draw(); | |
972 | gPad->Update(); | |
973 | } | |
c04c80e6 | 974 | } |
8c1c76e9 | 975 | c1->cd(); |
c04c80e6 | 976 | } |
977 | ||
978 | //__________________________________________________________________ | |
e156c3bb | 979 | TF1 *AliHFEtrdPIDqa::MakeThresholds(TGraph *threshist, Double_t lowerLimit, Double_t upperLimit){ |
c04c80e6 | 980 | // |
981 | // Create TF1 containing the threshold parametrisation | |
982 | // | |
983 | ||
984 | TF1 *threshparam = new TF1("thresh", "1-[0]-[1]*x-[2]*TMath::Exp(-[3]*x)", 0.1, 10); | |
e156c3bb | 985 | threshist->Fit(threshparam, "NE", "", lowerLimit, upperLimit); |
c04c80e6 | 986 | return threshparam; |
987 | } | |
988 | ||
989 | //__________________________________________________________________ | |
990 | void AliHFEtrdPIDqa::ClearLists(){ | |
991 | // | |
992 | // Clear lists for particle efficiencies and thresholds | |
993 | // | |
994 | if(fPionEfficiencies){ | |
995 | fPionEfficiencies->Delete(); | |
996 | delete fPionEfficiencies; | |
997 | fPionEfficiencies = NULL; | |
998 | } | |
999 | if(fProtonEfficiencies){ | |
1000 | fProtonEfficiencies->Delete(); | |
1001 | delete fProtonEfficiencies; | |
1002 | fProtonEfficiencies = NULL; | |
1003 | } | |
1004 | if(fThresholds){ | |
1005 | fThresholds->Delete(); | |
1006 | delete fThresholds; | |
1007 | fThresholds = NULL; | |
1008 | } | |
1009 | } | |
e3ae862b | 1010 | |
1011 | //__________________________________________________________________ | |
e17c1f86 | 1012 | Double_t AliHFEtrdPIDqa::EvalPionEfficiency(Int_t ntls, Int_t eEff, Double_t p, Int_t icentrality){ |
c2690925 | 1013 | // |
1014 | // calculate pion efficiency | |
1015 | // Arguments: | |
1016 | // Number of tracklets | |
1017 | // Electron Efficiency | |
1018 | // Momentum | |
1019 | // | |
e17c1f86 | 1020 | TGraphErrors *measurement = GetPionEfficiency(ntls, eEff, icentrality); |
e3ae862b | 1021 | if(!measurement) return -1.; |
1022 | return measurement->Eval(p); | |
1023 | } | |
1024 | ||
1025 | //__________________________________________________________________ | |
e17c1f86 | 1026 | Double_t AliHFEtrdPIDqa::EvalProtonEfficiency(Int_t ntls, Int_t eEff, Double_t p, Int_t icentrality){ |
c2690925 | 1027 | // |
1028 | // calculate proton efficiency | |
1029 | // Arguments: | |
1030 | // Number of tracklets | |
1031 | // Electron Efficiency | |
1032 | // Momentum | |
1033 | // | |
e17c1f86 | 1034 | TGraphErrors *measurement = GetProtonEfficiency(ntls, eEff, icentrality); |
e3ae862b | 1035 | if(!measurement) return -1.; |
1036 | return measurement->Eval(p); | |
1037 | } | |
1038 | ||
1039 | //__________________________________________________________________ | |
e17c1f86 | 1040 | Double_t AliHFEtrdPIDqa::EvalThreshold(Int_t ntls, Int_t eEff, Double_t p, Int_t icentrality){ |
c2690925 | 1041 | // |
1042 | // Get the threshold to reach a certain electron efficiency | |
1043 | // Arguments: | |
1044 | // Number of tracklets | |
1045 | // Electron Efficiency | |
1046 | // Momentum | |
1047 | // | |
e17c1f86 | 1048 | TGraph *measurement = GetThreshold(ntls, eEff, icentrality); |
e3ae862b | 1049 | if(!measurement) return -1.; |
1050 | return measurement->Eval(p); | |
1051 | } | |
1052 | ||
8c1c76e9 | 1053 | //__________________________________________________________________ |
e17c1f86 | 1054 | TGraphErrors *AliHFEtrdPIDqa::GetPionEfficiency(Int_t ntracklets, Int_t eleffpercent, Int_t icentrality){ |
8c1c76e9 | 1055 | // |
1056 | // Get Graph with pion efficiencies | |
1057 | // | |
e17c1f86 | 1058 | Char_t *listname=Form("%dTracklets", ntracklets); |
1059 | if(icentrality!=-1) listname=Form("%dTracklets%dCentrality", ntracklets, icentrality); | |
1060 | TList *graphs = dynamic_cast<TList *>(fPionEfficiencies->FindObject(listname)); | |
8c1c76e9 | 1061 | if(!graphs) return NULL; |
1062 | return dynamic_cast<TGraphErrors *>(graphs->FindObject(Form("eff%d", eleffpercent))); | |
1063 | } | |
1064 | ||
1065 | //__________________________________________________________________ | |
e17c1f86 | 1066 | TGraphErrors *AliHFEtrdPIDqa::GetProtonEfficiency(Int_t ntracklets, Int_t eleffpercent, Int_t icentrality){ |
8c1c76e9 | 1067 | // |
1068 | // Get Graph with proton efficiencies | |
1069 | // | |
e17c1f86 | 1070 | Char_t *listname=Form("%dTracklets", ntracklets); |
1071 | if(icentrality!=-1) listname=Form("%dTracklets%dCentrality", ntracklets, icentrality); | |
1072 | TList *graphs = dynamic_cast<TList *>(fProtonEfficiencies->FindObject(listname)); | |
8c1c76e9 | 1073 | if(!graphs) return NULL; |
1074 | return dynamic_cast<TGraphErrors *>(graphs->FindObject(Form("eff%d", eleffpercent))); | |
1075 | } | |
1076 | ||
1077 | //__________________________________________________________________ | |
e17c1f86 | 1078 | TGraph *AliHFEtrdPIDqa::GetThreshold(Int_t ntracklets, Int_t eleffpercent, Int_t icentrality){ |
8c1c76e9 | 1079 | // |
1080 | // Get Graph with threshols | |
1081 | // | |
e17c1f86 | 1082 | Char_t *listname=Form("%dTracklets", ntracklets); |
1083 | if(icentrality!=-1) listname=Form("%dTracklets%dCentrality", ntracklets, icentrality); | |
1084 | TList *graphs = dynamic_cast<TList *>(fThresholds->FindObject(listname)); | |
8c1c76e9 | 1085 | if(!graphs) return NULL; |
1086 | return dynamic_cast<TGraph *>(graphs->FindObject(Form("eff%d", eleffpercent))); | |
1087 | } | |
1088 |