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>
29 #include "AliAnalysisManager.h"
30 #include "AliAnalysisUtils.h"
31 #include "AliAODEvent.h"
32 #include "AliAODMCHeader.h"
33 #include "AliAODMCParticle.h"
34 #include "AliAODPid.h"
35 #include "AliAODTrack.h"
36 #include "AliAODTracklets.h"
37 #include "AliAODVertex.h"
38 #include "AliCentrality.h"
39 #include "AliInputEventHandler.h"
40 #include "AliHFEcuts.h"
41 #include "AliHFEextraCuts.h"
42 #include "AliHFEpidTPC.h"
43 #include "AliHFEreducedEvent.h"
44 #include "AliHFEreducedTrack.h"
45 #include "AliHFEreducedMCParticle.h"
46 #include "AliHFEsignalCuts.h"
48 #include "AliMCEvent.h"
49 #include "AliPIDResponse.h"
50 #include "AliVEvent.h"
51 #include "AliVTrack.h"
52 #include "AliVCluster.h"
53 #include "AliVVZERO.h"
55 #include "TTreeStream.h"
57 #include "AliHFEreducedEventCreatorAOD.h"
59 ClassImp(AliHFEreducedEventCreatorAOD)
61 AliHFEreducedEventCreatorAOD::AliHFEreducedEventCreatorAOD():
64 fAODArrayMCInfo(NULL),
77 fRemoveFirstEvent(kFALSE)
80 // Default constructor
84 AliHFEreducedEventCreatorAOD::AliHFEreducedEventCreatorAOD(const char *name):
85 AliAnalysisTaskSE(name),
87 fAODArrayMCInfo(NULL),
100 fRemoveFirstEvent(kFALSE)
103 // Default constructor
105 fTPCpid = new AliHFEpidTPC("QAtpcPID");
106 fAnalysisUtils = new AliAnalysisUtils;
107 DefineOutput(1, TTree::Class());
110 AliHFEreducedEventCreatorAOD::~AliHFEreducedEventCreatorAOD(){
112 // Default destructor
114 if(fTPCpid) delete fTPCpid;
115 if(fAnalysisUtils) delete fAnalysisUtils;
116 if(fHFEevent) delete fHFEevent;
119 void AliHFEreducedEventCreatorAOD::UserCreateOutputObjects(){
121 // Create debug tree, signal cuts and track cuts
126 // printf("testa\n");
127 fSignalCuts = new AliHFEsignalCuts("HFEsignalCuts", "HFE MC Signal definition");
130 fTrackCuts = new AliHFEcuts("fTrackCuts", "Basic HFE track cuts");
131 fTrackCuts->CreateStandardCuts();
132 fTrackCuts->SetAOD();
134 fTrackCuts->SetMinNClustersTPC(fNclustersTPC);
135 fTrackCuts->SetMinRatioTPCclusters(0);
136 fTrackCuts->SetTPCmodes(AliHFEextraCuts::kFound, AliHFEextraCuts::kFoundOverFindable);
137 fTrackCuts->SetMinNClustersTPCPID(fNclustersTPCPID);
138 fTrackCuts->SetMinNClustersITS(fNclustersITS);
140 fTrackCuts->SetUseMixedVertex(kTRUE);
141 fTrackCuts->SetVertexRange(10.);
143 fTrackCuts->Initialize();
146 fExtraCuts = new AliHFEextraCuts("hfeExtraCuts","HFE Extra Cuts");
148 fHFEevent = new AliHFEreducedEvent;
150 fHFEtree = new TTree("HFEtree", "HFE event tree");
151 fHFEtree->Branch("HFEevent", "AliHFEreducedEvent", fHFEevent,128000,0);
152 PostData(1, fHFEtree);
155 void AliHFEreducedEventCreatorAOD::UserExec(Option_t *){
157 // User Exec: Fill debug Tree
161 AliPIDResponse *pid = NULL;
162 AliInputEventHandler *handler = dynamic_cast<AliInputEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
164 // printf("testb\n");
165 pid = handler->GetPIDResponse();
167 AliError("No Handler");
170 // printf("testc\n");
171 AliError("No PID response");
175 AliError("No Input event");
179 if(fRemoveFirstEvent){
180 if(fAnalysisUtils->IsFirstEventInChunk(fInputEvent)) return;
183 AliAODTrack copyTrack;
186 Bool_t mcthere = kTRUE;
187 AliAODEvent *aodE = dynamic_cast<AliAODEvent *>(fInputEvent);
189 // printf("testd\n");
190 AliError("No AOD Event");
193 fAODMCHeader = dynamic_cast<AliAODMCHeader *>(fInputEvent->FindListObject(AliAODMCHeader::StdBranchName()));
198 fAODArrayMCInfo = dynamic_cast<TClonesArray *>(fInputEvent->FindListObject(AliAODMCParticle::StdBranchName()));
199 if(!fAODArrayMCInfo){
204 fSignalCuts->SetMCAODInfo(fAODArrayMCInfo);
205 fTrackCuts->SetMCEvent(aodE);
208 // Set for track cuts
210 // Check Monte-Carlo events for AODs
211 AliDebug(1, Form("Monte-Carlo Event: %p\n", fMCEvent));
213 AliDebug(1, Form("Available! Number of particles: %d\n", fMCEvent->GetNumberOfTracks()));
216 fTrackCuts->SetRecEvent(fInputEvent);
218 if(!fTrackCuts->CheckEventCuts("fCutsEvRec", fInputEvent)){
219 AliDebug(1, "Event rejected by the event cuts\n");
223 fExtraCuts = new AliHFEextraCuts("hfeExtraCuts","HFE Extra Cuts");
225 fExtraCuts->SetRecEventInfo(fInputEvent);
228 // Make Reduced Event
229 //AliHFEreducedEvent hfeevent;
230 fHFEevent->~AliHFEreducedEvent();
231 new(fHFEevent)AliHFEreducedEvent();
234 fHFEevent->SetRunNumber(fInputEvent->GetRunNumber());
237 AliDebug(1, "Get triggers\n");
238 UInt_t trigger = fInputHandler->IsEventSelected();
239 if(trigger & AliVEvent::kMB) fHFEevent->SetMBTrigger();
240 if(trigger & AliVEvent::kCentral) fHFEevent->SetCentralTrigger();
241 if(trigger & AliVEvent::kSemiCentral) fHFEevent->SetCentralTrigger();
242 if(trigger & AliVEvent::kEMCEJE) fHFEevent->SetEMCALTrigger();
244 // Get Primary Vertex
245 AliDebug(1, "Get Primary Vertex\n");
246 const AliVVertex *vertex = fInputEvent->GetPrimaryVertex();
251 AliDebug(1, "Found vertex\n");
253 ncontrib = vertex->GetNContributors();
254 vertex->GetCovarianceMatrix(vcov);
256 fHFEevent->SetVX(vtx[0]);
257 fHFEevent->SetVY(vtx[1]);
258 fHFEevent->SetVZ(vtx[2]);
259 fHFEevent->SetNContribVertex(ncontrib);
260 fHFEevent->SetVertexResolution(TMath::Sqrt(TMath::Abs(vcov[5])));
261 // Get Primary Vertex from SPD
262 const AliVVertex *vertexSPD = aodE->GetPrimaryVertexSPD();
264 AliDebug(1, "Found SPD vertex\n");
265 memset(vtx, 0, sizeof(Double_t) *3);
266 vertexSPD->GetXYZ(vtx);
267 fHFEevent->SetVXSPD(vtx[0]);
268 fHFEevent->SetVYSPD(vtx[1]);
269 fHFEevent->SetVZSPD(vtx[2]);
270 fHFEevent->SetNContribVertexSPD(vertexSPD->GetNContributors());
271 memset(vcov, 0, sizeof(Double_t)*6);
272 vertexSPD->GetCovarianceMatrix(vcov);
273 AliDebug(1, Form("Covariance Matrix vcov[5] %f\n",vcov[5]));
274 fHFEevent->SetVertexResolutionSPD(TMath::Sqrt(TMath::Abs(vcov[5])));
278 AliDebug(1, "Centrality\n");
279 AliCentrality *hicent = fInputEvent->GetCentrality();
280 if(hicent) fHFEevent->SetCentrality(
281 hicent->GetCentralityPercentile("V0M"),
282 hicent->GetCentralityPercentile("V0A"),
283 hicent->GetCentralityPercentile("V0C"),
284 hicent->GetCentralityPercentile("TKL"),
285 hicent->GetCentralityPercentile("TRK"),
286 hicent->GetCentralityPercentile("ZNA"),
287 hicent->GetCentralityPercentile("ZNC"),
288 hicent->GetCentralityPercentile("CL0"),
289 hicent->GetCentralityPercentile("CL1"),
290 hicent->GetCentralityPercentile("CND")
293 // Get VZERO Information
294 AliDebug(1, "VZERO info\n");
295 AliVVZERO *vzeroinfo = fInputEvent->GetVZEROData();
296 if(vzeroinfo) fHFEevent->SetV0Multiplicity(vzeroinfo->GetMTotV0A(), vzeroinfo->GetMTotV0C());
298 // Get ZDC Information
299 AliDebug(1, "ZDC info\n");
300 AliVZDC *zdcinfo = fInputEvent->GetZDCData();
301 if(zdcinfo) fHFEevent->SetZDCEnergy(zdcinfo->GetZNAEnergy(), zdcinfo->GetZNCEnergy(), zdcinfo->GetZPAEnergy(), zdcinfo->GetZPCEnergy());
303 // Set SPD multiplicity
304 AliDebug(1, "SPD multiplicity\n");
305 AliAODTracklets *tls = aodE->GetTracklets();
306 if(tls) fHFEevent->SetSPDMultiplicity(tls->GetNumberOfTracklets());
308 // Look for kink mother
309 AliDebug(1, "Vertices\n");
310 Int_t numberofvertices = aodE->GetNumberOfVertices();
311 Double_t listofmotherkink[numberofvertices];
312 Int_t numberofmotherkink = 0;
313 //printf("Number of vertices %d\n",numberofvertices);
314 for(Int_t ivertex=0; ivertex < numberofvertices; ivertex++) {
315 AliAODVertex *aodvertex = aodE->GetVertex(ivertex);
316 if(!aodvertex) continue;
317 //printf("Type %d\n",aodvertex->GetType());
318 if(aodvertex->GetType()==AliAODVertex::kKink) {
319 //printf("Find one kink\n");
320 AliAODTrack *mother = (AliAODTrack *) aodvertex->GetParent();
321 if(!mother) continue;
322 Int_t idmother = mother->GetID();
323 listofmotherkink[numberofmotherkink] = idmother;
324 //printf("ID %d\n",idmother);
325 numberofmotherkink++;
328 //printf("Number of kink mother in the events %d\n",numberofmotherkink);
331 // Loop on MC tracks only
333 AliAODMCParticle *mctrack(NULL);
337 AliDebug(1, "Loop MC tracks\n");
338 for(Int_t itrack = 0; itrack < fAODArrayMCInfo->GetEntriesFast(); itrack++) {
339 mctrack = (AliAODMCParticle *)(fAODArrayMCInfo->At(itrack));
340 if(!mctrack) continue;
341 AliHFEreducedMCParticle hfemcpart;
342 if(fTrackCuts->CheckParticleCuts(static_cast<UInt_t>(AliHFEcuts::kStepMCGenerated), mctrack)) continue;
343 hfemcpart.SetSignal();
345 hfemcpart.SetSignedPt(mctrack->Pt(), mctrack->Charge() > 0.);
346 hfemcpart.SetP(mctrack->P());
347 hfemcpart.SetEta(mctrack->Eta());
348 hfemcpart.SetPhi(mctrack->Phi());
349 hfemcpart.SetPdg(mctrack->GetPdgCode());
351 // Get Production Vertex in radial direction
352 hfemcpart.SetProductionVertex(mctrack->Xv(),mctrack->Yv(),mctrack->Zv());
354 // Get Mother PDG code of the particle
355 Int_t motherlabel = TMath::Abs(mctrack->GetMother());
356 if(motherlabel >= 0 && motherlabel < fAODArrayMCInfo->GetEntriesFast()){
357 AliAODMCParticle *mother = dynamic_cast<AliAODMCParticle *>(fAODArrayMCInfo->At(motherlabel));
358 if(mother) hfemcpart.SetMotherPdg(mother->GetPdgCode());
363 if(fSignalCuts->IsCharmElectron(mctrack)) source = 0;
364 else if(fSignalCuts->IsBeautyElectron(mctrack)) source = 1;
365 else if(fSignalCuts->IsGammaElectron(mctrack)) source = 2;
366 else if(fSignalCuts->IsNonHFElectron(mctrack)) source = 3;
367 else if(TMath::Abs(mctrack->GetPdgCode()) == 11) source = 4;
369 hfemcpart.SetSource(source);
371 fHFEevent->AddMCParticle(&hfemcpart);
376 // Loop on reconstructed tracks
378 TArrayI arraytrack(fInputEvent->GetNumberOfTracks());
381 AliAODTrack *track = 0x0;
382 AliDebug(1, "Loop reconstructed tracks\n");
383 for(Int_t itrack = 0; itrack < fInputEvent->GetNumberOfTracks(); itrack++){
385 track = dynamic_cast<AliAODTrack *>(fInputEvent->GetTrack(itrack));
387 // Cut track (Only basic track cuts)
388 // printf("testv\n");
389 if(!fTrackCuts->CheckParticleCuts(AliHFEcuts::kNcutStepsMCTrack + AliHFEcuts::kStepRecKineITSTPC, track)) continue;
394 AliHFEreducedTrack hfetrack;
395 hfetrack.SetSignedPt(track->Pt(), track->Charge() > 0);
396 hfetrack.SetP(track->P());
397 hfetrack.SetEta(track->Eta());
398 hfetrack.SetPhi(track->Phi());
399 hfetrack.SetTPCmomentum(track->GetDetPid() ? track->GetDetPid()->GetTPCmomentum() : track->P());
402 hfetrack.SetTrackID(track->GetID());
405 ULong_t status = track->GetStatus();
406 if((status & AliVTrack::kITSrefit) == AliVTrack::kITSrefit) hfetrack.SetITSrefit();
407 if((status & AliVTrack::kTPCrefit) == AliVTrack::kTPCrefit) hfetrack.SetTPCrefit();
408 if((status & AliVTrack::kTOFpid) == AliVTrack::kTOFpid) hfetrack.SetTOFpid();
409 //if((status & AliVTrack::kTOFmismatch) == AliVTrack::kTOFmismatch) hfetrack.SetTOFmismatch();
410 if(IsTOFmismatch(track, pid)) hfetrack.SetTOFmismatch(); // New version suggested by Pietro Antonioli
411 if(track->IsEMCAL()) hfetrack.SetEMCALpid();
413 for(Int_t k=0; k<20; k++) {
415 if((track->TestFilterBit(u))) {
416 hfetrack.SetFilterBit(k);
421 // Fill Monte-Carlo Information
422 Int_t label = TMath::Abs(track->GetLabel());
423 if(label < fAODArrayMCInfo->GetEntriesFast())
424 mctrack = dynamic_cast<AliAODMCParticle *>(fAODArrayMCInfo->At(label));
426 AliDebug(2, "Associated MC particle found\n");
427 if(fTrackCuts->CheckParticleCuts(static_cast<UInt_t>(AliHFEcuts::kStepMCGenerated), mctrack)) hfetrack.SetMCSignal();
429 hfetrack.SetMCSignedPt(mctrack->Pt(),mctrack->Charge() > 0.);
430 hfetrack.SetMCP(mctrack->P());
431 hfetrack.SetMCEta(mctrack->Eta());
432 hfetrack.SetMCPhi(mctrack->Phi());
433 hfetrack.SetMCPDG(mctrack->GetPdgCode());
435 // Get Production Vertex in radial direction
436 hfetrack.SetMCProdVtx(mctrack->Xv(),mctrack->Yv(),mctrack->Zv());
438 // Get Mother PDG code of the particle
439 Int_t motherlabel = TMath::Abs(mctrack->GetMother());
440 if(motherlabel >= 0 && motherlabel < fAODArrayMCInfo->GetEntriesFast()){
441 AliAODMCParticle *mother = dynamic_cast<AliAODMCParticle *>(fAODArrayMCInfo->At(motherlabel));
442 if(mother) hfetrack.SetMCMotherPdg(mother->GetPdgCode());
447 if(fSignalCuts->IsCharmElectron(mctrack)) source = 0;
448 else if(fSignalCuts->IsBeautyElectron(mctrack)) source = 1;
449 else if(fSignalCuts->IsGammaElectron(mctrack)) source = 2;
450 else if(fSignalCuts->IsNonHFElectron(mctrack)) source = 3;
451 else if(TMath::Abs(mctrack->GetPdgCode()) == 11) source = 4;
453 hfetrack.SetMCSource(source);
455 AliDebug(2, "Associated MC particle not found\n");
460 Float_t dcaxy = -999.,
462 fExtraCuts->GetImpactParameters((AliVTrack *)track,dcaxy,dcaz);
463 hfetrack.SetDCA(dcaxy, dcaz);
464 Double_t hfeImpactParam(-999.), hfeImpactParamResol(-999.);
465 fExtraCuts->GetHFEImpactParameters((AliVTrack *)track,hfeImpactParam,hfeImpactParamResol);
466 hfetrack.SetHFEImpactParam(hfeImpactParam,hfeImpactParamResol);
468 // Different number of clusters definitions
469 Int_t nclustersITS(track->GetITSNcls()),
470 nclustersTPC(track->GetTPCNcls()),
471 nclustersTPCall(track->GetTPCClusterMap().CountBits()),
472 nclustersTPCshared(0);
473 UChar_t nfindableTPC = track->GetTPCNclsF();
474 const TBits &sharedTPC = track->GetTPCSharedMap();
475 for(Int_t ibit = 0; ibit < 160; ibit++) if(sharedTPC.TestBitNumber(ibit)) nclustersTPCshared++;
476 hfetrack.SetITSnclusters(nclustersITS);
477 hfetrack.SetTPCnclusters(track->GetTPCNcls());
478 hfetrack.SetTRDnclusters(track->GetTRDncls());
479 hfetrack.SetTPCnclustersPID(track->GetTPCsignalN());
480 hfetrack.SetTPCcrossedRows(track->GetTPCNCrossedRows());
481 hfetrack.SetTPCnclustersAll(nclustersTPCall);
482 hfetrack.SetTPCsharedClusters(nclustersTPCshared);
483 hfetrack.SetTPCclusterRatio(nfindableTPC ? static_cast<Float_t>(nclustersTPC)/static_cast<Float_t>(nfindableTPC) : 0);
484 hfetrack.SetTPCclusterRatioAll(nfindableTPC ? static_cast<Float_t>(nclustersTPCall)/static_cast<Float_t>(nfindableTPC) : 0);
485 UChar_t itsPixel = track->GetITSClusterMap();
486 for(int ily = 0; ily < 6; ily++)
487 if(TESTBIT(itsPixel, ily)) hfetrack.SetITScluster(ily);
489 // TRD related quantities (Yvonne)
490 hfetrack.SetTRDntrackletsPID(track->GetTRDntrackletsPID());
491 hfetrack.SetTRDnslices(track->GetDetPid()->GetTRDnSlices());
492 hfetrack.SetTRDchi2(track->GetTRDchi2());
493 AliAODPid* aodpid= track->GetDetPid();
494 Double_t* arraytrdsignals;
495 arraytrdsignals=aodpid->GetTRDslices();
497 for(Int_t iplane = 0; iplane < 6; iplane++){
499 for(Int_t b=(iplane*8);b<((iplane*8)+8);b++){
500 if(track->GetTRDntrackletsPID()>0){
501 if(arraytrdsignals[b]>0.001) nslicetemp++;
504 if(nslicetemp > 0) hfetrack.SetTRDstatus(iplane);
509 if(fExtraCuts->IsKinkDaughter(track)) hfetrack.SetIsKinkDaughter();
512 for(Int_t kinkmother = 0; kinkmother < numberofmotherkink; kinkmother++) {
513 if(track->GetID() == listofmotherkink[kinkmother]) {
514 hfetrack.SetIsKinkMother();
521 Int_t id(track->GetID());
522 for(Int_t l=0; l < counterdc; l++){
523 Int_t iTrack2 = arraytrack.At(l);
525 hfetrack.SetDoubleCounted();
529 // Add the id at this place
530 arraytrack.AddAt(id,counterdc);
534 hfetrack.SetTPCdEdx(track->GetDetPid() ? track->GetDetPid()->GetTPCsignal() : 0.);
535 hfetrack.SetTPCsigmaEl(pid->NumberOfSigmasTPC(track, AliPID::kElectron));
536 hfetrack.SetTOFsigmaEl(pid->NumberOfSigmasTOF(track, AliPID::kElectron));
537 hfetrack.SetTOFmismatchProbability(pid->GetTOFMismatchProbability(track));
538 hfetrack.SetITSsigmaEl(pid->NumberOfSigmasITS(track, AliPID::kElectron));
540 copyTrack.~AliAODTrack();
541 new(©Track) AliAODTrack(*track);
542 if(fTPCpid->HasCentralityCorrection()) fTPCpid->ApplyCentralityCorrection(©Track, static_cast<Double_t>(ncontrib),AliHFEpidObject::kAODanalysis);
543 if(fTPCpid->HasEtaCorrection()) fTPCpid->ApplyEtaCorrection(©Track, AliHFEpidObject::kAODanalysis);
544 hfetrack.SetTPCsigmaElCorrected(pid->NumberOfSigmasTPC(©Track, AliPID::kElectron));
545 hfetrack.SetTPCdEdxCorrected(copyTrack.GetDetPid() ? copyTrack.GetDetPid()->GetTPCsignal() : 0.);
546 if(track->IsEMCAL()){
548 Double_t emcalEnergyOverP = -1.,
549 showershape[4] = {0.,0.,0.,0.};
550 hfetrack.SetEMCALSigmaEl(pid->NumberOfSigmasEMCAL(track, AliPID::kElectron, emcalEnergyOverP, &showershape[0]));
551 hfetrack.SetEMCALEoverP(emcalEnergyOverP);
552 hfetrack.SetEMCALShowerShape(showershape);
556 if(fNbOfTOFSigma>0.0){
557 AliDebug(1, "TOF cut\n");
558 if(!((status & AliVTrack::kTOFpid) == AliVTrack::kTOFpid)) continue;
559 if(TMath::Abs(pid->NumberOfSigmasTOF(track, AliPID::kElectron))> fNbOfTOFSigma) continue;
562 // Track finished, add NOW to the Event
563 fHFEevent->AddTrack(&hfetrack);
567 // Fill the debug tree
568 AliInfo(Form("Number of tracks: %d\n", fHFEevent->GetNumberOfTracks()));
569 AliInfo(Form("Number of MC particles: %d\n", fHFEevent->GetNumberOfMCParticles()));
573 PostData(1, fHFEtree);
576 void AliHFEreducedEventCreatorAOD::Terminate(Option_t *){
580 AliInfo("terminating...\n");
584 Bool_t AliHFEreducedEventCreatorAOD::IsTOFmismatch(const AliVTrack *const track, const AliPIDResponse *const pid) const {
588 Double_t probs[AliPID::kSPECIESC];
589 AliPIDResponse::EDetPidStatus status = pid->ComputeTOFProbability(track, AliPID::kSPECIESC, probs);
590 return status == AliPIDResponse::kDetMismatch;