]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnVATProcessInfo.cxx
method added to add a run list (A.Pulvirenti)
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnVATProcessInfo.cxx
1 //
2 // *** Class AliRsnVATProcessInfo ***
3 //
4 // Virtual class which makes computations at the event level,
5 // in order to return a list of histograms useful to have a look
6 // of the characteristics of used events.
7 // If can be inherited and customized for the needs of the analysis.
8 //
9 // authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
10 //          M. Vala (email: martin.vala@cern.ch)
11 //
12
13 #include <TList.h>
14 #include <TH1.h>
15
16 #include "AliLog.h"
17
18 #include "AliRsnFunction.h"
19 #include "AliRsnVATProcessInfo.h"
20
21 ClassImp(AliRsnVATProcessInfo)
22
23 //______________________________________________________________________________
24 AliRsnVATProcessInfo::AliRsnVATProcessInfo(const char *name) :
25   TNamed(name,name),
26   fHistUsedEvents(0x0),
27   fEventUsed(kFALSE),
28   fEventFunctions("AliRsnFunction", 0),
29   fPrintInfoNumber(1000)
30 {
31 //
32 // Constructor.
33 // Does nothing more than initialization of data members.
34 //
35
36   AliDebug(AliLog::kDebug+2, "Entering");
37   AliDebug(AliLog::kDebug+2, "Exiting");
38 }
39
40 //______________________________________________________________________________
41 AliRsnVATProcessInfo::AliRsnVATProcessInfo(const AliRsnVATProcessInfo& copy) :
42   TNamed(copy),
43   fHistUsedEvents(0x0),
44   fEventUsed(copy.fEventUsed),
45   fEventFunctions(copy.fEventFunctions),
46   fPrintInfoNumber(copy.fPrintInfoNumber)
47 {
48 //
49 // Copy constructor.
50 // Clones the histogram and copies the values of other data members
51 //
52
53   AliDebug(AliLog::kDebug+2, "Entering");
54   
55   fHistUsedEvents  = (TH1I*)copy.fHistUsedEvents->Clone();
56   
57   AliDebug(AliLog::kDebug+2, "Exiting");
58 }
59
60 //______________________________________________________________________________
61 AliRsnVATProcessInfo& AliRsnVATProcessInfo::operator= 
62 (const AliRsnVATProcessInfo& copy)
63 {
64 //
65 // Assignment operator.
66 // Clones the histogram and copies the values of other data members.
67 //
68
69   AliDebug(AliLog::kDebug+2, "Entering");
70
71   fHistUsedEvents  = (TH1I*)copy.fHistUsedEvents->Clone();
72   fEventUsed       = copy.fEventUsed;
73   fPrintInfoNumber = copy.fPrintInfoNumber;
74   fEventFunctions  = copy.fEventFunctions;
75   
76   AliDebug(AliLog::kDebug+2, "Exiting");
77   
78   return (*this);
79 }
80
81 //______________________________________________________________________________
82 AliRsnVATProcessInfo::~AliRsnVATProcessInfo()
83 {
84 //
85 // Destructor.
86 // Does nothing, since the histogram it creates is usually owned
87 // by another object (TList output of AnalysisTask's), but sets
88 // the data member pointers to NULL.
89 //
90
91   AliDebug(AliLog::kDebug+2, "Entering");
92   
93   fHistUsedEvents  = 0x0;
94   fEventUsed       = 0;
95   fPrintInfoNumber = 0;
96   
97   AliDebug(AliLog::kDebug+2, "Exiting");
98 }
99
100 //______________________________________________________________________________
101 void AliRsnVATProcessInfo::GenerateInfoList(TList *list)
102 {
103 //
104 // Allocate in memory the histograms created in this class and store them
105 // inside the TList object passed as argument, which usually belongs to 
106 // an AnalysisTask object, and represents one of its outputs.
107 // If the histogram was already initialized, it is deleted and recreated.
108 //
109
110   AliDebug(AliLog::kDebug+2, "Entering");
111
112   // delete existing allocation of stored objects
113   if (fHistUsedEvents) delete fHistUsedEvents;
114   
115   // create stored objects
116   fHistUsedEvents = new TH1I(GetEventHistogramName(), "Skipped/used events", 3, 0, 3);
117
118   // ad objects to list
119   list->Add(fHistUsedEvents);
120   
121   // add all other functions
122   Int_t  i;
123   TString hName("");
124   AliRsnFunction *fcn = 0;
125   for (i = 0; i < fEventFunctions.GetEntries(); i++)
126   {
127     fcn = (AliRsnFunction*)fEventFunctions.At(i);
128     hName += GetName();
129     hName += '_';
130     hName += fcn->GetName();
131     if (fcn->IsUsingTH1()) list->Add(fcn->CreateHistogram(hName.Data(), ""));
132     else list->Add(fcn->CreateHistogramSparse(hName.Data(), ""));
133   }
134
135   AliDebug(AliLog::kDebug+2, "Exiting");
136 }
137
138 //______________________________________________________________________________
139 void AliRsnVATProcessInfo::FillInfo()
140 {
141 //
142 // This method defines how the information histograms must be filled.
143 // The structure of this class is auto-consistent, but in case of inheritance
144 // this method must be modified accordingly.
145 // Current implementation uses the 'fEventUsed' flag to choose if the event
146 // has been used or not, and increments the corresponding bin in the related
147 // histogram (bin '0' = skipped, bin '1' = used).
148 //
149
150   fHistUsedEvents->Fill(fEventUsed);
151   
152   if (!fEventUsed) return;
153   
154   Int_t i;
155   AliRsnFunction *fcn = 0;
156   for (i = 0; i < fEventFunctions.GetEntries(); i++)
157   {
158     fcn = (AliRsnFunction*)fEventFunctions.At(i);
159     fcn->Fill();
160   }
161 }
162
163 //______________________________________________________________________________
164 void AliRsnVATProcessInfo::PrintInfo(const Long64_t &num)
165 {
166 //
167 // This method is used in some cases
168 // to inform about number of events processed
169 //
170
171   if ((num+1) % fPrintInfoNumber == 0) AliInfo(Form("Events processed %lld", num+1));
172 }
173
174 //______________________________________________________________________________
175 Long64_t AliRsnVATProcessInfo::GetNumerOfEventsProcessed()
176 {
177 //
178 // returns number of events from histogram
179 //
180
181   if (fHistUsedEvents) return fHistUsedEvents->Integral();
182   return 0;
183 }
184
185 //_____________________________________________________________________________
186 void AliRsnVATProcessInfo::AddEventFunction(AliRsnFunction * fcn)
187 {
188 //
189 // Adds a new computing function
190 //
191
192   AliDebug(AliLog::kDebug+2,"<-");
193   
194   fEventFunctions.Print();
195   Int_t size = fEventFunctions.GetEntries();
196   new(fEventFunctions[size]) AliRsnFunction(*fcn);
197   
198   AliDebug(AliLog::kDebug+2,"->");
199 }