22 #include "nusimdata/SimulationBase/MCParticle.h"
23 #include "nusimdata/SimulationBase/MCTruth.h"
31 #include "art/Framework/Core/EDAnalyzer.h"
32 #include "art/Framework/Principal/Event.h"
33 #include "art/Framework/Principal/Handle.h"
34 #include "art_root_io/TFileService.h"
35 #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"
81 Name(
"SimModuleLabel"),
82 Comment(
"tag of detector simulation data product")
86 Name(
"TpcTrackModuleLabel"),
87 Comment(
"tag of TPC track producer data product")
92 Comment(
"tag of pandora data product")
97 Comment(
"Print information about what's going on")
104 fhicl::Table<trkf::TrajectoryMCSFitter::Config>
fitter {
109 Name(
"BeamTimeLimits"),
124 virtual void analyze(
const art::Event& event)
override;
127 virtual void endJob()
override;
153 std::vector<std::string>
cuts{
"None",
"FV",
"SP",
"Geo",
"CC",
"AC",
"CT",
"CH",
"PT",
"PN",
"Tot",
"Remain"};
178 , fSimModuleLabel (config().SimModuleLabel())
179 , fTpcTrackModuleLabel (config().TpcTrackModuleLabel())
180 , fPandoraLabel (config().PandoraLabel())
181 , fVerbose (config().
Verbose())
182 , fBeamTimeMin (config().BeamTimeLimits().BeamTimeMin())
183 , fBeamTimeMax (config().BeamTimeLimits().BeamTimeMax())
184 , cosIdAlg (config().CosIdAlg())
185 , fMcsFitter (config().fitter)
194 art::ServiceHandle<art::TFileService>
tfs;
196 hBeamTime = tfs->make<TH1D>(
"BeamTime",
"", 100, -10, 10);
198 for(
size_t i = 0; i <
nTC; i++){
199 for(
size_t j = 0; j <
nCuts; j++){
200 TString hMom_name = Form(
"hTrueMom%s_%s",
trueCategories[i].c_str(),
cuts[j].c_str());
201 hTrueMom[i][j] = tfs->make<TH1D>(hMom_name,
"", 20, 0, 2);
202 TString hLength_name = Form(
"hTrueLength%s_%s",
trueCategories[i].c_str(),
cuts[j].c_str());
203 hTrueLength[i][j] = tfs->make<TH1D>(hLength_name,
"", 20, 0, 500);
204 TString hTheta_name = Form(
"hTrueTheta%s_%s",
trueCategories[i].c_str(),
cuts[j].c_str());
205 hTrueTheta[i][j] = tfs->make<TH1D>(hTheta_name,
"", 20, 0, 3.2);
206 TString hPhi_name = Form(
"hTruePhi%s_%s",
trueCategories[i].c_str(),
cuts[j].c_str());
207 hTruePhi[i][j] = tfs->make<TH1D>(hPhi_name,
"", 20, -3.2, 3.2);
211 for(
size_t i = 0; i <
nRC; i++){
212 for(
size_t j = 0; j <
nCuts; j++){
213 TString hMom_name = Form(
"hRecoMom%s_%s",
recoCategories[i].c_str(),
cuts[j].c_str());
214 hRecoMom[i][j] = tfs->make<TH1D>(hMom_name,
"", 20, 0, 2);
215 TString hLength_name = Form(
"hRecoLength%s_%s",
recoCategories[i].c_str(),
cuts[j].c_str());
216 hRecoLength[i][j] = tfs->make<TH1D>(hLength_name,
"", 20, 0, 500);
217 TString hTheta_name = Form(
"hRecoTheta%s_%s",
recoCategories[i].c_str(),
cuts[j].c_str());
218 hRecoTheta[i][j] = tfs->make<TH1D>(hTheta_name,
"", 20, 0, 3.2);
219 TString hPhi_name = Form(
"hRecoPhi%s_%s",
recoCategories[i].c_str(),
cuts[j].c_str());
220 hRecoPhi[i][j] = tfs->make<TH1D>(hPhi_name,
"", 20, -3.2, 3.2);
225 if(
fVerbose)
std::cout<<
"----------------- Cosmic ID Ana Module -------------------"<<std::endl;
235 std::cout<<
"============================================"<<std::endl
236 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
237 <<
"============================================"<<std::endl;
245 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
247 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
252 if( !pfParticleHandle.isValid() ){
259 art::FindManyP< recob::Track > pfPartToTrackAssoc(pfParticleHandle, event,
fTpcTrackModuleLabel);
270 std::map<int, simb::MCParticle> particles;
271 std::vector<simb::MCParticle> parts;
272 std::vector<int> nuParticleIds;
273 std::vector<int> lepParticleIds;
274 std::vector<int> dirtParticleIds;
275 std::vector<int> crParticleIds;
278 for (
auto const& particle: (*particleHandle)){
280 int partId = particle.TrackId();
281 particles[partId] = particle;
282 parts.push_back(particle);
284 art::Ptr<simb::MCTruth> truth = pi_serv->TrackIdToMCTruth_P(partId);
288 if(truth->Origin() == simb::kBeamNeutrino){
290 vtx.SetX(truth->GetNeutrino().Nu().Vx()); vtx.SetY(truth->GetNeutrino().Nu().Vy()); vtx.SetZ(truth->GetNeutrino().Nu().Vz());
293 dirtParticleIds.push_back(partId);
296 else if(pdg==13 && particle.Mother()==0){
297 lepParticleIds.push_back(partId);
301 nuParticleIds.push_back(partId);
308 crParticleIds.push_back(partId);
318 std::vector<double> fakeTpc0Flashes = fakeFlashes.first;
319 std::vector<double> fakeTpc1Flashes = fakeFlashes.second;
324 if(!tpc0BeamFlash && !tpc1BeamFlash)
return;
330 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
331 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
334 for (PFParticleIdMap::const_iterator it = pfParticleMap.begin(); it != pfParticleMap.end(); ++it){
336 const art::Ptr<recob::PFParticle> pParticle(it->second);
338 if (!pParticle->IsPrimary())
continue;
340 const int pdg(pParticle->PdgCode());
343 if(!isNeutrino)
continue;
346 std::vector<recob::Track> nuTracks;
349 for (
const size_t daughterId : pParticle->Daughters()){
352 art::Ptr<recob::PFParticle> pDaughter = pfParticleMap.at(daughterId);
353 const std::vector< art::Ptr<recob::Track> > associatedTracks(pfPartToTrackAssoc.at(pDaughter.key()));
354 if(associatedTracks.size() != 1)
continue;
358 nuTracks.push_back(tpcTrack);
361 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.
ID());
364 if(std::find(lepParticleIds.begin(), lepParticleIds.end(), trueId) != lepParticleIds.end()){
368 else if(std::find(nuParticleIds.begin(), nuParticleIds.end(), trueId) != nuParticleIds.end()){
369 if(pfpType != 0) pfpType = 4;
371 else if(std::find(dirtParticleIds.begin(), dirtParticleIds.end(), trueId) != dirtParticleIds.end()){
373 if(pfpType != 0 && pfpType != 4) pfpType = 1;
375 else if(std::find(crParticleIds.begin(), crParticleIds.end(), trueId) != crParticleIds.end()){
377 if(pfpType != 0 && pfpType != 4 && pfpType != 1) pfpType = 2;
381 if(particles.find(trueId) != particles.end()){
383 if(
std::abs(particles[trueId].PdgCode()) == 13){
386 double momentum = particles[trueId].P();
388 double theta = (se.second-se.first).Theta();
389 double phi = (se.second-se.first).Phi();
391 for(
size_t j = 0; j <
nCuts; j++){
393 if(j == 0) plot =
true;
395 cosIdAlg.
SetCuts(
true,
false,
false,
false,
false,
false,
false,
false,
false);
396 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
399 cosIdAlg.
SetCuts(
false,
true,
false,
false,
false,
false,
false,
false,
false);
400 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
403 cosIdAlg.
SetCuts(
false,
false,
true,
false,
false,
false,
false,
false,
false);
404 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
408 cosIdAlg.
SetCuts(
false,
false,
false,
true,
false,
false,
false,
false,
false);
409 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
412 cosIdAlg.
SetCuts(
false,
false,
false,
false,
true,
false,
false,
false,
false);
413 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
416 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
true,
false,
false,
false);
417 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
420 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
false,
true,
false,
false);
421 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
424 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
false,
false,
true,
false);
425 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
428 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
false,
false,
false,
true);
429 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
434 if(
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
436 if(j == 11 && !
cosIdAlg.
CosmicId(tpcTrack, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
439 hTrueMom[trackType][j]->Fill(momentum);
449 if(nuTracks.size() == 0)
continue;
452 std::sort(nuTracks.begin(), nuTracks.end(), [](
auto&
left,
auto&
right){
453 return left.Length() >
right.Length();});
458 double recoMuMomentum = 0.;
460 double length = nuTrack.Length();
461 double theta = nuTrack.Theta();
462 double phi = nuTrack.Phi();
471 for(
size_t j = 0; j <
nCuts; j++){
473 if(j == 0) plot =
true;
475 cosIdAlg.
SetCuts(
true,
false,
false,
false,
false,
false,
false,
false,
false);
481 cosIdAlg.
SetCuts(
false,
true,
false,
false,
false,
false,
false,
false,
false);
487 cosIdAlg.
SetCuts(
false,
false,
true,
false,
false,
false,
false,
false,
false);
493 cosIdAlg.
SetCuts(
false,
false,
false,
true,
false,
false,
false,
false,
false);
499 cosIdAlg.
SetCuts(
false,
false,
false,
false,
true,
false,
false,
false,
false);
505 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
true,
false,
false,
false);
511 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
false,
true,
false,
false);
517 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
false,
false,
true,
false);
523 cosIdAlg.
SetCuts(
false,
false,
false,
false,
false,
false,
false,
false,
true);
531 if(
cosIdAlg.
CosmicId(
detProp, *pParticle, pfParticleMap, event, fakeTpc0Flashes, fakeTpc1Flashes)) plot =
true;
533 if(j == 11 && !
cosIdAlg.
CosmicId(
detProp, *pParticle, pfParticleMap, event, fakeTpc0Flashes, fakeTpc1Flashes)){
538 hRecoMom[pfpType][j]->Fill(recoMuMomentum);
554 for (
unsigned int i = 0; i < pfParticleHandle->size(); ++i){
555 const art::Ptr<recob::PFParticle> pParticle(pfParticleHandle, i);
556 if (!pfParticleMap.insert(PFParticleIdMap::value_type(pParticle->Self(), pParticle)).second){
557 std::cout <<
" Unable to get PFParticle ID map, the input PFParticle collection has repeat IDs!" <<
"\n";
void GetPFParticleIdMap(const PFParticleHandle &pfParticleHandle, PFParticleIdMap &pfParticleMap)
fhicl::Atom< art::InputTag > TpcTrackModuleLabel
trkf::TrajectoryMCSFitter fMcsFitter
art::InputTag fTpcTrackModuleLabel
name of TPC track producer
bool BeamFlash(std::vector< double > flashes, double beamTimeMin, double beamTimeMax)
fhicl::Atom< art::InputTag > SimModuleLabel
Declaration of signal hit object.
bool CosmicId(recob::Track track, const art::Event &event, std::vector< double > t0Tpc0, std::vector< double > t0Tpc1)
std::vector< std::string > recoCategories
TH1D * hRecoLength[5][12]
fhicl::Atom< bool > Verbose
CosmicIdAna(Parameters const &config)
std::vector< std::string > cuts
float bestMomentum() const
momentum for best direction fit
art::EDAnalyzer::Table< Config > Parameters
double TpcLength(const simb::MCParticle &particle)
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)
TH1D * hTrueLength[4][12]
fhicl::Table< CosmicIdAlg::Config > CosIdAlg
std::map< size_t, art::Ptr< recob::PFParticle > > PFParticleIdMap
virtual void beginJob() override
trkf::TrackMomentumCalculator fRangeFitter
Definition of data types for geometry description.
Provides recob::Track data product.
art::InputTag fSimModuleLabel
name of detsim producer
Class storing the result of the Maximum Likelihood fit of Multiple Coulomb Scattering angles between ...
fhicl::Table< trkf::TrajectoryMCSFitter::Config > fitter
art::InputTag fPandoraLabel
art::Handle< std::vector< recob::PFParticle > > PFParticleHandle
virtual void endJob() override
Class for Maximum Likelihood fit of Multiple Coulomb Scattering angles between segments within a Trac...
std::pair< std::vector< double >, std::vector< double > > FakeTpcFlashes(std::vector< simb::MCParticle > particles)
stream1 can override from command line with o or output services user sbnd
bool fVerbose
print information about what's going on
fhicl::Atom< double > BeamTimeMax
art::ServiceHandle< art::TFileService > tfs
std::vector< std::string > trueCategories
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
virtual void analyze(const art::Event &event) override
fhicl::Table< BeamTime > BeamTimeLimits
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:
double GetTrackMomentum(double trkrange, int pdg) const
std::pair< TVector3, TVector3 > CrossingPoints(const simb::MCParticle &particle)
fhicl::Atom< art::InputTag > PandoraLabel
bool InFiducial(geo::Point_t point, double fiducial)
fhicl::Atom< double > BeamTimeMin
void SetCuts(bool FV, bool SP, bool Geo, bool CC, bool AC, bool CT, bool CH, bool PT, bool PN)