16#include "GaudiKernel/ServiceHandle.h"
38#include "TGraphErrors.h"
39#include "TClonesArray.h"
126 return StatusCode::SUCCESS;
158 if (
sc.isFailure()) {
160 return StatusCode::FAILURE;
175 if (cnvSvc.retrieve().isFailure()) {
181 ATH_MSG_ERROR(
" Can't get TileBeamElemContByteStreamCnv " );
191 return StatusCode::SUCCESS;
208 bool calibMode = (dqStatus->
calibMode() == 1);
231 return StatusCode::SUCCESS;
241 std::ostringstream sStr;
242 std::string trig_str;
252 sStr <<
m_file <<
"_" <<
m_run <<
"_" << trig_str <<
".root";
258 TFile*
fout =
new TFile(
m_file.c_str(),
"recreate");
261 TTree* t =
new TTree(
m_ntupleID.c_str(),
"TileCalib-Ntuple");
263 t->Branch(
"RunNumber", &
m_run,
"RunNumber/I");
264 t->Branch(
"TrigType", &
m_trigType,
"TrigType/I");
265 t->Branch(
"Time", &
m_time,
"Time/I");
266 t->Branch(
"Year", &
m_year,
"Year/I");
267 t->Branch(
"Month", &
m_month,
"Month/I");
268 t->Branch(
"Day", &
m_day,
"Day/I");
269 t->Branch(
"YDay", &
m_yday,
"YDay/I");
270 t->Branch(
"Hour", &
m_hour,
"Hour/I");
271 t->Branch(
"Min", &
m_min,
"Min/I");
272 t->Branch(
"nSamples", &
m_nSamples,
"nSamples/I");
273 t->Branch(
"nEvt", &
m_evtNr,
"nEvt/I");
274 t->Branch(
"ros", *
m_ros,
"ros[5][64][48][2]/b");
275 t->Branch(
"drawer", *
m_drawer,
"drawer[5][64][48][2]/b");
276 t->Branch(
"channel", *
m_channel,
"channel[5][64][48][2]/b");
277 t->Branch(
"gain", *
m_gain,
"gain[5][64][48][2]/O");
278 t->Branch(
"EvtGood", *
m_evt,
"Evt[5][64][48][2]/I");
279 t->Branch(
"ped", *
m_ped,
"ped[5][64][48][2]/F");
280 t->Branch(
"lfn", *
m_lfn,
"lfn[5][64][48][2]/F");
281 t->Branch(
"hfn", *
m_hfn,
"hfn[5][64][48][2]/F");
282 t->Branch(
"noise_cov", *
m_noise_cov,
"noise_cov[5][64][2]/F");
284 t->Branch(
"auto_corr", *
m_auto_corr,
"auto_corr[5][64][48][2][36]/F");
293 return StatusCode::SUCCESS;
307 ATH_MSG_WARNING(
"TileDigiNoiseCalibAlg::StoreRunInfo : dqStatus pointer is null" );
339 ATH_MSG_ERROR(
"No EventInfo object found! Can't read run number!" );
344 m_run = eventInfo->runNumber();
345 m_time = eventInfo->timeStamp();
357 localtime_r(&t_time, &t);
358 m_year = t.tm_year + 1900;
386 for (; collItr != lastColl; ++collItr) {
391 if (digitsItr != lastDigits) {
401 double mean_tmp[48][16][2] = {};
404 for (; digitsItr != lastDigits; ++digitsItr) {
406 adc_id = (*digitsItr)->adc_HWID();
415 std::vector<float> vdigits = (*digitsItr)->samples();
430 if (!(theDQstatus->
isAdcDQgood(ros, drawer, chan, gain))) {
432 <<
" channel: " << chan
434 <<
" due to DQ error found." );
441 <<
" channel: " << chan
442 <<
" due to DQ error found." );
447 double meansamp = 0.0;
448 double rmssamp = 0.0;
449 unsigned int dsize = vdigits.size();
452 ATH_MSG_ERROR(
"length of digits vector " << dsize <<
" - greater than 16 !" );
456 for (
unsigned int i = 0; i < dsize; ++i) {
457 double dig = vdigits[i];
459 rmssamp += dig * dig;
460 mean_tmp[chan][i][gain] = dig;
463 m_ped[ros][drawer][chan][gain] += vdigits[0];
464 m_sumPed2[ros][drawer][chan][gain] += vdigits[0] * vdigits[0];
467 m_evt[ros][drawer][chan][gain]++;
469 rmssamp = rmssamp / dsize - meansamp * meansamp;
470 rmssamp = (rmssamp > 0.0) ? sqrt(rmssamp * dsize / (dsize - 1)) : 0.0;
471 m_hfn[ros][drawer][chan][gain] += rmssamp;
472 m_sumRms2[ros][drawer][chan][gain] += rmssamp * rmssamp;
485 for (
int sample = 0; sample <
m_nSamples; ++sample) {
488 m_meanAmp[ros][drawer][chan_i][gain] += mean_tmp[chan_i][sample][gain];
490 m_meanAmp_ij[ros][drawer][chan_i][chan_j][gain] += mean_tmp[chan_i][sample][gain] * mean_tmp[chan_j][sample][gain];
497 return StatusCode::SUCCESS;
516 float tmpCorr[9][9] = {};
524 m_ros[ros][drawer][chan][gain] = ros;
525 m_drawer[ros][drawer][chan][gain] = drawer;
526 m_channel[ros][drawer][chan][gain] = chan;
527 m_gain[ros][drawer][chan][gain] = gain;
529 if (
m_evt[ros][drawer][chan][gain] > 0) {
530 int nev =
m_evt[ros][drawer][chan][gain];
531 m_ped[ros][drawer][chan][gain] /= nev;
532 double Ped =
m_ped[ros][drawer][chan][gain];
533 m_hfn[ros][drawer][chan][gain] /= nev;
538 PedRMS = (PedRMS > 0.0) ? sqrt(PedRMS * nev / (nev - 1)) : 0.0;
539 m_lfn[ros][drawer][chan][gain] = PedRMS;
553 m_auto_corr[ros][drawer][chan][gain][nVals] = tmpCorr[i][j];
562 m_auto_corr[ros][drawer][chan][gain][nVals] = tmpCorr[i][j];
583 double covar[48][48];
584 double mean_cov_ii = 0.;
585 double mean_cov_ij = 0.;
589 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];
591 if (chan_j < chan_i) {
592 mean_cov_ij += covar[chan_i][chan_j];
595 mean_cov_ii += covar[chan_i][chan_i];
598 if (mean_cov_ii != 0.) {
599 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.
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
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]
virtual StatusCode execute(const EventContext &ctx) override
Main method.
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