Belle II Software  release-05-02-19
TOPMCTrackMakerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 // Own include
12 #include <top/modules/TOPMCTrackMaker/TOPMCTrackMakerModule.h>
13 
14 // framework - DataStore
15 #include <framework/datastore/StoreArray.h>
16 
17 // framework aux
18 #include <framework/gearbox/Unit.h>
19 #include <framework/gearbox/Const.h>
20 #include <framework/geometry/BFieldManager.h>
21 
22 // dataobjects
23 #include <mdst/dataobjects/Track.h>
24 #include <mdst/dataobjects/TrackFitResult.h>
25 #include <tracking/dataobjects/ExtHit.h>
26 #include <mdst/dataobjects/MCParticle.h>
27 #include <top/dataobjects/TOPBarHit.h>
28 
29 using namespace std;
30 
31 namespace Belle2 {
37  //-----------------------------------------------------------------
38  // Register module
39  //-----------------------------------------------------------------
40 
41  REG_MODULE(TOPMCTrackMaker)
42 
43  //-----------------------------------------------------------------
44  // Implementation
45  //-----------------------------------------------------------------
46 
48 
49  {
50  // set module description (e.g. insert text)
51  setDescription("Constructs Tracks and ExtHits from MCParticles and TOPBarHits. "
52  "Utility needed for testing and debugging of TOP reconstruction.");
53  setPropertyFlags(c_ParallelProcessingCertified);
54 
55  // Add parameters
56 
57  }
58 
59  TOPMCTrackMakerModule::~TOPMCTrackMakerModule()
60  {
61  }
62 
63  void TOPMCTrackMakerModule::initialize()
64  {
65 
66  // input
67 
68  StoreArray<MCParticle> mcParticles;
69  mcParticles.isRequired();
70 
71  StoreArray<TOPBarHit> barHits;
72  barHits.isRequired();
73 
74  // output
75 
76  StoreArray<Track> tracks;
77  tracks.registerInDataStore();
78 
79  StoreArray<TrackFitResult> fitResults;
80  fitResults.registerInDataStore();
81 
82  StoreArray<ExtHit> extHits;
83  extHits.registerInDataStore();
84 
85  tracks.registerRelationTo(mcParticles);
86  tracks.registerRelationTo(extHits);
87 
88  }
89 
90  void TOPMCTrackMakerModule::beginRun()
91  {
92  }
93 
94  void TOPMCTrackMakerModule::event()
95  {
96 
97  StoreArray<MCParticle> mcParticles;
98  StoreArray<TOPBarHit> barHits;
99 
100  StoreArray<Track> tracks;
101  StoreArray<TrackFitResult> fitResults;
102  StoreArray<ExtHit> extHits;
103 
104  for (const auto& mcParticle : mcParticles) {
105  if (mcParticle.getStatus(MCParticle::c_PrimaryParticle) == 0) continue;
106  if (mcParticle.getCharge() == 0) continue;
107  const auto* barHit = mcParticle.getRelated<TOPBarHit>();
108  if (!barHit) continue;
109 
110  TMatrixDSym cov(6); // infinite precission
111  fitResults.appendNew(mcParticle.getVertex(),
112  mcParticle.getMomentum(),
113  cov,
114  mcParticle.getCharge(),
115  Const::pion,
116  1.0, // pValue
117  BFieldManager::getField(0, 0, 0).Z() / Unit::T,
118  0x38FFFFFFFFFFFFFF, // 56 hits, in all CDC layers
119  0, 56 - 5); // NDF = 56-5
120  auto* track = tracks.appendNew();
121  track->setTrackFitResultIndex(Const::pion, fitResults.getEntries() - 1);
122  track->addRelationTo(&mcParticle);
123 
124  const Const::ChargedStable& chargedStable = Const::pion;
125  double pmom = barHit->getMomentum().Mag();
126  double mass = chargedStable.getMass();
127  double beta = pmom / sqrt(pmom * pmom + mass * mass);
128  double tof = barHit->getLength() / beta / Const::speedOfLight;
129  auto* extHit = extHits.appendNew(chargedStable.getPDGCode(),
130  Const::TOP,
131  barHit->getModuleID(),
132  EXT_ENTER,
133  false,
134  tof,
135  barHit->getPosition(),
136  barHit->getMomentum(),
137  cov);
138  track->addRelationTo(extHit);
139  }
140 
141  }
142 
143 
144  void TOPMCTrackMakerModule::endRun()
145  {
146  }
147 
148  void TOPMCTrackMakerModule::terminate()
149  {
150  }
151 
152 
154 } // end Belle2 namespace
155 
Belle2::StoreArray::appendNew
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:256
Belle2::TOPMCTrackMakerModule
Constructs Tracks and ExtHits from MCParticles and TOPBarHits Utility needed for testing and debuggin...
Definition: TOPMCTrackMakerModule.h:37
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Const::ParticleType::getPDGCode
int getPDGCode() const
PDG code.
Definition: Const.h:349
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::TOPBarHit
Class to store track parameters of incoming MC particles relation to MCParticle filled in top/simulat...
Definition: TOPBarHit.h:36
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Const::ChargedStable
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:465
Belle2::StoreArray< MCParticle >
Belle2::Const::ParticleType::getMass
double getMass() const
Particle mass.
Definition: UnitConst.cc:310