49 ,
const std::string& name,
const IInterface* parent)
131 ATH_MSG_DEBUG(
"Obsolete calibrateEnergy flag is set to True in jobOptions - disabling it" );
148 int nsamp = (
m_tileInfo->NdigitSamples() > 7) ? 1 : 0;
155 msg(MSG::DEBUG) <<
"TileRawChannelBuilder created, storing rc in '"
169 return StatusCode::FAILURE;
175 std::ostringstream os;
178 std::vector<int> v = { 0x10d };
186 os <<
" (frag IDs):";
189 os <<
" 0x" << std::hex << fragID << std::dec;
193 ATH_MSG_INFO(
"Enable special treatment for demonstrator modules" << os.str());
224 return StatusCode::SUCCESS;
229 return StatusCode::SUCCESS;
242 return StatusCode::SUCCESS;
268 const unsigned int *cispar = DQstatus->
cispar();
269 if (0 == cispar[7]) {
276 m_capdaq = (cispar[7] < 10) ? 5.2 : 100.0;
281 <<
"; dophys is " << ((
m_idophys) ?
"true" :
"false")
282 <<
"; dolas is " << ((
m_idolas) ?
"true" :
"false")
283 <<
"; doped is " << ((
m_idoped) ?
"true" :
"false")
284 <<
"; docis is " << ((
m_idocis) ?
"true" :
"false")
305 int ros = (frag >> 8);
306 int drawer = (frag & 0xff);
326 <<
" is bad - skipping bad patterns check " );
331 <<
" looking for bad patterns in digits" );
334 float mindig, maxdig;
335 int nchbad[2] = { 0, 0 };
341 for (; digitItr != lastDigit; ++digitItr) {
351 <<
"/" << gain <<
" BAD DQ STATUS ");
361 ++dmuerr[channel / 3];
362 ++nchbad[channel / 24];
365 if (
msgLvl(MSG::VERBOSE)) {
367 msg(MSG::VERBOSE) <<
"BadCh " << ros
371 if (err < -5)
msg(MSG::VERBOSE) <<
" Warning " << err;
372 else msg(MSG::VERBOSE) <<
" Error " << err;
375 if (mindig < 0.1)
msg(MSG::VERBOSE) <<
" Underflow";
376 if (err < 0)
msg(MSG::VERBOSE) <<
" Const";
378 msg(MSG::VERBOSE) <<
" samp=";
379 std::vector<float> digits = pDigits->
samples();
380 for (
unsigned int i = 0; i < digits.size(); ++i) {
381 msg(MSG::VERBOSE) <<
" " << digits[i];
387 if (mindig < 0.01) err += 1;
389 if (err)
m_error[channel] = err - 10;
397 int ndmubad[2] = { 0, 0 };
408 int ndmulimit[2] = { 3, 3 };
411 if (frag == 0x30e || frag == 0x411)
417 bool printall =
true;
418 for (
int p = 0; p < 2; ++p) {
419 if (ndmubad[p] > ndmulimit[p] && nchbad[p] > 0) {
420 if (
msgLvl(MSG::VERBOSE)) {
421 msg(MSG::VERBOSE) <<
"Drawer 0x" << MSG::hex << frag << MSG::dec
422 <<
" masking whole " << ((p) ?
"second" :
"first")
425 msg(MSG::VERBOSE) <<
"nDMuErr ";
426 for (
int d = 0; d <
MAX_DMUS; ++d) {
427 msg(MSG::VERBOSE) <<
" " << dmuerr[d];
429 msg(MSG::VERBOSE) <<
" total " << ndmubad[p] <<
" errors" <<
endmsg;
431 msg(MSG::VERBOSE) <<
"ChErr ";
437 msg(MSG::VERBOSE) <<
" ";
440 msg(MSG::VERBOSE) <<
" total " << nchbad[p]
441 <<
" bad patterns" <<
endmsg;
447 for (; ch < chmax; ++ch) {
458 static const char *
const errname[26] = {
462 "-7 - underflow and overflow",
463 "-6 - constant signal",
464 "-5 - disconnected channel",
465 "-4 - half a drawer masked",
466 "-3 - bad DQ status",
467 "-2 - underflow in all samples",
468 "-1 - overflow in all samples",
470 "1 - jump from zero to saturation",
471 "2 - samples with zeros",
472 "3 - at least two saturated. others - close to pedestal",
473 "4 - two distinct levels with at least 2 samples each",
474 "5 - pedestal with jump up in one sample",
475 "6 - pedestal with jump down in one sample",
476 "7 - signal with jump up in one sample",
477 "8 - signal with jump down in one sample",
478 "9 - base line above threshold in low gain",
479 "10 - jump down in first sample in low gain",
480 "11 - jump down in last sample in low gain",
481 "12 - jump up in one sample above const",
482 "13 - jump down in one sample below const",
483 "14 - unrecoverable timing jump",
487 return errname[std::min(25, std::max(0,
int((ped + 500) * 1e-4)))];
505 for (; digitItr != lastDigit; ++digitItr) {
514 if (err == -8 || err == -7)
m_overflows.push_back(std::make_pair(rch, (*digitItr)));
515 float ped = rch->
pedestal() + 100000 + 10000 * err;
540 return StatusCode::SUCCESS;
555 ATH_MSG_DEBUG(
"Incomplete container - use noise filter corrections from DSP container" );
558 std::vector<IdentifierHash> hashes =
m_rawChannelCnt->GetAllCurrentHashes();
561 ATH_MSG_WARNING(
"Problem in applying noise corrections: DSP container ("
563 }
else if (hashes != dspHashes) {
565 "hash vectors do not match.");
574 ATH_MSG_ERROR(
" Error in applying noise corrections " << MSG::hex
575 <<
" collection IDs 0x" << coll->
identify() <<
" and 0x" << dcoll->
identify()
576 <<
" do not match " << MSG::dec );
586 while (dspItr != dspLast && adc_id != (*dspItr)->adc_HWID()) {
589 if (dspItr != dspLast) {
590 float corr = (*dspItr)->pedestal();
592 <<
" amp " << rch->amplitude() <<
" ped " << rch->pedestal()
593 <<
" corr " << corr );
595 rch->setAmplitude (rch->amplitude() - corr);
596 rch->setPedestal (rch->pedestal() + corr);
598 float ped = rch->pedestal();
600 rch->setPedestal (fmod(ped,10000.) +
int(corr)/10000 * 10000);
606 <<
" can not find channel in DSP container with HWID "
608 dspItr = dcoll->
begin();
617 if (noiseFilterTool->process(*
m_rawChannelCnt.get(), ctx).isFailure()) {
618 ATH_MSG_ERROR(
" Error status returned from noise filter " );
635 return StatusCode::SUCCESS;
666 a1 = phase < 0.0 ? 0.000940774 : 0.00102111;
667 a2 = phase < 0.0 ? 0.000759051 : 0.000689625;
668 b = phase < 0.0 ? -2.0 * 7.0 * (a1 - a2) : 2.0 * 12.5 * (a1 - a2);
669 c = phase < 0.0 ? 1.0 - 7.0 * 7.0 * (a1-a2) : 1.0 - 12.5 * 12.5 * (a1-a2);
670 if (phase < 12.5 && phase > -7.0) corr = a1 * phase * phase + 1.0;
671 else corr = phase * ( a2 * phase + b) + c;
689 double k1 = (phase < 0.0 ? -0.0000326707:0.000380336);
690 double k2 = (phase < 0.0 ? -0.000560962:-0.000670487);
691 double k3 = (phase < 0.0 ? -0.00000807869:0.00000501773);
692 double k4 = (phase < 0.0 ? -0.000000145008:0.0000000584647);
694 corr = 1.0 / (1.0 + (k1 + (k2 + (k3 + k4 *phase)*phase)*phase)*phase);
706 double correction = 0.0;
710 correction = (-0.00695743 + (0.0020673 - (0.0002976 + 0.00000361305 * phase) * phase) * phase) * phase;
712 correction = (0.0130013 + (0.00128769 + (-0.000550218 + 0.00000755344 * phase) * phase) * phase) * phase;
723 const std::vector<float> & digits,
float &dmin,
float &dmax,
float ADCmaxMinusEps,
float ADCmaskValueMinusEps) {
725 bool ebsp = ((ros == 3 && drawer == 14) || (ros == 4 && drawer == 17));
726 bool empty = ((eb && ((channel > 23 && channel < 30) || channel > 41)) || (ebsp && channel < 3));
727 bool not_gap = !(
empty || (eb && (channel == 0 || channel == 1 || channel == 12 || channel == 13))
728 || (ebsp && (channel == 18 || channel == 19)));
730 const float epsilon = 4.1;
731 const float delta[4] = { 29.9, 29.9, 49.9, 99.9 };
732 const float level1 = 99.9;
733 const float level2 = 149.9;
734 const float narrowLevel[2] = { 29.9, 49.9 };
735 const float delt = std::min(std::min(std::min(delta[0], delta[1]), std::min(delta[2], delta[3])),
736 std::min(narrowLevel[0], narrowLevel[1]));
737 const float secondMaxLevel = 0.3;
741 unsigned int nSamp = digits.size();
743 dmin = dmax = digits[0];
744 unsigned int pmin = 0;
745 unsigned int pmax = 0;
746 unsigned int nzero = (dmin < 0.01) ? 1 : 0;
747 unsigned int nover = (dmax > ADCmaxMinusEps) ? 1 : 0;
749 for (
unsigned int i = 1; i < nSamp; ++i) {
750 float dig = digits[i];
754 }
else if (dig < dmin) {
758 if (dig < 0.01) ++nzero;
759 else if (dig > ADCmaxMinusEps) ++nover;
762 float dmaxmin = dmax - dmin;
765 if (dmin > ADCmaxMinusEps) {
766 error = (dmin > ADCmaskValueMinusEps) ? -3 : -1;
768 }
else if (dmax < 0.01) {
771 }
else if (dmaxmin < 0.01) {
774 }
else if (nzero && nover) {
777 }
else if ((nzero && (not_gap ||
empty)) || nzero > 1) {
780 }
else if (gain == 0 && dmin > level2) {
783 }
else if (dmaxmin > delt) {
785 float abovemin = dmax;
786 float belowmax = dmin;
787 unsigned int nmin = 0;
788 unsigned int nmax = 0;
789 for (
unsigned int i = 0; i < nSamp; ++i) {
790 float smp = digits[i];
791 if (smp - dmin < epsilon) {
794 if (dmax - smp < epsilon) {
797 if (smp < abovemin && smp > dmin) {
800 if (smp > belowmax && smp < dmax) {
805 int gainInd = (abovemin != dmax || belowmax != dmin) ? gain + 2 : gain;
806 bool big_jump = (dmaxmin > delta[gainInd]);
807 bool max_in_middle = (pmax > 0 && pmax < nSamp - 1);
808 bool min_in_middle = (pmin > 0 && pmin < nSamp - 1);
810 if (nover > 1 && belowmax < level1) {
812 }
else if (
nmax + nmin == nSamp && big_jump) {
813 if (
nmax > 1 && nmin > 1) {
815 }
else if (
nmax == 1) {
819 }
else if (nmin == 1) {
823 if (
error == 0 && dmaxmin > narrowLevel[gain]) {
824 float secondMax = dmaxmin * secondMaxLevel;
825 float dminPlus = dmin + secondMax;
826 float dmaxMinus = dmax - secondMax;
828 if (max_in_middle && std::max(digits[pmax - 1], digits[pmax + 1]) < dminPlus) {
830 }
else if (min_in_middle && std::min(digits[pmin - 1], digits[pmin + 1]) > dmaxMinus) {
832 }
else if (big_jump && gain == 0) {
833 if (pmin == 0 && digits[1] > dmax - secondMax) {
835 }
else if (pmin == nSamp - 1 && digits[pmin - 1] > dmax - secondMax) {
840 if (!
error && big_jump) {
841 if ((max_in_middle || gain == 0) &&
nmax == 1 && belowmax < dminPlus) {
843 }
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.