7 #include "GaudiKernel/Chrono.h"
32 m_bitCorrelation(nullptr),
37 m_onlineTHoldBreaches(nullptr),
39 m_crossTalkFix(nullptr)
72 ATH_MSG_FATAL(
"Either specify an OnlineCalibFile or set CompareOnlineCalibFile to false");
73 return StatusCode::FAILURE;
96 const std::vector<Identifier> &
ids =
m_idHelperSvc->cscIdHelper().idVector();
101 for(
const auto &thisChamberId:
ids)
103 std::vector<Identifier> stripVect;
104 m_idHelperSvc->cscIdHelper().idChannels(thisChamberId,stripVect);
108 for(
const auto & thisStrip: stripVect)
111 m_idHelperSvc->cscIdHelper().get_channel_hash(thisStrip,stripHash);
122 for(
unsigned int stripItr = 0 ; stripItr <=
m_maxStripHash; stripItr++)
128 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
130 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
133 int stationEta =
m_idHelperSvc->cscIdHelper().stationEta(stripId);
134 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
135 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
136 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
137 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
140 char name[30],titleSeed[600];
141 TH1I*
hist =
nullptr;
145 sprintf(
name,
"ampHist%u",stripItr);
146 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d",
147 stationEta,(2*stationPhi+50 -
stationName),wireLayer,orientation,stripNumber);
152 hist->GetXaxis()->SetTitle(
"Amplitude (ADC value)");
153 hist->GetYaxis()->SetTitle(
"Counts");
159 sprintf(
name,
"sampHist%u_%d",stripItr,
cnt);
160 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d, sample %d",
161 stationEta,(2*stationPhi+50 -
stationName),wireLayer,orientation,stripNumber,
cnt);
174 sprintf(
name,
"bitHist%u",stripItr);
175 sprintf(titleSeed,
"Bit histogram for eta %d, sector %d, layer %d%c strip %d",
176 stationEta,(2*stationPhi+50 -
stationName),wireLayer,orientation,stripNumber);
179 hist->GetXaxis()->SetTitle(
"Bit");
180 hist->GetYaxis()->SetTitle(
"Counts");
220 if(!
ifile.is_open()){
222 return StatusCode::FAILURE;
226 unsigned int onlineId;
233 return StatusCode::FAILURE;
240 while(
ifile >> std::hex >> onlineId >> std::dec) {
244 ifile >> buf >> buf >> buf >> buf >>
rms >> buf >> f001;
245 double thold = f001 + 2*
rms;
246 ATH_MSG_VERBOSE(
"onlid: " << std::hex << onlineId << std::dec <<
" hash: " << hashId <<
" rms: " <<
rms <<
" f001: " << f001 <<
" thold: " << thold);
255 if(chanCnt != 30720){
256 ATH_MSG_FATAL(
"Did not retrieve expected 30720 channels from online database! Retrieved: " << chanCnt);
257 ATH_MSG_FATAL(
"Last onlineId read: " << std::hex << onlineId << std::dec);
258 return StatusCode::FAILURE;
277 return StatusCode::SUCCESS;
289 ATH_MSG_ERROR(
"There was an error collecting information from the RDO this event.");
290 return StatusCode::RECOVERABLE;
293 return StatusCode::SUCCESS;
300 return StatusCode::FAILURE;
315 return StatusCode::FAILURE;
325 return StatusCode::FAILURE;
334 return StatusCode::FAILURE;
338 return StatusCode::SUCCESS;
354 if (sc_read != StatusCode::SUCCESS)
357 return StatusCode::FAILURE;
362 if(rawDataContainer->
size() == 0)
365 return StatusCode::FAILURE;
375 for(
const auto rod : *rawDataContainer)
386 for(
const auto cluster: *
rod)
389 int numStrips = cluster->width();
390 int samplesPerStrip = (cluster->samples()).
size()/numStrips;
392 ATH_MSG_VERBOSE(
"About to collect info from " << numStrips <<
" strips");
393 for(
int stripItr = 0; stripItr <numStrips; stripItr++)
403 int stripHash = cscChannelHashId;
406 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
414 << stripHash <<
") from the wrong multilayer has appeared in the data. Its string id is " <<
m_idHelperSvc->cscIdHelper().show_to_string(stripId)
419 << stripHash <<
" " << cscChannelHashId);
435 m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, newHash );
450 std::vector<uint16_t> samples;
451 cluster->samples(stripItr,samplesPerStrip,samples);
457 for(
const auto & thisSample: samples)
459 (*m_ampHists)[stripHash]->Fill(thisSample);
461 (*((*m_sampHists)[stripHash]))[sampCnt]->Fill(thisSample);
464 TH2F* prodHist =
nullptr;
466 prodHist = (*m_bitProds)[stripHash];
476 " has online threshold breach. Sample: " << thisSample <<
" Thold: "
486 ATH_MSG_DEBUG(
"There is an empty rod (CscRawDataContainer).");
489 return StatusCode::SUCCESS;
502 for(
unsigned int stripHash = 0 ;stripHash <=
m_maxStripHash; stripHash++)
504 if(stripHash < 50 || stripHash%1000 == 0)
507 ATH_MSG_VERBOSE((
float)clock()/((
float)CLOCKS_PER_SEC) <<
" is the time");
510 TH1I * ampHist = (*m_ampHists)[stripHash];
514 if(ampHist->GetEntries() >0)
517 float histMean = ampHist->GetMean();
518 float histRMS = ampHist->GetRMS();
519 float histRMSError = ampHist->GetRMSError();
521 float lowbound = histMean - 3*histRMS;
522 float highbound = histMean + 3*histRMS;
525 int result = ampHist->Fit(
"gaus",
"QL",
"",lowbound,highbound);
527 TF1 * fittedFunction = ampHist->GetFunction(
"gaus");
528 double meanError = fittedFunction->GetParError(1);
529 double sigma = fittedFunction->GetParameter(2);
530 double sigmaError = fittedFunction->GetParError(2);
531 double chi2 = fittedFunction->GetChisquare();
532 int ndf = fittedFunction->GetNDF();
542 int num = (
int)ampHist->GetEntries();
543 int thr = ampHist->GetNbinsX() + 1;
544 double maxSum = 0.001*
num;
549 sum += ampHist->GetBinContent(thr);
551 }
while ((thr>0)&&(
sum<maxSum));
554 double threshold = ampHist->GetXaxis()->GetBinLowEdge(thr) +1;
575 return StatusCode::SUCCESS;
595 return StatusCode::RECOVERABLE;
608 return StatusCode::RECOVERABLE;
616 out <<
"END_HEADER\n";
625 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr)
627 int hashId = (*pedItr)->hashId();
628 double ped = (*pedItr)->value();
629 double noise = (*noiseItr)->value();
630 double rms = (*rmsItr)->value();
635 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
645 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
649 out <<
" " << chamberHash;
659 return StatusCode::SUCCESS;
669 out.open(onlineFileName.c_str());
673 return StatusCode::RECOVERABLE;
689 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr, ++f001Itr)
691 int hashId = (*pedItr)->hashId();
692 double ped = (*pedItr)->value();
693 double noise = (*noiseItr)->value();
695 double f001 = (*f001Itr)->value();
698 std::string onlineHexId;
701 readCdo->indexToStringId(&
m_idHelperSvc->cscIdHelper(), hashId,
"CHANNEL", onlineHexId).ignore();
706 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
715 char orientationChar = (
m_idHelperSvc->cscIdHelper().measuresPhi(
id) ?
'Y':
'X');
719 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
722 out.setf(std::ios::right);
723 out << std::setfill(
'0') << std::setw(8) << onlineHexId;
725 << std::setw(2) << chamberHash << orientationChar << (
m_idHelperSvc->cscIdHelper().wireLayer(
id)-1)
727 << std::setw(3) <<
m_idHelperSvc->cscIdHelper().strip(
id) -1 <<
" " ;
728 out.setf(std::ios::fixed);
731 out <<
" " << std::setprecision(3) << std::setw(8) <<
ped <<
" 0000.00";
732 out <<
" " << std::setprecision(3) << std::setw(8) <<
noise <<
" 0000.000";
739 return StatusCode::SUCCESS;
750 return StatusCode::RECOVERABLE;
752 out <<
"03-00 <END_HEADER>";
759 out <<
"\n<END_FILE>";
762 return StatusCode::SUCCESS;
773 out <<
"<NEW_PAR> " <<
results.parName() <<
"\n";
774 std::string idString;
778 for(; resItr != resEnd; ++resItr){
779 unsigned int hashId = (*resItr)->hashId();
780 double value = (*resItr)->value();
781 std::string idString;
783 readCdo->indexToStringId(&
m_idHelperSvc->cscIdHelper(), hashId,
"CHANNEL", idString).ignore();
785 out << idString <<
" " <<
value <<
"\n";
799 bool thereIsAnError =
false;
801 std::string histKey =
"cscPedCalibReport";
802 ATH_MSG_DEBUG(
"Recording pedestal amplitude histograms to TDS with key " << histKey);
821 ATH_MSG_ERROR(
"Failed to record CscCalibReportPed to storegate");
822 thereIsAnError =
true;
829 std::string
key =
"CscCalibResultPed";
845 thereIsAnError =
true;
850 return StatusCode::RECOVERABLE;
852 return StatusCode::SUCCESS;
864 for(
unsigned int hashItr =0; hashItr <=
m_maxStripHash; hashItr++) {
868 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
870 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
875 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
876 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
877 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
878 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
882 std::stringstream
name;
883 name <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
884 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
885 std::stringstream
title;
886 title <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
887 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
895 (*correlations)[hashItr] = correlationHist;
899 double n = (*m_ampHists)[hashItr]->GetEntries();
900 TH1I * bitHist = (*m_bitHists)[hashItr];
901 TH2F * bitProds = (*m_bitProds)[hashItr];
902 for(
unsigned int bit1 = 1; bit1 <=
m_numBits; bit1++){
903 for(
unsigned int bit2 = 1; bit2 <=bit1; bit2++){
905 float xy = bitProds->GetBinContent(bit1,bit2);
906 float x = bitHist->GetBinContent(bit1);
907 float y = bitHist->GetBinContent(bit2);
917 correlationHist->SetBinContent(bit1,bit2,
r);
919 correlationHist->SetBinContent(bit2,bit1,
r);
933 int phi = ((onlineId >> 13)&0x7)+1;
934 int eta = ((((onlineId >> 12)&0
x1) == 1) ? 1:-1);
935 int chamLay = ((onlineId>>11)&0
x1) +1;
936 int wireLay = ((onlineId>>9)&0x3) +1;
937 int measuresPhi = ((onlineId >> 8)&0
x1);
941 if( measuresPhi && eta == 1){
942 strip = 48 - ((onlineId)&0xff) ;
945 strip = ((onlineId)&0xff) +1;
951 m_idHelperSvc->cscIdHelper().get_channel_hash(chanId, chanHash);
953 hashId = (
unsigned int)chanHash;