319 std::vector<art::Ptr<raw::RawDigit>> rawdigitlist;
327 std::vector<art::Ptr<raw::RawDigit>> rawdigitlist2;
333 if (rawdigitlist.empty() && rawdigitlist2.empty())
return;
340 unsigned int dataSize;
342 dataSize = digitVec0->Samples();
343 if (dataSize != detProp.ReadOutWindowSize()) {
344 throw cet::exception(
"RawWaveformClnSigDump") <<
"Bad dataSize: " << dataSize;
347 unsigned int dataSize2 = digitVec20->Samples();
348 if (dataSize != dataSize2) {
350 <<
"RawDigits from the 2 data products have different dataSizes: " << dataSize <<
"not eq to" << dataSize2;
354 std::map<raw::ChannelID_t, art::Ptr<raw::RawDigit>> rawdigitMap;
356 if (rawdigitlist.size()) {
357 for (
size_t rdIter = 0; rdIter < digitVecHandle->size(); ++rdIter) {
359 chnum = digitVec->Channel();
361 rawdigitMap[chnum] = digitVec;
364 std::map<raw::ChannelID_t, art::Ptr<raw::RawDigit>> rawdigitMap2;
366 if (rawdigitlist2.size()) {
367 for (
size_t rdIter = 0; rdIter < digitVecHandle2->size(); ++rdIter) {
369 chnum2 = digitVec2->Channel();
371 rawdigitMap2[chnum2] = digitVec2;
379 <<
" No simb::MCParticle objects in this event - " 380 <<
" Line " << __LINE__ <<
" in file " << __FILE__ <<
std::endl;
384 auto simChannelHandle =
387 if (!simChannelHandle->size())
return;
393 auto mcHandles =
evt.getMany<std::vector<simb::MCTruth>>();
394 std::vector<std::pair<int, std::string>> track_id_to_label;
396 for (
auto const& mcHandle : mcHandles) {
397 const std::string& sModuleLabel = mcHandle.provenance()->moduleLabel();
399 std::vector<art::Ptr<simb::MCParticle>> mcParts = findMCParts.at(0);
401 int track_id = ptr->TrackId();
402 gf->
add(track_id, sModuleLabel);
411 std::map<raw::ChannelID_t, std::map<int, WireSigInfo>> Ch2TrkWSInfoMap;
414 std::map<int, std::vector<raw::ChannelID_t>> Trk2ChVecMap;
417 for (
auto const&
channel : (*simChannelHandle)) {
424 bool selectThisChannel =
false;
427 std::map<int, WireSigInfo> Trk2WSInfoMap;
430 auto const& timeSlices =
channel.TDCIDEMap();
431 for (
auto const& timeSlice : timeSlices) {
433 auto const& energyDeposits = timeSlice.second;
434 auto const tpctime = timeSlice.first;
435 unsigned int tdctick =
static_cast<unsigned int>(clockData.TPCTDC2Tick(
double(tpctime)));
436 if (tdctick < 0 || tdctick > (dataSize - 1))
continue;
439 for (
auto const& energyDeposit : energyDeposits) {
441 if (!energyDeposit.trackID)
continue;
442 int trkid = energyDeposit.trackID;
450 if (!eve_id)
continue;
453 if (Trk2WSInfoMap.find(trkid) == Trk2WSInfoMap.end()) {
458 wsinf.
tdcmin = dataSize - 1;
464 Trk2WSInfoMap.insert(std::pair<int, WireSigInfo>(trkid, wsinf));
466 if (tdctick < Trk2WSInfoMap.at(trkid).tdcmin) Trk2WSInfoMap.at(trkid).tdcmin = tdctick;
467 if (tdctick > Trk2WSInfoMap.at(trkid).tdcmax) Trk2WSInfoMap.at(trkid).tdcmax = tdctick;
468 Trk2WSInfoMap.at(trkid).edep += energyDeposit.energy;
469 Trk2WSInfoMap.at(trkid).numel += energyDeposit.numElectrons;
473 auto search2 = rawdigitMap2.find(ch1);
474 if (search2 == rawdigitMap2.end())
continue;
476 std::vector<short> rawadc(dataSize);
478 std::vector<short> adcvec2(dataSize);
479 for (
size_t j = 0; j < rawadc.size(); ++j) {
483 if (!Trk2WSInfoMap.empty()) {
484 for (std::pair<int, WireSigInfo> itmap : Trk2WSInfoMap) {
488 for (
size_t i = itmap.second.tdcmin; i <= itmap.second.tdcmax; i++) {
489 if (
abs(adcvec2[i]) >
abs(pkadc)) {
494 Trk2WSInfoMap.at(itmap.first).tdcpeak = pktdc;
495 Trk2WSInfoMap.at(itmap.first).adcpeak = pkadc;
506 itmap.second.genlab.resize(6,
' ');
507 itmap.second.procid.resize(7,
' ');
514 int trkid = itmap.first;
515 if (Trk2ChVecMap.find(trkid) == Trk2ChVecMap.end()) {
516 std::vector<raw::ChannelID_t> chvec;
517 Trk2ChVecMap.insert(std::pair<
int, std::vector<raw::ChannelID_t>>(trkid, chvec));
519 Trk2ChVecMap.at(trkid).push_back(ch1);
520 selectThisChannel =
true;
524 if (selectThisChannel) {
525 Ch2TrkWSInfoMap.insert(
526 std::pair<
raw::ChannelID_t, std::map<int, WireSigInfo>>(ch1, Trk2WSInfoMap));
532 std::set<raw::ChannelID_t> selected_channels;
535 if (!Trk2ChVecMap.empty()) {
536 for (
auto const& ittrk : Trk2ChVecMap) {
537 int i =
fRandFlat.fireInt(ittrk.second.size());
538 chnum = ittrk.second[i];
540 if (not selected_channels.insert(chnum).second) {
544 std::map<raw::ChannelID_t, std::map<int, WireSigInfo>>
::iterator itchn;
545 itchn = Ch2TrkWSInfoMap.find(chnum);
546 if (itchn != Ch2TrkWSInfoMap.end()) {
548 std::vector<short> adcvec(dataSize);
550 auto search = rawdigitMap.find(chnum);
551 if (
search == rawdigitMap.end())
continue;
553 std::vector<short> rawadc(dataSize);
555 for (
size_t j = 0; j < rawadc.size(); ++j) {
559 std::vector<short> adcvec2(dataSize);
561 auto search2 = rawdigitMap2.find(chnum);
562 if (search2 == rawdigitMap2.end())
continue;
565 for (
size_t j = 0; j < rawadc.size(); ++j) {
580 unsigned int icnt = 0;
581 for (
auto & it : itchn->second) {
595 if (icnt == 5)
break;
599 for (
unsigned int i = icnt; i < 5; ++i) {
612 for (
unsigned int itck = 0; itck < dataSize; ++itck) {
615 for (
unsigned int itck = 0; itck < dataSize; ++itck) {
623 unsigned int TDCMin, TDCMax;
624 bool foundmaxsig =
false;
625 for (
auto & it : itchn->second) {
626 if (it.second.edep > EDep && it.second.adcpeak != 0 && it.second.numel > 0){
627 EDep = it.second.edep;
628 TDCMin = it.second.tdcmin;
629 TDCMax = it.second.tdcmax;
634 int sigtdc1, sigtdc2, sighwid, sigfwid, sigtdcm;
642 sigfwid=sigtdc2 - sigtdc1;
644 sigtdcm=sigtdc1+sighwid;
651 int dt = fShortWaveformSize - sigfwid;
652 start_tick = sigtdc1 - dt *
fRandFlat.fire(0,1);
656 int mrgn = fShortWaveformSize/20;
657 int dt = fShortWaveformSize - 2*mrgn;
658 start_tick = sigtdcm - mrgn - dt *
fRandFlat.fire(0,1);
660 if (start_tick < 0) start_tick = 0;
661 end_tick = start_tick + fShortWaveformSize - 1;
662 if (end_tick >
int (dataSize - 1)) {
663 end_tick = dataSize - 1;
664 start_tick = end_tick - fShortWaveformSize + 1;
673 int it_trk[5],it_pdg[5],it_nel[5],pk_tdc[5],pk_adc[5];
674 unsigned int stck_1[5],stck_2[5];
678 unsigned int icnt = 0;
680 for (
auto & it : itchn->second) {
682 if (( it.second.tdcmin >= (
unsigned int)start_tick && it.second.tdcmin < (
unsigned int)end_tick) ||
683 ( it.second.tdcmax > (
unsigned int)start_tick && it.second.tdcmax <= (
unsigned int)end_tick)) {
685 it_trk[icnt] = it.first;
686 it_pdg[icnt] = it.second.pdgcode;
687 it_glb[icnt] = it.second.genlab;
688 it_prc[icnt] = it.second.procid;
689 it_edp[icnt] = it.second.edep;
690 it_nel[icnt] = it.second.numel;
692 unsigned int mintdc = it.second.tdcmin;
693 unsigned int maxtdc = it.second.tdcmax;
694 if (mintdc < (
unsigned int)start_tick)mintdc = start_tick;
695 if (maxtdc > (
unsigned int)end_tick)maxtdc = end_tick;
697 stck_1[icnt] = mintdc - start_tick;
698 stck_2[icnt] = maxtdc - start_tick;
699 pk_tdc[icnt] = it.second.tdcpeak - start_tick;
700 pk_adc[icnt] = it.second.adcpeak;
703 if (icnt == 5)
break;
709 for (
unsigned int i = 0; i < icnt; ++i) {
723 for (
unsigned int i = icnt; i < 5; ++i) {
736 for (
unsigned int itck = start_tick; itck < (start_tick +
fShortWaveformSize); ++itck) {
739 for (
unsigned int itck = start_tick; itck < (start_tick +
fShortWaveformSize); ++itck) {
751 int noisechancount = 0;
752 std::map<raw::ChannelID_t, bool> signalMap;
753 for (
auto const&
channel : (*simChannelHandle)) {
754 signalMap[
channel.Channel()] =
true;
758 std::vector<size_t> randigitmap;
759 for (
size_t i=0; i<rawdigitlist.size(); ++i) randigitmap.push_back(i);
760 std::shuffle ( randigitmap.begin(), randigitmap.end(), std::mt19937(seed) );
762 for (
size_t rdIter = 0; rdIter < rawdigitlist.size(); ++rdIter) {
766 std::vector<float> adcvec(dataSize);
768 size_t ranIdx=randigitmap[rdIter];
770 if (signalMap[digitVec->Channel()])
continue;
772 std::vector<short> rawadc(dataSize);
774 raw::Uncompress(digitVec->ADCs(), rawadc, digitVec->GetPedestal(), digitVec->Compression());
775 for (
size_t j = 0; j < rawadc.size(); ++j) {
776 adcvec[j] = rawadc[j] - digitVec->GetPedestal();
784 for (
unsigned int i = 0; i < 5; ++i) {
798 for (
unsigned int itck = 0; itck < dataSize; ++itck) {
803 int start_tick =
int((dataSize - fShortWaveformSize) *
fRandFlat.fire(0, 1));
804 for (
unsigned int itck = start_tick; itck < (start_tick +
fShortWaveformSize); ++itck) {
811 std::cout <<
"Total number of noise channels " << noisechancount <<
std::endl;
double E(const int i=0) const
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)
int TrackIdToEveTrackId(int tid) const
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
int c2numpy_uint32(c2numpy_writer *writer, uint32_t data)
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
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)