27#include "GaudiKernel/IInterface.h"
28#include "GaudiKernel/MsgStream.h"
53 const std::string& name,
54 const IInterface* parent) :
65 declareInterface<ZdcRecChannelTool>(
this);
68 "Supress channels with only 0");
71 "Minimum difference between min and max to be considered a signal");
87 msg(MSG::INFO) <<
"Initializing " << name() <<
endmsg;
103 msg(MSG::INFO) <<
"Using a time step of "
105 <<
"ps for the Bandwidth Limited Sin(x)/x Interpolation: "
117 m_spline = gsl_spline_alloc (interp_type, 14);
120 msg(MSG::DEBUG) <<
"--> ZDC : START OF MODIFICATION 0" <<
endmsg ;
122 const ZdcID* zdcId =
nullptr;
123 if (
detStore()->retrieve( zdcId ).isFailure() ) {
124 msg(MSG::ERROR) <<
"execute: Could not retrieve ZdcID object from the detector store" <<
endmsg;
125 return StatusCode::FAILURE;
128 msg(MSG::DEBUG) <<
"execute: retrieved ZdcID" <<
endmsg;
132 msg(MSG::DEBUG) <<
"--> ZDC : END OF MODIFICATION 0" <<
endmsg ;
133 return StatusCode::SUCCESS;
140 msg(MSG::INFO) <<
"Finalizing " << name() <<
endmsg;
145 return StatusCode::SUCCESS;
185 std::vector<std::vector<int> > wfm;
187 std::vector<int>::iterator it;
189 std::vector<float> energy_sum;
190 std::vector<float> energy_peak;
191 std::vector<float> time_cfd;
192 std::vector<float> time_sratio;
193 std::vector<float> chi;
199 std::vector<float> vcfd1;
200 std::vector<float> vcfd2;
201 std::vector<float> vcfd3;
214 for (
const ZdcDigits* digits_p : mydata) {
216 msg(MSG::DEBUG) <<
"--> ZDC : START OF MODIFICATION " <<
endmsg ;
217 id = digits_p->identify();
221 mChannel =
m_zdcId->channel(
id);
223 msg(MSG::DEBUG) <<
"--> ZDC : ZdcRecChannelTool::makeRawFromDigits: "
224 <<
" id;Side;Module;Type;Channel: "
225 <<
id.getString() <<
";"
243 wfm[0] = digits_p->get_digits_gain0_delay0();
244 if (wfm[0].
empty()) {
245 msg(MSG::DEBUG) <<
"ZERO SIZE g0d0 at ID " <<
id.getString() <<
endmsg;
249 wfm[1] = digits_p->get_digits_gain1_delay0();
250 if (wfm[1].
empty()) {
251 msg(MSG::DEBUG) <<
"ZERO SIZE g1d0 at ID " <<
id.getString() <<
endmsg;
256 msg(MSG::DEBUG) <<
" ------- 1 " <<
endmsg;
275 wfm[2] = digits_p->get_digits_gain0_delay1();
276 wfm[3] = digits_p->get_digits_gain1_delay1();
282 msg(MSG::DEBUG) <<
" ------- 2 " <<
endmsg;
287 for (vit = wfm.begin(); vit<wfm.end(); ++vit) {
288 if (vit->empty()) vit->resize(7);
290 for (it=vit->begin(); it<vit->end();++it) {
322 msg(MSG::DEBUG) <<
" ------- 3 " <<
endmsg;
354 for (vit = wfm.begin(); vit<wfm.end(); ++vit) {
356 soma = std::accumulate(v.begin(), v.end(), 0) ;
357 pico = *(std::max_element(v.begin(),v.end()) );
358 energy_sum.push_back ((
float) soma);
359 energy_peak.push_back((
float) pico);
378 imax = std::max_element(v.begin(),v.end()) - v.begin();
386 time_sratio.push_back(tsr);
389 msg(MSG::DEBUG) <<
"--> ZDC : ZdcRecChannelTool " <<
id.getString() <<
391 " Energy Sum=" << soma <<
392 " Energy Peak=" << pico <<
393 " Chi=" << *(chi.end() -1) <<
394 " t0=" <<
t0 <<
" t1=" << t1 <<
396 " Time by CFD=" << tzc <<
397 " Peak at imax = " <<
imax <<
398 " v[imax-1] = " << (
imax > 0 ? v[
imax-1] : 0) <<
399 " V[imax] = " << v[
imax] <<
400 " Sample Ratio A1/A2=" << tsr <<
endmsg;
404 msg(MSG::DEBUG) <<
" ------- 5 " <<
endmsg;
427 z->setEnergy (i, energy_peak[i]);
428 z->setTime (i, time_sratio[i]);
429 z->setChi (i, chi[i]);
433 z->setChi (i+k, chi[i]);
435 z->setEnergy (i+2*k, energy_sum[i]);
437 z->setChi (i+2*k, chi[i]);
446 msg(MSG::DEBUG) <<
" ------- 6 " <<
endmsg;
448 msg(MSG::DEBUG) <<
"--> ZDC : ZdcRecChannelTool ChannelCollection size " << ChannelCollection.
size() <<
endmsg ;
462 for (
const ZdcDigits* digits_p : mydata) {
463 digits_p->identify();
466 int ncal = ChannelCollection.
size();
467 msg(MSG::DEBUG) <<
" Zdc ---> Calibration for " << ncal <<
" channels " <<
endmsg;
478 unsigned int nsamples_local = 14;
485 std::vector<float> vaux;
486 unsigned int tmin = 0;
487 unsigned int tmax = 0;
495 int max_iterations = 100;
499 gsl_root_fsolver *s = gsl_root_fsolver_alloc (T);
508 std::vector<int>::iterator it;
510 std:: vector<float>
result;
514 msg(MSG::DEBUG) <<
"--> ZDC : ZdcRecChannelTool::getTimingCFD: Id " <<
id.getString() ;
524 for (vit = wfm.begin(); vit<wfm.end(); ++vit) {
527 for (it=
y.begin();it !=
y.end();++it) {
531 for (i=0;i<nsamples_local;i++) {
536 gsl_spline_init (
m_spline, t, v, nsamples_local);
540 for (i=0;i<nsamples_local;i++) {
547 gsl_spline_init (
m_spline, t, vf, nsamples_local);
557 vaux.assign(vf,vf+14);
558 tmin = std::min_element(vaux.begin(), vaux.end()) - vaux.begin();
559 tmax = std::max_element(vaux.begin(), vaux.end()) - vaux.begin();
593 gsl_root_fsolver_set (s, &
F, x_lo, x_hi);
599 status = gsl_root_fsolver_iterate(s);
600 r = gsl_root_fsolver_root(s);
601 x_lo = gsl_root_fsolver_x_lower(s);
602 x_hi = gsl_root_fsolver_x_upper(s);
603 status = gsl_root_test_interval (x_lo, x_hi, 0, 0.001);
607 while (status == GSL_CONTINUE && iterations < max_iterations);
611 gsl_root_fsolver_free (s);
621 return gsl_spline_eval (p->m_spline, x0, p->m_interp_acc);
651 std::vector<float> vt(7);
654 std::vector<float>::iterator vf_it;
662 msg(MSG::DEBUG) <<
"--> ZDC : START OF MODIFICATION 2 " <<
endmsg ;
666 mChannel =
m_zdcId->channel(
id);
667 msg(MSG::DEBUG) <<
"--> ZDC : ZdcRecChannelTool::getTimingSinc: "
668 <<
" id;Side;Module;Type;Channel: "
669 <<
id.getString() <<
";"
675 for (vvi_it = wfm.begin(); vvi_it<wfm.end(); ++vvi_it) {
691 x = (TMath::Pi() *(t*0.1 - i*25.))/25. ;
692 if (fabs(
x) < 1e-8) {
696 z =
z +
y[i]*(sin(
x)/(
x));
721 if ( (mSide == -1) && (mType == 0) && (mModule == 0) && (mChannel == 0) ) {
724 -0.483265 *
pow(tfpeak,2) +
725 0.00234842 *
pow(tfpeak,3);
730 if ( (mSide == 1) && (mType == 0) && (mModule == 0) && (mChannel == 0) ) {
735 -1.229 *
pow(tfpeak,2) +
736 0.006276 *
pow(tfpeak,3);
741 -1.19169 *
pow(tfpeak,2) +
742 0.005659 *
pow(tfpeak,3);
778 double CFD_frac = 1.0;
813 for (vit = wfm.begin(); vit<wfm.end(); ++vit) {
814 if ( (i < wfmIndex) && (mType == 0) )
820 for(
int I=0;
I<NSlice;
I++) {Slices[
I]=
y[
I];}
823 zdcSignalSinc.
process(Slices,gain,pedestal,CFD_frac,corr);
832 msg(MSG::DEBUG) <<
"--> ZDC : ZdcRecChannelTool::getTimingSinc2: "
static const Attributes_t empty
constexpr int pow(int base, int exp) noexcept
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
int process(double *, double gain=1., double ped=0., double frac=1., bool corr=true)