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