Public Member Functions | Private Attributes | List of all members
nnet::RawWaveformDump Class Reference
Inheritance diagram for nnet::RawWaveformDump:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 RawWaveformDump (fhicl::ParameterSet const &p)
 
 RawWaveformDump (RawWaveformDump const &)=delete
 
 RawWaveformDump (RawWaveformDump &&)=delete
 
RawWaveformDumpoperator= (RawWaveformDump const &)=delete
 
RawWaveformDumpoperator= (RawWaveformDump &&)=delete
 
void analyze (art::Event const &e) override
 
void beginJob () override
 
void endJob () override
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::string fDumpWaveformsFileName
 
std::string fSimulationProducerLabel
 producer that tracked simulated part. through detector More...
 
std::string fSimChannelLabel
 module that made simchannels More...
 
std::string fDigitModuleLabel
 module that made digits More...
 
std::string fWireProducerLabel
 
bool fUseFullWaveform
 
unsigned int fShortWaveformSize
 
std::string fSelectGenLabel
 
std::string fSelectProcID
 
int fSelectPDGCode
 
std::string fPlaneToDump
 
double fMinParticleEnergyGeV
 
double fMinEnergyDepositedMeV
 
int fMinNumberOfElectrons
 
int fMaxNumberOfElectrons
 
bool fSaveSignal
 
int fMaxNoiseChannelsPerEvent
 
std::string fCollectionPlaneLabel
 
art::ServiceHandle< geo::Geometryfgeom
 
art::ServiceHandle< cheat::ParticleInventoryServicePIS
 
CLHEP::RandFlat fRandFlat
 
c2numpy_writer npywriter
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 75 of file RawWaveformDump_module.cc.

Constructor & Destructor Documentation

nnet::RawWaveformDump::RawWaveformDump ( fhicl::ParameterSet const &  p)
explicit

Definition at line 170 of file RawWaveformDump_module.cc.

171  : EDAnalyzer{p}
172  , fDumpWaveformsFileName(p.get<std::string>("DumpWaveformsFileName", "dumpwaveforms"))
173  , fSimulationProducerLabel(p.get<std::string>("SimulationProducerLabel", "larg4Main"))
174  , fSimChannelLabel(p.get<std::string>("SimChannelLabel", "elecDrift"))
175  , fDigitModuleLabel(p.get<std::string>("DigitModuleLabel", "simWire"))
176  , fWireProducerLabel(p.get<std::string>("WireProducerLabel"))
177  , fUseFullWaveform(p.get<bool>("UseFullWaveform", true))
178  , fShortWaveformSize(p.get<unsigned int>("ShortWaveformSize"))
179  , fSelectGenLabel(p.get<std::string>("SelectGenLabel", "ANY"))
180  , fSelectProcID(p.get<std::string>("SelectProcID", "ANY"))
181  , fSelectPDGCode(p.get<int>("SelectPDGCode", 0))
182  , fPlaneToDump(p.get<std::string>("PlaneToDump"))
183  , fMinParticleEnergyGeV(p.get<double>("MinParticleEnergyGeV", 0.))
184  , fMinEnergyDepositedMeV(p.get<double>("MinEnergyDepositedMeV", 0.))
185  , fMinNumberOfElectrons(p.get<int>("MinNumberOfElectrons", 600))
186  , fMaxNumberOfElectrons(p.get<int>("MaxNumberOfElectrons", -1))
187  , fSaveSignal(p.get<bool>("SaveSignal", true))
188  , fMaxNoiseChannelsPerEvent(p.get<int>("MaxNoiseChannelsPerEvent"))
189  , fCollectionPlaneLabel(p.get<std::string>("CollectionPlaneLabel"))
191  instanceName, p, "SeedForRawWaveformDump"),
192  "HepJamesRandom", instanceName)}
193 {
194  if (std::getenv("CLUSTER") && std::getenv("PROCESS")) {
195  fDumpWaveformsFileName += string(std::getenv("CLUSTER")) + "-" + string(std::getenv("PROCESS")) + "-";
196  }
197 
198  if (fDigitModuleLabel.empty() && fWireProducerLabel.empty()) {
199  throw cet::exception("RawWaveformDump")
200  << "Both DigitModuleLabel and WireProducerLabel are empty";
201  }
202 
203  if ((!fDigitModuleLabel.empty()) && (!fWireProducerLabel.empty())) {
204  throw cet::exception("RawWaveformDump")
205  << "Only one of DigitModuleLabel and WireProducerLabel should be set";
206  }
207 }
std::string fDigitModuleLabel
module that made digits
base_engine_t & createEngine(seed_t seed)
std::string string
Definition: nybbler.cc:12
std::string fSimChannelLabel
module that made simchannels
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string getenv(std::string const &name)
Definition: getenv.cc:15
p
Definition: test.py:223
std::string fSimulationProducerLabel
producer that tracked simulated part. through detector
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
nnet::RawWaveformDump::RawWaveformDump ( RawWaveformDump const &  )
delete
nnet::RawWaveformDump::RawWaveformDump ( RawWaveformDump &&  )
delete

Member Function Documentation

void nnet::RawWaveformDump::analyze ( art::Event const &  e)
overridevirtual

Implements art::EDAnalyzer.

Definition at line 275 of file RawWaveformDump_module.cc.

276 {
277  cout << "Event "
278  << " " << evt.id().run() << " " << evt.id().subRun() << " " << evt.id().event() << endl;
279 
280  std::unique_ptr<genFinder> gf(new genFinder());
281 
282  // ... Read in the digit List object(s).
284  std::vector<art::Ptr<raw::RawDigit>> rawdigitlist;
285  if (evt.getByLabel(fDigitModuleLabel, digitVecHandle)) {
286  art::fill_ptr_vector(rawdigitlist, digitVecHandle);
287  }
288 
289  // ... Read in the wire List object(s).
290  art::Handle<std::vector<recob::Wire>> wireListHandle;
291  std::vector<art::Ptr<recob::Wire>> wirelist;
292  if (evt.getByLabel(fWireProducerLabel, wireListHandle)) {
293  art::fill_ptr_vector(wirelist, wireListHandle);
294  }
295 
296  if (rawdigitlist.empty() && wirelist.empty()) return;
297  if (rawdigitlist.size() && wirelist.size()) return;
298 
299  // channel status
300  lariov::ChannelStatusProvider const& channelStatus =
302 
303  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
304  auto const detProp =
306 
307  // ... Use the handle to get a particular (0th) element of collection.
308  unsigned int dataSize;
309  if (rawdigitlist.size()) {
310  art::Ptr<raw::RawDigit> digitVec0(digitVecHandle, 0);
311  dataSize = digitVec0->Samples(); //size of raw data vectors
312  }
313  else {
314  dataSize = (wirelist[0]->Signal()).size();
315  }
316  if (dataSize != detProp.ReadOutWindowSize()) {
317  std::cout << "!!!!! Bad dataSize: " << dataSize << std::endl;
318  return;
319  }
320 
321  // ... Build a map from channel number -> rawdigitVec
322  std::map<raw::ChannelID_t, art::Ptr<raw::RawDigit>> rawdigitMap;
323  raw::ChannelID_t chnum = raw::InvalidChannelID; // channel number
324  if (rawdigitlist.size()) {
325  for (size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter) {
326  art::Ptr<raw::RawDigit> digitVec(digitVecHandle, rdIter);
327  chnum = digitVec->Channel();
328  if (chnum == raw::InvalidChannelID) continue;
329  rawdigitMap[chnum] = digitVec;
330  }
331  }
332  // ... Build a map from channel number -> wire
333  std::map<raw::ChannelID_t, art::Ptr<recob::Wire>> wireMap;
334  if (wirelist.size()) {
335  for (size_t ich = 0; ich < wirelist.size(); ++ich) {
336  art::Ptr<recob::Wire> wire = wirelist[ich];
337  chnum = wire->Channel();
338  if (chnum == raw::InvalidChannelID) continue;
339  wireMap[chnum] = wire;
340  }
341  }
342 
343  // ... Read in MC particle list
345  if (!evt.getByLabel(fSimulationProducerLabel, particleHandle)) {
346  throw cet::exception("AnalysisExample")
347  << " No simb::MCParticle objects in this event - "
348  << " Line " << __LINE__ << " in file " << __FILE__ << std::endl;
349  }
350 
351  // ... Read in sim channel list
352  auto simChannelHandle =
353  evt.getValidHandle<std::vector<sim::SimChannel>>(fSimChannelLabel);
354 
355  if (!simChannelHandle->size()) return;
356 
357  // ... Create a map of track IDs to generator labels
358  //Get a list of generator names.
359  //std::vector<art::Handle<std::vector<simb::MCTruth>>> mcHandles;
360  //evt.getManyByType(mcHandles);
361  auto mcHandles = evt.getMany<std::vector<simb::MCTruth>>();
362  std::vector<std::pair<int, std::string>> track_id_to_label;
363 
364  for (auto const& mcHandle : mcHandles) {
365  const std::string& sModuleLabel = mcHandle.provenance()->moduleLabel();
366  art::FindManyP<simb::MCParticle> findMCParts(mcHandle, evt, fSimulationProducerLabel);
367  std::vector<art::Ptr<simb::MCParticle>> mcParts = findMCParts.at(0);
368  for (const art::Ptr<simb::MCParticle> ptr : mcParts) {
369  int track_id = ptr->TrackId();
370  gf->add(track_id, sModuleLabel);
371  }
372  }
373 
374  std::string dummystr6 = "none ";
375  std::string dummystr7 = "none ";
376 
377  if (fSaveSignal) {
378  // .. create a channel number to trackid-wire signal info map
379  std::map<raw::ChannelID_t, std::map<int, WireSigInfo>> Ch2TrkWSInfoMap;
380 
381  // .. create a track ID to vector of channel numbers (in w/c this track deposited energy) map
382  std::map<int, std::vector<raw::ChannelID_t>> Trk2ChVecMap;
383 
384  // ... Loop over simChannels
385  for (auto const& channel : (*simChannelHandle)) {
386 
387  // .. get simChannel channel number
388  const raw::ChannelID_t ch1 = channel.Channel();
389  if (ch1 == raw::InvalidChannelID) continue;
390  if (geo::PlaneGeo::ViewName(fgeom->View(ch1)) != fPlaneToDump[0]) continue;
391 
392  bool selectThisChannel = false;
393 
394  // .. create a track ID to wire signal info map
395  std::map<int, WireSigInfo> Trk2WSInfoMap;
396 
397  // ... Loop over all ticks with ionization energy deposited
398  auto const& timeSlices = channel.TDCIDEMap();
399  for (auto const& timeSlice : timeSlices) {
400 
401  auto const& energyDeposits = timeSlice.second;
402  auto const tpctime = timeSlice.first;
403  unsigned int tdctick = static_cast<unsigned int>(clockData.TPCTDC2Tick(double(tpctime)));
404  if (tdctick < 0 || tdctick > (dataSize - 1)) continue;
405 
406  // ... Loop over all energy depositions in this tick
407  for (auto const& energyDeposit : energyDeposits) {
408 
409  if (!energyDeposit.trackID) continue;
410  int trkid = energyDeposit.trackID;
411  simb::MCParticle particle = PIS->TrackIdToMotherParticle(trkid);
412  //std::cout << energyDeposit.trackID << " " << trkid << " " << particle.TrackId() << std::endl;
413 
414  // .. ignore this energy deposition if incident particle energy below some threshold
415  if (particle.E() < fMinParticleEnergyGeV) continue;
416 
417  int eve_id = PIS->TrackIdToEveTrackId(trkid);
418  if (!eve_id) continue;
419  std::string genlab = gf->get_gen(eve_id);
420 
421  if (Trk2WSInfoMap.find(trkid) == Trk2WSInfoMap.end()) {
422  WireSigInfo wsinf;
423  wsinf.pdgcode = particle.PdgCode();
424  wsinf.genlab = genlab;
425  wsinf.procid = particle.Process();
426  wsinf.tdcmin = dataSize - 1;
427  wsinf.tdcmax = 0;
428  wsinf.edep = 0.;
429  wsinf.numel = 0;
430  Trk2WSInfoMap.insert(std::pair<int, WireSigInfo>(trkid, wsinf));
431  }
432  if (tdctick < Trk2WSInfoMap.at(trkid).tdcmin) Trk2WSInfoMap.at(trkid).tdcmin = tdctick;
433  if (tdctick > Trk2WSInfoMap.at(trkid).tdcmax) Trk2WSInfoMap.at(trkid).tdcmax = tdctick;
434  Trk2WSInfoMap.at(trkid).edep += energyDeposit.energy;
435  Trk2WSInfoMap.at(trkid).numel += energyDeposit.numElectrons;
436  }
437  }
438 
439  if (!Trk2WSInfoMap.empty()) {
440  for (std::pair<int, WireSigInfo> itmap : Trk2WSInfoMap) {
441  if (fSelectGenLabel != "ANY") {
442  if (itmap.second.genlab != fSelectGenLabel) continue;
443  }
444  if (fSelectProcID != "ANY") {
445  if (itmap.second.procid != fSelectProcID) continue;
446  }
447  if (fSelectPDGCode != 0) {
448  if (itmap.second.pdgcode != fSelectPDGCode) continue;
449  }
450  itmap.second.genlab.resize(6, ' ');
451  itmap.second.procid.resize(7, ' ');
452  if (itmap.second.numel >= fMinNumberOfElectrons &&
453  itmap.second.edep >= fMinEnergyDepositedMeV) {
454  if (fMaxNumberOfElectrons >= 0 && itmap.second.numel >= fMaxNumberOfElectrons) {
455  continue;
456  }
457  else {
458  int trkid = itmap.first;
459  if (Trk2ChVecMap.find(trkid) == Trk2ChVecMap.end()) {
460  std::vector<raw::ChannelID_t> chvec;
461  Trk2ChVecMap.insert(std::pair<int, std::vector<raw::ChannelID_t>>(trkid, chvec));
462  }
463  Trk2ChVecMap.at(trkid).push_back(ch1);
464  selectThisChannel = true;
465  }
466  }
467  } // loop over Trk2WSinfoMap
468  if (selectThisChannel) {
469  Ch2TrkWSInfoMap.insert(
470  std::pair<raw::ChannelID_t, std::map<int, WireSigInfo>>(ch1, Trk2WSInfoMap));
471  }
472  } // if Trk2WSInfoMap not empty
473 
474  } // loop over SimChannels
475 
476  std::set<raw::ChannelID_t> selected_channels;
477 
478  // ... Now write out the signal waveforms for each track
479  if (!Trk2ChVecMap.empty()) {
480  for (auto const& ittrk : Trk2ChVecMap) {
481  int i = fRandFlat.fireInt(ittrk.second.size()); // randomly select one channel with a signal from this particle
482  chnum = ittrk.second[i];
483 
484  if (not selected_channels.insert(chnum).second) {
485  continue;
486  }
487 
488  std::map<raw::ChannelID_t, std::map<int, WireSigInfo>>::iterator itchn;
489  itchn = Ch2TrkWSInfoMap.find(chnum);
490  if (itchn != Ch2TrkWSInfoMap.end()) {
491 
492  std::vector<short> adcvec(dataSize); // vector to hold zero-padded full waveform
493 
494  if (rawdigitlist.size()) {
495  auto search = rawdigitMap.find(chnum);
496  if (search == rawdigitMap.end()) continue;
497  art::Ptr<raw::RawDigit> rawdig = (*search).second;
498  std::vector<short> rawadc(dataSize); // vector to hold uncompressed adc values later
499  raw::Uncompress(rawdig->ADCs(), rawadc, rawdig->GetPedestal(), rawdig->Compression());
500  for (size_t j = 0; j < rawadc.size(); ++j) {
501  adcvec[j] = rawadc[j] - rawdig->GetPedestal();
502  }
503  }
504  else if (wirelist.size()) {
505  auto search = wireMap.find(chnum);
506  if (search == wireMap.end()) continue;
507  art::Ptr<recob::Wire> wire = (*search).second;
508  const auto& signal = wire->Signal();
509  for (size_t j = 0; j < adcvec.size(); ++j) {
510  adcvec[j] = signal[j];
511  }
512  }
513 
514  // .. write out info for each peak
515  // a full waveform has at least one peak; the output will save up to 5 peaks (if there is
516  // only 1 peak, will fill the other 4 with 0);
517  // for fShortWaveformSize: only use the first peak's start_tick
518 
519  if (fUseFullWaveform) {
520 
521  c2numpy_uint32(&npywriter, evt.id().event());
522  c2numpy_uint32(&npywriter, chnum);
524  c2numpy_uint16(&npywriter,itchn->second.size()); // size of Trk2WSInfoMap, or #peaks
525  unsigned int icnt = 0;
526  for (auto const& it : itchn->second) {
527  c2numpy_int32(&npywriter, it.first); // trackid
528  c2numpy_int32(&npywriter, it.second.pdgcode); // pdgcode
529  c2numpy_string(&npywriter, it.second.genlab.c_str()); // genlab
530  c2numpy_string(&npywriter, it.second.procid.c_str()); // procid
531  c2numpy_float32(&npywriter, it.second.edep); // edepo
532  c2numpy_uint32(&npywriter, it.second.numel); // numelec
533 
534  c2numpy_uint16(&npywriter, it.second.tdcmin); // stck1
535  c2numpy_uint16(&npywriter, it.second.tdcmax); // stc2
536 
537  icnt++;
538  if (icnt == 5) break;
539  }
540 
541  // .. pad with 0's if number of peaks less than 5
542  for (unsigned int i = icnt; i < 5; ++i) {
545  c2numpy_string(&npywriter, dummystr6.c_str());
546  c2numpy_string(&npywriter, dummystr7.c_str());
551  }
552 
553  for (unsigned int itck = 0; itck < dataSize; ++itck) {
554  c2numpy_int16(&npywriter, adcvec[itck]);
555  }
556 
557  } else {
558 
559  // .. first loop to find largest signal
560  double EDep = 0.;
561  unsigned int TDCMin, TDCMax;
562  bool foundmaxsig = false;
563  for (auto & it : itchn->second) {
564  if (it.second.edep > EDep && it.second.numel > 0){
565  EDep = it.second.edep;
566  TDCMin = it.second.tdcmin;
567  TDCMax = it.second.tdcmax;
568  foundmaxsig = true;
569  }
570  }
571  if (foundmaxsig) {
572  int sigtdc1, sigtdc2, sighwid, sigfwid, sigtdcm;
574  sigtdc1 = TDCMin - 14/2;
575  sigtdc2 = TDCMax + 3*14/2;
576  } else {
577  sigtdc1 = TDCMin - 32/2;
578  sigtdc2 = TDCMax + 32/2;
579  }
580  sigfwid=sigtdc2 - sigtdc1;
581  sighwid=sigfwid/2;
582  sigtdcm=sigtdc1+sighwid;
583 
584  int start_tick = -1;
585  int end_tick = -1;
586  // .. set window edges to contain the largest signal
587  if (sigfwid < (int)fShortWaveformSize) {
588  // --> case 1: signal range fits within window
589  int dt = fShortWaveformSize - sigfwid;
590  start_tick = sigtdc1 - dt * fRandFlat.fire(0,1);
591  }
592  else {
593  // --> case 2: signal range larger than window
594  int mrgn = fShortWaveformSize/20;
595  int dt = fShortWaveformSize - 2*mrgn;
596  start_tick = sigtdcm - mrgn - dt * fRandFlat.fire(0,1);
597  }
598  if (start_tick < 0) start_tick = 0;
599  end_tick = start_tick + fShortWaveformSize - 1;
600  if (end_tick > int (dataSize - 1)) {
601  end_tick = dataSize - 1;
602  start_tick = end_tick - fShortWaveformSize + 1;
603  }
604 
605  c2numpy_uint32(&npywriter, evt.id().event());
606  c2numpy_uint32(&npywriter, chnum);
608 
609  // .. second loop to select only signals that are within the window
610 
611  int it_trk[5],it_pdg[5],it_nel[5];
612  unsigned int stck_1[5],stck_2[5];
613  std::string it_glb[5], it_prc[5];
614  double it_edp[5];
615 
616  unsigned int icnt = 0;
617 
618  for (auto & it : itchn->second) {
619  if (( it.second.tdcmin >= (unsigned int)start_tick && it.second.tdcmin < (unsigned int)end_tick) ||
620  ( it.second.tdcmax > (unsigned int)start_tick && it.second.tdcmax <= (unsigned int)end_tick)) {
621 
622  it_trk[icnt] = it.first;
623  it_pdg[icnt] = it.second.pdgcode;
624  it_glb[icnt] = it.second.genlab;
625  it_prc[icnt] = it.second.procid;
626  it_edp[icnt] = it.second.edep;
627  it_nel[icnt] = it.second.numel;
628 
629  unsigned int mintdc = it.second.tdcmin;
630  unsigned int maxtdc = it.second.tdcmax;
631  if (mintdc < (unsigned int)start_tick)mintdc = start_tick;
632  if (maxtdc > (unsigned int)end_tick)maxtdc = end_tick;
633 
634  stck_1[icnt] = mintdc - start_tick;
635  stck_2[icnt] = maxtdc - start_tick;
636 
637  icnt++;
638  if (icnt == 5) break;
639  }
640  }
641 
642  c2numpy_uint16(&npywriter, icnt); // number of peaks
643 
644  for (unsigned int i = 0; i < icnt; ++i) {
645  c2numpy_int32(&npywriter, it_trk[i]); // trackid
646  c2numpy_int32(&npywriter, it_pdg[i]); // pdgcode
647  c2numpy_string(&npywriter, it_glb[i].c_str()); // genlab
648  c2numpy_string(&npywriter, it_prc[i].c_str()); // procid
649  c2numpy_float32(&npywriter,it_edp[i]); // edepo
650  c2numpy_uint32(&npywriter, it_nel[i]); // numelec
651  c2numpy_uint16(&npywriter, stck_1[i]); // stck1
652  c2numpy_uint16(&npywriter, stck_2[i]); // stck2
653  }
654 
655  // .. pad with 0's if number of peaks less than 5
656  for (unsigned int i = icnt; i < 5; ++i) {
659  c2numpy_string(&npywriter, dummystr6.c_str());
660  c2numpy_string(&npywriter, dummystr7.c_str());
665  }
666 
667  for (unsigned int itck = start_tick; itck < (start_tick + fShortWaveformSize); ++itck) {
668  c2numpy_int16(&npywriter, adcvec[itck]);
669  }
670 
671  } // foundmaxsig
672  }
673  }
674  }
675  }
676  }
677  else {
678  //save noise
679  int noisechancount = 0;
680  std::map<raw::ChannelID_t, bool> signalMap;
681  for (auto const& channel : (*simChannelHandle)) {
682  signalMap[channel.Channel()] = true;
683  }
684  // .. create a vector for shuffling the wire channel indices
685  auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
686  size_t nchan = (rawdigitlist.empty() ? wirelist.size() : rawdigitlist.size());
687  std::vector<size_t> randigitmap;
688  for (size_t i=0; i<nchan; ++i) randigitmap.push_back(i);
689  std::shuffle ( randigitmap.begin(), randigitmap.end(), std::mt19937(seed) );
690 
691  for (size_t rdIter = 0; rdIter < (rawdigitlist.empty() ? wirelist.size() : rawdigitlist.size());
692  ++rdIter) {
693 
694  if (noisechancount==fMaxNoiseChannelsPerEvent)break;
695 
696  std::vector<short> adcvec(dataSize); // vector to wire adc values
697  if (rawdigitlist.size()) {
698  size_t ranIdx=randigitmap[rdIter];
699  art::Ptr<raw::RawDigit> digitVec(digitVecHandle, ranIdx);
700  if (signalMap[digitVec->Channel()]) continue;
701 
702  std::vector<short> rawadc(dataSize); // vector to hold uncompressed adc values later
703  if (geo::PlaneGeo::ViewName(fgeom->View(digitVec->Channel())) != fPlaneToDump[0]) continue;
704  raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->GetPedestal(), digitVec->Compression());
705  for (size_t j = 0; j < rawadc.size(); ++j) {
706  adcvec[j] = rawadc[j] - digitVec->GetPedestal();
707  }
708  c2numpy_uint32(&npywriter, evt.id().event());
709  c2numpy_uint32(&npywriter, digitVec->Channel());
711  geo::PlaneGeo::ViewName(fgeom->View(digitVec->Channel())).c_str());
712  }
713  else if (wirelist.size()) {
714  size_t ranIdx=randigitmap[rdIter];
715  art::Ptr<recob::Wire> wire = wirelist[ranIdx];
716  if (signalMap[wire->Channel()]) continue;
717  if (channelStatus.IsBad(wire->Channel())) continue;
718  if (geo::PlaneGeo::ViewName(fgeom->View(wire->Channel())) != fPlaneToDump[0]) continue;
719  const auto& signal = wire->Signal();
720  for (size_t j = 0; j < adcvec.size(); ++j) {
721  adcvec[j] = signal[j];
722  }
723  c2numpy_uint32(&npywriter, evt.id().event());
724  c2numpy_uint32(&npywriter, wire->Channel());
726  }
727 
728  c2numpy_uint16(&npywriter, 0); //number of peaks
729  for (unsigned int i = 0; i < 5; ++i) {
732  c2numpy_string(&npywriter, dummystr6.c_str());
733  c2numpy_string(&npywriter, dummystr7.c_str());
738  }
739 
740  if (fUseFullWaveform) {
741  for (unsigned int itck = 0; itck < dataSize; ++itck) {
742  c2numpy_int16(&npywriter, adcvec[itck]);
743  }
744  }
745  else {
746  int start_tick = int((dataSize - fShortWaveformSize) * fRandFlat.fire(0, 1));
747  for (unsigned int itck = start_tick; itck < (start_tick + fShortWaveformSize); ++itck) {
748  c2numpy_int16(&npywriter, adcvec[itck]);
749  }
750  }
751 
752  ++noisechancount;
753  }
754  std::cout << "Total number of noise channels " << noisechancount << std::endl;
755  }
756 }
double E(const int i=0) const
Definition: MCParticle.h:233
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
float GetPedestal() const
Definition: RawDigit.h:214
std::string fDigitModuleLabel
module that made digits
int c2numpy_int32(c2numpy_writer *writer, int32_t data)
Definition: c2numpy.h:290
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
int PdgCode() const
Definition: MCParticle.h:212
static std::string ViewName(geo::View_t view)
Returns the name of the specified view.
Definition: PlaneGeo.cxx:763
unsigned int event
Definition: DataStructs.h:636
unsigned int run
Definition: DataStructs.h:637
int c2numpy_int16(c2numpy_writer *writer, int16_t data)
Definition: c2numpy.h:282
void add(const int &track_id, const std::string &gname)
std::string string
Definition: nybbler.cc:12
std::string fSimChannelLabel
module that made simchannels
uint8_t channel
Definition: CRTFragment.hh:201
std::string Process() const
Definition: MCParticle.h:215
int c2numpy_uint16(c2numpy_writer *writer, uint16_t data)
Definition: c2numpy.h:314
art::ServiceHandle< geo::Geometry > fgeom
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
Definition: Wire.h:231
int c2numpy_uint32(c2numpy_writer *writer, uint32_t data)
Definition: c2numpy.h:322
Definition: search.py:1
Class providing information about the quality of channels.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
std::vector< float > Signal() const
Return a zero-padded full length vector filled with RoI signal.
Definition: Wire.cxx:47
int c2numpy_string(c2numpy_writer *writer, const char *data)
Definition: c2numpy.h:394
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
simb::MCParticle TrackIdToMotherParticle(int const id) const
int c2numpy_float32(c2numpy_writer *writer, float data)
Definition: c2numpy.h:354
genFinder * gf
unsigned int subRun
Definition: DataStructs.h:638
art::ServiceHandle< cheat::ParticleInventoryService > PIS
TCEvent evt
Definition: DataStructs.cxx:7
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
std::string fSimulationProducerLabel
producer that tracked simulated part. through detector
std::string get_gen(int tid)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void nnet::RawWaveformDump::beginJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 211 of file RawWaveformDump_module.cc.

212 {
213  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
214 
220 
221  for (unsigned int i = 0; i < 5; i++) {
222  std::ostringstream name;
223 
224  name.str("");
225  name << "tid" << i;
226  c2numpy_addcolumn(&npywriter, name.str().c_str(), C2NUMPY_INT32);
227 
228  name.str("");
229  name << "pdg" << i;
230  c2numpy_addcolumn(&npywriter, name.str().c_str(), C2NUMPY_INT32);
231 
232  name.str("");
233  name << "gen" << i;
234  c2numpy_addcolumn(&npywriter, name.str().c_str(), (c2numpy_type)((int)C2NUMPY_STRING + 6));
235 
236  name.str("");
237  name << "pid" << i;
238  c2numpy_addcolumn(&npywriter, name.str().c_str(), (c2numpy_type)((int)C2NUMPY_STRING + 7));
239 
240  name.str("");
241  name << "edp" << i;
242  c2numpy_addcolumn(&npywriter, name.str().c_str(), C2NUMPY_FLOAT32);
243 
244  name.str("");
245  name << "nel" << i;
246  c2numpy_addcolumn(&npywriter, name.str().c_str(), C2NUMPY_UINT32);
247 
248  name.str("");
249  name << "sti" << i;
250  c2numpy_addcolumn(&npywriter, name.str().c_str(), C2NUMPY_UINT16);
251 
252  name.str("");
253  name << "stf" << i;
254  c2numpy_addcolumn(&npywriter, name.str().c_str(), C2NUMPY_UINT16);
255  }
256 
257  for (unsigned int i = 0;
258  i < (fUseFullWaveform ? detProp.ReadOutWindowSize() : fShortWaveformSize);
259  i++) {
260  std::ostringstream name;
261  name << "tck_" << i;
262  c2numpy_addcolumn(&npywriter, name.str().c_str(), C2NUMPY_INT16);
263  }
264 }
static QCString name
Definition: declinfo.cpp:673
int c2numpy_init(c2numpy_writer *writer, const std::string outputFilePrefix, int32_t numRowsPerFile)
Definition: c2numpy.h:142
int c2numpy_addcolumn(c2numpy_writer *writer, const std::string name, c2numpy_type type)
Definition: c2numpy.h:158
c2numpy_type
Definition: c2numpy.h:29
void nnet::RawWaveformDump::endJob ( )
overridevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 268 of file RawWaveformDump_module.cc.

269 {
271 }
int c2numpy_close(c2numpy_writer *writer)
Definition: c2numpy.h:407
RawWaveformDump& nnet::RawWaveformDump::operator= ( RawWaveformDump const &  )
delete
RawWaveformDump& nnet::RawWaveformDump::operator= ( RawWaveformDump &&  )
delete

Member Data Documentation

std::string nnet::RawWaveformDump::fCollectionPlaneLabel
private

Definition at line 114 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fDigitModuleLabel
private

module that made digits

Definition at line 99 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fDumpWaveformsFileName
private

Definition at line 95 of file RawWaveformDump_module.cc.

art::ServiceHandle<geo::Geometry> nnet::RawWaveformDump::fgeom
private

Definition at line 115 of file RawWaveformDump_module.cc.

int nnet::RawWaveformDump::fMaxNoiseChannelsPerEvent
private

Definition at line 113 of file RawWaveformDump_module.cc.

int nnet::RawWaveformDump::fMaxNumberOfElectrons
private

Definition at line 111 of file RawWaveformDump_module.cc.

double nnet::RawWaveformDump::fMinEnergyDepositedMeV
private

Definition at line 109 of file RawWaveformDump_module.cc.

int nnet::RawWaveformDump::fMinNumberOfElectrons
private

Definition at line 110 of file RawWaveformDump_module.cc.

double nnet::RawWaveformDump::fMinParticleEnergyGeV
private

Definition at line 108 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fPlaneToDump
private

Definition at line 107 of file RawWaveformDump_module.cc.

CLHEP::RandFlat nnet::RawWaveformDump::fRandFlat
private

Definition at line 118 of file RawWaveformDump_module.cc.

bool nnet::RawWaveformDump::fSaveSignal
private

Definition at line 112 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fSelectGenLabel
private

Definition at line 104 of file RawWaveformDump_module.cc.

int nnet::RawWaveformDump::fSelectPDGCode
private

Definition at line 106 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fSelectProcID
private

Definition at line 105 of file RawWaveformDump_module.cc.

unsigned int nnet::RawWaveformDump::fShortWaveformSize
private

Definition at line 102 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fSimChannelLabel
private

module that made simchannels

Definition at line 98 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fSimulationProducerLabel
private

producer that tracked simulated part. through detector

Definition at line 97 of file RawWaveformDump_module.cc.

bool nnet::RawWaveformDump::fUseFullWaveform
private

Definition at line 101 of file RawWaveformDump_module.cc.

std::string nnet::RawWaveformDump::fWireProducerLabel
private

Definition at line 100 of file RawWaveformDump_module.cc.

c2numpy_writer nnet::RawWaveformDump::npywriter
private

Definition at line 120 of file RawWaveformDump_module.cc.

art::ServiceHandle<cheat::ParticleInventoryService> nnet::RawWaveformDump::PIS
private

Definition at line 116 of file RawWaveformDump_module.cc.


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