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