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"
21 #include "AliMUONCalibrationData.h"
22 #include "AliMUONLogger.h"
23 #include "AliMUONPadStatusMaker.h"
24 #include "AliMUONPadStatusMapMaker.h"
25 #include "AliMUONVCalibParam.h"
26 #include "AliMUONVDigit.h"
27 #include "AliMUONVDigitStore.h"
28 #include "AliMUONVStore.h"
29 #include "AliMpBusPatch.h"
30 #include "AliMpConstants.h"
31 #include "AliMpDDLStore.h"
32 #include "AliMpDEIterator.h"
33 #include "AliMpDetElement.h"
35 //-----------------------------------------------------------------------------
36 /// \class AliMUONDigitCalibrator
37 /// Class used to calibrate digits (either real or simulated ones).
39 /// The calibration consists of subtracting the pedestal
40 /// and multiplying by a gain, so that
41 /// Signal = (ADC-pedestal)*gain
43 /// Please note also that for the moment, if a digit lies on a dead channel
44 /// we remove this digit from the list of digits.
45 /// FIXME: this has to be revisited. By using the AliMUONDigit::fFlags we
46 /// should in principle flag a digit as bad w/o removing it, but this
47 /// then requires some changes in the cluster finder to deal with this extra
48 /// information correctly (e.g. to set a quality for the cluster if it contains
51 /// \author Laurent Aphecetche
52 //-----------------------------------------------------------------------------
56 ClassImp(AliMUONDigitCalibrator)
59 const Int_t AliMUONDigitCalibrator::fgkNoGain(0);
60 const Int_t AliMUONDigitCalibrator::fgkGainConstantCapa(1);
61 const Int_t AliMUONDigitCalibrator::fgkGain(2);
63 //_____________________________________________________________________________
64 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
65 const char* calibMode)
67 fLogger(new AliMUONLogger(20000)),
77 TString cMode(calibMode);
80 if ( cMode == "NOGAIN" )
82 fApplyGains = fgkNoGain;
83 AliInfo("Will NOT apply gain correction");
85 else if ( cMode == "GAINCONSTANTCAPA" )
87 fApplyGains = fgkGainConstantCapa;
88 AliInfo("Will apply gain correction, but with constant capacitance");
90 else if ( cMode == "GAIN" )
92 fApplyGains = fgkGain;
93 AliInfo("Will apply gain correction, with measured capacitances");
97 AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
98 fApplyGains = fgkNoGain;
101 fStatusMaker = new AliMUONPadStatusMaker(calib);
103 // this is here that we decide on our "goodness" policy, i.e.
104 // what do we call an invalid pad (a pad maybe bad because its HV
105 // was too low, or its pedestals too high, etc..)
106 // FIXME: find a way not to hard-code the goodness policy (i.e. the limits)
108 fStatusMaker->SetHVSt12Limits(1300,1600);
109 fStatusMaker->SetHVSt345Limits(1500,2000);
110 fStatusMaker->SetPedMeanLimits(50,200);
111 fStatusMaker->SetPedSigmaLimits(0.1,3);
114 //FIXME: kind of fake one for the moment, we consider dead only
115 // if ped and/or hv value missing.
116 //WARNING : getting this mask wrong is a very effective way of getting
117 //no digits at all out of this class ;-)
119 Bool_t deferredInitialization = kTRUE;
121 fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,mask,deferredInitialization);
123 fPedestals = calib.Pedestals();
125 fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
126 // to get the saturation value...
128 if ( fApplyGains == fgkGain )
130 fCapacitances = calib.Capacitances();
134 //_____________________________________________________________________________
135 AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
139 delete fStatusMapMaker;
141 AliInfo("Summary of messages:");
147 //_____________________________________________________________________________
149 AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
151 /// Calibrate the digits contained in digitStore
152 TIter next(digitStore.CreateTrackerIterator());
153 AliMUONVDigit* digit;
155 Double_t nsigmas(3.0);
157 AliDebug(1,Form("# of digits = %d",digitStore.GetSize()));
159 while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
161 if ( digit->DetElemId() != detElemId )
163 // Find out occupancy of that DE
164 detElemId = digit->DetElemId();
165 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
166 Double_t nchannels = de->NofChannels();
167 Double_t occ = digitStore.GetSize(detElemId)/nchannels;
170 nsigmas = 10.0; // enlarge (a lot) sigma cut if occupancy is high
171 // (which probably means zero suppression was not exactly OK).
172 fLogger->Log(Form("Will use %5.0f*sigma cut for DE %04d "
173 "due to high occupancy",nsigmas,detElemId));
181 CalibrateDigit(*digit,nsigmas);
185 //_____________________________________________________________________________
187 AliMUONDigitCalibrator::CalibrateDigit(AliMUONVDigit& digit, Double_t nsigmas)
189 /// Calibrate one digit
191 if ( digit.IsCalibrated() )
193 fLogger->Log("ERROR : trying to calibrate a digit twice");
197 Int_t statusMap = fStatusMapMaker->StatusMap(digit.DetElemId(),
199 digit.ManuChannel());
201 digit.SetStatusMap(statusMap);
202 digit.Calibrated(kTRUE);
204 if ( ( statusMap & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 )
206 // pad itself is bad (not testing its neighbours at this stage)
208 fLogger->Log(Form("%s:%d:Channel detElemId %d manuId %d "
209 "manuChannel %d is bad %x",__FILE__,__LINE__,
210 digit.DetElemId(),digit.ManuId(),
211 digit.ManuChannel(),digit.StatusMap()));
215 // If the channel is good, go on with the calibration itself.
217 AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
218 (fPedestals->FindObject(digit.DetElemId(),digit.ManuId()));
222 // no pedestal -> no charge
225 fLogger->Log(Form("Got a null pedestal object for DE,manu=%d,%d",
226 digit.DetElemId(),digit.ManuId()));
231 AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
232 (fGains->FindObject(digit.DetElemId(),digit.ManuId()));
236 if ( fApplyGains != fgkNoGain )
238 // no gain -> no charge
241 fLogger->Log(Form("Got a null gain object for DE,manu=%d,%d",
242 digit.DetElemId(),digit.ManuId()));
247 Int_t manuChannel = digit.ManuChannel();
248 Float_t adc = digit.ADC();
249 Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
253 if ( fApplyGains == fgkGainConstantCapa )
257 else if ( fApplyGains == fgkGain )
259 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(digit.DetElemId());
261 Int_t serialNumber = de->GetManuSerialFromId(digit.ManuId());
263 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
267 capa = param->ValueAsFloat(digit.ManuChannel());
271 fLogger->Log(Form("No capa found for serialNumber=%d",serialNumber));
276 if ( padc > nsigmas*pedestal->ValueAsFloat(manuChannel,1) )
278 if ( fApplyGains != fgkNoGain )
280 Float_t a0 = gain->ValueAsFloat(manuChannel,0);
281 Float_t a1 = gain->ValueAsFloat(manuChannel,1);
282 Int_t thres = gain->ValueAsInt(manuChannel,2);
289 charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
299 digit.SetCharge(charge);
301 Int_t saturation(3000);
305 saturation = gain->ValueAsInt(manuChannel,4);
308 if ( padc >= saturation )
310 digit.Saturated(kTRUE);