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 **************************************************************************/
16 /* $Id: AliTRDdigitizer.cxx 44182 2010-10-10 16:23:39Z cblume $ */
18 ////////////////////////////////////////////////////////////////////////////
20 // Helper class for TRD PID efficiency calculation. //
21 // Calculation of the hadron efficiency dependent on momentum and of //
22 // the errors implemented in function CalculatePionEff. The pion //
23 // efficiency is based on a predefined electron efficiency. //
24 // The default is 90%. To change the, one has to call the function //
25 // SetElectronEfficiency. //
26 // Other Helper functions decide based on 90% electron efficiency //
27 // whether a certain track is accepted as Electron Track. //
28 // The reference data is stored in the TRD OCDB. //
30 ////////////////////////////////////////////////////////////////////////////
33 #include "TObjArray.h"
38 #include "TGraphErrors.h"
42 #include "Cal/AliTRDCalPID.h"
43 #include "AliCDBManager.h"
44 #include "AliCDBEntry.h"
45 #include "AliESDtrack.h"
47 #include "AliTRDpidUtil.h"
49 ClassImp(AliTRDpidUtil)
51 Float_t AliTRDpidUtil::fgEleEffi = 0.9;
53 //________________________________________________________________________
54 AliTRDpidUtil::AliTRDpidUtil()
62 // Default constructor
66 //________________________________________________________________________
67 Bool_t AliTRDpidUtil::CalculatePionEffi(TH1* histo1, TH1* histo2)
68 // Double_t AliTRDpidUtil::GetError()
71 // Calculates the pion efficiency
74 histo1 -> SetLineColor(kRed);
75 histo2 -> SetLineColor(kBlue);
76 if(!histo1->GetEntries() || !histo2 -> GetEntries()){
77 AliError("Probability histos empty !");
80 if(histo1->GetNbinsX() != histo2->GetNbinsX()){
81 AliError(Form("Electron probability discretized differently from pions [%d %d] !", histo1->GetNbinsX(), histo2->GetNbinsX()));
84 histo1 -> Scale(1./histo1->GetEntries());
85 histo2 -> Scale(1./histo2->GetEntries());
87 // array of the integrated sum in each bin
88 Double_t sumElecE[kBins+2], sumPionsE[kBins+2];
89 memset(sumElecE, 0, (kBins+2)*sizeof(Double_t));
90 memset(sumPionsE, 0, (kBins+2)*sizeof(Double_t));
92 Int_t nbinE(histo1->GetNbinsX()),
96 // calculate electron efficiency for each bin
97 // and also integral distribution
98 for(Bool_t bFirst(kTRUE); abinE--;){
99 sumElecE[abinE] = sumElecE[abinE+1] + histo1->GetBinContent(abinE+1);
100 if((sumElecE[abinE] >= fgEleEffi) && bFirst){
102 fCalcEleEffi = sumElecE[cbinE];
106 fThreshold = histo1->GetBinCenter(cbinE);
108 // calculate pion efficiency of each bin
109 // and also integral distribution
111 sumPionsE[bbinE] = sumPionsE[bbinE+1] + histo2->GetBinContent(bbinE+1);
112 if(bbinE == cbinE) fPionEffi = sumPionsE[cbinE];
116 // pion efficiency vs electron efficiency
117 TGraph gEffis(nbinE, sumElecE, sumPionsE);
119 // use fit function to get derivate of the TGraph for error calculation
120 TF1 f1("f1","[0]*x*x+[1]*x+[2]", fgEleEffi-.05, fgEleEffi+.05);
121 gEffis.Fit(&f1, "Q", "", fgEleEffi-.05, fgEleEffi+.05);
123 // return the error of the pion efficiency
124 if(((1.-fPionEffi) < 0) || ((1.-fCalcEleEffi) < 0)){
125 AliError(" EleEffi or PioEffi > 1. Error can not be calculated. Please increase statistics or check your simulation!");
128 fError = sqrt(((1/histo2 -> GetEntries())*fPionEffi*(1-fPionEffi))+((f1.Derivative(fgEleEffi))*(f1.Derivative(fgEleEffi))*(1/histo1 -> GetEntries())*fCalcEleEffi*(1-fCalcEleEffi)));
130 AliDebug(2, Form("Pion Effi at [%f] : [%f +/- %f], Threshold[%f]", fCalcEleEffi, fPionEffi, fError, fThreshold));
131 AliDebug(2, Form("Derivative at %4.2f : %f\n", fgEleEffi, f1.Derivative(fgEleEffi)));
136 //__________________________________________________________________________
137 Int_t AliTRDpidUtil::GetMomentumBin(Double_t p)
140 // returns the momentum bin for a given momentum
143 Int_t pBin1 = -1; // check bin1
144 Int_t pBin2 = -1; // check bin2
146 if(p < 0) return -1; // return -1 if momentum < 0
147 if(p < AliTRDCalPID::GetMomentum(0)) return 0; // smallest momentum bin
148 if(p >= AliTRDCalPID::GetMomentum(AliTRDCalPID::kNMom-1)) return AliTRDCalPID::kNMom-1; // largest momentum bin
151 // calculate momentum bin for non extremal momenta
152 for(Int_t iMomBin = 1; iMomBin < AliTRDCalPID::kNMom; iMomBin++){
153 if(p < AliTRDCalPID::GetMomentum(iMomBin)){
160 if(p - AliTRDCalPID::GetMomentum(pBin1) >= AliTRDCalPID::GetMomentum(pBin2) - p){
172 //__________________________________________________________________________
173 Bool_t AliTRDpidUtil::IsElectron(const AliESDtrack *track, ETRDPIDMethod method){
175 // Do PID decision for the TRD based on 90% Electron efficiency threshold
177 // Author: Markus Fasel (M.Fasel@gsi.de)
179 if(method == kESD) method = kNN;
180 TString histname[2] = {"fHistThreshLQ", "fHistThreshNN"};
181 AliCDBManager *cdb = AliCDBManager::Instance();
182 AliCDBEntry *cdbThresholds = cdb->Get("TRD/Calib/PIDThresholds");
183 if (!cdbThresholds) return kFALSE;
184 TObjArray *histos = dynamic_cast<TObjArray *>(cdbThresholds->GetObject());
185 if (!histos) return kFALSE;
186 TH1 *thresholdHist = dynamic_cast<TH1F *>(histos->FindObject(histname[method].Data()));
187 if (!thresholdHist) return kFALSE;
188 Double_t threshold = thresholdHist->GetBinContent(GetMomentumBin(track->P()) + 1);
191 Double_t pidProbs[5];
192 track->GetTRDpid(pidProbs);
193 if(pidProbs[AliPID::kElectron] >= threshold) return kTRUE;
197 //__________________________________________________________________________
198 Double_t AliTRDpidUtil::GetSystematicError(const AliESDtrack *track, ETRDPIDMethod method){
200 // Returns the pion efficiency at 90% electron efficiency from the OCDB
202 // Author: Markus Fasel (M.Fasel@gsi.de)
204 if(method == kESD) method = kNN;
205 TString histname[2] = {"fHistPionEffLQ", "fHistPionEffNN"};
206 AliCDBManager *cdb = AliCDBManager::Instance();
207 AliCDBEntry *cdbThresholds = cdb->Get("TRD/Calib/PIDThresholds");
208 if (!cdbThresholds) return kFALSE;
209 TObjArray *histos = dynamic_cast<TObjArray *>(cdbThresholds->GetObject());
210 if (!histos) return kFALSE;
211 TH1 *thresholdHist = dynamic_cast<TH1F *>(histos->FindObject(histname[method].Data()));
212 if (!thresholdHist) return kFALSE;
213 return thresholdHist->GetBinContent(GetMomentumBin(track->P()) + 1);
216 //________________________________________________________________________
217 Int_t AliTRDpidUtil::Pdg2Pid(Int_t pdg){
219 // Private Helper function to get the paticle species (ALICE notation)
223 switch(TMath::Abs(pdg)){
225 species = AliPID::kElectron;
228 species = AliPID::kMuon;
231 species = AliPID::kPion;
234 species = AliPID::kKaon;
237 species = AliPID::kProton;
245 //________________________________________________________________________
246 Int_t AliTRDpidUtil::Mass2Pid(Float_t m){
248 // Private Helper function to get the paticle species (ALICE notation)
252 for(Int_t is(0); is<AliPID::kSPECIES; is++) if(TMath::Abs(m-AliPID::ParticleMass(is))<1.e-4) return is;