2 /*************************************************************************
3 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////
18 // Add general description //
27 ///////////////////////////////////////////////////////////////////////////
33 #include <AliCFContainer.h>
34 #include <AliCFGridSparse.h>
36 #include "AliDielectronSignalBase.h"
37 #include "AliDielectronSignalFunc.h"
39 #include "AliDielectronSpectrum.h"
41 ClassImp(AliDielectronSpectrum)
43 AliDielectronSpectrum::AliDielectronSpectrum() :
50 fStepSignificance(kFALSE),
57 fOwnerSpectrum(kTRUE),
62 fCurrentPositions(0x0)
65 // Default Constructor
67 fSignalMethods.SetOwner(kFALSE);
70 //______________________________________________
71 AliDielectronSpectrum::AliDielectronSpectrum(const char* name, const char* title) :
78 fStepSignificance(kFALSE),
85 fOwnerSpectrum(kTRUE),
90 fCurrentPositions(0x0)
95 fSignalMethods.SetOwner(kFALSE);
98 //______________________________________________
99 AliDielectronSpectrum::~AliDielectronSpectrum()
102 // Default Destructor
105 if (fNbins) delete [] fNbins;
106 if (fVars) delete [] fVars;
107 if (fCFCorrMatrix) delete fCFCorrMatrix;
108 if ( fOwnerSpectrum && fCFSpectrum ) delete fCFSpectrum;
111 //______________________________________________
112 void AliDielectronSpectrum::Process()
115 // Extract signal and perform correction in the specified bins
120 AliError("Cannot perform signal extraction, no signal container set");
124 if (fSignalMethods.GetEntries()==0){
125 AliWarning("No Signal extraction method specified, using a default one");
126 AliDielectronSignalFunc *func=new AliDielectronSignalFunc("gaus+exp","Gauss for Signal and Exponential background");
127 func->SetDefaults(1);
128 fSignalMethods.Add(func);
129 fSignalMethods.SetOwner();
132 //setup configured variables
133 if (!SetupVariables()) return;
135 //create container for the spectrum
139 AliError("Could not create the Spectrum container");
143 //get efficiency map if correction container is available
144 if (fCFCorrection&&!fCFCorrMatrix){
145 CreateCorrectionMatrix();
148 //loop over all configured bins and extract the signal
149 fCurrentBins=new Int_t[fNvars];
150 fCurrentPositions=new Double_t[fNvars];
151 ExtractSignalInBins();
152 delete [] fCurrentBins;
153 delete [] fCurrentPositions;
154 if (fSignalMethods.IsOwner()) {
155 fSignalMethods.Delete();
156 fSignalMethods.SetOwner(kFALSE);
161 //______________________________________________
162 Bool_t AliDielectronSpectrum::SetupVariables()
165 // Setup the variables arrays
168 TObjArray *arr=fVariables.Tokenize(":");
169 fNvars=arr->GetEntries();
170 fVars=new Int_t[fNvars];
171 fNbins=new Int_t[fNvars];
173 for (Int_t iVar=0; iVar<fNvars; ++iVar){
174 fVars[iVar]=fCFSignal->GetVar(arr->UncheckedAt(iVar)->GetName());
175 if (fVars[iVar]==-1){
176 AliError(Form("Variable '%s' not found in Signal container!",arr->UncheckedAt(iVar)->GetName()));
185 fNbins[iVar]=fCFSignal->GetNBins(fVars[iVar]);
191 //______________________________________________
192 void AliDielectronSpectrum::CreateCFSpectrum()
195 // Create CF container for the spectrum
199 if (fStepSignal) nAddStep+=2;
200 if (fStepSignificance) ++nAddStep;
201 if (fStepSOB) ++nAddStep;
203 Int_t nStep=nAddStep*(fSignalMethods.GetEntries());
204 if (fSignalMethods.GetEntries()>1) nStep+=nAddStep;
206 fCFSpectrum = new AliCFContainer(GetName(), GetTitle(), nStep, fNvars, fNbins);
208 // initialize the variables and their bin limits
209 for (Int_t iVar=0; iVar<fNvars; iVar++) {
210 fCFSpectrum->SetBinLimits(iVar, fCFSignal->GetBinLimits(fVars[iVar]));
211 fCFSpectrum->SetVarTitle(iVar, fCFSignal->GetVarTitle(fVars[iVar]));
216 for (Int_t iMethod=0; iMethod<fSignalMethods.GetEntries(); ++iMethod){
217 TString name(fSignalMethods.UncheckedAt(iMethod)->GetName());
219 fCFSpectrum->SetStepTitle(steps++,(name+" (Siganl)").Data());
220 fCFSpectrum->SetStepTitle(steps++,(name+" (Corrected Siganl)").Data());
222 if (fStepSignificance){
223 fCFSpectrum->SetStepTitle(steps++,(name+" (Significance)").Data());
226 fCFSpectrum->SetStepTitle(steps++,(name+" (S/B)").Data());
230 if (fSignalMethods.GetEntries()>1){
231 fCFSpectrum->SetStepTitle(steps++,"Mean of methods");
232 fCFSpectrum->SetStepTitle(steps++,"Mean of methods (Corrected)");
236 AliError("Something went wrong in the step creation");
242 //______________________________________________
243 void AliDielectronSpectrum::CreateCorrectionMatrix()
246 // Get the correction matrix for the corresponding variables
249 if (!fCFCorrection) return;
251 TObjArray *arr=fVariables.Tokenize(":");
252 Int_t nvars=arr->GetEntries();
253 Int_t *vars=new Int_t[nvars];
255 for (Int_t iVar=0; iVar<fNvars; ++iVar){
256 vars[iVar]=fCFCorrection->GetVar(arr->UncheckedAt(iVar)->GetName());
258 AliError(Form("Variable '%s' not found in Correction container!",arr->UncheckedAt(iVar)->GetName()));
266 fCFCorrMatrix =fCFCorrection->GetGrid(fCorrNom)->Project(nvars,vars,0,0);
267 AliCFGridSparse *hnDeNom=fCFCorrection->GetGrid(fCorrDenom)->Project(nvars,vars,0,0);
268 fCFCorrMatrix->Divide(hnDeNom);
272 //______________________________________________
273 void AliDielectronSpectrum::ExtractSignalInBins(Int_t variable)
276 // recursively loop over bins and extract signal
279 Int_t varPairType=fCFSignal->GetVar("PairType");
280 Int_t varMass=fCFSignal->GetVar("M");
282 for (Int_t ibin=0; ibin<fNbins[variable]; ++ibin){
284 fCFSignal->GetGrid(fSignalStep)->GetGrid()->GetAxis(fVars[variable])->SetRange(bin,bin);
285 fCurrentBins[variable]=bin;
286 fCurrentPositions[variable]=fCFSignal->GetGrid(fSignalStep)->GetBinCenter(fVars[variable],bin);
288 if (variable != fNvars-1) ExtractSignalInBins(variable+1);
290 TObjArray arrPairTypes(10);
291 arrPairTypes.SetOwner();
293 for (Int_t itype=0; itype<3; ++itype){
295 fCFSignal->SetRangeUser(varPairType,itype,itype,fSignalStep);
296 TH1 *h=fCFSignal->Project(varMass,fSignalStep);
298 arrPairTypes.AddAt(h,itype);
300 AliInfo(Form("Processing bin: %d (%.2f)",ibin, fCurrentPositions[variable]));
301 //loop over all signal extraction methods and retrieve signals
302 for (Int_t iMethod=0; iMethod<fSignalMethods.GetEntries(); ++iMethod){
303 AliDielectronSignalBase *signalMethod=(AliDielectronSignalBase*)fSignalMethods.At(iMethod);
304 signalMethod->Process(&arrPairTypes);
305 const TVectorD &val=signalMethod->GetValues();
306 const TVectorD &err=signalMethod->GetErrors();
308 //Fill sparse containers
312 fCFSpectrum->GetGrid(step)->SetElement(fCurrentBins,val(0));
313 fCFSpectrum->GetGrid(step)->SetElementError(fCurrentBins,err(0));
318 Float_t corrFactor = fCFCorrMatrix->GetElement(fCurrentPositions);
319 Float_t corrError = fCFCorrMatrix->GetElementError(fCurrentPositions);
321 Float_t value=val(0)*corrFactor;
322 fCFSpectrum->GetGrid(step)->SetElement(fCurrentBins,value);
323 Float_t error=TMath::Sqrt( (err(0)/val(0))*(err(0)/val(0)) +
324 (corrError/corrFactor)*(corrError/corrFactor)
326 fCFSpectrum->GetGrid(step)->SetElementError(fCurrentBins,error);
327 // printf("corrFactor: %f+-%f\n",value,error);
332 if (fStepSignificance) {
333 fCFSpectrum->GetGrid(step)->SetElement(fCurrentBins,val(2));
334 fCFSpectrum->GetGrid(step)->SetElementError(fCurrentBins,err(2));
339 fCFSpectrum->GetGrid(step)->SetElement(fCurrentBins,val(3));
340 fCFSpectrum->GetGrid(step)->SetElementError(fCurrentBins,err(3));
345 arrPairTypes.Delete();