Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////////////////
// Class: EXTRetriever
// Class: BNBEXTRetriever
// Plugin Type: producer
// File: EXTRetriever_module.cc
// File: BNBEXTRetriever_module.cc
//
// Created by hand Thurs June 24th 2021 by J. Zennamo (FNAL)
//
Expand All @@ -22,7 +22,7 @@
#include "larcorealg/Geometry/Exceptions.h"

#include "artdaq-core/Data/Fragment.hh"
#include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerUDPFragment.hh"
#include "sbndaq-artdaq-core/Overlays/ICARUS/ICARUSTriggerV3Fragment.hh"

#include "lardataalg/DetectorInfo/DetectorPropertiesStandard.h"
#include "lardata/DetectorInfoServices/DetectorPropertiesService.h"
Expand All @@ -36,10 +36,10 @@
#include <time.h>

namespace sbn {
class EXTRetriever;
class BNBEXTRetriever;
}

class sbn::EXTRetriever : public art::EDProducer {
class sbn::BNBEXTRetriever : public art::EDProducer {
public:

struct Config {
Expand All @@ -57,15 +57,15 @@ class sbn::EXTRetriever : public art::EDProducer {
using Parameters = art::EDProducer::Table<Config>;


explicit EXTRetriever(Parameters const& params);
explicit BNBEXTRetriever(Parameters const& params);
// The compiler-generated destructor is fine for non-base
// classes without bare pointers or other resource use.

// Plugins should not be copied or assigned.
EXTRetriever(EXTRetriever const&) = delete;
EXTRetriever(EXTRetriever&&) = delete;
EXTRetriever& operator=(EXTRetriever const&) = delete;
EXTRetriever& operator=(EXTRetriever&&) = delete;
BNBEXTRetriever(BNBEXTRetriever const&) = delete;
BNBEXTRetriever(BNBEXTRetriever&&) = delete;
BNBEXTRetriever& operator=(BNBEXTRetriever const&) = delete;
BNBEXTRetriever& operator=(BNBEXTRetriever&&) = delete;

// Required functions.
void produce(art::Event& e) override;
Expand All @@ -77,21 +77,27 @@ class sbn::EXTRetriever : public art::EDProducer {

// input labels
std::string raw_data_label_;
int TotalEXTCounts;
float TotalEXTCounts;
float totalMinBias;
float evtCount;
float scale_factor;

};


sbn::EXTRetriever::EXTRetriever(Parameters const& params)
sbn::BNBEXTRetriever::BNBEXTRetriever(Parameters const& params)
: EDProducer{params},
raw_data_label_(params().RawDataLabel())
{

produces< std::vector< sbn::EXTCountInfo >, art::InSubRun >();
TotalEXTCounts = 0;
totalMinBias = 0;
evtCount = 0;
scale_factor = 0;
}

void sbn::EXTRetriever::produce(art::Event& e)
void sbn::BNBEXTRetriever::produce(art::Event& e)
{

//Here we read in the artdaq Fragments and extract three pieces of information:
Expand All @@ -100,19 +106,30 @@ void sbn::EXTRetriever::produce(art::Event& e)
// 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event

int gate_type = 0;
auto const & raw_data = e.getProduct< std::vector<artdaq::Fragment> >({ raw_data_label_, "ICARUSTriggerUDP" });
auto const & raw_data = e.getProduct< std::vector<artdaq::Fragment> >({ raw_data_label_, "ICARUSTriggerV3" });

unsigned int number_of_gates_since_previous_event = 0;

for(auto raw_datum : raw_data){

icarus::ICARUSTriggerUDPFragment frag(raw_datum);
icarus::ICARUSTriggerV3Fragment frag(raw_datum);
std::string data = frag.GetDataString();
char *buffer = const_cast<char*>(data.c_str());
icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerString(buffer);
icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerV3String(buffer);
gate_type = datastream_info.gate_type;
number_of_gates_since_previous_event = frag.getDeltaGatesBNB();

number_of_gates_since_previous_event = frag.getDeltaGatesBNBOffMaj();

if(gate_type != 3)
return;

if(frag.getDeltaGatesBNBOffMinbias() > 0 && gate_type == 3){
evtCount++;
totalMinBias += frag.getDeltaGatesBNBOffMinbias();
}

// std::cout << "BNB OFF MAJ : " << frag.getDeltaGatesBNBOffMaj() << std::endl;
// std::cout << "Scale Factor : " << scale_factor << std::endl;

}

//We only want to process EXT gates, i.e. type 3
Expand All @@ -135,21 +152,38 @@ void sbn::EXTRetriever::produce(art::Event& e)
} //end loop over events


void sbn::EXTRetriever::beginSubRun(art::SubRun& sr)
void sbn::BNBEXTRetriever::beginSubRun(art::SubRun& sr)
{
TotalEXTCounts = 0;
totalMinBias = 0;
evtCount = 0;
scale_factor = 0;
return;
}

//____________________________________________________________________________
void sbn::EXTRetriever::endSubRun(art::SubRun& sr)
//____________________________________________________________________________
void sbn::BNBEXTRetriever::endSubRun(art::SubRun& sr)
{
// We will add all of the EXTCountInfo data-products to the
// art::SubRun so it persists

if(evtCount != 0 && totalMinBias != 0)
scale_factor = 1. - (evtCount/totalMinBias);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't figure out the rationale here.
Can you explain (and document) the intent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to scale by the minimum bias prescale rate, which can change run-to-run based on our configuration. The best way I found to do this was to use frag.getDeltaGatesBNBOffMinbias() BUT it doesn't work for event which haven't had a MinBias trigger yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the prescale rate with something like:

void sbn::BNBExtRetriever::beginRun(art::Run& run) {
  auto const& trigConfig = run.getProduct<icarus::TriggerConfiguration>(fTrigConfigLabel);
  fPrescale = trigConfig.getMinBiasPrescale(sbn::triggerSource::OffbeamBNB);
}

(#include "icaruscode/Decode/DataProducts/TriggerConfiguration.h")
With this information you can correct either statistically (* (1.0 - 1.0/fPrescale)) or exactly event by event.
The correct label from ICARUS Stage0 processing is triggerConfig if I am not wrong.

I don't understand the meaning of the fraction evtCount/totalMinBias... I would understand a gate count instead of the triggered event count on the denominator as an estimation of the prescale factor.

I am not sure what the existing code does in the presence of events with gate_type != 3.

else
std::cout << "FAILED! " << std::endl;
// probably want to throw an exception here

for(auto ExtInfo : fOutExtInfos){

ExtInfo.gates_since_last_trigger *= scale_factor;

}

auto p = std::make_unique< std::vector< sbn::EXTCountInfo > >(fOutExtInfos);

sr.put(std::move(p), art::subRunFragment());

return;
}

DEFINE_ART_MODULE(sbn::EXTRetriever)
DEFINE_ART_MODULE(sbn::BNBEXTRetriever)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cet_build_plugin(EXTRetriever art::module
cet_build_plugin(BNBEXTRetriever art::module
LIBRARIES
art::Persistency_Common
art::Utilities canvas::canvas
Expand Down
Loading