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") ;
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;});
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;
264 msg(MSG::INFO) <<
" to " << info->m_ttL1Calib <<
endmsg;
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;
271 ATH_MSG_DEBUG(
"ATLAS geometry " << atlasVersion <<
" version " << ver );
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) );
300 CHECK( info->initialize() );
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];
448 msg(MSG::DEBUG) <<
" High Gain: Peak value = " << peak_hi
449 <<
" at bin = " << it0_hi
450 <<
", info.m_digitsTime0BinHi = " << info.m_digitsTime0BinHi <<
endmsg;
452 msg(MSG::DEBUG) <<
" Low Gain: Peak value = " << peak_lo
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-1;
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-1;
470 info.m_digitsShapeLo[i] = info.m_digitsFullShapeLo[k];
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;
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];
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];
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;
579 msg(MSG::DEBUG) <<
" " << std::setw(3) << j1 <<
" ";
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)
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-1;
611 Shape[i] = FullShape[j];
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;
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)
628 return StatusCode::SUCCESS;
648 for (
int part = 0; part < 4; ++part) {
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*>());
659 for (
int gain = 0; gain < 2; ++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");
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) {
715 strncpy(buff, line.c_str(), 1023);
716 for (
int column = 0; column < dima; column++) {
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;
728 (*pDecoCova)(row, column) = pippo;
735 info.m_decoCovaria[part][modu].push_back(pDecoCova);