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, 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).
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
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
38 /// \author Laurent Aphecetche, Subatech
41 #include "AliMUONRejectList.h"
43 #include "AliMpConstants.h"
44 #include "AliMUON2DMap.h"
45 #include "AliMUONCalibParamNF.h"
46 #include "Riostream.h"
50 ClassImp(AliMUONRejectList)
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.
59 void Dump(const char* str, UInt_t n, UInt_t* ids, Float_t* values, Bool_t debug)
61 /// Dump the values array
66 for ( UInt_t i = 0; i < n; ++i )
70 AliMUONVCalibParam::DecodeUniqueID(key,a,b);
71 if ( s.CountChar('%')==3 )
73 cout << Form(s.Data(),a,b,values[i]) << endl;
77 cout << Form(s.Data(),a,values[i]) << endl;
83 cout << "------" << endl;
84 for ( UInt_t i = 0; i < n; ++i )
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;
96 Float_t GetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key)
98 /// Get the value corresponding to key, or zero if not found
99 Long64_t index = TMath::BinarySearch(n,ids,key);
101 Bool_t found = ( ( index >= 0 ) && ( ids[index] == key ) );
105 return values[index];
113 void Insert(UInt_t n, UInt_t* ids, Float_t* values, UInt_t index, UInt_t key, Float_t value)
115 /// Insert (key,value) into arrays ids and values.
117 for ( UInt_t i = n; i > index; --i )
120 values[i] = values[i-1];
123 values[index] = value;
126 Bool_t SetValue(UInt_t n, UInt_t* ids, Float_t* values, UInt_t key, Float_t value)
128 /// Set the value for a given key
129 Long64_t index = TMath::BinarySearch(n,ids, key);
131 Bool_t alreadyThere = ( ( index >= 0 ) && ( ids[index] == key ) );
136 values[index] = value;
139 Insert(n,ids,values,index+1,key,value);
143 void Copy(UInt_t n, UInt_t* src, UInt_t*& dest)
145 /// Copy src into dest
147 dest = new UInt_t[n];
148 memcpy(src,dest,n*sizeof(UInt_t));
151 void Copy(UInt_t n, Float_t* src, Float_t*& dest)
153 /// Copy src into dest
155 dest = new Float_t[n];
156 memcpy(src,dest,n*sizeof(Float_t));
161 //_____________________________________________________________________________
162 AliMUONRejectList::AliMUONRejectList()
165 fMaxNofDEs(156), // not nice to put a constant here, but that way this object does not need the mapping at creation time...
166 fMaxNofBPs(888), // same remark as above
167 fMaxNofManus(16828), // same as above...
171 fDEIds(new UInt_t[fMaxNofDEs]),
172 fDEProbas(new Float_t[fMaxNofDEs]),
173 fBPIds(new UInt_t[fMaxNofBPs]),
174 fBPProbas(new Float_t[fMaxNofBPs]),
175 fManuIds(new UInt_t[fMaxNofManus]),
176 fManuProbas(new Float_t[fMaxNofManus]),
177 fChannels(new AliMUON2DMap(kTRUE))
180 memset(fDEIds,0,fMaxNofDEs*sizeof(UInt_t));
181 memset(fDEProbas,0.0,fMaxNofDEs*sizeof(Float_t));
182 memset(fBPIds,0,fMaxNofBPs*sizeof(UInt_t));
183 memset(fBPProbas,0.0,fMaxNofBPs*sizeof(Float_t));
184 memset(fManuIds,0,fMaxNofManus*sizeof(UInt_t));
185 memset(fManuProbas,0.0,fMaxNofManus*sizeof(Float_t));
188 //_____________________________________________________________________________
189 AliMUONRejectList::AliMUONRejectList(TRootIOCtor* /*ioCtor*/)
206 /// ctor from root i/o
209 //_____________________________________________________________________________
210 AliMUONRejectList::AliMUONRejectList(const AliMUONRejectList& rl)
231 //_____________________________________________________________________________
232 AliMUONRejectList& AliMUONRejectList::operator=(const AliMUONRejectList& rl)
234 /// assignement operator
239 //_____________________________________________________________________________
241 AliMUONRejectList::CopyTo(AliMUONRejectList& rl) const
246 rl.fIsBinary = fIsBinary;
248 ::Copy(rl.fMaxNofDEs,fDEIds,rl.fDEIds);
249 ::Copy(rl.fMaxNofDEs,fDEProbas,rl.fDEProbas);
250 ::Copy(rl.fMaxNofBPs,fBPIds,rl.fBPIds);
251 ::Copy(rl.fMaxNofBPs,fBPProbas,rl.fBPProbas);
252 ::Copy(rl.fMaxNofManus,fManuIds,rl.fManuIds);
253 ::Copy(rl.fMaxNofManus,fManuProbas,rl.fManuProbas);
256 rl.fChannels = static_cast<AliMUONVStore*>(fChannels->Clone());
259 //_____________________________________________________________________________
260 AliMUONRejectList::~AliMUONRejectList()
269 delete[] fManuProbas;
272 //_____________________________________________________________________________
273 Float_t AliMUONRejectList::DetectionElementProbability(Int_t detElemId) const
275 /// Get the probability to reject a given detection element
276 return ::GetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0));
279 //_____________________________________________________________________________
280 Float_t AliMUONRejectList::BusPatchProbability(Int_t busPatchId) const
282 /// Get the probability to reject a given bus patch
283 return ::GetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0));
286 //_____________________________________________________________________________
287 Float_t AliMUONRejectList::ManuProbability(Int_t detElemId, Int_t manuId) const
289 /// Get the probability to reject a given manu
290 return ::GetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId));
293 //_____________________________________________________________________________
294 Float_t AliMUONRejectList::ChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
296 /// Get the probability to reject a given channel
297 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
298 if (!param) return 0.0;
299 return param->ValueAsFloat(manuChannel);
302 //_____________________________________________________________________________
303 void AliMUONRejectList::SetDetectionElementProbability(Int_t detElemId, Float_t proba)
305 /// Set the probability to reject a given detection element
306 if ( ::SetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0),proba) )
314 //_____________________________________________________________________________
315 void AliMUONRejectList::ZeroOrOne(Float_t proba)
317 /// If proba is anything else than 0 or 1, we set fIsBinary to kFALSe
319 Bool_t zeroorone = ( proba == 0.0 || proba == 1.0 );
320 if (!zeroorone) fIsBinary = kFALSE;
323 //_____________________________________________________________________________
324 void AliMUONRejectList::SetBusPatchProbability(Int_t busPatchId, Float_t proba)
326 /// Set the probability to reject a given bus patch
327 if ( ::SetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0),proba) )
334 //_____________________________________________________________________________
335 void AliMUONRejectList::SetManuProbability(Int_t detElemId, Int_t manuId, Float_t proba)
337 /// Set the probability to reject a given manu
338 if ( ::SetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId),proba) )
345 //_____________________________________________________________________________
346 void AliMUONRejectList::SetChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t proba)
348 /// Set the probability to reject a given channel
349 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
352 param = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),detElemId,manuId,0.0);
353 fChannels->Add(param);
355 param->SetValueAsFloat(manuChannel,0,proba);
359 //_____________________________________________________________________________
361 AliMUONRejectList::Print(Option_t* opt) const
367 Bool_t debug(kFALSE);
369 if ( sopt.Contains("DEBUG") ) debug=kTRUE;
371 cout << Form("We have probabilities for %d detection element(s), %d bus patch(es), %d manu(s)",
372 fNofDEs,fNofBPs,fNofManus) << endl;
374 ::Dump("DE %04d",fNofDEs,fDEIds,fDEProbas,debug);
375 ::Dump("BusPatch %04d",fNofBPs,fBPIds,fBPProbas,debug);
376 ::Dump("DE %04d MANU %4d",fNofManus,fManuIds,fManuProbas,debug);