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