]>
Commit | Line | Data |
---|---|---|
b6f591ae | 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 | /// \class AliMUONTrackerDataMaker | |
19 | /// | |
20 | /// Implementation of VTrackerDataMaker to read raw data and | |
21 | /// calibrate it (if required) | |
22 | /// | |
23 | /// \author Laurent Aphecetche, Subatech | |
24 | ||
25 | #include "AliMUONTrackerDataMaker.h" | |
26 | ||
27 | #include "AliCDBManager.h" | |
28 | #include "AliCDBStorage.h" | |
29 | #include "AliCodeTimer.h" | |
30 | #include "AliDAQ.h" | |
31 | #include "AliLog.h" | |
32 | #include "AliMUON2DMap.h" | |
33 | #include "AliMUONCalibParamND.h" | |
34 | #include "AliMUONCalibrationData.h" | |
35 | #include "AliMUONDigitCalibrator.h" | |
36 | #include "AliMUONRawStreamTrackerHP.h" | |
37 | #include "AliMUONTrackerData.h" | |
38 | #include "AliMpDDLStore.h" | |
39 | #include "AliRawEventHeaderBase.h" | |
40 | #include "AliRawReader.h" | |
41 | #include "Riostream.h" | |
42 | ||
43 | /// \cond CLASSIMP | |
44 | ClassImp(AliMUONTrackerDataMaker) | |
45 | /// \endcond | |
46 | ||
47 | Int_t AliMUONTrackerDataMaker::fgkCounter(0); | |
48 | ||
49 | //_____________________________________________________________________________ | |
50 | AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(TRootIOCtor*) | |
51 | : | |
52 | AliMUONVTrackerDataMaker(), | |
53 | fRawReader(0x0), | |
54 | fAccumulatedData(0x0), | |
55 | fOneEventData(0x0), | |
56 | fDigitCalibrator(0x0), | |
57 | fCalibrationData(0x0), | |
58 | fSource(""), | |
59 | fOCDBPath(""), | |
60 | fNumberOfEvents(0), | |
61 | fRunNumber(0), | |
62 | fIsRunning(kFALSE), | |
63 | fIsOwnerOfRawReader(kFALSE), | |
64 | fIsEventByEvent(kFALSE) | |
65 | { | |
cddcc1f3 | 66 | /// Root IO ctor |
b6f591ae | 67 | } |
68 | ||
69 | //_____________________________________________________________________________ | |
70 | AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam, | |
71 | Int_t runNumber, | |
72 | AliRawReader* rawReader, | |
73 | const char* cdbPath, | |
74 | const char* calibMode, | |
75 | Bool_t histogram, | |
76 | Double_t xmin, | |
77 | Double_t xmax) | |
78 | : | |
79 | AliMUONVTrackerDataMaker(), | |
80 | fRawReader(rawReader), | |
81 | fAccumulatedData(0x0), | |
82 | fOneEventData(new AliMUON2DMap(true)), | |
83 | fDigitCalibrator(0x0), | |
84 | fCalibrationData(0x0), | |
85 | fSource(""), | |
86 | fOCDBPath(cdbPath), | |
87 | fNumberOfEvents(0), | |
88 | fRunNumber(runNumber), | |
89 | fIsRunning(kFALSE), | |
90 | fIsOwnerOfRawReader(kFALSE), | |
91 | fIsEventByEvent(kFALSE) | |
92 | { | |
93 | /// Ctor in which this object will NOT be the owner of the reader | |
94 | /// and can NOT apply rewind to it, nor use Next on it. | |
95 | Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax); | |
96 | } | |
97 | ||
98 | ||
99 | //_____________________________________________________________________________ | |
100 | AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam, | |
101 | AliRawReader* rawReader, | |
102 | const char* cdbPath, | |
103 | const char* calibMode, | |
104 | Bool_t histogram, | |
105 | Double_t xmin, | |
106 | Double_t xmax) | |
107 | : | |
108 | AliMUONVTrackerDataMaker(), | |
109 | fRawReader(rawReader), | |
110 | fAccumulatedData(0x0), | |
111 | fOneEventData(new AliMUON2DMap(true)), | |
112 | fDigitCalibrator(0x0), | |
113 | fCalibrationData(0x0), | |
114 | fSource(""), | |
115 | fOCDBPath(cdbPath), | |
116 | fNumberOfEvents(0), | |
117 | fRunNumber(0), | |
118 | fIsRunning(kFALSE), | |
119 | fIsOwnerOfRawReader(kTRUE), | |
120 | fIsEventByEvent(kFALSE) | |
121 | { | |
122 | /// Ctor in which we take the ownership of the rawReader, so we can rewind | |
123 | /// and advance it as we wish | |
124 | ||
125 | if (fRawReader) | |
126 | { | |
127 | fRawReader->NextEvent(); // to be sure to get run number available | |
128 | fRunNumber = fRawReader->GetRunNumber(); | |
129 | fRawReader->RewindEvents(); | |
130 | } | |
131 | ||
132 | Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax); | |
133 | } | |
134 | ||
135 | //_____________________________________________________________________________ | |
136 | AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram) | |
137 | : | |
138 | AliMUONVTrackerDataMaker(), | |
139 | fRawReader(rawReader), | |
140 | fAccumulatedData(0x0), | |
141 | fOneEventData(new AliMUON2DMap(true)), | |
142 | fDigitCalibrator(0x0), | |
143 | fCalibrationData(0x0), | |
144 | fSource(""), | |
145 | fOCDBPath(""), | |
146 | fNumberOfEvents(0), | |
147 | fRunNumber(0), | |
148 | fIsRunning(kFALSE), | |
149 | fIsOwnerOfRawReader(kTRUE), | |
150 | fIsEventByEvent(kFALSE) | |
151 | { | |
152 | if (fRawReader) | |
153 | { | |
154 | fRawReader->NextEvent(); // to be sure to get run number available | |
155 | fRunNumber = fRawReader->GetRunNumber(); | |
156 | fRawReader->RewindEvents(); | |
157 | } | |
158 | ||
159 | Ctor(0x0,fRunNumber,"",histogram); | |
160 | ||
161 | } | |
162 | ||
163 | //_____________________________________________________________________________ | |
164 | void | |
165 | AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam, | |
166 | Int_t runNumber, | |
167 | const char* calibMode, | |
168 | Bool_t histogram, | |
169 | Double_t xmin, Double_t xmax) | |
170 | { | |
171 | /// "designated constructor" | |
172 | Bool_t calibrate = ( fOCDBPath.Length() > 0 ); | |
173 | ||
174 | TString name; | |
175 | TString type("RAW"); | |
176 | ||
177 | if ( calibrate ) | |
178 | { | |
179 | TString scalib(calibMode); | |
180 | scalib.ToUpper(); | |
181 | if ( scalib == "GAIN" ) type = "CALC"; | |
182 | if ( scalib == "NOGAIN" ) type = "CALZ"; | |
183 | if ( scalib == "GAINCONSTANTCAPA") type = "CALG"; | |
66cdf5b3 | 184 | if ( scalib == "INJECTIONGAIN" ) type = "CALE"; |
b6f591ae | 185 | } |
186 | ||
187 | if ( !fRunNumber ) | |
188 | { | |
189 | ++fgkCounter; | |
190 | name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter); | |
191 | } | |
192 | else | |
193 | { | |
194 | name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber); | |
195 | } | |
196 | ||
197 | fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1); | |
198 | fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge")); | |
199 | if (histogram) | |
200 | { | |
201 | fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax); | |
202 | } | |
203 | ||
204 | if ( calibrate ) | |
205 | { | |
206 | fCalibrationData = new AliMUONCalibrationData(runNumber); | |
207 | ||
208 | // force the reading of calibration NOW | |
209 | // FIXME: not really elegant and error prone (as we have the list of calib data twice, | |
210 | // once here and once in the digitcalibrator class, hence the change of them getting | |
211 | // out of sync) | |
212 | // But with the current CDBManager implementation, I don't know how to solve | |
213 | // this better (e.g. to avoid clearing cache messages and so on). | |
214 | ||
215 | AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage(); | |
216 | ||
217 | if ( storage->GetURI() != fOCDBPath.Data() ) | |
218 | { | |
219 | AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data()); | |
220 | } | |
221 | ||
222 | fCalibrationData->Pedestals(); | |
223 | fCalibrationData->Gains(); | |
224 | fCalibrationData->Neighbours(); | |
225 | fCalibrationData->HV(); | |
226 | fCalibrationData->Capacitances(); | |
227 | ||
228 | if ( storage->GetURI() != fOCDBPath.Data() ) | |
229 | { | |
230 | AliCDBManager::Instance()->SetDefaultStorage(storage); | |
231 | } | |
232 | ||
233 | fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode); | |
234 | //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ? | |
235 | } | |
236 | } | |
237 | ||
238 | //_____________________________________________________________________________ | |
239 | AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker() | |
240 | { | |
cddcc1f3 | 241 | /// dtor |
242 | ||
b6f591ae | 243 | delete fOneEventData; |
244 | delete fAccumulatedData; | |
245 | if ( fIsOwnerOfRawReader ) delete fRawReader; | |
246 | delete fCalibrationData; | |
247 | delete fDigitCalibrator; | |
248 | } | |
249 | ||
250 | //_____________________________________________________________________________ | |
251 | Bool_t | |
252 | AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other) | |
253 | { | |
254 | /// Adds other to this | |
255 | ||
256 | if (!fAccumulatedData) return kFALSE; | |
257 | ||
258 | if ( fIsEventByEvent ) | |
259 | { | |
260 | AliError("Cannot add event by event objects !"); | |
261 | return kFALSE; | |
262 | } | |
263 | ||
264 | if ( fRunNumber != other.fRunNumber ) fRunNumber = -1; | |
265 | ||
266 | fSource += "\n"; | |
267 | fSource += other.fSource; | |
268 | ||
269 | fNumberOfEvents += other.fNumberOfEvents; | |
270 | ||
271 | TList list; | |
272 | list.Add(other.fAccumulatedData); | |
273 | ||
274 | fAccumulatedData->Merge(&list); | |
275 | ||
276 | return kTRUE; | |
277 | } | |
278 | ||
279 | //_____________________________________________________________________________ | |
280 | Bool_t | |
281 | AliMUONTrackerDataMaker::NextEvent() | |
282 | { | |
283 | /// Read and process next event | |
284 | ||
285 | if ( !fIsOwnerOfRawReader ) | |
286 | { | |
287 | AliError("I'm not the owner of the raw reader. Cannot use NextEvent"); | |
288 | return kFALSE; | |
289 | } | |
290 | ||
291 | AliCodeTimerAuto(""); | |
292 | ||
293 | static Int_t nphysics(0); | |
294 | static Int_t ngood(0); | |
295 | ||
296 | if ( !IsRunning() ) return kTRUE; | |
297 | ||
298 | Bool_t ok = fRawReader->NextEvent(); | |
299 | ||
300 | if (!ok) | |
301 | { | |
302 | return kFALSE; | |
303 | } | |
304 | ||
305 | Int_t eventType = fRawReader->GetType(); | |
306 | ||
307 | ++fNumberOfEvents; | |
308 | ||
309 | if (eventType != AliRawEventHeaderBase::kPhysicsEvent ) | |
310 | { | |
311 | return kTRUE; // for the moment | |
312 | } | |
313 | ||
314 | ++nphysics; | |
315 | ||
316 | Bool_t pok = ProcessEvent(); | |
317 | ||
318 | if ( pok ) ++ngood; | |
319 | ||
320 | AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood)); | |
321 | ||
322 | return kTRUE; | |
323 | } | |
324 | ||
325 | //_____________________________________________________________________________ | |
326 | Bool_t AliMUONTrackerDataMaker::ProcessEvent() | |
327 | { | |
328 | /// Process current event | |
329 | /// | |
330 | /// Note that in case of calibration, we do not simply reuse the | |
331 | /// AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&) method, | |
332 | /// as this would require filling first a digitStore, and then calibrate it, | |
333 | /// and then convert it into a VStore, all this taking too much time. | |
334 | /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to | |
335 | /// duplicate this critical piece of calibration code ! | |
336 | /// | |
337 | ||
338 | AliCodeTimerAuto(""); | |
339 | ||
340 | AliMUONRawStreamTrackerHP stream(fRawReader); | |
341 | ||
342 | stream.DisableWarnings(); | |
343 | // stream.EnabbleErrorLogger(); | |
344 | ||
345 | const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK"); | |
346 | TArrayI nevents(nddls); | |
347 | ||
348 | for ( Int_t i = 0; i < nddls; ++i ) | |
349 | { | |
350 | nevents[i] = 0; | |
351 | } | |
352 | ||
353 | fOneEventData->Clear(); | |
354 | ||
355 | Int_t buspatchId; | |
356 | UShort_t manuId; | |
357 | UChar_t manuChannel; | |
358 | UShort_t adc; | |
359 | ||
360 | stream.First(); | |
361 | ||
362 | while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) ) | |
363 | { | |
364 | Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId); | |
365 | ||
366 | Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId); | |
367 | ||
368 | nevents[ddl] = 1; | |
369 | ||
370 | AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId)); | |
371 | if (!param) | |
372 | { | |
373 | param = new AliMUONCalibParamND(1,64,detElemId,manuId, | |
374 | AliMUONVCalibParam::InvalidFloatValue()); | |
375 | fOneEventData->Add(param); | |
376 | } | |
377 | ||
378 | Double_t charge(adc); | |
379 | ||
380 | if ( fDigitCalibrator ) | |
381 | { | |
382 | if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) ) | |
383 | { | |
384 | charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc,3.0); | |
385 | } | |
2b8a1212 | 386 | else |
387 | { | |
388 | charge = 0.0; | |
389 | } | |
b6f591ae | 390 | } |
391 | ||
392 | if (charge > 0.0 ) | |
393 | { | |
394 | param->SetValueAsDouble(manuChannel,0,charge); | |
395 | } | |
396 | } | |
397 | ||
398 | Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError(); | |
399 | ||
400 | if (!badEvent) | |
401 | { | |
402 | fAccumulatedData->Add(*fOneEventData,&nevents); | |
403 | } | |
404 | ||
405 | return !badEvent; | |
406 | } | |
407 | ||
408 | ||
409 | //_____________________________________________________________________________ | |
410 | void | |
411 | AliMUONTrackerDataMaker::Print(Option_t*) const | |
412 | { | |
413 | /// Printout | |
414 | ||
415 | cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO") | |
416 | << endl; | |
417 | } | |
418 | ||
419 | //_____________________________________________________________________________ | |
420 | void AliMUONTrackerDataMaker::Rewind() | |
421 | { | |
422 | /// Rewind events | |
423 | if ( fIsOwnerOfRawReader ) | |
424 | { | |
425 | fRawReader->RewindEvents(); | |
426 | fNumberOfEvents=0; | |
427 | } | |
428 | else | |
429 | { | |
430 | AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !"); | |
431 | } | |
432 | } | |
433 | ||
434 | //_____________________________________________________________________________ | |
435 | Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list) | |
436 | { | |
437 | /// Merge objects in collection | |
438 | ||
439 | if (!list) return 0; | |
440 | ||
441 | if ( list->IsEmpty() ) return NumberOfEvents(); | |
442 | ||
443 | TIter next(list); | |
444 | const TObject* o(0x0); | |
445 | ||
446 | while ( ( o = next() ) ) | |
447 | { | |
448 | const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o); | |
449 | if (!o) | |
450 | { | |
451 | AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it", | |
452 | o->GetName())); | |
453 | } | |
454 | else | |
455 | { | |
456 | Bool_t ok = Add(*data); | |
457 | if (!ok) | |
458 | { | |
459 | AliError("Got incompatible objects"); | |
460 | } | |
461 | } | |
462 | } | |
463 | ||
464 | return NumberOfEvents(); | |
465 | } | |
466 | ||
467 | //_____________________________________________________________________________ | |
468 | void | |
469 | AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader) | |
470 | { | |
471 | /// Change the rawreader (only works if isowner=true) | |
472 | ||
473 | if ( fIsOwnerOfRawReader ) | |
474 | { | |
475 | AliFatal("Improper use of this class ! Cannot change raw reader in this case"); | |
476 | } | |
477 | ||
478 | fRawReader = rawReader; | |
479 | ||
480 | } |