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

Public Member Functions

 CRTArtdaqFragmentProducer (fhicl::ParameterSet const &p)
 
 CRTArtdaqFragmentProducer (CRTArtdaqFragmentProducer const &)=delete
 
 CRTArtdaqFragmentProducer (CRTArtdaqFragmentProducer &&)=delete
 
CRTArtdaqFragmentProduceroperator= (CRTArtdaqFragmentProducer const &)=delete
 
CRTArtdaqFragmentProduceroperator= (CRTArtdaqFragmentProducer &&)=delete
 
void produce (art::Event &e) override
 

Private Types

enum  LIMITS { max_hits_in_fragment = 50, num_febs = 255, num_channels = 32 }
 

Private Attributes

int fRun
 
int fSubrun
 
int fEvent
 
art::InputTag fSimModuleLabel
 name of detsim producer More...
 
art::InputTag fCRTSimLabel
 name of CRT producer More...
 
std::string fFEBDataLabel
 name of FEBData producer More...
 
bool fVerbose
 print information about what's going on More...
 
double fClockSpeedCRT
 
size_t fFirstFEBMac5
 lowest mac5 address for CRT FEBs More...
 
geo::GeometryCore const * fGeometryService
 
CRTGeoAlg fCrtGeo
 
std::string taggers [num_febs]
 
uint16_t feb_hits_in_fragments [num_febs]
 
uint16_t ADCs [num_febs][max_hits_in_fragment][num_channels]
 
uint32_t T0s [num_febs][max_hits_in_fragment]
 
uint32_t T1s [num_febs][max_hits_in_fragment]
 
bool empty_fragment [num_febs]
 

Detailed Description

Definition at line 78 of file CRTArtdaqFragmentProducer_module.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

sbnd::trigger::CRTArtdaqFragmentProducer::CRTArtdaqFragmentProducer ( fhicl::ParameterSet const &  p)
explicit

Definition at line 130 of file CRTArtdaqFragmentProducer_module.cc.

131  : EDProducer{p},
132  fSimModuleLabel(p.get<std::string>("SimModuleLabel", "largeant")),
133  fCRTSimLabel(p.get<std::string>("CRTSimLabel", "crt")),
134  fFEBDataLabel(p.get<std::string>("FEBDataLabel", "crtsim")),
135  fVerbose(p.get<bool>("Verbose", false)),
136  fClockSpeedCRT(p.get<double>("ClockSpeedCRT")),
137  fFirstFEBMac5(p.get<size_t>("FirstFEBMac5", 0))
138  // More initializers here.
139 {
140  // Call appropriate produces<>() functions here.
141  produces< std::vector<artdaq::Fragment> >();
142 
143  // Get a pointer to the fGeometryServiceetry service provider
144  fGeometryService = lar::providerFrom<geo::Geometry>();
145 
146 }
bool fVerbose
print information about what&#39;s going on
size_t fFirstFEBMac5
lowest mac5 address for CRT FEBs
art::InputTag fSimModuleLabel
name of detsim producer
pdgs p
Definition: selectors.fcl:22
sbnd::trigger::CRTArtdaqFragmentProducer::CRTArtdaqFragmentProducer ( CRTArtdaqFragmentProducer const &  )
delete
sbnd::trigger::CRTArtdaqFragmentProducer::CRTArtdaqFragmentProducer ( CRTArtdaqFragmentProducer &&  )
delete

Member Function Documentation

CRTArtdaqFragmentProducer& sbnd::trigger::CRTArtdaqFragmentProducer::operator= ( CRTArtdaqFragmentProducer const &  )
delete
CRTArtdaqFragmentProducer& sbnd::trigger::CRTArtdaqFragmentProducer::operator= ( CRTArtdaqFragmentProducer &&  )
delete
void sbnd::trigger::CRTArtdaqFragmentProducer::produce ( art::Event &  e)
override

Definition at line 149 of file CRTArtdaqFragmentProducer_module.cc.

150 {
151 
152  // Fetch basic event info
153  // event information
154  fRun = e.run();
155  fSubrun = e.subRun();
156  fEvent = e.id().event();
157  if(fVerbose){
158  std::cout<<"============================================"<<std::endl
159  <<"Run = "<<fRun<<", SubRun = "<<fSubrun<<", Event = "<<fEvent<<std::endl
160  <<"============================================"<<std::endl;
161  }
162 
163 
164  for(int i=0; i<num_febs; i++){empty_fragment[i]=true;}
165 
166  int num_module = fCrtGeo.NumModules();
167 
168  //----------------------------------------------------------------------------------------------------------
169  // GETTING PRODUCTS
170  //----------------------------------------------------------------------------------------------------------
171 
172  // Get FEB data from the event
173  art::Handle<std::vector<sbnd::crt::FEBData>> feb_data_h;
174  e.getByLabel(fFEBDataLabel, feb_data_h);
175 
176  // make sure hits look good
177  if (!feb_data_h.isValid()) {
178  throw art::Exception(art::errors::Configuration) << "could not locate FEBData." << std::endl;;
179  }
180 
181  std::vector<art::Ptr<sbnd::crt::FEBData>> feb_data_v;
182  art::fill_ptr_vector(feb_data_v, feb_data_h);
183 
184  art::FindManyP<sim::AuxDetIDE, sbnd::crt::FEBTruthInfo> febdata_to_ides (feb_data_h, e, fFEBDataLabel);
185 
186  //Fill arrays with default values
188 
189  // fragments vector
190  std::unique_ptr<std::vector<artdaq::Fragment>> vecFrag = std::make_unique<std::vector<artdaq::Fragment>>();
191 
192  // set properties of fragment that are common to event
193  //quantities in fragment
194  uint16_t lostcpu = 0;
195  uint16_t lostfpga = 0;
196  uint32_t coinc = 0;
197  uint16_t lost_hits = 0; //number of lost hits from the previous one
198 
199 
200  //metadata
201  uint64_t run_start_time = 0;
202  uint64_t this_poll_start = 0;
203  uint64_t this_poll_end = 0;
204  int32_t system_clock_deviation = 0;
205  uint32_t feb_hits_in_poll = 0;
206 
207  //information from fragment header
208  uint64_t sequence_id = fEvent;
209 
210  uint64_t temp_last_time = 0;
211 
212  //random number generator to be used to simulate pedestal
213  std::default_random_engine generator;
214  std::normal_distribution<double> distribution(175.0,23.0);
215 
216  //list all fragment ids - uncomment if needed for daq running
217  /*if (fVerbose){std::cout<<"Num Modules: "<<fCrtGeo.NumModules()<<std::endl;}
218  for (size_t mod_i = 0; mod_i<fCrtGeo.NumModules(); mod_i++){
219  int plane = sbnd::CRTCommonUtils::GetPlaneIndex(fCrtGeo.GetTaggerName(fCrtGeo.ChannelToStripName(mod_i * 32)));
220  if (fVerbose){std::cout << std::hex << (32768 + 12288 + (plane * 256) + (int)mod_i) << std::endl;}
221  } */
222 
223  //loop through FEBData product and sort by module/mac5
224  for (size_t feb_i = 0; feb_i < feb_data_v.size(); feb_i++) {
225 
226  auto const feb_data = feb_data_v[feb_i];
227 
228  if(fVerbose){std::cout << "FEB " << feb_i << " with mac " << feb_data->Mac5() << std::endl;}
229 
230  empty_fragment[feb_data->Mac5()] = false;
231 
232  int channel = feb_data->Mac5() * 32;
233  std::string stripName = fCrtGeo.ChannelToStripName(channel);
234  std::string tagger = fCrtGeo.GetTaggerName(stripName);
235  taggers[feb_data->Mac5()] = tagger;
236 
237  T0s[feb_data->Mac5()][feb_hits_in_fragments[feb_data->Mac5()]] = feb_data->Ts0();
238  T1s[feb_data->Mac5()][feb_hits_in_fragments[feb_data->Mac5()]] = feb_data->Ts1();
239  for (int i_adc = 0; i_adc<32; i_adc++){
240  uint16_t adc = 0;
241  if (feb_data->ADC()[i_adc] > 4089){
242  adc = 4089;
243  }else if (feb_data->ADC()[i_adc] == 0){
244  //pull from a normal distribution to simulate pedestal
245  adc = distribution(generator);
246  }else{
247  adc = feb_data->ADC()[i_adc];
248  }
249  ADCs[feb_data->Mac5()][feb_hits_in_fragments[feb_data->Mac5()]][i_adc] = adc;
250  }
251 
252  feb_hits_in_fragments[feb_data->Mac5()]++;
253 
254  }//FEBData loop
255 
256  //make one fragment for every module
257  for (size_t feb_i = fFirstFEBMac5; feb_i < num_module+fFirstFEBMac5; feb_i++){
258  //quantities in fragment
259  if (empty_fragment[feb_i]){
260  //if no hits for a module, make a simulated "T1 reset" event to avoid missing fragments
261  feb_hits_in_fragments[feb_i] = 1;
262  int channel = feb_i * 32;
263  std::string stripName = fCrtGeo.ChannelToStripName(channel);
264  std::string tagger = fCrtGeo.GetTaggerName(stripName);
265  taggers[feb_i] = tagger;
266 
267  T0s[feb_i][0] = 0;
268  T1s[feb_i][0] = 0;
269  for (int i_adc = 0; i_adc<32; i_adc++){
270  uint16_t adc = distribution(generator);
271  ADCs[feb_i][0][i_adc] = adc;
272  }
273  }
274 
275  if (feb_hits_in_fragments[feb_i]==0) continue;
276 
277  //metadata
278  uint8_t mac5 = (uint8_t)feb_i; //last 8 bits of FEB mac5 address
279  uint16_t feb_hits_in_fragment = feb_hits_in_fragments[feb_i];
280 
281  sbndaq::BernCRTFragmentMetadataV2 metadata;
282 
283  metadata.set_mac5(mac5);
284  metadata.set_clock_deviation(system_clock_deviation);
285  metadata.set_hits_in_poll(feb_hits_in_poll);
286  metadata.set_hits_in_fragment(feb_hits_in_fragment);
287  metadata.set_run_start_time(run_start_time);
288  metadata.update_poll_time(this_poll_start, this_poll_end);
289 
290  uint64_t timestamp = (uint64_t)(T0s[feb_i][feb_hits_in_fragments[feb_i]]/fClockSpeedCRT); //absolute timestamp
291 
292  // create fragment
294  uint16_t fragmentIDVal = 32768 + 12288 + (plane_num * 256) + (uint16_t)mac5;
295  if(fVerbose){std::cout<<"fragmentID: "<<std::bitset<16>{fragmentIDVal}<<std::endl;}
296  auto fragment_uptr = artdaq::Fragment::FragmentBytes(sizeof(sbndaq::BernCRTHitV2)*metadata.hits_in_fragment(), //payload_size
297  sequence_id,
298  fragmentIDVal,
299  sbndaq::detail::FragmentType::BERNCRTV2,
300  metadata,
301  timestamp
302  ); // unique pointer
303 
304  // populate fragment
305  std::vector<sbndaq::BernCRTHitV2> data_vec;
306  for (int i_frag = 0; i_frag<feb_hits_in_fragments[feb_i]; i_frag++){
307  sbndaq::BernCRTHitV2 hit;
308 
309  uint8_t flags = 3;
310  uint32_t ts0 = T0s[feb_i][i_frag];
311  uint32_t ts1 = T1s[feb_i][i_frag];
312 
313  if (ts1==0){flags=11;}else if (ts0==0){flags=7;}
314 
315  uint64_t feb_hit_number = feb_hits_in_fragments[feb_i]; //hit counter for individual FEB, including hits lost in FEB or fragment generator
316  timestamp = (uint64_t)ts0/fClockSpeedCRT; //absolute timestamp
317  uint64_t last_accepted_timestamp = temp_last_time; //timestamp of previous accepted hit
318  temp_last_time = timestamp;
319 
320  hit.flags = (uint16_t)flags;
321  hit.lostcpu = (uint16_t)lostcpu;
322  hit.lostfpga = (uint16_t)lostfpga;
323  hit.ts0 = (uint32_t)ts0;
324  hit.ts1 = (uint32_t)ts1;
325  for (int i_adc = 0; i_adc<32; i_adc++){
326  hit.adc[i_adc] = ADCs[feb_i][i_frag][i_adc];
327  }
328  hit.coinc = (uint32_t)coinc;
329  hit.feb_hit_number = (uint64_t)feb_hit_number;
330  hit.timestamp = (uint64_t)timestamp;
331  hit.last_accepted_timestamp = (uint64_t)last_accepted_timestamp;
332  hit.lost_hits = (uint16_t)lost_hits;
333 
334  data_vec.emplace_back(hit);
335  }//bern crt hit vector
336 
337  //copy data vector of hits into the fragment we made
338  std::memcpy(fragment_uptr->dataBeginBytes(), data_vec.data(), sizeof(sbndaq::BernCRTHitV2)*metadata.hits_in_fragment());
339 
340  // add fragment to vector
341  vecFrag->push_back(*fragment_uptr);
342 
343  }//module (mac5) loop
344 
345  if(fVerbose) std::cout << "Fragments written: " << vecFrag->size() << std::endl;
346 
347  e.put(std::move(vecFrag));
348 
349 
350 } // CRTArtdaqFragmentProducer::produce()
bool fVerbose
print information about what&#39;s going on
size_t fFirstFEBMac5
lowest mac5 address for CRT FEBs
process_name hit
Definition: cheaterreco.fcl:51
std::string ChannelToStripName(size_t channel) const
enum::sbnd::CRTPlane GetPlaneIndex(std::string tagger)
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
uint32_t T1s[num_febs][max_hits_in_fragment]
std::string GetTaggerName(std::string name) const
uint16_t ADCs[num_febs][max_hits_in_fragment][num_channels]
do i e
uint32_t T0s[num_febs][max_hits_in_fragment]
BEGIN_PROLOG could also be cout

Member Data Documentation

uint16_t sbnd::trigger::CRTArtdaqFragmentProducer::ADCs[num_febs][max_hits_in_fragment][num_channels]
private

Definition at line 119 of file CRTArtdaqFragmentProducer_module.cc.

bool sbnd::trigger::CRTArtdaqFragmentProducer::empty_fragment[num_febs]
private

Definition at line 122 of file CRTArtdaqFragmentProducer_module.cc.

double sbnd::trigger::CRTArtdaqFragmentProducer::fClockSpeedCRT
private

Definition at line 102 of file CRTArtdaqFragmentProducer_module.cc.

CRTGeoAlg sbnd::trigger::CRTArtdaqFragmentProducer::fCrtGeo
private

Definition at line 107 of file CRTArtdaqFragmentProducer_module.cc.

art::InputTag sbnd::trigger::CRTArtdaqFragmentProducer::fCRTSimLabel
private

name of CRT producer

Definition at line 99 of file CRTArtdaqFragmentProducer_module.cc.

uint16_t sbnd::trigger::CRTArtdaqFragmentProducer::feb_hits_in_fragments[num_febs]
private

Definition at line 118 of file CRTArtdaqFragmentProducer_module.cc.

int sbnd::trigger::CRTArtdaqFragmentProducer::fEvent
private

Definition at line 95 of file CRTArtdaqFragmentProducer_module.cc.

std::string sbnd::trigger::CRTArtdaqFragmentProducer::fFEBDataLabel
private

name of FEBData producer

Definition at line 100 of file CRTArtdaqFragmentProducer_module.cc.

size_t sbnd::trigger::CRTArtdaqFragmentProducer::fFirstFEBMac5
private

lowest mac5 address for CRT FEBs

Definition at line 103 of file CRTArtdaqFragmentProducer_module.cc.

geo::GeometryCore const* sbnd::trigger::CRTArtdaqFragmentProducer::fGeometryService
private

Definition at line 106 of file CRTArtdaqFragmentProducer_module.cc.

int sbnd::trigger::CRTArtdaqFragmentProducer::fRun
private

Definition at line 93 of file CRTArtdaqFragmentProducer_module.cc.

art::InputTag sbnd::trigger::CRTArtdaqFragmentProducer::fSimModuleLabel
private

name of detsim producer

Definition at line 98 of file CRTArtdaqFragmentProducer_module.cc.

int sbnd::trigger::CRTArtdaqFragmentProducer::fSubrun
private

Definition at line 94 of file CRTArtdaqFragmentProducer_module.cc.

bool sbnd::trigger::CRTArtdaqFragmentProducer::fVerbose
private

print information about what's going on

Definition at line 101 of file CRTArtdaqFragmentProducer_module.cc.

uint32_t sbnd::trigger::CRTArtdaqFragmentProducer::T0s[num_febs][max_hits_in_fragment]
private

Definition at line 120 of file CRTArtdaqFragmentProducer_module.cc.

uint32_t sbnd::trigger::CRTArtdaqFragmentProducer::T1s[num_febs][max_hits_in_fragment]
private

Definition at line 121 of file CRTArtdaqFragmentProducer_module.cc.

std::string sbnd::trigger::CRTArtdaqFragmentProducer::taggers[num_febs]
private

Definition at line 117 of file CRTArtdaqFragmentProducer_module.cc.


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