270 auto beamHandle =
evt.getValidHandle<std::vector<beam::ProtoDUNEBeamEvent>>(
"beamevent");
271 std::vector<art::Ptr<beam::ProtoDUNEBeamEvent>> beamVec;
272 if( beamHandle.isValid()){
283 std::cout <<
"Failed quality check!\n" <<
std::endl;
292 std::cout <<
"Number of reconstructed momenta: " << momenta.size() <<
std::endl;
294 if( momenta.size() > 0 )
295 std::cout <<
"Measured Momentum: " << momenta.at(0) <<
std::endl;
299 const std::vector< double > & the_tofs = beamEvent.
GetTOFs();
300 const std::vector< int > & the_chans = beamEvent.
GetTOFChans();
303 std::cout <<
"Number of measured TOF: " << the_tofs.size() <<
std::endl;
307 std::cout <<
"All (TOF, Channels): " <<
std::endl;
308 for(
size_t i = 0; i < the_tofs.size(); ++i ){
309 std::cout <<
"\t(" << the_tofs[i] <<
", " << the_chans[i] <<
")" <<
std::endl;
315 std::cout <<
"Cerenkov status, pressure:" <<
std::endl;
345 std::cout<<
"Selected nominal beam momentum is: "<<nom_beam_mon<<
" GeV/c"<<
std::endl;
355 std::cout <<
"muon " << candidates.muon <<
std::endl;
356 std::cout <<
"pion " << candidates.pion <<
std::endl;
357 std::cout <<
"kaon " << candidates.kaon <<
std::endl;
358 std::cout <<
"proton " << candidates.proton <<
std::endl;
378 std::vector<art::Ptr<recob::Track> > tracklist;
383 art::FindManyP<recob::PFParticle> pfp_trk_assn(trackListHandle,
evt,
"pandoraTrack");
385 std::vector<art::Ptr<recob::Hit>> hitlist;
406 evttime = ts2.AsDouble();
410 if(!
evt.isRealData()){
411 for(
int ik=0; ik<6; ik++)
415 for(
int ik=0; ik<6; ik++)
423 if (beamVec.size()&&candidates.pion==1) {
429 for(
size_t ii = 0; ii < the_tofs.size(); ++ii ){
430 tofs.push_back(the_tofs[ii]);
431 ch_tofs.push_back(the_chans[ii]);
439 for (
size_t i = 0; i<
tracks.size(); ++i){
449 std::cout<<
"beamDirx/beamDiry/beamDirz:"<<
tracks[i].StartDirection().X()<<
"/"<<
tracks[i].StartDirection().Y()<<
"/"<<
tracks[i].StartDirection().Z()<<
std::endl;
457 std::cout<<
"beam mom size:"<<momenta.size()<<
std::endl;
458 for (
size_t i = 0; i<momenta.size(); ++i){
460 std::cout<<
"beam mom["<<i<<
"]:"<<momenta[i]<<
" [GeV]"<<
std::endl;
481 std::cout<<
"\n*******************************************************"<<
std::endl;
482 std::cout<<
"Moving on to the PFParticle section..."<<
std::endl;
491 auto recoParticles =
evt.getValidHandle<std::vector<recob::PFParticle>>(
fPFParticleTag);
506 if(beamParticles.size() == 0){
507 std::cerr <<
"We found no beam particles for this event... moving on" <<
std::endl;
516 std::cout<<
"we have "<<beamParticles.size()<<
" beam particle(s)"<<
std::endl;
527 auto recoTracks =
evt.getValidHandle<std::vector<recob::Track>>(
fTrackerTag);
528 art::FindManyP<recob::Hit> findHitsFromTracks(recoTracks,
evt,
fTrackerTag);
537 if(thisTrack != 0x0){
539 beamstx=thisTrack->
Start().X();
540 beamsty=thisTrack->
Start().Y();
541 beamstz=thisTrack->
Start().Z();
542 beamendx=thisTrack->
End().X();
543 beamendy=thisTrack->
End().Y();
544 beamendz=thisTrack->
End().Z();
545 std::cout<<
"beamstx "<<beamstx<<
std::endl;
547 std::vector<double> secondarystartx1;
548 std::vector<double> secondarystarty1;
549 std::vector<double> secondarystartz1;
550 std::vector<double> secondaryendx1;
551 std::vector<double> secondaryendy1;
552 std::vector<double> secondaryendz1;
553 std::vector<double> dQmichel1;
554 std::vector<double> dQtrackbegin1;
555 std::vector<double> dQtrackend1;
556 std::vector<double> tracklengthsecondary1;
557 std::vector<double> primsectheta1;
558 std::vector<int> endhitssecondary1,trackID1;
559 std::vector<double> trks1;
560 std::vector<double> ems1;
561 std::vector<double> michels1;
562 std::vector<double> nones1;
563 size_t NTracks = tracklist.size();
564 for(
size_t i=0;i<NTracks;i++){
570 double startx=
pos.X();
571 double starty=
pos.Y();
572 double startz=
pos.Z();
576 if(track.
Length()<5)
continue;
578 if(TMath::Max(endy,starty)>500 || TMath::Min(endy, starty)<200 || TMath::Max(startx, endx)>0||TMath::Min(startx,endx)<-200||TMath::Max(startz,endz)<30)
continue;
580 std::vector<int> wirenos;
581 std::vector<float> peakts,dqbuff1;
582 std::vector<float> dQstart,dQend;
583 std::vector<double> micheldq;
584 wirenos.clear();peakts.clear();dqbuff1.clear();
590 std::vector<std::tuple<double,double,double,double,int,double>> buff_ZYXTWQ;
592 double thetavalue=
theta12(beamstx,beamendx,beamsty,beamendy,beamstz,beamendz,startx,endx,starty,endy,startz,endz);
594 auto vhit=fmthm.at(i);
595 auto vmeta=fmthm.data(i);
596 for (
size_t ii = 0; ii<vhit.size(); ++ii){
597 bool fBadhit =
false;
603 if (vmeta[ii]->
Index()>=tracklist[i]->NumberTrajectoryPoints()){
604 throw cet::exception(
"Calorimetry_module.cc") <<
"Requested track trajectory index "<<vmeta[ii]->Index()<<
" exceeds the total number of trajectory points "<<tracklist[i]->NumberTrajectoryPoints()<<
" for track index "<<i<<
". Something is wrong with the track reconstruction. Please contact tjyang@fnal.gov!!";
606 if (!tracklist[i]->HasValidPoint(vmeta[ii]->
Index())){
612 auto loc = tracklist[i]->LocationAtPoint(vmeta[ii]->
Index());
613 if (fBadhit)
continue;
614 if (
loc.Z()<-100)
continue;
615 if(vhit[ii]->
WireID().Plane==2){
616 buff_ZYXTWQ.push_back(std::make_tuple(
loc.Z(),
loc.Y(),
loc.X(),vhit[ii]->PeakTime(),vhit[ii]->WireID().Wire,vhit[ii]->Integral()));
618 peakts.push_back(vhit[ii]->PeakTime());
622 wireno=vhit[ii]->WireID().Wire;
623 peaktime=vhit[ii]->PeakTime();
624 tpcno=vhit[ii]->WireID().TPC;
639 double trk_score=0.0;
641 double michel_score=0;
643 for(
size_t hitl=0;hitl<hitlist.size();hitl++){
644 std::array<float,4> cnn_out=hitResults.getOutput(hitlist[hitl]);
645 auto &
tracks = thass.at(hitlist[hitl].
key());
647 if (!
tracks.empty() &&
tracks[0].key()!=ptrack.key() && tracklist[
tracks[0].key()]->Length()>25)
continue;
649 float peakth1=hitlist[hitl]->PeakTime();
650 int wireh1=hitlist[hitl]->WireID().Wire;
651 for(
size_t m=0;
m<wirenos.size();
m++){
652 if(wireh1==wirenos[
m] && peakth1==peakts[
m]){
658 int planeid=hitlist[hitl]->WireID().Plane;
659 int tpcid=hitlist[hitl]->WireID().TPC;
660 if(
abs(wireh1-wireno)<20 &&
abs(peakth1-peaktime)<150 && planeid==2 && tpcid==tpcno){
662 micheldq.push_back(hitlist[hitl]->Integral());
663 micheldq.push_back(hitlist[hitl]->Integral());
664 trk_score+=cnn_out[hitResults.getIndex(
"track")];
665 em_score+=cnn_out[hitResults.getIndex(
"em")];
666 michel_score+=cnn_out[hitResults.getIndex(
"michel")];
667 none_score+=cnn_out[hitResults.getIndex(
"none")];
670 if(buff_ZYXTWQ.size()<10)
continue;
671 sort(buff_ZYXTWQ.begin(),buff_ZYXTWQ.end());
672 dQstart.clear(); dQend.clear();
673 int qi11=buff_ZYXTWQ.size();
674 for(
int qi=5;
qi<TMath::Min(15,qi11);
qi++){
675 dQstart.push_back(std::get<5>(buff_ZYXTWQ[
qi]));
678 for(
int qi=qi11-5;
qi<qi11;
qi++){
679 dQend.push_back(std::get<5>(buff_ZYXTWQ[
qi]));
681 secondarystartx1.push_back(startx);
682 secondarystarty1.push_back(starty);
683 secondarystartz1.push_back(startz);
684 secondaryendx1.push_back(endx);
685 secondaryendy1.push_back(endy);
686 secondaryendz1.push_back(endz);
687 endhitssecondary1.push_back(counter1);
688 tracklengthsecondary1.push_back(track.
Length());
689 trackID1.push_back(track.
ID());
690 dQmichel1.push_back(TMath::Median(micheldq.size(),&micheldq[0]));
691 dQtrackbegin1.push_back(TMath::Median(dQstart.size(),&dQstart[0]));
692 dQtrackend1.push_back(TMath::Median(dQend.size(),&dQend[0]));
693 primsectheta1.push_back(thetavalue);
694 trks1.push_back(trk_score);
695 ems1.push_back(em_score);
696 michels1.push_back(michel_score);
697 nones1.push_back(none_score);
717 endhitssecondary1.clear();
718 secondarystartx1.clear();
719 secondaryendx1.clear();
720 secondarystarty1.clear();
721 secondaryendy1.clear();
722 secondarystartz1.clear();
723 secondaryendz1.clear();
725 primsectheta1.clear();
726 dQtrackbegin1.clear();
728 tracklengthsecondary1.clear();
737 if(thisTrack != 0x0) {
739 std::cout <<
"Beam particle is track-like" <<
std::endl;
750 std::vector<double> tmp_primtrk_dqdx;
751 std::vector<double> tmp_primtrk_resrange;
752 std::vector<double> tmp_primtrk_dedx;
753 std::vector<double> tmp_primtrk_hitx;
754 std::vector<double> tmp_primtrk_hity;
755 std::vector<double> tmp_primtrk_hitz;
756 std::vector<double> tmp_primtrk_pitch;
757 for (
auto &
calo : calovector){
758 if (
calo.PlaneID().Plane == 2){
760 for (
size_t ihit = 0; ihit <
calo.dQdx().size(); ++ihit){
761 tmp_primtrk_dqdx.push_back(
calo.dQdx()[ihit]);
762 tmp_primtrk_resrange.push_back(
calo.ResidualRange()[ihit]);
763 tmp_primtrk_dedx.push_back(
calo.dEdx()[ihit]);
764 tmp_primtrk_pitch.push_back(
calo.TrkPitchVec()[ihit]);
766 const auto &primtrk_pos=(
calo.XYZ())[ihit];
767 tmp_primtrk_hitx.push_back(primtrk_pos.X());
768 tmp_primtrk_hity.push_back(primtrk_pos.Y());
769 tmp_primtrk_hitz.push_back(primtrk_pos.Z());
780 if (tmp_primtrk_hitz.size()!=0) {
790 tmp_primtrk_dqdx.clear();
791 tmp_primtrk_resrange.clear();
792 tmp_primtrk_dedx.clear();
793 tmp_primtrk_hitx.clear();
794 tmp_primtrk_hity.clear();
795 tmp_primtrk_hitz.clear();
796 tmp_primtrk_pitch.clear();
807 std::cout<<
"vtx_X:"<<vtx.X()<<
" ; vtx_Y:"<<vtx.Y()<<
" ; vtx_Z:"<<vtx.Z()<<
std::endl;
812 std::cout<<
"vtx_end_X:"<<vtx_end.X()<<
" ; vtx_end_Y:"<<vtx_end.Y()<<
" ; vtx_end_Z:"<<vtx_end.Z()<<
std::endl;
814 if (vtx.Z()==vtx_end.Z()) {
815 std::cout<<
"WARNING!! StartZ and EndZ are the same!!"<<
std::endl;
821 if(thisShower != 0x0) {
822 std::cout <<
"Beam particle is shower-like" <<
std::endl;
830 pdg_code.push_back(particle->PdgCode());
831 n_daughter.push_back(particle->NumDaughters());
832 isPrimary.push_back(particle->IsPrimary());
833 pfp_self.push_back(particle->Self());
836 std::cout<<
"pdg code:"<<particle->PdgCode()<<
std::endl;
837 std::cout<<
"IsPrimary:"<<particle->IsPrimary()<<
std::endl;
838 std::cout<<
"NumDaughters:"<<particle->NumDaughters()<<
std::endl;
839 std::cout<<
"Self:"<<particle->Self()<<
std::endl;
840 std::cout<<
"Parent:"<<particle->Parent()<<
std::endl;
842 if ((particle->NumDaughters())>0) {
843 for (
int ii=0; ii<(particle->NumDaughters());++ii) {
844 std::cout<<
"Daughter["<<ii<<
"]:"<<particle->Daughter(ii)<<
std::endl;
864 std::cout<<
"trkDirx/trkDiry/trkDirz:"<<trackdir.X()<<
"/"<<trackdir.Y()<<
"/"<<trackdir.Z()<<
std::endl;
872 std::cout<<
"trk ID: "<<thisTrack->
ID()<<
""<<
std::endl;
892 for(
const int daughterID : particle->Daughters()){
895 std::cout <<
"Daughter " << daughterID <<
" has " << daughterParticle->
NumDaughters() <<
" daughters" <<
std::endl;
902 std::cout <<
"Beam particle has " << trackDaughters.size() <<
" track-like daughters and " << showerDaughters.size() <<
" shower-like daughters." <<
std::endl;
904 std::cout<<
"# total Tracks:"<<nTrack<<
std::endl;
905 std::cout<<
"# total Showers:"<<nShower<<
std::endl;
910 std::cout<<
"*******************************************************"<<
std::endl;
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
std::vector< std::vector< double > > Msecondaryendz
std::vector< int > ch_tofs
PossibleParticleCands GetPIDCandidates(beam::ProtoDUNEBeamEvent const &beamevt, double nominal_momentum)
constexpr std::uint32_t timeLow() const
const int & GetTimingTrigger() const
std::vector< double > primtrk_starty
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
const std::vector< double > & GetTOFs() const
std::vector< std::vector< double > > MdQtrackbegin
std::vector< std::vector< double > > Msecondarystarty
std::vector< std::vector< double > > Mprimsectheta
std::vector< double > beamDirz
const recob::Shower * GetPFParticleShower(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Get the shower associated to this particle. Returns a null pointer if not found.
std::vector< double > primtrk_endx
std::vector< double > primtrk_endy
const double & GetCKov0Pressure() const
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
std::vector< std::vector< double > > Msecondarystartz
short low_pressure_status
std::vector< int > n_beamparticle
std::vector< anab::Calorimetry > GetRecoTrackCalorimetry(const recob::Track &track, art::Event const &evt, const std::string trackModule, const std::string caloModule) const
Get the Calorimetry(s) from a given reco track.
std::vector< double > primtrk_Diry
constexpr std::uint32_t timeHigh() const
const short & GetCKov1Status() const
const TVector3 GetPFParticleVertex(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Function to find the interaction vertex of a primary PFParticle.
std::vector< double > primtrk_startz
const art::InputTag fTrackModuleLabel
std::vector< double > beamPosy
std::vector< double > beamDiry
double theta12(double x1, double x2, double y1, double y2, double z1, double z2, double x1p, double x2p, double y1p, double y2p, double z1p, double z2p)
std::vector< double > primtrk_Dirz
std::vector< std::vector< double > > Mtracklengthsecondary
std::vector< double > primtrkID
std::vector< std::vector< double > > Msecondaryendx
bool IsBeamlike(const recob::Track &, const art::Event &, std::string)
std::string fHitsModuleLabel
short high_pressure_status
protoana::ProtoDUNEBeamlineUtils fBeamlineUtils
std::vector< double > primtrk_endz
std::vector< std::vector< double > > MdQtrackend
std::vector< std::vector< double > > emscore
std::vector< std::vector< double > > primtrk_resrange
std::string fPFParticleTag
Vector_t StartDirection() const
Access to track direction at different points.
std::vector< std::vector< double > > primtrk_dedx
double Length(size_t p=0) const
Access to various track properties.
std::vector< std::vector< int > > MtrackID
std::vector< double > primtrk_startx
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
Point_t const & Start() const
Access to track position at different points.
std::vector< std::vector< double > > primtrk_dqdx
std::vector< std::vector< double > > primtrk_hitz
const std::vector< double > & GetRecoBeamMomenta() const
const double & GetTOF() const
std::vector< std::vector< double > > Msecondarystartx
std::vector< std::vector< double > > trackscore
T get(std::string const &key) const
const recob::Track * GetPFParticleTrack(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the track associated to this particle. Returns a null pointer if not found.
Point_t const & Vertex() const
fhicl::ParameterSet fBeamPars
std::vector< double > primtrklen
std::vector< double > primtrk_Dirx
std::vector< int > pdg_code
std::vector< std::vector< double > > primtrk_hitx
const std::vector< const recob::PFParticle * > GetPFParticlesFromBeamSlice(art::Event const &evt, const std::string particleLabel) const
Return the pointers for the PFParticles in the beam slice. Returns an empty vector is no beam slice w...
bool IsGoodBeamlineTrigger(art::Event const &evt) const
static int max(int a, int b)
std::vector< double > primtrk_range
std::vector< double > beamDirx
Hierarchical representation of particle flow.
const std::vector< int > & GetTOFChans() const
int GetNActiveFembsForAPA(art::Event const &evt, int apa) const
Get number of active fembs in an APA.
const std::vector< const recob::Shower * > GetPFParticleDaughterShowers(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string showerLabel) const
Get the daughter showers from the PFParticle.
std::vector< std::vector< double > > primtrk_pitch
std::vector< std::vector< double > > Msecondaryendy
std::vector< std::vector< double > > nonescore
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
protoana::ProtoDUNEBeamCuts beam_cuts
std::vector< int > n_daughter
const TVector3 GetPFParticleSecondaryVertex(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Function to find the secondary interaction vertex of a primary PFParticle.
Point_t const & End() const
const std::vector< recob::Track > & GetBeamTracks() const
const short & GetCKov0Status() const
double cosine_beam_primtrk
std::vector< int > pfp_self
std::vector< double > tofs
std::vector< double > beamMomentum
std::vector< double > beamPosz
std::vector< double > beamPosx
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
const bool & CheckIsMatched() const
std::vector< std::vector< int > > Mendhitssecondary
protoana::ProtoDUNEDataUtils dataUtil
std::vector< int > isPrimary
const int & GetTOFChan() const
const std::vector< const recob::Track * > GetPFParticleDaughterTracks(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel, const std::string trackLabel) const
Get the daughter tracks from the PFParticle.
std::vector< std::vector< double > > primtrk_hity
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
std::string fCalorimetryTag
std::vector< std::vector< double > > michelscore
std::vector< std::vector< double > > MdQmichel
std::vector< int > primtrk_trktag
std::vector< int > pfp_daughter
const double & GetCKov1Pressure() const