1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
24 // Markus Fasel <M.Fasel@gsi.de>
26 #include "TObjArray.h"
30 #include "AliTRDPIDReference.h"
32 ClassImp(AliTRDPIDReference)
34 //____________________________________________________________
35 AliTRDPIDReference::AliTRDPIDReference():
43 SetBit(kIsOwner, kTRUE);
46 //____________________________________________________________
47 AliTRDPIDReference::AliTRDPIDReference(const Char_t *name):
48 TNamed(name, "TRD PID References"),
53 // Default constructor
55 SetBit(kIsOwner, kTRUE);
58 //____________________________________________________________
59 AliTRDPIDReference::AliTRDPIDReference(const AliTRDPIDReference &ref):
62 fMomentumBins(ref.fMomentumBins)
67 fRefContainer = new TObjArray(fMomentumBins.GetSize() * AliPID::kSPECIES);
68 fRefContainer->SetOwner();
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);
75 fRefContainer->AddAt(obj->Clone(),ent);
80 SetBit(kIsOwner, kTRUE);
83 //____________________________________________________________
84 AliTRDPIDReference &AliTRDPIDReference::operator=(const AliTRDPIDReference &ref){
86 // Assginment operator
87 // Only copies poiters, object is not the owner of the references
90 TNamed::operator=(ref);
91 if(TestBit(kIsOwner) && fRefContainer) delete fRefContainer;
92 fRefContainer = ref.fRefContainer;
93 fMomentumBins = ref.fMomentumBins;
94 SetBit(kIsOwner, kFALSE);
99 //____________________________________________________________
100 AliTRDPIDReference::~AliTRDPIDReference(){
103 // references are deleted if the object is the owner
105 if(fRefContainer && TestBit(kIsOwner)) delete fRefContainer;
108 //____________________________________________________________
109 void AliTRDPIDReference::SetNumberOfMomentumBins(Int_t nBins, Float_t *momenta){
111 // Set the momentum binning
113 if(fRefContainer) fRefContainer->Clear();
115 fRefContainer = new TObjArray;
116 fRefContainer->SetOwner();
118 fRefContainer->Expand(nBins * AliPID::kSPECIES);
119 fMomentumBins.Set(nBins,momenta);
122 //____________________________________________________________
123 void AliTRDPIDReference::AddReference(TObject *ref, AliPID::EParticleType spec, Int_t pbin){
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
131 AliError("Reference Container not initialized");
134 if(pbin > fMomentumBins.GetSize()){
135 AliError("Pbin overflow");
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);
142 //____________________________________________________________
143 TObject *AliTRDPIDReference::GetUpperReference(AliPID::EParticleType spec, Float_t p, Float_t &pUpper) const{
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
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");
159 AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin));
161 pUpper = fMomentumBins[bin];
162 return fRefContainer->At(spec * fMomentumBins.GetSize() + bin);
167 //____________________________________________________________
168 TObject *AliTRDPIDReference::GetLowerReference(AliPID::EParticleType spec, Float_t p, Float_t &pLower) const{
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
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");
184 AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin));
186 pLower = fMomentumBins[bin];
187 return fRefContainer->At(spec * fMomentumBins.GetSize() + bin);
192 //____________________________________________________________
193 void AliTRDPIDReference::Print(const Option_t*) const{
195 // Print content of the PID reference container
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]);
202 printf("=====================================\n");
204 printf("Content of the reference container:\n");
205 for(Int_t ip = 0; ip < GetNumberOfMomentumBins(); ip++){
207 for(Int_t is = 0; is < 5; is++) printf("%p|", fRefContainer->At(is * fMomentumBins.GetSize() + ip));