Skip to content

Commit

Permalink
backported changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdobbs committed Nov 16, 2021
1 parent 6368820 commit 25582d6
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 62 deletions.
150 changes: 127 additions & 23 deletions src/libraries/HDDM/DEventSourceREST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ DEventSourceREST::DEventSourceREST(const char* source_name)
USE_CCDB_FCAL_COVARIANCE = false;
gPARMS->SetDefaultParameter("REST:USE_CCDB_FCAL_COVARIANCE", USE_CCDB_FCAL_COVARIANCE,
"Load REST BFAL Shower covariance matrices from CCDB instead of the file.");

gPARMS->SetDefaultParameter("REST:JANACALIBCONTEXT", REST_JANA_CALIB_CONTEXT);
calib_generator = new JCalibrationGeneratorCCDB; // keep this around in case we need to use it
}

//----------------
Expand All @@ -77,6 +80,13 @@ DEventSourceREST::~DEventSourceREST()
if (ifs) {
delete ifs;
}

for(auto &entry : dJCalib_olds)
delete entry.second;
for(auto &entry : dTAGHGeoms)
delete entry.second;
for(auto &entry : dTAGMGeoms)
delete entry.second;
}

//----------------
Expand Down Expand Up @@ -166,13 +176,16 @@ jerror_t DEventSourceREST::GetEvent(JEvent &event)
break;
}

//set REST calib context
const hddm_r::CcdbContextList& locContextStrings = re.getCcdbContexts();
hddm_r::CcdbContextList::iterator Contextiter;
for (Contextiter = locContextStrings.begin(); Contextiter != locContextStrings.end(); ++Contextiter) {
string REST_JANA_CALIB_CONTEXT = Contextiter->getText();
gPARMS->SetDefaultParameter("REST:JANACALIBCONTEXT", REST_JANA_CALIB_CONTEXT);
}
// set REST calib context - use this to load calibration constants that were used
// to create the REST files, if needed, but let this be overridden by command-line options
if( REST_JANA_CALIB_CONTEXT == "" ) {
const hddm_r::CcdbContextList& locContextStrings = re.getCcdbContexts();
hddm_r::CcdbContextList::iterator Contextiter;
for (Contextiter = locContextStrings.begin(); Contextiter != locContextStrings.end(); ++Contextiter) {
REST_JANA_CALIB_CONTEXT = Contextiter->getText();
jout << " REST file next CCDB context = " << REST_JANA_CALIB_CONTEXT << endl; // DEBUG?
}
}

record->clear();
while (record->getReconstructedPhysicsEvents().size() == 0) {
Expand Down Expand Up @@ -234,9 +247,13 @@ jerror_t DEventSourceREST::GetObjects(JEvent &event, JFactory_base *factory)

JEventLoop* locEventLoop = event.GetJEventLoop();
string dataClassName = factory->GetDataClassName();


DApplication* dapp = dynamic_cast<DApplication*>(locEventLoop->GetJApplication());
JCalibration *jcalib = dapp->GetJCalibration(event.GetRunNumber());


//Get target center
//multiple reader threads can access this object: need lock
//multiple reader threads can access this object: need lock
bool locNewRunNumber = false;
unsigned int locRunNumber = event.GetRunNumber();
LockRead();
Expand All @@ -246,7 +263,6 @@ jerror_t DEventSourceREST::GetObjects(JEvent &event, JFactory_base *factory)
UnlockRead();
if(locNewRunNumber)
{
DApplication* dapp = dynamic_cast<DApplication*>(locEventLoop->GetJApplication());
DGeometry* locGeometry = dapp->GetDGeometry(locEventLoop->GetJEvent().GetRunNumber());
double locTargetCenterZ = 0.0;
locGeometry->GetTargetZ(locTargetCenterZ);
Expand All @@ -271,6 +287,7 @@ jerror_t DEventSourceREST::GetObjects(JEvent &event, JFactory_base *factory)
jout << "Error loading /DIRC/South/channel_status !" << endl;
}


LockRead();
{
dTargetCenterZMap[locRunNumber] = locTargetCenterZ;
Expand All @@ -291,9 +308,16 @@ jerror_t DEventSourceREST::GetObjects(JEvent &event, JFactory_base *factory)
<< " dy/dz=" << dBeamDirMap[locRunNumber].Y()
<< 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 );
dTAGHGeoms[locRunNumber] = new DTAGHGeometry(jcalib_old, locRunNumber);
dTAGMGeoms[locRunNumber] = new DTAGMGeometry(jcalib_old, locRunNumber);
dJCalib_olds[locRunNumber] = jcalib_old;
}
}
UnlockRead();

