19#include "GaudiKernel/ThreadLocalContext.h"
50 ,
const std::string& name,
const IInterface* parent)
132 ATH_MSG_DEBUG(
"Obsolete calibrateEnergy flag is set to True in jobOptions - disabling it" );
149 int nsamp = (
m_tileInfo->NdigitSamples() > 7) ? 1 : 0;
156 msg(MSG::DEBUG) <<
"TileRawChannelBuilder created, storing rc in '"
170 return StatusCode::FAILURE;
176 std::ostringstream os;
179 std::vector<int> v = { 0x10d };
187 os <<
" (frag IDs):";
190 os <<
" 0x" << std::hex << fragID << std::dec;
194 ATH_MSG_INFO(
"Enable special treatment for demonstrator modules" << os.str());
225 return StatusCode::SUCCESS;
230 return StatusCode::SUCCESS;
243 return StatusCode::SUCCESS;
269 const unsigned int *cispar = DQstatus->
cispar();
270 if (0 == cispar[7]) {
277 m_capdaq = (cispar[7] < 10) ? 5.2 : 100.0;
282 <<
"; dophys is " << ((
m_idophys) ?
"true" :
"false")
283 <<
"; dolas is " << ((
m_idolas) ?
"true" :
"false")
284 <<
"; doped is " << ((
m_idoped) ?
"true" :
"false")
285 <<
"; docis is " << ((
m_idocis) ?
"true" :
"false")
306 int ros = (frag >> 8);
307 int drawer = (frag & 0xff);
327 <<
" is bad - skipping bad patterns check " );
332 <<
" looking for bad patterns in digits" );
335 float mindig, maxdig;
336 int nchbad[2] = { 0, 0 };
342 for (; digitItr != lastDigit; ++digitItr) {
352 <<
"/" << gain <<
" BAD DQ STATUS ");
362 ++dmuerr[channel / 3];
363 ++nchbad[channel / 24];
366 if (
msgLvl(MSG::VERBOSE)) {
368 msg(MSG::VERBOSE) <<
"BadCh " << ros
372 if (err < -5)
msg(MSG::VERBOSE) <<
" Warning " << err;
373 else msg(MSG::VERBOSE) <<
" Error " << err;
376 if (mindig < 0.1)
msg(MSG::VERBOSE) <<
" Underflow";
377 if (err < 0)
msg(MSG::VERBOSE) <<
" Const";
379 msg(MSG::VERBOSE) <<
" samp=";
380 std::vector<float> digits = pDigits->
samples();
381 for (
unsigned int i = 0; i < digits.size(); ++i) {
382 msg(MSG::VERBOSE) <<
" " << digits[i];
388 if (mindig < 0.01) err += 1;
390 if (err)
m_error[channel] = err - 10;
398 int ndmubad[2] = { 0, 0 };
409 int ndmulimit[2] = { 3, 3 };
412 if (frag == 0x30e || frag == 0x411)
418 bool printall =
true;
419 for (
int p = 0; p < 2; ++p) {
420 if (ndmubad[p] > ndmulimit[p] && nchbad[p] > 0) {
421 if (
msgLvl(MSG::VERBOSE)) {
422 msg(MSG::VERBOSE) <<
"Drawer 0x" << MSG::hex << frag << MSG::dec
423 <<
" masking whole " << ((p) ?
"second" :
"first")
426 msg(MSG::VERBOSE) <<
"nDMuErr ";
427 for (
int d = 0; d <
MAX_DMUS; ++d) {
428 msg(MSG::VERBOSE) <<
" " << dmuerr[d];
430 msg(MSG::VERBOSE) <<
" total " << ndmubad[p] <<
" errors" <<
endmsg;
432 msg(MSG::VERBOSE) <<
"ChErr ";
438 msg(MSG::VERBOSE) <<
" ";
441 msg(MSG::VERBOSE) <<
" total " << nchbad[p]
442 <<
" bad patterns" <<
endmsg;
448 for (; ch < chmax; ++ch) {
459 static const char *
const errname[26] = {
463 "-7 - underflow and overflow",
464 "-6 - constant signal",
465 "-5 - disconnected channel",
466 "-4 - half a drawer masked",
467 "-3 - bad DQ status",
468 "-2 - underflow in all samples",
469 "-1 - overflow in all samples",
471 "1 - jump from zero to saturation",
472 "2 - samples with zeros",
473 "3 - at least two saturated. others - close to pedestal",
474 "4 - two distinct levels with at least 2 samples each",
475 "5 - pedestal with jump up in one sample",
476 "6 - pedestal with jump down in one sample",
477 "7 - signal with jump up in one sample",
478 "8 - signal with jump down in one sample",
479 "9 - base line above threshold in low gain",
480 "10 - jump down in first sample in low gain",
481 "11 - jump down in last sample in low gain",
482 "12 - jump up in one sample above const",
483 "13 - jump down in one sample below const",
484 "14 - unrecoverable timing jump",
488 return errname[std::min(25, std::max(0,
int((ped + 500) * 1e-4)))];
506 for (; digitItr != lastDigit; ++digitItr) {
515 if (err == -8 || err == -7)
m_overflows.push_back(std::make_pair(rch, (*digitItr)));
516 float ped = rch->
pedestal() + 100000 + 10000 * err;
541 return StatusCode::SUCCESS;
556 ATH_MSG_DEBUG(
"Incomplete container - use noise filter corrections from DSP container" );
559 std::vector<IdentifierHash> hashes =
m_rawChannelCnt->GetAllCurrentHashes();
562 ATH_MSG_WARNING(
"Problem in applying noise corrections: DSP container ("
564 }
else if (hashes != dspHashes) {
566 "hash vectors do not match.");
575 ATH_MSG_ERROR(
" Error in applying noise corrections " << MSG::hex
576 <<
" collection IDs 0x" << coll->
identify() <<
" and 0x" << dcoll->
identify()
577 <<
" do not match " << MSG::dec );
587 while (dspItr != dspLast && adc_id != (*dspItr)->adc_HWID()) {
590 if (dspItr != dspLast) {
591 float corr = (*dspItr)->pedestal();
593 <<
" amp " << rch->amplitude() <<
" ped " << rch->pedestal()
594 <<
" corr " << corr );
596 rch->setAmplitude (rch->amplitude() - corr);
597 rch->setPedestal (rch->pedestal() + corr);
599 float ped = rch->pedestal();
601 rch->setPedestal (fmod(ped,10000.) +
int(corr)/10000 * 10000);
607 <<
" can not find channel in DSP container with HWID "
609 dspItr = dcoll->
begin();
618 if (noiseFilterTool->process(*
m_rawChannelCnt.get(), ctx).isFailure()) {
619 ATH_MSG_ERROR(
" Error status returned from noise filter " );
636 return StatusCode::SUCCESS;
667 a1 = phase < 0.0 ? 0.000940774 : 0.00102111;
668 a2 = phase < 0.0 ? 0.000759051 : 0.000689625;
669 b = phase < 0.0 ? -2.0 * 7.0 * (a1 - a2) : 2.0 * 12.5 * (a1 - a2);
670 c = phase < 0.0 ? 1.0 - 7.0 * 7.0 * (a1-a2) : 1.0 - 12.5 * 12.5 * (a1-a2);
671 if (phase < 12.5 && phase > -7.0) corr = a1 * phase * phase + 1.0;
672 else corr = phase * ( a2 * phase + b) + c;
690 double k1 = (phase < 0.0 ? -0.0000326707:0.000380336);
691 double k2 = (phase < 0.0 ? -0.000560962:-0.000670487);
692 double k3 = (phase < 0.0 ? -0.00000807869:0.00000501773);
693 double k4 = (phase < 0.0 ? -0.000000145008:0.0000000584647);
695 corr = 1.0 / (1.0 + (k1 + (k2 + (k3 + k4 *phase)*phase)*phase)*phase);
707 double correction = 0.0;
711 correction = (-0.00695743 + (0.0020673 - (0.0002976 + 0.00000361305 * phase) * phase) * phase) * phase;
713 correction = (0.0130013 + (0.00128769 + (-0.000550218 + 0.00000755344 * phase) * phase) * phase) * phase;
724 const std::vector<float> & digits,
float &dmin,
float &dmax,
float ADCmaxMinusEps,
float ADCmaskValueMinusEps) {
726 bool ebsp = ((ros == 3 && drawer == 14) || (ros == 4 && drawer == 17));
727 bool empty = ((eb && ((channel > 23 && channel < 30) || channel > 41)) || (ebsp && channel < 3));
728 bool not_gap = !(
empty || (eb && (channel == 0 || channel == 1 || channel == 12 || channel == 13))
729 || (ebsp && (channel == 18 || channel == 19)));
731 const float epsilon = 4.1;
732 const float delta[4] = { 29.9, 29.9, 49.9, 99.9 };
733 const float level1 = 99.9;
734 const float level2 = 149.9;
735 const float narrowLevel[2] = { 29.9, 49.9 };
736 const float delt = std::min(std::min(std::min(delta[0], delta[1]), std::min(delta[2], delta[3])),
737 std::min(narrowLevel[0], narrowLevel[1]));
738 const float secondMaxLevel = 0.3;
742 unsigned int nSamp = digits.size();
744 dmin = dmax = digits[0];
745 unsigned int pmin = 0;
746 unsigned int pmax = 0;
747 unsigned int nzero = (dmin < 0.01) ? 1 : 0;
748 unsigned int nover = (dmax > ADCmaxMinusEps) ? 1 : 0;
750 for (
unsigned int i = 1; i < nSamp; ++i) {
751 float dig = digits[i];
755 }
else if (dig < dmin) {
759 if (dig < 0.01) ++nzero;
760 else if (dig > ADCmaxMinusEps) ++nover;
763 float dmaxmin = dmax - dmin;
766 if (dmin > ADCmaxMinusEps) {
767 error = (dmin > ADCmaskValueMinusEps) ? -3 : -1;
769 }
else if (dmax < 0.01) {
772 }
else if (dmaxmin < 0.01) {
775 }
else if (nzero && nover) {
778 }
else if ((nzero && (not_gap ||
empty)) || nzero > 1) {
781 }
else if (gain == 0 && dmin > level2) {
784 }
else if (dmaxmin > delt) {
786 float abovemin = dmax;
787 float belowmax = dmin;
788 unsigned int nmin = 0;
789 unsigned int nmax = 0;
790 for (
unsigned int i = 0; i < nSamp; ++i) {
791 float smp = digits[i];
792 if (smp - dmin < epsilon) {
795 if (dmax - smp < epsilon) {
798 if (smp < abovemin && smp > dmin) {
801 if (smp > belowmax && smp < dmax) {
806 int gainInd = (abovemin != dmax || belowmax != dmin) ? gain + 2 : gain;
807 bool big_jump = (dmaxmin > delta[gainInd]);
808 bool max_in_middle = (pmax > 0 && pmax < nSamp - 1);
809 bool min_in_middle = (pmin > 0 && pmin < nSamp - 1);
811 if (nover > 1 && belowmax < level1) {
813 }
else if (
nmax + nmin == nSamp && big_jump) {
814 if (
nmax > 1 && nmin > 1) {
816 }
else if (
nmax == 1) {
820 }
else if (nmin == 1) {
824 if (
error == 0 && dmaxmin > narrowLevel[gain]) {
825 float secondMax = dmaxmin * secondMaxLevel;
826 float dminPlus = dmin + secondMax;
827 float dmaxMinus = dmax - secondMax;
829 if (max_in_middle && std::max(digits[pmax - 1], digits[pmax + 1]) < dminPlus) {
831 }
else if (min_in_middle && std::min(digits[pmin - 1], digits[pmin + 1]) > dmaxMinus) {
833 }
else if (big_jump && gain == 0) {
834 if (pmin == 0 && digits[1] > dmax - secondMax) {
836 }
else if (pmin == nSamp - 1 && digits[pmin - 1] > dmax - secondMax) {
841 if (!
error && big_jump) {
842 if ((max_in_middle || gain == 0) &&
nmax == 1 && belowmax < dminPlus) {
844 }
else if ((min_in_middle || gain == 0) && nmin == 1 && abovemin > dmaxMinus) {
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
Handle class for recording to StoreGate.
static const InterfaceID IID_ITileRawChannelBuilder("TileRawChannelBuilder", 1, 0)
std::vector< std::pair< TileRawChannel *, const TileDigits * > > Overflows_t
static const Attributes_t empty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
a typed memory pool that saves time spent allocation small object.
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
virtual std::vector< IdentifierHash > GetAllCurrentHashes() const override final
Returns a collection of all hashes availiable in this IDC.
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
This is a "hash" representation of an Identifier.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Class that holds Data Quality fragment information and provides functions to extract the data quality...
bool isAdcDQgood(int partition, int drawer, int ch, int gain) const
returns status of single ADC returns False if there are any errors
int trigType() const
Trigger type.
uint32_t calibMode() const
Calibration mode.
bool incompleteDigits() const
A few extra items (from TileBeamInfoProvider).
const uint32_t * cispar() const
CIS parameters.
bool isBiGain() const
returns gain mode of run
const std::vector< float > & samples() const
Hash table for Tile fragments (==drawers ==collections in StoreGate)
virtual StatusCode finalize()
ToolHandle< TileCondToolTiming > m_tileToolTiming
Overflows_t & getOverflowedChannels(void)
static const char * BadPatternName(float ped)
TileRawChannelUnit::UNIT m_rChUnit
StatusCode build(const TileDigitsCollection *collection, const EventContext &ctx)
static const InterfaceID & interfaceID()
AlgTool InterfaceID.
float m_timeMinThresh
correct amplitude is time is above time min threshold
std::unique_ptr< TileMutableRawChannelContainer > m_rawChannelCnt
SG::ReadHandleKey< TileDQstatus > m_DQstatusKey
static double correctTime(double phase, bool of2=true)
Time correction factor.
virtual ~TileRawChannelBuilder()
Destructor.
float m_ADCmaskValueMinusEps
indicates channels which were masked in background dataset
SG::ReadHandleKey< TileRawChannelContainer > m_DSPContainerKey
float m_ampMinThresh
correct amplitude if it's above amplitude threshold (in ADC counts)
virtual StatusCode createContainer(const EventContext &ctx)
Create container in SG with name given by parameter (m_rawChannelContainerKey)
ServiceHandle< TileCablingSvc > m_cablingSvc
Name of Tile cabling service.
unsigned int m_evtCounter
const TileHWID * m_tileHWID
float m_timeMaxThresh
correct amplitude is time is below time max threshold
static int CorruptedData(int ros, int drawer, int channel, int gain, const std::vector< float > &digits, float &dmin, float &dmax, float ADCmaxMinusEps, float ADCmaskValueMinusEps)
ToolHandle< TileCondIdTransforms > m_tileIdTransforms
static const int MAX_CHANNELS
void fill_drawer_errors(const EventContext &ctx, const TileDigitsCollection *collection)
std::string getTileRawChannelContainerID(void)
virtual StatusCode commitContainer(const EventContext &ctx)
Commit RawChannelContiner in SG and make const.
static double correctAmp(double phase, bool of2=true)
Amplitude correction factor according to the time when using weights for tau=0 without iterations.
const TileCablingService * m_cabling
TileCabling instance.
virtual TileRawChannel * rawChannel(const TileDigits *digits, const EventContext &ctx)
Builder virtual method to be implemented by subclasses.
void initLog(const EventContext &ctx)
ToolHandleArray< ITileRawChannelTool > m_noiseFilterTools
int m_error[MAX_CHANNELS]
virtual StatusCode initialize()
Initializer.
const TileInfo * m_tileInfo
ToolHandle< TileCondToolEmscale > m_tileToolEmscale
TileFragHash::TYPE m_rChType
void resetOverflows(void)
SG::WriteHandleKey< TileRawChannelContainer > m_rawChannelContainerKey
Gaudi::Property< std::vector< int > > m_demoFragIDs
TileRawChannelBuilder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
static const int MAX_DMUS
void assign(const HWIdentifier &id, float amplitude, float time, float quality, float ped=0.0)
float pedestal(void) const
void setPedestal(float ped)
uint32_t getLvl1Type() const
Getter for level1 type.
uint32_t getDetEvType() const
Getter for detector event type.
void setLvl1Type(uint32_t lvl1Type)
Setter for level1 type from ROD header.
void setLvl1Id(uint32_t lvl1Id)
Setter for level1 id from ROD header.
void setRODBCID(uint32_t rodBCID)
Setter for BCID from ROD header.
void setDetEvType(uint32_t detEvType)
Setter for detector event type from ROD header.
uint32_t getLvl1Id() const
Getter for level1 id.
uint32_t getRODBCID() const
Getter for BCID from.
uint32_t get_bsflags() const
HWIdentifier adc_HWID(void) const
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.