]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnSimpleFunction.cxx
EMCAL Space Frame now included in geometry
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnSimpleFunction.cxx
CommitLineData
2a445445 1//
2// Class AliRsnSimpleFcn
3//
4// This class defines a base classe to implement a typical computation
5// which uses the internal RSN package event format (AliRsnEvent).
6// It contains some default flags which turn out to be useful:
7// - a flag to select only the "true" pairs (tracks from same resonance)
8// - a flag to know if the computation is done over two events (mixing)
9//
10// Any kind of analysis object should be implemented as inheriting from this
11// because the AliRsnAnalyzer which executes the analysis will accept a collection
12// of such objects, in order to have a unique format of processing method
13//
14// The user who implements a kind of computation type should inherit from
15// this class and override the virtual functions defined in it, which
16// initialize the final output histogram and define how to process data.
17//
18//
19// author: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
20//
21
22#include <Riostream.h>
23
24#include <TH1.h>
25#include <TH2.h>
26#include <TString.h>
27
28#include "AliLog.h"
29
30#include "AliRsnMCInfo.h"
31#include "AliRsnDaughter.h"
32#include "AliRsnEvent.h"
33#include "AliRsnCut.h"
34
35#include "AliRsnSimpleFunction.h"
36
37ClassImp(AliRsnSimpleFunction)
38
39//________________________________________________________________________________________
40AliRsnSimpleFunction::AliRsnSimpleFunction
41(const char *name, AliRsnPairDef *pd, AliRsnHistoDef *hd,
42 AliRsnCutMgr *cuts, Option_t *option) :
43 TNamed(name, ""),
44 fTrueFlag(kFALSE),
45 fMixFlag(kFALSE),
46 fPair(),
47 fPairDef(pd),
48 fHistoDef(hd),
49 fCuts(cuts),
50 fHisto1D(0x0),
51 fHisto2D(0x0)
52{
53//
54// Constructor.
55// The histogram data member cannot be passed externally,
56// its initialization MUST be defined inside the Init() method,
57// which must be overridden in any derivate implementation.
58// Last argument (option) allows to set in a user-friedly way the flags:
59// - TRUE (for true pairs)
60// - MIX (for mixing pairs)
61//
62
63 TString opt(option);
64 opt.ToUpper();
65 fTrueFlag = opt.Contains("TRUE");
66 fMixFlag = opt.Contains("MIX");
67}
68//________________________________________________________________________________________
69AliRsnSimpleFunction::AliRsnSimpleFunction(const AliRsnSimpleFunction &copy) :
70 TNamed(copy),
71 fTrueFlag(copy.fTrueFlag),
72 fMixFlag(copy.fMixFlag),
73 fPair(),
74 fPairDef(copy.fPairDef),
75 fHistoDef(copy.fHistoDef),
76 fCuts(copy.fCuts),
77 fHisto1D(0x0),
78 fHisto2D(0x0)
79{
80//
81// Copy constructor.
82// Pointer data members are not cloned.
83// The histogram is not copied, because it is always initialized
84// by the Init() method.
85//
86}
87//________________________________________________________________________________________
88const AliRsnSimpleFunction& AliRsnSimpleFunction::operator=
89(const AliRsnSimpleFunction &copy)
90{
91//
92// Assignment operator.
93// Behaves like copy constructor.
94// Also in this case, the histogram is not copied, and,
95// if it was present, it is destroyed and will need to be recreated.
96//
97
98 Clear();
99 SetName(copy.GetName());
100
101 fTrueFlag = copy.fTrueFlag;
102 fMixFlag = copy.fMixFlag;
103
104 fPairDef = copy.fPairDef;
105 fHistoDef = copy.fHistoDef;
106 fCuts = copy.fCuts;
107
108 return (*this);
109}
110//________________________________________________________________________________________
111void AliRsnSimpleFunction::Clear(Option_t* /*option*/)
112{
113//
114// Clear arrays and histogram.
115// For the sake of security, all pointers are also set explicitly to NULL.
116//
117 if (fHisto1D) delete fHisto1D;
118 fHisto1D = 0x0;
119 if (fHisto2D) delete fHisto2D;
120 fHisto2D = 0x0;
121}
122
123//________________________________________________________________________________________
124Bool_t AliRsnSimpleFunction::Init()
125{
126//
127// Initialization function.
128// By default, it initializes the owned histogram using the method
129// from AliRsnHistoDef class, giving the same name and title of this.
130// A user can override this behaviour, if necessary.
131// Before creating, the HistoDef is checked for proper initialization.
132//
133
134 Clear();
135
136 Char_t name[200];
137 sprintf(name, "h_%s", GetName());
138
139 switch (fHistoDef->GetNDimensions()) {
140 case 1:
141 fHisto1D = (TH1D*)fHistoDef->Create1DHistogram(name, "");
142 return kTRUE;
143 case 2:
144 fHisto2D = (TH2D*)fHistoDef->Create1DHistogram(name, "");
145 return kTRUE;
146 default:
147 AliError("Number of dimensions not properly set.");
148 return kFALSE;
149 }
150}
151
152//________________________________________________________________________________________
153Bool_t AliRsnSimpleFunction::ProcessOne(AliRsnEvent* /*event*/)
154{
155//
156// Process a single event according to the purposes of the derived class.
157// Here the user must put the code which defines how the internal histogram is filled.
158// The boolean return value allows to catch a failure in execution.
159//
160
161 AliWarning("This method must be defined in the derived class");
162 return kFALSE;
163}
164
165//________________________________________________________________________________________
166Bool_t AliRsnSimpleFunction::ProcessTwo(AliRsnEvent* /*event1*/, AliRsnEvent* /*event2*/)
167{
168//
169// Process two events according to relations between them.
170// This method must be defined whenever the derived object is used in event mixing.
171// The boolean return value allows to catch a failure in execution.
172//
173
174 AliWarning("This method must be defined in the derived class");
175 return kFALSE;
176}
177
178//________________________________________________________________________________________
179Bool_t AliRsnSimpleFunction::CutPass(AliRsnDaughter *d)
180{
181//
182// Check if the AliRsnDaughter argument pass its cuts.
183// If the cut data member is not initialized for it, returns kTRUE.
184//
185 if (!fCuts) return kTRUE;
186 else return fCuts->IsSelected(AliRsnCut::kParticle, d);
187}
188
189//________________________________________________________________________________________
190Bool_t AliRsnSimpleFunction::CutPass(AliRsnPairParticle *p)
191{
192//
193// Check if the AliRsnPairParticle argument pass its cuts.
194// If the cut data member is not initialized for it, returns kTRUE.
195// In this case, another separate check which could be necessary
196// concerns the possibility that the two tracks are a "true pair" of
197// daughters of the same resonance. If the corresponding flag is set,
198// this further check is done, and the method returns kTRUE only
199// when also this check is passed.
200//
201
202 Bool_t cutPassed, truePair;
203
204 cutPassed = fCuts->IsSelected(AliRsnCut::kPair, p);
205 truePair = fPair.IsTruePair(fPairDef->GetMotherPDG());
206
207 if (fTrueFlag) {
208 return (cutPassed && truePair);
209 }
210 else {
211 return cutPassed;
212 }
213}
214
215//________________________________________________________________________________________
216Bool_t AliRsnSimpleFunction::CutPass(AliRsnEvent *e)
217{
218//
219// Check if the AliRsnEvent argument pass its cuts.
220// If the cut data member is not initialized for it, returns kTRUE.
221//
222 if (!fCuts) return kTRUE;
223 else return fCuts->IsSelected(AliRsnCut::kEvent, e);
224}