Skip to content

Commit

Permalink
Merge pull request #772 from JeffersonLab/helicity_tools
Browse files Browse the repository at this point in the history
Helicity tools
  • Loading branch information
jrstevenjlab authored Aug 23, 2024
2 parents 8e9304a + 2e2658b commit ad67fa5
Show file tree
Hide file tree
Showing 20 changed files with 1,442 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/libraries/DAQ/DAQ_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using namespace jana;

#include "DBeamCurrent_factory.h"
#include "DBeamHelicity_factory.h"
#include "Df250Config.h"
#include "Df250PulseIntegral.h"
#include "Df250StreamingRawData.h"
Expand Down Expand Up @@ -46,6 +47,7 @@ using namespace jana;
#include "DDIRCTDCHit.h"
#include "DDIRCADCHit.h"
#include "DGEMSRSWindowRawData.h"
#include "DHELIDigiHit.h"
#include "Df125EmulatorAlgorithm_factory.h"
#include "Df125EmulatorAlgorithm_factory_v2.h"
#include "Df250EmulatorAlgorithm_factory.h"
Expand All @@ -57,6 +59,8 @@ jerror_t DAQ_init(JEventLoop *loop)
{
/// Create and register DTranslationTable factory
loop->AddFactory(new DBeamCurrent_factory());
loop->AddFactory(new JFactory<DHELIDigiHit>());
loop->AddFactory(new DBeamHelicity_factory());
loop->AddFactory(new JFactory<Df250Config>());
loop->AddFactory(new JFactory<Df250PulseIntegral>());
loop->AddFactory(new JFactory<Df250StreamingRawData>());
Expand Down
37 changes: 37 additions & 0 deletions src/libraries/DAQ/DBeamHelicity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// $Id$
//
// File: DBeamHelicity.h
//

#ifndef _DBeamHelicity_
#define _DBeamHelicity_

#include <JANA/JObject.h>
#include <JANA/JFactory.h>

class DBeamHelicity:public jana::JObject{
public:
JOBJECT_PUBLIC(DBeamHelicity);

// Need to add notes on meanings (Mark?)
bool pattern_sync;
bool t_settle;
bool helicity;
bool pair_sync;
bool ihwp; // from EPICS variable (0=IN and 1=OUT)
bool beam_on; // from EPICS variable (0=OFF and 1=ON)

// This method is used primarily for pretty printing
// the second argument to AddString is printf style format
void toStrings(vector<pair<string,string> > &items)const{
AddString(items, "pattern sync", "%d", pattern_sync);
AddString(items, "t_settle", "%d", t_settle);
AddString(items, "helicity", "%d", helicity);
AddString(items, "pair_sync", "%d", pair_sync);
AddString(items, "ihwp", "%d", ihwp);
AddString(items, "beam_on", "%d", beam_on);
}
};

#endif // _DBeamHelicity_

123 changes: 123 additions & 0 deletions src/libraries/DAQ/DBeamHelicity_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// $Id$
//
// File: DBeamHelicity_factory.cc
//

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <mutex>
using namespace std;

#include <DANA/DStatusBits.h>
#include <DAQ/DCODAEventInfo.h>
#include <DAQ/DCODAROCInfo.h>
#include <DAQ/DHELIDigiHit.h>
#include <DAQ/DEPICSvalue.h>
#include "DBeamHelicity_factory.h"
using namespace jana;

//init static class variable
int DBeamHelicity_factory::dIHWP = 0;
int DBeamHelicity_factory::dBeamOn = 1;

//------------------
// init
//------------------
jerror_t DBeamHelicity_factory::init(void)
{

return NOERROR;
}

//------------------
// brun
//------------------
jerror_t DBeamHelicity_factory::brun(jana::JEventLoop *loop, int32_t runnumber)
{

// Grab information from CCDB tables here

// Constants for determined helicity pattern (from Ken)

// Half Waveplate status at run start (could be from RCDB?)

return NOERROR;
}

//------------------
// evnt
//------------------
jerror_t DBeamHelicity_factory::evnt(JEventLoop *loop, uint64_t eventnumber){
double beamcurr = 0.0;
double beamthresh = 10.0;

// get info from EPICS variables
vector<const DEPICSvalue*> epicsvalues;
loop->Get(epicsvalues);
bool isEPICS = loop->GetJEvent().GetStatusBit(kSTATUS_EPICS_EVENT);

//kl I don't thing this works. Each thread has a separate instance of the factory, so these values only get set in the thread which
//processed the EPICS event. Locking doesn't help. Worry about this lated when everything is moved into a factory.
if(isEPICS) {
for(vector<const DEPICSvalue*>::const_iterator val_itr = epicsvalues.begin(); val_itr != epicsvalues.end(); val_itr++) {
const DEPICSvalue* epics_val = *val_itr;
if(epics_val->name == "IGL1I00DI24_24M"){
dIHWP = atoi(epics_val->sval.c_str());
}
if(epics_val->name == "IBCAD00CRCUR6"){
beamcurr = atof(epics_val->sval.c_str());
if(beamcurr > beamthresh) dBeamOn = 1;
else dBeamOn = 0;
std::cout << "Got IBCAD00CRCUR6 = " << beamcurr << ". Setting dBeamOn = " << dBeamOn << "Event = "<< eventnumber << endl;
}
}
return NOERROR;
}

// get helicity bits from fADC
vector<const DHELIDigiHit*> locHELIDigiHits;
loop->Get(locHELIDigiHits);
if(locHELIDigiHits.empty()) return NOERROR;

DBeamHelicity *locBeamHelicity = new DBeamHelicity;
locBeamHelicity->pattern_sync = 0;
locBeamHelicity->t_settle = 0;
locBeamHelicity->helicity = 0;
locBeamHelicity->pair_sync = 0;
locBeamHelicity->ihwp = dIHWP;
locBeamHelicity->beam_on = dBeamOn;

for(size_t loc_i=0; loc_i<locHELIDigiHits.size(); loc_i++) {

const DHELIDigiHit *locHELIDigiHit = locHELIDigiHits[loc_i];

if(locHELIDigiHit->pulse_integral < 1000) continue; // threshold for signal

if(locHELIDigiHit->chan == 0) locBeamHelicity->pattern_sync = 1;
if(locHELIDigiHit->chan == 1) locBeamHelicity->t_settle = 1;
if(locHELIDigiHit->chan == 2) locBeamHelicity->helicity = 1;
if(locHELIDigiHit->chan == 3) locBeamHelicity->pair_sync = 1;
}

_data.push_back(locBeamHelicity);

return NOERROR;
}

//------------------
// erun
//------------------
jerror_t DBeamHelicity_factory::erun(void)
{
return NOERROR;
}

//------------------
// fini
//------------------
jerror_t DBeamHelicity_factory::fini(void)
{
return NOERROR;
}
28 changes: 28 additions & 0 deletions src/libraries/DAQ/DBeamHelicity_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// $Id$
//
// File: DBeamHelicity_factory.h
//

#ifndef _DBeamHelicity_factory_
#define _DBeamHelicity_factory_

#include <JANA/JFactory.h>
#include "DBeamHelicity.h"

class DBeamHelicity_factory:public jana::JFactory<DBeamHelicity>{
public:
DBeamHelicity_factory(){};
~DBeamHelicity_factory(){};

static int dIHWP;
static int dBeamOn;

jerror_t init(void); ///< Called once at program start.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber); ///< Called everytime a new run number is detected.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber); ///< Called every event.
jerror_t erun(void); ///< Called everytime run number changes, provided brun has been called.
jerror_t fini(void); ///< Called after last event of last event source has been processed.
};

#endif // _DBeamHelicity_factory_

38 changes: 38 additions & 0 deletions src/libraries/DAQ/DHELIDigiHit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef _DHELIDigiHit_
#define _DHELIDigiHit_

#include <JANA/JObject.h>
#include <JANA/JFactory.h>

class DHELIDigiHit:public jana::JObject{
public:
JOBJECT_PUBLIC(DHELIDigiHit);

int chan; ///< channel number 0-3
uint32_t pulse_integral; ///< identified pulse integral as returned by FPGA algorithm
uint32_t pulse_time; ///< identified pulse time as returned by FPGA algorithm
uint32_t pedestal; ///< pedestal info used by FPGA (if any)
uint32_t QF; ///< Quality Factor from FPGA algorithms
uint32_t nsamples_integral; ///< number of samples used in integral
uint32_t nsamples_pedestal; ///< number of samples used in pedestal
uint32_t pulse_peak; ///< maximum sample in pulse

uint32_t datasource; ///< 0=window raw data, 1=old(pre-Fall16) firmware, 2=Df250PulseData

// This method is used primarily for pretty printing
// the second argument to AddString is printf style format
void toStrings(vector<pair<string,string> > &items)const{
AddString(items, "chan", "%d", chan);
AddString(items, "pulse_integral", "%d", pulse_integral);
AddString(items, "pulse_peak", "%d", pulse_peak);
AddString(items, "pulse_time", "%d", pulse_time);
AddString(items, "pedestal", "%d", pedestal);
AddString(items, "QF", "%d", QF);
AddString(items, "nsamples_integral", "%d", nsamples_integral);
AddString(items, "nsamples_pedestal", "%d", nsamples_pedestal);
}

};

#endif // _DHELIDigiHit_

31 changes: 31 additions & 0 deletions src/libraries/TTAB/DTranslationTable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ void DTranslationTable::SetSystemsToParse(string systems, int systems_to_parse_f
rocid_map[name_to_id[ "TRD"]] = {76};
rocid_map[name_to_id[ "FMWPC"]] = {88};
rocid_map[name_to_id[ "CTOF"]] = {77, 78};
rocid_map[name_to_id[ "HELI"]] = {71};


}

Expand Down Expand Up @@ -466,6 +468,7 @@ void DTranslationTable::ApplyTranslationTable(JEventLoop *loop) const
case RF: MakeRFDigiTime( chaninfo.rf, pd); break;
case TAC: MakeTACDigiHit( chaninfo.tac, pd); break;
case CTOF: MakeCTOFDigiHit( chaninfo.ctof, pd); break;
case HELI: MakeHELIDigiHit( chaninfo.heli, pd); break;
default:
if (VERBOSE > 4) ttout << " - Don't know how to make DigiHit objects for this detector type!" << std::endl;
break;
Expand Down Expand Up @@ -833,6 +836,7 @@ void DTranslationTable::ApplyTranslationTable(JEventLoop *loop) const
Addf250ObjectsToCallStack(loop, "DTOFDigiHit");
Addf250ObjectsToCallStack(loop, "DCTOFDigiHit");
Addf250ObjectsToCallStack(loop, "DTACDigiHit");
Addf250ObjectsToCallStack(loop, "DHELIDigiHit");
Addf125CDCObjectsToCallStack(loop, "DCDCDigiHit", cdcpulses.size()>0);
Addf125FDCObjectsToCallStack(loop, "DFDCCathodeDigiHit", fdcpulses.size()>0);
Addf125CDCObjectsToCallStack(loop, "DFMWPCDigiHit", cdcpulses.size()>0);
Expand Down Expand Up @@ -1338,6 +1342,22 @@ DPSDigiHit* DTranslationTable::MakePSDigiHit(const PSIndex_t &idx,
return h;
}

//---------------------------------
// MakeHELIDigiHit
//---------------------------------
DHELIDigiHit* DTranslationTable::MakeHELIDigiHit(const HELIIndex_t &idx,
const Df250PulseData *pd) const
{
DHELIDigiHit *h = new DHELIDigiHit();
CopyDf250Info(h, pd);

h->chan = idx.chan;

vDHELIDigiHit.push_back(h);

return h;
}

//---------------------------------
// MakeCDCDigiHit
//---------------------------------
Expand Down Expand Up @@ -1993,6 +2013,9 @@ const DTranslationTable::csc_t
case DTranslationTable::FMWPC:
if ( det_channel.fmwpc == in_channel.fmwpc )
found = true;
case DTranslationTable::HELI:
if ( det_channel.heli == in_channel.heli )
found = true;
break;

default:
Expand Down Expand Up @@ -2098,6 +2121,9 @@ string DTranslationTable::Channel2Str(const DChannelInfo &in_channel) const
ss << "layer = " << in_channel.fmwpc.layer;
ss << "wire = " << in_channel.fmwpc.wire;
break;
case DTranslationTable::HELI:
ss << "channel = " << in_channel.heli.chan;
break;

default:
ss << "Unknown detector type" << std::endl;
Expand Down Expand Up @@ -2397,6 +2423,8 @@ DTranslationTable::Detector_t DetectorStr2DetID(string &type)
return DTranslationTable::TRD;
} else if ( type == "fmwpc" ) {
return DTranslationTable::FMWPC;
} else if ( type == "heli" ) {
return DTranslationTable::HELI;
} else
{
return DTranslationTable::UNKNOWN_DETECTOR;
Expand Down Expand Up @@ -2685,6 +2713,9 @@ void StartElement(void *userData, const char *xmlname, const char **atts)
ci.fmwpc.layer = layer;
ci.fmwpc.wire = wire;
break;
case DTranslationTable::HELI:
ci.heli.chan = id;
break;
case DTranslationTable::UNKNOWN_DETECTOR:
default:
break;
Expand Down
Loading

0 comments on commit ad67fa5

Please sign in to comment.