41 #include "GaudiKernel/ToolHandle.h"
42 #include "GaudiKernel/ServiceHandle.h"
55 ISvcLocator* pSvcLocator)
58 , m_detStore(
"DetectorStore",
name)
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");
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)");
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)");
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)");
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)");
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)");
108 declareProperty(
"TTL1CosmicsGain",
m_ttL1CosmicsGain=5.0,
"gain of the Cosmics board");
109 declareProperty(
"TTL1CosmicsThresh",
m_ttL1CosmicsThresh=5.0,
"threshold in the Cosmics board");
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");
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");
119 declareProperty(
"filename_MuL1ShapeFile" ,
m_MuL1ShapeFile =
"pulse_adder_muon_physics.dat",
"Filename for muon level1 trigger pulse shape");
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");
135 declareProperty(
"filename_hi_phys" ,
m_pulsevar->
m_filenameHiPhys =
"pulsehi_physics.dat" ,
"Low gain physics pulseshape derivative");
140 declareProperty(
"filename_hi_las" ,
m_pulsevar->
m_filenameHiLas =
"pulsehi_laser.dat" ,
"Low gain laser pulseshape derivative");
144 declareProperty(
"filename_sleaklo" ,
m_pulsevar->
m_filenameSLeakLo =
"leaklo.0230055.12.cap.5.2.dat" ,
"Low gain CIS leakage pulse 5pF");
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");
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");
164 declareProperty(
"ADCmax" ,
m_ADCmax = 1023);
188 auto info = std::make_unique<TileInfo>();
229 SmartIF<IGeoModelSvc> geoModel{service(
"GeoModelSvc")};
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") ;
243 bool nothing_found = std::none_of(comparisons.begin(), comparisons.end(), [](
int zeroMeansFound){return zeroMeansFound==0;});
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 );
259 if (fabs(
info->m_ttL1Calib - 4.1) < 0.001) {
262 msg(MSG::INFO) <<
"Changing TTL1 calib from " <<
info->m_ttL1Calib;
263 info->m_ttL1Calib = 6.9;
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;
280 ,
info->m_TTL1BinsPerX,
info->m_TTL1FullShape,
info->m_TTL1Shape) );
284 ,
info->m_MuRcvBinsPerX,
info->m_MuRcvFullShape,
info->m_MuRcvShape) );
287 ,
info->m_MuL1BinsPerX,
info->m_MuL1FullShape,
info->m_MuL1Shape) );
305 return StatusCode::SUCCESS;
331 ATH_MSG_DEBUG(
" **** Start of High gain Pulse shapes in TileInfo " );
338 if (file_hi.empty()) {
340 return StatusCode::FAILURE;
343 std::ifstream shape_file_hi(file_hi.c_str());
344 if (!shape_file_hi.is_open()) {
346 return StatusCode::FAILURE;
349 if (std::getline(shape_file_hi,
line)) {
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" );
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" );
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" );
369 info.m_digitsFullShapeHi.resize(
info.m_digitsNBinsHi, 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;
377 shape_file_hi.close();
380 ATH_MSG_DEBUG(
" **** Start of Low gain Pulse shapes in TileInfo " );
387 if (file_lo.empty()) {
389 return StatusCode::FAILURE;
392 std::ifstream shape_file_lo(file_lo.c_str());
393 if (!shape_file_lo.is_open()) {
395 return StatusCode::FAILURE;
398 if (std::getline(shape_file_lo,
line)) {
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" );
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" );
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" );
418 info.m_digitsFullShapeLo.resize(
info.m_digitsNBinsLo, 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;
426 shape_file_lo.close();
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];
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];
449 <<
" at bin = " << it0_hi
450 <<
", info.m_digitsTime0BinHi = " <<
info.m_digitsTime0BinHi <<
endmsg;
453 <<
" at bin = " << it0_lo
454 <<
", info.m_digitsTime0BinLow = " <<
info.m_digitsTime0BinLo <<
endmsg;
458 info.m_digitsShapeHi.resize(
info.m_nSamples, 0.);
459 info.m_digitsShapeLo.resize(
info.m_nSamples, 0.);
462 for (
int i = 0;
i <
info.m_nSamples;
i++) {
463 int j =
info.m_digitsTime0BinHi + (
i -
info.m_iTrigSample) *
info.m_digitsBinsPerXHi;
465 if (j >
info.m_digitsNBinsHi) j =
info.m_digitsNBinsHi;
466 info.m_digitsShapeHi[
i] =
info.m_digitsFullShapeHi[j];
467 int k =
info.m_digitsTime0BinLo + (
i -
info.m_iTrigSample) *
info.m_digitsBinsPerXLo;
469 if (
k >
info.m_digitsNBinsLo)
k =
info.m_digitsNBinsLo;
470 info.m_digitsShapeLo[
i] =
info.m_digitsFullShapeLo[
k];
475 <<
" Number of samples = " <<
info.m_nSamples
476 <<
", Sample at Time 0 = " <<
info.m_iTrigSample <<
endmsg;
479 for (
int i = 0;
i <
info.m_nSamples;
i++) {
481 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
482 <<
info.m_digitsShapeHi[
i];
488 for (
int i = 0;
i <
info.m_nSamples;
i++) {
490 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
491 <<
info.m_digitsShapeLo[
i];
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;
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;
510 return StatusCode::SUCCESS;
515 const std::string& ShapeFile,
516 int &NBins,
int &Time0Bin,
int &BinsPerX
517 , std::vector<double> &FullShape, std::vector<double> &Shape) {
528 return StatusCode::FAILURE;
531 std::ifstream shape_file(
file.c_str());
532 if (!shape_file.is_open()) {
534 return StatusCode::FAILURE;
541 if (std::getline(shape_file,
line)) {
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" );
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" );
556 if (std::getline(shape_file,
line)) {
557 if (sscanf(
line.c_str(),
"%80d", &BinsPerX) == 1)
562 FullShape.resize(NBins, 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;
573 int nline = (NBins - 1) / 8 + 1;
575 for (
int jline = 0; jline < nline; jline++) {
578 if (
j2 > NBins)
j2 = NBins;
581 for (
int i =
j1;
i <
j2;
i++) {
583 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
593 for (
int i = 0;
i < NBins;
i++) {
594 if (FullShape[
i] > peak) {
601 <<
" at bin = " << it0
602 <<
", Time0Bin = " << Time0Bin );
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;
610 if (j > NBins) j = NBins;
611 Shape[
i] = FullShape[j];
616 <<
" Number of samples = " <<
info.m_nSamples
617 <<
", Sample at Time 0 = " <<
info.m_iTrigSample <<
endmsg;
620 for (
int i = 0;
i <
info.m_nSamples;
i++) {
622 << std::setiosflags(std::ios::showpoint) << std::setw(9) << std::setprecision(5)
628 return StatusCode::SUCCESS;
651 info.m_decoCovaria.push_back(std::vector<std::vector<TMatrixD*> >());
653 for (
int modu = 0; modu < 64; ++modu) {
656 info.m_decoCovaria[
part].push_back(std::vector<TMatrixD*>());
668 if (
gain == 0) sprintf(gainstr,
"Hi");
669 else sprintf(gainstr,
"Lo");
680 std::ifstream cov_file(
file.c_str());
682 if (!cov_file.is_open()) {
683 ATH_MSG_WARNING(
"Can't read input files, setting tileCoherNoise flag to FALSE" );
685 info.m_tileCoherNoise =
false;
689 ATH_MSG_DEBUG(
" **** Start of Decomposed Covariance Matrix Read Out" );
691 if (std::getline(cov_file,
line)) {
697 if (std::getline(cov_file,
line)) {
698 if (sscanf(
line.c_str(),
"%80d", &dima) == 1)
703 TMatrixD* pDecoCova =
new TMatrixD(dima, dima);
708 const char* TOKENS = {
" \t\n" };
712 while (std::getline(cov_file,
line) &&
row < dima) {
718 if (*
buff ==
'!' || *
buff ==
'*')
continue;
721 word = strtok_r(
buff, TOKENS, &saveptr);
723 word = strtok_r(
nullptr, TOKENS, &saveptr);
725 double pippo = (word) ?
atof(word) : 0.0;
735 info.m_decoCovaria[
part][modu].push_back(pDecoCova);