ATLAS Offline Software
Loading...
Searching...
No Matches
TileInfoLoader.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5//*****************************************************************************
6// Filename : TileInfoLoader
7// Author : Ed Frank
8// Created : May, 2002
9//
10// DESCRIPTION:
11// Implementation comments only. Class level comments go in .h file.
12//
13// HISTORY:
14// 17May02 efrank First version.
15//
16// BUGS:
17//
18//*****************************************************************************
19
20// Tile includes
28
29// Calo includes
33
34// Athena includes
39
40// Gaudi includes
41#include "GaudiKernel/ToolHandle.h"
42#include "GaudiKernel/ServiceHandle.h"
43
44
45#include "TMatrixD.h"
46#include "cstdio"
47#include "cstdlib"
48#include <iomanip>
49#include <string>
50#include <fstream>
51#include <algorithm> //for std::none-of
52
53//*****************************************************************************
54TileInfoLoader::TileInfoLoader(const std::string& name,
55 ISvcLocator* pSvcLocator)
56//*****************************************************************************
57 : AthService(name, pSvcLocator)
58 , m_detStore("DetectorStore", name)
61{
62
63 //==========================================================
64 //=== expected number of ADC samples in digitization
65 //==========================================================
66 declareProperty("NSamples", m_nSamples=7, "Number of 25ns time slices in TileDigits");
67 declareProperty("TrigSample", m_iTrigSample=3, "sample index of t=0 in TileDigits");
68
69 //==========================================================
70 //=== Noise and conversion factors used in digitization
71 //==========================================================
72 declareProperty("TileNoise", m_tileNoise=true , "true => add noise to TileDigits and TileRawChannels (used in MC generation)");
73 declareProperty("TileCoherNoise", m_tileCoherNoise=false, "true => add coherent noise to TileDigits and TileRawChannels (used in MC generation)");
74 declareProperty("TileZeroSuppress", m_tileZeroSuppress=false, "true => applies threshold cuts in HitToRC, HitToDigits, RCToCells");
75 declareProperty("NoiseScaleIndex", m_noiseScaleIndex=1, "allowed values 0-3 to choose proper ADC->OF noise scale factor for different OF methods");
76 declareProperty("ThresholdRawChannel", m_thresholdRawChannel=-3.0, "threshold for TileRawChannel [adc] (high gain only, negative -> cut on abs value)");
77 declareProperty("ThresholdDigits", m_thresholdDigits=-2.0, "threshold for TileDigits [adc] (high gain only, negative -> cut on abs value)");
78
79 // values for TileCal Level1 Trigger Towers
80 declareProperty("TTL1Calib", m_ttL1Calib=4.1, "converts pCb to mV for TTL1");
81 declareProperty("TTL1NoiseSigma", m_ttL1NoiseSigma=2.5, "sigma of noise in TTL1 (mV)");
82 declareProperty("TTL1Thresh", m_ttL1Thresh=5.0, "threshold cut for TTL1 signals (mV)");
83 declareProperty("TTL1Ped", m_ttL1Ped=0.0, "pedestal for TTL1 signals (mV)");
84 declareProperty("TTL1Max", m_ttL1Max=1850.0, "max value for TTL1 signals (mV)");
85
86 // values for TileCal Muon Receiver Boards (!!! TO UPDATE !!! DUMMY Values) ~1mV = 1 ADC count
87 declareProperty("MuRcvCalib", m_MuRcvCalib = 14.20, "converts pCb to ADC counts for MuRcv");
88 declareProperty("MuRcvNoiseSigma", m_MuRcvNoiseSigma = 2, "sigma of noise in MuRcv (ADC counts)");
89 declareProperty("MuRcvThresh", m_MuRcvThresh = 5, "threshold cut for MuRcv signals (ADC count)");
90 declareProperty("MuRcvPed", m_MuRcvPed = 11.73, "pedestal for MuRcv signals (ADC count)");
91 declareProperty("MuRcvMax", m_MuRcvMax = 255, "max value for MuRcv signals (ADC count)");
92
93 // values for Level1 Muon output (not used currently)
94 declareProperty("MuL1Calib", m_muL1Calib=204.2, "converts pCb to mV for Mu");
95 declareProperty("MuL1NoiseSigma", m_muL1NoiseSigma=15.6, "sigma of noise in Mu (mV)");
96 declareProperty("MuL1Thresh", m_muL1Thresh=5.0, "threshold cut for Mu signals (mV)");
97 declareProperty("MuL1Ped", m_muL1Ped=0.0, "pedestal for Mu signals (mV)");
98 declareProperty("MuL1Max", m_muL1Max=1850.0, "max value for Mu signals (mV)");
99
100 // new values for high gain MBTS output connected to normal trigger tower
101 declareProperty("MBTSL1Calib", m_mbtsL1Calib=222.0, "converts pCb to mV for MBTS");
102 declareProperty("MBTSL1NoiseSigma", m_mbtsL1NoiseSigma=0.6, "sigma of noise in MBTS (mV)");
103 declareProperty("MBTSL1Thresh", m_mbtsL1Thresh=5.0, "threshold cut for MBTS signals (mV)");
104 declareProperty("MBTSL1Ped", m_mbtsL1Ped=0.0, "pedestal for MBTS signals (mV)");
105 declareProperty("MBTSL1Max", m_mbtsL1Max=1850.0, "max value for MBTS signals (mV)");
106
107 // values for custom TileCal cosmic trigger boards
108 declareProperty("TTL1CosmicsGain", m_ttL1CosmicsGain=5.0, "gain of the Cosmics board");
109 declareProperty("TTL1CosmicsThresh", m_ttL1CosmicsThresh=5.0, "threshold in the Cosmics board");
110
111 //==========================================================
112 //=== Digits pulse shapes
113 //==========================================================
114 declareProperty("DigitsShapeFileHi", m_digitsShapeFileHi = "pulsehi_physics.dat", "Filename for high gain pulse shape");
115 declareProperty("DigitsShapeFileLo", m_digitsShapeFileLo = "pulselo_physics.dat", "Filename for low gain pulse shape");
116 //===Trigger Tower Pulse shapes
117 declareProperty("filename_TTL1ShapeFile" ,m_TTL1ShapeFile = "pulse_adder_tower_physics.dat", "Filename for trigger tower pulse shape");
118 declareProperty("filename_MuRcvShapeFile" ,m_MuRcvShapeFile = "pulse_adder_muonRcv_physics.dat", "Filename for Muon Receiver pulse shape"); // using the sames as for TTL1ShapeFile !!! TO UPDATE !!!
119 declareProperty("filename_MuL1ShapeFile" ,m_MuL1ShapeFile = "pulse_adder_muon_physics.dat", "Filename for muon level1 trigger pulse shape");
120
121 //==========================================================
122 //=== Reference pulseshapes
123 //==========================================================
124 //===CIS Pulse shapes and derivatives
125 declareProperty("filename_lo_cis" ,m_pulsevar->m_filenameLoCIS = "pulselo_cis_100.dat" ,"Low gain CIS pulseshape 100pF");
126 declareProperty("filename_lo_cis_der" ,m_pulsevar->m_filenameLoCISDer = "dpulselo_cis_100.dat" ,"Low gain CIS pulseshape derivative 100pF");
127 declareProperty("filename_slo_cis" ,m_pulsevar->m_filenameSLoCIS = "pulselo.0230055.12.cap.5.2.dat" ,"Low gain CIS pulseshape 5pF");
128 declareProperty("filename_slo_cis_der" ,m_pulsevar->m_filenameSLoCISDer= "dpulselo.0230055.12.cap.5.2.dat" ,"Low gain CIS pulseshape derivative pF");
129 declareProperty("filename_hi_cis" ,m_pulsevar->m_filenameHiCIS = "pulsehi_cis_100.dat" ,"High gain CIS pulseshape 100pF");
130 declareProperty("filename_hi_cis_der" ,m_pulsevar->m_filenameHiCISDer = "dpulsehi_cis_100.dat" ,"High gain CIS pulseshape derivative 100pF");
131 declareProperty("filename_shi_cis" ,m_pulsevar->m_filenameSHiCIS = "pulsehi.0230055.12.cap.5.2.dat" ,"High gain CIS pulseshape 5pF");
132 declareProperty("filename_shi_cis_der" ,m_pulsevar->m_filenameSHiCISDer= "dpulsehi.0230055.12.cap.5.2.dat" ,"High gain CIS pulseshape derivative 5pF");
133 //===Physics Pulse shapes and derivatives
134 declareProperty("filename_lo_phys" ,m_pulsevar->m_filenameLoPhys = "pulselo_physics.dat" ,"Low gain physics pulseshape");
135 declareProperty("filename_hi_phys" ,m_pulsevar->m_filenameHiPhys = "pulsehi_physics.dat" ,"Low gain physics pulseshape derivative");
136 declareProperty("filename_lo_phys_der",m_pulsevar->m_filenameLoPhysDer = "dpulselo_physics.dat" ,"High gain physics pulseshape");
137 declareProperty("filename_hi_phys_der",m_pulsevar->m_filenameHiPhysDer = "dpulsehi_physics.dat" ,"High gain physics pulseshape derivative");
138 //=== Laser Pulse shapes and derivatives
139 declareProperty("filename_lo_las" ,m_pulsevar->m_filenameLoLas = "pulselo_laser.dat" ,"Low gain laser pulseshape");
140 declareProperty("filename_hi_las" ,m_pulsevar->m_filenameHiLas = "pulsehi_laser.dat" ,"Low gain laser pulseshape derivative");
141 declareProperty("filename_lo_las_der" ,m_pulsevar->m_filenameLoLasDer = "dpulselo_laser.dat" ,"High gain laser pulseshape");
142 declareProperty("filename_hi_las_der" ,m_pulsevar->m_filenameHiLasDer = "dpulsehi_laser.dat" ,"High gain laser pulseshape derivative");
143 //=== CIS Leakage Pulse shapes and derivatives
144 declareProperty("filename_sleaklo" ,m_pulsevar->m_filenameSLeakLo = "leaklo.0230055.12.cap.5.2.dat" ,"Low gain CIS leakage pulse 5pF");
145 declareProperty("filename_leaklo" ,m_pulsevar->m_filenameLeakLo = "leaklo_100.dat" ,"Low gain CIS leakage pulse 100pF");
146 declareProperty("filename_dsleaklo" ,m_pulsevar->m_filenameDSLeakLo = "dsleaklo.0230055.12.cap.5.2.dat","Derivative low gain CIS leakage pulse 5pF");
147 declareProperty("filename_dleaklo" ,m_pulsevar->m_filenameDLeakLo = "dleaklo_100.dat" ,"Derivative low gain CIS leakage pulse 100pF");
148 declareProperty("filename_sleakhi" ,m_pulsevar->m_filenameSLeakHi = "leakhi.0230055.12.cap.5.2.dat" ,"High gain CIS leakage pulse 5pF");
149 declareProperty("filename_leakhi" ,m_pulsevar->m_filenameLeakHi = "leakhi_100.dat" ,"High gain CIS leakage pulse 100pF");
150 declareProperty("filename_dsleakhi" ,m_pulsevar->m_filenameDSLeakHi = "dsleakhi.0230055.12.cap.5.2.dat","Derivative high gain CIS leakage pulse 5pF");
151 declareProperty("filename_dleakhi" ,m_pulsevar->m_filenameDLeakHi = "dleakhi_100.dat" ,"Derivative high gain CIS leakage pulse 100pF");
152 //=== Digitizer noise RMS as a function of channel number
153 declareProperty("filename_orig_noise" ,m_pulsevar->m_filenameOrigNoise = "noise_digi_orig.dat" ,"file with noise rms per channel");
154 declareProperty("filename_nk_noise" ,m_pulsevar->m_filenameNkNoise = "noise_digi_nk.dat" ,"file with noise rms per channel");
155
156 //==========================================================
157 //=== Covariance matrices for noise simulation
158 //==========================================================
159 declareProperty("filename_DecoCovaFilePrefix" ,m_DecoCovaFilePrefix = "DecoCovaMatrix");
160
161 //==========================================================
162 //=== Digitization
163 //==========================================================
164 declareProperty("ADCmax" ,m_ADCmax = 1023);
165 declareProperty("ADCmaskValue" ,m_ADCmaskValue = 2047);
166
167 //==========================================================
168 //=== TileWienerFilterWeights configuration
169 //==========================================================
170 declareProperty("LoadWienerFilterWeights" ,m_loadWienerFilterWeights = false);
171 declareProperty("WienerFilterPhysicsNSamples",m_WFWeights->m_NSamples_Phys = 7);
172 declareProperty("WienerFilterLuminosity" ,m_WFWeights->m_Luminosity = 40);
173}
174
175//*****************************************************************************
177//*****************************************************************************
178 delete m_pulsevar;
179 delete m_WFWeights;
180}
181
182//*****************************************************************************
184//*****************************************************************************
185
186 ATH_MSG_DEBUG( "Initializing...." << name() );
187
188 auto info = std::make_unique<TileInfo>();
189
190 // Forward properties.
191 info->m_nSamples = m_nSamples;
192 info->m_iTrigSample = m_iTrigSample;
193 info->m_tileNoise = m_tileNoise;
194 info->m_tileCoherNoise = m_tileCoherNoise;
195 info->m_tileZeroSuppress = m_tileZeroSuppress;
196 info->m_noiseScaleIndex = m_noiseScaleIndex;
197 info->m_thresholdRawChannel = m_thresholdRawChannel;
198 info->m_thresholdDigits = m_thresholdDigits;
199 info->m_ttL1Calib = m_ttL1Calib;
200 info->m_ttL1NoiseSigma = m_ttL1NoiseSigma;
201 info->m_ttL1Thresh = m_ttL1Thresh;
202 info->m_ttL1Ped = m_ttL1Ped;
203 info->m_ttL1Max = m_ttL1Max;
204 info->m_MuRcvCalib = m_MuRcvCalib;
205 info->m_MuRcvNoiseSigma = m_MuRcvNoiseSigma;
206 info->m_MuRcvThresh = m_MuRcvThresh;
207 info->m_MuRcvPed = m_MuRcvPed;
208 info->m_MuRcvMax = m_MuRcvMax;
209 info->m_muL1Calib = m_muL1Calib;
210 info->m_muL1NoiseSigma = m_muL1NoiseSigma;
211 info->m_muL1Thresh = m_muL1Thresh;
212 info->m_muL1Ped = m_muL1Ped;
213 info->m_muL1Max = m_muL1Max;
214 info->m_mbtsL1Calib = m_mbtsL1Calib;
215 info->m_mbtsL1NoiseSigma = m_mbtsL1NoiseSigma;
216 info->m_mbtsL1Thresh = m_mbtsL1Thresh;
217 info->m_mbtsL1Ped = m_mbtsL1Ped;
218 info->m_mbtsL1Max = m_mbtsL1Max;
219 info->m_ttL1CosmicsGain = m_ttL1CosmicsGain;
220 info->m_ttL1CosmicsThresh = m_ttL1CosmicsThresh;
221 info->m_ADCmax = m_ADCmax;
222 info->m_ADCmaskValue = m_ADCmaskValue;
223
224 m_WFWeights->m_NSamples_Phys = info->m_nSamples; // to make sure that everything is consistent
225
226 //=== Find the detector store service.
227 CHECK( m_detStore.retrieve() );
228
229 SmartIF<IGeoModelSvc> geoModel{service("GeoModelSvc")};
230 if(!geoModel) {
231 ATH_MSG_ERROR( "Could not locate GeoModelSvc" );
232 } else {
233 // check the DetDescr version
234 std::string atlasVersion = geoModel->atlasVersion();
235 int geo = atlasVersion.compare(0,9,"ATLAS-GEO");
236 int run1 = atlasVersion.compare(0,8,"ATLAS-R1");
237 int ibl = atlasVersion.compare(0,9,"ATLAS-IBL");
238 int run2 = atlasVersion.compare(0,8,"ATLAS-R2");
239 int comm = atlasVersion.compare(0,10,"ATLAS-Comm");
240 int upg = atlasVersion.compare(0,7,"ATLAS-P") ;
241 int ver = 0;
242 const auto comparisons={geo, run1, ibl, run2, comm, upg};
243 bool nothing_found = std::none_of(comparisons.begin(), comparisons.end(), [](int zeroMeansFound){return zeroMeansFound==0;});
244 GeoModel::GeoConfig geoConfig = geoModel->geoConfig();
245 bool RUN2 = (nothing_found && (geoConfig==GeoModel::GEO_RUN2
246 || geoConfig==GeoModel::GEO_RUN3
247 || geoConfig==GeoModel::GEO_RUN4
248 )) || (run2 == 0); // calibration for all geometries >=RUN2 are the same as in RUN2
249
250 if (geo == 0 || comm == 0 || ibl == 0 || run1 == 0 || run2 == 0 || upg == 0 || RUN2) {
251 int pos = (atlasVersion.substr(9)).find('-');
252 if(run1 == 0 || run2 == 0) pos = (atlasVersion.substr(13)).find('-') + 4;
253 std::string geoVersion = atlasVersion.substr(pos+10,2)
254 + atlasVersion.substr(pos+13,2)
255 + atlasVersion.substr(pos+16,2);
256 ver = atoi(geoVersion.c_str());
257 ATH_MSG_DEBUG( "New ATLAS geometry detected: " << atlasVersion << " (" << geoVersion << ")" << " version " << ver );
258
259 if (fabs(info->m_ttL1Calib - 4.1) < 0.001) {
260 // They are TTL1Calib = 4.1 and TTL1NoiseSigma = 2.5 but should be 6.9 and 2.8 respectively.
261
262 msg(MSG::INFO) << "Changing TTL1 calib from " << info->m_ttL1Calib;
263 info->m_ttL1Calib = 6.9;
264 msg(MSG::INFO) << " to " << info->m_ttL1Calib << endmsg;
265
266 msg(MSG::INFO) << "Changing TTL1 noise sigma from " << info->m_ttL1NoiseSigma;
267 info->m_ttL1NoiseSigma = 2.8;
268 msg(MSG::INFO) << " to " << info->m_ttL1NoiseSigma << endmsg;
269 }
270 } else {
271 ATH_MSG_DEBUG( "ATLAS geometry " << atlasVersion << " version " << ver );
272 }
273
274 }
275
276 //=== Read in Shape profile of digits & TTL1
278
279 CHECK( buildTTL1Shapes(*info, m_TTL1ShapeFile, info->m_TTL1NBins, info->m_TTL1Time0Bin
280 , info->m_TTL1BinsPerX, info->m_TTL1FullShape, info->m_TTL1Shape) );
281
282
283 CHECK( buildTTL1Shapes(*info, m_MuRcvShapeFile, info->m_MuRcvNBins, info->m_MuRcvTime0Bin
284 , info->m_MuRcvBinsPerX, info->m_MuRcvFullShape, info->m_MuRcvShape) );
285
286 CHECK( buildTTL1Shapes(*info, m_MuL1ShapeFile, info->m_MuL1NBins, info->m_MuL1Time0Bin
287 , info->m_MuL1BinsPerX, info->m_MuL1FullShape, info->m_MuL1Shape) );
288
289 //=== Read in coherent noise if required
290 if (info->TileCoherNoise()) buildCovMatrix (*info);
291
292 // put pointer to new TilePulseShapes in TileInfo
293 // only if we want to use them (i.e. when we also read all calib files)
294 info->m_pulseShapes = m_pulsevar;
295
296 // point to WienerFilterWeights
297 if (m_loadWienerFilterWeights) info->m_WienerFilterWeights=m_WFWeights;
298
299 //=== Initialize and register TileInfo object
300 CHECK( info->initialize() );
301
302 CHECK( m_detStore->record(std::move(info), m_tileInfoName, false ) );
303 ATH_MSG_DEBUG( "Placed TileInfo object [" << m_tileInfoName << "] in the detector store." );
304
305 return StatusCode::SUCCESS;
306}
307
308//****************************************************************************
310//****************************************************************************
311
312 ATH_MSG_DEBUG( "TileInfoLoader::finalize()" );
313
314 return Service::finalize();
315}
316
317
318
321
322 ATH_MSG_DEBUG( "In buildDigitsShapesHiLo" );
323
324 // Read in Shape profile of digits signal from external file.
325
326 double It0;
327 double dbuff;
328 std::string line;
329
330 // Hi gain
331 ATH_MSG_DEBUG( " **** Start of High gain Pulse shapes in TileInfo " );
332
333 // Find the full path to filename:
334 std::string file_hi = PathResolver::find_file(m_digitsShapeFileHi, "DATAPATH");
335 ATH_MSG_DEBUG( "Reading file " << file_hi );
336
337 //=== Test if files are there and can be opened
338 if (file_hi.empty()) {
339 ATH_MSG_ERROR( "Could not find input file " << m_digitsShapeFileHi );
340 return StatusCode::FAILURE;
341 }
342
343 std::ifstream shape_file_hi(file_hi.c_str());
344 if (!shape_file_hi.is_open()) {
345 ATH_MSG_ERROR( "Could not open input file " << file_hi );
346 return StatusCode::FAILURE;
347 }
348
349 if (std::getline(shape_file_hi, line)) {
350 ATH_MSG_DEBUG( endmsg << line );
351 }
352
353 if (std::getline(shape_file_hi, line)) {
354 if (sscanf(line.c_str(), "%80d", &info.m_digitsNBinsHi) == 1)
355 ATH_MSG_DEBUG( std::setw(3) << info.m_digitsNBinsHi << " number of bins in shaping function" );
356 }
357
358 if (std::getline(shape_file_hi, line)) {
359 if (sscanf(line.c_str(), "%80d", &info.m_digitsTime0BinHi) == 1)
360 ATH_MSG_DEBUG( std::setw(3) << info.m_digitsTime0BinHi << " index of in-time bin" );
361 }
362
363 if (std::getline(shape_file_hi, line)) {
364 if (sscanf(line.c_str(), "%80d", &info.m_digitsBinsPerXHi) == 1)
365 ATH_MSG_DEBUG( std::setw(3) << info.m_digitsBinsPerXHi << " bins per beam crossing" );
366 }
367
368 // Read in the Hi gain shape vector.
369 info.m_digitsFullShapeHi.resize(info.m_digitsNBinsHi, 0.);
370 size_t jt = 0;
371 while (std::getline(shape_file_hi, line) && jt < info.m_digitsFullShapeHi.size()) {
372 int nread = sscanf(line.c_str(), "%80lf %80lf", &It0, &dbuff);
373 if (nread > 1) info.m_digitsFullShapeHi[jt++] = dbuff;
374 ATH_MSG_VERBOSE( "t= " << It0 << " a= " << dbuff );
375 }
376
377 shape_file_hi.close();
378
379 // Lo gain
380 ATH_MSG_DEBUG( " **** Start of Low gain Pulse shapes in TileInfo " );
381
382 // Find the full path to filename:
383 std::string file_lo = PathResolver::find_file(m_digitsShapeFileLo, "DATAPATH");
384 ATH_MSG_DEBUG( "Reading file " << file_lo );
385
386 //=== Test if files are there and can be opened
387 if (file_lo.empty()) {
388 ATH_MSG_ERROR( "Could not find input file " << m_digitsShapeFileLo );
389 return StatusCode::FAILURE;
390 }
391
392 std::ifstream shape_file_lo(file_lo.c_str());
393 if (!shape_file_lo.is_open()) {
394 ATH_MSG_ERROR( "Could not open input file " << file_lo );
395 return StatusCode::FAILURE;
396 }
397
398 if (std::getline(shape_file_lo, line)) {
399 ATH_MSG_DEBUG( endmsg << line );
400 }
401
402 if (std::getline(shape_file_lo, line)) {
403 if (sscanf(line.c_str(), "%80d", &info.m_digitsNBinsLo) == 1)
404 ATH_MSG_DEBUG( std::setw(3) << info.m_digitsNBinsLo << " number of bins in shaping function" );
405 }
406
407 if (std::getline(shape_file_lo, line)) {
408 if (sscanf(line.c_str(), "%80d", &info.m_digitsTime0BinLo) == 1)
409 ATH_MSG_DEBUG( std::setw(3) << info.m_digitsTime0BinLo << " index of in-time bin" );
410 }
411
412 if (std::getline(shape_file_lo, line)) {
413 if (sscanf(line.c_str(), "%80d", &info.m_digitsBinsPerXLo) == 1)
414 ATH_MSG_DEBUG( std::setw(3) << info.m_digitsBinsPerXLo << " bins per beam crossing" );
415 }
416
417 // Read in the Lo gain shape vector.
418 info.m_digitsFullShapeLo.resize(info.m_digitsNBinsLo, 0.);
419 jt = 0;
420 while (std::getline(shape_file_lo, line) && jt < info.m_digitsFullShapeLo.size()) {
421 int nread = sscanf(line.c_str(), "%80lf %80lf", &It0, &dbuff);
422 if (nread > 1) info.m_digitsFullShapeLo[jt++] = dbuff;
423 ATH_MSG_VERBOSE( "t= " << It0 << " a= " << dbuff );
424 }
425
426 shape_file_lo.close();
427
428 //find the greatest value in digitsFullShape (should equal info.m_digitsTime0Bin)
429 int it0_hi = 0;
430 int it0_lo = 0;
431 double peak_hi = 0;
432 double peak_lo = 0;
433 for (int i = 0; i < info.m_digitsNBinsHi; i++) {
434 if (info.m_digitsFullShapeHi[i] > peak_hi) {
435 peak_hi = info.m_digitsFullShapeHi[i];
436 it0_hi = i;
437 }
438 }
439
440 for (int i = 0; i < info.m_digitsNBinsLo; i++) {
441 if (info.m_digitsFullShapeLo[i] > peak_lo) {
442 peak_lo = info.m_digitsFullShapeLo[i];
443 it0_lo = i;
444 }
445 }
446
447 if (msgLvl(MSG::DEBUG)) {
448 msg(MSG::DEBUG) << " High Gain: Peak value = " << peak_hi
449 << " at bin = " << it0_hi
450 << ", info.m_digitsTime0BinHi = " << info.m_digitsTime0BinHi << endmsg;
451
452 msg(MSG::DEBUG) << " Low Gain: Peak value = " << peak_lo
453 << " at bin = " << it0_lo
454 << ", info.m_digitsTime0BinLow = " << info.m_digitsTime0BinLo << endmsg;
455 }
456
457 // Create vector of time profiles at beam crossings.
458 info.m_digitsShapeHi.resize(info.m_nSamples, 0.);
459 info.m_digitsShapeLo.resize(info.m_nSamples, 0.);
460// ATH_MSG_DEBUG( " Pasa el resize y va a entrar en el lopp" );
461
462 for (int i = 0; i < info.m_nSamples; i++) {
463 int j = info.m_digitsTime0BinHi + (i - info.m_iTrigSample) * info.m_digitsBinsPerXHi;
464 if (j < 0) j = 0;
465 if (j >= info.m_digitsNBinsHi) j = info.m_digitsNBinsHi-1;
466 info.m_digitsShapeHi[i] = info.m_digitsFullShapeHi[j];
467 int k = info.m_digitsTime0BinLo + (i - info.m_iTrigSample) * info.m_digitsBinsPerXLo;
468 if (k < 0) k = 0;
469 if (k >= info.m_digitsNBinsLo) k = info.m_digitsNBinsLo-1;
470 info.m_digitsShapeLo[i] = info.m_digitsFullShapeLo[k];
471 }
472
473 if (msgLvl(MSG::DEBUG)) {
474 msg(MSG::DEBUG) << " Shaping profile at beam crossings: "
475 << " Number of samples = " << info.m_nSamples
476 << ", Sample at Time 0 = " << info.m_iTrigSample << endmsg;
477
478 msg(MSG::DEBUG) << " High gain Shape factor = ";
479 for (int i = 0; i < info.m_nSamples; i++) {
480 msg(MSG::DEBUG) << std::setiosflags(std::ios::fixed)
481 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
482 << info.m_digitsShapeHi[i];
483 }
484
485 msg(MSG::DEBUG) << endmsg;
486
487 msg(MSG::DEBUG) << " Low gain Shape factor = ";
488 for (int i = 0; i < info.m_nSamples; i++) {
489 msg(MSG::DEBUG) << std::setiosflags(std::ios::fixed)
490 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
491 << info.m_digitsShapeLo[i];
492 }
493 msg(MSG::DEBUG) << endmsg;
494
495 }
496
497 // Create vector of derivatives from shaping vector.
498 info.m_digitsDerivativeHi.resize(info.m_digitsNBinsHi, 0.);
499 info.m_digitsDerivativeLo.resize(info.m_digitsNBinsLo, 0.);
500 for (int i = 1; i < info.m_digitsNBinsHi - 1; i++) {
501 info.m_digitsDerivativeHi[i] = (info.m_digitsFullShapeHi[i + 1]
502 - info.m_digitsFullShapeHi[i - 1]) / 2;
503 }
504
505 for (int i = 1; i < info.m_digitsNBinsLo - 1; i++) {
506 info.m_digitsDerivativeLo[i] = (info.m_digitsFullShapeLo[i + 1]
507 - info.m_digitsFullShapeLo[i - 1]) / 2;
508 }
509
510 return StatusCode::SUCCESS;
511}
512
515 const std::string& ShapeFile,
516 int &NBins, int &Time0Bin, int &BinsPerX
517 , std::vector<double> &FullShape, std::vector<double> &Shape) {
518
519 // Read in Shape profile of signal from external file.
520 ATH_MSG_DEBUG( " **** Start of TTL1 shapes in TileInfo " );
521
522 // Find the full path to filename:
523 std::string file = PathResolver::find_file(ShapeFile, "DATAPATH");
524 ATH_MSG_DEBUG( "Reading file " << file );
525
526 if (file.empty()) {
527 ATH_MSG_ERROR( "Could not find input file " << ShapeFile );
528 return StatusCode::FAILURE;
529 }
530
531 std::ifstream shape_file(file.c_str());
532 if (!shape_file.is_open()) {
533 ATH_MSG_ERROR( "Could not open input file " << file );
534 return StatusCode::FAILURE;
535 }
536
537 double It0;
538 double dbuff;
539 std::string line;
540
541 if (std::getline(shape_file, line)) {
542 ATH_MSG_DEBUG( endmsg << MSG::DEBUG << line );
543
544 }
545
546 if (std::getline(shape_file, line)) {
547 if (sscanf(line.c_str(), "%80d", &NBins) == 1)
548 ATH_MSG_DEBUG( std::setw(3) << NBins << " number of bins in shaping function" );
549 }
550
551 if (std::getline(shape_file, line)) {
552 if (sscanf(line.c_str(), "%80d", &Time0Bin) == 1)
553 ATH_MSG_DEBUG( std::setw(3) << Time0Bin << " index of in-time bin" );
554 }
555
556 if (std::getline(shape_file, line)) {
557 if (sscanf(line.c_str(), "%80d", &BinsPerX) == 1)
558 ATH_MSG_DEBUG( BinsPerX << " bins per beam crossing" );
559 }
560
561 // Read in the ttl1shape vector.
562 FullShape.resize(NBins, 0.);
563 size_t jt = 0;
564 while (std::getline(shape_file, line) && jt < FullShape.size()) {
565 int nread = sscanf(line.c_str(), "%80lf %80lf", &It0, &dbuff);
566 if (nread > 1) FullShape[jt++] = dbuff;
567 ATH_MSG_VERBOSE( "t= " << It0 << " a= " << dbuff );
568 }
569
570 shape_file.close();
571
572 // Print out ttl1shape values.
573 int nline = (NBins - 1) / 8 + 1;
574 if (msgLvl(MSG::DEBUG)) {
575 for (int jline = 0; jline < nline; jline++) {
576 int j1 = 8 * jline;
577 int j2 = j1 + 8;
578 if (j2 > NBins) j2 = NBins;
579 msg(MSG::DEBUG) << " " << std::setw(3) << j1 << " ";
580
581 for (int i = j1; i < j2; i++) {
582 msg(MSG::DEBUG) << std::setiosflags(std::ios::fixed)
583 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
584 << FullShape[i];
585 }
586 msg(MSG::DEBUG) << endmsg;
587 }
588 }
589
590 //find the greatest value in ttl1shape (should equal Time0Bin)
591 int it0 = 0;
592 double peak = 0;
593 for (int i = 0; i < NBins; i++) {
594 if (FullShape[i] > peak) {
595 peak = FullShape[i];
596 it0 = i;
597 }
598 }
599
600 ATH_MSG_DEBUG( " Peak value = " << peak
601 << " at bin = " << it0
602 << ", Time0Bin = " << Time0Bin );
603
604
605 // Create vector of time profiles at beam crossings.
606 Shape.resize(info.m_nSamples, 0.);
607 for (int i = 0; i < info.m_nSamples; i++) {
608 int j = Time0Bin + (i - info.m_iTrigSample) * BinsPerX;
609 if (j < 0) j = 0;
610 if (j >= NBins) j = NBins-1;
611 Shape[i] = FullShape[j];
612 }
613
614 if (msgLvl(MSG::DEBUG)) {
615 msg(MSG::DEBUG) << " TileInfo: profile at beam crossings: "
616 << " Number of samples = " << info.m_nSamples
617 << ", Sample at Time 0 = " << info.m_iTrigSample << endmsg;
618
619 msg(MSG::DEBUG) << " Shape factor = ";
620 for (int i = 0; i < info.m_nSamples; i++) {
621 msg(MSG::DEBUG) << std::setiosflags(std::ios::fixed)
622 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
623 << Shape[i];
624 }
625 msg(MSG::DEBUG) << endmsg;
626 }
627
628 return StatusCode::SUCCESS;
629}
630
633{
634// author:F Spano' - beg.
635// TOUPDATE:: In the future maybe read from a root file
636// Read in Covariance Matrix for Hi Gain/Lo Gain - Barrel/Ext Barrel
637// from four external files
638
639// Changed by F. Veloso: full coverage of the Tilecal without using
640// the same correlation matrix for all modules.
641
642 char partstr[10];
643 char gainstr[10];
644 char buff[1024];
645 std::string line;
646
647 // Cicle over 4 partitions, 64 modules and 2 gains
648 for (int part = 0; part < 4; ++part) {
649 // Create DecoCovaria[part]
650// ATH_MSG_DEBUG( "begin DecoCovaria.push_back" );
651 info.m_decoCovaria.push_back(std::vector<std::vector<TMatrixD*> >());
652// ATH_MSG_DEBUG( "DecoCovaria.push_back done" );
653 for (int modu = 0; modu < 64; ++modu) {
654 // Create DecoCovaria[part][modu]
655// ATH_MSG_DEBUG( " begin DecoCovaria[part].push_back" );
656 info.m_decoCovaria[part].push_back(std::vector<TMatrixD*>());
657// ATH_MSG_DEBUG( " DecoCovaria[part].push_back done" );
658
659 for (int gain = 0; gain < 2; ++gain) {
660// ATH_MSG_DEBUG( " part=" << part << " modu=" << modu << " gain=" << gain );
661
662 // Open file which corresponds to DecoCovaria[part][modu][gain]
663 if (part == 0) sprintf(partstr, "EBA");
664 else if (part == 1) sprintf(partstr, "LBA");
665 else if (part == 2) sprintf(partstr, "LBC");
666 else sprintf(partstr, "EBC");
667
668 if (gain == 0) sprintf(gainstr, "Hi");
669 else sprintf(gainstr, "Lo");
670
671 sprintf(buff, "%s%s%02d%s.txt", m_DecoCovaFilePrefix.c_str(), partstr, modu + 1, gainstr);
672 std::string file = PathResolver::find_file(buff, "DATAPATH");
673// ATH_MSG_DEBUG( " buff=" << buff << " file=" << file.c_str() );
674
675 if (file.empty()) {
676 ATH_MSG_WARNING( "Could not find input file " << buff );
677 } else {
678 ATH_MSG_DEBUG( "Reading file " << file );
679
680 std::ifstream cov_file(file.c_str());
681
682 if (!cov_file.is_open()) {
683 ATH_MSG_WARNING( "Can't read input files, setting tileCoherNoise flag to FALSE" );
684
685 info.m_tileCoherNoise = false;
686 return;
687 } else {
688
689 ATH_MSG_DEBUG( " **** Start of Decomposed Covariance Matrix Read Out" );
690
691 if (std::getline(cov_file, line)) {
692 ATH_MSG_DEBUG( "Matrix is being loaded: " << line );
693 }
694
695 //define Matrix dimension
696 int dima = 0;
697 if (std::getline(cov_file, line)) {
698 if (sscanf(line.c_str(), "%80d", &dima) == 1)
699 ATH_MSG_DEBUG( "The Dimension of the matrix is " << dima );
700 }
701
702 // define Matrix: at this level we cannot initialize it with a given one
703 TMatrixD* pDecoCova = new TMatrixD(dima, dima);
704
705 // load tokens to be searched for in a string
706 char* word;
707 char* saveptr;
708 const char* TOKENS = { " \t\n" };
709
710 // read Matrix
711 int row = 0;
712 while (std::getline(cov_file, line) && row < dima) {
713 ATH_MSG_DEBUG( "line " << row << " is " << line );
714
715 strncpy(buff, line.c_str(), 1023);
716 for (int column = 0; column < dima; column++) {
717 // Check for comment lines
718 if (*buff == '!' || *buff == '*') continue;
719 //
720 if (column == 0) {
721 word = strtok_r(buff, TOKENS, &saveptr);
722 } else {
723 word = strtok_r(nullptr, TOKENS, &saveptr);
724 }
725 double pippo = (word) ? atof(word) : 0.0;
726 // int nread = sscanf(buff, "%1f", &pippo);
727 ATH_MSG_VERBOSE( "elem " << column << " is " << pippo );
728 (*pDecoCova)(row, column) = pippo;
729 }
730 row++;
731 }
732
733 cov_file.close();
734 // Fill DecoCovaria[part][modu][gain]
735 info.m_decoCovaria[part][modu].push_back(pDecoCova);
736
737 }
738 }
739 }
740 }
741 }
742}
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
double m_ttL1NoiseSigma
double m_ttL1CosmicsThresh
std::string m_MuL1ShapeFile
double m_thresholdDigits
void buildCovMatrix(TileInfo &info)
std::string m_MuRcvShapeFile
double m_mbtsL1NoiseSigma
virtual StatusCode finalize() override
TilePulseShapes * m_pulsevar
Pointer to TilePulseShapes object.
double m_thresholdRawChannel
std::string m_DecoCovaFilePrefix
std::string m_digitsShapeFileHi
Filenames of input files.
StatusCode buildDigitsShapesHiLo(TileInfo &info)
std::string m_TTL1ShapeFile
Gaudi::Property< std::string > m_tileInfoName
virtual ~TileInfoLoader()
double m_MuRcvNoiseSigma
StatusCode buildTTL1Shapes(TileInfo &info, const std::string &ShapeFile, int &NBins, int &Time0Bin, int &BinsPerX, std::vector< double > &FullShape, std::vector< double > &Shape)
int m_nSamples
Properties to forward to TileInfo.
ServiceHandle< StoreGateSvc > m_detStore
TileInfoLoader(const std::string &name, ISvcLocator *pSvcLocator)
std::string m_digitsShapeFileLo
bool m_loadWienerFilterWeights
TileWienerFilterWeights * m_WFWeights
Pointer to Wiener Filtering weights.
virtual StatusCode initialize() override
TFile * file