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