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 #include "AliMUONTrackerCalibratedDataMaker.h"
20 #include "AliMUON2DMap.h"
21 #include "AliMUONCalibParamND.h"
22 #include "AliMUONCalibrationData.h"
23 #include "AliMUONDigitCalibrator.h"
24 #include "AliMUONDigitMaker.h"
25 #include "AliMUONDigitStoreV2R.h"
26 #include "AliMUONTrackerData.h"
27 #include "AliMUONVDigit.h"
28 #include "AliMUONVDigitStore.h"
29 #include "AliMpDDLStore.h"
30 #include "AliCodeTimer.h"
31 #include "AliCDBManager.h"
32 #include "AliCDBStorage.h"
33 #include "AliRawEventHeaderBase.h"
34 #include "AliRawReader.h"
36 #include <Riostream.h>
38 ///\class AliMUONTrackerCalibratedDataMaker
40 /// Creator of AliMUONVTrackerData from AliRawReader
42 ///\author Laurent Aphecetche, Subatech
45 ClassImp(AliMUONTrackerCalibratedDataMaker)
48 Int_t AliMUONTrackerCalibratedDataMaker::fgkCounter(0);
50 //_____________________________________________________________________________
51 AliMUONTrackerCalibratedDataMaker::AliMUONTrackerCalibratedDataMaker(AliRawReader* reader,
53 const char* calibMode,
57 : AliMUONVTrackerDataMaker(),
59 fAccumulatedData(0x0),
60 fOneEventData(new AliMUON2DMap(true)),
62 fSource("unspecified"),
65 fDigitCalibrator(0x0),
66 fCalibrationData(0x0),
71 reader->NextEvent(); // to be sure to get run number available
73 Int_t runNumber = reader->GetRunNumber();
77 Bool_t calibrate = ( fCDBPath.Length() > 0 );
79 TString basename("RAW");
83 TString scalib(calibMode);
85 if ( scalib == "GAIN" ) basename = "CALC";
86 if ( scalib == "NOGAIN" ) basename = "CALZ";
87 if ( scalib == "GAINCONSTANTCAPA" ) basename = "CALG";
92 name = Form("%s%s(%d)",
93 (histogram ? "H" : ""),
100 (histogram ? "H" : ""),
105 fAccumulatedData = new AliMUONTrackerData(name.Data(),"charge values",1);
106 fAccumulatedData->SetDimensionName(0,(calibrate ? "Calibrated charge" : "Raw charge"));
109 fAccumulatedData->MakeHistogramForDimension(0,kTRUE,xmin,xmax);
110 AliInfo(Form("Will histogram between %e and %e",xmin,xmax));
113 reader->RewindEvents();
115 fDigitMaker = new AliMUONDigitMaker;
116 fDigitMaker->SetMakeTriggerDigits(kFALSE);
117 fDigitStore = new AliMUONDigitStoreV2R;
121 fCalibrationData = new AliMUONCalibrationData(runNumber);
123 // force the reading of calibration NOW
124 // FIXME: not really elegant and error prone (as we have the list of calib data twice,
125 // once here and once in the digitcalibrator class, hence the change of them getting
127 // But with the current CDBManager implementation, I don't know how to solve
128 // this better (e.g. to avoid clearing cache messages and so on).
130 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
132 if ( storage->GetURI() != fCDBPath.Data() )
134 AliCDBManager::Instance()->SetDefaultStorage(fCDBPath.Data());
137 fCalibrationData->Pedestals();
138 fCalibrationData->Gains();
139 fCalibrationData->Neighbours();
140 fCalibrationData->HV();
141 fCalibrationData->Capacitances();
143 if ( storage->GetURI() != fCDBPath.Data() )
145 AliCDBManager::Instance()->SetDefaultStorage(storage);
148 fDigitCalibrator = new AliMUONDigitCalibrator(*fCalibrationData,calibMode);
152 //_____________________________________________________________________________
153 AliMUONTrackerCalibratedDataMaker::~AliMUONTrackerCalibratedDataMaker()
156 delete fOneEventData;
157 if ( fIsOwner ) delete fAccumulatedData;
160 delete fCalibrationData;
162 delete fDigitCalibrator;
165 //_____________________________________________________________________________
167 AliMUONTrackerCalibratedDataMaker::NextEvent()
171 AliCodeTimerAuto("");
173 static Int_t nphysics(0);
174 static Int_t ngood(0);
176 if ( !IsRunning() ) return kTRUE;
178 Bool_t ok = fRawReader->NextEvent();
182 fDigitMaker->Print();
186 Int_t eventType = fRawReader->GetType();
190 if (eventType != AliRawEventHeaderBase::kPhysicsEvent )
192 return kTRUE; // for the moment
197 Int_t rv = fDigitMaker->Raw2Digits(fRawReader,fDigitStore);
199 if ( ( rv & AliMUONDigitMaker::kTrackerBAD ) != 0 ) return kTRUE;
201 if ( fDigitCalibrator )
203 fDigitCalibrator->Calibrate(*fDigitStore);
206 Bool_t dok = ConvertDigits();
211 fAccumulatedData->Add(*fOneEventData);
214 AliDebug(1,Form("n %10d nphysics %10d ngood %10d",fNumberOfEvents,nphysics,ngood));
219 //_____________________________________________________________________________
221 AliMUONTrackerCalibratedDataMaker::ConvertDigits()
223 /// Convert digitstore into fOneEventData
225 AliCodeTimerAuto("");
227 TIter next(fDigitStore->CreateIterator());
228 AliMUONVDigit* digit;
230 fOneEventData->Clear();
232 while ( ( digit = static_cast<AliMUONVDigit*>(next())) )
234 Double_t value = ( digit->IsCalibrated() ? digit->Charge() : digit->ADC() );
238 Int_t detElemId = digit->DetElemId();
239 Int_t manuId = digit->ManuId();
241 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(fOneEventData->FindObject(detElemId,manuId));
244 param = new AliMUONCalibParamND(1,64,detElemId,manuId,
245 AliMUONVCalibParam::InvalidFloatValue());
246 fOneEventData->Add(param);
249 param->SetValueAsDouble(digit->ManuChannel(),0,value);
256 //_____________________________________________________________________________
258 AliMUONTrackerCalibratedDataMaker::Print(Option_t*) const
262 cout << "Source=" << Source() << " Running=" << ( IsRunning() ? "YES" : "NO")
267 //_____________________________________________________________________________
269 AliMUONTrackerCalibratedDataMaker::Rewind()
272 fRawReader->RewindEvents();