Additional safety check introduced
[u/mrichter/AliRoot.git] / ANALYSIS / AliRunAnalysis.cxx
CommitLineData
b26900d0 1#include "AliRunAnalysis.h"
2//________________________________
3///////////////////////////////////////////////////////////
4//
5// class AliRunAnalysis
6//
7//
8//
9// Piotr.Skowronski@cern.ch
10//
11///////////////////////////////////////////////////////////
12
13#include <stdlib.h>
14
15#include <TString.h>
16#include <TObjString.h>
17#include <TClass.h>
18#include <TFile.h>
19#include <TKey.h>
20#include <TObjArray.h>
21
22#include <AliRun.h>
23#include <AliRunLoader.h>
24#include <AliStack.h>
25#include <AliESDtrack.h>
26#include <AliESD.h>
27
9e5e23b5 28
b26900d0 29#include "AliEventCut.h"
a5556ea5 30#include "AliReader.h"
afa8b37b 31#include "AliVAODParticle.h"
b26900d0 32
b26900d0 33
34ClassImp(AliRunAnalysis)
35AliRunAnalysis::AliRunAnalysis():
91757255 36 TTask("RunAnalysis","Alice Analysis Manager") ,
a5556ea5 37 fReader(0x0),
b26900d0 38 fEventCut(0x0),
a5556ea5 39 fCutOnSim(kFALSE),
40 fCutOnRec(kTRUE)
b26900d0 41{
42 //ctor
43}
44/*********************************************************/
45
46AliRunAnalysis::~AliRunAnalysis()
47{
48 //dtor
a5556ea5 49 delete fReader;
b26900d0 50 delete fEventCut;
51}
52/*********************************************************/
53
54Int_t AliRunAnalysis::Run()
55{
56 //makes analysis
b26900d0 57
a5556ea5 58 if (fReader == 0x0)
59 {
60 Error("Run","Reader is not set");
61 return 1;
62 }
9e5e23b5 63 TDirectory* cwd = gDirectory;
b26900d0 64 /******************************/
65 /* Init Event */
66 /******************************/
a5556ea5 67 for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
b26900d0 68 {
a5556ea5 69 AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
b26900d0 70 analysis->Init();
71 }
a5556ea5 72
73 while (fReader->Next() == kFALSE)
b26900d0 74 {
a5556ea5 75 AliAOD* eventsim = fReader->GetEventSim();
76 AliAOD* eventrec = fReader->GetEventRec();
b26900d0 77
b26900d0 78 /******************************/
79 /* Event Cut */
80 /******************************/
cea0a066 81 if ( Rejected(eventrec,eventsim) )
b26900d0 82 {
afa8b37b 83 if (AliVAODParticle::GetDebug()) Info("Run","Event rejected by Event Cut");
a5556ea5 84 continue; //Did not pass the
b26900d0 85 }
86 /******************************/
87 /* Process Event */
88 /******************************/
a5556ea5 89 for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
b26900d0 90 {
a5556ea5 91 AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
afa8b37b 92 analysis->ProcessEvent(eventrec,eventsim);
b26900d0 93 }
b26900d0 94
a5556ea5 95 }//end of loop over events
b26900d0 96
97 /******************************/
98 /* Finish Event */
99 /******************************/
9e5e23b5 100 if (cwd) cwd->cd();
a5556ea5 101 for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
b26900d0 102 {
a5556ea5 103 AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
104 analysis->Finish();
b26900d0 105 }
106
107 return 0;
108}
109/*********************************************************/
110
a5556ea5 111void AliRunAnalysis::Add(AliAnalysis* a)
b26900d0 112{
a5556ea5 113 //adds a to the list of analysis
114 fAnalysies.Add(a);
b26900d0 115}
116/*********************************************************/
117
36715d31 118void AliRunAnalysis::SetEventCut(AliEventCut* evcut)
119{
120//Sets event - makes a private copy
121 delete fEventCut;
122 if (evcut) fEventCut = (AliEventCut*)evcut->Clone();
123 else fEventCut = 0x0;
124}
125
126/*********************************************************/
127
cea0a066 128Bool_t AliRunAnalysis::Rejected(AliAOD* recevent, AliAOD* simevent)
b26900d0 129{
a5556ea5 130 //checks the event cut
131 if (fEventCut == 0x0) return kFALSE;
132
133 if (fCutOnRec)
cea0a066 134 if (fEventCut->Rejected(recevent)) return kTRUE;
a5556ea5 135
136 if (fCutOnSim)
cea0a066 137 if (fEventCut->Rejected(simevent)) return kTRUE;
a5556ea5 138
139 return kFALSE;
b26900d0 140}