7#include "GaudiKernel/Chrono.h"
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;
143 int stationName =
m_idHelperSvc->cscIdHelper().stationName(stripId);
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;
353 StatusCode sc_read =
evtStore()->retrieve(rawDataContainer,
"CSCRDO");
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)
380 ATH_MSG_VERBOSE(
"There are " << rod->size() <<
" clusters in the ROD");
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++)
400 m_idHelperSvc->cscIdHelper().get_channel_hash(channelId, cscChannelHashId);
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)
415 <<
" " <<
m_idHelperSvc->cscIdHelper().show_to_string(channelId));
419 << stripHash <<
" " << cscChannelHashId);
423 << stripId <<
" " << channelId);
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;
612 out <<
m_peds->size() <<
" ";
616 out <<
"END_HEADER\n";
618 ATH_MSG_DEBUG(
"Begining loop over all " <<
m_peds->size() <<
" channels data was collected for.");
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();
632 ATH_MSG_DEBUG(
"we're on hash " << hashId <<
" with pedestal " << ped <<
"and noise " << noise);
635 m_idHelperSvc->cscIdHelper().get_id(hashId,
id, &channelContext);
645 m_idHelperSvc->cscIdHelper().get_module_hash(
id,chamberHash);
649 out <<
" " << chamberHash;
650 out <<
" " <<
m_idHelperSvc->cscIdHelper().show_to_string(
id) <<
" ";
659 return StatusCode::SUCCESS;
669 out.open(onlineFileName.c_str());
673 return StatusCode::RECOVERABLE;
678 ATH_MSG_DEBUG(
"Begining loop over all " <<
m_peds->size() <<
" channels data was collected for.");
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;
703 ATH_MSG_DEBUG(
"we're on hash " << hashId <<
" with pedestal " << ped <<
"and noise " << noise);
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;
785 out << idString <<
" " << value <<
"\n";
797 StatusCode
sc = StatusCode::SUCCESS;
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";
830 ATH_MSG_DEBUG(
"Recording calibration results to TDS with key " << key);
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);
873 int stationName =
m_idHelperSvc->cscIdHelper().stationName(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';
880 int sector = 2*stationPhi + 50 - stationName;
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;
889 TH2F* correlationHist =
new TH2F(
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);
910 float denom = (n*
x-
x*
x)*(n*
y-
y*
y);
914 r = (n*xy -
x*
y)/std::sqrt(denom);
917 correlationHist->SetBinContent(bit1,bit2,
r);
919 correlationHist->SetBinContent(bit2,bit1,
r);
932 int stationName = ((onlineId >> 16)&0x1) + 50;
933 int phi = ((onlineId >> 13)&0x7)+1;
934 int eta = ((((onlineId >> 12)&0x1) == 1) ? 1:-1);
935 int chamLay = ((onlineId>>11)&0x1) +1;
936 int wireLay = ((onlineId>>9)&0x3) +1;
937 int measuresPhi = ((onlineId >> 8)&0x1);
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;
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
void resize(size_type sz)
Resizes the collection to the specified number of elements.
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
DataVector< TH1I > * m_ampHists
unsigned int m_ampHistHighBound
DataVector< TH2F > * m_bitProds
DataVector< TH2F > * makeBitCorrelation()
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
DataVector< DataVector< TH1I > > * m_sampHists
std::string m_onlineDbFile
filename for file with online database information
DataVector< TH1I > * m_bitHists
unsigned int m_maxStripHash
Internally global variables.
void onlineToOfflineHashId(const unsigned int &onlineId, unsigned int &hashId) const
CscCalcPed(const std::string &name, ISvcLocator *pSvcLocator)
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()
SG::ReadCondHandleKey< CscCondDbData > m_readKey
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