21 #include "CoralBase/Blob.h"
27 #include "CaloDetDescr/CaloDetDescrElement.h"
35 #include "tbb/parallel_for.h"
42 m_calo_dd_man(nullptr),
44 m_larPhysWaveBin(nullptr),
45 m_groupingType(
"SubDetector")
104 return StatusCode::FAILURE;
108 if (
sc.isFailure()) {
110 return StatusCode::FAILURE;
118 if (
sc.isFailure()) {
120 return StatusCode::FAILURE;
129 if (
sc.isFailure()) {
130 msg(MSG::ERROR) <<
"Could not get LArOnlineID helper !" <<
endmsg;
131 return StatusCode::FAILURE;
140 if (
sc.isFailure()) {
141 msg(MSG::ERROR) <<
"Could not get LArOnlineID helper !" <<
endmsg;
142 return StatusCode::FAILURE;
161 return StatusCode::SUCCESS;
184 ATH_CHECK(caloSuperCellMgrHandle.isValid());
202 ATH_MSG_INFO(
" Will use helper class for start time." );
227 m_DSPConfig = std::make_unique<LArDSPConfig>(attrList);
233 return StatusCode::FAILURE;
258 std::unique_ptr<tbb::global_control> tbbgc;
261 tbbgc=std::make_unique<tbb::global_control>( tbb::global_control::max_allowed_parallelism,
m_nThreads);
268 tbb::parallel_for(tbb::blocked_range<size_t>(0,
m_allChannelData.size()),looper);
283 std::unique_ptr<LArOFCComplete> larOFCComplete=std::make_unique<LArOFCComplete>();
285 if (
sc.isFailure()) {
286 ATH_MSG_ERROR(
"Failed to set groupingType for LArOFCComplete object" );
290 if (
sc.isFailure()) {
296 std::unique_ptr<LArOFCComplete> larOFCCompleteV2=std::make_unique<LArOFCComplete>();
298 if (
sc.isFailure()) {
299 ATH_MSG_ERROR(
"Failed to set groupingType for LArOFCComplete object" );
303 if (
sc.isFailure()) {
309 std::unique_ptr<LArOFCBinComplete> larOFCBinComplete;
311 larOFCBinComplete=std::make_unique<LArOFCBinComplete>();
313 if (
sc.isFailure()) {
314 ATH_MSG_ERROR(
"Failed to set groupingType for LArOFCBinComplete object" );
318 if (
sc.isFailure() ) {
319 ATH_MSG_ERROR(
"Could not initialize LArOFCComplete data object - exit!" ) ;
325 std::unique_ptr<LArShapeComplete> larShapeComplete;
327 larShapeComplete = std::make_unique<LArShapeComplete>();
329 if (
sc.isFailure()) {
330 ATH_MSG_ERROR(
"Failed to set groupingType for LArShapeComplete object" );
334 if (
sc.isFailure()) {
335 ATH_MSG_ERROR(
"Failed initialize LArShapeComplete object" );
347 if (chanData.faultyOFC) ++nFailed;
350 const int gain=chanData.gain;
352 const std::vector<std::vector<float> > & allPhaseOFCa=chanData.ofc_a;
353 const std::vector<std::vector<float> > & allPhaseOFCb=chanData.ofc_b;
354 const std::vector<std::vector<float> > & allPhaseShape=chanData.shape;
355 const std::vector<std::vector<float> > & allPhaseShapeDer=chanData.shapeDer;
356 larOFCComplete->
set(ch_id,
gain,allPhaseOFCa,allPhaseOFCb,chanData.tstart,chanData.timeBinWidthOFC);
357 if (larOFCBinComplete) larOFCBinComplete->
set(ch_id,
gain,chanData.phasewMaxAt3);
358 if (
m_fillShape ) larShapeComplete->
set(ch_id,
gain,allPhaseShape,allPhaseShapeDer,chanData.tstart,chanData.timeBinWidthOFC);
362 const std::vector<std::vector<float> > & allPhaseOFCV2a=chanData.ofcV2_a;
363 const std::vector<std::vector<float> > & allPhaseOFCV2b=chanData.ofcV2_b;
364 larOFCCompleteV2->
set(ch_id,
gain,allPhaseOFCV2a,allPhaseOFCV2b,chanData.tstart,chanData.timeBinWidthOFC);
371 ATH_MSG_ERROR(
"Number of channels * gains with failed OFC verification: " << nFailed );
379 if (
sc.isFailure()) {
381 return StatusCode::FAILURE;
386 if (
sc.isFailure()) {
387 ATH_MSG_ERROR(
"Could not symlink ILArOFC with LArOFCComplete." );
388 return StatusCode::FAILURE;
396 if (
sc.isFailure()) {
398 return StatusCode::FAILURE;
403 if (
sc.isFailure()) {
404 ATH_MSG_ERROR(
"Could not symlink ILArOFC with LArOFCComplete." );
405 return StatusCode::FAILURE;
410 if (larOFCBinComplete) {
412 if (
sc.isFailure()) {
414 return StatusCode::FAILURE;
422 if (
sc.isFailure()) {
424 return StatusCode::FAILURE;
427 ATH_MSG_DEBUG(
"Trying to symlink ILArShape with LArShapeComplete");
429 if (
sc.isFailure()) {
430 ATH_MSG_ERROR(
"Could not symlink ILArShape with LArShapeComplete." );
431 return StatusCode::FAILURE;
433 ATH_MSG_INFO(
"ILArShape symlink with LArShapeComplete successfully" ) ;
440 ATH_MSG_INFO(
"Reverted corrections of non-cost wave container");
443 return StatusCode::SUCCESS;
466 <<
") is too small to fit your OFC request (" <<
m_nPoints <<
" points)" ) ;
494 aWave = aWave * (1./peak);
514 float maxSampleValAt3=-1;
529 Eigen::MatrixXd acInverseV2;
543 for (
unsigned iPhase=0;iPhase<
m_nPhases;iPhase++) {
546 <<
", Gain = " <<
gain <<
", Phase = " << iPhase <<
":");
550 std::vector<float>& theSamples=chanData.
shape[iPhase];
551 std::vector<float>& theSamplesDer=chanData.
shapeDer[iPhase];
557 for (
unsigned iSample=0;iSample<
m_nSamples;++iSample){
559 theSamples.push_back( aWave.
getSample(tbin) );
560 theSamplesDer.push_back( aDerivedWave.
getSample(tbin) );
565 maxSampleValAt3=theSamples[2];
571 Eigen::VectorXd delta;
573 if (thisChanUseDelta || thisChanUseDeltaV2) {
574 std::vector<float> theSamples32;
575 theSamples32.reserve(32);
576 for (
unsigned iSample=0;iSample<32 ;++iSample){
578 if (tbin>=aWave.
getSize())
continue;
579 theSamples32.push_back( aWave.
getSample(tbin) );
586 std::vector<float>& vOFC_a= chanData.
ofc_a[iPhase];
587 std::vector<float>& vOFC_b= chanData.
ofc_b[iPhase];
589 if (thisChanUseDelta) {
590 optFiltDelta(theSamples,theSamplesDer,acInverse,delta,vOFC_a,vOFC_b);
593 optFilt(theSamples,theSamplesDer,acInverse,vOFC_a,vOFC_b);
605 std::vector<float>& vOFCV2_a= chanData.
ofcV2_a[iPhase];
606 std::vector<float>& vOFCV2_b= chanData.
ofcV2_b[iPhase];
608 if (thisChanUseDeltaV2) {
609 optFiltDelta(theSamples,theSamplesDer,acInverseV2,delta,vOFCV2_a,vOFCV2_b);
612 optFilt(theSamples,theSamplesDer,acInverseV2,vOFCV2_a,vOFCV2_b);
642 if (
sc.isFailure()) {
651 WAVEIT it_e=waveCnt->
end(
gain);
652 for (;
it!=it_e;++
it) {
654 if (
cabling->isOnlineConnected (chid)){
663 return StatusCode::SUCCESS;
680 ATH_MSG_INFO(
"LArCaliWaveContainer: Corrections not yet applied, applying them now..." );
682 ATH_MSG_ERROR(
"Failed to apply corrections to LArCaliWaveContainer!" );
683 return StatusCode::FAILURE;
686 ATH_MSG_INFO(
"Applied corrections to non-const Wave container");
694 return StatusCode::FAILURE;
703 WAVEIT it_e=waveCnt->
end(
gain);
704 for (;
it!=it_e;++
it) {
706 for (
const auto& cw : wVec) {
715 return StatusCode::SUCCESS;
719 void LArOFCAlg::optFilt(
const std::vector<float> &gWave,
const std::vector<float> &gDerivWave,
const Eigen::MatrixXd& acInverse,
720 std::vector<float>& vecOFCa, std::vector<float>& vecOFCb) {
721 assert(gWave.size()==gDerivWave.size());
723 const int optNpt = gWave.size();
725 Eigen::VectorXd gResp(optNpt), gDerivResp(optNpt);
726 for (
int i=0;
i<optNpt;
i++) {
728 gDerivResp[
i] = gDerivWave[
i];
731 Eigen::Matrix2d isol;
733 (gResp.transpose()*acInverse*gResp)[0],
734 (gResp.transpose()*acInverse*gDerivResp)[0],
735 (gDerivResp.transpose()*acInverse*gResp)[0],
736 (gDerivResp.transpose()*acInverse*gDerivResp)[0];
739 Eigen::Vector2d Atau;
740 Eigen::Vector2d Ktemp;
741 Eigen::Matrix2d isolInv = isol.inverse();
750 Atau = isolInv*Ktemp;
753 Eigen::VectorXd OFCa = Amp[0]*acInverse*gResp + Amp[1]*acInverse*gDerivResp;
754 Eigen::VectorXd OFCb = Atau[0]*acInverse*gResp + Atau[1]*acInverse*gDerivResp;
757 vecOFCa.resize(optNpt);
758 vecOFCb.resize(optNpt);
759 for (
int i=0;
i<optNpt;
i++) {
771 const Eigen::MatrixXd& acInverse,
const Eigen::VectorXd& delta,
772 std::vector<float>& vecOFCa, std::vector<float>& vecOFCb) {
776 assert(gWave.size()==gDerivWave.size());
778 const int optNpt = gWave.size();
780 Eigen::VectorXd gResp(optNpt), gDerivResp(optNpt);
781 for (
int i=0;
i<optNpt;
i++) {
783 gDerivResp[
i] = gDerivWave[
i];
798 Eigen::Matrix3d isol;
800 (gResp.transpose()*acInverse*gResp)[0],
801 (gResp.transpose()*acInverse*gDerivResp),
802 (gResp.transpose()*acInverse*delta)[0],
804 (gDerivResp.transpose()*acInverse*gResp)[0],
805 (gDerivResp.transpose()*acInverse*gDerivResp)[0],
806 (gDerivResp.transpose()*acInverse*delta)[0],
808 (delta.transpose()*acInverse*gResp)[0],
809 (delta.transpose()*acInverse*gDerivResp)[0],
810 (delta.transpose()*acInverse*delta)[0];
814 Eigen::Vector3d Atau;
815 Eigen::Vector3d Ktemp;
816 Eigen::Matrix3d isolInv = isol.inverse();
828 Atau = isolInv*Ktemp;
831 Eigen::VectorXd OFCa = Amp[0]*acInverse*gResp + Amp[1]*acInverse*gDerivResp + Amp[2]*acInverse * delta;
832 Eigen::VectorXd OFCb = Atau[0]*acInverse*gResp + Atau[1]*acInverse*gDerivResp + Atau[2]*acInverse * delta ;
836 vecOFCa.resize(optNpt);
837 vecOFCb.resize(optNpt);
838 for (
int i=0;
i<optNpt;
i++) {
846 const float LArOFCAlg::m_fcal3Delta[5] ={0.0790199937765, 0.0952000226825, 0.0790199937765, 0.0952000226825, 0.0790199937765};
847 const float LArOFCAlg::m_fcal2Delta[5]={-0.01589001104, -0.0740399733186, -0.01589001104, -0.0740399733186, -0.01589001104};
848 const float LArOFCAlg::m_fcal1Delta[5] ={0.0679600232979, -0.139479996869, 0.0679600232979, -0.139479996869, 0.0679600232979};
878 for (
unsigned int i = 0;
i<samples.size();++
i) {
917 if (
cabling->isOnlineConnected (chid)){
921 ATH_MSG_ERROR(
" dde = 0 , onl_id, ofl_id= "<< chid<<
" "<<ofl_id );
930 if (fabs(dde->
eta())>4.0){
940 if (fabs(dde->
eta())>4.0){
956 const std::vector<float>& Shape,
const char* ofcversion,
const unsigned phase)
const {
959 float recAmpl=0, recTime=0;
960 for (
unsigned iSample=0;iSample<
m_nSamples;++iSample){
962 #ifdef LAROFCALG_DEBUGOUTPUT
963 ATH_MSG_VERBOSE(
"a["<<iSample<<
"]="<<vOFC_a[iSample] <<
" b["<<iSample<<
"]="<<vOFC_b[iSample]
964 <<
" Sample=" << aWave.getSample(tbin));
966 recAmpl += OFCa[iSample] * Shape[iSample];
967 recTime += OFCb[iSample] * Shape[iSample];
975 ATH_MSG_WARNING(
"Applying phase " <<
phase <<
" of " << ofcversion <<
" to original wave yields an Amplitude of "<< recAmpl
981 ATH_MSG_WARNING(
"Applying phase " <<
phase <<
" of " << ofcversion <<
" to original wave yields a time offset of " << recTime
990 mLog << MSG::WARNING <<
"OFCs";
997 #ifdef LAROFCALG_DEBUGOUTPUT
998 #undef LAROFCALG_DEBUGOUTPUT