172 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
176 std::cout<<
"============================================"<<std::endl
177 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
178 <<
"============================================"<<std::endl;
186 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
193 art::FindManyP<anab::Calorimetry> findManyCalo(tpcTrackHandle, event,
fCaloModuleLabel);
198 if( !pfParticleHandle.isValid() ){
205 art::FindManyP< recob::Track > pfPartToTrackAssoc(pfParticleHandle, event,
fTpcTrackModuleLabel);
211 std::map<int, simb::MCParticle> particles;
212 std::vector<int> nuParticleIds;
213 std::vector<int> lepParticleIds;
214 std::vector<int> dirtParticleIds;
215 std::vector<int> crParticleIds;
217 for (
auto const& particle: (*particleHandle)){
220 int partID = particle.TrackId();
221 particles[partID] = particle;
224 art::Ptr<simb::MCTruth> truth = pi_serv->TrackIdToMCTruth_P(partID);
228 if(truth->Origin() == simb::kBeamNeutrino){
230 vtx.SetX(truth->GetNeutrino().Nu().Vx()); vtx.SetY(truth->GetNeutrino().Nu().Vy()); vtx.SetZ(truth->GetNeutrino().Nu().Vz());
233 dirtParticleIds.push_back(partID);
236 else if(pdg==13 && particle.Mother()==0){
237 lepParticleIds.push_back(partID);
241 nuParticleIds.push_back(partID);
247 crParticleIds.push_back(partID);
256 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
258 for(
auto const& tpcTrack : (*tpcTrackHandle)){
261 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
263 std::string
type =
"none";
264 if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trueId) != lepParticleIds.end()) type =
"NuMuTrack";
265 if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trueId) != nuParticleIds.end()) type =
"NuTrack";
266 if(std::find(crParticleIds.begin(), crParticleIds.end(), trueId) != crParticleIds.end()) type =
"CrTrack";
267 if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trueId) != dirtParticleIds.end()) type =
"DirtTrack";
268 if(type ==
"none")
continue;
270 std::vector<art::Ptr<anab::Calorimetry>> calos = findManyCalo.at(tpcTrack.ID());
271 if(calos.size()==0)
continue;
274 if(
std::abs(particles[trueId].PdgCode()) != 13)
continue;
276 geo::Point_t trueEnd {particles[trueId].EndX(), particles[trueId].EndY(), particles[trueId].EndZ()};
284 TVector3 trueEndVec (particles[trueId].EndX(), particles[trueId].EndY(), particles[trueId].EndZ());
285 TVector3 start = tpcTrack.Vertex<TVector3>();
286 TVector3
end = tpcTrack.End<TVector3>();
288 if((start-trueEndVec).Mag() < (end-trueEndVec).Mag()) recoEnd = tpcTrack.Vertex();
297 int nbins =
hRatioTotal.begin()->second->GetNbinsX();
298 for(
int i = 0; i < nbins; i++){
299 double ratioCut =
hRatioTotal.begin()->second->GetBinCenter(i);
304 if((startChi2 > ratioCut && !
fTPCGeo.
InFiducial(tpcTrack.End(), 5.) && tpcTrack.End().Y() > 0)
305 || (endChi2 > ratioCut && !
fTPCGeo.
InFiducial(tpcTrack.Vertex(), 5.) && tpcTrack.Vertex().Y() > 0)){
314 for (PFParticleIdMap::const_iterator it = pfParticleMap.begin(); it != pfParticleMap.end(); ++it){
316 const art::Ptr<recob::PFParticle> pParticle(it->second);
318 if (!pParticle->IsPrimary())
continue;
320 const int pdg(pParticle->PdgCode());
321 const bool isNeutrino(
std::abs(pdg) == pandora::NU_E ||
std::abs(pdg) == pandora::NU_MU ||
std::abs(pdg) == pandora::NU_TAU);
323 if(!isNeutrino)
continue;
325 std::string type =
"none";
326 std::vector<recob::Track> nuTracks;
329 for (
const size_t daughterId : pParticle->Daughters()){
332 art::Ptr<recob::PFParticle> pDaughter = pfParticleMap.at(daughterId);
333 const std::vector< art::Ptr<recob::Track> > associatedTracks(pfPartToTrackAssoc.at(pDaughter.key()));
334 if(associatedTracks.size() != 1)
continue;
338 nuTracks.push_back(tpcTrack);
341 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
343 if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trueId) != lepParticleIds.end()){
346 else if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trueId) != nuParticleIds.end()){
347 if(type !=
"NuMuPfp") type =
"NuPfp";
349 else if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trueId) != dirtParticleIds.end()){
350 if(type !=
"NuMuPfp" && type !=
"NuPfp") type =
"DirtPfp";
352 else if(std::find(crParticleIds.begin(), crParticleIds.end(), trueId) != crParticleIds.end()){
353 if(type !=
"NuMuPfp" && type !=
"NuPfp" && type !=
"DirtPfp") type =
"CrPfp";
357 if(nuTracks.size() == 0)
continue;
359 std::sort(nuTracks.begin(), nuTracks.end(), [](
auto&
left,
auto&
right){
360 return left.Length() >
right.Length();});
363 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
366 std::vector<art::Ptr<anab::Calorimetry>> calos = findManyCalo.at(tpcTrack.ID());
367 if(calos.size()==0)
continue;
370 if(
std::abs(particles[trueId].PdgCode()) != 13)
continue;
372 geo::Point_t trueEnd {particles[trueId].EndX(), particles[trueId].EndY(), particles[trueId].EndZ()};
380 TVector3 trueEndVec (particles[trueId].EndX(), particles[trueId].EndY(), particles[trueId].EndZ());
381 TVector3 start = tpcTrack.Vertex<TVector3>();
382 TVector3 end = tpcTrack.End<TVector3>();
384 if((start-trueEndVec).Mag() < (end-trueEndVec).Mag()) recoEnd = tpcTrack.Vertex();
393 int nbins =
hRatioTotal.begin()->second->GetNbinsX();
394 for(
int i = 0; i < nbins; i++){
395 double ratioCut =
hRatioTotal.begin()->second->GetBinCenter(i);
400 if((startChi2 > ratioCut && !
fTPCGeo.
InFiducial(tpcTrack.End(), 5.) && tpcTrack.End().Y() > 0)
401 || (endChi2 > ratioCut && !
fTPCGeo.
InFiducial(tpcTrack.Vertex(), 5.) && tpcTrack.Vertex().Y() > 0)){
std::map< std::string, TH1D * > hNoStopLength
std::map< std::string, TH1D * > hRatioTag
std::map< std::string, TH1D * > hRatioTotal
double StoppingChiSq(geo::Point_t end, std::vector< art::Ptr< anab::Calorimetry >> calos)
std::map< size_t, art::Ptr< recob::PFParticle > > PFParticleIdMap
art::InputTag fSimModuleLabel
name of detsim producer
art::InputTag fTpcTrackModuleLabel
name of TPC track producer
void GetPFParticleIdMap(const PFParticleHandle &pfParticleHandle, PFParticleIdMap &pfParticleMap)
auto end(FixedBins< T, C > const &) noexcept
art::InputTag fPandoraLabel
bool fVerbose
print information about what's going on
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
art::Handle< std::vector< recob::PFParticle > > PFParticleHandle
StoppingParticleCosmicIdAlg spTag
std::map< std::string, TH1D * > hStopLength
art::InputTag fCaloModuleLabel
name of calorimetry producer
std::map< std::string, TH1D * > hStopChiSq
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
BEGIN_PROLOG could also be cout
std::map< std::string, TH1D * > hNoStopChiSq
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
bool InFiducial(geo::Point_t point, double fiducial)