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;
209 bool calibMode = (dqStatus->
calibMode() == 1);
232 return StatusCode::SUCCESS;
242 std::ostringstream sStr;
243 std::string trig_str;
253 sStr <<
m_file <<
"_" <<
m_run <<
"_" << trig_str <<
".root";
259 TFile*
fout =
new TFile(
m_file.c_str(),
"recreate");
262 TTree* t =
new TTree(
m_ntupleID.c_str(),
"TileCalib-Ntuple");
264 t->Branch(
"RunNumber", &
m_run,
"RunNumber/I");
265 t->Branch(
"TrigType", &
m_trigType,
"TrigType/I");
266 t->Branch(
"Time", &
m_time,
"Time/I");
267 t->Branch(
"Year", &
m_year,
"Year/I");
268 t->Branch(
"Month", &
m_month,
"Month/I");
269 t->Branch(
"Day", &
m_day,
"Day/I");
270 t->Branch(
"YDay", &
m_yday,
"YDay/I");
271 t->Branch(
"Hour", &
m_hour,
"Hour/I");
272 t->Branch(
"Min", &
m_min,
"Min/I");
273 t->Branch(
"nSamples", &
m_nSamples,
"nSamples/I");
274 t->Branch(
"nEvt", &
m_evtNr,
"nEvt/I");
275 t->Branch(
"ros", *
m_ros,
"ros[5][64][48][2]/b");
276 t->Branch(
"drawer", *
m_drawer,
"drawer[5][64][48][2]/b");
277 t->Branch(
"channel", *
m_channel,
"channel[5][64][48][2]/b");
278 t->Branch(
"gain", *
m_gain,
"gain[5][64][48][2]/O");
279 t->Branch(
"EvtGood", *
m_evt,
"Evt[5][64][48][2]/I");
280 t->Branch(
"ped", *
m_ped,
"ped[5][64][48][2]/F");
281 t->Branch(
"lfn", *
m_lfn,
"lfn[5][64][48][2]/F");
282 t->Branch(
"hfn", *
m_hfn,
"hfn[5][64][48][2]/F");
283 t->Branch(
"noise_cov", *
m_noise_cov,
"noise_cov[5][64][2]/F");
285 t->Branch(
"auto_corr", *
m_auto_corr,
"auto_corr[5][64][48][2][36]/F");
294 return StatusCode::SUCCESS;
308 ATH_MSG_WARNING(
"TileDigiNoiseCalibAlg::StoreRunInfo : dqStatus pointer is null" );
340 ATH_MSG_ERROR(
"No EventInfo object found! Can't read run number!" );
345 m_run = eventInfo->runNumber();
346 m_time = eventInfo->timeStamp();
358 localtime_r(&t_time, &t);
359 m_year = t.tm_year + 1900;
387 for (; collItr != lastColl; ++collItr) {
392 if (digitsItr != lastDigits) {
402 double mean_tmp[48][16][2] = {};
405 for (; digitsItr != lastDigits; ++digitsItr) {
407 adc_id = (*digitsItr)->adc_HWID();
416 std::vector<float> vdigits = (*digitsItr)->samples();
431 if (!(theDQstatus->
isAdcDQgood(ros, drawer, chan, gain))) {
433 <<
" channel: " << chan
435 <<
" due to DQ error found." );
442 <<
" channel: " << chan
443 <<
" due to DQ error found." );
448 double meansamp = 0.0;
449 double rmssamp = 0.0;
450 unsigned int dsize = vdigits.size();
453 ATH_MSG_ERROR(
"length of digits vector " << dsize <<
" - greater than 16 !" );
457 for (
unsigned int i = 0; i < dsize; ++i) {
458 double dig = vdigits[i];
460 rmssamp += dig * dig;
461 mean_tmp[chan][i][gain] = dig;
464 m_ped[ros][drawer][chan][gain] += vdigits[0];
465 m_sumPed2[ros][drawer][chan][gain] += vdigits[0] * vdigits[0];
468 m_evt[ros][drawer][chan][gain]++;
470 rmssamp = rmssamp / dsize - meansamp * meansamp;
471 rmssamp = (rmssamp > 0.0) ? sqrt(rmssamp * dsize / (dsize - 1)) : 0.0;
472 m_hfn[ros][drawer][chan][gain] += rmssamp;
473 m_sumRms2[ros][drawer][chan][gain] += rmssamp * rmssamp;
486 for (
int sample = 0; sample <
m_nSamples; ++sample) {
489 m_meanAmp[ros][drawer][chan_i][gain] += mean_tmp[chan_i][sample][gain];
491 m_meanAmp_ij[ros][drawer][chan_i][chan_j][gain] += mean_tmp[chan_i][sample][gain] * mean_tmp[chan_j][sample][gain];
498 return StatusCode::SUCCESS;
517 float tmpCorr[9][9] = {};
525 m_ros[ros][drawer][chan][gain] = ros;
526 m_drawer[ros][drawer][chan][gain] = drawer;
527 m_channel[ros][drawer][chan][gain] = chan;
528 m_gain[ros][drawer][chan][gain] = gain;
530 if (
m_evt[ros][drawer][chan][gain] > 0) {
531 int nev =
m_evt[ros][drawer][chan][gain];
532 m_ped[ros][drawer][chan][gain] /= nev;
533 double Ped =
m_ped[ros][drawer][chan][gain];
534 m_hfn[ros][drawer][chan][gain] /= nev;
539 PedRMS = (PedRMS > 0.0) ? sqrt(PedRMS * nev / (nev - 1)) : 0.0;
540 m_lfn[ros][drawer][chan][gain] = PedRMS;
554 m_auto_corr[ros][drawer][chan][gain][nVals] = tmpCorr[i][j];
563 m_auto_corr[ros][drawer][chan][gain][nVals] = tmpCorr[i][j];
584 double covar[48][48];
585 double mean_cov_ii = 0.;
586 double mean_cov_ij = 0.;
590 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];
592 if (chan_j < chan_i) {
593 mean_cov_ij += covar[chan_i][chan_j];
596 mean_cov_ii += covar[chan_i][chan_i];
599 if (mean_cov_ii != 0.) {
600 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
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