1 /**************************************************************************
2 * Copyright(c) 2004, 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 **************************************************************************/
16 /** @file AliFMDPreprocessor.cxx
17 @author Hans Hjersing Dalsgaard <canute@nbi.dk>
18 @date Mon Mar 27 12:39:09 2006
19 @brief Shuttle "preprocessor" for the FMD
21 //___________________________________________________________________
23 // The class processes data points from DCS (via Amanada), and DAQ DA
24 // files (via FXS) to make calibration data for the FMD.
30 // * pedestals - a (ASCII) Comma Separated Values files with the
33 // board FEC board number
34 // chip ALTRO chip number on FEC
35 // channel ALTRO channel number
36 // strip VA1 strip number
37 // sample Sample number
38 // ped Mean of ADC spectra
39 // noise Spread of ADC spectra
40 // mu Mean of Gaussian fit to ADC spectra
41 // sigma Variance of Gaussian fit to ADC spectra
42 // chi2 Chi^2 per degrees of freedom of fit
43 // * Gains - a (ASCII) Comma Separated Values files with the
46 // board FEC board number
47 // chip ALTRO chip number on FEC
48 // channel ALTRO channel number
49 // strip VA1 strip number
51 // error Error on gain
52 // chi2 Chi^2 per degrees of freedom of fit
56 // http://aliceinfo.cern.ch/Offline/Activities/Shuttle.html
58 // Latest changes by Christian Holm Christensen
64 #include "AliFMDPreprocessor.h"
65 #include "AliFMDCalibPedestal.h"
66 #include "AliFMDCalibGain.h"
67 #include "AliFMDCalibStripRange.h"
68 #include "AliFMDCalibSampleRate.h"
69 #include "AliFMDParameters.h"
70 #include "AliCDBMetaData.h"
71 #include "AliCDBManager.h"
72 // #include "AliDCSValue.h"
74 #include <TTimeStamp.h>
76 #include <TObjString.h>
81 ClassImp(AliFMDPreprocessor)
82 #if 0 // Do not remove - here to make Emacs happy
87 //____________________________________________________
88 AliFMDPreprocessor::AliFMDPreprocessor(AliShuttleInterface* shuttle)
89 : AliPreprocessor("FMD", shuttle)
91 AddRunType("PHYSICS");
92 AddRunType("STANDALONE");
93 AddRunType("PEDESTAL");
98 //____________________________________________________
99 Bool_t AliFMDPreprocessor::GetAndCheckFileSources(TList*& list,
103 // Convinience function
105 // list On return, list of files.
106 // system Alice system (DAQ, DCS, ...)
110 list = GetFileSources(system, id);
114 case kDAQ: sys = "DAQ"; break;
115 case kDCS: sys = "DCS"; break;
116 default: sys = "unknown"; break;
118 Log(Form("Failed to get file sources for %s/%d", sys.Data(), system));
124 //____________________________________________________
126 AliFMDPreprocessor::GetFromCDB(const char* second, const char* third)
128 return GetFromOCDB(second, third);
132 //____________________________________________________
133 UInt_t AliFMDPreprocessor::Process(TMap* /* dcsAliasMap */)
135 // Main member function.
137 // dcsAliassMap Map of DCS data point aliases.
139 // 0 on success, >0 otherwise
140 Bool_t resultPed = kTRUE;
141 Bool_t resultGain = kTRUE;
142 Bool_t resultRange = kTRUE;
143 Bool_t resultRate = kTRUE;
144 Bool_t resultZero = kTRUE;
145 Bool_t infoCalib = kTRUE;
146 Bool_t resultDead = kTRUE;
148 // if(!dcsAliasMap) return 1;
150 // Invoking the cdb manager and the FMD parameters class
151 // AliCDBManager* cdb = AliCDBManager::Instance();
152 // cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
156 TString runType(GetRunType());
158 AliFMDParameters* pars = AliFMDParameters::Instance();
159 if(runType.Contains("PEDESTAL", TString::kIgnoreCase))
160 pars->Init(this, false, AliFMDParameters::kAltroMap|AliFMDParameters::kPulseGain);
161 else if(runType.Contains("GAIN", TString::kIgnoreCase))
162 pars->Init(this, false, AliFMDParameters::kAltroMap|AliFMDParameters::kPedestal);
164 pars->Init(this, false, AliFMDParameters::kAltroMap);
166 // This is if the SOR contains Fee parameters, and we run a DA to
167 // extract these parameters. The same code could work if we get
168 // the information from DCS via the FXS
170 AliFMDCalibSampleRate* calibRate = 0;
171 AliFMDCalibStripRange* calibRange = 0;
172 AliFMDCalibZeroSuppression* calibZero = 0;
174 if (GetAndCheckFileSources(files, kDAQ,pars->GetConditionsShuttleID()))
175 infoCalib = GetInfoCalibration(files, calibRate, calibRange, calibZero);
177 resultRate = (!calibRate ? kFALSE : kTRUE);
178 resultRange = (!calibRange ? kFALSE : kTRUE);
179 resultZero = (!calibZero ? kFALSE : kTRUE);
183 //Creating calibration objects
184 AliFMDCalibPedestal* calibPed = 0;
185 AliFMDCalibGain* calibGain = 0;
186 AliFMDCalibDeadMap* calibDead = 0;
187 if (runType.Contains("PEDESTAL", TString::kIgnoreCase)) {
188 if (GetAndCheckFileSources(files, kDAQ, pars->GetPedestalShuttleID())) {
190 calibPed = GetPedestalCalibration(files);
192 resultPed = (calibPed ? kTRUE : kFALSE);
194 if (runType.Contains("GAIN", TString::kIgnoreCase)) {
195 if (GetAndCheckFileSources(files, kDAQ, pars->GetGainShuttleID())) {
197 calibGain = GetGainCalibration(files);
199 resultGain = (calibGain ? kTRUE : kFALSE);
201 if(runType.Contains("PEDESTAL", TString::kIgnoreCase) || runType.Contains("GAIN", TString::kIgnoreCase))
202 calibDead = GetDeadChannelMap(calibPed,calibGain);
204 //Storing Calibration objects
205 AliCDBMetaData metaData;
206 metaData.SetBeamPeriod(0);
207 metaData.SetResponsible("Hans H. Dalsgaard");
208 metaData.SetComment("Preprocessor stores pedestals and gains for the FMD.");
211 resultPed = Store("Calib","Pedestal", calibPed, &metaData, 0, kTRUE);
215 resultGain = Store("Calib","PulseGain", calibGain, &metaData, 0, kTRUE);
219 resultRange = Store("Calib","StripRange", calibRange, &metaData, 0, kTRUE);
223 resultRate = Store("Calib","SampleRate", calibRate, &metaData, 0, kTRUE);
227 resultZero = Store("Calib","ZeroSuppression", calibZero,&metaData,0,kTRUE);
231 resultDead = Store("Calib","Dead", calibDead,&metaData,0,kTRUE);
235 Bool_t success = (resultPed && resultGain && resultRange &&
236 resultRate && resultZero && resultDead && infoCalib);
238 Log(Form("FMD preprocessor was %s", (success ? "successful" : "failed")));
239 return (success ? 0 : 1);
242 //____________________________________________________________________
244 AliFMDPreprocessor::GetInfoCalibration(TList* files,
245 AliFMDCalibSampleRate*& s,
246 AliFMDCalibStripRange*& r,
247 AliFMDCalibZeroSuppression*& z)
249 // Get info calibrations.
251 // files List of files.
252 // s On return, newly allocated object
253 // r On return, newly allocated object
254 // z On return, newly allocated object
257 if (!files) return kFALSE; // Should really be false
258 if (files->GetEntries() <= 0) return kFALSE;
260 s = new AliFMDCalibSampleRate();
261 r = new AliFMDCalibStripRange();
262 z = new AliFMDCalibZeroSuppression();
264 AliFMDParameters* pars = AliFMDParameters::Instance();
266 TObjString* fileSource;
268 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
269 const Char_t* filename = GetFile(kDAQ, pars->GetConditionsShuttleID(), fileSource->GetName());
270 std::ifstream in(filename);
272 Log(Form("File %s not found!", filename));
282 //____________________________________________________________________
284 AliFMDPreprocessor::GetPedestalCalibration(const TList* pedFiles)
286 // Read DAQ DA produced CSV files of pedestals, and return a
287 // calibration object.
289 // pedFiles List of pedestal files
291 // A pointer to a newly allocated AliFMDCalibPedestal object, or
292 // null in case of errors.
293 if(!pedFiles) return 0;
295 AliFMDCalibPedestal* calibPed = new AliFMDCalibPedestal();
296 AliFMDParameters* pars = AliFMDParameters::Instance();
297 TIter iter(pedFiles);
298 TObjString* fileSource;
300 while((fileSource = dynamic_cast<TObjString*>(iter.Next()))) {
301 const Char_t* filename = GetFile(kDAQ, pars->GetPedestalShuttleID(),
302 fileSource->GetName());
303 std::ifstream in(filename);
305 Log(Form("File %s not found!", filename));
311 while((cc = in.peek())!=EOF) {
313 Log(Form("Bad read at line %d in %s", lineno, filename));
322 if(!line.Contains(pars->GetPedestalShuttleID())) {
323 Log(Form("File header is not from pedestal!: %s", line.Data()));
326 Log("File contains data from pedestals");
330 UShort_t det, sec, strip;
332 Float_t ped, noise, mu, sigma, chi2ndf;
346 // Ignore trailing garbage
347 // if (strip > 127) continue;
349 //Setting DDL to comply with the FMD in DAQ
350 // UInt_t FmdDDLBase = 3072;
351 // ddl = ddl - FmdDDLBase;
352 //Setting the pedestals via the hardware address
355 // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
358 calibPed->Set(det,ring,sec,strip,ped,noise);
365 //____________________________________________________________________
367 AliFMDPreprocessor::GetGainCalibration(const TList* gainFiles)
369 // Read DAQ DA produced CSV files of pedestals, and return a
370 // calibration object.
372 // pedFiles List of pedestal files
374 // A pointer to a newly allocated AliFMDCalibPedestal object, or
375 // null in case of errors.
376 if(!gainFiles) return 0;
378 AliFMDCalibGain* calibGain = new AliFMDCalibGain();
379 AliFMDParameters* pars = AliFMDParameters::Instance();
380 TIter iter(gainFiles);
381 TObjString* fileSource;
382 while((fileSource = dynamic_cast<TObjString *>(iter.Next()))) {
383 const Char_t* filename = GetFile(kDAQ, pars->GetGainShuttleID(),
384 fileSource->GetName());
385 std::ifstream in(filename);
387 Log(Form("File %s not found!", filename));
393 while((cc = in.peek())!=EOF) {
395 Log(Form("Bad read at line %d in %s", lineno, filename));
404 if(!line.Contains(pars->GetGainShuttleID())) {
405 Log(Form("File header is not from gains!: %s", line.Data()));
408 Log("File contains data from gains");
412 UShort_t det, sec, strip;
415 Float_t gain,error, chi2ndf;
426 // Ignore trailing garbage
427 //if(strip > 127) continue;
429 //Setting DDL to comply with the FMD in DAQ
430 // UInt_t FmdDDLBase = 3072;
431 // ddl = ddl - FmdDDLBase;
432 //Setting the pedestals via the hardware address
433 // pars->Hardware2Detector(ddl,board,chip,channel,det,ring,sec,str);
436 calibGain->Set(det,ring,sec,strip,gain);
441 //____________________________________________________________________
443 AliFMDPreprocessor::GetDeadChannelMap(AliFMDCalibPedestal* pedcalib,
444 AliFMDCalibGain* gaincalib) {
445 //creating dead channel map. '0' means 51200 entries
446 AliFMDCalibDeadMap* deadmap = new AliFMDCalibDeadMap(0);
447 //deadmap->Reset(kTRUE);
451 AliFMDParameters* pars = AliFMDParameters::Instance();
452 //Looping over the channels.
453 for(UShort_t det=1;det<=3;det++) {
454 Int_t nRings = (det==1 ? 1 : 2);
455 for (UShort_t ir = 0; ir < nRings; ir++) {
456 Char_t ring = (ir == 0 ? 'I' : 'O');
457 UShort_t nsec = (ir == 0 ? 20 : 40);
458 UShort_t nstr = (ir == 0 ? 512 : 256);
460 for(UShort_t sec =0; sec < nsec; sec++) {
462 for(UShort_t strip = 0; strip < nstr; strip++) {
464 Bool_t isDead = kFALSE;
466 noise = pedcalib->Width(det, ring, sec, strip);
468 noise = pars->GetPedestalWidth(det, ring, sec, strip);
471 gain = gaincalib->Value(det, ring, sec, strip);
473 gain = pars->GetPulseGain(det, ring, sec, strip);
475 //marking these channels dead.
476 if (gain < 0.5 || gain > 5 || noise > 10 || noise == 0) isDead = kTRUE;
478 deadmap->operator()(det, ring, sec, strip) = isDead;
486 //____________________________________________________________________