]>
Commit | Line | Data |
---|---|---|
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" | |
31 | #include "AliLog.h" | |
32 | ||
33 | #include "AliHFEtools.h" | |
34 | ||
35 | ClassImp(AliHFEtools) | |
36 | ||
37 | //__________________________________________ | |
38 | AliHFEtools::AliHFEtools(): | |
39 | TObject() | |
40 | { | |
41 | } | |
42 | ||
43 | //__________________________________________ | |
44 | Double_t *AliHFEtools::MakeLinearBinning(Int_t nBins, Double_t ymin, Double_t ymax){ | |
45 | // | |
46 | // Helper function for linearly binned array | |
47 | // | |
48 | Double_t *bins = new Double_t[nBins + 1]; | |
49 | Double_t stepsize = (ymax - ymin) / static_cast<Double_t>(nBins); | |
50 | bins[0] = ymin; | |
51 | for(Int_t ibin = 1; ibin <= nBins; ibin++) | |
52 | bins[ibin] = bins[ibin-1] + stepsize; | |
53 | return bins; | |
54 | } | |
55 | ||
56 | //__________________________________________ | |
57 | Double_t *AliHFEtools::MakeLogarithmicBinning(Int_t nBins, Double_t ymin, Double_t ymax){ | |
58 | // | |
59 | // Helper function for logartimically binned array | |
60 | // | |
61 | Double_t *bins = new Double_t[nBins+1]; | |
62 | bins[0] = ymin; | |
63 | Double_t factor = TMath::Power(ymax/ymin, 1./nBins); | |
64 | for(Int_t ibin = 1; ibin <= nBins; ibin++){ | |
65 | bins[ibin] = factor * bins[ibin-1]; | |
66 | } | |
67 | return bins; | |
68 | } | |
69 | ||
70 | //_________________________________________ | |
71 | Bool_t AliHFEtools::BinLogAxis(TObject *o, Int_t dim){ | |
72 | ||
73 | // | |
74 | // converts the axis (defined by the dimension) of THx or THnSparse | |
75 | // object to Log scale. Number of bins and bin min and bin max are preserved | |
76 | // | |
77 | ||
78 | ||
79 | if(!o){ | |
80 | AliError("Input histogram is null pointer"); | |
81 | return kFALSE; | |
82 | } | |
83 | ||
84 | TAxis *axis = 0x0; | |
85 | if(o->InheritsFrom("TH1")){ | |
86 | axis = (dynamic_cast<TH1F*>(o))->GetXaxis(); | |
87 | } | |
88 | else if(o->InheritsFrom("TH2")){ | |
89 | if(0 == dim){ | |
90 | axis = (dynamic_cast<TH2F*>(o))->GetXaxis(); | |
91 | } | |
92 | else if(1 == dim){ | |
93 | axis = (dynamic_cast<TH2F*>(o))->GetYaxis(); | |
94 | } | |
95 | else{ | |
96 | AliError("Only dim = 0 or 1 possible for TH2F"); | |
97 | } | |
98 | } | |
99 | else if(o->InheritsFrom("THnSparse")){ | |
100 | axis = (dynamic_cast<THnSparse*>(o))->GetAxis(dim); | |
101 | } | |
102 | else{ | |
103 | AliError("Type of input object not recognized, please check your code or update this finction"); | |
104 | return kFALSE; | |
105 | } | |
106 | if(!axis){ | |
107 | AliError(Form("Axis '%d' could not be identified in the object \n", dim)); | |
108 | return kFALSE; | |
109 | } | |
110 | ||
111 | Int_t bins = axis->GetNbins(); | |
112 | ||
113 | Double_t from = axis->GetXmin(); | |
114 | if(from <= 0){ | |
115 | AliError(Form("Log binning not possible for this axis [min = %f]\n", from)); | |
116 | } | |
117 | Double_t to = axis->GetXmax(); | |
118 | Double_t *newBins = new Double_t[bins+1]; | |
119 | newBins[0] = from; | |
120 | Double_t factor = TMath::Power(to/from, 1./bins); | |
121 | for(Int_t i=1; i<=bins; ++i){ | |
122 | newBins[i] = factor * newBins[i-1]; | |
123 | } | |
124 | axis->Set(bins, newBins); | |
125 | delete newBins; | |
126 | ||
127 | return kTRUE; | |
128 | } | |
129 | ||
130 | //__________________________________________ | |
131 | Float_t AliHFEtools::GetRapidity(TParticle *part){ | |
132 | // | |
133 | // return rapidity | |
134 | // | |
135 | Float_t rapidity; | |
136 | if(!((part->Energy() - part->Pz())*(part->Energy() + part->Pz())>0)) rapidity=-999; | |
137 | else rapidity = 0.5*(TMath::Log((part->Energy()+part->Pz()) / (part->Energy()-part->Pz()))); | |
138 | return rapidity; | |
139 | } | |
140 | ||
141 | //__________________________________________ | |
142 | Float_t AliHFEtools::GetRapidity(AliAODMCParticle *part){ | |
143 | // return rapidity | |
144 | ||
145 | Float_t rapidity; | |
146 | if(!((part->E() - part->Pz())*(part->E() + part->Pz())>0)) rapidity=-999; | |
147 | else rapidity = 0.5*(TMath::Log((part->E()+part->Pz()) / (part->E()-part->Pz()))); | |
148 | return rapidity; | |
149 | } | |
150 |