All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArtdaqFragmentProducer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: ArtdaqFragmentProducer
3 // Module Type: producer
4 // File: ArtdaqFragmentProducer_module.cc
5 //
6 // Producer module for creating DAQ-readable fragments from simulation
7 //
8 //
9 // Erin Yandel (eyandel@fnal.gov)
10 ////////////////////////////////////////////////////////////////////////
11 
12 // sbndcode includes
25 
26 
27 // LArSoft includes
34 #include "nusimdata/SimulationBase/MCParticle.h"
35 #include "nusimdata/SimulationBase/MCTruth.h"
37 
38 // artdaq includes
39 #include "sbndaq-artdaq-core/Overlays/Common/BernCRTFragmentV2.hh"
40 #include "sbndaq-artdaq-core/Overlays/Common/CAENV1730Fragment.hh"
41 #include "sbndaq-artdaq-core/Overlays/FragmentType.hh"
42 #include "artdaq-core/Data/Fragment.hh"
43 
44 // Framework includes
45 #include "art/Framework/Core/EDProducer.h"
46 #include "art/Framework/Principal/Event.h"
47 #include "art/Framework/Principal/Handle.h"
48 #include "art/Framework/Services/Registry/ServiceHandle.h"
49 #include "art_root_io/TFileService.h"
50 #include "art/Framework/Core/ModuleMacros.h"
51 #include "canvas/Persistency/Common/FindManyP.h"
52 #include "canvas/Utilities/Exception.h"
55 
56 // Utility libraries
57 #include "messagefacility/MessageLogger/MessageLogger.h"
58 #include "fhiclcpp/ParameterSet.h"
59 #include "fhiclcpp/types/Table.h"
60 #include "fhiclcpp/types/Atom.h"
61 #include "cetlib/pow.h"
62 
63 // random numbers
64 #include "nurandom/RandomUtils/NuRandomService.h"
65 #include "CLHEP/Random/RandFlat.h"
66 
67 // ROOT includes.
68 #include "TH1.h"
69 #include "TH2.h"
70 #include "TVector3.h"
71 #include "TString.h"
72 
73 // C++ includes
74 #include <map>
75 #include <vector>
76 #include <string>
77 #include <random>
78 #include <iomanip>
79 
80 namespace sbnd {
81  namespace trigger {
83  }
84 }
85 
86 class sbnd::trigger::ArtdaqFragmentProducer : public art::EDProducer {
87 public:
88  explicit ArtdaqFragmentProducer(fhicl::ParameterSet const& p);
89 
94 
95  // Required functions.
96  void produce(art::Event& e) override;
97 
98 
99 private:
100 
101  int fRun;
102  int fSubrun;
103  int fEvent;
104 
105  //CRT
106 
107  // fcl file parameters
108  art::InputTag fSimModuleLabel; ///< name of detsim producer
109  art::InputTag fCRTSimLabel; ///< name of CRT producer
110  std::string fFEBDataLabel; ///< name of FEBData producer
111  bool fVerbose; ///< print information about what's going on
113  size_t fFirstFEBMac5; ///< lowest mac5 address for CRT FEBs
114 
115  //limits for array sizes
116  enum LIMITS{
118  num_febs = 255,
120  };
121 
122  //arrays to store FEBinfo by module (want one fragment per module per event)
123  std::string taggers[num_febs];
129 
130 
131  // Other variables shared between different methods.
134 
135  //PMT
136 
137  // fhicl parameters
138  std::string fInputModuleNameWvfm;
140  int fBaseline; // baseline in simulation, default 8000 ADC (for expanding waveforms only, when not fully simulated)
141  int fMultiplicityThreshold; // number of PMT pairs in hardware trigger to pass
143  uint32_t nChannelsFrag;
144  uint32_t wfm_length; // ~10us, 2ns tick
145 
146  // PD information
147  opdet::sbndPDMapAlg pdMap; // photon detector map
148  std::vector<unsigned int> channelList;
149 
150  // waveforms
151  std::vector<std::vector<short>> wvf_channel;
152 
153  // sampling rate
154  double fSampling;
155 
156  // services
157  art::ServiceHandle<art::TFileService> tfs;
158 
159  // random numbers
160  CLHEP::HepRandomEngine& fTriggerTimeEngine;
161 
162 }; // class ArtdaqFragmentProducer
163 
164 
166  : EDProducer{p},
167  fSimModuleLabel(p.get<std::string>("SimModuleLabel", "largeant")),
168  fCRTSimLabel(p.get<std::string>("CRTSimLabel", "crt")),
169  fFEBDataLabel(p.get<std::string>("FEBDataLabel", "crtsim")),
170  fVerbose(p.get<bool>("Verbose", false)),
171  fClockSpeedCRT(p.get<double>("ClockSpeedCRT")),
172  fFirstFEBMac5(p.get<size_t>("FirstFEBMac5", 0)),
173  fInputModuleNameWvfm(p.get<std::string>("InputModuleNameWvfm")),
174  fInputModuleNameTrigger(p.get<std::string>("InputModuleNameTrigger")),
175  fBaseline(p.get<int>("Baseline",8000)),
176  fMultiplicityThreshold(p.get<int>("MultiplicityThreshold")),
177  fBeamWindowLength(p.get<double>("BeamWindowLength", 1.6)),
178  nChannelsFrag(p.get<double>("nChannelsFrag", 15)),
179  wfm_length(p.get<double>("WfmLength", 5120)),
180  fTriggerTimeEngine(art::ServiceHandle<rndm::NuRandomService>{}->createEngine(*this, "HepJamesRandom", "trigger", p, "SeedTriggerTime"))
181  // More initializers here.
182 {
183  // Call appropriate produces<>() functions here.
184  produces< std::vector<artdaq::Fragment> >();
185 
186  // Get a pointer to the fGeometryServiceetry service provider
187  fGeometryService = lar::providerFrom<geo::Geometry>();
188 
189  // get clock
190  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
191  fSampling = clockData.OpticalClock().Frequency(); // MHz
192 
193  // build PD map and channel list
194  auto subsetCondition = [](auto const& i)->bool { return i["pd_type"] == "pmt_coated" || i["pd_type"] == "pmt_uncoated"; };
195  auto pmtMap = pdMap.getCollectionFromCondition(subsetCondition);
196  if (fVerbose) std::cout << "Number of PDs selected: \t" << pmtMap.size() << "\n";
197  for(auto const& i:pmtMap){
198  channelList.push_back(i["channel"]);
199  }
200 
201 }
202 
203 
205 {
206 
207  // Fetch basic event info
208  // event information
209  fRun = e.run();
210  fSubrun = e.subRun();
211  fEvent = e.id().event();
212  if(fVerbose){
213  std::cout<<"============================================"<<std::endl
214  <<"Run = "<<fRun<<", SubRun = "<<fSubrun<<", Event = "<<fEvent<<std::endl
215  <<"============================================"<<std::endl;
216  }
217 
218  //----------------------------------------------------------------------------------------------------------
219  // CRT
220  //----------------------------------------------------------------------------------------------------------
221 
222  for(int i=0; i<num_febs; i++){empty_fragment[i]=true;}
223 
224  int num_module = fCrtGeo.NumModules();
225 
226  //----------------------------------------------------------------------------------------------------------
227  // GETTING PRODUCTS
228  //----------------------------------------------------------------------------------------------------------
229 
230  // Get FEB data from the event
231  art::Handle<std::vector<sbnd::crt::FEBData>> feb_data_h;
232  e.getByLabel(fFEBDataLabel, feb_data_h);
233 
234  // make sure hits look good
235  if (!feb_data_h.isValid()) {
236  throw art::Exception(art::errors::Configuration) << "could not locate FEBData." << std::endl;;
237  }
238 
239  std::vector<art::Ptr<sbnd::crt::FEBData>> feb_data_v;
240  art::fill_ptr_vector(feb_data_v, feb_data_h);
241 
242  art::FindManyP<sim::AuxDetIDE, sbnd::crt::FEBTruthInfo> febdata_to_ides (feb_data_h, e, fFEBDataLabel);
243 
244  //Fill arrays with default values
245  std::fill(feb_hits_in_fragments, feb_hits_in_fragments + sizeof(feb_hits_in_fragments), 0);
246 
247  // fragments vector
248  std::unique_ptr<std::vector<artdaq::Fragment>> vecFrag = std::make_unique<std::vector<artdaq::Fragment>>();
249 
250  // set properties of fragment that are common to event
251  //quantities in fragment
252  uint16_t lostcpu = 0;
253  uint16_t lostfpga = 0;
254  uint32_t coinc = 0;
255  uint16_t lost_hits = 0; //number of lost hits from the previous one
256 
257 
258  //metadata
259  uint64_t run_start_time = 0;
260  uint64_t this_poll_start = 0;
261  uint64_t this_poll_end = 0;
262  int32_t system_clock_deviation = 0;
263  uint32_t feb_hits_in_poll = 0;
264 
265  //information from fragment header
266  uint64_t sequence_id = fEvent;
267 
268  uint64_t temp_last_time = 0;
269 
270  //random number generator to bu used to simulate pedestal
271  std::default_random_engine generator;
272  std::normal_distribution<double> distribution(175.0,23.0);
273 
274  //loop through FEBData product and sort by module/mac5
275  for (size_t feb_i = 0; feb_i < feb_data_v.size(); feb_i++) {
276 
277  auto const feb_data = feb_data_v[feb_i];
278 
279  if(fVerbose){std::cout << "FEB " << feb_i << " with mac " << feb_data->Mac5() << std::endl;}
280 
281  empty_fragment[feb_data->Mac5()] = false;
282 
283  int channel = feb_data->Mac5() * 32;
284  std::string stripName = fCrtGeo.ChannelToStripName(channel);
285  std::string tagger = fCrtGeo.GetTaggerName(stripName);
286  taggers[feb_data->Mac5()] = tagger;
287 
288  T0s[feb_data->Mac5()][feb_hits_in_fragments[feb_data->Mac5()]] = feb_data->Ts0();
289  T1s[feb_data->Mac5()][feb_hits_in_fragments[feb_data->Mac5()]] = feb_data->Ts1();
290  for (int i_adc = 0; i_adc<32; i_adc++){
291  uint16_t adc = 0;
292  if (feb_data->ADC()[i_adc] > 4089){
293  adc = 4089;
294  }else if (feb_data->ADC()[i_adc] == 0){
295  //pull from a normal distribution to simulate pedestal
296  adc = distribution(generator);
297  }else{
298  adc = feb_data->ADC()[i_adc];
299  }
300  ADCs[feb_data->Mac5()][feb_hits_in_fragments[feb_data->Mac5()]][i_adc] = adc;
301  }
302 
303  feb_hits_in_fragments[feb_data->Mac5()]++;
304 
305  }//FEBData loop
306 
307  //make one fragment for every module
308  for (size_t feb_i = fFirstFEBMac5; feb_i < num_module+fFirstFEBMac5; feb_i++){
309  //quantities in fragment
310  if (empty_fragment[feb_i]){
311  //if no hits for a module, make a simulated "T1 reset" event to avoid missing fragments
312  feb_hits_in_fragments[feb_i] = 1;
313  int channel = feb_i * 32;
314  std::string stripName = fCrtGeo.ChannelToStripName(channel);
315  std::string tagger = fCrtGeo.GetTaggerName(stripName);
316  taggers[feb_i] = tagger;
317 
318  T0s[feb_i][0] = 0;
319  T1s[feb_i][0] = 0;
320  for (int i_adc = 0; i_adc<32; i_adc++){
321  uint16_t adc = distribution(generator);
322  ADCs[feb_i][0][i_adc] = adc;
323  }
324  }
325 
326  if (feb_hits_in_fragments[feb_i]==0) continue;
327 
328  //metadata
329  uint8_t mac5 = (uint8_t)feb_i; //last 8 bits of FEB mac5 address
330  uint16_t feb_hits_in_fragment = feb_hits_in_fragments[feb_i];
331 
332  sbndaq::BernCRTFragmentMetadataV2 metadata;
333 
334  metadata.set_mac5(mac5);
335  metadata.set_clock_deviation(system_clock_deviation);
336  metadata.set_hits_in_poll(feb_hits_in_poll);
337  metadata.set_hits_in_fragment(feb_hits_in_fragment);
338  metadata.set_run_start_time(run_start_time);
339  metadata.update_poll_time(this_poll_start, this_poll_end);
340 
341  uint64_t timestamp = (uint64_t)(T0s[feb_i][feb_hits_in_fragments[feb_i]]/fClockSpeedCRT); //absolute timestamp
342 
343  // create fragment
344  sbnd::CRTPlane plane_num = sbnd::CRTCommonUtils::GetPlaneIndex(taggers[feb_i]);
345  uint16_t fragmentIDVal = 32768 + 12288 + (plane_num * 256) + (uint16_t)mac5;
346  if(fVerbose){std::cout<<"fragmentID: "<<std::bitset<16>{fragmentIDVal}<<std::endl;}
347  auto fragment_uptr = artdaq::Fragment::FragmentBytes(sizeof(sbndaq::BernCRTHitV2)*metadata.hits_in_fragment(), //payload_size
348  sequence_id,
349  fragmentIDVal,
350  sbndaq::detail::FragmentType::BERNCRTV2,
351  metadata,
352  timestamp
353  ); // unique pointer
354 
355  // populate fragment
356  std::vector<sbndaq::BernCRTHitV2> data_vec;
357  for (int i_frag = 0; i_frag<feb_hits_in_fragments[feb_i]; i_frag++){
358  sbndaq::BernCRTHitV2 hit;
359 
360  uint8_t flags = 3;
361  uint32_t ts0 = T0s[feb_i][i_frag];
362  uint32_t ts1 = T1s[feb_i][i_frag];
363 
364  if (ts0==0){flags=7;}else if (ts1==0){flags=11;}
365 
366  uint64_t feb_hit_number = feb_hits_in_fragments[feb_i]; //hit counter for individual FEB, including hits lost in FEB or fragment generator
367  timestamp = (uint64_t)ts0/fClockSpeedCRT; //absolute timestamp
368  uint64_t last_accepted_timestamp = temp_last_time; //timestamp of previous accepted hit
369  temp_last_time = timestamp;
370 
371  hit.flags = (uint16_t)flags;
372  hit.lostcpu = (uint16_t)lostcpu;
373  hit.lostfpga = (uint16_t)lostfpga;
374  hit.ts0 = (uint32_t)ts0;
375  hit.ts1 = (uint32_t)ts1;
376  for (int i_adc = 0; i_adc<32; i_adc++){
377  hit.adc[i_adc] = ADCs[feb_i][i_frag][i_adc];
378  }
379  hit.coinc = (uint32_t)coinc;
380  hit.feb_hit_number = (uint64_t)feb_hit_number;
381  hit.timestamp = (uint64_t)timestamp;
382  hit.last_accepted_timestamp = (uint64_t)last_accepted_timestamp;
383  hit.lost_hits = (uint16_t)lost_hits;
384 
385  data_vec.emplace_back(hit);
386  }//bern crt hit vector
387 
388  //copy data vector of hits into the fragment we made
389  std::memcpy(fragment_uptr->dataBeginBytes(), data_vec.data(), sizeof(sbndaq::BernCRTHitV2)*metadata.hits_in_fragment());
390 
391  // add fragment to vector
392  vecFrag->push_back(*fragment_uptr);
393 
394  }//module (mac5) loop
395 
396  int num_crt_frags = vecFrag->size();
397  if(fVerbose) std::cout << "CRT Fragments written: " << num_crt_frags << std::endl;
398 
399  //----------------------------------------------------------------------------------------------------------
400  // PMT
401  //----------------------------------------------------------------------------------------------------------
402 
403  // access PMT waveforms and hardware trigger information
404  art::Handle< std::vector< raw::OpDetWaveform > > wvfmHandle;
405  art::Handle< std::vector< sbnd::comm::pmtTrigger > > triggerHandle;
406  e.getByLabel(fInputModuleNameWvfm, wvfmHandle);
407  e.getByLabel(fInputModuleNameTrigger, triggerHandle);
408 
409  if(!wvfmHandle.isValid()) {
410  throw art::Exception(art::errors::Configuration)
411  << "Could not find any waveforms, input must contain OpDetWaveforms." << "\n";
412  }
413  if(!triggerHandle.isValid()) {
414  throw art::Exception(art::errors::Configuration)
415  << "Could not find any PMT hardware trigger object, must run PMT trigger producer before running this module." << "\n";
416  }
417 
418  // create empty vectors to hold waveforms for each channel
419  double fMinStartTime = -1510.0;//in us
420  double fMaxEndTime = 1510.0;//in us
421 
422  for(auto const& wvf : (*wvfmHandle)) {
423  double fChNumber = wvf.ChannelNumber();
424  std::string opdetType = pdMap.pdType(fChNumber);
425  // only look at pmts
426  if (opdetType != "pmt_coated" && opdetType != "pmt_uncoated") continue;
427  if (wvf.TimeStamp() < fMinStartTime){ fMinStartTime = wvf.TimeStamp(); }
428  if ((double(wvf.size()) / fSampling + wvf.TimeStamp()) > fMaxEndTime){ fMaxEndTime = double(wvf.size()) / fSampling + wvf.TimeStamp();}
429  }
430 
431  if (fVerbose){std::cout<<"MinStartTime: "<<fMinStartTime<<" MaxEndTime: "<<fMaxEndTime<<std::endl;}
432 
433  std::vector<short> wvf_0; wvf_0.reserve((int)(3020*1e6/2));
434  for (double i = fMinStartTime; i<fMaxEndTime+(1./fSampling); i+=(1./fSampling)){
435  wvf_0.push_back(fBaseline);
436  }
437  for (size_t i = 0; i < channelList.size(); i++){
438  wvf_channel.push_back(wvf_0);
439  }
440 
441  // counters
442  int num_pmt_wvf = 0;
443 
444  // loop through waveform handles
445  size_t wvf_id = -1;
446  size_t hist_id = -1;
447  for(auto const& wvf : (*wvfmHandle)) {
448  wvf_id++;
449  double fChNumber = wvf.ChannelNumber();
450  std::string opdetType = pdMap.pdType(fChNumber);
451 
452  // only look at pmts
453  if (opdetType != "pmt_coated" && opdetType != "pmt_uncoated") continue;
454 
455  num_pmt_wvf++;
456 
457  double fStartTime = wvf.TimeStamp(); // in us
458  double fEndTime = double(wvf.size()) / fSampling + fStartTime; // in us
459 
460  // create full waveform
461  std::vector<short> wvf_full; wvf_full.reserve((short)(3020*1e6/2));
462 
463  if (fStartTime > fMinStartTime){
464  for (double i = fStartTime-fMinStartTime; i>0.; i-=(1./fSampling)){
465  wvf_full.push_back(fBaseline);
466  }
467  }
468 
469  for(unsigned int i = 0; i < wvf.size(); i++) {
470  wvf_full.push_back(wvf[i]);
471  }
472 
473  if (fEndTime < fMaxEndTime){
474  for (double i = fMaxEndTime-fEndTime; i>0.; i-=(1./fSampling)){
475  wvf_full.push_back(fBaseline);
476  }
477  }
478 
479  // combine waveform with any other waveforms from same channel
480  int i_ch = -1.;
481  auto ich = std::find(channelList.begin(), channelList.end(), fChNumber);
482  if (ich != channelList.end()){
483  i_ch = ich - channelList.begin();
484  }
485  if (wvf_channel.at(i_ch).size() < wvf_full.size()){
486  if (fVerbose) std::cout<<"Full waveform -- Previous Channel" << fChNumber <<" Size: "<<wvf_channel.at(i_ch).size()<<"New Channel" << fChNumber <<" Size: "<<wvf_full.size()<<std::endl;
487  for(unsigned int i = wvf_channel.at(i_ch).size(); i < wvf_full.size(); i++) {
488  wvf_channel.at(i_ch).push_back(fBaseline);
489  }
490  }
491  for(unsigned int i = 0; i < wvf_full.size(); i++) {
492  wvf_channel.at(i_ch)[i] += (wvf_full[i] - fBaseline);
493  }
494 
495  hist_id++;
496 
497  wvfmHandle.clear();
498  } // waveform handle loop
499 
500  // access hardware trigger information
501  std::vector<size_t> triggerIndex;
502  for(auto const& trigger : (*triggerHandle)) {
503  for (size_t idx = 0; idx < trigger.numPassed.size(); idx++) {
504  if (trigger.numPassed[idx] >= fMultiplicityThreshold) {
505  // save index
506  triggerIndex.push_back(idx);
507  // skip ahead by 5120 samples (downsampled by 4) before checking again
508  idx += 1280;
509  }
510  }
511  } // trigger handle loop
512 
513  if (fVerbose) std::cout << "Number of PMT hardware triggers found: " << triggerIndex.size() << std::endl;
514 
515  // set properties of fragment that are common to event
516  uint32_t nChannelsTotal = channelList.size();
517  //uint32_t nChannelsFrag = 15;
518  uint32_t nFrag = (uint32_t)nChannelsTotal/nChannelsFrag;
519  //uint32_t wfm_length = 5120; // ~10us, 2ns tick
520 
521  // fragment properties
522  uint32_t sequenceIDVal = fEvent;
523 
524  // create and populate common metadata
525  sbndaq::CAENV1730FragmentMetadata metadata;
526  metadata.nChannels = nChannelsFrag + 1; // 15 PMT channels + final channel to store beam window / trigger information
527  metadata.nSamples = wfm_length;
528 
529  // fragment handle properties
530  uint32_t eventCounterVal = fEvent;
531  uint32_t boardIDVal = 0;
532  uint32_t triggerTimeTagVal = (uint32_t)CLHEP::RandFlat::shoot(&fTriggerTimeEngine, 0, 1e9);
533  uint32_t eventSizeVal = ((wfm_length * (nChannelsFrag+1)) * sizeof(uint16_t) + sizeof(sbndaq::CAENV1730EventHeader)) / sizeof(uint32_t);
534 
535  // loop over PMT hardware triggers
536  for (auto wvfIdx : triggerIndex) {
537 
538  // index in full waveform, 2ns tick
539  size_t trigIdx = wvfIdx*4;
540  size_t startIdx = trigIdx-500; // -1us
541 
542  // determine and set timestamp for particular trigger
543  double triggerTime = fMinStartTime + wvfIdx*0.008; // in us
544  double timestampVal = 0.5 + (triggerTime*1e-6); // in seconds // std::time(nullptr); // current time
545  metadata.timeStampSec = (uint32_t)timestampVal;
546  metadata.timeStampNSec = (uint32_t)(timestampVal*1e9);
547 
548  // create fragments to hold waveforms, set properties and populate
549  // 15 PMTs stored per fragment, 120/15 = 8 fragments per trigger
550  for (size_t counter = 0; counter < nFrag; counter++) {
551 
552  // create fragment
553  const auto fragment_datasize_bytes = metadata.ExpectedDataSize();
554  uint32_t fragmentIDVal = counter;
555  auto fragment_uptr = artdaq::Fragment::FragmentBytes(fragment_datasize_bytes, sequenceIDVal, fragmentIDVal, sbndaq::detail::FragmentType::CAENV1730, metadata); // unique pointer
556  fragment_uptr->setTimestamp(timestampVal);
557 
558  // populate fragment header
559  auto header_ptr = reinterpret_cast<sbndaq::CAENV1730EventHeader*>(fragment_uptr->dataBeginBytes());
560 
561  header_ptr->eventCounter = eventCounterVal;
562  header_ptr->boardID = boardIDVal;
563  header_ptr->triggerTimeTag = triggerTimeTagVal; // ns // set timetag as random value for event
564  header_ptr->eventSize = eventSizeVal;
565 
566  // populate waveforms
567  // populate fragment with waveform
568  uint16_t* data_begin = reinterpret_cast<uint16_t*>(fragment_uptr->dataBeginBytes() + sizeof(sbndaq::CAENV1730EventHeader));
569  uint16_t* value_ptr = data_begin;
570  uint16_t value = 0;
571  size_t ch_offset = 0;
572 
573  // loop over channels
574  for (size_t i_ch = 0; i_ch < nChannelsFrag; i_ch++) {
575  ch_offset = (size_t)(i_ch*wfm_length);
576  // loop over waveform
577  for (size_t i_t = 0; i_t < wfm_length; i_t++) {
578  // set value
579  value = wvf_channel[counter*nChannelsFrag + i_ch][startIdx+i_t];
580  value_ptr = data_begin + ch_offset + i_t;
581  *value_ptr = value;
582  }
583  }
584 
585  // create add beam window trigger waveform
586  ch_offset = (size_t)(nChannelsFrag*wfm_length);
587  size_t beamStartIdx = abs(fMinStartTime)*1000/2;
588  size_t beamEndIdx = beamStartIdx + fBeamWindowLength*1000/2;
589  // loop over waveform
590  for (size_t i_t = 0; i_t < wfm_length; i_t++) {
591  // set value
592  if (startIdx + i_t >= beamStartIdx && startIdx + i_t <= beamEndIdx) value = 1;
593  else value = 0;
594  value_ptr = data_begin + ch_offset + i_t;
595  *value_ptr = value;
596  }
597 
598  // add fragment to vector
599  vecFrag->push_back(*fragment_uptr);
600  }
601  }
602 
603  if(fVerbose) std::cout << "PMT Fragments written: " << vecFrag->size() - num_crt_frags << std::endl;
604 
605 
606  //produce fragment vector
607  e.put(std::move(vecFrag));
608 
609  // clear variables
610  wvf_channel.clear();
611  wvf_channel.shrink_to_fit();
612 
613 } // ArtdaqFragmentProducer::produce()
614 
615 
616 
617 DEFINE_ART_MODULE(sbnd::trigger::ArtdaqFragmentProducer)
pdgs p
Definition: selectors.fcl:22
std::vector< std::vector< short > > wvf_channel
process_name hit
Definition: cheaterreco.fcl:51
art::ServiceHandle< art::TFileService > tfs
Access the description of detector geometry.
T abs(T value)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
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
art::InputTag fSimModuleLabel
name of detsim producer
art framework interface to geometry description for auxiliary detectors
enum::sbnd::CRTPlane GetPlaneIndex(std::string tagger)
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
ArtdaqFragmentProducer & operator=(ArtdaqFragmentProducer const &)=delete
Description of geometry of one entire detector.
Definition of data types for geometry description.
uint16_t ADCs[num_febs][max_hits_in_fragment][num_channels]
bool fVerbose
print information about what&#39;s going on
do i e
size_t fFirstFEBMac5
lowest mac5 address for CRT FEBs
art::InputTag fCRTSimLabel
name of CRT producer
stream1 can override from command line with o or output services user sbnd
Sample_t fBaseline
Waveform baseline [ADC counts].
uint32_t T0s[num_febs][max_hits_in_fragment]
temporary value
uint32_t T1s[num_febs][max_hits_in_fragment]
std::string fFEBDataLabel
name of FEBData producer
art framework interface to geometry description
BEGIN_PROLOG could also be cout