]>
Commit | Line | Data |
---|---|---|
51a0ce25 | 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 | // Container class for the reference distributions for TRD PID | |
17 | // The class contains the reference distributions and the momentum steps | |
18 | // the references are taken at. Mapping is done inside. To derive references, | |
19 | // the functions GetUpperReference and GetLowerReference return the next | |
20 | // reference distribution object and the momentum step above respectively below | |
21 | // the tracklet momentum. | |
22 | // | |
23 | // Authors: | |
24 | // Markus Fasel <M.Fasel@gsi.de> | |
25 | // | |
26 | #include "TObjArray.h" | |
27 | ||
28 | #include "AliLog.h" | |
29 | ||
30 | #include "AliTRDPIDReference.h" | |
31 | ||
32 | ClassImp(AliTRDPIDReference) | |
33 | ||
34 | //____________________________________________________________ | |
35 | AliTRDPIDReference::AliTRDPIDReference(): | |
36 | TNamed(), | |
37 | fRefContainer(NULL), | |
38 | fMomentumBins() | |
39 | { | |
40 | // | |
41 | // Dummy constructor | |
42 | // | |
43 | SetBit(kIsOwner, kTRUE); | |
44 | } | |
45 | ||
46 | //____________________________________________________________ | |
47 | AliTRDPIDReference::AliTRDPIDReference(const Char_t *name): | |
48 | TNamed(name, "TRD PID References"), | |
49 | fRefContainer(NULL), | |
50 | fMomentumBins() | |
51 | { | |
52 | // | |
53 | // Default constructor | |
54 | // | |
55 | SetBit(kIsOwner, kTRUE); | |
56 | } | |
57 | ||
58 | //____________________________________________________________ | |
59 | AliTRDPIDReference::AliTRDPIDReference(const AliTRDPIDReference &ref): | |
60 | TNamed(ref), | |
61 | fRefContainer(ref.fRefContainer), | |
62 | fMomentumBins(ref.fMomentumBins) | |
63 | { | |
64 | // | |
65 | // Copy constructor | |
66 | // Only copies poiters, object is not the owner of the references | |
67 | // | |
68 | SetBit(kIsOwner, kFALSE); | |
69 | } | |
70 | ||
71 | //____________________________________________________________ | |
72 | AliTRDPIDReference &AliTRDPIDReference::operator=(const AliTRDPIDReference &ref){ | |
73 | // | |
74 | // Assginment operator | |
75 | // Only copies poiters, object is not the owner of the references | |
76 | // | |
77 | if(this != &ref){ | |
78 | TNamed::operator=(ref); | |
79 | if(TestBit(kIsOwner) && fRefContainer) delete fRefContainer; | |
80 | fRefContainer = ref.fRefContainer; | |
81 | fMomentumBins = ref.fMomentumBins; | |
82 | SetBit(kIsOwner, kFALSE); | |
83 | } | |
84 | return *this; | |
85 | } | |
86 | ||
87 | //____________________________________________________________ | |
88 | AliTRDPIDReference::~AliTRDPIDReference(){ | |
89 | // | |
90 | // Destructor | |
91 | // references are deleted if the object is the owner | |
92 | // | |
93 | if(fRefContainer && TestBit(kIsOwner)) delete fRefContainer; | |
94 | } | |
95 | ||
96 | //____________________________________________________________ | |
97 | void AliTRDPIDReference::SetNumberOfMomentumBins(Int_t nBins, Float_t *momenta){ | |
98 | // | |
99 | // Set the momentum binning | |
100 | // | |
101 | if(fRefContainer) fRefContainer->Clear(); | |
102 | else{ | |
103 | fRefContainer = new TObjArray; | |
104 | fRefContainer->SetOwner(); | |
105 | } | |
106 | fRefContainer->Expand(nBins * AliPID::kSPECIES); | |
107 | fMomentumBins.Set(nBins,momenta); | |
108 | } | |
109 | ||
110 | //____________________________________________________________ | |
111 | void AliTRDPIDReference::AddReference(TObject *ref, AliPID::EParticleType spec, Int_t pbin){ | |
112 | // | |
113 | // Add a new reference distribution for a given species and a givem | |
114 | // momentum value to the reference container | |
115 | // The reference distribution is associated with the momentum value defined for the | |
116 | // given momentum bin | |
117 | // | |
118 | if(!fRefContainer){ | |
119 | AliError("Reference Container not initialized"); | |
120 | return; | |
121 | } | |
122 | if(pbin > fMomentumBins.GetSize()){ | |
123 | AliError("Pbin overflow"); | |
124 | return; | |
125 | } | |
126 | AliDebug(1, Form("Adding object with address %p to position %d", ref, spec * fMomentumBins.GetSize() + pbin)); | |
127 | fRefContainer->AddAt(ref, spec * fMomentumBins.GetSize() + pbin); | |
128 | } | |
129 | ||
130 | //____________________________________________________________ | |
131 | TObject *AliTRDPIDReference::GetUpperReference(AliPID::EParticleType spec, Float_t p, Float_t &pUpper) const{ | |
132 | // | |
133 | // Get the next reference associated with a momentum larger than the requested momentum | |
134 | // In case no next upper reference is found, NULL is returned | |
135 | // The momentum value the reference is associated to is stored in the reference pUpper | |
136 | // | |
137 | Int_t bin = -1; | |
138 | pUpper = 20; | |
139 | for(Int_t ip = 0; ip < fMomentumBins.GetSize(); ip++){ | |
140 | AliDebug(10, Form("Bin %d, p = %.1f", ip, fMomentumBins[ip])); | |
141 | if(p < fMomentumBins[ip]){ | |
142 | AliDebug(10, "Bin found"); | |
143 | bin = ip; | |
144 | break; | |
145 | } | |
146 | } | |
147 | AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin)); | |
148 | if(bin >= 0) { | |
149 | pUpper = fMomentumBins[bin]; | |
150 | return fRefContainer->At(spec * fMomentumBins.GetSize() + bin); | |
151 | } | |
152 | else return NULL; | |
153 | } | |
154 | ||
155 | //____________________________________________________________ | |
156 | TObject *AliTRDPIDReference::GetLowerReference(AliPID::EParticleType spec, Float_t p, Float_t &pLower) const{ | |
157 | // | |
158 | // Get the next reference associated with a momentum smaller than the requested momentum | |
159 | // In case no next lower reference is found, NULL is returned | |
160 | // The momentum value the reference is associated to is stored in the reference pLower | |
161 | // | |
162 | Int_t bin = -1; | |
163 | pLower = 0; | |
164 | for(Int_t ip = fMomentumBins.GetSize() - 1; ip >= 0; ip--){ | |
165 | AliDebug(10, Form("Bin %d, p = %.1f", ip, fMomentumBins[ip])); | |
166 | if(p > fMomentumBins[ip]){ | |
167 | AliDebug(10, "Bin found"); | |
168 | bin = ip; | |
169 | break; | |
170 | } | |
171 | } | |
172 | AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin)); | |
173 | if(bin >= 0){ | |
174 | pLower = fMomentumBins[bin]; | |
175 | return fRefContainer->At(spec * fMomentumBins.GetSize() + bin); | |
176 | } | |
177 | else return NULL; | |
178 | } | |
179 | ||
180 | //____________________________________________________________ | |
181 | void AliTRDPIDReference::Print(const Option_t*) const{ | |
182 | // | |
183 | // Print content of the PID reference container | |
184 | // | |
185 | printf("Number of Momentum Bins: %d\n", GetNumberOfMomentumBins()); | |
186 | printf("=====================================\n"); | |
187 | for(Int_t ip = 0; ip < GetNumberOfMomentumBins(); ip++){ | |
188 | printf("Bin %d: p = %.1f\n", ip, fMomentumBins[ip]); | |
189 | } | |
190 | printf("=====================================\n"); | |
191 | if(fRefContainer){ | |
192 | printf("Content of the reference container:\n"); | |
193 | for(Int_t ip = 0; ip < GetNumberOfMomentumBins(); ip++){ | |
194 | printf("["); | |
195 | for(Int_t is = 0; is < 5; is++) printf("%p|", fRefContainer->At(is * fMomentumBins.GetSize() + ip)); | |
196 | printf("]\n"); | |
197 | } | |
198 | } | |
199 | } |