// do multiple things to limit the number of locks
// make sure that we have a handle to the FCAL shower factory
if(USE_CCDB_FCAL_COVARIANCE) {
Expand Down Expand Up @@ -590,25 +614,61 @@ jerror_t DEventSourceREST::Extract_DBeamPhoton(hddm_r::HDDM *record,
hddm_r::TagmBeamPhotonList::iterator locTAGMiter;
for(locTAGMiter = locTagmBeamPhotonList.begin(); locTAGMiter != locTagmBeamPhotonList.end(); ++locTAGMiter)
{
if (locTAGMiter->getJtag() != tag)
continue;
if (locTAGMiter->getJtag() != tag)
continue;

DBeamPhoton* gamma = new DBeamPhoton();
DBeamPhoton* gamma = new DBeamPhoton();

// load the counter number (if it exists) and set the energy based on the counter
unsigned int column = 0;
hddm_r::TagmChannelList &locTagmChannelList = locTAGMiter->getTagmChannels();
if (locTagmChannelList.size() > 0) {
// it's easy if the column is already set
column = locTagmChannelList().getColumn();
} else {
// if the TAGM column isn't saved in the REST file, then we do one of two things
// 1) if there's no special CCDB context associated with the file, we can just
// reverse engineer the counter, assuming the latest CCDB
// 2) If there is a special CCDB context specified, then use that instead
if (dJCalib_olds[locRunNumber] == nullptr) {
if (!tagmGeom->E_to_column(locTAGMiter->getE(), column)) {
column = 0;
}
} else {
if (!dTAGMGeoms[locRunNumber]->E_to_column(locTAGMiter->getE(), column)) {
column = 0;
}
}

if(column == 0)
std::cerr << "Error in DEventSourceREST - tagger microscope could not look up column for energy "
<< locTAGMiter->getE() << std::endl;
}

// sometimes the simulation will set photons that miss the tagger counters to have a column of zero - skip these
if(column == 0) {
continue;
}

DVector3 mom(0.0, 0.0, locTAGMiter->getE());
double Elo = tagmGeom->getElow(column);
double Ehi = tagmGeom->getEhigh(column);
double Ebeam = (Elo + Ehi)/2.;

// read the rest of the data from the REST file
DVector3 mom(0.0, 0.0, Ebeam);
gamma->setPID(Gamma);
gamma->setMomentum(mom);
gamma->setPosition(pos);
gamma->setTime(locTAGMiter->getT());
gamma->dSystem = SYS_TAGM;
gamma->dCounter = column;

auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
locCovarianceMatrix->ResizeTo(7, 7);
locCovarianceMatrix->Zero();
auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
locCovarianceMatrix->ResizeTo(7, 7);
locCovarianceMatrix->Zero();
gamma->setErrorMatrix(locCovarianceMatrix);

tagmGeom->E_to_column(locTAGMiter->getE(), gamma->dCounter);
dbeam_photons.push_back(gamma);

dbeam_photons.push_back(gamma);
}

const hddm_r::TaghBeamPhotonList &locTaghBeamPhotonList = record->getTaghBeamPhotons();
Expand All @@ -620,20 +680,51 @@ jerror_t DEventSourceREST::Extract_DBeamPhoton(hddm_r::HDDM *record,

DBeamPhoton* gamma = new DBeamPhoton();

// load the counter number (if it exists) and set the energy based on the counter
unsigned int counter = 0;
hddm_r::TaghChannelList &locTaghChannelList = locTAGHiter->getTaghChannels();
if (locTaghChannelList.size() > 0) {
// it's easy if the column is already set
counter = locTaghChannelList().getCounter();
} else {
// if the TAGM column isn't saved in the REST file, then we do one of two things
// 1) if there's no special CCDB context associated with the file, we can just
// reverse engineer the counter, assuming the latest CCDB
// 2) If there is a special CCDB context specified, then use that instead
if (dJCalib_olds[locRunNumber] == nullptr) {
if (!taghGeom->E_to_counter(locTAGHiter->getE(), counter)) {
counter = 0;
}
} else {
if (!dTAGHGeoms[locRunNumber]->E_to_counter(locTAGHiter->getE(), counter)) {
counter = 0;
}
}

if(counter == 0)
std::cerr << "Error in DEventSourceREST - tagger hodoscope could not look up counter for energy "
<< locTAGHiter->getE() << std::endl;
}

// sometimes the simulation will set photons that miss the tagger counters to have a column of zero - skip these
if(counter == 0) {
continue;
}

DVector3 mom(0.0, 0.0, locTAGHiter->getE());
gamma->setPID(Gamma);
gamma->setMomentum(mom);
gamma->setPosition(pos);
gamma->setTime(locTAGHiter->getT());
gamma->dSystem = SYS_TAGH;
gamma->dCounter = counter;

auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
locCovarianceMatrix->ResizeTo(7, 7);
locCovarianceMatrix->Zero();
gamma->setErrorMatrix(locCovarianceMatrix);

taghGeom->E_to_counter(locTAGHiter->getE(), gamma->dCounter);
dbeam_photons.push_back(gamma);
dbeam_photons.push_back(gamma);
}

if((tag == "TAGGEDMCGEN") && dbeam_photons.empty())
Expand Down Expand Up @@ -849,6 +940,19 @@ jerror_t DEventSourceREST::Extract_DTrigger(hddm_r::HDDM *record, JFactory<DTrig
DTrigger *locTrigger = new DTrigger();
locTrigger->Set_L1TriggerBits(Convert_SignedIntToUnsigned(iter->getL1_trig_bits()));
locTrigger->Set_L1FrontPanelTriggerBits(Convert_SignedIntToUnsigned(iter->getL1_fp_trig_bits()));

const hddm_r::TriggerEnergySumsList& locTriggerEnergySumsList = iter->getTriggerEnergySumses();
hddm_r::TriggerEnergySumsList::iterator locTriggerEnergySumsIterator = locTriggerEnergySumsList.begin();
if(locTriggerEnergySumsIterator == locTriggerEnergySumsList.end()) {
locTrigger->Set_GTP_BCALEnergy(0);
locTrigger->Set_GTP_FCALEnergy(0);
} else { //should only be 1
for(; locTriggerEnergySumsIterator != locTriggerEnergySumsList.end(); ++locTriggerEnergySumsIterator) {
locTrigger->Set_GTP_BCALEnergy(locTriggerEnergySumsIterator->getBCALEnergySum());
locTrigger->Set_GTP_FCALEnergy(locTriggerEnergySumsIterator->getFCALEnergySum());
}
}

data.push_back(locTrigger);
}

Expand Down
10 changes: 10 additions & 0 deletions src/libraries/HDDM/DEventSourceREST.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <JANA/JEventSource.h>
#include <JANA/jerror.h>
#include <JANA/JCalibration.h>
#include <JANA/JCalibrationCCDB.h>
#include <JANA/JCalibrationGeneratorCCDB.h>

#include "hddm_r.hpp"

Expand Down Expand Up @@ -124,6 +126,14 @@ class DEventSourceREST:public JEventSource

std::ifstream *ifs; // input hddm file ifstream
hddm_r::istream *fin; // provides hddm layer on top of ifstream

string REST_JANA_CALIB_CONTEXT = "";
JCalibrationGeneratorCCDB *calib_generator;

map<unsigned int, JCalibration *> dJCalib_olds; //unsigned int is run number
map<unsigned int, DTAGHGeometry *> dTAGHGeoms; //unsigned int is run number
map<unsigned int, DTAGMGeometry *> dTAGMGeoms; //unsigned int is run number

};

#endif //_JEVENT_SOURCEREST_H_
9 changes: 7 additions & 2 deletions src/libraries/HDDM/rest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
</vertex>
</reaction>
<tagmBeamPhoton maxOccurs="unbounded" minOccurs="0" jtag="string"
t="float" E="float" tunit="ns" Eunit="GeV"/>
t="float" E="float" tunit="ns" Eunit="GeV">
<tagmChannel minOccurs="0" column="int"/>
</tagmBeamPhoton>
<taghBeamPhoton maxOccurs="unbounded" minOccurs="0" jtag="string"
t="float" E="float" tunit="ns" Eunit="GeV"/>
t="float" E="float" tunit="ns" Eunit="GeV">
<taghChannel minOccurs="0" counter="int"/>
</taghBeamPhoton>
<fcalShower minOccurs="0" maxOccurs="unbounded" jtag="string"
x="float" y="float" z="float" t="float" E="float"
xerr="float" yerr="float" zerr="float" terr="float" Eerr="float"
Expand Down Expand Up @@ -99,6 +103,7 @@
tsync="float" tunit="ns"/>
<trigger minOccurs="0" maxOccurs="1" jtag="string"
l1_trig_bits="int" l1_fp_trig_bits="int">
<triggerEnergySums BCALEnergySum="float" FCALEnergySum="float" minOccurs="0"/>
</trigger>

<detectorMatches minOccurs="1" maxOccurs="1" jtag="string">
Expand Down
10 changes: 8 additions & 2 deletions src/libraries/PID/DBeamPhoton_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ void DBeamPhoton_factory::Set_BeamPhoton(DBeamPhoton* gamma, const DTAGMHit* hit
gamma->setPosition(pos);
gamma->setTime(hit->t);
gamma->dCounter = hit->column;
gamma->dSystem = SYS_TAGM;
if(gamma->dCounter == 0) // handle photons from simulation that miss tagger counters
gamma->dSystem = SYS_NULL;
else
gamma->dSystem = SYS_TAGM;
gamma->AddAssociatedObject(hit);

auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
Expand All @@ -144,7 +147,10 @@ void DBeamPhoton_factory::Set_BeamPhoton(DBeamPhoton* gamma, const DTAGHHit* hit
gamma->setPosition(pos);
gamma->setTime(hit->t);
gamma->dCounter = hit->counter_id;
gamma->dSystem = SYS_TAGH;
if(gamma->dCounter == 0) // handle photons from simulation that miss tagger counters
gamma->dSystem = SYS_NULL;
else
gamma->dSystem = SYS_TAGH;
gamma->AddAssociatedObject(hit);

auto locCovarianceMatrix = dResourcePool_TMatrixFSym->Get_SharedResource();
Expand Down
27 changes: 26 additions & 1 deletion src/libraries/PID/DBeamPhoton_factory_MCGEN.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using namespace std;

#include "DBeamPhoton_factory_MCGEN.h"
#include "TAGGER/DTAGHGeometry.h"
#include "TAGGER/DTAGMGeometry.h"

using namespace jana;

//------------------
Expand Down Expand Up @@ -62,9 +65,31 @@ jerror_t DBeamPhoton_factory_MCGEN::evnt(jana::JEventLoop *locEventLoop, uint64_
}
}

//Photon is NOT TAGGED //Create a beam object from the DMCReaction
// extract the TAGH geometry
vector<const DTAGHGeometry*> taghGeomVect;
eventLoop->Get(taghGeomVect);
if (taghGeomVect.empty())
return NOERROR;
const DTAGHGeometry* taghGeom = taghGeomVect[0];

// extract the TAGM geometry
vector<const DTAGMGeometry*> tagmGeomVect;
eventLoop->Get(tagmGeomVect);
if (tagmGeomVect.empty())
return NOERROR;
const DTAGMGeometry* tagmGeom = tagmGeomVect[0];

//Photon is NOT TAGGED //Create a beam object from the DMCReaction
auto *locBeamPhoton = new DBeamPhoton;
*(DKinematicData*)locBeamPhoton = locMCReactions[0]->beam;

if(tagmGeom->E_to_column(locBeamPhoton->energy(), locBeamPhoton->dCounter))
locBeamPhoton->dSystem = SYS_TAGM;
else if(taghGeom->E_to_counter(locBeamPhoton->energy(), locBeamPhoton->dCounter))
locBeamPhoton->dSystem = SYS_TAGH;
else
locBeamPhoton->dSystem = SYS_NULL;

_data.push_back(locBeamPhoton);

return NOERROR;
Expand Down
10 changes: 8 additions & 2 deletions src/libraries/PID/DBeamPhoton_factory_TRUTH.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ jerror_t DBeamPhoton_factory_TRUTH::evnt(jana::JEventLoop *locEventLoop, uint64_
gamma->setMomentum(mom);
gamma->setPosition(pos);
gamma->setTime(tagm_hits[ih]->t);
gamma->dSystem = SYS_TAGM;
if(gamma->dCounter == 0) // handle photons from simulation that miss tagger counters
gamma->dSystem = SYS_NULL;
else
gamma->dSystem = SYS_TAGM;
gamma->dCounter = tagm_hits[ih]->column;
gamma->AddAssociatedObject(tagm_hits[ih]);
_data.push_back(gamma);
Expand All @@ -67,7 +70,10 @@ jerror_t DBeamPhoton_factory_TRUTH::evnt(jana::JEventLoop *locEventLoop, uint64_
gamma->setMomentum(mom);
gamma->setPosition(pos);
gamma->setTime(tagh_hits[ih]->t);
gamma->dSystem = SYS_TAGH;
if(gamma->dCounter == 0) // handle photons from simulation that miss tagger counters
gamma->dSystem = SYS_NULL;
else
gamma->dSystem = SYS_TAGH;
gamma->dCounter = tagh_hits[ih]->counter_id;
gamma->AddAssociatedObject(tagh_hits[ih]);
_data.push_back(gamma);
Expand Down
Loading

0 comments on commit 25582d6

Please sign in to comment.