1 // $Id: AliJetEmbeddingFromAODTask.cxx $
3 // Jet embedding from AOD task.
5 // Author: S.Aiola, C.Loizides
7 #include "AliJetEmbeddingFromAODTask.h"
13 #include <TClonesArray.h>
14 #include <TObjArray.h>
15 #include <TObjString.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),
62 // Default constructor.
63 SetSuffix("AODEmbedding");
65 fAODfilterBits[0] = -1;
66 fAODfilterBits[1] = -1;
69 //________________________________________________________________________
70 AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask(const char *name, Bool_t drawqa) :
71 AliJetModelBaseTask(name, drawqa),
73 fAODTreeName("aodTree"),
74 fAODHeaderName("header"),
75 fAODVertexName("vertices"),
76 fAODTrackName("tracks"),
77 fAODClusName("caloClusters"),
78 fAODCellsName("emcalCells"),
81 fTriggerMask(AliVEvent::kAny),
87 fCurrentAODFileID(-1),
96 // Standard constructor.
97 SetSuffix("AODEmbedding");
99 fAODfilterBits[0] = -1;
100 fAODfilterBits[1] = -1;
103 //________________________________________________________________________
104 AliJetEmbeddingFromAODTask::~AliJetEmbeddingFromAODTask()
108 if (fCurrentAODFile) {
109 fCurrentAODFile->Close();
110 delete fCurrentAODFile;
114 //________________________________________________________________________
115 void AliJetEmbeddingFromAODTask::UserCreateOutputObjects()
120 AliJetModelBaseTask::UserCreateOutputObjects();
122 fHistFileIDs = new TH2C("fHistFileIDs", "fHistFileIDs", fTotalFiles, -0.5, fTotalFiles - 0.5, fFileList->GetEntriesFast(), -0.5, fFileList->GetEntriesFast() -0.5);
123 fHistFileIDs->GetXaxis()->SetTitle("File no. (PYTHIA)");
124 fHistFileIDs->GetYaxis()->SetTitle("File no. (Embedded AOD)");
125 fOutput->Add(fHistFileIDs);
127 PostData(1, fOutput);
130 //________________________________________________________________________
131 Bool_t AliJetEmbeddingFromAODTask::UserNotify()
133 TString path(fInputHandler->GetTree()->GetCurrentFile()->GetPath());
134 if (path.EndsWith("/"))
135 path.Remove(path.Length()-1);
136 path.Remove(path.Last('/'));
137 path.Remove(0, path.Last('/')+1);
139 AliWarning(Form("Could not extract file number from path %s", path.Data()));
142 fCurrentFileID = path.Atoi();
143 fCurrentAODFileID = fFileList->GetEntriesFast() * fCurrentFileID / fTotalFiles;
144 AliInfo(Form("Start embedding from file ID %d", fCurrentAODFileID));
148 //________________________________________________________________________
149 Bool_t AliJetEmbeddingFromAODTask::ExecOnce()
151 if (fAODTreeName.Contains("aod"))
152 fEsdTreeMode = kFALSE;
154 fEsdTreeMode = kTRUE;
156 return AliJetModelBaseTask::ExecOnce();
159 //________________________________________________________________________
160 Bool_t AliJetEmbeddingFromAODTask::OpenNextFile()
162 if (fCurrentAODFile) {
163 fCurrentAODFile->Close();
164 delete fCurrentAODFile;
168 if (fCurrentAODFileID >= fFileList->GetEntriesFast())
171 TObjString *objFileName = static_cast<TObjString*>(fFileList->At(fCurrentAODFileID));
172 TString fileName = objFileName->GetString();
174 if (fileName.BeginsWith("alien://") && !gGrid) {
175 AliInfo("Trying to connect to AliEn ...");
176 TGrid::Connect("alien://");
179 fCurrentAODFile = TFile::Open(fileName);
181 if (!fCurrentAODFile || fCurrentAODFile->IsZombie()) {
186 fHistFileIDs->Fill(fCurrentFileID, fCurrentAODFileID);
192 //________________________________________________________________________
193 Bool_t AliJetEmbeddingFromAODTask::GetNextEntry()
195 static TTree *tree = 0;
196 static Int_t entry = 0;
202 if (!fCurrentAODFile || !tree || entry >= tree->GetEntries()) {
206 tree = static_cast<TTree*>(fCurrentAODFile->Get(fAODTreeName));
210 if (!fAODHeaderName.IsNull())
211 tree->SetBranchAddress(fAODHeaderName, &fAODHeader);
213 if (!fAODVertexName.IsNull())
214 tree->SetBranchAddress(fAODVertexName, &fAODVertex);
216 if (!fAODTrackName.IsNull())
217 tree->SetBranchAddress(fAODTrackName, &fAODTracks);
219 if (!fAODClusName.IsNull())
220 tree->SetBranchAddress(fAODClusName, &fAODClusters);
222 if (!fAODCellsName.IsNull())
223 tree->SetBranchAddress(fAODCellsName, &fAODCaloCells);
228 tree->GetEntry(entry);
232 if (attempts == 1000)
233 AliWarning("After 1000 attempts no event has been accepted by the event selection (trigger, centrality...)!");
235 } while (!IsAODEventSelected() && tree);
240 //________________________________________________________________________
241 Bool_t AliJetEmbeddingFromAODTask::IsAODEventSelected()
243 if (!fEsdTreeMode && fAODHeader) {
244 AliAODHeader *aodHeader = static_cast<AliAODHeader*>(fAODHeader);
246 UInt_t offlineTrigger = aodHeader->GetOfflineTrigger();
248 if ((offlineTrigger & fTriggerMask) == 0) {
249 AliDebug(2, Form("Event rejected due to physics selection. Event trigger mask: %d, trigger mask selection: %d.", offlineTrigger, fTriggerMask));
253 AliCentrality *cent = aodHeader->GetCentralityP();
254 Float_t centVal = cent->GetCentralityPercentile("V0M");
255 if (centVal < fMinCentrality || centVal >= fMaxCentrality) {
256 AliDebug(2, Form("Event rejected due to centrality selection. Event centrality: %f, centrality range selection: %f to %f", centVal, fMinCentrality, fMaxCentrality));
262 Double_t vert[3]={0};
263 ((AliVVertex*)fAODVertex->At(0))->GetXYZ(vert);
264 if (TMath::Abs(vert[2]) > fZVertexCut) {
265 AliDebug(2,Form("Event rejected due to Z vertex selection. Event Z vertex: %f, Z vertex cut: %f", vert[2], fZVertexCut));
273 //________________________________________________________________________
274 void AliJetEmbeddingFromAODTask::Run()
276 if (!GetNextEntry()) {
277 AliError("Unable to get AOD event to embed. Nothing will be embedded.");
281 if (fTracks && fOutTracks) {
287 AliDebug(2, Form("%d tracks will be processed for embedding.", fAODTracks->GetEntriesFast()));
288 for (Int_t i = 0; i < fAODTracks->GetEntriesFast(); i++) {
289 AliVTrack *track = static_cast<AliVTrack*>(fAODTracks->At(i));
291 AliError(Form("Could not find track %d in branch %s of tree %s!", i, fAODTrackName.Data(), fAODTreeName.Data()));
296 Bool_t isEmc = kFALSE;
298 AliAODTrack *aodtrack = static_cast<AliAODTrack*>(track);
299 if (aodtrack->TestFilterBit(fAODfilterBits[0])) {
302 else if (aodtrack->TestFilterBit(fAODfilterBits[1])) {
303 if ((aodtrack->GetStatus()&AliESDtrack::kITSrefit)==0) {
313 else { /*not a good track*/
317 if (TMath::Abs(aodtrack->GetTrackEtaOnEMCal()) < 0.75 &&
318 aodtrack->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() &&
319 aodtrack->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad())
322 else { /*not AOD mode, let's see if it is PicoTrack*/
323 AliPicoTrack *ptrack = dynamic_cast<AliPicoTrack*>(track);
325 type = ptrack->GetTrackType();
326 isEmc = ptrack->IsEMCAL();
330 AliDebug(3, Form("Embedding track with pT = %f, eta = %f, phi = %f", track->Pt(), track->Eta(), track->Phi()));
331 AddTrack(track->Pt(), track->Eta(), track->Phi(), type, track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), isEmc);
336 if (fClusters && fOutClusters) {
342 for (Int_t i = 0; i < fAODClusters->GetEntriesFast(); i++) {
343 AliVCluster *clus = static_cast<AliVCluster*>(fAODClusters->At(i));
345 AliError(Form("Could not find cluster %d in branch %s of tree %s!", i, fAODClusName.Data(), fAODTreeName.Data()));
349 Double_t vert[3] = {0,0,0};
350 clus->GetMomentum(vect,vert);
351 AddCluster(clus->E(), vect.Eta(), vect.Phi());
356 if (fCaloCells && fOutCaloCells) {
358 Int_t totalCells = fCaloCells->GetNumberOfCells();
360 totalCells += fAODCaloCells->GetNumberOfCells();
362 SetNumberOfOutCells(totalCells);
367 for (Short_t i = 0; i < fAODCaloCells->GetNumberOfCells(); i++) {
368 Short_t mclabel = -1;
371 Short_t cellNum = -1;
374 fAODCaloCells->GetCell(i, cellNum, amp, time, mclabel, efrac);
375 AliDebug(3,Form("Adding cell with amplitude %f, absolute ID %d, time %f", amp, cellNum, time));
376 AddCell(amp, cellNum, time);