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(Int_t runNumber,
72 const char* calibMode,
77 : AliMUONVTrackerDataMaker(),
79 fIsOwnerOfRawReader(kFALSE),
80 fAccumulatedData(0x0),
81 fOneEventData(new AliMUON2DMap(true)),
82 fSource("unspecified"),
84 fDigitCalibrator(0x0),
85 fCalibrationData(0x0),
88 fUseHPDecoder(useHPdecoder)
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
93 Ctor(runNumber,calibMode,histogram,xmin,xmax);
96 //_____________________________________________________________________________
97 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(AliRawReader* reader,
99 const char* calibMode,
104 : AliMUONVTrackerDataMaker(),
106 fIsOwnerOfRawReader(kTRUE),
107 fAccumulatedData(0x0),
108 fOneEventData(new AliMUON2DMap(true)),
109 fSource("unspecified"),
111 fDigitCalibrator(0x0),
112 fCalibrationData(0x0),
115 fUseHPDecoder(useHPDecoder)
117 /// Ctor, in which we are the owner of the reader, so we can rewind and advance it
124 fRawReader->NextEvent(); // to be sure to get run number available
125 runNumber = reader->GetRunNumber();
126 fRawReader->RewindEvents();
129 Ctor(runNumber,calibMode,histogram,xmin,xmax);
132 //_____________________________________________________________________________
134 AliMUONTrackerCalibratedDataMaker::Ctor(Int_t runNumber, const char* calibMode,
135 Bool_t histogram, Double_t xmin, Double_t xmax)
137 /// "designated" constructor.
141 Bool_t calibrate = ( fCDBPath.Length() > 0 );
143 TString basename("RAW");
147 TString scalib(calibMode);
149 if ( scalib == "GAIN" ) basename = "CALC";
150 if ( scalib == "NOGAIN" ) basename = "CALZ";
151 if ( scalib == "GAINCONSTANTCAPA" ) basename = "CALG";
156 name = Form("%s%s_%d",
157 (histogram ? "H" : ""),
163 name = Form("%s%s%d",
164 (histogram ? "H" : ""),
169 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
170 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
173 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
174 AliInfo(Form("Will histogram between %e and %e",xmin,xmax));
179 fCalibrationData = new AliMUONCalibrationData(runNumber);
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
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).
188 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
190 if ( storage->GetURI() != fCDBPath.Data() )
192 AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
195 fCalibrationData->Pedestals();
196 fCalibrationData->Gains();
197 fCalibrationData->Neighbours();
198 fCalibrationData->HV();
199 fCalibrationData->Capacitances();
201 if ( storage->GetURI() != fCDBPath.Data() )
203 AliCDBManager::Instance()->SetDefaultStorage(storage);
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 ?
212 //_____________________________________________________________________________
213 AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
216 delete fOneEventData;
217 delete fAccumulatedData;
218 if ( fIsOwnerOfRawReader ) delete fRawReader;
219 delete fCalibrationData;
220 delete fDigitCalibrator;
223 //_____________________________________________________________________________
225 AliMUONTrackerCalibratedDataMaker::Merge(TCollection*)
228 AliError("Not implemented yet");
232 //_____________________________________________________________________________
234 AliMUONTrackerCalibratedDataMaker::NextEvent()
236 /// Read and process next event
238 if ( !fIsOwnerOfRawReader )
240 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
244 AliCodeTimerAuto("");
246 static Int_t nphysics(0);
247 static Int_t ngood(0);
249 if ( !IsRunning() ) return kTRUE;
251 Bool_t ok = fRawReader->NextEvent();
258 Int_t eventType = fRawReader->GetType();
262 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
264 return kTRUE; // for the moment
269 Bool_t pok = ProcessEvent();
273 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
278 //_____________________________________________________________________________
280 AliMUONTrackerCalibratedDataMaker::ProcessEvent()
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.
287 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
288 /// duplicate this critical piece of calibration code !
291 AliCodeTimerAuto("");
293 AliMUONVRawStreamTracker* stream = 0x0;
297 stream = new AliMUONRawStreamTrackerHP(fRawReader);
301 stream = new AliMUONRawStreamTracker(fRawReader);
311 fOneEventData->Clear();
313 while ( stream->Next(buspatchId,manuId,manuChannel,adc) )
315 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
317 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
320 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
321 AliMUONVCalibParam::InvalidFloatValue());
322 fOneEventData->Add(param);
325 Bool_t ok = fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel);
329 Float_t charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0);
333 param->SetValueAsDouble(manuChannel,0,charge);
340 if ( !stream->IsErrorMessage() )
343 fAccumulatedData->Add(*fOneEventData);
351 //_____________________________________________________________________________
353 AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
357 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
362 //_____________________________________________________________________________
364 AliMUONTrackerCalibratedDataMaker::Rewind()
367 fRawReader->RewindEvents();
371 //_____________________________________________________________________________
373 AliMUONTrackerCalibratedDataMaker::SetRawReader(AliRawReader* rawReader)
375 /// Points to another raw reader
377 if ( fIsOwnerOfRawReader )
379 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
381 fRawReader = rawReader;