]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnVATProcessInfo.cxx
Another bugfix in efficiency computation task, plus some changes in macros
[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 "AliRsnEvent.h"
19 #include "AliRsnFunction.h"
20 #include "AliRsnVATProcessInfo.h"
21
22 ClassImp(AliRsnVATProcessInfo)
23
24 //______________________________________________________________________________
25 AliRsnVATProcessInfo::AliRsnVATProcessInfo(const char *name) :
26    TNamed(name, name),
27    fHistUsedEvents(0x0),
28    fEventUsed(kFALSE),
29    fEventFunctions("AliRsnFunction", 0),
30    fPrintInfoNumber(1000)
31 {
32 //
33 // Constructor.
34 // Does nothing more than initialization of data members.
35 //
36
37    AliDebug(AliLog::kDebug + 2, "Entering");
38    AliDebug(AliLog::kDebug + 2, "Exiting");
39 }
40
41 //______________________________________________________________________________
42 AliRsnVATProcessInfo::AliRsnVATProcessInfo(const AliRsnVATProcessInfo& copy) :
43    TNamed(copy),
44    fHistUsedEvents(0x0),
45    fEventUsed(copy.fEventUsed),
46    fEventFunctions(copy.fEventFunctions),
47    fPrintInfoNumber(copy.fPrintInfoNumber)
48 {
49 //
50 // Copy constructor.
51 // Clones the histogram and copies the values of other data members
52 //
53
54    AliDebug(AliLog::kDebug + 2, "Entering");
55
56    fHistUsedEvents  = (TH1I*)copy.fHistUsedEvents->Clone();
57
58    AliDebug(AliLog::kDebug + 2, "Exiting");
59 }
60
61 //______________________________________________________________________________
62 AliRsnVATProcessInfo& AliRsnVATProcessInfo::operator=
63 (const AliRsnVATProcessInfo& copy)
64 {
65 //
66 // Assignment operator.
67 // Clones the histogram and copies the values of other data members.
68 //
69
70    AliDebug(AliLog::kDebug + 2, "Entering");
71
72    fHistUsedEvents  = (TH1I*)copy.fHistUsedEvents->Clone();
73    fEventUsed       = copy.fEventUsed;
74    fPrintInfoNumber = copy.fPrintInfoNumber;
75    fEventFunctions  = copy.fEventFunctions;
76
77    AliDebug(AliLog::kDebug + 2, "Exiting");
78
79    return (*this);
80 }
81
82 //______________________________________________________________________________
83 AliRsnVATProcessInfo::~AliRsnVATProcessInfo()
84 {
85 //
86 // Destructor.
87 // Does nothing, since the histogram it creates is usually owned
88 // by another object (TList output of AnalysisTask's), but sets
89 // the data member pointers to NULL.
90 //
91
92    AliDebug(AliLog::kDebug + 2, "Entering");
93
94    fHistUsedEvents  = 0x0;
95    fEventUsed       = 0;
96    fPrintInfoNumber = 0;
97
98    AliDebug(AliLog::kDebug + 2, "Exiting");
99 }
100
101 //______________________________________________________________________________
102 void AliRsnVATProcessInfo::GenerateInfoList(TList *list)
103 {
104 //
105 // Allocate in memory the histograms created in this class and store them
106 // inside the TList object passed as argument, which usually belongs to
107 // an AnalysisTask object, and represents one of its outputs.
108 // If the histogram was already initialized, it is deleted and recreated.
109 //
110
111    AliDebug(AliLog::kDebug + 2, "Entering");
112
113    // delete existing allocation of stored objects
114    if (fHistUsedEvents) delete fHistUsedEvents;
115
116    // create stored objects
117    fHistUsedEvents = new TH1I(GetEventHistogramName(), "Skipped/used events", 2, 0, 2);
118
119    // ad objects to list
120    list->Add(fHistUsedEvents);
121
122    // add all other functions
123    Int_t  i;
124    TString hName("");
125    AliRsnFunction *fcn = 0;
126    for (i = 0; i < fEventFunctions.GetEntries(); i++) {
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(AliRsnEvent *event)
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       fcn = (AliRsnFunction*)fEventFunctions.At(i);
158       fcn->Fill(event);
159    }
160 }
161
162 //______________________________________________________________________________
163 void AliRsnVATProcessInfo::PrintInfo(const Long64_t &num)
164 {
165 //
166 // This method is used in some cases
167 // to inform about number of events processed
168 //
169
170    if ((num + 1) % fPrintInfoNumber == 0) AliInfo(Form("Events processed %lld", num + 1));
171 }
172
173 //______________________________________________________________________________
174 Long64_t AliRsnVATProcessInfo::GetNumerOfEventsProcessed()
175 {
176 //
177 // returns number of events from histogram
178 //
179
180    if (fHistUsedEvents) return (Long64_t)fHistUsedEvents->GetEntries();
181    return 0;
182 }
183
184 //_____________________________________________________________________________
185 void AliRsnVATProcessInfo::AddEventFunction(AliRsnFunction * fcn)
186 {
187 //
188 // Adds a new computing function
189 //
190
191    AliDebug(AliLog::kDebug + 2, "<-");
192
193    fEventFunctions.Print();
194    Int_t size = fEventFunctions.GetEntries();
195    new(fEventFunctions[size]) AliRsnFunction(*fcn);
196
197    AliDebug(AliLog::kDebug + 2, "->");
198 }