Belle II Software release-09-00-00
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
17using namespace std;
18
19namespace Belle2 {
25 //-----------------------------------------------------------------
27 //-----------------------------------------------------------------
28
29 REG_MODULE(CDCDedxHitSaver);
30
31 //-----------------------------------------------------------------
32 // Implementation
33 //-----------------------------------------------------------------
34
36
37 {
38 // set module description
39 setDescription("Module that stores CDC hit information from recoTracks, which is needed for dedx.");
41 }
42
44 {
45 }
46
48 {
49 m_tracks.isRequired();
51 m_hits.registerInDataStore();
52 m_tracks.registerRelationTo(m_hits);
53
54 if (not genfit::MaterialEffects::getInstance()->isInitialized()) {
55 B2FATAL("Need to have SetupGenfitExtrapolationModule in path before this one.");
56 }
57
58 }
59
61 {
62 // clear output collection
63 m_hits.clear();
64
65 // loop over tracks and save CDC hits stored in recoTracks
66 for (const auto& track : m_tracks) {
67 const RecoTrack* recoTrack = track.getRelatedTo<RecoTrack>();
68 if (not recoTrack) {
69 B2WARNING("No related recoTrack for this track");
70 continue;
71 }
72 if (recoTrack->getTrackFitStatus()->isTrackPruned()) {
73 B2ERROR("GFTrack is pruned, please run CDCDedxHitSaver only on unpruned tracks! Skipping this track.");
74 continue;
75 }
76
77 // loop over hits of this track
78 for (const auto& hitPoint : recoTrack->getHitPointsWithMeasurement()) {
79 // get CDCHit
80 const auto* rawMeasurement = hitPoint->getRawMeasurement(0);
81 if (not rawMeasurement) continue;
82 const auto* cdcRecoHit = dynamic_cast<const CDCRecoHit*>(rawMeasurement);
83 if (not cdcRecoHit) continue;
84 const auto* cdcHit = cdcRecoHit->getCDCHit();
85 if (not cdcHit) continue;
86
87 // make sure the fitter info exists
88 const auto* fitterInfo = hitPoint->getFitterInfo();
89 if (not fitterInfo) continue;
90
91 // check which algorithm found this hit
92 const RecoHitInformation* hitInfo = recoTrack->getRecoHitInformation(cdcHit);
93 int foundByTrackFinder = hitInfo ? hitInfo->getFoundByTrackFinder() : RecoHitInformation::c_undefinedTrackFinder;
94
95 // get weights
96 std::map<int, double> weights;
97 for (const auto& rep : recoTrack->getRepresentations()) {
98 const auto* kalmanFitterInfo = hitPoint->getKalmanFitterInfo(rep);
99 if (not kalmanFitterInfo) continue;
100 auto wts = kalmanFitterInfo->getWeights();
101 double wt = 0;
102 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)
103 weights[abs(rep->getPDG())] = wt;
104 }
105
106 // get needed vectors, save the hit and add relation to track
107 try {
108 const genfit::MeasuredStateOnPlane& mop = fitterInfo->getFittedState();
109 auto pocaMom = ROOT::Math::XYZVector(mop.getMom());
110 auto pocaOnTrack = ROOT::Math::XYZVector(mop.getPos());
111 auto pocaOnWire = ROOT::Math::XYZVector(mop.getPlane()->getO());
112
113 auto* hit = m_hits.appendNew(cdcRecoHit->getWireID(), cdcHit->getTDCCount(), cdcHit->getADCCount(),
114 pocaMom, pocaOnTrack, pocaOnWire, foundByTrackFinder,
115 weights[211], weights[321], weights[2212]);
116 track.addRelationTo(hit);
117 } catch (genfit::Exception&) {
118 B2WARNING("Track: " << track.getArrayIndex() << ": genfit::MeasuredStateOnPlane exception occured");
119 continue;
120 }
121
122 }
123 }
124
125 }
126
128} // 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
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
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
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:650
Abstract base class for different kinds of events.
STL namespace.