24 #include "nusimdata/SimulationBase/MCParticle.h"
27 #include "art/Framework/Core/EDAnalyzer.h"
28 #include "art/Framework/Principal/Event.h"
29 #include "art/Framework/Principal/Handle.h"
30 #include "art/Framework/Services/Registry/ServiceHandle.h"
31 #include "art_root_io/TFileService.h"
32 #include "canvas/Persistency/Common/FindManyP.h"
37 #include "fhiclcpp/ParameterSet.h"
38 #include "fhiclcpp/types/Table.h"
39 #include "fhiclcpp/types/Atom.h"
41 #include "Pandora/PdgTable.h"
66 Name(
"SimModuleLabel"),
67 Comment(
"tag of detector simulation data product")
72 Comment(
"tag of CRT hit producer data product")
76 Name(
"TPCTrackLabel"),
77 Comment(
"tag of tpc track producer data product")
82 Comment(
"tag of pandora data product")
87 Comment(
"Print information about what's going on")
98 fhicl::Table<CrtHitCosmicIdAlg::Config>
CHTagAlg {
113 virtual void analyze(
const art::Event& event)
override;
116 virtual void endJob()
override;
140 std::vector<std::string>
types {
"NuMuTrack",
"CrTrack",
"DirtTrack",
"NuTrack",
"NuMuPfp",
"CrPfp",
"DirtPfp",
"NuPfp"};
155 , fSimModuleLabel (config().SimModuleLabel())
156 , fCRTHitLabel (config().CRTHitLabel())
158 , fPandoraLabel (config().PandoraLabel())
159 , fVerbose (config().
Verbose())
160 , t0Alg (config().CRTT0Alg())
161 , fCrtBackTrack (config().CrtBackTrack())
162 , chTag (config().CHTagAlg())
172 art::ServiceHandle<art::TFileService>
tfs;
175 hMatchDCA[
type] = tfs->make<TH1D>(Form(
"%sMatchDCA",
type.c_str()),
"", 60, 0, 100);
177 hDCATotal[
type] = tfs->make<TH1D>(Form(
"%sDCATotal",
type.c_str()),
"", 20, 0, 80);
178 hDCATag[
type] = tfs->make<TH1D>(Form(
"%sDCATag",
type.c_str()),
"", 20, 0, 80);
180 hLengthTag[
type] = tfs->make<TH1D>(Form(
"%sLengthTag",
type.c_str()),
"", 20, 0, 400);
184 if(
fVerbose)
std::cout<<
"----------------- CRT T0 Matching Ana Module -------------------"<<std::endl;
194 std::cout<<
"============================================"<<std::endl
195 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
196 <<
"============================================"<<std::endl;
204 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
205 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
208 art::Handle< std::vector<sbn::crt::CRTHit>> crtHitHandle;
209 std::vector<art::Ptr<sbn::crt::CRTHit> > crtHitList;
211 art::fill_ptr_vector(crtHitList, crtHitHandle);
214 std::vector<sbn::crt::CRTHit> crtHits;
215 std::map<int, int> numHitMap;
217 for(
auto const&
hit : (crtHitList)){
218 crtHits.push_back(*
hit);
221 double hitTime =
hit->ts1_ns * 1
e-3;
222 if(hitTime > 0 && hitTime < 4)
continue;
223 numHitMap[hitTrueID]++;
227 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
228 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
233 if( !pfParticleHandle.isValid() ){
240 art::FindManyP< recob::Track > pfPartToTrackAssoc(pfParticleHandle, event,
fTPCTrackLabel);
246 std::map<int, simb::MCParticle> particles;
247 std::vector<int> nuParticleIds;
248 std::vector<int> lepParticleIds;
249 std::vector<int> dirtParticleIds;
250 std::vector<int> crParticleIds;
252 for (
auto const& particle: (*particleHandle)){
255 int partID = particle.TrackId();
256 particles[partID] = particle;
259 art::Ptr<simb::MCTruth> truth = pi_serv->TrackIdToMCTruth_P(partID);
263 if(truth->Origin() == simb::kBeamNeutrino){
265 vtx.SetX(truth->GetNeutrino().Nu().Vx()); vtx.SetY(truth->GetNeutrino().Nu().Vy()); vtx.SetZ(truth->GetNeutrino().Nu().Vz());
268 dirtParticleIds.push_back(partID);
271 else if(pdg==13 && particle.Mother()==0){
272 lepParticleIds.push_back(partID);
276 nuParticleIds.push_back(partID);
282 crParticleIds.push_back(partID);
290 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
291 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
294 for (
auto const& tpcTrack : (*tpcTrackHandle)){
296 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
298 std::string
type =
"none";
299 if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trackTrueID) != lepParticleIds.end()) type =
"NuMuTrack";
300 if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trackTrueID) != nuParticleIds.end()) type =
"NuTrack";
301 if(std::find(crParticleIds.begin(), crParticleIds.end(), trackTrueID) != crParticleIds.end()) type =
"CrTrack";
302 if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trackTrueID) != dirtParticleIds.end()) type =
"DirtTrack";
303 if(type ==
"none")
continue;
308 if(closest.second != -99999){
310 if(hitTrueID == trackTrueID && hitTrueID != -99999){
318 if(numHitMap.find(trackTrueID) != numHitMap.end()){
325 int nbins =
hDCATotal.begin()->second->GetNbinsX();
326 for(
int i = 0; i < nbins; i++){
327 double DCAcut =
hDCATotal.begin()->second->GetBinCenter(i);
332 if(closest.second < DCAcut && closest.second != -99999){
333 double hitTime = closest.first.ts1_ns * 1
e-3;
334 if(hitTime > 0 && hitTime < 4)
continue;
347 for (PFParticleIdMap::const_iterator it = pfParticleMap.begin(); it != pfParticleMap.end(); ++it){
349 const art::Ptr<recob::PFParticle> pParticle(it->second);
351 if (!pParticle->IsPrimary())
continue;
353 const int pdg(pParticle->PdgCode());
356 if(!isNeutrino)
continue;
358 std::string
type =
"none";
359 std::vector<recob::Track> nuTracks;
362 for (
const size_t daughterId : pParticle->Daughters()){
365 art::Ptr<recob::PFParticle> pDaughter = pfParticleMap.at(daughterId);
366 const std::vector< art::Ptr<recob::Track> > associatedTracks(pfPartToTrackAssoc.at(pDaughter.key()));
367 if(associatedTracks.size() != 1)
continue;
371 nuTracks.push_back(tpcTrack);
374 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
376 if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trueId) != lepParticleIds.end()){
379 else if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trueId) != nuParticleIds.end()){
380 if(type !=
"NuMuPfp") type =
"NuPfp";
382 else if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trueId) != dirtParticleIds.end()){
383 if(type !=
"NuMuPfp" && type !=
"NuPfp") type =
"DirtPfp";
385 else if(std::find(crParticleIds.begin(), crParticleIds.end(), trueId) != crParticleIds.end()){
386 if(type !=
"NuMuPfp" && type !=
"NuPfp" && type !=
"DirtPfp") type =
"CrPfp";
390 if(nuTracks.size() == 0)
continue;
392 std::sort(nuTracks.begin(), nuTracks.end(), [](
auto&
left,
auto&
right){
393 return left.Length() >
right.Length();});
396 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
399 if(numHitMap.find(trackTrueID) != numHitMap.end()){
409 if(closest.second != -99999){
411 if(hitTrueID == trackTrueID && hitTrueID != -99999){
420 int nbins =
hDCATotal.begin()->second->GetNbinsX();
421 for(
int i = 0; i < nbins; i++){
422 double DCAcut =
hDCATotal.begin()->second->GetBinCenter(i);
427 if(closest.second < DCAcut && closest.second != -99999){
428 double hitTime = closest.first.ts1_ns * 1
e-3;
429 if(hitTime > 0 && hitTime < 4)
continue;
450 for (
unsigned int i = 0; i < pfParticleHandle->size(); ++i){
451 const art::Ptr<recob::PFParticle> pParticle(pfParticleHandle, i);
452 if (!pfParticleMap.insert(PFParticleIdMap::value_type(pParticle->Self(), pParticle)).second){
453 std::cout <<
" Unable to get PFParticle ID map, the input PFParticle collection has repeat IDs!" <<
"\n";
std::map< size_t, art::Ptr< recob::PFParticle > > PFParticleIdMap
art::InputTag fCRTHitLabel
name of CRT producer
virtual void endJob() override
std::vector< std::string > types
fhicl::Atom< art::InputTag > SimModuleLabel
Declaration of signal hit object.
bool fVerbose
print information about what's going on
void GetPFParticleIdMap(const PFParticleHandle &pfParticleHandle, PFParticleIdMap &pfParticleMap)
int TrueIdFromTotalEnergy(const art::Event &event, const sbnd::crt::CRTData &data)
fhicl::Atom< bool > Verbose
int TrueIdFromHitId(const art::Event &event, int hit_i)
std::map< std::string, TH1D * > hDCATotal
std::map< std::string, TH1D * > hNoMatchDCA
art::EDAnalyzer::Table< Config > Parameters
void Initialize(const art::Event &event)
std::pair< sbn::crt::CRTHit, double > ClosestCRTHit(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::pair< double, double > t0MinMax, std::vector< sbn::crt::CRTHit > crtHits, int driftDirection)
std::map< std::string, TH1D * > hLengthTotal
fhicl::Table< CRTT0MatchAlg::Config > CRTT0Alg
art::InputTag fTPCTrackLabel
name of CRT producer
std::map< std::string, TH1D * > hNumTrueMatches
std::map< std::string, TH1D * > hDCATag
virtual void beginJob() override
BEGIN_PROLOG vertical distance to the surface Name
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
BEGIN_PROLOG don t mess with this TPCTrackLabel
bool CrtHitCosmicId(detinfo::DetectorPropertiesData const &detProp, recob::Track track, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
Definition of data types for geometry description.
std::map< std::string, TH1D * > hMatchDCA
Provides recob::Track data product.
CRTHitCosmicIdAna(Parameters const &config)
art::InputTag fPandoraLabel
fhicl::Table< CRTBackTracker::Config > CrtBackTrack
fhicl::Atom< art::InputTag > PandoraLabel
fhicl::Atom< art::InputTag > TPCTrackLabel
virtual void analyze(const art::Event &event) override
CRTBackTracker fCrtBackTrack
stream1 can override from command line with o or output services user sbnd
art::ServiceHandle< art::TFileService > tfs
fhicl::Atom< art::InputTag > CRTHitLabel
art::Handle< std::vector< recob::PFParticle > > PFParticleHandle
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
Track from a non-cascading particle.A recob::Track consists of a recob::TrackTrajectory, plus additional members relevant for a "fitted" track:
fhicl::Table< CrtHitCosmicIdAlg::Config > CHTagAlg
bool InFiducial(geo::Point_t point, double fiducial)
art::InputTag fSimModuleLabel
name of detsim producer
std::map< std::string, TH1D * > hLengthTag