]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONRejectList.cxx
Updated strong pid algo for Dplus (Giacomo)
[u/mrichter/AliRoot.git] / MUON / AliMUONRejectList.cxx
CommitLineData
fe783497 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// $Id$
17
18///
19/// \class AliMUONRejectList
20///
21/// Object to hold the probability to reject elements during reconstruction.
22///
23/// Those elements are either channels, manus,
24/// bus patches, detection elements, or all the four.
25/// (we do not consider the next level, chamber, because if a full
26/// chamber is missing, we assume we'll remove that run from the
27/// list of usable runs anyway).
28///
29/// The probability of rejection can be different from 0.0 or 1.0 only for
30/// simulations, in which case it means that :
31/// - this object was created from inspection of real data occupancy maps + ad-hoc rejections over
32/// several runs
33/// - the probability then reflects the chance a given element was useable
34/// during data taking. For instance, if one DE has a probability of 0.8, it means
35/// it was on (or correctly behaving during data taking) only for 20% of the
36/// events.
37///
38/// \author Laurent Aphecetche, Subatech
39///
40
41#include "AliMUONRejectList.h"
42
43#include "AliMpConstants.h"
44#include "AliMUON2DMap.h"
45#include "AliMUONCalibParamNF.h"
46#include "Riostream.h"
47#include "TMath.h"
48
49/// \cond CLASSIMP
50ClassImp(AliMUONRejectList)
51/// \endcond
52
53namespace
54{
55 /// The functions below are here to help re-invent the wheel,
56 /// i.e. code something which acts as std::map<int,float>
57 /// to circumvent the fact that AliRoot does not allow STL to be used.
58
59 void Dump(const char* str, UInt_t n, UInt_t* ids, Float_t* values, Bool_t debug)
60 {
61 /// Dump the values array
62
63 TString s(str);
64 s += " PROBA %e";
65
66 for ( UInt_t i = 0; i < n; ++i )
67 {
68 UInt_t key = ids[i];
69 Int_t a,b;
70 AliMUONVCalibParam::DecodeUniqueID(key,a,b);
71 if ( s.CountChar('%')==3 )
72 {
73 cout << Form(s.Data(),a,b,values[i]) << endl;
74 }
75 else
76 {
77 cout << Form(s.Data(),a,values[i]) << endl;
78 }
79 }
80
81 if ( debug )
82 {
83 cout << "------" << endl;
84 for ( UInt_t i = 0; i < n; ++i )
85 {
86 UInt_t key = ids[i];
87 Int_t a,b;
88 AliMUONVCalibParam::DecodeUniqueID(key,a,b);
89 cout << Form("ids[%5d]=%d values[%5d]=%e (a,b)=(%5d,%5d)",
90 i,ids[i],i,values[i],a,b) << endl;
91 }
92
93 }
94 }
95
96 Float_t GetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key)
97 {
98 /// Get the value corresponding to key, or zero if not found
99 Long64_t index = TMath::BinarySearch(n,ids,key);
100
101 Bool_t found = ( ( index >= 0 ) && ( ids[index] == key ) );
102
103 if ( found )
104 {
105 return values[index];
106 }
107 else
108 {
109 return 0.0;
110 }
111 }
112
113 void Insert(UInt_t n, UInt_t* ids, Float_t* values, UInt_t index, UInt_t key, Float_t value)
114 {
115 /// Insert (key,value) into arrays ids and values.
116
117 for ( UInt_t i = n; i > index; --i )
118 {
119 ids[i] = ids[i-1];
120 values[i] = values[i-1];
121 }
122 ids[index] = key;
123 values[index] = value;
124 }
125
126 Bool_t SetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key, Float_t value)
127 {
128 /// Set the value for a given key
129 Long64_t index = TMath::BinarySearch(n,ids, key);
130
131 Bool_t alreadyThere = ( ( index >= 0 ) && ( ids[index] == key ) );
132
133 if ( alreadyThere )
134 {
135 // replacement
136 values[index] = value;
137 return kFALSE;
138 }
139 Insert(n,ids,values,index+1,key,value);
140 return kTRUE;
141 }
142
143 void Copy(UInt_t n, UInt_t* src, UInt_t*& dest)
144 {
145 /// Copy src into dest
146 delete[] dest;
62b6f26d 147 dest = 0;
148 if ( src && n )
149 {
150 dest = new UInt_t[n];
151 memcpy(src,dest,n*sizeof(UInt_t));
152 }
fe783497 153 }
154
155 void Copy(UInt_t n, Float_t* src, Float_t*& dest)
156 {
157 /// Copy src into dest
158 delete[] dest;
62b6f26d 159 dest = 0;
160 if ( src && n )
161 {
162 dest = new Float_t[n];
163 memcpy(src,dest,n*sizeof(Float_t));
164 }
fe783497 165 }
166
167}
168
169//_____________________________________________________________________________
170AliMUONRejectList::AliMUONRejectList()
171: TObject(),
172fIsBinary(kTRUE),
173fMaxNofDEs(156), // not nice to put a constant here, but that way this object does not need the mapping at creation time...
174fMaxNofBPs(888), // same remark as above
175fMaxNofManus(16828), // same as above...
176fNofDEs(),
177fNofBPs(),
178fNofManus(),
179fDEIds(new UInt_t[fMaxNofDEs]),
180fDEProbas(new Float_t[fMaxNofDEs]),
181fBPIds(new UInt_t[fMaxNofBPs]),
182fBPProbas(new Float_t[fMaxNofBPs]),
183fManuIds(new UInt_t[fMaxNofManus]),
184fManuProbas(new Float_t[fMaxNofManus]),
185fChannels(new AliMUON2DMap(kTRUE))
186{
187 /// normal ctor
188 memset(fDEIds,0,fMaxNofDEs*sizeof(UInt_t));
74343395 189 memset(fDEProbas,0,fMaxNofDEs*sizeof(Float_t));
fe783497 190 memset(fBPIds,0,fMaxNofBPs*sizeof(UInt_t));
74343395 191 memset(fBPProbas,0,fMaxNofBPs*sizeof(Float_t));
fe783497 192 memset(fManuIds,0,fMaxNofManus*sizeof(UInt_t));
74343395 193 memset(fManuProbas,0,fMaxNofManus*sizeof(Float_t));
fe783497 194}
195
196//_____________________________________________________________________________
197AliMUONRejectList::AliMUONRejectList(TRootIOCtor* /*ioCtor*/)
198: TObject(),
199fIsBinary(kTRUE),
200fMaxNofDEs(),
201fMaxNofBPs(),
202fMaxNofManus(),
203fNofDEs(),
204fNofBPs(),
205fNofManus(0),
206fDEIds(0x0),
207fDEProbas(0x0),
208fBPIds(0x0),
209fBPProbas(0x0),
210fManuIds(0x0),
211fManuProbas(0x0),
212fChannels(0x0)
213{
214 /// ctor from root i/o
215}
216
217//_____________________________________________________________________________
218AliMUONRejectList::AliMUONRejectList(const AliMUONRejectList& rl)
219: TObject(rl),
220fIsBinary(kTRUE),
221fMaxNofDEs(),
222fMaxNofBPs(),
223fMaxNofManus(),
224fNofDEs(),
225fNofBPs(),
226fNofManus(0),
227fDEIds(0x0),
228fDEProbas(0x0),
229fBPIds(0x0),
230fBPProbas(0x0),
231fManuIds(0x0),
232fManuProbas(0x0),
233fChannels(0x0)
234{
235 /// Copy ctor
236 rl.CopyTo(*this);
237}
238
239//_____________________________________________________________________________
240AliMUONRejectList& AliMUONRejectList::operator=(const AliMUONRejectList& rl)
241{
242 /// assignement operator
6350d0c0 243 if ( this != &rl )
244 {
245 rl.CopyTo(*this);
246 }
fe783497 247 return *this;
248}
249
250//_____________________________________________________________________________
251void
252AliMUONRejectList::CopyTo(AliMUONRejectList& rl) const
253{
254 /// Copy this to rl
255 TObject::Copy(rl);
256
257 rl.fIsBinary = fIsBinary;
258
259 ::Copy(rl.fMaxNofDEs,fDEIds,rl.fDEIds);
260 ::Copy(rl.fMaxNofDEs,fDEProbas,rl.fDEProbas);
261 ::Copy(rl.fMaxNofBPs,fBPIds,rl.fBPIds);
262 ::Copy(rl.fMaxNofBPs,fBPProbas,rl.fBPProbas);
263 ::Copy(rl.fMaxNofManus,fManuIds,rl.fManuIds);
264 ::Copy(rl.fMaxNofManus,fManuProbas,rl.fManuProbas);
265
266 delete rl.fChannels;
62b6f26d 267 rl.fChannels = 0x0;
268
269 if ( fChannels )
270 {
271 rl.fChannels = static_cast<AliMUONVStore*>(fChannels->Clone());
272 }
fe783497 273}
274
275//_____________________________________________________________________________
276AliMUONRejectList::~AliMUONRejectList()
277{
278 /// dtor
279 delete fChannels;
280 delete[] fDEIds;
281 delete[] fDEProbas;
282 delete[] fBPIds;
283 delete[] fBPProbas;
284 delete[] fManuIds;
285 delete[] fManuProbas;
286}
287
288//_____________________________________________________________________________
289Float_t AliMUONRejectList::DetectionElementProbability(Int_t detElemId) const
290{
291 /// Get the probability to reject a given detection element
292 return ::GetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0));
293}
294
295//_____________________________________________________________________________
296Float_t AliMUONRejectList::BusPatchProbability(Int_t busPatchId) const
297{
298 /// Get the probability to reject a given bus patch
299 return ::GetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0));
300}
301
302//_____________________________________________________________________________
303Float_t AliMUONRejectList::ManuProbability(Int_t detElemId, Int_t manuId) const
304{
305 /// Get the probability to reject a given manu
306 return ::GetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId));
307}
308
309//_____________________________________________________________________________
310Float_t AliMUONRejectList::ChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
311{
312 /// Get the probability to reject a given channel
313 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
314 if (!param) return 0.0;
315 return param->ValueAsFloat(manuChannel);
316}
317
318//_____________________________________________________________________________
319void AliMUONRejectList::SetDetectionElementProbability(Int_t detElemId, Float_t proba)
320{
321 /// Set the probability to reject a given detection element
322 if ( ::SetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0),proba) )
323 {
324 ++fNofDEs;
325 }
326
327 ZeroOrOne(proba);
328}
329
330//_____________________________________________________________________________
331void AliMUONRejectList::ZeroOrOne(Float_t proba)
332{
333 /// If proba is anything else than 0 or 1, we set fIsBinary to kFALSe
334
335 Bool_t zeroorone = ( proba == 0.0 || proba == 1.0 );
336 if (!zeroorone) fIsBinary = kFALSE;
337}
338
339//_____________________________________________________________________________
340void AliMUONRejectList::SetBusPatchProbability(Int_t busPatchId, Float_t proba)
341{
342 /// Set the probability to reject a given bus patch
343 if ( ::SetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0),proba) )
344 {
345 ++fNofBPs;
346 }
347 ZeroOrOne(proba);
348}
349
350//_____________________________________________________________________________
351void AliMUONRejectList::SetManuProbability(Int_t detElemId, Int_t manuId, Float_t proba)
352{
353 /// Set the probability to reject a given manu
354 if ( ::SetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId),proba) )
355 {
356 ++fNofManus;
357 }
358 ZeroOrOne(proba);
359}
360
361//_____________________________________________________________________________
362void AliMUONRejectList::SetChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t proba)
363{
364 /// Set the probability to reject a given channel
365 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
366 if (!param)
367 {
368 param = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0.0);
369 fChannels->Add(param);
370 }
371 param->SetValueAsFloat(manuChannel,0,proba);
372 ZeroOrOne(proba);
373}
374
375//_____________________________________________________________________________
376void
377AliMUONRejectList::Print(Option_t* opt) const
378{
379 /// Printout
380
381 TString sopt(opt);
382 sopt.ToUpper();
383 Bool_t debug(kFALSE);
384
385 if ( sopt.Contains("DEBUG") ) debug=kTRUE;
386
387 cout << Form("We have probabilities for %d detection element(s), %d bus patch(es), %d manu(s)",
388 fNofDEs,fNofBPs,fNofManus) << endl;
389
390 ::Dump("DE %04d",fNofDEs,fDEIds,fDEProbas,debug);
391 ::Dump("BusPatch %04d",fNofBPs,fBPIds,fBPProbas,debug);
392 ::Dump("DE %04d MANU %4d",fNofManus,fManuIds,fManuProbas,debug);
393}