5 // Author: S.Aiola, C.Loizides
7 #include "AliJetModelBaseTask.h"
9 #include <TClonesArray.h>
11 #include <TLorentzVector.h>
15 #include "AliVEvent.h"
16 #include "AliAODCaloCluster.h"
17 #include "AliESDCaloCluster.h"
18 #include "AliVCluster.h"
19 #include "AliEMCALDigit.h"
20 #include "AliEMCALRecPoint.h"
21 #include "AliESDCaloCells.h"
22 #include "AliAODCaloCells.h"
23 #include "AliVCaloCells.h"
24 #include "AliPicoTrack.h"
25 #include "AliEMCALGeometry.h"
28 ClassImp(AliJetModelBaseTask)
30 //________________________________________________________________________
31 AliJetModelBaseTask::AliJetModelBaseTask() :
32 AliAnalysisTaskSE("AliJetModelBaseTask"),
44 fPhiMax(TMath::Pi() * 2),
66 // Default constructor.
69 //________________________________________________________________________
70 AliJetModelBaseTask::AliJetModelBaseTask(const char *name, Bool_t drawqa) :
71 AliAnalysisTaskSE(name),
73 fTracksName("PicoTracks"),
74 fOutTracksName("PicoTracksEmbedded"),
75 fCaloName("CaloClustersCorr"),
76 fOutCaloName("CaloClustersCorrEmbedded"),
83 fPhiMax(TMath::Pi() * 2),
105 // Standard constructor.
108 DefineOutput(1, TList::Class());
112 //________________________________________________________________________
113 AliJetModelBaseTask::~AliJetModelBaseTask()
118 //________________________________________________________________________
119 void AliJetModelBaseTask::UserCreateOutputObjects()
121 // Create user output.
126 fOutput = new TList();
129 PostData(1, fOutput);
132 //________________________________________________________________________
133 void AliJetModelBaseTask::UserExec(Option_t *)
135 // Execute per event.
138 fIsInit = ExecOnce();
145 fOutTracks->Delete();
147 fOutClusters->Delete();
150 AliVCaloCells *tempCaloCells = 0;
155 tempCaloCells = fCaloCells;
156 fCaloCells = static_cast<AliVCaloCells*>(tempCaloCells->Clone(Form("%s_old",fCaloCells->GetName())));
164 fCaloCells = tempCaloCells;
168 //________________________________________________________________________
169 Bool_t AliJetModelBaseTask::ExecOnce()
174 gRandom = new TRandom3(0);
176 fEsdMode = InputEvent()->InheritsFrom("AliESDEvent");
178 if (fPtMax < fPtMin) {
179 AliWarning (Form("PtMax (%f) < PtMin (%f), setting PtMax = PtMin = %f", fPtMax, fPtMin, fPtMin));
183 if (fEtaMax < fEtaMin) {
184 AliWarning (Form("EtaMax (%f) < EtaMin (%f), setting EtaMax = EtaMin = %f", fEtaMax, fEtaMin, fEtaMin));
188 if (fPhiMax < fPhiMin) {
189 AliWarning (Form("PhiMax (%f) < PhiMin (%f), setting PhiMax = PhiMin = %f", fPhiMax, fPhiMin, fPhiMin));
193 if (!fCaloCells && !fCellsName.IsNull()) {
194 fCaloCells = dynamic_cast<AliVCaloCells*>(InputEvent()->FindListObject(fCellsName));
196 AliError(Form("%s: Couldn't retrieve calo cells with name %s!", GetName(), fCellsName.Data()));
200 if (!fCaloCells->InheritsFrom("AliVCaloCells")) {
201 AliError(Form("%s: Collection %s does not contain a AliVCaloCells object!", GetName(), fCellsName.Data()));
206 if (!fOutCaloCells) {
207 fOutCellsName = fCellsName;
209 fOutCellsName += fSuffix;
212 fOutCaloCells = new AliESDCaloCells(fOutCellsName,fOutCellsName);
214 fOutCaloCells = new AliAODCaloCells(fOutCellsName,fOutCellsName);
216 if (InputEvent()->FindListObject(fOutCellsName)) {
217 AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fOutCellsName.Data()));
221 InputEvent()->AddObject(fOutCaloCells);
225 fOutCaloCells = fCaloCells;
230 if (fNTracks > 0 && !fTracks && !fTracksName.IsNull()) {
231 fTracks = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTracksName));
233 AliError(Form("%s: Couldn't retrieve tracks with name %s!", GetName(), fTracksName.Data()));
237 if (!fTracks->GetClass()->GetBaseClass("AliPicoTrack")) {
238 AliError(Form("%s: Collection %s does not contain AliPicoTrack objects!", GetName(), fTracksName.Data()));
244 fOutTracksName = fTracksName;
246 fOutTracksName += fSuffix;
247 fOutTracks = new TClonesArray("AliPicoTrack", fTracks->GetSize());
248 fOutTracks->SetName(fOutTracksName);
249 if (InputEvent()->FindListObject(fOutTracksName)) {
250 AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fOutTracksName.Data()));
254 InputEvent()->AddObject(fOutTracks);
258 fOutTracks = fTracks;
263 if (fNClusters > 0 && !fClusters && !fCaloName.IsNull()) {
264 fClusters = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fCaloName));
267 AliError(Form("%s: Couldn't retrieve clusters with name %s!", GetName(), fCaloName.Data()));
271 if (!fClusters->GetClass()->GetBaseClass("AliVCluster")) {
272 AliError(Form("%s: Collection %s does not contain AliVCluster objects!", GetName(), fCaloName.Data()));
278 fOutCaloName = fCaloName;
280 fOutCaloName += fSuffix;
281 fOutClusters = new TClonesArray(fClusters->GetClass()->GetName(), fClusters->GetSize());
282 fOutClusters->SetName(fOutCaloName);
283 if (InputEvent()->FindListObject(fOutCaloName)) {
284 AliFatal(Form("%s: Collection %s is already present in the event!", GetName(), fOutCaloName.Data()));
288 InputEvent()->AddObject(fOutClusters);
292 fOutClusters = fClusters;
297 if (!fCaloName.IsNull() || !fCellsName.IsNull()) {
299 if (fGeomName.Length() > 0) {
300 fGeom = AliEMCALGeometry::GetInstance(fGeomName);
302 AliError(Form("Could not get geometry with name %s!", fGeomName.Data()));
304 fGeom = AliEMCALGeometry::GetInstance();
306 AliError("Could not get default geometry!");
310 const Double_t EmcalMinEta = fGeom->GetArm1EtaMin();
311 const Double_t EmcalMaxEta = fGeom->GetArm1EtaMax();
312 const Double_t EmcalMinPhi = fGeom->GetArm1PhiMin() * TMath::DegToRad();
313 const Double_t EmcalMaxPhi = fGeom->GetArm1PhiMax() * TMath::DegToRad();
315 if (fEtaMax > EmcalMaxEta) fEtaMax = EmcalMaxEta;
316 if (fEtaMax < EmcalMinEta) fEtaMax = EmcalMinEta;
317 if (fEtaMin > EmcalMaxEta) fEtaMin = EmcalMaxEta;
318 if (fEtaMin < EmcalMinEta) fEtaMin = EmcalMinEta;
320 if (fPhiMax > EmcalMaxPhi) fPhiMax = EmcalMaxPhi;
321 if (fPhiMax < EmcalMinPhi) fPhiMax = EmcalMinPhi;
322 if (fPhiMin > EmcalMaxPhi) fPhiMin = EmcalMaxPhi;
323 if (fPhiMin < EmcalMinPhi) fPhiMin = EmcalMinPhi;
329 //________________________________________________________________________
330 Int_t AliJetModelBaseTask::SetNumberOfOutCells(Int_t n)
332 if (fOutCaloCells->GetNumberOfCells() < n) {
333 fOutCaloCells->DeleteContainer();
334 fOutCaloCells->CreateContainer(n);
337 fOutCaloCells->SetNumberOfCells(n);
345 //________________________________________________________________________
346 void AliJetModelBaseTask::CopyCells()
348 for (Short_t i = 0; i < fCaloCells->GetNumberOfCells(); i++) {
349 Short_t mclabel = -1;
352 Short_t cellNum = -1;
355 fCaloCells->GetCell(i, cellNum, amp, time, mclabel, efrac);
356 fOutCaloCells->SetCell(i, cellNum, amp, time, mclabel, efrac);
359 fAddedCells = fCaloCells->GetNumberOfCells();
361 AliDebug(2, Form("%d cells from the PYTHIA event", fAddedCells));
364 //________________________________________________________________________
365 Int_t AliJetModelBaseTask::AddCell(Double_t e, Double_t eta, Double_t phi)
367 // Add a cell to the event.
370 if (eta < -100 || phi < 0) {
371 GetRandomCell(eta, phi, absId);
374 fGeom->EtaPhiFromIndex(absId, eta, phi);
378 AliWarning(Form("Unable to embed cell in eta = %f, phi = %f!"
379 " Maybe the eta-phi range is not inside the EMCal acceptance (eta = [%f, %f], phi = [%f, %f])",
380 eta, phi, fEtaMin, fEtaMax, fPhiMin, fPhiMax));
385 Double_t pt = GetRandomPt();
386 TLorentzVector nPart;
387 nPart.SetPtEtaPhiM(pt, eta, phi, 0);
391 return AddCell(e, absId);
394 //________________________________________________________________________
395 Int_t AliJetModelBaseTask::AddCell(Double_t e, Int_t absId, Double_t time)
397 // Add a cell to the event.
399 Bool_t r = fOutCaloCells->SetCell(fAddedCells, absId, e, time, fMarkMC, 0);
411 //________________________________________________________________________
412 AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Double_t eta, Double_t phi)
414 // Add a cluster to the event.
417 if (eta < -100 || phi < 0) {
418 GetRandomCell(eta, phi, absId);
421 fGeom->EtaPhiFromIndex(absId, eta, phi);
425 AliWarning(Form("Unable to embed cluster in eta = %f, phi = %f!"
426 " Maybe the eta-phi range is not inside the EMCal acceptance (eta = [%f, %f], phi = [%f, %f])",
427 eta, phi, fEtaMin, fEtaMax, fPhiMin, fPhiMax));
432 Double_t pt = GetRandomPt();
433 TLorentzVector nPart;
434 nPart.SetPtEtaPhiM(pt, eta, phi, 0);
438 return AddCluster(e, absId);
441 //________________________________________________________________________
442 AliVCluster* AliJetModelBaseTask::AddCluster(Double_t e, Int_t absId)
444 // Add a cluster to the event.
446 const Int_t nClusters = fOutClusters->GetEntriesFast();
448 TClonesArray digits("AliEMCALDigit", 1);
450 AliEMCALDigit *digit = static_cast<AliEMCALDigit*>(digits.New(0));
452 digit->SetIndexInList(0);
453 digit->SetType(AliEMCALDigit::kHG);
454 digit->SetAmplitude(e);
456 AliEMCALRecPoint recPoint("");
457 recPoint.AddDigit(*digit, e, kFALSE);
458 recPoint.EvalGlobalPosition(0, &digits);
461 recPoint.GetGlobalPosition(gpos);
465 AliVCluster *cluster = static_cast<AliVCluster*>(fOutClusters->New(nClusters));
466 cluster->SetType(AliVCluster::kEMCALClusterv1);
467 cluster->SetE(recPoint.GetEnergy());
468 cluster->SetPosition(g);
469 cluster->SetNCells(1);
470 UShort_t shortAbsId = absId;
471 cluster->SetCellsAbsId(&shortAbsId);
472 Double32_t fract = 1;
473 cluster->SetCellsAmplitudeFraction(&fract);
474 cluster->SetID(nClusters);
475 cluster->SetEmcCpvDistance(-1);
479 AliESDCaloCluster *esdClus = static_cast<AliESDCaloCluster*>(cluster);
480 TArrayI parents(1, &fMarkMC);
481 esdClus->AddLabels(parents);
484 AliAODCaloCluster *aodClus = static_cast<AliAODCaloCluster*>(cluster);
485 aodClus->SetLabel(&fMarkMC, 1);
491 //________________________________________________________________________
492 AliPicoTrack* AliJetModelBaseTask::AddTrack(Double_t pt, Double_t eta, Double_t phi, Byte_t type, Double_t etaemc, Double_t phiemc, Bool_t ise)
494 // Add a track to the event.
496 const Int_t nTracks = fOutTracks->GetEntriesFast();
501 eta = GetRandomEta();
503 phi = GetRandomPhi();
505 AliPicoTrack *track = new ((*fOutTracks)[nTracks]) AliPicoTrack(pt,
518 //________________________________________________________________________
519 void AliJetModelBaseTask::CopyClusters()
521 // Copy all the clusters in the new collection
523 const Int_t nClusters = fClusters->GetEntriesFast();
524 Int_t nCopiedClusters = 0;
527 for (Int_t i = 0; i < nClusters; ++i) {
528 AliESDCaloCluster *esdcluster = static_cast<AliESDCaloCluster*>(fClusters->At(i));
529 if (!esdcluster || !esdcluster->IsEMCAL())
531 new ((*fOutClusters)[nCopiedClusters]) AliESDCaloCluster(*esdcluster);
536 for (Int_t i = 0; i < nClusters; ++i) {
537 AliAODCaloCluster *aodcluster = static_cast<AliAODCaloCluster*>(fClusters->At(i));
538 if (!aodcluster || !aodcluster->IsEMCAL())
540 new ((*fOutClusters)[nCopiedClusters]) AliAODCaloCluster(*aodcluster);
546 //________________________________________________________________________
547 void AliJetModelBaseTask::CopyTracks()
549 const Int_t nTracks = fTracks->GetEntriesFast();
550 Int_t nCopiedTracks = 0;
551 for (Int_t i = 0; i < nTracks; ++i) {
552 AliPicoTrack *track = static_cast<AliPicoTrack*>(fTracks->At(i));
555 new ((*fOutTracks)[nCopiedTracks]) AliPicoTrack(*track);
560 //________________________________________________________________________
561 void AliJetModelBaseTask::GetRandomCell(Double_t &eta, Double_t &phi, Int_t &absId)
566 Double_t rndEta = eta;
567 Double_t rndPhi = phi;
570 rndEta = GetRandomEta();
572 rndPhi = GetRandomPhi();
573 fGeom->GetAbsCellIdFromEtaPhi(rndEta, rndPhi, absId);
575 } while (absId == -1 && repeats < 100);
578 AliWarning(Form("Could not extract random cluster! Random eta-phi extracted more than 100 times!\n"
579 "eta [%f, %f], phi [%f, %f]\n", fEtaMin, fEtaMax, fPhiMin, fPhiMax));
587 //________________________________________________________________________
588 Double_t AliJetModelBaseTask::GetRandomEta()
592 return gRandom->Rndm() * (fEtaMax - fEtaMin) + fEtaMin;
595 //________________________________________________________________________
596 Double_t AliJetModelBaseTask::GetRandomPhi()
600 return gRandom->Rndm() * (fPhiMax - fPhiMin) + fPhiMin;
603 //________________________________________________________________________
604 Double_t AliJetModelBaseTask::GetRandomPt()
609 return fPtSpectrum->GetRandom();
611 return gRandom->Rndm() * (fPtMax - fPtMin) + fPtMin;
614 //________________________________________________________________________
615 void AliJetModelBaseTask::Run()