]>
Commit | Line | Data |
---|---|---|
9239b066 | 1 | // $Id$ |
b16bb001 | 2 | // |
3 | // Jet embedding from AOD task. | |
4 | // | |
5 | // Author: S.Aiola, C.Loizides | |
6 | ||
7 | #include "AliJetEmbeddingFromAODTask.h" | |
8 | ||
4358e58a | 9 | // C++ standard library |
10 | #include <vector> | |
11 | ||
12 | // ROOT | |
b16bb001 | 13 | #include <TFile.h> |
14 | #include <TTree.h> | |
15 | #include <TClonesArray.h> | |
16 | #include <TObjArray.h> | |
17 | #include <TObjString.h> | |
18 | #include <TGrid.h> | |
19 | #include <TH2C.h> | |
cd6431de | 20 | #include <TList.h> |
21 | #include <TStreamerInfo.h> | |
6a20534a | 22 | #include <TRandom.h> |
2103dc6a | 23 | #include <TSystem.h> |
4358e58a | 24 | #include <TLorentzVector.h> |
b16bb001 | 25 | |
4358e58a | 26 | // AliRoot |
b16bb001 | 27 | #include "AliVEvent.h" |
28 | #include "AliAODTrack.h" | |
29 | #include "AliESDtrack.h" | |
30 | #include "AliPicoTrack.h" | |
31 | #include "AliVTrack.h" | |
32 | #include "AliVCluster.h" | |
33 | #include "AliVCaloCells.h" | |
787a3c4f | 34 | #include "AliAODMCParticle.h" |
b16bb001 | 35 | #include "AliCentrality.h" |
36 | #include "AliVHeader.h" | |
37 | #include "AliVVertex.h" | |
38 | #include "AliAODHeader.h" | |
4358e58a | 39 | #include "AliFJWrapper.h" |
b16bb001 | 40 | #include "AliLog.h" |
41 | #include "AliInputEventHandler.h" | |
43032ce2 | 42 | #include "AliNamedString.h" |
b16bb001 | 43 | |
44 | ClassImp(AliJetEmbeddingFromAODTask) | |
45 | ||
46 | //________________________________________________________________________ | |
47 | AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask() : | |
48 | AliJetModelBaseTask("AliJetEmbeddingFromAODTask"), | |
49 | fFileList(0), | |
6a20534a | 50 | fRandomAccess(kFALSE), |
b16bb001 | 51 | fAODTreeName(), |
52 | fAODHeaderName(), | |
53 | fAODVertexName(), | |
54 | fAODTrackName(), | |
55 | fAODClusName(), | |
56 | fAODCellsName(), | |
787a3c4f | 57 | fAODMCParticlesName(), |
6fd2f1a9 | 58 | fMinCentrality(-1), |
59 | fMaxCentrality(-1), | |
b16bb001 | 60 | fTriggerMask(AliVEvent::kAny), |
61 | fZVertexCut(10), | |
6fd2f1a9 | 62 | fMaxVertexDist(999), |
4358e58a | 63 | fJetMinPt(0), |
64 | fJetMinEta(-0.5), | |
65 | fJetMaxEta(0.5), | |
66 | fJetMinPhi(-999), | |
67 | fJetMaxPhi(999), | |
05077f28 | 68 | fJetConstituentMinPt(0), |
4358e58a | 69 | fJetRadius(0.4), |
70 | fJetType(0), | |
71 | fJetAlgo(1), | |
72 | fJetParticleLevel(kTRUE), | |
43032ce2 | 73 | fParticleMinPt(0), |
74 | fParticleMaxPt(0), | |
75 | fParticleSelection(0), | |
9adcb46d | 76 | fIncludeNoITS(kFALSE), |
77 | fCutMaxFractionSharedTPCClusters(0.4), | |
5ce8ae64 | 78 | fUseNegativeLabels(kTRUE), |
79 | fTrackEfficiency(1), | |
4358e58a | 80 | fIsAODMC(kFALSE), |
6a20534a | 81 | fTotalFiles(2050), |
82 | fAttempts(5), | |
b16bb001 | 83 | fEsdTreeMode(kFALSE), |
84 | fCurrentFileID(0), | |
6a20534a | 85 | fCurrentAODFileID(0), |
b16bb001 | 86 | fCurrentAODFile(0), |
cd6431de | 87 | fPicoTrackVersion(0), |
6a20534a | 88 | fCurrentAODTree(0), |
b16bb001 | 89 | fAODHeader(0), |
90 | fAODVertex(0), | |
91 | fAODTracks(0), | |
92 | fAODClusters(0), | |
93 | fAODCaloCells(0), | |
787a3c4f | 94 | fAODMCParticles(0), |
6a20534a | 95 | fCurrentAODEntry(-1), |
43032ce2 | 96 | fAODFilePath(0), |
6a20534a | 97 | fHistFileMatching(0), |
98 | fHistAODFileError(0), | |
2103dc6a | 99 | fHistNotEmbedded(0), |
6fd2f1a9 | 100 | fHistEmbeddingQA(0), |
52286a19 | 101 | fHistRejectedEvents(0), |
102 | fEmbeddingCount(0) | |
b16bb001 | 103 | { |
104 | // Default constructor. | |
105 | SetSuffix("AODEmbedding"); | |
b16bb001 | 106 | fAODfilterBits[0] = -1; |
107 | fAODfilterBits[1] = -1; | |
5be3857d | 108 | fEtaMin = -1; |
109 | fEtaMax = 1; | |
110 | fPhiMin = -10; | |
111 | fPhiMax = 10; | |
112 | fPtMin = 0; | |
113 | fPtMax = 1000; | |
b16bb001 | 114 | } |
115 | ||
116 | //________________________________________________________________________ | |
117 | AliJetEmbeddingFromAODTask::AliJetEmbeddingFromAODTask(const char *name, Bool_t drawqa) : | |
118 | AliJetModelBaseTask(name, drawqa), | |
119 | fFileList(0), | |
6a20534a | 120 | fRandomAccess(kFALSE), |
b16bb001 | 121 | fAODTreeName("aodTree"), |
122 | fAODHeaderName("header"), | |
123 | fAODVertexName("vertices"), | |
124 | fAODTrackName("tracks"), | |
787a3c4f | 125 | fAODClusName(""), |
b16bb001 | 126 | fAODCellsName("emcalCells"), |
787a3c4f | 127 | fAODMCParticlesName(AliAODMCParticle::StdBranchName()), |
6fd2f1a9 | 128 | fMinCentrality(-1), |
129 | fMaxCentrality(-1), | |
b16bb001 | 130 | fTriggerMask(AliVEvent::kAny), |
131 | fZVertexCut(10), | |
6fd2f1a9 | 132 | fMaxVertexDist(999), |
4358e58a | 133 | fJetMinPt(0), |
134 | fJetMinEta(-0.5), | |
135 | fJetMaxEta(0.5), | |
136 | fJetMinPhi(-999), | |
137 | fJetMaxPhi(999), | |
05077f28 | 138 | fJetConstituentMinPt(0), |
4358e58a | 139 | fJetRadius(0.4), |
140 | fJetType(0), | |
141 | fJetAlgo(1), | |
142 | fJetParticleLevel(kTRUE), | |
43032ce2 | 143 | fParticleMinPt(0), |
144 | fParticleMaxPt(0), | |
145 | fParticleSelection(0), | |
9adcb46d | 146 | fIncludeNoITS(kFALSE), |
147 | fCutMaxFractionSharedTPCClusters(0.4), | |
5ce8ae64 | 148 | fUseNegativeLabels(kTRUE), |
149 | fTrackEfficiency(1), | |
4358e58a | 150 | fIsAODMC(kFALSE), |
6a20534a | 151 | fTotalFiles(2050), |
152 | fAttempts(5), | |
b16bb001 | 153 | fEsdTreeMode(kFALSE), |
154 | fCurrentFileID(0), | |
6a20534a | 155 | fCurrentAODFileID(0), |
b16bb001 | 156 | fCurrentAODFile(0), |
cd6431de | 157 | fPicoTrackVersion(0), |
6a20534a | 158 | fCurrentAODTree(0), |
b16bb001 | 159 | fAODHeader(0), |
160 | fAODVertex(0), | |
161 | fAODTracks(0), | |
162 | fAODClusters(0), | |
787a3c4f | 163 | fAODCaloCells(0), |
164 | fAODMCParticles(0), | |
6a20534a | 165 | fCurrentAODEntry(-1), |
43032ce2 | 166 | fAODFilePath(0), |
6a20534a | 167 | fHistFileMatching(0), |
168 | fHistAODFileError(0), | |
2103dc6a | 169 | fHistNotEmbedded(0), |
6fd2f1a9 | 170 | fHistEmbeddingQA(0), |
52286a19 | 171 | fHistRejectedEvents(0), |
172 | fEmbeddingCount(0) | |
b16bb001 | 173 | { |
174 | // Standard constructor. | |
175 | SetSuffix("AODEmbedding"); | |
b16bb001 | 176 | fAODfilterBits[0] = -1; |
177 | fAODfilterBits[1] = -1; | |
5be3857d | 178 | fEtaMin = -1; |
179 | fEtaMax = 1; | |
180 | fPhiMin = -10; | |
181 | fPhiMax = 10; | |
182 | fPtMin = 0; | |
183 | fPtMax = 1000; | |
b16bb001 | 184 | } |
185 | ||
186 | //________________________________________________________________________ | |
187 | AliJetEmbeddingFromAODTask::~AliJetEmbeddingFromAODTask() | |
188 | { | |
189 | // Destructor | |
190 | ||
191 | if (fCurrentAODFile) { | |
192 | fCurrentAODFile->Close(); | |
193 | delete fCurrentAODFile; | |
194 | } | |
195 | } | |
196 | ||
197 | //________________________________________________________________________ | |
198 | void AliJetEmbeddingFromAODTask::UserCreateOutputObjects() | |
199 | { | |
200 | if (!fQAhistos) | |
201 | return; | |
202 | ||
203 | AliJetModelBaseTask::UserCreateOutputObjects(); | |
204 | ||
6a20534a | 205 | fHistFileMatching = new TH2C("fHistFileMatching", "fHistFileMatching", fTotalFiles, -0.5, fTotalFiles - 0.5, fFileList->GetEntriesFast(), -0.5, fFileList->GetEntriesFast() -0.5); |
206 | fHistFileMatching->GetXaxis()->SetTitle("File no. (PYTHIA)"); | |
207 | fHistFileMatching->GetYaxis()->SetTitle("File no. (Embedded AOD)"); | |
208 | fHistFileMatching->GetZaxis()->SetTitle("counts"); | |
209 | fOutput->Add(fHistFileMatching); | |
210 | ||
211 | fHistAODFileError = new TH1C("fHistAODFileError", "fHistAODFileError", fFileList->GetEntriesFast(), -0.5, fFileList->GetEntriesFast() -0.5); | |
212 | fHistAODFileError->GetXaxis()->SetTitle("File no. (Embedded AOD)"); | |
213 | fHistAODFileError->GetYaxis()->SetTitle("counts"); | |
214 | fOutput->Add(fHistAODFileError); | |
215 | ||
216 | fHistNotEmbedded = new TH1C("fHistNotEmbedded", "fHistNotEmbedded", fTotalFiles, -0.5, fTotalFiles - 0.5); | |
217 | fHistNotEmbedded->GetXaxis()->SetTitle("File no. (PYTHIA)"); | |
218 | fHistNotEmbedded->GetYaxis()->SetTitle("counts"); | |
219 | fOutput->Add(fHistNotEmbedded); | |
b16bb001 | 220 | |
2103dc6a | 221 | fHistEmbeddingQA = new TH1F("fHistEmbeddingQA", "fHistEmbeddingQA", 2, 0, 2); |
222 | fHistEmbeddingQA->GetXaxis()->SetTitle("Event state"); | |
223 | fHistEmbeddingQA->GetYaxis()->SetTitle("counts"); | |
224 | fHistEmbeddingQA->GetXaxis()->SetBinLabel(1, "OK"); | |
225 | fHistEmbeddingQA->GetXaxis()->SetBinLabel(2, "Not embedded"); | |
226 | fOutput->Add(fHistEmbeddingQA); | |
227 | ||
6fd2f1a9 | 228 | fHistRejectedEvents = new TH1F("fHistRejectedEvents", "fHistRejectedEvents", 500, -0.5, 499.5); |
229 | fHistRejectedEvents->GetXaxis()->SetTitle("# of rejected events"); | |
230 | fHistRejectedEvents->GetYaxis()->SetTitle("counts"); | |
231 | fOutput->Add(fHistRejectedEvents); | |
232 | ||
b16bb001 | 233 | PostData(1, fOutput); |
234 | } | |
235 | ||
236 | //________________________________________________________________________ | |
237 | Bool_t AliJetEmbeddingFromAODTask::UserNotify() | |
238 | { | |
239 | TString path(fInputHandler->GetTree()->GetCurrentFile()->GetPath()); | |
240 | if (path.EndsWith("/")) | |
241 | path.Remove(path.Length()-1); | |
242 | path.Remove(path.Last('/')); | |
243 | path.Remove(0, path.Last('/')+1); | |
244 | if (!path.IsDec()) { | |
245 | AliWarning(Form("Could not extract file number from path %s", path.Data())); | |
246 | return kTRUE; | |
247 | } | |
248 | fCurrentFileID = path.Atoi(); | |
6a20534a | 249 | if (!fRandomAccess) { |
250 | fCurrentAODFileID = fFileList->GetEntriesFast() * fCurrentFileID / fTotalFiles-1; | |
251 | AliInfo(Form("Start embedding from file ID %d", fCurrentAODFileID)); | |
252 | } | |
b16bb001 | 253 | return kTRUE; |
254 | } | |
255 | ||
256 | //________________________________________________________________________ | |
257 | Bool_t AliJetEmbeddingFromAODTask::ExecOnce() | |
258 | { | |
259 | if (fAODTreeName.Contains("aod")) | |
260 | fEsdTreeMode = kFALSE; | |
261 | else | |
262 | fEsdTreeMode = kTRUE; | |
263 | ||
43032ce2 | 264 | fAODFilePath = static_cast<AliNamedString*>(InputEvent()->FindListObject("AODEmbeddingFile")); |
265 | if (!fAODFilePath) { | |
266 | fAODFilePath = new AliNamedString("AODEmbeddingFile", ""); | |
267 | AliDebug(3,"Adding AOD embedding file path object to the event list..."); | |
268 | InputEvent()->AddObject(fAODFilePath); | |
269 | } | |
270 | ||
b16bb001 | 271 | return AliJetModelBaseTask::ExecOnce(); |
272 | } | |
273 | ||
274 | //________________________________________________________________________ | |
275 | Bool_t AliJetEmbeddingFromAODTask::OpenNextFile() | |
276 | { | |
277 | if (fCurrentAODFile) { | |
278 | fCurrentAODFile->Close(); | |
279 | delete fCurrentAODFile; | |
280 | fCurrentAODFile = 0; | |
281 | } | |
282 | ||
6a20534a | 283 | Int_t i = 0; |
b16bb001 | 284 | |
2103dc6a | 285 | while ((!fCurrentAODFile || fCurrentAODFile->IsZombie()) && i < fAttempts) { |
286 | if (i > 0 && fHistAODFileError) { | |
6a20534a | 287 | fHistAODFileError->Fill(fCurrentAODFileID); |
288 | } | |
289 | ||
2103dc6a | 290 | fCurrentAODFile = GetNextFile(); |
7030f36f | 291 | i++; |
2103dc6a | 292 | } |
b16bb001 | 293 | |
c8a63f73 | 294 | if (!fCurrentAODFile || fCurrentAODFile->IsZombie()) { |
295 | AliError("Could not open AOD file to embed!"); | |
b16bb001 | 296 | return kFALSE; |
c8a63f73 | 297 | } |
b16bb001 | 298 | |
cd6431de | 299 | const TList *clist = fCurrentAODFile->GetStreamerInfoCache(); |
300 | if(clist) { | |
301 | TStreamerInfo *cinfo = static_cast<TStreamerInfo*>(clist->FindObject("AliPicoTrack")); | |
302 | if(cinfo) | |
303 | fPicoTrackVersion = cinfo->GetClassVersion(); | |
304 | else | |
305 | fPicoTrackVersion = 0; | |
306 | } | |
307 | ||
6a20534a | 308 | fCurrentAODTree = static_cast<TTree*>(fCurrentAODFile->Get(fAODTreeName)); |
c8a63f73 | 309 | if (!fCurrentAODTree) { |
310 | AliError(Form("Could not get tree %s from file %s", fAODTreeName.Data(), fCurrentAODFile->GetName())); | |
6a20534a | 311 | return kFALSE; |
c8a63f73 | 312 | } |
6a20534a | 313 | |
314 | if (!fAODHeaderName.IsNull()) | |
315 | fCurrentAODTree->SetBranchAddress(fAODHeaderName, &fAODHeader); | |
316 | ||
317 | if (!fAODVertexName.IsNull()) | |
318 | fCurrentAODTree->SetBranchAddress(fAODVertexName, &fAODVertex); | |
319 | ||
320 | if (!fAODTrackName.IsNull()) | |
321 | fCurrentAODTree->SetBranchAddress(fAODTrackName, &fAODTracks); | |
322 | ||
323 | if (!fAODClusName.IsNull()) | |
324 | fCurrentAODTree->SetBranchAddress(fAODClusName, &fAODClusters); | |
325 | ||
326 | if (!fAODCellsName.IsNull()) | |
327 | fCurrentAODTree->SetBranchAddress(fAODCellsName, &fAODCaloCells); | |
328 | ||
329 | if (!fAODMCParticlesName.IsNull()) | |
330 | fCurrentAODTree->SetBranchAddress(fAODMCParticlesName, &fAODMCParticles); | |
331 | ||
332 | if (fRandomAccess) | |
333 | fCurrentAODEntry = TMath::Nint(gRandom->Rndm()*fCurrentAODTree->GetEntries()); | |
334 | else | |
6fd2f1a9 | 335 | fCurrentAODEntry = -1; |
7030f36f | 336 | |
6fd2f1a9 | 337 | AliDebug(3,Form("Will start embedding from entry %d", fCurrentAODEntry+1)); |
6a20534a | 338 | |
7030f36f | 339 | if (fHistFileMatching) |
6a20534a | 340 | fHistFileMatching->Fill(fCurrentFileID, fCurrentAODFileID-1); |
52286a19 | 341 | |
342 | fEmbeddingCount = 0; | |
b16bb001 | 343 | |
b16bb001 | 344 | return kTRUE; |
345 | } | |
346 | ||
347 | //________________________________________________________________________ | |
2103dc6a | 348 | TFile* AliJetEmbeddingFromAODTask::GetNextFile() |
b16bb001 | 349 | { |
2103dc6a | 350 | if (fRandomAccess) |
351 | fCurrentAODFileID = TMath::Nint(gRandom->Rndm()*fFileList->GetEntriesFast()); | |
352 | else | |
353 | fCurrentAODFileID++; | |
354 | ||
355 | if (fCurrentAODFileID >= fFileList->GetEntriesFast()) { | |
356 | AliError("No more file in the list!"); | |
357 | return 0; | |
358 | } | |
359 | ||
360 | TObjString *objFileName = static_cast<TObjString*>(fFileList->At(fCurrentAODFileID)); | |
361 | TString fileName(objFileName->GetString()); | |
b16bb001 | 362 | |
4358e58a | 363 | if (fileName.BeginsWith("alien://") && !gGrid) { |
364 | AliInfo("Trying to connect to AliEn ..."); | |
365 | TGrid::Connect("alien://"); | |
366 | } | |
367 | ||
2103dc6a | 368 | TString baseFileName(fileName); |
369 | if (baseFileName.Contains(".zip#")) { | |
370 | Ssiz_t pos = baseFileName.Last('#'); | |
371 | baseFileName.Remove(pos); | |
372 | } | |
373 | ||
374 | if (gSystem->AccessPathName(baseFileName)) { | |
c8a63f73 | 375 | AliError(Form("File %s does not exist!", baseFileName.Data())); |
2103dc6a | 376 | return 0; |
377 | } | |
378 | ||
379 | AliDebug(3,Form("Trying to open file %s...", fileName.Data())); | |
380 | TFile *file = TFile::Open(fileName); | |
381 | ||
c8a63f73 | 382 | if (!file || file->IsZombie()) { |
383 | AliError(Form("Unable to open file: %s!", fileName.Data())); | |
384 | return 0; | |
385 | } | |
2103dc6a | 386 | |
387 | return file; | |
6a20534a | 388 | } |
389 | ||
390 | //________________________________________________________________________ | |
391 | Bool_t AliJetEmbeddingFromAODTask::GetNextEntry() | |
392 | { | |
6fd2f1a9 | 393 | Int_t attempts = -1; |
b16bb001 | 394 | |
395 | do { | |
6fd2f1a9 | 396 | if (!fCurrentAODFile || !fCurrentAODTree || fCurrentAODEntry+1 >= fCurrentAODTree->GetEntries()) { |
c8a63f73 | 397 | if (!OpenNextFile()) { |
398 | AliError("Could not open the next file!"); | |
b16bb001 | 399 | return kFALSE; |
c8a63f73 | 400 | } |
b16bb001 | 401 | } |
6fd2f1a9 | 402 | |
403 | if (!fCurrentAODTree) { | |
404 | AliError("Could not get the tree!"); | |
405 | return kFALSE; | |
406 | } | |
b16bb001 | 407 | |
6a20534a | 408 | fCurrentAODEntry++; |
6fd2f1a9 | 409 | fCurrentAODTree->GetEntry(fCurrentAODEntry); |
b16bb001 | 410 | |
6fd2f1a9 | 411 | attempts++; |
b16bb001 | 412 | if (attempts == 1000) |
413 | AliWarning("After 1000 attempts no event has been accepted by the event selection (trigger, centrality...)!"); | |
414 | ||
6fd2f1a9 | 415 | } while (!IsAODEventSelected()); |
416 | ||
43032ce2 | 417 | if (fHistRejectedEvents) |
418 | fHistRejectedEvents->Fill(attempts); | |
b16bb001 | 419 | |
6fd2f1a9 | 420 | if (!fCurrentAODTree) |
421 | return kFALSE; | |
422 | ||
52286a19 | 423 | fEmbeddingCount++; |
424 | ||
6fd2f1a9 | 425 | return kTRUE; |
b16bb001 | 426 | } |
427 | ||
428 | //________________________________________________________________________ | |
429 | Bool_t AliJetEmbeddingFromAODTask::IsAODEventSelected() | |
430 | { | |
4358e58a | 431 | // AOD event selection. |
6fd2f1a9 | 432 | |
b16bb001 | 433 | if (!fEsdTreeMode && fAODHeader) { |
434 | AliAODHeader *aodHeader = static_cast<AliAODHeader*>(fAODHeader); | |
435 | ||
4358e58a | 436 | // Trigger selection |
43032ce2 | 437 | if (fTriggerMask != 0) { |
6a20534a | 438 | UInt_t offlineTrigger = aodHeader->GetOfflineTrigger(); |
439 | ||
440 | if ((offlineTrigger & fTriggerMask) == 0) { | |
4358e58a | 441 | AliDebug(2,Form("Event rejected due to physics selection. Event trigger mask: %d, trigger mask selection: %d.", |
442 | offlineTrigger, fTriggerMask)); | |
6a20534a | 443 | return kFALSE; |
444 | } | |
b16bb001 | 445 | } |
446 | ||
4358e58a | 447 | // Centrality selection |
6a20534a | 448 | if (fMinCentrality >= 0) { |
449 | AliCentrality *cent = aodHeader->GetCentralityP(); | |
450 | Float_t centVal = cent->GetCentralityPercentile("V0M"); | |
451 | if (centVal < fMinCentrality || centVal >= fMaxCentrality) { | |
4358e58a | 452 | AliDebug(2,Form("Event rejected due to centrality selection. Event centrality: %f, centrality range selection: %f to %f", |
453 | centVal, fMinCentrality, fMaxCentrality)); | |
6a20534a | 454 | return kFALSE; |
455 | } | |
b16bb001 | 456 | } |
457 | } | |
458 | ||
4358e58a | 459 | // Vertex selection |
b16bb001 | 460 | if (fAODVertex) { |
461 | Double_t vert[3]={0}; | |
462 | ((AliVVertex*)fAODVertex->At(0))->GetXYZ(vert); | |
463 | if (TMath::Abs(vert[2]) > fZVertexCut) { | |
4358e58a | 464 | AliDebug(2,Form("Event rejected due to Z vertex selection. Event Z vertex: %f, Z vertex cut: %f", |
465 | vert[2], fZVertexCut)); | |
b16bb001 | 466 | return kFALSE; |
467 | } | |
6fd2f1a9 | 468 | Double_t dist = TMath::Sqrt((vert[0]-fVertex[0])*(vert[0]-fVertex[0])+(vert[1]-fVertex[1])*(vert[1]-fVertex[1])+(vert[2]-fVertex[2])*(vert[2]-fVertex[2])); |
469 | if (dist > fMaxVertexDist) { | |
470 | AliDebug(2,Form("Event rejected because the distance between the current and embedded verteces is > %f. " | |
471 | "Current event vertex (%f, %f, %f), embedded event vertex (%f, %f, %f). Distance = %f", | |
472 | fMaxVertexDist, fVertex[0], fVertex[1], fVertex[2], vert[0], vert[1], vert[2], dist)); | |
473 | return kFALSE; | |
474 | } | |
475 | ||
b16bb001 | 476 | } |
477 | ||
43032ce2 | 478 | // Particle selection |
479 | if ((fParticleSelection == 1 && FindParticleInRange(fAODTracks)==kFALSE) || | |
480 | (fParticleSelection == 2 && FindParticleInRange(fAODClusters)==kFALSE) || | |
481 | (fParticleSelection == 3 && FindParticleInRange(fAODMCParticles)==kFALSE)) | |
482 | return kFALSE; | |
483 | ||
4358e58a | 484 | // Jet selection |
485 | if (fJetMinPt > 0) { | |
486 | TLorentzVector jet; | |
487 | ||
488 | if (fJetParticleLevel) { | |
489 | if (fAODMCParticles) | |
490 | jet = GetLeadingJet(fAODMCParticles); | |
491 | else { | |
492 | AliWarning("Particle level jets selected, but not MC particles found. The jet event selection will be skipped."); | |
493 | return kTRUE; | |
494 | } | |
495 | } | |
496 | else { | |
497 | if (fAODTracks || fAODClusters) | |
498 | jet = GetLeadingJet(fAODTracks, fAODClusters); | |
499 | else { | |
500 | AliWarning("Detector level jets selected, but not tracks or clusters found. The jet event selection will be skipped."); | |
501 | return kTRUE; | |
502 | } | |
503 | } | |
504 | ||
05077f28 | 505 | AliDebug(1, Form("Leading jet pt = %f", jet.Pt())); |
4358e58a | 506 | if (jet.Pt() < fJetMinPt) |
507 | return kFALSE; | |
508 | } | |
509 | ||
b16bb001 | 510 | return kTRUE; |
511 | } | |
512 | ||
43032ce2 | 513 | //________________________________________________________________________ |
514 | Bool_t AliJetEmbeddingFromAODTask::FindParticleInRange(TClonesArray *array) | |
515 | { | |
516 | if (!array) return kFALSE; | |
517 | ||
518 | if (array->GetClass()->InheritsFrom("AliVParticle")) { | |
519 | const Int_t nentries = array->GetEntriesFast(); | |
520 | for (Int_t i = 0; i < nentries; i++) { | |
521 | AliVParticle *part = static_cast<AliVParticle*>(array->At(i)); | |
522 | if (!part) continue; | |
523 | if (part->Pt() > fParticleMinPt && part->Pt() < fParticleMaxPt) return kTRUE; | |
524 | } | |
525 | } | |
526 | else if (array->GetClass()->InheritsFrom("AliVCluster")) { | |
527 | const Int_t nentries = array->GetEntriesFast(); | |
528 | for (Int_t i = 0; i < nentries; i++) { | |
529 | AliVCluster *clus = static_cast<AliVCluster*>(array->At(i)); | |
530 | if (!clus) continue; | |
531 | ||
532 | TLorentzVector vect; | |
533 | Double_t vert[3] = {0,0,0}; | |
534 | clus->GetMomentum(vect,vert); | |
535 | ||
536 | if (vect.Pt() > fParticleMinPt && vect.Pt() < fParticleMaxPt) return kTRUE; | |
537 | } | |
538 | } | |
539 | else { | |
540 | AliWarning(Form("Unable to do event selection based on particle pT: %s class type not recognized.",array->GetClass()->GetName())); | |
541 | } | |
542 | ||
543 | return kFALSE; | |
544 | } | |
545 | ||
b16bb001 | 546 | //________________________________________________________________________ |
547 | void AliJetEmbeddingFromAODTask::Run() | |
548 | { | |
549 | if (!GetNextEntry()) { | |
7030f36f | 550 | if (fHistNotEmbedded) |
551 | fHistNotEmbedded->Fill(fCurrentFileID); | |
2103dc6a | 552 | if (fHistEmbeddingQA) |
553 | fHistEmbeddingQA->Fill("Not embedded", 1); | |
6a20534a | 554 | AliError("Unable to get the AOD event to embed. Nothing will be embedded."); |
b16bb001 | 555 | return; |
556 | } | |
557 | ||
2103dc6a | 558 | if (fHistEmbeddingQA) |
559 | fHistEmbeddingQA->Fill("OK", 1); | |
560 | ||
43032ce2 | 561 | fAODFilePath->SetString(fCurrentAODFile->GetName()); |
562 | ||
787a3c4f | 563 | if (fOutMCParticles) { |
564 | ||
565 | if (fCopyArray && fMCParticles) | |
566 | CopyMCParticles(); | |
567 | ||
568 | if (fAODMCParticles) { | |
4358e58a | 569 | AliDebug(3, Form("%d MC particles will be processed for embedding.", fAODMCParticles->GetEntriesFast())); |
787a3c4f | 570 | for (Int_t i = 0; i < fAODMCParticles->GetEntriesFast(); i++) { |
571 | AliAODMCParticle *part = static_cast<AliAODMCParticle*>(fAODMCParticles->At(i)); | |
572 | if (!part) { | |
573 | AliError(Form("Could not find MC particle %d in branch %s of tree %s!", i, fAODMCParticlesName.Data(), fAODTreeName.Data())); | |
574 | continue; | |
575 | } | |
576 | ||
5be3857d | 577 | AliDebug(3, Form("Processing MC particle %d with pT = %f, eta = %f, phi = %f", i, part->Pt(), part->Eta(), part->Phi())); |
578 | ||
787a3c4f | 579 | if (!part->IsPhysicalPrimary()) |
580 | continue; | |
581 | ||
5be3857d | 582 | if (part->Pt() < fPtMin || part->Pt() > fPtMax || |
583 | part->Eta() < fEtaMin || part->Eta() > fEtaMax || | |
584 | part->Phi() < fPhiMin || part->Phi() > fPhiMax) | |
585 | continue; | |
586 | ||
787a3c4f | 587 | AddMCParticle(part, i); |
5be3857d | 588 | AliDebug(3, "Embedded!"); |
787a3c4f | 589 | } |
590 | } | |
591 | } | |
592 | ||
593 | if (fOutTracks) { | |
b16bb001 | 594 | |
787a3c4f | 595 | if (fCopyArray && fTracks) |
b16bb001 | 596 | CopyTracks(); |
597 | ||
4358e58a | 598 | AliDebug(3, Form("Start embedding with %d tracks.", fOutTracks->GetEntriesFast())); |
5be3857d | 599 | |
b16bb001 | 600 | if (fAODTracks) { |
4358e58a | 601 | AliDebug(3, Form("%d tracks will be processed for embedding.", fAODTracks->GetEntriesFast())); |
b16bb001 | 602 | for (Int_t i = 0; i < fAODTracks->GetEntriesFast(); i++) { |
603 | AliVTrack *track = static_cast<AliVTrack*>(fAODTracks->At(i)); | |
604 | if (!track) { | |
605 | AliError(Form("Could not find track %d in branch %s of tree %s!", i, fAODTrackName.Data(), fAODTreeName.Data())); | |
606 | continue; | |
607 | } | |
608 | ||
5be3857d | 609 | AliDebug(3, Form("Processing track %d with pT = %f, eta = %f, phi = %f, label = %d", i, track->Pt(), track->Eta(), track->Phi(), track->GetLabel())); |
610 | ||
b16bb001 | 611 | Int_t type = 0; |
612 | Bool_t isEmc = kFALSE; | |
613 | if (!fEsdTreeMode) { | |
614 | AliAODTrack *aodtrack = static_cast<AliAODTrack*>(track); | |
615 | if (aodtrack->TestFilterBit(fAODfilterBits[0])) { | |
616 | type = 0; | |
617 | } | |
618 | else if (aodtrack->TestFilterBit(fAODfilterBits[1])) { | |
619 | if ((aodtrack->GetStatus()&AliESDtrack::kITSrefit)==0) { | |
620 | if (fIncludeNoITS) | |
621 | type = 2; | |
5be3857d | 622 | else { |
623 | AliDebug(3, "Track not embedded because ITS refit failed."); | |
b16bb001 | 624 | continue; |
e2b76953 | 625 | } |
5be3857d | 626 | } |
b16bb001 | 627 | else { |
628 | type = 1; | |
629 | } | |
630 | } | |
631 | else { /*not a good track*/ | |
5be3857d | 632 | AliDebug(3, "Track not embedded because not an hybrid track."); |
b16bb001 | 633 | continue; |
634 | } | |
9adcb46d | 635 | if (fCutMaxFractionSharedTPCClusters > 0) { |
636 | Double_t frac = Double_t(aodtrack->GetTPCnclsS()) / Double_t(aodtrack->GetTPCncls()); | |
637 | if (frac > fCutMaxFractionSharedTPCClusters) | |
638 | continue; | |
639 | } | |
b16bb001 | 640 | if (TMath::Abs(aodtrack->GetTrackEtaOnEMCal()) < 0.75 && |
641 | aodtrack->GetTrackPhiOnEMCal() > 70 * TMath::DegToRad() && | |
642 | aodtrack->GetTrackPhiOnEMCal() < 190 * TMath::DegToRad()) | |
643 | isEmc = kTRUE; | |
644 | } | |
cd6431de | 645 | else if (fPicoTrackVersion > 0) { /*not AOD mode, let's see if it is PicoTrack*/ |
b16bb001 | 646 | AliPicoTrack *ptrack = dynamic_cast<AliPicoTrack*>(track); |
647 | if (ptrack) { | |
cd6431de | 648 | if (fPicoTrackVersion >= 3) |
649 | type = ptrack->GetTrackType(); | |
650 | else | |
651 | type = ptrack->GetLabel(); | |
b16bb001 | 652 | isEmc = ptrack->IsEMCAL(); |
e2b76953 | 653 | |
654 | if (!fIncludeNoITS && type==2) { | |
655 | AliDebug(3, "Track not embedded because ITS refit failed."); | |
656 | continue; | |
657 | } | |
b16bb001 | 658 | } |
659 | } | |
660 | ||
5be3857d | 661 | if (track->Pt() < fPtMin || track->Pt() > fPtMax || |
662 | track->Eta() < fEtaMin || track->Eta() > fEtaMax || | |
663 | track->Phi() < fPhiMin || track->Phi() > fPhiMax) { | |
664 | AliDebug(3, "Track not embedded because out of limits."); | |
665 | continue; | |
666 | } | |
667 | ||
5ce8ae64 | 668 | if (fTrackEfficiency < 1) { |
669 | Double_t r = gRandom->Rndm(); | |
5be3857d | 670 | if (fTrackEfficiency < r) { |
671 | AliDebug(3, "Track not embedded because of artificial inefiiciency."); | |
5ce8ae64 | 672 | continue; |
4358e58a | 673 | } |
5be3857d | 674 | } |
5ce8ae64 | 675 | |
7030f36f | 676 | Int_t label = 0; |
4358e58a | 677 | if (fIsAODMC) { |
5ce8ae64 | 678 | if (fUseNegativeLabels) |
679 | label = track->GetLabel(); | |
680 | else | |
681 | label = TMath::Abs(track->GetLabel()); | |
682 | ||
4358e58a | 683 | if (label == 0) |
cac0e10b | 684 | AliDebug(1,Form("%s: Track %d with label==0", GetName(), i)); |
7030f36f | 685 | } |
686 | ||
56bd3193 | 687 | AddTrack(track->Pt(), track->Eta(), track->Phi(), type, track->GetTrackEtaOnEMCal(), track->GetTrackPhiOnEMCal(), track->GetTrackPtOnEMCal(), isEmc, label, track->Charge()); |
5be3857d | 688 | AliDebug(3, "Track embedded!"); |
b16bb001 | 689 | } |
690 | } | |
691 | } | |
692 | ||
787a3c4f | 693 | if (fOutClusters) { |
b16bb001 | 694 | |
787a3c4f | 695 | if (fCopyArray && fClusters) |
b16bb001 | 696 | CopyClusters(); |
697 | ||
698 | if (fAODClusters) { | |
699 | for (Int_t i = 0; i < fAODClusters->GetEntriesFast(); i++) { | |
700 | AliVCluster *clus = static_cast<AliVCluster*>(fAODClusters->At(i)); | |
701 | if (!clus) { | |
702 | AliError(Form("Could not find cluster %d in branch %s of tree %s!", i, fAODClusName.Data(), fAODTreeName.Data())); | |
703 | continue; | |
704 | } | |
fde82e42 | 705 | |
706 | if (!clus->IsEMCAL()) | |
707 | continue; | |
708 | ||
b16bb001 | 709 | TLorentzVector vect; |
710 | Double_t vert[3] = {0,0,0}; | |
711 | clus->GetMomentum(vect,vert); | |
5be3857d | 712 | |
713 | if (vect.Pt() < fPtMin || vect.Pt() > fPtMax || | |
714 | vect.Eta() < fEtaMin || vect.Eta() > fEtaMax || | |
715 | vect.Phi() < fPhiMin || vect.Phi() > fPhiMax) | |
716 | continue; | |
fde82e42 | 717 | |
4358e58a | 718 | Int_t label = 0; |
719 | if (fIsAODMC) { | |
720 | label = clus->GetLabel(); | |
721 | if (label <= 0) | |
cac0e10b | 722 | AliDebug(1,Form("%s: Clus %d with label<=0", GetName(), i)); |
4358e58a | 723 | } |
507f74bc | 724 | AddCluster(clus); |
b16bb001 | 725 | } |
726 | } | |
727 | } | |
728 | ||
787a3c4f | 729 | if (fOutCaloCells) { |
730 | ||
4358e58a | 731 | Double_t totalEnergy = 0; |
787a3c4f | 732 | Int_t totalCells = 0; |
b16bb001 | 733 | |
787a3c4f | 734 | if (fCaloCells) |
735 | totalCells += fCaloCells->GetNumberOfCells(); | |
b16bb001 | 736 | if (fAODCaloCells) |
737 | totalCells += fAODCaloCells->GetNumberOfCells(); | |
738 | ||
739 | SetNumberOfOutCells(totalCells); | |
740 | ||
787a3c4f | 741 | if (fCaloCells) |
742 | CopyCells(); | |
b16bb001 | 743 | |
744 | if (fAODCaloCells) { | |
745 | for (Short_t i = 0; i < fAODCaloCells->GetNumberOfCells(); i++) { | |
60d77596 | 746 | Int_t mclabel = 0; |
b16bb001 | 747 | Double_t efrac = 0.; |
748 | Double_t time = -1; | |
749 | Short_t cellNum = -1; | |
750 | Double_t amp = -1; | |
751 | ||
752 | fAODCaloCells->GetCell(i, cellNum, amp, time, mclabel, efrac); | |
4358e58a | 753 | |
754 | if (fIsAODMC) { | |
755 | if (mclabel <= 0) | |
cac0e10b | 756 | AliDebug(1,Form("%s: Cell %d with label<=0", GetName(), i)); |
4358e58a | 757 | } |
758 | else { | |
759 | mclabel = 0; | |
760 | } | |
761 | ||
762 | AliDebug(2,Form("Adding cell with amplitude %f, absolute ID %d, time %f, mc label %d", amp, cellNum, time, mclabel)); | |
787a3c4f | 763 | AddCell(amp, cellNum, time, mclabel); |
4358e58a | 764 | totalEnergy += amp; |
b16bb001 | 765 | } |
766 | } | |
4358e58a | 767 | AliDebug(2,Form("Added cells = %d (energy = %f), total cells = %d", fAddedCells, totalEnergy, totalCells)); |
b16bb001 | 768 | } |
769 | } | |
4358e58a | 770 | |
771 | //________________________________________________________________________ | |
772 | TLorentzVector AliJetEmbeddingFromAODTask::GetLeadingJet(TClonesArray *tracks, TClonesArray *clusters) | |
773 | { | |
774 | TString name("kt"); | |
775 | fastjet::JetAlgorithm jalgo(fastjet::kt_algorithm); | |
776 | if (fJetAlgo == 1) { | |
777 | name = "antikt"; | |
778 | jalgo = fastjet::antikt_algorithm; | |
779 | } | |
780 | ||
781 | // setup fj wrapper | |
782 | AliFJWrapper fjw(name, name); | |
783 | fjw.SetAreaType(fastjet::active_area_explicit_ghosts); | |
784 | fjw.SetGhostArea(1); // set a very large ghost area to speed up jet finding | |
785 | fjw.SetR(fJetRadius); | |
786 | fjw.SetAlgorithm(jalgo); | |
787 | fjw.SetMaxRap(1); | |
788 | fjw.Clear(); | |
789 | ||
790 | if (tracks) { | |
791 | const Int_t Ntracks = tracks->GetEntries(); | |
792 | for (Int_t iTracks = 0; iTracks < Ntracks; ++iTracks) { | |
793 | AliVParticle *t = static_cast<AliVParticle*>(tracks->At(iTracks)); | |
794 | if (!t) | |
795 | continue; | |
05077f28 | 796 | |
797 | AliAODMCParticle *aodmcpart = dynamic_cast<AliAODMCParticle*>(t); | |
798 | if (aodmcpart && !aodmcpart->IsPhysicalPrimary()) | |
799 | continue; | |
4358e58a | 800 | |
801 | if ((fJetType == 1 && t->Charge() == 0) || | |
802 | (fJetType == 2 && t->Charge() != 0)) | |
803 | continue; | |
804 | ||
05077f28 | 805 | if (t->Pt() < fJetConstituentMinPt) |
4358e58a | 806 | continue; |
807 | ||
808 | fjw.AddInputVector(t->Px(), t->Py(), t->Pz(), t->P(), iTracks + 100); | |
809 | } | |
810 | } | |
811 | ||
812 | if (clusters && fJetType != 1) { | |
813 | Double_t vert[3]={0}; | |
814 | if (fAODVertex) | |
815 | ((AliVVertex*)fAODVertex->At(0))->GetXYZ(vert); | |
816 | ||
817 | const Int_t Nclus = clusters->GetEntries(); | |
818 | for (Int_t iClus = 0; iClus < Nclus; ++iClus) { | |
819 | AliVCluster *c = static_cast<AliVCluster*>(clusters->At(iClus)); | |
820 | if (!c) | |
821 | continue; | |
822 | ||
823 | if (!c->IsEMCAL()) | |
824 | continue; | |
825 | ||
826 | TLorentzVector nP; | |
827 | c->GetMomentum(nP, vert); | |
828 | ||
05077f28 | 829 | if (nP.Pt() < fJetConstituentMinPt) |
4358e58a | 830 | continue; |
831 | ||
832 | fjw.AddInputVector(nP.Px(), nP.Py(), nP.Pz(), nP.P(), -iClus - 100); | |
833 | } | |
834 | } | |
835 | ||
836 | // run jet finder | |
837 | fjw.Run(); | |
838 | ||
839 | std::vector<fastjet::PseudoJet> jets_incl = fjw.GetInclusiveJets(); | |
840 | AliDebug(1,Form("%d jets found", (Int_t)jets_incl.size())); | |
841 | ||
842 | TLorentzVector jet; | |
843 | ||
844 | Int_t njets = jets_incl.size(); | |
845 | ||
846 | if (njets > 0) { | |
05077f28 | 847 | //std::vector<fastjet::PseudoJet> jets_incl_sorted = fastjet::sorted_by_pt(jets_incl); |
4358e58a | 848 | for (Int_t i = 0; i < njets; i++) { |
05077f28 | 849 | if (jet.Pt() >= jets_incl[i].perp()) |
850 | continue; | |
851 | if (jets_incl[i].eta() < fJetMinEta || jets_incl[i].eta() > fJetMaxEta || jets_incl[i].phi() < fJetMinPhi || jets_incl[i].phi() > fJetMaxPhi) | |
852 | continue; | |
853 | jet.SetPxPyPzE(jets_incl[i].px(), jets_incl[i].py(), jets_incl[i].pz(), jets_incl[i].E()); | |
4358e58a | 854 | } |
855 | } | |
856 | ||
857 | return jet; | |
858 | } |