22 #include "nusimdata/SimulationBase/MCParticle.h"
25 #include "art/Framework/Core/EDAnalyzer.h"
26 #include "art/Framework/Principal/Event.h"
27 #include "art/Framework/Principal/Handle.h"
28 #include "art/Framework/Services/Registry/ServiceHandle.h"
29 #include "art_root_io/TFileService.h"
30 #include "art/Framework/Core/ModuleMacros.h"
31 #include "canvas/Persistency/Common/FindManyP.h"
36 #include "messagefacility/MessageLogger/MessageLogger.h"
37 #include "fhiclcpp/ParameterSet.h"
38 #include "fhiclcpp/types/Table.h"
39 #include "fhiclcpp/types/Atom.h"
67 Name(
"SimModuleLabel"),
68 Comment(
"tag of detector simulation data product")
73 Comment(
"tag of CRT hit data product")
77 Name(
"CRTTrackLabel"),
78 Comment(
"tag of CRT track data product")
83 Comment(
"Print information about what's going on")
88 Comment(
"Print detailed information about every track")
101 fhicl::Table<CRTEventDisplay::Config>
Evd {
106 Name(
"CrtBackTrack"),
120 virtual void analyze(
const art::Event& event)
override;
123 virtual void endJob()
override;
168 , fSimModuleLabel (config().SimModuleLabel())
169 , fCRTHitLabel (config().CRTHitLabel())
170 , fCRTTrackLabel (config().CRTTrackLabel())
171 , fVerbose (config().
Verbose())
172 , fVeryVerbose (config().VeryVerbose())
173 , fPlot (config().Plot())
174 , fPlotTrackID (config().PlotTrackID())
175 , evd (config().Evd())
176 , fCrtBackTrack (config().CrtBackTrack())
184 art::ServiceHandle<art::TFileService>
tfs;
187 std::string
tagger =
"All";
189 hCrossDistance[tagger] = tfs->make<TH1D>(Form(
"CrossDistance_%s", tagger.c_str()),
"", 40, 0, 100);
190 hTrackDist[tagger] = tfs->make<TH1D>(Form(
"TrackDist_%s", tagger.c_str()),
"", 40, 0, 200);
192 hEffMomTotal[tagger] = tfs->make<TH1D>(Form(
"EffMomTotal_%s", tagger.c_str()),
"", 20, 0, 10);
193 hEffMomReco[tagger] = tfs->make<TH1D>(Form(
"EffMomReco_%s", tagger.c_str()),
"", 20, 0, 10);
194 hEffThetaTotal[tagger] = tfs->make<TH1D>(Form(
"EffThetaTotal_%s", tagger.c_str()),
"", 20, 0, 3.2);
195 hEffThetaReco[tagger] = tfs->make<TH1D>(Form(
"EffThetaReco_%s", tagger.c_str()),
"", 20, 0, 3.2);
196 hEffPhiTotal[tagger] = tfs->make<TH1D>(Form(
"EffPhiTotal_%s", tagger.c_str()),
"", 20, -3.2, 3.2);
197 hEffPhiReco[tagger] = tfs->make<TH1D>(Form(
"EffPhiReco_%s", tagger.c_str()),
"", 20, -3.2, 3.2);
199 hTime = tfs->make<TH1D>(
"Time",
"", 100, -2000, 4000);
200 hTime2 = tfs->make<TH1D>(
"Time2",
"", 100, -2000, 4000);
201 hX1 = tfs->make<TH1D>(
"X1",
"", 100, -1000, 1000);
202 hX2 = tfs->make<TH1D>(
"X2",
"", 100, -1000, 1000);
203 hY1 = tfs->make<TH1D>(
"Y1",
"", 100, -1000, 1000);
204 hY2 = tfs->make<TH1D>(
"Y2",
"", 100, -1000, 1000);
205 hZ1 = tfs->make<TH1D>(
"Z1",
"", 100, -1000, 1000);
206 hZ2 = tfs->make<TH1D>(
"Z2",
"", 100, -1000, 1000);
209 std::cout<<
"----------------- CRT Track Reco Ana Module -------------------"<<std::endl;
221 std::cout<<
"============================================"<<std::endl
222 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
223 <<
"============================================"<<std::endl;
230 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
233 auto crtHitHandle =
event.getValidHandle<std::vector<sbn::crt::CRTHit>>(
fCRTHitLabel);
236 auto crtTrackHandle =
event.getValidHandle<std::vector<sbn::crt::CRTTrack>>(
fCRTTrackLabel);
239 art::FindManyP<sbn::crt::CRTHit> findManyHits(crtTrackHandle, event,
fCRTTrackLabel);
244 std::map<int, std::vector<sbn::crt::CRTTrack>> crtTracks;
247 for(
auto const&
track : (*crtTrackHandle)){
250 if(trueId == -99999)
continue;
251 crtTracks[trueId].push_back(
track);
254 std::map<int, std::vector<sbn::crt::CRTHit>> crtHits;
255 double minHitTime = 99999;
256 double maxHitTime = -99999;
258 for(
auto const&
hit : (*crtHitHandle)){
259 double hitTime = (double)(
int)
hit.ts1_ns * 1
e-3;
260 if(hitTime < minHitTime) minHitTime = hitTime;
261 if(hitTime > maxHitTime) maxHitTime = hitTime;
265 if(trueId == -99999)
continue;
266 crtHits[trueId].push_back(
hit);
273 std::map<int, simb::MCParticle> particles;
274 for (
auto const& particle: (*particleHandle)){
275 int partId = particle.TrackId();
276 particles[partId] = particle;
279 double time = particle.T() * 1
e-3;
280 if(time < minHitTime || time > maxHitTime)
continue;
282 if(!(
std::abs(particle.PdgCode()) == 13 && particle.Mother()==0))
continue;
285 if(crtHits.find(partId) == crtHits.end())
continue;
287 std::vector<std::string> hitTaggers;
288 for(
auto const&
hit : crtHits[partId]){
289 if(std::find(hitTaggers.begin(), hitTaggers.end(),
hit.tagger) != hitTaggers.end())
continue;
290 hitTaggers.push_back(
hit.tagger);
293 if(nPlanesHit < 2)
continue;
295 double momentum = particle.P();
296 TVector3 start (particle.Vx(), particle.Vy(), particle.Vz());
297 TVector3
end (particle.EndX(), particle.EndY(), particle.EndZ());
298 double theta = (
end-start).Theta();
299 double phi = (
end-start).Phi();
300 for(
auto const&
tagger : hitTaggers){
309 if(crtTracks.find(partId) == crtTracks.end())
continue;
310 for(
auto const&
tagger : hitTaggers){
324 for(
auto const&
track : (*crtTrackHandle)){
334 std::vector<art::Ptr<sbn::crt::CRTHit>> hits = findManyHits.at(track_i);
338 if(particles.find(trueId) == particles.end())
continue;
343 double denominator = (
end - start).Mag();
346 simb::MCParticle particle = particles[trueId];
348 int nTraj = particle.NumberTrajectoryPoints();
351 for(
int j = 0; j < nTraj; j++){
352 TVector3 pt (particle.Vx(j), particle.Vy(j), particle.Vz(j));
353 if (pt.X() >= crtLims[0] && pt.X() <= crtLims[3] && pt.Y() >= crtLims[1] && pt.Y() <= crtLims[4] && pt.Z() >= crtLims[2] && pt.Z() <= crtLims[5]){
354 double numerator = ((pt - start).Cross(pt -
end)).Mag();
355 aveDCA += numerator/denominator;
360 aveDCA = aveDCA/npts;
364 for(
auto const&
hit : hits){
366 if(trueCross.X() == -99999)
continue;
368 double dist = std::sqrt(std::pow(
hit->x_pos - trueCross.X(), 2)
369 + std::pow(
hit->y_pos - trueCross.Y(), 2)
370 + std::pow(
hit->z_pos - trueCross.Z(), 2));
386 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
fhicl::Atom< art::InputTag > SimModuleLabel
fhicl::Atom< art::InputTag > CRTTrackLabel
int TrueIdFromTrackId(const art::Event &event, int track_i)
void Draw(detinfo::DetectorClocksData const &clockData, const art::Event &event)
fhicl::Atom< int > PlotTrackID
art::InputTag fCRTHitLabel
name of CRT hit producer
CRTTrackRecoAna(Parameters const &config)
std::map< std::string, TH1D * > hCrossDistance
CRTTaggerGeo GetTagger(std::string taggerName) const
fhicl::Atom< bool > VeryVerbose
virtual void analyze(const art::Event &event) override
art::InputTag fSimModuleLabel
name of detsim producer
process_name use argoneut_mc_hitfinder track
std::map< std::string, TH1D * > hEffPhiReco
int TrueIdFromHitId(const art::Event &event, int hit_i)
fhicl::Atom< art::InputTag > CRTHitLabel
void Initialize(const art::Event &event)
art::EDAnalyzer::Table< Config > Parameters
virtual void endJob() override
CRTBackTracker fCrtBackTrack
art::InputTag fCRTTrackLabel
name of CRT track producer
int fPlotTrackID
id of track to plot
std::map< std::string, TH1D * > hTrackDist
virtual void beginJob() override
auto end(FixedBins< T, C > const &) noexcept
std::map< std::string, TH1D * > hEffThetaReco
BEGIN_PROLOG vertical distance to the surface Name
size_t NumTaggers() const
Definition of data types for geometry description.
fhicl::Atom< bool > Verbose
std::map< std::string, TH1D * > hEffMomTotal
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
geo::Point_t TaggerCrossingPoint(std::string taggerName, const simb::MCParticle &particle)
void SetDrawTrueTracks(bool tf)
bool fVeryVerbose
print more information about what's going on
std::map< std::string, TH1D * > hEffPhiTotal
stream1 can override from command line with o or output services user sbnd
art::ServiceHandle< art::TFileService > tfs
std::vector< double > CRTLimits() const
fhicl::Table< CRTEventDisplay::Config > Evd
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
bool fVerbose
print information about what's going on
std::map< std::string, TH1D * > hEffThetaTotal
std::map< std::string, TH1D * > hEffMomReco
BEGIN_PROLOG could also be cout
fhicl::Table< CRTBackTracker::Config > CrtBackTrack