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):
61 fRefContainer(ref.fRefContainer),
62 fMomentumBins(ref.fMomentumBins)
66 // Only copies poiters, object is not the owner of the references
68 SetBit(kIsOwner, kFALSE);
71 //____________________________________________________________
72 AliTRDPIDReference &AliTRDPIDReference::operator=(const AliTRDPIDReference &ref){
74 // Assginment operator
75 // Only copies poiters, object is not the owner of the references
78 TNamed::operator=(ref);
79 if(TestBit(kIsOwner) && fRefContainer) delete fRefContainer;
80 fRefContainer = ref.fRefContainer;
81 fMomentumBins = ref.fMomentumBins;
82 SetBit(kIsOwner, kFALSE);
87 //____________________________________________________________
88 AliTRDPIDReference::~AliTRDPIDReference(){
91 // references are deleted if the object is the owner
93 if(fRefContainer && TestBit(kIsOwner)) delete fRefContainer;
96 //____________________________________________________________
97 void AliTRDPIDReference::SetNumberOfMomentumBins(Int_t nBins, Float_t *momenta){
99 // Set the momentum binning
101 if(fRefContainer) fRefContainer->Clear();
103 fRefContainer = new TObjArray;
104 fRefContainer->SetOwner();
106 fRefContainer->Expand(nBins * AliPID::kSPECIES);
107 fMomentumBins.Set(nBins,momenta);
110 //____________________________________________________________
111 void AliTRDPIDReference::AddReference(TObject *ref, AliPID::EParticleType spec, Int_t pbin){
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
119 AliError("Reference Container not initialized");
122 if(pbin > fMomentumBins.GetSize()){
123 AliError("Pbin overflow");
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);
130 //____________________________________________________________
131 TObject *AliTRDPIDReference::GetUpperReference(AliPID::EParticleType spec, Float_t p, Float_t &pUpper) const{
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
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");
147 AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin));
149 pUpper = fMomentumBins[bin];
150 return fRefContainer->At(spec * fMomentumBins.GetSize() + bin);
155 //____________________________________________________________
156 TObject *AliTRDPIDReference::GetLowerReference(AliPID::EParticleType spec, Float_t p, Float_t &pLower) const{
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
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");
172 AliDebug(2, Form("p = %.1f, bin = %d\n", p, bin));
174 pLower = fMomentumBins[bin];
175 return fRefContainer->At(spec * fMomentumBins.GetSize() + bin);
180 //____________________________________________________________
181 void AliTRDPIDReference::Print(const Option_t*) const{
183 // Print content of the PID reference container
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]);
190 printf("=====================================\n");
192 printf("Content of the reference container:\n");
193 for(Int_t ip = 0; ip < GetNumberOfMomentumBins(); ip++){
195 for(Int_t is = 0; is < 5; is++) printf("%p|", fRefContainer->At(is * fMomentumBins.GetSize() + ip));