20 #include "art_root_io/TFileService.h" 22 #include "canvas/Persistency/Common/FindManyP.h" 42 #include "dune/DuneObj/ProtoDUNEBeamEvent.h" 50 #include "dune/Protodune/singlephase/DataUtils/ProtoDUNEDataUtils.h" 58 #include "TTimeStamp.h" 71 #include "TPaveStats.h" 99 virtual void endJob()
override;
303 fPandoraBeam = tfs->make<TTree>(
"PandoraBeam",
"Beam events reconstructed with Pandora");
465 bool beamTriggerEvent =
false;
473 if(geantGoodParticle != 0x0){
474 std::cout<<
"geant good particle loop "<<
std::endl;
475 std::cout <<
"Found GEANT particle corresponding to the good particle with pdg = " << geantGoodParticle->
PdgCode()
476 <<
" , track id = " << geantGoodParticle->
TrackId()
477 <<
" , Vx/Vy/Vz = " << geantGoodParticle->
Vx() <<
"/"<< geantGoodParticle->
Vy() <<
"/" << geantGoodParticle->
Vz()
481 std::vector<double> tmp_primtrk_truth_Z;
482 std::vector<double> tmp_primtrk_truth_Eng;
483 std::vector<double> tmp_primtrk_truth_trkide;
485 beamTriggerEvent =
true;
499 beamid = geantGoodParticle->
TrackId();
542 if (thisTrajectoryProcessMap1.size()){
543 for(
auto const& couple: thisTrajectoryProcessMap1){
557 std::cout<<
"interaction map size "<<thisTrajectoryProcessMap1.size()<<
std::endl;
558 if (thisTrajectoryProcessMap1.size()){
559 for(
auto const& couple1: thisTrajectoryProcessMap1){
561 if ((truetraj.
KeyToProcess(couple1.second)).find(
"CoulombScat")!= std::string::npos)
continue;
563 auto interactionPos4D = (truetraj.
at(couple1.first)).first ;
564 if (interactionPos4D.Z() <
minZ || interactionPos4D.Z() >
maxZ )
continue;
565 else if (interactionPos4D.X() <
minX || interactionPos4D.X() >
maxX )
continue;
566 else if (interactionPos4D.Y() <
minY || interactionPos4D.Y() >
maxY )
continue;
571 std::cout<<
"number of interactions "<<thisTrajectoryProcessMap1.size()<<
std::endl;
572 std::cout<<
"int X, Y, Z and process "<<((truetraj.
at(couple1.first)).first).X()<<
" "<<((truetraj.
at(couple1.first)).first).Y()<<
" "<<((truetraj.
at(couple1.first)).first).Z()<<
" "<<truetraj.
KeyToProcess(couple1.second)<<
std::endl;
574 double interactionAngle = 999999.;
577 auto prevInteractionPos4D = (truetraj.
at(couple1.first-1)).first ;
578 auto prevInteractionPos3D = prevInteractionPos4D.Vect() ;
579 auto interactionPos3D = interactionPos4D.Vect() ;
580 auto distanceBtwPoint = interactionPos3D - prevInteractionPos3D;
582 if (truetraj.
size() > couple1.first + 1) {
584 auto nextInteractionPos4D = (truetraj.
at(couple1.first+1)).first ;
585 auto nextInteractionPos3D = nextInteractionPos4D.Vect() ;
586 auto distanceBtwPointNext = nextInteractionPos3D - interactionPos3D;
587 interactionAngles.push_back(TMath::ACos(distanceBtwPointNext.Dot(distanceBtwPoint)/(distanceBtwPointNext.Mag()*distanceBtwPoint.Mag() ) ));
596 std::map<double, sim::IDE> orderedSimIDE;
597 for (
auto& ide : simIDE_prim) orderedSimIDE[ide->z]= *ide;
598 auto inTPCPoint = truetraj.
begin();
599 auto Momentum0 = inTPCPoint->second;
600 auto old_iter = orderedSimIDE.begin();
602 double xi=0.0;
double yi=0.0;
double zi=0.0;
606 for (
auto iter= orderedSimIDE.begin(); iter!= orderedSimIDE.end(); iter++,old_iter++){
607 auto currentIde = iter->second;
608 if(currentIde.z<
minZ)
continue;
609 else if (currentIde.x <
minX || currentIde.x >
maxX )
continue;
610 else if (currentIde.y <
minY || currentIde.y >
maxY )
continue;
611 tmp_primtrk_truth_Z.push_back(currentIde.z);
612 tmp_primtrk_truth_Eng.push_back(currentIde.energy);
613 tmp_primtrk_truth_trkide.push_back(currentIde.trackID);
619 if(currentIde.trackID>=0){
623 xi=currentIde.x;yi=currentIde.y;zi=currentIde.z;
632 tmp_primtrk_truth_Z.clear();
633 tmp_primtrk_truth_Eng.clear();
634 tmp_primtrk_truth_trkide.clear();
675 std::vector<art::Ptr<recob::Track> > tracklist;
676 auto trackListHandle = evt.
getHandle< std::vector<recob::Track> >(
"pandoraTrack");
679 std::vector<art::Ptr<recob::PFParticle> > pfplist;
680 auto PFPListHandle = evt.
getHandle< std::vector<recob::PFParticle> >(
"pandora");
684 std::vector<art::Ptr<recob::Cluster>> clusterlist;
685 auto clusterListHandle = evt.
getHandle< std::vector<recob::Cluster> >(
"pandora");
686 if(clusterListHandle)
689 art::FindManyP<recob::Cluster> fmcp(PFPListHandle,evt,
"pandora");
690 art::FindManyP<recob::Track> pftrack(PFPListHandle,evt,
"pandoraTrack");
692 std::cout<<
"number of pfp_particles "<<pfplist.size()<<
std::endl;
693 std::cout<<
" size of pfParticles "<<pfParticles.size()<<
std::endl;
734 if(thisTrack != 0x0){
753 std::cout<<
"this Track track ID "<<thisTrack->
ID()<<
std::endl;
774 if(calovector.size() != 3)
775 std::cerr <<
"WARNING::Calorimetry vector size for primary is = " << calovector.size() <<
std::endl;
776 std::vector<double> tmp_primtrk_dqdx;
777 std::vector<double> tmp_primtrk_resrange;
778 std::vector<double> tmp_primtrk_dedx;
779 std::vector<double> tmp_primtrk_hitx;
780 std::vector<double> tmp_primtrk_hity;
781 std::vector<double> tmp_primtrk_hitz;
782 std::vector<double> tmp_primtrk_pitch;
783 for (
auto &
calo : calovector) {
784 if (
calo.PlaneID().Plane == 2){
786 for (
size_t ihit = 0; ihit <
calo.dQdx().size(); ++ihit){
787 tmp_primtrk_dqdx.push_back(
calo.dQdx()[ihit]);
788 tmp_primtrk_resrange.push_back(
calo.ResidualRange()[ihit]);
789 tmp_primtrk_dedx.push_back(
calo.dEdx()[ihit]);
790 tmp_primtrk_pitch.push_back(
calo.TrkPitchVec()[ihit]);
792 const auto &primtrk_pos=(
calo.XYZ())[ihit];
793 tmp_primtrk_hitx.push_back(primtrk_pos.X());
794 tmp_primtrk_hity.push_back(primtrk_pos.Y());
795 tmp_primtrk_hitz.push_back(primtrk_pos.Z());
800 if(tmp_primtrk_dqdx.size()!=0){
801 if(tmp_primtrk_hitz[0]>tmp_primtrk_hitz[tmp_primtrk_hitz.size()-1]){
802 std::reverse(tmp_primtrk_hitz.begin(),tmp_primtrk_hitz.end());
803 std::reverse(tmp_primtrk_pitch.begin(),tmp_primtrk_pitch.end());
804 std::reverse(tmp_primtrk_dedx.begin(),tmp_primtrk_dedx.end());
805 std::reverse(tmp_primtrk_dqdx.begin(),tmp_primtrk_dqdx.end());
806 std::reverse(tmp_primtrk_resrange.begin(),tmp_primtrk_resrange.end());
816 tmp_primtrk_dqdx.clear();
817 tmp_primtrk_resrange.clear();
818 tmp_primtrk_dedx.clear();
819 tmp_primtrk_hitx.clear();
820 tmp_primtrk_hity.clear();
821 tmp_primtrk_hitz.clear();
822 tmp_primtrk_pitch.clear();
824 for(
size_t k = 0;
k < calovector.size() &&
k<3;
k++){
831 std::vector<float> Stw, Endw, Stt, Endt, Stwires, Endwires, Stticks, Endticks, TPCb, TPCcl;
832 Stw.clear(); Endw.clear(); Stt.clear(); Endt.clear(); Stwires.clear(); Endwires.clear(); Stticks.clear(); Endticks.clear(); TPCb.clear(); TPCcl.clear();
834 float numw, numt,wire_no,ticks_no;
835 for(
size_t p1=0;p1<pfplist.size();p1++){
836 std::vector<art::Ptr<recob::Track>>
trk=pftrack.at(p1);
837 std::vector<art::Ptr<recob::Cluster>> allClusters=fmcp.at(p1);
838 for(
size_t c1=0;
c1<allClusters.size();
c1++){
841 Stw.push_back(allClusters[
c1]->StartWire());
842 Endw.push_back(allClusters[
c1]->EndWire());
843 Stt.push_back(allClusters[
c1]->StartTick());
844 Endt.push_back(allClusters[
c1]->EndTick());
848 Stwires.push_back(allClusters[
c1]->StartWire());
849 Endwires.push_back(allClusters[
c1]->EndWire());
850 Stticks.push_back(allClusters[
c1]->StartTick());
851 Endticks.push_back(allClusters[
c1]->EndTick());
852 TPCcl.push_back(allClusters[
c1]->
Plane().
TPC);
856 for(
size_t clt=0;clt<Stw.size();clt++){
857 for(
size_t cl1=0;cl1<Stwires.size();cl1++){
858 if(TPCcl[cl1]!=TPCb[clt])
continue;
860 den=(Stw[clt]-Endw[clt])*(Stticks[cl1]-Endticks[cl1])-(Stt[clt]-Endt[clt])*(Stwires[cl1]-Endwires[cl1]);
862 numw=(Stw[clt]*Endt[clt]-Stt[clt]*Endw[clt])*(Stwires[cl1]-Endwires[cl1])-(Stw[clt]-Endw[clt])*(Stwires[cl1]*Endticks[cl1]-Stticks[cl1]*Endwires[cl1]);
863 numt=(Stw[clt]*Endt[clt]-Stt[clt]*Endw[clt])*(Stticks[cl1]-Endticks[cl1])-(Stt[clt]-Endt[clt])*(Stwires[cl1]*Endticks[cl1]-Stticks[cl1]*Endwires[cl1]);
867 if(((Stw[clt]<wire_no && Endw[clt]>wire_no)||(Stw[clt]>wire_no && Endw[clt]<wire_no))&&((Stt[clt]<ticks_no && Endt[clt]>ticks_no)||(Stt[clt]>ticks_no && Endt[clt]<ticks_no)) && ((Stwires[cl1]<wire_no && Endwires[cl1]>wire_no)||(Stwires[cl1]>wire_no && Endwires[cl1]<wire_no)) && ((Stticks[cl1]<ticks_no && Endticks[cl1]>ticks_no)||(Stticks[cl1]>ticks_no && Endticks[cl1]<ticks_no)))
869 std::cout<<
"intersection wire and ticks are "<<std::round(wire_no)<<
" "<<ticks_no<<
" Stw Endw StT EndT "<<Stwires[cl1]<<
" "<<Endwires[cl1]<<
" "<<Stticks[cl1]<<
" "<<Endticks[cl1]<<
std::endl;
872 unsigned int wireno=std::round(wire_no);
875 std::cout<<
"Z position of intersection = "<<xyzStart[2]<<
" "<<xyzEnd[2]<<
" "<<wireno<<
std::endl;
890 else if(thisShower != 0x0){
908 if( (thisShower->
dEdx()).
size() > 0 )
912 std::cout <<
"INFO::Primary pfParticle is not track or shower. Skip!" <<
std::endl;
929 std::cout <<
"INFO::Number of daughters is " << particle->NumDaughters() <<
". Only the first NMAXDAUGTHERS are processed." <<
std::endl;
932 for(
const int daughterID : particle->Daughters()){
935 std::cout <<
"Daughter " << daughterID <<
" has " << daughterParticle->
NumDaughters() <<
" daughters" <<
std::endl;
940 if(daughterTrack != 0x0){
965 if(daughtercalovector.size() != 3)
966 std::cerr <<
"WARNING::Calorimetry vector size for daughter is = " << daughtercalovector.size() <<
std::endl;
968 for(
size_t k = 0;
k < daughtercalovector.size() &&
k<3;
k++){
975 if(mcdaughterparticle != 0x0){
1000 std::cout <<
"Daughter Process = " << (mcdaughterparticle->
Process()).c_str()
1001 <<
" , mother = " << mcdaughterparticle->
Mother()
1005 else if(daughterShower != 0x0){
1021 if( (daughterShower->
dEdx()).
size() > 0 )
1025 std::cout <<
"INFO::Daughter pfParticle is not track or shower. Skip!" <<
std::endl;
1048 if(beamTriggerEvent)
1073 for(
int k=0;
k < 3;
k++){
1088 for(
int l=0;
l < 3;
l++){
1139 for(
int l=0;
l < 4;
l++){
1155 for(
int l=0;
l < 3;
l++){
1181 for(
int l=0;
l < 4;
l++){
double E(const int i=0) const
std::vector< float > beamtrk_Py
double fdaughterMomentumByRangeProton[NMAXDAUGTHERS]
double fdaughterEndMomentum[NMAXDAUGTHERS]
virtual void beginJob() override
unsigned int NumberTrajectoryPoints() const
double fdaughter_truth_Theta[NMAXDAUGTHERS]
const TVector3 & ShowerStart() const
const TLorentzVector & Position(const int i=0) const
double EndMomentum() const
double fdaughter_truth_EndMomentum[NMAXDAUGTHERS][4]
constexpr std::uint32_t timeLow() const
double fprimary_truth_EndMomentum[4]
std::vector< std::vector< double > > primtrk_truth_Eng
double Py(const int i=0) const
std::vector< std::vector< double > > primtrk_hitx
int NumDaughters() const
Returns the number of daughter particles flowing from this one.
const simb::MCParticle * GetGeantGoodParticle(const simb::MCTruth &genTruth, const art::Event &evt) const
std::vector< std::vector< double > > primtrk_pitch
std::vector< std::vector< double > > primtrk_truth_trkide
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.
Handle< PROD > getHandle(SelectorBase const &) const
enum geo::_plane_proj View_t
Enumerate the possible plane projections.
std::string fPFParticleTag
double fdaughter_truth_Pt[NMAXDAUGTHERS]
const simb::MCTrajectory & Trajectory() const
const recob::TrackTrajectory & Trajectory() const
Access to the stored recob::TrackTrajectory.
truepion(fhicl::ParameterSet const &p)
double fprimary_truth_Phi
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.
const value_type & at(const size_type i) const
std::vector< double > primtrk_range
constexpr std::uint32_t timeHigh() const
double fprimaryShowerMIPEnergy
std::string KeyToProcess(unsigned char const &key) const
const std::vector< const recob::Hit * > GetPFParticleHits(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Get the hits associated to the PFParticle.
const std::vector< double > & Energy() const
double Px(const int i=0) 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< float > beamtrk_Pz
virtual void endJob() override
double fdaughter_truth_StartPosition[NMAXDAUGTHERS][4]
std::string truth_last_process
Plane(const Point_t &planePos, const Vector_t &planeDir)
Constructor from reference position on the plane and direction orthogonal to the plane.
double fprimaryStartDirection[3]
std::vector< const sim::IDE * > TrackIdToSimIDEs_Ps(int const &id) const
double fprimaryShowerEnergy
int fprimaryShowerBestPlane
std::vector< double > interactionZ
double fdaughterOpeningAngle[NMAXDAUGTHERS]
EDAnalyzer(fhicl::ParameterSet const &pset)
std::string Process() const
int fisdaughtertrack[NMAXDAUGTHERS]
unsigned char ProcessToKey(std::string const &process) const
std::vector< float > beamtrk_Px
double fdaughterRange[NMAXDAUGTHERS][3]
double fdaughter_truth_P[NMAXDAUGTHERS]
double fdaughterShowerMIPEnergy[NMAXDAUGTHERS]
int NumberDaughters() const
art framework interface to geometry description
double fdaughterStartDirection[NMAXDAUGTHERS][3]
std::vector< float > beamtrk_Eng
double fprimaryKineticEnergy[3]
double fdaughterKineticEnergy[NMAXDAUGTHERS][3]
double fdaughterShowerdEdx[NMAXDAUGTHERS]
double fprimary_truth_StartPosition[4]
double fdaughterLength[NMAXDAUGTHERS]
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::vector< double > interactionX
std::vector< float > beamtrk_z
int fprimary_truth_TrackId
double Pt(const int i=0) const
int fdaughterID[NMAXDAUGTHERS]
double fprimaryShowerdEdx
std::vector< std::vector< double > > primtrk_hity
double Length(size_t p=0) const
Access to various track properties.
geo::GeometryCore const * fGeometry
const std::vector< double > & dEdx() const
#define DEFINE_ART_MODULE(klass)
const std::vector< double > & MIPEnergy() const
std::string EndProcess() const
double fprimary_truth_EndPosition[4]
Point_t const & Start() const
Access to track position at different points.
std::vector< std::vector< double > > primtrk_dedx
truepion & operator=(truepion const &)=delete
std::vector< double > Zintersection
double fprimary_truth_Momentum[4]
std::string fCalorimetryTag
double Theta() const
Access to spherical or geographical angles at vertex or at any point.
int fdaughter_truth_TrackId[NMAXDAUGTHERS]
int fprimary_truth_Process
double P(const int i=0) 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.
double fdaughter_truth_Phi[NMAXDAUGTHERS]
double fdaughter_truth_Mass[NMAXDAUGTHERS]
double T(const int i=0) const
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
double fdaughterEndPosition[NMAXDAUGTHERS][3]
std::vector< std::vector< double > > primtrk_truth_Z
std::vector< std::vector< double > > primtrk_dqdx
SubRunNumber_t subRun() const
double fdaughterPhi[NMAXDAUGTHERS]
const simb::MCParticle * GetMCParticleFromRecoTrack(detinfo::DetectorClocksData const &clockData, const recob::Track &track, art::Event const &evt, std::string trackModule) const
double fdaughterMomentumByRangeMuon[NMAXDAUGTHERS]
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...
double fdaughterTheta[NMAXDAUGTHERS]
const TVector3 & Direction() const
double fbeamtrackMomentum
int fisdaughtershower[NMAXDAUGTHERS]
Description of geometry of one entire detector.
std::string fGeneratorTag
double fprimaryEndPosition[3]
ProcessMap const & TrajectoryProcesses() const
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Definition of data types for geometry description.
protoana::ProtoDUNEPFParticleUtils pfpUtil
int fdaughterShowerBestPlane[NMAXDAUGTHERS]
double fprimaryMomentumByRangeMuon
std::vector< double > timeintersection
std::vector< float > beamtrk_x
int fdaughter_truth_Pdg[NMAXDAUGTHERS]
double fprimary_truth_Theta
double fdaughterMomentum[NMAXDAUGTHERS]
Vector_t EndDirection() const
Returns the direction of the trajectory at the last point.
double fdaughterStartPosition[NMAXDAUGTHERS][3]
double fdaughter_truth_EndPosition[NMAXDAUGTHERS][4]
double Vx(const int i=0) const
int fprimary_truth_Isbeammatched
Declaration of signal hit object.
double StartMomentum() const
Hierarchical representation of particle flow.
void FillCosmicsTree(art::Event const &evt, std::string pfParticleTag)
std::vector< double > interactionAngles
int fprimary_truth_NDaughters
double fdaughter_truth_Momentum[NMAXDAUGTHERS][4]
static unsigned int reverse(QString &chars, unsigned char *level, unsigned int a, unsigned int b)
std::vector< std::vector< double > > primtrk_hitz
Point_t const & End() const
Returns the position of the last valid point of the trajectory [cm].
const TLorentzVector & Momentum(const int i=0) const
double Pz(const int i=0) const
Provides recob::Track data product.
double fprimaryOpeningAngle
double Vz(const int i=0) const
double fprimaryStartPosition[3]
std::string fprimary_truth_EndProcess
void WireEndPoints(geo::WireID const &wireid, double *xyzStart, double *xyzEnd) const
Fills two arrays with the coordinates of the wire end points.
double fdaughterShowerEnergy[NMAXDAUGTHERS]
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.
EventNumber_t event() const
Point_t const & End() const
void analyze(art::Event const &evt) override
double fprimary_truth_Mass
protoana::ProtoDUNETrackUtils trackUtil
protoana::ProtoDUNEDataUtils dataUtil
double fprimaryEndMomentum
std::vector< std::string > interactionProcesslist
auto const & get(AssnsNode< L, R, D > const &r)
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
unsigned int GetNumberPrimaryPFParticle(art::Event const &evt, const std::string particleLabel) const
Get the number of primary PFParticles.
Vector_t StartDirection() const
Returns the direction of the trajectory at the first point.
second_as<> second
Type of time stored in seconds, in double precision.
recob::tracking::Plane Plane
Point_t const & Start() const
Returns the position of the first valid point of the trajectory [cm].
int fdaughterNHits[NMAXDAUGTHERS]
double fprimary_truth_tracklength
std::vector< double > interactionY
int fdaughter_truth_Process[NMAXDAUGTHERS]
protoana::ProtoDUNETruthUtils truthUtil
std::vector< std::vector< double > > primtrk_resrange
const art::InputTag fBeamModuleLabel
float GetBeamCosmicScore(const recob::PFParticle &particle, art::Event const &evt, const std::string particleLabel) const
Access the BDT output used to decide if a slice is beam-like or cosmic-like.
double fprimaryEndDirection[3]
double Vy(const int i=0) const
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
double GetTrackMomentum(double trkrange, int pdg) const
QTextStream & endl(QTextStream &s)
std::vector< float > beamtrk_y
double fdaughterEndDirection[NMAXDAUGTHERS][3]
double fprimaryMomentumByRangeProton