16#include "GaudiKernel/ServiceHandle.h"
17#include "GaudiKernel/ThreadLocalContext.h"
39#include "TGraphErrors.h"
40#include "TClonesArray.h"
127 return StatusCode::SUCCESS;
159 if (
sc.isFailure()) {
161 return StatusCode::FAILURE;
176 if (cnvSvc.retrieve().isFailure()) {
182 ATH_MSG_ERROR(
" Can't get TileBeamElemContByteStreamCnv " );
192 return StatusCode::SUCCESS;
198 const EventContext& ctx = Gaudi::Hive::currentContext();
210 bool calibMode = (dqStatus->
calibMode() == 1);
233 return StatusCode::SUCCESS;
243 std::ostringstream sStr;
244 std::string trig_str;
254 sStr <<
m_file <<
"_" <<
m_run <<
"_" << trig_str <<
".root";
260 TFile*
fout =
new TFile(
m_file.c_str(),
"recreate");
263 TTree* t =
new TTree(
m_ntupleID.c_str(),
"TileCalib-Ntuple");
265 t->Branch(
"RunNumber", &
m_run,
"RunNumber/I");
266 t->Branch(
"TrigType", &
m_trigType,
"TrigType/I");
267 t->Branch(
"Time", &
m_time,
"Time/I");
268 t->Branch(
"Year", &
m_year,
"Year/I");
269 t->Branch(
"Month", &
m_month,
"Month/I");
270 t->Branch(
"Day", &
m_day,
"Day/I");
271 t->Branch(
"YDay", &
m_yday,
"YDay/I");
272 t->Branch(
"Hour", &
m_hour,
"Hour/I");
273 t->Branch(
"Min", &
m_min,
"Min/I");
274 t->Branch(
"nSamples", &
m_nSamples,
"nSamples/I");
275 t->Branch(
"nEvt", &
m_evtNr,
"nEvt/I");
276 t->Branch(
"ros", *
m_ros,
"ros[5][64][48][2]/b");
277 t->Branch(
"drawer", *
m_drawer,
"drawer[5][64][48][2]/b");
278 t->Branch(
"channel", *
m_channel,
"channel[5][64][48][2]/b");
279 t->Branch(
"gain", *
m_gain,
"gain[5][64][48][2]/O");
280 t->Branch(
"EvtGood", *
m_evt,
"Evt[5][64][48][2]/I");
281 t->Branch(
"ped", *
m_ped,
"ped[5][64][48][2]/F");
282 t->Branch(
"lfn", *
m_lfn,
"lfn[5][64][48][2]/F");
283 t->Branch(
"hfn", *
m_hfn,
"hfn[5][64][48][2]/F");
284 t->Branch(
"noise_cov", *
m_noise_cov,
"noise_cov[5][64][2]/F");
286 t->Branch(
"auto_corr", *
m_auto_corr,
"auto_corr[5][64][48][2][36]/F");
295 return StatusCode::SUCCESS;
309 ATH_MSG_WARNING(
"TileDigiNoiseCalibAlg::StoreRunInfo : dqStatus pointer is null" );
341 ATH_MSG_ERROR(
"No EventInfo object found! Can't read run number!" );
346 m_run = eventInfo->runNumber();
347 m_time = eventInfo->timeStamp();
359 localtime_r(&t_time, &t);
360 m_year = t.tm_year + 1900;
388 for (; collItr != lastColl; ++collItr) {
393 if (digitsItr != lastDigits) {
403 double mean_tmp[48][16][2] = {};
406 for (; digitsItr != lastDigits; ++digitsItr) {
408 adc_id = (*digitsItr)->adc_HWID();
417 std::vector<float> vdigits = (*digitsItr)->samples();
432 if (!(theDQstatus->
isAdcDQgood(ros, drawer, chan, gain))) {
434 <<
" channel: " << chan
436 <<
" due to DQ error found." );
443 <<
" channel: " << chan
444 <<
" due to DQ error found." );
449 double meansamp = 0.0;
450 double rmssamp = 0.0;
451 unsigned int dsize = vdigits.size();
454 ATH_MSG_ERROR(
"length of digits vector " << dsize <<
" - greater than 16 !" );
458 for (
unsigned int i = 0; i < dsize; ++i) {
459 double dig = vdigits[i];
461 rmssamp += dig * dig;
462 mean_tmp[chan][i][gain] = dig;
465 m_ped[ros][drawer][chan][gain] += vdigits[0];
466 m_sumPed2[ros][drawer][chan][gain] += vdigits[0] * vdigits[0];
469 m_evt[ros][drawer][chan][gain]++;
471 rmssamp = rmssamp / dsize - meansamp * meansamp;
472 rmssamp = (rmssamp > 0.0) ? sqrt(rmssamp * dsize / (dsize - 1)) : 0.0;
473 m_hfn[ros][drawer][chan][gain] += rmssamp;
474 m_sumRms2[ros][drawer][chan][gain] += rmssamp * rmssamp;
487 for (
int sample = 0; sample <
m_nSamples; ++sample) {
490 m_meanAmp[ros][drawer][chan_i][gain] += mean_tmp[chan_i][sample][gain];
492 m_meanAmp_ij[ros][drawer][chan_i][chan_j][gain] += mean_tmp[chan_i][sample][gain] * mean_tmp[chan_j][sample][gain];
499 return StatusCode::SUCCESS;
518 float tmpCorr[9][9] = {};
526 m_ros[ros][drawer][chan][gain] = ros;
527 m_drawer[ros][drawer][chan][gain] = drawer;
528 m_channel[ros][drawer][chan][gain] = chan;
529 m_gain[ros][drawer][chan][gain] = gain;
531 if (
m_evt[ros][drawer][chan][gain] > 0) {
532 int nev =
m_evt[ros][drawer][chan][gain];
533 m_ped[ros][drawer][chan][gain] /= nev;
534 double Ped =
m_ped[ros][drawer][chan][gain];
535 m_hfn[ros][drawer][chan][gain] /= nev;
540 PedRMS = (PedRMS > 0.0) ? sqrt(PedRMS * nev / (nev - 1)) : 0.0;
541 m_lfn[ros][drawer][chan][gain] = PedRMS;
555 m_auto_corr[ros][drawer][chan][gain][nVals] = tmpCorr[i][j];
564 m_auto_corr[ros][drawer][chan][gain][nVals] = tmpCorr[i][j];
585 double covar[48][48];
586 double mean_cov_ii = 0.;
587 double mean_cov_ij = 0.;
591 covar[chan_i][chan_j] =
m_meanAmp_ij[ros][drawer][chan_i][chan_j][gain] -
m_meanAmp[ros][drawer][chan_i][gain] *
m_meanAmp[ros][drawer][chan_j][gain];
593 if (chan_j < chan_i) {
594 mean_cov_ij += covar[chan_i][chan_j];
597 mean_cov_ii += covar[chan_i][chan_i];
600 if (mean_cov_ii != 0.) {
601 m_noise_cov[ros][drawer][gain] = (2. * mean_cov_ij) / (mean_cov_ii * 47.);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
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.
static const Attributes_t empty
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
This AthConstConverter class provides conversion from ByteStream to TileBeamElemContainer.
static const TileCablingService * getInstance()
get pointer to service instance
static const unsigned int MAX_ROS
Number of ROSs.
static std::string getDrawerString(unsigned int ros, unsigned int drawer)
Return the drawer name, e.g.
static const unsigned int MAX_GAIN
Number of gains per channel.
static const unsigned int MAX_DRAWER
Number of drawers in ROS 1-4.
static const unsigned int MAX_CHAN
Number of channels in drawer.
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
bool isChanDQgood(int partition, int drawer, int ch) const
returns status of single channel (if bigain, returns AND of ADCs' status
uint32_t calibMode() const
Calibration mode.
const uint32_t * cispar() const
CIS parameters.
TileOFCorrelation * m_tileOFCorrelation
double(* m_meanAmp_ij)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_CHAN][Tile::MAX_GAIN]
ToolHandle< TileRawChannelBuilderFlatFilter > m_adderFilterAlgTool
std::string m_dspRawChannelContainer
double(* m_sumRms2)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_auto_corr)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN][NVALS]
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
virtual StatusCode initialize() override
Only array initialization is done here All the helpers initialization is done at the first event.
uint8_t(* m_channel)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
bool(* m_gain)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
TileDigiNoiseCalibAlg(const std::string &name, ISvcLocator *pSvcLocator)
const uint32_t * m_cispar
virtual StatusCode execute() override
Main method.
SG::ReadHandleKey< TileDQstatus > m_dqStatusKey
float(* m_hfn)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
StatusCode fillDigits(const TileDQstatus *theDQstatus)
fillDigits is called at every events.
float(* m_noise_cov)[Tile::MAX_DRAWER][Tile::MAX_GAIN]
uint8_t(* m_ros)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
void finalDigits()
finalDigits is called during finalize Here the average Ped, m_lfn, m_hfn and covariance are calculate...
TileBeamElemContByteStreamCnv * m_beamCnv
virtual ~TileDigiNoiseCalibAlg()
virtual StatusCode finalize() override
The output ntuple is created in finalize method.
const TileHWID * m_tileHWID
double(* m_meanAmp)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
StatusCode FirstEvt_initialize()
Initialization done at the first event.
SG::ReadHandleKey< TileDigitsContainer > m_digitsContainerKey
std::string m_beamElemContainer
void StoreRunInfo(const TileDQstatus *dqStatus)
StoreRunInfo is called only during the first event.
const TileCablingService * m_cabling
float(* m_lfn)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
int digiChannel2PMT(int ros, int chan)
double(* m_sumPed2)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
int(* m_evt)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
uint8_t(* m_drawer)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
float(* m_ped)[Tile::MAX_DRAWER][Tile::MAX_CHAN][Tile::MAX_GAIN]
@ IS_CALIBRATION
true: calibration, false: physics
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
static constexpr CLID ID()
Tell the compiler to optimize assuming that FP may trap.
#define CXXUTILS_TRAPPING_FP