From 5dd282d239028b15f3eb12f1739b3bf43ebe9964 Mon Sep 17 00:00:00 2001 From: Sean Dobbs Date: Wed, 8 May 2024 10:34:21 -0400 Subject: [PATCH] Add code to mask dead channels when reading in HDDM/REST events This is mainly for random hits that are merged in, when the bad channel mask was updated after the random trigger files were created --- src/libraries/HDDM/DEventSourceHDDM.cc | 22 ++++++++++++++ src/libraries/HDDM/DEventSourceHDDM.h | 4 +++ src/libraries/HDDM/DEventSourceREST.cc | 30 +++++++++++++++++-- src/libraries/HDDM/DEventSourceREST.h | 9 ++++++ .../TAGGER/DTAGHHit_factory_Calib.cc | 20 ++++++------- src/libraries/TAGGER/DTAGHHit_factory_Calib.h | 3 +- .../TAGGER/DTAGMHit_factory_Calib.cc | 24 +++++++-------- src/libraries/TAGGER/DTAGMHit_factory_Calib.h | 2 +- 8 files changed, 88 insertions(+), 26 deletions(-) diff --git a/src/libraries/HDDM/DEventSourceHDDM.cc b/src/libraries/HDDM/DEventSourceHDDM.cc index 1bcb118622..fb43d2aa37 100644 --- a/src/libraries/HDDM/DEventSourceHDDM.cc +++ b/src/libraries/HDDM/DEventSourceHDDM.cc @@ -43,6 +43,9 @@ using namespace std; #include #include +#include +#include + //------------------------------------------------------------------ // Binary predicate used to sort hits @@ -253,6 +256,13 @@ jerror_t DEventSourceHDDM::GetObjects(JEvent &event, JFactory_base *factory) psGeom = psGeomVect[0]; + // load dead channel tables + if(!DTAGHHit_factory_Calib::load_ccdb_constants(loop, "counter_quality", "code", tagh_counter_quality)) { + jerr << "Error loading /PHOTON_BEAM/hodoscope/counter_quality in DEventSourceHDDM::GetObjects() ... " << endl; + } + if(!DTAGMHit_factory_Calib::load_ccdb_constants(loop, "fiber_quality", "code", tagm_fiber_quality)) { + jerr << "Error loading /PHOTON_BEAM/microscope/fiber_quality in DEventSourceHDDM::GetObjects() ... " << endl; + } } // Warning: This class is not completely thread-safe and can fail if running @@ -2503,6 +2513,12 @@ jerror_t DEventSourceHDDM::Extract_DTAGMHit(hddm_s::HDDM *record, const hddm_s::TaggerHitList &hits = iter->getTaggerHits(); hddm_s::TaggerHitList::iterator hiter; for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { + + // throw away hits from bad or noisy counters + int quality = tagm_fiber_quality[hiter->getRow()][hiter->getColumn()]; + if (quality != DTAGMHit_factory_Calib::k_fiber_good ) + continue; + DTAGMHit *taghit = new DTAGMHit(); taghit->E = hiter->getE(); taghit->t = hiter->getT(); @@ -2566,6 +2582,12 @@ jerror_t DEventSourceHDDM::Extract_DTAGHHit( hddm_s::HDDM *record, const hddm_s::TaggerHitList &hits = iter->getTaggerHits(); hddm_s::TaggerHitList::iterator hiter; for (hiter = hits.begin(); hiter != hits.end(); ++hiter) { + + // throw away hits from bad or noisy counters + int quality = tagh_counter_quality[hiter->getCounterId()]; + if (quality != DTAGHHit_factory_Calib::k_counter_good ) + continue; + DTAGHHit *taghit = new DTAGHHit(); taghit->E = hiter->getE(); taghit->t = hiter->getT(); diff --git a/src/libraries/HDDM/DEventSourceHDDM.h b/src/libraries/HDDM/DEventSourceHDDM.h index f52f26f5e6..6c85fadc2c 100644 --- a/src/libraries/HDDM/DEventSourceHDDM.h +++ b/src/libraries/HDDM/DEventSourceHDDM.h @@ -187,6 +187,10 @@ class DEventSourceHDDM:public JEventSource JCalibration *jcalib; float uscale[192],vscale[192]; + double tagh_counter_quality[TAGH_MAX_COUNTER+1]; + double tagm_fiber_quality[TAGM_MAX_ROW+1][TAGM_MAX_COLUMN+1]; + + }; #endif //_JEVENT_SOURCEHDDM_H_ diff --git a/src/libraries/HDDM/DEventSourceREST.cc b/src/libraries/HDDM/DEventSourceREST.cc index 277e4419f6..754d2f3f84 100644 --- a/src/libraries/HDDM/DEventSourceREST.cc +++ b/src/libraries/HDDM/DEventSourceREST.cc @@ -15,6 +15,9 @@ #include #include +#include +#include + #include #include @@ -308,6 +311,19 @@ jerror_t DEventSourceREST::GetObjects(JEvent &event, JFactory_base *factory) << " dy/dz=" << dBeamDirMap[locRunNumber].Y() << endl; + // load tagger quality tables +// dTAGHCounterQualities[locRunNumber] = new double[TAGH_MAX_COUNTER+1]; +// dTAGMFiberQualities[locRunNumber] = new double*[TAGM_MAX_ROW+1]; +// for(int i; iMakeJCalibration(jcalib->GetURL(), locRunNumber, REST_JANA_CALIB_CONTEXT ); @@ -655,7 +671,12 @@ jerror_t DEventSourceREST::Extract_DBeamPhoton(hddm_r::HDDM *record, if(column == 0) { continue; } - + + // throw away hits from bad or noisy counters + int quality = dTAGMFiberQualities[locRunNumber][0][column]; // I think this works for the row? - we are generally not worrying about the quality of individual fibers + if (quality != DTAGMHit_factory_Calib::k_fiber_good ) + continue; + DBeamPhoton* gamma = new DBeamPhoton(); double Elo_tagm = tagmGeom->getElow(column); @@ -716,7 +737,12 @@ jerror_t DEventSourceREST::Extract_DBeamPhoton(hddm_r::HDDM *record, if(counter == 0) { continue; } - + + // throw away hits from bad or noisy counters + int quality = dTAGHCounterQualities[locRunNumber][counter]; + if (quality != DTAGHHit_factory_Calib::k_counter_good ) + continue; + DBeamPhoton* gamma = new DBeamPhoton(); double Elo_tagh = taghGeom->getElow(counter); diff --git a/src/libraries/HDDM/DEventSourceREST.h b/src/libraries/HDDM/DEventSourceREST.h index b1b698d66e..ff09a48340 100644 --- a/src/libraries/HDDM/DEventSourceREST.h +++ b/src/libraries/HDDM/DEventSourceREST.h @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -140,6 +142,13 @@ class DEventSourceREST:public JEventSource map dTAGHGeoms; //unsigned int is run number map dTAGMGeoms; //unsigned int is run number + //map dTAGHCounterQualities; + map dTAGHCounterQualities; + //map dTAGMFiberQualities; + map dTAGMFiberQualities; + + + }; #endif //_JEVENT_SOURCEREST_H_ diff --git a/src/libraries/TAGGER/DTAGHHit_factory_Calib.cc b/src/libraries/TAGGER/DTAGHHit_factory_Calib.cc index 55615eb037..110bc31c60 100644 --- a/src/libraries/TAGGER/DTAGHHit_factory_Calib.cc +++ b/src/libraries/TAGGER/DTAGHHit_factory_Calib.cc @@ -97,15 +97,15 @@ jerror_t DTAGHHit_factory_Calib::brun(jana::JEventLoop *eventLoop, int32_t runnu else jerr << "Unable to get TAGH_TDC_BASE_TIME_OFFSET from /PHOTON_BEAM/hodoscope/base_time_offset !" << endl; - if (load_ccdb_constants("fadc_gains", "gain", fadc_gains) && - load_ccdb_constants("fadc_pedestals", "pedestal", fadc_pedestals) && - load_ccdb_constants("fadc_time_offsets", "offset", fadc_time_offsets) && - load_ccdb_constants("tdc_time_offsets", "offset", tdc_time_offsets) && - load_ccdb_constants("counter_quality", "code", counter_quality) && - load_ccdb_constants("tdc_timewalk", "c0", tdc_twalk_c0) && - load_ccdb_constants("tdc_timewalk", "c1", tdc_twalk_c1) && - load_ccdb_constants("tdc_timewalk", "c2", tdc_twalk_c2) && - load_ccdb_constants("tdc_timewalk", "c3", tdc_twalk_c3)) + if (load_ccdb_constants(eventLoop, "fadc_gains", "gain", fadc_gains) && + load_ccdb_constants(eventLoop, "fadc_pedestals", "pedestal", fadc_pedestals) && + load_ccdb_constants(eventLoop, "fadc_time_offsets", "offset", fadc_time_offsets) && + load_ccdb_constants(eventLoop, "tdc_time_offsets", "offset", tdc_time_offsets) && + load_ccdb_constants(eventLoop, "counter_quality", "code", counter_quality) && + load_ccdb_constants(eventLoop, "tdc_timewalk", "c0", tdc_twalk_c0) && + load_ccdb_constants(eventLoop, "tdc_timewalk", "c1", tdc_twalk_c1) && + load_ccdb_constants(eventLoop, "tdc_timewalk", "c2", tdc_twalk_c2) && + load_ccdb_constants(eventLoop, "tdc_timewalk", "c3", tdc_twalk_c3)) { return NOERROR; } @@ -273,7 +273,7 @@ jerror_t DTAGHHit_factory_Calib::fini(void) //--------------------- // load_ccdb_constants //--------------------- -bool DTAGHHit_factory_Calib::load_ccdb_constants( +bool DTAGHHit_factory_Calib::load_ccdb_constants( jana::JEventLoop *eventLoop, std::string table_name, std::string column_name, double result[TAGH_MAX_COUNTER+1]) diff --git a/src/libraries/TAGGER/DTAGHHit_factory_Calib.h b/src/libraries/TAGGER/DTAGHHit_factory_Calib.h index e08141ae45..bc34806b1c 100644 --- a/src/libraries/TAGGER/DTAGHHit_factory_Calib.h +++ b/src/libraries/TAGGER/DTAGHHit_factory_Calib.h @@ -44,7 +44,8 @@ class DTAGHHit_factory_Calib:public jana::JFactory{ double tdc_twalk_c2[TAGH_MAX_COUNTER+1]; double tdc_twalk_c3[TAGH_MAX_COUNTER+1]; - bool load_ccdb_constants(std::string table_name, + bool static load_ccdb_constants(jana::JEventLoop *eventLoop, + std::string table_name, std::string column_name, double table[TAGH_MAX_COUNTER+1]); diff --git a/src/libraries/TAGGER/DTAGMHit_factory_Calib.cc b/src/libraries/TAGGER/DTAGMHit_factory_Calib.cc index bf5093f786..5aa9d2678e 100644 --- a/src/libraries/TAGGER/DTAGMHit_factory_Calib.cc +++ b/src/libraries/TAGGER/DTAGMHit_factory_Calib.cc @@ -99,17 +99,17 @@ jerror_t DTAGMHit_factory_Calib::brun(jana::JEventLoop *eventLoop, int32_t runnu else jerr << "Unable to get TAGM_TDC_BASE_TIME_OFFSET from /PHOTON_BEAM/microscope/base_time_offset !" << endl; - if (load_ccdb_constants("fadc_gains", "gain", fadc_gains) && - load_ccdb_constants("fadc_pedestals", "pedestal", fadc_pedestals) && - load_ccdb_constants("fadc_time_offsets", "offset", fadc_time_offsets) && - load_ccdb_constants("tdc_time_offsets", "offset", tdc_time_offsets) && - load_ccdb_constants("fiber_quality", "code", fiber_quality) && - load_ccdb_constants("tdc_timewalk_corrections", "c0", tw_c0) && - load_ccdb_constants("tdc_timewalk_corrections", "c1", tw_c1) && - load_ccdb_constants("tdc_timewalk_corrections", "c2", tw_c2) && - load_ccdb_constants("tdc_timewalk_corrections", "threshold", tw_c3) && - load_ccdb_constants("tdc_timewalk_corrections", "reference", ref) && - load_ccdb_constants("integral_cuts", "integral", int_cuts)) + if (load_ccdb_constants(eventLoop, "fadc_gains", "gain", fadc_gains) && + load_ccdb_constants(eventLoop, "fadc_pedestals", "pedestal", fadc_pedestals) && + load_ccdb_constants(eventLoop, "fadc_time_offsets", "offset", fadc_time_offsets) && + load_ccdb_constants(eventLoop, "tdc_time_offsets", "offset", tdc_time_offsets) && + load_ccdb_constants(eventLoop, "fiber_quality", "code", fiber_quality) && + load_ccdb_constants(eventLoop, "tdc_timewalk_corrections", "c0", tw_c0) && + load_ccdb_constants(eventLoop, "tdc_timewalk_corrections", "c1", tw_c1) && + load_ccdb_constants(eventLoop, "tdc_timewalk_corrections", "c2", tw_c2) && + load_ccdb_constants(eventLoop, "tdc_timewalk_corrections", "threshold", tw_c3) && + load_ccdb_constants(eventLoop, "tdc_timewalk_corrections", "reference", ref) && + load_ccdb_constants(eventLoop, "integral_cuts", "integral", int_cuts)) { return NOERROR; } @@ -324,7 +324,7 @@ jerror_t DTAGMHit_factory_Calib::fini(void) //--------------------- // load_ccdb_constants //--------------------- -bool DTAGMHit_factory_Calib::load_ccdb_constants( +bool DTAGMHit_factory_Calib::load_ccdb_constants( jana::JEventLoop *eventLoop, std::string table_name, std::string column_name, double result[TAGM_MAX_ROW+1][TAGM_MAX_COLUMN+1]) diff --git a/src/libraries/TAGGER/DTAGMHit_factory_Calib.h b/src/libraries/TAGGER/DTAGMHit_factory_Calib.h index 03be9375e4..b8e2609a73 100644 --- a/src/libraries/TAGGER/DTAGMHit_factory_Calib.h +++ b/src/libraries/TAGGER/DTAGMHit_factory_Calib.h @@ -52,7 +52,7 @@ class DTAGMHit_factory_Calib: public jana::JFactory { double ref[TAGM_MAX_ROW+1][TAGM_MAX_COLUMN+1]; double int_cuts[TAGM_MAX_ROW+1][TAGM_MAX_COLUMN+1]; - bool load_ccdb_constants(std::string table_name, + bool static load_ccdb_constants(jana::JEventLoop *eventLoop, std::string table_name, std::string column_name, double table[TAGM_MAX_ROW+1][TAGM_MAX_COLUMN+1]); private: