23 ATH_MSG_DEBUG(
"==== LArRampBuilder - looking at SuperCells ====");
25 sc =
detStore()->retrieve(ll,
"LArOnline_SuperCellID");
27 msg(MSG::ERROR) <<
"Could not get LArOnlineID helper !" <<
endmsg;
28 return StatusCode::FAILURE;
39 msg(MSG::ERROR) <<
"Could not get LArOnlineID helper !" <<
endmsg;
40 return StatusCode::FAILURE;
57 m_ramps=std::make_unique<LArConditionsContainer<ACCRAMP> >();
67 return StatusCode::SUCCESS;
77 if (
sc!=StatusCode::SUCCESS) {
81 ATH_MSG_DEBUG(
"LArParabolaPeakRecoTool retrieved with success!");
86 if (
detStore()->retrieve (idHelper,
"CaloCell_ID").isSuccess() ) {
105 ATH_MSG_DEBUG(
"LArShapePeakRecoTool retrieved with success!");
131 ATH_MSG_ERROR(
"Key list is empty! No containers to process!");
132 return StatusCode::FAILURE;
138 if (
sc.isFailure()) {
139 ATH_MSG_ERROR(
"Failed to retrieve FebErrorSummary object!");
145 ATH_MSG_WARNING(
"No FebErrorSummaryObject found! Feb errors not checked!");
150 cabling = {*cablingHdl};
153 return StatusCode::FAILURE;
157 cabling = {*cablingHdl};
160 return StatusCode::FAILURE;
165 std::vector<std::string>::const_iterator key_it=
m_keylist.begin();
166 std::vector<std::string>::const_iterator key_it_e=
m_keylist.end();
178 std::vector<double> tempWave;
179 int NSamplesKeep = 8;
180 tempWave.resize(24*NSamplesKeep);
191 sc=
detStore()->retrieve(caliWaveContainer,
"CaliWave");
192 if (
sc.isFailure()) {
193 ATH_MSG_WARNING(
"Cannot read LArCaliWaveContainer from StoreGate for key 'CaliWave' ! ");
194 return StatusCode::FAILURE;
196 ATH_MSG_DEBUG(
"Succefully retrieved LArCaliWaveContainer from StoreGate!");
197 for (;key_it!=key_it_e;++key_it) {
201 if(*key_it ==
"HIGH") {
203 }
else if(*key_it ==
"MEDIUM") {
205 }
else if(*key_it ==
"LOW") {
225 for (; itVec != itVec_e; ++itVec) {
228 unsigned int DAC = larCaliWave.getDAC();
232 for(
int i=0;i<24*NSamplesKeep;i++){
233 tempWave[i] = larCaliWave.getSample(i);
234 if(tempWave[i]<-500) {
242 m_CaliWaves[gainref][chidwave_hash].push_back(tempWave);
243 m_CaliDACs[gainref][chidwave_hash].push_back(DAC);
258 if (
sc.isFailure()) {
259 ATH_MSG_WARNING(
"Cannot remove LArCaliWaveContainer from StoreGate ! ");
260 return StatusCode::FAILURE;
262 ATH_MSG_DEBUG(
"Successfully removed LArCaliWaveContainer from StoreGate ");
271 for (;key_it!=key_it_e;++key_it) {
273 sc=
evtStore()->retrieve(larAccumulatedCalibDigitContainer,*key_it);
274 if (
sc.isFailure()) {
275 ATH_MSG_WARNING(
"Cannot read LArAccumulatedCalibDigitContainer from StoreGate! key=" << *key_it);
276 if ( (std::next(key_it) == key_it_e) && foundkey==0 ){
277 ATH_MSG_ERROR(
"None of the provided LArAccumulatedDigitContainer keys could be read");
278 return StatusCode::FAILURE;
286 if(larAccumulatedCalibDigitContainer->
empty()) {
287 ATH_MSG_DEBUG(
"LArAccumulatedCalibDigitContainer with key=" << *key_it <<
" is empty ");
289 ATH_MSG_DEBUG(
"LArAccumulatedCalibDigitContainer with key=" << *key_it <<
" has size " << larAccumulatedCalibDigitContainer->
size());
294 if (!(digit->isPulsed())){
301 const uint16_t febErrs=febErrSum->
feb_error(febid);
303 if (febid!=lastFailedFEB) {
306 <<
" reports error(s):" << febErrSum->
error_to_string(febErrs) <<
". Data ignored.");
324 {
ATH_MSG_ERROR(
"Found not-matching gain number ("<< (
int)gain <<
")");
325 return StatusCode::FAILURE;
338 if (
sc.isFailure()) {
339 ATH_MSG_FATAL(
"No pedestals found in database. Aborting executiong." );
344 float DBpedestal = larPedestal->
pedestal(chid,gain);
350 <<
". Skipping channel."
357 <<
". Skipping channel."
371 ATH_MSG_ERROR(
"Failed to accumulate sub-steps: Inconsistent number of ADC samples");
374 ATH_MSG_ERROR(
"Failed to accumulate sub-steps: Numeric Overflow");
379 return StatusCode::SUCCESS;
396 std::unique_ptr<LArRampComplete> larRampComplete;
398 larRampComplete=std::make_unique<LArRampComplete>();
400 ATH_CHECK(larRampComplete->initialize());
407 cabling = {*cablingHdl};
410 return StatusCode::FAILURE;
415 cabling = {*cablingHdl};
418 return StatusCode::FAILURE;
428 int containerCounter=0;
436 if (cell_it==cell_it_e) {
437 ATH_MSG_INFO(
"No ramp points found for gain " << gain);
441 std::unique_ptr<LArRawRampContainer> larRawRampContainer;
443 larRawRampContainer=std::make_unique<LArRawRampContainer>();
447 for (;cell_it!=cell_it_e;cell_it++){
451 ACCRAMP::const_iterator dac_it=cell_it->begin();
452 ACCRAMP::const_iterator dac_it_e=cell_it->end();
453 auto rawramp=std::make_unique<LArRawRamp>(chid,gain);
455 std::vector<float> peak;
456 float adcpeak, timepeak;
457 std::vector<float> adc0v;
458 bool isADCsat =
false;
463 for (;dac_it!=dac_it_e;++dac_it) {
476 if(dac_it!=cell_it->begin())
477 ATH_MSG_ERROR(
"DAC0 is not the first DAC ? This might be a problem... " );
478 adc0v = dac_it->second.mean();
480 ramppoint.
RMS = dac_it->second.RMS();
481 ramppoint.
NTriggers = dac_it->second.nTriggers();
483 const size_t nS=dac_it->second.nsamples();
484 adc0v.resize(nS,0.0);
486 ramppoint.
RMS.resize(nS);
487 ramppoint.
NTriggers = dac_it->second.nTriggers();
488 for(
size_t k=0;k<nS;++k){
489 ramppoint.
Samples[k]=dac_it->second.mean(k) - adc0v[k];
490 ramppoint.
RMS[k]=dac_it->second.RMS(k);
492 if(ramppoint.
Samples[k]>MaxADC){
503 for (
size_t k=0;k<ramppoint.
Samples.size();++k) {
510 unsigned kMax = max_element(ramppoint.
Samples.begin(),ramppoint.
Samples.end()) - ramppoint.
Samples.begin() ;
514 if ( kMax < 2 || kMax+2 >= ramppoint.
Samples.size() ) {
519 if (cabling->isOnlineConnected(chid) && isgood) {
522 <<
", Amp[2]=" << ramppoint.
Samples[2] <<
" )" );
523 if (
msgLvl(MSG::VERBOSE)) {
524 msg(MSG::VERBOSE) <<
" Samples: ";
525 for (
unsigned k=0;k<ramppoint.
Samples.size();k++)
553 if (results.getValid()) {
554 adcpeak = results.getAmplitude();
555 timepeak = results.getTau();
558 ATH_MSG_ERROR(
"LArOFPeak reco tool returns invalid result.");
569 unsigned int GoodIndex = 9999;
570 for(
unsigned int i=0;i<
m_CaliDACs[gain][chid_hash].size();i++){
571 if(dac_it->first ==
m_CaliDACs[gain][chid_hash][i]) GoodIndex=i;
573 if(GoodIndex == 9999) {
574 ATH_MSG_WARNING(
"No wave found for cell = " << chid_hash <<
", DAC = " << dac_it->first);
576 for(
unsigned int i=0;i<
m_CaliDACs[gain][chid_hash].size();i++){
577 int dacdiff = dac_it->first -
m_CaliDACs[gain][chid_hash][i];
587 for(
unsigned int k=0;k<
m_CaliWaves[gain][chid_hash][GoodIndex].size();k++){
597 peak.push_back(-999);
598 peak.push_back(-999);
614 int layer=
m_emId->sampling(
id);
626 ATH_MSG_ERROR(
"Both OF and Parabola reconstruction modes not available!" ) ;
627 return StatusCode::FAILURE ;
630 ramppoint.
ADC = adcpeak;
631 ramppoint.
DAC = dac_it->first;
635 const float rinjval = rinj->
Rinj(chid);
636 if(rinjval < 4) ramppoint.
DAC /= 2;
646 if( (dac_it->first>=
m_minDAC) && ramppoint.
ADC > -998
648 rawramp->add(ramppoint);
652 if(ramppoint.
DAC < 200){
663 if (larRampComplete) {
664 std::vector<LArRawRamp::RAMPPOINT_t>&
data=rawramp->theRamp();
666 std::vector<float> rampCoeffs;
667 std::vector<int> vSat;
669 if (
sc!=StatusCode::SUCCESS){
670 if (!cabling->isOnlineConnected(chid))
679 ATH_MSG_ERROR(
"Negative 1rst order coef for ramp = " << rampCoeffs[1] <<
" for channel "
682 if (vSat[0] != -1) { rawramp->setsat(vSat[0]); }
684 if (isADCsat) { rawramp->setsat(
data.size()-1); }
685 if (!isADCsat) { rawramp->setsat(
data.size()); }
689 larRampComplete->set(chid,(
int)gain,rampCoeffs);
694 if (larRawRampContainer){
695 larRawRampContainer->push_back(std::move(rawramp));
699 if (larRawRampContainer) {
716 ATH_MSG_INFO(
"Recording LArRawRampContainer for gain " << (
int)gain <<
" key=" << key);
717 sc=
detStore()->record(std::move(larRawRampContainer),key);
718 if (
sc.isFailure()) {
725 if (containerCounter==0) {
727 return StatusCode::FAILURE;
730 if (larRampComplete){
732 ATH_MSG_INFO(
" Summary : Number of cells with a ramp value computed : " << NRamp );
733 ATH_MSG_INFO(
" Summary : Number of Barrel PS cells side A or C (connected+unconnected): 3904+ 192 = 4096 ");
734 ATH_MSG_INFO(
" Summary : Number of Barrel cells side A or C (connected+unconnected): 50944+2304 = 53248 ");
735 ATH_MSG_INFO(
" Summary : Number of EMEC cells side A or C (connected+unconnected): 31872+3456 = 35328 ");
736 ATH_MSG_INFO(
" Summary : Number of HEC cells side A or C (connected+unconnected): 2816+ 256 = 3072 ");
737 ATH_MSG_INFO(
" Summary : Number of FCAL cells side A or C (connected+unconnected): 1762+ 30 = 1792 ");
741 if (
sc.isFailure()) {
745 if (
sc.isFailure()) {
751 return StatusCode::SUCCESS;
756 std::vector<float>& rampCoeffs, std::vector<int>& vSat,
759 unsigned linRange=
data.size();
763 if (cabling->isOnlineConnected(chid) && isgood ) {
764 ATH_MSG_ERROR(
"Not enough datapoints (" << linRange <<
") to fit a polynom!" );
765 return StatusCode::FAILURE;
768 ATH_MSG_DEBUG(
"Not enough datapoints (" << linRange <<
") to fit a polynom for a disconnected or known bad channel!" );
769 return StatusCode::FAILURE;
775 float thisslope = 0., meanslope = 0.;
776 std::vector<float> accslope;
777 accslope.push_back(0);
778 for (
unsigned int DACIndex=1;DACIndex<linRange;DACIndex++){
779 thisslope = (
data[DACIndex].ADC -
data[DACIndex-1].ADC)/(
data[DACIndex].DAC -
data[DACIndex-1].DAC);
784 }
else { scut = meanslope/10.;}
785 if ( (satpoint == -1) && ((meanslope-thisslope) > scut) ) {
793 meanslope = ( thisslope + (DACIndex-1)*(accslope[DACIndex-1]) )/DACIndex;
794 accslope.push_back(meanslope);
798 if (satpoint != -1) { linRange = satpoint; }
801 vSat.push_back(satpoint);
809 if (cabling->isOnlineConnected(chid) && isgood )
813 <<
" (channel disconnected or known to be bad)");
815 return StatusCode::FAILURE;
820 <<
". Dead channel?" );
821 return StatusCode::FAILURE;
827 Eigen::MatrixXd alpha(
deg,
deg);
828 Eigen::VectorXd beta(
deg);
830 for (
unsigned k=0;k<
deg;k++)
831 for (
unsigned j=0;j<=k;j++)
834 for (
unsigned i=begin;i<linRange;i++)
845 if (
data[i].NTriggers ) {
847 sigma2 = 100./
data[i].NTriggers;
857 alpha(k,j)+=(std::pow(
data[i].
ADC,(
int)k)*std::pow(
data[i].
ADC,(
int)j))/sigma2;
859 alpha(k,j)+=(std::pow(
data[i].
ADC,(
int)k+1)*std::pow(
data[i].
ADC,(
int)j+1))/sigma2;
861 alpha(j,k)=alpha(k,j);
865 for (
unsigned k=0;k<
deg;k++)
868 for (
unsigned i=begin;i<linRange;i++) {
870 if (
data[i].NTriggers ) {
871 sigma2 = 100./
data[i].NTriggers;
882 const Eigen::VectorXd comp=alpha.colPivHouseholderQr().solve(beta);
886 rampCoeffs.push_back(0);
888 for (
int l=0;l<comp.size() ;l++)
889 rampCoeffs.push_back(comp[l]);
891#ifdef LARRAMPBUILDER_DEBUGOUTPUT
894 for (
unsigned i=1;i<
data.size();i++)
895 std::cout <<
data[i].DAC <<
" " <<
data[i].
ADC <<
" " << std::endl;
896 std::cout <<
"LinRange= " << linRange <<
" satpoint= " << satpoint<<std::endl;
897 for (
unsigned k=0;k<
deg;k++) {
898 std::cout<<
"Beta "<<k<<
" "<<beta[k]<<std::endl;
899 for (
unsigned j=0;j<=k;j++) {
900 std::cout<<
"Alpha "<<j<<
" "<<alpha(k,j)<<std::endl;
906 for (
unsigned k=0;k<linRange;k++)
907 {
double DACcalc=comp[0];
908 for (
int i=1;i<comp.size();i++)
910 sigma+=(DACcalc-
data[k].DAC)*(DACcalc-
data[k].DAC);
914 sigma=sigma/(linRange-1);
916 std::cout <<
"Components: ";
917 for (
int i=0;i<comp.size();i++)
918 std::cout << comp[i] <<
" ";
919 std::cout <<
"sigma=" << sigma << std::endl;
920#undef LARRAMPBUILDER_DEBUGOUTPUT
923 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
char data[hepevt_bytes_allocation_ATLAS]
double delay(std::size_t d)
LArBadXCont< LArBadChannel > LArBadChannelCont
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
static const Attributes_t empty
constexpr int pow(int base, int exp) noexcept
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
Helper class for offline cell identifiers.
const LArEM_ID * em_idHelper() const
access to EM idHelper
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
virtual float pedestal(const HWIdentifier &id, int gain) const =0
virtual const float & Rinj(const HWIdentifier &id) const =0
value_type get_compact() const
Get the compact id.
This is a "hash" representation of an Identifier.
value_type get_compact() const
Get the compact id.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
Container class for LArAccumulatedCalibDigit.
Data class for calibration ADC samples preprocessed by the DSP.
Liquid Argon Cumulative Wave Container.
Helper class to accumulate calibration triggers.
ERRTYPE add(const std::vector< short > &digits)
accumulated individual set of digits.
HWIdentifier channelId() const
ConditionsMap::const_iterator ConstConditionsMapIterator
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
ConditionsMap::iterator ConditionsMapIterator
Holds information from the FEB Error Summary.
static std::string error_to_string(uint16_t error)
interpret the error in string
uint16_t feb_error(HWIdentifier febid) const
get error for feb
Helper for the Liquid Argon Calorimeter cell identifiers.
std::unique_ptr< LArConditionsContainer< ACCRAMP > > m_ramps
Gaudi::Property< bool > m_doBadChannelMask
SG::ReadCondHandleKey< LArBadChannelCont > m_bcContKey
PublicToolHandle< LArParabolaPeakRecoTool > m_peakParabolaTool
BooleanProperty m_satSlope
IntegerProperty m_deadChannelCut
LArBadChannelMask m_bcMask
Gaudi::Property< std::string > m_hec_key
virtual StatusCode stop()
Gaudi::Property< std::string > m_groupingType
std::vector< float > m_thePedestal
std::vector< std::vector< std::vector< unsigned int > > > m_CaliDACs
BooleanProperty m_dac0sub
Gaudi::Property< bool > m_ishec
Gaudi::Property< bool > m_isSC
std::vector< std::vector< std::vector< std::vector< double > > > > m_CaliWaves
const LArOnlineID_Base * m_onlineHelper
Gaudi::Property< std::vector< std::string > > m_keylist
std::vector< std::vector< int > > m_IndexHighestDAC
Gaudi::Property< std::string > m_keyoutput
FloatProperty m_delayShift
std::vector< std::vector< int > > m_IndexDAC0
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
StringProperty m_recoTypeProp
StatusCode rampfit(unsigned deg, const std::vector< LArRawRamp::RAMPPOINT_t > &data, std::vector< float > &rampCoeffs, std::vector< int > &vSat, const HWIdentifier chid, const LArOnOffIdMapping *cabling, const LArBadChannelCont *bcCont)
UnsignedIntegerProperty m_minDAC
Gaudi::Property< bool > m_iterate
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKeySC
uint16_t m_fatalFebErrorPattern
ToolHandle< LArOFPeakRecoTool > m_peakOFTool
BooleanProperty m_withIntercept
const LArEM_Base_ID * m_emId
UnsignedIntegerProperty m_DAC0
Gaudi::Property< std::vector< std::string > > m_problemsToMask
BooleanProperty m_correctBias
BooleanProperty m_saveRawRamp
BooleanProperty m_saveRecRamp
PublicToolHandle< LArShapePeakRecoTool > m_peakShapeTool
std::vector< float > Samples
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring