]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliHFEextraEventCuts.cxx
Coverity
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEextraEventCuts.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 // Cut on the Event at reconstructed level: for the moment 
16 // the requirements on the number of charged tracks and on 
17 // the vertex position and resolution are implemented
18 // The argument of IsSelected member function (passed object) is cast into 
19 // an AliESDEvent. In the future may be modified to use AliVEvent interface
20 // and include more cut variables.
21 // The class derives from AliCFCutBase
22 // Author:S.Arcelli Silvia.Arcelli@cern.ch
23 //
24 //
25 #include "TH1F.h"
26 #include "TList.h"
27 #include "TBits.h"
28 #include "AliLog.h"
29 #include "AliESDEvent.h"
30 #include "AliESDVertex.h"
31 #include "AliAODEvent.h"
32 #include "AliAODVertex.h"
33 #include "AliHFEextraEventCuts.h"
34 ClassImp(AliHFEextraEventCuts) 
35 //____________________________________________________________________
36 AliHFEextraEventCuts::AliHFEextraEventCuts() : 
37   AliCFCutBase(),
38   fRequireVtxCuts(kFALSE),
39   fVtxZMax(1.e99),
40   fVtxZMin(-1.e99),
41   fVtxNCtrbMin(0),
42   fVtxMixed(0),
43   fVtxSPD(0),
44   fCheckCorrelationSPDVtx(0),
45   fBitMap(0x0)
46 {
47   //
48   //ctor
49   //
50 }
51
52 //____________________________________________________________________
53 AliHFEextraEventCuts::AliHFEextraEventCuts(Char_t* name, Char_t* title) : 
54   AliCFCutBase(name,title),
55   fRequireVtxCuts(kFALSE),
56   fVtxZMax(1.e99),
57   fVtxZMin(-1.e99),
58   fVtxNCtrbMin(0),
59   fVtxMixed(0),
60   fVtxSPD(0),
61   fCheckCorrelationSPDVtx(0),
62   fBitMap(0x0)
63  {
64   //
65   //ctor
66   //
67   fBitMap=new TBits(0);
68   Initialise();
69  }
70
71 //____________________________________________________________________
72 AliHFEextraEventCuts::AliHFEextraEventCuts(const AliHFEextraEventCuts& c) : 
73   AliCFCutBase(c),
74   fRequireVtxCuts(c.fRequireVtxCuts),
75   fVtxZMax(c.fVtxZMax),
76   fVtxZMin(c.fVtxZMin),
77   fVtxNCtrbMin(c.fVtxNCtrbMin),
78   fVtxMixed(c.fVtxMixed),
79   fVtxSPD(c.fVtxSPD),
80   fCheckCorrelationSPDVtx(c.fCheckCorrelationSPDVtx),
81   fBitMap(c.fBitMap)
82 {
83   //
84   //copy constructor
85   //
86   for (Int_t i=0; i<c.kNCuts; i++){
87     for (Int_t j=0; j<c.kNStepQA; j++){
88       if(c.fhQA[i][j]) fhQA[i][j] = (TH1F*)c.fhQA[i][j]->Clone();
89     }
90   }
91
92 }
93
94 //____________________________________________________________________
95 AliHFEextraEventCuts::~AliHFEextraEventCuts() {
96   //
97   //dtor
98   //
99
100   for (Int_t i=0; i<kNCuts; i++){
101     for (Int_t j=0; j<kNStepQA; j++){
102       if(fhQA[i][j]) delete fhQA[i][j];
103     }
104   }
105
106   if(fBitMap)delete fBitMap;
107
108 }
109 //_____________________________________________________________________________
110 void AliHFEextraEventCuts::Initialise()
111 {
112
113   //
114   //initialization
115   //
116
117   //
118   // sets pointers to histos to zero
119   //
120
121   for(Int_t i=0; i<kNCuts; i++){
122     for(Int_t j =0; j<kNStepQA; j++){
123       fhQA[i][j]=0x0;
124     }
125   }
126 }
127
128 //____________________________________________________________________
129 AliHFEextraEventCuts& AliHFEextraEventCuts::operator=(const AliHFEextraEventCuts& c)
130 {
131   //
132   // Assignment operator
133   //
134   if (this != &c) {
135     AliCFCutBase::operator=(c) ;
136     fRequireVtxCuts=c.fRequireVtxCuts;
137     fVtxZMax=c.fVtxZMax;
138     fVtxZMin=c.fVtxZMin;
139     fVtxNCtrbMin=c.fVtxNCtrbMin;
140     fVtxMixed=c.fVtxMixed;
141     fVtxSPD=c.fVtxSPD;
142     fCheckCorrelationSPDVtx=c.fCheckCorrelationSPDVtx;
143     fBitMap=c.fBitMap;
144   }
145
146   for (Int_t i=0; i<c.kNCuts; i++){
147     for (Int_t j=0; j<c.kNStepQA; j++){
148       if(c.fhQA[i][j]) fhQA[i][j] = (TH1F*)c.fhQA[i][j]->Clone();
149     }
150   }
151
152
153   return *this ;
154 }
155
156 //____________________________________________________________________
157 Bool_t AliHFEextraEventCuts::IsSelected(TObject* obj) {
158   //
159   //Check if the requested cuts are passed
160   //
161
162
163   SelectionBitMap(obj);
164
165   if (fIsQAOn) FillHistograms(obj,0);
166   Bool_t isSelected = kTRUE;
167
168   for (UInt_t icut=0; icut<fBitMap->GetNbits();icut++)
169         if(!fBitMap->TestBitNumber(icut)) isSelected = kFALSE;
170
171   if (!isSelected) return kFALSE ;
172   if (fIsQAOn) FillHistograms(obj,1);
173   return kTRUE;
174
175 }
176 //____________________________________________________________________
177 void AliHFEextraEventCuts::SelectionBitMap(TObject* obj) {
178   //
179   //cut on the number of charged tracks and on the event vertex.
180   //so far specific to AliESDEvents
181   //
182
183   //Check if the requested cuts are passed and return a bitmap
184   for(Int_t j=0;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE);
185
186
187
188   AliESDEvent* esd = dynamic_cast<AliESDEvent *>(obj);
189   AliAODEvent* aod = dynamic_cast<AliAODEvent *>(obj);
190
191
192   // ESD
193
194   if ( esd ) {
195     
196     //now start checking the cuts,
197     //first assume the event will be accepted: 
198     for(Int_t j=0;j<kNCuts;j++)fBitMap->SetBitNumber(j,kTRUE);
199     
200     
201     
202     if(fRequireVtxCuts){
203       const AliESDVertex* vtxESD = 0x0;
204       if      (fVtxMixed) {
205         vtxESD = esd->GetPrimaryVertexTracks() ;
206         if((!vtxESD) || (vtxESD->GetNContributors() <= 0)) {
207           vtxESD = esd->GetPrimaryVertexSPD() ;
208           if((!vtxESD) || (vtxESD->GetNContributors() <= 0)) {
209             for(Int_t j=1;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE); 
210             AliWarning("Cannot get vertex, skipping event");
211             return;
212           }
213         }
214       }
215       else if(fVtxSPD) {   
216         vtxESD = esd->GetPrimaryVertexSPD() ;
217         if(fCheckCorrelationSPDVtx) {
218           const AliESDVertex* vtxESDtr = esd->GetPrimaryVertexTracks();
219           if((vtxESD) && (vtxESD->GetNContributors() > 0) && (vtxESDtr) && (vtxESDtr->GetNContributors() > 0)) {
220             if(TMath::Abs(vtxESD->GetZv()-vtxESDtr->GetZv())>0.5) return;
221           }
222           else return;
223         }
224       }
225       else {
226         vtxESD = esd->GetPrimaryVertexTracks() ;
227       }
228       
229       if(!vtxESD){
230         for(Int_t j=1;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE); 
231         AliWarning("Cannot get vertex, skipping event");
232         return;
233       }
234       
235       // Pick up the position and uncertainties
236       Double_t vtxPos[3];
237       vtxPos[0] = vtxESD->GetXv();
238       vtxPos[1] = vtxESD->GetYv();
239       vtxPos[2] = vtxESD->GetZv();
240       
241       Int_t nCtrb = vtxESD->GetNContributors();
242       
243       // Apply the cut
244       
245       if (vtxPos[2]>fVtxZMax || vtxPos[2]<fVtxZMin)
246         fBitMap->SetBitNumber(0,kFALSE); 
247       if (nCtrb<fVtxNCtrbMin)
248         fBitMap->SetBitNumber(1,kFALSE);
249       
250     }  
251     return;
252     
253     
254   }
255
256   //
257
258   // AOD
259
260   if ( aod ) {
261     
262     //now start checking the cuts,
263     //first assume the event will be accepted: 
264     for(Int_t j=0;j<kNCuts;j++)fBitMap->SetBitNumber(j,kTRUE);
265     
266     
267     
268     if(fRequireVtxCuts){
269       const AliAODVertex* vtxAOD = 0x0;
270       if      (fVtxMixed) {
271         vtxAOD = aod->GetPrimaryVertex();
272         if((!vtxAOD) || (vtxAOD->GetNContributors() <= 0)) {
273           vtxAOD = aod->GetPrimaryVertexSPD() ;
274           if((!vtxAOD) || (vtxAOD->GetNContributors() <= 0)) {
275             for(Int_t j=1;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE); 
276             AliWarning("Cannot get vertex, skipping event");
277             return;
278           }
279         }
280       }
281       else if(fVtxSPD) {   
282         vtxAOD = aod->GetPrimaryVertexSPD() ;
283         if(fCheckCorrelationSPDVtx) {
284           const AliAODVertex* vtxAODtr = aod->GetPrimaryVertex();
285           if((vtxAOD) && (vtxAOD->GetNContributors() > 0) && (vtxAODtr) && (vtxAODtr->GetNContributors() > 0)) {
286             if(TMath::Abs(vtxAOD->GetZ()-vtxAODtr->GetZ())>0.5) return;
287           }
288           else return;
289         }
290       }
291       else {
292         vtxAOD = aod->GetPrimaryVertex() ;
293       }
294       
295       if(!vtxAOD){
296         for(Int_t j=1;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE); 
297         AliWarning("Cannot get vertex, skipping event");
298         return;
299       }
300       
301       // Pick up the position and uncertainties
302       Double_t vtxPos[3];
303       vtxPos[0] = vtxAOD->GetX();
304       vtxPos[1] = vtxAOD->GetY();
305       vtxPos[2] = vtxAOD->GetZ();
306       
307       Int_t nCtrb = vtxAOD->GetNContributors();
308       //printf("AliHFEextraCuts:: %d, %f, %f, %f\n",nCtrb,vtxPos[0],vtxPos[1],vtxPos[2]);
309       
310       // Apply the cut
311       
312       if (vtxPos[2]>fVtxZMax || vtxPos[2]<fVtxZMin)
313         fBitMap->SetBitNumber(0,kFALSE); 
314       if (nCtrb<fVtxNCtrbMin)
315         fBitMap->SetBitNumber(1,kFALSE);
316       
317     }  
318     return;
319     
320     
321   }
322   
323   return;
324   
325 }
326
327 //_____________________________________________________________________________
328 void AliHFEextraEventCuts::FillHistograms(TObject* obj, Bool_t b)
329 {
330   //
331   // fill the QA histograms
332   //
333
334   if(!fIsQAOn) return;
335   // cast TObject into VParticle
336   AliESDEvent* esd = dynamic_cast<AliESDEvent *>(obj);
337   if (!esd ) return  ;
338
339   // index = 0: fill histograms before cuts
340   // index = 1: fill histograms after cuts
341   Int_t index = -1;
342   index = ((b) ? 1 : 0);
343
344
345   //look at vertex parameters:
346   const AliESDVertex* vtxESD = 0x0;
347   if      (fVtxMixed) {
348     vtxESD = esd->GetPrimaryVertexTracks() ;
349     if((!vtxESD) || (vtxESD->GetNContributors() <= 0)) {
350       vtxESD = esd->GetPrimaryVertexSPD() ;
351       if((!vtxESD) || (vtxESD->GetNContributors() <= 0)) {
352         return;
353       }
354     }
355   }
356   else {   
357     vtxESD = esd->GetPrimaryVertexTracks() ;
358   }
359   if(!vtxESD)return;
360   // vertex position and uncertainties
361   fhQA[kVtxPosZ] [index]->Fill(vtxESD->GetZv());
362   fhQA[kVtxNCtrb][index]->Fill(vtxESD->GetNContributors());
363   
364 }
365
366 //____________________________________________________________________
367 void AliHFEextraEventCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t *bins)
368 {
369   //
370   //setting x-axis bin limits of QA histogram fhQA[index] 
371   // 
372
373   for(Int_t i=0;i<kNStepQA;i++){
374     if(!fhQA[index][i]){AliWarning("non-existing histogram!");
375     return;
376     }
377     fhQA[index][i]->GetXaxis()->Set(nbins,bins);
378   }
379 }
380 //____________________________________________________________________
381 void AliHFEextraEventCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t xmin, Double_t xmax)
382 {
383   //
384   //setting x-axis bins and range of QA histogram fhQA[index] 
385   // 
386
387   for(Int_t i=0;i<kNStepQA;i++){
388     if(!fhQA[index][i]){AliWarning("non-existing histogram!");
389     return;
390     }
391     fhQA[index][i]->GetXaxis()->Set(nbins,xmin,xmax);
392   }
393 }
394
395 //_____________________________________________________________________________
396  void AliHFEextraEventCuts::DefineHistograms() {
397   //
398   // histograms for cut variables
399   //
400   Int_t color = 2;
401
402   if(!fIsQAOn) {
403     AliInfo(Form("No QA histos requested, Please first set the QA flag on!"));
404     return;
405   }  
406   
407   // book QA histograms
408
409   Char_t str[5];
410   for (Int_t i=0; i<kNStepQA; i++) {
411     if (i==0) snprintf(str,5," ");
412     else snprintf(str,5,"_cut");
413
414     fhQA[kVtxPosZ][i]   = new  TH1F(Form("%s_Vtx_Pos_Z%s",GetName(),str),               "",200,-50.,50.);
415     fhQA[kVtxNCtrb][i]  = new  TH1F(Form("%s_Vtx_N_Ctrb%s",GetName(),str),              "",1000,0.,1000.);
416  
417     fhQA[kVtxPosZ][i]   ->SetXTitle("Vertex Position Z (cm)");
418     fhQA[kVtxNCtrb][i]  ->SetXTitle("Number of contributors");
419   }
420
421   for(Int_t i=0; i<kNCuts; i++) fhQA[i][1]->SetLineColor(color);
422
423 }
424
425 //_____________________________________________________________________________
426 void AliHFEextraEventCuts::AddQAHistograms(TList *qaList) {
427   //
428   // saves the histograms in a TList
429   //
430
431   DefineHistograms();
432
433   for (Int_t j=0; j<kNStepQA; j++) {
434     for(Int_t i=0; i<kNCuts; i++)
435         qaList->Add(fhQA[i][j]);
436   }
437 }