7#include "GaudiKernel/Chrono.h"
68 ATH_MSG_FATAL(
"Either specify an OnlineCalibFile or set CompareOnlineCalibFile to false");
69 return StatusCode::FAILURE;
91 const std::vector<Identifier> &ids =
m_idHelperSvc->cscIdHelper().idVector();
96 for(
const auto &thisChamberId: ids)
98 std::vector<Identifier> stripVect;
99 m_idHelperSvc->cscIdHelper().idChannels(thisChamberId,stripVect);
103 for(
const auto & thisStrip: stripVect)
106 m_idHelperSvc->cscIdHelper().get_channel_hash(thisStrip,stripHash);
117 for(
unsigned int stripItr = 0 ; stripItr <=
m_maxStripHash; stripItr++)
123 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
125 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
128 int stationEta =
m_idHelperSvc->cscIdHelper().stationEta(stripId);
129 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
130 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
131 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
132 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
135 char name[30],titleSeed[600];
136 TH1I* hist =
nullptr;
138 int stationName =
m_idHelperSvc->cscIdHelper().stationName(stripId);
140 sprintf(name,
"ampHist%u",stripItr);
141 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d",
142 stationEta,(2*stationPhi+50 - stationName),wireLayer,orientation,stripNumber);
147 hist->GetXaxis()->SetTitle(
"Amplitude (ADC value)");
148 hist->GetYaxis()->SetTitle(
"Counts");
152 std::vector<TH1I*> tempVect;
154 sprintf(name,
"sampHist%u_%d",stripItr,cnt);
155 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d, sample %d",
156 stationEta,(2*stationPhi+50 - stationName),wireLayer,orientation,stripNumber,cnt);
160 tempVect.push_back(hist);
169 sprintf(name,
"bitHist%u",stripItr);
170 sprintf(titleSeed,
"Bit histogram for eta %d, sector %d, layer %d%c strip %d",
171 stationEta,(2*stationPhi+50 - stationName),wireLayer,orientation,stripNumber);
174 hist->GetXaxis()->SetTitle(
"Bit");
175 hist->GetYaxis()->SetTitle(
"Counts");
215 if(!ifile.is_open()){
217 return StatusCode::FAILURE;
221 unsigned int onlineId;
228 return StatusCode::FAILURE;
235 while(ifile >> std::hex >> onlineId >> std::dec) {
239 ifile >> buf >> buf >> buf >> buf >> rms >> buf >> f001;
240 double thold = f001 + 2*rms;
241 ATH_MSG_VERBOSE(
"onlid: " << std::hex << onlineId << std::dec <<
" hash: " << hashId <<
" rms: " << rms <<
" f001: " << f001 <<
" thold: " << thold);
250 if(chanCnt != 30720){
251 ATH_MSG_FATAL(
"Did not retrieve expected 30720 channels from online database! Retrieved: " << chanCnt);
252 ATH_MSG_FATAL(
"Last onlineId read: " << std::hex << onlineId << std::dec);
253 return StatusCode::FAILURE;
272 return StatusCode::SUCCESS;
284 ATH_MSG_ERROR(
"There was an error collecting information from the RDO this event.");
285 return StatusCode::RECOVERABLE;
288 return StatusCode::SUCCESS;
295 return StatusCode::FAILURE;
310 return StatusCode::FAILURE;
320 return StatusCode::FAILURE;
329 return StatusCode::FAILURE;
333 return StatusCode::SUCCESS;
348 StatusCode sc_read =
evtStore()->retrieve(rawDataContainer,
"CSCRDO");
349 if (sc_read != StatusCode::SUCCESS)
352 return StatusCode::FAILURE;
357 if(rawDataContainer->
size() == 0)
360 return StatusCode::FAILURE;
370 static const std::string rodChronoStr{
"RodItr"};
371 static const std::string clusterChronoStr{
"ClusterItr"};
372 static const std::string stripChronoStr{
"stripItr"};
373 static const std::string afterId1Str{
"afterID1"};
374 static const std::string afterId2Str{
"afterID2"};
376 for(
const auto rod : *rawDataContainer)
381 ATH_MSG_VERBOSE(
"There are " << rod->size() <<
" clusters in the ROD");
387 for(
const auto cluster: *rod)
390 int numStrips = cluster->width();
391 int samplesPerStrip = (cluster->samples()).size()/numStrips;
393 ATH_MSG_VERBOSE(
"About to collect info from " << numStrips <<
" strips");
394 for(
int stripItr = 0; stripItr <numStrips; stripItr++)
401 m_idHelperSvc->cscIdHelper().get_channel_hash(channelId, cscChannelHashId);
404 int stripHash = cscChannelHashId;
407 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
415 << stripHash <<
") from the wrong multilayer has appeared in the data. Its string id is " <<
m_idHelperSvc->cscIdHelper().show_to_string(stripId)
416 <<
" " <<
m_idHelperSvc->cscIdHelper().show_to_string(channelId));
420 << stripHash <<
" " << cscChannelHashId);
424 << stripId <<
" " << channelId);
436 m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, newHash );
455 std::vector<uint16_t> samples;
456 cluster->samples(stripItr,samplesPerStrip,samples);
462 for(
const auto & thisSample: samples)
469 TH2F* prodHist =
nullptr;
471 prodHist = (*m_bitProds)[stripHash];
481 " has online threshold breach. Sample: " << thisSample <<
" Thold: "
491 ATH_MSG_DEBUG(
"There is an empty rod (CscRawDataContainer).");
494 return StatusCode::SUCCESS;
507 for(
unsigned int stripHash = 0 ;stripHash <=
m_maxStripHash; stripHash++)
509 if(stripHash < 50 || stripHash%1000 == 0)
512 ATH_MSG_VERBOSE((
float)clock()/((
float)CLOCKS_PER_SEC) <<
" is the time");
519 if(ampHist->GetEntries() >0)
522 float histMean = ampHist->GetMean();
523 float histRMS = ampHist->GetRMS();
524 float histRMSError = ampHist->GetRMSError();
526 float lowbound = histMean - 3*histRMS;
527 float highbound = histMean + 3*histRMS;
530 int result = ampHist->Fit(
"gaus",
"QL",
"",lowbound,highbound);
532 TF1 * fittedFunction = ampHist->GetFunction(
"gaus");
533 double meanError = fittedFunction->GetParError(1);
534 double sigma = fittedFunction->GetParameter(2);
535 double sigmaError = fittedFunction->GetParError(2);
536 double chi2 = fittedFunction->GetChisquare();
537 int ndf = fittedFunction->GetNDF();
547 int num = (int)ampHist->GetEntries();
548 int thr = ampHist->GetNbinsX() + 1;
549 double maxSum = 0.001*num;
554 sum += ampHist->GetBinContent(thr);
556 }
while ((thr>0)&&(sum<maxSum));
559 double threshold = ampHist->GetXaxis()->GetBinLowEdge(thr) +1;
580 return StatusCode::SUCCESS;
600 return StatusCode::RECOVERABLE;
613 return StatusCode::RECOVERABLE;
617 out <<
m_peds->size() <<
" ";
621 out <<
"END_HEADER\n";
623 ATH_MSG_DEBUG(
"Begining loop over all " <<
m_peds->size() <<
" channels data was collected for.");
630 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr)
632 int hashId = (*pedItr)->hashId();
633 double ped = (*pedItr)->value();
634 double noise = (*noiseItr)->value();
635 double rms = (*rmsItr)->value();
637 ATH_MSG_DEBUG(
"we're on hash " << hashId <<
" with pedestal " << ped <<
"and noise " << noise);
640 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
650 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
654 out <<
" " << chamberHash;
655 out <<
" " <<
m_idHelperSvc->cscIdHelper().show_to_string(
id) <<
" ";
664 return StatusCode::SUCCESS;
674 out.open(onlineFileName.c_str());
678 return StatusCode::RECOVERABLE;
683 ATH_MSG_DEBUG(
"Begining loop over all " <<
m_peds->size() <<
" channels data was collected for.");
694 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr, ++f001Itr)
696 int hashId = (*pedItr)->hashId();
697 double ped = (*pedItr)->value();
698 double noise = (*noiseItr)->value();
700 double f001 = (*f001Itr)->value();
703 std::string onlineHexId;
708 ATH_MSG_DEBUG(
"we're on hash " << hashId <<
" with pedestal " << ped <<
"and noise " << noise);
711 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
720 char orientationChar = (
m_idHelperSvc->cscIdHelper().measuresPhi(
id) ?
'Y':
'X');
724 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
727 out.setf(std::ios::right);
728 out << std::setfill(
'0') << std::setw(8) << onlineHexId;
730 << std::setw(2) << chamberHash << orientationChar << (
m_idHelperSvc->cscIdHelper().wireLayer(
id)-1)
732 << std::setw(3) <<
m_idHelperSvc->cscIdHelper().strip(
id) -1 <<
" " ;
733 out.setf(std::ios::fixed);
736 out <<
" " << std::setprecision(3) << std::setw(8) << ped <<
" 0000.00";
737 out <<
" " << std::setprecision(3) << std::setw(8) << noise <<
" 0000.000";
744 return StatusCode::SUCCESS;
755 return StatusCode::RECOVERABLE;
757 out <<
"03-00 <END_HEADER>";
764 out <<
"\n<END_FILE>";
767 return StatusCode::SUCCESS;
778 out <<
"<NEW_PAR> " << results.parName() <<
"\n";
779 std::string idString;
783 for(; resItr != resEnd; ++resItr){
784 unsigned int hashId = (*resItr)->hashId();
785 double value = (*resItr)->value();
786 std::string idString;
790 out << idString <<
" " << value <<
"\n";
802 StatusCode
sc = StatusCode::SUCCESS;
804 bool thereIsAnError =
false;
806 std::string histKey =
"cscPedCalibReport";
807 ATH_MSG_DEBUG(
"Recording pedestal amplitude histograms to TDS with key " << histKey);
811 report->setPedAmpHists(std::move(
m_ampHists));
826 ATH_MSG_ERROR(
"Failed to record CscCalibReportPed to storegate");
827 thereIsAnError =
true;
834 std::string key =
"CscCalibResultPed";
835 ATH_MSG_DEBUG(
"Recording calibration results to TDS with key " << key);
850 thereIsAnError =
true;
855 return StatusCode::RECOVERABLE;
857 return StatusCode::SUCCESS;
863 std::vector<TH2F*> correlations;
869 for(
unsigned int hashItr =0; hashItr <=
m_maxStripHash; hashItr++) {
873 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
875 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
878 int stationName =
m_idHelperSvc->cscIdHelper().stationName(stripId);
880 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
881 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
882 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
883 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
885 int sector = 2*stationPhi + 50 - stationName;
887 std::stringstream name;
888 name <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
889 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
890 std::stringstream title;
891 title <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
892 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
894 TH2F* correlationHist =
new TH2F(
900 correlations[hashItr] = correlationHist;
906 TH2F * bitProds = (*m_bitProds)[hashItr];
907 for(
unsigned int bit1 = 1; bit1 <=
m_numBits; bit1++){
908 for(
unsigned int bit2 = 1; bit2 <=bit1; bit2++){
910 float xy = bitProds->GetBinContent(bit1,bit2);
911 float x = bitHist->GetBinContent(bit1);
912 float y = bitHist->GetBinContent(bit2);
915 float denom = (n*
x-
x*
x)*(n*
y-
y*
y);
919 r = (n*xy -
x*
y)/std::sqrt(denom);
922 correlationHist->SetBinContent(bit1,bit2,
r);
924 correlationHist->SetBinContent(bit2,bit1,
r);
937 int stationName = ((onlineId >> 16)&0x1) + 50;
938 int phi = ((onlineId >> 13)&0x7)+1;
939 int eta = ((((onlineId >> 12)&0x1) == 1) ? 1:-1);
940 int chamLay = ((onlineId>>11)&0x1) +1;
941 int wireLay = ((onlineId>>9)&0x3) +1;
942 int measuresPhi = ((onlineId >> 8)&0x1);
946 if( measuresPhi &&
eta == 1){
947 strip = 48 - ((onlineId)&0xff) ;
950 strip = ((onlineId)&0xff) +1;
956 m_idHelperSvc->cscIdHelper().get_channel_hash(chanId, chanHash);
958 hashId = (
unsigned int)chanHash;
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
StatusCode indexToStringId(const CscIdHelper *, const unsigned int &, std::string_view, std::string &) const
This container provides access to collections of CSC RDOs and a mechanism for recording them.
DataModel_detail::const_iterator< DataVector > const_iterator
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
size_t size() const
Duplicate of fullSize for backwards compatability.
This is a "hash" representation of an Identifier.
constexpr bool is_valid() const
std::string getString() const
Provide a string form of the identifier - hexadecimal.
std::string m_titlePostfix
CscCalibResultCollection * m_noises
CscCalibResultCollection * m_peds
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Services and tools.
unsigned int m_ampHistNumBins
SmartIF< IChronoStatSvc > m_chronoSvc
int m_expectedChamberLayer
unsigned int m_ampHistHighBound
DataVector< TH2F > * m_bitProds
StatusCode initialize(void)
basic required functions
StatusCode fillBitHist(TH1I *bitHist, const uint16_t &val, TH2F *bitProds)
const unsigned int m_numBits
StatusCode finalize(void)
StatusCode calculateParameters()
Finalize functions.
DataVector< TH1F > * m_bitCorrelation
StatusCode storeGateRecord()
CscCalibResultCollection * m_f001s
std::vector< std::vector< TH1I * > > m_sampHists
std::string m_onlineDbFile
filename for file with online database information
unsigned int m_maxStripHash
Internally global variables.
void onlineToOfflineHashId(const unsigned int &onlineId, unsigned int &hashId) const
CscCalcPed(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< TH1I * > m_bitHists
StatusCode collectEventInfo()
event loop functions
std::vector< int > m_onlineThresholdFailureCount
std::vector< int > m_onlineThresholds
std::string m_calOutputVersion
std::string m_titlePrefix
void outputParameter3(const CscCalibResultCollection &results, std::ofstream &out)
CscCalibResultCollection * m_onlineTHoldBreaches
float m_thresholdMultiplier
StatusCode writeCalibrationFile()
std::vector< TH2F * > makeBitCorrelation()
SG::ReadCondHandleKey< CscCondDbData > m_readKey
std::vector< TH1I * > m_ampHists
ToolHandle< Muon::ICSC_RDO_Decoder > m_cscRdoDecoderTool
unsigned int m_ampHistLowBound
CscCalibResultCollection * m_rmses
std::string m_outputFileName
Parameters input through joboptions.
double chi2(TH1 *h0, TH1 *h1)
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts