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"
25 #include "AliMUON2DMap.h"
26 #include "AliMUONCalibParamND.h"
27 #include "AliMUONCalibrationData.h"
28 #include "AliMUONDigitCalibrator.h"
29 #include "AliMUONRawStreamTracker.h"
30 #include "AliMUONRawStreamTrackerHP.h"
31 #include "AliMUONRecoParam.h"
32 #include "AliMUONReconstructor.h"
33 #include "AliMUONTrackerData.h"
34 #include "AliMpDDLStore.h"
35 #include "AliRawEventHeaderBase.h"
36 #include "AliRawReader.h"
37 #include <Riostream.h>
39 ///\class AliMUONTrackerCalibratedDataMaker
41 /// Creator of AliMUONVTrackerData from AliRawReader
43 ///\author Laurent Aphecetche, Subatech
46 ClassImp(AliMUONTrackerCalibratedDataMaker)
49 Int_t AliMUONTrackerCalibratedDataMaker::fgkCounter(0);
51 //_____________________________________________________________________________
52 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(TRootIOCtor*)
53 : AliMUONVTrackerDataMaker(),
55 fIsOwnerOfRawReader(kFALSE),
56 fAccumulatedData(0x0),
60 fDigitCalibrator(0x0),
61 fCalibrationData(0x0),
69 //_____________________________________________________________________________
70 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(const AliMUONRecoParam* recoParam,
74 const char* calibMode,
79 : AliMUONVTrackerDataMaker(),
81 fIsOwnerOfRawReader(kFALSE),
82 fAccumulatedData(0x0),
83 fOneEventData(new AliMUON2DMap(true)),
84 fSource("unspecified"),
86 fDigitCalibrator(0x0),
87 fCalibrationData(0x0),
90 fUseHPDecoder(useHPdecoder)
92 /// Ctor in which this object will NOT be owner of the reader,
93 /// and can NOT apply rewind to it, nor use Next on it
95 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
98 //_____________________________________________________________________________
99 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(const AliMUONRecoParam* recoParam,
100 AliRawReader* reader,
102 const char* calibMode,
107 : AliMUONVTrackerDataMaker(),
109 fIsOwnerOfRawReader(kTRUE),
110 fAccumulatedData(0x0),
111 fOneEventData(new AliMUON2DMap(true)),
112 fSource("unspecified"),
114 fDigitCalibrator(0x0),
115 fCalibrationData(0x0),
118 fUseHPDecoder(useHPDecoder)
120 /// Ctor, in which we are the owner of the reader, so we can rewind and advance it
127 fRawReader->NextEvent(); // to be sure to get run number available
128 runNumber = reader->GetRunNumber();
129 fRawReader->RewindEvents();
132 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
135 //_____________________________________________________________________________
137 AliMUONTrackerCalibratedDataMaker::Ctor(const AliMUONRecoParam* recoParam,
138 Int_t runNumber, const char* calibMode,
139 Bool_t histogram, Double_t xmin, Double_t xmax)
141 /// "designated" constructor.
145 Bool_t calibrate = ( fCDBPath.Length() > 0 );
147 TString basename("RAW");
151 TString scalib(calibMode);
153 if ( scalib == "GAIN" ) basename = "CALC";
154 if ( scalib == "NOGAIN" ) basename = "CALZ";
155 if ( scalib == "GAINCONSTANTCAPA" ) basename = "CALG";
160 name = Form("%s%s_%d",
161 (histogram ? "H" : ""),
167 name = Form("%s%s%d",
168 (histogram ? "H" : ""),
173 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
174 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
177 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
178 AliInfo(Form("Will histogram between %e and %e",xmin,xmax));
183 fCalibrationData = new AliMUONCalibrationData(runNumber);
185 // force the reading of calibration NOW
186 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
187 // once here and once in the digitcalibrator class, hence the change of them getting
189 // But with the current CDBManager implementation, I don't know how to solve
190 // this better (e.g. to avoid clearing cache messages and so on).
192 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
194 if ( storage->GetURI() != fCDBPath.Data() )
196 AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
199 fCalibrationData->Pedestals();
200 fCalibrationData->Gains();
201 fCalibrationData->Neighbours();
202 fCalibrationData->HV();
203 fCalibrationData->Capacitances();
205 if ( storage->GetURI() != fCDBPath.Data() )
207 AliCDBManager::Instance()->SetDefaultStorage(storage);
210 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
211 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
215 //_____________________________________________________________________________
216 AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
219 delete fOneEventData;
220 delete fAccumulatedData;
221 if ( fIsOwnerOfRawReader ) delete fRawReader;
222 delete fCalibrationData;
223 delete fDigitCalibrator;
226 //_____________________________________________________________________________
228 AliMUONTrackerCalibratedDataMaker::Merge(TCollection*)
231 AliError("Not implemented yet");
235 //_____________________________________________________________________________
237 AliMUONTrackerCalibratedDataMaker::NextEvent()
239 /// Read and process next event
241 if ( !fIsOwnerOfRawReader )
243 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
247 AliCodeTimerAuto("");
249 static Int_t nphysics(0);
250 static Int_t ngood(0);
252 if ( !IsRunning() ) return kTRUE;
254 Bool_t ok = fRawReader->NextEvent();
261 Int_t eventType = fRawReader->GetType();
265 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
267 return kTRUE; // for the moment
272 Bool_t pok = ProcessEvent();
276 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
281 //_____________________________________________________________________________
283 AliMUONTrackerCalibratedDataMaker::ProcessEvent()
285 /// Process current event
286 /// Note that we do not simply reuse the AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&)
287 /// method, as this would require filling first a digitStore, and then calibrate it, and
288 /// then convert it into a VStore, all this taking too much time.
290 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
291 /// duplicate this critical piece of calibration code !
294 AliCodeTimerAuto("");
296 AliMUONVRawStreamTracker* stream = 0x0;
300 stream = new AliMUONRawStreamTrackerHP(fRawReader);
304 stream = new AliMUONRawStreamTracker(fRawReader);
307 stream->EnabbleErrorLogger();
315 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
316 TArrayI nevents(nddls);
318 for ( Int_t i = 0; i < nddls; ++i )
323 fOneEventData->Clear();
325 while ( stream->Next(buspatchId,manuId,manuChannel,adc) )
327 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
329 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
333 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
336 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
337 AliMUONVCalibParam::InvalidFloatValue());
338 fOneEventData->Add(param);
341 Bool_t ok = fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel);
345 Float_t charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0);
349 param->SetValueAsDouble(manuChannel,0,charge);
356 if ( !stream->IsErrorMessage() )
359 fAccumulatedData->Add(*fOneEventData,&nevents);
367 //_____________________________________________________________________________
369 AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
373 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
378 //_____________________________________________________________________________
380 AliMUONTrackerCalibratedDataMaker::Rewind()
383 fRawReader->RewindEvents();
387 //_____________________________________________________________________________
389 AliMUONTrackerCalibratedDataMaker::SetRawReader(AliRawReader* rawReader)
391 /// Points to another raw reader
393 if ( fIsOwnerOfRawReader )
395 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
397 fRawReader = rawReader;