]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/AliJetModelBaseTask.cxx
Patch for jet analysis
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / AliJetModelBaseTask.cxx
CommitLineData
762e8424 1// $Id$
2//
3// Jet modelling task.
4//
297edd60 5// Author: S.Aiola, C.Loizides
762e8424 6
ffe32451 7#include "AliJetModelBaseTask.h"
8
762e8424 9#include <TClonesArray.h>
65bb5510 10#include <TH1.h>
762e8424 11#include <TLorentzVector.h>
12#include <TRandom3.h>
13
e44e8726 14#include "AliAODCaloCluster.h"
ffe32451 15#include "AliAnalysisManager.h"
762e8424 16#include "AliEMCALDigit.h"
762e8424 17#include "AliEMCALGeometry.h"
ffe32451 18#include "AliEMCALRecPoint.h"
19#include "AliESDCaloCluster.h"
762e8424 20#include "AliLog.h"
ffe32451 21#include "AliPicoTrack.h"
22#include "AliVCluster.h"
23#include "AliVEvent.h"
762e8424 24
25ClassImp(AliJetModelBaseTask)
26
27//________________________________________________________________________
28AliJetModelBaseTask::AliJetModelBaseTask() :
29 AliAnalysisTaskSE("AliJetModelBaseTask"),
30 fGeomName(),
31 fTracksName(),
32 fOutTracksName(),
33 fCaloName(),
34 fOutCaloName(),
35 fSuffix(),
36 fEtaMin(-1),
37 fEtaMax(1),
38 fPhiMin(0),
39 fPhiMax(TMath::Pi() * 2),
40 fPtMin(0),
41 fPtMax(0),
42 fCopyArray(kTRUE),
43 fNClusters(0),
44 fNTracks(0),
a825589f 45 fMarkMC(kTRUE),
e44e8726 46 fPtSpectrum(0),
ffe32451 47 fIsInit(0),
762e8424 48 fGeom(0),
49 fClusters(0),
50 fOutClusters(0),
51 fTracks(0),
52 fOutTracks(0)
53{
54 // Default constructor.
55}
56
57//________________________________________________________________________
58AliJetModelBaseTask::AliJetModelBaseTask(const char *name) :
59 AliAnalysisTaskSE(name),
60 fGeomName(""),
61 fTracksName("PicoTracks"),
62 fOutTracksName("PicoTracksEmbedded"),
63 fCaloName("CaloClustersCorr"),
64 fOutCaloName("CaloClustersCorrEmbedded"),
65 fSuffix("Processed"),
66 fEtaMin(-1),
67 fEtaMax(1),
68 fPhiMin(0),
69 fPhiMax(TMath::Pi() * 2),
70 fPtMin(50),
71 fPtMax(60),
72 fCopyArray(kTRUE),
73 fNClusters(0),
74 fNTracks(1),
a825589f 75 fMarkMC(kTRUE),
e44e8726 76 fPtSpectrum(0),
ffe32451 77 fIsInit(0),
762e8424 78 fGeom(0),
79 fClusters(0),
80 fOutClusters(0),
81 fTracks(0),
82 fOutTracks(0)
83{
84 // Standard constructor.
762e8424 85}
86
87//________________________________________________________________________
88AliJetModelBaseTask::~AliJetModelBaseTask()
89{
90 // Destructor
91}
92
93//________________________________________________________________________
ffe32451 94void AliJetModelBaseTask::UserExec(Option_t *)
95{
96 // Execute per event.
97
b4ffb4d2 98 if (!fIsInit) {
ffe32451 99 ExecOnce();
b4ffb4d2 100 fIsInit = 1;
101 }
ffe32451 102 Run();
103}
104
105//________________________________________________________________________
106AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Double_t eta, Double_t phi)
107{
108 // Add a cluster to the event.
109
110 Int_t absId = 0;
111 if (eta < -100 || phi < 0) {
112 GetRandomCell(eta, phi, absId);
113 }
114 else {
115 fGeom->EtaPhiFromIndex(absId, eta, phi);
116 }
117
118 if (absId == -1) {
119 AliWarning(Form("Unable to embed cluster in eta = %f, phi = %f!"
120 " Maybe the eta-phi range is not inside the EMCal acceptance (eta = [%f, %f], phi = [%f, %f])",
121 eta, phi, fEtaMin, fEtaMax, fPhiMin, fPhiMax));
122 return 0;
123 }
124
125 if (e < 0) {
126 Double_t pt = GetRandomPt();
127 TLorentzVector nPart;
128 nPart.SetPtEtaPhiM(pt, eta, phi, 0);
129 e = nPart.E();
130 }
131
132 return AddCluster(e, absId);
133}
134
135//________________________________________________________________________
136AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Int_t absId)
137{
138 // Add a cluster to the event.
139
140 const Int_t nClusters = fOutClusters->GetEntriesFast();
141
142 TClonesArray digits("AliEMCALDigit", 1);
143
144 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(digits.New(0));
145 digit->SetId(absId);
146 digit->SetIndexInList(0);
147 digit->SetType(AliEMCALDigit::kHG);
148 digit->SetAmplitude(e);
149
150 AliEMCALRecPoint recPoint("");
151 recPoint.AddDigit(*digit, e, kFALSE);
152 recPoint.EvalGlobalPosition(0, &digits);
153
154 TVector3 gpos;
155 recPoint.GetGlobalPosition(gpos);
156 Float_t g[3];
157 gpos.GetXYZ(g);
158
159 AliVCluster *cluster = static_cast<AliVCluster*>(fOutClusters->New(nClusters));
160 cluster->SetType(AliVCluster::kEMCALClusterv1);
161 cluster->SetE(recPoint.GetEnergy());
162 cluster->SetPosition(g);
163 cluster->SetNCells(1);
164 UShort_t shortAbsId = absId;
165 cluster->SetCellsAbsId(&shortAbsId);
166 Double32_t fract = 1;
167 cluster->SetCellsAmplitudeFraction(&fract);
168 cluster->SetID(nClusters);
169 cluster->SetEmcCpvDistance(-1);
a825589f 170 if (fMarkMC)
171 cluster->SetChi2(100); // MC flag!
ffe32451 172
173 return cluster;
174}
175
176//________________________________________________________________________
177AliPicoTrack* AliJetModelBaseTask::AddTrack(Double_t pt, Double_t eta, Double_t phi)
178{
179 // Add a track to the event.
180
181 const Int_t nTracks = fOutTracks->GetEntriesFast();
182
183 if (pt < 0)
184 pt = GetRandomPt();
185 if (eta < -100)
186 eta = GetRandomEta();
187 if (phi < 0)
188 phi = GetRandomPhi();
189
a825589f 190 Int_t label = fMarkMC ? 100 : 0;
191
ffe32451 192 AliPicoTrack *track = new ((*fOutTracks)[nTracks]) AliPicoTrack(pt,
193 eta,
194 phi,
195 1,
a825589f 196 label, // MC flag!
ffe32451 197 0,
198 0,
199 kFALSE);
200 return track;
201}
202
203//________________________________________________________________________
204void AliJetModelBaseTask::CopyClusters()
205{
206 // Copy all the clusters in the new collection
207
208 Bool_t esdMode = (Bool_t)(fClusters->GetClass()->GetBaseClass("AliESDCaloCluster") != 0);
209 const Int_t nClusters = fClusters->GetEntriesFast();
56cc432c 210 Int_t nCopiedClusters = 0;
ffe32451 211
212 if (esdMode) {
213 for (Int_t i = 0; i < nClusters; ++i) {
214 AliESDCaloCluster *esdcluster = static_cast<AliESDCaloCluster*>(fClusters->At(i));
56cc432c 215 if (!esdcluster || !esdcluster->IsEMCAL())
ffe32451 216 continue;
56cc432c 217 new ((*fOutClusters)[nCopiedClusters]) AliESDCaloCluster(*esdcluster);
218 nCopiedClusters++;
ffe32451 219 }
220 }
221 else {
222 for (Int_t i = 0; i < nClusters; ++i) {
223 AliAODCaloCluster *aodcluster = static_cast<AliAODCaloCluster*>(fClusters->At(i));
56cc432c 224 if (!aodcluster || !aodcluster->IsEMCAL())
ffe32451 225 continue;
56cc432c 226 new ((*fOutClusters)[nCopiedClusters]) AliAODCaloCluster(*aodcluster);
227 nCopiedClusters++;
ffe32451 228 }
229 }
230}
231
232//________________________________________________________________________
233void AliJetModelBaseTask::CopyTracks()
234{
235 const Int_t nTracks = fTracks->GetEntriesFast();
56cc432c 236 Int_t nCopiedTracks = 0;
ffe32451 237 for (Int_t i = 0; i < nTracks; ++i) {
238 AliPicoTrack *track = static_cast<AliPicoTrack*>(fTracks->At(i));
239 if (!track)
240 continue;
56cc432c 241 new ((*fOutTracks)[nCopiedTracks]) AliPicoTrack(*track);
242 nCopiedTracks++;
ffe32451 243 }
244}
245
246//________________________________________________________________________
247void AliJetModelBaseTask::ExecOnce()
762e8424 248{
249 // Init task.
250
251 if (fPtMax < fPtMin) {
252 AliWarning (Form("PtMax (%f) < PtMin (%f), setting PtMax = PtMin = %f", fPtMax, fPtMin, fPtMin));
253 fPtMax = fPtMin;
254 }
255
256 if (fEtaMax < fEtaMin) {
257 AliWarning (Form("EtaMax (%f) < EtaMin (%f), setting EtaMax = EtaMin = %f", fEtaMax, fEtaMin, fEtaMin));
258 fEtaMax = fEtaMin;
259 }
260
261 if (fPhiMax < fPhiMin) {
262 AliWarning (Form("PhiMax (%f) < PhiMin (%f), setting PhiMax = PhiMin = %f", fPhiMax, fPhiMin, fPhiMin));
263 fPhiMax = fPhiMin;
264 }
265
a5621834 266 if (fNTracks > 0 && !fTracks && !fTracksName.IsNull()) {
762e8424 267 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
acd859a2 268 if (!fTracks) {
e44e8726 269 AliError(Form("%s: Couldn't retrieve tracks with name %s!", GetName(), fTracksName.Data()));
acd859a2 270 return;
271 }
e44e8726 272
273 if (!fTracks->GetClass()->GetBaseClass("AliPicoTrack")) {
274 AliError(Form("%s: Collection %s does not contain AliPicoTrack objects!", GetName(), fTracksName.Data()));
275 fTracks = 0;
762e8424 276 return;
277 }
762e8424 278
279 if (!fOutTracks) {
280 fOutTracksName = fTracksName;
281 if (fCopyArray) {
282 fOutTracksName += fSuffix;
e44e8726 283 fOutTracks = new TClonesArray("AliPicoTrack", fTracks->GetSize());
762e8424 284 fOutTracks->SetName(fOutTracksName);
285 }
286 else {
287 fOutTracks = fTracks;
288 }
289 }
290
291 if (fCopyArray) {
292 if (!(InputEvent()->FindListObject(fOutTracksName)))
293 InputEvent()->AddObject(fOutTracks);
762e8424 294 }
295 }
296
a5621834 297 if (fNClusters > 0 && !fClusters && !fCaloName.IsNull()) {
762e8424 298 fClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
299
300 if (!fClusters) {
e44e8726 301 AliError(Form("%s: Couldn't retrieve clusters with name %s!", GetName(), fCaloName.Data()));
302 return;
303 }
304
305 if (!fClusters->GetClass()->GetBaseClass("AliVCluster")) {
306 AliError(Form("%s: Collection %s does not contain AliVCluster objects!", GetName(), fCaloName.Data()));
307 fClusters = 0;
762e8424 308 return;
309 }
310
311 if (!fOutClusters) {
312 fOutCaloName = fCaloName;
313 if (fCopyArray) {
314 fOutCaloName += fSuffix;
e44e8726 315 fOutClusters = new TClonesArray(fClusters->GetClass()->GetName(), fClusters->GetSize());
762e8424 316 fOutClusters->SetName(fOutCaloName);
317 }
318 else {
319 fOutClusters = fClusters;
320 }
321 }
322
323 if (fCopyArray) {
324 if (!(InputEvent()->FindListObject(fOutCaloName)))
325 InputEvent()->AddObject(fOutClusters);
762e8424 326 }
762e8424 327
bb838b50 328 if (!fGeom) {
329 if (fGeomName.Length() > 0) {
330 fGeom = AliEMCALGeometry::GetInstance(fGeomName);
331 if (!fGeom)
332 AliError(Form("Could not get geometry with name %s!", fGeomName.Data()));
333 } else {
334 fGeom = AliEMCALGeometry::GetInstance();
335 if (!fGeom)
336 AliError("Could not get default geometry!");
337 }
762e8424 338 }
bb838b50 339
3d0b9d27 340 const Double_t EmcalMinEta = fGeom->GetArm1EtaMin();
341 const Double_t EmcalMaxEta = fGeom->GetArm1EtaMax();
342 const Double_t EmcalMinPhi = fGeom->GetArm1PhiMin() * TMath::DegToRad();
343 const Double_t EmcalMaxPhi = fGeom->GetArm1PhiMax() * TMath::DegToRad();
344
345 if (fEtaMax > EmcalMaxEta) fEtaMax = EmcalMaxEta;
346 if (fEtaMax < EmcalMinEta) fEtaMax = EmcalMinEta;
347 if (fEtaMin > EmcalMaxEta) fEtaMin = EmcalMaxEta;
348 if (fEtaMin < EmcalMinEta) fEtaMin = EmcalMinEta;
762e8424 349
3d0b9d27 350 if (fPhiMax > EmcalMaxPhi) fPhiMax = EmcalMaxPhi;
351 if (fPhiMax < EmcalMinPhi) fPhiMax = EmcalMinPhi;
352 if (fPhiMin > EmcalMaxPhi) fPhiMin = EmcalMaxPhi;
353 if (fPhiMin < EmcalMinPhi) fPhiMin = EmcalMinPhi;
762e8424 354 }
355}
356
357//________________________________________________________________________
358void AliJetModelBaseTask::GetRandomCell(Double_t &eta, Double_t &phi, Int_t &absId)
359{
acd859a2 360 // Get random cell.
361
762e8424 362 Int_t repeats = 0;
05debff6 363 Double_t rndEta = eta;
364 Double_t rndPhi = phi;
762e8424 365 do {
05debff6 366 if (eta < -100)
367 rndEta = GetRandomEta();
368 if (phi < 0)
369 rndPhi = GetRandomPhi();
370 fGeom->GetAbsCellIdFromEtaPhi(rndEta, rndPhi, absId);
762e8424 371 repeats++;
372 } while (absId == -1 && repeats < 100);
373
374 if (!(absId > -1)) {
375 AliWarning(Form("Could not extract random cluster! Random eta-phi extracted more than 100 times!\n"
376 "eta [%f, %f], phi [%f, %f]\n", fEtaMin, fEtaMax, fPhiMin, fPhiMax));
377 }
05debff6 378 else {
379 eta = rndEta;
380 phi = rndPhi;
381 }
762e8424 382}
383
384//________________________________________________________________________
385Double_t AliJetModelBaseTask::GetRandomEta()
386{
acd859a2 387 // Get random eta.
388
762e8424 389 return gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
390}
391
392//________________________________________________________________________
393Double_t AliJetModelBaseTask::GetRandomPhi()
394{
acd859a2 395 // Get random phi.
396
762e8424 397 return gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
398}
399
400//________________________________________________________________________
401Double_t AliJetModelBaseTask::GetRandomPt()
402{
acd859a2 403 // Get random pt.
404
e44e8726 405 if (fPtSpectrum)
406 return fPtSpectrum->GetRandom();
407 else
408 return gRandom->Rndm() * (fPtMax - fPtMin) + fPtMin;
762e8424 409}
410
762e8424 411//________________________________________________________________________
412void AliJetModelBaseTask::Run()
413{
acd859a2 414 // Run.
762e8424 415}