Update master to aliroot
[u/mrichter/AliRoot.git] / STEER / STEERBase / AliTRDPIDResponseObject.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 //    Daniel Lohner <Daniel.Lohner@cern.ch>
26
27 #include "AliLog.h"
28
29 #include "AliTRDPIDResponseObject.h"
30
31 #ifndef AliTRDPIDREFERENCE_H
32 #include "AliTRDPIDReference.h"
33 #endif
34
35 #ifndef AliTRDPIDPARAMS_H
36 #include "AliTRDPIDParams.h"
37 #endif
38
39
40 ClassImp(AliTRDPIDResponseObject)
41
42 //____________________________________________________________
43 AliTRDPIDResponseObject::AliTRDPIDResponseObject():
44     TNamed(),
45     fNSlicesQ0(4)
46 {
47     //
48     // Dummy constructor
49     //
50     SetBit(kIsOwner, kTRUE);
51
52     for(Int_t method=0;method<AliTRDPIDResponse::kNMethod;method++){
53         fPIDParams[method]=NULL;
54         fPIDReference[method]=NULL;
55     }
56 }
57
58 //____________________________________________________________
59 AliTRDPIDResponseObject::AliTRDPIDResponseObject(const Char_t *name):
60 TNamed(name, "TRD PID Response Object"),
61 fNSlicesQ0(4)
62 {
63         //
64         // Default constructor
65         //
66         SetBit(kIsOwner, kTRUE);
67
68         for(Int_t method=0;method<AliTRDPIDResponse::kNMethod;method++){
69             fPIDParams[method]=NULL;
70             fPIDReference[method]=NULL;
71         }
72 }
73
74 //____________________________________________________________
75 AliTRDPIDResponseObject::AliTRDPIDResponseObject(const AliTRDPIDResponseObject &ref):
76 TNamed(ref),
77 fNSlicesQ0(ref.fNSlicesQ0)
78 {
79     //
80     // Copy constructor
81     // Only copies pointers, object is not the owner of the references
82     //
83     SetBit(kIsOwner, kFALSE);
84
85     for(Int_t method=0;method<AliTRDPIDResponse::kNMethod;method++){
86         fPIDParams[method]=ref.fPIDParams[method];       // new Object is not owner, copy only pointer
87         fPIDReference[method]=ref.fPIDReference[method];    // new Object is not owner, copy only pointer
88     }
89 }
90 //____________________________________________________________
91 AliTRDPIDResponseObject &AliTRDPIDResponseObject::operator=(const AliTRDPIDResponseObject &ref){
92         //
93         // Assginment operator
94         // Only copies poiters, object is not the owner of the references
95         //
96         if(this != &ref){
97             TNamed::operator=(ref);
98             fNSlicesQ0=ref.fNSlicesQ0;
99             for(Int_t method=0;method<AliTRDPIDResponse::kNMethod;method++){
100               if(TestBit(kIsOwner) && fPIDParams[method]){
101                 delete fPIDParams[method];
102                 fPIDParams[method]= 0;
103               }
104               if(TestBit(kIsOwner) && fPIDReference[method]){
105                 delete fPIDReference[method];
106                 fPIDReference[method] = 0;
107               }
108               printf("Assignment");
109               fPIDParams[method]=ref.fPIDParams[method];       // new Object is not owner, copy only pointer
110               fPIDReference[method]=ref.fPIDReference[method];    // new Object is not owner, copy only pointer
111             }
112             SetBit(kIsOwner, kFALSE);
113         }
114         return *this;
115 }
116
117 //____________________________________________________________
118 AliTRDPIDResponseObject::~AliTRDPIDResponseObject(){
119         //
120         // Destructor
121         // references are deleted if the object is the owner
122         //
123     for(Int_t method=0;method<AliTRDPIDResponse::kNMethod;method++){
124         if(fPIDParams[method] && TestBit(kIsOwner)){
125         delete fPIDParams[method];fPIDParams[method] = 0;
126       }
127       if(fPIDReference[method] && TestBit(kIsOwner)){
128         delete fPIDReference[method];
129         fPIDReference[method] = 0;
130       }
131     }
132 }
133
134 //____________________________________________________________
135 void AliTRDPIDResponseObject::SetPIDParams(AliTRDPIDParams *params,AliTRDPIDResponse::ETRDPIDMethod method){
136
137     if(Int_t(method)>=Int_t(AliTRDPIDResponse::kNMethod)||Int_t(method)<0){
138         AliError("Method does not exist");
139         return;
140     }
141     if(fPIDParams[method]){
142         delete fPIDParams[method];
143         fPIDParams[method]=NULL;
144     }
145
146     fPIDParams[method]=new AliTRDPIDParams(*params);
147 }
148
149 //____________________________________________________________
150 void AliTRDPIDResponseObject::SetPIDReference(AliTRDPIDReference *reference,AliTRDPIDResponse::ETRDPIDMethod method){
151
152     if(Int_t(method)>=Int_t(AliTRDPIDResponse::kNMethod)||Int_t(method)<0){
153         AliError("Method does not exist");
154         return;
155     }
156     if(fPIDReference[method]){
157         delete fPIDReference[method];
158         fPIDReference[method]=NULL;
159     }
160     fPIDReference[method]=new AliTRDPIDReference(*reference);
161 }
162
163 //____________________________________________________________
164 TObject *AliTRDPIDResponseObject::GetUpperReference(AliPID::EParticleType spec, Float_t p, Float_t &pUpper,AliTRDPIDResponse::ETRDPIDMethod method) const{
165
166     if(Int_t(method)>=Int_t(AliTRDPIDResponse::kNMethod)||Int_t(method)<0){
167         AliError("Method does not exist");
168         return NULL;
169     }
170    
171     if(fPIDReference[method]){
172         return fPIDReference[method]->GetUpperReference(spec,p,pUpper);
173     }
174     return NULL;
175 }
176
177
178 //____________________________________________________________
179 TObject *AliTRDPIDResponseObject::GetLowerReference(AliPID::EParticleType spec, Float_t p, Float_t &pLower,AliTRDPIDResponse::ETRDPIDMethod method) const{
180
181     if(Int_t(method)>=Int_t(AliTRDPIDResponse::kNMethod)||Int_t(method)<0){
182         AliError("Method does not exist");
183         return NULL;
184     }
185
186     if(fPIDReference[method]){
187          return fPIDReference[method]->GetLowerReference(spec,p,pLower);
188      }
189     return NULL;
190 }
191
192 //____________________________________________________________
193 Bool_t AliTRDPIDResponseObject::GetThresholdParameters(Int_t ntracklets, Double_t efficiency, Double_t *params,Double_t centrality,AliTRDPIDResponse::ETRDPIDMethod method) const{
194
195     if(Int_t(method)>=Int_t(AliTRDPIDResponse::kNMethod)||Int_t(method)<0){
196         AliError("Method does not exist");
197         return kFALSE;
198     }
199
200     if(fPIDParams[method]){
201         return fPIDParams[method]->GetThresholdParameters(ntracklets,efficiency,params,centrality);
202     }
203     AliError("TRD Threshold Container does not exist");
204     return kFALSE;
205 }
206
207 //____________________________________________________________
208 Int_t AliTRDPIDResponseObject::GetNumberOfMomentumBins(AliTRDPIDResponse::ETRDPIDMethod method) const{
209
210     if(Int_t(method)>=Int_t(AliTRDPIDResponse::kNMethod)||Int_t(method)<0){
211         AliError("Method does not exist");
212         return 0;
213     }
214
215     if(fPIDReference[method]){
216         return fPIDReference[method]->GetNumberOfMomentumBins();
217     }
218     return 0;
219 }
220
221 //____________________________________________________________
222 void AliTRDPIDResponseObject::Print(const Option_t* opt) const{
223         //
224         // Print content of the PID object
225         //
226     printf("Content of AliTRDPIDResponseObject \n\n");
227    
228     for(Int_t method=0;method<AliTRDPIDResponse::kNMethod;method++){
229         if(fPIDReference[method])fPIDReference[method]->Print(opt);
230         if(fPIDParams[method])fPIDParams[method]->Print(opt);
231     }
232 }