Belle II Software  release-08-01-10
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 header.
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  //-----------------------------------------------------------------
37  //-----------------------------------------------------------------
38 
39  REG_MODULE(TOPMCTrackMaker);
40 
41  //-----------------------------------------------------------------
42  // Implementation
43  //-----------------------------------------------------------------
44 
45  TOPMCTrackMakerModule::TOPMCTrackMakerModule() : Module()
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.");
52 
53  // Add parameters
54 
55  }
56 
58  {
59  }
60 
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 
89  {
90  }
91 
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().R();
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 
143  {
144  }
145 
147  {
148  }
149 
150 
152 } // end Belle2 namespace
153 
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:580
int getPDGCode() const
PDG code.
Definition: Const.h:464
double getMass() const
Particle mass.
Definition: UnitConst.cc:356
static const ChargedStable pion
charged pion particle
Definition: Const.h:652
static const double speedOfLight
[cm/ns]
Definition: Const.h:686
@ c_PrimaryParticle
bit 0: Particle is primary particle.
Definition: MCParticle.h:47
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
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:28
static const double T
[tesla]
Definition: Unit.h:120
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:91
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
virtual ~TOPMCTrackMakerModule()
Destructor.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
Abstract base class for different kinds of events.