AliRoot Core  a565103 (a565103)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONDigitCalibrator.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 
18 #include "AliMUONDigitCalibrator.h"
19 
20 #include "AliCDBEntry.h"
21 #include "AliCDBManager.h"
22 #include "AliLog.h"
23 #include "AliMUONCalibrationData.h"
24 #include "AliMUONConstants.h"
25 #include "AliMUONLogger.h"
26 #include "AliMUONPadStatusMaker.h"
28 #include "AliMUONRecoParam.h"
29 #include "AliMUONVCalibParam.h"
30 #include "AliMUONVDigit.h"
31 #include "AliMUONVDigitStore.h"
32 #include "AliMUONVStore.h"
33 #include "AliMpBusPatch.h"
34 #include "AliMpConstants.h"
35 #include "AliMpCDB.h"
36 #include "AliMpDDLStore.h"
37 #include "AliMpDEIterator.h"
38 #include "AliMpDetElement.h"
39 #include "AliMpManuStore.h"
40 
41 //-----------------------------------------------------------------------------
58 //-----------------------------------------------------------------------------
59 
60 
64 
65 //_____________________________________________________________________________
67 : TObject(),
68 fLogger(new AliMUONLogger(20000)),
69 fStatusMaker(0x0),
70 fStatusMapMaker(0x0),
71 fPedestals(0x0),
72 fNumberOfBadPads(0),
73 fNumberOfPads(0),
74 fChargeSigmaCut(0),
75 fMask(0)
76 {
78 
79  AliMUONRecoParam* recoParam(0x0);
80 
81  AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam",runNumber);
82  if (e)
83  {
84  TObject* o = e->GetObject();
85  if ( o->IsA() == TObjArray::Class() )
86  {
87  TObjArray* a = static_cast<TObjArray*>(o);
88 // a->SetOwner(kTRUE); // FIXME: this should be done but somehow makes the reco crash at the end at cleaning stage... investigate why ?
89  TIter next(a);
91  while ( ( p = static_cast<AliMUONRecoParam*>(next()) ))
92  {
93  if ( p->IsDefault()) recoParam = p;
94  }
95  }
96  else
97  {
98  recoParam = static_cast<AliMUONRecoParam*>(o);
99  }
100  }
101  if (!recoParam)
102  {
103  AliError("Cannot get the recoParam. Failing");
104  return;
105  }
106 
107  // OK. Now get all we need and work...
108 
109  AliMUONCalibrationData calib(runNumber);
110 
111  Ctor(calib,recoParam,kFALSE);
112 }
113 
114 //_____________________________________________________________________________
116  const AliMUONRecoParam* recoParams)
117 : TObject(),
118 fLogger(new AliMUONLogger(20000)),
119 fStatusMaker(0x0),
120 fStatusMapMaker(0x0),
121 fPedestals(0x0),
122 fNumberOfBadPads(0),
123 fNumberOfPads(0),
124 fChargeSigmaCut(0),
125 fMask(0)
126 {
128 
129  Ctor(calib,recoParams);
130 }
131 
132 //_____________________________________________________________________________
134 : TObject(),
135 fLogger(new AliMUONLogger(20000)),
136 fStatusMaker(0x0),
137 fStatusMapMaker(0x0),
138 fPedestals(0x0),
139 fNumberOfBadPads(0),
140 fNumberOfPads(0),
141 fChargeSigmaCut(0),
142 fMask(0)
143 {
145 
146  Ctor(calib,0x0);
147 }
148 
149 //_____________________________________________________________________________
150 void
152  const AliMUONRecoParam* recoParams,
153  Bool_t deferredInitialization)
154 {
156 
157  // Load mapping manu store
158  if ( ! AliMpCDB::LoadManuStore() ) {
159  AliFatal("Could not access manu store from OCDB !");
160  }
161 
162  fStatusMaker = new AliMUONPadStatusMaker(calib);
163 
164  // Set default values, as loose as reasonable
165 
166  fChargeSigmaCut = 3.0;
167 
168  fMask = 0x8080; // reject pads where ped *or* hv are missing
169 
170  if ( recoParams )
171  {
172  // if we have reco params, we use limits and cuts from there :
173 
174  fStatusMaker->SetLimits(*recoParams);
175 
176  fMask = recoParams->PadGoodnessMask();
177  //WARNING : getting this mask wrong is a very effective way of getting
178  //no digits at all out of this class ;-)
179 
180  fChargeSigmaCut = recoParams->ChargeSigmaCut();
181  }
182  else
183  {
184  fLogger->Log("No RecoParam available");
185  fLogger->Log(Form("SigmaCut=%e",fChargeSigmaCut));
186  }
187 
188  fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,fMask,deferredInitialization);
189 
190  fPedestals = calib.Pedestals();
191 }
192 
193 //_____________________________________________________________________________
195 {
197 
198  if ( fNumberOfPads > 0 )
199  {
200  if ( fStatusMaker )
201  {
203  }
204 
205  AliInfo("Summary of messages:");
206 
207  fLogger->Print();
208 
209  AliInfo(Form("We have seen %g pads, and rejected %g (%7.2f %%)",
211  ( fNumberOfPads > 0 ) ? fNumberOfBadPads*100.0/fNumberOfPads : 0 ));
212  }
213 
214  delete fStatusMaker;
215  delete fStatusMapMaker;
216  delete fLogger;
217 }
218 
219 //_____________________________________________________________________________
220 void
222 {
224  TIter next(digitStore.CreateTrackerIterator());
225  AliMUONVDigit* digit;
226 
227  fStatusMapMaker->RefreshRejectProbabilities(); // this will do something only for simulations
228  // (and only for those simulations where the reject list contain probabilities which are
229  // different from zero or one)
230 
231  AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
232 
233  while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
234  {
235  if ( digit->IsCalibrated() )
236  {
237  fLogger->Log("ERROR : trying to calibrate a digit twice");
238  return;
239  }
240 
241  digit->Calibrated(kTRUE);
242  digit->ChargeInFC(kTRUE);
243 
244  Float_t charge(0.0);
245  Int_t statusMap;
246  Bool_t isSaturated(kFALSE);
247 
248  ++fNumberOfPads;
249 
250  Bool_t ok = IsValidDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),&statusMap);
251 
252  digit->SetStatusMap(statusMap);
253 
254  if (ok)
255  {
256  charge = CalibrateDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
257  digit->ADC(),fChargeSigmaCut,&isSaturated);
258  }
259  else
260  {
261  ++fNumberOfBadPads;
262  }
263 
264  digit->SetCharge(charge);
265  digit->Saturated(isSaturated);
266 
267  }
268 }
269 
270 //_____________________________________________________________________________
271 Float_t
272 AliMUONDigitCalibrator::CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
273  Float_t adc, Float_t nsigmas,
274  Bool_t* isSaturated) const
275 
276 {
279 
280  if ( nsigmas < 0 )
281  {
282  nsigmas = fChargeSigmaCut;
283  }
284 
285  fLogger->Log(Form("ChargeSigmaCut used = %e",nsigmas));
286 
287  AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
288  (fPedestals->FindObject(detElemId,manuId));
289 
290  if (!pedestal)
291  {
292  // no pedestal -> no charge
293  fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",detElemId,manuId));
294  return 0.0;
295  }
296 
297  Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
298 
299  // Gain (mV/fC) = 1/(a0*capa) with a0~1.25 and capa~0.2
300  Float_t charge(0);
301  Float_t capa(AliMUONConstants::DefaultCapa()); // capa = 0.2 and a0 = 1.25
302  Float_t a0(AliMUONConstants::DefaultA0()); // is equivalent to gain = 4 mV/fC
303  Float_t adc2mv(AliMUONConstants::DefaultADC2MV()); // 1 ADC channel = 0.61 mV
304  //
305  // Note that the ChargeMax (for one pad) is roughly 4096 * 0.61 mV/channel / 4 mV/fC = 625 fC
306 
307  if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
308  {
309  charge = a0*padc*capa*adc2mv;
310  }
311 
312  if ( isSaturated )
313  {
314  const Int_t saturation(3000);
315 
316  if ( padc >= saturation )
317  {
318  *isSaturated = kTRUE;
319  }
320  else
321  {
322  *isSaturated = kFALSE;
323  }
324  }
325 
326  return ( charge > 0.0 ? charge : 0.0 );
327 }
328 
329 //_____________________________________________________________________________
330 Bool_t
331 AliMUONDigitCalibrator::IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
332  Int_t* statusMap) const
333 
334 {
336 
337  // initialize the statusmap to dead by default
338  if (statusMap) *statusMap = AliMUONPadStatusMapMaker::SelfDeadMask();
339 
340  // First a protection against bad input parameters
342  if (!de) return kFALSE; // not existing DE
343  if (!de->IsExistingChannel(manuId,manuChannel))
344  {
345  // non-existing (might happen when we get parity errors in read-out
346  // that spoils the manuId
347  return kFALSE;
348  }
349  if (!de->IsConnectedChannel(manuId,manuChannel))
350  {
351  // existing (in read-out), but not connected channel
352  return kFALSE;
353  }
354 
355  // ok, now we have a valid channel number, so let's see if that pad
356  // behaves or not ;-)
357 
358  Int_t sm = StatusMap(detElemId,manuId,manuChannel);
359 
360  if (statusMap) *statusMap = sm;
361 
362  if ( ( sm & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
363  {
364  // pad itself is bad (not testing its neighbours at this stage)
365  return kFALSE;
366  }
367 
368  return kTRUE;
369 }
370 
371 //_____________________________________________________________________________
372 Int_t
373 AliMUONDigitCalibrator::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
374 {
376  return fStatusMaker->PadStatus(detElemId,manuId,manuChannel);
377 }
378 
379 //_____________________________________________________________________________
380 Int_t
381 AliMUONDigitCalibrator::StatusMap(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
382 {
384  return fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
385 
386 }
387 
Convert a pad status container into a pad status map container.
UInt_t fMask
! mask used to cut bad channels
AliMUONDigitCalibrator(Int_t runNumber)
Interface for a digit container.
void Print(Option_t *opt="") const
virtual Float_t ValueAsFloat(Int_t i, Int_t j=0) const =0
#define TObjArray
Double_t ChargeSigmaCut() const
Number of sigma cut we must apply when cutting on adc-ped.
Double_t fNumberOfBadPads
! # of times we've rejected a bad pad
Double_t fChargeSigmaCut
! number of sigmas to cut on
Int_t Log(const char *message)
Int_t StatusMap(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
AliMUONPadStatusMapMaker * fStatusMapMaker
! to build status map
Class with MUON reconstruction parameters.
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
AliMUONPadStatusMaker * fStatusMaker
! to build pad statuses
static Bool_t LoadManuStore(Bool_t warn=false)
Definition: AliMpCDB.cxx:203
The class defines the electronics properties of detection element.
static Float_t DefaultA0()
virtual Int_t GetSize() const =0
Number of digits we store.
void Ctor(const AliMUONCalibrationData &calib, const AliMUONRecoParam *recoParams, Bool_t deferredInitialization=kTRUE)
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
A logger that keeps track of the number of times a message appeared.
Definition: AliMUONLogger.h:24
Container of calibration values for a given number of channels.
static AliMpDDLStore * Instance(Bool_t warn=true)
AliMUONVStore * StatusMap() const
AliMUONVCalibParam * PadStatus(Int_t detElemId, Int_t manuId) const
Float_t CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel, Float_t adc, Float_t nsigmas=-1, Bool_t *isSaturated=0x0) const
AliMUONLogger * fLogger
! to log repeated messages
Class to calibrate the digits.
static Float_t DefaultCapa()
static Float_t DefaultADC2MV()
virtual TIterator * CreateTrackerIterator() const =0
Create an iterator to loop over tracker digits only.
Double_t fNumberOfPads
! # of pads we've seen
AliMUONVStore * Pedestals() const
Get the pedestal store.
static Int_t SelfDeadMask()
Return status bit map to tell a pad is bad.
Int_t PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
Single entry point to access MUON calibration data.
ABC of a MUON digit.
Definition: AliMUONVDigit.h:18
UInt_t PadGoodnessMask() const
Get the goodness mask.
Bool_t IsConnectedChannel(Int_t manuId, Int_t manuChannel) const
Bool_t IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel, Int_t *statusMap=0x0) const
Bool_t IsExistingChannel(Int_t manuId, Int_t manuChannel) const
AliMUONVStore * fPedestals
! pedestal values
Make a 2DStore of pad statuses, using different sources of information.
virtual TObject * FindObject(const char *name) const
Find an object by name.
virtual void Calibrate(AliMUONVDigitStore &digitStore)
void SetLimits(const AliMUONRecoParam &recoParams)