190 std::unique_ptr<vector<sbnd::ToF::ToF>> ToF_vec(
new vector<sbnd::ToF::ToF>);
192 art::Handle< std::vector<sbn::crt::CRTTrack> > crtTrackListHandle;
193 std::vector< art::Ptr<sbn::crt::CRTTrack> > crtTrackList;
195 art::fill_ptr_vector(crtTrackList, crtTrackListHandle);
198 std::vector<std::vector<art::Ptr<CRTHit>>> trackhits;
202 for(
size_t itrk=0; itrk<crtTrackList.size(); itrk++){
203 std::vector<art::Ptr<CRTHit>> trkhits = findManyHits.at(itrk);
204 std::sort(trkhits.begin(),trkhits.end(),
205 [](
const art::Ptr<CRTHit>&
a,
const art::Ptr<CRTHit>& b)->
bool
207 return a->ts1_ns < b->ts1_ns;
209 trackhits.push_back(trkhits);
214 art::Handle< std::vector<sbn::crt::CRTHit> > crtHitListHandle;
215 std::vector< art::Ptr<sbn::crt::CRTHit> > crtHitList;
217 art::fill_ptr_vector(crtHitList, crtHitListHandle);
219 map<int, std::vector<art::Ptr<CRTHit>> > tof_crt_hits;
220 map<int, std::vector<art::Ptr<recob::OpHit>> > tof_op_hits;
221 map<int, std::vector<art::Ptr<recob::OpFlash>> > tof_op_flashes;
222 map<int, std::vector<int>> tof_op_tpc;
224 for(
auto const&
crt : crtHitList){
231 for(
auto const& trkhits: trackhits){
232 for(
size_t ihit=0; ihit<trkhits.size(); ihit++){
246 bool found_tof =
false;
247 int ophit_index = -1;
249 art::Handle< std::vector<recob::OpHit> > opHitListHandle;
250 std::vector< art::Ptr<recob::OpHit> > opHitList;
252 art::fill_ptr_vector(opHitList, opHitListHandle);
254 for(
auto const&
hit : opHitList){
259 pehit_max =
hit->PE();
260 ophit_index =
hit.key();
267 tof_crt_hits[index].push_back(
crt);
268 tof_op_hits[index].push_back(opHitList[ophit_index]);
273 new_tof.
tof =
crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-
fOpDelay);
280 ToF_vec->push_back(new_tof);
291 double ophit_minTOF = DBL_MAX;
292 bool found_tof =
false;
293 int ophit_index = -1;
295 art::Handle< std::vector<recob::OpHit> > opHitListHandle;
296 std::vector< art::Ptr<recob::OpHit> > opHitList;
298 art::fill_ptr_vector(opHitList, opHitListHandle);
300 for(
auto const&
hit : opHitList){
305 ophit_minTOF =
abs(
crt->ts1_ns-thit);
306 ophit_index =
hit.key();
313 tof_crt_hits[index].push_back(
crt);
314 tof_op_hits[index].push_back(opHitList[ophit_index]);
319 new_tof.
tof =
crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-
fOpDelay);
326 ToF_vec->push_back(new_tof);
337 double peflash_max=0;
338 bool found_tof =
false;
339 int opflash_index = -1;
342 std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
343 std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
345 for(
int i=0; i<2; i++) {
347 art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
350 for(
auto const& flashList : opFlashLists){
351 for(
size_t iflash=0; iflash<flashList.second.size(); iflash++){
352 auto const& flash = flashList.second[iflash];
354 double tflash = flash->Time()*1e3-
fOpDelay;
356 peflash_max=flash->TotalPE();
357 opflash_index = flash.key();
359 flash_tpc = flashList.first;
366 tof_crt_hits[index].push_back(
crt);
367 tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
368 tof_op_tpc[index].push_back(flash_tpc);
373 new_tof.
tof =
crt->ts1_ns - (opFlashLists[flash_tpc][opflash_index]->Time()*1e3-
fOpDelay);
376 new_tof.
pmt_time = opFlashLists[flash_tpc][opflash_index]->Time()*1e3-
fOpDelay;
381 ToF_vec->push_back(new_tof);
392 double flash_minTOF = DBL_MAX;
393 bool found_tof =
false;
394 int opflash_index = -1;
397 std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
398 std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
400 for(
int i=0; i<2; i++) {
402 art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
405 for(
auto const& flashList : opFlashLists){
406 for(
size_t iflash=0; iflash<flashList.second.size(); iflash++){
407 auto const& flash = flashList.second[iflash];
409 double tflash = flash->Time()*1e3-
fOpDelay;
411 flash_minTOF=
abs(
crt->ts1_ns-tflash);
412 opflash_index = flash.key();
414 flash_tpc = flashList.first;
421 tof_crt_hits[index].push_back(
crt);
422 tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
423 tof_op_tpc[index].push_back(flash_tpc);
428 new_tof.
tof =
crt->ts1_ns - (opFlashLists[flash_tpc][opflash_index]->Time()*1e3-
fOpDelay);
431 new_tof.
pmt_time = opFlashLists[flash_tpc][opflash_index]->Time()*1e3-
fOpDelay;
436 ToF_vec->push_back(new_tof);
447 double peflash_max=0;
448 bool found_tof =
false;
449 int opflash_index = -1;
451 int ophit_index = -1;
453 std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
454 std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
456 for(
int i=0; i<2; i++) {
458 art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
461 art::Handle< std::vector<recob::OpHit> > opHitListHandle;
462 std::vector< art::Ptr<recob::OpHit> > opHitList;
464 art::fill_ptr_vector(opHitList, opHitListHandle);
466 for(
auto const& flashList : opFlashLists){
467 art::FindManyP<recob::OpHit> findManyOpHits(flashHandles[flashList.first],
evt,
fFlashLabels[flashList.first]);
468 for(
size_t iflash=0; iflash<flashList.second.size(); iflash++){
469 auto const& flash = flashList.second[iflash];
471 double tflash = flash->AbsTime()*1e3-
fOpDelay;
473 peflash_max=flash->TotalPE();
474 opflash_index = flash.key();
476 flash_tpc = flashList.first;
477 vector<art::Ptr<recob::OpHit>> hits = findManyOpHits.at(flash.key());
478 double flashMinHitT = DBL_MAX;
479 for(
auto const&
hit : hits){
481 if(tPmt < flashMinHitT){
483 ophit_index =
hit.key();
492 tof_crt_hits[index].push_back(
crt);
493 tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
494 tof_op_tpc[index].push_back(flash_tpc);
495 tof_op_hits[index].push_back(opHitList[ophit_index]);
500 new_tof.
tof =
crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-
fOpDelay);
509 ToF_vec->push_back(new_tof);
520 double flash_minTOF = DBL_MAX;
521 bool found_tof =
false;
522 int opflash_index = -1;
524 int ophit_index = -1;
526 std::map<int, art::Handle< std::vector<recob::OpFlash> > > flashHandles;
527 std::map<int,std::vector< art::Ptr<recob::OpFlash> >> opFlashLists;
529 for(
int i=0; i<2; i++) {
531 art::fill_ptr_vector(opFlashLists[i], flashHandles[i]);
534 art::Handle< std::vector<recob::OpHit> > opHitListHandle;
535 std::vector< art::Ptr<recob::OpHit> > opHitList;
537 art::fill_ptr_vector(opHitList, opHitListHandle);
539 for(
auto const& flashList : opFlashLists){
540 art::FindManyP<recob::OpHit> findManyOpHits(flashHandles[flashList.first],
evt,
fFlashLabels[flashList.first]);
541 for(
size_t iflash=0; iflash<flashList.second.size(); iflash++){
542 auto const& flash = flashList.second[iflash];
544 double tflash = flash->Time()*1e3-
fOpDelay;
546 flash_minTOF=
abs(
crt->ts1_ns-tflash);
547 opflash_index = flash.key();
549 flash_tpc = flashList.first;
550 vector<art::Ptr<recob::OpHit>> hits = findManyOpHits.at(flash.key());
551 double flashMinHitT = DBL_MAX;
552 for(
auto const&
hit : hits){
554 if(tPmt < flashMinHitT){
556 ophit_index =
hit.key();
565 tof_crt_hits[index].push_back(
crt);
566 tof_op_flashes[index].push_back(opFlashLists[flash_tpc][opflash_index]);
567 tof_op_tpc[index].push_back(flash_tpc);
568 tof_op_hits[index].push_back(opHitList[ophit_index]);
573 new_tof.
tof =
crt->ts1_ns - (opHitList[ophit_index]->PeakTime()*1e3-
fOpDelay);
582 ToF_vec->push_back(new_tof);
595 if(!tof_crt_hits.empty()){
596 for (
auto& ele: tof_crt_hits){
597 double min_time = DBL_MAX;
600 for (
auto const&
hit: ele.second){
601 if(
hit->ts1_ns < min_time){
602 min_time =
hit->ts1_ns;
603 min_index = all_index;
609 new_tof.
tof = trackhits[ele.first].front()->ts1_ns - (tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay);
610 new_tof.
crt_time = trackhits[ele.first].front()->ts1_ns;
611 new_tof.
pmt_time = tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay;
612 new_tof.
crt_tagger = trackhits[ele.first].front()->tagger;
615 new_tof.
pmt_hit_id = tof_op_hits[ele.first][min_index].key();
616 ToF_vec->push_back(new_tof);
626 if(!tof_crt_hits.empty()){
627 for (
auto& ele: tof_crt_hits){
628 double min_time = DBL_MAX;
631 for (
auto const&
hit: ele.second){
632 if(
hit->ts1_ns < min_time){
633 min_time =
hit->ts1_ns;
634 min_index = all_index;
640 new_tof.
tof = trackhits[ele.first].front()->ts1_ns - (tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay);
641 new_tof.
crt_time = trackhits[ele.first].front()->ts1_ns;
642 new_tof.
pmt_time = tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay;
643 new_tof.
crt_tagger = trackhits[ele.first].front()->tagger;
646 new_tof.
pmt_hit_id = tof_op_hits[ele.first][min_index].key();
647 ToF_vec->push_back(new_tof);
657 if(!tof_crt_hits.empty()){
658 for (
auto& ele: tof_crt_hits){
659 double min_time = DBL_MAX;
662 for (
auto const&
hit: ele.second){
663 if(
hit->ts1_ns < min_time){
664 min_time =
hit->ts1_ns;
665 min_index = all_index;
671 new_tof.
tof = trackhits[ele.first].front()->ts1_ns - (tof_op_flashes[ele.first][min_index]->Time()*1e3-
fOpDelay);
672 new_tof.
crt_time = trackhits[ele.first].front()->ts1_ns;
673 new_tof.
pmt_time = tof_op_flashes[ele.first][min_index]->Time()*1e3-
fOpDelay;
674 new_tof.
crt_tagger = trackhits[ele.first].front()->tagger;
677 new_tof.
flash_tpc_id = tof_op_tpc[ele.first][min_index];
678 new_tof.
pmt_flash_id = tof_op_flashes[ele.first][min_index].key();
679 ToF_vec->push_back(new_tof);
689 if(!tof_crt_hits.empty()){
690 for (
auto& ele: tof_crt_hits){
691 double min_time = DBL_MAX;
694 for (
auto const&
hit: ele.second){
695 if(
hit->ts1_ns < min_time){
696 min_time =
hit->ts1_ns;
697 min_index = all_index;
703 new_tof.
tof = trackhits[ele.first].front()->ts1_ns - (tof_op_flashes[ele.first][min_index]->Time()*1e3-
fOpDelay);
704 new_tof.
crt_time = trackhits[ele.first].front()->ts1_ns;
705 new_tof.
pmt_time = tof_op_flashes[ele.first][min_index]->Time()*1e3-
fOpDelay;
706 new_tof.
crt_tagger = trackhits[ele.first].front()->tagger;
709 new_tof.
flash_tpc_id = tof_op_tpc[ele.first][min_index];
710 new_tof.
pmt_flash_id = tof_op_flashes[ele.first][min_index].key();
711 ToF_vec->push_back(new_tof);
721 if(!tof_crt_hits.empty()){
722 for (
auto& ele: tof_crt_hits){
723 double min_time = DBL_MAX;
726 for (
auto const&
hit: ele.second){
727 if(
hit->ts1_ns < min_time){
728 min_time =
hit->ts1_ns;
729 min_index = all_index;
735 new_tof.
tof = trackhits[ele.first].front()->ts1_ns - (tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay);
736 new_tof.
crt_time = trackhits[ele.first].front()->ts1_ns;
737 new_tof.
pmt_time = tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay;
738 new_tof.
crt_tagger = trackhits[ele.first].front()->tagger;
741 new_tof.
flash_tpc_id = tof_op_tpc[ele.first][min_index];
742 new_tof.
pmt_flash_id = tof_op_flashes[ele.first][min_index].key();
743 new_tof.
pmt_hit_id = tof_op_hits[ele.first][min_index].key();
744 ToF_vec->push_back(new_tof);
754 if(!tof_crt_hits.empty()){
755 for (
auto& ele: tof_crt_hits){
756 double min_time = DBL_MAX;
759 for (
auto const&
hit: ele.second){
760 if(
hit->ts1_ns < min_time){
761 min_time =
hit->ts1_ns;
762 min_index = all_index;
768 new_tof.
tof = trackhits[ele.first].front()->ts1_ns - (tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay);
769 new_tof.
crt_time = trackhits[ele.first].front()->ts1_ns;
770 new_tof.
pmt_time = tof_op_hits[ele.first][min_index]->PeakTime()*1e3-
fOpDelay;
771 new_tof.
crt_tagger = trackhits[ele.first].front()->tagger;
774 new_tof.
flash_tpc_id = tof_op_tpc[ele.first][min_index];
775 new_tof.
pmt_flash_id = tof_op_flashes[ele.first][min_index].key();
776 new_tof.
pmt_hit_id = tof_op_hits[ele.first][min_index].key();
777 ToF_vec->push_back(new_tof);
783 evt.put(std::move(ToF_vec));
bool HitCompare(const art::Ptr< CRTHit > &h1, const art::Ptr< CRTHit > &h2)
art::InputTag fOpHitModuleLabel
art::InputTag fCrtHitModuleLabel
map< int, art::InputTag > fFlashLabels
art::InputTag fCrtTrackModuleLabel