]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/EMCALTasks/AliAnalysisTaskEMCALIsoPhoton.cxx
remove obsolete restriction on aplication of time cuts in case of AOD analysis
[u/mrichter/AliRoot.git] / PWGGA / EMCALTasks / AliAnalysisTaskEMCALIsoPhoton.cxx
CommitLineData
bd092f0f 1// $Id$
30159e6f 2
bd092f0f 3#include "AliAnalysisTaskEMCALIsoPhoton.h"
30159e6f 4
bd092f0f 5#include <TCanvas.h>
6#include <TChain.h>
7#include <TFile.h>
8#include <TH1F.h>
9#include <TH2F.h>
caaf99d3 10#include <TH3F.h>
965c985f 11#include <THnSparse.h>
bd092f0f 12#include <TLorentzVector.h>
a62631a9 13#include <TList.h>
bd092f0f 14
15#include "AliAnalysisManager.h"
16#include "AliAnalysisTask.h"
17#include "AliEMCALGeometry.h"
18#include "AliEMCALRecoUtils.h"
19#include "AliESDCaloCells.h"
20#include "AliESDCaloCluster.h"
30159e6f 21#include "AliESDEvent.h"
22#include "AliESDHeader.h"
30159e6f 23#include "AliESDInputHandler.h"
bd092f0f 24#include "AliESDUtils.h"
30159e6f 25#include "AliESDtrack.h"
26#include "AliESDtrackCuts.h"
bd092f0f 27#include "AliMCEvent.h"
28#include "AliMCEventHandler.h"
29#include "AliStack.h"
30159e6f 30#include "AliV0vertexer.h"
30159e6f 31#include "AliVCluster.h"
32
30159e6f 33ClassImp(AliAnalysisTaskEMCALIsoPhoton)
34
35//________________________________________________________________________
bd092f0f 36AliAnalysisTaskEMCALIsoPhoton::AliAnalysisTaskEMCALIsoPhoton() :
37 AliAnalysisTaskSE(),
38 fCaloClusters(0),
39 fSelPrimTracks(0),
3f4073ba 40 fTracks(0),
bd092f0f 41 fEMCalCells(0),
42 fPrTrCuts(0),
43 fGeom(0x0),
9148fa89 44 fGeoName("EMCAL_COMPLETEV1"),
45 fPeriod("LHC11c"),
46 fTrigBit("kEMC7"),
47 fIsTrain(0),
c7bb0b43 48 fIsMc(0),
ecd47673 49 fDebug(0),
f3843637 50 fPathStrOpt("/"),
9148fa89 51 fExoticCut(0.97),
52 fIsoConeR(0.4),
965c985f 53 fNDimensions(7),
54 fECut(3.),
16a4050e 55 fTrackMult(0),
f507c09b 56 fMcIdFamily(""),
57 fNClusForDirPho(0),
58 fDirPhoPt(0),
f9e2362a 59 fHigherPtCone(0),
bd092f0f 60 fESD(0),
c7bb0b43 61 fMCEvent(0),
62 fStack(0),
bd092f0f 63 fOutputList(0),
64 fEvtSel(0),
0b21f686 65 fNClusEt10(0),
f507c09b 66 fPVtxZ(0),
67 fTrMultDist(0),
caaf99d3 68 fMCDirPhotonPtEtaPhi(0),
c7bb0b43 69 fDecayPhotonPtMC(0),
bd092f0f 70 fCellAbsIdVsAmpl(0),
16a4050e 71 fNClusHighClusE(0),
f9e2362a 72 fHigherPtConeM02(0),
f507c09b 73 fClusEtMcPt(0),
74 fClusMcDetaDphi(0),
75 fNClusPerPho(0),
092ceec8 76 fMCDirPhotonPtEtaPhiNoClus(0),
965c985f 77 fHnOutput(0)
bd092f0f 78{
79 // Default constructor.
80}
81
82//________________________________________________________________________
83AliAnalysisTaskEMCALIsoPhoton::AliAnalysisTaskEMCALIsoPhoton(const char *name) :
84 AliAnalysisTaskSE(name),
30159e6f 85 fCaloClusters(0),
86 fSelPrimTracks(0),
3f4073ba 87 fTracks(0),
30159e6f 88 fEMCalCells(0),
89 fPrTrCuts(0),
90 fGeom(0x0),
91 fGeoName("EMCAL_COMPLETEV1"),
92 fPeriod("LHC11c"),
751194e8 93 fTrigBit("kEMC7"),
30159e6f 94 fIsTrain(0),
c7bb0b43 95 fIsMc(0),
ecd47673 96 fDebug(0),
f3843637 97 fPathStrOpt("/"),
30159e6f 98 fExoticCut(0.97),
99 fIsoConeR(0.4),
965c985f 100 fNDimensions(7),
101 fECut(3.),
16a4050e 102 fTrackMult(0),
f507c09b 103 fMcIdFamily(""),
104 fNClusForDirPho(0),
105 fDirPhoPt(0),
f9e2362a 106 fHigherPtCone(0),
30159e6f 107 fESD(0),
c7bb0b43 108 fMCEvent(0),
109 fStack(0),
30159e6f 110 fOutputList(0),
30159e6f 111 fEvtSel(0),
0b21f686 112 fNClusEt10(0),
bd092f0f 113 fPVtxZ(0),
f507c09b 114 fTrMultDist(0),
caaf99d3 115 fMCDirPhotonPtEtaPhi(0),
c7bb0b43 116 fDecayPhotonPtMC(0),
117 fCellAbsIdVsAmpl(0),
bd092f0f 118 fNClusHighClusE(0),
f9e2362a 119 fHigherPtConeM02(0),
f507c09b 120 fClusEtMcPt(0),
121 fClusMcDetaDphi(0),
122 fNClusPerPho(0),
092ceec8 123 fMCDirPhotonPtEtaPhiNoClus(0),
965c985f 124 fHnOutput(0)
30159e6f 125{
126 // Constructor
127
128 // Define input and output slots here
129 // Input slot #0 works with a TChain
130 DefineInput(0, TChain::Class());
131 // Output slot #0 id reserved by the base class for AOD
132 // Output slot #1 writes into a TH1 container
133 DefineOutput(1, TList::Class());
134}
bd092f0f 135
30159e6f 136//________________________________________________________________________
137void AliAnalysisTaskEMCALIsoPhoton::UserCreateOutputObjects()
138{
bd092f0f 139 // Create histograms, called once.
30159e6f 140
141 fCaloClusters = new TRefArray();
142 fSelPrimTracks = new TObjArray();
143
144
145 fOutputList = new TList();
a62631a9 146 fOutputList->SetOwner();// Container cleans up all histos (avoids leaks in merging)
30159e6f 147
f507c09b 148 fGeom = AliEMCALGeometry::GetInstance(fGeoName.Data());
30159e6f 149
150 fEvtSel = new TH1F("hEvtSel","Event selection counter (0=all trg, 1=pvz cut) ;evt cut ;dN/dcut}",2,0,2);
151 fOutputList->Add(fEvtSel);
0b21f686 152
153 fNClusEt10 = new TH1F("hNClusEt10","# of cluster with E_{T}>10 per event;E;",101,-0.5,100.5);
154 fOutputList->Add(fNClusEt10);
30159e6f 155
156 fPVtxZ = new TH1F("hPVtxZ","primary vertex Z before cut;prim-vz(cm) ;",200,-100,100);
157 fOutputList->Add(fPVtxZ);
c7bb0b43 158
f507c09b 159 fTrMultDist = new TH1F("fTrMultDist","track multiplicity;tracks/event;#events",200,0.5,200.5);
160 fOutputList->Add(fTrMultDist);
161
caaf99d3 162 fMCDirPhotonPtEtaPhi = new TH3F("hMCDirPhotonPtEtaPhi","photon (gq->#gammaq) p_{T}, #eta, #phi;GeV/c;#eta;#phi",1000,0,100,154,-0.77,0.77,130,1.38,3.20);
163 fMCDirPhotonPtEtaPhi->Sumw2();
164 fOutputList->Add(fMCDirPhotonPtEtaPhi);
c7bb0b43 165
166 fDecayPhotonPtMC = new TH1F("hDecayPhotonPtMC","decay photon p_{T};GeV/c;dN/dp_{T} (c GeV^{-1})",1000,0,100);
167 fDecayPhotonPtMC->Sumw2();
168 fOutputList->Add(fDecayPhotonPtMC);
169
30159e6f 170 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);
a62631a9 171 fOutputList->Add(fCellAbsIdVsAmpl);
30159e6f 172
173 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);
174 fOutputList->Add(fNClusHighClusE);
175
f9e2362a 176 fHigherPtConeM02 = new TH2F("hHigherPtConeM02","#lambda_{0}^{2} vs. in-cone-p_{T}^{max};p_{T}^{max} (GeV/c, in the cone);#lambda_{0}^{2}",1000,0,100,400,0,4);
177 fOutputList->Add(fHigherPtConeM02);
178
f507c09b 179 fClusEtMcPt = new TH2F("hClusEtMcPt","E_{T}^{clus} vs. p_{T}^{mc}; p_{T}^{mc};E_{T}^{clus}",500,0,100,500,0,100);
180 fOutputList->Add(fClusEtMcPt);
181
182 fClusMcDetaDphi = new TH2F("hClusMcDetaDphi","#Delta#phi vs. #Delta#eta (reco-mc);#Delta#eta;#Delta#phi",100,-.7,.7,100,-.7,.7);
183 fOutputList->Add(fClusMcDetaDphi);
184
185 fNClusPerPho = new TH2F("hNClusPerPho","Number of clusters per prompt photon;p_{T}^{MC};N_{clus}",500,0,100,11,-0.5,10.5);
186 fOutputList->Add(fNClusPerPho);
187
092ceec8 188 fMCDirPhotonPtEtaPhiNoClus = new TH3F("hMCDirPhotonPhiEtaNoClus","p_{T}, #eta and #phi of prompt photons with no reco clusters;p_{T};#eta;#phi",1000,0,100,154,-0.77,0.77,130,1.38,3.20);
189 fOutputList->Add(fMCDirPhotonPtEtaPhiNoClus);
f507c09b 190
191 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=100, nPhoMcPt=101;
192 Int_t bins[] = {nEt, nM02, nCeIso, nTrIso, nAllIso, nCeIsoNoUE, nAllIsoNoUE, nTrClDphi, nTrClDeta,nClEta,nClPhi,nTime,nMult,nPhoMcPt};
c1f18270 193 fNDimensions = sizeof(bins)/sizeof(Int_t);
194 const Int_t ndims = fNDimensions;
f507c09b 195 Double_t xmin[] = { 0., 0., -10., -10., -10., -10., -10., -0.1,-0.05, -0.7, 1.4,-0.15e-06,-0.5,-1.5};
196 Double_t xmax[] = { 100., 4., 190., 190., 190., 190., 190., 0.1, 0.05, 0.7, 3.192, 0.15e-06,99.5,99.5};
197 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,mc-p_{T}^{#gamma}", ndims, bins, xmin, xmax);
965c985f 198 fOutputList->Add(fHnOutput);
199
200
201
30159e6f 202 PostData(1, fOutputList);
203}
204
205//________________________________________________________________________
206void AliAnalysisTaskEMCALIsoPhoton::UserExec(Option_t *)
207{
bd092f0f 208 // Main loop, called for each event.
209
210 // event trigger selection
30159e6f 211 Bool_t isSelected = 0;
751194e8 212 if(fPeriod.Contains("11a")){
213 if(fTrigBit.Contains("kEMC"))
214 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kEMC1);
215 else
216 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB);
217 }
218 else{
219 if(fTrigBit.Contains("kEMC"))
220 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kEMC7);
221 else
f507c09b 222 if(fTrigBit.Contains("kMB"))
223 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB);
224 else
225 isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kINT7);
751194e8 226 }
c7bb0b43 227 if(fIsMc)
228 isSelected = kTRUE;
ecd47673 229 if(fDebug)
230 printf("isSelected = %d, fIsMC=%d\n", isSelected, fIsMc);
30159e6f 231 if(!isSelected )
232 return;
f3843637 233 if(fIsMc){
234 TTree *tree = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->GetTree();
235 TFile *file = (TFile*)tree->GetCurrentFile();
236 TString filename = file->GetName();
237 if(!filename.Contains(fPathStrOpt.Data()))
238 return;
239 }
30159e6f 240 fESD = dynamic_cast<AliESDEvent*>(InputEvent());
241 if (!fESD) {
242 printf("ERROR: fESD not available\n");
243 return;
244 }
245
246 fEvtSel->Fill(0);
ecd47673 247 if(fDebug)
248 printf("fESD is ok\n");
30159e6f 249
250 AliESDVertex *pv = (AliESDVertex*)fESD->GetPrimaryVertex();
251 if(!pv)
252 return;
253 fPVtxZ->Fill(pv->GetZ());
254 if(TMath::Abs(pv->GetZ())>15)
255 return;
ecd47673 256 if(fDebug)
257 printf("passed vertex cut\n");
30159e6f 258
259 fEvtSel->Fill(1);
bd092f0f 260
06a28959 261 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject("Tracks"));
262 if(!fTracks){
263 AliError("Track array in event is NULL!");
264 return;
265 }
30159e6f 266 // Track loop to fill a pT spectrum
3f4073ba 267 const Int_t Ntracks = fTracks->GetEntriesFast();
268 for (Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) {
269 // for (Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
270 //AliESDtrack* track = (AliESDtrack*)fESD->GetTrack(iTracks);
271 AliVTrack *track = static_cast<AliVTrack*>(fTracks->At(iTracks));
30159e6f 272 if (!track)
273 continue;
274 if (fPrTrCuts && fPrTrCuts->IsSelected(track)){
275 fSelPrimTracks->Add(track);
276 //printf("pt,eta,phi:%1.1f,%1.1f,%1.1f \n",track->Pt(),track->Eta(), track->Phi());
277 }
bd092f0f 278 }
279
30159e6f 280 if(!fIsTrain){
281 for(Int_t mod=0; mod < (fGeom->GetEMCGeometry())->GetNumberOfSuperModules(); mod++){
282 if(fGeoName=="EMCAL_FIRSTYEARV1" && mod>3)
283 break;
284 fGeom->SetMisalMatrix(fESD->GetEMCALMatrix(mod), mod);
285 }
286 }
16a4050e 287 AliESDtrackCuts *fTrackCuts = new AliESDtrackCuts();
f507c09b 288 fTrackMult = fTrackCuts->GetReferenceMultiplicity(fESD);//kTrackletsITSTPC ,0.5);
289 fTrMultDist->Fill(fTrackMult);
16a4050e 290
30159e6f 291 fESD->GetEMCALClusters(fCaloClusters);
292 fEMCalCells = fESD->GetEMCALCells();
293
294
c7bb0b43 295
296 fMCEvent = MCEvent();
ecd47673 297 if(fMCEvent){
298 if(fDebug)
ec9ab86b 299 std::cout<<"MCevent exists\n";
c7bb0b43 300 fStack = (AliStack*)fMCEvent->Stack();
ecd47673 301 }
302 else{
303 if(fDebug)
ec9ab86b 304 std::cout<<"ERROR: NO MC EVENT!!!!!!\n";
ecd47673 305 }
f507c09b 306 FollowGamma();
307 if(fDebug)
308 printf("passed calling of FollowGamma\n");
309 FillClusHists();
310 if(fDebug)
311 printf("passed calling of FillClusHists\n");
63e40cb8 312 FillMcHists();
ecd47673 313 if(fDebug)
314 printf("passed calling of FillMcHists\n");
315
f507c09b 316 fCaloClusters->Clear();
317 fSelPrimTracks->Clear();
318 fNClusForDirPho = 0;
c7bb0b43 319
30159e6f 320 PostData(1, fOutputList);
321}
bd092f0f 322
30159e6f 323//________________________________________________________________________
324void AliAnalysisTaskEMCALIsoPhoton::FillClusHists()
325{
bd092f0f 326 // Fill cluster histograms.
327
30159e6f 328 if(!fCaloClusters)
329 return;
330 const Int_t nclus = fCaloClusters->GetEntries();
331 if(nclus==0)
332 return;
ecd47673 333 if(fDebug)
334 printf("Inside FillClusHists and there are %d clusters\n",nclus);
e681d9ce 335 Double_t maxE = 0;
0b21f686 336 Int_t nclus10 = 0;
f507c09b 337 Double_t ptmc=-1;
30159e6f 338 for(Int_t ic=0;ic<nclus;ic++){
339 maxE=0;
340 AliESDCaloCluster *c = static_cast<AliESDCaloCluster*>(fCaloClusters->At(ic));
341 if(!c)
342 continue;
343 if(!c->IsEMCAL())
344 continue;
965c985f 345 if(c->E()<fECut)
346 continue;
30159e6f 347 Short_t id;
348 Double_t Emax = GetMaxCellEnergy( c, id);
349 Double_t Ecross = GetCrossEnergy( c, id);
350 if((1-Ecross/Emax)>fExoticCut)
351 continue;
352 Float_t clsPos[3] = {0,0,0};
353 c->GetPosition(clsPos);
354 TVector3 clsVec(clsPos);
3dc2825e 355 Double_t Et = c->E()*TMath::Sin(clsVec.Theta());
f507c09b 356 if(fDebug)
357 printf("\tcluster eta=%1.1f,phi=%1.1f,E=%1.1f\n",clsVec.Eta(),clsVec.Phi(),c->E());
0b21f686 358 if(Et>10)
359 nclus10++;
30159e6f 360 Float_t ceiso, cephiband, cecore;
361 Float_t triso, trphiband, trcore;
362 Float_t alliso, allphiband, allcore;
363 Float_t phibandArea = (1.4 - 2*fIsoConeR)*2*fIsoConeR;
364 Float_t netConeArea = TMath::Pi()*(fIsoConeR*fIsoConeR - 0.04*0.04);
365 GetCeIso(clsVec, ceiso, cephiband, cecore);
366 GetTrIso(clsVec, triso, trphiband, trcore);
f9e2362a 367 Double_t dr = TMath::Sqrt(c->GetTrackDx()*c->GetTrackDx() + c->GetTrackDz()*c->GetTrackDz());
368 if(Et>10 && Et<15 && dr>0.025){
369 fHigherPtConeM02->Fill(fHigherPtCone,c->GetM02());
370 if(fDebug)
371 printf("\t\tHigher track pt inside the cone: %1.1f GeV/c; M02=%1.2f\n",fHigherPtCone,c->GetM02());
372 }
30159e6f 373 alliso = ceiso + triso;
374 allphiband = cephiband + trphiband;
375 allcore = cecore + trcore;
376 Float_t ceisoue = cephiband/phibandArea*netConeArea;
377 Float_t trisoue = trphiband/phibandArea*netConeArea;
378 Float_t allisoue = allphiband/phibandArea*netConeArea;
965c985f 379 const Int_t ndims = fNDimensions;
380 Double_t outputValues[ndims];
f507c09b 381 ptmc = GetClusSource(c);
965c985f 382 outputValues[0] = Et;
383 outputValues[1] = c->GetM02();
384 outputValues[2] = ceiso-cecore-ceisoue;
385 outputValues[3] = triso-trisoue;
386 outputValues[4] = alliso-cecore-allisoue;
302b398c 387 outputValues[5] = ceiso-Et;
388 outputValues[6] = alliso-Et;
717bb45b 389 outputValues[7] = c->GetTrackDx();
390 outputValues[8] = c->GetTrackDz();
391 outputValues[9] = clsVec.Eta();
392 outputValues[10] = clsVec.Phi();
16a4050e 393 outputValues[11] = fEMCalCells->GetCellTime(id);
394 outputValues[12] = fTrackMult;
f507c09b 395 outputValues[13] = ptmc;
965c985f 396 fHnOutput->Fill(outputValues);
30159e6f 397 if(c->E()>maxE)
398 maxE = c->E();
399 }
400 fNClusHighClusE->Fill(maxE,nclus);
0b21f686 401 fNClusEt10->Fill(nclus10);
f507c09b 402 fNClusPerPho->Fill(fDirPhoPt,fNClusForDirPho);
30159e6f 403}
bd092f0f 404
30159e6f 405//________________________________________________________________________
406void AliAnalysisTaskEMCALIsoPhoton::GetCeIso(TVector3 vec, Float_t &iso, Float_t &phiband, Float_t &core)
407{
bd092f0f 408 // Get cell isolation.
409
30159e6f 410 if(!fEMCalCells)
411 return;
412 const Int_t ncells = fEMCalCells->GetNumberOfCells();
413 Float_t totiso=0;
414 Float_t totband=0;
415 Float_t totcore=0;
416 Float_t etacl = vec.Eta();
417 Float_t phicl = vec.Phi();
418 Float_t thetacl = vec.Theta();
419 if(phicl<0)
420 phicl+=TMath::TwoPi();
421 Int_t absid = -1;
422 Float_t eta=-1, phi=-1;
423 for(int icell=0;icell<ncells;icell++){
424 absid = TMath::Abs(fEMCalCells->GetCellNumber(icell));
425 if(!fGeom)
426 return;
427 fGeom->EtaPhiFromIndex(absid,eta,phi);
428 Float_t dphi = TMath::Abs(phi-phicl);
429 Float_t deta = TMath::Abs(eta-etacl);
430 Float_t R = TMath::Sqrt(deta*deta + dphi*dphi);
431 Float_t etcell = fEMCalCells->GetCellAmplitude(absid)*TMath::Sin(thetacl);
432 if(R<fIsoConeR){
433 totiso += etcell;
434 if(R<0.04)
435 totcore += etcell;
436 }
437 else{
438 if(dphi>fIsoConeR)
439 continue;
440 if(deta<fIsoConeR)
441 continue;
442 totband += fEMCalCells->GetCellAmplitude(absid)*TMath::Sin(thetacl);
443 }
444 }
445 iso = totiso;
446 phiband = totband;
447 core = totcore;
448}
bd092f0f 449
30159e6f 450//________________________________________________________________________
451void AliAnalysisTaskEMCALIsoPhoton::GetTrIso(TVector3 vec, Float_t &iso, Float_t &phiband, Float_t &core)
452{
bd092f0f 453 // Get track isolation.
454
30159e6f 455 if(!fSelPrimTracks)
456 return;
f9e2362a 457 fHigherPtCone = 0;
30159e6f 458 const Int_t ntracks = fSelPrimTracks->GetEntries();
459 Double_t totiso=0;
460 Double_t totband=0;
461 Double_t totcore=0;
462 Double_t etacl = vec.Eta();
463 Double_t phicl = vec.Phi();
464 if(phicl<0)
465 phicl+=TMath::TwoPi();
466 for(int itrack=0;itrack<ntracks;itrack++){
3f4073ba 467 AliVTrack *track = static_cast<AliVTrack*> (fSelPrimTracks->At(itrack));
30159e6f 468 if(!track)
469 continue;
470 Double_t dphi = TMath::Abs(track->Phi()-phicl);
471 Double_t deta = TMath::Abs(track->Eta()-etacl);
472 Double_t R = TMath::Sqrt(deta*deta + dphi*dphi);
473 Double_t pt = track->Pt();
f9e2362a 474 if(pt>fHigherPtCone)
475 fHigherPtCone = pt;
30159e6f 476 if(R<fIsoConeR){
477 totiso += track->Pt();
478 if(R<0.04)
479 totcore += pt;
480 }
481 else{
482 if(dphi>fIsoConeR)
483 continue;
484 if(deta<fIsoConeR)
485 continue;
486 totband += track->Pt();
487 }
488 }
489 iso = totiso;
490 phiband = totband;
491 core = totcore;
492}
bd092f0f 493
30159e6f 494//________________________________________________________________________
495Double_t AliAnalysisTaskEMCALIsoPhoton::GetCrossEnergy(const AliVCluster *cluster, Short_t &idmax)
496{
497 // Calculate the energy of cross cells around the leading cell.
498
499 AliVCaloCells *cells = 0;
500 cells = fESD->GetEMCALCells();
501 if (!cells)
502 return 0;
503
30159e6f 504 if (!fGeom)
505 return 0;
506
507 Int_t iSupMod = -1;
508 Int_t iTower = -1;
509 Int_t iIphi = -1;
510 Int_t iIeta = -1;
511 Int_t iphi = -1;
512 Int_t ieta = -1;
513 Int_t iphis = -1;
514 Int_t ietas = -1;
515
516 Double_t crossEnergy = 0;
517
518 fGeom->GetCellIndex(idmax,iSupMod,iTower,iIphi,iIeta);
519 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphis,ietas);
520
521 Int_t ncells = cluster->GetNCells();
522 for (Int_t i=0; i<ncells; i++) {
523 Int_t cellAbsId = cluster->GetCellAbsId(i);
524 fGeom->GetCellIndex(cellAbsId,iSupMod,iTower,iIphi,iIeta);
525 fGeom->GetCellPhiEtaIndexInSModule(iSupMod,iTower,iIphi, iIeta,iphi,ieta);
526 Int_t aphidiff = TMath::Abs(iphi-iphis);
527 if (aphidiff>1)
528 continue;
529 Int_t aetadiff = TMath::Abs(ieta-ietas);
530 if (aetadiff>1)
531 continue;
532 if ( (aphidiff==1 && aetadiff==0) ||
533 (aphidiff==0 && aetadiff==1) ) {
534 crossEnergy += cells->GetCellAmplitude(cellAbsId);
535 }
536 }
537
538 return crossEnergy;
539}
540
30159e6f 541//________________________________________________________________________
542Double_t AliAnalysisTaskEMCALIsoPhoton ::GetMaxCellEnergy(const AliVCluster *cluster, Short_t &id) const
543{
544 // Get maximum energy of attached cell.
545
546 id = -1;
547
548 AliVCaloCells *cells = 0;
549 cells = fESD->GetEMCALCells();
550 if (!cells)
551 return 0;
552
553 Double_t maxe = 0;
554 Int_t ncells = cluster->GetNCells();
555 for (Int_t i=0; i<ncells; i++) {
556 Double_t e = cells->GetCellAmplitude(TMath::Abs(cluster->GetCellAbsId(i)));
557 if (e>maxe) {
558 maxe = e;
559 id = cluster->GetCellAbsId(i);
560 }
561 }
562 return maxe;
563}
bd092f0f 564
c7bb0b43 565//________________________________________________________________________
566void AliAnalysisTaskEMCALIsoPhoton ::FillMcHists()
567{
568 if(!fStack)
569 return;
570 Int_t nTracks = fStack->GetNtrack();
ecd47673 571 if(fDebug)
572 printf("Inside FillMcHists and there are %d mcparts\n",nTracks);
c7bb0b43 573 for(Int_t iTrack=0;iTrack<nTracks;iTrack++){
574 TParticle *mcp = static_cast<TParticle*>(fStack->Particle(iTrack));
575 if(!mcp)
576 continue;
577 Int_t pdg = mcp->GetPdgCode();
578 if(pdg!=22)
579 continue;
f2acdbe9 580 if(TMath::Abs(mcp->Eta())>0.7 ||mcp->Phi()<1.4 || mcp->Phi()>3.2)
581 continue;
c7bb0b43 582 Int_t imom = mcp->GetMother(0);
583 if(imom<0 || imom>nTracks)
584 continue;
585 TParticle *mcmom = static_cast<TParticle*>(fStack->Particle(imom));
586 if(!mcmom)
587 continue;
588 Int_t pdgMom = mcmom->GetPdgCode();
ec9ab86b 589 if((imom==6 || imom==7) && pdgMom==22) {
caaf99d3 590 fMCDirPhotonPtEtaPhi->Fill(mcp->Pt(),mcp->Eta(),mcp->Phi());
f507c09b 591 if(fNClusForDirPho==0)
092ceec8 592 fMCDirPhotonPtEtaPhiNoClus->Fill(mcp->Pt(),mcp->Eta(),mcp->Phi());
40c4f1bf 593 if(fDebug){
f2acdbe9 594 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());
40c4f1bf 595 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());
596 }
f2acdbe9 597 }
c7bb0b43 598 else{
599 if(TMath::Abs(pdgMom)>100 && TMath::Abs(pdgMom)<1000)
600 fDecayPhotonPtMC->Fill(mcp->Pt());
601 }
602 }
603}
30159e6f 604//________________________________________________________________________
f507c09b 605Float_t AliAnalysisTaskEMCALIsoPhoton::GetClusSource(const AliVCluster *c)
606{
607 if(!c)
608 return -1;
609 if(!fStack)
610 return -1;
611 Int_t nmcp = fStack->GetNtrack();
612 Int_t clabel = c->GetLabel();
613 if(fDebug && fMcIdFamily.Contains(Form("%d",clabel)))
614 printf("\n\t ==== Label %d is a descendent of the prompt photon ====\n\n",clabel);
615 if(!fMcIdFamily.Contains(Form("%d",clabel)))
616 return -1;
617 fNClusForDirPho++;
618 TString partonposstr = (TSubString)fMcIdFamily.operator()(0,1);
619 Int_t partonpos = partonposstr.Atoi();
620 if(fDebug)
621 printf("\t^^^^ parton position = %d ^^^^\n",partonpos);
622 if(clabel<0 || clabel>nmcp)
623 return 0;
624 Float_t clsPos[3] = {0,0,0};
625 c->GetPosition(clsPos);
626 TVector3 clsVec(clsPos);
627 Double_t Et = c->E()*TMath::Sin(clsVec.Theta());
628 TParticle *mcp = static_cast<TParticle*>(fStack->Particle(partonpos));
629 if(!mcp)
630 return -1;
631 if(fDebug){
632 printf("\tclus mc truth eta=%1.1f,phi=%1.1f,E=%1.1f, pdgcode=%d, stackpos=%d\n",mcp->Eta(),mcp->Phi(),mcp->Energy(),mcp->GetPdgCode(),clabel);
633 }
634 Int_t lab1 = mcp->GetFirstDaughter();
635 if(lab1<0 || lab1>nmcp)
636 return -1;
637 TParticle *mcd = static_cast<TParticle*>(fStack->Particle(lab1));
638 if(!mcd)
639 return -1;
640 if(fDebug)
641 printf("\t\tmom mc truth eta=%1.1f,phi=%1.1f,E=%1.1f, pdgcode=%d, stackpos=%d\n",mcd->Eta(),mcd->Phi(),mcd->Energy(),mcd->GetPdgCode(),lab1);
642 if(mcd->GetPdgCode()==22){
643 fClusEtMcPt->Fill(mcd->Pt(), Et);
644 fClusMcDetaDphi->Fill(clsVec.Eta() - mcd->Eta(), clsVec.Phi() - mcd->Phi());
645 }
646 else{
647 printf("Warning: daughter of photon parton is not a photon\n");
648 return -1;
649 }
650 return fDirPhoPt;
651}
652//________________________________________________________________________
653void AliAnalysisTaskEMCALIsoPhoton::FollowGamma()
654{
655 if(!fStack)
656 return;
657 Int_t selfid = 6;
658 TParticle *mcp = static_cast<TParticle*>(fStack->Particle(selfid));
659 if(!mcp)
660 return;
661 if(mcp->GetPdgCode()!=22){
662 mcp = static_cast<TParticle*>(fStack->Particle(++selfid));
663 if(!mcp)
664 return;
665 }
666 Int_t daug0f = mcp->GetFirstDaughter();
667 Int_t daug0l = mcp->GetLastDaughter();
668 Int_t nd0 = daug0l - daug0f;
669 if(fDebug)
670 printf("\n\tGenerated gamma (%d) eta=%1.1f,phi=%1.1f,E=%1.1f, pdgcode=%d, n-daug=%d\n",selfid,mcp->Eta(),mcp->Phi(),mcp->Energy(),mcp->GetPdgCode(),nd0+1);
671 fMcIdFamily = Form("%d,",selfid);
672 GetDaughtersInfo(daug0f,daug0l, selfid,"");
673 if(fDebug){
674 printf("\t---- end of the prompt gamma's family tree ----\n\n");
675 printf("Family id string = %s,\n\n",fMcIdFamily.Data());
676 }
677 TParticle *md = static_cast<TParticle*>(fStack->Particle(daug0f));
678 if(!md)
679 return;
680 fDirPhoPt = md->Pt();
681}
682//________________________________________________________________________
683void AliAnalysisTaskEMCALIsoPhoton::GetDaughtersInfo(const int firstd, const int lastd, const int selfid, const char *inputind)
684{
685 int nmcp = fStack->GetNtrack();
686 if(firstd<0 || firstd>nmcp)
687 return;
688 if(lastd<0 || lastd>nmcp)
689 return;
690 if(firstd>lastd){
691 printf("WARNING: First daughter > last (%d,%d)\n",firstd,lastd);
692 return;
693 }
694 TString indenter = Form("\t%s",inputind);
695 TParticle *dp = 0x0;
696 if(fDebug)
697 printf("\t%s--- Daughters of particle %d ---\n", indenter.Data(), selfid);
698 for(int id=firstd; id<lastd+1; id++){
699 dp = static_cast<TParticle*>(fStack->Particle(id));
700 if(!dp)
701 continue;
702 Int_t dfd = dp->GetFirstDaughter();
703 Int_t dld = dp->GetLastDaughter();
704 Int_t dnd = dld - dfd + 1;
705 Float_t vr = TMath::Sqrt(dp->Vx()*dp->Vx()+dp->Vy()*dp->Vy());
706 if(fDebug)
707 printf("\t%sParticle daughter(%d) eta=%1.1f,phi=%1.1f,E=%1.1f, vR=%1.1f, pdgcode=%d, n-daug=%d(%d,%d)\n", indenter.Data(),id, dp->Eta(), dp->Phi(), dp->Energy(), vr, dp->GetPdgCode(), dnd, dfd, dld);
708 fMcIdFamily += Form("%d,",id);
709 GetDaughtersInfo(dfd,dld,id,indenter.Data());
710 }
711}
712//________________________________________________________________________
30159e6f 713void AliAnalysisTaskEMCALIsoPhoton::Terminate(Option_t *)
714{
bd092f0f 715 // Called once at the end of the query.
30159e6f 716}