ATLAS Offline Software
LArPhysWaveTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 LArPhysWaveTool::LArPhysWaveTool ( const std::string& type,
8  const std::string& name,
9  const IInterface* parent )
11 {
12  // Declare additional interface
13  declareInterface<LArPhysWaveTool>(this);
14 
15  // Prepare defaults property values
16  bool injPcorr[4] = { false , true , true , false } ;
17  m_injPointCorrLayer.clear();
18  for ( unsigned i=0;i<4;i++ ) m_injPointCorrLayer.push_back(injPcorr[i]) ;
19 
20  bool injPtaur[4] = { false , false , true , false } ;
21  m_injPointUseTauR.clear();
22  for ( unsigned i=0;i<4;i++ ) m_injPointUseTauR.push_back(injPtaur[i]) ;
23 
24  // Declare properties
25  declareProperty("InjPointCorr", m_injPointCorr=false);
26  declareProperty("InjPointCorrLayer",m_injPointCorrLayer);
27  declareProperty("InjPointUseTauR", m_injPointUseTauR);
28  declareProperty("NormalizeCali", m_normalizeCali=true);
29  declareProperty("TimeOriginShift", m_timeOriginShift=false);
30  declareProperty("SubtractBaseline", m_subtractBaseline=true);
31 }
32 
34 
35 
36 
38  const LArCaliWave& larCaliWave,
39  int /*region*/, int layer,
40  LArPhysWave& predLArPhysWave,
41  float& MphysMcali) const {
42 
43 
44  // calib. signal at Mother Board :
45  LArWave gCaliMB(larCaliWave);
46  LArWave gPhys;
47  LArWaveHelper wHelper;
48 
49  // shift gCaliMB to start point and remove baseline
50 
51  unsigned tstart = wHelper.getStart(gCaliMB) ;
52  double baseline = wHelper.getBaseline(gCaliMB,tstart) ;
53  if ( m_subtractBaseline ) gCaliMB = gCaliMB + (-baseline) ;
54  if ( m_timeOriginShift ) gCaliMB = wHelper.translate(gCaliMB,-tstart,baseline) ;
55 
56  // normalization of calibration pulse
57 
58  if ( m_normalizeCali ) {
59  double peak = gCaliMB.getSample( wHelper.getMax(gCaliMB) ) ;
60  ATH_MSG_VERBOSE ( "*** Normalisation \t|-> YES (CaliWave peak = " << peak << ")" );
61  if ( peak <=0 ) {
62  ATH_MSG_WARNING ( "Peak value <=0 , cannot normalize!" );
63  } else {
64  gCaliMB = gCaliMB * (1./peak) ;
65  }
66  } else {
67  ATH_MSG_VERBOSE ( "*** Normalisation \t|-> NO" );
68  }
69 
70  // ionisation waveform prediction
71 
72  ATH_MSG_VERBOSE ( "*** Physics waveform\t|-> m_Tdrift = " << larWFParam.tdrift() << " ns " );
73  ATH_MSG_VERBOSE ( "*** Physics waveform\t|-> m_Fstep = " << larWFParam.fstep() << " ns " );
74  ATH_MSG_VERBOSE ( "*** Physics waveform\t|-> m_Tcal = " << larWFParam.tcal() << " ns " );
75  ATH_MSG_VERBOSE ( "*** Physics waveform\t|-> m_Omega0 = " << larWFParam.omega0() << " GHz" );
76  ATH_MSG_VERBOSE ( "*** Physics waveform\t|-> m_Taur = " << larWFParam.taur() << " ns " );
77 
78  bool doInjPointCorr = ( ( ( layer>=0 && layer<4 && m_injPointCorrLayer[layer] ) || m_injPointCorr )
79  && larWFParam.omega0() != 0. ) ;
80 
81  const unsigned N = gCaliMB.getSize();
82  const double dt = gCaliMB.getDt() ;
83 
84 
85  if ( ! doInjPointCorr ) {
86  // perform only exp->triangle correction
87  ATH_MSG_VERBOSE ( "*** Inj. Point Corr \t|-> NO" );
88  gPhys = exp2Tri ( gCaliMB,N,dt, larWFParam) ;
89  } else {
90  // perform exp->triangle and then injection point correction
91  ATH_MSG_VERBOSE ( "*** Inj. Point Corr \t|-> YES" );
92  if ( !m_injPointUseTauR[layer] ) {
93  //Copy LArWFParams and set Taur to 0
94  LArWFParams paramsNoTaur=larWFParam;
95  paramsNoTaur.setTaur(0);
96  ATH_MSG_VERBOSE ( "*** Inj. Point TauR \t|-> NO" );
97  gPhys = injResp ( exp2Tri ( gCaliMB,N,dt,paramsNoTaur),N,dt,paramsNoTaur);
98  }
99  else {
100  gPhys = injResp ( exp2Tri ( gCaliMB,N,dt,larWFParam),N,dt,larWFParam);
101  }
102  }
103 
104  // compute Mphys/Mcal
105  if ( m_normalizeCali ) {
106  // caliwave is normalized to 1 => Mcali = 1
107  MphysMcali = gPhys.getSample( wHelper.getMax(gPhys) ) ;
108  } else {
109  MphysMcali = gPhys.getSample( wHelper.getMax(gPhys) ) /
110  gCaliMB.getSample( wHelper.getMax(gCaliMB) ) ;
111  }
112  ATH_MSG_VERBOSE ( "*** Physics waveform\t|-> m_MphysMcali = " << MphysMcali );
113 
114  predLArPhysWave = LArPhysWave( gPhys.getWave(), larCaliWave.getDt() );
115 
116  return StatusCode::SUCCESS;
117 }
118 
119 LArWave LArPhysWaveTool::exp2Tri (const LArWave &w,const unsigned N, const double dt, const LArWFParams& params) const {
120  return w + ( w % caliPhysCorr(N,dt,params) ) ;
121 }
122 
123 
124 LArWave LArPhysWaveTool::caliPhysCorr(const unsigned N, const double dt, const LArWFParams& params) {
125  LArWave w(N,dt);
126  for ( unsigned i=0 ; i<N ; i++ ) {
127  w.setSample(i,caliPhysCorr(i*dt,params)) ;
128  }
129  return w ;
130 }
131 
132 /* =====================================================================
133  * Function: Calibration to Ionisation correction function
134  * ===================================================================== */
136  const double fstep = params.fstep() ;
137  const double Tc = params.tcal() ;
138  const double Td = params.tdrift() ;
139  if ( t<Td ) {
140  if ( fstep==0. ) return ((1.-Tc/Td)-t/Td)/Tc ;
141  return (1.-fstep)/Tc * exp (-fstep*t/Tc)
142  +1./(fstep*Td) * ((1.-fstep)*exp(-fstep*t/Tc)-1.);
143  }
144  else {
145  if ( fstep==0. ) return ((1.-Tc/Td)-t/Td)/Tc
146  + ((t-Td)/Td+Tc/Td)/Tc ;
147  return (1.-fstep)/Tc * exp (-fstep*t/Tc)
148  +1./(fstep*Td) * ( (1.-fstep)*exp(-fstep*t/Tc) - 1. )
149  -1./(fstep*Td) * ( (1.-fstep)*exp(-fstep*(t-Td)/Tc) - 1. ) ;
150  }
151 }
152 
153 // /******************************************************************
154 // * Ionisation waveform prediction
155 // * mode = 1 --> direct exponential to triangular, using wave W
156 // * mode = 2 --> exponential to stepresp to triangular, using gCali
157 // ******************************************************************/
158 // LArPhysWave LArPhysWaveTool::physPred ( int mode , LArPhysWave W ) const {
159 // if ( mode<1 || mode>2 ) mode=1;
160 // if ( mode==1 ) return injResp ( exp2Tri ( W ) );
161 // else return injResp ( step2Tri ( stepResp() ) ) ;
162 // }
163 // /*******************************************************************
164 // * Ionisation waveform prediction (default)
165 // ******************************************************************/
166 // LArPhysWave LArPhysWaveTool::physPred ( LArPhysWave W ) const {
167 // return physPred ( 1 , W ) ;
168 // }
169 /*******************************************************************
170  * Injection point correction
171  *******************************************************************/
172 LArWave LArPhysWaveTool::injResp (const LArWave& w, unsigned N, double dt, const LArWFParams& params) const {
173  return w % injCorr(N,dt,params);
174 }
175 
177  const unsigned N=gCali.getSize();
178  const double dt=gCali.getDt();
179 
180  return gCali + gCali % stepCorr(N,dt,params) ;
181 }
182 LArWave LArPhysWaveTool::step2Tri (const LArWave& w, unsigned N, double dt, const LArWFParams& params) const {
183  return w + w % stepPhysCorr(N,dt,params.tdrift()) ;
184 }
185 /* =================================================================
186  * Function: Step response to Ionisation correction function
187  * =============================================================== */
188 double LArPhysWaveTool::stepPhysCorr ( double t, const double Td) {
189  if ( t<0. || t>=Td ) return 0. ;
190  else return -1./Td ;
191 }
192 LArWave LArPhysWaveTool::stepPhysCorr(unsigned N, double dt, const double Td) {
193  LArWave w(N,dt) ;
194  for ( unsigned i=0 ; i<N ; i++ ) w.setSample(i,stepPhysCorr(i*dt,Td)) ;
195  return w ;
196 }
197 
198 
200  LArWave w(N,dt) ;
201  for ( unsigned i=0 ; i<N ; i++ ) w.setSample(i,stepCorr(i*dt,params)) ;
202  return w ;
203 }
205  const double fstep = params.fstep();
206  const double Tc = params.tcal();
207  return (1.-fstep)/Tc * exp( -fstep*t/Tc );
208 }
209 
210 
212  LArWave w(N,dt) ;
213  for ( unsigned i=0 ; i<N ; i++ ) w.setSample(i,injCorr(i*dt,params)) ;
214  return w ;
215 }
216 /* =================================================================
217  * Function: injection point correction function
218  * =============================================================== */
219 double LArPhysWaveTool::injCorr ( double t, const LArWFParams& params) {
220  const double tau0 = 1./params.omega0();
221  const double taur = params.taur();
222  const double Delta = std::pow(taur,2) - std::pow(2*tau0,2) ;
223  if ( Delta > 0 ) {
224  double sqrtDelta = std::sqrt(Delta) ;
225  double taup = 0.5*( taur + sqrtDelta ) ;
226  double taum = 0.5*( taur - sqrtDelta ) ;
227  return ( exp(-t/taup) - exp(-t/taum) ) / ( taup - taum ) ;
228  } else if ( Delta < 0 ) {
229  double T = std::sqrt(-Delta) ;
230  double A = 2 * taur / ( std::pow(taur,2) - Delta ) ;
231  double B = 2 * T / ( std::pow(taur,2) - Delta ) ;
232  return 2 * exp(-A*t) * sin(B*t) / T ;
233  } else {
234  double tau = 0.5 * taur ;
235  return exp(-t/tau) * t / std::pow(tau,2) ;
236  }
237 #if 0
238  double taur2 = taur*taur, tau02 = tau0*tau0 ;
239  double taua = sqrt( 4.*tau02 - taur2 );
240  return (2./taua)*exp(-t*taur/(2.*tau02))*sin(t*taua/(2.*tau02));
241 #endif
242 }
LArWave
Definition: LArWave.h:31
LArWFParams::taur
double taur() const
Definition: LArWFParams.h:271
python.TriggerHandler.tstart
string tstart
Definition: TriggerHandler.py:299
LArPhysWaveTool::makeLArPhysWave
StatusCode makeLArPhysWave(const LArWFParams &, const LArCaliWave &, int region, int layer, LArPhysWave &predLArPhysWave, float &MphysMcali) const
Definition: LArPhysWaveTool.cxx:37
LArPhysWaveTool::caliPhysCorr
static double caliPhysCorr(double t, const LArWFParams &params)
Definition: LArPhysWaveTool.cxx:135
LArWave::getSize
size_t getSize() const
number of time samples
Definition: LArWave.h:62
LArWaveHelper::getStart
unsigned getStart(const LArWave &theWave) const
Definition: LArWaveHelper.cxx:409
LArPhysWaveTool::m_timeOriginShift
bool m_timeOriginShift
Definition: LArPhysWaveTool.h:44
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArWave::getWave
const std::vector< double > & getWave() const
Wave parameters.
Definition: LArWave.h:167
LArWaveHelper::getBaseline
double getBaseline(const LArWave &theWave, unsigned nBase) const
Definition: LArWaveHelper.cxx:347
LArWave::getDt
const double & getDt() const
delta time
Definition: LArWave.h:50
LArPhysWaveTool::m_injPointCorrLayer
std::vector< bool > m_injPointCorrLayer
Definition: LArPhysWaveTool.h:45
LArWaveHelper::translate
LArWave translate(const LArWave &theWave, int nShift, double baseline=0.) const
Definition: LArWaveHelper.cxx:11
LArWaveHelper
Definition: LArWaveHelper.h:14
LArPhysWaveTool::m_injPointUseTauR
std::vector< bool > m_injPointUseTauR
Definition: LArPhysWaveTool.h:45
LArPhysWaveTool::stepPhysCorr
static double stepPhysCorr(double t, const double dT)
Definition: LArPhysWaveTool.cxx:188
LArWFParams
Definition: LArWFParams.h:20
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
LArWaveHelper::getMax
unsigned int getMax(const LArWave &theWave) const
return index of maximum sample
Definition: LArWaveHelper.cxx:89
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
LArPhysWave
Definition: LArPhysWave.h:14
LArPhysWaveTool::m_normalizeCali
bool m_normalizeCali
Definition: LArPhysWaveTool.h:43
LArPhysWaveTool::stepCorr
static LArWave stepCorr(unsigned N, double dt, const LArWFParams &params)
Definition: LArPhysWaveTool.cxx:199
LArWFParams::tcal
double tcal() const
Definition: LArWFParams.h:267
LArWFParams::fstep
double fstep() const
Definition: LArWFParams.h:268
LArWave::getSample
const double & getSample(const unsigned int i) const
Amplitude per time bin.
Definition: LArWave.h:53
LArPhysWaveTool.h
A
LArPhysWaveTool::LArPhysWaveTool
LArPhysWaveTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: LArPhysWaveTool.cxx:7
LArCaliWave
Definition: LArCaliWave.h:44
LArPhysWaveTool::m_injPointCorr
bool m_injPointCorr
Definition: LArPhysWaveTool.h:43
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloNoise_fillDB.dt
dt
Definition: CaloNoise_fillDB.py:58
LArPhysWaveTool::m_subtractBaseline
bool m_subtractBaseline
Definition: LArPhysWaveTool.h:44
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
LArPhysWaveTool::injResp
LArWave injResp(const LArWave &w, unsigned N, double dt, const LArWFParams &params) const
Definition: LArPhysWaveTool.cxx:172
LArWFParams::setTaur
void setTaur(double taur)
Definition: LArWFParams.h:230
baseline
@ baseline
Definition: SUSYToolsTester.cxx:99
LArPhysWaveTool::stepResp
LArWave stepResp(const LArCaliWave &gCali, const LArWFParams &params) const
Definition: LArPhysWaveTool.cxx:176
test_pyathena.parent
parent
Definition: test_pyathena.py:15
LArWFParams::omega0
double omega0() const
Definition: LArWFParams.h:270
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArPhysWaveTool::exp2Tri
LArWave exp2Tri(const LArWave &, const unsigned N, const double dt, const LArWFParams &params) const
Definition: LArPhysWaveTool.cxx:119
dqt_zlumi_alleff_HIST.B
B
Definition: dqt_zlumi_alleff_HIST.py:110
LArWFParams::tdrift
double tdrift() const
Definition: LArWFParams.h:269
LArPhysWaveTool::step2Tri
LArWave step2Tri(const LArWave &w, unsigned N, double dt, const LArWFParams &params) const
Definition: LArPhysWaveTool.cxx:182
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArPhysWaveTool::~LArPhysWaveTool
virtual ~LArPhysWaveTool()
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
AthAlgTool
Definition: AthAlgTool.h:26
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
LArPhysWaveTool::injCorr
static LArWave injCorr(unsigned N, double dt, const LArWFParams &params)
Definition: LArPhysWaveTool.cxx:211