]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliRunAnalysis.cxx
c43763dd406b27c6046b9791216e6a627f33bb3d
[u/mrichter/AliRoot.git] / ANALYSIS / AliRunAnalysis.cxx
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
28
29 #include "AliEventCut.h"
30 #include "AliReader.h"
31 #include "AliVAODParticle.h"
32
33
34 ClassImp(AliRunAnalysis)
35 AliRunAnalysis::AliRunAnalysis():
36  TTask("RunAnalysis","Alice Analysis Manager"),
37  fAnalysies(10),
38  fReader(0x0),
39  fEventCut(0x0),
40  fCutOnSim(kFALSE),
41  fCutOnRec(kTRUE)
42 {
43   //ctor
44 }
45 /*********************************************************/
46
47 AliRunAnalysis::~AliRunAnalysis()
48 {
49   //dtor
50   delete fReader;
51   delete fEventCut;
52 }
53 /*********************************************************/
54
55 Int_t AliRunAnalysis::Run()
56 {
57  //makes analysis
58
59  if (fReader == 0x0)
60   {
61     Error("Run","Reader is not set");
62     return 1;
63   }
64  TDirectory* cwd = gDirectory; 
65  Int_t nanal = fAnalysies.GetEntries();
66  if (AliVAODParticle::GetDebug()) Info("Run","There is %d analysies",nanal);
67  /******************************/ 
68  /*  Init Event                */ 
69  /******************************/ 
70  if (AliVAODParticle::GetDebug()) Info("Run","Intializing analyses...");
71  for (Int_t an = 0; an < nanal; an++)
72   {   
73       if (AliVAODParticle::GetDebug()) Info("Run","Intializing analysis %d", an);
74       AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
75       if (AliVAODParticle::GetDebug()) 
76        { 
77          Info("Run","Intializing analysis %d address %#x", an, analysis);
78          Info("Run","Intializing analysis %d name %d", an, analysis->GetName());
79          Info("Run","Intializing analysis %d: Calling Init...", an);
80        } 
81       analysis->Init();
82       if (AliVAODParticle::GetDebug()) Info("Run","Intializing analysis %d: Calling Init... Done");
83   }
84  if (AliVAODParticle::GetDebug()) Info("Run","Intializing analyses... Done.");
85   
86  while (fReader->Next() == kFALSE)
87   {
88      AliAOD* eventrec = fReader->GetEventRec();
89      AliAOD* eventsim = fReader->GetEventSim();
90
91      /******************************/ 
92      /*  Event Cut                 */ 
93      /******************************/ 
94      if ( Rejected(eventrec,eventsim) )
95       {
96         if (AliVAODParticle::GetDebug()) Info("Run","Event rejected by Event Cut");
97         continue; //Did not pass the 
98       }
99       
100      /******************************/ 
101      /*  Process Event             */ 
102      /******************************/ 
103      if (AliVAODParticle::GetDebug())  Info("Run","There is %d analyses",fAnalysies.GetEntries());
104      
105      for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
106       {
107           AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
108           analysis->ProcessEvent(eventrec,eventsim);
109       }
110     
111   }//end of loop over events
112
113  /******************************/ 
114  /*  Finish Event              */ 
115  /******************************/ 
116  if (AliVAODParticle::GetDebug()) Info("Run","Finishing analyses... ");
117  if (AliVAODParticle::GetDebug()) Info("Run","There is %d anlyses",fAnalysies.GetEntries());
118  if (cwd) cwd->cd();
119  for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
120   {
121       if (AliVAODParticle::GetDebug()) Info("Run","Finishing analysis %d", an);
122       AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
123       if (AliVAODParticle::GetDebug()) 
124        { 
125          Info("Run","Finishing analysis %d address %#x", an, analysis);
126          Info("Run","Finishing analysis %d name %d", an, analysis->GetName());
127          Info("Run","Finishing analysis %d: Calling Finish...",an);
128        } 
129       analysis->Finish();
130       if (AliVAODParticle::GetDebug()) Info("Run","Finishing analysis %d: Calling Finish... Done");
131   }
132  if (AliVAODParticle::GetDebug()) Info("Run","Finishing done");
133
134  return 0;   
135 }
136 /*********************************************************/
137
138 void  AliRunAnalysis::Add(AliAnalysis* a)
139 {
140   //adds a to the list of analysis
141   fAnalysies.Add(a);
142 }
143 /*********************************************************/
144
145 void AliRunAnalysis::SetEventCut(AliEventCut* evcut)
146 {
147 //Sets event -  makes a private copy
148   delete fEventCut;
149   if (evcut) fEventCut = (AliEventCut*)evcut->Clone();
150   else fEventCut = 0x0;
151 }
152
153 /*********************************************************/
154
155 Bool_t AliRunAnalysis::Rejected(AliAOD* recevent, AliAOD* simevent)
156 {
157   //checks the event cut
158   if (fEventCut == 0x0) return kFALSE;
159   
160   if (fCutOnRec)
161     if (fEventCut->Rejected(recevent)) return kTRUE;
162     
163   if (fCutOnSim)
164     if (fEventCut->Rejected(simevent)) return kTRUE;
165   
166   return kFALSE;
167 }