]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/dielectron/AliDielectronCF.cxx
Leftovers from debugging cleaned up.
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronCF.cxx
CommitLineData
b2a297fa 1/*************************************************************************
2* Copyright(c) 1998-2009, 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///////////////////////////////////////////////////////////////////////////
17// Dielectron Correction framework manager //
18// //
19/*
20
21
22
23
24
25
26
27
28
29*/
30// //
31///////////////////////////////////////////////////////////////////////////
32
33#include <TList.h>
34
35#include <AliCFContainer.h>
36#include <AliAnalysisFilter.h>
37#include <AliAnalysisCuts.h>
6551594b 38#include <AliVParticle.h>
b2a297fa 39#include <AliLog.h>
40
41#include "AliDielectronCF.h"
42#include "AliDielectronMC.h"
6551594b 43#include "AliDielectronPair.h"
b2a297fa 44
45ClassImp(AliDielectronCF)
46
47AliDielectronCF::AliDielectronCF() :
48 TNamed("DielectronCF","DielectronCF"),
49 fNSteps(0),
50 fNVars(0),
6551594b 51 fNVarsLeg(0),
b2a297fa 52 fNCuts(0),
6551594b 53 fValues(0x0),
e123f993 54 fStepForMCtruth(kFALSE),
55 fStepForNoCutsMCmotherPid(kFALSE),
56 fStepForAfterAllCuts(kTRUE),
57 fStepsForEachCut(kFALSE),
b2a297fa 58 fStepsForCutsIncreasing(kFALSE),
572b0139 59 fStepsForSignal(kTRUE),
60 fStepsForBackground(kFALSE),
b2a297fa 61 fNStepMasks(0),
62 fPdgMother(-1),
572b0139 63 fCfContainer(0x0),
64 fHasMC(kFALSE),
65 fNAddSteps(0)
b2a297fa 66{
67 //
68 // Default constructor
69 //
70 for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues; ++i){
71 fVariables[i]=0;
72 }
73
74 for (Int_t i=0; i<kNmaxAddSteps; ++i){
e123f993 75 fNBins[i]=0;
76 fVarLoLimit[i]=0.;
77 fVarUpLimit[i]=0.;
6551594b 78 fNBinsLeg[i]=0;
79 fVarLoLimitLeg[i]=0.;
80 fVarUpLimitLeg[i]=0.;
e123f993 81 fStepMasks[i]=0xFFFFFF;
b2a297fa 82 }
83}
84
85//________________________________________________________________
86AliDielectronCF::AliDielectronCF(const char* name, const char* title) :
87 TNamed(name, title),
88 fNSteps(0),
89 fNVars(0),
6551594b 90 fNVarsLeg(0),
b2a297fa 91 fNCuts(0),
6551594b 92 fValues(0x0),
e123f993 93 fStepForMCtruth(kFALSE),
94 fStepForNoCutsMCmotherPid(kFALSE),
95 fStepForAfterAllCuts(kTRUE),
96 fStepsForEachCut(kFALSE),
b2a297fa 97 fStepsForCutsIncreasing(kFALSE),
572b0139 98 fStepsForSignal(kTRUE),
99 fStepsForBackground(kFALSE),
b2a297fa 100 fNStepMasks(0),
101 fPdgMother(-1),
572b0139 102 fCfContainer(0x0),
103 fHasMC(kFALSE),
104 fNAddSteps(0)
b2a297fa 105{
106 //
107 // Named constructor
108 //
109 for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues; ++i){
110 fVariables[i]=0;
111 }
112
113 for (Int_t i=0; i<kNmaxAddSteps; ++i){
e123f993 114 fNBins[i]=0;
115 fVarLoLimit[i]=0.;
116 fVarUpLimit[i]=0.;
6551594b 117 fNBinsLeg[i]=0;
118 fVarLoLimitLeg[i]=0.;
119 fVarUpLimitLeg[i]=0.;
e123f993 120 fStepMasks[i]=0xFFFFFF;
b2a297fa 121 }
122}
123
124//________________________________________________________________
125AliDielectronCF::~AliDielectronCF()
126{
127 //
128 // Destructor
129 //
6551594b 130 if (fValues) delete [] fValues;
b2a297fa 131}
132
133//________________________________________________________________
6551594b 134void AliDielectronCF::AddVariable(AliDielectronVarManager::ValueTypes type, Int_t nbins, Double_t min, Double_t max, Bool_t leg)
b2a297fa 135{
136 //
137 // Add a variable to the CF configuration
138 //
6551594b 139
140 if (!leg){
141 fVariables[fNVars] = (UInt_t)type;
142 fVarLoLimit[fNVars] = min;
143 fVarUpLimit[fNVars] = max;
144 fNBins[fNVars] = nbins;
145 ++fNVars;
146 } else {
147 fVariablesLeg[fNVarsLeg] = (UInt_t)type;
148 fVarLoLimitLeg[fNVarsLeg] = min;
149 fVarUpLimitLeg[fNVarsLeg] = max;
150 fNBinsLeg[fNVarsLeg] = nbins;
151 ++fNVarsLeg;
152 }
b2a297fa 153}
154
155//________________________________________________________________
156void AliDielectronCF::InitialiseContainer(const AliAnalysisFilter& filter)
157{
158 //
159 // Initialise container based on the cuts in the analysis filter
160 //
161
162 fNCuts=filter.GetCuts()->GetEntries();
e123f993 163
572b0139 164 fHasMC=AliDielectronMC::Instance()->HasMC();
165 fNAddSteps=1;
166 if (fHasMC){
167 if (fStepsForSignal) ++fNAddSteps;
168 if (fStepsForBackground) ++fNAddSteps;
169 } else {
170 //if
171 fStepForMCtruth=kFALSE;
172 fStepForNoCutsMCmotherPid=kFALSE;
173 fStepsForSignal=kFALSE;
174 fStepsForBackground=kFALSE;
175 }
176
e123f993 177 fNSteps=0;
178 if (fStepForMCtruth) ++fNSteps;
179 if (fStepForNoCutsMCmotherPid) ++fNSteps;
572b0139 180 if (fStepForAfterAllCuts) fNSteps+=fNAddSteps;
181
182 if (fStepsForEachCut&&fNCuts>1) fNSteps+=(fNAddSteps*fNCuts); //one step for each cut + Signal (MC)
183 if (fStepsForCutsIncreasing&&fNCuts>2) fNSteps+=(fNAddSteps*(fNCuts-2)); //one step for the increasing cuts + Signal (MC)
b2a297fa 184 // e.g. cut2&cut3, cut2&cut3&cut4
572b0139 185 fNSteps+=(fNAddSteps*fNStepMasks); // cuts for the additional cut masks
b2a297fa 186 // create the container
6551594b 187 Int_t *nbins=new Int_t[fNVars+2*fNVarsLeg];
188 for (Int_t i=0;i<fNVars;++i) nbins[i]=fNBins[i];
189 for (Int_t i=0;i<fNVarsLeg;++i) nbins[i+fNVars]=fNBinsLeg[i];
190 for (Int_t i=0;i<fNVarsLeg;++i) nbins[i+fNVars+fNVarsLeg]=fNBinsLeg[i];
191
192 fCfContainer = new AliCFContainer(GetName(), GetTitle(), fNSteps, fNVars+2*fNVarsLeg, nbins);
193 delete [] nbins;
b2a297fa 194
195 // initialize the variables and their bin limits
196 for (Int_t iVar=0; iVar<fNVars; iVar++) {
197 UInt_t type=fVariables[iVar];
198 Int_t nBins = fNBins[iVar];
199 Double_t loLim = fVarLoLimit[iVar];
200 Double_t upLim = fVarUpLimit[iVar];
201 Double_t *binLim = new Double_t[nBins+1];
202
203 // set the bin limits
204 for(Int_t iBin=0; iBin<=nBins; iBin++) binLim[iBin] = loLim + (upLim-loLim) / nBins*(Double_t)iBin;
205
206 fCfContainer->SetBinLimits(iVar, binLim);
207 fCfContainer->SetVarTitle(iVar, AliDielectronVarManager::GetValueName(type));
6551594b 208 delete [] binLim;
209 }
210
211 // initialize the variables and their bin limits for the Legs
212 for (Int_t iVar=0; iVar<fNVarsLeg; iVar++) {
213 UInt_t type=fVariablesLeg[iVar];
214 Int_t nBins = fNBinsLeg[iVar];
215 Double_t loLim = fVarLoLimitLeg[iVar];
216 Double_t upLim = fVarUpLimitLeg[iVar];
217 Double_t *binLim = new Double_t[nBins+1];
218
219 // set the bin limits
220 for(Int_t iBin=0; iBin<=nBins; iBin++) binLim[iBin] = loLim + (upLim-loLim) / nBins*(Double_t)iBin;
221
222 //Leg1
223 fCfContainer->SetBinLimits(iVar+fNVars, binLim);
224 fCfContainer->SetVarTitle(iVar+fNVars, Form("Leg1_%s",AliDielectronVarManager::GetValueName(type)));
225
226 //Leg2
227 fCfContainer->SetBinLimits(iVar+fNVars+fNVarsLeg, binLim);
228 fCfContainer->SetVarTitle(iVar+fNVars+fNVarsLeg, Form("Leg2_%s",AliDielectronVarManager::GetValueName(type)));
229
230 delete [] binLim;
b2a297fa 231 }
6551594b 232
233 // array for storing values
234 fValues = new Double_t[fNVars+2*fNVarsLeg];
b2a297fa 235
236 //=================//
237 // Set step titles //
238 //=================//
239 Int_t step=0;
240
241 //Pure MC truth
e123f993 242 if (fStepForMCtruth){
8df8e382 243 fCfContainer->SetStepTitle(step++,"MC truth");
e123f993 244 }
b2a297fa 245
246 //before cuts (MC truth)
e123f993 247 if (fStepForNoCutsMCmotherPid){
a655b716 248 fCfContainer->SetStepTitle(step++,"No cuts (Signal)");
e123f993 249 }
b2a297fa 250
e123f993 251 TString cutName;
b2a297fa 252 //Steps for each of the cuts
e123f993 253 if (fStepsForEachCut&&fNCuts>1){
b2a297fa 254 for (Int_t iCut=0; iCut<fNCuts;++iCut) {
37e9382d 255 cutName=filter.GetCuts()->At(iCut)->GetName(); //TODO: User GetTitle???
572b0139 256
b2a297fa 257 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
572b0139 258
259 if (fHasMC){
260 if (fStepsForSignal)
261 fCfContainer->SetStepTitle(step++, (cutName+" (Signal)").Data()); //Step for the cut with MC truth
262 if (fStepsForBackground)
263 fCfContainer->SetStepTitle(step++, (cutName+" (Background)").Data()); //Step for the cut with MC truth
264 }
b2a297fa 265 }
266 }
267
268 //Steps for increasing cut match
78091935 269 if (fStepsForCutsIncreasing&&fNCuts>2){
37e9382d 270 cutName=filter.GetCuts()->At(0)->GetName(); //TODO: User GetTitle???
b2a297fa 271 for (Int_t iCut=1; iCut<fNCuts-1;++iCut) {
272 cutName+="&";
273 cutName+=filter.GetCuts()->At(iCut)->GetName();
572b0139 274
b2a297fa 275 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
572b0139 276
277 if (fHasMC){
278 if (fStepsForSignal)
279 fCfContainer->SetStepTitle(step++, (cutName+" (Signal)").Data()); //Step for the cut with MC truth
280 if (fStepsForBackground)
281 fCfContainer->SetStepTitle(step++, (cutName+" (Background)").Data()); //Step for the cut with MC truth
282 }
b2a297fa 283 }
284 }
285
286 //Steps of user defined cut combinations
287 for (UInt_t iComb=0; iComb<fNStepMasks; ++iComb){
37e9382d 288 cutName="";
b2a297fa 289 UInt_t mask=fStepMasks[iComb];
290 for (Int_t iCut=0; iCut<fNCuts;++iCut) {
291 if (mask&(1<<iCut)){
292 if (cutName.IsNull()){
293 cutName=filter.GetCuts()->At(iCut)->GetName();
294 }else{
295 cutName+="&";
296 cutName+=filter.GetCuts()->At(iCut)->GetName();
297 }
298 }
299 }
572b0139 300
b2a297fa 301 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
572b0139 302
303 if (fHasMC){
304 if (fStepsForSignal)
305 fCfContainer->SetStepTitle(step++, (cutName+" (Signal)").Data()); //Step for the cut with MC truth
306 if (fStepsForBackground)
307 fCfContainer->SetStepTitle(step++, (cutName+" (Background)").Data()); //Step for the cut with MC truth
308 }
309 }
310
311 //After All cuts
312 if (fStepForAfterAllCuts){
313 cutName="No pair cuts";
314 if (filter.GetCuts()->At(0)){
315 cutName=filter.GetCuts()->At(0)->GetName(); //TODO: User GetTitle???
316 for (Int_t iCut=1; iCut<fNCuts;++iCut) {
317 cutName+="&";
318 cutName+=filter.GetCuts()->At(iCut)->GetName();
319 }
572b0139 320 }
8df8e382 321 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
572b0139 322 if (fHasMC){
323 if (fStepsForSignal)
324 fCfContainer->SetStepTitle(step++, (cutName+" (Signal)").Data()); //Step for the cut with MC truth
325 if (fStepsForBackground)
326 fCfContainer->SetStepTitle(step++, (cutName+" (Background)").Data()); //Step for the cut with MC truth
327 }
b2a297fa 328 }
329
330 if (step!=fNSteps) {
8df8e382 331 AliError(Form("Something went wrong in the naming of the steps!!! (%d != %d)",step,fNSteps));
b2a297fa 332 }
333}
334
335//________________________________________________________________
6551594b 336void AliDielectronCF::Fill(UInt_t mask, const AliDielectronPair *particle)
b2a297fa 337{
338 //
339 // Fill the containers
340 //
341
342 Bool_t isMCTruth=kFALSE;
572b0139 343 if (fHasMC) isMCTruth=AliDielectronMC::Instance()->IsMotherPdg(particle,fPdgMother);
b2a297fa 344
6551594b 345 Double_t valuesPair[AliDielectronVarManager::kNMaxValues];
346 AliDielectronVarManager::Fill(particle,valuesPair);
b2a297fa 347
b2a297fa 348 for (Int_t iVar=0; iVar<fNVars; ++iVar){
349 Int_t var=fVariables[iVar];
6551594b 350 fValues[iVar]=valuesPair[var];
b2a297fa 351 }
352
6551594b 353 if (fNVarsLeg>0){
354 Double_t valuesLeg1[AliDielectronVarManager::kNMaxValues];
355 AliDielectronVarManager::Fill(particle->GetFirstDaughter(),valuesLeg1);
356 Double_t valuesLeg2[AliDielectronVarManager::kNMaxValues];
357 AliDielectronVarManager::Fill(particle->GetSecondDaughter(),valuesLeg2);
358
359 for (Int_t iVar=0; iVar<fNVarsLeg; ++iVar){
360 Int_t var=fVariablesLeg[iVar];
361 fValues[iVar+fNVars]=valuesLeg1[var];
362 fValues[iVar+fNVars+fNVarsLeg]=valuesLeg2[var];
363 }
364 }
365
b2a297fa 366 UInt_t selectedMask=(1<<fNCuts)-1;
367
368 //============//
369 // Fill steps //
370 //============//
371 // step 0 would be full MC truth and is handled in FillMC
e123f993 372 Int_t step=0;
373 if (fStepForMCtruth) ++step;
8df8e382 374
b2a297fa 375 //No cuts (MC truth)
e123f993 376 if (fStepForNoCutsMCmotherPid){
6551594b 377 if (isMCTruth) fCfContainer->Fill(fValues,step);
b2a297fa 378 ++step;
b2a297fa 379 }
e123f993 380
b2a297fa 381 //Steps for each of the cuts
e123f993 382 if (fStepsForEachCut&&fNCuts>1){
b2a297fa 383 for (Int_t iCut=0; iCut<fNCuts;++iCut) {
384 if (mask&(1<<iCut)) {
6551594b 385 fCfContainer->Fill(fValues,step);
b2a297fa 386 ++step;
572b0139 387
388 if (fHasMC){
389 if ( fStepsForSignal){
390 if (isMCTruth) fCfContainer->Fill(fValues,step);
391 ++step;
392 }
393 if ( fStepsForBackground ){
394 if (!isMCTruth) fCfContainer->Fill(fValues,step);
395 ++step;
396 }
397 }
b2a297fa 398 } else {
572b0139 399 step+=fNAddSteps;
b2a297fa 400 }
401 }
402 }
403
404 //Steps for increasing cut match
78091935 405 if (fStepsForCutsIncreasing&&fNCuts>2){
b2a297fa 406 for (Int_t iCut=1; iCut<fNCuts-1;++iCut) {
407 if (mask&(1<<((iCut+1)-1))) {
6551594b 408 fCfContainer->Fill(fValues,step);
b2a297fa 409 ++step;
572b0139 410
411 if (fHasMC){
412 if ( fStepsForSignal){
413 if (isMCTruth) fCfContainer->Fill(fValues,step);
414 ++step;
415 }
416 if ( fStepsForBackground ){
417 if (!isMCTruth) fCfContainer->Fill(fValues,step);
418 ++step;
419 }
420 }
b2a297fa 421 } else {
572b0139 422 step+=fNAddSteps;
b2a297fa 423 }
424 }
425 }
426
427 //Steps of user defined cut combinations
428 for (UInt_t iComb=0; iComb<fNStepMasks; ++iComb){
429 UInt_t userMask=fStepMasks[iComb];
430 if (mask&userMask) {
6551594b 431 fCfContainer->Fill(fValues,step);
b2a297fa 432 ++step;
572b0139 433
434 if (fHasMC){
435 if ( fStepsForSignal){
436 if (isMCTruth) fCfContainer->Fill(fValues,step);
437 ++step;
438 }
439 if ( fStepsForBackground ){
440 if (!isMCTruth) fCfContainer->Fill(fValues,step);
441 ++step;
442 }
443 }
444 } else {
445 step+=fNAddSteps;
446 }
447 }
448
449 //All cuts
450 if (fStepForAfterAllCuts){
451 if (mask == selectedMask){
452 fCfContainer->Fill(fValues,step);
b2a297fa 453 ++step;
572b0139 454
455 if (fHasMC){
456 if ( fStepsForSignal){
457 if (isMCTruth) fCfContainer->Fill(fValues,step);
458 ++step;
459 }
460 if ( fStepsForBackground ){
461 if (!isMCTruth) fCfContainer->Fill(fValues,step);
462 ++step;
463 }
464 }
b2a297fa 465 } else {
572b0139 466 step+=fNAddSteps;
b2a297fa 467 }
468 }
469
572b0139 470 if (step!=fNSteps) {
471 AliError("Something went wrong in the step filling!!!");
472 }
473
b2a297fa 474}
475
476//________________________________________________________________
477void AliDielectronCF::FillMC(const TObject *particle)
478{
479 //
480 // fill MC part of the Container
481 //
e123f993 482 if (!fStepForMCtruth) return;
483
6551594b 484 Double_t valuesPair[AliDielectronVarManager::kNMaxValues];
485 AliDielectronVarManager::Fill(particle,valuesPair);
8df8e382 486
487 AliVParticle *d1=0x0;
488 AliVParticle *d2=0x0;
489 AliDielectronMC::Instance()->GetDaughters(particle,d1,d2);
490
491 valuesPair[AliDielectronVarManager::kThetaHE]=AliDielectronPair::ThetaPhiCM(d1,d2,kTRUE,kTRUE);
492 valuesPair[AliDielectronVarManager::kPhiHE]=AliDielectronPair::ThetaPhiCM(d1,d2,kTRUE,kFALSE);
493 valuesPair[AliDielectronVarManager::kThetaCS]=AliDielectronPair::ThetaPhiCM(d1,d2,kFALSE,kTRUE);
494 valuesPair[AliDielectronVarManager::kPhiCS]=AliDielectronPair::ThetaPhiCM(d1,d2,kFALSE,kFALSE);
6551594b 495
a655b716 496 //TODO: temporary solution, set manually the pair type to 1: unlikesign SE
6551594b 497 valuesPair[AliDielectronVarManager::kPairType]=1;
b2a297fa 498
b2a297fa 499 for (Int_t iVar=0; iVar<fNVars; ++iVar){
500 Int_t var=fVariables[iVar];
6551594b 501 fValues[iVar]=valuesPair[var];
b2a297fa 502 }
6551594b 503
504 if (fNVarsLeg>0){
6551594b 505 Double_t valuesLeg1[AliDielectronVarManager::kNMaxValues];
6551594b 506 Double_t valuesLeg2[AliDielectronVarManager::kNMaxValues];
a655b716 507 if (d1->Pt()>d2->Pt()){
508 AliDielectronVarManager::Fill(d1,valuesLeg1);
509 AliDielectronVarManager::Fill(d2,valuesLeg2);
510 } else {
511 AliDielectronVarManager::Fill(d2,valuesLeg1);
512 AliDielectronVarManager::Fill(d1,valuesLeg2);
513 }
6551594b 514
515 for (Int_t iVar=0; iVar<fNVarsLeg; ++iVar){
516 Int_t var=fVariablesLeg[iVar];
517 fValues[iVar+fNVars]=valuesLeg1[var];
518 fValues[iVar+fNVars+fNVarsLeg]=valuesLeg2[var];
519 }
520 }
521
522 fCfContainer->Fill(fValues,0);
b2a297fa 523}
524