]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnCutStd.cxx
Added the possibility to cut in dip angle, to reject electrons close to the kinematic...
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutStd.cxx
1 //
2 // Class AliRsnCutStd
3 //
4 // General implementation of a single cut strategy, which can be:
5 // - a value contained in a given interval  [--> IsBetween()   ]
6 // - a value equal to a given reference     [--> MatchesValue()]
7 //
8 // In all cases, the reference value(s) is (are) given as data members
9 // and each kind of cut requires a given value type (Int, UInt, Double),
10 // but the cut check procedure is then automatized and chosen thanks to
11 // an enumeration of the implemented cut types.
12 // At the end, the user (or any other point which uses this object) has
13 // to use the method IsSelected() to check if this cut has been passed.
14 //
15 // authors: Martin Vala (martin.vala@cern.ch)
16 //          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
17 //
18
19 #include <TMath.h>
20 #include <TLorentzVector.h>
21
22 #include "AliStack.h"
23 #include "AliMCEvent.h"
24 #include "AliRsnDaughter.h"
25 #include "AliRsnMother.h"
26 #include "AliRsnEvent.h"
27
28 #include "AliRsnCutStd.h"
29
30 ClassImp(AliRsnCutStd)
31
32 //_________________________________________________________________________________________________
33 AliRsnCutStd::AliRsnCutStd() :
34   AliRsnCut(),
35   fType(kLastType),
36   fUseMC(kFALSE),
37   fMass(0.0)
38 {
39 //
40 // Default constructor.
41 //
42 }
43
44 //_________________________________________________________________________________________________
45 AliRsnCutStd::AliRsnCutStd
46 (const char *name, ETarget target, EType type, Int_t val1, Int_t val2, Bool_t useMC) :
47   AliRsnCut(name, target, val1, val2),
48   fType(type),
49   fUseMC(useMC),
50   fMass(0.0)
51 {
52 //
53 // Main constructor.
54 // Checks also that cut values are given in the correct type,
55 // in order to avoid that one passes, for example, a value which should be double
56 // but is interpreted as integer due to the overloading of constructors.
57 //
58
59   switch (fType) 
60   {
61     // int
62     case kMult:
63     case kCharge:
64       break;
65     // double
66     case kP:
67     case kPt:
68     case kPtLeading:
69     case kEta:
70     case kY:
71     case kDipAngle:
72     case kThetaDeg:
73       if (fVarType != kDouble) 
74       {
75         AliWarning(Form("[INT CONSTRUCTOR] Cut '%s' is based on DOUBLE. Casting values to DOUBLE", GetName()));
76         SetRange((Double_t)val1, (Double_t)val2);
77         AliWarning(Form("[INT CONSTRUCTOR] Cut '%s' DOUBLE range = %f, %f", GetName(), fMinD, fMaxD));
78       }
79       break;
80     // other cuts are not based on a value, so no problem
81     default:
82       break;
83   }
84 }
85
86 //_________________________________________________________________________________________________
87 AliRsnCutStd::AliRsnCutStd
88 (const char *name, ETarget target, EType type, Double_t val1, Double_t val2, Bool_t useMC) :
89   AliRsnCut(name, target, val1, val2),
90   fType(type),
91   fUseMC(useMC),
92   fMass(0.0)
93 {
94 //
95 // Main constructor.
96 // Checks also that cut values are given in the correct type,
97 // in order to avoid that one passes, for example, a value which should be double
98 // but is interpreted as integer due to the overloading of constructors
99 //
100
101   switch (fType) 
102   {
103     // int
104     case kMult:
105     case kCharge:
106       if (fVarType != kInt) 
107       {
108         AliWarning(Form("[DOUBLE CONSTRUCTOR] Cut '%s' is based on INT. Casting values to INT", GetName()));
109         SetRange((Int_t)val1, (Int_t)val2);
110         AliWarning(Form("[DOUBLE CONSTRUCTOR] Cut '%s' INT range = %d, %d", GetName(), fMinI, fMaxI));
111       }
112       break;
113     // double
114     case kP:
115     case kPt:
116     case kPtLeading:
117     case kEta:
118     case kY:
119     case kDipAngle:
120     case kThetaDeg:
121       break;
122     // other cuts are not based on a value, so no problem
123     default:
124       break;
125   }
126 }
127
128 //_________________________________________________________________________________________________
129 AliRsnCut::EVarType AliRsnCutStd::CheckType()
130 {
131 //
132 // Returns the variable type expected for the selected cut type
133 //
134
135   switch (fType) 
136   {
137     // integer cuts
138     case kMult:
139     case kCharge:
140       return kInt;
141     // double couts
142     case kP:
143     case kPt:
144     case kPtLeading:
145     case kEta:
146     case kY:
147     case kDipAngle:
148     case kThetaDeg:
149       return kDouble;
150     // other cuts are not based on a value, so no problem
151     default:
152       return kNoVar;
153   }
154 }
155
156 //_________________________________________________________________________________________________
157 Bool_t AliRsnCutStd::IsSelected(TObject *obj1, TObject *obj2)
158 {
159   // coherence check using the mother class method
160   if (!TargetOK(obj1, obj2)) 
161   {
162     AliError("Wrong target. Skipping cut");
163     return kTRUE;
164   }
165   
166   // if coherence check is OK, only one of the following
167   // dynamic casts will be successful, and it will trigger
168   // the correct internal method to check the cut
169   AliRsnDaughter *objD = dynamic_cast<AliRsnDaughter*>(obj1);
170   AliRsnMother   *objM = dynamic_cast<AliRsnMother*>(obj1);
171   AliRsnEvent    *objE = dynamic_cast<AliRsnEvent*>(obj1);  
172   if (objD) return IsDaughterSelected(objD);
173   else if (objM) return IsMotherSelected(objM);
174   else if (objE) return IsEventSelected(objE);
175   else return kTRUE;
176 }
177
178 //_________________________________________________________________________________________________
179 Bool_t AliRsnCutStd::IsDaughterSelected(AliRsnDaughter *daughter)
180 {
181 //
182 // Cut checker.
183 //
184
185   // get the correct reference object for kinematic cuts
186   // and check that this reference is not NULL, to avoid segfaults
187   AliVParticle *ref = fUseMC ? daughter->GetRefMC() : daughter->GetRef();
188
189   // loop on allowed possibilities
190   switch (fType) 
191   {
192     case kP:
193       fCutValueD = ref->P();
194       return OkRange();
195     case kPt:
196       fCutValueD = ref->Pt();
197       return OkRange();
198     case kThetaDeg:
199       fCutValueD = ref->Theta() * TMath::RadToDeg();
200       return OkRange();
201     case kEta:
202       fCutValueD = ref->Eta();
203       return OkRange();
204     case kCharge:
205       fCutValueI = (Int_t)ref->Charge();
206       return OkValue();
207     case kPhysPrimary:
208       if (!fEvent->GetRefMC()) return kFALSE;
209       else
210       {
211         return fEvent->GetRefMC()->Stack()->IsPhysicalPrimary(TMath::Abs(((AliVTrack*)ref)->GetLabel()));
212       }
213     default:
214       AliWarning(Form("Value %d is not included in available cuts for DAUGHTER. Cut skipped.", fType));
215       return kTRUE;
216   }
217 }
218
219 //_________________________________________________________________________________________________
220 Bool_t AliRsnCutStd::IsMotherSelected(AliRsnMother * const mother)
221 {
222 //
223 // Cut checker
224 //
225   
226   // use MC flag if required
227   TLorentzVector &sum = fUseMC ? mother->SumMC() : mother->Sum();
228   TLorentzVector &ref = fUseMC ? mother->RefMC() : mother->Ref();
229   
230   // loop on allowed possibilities
231   switch (fType) 
232   {
233     case kP:
234       fCutValueD = sum.P();
235       return OkRange();
236     case kPt:
237       fCutValueD = sum.Perp();
238       return OkRange();
239     case kEta:
240       fCutValueD = sum.Eta();
241       return OkRange();
242     case kY:
243       fCutValueD = ref.Rapidity();
244       return OkRange();
245     case kDipAngle:
246       fCutValueD  = mother->GetDaughter(0)->P().Perp() * mother->GetDaughter(1)->P().Perp();
247       fCutValueD += mother->GetDaughter(0)->P().Pz() * mother->GetDaughter(1)->P().Pz();
248       fCutValueD += mother->GetDaughter(0)->P().Mag() * mother->GetDaughter(1)->P().Mag();
249       fCutValueD  = TMath::ACos(fCutValueD);
250       return OkRange();
251     case kSameLabel:
252       return mother->IsLabelEqual();
253     default:
254       AliWarning(Form("Value %d is not included in available cuts for PAIR. Cut skipped.", fType));
255       return kTRUE;
256   }
257 }
258
259 //_________________________________________________________________________________________________
260 Bool_t AliRsnCutStd::IsEventSelected(AliRsnEvent * const event)
261 {
262 //
263 // Cut checker
264 //
265
266   // loop on allowed possibilities
267   switch (fType) 
268   {
269     case kMult:
270       fCutValueI = event->GetMultiplicity();
271       return OkRange();
272     case kPtLeading:
273     {
274       int leadingID = event->SelectLeadingParticle(0);
275       if(leadingID >= 0) {
276           AliRsnDaughter leadingPart = event->GetDaughter(leadingID);
277           AliVParticle *ref = fUseMC ? leadingPart.GetRefMC() : leadingPart.GetRef();
278           fCutValueD = ref->Pt();
279       }
280       else fCutValueD = 0;
281       return OkRange();
282     }
283     default:
284       AliWarning(Form("Value %d is not included in available cuts for EVENT. Cut skipped.", fType));
285       return kTRUE;
286   }
287 }