Updated to Jet embedding to add real jets (J. Klein)
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskFastEmbedding.cxx
CommitLineData
b725dccf 1/*************************************************************************
2 * *
3 * Task for fast embedding *
4 * read extra input from AOD *
5 * *
6 *************************************************************************/
7
8
9/**************************************************************************
10 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
11 * *
12 * Author: The ALICE Off-line Project. *
13 * Contributors are mentioned in the code where appropriate. *
14 * *
15 * Permission to use, copy, modify and distribute this software and its *
16 * documentation strictly for non-commercial purposes is hereby granted *
17 * without fee, provided that the above copyright notice appears in all *
18 * copies and that both the copyright notice and this permission notice *
19 * appear in the supporting documentation. The authors make no claims *
20 * about the suitability of this software for any purpose. It is *
21 * provided "as is" without express or implied warranty. *
22 **************************************************************************/
23
24/* $Id: */
25
26#include <TFile.h>
27#include <TTree.h>
28#include <TChain.h>
29#include <TClonesArray.h>
30#include <TDirectory.h>
31#include <TSystem.h>
32#include <TRef.h>
33#include <TRandom3.h>
34#include <TH1F.h>
35#include <TH2F.h>
36
37
38#include "AliAnalysisTaskFastEmbedding.h"
39#include "AliAnalysisManager.h"
40#include "AliAODEvent.h"
41#include "AliAODTrack.h"
42#include "AliAODJet.h"
43#include "AliAODMCParticle.h"
44
45#include "AliLog.h"
46
47ClassImp(AliAnalysisTaskFastEmbedding)
48
49//__________________________________________________________________________
50AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding()
51 : AliAnalysisTaskSE()
52 ,fAODout(0)
53 ,fAODevent(0)
54 ,fAODtree(0)
55 ,fAODfile(0)
0ed51e0d 56 ,rndm(0)
b725dccf 57 ,fAODPathArray(0)
58 ,fAODPath("AliAOD.root")
59 ,fTrackBranch("aodExtraTracks")
60 ,fMCparticlesBranch("aodExtraMCparticles")
1a2bb6d5 61 ,fJetBranch("")
b725dccf 62 ,fEntry(0)
b725dccf 63 ,fEmbedMode(0)
64 ,fEvtSelecMode(0)
65 ,fEvtSelMinJetPt(-1)
66 ,fEvtSelMaxJetPt(-1)
67 ,fToyMinNbOfTracks(1)
68 ,fToyMaxNbOfTracks(1)
69 ,fToyMinTrackPt(50.)
70 ,fToyMaxTrackPt(50.)
71 ,fToyDistributionTrackPt(0.)
72 ,fToyMinTrackEta(-.5)
73 ,fToyMaxTrackEta(.5)
74 ,fToyMinTrackPhi(0.)
75 ,fToyMaxTrackPhi(2*TMath::Pi())
76 ,fToyFilterMap(0)
77 ,fHistList(0)
78 ,fh1TrackPt(0)
79 ,fh2TrackEtaPhi(0)
80 ,fh1TrackN(0)
81 ,fh1MCTrackPt(0)
82 ,fh2MCTrackEtaPhi(0)
83 ,fh1MCTrackN(0)
84
85
86{
87 // default constructor
88
89}
90
91
92//__________________________________________________________________________
93AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding(const char *name)
94 : AliAnalysisTaskSE(name)
95 ,fAODout(0)
96 ,fAODevent(0)
97 ,fAODtree(0)
98 ,fAODfile(0)
0ed51e0d 99 ,rndm(0)
b725dccf 100 ,fAODPathArray(0)
101 ,fAODPath("AliAOD.root")
102 ,fTrackBranch("aodExtraTracks")
103 ,fMCparticlesBranch("aodExtraMCparticles")
1a2bb6d5 104 ,fJetBranch("")
b725dccf 105 ,fEntry(0)
b725dccf 106 ,fEmbedMode(0)
107 ,fEvtSelecMode(0)
108 ,fEvtSelMinJetPt(-1)
109 ,fEvtSelMaxJetPt(-1)
110 ,fToyMinNbOfTracks(1)
111 ,fToyMaxNbOfTracks(1)
112 ,fToyMinTrackPt(50.)
113 ,fToyMaxTrackPt(50.)
114 ,fToyDistributionTrackPt(0.)
115 ,fToyMinTrackEta(-.5)
116 ,fToyMaxTrackEta(.5)
117 ,fToyMinTrackPhi(0.)
118 ,fToyMaxTrackPhi(2*TMath::Pi())
119 ,fToyFilterMap(0)
120 ,fHistList(0)
121 ,fh1TrackPt(0)
122 ,fh2TrackEtaPhi(0)
123 ,fh1TrackN(0)
124 ,fh1MCTrackPt(0)
125 ,fh2MCTrackEtaPhi(0)
126 ,fh1MCTrackN(0)
127{
128 // constructor
129 DefineOutput(1, TList::Class());
130}
131
132
133//__________________________________________________________________________
134AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding(const AliAnalysisTaskFastEmbedding &copy)
135 : AliAnalysisTaskSE()
136 ,fAODout(copy.fAODout)
137 ,fAODevent(copy.fAODevent)
138 ,fAODtree(copy.fAODtree)
139 ,fAODfile(copy.fAODfile)
140 ,rndm(copy.rndm)
141 ,fAODPathArray(copy.fAODPathArray)
142 ,fAODPath(copy.fAODPath)
143 ,fTrackBranch(copy.fTrackBranch)
144 ,fMCparticlesBranch(copy.fMCparticlesBranch)
1a2bb6d5 145 ,fJetBranch(copy.fJetBranch)
b725dccf 146 ,fEntry(copy.fEntry)
b725dccf 147 ,fEmbedMode(copy.fEmbedMode)
148 ,fEvtSelecMode(copy.fEvtSelecMode)
149 ,fEvtSelMinJetPt(copy.fEvtSelMinJetPt)
150 ,fEvtSelMaxJetPt(copy.fEvtSelMaxJetPt)
151 ,fToyMinNbOfTracks(copy.fToyMinNbOfTracks)
152 ,fToyMaxNbOfTracks(copy.fToyMaxNbOfTracks)
153 ,fToyMinTrackPt(copy.fToyMinTrackPt)
154 ,fToyMaxTrackPt(copy.fToyMaxTrackPt)
155 ,fToyDistributionTrackPt(copy.fToyDistributionTrackPt)
156 ,fToyMinTrackEta(copy.fToyMinTrackEta)
157 ,fToyMaxTrackEta(copy.fToyMaxTrackEta)
158 ,fToyMinTrackPhi(copy.fToyMinTrackPhi)
159 ,fToyMaxTrackPhi(copy.fToyMaxTrackPhi)
160 ,fToyFilterMap(copy.fToyFilterMap)
161 ,fHistList(copy.fHistList)
162 ,fh1TrackPt(copy.fh1TrackPt)
163 ,fh2TrackEtaPhi(copy.fh2TrackEtaPhi)
164 ,fh1TrackN(copy.fh1TrackN)
165 ,fh1MCTrackPt(copy.fh1MCTrackPt)
166 ,fh2MCTrackEtaPhi(copy.fh2MCTrackEtaPhi)
167 ,fh1MCTrackN(copy.fh1MCTrackN)
168{
169 // copy constructor
170}
171
172
173//__________________________________________________________________________
174AliAnalysisTaskFastEmbedding& AliAnalysisTaskFastEmbedding::operator=(const AliAnalysisTaskFastEmbedding& o)
175{
176 // assignment
177
178 if(this!=&o){
179 AliAnalysisTaskSE::operator=(o);
180 fAODout = o.fAODout;
181 fAODevent = o.fAODevent;
182 fAODtree = o.fAODtree;
183 fAODfile = o.fAODfile;
184 rndm = o.rndm;
185 fAODPathArray = o.fAODPathArray;
186 fAODPath = o.fAODPath;
187 fTrackBranch = o.fTrackBranch;
188 fMCparticlesBranch = o.fMCparticlesBranch;
1a2bb6d5 189 fJetBranch = o.fJetBranch;
b725dccf 190 fEntry = o.fEntry;
b725dccf 191 fEmbedMode = o.fEmbedMode;
192 fEvtSelecMode = o.fEvtSelecMode;
193 fEvtSelMinJetPt = o.fEvtSelMinJetPt;
194 fEvtSelMaxJetPt = o.fEvtSelMaxJetPt;
195 fToyMinNbOfTracks = o.fToyMinNbOfTracks;
196 fToyMaxNbOfTracks = o.fToyMaxNbOfTracks;
197 fToyMinTrackPt = o.fToyMinTrackPt;
198 fToyMaxTrackPt = o.fToyMaxTrackPt;
199 fToyDistributionTrackPt = o.fToyDistributionTrackPt;
200 fToyMinTrackEta = o.fToyMinTrackEta;
201 fToyMaxTrackEta = o.fToyMaxTrackEta;
202 fToyMinTrackPhi = o.fToyMinTrackPhi;
203 fToyMaxTrackPhi = o.fToyMaxTrackPhi;
204 fToyFilterMap = o.fToyFilterMap;
205 fHistList = o.fHistList;
206 fh1TrackPt = o.fh1TrackPt;
207 fh2TrackEtaPhi = o.fh2TrackEtaPhi;
208 fh1TrackN = o.fh1TrackN;
209 fh1MCTrackPt = o.fh1MCTrackPt;
210 fh2MCTrackEtaPhi = o.fh2MCTrackEtaPhi;
211 fh1MCTrackN = o.fh1MCTrackN;
212 }
213
214 return *this;
215}
216
217
218//__________________________________________________________________________
219AliAnalysisTaskFastEmbedding::~AliAnalysisTaskFastEmbedding()
220{
221 // destructor
222 delete rndm;
223}
224
225
226//__________________________________________________________________________
227void AliAnalysisTaskFastEmbedding::UserCreateOutputObjects()
228{
229 // create output objects
230 if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::UserCreateOutputObjects()");
231
0ed51e0d 232 rndm = new TRandom3();
233 Int_t id = GetJobID();
234 if(id>-1) rndm->SetSeed(id);
235 else rndm->SetSeed(); // a TTUID is generated and used for seed
236 AliInfo(Form("TRandom3 seed: %d", rndm->GetSeed()));
b725dccf 237
238
239 // embed mode with AOD
240 if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks || fEmbedMode==kAODJet4Mom){
241
242 // open input AOD
243 if(fAODPathArray){
1a2bb6d5 244 Int_t rc = SelectAODfile();
245 if(rc<0) return;
b725dccf 246 }
247
1a2bb6d5 248 Int_t rc = OpenAODfile();
249 if(rc<0) return;
b725dccf 250
b725dccf 251 } //end: embed mode with AOD
252
253
254 // connect output aod
255 // create a new branch for extra tracks
256 fAODout = AODEvent();
257 if(!fAODout){
258 AliError("Output AOD not found.");
259 return;
260 }
261 if(!fAODout->FindListObject(fTrackBranch.Data()) && strlen(fTrackBranch.Data())){
262 AliInfo(Form("Add AOD branch %s", fTrackBranch.Data()));
263 TClonesArray *tracks = new TClonesArray("AliAODTrack",0);
264 tracks->SetName(fTrackBranch.Data());
265 AddAODBranch("TClonesArray", &tracks);
266 }
267 // create new branch for extra mcparticle if available as input
268 if(fAODevent && fAODevent->FindListObject("mcparticles") && strlen(fMCparticlesBranch.Data())){
269 AliInfo(Form("Add AOD branch %s", fMCparticlesBranch.Data()));
270 TClonesArray *mcparticles = new TClonesArray("AliAODMCParticle",0);
271 mcparticles->SetName(fMCparticlesBranch.Data());
272 AddAODBranch("TClonesArray", &mcparticles);
273 }
274
275
276
277
278 //qa histograms
279
280 OpenFile(1);
281 fHistList = new TList();
282
283 Bool_t oldStatus = TH1::AddDirectoryStatus();
284 TH1::AddDirectory(kFALSE);
285
286 fh1TrackPt = new TH1F("fh1TrackPt","pT of extra tracks;p_{T};entries", 300, 0., 300.);
287 fh2TrackEtaPhi = new TH2F("fh2TrackEtaPhi","eta-phi distribution of extra tracks;#eta;#phi", 20, -1., 1., 60, 0., 2*TMath::Pi());
288 fh1TrackN = new TH1F("fh1TrackN", "nb. of extra tracks per event;nb. of tracks;entries",300, 0., 3000.);
289
290 fHistList->Add(fh1TrackPt);
291 fHistList->Add(fh2TrackEtaPhi);
292 fHistList->Add(fh1TrackN);
293
294
295 if(fAODevent && fAODevent->FindListObject("mcparticles") && strlen(fMCparticlesBranch.Data())){
296
297 fh1MCTrackPt = new TH1F("fh1MCTrackPt","pT of MC extra tracks;p_{T};entries", 300, 0., 300.);
298 fh2MCTrackEtaPhi = new TH2F("fh2MCTrackEtaPhi","eta-phi distribution of MC extra tracks;#eta;#phi", 20, -1., 1., 60, 0., 2*TMath::Pi());
299 fh1MCTrackN = new TH1F("fh1MCTrackN", "nb. of MC extra tracks per event;nb. of tracks;entries",300, 0., 3000.);
300
301 fHistList->Add(fh1MCTrackPt);
302 fHistList->Add(fh2MCTrackEtaPhi);
303 fHistList->Add(fh1MCTrackN);
304
305 }
306
307 TH1::AddDirectory(oldStatus);
308
309}
310
311
312//__________________________________________________________________________
313void AliAnalysisTaskFastEmbedding::Init()
314{
315 // Initialization
316 if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::Init()");
317
b725dccf 318}
319
320
321//__________________________________________________________________________
322void AliAnalysisTaskFastEmbedding::UserExec(Option_t *)
323{
324 if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::UserExec()");
325
326 if(!fAODout){
327 AliError("Need output AOD, but is not connected.");
328 return;
329 }
330
331 // connect aod out
332 TClonesArray *tracks = (TClonesArray*)(fAODout->FindListObject(fTrackBranch.Data()));
333 if(!tracks){
334 AliError("Extra track branch not found in output.");
335 return;
336 }
337 tracks->Delete();
338 Int_t nAODtracks=0;
339
340
341 TRef dummy;
342
343 // === embed mode with AOD ===
344 if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks || fEmbedMode==kAODJet4Mom){
345 if(!fAODevent){
346 AliError("Need input AOD, but is not connected.");
347 return;
348 }
349
1a2bb6d5 350 // fetch jets
351 TClonesArray *aodJets = 0;
352 if(fJetBranch.Length()) aodJets = dynamic_cast<TClonesArray*>(fAODevent->FindListObject(fJetBranch.Data()));
353 else aodJets = fAODevent->GetJets();
354 if(!aodJets){
355 AliError("Could not find jets in AOD. Check jet branch when indicated.");
356 return;
357 }
358
359
b725dccf 360 Int_t nEvents = fAODtree->GetEntries();
b725dccf 361
362 Bool_t useEntry = kFALSE;
363 while(!useEntry){ // protection need, if no event fulfills requierment
a11972e9 364 if(fEntry>=nEvents){
1a2bb6d5 365 fEntry=0;
366 if(!fAODPathArray){
367 AliDebug(AliLog::kDebug, "Last event in AOD reached, start from entry 0 again.");
368 }
369 else {
370 AliDebug(AliLog::kDebug, "Last event in AOD reached, select new AOD file ...");
371 Int_t rc = SelectAODfile();
372 if(rc<0) return;
373
374 rc = OpenAODfile();
375 if(rc<0) return;
a11972e9 376
377 // new file => we must use the new jet array
378 if(fJetBranch.Length()) aodJets = dynamic_cast<TClonesArray*>(fAODevent->FindListObject(fJetBranch.Data()));
379 else aodJets = fAODevent->GetJets();
380 if(!aodJets){
381 AliError("Could not find jets in AOD. Check jet branch when indicated.");
382 return;
383 }
1a2bb6d5 384 }
385 }
386
b725dccf 387 fAODtree->GetEvent(fEntry);
388
389 // jet pt selection
390 if(fEvtSelecMode==kEventsJetPt){
1a2bb6d5 391 Int_t nJets = aodJets->GetEntries();
b725dccf 392 for(Int_t ij=0; ij<nJets; ++ij){
1a2bb6d5 393 AliAODJet *jet = dynamic_cast<AliAODJet*>(aodJets->At(ij));
394 if(!jet) continue;
b725dccf 395
396 if( (fEvtSelMinJetPt==-1. || jet->Pt()>=fEvtSelMinJetPt)
397 && (fEvtSelMaxJetPt==-1. || jet->Pt()<=fEvtSelMaxJetPt)){
398 useEntry = kTRUE;
399 break;
400 }
401 }
402 }
403
404 // no selection
405 if(fEvtSelecMode==kEventsAll){
406 useEntry = kTRUE;
407 }
408
409 fEntry++;
410 }
411 AliInfo(Form("Use entry %d from extra AOD.", fEntry-1));
412
413
414 TClonesArray *mcpartIN = (TClonesArray*)(fAODevent->FindListObject("mcparticles"));
415 TClonesArray *mcpartOUT = 0x0;
416 if(mcpartIN){
417 mcpartOUT = (TClonesArray*)(fAODout->FindListObject(fMCparticlesBranch.Data()));
418 mcpartOUT->Delete();
419 } else {
420 AliInfo("No extra MC particles found.");
421 }
422
423
424 if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks){ // take all tracks or jet tracks
425 // loop over input tracks
426 // add to output aod
427 Int_t nTracks = fAODevent->GetNumberOfTracks();
428 fh1TrackN->Fill((Float_t)nTracks);
429
430 for(Int_t it=0; it<nTracks; ++it){
431 AliAODTrack *tmpTr = fAODevent->GetTrack(it);
432 // ?? test filter bit, or something else??
433
434 if(fEmbedMode==kAODJetTracks){
435 // jet track? else continue
436 // not implemented yet
437 continue;
438 }
439
440 new ((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr);
441 dummy = (*tracks)[nAODtracks-1];
442
443 fh1TrackPt->Fill(tmpTr->Pt());
444 fh2TrackEtaPhi->Fill(tmpTr->Eta(), tmpTr->Phi());
445 }
446
447 if(mcpartIN){
448 Int_t nMCpart = mcpartIN->GetEntriesFast();
449
450 Int_t nPhysicalPrimary=0;
451 Int_t nAODmcpart=0;
452 for(Int_t ip=0; ip<nMCpart; ++ip){
453 AliAODMCParticle *tmpPart = (AliAODMCParticle*) mcpartIN->At(ip);
454
455 if(fEmbedMode==kAODJetTracks){
456 // jet track? else continue
457 // not implemented yet
458 continue;
459 }
460
461 new((*mcpartOUT)[nAODmcpart++]) AliAODMCParticle(*tmpPart);
462 dummy = (*mcpartOUT)[nAODmcpart-1];
463
464 if(tmpPart->IsPhysicalPrimary() && tmpPart->Charge()!=0. && tmpPart->Charge()!=-99. ){
465 fh1MCTrackPt->Fill(tmpPart->Pt());
466 fh2MCTrackEtaPhi->Fill(tmpPart->Eta(), tmpPart->Phi());
467 nPhysicalPrimary++;
468 }
469 }
470 fh1MCTrackN->Fill((Float_t)nPhysicalPrimary);
471
472 }
473 } // end: embed all tracks or jet tracks
474
475
476 if(fEmbedMode==kAODJet4Mom){
477
478 // loop over jets
1a2bb6d5 479 Int_t nJets = aodJets->GetEntries();
b725dccf 480 fh1TrackN->Fill((Float_t)nJets);
481 for(Int_t ij=0; ij<nJets; ++ij){
1a2bb6d5 482 AliAODJet *jet = dynamic_cast<AliAODJet*>(aodJets->At(ij));
483 if(!jet) continue;
b725dccf 484 AliAODTrack *tmpTr = (AliAODTrack*)jet;
485
486 new ((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr);
487 dummy = (*tracks)[nAODtracks-1];
488
489 fh1TrackPt->Fill(tmpTr->Pt());
490 fh2TrackEtaPhi->Fill(tmpTr->Eta(), tmpTr->Phi());
491 }
492
493 } // end: embed jets as 4-momenta
494
495
496 } //end: embed mode with AOD
497
498
499 // === embed mode with toy ===
500 if(fEmbedMode==kToyTracks){
501 Int_t nT = (Int_t)(rndm->Uniform(fToyMinNbOfTracks, fToyMaxNbOfTracks)+0.5);
502
503 fh1TrackN->Fill((Float_t)nT);
504
505 for(Int_t i=0; i<nT; ++i){
506
507 Double_t pt = -1.;
508 if(fToyMinTrackPt!=fToyMaxTrackPt){
509 if(fToyDistributionTrackPt==0){
510 pt = rndm->Uniform(fToyMinTrackPt, fToyMaxTrackPt);
511 } else {
512 while(pt<fToyMinTrackPt||pt>fToyMaxTrackPt){
513 pt = rndm->Exp(fToyDistributionTrackPt); // no power law yet!!
514 pt += fToyMinTrackPt;
515 }
516 }
517 } else {
518 pt = fToyMinTrackPt;
519 }
520 Double_t eta = rndm->Uniform(fToyMinTrackEta,fToyMaxTrackEta);
521 Double_t phi = rndm->Uniform(fToyMinTrackPhi,fToyMaxTrackPhi);
522 phi = TVector2::Phi_0_2pi(phi);
523
524 Printf("Add track #%d: pt %.2f, eta %.2f, phi %.2f", i, pt, eta, phi);
525
526 Double_t theta = 2*TMath::ATan(1/TMath::Exp(eta));
527 Float_t mom[3];
528 mom[0] = pt;
529 mom[1] = phi;
530 mom[2] = theta;
531
532 Float_t xyz[3];
533 xyz[0] = -999.;
534 xyz[1] = -999.;
535 xyz[2] = -999.;
536
537 AliAODTrack *tmpTr = new AliAODTrack( -999, // id
538 -999, // label
539 mom, // momentum[3]
540 kFALSE, // cartesian
541 xyz, // position
542 kFALSE, // DCA
543 NULL, // covMatrix,
544 -99, // charge
545 0, // itsClusMap
546 NULL, // pid
547 NULL, // prodVertex
548 kFALSE, // used for vertex fit
549 kFALSE, // used for prim vtx fit
550 AliAODTrack::kUndef, // type
551 fToyFilterMap, // select info
552 -999. // chi2 per NDF
553 );
0ed51e0d 554 tmpTr->SetFlags(1<<27);
b725dccf 555
556 new((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr);
557 dummy = (*tracks)[nAODtracks-1];
558
559 fh1TrackPt->Fill(pt);
560 fh2TrackEtaPhi->Fill(eta,phi);
561
562 delete tmpTr;
563 }
564 } //end: embed mode with toy
565
566
567 PostData(1, fHistList);
568}
569
570
571//__________________________________________________________________________
572void AliAnalysisTaskFastEmbedding::Terminate(Option_t *)
573{
574 if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::Terminate()");
575
576 if(fAODfile && fAODfile->IsOpen())
577 fAODfile->Close();
578
579}
580
581//__________________________________________________________________________
b725dccf 582Int_t AliAnalysisTaskFastEmbedding::GetJobID()
583{
0ed51e0d 584 Int_t id=-1;
b725dccf 585
0ed51e0d 586 const char* env = gSystem->Getenv("ALIEN_PROC_ID"); // GRID
587 //if(!env || !strlen(env)) env = gSystem->Getenv("LSB_JOBINDEX"); // GSI
b725dccf 588
589 if(env && strlen(env)){
590 id= atoi(env);
591 AliInfo(Form("Job index %d", id));
592 }
593 else{
594 AliInfo("Job index not found. Okay if running locally.");
b725dccf 595 }
596
597 return id;
0ed51e0d 598}
b725dccf 599
600//__________________________________________________________________________
601
1a2bb6d5 602Int_t AliAnalysisTaskFastEmbedding::SelectAODfile(){
b725dccf 603
1a2bb6d5 604 Int_t nFiles = fAODPathArray->GetEntries();
605 Int_t n = rndm->Integer(nFiles);
606 AliInfo(Form("Select AOD file %d", n));
607 TObjString *objStr = (TObjString*) fAODPathArray->At(n);
608 if(!objStr){
609 AliError("Could not get path of aod file.");
610 return -1;
611 }
612 fAODPath = objStr->GetString();
613
614 return n;
615}
616
617Int_t AliAnalysisTaskFastEmbedding::OpenAODfile(){
618
619 TDirectory *owd = gDirectory;
a11972e9 620 if (fAODfile)
621 fAODfile->Close();
1a2bb6d5 622 fAODfile = TFile::Open(fAODPath.Data());
623 owd->cd();
624 if(!fAODfile){
625 AliError("Could not open AOD file.");
626 return -1;
627 }
628
629 fAODtree = (TTree*)fAODfile->Get("aodTree");
630
631 if(!fAODtree){
632 AliError("AOD tree not found.");
633 return -1;
634 }
635
a11972e9 636 delete fAODevent;
1a2bb6d5 637 fAODevent = new AliAODEvent();
638 fAODevent->ReadFromTree(fAODtree);
639 if(!fAODevent){
640 AliError("AOD event not found.");
641 return -1;
642 }
643
644 return 1;
645}
b725dccf 646