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 **************************************************************************/
18 #include "AliMUONDigitCalibrator.h"
20 #include "AliCDBEntry.h"
21 #include "AliCDBManager.h"
23 #include "AliMUONCalibrationData.h"
24 #include "AliMUONConstants.h"
25 #include "AliMUONLogger.h"
26 #include "AliMUONPadStatusMaker.h"
27 #include "AliMUONPadStatusMapMaker.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"
36 #include "AliMpDDLStore.h"
37 #include "AliMpDEIterator.h"
38 #include "AliMpDetElement.h"
39 #include "AliMpManuStore.h"
41 //-----------------------------------------------------------------------------
42 /// \class AliMUONDigitCalibrator
43 /// Class used to calibrate digits (either real or simulated ones).
45 /// The calibration consists of subtracting the pedestal
46 /// and multiplying by a gain, so that
47 /// Signal = (ADC-pedestal)*gain
49 /// Please note also that for the moment, if a digit lies on a dead channel
50 /// we remove this digit from the list of digits.
51 /// FIXME: this has to be revisited. By using the AliMUONDigit::fFlags we
52 /// should in principle flag a digit as bad w/o removing it, but this
53 /// then requires some changes in the cluster finder to deal with this extra
54 /// information correctly (e.g. to set a quality for the cluster if it contains
57 /// \author Laurent Aphecetche
58 //-----------------------------------------------------------------------------
62 ClassImp(AliMUONDigitCalibrator)
65 const Int_t AliMUONDigitCalibrator::fgkNoGain(0);
66 const Int_t AliMUONDigitCalibrator::fgkGainConstantCapa(1);
67 const Int_t AliMUONDigitCalibrator::fgkGain(2);
68 const Int_t AliMUONDigitCalibrator::fgkInjectionGain(3);
70 //_____________________________________________________________________________
71 AliMUONDigitCalibrator::AliMUONDigitCalibrator(Int_t runNumber, const char* calibMode)
73 fLogger(new AliMUONLogger(20000)),
87 AliMUONRecoParam* recoParam(0x0);
89 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam",runNumber);
92 TObject* o = e->GetObject();
93 if ( o->IsA() == TObjArray::Class() )
95 TObjArray* a = static_cast<TObjArray*>(o);
98 while ( ( p = static_cast<AliMUONRecoParam*>(next()) ))
100 if ( p->IsDefault()) recoParam = p;
105 recoParam = static_cast<AliMUONRecoParam*>(o);
110 AliError("Cannot get the recoParam. Failing");
114 // OK. Now get all we need and work...
116 AliMUONCalibrationData calib(runNumber);
118 Ctor(calibMode,calib,recoParam,kFALSE);
121 //_____________________________________________________________________________
122 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
123 const AliMUONRecoParam* recoParams,
124 const char* calibMode)
126 fLogger(new AliMUONLogger(20000)),
128 fStatusMapMaker(0x0),
140 Ctor(calibMode,calib,recoParams);
143 //_____________________________________________________________________________
144 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
145 const char* calibMode)
147 fLogger(new AliMUONLogger(20000)),
149 fStatusMapMaker(0x0),
161 Ctor(calibMode,calib,0x0);
164 //_____________________________________________________________________________
166 AliMUONDigitCalibrator::Ctor(const char* calibMode,
167 const AliMUONCalibrationData& calib,
168 const AliMUONRecoParam* recoParams,
169 Bool_t deferredInitialization)
173 TString cMode(calibMode);
176 if ( cMode == "NOGAIN" )
178 fApplyGains = fgkNoGain;
179 AliInfo("Will NOT apply gain correction");
181 else if ( cMode == "GAINCONSTANTCAPA" )
183 fApplyGains = fgkGainConstantCapa;
184 AliInfo("Will apply gain correction, but with constant capacitance");
186 else if ( cMode == "GAIN" )
188 fApplyGains = fgkGain;
189 AliInfo("Will apply gain correction, with measured capacitances");
191 else if ( cMode == "INJECTIONGAIN")
193 fApplyGains = fgkInjectionGain;
194 AliInfo("Will apply injection gain correction, with EMELEC factory gains");
198 AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
199 fApplyGains = fgkNoGain;
202 // Load mapping manu store
203 if ( ! AliMpCDB::LoadManuStore() ) {
204 AliFatal("Could not access manu store from OCDB !");
207 fStatusMaker = new AliMUONPadStatusMaker(calib);
209 // Set default values, as loose as reasonable
211 fChargeSigmaCut = 3.0;
213 fMask = 0x8080; // reject pads where ped *or* hv are missing
217 // if we have reco params, we use limits and cuts from there :
219 fStatusMaker->SetLimits(*recoParams);
221 fMask = recoParams->PadGoodnessMask();
222 //WARNING : getting this mask wrong is a very effective way of getting
223 //no digits at all out of this class ;-)
225 fChargeSigmaCut = recoParams->ChargeSigmaCut();
229 fLogger->Log("No RecoParam available");
230 fLogger->Log(Form("SigmaCut=%e",fChargeSigmaCut));
233 fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,fMask,deferredInitialization);
235 fPedestals = calib.Pedestals();
237 fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
238 // to get the saturation value...
240 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
242 fCapacitances = calib.Capacitances();
246 //_____________________________________________________________________________
247 AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
251 if ( fNumberOfPads > 0 )
255 fStatusMaker->Report(fMask);
258 AliInfo("Summary of messages:");
262 AliInfo(Form("We have seen %g pads, and rejected %g (%7.2f %%)",
263 fNumberOfPads,fNumberOfBadPads,
264 ( fNumberOfPads > 0 ) ? fNumberOfBadPads*100.0/fNumberOfPads : 0 ));
268 delete fStatusMapMaker;
272 //_____________________________________________________________________________
274 AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
276 /// Calibrate the digits contained in digitStore
277 TIter next(digitStore.CreateTrackerIterator());
278 AliMUONVDigit* digit;
280 fStatusMapMaker->RefreshRejectProbabilities(); // this will do something only for simulations
281 // (and only for those simulations where the reject list contain probabilities which are
282 // different from zero or one)
284 AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
286 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
288 if ( digit->IsCalibrated() )
290 fLogger->Log("ERROR : trying to calibrate a digit twice");
294 digit->Calibrated(kTRUE);
298 Bool_t isSaturated(kFALSE);
302 Bool_t ok = IsValidDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),&statusMap);
304 digit->SetStatusMap(statusMap);
308 charge = CalibrateDigit(digit->DetElemId(),digit->ManuId(),digit->ManuChannel(),
309 digit->ADC(),fChargeSigmaCut,&isSaturated);
316 digit->SetCharge(charge);
317 digit->Saturated(isSaturated);
321 //_____________________________________________________________________________
323 AliMUONDigitCalibrator::CalibrateDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
324 Float_t adc, Float_t nsigmas,
325 Bool_t* isSaturated) const
328 /// Calibrate one digit
329 /// Return the digit charge, in fC
333 nsigmas = fChargeSigmaCut;
336 fLogger->Log(Form("ChargeSigmaCut used = %e",nsigmas));
338 AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
339 (fPedestals->FindObject(detElemId,manuId));
343 // no pedestal -> no charge
344 fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",detElemId,manuId));
349 AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
350 (fGains->FindObject(detElemId,manuId));
354 if ( fApplyGains != fgkNoGain )
356 // no gain -> no charge
357 fLogger->Log(Form("Got a null gain object for DE,manu=%d,%d",
363 Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
365 // Gain (mV/fC) = 1/(a0*capa) with a0~1.25 and capa~0.2
367 Float_t capa(AliMUONConstants::DefaultCapa()); // capa = 0.2 and a0 = 1.25
368 Float_t a0(AliMUONConstants::DefaultA0()); // is equivalent to gain = 4 mV/fC
370 Float_t adc2mv(AliMUONConstants::DefaultADC2MV()); // 1 ADC channel = 0.61 mV
371 Float_t injGain(4); // By default the gain is set to 4 mV/fC
373 // Note that the ChargeMax (for one pad) is roughly 4096 * 0.61 mV/channel / 4 mV/fC = 625 fC
375 if ( fApplyGains == fgkGain || fApplyGains == fgkInjectionGain )
378 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
380 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
384 capa = param->ValueAsFloat(manuChannel,0);
385 injGain = param->ValueAsFloat(manuChannel,1);
388 fLogger->Log(Form("injGain is %e < 0 for serialNumber=%d",injGain,serialNumber));
394 // If capa not found in the OCDB we exit
395 fLogger->Log(Form("No capa (injGain) found for serialNumber=%d",serialNumber));
400 if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
402 if ( fApplyGains == fgkGain || fApplyGains == fgkGainConstantCapa )
404 a0 = gain->ValueAsFloat(manuChannel,0);
405 a1 = gain->ValueAsFloat(manuChannel,1);
406 Int_t thres = gain->ValueAsInt(manuChannel,2);
413 charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
415 charge *= capa*adc2mv;
417 else if ( fApplyGains == fgkInjectionGain )
420 charge = padc*adc2mv/injGain;
424 charge = a0*padc*capa*adc2mv;
430 Int_t saturation(3000);
432 if ( gain && ( fApplyGains != fgkNoGain ) )
434 saturation = gain->ValueAsInt(manuChannel,4);
437 if ( padc >= saturation )
439 *isSaturated = kTRUE;
443 *isSaturated = kFALSE;
447 return ( charge > 0.0 ? charge : 0.0 );
450 //_____________________________________________________________________________
452 AliMUONDigitCalibrator::IsValidDigit(Int_t detElemId, Int_t manuId, Int_t manuChannel,
453 Int_t* statusMap) const
456 /// Check if a given pad is ok or not.
458 // First a protection against bad input parameters
459 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
460 if (!de) return kFALSE; // not existing DE
461 if (!de->IsExistingChannel(manuId,manuChannel))
463 // non-existing (might happen when we get parity errors in read-out
464 // that spoils the manuId
467 if (!de->IsConnectedChannel(manuId,manuChannel))
469 // existing (in read-out), but not connected channel
473 // ok, now we have a valid channel number, so let's see if that pad
474 // behaves or not ;-)
476 Int_t sm = fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);
478 if (statusMap) *statusMap = sm;
480 if ( ( sm & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
482 // pad itself is bad (not testing its neighbours at this stage)
489 //_____________________________________________________________________________
491 AliMUONDigitCalibrator::PadStatus(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
493 /// Return the status of the given pad
494 return fStatusMaker->PadStatus(detElemId,manuId,manuChannel);
497 //_____________________________________________________________________________
499 AliMUONDigitCalibrator::StatusMap(Int_t detElemId, Int_t manuId, Int_t manuChannel) const
501 /// Return the status map of the given pad
502 return fStatusMapMaker->StatusMap(detElemId,manuId,manuChannel);