Line data Source code
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, pcbs (for slats) and HV channels,
25 : /// or all of them.
26 : ///
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 :
45 : #include "AliLog.h"
46 : #include "AliMpArea.h"
47 : #include "AliMpConstants.h"
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"
57 : #include "AliMUON2DMap.h"
58 : #include "AliMUONCalibParamNF.h"
59 : #include "Riostream.h"
60 : #include "TMath.h"
61 :
62 : using std::cout;
63 : using std::endl;
64 : /// \cond CLASSIMP
65 18 : ClassImp(AliMUONRejectList)
66 : /// \endcond
67 :
68 : namespace
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 0 : TString s(str);
79 0 : s += " PROBA %e";
80 :
81 0 : for ( UInt_t i = 0; i < n; ++i )
82 : {
83 0 : UInt_t key = ids[i];
84 0 : Int_t a,b;
85 0 : AliMUONVCalibParam::DecodeUniqueID(key,a,b);
86 0 : if ( s.CountChar('%')==3 )
87 : {
88 0 : cout << Form(s.Data(),a,b,values[i]) << endl;
89 : }
90 : else
91 : {
92 0 : cout << Form(s.Data(),a,values[i]) << endl;
93 : }
94 0 : }
95 :
96 0 : if ( debug )
97 : {
98 0 : cout << "------" << endl;
99 0 : for ( UInt_t i = 0; i < n; ++i )
100 : {
101 0 : UInt_t key = ids[i];
102 0 : Int_t a,b;
103 0 : AliMUONVCalibParam::DecodeUniqueID(key,a,b);
104 0 : cout << Form("ids[%5d]=%d values[%5d]=%e (a,b)=(%5d,%5d)",
105 0 : i,ids[i],i,values[i],a,b) << endl;
106 0 : }
107 :
108 0 : }
109 0 : }
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 12768096 : Long64_t index = TMath::BinarySearch(n,ids,key);
115 :
116 12768096 : Bool_t found = ( ( index >= 0 ) && ( ids[index] == key ) );
117 :
118 6384048 : if ( found )
119 : {
120 0 : return values[index];
121 : }
122 : else
123 : {
124 6384048 : return 0.0;
125 : }
126 6384048 : }
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 0 : for ( UInt_t i = n; i > index; --i )
133 : {
134 0 : ids[i] = ids[i-1];
135 0 : values[i] = values[i-1];
136 : }
137 0 : ids[index] = key;
138 0 : values[index] = value;
139 0 : }
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 0 : Long64_t index = TMath::BinarySearch(n,ids, key);
145 :
146 0 : Bool_t alreadyThere = ( ( index >= 0 ) && ( ids[index] == key ) );
147 :
148 0 : if ( alreadyThere )
149 : {
150 : // replacement
151 0 : values[index] = value;
152 0 : return kFALSE;
153 : }
154 0 : Insert(n,ids,values,index+1,key,value);
155 0 : return kTRUE;
156 0 : }
157 :
158 : void Copy(UInt_t n, UInt_t* src, UInt_t*& dest)
159 : {
160 : /// Copy src into dest
161 0 : delete[] dest;
162 0 : dest = 0;
163 0 : if ( src && n )
164 : {
165 0 : dest = new UInt_t[n];
166 0 : memcpy(dest,src,n*sizeof(UInt_t));
167 0 : }
168 0 : }
169 :
170 : void Copy(UInt_t n, Float_t* src, Float_t*& dest)
171 : {
172 : /// Copy src into dest
173 0 : delete[] dest;
174 0 : dest = 0;
175 0 : if ( src && n )
176 : {
177 0 : dest = new Float_t[n];
178 0 : memcpy(dest,src,n*sizeof(Float_t));
179 0 : }
180 0 : }
181 :
182 : }
183 :
184 : //_____________________________________________________________________________
185 : AliMUONRejectList::AliMUONRejectList()
186 0 : : TObject(),
187 0 : fIsBinary(kTRUE),
188 0 : fMaxNofDEs(156), // not nice to put a constant here, but that way this object does not need the mapping at creation time...
189 0 : fMaxNofBPs(888), // same remark as above
190 0 : fMaxNofManus(16828), // same as above...
191 0 : fNofDEs(),
192 0 : fNofBPs(),
193 0 : fNofManus(),
194 0 : fDEIds(new UInt_t[fMaxNofDEs]),
195 0 : fDEProbas(new Float_t[fMaxNofDEs]),
196 0 : fBPIds(new UInt_t[fMaxNofBPs]),
197 0 : fBPProbas(new Float_t[fMaxNofBPs]),
198 0 : fManuIds(new UInt_t[fMaxNofManus]),
199 0 : fManuProbas(new Float_t[fMaxNofManus]),
200 0 : fChannels(new AliMUON2DMap(kTRUE))
201 0 : {
202 : /// normal ctor
203 0 : memset(fDEIds,0,fMaxNofDEs*sizeof(UInt_t));
204 0 : memset(fDEProbas,0,fMaxNofDEs*sizeof(Float_t));
205 0 : memset(fBPIds,0,fMaxNofBPs*sizeof(UInt_t));
206 0 : memset(fBPProbas,0,fMaxNofBPs*sizeof(Float_t));
207 0 : memset(fManuIds,0,fMaxNofManus*sizeof(UInt_t));
208 0 : memset(fManuProbas,0,fMaxNofManus*sizeof(Float_t));
209 0 : }
210 :
211 : //_____________________________________________________________________________
212 : AliMUONRejectList::AliMUONRejectList(TRootIOCtor* /*ioCtor*/)
213 2 : : TObject(),
214 2 : fIsBinary(kTRUE),
215 2 : fMaxNofDEs(),
216 2 : fMaxNofBPs(),
217 2 : fMaxNofManus(),
218 2 : fNofDEs(),
219 2 : fNofBPs(),
220 2 : fNofManus(0),
221 2 : fDEIds(0x0),
222 2 : fDEProbas(0x0),
223 2 : fBPIds(0x0),
224 2 : fBPProbas(0x0),
225 2 : fManuIds(0x0),
226 2 : fManuProbas(0x0),
227 2 : fChannels(0x0)
228 10 : {
229 : /// ctor from root i/o
230 4 : }
231 :
232 : //_____________________________________________________________________________
233 : AliMUONRejectList::AliMUONRejectList(const AliMUONRejectList& rl)
234 0 : : TObject(rl),
235 0 : fIsBinary(rl.fIsBinary),
236 0 : fMaxNofDEs(rl.fMaxNofDEs),
237 0 : fMaxNofBPs(rl.fMaxNofBPs),
238 0 : fMaxNofManus(rl.fMaxNofManus),
239 0 : fNofDEs(rl.fNofDEs),
240 0 : fNofBPs(rl.fNofBPs),
241 0 : fNofManus(rl.fNofManus),
242 0 : fDEIds(0x0),
243 0 : fDEProbas(0x0),
244 0 : fBPIds(0x0),
245 0 : fBPProbas(0x0),
246 0 : fManuIds(0x0),
247 0 : fManuProbas(0x0),
248 0 : fChannels(0x0)
249 0 : {
250 : /// Copy ctor
251 :
252 0 : ::Copy(rl.fMaxNofDEs,rl.fDEIds,fDEIds);
253 0 : ::Copy(rl.fMaxNofDEs,rl.fDEProbas,fDEProbas);
254 0 : ::Copy(rl.fMaxNofBPs,rl.fBPIds,fBPIds);
255 0 : ::Copy(rl.fMaxNofBPs,rl.fBPProbas,fBPProbas);
256 0 : ::Copy(rl.fMaxNofManus,rl.fManuIds,fManuIds);
257 0 : ::Copy(rl.fMaxNofManus,rl.fManuProbas,fManuProbas);
258 :
259 0 : if ( rl.fChannels )
260 : {
261 0 : fChannels = static_cast<AliMUONVStore*>(rl.fChannels->Clone());
262 0 : }
263 0 : }
264 :
265 : //_____________________________________________________________________________
266 : AliMUONRejectList& AliMUONRejectList::operator=(const AliMUONRejectList& rl)
267 : {
268 : /// assignement operator
269 0 : if ( this != &rl )
270 : {
271 0 : static_cast<TObject&>(*this)=rl;
272 :
273 0 : fIsBinary = rl.fIsBinary;
274 0 : fMaxNofDEs = rl.fMaxNofDEs;
275 0 : fMaxNofBPs = rl.fMaxNofBPs;
276 0 : fMaxNofManus = rl.fMaxNofManus;
277 0 : fNofDEs = rl.fNofDEs;
278 0 : fNofBPs = rl.fNofBPs;
279 0 : fNofManus = rl.fNofManus;
280 :
281 0 : ::Copy(rl.fMaxNofDEs,rl.fDEIds,fDEIds);
282 0 : ::Copy(rl.fMaxNofDEs,rl.fDEProbas,fDEProbas);
283 0 : ::Copy(rl.fMaxNofBPs,rl.fBPIds,fBPIds);
284 0 : ::Copy(rl.fMaxNofBPs,rl.fBPProbas,fBPProbas);
285 0 : ::Copy(rl.fMaxNofManus,rl.fManuIds,fManuIds);
286 0 : ::Copy(rl.fMaxNofManus,rl.fManuProbas,fManuProbas);
287 :
288 0 : delete fChannels;
289 0 : fChannels = 0x0;
290 :
291 0 : if ( rl.fChannels )
292 : {
293 0 : fChannels = static_cast<AliMUONVStore*>(rl.fChannels->Clone());
294 0 : }
295 :
296 : }
297 0 : return *this;
298 : }
299 :
300 : //_____________________________________________________________________________
301 : AliMUONRejectList::~AliMUONRejectList()
302 0 : {
303 : /// dtor
304 0 : delete fChannels;
305 0 : delete[] fDEIds;
306 0 : delete[] fDEProbas;
307 0 : delete[] fBPIds;
308 0 : delete[] fBPProbas;
309 0 : delete[] fManuIds;
310 0 : delete[] fManuProbas;
311 0 : }
312 :
313 : //_____________________________________________________________________________
314 : Float_t AliMUONRejectList::DetectionElementProbability(Int_t detElemId) const
315 : {
316 : /// Get the probability to reject a given detection element
317 4256032 : return ::GetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0));
318 : }
319 :
320 : //_____________________________________________________________________________
321 : Float_t AliMUONRejectList::BusPatchProbability(Int_t busPatchId) const
322 : {
323 : /// Get the probability to reject a given bus patch
324 4256032 : return ::GetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0));
325 : }
326 :
327 : //_____________________________________________________________________________
328 : Float_t AliMUONRejectList::ManuProbability(Int_t detElemId, Int_t manuId) const
329 : {
330 : /// Get the probability to reject a given manu
331 4256032 : return ::GetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId));
332 : }
333 :
334 : //_____________________________________________________________________________
335 : Float_t AliMUONRejectList::ChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
336 : {
337 : /// Get the probability to reject a given channel
338 4256032 : AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
339 4256032 : if (!param) return 0.0;
340 0 : return param->ValueAsFloat(manuChannel);
341 2128016 : }
342 :
343 : //_____________________________________________________________________________
344 : void AliMUONRejectList::SetDetectionElementProbability(Int_t detElemId, Float_t proba)
345 : {
346 : /// Set the probability to reject a given detection element
347 0 : if ( ::SetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0),proba) )
348 : {
349 0 : ++fNofDEs;
350 0 : }
351 :
352 0 : ZeroOrOne(proba);
353 0 : }
354 :
355 : //_____________________________________________________________________________
356 : void AliMUONRejectList::ZeroOrOne(Float_t proba)
357 : {
358 : /// If proba is anything else than 0 or 1, we set fIsBinary to kFALSe
359 :
360 0 : Bool_t zeroorone = ( proba == 0.0 || proba == 1.0 );
361 0 : if (!zeroorone) fIsBinary = kFALSE;
362 0 : }
363 :
364 : //_____________________________________________________________________________
365 : void AliMUONRejectList::SetBusPatchProbability(Int_t busPatchId, Float_t proba)
366 : {
367 : /// Set the probability to reject a given bus patch
368 0 : if ( ::SetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0),proba) )
369 : {
370 0 : ++fNofBPs;
371 0 : }
372 0 : ZeroOrOne(proba);
373 0 : }
374 :
375 : //_____________________________________________________________________________
376 : void AliMUONRejectList::SetManuProbability(Int_t detElemId, Int_t manuId, Float_t proba)
377 : {
378 : /// Set the probability to reject a given manu
379 0 : if ( ::SetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId),proba) )
380 : {
381 0 : ++fNofManus;
382 0 : }
383 0 : ZeroOrOne(proba);
384 0 : }
385 :
386 : //_____________________________________________________________________________
387 : void 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 0 : AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
391 0 : if (!param)
392 : {
393 0 : param = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0.0);
394 0 : fChannels->Add(param);
395 0 : }
396 0 : param->SetValueAsFloat(manuChannel,0,proba);
397 0 : ZeroOrOne(proba);
398 0 : }
399 :
400 : //_____________________________________________________________________________
401 : void 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 0 : AliMpSegmentation* seg = AliMpSegmentation::Instance();
405 0 : AliMp::CathodType ct[] = { AliMp::kCath0, AliMp::kCath1 };
406 :
407 0 : for ( Int_t i = 0; i < 2; ++i )
408 : {
409 0 : const AliMpVSegmentation* vseg = seg->GetMpSegmentation(detElemId,ct[i]);
410 0 : if (!vseg)
411 : {
412 0 : AliError(Form("Could not get segmentation of DE %d",detElemId));
413 0 : continue;
414 : }
415 0 : const AliMpSlat* slat = seg->GetSlat(vseg);
416 0 : if (!slat)
417 : {
418 0 : AliError(Form("Could not get slat from DE %d",detElemId));
419 0 : continue;
420 : }
421 0 : AliMpPCB* pcb = slat->GetPCB(pcbNumber);
422 0 : for ( Int_t j = 0; j < pcb->GetSize(); ++j )
423 : {
424 0 : AliMpMotifPosition* mp = pcb->GetMotifPosition(j);
425 0 : SetManuProbability(detElemId,mp->GetID(),proba);
426 : }
427 0 : }
428 0 : }
429 :
430 : //_____________________________________________________________________________
431 : void 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 0 : AliMpDCSNamer hv("TRACKER");
437 :
438 0 : TString alias = hv.DCSAliasFromName(dcsName);
439 :
440 0 : Int_t detElemId = hv.DetElemIdFromDCSAlias(alias.Data());
441 0 : Int_t index = hv.DCSIndexFromDCSAlias(alias.Data());
442 :
443 0 : AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
444 :
445 0 : const AliMpArrayI* manus = de->ManusForHV(index);
446 :
447 0 : for ( Int_t i = 0; i < manus->GetSize(); ++ i )
448 : {
449 0 : Int_t manuId = manus->GetValue(i);
450 0 : SetManuProbability(detElemId,manuId,proba);
451 : }
452 0 : }
453 :
454 : //_____________________________________________________________________________
455 : void
456 : AliMUONRejectList::Print(Option_t* opt) const
457 : {
458 : /// Printout
459 :
460 0 : TString sopt(opt);
461 0 : sopt.ToUpper();
462 : Bool_t debug(kFALSE);
463 :
464 0 : if ( sopt.Contains("DEBUG") ) debug=kTRUE;
465 :
466 0 : cout << Form("We have probabilities for %d detection element(s), %d bus patch(es), %d manu(s)",
467 0 : fNofDEs,fNofBPs,fNofManus) << endl;
468 :
469 0 : ::Dump("DE %04d",fNofDEs,fDEIds,fDEProbas,debug);
470 0 : ::Dump("BusPatch %04d",fNofBPs,fBPIds,fBPProbas,debug);
471 0 : ::Dump("DE %04d MANU %4d",fNofManus,fManuIds,fManuProbas,debug);
472 0 : }
|