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 **************************************************************************/
17 // Interface to the user task
18 // Several strategies for Electron identification implemented.
19 // In addition users can combine different detectors or use
20 // single detector PID
23 // Markus Fasel <M.Fasel@gsi.de>
28 #include <TIterator.h>
31 #include <TObjArray.h>
32 #include <TObjString.h>
37 #include "AliVParticle.h"
39 #include "AliHFEcontainer.h"
40 #include "AliHFEpid.h"
41 #include "AliHFEpidQAmanager.h"
42 #include "AliHFEpidITS.h"
43 #include "AliHFEpidTPC.h"
44 #include "AliHFEpidTRD.h"
45 #include "AliHFEpidTOF.h"
46 #include "AliHFEpidEMCAL.h"
47 #include "AliHFEpidMC.h"
48 #include "AliHFEpidBayes.h"
49 #include "AliHFEvarManager.h"
53 const Char_t* AliHFEpid::fgkDetectorName[AliHFEpid::kNdetectorPID + 1] = {
64 //____________________________________________________________
65 AliHFEpid::AliHFEpid():
73 // Default constructor
75 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
76 memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
77 memset(fSortedOrder, 0, sizeof(UInt_t) * kNdetectorPID);
80 //____________________________________________________________
81 AliHFEpid::AliHFEpid(const Char_t *name):
89 // Default constructor
90 // Create PID objects for all detectors
92 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
93 memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
94 memset(fSortedOrder, 0, sizeof(UInt_t) * kNdetectorPID);
96 fDetectorPID[kMCpid] = new AliHFEpidMC("MCPID");
97 fDetectorPID[kBAYESpid] = new AliHFEpidBayes("BAYESPID");
98 fDetectorPID[kTPCpid] = new AliHFEpidTPC("TPCPID");
99 fDetectorPID[kTRDpid] = new AliHFEpidTRD("TRDPID");
100 fDetectorPID[kTOFpid] = new AliHFEpidTOF("TOFPID");
101 fDetectorPID[kEMCALpid] = new AliHFEpidEMCAL("EMCALPID");
105 //____________________________________________________________
106 AliHFEpid::AliHFEpid(const AliHFEpid &c):
108 fEnabledDetectors(c.fEnabledDetectors),
109 fNPIDdetectors(c.fNPIDdetectors),
110 fVarManager(c.fVarManager),
116 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
120 //____________________________________________________________
121 AliHFEpid& AliHFEpid::operator=(const AliHFEpid &c){
123 // Assignment operator
125 if(&c != this) c.Copy(*this);
129 //____________________________________________________________
130 AliHFEpid::~AliHFEpid(){
134 for(Int_t idet = 0; idet < kNdetectorPID; idet++)
135 if(fDetectorPID[idet]) delete fDetectorPID[idet];
136 ClearCommonObjects();
139 //____________________________________________________________
140 void AliHFEpid::Copy(TObject &o) const{
146 AliHFEpid &target = dynamic_cast<AliHFEpid &>(o);
147 target.ClearCommonObjects();
149 target.fEnabledDetectors = fEnabledDetectors;
150 target.fNPIDdetectors = fNPIDdetectors;
151 target.fVarManager = fVarManager;
153 // Copy detector PIDs
154 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
155 //Cleanup pointers in case of assignment
156 if(target.fDetectorPID[idet])
157 delete target.fDetectorPID[idet];
158 if(fDetectorPID[idet])
159 target.fDetectorPID[idet] = dynamic_cast<AliHFEpidBase *>(fDetectorPID[idet]->Clone());
161 memcpy(target.fDetectorOrder, fDetectorOrder, sizeof(UInt_t) * kNdetectorPID);
162 memcpy(target.fSortedOrder, fSortedOrder, sizeof(UInt_t) * kNdetectorPID);
165 //____________________________________________________________
166 void AliHFEpid::AddCommonObject(TObject * const o){
168 // Add common object to the garbage collection
170 if(!fCommonObjects) fCommonObjects = new TObjArray;
171 fCommonObjects->Add(o);
174 //____________________________________________________________
175 void AliHFEpid::ClearCommonObjects(){
177 // empty garbage collection
180 fCommonObjects->Delete();
181 delete fCommonObjects;
182 fCommonObjects = NULL;
186 //____________________________________________________________
187 void AliHFEpid::AddDetector(TString detector, UInt_t position){
189 // Add Detector in position
191 UInt_t detectorID = kUndefined;
193 if(!detector.CompareTo("MC")) detectorID = kMCpid;
194 else if(!detector.CompareTo("BAYES")) detectorID = kBAYESpid;
195 else if(!detector.CompareTo("TPC")) detectorID = kTPCpid;
196 else if(!detector.CompareTo("TRD")) detectorID = kTRDpid;
197 else if(!detector.CompareTo("TOF")) detectorID = kTOFpid;
198 else if(!detector.CompareTo("EMCAL")) detectorID = kEMCALpid;
199 else AliError("Detector not available");
201 if(detectorID == kUndefined) return;
202 if(IsDetectorOn(detectorID)) return;
203 SwitchOnDetector(detectorID);
204 fDetectorOrder[detectorID] = position;
208 //____________________________________________________________
209 Bool_t AliHFEpid::InitializePID(Int_t run){
211 // Initializes the PID object
214 if(!TestBit(kDetectorsSorted)) SortDetectors();
215 Bool_t status = kTRUE;
216 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
217 if(!IsDetectorOn(idet)) continue;
218 if(fDetectorPID[idet]){
219 status &= fDetectorPID[idet]->InitializePID(run);
220 if(HasMCData() && status) fDetectorPID[idet]->SetHasMCData();
228 //____________________________________________________________
229 Bool_t AliHFEpid::IsSelected(const AliHFEpidObject * const track, AliHFEcontainer *cont, const Char_t *contname, AliHFEpidQAmanager *pidqa){
233 Bool_t isSelected = kTRUE;
234 AliDebug(1, Form("Particle used for PID, QA available: %s", pidqa ? "Yes" : "No"));
235 for(UInt_t idet = 0; idet < fNPIDdetectors; idet++){
236 AliDebug(2, Form("Using Detector %s\n", SortedDetectorName(idet)));
237 if(TMath::Abs(fDetectorPID[fSortedOrder[idet]]->IsSelected(track, pidqa)) != 11){
241 AliDebug(2, "Particlae selected by detector");
242 if(fVarManager && cont){
243 TString reccontname = contname; reccontname += "Reco";
244 AliDebug(2, Form("Filling container %s", reccontname.Data()));
245 if(fVarManager->IsSignalTrack())
246 fVarManager->FillContainerStepname(cont, reccontname.Data(), SortedDetectorName(idet));
248 TString mccontname = contname; mccontname += "MC";
249 AliDebug(2, Form("MC Information available, Filling container %s", mccontname.Data()));
250 if(fVarManager->IsSignalTrack()) {
251 fVarManager->FillContainerStepname(cont, mccontname.Data(), SortedDetectorName(idet), kTRUE);
252 if(cont->GetCorrelationMatrix("correlationstepafterTOF")){
253 TString tstept("TOFPID");
254 if(!tstept.CompareTo(SortedDetectorName(idet))) {
255 fVarManager->FillCorrelationMatrix(cont->GetCorrelationMatrix("correlationstepafterTOF"));
256 //printf("Step %s\n",(const char*) SortedDetectorName(idet));
261 // The PID will NOT fill the double counting information
267 //____________________________________________________________
268 void AliHFEpid::SortDetectors(){
270 // Make sorted list of detectors
272 if(TestBit(kDetectorsSorted)) return; // Don't sort detectors when they are already sorted
273 TMath::Sort(static_cast<UInt_t>(kNdetectorPID), fDetectorOrder, fSortedOrder, kFALSE);
274 SetBit(kDetectorsSorted);
277 //____________________________________________________________
278 void AliHFEpid::SetPIDResponse(const AliPIDResponse * const pid){
280 // Set ESD PID to the Detector PID objects
282 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
283 if(fDetectorPID[idet]) fDetectorPID[idet]->SetPIDResponse(pid);
287 //____________________________________________________________
288 const AliPIDResponse *AliHFEpid::GetPIDResponse() const {
290 // Return PID response function
292 const AliPIDResponse *response = NULL;
293 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
294 if(fDetectorPID[idet]){
295 response = fDetectorPID[idet]->GetPIDResponse();
302 //____________________________________________________________
303 void AliHFEpid::ConfigureTPCasymmetric(Double_t pmin, Double_t pmax, Double_t sigmamin, Double_t sigmamax){
305 // TPC alone, symmetric 3 sigma cut and asymmetric sigma cut in the momentum region between 2GeV/c and 10 GeV/c and sigma between -1 and 100
307 AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
309 pid->SetTPCnSigma(3);
310 pid->SetAsymmetricTPCsigmaCut(pmin, pmax, sigmamin, sigmamax);
314 //____________________________________________________________
315 void AliHFEpid::ConfigureTPCrejectionSimple(){
317 // TPC alone, symmetric 3 sigma cut and 2 - -100 sigma pion rejection
319 AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
321 pid->SetTPCnSigma(3);
322 pid->SetRejectParticle(AliPID::kPion, 0., -100., 10., 1.);
326 //____________________________________________________________
327 void AliHFEpid::ConfigureTOF(Float_t TOFCut){
329 // Set Number of sigmas for TOF PID
331 AliHFEpidTOF *tofpid = dynamic_cast<AliHFEpidTOF *>(fDetectorPID[kTOFpid]);
332 if(tofpid) tofpid->SetTOFnSigma(TOFCut);
335 //____________________________________________________________
336 void AliHFEpid::ConfigureTPCcentralityCut(Int_t centralityBin, const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
338 // Cofigure centrality dependent cut function for TPC PID
340 ConfigureTPCcut(centralityBin, lowerCutParam, params, upperTPCCut);
343 //____________________________________________________________
344 void AliHFEpid::ConfigureTPCdefaultCut(const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
346 // Cofigure default cut function for TPC PID
348 ConfigureTPCcut(-1, lowerCutParam, params, upperTPCCut);
351 //____________________________________________________________
352 void AliHFEpid::ConfigureTPCcut(Int_t centralityBin, const char *lowerCutParam, const Double_t * const params, Float_t upperTPCCut){
354 // Cofigure cut function for TPC PID
355 // if no function parameterizaion is given, then the default one (exponential) is chosen
358 if(HasMCData()) AliInfo("Configuring TPC for MC\n");
359 AliHFEpidTPC *tpcpid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
360 //TF1 *upperCut = new TF1("upperCut", "[0] * TMath::Exp([1]*x)", 0, 20);
361 TF1 *upperCut = new TF1(Form("upperCut%s", centralityBin < 0 ? "Default" : Form("Bin%d", centralityBin)), "[0]", 0, 20); // Use constant upper cut
362 TF1 *lowerCut = new TF1(Form("lowerCut%s", centralityBin < 0 ? "Default" : Form("Bin%d", centralityBin)), lowerCutParam == NULL ? "[0] * TMath::Exp([1]*x) + [2]": lowerCutParam, 0, 20);
364 upperCut->SetParameter(0, upperTPCCut); // pp
367 for(Int_t ipar = 0; ipar < lowerCut->GetNpar(); ipar++)
369 lowerCut->SetParameter(ipar, params[ipar]);
370 // printf("printout %i %s %f \n", centralityBin, lowerCutParam, params[ipar]);
373 // Set default parameterization
374 if(HasMCData()) lowerCut->SetParameter(0, -2.5);
375 else lowerCut->SetParameter(0, -4.03); //pp
376 lowerCut->SetParameter(1, -0.22); // pp
378 if(HasMCData()) lowerCut->SetParameter(2, -2.2);
379 else lowerCut->SetParameter(2, 0.92); //pp
384 tpcpid->SetTPCnSigma(2);
385 if(centralityBin < 0){
386 tpcpid->SetUpperSigmaCutDefault(upperCut);
387 tpcpid->SetLowerSigmaCutDefault(lowerCut);
389 tpcpid->SetUpperSigmaCutCentrality(upperCut, centralityBin);
390 tpcpid->SetLowerSigmaCutCentrality(lowerCut, centralityBin);
393 AddCommonObject(upperCut);
394 AddCommonObject(lowerCut);
397 //____________________________________________________________
398 void AliHFEpid::ConfigureBayesDetectorMask(Int_t detmask){
400 // Configure detector mask for Bayes PID
401 // if no detector mask is set the default mask is chosen
404 if(HasMCData()) AliInfo("Configuring Bayes for MC\n");
405 AliHFEpidBayes *bayespid = dynamic_cast<AliHFEpidBayes *>(fDetectorPID[kBAYESpid]);
409 bayespid->SetBayesDetectorMask(detmask);
410 printf("detector mask in pid class %i \n",detmask);
415 //____________________________________________________________
416 void AliHFEpid::ConfigureBayesPIDThreshold(Float_t pidthres){
418 // Configure pid threshold for Bayes PID
419 // if no threshold is set the default threshold is chosen
422 if(HasMCData()) AliInfo("Configuring Bayes for MC\n");
423 AliHFEpidBayes *bayespid = dynamic_cast<AliHFEpidBayes *>(fDetectorPID[kBAYESpid]);
427 bayespid->SetBayesPIDThreshold(pidthres);
428 printf("combined pidthreshold %f \n",pidthres);
433 //____________________________________________________________
434 void AliHFEpid::PrintStatus() const {
436 // Print the PID configuration
438 printf("\n%s: Printing configuration\n", GetName());
439 printf("===============================================\n");
440 printf("PID Detectors: \n");
442 TString detectors[kNdetectorPID] = {"MC", "BAYES", "ITS", "TPC", "TRD", "TOF", "EMCAL"};
443 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
444 if(IsDetectorOn(idet)){
445 printf("\t%s\n", detectors[idet].Data());
449 if(!npid) printf("\tNone\n");