Separating run-dependent mapping data from data, which are not
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerCalibratedDataMaker.cxx
CommitLineData
8741815f 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 "AliMUONTrackerCalibratedDataMaker.h"
19
515cc5b5 20#include "AliCDBManager.h"
21#include "AliCDBStorage.h"
22#include "AliCodeTimer.h"
23#include "AliLog.h"
8741815f 24#include "AliMUON2DMap.h"
25#include "AliMUONCalibParamND.h"
26#include "AliMUONCalibrationData.h"
27#include "AliMUONDigitCalibrator.h"
515cc5b5 28#include "AliMUONRawStreamTracker.h"
29#include "AliMUONRawStreamTrackerHP.h"
30#include "AliMUONRecoParam.h"
31#include "AliMUONReconstructor.h"
8741815f 32#include "AliMUONTrackerData.h"
8741815f 33#include "AliMpDDLStore.h"
8741815f 34#include "AliRawEventHeaderBase.h"
35#include "AliRawReader.h"
8741815f 36#include <Riostream.h>
37
38///\class AliMUONTrackerCalibratedDataMaker
39///
40/// Creator of AliMUONVTrackerData from AliRawReader
41///
42///\author Laurent Aphecetche, Subatech
43
44///\cond CLASSIMP
45ClassImp(AliMUONTrackerCalibratedDataMaker)
46///\endcond
47
48Int_t AliMUONTrackerCalibratedDataMaker::fgkCounter(0);
49
50//_____________________________________________________________________________
515cc5b5 51AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(TRootIOCtor*)
52: AliMUONVTrackerDataMaker(),
53fRawReader(0x0),
54fIsOwnerOfRawReader(kFALSE),
55fAccumulatedData(0x0),
56fOneEventData(0x0),
57fSource(""),
58fIsRunning(kFALSE),
59fDigitCalibrator(0x0),
60fCalibrationData(0x0),
61fCDBPath(""),
62fNumberOfEvents(0),
63fUseHPDecoder(kTRUE)
64{
65 /// Root IO ctor
66}
67
68//_____________________________________________________________________________
69AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(Int_t runNumber,
70 AliRawReader* reader,
71 const char* cdbpath,
72 const char* calibMode,
73 Bool_t histogram,
74 Double_t xmin,
75 Double_t xmax,
76 Bool_t useHPdecoder)
77: AliMUONVTrackerDataMaker(),
78fRawReader(reader),
79fIsOwnerOfRawReader(kFALSE),
80fAccumulatedData(0x0),
81fOneEventData(new AliMUON2DMap(true)),
82fSource("unspecified"),
83fIsRunning(kFALSE),
84fDigitCalibrator(0x0),
85fCalibrationData(0x0),
86fCDBPath(cdbpath),
87fNumberOfEvents(0),
88fUseHPDecoder(useHPdecoder)
89{
90 /// Ctor in which this object will NOT be owner of the reader,
91 /// and can NOT apply rewind to it, nor use Next on it
92
93 Ctor(runNumber,calibMode,histogram,xmin,xmax);
94}
95
96//_____________________________________________________________________________
8741815f 97AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(AliRawReader* reader,
10eb3d17 98 const char* cdbpath,
99 const char* calibMode,
100 Bool_t histogram,
101 Double_t xmin,
515cc5b5 102 Double_t xmax,
103 Bool_t useHPDecoder)
8741815f 104: AliMUONVTrackerDataMaker(),
515cc5b5 105fRawReader(reader),
106fIsOwnerOfRawReader(kTRUE),
107fAccumulatedData(0x0),
108fOneEventData(new AliMUON2DMap(true)),
109fSource("unspecified"),
110fIsRunning(kFALSE),
111fDigitCalibrator(0x0),
112fCalibrationData(0x0),
113fCDBPath(cdbpath),
114fNumberOfEvents(0),
115fUseHPDecoder(useHPDecoder)
49419555 116{
515cc5b5 117 /// Ctor, in which we are the owner of the reader, so we can rewind and advance it
118 /// as we wish
49419555 119
515cc5b5 120 Int_t runNumber(0);
121
49419555 122 if ( fRawReader )
123 {
515cc5b5 124 fRawReader->NextEvent(); // to be sure to get run number available
49419555 125 runNumber = reader->GetRunNumber();
515cc5b5 126 fRawReader->RewindEvents();
49419555 127 }
515cc5b5 128
129 Ctor(runNumber,calibMode,histogram,xmin,xmax);
130}
131
132//_____________________________________________________________________________
133void
134AliMUONTrackerCalibratedDataMaker::Ctor(Int_t runNumber, const char* calibMode,
135 Bool_t histogram, Double_t xmin, Double_t xmax)
136{
137 /// "designated" constructor.
138
8741815f 139 ++fgkCounter;
140
141 Bool_t calibrate = ( fCDBPath.Length() > 0 );
8741815f 142 TString name;
10eb3d17 143 TString basename("RAW");
144
145 if ( calibrate )
146 {
147 TString scalib(calibMode);
148 scalib.ToUpper();
149 if ( scalib == "GAIN" ) basename = "CALC";
150 if ( scalib == "NOGAIN" ) basename = "CALZ";
151 if ( scalib == "GAINCONSTANTCAPA" ) basename = "CALG";
152 }
8741815f 153
154 if (!runNumber)
155 {
515cc5b5 156 name = Form("%s%s_%d",
10eb3d17 157 (histogram ? "H" : ""),
158 basename.Data(),
159 fgkCounter);
8741815f 160 }
161 else
162 {
10eb3d17 163 name = Form("%s%s%d",
164 (histogram ? "H" : ""),
165 basename.Data(),
166 runNumber);
8741815f 167 }
168
169 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
170 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
10eb3d17 171 if ( histogram )
172 {
173 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
174 AliInfo(Form("Will histogram between %e and %e",xmin,xmax));
175 }
8741815f 176
8741815f 177 if ( calibrate )
178 {
179 fCalibrationData = new AliMUONCalibrationData(runNumber);
180
181 // force the reading of calibration NOW
182 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
183 // once here and once in the digitcalibrator class, hence the change of them getting
184 // out of sync)
185 // But with the current CDBManager implementation, I don't know how to solve
186 // this better (e.g. to avoid clearing cache messages and so on).
187
188 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
189
190 if ( storage->GetURI() != fCDBPath.Data() )
191 {
192 AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
193 }
194
195 fCalibrationData->Pedestals();
196 fCalibrationData->Gains();
197 fCalibrationData->Neighbours();
198 fCalibrationData->HV();
199 fCalibrationData->Capacitances();
200
201 if ( storage->GetURI() != fCDBPath.Data() )
202 {
203 AliCDBManager::Instance()->SetDefaultStorage(storage);
204 }
205
515cc5b5 206 const AliMUONRecoParam* recoParams = AliMUONReconstructor::GetRecoParam();
207 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParams,calibMode);
208 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
8741815f 209 }
210}
211
212//_____________________________________________________________________________
213AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
214{
215 /// dtor
216 delete fOneEventData;
49419555 217 delete fAccumulatedData;
515cc5b5 218 if ( fIsOwnerOfRawReader ) delete fRawReader;
8741815f 219 delete fCalibrationData;
8741815f 220 delete fDigitCalibrator;
221}
222
223//_____________________________________________________________________________
49419555 224Long64_t
225AliMUONTrackerCalibratedDataMaker::Merge(TCollection*)
226{
227 /// Merge
228 AliError("Not implemented yet");
229 return 0;
230}
231
232//_____________________________________________________________________________
8741815f 233Bool_t
234AliMUONTrackerCalibratedDataMaker::NextEvent()
235{
515cc5b5 236 /// Read and process next event
8741815f 237
515cc5b5 238 if ( !fIsOwnerOfRawReader )
239 {
240 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
241 return kFALSE;
242 }
243
8741815f 244 AliCodeTimerAuto("");
245
246 static Int_t nphysics(0);
247 static Int_t ngood(0);
248
249 if ( !IsRunning() ) return kTRUE;
250
251 Bool_t ok = fRawReader->NextEvent();
252
253 if (!ok)
254 {
8741815f 255 return kFALSE;
256 }
257
258 Int_t eventType = fRawReader->GetType();
259
260 ++fNumberOfEvents;
261
262 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
263 {
264 return kTRUE; // for the moment
265 }
266
267 ++nphysics;
268
515cc5b5 269 Bool_t pok = ProcessEvent();
270
271 if ( pok ) ++ngood;
272
273 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
274
275 return kTRUE;
8741815f 276}
277
278//_____________________________________________________________________________
515cc5b5 279Bool_t
280AliMUONTrackerCalibratedDataMaker::ProcessEvent()
8741815f 281{
515cc5b5 282 /// Process current event
283 /// Note that we do not simply reuse the AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&)
284 /// method, as this would require filling first a digitStore, and then calibrate it, and
285 /// then convert it into a VStore, all this taking too much time.
286 ///
287 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
288 /// duplicate this critical piece of calibration code !
289 ///
8741815f 290
291 AliCodeTimerAuto("");
8741815f 292
515cc5b5 293 AliMUONVRawStreamTracker* stream = 0x0;
8741815f 294
515cc5b5 295 if ( fUseHPDecoder )
296 {
297 stream = new AliMUONRawStreamTrackerHP(fRawReader);
298 }
299 else
8741815f 300 {
515cc5b5 301 stream = new AliMUONRawStreamTracker(fRawReader);
302 }
303
304 stream->First();
305
306 Int_t buspatchId;
307 UShort_t manuId;
308 UChar_t manuChannel;
309 UShort_t adc;
310
311 fOneEventData->Clear();
312
313 while ( stream->Next(buspatchId,manuId,manuChannel,adc) )
314 {
315 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
316
317 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
318 if (!param)
319 {
320 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
321 AliMUONVCalibParam::InvalidFloatValue());
322 fOneEventData->Add(param);
323 }
324
325 Bool_t ok = fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel);
8741815f 326
515cc5b5 327 if ( ok )
8741815f 328 {
515cc5b5 329 Float_t charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0);
8741815f 330
515cc5b5 331 if (charge > 0.0 )
8741815f 332 {
515cc5b5 333 param->SetValueAsDouble(manuChannel,0,charge);
8741815f 334 }
8741815f 335 }
515cc5b5 336 }
337
338 Bool_t good(kFALSE);
339
340 if ( !stream->IsErrorMessage() )
341 {
342 good = kTRUE;
343 fAccumulatedData->Add(*fOneEventData);
8741815f 344 }
515cc5b5 345
346 delete stream;
347
348 return good;
8741815f 349}
350
351//_____________________________________________________________________________
352void
353AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
354{
355 /// Printout
356
357 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
358 << endl;
359
360}
361
362//_____________________________________________________________________________
363void
364AliMUONTrackerCalibratedDataMaker::Rewind()
365{
366 /// Rewind events
367 fRawReader->RewindEvents();
368 fNumberOfEvents=0;
369}
515cc5b5 370
371//_____________________________________________________________________________
372void
373AliMUONTrackerCalibratedDataMaker::SetRawReader(AliRawReader* rawReader)
374{
375 /// Points to another raw reader
376
377 if ( fIsOwnerOfRawReader )
378 {
379 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
380 }
381 fRawReader = rawReader;
382}