Belle II Software  release-08-01-10
CDCfromEclPathTruthVarSet.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <tracking/ckf/cdc/filters/paths/CDCfromEclPathTruthVarSet.h>
9 
10 #include <tracking/ckf/cdc/entities/CDCCKFState.h>
11 
12 #include <ecl/dataobjects/ECLShower.h>
13 #include <mdst/dataobjects/MCParticle.h>
14 
15 #include <tracking/dataobjects/RecoTrack.h>
16 
17 using namespace Belle2;
18 
20 {
21  // check if hit belongs to same seed
22  const auto& seed = path->front();
23  const auto* seedRecoTrack = seed.getSeed();
24  const auto* seedEclShower = seedRecoTrack->getRelated<ECLShower>("ECLShowers");
25  const auto* seedMCParticle = seedEclShower->getRelated<MCParticle>();
26  const auto* seedMCTrack = seedRecoTrack->getRelated<RecoTrack>("MCRecoTracks");
27 
28  int daughters = 0;
29  std::vector<MCParticle*> daughterMCParticles;
30  if (seedMCParticle->getNDaughters() > 0) {
31  daughterMCParticles = seedMCParticle->getDaughters();
32  }
33 
34  int matched = 0;
35 
36  for (auto const& state : *path) {
37  if (state.isSeed()) {
38  continue;
39  }
40 
41  const auto wireHit = state.getWireHit();
42  const auto cdcHit = wireHit->getHit();
43  auto* hitMCTrack = cdcHit->getRelated<RecoTrack>("MCRecoTracks");
44 
45  if (seedMCTrack != 0 && seedMCTrack == hitMCTrack) {
46  matched += 1;
47  }
48  }
49 
50 
51  var<named("matched")>() = matched;
52  var<named("daughters")>() = daughters;
53  var<named("PDG")>() = seedMCParticle->getPDG();
54 
55  auto seedMom = seedMCParticle->getMomentum();
56  var<named("seed_p_truth")>() = seedMom.R();
57  var<named("seed_theta_truth")>() = seedMom.Theta() * 180. / M_PI;
58  var<named("seed_pt_truth")>() = seedMom.Rho();
59  var<named("seed_pz_truth")>() = seedMom.Z();
60  var<named("seed_px_truth")>() = seedMom.X();
61  var<named("seed_py_truth")>() = seedMom.Y();
62 
63  // before, I used "RecoTracks" instead so I could get the msop.
64  // Gets track of mother particle (be careful, eg for photon guns)
65  const auto* particleMCTrack = seedMCParticle->getRelated<RecoTrack>("MCRecoTracks");
66  int mcTrackHits = -1;
67  if (particleMCTrack) {
68  mcTrackHits = particleMCTrack->getNumberOfCDCHits();
69  }
70  var<named("mcTrackHits")>() = mcTrackHits;
71 
72  return true;
73 }
virtual bool extract(const BaseCDCPathFilter::Object *path) override
Generate and assign the variables from the object.
Class to store ECL Showers.
Definition: ECLShower.h:30
ROOT::Math::XYZVector getMomentum() const
The method to get return ROOT::Math::XYZVector Momentum.
Definition: ECLShower.h:452
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
unsigned int getNumberOfCDCHits() const
Return the number of cdc hits.
Definition: RecoTrack.h:427
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
AObject Object
Type of the object to be analysed.
Definition: Filter.dcl.h:33
constexpr static int named(const char *name)
Getter for the index from the name.
Definition: VarSet.h:78
Float_t & var()
Reference getter for the value of the ith variable. Static version.
Definition: VarSet.h:93
Abstract base class for different kinds of events.