]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliRunAnalysis.cxx
Streamline the different messages output by the code using the AliLog, Remove warning...
[u/mrichter/AliRoot.git] / ANALYSIS / AliRunAnalysis.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 #include "AliRunAnalysis.h"
19 #include "AliLog.h"
20
21 //________________________________
22 ///////////////////////////////////////////////////////////
23 //
24 // class AliRunAnalysis
25 //
26 //
27 //
28 // Piotr.Skowronski@cern.ch
29 //
30 ///////////////////////////////////////////////////////////
31
32 #include <stdlib.h>
33
34 #include <TString.h>
35 #include <TObjString.h>
36 #include <TClass.h>
37 #include <TFile.h>
38 #include <TKey.h>
39 #include <TObjArray.h>
40
41 #include <AliRun.h>
42 #include <AliRunLoader.h>
43 #include <AliStack.h>
44 #include <AliESDtrack.h>
45 #include <AliESD.h>
46
47
48 #include "AliEventCut.h"
49 #include "AliReader.h"
50 #include "AliVAODParticle.h"
51
52
53 ClassImp(AliRunAnalysis)
54 AliRunAnalysis::AliRunAnalysis():
55  TTask("RunAnalysis","Alice Analysis Manager"),
56  fAnalysies(10),
57  fReader(0x0),
58  fEventCut(0x0),
59  fCutOnSim(kFALSE),
60  fCutOnRec(kTRUE)
61 {
62   //ctor
63 }
64 /*********************************************************/
65
66 AliRunAnalysis::~AliRunAnalysis()
67 {
68   //dtor
69   delete fReader;
70   delete fEventCut;
71 }
72 /*********************************************************/
73
74 Int_t AliRunAnalysis::Run()
75 {
76  //makes analysis
77
78  if (fReader == 0x0)
79   {
80     AliError("Reader is not set");
81     return 1;
82   }
83  TDirectory* cwd = gDirectory; 
84  Int_t nanal = fAnalysies.GetEntries();
85  AliDebug(1,Form("There are %d analyses",nanal));
86  /******************************/ 
87  /*  Init Event                */ 
88  /******************************/ 
89  AliDebug(1,"Intializing analyses...");
90  for (Int_t an = 0; an < nanal; an++)
91   {   
92       AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
93       AliDebug(1,Form("Intializing analysis %d,address=%#x, name=%s", 
94                       an, analysis, analysis->GetName()));
95       analysis->Init();
96       AliDebug(1,Form("Init done for analysis %d",an));
97   }
98  AliDebug(1,"Intializing analyses... Done.");
99   
100  while (fReader->Next() == kFALSE)
101   {
102      AliAOD* eventrec = fReader->GetEventRec();
103      AliAOD* eventsim = fReader->GetEventSim();
104
105      /******************************/ 
106      /*  Event Cut                 */ 
107      /******************************/ 
108      if ( Rejected(eventrec,eventsim) )
109       {
110         AliDebug(1,"Event rejected by Event Cut");
111         continue; //Did not pass the 
112       }
113       
114      /******************************/ 
115      /*  Process Event             */ 
116      /******************************/ 
117      AliDebug(1,Form("There is %d analyses",fAnalysies.GetEntries()));
118      
119      for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
120       {
121           AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
122           analysis->ProcessEvent(eventrec,eventsim);
123       }
124     
125   }//end of loop over events
126
127  /******************************/ 
128  /*  Finish Event              */ 
129  /******************************/ 
130  AliDebug(1,Form("Finishing analyses...\n There are %d anlyses",fAnalysies.GetEntries()));
131  if (cwd) cwd->cd();
132  for (Int_t an = 0; an < fAnalysies.GetEntries(); an++)
133   {
134       AliAnalysis* analysis = (AliAnalysis*)fAnalysies.At(an);
135       AliDebug(1,Form("Calling Finish for analysis %d address %#x name=%s", 
136                       an, analysis,analysis->GetName()));
137       analysis->Finish();
138       AliDebug(1,Form("Called Finish for analysis %d",an));
139   }
140  AliDebug(1,"Finishing done");
141
142  return 0;   
143 }
144 /*********************************************************/
145
146 void  AliRunAnalysis::Add(AliAnalysis* a)
147 {
148   //adds a to the list of analysis
149   fAnalysies.Add(a);
150 }
151 /*********************************************************/
152
153 void AliRunAnalysis::SetEventCut(AliEventCut* evcut)
154 {
155 //Sets event -  makes a private copy
156   delete fEventCut;
157   if (evcut) fEventCut = (AliEventCut*)evcut->Clone();
158   else fEventCut = 0x0;
159 }
160
161 /*********************************************************/
162
163 Bool_t AliRunAnalysis::Rejected(AliAOD* recevent, AliAOD* simevent)
164 {
165   //checks the event cut
166   if (fEventCut == 0x0) return kFALSE;
167   
168   if (fCutOnRec)
169     if (fEventCut->Rejected(recevent)) return kTRUE;
170     
171   if (fCutOnSim)
172     if (fEventCut->Rejected(simevent)) return kTRUE;
173   
174   return kFALSE;
175 }