25 #include "nusimdata/SimulationBase/MCParticle.h"
29 #include "art/Framework/Core/EDAnalyzer.h"
30 #include "art/Framework/Principal/Event.h"
31 #include "art/Framework/Principal/Handle.h"
32 #include "art/Framework/Services/Registry/ServiceHandle.h"
33 #include "art_root_io/TFileService.h"
34 #include "art/Framework/Core/ModuleMacros.h"
35 #include "canvas/Persistency/Common/FindManyP.h"
36 #include "canvas/Utilities/Exception.h"
41 #include "messagefacility/MessageLogger/MessageLogger.h"
42 #include "fhiclcpp/ParameterSet.h"
43 #include "fhiclcpp/types/Table.h"
44 #include "fhiclcpp/types/Atom.h"
45 #include "cetlib/pow.h"
71 Name(
"SimModuleLabel"),
72 Comment(
"tag of detector simulation data product")
76 Name(
"CRTTrackLabel"),
77 Comment(
"tag of CRT track producer data product")
81 Name(
"TPCTrackLabel"),
82 Comment(
"tag of tpc track producer data product")
87 Comment(
"Print information about what's going on")
98 fhicl::Table<CRTEventDisplay::Config>
Evd {
113 virtual void analyze(
const art::Event& event)
override;
116 virtual void endJob()
override;
165 , fSimModuleLabel (config().SimModuleLabel())
166 , fCRTTrackLabel (config().CRTTrackLabel())
168 , fVerbose (config().
Verbose())
169 , trackAlg (config().CRTTrackAlg())
170 , fCrtBackTrack (config().CrtBackTrack())
171 , evd (config().Evd())
181 art::ServiceHandle<art::TFileService>
tfs;
183 hAngle = tfs->make<TH1D>(
"Angle",
"", 50, 0, 2);
184 hMatchAngle = tfs->make<TH1D>(
"MatchAngle",
"", 50, 0, 2);
185 hNoMatchAngle = tfs->make<TH1D>(
"NoMatchAngle",
"", 50, 0, 2);
187 hDCA = tfs->make<TH1D>(
"DCA",
"", 50, 0, 150);
188 hMatchDCA = tfs->make<TH1D>(
"MatchDCA",
"", 50, 0, 150);
189 hNoMatchDCA = tfs->make<TH1D>(
"NoMatchDCA",
"", 50, 0, 150);
191 hMatchAngleDCA = tfs->make<TH2D>(
"MatchAngleDCA",
"", 20, 0, 2, 20, 0, 150);
192 hNoMatchAngleDCA = tfs->make<TH2D>(
"NoMatchAngleDCA",
"", 20, 0, 2, 20, 0, 150);
195 hEffAngleReco = tfs->make<TH1D>(
"EffAngleReco",
"", 20, 0, 1);
199 hEffDCATotal = tfs->make<TH1D>(
"EffDCATotal",
"", 20, 0, 100);
200 hEffDCAReco = tfs->make<TH1D>(
"EffDCAReco",
"", 20, 0, 100);
202 hPurityDCAReco = tfs->make<TH1D>(
"PurityDCAReco",
"", 20, 0, 100);
205 if(
fVerbose)
std::cout<<
"----------------- CRT T0 Matching Ana Module -------------------"<<std::endl;
215 std::cout<<
"============================================"<<std::endl
216 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
217 <<
"============================================"<<std::endl;
225 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
228 art::Handle< std::vector<sbn::crt::CRTTrack>> crtTrackHandle;
229 std::vector<art::Ptr<sbn::crt::CRTTrack> > crtTrackList;
231 art::fill_ptr_vector(crtTrackList, crtTrackHandle);
234 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
235 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
243 std::map<int, simb::MCParticle> particles;
245 for (
auto const& particle: (*particleHandle)){
248 int partID = particle.TrackId();
249 particles[partID] = particle;
253 std::vector<sbn::crt::CRTTrack> crtTracks;
254 std::map<int, std::vector<sbn::crt::CRTTrack>> crtTrackMap;
256 double minTrackTime = 99999;
257 double maxTrackTime = -99999;
259 for(
auto const&
track : (*crtTrackHandle)){
260 crtTracks.push_back(
track);
263 if(trueID != -99999) crtTrackMap[trueID].push_back(
track);
265 double trackTime = (double)(
int)
track.ts1_ns * 1
e-3;
266 if(trackTime < minTrackTime) minTrackTime = trackTime;
267 if(trackTime > maxTrackTime) maxTrackTime = trackTime;
274 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
275 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
278 for (
auto const& tpcTrack : (*tpcTrackHandle)){
280 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
283 if(particles.find(trackTrueID) == particles.end())
continue;
285 if(!(
std::abs(particles[trackTrueID].PdgCode()) == 13 && particles[trackTrueID].Mother() == 0))
continue;
288 double trueTime = particles[trackTrueID].T() * 1
e-3;
289 if(trueTime < minTrackTime || trueTime > maxTrackTime)
continue;
296 if(closestAngle.second != -99999){
297 hAngle->Fill(closestAngle.second);
300 if(closestAngle.second != -99999){
302 if(crtTrueID == trackTrueID && crtTrueID != -99999){
311 for(
int i = 0; i < nbinsAngle; i++){
315 if(crtTrackMap.find(trackTrueID) != crtTrackMap.end()){
319 if(closestAngle.second < angleCut && closestAngle.second != -99999){
325 if(closestAngle.second < angleCut && closestAngle.second != -99999){
329 double trackTime = closestAngle.first.ts1_ns * 1
e-3;
330 if(particles.find(trackTrueID) != particles.end()){
331 if(
std::abs(trackTime - trueTime) < 2.){
343 if(closestDCA.second != -99999){
344 hDCA->Fill(closestDCA.second);
346 if(closestDCA.second != -99999){
348 if(crtTrueID == trackTrueID && crtTrueID != -99999){
357 for(
int i = 0; i < nbinsDCA; i++){
361 if(crtTrackMap.find(trackTrueID) != crtTrackMap.end()){
365 if(closestDCA.second < DCAcut && closestDCA.second != -99999){
371 if(closestDCA.second < DCAcut && closestDCA.second != -99999){
375 double trackTime = closestDCA.first.ts1_ns * 1
e-3;
376 if(particles.find(trackTrueID) != particles.end()){
377 if(
std::abs(trackTime - trueTime) < 2.){
389 for(
auto const& possTrack : possTracks){
393 if(crtTrueID == trackTrueID && crtTrueID != -99999){
int TrueIdFromTrackId(const art::Event &event, int track_i)
fhicl::Table< CRTTrackMatchAlg::Config > CRTTrackAlg
Functions to help with numbers.
art::InputTag fSimModuleLabel
name of detsim producer
Declaration of signal hit object.
virtual void endJob() override
fhicl::Atom< art::InputTag > TPCTrackLabel
fhicl::Table< CRTEventDisplay::Config > Evd
process_name use argoneut_mc_hitfinder track
fhicl::Atom< art::InputTag > CRTTrackLabel
double AngleBetweenTracks(recob::Track tpcTrack, sbn::crt::CRTTrack crtTrack)
double AveDCABetweenTracks(recob::Track tpcTrack, sbn::crt::CRTTrack crtTrack, double shift)
int TrueIdFromTotalEnergy(const art::Event &event, const sbnd::crt::CRTData &data)
void Initialize(const art::Event &event)
fhicl::Table< CRTBackTracker::Config > CrtBackTrack
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.)
virtual void analyze(const art::Event &event) override
CRTTrackMatchAlg trackAlg
CRTTrackMatchingAna(Parameters const &config)
fhicl::Atom< bool > Verbose
art::InputTag fCRTTrackLabel
name of CRT producer
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)
fhicl::Atom< art::InputTag > SimModuleLabel
BEGIN_PROLOG don t mess with this TPCTrackLabel
Definition of data types for geometry description.
Provides recob::Track data product.
std::vector< sbn::crt::CRTTrack > AllPossibleCRTTracks(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTTrack > crtTracks, const art::Event &event)
bool fVerbose
print information about what's going on
double DistToCrtHit(TVector3 trackPos, sbn::crt::CRTHit crtHit)
virtual void beginJob() 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.)
object containing MC truth information necessary for making RawDigits and doing back tracking ...
art::InputTag fTPCTrackLabel
name of CRT producer
stream1 can override from command line with o or output services user sbnd
finds tracks best matching by angle
art::ServiceHandle< art::TFileService > tfs
CRTBackTracker fCrtBackTrack
BEGIN_PROLOG could also be cout
art::EDAnalyzer::Table< Config > Parameters