All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
sbn::BNBRetriever Class Reference
Inheritance diagram for sbn::BNBRetriever:

Classes

struct  Config
 
struct  MWRdata_t
 
struct  TriggerInfo_t
 

Public Types

using Parameters = art::EDProducer::Table< Config >
 

Public Member Functions

 BNBRetriever (Parameters const &params)
 
 BNBRetriever (BNBRetriever const &)=delete
 
 BNBRetriever (BNBRetriever &&)=delete
 
BNBRetrieveroperator= (BNBRetriever const &)=delete
 
BNBRetrieveroperator= (BNBRetriever &&)=delete
 
void produce (art::Event &e) override
 
void beginSubRun (art::SubRun &sr) override
 
void endSubRun (art::SubRun &sr) override
 

Private Member Functions

TriggerInfo_t extractTriggerInfo (art::Event const &e) const
 Returns the information of the trigger in the current event. More...
 
MWRdata_t extractSpillTimes (TriggerInfo_t const &triggerInfo) const
 Determines spill times and extracts data based on multiwire devices. More...
 
int matchMultiWireData (art::EventID const &eventID, TriggerInfo_t const &triggerInfo, MWRdata_t const &MWRdata, bool isFirstEventInRun, std::vector< sbn::BNBSpillInfo > &beamInfos) const
 Matches spill times with multiwire chamber data from the database. More...
 
sbn::BNBSpillInfo makeBNBSpillInfo (art::EventID const &eventID, double time, MWRdata_t const &MWRdata, std::vector< int > const &matched_MWR) const
 Assembles and returns a spill information record. More...
 

Private Attributes

std::vector< sbn::BNBSpillInfofOutbeamInfos
 
double fTimePad
 
std::string fURL
 
MWRData mwrdata
 
std::string raw_data_label
 
std::string fDeviceUsedForTiming
 
unsigned int TotalBeamSpills
 
art::ServiceHandle
< ifbeam_ns::IFBeam > 
ifbeam_handle
 
std::unique_ptr
< ifbeam_ns::BeamFolder > 
bfp
 
std::unique_ptr
< ifbeam_ns::BeamFolder > 
bfp_mwr
 

Static Private Attributes

static constexpr double MWRtoroidDelay = -0.035
 the same time point is measured t by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] More...
 

Detailed Description

Definition at line 39 of file BNBRetriever_module.cc.

Member Typedef Documentation

using sbn::BNBRetriever::Parameters = art::EDProducer::Table<Config>

Definition at line 90 of file BNBRetriever_module.cc.

Constructor & Destructor Documentation

sbn::BNBRetriever::BNBRetriever ( Parameters const &  params)
explicit

Definition at line 176 of file BNBRetriever_module.cc.

177  : EDProducer{params},
178  fTimePad(params().TimePadding()),
179  raw_data_label(params().RawDataLabel()),
180  fDeviceUsedForTiming(params().DeviceUsedForTiming()),
181  bfp( ifbeam_handle->getBeamFolder(params().Bundle(), params().URL(), params().TimeWindow())),
182  bfp_mwr( ifbeam_handle->getBeamFolder(params().MultiWireBundle(), params().URL(), params().MWR_TimeWindow()))
183 {
184 
185  // Check fTimePad is positive
186  if (fTimePad < 0) {
187  throw art::Exception(art::errors::Configuration)
188  << "Parameter `TimePadding` must be non-negative (" << fTimePad << " was specified).\n";
189  }//End Time check
190 
191  // how close in time does the spill time have to be from the DAQ time (in seconds).
192  // If these are too large then it fails to capture the device
193  // If these are too small then the time jitter in devices means we miss good data
194  //
195  // These values should likely not be changed unless authors of the IFBeam API are consulted
196  //
197  bfp->set_epsilon(0.02); //20 ms, this was tuned by hand and compared to IFBeamDB times
198  bfp_mwr->set_epsilon(0.5);
199 
200  //bfp_mwr->setValidWindow(86400);
201  bfp_mwr->setValidWindow(3605);
202  produces< std::vector< sbn::BNBSpillInfo >, art::InSubRun >();
203  TotalBeamSpills = 0;
204 }
std::string fDeviceUsedForTiming
unsigned int TotalBeamSpills
std::unique_ptr< ifbeam_ns::BeamFolder > bfp
std::unique_ptr< ifbeam_ns::BeamFolder > bfp_mwr
art::ServiceHandle< ifbeam_ns::IFBeam > ifbeam_handle
sbn::BNBRetriever::BNBRetriever ( BNBRetriever const &  )
delete
sbn::BNBRetriever::BNBRetriever ( BNBRetriever &&  )
delete

Member Function Documentation

void sbn::BNBRetriever::beginSubRun ( art::SubRun &  sr)
override

Definition at line 614 of file BNBRetriever_module.cc.

615 {
616  return;
617 }
void sbn::BNBRetriever::endSubRun ( art::SubRun &  sr)
override

Definition at line 620 of file BNBRetriever_module.cc.

621 {
622  // We will add all of the BNBSpillInfo data-products to the
623  // art::SubRun so it persists
624  // currently this is ~2.7 kB/event or ~0.07 kB/spill
625 
626 mf::LogDebug("BNBRetriever")<< "Total number of DAQ Spills : " << TotalBeamSpills << std::endl;
627 mf::LogDebug("BNBRetriever")<< "Total number of Selected Spills : " << fOutbeamInfos.size() << std::endl;
628 
629  auto p = std::make_unique< std::vector< sbn::BNBSpillInfo > >();
630  std::swap(*p, fOutbeamInfos);
631 
632  sr.put(std::move(p), art::subRunFragment());
633 
634  return;
635 }
pdgs p
Definition: selectors.fcl:22
unsigned int TotalBeamSpills
std::vector< sbn::BNBSpillInfo > fOutbeamInfos
sbn::BNBRetriever::MWRdata_t sbn::BNBRetriever::extractSpillTimes ( TriggerInfo_t const &  triggerInfo) const
private

Determines spill times and extracts data based on multiwire devices.

Parameters
triggerInfoinformation from the trigger of this event
Returns
times and unpacked data, per device ("M875BB", "M876BB", "MMBTBB")

Check the device name and interate the double-vector index

Definition at line 276 of file BNBRetriever_module.cc.

