Create DA RPM
[u/mrichter/AliRoot.git] / CORRFW / AliCFEventClassCuts.cxx
CommitLineData
563113d0 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// To select on the Event Class: look at the Trigger mask and the ZDC info.
16// Only pp-running trigger types implemented so far
17// handles all masks for the trigger description
9baeb4ef 18// and some general combinations like MB1,MB2,MB3,MB4 and MB5.
563113d0 19// The argument of IsSelected member function (passed object) is cast into
20// an AliVEvent, but cuts have a true meaning only for AliESD(AOD)Event
21// type objects.
22// The class derives from AliCFCutBase
23// Author:S.Arcelli Silvia.Arcelli@cern.ch
24//
25//
26#include "TH1F.h"
27#include "TList.h"
28#include "AliLog.h"
563113d0 29#include "AliVEvent.h"
30#include "AliCFEventClassCuts.h"
31ClassImp(AliCFEventClassCuts)
32//____________________________________________________________________
33AliCFEventClassCuts::AliCFEventClassCuts() :
34 AliCFCutBase(),
35 fTriggerType(0),
36 fTriggerAND(kFALSE),
37 fZDCN1EnergyMin(-1.e99),
38 fZDCP1EnergyMin(-1.e99),
39 fZDCN2EnergyMin(-1.e99),
40 fZDCP2EnergyMin(-1.e99),
41 fZDCEM1EnergyMin(-1.e99),
42 fZDCEM2EnergyMin(-1.e99),
43 fZDCN1EnergyMax(1.e99),
44 fZDCP1EnergyMax(1.e99),
45 fZDCN2EnergyMax(1.e99),
46 fZDCP2EnergyMax(1.e99),
47 fZDCEM1EnergyMax(1.e99),
48 fZDCEM2EnergyMax(1.e99),
107a3100 49 fBitMap(0x0)
563113d0 50{
51 //
52 //ctor
53 //
54
55 fBitMap=new TBits(0);
56 Initialise();
57}
9baeb4ef 58
563113d0 59//____________________________________________________________________
60AliCFEventClassCuts::AliCFEventClassCuts(Char_t* name, Char_t* title) :
61 AliCFCutBase(name,title),
62 fTriggerType(0),
63 fTriggerAND(kFALSE),
64 fZDCN1EnergyMin(-1.e99),
65 fZDCP1EnergyMin(-1.e99),
66 fZDCN2EnergyMin(-1.e99),
67 fZDCP2EnergyMin(-1.e99),
68 fZDCEM1EnergyMin(-1.e99),
69 fZDCEM2EnergyMin(-1.e99),
70 fZDCN1EnergyMax(1.e99),
71 fZDCP1EnergyMax(1.e99),
72 fZDCN2EnergyMax(1.e99),
73 fZDCP2EnergyMax(1.e99),
74 fZDCEM1EnergyMax(1.e99),
75 fZDCEM2EnergyMax(1.e99),
107a3100 76 fBitMap(0x0)
563113d0 77{
78 //
79 //ctor
80 //
81 fBitMap=new TBits(0);
82 Initialise();
83 }
9baeb4ef 84
85//_____________________________________________________________________________
563113d0 86AliCFEventClassCuts::AliCFEventClassCuts(const AliCFEventClassCuts& c) :
87 AliCFCutBase(c),
88 fTriggerType(c.fTriggerType),
89 fTriggerAND(c.fTriggerAND),
90 fZDCN1EnergyMin(c.fZDCN1EnergyMin),
91 fZDCP1EnergyMin(c.fZDCP1EnergyMin),
92 fZDCN2EnergyMin(c.fZDCN2EnergyMin),
93 fZDCP2EnergyMin(c.fZDCP2EnergyMin),
94 fZDCEM1EnergyMin(c.fZDCEM1EnergyMin),
95 fZDCEM2EnergyMin(c.fZDCEM2EnergyMin),
96 fZDCN1EnergyMax(c.fZDCN1EnergyMax),
97 fZDCP1EnergyMax(c.fZDCP1EnergyMax),
98 fZDCN2EnergyMax(c.fZDCN2EnergyMax),
99 fZDCP2EnergyMax(c.fZDCP2EnergyMax),
100 fZDCEM1EnergyMax(c.fZDCEM1EnergyMax),
101 fZDCEM2EnergyMax(c.fZDCEM2EnergyMax),
107a3100 102 fBitMap(c.fBitMap)
563113d0 103
104{
105 //
106 //copy constructor
107 //
108}
9baeb4ef 109
110//_____________________________________________________________________________
563113d0 111AliCFEventClassCuts& AliCFEventClassCuts::operator=(const AliCFEventClassCuts& c){
112 //
113 // Assignment operator
114 //
115 if (this != &c) {
116 AliCFCutBase::operator=(c) ;
117 fTriggerType = c.fTriggerType ;
118 fTriggerAND = c.fTriggerAND ;
119 fZDCN1EnergyMin = c.fZDCN1EnergyMin;
120 fZDCP1EnergyMin = c.fZDCP1EnergyMin;
121 fZDCN2EnergyMin = c.fZDCN2EnergyMin;
122 fZDCP2EnergyMin = c.fZDCP2EnergyMin;
123 fZDCEM1EnergyMin = c.fZDCEM1EnergyMin;
124 fZDCEM2EnergyMin = c.fZDCEM2EnergyMin;
125 fZDCN1EnergyMax = c.fZDCN1EnergyMax;
126 fZDCP1EnergyMax = c.fZDCP1EnergyMax;
127 fZDCN2EnergyMax = c.fZDCN2EnergyMax;
128 fZDCP2EnergyMax = c.fZDCP2EnergyMax;
129 fZDCEM1EnergyMax = c.fZDCEM1EnergyMax;
130 fZDCEM2EnergyMax = c.fZDCEM2EnergyMax;
131 fBitMap = c.fBitMap;
563113d0 132 }
133
134
135 for (Int_t i=0; i<c.kNCuts; i++){
136 for (Int_t j=0; j<c.kNStepQA; j++){
137 if(c.fhQA[i][j]) fhQA[i][j] = (TH1F*)c.fhQA[i][j]->Clone();
138 }
139 }
140
141 return *this ;
142}
143
9baeb4ef 144//_____________________________________________________________________________
563113d0 145AliCFEventClassCuts::~AliCFEventClassCuts()
146{
147 //
148 // destructor
149 //
150 for (Int_t i=0; i<kNCuts; i++){
151 for (Int_t j=0; j<kNStepQA; j++){
152 if(fhQA[i][j]) delete fhQA[i][j];
153 }
154 }
155
156 if(fBitMap)delete fBitMap;
563113d0 157
158}
9baeb4ef 159
160//_____________________________________________________________________________
563113d0 161void AliCFEventClassCuts::Initialise()
162{
163 //
164 //initialization
165 //
563113d0 166 // sets pointers to histos to zero
563113d0 167 for(Int_t i=0; i<kNCuts; i++){
168 for(Int_t j =0; j<kNStepQA; j++){
169 fhQA[i][j]=0x0;
170 }
171 }
563113d0 172}
9baeb4ef 173
563113d0 174//____________________________________________________________________
9eeae5d5 175Bool_t AliCFEventClassCuts::IsSelected(TObject* obj) {
563113d0 176 //
177 //Check if the requested cuts are passed
178 //
179
107a3100 180 SelectionBitMap(obj);
563113d0 181
107a3100 182 if (fIsQAOn) FillHistograms(obj,0);
563113d0 183 Bool_t isSelected = kTRUE;
184
107a3100 185 for (UInt_t icut=0; icut<fBitMap->GetNbits();icut++)
186 if(!fBitMap->TestBitNumber(icut)) isSelected = kFALSE;
563113d0 187
107a3100 188 if (!isSelected) return kFALSE ;
189 if (fIsQAOn) FillHistograms(obj,1);
190 return kTRUE;
563113d0 191}
192
193//____________________________________________________________________
107a3100 194void AliCFEventClassCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t *bins)
195{
196 //
197 //setting x-axis bin limits of QA histogram fhQA[index]
198 //
199 for(Int_t i=0;i<kNStepQA;i++){
200 if(!fhQA[index][i]){AliWarning("non-existing histogram!");
201 return;
202 }
203 fhQA[index][i]->GetXaxis()->Set(nbins,bins);
204 }
205}
206//____________________________________________________________________
207void AliCFEventClassCuts::SetHistogramBins(Int_t index, Int_t nbins, Double_t xmin, Double_t xmax)
208{
209 //
210 //setting x-axis bins and range of QA histogram fhQA[index]
211 //
212 for(Int_t i=0;i<kNStepQA;i++){
213 if(!fhQA[index][i]){AliWarning("non-existing histogram!");
214 return;
215 }
216 fhQA[index][i]->GetXaxis()->Set(nbins,xmin,xmax);
217 }
218}
219//____________________________________________________________________
220void AliCFEventClassCuts::SelectionBitMap(TObject* obj) {
563113d0 221 //
222 //cut on trigger type (just pp running trigger types implemented so far)
223 //and on the energy observed in the ZDC. The argument is cast into
224 //an AliVEvent, but has true meaning only for AliESDEvent type objects.
225 //Check if the requested cuts are passed and return a bitmap
226 //
227
228 for(Int_t j=0;j<kNCuts;j++)fBitMap->SetBitNumber(j,kFALSE);
107a3100 229
563113d0 230 AliVEvent* esd = dynamic_cast<AliVEvent *>(obj);
107a3100 231 if (!esd ) return;
563113d0 232
233
234 //now start checking the cuts
235 //first assume the event will be accepted:
236 for(Int_t j=0;j<kNCuts;j++)fBitMap->SetBitNumber(j,kTRUE);
237
238
239 //Check the trigger:
240
241 //look at the Trigger mask in current event
242 TBits *triggerBitMap=new TBits(0);
243 TriggerBitMap(esd,triggerBitMap);
244 //now compare to what was requested as a Trigger:
245 if(fTriggerType.GetNbits()>0)fBitMap->SetBitNumber(0,kFALSE); //trigger required, initialize to false
246 for(Int_t j=0;j<kNTriggers+kNTriggersMB;j++){
247 if(fTriggerType.TestBitNumber(j)){
248 if(!fTriggerAND){
249 if(triggerBitMap->TestBitNumber(j) == fTriggerType.TestBitNumber(j)){
250 fBitMap->SetBitNumber(0,kTRUE);
251
252 break;// @least one requested bit fired, ok
253 }
254 }else{
255 if(!triggerBitMap->TestBitNumber(j)){
256 break;
257 }
258 }
259 }
260 }
261
262 delete triggerBitMap;
263 //Then, cut on the energy observed in the ZDC
264
265 if( esd->GetZDCN1Energy()<fZDCN1EnergyMin || esd->GetZDCN1Energy()>fZDCN1EnergyMax)fBitMap->SetBitNumber(1,kFALSE);
266 if( esd->GetZDCP1Energy()<fZDCP1EnergyMin || esd->GetZDCP1Energy()>fZDCP1EnergyMax)fBitMap->SetBitNumber(2,kFALSE);
267 if( esd->GetZDCN2Energy()<fZDCN2EnergyMin || esd->GetZDCN2Energy()>fZDCN2EnergyMax)fBitMap->SetBitNumber(3,kFALSE);
268 if( esd->GetZDCP2Energy()<fZDCP2EnergyMin || esd->GetZDCP2Energy()>fZDCP2EnergyMax)fBitMap->SetBitNumber(4,kFALSE);
269 if( esd->GetZDCEMEnergy(0)<fZDCEM1EnergyMin || esd->GetZDCEMEnergy(0)>fZDCEM1EnergyMax)fBitMap->SetBitNumber(5,kFALSE);
270 if( esd->GetZDCEMEnergy(1)<fZDCEM2EnergyMin || esd->GetZDCEMEnergy(1)>fZDCEM2EnergyMax)fBitMap->SetBitNumber(6,kFALSE);
107a3100 271 return ;
563113d0 272
273}
9baeb4ef 274
563113d0 275//_____________________________________________________________________________
276Bool_t AliCFEventClassCuts::IsTriggered(AliVEvent* ev, TriggerType trigger) {
277 //
278 //look at the Trigger mask in current event
279 TBits *triggerBitMap=new TBits(0);
280 TriggerBitMap(ev,triggerBitMap);
281 Bool_t isTriggered=kFALSE;
282 if(triggerBitMap->TestBitNumber(trigger))isTriggered=kTRUE;
283 delete triggerBitMap;
284 return isTriggered;
285
286}
9baeb4ef 287
563113d0 288//_____________________________________________________________________________
289void AliCFEventClassCuts::TriggerBitMap(AliVEvent* ev, TBits *bitmapT ) {
290 //
291
292 for(Int_t itrig=0;itrig<kNTriggers+kNTriggersMB;itrig++)bitmapT->SetBitNumber(itrig,kFALSE);
293 if (!ev ) return;
294
295 ULong64_t triggerMask = ev->GetTriggerMask();
296 //run over the different triggers in the mask, and check which bits have fired
297 for(Int_t itrig=0;itrig<kNTriggers;itrig++){
298 bitmapT->SetBitNumber(itrig,kFALSE);
299 if (triggerMask&(0x1 <<itrig)){
300 bitmapT->SetBitNumber(itrig,kTRUE);
301 }
302 }
303
304 //Trigger combinations, Minimum bias triggers
305
306 //MB1 case: (GFO || V0OR) && !BG
307 if((bitmapT->TestBitNumber(5) || (bitmapT->TestBitNumber(0) || bitmapT->TestBitNumber(1))) && !bitmapT->TestBitNumber(2)) bitmapT->SetBitNumber(17,kTRUE);
308
309 //MB2 case: (GFO && V0OR) && !BG
310 if((bitmapT->TestBitNumber(5) && (bitmapT->TestBitNumber(0) || bitmapT->TestBitNumber(1))) && !bitmapT->TestBitNumber(2)) bitmapT->SetBitNumber(18,kTRUE);
311
312 //MB3 case : (GFO && V0AND) && !BG
313 if((bitmapT->TestBitNumber(5) && (bitmapT->TestBitNumber(0) && bitmapT->TestBitNumber(1))) && !bitmapT->TestBitNumber(2)) bitmapT->SetBitNumber(19,kTRUE);
314
315 //MB4 case: (GFO || V0AND) && !BG
316 if((bitmapT->TestBitNumber(5) || (bitmapT->TestBitNumber(0) && bitmapT->TestBitNumber(1))) && !bitmapT->TestBitNumber(2)) bitmapT->SetBitNumber(20,kTRUE);
317
318 //MB5 case:: GFO && !BG
319 if(bitmapT->TestBitNumber(5) && !bitmapT->TestBitNumber(2)) bitmapT->SetBitNumber(21,kTRUE);
320
321 return;
322}
9baeb4ef 323
324//_____________________________________________________________________________
563113d0 325 void AliCFEventClassCuts::DefineHistograms() {
326 //
327 // histograms for cut variables
328 //
329 Int_t color = 2;
330
331 if(!fIsQAOn) {
107a3100 332 AliInfo(Form("No QA histos requested, Please first set the QA flag on!"));
563113d0 333 return;
334 }
335
336 // book QA histograms
4bc0c5f9 337 Char_t str[5];
563113d0 338 for (Int_t i=0; i<kNStepQA; i++) {
4bc0c5f9 339 if (i==0) snprintf(str,5," ");
340 else snprintf(str,5,"_cut");
563113d0 341
107a3100 342 fhQA[kTrigger][i] = new TH1F(Form("%s_TriggerBits%s",GetName(),str), "",23,-0.5,22.5);
343 fhQA[kZDCEnergyN1][i] = new TH1F(Form("%s_ZDC_Energy_N1%s",GetName(),str), "",800,-500,7500);
344 fhQA[kZDCEnergyP1][i] = new TH1F(Form("%s_ZDC_Energy_P1%s",GetName(),str), "",800,-500,7500);
345 fhQA[kZDCEnergyN2][i] = new TH1F(Form("%s_ZDC_Energy_N2%s",GetName(),str), "",800,-500,7500);
346 fhQA[kZDCEnergyP2][i] = new TH1F(Form("%s_ZDC_Energy_P2%s",GetName(),str), "",800,-500,7500);
347 fhQA[kZDCEnergyEM1][i] = new TH1F(Form("%s_ZDC_Energy_EM1%s",GetName(),str), "",800,-500,7500);
348 fhQA[kZDCEnergyEM2][i] = new TH1F(Form("%s_ZDC_Energy_EM2%s",GetName(),str), "",800,-500,7500);
563113d0 349
350 fhQA[kTrigger][i] ->SetXTitle("Trigger Bits");
351 fhQA[kZDCEnergyN1][i] ->SetXTitle("ZDC Energy N1 (GeV)");
352 fhQA[kZDCEnergyP1][i] ->SetXTitle("ZDC Energy P1 (GeV)");
353 fhQA[kZDCEnergyN2][i] ->SetXTitle("ZDC Energy N2 (GeV)");
354 fhQA[kZDCEnergyP2][i] ->SetXTitle("ZDC Energy P2 (GeV)");
355 fhQA[kZDCEnergyEM1][i] ->SetXTitle("ZDC Energy EM1 (GeV)");
356 fhQA[kZDCEnergyEM2][i] ->SetXTitle("ZDC Energy EM2 (GeV)");
357
358 }
359
360 for(Int_t i=0; i<kNCuts; i++) fhQA[i][1]->SetLineColor(color);
361
362}
9baeb4ef 363
364//_____________________________________________________________________________
107a3100 365void AliCFEventClassCuts::FillHistograms(TObject* obj, Bool_t afterCuts)
563113d0 366{
367 //
368 // fill the QA histograms
369 //
370 if(!fIsQAOn) return;
371
372 // cast TObject into VParticle
373 AliVEvent* esd = dynamic_cast<AliVEvent *>(obj);
374 if (!esd ) return ;
375
563113d0 376 //look at the Trigger mask in current event
377 TBits *triggerBitMap=new TBits(0);
378 TriggerBitMap(esd, triggerBitMap);
379
380 //trigger Mask
381 for(Int_t itrig=0;itrig<kNTriggers+kNTriggersMB;itrig++){
382 if(triggerBitMap->TestBitNumber(itrig)){
107a3100 383 fhQA[kTrigger][afterCuts]->Fill(itrig);
563113d0 384 }
385 }
386
387 delete triggerBitMap;
388
389 //ZDC Quantities
107a3100 390 fhQA[kZDCEnergyN1][afterCuts] ->Fill(esd->GetZDCN1Energy());
391 fhQA[kZDCEnergyP1][afterCuts] ->Fill(esd->GetZDCP1Energy());
392 fhQA[kZDCEnergyN2][afterCuts] ->Fill(esd->GetZDCN2Energy());
393 fhQA[kZDCEnergyP2][afterCuts] ->Fill(esd->GetZDCP2Energy());
394 fhQA[kZDCEnergyEM1][afterCuts]->Fill(esd->GetZDCEMEnergy(0));
395 fhQA[kZDCEnergyEM2][afterCuts]->Fill(esd->GetZDCEMEnergy(1));
563113d0 396
397}
9baeb4ef 398
399//_____________________________________________________________________________
107a3100 400void AliCFEventClassCuts::AddQAHistograms(TList *qaList) {
563113d0 401 //
402 // saves the histograms in a TList
403 //
107a3100 404
405 DefineHistograms();
563113d0 406
407 for (Int_t j=0; j<kNStepQA; j++) {
408 for(Int_t i=0; i<kNCuts; i++)
107a3100 409 qaList->Add(fhQA[i][j]);
563113d0 410 }
411}