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>
30 #include <TObjArray.h>
31 #include <TObjString.h>
34 #include "AliAODpidUtil.h"
35 #include "AliESDpid.h"
38 #include "AliVParticle.h"
40 #include "AliHFEcontainer.h"
41 #include "AliHFEpid.h"
42 #include "AliHFEpidBase.h"
43 #include "AliHFEpidQAmanager.h"
44 #include "AliHFEpidITS.h"
45 #include "AliHFEpidTPC.h"
46 #include "AliHFEpidTRD.h"
47 #include "AliHFEpidTOF.h"
48 #include "AliHFEpidMC.h"
49 #include "AliHFEvarManager.h"
53 const Char_t* AliHFEpid::fgkDetectorName[AliHFEpid::kNdetectorPID + 1] = {
63 //____________________________________________________________
64 AliHFEpid::AliHFEpid():
72 // Default constructor
74 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
75 memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
76 memset(fDetectorOrder, 0, sizeof(UInt_t) * kNdetectorPID);
79 //____________________________________________________________
80 AliHFEpid::AliHFEpid(const Char_t *name):
88 // Default constructor
89 // Create PID objects for all detectors
91 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
92 memset(fDetectorOrder, kUndefined, sizeof(UInt_t) * kNdetectorPID);
93 memset(fSortedOrder, 0, sizeof(UInt_t) * kNdetectorPID);
95 fDetectorPID[kMCpid] = new AliHFEpidMC("MCPID");
96 fDetectorPID[kTPCpid] = new AliHFEpidTPC("TPCPID");
97 fDetectorPID[kTRDpid] = new AliHFEpidTRD("TRDPID");
98 fDetectorPID[kTOFpid] = new AliHFEpidTOF("TOFPID");
102 //____________________________________________________________
103 AliHFEpid::AliHFEpid(const AliHFEpid &c):
105 fEnabledDetectors(c.fEnabledDetectors),
106 fNPIDdetectors(c.fNPIDdetectors),
107 fVarManager(c.fVarManager),
113 memset(fDetectorPID, 0, sizeof(AliHFEpidBase *) * kNdetectorPID);
117 //____________________________________________________________
118 AliHFEpid& AliHFEpid::operator=(const AliHFEpid &c){
120 // Assignment operator
122 if(&c != this) c.Copy(*this);
126 //____________________________________________________________
127 AliHFEpid::~AliHFEpid(){
131 for(Int_t idet = 0; idet < kNdetectorPID; idet++)
132 if(fDetectorPID[idet]) delete fDetectorPID[idet];
133 ClearCommonObjects();
136 //____________________________________________________________
137 void AliHFEpid::Copy(TObject &o) const{
143 AliHFEpid &target = dynamic_cast<AliHFEpid &>(o);
144 target.ClearCommonObjects();
146 target.fEnabledDetectors = fEnabledDetectors;
147 target.fNPIDdetectors = fNPIDdetectors;
148 target.fVarManager = fVarManager;
150 // Copy detector PIDs
151 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
152 //Cleanup pointers in case of assignment
153 if(target.fDetectorPID[idet])
154 delete target.fDetectorPID[idet];
155 if(fDetectorPID[idet])
156 target.fDetectorPID[idet] = dynamic_cast<AliHFEpidBase *>(fDetectorPID[idet]->Clone());
158 memcpy(target.fDetectorOrder, fDetectorOrder, sizeof(UInt_t) * kNdetectorPID);
159 memcpy(target.fSortedOrder, fSortedOrder, sizeof(UInt_t) * kNdetectorPID);
162 //____________________________________________________________
163 void AliHFEpid::AddCommonObject(TObject * const o){
165 // Add common object to the garbage collection
167 if(!fCommonObjects) fCommonObjects = new TObjArray;
168 fCommonObjects->Add(o);
171 //____________________________________________________________
172 void AliHFEpid::ClearCommonObjects(){
174 // empty garbage collection
177 fCommonObjects->Delete();
178 delete fCommonObjects;
179 fCommonObjects = NULL;
183 //____________________________________________________________
184 void AliHFEpid::AddDetector(TString detector, UInt_t position){
186 // Add Detector in position
188 UInt_t detectorID = kUndefined;
190 if(!detector.CompareTo("MC")) detectorID = kMCpid;
191 else if(!detector.CompareTo("TPC")) detectorID = kTPCpid;
192 else if(!detector.CompareTo("TRD")) detectorID = kTRDpid;
193 else if(!detector.CompareTo("TOF")) detectorID = kTOFpid;
194 else AliError("Detector not available");
196 if(detectorID == kUndefined) return;
197 if(IsDetectorOn(detectorID)) return;
198 SwitchOnDetector(detectorID);
199 fDetectorOrder[detectorID] = position;
203 //____________________________________________________________
204 Bool_t AliHFEpid::InitializePID(){
206 // Initializes the PID object
209 TMath::Sort(static_cast<UInt_t>(kNdetectorPID), fDetectorOrder, fSortedOrder, kFALSE);
210 // Initialize PID Objects
211 Bool_t status = kTRUE;
212 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
213 if(!IsDetectorOn(idet)) continue;
214 if(fDetectorPID[idet]){
215 status &= fDetectorPID[idet]->InitializePID();
216 if(HasMCData() && status) fDetectorPID[idet]->SetHasMCData();
223 //____________________________________________________________
224 Bool_t AliHFEpid::IsSelected(AliHFEpidObject *track, AliHFEcontainer *cont, const Char_t *contname, AliHFEpidQAmanager *pidqa){
228 Bool_t isSelected = kTRUE;
229 AliDebug(1, Form("Particle used for PID, QA available: %s", pidqa ? "Yes" : "No"));
230 for(UInt_t idet = 0; idet < fNPIDdetectors; idet++){
231 AliDebug(2, Form("Using Detector %s\n", SortedDetectorName(idet)));
232 if(TMath::Abs(fDetectorPID[fSortedOrder[idet]]->IsSelected(track, pidqa)) != 11){
236 AliDebug(2, "Particlae selected by detector");
237 if(fVarManager && cont){
238 Char_t reccontname[256];
239 sprintf(reccontname, "%sReco", contname);
240 AliDebug(2, Form("Filling container %s", reccontname));
241 if(fVarManager->IsSignalTrack())
242 fVarManager->FillContainerStepname(cont, reccontname, SortedDetectorName(idet));
244 Char_t mccontname[256];
245 sprintf(mccontname, "%sMC", contname);
246 AliDebug(2, Form("MC Information available, Filling container %s", mccontname));
247 if(fVarManager->IsSignalTrack())
248 fVarManager->FillContainerStepname(cont, mccontname, SortedDetectorName(idet), kTRUE);
250 // The PID will NOT fill the double counting information
256 //____________________________________________________________
257 void AliHFEpid::SetESDpid(AliESDpid *pid){
259 // Set ESD PID to the Detector PID objects
261 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
262 if(fDetectorPID[idet]) fDetectorPID[idet]->SetESDpid(pid);
266 //____________________________________________________________
267 void AliHFEpid::SetAODpid(AliAODpidUtil *pid){
269 // Set ESD PID to the Detector PID objects
271 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
272 if(fDetectorPID[idet]) fDetectorPID[idet]->SetAODpid(pid);
276 //____________________________________________________________
277 void AliHFEpid::ConfigureTPCasymmetric(Double_t pmin, Double_t pmax, Double_t sigmamin, Double_t sigmamax){
279 // 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
281 AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
282 pid->SetTPCnSigma(3);
283 pid->SetAsymmetricTPCsigmaCut(pmin, pmax, sigmamin, sigmamax);
286 //____________________________________________________________
287 void AliHFEpid::ConfigureTPCrejectionSimple(){
289 // TPC alone, symmetric 3 sigma cut and 2 - -100 sigma pion rejection
291 AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
292 pid->SetTPCnSigma(3);
293 pid->SetRejectParticle(AliPID::kPion, 0., -100., 10., 1.);
296 //____________________________________________________________
297 void AliHFEpid::ConfigureTPCrejection(){
299 // Combined TPC-TOF PID, combination is discribed in the funtion MakePidTpcTof
301 if(HasMCData()) printf("Configuring TPC for MC\n");
302 AliHFEpidTPC *tpcpid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
303 AliHFEpidTOF *tofpid = dynamic_cast<AliHFEpidTOF *>(fDetectorPID[kTOFpid]);
304 tpcpid->SetTPCnSigma(2);
305 tofpid->SetTOFnSigma(3);
307 //TF1 *upperCut = new TF1("upperCut", "[0] * TMath::Exp([1]*x)", 0, 20);
308 TF1 *upperCut = new TF1("upperCut", "[0]", 0, 20); // Use constant upper cut
309 TF1 *lowerCut = new TF1("lowerCut", "[0] * TMath::Exp([1]*x) + [2]", 0, 20);
310 upperCut->SetParameter(0, 3.);
311 //upperCut->SetParameter(0, 2.7);
312 //upperCut->SetParameter(1, -0.4357);
314 if(HasMCData()) lowerCut->SetParameter(0, -2.5);
315 else lowerCut->SetParameter(0, -3.7);
317 lowerCut->SetParameter(1, -0.8);
319 if(HasMCData()) lowerCut->SetParameter(2, -2.2);
320 else lowerCut->SetParameter(2, -0.35);
322 tpcpid->SetUpperSigmaCut(upperCut);
323 tpcpid->SetLowerSigmaCut(lowerCut);
324 AddCommonObject(upperCut);
325 AddCommonObject(lowerCut);
328 //____________________________________________________________
329 void AliHFEpid::ConfigureTPCstrategyParis(){
331 // TPC alone, symmetric 3 sigma cut and 2 - -100 sigma pion rejection
333 AliHFEpidTPC *pid = dynamic_cast<AliHFEpidTPC *>(fDetectorPID[kTPCpid]);
334 pid->SetTPCnSigma(2);
335 pid->SetRejectParticle(AliPID::kProton, 0., -3., 10., 3.);
336 pid->SetRejectParticle(AliPID::kKaon, 0., -3., 10., 3.);
339 //____________________________________________________________
340 void AliHFEpid::PrintStatus() const {
342 // Print the PID configuration
344 printf("\n%s: Printing configuration\n", GetName());
345 printf("===============================================\n");
346 printf("PID Detectors: \n");
348 TString detectors[kNdetectorPID] = {"MC", "ESD", "ITS", "TPC", "TRD", "TOF"};
349 for(Int_t idet = 0; idet < kNdetectorPID; idet++){
350 if(IsDetectorOn(idet)){
351 printf("\t%s\n", detectors[idet].Data());
355 if(!npid) printf("\tNone\n");