7#include "CoralBase/Blob.h"
8#include "CoralBase/AttributeListSpecification.h"
31template<
class _T>
inline _T
sqr(
const _T &data) {
return data * data; }
33inline int imax(
int i,
int j) {
return i < j ? j : i; }
36 :
TimeDiffHisto((
"pmt_dtime"+id).c_str(),(
"pmt_dtime"+id).c_str(),1200,-60,60)
40 ,
timeHisto((
"time" + id).c_str(), (
"time" + id).c_str(), 200, -100, 100)
41 ,
eneHisto((
"energy" + id).c_str(), (
"energy" + id).c_str(), 300, 0., 300.)
42 ,
gainHisto((
"gain" + id).c_str(), (
"gain" + id).c_str(), 2, 0, 2)
45#ifdef TileLaserTimingPMT0Mon
46 , TimeDiffHistoHigh((
"dtime" + id +
"hi").c_str(), (
"dtime" + id +
"hi").c_str(), 200, -40, 40)
47 , TimeDiffHistoLow((
"dtime" + id +
"lo").c_str(), (
"dtime" + id +
"lo").c_str(), 200, -60, 60)
50#ifdef TileLaserTimingMonPulse
51 , pulseShapeHigh((
"pulseShape_" + id +
"hi").c_str(), (
"pulseShape_" + id +
"hi").c_str(), 400, -200., 300., 0, 100000.)
52 , pulseShapeLow((
"pulseShape_" + id +
"lo").c_str(), (
"pulseShape_" + id +
"lo").c_str(), 400, -200., 300., 0, 100000.)
55 ,
TimeDiffResHis((
"dtimeRes"+id).c_str(),(
"dtimeRes"+id).c_str(),1000,-40.,40.)
58#ifdef TileLaserTimingPMT0
95 :
Digi0TimeDiffHisto((
"TimeDiff" + id).c_str(), (
"TimeDiff" + id).c_str(), 2000, -100., 100.)
96 ,
Digi0Time((
"Digi0Time" + id).c_str(), (
"Digi0Time" + id).c_str(), 2000, -100., 100.)
100 for (
int i = 0; i < 48; ++i) {
101 std::ostringstream sout;
102 sout <<
id <<
'_' << i;
110float const TileLaserTimingTool::s_fiberLength[2][48] = {{167.1,167.1,178.7,178.7,190.3,190.3,201.9,201.9,213.5,213.5,
111 225.1,225.1,236.7,236.7,248.3,248.3,259.9,259.9,271.5,271.5,
112 283.1,283.1,294.7,294.7,201.9,201.9,213.5,213.5,225.1,225.1,
113 236.7,236.7,248.3,248.3,259.9,259.9,271.5,271.5,283.1,283.1,
114 294.7,294.7,306.3,306.3,317.9,317.9,329.6,329.6},
116 { 51.1, 51.1, 62.7, 62.7, 74.3, 74.3, 85.9, 85.9, 97.5, 97.5,
117 109.1,109.1,120.7,120.7,132.3,132.3,143.9,143.9,143.9,143.9,
118 167.1,167.1,178.1,178.1,178.1,178.1,178.1,178.1,213.5,213.5,
119 213.5,213.5,236.7,236.7,236.7,236.7,259.9,259.9,259.9,259.9,
120 283.1,283.1,294.7,294.7,294.7,294.7,294.7,294.7}};
126 declareInterface<ITileCalibTool>(
this );
128#ifdef TileLaserTimingMonPulse
130 m_h1_time_check =
new TH1F(
"h1_time_check",
"Time(Tfit based) - Time(cispar based)", 1000, -200., 200.);
131 m_h2_time_check =
new TH2F(
"h2_time_check",
"Time(Tfit based) vs Time(cispar based)", 1000, -200., 200., 1000, -200., 200.);
133 m_PulseShapeHigh =
new TProfile(
"pulse_shape_HG",
"pulse shape HG", 400, -200., 300., 0, 100000.);
134 m_PulseShapeLow =
new TProfile(
"pulse_shape_LG",
"pulse shape LG", 400, -200., 300., 0, 100000.);
161#ifdef TileLaserTimingPMT0Mon
177#ifdef TileLaserTimingMon
212#ifdef TileLaserTimingPMT0Mon
213 delete[] m_TimeDiffHighMean;
214 delete[] m_TimeDiffHighMeanError;
215 delete[] m_TimeDiffHighSigma;
216 delete[] m_TimeDiffLowMean;
217 delete[] m_TimeDiffLowMeanError;
218 delete[] m_TimeDiffLowSigma;
219 delete[] m_TimeDiffNoCFCorrMean;
220 delete[] m_TimeDiffNoCFCorrMeanError;
221 delete[] m_TimeDiffNoCFCorrSigma;
226#ifdef TileLaserTimingMon
262 m_gaussf =
new TF1(
"GainGauss",
"[0]*exp(- (x-[1])*(x-[1])/(2*[2]*[2]))", -60, 60);
277 return StatusCode::SUCCESS;
282 ATH_MSG_INFO(
"initNtuple(" << runNumber <<
"," << runType <<
"," << rootFile <<
")" );
284 return StatusCode::SUCCESS;
333 float dtime, dtimeNoCFCorr;
335#ifdef TileLaserTimingMonPulse
336 float f_SampleTime, f_phase1, f_phase2, f_time, f_tfittime;
350 for (; itColl != itCollEnd; ++itColl) {
352 frag = (*itColl)->identify();
353 const auto *digiCollIt = digitsCnt->indexFindPtr(digitsCnt->hashFunc()(frag));
354 if (digiCollIt ==
nullptr) {
358 digiColl = digiCollIt;
359 colls = (*itColl)->
size();
361 <<
" digiColl->size:" << digiColl->
size()
362 <<
" drawer:" <<
drawerIdStr((*itColl)->identify()) );
364 if (digiColl->
size() != colls) {
365 ATH_MSG_ERROR(
" size of TileDigitsCollection and TileRawChannelCollection differ for drawer:" <<
drawerIdStr((*itColl)->identify()) );
382 for (
size_t i = 0; i < colls; ++i) {
383 digits = digiColl->
at(i);
384 rawch = (*itColl)->at(i);
396 if (rawch && digits) {
416 dtimeNoCFCorr = pmtdata.
time - pmt0data.
time;
420#ifdef TileLaserTimingPMT0
423 if(gain == 0) pmtdata.TimeDiffHistoLow.Fill(dtime);
424 else pmtdata.TimeDiffHistoHigh.Fill(dtime);
427#ifdef TileLaserTimingMon
434#ifdef TileLaserTimingMonPulse
436 std::vector<float> sample = digits->
samples();
439 <<
" in:" << sample.size() <<
" expected:" <<
m_nSamples.value() );
441 for (
unsigned jsample = 0; jsample <
m_nSamples; ++jsample) {
442 f_SampleTime = ((float) jsample) * 25.;
443 f_phase1 = (25. * ((float) phase)) / (30. * 8);
444 f_phase2 = -pmtdata.
time;
445 f_time = f_SampleTime + f_phase1 - 100;
446 f_tfittime = f_SampleTime + f_phase2 - 100;
452 if (phase < 140 || phase > 160) {
455 m_h1_time_check->Fill(f_phase1 - f_phase2);
456 m_h2_time_check->Fill(f_phase1, f_phase2);
459 pmtdata.pulseShapeLow.Fill(f_tfittime, (LG2HG * (sample[jsample] - rawch->
pedestal())));
464 pmtdata.pulseShapeHigh.Fill(f_tfittime, (sample[jsample] - rawch->
pedestal()));
482 for (
int ipmt = 0; ipmt < 6; ++ipmt) {
491#ifdef TileLaserTimingMon
495 if (
msgLvl(MSG::VERBOSE) && (ros == 1) && (drawer == 1)) {
502 for (
int ipmt = 0; ipmt <
NCHANNELS; ipmt++) {
506 if (
msgLvl(MSG::VERBOSE) && (ros == 1) && (drawer == 1)) {
507 ATH_MSG_VERBOSE(
" ipmt:" << ipmt <<
" ChannelOffset:" << ChannelOffset );
527 if (
msgLvl(MSG::VERBOSE) && (ros == 1) && (drawer == 1)) {
536 return StatusCode::SUCCESS;
545 float fmean, fdummy, fchi2, fmeanerr;
551 for (
int ipmt = 0; ipmt <
NCHANNELS; ++ipmt) {
555#ifdef TileLaserTimingMon
564#ifdef TileLaserTimingMonPulse
565 if(pmtd.TimeDiffHistoLow.GetEntries() > 0.99 *
m_nevts) {
566 m_PulseShapeLow->Add(&pmtd.pulseShapeLow);
569 if(pmtd.TimeDiffHistoHigh.GetEntries() > 0.99 *
m_nevts) {
570 m_PulseShapeHigh->Add(&pmtd.pulseShapeHigh);
582#ifdef TileLaserTimingPMT0
587 fitGauss(pmtd.
TimeDiffNoCFCorrHisto, m_TimeDiffNoCFCorrMean[ros][drawer][ipmt], m_TimeDiffNoCFCorrSigma[ros][drawer][ipmt], m_TimeDiffNoCFCorrMeanError[ros][drawer][ipmt]);
594 fitGauss(pmtd.TimeDiffHistoLow, m_TimeDiffLowMean[ros][drawer][ipmt], m_TimeDiffLowSigma[ros][drawer][ipmt], m_TimeDiffLowMeanError[ros][drawer][ipmt]);
598 fitGauss(pmtd.TimeDiffHistoHigh, m_TimeDiffHighMean[ros][drawer][ipmt], m_TimeDiffHighSigma[ros][drawer][ipmt], m_TimeDiffHighMeanError[ros][drawer][ipmt]);
616 <<
" has chi2 value " << fchi2
617 <<
" force timing residual same as PMT-1 " );
624 if (fabs(fmean) > 100) {
626 <<
" has ChannelOffset " << fmean
627 <<
" force timing residual same as PMT-1" );
641#ifdef TileLaserTimingMonPulse
647 m_ADCAmplitude[ros][drawer][ipmt] = fmax(pmtd.pulseShapeHigh.GetMaximum(), pmtd.pulseShapeLow.GetMaximum());
651 if (
msgLvl(MSG::VERBOSE) && (ros == 1) && (drawer == 1)) {
652 msg(MSG::VERBOSE) <<
"ipmt: " << ipmt
653 <<
" TimeDiffLow: " << m_TimeDiffLowMean[ros][drawer][ipmt] <<
"(" << m_TimeDiffLowSigma[ros][drawer][ipmt] <<
") +-" << m_TimeDiffLowMeanError[ros][drawer][ipmt]
654 <<
" TimeDiffHigh:" << m_TimeDiffHighMean[ros][drawer][ipmt] <<
"(" << m_TimeDiffHighSigma[ros][drawer][ipmt] <<
") +-" << m_TimeDiffHighMeanError[ros][drawer][ipmt] <<
endmsg;
657 <<
" TomeDiffNoCF:" << m_TimeDiffNoCFCorrMean[ros][drawer][ipmt] <<
"(" << m_TimeDiffNoCFCorrSigma[ros][drawer][ipmt] <<
") +-" << m_TimeDiffNoCFCorrMeanError[ros][drawer][ipmt] <<
endmsg;
674 <<
" drawer:" << drawer
700 for (
int ipmt = 0; ipmt <
NCHANNELS; ++ipmt) {
703 if (
isConnectedPMT(ros, ipmt) && (timeDiffs[ros][drawer][ipmt] < 300)) {
704 drawerd.
digid[ipmt / 6].
Add(timeDiffs[ros][drawer][ipmt]);
712 if (
isConnectedPMT(ros, ipmt) && (timeDiffs[ros][drawer][ipmt] < 300)) {
713 if (ipmt < 6) drawerd.
digid[0].
Add(timeDiffs[ros][drawer][ipmt]);
714 else if (ipmt > 5 && ipmt < 12) drawerd.
digid[1].
Add(timeDiffs[ros][drawer][ipmt]);
715 else if (ipmt > 11 && ipmt < 18) drawerd.
digid[2].
Add(timeDiffs[ros][drawer][ipmt]);
716 else if (ipmt > 17 && ipmt < 24) drawerd.
digid[3].
Add(timeDiffs[ros][drawer][ipmt]);
717 else if (ipmt > 27 && ipmt < 34) {
718 drawerd.
digid[4].
Add(timeDiffs[ros][drawer][ipmt]);
719 drawerd.
digid[5].
Add(timeDiffs[ros][drawer][ipmt]);
720 }
else if (ipmt > 35) {
721 drawerd.
digid[6].
Add(timeDiffs[ros][drawer][ipmt]);
722 drawerd.
digid[7].
Add(timeDiffs[ros][drawer][ipmt]);
730 else if (ipmt == 33) {
733 }
else if (ipmt == 47) {
740 for (
int digi = 0; digi <
NDIGI; ++digi) {
746 <<
" drawer: " << drawer
750 <<
" DSkewSet: " <<
m_DSkewSet[ros][drawer][digi] );
756 return StatusCode::SUCCESS;
761 ATH_MSG_INFO(
"writeNtuple(" << runNumber <<
"," << runType <<
"," << rootFile <<
")" );
764 TTree *t =
new TTree(
m_ntupleID.value().c_str(),
"TileLaserTimingNtuple");
765 t->Branch(
"DrawerOffset",
m_DrawerOffset,
"DrawerOffset[5][64]/F");
768 t->Branch(
"ChannelOffset",
m_ChannelOffset,
"ChannelOffset[5][64][48]/F");
771 t->Branch(
"ADCAmplitude",
m_ADCAmplitude,
"ADCAmplitude[5][64][48]/F");
773 t->Branch(
"PedestalMean",
m_PedestalMean,
"PedestalMean[5][64][48]/F");
774 t->Branch(
"PedestalSigma",
m_PedestalSigma,
"PedestalSigma[5][64][48]/F");
776 t->Branch(
"TimeDiffMean",
m_TimeDiffMean,
"TimeDiffMean[5][64][48]/F");
778 t->Branch(
"TimeDiffSigma",
m_TimeDiffSigma,
"TimeDiffSigma[5][64][48]/F");
780#ifdef TileLaserTimingPMT0Mon
781 t->Branch(
"TimeDiffHighMean", m_TimeDiffHighMean,
"TimeDiffHighMean[5][64][48]/F");
782 t->Branch(
"TimeDiffHighMeanError", m_TimeDiffHighMeanError,
"TimeDiffHighMeanError[5][64][48]/F");
783 t->Branch(
"TimeDiffHighSigma", m_TimeDiffHighSigma,
"TimeDiffHighSigma[5][64][48]/F");
784 t->Branch(
"TimeDiffLowMean", m_TimeDiffLowMean,
"TimeDiffLowMean[5][64][48]/F");
785 t->Branch(
"TimeDiffLowMeanError", m_TimeDiffLowMeanError,
"TimeDiffLowMeanError[5][64][48]/F");
786 t->Branch(
"TimeDiffLowSigma", m_TimeDiffLowSigma,
"TimeDiffLowSigma[5][64][48]/F");
787 t->Branch(
"TimeDiffNoCFCorrMean", m_TimeDiffNoCFCorrMean,
"TimeDiffNoCFCorrMean[5][64][48]/F");
788 t->Branch(
"TimeDiffNoCFCorrMeanError", m_TimeDiffNoCFCorrMeanError,
"TimeDiffNoCFCorrMeanError[5][64][48]/F");
789 t->Branch(
"TimeDiffNoCFCorrSigma", m_TimeDiffNoCFCorrSigma,
"TimeDiffNoCFCorrSigma[5][64][48]/F");
791 t->Branch(
"FiberLength",
m_FiberLength,
"FiberLength[5][64][48]/F");
793#ifdef TileLaserTimingMon
797 t->Branch(
"IsConnected",
m_IsConnected,
"IsConnected[5][64][48]/F");
815 t->Branch(
"DSkewSet",
m_DSkewSet,
"DSkewSet[5][64][8]/F");
816 t->Branch(
"DigiMean",
m_DigiMean,
"DigiMean[5][64][8]/F");
821 ATH_MSG_INFO(
"writeNtuple(" << runNumber <<
"," << runType <<
"," << rootFile <<
") data written" );
828 ATH_MSG_VERBOSE(
"writeNtuple() ros:" << ros <<
" drawer:" << drawer );
833#ifdef TileLaserTimingMon
836 for (
int ipmt = 0; ipmt <
NCHANNELS; ++ipmt) {
840#ifdef TileLaserTimingMon
856 return StatusCode::SUCCESS;
863 return StatusCode::SUCCESS;
870 return !(ipmt == 31 || ipmt == 32 || ipmt == 43);
872 return !( ipmt == 18 || ipmt == 19 || ipmt == 24 || ipmt == 25
873 || ipmt == 26 || ipmt == 27 || ipmt == 30 || ipmt == 31
874 || ipmt == 34 || ipmt == 35 || ipmt == 38 || ipmt == 39
875 || ipmt == 44 || ipmt == 45 || ipmt == 46 || ipmt == 47);
884 if (hi.GetEntries() == 0) {
885 p1 = p2 = p1_err = 0.0;
888 double MaxAmplitude = hi.GetMaximum();
889 double MeanTimeDiff = hi.GetMean();
890 double RMSTimeDiff = hi.GetRMS();
891 m_gaussf->SetParameter(0, MaxAmplitude);
892 m_gaussf->SetParameter(1, MeanTimeDiff);
893 m_gaussf->SetParameter(2, RMSTimeDiff);
894 m_gaussf->SetRange(MeanTimeDiff - 2.0 * RMSTimeDiff, MeanTimeDiff + 2.0 * RMSTimeDiff);
905 if (hi.GetEntries() == 0) {
906 p1 = p2 =
chi2 = p1_err = w1 = w2 = 0.0;
910 double MaxAmplitude = hi.GetMaximum();
911 double MeanTimeDiff = hi.GetMean();
912 double RMSTimeDiff = hi.GetRMS();
914 m_gaussf->SetParameter(0, MaxAmplitude);
915 m_gaussf->SetParameter(1, MeanTimeDiff);
916 m_gaussf->SetParameter(2, RMSTimeDiff);
917 m_gaussf->SetRange(MeanTimeDiff - w1 * RMSTimeDiff, MeanTimeDiff + w1 * RMSTimeDiff);
920 double FittedAmplitude =
m_gaussf->GetParameter(0);
921 double FittedMean =
m_gaussf->GetParameter(1);
922 double FittedSigma =
m_gaussf->GetParameter(2);
926 m_gaussf->SetParameter(0, FittedAmplitude);
927 m_gaussf->SetParameter(1, FittedMean);
928 m_gaussf->SetParameter(2, FittedSigma);
929 m_gaussf->SetRange(FittedMean - w2 * FittedSigma, FittedMean + w2 * FittedSigma);
944 float DeltaParity = 0;
949 for (
int ipmt = 0; ipmt <
NCHANNELS; ++ipmt) {
953 if (fabs(ChannelOffset[ros][drawer][ipmt]) <
m_maxTimeDiff) {
954 MeanOddPmtTdiff[ros][drawer] += ChannelOffset[ros][drawer][ipmt];
955 ++OddPmtCounter[ros][drawer];
958 <<
" time overflow (" << ChannelOffset[ros][drawer][ipmt]
961 <<
" pmt:" << ipmt );
964 }
else if (ipmt % 2 == 0) {
966 if (fabs(ChannelOffset[ros][drawer][ipmt]) <
m_maxTimeDiff) {
967 MeanEvenPmtTdiff[ros][drawer] += ChannelOffset[ros][drawer][ipmt];
968 ++EvenPmtCounter[ros][drawer];
971 <<
" time overflow (" << ChannelOffset[ros][drawer][ipmt]
974 <<
" pmt:" << ipmt );
981 MeanOddPmtTdiff[ros][drawer] /= (float) OddPmtCounter[ros][drawer];
982 MeanEvenPmtTdiff[ros][drawer] /= (float) EvenPmtCounter[ros][drawer];
983 DeltaParity = 0.5 * (MeanOddPmtTdiff[ros][drawer] - MeanEvenPmtTdiff[ros][drawer]);
985 EvenOddTimeDiff[ros][drawer] = 2 * DeltaParity;
989 <<
" drawer:" << drawer
990 <<
" EvenOddTimeDiff:" << EvenOddTimeDiff[ros][drawer]
991 <<
" | MeanOddPmtTdiff:" << MeanOddPmtTdiff[ros][drawer]
992 <<
" MeanEvenPmtTdiff:" << MeanEvenPmtTdiff[ros][drawer]
993 <<
" DeltaParity:" << DeltaParity );
998 for (
int ipmt = 0; ipmt <
NCHANNELS; ++ipmt) {
1001 ChannelOffset[ros][drawer][ipmt] -= DeltaParity;
1002 else if (ipmt % 2 == 0) ChannelOffset[ros][drawer][ipmt] += DeltaParity;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
static const TileCablingService * getInstance()
get pointer to service instance
static const unsigned int MAX_ROS
Number of ROSs.
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
const std::vector< float > & samples() const
float pedestal(void) const
float time(int ind=0) const
float amplitude(int ind=0) const
Identifier identify(void) const
HWIdentifier adc_HWID(void) const
void getStat(double &mean, double &sigma)
double chi2(TH1 *h0, TH1 *h1)