]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/STEERBase/AliTRDPIDReference.cxx
ALIROOT-5633 o limit the momentum range for deuteron and triton in ITSnSigma o Simpli...
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliTRDPIDReference.cxx
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(NULL),
62                   fMomentumBins(ref.fMomentumBins)
63 {
64     //
65     // Copy constructor
66     //
67     fRefContainer = new TObjArray(fMomentumBins.GetSize() * AliPID::kSPECIES);
68     fRefContainer->SetOwner();
69
70     for(Int_t ip = 0; ip < GetNumberOfMomentumBins(); ip++){
71         for(Int_t is = 0; is < 5; is++){
72             Int_t ent=is * fMomentumBins.GetSize() + ip;
73             TObject *obj=ref.fRefContainer->At(ent);
74             if(obj){
75                 fRefContainer->AddAt(obj->Clone(),ent);
76             }
77         }
78     }
79
80     SetBit(kIsOwner, kTRUE);
81 }
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         if(this != &ref){
90                 TNamed::operator=(ref);
91                 if(TestBit(kIsOwner) && fRefContainer) delete fRefContainer;
92                 fRefContainer = ref.fRefContainer;
93                 fMomentumBins = ref.fMomentumBins;
94                 SetBit(kIsOwner, kFALSE);
95         }
96         return *this;
97 }
98
99 //____________________________________________________________
100 AliTRDPIDReference::~AliTRDPIDReference(){
101         //
102         // Destructor
103         // references are deleted if the object is the owner
104         //
105         if(fRefContainer && TestBit(kIsOwner)) delete fRefContainer;
106 }
107
108 //____________________________________________________________
109 void AliTRDPIDReference::SetNumberOfMomentumBins(Int_t nBins, Float_t *momenta){
110         //
111         // Set the momentum binning
112         //
113         if(fRefContainer) fRefContainer->Clear();
114         else{
115                 fRefContainer = new TObjArray;
116                 fRefContainer->SetOwner();
117         }
118         fRefContainer->Expand(nBins * AliPID::kSPECIES);
119         fMomentumBins.Set(nBins,momenta);
120 }
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         if(!fRefContainer){
131                 AliError("Reference Container not initialized");
132                 return;
133         }
134         if(pbin > fMomentumBins.GetSize()){
135                 AliError("Pbin overflow");
136                 return;
137         }
138         AliDebug(1, Form("Adding object with address %p to position %d", ref, spec * fMomentumBins.GetSize() + pbin));
139         fRefContainer->AddAt(ref->Clone(), spec * fMomentumBins.GetSize() + pbin);
140 }
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         pUpper = 20;
151         for(Int_t ip = 0; ip < fMomentumBins.GetSize(); ip++){
152                 AliDebug(10, Form("Bin %d, p = %.1f", ip, fMomentumBins[ip]));
153                 if(p < fMomentumBins[ip]){
154                         AliDebug(10, "Bin found");
155                         bin = ip;
156                         break;
157                 }
158         }
159         AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin));
160         if(bin >= 0) {
161                 pUpper = fMomentumBins[bin];
162                 return fRefContainer->At(spec * fMomentumBins.GetSize() + bin);
163         }
164         else return NULL;
165 }
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         pLower = 0;
176         for(Int_t ip = fMomentumBins.GetSize() - 1; ip >= 0; ip--){
177                 AliDebug(10, Form("Bin %d, p = %.1f", ip, fMomentumBins[ip]));
178                 if(p > fMomentumBins[ip]){
179                         AliDebug(10, "Bin found");
180                         bin = ip;
181                         break;
182                 }
183         }
184         AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin));
185         if(bin >= 0){
186                 pLower = fMomentumBins[bin];
187                 return fRefContainer->At(spec * fMomentumBins.GetSize() + bin);
188         }
189         else return NULL;
190 }
191
192 //____________________________________________________________
193 void AliTRDPIDReference::Print(const Option_t*) const{
194         //
195         // Print content of the PID reference container
196         //
197         printf("Number of Momentum Bins: %d\n", GetNumberOfMomentumBins());
198         printf("=====================================\n");
199         for(Int_t ip = 0; ip < GetNumberOfMomentumBins(); ip++){
200                 printf("Bin %d: p = %.1f\n", ip, fMomentumBins[ip]);
201         }
202         printf("=====================================\n");
203         if(fRefContainer){
204                 printf("Content of the reference container:\n");
205                 for(Int_t ip = 0; ip < GetNumberOfMomentumBins(); ip++){
206                         printf("[");
207                         for(Int_t is = 0; is < 5; is++) printf("%p|", fRefContainer->At(is * fMomentumBins.GetSize() + ip));
208                         printf("]\n");
209                 }
210         }
211 }