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