removed obsolete AliMUONAlignmentRecord classes (AliMillePedeRecord is now used,...
[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,
6bf5f165 24/// bus patches, detection elements, pcbs (for slats) and HV channels,
25/// or all of them.
26///
fe783497 27/// (we do not consider the next level, chamber, because if a full
28/// chamber is missing, we assume we'll remove that run from the
29/// list of usable runs anyway).
30///
31/// The probability of rejection can be different from 0.0 or 1.0 only for
32/// simulations, in which case it means that :
33/// - this object was created from inspection of real data occupancy maps + ad-hoc rejections over
34/// several runs
35/// - the probability then reflects the chance a given element was useable
36/// during data taking. For instance, if one DE has a probability of 0.8, it means
37/// it was on (or correctly behaving during data taking) only for 20% of the
38/// events.
39///
40/// \author Laurent Aphecetche, Subatech
41///
42
43#include "AliMUONRejectList.h"
44
6bf5f165 45#include "AliLog.h"
46#include "AliMpArea.h"
fe783497 47#include "AliMpConstants.h"
6bf5f165 48#include "AliMpDCSNamer.h"
49#include "AliMpDDLStore.h"
50#include "AliMpDEStore.h"
51#include "AliMpDetElement.h"
52#include "AliMpMotifPosition.h"
53#include "AliMpPCB.h"
54#include "AliMpSegmentation.h"
55#include "AliMpSlat.h"
56#include "AliMpVSegmentation.h"
fe783497 57#include "AliMUON2DMap.h"
58#include "AliMUONCalibParamNF.h"
59#include "Riostream.h"
60#include "TMath.h"
61
b80faac0 62using std::cout;
63using std::endl;
fe783497 64/// \cond CLASSIMP
65ClassImp(AliMUONRejectList)
66/// \endcond
67
68namespace
69{
70 /// The functions below are here to help re-invent the wheel,
71 /// i.e. code something which acts as std::map<int,float>
72 /// to circumvent the fact that AliRoot does not allow STL to be used.
73
74 void Dump(const char* str, UInt_t n, UInt_t* ids, Float_t* values, Bool_t debug)
75 {
76 /// Dump the values array
77
78 TString s(str);
79 s += " PROBA %e";
80
81 for ( UInt_t i = 0; i < n; ++i )
82 {
83 UInt_t key = ids[i];
84 Int_t a,b;
85 AliMUONVCalibParam::DecodeUniqueID(key,a,b);
86 if ( s.CountChar('%')==3 )
87 {
88 cout << Form(s.Data(),a,b,values[i]) << endl;
89 }
90 else
91 {
92 cout << Form(s.Data(),a,values[i]) << endl;
93 }
94 }
95
96 if ( debug )
97 {
98 cout << "------" << endl;
99 for ( UInt_t i = 0; i < n; ++i )
100 {
101 UInt_t key = ids[i];
102 Int_t a,b;
103 AliMUONVCalibParam::DecodeUniqueID(key,a,b);
104 cout << Form("ids[%5d]=%d values[%5d]=%e (a,b)=(%5d,%5d)",
105 i,ids[i],i,values[i],a,b) << endl;
106 }
107
108 }
109 }
110
111 Float_t GetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key)
112 {
113 /// Get the value corresponding to key, or zero if not found
114 Long64_t index = TMath::BinarySearch(n,ids,key);
115
116 Bool_t found = ( ( index >= 0 ) && ( ids[index] == key ) );
117
118 if ( found )
119 {
120 return values[index];
121 }
122 else
123 {
124 return 0.0;
125 }
126 }
127
128 void Insert(UInt_t n, UInt_t* ids, Float_t* values, UInt_t index, UInt_t key, Float_t value)
129 {
130 /// Insert (key,value) into arrays ids and values.
131
132 for ( UInt_t i = n; i > index; --i )
133 {
134 ids[i] = ids[i-1];
135 values[i] = values[i-1];
136 }
137 ids[index] = key;
138 values[index] = value;
139 }
140
141 Bool_t SetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key, Float_t value)
142 {
143 /// Set the value for a given key
144 Long64_t index = TMath::BinarySearch(n,ids, key);
145
146 Bool_t alreadyThere = ( ( index >= 0 ) && ( ids[index] == key ) );
147
148 if ( alreadyThere )
149 {
150 // replacement
151 values[index] = value;
152 return kFALSE;
153 }
154 Insert(n,ids,values,index+1,key,value);
155 return kTRUE;
156 }
157
158 void Copy(UInt_t n, UInt_t* src, UInt_t*& dest)
159 {
160 /// Copy src into dest
161 delete[] dest;
62b6f26d 162 dest = 0;
163 if ( src && n )
164 {
165 dest = new UInt_t[n];
c6496ae2 166 memcpy(dest,src,n*sizeof(UInt_t));
62b6f26d 167 }
fe783497 168 }
169
170 void Copy(UInt_t n, Float_t* src, Float_t*& dest)
171 {
172 /// Copy src into dest
173 delete[] dest;
62b6f26d 174 dest = 0;
175 if ( src && n )
176 {
177 dest = new Float_t[n];
c6496ae2 178 memcpy(dest,src,n*sizeof(Float_t));
62b6f26d 179 }
fe783497 180 }
181
182}
183
184//_____________________________________________________________________________
185AliMUONRejectList::AliMUONRejectList()
186: TObject(),
187fIsBinary(kTRUE),
188fMaxNofDEs(156), // not nice to put a constant here, but that way this object does not need the mapping at creation time...
189fMaxNofBPs(888), // same remark as above
190fMaxNofManus(16828), // same as above...
191fNofDEs(),
192fNofBPs(),
193fNofManus(),
194fDEIds(new UInt_t[fMaxNofDEs]),
195fDEProbas(new Float_t[fMaxNofDEs]),
196fBPIds(new UInt_t[fMaxNofBPs]),
197fBPProbas(new Float_t[fMaxNofBPs]),
198fManuIds(new UInt_t[fMaxNofManus]),
199fManuProbas(new Float_t[fMaxNofManus]),
200fChannels(new AliMUON2DMap(kTRUE))
201{
202 /// normal ctor
203 memset(fDEIds,0,fMaxNofDEs*sizeof(UInt_t));
74343395 204 memset(fDEProbas,0,fMaxNofDEs*sizeof(Float_t));
fe783497 205 memset(fBPIds,0,fMaxNofBPs*sizeof(UInt_t));
74343395 206 memset(fBPProbas,0,fMaxNofBPs*sizeof(Float_t));
fe783497 207 memset(fManuIds,0,fMaxNofManus*sizeof(UInt_t));
74343395 208 memset(fManuProbas,0,fMaxNofManus*sizeof(Float_t));
fe783497 209}
210
211//_____________________________________________________________________________
212AliMUONRejectList::AliMUONRejectList(TRootIOCtor* /*ioCtor*/)
213: TObject(),
214fIsBinary(kTRUE),
215fMaxNofDEs(),
216fMaxNofBPs(),
217fMaxNofManus(),
218fNofDEs(),
219fNofBPs(),
220fNofManus(0),
221fDEIds(0x0),
222fDEProbas(0x0),
223fBPIds(0x0),
224fBPProbas(0x0),
225fManuIds(0x0),
226fManuProbas(0x0),
227fChannels(0x0)
228{
229 /// ctor from root i/o
230}
231
232//_____________________________________________________________________________
233AliMUONRejectList::AliMUONRejectList(const AliMUONRejectList& rl)
234: TObject(rl),
c6496ae2 235fIsBinary(rl.fIsBinary),
236fMaxNofDEs(rl.fMaxNofDEs),
237fMaxNofBPs(rl.fMaxNofBPs),
238fMaxNofManus(rl.fMaxNofManus),
239fNofDEs(rl.fNofDEs),
240fNofBPs(rl.fNofBPs),
241fNofManus(rl.fNofManus),
fe783497 242fDEIds(0x0),
243fDEProbas(0x0),
244fBPIds(0x0),
245fBPProbas(0x0),
246fManuIds(0x0),
247fManuProbas(0x0),
248fChannels(0x0)
249{
250 /// Copy ctor
c6496ae2 251
252 ::Copy(rl.fMaxNofDEs,rl.fDEIds,fDEIds);
253 ::Copy(rl.fMaxNofDEs,rl.fDEProbas,fDEProbas);
254 ::Copy(rl.fMaxNofBPs,rl.fBPIds,fBPIds);
255 ::Copy(rl.fMaxNofBPs,rl.fBPProbas,fBPProbas);
256 ::Copy(rl.fMaxNofManus,rl.fManuIds,fManuIds);
257 ::Copy(rl.fMaxNofManus,rl.fManuProbas,fManuProbas);
258
259 if ( rl.fChannels )
260 {
261 fChannels = static_cast<AliMUONVStore*>(rl.fChannels->Clone());
262 }
fe783497 263}
264
265//_____________________________________________________________________________
266AliMUONRejectList& AliMUONRejectList::operator=(const AliMUONRejectList& rl)
267{
268 /// assignement operator
6350d0c0 269 if ( this != &rl )
270 {
c6496ae2 271 static_cast<TObject&>(*this)=rl;
272
273 fIsBinary = rl.fIsBinary;
274 fMaxNofDEs = rl.fMaxNofDEs;
275 fMaxNofBPs = rl.fMaxNofBPs;
276 fMaxNofManus = rl.fMaxNofManus;
277 fNofDEs = rl.fNofDEs;
278 fNofBPs = rl.fNofBPs;
279 fNofManus = rl.fNofManus;
280
281 ::Copy(rl.fMaxNofDEs,rl.fDEIds,fDEIds);
282 ::Copy(rl.fMaxNofDEs,rl.fDEProbas,fDEProbas);
283 ::Copy(rl.fMaxNofBPs,rl.fBPIds,fBPIds);
284 ::Copy(rl.fMaxNofBPs,rl.fBPProbas,fBPProbas);
285 ::Copy(rl.fMaxNofManus,rl.fManuIds,fManuIds);
286 ::Copy(rl.fMaxNofManus,rl.fManuProbas,fManuProbas);
287
288 delete fChannels;
289 fChannels = 0x0;
290
291 if ( rl.fChannels )
292 {
293 fChannels = static_cast<AliMUONVStore*>(rl.fChannels->Clone());
294 }
295
6350d0c0 296 }
fe783497 297 return *this;
298}
299
300//_____________________________________________________________________________
fe783497 301AliMUONRejectList::~AliMUONRejectList()
302{
303 /// dtor
304 delete fChannels;
305 delete[] fDEIds;
306 delete[] fDEProbas;
307 delete[] fBPIds;
308 delete[] fBPProbas;
309 delete[] fManuIds;
310 delete[] fManuProbas;
311}
312
313//_____________________________________________________________________________
314Float_t AliMUONRejectList::DetectionElementProbability(Int_t detElemId) const
315{
316 /// Get the probability to reject a given detection element
317 return ::GetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0));
318}
319
320//_____________________________________________________________________________
321Float_t AliMUONRejectList::BusPatchProbability(Int_t busPatchId) const
322{
323 /// Get the probability to reject a given bus patch
324 return ::GetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0));
325}
326
327//_____________________________________________________________________________
328Float_t AliMUONRejectList::ManuProbability(Int_t detElemId, Int_t manuId) const
329{
330 /// Get the probability to reject a given manu
331 return ::GetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId));
332}
333
334//_____________________________________________________________________________
335Float_t AliMUONRejectList::ChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
336{
337 /// Get the probability to reject a given channel
338 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
339 if (!param) return 0.0;
340 return param->ValueAsFloat(manuChannel);
341}
342
343//_____________________________________________________________________________
344void AliMUONRejectList::SetDetectionElementProbability(Int_t detElemId, Float_t proba)
345{
346 /// Set the probability to reject a given detection element
347 if ( ::SetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0),proba) )
348 {
349 ++fNofDEs;
350 }
351
352 ZeroOrOne(proba);
353}
354
355//_____________________________________________________________________________
356void AliMUONRejectList::ZeroOrOne(Float_t proba)
357{
358 /// If proba is anything else than 0 or 1, we set fIsBinary to kFALSe
359
360 Bool_t zeroorone = ( proba == 0.0 || proba == 1.0 );
361 if (!zeroorone) fIsBinary = kFALSE;
362}
363
364//_____________________________________________________________________________
365void AliMUONRejectList::SetBusPatchProbability(Int_t busPatchId, Float_t proba)
366{
367 /// Set the probability to reject a given bus patch
368 if ( ::SetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0),proba) )
369 {
370 ++fNofBPs;
371 }
372 ZeroOrOne(proba);
373}
374
375//_____________________________________________________________________________
376void AliMUONRejectList::SetManuProbability(Int_t detElemId, Int_t manuId, Float_t proba)
377{
378 /// Set the probability to reject a given manu
379 if ( ::SetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId),proba) )
380 {
381 ++fNofManus;
382 }
383 ZeroOrOne(proba);
384}
385
386//_____________________________________________________________________________
387void AliMUONRejectList::SetChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t proba)
388{
389 /// Set the probability to reject a given channel
390 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
391 if (!param)
392 {
393 param = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0.0);
394 fChannels->Add(param);
395 }
396 param->SetValueAsFloat(manuChannel,0,proba);
397 ZeroOrOne(proba);
398}
399
400//_____________________________________________________________________________
6bf5f165 401void AliMUONRejectList::SetPCBProbability(Int_t detElemId, Int_t pcbNumber, Float_t proba)
402{
403 /// Set the probability to reject all the manus of a given (slat) PCB
404 AliMpSegmentation* seg = AliMpSegmentation::Instance();
405 AliMp::CathodType ct[] = { AliMp::kCath0, AliMp::kCath1 };
406
407 for ( Int_t i = 0; i < 2; ++i )
408 {
409 const AliMpVSegmentation* vseg = seg->GetMpSegmentation(detElemId,ct[i]);
410 if (!vseg)
411 {
412 AliError(Form("Could not get segmentation of DE %d",detElemId));
413 continue;
414 }
415 const AliMpSlat* slat = seg->GetSlat(vseg);
416 if (!slat)
417 {
418 AliError(Form("Could not get slat from DE %d",detElemId));
419 continue;
420 }
421 AliMpPCB* pcb = slat->GetPCB(pcbNumber);
422 for ( Int_t j = 0; j < pcb->GetSize(); ++j )
423 {
424 AliMpMotifPosition* mp = pcb->GetMotifPosition(j);
425 SetManuProbability(detElemId,mp->GetID(),proba);
426 }
427 }
428}
429
430//_____________________________________________________________________________
431void AliMUONRejectList::SetHVProbability(const char* dcsName, Float_t proba)
432{
433 /// Set the probability to reject all the manus of a given HV part
434 /// Caution : the dcs string is a dcs NAME, _not_ an alias
435
436 AliMpDCSNamer hv("TRACKER");
437
438 TString alias = hv.DCSAliasFromName(dcsName);
439
440 Int_t detElemId = hv.DetElemIdFromDCSAlias(alias.Data());
441 Int_t index = hv.DCSIndexFromDCSAlias(alias.Data());
442
443 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
444
445 const AliMpArrayI* manus = de->ManusForHV(index);
446
447 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
448 {
449 Int_t manuId = manus->GetValue(i);
450 SetManuProbability(detElemId,manuId,proba);
451 }
452}
453
454//_____________________________________________________________________________
fe783497 455void
456AliMUONRejectList::Print(Option_t* opt) const
457{
458 /// Printout
459
460 TString sopt(opt);
461 sopt.ToUpper();
462 Bool_t debug(kFALSE);
463
464 if ( sopt.Contains("DEBUG") ) debug=kTRUE;
465
466 cout << Form("We have probabilities for %d detection element(s), %d bus patch(es), %d manu(s)",
467 fNofDEs,fNofBPs,fNofManus) << endl;
468
469 ::Dump("DE %04d",fNofDEs,fDEIds,fDEProbas,debug);
470 ::Dump("BusPatch %04d",fNofBPs,fBPIds,fBPProbas,debug);
471 ::Dump("DE %04d MANU %4d",fNofManus,fManuIds,fManuProbas,debug);
472}