1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
16 // Toolkit containing various usefull things
17 // Usable everywhere in the hfe software package
18 // For more information see the cxx file
21 // All authors of the HFE group
24 #include <TParticle.h>
27 #include "THnSparse.h"
30 #include "AliAODMCParticle.h"
31 #include "AliESDpid.h"
33 #include "AliTOFPIDResponse.h"
35 #include "AliHFEtools.h"
39 AliESDpid *AliHFEtools::fgDefaultPID = NULL;
40 Int_t AliHFEtools::fgLogLevel = 1;
42 //__________________________________________
43 AliHFEtools::AliHFEtools():
48 //__________________________________________
49 Double_t *AliHFEtools::MakeLinearBinning(Int_t nBins, Double_t ymin, Double_t ymax){
51 // Helper function for linearly binned array
53 Double_t *bins = new Double_t[nBins + 1];
54 Double_t stepsize = (ymax - ymin) / static_cast<Double_t>(nBins);
56 for(Int_t ibin = 1; ibin <= nBins; ibin++)
57 bins[ibin] = bins[ibin-1] + stepsize;
61 //__________________________________________
62 Double_t *AliHFEtools::MakeLogarithmicBinning(Int_t nBins, Double_t ymin, Double_t ymax){
64 // Helper function for logartimically binned array
66 Double_t *bins = new Double_t[nBins+1];
68 Double_t factor = TMath::Power(ymax/ymin, 1./nBins);
69 for(Int_t ibin = 1; ibin <= nBins; ibin++){
70 bins[ibin] = factor * bins[ibin-1];
75 //_________________________________________
76 Bool_t AliHFEtools::BinLogAxis(TObject *o, Int_t dim){
79 // converts the axis (defined by the dimension) of THx or THnSparse
80 // object to Log scale. Number of bins and bin min and bin max are preserved
85 AliError("Input histogram is null pointer");
90 if(o->InheritsFrom("TH1")){
91 axis = (dynamic_cast<TH1F*>(o))->GetXaxis();
93 else if(o->InheritsFrom("TH2")){
95 axis = (dynamic_cast<TH2F*>(o))->GetXaxis();
98 axis = (dynamic_cast<TH2F*>(o))->GetYaxis();
101 AliError("Only dim = 0 or 1 possible for TH2F");
104 else if(o->InheritsFrom("THnSparse")){
105 axis = (dynamic_cast<THnSparse*>(o))->GetAxis(dim);
108 AliError("Type of input object not recognized, please check your code or update this finction");
112 AliError(Form("Axis '%d' could not be identified in the object \n", dim));
116 Int_t bins = axis->GetNbins();
118 Double_t from = axis->GetXmin();
120 AliError(Form("Log binning not possible for this axis [min = %f]\n", from));
122 Double_t to = axis->GetXmax();
123 Double_t *newBins = new Double_t[bins+1];
125 Double_t factor = TMath::Power(to/from, 1./bins);
126 for(Int_t i=1; i<=bins; ++i){
127 newBins[i] = factor * newBins[i-1];
129 axis->Set(bins, newBins);
135 //__________________________________________
136 Float_t AliHFEtools::GetRapidity(TParticle *part){
141 if(!((part->Energy() - part->Pz())*(part->Energy() + part->Pz())>0)) rapidity=-999;
142 else rapidity = 0.5*(TMath::Log((part->Energy()+part->Pz()) / (part->Energy()-part->Pz())));
146 //__________________________________________
147 Float_t AliHFEtools::GetRapidity(AliAODMCParticle *part){
151 if(!((part->E() - part->Pz())*(part->E() + part->Pz())>0)) rapidity=-999;
152 else rapidity = 0.5*(TMath::Log((part->E()+part->Pz()) / (part->E()-part->Pz())));
156 //__________________________________________
157 AliESDpid* AliHFEtools::GetDefaultPID(Bool_t isMC){
159 // Get the default PID as singleton instance
162 fgDefaultPID = new AliESDpid;
163 Double_t tres = isMC ? 80. : 130.;
164 fgDefaultPID->GetTOFResponse().SetTimeResolution(tres);
166 // TPC Bethe Bloch parameters
167 Double_t alephParameters[5];
170 alephParameters[0] = 2.15898e+00/50.;
171 alephParameters[1] = 1.75295e+01;
172 alephParameters[2] = 3.40030e-09;
173 alephParameters[3] = 1.96178e+00;
174 alephParameters[4] = 3.91720e+00;
176 alephParameters[0] = 0.0283086/0.97;
177 //alephParameters[0] = 0.0283086;
178 alephParameters[1] = 2.63394e+01;
179 alephParameters[2] = 5.04114e-11;
180 alephParameters[3] = 2.12543e+00;
181 alephParameters[4] = 4.88663e+00;
183 fgDefaultPID->GetTPCResponse().SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2], alephParameters[3],alephParameters[4]);
184 fgDefaultPID->GetTPCResponse().SetSigma(3.79301e-03, 2.21280e+04);
188 printf("Error - You are using the default PID: You should use the PID coming from the tender\n");
189 printf("Error - Arrrrrrrrr...\n");
190 printf("Error - Please rethink your program logic. Using default PID is really dangerous\n");
191 printf("Error - TOF PID is adapted to Monte Carlo\n");
196 //__________________________________________
197 void AliHFEtools::DestroyDefaultPID(){
199 // Destroy default PID object if existing
201 if(fgDefaultPID) delete fgDefaultPID;