Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code to mask dead channels when reading in HDDM/REST events #846

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/libraries/HDDM/DEventSourceHDDM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ using namespace std;
#include <ECAL/DECALGeometry.h>
#include <ECAL/DECALHit.h>

#include <TAGGER/DTAGHHit_factory_Calib.h>
#include <TAGGER/DTAGMHit_factory_Calib.h>


//------------------------------------------------------------------
// Binary predicate used to sort hits
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/libraries/HDDM/DEventSourceHDDM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
30 changes: 28 additions & 2 deletions src/libraries/HDDM/DEventSourceREST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include <JANA/JEvent.h>
#include <DANA/DStatusBits.h>

#include <TAGGER/DTAGHHit_factory_Calib.h>
#include <TAGGER/DTAGMHit_factory_Calib.h>

#include <DVector2.h>
#include <DEventSourceREST.h>

Expand Down Expand Up @@ -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; i<TAGM_MAX_ROW+1; i++)
// dTAGMFiberQualities[locRunNumber][i] = new double[TAGM_MAX_COLUMN+1];

if(!DTAGHHit_factory_Calib::load_ccdb_constants(locEventLoop, "counter_quality", "code", dTAGHCounterQualities[locRunNumber])) {
jerr << "Error loading /PHOTON_BEAM/hodoscope/counter_quality in DEventSourceREST::GetObjects() ... " << endl;
}
if(!DTAGMHit_factory_Calib::load_ccdb_constants(locEventLoop, "fiber_quality", "code", dTAGMFiberQualities[locRunNumber])) {
jerr << "Error loading /PHOTON_BEAM/microscope/fiber_quality in DEventSourceREST::GetObjects() ... " << endl;
}

// tagger related configs for reverse mapping tagger energy to counter number
if( REST_JANA_CALIB_CONTEXT != "" ) {
JCalibration *jcalib_old = calib_generator->MakeJCalibration(jcalib->GetURL(), locRunNumber, REST_JANA_CALIB_CONTEXT );
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/libraries/HDDM/DEventSourceREST.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include <DIRC/DDIRCPmtHit.h>
#include <DIRC/DDIRCTruthBarHit.h>
#include <PID/DParticleID.h>
#include <TAGGER/DTAGMHit.h>
#include <TAGGER/DTAGHHit.h>
#include <TAGGER/DTAGMGeometry.h>
#include <TAGGER/DTAGHGeometry.h>
#include <HDDM/DEventHitStatistics.h>
Expand Down Expand Up @@ -140,6 +142,13 @@ class DEventSourceREST:public JEventSource
map<unsigned int, DTAGHGeometry *> dTAGHGeoms; //unsigned int is run number
map<unsigned int, DTAGMGeometry *> dTAGMGeoms; //unsigned int is run number

//map<unsigned int, double *> dTAGHCounterQualities;
map<unsigned int, double [TAGH_MAX_COUNTER+1]> dTAGHCounterQualities;
//map<unsigned int, double **> dTAGMFiberQualities;
map<unsigned int, double [TAGM_MAX_ROW+1][TAGM_MAX_COLUMN+1]> dTAGMFiberQualities;



};

#endif //_JEVENT_SOURCEREST_H_
20 changes: 10 additions & 10 deletions src/libraries/TAGGER/DTAGHHit_factory_Calib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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])
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/TAGGER/DTAGHHit_factory_Calib.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class DTAGHHit_factory_Calib:public jana::JFactory<DTAGHHit>{
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]);

Expand Down
24 changes: 12 additions & 12 deletions src/libraries/TAGGER/DTAGMHit_factory_Calib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/TAGGER/DTAGMHit_factory_Calib.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DTAGMHit_factory_Calib: public jana::JFactory<DTAGMHit> {
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:
Expand Down