]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONDigitCalibrator.cxx
bug fixed (Valerie)
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitCalibrator.cxx
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 "AliMUONCalibrationData.h"
21 #include "AliMUONVDigit.h"
22 #include "AliMUONVDigitStore.h"
23 #include "AliMUONLogger.h"
24 #include "AliMUONPadStatusMaker.h"
25 #include "AliMUONPadStatusMapMaker.h"
26 #include "AliMUONVStore.h"
27 #include "AliMUONVCalibParam.h"
28 #include "AliMpConstants.h"
29 #include "AliMpDetElement.h"
30 #include "AliMpDDLStore.h"
31 #include "AliLog.h"
32
33 //-----------------------------------------------------------------------------
34 /// \class AliMUONDigitCalibrator
35 /// Class used to calibrate digits (either real or simulated ones).
36 ///
37 /// The calibration consists of subtracting the pedestal
38 /// and multiplying by a gain, so that
39 /// Signal = (ADC-pedestal)*gain
40 ///
41 /// Please note also that for the moment, if a digit lies on a dead channel
42 /// we remove this digit from the list of digits.
43 /// FIXME: this has to be revisited. By using the AliMUONDigit::fFlags we
44 /// should in principle flag a digit as bad w/o removing it, but this 
45 /// then requires some changes in the cluster finder to deal with this extra
46 /// information correctly (e.g. to set a quality for the cluster if it contains
47 /// bad digits).
48 ///
49 /// \author Laurent Aphecetche
50 //-----------------------------------------------------------------------------
51
52
53 /// \cond CLASSIMP
54 ClassImp(AliMUONDigitCalibrator)
55 /// \endcond
56
57 const Int_t AliMUONDigitCalibrator::fgkNoGain(0);
58 const Int_t AliMUONDigitCalibrator::fgkGainConstantCapa(1);
59 const Int_t AliMUONDigitCalibrator::fgkGain(2);
60
61 //_____________________________________________________________________________
62 AliMUONDigitCalibrator::AliMUONDigitCalibrator(const AliMUONCalibrationData& calib,
63                                                const char* calibMode)
64 : TObject(),
65 fLogger(new AliMUONLogger(1000)),
66 fStatusMaker(0x0),
67 fStatusMapMaker(0x0),
68 fPedestals(0x0),
69 fGains(0x0),
70 fApplyGains(0),
71 fCapacitances(0x0)
72 {
73   /// ctor
74   
75   TString cMode(calibMode);
76   cMode.ToUpper();
77   
78   if ( cMode == "NOGAIN" ) 
79   {
80     fApplyGains = fgkNoGain;
81     AliInfo("Will NOT apply gain correction");
82   }
83   else if ( cMode = "GAINCONSTANTCAPA" ) 
84   {
85     fApplyGains = fgkGainConstantCapa;
86     AliInfo("Will apply gain correction, but with constant capacitance");
87   }
88   else if ( cMode == "GAIN" ) 
89   {
90     fApplyGains = fgkGain;
91     AliInfo("Will apply gain correction, with measured capacitances");
92   }
93   else
94   {
95     AliError(Form("Invalid calib mode = %s. Will use NOGAIN instead",calibMode));
96     fApplyGains = fgkNoGain;
97   }
98        
99   fStatusMaker = new AliMUONPadStatusMaker(calib);
100   
101   // this is here that we decide on our "goodness" policy, i.e.
102   // what do we call an invalid pad (a pad maybe bad because its HV
103   // was too low, or its pedestals too high, etc..)
104   // FIXME: find a way not to hard-code the goodness policy (i.e. the limits)
105   // here...
106   fStatusMaker->SetHVSt12Limits(1300,1600);
107   fStatusMaker->SetHVSt345Limits(1500,2000);
108   fStatusMaker->SetPedMeanLimits(50,200);
109   fStatusMaker->SetPedSigmaLimits(0.1,3);
110   
111   Int_t mask(0x8080); 
112   //FIXME: kind of fake one for the moment, we consider dead only 
113   // if ped and/or hv value missing.
114   //WARNING : getting this mask wrong is a very effective way of getting
115   //no digits at all out of this class ;-)
116   
117   Bool_t deferredInitialization = kTRUE;
118   
119   fStatusMapMaker = new AliMUONPadStatusMapMaker(*fStatusMaker,mask,deferredInitialization);
120   
121   fPedestals = calib.Pedestals();
122
123   fGains = calib.Gains(); // we get gains whatever the calibMode is, in order
124   // to get the saturation value...
125
126   if ( fApplyGains == fgkGain ) 
127   {
128     fCapacitances = calib.Capacitances();
129   }
130 }
131
132 //_____________________________________________________________________________
133 AliMUONDigitCalibrator::~AliMUONDigitCalibrator()
134 {
135   /// dtor.
136   delete fStatusMaker;
137   delete fStatusMapMaker;
138   
139   AliInfo("Summary of messages:");
140   fLogger->Print();
141
142   delete fLogger;
143 }
144
145 //_____________________________________________________________________________
146 void
147 AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore& digitStore)
148 {
149   /// Calibrate the digits contained in digitStore  
150   TIter next(digitStore.CreateTrackerIterator());
151   AliMUONVDigit* digit;
152   
153   while ( ( digit = static_cast<AliMUONVDigit*>(next() ) ) )
154   {
155     CalibrateDigit(*digit);
156   }
157 }
158
159 //_____________________________________________________________________________
160 void
161 AliMUONDigitCalibrator::CalibrateDigit(AliMUONVDigit& digit)
162 {
163   /// Calibrate one digit
164   
165   if ( digit.IsCalibrated() ) 
166   {
167     fLogger->Log("ERROR : trying to calibrate a digit twice");
168     return;
169   }
170   
171   Int_t statusMap = fStatusMapMaker->StatusMap(digit.DetElemId(),
172                                                digit.ManuId(),
173                                                digit.ManuChannel());
174
175   digit.SetStatusMap(statusMap);
176   digit.Calibrated(kTRUE);
177   
178   if ( ( statusMap & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0 ) 
179   {
180     // pad itself is bad (not testing its neighbours at this stage)
181     digit.SetCharge(0);
182     fLogger->Log(Form("%s:%d:Channel detElemId %d manuId %d "
183                     "manuChannel %d is bad %x",__FILE__,__LINE__,
184                     digit.DetElemId(),digit.ManuId(),
185                     digit.ManuChannel(),digit.StatusMap()));
186   }
187   else
188   {
189     // If the channel is good, go on with the calibration itself.
190
191     AliMUONVCalibParam* pedestal = static_cast<AliMUONVCalibParam*>
192     (fPedestals->FindObject(digit.DetElemId(),digit.ManuId()));
193     
194     if (!pedestal)
195     {
196       AliFatal(Form("Got a null ped object for DE,manu=%d,%d",
197                     digit.DetElemId(),digit.ManuId()));
198       
199     }
200
201     AliMUONVCalibParam* gain = static_cast<AliMUONVCalibParam*>
202         (fGains->FindObject(digit.DetElemId(),digit.ManuId()));
203
204     if (!gain)
205     {
206       AliFatal(Form("Got a null gain object for DE,manu=%d,%d",
207                     digit.DetElemId(),digit.ManuId()));        
208     }
209     
210     Int_t manuChannel = digit.ManuChannel();
211     Float_t adc = digit.ADC();
212     Float_t padc = adc-pedestal->ValueAsFloat(manuChannel,0);
213     Float_t charge(0);
214     Float_t capa(1.0);
215     
216     if ( fApplyGains == fgkGainConstantCapa ) 
217     {
218       capa = 0.2; // pF
219     }
220     else if ( fApplyGains == fgkGain ) 
221     {
222       AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(digit.DetElemId());
223       
224       Int_t serialNumber = de->GetManuSerialFromId(digit.ManuId());
225
226       AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fCapacitances->FindObject(serialNumber));
227       
228       capa = param->ValueAsFloat(digit.ManuChannel());
229     }
230     
231     if ( padc > 3.0*pedestal->ValueAsFloat(manuChannel,1) ) 
232     {
233       if ( fApplyGains != fgkNoGain ) 
234       {
235         Float_t a0 = gain->ValueAsFloat(manuChannel,0);
236         Float_t a1 = gain->ValueAsFloat(manuChannel,1);
237         Int_t thres = gain->ValueAsInt(manuChannel,2);
238         if ( padc < thres ) 
239         {
240           charge = a0*padc;
241         }
242         else
243         {
244           charge = a0*thres + a0*(padc-thres) + a1*(padc-thres)*(padc-thres);
245         }
246       }
247       else
248       {
249         charge = padc;
250       }
251     }
252     charge *= capa;
253     digit.SetCharge(charge);
254     Int_t saturation = gain->ValueAsInt(manuChannel,4);
255     if ( padc >= saturation )
256     {
257       digit.Saturated(kTRUE);
258     }
259   }
260 }