fixed an omission in the previous commit of this class
[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>
38#include <AliLog.h>
39
40#include "AliDielectronCF.h"
41#include "AliDielectronMC.h"
42
43ClassImp(AliDielectronCF)
44
45AliDielectronCF::AliDielectronCF() :
46 TNamed("DielectronCF","DielectronCF"),
47 fNSteps(0),
48 fNVars(0),
49 fNCuts(0),
e123f993 50 fStepForMCtruth(kFALSE),
51 fStepForNoCutsMCmotherPid(kFALSE),
52 fStepForAfterAllCuts(kTRUE),
53 fStepsForEachCut(kFALSE),
b2a297fa 54 fStepsForCutsIncreasing(kFALSE),
55 fNStepMasks(0),
56 fPdgMother(-1),
57 fCfContainer(0x0)
58{
59 //
60 // Default constructor
61 //
62 for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues; ++i){
63 fVariables[i]=0;
64 }
65
66 for (Int_t i=0; i<kNmaxAddSteps; ++i){
e123f993 67 fNBins[i]=0;
68 fVarLoLimit[i]=0.;
69 fVarUpLimit[i]=0.;
70 fStepMasks[i]=0xFFFFFF;
b2a297fa 71 }
72}
73
74//________________________________________________________________
75AliDielectronCF::AliDielectronCF(const char* name, const char* title) :
76 TNamed(name, title),
77 fNSteps(0),
78 fNVars(0),
79 fNCuts(0),
e123f993 80 fStepForMCtruth(kFALSE),
81 fStepForNoCutsMCmotherPid(kFALSE),
82 fStepForAfterAllCuts(kTRUE),
83 fStepsForEachCut(kFALSE),
b2a297fa 84 fStepsForCutsIncreasing(kFALSE),
85 fNStepMasks(0),
86 fPdgMother(-1),
87 fCfContainer(0x0)
88{
89 //
90 // Named constructor
91 //
92 for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues; ++i){
93 fVariables[i]=0;
94 }
95
96 for (Int_t i=0; i<kNmaxAddSteps; ++i){
e123f993 97 fNBins[i]=0;
98 fVarLoLimit[i]=0.;
99 fVarUpLimit[i]=0.;
100 fStepMasks[i]=0xFFFFFF;
b2a297fa 101 }
102}
103
104//________________________________________________________________
105AliDielectronCF::~AliDielectronCF()
106{
107 //
108 // Destructor
109 //
110
111}
112
113//________________________________________________________________
114void AliDielectronCF::AddVariable(AliDielectronVarManager::ValueTypes type, Int_t nbins, Double_t min, Double_t max)
115{
116 //
117 // Add a variable to the CF configuration
118 //
119 fVariables[fNVars] = (UInt_t)type;
120 fVarLoLimit[fNVars] = min;
121 fVarUpLimit[fNVars] = max;
122 fNBins[fNVars] = nbins;
123 ++fNVars;
124}
125
126//________________________________________________________________
127void AliDielectronCF::InitialiseContainer(const AliAnalysisFilter& filter)
128{
129 //
130 // Initialise container based on the cuts in the analysis filter
131 //
132
133 fNCuts=filter.GetCuts()->GetEntries();
e123f993 134
135 fNSteps=0;
136 if (fStepForMCtruth) ++fNSteps;
137 if (fStepForNoCutsMCmotherPid) ++fNSteps;
138 if (fStepForAfterAllCuts) fNSteps+=2;
b2a297fa 139
e123f993 140 if (fStepsForEachCut&&fNCuts>1) fNSteps+=(2*fNCuts); //one step for each cut + MC truth
78091935 141 if (fStepsForCutsIncreasing&&fNCuts>2) fNSteps+=(2*(fNCuts-2)); //one step for the increasing cuts + MC truth
b2a297fa 142 // e.g. cut2&cut3, cut2&cut3&cut4
143 fNSteps+=(2*fNStepMasks); // cuts for the additional cut masks
144 // create the container
145 fCfContainer = new AliCFContainer(GetName(), GetTitle(), fNSteps, fNVars, fNBins);
146
147 // initialize the variables and their bin limits
148 for (Int_t iVar=0; iVar<fNVars; iVar++) {
149 UInt_t type=fVariables[iVar];
150 Int_t nBins = fNBins[iVar];
151 Double_t loLim = fVarLoLimit[iVar];
152 Double_t upLim = fVarUpLimit[iVar];
153 Double_t *binLim = new Double_t[nBins+1];
154
155 // set the bin limits
156 for(Int_t iBin=0; iBin<=nBins; iBin++) binLim[iBin] = loLim + (upLim-loLim) / nBins*(Double_t)iBin;
157
158 fCfContainer->SetBinLimits(iVar, binLim);
159 fCfContainer->SetVarTitle(iVar, AliDielectronVarManager::GetValueName(type));
160 delete binLim;
161 }
162
163 //=================//
164 // Set step titles //
165 //=================//
166 Int_t step=0;
167
168 //Pure MC truth
e123f993 169 if (fStepForMCtruth){
170 fCfContainer->SetStepTitle(step++,"MC truth");
171 }
b2a297fa 172
173 //before cuts (MC truth)
e123f993 174 if (fStepForNoCutsMCmotherPid){
175 fCfContainer->SetStepTitle(step++,"No cuts (MC mother)");
176 }
b2a297fa 177
178 //After All cuts
e123f993 179 TString cutName;
180 if (fStepForAfterAllCuts){
181 cutName="All Cuts"; //TODO: User GetTitle???
182 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
183 cutName+=" (MC truth)";
184 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut with MC truth
185 }
b2a297fa 186
187 //Steps for each of the cuts
e123f993 188 if (fStepsForEachCut&&fNCuts>1){
b2a297fa 189 for (Int_t iCut=0; iCut<fNCuts;++iCut) {
37e9382d 190 cutName=filter.GetCuts()->At(iCut)->GetName(); //TODO: User GetTitle???
b2a297fa 191 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
e123f993 192 cutName+=" (MC mother)";
b2a297fa 193 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut with MC truth
194 }
195 }
196
197 //Steps for increasing cut match
78091935 198 if (fStepsForCutsIncreasing&&fNCuts>2){
37e9382d 199 cutName=filter.GetCuts()->At(0)->GetName(); //TODO: User GetTitle???
b2a297fa 200 for (Int_t iCut=1; iCut<fNCuts-1;++iCut) {
201 cutName+="&";
202 cutName+=filter.GetCuts()->At(iCut)->GetName();
203 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
e123f993 204 cutName+=" (MC mother)";
b2a297fa 205 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut with MC truth
206 }
207 }
208
209 //Steps of user defined cut combinations
210 for (UInt_t iComb=0; iComb<fNStepMasks; ++iComb){
37e9382d 211 cutName="";
b2a297fa 212 UInt_t mask=fStepMasks[iComb];
213 for (Int_t iCut=0; iCut<fNCuts;++iCut) {
214 if (mask&(1<<iCut)){
215 if (cutName.IsNull()){
216 cutName=filter.GetCuts()->At(iCut)->GetName();
217 }else{
218 cutName+="&";
219 cutName+=filter.GetCuts()->At(iCut)->GetName();
220 }
221 }
222 }
223 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut
e123f993 224 cutName+=" (MC mother)";
b2a297fa 225 fCfContainer->SetStepTitle(step++, cutName.Data()); //Step for the cut with MC truth
226 }
227
228 if (step!=fNSteps) {
229 AliError("Something went wrong in the naming of the steps!!!");
230 }
231}
232
233//________________________________________________________________
234void AliDielectronCF::Fill(UInt_t mask, const TObject *particle)
235{
236 //
237 // Fill the containers
238 //
239
240 Bool_t isMCTruth=kFALSE;
241 if (fPdgMother>=0) isMCTruth=AliDielectronMC::Instance()->IsMotherPdg(particle,fPdgMother);
242
243 Double_t valuesAll[AliDielectronVarManager::kNMaxValues];
244 AliDielectronVarManager::Fill(particle,valuesAll);
245
246 Double_t values[AliDielectronVarManager::kNMaxValues];
247 for (Int_t iVar=0; iVar<fNVars; ++iVar){
248 Int_t var=fVariables[iVar];
249 values[iVar]=valuesAll[var];
250 }
251
252 UInt_t selectedMask=(1<<fNCuts)-1;
253
254 //============//
255 // Fill steps //
256 //============//
257 // step 0 would be full MC truth and is handled in FillMC
e123f993 258 Int_t step=0;
259 if (fStepForMCtruth) ++step;
b2a297fa 260
261 //No cuts (MC truth)
e123f993 262 if (fStepForNoCutsMCmotherPid){
b2a297fa 263 if (isMCTruth) fCfContainer->Fill(values,step);
264 ++step;
b2a297fa 265 }
e123f993 266
267 //All cuts
268 if (fStepForAfterAllCuts){
269 if (mask == selectedMask){
270 fCfContainer->Fill(values,step);
271 ++step;
272 if (isMCTruth) fCfContainer->Fill(values,step);
273 ++step;
274 } else {
275 step+=2;
276 }
277 }
278
b2a297fa 279 //Steps for each of the cuts
e123f993 280 if (fStepsForEachCut&&fNCuts>1){
b2a297fa 281 for (Int_t iCut=0; iCut<fNCuts;++iCut) {
282 if (mask&(1<<iCut)) {
283 fCfContainer->Fill(values,step);
284 ++step;
285 if (isMCTruth) fCfContainer->Fill(values,step);
286 ++step;
287 } else {
288 step+=2;
289 }
290 }
291 }
292
293 //Steps for increasing cut match
78091935 294 if (fStepsForCutsIncreasing&&fNCuts>2){
b2a297fa 295 for (Int_t iCut=1; iCut<fNCuts-1;++iCut) {
296 if (mask&(1<<((iCut+1)-1))) {
297 fCfContainer->Fill(values,step);
298 ++step;
299 if (isMCTruth) fCfContainer->Fill(values,step);
300 ++step;
301 } else {
302 step+=2;
303 }
304 }
305 }
306
307 //Steps of user defined cut combinations
308 for (UInt_t iComb=0; iComb<fNStepMasks; ++iComb){
309 UInt_t userMask=fStepMasks[iComb];
310 if (mask&userMask) {
311 fCfContainer->Fill(values,step);
312 ++step;
313 if (isMCTruth) fCfContainer->Fill(values,step);
314 ++step;
315 } else {
316 step+=2;
317 }
318 }
319
320}
321
322//________________________________________________________________
323void AliDielectronCF::FillMC(const TObject *particle)
324{
325 //
326 // fill MC part of the Container
327 //
e123f993 328 if (!fStepForMCtruth) return;
329
b2a297fa 330 Double_t valuesAll[AliDielectronVarManager::kNMaxValues];
331 AliDielectronVarManager::Fill(particle,valuesAll);
332
333 Double_t values[AliDielectronVarManager::kNMaxValues];
334 for (Int_t iVar=0; iVar<fNVars; ++iVar){
335 Int_t var=fVariables[iVar];
336 values[iVar]=valuesAll[var];
337 }
338 //TODO: temporary solution, set manually the pair type to 1: mixed e+-
339 values[AliDielectronVarManager::kPairType]=1;
340 fCfContainer->Fill(values,0);
341}
342