262 std::cout<<
"============================================"<<std::endl
263 <<
"Run = "<<
event.run()<<
", SubRun = "<<
event.subRun()<<
", Event = "<<
event.id().event()<<std::endl
264 <<
"============================================"<<std::endl;
273 art::ServiceHandle<cheat::ParticleInventoryService> pi_serv;
274 auto particleHandle =
event.getValidHandle<std::vector<simb::MCParticle>>(
fSimModuleLabel);
277 art::Handle< std::vector<sbn::crt::CRTHit>> crtHitHandle;
278 std::vector<art::Ptr<sbn::crt::CRTHit> > crtHitList;
280 art::fill_ptr_vector(crtHitList, crtHitHandle);
283 art::Handle< std::vector<sbn::crt::CRTTrack>> crtTrackHandle;
284 std::vector<art::Ptr<sbn::crt::CRTTrack> > crtTrackList;
286 art::fill_ptr_vector(crtTrackList, crtTrackHandle);
287 art::FindManyP<sbn::crt::CRTHit> findManyCrtHits(crtTrackHandle, event,
fCRTTrackLabel);
290 auto tpcTrackHandle =
event.getValidHandle<std::vector<recob::Track>>(
fTPCTrackLabel);
291 art::FindManyP<recob::Hit> findManyHits(tpcTrackHandle, event,
fTPCTrackLabel);
300 double minHitTime = 99999;
301 double maxHitTime = -99999;
302 for(
auto const&
hit : (*crtHitHandle)){
303 double hitTime = (double)(
int)
hit.ts1_ns * 1
e-3;
304 if(hitTime < minHitTime) minHitTime = hitTime;
305 if(hitTime > maxHitTime) maxHitTime = hitTime;
308 std::map<int, simb::MCParticle> particles;
309 std::map<int, CRTTruthMatch> truthMatching;
311 for (
auto const& particle: (*particleHandle)){
313 CRTTruthMatch truthMatch;
315 int partID = particle.TrackId();
316 particles[partID] = particle;
319 if(!(
std::abs(particle.PdgCode()) == 13 && particle.Mother()==0))
continue;
321 double time = particle.T() * 1
e-3;
322 if(time < minHitTime || time > maxHitTime)
continue;
324 truthMatch.partID = partID;
325 truthMatch.trueT0 = time;
326 truthMatch.hasTpcTrack =
false;
334 if(trueCP.X() != -99999){
335 truthMatch.trueCrosses[taggerName] = trueCP;
338 truthMatch.validCrosses[taggerName] = validCP;
341 truthMatching[partID] = truthMatch;
348 std::vector<sbn::crt::CRTHit> crtHits;
350 for (
auto const& crtHit: (*crtHitHandle)){
351 crtHits.push_back(crtHit);
353 std::string taggerName = crtHit.tagger;
360 if(truthMatching.find(partID) == truthMatching.end())
continue;
362 truthMatching[partID].crtHits[taggerName].push_back(crtHit);
368 std::vector<sbn::crt::CRTTrack> crtTracks;
370 for (
auto const& crtTrack : (*crtTrackHandle)){
371 crtTracks.push_back(crtTrack);
376 if(truthMatching.find(partID) == truthMatching.end())
continue;
378 truthMatching[partID].crtTracks.push_back(crtTrack);
384 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
385 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
388 for (
auto const& tpcTrack : (*tpcTrackHandle)){
390 std::vector<art::Ptr<recob::Hit>> hits = findManyHits.at(tpcTrack.ID());
392 if(truthMatching.find(partID) == truthMatching.end())
continue;
393 truthMatching[partID].hasTpcTrack =
true;
398 if(hitT0 != -99999) truthMatching[partID].hitT0s.push_back(hitT0);
402 if(trackT0 != -99999) truthMatching[partID].trackT0s.push_back(trackT0);
410 for(
auto const& truthMatch : truthMatching){
411 CRTTruthMatch match = truthMatch.second;
412 int partID = match.partID;
414 double momentum = particles[partID].P();
415 TVector3 start(particles[partID].Vx(), particles[partID].Vy(), particles[partID].Vz());
416 TVector3
end(particles[partID].EndX(), particles[partID].EndY(), particles[partID].EndZ());
417 double theta = (
end-start).Theta();
418 double phi = (
end-start).Phi();
422 for(
auto const& trueCross : match.trueCrosses){
424 std::string taggerName = trueCross.first;
427 double minDist = 99999;
430 if(match.crtHits.find(taggerName) == match.crtHits.end())
continue;
431 for(
auto const& crtHit : match.crtHits[taggerName]){
432 double dist = pow(crtHit.x_pos-trueCP.X(), 2) + pow(crtHit.y_pos-trueCP.Y(), 2) + pow(crtHit.z_pos-trueCP.Z(), 2);
440 if(minDist != 99999){
448 double minThetaDiff = 99999;
449 double minPhiDiff = 99999;
450 double minTheta = 99999;
451 double minPhi = 99999;
452 bool complete =
true;
454 simb::MCParticle particle = particles[match.partID];
455 TVector3 trueStart(particle.Vx(), particle.Vy(), particle.Vz());
456 TVector3 trueEnd(particle.EndX(), particle.EndY(), particle.EndZ());
457 if(trueEnd.Y() > trueStart.Y()) std::swap(trueStart, trueEnd);
458 double trueTheta = (trueEnd - trueStart).Theta();
459 double truePhi = (trueEnd - trueStart).Phi();
461 for(
auto const& crtTrack : match.crtTracks){
463 TVector3 recoStart(crtTrack.x1_pos, crtTrack.y1_pos, crtTrack.z1_pos);
464 TVector3 recoEnd(crtTrack.x2_pos, crtTrack.y2_pos, crtTrack.z2_pos);
465 if(recoEnd.Y() > recoStart.Y()) std::swap(recoStart, recoEnd);
466 double recoTheta = (recoEnd - recoStart).Theta();
467 double recoPhi = (recoEnd - recoStart).Phi();
468 double thetaDiff = TMath::ATan2(TMath::Sin(recoTheta-trueTheta), TMath::Cos(recoTheta-trueTheta));
469 double phiDiff = TMath::ATan2(TMath::Sin(recoPhi-truePhi), TMath::Cos(recoPhi-truePhi));
470 if(thetaDiff < minThetaDiff){
471 minThetaDiff = thetaDiff;
472 minPhiDiff = phiDiff;
473 minTheta = recoTheta;
475 complete = crtTrack.complete;
479 if(minThetaDiff != 99999){
503 double bestHitT0Diff = 99999;
504 for(
auto const& hitT0 : match.hitT0s){
505 double hitT0Diff =
std::abs(match.trueT0 - hitT0);
506 if(hitT0Diff < bestHitT0Diff) bestHitT0Diff = hitT0Diff;
508 if(bestHitT0Diff != 99999){
513 if(bestHitT0Diff < 2){
523 double bestTrackT0Diff = 99999;
524 for(
auto const& trackT0 : match.trackT0s){
525 double trackT0Diff =
std::abs(match.trueT0 - trackT0);
526 if(trackT0Diff < bestTrackT0Diff) bestTrackT0Diff = trackT0Diff;
528 if(bestTrackT0Diff != 99999){
533 if(bestTrackT0Diff < 2){
541 bool matchesCRTHit = (match.crtHits.size() > 0);
542 bool matchesCRTTrack = (match.crtTracks.size() > 0);
543 bool matchesHitT0 = (match.hitT0s.size() > 0);
544 bool matchesTrackT0 = (match.trackT0s.size() > 0);
545 std::vector<bool> matches{matchesCRTHit, matchesCRTTrack, matchesHitT0, matchesTrackT0};
547 std::vector<bool> crtHitCategories;
548 std::vector<bool> crtTrackCategories;
549 std::vector<bool> hitT0Categories;
550 std::vector<bool> trackT0Categories;
553 crtHitCategories.push_back((match.trueCrosses.size() > 0));
554 crtTrackCategories.push_back((match.trueCrosses.size() > 1));
555 hitT0Categories.push_back((match.trueCrosses.size() > 0) && match.hasTpcTrack);
556 trackT0Categories.push_back((match.trueCrosses.size() > 1) && match.hasTpcTrack);
560 bool validHit =
false;
561 for(
auto const& valid : match.validCrosses){
562 if(valid.second) validHit =
true;
564 crtHitCategories.push_back(validHit);
565 crtTrackCategories.push_back(match.crtHits.size() > 1);
566 hitT0Categories.push_back((match.crtHits.size() > 0 && match.hasTpcTrack));
567 trackT0Categories.push_back((match.crtTracks.size() > 0 && match.hasTpcTrack));
571 crtHitCategories.push_back(entersCRT);
572 crtTrackCategories.push_back(entersCRT);
573 hitT0Categories.push_back((entersCRT && match.hasTpcTrack));
574 trackT0Categories.push_back((entersCRT && match.hasTpcTrack));
578 crtHitCategories.push_back(entersTPC);
579 crtTrackCategories.push_back(entersTPC);
580 hitT0Categories.push_back((entersTPC && match.hasTpcTrack));
581 trackT0Categories.push_back((entersTPC && match.hasTpcTrack));
585 crtHitCategories.push_back(crossesCRT);
586 crtTrackCategories.push_back(crossesCRT);
587 hitT0Categories.push_back((crossesCRT && match.hasTpcTrack));
588 trackT0Categories.push_back((crossesCRT && match.hasTpcTrack));
592 crtHitCategories.push_back(crossesTPC);
593 crtTrackCategories.push_back(crossesTPC);
594 hitT0Categories.push_back((crossesTPC && match.hasTpcTrack));
595 trackT0Categories.push_back((crossesTPC && match.hasTpcTrack));
597 std::vector<std::vector<bool>> matchCategories{crtHitCategories, crtTrackCategories, hitT0Categories, trackT0Categories};
599 for(
size_t si = 0; si <
stage.size(); si++){
600 for(
size_t ci = 0; ci <
category.size(); ci++){
601 if(!matchCategories[si][ci])
continue;
602 hEffMom[si][ci][0]->Fill(momentum);
606 if(!matches[si])
continue;
607 hEffMom[si][ci][1]->Fill(momentum);
int TrueIdFromTrackId(const art::Event &event, int track_i)
TH1D * hEffTheta[4][6][2]
bool CrossesVolume(const simb::MCParticle &particle)
CRTTaggerGeo GetTagger(std::string taggerName) const
bool fVerbose
print information about what's going on
std::map< std::string, TH3D * > hTaggerXYZResolution
int TrueIdFromHitId(const art::Event &event, int hit_i)
float z_pos
position in z-direction (cm).
void Initialize(const art::Event &event)
TH1D * hPurityTheta[2][2]
auto end(FixedBins< T, C > const &) noexcept
TH1D * hTrackThetaDiff[3]
bool EntersVolume(const simb::MCParticle &particle)
int TrueParticleIDFromTotalRecoHits(detinfo::DetectorClocksData const &clockData, const std::vector< art::Ptr< recob::Hit > > &hits, bool rollup_unsaved_ids=1)
size_t NumTaggers() const
art::InputTag fTPCTrackLabel
name of CRT producer
art::InputTag fCRTTrackLabel
name of CRT producer
float y_pos
position in y-direction (cm).
double T0FromCRTHits(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTHit > crtHits, const art::Event &event)
std::vector< std::string > stage
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
geo::Point_t TaggerCrossingPoint(std::string taggerName, const simb::MCParticle &particle)
float x_pos
position in x-direction (cm).
std::vector< std::string > category
CRTBackTracker fCrtBackTrack
art::InputTag fSimModuleLabel
name of detsim producer
bool EntersVolume(const simb::MCParticle &particle)
double T0FromCRTTracks(detinfo::DetectorPropertiesData const &detProp, recob::Track tpcTrack, std::vector< sbn::crt::CRTTrack > crtTracks, const art::Event &event)
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
art::InputTag fCRTHitLabel
name of CRT producer
bool ValidCrossingPoint(std::string taggerName, const simb::MCParticle &particle)
BEGIN_PROLOG could also be cout
bool CrossesVolume(const simb::MCParticle &particle)
CRTTrackMatchAlg crtTrackAlg