]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnSimpleFunction.cxx
Package revised - New AnalysisTask's - Added more functions
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnSimpleFunction.cxx
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
37 ClassImp(AliRsnSimpleFunction)
38
39 //________________________________________________________________________________________
40 AliRsnSimpleFunction::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 //________________________________________________________________________________________
69 AliRsnSimpleFunction::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 //________________________________________________________________________________________
88 const 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 //________________________________________________________________________________________
111 void 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 //________________________________________________________________________________________
124 Bool_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     fHisto1D = (TH1D*)fHistoDef->CreateHistogram(name, "");
140     return kTRUE;
141 }
142
143 //________________________________________________________________________________________
144 Bool_t AliRsnSimpleFunction::ProcessOne(AliRsnEvent* /*event*/)
145 {
146 //
147 // Process a single event according to the purposes of the derived class.
148 // Here the user must put the code which defines how the internal histogram is filled.
149 // The boolean return value allows to catch a failure in execution.
150 //
151
152     AliWarning("This method must be defined in the derived class");
153     return kFALSE;
154 }
155
156 //________________________________________________________________________________________
157 Bool_t AliRsnSimpleFunction::ProcessTwo(AliRsnEvent* /*event1*/, AliRsnEvent* /*event2*/)
158 {
159 //
160 // Process two events according to relations between them.
161 // This method must be defined whenever the derived object is used in event mixing.
162 // The boolean return value allows to catch a failure in execution.
163 //
164
165     AliWarning("This method must be defined in the derived class");
166     return kFALSE;
167 }
168
169 //________________________________________________________________________________________
170 Bool_t AliRsnSimpleFunction::CutPass(AliRsnDaughter *d)
171 {
172 //
173 // Check if the AliRsnDaughter argument pass its cuts.
174 // If the cut data member is not initialized for it, returns kTRUE.
175 //
176     if (!fCuts) return kTRUE;
177     else return fCuts->IsSelected(AliRsnCut::kParticle, d);
178 }
179
180 //________________________________________________________________________________________
181 Bool_t AliRsnSimpleFunction::CutPass(AliRsnPairParticle *p)
182 {
183 //
184 // Check if the AliRsnPairParticle argument pass its cuts.
185 // If the cut data member is not initialized for it, returns kTRUE.
186 // In this case, another separate check which could be necessary
187 // concerns the possibility that the two tracks are a "true pair" of 
188 // daughters of the same resonance. If the corresponding flag is set,
189 // this further check is done, and the method returns kTRUE only 
190 // when also this check is passed.
191 //
192
193     Bool_t cutPassed, truePair;
194     
195     cutPassed = fCuts->IsSelected(AliRsnCut::kPair, p);
196     truePair = fPair.IsTruePair(fPairDef->GetMotherPDG());
197     
198     if (fTrueFlag) {
199         return (cutPassed && truePair);
200     }
201     else {
202         return cutPassed;
203     }
204 }
205
206 //________________________________________________________________________________________
207 Bool_t AliRsnSimpleFunction::CutPass(AliRsnEvent *e)
208 {
209 //
210 // Check if the AliRsnEvent argument pass its cuts.
211 // If the cut data member is not initialized for it, returns kTRUE.
212 //
213     if (!fCuts) return kTRUE;
214     else return fCuts->IsSelected(AliRsnCut::kEvent, e);
215 }