ATLAS Offline Software
TileSampleGenerator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
9 #include "TArrayD.h"
10 #include "TMath.h"
11 #include "TF1.h"
12 #include "TRandom3.h"
13 
14 #include <iostream>
15 #include <cstdio>
16 
17 using namespace std;
18 
19 //
20 //_______________________________________________________________
22  m_ps(0), m_buf(0), m_DEBUG(false), m_rndm(nullptr) {
23 
24 }
25 
26 //
27 //_______________________________________________________________
29  m_ps(ps), m_buf(buf), m_DEBUG(dd_DEBUG) {
30  m_rndm = new TRandom3();
31 }
32 
33 //
34 //_______________________________________________________________
36  delete m_rndm;
37 }
38 
39 //
40 //_______________________________________________________________
41 void TileSampleGenerator::fillSamples(double t0, double pedestal, double amplitude1, double amplitude2, TF1* pdf, bool addNoise, double itOffset, double otOffset) {
42  for (unsigned int i = 0; i < m_buf->size(); ++i) {
43  double x1 = m_buf->getTime(i) - t0 + itOffset;
44  double y1 = m_ps->eval(x1) * amplitude1;
45  double x2 = m_buf->getTime(i) - t0 + otOffset;
46  double y2 = m_ps->eval(x2) * amplitude2;
47  double y = y1 + y2 + pedestal;
48 
49  double noise(0), val(y);
50  if (addNoise) {
51  noise = pdf->GetRandom();
52  val += noise;
53  }
54 
56  m_buf->setValue(i, val);
57  }
58 
59  return;
60 }
61 
62 //
63 //________________________________________________________
64 void TileSampleGenerator::fillNSamples(double t0, double pedestal, double amp_it, const vector<float>& amp_pu, TF1* pdf, bool addNoise, double itOffset, int nSamples, int nPul) {
65 
66  std::unique_ptr<TileSampleBuffer> bufall(new TileSampleBuffer(nPul, -25*((nPul-1)/2), 25.));
67 
68  if(m_DEBUG){
69  cout << "Pileup pulses:" << std::endl;
70  for (std::vector<float>::const_iterator i = amp_pu.begin(); i != amp_pu.end(); ++i)
71  std::cout << *i << ' ';
72  std::cout << std::endl;
73  }
74 
75 
76  for (int i = 0; i < nSamples; i++) { //Loop over output samples
77  double tin, amp_it_out;
78  int nPul = amp_pu.size();
79  vector<int> t(nPul);
80  vector<float> amp_pu_out(nPul);
81  int x = (nPul-1)/2 + nSamples;
82  double amp_total = pedestal;
83 
84  if (m_DEBUG)
85  cout << "sample to compute: " << i << " " << amp_total << std::endl;
86 
87  for (int j = 0; j < nPul ; j++) { //Loop over PU pulses
88 
89  t[j] = bufall->getTime(x + i - j) - t0;
90 
91  if (m_DEBUG)
92  cout << "pileupsample to compute " << j << std::endl;
93  if (m_DEBUG)
94  cout << " time in " << i << " " << j << " " << (x + i - j) << " " << " buf " << bufall->getTime(x + i - j) << " time_out " << t[j] << std::endl;
95 
96  if (t[j] < -((nSamples-1)/2)*25. || t[j] > ((nSamples+1)/2)*25.)
97  continue; //Limits of the PulseShape
98  amp_pu_out[j] = m_ps->eval(t[j]) * amp_pu.at(j); // PU Contribution
99  amp_total += amp_pu_out[j];
100 
101  if (m_DEBUG)
102  cout << " amp_pu " << amp_pu.at(j) << " ps " << m_ps->eval(t[j]) << " amp_out " << amp_pu_out[j] << std::endl;
103  if (m_DEBUG)
104  cout << " amp_total " << amp_total << std::endl;
105  }
106 
107  tin = m_buf->getTime(i) - t0 + itOffset;
108  amp_it_out = m_ps->eval(tin) * amp_it; //Contribution from In-time Pulse
109  amp_total += amp_it_out;
110 
111  if (m_DEBUG)
112  cout << " INTIME amp_it " << amp_it << " ps " << m_ps->eval(tin) << " amp_it_out " << amp_it_out << std::endl;
113  if (m_DEBUG)
114  std::cout << " amp_total " << amp_total << std::endl;
115 
116  double noise(0), val(amp_total);
117  if (addNoise) {
118  noise = pdf->GetRandom();
119  val += noise;
120  }
121  if (m_DEBUG)
122  cout << " FINAL " << amp_total << std::endl;
123  m_buf->setValueNoise(i, (noise));
124  m_buf->setValue(i, val);
125  }
126 
127  return;
128 }
129 
130 //
131 //________________________________________________________
132 // Simulation of the PMT pulse shapes for QIE FEB
133 // Please e-mail your questions to alexander.paramonov@cern.ch
134 //________________________________________________________
135 void TileSampleGenerator::fill7SamplesQIE(float amp_it, float *amp_pu) { //float t0, addNoise
136 
137  //amp_it = energy/charge of the in-time pulse in fC
138 
139  //amp_pu charge deposited by out-of-time interactions assuming the interactions are every 25 ns
140  //the amplitudes are in fC
141 
142  //The in-time signal produces charges in amp_total[3] and amp_total[4]; ~80% of charge is added to amp_total[3]
143 
144  float amp_total[7] = { 0, 0, 0, 0, 0, 0, 0 };
145  float tail_Q = 0;
146  const float Q_1pe = 17.; //Average charge per a photo-electron
147  const float tail_prob = 0.18; //Probability for a photo-electron to have 25<t<75 ns
148 
149  for (int i = 0; i < 7; i++) { //Loop over output samples
150 
151  //if (m_DEBUG)
152  // std::cout << "sample to compute: " << i << " " << amp_total << std::endl;
153 
154  if (i != 3) { //out-of-time pileup
155  tail_Q = Q_1pe * m_rndm->Binomial((int) (amp_pu[i] / Q_1pe), tail_prob);
156 
157  amp_total[i] += amp_pu[i] - tail_Q;
158  if (i < 6)
159  amp_total[i + 1] += tail_Q;
160 
161  } else { //in-time pulse
162 
163  tail_Q = Q_1pe * m_rndm->Binomial((int) amp_it / Q_1pe, tail_prob);
164 
165  amp_total[3] += amp_it - tail_Q;
166  amp_total[4] += tail_Q;
167  }
168 
169  /*
170  double noise(0), val(amp_total);
171  if (addNoise) {
172  noise = pdf->GetRandom();
173  amp_total[i] += noise;
174  }
175 
176  if (m_DEBUG)
177  std::cout << " FINAL " << amp_total << std::endl;
178  */
179  }
180 
181  for (unsigned int i = 0; i < 7; i++) { //Loop over output samples
182  m_buf->setValueNoise(i, 0);
183  m_buf->setValue(i, amp_total[i]);
184  }
185 
186  return;
187 }
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
TileSampleGenerator::fillNSamples
void fillNSamples(double t0, double pedestal, double amp_it, const std::vector< float > &amp_pu, TF1 *pdf, bool addNoise, double itOffset=0, int nSamples=7, int nPul=21)
Definition: TileSampleGenerator.cxx:64
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
TilePulseShape::eval
double eval(double x, bool useSpline=true, bool useUndershoot=false)
Definition: TilePulseShape.cxx:75
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
TilePulseShape
Definition: TilePulseShape.h:17
TileSampleBuffer
Definition: TileSampleBuffer.h:14
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TileSampleGenerator::fill7SamplesQIE
void fill7SamplesQIE(float amp_it, float *amp_pu)
Definition: TileSampleGenerator.cxx:135
x
#define x
TileSampleGenerator::m_ps
TilePulseShape * m_ps
Definition: TileSampleGenerator.h:30
TileSampleGenerator::m_DEBUG
bool m_DEBUG
Definition: TileSampleGenerator.h:32
TileSampleBuffer::setValueNoise
void setValueNoise(unsigned int i, double val)
Definition: TileSampleBuffer.h:27
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
TileSampleGenerator::fillSamples
void fillSamples(double t0, double pedestal, double amplitude1, double amplitude2, TF1 *pdf, bool addNoise, double itOffset=0, double otOffset=50)
Definition: TileSampleGenerator.cxx:41
lumiFormat.i
int i
Definition: lumiFormat.py:85
TileSampleBuffer::size
unsigned int size()
Definition: TileSampleBuffer.h:24
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
TileSampleGenerator::~TileSampleGenerator
virtual ~TileSampleGenerator()
Definition: TileSampleGenerator.cxx:35
TileSampleGenerator::TileSampleGenerator
TileSampleGenerator()
Definition: TileSampleGenerator.cxx:21
TileSampleBuffer::setValue
void setValue(unsigned int i, double val)
Definition: TileSampleBuffer.h:21
TileSampleBuffer::getTime
double getTime(unsigned int i)
Definition: TileSampleBuffer.h:44
y
#define y
Trk::addNoise
@ addNoise
Definition: MaterialUpdateMode.h:19
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
TileSampleGenerator.h
PowhegPythia8EvtGen_jetjet.pdf
pdf
Definition: PowhegPythia8EvtGen_jetjet.py:4
TileSampleGenerator::m_rndm
TRandom3 * m_rndm
Definition: TileSampleGenerator.h:33
TileSampleGenerator::m_buf
TileSampleBuffer * m_buf
Definition: TileSampleGenerator.h:31
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
TilePulseShape.h
TileSampleBuffer.h
WriteCellNoiseToCool.noise
noise
Definition: WriteCellNoiseToCool.py:380