1 // $Id: AliJetEmbeddingFromAODTask.cxx $
3 // Jet embedding from AOD task.
5 // Author: S.Aiola, C.Loizides
7 #include "AliJetEmbeddingFromAODTask.h"
11 #include <TClonesArray.h>
12 #include <TObjArray.h>
13 #include <TObjString.h>
17 #include <TStreamerInfo.h>
20 #include "AliVEvent.h"
21 #include "AliAODTrack.h"
22 #include "AliESDtrack.h"
23 #include "AliPicoTrack.h"
24 #include "AliVTrack.h"
25 #include "AliVCluster.h"
26 #include "AliVCaloCells.h"
27 #include "AliAODMCParticle.h"
28 #include "AliCentrality.h"
29 #include "AliVHeader.h"
30 #include "AliVVertex.h"
31 #include "AliAODHeader.h"
33 #include "AliInputEventHandler.h"
35 ClassImp(AliJetEmbeddingFromAODTask)
37 //________________________________________________________________________
38 AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask() :
39 AliJetModelBaseTask("AliJetEmbeddingFromAODTask"),
41 fRandomAccess(kFALSE),
48 fAODMCParticlesName(),
51 fTriggerMask(AliVEvent::kAny),
54 fUseNegativeLabels(kTRUE),
76 // Default constructor.
77 SetSuffix("AODEmbedding");
79 fAODfilterBits[0] = -1;
80 fAODfilterBits[1] = -1;
83 //________________________________________________________________________
84 AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask(const char *name, Bool_t drawqa) :
85 AliJetModelBaseTask(name, drawqa),
87 fRandomAccess(kFALSE),
88 fAODTreeName("aodTree"),
89 fAODHeaderName("header"),
90 fAODVertexName("vertices"),
91 fAODTrackName("tracks"),
93 fAODCellsName("emcalCells"),
94 fAODMCParticlesName(AliAODMCParticle::StdBranchName()),
97 fTriggerMask(AliVEvent::kAny),
100 fUseNegativeLabels(kTRUE),
105 fEsdTreeMode(kFALSE),
107 fCurrentAODFileID(0),
109 fPicoTrackVersion(0),
117 fCurrentAODEntry(-1),
118 fHistFileMatching(0),
119 fHistAODFileError(0),
122 // Standard constructor.
123 SetSuffix("AODEmbedding");
125 fAODfilterBits[0] = -1;
126 fAODfilterBits[1] = -1;
129 //________________________________________________________________________
130 AliJetEmbeddingFromAODTask::~AliJetEmbeddingFromAODTask()
134 if (fCurrentAODFile) {
135 fCurrentAODFile->Close();
136 delete fCurrentAODFile;
140 //________________________________________________________________________
141 void AliJetEmbeddingFromAODTask::UserCreateOutputObjects()
146 AliJetModelBaseTask::UserCreateOutputObjects();
148 fHistFileMatching = new TH2C("fHistFileMatching", "fHistFileMatching", fTotalFiles, -0.5, fTotalFiles - 0.5, fFileList->GetEntriesFast(), -0.5, fFileList->GetEntriesFast() -0.5);
149 fHistFileMatching->GetXaxis()->SetTitle("File no. (PYTHIA)");
150 fHistFileMatching->GetYaxis()->SetTitle("File no. (Embedded AOD)");
151 fHistFileMatching->GetZaxis()->SetTitle("counts");
152 fOutput->Add(fHistFileMatching);
154 fHistAODFileError = new TH1C("fHistAODFileError", "fHistAODFileError", fFileList->GetEntriesFast(), -0.5, fFileList->GetEntriesFast() -0.5);
155 fHistAODFileError->GetXaxis()->SetTitle("File no. (Embedded AOD)");
156 fHistAODFileError->GetYaxis()->SetTitle("counts");
157 fOutput->Add(fHistAODFileError);
159 fHistNotEmbedded = new TH1C("fHistNotEmbedded", "fHistNotEmbedded", fTotalFiles, -0.5, fTotalFiles - 0.5);
160 fHistNotEmbedded->GetXaxis()->SetTitle("File no. (PYTHIA)");
161 fHistNotEmbedded->GetYaxis()->SetTitle("counts");
162 fOutput->Add(fHistNotEmbedded);
164 PostData(1, fOutput);
167 //________________________________________________________________________
168 Bool_t AliJetEmbeddingFromAODTask::UserNotify()
170 TString path(fInputHandler->GetTree()->GetCurrentFile()->GetPath());
171 if (path.EndsWith("/"))
172 path.Remove(path.Length()-1);
173 path.Remove(path.Last('/'));
174 path.Remove(0, path.Last('/')+1);
176 AliWarning(Form("Could not extract file number from path %s", path.Data()));
179 fCurrentFileID = path.Atoi();
180 if (!fRandomAccess) {
181 fCurrentAODFileID = fFileList->GetEntriesFast() * fCurrentFileID / fTotalFiles-1;
182 AliInfo(Form("Start embedding from file ID %d", fCurrentAODFileID));
187 //________________________________________________________________________
188 Bool_t AliJetEmbeddingFromAODTask::ExecOnce()
190 if (fAODTreeName.Contains("aod"))
191 fEsdTreeMode = kFALSE;
193 fEsdTreeMode = kTRUE;
195 return AliJetModelBaseTask::ExecOnce();
198 //________________________________________________________________________
199 Bool_t AliJetEmbeddingFromAODTask::OpenNextFile()
201 if (fCurrentAODFile) {
202 fCurrentAODFile->Close();
203 delete fCurrentAODFile;
212 AliDebug(3,Form("Failed to open file %s...", fileName.Data()));
213 if (fHistAODFileError)
214 fHistAODFileError->Fill(fCurrentAODFileID);
217 fileName = GetNextFileName();
219 if (fileName.IsNull())
222 if (fileName.BeginsWith("alien://") && !gGrid) {
223 AliInfo("Trying to connect to AliEn ...");
224 TGrid::Connect("alien://");
227 AliDebug(3,Form("Trying to open file %s...", fileName.Data()));
228 fCurrentAODFile = TFile::Open(fileName);
232 } while ((!fCurrentAODFile || fCurrentAODFile->IsZombie()) && i < fAttempts);
234 if (!fCurrentAODFile || fCurrentAODFile->IsZombie())
237 const TList *clist = fCurrentAODFile->GetStreamerInfoCache();
239 TStreamerInfo *cinfo = static_cast<TStreamerInfo*>(clist->FindObject("AliPicoTrack"));
241 fPicoTrackVersion = cinfo->GetClassVersion();
243 fPicoTrackVersion = 0;
246 fCurrentAODTree = static_cast<TTree*>(fCurrentAODFile->Get(fAODTreeName));
247 if (!fCurrentAODTree)
250 if (!fAODHeaderName.IsNull())
251 fCurrentAODTree->SetBranchAddress(fAODHeaderName, &fAODHeader);
253 if (!fAODVertexName.IsNull())
254 fCurrentAODTree->SetBranchAddress(fAODVertexName, &fAODVertex);
256 if (!fAODTrackName.IsNull())
257 fCurrentAODTree->SetBranchAddress(fAODTrackName, &fAODTracks);
259 if (!fAODClusName.IsNull())
260 fCurrentAODTree->SetBranchAddress(fAODClusName, &fAODClusters);
262 if (!fAODCellsName.IsNull())
263 fCurrentAODTree->SetBranchAddress(fAODCellsName, &fAODCaloCells);
265 if (!fAODMCParticlesName.IsNull())
266 fCurrentAODTree->SetBranchAddress(fAODMCParticlesName, &fAODMCParticles);
269 fCurrentAODEntry = TMath::Nint(gRandom->Rndm()*fCurrentAODTree->GetEntries());
271 fCurrentAODEntry = 0;
273 AliDebug(2,Form("Will start embedding from entry %d", fCurrentAODEntry));
275 if (fHistFileMatching)
276 fHistFileMatching->Fill(fCurrentFileID, fCurrentAODFileID-1);
281 //________________________________________________________________________
282 TString AliJetEmbeddingFromAODTask::GetNextFileName()
285 fCurrentAODFileID = TMath::Nint(gRandom->Rndm()*fFileList->GetEntriesFast());
289 if (fCurrentAODFileID >= fFileList->GetEntriesFast())
292 TObjString *objFileName = static_cast<TObjString*>(fFileList->At(fCurrentAODFileID));
293 return objFileName->GetString();
296 //________________________________________________________________________
297 Bool_t AliJetEmbeddingFromAODTask::GetNextEntry()
302 if (!fCurrentAODFile || !fCurrentAODTree || fCurrentAODEntry >= fCurrentAODTree->GetEntries()) {
307 fCurrentAODTree->GetEntry(fCurrentAODEntry);
311 if (attempts == 1000)
312 AliWarning("After 1000 attempts no event has been accepted by the event selection (trigger, centrality...)!");
314 } while (!IsAODEventSelected() && fCurrentAODTree);
316 return (fCurrentAODTree!=0);
319 //________________________________________________________________________
320 Bool_t AliJetEmbeddingFromAODTask::IsAODEventSelected()
322 if (!fEsdTreeMode && fAODHeader) {
323 AliAODHeader *aodHeader = static_cast<AliAODHeader*>(fAODHeader);
325 if (fTriggerMask != AliVEvent::kAny) {
326 UInt_t offlineTrigger = aodHeader->GetOfflineTrigger();
328 if ((offlineTrigger & fTriggerMask) == 0) {
329 AliDebug(2,Form("Event rejected due to physics selection. Event trigger mask: %d, trigger mask selection: %d.", offlineTrigger, fTriggerMask));
334 if (fMinCentrality >= 0) {
335 AliCentrality *cent = aodHeader->GetCentralityP();
336 Float_t centVal = cent->GetCentralityPercentile("V0M");
337 if (centVal < fMinCentrality || centVal >= fMaxCentrality) {
338 AliDebug(2,Form("Event rejected due to centrality selection. Event centrality: %f, centrality range selection: %f to %f", centVal, fMinCentrality, fMaxCentrality));
345 Double_t vert[3]={0};
346 ((AliVVertex*)fAODVertex->At(0))->GetXYZ(vert);
347 if (TMath::Abs(vert[2]) > fZVertexCut) {
348 AliDebug(2,Form("Event rejected due to Z vertex selection. Event Z vertex: %f, Z vertex cut: %f", vert[2], fZVertexCut));
356 //________________________________________________________________________
357 void AliJetEmbeddingFromAODTask::Run()
359 if (!GetNextEntry()) {
360 if (fHistNotEmbedded)
361 fHistNotEmbedded->Fill(fCurrentFileID);
362 AliError("Unable to get the AOD event to embed. Nothing will be embedded.");
366 if (fOutMCParticles) {
368 if (fCopyArray && fMCParticles)
371 if (fAODMCParticles) {
372 for (Int_t i = 0; i < fAODMCParticles->GetEntriesFast(); i++) {
373 AliAODMCParticle *part = static_cast<AliAODMCParticle*>(fAODMCParticles->At(i));
375 AliError(Form("Could not find MC particle %d in branch %s of tree %s!", i, fAODMCParticlesName.Data(), fAODTreeName.Data()));
379 if (!part->IsPhysicalPrimary())
382 AliDebug(3, Form("Embedding MC particle with pT = %f, eta = %f, phi = %f", part->Pt(), part->Eta(), part->Phi()));
383 AddMCParticle(part, i);
390 if (fCopyArray && fTracks)
394 AliDebug(2, Form("%d tracks will be processed for embedding.", fAODTracks->GetEntriesFast()));
395 for (Int_t i = 0; i < fAODTracks->GetEntriesFast(); i++) {
396 AliVTrack *track = static_cast<AliVTrack*>(fAODTracks->At(i));
398 AliError(Form("Could not find track %d in branch %s of tree %s!", i, fAODTrackName.Data(), fAODTreeName.Data()));
403 Bool_t isEmc = kFALSE;
405 AliAODTrack *aodtrack = static_cast<AliAODTrack*>(track);
406 if (aodtrack->TestFilterBit(fAODfilterBits[0])) {
409 else if (aodtrack->TestFilterBit(fAODfilterBits[1])) {
410 if ((aodtrack->GetStatus()&AliESDtrack::kITSrefit)==0) {
420 else { /*not a good track*/
424 if (TMath::Abs(aodtrack->GetTrackEtaOnEMCal()) < 0.75 &&
425 aodtrack->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() &&
426 aodtrack->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad())
429 else if (fPicoTrackVersion > 0) { /*not AOD mode, let's see if it is PicoTrack*/
430 AliPicoTrack *ptrack = dynamic_cast<AliPicoTrack*>(track);
432 if (fPicoTrackVersion >= 3)
433 type = ptrack->GetTrackType();
435 type = ptrack->GetLabel();
436 isEmc = ptrack->IsEMCAL();
440 if (fTrackEfficiency < 1) {
441 Double_t r = gRandom->Rndm();
442 if (fTrackEfficiency < r)
448 if (fUseNegativeLabels)
449 label = track->GetLabel();
451 label = TMath::Abs(track->GetLabel());
454 AliWarning(Form("%s: Track %d with label==0", GetName(), i));
459 AliDebug(3, Form("Embedding track with pT = %f, eta = %f, phi = %f, label = %d", track->Pt(), track->Eta(), track->Phi(), label));
460 AddTrack(track->Pt(), track->Eta(), track->Phi(), type, track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), isEmc, label);
467 if (fCopyArray && fClusters)
471 for (Int_t i = 0; i < fAODClusters->GetEntriesFast(); i++) {
472 AliVCluster *clus = static_cast<AliVCluster*>(fAODClusters->At(i));
474 AliError(Form("Could not find cluster %d in branch %s of tree %s!", i, fAODClusName.Data(), fAODTreeName.Data()));
478 Double_t vert[3] = {0,0,0};
479 clus->GetMomentum(vect,vert);
480 AddCluster(clus->E(), vect.Eta(), vect.Phi(), clus->GetLabel());
487 Int_t totalCells = 0;
490 totalCells += fCaloCells->GetNumberOfCells();
492 totalCells += fAODCaloCells->GetNumberOfCells();
494 SetNumberOfOutCells(totalCells);
500 for (Short_t i = 0; i < fAODCaloCells->GetNumberOfCells(); i++) {
504 Short_t cellNum = -1;
507 fAODCaloCells->GetCell(i, cellNum, amp, time, mclabel, efrac);
508 AliDebug(3,Form("Adding cell with amplitude %f, absolute ID %d, time %f", amp, cellNum, time));
509 AddCell(amp, cellNum, time, mclabel);
513 AliDebug(2,Form("Added cells = %d, total cells = %d", fAddedCells, totalCells));