1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //////////////////////////////////////////////////////////////////////////
20 // Container for the distributions of dE/dx and the time bin of the //
21 // max. cluster for electrons and pions //
24 // Prashant Shukla <shukla@pi0.physi.uni-heidelberg.de> //
25 // Alex Bercuci <a.bercuci@gsi.de> //
27 //////////////////////////////////////////////////////////////////////////
37 #include "AliESDtrack.h"
39 #include "AliTRDCalPID.h"
40 #include "AliTRDcalibDB.h"
42 ClassImp(AliTRDCalPID)
44 Char_t* AliTRDCalPID::fpartName[AliPID::kSPECIES] = {"electron", "muon", "pion", "kaon", "proton"};
46 Char_t* AliTRDCalPID::fpartSymb[AliPID::kSPECIES] = {"EL", "MU", "PI", "KA", "PR"};
48 Float_t AliTRDCalPID::fTrackMomentum[kNMom] = {0.6, 0.8, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 10.0};
50 Float_t AliTRDCalPID::fTrackSegLength[kNLength] = {3.7, 3.9, 4.2, 5.0};
53 //_________________________________________________________________________
54 AliTRDCalPID::AliTRDCalPID()
55 :TNamed("pid", "PID for TRD")
61 // The Default constructor
68 //_________________________________________________________________________
69 AliTRDCalPID::AliTRDCalPID(const Text_t *name, const Text_t *title)
76 // The main constructor
83 //_____________________________________________________________________________
84 AliTRDCalPID::AliTRDCalPID(const AliTRDCalPID &c)
86 ,fMeanChargeRatio(c.fMeanChargeRatio)
94 if (this != &c) ((AliTRDCalPID &) c).Copy(*this);
98 //_________________________________________________________________________
99 AliTRDCalPID::~AliTRDCalPID()
109 //_________________________________________________________________________
110 void AliTRDCalPID::CleanUp()
113 // Delets all newly created objects
127 //_____________________________________________________________________________
128 AliTRDCalPID &AliTRDCalPID::operator=(const AliTRDCalPID &c)
131 // Assignment operator
134 if (this != &c) ((AliTRDCalPID &) c).Copy(*this);
139 //_____________________________________________________________________________
140 void AliTRDCalPID::Copy(TObject &c) const
146 AliTRDCalPID& target = (AliTRDCalPID &) c;
150 target.fMeanChargeRatio = fMeanChargeRatio;
153 target.fHistdEdx = (TObjArray*) fHistdEdx->Clone();
156 target.fHistTimeBin = (TObjArray*) fHistTimeBin->Clone();
163 //_________________________________________________________________________
164 void AliTRDCalPID::Init()
170 fHistdEdx = new TObjArray(AliPID::kSPECIES * kNMom/* * kNLength*/);
171 fHistdEdx->SetOwner();
172 fHistTimeBin = new TObjArray(2 * kNMom);
173 fHistTimeBin->SetOwner();
175 // Initialization of estimator at object instantiation because late
176 // initialization in function GetProbability() is not working due to
177 // constantness of this function.
178 // fEstimator = new AliTRDCalPIDRefMaker();
180 // ADC Gain normalization
181 fMeanChargeRatio = 1.0;
184 //_________________________________________________________________________
185 Bool_t AliTRDCalPID::LoadLQReferences(Char_t *refFile)
188 // Read the TRD dEdx histograms.
191 Int_t nTimeBins = 22;
192 // Get number of time bins from CDB
193 AliTRDcalibDB *calibration = AliTRDcalibDB::Instance();
195 AliWarning(Form("No AliTRDcalibDB available. Using %d time bins.", nTimeBins));
197 if(calibration->GetRun() > -1) nTimeBins = calibration->GetNumberOfTimeBins();
198 else AliWarning(Form("Run number not set. Using %d time bins.", nTimeBins));
202 // Read histogram Root file
203 TFile *histFile = TFile::Open(refFile, "READ");
204 if (!histFile || !histFile->IsOpen()) {
205 AliError(Form("Opening TRD histgram file %s failed", refFile));
211 for (Int_t iparticle = 0; iparticle < AliPID::kSPECIES; iparticle++){
212 for (Int_t imom = 0; imom < kNMom; imom++){
213 TH2D* hist = (TH2D*)histFile->Get(Form("h2dEdx%s%02d", fpartSymb[iparticle], imom/*, ilength*/))->Clone();
214 hist->Scale(1./hist->Integral());
215 fHistdEdx->AddAt(hist, GetHistID(iparticle, imom));
217 if (iparticle != AliPID::kElectron && iparticle != AliPID::kPion) continue;
219 TH1F* ht = (TH1F*)histFile->Get(Form("h1MaxTB%s%02d", fpartSymb[iparticle], imom))->Clone();
220 if(ht->GetNbinsX() != nTimeBins) AliWarning(Form("The number of time bins %d defined in h1MaxTB%s%02d differs from calibration value of %d. This may lead to erroneous results.", ht->GetNbinsX(), fpartSymb[iparticle], imom, nTimeBins));
221 ht->Scale(1./ht->Integral());
222 fHistTimeBin->AddAt(ht, ((iparticle==AliPID::kElectron)?0:1)*kNMom + imom);
229 // Number of bins and bin size
230 //TH1F* hist = (TH1F*) fHistdEdx->At(GetHistID(AliPID::kPion, 1));
231 //fNbins = hist->GetNbinsX();
232 //fBinSize = hist->GetBinWidth(1);
238 // //_________________________________________________________________________
239 // Double_t AliTRDCalPID::GetMean(Int_t k, Int_t ip) const
242 // // Gets mean of de/dx dist. of e
245 // AliInfo(Form("Mean for particle = %s and momentum = %.2f is:\n"
247 // ,fTrackMomentum[ip]));
248 // if (k < 0 || k > AliPID::kSPECIES) {
252 // return ((TH1F*) fHistdEdx->At(GetHistID(k,ip)))->GetMean();
256 // //_________________________________________________________________________
257 // Double_t AliTRDCalPID::GetNormalization(Int_t k, Int_t ip) const
260 // // Gets Normalization of de/dx dist. of e
263 // AliInfo(Form("Normalization for particle = %s and momentum = %.2f is:\n"
265 // ,fTrackMomentum[ip]));
266 // if (k < 0 || k > AliPID::kSPECIES) {
270 // return ((TH1F*) fHistdEdx->At(GetHistID(k,ip)))->Integral();
274 //_________________________________________________________________________
275 TH1* AliTRDCalPID::GetHistogram(Int_t k, Int_t ip/*, Int_t il*/) const
278 // Returns one selected dEdx histogram
281 if (k < 0 || k >= AliPID::kSPECIES) return 0x0;
282 if(ip<0 || ip>= kNMom ) return 0x0;
284 AliInfo(Form("Retrive dEdx histogram for %s of %5.2f GeV/c", fpartName[k], fTrackMomentum[ip]));
286 return (TH1*)fHistdEdx->At(GetHistID(k, ip));
290 //_________________________________________________________________________
291 TH1* AliTRDCalPID::GetHistogramT(Int_t k, Int_t ip) const
294 // Returns one selected time bin max histogram
297 if (k < 0 || k >= AliPID::kSPECIES) return 0x0;
298 if(ip<0 || ip>= kNMom ) return 0x0;
300 AliInfo(Form("Retrive MaxTB histogram for %s of %5.2f GeV/c", fpartName[k], fTrackMomentum[ip]));
302 return (TH1*)fHistTimeBin->At(((k==AliPID::kElectron)?0:1)*kNMom+ip);
307 //_________________________________________________________________________
308 Double_t AliTRDCalPID::GetProbability(Int_t spec, Float_t mom, Float_t *dedx, Float_t length) const
311 // Core function of AliTRDCalPID class for calculating the
312 // likelihood for species "spec" (see AliTRDtrack::kNspecie) of a
313 // given momentum "mom" and a given dE/dx (slice "dedx") yield per
317 if (spec < 0 || spec >= AliPID::kSPECIES) return 0.;
319 //Double_t dedx = dedx1/fMeanChargeRatio;
321 // find the interval in momentum and track segment length which applies for this data
323 while(ilength<kNLength-1 && length>fTrackSegLength[ilength]){
327 while(imom<kNMom-1 && mom>fTrackMomentum[imom]) imom++;
329 Int_t nbinsx, nbinsy;
330 TAxis *ax = 0x0, *ay = 0x0;
332 Double_t mom1 = fTrackMomentum[imom-1], mom2 = fTrackMomentum[imom];
334 if(!(hist = (TH2D*)fHistdEdx->At(GetHistID(spec, imom-1/*, ilength*/)))){
335 AliInfo(Form("Looking for spec(%d) mom(%f) Ex(%f) Ey(%f) length(%f)", spec, mom, dedx[0], dedx[1], length));
336 AliError(Form("EHistogram id %d not found in DB.", GetHistID(spec, imom-1)));
339 ax = hist->GetXaxis(); nbinsx = ax->GetNbins();
340 ay = hist->GetYaxis(); nbinsy = ay->GetNbins();
341 Float_t x = dedx[0]+dedx[1], y = dedx[2];
342 Bool_t kX = (x < ax->GetBinUpEdge(nbinsx));
343 Bool_t kY = (y < ay->GetBinUpEdge(nbinsy));
345 if(kY) LQ1 = hist->GetBinContent( hist->FindBin(x, y));
346 //fEstimator->Estimate2D2(hist, x, y);
347 else LQ1 = hist->GetBinContent(ax->FindBin(x), nbinsy);
349 if(kY) LQ1 = hist->GetBinContent(nbinsx, ay->FindBin(y));
350 else LQ1 = hist->GetBinContent(nbinsx, nbinsy);
353 if(!(hist = (TH2D*)fHistdEdx->At(GetHistID(spec, imom/*, ilength*/)))){
354 AliInfo(Form("Looking for spec(%d) mom(%f) Ex(%f) Ey(%f) length(%f)", spec, mom, dedx[0], dedx[1], length));
355 AliError(Form("EHistogram id %d not found in DB.", GetHistID(spec, imom)));
359 if(kY) LQ2 = hist->GetBinContent( hist->FindBin(x, y));
360 //fEstimator->Estimate2D2(hist, x, y);
361 else LQ2 = hist->GetBinContent(ax->FindBin(x), nbinsy);
363 if(kY) LQ2 = hist->GetBinContent(nbinsx, ay->FindBin(y));
364 else LQ2 = hist->GetBinContent(nbinsx, nbinsy);
367 // return interpolation over momentum binning
368 return LQ1 + (LQ2 - LQ1)*(mom - mom1)/(mom2 - mom1);
372 //_________________________________________________________________________
373 Double_t AliTRDCalPID::GetProbabilityT(Int_t spec, Double_t mom, Int_t timbin) const
376 // Gets the Probability of having timbin at a given momentum (mom)
377 // and particle type (spec) (0 for e) and (2 for pi)
378 // from the precalculated timbin distributions
381 if (spec < 0 || spec >= AliPID::kSPECIES) return 0.;
383 Int_t iTBin = timbin+1;
385 // Everything which is not an electron counts as a pion for time bin max
386 //if(spec != AliPID::kElectron) spec = AliPID::kPion;
391 while(imom<kNMom-1 && mom>fTrackMomentum[imom]) imom++;
393 Double_t mom1 = fTrackMomentum[imom-1], mom2 = fTrackMomentum[imom];
395 if(!(hist = (TH1F*) fHistTimeBin->At(((spec==AliPID::kElectron)?0:1)*kNMom+imom-1))){
396 AliInfo(Form("Looking for spec(%d) mom(%f) timbin(%d)", spec, mom, timbin));
397 AliError(Form("THistogram id %d not found in DB.", ((spec==AliPID::kElectron)?0:1)*kNMom+imom-1));
400 Double_t LQ1 = hist->GetBinContent(iTBin);
402 if(!(hist = (TH1F*) fHistTimeBin->At(((spec==AliPID::kElectron)?0:1)*kNMom+imom))){
403 AliInfo(Form("Looking for spec(%d) mom(%f) timbin(%d)", spec, mom, timbin));
404 AliError(Form("THistogram id %d not found in DB.", ((spec==AliPID::kElectron)?0:1)*kNMom+imom));
407 Double_t LQ2 = hist->GetBinContent(iTBin);
409 // return interpolation over momentum binning
410 return LQ1 + (LQ2 - LQ1)*(mom - mom1)/(mom2 - mom1);