]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/AliFlowTasks/AliFlowEventCuts.cxx
5772078c542a32c9f21afb165e68c833496b63d3
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowTasks / AliFlowEventCuts.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */ 
17
18 // AliFlowEventCuts:
19 // An event cut class for the flow framework
20 //
21 // origin: Mikolaj Krzewicki (mikolaj.krzewicki@cern.ch)
22
23 #include <limits.h>
24 #include <float.h>
25 #include "TMath.h"
26 #include "TNamed.h"
27 #include "AliVVertex.h"
28 #include "AliVEvent.h"
29 #include "AliESDEvent.h"
30 #include "AliESDVZERO.h"
31 #include "AliMultiplicity.h"
32 #include "AliMCEvent.h"
33 #include "AliFlowEventCuts.h"
34 #include "AliFlowTrackCuts.h"
35
36 ClassImp(AliFlowEventCuts)
37
38 //-----------------------------------------------------------------------
39 AliFlowEventCuts::AliFlowEventCuts():
40   TNamed(),
41   fCutNumberOfTracks(kFALSE),
42   fNumberOfTracksMax(INT_MAX),
43   fNumberOfTracksMin(INT_MIN),
44   fCutRefMult(kFALSE),
45   fRefMultMethod(kTPConly),
46   fRefMultMax(INT_MAX),
47   fRefMultMin(INT_MIN),
48   fRefMultCuts(NULL),
49   fMeanPtCuts(NULL),
50   fCutPrimaryVertexX(kFALSE),
51   fPrimaryVertexXmax(INT_MAX),
52   fPrimaryVertexXmin(INT_MIN),
53   fCutPrimaryVertexY(kFALSE),
54   fPrimaryVertexYmax(INT_MAX),
55   fPrimaryVertexYmin(INT_MIN),
56   fCutPrimaryVertexZ(kFALSE),
57   fPrimaryVertexZmax(INT_MAX),
58   fPrimaryVertexZmin(INT_MIN),
59   fCutNContributors(kFALSE),
60   fNContributorsMax(INT_MAX),
61   fNContributorsMin(INT_MIN),
62   fCutMeanPt(kFALSE),
63   fMeanPtMax(-DBL_MAX),
64   fMeanPtMin(DBL_MAX)
65 {
66   //constructor 
67 }
68
69 //-----------------------------------------------------------------------
70 AliFlowEventCuts::AliFlowEventCuts(const char* name, const char* title):
71   TNamed(name, title),
72   fCutNumberOfTracks(kFALSE),
73   fNumberOfTracksMax(INT_MAX),
74   fNumberOfTracksMin(INT_MIN),
75   fCutRefMult(kFALSE),
76   fRefMultMethod(kTPConly),
77   fRefMultMax(INT_MAX),
78   fRefMultMin(INT_MIN),
79   fRefMultCuts(NULL),
80   fMeanPtCuts(NULL),
81   fCutPrimaryVertexX(kFALSE),
82   fPrimaryVertexXmax(INT_MAX),
83   fPrimaryVertexXmin(INT_MIN),
84   fCutPrimaryVertexY(kFALSE),
85   fPrimaryVertexYmax(INT_MAX),
86   fPrimaryVertexYmin(INT_MIN),
87   fCutPrimaryVertexZ(kFALSE),
88   fPrimaryVertexZmax(INT_MAX),
89   fPrimaryVertexZmin(INT_MIN),
90   fCutNContributors(kFALSE),
91   fNContributorsMax(INT_MAX),
92   fNContributorsMin(INT_MIN),
93   fCutMeanPt(kFALSE),
94   fMeanPtMax(-DBL_MAX),
95   fMeanPtMin(DBL_MAX)
96 {
97   //constructor 
98 }
99
100 ////-----------------------------------------------------------------------
101 AliFlowEventCuts::AliFlowEventCuts(const AliFlowEventCuts& that):
102   TNamed(that),
103   fCutNumberOfTracks(that.fCutNumberOfTracks),
104   fNumberOfTracksMax(that.fNumberOfTracksMax),
105   fNumberOfTracksMin(that.fNumberOfTracksMin),
106   fCutRefMult(that.fCutRefMult),
107   fRefMultMethod(that.fRefMultMethod),
108   fRefMultMax(that.fRefMultMax),
109   fRefMultMin(that.fRefMultMin),
110   fRefMultCuts(NULL),
111   fMeanPtCuts(NULL),
112   fCutPrimaryVertexX(that.fCutPrimaryVertexX),
113   fPrimaryVertexXmax(that.fPrimaryVertexXmax),
114   fPrimaryVertexXmin(that.fPrimaryVertexXmin),
115   fCutPrimaryVertexY(that.fCutPrimaryVertexX),
116   fPrimaryVertexYmax(that.fPrimaryVertexYmax),
117   fPrimaryVertexYmin(that.fPrimaryVertexYmin),
118   fCutPrimaryVertexZ(that.fCutPrimaryVertexX),
119   fPrimaryVertexZmax(that.fPrimaryVertexZmax),
120   fPrimaryVertexZmin(that.fPrimaryVertexZmin),
121   fCutNContributors(that.fCutNContributors),
122   fNContributorsMax(that.fNContributorsMax),
123   fNContributorsMin(that.fNContributorsMin),
124   fCutMeanPt(that.fCutMeanPt),
125   fMeanPtMax(that.fMeanPtMax),
126   fMeanPtMin(that.fMeanPtMin)
127 {
128   //copy constructor 
129   if (that.fRefMultCuts)
130     fRefMultCuts = new AliFlowTrackCuts(*(that.fRefMultCuts));
131   if (that.fMeanPtCuts)
132     fMeanPtCuts = new AliFlowTrackCuts(*(that.fMeanPtCuts));
133 }
134
135 ////-----------------------------------------------------------------------
136 AliFlowEventCuts::~AliFlowEventCuts()
137 {
138   //dtor
139   delete fMeanPtCuts;
140   delete fRefMultCuts;
141 }
142
143 ////-----------------------------------------------------------------------
144 AliFlowEventCuts& AliFlowEventCuts::operator=(const AliFlowEventCuts& that)
145 {
146   //assignment
147   fCutNumberOfTracks=that.fCutNumberOfTracks;
148   fNumberOfTracksMax=that.fNumberOfTracksMax;
149   fNumberOfTracksMin=that.fNumberOfTracksMin;
150   fCutRefMult=that.fCutRefMult;
151   fRefMultMethod=that.fRefMultMethod;
152   fRefMultMax=that.fRefMultMax;
153   fRefMultMin=that.fRefMultMin;
154   if (that.fRefMultCuts) *fRefMultCuts=*(that.fRefMultCuts);
155   if (that.fMeanPtCuts) *fMeanPtCuts=*(that.fMeanPtCuts);
156   fCutPrimaryVertexX=that.fCutPrimaryVertexX;
157   fPrimaryVertexXmin=that.fPrimaryVertexXmin;
158   fPrimaryVertexXmax=that.fPrimaryVertexXmax;
159   fPrimaryVertexYmin=that.fPrimaryVertexYmin;
160   fPrimaryVertexYmax=that.fPrimaryVertexYmax;
161   fPrimaryVertexZmin=that.fPrimaryVertexZmin;
162   fPrimaryVertexZmax=that.fPrimaryVertexZmax;
163   fCutNContributors=that.fCutNContributors;
164   fNContributorsMax=that.fNContributorsMax;
165   fNContributorsMin=that.fNContributorsMin;
166   fCutMeanPt=that.fCutMeanPt;
167   fMeanPtMax=that.fMeanPtMax;
168   fMeanPtMin=that.fMeanPtMin;
169   return *this;
170 }
171
172 //----------------------------------------------------------------------- 
173 Bool_t AliFlowEventCuts::IsSelected(const TObject* obj)
174 {
175   //check cuts
176   const AliVEvent* vevent = dynamic_cast<const AliVEvent*>(obj);
177   if (vevent) return PassesCuts(vevent);
178   return kFALSE;  //when passed wrong type of object
179 }
180 //----------------------------------------------------------------------- 
181 Bool_t AliFlowEventCuts::PassesCuts(const AliVEvent *event)
182 {
183   ///check if event passes cuts
184   if(fCutNumberOfTracks) {if (event->GetNumberOfTracks() < fNumberOfTracksMin || event->GetNumberOfTracks() >= fNumberOfTracksMax ) return kFALSE;}
185   if(fCutRefMult)
186   {
187     //reference multiplicity still to be defined
188     Double_t refMult = RefMult(event);
189     if (refMult < fRefMultMin || refMult >= fRefMultMax )
190       return kFALSE;
191   }
192   const AliVVertex* pvtx=event->GetPrimaryVertex();
193   Double_t pvtxx = pvtx->GetX();
194   Double_t pvtxy = pvtx->GetY();
195   Double_t pvtxz = pvtx->GetZ();
196   Int_t ncontrib = pvtx->GetNContributors();
197   if (fCutNContributors)
198   {
199     if (ncontrib < fNContributorsMin || ncontrib >= fNContributorsMax)
200       return kFALSE;
201   }
202   if (fCutPrimaryVertexX)
203   {
204     if (pvtxx < fPrimaryVertexXmin || pvtxx >= fPrimaryVertexXmax)
205       return kFALSE;
206   }
207   if (fCutPrimaryVertexY)
208   {
209     if (pvtxy < fPrimaryVertexYmin || pvtxy >= fPrimaryVertexYmax)
210       return kFALSE;
211   }
212   if (fCutPrimaryVertexZ)
213   {
214     if (pvtxz < fPrimaryVertexZmin || pvtxz >= fPrimaryVertexZmax)
215       return kFALSE;
216   }
217   if (fCutMeanPt)
218   {
219     Float_t meanpt=0.0;
220     Int_t ntracks=event->GetNumberOfTracks();
221     Int_t nselected=0;
222     for (Int_t i=0; i<ntracks; i++)
223     {
224       AliVParticle* track = event->GetTrack(i);
225       if (!track) continue;
226       Bool_t pass=kTRUE;
227       if (fMeanPtCuts) pass=fMeanPtCuts->IsSelected(track);
228       if (pass) 
229       {
230         meanpt += track->Pt();
231         nselected++;
232       }
233     }
234     meanpt=meanpt/nselected;
235     if (meanpt<fMeanPtMin || meanpt >= fMeanPtMax) return kFALSE;
236   }
237   return kTRUE;
238 }
239
240 //----------------------------------------------------------------------- 
241 AliFlowEventCuts* AliFlowEventCuts::StandardCuts()
242 {
243   //make a set of standard event cuts, caller becomes owner
244   AliFlowEventCuts* cuts = new AliFlowEventCuts();
245   return cuts;
246 }
247
248 //----------------------------------------------------------------------- 
249 Int_t AliFlowEventCuts::RefMult(const AliVEvent* event)
250 {
251   //calculate the reference multiplicity, if all fails return 0
252   AliESDVZERO* vzero = NULL;
253   const AliESDEvent* esdevent = dynamic_cast<const AliESDEvent*>(event);
254   const AliMultiplicity* mult = esdevent->GetMultiplicity();
255   Int_t refmult=0;
256   if (!fRefMultCuts)
257   {
258     switch (fRefMultMethod)
259     {
260       case kTPConly:
261         fRefMultCuts = AliFlowTrackCuts::GetStandardTPCOnlyTrackCuts();
262         fRefMultCuts->SetEtaRange(-0.8,0.8);
263         fRefMultCuts->SetPtMin(0.15);
264         break;
265       case kSPDtracklets:
266         fRefMultCuts = new AliFlowTrackCuts();
267         fRefMultCuts->SetParamType(AliFlowTrackCuts::kESD_SPDtracklet);
268         fRefMultCuts->SetEtaRange(-0.8,0.8);
269         break;
270       case kV0:
271         if (!esdevent) return 0;
272         vzero=esdevent->GetVZEROData();
273         if (!vzero) return 0;
274         refmult += TMath::Nint(vzero->GetMTotV0A());
275         refmult += TMath::Nint(vzero->GetMTotV0C());
276         return refmult;
277       case kSPD1clusters:
278         if (!mult) return 0;
279         refmult = mult->GetNumberOfITSClusters(1);
280         return refmult;
281       default:
282         return 0;
283     }
284   }
285
286   fRefMultCuts->SetEvent(const_cast<AliVEvent*>(event));
287   for (Int_t i=0; i<fRefMultCuts->GetNumberOfInputObjects(); i++)
288   {
289     if (fRefMultCuts->IsSelected(fRefMultCuts->GetInputObject(i),i))
290       refmult++;
291   }
292   return refmult;
293 }