1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 /// \class AliMUONRejectList
21 /// Object to hold the probability to reject elements during reconstruction.
23 /// Those elements are either channels, manus,
24 /// bus patches, detection elements, pcbs (for slats) and HV channels,
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).
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
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
40 /// \author Laurent Aphecetche, Subatech
43 #include "AliMUONRejectList.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"
54 #include "AliMpSegmentation.h"
55 #include "AliMpSlat.h"
56 #include "AliMpVSegmentation.h"
57 #include "AliMUON2DMap.h"
58 #include "AliMUONCalibParamNF.h"
59 #include "Riostream.h"
65 ClassImp(AliMUONRejectList)
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.
74 void Dump(const char* str, UInt_t n, UInt_t* ids, Float_t* values, Bool_t debug)
76 /// Dump the values array
81 for ( UInt_t i = 0; i < n; ++i )
85 AliMUONVCalibParam::DecodeUniqueID(key,a,b);
86 if ( s.CountChar('%')==3 )
88 cout << Form(s.Data(),a,b,values[i]) << endl;
92 cout << Form(s.Data(),a,values[i]) << endl;
98 cout << "------" << endl;
99 for ( UInt_t i = 0; i < n; ++i )
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;
111 Float_t GetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key)
113 /// Get the value corresponding to key, or zero if not found
114 Long64_t index = TMath::BinarySearch(n,ids,key);
116 Bool_t found = ( ( index >= 0 ) && ( ids[index] == key ) );
120 return values[index];
128 void Insert(UInt_t n, UInt_t* ids, Float_t* values, UInt_t index, UInt_t key, Float_t value)
130 /// Insert (key,value) into arrays ids and values.
132 for ( UInt_t i = n; i > index; --i )
135 values[i] = values[i-1];
138 values[index] = value;
141 Bool_t SetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key, Float_t value)
143 /// Set the value for a given key
144 Long64_t index = TMath::BinarySearch(n,ids, key);
146 Bool_t alreadyThere = ( ( index >= 0 ) && ( ids[index] == key ) );
151 values[index] = value;
154 Insert(n,ids,values,index+1,key,value);
158 void Copy(UInt_t n, UInt_t* src, UInt_t*& dest)
160 /// Copy src into dest
165 dest = new UInt_t[n];
166 memcpy(dest,src,n*sizeof(UInt_t));
170 void Copy(UInt_t n, Float_t* src, Float_t*& dest)
172 /// Copy src into dest
177 dest = new Float_t[n];
178 memcpy(dest,src,n*sizeof(Float_t));
184 //_____________________________________________________________________________
185 AliMUONRejectList::AliMUONRejectList()
188 fMaxNofDEs(156), // not nice to put a constant here, but that way this object does not need the mapping at creation time...
189 fMaxNofBPs(888), // same remark as above
190 fMaxNofManus(16828), // same as above...
194 fDEIds(new UInt_t[fMaxNofDEs]),
195 fDEProbas(new Float_t[fMaxNofDEs]),
196 fBPIds(new UInt_t[fMaxNofBPs]),
197 fBPProbas(new Float_t[fMaxNofBPs]),
198 fManuIds(new UInt_t[fMaxNofManus]),
199 fManuProbas(new Float_t[fMaxNofManus]),
200 fChannels(new AliMUON2DMap(kTRUE))
203 memset(fDEIds,0,fMaxNofDEs*sizeof(UInt_t));
204 memset(fDEProbas,0,fMaxNofDEs*sizeof(Float_t));
205 memset(fBPIds,0,fMaxNofBPs*sizeof(UInt_t));
206 memset(fBPProbas,0,fMaxNofBPs*sizeof(Float_t));
207 memset(fManuIds,0,fMaxNofManus*sizeof(UInt_t));
208 memset(fManuProbas,0,fMaxNofManus*sizeof(Float_t));
211 //_____________________________________________________________________________
212 AliMUONRejectList::AliMUONRejectList(TRootIOCtor* /*ioCtor*/)
229 /// ctor from root i/o
232 //_____________________________________________________________________________
233 AliMUONRejectList::AliMUONRejectList(const AliMUONRejectList& rl)
235 fIsBinary(rl.fIsBinary),
236 fMaxNofDEs(rl.fMaxNofDEs),
237 fMaxNofBPs(rl.fMaxNofBPs),
238 fMaxNofManus(rl.fMaxNofManus),
241 fNofManus(rl.fNofManus),
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);
261 fChannels = static_cast<AliMUONVStore*>(rl.fChannels->Clone());
265 //_____________________________________________________________________________
266 AliMUONRejectList& AliMUONRejectList::operator=(const AliMUONRejectList& rl)
268 /// assignement operator
271 static_cast<TObject&>(*this)=rl;
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;
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);
293 fChannels = static_cast<AliMUONVStore*>(rl.fChannels->Clone());
300 //_____________________________________________________________________________
301 AliMUONRejectList::~AliMUONRejectList()
310 delete[] fManuProbas;
313 //_____________________________________________________________________________
314 Float_t AliMUONRejectList::DetectionElementProbability(Int_t detElemId) const
316 /// Get the probability to reject a given detection element
317 return ::GetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0));
320 //_____________________________________________________________________________
321 Float_t AliMUONRejectList::BusPatchProbability(Int_t busPatchId) const
323 /// Get the probability to reject a given bus patch
324 return ::GetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0));
327 //_____________________________________________________________________________
328 Float_t AliMUONRejectList::ManuProbability(Int_t detElemId, Int_t manuId) const
330 /// Get the probability to reject a given manu
331 return ::GetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId));
334 //_____________________________________________________________________________
335 Float_t AliMUONRejectList::ChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
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);
343 //_____________________________________________________________________________
344 void AliMUONRejectList::SetDetectionElementProbability(Int_t detElemId, Float_t proba)
346 /// Set the probability to reject a given detection element
347 if ( ::SetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0),proba) )
355 //_____________________________________________________________________________
356 void AliMUONRejectList::ZeroOrOne(Float_t proba)
358 /// If proba is anything else than 0 or 1, we set fIsBinary to kFALSe
360 Bool_t zeroorone = ( proba == 0.0 || proba == 1.0 );
361 if (!zeroorone) fIsBinary = kFALSE;
364 //_____________________________________________________________________________
365 void AliMUONRejectList::SetBusPatchProbability(Int_t busPatchId, Float_t proba)
367 /// Set the probability to reject a given bus patch
368 if ( ::SetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0),proba) )
375 //_____________________________________________________________________________
376 void AliMUONRejectList::SetManuProbability(Int_t detElemId, Int_t manuId, Float_t proba)
378 /// Set the probability to reject a given manu
379 if ( ::SetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId),proba) )
386 //_____________________________________________________________________________
387 void AliMUONRejectList::SetChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t proba)
389 /// Set the probability to reject a given channel
390 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
393 param = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0.0);
394 fChannels->Add(param);
396 param->SetValueAsFloat(manuChannel,0,proba);
400 //_____________________________________________________________________________
401 void AliMUONRejectList::SetPCBProbability(Int_t detElemId, Int_t pcbNumber, Float_t proba)
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 };
407 for ( Int_t i = 0; i < 2; ++i )
409 const AliMpVSegmentation* vseg = seg->GetMpSegmentation(detElemId,ct[i]);
412 AliError(Form("Could not get segmentation of DE %d",detElemId));
415 const AliMpSlat* slat = seg->GetSlat(vseg);
418 AliError(Form("Could not get slat from DE %d",detElemId));
421 AliMpPCB* pcb = slat->GetPCB(pcbNumber);
422 for ( Int_t j = 0; j < pcb->GetSize(); ++j )
424 AliMpMotifPosition* mp = pcb->GetMotifPosition(j);
425 SetManuProbability(detElemId,mp->GetID(),proba);
430 //_____________________________________________________________________________
431 void AliMUONRejectList::SetHVProbability(const char* dcsName, Float_t proba)
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
436 AliMpDCSNamer hv("TRACKER");
438 TString alias = hv.DCSAliasFromName(dcsName);
440 Int_t detElemId = hv.DetElemIdFromDCSAlias(alias.Data());
441 Int_t index = hv.DCSIndexFromDCSAlias(alias.Data());
443 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
445 const AliMpArrayI* manus = de->ManusForHV(index);
447 for ( Int_t i = 0; i < manus->GetSize(); ++ i )
449 Int_t manuId = manus->GetValue(i);
450 SetManuProbability(detElemId,manuId,proba);
454 //_____________________________________________________________________________
456 AliMUONRejectList::Print(Option_t* opt) const
462 Bool_t debug(kFALSE);
464 if ( sopt.Contains("DEBUG") ) debug=kTRUE;
466 cout << Form("We have probabilities for %d detection element(s), %d bus patch(es), %d manu(s)",
467 fNofDEs,fNofBPs,fNofManus) << endl;
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);