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