AliRoot Core  edcc906 (edcc906)
AliMUONRejectList.cxx
Go to the documentation of this file.
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 
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;
65 ClassImp(AliMUONRejectList)
67 
68 namespace
69 {
73 
74  void Dump(const char* str, UInt_t n, UInt_t* ids, Float_t* values, Bool_t debug)
75  {
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;
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;
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  {
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  {
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  {
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  {
161  delete[] dest;
162  dest = 0;
163  if ( src && n )
164  {
165  dest = new UInt_t[n];
166  memcpy(dest,src,n*sizeof(UInt_t));
167  }
168  }
169 
170  void Copy(UInt_t n, Float_t* src, Float_t*& dest)
171  {
173  delete[] dest;
174  dest = 0;
175  if ( src && n )
176  {
177  dest = new Float_t[n];
178  memcpy(dest,src,n*sizeof(Float_t));
179  }
180  }
181 
182 }
183 
184 //_____________________________________________________________________________
186 : TObject(),
187 fIsBinary(kTRUE),
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...
191 fNofDEs(),
192 fNofBPs(),
193 fNofManus(),
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))
201 {
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));
209 }
210 
211 //_____________________________________________________________________________
212 AliMUONRejectList::AliMUONRejectList(TRootIOCtor* /*ioCtor*/)
213 : TObject(),
214 fIsBinary(kTRUE),
215 fMaxNofDEs(),
216 fMaxNofBPs(),
217 fMaxNofManus(),
218 fNofDEs(),
219 fNofBPs(),
220 fNofManus(0),
221 fDEIds(0x0),
222 fDEProbas(0x0),
223 fBPIds(0x0),
224 fBPProbas(0x0),
225 fManuIds(0x0),
226 fManuProbas(0x0),
227 fChannels(0x0)
228 {
230 }
231 
232 //_____________________________________________________________________________
234 : TObject(rl),
235 fIsBinary(rl.fIsBinary),
239 fNofDEs(rl.fNofDEs),
240 fNofBPs(rl.fNofBPs),
241 fNofManus(rl.fNofManus),
242 fDEIds(0x0),
243 fDEProbas(0x0),
244 fBPIds(0x0),
245 fBPProbas(0x0),
246 fManuIds(0x0),
247 fManuProbas(0x0),
248 fChannels(0x0)
249 {
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  }
263 }
264 
265 //_____________________________________________________________________________
267 {
269  if ( this != &rl )
270  {
271  static_cast<TObject&>(*this)=rl;
272 
273  fIsBinary = rl.fIsBinary;
274  fMaxNofDEs = rl.fMaxNofDEs;
275  fMaxNofBPs = rl.fMaxNofBPs;
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 
296  }
297  return *this;
298 }
299 
300 //_____________________________________________________________________________
302 {
304  delete fChannels;
305  delete[] fDEIds;
306  delete[] fDEProbas;
307  delete[] fBPIds;
308  delete[] fBPProbas;
309  delete[] fManuIds;
310  delete[] fManuProbas;
311 }
312 
313 //_____________________________________________________________________________
315 {
317  return ::GetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0));
318 }
319 
320 //_____________________________________________________________________________
321 Float_t AliMUONRejectList::BusPatchProbability(Int_t busPatchId) const
322 {
324  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 {
331  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 {
338  AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fChannels->FindObject(detElemId,manuId));
339  if (!param) return 0.0;
340  return param->ValueAsFloat(manuChannel);
341 }
342 
343 //_____________________________________________________________________________
344 void AliMUONRejectList::SetDetectionElementProbability(Int_t detElemId, Float_t proba)
345 {
347  if ( ::SetValue(fNofDEs,fDEIds,fDEProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,0),proba) )
348  {
349  ++fNofDEs;
350  }
351 
352  ZeroOrOne(proba);
353 }
354 
355 //_____________________________________________________________________________
356 void AliMUONRejectList::ZeroOrOne(Float_t proba)
357 {
359 
360  Bool_t zeroorone = ( proba == 0.0 || proba == 1.0 );
361  if (!zeroorone) fIsBinary = kFALSE;
362 }
363 
364 //_____________________________________________________________________________
365 void AliMUONRejectList::SetBusPatchProbability(Int_t busPatchId, Float_t proba)
366 {
368  if ( ::SetValue(fNofBPs,fBPIds,fBPProbas,AliMUONVCalibParam::BuildUniqueID(busPatchId,0),proba) )
369  {
370  ++fNofBPs;
371  }
372  ZeroOrOne(proba);
373 }
374 
375 //_____________________________________________________________________________
376 void AliMUONRejectList::SetManuProbability(Int_t detElemId, Int_t manuId, Float_t proba)
377 {
379  if ( ::SetValue(fNofManus,fManuIds,fManuProbas,AliMUONVCalibParam::BuildUniqueID(detElemId,manuId),proba) )
380  {
381  ++fNofManus;
382  }
383  ZeroOrOne(proba);
384 }
385 
386 //_____________________________________________________________________________
387 void AliMUONRejectList::SetChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t proba)
388 {
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 //_____________________________________________________________________________
401 void AliMUONRejectList::SetPCBProbability(Int_t detElemId, Int_t pcbNumber, Float_t proba)
402 {
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 //_____________________________________________________________________________
431 void AliMUONRejectList::SetHVProbability(const char* dcsName, Float_t proba)
432 {
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 
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 //_____________________________________________________________________________
455 void
456 AliMUONRejectList::Print(Option_t* opt) const
457 {
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 }
TBrowser b
Definition: RunAnaESD.C:12
Singleton container class for mapping segmentations.
Float_t ManuProbability(Int_t detElemId, Int_t manuId) const
const AliMpVSegmentation * GetMpSegmentation(Int_t detElemId, AliMp::CathodType cath, Bool_t warn=true) const
Int_t GetSize() const
static AliMpSegmentation * Instance(Bool_t warn=true)
virtual Float_t ValueAsFloat(Int_t i, Int_t j=0) const =0
UInt_t fMaxNofDEs
max number of detection elements (for allocation purposes)
Implementation of AliMUONVCalibParam for tuples of floats.
virtual void SetValueAsFloat(Int_t i, Int_t j, Float_t value)=0
Set one value, for channel i, dimension j. Consider value is a float.
const AliMpSlat * GetSlat(const AliMpVSegmentation *kSegmentation, Bool_t warn=true) const
void Print(Option_t *opt="") const
A PCB for station 3,4 or 5.
Definition: AliMpPCB.h:46
Collection of methods usefull to DCS handling for MUON TRK and TRG.
Definition: AliMpDCSNamer.h:22
Int_t GetSize() const
The number of motifs, aka manus.
Definition: AliMpPCB.cxx:588
UInt_t * fDEIds
array of detection element ids
static UInt_t BuildUniqueID(Int_t id0, Int_t id1)
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
A slat (building block of stations 3, 4 and 5)
Definition: AliMpSlat.h:51
The class defines the electronics properties of detection element.
Float_t * fManuProbas
array of proba for manus
void SetHVProbability(const char *dcsName, Float_t proba=1.0)
UInt_t fMaxNofManus
max number of manus (for allocation purposes)
Float_t DetectionElementProbability(Int_t detElemId) const
void SetDetectionElementProbability(Int_t detElemId, Float_t proba=1.0)
UInt_t fNofManus
actual number of manus for which we have probabilities
Float_t * fDEProbas
array of probabilities of DEs
Container of calibration values for a given number of channels.
static AliMpDDLStore * Instance(Bool_t warn=true)
AliMUONVStore * fChannels
probabilities for all channels
static Int_t ManuNofChannels()
Max number of channels per manu.
Int_t GetID() const
Return motif position ID = manu id.
A placed motif.
AliMpPCB * GetPCB(Int_t i) const
Returns the i-th PCB of this slat.
Definition: AliMpSlat.cxx:435
TString DCSAliasFromName(const char *dcsName) const
Bool_t fIsBinary
Whether or not we only store zeros and ones for probabilities.
Float_t ChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
void SetManuProbability(Int_t detElemId, Int_t manuId, Float_t proba=1.0)
Int_t DCSIndexFromDCSAlias(const char *dcsAlias) const
AliMUONRejectList & operator=(const AliMUONRejectList &rl)
Helper class for sorted integer array.
Definition: AliMpArrayI.h:21
UInt_t fMaxNofBPs
max number of bus patches (for allocation purposes)
AliMpMotifPosition * GetMotifPosition(Int_t i) const
Definition: AliMpPCB.cxx:553
Basic implementation of AliMUONVStore container using AliMpExMap internally.
Definition: AliMUON2DMap.h:20
UInt_t * fManuIds
array of manu ids
UInt_t fNofDEs
actual number of detection elements for which we have probabilities
virtual Bool_t Add(TObject *object)=0
Add an object to the store.
UInt_t * fBPIds
array of bus patch ids
static void DecodeUniqueID(UInt_t uniqueID, Int_t &id0, Int_t &id1)
void SetChannelProbability(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t proba=1.0)
void ZeroOrOne(Float_t proba)
The abstract base class for the segmentation.
Object to hold the list of elements we want to reject from the reconstruction.
Float_t BusPatchProbability(Int_t busPatchId) const
const AliMpArrayI * ManusForHV(Int_t hvIndex) const
#define AliError(message)
Definition: AliLog.h:591
Int_t GetValue(Int_t index) const
Float_t * fBPProbas
array of proba for bus patches
Int_t DetElemIdFromDCSAlias(const char *dcsAlias) const
Base class for MUON data stores.
Definition: AliMUONVStore.h:22
void SetPCBProbability(Int_t detElemId, Int_t pcbNumber, Float_t proba=1.0)
Int_t debug
void SetBusPatchProbability(Int_t busPatchId, Float_t proba=1.0)
virtual TObject * FindObject(const char *name) const
Find an object by name.
UInt_t fNofBPs
actual number of bus patches for which we have probabilities