7#include "GaudiKernel/Chrono.h"
69 ATH_MSG_FATAL(
"Either specify an OnlineCalibFile or set CompareOnlineCalibFile to false");
70 return StatusCode::FAILURE;
92 const std::vector<Identifier> &ids =
m_idHelperSvc->cscIdHelper().idVector();
97 for(
const auto &thisChamberId: ids)
99 std::vector<Identifier> stripVect;
100 m_idHelperSvc->cscIdHelper().idChannels(thisChamberId,stripVect);
104 for(
const auto & thisStrip: stripVect)
107 m_idHelperSvc->cscIdHelper().get_channel_hash(thisStrip,stripHash);
118 for(
unsigned int stripItr = 0 ; stripItr <=
m_maxStripHash; stripItr++)
124 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
126 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
129 int stationEta =
m_idHelperSvc->cscIdHelper().stationEta(stripId);
130 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
131 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
132 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
133 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
136 char name[30],titleSeed[600];
137 TH1I* hist =
nullptr;
139 int stationName =
m_idHelperSvc->cscIdHelper().stationName(stripId);
141 sprintf(name,
"ampHist%u",stripItr);
142 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d",
143 stationEta,(2*stationPhi+50 - stationName),wireLayer,orientation,stripNumber);
148 hist->GetXaxis()->SetTitle(
"Amplitude (ADC value)");
149 hist->GetYaxis()->SetTitle(
"Counts");
153 std::vector<TH1I*> tempVect;
155 sprintf(name,
"sampHist%u_%d",stripItr,cnt);
156 sprintf(titleSeed,
"Amplitude Histogram for eta %d, sector %d, layer %d%c, strip %d, sample %d",
157 stationEta,(2*stationPhi+50 - stationName),wireLayer,orientation,stripNumber,cnt);
161 tempVect.push_back(hist);
170 sprintf(name,
"bitHist%u",stripItr);
171 sprintf(titleSeed,
"Bit histogram for eta %d, sector %d, layer %d%c strip %d",
172 stationEta,(2*stationPhi+50 - stationName),wireLayer,orientation,stripNumber);
175 hist->GetXaxis()->SetTitle(
"Bit");
176 hist->GetYaxis()->SetTitle(
"Counts");
216 if(!ifile.is_open()){
218 return StatusCode::FAILURE;
222 unsigned int onlineId;
229 return StatusCode::FAILURE;
236 while(ifile >> std::hex >> onlineId >> std::dec) {
240 ifile >> buf >> buf >> buf >> buf >> rms >> buf >> f001;
241 double thold = f001 + 2*rms;
242 ATH_MSG_VERBOSE(
"onlid: " << std::hex << onlineId << std::dec <<
" hash: " << hashId <<
" rms: " << rms <<
" f001: " << f001 <<
" thold: " << thold);
251 if(chanCnt != 30720){
252 ATH_MSG_FATAL(
"Did not retrieve expected 30720 channels from online database! Retrieved: " << chanCnt);
253 ATH_MSG_FATAL(
"Last onlineId read: " << std::hex << onlineId << std::dec);
254 return StatusCode::FAILURE;
273 return StatusCode::SUCCESS;
285 ATH_MSG_ERROR(
"There was an error collecting information from the RDO this event.");
286 return StatusCode::RECOVERABLE;
289 return StatusCode::SUCCESS;
296 return StatusCode::FAILURE;
311 return StatusCode::FAILURE;
321 return StatusCode::FAILURE;
330 return StatusCode::FAILURE;
334 return StatusCode::SUCCESS;
349 StatusCode sc_read =
evtStore()->retrieve(rawDataContainer,
"CSCRDO");
350 if (sc_read != StatusCode::SUCCESS)
353 return StatusCode::FAILURE;
358 if(rawDataContainer->
size() == 0)
361 return StatusCode::FAILURE;
371 for(
const auto rod : *rawDataContainer)
376 ATH_MSG_VERBOSE(
"There are " << rod->size() <<
" clusters in the ROD");
382 for(
const auto cluster: *rod)
385 int numStrips = cluster->width();
386 int samplesPerStrip = (cluster->samples()).size()/numStrips;
388 ATH_MSG_VERBOSE(
"About to collect info from " << numStrips <<
" strips");
389 for(
int stripItr = 0; stripItr <numStrips; stripItr++)
396 m_idHelperSvc->cscIdHelper().get_channel_hash(channelId, cscChannelHashId);
399 int stripHash = cscChannelHashId;
402 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
410 << stripHash <<
") from the wrong multilayer has appeared in the data. Its string id is " <<
m_idHelperSvc->cscIdHelper().show_to_string(stripId)
411 <<
" " <<
m_idHelperSvc->cscIdHelper().show_to_string(channelId));
415 << stripHash <<
" " << cscChannelHashId);
419 << stripId <<
" " << channelId);
431 m_idHelperSvc->cscIdHelper().get_channel_hash(stripId, newHash );
446 std::vector<uint16_t> samples;
447 cluster->samples(stripItr,samplesPerStrip,samples);
453 for(
const auto & thisSample: samples)
460 TH2F* prodHist =
nullptr;
462 prodHist = (*m_bitProds)[stripHash];
472 " has online threshold breach. Sample: " << thisSample <<
" Thold: "
482 ATH_MSG_DEBUG(
"There is an empty rod (CscRawDataContainer).");
485 return StatusCode::SUCCESS;
498 for(
unsigned int stripHash = 0 ;stripHash <=
m_maxStripHash; stripHash++)
500 if(stripHash < 50 || stripHash%1000 == 0)
503 ATH_MSG_VERBOSE((
float)clock()/((
float)CLOCKS_PER_SEC) <<
" is the time");
510 if(ampHist->GetEntries() >0)
513 float histMean = ampHist->GetMean();
514 float histRMS = ampHist->GetRMS();
515 float histRMSError = ampHist->GetRMSError();
517 float lowbound = histMean - 3*histRMS;
518 float highbound = histMean + 3*histRMS;
521 int result = ampHist->Fit(
"gaus",
"QL",
"",lowbound,highbound);
523 TF1 * fittedFunction = ampHist->GetFunction(
"gaus");
524 double meanError = fittedFunction->GetParError(1);
525 double sigma = fittedFunction->GetParameter(2);
526 double sigmaError = fittedFunction->GetParError(2);
527 double chi2 = fittedFunction->GetChisquare();
528 int ndf = fittedFunction->GetNDF();
538 int num = (int)ampHist->GetEntries();
539 int thr = ampHist->GetNbinsX() + 1;
540 double maxSum = 0.001*num;
545 sum += ampHist->GetBinContent(thr);
547 }
while ((thr>0)&&(sum<maxSum));
550 double threshold = ampHist->GetXaxis()->GetBinLowEdge(thr) +1;
571 return StatusCode::SUCCESS;
591 return StatusCode::RECOVERABLE;
604 return StatusCode::RECOVERABLE;
608 out <<
m_peds->size() <<
" ";
612 out <<
"END_HEADER\n";
614 ATH_MSG_DEBUG(
"Begining loop over all " <<
m_peds->size() <<
" channels data was collected for.");
621 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr)
623 int hashId = (*pedItr)->hashId();
624 double ped = (*pedItr)->value();
625 double noise = (*noiseItr)->value();
626 double rms = (*rmsItr)->value();
628 ATH_MSG_DEBUG(
"we're on hash " << hashId <<
" with pedestal " << ped <<
"and noise " << noise);
631 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
641 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
645 out <<
" " << chamberHash;
646 out <<
" " <<
m_idHelperSvc->cscIdHelper().show_to_string(
id) <<
" ";
655 return StatusCode::SUCCESS;
665 out.open(onlineFileName.c_str());
669 return StatusCode::RECOVERABLE;
674 ATH_MSG_DEBUG(
"Begining loop over all " <<
m_peds->size() <<
" channels data was collected for.");
685 for(;pedItr!= pedEnd;++pedItr,++noiseItr, ++rmsItr, ++f001Itr)
687 int hashId = (*pedItr)->hashId();
688 double ped = (*pedItr)->value();
689 double noise = (*noiseItr)->value();
691 double f001 = (*f001Itr)->value();
694 std::string onlineHexId;
699 ATH_MSG_DEBUG(
"we're on hash " << hashId <<
" with pedestal " << ped <<
"and noise " << noise);
702 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
711 char orientationChar = (
m_idHelperSvc->cscIdHelper().measuresPhi(
id) ?
'Y':
'X');
715 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
718 out.setf(std::ios::right);
719 out << std::setfill(
'0') << std::setw(8) << onlineHexId;
721 << std::setw(2) << chamberHash << orientationChar << (
m_idHelperSvc->cscIdHelper().wireLayer(
id)-1)
723 << std::setw(3) <<
m_idHelperSvc->cscIdHelper().strip(
id) -1 <<
" " ;
724 out.setf(std::ios::fixed);
727 out <<
" " << std::setprecision(3) << std::setw(8) << ped <<
" 0000.00";
728 out <<
" " << std::setprecision(3) << std::setw(8) << noise <<
" 0000.000";
735 return StatusCode::SUCCESS;
746 return StatusCode::RECOVERABLE;
748 out <<
"03-00 <END_HEADER>";
755 out <<
"\n<END_FILE>";
758 return StatusCode::SUCCESS;
769 out <<
"<NEW_PAR> " << results.parName() <<
"\n";
770 std::string idString;
774 for(; resItr != resEnd; ++resItr){
775 unsigned int hashId = (*resItr)->hashId();
776 double value = (*resItr)->value();
777 std::string idString;
781 out << idString <<
" " << value <<
"\n";
793 StatusCode
sc = StatusCode::SUCCESS;
795 bool thereIsAnError =
false;
797 std::string histKey =
"cscPedCalibReport";
798 ATH_MSG_DEBUG(
"Recording pedestal amplitude histograms to TDS with key " << histKey);
802 report->setPedAmpHists(std::move(
m_ampHists));
817 ATH_MSG_ERROR(
"Failed to record CscCalibReportPed to storegate");
818 thereIsAnError =
true;
825 std::string key =
"CscCalibResultPed";
826 ATH_MSG_DEBUG(
"Recording calibration results to TDS with key " << key);
841 thereIsAnError =
true;
846 return StatusCode::RECOVERABLE;
848 return StatusCode::SUCCESS;
854 std::vector<TH2F*> correlations;
860 for(
unsigned int hashItr =0; hashItr <=
m_maxStripHash; hashItr++) {
864 m_idHelperSvc->cscIdHelper().get_id(stripHash, stripId, &channelContext);
866 int chamLayer =
m_idHelperSvc->cscIdHelper().chamberLayer(stripId);
869 int stationName =
m_idHelperSvc->cscIdHelper().stationName(stripId);
871 int stationPhi =
m_idHelperSvc->cscIdHelper().stationPhi(stripId);
872 int stripNumber =
m_idHelperSvc->cscIdHelper().strip(stripId);
873 int wireLayer =
m_idHelperSvc->cscIdHelper().wireLayer(stripId);
874 char orientation =
m_idHelperSvc->cscIdHelper().measuresPhi(stripId) ?
'Y':
'X';
876 int sector = 2*stationPhi + 50 - stationName;
878 std::stringstream name;
879 name <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
880 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
881 std::stringstream title;
882 title <<
"h_bitCorr_sector_" << std::setfill(
'0') << std::setw(2) << sector <<
883 "_lay_" << wireLayer << orientation <<
"_strip_" << std::setw(3) << stripNumber;
885 TH2F* correlationHist =
new TH2F(
891 correlations[hashItr] = correlationHist;
897 TH2F * bitProds = (*m_bitProds)[hashItr];
898 for(
unsigned int bit1 = 1; bit1 <=
m_numBits; bit1++){
899 for(
unsigned int bit2 = 1; bit2 <=bit1; bit2++){
901 float xy = bitProds->GetBinContent(bit1,bit2);
902 float x = bitHist->GetBinContent(bit1);
903 float y = bitHist->GetBinContent(bit2);
906 float denom = (n*
x-
x*
x)*(n*
y-
y*
y);
910 r = (n*xy -
x*
y)/std::sqrt(denom);
913 correlationHist->SetBinContent(bit1,bit2,
r);
915 correlationHist->SetBinContent(bit2,bit1,
r);
928 int stationName = ((onlineId >> 16)&0x1) + 50;
929 int phi = ((onlineId >> 13)&0x7)+1;
930 int eta = ((((onlineId >> 12)&0x1) == 1) ? 1:-1);
931 int chamLay = ((onlineId>>11)&0x1) +1;
932 int wireLay = ((onlineId>>9)&0x3) +1;
933 int measuresPhi = ((onlineId >> 8)&0x1);
937 if( measuresPhi &&
eta == 1){
938 strip = 48 - ((onlineId)&0xff) ;
941 strip = ((onlineId)&0xff) +1;
947 m_idHelperSvc->cscIdHelper().get_channel_hash(chanId, chanHash);
949 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 &, const std::string &, 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.
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