Public Member Functions | Private Member Functions | Private Attributes | List of all members
dune::AnaRootParser Class Reference

Creates a simple ROOT tree with tracking and calorimetry information. More...

Inheritance diagram for dune::AnaRootParser:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 AnaRootParser (fhicl::ParameterSet const &pset)
 
virtual ~AnaRootParser ()
 
void analyze (const art::Event &evt)
 read access to event More...
 
void beginSubRun (const art::SubRun &sr)
 
void endSubRun (const art::SubRun &sr)
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void HitsBackTrack (detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit, int &trackid, float &maxe, float &purity)
 
double length (const recob::Track &track)
 
double driftedLength (detinfo::DetectorPropertiesData const &detProp, const simb::MCParticle &part, TLorentzVector &start, TLorentzVector &end, unsigned int &starti, unsigned int &endi)
 
double driftedLength (detinfo::DetectorPropertiesData const &detProp, const sim::MCTrack &mctrack, TLorentzVector &tpcstart, TLorentzVector &tpcend, TLorentzVector &tpcmom)
 
double length (const simb::MCParticle &part, TLorentzVector &start, TLorentzVector &end, unsigned int &starti, unsigned int &endi)
 
double bdist (const TVector3 &pos)
 
int CountHits (const art::Event &evt, const art::InputTag &which, unsigned int cryostat, unsigned int tpc, unsigned int plane)
 
size_t GetNTrackers () const
 Returns the number of trackers configured. More...
 
size_t GetNVertexAlgos () const
 
size_t GetNShowerAlgos () const
 Returns the number of shower algorithms configured. More...
 
std::vector< std::stringGetShowerAlgos () const
 Returns the name of configured shower algorithms (converted to string) More...
 
void CreateData (bool bClearData=false)
 Creates the structure for the tree data; optionally initializes it. More...
 
void SetAddresses ()
 Sets the addresses of all the tree branches, creating the missing ones. More...
 
void SetTrackerAddresses (size_t iTracker)
 
void SetVertexAddresses (size_t iVertexAlg)
 
void SetShowerAddresses (size_t iShower)
 
void SetPFParticleAddress ()
 
void CreateTree (bool bClearData=false)
 Create the output tree and the data structures, if needed. More...
 
void DestroyData ()
 Destroy the local buffers (existing branches will point to invalid address!) More...
 
void CheckData (std::string caller) const
 Helper function: throws if no data structure is available. More...
 
void CheckTree (std::string caller) const
 Helper function: throws if no tree is available. More...
 
void FillShower (AnaRootParserDataStruct::ShowerDataStruct &showerData, size_t iShower, recob::Shower const &showers, const bool fSavePFParticleInfo, const std::map< Short_t, Short_t > &showerIDtoPFParticleIDMap) const
 Stores the information of shower in slot iShower of showerData. More...
 
void FillShowers (AnaRootParserDataStruct::ShowerDataStruct &showerData, std::vector< recob::Shower > const &showers, const bool fSavePFParticleInfo, const std::map< Short_t, Short_t > &showerIDtoPFParticleIDMap) const
 Stores the information of all showers into showerData. More...
 

Private Attributes

TTree * fTree
 
std::unique_ptr< AnaRootParserDataStructfData
 
AnaRootParserDataStruct::SubRunData_t SubRunData
 
int fLogLevel
 
short fEventsPerSubrun
 
std::string fRawDigitModuleLabel
 
std::string fHitsModuleLabel
 
std::string fPhotonPropS1ModuleLabel
 
std::string fElecDriftModuleLabel
 
std::string fCalDataModuleLabel
 
std::string fGenieGenModuleLabel
 
std::string fCryGenModuleLabel
 
std::string fProtoGenModuleLabel
 
std::string fG4ModuleLabel
 
std::string fSimEnergyDepositTPCActiveLabel
 
std::string fClusterModuleLabel
 
std::string fPandoraNuVertexModuleLabel
 
std::string fOpFlashModuleLabel
 
std::string fExternalCounterModuleLabel
 
std::string fMCShowerModuleLabel
 
std::string fMCTrackModuleLabel
 
std::vector< std::stringfTrackModuleLabel
 
std::string fPFParticleModuleLabel
 
std::vector< std::stringfVertexModuleLabel
 
std::vector< std::stringfShowerModuleLabel
 
std::vector< std::stringfCalorimetryModuleLabel
 
std::vector< std::stringfParticleIDModuleLabel
 
std::vector< std::stringfMVAPIDShowerModuleLabel
 
std::vector< std::stringfMVAPIDTrackModuleLabel
 
std::vector< std::stringfFlashT0FinderLabel
 
std::vector< std::stringfMCT0FinderLabel
 
std::string fPOTModuleLabel
 
std::string fCosmicClusterTaggerAssocLabel
 
bool fIsMC
 whether to use a permanent buffer (faster, huge memory) More...
 
bool fUseBuffer
 whether to use a permanent buffer (faster, huge memory) More...
 
bool fSaveAuxDetInfo
 whether to extract and save auxiliary detector data More...
 
bool fSaveCryInfo
 
bool fSaveGenieInfo
 whether to extract and save CRY particle data More...
 
bool fSaveProtoInfo
 whether to extract and save Genie information More...
 
bool fSavePhotonInfo
 whether to extract and save ProtDUNE beam simulation information More...
 
bool fSaveGeneratorInfo
 whether to extract and save collected photons More...
 
bool fSaveGeantInfo
 whether to extract and save Geant information More...
 
bool fSaveGeantInAVInfo
 whether to extract and save Geant information More...
 
bool fSaveGeantTrajectoryInfo
 whether to extract and save Geant information More...
 
bool fSaveSimEnergyDepositTPCActiveInfo
 whether to extract and save Geant information More...
 
bool fSaveMCShowerInfo
 whether to extract and save Cluster information More...
 
bool fSaveMCTrackInfo
 whether to extract and save MC Shower information More...
 
bool fSaveHitInfo
 whether to extract and save MC Track information More...
 
bool fSaveRawDigitInfo
 whether to extract and save Hit information More...
 
bool fSaveRecobWireInfo
 whether to extract and save raw digit information More...
 
bool fSaveTrackInfo
 whether to extract and save recob wire information More...
 
bool fSaveVertexInfo
 whether to extract and save Track information More...
 
bool fSaveClusterInfo
 whether to extract and save Vertex information More...
 
bool fSavePandoraNuVertexInfo
 whether to extract and save Cluster information More...
 
bool fSaveFlashInfo
 whether to extract and save nu vertex information from Pandora More...
 
bool fSaveExternCounterInfo
 whether to extract and save Flash information More...
 
bool fSaveShowerInfo
 whether to extract and save External Counter information More...
 
bool fSavePFParticleInfo
 whether to extract and save Shower information More...
 
std::vector< std::stringfCosmicTaggerAssocLabel
 whether to extract and save PFParticle information More...
 
std::vector< std::stringfContainmentTaggerAssocLabel
 
std::vector< std::stringfFlashMatchAssocLabel
 
bool bIgnoreMissingShowers
 whether to ignore missing shower information More...
 
bool isCosmics
 if it contains cosmics More...
 
bool fSaveCaloCosmics
 save calorimetry information for cosmics More...
 
float fG4minE
 Energy threshold to save g4 particle info. More...
 
trkf::TrajectoryMCSFitter fMCSFitter
 
double ActiveBounds [6]
 objet holding the configuration of the uBoone MCS fitting alg More...
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Creates a simple ROOT tree with tracking and calorimetry information.

Configuration parameters

Definition at line 1374 of file AnaRootParser_module.cc.

Constructor & Destructor Documentation

dune::AnaRootParser::AnaRootParser ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 3998 of file AnaRootParser_module.cc.

3998  :
3999  EDAnalyzer(pset),
4000  fTree(nullptr),
4001  // fPOT(nullptr),
4002 
4003  fLogLevel (pset.get< short >("LogLevel") ),
4004  fEventsPerSubrun (pset.get< short >("EventsPerSubrun") ),
4005  fRawDigitModuleLabel (pset.get< std::string >("RawDigitModuleLabel") ),
4006  fHitsModuleLabel (pset.get< std::string >("HitsModuleLabel") ),
4007  fPhotonPropS1ModuleLabel (pset.get< std::string >("PhotonPropS1ModuleLabel") ),
4008  fElecDriftModuleLabel (pset.get< std::string >("ElecDriftModuleLabel") ),
4009  fCalDataModuleLabel (pset.get< std::string >("CalDataModuleLabel") ),
4010  fGenieGenModuleLabel (pset.get< std::string >("GenieGenModuleLabel") ),
4011  fCryGenModuleLabel (pset.get< std::string >("CryGenModuleLabel") ),
4012  fProtoGenModuleLabel (pset.get< std::string >("ProtoGenModuleLabel") ),
4013  fG4ModuleLabel (pset.get< std::string >("G4ModuleLabel") ),
4014  fSimEnergyDepositTPCActiveLabel (pset.get< std::string >("SimEnergyDepositTPCActiveLabel") ),
4015  fClusterModuleLabel (pset.get< std::string >("ClusterModuleLabel") ),
4016  fPandoraNuVertexModuleLabel (pset.get< std::string >("PandoraNuVertexModuleLabel") ),
4017  fOpFlashModuleLabel (pset.get< std::string >("OpFlashModuleLabel") ),
4018  fExternalCounterModuleLabel (pset.get< std::string >("ExternalCounterModuleLabel") ),
4019  fMCShowerModuleLabel (pset.get< std::string >("MCShowerModuleLabel") ),
4020  fMCTrackModuleLabel (pset.get< std::string >("MCTrackModuleLabel") ),
4021  fTrackModuleLabel (pset.get< std::vector<std::string> >("TrackModuleLabel")),
4022  fVertexModuleLabel (pset.get< std::vector<std::string> >("VertexModuleLabel")),
4023  fShowerModuleLabel (pset.get< std::vector<std::string> >("ShowerModuleLabel")),
4024  fCalorimetryModuleLabel (pset.get< std::vector<std::string> >("CalorimetryModuleLabel")),
4025  fParticleIDModuleLabel (pset.get< std::vector<std::string> >("ParticleIDModuleLabel") ),
4026  fMVAPIDShowerModuleLabel (pset.get< std::vector<std::string> >("MVAPIDShowerModuleLabel") ),
4027  fMVAPIDTrackModuleLabel (pset.get< std::vector<std::string> >("MVAPIDTrackModuleLabel") ),
4028  fFlashT0FinderLabel (pset.get< std::vector<std::string> >("FlashT0FinderLabel") ),
4029  fMCT0FinderLabel (pset.get< std::vector<std::string> >("MCT0FinderLabel") ),
4030  fPOTModuleLabel (pset.get< std::string >("POTModuleLabel")),
4031  fCosmicClusterTaggerAssocLabel (pset.get< std::string >("CosmicClusterTaggerAssocLabel")),
4032  fIsMC (pset.get< bool >("IsMC", false)),
4033  fUseBuffer (pset.get< bool >("UseBuffers", false)),
4034  fSaveAuxDetInfo (pset.get< bool >("SaveAuxDetInfo", false)),
4035  fSaveCryInfo (pset.get< bool >("SaveCryInfo", false)),
4036  fSaveGenieInfo (pset.get< bool >("SaveGenieInfo", false)),
4037  fSaveProtoInfo (pset.get< bool >("SaveProtoInfo", false)),
4038  fSavePhotonInfo (pset.get< bool >("SavePhotonInfo", false)),
4039  fSaveGeneratorInfo (pset.get< bool >("SaveGeneratorInfo", false)),
4040  fSaveGeantInfo (pset.get< bool >("SaveGeantInfo", false)),
4041  fSaveGeantInAVInfo (pset.get< bool >("SaveGeantInAVInfo", false)),
4042  fSaveGeantTrajectoryInfo (pset.get< bool >("SaveGeantTrajectoryInfo", false)),
4043  fSaveSimEnergyDepositTPCActiveInfo (pset.get< bool >("SaveSimEnergyDepositTPCActiveInfo", false)),
4044  fSaveMCShowerInfo (pset.get< bool >("SaveMCShowerInfo", false)),
4045  fSaveMCTrackInfo (pset.get< bool >("SaveMCTrackInfo", false)),
4046  fSaveHitInfo (pset.get< bool >("SaveHitInfo", false)),
4047  fSaveRawDigitInfo (pset.get< bool >("SaveRawDigitInfo", false)),
4048  fSaveRecobWireInfo (pset.get< bool >("SaveRecobWireInfo", false)),
4049  fSaveTrackInfo (pset.get< bool >("SaveTrackInfo", false)),
4050  fSaveVertexInfo (pset.get< bool >("SaveVertexInfo", false)),
4051  fSaveClusterInfo (pset.get< bool >("SaveClusterInfo", false)),
4052  fSavePandoraNuVertexInfo (pset.get< bool >("SavePandoraNuVertexInfo", false)),
4053  fSaveFlashInfo (pset.get< bool >("SaveFlashInfo", false)),
4054  fSaveExternCounterInfo (pset.get< bool >("SaveExternCounterInfo", false)),
4055  fSaveShowerInfo (pset.get< bool >("SaveShowerInfo", false)),
4056  fSavePFParticleInfo (pset.get< bool >("SavePFParticleInfo", false)),
4057  fCosmicTaggerAssocLabel (pset.get<std::vector< std::string > >("CosmicTaggerAssocLabel") ),
4058  fContainmentTaggerAssocLabel (pset.get<std::vector< std::string > >("ContainmentTaggerAssocLabel") ),
4059  fFlashMatchAssocLabel (pset.get<std::vector< std::string > >("FlashMatchAssocLabel") ),
4060  bIgnoreMissingShowers (pset.get< bool >("IgnoreMissingShowers", false)),
4061  isCosmics(false),
4062  fSaveCaloCosmics (pset.get< bool >("SaveCaloCosmics",false)),
4063  fG4minE (pset.get< float>("G4minE",0.01)),
4064  fMCSFitter( pset.get<fhicl::ParameterSet>("TrajMCSFitter") )
4065 
4066 {
4067 
4068  if (fSavePFParticleInfo) fPFParticleModuleLabel = pset.get<std::string>("PFParticleModuleLabel");
4069 
4070  if (fSaveAuxDetInfo == true) fSaveGeantInfo = true;
4071 // if (fSaveRawDigitInfo == true) fSaveHitInfo = true;
4072  mf::LogInfo("AnaRootParser") << "Configuration:"
4073  << "\n UseBuffers: " << std::boolalpha << fUseBuffer
4074  ;
4075  if (GetNTrackers() > kMaxTrackers) {
4077  << "AnaRootParser currently supports only up to " << kMaxTrackers
4078  << " tracking algorithms, but " << GetNTrackers() << " are specified."
4079  << "\nYou can increase kMaxTrackers and recompile.";
4080  } // if too many trackers
4081  if (fTrackModuleLabel.size() != fCalorimetryModuleLabel.size()){
4083  << "fTrackModuleLabel.size() = "<<fTrackModuleLabel.size()<<" does not match "
4084  << "fCalorimetryModuleLabel.size() = "<<fCalorimetryModuleLabel.size();
4085  }
4086  if (fTrackModuleLabel.size() != fParticleIDModuleLabel.size()){
4088  << "fTrackModuleLabel.size() = "<<fTrackModuleLabel.size()<<" does not match "
4089  << "fParticleIDModuleLabel.size() = "<<fParticleIDModuleLabel.size();
4090  }
4091  if (fTrackModuleLabel.size() != fFlashT0FinderLabel.size()){
4093  << "fTrackModuleLabel.size() = "<<fTrackModuleLabel.size()<<" does not match "
4094  << "fFlashT0FinderLabel.size() = "<<fFlashT0FinderLabel.size();
4095  }
4096  if (fTrackModuleLabel.size() != fMCT0FinderLabel.size()){
4098  << "fTrackModuleLabel.size() = "<<fTrackModuleLabel.size()<<" does not match "
4099  << "fMCT0FinderLabel.size() = "<<fMCT0FinderLabel.size();
4100  }
4101  if (fTrackModuleLabel.size() != fCosmicTaggerAssocLabel.size()) {
4103  << "fTrackModuleLabel.size() = "<<fTrackModuleLabel.size()<<" does not match "
4104  << "fCosmicTaggerAssocLabel.size() = "<<fCosmicTaggerAssocLabel.size();
4105  }
4106  if (fTrackModuleLabel.size() != fContainmentTaggerAssocLabel.size()) {
4108  << "fTrackModuleLabel.size() = "<<fTrackModuleLabel.size()<<" does not match "
4109  << "fCosmicTaggerAssocLabel.size() = "<<fContainmentTaggerAssocLabel.size();
4110  }
4111  if (fTrackModuleLabel.size() != fFlashMatchAssocLabel.size()) {
4113  << "fTrackModuleLabel.size() = "<<fTrackModuleLabel.size()<<" does not match "
4114  << "fCosmicTaggerAssocLabel.size() = "<<fFlashMatchAssocLabel.size();
4115  }
4116  if (GetNVertexAlgos() > kMaxVertexAlgos) {
4118  << "AnaRootParser currently supports only up to " << kMaxVertexAlgos
4119  << " tracking algorithms, but " << GetNVertexAlgos() << " are specified."
4120  << "\nYou can increase kMaxVertexAlgos and recompile.";
4121  } // if too many trackers
4122 
4123  // Build my Cryostat boundaries array...Taken from Tyler Alion in Geometry Core. Should still return the same values for uBoone.
4124  ActiveBounds[0] = ActiveBounds[2] = ActiveBounds[4] = DBL_MAX;
4125  ActiveBounds[1] = ActiveBounds[3] = ActiveBounds[5] = -DBL_MAX;
4126  // assume single cryostats
4127  auto const* geom = lar::providerFrom<geo::Geometry>();
4128  for (geo::TPCGeo const& TPC: geom->IterateTPCs()) {
4129  // get center in world coordinates
4130  double origin[3] = {0.};
4131  double center[3] = {0.};
4132  TPC.LocalToWorld(origin, center);
4133  double tpcDim[3] = {TPC.HalfWidth(), TPC.HalfHeight(), 0.5*TPC.Length() };
4134 
4135  if( center[0] - tpcDim[0] < ActiveBounds[0] ) ActiveBounds[0] = center[0] - tpcDim[0];
4136  if( center[0] + tpcDim[0] > ActiveBounds[1] ) ActiveBounds[1] = center[0] + tpcDim[0];
4137  if( center[1] - tpcDim[1] < ActiveBounds[2] ) ActiveBounds[2] = center[1] - tpcDim[1];
4138  if( center[1] + tpcDim[1] > ActiveBounds[3] ) ActiveBounds[3] = center[1] + tpcDim[1];
4139  if( center[2] - tpcDim[2] < ActiveBounds[4] ) ActiveBounds[4] = center[2] - tpcDim[2];
4140  if( center[2] + tpcDim[2] > ActiveBounds[5] ) ActiveBounds[5] = center[2] + tpcDim[2];
4141  } // for all TPC
4142  std::cout << "Active Boundaries: "
4143  << "\n\tx: " << ActiveBounds[0] << " to " << ActiveBounds[1]
4144  << "\n\ty: " << ActiveBounds[2] << " to " << ActiveBounds[3]
4145  << "\n\tz: " << ActiveBounds[4] << " to " << ActiveBounds[5]
4146  << std::endl;
4147 } // dune::AnaRootParser::AnaRootParser()
std::vector< std::string > fCalorimetryModuleLabel
bool fSaveHitInfo
whether to extract and save MC Track information
std::vector< std::string > fMCT0FinderLabel
bool fSaveGeantTrajectoryInfo
whether to extract and save Geant information
bool fSaveGeantInfo
whether to extract and save Geant information
bool fSaveSimEnergyDepositTPCActiveInfo
whether to extract and save Geant information
std::string string
Definition: nybbler.cc:12
bool fIsMC
whether to use a permanent buffer (faster, huge memory)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
size_t GetNVertexAlgos() const
double ActiveBounds[6]
objet holding the configuration of the uBoone MCS fitting alg
std::string fSimEnergyDepositTPCActiveLabel
Geometry information for a single TPC.
Definition: TPCGeo.h:38
bool fSaveGenieInfo
whether to extract and save CRY particle data
size_t GetNTrackers() const
Returns the number of trackers configured.
bool isCosmics
if it contains cosmics
float fG4minE
Energy threshold to save g4 particle info.
std::string fPandoraNuVertexModuleLabel
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::vector< std::string > fMVAPIDTrackModuleLabel
bool fSaveGeantInAVInfo
whether to extract and save Geant information
std::string fExternalCounterModuleLabel
bool fUseBuffer
whether to use a permanent buffer (faster, huge memory)
bool fSaveGeneratorInfo
whether to extract and save collected photons
std::vector< std::string > fShowerModuleLabel
bool fSavePFParticleInfo
whether to extract and save Shower information
std::vector< std::string > fCosmicTaggerAssocLabel
whether to extract and save PFParticle information
constexpr int kMaxTrackers
bool fSaveExternCounterInfo
whether to extract and save Flash information
constexpr int kMaxVertexAlgos
trkf::TrajectoryMCSFitter fMCSFitter
bool fSavePhotonInfo
whether to extract and save ProtDUNE beam simulation information
std::vector< std::string > fFlashT0FinderLabel
std::vector< std::string > fContainmentTaggerAssocLabel
bool fSaveShowerInfo
whether to extract and save External Counter information
bool fSaveProtoInfo
whether to extract and save Genie information
bool fSaveCaloCosmics
save calorimetry information for cosmics
std::vector< std::string > fParticleIDModuleLabel
bool fSaveRecobWireInfo
whether to extract and save raw digit information
bool bIgnoreMissingShowers
whether to ignore missing shower information
std::vector< std::string > fVertexModuleLabel
bool fSavePandoraNuVertexInfo
whether to extract and save Cluster information
bool fSaveRawDigitInfo
whether to extract and save Hit information
bool fSaveMCShowerInfo
whether to extract and save Cluster information
bool fSaveClusterInfo
whether to extract and save Vertex information
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool fSaveFlashInfo
whether to extract and save nu vertex information from Pandora
bool fSaveAuxDetInfo
whether to extract and save auxiliary detector data
std::vector< std::string > fMVAPIDShowerModuleLabel
bool fSaveTrackInfo
whether to extract and save recob wire information
def center(depos, point)
Definition: depos.py:117
std::vector< std::string > fFlashMatchAssocLabel
bool fSaveMCTrackInfo
whether to extract and save MC Shower information
std::string fCosmicClusterTaggerAssocLabel
std::vector< std::string > fTrackModuleLabel
bool fSaveVertexInfo
whether to extract and save Track information
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
QTextStream & endl(QTextStream &s)
dune::AnaRootParser::~AnaRootParser ( )
virtual

Definition at line 4150 of file AnaRootParser_module.cc.

4151 {
4152  DestroyData();
4153 }
void DestroyData()
Destroy the local buffers (existing branches will point to invalid address!)

Member Function Documentation

void dune::AnaRootParser::analyze ( const art::Event evt)

read access to event

transfer the run and subrun data to the tree data object

Definition at line 4221 of file AnaRootParser_module.cc.

