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 /// \class AliMUONTrackerDataMaker
20 /// Implementation of VTrackerDataMaker to read raw data and
21 /// calibrate it (if required)
23 /// \author Laurent Aphecetche, Subatech
25 #include "AliMUONTrackerDataMaker.h"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
29 #include "AliCodeTimer.h"
32 #include "AliMUON2DMap.h"
33 #include "AliMUONCalibParamND.h"
34 #include "AliMUONCalibrationData.h"
35 #include "AliMUONDigitCalibrator.h"
36 #include "AliMUONLogger.h"
37 #include "AliMUONRawStreamTrackerHP.h"
38 #include "AliMUONTrackerData.h"
39 #include "AliMpDDLStore.h"
40 #include "AliRawEventHeaderBase.h"
41 #include "AliRawReader.h"
42 #include "Riostream.h"
45 ClassImp(AliMUONTrackerDataMaker)
48 Int_t AliMUONTrackerDataMaker::fgkCounter(0);
50 //_____________________________________________________________________________
51 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(TRootIOCtor*)
53 AliMUONVTrackerDataMaker(),
55 fAccumulatedData(0x0),
56 fIsOwnerOfAccumulatedData(kTRUE),
58 fDigitCalibrator(0x0),
59 fCalibrationData(0x0),
65 fIsOwnerOfRawReader(kFALSE),
66 fIsEventByEvent(kFALSE),
68 fLastEventWasEmpty(kFALSE),
69 fNumberOfPhysicsEvents(0),
70 fNumberOfGoodPhysicsEvents(0),
78 //_____________________________________________________________________________
79 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
81 AliRawReader* rawReader,
83 const char* calibMode,
88 AliMUONVTrackerDataMaker(),
89 fRawReader(rawReader),
90 fAccumulatedData(0x0),
91 fIsOwnerOfAccumulatedData(kTRUE),
92 fOneEventData(new AliMUON2DMap(true)),
93 fDigitCalibrator(0x0),
94 fCalibrationData(0x0),
98 fRunNumber(runNumber),
100 fIsOwnerOfRawReader(kFALSE),
101 fIsEventByEvent(kFALSE),
103 fLastEventWasEmpty(kFALSE),
104 fNumberOfPhysicsEvents(0),
105 fNumberOfGoodPhysicsEvents(0),
110 /// Ctor in which this object will NOT be the owner of the reader
111 /// and can NOT apply rewind to it, nor use Next on it.
112 Ctor(recoParam,runNumber,calibMode,histogram,xmin,xmax);
116 //_____________________________________________________________________________
117 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(const AliMUONRecoParam* recoParam,
118 AliRawReader* rawReader,
120 const char* calibMode,
125 AliMUONVTrackerDataMaker(),
126 fRawReader(rawReader),
127 fAccumulatedData(0x0),
128 fIsOwnerOfAccumulatedData(kTRUE),
129 fOneEventData(new AliMUON2DMap(true)),
130 fDigitCalibrator(0x0),
131 fCalibrationData(0x0),
137 fIsOwnerOfRawReader(kTRUE),
138 fIsEventByEvent(kFALSE),
140 fLastEventWasEmpty(kFALSE),
141 fNumberOfPhysicsEvents(0),
142 fNumberOfGoodPhysicsEvents(0),
147 /// Ctor in which we take the ownership of the rawReader, so we can rewind
148 /// and advance it as we wish
152 fRawReader->NextEvent(); // to be sure to get run number available
153 fRunNumber = fRawReader->GetRunNumber();
154 fRawReader->RewindEvents();
157 Ctor(recoParam,fRunNumber,calibMode,histogram,xmin,xmax);
160 //_____________________________________________________________________________
161 AliMUONTrackerDataMaker::AliMUONTrackerDataMaker(AliRawReader* rawReader, Bool_t histogram)
163 AliMUONVTrackerDataMaker(),
164 fRawReader(rawReader),
165 fAccumulatedData(0x0),
166 fIsOwnerOfAccumulatedData(kTRUE),
167 fOneEventData(new AliMUON2DMap(true)),
168 fDigitCalibrator(0x0),
169 fCalibrationData(0x0),
175 fIsOwnerOfRawReader(kTRUE),
176 fIsEventByEvent(kFALSE),
178 fLastEventWasEmpty(kFALSE),
179 fNumberOfPhysicsEvents(0),
180 fNumberOfGoodPhysicsEvents(0),
185 /// Ctor from raw data reader
188 fRawReader->NextEvent(); // to be sure to get run number available
189 fRunNumber = fRawReader->GetRunNumber();
190 fRawReader->RewindEvents();
193 Ctor(0x0,fRunNumber,"",histogram);
197 //_____________________________________________________________________________
199 AliMUONTrackerDataMaker::Ctor(const AliMUONRecoParam* recoParam,
201 const char* calibMode,
203 Double_t xmin, Double_t xmax)
205 /// "designated constructor"
207 Bool_t calibrate = ( strlen(calibMode) > 0 );
214 TString scalib(calibMode);
216 if ( scalib == "GAIN" ) type = "CALC";
217 if ( scalib == "NOGAIN" ) type = "CALZ";
218 if ( scalib == "GAINCONSTANTCAPA") type = "CALG";
219 if ( scalib == "INJECTIONGAIN" ) type = "CALE";
225 name = Form("%s%s_%d",(histogram?"H":""),type.Data(),fgkCounter);
229 name = Form("%s%s%d",(histogram?"H":""),type.Data(),fRunNumber);
232 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
233 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
236 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
241 fCalibrationData = new AliMUONCalibrationData(runNumber);
243 // force the reading of calibration NOW
244 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
245 // once here and once in the digitcalibrator class, hence the change of them getting
247 // But with the current CDBManager implementation, I don't know how to solve
248 // this better (e.g. to avoid clearing cache messages and so on).
250 AliCDBStorage* storage(0x0);
252 if ( fOCDBPath.Length() > 0 )
254 storage = AliCDBManager::Instance()->GetDefaultStorage();
256 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
258 AliCDBManager::Instance()->SetDefaultStorage(fOCDBPath.Data());
262 fCalibrationData->Pedestals();
263 fCalibrationData->Gains();
264 fCalibrationData->Neighbours();
265 fCalibrationData->HV();
266 fCalibrationData->Capacitances();
268 if ( storage && ( storage->GetURI() != fOCDBPath.Data() ) )
270 AliCDBManager::Instance()->SetDefaultStorage(storage);
273 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,recoParam,calibMode);
274 //FIXME: get the reco param from GUI and/or from OCDB if not used from the QA code ?
278 //_____________________________________________________________________________
279 AliMUONTrackerDataMaker::~AliMUONTrackerDataMaker()
283 delete fOneEventData;
284 if ( fIsOwnerOfAccumulatedData ) delete fAccumulatedData;
285 if ( fIsOwnerOfRawReader ) delete fRawReader;
286 delete fCalibrationData;
287 delete fDigitCalibrator;
290 //_____________________________________________________________________________
292 AliMUONTrackerDataMaker::Add(const AliMUONTrackerDataMaker& other)
294 /// Adds other to this
296 if (!fAccumulatedData) return kFALSE;
298 if ( fIsEventByEvent )
300 AliError("Cannot add event by event objects !");
304 if ( fRunNumber != other.fRunNumber ) fRunNumber = -1;
307 fSource += other.fSource;
309 fNumberOfEvents += other.fNumberOfEvents;
310 fNumberOfPhysicsEvents += other.fNumberOfPhysicsEvents;
311 fNumberOfGoodPhysicsEvents += other.fNumberOfGoodPhysicsEvents;
314 list.Add(other.fAccumulatedData);
316 fAccumulatedData->Merge(&list);
321 //_____________________________________________________________________________
323 AliMUONTrackerDataMaker::NextEvent()
325 /// Read and process next event
327 if ( !fIsOwnerOfRawReader )
329 AliError("I'm not the owner of the raw reader. Cannot use NextEvent");
333 AliCodeTimerAuto("",0);
335 if ( !IsRunning() ) return kTRUE;
339 if ( fLastEvent >= fFirstEvent && fLastEvent > 0 ) // do we have an event range to consider ?
341 // skip up to first event
343 while ( (fNumberOfEvents-1) < fFirstEvent && ( ok = fRawReader->NextEvent() ) )
348 if ( ok && (fNumberOfEvents-1) <= fLastEvent )
350 ok = fRawReader->NextEvent();
354 fNumberOfEvents=fLastEvent+1;
360 // no event range, just proceed...
361 ok = fRawReader->NextEvent();
374 //_____________________________________________________________________________
375 Bool_t AliMUONTrackerDataMaker::ProcessEvent()
377 /// Process current event
379 /// Note that in case of calibration, we do not simply reuse the
380 /// AliMUONDigitCalibrator::Calibrate(AliMUONVDigitStore&) method,
381 /// as this would require filling first a digitStore, and then calibrate it,
382 /// and then convert it into a VStore, all this taking too much time.
383 /// But we *do* reuse the AliMUONDigitCalibrator::CalibrateDigit in order not to
384 /// duplicate this critical piece of calibration code !
389 Int_t eventType = fRawReader->GetType();
391 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
393 return kTRUE; // for the moment
396 ++fNumberOfPhysicsEvents;
398 fLastEventWasEmpty = kFALSE;
400 AliCodeTimerAuto("",0);
402 AliMUONRawStreamTrackerHP stream(fRawReader);
404 stream.DisableWarnings();
405 stream.DisableRawReaderErrorLogger();
406 stream.DisableMUONErrorLogger();
410 stream.TryRecover(kTRUE);
414 stream.TryRecover(kFALSE);
419 stream.EnableMUONErrorLogger();
420 stream.SetMUONErrorLogger(fLogger);
421 stream.SetLoggingDetailLevel(AliMUONRawStreamTrackerHP::kMediumErrorDetail);
424 const Int_t nddls = AliDAQ::NumberOfDdls("MUONTRK");
425 TArrayI nevents(nddls);
427 for ( Int_t i = 0; i < nddls; ++i )
432 fOneEventData->Clear();
441 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
443 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(buspatchId);
445 Int_t ddl = AliMpDDLStore::Instance()->GetDDLfromBus(buspatchId);
449 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
452 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
453 AliMUONVCalibParam::InvalidFloatValue());
454 fOneEventData->Add(param);
457 Double_t charge(adc);
459 if ( fDigitCalibrator )
461 if ( fDigitCalibrator->IsValidDigit(detElemId, manuId, manuChannel) )
463 charge = fDigitCalibrator->CalibrateDigit(detElemId, manuId, manuChannel,adc);
473 param->SetValueAsDouble(manuChannel,0,charge);
477 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
481 fAccumulatedData->Add(*fOneEventData,&nevents);
482 if ( fOneEventData->GetSize() == 0 ) fLastEventWasEmpty = kTRUE;
483 ++fNumberOfGoodPhysicsEvents;
486 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,fNumberOfPhysicsEvents,fNumberOfGoodPhysicsEvents));
492 //_____________________________________________________________________________
494 AliMUONTrackerDataMaker::Print(Option_t*) const
498 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
502 //_____________________________________________________________________________
503 void AliMUONTrackerDataMaker::Rewind()
506 if ( fIsOwnerOfRawReader )
508 fRawReader->RewindEvents();
510 fNumberOfPhysicsEvents=0;
511 fNumberOfGoodPhysicsEvents=0;
515 AliError("Wrong usage of this class : cannot rewind as I am not owner of the raw reader !");
519 //_____________________________________________________________________________
520 Long64_t AliMUONTrackerDataMaker::Merge(TCollection* list)
522 /// Merge objects in collection
526 if ( list->IsEmpty() ) return NumberOfEvents();
529 const TObject* o(0x0);
531 while ( ( o = next() ) )
533 const AliMUONTrackerDataMaker* data = dynamic_cast<const AliMUONTrackerDataMaker*>(o);
536 AliError(Form("Object named %s is not an AliMUONTrackerDataMaker ! Skipping it",
541 Bool_t ok = Add(*data);
544 AliError("Got incompatible objects");
549 return NumberOfEvents();
552 //_____________________________________________________________________________
554 AliMUONTrackerDataMaker::SetRawReader(AliRawReader* rawReader)
556 /// Change the rawreader (only works if isowner=true)
558 if ( fIsOwnerOfRawReader )
560 AliFatal("Improper use of this class ! Cannot change raw reader in this case");
563 fRawReader = rawReader;