1 /*************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 // Class to perform pt-spectra (and ptMin-spectra) extraction of mothers //
17 // particles starting from measured pt-spectra of daughter particles //
18 // that come from inclusive decays. //
19 // E.g.: B->J/psi+X , B->e+X, B->D0+X, etc. //
21 // In order to use this class, one first has to run a simulation //
22 // (only kinematics) of the decay channel under study. The analysis //
23 // can be runned using the class AliAnalysisTaskPtMothFromPtDaugh //
24 // which loops on events to create a TNtupla that stores just //
25 // kinematics informations for mothers and daughters of the decay //
26 // under study (this is made in order to speed up). //
28 // Therefore the standard inputs of this class are: //
29 // (1) The TNtupla (created by the task using a TChain of galice.root) //
30 // (2) pT-spectrum of the daughter particles //
32 // Output would be the pT (and pTMin) spectrum of the mother, based //
33 // on the correction factors computed from the Kinematics.root files //
36 // Authors: Giuseppe E. Bruno & Fiorella Fionda //
37 // (Giuseppe.Bruno@ba.infn.it) (Fiorella.Fionda@ba.infn.it) //
38 ////////////////////////////////////////////////////////////////////////////
43 #include "TParticle.h"
46 #include "AliPtMothFromPtDaugh.h"
50 ClassImp(AliPtMothFromPtDaugh)
51 //________________________________________________________________
52 AliPtMothFromPtDaugh::AliPtMothFromPtDaugh() :
53 TNamed("AliPtMoth","AliPtMoth"),
59 fHistoPtDaughter(0x0),
61 fHistoPtMinMothers(0x0),
69 fAnalysisMode(kUserAnalysis)
72 // Default constructor
76 //________________________________________________________________
77 AliPtMothFromPtDaugh::AliPtMothFromPtDaugh(const char* name, const char* title) :
84 fHistoPtDaughter(0x0),
86 fHistoPtMinMothers(0x0),
94 fAnalysisMode(kUserAnalysis)
101 //________________________________________________________________
102 AliPtMothFromPtDaugh::~AliPtMothFromPtDaugh()
105 // Default destructor
107 if(fDecayKine) {delete fDecayKine;}
109 if(fMothers) {delete fMothers;}
111 if(fHistoPtMothers) { delete fHistoPtMothers; }
113 if(fHistoPtMinMothers) { delete fHistoPtMinMothers;}
114 fHistoPtMinMothers=0;
115 if(fHistoPtDaughter) { delete fHistoPtDaughter; fHistoPtDaughter=0;}
118 //______________________________________________________________________________________
119 AliPtMothFromPtDaugh::AliPtMothFromPtDaugh(const AliPtMothFromPtDaugh& extraction) :
128 fHistoPtMinMothers(0),
130 fDaughter(extraction.fDaughter),
131 fyMothMax(extraction.fyMothMax),
132 fyMothMin(extraction.fyMothMin),
133 fyDaughMax(extraction.fyDaughMax),
134 fyDaughMin(extraction.fyDaughMin),
135 fUseEta(extraction.fUseEta),
136 fAnalysisMode(extraction.fAnalysisMode)
139 if(extraction.fHistoPtDaughter) fHistoPtDaughter =(TH1F*)extraction.fHistoPtDaughter->Clone("fHistoPtDaughter_copy");
140 if(extraction.fHistoPtMothers) fHistoPtMothers = (TH1F*)extraction.fHistoPtMothers->Clone("fHistoPtMothers_copy");
141 if(extraction.fHistoPtMinMothers) fHistoPtMinMothers = (TH1F*)extraction.fHistoPtMinMothers->Clone("fHistoPtMinMothers_copy");
144 fWij = new Double_t*[2*(fHistoPtMothers->GetNbinsX())];
145 for(Int_t i=0;i<2*(fHistoPtMothers->GetNbinsX());i++) *(fWij+i)=new Double_t[fHistoPtDaughter->GetNbinsX()];
146 for(Int_t i=0;i<2*(fHistoPtMothers->GetNbinsX());i++){
147 for(Int_t j=0;j<fHistoPtDaughter->GetNbinsX();j++){
148 fWij[i][j]=extraction.fWij[i][j];
154 fFi=new Double_t[2*(fHistoPtMothers->GetNbinsX())];
155 for(Int_t i=0;i<2*(fHistoPtMothers->GetNbinsX());i++) fFi[i]=extraction.fFi[i];
158 if(extraction.fWijMin){
159 fWijMin = new Double_t*[2*(fHistoPtMinMothers->GetNbinsX())];
160 for(Int_t i=0;i<2*(fHistoPtMinMothers->GetNbinsX());i++) *(fWijMin+i)=new Double_t[fHistoPtDaughter->GetNbinsX()];
161 for(Int_t i=0;i<2*(fHistoPtMinMothers->GetNbinsX());i++){
162 for(Int_t j=0;j<fHistoPtDaughter->GetNbinsX();j++){
163 fWijMin[i][j]=extraction.fWijMin[i][j];
168 if(extraction.fFiMin){
169 fFiMin=new Double_t[2*(fHistoPtMinMothers->GetNbinsX())];
170 for(Int_t i=0;i<2*(fHistoPtMinMothers->GetNbinsX());i++) fFiMin[i]=extraction.fFiMin[i];
173 if(extraction.fDecayKine) fDecayKine = (TNtuple*)extraction.fDecayKine->CloneTree();
175 if(extraction.fMothers) fMothers = new TArrayI(*(extraction.fMothers));
177 extraction.Copy(*this);
180 //______________________________________________________________________________________
181 AliPtMothFromPtDaugh& AliPtMothFromPtDaugh::operator=(const AliPtMothFromPtDaugh &extraction)
183 // operator assignment
184 if (this!=&extraction) {
185 this->~AliPtMothFromPtDaugh();
186 new(this) AliPtMothFromPtDaugh(extraction);
191 //______________________________________________________________________________________
192 Bool_t AliPtMothFromPtDaugh::CreateWeights()
194 // Set mothers and daughters pdg codes if not
195 // Put a control if mothers histograms binning-size, rapidity (or pseudoapidity) range
196 // are setting. Read daughter histogram (histName) from the file (pathFileName)
197 // Initialize dimensions for correction factors
200 if(!fMothers) {AliError("Set pdg codes of mothers by SetPdgMothers!\n"); return kFALSE;}
201 if(!fDaughter) {AliError("Set pdg code of daughter by SetPdgDaughter!\n"); return kFALSE;}
202 if(!fHistoPtDaughter) { AliError("Daughter histogram doesn't exist! \n"); return kFALSE;}
204 //Set Rapidity or Pseudorapidity range for mothers if not
205 if(!fyMothMax || !fyMothMin ){ AliError("Set rapidity range or pseudoRapidity range for mothers: use SetYmothers(ymin,ymax) or SetEtaMothers(etamin,etamax)"); return kFALSE;}
206 if(!fyDaughMax || !fyDaughMin){ AliError("Set rapidity range or pseudoRapidity range for daughters:use SetYdaughters(ymin,ymax) or SetEtaDaughters(etamin,etamax)"); return kFALSE;}
207 if(!fHistoPtMothers) {AliError("Call method SetBinsPtMoth to set pT-histogram "); return kFALSE;}
208 if(!fHistoPtMinMothers){AliError("Call method SetBinsPtMinMoth to set pTmin-histogram "); return kFALSE;}
210 Int_t nbinsM=(fHistoPtMothers->GetNbinsX()+2);
211 Int_t nbinsD=(fHistoPtDaughter->GetNbinsX()+2);
212 Int_t nbinsMmin=(fHistoPtMinMothers->GetNbinsX()+2);
214 //Create pointers for weights to reconstruct daughter and mothers pT-spectra
215 fWij=new Double_t*[2*nbinsM];
216 for(Int_t i=0;i<2*nbinsM;i++)
217 {*(fWij+i)=new Double_t[nbinsD];}
218 fFi=new Double_t[2*nbinsM];
220 fWijMin=new Double_t*[2*nbinsMmin];
221 for(Int_t i=0;i<2*nbinsMmin;i++)
222 {*(fWijMin+i)=new Double_t[nbinsD];}
223 fFiMin=new Double_t[2*nbinsMmin];
224 AliInfo(Form("Pt-mothers distribution: pt_min = %f pt_max=%f n_bins=%d \n",
225 fHistoPtMothers->GetBinLowEdge(1),fHistoPtMothers->GetBinLowEdge(nbinsM-1),nbinsM-2));
226 AliInfo(Form("PtMinimum-mothers distribution: pt_min = %f pt_max=%f n_bins=%d \n",
227 fHistoPtMinMothers->GetBinLowEdge(1),fHistoPtMinMothers->GetBinLowEdge(nbinsMmin-1),nbinsMmin-2));
228 AliInfo(Form("Pt-daughters distribution: pt_min = %f pt_max=%f n_bins=%d \n",
229 fHistoPtDaughter->GetBinLowEdge(1),fHistoPtDaughter->GetBinLowEdge(nbinsD-1),nbinsD-2));
233 //______________________________________________________________________________________
234 void AliPtMothFromPtDaugh::DeleteWeights()
236 //delete correction factors
237 //delete histogram of daughters
238 if(!fHistoPtMothers || !fHistoPtMinMothers) {AliError("Mothers histograms don't exist! Cannot delete correction factors"); return;}
239 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
240 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
242 for(Int_t i=0; i<(2*nbinsM); i++) delete fWij[i];
243 delete [] fWij; fWij=0;
245 if(fFi) { delete fFi; fFi=0;}
247 for(Int_t i=0; i<(2*nbinsMmin); i++) delete fWijMin[i];
248 delete [] fWijMin; fWijMin=0;
250 if(fFiMin) { delete fFiMin; fFiMin=0;}
255 //______________________________________________________________________________________
256 Bool_t AliPtMothFromPtDaugh::ReadHistoPtDaught(const TH1F *hist)
258 //Initialize daughter histograms with hist
259 if(!hist) {AliError("Set correct histograms of daughter! It doesn't exist!\n"); return kFALSE;}
260 if(fHistoPtDaughter) delete fHistoPtDaughter;
261 fHistoPtDaughter = (TH1F*)hist->Clone();
265 //______________________________________________________________________________________
266 Double_t* AliPtMothFromPtDaugh::SetBinsSize(Double_t ptmin, Double_t ptmax,Int_t nbins,Double_t alpha)
268 // return a pointer of double which contains the binning size for (mothers) histograms:
269 // alpha have to be > 0 and:
270 // alpha = 1 equal binning size
271 // alpha < 1 increasing "
272 // alpha > 1 decreasing "
273 if(ptmin<0 || ptmax<0 || nbins<=0 || alpha<=0) {AliError("Set correct bin-size: ptmin>=0, ptmax>=0, nbins>0, alpha>0! \n"); return 0;}
274 Double_t *edgebin = new Double_t[nbins+1];
275 Double_t ptmin1=TMath::Power(ptmin,alpha);
276 Double_t ptmax1=TMath::Power(ptmax,alpha);
277 Double_t size=(ptmax1-ptmin1)/nbins;
278 for(Int_t i=0;i<nbins+1;i++) *(edgebin+i)=TMath::Power((ptmin1+i*size),(Double_t)1/alpha);
282 //______________________________________________________________________________________
283 void AliPtMothFromPtDaugh::SetBinsPtMoth(Double_t ptmin, Double_t ptmax,Int_t nbins,Double_t alpha)
285 // Set bin size for pt-spectrum of mothers using SetBinsSize:
286 // alpha have to be > 0 and:
287 // alpha = 1 equal binning size
288 // alpha < 1 increasing "
289 // alpha > 1 decreasing "
290 Double_t* edges = SetBinsSize(ptmin,ptmax,nbins,alpha);
291 SetBinsPtMoth(nbins,edges);
296 //______________________________________________________________________________________
297 void AliPtMothFromPtDaugh::SetBinsPtMoth(Int_t nbins,Double_t *edgeBins)
299 //set bin size given by the pointer edgeBins for pt-spectrum of mothers:
300 //the dimension of the pointer edgeBins is nbins+1 and the points
301 //has to be written in increasing order
302 if(nbins<0) {AliError("Numbers of bins should be > 0 !\n"); return;}
303 if(fHistoPtMothers) {delete fHistoPtMothers; fHistoPtMothers=0;}
304 fHistoPtMothers=new TH1F("fHistoPtMothers","Reconstructed p_{T}(Mothers)-spectrum",nbins,edgeBins);
308 //______________________________________________________________________________________
309 void AliPtMothFromPtDaugh::SetBinsPtMinMoth(Int_t nbins,Double_t *edgeBins)
311 //set bin size given by the pointer edgeBins for ptMin-spectrum of mothers:
312 //the dimension of the pointer edgeBins is nbins+1 and the points
313 //has to be written in increasing order
314 if(nbins<0) {AliError("Numbers of bins should be > 0 !\n"); return;}
315 if(fHistoPtMinMothers) {delete fHistoPtMinMothers; fHistoPtMinMothers=0;}
316 fHistoPtMinMothers = new TH1F("fHistoPtMinMothers","Reconstructed p_{T}^{MIN}(Mothers)-spectrum",nbins,edgeBins);
320 //______________________________________________________________________________________
321 void AliPtMothFromPtDaugh::SetBinsPtMinMoth(Double_t ptmin, Double_t ptmax,Int_t nbins,Double_t alpha)
323 // Set bin size for ptMin-spectrum of mothers using SetBinsSize:
324 // alpha have to be > 0 and:
325 // alpha = 1 equal binning size
326 // alpha < 1 increasing "
327 // alpha > 1 decreasing "
328 Double_t* edges = SetBinsSize(ptmin,ptmax,nbins,alpha);
329 SetBinsPtMinMoth(nbins,edges);
334 //______________________________________________________________________________________
335 void AliPtMothFromPtDaugh::SetPdgMothersPrivate(Int_t n_mothers,Int_t *pdgM)
337 // Set pdg codes of mothers given by the pointer pdgM for the analysis.
338 // This is a private method.
339 if(fMothers) { delete fMothers; fMothers = 0; }
340 fMothers = new TArrayI(n_mothers,pdgM);
343 //______________________________________________________________________________________
344 void AliPtMothFromPtDaugh::SetPdgMothers(Int_t n_mothers,Int_t *pdgM)
346 // Set user pdg codes of mothers: first check
347 // that the kUserAnalysis is the selected Analysis_mode.
348 // If not print out a message of error.
349 if(fAnalysisMode!=kUserAnalysis) {
350 AliError("Nothing done: set the mode to kUserAnalysis first");
353 //Set pdg codes of mothers given by the pointer pdgM for the analysis
354 SetPdgMothersPrivate(n_mothers,pdgM);
358 //______________________________________________________________________________________
359 void AliPtMothFromPtDaugh::SetBeautyMothers()
361 // Set pdg codes of beauty particles:
362 // B-mesons (1-24) B-barions (25-59)
363 Int_t pdgBeauty[]={511,521,513,523,10511,10521,10513,10523,20513,
364 20523,515,525,531,10531,533,10533,205433,535,541,10541,543,10543,
365 20543,545,5122,5112,5212,5222,5114,5214,5224,5132,5232,5312,5322,
366 5314,5324,5332,5334,5142,5242,5412,5422,5414,5424,5342,5432,5434,
367 5442,5444,5512,5522,5514,5524,5532,5534,5542,5544,5554};
368 Int_t *pdgB=new Int_t[59];
369 for(Int_t i=0;i<59;i++) pdgB[i]=pdgBeauty[i];
370 SetPdgMothersPrivate(59,pdgB);
373 //______________________________________________________________________________________
374 void AliPtMothFromPtDaugh::InitDefaultAnalysis()
376 // Set mothers and daughter pdg codes depending from the selected analysis.
377 // case kUserAnalysis: mothers and daughter are set by user (nothing to be done)
378 // case kBtoJPSI: inclusive B-> J/Psi + X channels
379 // case kBtoEle: inclusive B-> e + X channels
380 // case kBtoMuon: inclusive B-> mu + X channels
381 // case kBtoD0: inclusive B-> D0 + X channels
383 switch(fAnalysisMode)
406 //______________________________________________________________________________________
407 Double_t* AliPtMothFromPtDaugh::GetBinsSize(const TH1F *hist,Int_t &n) const
409 // return the binning size of the histogram hist
410 // n return the number of bins
411 Double_t* edges = (Double_t*)hist->GetXaxis()->GetXbins()->GetArray();
416 //______________________________________________________________________________________
417 Bool_t AliPtMothFromPtDaugh::GetEtaMothers(Double_t &etaMin, Double_t &etaMax) const
419 // method to get the bounds of the pseudorapidity range
420 // for mothers. Return kTRUE if pseudorapidity is used and put
421 // pseudorapidity edges in etaMin and etaMax
423 if(fUseEta == kFALSE){
424 AliError("You are using RAPIDITY range! \n");
434 //______________________________________________________________________________________
435 Bool_t AliPtMothFromPtDaugh::GetEtaDaughter(Double_t &etaMin, Double_t &etaMax) const
437 // method to get the bounds of the pseudorapidity range
438 // for daughters. Return kTRUE if pseudorapidity is used and put
439 // pseudorapidity edges in etaMin and etaMax
441 if(fUseEta == kFALSE){
442 AliError("You are using RAPIDITY range! \n");
452 //______________________________________________________________________________________
453 Bool_t AliPtMothFromPtDaugh::GetYMothers(Double_t &yMin, Double_t &yMax) const
455 // method to get the bounds of the rapidity range
456 // for mothers. Return kTRUE if rapidity is used and put
457 // rapidity edges in yMin and yMax
459 if(fUseEta == kTRUE){
460 AliError("You are using PSEUDORAPIDITY range! \n");
470 //______________________________________________________________________________________
471 Bool_t AliPtMothFromPtDaugh::GetYDaughter(Double_t &yMin, Double_t &yMax) const
473 // method to get the bounds of the rapidity range
474 // for daughters. Return kTRUE if rapidity is used and put
475 // rapidity edges in yMin and yMax
477 if(fUseEta == kTRUE){
478 AliError("You are using PSEUDORAPIDITY range! \n");
489 //______________________________________________________________________________________
490 void AliPtMothFromPtDaugh::SetPdgDaugh(Int_t pdgD)
492 // Set pdg code for daughter particle. Check
493 // that the kUserAnalysis is the selected Analysis_mode.
494 // If not print out a message of error.
495 switch(fAnalysisMode)
501 if(pdgD!= 443) {AliError("Nothing done: first change AnalysisMode to kUserAnalysis");}
502 else {fDaughter = pdgD;}
505 if(pdgD!= 11) {AliError("Nothing done: first change AnalysisMode to kUserAnalysis");}
506 else {fDaughter = pdgD;}
509 if(pdgD!= 13) {AliError("Nothing done: first change AnalysisMode to kUserAnalysis");}
510 else {fDaughter = pdgD;}
513 if(pdgD!= 421) {AliError("Nothing done: first change AnalysisMode to kUserAnalysis");}
514 else {fDaughter = pdgD;}
520 //______________________________________________________________________________________
521 Int_t* AliPtMothFromPtDaugh::GetPdgMothers(Int_t &n_mothers) const
523 // return the pointer to the array of pdg codes of mothers particles
524 // if it exist. Put its dimension in n_mothers
526 if(!fMothers) {AliError("Mothers pdg are not defined! \n"); return 0x0;}
527 n_mothers = fMothers->GetSize();
528 return fMothers->GetArray();
531 //______________________________________________________________________________________
532 Double_t AliPtMothFromPtDaugh::GetW(Int_t i,Int_t j) const
534 // Return value of correction factors Wij at the position i (pt-mothers bin index)-
535 // j (pt-daughter bin index). Bin 0 is the underflow, bin nbins+1 the overflow.
536 // If Wij don't exist or the indices i or j are out of the variability range return 0
538 if(!fWij) {AliError("Correction factors Wij are not been evaluated yet!\n"); return 0;}
539 if(!fHistoPtMothers) {AliError("mothers pt-histogram doesn't exist!\n"); return 0;}
540 if(!fHistoPtDaughter) {AliError("daughters pt-histogram doesn't exist!\n"); return 0;}
541 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
542 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
543 if(i<0 || i>nbinsM-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow ",0,nbinsM-1,nbinsM-1)); return 0;}
545 if(j<0 || j>nbinsD-1) {AliError(Form("Index j out of range: %d =< j =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsD-1,nbinsD-1)); return 0;}
549 //______________________________________________________________________________________
550 Double_t AliPtMothFromPtDaugh::GetStatErrW(Int_t i,Int_t j) const
552 // Return value of statistical error on correction factors Wij at the position
553 // i (pt-mothers bin index)- j (pt-daughter bin index). Bin 0 is the underflow,
554 // bin nbins+1 the overflow. If Wij don't exist or the indices i or j are out of the
555 // variability range return 0
557 if(!fHistoPtMothers) {AliError("mothers pt-histogram doesn't exist!\n"); return 0;}
558 if(!fHistoPtDaughter) {AliError("daughters pt-histogram doesn't exist!\n"); return 0;}
560 if(!fWij) {AliError("Correction factors Wij are not been evaluated yet!\n"); return 0;}
561 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
562 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
563 if(i<0 || i>nbinsM-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsM-1,nbinsM-1)); return 0;}
564 if(j<0 || j>nbinsD-1) {AliError(Form("Index j out of range: %d =< j =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsD-1,nbinsD-1)); return 0;}
565 return fWij[i+nbinsM][j];
568 //______________________________________________________________________________________
569 Double_t AliPtMothFromPtDaugh::GetF(Int_t i) const
571 // Return value of correction factors Fi at the position i (pt-mothers bin index).
572 // Bin 0 is the underflow, bin nbins+1 the overflow.
573 // If Fi don't exist or the index i is out of the variability range return 0
575 if(!fFi) {AliError("Correction factors Fi are not been evaluated yet!\n"); return 0;}
576 if(!fHistoPtMothers) {AliError("mothers pt-histogram doesn't exist!\n"); return 0;}
577 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
578 if(i<0 || i>nbinsM-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsM-1,nbinsM-1)); return 0;}
582 //______________________________________________________________________________________
583 Double_t AliPtMothFromPtDaugh::GetStatErrF(Int_t i) const
585 // Return statistical error on correction factors Fi at the position i (pt-mothers bin index).
586 // Bin 0 is the underflow, bin nbins+1 the overflow.
587 // If Fi don't exist or the index i is out of the variability range return 0
589 if(!fFi) {AliError("Correction factors Fi are not been evaluated yet!\n"); return 0;}
590 if(!fHistoPtMothers) {AliError("mothers pt-histogram doesn't exist!\n"); return 0;}
591 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
592 if(i<0 || i>nbinsM-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsM-1,nbinsM-1)); return 0;}
594 return fFi[i+nbinsM];
597 //______________________________________________________________________________________
598 Double_t AliPtMothFromPtDaugh::GetWmin(Int_t i,Int_t j) const
600 // Return value of correction factors Wij_min at the position i (ptMin-mothers bin index)-
601 // j (pt-daughter bin index). Bin 0 is the underflow, bin nbins+1 the overflow.
602 // If Wij_min don't exist or the indices i or j are out of the variability range return 0
604 if(!fWijMin) {AliError("Correction factors Wij_min are not been evaluated yet!\n"); return 0;}
605 if(!fHistoPtMinMothers) {AliError("mothers ptMin-histogram doesn't exist!\n"); return 0;}
606 if(!fHistoPtDaughter) {AliError("daughters pt-histogram doesn't exist!\n"); return 0;}
607 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
608 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
609 if(i<0 || i>nbinsMmin-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsMmin-1,nbinsMmin-1)); return 0;}
610 if(j<0 || j>nbinsD-1) {AliError(Form("Index j out of range: %d =< j =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsD-1,nbinsD-1)); return 0;}
611 return fWijMin[i][j];
614 //______________________________________________________________________________________
615 Double_t AliPtMothFromPtDaugh::GetStatErrWmin(Int_t i,Int_t j) const
617 // Return value of statistical error on correction factors Wij_min at the position
618 // i (ptMin-mothers bin index)- j (pt-daughter bin index). Bin 0 is the underflow,
619 // bin nbins+1 the overflow. If Wij_min don't exist or the indices i or j are out of the
620 // variability range return 0
622 if(!fWijMin) {AliError("Correction factors Wij_min are not been evaluated yet!\n"); return 0;}
623 if(!fHistoPtMinMothers) {AliError("mothers ptMin-histogram doesn't exist!\n"); return 0;}
624 if(!fHistoPtDaughter) {AliError("daughters pt-histogram doesn't exist!\n"); return 0;}
625 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
626 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
627 if(i<0 || i>nbinsMmin-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsMmin-1,nbinsMmin-1)); return 0;}
628 if(j<0 || j>nbinsD-1) {AliError(Form("Index j out of range: %d =< j =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsD-1,nbinsD-1)); return 0;}
630 return fWijMin[i+nbinsMmin][j];
633 //______________________________________________________________________________________
634 Double_t AliPtMothFromPtDaugh::GetFmin(Int_t i) const
636 // Return value of correction factors Fi_min at the position i (ptMin-mothers bin index).
637 // Bin 0 is the underflow, bin nbins+1 the overflow.
638 // If Fi_min don't exist or the index i is out of the variability range return 0
640 if(!fFiMin) {AliError("Correction factors Fi_min are not been evaluated yet!\n"); return 0;}
641 if(!fHistoPtMinMothers) {AliError("mothers ptMin-histogram doesn't exist!\n"); return 0;}
642 Int_t nbinsMmin=fHistoPtMothers->GetNbinsX()+2;
643 if(i<0 || i>nbinsMmin-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsMmin-1,nbinsMmin-1)); return 0;}
647 //______________________________________________________________________________________
648 Double_t AliPtMothFromPtDaugh::GetStatErrFmin(Int_t i) const
650 // Return statistical error on correction factors Fi_min at the position i (ptMin-mothers bin index).
651 // Bin 0 is the underflow, bin nbins+1 the overflow.
652 // If Fi_min don't exist or the index i is out of the variability range return 0
654 if(!fFiMin) {AliError("Correction factors Fi_min are not been evaluated yet!\n"); return 0;}
655 if(!fHistoPtMinMothers) {AliError("mothers ptMin-histogram doesn't exist!\n"); return 0;}
656 Int_t nbinsMmin=fHistoPtMothers->GetNbinsX()+2;
657 if(i<0 || i>nbinsMmin-1) {AliError(Form("Index i out of range: %d =< i =< %d. Bin 0 is the underflow - bin %d is the overflow.",0,nbinsMmin-1,nbinsMmin-1)); return 0;}
659 return fFiMin[i+nbinsMmin];
662 //______________________________________________________________________________________
663 Bool_t AliPtMothFromPtDaugh::IsMothers(Int_t pdgCode)
665 //return kTRUE if pdgCode is in the list of pdg codes of mothers
666 Int_t dim = fMothers->GetSize();
667 for(Int_t i=0;i<dim;i++) {
668 Int_t pdgMother = (Int_t)fMothers->GetAt(i);
669 if(pdgCode == pdgMother) return kTRUE; }
673 //______________________________________________________________________________________
674 Bool_t AliPtMothFromPtDaugh::IsSelectedDaugh(const TParticle *part, Int_t &labelDaugh, AliStack *const stack)
676 // return kTRUE if particle part has the selected daughter
677 // if yes put the label of the track in labelDaugh
679 Int_t nDg=part->GetNDaughters();
680 if(nDg<=0) {AliError("I have no daugh!\n"); return kFALSE;}
681 for(Int_t i=part->GetFirstDaughter();i<part->GetLastDaughter()+1;i++)
683 daugh=stack->Particle(i);
684 if(TMath::Abs(daugh->GetPdgCode())==fDaughter) {
692 //______________________________________________________________________________________
693 Bool_t AliPtMothFromPtDaugh::Rapidity(const TParticle *particle, Double_t &y)
695 // Evaluated rapidity of particle and put it in y. Return kFALSE if
696 // cannot compute rapidity
698 if(particle->Energy()-particle->Pz()<=0) return kFALSE;
699 y=0.5*TMath::Log((particle->Energy()+particle->Pz())/(particle->Energy()-particle->Pz()));
703 //______________________________________________________________________________________
704 Int_t AliPtMothFromPtDaugh::GiveBinIndex(Double_t Ptpart,const TH1F *ptHist) const
706 // Return the bin index of pt respect to the binning size of ptHist
707 // bin 0 is the underflow - nbins+1 is the overflow
708 Int_t nbins=ptHist->GetNbinsX();
710 for(Int_t i=1;i<nbins+2;i++)
712 if(Ptpart<(ptHist->GetBinLowEdge(i)))
721 //______________________________________________________________________________________
722 Bool_t AliPtMothFromPtDaugh::CutDaugh(Double_t yD,Double_t ptD)
724 // put a control for rapidity yD and transverse momentum ptD of daughter
725 // return kTRUE if fyDaughMin < yD < fyDaughMax and ptMinDaugh < ptD < ptMaxDaugh
726 Double_t ptMinDaugh = fHistoPtDaughter->GetBinLowEdge(1);
727 Double_t ptMaxDaugh = fHistoPtDaughter->GetBinLowEdge(fHistoPtDaughter->GetNbinsX());
728 if( yD < fyDaughMin || yD > fyDaughMax ) return kFALSE;
729 if( ptD > ptMaxDaugh || ptD < ptMinDaugh ) return kFALSE;
733 //______________________________________________________________________________________
734 Bool_t AliPtMothFromPtDaugh::EvaluateWij()
736 // Evaluate correction factors using to extract the ptRaw and
737 // ptMinRaw distributions. Statistical errors on those are computed too
739 if(!fHistoPtMothers || !fHistoPtDaughter || !fHistoPtMinMothers)
740 {AliError("Control mother and daughter histograms!\n"); return kFALSE;}
742 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
743 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
744 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
745 Float_t pdgM, pdgD, pxM,pyM,pzM,yM,pxD,pyD,pzD,yD,etaM,etaD,cutVarM,cutVarD;
746 Double_t* entries=new Double_t[nbinsD];
747 for(Int_t ii=0;ii<nbinsD;ii++) {entries[ii]=0.;}
749 if(!fDecayKine) {AliError("TNtupla is not defined!\n"); return kFALSE;}
750 fDecayKine->SetBranchAddress("pdgM",&pdgM);
751 fDecayKine->SetBranchAddress("pxM",&pxM);
752 fDecayKine->SetBranchAddress("pyM",&pyM);
753 fDecayKine->SetBranchAddress("pzM",&pzM);
754 fDecayKine->SetBranchAddress("yM",&yM);
755 fDecayKine->SetBranchAddress("etaM",&etaM);
756 fDecayKine->SetBranchAddress("pdgD",&pdgD);
757 fDecayKine->SetBranchAddress("pxD",&pxD);
758 fDecayKine->SetBranchAddress("pyD",&pyD);
759 fDecayKine->SetBranchAddress("pzD",&pzD);
760 fDecayKine->SetBranchAddress("yD",&yD);
761 fDecayKine->SetBranchAddress("etaD",&etaD);
763 // Initialize correction factors for pT and pTmin if those exist
764 if(!fWij) {AliError("Correction factors Wij have not been created!\n"); return kFALSE;}
765 if(!fWijMin) {AliError("Correction factors Wij_min have not been created!\n"); return kFALSE;}
766 for(Int_t ii=0;ii<(2*nbinsM);ii++){
767 for(Int_t jj=0;jj<nbinsD;jj++){
771 for(Int_t ii=0;ii<(2*nbinsMmin);ii++){
772 for(Int_t jj=0;jj<nbinsD;jj++){
776 Int_t nentries = (Int_t)fDecayKine->GetEntries();
778 Int_t nb = (Int_t)fDecayKine->GetEvent(fNcurrent);
779 for (Int_t iev=0; iev<nentries; iev++){
780 // check if rapidity or pseudorapidity range is set
781 if(fUseEta == kFALSE) {cutVarD = yD; cutVarM = yM;}
782 else {cutVarD = etaD; cutVarM = etaM;}
783 ptD=TMath::Sqrt(pxD*pxD+pyD*pyD);
784 ptM=TMath::Sqrt(pxM*pxM+pyM*pyM);
785 pdgM = TMath::Abs(pdgM);
786 if((TMath::Abs(pdgD))==fDaughter && IsMothers((Int_t)pdgM))
788 j=GiveBinIndex(ptD,fHistoPtDaughter);
789 i=GiveBinIndex(ptM,fHistoPtMothers);
790 iMin=GiveBinIndex(ptM,fHistoPtMinMothers);
791 if(!CutDaugh(cutVarD,ptD)) { fNcurrent++; nb = (Int_t)fDecayKine->GetEvent(fNcurrent); continue;}
792 if(cutVarM>fyMothMin && cutVarM<fyMothMax){
794 for(Int_t k=0;k<iMin+1;k++) {fWijMin[k][j]+=1.;}
799 nb = (Int_t)fDecayKine->GetEvent(fNcurrent);
801 for(Int_t jj=0;jj<nbinsD;jj++){
802 for(Int_t ii=0;ii<nbinsM;ii++){
804 fWij[ii][jj]=fWij[ii][jj]/entries[jj];
805 // evaluate statistical errors on fWij
806 fWij[ii+nbinsM][jj]=(TMath::Sqrt(fWij[ii][jj]*(1-(fWij[ii][jj]/entries[jj]))))/entries[jj];
809 // if there are no entries in the bin-j of daughter distribution
810 // set factor = -1 and error = 999
812 fWij[ii+nbinsM][jj]=999;
815 for(Int_t ii=0;ii<nbinsMmin;ii++){
817 fWijMin[ii][jj]=fWijMin[ii][jj]/entries[jj];
818 //evaluate statistical errors on fWijMin
819 fWijMin[ii+nbinsMmin][jj] = (TMath::Sqrt(fWijMin[ii][jj]*(1-(fWijMin[ii][jj]/entries[jj]))))/entries[jj];
822 //if there are no entries set correction factor = -1 and error = -999
824 fWijMin[ii+nbinsMmin][jj]=999;
832 //______________________________________________________________________________________
833 Bool_t AliPtMothFromPtDaugh::EvaluateFi()
835 // Evaluate acceptance correction factors that are applied on the
836 // raw distributions. Statistical errors on those are computed too
838 if(!fHistoPtMothers || !fHistoPtMinMothers)
839 {AliError("Control mother histograms!\n"); return kFALSE;}
841 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
842 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
843 Double_t* entries=new Double_t[nbinsM];
844 Double_t* entries1=new Double_t[nbinsMmin];
845 if(!fFi) {AliError("Correction factors Fi have not been created!\n"); return kFALSE;}
846 if(!fFiMin) {AliError("Correction factors Fi_min have not been created!\n"); return kFALSE;}
847 //initialize the correction factor for pT and pTmin
848 for(Int_t ii=0;ii<nbinsM;ii++){
849 fFi[ii]=0.; //for correction factors
850 fFi[ii+nbinsM]=0.; //for statistical error on correction factors
853 for(Int_t ii=0;ii<nbinsMmin;ii++){
855 fFiMin[ii]=0.; //for correction factors
856 fFiMin[ii+nbinsMmin]=0.; //for statistical error on correction factors
858 Float_t pdgM, pdgD, pxM,pyM,pzM,yM,pxD,pyD,pzD,yD,etaM,etaD,cutVarD,cutVarM;
860 if(!fDecayKine) {AliError("TNtupla is not defined!\n"); return kFALSE;}
861 fDecayKine->SetBranchAddress("pdgM",&pdgM);
862 fDecayKine->SetBranchAddress("pxM",&pxM);
863 fDecayKine->SetBranchAddress("pyM",&pyM);
864 fDecayKine->SetBranchAddress("pzM",&pzM);
865 fDecayKine->SetBranchAddress("yM",&yM);
866 fDecayKine->SetBranchAddress("etaM",&etaM);
867 fDecayKine->SetBranchAddress("pdgD",&pdgD);
868 fDecayKine->SetBranchAddress("pxD",&pxD);
869 fDecayKine->SetBranchAddress("pyD",&pyD);
870 fDecayKine->SetBranchAddress("pzD",&pzD);
871 fDecayKine->SetBranchAddress("yD",&yD);
872 fDecayKine->SetBranchAddress("etaD",&etaD);
875 Int_t nentries = (Int_t)fDecayKine->GetEntries();
877 Int_t nb = (Int_t)fDecayKine->GetEvent(fNcurrent);
879 for (Int_t iev=0; iev<nentries; iev++){
880 pdgM = TMath::Abs(pdgM);
881 if((TMath::Abs(pdgD))==fDaughter && IsMothers((Int_t)pdgM))
883 //check if rapidity or pseudorapidity range is set
884 if(fUseEta == kFALSE) {cutVarD = yD; cutVarM = yM;}
885 else {cutVarD = etaD; cutVarM = etaM;}
886 ptD=TMath::Sqrt(pxD*pxD+pyD*pyD);
887 ptM=TMath::Sqrt(pxM*pxM+pyM*pyM);
888 i=GiveBinIndex(ptM,fHistoPtMothers);
889 iMin=GiveBinIndex(ptM,fHistoPtMinMothers);
890 if(cutVarM<fyMothMin || cutVarM>fyMothMax){
891 fNcurrent++; nb = (Int_t)fDecayKine->GetEvent(fNcurrent); continue;}
893 for(Int_t k=0; k<iMin+1;k++) {entries1[k]+=1;}
894 if(!CutDaugh(cutVarD,ptD)) {fNcurrent++; nb = (Int_t)fDecayKine->GetEvent(fNcurrent); continue;}
896 for(Int_t k=0; k<iMin+1;k++) {fFiMin[k]+=1.;}
899 nb = (Int_t) fDecayKine->GetEvent(fNcurrent);
902 for(Int_t ii=0;ii<nbinsM;ii++){
904 fFi[ii]/=entries[ii];
905 fFi[ii+nbinsM]=(TMath::Sqrt(fFi[ii]*(1-(fFi[ii]/entries[ii]))))/entries[ii];
912 for(Int_t ii=0;ii<nbinsMmin;ii++){
914 fFiMin[ii]/=entries1[ii];
915 fFiMin[ii+nbinsMmin]=(TMath::Sqrt(fFiMin[ii]*(1-(fFiMin[ii]/entries1[ii]))))/entries1[ii];
917 else {fFiMin[ii]=-1; fFiMin[ii+nbinsMmin]=999;}
924 //______________________________________________________________________________________
925 Bool_t AliPtMothFromPtDaugh::EvaluatePtMothRaw(TH1F *histoPt, TH1F *histoPtMin)
927 //Apply the fWij and fWijMin on the daughter distribution
928 //in order to evaluate the pt and ptMin raw distributions for mothers
930 if(!fHistoPtMothers || !fHistoPtDaughter || !fHistoPtMinMothers)
931 {AliError("Control mother and daughter histograms!\n"); return kFALSE;}
933 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
934 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
935 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
938 Double_t wMinfill=0.;
939 for(Int_t j=0;j<nbinsD;j++){
940 for(Int_t i=0;i<nbinsM;i++){
941 lowedge=fHistoPtMothers->GetBinCenter(i);
942 if(fWij[i][j]>=0) wfill=fWij[i][j]*(fHistoPtDaughter->GetBinContent(j));
943 histoPt->Fill(lowedge,wfill);
945 for(Int_t i=0;i<nbinsMmin;i++){
946 lowedge=fHistoPtMinMothers->GetBinLowEdge(i);
947 if(fWijMin[i][j]>=0) wMinfill=fWijMin[i][j]*(fHistoPtDaughter->GetBinContent(j));
948 histoPtMin->Fill(lowedge,wMinfill);
954 //______________________________________________________________________________________
955 Bool_t AliPtMothFromPtDaugh::EvaluateErrPt(Double_t *erStat)
957 // Evaluate the statistical error on the pt-mothers distribution.
958 // sigmaX: contribution that came from the measured distibution
959 // sigmaWij: contribution that came from the fWij factors
960 // sigmaFi: contribution that came from the fFi factors
962 if(!fHistoPtMothers || !fHistoPtDaughter)
963 {AliError("Control mother(pt) and daughter histograms!\n"); return kFALSE;}
965 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
966 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
968 Double_t sigmaX, sigmaWij, sigmaFi;
969 for(Int_t i=0;i<nbinsM;i++){
973 for(Int_t j=0;j<nbinsD;j++){
975 sigmaX+=(((fWij[i][j])*(fWij[i][j]))*((fHistoPtDaughter->GetBinError(j))*(fHistoPtDaughter->GetBinError(j))));
976 sigmaWij+=((fHistoPtDaughter->GetBinContent(j))*(fHistoPtDaughter->GetBinContent(j)))*(fWij[i+nbinsM][j]*fWij[i+nbinsM][j]);
977 sigmaFi+=(fWij[i][j])*(fHistoPtDaughter->GetBinContent(j));
980 if(fFi[i]>0) sigmaFi=((sigmaFi*sigmaFi)*(fFi[i+nbinsM]*fFi[i+nbinsM]))/(fFi[i]*fFi[i]);
981 m=TMath::Sqrt(sigmaX+sigmaWij+sigmaFi);
982 if(fFi[i]>0) erStat[i]=(1/fFi[i])*m;
988 //______________________________________________________________________________________
989 Bool_t AliPtMothFromPtDaugh::EvaluateErrPtMin(Double_t *erStat)
991 // Evaluate statistical error on ptMin mothers distribution
992 // sigmaMinX: contribution that came from the measured distibution
993 // sigmaMinWij: contribution that came from the fWijMin factors
994 // sigmaMinFi: contribution that came from the fFiMin factors
996 if(!fHistoPtDaughter || !fHistoPtMinMothers)
997 {AliError("Control mother(ptMin) and daughter histograms!\n"); return kFALSE;}
999 Int_t nbinsD=fHistoPtDaughter->GetNbinsX()+2;
1000 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
1003 Double_t sigmaMinWij;
1004 Double_t sigmaMinFi;
1005 for(Int_t i=0;i<nbinsMmin;i++){
1009 for(Int_t j=0;j<nbinsD;j++){
1010 if(fWijMin[i][j]>=0){
1011 sigmaMinX+=(((fWijMin[i][j])*(fWijMin[i][j]))*((fHistoPtDaughter->GetBinError(j))*(fHistoPtDaughter->GetBinError(j))));
1012 sigmaMinWij+=((fHistoPtDaughter->GetBinContent(j))*(fHistoPtDaughter->GetBinContent(j)))*(fWijMin[i+nbinsMmin][j]*fWijMin[i+nbinsMmin][j]);
1013 sigmaMinFi+=(fWijMin[i][j])*(fHistoPtDaughter->GetBinContent(j));
1016 if(fFiMin[i]>0) sigmaMinFi=((sigmaMinFi*sigmaMinFi)*(fFiMin[i+nbinsMmin]*fFiMin[i+nbinsMmin]))/(fFiMin[i]*fFiMin[i]);
1017 m1=TMath::Sqrt(sigmaMinX+sigmaMinWij+sigmaMinFi);
1018 if(fFiMin[i]>0) erStat[i]=(1/fFiMin[i])*m1;
1025 //______________________________________________________________________________________
1026 Bool_t AliPtMothFromPtDaugh::EvaluatePtMoth()
1028 // Evaluate pt and ptMin distribution for mothers
1029 // First evaluate the sigma raw distribution by calling EvaluatePtMothRaw
1030 // then evaluate the pt and ptMin mothers distribution.
1031 // Statistical errors on those distributions are evaluated too.
1033 if(!EvaluateWij()) return kFALSE;
1034 if(!EvaluateFi()) return kFALSE;
1036 // reset pt and ptMin mothers histograms
1037 fHistoPtMothers->Reset();
1038 fHistoPtMinMothers->Reset();
1040 TH1F *histoPt=(TH1F*)fHistoPtMothers->Clone();
1041 TH1F *histoPtMin=(TH1F*)fHistoPtMinMothers->Clone();
1042 EvaluatePtMothRaw(histoPt,histoPtMin);
1043 Int_t nbinsM=fHistoPtMothers->GetNbinsX()+2;
1044 Int_t nbinsMmin=fHistoPtMinMothers->GetNbinsX()+2;
1045 Double_t *erPtStat=new Double_t[nbinsM+2];
1046 EvaluateErrPt(erPtStat);
1047 Double_t *erPtMinStat=new Double_t[nbinsMmin+2];
1048 EvaluateErrPtMin(erPtMinStat);
1052 for(Int_t i=0;i<nbinsM;i++){
1054 lowedge=fHistoPtMothers->GetBinCenter(i);
1056 fwfill=(histoPt->GetBinContent(i))/fFi[i];
1057 fHistoPtMothers->Fill(lowedge,fwfill);
1058 fHistoPtMothers->SetBinError(i,erPtStat[i]);
1061 for(Int_t i=0;i<nbinsMmin;i++){
1063 lowedge=fHistoPtMinMothers->GetBinCenter(i);
1065 fMinfill=(histoPtMin->GetBinContent(i))/fFiMin[i];
1066 fHistoPtMinMothers->Fill(lowedge,fMinfill);
1067 fHistoPtMinMothers->SetBinError(i,erPtMinStat[i]);
1073 //______________________________________________________________________________________
1074 void AliPtMothFromPtDaugh::WritePtMothHistoToFile(char *fileOutName)
1076 // Write pt and ptMin histograms of mothers in a file
1077 // with name fileOutName. Default name is "Mothers.root".
1078 AliError(Form("Write mothers histograms in the file %s \n",fileOutName));
1079 if(!fHistoPtMothers) {AliError("Cannot write pt-mothers histogram! It doesn't exists!"); return;}
1080 if(!fHistoPtMinMothers) { AliError("Cannot write ptMin-mothers histogram! It doesn't exists!"); return;}
1081 TFile *outFile = TFile::Open(fileOutName,"RECREATE");
1083 fHistoPtMothers->Write();
1084 fHistoPtMinMothers->Write();