]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG/CaloTrackCorrBase/AliAnalysisTaskCounter.cxx
simplify track pT retrieval
[u/mrichter/AliRoot.git] / PWG / CaloTrackCorrBase / AliAnalysisTaskCounter.cxx
CommitLineData
0b080dc9 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
dd094cf8 4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
dd094cf8 15
16//_________________________________________________________________________
17// Count events with different selections
18//
19// It produces a histogram with the number of events with 9 bins:
20// 0: all events (that passed the physics selection if it was on)
21// 1: same but cross check that event pointer did exist
22// 2: passes vertex cut
23// 3: passes track number cut, tracks for eta < 0.8
24// 4: 3 && 2
99e2921c 25// 5: pass V0AND
dd094cf8 26// 6: 5 && 2
27// 7: 5 && 3
28// 8: 5 && 3 && 2
29// 9: not pileup from SPD
30// 10: Good vertex
31// 11: 10 && 5
32// 12: 10 && 3
33// 13: 10 && 2
34// 14: 10 && 2 && 3 && 5
35// 15: 10 && 9
36// 16: 9 && 5
37//
38// Author: Gustavo Conesa Balbastre (LPSC)
39//
40//_________________________________________________________________________
46f9f991 41#include <TSystem.h>
42#include <TFile.h>
43#include <TKey.h>
44#include <TH2F.h>
45#include <TProfile.h>
46#include <TProfile2D.h>
47#include <TList.h>
48#include <TClonesArray.h>
5b96be07 49#include <TGeoGlobalMagField.h>
dd094cf8 50#include "AliAODHeader.h"
99e2921c 51//#include "AliTriggerAnalysis.h"
dd094cf8 52#include "AliESDEvent.h"
cd2e4ce6 53#include "AliAODEvent.h"
dd094cf8 54#include "AliESDtrackCuts.h"
55#include "AliAnalysisManager.h"
56#include "AliInputEventHandler.h"
57
58#include "AliAnalysisTaskCounter.h"
59ClassImp(AliAnalysisTaskCounter)
60
0de1814a 61//______________________________________________________________
dd094cf8 62AliAnalysisTaskCounter::AliAnalysisTaskCounter(const char *name)
63: AliAnalysisTaskSE(name),
cd2e4ce6 64 fAcceptFastCluster(kTRUE),
65 fZVertexCut(10.),
dd094cf8 66 fTrackMultEtaCut(0.8),
46f9f991 67 fAvgTrials(-1),
997b261e 68 fOutputContainer(0x0),
dd094cf8 69 fESDtrackCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
99e2921c 70 //fTriggerAnalysis (new AliTriggerAnalysis),
ed834a27 71 fCurrFileName(0), fCheckMCCrossSection(kFALSE),
72 fhNEvents(0),
cd2e4ce6 73 fhXVertex(0), fhYVertex(0), fhZVertex(0),
e19ca838 74 fhXGoodVertex(0),fhYGoodVertex(0),fhZGoodVertex(0),
46f9f991 75 fhCentrality(0), fhEventPlaneAngle(0),
76 fh1Xsec(0), fh1Trials(0)
dd094cf8 77{
78 //ctor
79 DefineOutput(1, TList::Class());
80}
81
0de1814a 82//______________________________________________
dd094cf8 83AliAnalysisTaskCounter::AliAnalysisTaskCounter()
84 : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskCounter"),
cd2e4ce6 85 fAcceptFastCluster(kTRUE),
dd094cf8 86 fZVertexCut(10.),
87 fTrackMultEtaCut(0.8),
46f9f991 88 fAvgTrials(-1),
997b261e 89 fOutputContainer(0x0),
dd094cf8 90 fESDtrackCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
99e2921c 91 //fTriggerAnalysis (new AliTriggerAnalysis),
c457c558 92 fCurrFileName(0), fCheckMCCrossSection(kFALSE),
dd094cf8 93 fhNEvents(0),
cd2e4ce6 94 fhXVertex(0), fhYVertex(0), fhZVertex(0),
e19ca838 95 fhXGoodVertex(0),fhYGoodVertex(0),fhZGoodVertex(0),
46f9f991 96 fhCentrality(0), fhEventPlaneAngle(0),
97 fh1Xsec(0), fh1Trials(0)
dd094cf8 98{
99 // ctor
100 DefineOutput(1, TList::Class());
101}
102
103//__________________________________________________
104AliAnalysisTaskCounter::~AliAnalysisTaskCounter()
105{
106 //Destructor
0792da48 107
108 if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) return;
109
110 if(fOutputContainer)
111 {
dd094cf8 112 fOutputContainer->Delete() ;
113 delete fOutputContainer ;
114 }
115
116 if(fESDtrackCuts) delete fESDtrackCuts;
99e2921c 117 //if(fTriggerAnalysis) delete fTriggerAnalysis;
dd094cf8 118
119}
120
121
0de1814a 122//____________________________________________________
dd094cf8 123void AliAnalysisTaskCounter::UserCreateOutputObjects()
124{
125 // Init histograms
126
127 fOutputContainer = new TList();
128
e2e3a909 129 if(fCheckMCCrossSection)
130 {
131 fh1Xsec = new TH1F("hXsec","xsec from pyxsec.root",1,0,1);
132 fh1Xsec->GetXaxis()->SetBinLabel(1,"<#sigma>");
133 fOutputContainer->Add(fh1Xsec);
134
135 fh1Trials = new TH1F("hTrials","trials root file",1,0,1);
136 fh1Trials->GetXaxis()->SetBinLabel(1,"#sum{ntrials}");
137 fOutputContainer->Add(fh1Trials);
138 }
46f9f991 139
dd094cf8 140 fhZVertex = new TH1F("hZVertex", " Z vertex distribution" , 200 , -50 , 50 ) ;
141 fhZVertex->SetXTitle("v_{z} (cm)");
142 fOutputContainer->Add(fhZVertex);
143
144 fhZGoodVertex = new TH1F("hZGoodVertex", " Good Z vertex distribution" , 200 , -50 , 50 ) ;
145 fhZGoodVertex->SetXTitle("v_{z} (cm)");
146 fOutputContainer->Add(fhZGoodVertex);
147
148 fhXVertex = new TH1F("hXVertex", " X vertex distribution" , 200 , -2 , 2 ) ;
149 fhXVertex->SetXTitle("v_{x} (cm)");
150 fOutputContainer->Add(fhXVertex);
151
152 fhXGoodVertex = new TH1F("hXGoodVertex", " Good X vertex distribution" , 200 , -2 , 2 ) ;
153 fhXGoodVertex->SetXTitle("v_{x} (cm)");
154 fOutputContainer->Add(fhXGoodVertex);
155
156 fhYVertex = new TH1F("hYVertex", " Y vertex distribution" , 200 , -2 , 2 ) ;
157 fhYVertex->SetXTitle("v_{y} (cm)");
158 fOutputContainer->Add(fhYVertex);
159
160 fhYGoodVertex = new TH1F("hYGoodVertex", " Good Y vertex distribution" , 200 , -2 , 2 ) ;
161 fhYGoodVertex->SetXTitle("v_{y} (cm)");
162 fOutputContainer->Add(fhYGoodVertex);
163
e19ca838 164 fhCentrality = new TH1F("hCentrality","Number of events in centrality bin, |vz|<10 cm, method <V0M> ",100,0.,100.) ;
165 fhCentrality->SetXTitle("Centrality bin");
166 fOutputContainer->Add(fhCentrality) ;
dd094cf8 167
0792da48 168 fhEventPlaneAngle=new TH1F("hEventPlaneAngle","Number of events in event plane, |vz|<10 cm, method <V0> ",100,0.,TMath::Pi()) ;
169 fhEventPlaneAngle->SetXTitle("EP angle (rad)");
170 fOutputContainer->Add(fhEventPlaneAngle) ;
171
cd2e4ce6 172 fhNEvents = new TH1I("hNEvents", "Number of analyzed events", 21, 0, 21) ;
e2e3a909 173 //fhNEvents->SetXTitle("Selection");
dd094cf8 174 fhNEvents->SetYTitle("# events");
175 fhNEvents->GetXaxis()->SetBinLabel(1 ,"1 = PS");
176 fhNEvents->GetXaxis()->SetBinLabel(2 ,"2 = 1 & ESD");
177 fhNEvents->GetXaxis()->SetBinLabel(3 ,"3 = 2 & |Z|<10");
178 fhNEvents->GetXaxis()->SetBinLabel(4 ,"4 = 2 & |eta|<0.8");
179 fhNEvents->GetXaxis()->SetBinLabel(5 ,"5 = 3 & 4");
180 fhNEvents->GetXaxis()->SetBinLabel(6 ,"6 = 2 & V0AND");
181 fhNEvents->GetXaxis()->SetBinLabel(7 ,"7 = 3 & 6");
182 fhNEvents->GetXaxis()->SetBinLabel(8 ,"8 = 4 & 6");
183 fhNEvents->GetXaxis()->SetBinLabel(9 ,"9 = 5 & 6");
184 fhNEvents->GetXaxis()->SetBinLabel(10,"10 = 2 & not pileup");
185 fhNEvents->GetXaxis()->SetBinLabel(11,"11 = 2 & good vertex");
186 fhNEvents->GetXaxis()->SetBinLabel(12,"12 = 3 & 11");
187 fhNEvents->GetXaxis()->SetBinLabel(13,"13 = 4 & 11");
188 fhNEvents->GetXaxis()->SetBinLabel(14,"14 = 6 & 11");
189 fhNEvents->GetXaxis()->SetBinLabel(15,"15 = 9 & 11");
190 fhNEvents->GetXaxis()->SetBinLabel(16,"16 = 10 & 11");
191 fhNEvents->GetXaxis()->SetBinLabel(17,"17 = 6 & 10");
0b080dc9 192 fhNEvents->GetXaxis()->SetBinLabel(17,"17 = 1 & |Z|<50");
cd2e4ce6 193 fhNEvents->GetXaxis()->SetBinLabel(18,"18 = Reject EMCAL 1");
0b080dc9 194 fhNEvents->GetXaxis()->SetBinLabel(19,"19 = 18 & 2");
cd2e4ce6 195 fhNEvents->GetXaxis()->SetBinLabel(20,"20 = Reject EMCAL 2");
e2e3a909 196 fhNEvents->GetXaxis()->SetBinLabel(21,"21 = 20 & 2");
dd094cf8 197
198 fOutputContainer->Add(fhNEvents);
199
200 fOutputContainer->SetOwner(kTRUE);
201
202 PostData(1,fOutputContainer);
203
204}
205
46f9f991 206
0de1814a 207//_______________________________________________
dd094cf8 208void AliAnalysisTaskCounter::UserExec(Option_t *)
209{
210 // Main loop
211 // Called for each event
212
213 //printf("___ Event __ %d __\n",(Int_t)Entry());
214
46f9f991 215 Notify();
216
dd094cf8 217 fhNEvents->Fill(0.5);
218
219 AliVEvent * event = InputEvent();
dd094cf8 220 AliESDEvent * esdevent = dynamic_cast<AliESDEvent*> (event);
cd2e4ce6 221 AliAODEvent * aodevent = dynamic_cast<AliAODEvent*> (event);
222
5b96be07 223 // Init mag field for tracks in case of ESDs, needed, not clear why
224 if (!TGeoGlobalMagField::Instance()->GetField() && esdevent) esdevent->InitMagneticField();
225
997b261e 226 TString triggerclasses = event->GetFiredTriggerClasses();
cd2e4ce6 227
997b261e 228 //printf("Trigger class fired: %s \n",event->GetFiredTriggerClasses().Data());
229
0de1814a 230 if (triggerclasses.Contains("FAST") && !triggerclasses.Contains("ALL") && !fAcceptFastCluster)
231 {
cd2e4ce6 232 //printf("Do not count events from fast cluster, trigger name %s\n",triggerclasses.Data());
233 return;
234 }
dd094cf8 235
236 fhNEvents->Fill(1.5);
237
238 //Initialize bools
239 Bool_t bSelectVZ = kFALSE;
240 Bool_t bV0AND = kFALSE;
241 Bool_t bPileup = kFALSE;
242 Bool_t bGoodV = kFALSE;
243 Bool_t bSelectTrack = kFALSE;
244 Int_t trackMult = 0;
245
246 //---------------------------------
247 //Get the primary vertex, cut on Z
248 //---------------------------------
249 Double_t v[3];
250 event->GetPrimaryVertex()->GetXYZ(v) ;
251 fhXVertex->Fill(v[0]);
252 fhYVertex->Fill(v[1]);
253 fhZVertex->Fill(v[2]);
254
0de1814a 255 if(TMath::Abs(v[2]) < fZVertexCut)
256 {
dd094cf8 257 bSelectVZ=kTRUE;
258 fhNEvents->Fill(2.5);
259 }
260 //else printf("Vertex out %f \n",v[2]);
261
dd094cf8 262 //--------------------------------------------------
997b261e 263 //Count tracks, cut on number of tracks in eta < 0.8
dd094cf8 264 //--------------------------------------------------
997b261e 265 Int_t nTracks = event->GetNumberOfTracks() ;
266 for (Int_t itrack = 0; itrack < nTracks; itrack++)
267 {////////////// track loop
268 AliVTrack * track = (AliVTrack*)event->GetTrack(itrack) ; // retrieve track from esd
269
270 //ESDs
271 if(esdevent && !fESDtrackCuts->AcceptTrack((AliESDtrack*)track)) continue;
272
273 //AODs
274 if(aodevent && !((AliAODTrack*)track)->IsHybridGlobalConstrainedGlobal()) continue ;
275
276 //Do not count tracks out of acceptance cut
277 if(TMath::Abs(track->Eta())< fTrackMultEtaCut) trackMult++;
dd094cf8 278 }
279
280 //printf("AliAnalysisTaskCounter::UserExec() - Track Mult %d \n",trackMult);
281
282 //--------------------------------------------------
283 // At least one track
284 //--------------------------------------------------
d2655d46 285 if (trackMult > 0)
286 {
dd094cf8 287 bSelectTrack = kTRUE;
288 fhNEvents->Fill(3.5);
289 if(bSelectVZ) fhNEvents->Fill(4.5);
290 }
291
292 //---------------------------------
293 // V0AND
294 //---------------------------------
997b261e 295
99e2921c 296 //if(esdevent) bV0AND = fTriggerAnalysis->IsOfflineTriggerFired(esdevent, AliTriggerAnalysis::kV0AND);
297 AliVVZERO* v0 = fInputEvent->GetVZEROData();
298 bV0AND = ((v0->GetV0ADecision()==1) && (v0->GetV0CDecision()==1));
dd094cf8 299
300 if(bV0AND)
301 {
302 fhNEvents->Fill(5.5);
303 if (bSelectVZ) fhNEvents->Fill(6.5);
304 if (bSelectTrack) fhNEvents->Fill(7.5);
305 if (bSelectVZ && bSelectTrack) fhNEvents->Fill(8.5);
306 }
307
308 //---------------------------------
309 // Pileup
310 //---------------------------------
997b261e 311 bPileup = event->IsPileupFromSPD(3, 0.8, 3., 2., 5.); //Default values, if not it does not compile
312 //bPileup = event->IsPileupFromSPD();
0de1814a 313
314 if (!bPileup)
315 {
dd094cf8 316 fhNEvents->Fill(9.5);
317 if(bV0AND) fhNEvents->Fill(16.5);
318 }
319
320 //---------------------------------
321 // Good vertex
322 //---------------------------------
997b261e 323 bGoodV = CheckForPrimaryVertex();
d2655d46 324
325 //Remove events with vertex (0,0,0), bad vertex reconstruction
326 if(TMath::Abs(v[0]) < 1.e-6 &&
327 TMath::Abs(v[1]) < 1.e-6 &&
328 TMath::Abs(v[2]) < 1.e-6) bGoodV = kFALSE;
329
dd094cf8 330 if(bGoodV)
331 {
332 fhXGoodVertex->Fill(v[0]);
333 fhYGoodVertex->Fill(v[1]);
334 fhZGoodVertex->Fill(v[2]);
335
336 fhNEvents->Fill(10.5);
337 if(bSelectVZ) fhNEvents->Fill(11.5);
338 if(bSelectTrack) fhNEvents->Fill(12.5);
339 if(bV0AND) fhNEvents->Fill(13.5);
340 if(bSelectVZ && bSelectTrack && bV0AND)
341 fhNEvents->Fill(14.5);
342 if(!bPileup) fhNEvents->Fill(15.5);
e19ca838 343
0792da48 344 if(TMath::Abs(v[2]) < 10.)
e19ca838 345 {
0792da48 346 if(InputEvent()->GetCentrality())
347 fhCentrality->Fill(InputEvent()->GetCentrality()->GetCentralityPercentile("V0M"));
348
349 if(InputEvent()->GetEventplane())
350 {
351 Float_t ep = InputEvent()->GetEventplane()->GetEventplane("V0", InputEvent());
352
353 ep+=TMath::Pi()/2.; // put same range as for <Q> method, [0,pi]
354
355 fhEventPlaneAngle->Fill(ep);
356 }
e19ca838 357 }
358
dd094cf8 359 }
360
361 //printf("AliAnalysisTaskCounter::UserExec() : z vertex %d, good vertex %d, v0and %d, pile up %d, track mult %d\n ", bSelectVZ, bGoodV, bV0AND, bPileup, trackMult);
362
0b080dc9 363 // Events that could be rejected in EMCAL
cd2e4ce6 364 // LHC11a, SM4 and some SM3 events cut with this
365 Bool_t bEMCALRejected = kFALSE;
0b080dc9 366 for (Int_t i = 0; i < InputEvent()->GetNumberOfCaloClusters(); i++)
367 {
368 AliVCluster *clus = InputEvent()->GetCaloCluster(i);
369 if(clus->IsEMCAL()){
0de1814a 370 if ((clus->E() > 500 && clus->GetNCells() > 200 ) || clus->GetNCells() > 200)
371 {
cd2e4ce6 372
0b080dc9 373 //printf("Counter: Reject event with cluster: E %f, ncells %d\n",clus->E(),clus->GetNCells());
cd2e4ce6 374
0b080dc9 375 fhNEvents->Fill(17.5);
376 if(bSelectVZ) fhNEvents->Fill(18.5);
cd2e4ce6 377 bEMCALRejected = kTRUE;
0b080dc9 378 break;
379 }
0b080dc9 380 }
381 }
382
cd2e4ce6 383 //LHC11a, 3 last runs, cut with this
0de1814a 384 if(!bEMCALRejected)
385 {
cd2e4ce6 386 // Count number of cells in SM3 with energy larger than 0.1, cut on this number
75153e10 387 Int_t ncellsSM3 = 0;
388 Int_t ncellsSM4 = 0;
0de1814a 389 for(Int_t icell = 0; icell < event->GetEMCALCells()->GetNumberOfCells(); icell++)
390 {
75153e10 391 if(event->GetEMCALCells()->GetAmplitude(icell) > 0.1 && event->GetEMCALCells()->GetCellNumber(icell)/(24*48)==3) ncellsSM3++;
392 if(event->GetEMCALCells()->GetAmplitude(icell) > 0.1 && event->GetEMCALCells()->GetCellNumber(icell)/(24*48)==4) ncellsSM4++;
cd2e4ce6 393 }
394
395 Int_t ncellcut = 21;
396 if(triggerclasses.Contains("EMC")) ncellcut = 35;
397
0de1814a 398 if( ncellsSM3 >= ncellcut || ncellsSM4 >= 100 )
399 {
cd2e4ce6 400 //printf("Counter: reject event with ncells in SM3: ncells %d\n",ncells);
401
402 fhNEvents->Fill(19.5);
403 if(bSelectVZ) fhNEvents->Fill(20.5);
404 }
405
406 }
407
dd094cf8 408 PostData(1,fOutputContainer);
409
410}
411
46f9f991 412
0de1814a 413//____________________________________________________
414Bool_t AliAnalysisTaskCounter::CheckForPrimaryVertex()
415{
ad0a8527 416 //Check if the vertex was well reconstructed, copy of conversion group
dd094cf8 417
ad0a8527 418 AliESDEvent * esdevent = dynamic_cast<AliESDEvent*> (InputEvent());
419 AliAODEvent * aodevent = dynamic_cast<AliAODEvent*> (InputEvent());
dd094cf8 420
ad0a8527 421 if(esdevent)
0de1814a 422 {
ad0a8527 423 if(esdevent->GetPrimaryVertex()->GetNContributors() > 0)
424 {
425 return kTRUE;
426 }
427
428 if(esdevent->GetPrimaryVertex()->GetNContributors() < 1)
429 {
430 // SPD vertex
431 if(esdevent->GetPrimaryVertexSPD()->GetNContributors() > 0)
432 {
433 return kTRUE;
434
435 }
436 if(esdevent->GetPrimaryVertexSPD()->GetNContributors() < 1)
437 {
438 return kFALSE;
439 }
440 }
dd094cf8 441 }
ad0a8527 442 else if(aodevent)
443 {
444 if (aodevent->GetPrimaryVertex() != NULL)
0de1814a 445 {
ad0a8527 446 if(aodevent->GetPrimaryVertex()->GetNContributors() > 0)
447 {
448 return kTRUE;
449 }
dd094cf8 450 }
ad0a8527 451
452 if(aodevent->GetPrimaryVertexSPD() != NULL)
0de1814a 453 {
ad0a8527 454 if(aodevent->GetPrimaryVertexSPD()->GetNContributors() > 0)
455 {
456 return kTRUE;
457 }
458 else
459 {
460 AliWarning(Form("Number of contributors from bad vertex type:: %s",aodevent->GetPrimaryVertex()->GetName()));
461 return kFALSE;
462 }
dd094cf8 463 }
464 }
ad0a8527 465 else return kTRUE;
0de1814a 466
ad0a8527 467 return kFALSE;
468
dd094cf8 469}
470
471
dd094cf8 472//_____________________________________________________
473void AliAnalysisTaskCounter::FinishTaskOutput()
474{
475 // Put in the output some event summary histograms
476
477 AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
478 AliInputEventHandler *inputH = dynamic_cast<AliInputEventHandler*>(am->GetInputEventHandler());
479 if (!inputH) return;
480 TH2F *histStat = dynamic_cast<TH2F*>(inputH->GetStatistics());
481 TH2F *histBin0 = dynamic_cast<TH2F*>(inputH->GetStatistics("BIN0"));
482
483 if(histStat)
484 fOutputContainer->Add(histStat);
49b5c49b 485 else if(DebugLevel() > 1)
dd094cf8 486 printf("AliAnalysisTaskCounter::FinishTaskOutput() - Stat histogram not available check, \n if ESDs, that AliPhysicsSelection was on, \n if AODs, if EventStat_temp.root exists \n");
487
488 if(histBin0)
489 fOutputContainer->Add(histBin0);
490
491}
46f9f991 492
493
494//_____________________________________
495Bool_t AliAnalysisTaskCounter::Notify()
496{
497 //
498 // Implemented Notify() to read the cross sections
499 // and number of trials from pyxsec.root
500 //
501
ed834a27 502 if(!fCheckMCCrossSection) return kTRUE;
503
46f9f991 504 // Fetch the aod also from the input in,
505 // have todo it in notify
506
507 Float_t xsection = 0;
508 Float_t trials = 1;
509 fAvgTrials = -1;
510
511 TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
512 if(!tree) return kFALSE;
513
514 TFile *curfile = tree->GetCurrentFile();
515
516 if(!curfile) return kFALSE;
517
518 if(fCurrFileName == curfile->GetName()) return kFALSE;
519
520 fCurrFileName = TString(curfile->GetName());
521
522 if(!fh1Xsec||!fh1Trials)
523 {
524 Printf("%s%d No Histogram fh1Xsec",(char*)__FILE__,__LINE__);
525 return kFALSE;
526 }
527
e3f791f6 528 Bool_t ok = PythiaInfoFromFile(fCurrFileName,xsection,trials);
529
530 if(!ok) return kFALSE;
46f9f991 531
532 fh1Xsec->Fill("<#sigma>",xsection);
533
534 // construct a poor man average trials
535 Float_t nEntries = (Float_t)tree->GetTree()->GetEntries();
536
537 if(trials >= nEntries && nEntries > 0.) fAvgTrials = trials/nEntries;
538
539 fh1Trials->Fill("#sum{ntrials}",trials);
540
541 printf("AliAnalysisTaskCounter::Notify() - xs %f, trial %f, avg trials %f\n",xsection,trials, fAvgTrials);
542
543 if(fDebug) Printf("Reading File %s",fInputHandler->GetTree()->GetCurrentFile()->GetName());
544
545 return kTRUE;
546}
547
548//_____________________________________________________________________________________________________
549Bool_t AliAnalysisTaskCounter::PythiaInfoFromFile(TString file,Float_t & xsec,Float_t & trials)
550{
551 //
552 // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
553 // This is to called in Notify and should provide the path to the AOD/ESD file
ed834a27 554
46f9f991 555 xsec = 0;
556 trials = 1;
557
558 if(file.Contains("root_archive.zip#"))
559 {
560 Ssiz_t pos1 = file.Index("root_archive",12,0,TString::kExact);
561 Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
562 Ssiz_t pos2 = file.Index(".root",5,TString::kExact);
563 file.Replace(pos+1,pos2-pos1,"");
564 }
565 else
566 {
567 // not an archive take the basename....
568 file.ReplaceAll(gSystem->BaseName(file.Data()),"");
569 }
570
571 //Printf("%s",file.Data());
572
573 TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); // problem that we cannot really test the existance of a file in a archive so we have to lvie with open error message from root
574 if(!fxsec)
575 {
576 // next trial fetch the histgram file
577 fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
578 if(!fxsec)
579 {
580 // not a severe condition but inciate that we have no information
581 return kFALSE;
582 }
583 else
584 {
585 // find the tlist we want to be independtent of the name so use the Tkey
586 TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0);
587 if(!key)
588 {
589 fxsec->Close();
590 return kFALSE;
591 }
592
593 TList *list = dynamic_cast<TList*>(key->ReadObj());
594 if(!list)
595 {
596 fxsec->Close();
597 return kFALSE;
598 }
599
600 xsec = ((TProfile*)list->FindObject("h1Xsec")) ->GetBinContent(1);
601 trials = ((TH1F*) list->FindObject("h1Trials"))->GetBinContent(1);
602 fxsec->Close();
603 }
604 } // no tree pyxsec.root
605 else
606 {
607 TTree *xtree = (TTree*)fxsec->Get("Xsection");
608 if(!xtree)
609 {
610 fxsec->Close();
611 return kFALSE;
612 }
613
614 UInt_t ntrials = 0;
615 Double_t xsection = 0;
616 xtree->SetBranchAddress("xsection",&xsection);
617 xtree->SetBranchAddress("ntrials",&ntrials);
618 xtree->GetEntry(0);
619 trials = ntrials;
620 xsec = xsection;
621 fxsec->Close();
622 }
623
624 return kTRUE;
72704df1 625}
626