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