276  {
277 
278  // These lines get everything primed within the IFBeamDB
279  // They seem redundant but they are needed
280  try{auto cur_vec_temp = bfp->GetNamedVector((triggerInfo.t_previous_event)-fTimePad,"E:THCURR");} catch (WebAPIException &we) {}
281  try{auto packed_M876BB_temp = bfp_mwr->GetNamedVector((triggerInfo.t_current_event)+fTimePad,"E:M875BB{4440:888}.RAW");} catch (WebAPIException &we) {}
282 
283 
284  //The multiwire chambers provide their
285  // data in a vector format but we'll have
286  // to sort through it in std::string format
287  // to correctly unpack it
288  std::vector< std::vector< std::vector< int > > > unpacked_MWR;
289  std::vector< std::vector< double> > MWR_times;
290  unpacked_MWR.resize(3);
291  MWR_times.resize(3);
292  std::string packed_data_str;
293 
294  //Create a list of all the MWR devices with their different
295  // memory buffer increments
296  // generally in the format: "E:<Device>.{Memory Block}"
297  std::vector<std::string> vars = bfp_mwr->GetDeviceList();
298  mf::LogDebug("BNBRetriever") << " Number of MWR Device Blocks Found : " << vars.size() << std::endl;
299  // Tracking the time from the IFBeamDB
300  double time_for_mwr;
301 
302  // this is an iterator to track which of the
303  // three devices we will be working with
304  int dev = 0;
305 
306  // The MWR devices are annoying and have confusing buffer
307  // what we'll do is sort through all of them first and then
308  // match them to the closest spills in time
309  //
310 
311  // int t_steps = int(((triggerInfo.t_previous_event - fTimePad) - (triggerInfo.t_current_event + fTimePad))/0.5)+25;
312  int t_steps = int(((triggerInfo.t_current_event + fTimePad) - (triggerInfo.t_previous_event - fTimePad - 20.))/0.5)+25;
313  mf::LogDebug("BNBRetriever") << " t_steps " << t_steps << std::endl;
314 
315  for(int t = 0; t < t_steps; t++){//Iterate through time increments
316  for (std::string const& var : vars) {// Iterate through the devices
317 
318  //Make sure we have a device
319  if(var.empty()){
320  mf::LogDebug("BNBRetriever") << " NO MWR DEVICES?!" << std::endl;
321  continue;
322  }
323  /// Check the device name and interate the double-vector index
324  if(var.find("M875BB") != std::string::npos ) dev = 0;
325  else if(var.find("M876BB") != std::string::npos ) dev = 1;
326  else if(var.find("MMBTBB") != std::string::npos ) dev = 2;
327  else{
328  mf::LogDebug("BNBRetriever") << " NOT matched to a MWR DEVICES?!" << var << std::endl;
329  continue;}
330 
331  time_for_mwr = 0;
332 
333  try{
334  //Pull the MWR data for the device
335  // these data are "packed"
336  std::vector<double> packed_MWR = bfp_mwr->GetNamedVector((triggerInfo.t_previous_event)-20.-fTimePad+double(0.5*t),var,&time_for_mwr);
337 
338  //We'll convert this into a format
339  // that we can unpack doubles >> strings
340  //
341  packed_data_str.clear();
342  packed_data_str += std::to_string(int(time_for_mwr));
343  packed_data_str.append(",");
344  packed_data_str.append(var);
345  packed_data_str.append(",,");
346 
347  /* for(auto const value: packed_MWR){
348  packed_data_str += ',';
349  packed_data_str += std::to_string(int(value));
350  }*/
351  for(int j = 0; j < int(packed_MWR.size()); j++){
352  packed_data_str += std::to_string(int(packed_MWR[j]));
353  if(j < int(packed_MWR.size())-1)
354  packed_data_str.append(",");
355  }
356 
357  // Use Zarko's unpacking function to turn this into consumeable data
358  std::vector<double> MWR_times_temp;
359 
360  // There is a 35 ms offset between the toriod and the MWR times
361  // we'll just remove that here to match to the spill times
362  std::vector< std::vector< int > > unpacked_MWR_temp = mwrdata.unpackMWR(packed_data_str,MWR_times_temp,MWRtoroidDelay);
363 
364  //There are four events that are packed into one MWR IFBeam entry
365  for(std::size_t s: util::counter(unpacked_MWR_temp.size())){
366 
367  // If this entry has a unique time them store it for later
368  if(std::find(MWR_times[dev].begin(), MWR_times[dev].end(), MWR_times_temp[s]) == MWR_times[dev].end()){
369  unpacked_MWR[dev].push_back(unpacked_MWR_temp[s]);
370  MWR_times[dev].push_back(MWR_times_temp[s]);
371  }//check for unique time
372  }//Iterate through the unpacked events
373  }//try
374  catch (WebAPIException &we) {
375  //Ignore when we can't find the MWR devices
376  // they don't always report and the timing of them can be annoying
377 
378  }//catch
379  }// Iterate over all the multiwire devices
380  }// Iterate over all times
381 
382  mf::LogDebug("BNBRetriever") << " Number of MWR[0] times : " << MWR_times[0].size() << std::endl;
383  mf::LogDebug("BNBRetriever") << " Number of MWR[0]s : " << unpacked_MWR[0].size() << std::endl;
384  mf::LogDebug("BNBRetriever") << " Number of MWR[1] times : " << MWR_times[1].size() << std::endl;
385  mf::LogDebug("BNBRetriever") << " Number of MWR[1]s : " << unpacked_MWR[1].size() << std::endl;
386  mf::LogDebug("BNBRetriever") << " Number of MWR[2] times : " << MWR_times[2].size() << std::endl;
387  mf::LogDebug("BNBRetriever") << " Number of MWR[2]s : " << unpacked_MWR[2].size() << std::endl;
388 
389  return { std::move(MWR_times), std::move(unpacked_MWR) };
390 }
std::unique_ptr< ifbeam_ns::BeamFolder > bfp
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
std::unique_ptr< ifbeam_ns::BeamFolder > bfp_mwr
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
std::vector< std::vector< int > > unpackMWR(std::string packed_data, std::vector< double > &time_stamp, double timeoffset=0) const
Definition: MWRData.cpp:13
static constexpr double MWRtoroidDelay
the same time point is measured t by MWR and _t + MWRtoroidDelay`_ by the toroid [ms] ...
sbn::BNBRetriever::TriggerInfo_t sbn::BNBRetriever::extractTriggerInfo ( art::Event const &  e) const
private

Returns the information of the trigger in the current event.

Definition at line 241 of file BNBRetriever_module.cc.

241  {
242 
243  //Here we read in the artdaq Fragments and extract three pieces of information:
244  // 1. The time of the current event, t_current_event
245  // 2. the time of the previously triggered event, t_previous_event (NOTE: Events are non-sequential!)
246  // 3. the number of beam spills since the previously triggered event, number_of_gates_since_previous_event
247 
248  auto const & raw_data = e.getProduct< std::vector<artdaq::Fragment> >({ raw_data_label, "ICARUSTriggerV2" });
249 
250  TriggerInfo_t triggerInfo;
251 
252  for(auto raw_datum : raw_data){
253 
254  uint64_t artdaq_ts = raw_datum.timestamp();
255  icarus::ICARUSTriggerV2Fragment frag(raw_datum);
256  std::string data = frag.GetDataString();
257  char *buffer = const_cast<char*>(data.c_str());
258  icarus::ICARUSTriggerInfo datastream_info = icarus::parse_ICARUSTriggerV2String(buffer);
259  triggerInfo.gate_type = datastream_info.gate_type;
260  triggerInfo.number_of_gates_since_previous_event = frag.getDeltaGatesBNB();
261 
262  triggerInfo.t_current_event = static_cast<double>(artdaq_ts)/(1000000000.0); //check this offset...
263  if(triggerInfo.gate_type == 1)
264  triggerInfo.t_previous_event = (static_cast<double>(frag.getLastTimestampBNB()))/(1e9);
265  else
266  triggerInfo.t_previous_event = (static_cast<double>(frag.getLastTimestampOther()))/(1000000000.0);
267 
268  }
269 
270  mf::LogDebug("BNBRetriever") << std::setprecision(19) << "Previous : " << triggerInfo.t_previous_event << ", Current : " << triggerInfo.t_current_event << std::endl;
271 
272  return triggerInfo;
273 }
do i e
sbn::BNBSpillInfo sbn::BNBRetriever::makeBNBSpillInfo ( art::EventID const &  eventID,
double  time,
MWRdata_t const &  MWRdata,
std::vector< int > const &  matched_MWR 
) const
private

Assembles and returns a spill information record.

Parameters
eventIDID of the event the information is associated to
timetime of the spill
MWRdataall extracted data from multiwire chambers
matched_MWRdata from multiwire chambers matched with the time
Returns
a sbn::BNBSpillInfo object with information on the spill at time

Definition at line 509 of file BNBRetriever_module.cc.

510 {
511 
512  auto const& [ MWR_times, unpacked_MWR ] = MWRdata; // alias
513 
514  // initializing all of our device carriers
515  // device definitions can be found in BNBSpillInfo.h
516 
517  double TOR860 = 0; // units e12 protons
518  double TOR875 = 0; // units e12 protons
519  double LM875A = 0; // units R/s
520  double LM875B = 0; // units R/s
521  double LM875C = 0; // units R/s
522  double HP875 = 0; // units mm
523  double VP875 = 0; // units mm
524  double HPTG1 = 0; // units mm
525  double VPTG1 = 0; // units mm
526  double HPTG2 = 0; // units mm
527  double VPTG2 = 0; // units mm
528  double BTJT2 = 0; // units Deg C
529  double THCURR = 0; // units kiloAmps
530 
531  double TOR860_time = 0; // units s
532 
533  // Here we request all the devices
534  // since sometimes devices fail to report we'll
535  // allow each to throw an exception but still move forward
536  // interpreting these failures will be part of the beam quality analyses
537  try{bfp->GetNamedData(time, "E:TOR860@",&TOR860,&TOR860_time);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
538  try{bfp->GetNamedData(time, "E:TOR875",&TOR875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
539  try{bfp->GetNamedData(time, "E:LM875A",&LM875A);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
540  try{bfp->GetNamedData(time, "E:LM875B",&LM875B);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
541  try{bfp->GetNamedData(time, "E:LM875C",&LM875C);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
542  try{bfp->GetNamedData(time, "E:HP875",&HP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
543  try{bfp->GetNamedData(time, "E:VP875",&VP875);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
544  try{bfp->GetNamedData(time, "E:HPTG1",&HPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
545  try{bfp->GetNamedData(time, "E:VPTG1",&VPTG1);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
546  try{bfp->GetNamedData(time, "E:HPTG2",&HPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
547  try{bfp->GetNamedData(time, "E:VPTG2",&VPTG2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
548  try{bfp->GetNamedData(time, "E:BTJT2",&BTJT2);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
549  try{bfp->GetNamedData(time, "E:THCURR",&THCURR);}catch (WebAPIException &we) {mf::LogDebug("BNBRetriever")<< "At time : " << time << " " << "got exception: " << we.what() << "\n";}
550 
551  //crunch the times
552  unsigned long int time_closest_int = (int) TOR860_time;
553  double time_closest_ns = (TOR860_time - time_closest_int)*1e9;
554 
555  //Store everything in our data-product
556  sbn::BNBSpillInfo beamInfo;
557  beamInfo.TOR860 = TOR860*1e12; //add in factor of 1e12 protons to get correct POT units
558  beamInfo.TOR875 = TOR875*1e12; //add in factor of 1e12 protons to get correct POT units
559  beamInfo.LM875A = LM875A;
560  beamInfo.LM875B = LM875B;
561  beamInfo.LM875C = LM875C;
562  beamInfo.HP875 = HP875;
563  beamInfo.VP875 = VP875;
564  beamInfo.HPTG1 = HPTG1;
565  beamInfo.VPTG1 = VPTG1;
566  beamInfo.HPTG2 = HPTG2;
567  beamInfo.VPTG2 = VPTG2;
568  beamInfo.BTJT2 = BTJT2;
569  beamInfo.THCURR = THCURR;
570  beamInfo.spill_time_s = time_closest_int;
571  beamInfo.spill_time_ns = time_closest_ns;
572 
573  for(auto const& MWRdata: unpacked_MWR){
574  std::ignore = MWRdata;
575  assert(!MWRdata.empty());
576  }
577 
578  if(unpacked_MWR[0].empty()){
579  beamInfo.M875BB.clear();
580  beamInfo.M875BB_spill_time_diff = -999;//units in seconds
581  }
582  else{
583  beamInfo.M875BB = unpacked_MWR[0][matched_MWR[0]];
584  beamInfo.M875BB_spill_time_diff = (MWR_times[0][matched_MWR[0]] - time);
585  }
586 
587  if(unpacked_MWR[1].empty()){
588  beamInfo.M876BB.clear();
589  beamInfo.M876BB_spill_time_diff = -999;//units in seconds
590  }
591  else{
592  beamInfo.M876BB = unpacked_MWR[1][matched_MWR[1]];
593  beamInfo.M876BB_spill_time_diff = (MWR_times[1][matched_MWR[1]] - time);
594  }
595 
596  if(unpacked_MWR[2].empty()){
597  beamInfo.MMBTBB.clear();
598  beamInfo.MMBTBB_spill_time_diff = -999;//units in seconds
599  }
600  else{
601  beamInfo.MMBTBB = unpacked_MWR[2][matched_MWR[2]];
602  beamInfo.MMBTBB_spill_time_diff = (MWR_times[2][matched_MWR[2]] - time);
603  }
604  // We do not write these to the art::Events because
605  // we can filter events but want to keep all the POT
606  // information, so we'll write it to the SubRun
607 
608  beamInfo.event = eventID.event(); // the rest of ID is known by art::SubRun
609 
610  return beamInfo;
611 }
float M876BB_spill_time_diff
the time difference between M876BB and the matched spill
Definition: BNBSpillInfo.h:50
std::vector< int > M876BB
Multiwire station after Mag 875...?
Definition: BNBSpillInfo.h:46
float LM875C
Loss Monitor after the RWM, unit R/s.
Definition: BNBSpillInfo.h:30
float VPTG2
Horizontal Position Monitor at Target Station 2, closest to target, units mm.
Definition: BNBSpillInfo.h:38
float VPTG1
Horizontal Position Monitor at Target Station 1, units mm.
Definition: BNBSpillInfo.h:35
unsigned long int spill_time_ns
The IFDB Beam Spill Time, unit nsec.
Definition: BNBSpillInfo.h:18
float MMBTBB_spill_time_diff
the time difference between MMBTBB and the matched spill
Definition: BNBSpillInfo.h:51
float TOR875
Toroid after Mag 875, units e12 Protons.
Definition: BNBSpillInfo.h:26
float LM875A
Loss Monitor before the RWM, unit R/s.
Definition: BNBSpillInfo.h:28
std::unique_ptr< ifbeam_ns::BeamFolder > bfp
float BTJT2
Temperature of air exiting target, units Deg C.
Definition: BNBSpillInfo.h:40
std::vector< int > MMBTBB
Multiwire station at the target station,.
Definition: BNBSpillInfo.h:47
float HP875
Horizontal Position Monitor after Mag 875, units mm.
Definition: BNBSpillInfo.h:31
float HPTG2
Horizontal Position Monitor at Target Station 2, closest to target, units mm.
Definition: BNBSpillInfo.h:37
float THCURR
Current applied to Horn, units kiloAmperes.
Definition: BNBSpillInfo.h:42
unsigned long int spill_time_s
The IFDB Beam Spill Time, unit sec.
Definition: BNBSpillInfo.h:17
float VP875
Verticle Position Monitor after Mag 875, units mm.
Definition: BNBSpillInfo.h:32
unsigned int event
Definition: BNBSpillInfo.h:20
float TOR860
Toroid before Mag 875, units e12 Protons.
Definition: BNBSpillInfo.h:25
std::vector< int > M875BB
Multiwire station before Mag 875...?
Definition: BNBSpillInfo.h:45
float LM875B
Loss Monitor after the RWM, unit R/s.
Definition: BNBSpillInfo.h:29
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
float M875BB_spill_time_diff
the time difference between M875BB and the matched spill
Definition: BNBSpillInfo.h:49
float HPTG1
Horizontal Position Monitor at Target Station 1, units mm.
Definition: BNBSpillInfo.h:34
int sbn::BNBRetriever::matchMultiWireData ( art::EventID const &  eventID,
TriggerInfo_t const &  triggerInfo,
MWRdata_t const &  MWRdata,
bool  isFirstEventInRun,
std::vector< sbn::BNBSpillInfo > &  beamInfos 
) const
private

Matches spill times with multiwire chamber data from the database.

Parameters
eventIDID of the event the information is associated to
triggerInfoinformation from the trigger of this event
MWRdatadata from multiwire chambers
isFirstEventInRunwhether we are processing the first event of the run
[out]beamInfoscontainer to add spill information records to
Returns
count of matched spills

Definition at line 393 of file BNBRetriever_module.cc.

398  {
399 
400  auto const& [ MWR_times, unpacked_MWR ] = MWRdata; // alias
401 
402  //Here we will start collecting all the other beamline devices
403  // First we get the times that the beamline device fired
404  // we have to pick a specific variable to use
405  std::vector<double> times_temps = bfp->GetTimeList(fDeviceUsedForTiming);
406 
407  // We'll keep track of how many of these spills match to our
408  // DAQ trigger times
409  int spill_count = 0;
410  std::vector<int> matched_MWR;
411  matched_MWR.resize(3);
412 
413 
414  // NOTE: for now, this is dead code because we don't
415  // do anything for the first event in a run. We may want to revisit
416  // this later to understand if there is a way we can do the POT
417  // accounting in the first event.
418  //
419  // Need to handle the first event in a run differently
420  if(isFirstEventInRun){
421 
422  //We'll remove the spills after our event
423  int spills_after_our_target = 0;
424  // iterate through all the spills to find the
425  // spills that are after our triggered event
426  for (size_t i = 0; i < times_temps.size(); i++) {
427  if(times_temps[i] > (triggerInfo.t_current_event+fTimePad)){
428  spills_after_our_target++;
429  }
430  }//end loop through spill times
431 
432  // Remove the spills after our trigger
433  times_temps.erase(times_temps.end()-spills_after_our_target,times_temps.end());
434 
435  // Remove the spills before the start of our Run
436  times_temps.erase(times_temps.begin(), times_temps.end() - std::min(int(triggerInfo.number_of_gates_since_previous_event), int(times_temps.size())));
437 
438  }//end fix for "first event"
439 
440  // Iterating through each of the beamline times
441  for (size_t i = 0; i < times_temps.size(); i++) {
442 
443  // Only continue if these times are matched to our DAQ time
444 
445  if(!isFirstEventInRun){//We already addressed the "first event" above
446  if(times_temps[i] > (triggerInfo.t_current_event)){continue;}
447  if(times_temps[i] <= (triggerInfo.t_previous_event)){continue;}
448  }
449 
450 
451  //Great we found a matched spill! Let's count it
452  spill_count++;
453 
454  //Loop through the multiwire devices:
455 
456  for(int dev = 0; dev < int(MWR_times.size()); dev++){
457 
458  //Loop through the multiwire times:
459  double Tdiff = 1000000000.;
460  matched_MWR[dev] = 0;
461 
462  for(int mwrt = 0; mwrt < int(MWR_times[dev].size()); mwrt++){
463 
464  //found a candidate match!
465  if(fabs((MWR_times[dev][mwrt] - times_temps[i])) >= Tdiff){continue;}
466 
467  bool best_match = true;
468 
469  //Check for a better match...
470  for (size_t j = 0; j < times_temps.size(); j++) {
471  if( j == i) continue;
472  if(times_temps[j] > (triggerInfo.t_current_event+fTimePad)){continue;}
473  if(times_temps[j] <= (triggerInfo.t_previous_event-fTimePad)){continue;}
474 
475  //is there a better match later in the spill sequence
476  if(fabs((MWR_times[dev][mwrt] - times_temps[j])) <
477  fabs((MWR_times[dev][mwrt] - times_temps[i]))){
478  //we can have patience...
479  best_match = false;
480  break;
481  }
482  }//end better match check
483 
484  //Verified best match!
485  if(best_match == true){
486  matched_MWR[dev] = mwrt;
487  Tdiff = fabs((MWR_times[dev][mwrt] - times_temps[i]));
488  }
489 
490  }//end loop over MWR times
491 
492  }//end loop over MWR devices
493 
494  sbn::BNBSpillInfo spillInfo = makeBNBSpillInfo(eventID, times_temps[i], MWRdata, matched_MWR);
495 
496  beamInfos.push_back(std::move(spillInfo));
497 
498  // We do not write these to the art::Events because
499  // we can filter events but want to keep all the POT
500  // information, so we'll write it to the SubRun
501 
502  }//end iteration over beam device times
503 
504  return spill_count;
505 }
std::string fDeviceUsedForTiming
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
std::unique_ptr< ifbeam_ns::BeamFolder > bfp
sbn::BNBSpillInfo makeBNBSpillInfo(art::EventID const &eventID, double time, MWRdata_t const &MWRdata, std::vector< int > const &matched_MWR) const
Assembles and returns a spill information record.
BNBRetriever& sbn::BNBRetriever::operator= ( BNBRetriever const &  )
delete
BNBRetriever& sbn::BNBRetriever::operator= ( BNBRetriever &&  )
delete
void sbn::BNBRetriever::produce ( art::Event &  e)
override

Definition at line 207 of file BNBRetriever_module.cc.

208 {
209 
210  // If this is the first event in the run, then ignore it
211  // We do not currently have the ability to figure out the first
212  // spill that the DAQ was sensitive to, so don't try to save any
213  // spill information
214  //
215  // TODO: long-term goal -- can we fix this?
216  if (e.event() == 1) return;
217 
218  TriggerInfo_t const triggerInfo = extractTriggerInfo(e);
219 
220  //We only want to process BNB gates, i.e. type 1
221  if(triggerInfo.gate_type != 1) return;
222  // Keep track of the number of beam gates the DAQ thinks
223  // are in this job
224  TotalBeamSpills += triggerInfo.number_of_gates_since_previous_event;
225 
226 
227  MWRdata_t const MWRdata = extractSpillTimes(triggerInfo);
228 
229 
230  int const spill_count = matchMultiWireData(e.id(), triggerInfo, MWRdata, e.event() == 1, fOutbeamInfos);
231 
232 
233  if(spill_count > int(triggerInfo.number_of_gates_since_previous_event))
234  mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << triggerInfo.number_of_gates_since_previous_event << " \t \t ::: WRONG!"<< std::endl;
235  else
236  mf::LogDebug("BNBRetriever")<< "Event Spills : " << spill_count << ", DAQ Spills : " << triggerInfo.number_of_gates_since_previous_event << std::endl;
237 
238 }//end iteration over art::Events
MWRdata_t extractSpillTimes(TriggerInfo_t const &triggerInfo) const
Determines spill times and extracts data based on multiwire devices.
TriggerInfo_t extractTriggerInfo(art::Event const &e) const
Returns the information of the trigger in the current event.
unsigned int TotalBeamSpills
std::vector< sbn::BNBSpillInfo > fOutbeamInfos
int matchMultiWireData(art::EventID const &eventID, TriggerInfo_t const &triggerInfo, MWRdata_t const &MWRdata, bool isFirstEventInRun, std::vector< sbn::BNBSpillInfo > &beamInfos) const
Matches spill times with multiwire chamber data from the database.
do i e

Member Data Documentation

std::unique_ptr<ifbeam_ns::BeamFolder> sbn::BNBRetriever::bfp
private

Definition at line 119 of file BNBRetriever_module.cc.

std::unique_ptr<ifbeam_ns::BeamFolder> sbn::BNBRetriever::bfp_mwr
private

Definition at line 120 of file BNBRetriever_module.cc.

std::string sbn::BNBRetriever::fDeviceUsedForTiming
private

Definition at line 115 of file BNBRetriever_module.cc.

std::vector< sbn::BNBSpillInfo > sbn::BNBRetriever::fOutbeamInfos
private

Definition at line 110 of file BNBRetriever_module.cc.

double sbn::BNBRetriever::fTimePad
private

Definition at line 111 of file BNBRetriever_module.cc.

std::string sbn::BNBRetriever::fURL
private

Definition at line 112 of file BNBRetriever_module.cc.

art::ServiceHandle<ifbeam_ns::IFBeam> sbn::BNBRetriever::ifbeam_handle
private

Definition at line 118 of file BNBRetriever_module.cc.

MWRData sbn::BNBRetriever::mwrdata
private

Definition at line 113 of file BNBRetriever_module.cc.

constexpr double sbn::BNBRetriever::MWRtoroidDelay = -0.035
staticprivate

the same time point is measured t by MWR and _t + MWRtoroidDelay`_ by the toroid [ms]

Definition at line 135 of file BNBRetriever_module.cc.

std::string sbn::BNBRetriever::raw_data_label
private

Definition at line 114 of file BNBRetriever_module.cc.

unsigned int sbn::BNBRetriever::TotalBeamSpills
private

Definition at line 116 of file BNBRetriever_module.cc.


The documentation for this class was generated from the following file: