41#include <CLHEP/Random/Randomize.h>
42#include <CLHEP/Units/SystemOfUnits.h>
54using CLHEP::RandGaussQ;
174 ATH_MSG_FATAL(
"Could not find input file Distributions_small_h2000_177531_JetTauEtmiss.root");
175 return StatusCode::FAILURE;
179 return StatusCode::FAILURE;
189 ATH_MSG_FATAL(
"Could not find input file Distributions_MB_minbias_inelastic_lowjetphoton_e8314_e7400_s3508.root");
190 return StatusCode::FAILURE;
195 return StatusCode::FAILURE;
196 ATH_MSG_DEBUG(
"Made PU amp distributions for each partition and channel");
204 ATH_MSG_FATAL(
"Could not find input file Distributions_small_h2000_177531_ZeroBias.root");
205 return StatusCode::FAILURE;
209 return StatusCode::FAILURE;
232 ATH_MSG_FATAL(
"Could not initialize find Random Number Service.");
233 return StatusCode::FAILURE;
240 for (
int ros = 1; ros < 5; ++ros){
244 for (
int drawer = 0; drawer < 64; ++drawer){
245 m_PUAmp[ros-1][drawer].clear();
246 m_PUAmp[ros-1][drawer].resize(48);
247 for (
int channel = 0; channel < 48; channel++){
248 m_PUAmp[ros-1][drawer][channel].clear();
254 for (
int ros = 1; ros < 5; ++ros) {
255 for (
int drawer = 0; drawer < 64; ++drawer){
256 for (
int channel = 0; channel < 48; ++channel) {
264 return StatusCode::SUCCESS;
278 CLHEP::HepRandomEngine* rndmEngine = rngWrapper->
getEngine(ctx);
281 auto digitsContainer = std::make_unique<TileMutableDigitsContainer>(
true,
289 auto rawChannelContainer = std::make_unique<TileMutableRawChannelContainer>(
true,
m_rChType,
m_rChUnit);
290 ATH_CHECK( rawChannelContainer->status() );
292 DataPool < TileDigits > tileDigitsPool(
m_tileHWID->adc_hash_max());
294 double tFit = 0, ped = 100;
296 TF1 *pdf =
new TF1();
297 TF1 *pdf_PhaseI =
new TF1();
298 TF1 *pdf_lo =
new TF1();
299 TF1 *pdf_hi =
new TF1();
304 Double_t sigma_lo = 1;
305 pdf_lo =
new TF1(
"pdf_lo",
"(1/(sqrt(2*pi)*[0])) * (exp(-0.5*(x/[0])**2)/(sqrt(2*pi)*[0]))", -100, 100);
306 pdf_lo->SetParameter(0,sigma_lo);
308 Double_t sigma_hi = 2.5;
309 pdf_hi =
new TF1(
"pdf_hi",
"(1/(sqrt(2*pi)*[0])) * (exp(-0.5*(x/[0])**2)/(sqrt(2*pi)*[0]))", -100, 100);
310 pdf_hi->SetParameter(0,sigma_hi);
316 pdf_PhaseI =
new TF1(
"pdf_PhaseI",
"[0] * (exp(-0.5*(x/[1])**2)/(sqrt(2*pi)*[1]) + [2] *exp(-0.5*(x/[3])**2)/(sqrt(2*pi)*[3]))", -100., 100.);
328 double n_inTimeAmp = 0.0;
331 for (
int ros = 1; ros < 5; ++ros) {
332 for (
int drawer = 0; drawer < 64; ++drawer) {
334 for (
int channel = 0; channel < 48; ++channel) {
346 bool isHGSaturated =
false;
348 for (
int igain = 1; igain >= 0; igain--) {
366 m_ps[gain]->scalePulse(deformatedTime, deformatedTime);
373 addPileUp(n_inTimeAmp, gain, ros, drawer, channel);
377 m_ps[gain]->scalePulse(deformatedTime, deformatedTime);
379 double scaleFactor = (
m_PhaseII ? 40.0 : 64.0);
380 n_inTimeAmp /= scaleFactor;
381 for (
auto &Value :
m_PUAmp[ros-1][drawer][channel]) {
382 ampValue /= scaleFactor;
387 pdf = (gain==1) ? pdf_hi : pdf_lo;
398 m_buf->getValueVector(samples);
404 RandGaussQ::shootArray(rndmEngine, samples.size(), Rndm, 0.0, 1.0);
405 RandFlat::shootArray(rndmEngine, 1, Rndm_dG, 0.0, 1.0);
406 for (
unsigned int js = 0; js < samples.size(); ++js) {
408 if (Rndm_dG[0] <
Norm)
409 samples[js] += (float) Hfn1 * Rndm[js];
411 samples[js] += (float) Hfn2 * Rndm[js];
415 for (
unsigned int i = 0; i < samples.size(); ++i) {
417 isHGSaturated =
true;
427 ATH_MSG_VERBOSE(
"New ADC " << ros <<
"/" << drawer <<
"/" << channel <<
"/ saving gain " << gain);
432 ATH_CHECK( digitsContainer->push_back(digit) );
434 auto rawChannel = std::make_unique<TileRawChannel>(digit->adc_HWID(),
440 ATH_CHECK( rawChannelContainer->push_back(std::move(rawChannel)) );
445 ATH_MSG_VERBOSE(
"New ADC " << ros <<
"/" << drawer <<
"/" << channel <<
"/ saving gain " << gain);
450 ATH_CHECK( digitsContainer->push_back(digit) );
452 auto rawChannel = std::make_unique<TileRawChannel>(digit->adc_HWID(),
458 ATH_CHECK( rawChannelContainer->push_back(std::move(rawChannel)) );
474 float my_PUAmp[7] = {0};
476 for (
int i = 0; i < 7; i++)
486 m_tsg->fill7SamplesQIE((
float) n_inTimeAmp, my_PUAmp);
490 m_buf->getValueVector(samples);
492 ATH_MSG_VERBOSE(
"New ADC " << ros <<
"/" << drawer <<
"/" << channel <<
"/ saving gain " << gain);
498 ATH_CHECK( digitsContainer->push_back(digit) );
500 auto rawChannel = std::make_unique<TileRawChannel>(digit->adc_HWID(),
506 ATH_CHECK( rawChannelContainer->push_back(std::move(rawChannel)) );
511 bool isHGSaturated =
false;
513 for (
int igain = 1; igain >= 0; --igain) {
528 pdf = (gain == 1) ? pdf_hi : pdf_lo;
542 m_ps[gain]->scalePulse(deformatedTime, deformatedTime);
545 m_PUAmp[ros-1][drawer][channel].pop_back();
546 m_PUAmp[ros-1][drawer][channel].insert(
m_PUAmp[ros-1][drawer][channel].begin(), 0);
553 m_PUAmp[ros-1][drawer][channel].front() += n_inTimeAmp;
555 sample =
m_tsg->fillSample(tFit, ped,
556 m_PUAmp[ros-1][drawer][channel],
567 sample =
m_tsg->fillSample(tFit, ped,
568 m_PUAmp[ros-1][drawer][channel],
585 isHGSaturated =
true;
590 samples.push_back(sample);
592 ATH_MSG_VERBOSE(
"New chain ADC " << ros <<
"/" << drawer <<
"/" << channel <<
" - saving gain " << gain);
597 ATH_CHECK(digitsContainer->push_back(digit));
600 auto rawChannel = std::make_unique<TileRawChannel>(
606 ATH_CHECK(rawChannelContainer->push_back(std::move(rawChannel)));
633 return StatusCode::SUCCESS;
649 return StatusCode::SUCCESS;
653 file =
new TFile(fileName.c_str());
654 if (
file->IsZombie()) {
655 ATH_MSG_FATAL(
"Error reading amplitude distribution from " << fileName <<
".");
658 TKey *key =
file->FindKey(histName.c_str());
660 ATH_MSG_FATAL(
"Could not find histogram " << histName <<
" in file " << fileName <<
".");
663 hist = (TH1F*)
file->Get(histName.c_str());
665 hist->SetBinContent(i, 0.);
672 std::string histName;
676 file =
new TFile(fileName.c_str());
677 if (
file->IsZombie()) {
678 ATH_MSG_FATAL(
"Error reading amplitude distributions from " << fileName <<
".");
682 for(
int ros=0; ros<4; ros++){
684 hists.push_back(std::vector<TH1F*>());
685 for(
int channel=0; channel<48; channel++){
687 histName =
"ene_ros_" + std::to_string(ros+1) +
"_channel_" + std::to_string(channel+1);
689 key =
file->FindKey(histName.c_str());
691 ATH_MSG_FATAL(
"Could not find histogram " << histName <<
" in file " << fileName <<
".");
695 hist = (TH1F*)
file->Get(histName.c_str());
698 hist->SetBinContent(i, 0.);
700 hists[ros].push_back(hist);
721 for (
int imu = 0; imu<mu; imu++){
737 ATH_MSG_VERBOSE(
"Random amplitudes for PU: " << amp_1 <<
" " << amp_2);
787 double scaleFactor =
m_PhaseII ? 40 : 64;
788 n_inTimeAmp /= scaleFactor;
801 auto random = std::make_unique<TRandom3>(
m_seed);
806 for (
int imu = 0; imu<mu; imu++){
814 m_PUAmp[ros-1][drawer][channel].front() += amp;
820 m_PUAmp[ros-1][drawer][channel].front() /= 64;
823 m_PUAmp[ros-1][drawer][channel].front() /= 40;
827 if(
m_PUAmp[ros-1][drawer][channel].front() < 0)
m_PUAmp[ros-1][drawer][channel].front() = 0;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
size_t size() const
Number of registered mappings.
Helper for holding non-const raw data prior to recording in SG.
Helper for holding non-const raw data prior to recording in SG.
A wrapper class for event-slot-local random engines.
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
TFile * m_pileup_AmpDistFile
File containing amplitude histograms for PU pulses.
bool m_useOotADist
Set to TRUE in order to use a distribution for the out-of-time amplitude instead of a constant value.
TFile * m_itFile
File that holds the distribution of in-time amplitudes.
SG::WriteHandleKey< TileRawChannelContainer > m_rawChannelContainerKey
std::string m_itADistHistName
Name of histogram for in-time amplitude distribution.
std::string m_itADistFileName
Filename of file to use for amplitude distribution of in-time pulses.
bool m_chanNoise
Add channel specific noise.
const TileHWID * m_tileHWID
virtual StatusCode initialize() override
initialize method
virtual StatusCode finalize() override
finalize method
double m_ootAmp
Amplitude of out-of-time pulse.
std::string m_ootADistFileName
Filename of file to use for amplitude distribution of out-of-time pulses.
TH1F * m_ootDist
Histogram to hold the distribution of out-of-time amplitudes.
std::string m_ootADistHistName
Name of histogram for out-of-time amplitude distribution.
bool m_simPulseChain
Simulate continous output of readout for HL-LHC paradigm.
TFile * m_ootFile
File that holds the distribution of out-of-time amplitudes.
TileFragHash::TYPE m_rChType
Type of TileRawChannels (Digitizar, OF1, OF2, Fit, etc.)(see TileFragHash.h).
TileSampleBuffer * m_buf
Buffer class to hold generated pulses.
ToolHandle< TileCondToolNoiseSample > m_tileToolNoiseSample
virtual StatusCode execute(const EventContext &ctx) override
execute method
TFile * m_ootOffsetFile
File that holds the distribution of out-of-time timing offsets.
double m_itOffset
In-time pulse offset from nominal time.
void addPileUpSample(int gain, int ros, int drawer, int channel)
Fill only a BC with pile-up amplitude.
std::vector< std::vector< std::vector< std::vector< float > > > > m_PUAmp
std::unique_ptr< TRandom3 > m_random
double m_ped_HG
Pedestal value for HG if specific channel pedestal is not used.
double m_GNAmpTwo
Amplitude of second gaussian of double gaussian noise.
float m_gausC2C
RMS for the in-time pulse offset (channel-to-channel phase variation).
std::string m_ootOffsetFileName
File name for offset timing distribution histogram.
bool m_useOffsetHisto
Internally used to keep track of wether a histogram has been opened or not.
TileRawChannelUnit::UNIT m_rChUnit
Units used for the TileRawChannels (ADC, pCb, etc.)(see TileInfo.h).
const TileInfo * m_tileInfo
int m_nPul
number of pileup pulses
double m_GNAmpOne
Amplitude of first gaussian of double gaussian noise.
double m_ootOffset
Out-of-time pulse offset from nominal time.
TH1F * m_ootOffsetDist
Histogram to hold the distribution of out-of-time timing offsets.
SG::WriteHandleKey< TileDigitsContainer > m_digitsContainerKey
virtual ~TileDigitsFromPulse()
TilePulseShape * m_ps[2]
Class for defining pulse.
double m_GNSigmaTwo
Standard deviation of second gaussian of double gaussian noise.
ServiceHandle< IAthRNGSvc > m_rndmSvc
Random number service to use.
TileSampleGenerator * m_tsg
Pulse generating class.
double m_itAPulseProb
Probability to add an in-time pulse.
bool m_simQIE
Raw PMT pulses are generated if the option is set to true.
double m_imperfectionMean
Mean value of pulse shape broadening.
Gaudi::Property< std::string > m_randomStreamName
Random Stream Name.
std::string m_pileupAmpDistFileName
Filename for PU amplitude distribution histograms.
bool makeDist(TFile *&file, TH1F *&hist, const std::string &fileName, const std::string &histName="h_Eopt_hi")
Method to read distribution from file.
TH1F * m_itDist
Histogram to hold the distribution of in-time amplitudes.
double m_GNSigmaOne
Standard deviation of first gaussian of double gaussian noise.
int m_AmpDistLowLim
Set all bins to the left of this bin to 0 in the amplitude distribution histograms.
double m_ped_LG
Pedestal value for LG if specific channel pedestal is not used.
double m_imperfectionRms
RMS of pulse shape broadening.
float m_pileUpFraction
Probability that an out-of-time component will be added.
TileDigitsFromPulse(const std::string &name, ISvcLocator *pSvcLocator)
std::vector< std::vector< TH1F * > > m_pileup_AmpDists
Matrix of PU amplitude distribution histograms (PU per partition and channel).
bool m_useItADist
Set to TRUE in order to use a distribution for the in-time amplitude instead of a constant value.
bool m_chanPed
Use channel specific pedestal value if true.
void addPileUp(double &n_inTimeAmp, int gain, int ros, int drawer, int channel)
Fill vector with pile-up amplitudes.
bool m_gaussNoise
Set to TRUE in order to create noise from double gaussian.
std::string m_ootOffsetHistName
Name of the histogram for timing offset distribution.
int m_nSamples
number of read out samples
int m_BunchSpacing
Time between pulses in ms 25, 50 or 75.
double m_inTimeAmp
Amplitude of in-time pulse.
void Norm(TH1 *h, double scale)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts