284 std::vector<art::Ptr<raw::RawDigit>> rawdigitlist;
291 std::vector<art::Ptr<recob::Wire>> wirelist;
296 if (rawdigitlist.empty() && wirelist.empty())
return;
297 if (rawdigitlist.size() && wirelist.size())
return;
308 unsigned int dataSize;
309 if (rawdigitlist.size()) {
311 dataSize = digitVec0->Samples();
314 dataSize = (wirelist[0]->Signal()).
size();
316 if (dataSize != detProp.ReadOutWindowSize()) {
317 std::cout <<
"!!!!! Bad dataSize: " << dataSize <<
std::endl;
322 std::map<raw::ChannelID_t, art::Ptr<raw::RawDigit>> rawdigitMap;
324 if (rawdigitlist.size()) {
325 for (
size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter) {
327 chnum = digitVec->Channel();
329 rawdigitMap[chnum] = digitVec;
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) {
339 wireMap[chnum] = wire;
347 <<
" No simb::MCParticle objects in this event - " 348 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
352 auto simChannelHandle =
355 if (!simChannelHandle->size())
return;
361 auto mcHandles =
evt.getMany<std::vector<simb::MCTruth>>();
362 std::vector<std::pair<int, std::string>> track_id_to_label;
364 for (
auto const& mcHandle : mcHandles) {
365 const std::string& sModuleLabel = mcHandle.provenance()->moduleLabel();
367 std::vector<art::Ptr<simb::MCParticle>> mcParts = findMCParts.at(0);
369 int track_id = ptr->TrackId();
370 gf->
add(track_id, sModuleLabel);
379 std::map<raw::ChannelID_t, std::map<int, WireSigInfo>> Ch2TrkWSInfoMap;
382 std::map<int, std::vector<raw::ChannelID_t>> Trk2ChVecMap;
385 for (
auto const&
channel : (*simChannelHandle)) {
392 bool selectThisChannel =
false;
395 std::map<int, WireSigInfo> Trk2WSInfoMap;
398 auto const& timeSlices =
channel.TDCIDEMap();
399 for (
auto const& timeSlice : timeSlices) {
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;
407 for (
auto const& energyDeposit : energyDeposits) {
409 if (!energyDeposit.trackID)
continue;
410 int trkid = energyDeposit.trackID;
418 if (!eve_id)
continue;
421 if (Trk2WSInfoMap.find(trkid) == Trk2WSInfoMap.end()) {
426 wsinf.
tdcmin = dataSize - 1;
430 Trk2WSInfoMap.insert(std::pair<int, WireSigInfo>(trkid, wsinf));
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;
439 if (!Trk2WSInfoMap.empty()) {
440 for (std::pair<int, WireSigInfo> itmap : Trk2WSInfoMap) {
450 itmap.second.genlab.resize(6,
' ');
451 itmap.second.procid.resize(7,
' ');
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));
463 Trk2ChVecMap.at(trkid).push_back(ch1);
464 selectThisChannel =
true;
468 if (selectThisChannel) {
469 Ch2TrkWSInfoMap.insert(
470 std::pair<
raw::ChannelID_t, std::map<int, WireSigInfo>>(ch1, Trk2WSInfoMap));
476 std::set<raw::ChannelID_t> selected_channels;
479 if (!Trk2ChVecMap.empty()) {
480 for (
auto const& ittrk : Trk2ChVecMap) {
481 int i =
fRandFlat.fireInt(ittrk.second.size());
482 chnum = ittrk.second[i];
484 if (not selected_channels.insert(chnum).second) {
488 std::map<raw::ChannelID_t, std::map<int, WireSigInfo>>
::iterator itchn;
489 itchn = Ch2TrkWSInfoMap.find(chnum);
490 if (itchn != Ch2TrkWSInfoMap.end()) {
492 std::vector<short> adcvec(dataSize);
494 if (rawdigitlist.size()) {
495 auto search = rawdigitMap.find(chnum);
496 if (
search == rawdigitMap.end())
continue;
498 std::vector<short> rawadc(dataSize);
500 for (
size_t j = 0; j < rawadc.size(); ++j) {
504 else if (wirelist.size()) {
505 auto search = wireMap.find(chnum);
506 if (
search == wireMap.end())
continue;
508 const auto& signal = wire->
Signal();
509 for (
size_t j = 0; j < adcvec.size(); ++j) {
510 adcvec[j] = signal[j];
525 unsigned int icnt = 0;
526 for (
auto const& it : itchn->second) {
538 if (icnt == 5)
break;
542 for (
unsigned int i = icnt; i < 5; ++i) {
553 for (
unsigned int itck = 0; itck < dataSize; ++itck) {
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;
572 int sigtdc1, sigtdc2, sighwid, sigfwid, sigtdcm;
574 sigtdc1 = TDCMin - 14/2;
575 sigtdc2 = TDCMax + 3*14/2;
577 sigtdc1 = TDCMin - 32/2;
578 sigtdc2 = TDCMax + 32/2;
580 sigfwid=sigtdc2 - sigtdc1;
582 sigtdcm=sigtdc1+sighwid;
589 int dt = fShortWaveformSize - sigfwid;
590 start_tick = sigtdc1 - dt *
fRandFlat.fire(0,1);
594 int mrgn = fShortWaveformSize/20;
595 int dt = fShortWaveformSize - 2*mrgn;
596 start_tick = sigtdcm - mrgn - dt *
fRandFlat.fire(0,1);
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;
611 int it_trk[5],it_pdg[5],it_nel[5];
612 unsigned int stck_1[5],stck_2[5];
616 unsigned int icnt = 0;
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)) {
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;
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;
634 stck_1[icnt] = mintdc - start_tick;
635 stck_2[icnt] = maxtdc - start_tick;
638 if (icnt == 5)
break;
644 for (
unsigned int i = 0; i < icnt; ++i) {
656 for (
unsigned int i = icnt; i < 5; ++i) {
667 for (
unsigned int itck = start_tick; itck < (start_tick +
fShortWaveformSize); ++itck) {
679 int noisechancount = 0;
680 std::map<raw::ChannelID_t, bool> signalMap;
681 for (
auto const&
channel : (*simChannelHandle)) {
682 signalMap[
channel.Channel()] =
true;
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) );
691 for (
size_t rdIter = 0; rdIter < (rawdigitlist.empty() ? wirelist.size() : rawdigitlist.size());
696 std::vector<short> adcvec(dataSize);
697 if (rawdigitlist.size()) {
698 size_t ranIdx=randigitmap[rdIter];
700 if (signalMap[digitVec->Channel()])
continue;
702 std::vector<short> rawadc(dataSize);
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();
713 else if (wirelist.size()) {
714 size_t ranIdx=randigitmap[rdIter];
716 if (signalMap[wire->
Channel()])
continue;
719 const auto& signal = wire->
Signal();
720 for (
size_t j = 0; j < adcvec.size(); ++j) {
721 adcvec[j] = signal[j];
729 for (
unsigned int i = 0; i < 5; ++i) {
741 for (
unsigned int itck = 0; itck < dataSize; ++itck) {
746 int start_tick =
int((dataSize - fShortWaveformSize) *
fRandFlat.fire(0, 1));
747 for (
unsigned int itck = start_tick; itck < (start_tick +
fShortWaveformSize); ++itck) {
754 std::cout <<
"Total number of noise channels " << noisechancount <<
std::endl;
double E(const int i=0) const
virtual bool IsBad(raw::ChannelID_t channel) const =0
Returns whether the specified channel is bad in the current run.
float GetPedestal() const
int c2numpy_int32(c2numpy_writer *writer, int32_t data)
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
static std::string ViewName(geo::View_t view)
Returns the name of the specified view.
int c2numpy_int16(c2numpy_writer *writer, int16_t data)
void add(const int &track_id, const std::string &gname)
std::string Process() const
int c2numpy_uint16(c2numpy_writer *writer, uint16_t data)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
int TrackIdToEveTrackId(int tid) const
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
int c2numpy_uint32(c2numpy_writer *writer, uint32_t data)
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.
int c2numpy_string(c2numpy_writer *writer, const char *data)
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
simb::MCParticle TrackIdToMotherParticle(int const id) const
int c2numpy_float32(c2numpy_writer *writer, float data)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
std::string get_gen(int tid)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)