4222 {
4223 
4224  //services
4225 // art::ServiceHandle<cheat::BackTrackerService> bt_serv;
4227 
4228  // collect the sizes which might be needed to resize the tree data structure:
4229 
4230  // RawDigit
4231  std::vector<art::Ptr<raw::RawDigit> > rawdigitlist;
4232  auto rawdigitVecHandle = evt.getHandle< std::vector<raw::RawDigit> >(fRawDigitModuleLabel);
4233  if (rawdigitVecHandle)
4234  art::fill_ptr_vector(rawdigitlist, rawdigitVecHandle);
4235 
4236  // RecobWire
4237  std::vector<art::Ptr<recob::Wire> > recobwirelist;
4238  auto recobwireVecHandle = evt.getHandle< std::vector<recob::Wire> >(fCalDataModuleLabel);
4239  if (recobwireVecHandle)
4240  art::fill_ptr_vector(recobwirelist, recobwireVecHandle);
4241 
4242 
4243  // recob::Wire
4244 // auto wireVecHandle = evt.getHandle< std::vector<recob::Wire> >(fCalDataModuleLabel);
4245 
4246  // * photons
4247  //std::vector<art::Ptr<sim::SimPhotonsLite> > photonlist;
4249  if(fSavePhotonInfo) photonHandle = evt.getHandle< std::vector<sim::SimPhotonsLite> >(fPhotonPropS1ModuleLabel);
4250 // art::fill_ptr_vector(photonlist, photonHandle);
4251 
4252  // * hits
4253  std::vector<art::Ptr<recob::Hit> > hitlist;
4254  auto hitListHandle = evt.getHandle< std::vector<recob::Hit> >(fHitsModuleLabel);
4255  if (hitListHandle)
4256  art::fill_ptr_vector(hitlist, hitListHandle);
4257 
4258  // * clusters
4259  art::Handle< std::vector<recob::Cluster> > clusterListHandle;
4260  std::vector<art::Ptr<recob::Cluster> > clusterlist;
4261  if (fSaveClusterInfo){
4262  clusterListHandle = evt.getHandle< std::vector<recob::Cluster> >(fClusterModuleLabel);
4263  if (clusterListHandle)
4264  art::fill_ptr_vector(clusterlist, clusterListHandle);
4265  }
4266 
4267  // * flashes
4268  std::vector<art::Ptr<recob::OpFlash> > flashlist;
4269  auto flashListHandle = evt.getHandle< std::vector<recob::OpFlash> >(fOpFlashModuleLabel);
4270  if (flashListHandle)
4271  art::fill_ptr_vector(flashlist, flashListHandle);
4272 
4273  // * External Counters
4274  std::vector<art::Ptr<raw::ExternalTrigger> > countlist;
4275  auto countListHandle = evt.getHandle< std::vector<raw::ExternalTrigger> >(fExternalCounterModuleLabel);
4276  if (countListHandle)
4277  art::fill_ptr_vector(countlist, countListHandle);
4278 
4279  // * MC truth information
4280  art::Handle< std::vector<simb::MCTruth> > mctruthListHandle;
4281  std::vector<art::Ptr<simb::MCTruth> > mclist;
4282  if (fIsMC){
4283  mctruthListHandle = evt.getHandle< std::vector<simb::MCTruth> >(fGenieGenModuleLabel);
4284  if (mctruthListHandle)
4285  art::fill_ptr_vector(mclist, mctruthListHandle);
4286  }
4287 
4288  // SimEnergyDepositTPCActive
4289  int nSimEnergyDepositsTPCActive = 0;
4290  int nParticlesWithSimEnergyDepositsTPCActive = 0;
4291  int nLowestParticleIDSimEnergyDepositsTPCActive = 0;
4292  int nHighestParticleIDSimEnergyDepositsTPCActive = 0;
4293 
4294  std::vector<art::Ptr<sim::SimEnergyDeposit> > energyDepositTPCActivelist;
4296  {
4297  auto energyDepositTPCActiveHandle = evt.getHandle< std::vector<sim::SimEnergyDeposit> >(fSimEnergyDepositTPCActiveLabel);
4298  if (energyDepositTPCActiveHandle)
4299  {
4300  art::fill_ptr_vector(energyDepositTPCActivelist,energyDepositTPCActiveHandle);
4301  nSimEnergyDepositsTPCActive = energyDepositTPCActivelist.size();
4302 
4303  std::vector<int> tempparticleID;
4304  tempparticleID.resize(nSimEnergyDepositsTPCActive);
4305  FillWith(tempparticleID, 0);
4306 
4307  for(int sedavit = 0; sedavit < nSimEnergyDepositsTPCActive; sedavit++)
4308  {
4309  if( std::find(tempparticleID.begin(), tempparticleID.end(), energyDepositTPCActivelist[sedavit]->TrackID()) == tempparticleID.end() ) //check if current particle ID is already in the vector. if true: not in vector
4310  {
4311  tempparticleID[nParticlesWithSimEnergyDepositsTPCActive] = energyDepositTPCActivelist[sedavit]->TrackID();
4312  nParticlesWithSimEnergyDepositsTPCActive++;
4313  }
4314  if(energyDepositTPCActivelist[sedavit]->TrackID() < nLowestParticleIDSimEnergyDepositsTPCActive) nLowestParticleIDSimEnergyDepositsTPCActive=energyDepositTPCActivelist[sedavit]->TrackID();
4315  if(energyDepositTPCActivelist[sedavit]->TrackID() > nHighestParticleIDSimEnergyDepositsTPCActive) nHighestParticleIDSimEnergyDepositsTPCActive=energyDepositTPCActivelist[sedavit]->TrackID();
4316  }
4317 
4318  }
4319  }
4320 
4321  // *MC truth cosmic generator information
4322  std::vector<art::Ptr<simb::MCTruth> > mclistcry;
4323  if (fIsMC && fSaveCryInfo){
4324  auto mctruthcryListHandle = evt.getHandle< std::vector<simb::MCTruth> >(fCryGenModuleLabel);
4325  if (mctruthcryListHandle){
4326  art::fill_ptr_vector(mclistcry, mctruthcryListHandle);
4327  }
4328  else{
4329  // If we requested this info but it doesn't exist, don't use it.
4330  fSaveCryInfo = false;
4331  mf::LogError("AnaRootParser") << "Requested CRY information but none exists, hence not saving CRY information.";
4332  }
4333  }
4334 
4335  // ProtoDUNE beam generator information
4336  std::vector<art::Ptr<simb::MCTruth> > mclistproto;
4337  if(fIsMC && fSaveProtoInfo){
4338  auto mctruthprotoListHandle = evt.getHandle< std::vector<simb::MCTruth> >(fProtoGenModuleLabel);
4339  if (mctruthprotoListHandle){
4340  art::fill_ptr_vector(mclistproto,mctruthprotoListHandle);
4341  }
4342  else{
4343  // If we requested this info but it doesn't exist, don't use it.
4344  fSaveProtoInfo = false;
4345  mf::LogError("AnaRootParser") << "Requested protoDUNE beam generator information but none exists, hence not saving protoDUNE beam generator information.";
4346  }
4347  }
4348 
4349  // *MC Shower information
4351  if (fIsMC)
4352  mcshowerh = evt.getHandle< std::vector<sim::MCShower> >(fMCShowerModuleLabel);
4353 
4354  int nMCShowers = 0;
4355  if (fSaveMCShowerInfo && mcshowerh.isValid())
4356  nMCShowers = mcshowerh->size();
4357 
4358  // *MC Track information
4360  if (fIsMC)
4361  mctrackh = evt.getHandle< std::vector<sim::MCTrack> >(fMCTrackModuleLabel);
4362 
4363  int nMCTracks = 0;
4364  if (fSaveMCTrackInfo && mctrackh.isValid())
4365  nMCTracks = mctrackh->size();
4366 
4367  art::Ptr<simb::MCTruth> mctruthcry;
4368  int nCryPrimaries = 0;
4369 
4370  if (fSaveCryInfo){
4371  mctruthcry = mclistcry[0];
4372  nCryPrimaries = mctruthcry->NParticles();
4373  }
4374 
4375  art::Ptr<simb::MCTruth> mctruthproto;
4376  int nProtoPrimaries = 0;
4377  if( fSaveProtoInfo){
4378  mctruthproto = mclistproto[0];
4379  nProtoPrimaries = mctruthproto->NParticles();
4380  }
4381 
4382  int nPhotons=0;
4383  int nGeniePrimaries = 0, nGeneratorParticles = 0, nGEANTparticles = 0, nGEANTparticlesInAV = 0, nGEANTtrajectorysteps=0;
4384 
4385  art::Ptr<simb::MCTruth> mctruth;
4386 
4387 
4388  if (fIsMC) { //is MC
4389 
4390  //find origin
4391  auto const allmclists = evt.getMany<std::vector<simb::MCTruth>>();
4392  for(size_t mcl = 0; mcl < allmclists.size(); ++mcl){
4393  art::Handle< std::vector<simb::MCTruth> > mclistHandle = allmclists[mcl];
4394  for(size_t m = 0; m < mclistHandle->size(); ++m){
4395  art::Ptr<simb::MCTruth> mct(mclistHandle, m);
4396  if (mct->Origin() == simb::kCosmicRay) isCosmics = true;
4397  }
4398  }
4399  if (fSaveCaloCosmics) isCosmics = false; //override to save calo info
4400 
4401  // GENIE
4402  if (!mclist.empty()){//at least one mc record
4403 
4404  // double maxenergy = -1;
4405  // int imc0 = 0;
4406  // for (std::map<art::Ptr<simb::MCTruth>,double>::iterator ii=mctruthemap.begin(); ii!=mctruthemap.end(); ++ii){
4407  // if ((ii->second)>maxenergy){
4408  // maxenergy = ii->second;
4409  // mctruth = ii->first;
4410  // imc = imc0;
4411  // }
4412  // imc0++;
4413  // }
4414 
4415  //imc = 0; //set imc to 0 to solve a confusion for BNB+cosmic files where there are two MCTruth
4416  mctruth = mclist[0];
4417 
4418  if (mctruth->NeutrinoSet()) nGeniePrimaries = mctruth->NParticles();
4419  //} //end (fSaveGenieInfo)
4420 
4421  const sim::ParticleList& plist = pi_serv->ParticleList();
4422  nGEANTparticles = plist.size();
4423 
4424  sim::ParticleList::const_iterator itPart = plist.begin(),
4425  pend = plist.end(); // iterator to pairs (track id, particle)
4426 
4427  std::string pri("primary");
4428  for(size_t iPart = 0; (iPart < plist.size()) && (itPart != pend); ++iPart)
4429  {
4430  const simb::MCParticle* pPart = (itPart++)->second;
4431  if (!pPart)
4432  {
4434  << "GEANT particle #" << iPart << " returned a null pointer";
4435  }
4436  nGEANTtrajectorysteps += pPart->NumberTrajectoryPoints();
4437 
4438  if(pPart->Mother() == 0 && pPart->Process() == pri) nGeneratorParticles++;
4439 
4440  TLorentzVector mcstart, mcend;
4441  unsigned int pstarti, pendi;
4442  double plen = length(*pPart, mcstart, mcend, pstarti, pendi);
4443  if( plen != 0) nGEANTparticlesInAV += 1;
4444 
4445  } // for particles
4446 
4447  // counting photons
4448  if(fSavePhotonInfo)
4449  {
4450  for ( auto const& pmt : (*photonHandle) )
4451  {
4452  std::map<int, int> PhotonsMap = pmt.DetectedPhotons;
4453 
4454  for(auto itphoton = PhotonsMap.begin(); itphoton!= PhotonsMap.end(); itphoton++)
4455  {
4456  for(int i = 0; i < itphoton->second ; i++)
4457  {
4458  nPhotons++;
4459  }
4460  }
4461  }
4462  }
4463  } // if have MC truth
4464  MF_LOG_DEBUG("AnaRootParser") << "Expected "
4465  << nGEANTparticles << " GEANT particles, "
4466  << nGeniePrimaries << " GENIE particles";
4467  } // if MC
4468 
4469 CreateData(); // tracker data is created with default constructor
4470 if (fSaveGenieInfo){ fData->ResizeGenie(nGeniePrimaries);}
4471 if (fSaveCryInfo){ fData->ResizeCry(nCryPrimaries);}
4472 if (fSaveProtoInfo){ fData->ResizeProto(nProtoPrimaries);}
4473 if (fSaveGeneratorInfo){ fData->ResizeGenerator(nGeneratorParticles);}
4474 if (fSaveGeantInfo){ fData->ResizeGEANT(nGEANTparticles);}
4475 if (fSaveGeantInfo && fSaveGeantInAVInfo){ fData->ResizeGEANTInAV(nGEANTparticlesInAV);}
4476 if (fSaveGeantTrajectoryInfo){ fData->ResizeGEANTTrajectory(nGEANTtrajectorysteps);}
4477 if (fSaveSimEnergyDepositTPCActiveInfo) {fData->ResizeSimEnergyDepositsTPCActive(nSimEnergyDepositsTPCActive, nParticlesWithSimEnergyDepositsTPCActive);}
4478 if (fSaveMCShowerInfo){ fData->ResizeMCShower(nMCShowers);}
4479 if (fSaveMCTrackInfo){ fData->ResizeMCTrack(nMCTracks);}
4480 if (fSavePhotonInfo){ fData->ResizePhotons(nPhotons);}
4481 
4482 if(fLogLevel >= 1)
4483 {
4484  std::cout << "nGeneratorParticles: " << nGeneratorParticles << std::endl;
4485  std::cout << "nGEANTparticles: " << nGEANTparticles << std::endl;
4486  std::cout << "nGEANTtrajectorysteps: " << nGEANTtrajectorysteps << std::endl;
4487  std::cout << "nGEANTparticlesInAV: " << nGEANTparticlesInAV << std::endl;
4488  std::cout << "nSimEnergyDepositsTPCActive: " << nSimEnergyDepositsTPCActive << std::endl;
4489  std::cout << "nParticlesWithSimEnergyDepositsTPCActive: " << nParticlesWithSimEnergyDepositsTPCActive << std::endl;
4490  std::cout << "nLowestParticleIDSimEnergyDepositsTPCActive: " << nLowestParticleIDSimEnergyDepositsTPCActive << std::endl;
4491  std::cout << "nHighestParticleIDSimEnergyDepositsTPCActive: " << nHighestParticleIDSimEnergyDepositsTPCActive << std::endl;
4492  std::cout << "nPhotons: " << nPhotons << std::endl;
4493 }
4494 
4495  fData->ClearLocalData(); // don't bother clearing tracker data yet
4496 
4497  const size_t NTrackers = GetNTrackers(); // number of trackers passed into fTrackModuleLabel
4498  const size_t NShowerAlgos = GetNShowerAlgos(); // number of shower algorithms into fShowerModuleLabel
4499  const size_t NChannels = rawdigitlist.size(); //number of channels holding raw waveforms
4500  const size_t NRecoChannels = recobwirelist.size(); //number of channels holding ROI's
4501  const size_t NHits = hitlist.size(); // number of hits
4502  const size_t NVertexAlgos = GetNVertexAlgos(); // number of vertex algos
4503  const size_t NClusters = clusterlist.size(); //number of clusters
4504  const size_t NFlashes = flashlist.size(); // number of flashes
4505  const size_t NExternCounts = countlist.size(); // number of External Counters
4506  // make sure there is the data, the tree and everything;
4507  CreateTree();
4508 
4509  /// transfer the run and subrun data to the tree data object
4510  // fData->RunData = RunData;
4511  fData->SubRunData = SubRunData;
4512 
4513  fData->isdata = int(!fIsMC);
4514 
4515  // raw trigger
4516  std::vector<art::Ptr<raw::Trigger> > triggerlist;
4517  auto triggerListHandle = evt.getHandle< std::vector<raw::Trigger>>(fRawDigitModuleLabel);
4518  if (triggerListHandle){ art::fill_ptr_vector(triggerlist, triggerListHandle);}
4519 
4520  if (triggerlist.size()){
4521  fData->triggernumber = triggerlist[0]->TriggerNumber();
4522  fData->triggertime = triggerlist[0]->TriggerTime();
4523  fData->beamgatetime = triggerlist[0]->BeamGateTime();
4524  fData->triggerbits = triggerlist[0]->TriggerBits();
4525  }
4526 
4527 // vertices
4528  std::vector< art::Handle< std::vector<recob::Vertex> > > vertexListHandle(NVertexAlgos);
4529  std::vector< std::vector<art::Ptr<recob::Vertex> > > vertexlist(NVertexAlgos);
4530  for (unsigned int it = 0; it < NVertexAlgos; ++it){
4531  vertexListHandle[it] = evt.getHandle< std::vector<recob::Vertex> >(fVertexModuleLabel[it]);
4532  if (vertexListHandle[it])
4533  art::fill_ptr_vector(vertexlist[it], vertexListHandle[it]);
4534 }
4535 
4536 // PFParticles
4537 lar_pandora::PFParticleVector pfparticlelist;
4538 lar_pandora::PFParticlesToClusters pfParticleToClusterMap;
4539 lar_pandora::LArPandoraHelper::CollectPFParticles(evt, fPFParticleModuleLabel, pfparticlelist, pfParticleToClusterMap);
4540 
4541 // tracks
4542 std::vector< art::Handle< std::vector<recob::Track> > > trackListHandle(NTrackers);
4543 std::vector< std::vector<art::Ptr<recob::Track> > > tracklist(NTrackers);
4544 for (unsigned int it = 0; it < NTrackers; ++it){
4545  trackListHandle[it] = evt.getHandle< std::vector<recob::Track> >(fTrackModuleLabel[it]);
4546  if (trackListHandle[it])
4547  art::fill_ptr_vector(tracklist[it], trackListHandle[it]);
4548 }
4549 
4550 // showers
4551 // It seems that sometimes the shower data product does not exist;
4552 // in that case, we store a nullptr in place of the pointer to the vector;
4553 // the data structure itself is owned by art::Event and we should not try
4554 // to manage its memory
4555 std::vector<std::vector<recob::Shower> const*> showerList;
4556 std::vector< art::Handle< std::vector<recob::Shower> > > showerListHandle;
4557 showerList.reserve(fShowerModuleLabel.size());
4558 if (fSaveShowerInfo) {
4559  for (art::InputTag ShowerInputTag: fShowerModuleLabel) {
4560  auto ShowerHandle = evt.getHandle<std::vector<recob::Shower>>(ShowerInputTag);
4561  if (!ShowerHandle) {
4562  showerList.push_back(nullptr);
4563  if (!bIgnoreMissingShowers) {
4565  << "Showers with input tag '" << ShowerInputTag.encode()
4566  << "' were not found in the event."
4567  " If you really know what you are doing,"
4568  " set AnaRootParser's configuration parameter IgnoreMissingShowers"
4569  " to \"true\"; the lack of any shower set will be tolerated,"
4570  " and the shower list in the corresponding event will be set to"
4571  " a list of one shower, with an invalid ID.\n";
4572  } // if bIgnoreMissingShowers
4573  else {
4574  // this message is more alarming than strictly necessary; by design.
4575  mf::LogError("AnaRootParser")
4576  << "No showers found for input tag '" << ShowerInputTag.encode()
4577  << "' ; FILLING WITH FAKE DATA AS FOR USER'S REQUEST";
4578  }
4579  }
4580 
4581  else showerList.push_back(ShowerHandle.product());
4582 
4583  showerListHandle.push_back(ShowerHandle); // either way, put it into the handle list
4584 
4585  }
4586 
4587 } // for shower input tag
4588 
4589 
4590 // Find the simb::MCFlux objects corresponding to
4591 // each simb::MCTruth object made by the generator with
4592 // the label fGenieGenModuleLabel
4593 // art::FindOne<simb::MCFlux> find_mcflux(mctruthListHandle, evt, fGenieGenModuleLabel);
4594 
4595 std::vector<const sim::AuxDetSimChannel*> fAuxDetSimChannels;
4596 if (fSaveAuxDetInfo){
4597  evt.getView(fElecDriftModuleLabel, fAuxDetSimChannels);
4598 }
4599 
4600 std::vector<const sim::SimChannel*> fSimChannels;
4601 if (fIsMC && fSaveGeantInfo){ evt.getView(fElecDriftModuleLabel, fSimChannels);}
4602 
4603  fData->run = evt.run();
4604  fData->subrun = evt.subRun();
4605  fData->event = evt.id().event() + fEventsPerSubrun*evt.subRun();
4606 
4607  art::Timestamp ts = evt.time();
4608  fData->evttime_seconds = ts.timeHigh();
4609  fData->evttime_nanoseconds = ts.timeLow();
4610 
4611  //copied from MergeDataPaddles.cxx
4612  auto beam = evt.getHandle< raw::BeamInfo >("beamdata");
4613  if (beam){
4614  fData->beamtime = (double)beam->get_t_ms();
4615  fData->beamtime/=1000.; //in second
4616  std::map<std::string, std::vector<double>> datamap = beam->GetDataMap();
4617  if (datamap["E:TOR860"].size()){
4618  fData->potbnb = datamap["E:TOR860"][0];
4619  }
4620  if (datamap["E:TORTGT"].size()){
4621  fData->potnumitgt = datamap["E:TORTGT"][0];
4622  }
4623  if (datamap["E:TOR101"].size()){
4624  fData->potnumi101 = datamap["E:TOR101"][0];
4625  }
4626  }
4627 
4628  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
4629  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clockData);
4630 // std::cout<<detProp.NumberTimeSamples()<<" "<<detProp.ReadOutWindowSize()<<std::endl;
4631 // std::cout<<geom->DetHalfHeight()2<<" "<<geom->DetHalfWidth()2<<" "<<geom->DetLength()<<std::endl;
4632 // std::cout<<geom->Nwires(0)<<" "<<geom->Nwires(1)<<" "<<geom->Nwires(2)<<std::endl;
4633 
4634 
4635 //RawDigit info
4636 if (fSaveRawDigitInfo){
4637  fData->no_channels = (int) NChannels;
4638  if (NChannels>0)
4639  {
4640  fData->no_ticks = (int) rawdigitlist[0]->Samples();
4641  fData->no_ticksinallchannels = fData->no_channels*fData->no_ticks;
4642  }
4643  else
4644  {
4645  fData->no_ticks = 0;
4646  fData->no_ticksinallchannels = 0;
4647  }
4648 
4649  for (int i = 0; i < fData->no_channels ; i++) //loop over channels holding raw waveforms
4650  {
4651  fData->rawD_Channel[i] = (int) rawdigitlist[i]->Channel();
4652  int k=0;
4653 
4654  for (int j = fData->no_ticks*i; j < (fData->no_ticks*(i+1)) && j < kMaxReadoutTicksInAllChannels ; j++) //loop over ticks
4655  {
4656  fData->rawD_ADC[j] = rawdigitlist[i]->ADC(k);
4657  k++;
4658  }
4659  }
4660 }
4661 
4662 //RecobWire info
4663 if (fSaveRecobWireInfo){
4664  fData->no_recochannels = (int) NRecoChannels;
4665  int RecoWTick=0;
4666 
4667  for(int i = 0; i < fData->no_recochannels; i++) //loop over channels holding reco waveforms
4668  {
4669  fData->recoW_NTicks[i]=0;
4670  fData->recoW_Channel[i] = recobwirelist[i]->Channel();
4671  const recob::Wire::RegionsOfInterest_t& signalROI = recobwirelist[i]->SignalROI();
4672 
4673  for(const auto& range : signalROI.get_ranges()) //loop over ROIs
4674  {
4675  const std::vector<float>& signal = range.data();
4676  int NTicksInThisROI = range.end_index() - range.begin_index();
4677 
4678  for(int j = 0; j < NTicksInThisROI; j++) //loop over ticks
4679  {
4680  fData->recoW_Tick[RecoWTick] = j+range.begin_index();
4681  fData->recoW_ADC[RecoWTick] = signal.at(j);
4682  RecoWTick++;
4683  }
4684  fData->recoW_NTicks[i] += NTicksInThisROI;
4685  }
4686  }
4687  fData->no_recoticksinallchannels = RecoWTick;
4688 }
4689 
4690 //hit information
4691 if (fSaveHitInfo){
4692 
4693  int trueID = -9999;
4694  float maxe = -9999;
4695  float purity = -9999;
4696 
4697  fData->no_hits = (int) NHits;
4698  fData->NHitsInAllTracks = (int) NHits;
4699  fData->no_hits_stored = TMath::Min( (int) NHits, (int) kMaxHits);
4700  if (NHits > kMaxHits) {
4701  // got this error? consider increasing kMaxHits
4702  // (or ask for a redesign using vectors)
4703  mf::LogError("AnaRootParser:limits") << "event has " << NHits
4704  << " hits, only kMaxHits=" << kMaxHits << " stored in tree";
4705  }
4706 
4707 // trying to assign a space point to those recob::Hits t hat were assigned to a track, checking for every hit. Not really working yet.
4708 // art::FindManyP<recob::SpacePoint> fmsp(hitlist,evt,"pmtrack");
4709 
4710  auto hitResults = anab::FVectorReader<recob::Hit, 4>::create(evt, "dprawhit");
4711  const auto & fitParams = hitResults->vectors();
4712 
4713  for (size_t i = 0; i < NHits && i < kMaxHits ; ++i){//loop over hits
4714  fData->hit_channel[i] = hitlist[i]->Channel();
4715  fData->hit_tpc[i] = hitlist[i]->WireID().TPC;
4716  fData->hit_view[i] = hitlist[i]->WireID().Plane;
4717  fData->hit_wire[i] = hitlist[i]->WireID().Wire;
4718  fData->hit_peakT[i] = hitlist[i]->PeakTime();
4719  fData->hit_chargesum[i] = hitlist[i]->SummedADC();
4720  fData->hit_chargeintegral[i] = hitlist[i]->Integral();
4721  fData->hit_ph[i] = hitlist[i]->PeakAmplitude();
4722  fData->hit_startT[i] = hitlist[i]->StartTick();
4723  fData->hit_endT[i] = hitlist[i]->EndTick();
4724  fData->hit_rms[i] = hitlist[i]->RMS();
4725  fData->hit_goodnessOfFit[i] = hitlist[i]->GoodnessOfFit();
4726 
4727  fData->hit_fitparamt0[i] = fitParams[i][0];
4728  fData->hit_fitparamtau1[i] = fitParams[i][1];
4729  fData->hit_fitparamtau2[i] = fitParams[i][2];
4730  fData->hit_fitparamampl[i] = fitParams[i][3];
4731 
4732  fData->hit_multiplicity[i] = hitlist[i]->Multiplicity();
4733 
4734  //quantities from backtracker are different from the real value in MC
4735 
4736  if( fIsMC )
4737  HitsBackTrack(clockData, hitlist[i], trueID, maxe, purity );
4738 
4739  fData->hit_trueID[i] = trueID;
4740  fData->hit_trueEnergyMax[i] = maxe;
4741  fData->hit_trueEnergyFraction[i] = purity;
4742 
4743 /*
4744  std::vector< art::Ptr<recob::SpacePoint> > sptv = fmsp.at(i);
4745  if (fmsp.at(i).size()!=0){
4746  std::cout << "sptv[i]->XYZ()[0]: " << sptv[i]->XYZ()[0] << std::endl;
4747  std::cout << "sptv[i]->XYZ()[1]: " << sptv[i]->XYZ()[1] << std::endl;
4748  std::cout << "sptv[i]->XYZ()[2]: " << sptv[i]->XYZ()[2] << std::endl;
4749  }
4750  std::cout << "test3" << std::endl;
4751 // std::cout << "test" << std::endl;
4752 // art::FindManyP<recob::SpacePoint> fmsp(hitListHandle,evt,"pmtrack");
4753 // art::FindManyP<recob::SpacePoint> fmsp(allHits, evt, fSpacePointModuleLabel);
4754 // art::FindManyP<recob::SpacePoint> fmsp(hitlist,evt,"pmtrack");
4755  for (size_t i = 0; i < NHits && i < kMaxHits ; ++i){//loop over hits
4756  if (fmsp.isValid()){
4757  if (fmsp.at(i).size()!=0){
4758 
4759  std::cout << "Spacepoint in x for hit" << i << ": " << fmsp.at(i)[0]->XYZ()[0] << std::endl;
4760  // fData->hit_clusterid[i] = fmcl.at(i)[0]->ID();
4761  // fData->hit_clusterKey[i] = fmcl.at(i)[0].key();
4762  }
4763  else std::cout << "No spacepoint for this hit" << std::endl;
4764  }
4765  }
4766  //Get space points associated with the hit
4767  std::vector< art::Ptr<recob::SpacePoint> > sptv = fmsp.at(hits[ipl][i]);
4768 */
4769 
4770 
4771 
4772  //std::vector<double> xyz = bt_serv->HitToXYZ(hitlist[i]);
4773  //when the size of simIDEs is zero, the above function throws an exception
4774  //and crashes, so check that the simIDEs have non-zero size before
4775  //extracting hit true XYZ from simIDEs
4776  // if (fIsMC){
4777  // std::vector<sim::IDE> ides;
4778  // try{bt_serv->HitToSimIDEs(hitlist[i], ides); }
4779  // catch(...){}
4780  // if (ides.size()>0){
4781  // std::vector<double> xyz = bt_serv->SimIDEsToXYZ(ides);
4782  // fData->hit_trueX[i] = xyz[0];
4783  // }
4784  // }
4785  /*
4786  for (unsigned int it=0; it<fTrackModuleLabel.size();++it){
4787  art::FindManyP<recob::Track> fmtk(hitListHandle,evt,fTrackModuleLabel[it]);
4788  if (fmtk.at(i).size()!=0){
4789  hit_trkid[it][i] = fmtk.at(i)[0]->ID();
4790  }
4791  else
4792  hit_trkid[it][i] = 0;
4793  }
4794  */
4795 
4796 /*
4797  if (fSaveRawDigitInfo){
4798  //Hit to RawDigit information
4799  art::FindManyP<raw::RawDigit> fmrd(hitListHandle,evt,fHitsModuleLabel);
4800  if (hitlist[i]->WireID().Plane==2)
4801  {
4802  int dataSize = fmrd.at(i)[0]->Samples();
4803  short ped = fmrd.at(i)[0]->GetPedestal();
4804 
4805  std::vector<short> rawadc(dataSize);
4806  raw::Uncompress(fmrd.at(i)[0]->ADCs(), rawadc, fmrd.at(i)[0]->Compression());
4807  int t0 = hitlist[i]->PeakTime() - 3*(hitlist[i]->RMS());
4808  if (t0<0) t0 = 0;
4809  int t1 = hitlist[i]->PeakTime() + 3*(hitlist[i]->RMS());
4810  if (t1>=dataSize) t1 = dataSize-1;
4811  fData->rawD_ph[i] = -1;
4812  fData->rawD_peakT[i] = -1;
4813  for (int j = t0; j<=t1; ++j){
4814  if (rawadc[j]-ped>fData->rawD_ph[i]){
4815  fData->rawD_ph[i] = rawadc[j]-ped;
4816  fData->rawD_peakT[i] = j;
4817  }
4818  }
4819  fData->rawD_charge[i] = 0;
4820  fData->rawD_fwhh[i] = 0;
4821  double mean_t = 0.0;
4822  double mean_t2 = 0.0;
4823  for (int j = t0; j<=t1; ++j){
4824  if (rawadc[j]-ped>=0.5*fData->rawD_ph[i]){
4825  ++fData->rawD_fwhh[i];
4826  }
4827  if (rawadc[j]-ped>=0.1*fData->rawD_ph[i]){
4828  fData->rawD_charge[i] += rawadc[j]-ped;
4829  mean_t += (double)j*(rawadc[j]-ped);
4830  mean_t2 += (double)j*(double)j*(rawadc[j]-ped);
4831  }
4832  }
4833  mean_t/=fData->rawD_charge[i];
4834  mean_t2/=fData->rawD_charge[i];
4835  fData->rawD_rms[i] = sqrt(mean_t2-mean_t*mean_t);
4836  }
4837  } // Save RawDigitInfo
4838 */
4839  /* if (!evt.isRealData()&&!isCosmics){
4840  fData -> hit_nelec[i] = 0;
4841  fData -> hit_energy[i] = 0;
4842  const sim::SimChannel* chan = 0;
4843  for(size_t sc = 0; sc < fSimChannels.size(); ++sc){
4844  if(fSimChannels[sc]->Channel() == hitlist[i]->Channel()) chan = fSimChannels[sc];
4845  }
4846  if (chan){
4847  for(auto const& mapitr : chan->TDCIDEMap()){
4848  // loop over the vector of IDE objects.
4849  for(auto const& ide : mapitr.second){
4850  fData -> hit_nelec[i] += ide.numElectrons;
4851  fData -> hit_energy[i] += ide.energy;
4852  }
4853  }
4854  }
4855  }*/
4856  } // Loop over hits
4857 
4858 
4859  hitListHandle = evt.getHandle< std::vector<recob::Hit> >(fHitsModuleLabel);
4860  if (hitListHandle){
4861  //Find tracks associated with hits
4862  art::FindManyP<recob::Track> fmtk(hitListHandle,evt,fTrackModuleLabel[0]);
4863  for (size_t i = 0; i < NHits && i < kMaxHits ; ++i){//loop over hits
4864  if (fmtk.isValid()){
4865  if (fmtk.at(i).size()!=0){
4866  fData->hit_trkid[i] = fmtk.at(i)[0]->ID();
4867  // fData->hit_trkKey[i] = fmtk.at(i)[0].key();
4868 
4869  }
4870  else
4871  fData->hit_trkid[i] = -1;
4872  }
4873  }
4874  }
4875 
4876  //In the case of ClusterCrawler or linecluster, use "linecluster or clustercrawler" as HitModuleLabel.
4877  //using cchit will not make this association. In the case of gaushit, just use gaushit
4878  //Not initializing clusterID to -1 since some clustering algorithms assign negative IDs!
4879  hitListHandle = evt.getHandle< std::vector<recob::Hit> >(fHitsModuleLabel);
4880  if (hitListHandle){
4881  //Find clusters associated with hits
4882  art::FindManyP<recob::Cluster> fmcl(hitListHandle,evt,fClusterModuleLabel);
4883  for (size_t i = 0; i < NHits && i < kMaxHits ; ++i){//loop over hits
4884  if (fmcl.isValid()){
4885  if (fmcl.at(i).size()!=0){
4886  fData->hit_clusterid[i] = fmcl.at(i)[0]->ID();
4887  // fData->hit_clusterKey[i] = fmcl.at(i)[0].key();
4888  }
4889  else
4890  fData->hit_clusterid[i] = -1;
4891  }
4892  }
4893  }
4894 }// end (fSaveHitInfo)
4895 
4897  lar_pandora::PFParticleVector particleVector;
4899  lar_pandora::VertexVector vertexVector;
4900  lar_pandora::PFParticlesToVertices particlesToVertices;
4901  lar_pandora::LArPandoraHelper::CollectVertices(evt, fPandoraNuVertexModuleLabel, vertexVector, particlesToVertices);
4902 
4903  short nprim = 0;
4904  for (unsigned int n = 0; n < particleVector.size(); ++n) {
4905  const art::Ptr<recob::PFParticle> particle = particleVector.at(n);
4906  if(particle->IsPrimary()) nprim++;
4907  }
4908 
4909  if (nprim > kMaxVertices){
4910  // got this error? consider increasing kMaxClusters
4911  // (or ask for a redesign using vectors)
4912  mf::LogError("AnaRootParser:limits") << "event has " << nprim
4913  << " nu neutrino vertices, only kMaxVertices=" << kMaxVertices << " stored in tree";
4914  }
4915 
4916  fData->nnuvtx = nprim;
4917 
4918  short iv = 0;
4919  for (unsigned int n = 0; n < particleVector.size(); ++n) {
4920  const art::Ptr<recob::PFParticle> particle = particleVector.at(n);
4921  if(particle->IsPrimary()) {
4922  lar_pandora::PFParticlesToVertices::const_iterator vIter = particlesToVertices.find(particle);
4923  if (particlesToVertices.end() != vIter) {
4924  const lar_pandora::VertexVector &vertexVector = vIter->second;
4925  if (!vertexVector.empty()) {
4926  if (vertexVector.size() == 1) {
4927  const art::Ptr<recob::Vertex> vertex = *(vertexVector.begin());
4928  double xyz[3] = {0.0, 0.0, 0.0} ;
4929  vertex->XYZ(xyz);
4930  fData->nuvtxx[iv] = xyz[0];
4931  fData->nuvtxy[iv] = xyz[1];
4932  fData->nuvtxz[iv] = xyz[2];
4933  fData->nuvtxpdg[iv] = particle->PdgCode();
4934  iv++;
4935  }
4936  }
4937  }
4938  }
4939  }
4940 } // save PandoraNuVertexInfo
4941 
4942 if (fSaveClusterInfo){
4943  fData->nclusters = (int) NClusters;
4944  if (NClusters > kMaxClusters){
4945  // got this error? consider increasing kMaxClusters
4946  // (or ask for a redesign using vectors)
4947  mf::LogError("AnaRootParser:limits") << "event has " << NClusters
4948  << " clusters, only kMaxClusters=" << kMaxClusters << " stored in tree";
4949  }
4950  for(unsigned int ic=0; ic<NClusters;++ic){//loop over clusters
4951  art::Ptr<recob::Cluster> clusterholder(clusterListHandle, ic);
4952  const recob::Cluster& cluster = *clusterholder;
4953  fData->clusterId[ic] = cluster.ID();
4954  fData->clusterView[ic] = cluster.View();
4955  // View 3 in LArSoft corresponds to View 0 in real life (3m long channels). View 2 in LArSoft corresponds to View 1 in real life (1m long channels).
4956  if(fData->clusterView[ic] == 3) {fData->clusterView[ic] = 0;}
4957  if(fData->clusterView[ic] == 2) {fData->clusterView[ic] = 1;}
4958  fData->cluster_isValid[ic] = cluster.isValid();
4959  fData->cluster_StartCharge[ic] = cluster.StartCharge();
4960  fData->cluster_StartAngle[ic] = cluster.StartAngle();
4961  fData->cluster_EndCharge[ic] = cluster.EndCharge();
4962  fData->cluster_EndAngle[ic] = cluster.EndAngle();
4963  fData->cluster_Integral[ic] = cluster.Integral();
4964  fData->cluster_IntegralAverage[ic] = cluster.IntegralAverage();
4965  fData->cluster_SummedADC[ic] = cluster.SummedADC();
4966  fData->cluster_SummedADCaverage[ic] = cluster.SummedADCaverage();
4967  fData->cluster_MultipleHitDensity[ic] = cluster.MultipleHitDensity();
4968  fData->cluster_Width[ic] = cluster.Width();
4969  fData->cluster_NHits[ic] = cluster.NHits();
4970  fData->cluster_StartWire[ic] = cluster.StartWire();
4971  fData->cluster_StartTick[ic] = cluster.StartTick();
4972  fData->cluster_EndWire[ic] = cluster.EndWire();
4973  fData->cluster_EndTick[ic] = cluster.EndTick();
4974 
4975  // Transform StartWire and EndWire to channels
4976  if(fData->clusterView[ic] == 1){fData->cluster_StartWire[ic]+=320; fData->cluster_EndWire[ic] += 320;}
4977 
4978  //Cosmic Tagger information for cluster
4979  /* art::FindManyP<anab::CosmicTag> fmcct(clusterListHandle,evt,fCosmicClusterTaggerAssocLabel);
4980  if (fmcct.isValid()){
4981  fData->cluncosmictags_tagger[ic] = fmcct.at(ic).size();
4982  if (fmcct.at(ic).size()>0){
4983  if(fmcct.at(ic).size()>1)
4984  std::cerr << "\n Warning : more than one cosmic tag per cluster in module! assigning the first tag to the cluster" << fCosmicClusterTaggerAssocLabel;
4985  fData->clucosmicscore_tagger[ic] = fmcct.at(ic).at(0)->CosmicScore();
4986  fData->clucosmictype_tagger[ic] = fmcct.at(ic).at(0)->CosmicType();
4987  }
4988  } */
4989  }//end loop over clusters
4990 }//end fSaveClusterInfo
4991 
4992 if (fSaveFlashInfo){
4993  fData->no_flashes = (int) NFlashes;
4994  if (NFlashes > kMaxFlashes) {
4995  // got this error? consider increasing kMaxHits
4996  // (or ask for a redesign using vectors)
4997  mf::LogError("AnaRootParser:limits") << "event has " << NFlashes
4998  << " flashes, only kMaxFlashes=" << kMaxFlashes << " stored in tree";
4999  }
5000  for (size_t i = 0; i < NFlashes && i < kMaxFlashes ; ++i){//loop over hits
5001  fData->flash_time[i] = flashlist[i]->Time();
5002  fData->flash_pe[i] = flashlist[i]->TotalPE();
5003  fData->flash_ycenter[i] = flashlist[i]->YCenter();
5004  fData->flash_zcenter[i] = flashlist[i]->ZCenter();
5005  fData->flash_ywidth[i] = flashlist[i]->YWidth();
5006  fData->flash_zwidth[i] = flashlist[i]->ZWidth();
5007  fData->flash_timewidth[i] = flashlist[i]->TimeWidth();
5008  }
5009 }
5010 
5012  fData->no_ExternCounts = (int) NExternCounts;
5013  if (NExternCounts > kMaxExternCounts) {
5014  // got this error? consider increasing kMaxHits
5015  // (or ask for a redesign using vectors)
5016  mf::LogError("AnaRootParser:limits") << "event has " << NExternCounts
5017  << " External Counters, only kMaxExternCounts=" << kMaxExternCounts << " stored in tree";
5018  }
5019  for (size_t i = 0; i < NExternCounts && i < kMaxExternCounts ; ++i){//loop over hits
5020  fData->externcounts_time[i] = countlist[i]->GetTrigTime();
5021  fData->externcounts_id[i] = countlist[i]->GetTrigID();
5022  }
5023 }
5024 
5025 
5026 // Declare object-ID-to-PFParticleID maps so we can assign hasPFParticle and PFParticleID to the tracks, showers, vertices.
5027 std::map<Short_t, Short_t> trackIDtoPFParticleIDMap, vertexIDtoPFParticleIDMap, showerIDtoPFParticleIDMap;
5028 
5029 //Save PFParticle information
5030 if (fSavePFParticleInfo){
5031  AnaRootParserDataStruct::PFParticleDataStruct& PFParticleData = fData->GetPFParticleData();
5032  size_t NPFParticles = pfparticlelist.size();
5033 
5034  PFParticleData.SetMaxPFParticles(std::max(NPFParticles, (size_t) 1));
5035  PFParticleData.Clear(); // clear all the data
5036 
5037  PFParticleData.nPFParticles = (short) NPFParticles;
5038 
5039  // now set the tree addresses to the newly allocated memory;
5040  // this creates the tree branches in case they are not there yet
5042 
5043  if (NPFParticles > PFParticleData.GetMaxPFParticles()) {
5044  mf::LogError("AnaRootParser:limits") << "event has " << NPFParticles
5045  << " PFParticles, only "
5046  << PFParticleData.GetMaxPFParticles() << " stored in tree";
5047  }
5048 
5049  lar_pandora::PFParticleVector neutrinoPFParticles;
5050  lar_pandora::LArPandoraHelper::SelectNeutrinoPFParticles(pfparticlelist, neutrinoPFParticles);
5051  PFParticleData.pfp_numNeutrinos = neutrinoPFParticles.size();
5052 
5053  for (size_t i = 0; i < std::min(neutrinoPFParticles.size(), (size_t)kMaxNPFPNeutrinos); ++i) {
5054  PFParticleData.pfp_neutrinoIDs[i] = neutrinoPFParticles[i]->Self();
5055  }
5056 
5057  if (neutrinoPFParticles.size() > kMaxNPFPNeutrinos)
5058  std::cerr << "Warning: there were " << neutrinoPFParticles.size() << " reconstructed PFParticle neutrinos; only the first " << kMaxNPFPNeutrinos << " being stored in tree" << std::endl;
5059 
5060  // Get a PFParticle-to-vertex map.
5061  lar_pandora::VertexVector allPfParticleVertices;
5062  lar_pandora::PFParticlesToVertices pfParticleToVertexMap;
5063  lar_pandora::LArPandoraHelper::CollectVertices(evt, fPFParticleModuleLabel, allPfParticleVertices, pfParticleToVertexMap);
5064 
5065  // Get a PFParticle-to-track map.
5066  lar_pandora::TrackVector allPfParticleTracks;
5067  lar_pandora::PFParticlesToTracks pfParticleToTrackMap;
5068  lar_pandora::LArPandoraHelper::CollectTracks(evt, fPFParticleModuleLabel, allPfParticleTracks, pfParticleToTrackMap);
5069 
5070  // Get a PFParticle-to-shower map.
5071  lar_pandora::ShowerVector allPfParticleShowers;
5072  lar_pandora::PFParticlesToShowers pfParticleToShowerMap;
5073  lar_pandora::LArPandoraHelper::CollectShowers(evt, fPFParticleModuleLabel, allPfParticleShowers, pfParticleToShowerMap);
5074 
5075  for (size_t i = 0; i < NPFParticles && i < PFParticleData.GetMaxPFParticles() ; ++i){
5076  PFParticleData.pfp_selfID[i] = pfparticlelist[i]->Self();
5077  PFParticleData.pfp_isPrimary[i] = (Short_t)pfparticlelist[i]->IsPrimary();
5078  PFParticleData.pfp_numDaughters[i] = pfparticlelist[i]->NumDaughters();
5079  PFParticleData.pfp_parentID[i] = pfparticlelist[i]->Parent();
5080  PFParticleData.pfp_pdgCode[i] = pfparticlelist[i]->PdgCode();
5081  PFParticleData.pfp_isNeutrino[i] = lar_pandora::LArPandoraHelper::IsNeutrino(pfparticlelist[i]);
5082 
5083  // Set the daughter IDs.
5084  std::vector<size_t> daughterIDs = pfparticlelist[i]->Daughters();
5085 
5086  for (size_t j = 0; j < daughterIDs.size(); ++j)
5087  PFParticleData.pfp_daughterIDs[i][j] = daughterIDs[j];
5088 
5089  // Set the vertex ID.
5090  auto vertexMapIter = pfParticleToVertexMap.find(pfparticlelist[i]);
5091  if (vertexMapIter != pfParticleToVertexMap.end()) {
5092  lar_pandora::VertexVector pfParticleVertices = vertexMapIter->second;
5093 
5094  if (pfParticleVertices.size() > 1)
5095  std::cerr << "Warning: there was more than one vertex found for PFParticle with ID " << pfparticlelist[i]->Self() << ", storing only one" << std::endl;
5096 
5097  if (pfParticleVertices.size() > 0) {
5098  PFParticleData.pfp_vertexID[i] = pfParticleVertices.at(0)->ID();
5099  vertexIDtoPFParticleIDMap.insert(std::make_pair(pfParticleVertices.at(0)->ID(), pfparticlelist[i]->Self()));
5100  }
5101  }
5102  else
5103  std::cerr << "Warning: there was no vertex found for PFParticle with ID " << pfparticlelist[i]->Self() << std::endl;
5104 
5105  if (lar_pandora::LArPandoraHelper::IsTrack(pfparticlelist[i])){
5106  PFParticleData.pfp_isTrack[i] = 1;
5107 
5108  // Set the track ID.
5109  auto trackMapIter = pfParticleToTrackMap.find(pfparticlelist[i]);
5110  if (trackMapIter != pfParticleToTrackMap.end()) {
5111  lar_pandora::TrackVector pfParticleTracks = trackMapIter->second;
5112 
5113  if (pfParticleTracks.size() > 1)
5114  std::cerr << "Warning: there was more than one track found for PFParticle with ID " << pfparticlelist[i]->Self() << std::endl;
5115 
5116  if (pfParticleTracks.size() > 0) {
5117  PFParticleData.pfp_trackID[i] = pfParticleTracks.at(0)->ID();
5118  trackIDtoPFParticleIDMap.insert(std::make_pair(pfParticleTracks.at(0)->ID(), pfparticlelist[i]->Self()));
5119  }
5120  }
5121  else
5122  std::cerr << "Warning: there was no track found for track-like PFParticle with ID " << pfparticlelist[i]->Self() << std::endl;
5123  }
5124  else
5125  PFParticleData.pfp_isTrack[i] = 0;
5126 
5127  if (lar_pandora::LArPandoraHelper::IsShower(pfparticlelist[i])) {
5128  PFParticleData.pfp_isShower[i] = 1;
5129  // Set the shower ID.
5130  auto showerMapIter = pfParticleToShowerMap.find(pfparticlelist[i]);
5131  if (showerMapIter != pfParticleToShowerMap.end()) {
5132  lar_pandora::ShowerVector pfParticleShowers = showerMapIter->second;
5133 
5134  if (pfParticleShowers.size() > 1)
5135  std::cerr << "Warning: there was more than one shower found for PFParticle with ID " << pfparticlelist[i]->Self() << std::endl;
5136 
5137  if (pfParticleShowers.size() > 0) {
5138  PFParticleData.pfp_showerID[i] = pfParticleShowers.at(0)->ID();
5139  showerIDtoPFParticleIDMap.insert(std::make_pair(pfParticleShowers.at(0)->ID(), pfparticlelist[i]->Self()));
5140  }
5141  }
5142  else
5143  std::cerr << "Warning: there was no shower found for shower-like PFParticle with ID " << pfparticlelist[i]->Self() << std::endl;
5144  }
5145  else
5146  PFParticleData.pfp_isShower[i] = 0;
5147 
5148  // Set the cluster IDs.
5149  auto clusterMapIter = pfParticleToClusterMap.find(pfparticlelist[i]);
5150  if (clusterMapIter != pfParticleToClusterMap.end()) {
5151  lar_pandora::ClusterVector pfParticleClusters = clusterMapIter->second;
5152  PFParticleData.pfp_numClusters[i] = pfParticleClusters.size();
5153 
5154  for (size_t j = 0; j < pfParticleClusters.size(); ++j)
5155  PFParticleData.pfp_clusterIDs[i][j] = pfParticleClusters[j]->ID();
5156  }
5157  //else
5158  // std::cerr << "Warning: there were no clusters found for PFParticle with ID " << pfparticlelist[i]->Self() << std::endl;
5159  }
5160 } // if fSavePFParticleInfo
5161 
5162 if (fSaveShowerInfo){
5163 
5164  // fill data from all the shower algorithms
5165  for (size_t iShowerAlgo = 0; iShowerAlgo < NShowerAlgos; ++iShowerAlgo) {
5166  AnaRootParserDataStruct::ShowerDataStruct& ShowerData
5167  = fData->GetShowerData(iShowerAlgo);
5168  std::vector<recob::Shower> const* pShowers = showerList[iShowerAlgo];
5169  art::Handle< std::vector<recob::Shower> > showerHandle = showerListHandle[iShowerAlgo];
5170 
5171  if (pShowers){
5172  FillShowers(ShowerData, *pShowers, fSavePFParticleInfo, showerIDtoPFParticleIDMap);
5173 
5174  if(fMVAPIDShowerModuleLabel[iShowerAlgo].size()){
5175  art::FindOneP<anab::MVAPIDResult> fmvapid(showerHandle, evt, fMVAPIDShowerModuleLabel[iShowerAlgo]);
5176  if(fmvapid.isValid()){
5177  for(unsigned int iShower=0;iShower<showerHandle->size();++iShower){
5178  const art::Ptr<anab::MVAPIDResult> pid = fmvapid.at(iShower);
5179  ShowerData.shwr_pidmvamu[iShower] = pid->mvaOutput.at("muon");
5180  ShowerData.shwr_pidmvae[iShower] = pid->mvaOutput.at("electron");
5181  ShowerData.shwr_pidmvapich[iShower] = pid->mvaOutput.at("pich");
5182  ShowerData.shwr_pidmvaphoton[iShower] = pid->mvaOutput.at("photon");
5183  ShowerData.shwr_pidmvapr[iShower] = pid->mvaOutput.at("proton");
5184  }
5185  } // fmvapid.isValid()
5186  }
5187  }
5188  else ShowerData.MarkMissing(fTree); // tree should reflect lack of data
5189  } // for iShowerAlgo
5190 
5191 } // if fSaveShowerInfo
5192 
5193 //track information for multiple trackers
5194 if (fSaveTrackInfo) {
5195 
5196  // Get Geometry
5198 
5199  for (unsigned int iTracker=0; iTracker < NTrackers; ++iTracker){
5200  AnaRootParserDataStruct::TrackDataStruct& TrackerData = fData->GetTrackerData(iTracker);
5201 
5202  size_t NTracks = tracklist[iTracker].size();
5203 
5204  // allocate enough space for this number of tracks (but at least for one of them!)
5205  TrackerData.SetMaxTracks(std::max(NTracks, (size_t) 1));
5206  TrackerData.Clear(); // clear all the data
5207 
5208  TrackerData.ntracks = (int) NTracks;
5209  /*
5210  //First loop over tracks to get array sizes (number of hits in each track)
5211  for(size_t iTrk=0; iTrk < NTracks; ++iTrk){//loop over tracks
5212  art::FindMany<anab::Calorimetry> fmcaltemp(trackListHandle[iTracker], evt, fCalorimetryModuleLabel[iTracker]);
5213  if (fmcaltemp.isValid()){
5214  std::vector<const anab::Calorimetry*> calostemp = fmcaltemp.at(iTrk);
5215  for (size_t ical = 0; ical<calostemp.size(); ++ical){
5216  if (!calostemp[ical]) continue;
5217  if (!calostemp[ical]->PlaneID().isValid) continue;
5218  int planenumtemp = calostemp[ical]->PlaneID().Plane;
5219  if (planenumtemp<0||planenumtemp>2) continue;
5220  //For now make the second argument as 13 for muons.
5221  // const size_t NHitsTemp = calostemp[ical] -> dEdx().size();
5222  // TrackerData.NHitsInAllTracks+=(int) NHitsTemp;
5223  // fData->NHitsInAllTracks+=(int) NHitsTemp;
5224  } // for calorimetry info
5225  } // if has calorimetry info
5226  }//loop over tracks
5227  */
5228 
5229  // now set the tree addresses to the newly allocated memory;
5230  // this creates the tree branches in case they are not there yet
5231  SetTrackerAddresses(iTracker);
5232  if (NTracks > TrackerData.GetMaxTracks()) {
5233  // got this error? it might be a bug,
5234  // since we are supposed to have allocated enough space to fit all tracks
5235  mf::LogError("AnaRootParser:limits") << "event has " << NTracks
5236  << " " << fTrackModuleLabel[iTracker] << " tracks, only "
5237  << TrackerData.GetMaxTracks() << " stored in tree";
5238  }
5239 
5240  //call the track momentum algorithm that gives you momentum based on track range
5241  // - change the minimal track length requirement to 50 cm
5243 
5244  recob::MCSFitResult res;
5245 
5246  int HitIterator=0;
5247  int HitIterator2=0;
5248 
5249  int trueID = -9999;
5250  float maxe = -9999.;
5251  float purity = -9999.;
5252 
5253  for(size_t iTrk=0; iTrk < NTracks; ++iTrk){//loop over tracks
5254 
5255  //save t0 from reconstructed flash track matching for every track
5256  art::FindManyP<anab::T0> fmt0(trackListHandle[iTracker],evt,fFlashT0FinderLabel[iTracker]);
5257  if (fmt0.isValid()){
5258  if(fmt0.at(iTrk).size()>0){
5259  if(fmt0.at(iTrk).size()>1)
5260  std::cerr << "\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" << fFlashT0FinderLabel[iTracker];
5261  TrackerData.trkflashT0[iTrk] = fmt0.at(iTrk).at(0)->Time();
5262  }
5263  }
5264 
5265  //save t0 from reconstructed flash track matching for every track
5266  art::FindManyP<anab::T0> fmmct0(trackListHandle[iTracker],evt,fMCT0FinderLabel[iTracker]);
5267  if (fmmct0.isValid()){
5268  if(fmmct0.at(iTrk).size()>0){
5269  if(fmmct0.at(iTrk).size()>1)
5270  std::cerr << "\n Warning : more than one cosmic tag per track in module! assigning the first tag to the cluster" << fMCT0FinderLabel[iTracker];
5271  TrackerData.trktrueT0[iTrk] = fmmct0.at(iTrk).at(0)->Time();
5272  }
5273  }
5274 
5275  //Cosmic Tagger information
5276  art::FindManyP<anab::CosmicTag> fmct(trackListHandle[iTracker],evt,fCosmicTaggerAssocLabel[iTracker]);
5277  if (fmct.isValid()){
5278  TrackerData.trkncosmictags_tagger[iTrk] = fmct.at(iTrk).size();
5279  if (fmct.at(iTrk).size()>0){
5280  if(fmct.at(iTrk).size()>1)
5281  std::cerr << "\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" << fCosmicTaggerAssocLabel[iTracker];
5282  TrackerData.trkcosmicscore_tagger[iTrk] = fmct.at(iTrk).at(0)->CosmicScore();
5283  TrackerData.trkcosmictype_tagger[iTrk] = fmct.at(iTrk).at(0)->CosmicType();
5284  }
5285  }
5286 
5287  //Containment Tagger information
5288  art::FindManyP<anab::CosmicTag> fmcnt(trackListHandle[iTracker],evt,fContainmentTaggerAssocLabel[iTracker]);
5289  if (fmcnt.isValid()){
5290  TrackerData.trkncosmictags_containmenttagger[iTrk] = fmcnt.at(iTrk).size();
5291  if (fmcnt.at(iTrk).size()>0){
5292  if(fmcnt.at(iTrk).size()>1)
5293  std::cerr << "\n Warning : more than one containment tag per track in module! assigning the first tag to the track" << fContainmentTaggerAssocLabel[iTracker];
5294  TrackerData.trkcosmicscore_containmenttagger[iTrk] = fmcnt.at(iTrk).at(0)->CosmicScore();
5295  TrackerData.trkcosmictype_containmenttagger[iTrk] = fmcnt.at(iTrk).at(0)->CosmicType();
5296  }
5297  }
5298 
5299  //Flash match compatibility information
5300  //Unlike CosmicTagger, Flash match doesn't assign a cosmic tag for every track. For those tracks, AnaRootParser initializes them with -999 or -9999
5301  art::FindManyP<anab::CosmicTag> fmbfm(trackListHandle[iTracker],evt,fFlashMatchAssocLabel[iTracker]);
5302  if (fmbfm.isValid()){
5303  TrackerData.trkncosmictags_flashmatch[iTrk] = fmbfm.at(iTrk).size();
5304  if (fmbfm.at(iTrk).size()>0){
5305  if(fmbfm.at(iTrk).size()>1)
5306  std::cerr << "\n Warning : more than one cosmic tag per track in module! assigning the first tag to the track" << fFlashMatchAssocLabel[iTracker];
5307  TrackerData.trkcosmicscore_flashmatch[iTrk] = fmbfm.at(iTrk).at(0)->CosmicScore();
5308  TrackerData.trkcosmictype_flashmatch[iTrk] = fmbfm.at(iTrk).at(0)->CosmicType();
5309  //std::cout<<"\n"<<evt.event()<<"\t"<<iTrk<<"\t"<<fmbfm.at(iTrk).at(0)->CosmicScore()<<"\t"<<fmbfm.at(iTrk).at(0)->CosmicType();
5310  }
5311  }
5312 
5313  art::Ptr<recob::Track> ptrack(trackListHandle[iTracker], iTrk);
5314  const recob::Track& track = *ptrack;
5315 
5316  TVector3 pos, dir_start, dir_end, end;
5317  TVector3 dir_start_flipped, dir_end_flipped;
5318  double tlen = 0., mom = 0.;
5319  int TrackID = -1;
5320 
5321  int ntraj = track.NumberTrajectoryPoints();
5322  if (ntraj > 0) {
5323  pos = track.Vertex<TVector3>();
5324  dir_start = track.VertexDirection<TVector3>();
5325  dir_end = track.EndDirection<TVector3>();
5326  end = track.End<TVector3>();
5327 
5328  dir_start_flipped.SetXYZ(dir_start.Z(), dir_start.Y(), dir_start.X());
5329  dir_end_flipped.SetXYZ(dir_end.Z(), dir_end.Y(), dir_end.X());
5330 
5331  tlen = length(track);
5332  if(track.NumberTrajectoryPoints() > 0)
5333  mom = track.VertexMomentum();
5334  // fill non-bezier-track reco branches
5335  TrackID = track.ID();
5336 
5337  double theta_xz = std::atan2(dir_start.X(), dir_start.Z());
5338  double theta_yz = std::atan2(dir_start.Y(), dir_start.Z());
5339  double dpos = bdist(pos); // FIXME - Passing an uncorrected position....
5340  double dend = bdist(end); // FIXME - Passing an uncorrected position....
5341 
5342  TrackerData.trkId[iTrk] = TrackID;
5343  TrackerData.trkstartx[iTrk] = pos.X();
5344  TrackerData.trkstarty[iTrk] = pos.Y();
5345  TrackerData.trkstartz[iTrk] = pos.Z();
5346  TrackerData.trkstartd[iTrk] = dpos;
5347  TrackerData.trkendx[iTrk] = end.X();
5348  TrackerData.trkendy[iTrk] = end.Y();
5349  TrackerData.trkendz[iTrk] = end.Z();
5350  TrackerData.trkendd[iTrk] = dend;
5351  TrackerData.trkstarttheta[iTrk] = (180.0/3.14159)*dir_start_flipped.Theta();
5352  TrackerData.trkstartphi[iTrk] = (180.0/3.14159)*dir_start_flipped.Phi();
5353  TrackerData.trkstartdirectionx[iTrk] = dir_start.X();
5354  TrackerData.trkstartdirectiony[iTrk] = dir_start.Y();
5355  TrackerData.trkstartdirectionz[iTrk] = dir_start.Z();
5356 
5357  if(fLogLevel >= 2)
5358  {
5359  std::cout << std::endl;
5360  std::cout << "start.X(): " << pos.X() << "\t" << "start.Y(): " << pos.Y() << "\t" << "start.Z(): " << pos.Z() << std::endl;
5361  std::cout << "end.X(): " << end.X() << "\t" << "end.Y(): " << end.Y() << "\t" << "end.Z(): " << end.Z() << std::endl;
5362  std::cout << "dir_start.X(): " << dir_start.X() << "\t" << "dir_start.Y(): " << dir_start.Y() << "\t" << "dir_start.Z(): " << dir_start.Z() << std::endl;
5363  std::cout << "dir_end.X(): " << dir_end.X() << "\t" << "dir_end.Y(): " << dir_end.Y() << "\t" << "dir_end.Z(): " << dir_end.Z() << std::endl;
5364  std::cout << "dir_start_flipped.Theta(): " << (180.0/3.14159)*dir_start_flipped.Theta() << "\t" << "dir_start_flipped.Phi(): " << (180.0/3.14159)*dir_start_flipped.Phi() << std::endl;
5365  std::cout << "dir_end_flipped.Theta(): " << (180.0/3.14159)*dir_end_flipped.Theta() << "\t" << "dir_end_flipped.Phi(): " << (180.0/3.14159)*dir_end_flipped.Phi() << std::endl;
5366  std::cout << std::endl;
5367  }
5368 
5369  TrackerData.trkendtheta[iTrk] = (180.0/3.14159)*dir_end_flipped.Theta();
5370  TrackerData.trkendphi[iTrk] = (180.0/3.14159)*dir_end_flipped.Phi();
5371  TrackerData.trkenddirectionx[iTrk] = dir_end.X();
5372  TrackerData.trkenddirectiony[iTrk] = dir_end.Y();
5373  TrackerData.trkenddirectionz[iTrk] = dir_end.Z();
5374 
5375  TrackerData.trkthetaxz[iTrk] = theta_xz;
5376  TrackerData.trkthetayz[iTrk] = theta_yz;
5377  TrackerData.trkmom[iTrk] = mom;
5378  TrackerData.trkchi2PerNDF[iTrk] = track.Chi2PerNdof();
5379  TrackerData.trkNDF[iTrk] = track.Ndof();
5380  TrackerData.trklen[iTrk] = tlen;
5381  TrackerData.trklenstraightline[iTrk] = sqrt(pow(pos.X()-end.X(),2) + pow(pos.Y()-end.Y(),2) + pow(pos.Z()-end.Z(),2));
5382  TrackerData.trkmomrange[iTrk] = trkm.GetTrackMomentum(tlen,13);
5383  TrackerData.trkmommschi2[iTrk] = trkm.GetMomentumMultiScatterChi2(ptrack);
5384  TrackerData.trkmommsllhd[iTrk] = trkm.GetMomentumMultiScatterLLHD(ptrack);
5385 
5386  //uBoone MCS
5387  res = fMCSFitter.fitMcs(*ptrack);
5388  TrackerData.trkmommscmic[iTrk] = res.bestMomentum();
5389  TrackerData.trkmommscfwd[iTrk] = res.fwdMomentum();
5390  TrackerData.trkmommscbwd[iTrk] = res.bwdMomentum();
5391  TrackerData.trkmommscllfwd[iTrk] = res.fwdLogLikelihood();
5392  TrackerData.trkmommscllbwd[iTrk] = res.bwdLogLikelihood();
5393 
5394 
5395  if (fSavePFParticleInfo) {
5396  auto mapIter = trackIDtoPFParticleIDMap.find(TrackID);
5397  if (mapIter != trackIDtoPFParticleIDMap.end()) {
5398  // This track has a corresponding PFParticle.
5399  TrackerData.trkhasPFParticle[iTrk] = 1;
5400  TrackerData.trkPFParticleID[iTrk] = mapIter->second;
5401  }
5402  else
5403  TrackerData.trkhasPFParticle[iTrk] = 0;
5404  }
5405 
5406  } // if we have trajectory
5407 
5408  // find vertices associated with this track
5409  /*
5410  art::FindMany<recob::Vertex> fmvtx(trackListHandle[iTracker], evt, fVertexModuleLabel[iTracker]);
5411  if(fmvtx.isValid()) {
5412  std::vector<const recob::Vertex*> verts = fmvtx.at(iTrk);
5413  // should have two at most
5414  for(size_t ivx = 0; ivx < verts.size(); ++ivx) {
5415  verts[ivx]->XYZ(xyz);
5416  // find the vertex in TrackerData to get the index
5417  short theVtx = -1;
5418  for(short jvx = 0; jvx < TrackerData.nvtx; ++jvx) {
5419  if(TrackerData.vtx[jvx][2] == xyz[2]) {
5420  theVtx = jvx;
5421  break;
5422  }
5423  } // jvx
5424  // decide if it should be assigned to the track Start or End.
5425  // A simple dz test should suffice
5426  if(fabs(xyz[2] - TrackerData.trkstartz[iTrk]) <
5427  fabs(xyz[2] - TrackerData.trkendz[iTrk])) {
5428  TrackerData.trksvtxid[iTrk] = theVtx;
5429  } else {
5430  TrackerData.trkevtxid[iTrk] = theVtx;
5431  }
5432  } // vertices
5433  } // fmvtx.isValid()
5434  */
5435 
5436 
5437  /* //commented out because now have several Vertices
5438  Float_t minsdist = 10000;
5439  Float_t minedist = 10000;
5440  for (int ivx = 0; ivx < NVertices && ivx < kMaxVertices; ++ivx){
5441  Float_t sdist = sqrt(pow(TrackerData.trkstartx[iTrk]-VertexData.vtxx[ivx],2)+
5442  pow(TrackerData.trkstarty[iTrk]-VertexData.vtxy[ivx],2)+
5443  pow(TrackerData.trkstartz[iTrk]-VertexData.vtxz[ivx],2));
5444  Float_t edist = sqrt(pow(TrackerData.trkendx[iTrk]-VertexData.vtxx[ivx],2)+
5445  pow(TrackerData.trkendy[iTrk]-VertexData.vtxy[ivx],2)+
5446  pow(TrackerData.trkendz[iTrk]-VertexData.vtxz[ivx],2));
5447  if (sdist<minsdist){
5448  minsdist = sdist;
5449  if (minsdist<10) TrackerData.trksvtxid[iTrk] = ivx;
5450  }
5451  if (edist<minedist){
5452  minedist = edist;
5453  if (minedist<10) TrackerData.trkevtxid[iTrk] = ivx;
5454  }
5455  }*/
5456 
5457  // find particle ID info
5458  /*
5459  art::FindMany<anab::ParticleID> fmpid(trackListHandle[iTracker], evt, fParticleIDModuleLabel[iTracker]);
5460  if(fmpid.isValid()) {
5461  std::vector<const anab::ParticleID*> pids = fmpid.at(iTrk);
5462  //if(pids.size() > 1) {
5463  //mf::LogError("AnaRootParser:limits")
5464  //<< "the " << fTrackModuleLabel[iTracker] << " track #" << iTrk
5465  //<< " has " << pids.size()
5466  //<< " set of ParticleID variables. Only one stored in the tree";
5467  //}
5468  for (size_t ipid = 0; ipid < pids.size(); ++ipid){
5469  if (!pids[ipid]->PlaneID().isValid) continue;
5470  int planenum = pids[ipid]->PlaneID().Plane;
5471  if (planenum<0||planenum>2) continue;
5472  TrackerData.trkpidpdg[iTrk][planenum] = pids[ipid]->Pdg();
5473  TrackerData.trkpidchi[iTrk][planenum] = pids[ipid]->MinChi2();
5474  TrackerData.trkpidchipr[iTrk][planenum] = pids[ipid]->Chi2Proton();
5475  TrackerData.trkpidchika[iTrk][planenum] = pids[ipid]->Chi2Kaon();
5476  TrackerData.trkpidchipi[iTrk][planenum] = pids[ipid]->Chi2Pion();
5477  TrackerData.trkpidchimu[iTrk][planenum] = pids[ipid]->Chi2Muon();
5478  TrackerData.trkpidpida[iTrk][planenum] = pids[ipid]->PIDA();
5479  }
5480  } // fmpid.isValid()
5481  */
5482  if(fMVAPIDTrackModuleLabel[iTracker].size()){
5483  art::FindOneP<anab::MVAPIDResult> fmvapid(trackListHandle[iTracker], evt, fMVAPIDTrackModuleLabel[iTracker]);
5484  if(fmvapid.isValid()) {
5485  const art::Ptr<anab::MVAPIDResult> pid = fmvapid.at(iTrk);
5486  TrackerData.trkpidmvamu[iTrk] = pid->mvaOutput.at("muon");
5487  TrackerData.trkpidmvae[iTrk] = pid->mvaOutput.at("electron");
5488  TrackerData.trkpidmvapich[iTrk] = pid->mvaOutput.at("pich");
5489  TrackerData.trkpidmvaphoton[iTrk] = pid->mvaOutput.at("photon");
5490  TrackerData.trkpidmvapr[iTrk] = pid->mvaOutput.at("proton");
5491  } // fmvapid.isValid()
5492  }
5493 
5494 
5495  art::FindManyP<recob::Hit, recob::TrackHitMeta> fmthm(trackListHandle[iTracker], evt, "pmtrack");
5496 
5497 // if (fmthm.isValid()){
5498  auto vhit = fmthm.at(iTrk);
5499  auto vmeta = fmthm.data(iTrk);
5500 
5501  TrackerData.NHitsPerTrack[iTrk] = vhit.size();
5502  art::FindManyP<recob::SpacePoint> fmspts(vhit, evt, "pmtrack");
5503 
5504  int NHitsView0 = 0;
5505  int NHitsView1 = 0;
5506 
5507  if(fLogLevel >= 2)
5508  {
5509  std::cout << "track.NumberTrajectoryPoints(): " << track.NumberTrajectoryPoints() << std::endl;
5510  std::cout << "track.NPoints(): " << track.NPoints() << std::endl;
5511  std::cout << "vhit.size(): " << vhit.size() << std::endl;
5512  std::cout << "vmeta.size(): " << vmeta.size() << std::endl;
5513  std::cout << "fmspts.size(): " << fmspts.size() << std::endl;
5514  }
5515 
5516  for (unsigned int h = 0; h < vhit.size(); h++)
5517  {
5518  //corrected pitch
5519  double angleToVert = geomhandle->WireAngleToVertical(vhit[h]->View(), vhit[h]->WireID().TPC, vhit[h]->WireID().Cryostat) - 0.5*::util::pi<>();
5520  const TVector3& dir = tracklist[iTracker][iTrk]->DirectionAtPoint<TVector3>(h);
5521  const TVector3& loc = tracklist[iTracker][iTrk]->LocationAtPoint<TVector3>(h);
5522  double cosgamma = std::abs(std::sin(angleToVert)*dir.Y() + std::cos(angleToVert)*dir.Z());
5523 
5524 
5525  TrackerData.hittrklocaltrackdirectionx[HitIterator2] = dir.X();
5526  TrackerData.hittrklocaltrackdirectiony[HitIterator2] = dir.Y();
5527  TrackerData.hittrklocaltrackdirectionz[HitIterator2] = dir.Z();
5528 
5529 
5530  //XYZ
5531  std::vector< art::Ptr<recob::SpacePoint> > sptv = fmspts.at(h);
5532  TrackerData.hittrkx[HitIterator2] = sptv[0]->XYZ()[0];
5533  TrackerData.hittrky[HitIterator2] = sptv[0]->XYZ()[1];
5534  TrackerData.hittrkz[HitIterator2] = sptv[0]->XYZ()[2];
5535 
5536  TVector3 dir_hit_flipped;
5537  dir_hit_flipped.SetXYZ(dir.Z(), dir.Y(), dir.X());
5538 
5539  TrackerData.hittrklocaltrackdirectiontheta[HitIterator2] = (180.0/3.14159)*dir_hit_flipped.Theta();
5540  TrackerData.hittrklocaltrackdirectionphi[HitIterator2] = (180.0/3.14159)*dir_hit_flipped.Phi();
5541 
5542  //dx
5543  if(vhit[h]->WireID().Plane == 0) TrackerData.hittrkpitchC[HitIterator2] = std::abs(geomhandle->WirePitch()/( sin(dir_hit_flipped.Theta())*sin(dir_hit_flipped.Phi()) ));
5544  if(vhit[h]->WireID().Plane == 1) TrackerData.hittrkpitchC[HitIterator2] = std::abs(geomhandle->WirePitch()/( sin(dir_hit_flipped.Theta())*cos(dir_hit_flipped.Phi()) ));
5545 
5546  TrackerData.hittrkds[HitIterator2] = vmeta[h]->Dx();
5547 
5548  if(fLogLevel >= 2)
5549  {
5550  std::cout << "pos.X(): " << sptv[0]->XYZ()[0] << "\t" << "pos.Y(): " << sptv[0]->XYZ()[1] << "\t" << "pos.Z(): " << sptv[0]->XYZ()[2] << std::endl;
5551  std::cout << "pos2.X(): " << loc.X() << "\t" << "pos2.Y(): " << loc.Y() << "\t" << "pos2.Z(): " << loc.Z() << std::endl;
5552  std::cout << "dir.X(): " << dir.X() << "\t" << "dir.Y(): " << dir.Y() << "\t" << "dir.Z(): " << dir.Z() << std::endl;
5553  std::cout << "dir_hit_flipped.Theta(): " << (180.0/3.14159)*dir_hit_flipped.Theta() << "\t" << "dir_hit_flipped.Phi(): " << (180.0/3.14159)*dir_hit_flipped.Phi() << std::endl;
5554  std::cout << "vmeta[h]->Dx(): " << vmeta[h]->Dx() << std::endl;
5555  std::cout << "Dx corrected pitch old: " << geomhandle->WirePitch()/cosgamma << std::endl;
5556  std::cout << "Dx corrected pitch new: " << TrackerData.hittrkpitchC[HitIterator2] << std::endl;
5557  std::cout << "view: " << vhit[h]->WireID().Plane << std::endl;
5558  }
5559 
5560  //hit variables
5561  TrackerData.hittrkchannel[HitIterator2] = vhit[h]->Channel();
5562  TrackerData.hittrktpc[HitIterator2] = vhit[h]->WireID().TPC;
5563  TrackerData.hittrkview[HitIterator2] = vhit[h]->WireID().Plane;
5564  TrackerData.hittrkwire[HitIterator2] = vhit[h]->WireID().Wire;
5565  TrackerData.hittrkpeakT[HitIterator2] = vhit[h]->PeakTime();
5566  TrackerData.hittrkchargeintegral[HitIterator2] = vhit[h]->Integral();
5567  TrackerData.hittrkph[HitIterator2] = vhit[h]->PeakAmplitude();
5568  TrackerData.hittrkchargesum[HitIterator2] = vhit[h]->SummedADC();
5569  TrackerData.hittrkstarT[HitIterator2] = vhit[h]->StartTick();
5570  TrackerData.hittrkendT[HitIterator2] = vhit[h]->EndTick();
5571  TrackerData.hittrkrms[HitIterator2] = vhit[h]->RMS();
5572  TrackerData.hittrkgoddnessofFit[HitIterator2] = vhit[h]->GoodnessOfFit();
5573  TrackerData.hittrkmultiplicity[HitIterator2] = vhit[h]->Multiplicity();
5574 
5575  //quantities from backtracker are different from the real value in MC
5576  if( fIsMC )
5577  HitsBackTrack(clockData, vhit[h], trueID, maxe, purity );
5578 
5579  TrackerData.hittrktrueID[HitIterator2] = trueID;
5580  TrackerData.hittrktrueEnergyMax[HitIterator2] = maxe;
5581  TrackerData.hittrktrueEnergyFraction[HitIterator2] = purity;
5582 
5583  HitIterator2++;
5584 
5585  if(vhit[h]->WireID().Plane == 0) NHitsView0++;
5586  if(vhit[h]->WireID().Plane == 1) NHitsView1++;
5587  }
5588  TrackerData.ntrkhitsperview[iTrk][0] = NHitsView0;
5589  TrackerData.ntrkhitsperview[iTrk][1] = NHitsView1;
5590 
5591 // }
5592 
5593 /*
5594  std::cout << "tracklist[iTracker][iTrk]->NumberTrajectoryPoints(): " << tracklist[iTracker][iTrk]->NumberTrajectoryPoints() << std::endl;
5595  for(size_t itp = 0; itp < tracklist[iTracker][iTrk]->NumberTrajectoryPoints(); ++itp)
5596  {
5597  const TVector3& pos = tracklist[iTracker][iTrk]->LocationAtPoint(itp);
5598  }
5599 */
5600 //
5601 // art::FindManyP<recob::Hit> fmht(trackListHandle[iTracker], evt, fTrackModuleLabel);
5602 // std::vector< art::Ptr<recob::Hit> > allHits = fmht.at(trkIter);
5603 // art::FindManyP<recob::SpacePoint> fmspts(allHits, evt, fSpacePointModuleLabel);
5604 //
5605 /*
5606  art::FindManyP<recob::SpacePoint> fmspts(vhit, evt, "pmtrack");
5607  for (size_t h = 0; h < vhit.size(); ++h)
5608  {
5609  std::vector< art::Ptr<recob::SpacePoint> > sptv = fmspts.at(h);
5610 
5611  for (size_t j = 0; j < sptv.size(); ++j)
5612  {
5613  std::cout << "sptv[j]->XYZ()[0]: " << sptv[j]->XYZ()[0] << std::endl;
5614  std::cout << "sptv[j]->XYZ()[1]: " << sptv[j]->XYZ()[1] << std::endl;
5615  std::cout << "sptv[j]->XYZ()[2]: " << sptv[j]->XYZ()[2] << std::endl;
5616  std::cout << "sptv[j]->ErrXYZ()[0]: " << sptv[j]->ErrXYZ()[0] << std::endl;
5617  std::cout << "sptv[j]->ErrXYZ()[1]: " << sptv[j]->ErrXYZ()[1] << std::endl;
5618  std::cout << "sptv[j]->ErrXYZ()[2]: " << sptv[j]->ErrXYZ()[2] << std::endl;
5619  }
5620  }
5621 */
5622 //
5623 
5624 
5625 /////////////////////
5626  art::FindMany<anab::Calorimetry> fmcal(trackListHandle[iTracker], evt, fCalorimetryModuleLabel[iTracker]);
5627  if (fmcal.isValid()){
5628  std::vector<const anab::Calorimetry*> calos = fmcal.at(iTrk);
5629  if (calos.size() > TrackerData.GetMaxPlanesPerTrack(iTrk)) {
5630  // if you get this message, there is probably a bug somewhere since
5631  // the calorimetry planes should be 3.
5632  mf::LogError("AnaRootParser:limits")
5633  << "the " << fTrackModuleLabel[iTracker] << " track #" << iTrk
5634  << " has " << calos.size() << " planes for calorimetry , only "
5635  << TrackerData.GetMaxPlanesPerTrack(iTrk) << " stored in tree";
5636  }
5637 
5638  // for (size_t ical = 0; ical<calos.size(); ++ical){
5639  for (size_t ical = calos.size() - 1; ical <= 1 ; --ical){ //reverse order so that we access info on plane 0 (which is view 0 in real life) first
5640  if (!calos[ical]) continue;
5641  if (!calos[ical]->PlaneID().isValid) continue;
5642  int planenum = calos[ical]->PlaneID().Plane;
5643  if (planenum<0||planenum>1) continue; //only two planes (0 and 1) in dual phase
5644  TrackerData.trkke[iTrk][planenum] = calos[ical]->KineticEnergy();
5645  TrackerData.trkrange[iTrk][planenum] = calos[ical]->Range();
5646  //For now make the second argument as 13 for muons.
5647  TrackerData.trkpitchc[iTrk][planenum]= calos[ical] -> TrkPitchC();
5648  const size_t NHits = calos[ical] -> dEdx().size();
5649 // TrackerData.ntrkhitsperview[iTrk][planenum] = (int) NHits;
5650  if (NHits > TrackerData.GetMaxHitsPerTrack(iTrk, planenum)) {
5651  // if you get this error, you'll have to increase kMaxTrackHits
5652  mf::LogError("AnaRootParser:limits")
5653  << "the " << fTrackModuleLabel[iTracker] << " track #" << iTrk
5654  << " has " << NHits << " hits on calorimetry plane #" << planenum
5655  <<", only "
5656  << TrackerData.GetMaxHitsPerTrack(iTrk, planenum) << " stored in tree";
5657  }
5658  if (!isCosmics){
5659  for(size_t iTrkHit = 0; iTrkHit < NHits && iTrkHit < TrackerData.GetMaxHitsPerTrack(iTrk, planenum); ++iTrkHit) {
5660  TrackerData.trkdedx[iTrk][planenum][iTrkHit] = (calos[ical] -> dEdx())[iTrkHit];
5661  TrackerData.trkdqdx[iTrk][planenum][iTrkHit] = (calos[ical] -> dQdx())[iTrkHit];
5662  TrackerData.trkresrg[iTrk][planenum][iTrkHit] = (calos[ical] -> ResidualRange())[iTrkHit];
5663  TrackerData.trktpc[iTrk][planenum][iTrkHit] = (calos[ical] -> PlaneID()).TPC;
5664  const auto& TrkPos = (calos[ical] -> XYZ())[iTrkHit];
5665  auto& TrkXYZ = TrackerData.trkxyz[iTrk][planenum][iTrkHit];
5666  TrkXYZ[0] = TrkPos.X();
5667  TrkXYZ[1] = TrkPos.Y();
5668  TrkXYZ[2] = TrkPos.Z();
5669  //TrackerData.trkdedx2.push_back((calos[ical] -> dEdx())[iTrkHit]);
5670  TrackerData.trkdedx2[HitIterator] = (calos[ical] -> dEdx())[iTrkHit];
5671  TrackerData.trkdqdx2[HitIterator] = (calos[ical] -> dQdx())[iTrkHit];
5672  TrackerData.trktpc2[HitIterator] = (calos[ical] -> PlaneID()).TPC;
5673  TrackerData.trkx2[HitIterator] = TrkPos.X();
5674  TrackerData.trky2[HitIterator] = TrkPos.Y();
5675  TrackerData.trkz2[HitIterator] = TrkPos.Z();
5676  HitIterator++;
5677  } // for track hits
5678  }
5679  } // for calorimetry info
5680 
5681 
5682  //best plane
5683  if(TrackerData.ntrkhitsperview[iTrk][0] > TrackerData.ntrkhitsperview[iTrk][1] && TrackerData.ntrkhitsperview[iTrk][0] > TrackerData.ntrkhitsperview[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 0;
5684  else if(TrackerData.ntrkhitsperview[iTrk][1] > TrackerData.ntrkhitsperview[iTrk][0] && TrackerData.ntrkhitsperview[iTrk][1] > TrackerData.ntrkhitsperview[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 1;
5685  else if(TrackerData.ntrkhitsperview[iTrk][2] > TrackerData.ntrkhitsperview[iTrk][0] && TrackerData.ntrkhitsperview[iTrk][2] > TrackerData.ntrkhitsperview[iTrk][1]) TrackerData.trkpidbestplane[iTrk] = 2;
5686  else if(TrackerData.ntrkhitsperview[iTrk][2] == TrackerData.ntrkhitsperview[iTrk][0] && TrackerData.ntrkhitsperview[iTrk][2] > TrackerData.ntrkhitsperview[iTrk][1]) TrackerData.trkpidbestplane[iTrk] = 2;
5687  else if(TrackerData.ntrkhitsperview[iTrk][2] == TrackerData.ntrkhitsperview[iTrk][1] && TrackerData.ntrkhitsperview[iTrk][2] > TrackerData.ntrkhitsperview[iTrk][0]) TrackerData.trkpidbestplane[iTrk] = 2;
5688  else if(TrackerData.ntrkhitsperview[iTrk][1] == TrackerData.ntrkhitsperview[iTrk][0] && TrackerData.ntrkhitsperview[iTrk][1] > TrackerData.ntrkhitsperview[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 0;
5689  else if(TrackerData.ntrkhitsperview[iTrk][1] == TrackerData.ntrkhitsperview[iTrk][0] && TrackerData.ntrkhitsperview[iTrk][1] == TrackerData.ntrkhitsperview[iTrk][2]) TrackerData.trkpidbestplane[iTrk] = 2;
5690 
5691  // FIXME - Do i want to add someway to work out the best TPC???....
5692  } // if has calorimetry info
5693 /*
5694  //track truth information
5695  if (fIsMC){
5696  //get the hits on each plane
5697  art::FindManyP<recob::Hit> fmht(trackListHandle[iTracker], evt, fTrackModuleLabel[iTracker]);
5698  std::vector< art::Ptr<recob::Hit> > allHits = fmht.at(iTrk);
5699  std::vector< art::Ptr<recob::Hit> > hits[kNplanes];
5700 
5701  for(size_t ah = 0; ah < allHits.size(); ++ah){
5702 // if ( allHits[ah]->WireID().Plane >= 0 && // always true
5703  if( allHits[ah]->WireID().Plane < 3){
5704  hits[allHits[ah]->WireID().Plane].push_back(allHits[ah]);
5705  }
5706  }
5707  for (size_t ipl = 0; ipl < 3; ++ipl){
5708  double maxe = 0;
5709  HitsBackTrack(clockData, hits[ipl],TrackerData.trkidtruth[iTrk][ipl],TrackerData.trkpurtruth[iTrk][ipl],maxe);
5710  //std::cout<<"\n"<<iTracker<<"\t"<<iTrk<<"\t"<<ipl<<"\t"<<trkidtruth[iTracker][iTrk][ipl]<<"\t"<<trkpurtruth[iTracker][iTrk][ipl]<<"\t"<<maxe;
5711  if (TrackerData.trkidtruth[iTrk][ipl]>0){
5712  const art::Ptr<simb::MCTruth> mc = pi_serv->TrackIdToMCTruth_P(TrackerData.trkidtruth[iTrk][ipl]);
5713  TrackerData.trkorigin[iTrk][ipl] = mc->Origin();
5714  const simb::MCParticle *particle = pi_serv->TrackIdToParticle_P(TrackerData.trkidtruth[iTrk][ipl]);
5715  double tote = 0;
5716  const std::vector<const sim::IDE*> vide=bt_serv->TrackIdToSimIDEs_Ps(TrackerData.trkidtruth[iTrk][ipl]);
5717  for (auto ide: vide) {
5718  tote += ide->energy;
5719  }
5720  TrackerData.trkpdgtruth[iTrk][ipl] = particle->PdgCode();
5721  TrackerData.trkefftruth[iTrk][ipl] = maxe/(tote/kNplanes); //tote include both induction and collection energies
5722  //std::cout<<"\n"<<trkpdgtruth[iTracker][iTrk][ipl]<<"\t"<<trkefftruth[iTracker][iTrk][ipl];
5723  }
5724  }
5725 
5726  double maxe = 0;
5727  HitsBackTrack(clockData, allHits,TrackerData.trkg4id[iTrk],TrackerData.trkpurity[iTrk],maxe);
5728  if (TrackerData.trkg4id[iTrk]>0){
5729  const art::Ptr<simb::MCTruth> mc = pi_serv->TrackIdToMCTruth_P(TrackerData.trkg4id[iTrk]);
5730  TrackerData.trkorig[iTrk] = mc->Origin();
5731  }
5732  if (allHits.size()){
5733  std::vector<art::Ptr<recob::Hit> > all_hits;
5734  art::Handle<std::vector<recob::Hit> > hithandle;
5735  float totenergy = 0;
5736  if (evt.get(allHits[0].id(), hithandle)){
5737  art::fill_ptr_vector(all_hits, hithandle);
5738  for(size_t h = 0; h < all_hits.size(); ++h){
5739 
5740  art::Ptr<recob::Hit> hit = all_hits[h];
5741  std::vector<sim::IDE> ides;
5742  //bt_serv->HitToSimIDEs(hit,ides);
5743  std::vector<sim::TrackIDE> eveIDs = bt_serv->HitToEveTrackIDEs(clockData, hit);
5744 
5745  for(size_t e = 0; e < eveIDs.size(); ++e){
5746  //std::cout<<h<<" "<<e<<" "<<eveIDs[e].trackID<<" "<<eveIDs[e].energy<<" "<<eveIDs[e].energyFrac<<std::endl;
5747  if (eveIDs[e].trackID==TrackerData.trkg4id[iTrk]) totenergy += eveIDs[e].energy;
5748  }
5749  }
5750  }
5751  if (totenergy) TrackerData.trkcompleteness[iTrk] = maxe/totenergy;
5752  }
5753  }//end if (fIsMC)
5754 */
5755  }//end loop over track
5756  //std::cout << "HitIterator: " << HitIterator << std::endl;
5757  }//end loop over track module labels
5758 }// end (fSaveTrackInfo)
5759 
5760  /*trkf::TrackMomentumCalculator trkm;
5761  std::cout<<"\t"<<trkm.GetTrackMomentum(200,2212)<<"\t"<<trkm.GetTrackMomentum(-10, 13)<<"\t"<<trkm.GetTrackMomentum(300,-19)<<"\n";
5762  */
5763 
5764  //Save Vertex information for multiple algorithms
5765  if (fSaveVertexInfo){
5766  for (unsigned int iVertexAlg=0; iVertexAlg < NVertexAlgos; ++iVertexAlg){
5767  AnaRootParserDataStruct::VertexDataStruct& VertexData = fData->GetVertexData(iVertexAlg);
5768 
5769  size_t NVertices = vertexlist[iVertexAlg].size();
5770 
5771  VertexData.SetMaxVertices(std::max(NVertices, (size_t) 1));
5772  VertexData.Clear(); // clear all the data
5773 
5774  VertexData.nvtx = (short) NVertices;
5775 
5776  // now set the tree addresses to the newly allocated memory;
5777  // this creates the tree branches in case they are not there yet
5778  SetVertexAddresses(iVertexAlg);
5779  if (NVertices > VertexData.GetMaxVertices()) {
5780  // got this error? it might be a bug,
5781  // since we are supposed to have allocated enough space to fit all tracks
5782  mf::LogError("AnaRootParser:limits") << "event has " << NVertices
5783  << " " << fVertexModuleLabel[iVertexAlg] << " tracks, only "
5784  << VertexData.GetMaxVertices() << " stored in tree";
5785  }
5786 
5787  for (size_t i = 0; i < NVertices && i < kMaxVertices ; ++i){//loop over hits
5788  VertexData.vtxId[i] = vertexlist[iVertexAlg][i]->ID();
5789  Double_t xyz[3] = {};
5790  vertexlist[iVertexAlg][i] -> XYZ(xyz);
5791  VertexData.vtxx[i] = xyz[0];
5792  VertexData.vtxy[i] = xyz[1];
5793  VertexData.vtxz[i] = xyz[2];
5794 
5795  if (fSavePFParticleInfo) {
5796  auto mapIter = vertexIDtoPFParticleIDMap.find(vertexlist[iVertexAlg][i]->ID());
5797  if (mapIter != vertexIDtoPFParticleIDMap.end()) {
5798  // This vertex has a corresponding PFParticle.
5799  VertexData.vtxhasPFParticle[i] = 1;
5800  VertexData.vtxPFParticleID[i] = mapIter->second;
5801  }
5802  else
5803  VertexData.vtxhasPFParticle[i] = 0;
5804  }
5805 
5806  // find PFParticle ID info
5807  art::FindMany<recob::PFParticle> fmPFParticle(vertexListHandle[iVertexAlg], evt, fPFParticleModuleLabel);
5808  if(fmPFParticle.isValid()) {
5809  std::vector<const recob::PFParticle*> pfparticles = fmPFParticle.at(i);
5810  if(pfparticles.size() > 1)
5811  std::cerr << "Warning: more than one associated PFParticle found for a vertex. Only one stored in tree." << std::endl;
5812  if (pfparticles.size() == 0)
5813  VertexData.vtxhasPFParticle[i] = 0;
5814  else {
5815  VertexData.vtxhasPFParticle[i] = 1;
5816  VertexData.vtxPFParticleID[i] = pfparticles.at(0)->Self();
5817  }
5818  } // fmPFParticle.isValid()
5819  }
5820  }
5821  }
5822 
5823 
5824  //mc truth information
5825  if (fIsMC)
5826  {
5827 
5828  if (fSaveCryInfo)
5829  {
5830 
5831  //store cry (cosmic generator information)
5832  fData->mcevts_truthcry = mclistcry.size();
5833  fData->cry_no_primaries = nCryPrimaries;
5834  //fData->cry_no_primaries;
5835  for(Int_t iPartc = 0; iPartc < mctruthcry->NParticles(); ++iPartc){
5836  const simb::MCParticle& partc(mctruthcry->GetParticle(iPartc));
5837  fData->cry_primaries_pdg[iPartc]=partc.PdgCode();
5838  fData->cry_Eng[iPartc]=partc.E();
5839  fData->cry_Px[iPartc]=partc.Px();
5840  fData->cry_Py[iPartc]=partc.Py();
5841  fData->cry_Pz[iPartc]=partc.Pz();
5842  fData->cry_P[iPartc]=partc.P();
5843  fData->cry_StartPointx[iPartc] = partc.Vx();
5844  fData->cry_StartPointy[iPartc] = partc.Vy();
5845  fData->cry_StartPointz[iPartc] = partc.Vz();
5846  fData->cry_StartPointt[iPartc] = partc.T();
5847  fData->cry_status_code[iPartc]=partc.StatusCode();
5848  fData->cry_mass[iPartc]=partc.Mass();
5849  fData->cry_trackID[iPartc]=partc.TrackId();
5850  fData->cry_ND[iPartc]=partc.NumberDaughters();
5851  fData->cry_mother[iPartc]=partc.Mother();
5852  } // for cry particles
5853  }// end fSaveCryInfo
5854 
5855  // Save the protoDUNE beam generator information
5856  if(fSaveProtoInfo){
5857  fData->proto_no_primaries = nProtoPrimaries;
5858  for(Int_t iPartp = 0; iPartp < nProtoPrimaries; ++iPartp){
5859  const simb::MCParticle& partp(mctruthproto->GetParticle(iPartp));
5860 
5861  fData->proto_isGoodParticle[iPartp] = (partp.Process() == "primary");
5862  fData->proto_vx[iPartp] = partp.Vx();
5863  fData->proto_vy[iPartp] = partp.Vy();
5864  fData->proto_vz[iPartp] = partp.Vz();
5865  fData->proto_t[iPartp] = partp.T();
5866  fData->proto_px[iPartp] = partp.Px();
5867  fData->proto_py[iPartp] = partp.Py();
5868  fData->proto_pz[iPartp] = partp.Pz();
5869  fData->proto_momentum[iPartp] = partp.P();
5870  fData->proto_energy[iPartp] = partp.E();
5871  fData->proto_pdg[iPartp] = partp.PdgCode();
5872  }
5873  }
5874 
5875  //save neutrino interaction information
5876  fData->mcevts_truth = mclist.size();
5877  if (fData->mcevts_truth > 0) //at least one mc record
5878  {
5879  if (fSaveGenieInfo)
5880  {
5881  int neutrino_i = 0;
5882  for(unsigned int iList = 0; (iList < mclist.size()) && (neutrino_i < kMaxTruth) ; ++iList){
5883  if (mclist[iList]->NeutrinoSet()){
5884  fData->nuPDG_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().PdgCode();
5885  fData->ccnc_truth[neutrino_i] = mclist[iList]->GetNeutrino().CCNC();
5886  fData->mode_truth[neutrino_i] = mclist[iList]->GetNeutrino().Mode();
5887  fData->Q2_truth[neutrino_i] = mclist[iList]->GetNeutrino().QSqr();
5888  fData->W_truth[neutrino_i] = mclist[iList]->GetNeutrino().W();
5889  fData->X_truth[neutrino_i] = mclist[iList]->GetNeutrino().X();
5890  fData->Y_truth[neutrino_i] = mclist[iList]->GetNeutrino().Y();
5891  fData->hitnuc_truth[neutrino_i] = mclist[iList]->GetNeutrino().HitNuc();
5892  fData->enu_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().E();
5893  fData->nuvtxx_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Vx();
5894  fData->nuvtxy_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Vy();
5895  fData->nuvtxz_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Vz();
5896  if (mclist[iList]->GetNeutrino().Nu().P()){
5897  fData->nu_dcosx_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Px()/mclist[iList]->GetNeutrino().Nu().P();
5898  fData->nu_dcosy_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Py()/mclist[iList]->GetNeutrino().Nu().P();
5899  fData->nu_dcosz_truth[neutrino_i] = mclist[iList]->GetNeutrino().Nu().Pz()/mclist[iList]->GetNeutrino().Nu().P();
5900  }
5901  fData->lep_mom_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().P();
5902  if (mclist[iList]->GetNeutrino().Lepton().P()){
5903  fData->lep_dcosx_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().Px()/mclist[iList]->GetNeutrino().Lepton().P();
5904  fData->lep_dcosy_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().Py()/mclist[iList]->GetNeutrino().Lepton().P();
5905  fData->lep_dcosz_truth[neutrino_i] = mclist[iList]->GetNeutrino().Lepton().Pz()/mclist[iList]->GetNeutrino().Lepton().P();
5906  }
5907 
5908  //flux information
5909  //
5910  // Double-check that a simb::MCFlux object is associated with the
5911  // current simb::MCTruth object. For GENIE events, these should
5912  // always accompany each other. Other generators (e.g., MARLEY) may
5913  // create simb::MCTruth objects without corresponding simb::MCFlux
5914  // objects. -- S. Gardiner
5915  /* if (find_mcflux.isValid()) {
5916  auto flux_maybe_ref = find_mcflux.at(iList);
5917  if (flux_maybe_ref.isValid()) {
5918  auto flux_ref = flux_maybe_ref.ref();
5919  fData->vx_flux[neutrino_i] = flux_ref.fvx;
5920  fData->vy_flux[neutrino_i] = flux_ref.fvy;
5921  fData->vz_flux[neutrino_i] = flux_ref.fvz;
5922  fData->pdpx_flux[neutrino_i] = flux_ref.fpdpx;
5923  fData->pdpy_flux[neutrino_i] = flux_ref.fpdpy;
5924  fData->pdpz_flux[neutrino_i] = flux_ref.fpdpz;
5925  fData->ppdxdz_flux[neutrino_i] = flux_ref.fppdxdz;
5926  fData->ppdydz_flux[neutrino_i] = flux_ref.fppdydz;
5927  fData->pppz_flux[neutrino_i] = flux_ref.fpppz;
5928 
5929  fData->ptype_flux[neutrino_i] = flux_ref.fptype;
5930  fData->ppvx_flux[neutrino_i] = flux_ref.fppvx;
5931  fData->ppvy_flux[neutrino_i] = flux_ref.fppvy;
5932  fData->ppvz_flux[neutrino_i] = flux_ref.fppvz;
5933  fData->muparpx_flux[neutrino_i] = flux_ref.fmuparpx;
5934  fData->muparpy_flux[neutrino_i] = flux_ref.fmuparpy;
5935  fData->muparpz_flux[neutrino_i] = flux_ref.fmuparpz;
5936  fData->mupare_flux[neutrino_i] = flux_ref.fmupare;
5937 
5938  fData->tgen_flux[neutrino_i] = flux_ref.ftgen;
5939  fData->tgptype_flux[neutrino_i] = flux_ref.ftgptype;
5940  fData->tgppx_flux[neutrino_i] = flux_ref.ftgppx;
5941  fData->tgppy_flux[neutrino_i] = flux_ref.ftgppy;
5942  fData->tgppz_flux[neutrino_i] = flux_ref.ftgppz;
5943  fData->tprivx_flux[neutrino_i] = flux_ref.ftprivx;
5944  fData->tprivy_flux[neutrino_i] = flux_ref.ftprivy;
5945  fData->tprivz_flux[neutrino_i] = flux_ref.ftprivz;
5946 
5947  fData->dk2gen_flux[neutrino_i] = flux_ref.fdk2gen;
5948  fData->gen2vtx_flux[neutrino_i] = flux_ref.fgen2vtx;
5949 
5950  fData->tpx_flux[neutrino_i] = flux_ref.ftpx;
5951  fData->tpy_flux[neutrino_i] = flux_ref.ftpy;
5952  fData->tpz_flux[neutrino_i] = flux_ref.ftpz;
5953  fData->tptype_flux[neutrino_i] = flux_ref.ftptype;
5954  } // flux_maybe_ref.isValid()
5955  } // find_mcflux.isValid() */
5956  neutrino_i++;
5957  }//mclist is NeutrinoSet()
5958  }//loop over mclist
5959 
5960  if (mctruth->NeutrinoSet()){
5961  //genie particles information
5962  fData->genie_no_primaries = mctruth->NParticles();
5963 
5964  size_t StoreParticles = std::min((size_t) fData->genie_no_primaries, fData->GetMaxGeniePrimaries());
5965  if (fData->genie_no_primaries > (int) StoreParticles) {
5966  // got this error? it might be a bug,
5967  // since the structure should have enough room for everything
5968  mf::LogError("AnaRootParser:limits") << "event has "
5969  << fData->genie_no_primaries << " MC particles, only "
5970  << StoreParticles << " stored in tree";
5971  }
5972  for(size_t iPart = 0; iPart < StoreParticles; ++iPart){
5973  const simb::MCParticle& part(mctruth->GetParticle(iPart));
5974  fData->genie_primaries_pdg[iPart]=part.PdgCode();
5975  fData->genie_Eng[iPart]=part.E();
5976  fData->genie_Px[iPart]=part.Px();
5977  fData->genie_Py[iPart]=part.Py();
5978  fData->genie_Pz[iPart]=part.Pz();
5979  fData->genie_P[iPart]=part.P();
5980  fData->genie_status_code[iPart]=part.StatusCode();
5981  fData->genie_mass[iPart]=part.Mass();
5982  fData->genie_trackID[iPart]=part.TrackId();
5983  fData->genie_ND[iPart]=part.NumberDaughters();
5984  fData->genie_mother[iPart]=part.Mother();
5985  } // for particle
5986  //const simb::MCNeutrino& nu(mctruth->GetNeutrino());
5987  } //if neutrino set
5988  }// end (fSaveGenieInfo)
5989 
5990  //Extract MC Shower information and fill the Shower branches
5991  if (fSaveMCShowerInfo)
5992  {
5993  fData->no_mcshowers = nMCShowers;
5994  size_t shwr = 0;
5995  for(std::vector<sim::MCShower>::const_iterator imcshwr = mcshowerh->begin();
5996  imcshwr != mcshowerh->end(); ++imcshwr) {
5997  const sim::MCShower& mcshwr = *imcshwr;
5998  fData->mcshwr_origin[shwr] = mcshwr.Origin();
5999  fData->mcshwr_pdg[shwr] = mcshwr.PdgCode();
6000  fData->mcshwr_TrackId[shwr] = mcshwr.TrackID();
6001  fData->mcshwr_Process[shwr] = mcshwr.Process();
6002  fData->mcshwr_startX[shwr] = mcshwr.Start().X();
6003  fData->mcshwr_startY[shwr] = mcshwr.Start().Y();
6004  fData->mcshwr_startZ[shwr] = mcshwr.Start().Z();
6005  fData->mcshwr_endX[shwr] = mcshwr.End().X();
6006  fData->mcshwr_endY[shwr] = mcshwr.End().Y();
6007  fData->mcshwr_endZ[shwr] = mcshwr.End().Z();
6008  if (mcshwr.DetProfile().E()!= 0){
6009  fData->mcshwr_isEngDeposited[shwr] = 1;
6010  fData->mcshwr_CombEngX[shwr] = mcshwr.DetProfile().X();
6011  fData->mcshwr_CombEngY[shwr] = mcshwr.DetProfile().Y();
6012  fData->mcshwr_CombEngZ[shwr] = mcshwr.DetProfile().Z();
6013  fData->mcshwr_CombEngPx[shwr] = mcshwr.DetProfile().Px();
6014  fData->mcshwr_CombEngPy[shwr] = mcshwr.DetProfile().Py();
6015  fData->mcshwr_CombEngPz[shwr] = mcshwr.DetProfile().Pz();
6016  fData->mcshwr_CombEngE[shwr] = mcshwr.DetProfile().E();
6017  fData->mcshwr_dEdx[shwr] = mcshwr.dEdx();
6018  fData->mcshwr_StartDirX[shwr] = mcshwr.StartDir().X();
6019  fData->mcshwr_StartDirY[shwr] = mcshwr.StartDir().Y();
6020  fData->mcshwr_StartDirZ[shwr] = mcshwr.StartDir().Z();
6021  }
6022  else
6023  fData->mcshwr_isEngDeposited[shwr] = 0;
6024  fData->mcshwr_Motherpdg[shwr] = mcshwr.MotherPdgCode();
6025  fData->mcshwr_MotherTrkId[shwr] = mcshwr.MotherTrackID();
6026  fData->mcshwr_MotherProcess[shwr] = mcshwr.MotherProcess();
6027  fData->mcshwr_MotherstartX[shwr] = mcshwr.MotherStart().X();
6028  fData->mcshwr_MotherstartY[shwr] = mcshwr.MotherStart().Y();
6029  fData->mcshwr_MotherstartZ[shwr] = mcshwr.MotherStart().Z();
6030  fData->mcshwr_MotherendX[shwr] = mcshwr.MotherEnd().X();
6031  fData->mcshwr_MotherendY[shwr] = mcshwr.MotherEnd().Y();
6032  fData->mcshwr_MotherendZ[shwr] = mcshwr.MotherEnd().Z();
6033  fData->mcshwr_Ancestorpdg[shwr] = mcshwr.AncestorPdgCode();
6034  fData->mcshwr_AncestorTrkId[shwr] = mcshwr.AncestorTrackID();
6035  fData->mcshwr_AncestorProcess[shwr] = mcshwr.AncestorProcess();
6036  fData->mcshwr_AncestorstartX[shwr] = mcshwr.AncestorStart().X();
6037  fData->mcshwr_AncestorstartY[shwr] = mcshwr.AncestorStart().Y();
6038  fData->mcshwr_AncestorstartZ[shwr] = mcshwr.AncestorStart().Z();
6039  fData->mcshwr_AncestorendX[shwr] = mcshwr.AncestorEnd().X();
6040  fData->mcshwr_AncestorendY[shwr] = mcshwr.AncestorEnd().Y();
6041  fData->mcshwr_AncestorendZ[shwr] = mcshwr.AncestorEnd().Z();
6042  ++shwr;
6043  }
6044  fData->mcshwr_Process.resize(shwr);
6045  fData->mcshwr_MotherProcess.resize(shwr);
6046  fData->mcshwr_AncestorProcess.resize(shwr);
6047  }//End if (fSaveMCShowerInfo){
6048 
6049  //Extract MC Track information and fill the Shower branches
6050  if (fSaveMCTrackInfo)
6051  {
6052  fData->no_mctracks = nMCTracks;
6053  size_t trk = 0;
6054  for(std::vector<sim::MCTrack>::const_iterator imctrk = mctrackh->begin();imctrk != mctrackh->end(); ++imctrk) {
6055  const sim::MCTrack& mctrk = *imctrk;
6056  TLorentzVector tpcstart, tpcend, tpcmom;
6057  double plen = driftedLength(detProp, mctrk, tpcstart, tpcend, tpcmom);
6058  fData->mctrk_origin[trk] = mctrk.Origin();
6059  fData->mctrk_pdg[trk] = mctrk.PdgCode();
6060  fData->mctrk_TrackId[trk] = mctrk.TrackID();
6061  fData->mctrk_Process[trk] = mctrk.Process();
6062  fData->mctrk_startX[trk] = mctrk.Start().X();
6063  fData->mctrk_startY[trk] = mctrk.Start().Y();
6064  fData->mctrk_startZ[trk] = mctrk.Start().Z();
6065  fData->mctrk_endX[trk] = mctrk.End().X();
6066  fData->mctrk_endY[trk] = mctrk.End().Y();
6067  fData->mctrk_endZ[trk] = mctrk.End().Z();
6068  fData->mctrk_Motherpdg[trk] = mctrk.MotherPdgCode();
6069  fData->mctrk_MotherTrkId[trk] = mctrk.MotherTrackID();
6070  fData->mctrk_MotherProcess[trk] = mctrk.MotherProcess();
6071  fData->mctrk_MotherstartX[trk] = mctrk.MotherStart().X();
6072  fData->mctrk_MotherstartY[trk] = mctrk.MotherStart().Y();
6073  fData->mctrk_MotherstartZ[trk] = mctrk.MotherStart().Z();
6074  fData->mctrk_MotherendX[trk] = mctrk.MotherEnd().X();
6075  fData->mctrk_MotherendY[trk] = mctrk.MotherEnd().Y();
6076  fData->mctrk_MotherendZ[trk] = mctrk.MotherEnd().Z();
6077  fData->mctrk_Ancestorpdg[trk] = mctrk.AncestorPdgCode();
6078  fData->mctrk_AncestorTrkId[trk] = mctrk.AncestorTrackID();
6079  fData->mctrk_AncestorProcess[trk] = mctrk.AncestorProcess();
6080  fData->mctrk_AncestorstartX[trk] = mctrk.AncestorStart().X();
6081  fData->mctrk_AncestorstartY[trk] = mctrk.AncestorStart().Y();
6082  fData->mctrk_AncestorstartZ[trk] = mctrk.AncestorStart().Z();
6083  fData->mctrk_AncestorendX[trk] = mctrk.AncestorEnd().X();
6084  fData->mctrk_AncestorendY[trk] = mctrk.AncestorEnd().Y();
6085  fData->mctrk_AncestorendZ[trk] = mctrk.AncestorEnd().Z();
6086 
6087  fData->mctrk_len_drifted[trk] = plen;
6088 
6089  if (plen != 0){
6090  fData->mctrk_startX_drifted[trk] = tpcstart.X();
6091  fData->mctrk_startY_drifted[trk] = tpcstart.Y();
6092  fData->mctrk_startZ_drifted[trk] = tpcstart.Z();
6093  fData->mctrk_endX_drifted[trk] = tpcend.X();
6094  fData->mctrk_endY_drifted[trk] = tpcend.Y();
6095  fData->mctrk_endZ_drifted[trk] = tpcend.Z();
6096  fData->mctrk_p_drifted[trk] = tpcmom.Vect().Mag();
6097  fData->mctrk_px_drifted[trk] = tpcmom.X();
6098  fData->mctrk_py_drifted[trk] = tpcmom.Y();
6099  fData->mctrk_pz_drifted[trk] = tpcmom.Z();
6100  }
6101  ++trk;
6102  }
6103 
6104  fData->mctrk_Process.resize(trk);
6105  fData->mctrk_MotherProcess.resize(trk);
6106  fData->mctrk_AncestorProcess.resize(trk);
6107  }//End if (fSaveMCTrackInfo){
6108 
6109 
6110  //Photon particles information
6111  if (fSavePhotonInfo)
6112  {
6113  int photoncounter=0;
6114  for ( auto const& pmt : (*photonHandle) )
6115  {
6116  std::map<int, int> PhotonsMap = pmt.DetectedPhotons;
6117 
6118  for(auto itphoton = PhotonsMap.begin(); itphoton!= PhotonsMap.end(); itphoton++)
6119  {
6120  for(int iphotonatthistime = 0; iphotonatthistime < itphoton->second ; iphotonatthistime++)
6121  {
6122  fData->photons_time[photoncounter]=itphoton->first;
6123  fData->photons_channel[photoncounter]=pmt.OpChannel;
6124  photoncounter++;
6125  }
6126  }
6127  }
6128  fData->numberofphotons=photoncounter;
6129  }
6130 
6131  //Generator particles information
6132  if (fSaveGeneratorInfo)
6133  {
6134  const sim::ParticleList& plist = pi_serv->ParticleList();
6135 
6136  size_t generator_particle=0;
6137  sim::ParticleList::const_iterator itPart = plist.begin(),
6138  pend = plist.end(); // iterator to pairs (track id, particle)
6139 
6140  for(size_t iPart = 0; (iPart < plist.size()) && (itPart != pend); ++iPart){
6141 
6142  const simb::MCParticle* pPart = (itPart++)->second;
6143  if (!pPart) {
6145  << "GEANT particle #" << iPart << " returned a null pointer";
6146  }
6147 
6148  if (iPart < fData->GetMaxGeneratorparticles()) {
6149 
6150  std::string pri("primary");
6151  if( pPart->Mother() == 0 && pPart->Process() == pri )
6152  {
6153  fData->TrackId[generator_particle]=pPart->TrackId();
6154  fData->pdg[generator_particle]=pPart->PdgCode();
6155  fData->status[generator_particle] = pPart->StatusCode();
6156  fData->Eng[generator_particle]=pPart->E();
6157  fData->Mass[generator_particle]=pPart->Mass();
6158  fData->Px[generator_particle]=pPart->Px();
6159  fData->Py[generator_particle]=pPart->Py();
6160  fData->Pz[generator_particle]=pPart->Pz();
6161  fData->P[generator_particle]=pPart->Momentum().Vect().Mag();
6162  fData->StartPointx[generator_particle]=pPart->Vx();
6163  fData->StartPointy[generator_particle]=pPart->Vy();
6164  fData->StartPointz[generator_particle]=pPart->Vz();
6165  fData->StartT[generator_particle] = pPart->T();
6166 
6167  TVector3 momentum_start_flipped;
6168  momentum_start_flipped.SetXYZ(pPart->Pz(), pPart->Py(), pPart->Px());
6169 
6170  fData->theta[generator_particle] = (180.0/3.14159)*momentum_start_flipped.Theta();
6171  fData->phi[generator_particle] = (180.0/3.14159)*momentum_start_flipped.Phi();
6172  }
6173  ++generator_particle;
6174  }
6175  else if (iPart == fData->GetMaxGeneratorparticles()) {
6176  // got this error? it might be a bug,
6177  // since the structure should have enough room for everything
6178  mf::LogError("AnaRootParser:limits") << "event has "
6179  << plist.size() << " MC particles, only "
6180  << fData->GetMaxGeneratorparticles() << " will be stored in tree";
6181  }
6182  } // for particles
6183  fData->generator_list_size = generator_particle;
6184  fData->processname.resize(generator_particle);
6185  MF_LOG_DEBUG("AnaRootParser")
6186  << "Counted "
6187  << fData->generator_list_size << " Generator particles";
6188  }//fSaveGeneratorInfo
6189 
6190 
6191 
6192 
6193  //GEANT particles information
6194  if (fSaveGeantInfo)
6195  {
6196 
6197  const sim::ParticleList& plist = pi_serv->ParticleList();
6198 
6199  std::string pri("primary");
6200  int primary=0;
6201  int active = 0;
6202  size_t geant_particle=0;
6203  sim::ParticleList::const_iterator itPart = plist.begin(),
6204  pend = plist.end(); // iterator to pairs (track id, particle)
6205 
6206  // helper map track ID => index
6207  std::map<int, size_t> TrackIDtoIndex;
6208  std::vector<int> gpdg;
6209  std::vector<int> gmother;
6210  for(size_t iPart = 0; (iPart < plist.size()) && (itPart != pend); ++iPart){
6211  const simb::MCParticle* pPart = (itPart++)->second;
6212  if (!pPart) {
6214  << "GEANT particle #" << iPart << " returned a null pointer";
6215  }
6216 
6217  bool isPrimary = pPart->Process() == pri;
6218  int TrackID = pPart->TrackId();
6219  TrackIDtoIndex.emplace(TrackID, iPart);
6220  gpdg.push_back(pPart->PdgCode());
6221  gmother.push_back(pPart->Mother());
6222  if (iPart < fData->GetMaxGEANTparticles()) {
6223 // if (pPart->E()<fG4minE&&(!isPrimary)) continue;
6224  if (isPrimary) ++primary;
6225 
6226  TLorentzVector mcstart, mcend;
6227  unsigned int pstarti, pendi;
6228  double plen = length(*pPart, mcstart, mcend, pstarti, pendi);
6229  bool isActive = plen != 0;
6230 
6231 // TLorentzVector mcstartdrifted, mcenddrifted;
6232 // unsigned int pstartdriftedi, penddriftedi;
6233 // double plendrifted = driftedLength(*pPart, mcstartdrifted, mcenddrifted, pstartdriftedi, penddriftedi);
6234 // bool isDrifted = plendrifted!= 0;
6235 
6236  if(fLogLevel >= 3)
6237  {
6238  std::cout << "pPart->TrackId():" << pPart->TrackId() << std::endl;
6239  std::cout << "pPart->Mother():" << pPart->Mother() << std::endl;
6240  std::cout << "pPart->PdgCode():" << pPart->PdgCode() << std::endl;
6241  std::cout << std::endl;
6242  }
6243 
6244 
6245  fData->process_primary[geant_particle] = int(isPrimary);
6246  fData->processname[geant_particle]= pPart->Process();
6247  fData->Mother[geant_particle]=pPart->Mother();
6248  fData->TrackId[geant_particle]=pPart->TrackId();
6249  fData->pdg[geant_particle]=pPart->PdgCode();
6250  fData->status[geant_particle] = pPart->StatusCode();
6251  fData->Eng[geant_particle]=pPart->E();
6252  fData->EndE[geant_particle]=pPart->EndE();
6253  fData->Mass[geant_particle]=pPart->Mass();
6254  fData->Px[geant_particle]=pPart->Px();
6255  fData->Py[geant_particle]=pPart->Py();
6256  fData->Pz[geant_particle]=pPart->Pz();
6257  fData->P[geant_particle]=pPart->Momentum().Vect().Mag();
6258  fData->StartPointx[geant_particle]=pPart->Vx();
6259  fData->StartPointy[geant_particle]=pPart->Vy();
6260  fData->StartPointz[geant_particle]=pPart->Vz();
6261  fData->StartT[geant_particle] = pPart->T();
6262  fData->EndPointx[geant_particle]=pPart->EndPosition()[0];
6263  fData->EndPointy[geant_particle]=pPart->EndPosition()[1];
6264  fData->EndPointz[geant_particle]=pPart->EndPosition()[2];
6265  fData->EndT[geant_particle] = pPart->EndT();
6266 
6267  fData->NTrajectoryPointsPerParticle[geant_particle] = pPart->NumberTrajectoryPoints();
6268 
6269  //fData->theta[geant_particle] = pPart->Momentum().Theta();
6270  //fData->phi[geant_particle] = pPart->Momentum().Phi();
6271  //Change definition of theta and phi (swap x and z coordinate since x is "up" in dual phase)
6272  TVector3 momentum_start_flipped;
6273  momentum_start_flipped.SetXYZ(pPart->Pz(), pPart->Py(), pPart->Px());
6274 
6275  fData->theta[geant_particle] = (180.0/3.14159)*momentum_start_flipped.Theta();
6276  fData->phi[geant_particle] = (180.0/3.14159)*momentum_start_flipped.Phi();
6277 
6278  fData->theta_xz[geant_particle] = std::atan2(pPart->Px(), pPart->Pz());
6279  fData->theta_yz[geant_particle] = std::atan2(pPart->Py(), pPart->Pz());
6280 // fData->pathlen_drifted[geant_particle] = plendrifted;
6281  fData->NumberDaughters[geant_particle]=pPart->NumberDaughters();
6282  fData->inTPCActive[geant_particle] = int(isActive);
6283 // fData->inTPCDrifted[geant_particle] = int(isDrifted);
6284  art::Ptr<simb::MCTruth> const& mc_truth = pi_serv->ParticleToMCTruth_P(pPart);
6285  if (mc_truth){
6286  fData->origin[geant_particle] = mc_truth->Origin();
6287  fData->MCTruthIndex[geant_particle] = mc_truth.key();
6288  }
6289 
6290  if (isActive && fSaveGeantInAVInfo){
6291  fData->pathlen_tpcAV[active] = plen;
6292  fData->TrackId_tpcAV[active] = pPart->TrackId();
6293  fData->PDGCode_tpcAV[active] = pPart->PdgCode();
6294 
6295  fData->StartPointx_tpcAV[active] = mcstart.X();
6296  fData->StartPointy_tpcAV[active] = mcstart.Y();
6297  fData->StartPointz_tpcAV[active] = mcstart.Z();
6298  fData->StartT_tpcAV[active] = mcstart.T();
6299  fData->StartE_tpcAV[active] = pPart->E(pstarti);
6300  fData->StartP_tpcAV[active] = pPart->P(pstarti);
6301  fData->StartPx_tpcAV[active] = pPart->Px(pstarti);
6302  fData->StartPy_tpcAV[active] = pPart->Py(pstarti);
6303  fData->StartPz_tpcAV[active] = pPart->Pz(pstarti);
6304  fData->EndPointx_tpcAV[active] = mcend.X();
6305  fData->EndPointy_tpcAV[active] = mcend.Y();
6306  fData->EndPointz_tpcAV[active] = mcend.Z();
6307  fData->EndT_tpcAV[active] = mcend.T();
6308  fData->EndE_tpcAV[active] = pPart->E(pendi);
6309  fData->EndP_tpcAV[active] = pPart->P(pendi);
6310  fData->EndPx_tpcAV[active] = pPart->Px(pendi);
6311  fData->EndPy_tpcAV[active] = pPart->Py(pendi);
6312  fData->EndPz_tpcAV[active] = pPart->Pz(pendi);
6313 
6314  //Change definition of theta and phi (swap x and z coordinate since x is "up" in dual phase)
6315  TVector3 momentum_start_tpcAv_flipped;
6316  momentum_start_tpcAv_flipped.SetXYZ(pPart->Pz(pstarti), pPart->Py(pstarti), pPart->Px(pstarti));
6317  TVector3 momentum_end_tpcAv_flipped;
6318  momentum_end_tpcAv_flipped.SetXYZ(pPart->Pz(pendi), pPart->Py(pendi), pPart->Px(pendi));
6319 
6320  fData->thetastart_tpcAV[active] = (180.0/3.14159)*momentum_start_tpcAv_flipped.Theta();
6321  fData->phistart_tpcAV[active] = (180.0/3.14159)*momentum_start_tpcAv_flipped.Phi();
6322 
6323  fData->thetaend_tpcAV[active] = (180.0/3.14159)*momentum_end_tpcAv_flipped.Theta();
6324  fData->phiend_tpcAV[active] = (180.0/3.14159)*momentum_end_tpcAv_flipped.Phi();
6325 
6326  active++;
6327  }
6328 
6329 /*
6330  if (isDrifted){
6331  fData->StartPointx_drifted[geant_particle] = mcstartdrifted.X();
6332  fData->StartPointy_drifted[geant_particle] = mcstartdrifted.Y();
6333  fData->StartPointz_drifted[geant_particle] = mcstartdrifted.Z();
6334  fData->StartT_drifted[geant_particle] = mcstartdrifted.T();
6335  fData->StartE_drifted[geant_particle] = pPart->E(pstartdriftedi);
6336  fData->StartP_drifted[geant_particle] = pPart->P(pstartdriftedi);
6337  fData->StartPx_drifted[geant_particle] = pPart->Px(pstartdriftedi);
6338  fData->StartPy_drifted[geant_particle] = pPart->Py(pstartdriftedi);
6339  fData->StartPz_drifted[geant_particle] = pPart->Pz(pstartdriftedi);
6340  fData->EndPointx_drifted[geant_particle] = mcenddrifted.X();
6341  fData->EndPointy_drifted[geant_particle] = mcenddrifted.Y();
6342  fData->EndPointz_drifted[geant_particle] = mcenddrifted.Z();
6343  fData->EndT_drifted[geant_particle] = mcenddrifted.T();
6344  fData->EndE_drifted[geant_particle] = pPart->E(penddriftedi);
6345  fData->EndP_drifted[geant_particle] = pPart->P(penddriftedi);
6346  fData->EndPx_drifted[geant_particle] = pPart->Px(penddriftedi);
6347  fData->EndPy_drifted[geant_particle] = pPart->Py(penddriftedi);
6348  fData->EndPz_drifted[geant_particle] = pPart->Pz(penddriftedi);
6349  }
6350 */
6351  //access auxiliary detector parameters
6352  if (fSaveAuxDetInfo) {
6353  unsigned short nAD = 0; // number of cells that particle hit
6354 
6355  // find deposit of this particle in each of the detector cells
6356  for (const sim::AuxDetSimChannel* c: fAuxDetSimChannels) {
6357 
6358  // find if this cell has a contribution (IDE) from this particle,
6359  // and which one
6360  const std::vector<sim::AuxDetIDE>& setOfIDEs = c->AuxDetIDEs();
6361  // using a C++ "lambda" function here; this one:
6362  // - sees only TrackID from the current scope
6363  // - takes one parameter: the AuxDetIDE to be tested
6364  // - returns if that IDE belongs to the track we are looking for
6366  = std::find_if(
6367  setOfIDEs.begin(), setOfIDEs.end(),
6368  [TrackID](const sim::AuxDetIDE& IDE){ return IDE.trackID == TrackID; }
6369  );
6370  if (iIDE == setOfIDEs.end()) continue;
6371 
6372  // now iIDE points to the energy released by the track #i (TrackID)
6373 
6374  // look for IDE with matching trackID
6375  // find trackIDs stored in setOfIDEs with the same trackID, but negative,
6376  // this is an untracked particle who's energy should be added as deposited by this original trackID
6377  float totalE = 0.; // total energy deposited around by the GEANT particle in this cell
6378  for(const auto& adtracks: setOfIDEs) {
6379  if( fabs(adtracks.trackID) == TrackID )
6380  totalE += adtracks.energyDeposited;
6381  } // for
6382 
6383  // fill the structure
6384  if (nAD < kMaxAuxDets) {
6385  fData->AuxDetID[geant_particle][nAD] = c->AuxDetID();
6386  fData->entryX[geant_particle][nAD] = iIDE->entryX;
6387  fData->entryY[geant_particle][nAD] = iIDE->entryY;
6388  fData->entryZ[geant_particle][nAD] = iIDE->entryZ;
6389  fData->entryT[geant_particle][nAD] = iIDE->entryT;
6390  fData->exitX[geant_particle][nAD] = iIDE->exitX;
6391  fData->exitY[geant_particle][nAD] = iIDE->exitY;
6392  fData->exitZ[geant_particle][nAD] = iIDE->exitZ;
6393  fData->exitT[geant_particle][nAD] = iIDE->exitT;
6394  fData->exitPx[geant_particle][nAD] = iIDE->exitMomentumX;
6395  fData->exitPy[geant_particle][nAD] = iIDE->exitMomentumY;
6396  fData->exitPz[geant_particle][nAD] = iIDE->exitMomentumZ;
6397  fData->CombinedEnergyDep[geant_particle][nAD] = totalE;
6398  }
6399  ++nAD;
6400  } // for aux det sim channels
6401  fData->NAuxDets[geant_particle] = nAD;
6402 
6403  if (nAD > kMaxAuxDets) {
6404  // got this error? consider increasing kMaxAuxDets
6405  mf::LogError("AnaRootParser:limits")
6406  << "particle #" << iPart
6407  << " touches " << nAD << " auxiliary detector cells, only "
6408  << kMaxAuxDets << " of them are saved in the tree";
6409  } // if too many detector cells
6410  } // if (fSaveAuxDetInfo)
6411 
6412  ++geant_particle;
6413  }
6414  else if (iPart == fData->GetMaxGEANTparticles()) {
6415  // got this error? it might be a bug,
6416  // since the structure should have enough room for everything
6417  mf::LogError("AnaRootParser:limits") << "event has "
6418  << plist.size() << " MC particles, only "
6419  << fData->GetMaxGEANTparticles() << " will be stored in tree";
6420  }
6421  } // for particles
6422 
6423  fData->geant_list_size_in_tpcAV = active;
6424  fData->no_primaries = primary;
6425  fData->geant_list_size = geant_particle;
6426  fData->processname.resize(geant_particle);
6427  MF_LOG_DEBUG("AnaRootParser")
6428  << "Counted "
6429  << fData->geant_list_size << " GEANT particles ("
6430  << fData->geant_list_size_in_tpcAV << " in AV), "
6431  << fData->no_primaries << " primaries, "
6432  << fData->genie_no_primaries << " GENIE particles";
6433 
6434  FillWith(fData->MergedId, 0);
6435 
6436  // for each particle, consider all the direct ancestors with the same
6437  // PDG ID, and mark them as belonging to the same "group"
6438  // (having the same MergedId)
6439 
6440 
6441  int currentMergedId = 1;
6442  for(size_t iPart = 0; iPart < geant_particle; ++iPart){
6443  // if the particle already belongs to a group, don't bother
6444  if (fData->MergedId[iPart]) continue;
6445  // the particle starts its own group
6446  fData->MergedId[iPart] = currentMergedId;
6447  int currentMotherTrackId = fData->Mother[iPart];
6448  while (currentMotherTrackId > 0) {
6449  if (TrackIDtoIndex.find(currentMotherTrackId)==TrackIDtoIndex.end()) break;
6450  unsigned int gindex = TrackIDtoIndex[currentMotherTrackId];
6451  if (gindex>=plist.size()) break;
6452  // if the mother particle is of a different type,
6453  // don't bother with iPart ancestry any further
6454  if (gpdg[gindex]!=fData->pdg[iPart]) break;
6455  if (TrackIDtoIndex.find(currentMotherTrackId)!=TrackIDtoIndex.end()){
6456  unsigned int igeantMother = TrackIDtoIndex[currentMotherTrackId];
6457  if (igeantMother<geant_particle){
6458  fData->MergedId[igeantMother] = currentMergedId;
6459  }
6460  }
6461  currentMotherTrackId = gmother[gindex];
6462  }
6463  ++currentMergedId;
6464  }// for merging check
6465 
6466  } // if (fSaveGeantInfo)
6467 
6468  //GEANT trajectory information
6470  {
6471  const sim::ParticleList& plist = pi_serv->ParticleList();
6472  sim::ParticleList::const_iterator itPart = plist.begin(),
6473  pend = plist.end(); // iterator to pairs (track id, particle)
6474  int trajpointcounter = 0;
6475 
6476  for(size_t iPart = 0; (iPart < plist.size()) && (itPart != pend); ++iPart)
6477  {
6478  const simb::MCParticle* pPart = (itPart++)->second;
6479  if (!pPart)
6480  {
6482  << "GEANT particle #" << iPart << " returned a null pointer";
6483  }
6484 
6485  unsigned int numberTrajectoryPoints = pPart->NumberTrajectoryPoints();
6486  for(unsigned int trajpoint=0; trajpoint < numberTrajectoryPoints; ++trajpoint)
6487  {
6488  const TLorentzVector& trajpointPosition= pPart->Position(trajpoint);
6489  //const TLorentzVector& trajpointMomentum= pPart->Momentum(trajpoint);
6490 
6491  fData->TrajTrackId[trajpointcounter] = pPart->TrackId();
6492  fData->TrajPDGCode[trajpointcounter] = pPart->PdgCode();
6493 
6494  fData->TrajX[trajpointcounter] = trajpointPosition.X();
6495  fData->TrajY[trajpointcounter] = trajpointPosition.Y();
6496  fData->TrajZ[trajpointcounter] = trajpointPosition.Z();
6497  fData->TrajT[trajpointcounter] = pPart->T(trajpoint);
6498  fData->TrajE[trajpointcounter] = pPart->E(trajpoint);
6499  fData->TrajP[trajpointcounter] = pPart->P(trajpoint);
6500  fData->TrajPx[trajpointcounter] = pPart->Px(trajpoint);
6501  fData->TrajPy[trajpointcounter] = pPart->Py(trajpoint);
6502  fData->TrajPz[trajpointcounter] = pPart->Pz(trajpoint);
6503 
6504  TVector3 trajpointMomentum_flipped;
6505  trajpointMomentum_flipped.SetXYZ(pPart->Pz(trajpoint), pPart->Py(trajpoint), pPart->Px(trajpoint));
6506 
6507  fData->TrajTheta[trajpointcounter] = (180.0/3.14159)*trajpointMomentum_flipped.Theta();
6508  fData->TrajPhi[trajpointcounter] = (180.0/3.14159)*trajpointMomentum_flipped.Phi();
6509 
6510  if(fLogLevel >= 4)
6511  {
6512  std::cout << std::endl;
6513  std::cout << "trajpointcounter: " << trajpointcounter << std::endl;
6514  std::cout << "fData->TrajTrackId[trajpointcounter]: " << fData->TrajTrackId[trajpointcounter] << std::endl;
6515  std::cout << "fData->TrajPDGCode[trajpointcounter]: " << fData->TrajPDGCode[trajpointcounter] << std::endl;
6516  std::cout << "fData->TrajX[trajpointcounter]: " << fData->TrajX[trajpointcounter] << std::endl;
6517  std::cout << "fData->TrajY[trajpointcounter]: " << fData->TrajY[trajpointcounter] << std::endl;
6518  std::cout << "fData->TrajZ[trajpointcounter]: " << fData->TrajZ[trajpointcounter] << std::endl;
6519  std::cout << "fData->TrajT[trajpointcounter]: " << fData->TrajT[trajpointcounter] << std::endl;
6520  std::cout << "fData->TrajE[trajpointcounter]: " << fData->TrajE[trajpointcounter] << std::endl;
6521  std::cout << "fData->TrajP[trajpointcounter]: " << fData->TrajP[trajpointcounter] << std::endl;
6522  std::cout << "fData->TrajPx[trajpointcounter]: " << fData->TrajPx[trajpointcounter] << std::endl;
6523  std::cout << "fData->TrajPy[trajpointcounter]: " << fData->TrajPy[trajpointcounter] << std::endl;
6524  std::cout << "fData->TrajPz[trajpointcounter]: " << fData->TrajPz[trajpointcounter] << std::endl;
6525  std::cout << "fData->TrajTheta[trajpointcounter]: " << fData->TrajTheta[trajpointcounter] << std::endl;
6526  std::cout << "fData->TrajPhi[trajpointcounter]: " << fData->TrajPhi[trajpointcounter] << std::endl;
6527  }
6528 
6529  trajpointcounter++;
6530  }
6531  } // for particles
6532 
6533  fData->geant_trajectory_size = trajpointcounter;
6534  }// if (fSaveGeantTrajectoryInfo)
6535 
6536 
6538  {
6539  fData->simenergydeposit_size = nSimEnergyDepositsTPCActive;
6540  fData->particleswithsimenergydeposit_size = nParticlesWithSimEnergyDepositsTPCActive;
6541 
6542  // Find particle ID's for each particle with sim energy deposit in this event
6543  int particlewithsedit=0;
6544  for(int sedavit = 0; sedavit < nSimEnergyDepositsTPCActive; sedavit++)
6545  {
6546  if (std::find(fData->ParticleIDSimEnergyDepositsTPCActivePerParticle.begin(), fData->ParticleIDSimEnergyDepositsTPCActivePerParticle.end(), energyDepositTPCActivelist[sedavit]->TrackID()) == fData->ParticleIDSimEnergyDepositsTPCActivePerParticle.end() ) //check if current particle ID is already in the vector. if true: not in vector
6547  {
6548  fData->ParticleIDSimEnergyDepositsTPCActivePerParticle[particlewithsedit] = energyDepositTPCActivelist[sedavit]->TrackID();
6549 
6550  particlewithsedit++;
6551  }
6552  }
6553 
6554  //Sort particle ID's for each particle with sim energy deposit in this event by particle ID.
6555  std::sort(fData->ParticleIDSimEnergyDepositsTPCActivePerParticle.begin(), fData->ParticleIDSimEnergyDepositsTPCActivePerParticle.end());
6556 
6557 
6558  // Find number of sim energy deposits for each particle in this event and sort all SEDs by Particle ID.
6559  std::vector<int> it_sortedbyparticleID;
6560 
6561  int totalsed = 0;
6562  for(int psedavit = 0; psedavit < nParticlesWithSimEnergyDepositsTPCActive; psedavit++)
6563  {
6564  int NSEDForThisParticle = 0;
6565  for(int sedavit = 0; sedavit < nSimEnergyDepositsTPCActive; sedavit++)
6566  {
6567  if(energyDepositTPCActivelist[sedavit]->TrackID() == fData->ParticleIDSimEnergyDepositsTPCActivePerParticle[psedavit])
6568  {
6569  NSEDForThisParticle++;
6570  it_sortedbyparticleID.push_back(sedavit);
6571  }
6572  }
6573 
6574  fData->NSimEnergyDepositsTPCActivePerParticle[psedavit] = NSEDForThisParticle;
6575  totalsed += NSEDForThisParticle;
6576  }
6577 
6578 /*
6579  std::cout << std::endl;
6580  std::cout << "it_sortedbyparticleID.size(): " << it_sortedbyparticleID.size() << std::endl;
6581 
6582  for(int sedavit=0; sedavit < nSimEnergyDepositsTPCActive; sedavit++)
6583  {
6584  std::cout << std::endl;
6585  std::cout << "energyDepositTPCActivelist[" << sedavit << "]->TrackID(): " << energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->TrackID() << std::endl;
6586  std::cout << "energyDepositTPCActivelist[" << sedavit << "]->Time(): " << energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->Time() << std::endl;
6587  }
6588 */
6589 
6590 
6591 //Algorithm to sort SEDs by time
6592 /*
6593  //Now also sort SEDs by time
6594  //Sort by time (after sorting by particle ID)
6595  std::vector<int> it_sortedbyparticleIDandtime;
6596 
6597  int sedavit_currentparticle=0;
6598  int sedavit_mintime_currentparticle = -1;
6599 
6600 
6601  for(int psedavit = 0; psedavit < nParticlesWithSimEnergyDepositsTPCActive; psedavit++)
6602  {
6603  for(int NSEDForThisParticle = 0; NSEDForThisParticle < fData->NSimEnergyDepositsTPCActivePerParticle[psedavit]; NSEDForThisParticle++)
6604  {
6605  double mintime_currentparticle = 1e9;
6606 
6607  for(int sedavit = sedavit_currentparticle; sedavit < sedavit_currentparticle + fData->NSimEnergyDepositsTPCActivePerParticle[psedavit]; sedavit++)
6608  {
6609  if( energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->Time() < mintime_currentparticle && ( std::find(it_sortedbyparticleIDandtime.begin(), it_sortedbyparticleIDandtime.end(), sedavit) == it_sortedbyparticleIDandtime.end() ) )
6610  {
6611  mintime_currentparticle = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->Time();
6612  sedavit_mintime_currentparticle = sedavit;
6613  }
6614  }
6615  it_sortedbyparticleIDandtime.push_back(sedavit_mintime_currentparticle);
6616  }
6617  sedavit_currentparticle+=fData->NSimEnergyDepositsTPCActivePerParticle[psedavit];
6618  }
6619 
6620 */
6621 
6622 
6623 //Alternative algorithm to sort SEDs by time
6624 /*
6625  //Sort by time (after sorting by particle ID)
6626  std::vector<int> it_sortedbyparticleIDandtime;
6627  it_sortedbyparticleIDandtime.resize(nSimEnergyDepositsTPCActive);
6628  FillWith(it_sortedbyparticleIDandtime, -1);
6629 
6630  int sedavit_sortedbyparticleIDandtime = 0;
6631  int mintime_sedavit = -1;
6632  int psedavit=0;
6633 
6634  //for(int sedavit_sortedbyparticleIDandtime = 0; sedavit_sortedbyparticleIDandtime < nSimEnergyDepositsTPCActive; i++)
6635  //{
6636  while(sedavit_sortedbyparticleIDandtime < nSimEnergyDepositsTPCActive )
6637  {
6638  double mintime = 1e9;
6639  bool FoundSEDForThisParticleID = false;
6640  int NSEDForThisParticle = 0;
6641 
6642  for(int sedavit = 0; sedavit < nSimEnergyDepositsTPCActive; sedavit++)
6643  {
6644  if( energyDepositTPCActivelist[sedavit]->TrackID() == fData->ParticleIDSimEnergyDepositsTPCActivePerParticle[psedavit] )
6645  {
6646  if( energyDepositTPCActivelist[sedavit]->Time() < mintime && ( std::find(it_sortedbyparticleIDandtime.begin(), it_sortedbyparticleIDandtime.end(), sedavit) == it_sortedbyparticleIDandtime.end() ) )
6647  {
6648  mintime = energyDepositTPCActivelist[sedavit]->Time();
6649  mintime_sedavit = sedavit;
6650  FoundSEDForThisParticleID = true;
6651  }
6652  }
6653  }
6654 
6655  if( FoundSEDForThisParticleID )
6656  {
6657  it_sortedbyparticleIDandtime[sedavit_sortedbyparticleIDandtime] = mintime_sedavit;
6658  sedavit_sortedbyparticleIDandtime++;
6659  }
6660  else
6661  {
6662  psedavit++;
6663  }
6664  }
6665 */
6666 
6667  // For each energy deposit in this event (sorted by particle ID, not by time)
6668 
6669  for(int sedavit = 0; sedavit < nSimEnergyDepositsTPCActive; sedavit++)
6670  {
6671  fData->SEDTPCAVTrackID[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->TrackID();
6672  fData->SEDTPCAVPDGCode[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->PdgCode();
6673  fData->SEDTPCAVEnergy[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->Energy();
6674  fData->SEDTPCAVNumPhotons[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->NumPhotons();
6675  fData->SEDTPCAVNumElectrons[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->NumElectrons();
6676  fData->SEDTPCAVLength[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->StepLength();
6677 
6678  fData->SEDTPCAVStartTime[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->StartT();
6679  fData->SEDTPCAVStartX[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->StartX();
6680  fData->SEDTPCAVStartY[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->StartY();
6681  fData->SEDTPCAVStartZ[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->StartZ();
6682 
6683  fData->SEDTPCAVMidTime[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->Time();
6684  fData->SEDTPCAVMidX[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->MidPointX();
6685  fData->SEDTPCAVMidY[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->MidPointY();
6686  fData->SEDTPCAVMidZ[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->MidPointZ();
6687 
6688  fData->SEDTPCAVEndTime[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->EndT();
6689  fData->SEDTPCAVEndX[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->EndX();
6690  fData->SEDTPCAVEndY[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->EndY();
6691  fData->SEDTPCAVEndZ[sedavit] = energyDepositTPCActivelist[it_sortedbyparticleID[sedavit]]->EndZ();
6692 
6693 
6694  if(fLogLevel >= 5)
6695  {
6696  std::cout << std::endl;
6697  std::cout << "sedavit: " << sedavit << std::endl;
6698  std::cout << "fData->SEDTPCAVTrackID[" << sedavit << "]: " << fData->SEDTPCAVTrackID[sedavit] << std::endl;
6699  std::cout << "fData->SEDTPCAVPDGCode[" << sedavit << "]: " << fData->SEDTPCAVPDGCode[sedavit] << std::endl;
6700  std::cout << "fData->SEDTPCAVEnergy[" << sedavit << "]: " << fData->SEDTPCAVEnergy[sedavit] << std::endl;
6701  std::cout << "fData->SEDTPCAVNumPhotons[" << sedavit << "]: " << fData->SEDTPCAVNumPhotons[sedavit] << std::endl;
6702  std::cout << "fData->SEDTPCAVNumElectrons[" << sedavit << "]: " << fData->SEDTPCAVNumElectrons[sedavit] << std::endl;
6703 
6704  std::cout << "fData->SEDTPCAVLength[" << sedavit << "]: " << fData->SEDTPCAVLength[sedavit] << std::endl;
6705  std::cout << "fData->SEDTPCAVStartTime[" << sedavit << "]: " << fData->SEDTPCAVStartTime[sedavit] << std::endl;
6706  std::cout << "fData->SEDTPCAVStartX[" << sedavit << "]: " << fData->SEDTPCAVStartX[sedavit] << std::endl;
6707  std::cout << "fData->SEDTPCAVStartY[" << sedavit << "]: " << fData->SEDTPCAVStartY[sedavit] << std::endl;
6708  std::cout << "fData->SEDTPCAVStartZ[" << sedavit << "]: " << fData->SEDTPCAVStartZ[sedavit] << std::endl;
6709  std::cout << "fData->SEDTPCAVMidTime[" << sedavit << "]: " << fData->SEDTPCAVMidTime[sedavit] << std::endl;
6710  std::cout << "fData->SEDTPCAVMidX[" << sedavit << "]: " << fData->SEDTPCAVMidX[sedavit] << std::endl;
6711  std::cout << "fData->SEDTPCAVMidY[" << sedavit << "]: " << fData->SEDTPCAVMidY[sedavit] << std::endl;
6712  std::cout << "fData->SEDTPCAVMidZ[" << sedavit << "]: " << fData->SEDTPCAVMidZ[sedavit] << std::endl;
6713  std::cout << "fData->SEDTPCAVEndTime[" << sedavit << "]: " << fData->SEDTPCAVEndTime[sedavit] << std::endl;
6714  std::cout << "fData->SEDTPCAVEndX[" << sedavit << "]: " << fData->SEDTPCAVEndX[sedavit] << std::endl;
6715  std::cout << "fData->SEDTPCAVEndY[" << sedavit << "]: " << fData->SEDTPCAVEndY[sedavit] << std::endl;
6716  std::cout << "fData->SEDTPCAVEndZ[" << sedavit << "]: " << fData->SEDTPCAVEndZ[sedavit] << std::endl;
6717  }
6718  }
6719  }
6720  }//if (mcevts_truth)
6721  }//if (fIsMC){
6722 
6723  fData->taulife = detProp.ElectronLifetime();
6724 
6725  fTree->Fill();
6726 
6727  if (mf::isDebugEnabled()) {
6728  // use mf::LogDebug instead of MF_LOG_DEBUG because we reuse it in many lines;
6729  // thus, we protect this part of the code with the line above
6730  mf::LogDebug logStream("AnaRootParserStructure");
6731  logStream
6732  << "Tree data structure contains:"
6733  << "\n - " << fData->no_hits << " hits (" << fData->GetMaxHits() << ")"
6734  << "\n - " << fData->NHitsInAllTracks << " hits (" << fData->GetMaxHits() << ")"
6735  << "\n - " << fData->genie_no_primaries << " genie primaries (" << fData->GetMaxGeniePrimaries() << ")"
6736  << "\n - " << fData->geant_list_size << " GEANT particles (" << fData->GetMaxGEANTparticles() << "), "
6737  << fData->no_primaries << " primaries"
6738  << "\n - " << fData->geant_list_size_in_tpcAV << " GEANT particles in AV "
6739  << "\n - " << ((int) fData->kNTracker) << " trackers:"
6740  ;
6741 
6742  size_t iTracker = 0;
6743  for (auto tracker = fData->TrackData.cbegin();
6744  tracker != fData->TrackData.cend(); ++tracker, ++iTracker
6745  ) {
6746  logStream
6747  << "\n -> " << tracker->ntracks << " " << fTrackModuleLabel[iTracker]
6748  << " tracks (" << tracker->GetMaxTracks() << ")"
6749  ;
6750  for (int iTrk = 0; iTrk < tracker->ntracks; ++iTrk) {
6751  logStream << "\n [" << iTrk << "] "<< tracker->ntrkhitsperview[iTrk][0];
6752  for (size_t ipl = 1; ipl < tracker->GetMaxPlanesPerTrack(iTrk); ++ipl)
6753  logStream << " + " << tracker->ntrkhitsperview[iTrk][ipl];
6754  logStream << " hits (" << tracker->GetMaxHitsPerTrack(iTrk, 0);
6755  for (size_t ipl = 1; ipl < tracker->GetMaxPlanesPerTrack(iTrk); ++ipl)
6756  logStream << " + " << tracker->GetMaxHitsPerTrack(iTrk, ipl);
6757  logStream << ")";
6758  } // for tracks
6759  } // for trackers
6760  } // if logging enabled
6761 
6762  // if we don't use a permanent buffer (which can be huge),
6763  // delete the current buffer, and we'll create a new one on the next event
6764 
6765  if (!fUseBuffer) {
6766  MF_LOG_DEBUG("AnaRootParserStructure") << "Freeing the tree data structure";
6767  DestroyData();
6768  }
6769  } // dune::AnaRootParser::analyze()
double E(const int i=0) const
Definition: MCParticle.h:233
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void XYZ(double *xyz) const
Legacy method to access vertex position, preserved to avoid breaking code. Please try to use Vertex::...
Definition: Vertex.cxx:36
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:218
const TLorentzVector & Position(const int i=0) const
Definition: MCParticle.h:219
simb::Origin_t Origin() const
Definition: MCTrack.h:40
int PdgCode() const
Definition: MCParticle.h:212
std::vector< std::string > fCalorimetryModuleLabel
constexpr std::uint32_t timeLow() const
Definition: Timestamp.h:29
bool fSaveHitInfo
whether to extract and save MC Track information
void DestroyData()
Destroy the local buffers (existing branches will point to invalid address!)
double VertexMomentum() const
Definition: Track.h:142
const MCStep & End() const
Definition: MCShower.h:56
double Py(const int i=0) const
Definition: MCParticle.h:231
float SummedADCaverage() const
Returns the average signal ADC counts of the cluster hits.
Definition: Cluster.h:656
float IntegralAverage() const
Returns the average charge of the cluster hits.
Definition: Cluster.h:622
constexpr int kMaxClusters
std::vector< std::string > fMCT0FinderLabel
float bwdLogLikelihood() const
minimum negative log likelihood value from fit assuming a backward track direction ...
Definition: MCSFitResult.h:44
double EndE() const
Definition: MCParticle.h:244
const TLorentzVector & EndPosition() const
Definition: MCParticle.h:225
bool fSaveGeantTrajectoryInfo
whether to extract and save Geant information
bool fSaveGeantInfo
whether to extract and save Geant information
bool fSaveSimEnergyDepositTPCActiveInfo
whether to extract and save Geant information
std::map< art::Ptr< recob::PFParticle >, ClusterVector > PFParticlesToClusters
AdcChannelData::View View
unsigned int TrackID() const
Definition: MCShower.h:53
static bool IsNeutrino(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as a neutrino.
constexpr int kMaxNPFPNeutrinos
void HitsBackTrack(detinfo::DetectorClocksData const &clockData, art::Ptr< recob::Hit > const &hit, int &trackid, float &maxe, float &purity)
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
std::string string
Definition: nybbler.cc:12
unsigned int ID
bool fIsMC
whether to use a permanent buffer (faster, huge memory)
constexpr int kMaxVertices
const std::string & AncestorProcess() const
Definition: MCTrack.h:57
float bwdMomentum() const
momentum value from fit assuming a backward track direction
Definition: MCSFitResult.h:38
int Mother() const
Definition: MCParticle.h:213
size_t GetNVertexAlgos() const
std::string fSimEnergyDepositTPCActiveLabel
constexpr std::uint32_t timeHigh() const
Definition: Timestamp.h:34
simb::Origin_t Origin() const
Definition: MCTruth.h:74
double Mass() const
Definition: MCParticle.h:239
constexpr T pow(T x)
Definition: pow.h:72
constexpr int kMaxHits
bool fSaveGenieInfo
whether to extract and save CRY particle data
double Px(const int i=0) const
Definition: MCParticle.h:230
const MCStep & MotherEnd() const
Definition: MCTrack.h:53
unsigned int AncestorTrackID() const
Definition: MCTrack.h:56
static std::unique_ptr< FVectorReader > create(const art::Event &evt, const art::InputTag &tag)
Definition: MVAReader.h:29
size_t GetNTrackers() const
Returns the number of trackers configured.
size_t NumberTrajectoryPoints() const
Various functions related to the presence and the number of (valid) points.
Definition: Track.h:102
float StartWire() const
Returns the wire coordinate of the start of the cluster.
Definition: Cluster.h:286
int PdgCode() const
Definition: MCShower.h:52
Vector_t VertexDirection() const
Definition: Track.h:132
static bool IsShower(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as shower-like.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
int StatusCode() const
Definition: MCParticle.h:211
std::pair< float, std::string > P
int PdgCode() const
Return the type of particle as a PDG ID.
Definition: PFParticle.h:83
bool isCosmics
if it contains cosmics
Set of hits with a 2D structure.
Definition: Cluster.h:71
std::vector< art::Ptr< recob::Shower > > ShowerVector
intermediate_table::const_iterator const_iterator
float EndTick() const
Returns the tick coordinate of the end of the cluster.
Definition: Cluster.h:342
std::string fPandoraNuVertexModuleLabel
int NParticles() const
Definition: MCTruth.h:75
float MultipleHitDensity() const
Density of wires in the cluster with more than one hit.
Definition: Cluster.h:723
string dir
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Cluster finding and building.
std::string Process() const
Definition: MCParticle.h:215
std::vector< std::string > fMVAPIDTrackModuleLabel
bool fSaveGeantInAVInfo
whether to extract and save Geant information
int AncestorPdgCode() const
Definition: MCTrack.h:55
std::string fExternalCounterModuleLabel
bool isValid() const
Returns if the cluster is valid (that is, if its ID is not invalid)
Definition: Cluster.h:753
const MCStep & End() const
Definition: MCTrack.h:45
float StartAngle() const
Returns the starting angle of the cluster.
Definition: Cluster.h:475
bool fUseBuffer
whether to use a permanent buffer (faster, huge memory)
geo::Length_t WirePitch(geo::PlaneID const &planeid) const
Returns the distance between two consecutive wires.
void CreateTree(bool bClearData=false)
Create the output tree and the data structures, if needed.
std::map< art::Ptr< recob::PFParticle >, TrackVector > PFParticlesToTracks
const art::Ptr< simb::MCTruth > & ParticleToMCTruth_P(const simb::MCParticle *p) const
int NumberDaughters() const
Definition: MCParticle.h:217
unsigned int MotherTrackID() const
Definition: MCTrack.h:50
std::map< art::Ptr< recob::PFParticle >, VertexVector > PFParticlesToVertices
int TrackId() const
Definition: MCParticle.h:210
recob::MCSFitResult fitMcs(const recob::TrackTrajectory &traj) const
bool fSaveGeneratorInfo
whether to extract and save collected photons
bool isValid() const noexcept
Definition: Handle.h:191
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
const TVector3 & StartDir() const
Definition: MCShower.h:82
Collection of particles crossing one auxiliary detector cell.
std::vector< std::string > fShowerModuleLabel
bool fSavePFParticleInfo
whether to extract and save Shower information
T abs(T value)
float EndCharge() const
Returns the charge on the last wire of the cluster.
Definition: Cluster.h:498
double dEdx(float dqdx, float Efield)
Definition: doAna.cpp:21
float SummedADC() const
Returns the total charge of the cluster from signal ADC counts.
Definition: Cluster.h:634
double bdist(const TVector3 &pos)
float bestMomentum() const
momentum for best direction fit
Definition: MCSFitResult.h:56
simb::Origin_t Origin() const
Definition: MCShower.h:50
std::vector< std::string > fCosmicTaggerAssocLabel
whether to extract and save PFParticle information
std::map< art::Ptr< recob::PFParticle >, ShowerVector > PFParticlesToShowers
double Px() const
Definition: MCStep.h:46
Timestamp time() const
bool fSaveExternCounterInfo
whether to extract and save Flash information
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
int MotherPdgCode() const
Definition: MCShower.h:58
const std::string & AncestorProcess() const
Definition: MCShower.h:66
std::vector< art::Ptr< recob::PFParticle > > PFParticleVector
std::void_t< T > n
static void CollectShowers(const art::Event &evt, const std::string &label, ShowerVector &showerVector, PFParticlesToShowers &particlesToShowers)
Collect the reconstructed PFParticles and associated Showers from the ART event record.
trkf::TrajectoryMCSFitter fMCSFitter
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
Definition: DataViewImpl.h:479
float Chi2PerNdof() const
Definition: Track.h:169
double P(const int i=0) const
Definition: MCParticle.h:234
key_type key() const noexcept
Definition: Ptr.h:216
void CreateData(bool bClearData=false)
Creates the structure for the tree data; optionally initializes it.
bool fSavePhotonInfo
whether to extract and save ProtDUNE beam simulation information
float Width() const
A measure of the cluster width, in homogenized units.
Definition: Cluster.h:727
constexpr int kMaxFlashes
std::vector< std::string > fFlashT0FinderLabel
Point_t const & Vertex() const
Definition: Track.h:124
std::vector< std::string > fContainmentTaggerAssocLabel
static void CollectVertices(const art::Event &evt, const std::string &label, VertexVector &vertexVector, PFParticlesToVertices &particlesToVertices)
Collect the reconstructed PFParticles and associated Vertices from the ART event record.
void SetVertexAddresses(size_t iVertexAlg)
double T(const int i=0) const
Definition: MCParticle.h:224
double length(const recob::Track &track)
double Z() const
Definition: MCStep.h:44
bool fSaveShowerInfo
whether to extract and save External Counter information
constexpr int kMaxTruth
size_t NPoints() const
Definition: Track.h:103
std::unique_ptr< AnaRootParserDataStruct > fData
SubRunNumber_t subRun() const
Definition: DataViewImpl.cc:78
bool fSaveProtoInfo
whether to extract and save Genie information
bool IsPrimary() const
Returns whether the particle is the root of the flow.
Definition: PFParticle.h:86
bool isDebugEnabled()
size_t GetNShowerAlgos() const
Returns the number of shower algorithms configured.
double Py() const
Definition: MCStep.h:47
bool fSaveCaloCosmics
save calorimetry information for cosmics
double Y() const
Definition: MCStep.h:43
std::vector< art::Ptr< recob::Track > > TrackVector
const MCStep & AncestorStart() const
Definition: MCShower.h:67
RunNumber_t run() const
Definition: DataViewImpl.cc:71
static int max(int a, int b)
double EndT() const
Definition: MCParticle.h:229
constexpr unsigned short kMaxAuxDets
max number of auxiliary detector cells per MC particle
void FillShowers(AnaRootParserDataStruct::ShowerDataStruct &showerData, std::vector< recob::Shower > const &showers, const bool fSavePFParticleInfo, const std::map< Short_t, Short_t > &showerIDtoPFParticleIDMap) const
Stores the information of all showers into showerData.
const MCStep & AncestorStart() const
Definition: MCTrack.h:58
static void CollectTracks(const art::Event &evt, const std::string &label, TrackVector &trackVector, PFParticlesToTracks &particlesToTracks)
Collect the reconstructed PFParticles and associated Tracks from the ART event record.
const std::string & MotherProcess() const
Definition: MCShower.h:60
double driftedLength(detinfo::DetectorPropertiesData const &detProp, const simb::MCParticle &part, TLorentzVector &start, TLorentzVector &end, unsigned int &starti, unsigned int &endi)
static void CollectPFParticles(const art::Event &evt, const std::string &label, PFParticleVector &particleVector)
Collect the reconstructed PFParticles from the ART event record.
double dEdx() const
Definition: MCShower.h:81
unsigned int AncestorTrackID() const
Definition: MCShower.h:65
bool fSaveRecobWireInfo
whether to extract and save raw digit information
int Ndof() const
Definition: Track.h:170
bool bIgnoreMissingShowers
whether to ignore missing shower information
const MCStep & AncestorEnd() const
Definition: MCShower.h:68
int PdgCode() const
Definition: MCTrack.h:41
const MCStep & DetProfile() const
Definition: MCShower.h:70
std::vector< std::string > fVertexModuleLabel
const sim::ParticleList & ParticleList() const
Class storing the result of the Maximum Likelihood fit of Multiple Coulomb Scattering angles between ...
Definition: MCSFitResult.h:19
bool fSavePandoraNuVertexInfo
whether to extract and save Cluster information
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
static void SelectNeutrinoPFParticles(const PFParticleVector &inputParticles, PFParticleVector &outputParticles)
Select reconstructed neutrino particles from a list of all reconstructed particles.
bool fSaveRawDigitInfo
whether to extract and save Hit information
bool fSaveMCShowerInfo
whether to extract and save Cluster information
bool fSaveClusterInfo
whether to extract and save Vertex information
const MCStep & Start() const
Definition: MCShower.h:55
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
double Vx(const int i=0) const
Definition: MCParticle.h:221
int ID() const
Definition: Track.h:198
geo::View_t View() const
Returns the view for this cluster.
Definition: Cluster.h:741
constexpr int kMaxExternCounts
const MCStep & MotherStart() const
Definition: MCTrack.h:52
void SetTrackerAddresses(size_t iTracker)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
int MotherPdgCode() const
Definition: MCTrack.h:49
const MCStep & MotherEnd() const
Definition: MCShower.h:62
float StartCharge() const
Returns the charge on the first wire of the cluster.
Definition: Cluster.h:454
bool fSaveFlashInfo
whether to extract and save nu vertex information from Pandora
ID_t ID() const
Identifier of this cluster.
Definition: Cluster.h:738
bool fSaveAuxDetInfo
whether to extract and save auxiliary detector data
std::vector< std::string > fMVAPIDShowerModuleLabel
bool fSaveTrackInfo
whether to extract and save recob wire information
Vector_t EndDirection() const
Definition: Track.h:133
MC truth information to make RawDigits and do back tracking.
const TLorentzVector & Momentum(const int i=0) const
Definition: MCParticle.h:220
const std::string & Process() const
Definition: MCTrack.h:43
const std::string & MotherProcess() const
Definition: MCTrack.h:51
std::vector< std::string > fFlashMatchAssocLabel
#define MF_LOG_DEBUG(id)
static bool IsTrack(const art::Ptr< recob::PFParticle > particle)
Determine whether a particle has been reconstructed as track-like.
double Pz(const int i=0) const
Definition: MCParticle.h:232
float fwdLogLikelihood() const
minimum negative log likelihood value from fit assuming a forward track direction ...
Definition: MCSFitResult.h:35
double E() const
Definition: MCStep.h:49
unsigned int MotherTrackID() const
Definition: MCShower.h:59
double Vz(const int i=0) const
Definition: MCParticle.h:223
const std::string & Process() const
Definition: MCShower.h:54
double Pz() const
Definition: MCStep.h:48
std::vector< art::Ptr< recob::Vertex > > VertexVector
EventNumber_t event() const
Definition: EventID.h:116
Point_t const & End() const
Definition: Track.h:125
const MCStep & MotherStart() const
Definition: MCShower.h:61
detail::Node< FrameID, bool > PlaneID
Definition: CRTID.h:125
const MCStep & Start() const
Definition: MCTrack.h:44
bool fSaveMCTrackInfo
whether to extract and save MC Shower information
double X() const
Definition: MCStep.h:42
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:500
std::vector< art::Ptr< recob::Cluster > > ClusterVector
unsigned int NHits() const
Number of hits in the cluster.
Definition: Cluster.h:275
unsigned int TrackID() const
Definition: MCTrack.h:42
bool NeutrinoSet() const
Definition: MCTruth.h:78
AnaRootParserDataStruct::SubRunData_t SubRunData
int AncestorPdgCode() const
Definition: MCShower.h:64
float fwdMomentum() const
momentum value from fit assuming a forward track direction
Definition: MCSFitResult.h:29
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
std::map< std::string, double > mvaOutput
Definition: MVAPIDResult.h:27
float EndAngle() const
Returns the ending angle of the cluster.
Definition: Cluster.h:519
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
recob::tracking::Plane Plane
Definition: TrackState.h:17
constexpr int kMaxReadoutTicksInAllChannels
float StartTick() const
Returns the tick coordinate of the start of the cluster.
Definition: Cluster.h:297
std::vector< std::string > fTrackModuleLabel
double WireAngleToVertical(geo::View_t view, geo::TPCID const &tpcid) const
Returns the angle of the wires in the specified view from vertical.
EventID id() const
Definition: Event.cc:34
double Vy(const int i=0) const
Definition: MCParticle.h:222
const MCStep & AncestorEnd() const
Definition: MCTrack.h:59
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
Definition: Track.h:49
bool fSaveVertexInfo
whether to extract and save Track information
Cosmic rays.
Definition: MCTruth.h:24
QTextStream & endl(QTextStream &s)
float Integral() const
Returns the total charge of the cluster from hit shape.
Definition: Cluster.h:600
float EndWire() const
Returns the wire coordinate of the end of the cluster.
Definition: Cluster.h:329
vertex reconstruction
double dune::AnaRootParser::bdist ( const TVector3 &  pos)
private

Definition at line 6891 of file AnaRootParser_module.cc.

6892  {
6893  double d1 = -ActiveBounds[0] + pos.X();
6894  double d2 = ActiveBounds[1] - pos.X();
6895  double d3 = -ActiveBounds[2] + pos.Y();
6896  double d4 = ActiveBounds[3] - pos.Y();
6897  double d5 = -ActiveBounds[4] + pos.Z();
6898  double d6 = ActiveBounds[5] - pos.Z();
6899 
6900  double Xmin = std::min(d1, d2);
6901  double result = 0;
6902  if (Xmin<0) result = std::min(std::min(std::min( d3, d4), d5), d6); // - FIXME Passing uncorrected hits means X positions are very wrong ( outside of ActiveVolume )
6903  else result = std::min(std::min(std::min(std::min(Xmin, d3), d4), d5), d6);
6904  if (result<-1) result = -1;
6905  /*
6906  std::cout << "\n" << std::endl;
6907  std::cout << "-"<<ActiveBounds[0]<<" + "<<pos.X()<< " = " << d1 << "\n"
6908  << ActiveBounds[1]<<" - "<<pos.X()<< " = " << d2 << "\n"
6909  << "-"<<ActiveBounds[2]<<" + "<<pos.Y()<< " = " << d3 << "\n"
6910  << ActiveBounds[3]<<" - "<<pos.Y()<< " = " << d4 << "\n"
6911  << "-"<<ActiveBounds[4]<<" + "<<pos.Z()<< " = " << d5 << "\n"
6912  << ActiveBounds[5]<<" - "<<pos.Z()<< " = " << d6 << "\n"
6913  << "And the Minimum is " << result << std::endl;
6914  */
6915  return result;
6916  }
static QCString result
double ActiveBounds[6]
objet holding the configuration of the uBoone MCS fitting alg
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void dune::AnaRootParser::beginSubRun ( const art::SubRun sr)

Definition at line 4173 of file AnaRootParser_module.cc.

4174 {
4175 
4176  // auto potListHandle = sr.getHandle< sumdata::POTSummary >(fPOTModuleLabel);
4177  // if(potListHandle)
4178  // SubRunData.pot=potListHandle->totpot;
4179  // else
4180  // SubRunData.pot=0.;
4181 
4182 }
void dune::AnaRootParser::CheckData ( std::string  caller) const
inlineprivate

Helper function: throws if no data structure is available.

Definition at line 1594 of file AnaRootParser_module.cc.

1595  {
1596  if (fData) return;
1598  << "AnaRootParser::" << caller << ": no data";
1599  } // CheckData()
std::unique_ptr< AnaRootParserDataStruct > fData
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void dune::AnaRootParser::CheckTree ( std::string  caller) const
inlineprivate

Helper function: throws if no tree is available.

Definition at line 1601 of file AnaRootParser_module.cc.

1602  {
1603  if (fTree) return;
1605  << "AnaRootParser::" << caller << ": no tree";
1606  } // CheckData()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
int dune::AnaRootParser::CountHits ( const art::Event evt,
const art::InputTag which,
unsigned int  cryostat,
unsigned int  tpc,
unsigned int  plane 
)
private

Definition at line 7054 of file AnaRootParser_module.cc.

7059  {
7060  std::vector<const recob::Hit*> temp;
7061  int NumberOfHitsBeforeThisPlane=0;
7062  evt.getView(which, temp); //temp.size() = total number of hits for this event (number of all hits in all Cryostats, TPC's, planes and wires)
7063  for(size_t t = 0; t < temp.size(); ++t){
7064  if( temp[t]->WireID().Cryostat == cryostat&& temp[t]->WireID().TPC == tpc && temp[t]->WireID().Plane == plane ) break;
7065  NumberOfHitsBeforeThisPlane++;
7066  }
7067  return NumberOfHitsBeforeThisPlane;
7068  }
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
Definition: DataViewImpl.h:500
void dune::AnaRootParser::CreateData ( bool  bClearData = false)
inlineprivate

Creates the structure for the tree data; optionally initializes it.

Definition at line 1494 of file AnaRootParser_module.cc.

1495  {
1496  if (!fData) {
1497  fData.reset
1498  (new AnaRootParserDataStruct(GetNTrackers(), GetNVertexAlgos(), GetShowerAlgos()));
1522  }
1523  else {
1524  fData->SetTrackers(GetNTrackers());
1525  fData->SetVertexAlgos(GetNVertexAlgos());
1526  fData->SetShowerAlgos(GetShowerAlgos());
1527  if (bClearData) fData->Clear();
1528  }
1529  } // CreateData()
bool fSaveHitInfo
whether to extract and save MC Track information
bool fSaveGeantTrajectoryInfo
whether to extract and save Geant information
bool fSaveGeantInfo
whether to extract and save Geant information
bool fSaveSimEnergyDepositTPCActiveInfo
whether to extract and save Geant information
size_t GetNVertexAlgos() const
bool fSaveGenieInfo
whether to extract and save CRY particle data
size_t GetNTrackers() const
Returns the number of trackers configured.
bool fSaveGeantInAVInfo
whether to extract and save Geant information
std::vector< std::string > GetShowerAlgos() const
Returns the name of configured shower algorithms (converted to string)
bool fSaveGeneratorInfo
whether to extract and save collected photons
bool fSavePFParticleInfo
whether to extract and save Shower information
bool fSaveExternCounterInfo
whether to extract and save Flash information
bool fSavePhotonInfo
whether to extract and save ProtDUNE beam simulation information
bool fSaveShowerInfo
whether to extract and save External Counter information
std::unique_ptr< AnaRootParserDataStruct > fData
bool fSaveProtoInfo
whether to extract and save Genie information
bool fSaveRecobWireInfo
whether to extract and save raw digit information
bool fSavePandoraNuVertexInfo
whether to extract and save Cluster information
bool fSaveRawDigitInfo
whether to extract and save Hit information
bool fSaveMCShowerInfo
whether to extract and save Cluster information
bool fSaveClusterInfo
whether to extract and save Vertex information
bool fSaveFlashInfo
whether to extract and save nu vertex information from Pandora
bool fSaveAuxDetInfo
whether to extract and save auxiliary detector data
bool fSaveTrackInfo
whether to extract and save recob wire information
bool fSaveMCTrackInfo
whether to extract and save MC Shower information
bool fSaveVertexInfo
whether to extract and save Track information
void dune::AnaRootParser::CreateTree ( bool  bClearData = false)
private

Create the output tree and the data structures, if needed.

Definition at line 4155 of file AnaRootParser_module.cc.

4155  {
4156  if (!fTree) {
4158  fTree = tfs->make<TTree>("anatree","analysis tree");
4159  }
4160  /* if (!fPOT) {
4161  art::ServiceHandle<art::TFileService> tfs;
4162  fPOT = tfs->make<TTree>("pottree","pot tree");
4163  fPOT->Branch("pot",&SubRunData.pot,"pot/D");
4164  fPOT->Branch("potbnbETOR860",&SubRunData.potbnbETOR860,"potbnbETOR860/D");
4165  fPOT->Branch("potbnbETOR875",&SubRunData.potbnbETOR875,"potbnbETOR875/D");
4166  fPOT->Branch("potnumiETORTGT",&SubRunData.potnumiETORTGT,"potnumiETORTGT/D");
4167  }*/
4168  CreateData(bClearData);
4169  SetAddresses();
4170 } // dune::AnaRootParser::CreateTree()
void SetAddresses()
Sets the addresses of all the tree branches, creating the missing ones.
void CreateData(bool bClearData=false)
Creates the structure for the tree data; optionally initializes it.
void dune::AnaRootParser::DestroyData ( )
inlineprivate

Destroy the local buffers (existing branches will point to invalid address!)

Definition at line 1591 of file AnaRootParser_module.cc.

1591 { fData.reset(); }
std::unique_ptr< AnaRootParserDataStruct > fData
double dune::AnaRootParser::driftedLength ( detinfo::DetectorPropertiesData const &  detProp,
const simb::MCParticle part,
TLorentzVector &  start,
TLorentzVector &  end,
unsigned int &  starti,
unsigned int &  endi 
)
private

Definition at line 6976 of file AnaRootParser_module.cc.

6978  {
6979  auto const* geom = lar::providerFrom<geo::Geometry>();
6980 
6981  //compute the drift x range
6982  double vDrift = detProp.DriftVelocity()*1e-3; //cm/ns
6983  double xrange[2] = {DBL_MAX, -DBL_MAX };
6984  for (unsigned int c=0; c<geom->Ncryostats(); ++c) {
6985  for (unsigned int t=0; t<geom->NTPC(c); ++t) {
6986  double Xat0 = detProp.ConvertTicksToX(0,0,t,c);
6987  double XatT = detProp.ConvertTicksToX(detProp.NumberTimeSamples(),0,t,c);
6988  xrange[0] = std::min(std::min(Xat0, XatT), xrange[0]);
6989  xrange[1] = std::max(std::max(Xat0, XatT), xrange[1]);
6990  }
6991  }
6992 
6993  double result = 0.;
6994  TVector3 disp;
6995  bool first = true;
6996 
6997  for(unsigned int i = 0; i < p.NumberTrajectoryPoints(); ++i) {
6998  // check if the particle is inside a TPC
6999  if (p.Vx(i) >= ActiveBounds[0] && p.Vx(i) <= ActiveBounds[1] &&
7000  p.Vy(i) >= ActiveBounds[2] && p.Vy(i) <= ActiveBounds[3] &&
7001  p.Vz(i) >= ActiveBounds[4] && p.Vz(i) <= ActiveBounds[5]){
7002  // Doing some manual shifting to account for
7003  // an interaction not occuring with the beam dump
7004  // we will reconstruct an x distance different from
7005  // where the particle actually passed to to the time
7006  // being different from in-spill interactions
7007  double newX = p.Vx(i)+(p.T(i)*vDrift);
7008  if (newX < xrange[0] || newX > xrange[1]) continue;
7009  TLorentzVector pos(newX,p.Vy(i),p.Vz(i),p.T());
7010  if(first){
7011  start = pos;
7012  starti=i;
7013  first = false;
7014  }
7015  else {
7016  disp -= pos.Vect();
7017  result += disp.Mag();
7018  }
7019  disp = pos.Vect();
7020  end = pos;
7021  endi = i;
7022  }
7023  }
7024  return result;
7025  }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static QCString result
double ActiveBounds[6]
objet holding the configuration of the uBoone MCS fitting alg
const double e
p
Definition: test.py:223
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
double dune::AnaRootParser::driftedLength ( detinfo::DetectorPropertiesData const &  detProp,
const sim::MCTrack mctrack,
TLorentzVector &  tpcstart,
TLorentzVector &  tpcend,
TLorentzVector &  tpcmom 
)
private

Definition at line 6925 of file AnaRootParser_module.cc.

6926  {
6927  auto const* geom = lar::providerFrom<geo::Geometry>();
6928 
6929  //compute the drift x range
6930  double vDrift = detProp.DriftVelocity()*1e-3; //cm/ns
6931  double xrange[2] = {DBL_MAX, -DBL_MAX };
6932  for (unsigned int c=0; c<geom->Ncryostats(); ++c) {
6933  for (unsigned int t=0; t<geom->NTPC(c); ++t) {
6934  double Xat0 = detProp.ConvertTicksToX(0,0,t,c);
6935  double XatT = detProp.ConvertTicksToX(detProp.NumberTimeSamples(),0,t,c);
6936  xrange[0] = std::min(std::min(Xat0, XatT), xrange[0]);
6937  xrange[1] = std::max(std::max(Xat0, XatT), xrange[1]);
6938  }
6939  }
6940 
6941  double result = 0.;
6942  TVector3 disp;
6943  bool first = true;
6944 
6945  for(auto step: mctrack) {
6946  // check if the particle is inside a TPC
6947  if (step.X() >= ActiveBounds[0] && step.X() <= ActiveBounds[1] &&
6948  step.Y() >= ActiveBounds[2] && step.Y() <= ActiveBounds[3] &&
6949  step.Z() >= ActiveBounds[4] && step.Z() <= ActiveBounds[5] ){
6950  // Doing some manual shifting to account for
6951  // an interaction not occuring with the beam dump
6952  // we will reconstruct an x distance different from
6953  // where the particle actually passed to to the time
6954  // being different from in-spill interactions
6955  double newX = step.X()+(step.T()*vDrift);
6956  if (newX < xrange[0] || newX > xrange[1]) continue;
6957 
6958  TLorentzVector pos(newX,step.Y(),step.Z(),step.T());
6959  if(first){
6960  tpcstart = pos;
6961  tpcmom = step.Momentum();
6962  first = false;
6963  }
6964  else {
6965  disp -= pos.Vect();
6966  result += disp.Mag();
6967  }
6968  disp = pos.Vect();
6969  tpcend = pos;
6970  }
6971  }
6972  return result;
6973  }
static QCString result
double ActiveBounds[6]
objet holding the configuration of the uBoone MCS fitting alg
const double e
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void dune::AnaRootParser::endSubRun ( const art::SubRun sr)

Definition at line 4184 of file AnaRootParser_module.cc.

4185 {
4186 
4187  /* auto potListHandle = sr.getHandle< sumdata::POTSummary >(fPOTModuleLabel);
4188  if (potListHandle)
4189  SubRunData.pot=potListHandle->totpot;
4190  else
4191  SubRunData.pot=0.;
4192 
4193  art::InputTag itag1("beamdata","bnbETOR860");
4194  auto potSummaryHandlebnbETOR860 = sr.getHandle<sumdata::POTSummary>(itag1);
4195  if (potSummaryHandlebnbETOR860){
4196  SubRunData.potbnbETOR860 = potSummaryHandlebnbETOR860->totpot;
4197  }
4198  else
4199  SubRunData.potbnbETOR860 = 0;
4200 
4201  art::InputTag itag2("beamdata","bnbETOR875");
4202  auto potSummaryHandlebnbETOR875 = sr.getHandle<sumdata::POTSummary>(itag2);
4203  if (potSummaryHandlebnbETOR875){
4204  SubRunData.potbnbETOR875 = potSummaryHandlebnbETOR875->totpot;
4205  }
4206  else
4207  SubRunData.potbnbETOR875 = 0;
4208 
4209  art::InputTag itag3("beamdata","numiETORTGT");
4210  auto potSummaryHandlenumiETORTGT = sr.getHandle<sumdata::POTSummary>(itag3);
4211  if (potSummaryHandlenumiETORTGT){
4212  SubRunData.potnumiETORTGT = potSummaryHandlenumiETORTGT->totpot;
4213  }
4214  else
4215  SubRunData.potnumiETORTGT = 0;
4216 
4217  if (fPOT) fPOT->Fill();
4218  */
4219 }
void dune::AnaRootParser::FillShower ( AnaRootParserDataStruct::ShowerDataStruct showerData,
size_t  iShower,
recob::Shower const &  showers,
const bool  fSavePFParticleInfo,
const std::map< Short_t, Short_t > &  showerIDtoPFParticleIDMap 
) const
private

Stores the information of shower in slot iShower of showerData.

Definition at line 6772 of file AnaRootParser_module.cc.

6775  {
6776 
6777  showerData.showerID[iShower] = shower.ID();
6778  showerData.shwr_bestplane[iShower] = shower.best_plane();
6779  showerData.shwr_length[iShower] = shower.Length();
6780 
6781  TVector3 const& dir_start = shower.Direction();
6782  showerData.shwr_startdcosx[iShower] = dir_start.X();
6783  showerData.shwr_startdcosy[iShower] = dir_start.Y();
6784  showerData.shwr_startdcosz[iShower] = dir_start.Z();
6785 
6786  TVector3 const& pos_start = shower.ShowerStart();
6787  showerData.shwr_startx[iShower] = pos_start.X();
6788  showerData.shwr_starty[iShower] = pos_start.Y();
6789  showerData.shwr_startz[iShower] = pos_start.Z();
6790 
6791  if (fSavePFParticleInfo) {
6792  auto mapIter = showerIDtoPFParticleIDMap.find(shower.ID());
6793  if (mapIter != showerIDtoPFParticleIDMap.end()) {
6794  // This vertex has a corresponding PFParticle.
6795  showerData.shwr_hasPFParticle[iShower] = 1;
6796  showerData.shwr_PFParticleID[iShower] = mapIter->second;
6797  }
6798  else
6799  showerData.shwr_hasPFParticle[iShower] = 0;
6800  }
6801 
6802  if (shower.Energy().size() == kNplanes)
6803  std::copy_n
6804  (shower.Energy().begin(), kNplanes, &showerData.shwr_totEng[iShower][0]);
6805  if (shower.dEdx().size() == kNplanes)
6806  std::copy_n
6807  (shower.dEdx().begin(), kNplanes, &showerData.shwr_dedx[iShower][0]);
6808  if (shower.MIPEnergy().size() == kNplanes)
6809  std::copy_n
6810  (shower.MIPEnergy().begin(), kNplanes, &showerData.shwr_mipEng[iShower][0]);
6811 
6812  } // dune::AnaRootParser::FillShower()
bool fSavePFParticleInfo
whether to extract and save Shower information
constexpr int kNplanes
void dune::AnaRootParser::FillShowers ( AnaRootParserDataStruct::ShowerDataStruct showerData,
std::vector< recob::Shower > const &  showers,
const bool  fSavePFParticleInfo,
const std::map< Short_t, Short_t > &  showerIDtoPFParticleIDMap 
) const
private

Stores the information of all showers into showerData.

Definition at line 6815 of file AnaRootParser_module.cc.

6818  {
6819 
6820  const size_t NShowers = showers.size();
6821 
6822  //
6823  // prepare the data structures, the tree and the connection between them
6824  //
6825 
6826  // allocate enough space for this number of showers
6827  // (but at least for one of them!)
6828  showerData.SetMaxShowers(std::max(NShowers, (size_t) 1));
6829  showerData.Clear(); // clear all the data
6830 
6831  // now set the tree addresses to the newly allocated memory;
6832  // this creates the tree branches in case they are not there yet
6833  showerData.SetAddresses(fTree);
6834  if (NShowers > showerData.GetMaxShowers()) {
6835  // got this error? it might be a bug,
6836  // since we are supposed to have allocated enough space to fit all showers
6837  mf::LogError("AnaRootParser:limits") << "event has " << NShowers
6838  << " " << showerData.Name() << " showers, only "
6839  << showerData.GetMaxShowers() << " stored in tree";
6840  }
6841 
6842  //
6843  // now set the data
6844  //
6845  // set the record of the number of showers
6846  // (data structures are already properly resized)
6847  showerData.nshowers = (Short_t) NShowers;
6848 
6849  // set all the showers one by one
6850  for (size_t i = 0; i < NShowers; ++i) FillShower(showerData, i, showers[i], fSavePFParticleInfo, showerIDtoPFParticleIDMap);
6851 
6852  } // dune::AnaRootParser::FillShowers()
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
void FillShower(AnaRootParserDataStruct::ShowerDataStruct &showerData, size_t iShower, recob::Shower const &showers, const bool fSavePFParticleInfo, const std::map< Short_t, Short_t > &showerIDtoPFParticleIDMap) const
Stores the information of shower in slot iShower of showerData.
bool fSavePFParticleInfo
whether to extract and save Shower information
static int max(int a, int b)
size_t dune::AnaRootParser::GetNShowerAlgos ( ) const
inlineprivate

Returns the number of shower algorithms configured.

Definition at line 1487 of file AnaRootParser_module.cc.

1487 { return fShowerModuleLabel.size(); }
std::vector< std::string > fShowerModuleLabel
size_t dune::AnaRootParser::GetNTrackers ( ) const
inlineprivate

Returns the number of trackers configured.

Definition at line 1482 of file AnaRootParser_module.cc.

1482 { return fTrackModuleLabel.size(); }
std::vector< std::string > fTrackModuleLabel
size_t dune::AnaRootParser::GetNVertexAlgos ( ) const
inlineprivate

Definition at line 1484 of file AnaRootParser_module.cc.

1484 { return fVertexModuleLabel.size(); }
std::vector< std::string > fVertexModuleLabel
std::vector<std::string> dune::AnaRootParser::GetShowerAlgos ( ) const
inlineprivate

Returns the name of configured shower algorithms (converted to string)

Definition at line 1490 of file AnaRootParser_module.cc.

1491  { return { fShowerModuleLabel.begin(), fShowerModuleLabel.end() }; }
std::vector< std::string > fShowerModuleLabel
void dune::AnaRootParser::HitsBackTrack ( detinfo::DetectorClocksData const &  clockData,
art::Ptr< recob::Hit > const &  hit,
int &  trackid,
float &  maxe,
float &  purity 
)
private

Definition at line 6856 of file AnaRootParser_module.cc.

6856  {
6857 
6858  trackid = -1;
6859  purity = -1;
6860 
6862 
6863  std::map<int,double> trkide;
6864  std::vector<sim::IDE> ides;
6865 
6866  //bt_serv->HitToSimIDEs(hit,ides);
6867  std::vector<sim::TrackIDE> eveIDs = bt_serv->HitToEveTrackIDEs(clockData, hit);
6868 
6869  for(size_t e = 0; e < eveIDs.size(); ++e){
6870  //std::cout<<" "<<e<<" "<<eveIDs[e].trackID<<" "<<eveIDs[e].energy<<" "<<eveIDs[e].energyFrac<<std::endl;
6871  trkide[eveIDs[e].trackID] += eveIDs[e].energy;
6872  }
6873 
6874  maxe = 0;
6875  double tote = 0;
6876  for (std::map<int,double>::iterator ii = trkide.begin(); ii!=trkide.end(); ++ii){
6877  tote += ii->second;
6878  if ((ii->second)>maxe){
6879  maxe = ii->second;
6880  trackid = ii->first;
6881  }
6882  }
6883 
6884  //std::cout << "the total energy of this reco track is: " << tote << std::endl;
6885  if (tote>0){
6886  purity = maxe/tote;
6887  }
6888  }
intermediate_table::iterator iterator
const double e
std::vector< sim::TrackIDE > HitToEveTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
double dune::AnaRootParser::length ( const recob::Track track)
private

Definition at line 6919 of file AnaRootParser_module.cc.

6920  {
6921  return track.Length();
6922  }
double Length(size_t p=0) const
Access to various track properties.
Definition: Track.h:167
double dune::AnaRootParser::length ( const simb::MCParticle part,
TLorentzVector &  start,
TLorentzVector &  end,
unsigned int &  starti,
unsigned int &  endi 
)
private

Definition at line 7028 of file AnaRootParser_module.cc.

7029  {
7030  double result = 0.;
7031  TVector3 disp;
7032  bool first = true;
7033 
7034  for(unsigned int i = 0; i < p.NumberTrajectoryPoints(); ++i) {
7035  // check if the particle is inside a TPC
7036  if (p.Vx(i) >= ActiveBounds[0] && p.Vx(i) <= ActiveBounds[1] && p.Vy(i) >= ActiveBounds[2] && p.Vy(i) <= ActiveBounds[3] && p.Vz(i) >= ActiveBounds[4] && p.Vz(i) <= ActiveBounds[5]){
7037  if(first){
7038  start = p.Position(i);
7039  first = false;
7040  starti = i;
7041  }else{
7042  disp -= p.Position(i).Vect();
7043  result += disp.Mag();
7044  }
7045  disp = p.Position(i).Vect();
7046  end = p.Position(i);
7047  endi = i;
7048  }
7049  }
7050  return result;
7051  }
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
static QCString result
double ActiveBounds[6]
objet holding the configuration of the uBoone MCS fitting alg
p
Definition: test.py:223
void dune::AnaRootParser::SetAddresses ( )
inlineprivate

Sets the addresses of all the tree branches, creating the missing ones.

Definition at line 1532 of file AnaRootParser_module.cc.

1533  {
1534  CheckData(__func__); CheckTree(__func__);
1535  fData->SetAddresses
1537  } // SetAddresses()
void CheckTree(std::string caller) const
Helper function: throws if no tree is available.
bool isCosmics
if it contains cosmics
std::vector< std::string > fShowerModuleLabel
std::unique_ptr< AnaRootParserDataStruct > fData
std::vector< std::string > fVertexModuleLabel
void CheckData(std::string caller) const
Helper function: throws if no data structure is available.
std::vector< std::string > fTrackModuleLabel
void dune::AnaRootParser::SetPFParticleAddress ( )
inlineprivate

Sets the addresses of the tree branch of the PFParticle, creating it if missing

Definition at line 1581 of file AnaRootParser_module.cc.

1582  {
1583  CheckData(__func__); CheckTree(__func__);
1584  fData->GetPFParticleData().SetAddresses(fTree);
1585  } // SetPFParticleAddress()
void CheckTree(std::string caller) const
Helper function: throws if no tree is available.
std::unique_ptr< AnaRootParserDataStruct > fData
void CheckData(std::string caller) const
Helper function: throws if no data structure is available.
void dune::AnaRootParser::SetShowerAddresses ( size_t  iShower)
inlineprivate

Sets the addresses of all the tree branches of the specified shower algo, creating the missing ones

Definition at line 1568 of file AnaRootParser_module.cc.

1569  {
1570  CheckData(__func__); CheckTree(__func__);
1571  if (iShower >= fData->GetNShowerAlgos()) {
1573  << "AnaRootParser::SetShowerAddresses(): no shower algo #" << iShower
1574  << " (" << fData->GetNShowerAlgos() << " available)";
1575  }
1576  fData->GetShowerData(iShower).SetAddresses(fTree);
1577  } // SetShowerAddresses()
void CheckTree(std::string caller) const
Helper function: throws if no tree is available.
std::unique_ptr< AnaRootParserDataStruct > fData
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void CheckData(std::string caller) const
Helper function: throws if no data structure is available.
void dune::AnaRootParser::SetTrackerAddresses ( size_t  iTracker)
inlineprivate

Sets the addresses of all the tree branches of the specified tracking algo, creating the missing ones

Definition at line 1541 of file AnaRootParser_module.cc.

1542  {
1543  CheckData(__func__); CheckTree(__func__);
1544  if (iTracker >= fData->GetNTrackers()) {
1546  << "AnaRootParser::SetTrackerAddresses(): no tracker #" << iTracker
1547  << " (" << fData->GetNTrackers() << " available)";
1548  }
1549  fData->GetTrackerData(iTracker)
1550  .SetAddresses(fTree, fTrackModuleLabel[iTracker], isCosmics);
1551  } // SetTrackerAddresses()
void CheckTree(std::string caller) const
Helper function: throws if no tree is available.
bool isCosmics
if it contains cosmics
std::unique_ptr< AnaRootParserDataStruct > fData
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void CheckData(std::string caller) const
Helper function: throws if no data structure is available.
std::vector< std::string > fTrackModuleLabel
void dune::AnaRootParser::SetVertexAddresses ( size_t  iVertexAlg)
inlineprivate

Definition at line 1554 of file AnaRootParser_module.cc.

1555  {
1556  CheckData(__func__); CheckTree(__func__);
1557  if (iVertexAlg >= fData->GetNVertexAlgos()) {
1559  << "AnaRootParser::SetVertexAddresses(): no vertex alg #" << iVertexAlg
1560  << " (" << fData->GetNVertexAlgos() << " available)";
1561  }
1562  fData->GetVertexData(iVertexAlg)
1563  .SetAddresses(fTree, fVertexModuleLabel[iVertexAlg], isCosmics);
1564  } // SetVertexAddresses()
void CheckTree(std::string caller) const
Helper function: throws if no tree is available.
bool isCosmics
if it contains cosmics
std::unique_ptr< AnaRootParserDataStruct > fData
std::vector< std::string > fVertexModuleLabel
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void CheckData(std::string caller) const
Helper function: throws if no data structure is available.

Member Data Documentation

double dune::AnaRootParser::ActiveBounds[6]
private

objet holding the configuration of the uBoone MCS fitting alg

Definition at line 1479 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::bIgnoreMissingShowers
private

whether to ignore missing shower information

Definition at line 1471 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fCalDataModuleLabel
private

Definition at line 1415 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fCalorimetryModuleLabel
private

Definition at line 1431 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fClusterModuleLabel
private

Definition at line 1421 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fContainmentTaggerAssocLabel
private

Definition at line 1468 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fCosmicClusterTaggerAssocLabel
private

Definition at line 1438 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fCosmicTaggerAssocLabel
private

whether to extract and save PFParticle information

Definition at line 1467 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fCryGenModuleLabel
private

Definition at line 1417 of file AnaRootParser_module.cc.

std::unique_ptr<AnaRootParserDataStruct> dune::AnaRootParser::fData
private

Definition at line 1404 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fElecDriftModuleLabel
private

Definition at line 1414 of file AnaRootParser_module.cc.

short dune::AnaRootParser::fEventsPerSubrun
private

Definition at line 1409 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fExternalCounterModuleLabel
private

Definition at line 1424 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fFlashMatchAssocLabel
private

Definition at line 1469 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fFlashT0FinderLabel
private

Definition at line 1435 of file AnaRootParser_module.cc.

float dune::AnaRootParser::fG4minE
private

Energy threshold to save g4 particle info.

Definition at line 1475 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fG4ModuleLabel
private

Definition at line 1419 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fGenieGenModuleLabel
private

Definition at line 1416 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fHitsModuleLabel
private

Definition at line 1412 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fIsMC
private

whether to use a permanent buffer (faster, huge memory)

Definition at line 1439 of file AnaRootParser_module.cc.

int dune::AnaRootParser::fLogLevel
private

Definition at line 1408 of file AnaRootParser_module.cc.

trkf::TrajectoryMCSFitter dune::AnaRootParser::fMCSFitter
private

Definition at line 1477 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fMCShowerModuleLabel
private

Definition at line 1425 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fMCT0FinderLabel
private

Definition at line 1436 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fMCTrackModuleLabel
private

Definition at line 1426 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fMVAPIDShowerModuleLabel
private

Definition at line 1433 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fMVAPIDTrackModuleLabel
private

Definition at line 1434 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fOpFlashModuleLabel
private

Definition at line 1423 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fPandoraNuVertexModuleLabel
private

Definition at line 1422 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fParticleIDModuleLabel
private

Definition at line 1432 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fPFParticleModuleLabel
private

Definition at line 1428 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fPhotonPropS1ModuleLabel
private

Definition at line 1413 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fPOTModuleLabel
private

Definition at line 1437 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fProtoGenModuleLabel
private

Definition at line 1418 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fRawDigitModuleLabel
private

Definition at line 1411 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveAuxDetInfo
private

whether to extract and save auxiliary detector data

Definition at line 1443 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveCaloCosmics
private

save calorimetry information for cosmics

Definition at line 1474 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveClusterInfo
private

whether to extract and save Vertex information

Definition at line 1460 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveCryInfo
private

Definition at line 1444 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveExternCounterInfo
private

whether to extract and save Flash information

Definition at line 1463 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveFlashInfo
private

whether to extract and save nu vertex information from Pandora

Definition at line 1462 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveGeantInAVInfo
private

whether to extract and save Geant information

Definition at line 1450 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveGeantInfo
private

whether to extract and save Geant information

Definition at line 1449 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveGeantTrajectoryInfo
private

whether to extract and save Geant information

Definition at line 1451 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveGeneratorInfo
private

whether to extract and save collected photons

Definition at line 1448 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveGenieInfo
private

whether to extract and save CRY particle data

Definition at line 1445 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveHitInfo
private

whether to extract and save MC Track information

Definition at line 1455 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveMCShowerInfo
private

whether to extract and save Cluster information

Definition at line 1453 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveMCTrackInfo
private

whether to extract and save MC Shower information

Definition at line 1454 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSavePandoraNuVertexInfo
private

whether to extract and save Cluster information

Definition at line 1461 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSavePFParticleInfo
private

whether to extract and save Shower information

Definition at line 1465 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSavePhotonInfo
private

whether to extract and save ProtDUNE beam simulation information

Definition at line 1447 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveProtoInfo
private

whether to extract and save Genie information

Definition at line 1446 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveRawDigitInfo
private

whether to extract and save Hit information

Definition at line 1456 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveRecobWireInfo
private

whether to extract and save raw digit information

Definition at line 1457 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveShowerInfo
private

whether to extract and save External Counter information

Definition at line 1464 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveSimEnergyDepositTPCActiveInfo
private

whether to extract and save Geant information

Definition at line 1452 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveTrackInfo
private

whether to extract and save recob wire information

Definition at line 1458 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fSaveVertexInfo
private

whether to extract and save Track information

Definition at line 1459 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fShowerModuleLabel
private

Definition at line 1430 of file AnaRootParser_module.cc.

std::string dune::AnaRootParser::fSimEnergyDepositTPCActiveLabel
private

Definition at line 1420 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fTrackModuleLabel
private

Definition at line 1427 of file AnaRootParser_module.cc.

TTree* dune::AnaRootParser::fTree
private

Definition at line 1399 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::fUseBuffer
private

whether to use a permanent buffer (faster, huge memory)

Definition at line 1440 of file AnaRootParser_module.cc.

std::vector<std::string> dune::AnaRootParser::fVertexModuleLabel
private

Definition at line 1429 of file AnaRootParser_module.cc.

bool dune::AnaRootParser::isCosmics
private

if it contains cosmics

Definition at line 1473 of file AnaRootParser_module.cc.

AnaRootParserDataStruct::SubRunData_t dune::AnaRootParser::SubRunData
private

Definition at line 1406 of file AnaRootParser_module.cc.


The documentation for this class was generated from the following file: