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 //////////////////////////////////////////////////////////
17 // Filter the ESDCaloClusters and ESDCaloCells of EMCAL,
18 // PHOS or both, creating the corresponing AODCaloClusters
20 // Keep also the AODHeader information and the vertex.
21 // Keep tracks, v0s, VZERO if requested
22 // Select events containing a cluster or track avobe a given threshold
23 // Copy of AliAnalysisTaskESDfilter.
24 // Author: Gustavo Conesa Balbastre (INFN - Frascati)
25 //////////////////////////////////////////////////////////
28 #include "TGeoManager.h"
31 #include "TInterpreter.h"
34 #include "AliESDEvent.h"
35 #include "AliAODEvent.h"
37 #include "AliVCluster.h"
38 #include "AliVCaloCells.h"
39 #include "AliVEventHandler.h"
40 #include "AliAODHandler.h"
41 #include "AliAnalysisManager.h"
42 #include "AliInputEventHandler.h"
45 #include "AliEMCALRecoUtils.h"
46 #include "AliEMCALGeometry.h"
48 #include "AliAnalysisTaskCaloFilter.h"
50 ClassImp(AliAnalysisTaskCaloFilter)
52 ////////////////////////////////////////////////////////////////////////
54 AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter():
55 AliAnalysisTaskSE("CaloFilterTask"),
56 fCaloFilter(0), fEventSelection(),
57 fAcceptAllMBEvent(kFALSE),fMBTriggerMask(AliVEvent::kMB),
59 fEMCALGeo(0x0), fEMCALGeoName("EMCAL_COMPLETE12SMV1"),
60 fEMCALRecoUtils(new AliEMCALRecoUtils),
61 fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
62 fGeoMatrixSet(kFALSE),
63 fConfigName(""), fFillAODFile(kTRUE),
64 fFillMCParticles(kFALSE),
65 fFillTracks(kFALSE), fFillHybridTracks(kFALSE),
66 fFillAllVertices(kFALSE), fFillv0s(kFALSE),
68 fEMCALEnergyCut(0.), fEMCALNcellsCut (0),
69 fPHOSEnergyCut(0.), fPHOSNcellsCut (0),
71 fVzCut(100.), fCheckEventVertex(kTRUE),
73 fESDEvent(0x0), fAODEvent(0x0)
75 // Default constructor
77 fEventSelection[0] = kFALSE;
78 fEventSelection[1] = kFALSE;
79 fEventSelection[2] = kFALSE;
81 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
82 //for(Int_t i = 0; i < 5 ; i++) fPHOSMatrix[i] = 0 ;
86 //__________________________________________________
87 AliAnalysisTaskCaloFilter::AliAnalysisTaskCaloFilter(const char* name):
88 AliAnalysisTaskSE(name),
89 fCaloFilter(0), fEventSelection(),
90 fAcceptAllMBEvent(kFALSE),fMBTriggerMask(AliVEvent::kMB),
92 fEMCALGeo(0x0), fEMCALGeoName("EMCAL_COMPLETE12SMV1"),
93 fEMCALRecoUtils(new AliEMCALRecoUtils),
94 fLoadEMCALMatrices(kFALSE), //fLoadPHOSMatrices(kFALSE),
95 fGeoMatrixSet(kFALSE),
96 fConfigName(""), fFillAODFile(kTRUE),
97 fFillMCParticles(kFALSE),
98 fFillTracks(kFALSE), fFillHybridTracks(kFALSE),
99 fFillAllVertices(kFALSE), fFillv0s(kFALSE),
101 fEMCALEnergyCut(0.), fEMCALNcellsCut(0),
102 fPHOSEnergyCut(0.), fPHOSNcellsCut(0),
104 fVzCut(100.), fCheckEventVertex(kTRUE),
106 fESDEvent(0x0), fAODEvent(0x0)
110 fEventSelection[0] = kFALSE;
111 fEventSelection[1] = kFALSE;
112 fEventSelection[2] = kFALSE;
114 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = 0 ;
115 //for(Int_t i = 0; i < 5 ; i++) fPHOSMatrix[i] = 0 ;
119 //__________________________________________________
120 AliAnalysisTaskCaloFilter::~AliAnalysisTaskCaloFilter()
124 if(fEMCALGeo) delete fEMCALGeo;
125 if(fEMCALRecoUtils) delete fEMCALRecoUtils;
129 //_____________________________________________
130 Bool_t AliAnalysisTaskCaloFilter::AcceptEvent()
132 // Define conditions to accept the event to be filtered
134 if(!AcceptEventVertex()) return kFALSE;
136 Bool_t eventSel = kFALSE;
138 Bool_t isMB = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & fMBTriggerMask);
140 if ( isMB && fAcceptAllMBEvent ) eventSel = kTRUE; // accept any MB event
142 else if( fEventSelection[0] && AcceptEventEMCAL() ) eventSel = kTRUE; // accept event depending on EMCAL activity
144 else if( fEventSelection[1] && AcceptEventPHOS () ) eventSel = kTRUE; // accept event depending on PHOS activity
146 else if( fEventSelection[2] && AcceptEventTrack() ) eventSel = kTRUE; // accept event depending on Track activity
152 //__________________________________________________
153 Bool_t AliAnalysisTaskCaloFilter::AcceptEventEMCAL()
155 // Accept event given there is a EMCAL cluster with enough energy, and not noisy, exotic
157 if(fCaloFilter==kPHOS) return kTRUE; // accept
159 if(fEMCALEnergyCut <= 0) return kTRUE; // accept
161 Int_t nCluster = InputEvent() -> GetNumberOfCaloClusters();
162 AliVCaloCells * caloCell = InputEvent() -> GetEMCALCells();
163 Int_t bc = InputEvent() -> GetBunchCrossNumber();
165 for(Int_t icalo = 0; icalo < nCluster; icalo++)
167 AliVCluster *clus = (AliVCluster*) (InputEvent()->GetCaloCluster(icalo));
169 if( ( clus->IsEMCAL() ) && ( clus->GetNCells() > fEMCALNcellsCut ) && ( clus->E() > fEMCALEnergyCut ) &&
170 fEMCALRecoUtils->IsGoodCluster(clus,fEMCALGeo,caloCell,bc))
173 AliDebug(1,Form("Accept : E %2.2f > %2.2f, nCells %d > %d",
174 clus->E(), fEMCALEnergyCut, clus->GetNCells(), fEMCALNcellsCut));
181 AliDebug(1,"Reject");
183 //printf("Fired %s\n",((AliESDEvent*)InputEvent())->GetFiredTriggerClasses().Data());
189 //_________________________________________________
190 Bool_t AliAnalysisTaskCaloFilter::AcceptEventPHOS()
192 // Accept event given there is a PHOS cluster with enough energy and not noisy/exotic
194 if(fCaloFilter==kEMCAL) return kTRUE; // accept
196 if(fPHOSEnergyCut <= 0) return kTRUE; // accept
198 Int_t nCluster = InputEvent() -> GetNumberOfCaloClusters();
200 for(Int_t icalo = 0; icalo < nCluster; icalo++)
202 AliVCluster *clus = (AliVCluster*) (InputEvent()->GetCaloCluster(icalo));
204 if( ( clus->IsPHOS() ) && ( clus->GetNCells() > fPHOSNcellsCut ) && ( clus->E() > fPHOSEnergyCut ))
207 AliDebug(1,Form("Accept : E %2.2f > %2.2f, nCells %d > %d",
208 clus->E(), fPHOSEnergyCut, clus->GetNCells(), fPHOSNcellsCut));
215 AliDebug(1,"Reject");
221 //__________________________________________________
222 Bool_t AliAnalysisTaskCaloFilter::AcceptEventTrack()
224 // Accept event if there is a track avobe a certain pT
226 if(fTrackPtCut <= 0) return kTRUE; // accept
228 Double_t pTrack[3] = {0,0,0};
230 for (Int_t nTrack = 0; nTrack < fEvent->GetNumberOfTracks(); ++nTrack)
232 AliVTrack *track = (AliVTrack*) fEvent->GetTrack(nTrack);
234 // Select only hybrid tracks?
235 if(fAODEvent && fFillHybridTracks && !((AliAODTrack*)track)->IsHybridGlobalConstrainedGlobal()) continue;
237 track->GetPxPyPz(pTrack) ;
239 TLorentzVector momentum(pTrack[0],pTrack[1],pTrack[2],0);
241 if(momentum.Pt() > fTrackPtCut)
243 AliDebug(1,Form("Accept : pT %2.2f > %2.2f",momentum.Pt(), fTrackPtCut));
250 AliDebug(1,"Reject");
256 //___________________________________________________
257 Bool_t AliAnalysisTaskCaloFilter::AcceptEventVertex()
259 // Accept event with good vertex
262 InputEvent()->GetPrimaryVertex()->GetXYZ(v) ;
264 if(TMath::Abs(v[2]) > fVzCut)
266 AliDebug(1,Form("Vz Reject : vz %2.2f > %2.2f",v[2],fVzCut));
271 return CheckForPrimaryVertex();
274 //_______________________________________________________
275 Bool_t AliAnalysisTaskCaloFilter::CheckForPrimaryVertex()
277 //Check if the vertex was well reconstructed, copy from v0Reader of conversion group
278 //It only works for ESDs
280 if(!fCheckEventVertex) return kTRUE;
285 // Check that the vertex is not (0,0,0)
287 InputEvent()->GetPrimaryVertex()->GetXYZ(v) ;
289 if(TMath::Abs(v[2]) < 1e-6 &&
290 TMath::Abs(v[1]) < 1e-6 &&
291 TMath::Abs(v[0]) < 1e-6 )
293 AliDebug(1,"Reject v(0,0,0)");
302 if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors() > 0)
307 if(fESDEvent->GetPrimaryVertexTracks()->GetNContributors() < 1)
310 if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors() > 0)
312 //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
316 if(fESDEvent->GetPrimaryVertexSPD()->GetNContributors() < 1)
318 // cout<<"bad vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
319 AliDebug(1,"Reject, GetPrimaryVertexSPD()->GetNContributors() < 1");
325 AliDebug(1,"Reject, GetPrimaryVertexTracks()->GetNContributors() > 1");
331 //__________________________________________________
332 void AliAnalysisTaskCaloFilter::CorrectionsInEMCAL()
334 //If EMCAL, and requested, correct energy, position ...
336 //Need to do this in a separate loop before filling the ESDs because of the track matching recalculations
338 if(fCorrect && (fCaloFilter==kEMCAL || fCaloFilter==kBoth) )
342 if(fLoadEMCALMatrices)
344 AliInfo("Load user defined EMCAL geometry matrices");
345 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
347 if(fEMCALMatrix[mod])
350 fEMCALMatrix[mod]->Print();
351 fEMCALGeo->SetMisalMatrix(fEMCALMatrix[mod],mod) ;
356 else if(!gGeoManager)
358 AliInfo("Get geo matrices from data");
359 //Still not implemented in AOD, just a workaround to be able to work at least with ESDs
360 if(!strcmp(InputEvent()->GetName(),"AliAODEvent"))
362 AliDebug(1,"Use ideal geometry, values geometry matrix not kept in AODs");
366 AliDebug(1,"Load Misaligned matrices");
367 AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent()) ;
370 AliInfo("This event does not contain ESDs?");
373 for(Int_t mod=0; mod < (fEMCALGeo->GetEMCGeometry())->GetNumberOfSuperModules(); mod++)
376 esd->GetEMCALMatrix(mod)->Print();
377 if(esd->GetEMCALMatrix(mod)) fEMCALGeo->SetMisalMatrix(esd->GetEMCALMatrix(mod),mod) ;
381 }//Load matrices from Data
386 Int_t nCaloClus = InputEvent()->GetNumberOfCaloClusters();
388 for (Int_t iClust=0; iClust<nCaloClus; ++iClust)
390 AliVCluster * cluster = InputEvent()->GetCaloCluster(iClust);
392 if(cluster->IsPHOS()) continue ;
394 Float_t position[]={0,0,0};
396 AliDebug(1,Form("Check cluster %d for bad channels and close to border",cluster->GetID()));
398 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo,cluster->GetCellsAbsId(), cluster->GetNCells())) continue;
400 AliDebug(2,Form("Filter, before : i %d, E %f, dispersion %f, m02 %f, m20 %f, distToBad %f",iClust,cluster->E(),
401 cluster->GetDispersion(),cluster->GetM02(),cluster->GetM20(), cluster->GetDistanceToBadChannel()));
402 cluster->GetPosition(position);
403 AliDebug(2,Form("Filter, before : i %d, x %f, y %f, z %f",cluster->GetID(), position[0], position[1], position[2]));
405 //Recalculate distance to bad channels, if new list of bad channels provided
406 fEMCALRecoUtils->RecalculateClusterDistanceToBadChannel(fEMCALGeo, InputEvent()->GetEMCALCells(), cluster);
408 if(fEMCALRecoUtils->IsRecalibrationOn())
410 fEMCALRecoUtils->RecalibrateClusterEnergy(fEMCALGeo, cluster, InputEvent()->GetEMCALCells());
411 fEMCALRecoUtils->RecalculateClusterShowerShapeParameters(fEMCALGeo, InputEvent()->GetEMCALCells(),cluster);
412 fEMCALRecoUtils->RecalculateClusterPID(cluster);
415 fEMCALRecoUtils->RecalculateClusterPosition(fEMCALGeo, InputEvent()->GetEMCALCells(),cluster);
417 AliDebug(2,Form("Filter, after : i %d, E %f, dispersion %f, m02 %f, m20 %f, distToBad %f",cluster->GetID(),cluster->E(),
418 cluster->GetDispersion(),cluster->GetM02(),cluster->GetM20(), cluster->GetDistanceToBadChannel()));
419 cluster->GetPosition(position);
420 AliDebug(1,Form("Filter, after : i %d, x %f, y %f, z %f",cluster->GetID(), position[0], position[1], position[2]));
422 cluster->SetE(fEMCALRecoUtils->CorrectClusterEnergyLinearity(cluster));
426 //Recalculate track-matching
427 fEMCALRecoUtils->FindMatches(InputEvent(),0,fEMCALGeo);
429 } // corrections in EMCAL
432 //________________________________________________
433 void AliAnalysisTaskCaloFilter::FillAODCaloCells()
435 // Fill EMCAL/PHOS cell info
438 if ((fCaloFilter==kBoth || fCaloFilter==kEMCAL) && fEvent->GetEMCALCells())
439 { // protection against missing ESD information
440 AliVCaloCells &eventEMcells = *(fEvent->GetEMCALCells());
441 Int_t nEMcell = eventEMcells.GetNumberOfCells() ;
443 AliAODCaloCells &aodEMcells = *(AODEvent()->GetEMCALCells());
444 aodEMcells.CreateContainer(nEMcell);
445 aodEMcells.SetType(AliVCaloCells::kEMCALCell);
446 Double_t calibFactor = 1.;
447 for (Int_t iCell = 0; iCell < nEMcell; iCell++)
449 Int_t imod = -1, iphi =-1, ieta=-1,iTower = -1, iIphi = -1, iIeta = -1;
450 fEMCALGeo->GetCellIndex(eventEMcells.GetCellNumber(iCell),imod,iTower,iIphi,iIeta);
451 fEMCALGeo->GetCellPhiEtaIndexInSModule(imod,iTower,iIphi, iIeta,iphi,ieta);
453 if(fCorrect && fEMCALRecoUtils->IsRecalibrationOn())
455 calibFactor = fEMCALRecoUtils->GetEMCALChannelRecalibrationFactor(imod,ieta,iphi);
458 if(!fEMCALRecoUtils->GetEMCALChannelStatus(imod, ieta, iphi))
459 { //Channel is not declared as bad
460 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),eventEMcells.GetAmplitude(iCell)*calibFactor,
461 eventEMcells.GetTime(iCell),eventEMcells.GetMCLabel(iCell),eventEMcells.GetEFraction(iCell));
462 //printf("GOOD channel\n");
466 aodEMcells.SetCell(iCell,eventEMcells.GetCellNumber(iCell),0,-1,-1,0);
467 //printf("BAD channel\n");
474 if ((fCaloFilter==kBoth || fCaloFilter==kPHOS) && fEvent->GetPHOSCells())
475 { // protection against missing ESD information
476 AliVCaloCells &eventPHcells = *(fEvent->GetPHOSCells());
477 Int_t nPHcell = eventPHcells.GetNumberOfCells() ;
479 AliAODCaloCells &aodPHcells = *(AODEvent()->GetPHOSCells());
480 aodPHcells.CreateContainer(nPHcell);
481 aodPHcells.SetType(AliVCaloCells::kPHOSCell);
483 for (Int_t iCell = 0; iCell < nPHcell; iCell++)
485 aodPHcells.SetCell(iCell,eventPHcells.GetCellNumber(iCell),eventPHcells.GetAmplitude(iCell),
486 eventPHcells.GetTime(iCell),eventPHcells.GetMCLabel(iCell),eventPHcells.GetEFraction(iCell));
494 //___________________________________________________
495 void AliAnalysisTaskCaloFilter::FillAODCaloClusters()
497 // Fill the AOD with caloclusters
499 // Access to the AOD container of clusters
501 TClonesArray &caloClusters = *(AODEvent()->GetCaloClusters());
505 Int_t nCaloClus = fEvent->GetNumberOfCaloClusters();
506 for (Int_t iClust=0; iClust<nCaloClus; ++iClust)
509 AliVCluster * cluster = fEvent->GetCaloCluster(iClust);
511 //Check which calorimeter information we want to keep.
513 if(fCaloFilter!=kBoth)
515 if (fCaloFilter==kPHOS && cluster->IsEMCAL()) continue ;
516 else if(fCaloFilter==kEMCAL && cluster->IsPHOS()) continue ;
519 // Get original residuals, in case of previous recalculation, reset them
520 Float_t dR = cluster->GetTrackDx();
521 Float_t dZ = cluster->GetTrackDz();
523 AliDebug(2,Form("Original residuals : dZ %f, dR %f",dZ, dR));
525 //--------------------------------------------------------------
526 //If EMCAL and corrections done, get the new matching parameters, do not copy noisy clusters
527 if(cluster->IsEMCAL() && fCorrect)
529 AliDebug(2,Form("Check cluster %d for bad channels and close to border",cluster->GetID()));
531 if(fEMCALRecoUtils->ClusterContainsBadChannel(fEMCALGeo,cluster->GetCellsAbsId(), cluster->GetNCells())) continue;
533 if(fEMCALRecoUtils->IsExoticCluster(cluster, InputEvent()->GetEMCALCells(),InputEvent()->GetBunchCrossNumber())) continue;
535 fEMCALRecoUtils->GetMatchedResiduals(cluster->GetID(),dR,dZ);
536 cluster->SetTrackDistance(dR,dZ);
539 AliDebug(2,Form("EMCAL? %d, PHOS? %d Track-Cluster Residuals : dZ %f, dR %f",cluster->IsEMCAL(), cluster->IsPHOS(),dZ, dR));
541 //--------------------------------------------------------------
545 Int_t id = cluster->GetID();
546 Float_t energy = cluster->E();
547 cluster->GetPosition(posF);
549 AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++])
550 AliAODCaloCluster(id,
551 cluster->GetNLabels(),
552 cluster->GetLabels(),
558 caloCluster->SetCaloCluster(cluster->GetDistanceToBadChannel(),
559 cluster->GetDispersion(),
560 cluster->GetM20(), cluster->GetM02(),
562 cluster->GetNExMax(),cluster->GetTOF()) ;
564 caloCluster->SetPIDFromESD(cluster->GetPID());
565 caloCluster->SetNCells(cluster->GetNCells());
566 caloCluster->SetCellsAbsId(cluster->GetCellsAbsId());
567 caloCluster->SetCellsAmplitudeFraction(cluster->GetCellsAmplitudeFraction());
568 caloCluster->SetTrackDistance(dR, dZ);
570 AliDebug(2,Form("Filter, aod : i %d, E %f, dispersion %f, m02 %f, m20 %f",caloCluster->GetID(),caloCluster->E(),
571 caloCluster->GetDispersion(),caloCluster->GetM02(),caloCluster->GetM20()));
572 caloCluster->GetPosition(posF);
573 AliDebug(2,Form("Filter, aod : i %d, x %f, y %f, z %f",caloCluster->GetID(), posF[0], posF[1], posF[2]));
575 //Matched tracks, just to know if there was any match, the track pointer is useless if tracks not stored
576 if(TMath::Abs(dR) < 990 && TMath::Abs(dZ) < 990)
577 { //Default value in PHOS 999, in EMCAL 1024, why?
578 caloCluster->AddTrackMatched(new AliAODTrack);
580 // TO DO, in case Tracks available, think how to put the matched track in AOD
583 caloClusters.Expand(jClusters); // resize TObjArray to 'remove' slots
587 //__________________________________________________
588 void AliAnalysisTaskCaloFilter::FillAODCaloTrigger()
590 // AOD CaloTrigger copy
592 if( !AODEvent() || !fAODEvent ) return;
594 AliAODCaloTrigger* triggerEM = AODEvent()->GetCaloTrigger("EMCAL");
595 AliAODCaloTrigger* triggerPH = AODEvent()->GetCaloTrigger("PHOS");
599 AliAODCaloTrigger* inTriggerEM = fAODEvent ->GetCaloTrigger("EMCAL");
600 AliAODCaloTrigger* inTriggerPH = fAODEvent ->GetCaloTrigger("PHOS");
602 if(inTriggerPH && (fCaloFilter==kBoth || fCaloFilter==kPHOS)) *triggerPH = *inTriggerPH;
604 if(inTriggerEM && (fCaloFilter==kBoth || fCaloFilter==kEMCAL)) *triggerEM = *inTriggerEM;
607 //______________________________________________
608 void AliAnalysisTaskCaloFilter::FillAODHeader()
612 AliAODHeader* header = dynamic_cast<AliAODHeader*>(AODEvent()->GetHeader());
615 AliFatal("Not a standard AOD");
616 return; // not needed but coverity complains
622 *header = *((AliAODHeader*)fAODEvent->GetHeader());
626 if(!fESDEvent) return;
630 header->SetRunNumber(fEvent->GetRunNumber());
632 TTree* tree = fInputHandler->GetTree();
635 TFile* file = tree->GetCurrentFile();
636 if (file) header->SetESDFileName(file->GetName());
639 header->SetBunchCrossNumber(fEvent->GetBunchCrossNumber());
640 header->SetOrbitNumber(fEvent->GetOrbitNumber());
641 header->SetPeriodNumber(fEvent->GetPeriodNumber());
642 header->SetEventType(fEvent->GetEventType());
645 if(fEvent->GetCentrality())
647 header->SetCentrality(new AliCentrality(*(fEvent->GetCentrality())));
651 header->SetCentrality(0);
655 header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
656 header->SetFiredTriggerClasses(fESDEvent->GetFiredTriggerClasses());
657 header->SetTriggerMask(fEvent->GetTriggerMask());
658 header->SetTriggerCluster(fEvent->GetTriggerCluster());
659 header->SetL0TriggerInputs(fESDEvent->GetHeader()->GetL0TriggerInputs());
660 header->SetL1TriggerInputs(fESDEvent->GetHeader()->GetL1TriggerInputs());
661 header->SetL2TriggerInputs(fESDEvent->GetHeader()->GetL2TriggerInputs());
663 header->SetMagneticField(fEvent->GetMagneticField());
664 header->SetMuonMagFieldScale(fESDEvent->GetCurrentDip()/6000.);
666 header->SetZDCN1Energy(fEvent->GetZDCN1Energy());
667 header->SetZDCP1Energy(fEvent->GetZDCP1Energy());
668 header->SetZDCN2Energy(fEvent->GetZDCN2Energy());
669 header->SetZDCP2Energy(fEvent->GetZDCP2Energy());
670 header->SetZDCEMEnergy(fEvent->GetZDCEMEnergy(0),fEvent->GetZDCEMEnergy(1));
672 Float_t diamxy[2]={(Float_t)fEvent->GetDiamondX(),(Float_t)fEvent->GetDiamondY()};
674 fEvent->GetDiamondCovXY(diamcov);
675 header->SetDiamond(diamxy,diamcov);
676 header->SetDiamondZ(fESDEvent->GetDiamondZ(),fESDEvent->GetSigma2DiamondZ());
681 //__________________________________________________
682 void AliAnalysisTaskCaloFilter::FillAODMCParticles()
686 if(!fFillMCParticles) return;
688 TClonesArray* inMCParticles = (TClonesArray*) (fAODEvent ->FindListObject("mcparticles"));
689 TClonesArray* ouMCParticles = (TClonesArray*) ( AODEvent()->FindListObject("mcparticles"));
691 if( inMCParticles && ouMCParticles ) new (ouMCParticles) TClonesArray(*inMCParticles);
695 //_____________________________________________
696 void AliAnalysisTaskCaloFilter::FillAODTracks()
700 if(!fFillTracks) return;
702 AliAODTrack* aodTrack(0x0);
704 Double_t pos[3] = { 0. };
705 Double_t covTr[21]= { 0. };
706 //Double_t pid[10] = { 0. };
707 Double_t p[3] = { 0. };
712 //TClonesArray* inTracks = fAODEvent ->GetTracks();
713 TClonesArray* ouTracks = AODEvent()->GetTracks();
714 //new (ouTracks) TClonesArray(*inTracks);
716 //printf("N tracks %d\n",fAODEvent->GetNumberOfTracks());
717 Int_t nCopyTrack = 0;
718 for (Int_t nTrack = 0; nTrack < fAODEvent->GetNumberOfTracks(); ++nTrack)
720 AliAODTrack *track = dynamic_cast<AliAODTrack*>(fAODEvent->GetTrack(nTrack));
721 if(!track) AliFatal("Not a standard AOD");
723 // Select only hybrid tracks?
724 if(fFillHybridTracks && !track->IsHybridGlobalConstrainedGlobal()) continue;
726 // Remove PID object to save space
727 //track->SetDetPID(0x0);
729 //new((*ouTracks)[nCopyTrack++]) AliAODTrack(*track);
732 Bool_t isDCA = track->GetPosition(pos);
733 track->GetCovMatrix(covTr);
734 //track->GetPID(pid);
736 AliAODVertex* primVertex = (AliAODVertex*) AODEvent()->GetVertices()->At(0); // primary vertex, copied previously!!!
738 aodTrack = new((*ouTracks)[nCopyTrack++]) AliAODTrack(
747 track->GetITSClusterMap(),
750 track->GetUsedForVtxFit(),
751 track->GetUsedForPrimVtxFit(),
752 (AliAODTrack::AODTrk_t) track->GetType(),
753 track->GetFilterMap());
756 aodTrack->SetPIDForTracking(track->GetPIDForTracking());
757 aodTrack->SetIsHybridGlobalConstrainedGlobal(track->IsHybridGlobalConstrainedGlobal());
758 aodTrack->SetIsHybridTPCConstrainedGlobal (track->IsHybridTPCConstrainedGlobal());
759 aodTrack->SetIsGlobalConstrained (track->IsGlobalConstrained());
760 aodTrack->SetIsTPCConstrained (track->IsTPCConstrained());
762 aodTrack->SetTPCFitMap (track->GetTPCFitMap());
763 aodTrack->SetTPCClusterMap(track->GetTPCClusterMap());
764 aodTrack->SetTPCSharedMap (track->GetTPCSharedMap());
766 aodTrack->SetChi2MatchTrigger(track->GetChi2MatchTrigger());
768 // set the DCA values to the AOD track
770 aodTrack->SetPxPyPzAtDCA(track->PxAtDCA(),track->PyAtDCA(),track->PzAtDCA());
771 aodTrack->SetXYAtDCA (track->XAtDCA() ,track->YAtDCA());
773 aodTrack->SetFlags (track->GetFlags());
774 aodTrack->SetTPCPointsF (track->GetTPCNclsF());
778 if(track->IsEMCAL()) aodTrack->SetEMCALcluster(track->GetEMCALcluster());
779 if(track->IsPHOS()) aodTrack->SetPHOScluster (track->GetPHOScluster());
780 aodTrack->SetTrackPhiEtaPtOnEMCal( track->GetTrackPhiOnEMCal(), track->GetTrackPhiOnEMCal(), track->GetTrackPtOnEMCal() );
784 //printf("Final N tracks %d\n",nCopyTrack);
791 //_________________________________________
792 void AliAnalysisTaskCaloFilter::FillAODv0s()
794 // Copy v0s (use if you know what you do, use quite a lot of memory)
796 if(!fFillv0s) return;
801 TClonesArray* inv0 = fAODEvent ->GetV0s();
802 TClonesArray* ouv0 = AODEvent()->GetV0s();
804 //new (ouv0s) TClonesArray(*inv0s);
806 Int_t allv0s = inv0->GetEntriesFast();
808 for (Int_t nv0s = 0; nv0s < allv0s; ++nv0s)
810 AliAODv0 *v0 = (AliAODv0*)inv0->At(nv0s);
812 new((*ouv0)[nv0s]) AliAODv0(*v0);
820 //____________________________________________
821 void AliAnalysisTaskCaloFilter::FillAODVZERO()
825 if(!fFillVZERO) return;
827 AliAODVZERO* vzeroData = AODEvent()->GetVZEROData();
829 if(fESDEvent) *vzeroData = *(fESDEvent->GetVZEROData());
830 else *vzeroData = *(fAODEvent->GetVZEROData());
834 //_______________________________________________
835 void AliAnalysisTaskCaloFilter::FillAODVertices()
839 // set arrays and pointers
842 for (Int_t i = 0; i < 6; i++) covVtx[i] = 0.;
847 TClonesArray* inVertices = fAODEvent ->GetVertices();
848 TClonesArray* ouVertices = AODEvent()->GetVertices();
850 //new (ouVertices) TClonesArray(*inVertices);
852 //Keep only the first 3 vertices if not requested
853 Int_t allVertices = inVertices->GetEntriesFast();
855 //printf("n Vertices %d\n",allVertices);
857 if(!fFillAllVertices)
859 if(allVertices > 3) allVertices = 3;
862 //printf("Final n Vertices %d\n",allVertices);
864 for (Int_t nVertices = 0; nVertices < allVertices; ++nVertices)
866 AliAODVertex *vertex = (AliAODVertex*)inVertices->At(nVertices);
868 new((*ouVertices)[nVertices]) AliAODVertex(*vertex);
874 if(!fESDEvent) return;
878 // Access to the AOD container of vertices
880 TClonesArray &vertices = *(AODEvent()->GetVertices());
882 // Add primary vertex. The primary tracks will be defined
883 // after the loops on the composite objects (v0, cascades, kinks)
884 fEvent ->GetPrimaryVertex()->GetXYZ(pos);
885 fESDEvent->GetPrimaryVertex()->GetCovMatrix(covVtx);
886 Float_t chi = fESDEvent->GetPrimaryVertex()->GetChi2toNDF();
888 AliAODVertex * primary = new(vertices[jVertices++])
889 AliAODVertex(pos, covVtx, chi, NULL, -1, AliAODVertex::kPrimary);
890 primary->SetName(fEvent->GetPrimaryVertex()->GetName());
891 primary->SetTitle(fEvent->GetPrimaryVertex()->GetTitle());
895 //____________________________________
896 void AliAnalysisTaskCaloFilter::Init()
898 //Init analysis with configuration macro if available
900 if(gROOT->LoadMacro(fConfigName) >=0)
902 AliInfo(Form("Configure analysis with %s",fConfigName.Data()));
904 AliAnalysisTaskCaloFilter *filter = (AliAnalysisTaskCaloFilter*)gInterpreter->ProcessLine("ConfigCaloFilter()");
906 fEMCALGeoName = filter->fEMCALGeoName;
907 fLoadEMCALMatrices = filter->fLoadEMCALMatrices;
908 fFillAODFile = filter->fFillAODFile;
909 fFillTracks = filter->fFillTracks;
910 fFillHybridTracks = filter->fFillHybridTracks;
911 fFillv0s = filter->fFillv0s;
912 fFillVZERO = filter->fFillVZERO;
913 fFillAllVertices = filter->fFillAllVertices;
914 fEMCALRecoUtils = filter->fEMCALRecoUtils;
915 fConfigName = filter->fConfigName;
916 fCaloFilter = filter->fCaloFilter;
917 fEventSelection[0] = filter->fEventSelection[0];
918 fEventSelection[1] = filter->fEventSelection[1];
919 fEventSelection[2] = filter->fEventSelection[2];
920 fAcceptAllMBEvent = filter->fAcceptAllMBEvent;
921 fMBTriggerMask = filter->fMBTriggerMask;
922 fCorrect = filter->fCorrect;
923 fEMCALEnergyCut = filter->fEMCALEnergyCut;
924 fEMCALNcellsCut = filter->fEMCALNcellsCut;
925 fPHOSEnergyCut = filter->fPHOSEnergyCut;
926 fPHOSNcellsCut = filter->fPHOSNcellsCut;
927 fTrackPtCut = filter->fTrackPtCut;
928 fVzCut = filter->fVzCut;
929 fCheckEventVertex = filter->fCheckEventVertex;
931 for(Int_t i = 0; i < 12; i++) fEMCALMatrix[i] = filter->fEMCALMatrix[i] ;
935 //_________________________________________
936 void AliAnalysisTaskCaloFilter::PrintInfo()
940 printf("AnalysisCaloFilter::PrintInfo() \n");
942 printf("\t Not only filter, correct Clusters? %d\n",fCorrect);
943 printf("\t Calorimeter Filtering Option ? %d\n",fCaloFilter);
945 //printf("\t Use handmade geo matrices? EMCAL %d, PHOS %d\n",fLoadEMCALMatrices, fLoadPHOSMatrices);
946 printf("\t Use handmade geo matrices? EMCAL %d, PHOS 0\n",fLoadEMCALMatrices);
948 printf("\t Fill: AOD file? %d Tracks? %d; all Vertex? %d; v0s? %d; VZERO ? %d\n",
949 fFillAODFile,fFillTracks,fFillAllVertices, fFillv0s, fFillVZERO);
951 printf("\t Event Selection based : EMCAL? %d, PHOS? %d Tracks? %d - Accept all MB with mask %d? %d\n",
952 fEventSelection[0],fEventSelection[1],fEventSelection[2],fMBTriggerMask, fAcceptAllMBEvent);
954 printf("\t \t EMCAL E > %2.2f, EMCAL nCells >= %d, PHOS E > %2.2f, PHOS nCells >= %d, Track pT > %2.2f, |vz| < %2.2f\n",
955 fEMCALEnergyCut,fEMCALNcellsCut,fPHOSEnergyCut,fPHOSNcellsCut, fTrackPtCut,fVzCut);
958 //_______________________________________________________
959 void AliAnalysisTaskCaloFilter::UserCreateOutputObjects()
963 fEMCALGeo = AliEMCALGeometry::GetInstance(fEMCALGeoName) ;
967 TClonesArray * aodMCParticles = new TClonesArray("AliAODMCParticle",500);
968 aodMCParticles->SetName("mcparticles");
969 ((AliAODHandler*)AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler())->AddBranch("TClonesArray", &aodMCParticles);
974 //____________________________________________________________
975 void AliAnalysisTaskCaloFilter::UserExec(Option_t */*option*/)
977 // Execute analysis for current event
978 // Copy input ESD or AOD header, vertex, CaloClusters and CaloCells to output AOD
980 AliDebug(1,Form("Analysing event # %d", (Int_t)Entry()));
982 fEvent = InputEvent();
983 fAODEvent = dynamic_cast<AliAODEvent*> (fEvent);
984 fESDEvent = dynamic_cast<AliESDEvent*> (fEvent);
988 AliInfo("This event does not contain Input?");
992 // printf("Start processing : %s\n",fAODEvent->GetFiredTriggerClasses().Data());
996 if(!AcceptEvent()) return ;
998 //Magic line to write events to file
1000 AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(fFillAODFile);
1004 Int_t nVertices = 0;
1005 if(fFillv0s) nVertices = fEvent->GetNumberOfV0s();
1006 Int_t nCaloClus = fEvent->GetNumberOfCaloClusters();
1007 Int_t nTracks = fEvent->GetNumberOfTracks();
1009 AODEvent()->ResetStd(nTracks, nVertices, 0, 0, 0, nCaloClus, 0, 0);
1019 FillAODVertices(); // Do it before the track filtering to have the reference to the vertex
1028 CorrectionsInEMCAL();
1031 FillAODCaloClusters();
1037 FillAODCaloTrigger();
1040 FillAODMCParticles();
1042 //printf("Filtered event, end processing : %s\n",fAODEvent->GetFiredTriggerClasses().Data());