Belle II Software development
CDCDedxHitSaverModule.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#include <cdc/modules/CDCDedxPID/CDCDedxHitSaverModule.h>
10#include <cdc/dataobjects/CDCHit.h>
11#include <cdc/dataobjects/CDCRecoHit.h>
12#include <genfit/KalmanFitterInfo.h>
13#include <genfit/Exception.h>
14#include <genfit/MaterialEffects.h>
15#include <map>
16
17namespace Belle2 {
23 //-----------------------------------------------------------------
25 //-----------------------------------------------------------------
26
27 REG_MODULE(CDCDedxHitSaver);
28
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32
34
35 {
36 // set module description
37 setDescription("Module that stores CDC hit information from recoTracks, which is needed for dedx.");
39 }
40
42 {
43 }
44
46 {
47 m_tracks.isRequired();
48 m_recoTracks.isRequired();
49 m_hits.registerInDataStore();
50 m_tracks.registerRelationTo(m_hits);
51
52 if (not genfit::MaterialEffects::getInstance()->isInitialized()) {
53 B2FATAL("Need to have SetupGenfitExtrapolationModule in path before this one.");
54 }
55
56 }
57
59 {
60 // clear output collection
61 m_hits.clear();
62
63 // loop over tracks and save CDC hits stored in recoTracks
64 for (const auto& track : m_tracks) {
65
66 const RecoTrack* recoTrack = track.getRelatedTo<RecoTrack>();
67
68 if (not recoTrack) {
69 B2WARNING("No related recoTrack for this track");
70 continue;
71 }
72
73 if (recoTrack->hasTrackFitStatus()) {
74 if (recoTrack->getTrackFitStatus()->isTrackPruned()) {
75 B2ERROR("GFTrack is pruned, please run CDCDedxHitSaver only on unpruned tracks! Skipping this track.");
76 continue;
77 }
78 } else // The RecoTrack might not have a fit status for reasons: let's skip it
79 continue;
80
81 // loop over hits of this track
82 for (const auto& hitPoint : recoTrack->getHitPointsWithMeasurement()) {
83 // get CDCHit
84 const auto* rawMeasurement = hitPoint->getRawMeasurement(0);
85 if (not rawMeasurement) continue;
86 const auto* cdcRecoHit = dynamic_cast<const CDCRecoHit*>(rawMeasurement);
87 if (not cdcRecoHit) continue;
88 const auto* cdcHit = cdcRecoHit->getCDCHit();
89 if (not cdcHit) continue;
90
91 // make sure the fitter info exists
92 const auto* fitterInfo = hitPoint->getFitterInfo();
93 if (not fitterInfo) continue;
94
95 // check which algorithm found this hit
96 const RecoHitInformation* hitInfo = recoTrack->getRecoHitInformation(cdcHit);
97 int foundByTrackFinder = hitInfo ? hitInfo->getFoundByTrackFinder() : RecoHitInformation::c_undefinedTrackFinder;
98
99 // get weights
100 std::map<int, double> weights;
101 for (const auto& rep : recoTrack->getRepresentations()) {
102 const auto* kalmanFitterInfo = hitPoint->getKalmanFitterInfo(rep);
103 if (not kalmanFitterInfo) continue;
104 auto wts = kalmanFitterInfo->getWeights();
105 double wt = 0;
106 for (double w : wts) if (w > wt) wt = w; // take the largest one (there should be always two, but safer to do in this way)
107 weights[std::abs(rep->getPDG())] = wt;
108 }
109
110 // get needed vectors, save the hit and add relation to track
111 try {
112 const genfit::MeasuredStateOnPlane& mop = fitterInfo->getFittedState();
113 auto pocaMom = ROOT::Math::XYZVector(mop.getMom());
114 auto pocaOnTrack = ROOT::Math::XYZVector(mop.getPos());
115 auto pocaOnWire = ROOT::Math::XYZVector(mop.getPlane()->getO());
116
117 auto* hit = m_hits.appendNew(cdcRecoHit->getWireID(), cdcHit->getTDCCount(), cdcHit->getADCCount(),
118 pocaMom, pocaOnTrack, pocaOnWire, foundByTrackFinder,
119 weights[211], weights[321], weights[2212]);
120 track.addRelationTo(hit);
121 } catch (genfit::Exception&) {
122 B2WARNING("Track: " << track.getArrayIndex() << ": genfit::MeasuredStateOnPlane exception occurred");
123 continue;
124 }
125
126 }
127 }
128
129 }
130
132} // end Belle2 namespace
StoreArray< Track > m_tracks
required collection of tracks
StoreArray< RecoTrack > m_recoTracks
required collection of reco tracks
StoreArray< CDCDedxHit > m_hits
output collection of hits
This class is used to transfer CDC information to the track fit.
Definition: CDCRecoHit.h:32
const CDCHit * getCDCHit() const
get the pointer to the CDCHit object that was used to create this CDCRecoHit object.
Definition: CDCRecoHit.h:112
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
This class stores additional information to every CDC/SVD/PXD hit stored in a RecoTrack.
OriginTrackFinder getFoundByTrackFinder() const
Get which track finder has found the track.
This is the Reconstruction Event-Data Model Track.
Definition: RecoTrack.h:79
const std::vector< genfit::AbsTrackRep * > & getRepresentations() const
Return a list of track representations. You are not allowed to modify or delete them!
Definition: RecoTrack.h:638
bool hasTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Check, if there is a fit status for the given representation or for the cardinal one.
Definition: RecoTrack.cc:543
RecoHitInformation * getRecoHitInformation(HitType *hit) const
Return the reco hit information for a generic hit from the storeArray.
Definition: RecoTrack.h:312
const genfit::FitStatus * getTrackFitStatus(const genfit::AbsTrackRep *representation=nullptr) const
Return the track fit status for the given representation or for the cardinal one. You are not allowed...
Definition: RecoTrack.h:621
const std::vector< genfit::TrackPoint * > & getHitPointsWithMeasurement() const
Return a list of measurements and track points, which can be used e.g. to extrapolate....
Definition: RecoTrack.h:708
CDCDedxHitSaverModule()
Default constructor.
virtual void initialize() override
Initialize the module.
virtual void event() override
This method is called for each event.
virtual ~CDCDedxHitSaverModule()
Destructor.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.