23 #include "nusimdata/SimulationBase/MCParticle.h"
26 #include "art/Framework/Core/EDAnalyzer.h"
27 #include "art/Framework/Principal/Event.h"
28 #include "art/Framework/Principal/Handle.h"
29 #include "art/Framework/Services/Registry/ServiceHandle.h"
30 #include "art_root_io/TFileService.h"
31 #include "canvas/Persistency/Common/FindManyP.h"
36 #include "fhiclcpp/ParameterSet.h"
37 #include "fhiclcpp/types/Table.h"
38 #include "fhiclcpp/types/Atom.h"
40 #include "Pandora/PdgTable.h"
65 Name(
"SimModuleLabel"),
66 Comment(
"tag of detector simulation data product")
70 Name(
"CRTTrackLabel"),
71 Comment(
"tag of CRT track producer data product")
75 Name(
"TPCTrackLabel"),
76 Comment(
"tag of tpc track producer data product")
81 Comment(
"tag of pandora data product")
86 Comment(
"Print information about what's going on")
90 Name(
"TrackMatchAlg"),
97 fhicl::Table<CrtTrackCosmicIdAlg::Config>
CTTagAlg {
112 virtual void analyze(
const art::Event& event)
override;
115 virtual void endJob()
override;
139 std::vector<std::string>
types {
"NuMuTrack",
"CrTrack",
"DirtTrack",
"NuTrack",
"NuMuPfp",
"CrPfp",
"DirtPfp",
"NuPfp"};
156 , fSimModuleLabel (config().SimModuleLabel())
157 , fCRTTrackLabel (config().CRTTrackLabel())
159 , fPandoraLabel (config().PandoraLabel())
160 , fVerbose (config().
Verbose())
161 , trackAlg (config().TrackMatchAlg())
162 , fCrtBackTrack (config().CrtBackTrack())
163 , ctTag (config().CTTagAlg())
173 art::ServiceHandle<art::TFileService>
tfs;
176 hMatchDCA[
type] = tfs->make<TH1D>(Form(
"%sMatchDCA",
type.c_str()),
"", 60, 0, 100);
180 hDCATotal[
type] = tfs->make<TH1D>(Form(
"%sDCATotal",
type.c_str()),
"", 20, 0, 80);
181 hDCATag[
type] = tfs->make<TH1D>(Form(
"%sDCATag",
type.c_str()),
"", 20, 0, 80);
183 hLengthTag[
type] = tfs->make<TH1D>(Form(
"%sLengthTag",
type.c_str()),
"", 20, 0, 400);
187 if(
fVerbose)
std::cout<<
"----------------- CRT T0 Matching Ana Module -------------------"<<std::endl;
197 std::cout<<
"============================================"<<std::endl
198 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
199 <<
"============================================"<<std::endl;
207 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
208 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
211 art::Handle< std::vector<sbn::crt::CRTTrack>> crtTrackHandle;
212 std::vector<art::Ptr<sbn::crt::CRTTrack> > crtTrackList;
214 art::fill_ptr_vector(crtTrackList, crtTrackHandle);
217 std::vector<sbn::crt::CRTTrack> crtTracks;
218 std::map<int, int> numCrtTrackMap;
220 for(
auto const&
track : (crtTrackList)){
221 crtTracks.push_back(*
track);
224 double trackTime =
track->ts1_ns * 1
e-3;
225 if(trackTime > 0 && trackTime < 4)
continue;
226 numCrtTrackMap[trackTrueID]++;
230 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
231 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
236 if( !pfParticleHandle.isValid() ){
243 art::FindManyP< recob::Track > pfPartToTrackAssoc(pfParticleHandle, event,
fTPCTrackLabel);
249 std::map<int, simb::MCParticle> particles;
250 std::vector<int> nuParticleIds;
251 std::vector<int> lepParticleIds;
252 std::vector<int> dirtParticleIds;
253 std::vector<int> crParticleIds;
255 for (
auto const& particle: (*particleHandle)){
258 int partID = particle.TrackId();
259 particles[partID] = particle;
262 art::Ptr<simb::MCTruth> truth = pi_serv->TrackIdToMCTruth_P(partID);
266 if(truth->Origin() == simb::kBeamNeutrino){
268 vtx.SetX(truth->GetNeutrino().Nu().Vx()); vtx.SetY(truth->GetNeutrino().Nu().Vy()); vtx.SetZ(truth->GetNeutrino().Nu().Vz());
271 dirtParticleIds.push_back(partID);
274 else if(pdg==13 && particle.Mother()==0){
275 lepParticleIds.push_back(partID);
279 nuParticleIds.push_back(partID);
285 crParticleIds.push_back(partID);
293 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
294 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
297 for (
auto const& tpcTrack : (*tpcTrackHandle)){
299 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
301 std::string
type =
"none";
302 if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trackTrueID) != lepParticleIds.end()) type =
"NuMuTrack";
303 if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trackTrueID) != nuParticleIds.end()) type =
"NuTrack";
304 if(std::find(crParticleIds.begin(), crParticleIds.end(), trackTrueID) != crParticleIds.end()) type =
"CrTrack";
305 if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trackTrueID) != dirtParticleIds.end()) type =
"DirtTrack";
306 if(type ==
"none")
continue;
308 if(numCrtTrackMap.find(trackTrueID) != numCrtTrackMap.end()){
319 if(closestAngle.second != -99999){
321 if(crtTrackTrueID == trackTrueID && crtTrackTrueID != -99999){
329 if(closestDCA.second != -99999){
331 if(crtTrackTrueID == trackTrueID && crtTrackTrueID != -99999){
340 int nbins =
hDCATotal.begin()->second->GetNbinsX();
341 for(
int i = 0; i < nbins; i++){
342 double DCAcut =
hDCATotal.begin()->second->GetBinCenter(i);
347 if(closestDCA.second < DCAcut && closestDCA.second != -99999){
348 double trackTime = closestDCA.first.ts1_ns * 1
e-3;
349 if(trackTime > 0 && trackTime < 4)
continue;
363 for (PFParticleIdMap::const_iterator it = pfParticleMap.begin(); it != pfParticleMap.end(); ++it){
365 const art::Ptr<recob::PFParticle> pParticle(it->second);
367 if (!pParticle->IsPrimary())
continue;
369 const int pdg(pParticle->PdgCode());
372 if(!isNeutrino)
continue;
374 std::string
type =
"none";
375 std::vector<recob::Track> nuTracks;
378 for (
const size_t daughterId : pParticle->Daughters()){
381 art::Ptr<recob::PFParticle> pDaughter = pfParticleMap.at(daughterId);
382 const std::vector< art::Ptr<recob::Track> > associatedTracks(pfPartToTrackAssoc.at(pDaughter.key()));
383 if(associatedTracks.size() != 1)
continue;
387 nuTracks.push_back(tpcTrack);
390 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
392 if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trueId) != lepParticleIds.end()){
395 else if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trueId) != nuParticleIds.end()){
396 if(type !=
"NuMuPfp") type =
"NuPfp";
398 else if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trueId) != dirtParticleIds.end()){
399 if(type !=
"NuMuPfp" && type !=
"NuPfp") type =
"DirtPfp";
401 else if(std::find(crParticleIds.begin(), crParticleIds.end(), trueId) != crParticleIds.end()){
402 if(type !=
"NuMuPfp" && type !=
"NuPfp" && type !=
"DirtPfp") type =
"CrPfp";
406 if(nuTracks.size() == 0)
continue;
408 std::sort(nuTracks.begin(), nuTracks.end(), [](
auto&
left,
auto&
right){
409 return left.Length() >
right.Length();});
412 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
415 if(numCrtTrackMap.find(trackTrueID) != numCrtTrackMap.end()){
425 if(closestAngle.second != -99999){
427 if(crtTrackTrueID == trackTrueID && crtTrackTrueID != -99999){
435 if(closestDCA.second != -99999){
437 if(crtTrackTrueID == trackTrueID && crtTrackTrueID != -99999){
446 int nbins =
hDCATotal.begin()->second->GetNbinsX();
447 for(
int i = 0; i < nbins; i++){
448 double DCAcut =
hDCATotal.begin()->second->GetBinCenter(i);
453 if(closestDCA.second < DCAcut && closestDCA.second != -99999){
454 double trackTime = closestDCA.first.ts1_ns * 1
e-3;
455 if(trackTime > 0 && trackTime < 4)
continue;
478 for (
unsigned int i = 0; i < pfParticleHandle->size(); ++i){
479 const art::Ptr<recob::PFParticle> pParticle(pfParticleHandle, i);
480 if (!pfParticleMap.insert(PFParticleIdMap::value_type(pParticle->Self(), pParticle)).second){
481 std::cout <<
" Unable to get PFParticle ID map, the input PFParticle collection has repeat IDs!" <<
"\n";
int TrueIdFromTrackId(const art::Event &event, int track_i)
art::Handle< std::vector< recob::PFParticle > > PFParticleHandle
Declaration of signal hit object.
std::map< size_t, art::Ptr< recob::PFParticle > > PFParticleIdMap
fhicl::Atom< art::InputTag > SimModuleLabel
art::InputTag fCRTTrackLabel
name of CRT producer
bool fVerbose
print information about what's going on
void GetPFParticleIdMap(const PFParticleHandle &pfParticleHandle, PFParticleIdMap &pfParticleMap)
process_name use argoneut_mc_hitfinder track
std::vector< std::string > types
int TrueIdFromTotalEnergy(const art::Event &event, const sbnd::crt::CRTData &data)
fhicl::Atom< art::InputTag > CRTTrackLabel
std::map< std::string, TH1D * > hDCATag
std::map< std::string, TH1D * > hDCATotal
CrtTrackCosmicIdAlg ctTag
CRTBackTracker fCrtBackTrack
void Initialize(const art::Event &event)
art::InputTag fSimModuleLabel
name of detsim producer
art::EDAnalyzer::Table< Config > Parameters
std::pair< sbn::crt::CRTTrack, double > ClosestCRTTrackByDCA(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTTrack > crtTracks, const art::Event &event, double minAngle=0.)
fhicl::Atom< art::InputTag > PandoraLabel
bool CrtTrackCosmicId(detinfo::DetectorPropertiesData const &detProp, recob::Track track, std::vector< sbn::crt::CRTTrack > crtTracks, const art::Event &event)
BEGIN_PROLOG vertical distance to the surface Name
std::map< std::string, TH1D * > hNumTrueMatches
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
std::map< std::string, TH1D * > hNoMatchDCA
BEGIN_PROLOG don t mess with this TPCTrackLabel
Definition of data types for geometry description.
Provides recob::Track data product.
fhicl::Table< CRTBackTracker::Config > CrtBackTrack
art::InputTag fPandoraLabel
virtual void beginJob() override
std::map< std::string, TH1D * > hLengthTag
std::map< std::string, TH1D * > hMatchAngle
fhicl::Table< CrtTrackCosmicIdAlg::Config > CTTagAlg
virtual void analyze(const art::Event &event) override
std::pair< sbn::crt::CRTTrack, double > ClosestCRTTrackByAngle(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTTrack > crtTracks, const art::Event &event, double minDCA=0.)
CRTTrackMatchAlg trackAlg
fhicl::Table< CRTTrackMatchAlg::Config > TrackMatchAlg
fhicl::Atom< bool > Verbose
stream1 can override from command line with o or output services user sbnd
art::ServiceHandle< art::TFileService > tfs
std::map< std::string, TH1D * > hMatchDCA
art::InputTag fTPCTrackLabel
name of CRT producer
std::map< std::string, TH1D * > hLengthTotal
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
CRTTrackCosmicIdAna(Parameters const &config)
fhicl::Atom< art::InputTag > TPCTrackLabel
BEGIN_PROLOG could also be cout
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)
std::map< std::string, TH1D * > hNoMatchAngle
virtual void endJob() override