Belle II Software  release-05-01-25
CDCfromEclPathTruthVarSet.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Simon Kurz, Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/ckf/cdc/filters/paths/CDCfromEclPathTruthVarSet.h>
11 
12 #include <tracking/ckf/cdc/entities/CDCCKFState.h>
13 
14 #include <ecl/dataobjects/ECLShower.h>
15 #include <mdst/dataobjects/MCParticle.h>
16 
17 #include <tracking/dataobjects/RecoTrack.h>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 bool CDCfromEclPathTruthVarSet::extract(const BaseCDCPathFilter::Object* path)
23 {
24  // check if hit belongs to same seed
25  const auto& seed = path->front();
26  const auto* seedRecoTrack = seed.getSeed();
27  const auto* seedEclShower = seedRecoTrack->getRelated<ECLShower>("ECLShowers");
28  const auto* seedMCParticle = seedEclShower->getRelated<MCParticle>();
29  const auto* seedMCTrack = seedRecoTrack->getRelated<RecoTrack>("MCRecoTracks");
30 
31  int daughters = 0;
32  std::vector<MCParticle*> daughterMCParticles;
33  if (seedMCParticle->getNDaughters() > 0) {
34  daughterMCParticles = seedMCParticle->getDaughters();
35  }
36 
37  int matched = 0;
38 
39  for (auto const& state : *path) {
40  if (state.isSeed()) {
41  continue;
42  }
43 
44  const auto wireHit = state.getWireHit();
45  const auto cdcHit = wireHit->getHit();
46  auto* hitMCTrack = cdcHit->getRelated<RecoTrack>("MCRecoTracks");
47 
48  if (seedMCTrack != 0 && seedMCTrack == hitMCTrack) {
49  matched += 1;
50  }
51  }
52 
53 
54  var<named("matched")>() = matched;
55  var<named("daughters")>() = daughters;
56  var<named("PDG")>() = seedMCParticle->getPDG();
57 
58  auto seedMom = seedMCParticle->getMomentum();
59  var<named("seed_p_truth")>() = seedMom.Mag();
60  var<named("seed_theta_truth")>() = seedMom.Theta() * 180. / M_PI;
61  var<named("seed_pt_truth")>() = seedMom.Perp();
62  var<named("seed_pz_truth")>() = seedMom.Z();
63  var<named("seed_px_truth")>() = seedMom.X();
64  var<named("seed_py_truth")>() = seedMom.Y();
65 
66  // before, I used "RecoTracks" instead so I could get the msop.
67  // Gets track of mother particle (be careful, eg for photon guns)
68  const auto* particleMCTrack = seedMCParticle->getRelated<RecoTrack>("MCRecoTracks");
69  int mcTrackHits = -1;
70  if (particleMCTrack) {
71  mcTrackHits = particleMCTrack->getNumberOfCDCHits();
72  }
73  var<named("mcTrackHits")>() = mcTrackHits;
74 
75  return true;
76 }
Belle2::RelationsInterface::getRelated
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
Definition: RelationsObject.h:280
Belle2::ECLShower::getMomentum
TVector3 getMomentum() const
The method to get return TVector3 Momentum.
Definition: ECLShower.h:439
Belle2::RecoTrack
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:78
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RecoTrack::getNumberOfCDCHits
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
Definition: RecoTrack.h:417
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::TrackFindingCDC::Filter::Object
AObject Object
Type of the object to be analysed.
Definition: Filter.dcl.h:43
Belle2::ECLShower
Class to store ECL Showers.
Definition: ECLShower.h:42