Add request to remove clusters close to borders in general invariant mass plots
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliHFEtools.cxx
CommitLineData
70da6c5a 1/**************************************************************************
2* Copyright(c) 1998-1999, 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// Toolkit containing various usefull things
17// Usable everywhere in the hfe software package
18// For more information see the cxx file
19//
20// Authors
21// All authors of the HFE group
22//
23#include <TMath.h>
24#include <TParticle.h>
25#include "TH1.h"
26#include "TH2.h"
27#include "THnSparse.h"
28#include "TAxis.h"
29
30#include "AliAODMCParticle.h"
faee3b18 31#include "AliESDpid.h"
70da6c5a 32#include "AliLog.h"
faee3b18 33#include "AliTOFPIDResponse.h"
70da6c5a 34
35#include "AliHFEtools.h"
36
37ClassImp(AliHFEtools)
38
faee3b18 39AliESDpid *AliHFEtools::fgDefaultPID = NULL;
40Int_t AliHFEtools::fgLogLevel = 1;
41
70da6c5a 42//__________________________________________
43AliHFEtools::AliHFEtools():
44 TObject()
45{
46}
47
48//__________________________________________
49Double_t *AliHFEtools::MakeLinearBinning(Int_t nBins, Double_t ymin, Double_t ymax){
50 //
51 // Helper function for linearly binned array
52 //
53 Double_t *bins = new Double_t[nBins + 1];
54 Double_t stepsize = (ymax - ymin) / static_cast<Double_t>(nBins);
55 bins[0] = ymin;
56 for(Int_t ibin = 1; ibin <= nBins; ibin++)
57 bins[ibin] = bins[ibin-1] + stepsize;
58 return bins;
59}
60
61//__________________________________________
62Double_t *AliHFEtools::MakeLogarithmicBinning(Int_t nBins, Double_t ymin, Double_t ymax){
63 //
64 // Helper function for logartimically binned array
65 //
66 Double_t *bins = new Double_t[nBins+1];
67 bins[0] = ymin;
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];
71 }
72 return bins;
73}
74
75//_________________________________________
76Bool_t AliHFEtools::BinLogAxis(TObject *o, Int_t dim){
77
78 //
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
81 //
82
83
84 if(!o){
85 AliError("Input histogram is null pointer");
86 return kFALSE;
87 }
88
89 TAxis *axis = 0x0;
90 if(o->InheritsFrom("TH1")){
91 axis = (dynamic_cast<TH1F*>(o))->GetXaxis();
92 }
93 else if(o->InheritsFrom("TH2")){
94 if(0 == dim){
95 axis = (dynamic_cast<TH2F*>(o))->GetXaxis();
96 }
97 else if(1 == dim){
98 axis = (dynamic_cast<TH2F*>(o))->GetYaxis();
99 }
100 else{
101 AliError("Only dim = 0 or 1 possible for TH2F");
102 }
103 }
104 else if(o->InheritsFrom("THnSparse")){
105 axis = (dynamic_cast<THnSparse*>(o))->GetAxis(dim);
106 }
107 else{
108 AliError("Type of input object not recognized, please check your code or update this finction");
109 return kFALSE;
110 }
111 if(!axis){
112 AliError(Form("Axis '%d' could not be identified in the object \n", dim));
113 return kFALSE;
114 }
115
116 Int_t bins = axis->GetNbins();
117
118 Double_t from = axis->GetXmin();
119 if(from <= 0){
120 AliError(Form("Log binning not possible for this axis [min = %f]\n", from));
121 }
122 Double_t to = axis->GetXmax();
123 Double_t *newBins = new Double_t[bins+1];
124 newBins[0] = from;
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];
128 }
129 axis->Set(bins, newBins);
b5ed6afb 130 delete [] newBins;
70da6c5a 131
132 return kTRUE;
133}
134
135//__________________________________________
136Float_t AliHFEtools::GetRapidity(TParticle *part){
137 //
138 // return rapidity
139 //
140 Float_t rapidity;
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())));
143 return rapidity;
144}
145
146//__________________________________________
147Float_t AliHFEtools::GetRapidity(AliAODMCParticle *part){
148 // return rapidity
149
150 Float_t rapidity;
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())));
153 return rapidity;
154}
155
faee3b18 156//__________________________________________
157AliESDpid* AliHFEtools::GetDefaultPID(Bool_t isMC){
158 //
159 // Get the default PID as singleton instance
160 //
161 if(!fgDefaultPID){
162 fgDefaultPID = new AliESDpid;
163 Double_t tres = isMC ? 80. : 130.;
164 fgDefaultPID->GetTOFResponse().SetTimeResolution(tres);
165
166 // TPC Bethe Bloch parameters
167 Double_t alephParameters[5];
168 if(isMC){
169 // simulation
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;
175 } else {
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;
182 }
183 fgDefaultPID->GetTPCResponse().SetBetheBlochParameters(alephParameters[0],alephParameters[1],alephParameters[2], alephParameters[3],alephParameters[4]);
184
185 }
186 if(fgLogLevel){
187 printf("Error - You are using the default PID: You should use the PID coming from the tender");
188 printf("Error - Arrrrrrrrr...");
189 printf("Error - Please rethink your program logic. Using default PID is really dangerous");
190 printf("Error - TOF PID is adapted to Monte Carlo");
191 }
192 return fgDefaultPID;
193}
194
195//__________________________________________
196void AliHFEtools::DestroyDefaultPID(){
197 //
198 // Destroy default PID object if existing
199 //
200 if(fgDefaultPID) delete fgDefaultPID;
201 fgDefaultPID = NULL;
202}