ATLAS Offline Software
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 
11 namespace 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 
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 
98 bool 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 
125 bool 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 
152 bool 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 
167 double 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 
184 double 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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
ZDC::ZdcRecTool::m_tf1FermiExpFit
TF1 * m_tf1FermiExpFit
Definition: ZdcRecTool.h:48
PlotCalibFromCool.norm
norm
Definition: PlotCalibFromCool.py:100
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:126
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ZDC::ZdcRecTool::sigprocPeakFitter
bool sigprocPeakFitter(const std::vector< unsigned short > &adc, float deltaT, float &amp, float &time, float &qual)
Definition: ZdcRecTool.cxx:125
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
ALFA_EventTPCnv_Dict::t0
std::vector< ALFA_RawData_p1 > t0
Definition: ALFA_EventTPCnvDict.h:42
xAOD::ZdcModule_v1
Class containing ZDC Module information.
Definition: ZdcModule_v1.h:25
asg
Definition: DataHandleTestTool.h:28
ZDC::ZdcRecTool::~ZdcRecTool
virtual ~ZdcRecTool()
Definition: ZdcRecTool.cxx:26
ZDC::ZdcRecTool::sigprocSincInterp
bool sigprocSincInterp(const std::vector< unsigned short > &adc, float deltaT, float &amp, float &time, float &qual)
Definition: ZdcRecTool.cxx:152
ZDC::SincInterp
double SincInterp(const double *xvec, const double *pvec)
Definition: ZdcSincInterp.cxx:11
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
ZdcRecTool.h
ZDC::ZdcRecTool::m_init
bool m_init
Definition: ZdcRecTool.h:53
ZDC::ZdcRecTool::m_zdcModuleContainerName
std::string m_zdcModuleContainerName
Definition: ZdcRecTool.h:58
python.PyAthena.module
module
Definition: PyAthena.py:134
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ZDC::ZdcRecTool::m_tf1SincInterp
TF1 * m_tf1SincInterp
Definition: ZdcRecTool.h:47
lumiFormat.i
int i
Definition: lumiFormat.py:92
ret
T ret(T t)
Definition: rootspy.cxx:260
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ZDC::ZdcRecTool::m_zdcRecConfigPath
std::string m_zdcRecConfigPath
Definition: ZdcRecTool.h:55
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ZDC::ZdcRecTool::ZdcRecTool
ZdcRecTool(const std::string &name)
Definition: ZdcRecTool.cxx:14
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
ZDC::ZdcRecTool::initializeTool
virtual StatusCode initializeTool() override
Initialize the tool.
Definition: ZdcRecTool.cxx:31
ZDC::ZdcRecTool::m_name
std::string m_name
Definition: ZdcRecTool.h:51
ZDC::ZdcRecTool::m_eventReady
bool m_eventReady
Definition: ZdcRecTool.h:57
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ZDC::ZdcRecTool::reprocessZdc
virtual StatusCode reprocessZdc() override
Definition: ZdcRecTool.cxx:82
ZDC::ZdcRecTool::sigprocMaxFinder
bool sigprocMaxFinder(const std::vector< unsigned short > &adc, float deltaT, float &amp, float &time, float &qual)
Definition: ZdcRecTool.cxx:98
ZDC::ZdcRecTool::recoZdcModules
virtual StatusCode recoZdcModules(const xAOD::ZdcModuleContainer &moduleContainer) override
Definition: ZdcRecTool.cxx:67
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ReadFloatFromCool.adc
adc
Definition: ReadFloatFromCool.py:48
ZDC::ZdcRecTool::recoZdcModule
virtual StatusCode recoZdcModule(const xAOD::ZdcModule &module) override
Definition: ZdcRecTool.cxx:53
ZDC
Definition: RpdSubtractCentroidTool.cxx:13
ZDC::ZdcRecTool::m_zdcModules
const xAOD::ZdcModuleContainer * m_zdcModules
Definition: ZdcRecTool.h:59
beamspotman.qual
qual
Definition: beamspotman.py:481
pvec
std::array< fp_t, 2 > pvec
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:9
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
python.DataFormatRates.env
env
Definition: DataFormatRates.py:32
ZDC::FermiExpFit
double FermiExpFit(double *xvec, double *pvec)
Definition: ZdcRecTool.cxx:184