3 #include "AliAnalysisTaskEMCALIsoPhoton.h"
10 #include <THnSparse.h>
11 #include <TLorentzVector.h>
14 #include "AliAnalysisManager.h"
15 #include "AliAnalysisTask.h"
16 #include "AliEMCALGeometry.h"
17 #include "AliEMCALRecoUtils.h"
18 #include "AliESDCaloCells.h"
19 #include "AliESDCaloCluster.h"
20 #include "AliESDEvent.h"
21 #include "AliESDHeader.h"
22 #include "AliESDInputHandler.h"
23 #include "AliESDUtils.h"
24 #include "AliESDtrack.h"
25 #include "AliESDtrackCuts.h"
26 #include "AliMCEvent.h"
27 #include "AliMCEventHandler.h"
29 #include "AliV0vertexer.h"
30 #include "AliVCluster.h"
32 ClassImp(AliAnalysisTaskEMCALIsoPhoton)
34 //________________________________________________________________________
35 AliAnalysisTaskEMCALIsoPhoton::AliAnalysisTaskEMCALIsoPhoton() :
43 fGeoName("EMCAL_COMPLETEV1"),
67 // Default constructor.
70 //________________________________________________________________________
71 AliAnalysisTaskEMCALIsoPhoton::AliAnalysisTaskEMCALIsoPhoton(const char *name) :
72 AliAnalysisTaskSE(name),
79 fGeoName("EMCAL_COMPLETEV1"),
105 // Define input and output slots here
106 // Input slot #0 works with a TChain
107 DefineInput(0, TChain::Class());
108 // Output slot #0 id reserved by the base class for AOD
109 // Output slot #1 writes into a TH1 container
110 DefineOutput(1, TList::Class());
113 //________________________________________________________________________
114 void AliAnalysisTaskEMCALIsoPhoton::UserCreateOutputObjects()
116 // Create histograms, called once.
118 fCaloClusters = new TRefArray();
119 fSelPrimTracks = new TObjArray();
122 fOutputList = new TList();
123 fOutputList->SetOwner();// Container cleans up all histos (avoids leaks in merging)
125 fGeom = AliEMCALGeometry::GetInstance(fGeoName);
127 fEvtSel = new TH1F("hEvtSel","Event selection counter (0=all trg, 1=pvz cut) ;evt cut ;dN/dcut}",2,0,2);
128 fOutputList->Add(fEvtSel);
130 fNClusEt10 = new TH1F("hNClusEt10","# of cluster with E_{T}>10 per event;E;",101,-0.5,100.5);
131 fOutputList->Add(fNClusEt10);
133 fPVtxZ = new TH1F("hPVtxZ","primary vertex Z before cut;prim-vz(cm) ;",200,-100,100);
134 fOutputList->Add(fPVtxZ);
136 fDirPhotonPtMC = new TH1F("hDirPhotonPtMC","photon (gq->#gammaq) p_{T};GeV/c;dN/dp_{T} (c GeV^{-1})",1000,0,100);
137 fDirPhotonPtMC->Sumw2();
138 fOutputList->Add(fDirPhotonPtMC);
140 fDecayPhotonPtMC = new TH1F("hDecayPhotonPtMC","decay photon p_{T};GeV/c;dN/dp_{T} (c GeV^{-1})",1000,0,100);
141 fDecayPhotonPtMC->Sumw2();
142 fOutputList->Add(fDecayPhotonPtMC);
144 fCellAbsIdVsAmpl = new TH2F("hCellAbsIdVsAmpl","cell abs id vs cell amplitude (energy);E (GeV);ID",200,0,100,24*48*10,-0.5,24*48*10-0.5);
145 fOutputList->Add(fCellAbsIdVsAmpl);
147 fNClusHighClusE = new TH2F("hNClusHighClusE","total number of clusters vs. highest clus energy in the event;E (GeV);NClus",200,0,100,301,-0.5,300.5);
148 fOutputList->Add(fNClusHighClusE);
150 Int_t nEt=1000, nM02=400, nCeIso=1000, nTrIso=1000, nAllIso=1000, nCeIsoNoUE=1000, nAllIsoNoUE=1000, nTrClDphi=200, nTrClDeta=100, nClEta=140, nClPhi=128, nTime=60, nMult=20;
151 Int_t bins[] = {nEt, nM02, nCeIso, nTrIso, nAllIso, nCeIsoNoUE, nAllIsoNoUE, nTrClDphi, nTrClDeta,nClEta,nClPhi,nTime,nMult};
152 fNDimensions = sizeof(bins)/sizeof(Int_t);
153 const Int_t ndims = fNDimensions;
154 Double_t xmin[] = { 0., 0., -10., -10., -10., -10., -10., -0.1,-0.05, -0.7, 1.4,-0.15e-06,-0.5};
155 Double_t xmax[] = { 100., 4., 190., 190., 190., 190., 190., 0.1, 0.05, 0.7, 3.192, 0.15e-06,99.5};
156 fHnOutput = new THnSparseF("fHnOutput","Output matrix: E_{T},M02,CeIso,TrIso,AllIso, CeIsoNoUESub, AllIsoNoUESub, d#phi_{trk},d#eta_{trk},#eta_{clus},#phi_{clus},T_{max},mult", ndims, bins, xmin, xmax);
157 fOutputList->Add(fHnOutput);
161 PostData(1, fOutputList);
164 //________________________________________________________________________
165 void AliAnalysisTaskEMCALIsoPhoton::UserExec(Option_t *)
167 // Main loop, called for each event.
169 // event trigger selection
170 Bool_t isSelected = 0;
171 if(fPeriod.Contains("11a")){
172 if(fTrigBit.Contains("kEMC"))
173 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kEMC1);
175 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB);
178 if(fTrigBit.Contains("kEMC"))
179 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kEMC7);
181 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kINT7);
186 printf("isSelected = %d, fIsMC=%d\n", isSelected, fIsMc);
190 fESD = dynamic_cast<AliESDEvent*>(InputEvent());
192 printf("ERROR: fESD not available\n");
198 printf("fESD is ok\n");
200 AliESDVertex *pv = (AliESDVertex*)fESD->GetPrimaryVertex();
203 fPVtxZ->Fill(pv->GetZ());
204 if(TMath::Abs(pv->GetZ())>15)
207 printf("passed vertex cut\n");
212 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("Tracks"));
213 // Track loop to fill a pT spectrum
214 const Int_t Ntracks = fTracks->GetEntriesFast();
215 for (Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) {
216 // for (Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
217 //AliESDtrack* track = (AliESDtrack*)fESD->GetTrack(iTracks);
218 AliVTrack *track = static_cast<AliVTrack*>(fTracks->At(iTracks));
221 if (fPrTrCuts && fPrTrCuts->IsSelected(track)){
222 fSelPrimTracks->Add(track);
223 //printf("pt,eta,phi:%1.1f,%1.1f,%1.1f \n",track->Pt(),track->Eta(), track->Phi());
228 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
229 if(fGeoName=="EMCAL_FIRSTYEARV1" && mod>3)
231 fGeom->SetMisalMatrix(fESD->GetEMCALMatrix(mod), mod);
234 AliESDtrackCuts *fTrackCuts = new AliESDtrackCuts();
235 fTrackMult = fTrackCuts->GetReferenceMultiplicity(fESD);//kTrackletsITSTPC ,0.5);
237 fESD->GetEMCALClusters(fCaloClusters);
238 fEMCalCells = fESD->GetEMCALCells();
243 printf("passed calling of FillClusHists\n");
245 fCaloClusters->Clear();
246 fSelPrimTracks->Clear();
248 fMCEvent = MCEvent();
251 cout<<"MCevent exists\n";
252 fStack = (AliStack*)fMCEvent->Stack();
256 cout<<"ERROR: NO MC EVENT!!!!!!\n";
260 printf("passed calling of FillMcHists\n");
263 PostData(1, fOutputList);
266 //________________________________________________________________________
267 void AliAnalysisTaskEMCALIsoPhoton::FillClusHists()
269 // Fill cluster histograms.
273 const Int_t nclus = fCaloClusters->GetEntries();
277 printf("Inside FillClusHists and there are %d clusters\n",nclus);
280 for(Int_t ic=0;ic<nclus;ic++){
282 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(fCaloClusters->At(ic));
290 Double_t Emax = GetMaxCellEnergy( c, id);
291 Double_t Ecross = GetCrossEnergy( c, id);
292 if((1-Ecross/Emax)>fExoticCut)
294 Float_t clsPos[3] = {0,0,0};
295 c->GetPosition(clsPos);
296 TVector3 clsVec(clsPos);
297 Double_t Et = c->E()*TMath::Sin(clsVec.Theta());
300 Float_t ceiso, cephiband, cecore;
301 Float_t triso, trphiband, trcore;
302 Float_t alliso, allphiband, allcore;
303 Float_t phibandArea = (1.4 - 2*fIsoConeR)*2*fIsoConeR;
304 Float_t netConeArea = TMath::Pi()*(fIsoConeR*fIsoConeR - 0.04*0.04);
305 GetCeIso(clsVec, ceiso, cephiband, cecore);
306 GetTrIso(clsVec, triso, trphiband, trcore);
307 alliso = ceiso + triso;
308 allphiband = cephiband + trphiband;
309 allcore = cecore + trcore;
310 Float_t ceisoue = cephiband/phibandArea*netConeArea;
311 Float_t trisoue = trphiband/phibandArea*netConeArea;
312 Float_t allisoue = allphiband/phibandArea*netConeArea;
313 const Int_t ndims = fNDimensions;
314 Double_t outputValues[ndims];
315 outputValues[0] = Et;
316 outputValues[1] = c->GetM02();
317 outputValues[2] = ceiso-cecore-ceisoue;
318 outputValues[3] = triso-trisoue;
319 outputValues[4] = alliso-cecore-allisoue;
320 outputValues[5] = ceiso-Et;
321 outputValues[6] = alliso-Et;
322 outputValues[7] = c->GetTrackDx();
323 outputValues[8] = c->GetTrackDz();
324 outputValues[9] = clsVec.Eta();
325 outputValues[10] = clsVec.Phi();
326 outputValues[11] = fEMCalCells->GetCellTime(id);
327 outputValues[12] = fTrackMult;
328 fHnOutput->Fill(outputValues);
332 fNClusHighClusE->Fill(maxE,nclus);
333 fNClusEt10->Fill(nclus10);
336 //________________________________________________________________________
337 void AliAnalysisTaskEMCALIsoPhoton::GetCeIso(TVector3 vec, Float_t &iso, Float_t &phiband, Float_t &core)
339 // Get cell isolation.
343 const Int_t ncells = fEMCalCells->GetNumberOfCells();
347 Float_t etacl = vec.Eta();
348 Float_t phicl = vec.Phi();
349 Float_t thetacl = vec.Theta();
351 phicl+=TMath::TwoPi();
353 Float_t eta=-1, phi=-1;
354 for(int icell=0;icell<ncells;icell++){
355 absid = TMath::Abs(fEMCalCells->GetCellNumber(icell));
358 fGeom->EtaPhiFromIndex(absid,eta,phi);
359 Float_t dphi = TMath::Abs(phi-phicl);
360 Float_t deta = TMath::Abs(eta-etacl);
361 Float_t R = TMath::Sqrt(deta*deta + dphi*dphi);
362 Float_t etcell = fEMCalCells->GetCellAmplitude(absid)*TMath::Sin(thetacl);
373 totband += fEMCalCells->GetCellAmplitude(absid)*TMath::Sin(thetacl);
381 //________________________________________________________________________
382 void AliAnalysisTaskEMCALIsoPhoton::GetTrIso(TVector3 vec, Float_t &iso, Float_t &phiband, Float_t &core)
384 // Get track isolation.
388 const Int_t ntracks = fSelPrimTracks->GetEntries();
392 Double_t etacl = vec.Eta();
393 Double_t phicl = vec.Phi();
395 phicl+=TMath::TwoPi();
396 for(int itrack=0;itrack<ntracks;itrack++){
397 AliVTrack *track = static_cast<AliVTrack*> (fSelPrimTracks->At(itrack));
400 Double_t dphi = TMath::Abs(track->Phi()-phicl);
401 Double_t deta = TMath::Abs(track->Eta()-etacl);
402 Double_t R = TMath::Sqrt(deta*deta + dphi*dphi);
403 Double_t pt = track->Pt();
405 totiso += track->Pt();
414 totband += track->Pt();
422 //________________________________________________________________________
423 Double_t AliAnalysisTaskEMCALIsoPhoton::GetCrossEnergy(const AliVCluster *cluster, Short_t &idmax)
425 // Calculate the energy of cross cells around the leading cell.
427 AliVCaloCells *cells = 0;
428 cells = fESD->GetEMCALCells();
444 Double_t crossEnergy = 0;
446 fGeom->GetCellIndex(idmax,iSupMod,iTower,iIphi,iIeta);
447 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphis,ietas);
449 Int_t ncells = cluster->GetNCells();
450 for (Int_t i=0; i<ncells; i++) {
451 Int_t cellAbsId = cluster->GetCellAbsId(i);
452 fGeom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta);
453 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
454 Int_t aphidiff = TMath::Abs(iphi-iphis);
457 Int_t aetadiff = TMath::Abs(ieta-ietas);
460 if ( (aphidiff==1 && aetadiff==0) ||
461 (aphidiff==0 && aetadiff==1) ) {
462 crossEnergy += cells->GetCellAmplitude(cellAbsId);
469 //________________________________________________________________________
470 Double_t AliAnalysisTaskEMCALIsoPhoton ::GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const
472 // Get maximum energy of attached cell.
476 AliVCaloCells *cells = 0;
477 cells = fESD->GetEMCALCells();
482 Int_t ncells = cluster->GetNCells();
483 for (Int_t i=0; i<ncells; i++) {
484 Double_t e = cells->GetCellAmplitude(TMath::Abs(cluster->GetCellAbsId(i)));
487 id = cluster->GetCellAbsId(i);
493 //________________________________________________________________________
494 void AliAnalysisTaskEMCALIsoPhoton ::FillMcHists()
498 Int_t nTracks = fStack->GetNtrack();
500 printf("Inside FillMcHists and there are %d mcparts\n",nTracks);
501 for(Int_t iTrack=0;iTrack<nTracks;iTrack++){
502 TParticle *mcp = static_cast<TParticle*>(fStack->Particle(iTrack));
505 Int_t pdg = mcp->GetPdgCode();
508 if(TMath::Abs(mcp->Eta())>0.7 ||mcp->Phi()<1.4 || mcp->Phi()>3.2)
510 Int_t imom = mcp->GetMother(0);
511 if(imom<0 || imom>nTracks)
513 TParticle *mcmom = static_cast<TParticle*>(fStack->Particle(imom));
516 Int_t pdgMom = mcmom->GetPdgCode();
517 if(imom==6 || imom==7 && pdgMom==22) {
518 fDirPhotonPtMC->Fill(mcp->Pt());
520 printf("Found \"photonic\" parton at position %d, with pt=%1.1f, eta=%1.1f and phi=%1.1f, and status=%d,\n",imom,mcmom->Pt(), mcmom->Eta(), mcmom->Phi(), mcmom->GetStatusCode());
521 printf("with a final photon at position %d, with pt=%1.1f, eta=%1.1f and phi=%1.1f, and status=%d\n",iTrack,mcp->Pt(), mcp->Eta(), mcp->Phi(),mcp->GetStatusCode());
524 if(TMath::Abs(pdgMom)>100 && TMath::Abs(pdgMom)<1000)
525 fDecayPhotonPtMC->Fill(mcp->Pt());
529 //________________________________________________________________________
530 void AliAnalysisTaskEMCALIsoPhoton::Terminate(Option_t *)
532 // Called once at the end of the query.