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 "AliMUONTrackerCalibratedDataMaker.h"
20 #include "AliCDBManager.h"
21 #include "AliCDBStorage.h"
22 #include "AliCodeTimer.h"
24 #include "AliMUON2DMap.h"
25 #include "AliMUONCalibParamND.h"
26 #include "AliMUONCalibrationData.h"
27 #include "AliMUONDigitCalibrator.h"
28 #include "AliMUONRawStreamTracker.h"
29 #include "AliMUONRawStreamTrackerHP.h"
30 #include "AliMUONRecoParam.h"
31 #include "AliMUONReconstructor.h"
32 #include "AliMUONTrackerData.h"
33 #include "AliMpDDLStore.h"
34 #include "AliRawEventHeaderBase.h"
35 #include "AliRawReader.h"
36 #include <Riostream.h>
38 ///\class AliMUONTrackerCalibratedDataMaker
40 /// Creator of AliMUONVTrackerData from AliRawReader
42 ///\author Laurent Aphecetche, Subatech
45 ClassImp(AliMUONTrackerCalibratedDataMaker)
48 Int_t AliMUONTrackerCalibratedDataMaker::fgkCounter(0);
50 //_____________________________________________________________________________
51 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(TRootIOCtor*)
52 : AliMUONVTrackerDataMaker(),
54 fIsOwnerOfRawReader(kFALSE),
55 fAccumulatedData(0x0),
59 fDigitCalibrator(0x0),
60 fCalibrationData(0x0),
68 //_____________________________________________________________________________
69 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(const AliMUONRecoParam* recoParam,
73 const char* calibMode,
78 : AliMUONVTrackerDataMaker(),
80 fIsOwnerOfRawReader(kFALSE),
81 fAccumulatedData(0x0),
82 fOneEventData(new AliMUON2DMap(true)),
83 fSource("unspecified"),
85 fDigitCalibrator(0x0),
86 fCalibrationData(0x0),
89 fUseHPDecoder(useHPdecoder)
91 /// Ctor in which this object will NOT be owner of the reader,
92 /// and can NOT apply rewind to it, nor use Next on it
94 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
97 //_____________________________________________________________________________
98 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(const AliMUONRecoParam* recoParam,
101 const char* calibMode,
106 : AliMUONVTrackerDataMaker(),
108 fIsOwnerOfRawReader(kTRUE),
109 fAccumulatedData(0x0),
110 fOneEventData(new AliMUON2DMap(true)),
111 fSource("unspecified"),
113 fDigitCalibrator(0x0),
114 fCalibrationData(0x0),
117 fUseHPDecoder(useHPDecoder)
119 /// Ctor, in which we are the owner of the reader, so we can rewind and advance it
126 fRawReader->NextEvent(); // to be sure to get run number available
127 runNumber = reader->GetRunNumber();
128 fRawReader->RewindEvents();
131 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
134 //_____________________________________________________________________________
136 AliMUONTrackerCalibratedDataMaker::Ctor(const AliMUONRecoParam* recoParam,
137 Int_t runNumber, const char* calibMode,
138 Bool_t histogram, Double_t xmin, Double_t xmax)
140 /// "designated" constructor.
144 Bool_t calibrate = ( fCDBPath.Length() > 0 );
146 TString basename("RAW");
150 TString scalib(calibMode);
152 if ( scalib == "GAIN" ) basename = "CALC";
153 if ( scalib == "NOGAIN" ) basename = "CALZ";
154 if ( scalib == "GAINCONSTANTCAPA" ) basename = "CALG";
159 name = Form("%s%s_%d",
160 (histogram ? "H" : ""),
166 name = Form("%s%s%d",
167 (histogram ? "H" : ""),
172 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
173 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
176 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
177 AliInfo(Form("Will histogram between %e and %e",xmin,xmax));
182 fCalibrationData = new AliMUONCalibrationData(runNumber);
184 // force the reading of calibration NOW
185 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
186 // once here and once in the digitcalibrator class, hence the change of them getting
188 // But with the current CDBManager implementation, I don't know how to solve
189 // this better (e.g. to avoid clearing cache messages and so on).
191 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
193 if ( storage->GetURI() != fCDBPath.Data() )
195 AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
198 fCalibrationData->Pedestals();
199 fCalibrationData->Gains();
200 fCalibrationData->Neighbours();
201 fCalibrationData->HV();
202 fCalibrationData->Capacitances();
204 if ( storage->GetURI() != fCDBPath.Data() )
206 AliCDBManager::Instance()->SetDefaultStorage(storage);
209 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
210 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
214 //_____________________________________________________________________________
215 AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
218 delete fOneEventData;
219 delete fAccumulatedData;
220 if ( fIsOwnerOfRawReader ) delete fRawReader;
221 delete fCalibrationData;
222 delete fDigitCalibrator;
225 //_____________________________________________________________________________
227 AliMUONTrackerCalibratedDataMaker::Merge(TCollection*)
230 AliError("Not implemented yet");
234 //_____________________________________________________________________________
236 AliMUONTrackerCalibratedDataMaker::NextEvent()
238 /// Read and process next event
240 if ( !fIsOwnerOfRawReader )
242 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
246 AliCodeTimerAuto("");
248 static Int_t nphysics(0);
249 static Int_t ngood(0);
251 if ( !IsRunning() ) return kTRUE;
253 Bool_t ok = fRawReader->NextEvent();
260 Int_t eventType = fRawReader->GetType();
264 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
266 return kTRUE; // for the moment
271 Bool_t pok = ProcessEvent();
275 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
280 //_____________________________________________________________________________
282 AliMUONTrackerCalibratedDataMaker::ProcessEvent()
284 /// Process current event
285 /// Note that we do not simply reuse the AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&)
286 /// method, as this would require filling first a digitStore, and then calibrate it, and
287 /// then convert it into a VStore, all this taking too much time.
289 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
290 /// duplicate this critical piece of calibration code !
293 AliCodeTimerAuto("");
295 AliMUONVRawStreamTracker* stream = 0x0;
299 stream = new AliMUONRawStreamTrackerHP(fRawReader);
303 stream = new AliMUONRawStreamTracker(fRawReader);
313 fOneEventData->Clear();
315 while ( stream->Next(buspatchId,manuId,manuChannel,adc) )
317 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
319 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
322 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
323 AliMUONVCalibParam::InvalidFloatValue());
324 fOneEventData->Add(param);
327 Bool_t ok = fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel);
331 Float_t charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0);
335 param->SetValueAsDouble(manuChannel,0,charge);
342 if ( !stream->IsErrorMessage() )
345 fAccumulatedData->Add(*fOneEventData);
353 //_____________________________________________________________________________
355 AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
359 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
364 //_____________________________________________________________________________
366 AliMUONTrackerCalibratedDataMaker::Rewind()
369 fRawReader->RewindEvents();
373 //_____________________________________________________________________________
375 AliMUONTrackerCalibratedDataMaker::SetRawReader(AliRawReader* rawReader)
377 /// Points to another raw reader
379 if ( fIsOwnerOfRawReader )
381 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
383 fRawReader = rawReader;