7 #include "GaudiKernel/Chrono.h"
33 m_bitCorrelation(nullptr),
38 m_onlineTHoldBreaches(nullptr),
40 m_crossTalkFix(nullptr)
73 ATH_MSG_FATAL(
"Either specify an OnlineCalibFile or set CompareOnlineCalibFile to false");
74 return StatusCode::FAILURE;
88 IToolSvc* toolSvc=
nullptr;
99 const std::vector<Identifier> &
ids =
m_idHelperSvc->cscIdHelper().idVector();
104 for(
const auto &thisChamberId:
ids)
106 std::vector<Identifier> stripVect;
107 m_idHelperSvc->cscIdHelper().idChannels(thisChamberId,stripVect);
111 for(
const auto & thisStrip: stripVect)
114 m_idHelperSvc->cscIdHelper().get_channel_hash(thisStrip,stripHash);
125 for(
unsigned int stripItr = 0 ; stripItr <=
m_maxStripHash; stripItr++)
131 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
133 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
136 int stationEta =
m_idHelperSvc->cscIdHelper().stationEta(stripId);
137 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
138 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
139 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
140 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
143 char name[30],titleSeed[600];
148 sprintf(
name,
"ampHist%u",stripItr);
149 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d",
150 stationEta,(2*stationPhi+50 -
stationName),wireLayer,orientation,stripNumber);
155 hist->GetXaxis()->SetTitle(
"Amplitude (ADC value)");
156 hist->GetYaxis()->SetTitle(
"Counts");
162 sprintf(
name,
"sampHist%u_%d",stripItr,
cnt);
163 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d, sample %d",
164 stationEta,(2*stationPhi+50 -
stationName),wireLayer,orientation,stripNumber,
cnt);
177 sprintf(
name,
"bitHist%u",stripItr);
178 sprintf(titleSeed,
"Bit histogram for eta %d, sector %d, layer %d%c strip %d",
179 stationEta,(2*stationPhi+50 -
stationName),wireLayer,orientation,stripNumber);
182 hist->GetXaxis()->SetTitle(
"Bit");
183 hist->GetYaxis()->SetTitle(
"Counts");
223 if(!
ifile.is_open()){
225 return StatusCode::FAILURE;
229 unsigned int onlineId;
236 return StatusCode::FAILURE;
243 while(
ifile >> std::hex >> onlineId >> std::dec) {
247 ifile >> buf >> buf >> buf >> buf >>
rms >> buf >> f001;
248 double thold = f001 + 2*
rms;
249 ATH_MSG_VERBOSE(
"onlid: " << std::hex << onlineId << std::dec <<
" hash: " << hashId <<
" rms: " <<
rms <<
" f001: " << f001 <<
" thold: " << thold);
258 if(chanCnt != 30720){
259 ATH_MSG_FATAL(
"Did not retrieve expected 30720 channels from online database! Retrieved: " << chanCnt);
260 ATH_MSG_FATAL(
"Last onlineId read: " << std::hex << onlineId << std::dec);
261 return StatusCode::FAILURE;
280 return StatusCode::SUCCESS;
292 ATH_MSG_ERROR(
"There was an error collecting information from the RDO this event.");
293 return StatusCode::RECOVERABLE;
296 return StatusCode::SUCCESS;
303 return StatusCode::FAILURE;
318 return StatusCode::FAILURE;
328 return StatusCode::FAILURE;
337 return StatusCode::FAILURE;
341 return StatusCode::SUCCESS;
357 if (sc_read != StatusCode::SUCCESS)
360 return StatusCode::FAILURE;
365 if(rawDataContainer->
size() == 0)
368 return StatusCode::FAILURE;
378 for(
const auto rod : *rawDataContainer)
389 for(
const auto cluster: *
rod)
392 int numStrips = cluster->width();
393 int samplesPerStrip = (cluster->samples()).
size()/numStrips;
395 ATH_MSG_VERBOSE(
"About to collect info from " << numStrips <<
" strips");
396 for(
int stripItr = 0; stripItr <numStrips; stripItr++)
406 int stripHash = cscChannelHashId;
409 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
417 << stripHash <<
") from the wrong multilayer has appeared in the data. Its string id is " <<
m_idHelperSvc->cscIdHelper().show_to_string(stripId)
422 << stripHash <<
" " << cscChannelHashId);
438 m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, newHash );
454 cluster->samples(stripItr,samplesPerStrip,
samples);
460 for(
const auto & thisSample:
samples)
462 (*m_ampHists)[stripHash]->Fill(thisSample);
464 (*((*m_sampHists)[stripHash]))[sampCnt]->Fill(thisSample);
467 TH2F* prodHist =
nullptr;
469 prodHist = (*m_bitProds)[stripHash];
479 " has online threshold breach. Sample: " << thisSample <<
" Thold: "
489 ATH_MSG_DEBUG(
"There is an empty rod (CscRawDataContainer).");
492 return StatusCode::SUCCESS;
505 for(
unsigned int stripHash = 0 ;stripHash <=
m_maxStripHash; stripHash++)
507 if(stripHash < 50 || stripHash%1000 == 0)
510 ATH_MSG_VERBOSE((
float)clock()/((
float)CLOCKS_PER_SEC) <<
" is the time");
513 TH1I * ampHist = (*m_ampHists)[stripHash];
517 if(ampHist->GetEntries() >0)
520 float histMean = ampHist->GetMean();
521 float histRMS = ampHist->GetRMS();
522 float histRMSError = ampHist->GetRMSError();
524 float lowbound = histMean - 3*histRMS;
525 float highbound = histMean + 3*histRMS;
528 int result = ampHist->Fit(
"gaus",
"QL",
"",lowbound,highbound);
530 TF1 * fittedFunction = ampHist->GetFunction(
"gaus");
531 double meanError = fittedFunction->GetParError(1);
532 double sigma = fittedFunction->GetParameter(2);
533 double sigmaError = fittedFunction->GetParError(2);
534 double chi2 = fittedFunction->GetChisquare();
535 int ndf = fittedFunction->GetNDF();
545 int num = (
int)ampHist->GetEntries();
546 int thr = ampHist->GetNbinsX() + 1;
547 double maxSum = 0.001*
num;
554 }
while ((thr>0)&&(
sum<maxSum));
557 double threshold = ampHist->GetXaxis()->GetBinLowEdge(thr) +1;
578 return StatusCode::SUCCESS;
598 return StatusCode::RECOVERABLE;
611 return StatusCode::RECOVERABLE;
619 out <<
"END_HEADER\n";
628 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr)
630 int hashId = (*pedItr)->hashId();
631 double ped = (*pedItr)->value();
632 double noise = (*noiseItr)->value();
633 double rms = (*rmsItr)->value();
638 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
648 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
652 out <<
" " << chamberHash;
662 return StatusCode::SUCCESS;
672 out.open(onlineFileName.c_str());
676 return StatusCode::RECOVERABLE;
692 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr, ++f001Itr)
694 int hashId = (*pedItr)->hashId();
695 double ped = (*pedItr)->value();
696 double noise = (*noiseItr)->value();
698 double f001 = (*f001Itr)->value();
701 std::string onlineHexId;
704 readCdo->indexToStringId(&
m_idHelperSvc->cscIdHelper(), hashId,
"CHANNEL", onlineHexId).ignore();
709 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
718 char orientationChar = (
m_idHelperSvc->cscIdHelper().measuresPhi(
id) ?
'Y':
'X');
722 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
725 out.setf(std::ios::right);
726 out << std::setfill(
'0') << std::setw(8) << onlineHexId;
728 << std::setw(2) << chamberHash << orientationChar << (
m_idHelperSvc->cscIdHelper().wireLayer(
id)-1)
730 << std::setw(3) <<
m_idHelperSvc->cscIdHelper().strip(
id) -1 <<
" " ;
731 out.setf(std::ios::fixed);
734 out <<
" " << std::setprecision(3) << std::setw(8) <<
ped <<
" 0000.00";
735 out <<
" " << std::setprecision(3) << std::setw(8) <<
noise <<
" 0000.000";
742 return StatusCode::SUCCESS;
753 return StatusCode::RECOVERABLE;
755 out <<
"03-00 <END_HEADER>";
762 out <<
"\n<END_FILE>";
765 return StatusCode::SUCCESS;
776 out <<
"<NEW_PAR> " <<
results.parName() <<
"\n";
777 std::string idString;
781 for(; resItr != resEnd; ++resItr){
782 unsigned int hashId = (*resItr)->hashId();
783 double value = (*resItr)->value();
784 std::string idString;
786 readCdo->indexToStringId(&
m_idHelperSvc->cscIdHelper(), hashId,
"CHANNEL", idString).ignore();
788 out << idString <<
" " <<
value <<
"\n";
802 bool thereIsAnError =
false;
804 std::string histKey =
"cscPedCalibReport";
805 ATH_MSG_DEBUG(
"Recording pedestal amplitude histograms to TDS with key " << histKey);
824 ATH_MSG_ERROR(
"Failed to record CscCalibReportPed to storegate");
825 thereIsAnError =
true;
832 std::string
key =
"CscCalibResultPed";
848 thereIsAnError =
true;
853 return StatusCode::RECOVERABLE;
855 return StatusCode::SUCCESS;
867 for(
unsigned int hashItr =0; hashItr <=
m_maxStripHash; hashItr++) {
871 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
873 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
878 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
879 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
880 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
881 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
885 std::stringstream
name;
886 name <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
887 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
888 std::stringstream
title;
889 title <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
890 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
898 (*correlations)[hashItr] = correlationHist;
902 double n = (*m_ampHists)[hashItr]->GetEntries();
903 TH1I * bitHist = (*m_bitHists)[hashItr];
904 TH2F * bitProds = (*m_bitProds)[hashItr];
905 for(
unsigned int bit1 = 1; bit1 <=
m_numBits; bit1++){
906 for(
unsigned int bit2 = 1; bit2 <=bit1; bit2++){
936 int phi = ((onlineId >> 13)&0x7)+1;
937 int eta = ((((onlineId >> 12)&0
x1) == 1) ? 1:-1);
938 int chamLay = ((onlineId>>11)&0
x1) +1;
939 int wireLay = ((onlineId>>9)&0x3) +1;
940 int measuresPhi = ((onlineId >> 8)&0
x1);
944 if( measuresPhi &&
eta == 1){
945 strip = 48 - ((onlineId)&0xff) ;
948 strip = ((onlineId)&0xff) +1;
954 m_idHelperSvc->cscIdHelper().get_channel_hash(chanId, chanHash);
956 hashId = (
unsigned int)chanHash;