ATLAS Offline Software
Loading...
Searching...
No Matches
ZdcRecTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7#include "TGraph.h"
8#include "TEnv.h"
9#include "TSystem.h"
10
11namespace ZDC
12{
13
14 ZdcRecTool::ZdcRecTool(const std::string& name) : asg::AsgTool(name),
15 m_name(name),
16 m_init(false)
17 {
18 declareProperty("ZdcModuleContainerName",m_zdcModuleContainerName="ZdcModules","Location of ZDC processed data");
19 declareProperty("ZdcRecConfigPath",m_zdcRecConfigPath="$ROOTCOREDIR/data/HIEventUtils/","ZDC Rec config file path");
20
21 ATH_MSG_DEBUG("Creating ZdcRecoTool named " << m_name);
22 ATH_MSG_INFO("ZDC config file path " << m_zdcRecConfigPath);
23
24 }
25
27 {
28 ATH_MSG_DEBUG("Deleting ZdcRecoTool named " << m_name);
29 }
30
32 {
33 m_init = true;
34 m_tf1SincInterp = new TF1("SincInterp",SincInterp,-5.,160.,8);
35 m_tf1SincInterp->SetNpx(300);
36 m_tf1FermiExpFit = new TF1("FermiExpFit",FermiExpFit,-5.,160.,7);
37 m_tf1FermiExpFit->SetNpx(300);
38
39 char* path = gSystem->ExpandPathName(m_zdcRecConfigPath.c_str());
40 ATH_MSG_INFO("Resolved file path " << path);
41
42 TString zdcConf(path);
43 zdcConf += "/ZdcRecConfig.conf";
44
45 TEnv env(zdcConf);
46
47 ATH_MSG_INFO("ZdcC calibration LG " << env.GetValue("ZdcCCalibrationLG","1.;1.;1.;1."));
48
49 return StatusCode::SUCCESS;
50
51 }
52
54 {
55
56 ATH_MSG_DEBUG("Not processing ZDC module S/T/M/C = "
57 << module.zdcSide() << " "
58 << module.zdcType() << " "
59 << module.zdcModule() << " "
60 << module.zdcChannel()
61 );
62
63
64 return StatusCode::SUCCESS;
65}
66
67StatusCode ZdcRecTool::recoZdcModules(const xAOD::ZdcModuleContainer& moduleContainer)
68{
69 if (!m_eventReady)
70 {
71 ATH_MSG_INFO("Event not ready for ZDC reco!");
72 return StatusCode::FAILURE;
73 }
74
75 for (const auto zdcModule : moduleContainer)
76 {
77 ATH_CHECK(recoZdcModule(*zdcModule));
78 }
79 return StatusCode::SUCCESS;
80}
81
83{
84 if (!m_init)
85 {
86 ATH_MSG_INFO("Tool not initialized!");
87 return StatusCode::FAILURE;
88 }
89 m_eventReady = false;
91 m_eventReady = true;
92
94
95 return StatusCode::SUCCESS;
96}
97
98bool ZdcRecTool::sigprocMaxFinder(const std::vector<unsigned short>& adc, float deltaT, float& amp, float& time, float& qual)
99{
100 size_t nsamp = adc.size();
101 float presamp = adc.at(0);
102 unsigned short max_adc = 0;
103 int max_index = -1;
104 for (size_t i = 0;i<nsamp;i++)
105 {
106 if (adc[i]>max_adc)
107 {
108 max_adc = adc[i];
109 max_index = i;
110 }
111 }
112 amp = max_adc - presamp;
113 time = max_index*deltaT;
114 qual = 1.;
115
116 if(max_index==-1)
117 {
118 qual=0.;
119 return false;
120 }
121
122 return true;
123}
124
125bool ZdcRecTool::sigprocPeakFitter(const std::vector<unsigned short>& adc, float deltaT, float& amp, float& time, float& qual)
126{
127 TGraph g;
128 size_t nsamp = adc.size();
129 float presamp = adc.at(0);
130 unsigned short max_adc = 0;
131 for (size_t i = 0;i<nsamp;i++)
132 {
133 if (adc.at(i)>max_adc)
134 {
135 max_adc = adc.at(i);
136 }
137 g.SetPoint(i,i*deltaT,adc.at(i)-presamp);
138 }
139 double timeScale = deltaT/12.5;
140 m_tf1FermiExpFit->SetParameters(max_adc-presamp,30*timeScale, 2.5*timeScale, 25*timeScale);
141 m_tf1FermiExpFit->SetParLimits(0,0,1024);
142 m_tf1FermiExpFit->SetParLimits(1,10*timeScale,50*timeScale);
143 m_tf1FermiExpFit->FixParameter(2,2.5*timeScale);
144 m_tf1FermiExpFit->SetParLimits(3,10*timeScale,40*timeScale);
145 g.Fit("FermiExpFit","QWR","");
146 amp = m_tf1FermiExpFit->GetMaximum();
147 time = m_tf1FermiExpFit->GetMaximumX();
148 qual = 1.;
149 return true;
150}
151
152bool ZdcRecTool::sigprocSincInterp(const std::vector<unsigned short>& adc, float deltaT, float& amp, float& time, float& qual)
153{
154 size_t nsamp = adc.size();
155 float presamp = adc.at(0);
156 m_tf1SincInterp->SetParameter(0,deltaT);
157 for (size_t i = 0;i<nsamp;i++)
158 {
159 m_tf1SincInterp->SetParameter(i+1,adc.at(i)-presamp);
160 }
161 amp = m_tf1SincInterp->GetMaximum();
162 time = m_tf1SincInterp->GetMaximumX();
163 qual = 1.;
164 return true;
165}
166
167double SincInterp(double* xvec, double* pvec)
168{
169 // pvec are the sample values
170 double ret = 0;
171 double T = pvec[0]; // deltaT
172 double t = xvec[0];
173 for (int isamp = 0;isamp<7;isamp++)
174 {
175 double arg = (t - isamp*T)/T;
176 if (arg!=0.0)
177 {
178 ret += pvec[isamp+1] * std::sin(TMath::Pi()*arg)/(TMath::Pi()*arg);
179 }
180 }
181 return ret;
182}
183
184double FermiExpFit(double* xvec, double* pvec)
185{
186 const float offsetScale = 3;
187
188 double t = xvec[0];
189
190 double amp = pvec[0];
191 double t0 = pvec[1];
192 double tau1 = pvec[2];
193 double tau2 = pvec[3];
194
195 double tauRatio = tau2/tau1;
196 double tauRatioMinunsOne = tauRatio - 1;
197
198 double norm = ( std::exp(-offsetScale/tauRatio)*pow(1./tauRatioMinunsOne, 1./(1 + tauRatio))/
199 ( 1 + pow(1./tauRatioMinunsOne, 1./(1 + 1/tauRatio))) );
200
201 double deltaT = t - (t0 - offsetScale*tau1);
202 if (deltaT < 0) deltaT = 0;
203
204 double expTerm = std::exp(-deltaT/tau2);
205 double fermiTerm = 1./(1. + std::exp(-(t - t0)/tau1));
206
207 return amp*expTerm*fermiTerm/norm;
208}
209
210} // namespace ZDC
211
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
std::array< fp_t, 2 > pvec
static Double_t t0
constexpr int pow(int base, int exp) noexcept
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
bool sigprocMaxFinder(const std::vector< unsigned short > &adc, float deltaT, float &amp, float &time, float &qual)
ZdcRecTool(const std::string &name)
TF1 * m_tf1FermiExpFit
Definition ZdcRecTool.h:48
std::string m_zdcModuleContainerName
Definition ZdcRecTool.h:58
std::string m_zdcRecConfigPath
Definition ZdcRecTool.h:55
bool sigprocSincInterp(const std::vector< unsigned short > &adc, float deltaT, float &amp, float &time, float &qual)
bool sigprocPeakFitter(const std::vector< unsigned short > &adc, float deltaT, float &amp, float &time, float &qual)
std::string m_name
Definition ZdcRecTool.h:51
TF1 * m_tf1SincInterp
Definition ZdcRecTool.h:47
virtual ~ZdcRecTool()
virtual StatusCode recoZdcModules(const xAOD::ZdcModuleContainer &moduleContainer) override
virtual StatusCode recoZdcModule(const xAOD::ZdcModule &module) override
virtual StatusCode reprocessZdc() override
const xAOD::ZdcModuleContainer * m_zdcModules
Definition ZdcRecTool.h:59
virtual StatusCode initializeTool() override
Initialize the tool.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
double SincInterp(const double *xvec, const double *pvec)
double FermiExpFit(double *xvec, double *pvec)
ZdcModuleContainer_v1 ZdcModuleContainer
ZdcModule_v1 ZdcModule
Definition ZdcModule.h:15