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>
19 #include "AliVEvent.h"
20 #include "AliAODTrack.h"
21 #include "AliESDtrack.h"
22 #include "AliPicoTrack.h"
23 #include "AliVTrack.h"
24 #include "AliVCluster.h"
25 #include "AliVCaloCells.h"
26 #include "AliCentrality.h"
27 #include "AliVHeader.h"
28 #include "AliVVertex.h"
29 #include "AliAODHeader.h"
31 #include "AliInputEventHandler.h"
33 ClassImp(AliJetEmbeddingFromAODTask)
35 //________________________________________________________________________
36 AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask() :
37 AliJetModelBaseTask("AliJetEmbeddingFromAODTask"),
47 fTriggerMask(AliVEvent::kAny),
53 fCurrentAODFileID(-1),
63 // Default constructor.
64 SetSuffix("AODEmbedding");
66 fAODfilterBits[0] = -1;
67 fAODfilterBits[1] = -1;
70 //________________________________________________________________________
71 AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask(const char *name, Bool_t drawqa) :
72 AliJetModelBaseTask(name, drawqa),
74 fAODTreeName("aodTree"),
75 fAODHeaderName("header"),
76 fAODVertexName("vertices"),
77 fAODTrackName("tracks"),
78 fAODClusName("caloClusters"),
79 fAODCellsName("emcalCells"),
82 fTriggerMask(AliVEvent::kAny),
88 fCurrentAODFileID(-1),
98 // Standard constructor.
99 SetSuffix("AODEmbedding");
101 fAODfilterBits[0] = -1;
102 fAODfilterBits[1] = -1;
105 //________________________________________________________________________
106 AliJetEmbeddingFromAODTask::~AliJetEmbeddingFromAODTask()
110 if (fCurrentAODFile) {
111 fCurrentAODFile->Close();
112 delete fCurrentAODFile;
116 //________________________________________________________________________
117 void AliJetEmbeddingFromAODTask::UserCreateOutputObjects()
122 AliJetModelBaseTask::UserCreateOutputObjects();
124 fHistFileIDs = new TH2C("fHistFileIDs", "fHistFileIDs", fTotalFiles, -0.5, fTotalFiles - 0.5, fFileList->GetEntriesFast(), -0.5, fFileList->GetEntriesFast() -0.5);
125 fHistFileIDs->GetXaxis()->SetTitle("File no. (PYTHIA)");
126 fHistFileIDs->GetYaxis()->SetTitle("File no. (Embedded AOD)");
127 fOutput->Add(fHistFileIDs);
129 PostData(1, fOutput);
132 //________________________________________________________________________
133 Bool_t AliJetEmbeddingFromAODTask::UserNotify()
135 TString path(fInputHandler->GetTree()->GetCurrentFile()->GetPath());
136 if (path.EndsWith("/"))
137 path.Remove(path.Length()-1);
138 path.Remove(path.Last('/'));
139 path.Remove(0, path.Last('/')+1);
141 AliWarning(Form("Could not extract file number from path %s", path.Data()));
144 fCurrentFileID = path.Atoi();
145 fCurrentAODFileID = fFileList->GetEntriesFast() * fCurrentFileID / fTotalFiles;
146 AliInfo(Form("Start embedding from file ID %d", fCurrentAODFileID));
150 //________________________________________________________________________
151 Bool_t AliJetEmbeddingFromAODTask::ExecOnce()
153 if (fAODTreeName.Contains("aod"))
154 fEsdTreeMode = kFALSE;
156 fEsdTreeMode = kTRUE;
158 return AliJetModelBaseTask::ExecOnce();
161 //________________________________________________________________________
162 Bool_t AliJetEmbeddingFromAODTask::OpenNextFile()
164 if (fCurrentAODFile) {
165 fCurrentAODFile->Close();
166 delete fCurrentAODFile;
170 if (fCurrentAODFileID >= fFileList->GetEntriesFast())
173 TObjString *objFileName = static_cast<TObjString*>(fFileList->At(fCurrentAODFileID));
174 TString fileName = objFileName->GetString();
176 if (fileName.BeginsWith("alien://") && !gGrid) {
177 AliInfo("Trying to connect to AliEn ...");
178 TGrid::Connect("alien://");
181 fCurrentAODFile = TFile::Open(fileName);
183 if (!fCurrentAODFile || fCurrentAODFile->IsZombie()) {
187 const TList *clist = fCurrentAODFile->GetStreamerInfoCache();
189 TStreamerInfo *cinfo = static_cast<TStreamerInfo*>(clist->FindObject("AliPicoTrack"));
191 fPicoTrackVersion = cinfo->GetClassVersion();
193 fPicoTrackVersion = 0;
197 fHistFileIDs->Fill(fCurrentFileID, fCurrentAODFileID);
203 //________________________________________________________________________
204 Bool_t AliJetEmbeddingFromAODTask::GetNextEntry()
206 static TTree *tree = 0;
207 static Int_t entry = 0;
213 if (!fCurrentAODFile || !tree || entry >= tree->GetEntries()) {
217 tree = static_cast<TTree*>(fCurrentAODFile->Get(fAODTreeName));
221 if (!fAODHeaderName.IsNull())
222 tree->SetBranchAddress(fAODHeaderName, &fAODHeader);
224 if (!fAODVertexName.IsNull())
225 tree->SetBranchAddress(fAODVertexName, &fAODVertex);
227 if (!fAODTrackName.IsNull())
228 tree->SetBranchAddress(fAODTrackName, &fAODTracks);
230 if (!fAODClusName.IsNull())
231 tree->SetBranchAddress(fAODClusName, &fAODClusters);
233 if (!fAODCellsName.IsNull())
234 tree->SetBranchAddress(fAODCellsName, &fAODCaloCells);
239 tree->GetEntry(entry);
243 if (attempts == 1000)
244 AliWarning("After 1000 attempts no event has been accepted by the event selection (trigger, centrality...)!");
246 } while (!IsAODEventSelected() && tree);
251 //________________________________________________________________________
252 Bool_t AliJetEmbeddingFromAODTask::IsAODEventSelected()
254 if (!fEsdTreeMode && fAODHeader) {
255 AliAODHeader *aodHeader = static_cast<AliAODHeader*>(fAODHeader);
257 UInt_t offlineTrigger = aodHeader->GetOfflineTrigger();
259 if ((offlineTrigger & fTriggerMask) == 0) {
260 AliDebug(2, Form("Event rejected due to physics selection. Event trigger mask: %d, trigger mask selection: %d.", offlineTrigger, fTriggerMask));
264 AliCentrality *cent = aodHeader->GetCentralityP();
265 Float_t centVal = cent->GetCentralityPercentile("V0M");
266 if (centVal < fMinCentrality || centVal >= fMaxCentrality) {
267 AliDebug(2, Form("Event rejected due to centrality selection. Event centrality: %f, centrality range selection: %f to %f", centVal, fMinCentrality, fMaxCentrality));
273 Double_t vert[3]={0};
274 ((AliVVertex*)fAODVertex->At(0))->GetXYZ(vert);
275 if (TMath::Abs(vert[2]) > fZVertexCut) {
276 AliDebug(2,Form("Event rejected due to Z vertex selection. Event Z vertex: %f, Z vertex cut: %f", vert[2], fZVertexCut));
284 //________________________________________________________________________
285 void AliJetEmbeddingFromAODTask::Run()
287 if (!GetNextEntry()) {
288 AliError("Unable to get AOD event to embed. Nothing will be embedded.");
292 if (fTracks && fOutTracks) {
298 AliDebug(2, Form("%d tracks will be processed for embedding.", fAODTracks->GetEntriesFast()));
299 for (Int_t i = 0; i < fAODTracks->GetEntriesFast(); i++) {
300 AliVTrack *track = static_cast<AliVTrack*>(fAODTracks->At(i));
302 AliError(Form("Could not find track %d in branch %s of tree %s!", i, fAODTrackName.Data(), fAODTreeName.Data()));
307 Bool_t isEmc = kFALSE;
309 AliAODTrack *aodtrack = static_cast<AliAODTrack*>(track);
310 if (aodtrack->TestFilterBit(fAODfilterBits[0])) {
313 else if (aodtrack->TestFilterBit(fAODfilterBits[1])) {
314 if ((aodtrack->GetStatus()&AliESDtrack::kITSrefit)==0) {
324 else { /*not a good track*/
328 if (TMath::Abs(aodtrack->GetTrackEtaOnEMCal()) < 0.75 &&
329 aodtrack->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() &&
330 aodtrack->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad())
333 else if (fPicoTrackVersion > 0) { /*not AOD mode, let's see if it is PicoTrack*/
334 AliPicoTrack *ptrack = dynamic_cast<AliPicoTrack*>(track);
336 if (fPicoTrackVersion >= 3)
337 type = ptrack->GetTrackType();
339 type = ptrack->GetLabel();
340 isEmc = ptrack->IsEMCAL();
344 AliDebug(3, Form("Embedding track with pT = %f, eta = %f, phi = %f", track->Pt(), track->Eta(), track->Phi()));
345 AddTrack(track->Pt(), track->Eta(), track->Phi(), type, track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), isEmc);
350 if (fClusters && fOutClusters) {
356 for (Int_t i = 0; i < fAODClusters->GetEntriesFast(); i++) {
357 AliVCluster *clus = static_cast<AliVCluster*>(fAODClusters->At(i));
359 AliError(Form("Could not find cluster %d in branch %s of tree %s!", i, fAODClusName.Data(), fAODTreeName.Data()));
363 Double_t vert[3] = {0,0,0};
364 clus->GetMomentum(vect,vert);
365 AddCluster(clus->E(), vect.Eta(), vect.Phi());
370 if (fCaloCells && fOutCaloCells) {
372 Int_t totalCells = fCaloCells->GetNumberOfCells();
374 totalCells += fAODCaloCells->GetNumberOfCells();
376 SetNumberOfOutCells(totalCells);
381 for (Short_t i = 0; i < fAODCaloCells->GetNumberOfCells(); i++) {
385 Short_t cellNum = -1;
388 fAODCaloCells->GetCell(i, cellNum, amp, time, mclabel, efrac);
389 AliDebug(3,Form("Adding cell with amplitude %f, absolute ID %d, time %f", amp, cellNum, time));
390 AddCell(amp, cellNum, time);
394 AliDebug(2,Form("Added cells = %d, total cells = %d", fAddedCells, totalCells));