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 // the tree is represented as reduced events
20 // M.Fasel <M.Fasel@gsi.de>
26 #include <TParticle.h>
30 #include "AliAnalysisManager.h"
31 #include "AliAODMCHeader.h"
32 #include "AliAnalysisUtils.h"
33 #include "AliCentrality.h"
34 #include "AliESDEvent.h"
35 #include "AliESDtrack.h"
36 #include "AliESDVertex.h"
37 #include "AliInputEventHandler.h"
38 #include "AliHFEcuts.h"
39 #include "AliHFEextraCuts.h"
40 #include "AliHFEpidTPC.h"
41 #include "AliHFEreducedEvent.h"
42 #include "AliHFEreducedTrack.h"
43 #include "AliHFEreducedMCParticle.h"
44 #include "AliHFEsignalCuts.h"
46 #include "AliMCEvent.h"
47 #include "AliMCParticle.h"
48 #include "AliMCEventHandler.h"
49 #include "AliMultiplicity.h"
50 #include "AliPIDResponse.h"
51 #include "AliVEvent.h"
52 #include "AliVTrack.h"
53 #include "AliVCluster.h"
54 #include "AliVVZERO.h"
56 #include "AliTRDTriggerAnalysis.h"
57 #include "TTreeStream.h"
59 #include "AliHFEreducedEventCreatorESD.h"
61 ClassImp(AliHFEreducedEventCreatorESD)
63 AliHFEreducedEventCreatorESD::AliHFEreducedEventCreatorESD():
72 fTRDTriggerAnalysis(NULL),
77 fRemoveFirstEvent(kFALSE)
80 // Default constructor
84 AliHFEreducedEventCreatorESD::AliHFEreducedEventCreatorESD(const char *name):
85 AliAnalysisTaskSE(name),
93 fTRDTriggerAnalysis(NULL),
98 fRemoveFirstEvent(kFALSE)
101 // Default constructor
103 fTPCpid = new AliHFEpidTPC("QAtpcPID");
104 fAnalysisUtils = new AliAnalysisUtils;
105 fTRDTriggerAnalysis = new AliTRDTriggerAnalysis();
106 fTRDTriggerAnalysis->SetRequireMatchElectron(kTRUE);
107 DefineOutput(1, TTree::Class());
110 AliHFEreducedEventCreatorESD::~AliHFEreducedEventCreatorESD(){
112 // Default destructor
114 if(fAnalysisUtils) delete fAnalysisUtils;
115 if(fTPCpid) delete fTPCpid;
116 if(fTRDTriggerAnalysis) delete fTRDTriggerAnalysis;
117 if(fHFEevent) delete fHFEevent;
118 if(fSignalCuts) delete fSignalCuts;
119 if(fTrackCuts) delete fTrackCuts;
123 void AliHFEreducedEventCreatorESD::UserCreateOutputObjects(){
125 // Create debug tree, signal cuts and track cuts
130 // printf("testa\n");
131 fSignalCuts = new AliHFEsignalCuts("HFEsignalCuts", "HFE MC Signal definition");
134 fTrackCuts = new AliHFEcuts("fTrackCuts", "Basic HFE track cuts");
135 fTrackCuts->CreateStandardCuts();
137 fTrackCuts->SetMaxChi2perClusterTPC(1000.); // switch off this cut (for the moment);
138 fTrackCuts->SetMinNClustersTPC(fNclustersTPC);
139 fTrackCuts->SetMinRatioTPCclusters(0);
140 fTrackCuts->SetTPCmodes(AliHFEextraCuts::kFound, AliHFEextraCuts::kFoundOverFindable);
141 fTrackCuts->SetMinNClustersTPCPID(fNclustersTPCPID);
142 fTrackCuts->SetMinNClustersITS(fNclustersITS);
144 fTrackCuts->SetUseMixedVertex(kTRUE);
145 fTrackCuts->SetVertexRange(10.);
147 fTrackCuts->Initialize();
150 fExtraCuts = new AliHFEextraCuts("hfeExtraCuts","HFE Extra Cuts");
152 fHFEevent = new AliHFEreducedEvent;
154 fHFEtree = new TTree("HFEtree", "HFE event tree");
155 fHFEtree->Branch("HFEevent", "AliHFEreducedEvent", fHFEevent,128000,0);
156 PostData(1, fHFEtree);
159 void AliHFEreducedEventCreatorESD::UserExec(Option_t *){
161 // User Exec: Fill debug Tree
165 AliPIDResponse *pid = NULL;
166 AliInputEventHandler *handler = dynamic_cast<AliInputEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
168 // printf("testb\n");
169 pid = handler->GetPIDResponse();
171 AliError("No Handler");
174 // printf("testc\n");
175 AliError("No PID response");
179 AliError("No Input event");
183 if(fRemoveFirstEvent){
184 if(fAnalysisUtils->IsFirstEventInChunk(fInputEvent)) return;
187 AliDebug(1, "Event Selected");
189 AliESDtrack copyTrack;
192 Bool_t mcthere = dynamic_cast<AliMCEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()) != NULL;
194 fTrackCuts->SetMCEvent(fMCEvent);
195 fSignalCuts->SetMCEvent(fMCEvent);
198 fTrackCuts->SetRecEvent(fInputEvent);
200 if(!fTrackCuts->CheckEventCuts("fCutsEvRec", fInputEvent)){
201 AliDebug(1, "Event rejected by the event cuts\n");
205 // reject pile up in case of pp
206 AliESDEvent *event = dynamic_cast<AliESDEvent *>(fInputEvent);
208 TString beamtype = event->GetBeamType();
209 //printf("beamtype %s\n",(const char*)beamtype);
210 if (strstr(beamtype,"p-p")) {
211 //printf("Reject\n");
212 if(fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5)){
213 AliDebug(1, "Event flagged as pileup\n");
220 fExtraCuts = new AliHFEextraCuts("hfeExtraCuts","HFE Extra Cuts");
222 fExtraCuts->SetRecEventInfo(fInputEvent);
225 // Make Reduced Event
226 //AliHFEreducedEvent hfeevent;
227 fHFEevent->~AliHFEreducedEvent();
228 new(fHFEevent)AliHFEreducedEvent();
231 fHFEevent->SetRunNumber(fInputEvent->GetRunNumber());
234 UInt_t trigger = fInputHandler->IsEventSelected();
235 if(trigger & AliVEvent::kMB) fHFEevent->SetMBTrigger();
236 if((trigger & AliVEvent::kINT7)||(trigger & AliVEvent::kINT8)) fHFEevent->SetINTTrigger();
237 if(trigger & AliVEvent::kCentral) fHFEevent->SetCentralTrigger();
238 if(trigger & AliVEvent::kSemiCentral) fHFEevent->SetCentralTrigger();
239 if(trigger & AliVEvent::kEMCEJE) fHFEevent->SetEMCALTrigger();
241 fTRDTriggerAnalysis->CalcTriggers(event);
242 if(fTRDTriggerAnalysis->HasTriggeredConfirmed(AliTRDTriggerAnalysis::kHSE)) fHFEevent->SetTRDSETrigger();
243 if(fTRDTriggerAnalysis->HasTriggeredConfirmed(AliTRDTriggerAnalysis::kHQU)) fHFEevent->SetTRDDQTrigger();
245 // Get Primary Vertex
246 const AliVVertex *vertex = fInputEvent->GetPrimaryVertex();
249 fHFEevent->SetVX(vtx[0]);
250 fHFEevent->SetVY(vtx[1]);
251 fHFEevent->SetVZ(vtx[2]);
252 Int_t ncontrib(vertex->GetNContributors());
253 fHFEevent->SetNContribVertex(ncontrib);
255 vertex->GetCovarianceMatrix(vcov);
256 fHFEevent->SetVertexResolution(TMath::Sqrt(vcov[5]));
257 // Get Primary Vertex from SPD
258 const AliVVertex *vertexSPD = event->GetPrimaryVertexSPD();
260 memset(vtx, 0, sizeof(Double_t) *3);
261 vertexSPD->GetXYZ(vtx);
262 fHFEevent->SetVXSPD(vtx[0]);
263 fHFEevent->SetVYSPD(vtx[1]);
264 fHFEevent->SetVZSPD(vtx[2]);
265 fHFEevent->SetNContribVertexSPD(vertexSPD->GetNContributors());
266 memset(vcov, 0, sizeof(Double_t)*6);
267 vertex->GetCovarianceMatrix(vcov);
268 fHFEevent->SetVertexResolutionSPD(TMath::Sqrt(vcov[5]));
272 AliCentrality *hicent = fInputEvent->GetCentrality();
273 fHFEevent->SetCentrality(
274 hicent->GetCentralityPercentile("V0M"),
275 hicent->GetCentralityPercentile("V0A"),
276 hicent->GetCentralityPercentile("V0C"),
277 hicent->GetCentralityPercentile("TKL"),
278 hicent->GetCentralityPercentile("TRK"),
279 hicent->GetCentralityPercentile("ZNA"),
280 hicent->GetCentralityPercentile("ZNC"),
281 hicent->GetCentralityPercentile("CL0"),
282 hicent->GetCentralityPercentile("CL1"),
283 hicent->GetCentralityPercentile("CND")
286 // Get VZERO Information
287 AliVVZERO *vzeroinfo = fInputEvent->GetVZEROData();
288 if(vzeroinfo) fHFEevent->SetV0Multiplicity(vzeroinfo->GetMTotV0A(), vzeroinfo->GetMTotV0C());
290 // Get ZDC Information
291 AliVZDC *zdcinfo = fInputEvent->GetZDCData();
292 if(zdcinfo) fHFEevent->SetZDCEnergy(zdcinfo->GetZNAEnergy(), zdcinfo->GetZNCEnergy(), zdcinfo->GetZPAEnergy(), zdcinfo->GetZPCEnergy());
294 // Set SPD multiplicity
295 const AliMultiplicity *mult = event->GetMultiplicity();
296 if(mult) fHFEevent->SetSPDMultiplicity(mult->GetNumberOfTracklets());
299 // Loop on MC tracks only
301 AliMCParticle *mctrack(NULL);
305 for(Int_t itrack = 0; itrack < fMCEvent->GetNumberOfTracks(); itrack++) {
306 mctrack = (AliMCParticle *)(fMCEvent->GetTrack(itrack));
307 if(!mctrack) continue;
308 AliHFEreducedMCParticle hfemcpart;
309 if(!fTrackCuts->CheckParticleCuts(static_cast<UInt_t>(AliHFEcuts::kStepMCGenerated), mctrack)) continue;
310 hfemcpart.SetSignal();
312 hfemcpart.SetSignedPt(mctrack->Pt(), mctrack->Charge() > 0.);
313 hfemcpart.SetP(mctrack->P());
314 hfemcpart.SetEta(mctrack->Eta());
315 hfemcpart.SetPhi(mctrack->Phi());
316 hfemcpart.SetPdg(mctrack->PdgCode());
318 // Get Production Vertex in radial direction
319 hfemcpart.SetProductionVertex(mctrack->Xv(),mctrack->Yv(),mctrack->Zv());
321 // Get Mother PDG code of the particle
322 Int_t motherlabel = TMath::Abs(mctrack->GetMother());
323 if(motherlabel >= 0 && motherlabel < fMCEvent->GetNumberOfTracks()){
324 AliMCParticle *mother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(motherlabel));
325 if(mother) hfemcpart.SetMotherPdg(mother->PdgCode());
330 if(fSignalCuts->IsCharmElectron(mctrack)) source = 0;
331 else if(fSignalCuts->IsBeautyElectron(mctrack)) source = 1;
332 else if(fSignalCuts->IsGammaElectron(mctrack)) source = 2;
333 else if(fSignalCuts->IsNonHFElectron(mctrack)) source = 3;
334 else if(TMath::Abs(mctrack->PdgCode()) == 11) source = 4;
336 hfemcpart.SetSource(source);
338 fHFEevent->AddMCParticle(&hfemcpart);
343 // Loop on reconstructed tracks
345 TArrayI arraytrack(fInputEvent->GetNumberOfTracks());
348 AliESDtrack *track = 0x0;
349 for(Int_t itrack = 0; itrack < fInputEvent->GetNumberOfTracks(); itrack++){
351 track = dynamic_cast<AliESDtrack *>(fInputEvent->GetTrack(itrack));
353 // Cut track (Only basic track cuts)
354 // printf("testv\n");
355 if(!fTrackCuts->CheckParticleCuts(AliHFEcuts::kNcutStepsMCTrack + AliHFEcuts::kStepRecKineITSTPC, track)) continue;
360 AliHFEreducedTrack hfetrack;
361 hfetrack.SetSignedPt(track->Pt(), track->Charge() > 0);
362 hfetrack.SetP(track->P());
363 hfetrack.SetEta(track->Eta());
364 hfetrack.SetPhi(track->Phi());
365 hfetrack.SetTPCmomentum(track->GetTPCmomentum());
368 hfetrack.SetTrackID(track->GetID());
371 ULong_t status = track->GetStatus();
372 if((status & AliVTrack::kITSrefit) == AliVTrack::kITSrefit) hfetrack.SetITSrefit();
373 if((status & AliVTrack::kTPCrefit) == AliVTrack::kTPCrefit) hfetrack.SetTPCrefit();
374 if((status & AliVTrack::kTOFpid) == AliVTrack::kTOFpid) hfetrack.SetTOFpid();
375 //if((status & AliVTrack::kTOFmismatch) == AliVTrack::kTOFmismatch) hfetrack.SetTOFmismatch();
376 if(IsTOFmismatch(track, pid)) hfetrack.SetTOFmismatch(); // New version suggested by Pietro Antonioli
377 Bool_t isEMCAL(kFALSE);
378 Int_t fClsId = track->GetEMCALcluster();
379 if(fClsId >= 0) isEMCAL = kTRUE;
380 AliDebug(2, Form("cluster ID: %d, EMCAL: %s", fClsId, isEMCAL ? "yes" : "no"));
381 if(isEMCAL) hfetrack.SetEMCALpid();
382 // no filter bits available for ESDs
385 AliHFEreducedTrack::EV0PID_t v0pid = AliHFEreducedTrack::kV0undef;
386 if(track->TestBit(BIT(14))) v0pid = AliHFEreducedTrack::kV0electron;
387 else if(track->TestBit(BIT(15))) v0pid = AliHFEreducedTrack::kV0pion;
388 else if(track->TestBit(BIT(16))) v0pid = AliHFEreducedTrack::kV0proton;
389 hfetrack.SetV0PID(v0pid);
392 // Fill Monte-Carlo Information
393 Int_t label = TMath::Abs(track->GetLabel());
394 if(label < fMCEvent->GetNumberOfTracks())
395 mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(label));
397 AliDebug(2, "Associated MC particle found");
398 if(fTrackCuts->CheckParticleCuts(static_cast<UInt_t>(AliHFEcuts::kStepMCGenerated), mctrack)) hfetrack.SetMCSignal();
400 hfetrack.SetMCSignedPt(mctrack->Pt(),mctrack->Charge() > 0.);
401 hfetrack.SetMCP(mctrack->P());
402 hfetrack.SetMCEta(mctrack->Eta());
403 hfetrack.SetMCPhi(mctrack->Phi());
404 hfetrack.SetMCPDG(mctrack->PdgCode());
406 // Get Production Vertex in radial direction
407 hfetrack.SetMCProdVtx(mctrack->Xv(),mctrack->Yv(),mctrack->Zv());
409 // Get Mother PDG code of the particle
410 Int_t motherlabel = TMath::Abs(mctrack->GetMother());
411 if(motherlabel >= 0 && motherlabel < fMCEvent->GetNumberOfTracks()){
412 AliMCParticle *mother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(motherlabel));
413 if(mother) hfetrack.SetMCMotherPdg(mother->PdgCode());
418 if(fSignalCuts->IsCharmElectron(mctrack)) source = 0;
419 else if(fSignalCuts->IsBeautyElectron(mctrack)) source = 1;
420 else if(fSignalCuts->IsGammaElectron(mctrack)) source = 2;
421 else if(fSignalCuts->IsNonHFElectron(mctrack)) source = 3;
422 else if(TMath::Abs(mctrack->PdgCode()) == 11) source = 4;
424 hfetrack.SetMCSource(source);
426 AliDebug(2, "Associated MC particle not found");
431 Float_t dcaxy = -999.,
433 fExtraCuts->GetImpactParameters((AliVTrack *)track,dcaxy,dcaz);
434 hfetrack.SetDCA(dcaxy, dcaz);
435 Double_t hfeImpactParam(-999.), hfeImpactParamResol(-999.);
436 fExtraCuts->GetHFEImpactParameters((AliVTrack *)track,hfeImpactParam,hfeImpactParamResol);
437 hfetrack.SetHFEImpactParam(hfeImpactParam,hfeImpactParamResol);
439 // Different number of clusters definitions
440 Int_t nclustersITS(track->GetITSclusters(NULL)),
441 nclustersTPC(track->GetTPCNcls()),
442 nclustersTPCall(track->GetTPCClusterMap().CountBits()),
443 nclustersTPCshared(0);
444 UChar_t nfindableTPC = track->GetTPCNclsF();
445 const TBits &sharedTPC = track->GetTPCSharedMap();
446 for(Int_t ibit = 0; ibit < 160; ibit++) if(sharedTPC.TestBitNumber(ibit)) nclustersTPCshared++;
447 hfetrack.SetChi2PerTPCcluster(track->GetTPCchi2()/Double_t(nclustersTPC));
448 hfetrack.SetITSnclusters(nclustersITS);
449 hfetrack.SetTPCnclusters(nclustersTPC);
450 hfetrack.SetTRDnclusters(track->GetTRDncls());
451 hfetrack.SetTPCnclustersPID(track->GetTPCsignalN());
452 hfetrack.SetTPCcrossedRows(track->GetTPCCrossedRows());
453 hfetrack.SetTPCnclustersAll(nclustersTPCall);
454 hfetrack.SetTPCsharedClusters(nclustersTPCshared);
455 hfetrack.SetTPCclusterRatio(nfindableTPC ? static_cast<Float_t>(nclustersTPC)/static_cast<Float_t>(nfindableTPC) : 0);
456 hfetrack.SetTPCclusterRatioAll(nfindableTPC ? static_cast<Float_t>(nclustersTPCall)/static_cast<Float_t>(nfindableTPC) : 0);
457 UChar_t itsPixel = track->GetITSClusterMap();
458 for(int ily = 0; ily < 6; ily++)
459 if(TESTBIT(itsPixel, ily)) hfetrack.SetITScluster(ily);
461 // TRD related quantities (Yvonne)
462 Int_t nslices = track->GetNumberOfTRDslices();
463 hfetrack.SetTRDntrackletsPID(track->GetTRDntrackletsPID());
464 hfetrack.SetTRDnslices(nslices);
465 hfetrack.SetTRDchi2(track->GetTRDchi2());
467 for(Int_t iplane = 0; iplane < 6; iplane++){
469 for(Int_t isl = 0; isl < nslices; isl++){
470 if(track->GetTRDntrackletsPID()>0){
471 if(track->GetTRDslice(iplane, isl)>0.001) nslicetemp++;
474 if(nslicetemp > 0) hfetrack.SetTRDstatus(iplane);
478 //test for kink tracks
479 if(fExtraCuts->IsKinkMother(track)) hfetrack.SetIsKinkMother();
480 else if(fExtraCuts->IsKinkDaughter(track)) hfetrack.SetIsKinkDaughter();
483 Int_t id(track->GetID());
484 for(Int_t l=0; l < counterdc; l++){
485 Int_t iTrack2 = arraytrack.At(l);
487 hfetrack.SetDoubleCounted();
491 // Add the id at this place
492 arraytrack.AddAt(id,counterdc);
496 hfetrack.SetTPCdEdx(track->GetTPCsignal());
497 hfetrack.SetTPCsigmaEl(pid->NumberOfSigmasTPC(track, AliPID::kElectron));
498 hfetrack.SetTOFsigmaEl(pid->NumberOfSigmasTOF(track, AliPID::kElectron));
499 hfetrack.SetTOFmismatchProbability(pid->GetTOFMismatchProbability(track));
500 hfetrack.SetITSsigmaEl(pid->NumberOfSigmasITS(track, AliPID::kElectron));
502 copyTrack.~AliESDtrack();
503 new(©Track) AliESDtrack(*track);
504 if(fTPCpid->HasCentralityCorrection()) fTPCpid->ApplyCentralityCorrection(©Track, static_cast<Double_t>(ncontrib),AliHFEpidObject::kESDanalysis);
505 if(fTPCpid->HasEtaCorrection()) fTPCpid->ApplyEtaCorrection(©Track, AliHFEpidObject::kESDanalysis);
506 hfetrack.SetTPCsigmaElCorrected(pid->NumberOfSigmasTPC(©Track, AliPID::kElectron));
507 hfetrack.SetTPCdEdxCorrected(copyTrack.GetTPCsignal());
509 AliDebug(2, "Adding EMCAL PID information");
511 Double_t emcalEnergyOverP = -1.,
512 showershape[4] = {0.,0.,0.,0.};
513 hfetrack.SetEMCALSigmaEl(pid->NumberOfSigmasEMCAL(track, AliPID::kElectron, emcalEnergyOverP, &showershape[0]));
514 hfetrack.SetEMCALEoverP(emcalEnergyOverP);
515 hfetrack.SetEMCALShowerShape(showershape);
518 // Track finished, add NOW to the Event
519 fHFEevent->AddTrack(&hfetrack);
523 // Fill the debug tree
524 //AliInfo(Form("Number of tracks: %d\n", fHFEevent->GetNumberOfTracks()));
525 //AliInfo(Form("Number of MC particles: %d\n", fHFEevent->GetNumberOfMCParticles()));
529 PostData(1, fHFEtree);
532 void AliHFEreducedEventCreatorESD::Terminate(Option_t *){
536 AliInfo("terminating...\n");
540 Bool_t AliHFEreducedEventCreatorESD::IsTOFmismatch(const AliVTrack *const track, const AliPIDResponse *const pid) const {
544 Double_t probs[AliPID::kSPECIESC];
545 AliPIDResponse::EDetPidStatus status = pid->ComputeTOFProbability(track, AliPID::kSPECIESC, probs);
546 return status == AliPIDResponse::kDetMismatch;