Belle II Software development
CDCBadWireCollector.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#include <cdc/modules/cdcCalibrationCollector/CDCBadWireCollector.h>
9#include <cdc/translators/RealisticTDCCountTranslator.h>
10#include <framework/datastore/RelationArray.h>
11#include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
12#include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
13#include <cdc/dataobjects/WireID.h>
14#include <TH1F.h>
15
16//using namespace std;
17using namespace Belle2;
18using namespace CDC;
19using namespace TrackFindingCDC;
20
21
22REG_MODULE(CDCBadWireCollector);
23
24
26{
27 setDescription("Collector module for cdc calibration");
28 setPropertyFlags(c_ParallelProcessingCertified); // specify this flag if you need parallel processing
29 addParam("minimumPt", m_minimumPt, "Tracks with tranverse momentum smaller than this value will not used", 1.0);
30 addParam("minimumNDF", m_minimumNDF, "Discard tracks whose degree-of-freedom below this value", 5.);
31}
32
36
38{
39 m_Tracks.isRequired(m_trackArrayName);
41 m_CDCHits.isRequired(m_cdcHitArrayName);
43
44 auto m_efftree = new TTree(m_effTreeName.c_str(), "tree for wire efficiency");
45 m_efftree->Branch<unsigned short>("layerID", &layerID);
46 m_efftree->Branch<unsigned short>("wireID", &wireID);
47 m_efftree->Branch<float>("z", &z);
48 m_efftree->Branch<bool>("isFound", &isFound);
49 registerObject<TTree>("efftree", m_efftree);
50
51 auto m_hNDF = new TH1F("hNDF", "NDF of fitted track;NDF;Tracks", 71, -1, 70);
52 auto m_hPval = new TH1F("hPval", "p-values of tracks;pVal;Tracks", 1000, 0, 1);
53
54 registerObject<TH1F>("hNDF", m_hNDF);
55 registerObject<TH1F>("hPval", m_hPval);
56}
57
59{
60 // Collects the WireID and Layer of every hit in this event
61 // Used in wire efficiency building
62 std::vector<unsigned short> wiresInCDCTrack;
63
64 for (CDCTrack& cdcTrack : *m_CDCTracks) {
65 for (CDCRecoHit3D& cdcHit : cdcTrack) {
66 unsigned short eWireID = cdcHit.getWire().getEWire();
67 wiresInCDCTrack.push_back(eWireID);
68 }
69 }
70 // WireID collection finished
71 const int nTr = m_Tracks.getEntries();
72 for (int i = 0; i < nTr; ++i) {
73 const Belle2::Track* b2track = m_Tracks[i];
75 if (!fitresult) {
76 B2WARNING("No track fit result found.");
77 continue;
78 }
79
80 double ndf = fitresult->getNDF();
81 double pval = fitresult->getPValue();
82 double pt = fitresult->getTransverseMomentum();
83 double d0 = fitresult->getD0();
84 double z0 = fitresult->getZ0();
85 getObjectPtr<TH1F>("hPval")->Fill(pval);
86 getObjectPtr<TH1F>("hNDF")->Fill(ndf);
87
88 // Cut on NDF, Pt
89 if (ndf < m_minimumNDF) continue;
90 if (pt < m_minimumPt) continue;
91
92 // Request tracks coming from IP
93 if (d0 > 2 || z0 > 5) continue;
94
95 const Helix helixFit = fitresult->getHelix();
96 buildEfficiencies(wiresInCDCTrack, helixFit);
97 }
98}
99
102 const Helix& helixFit) const
103{
104 Vector3D crosspoint;
105 if (layer.isAxial())
106 crosspoint = Vector3D(xyz);
107 else {
108 const CDCWire& oneWire = layer.getWire(1);
109 double newR = oneWire.getWirePos2DAtZ(xyz.Z()).norm();
110 double arcLength = helixFit.getArcLength2DAtCylindricalR(newR);
111 B2Vector3D xyzOnWire = B2Vector3D(helixFit.getPositionAtArcLength2D(arcLength));
112 crosspoint = Vector3D(xyzOnWire);
113 }
114 const CDCWire& wire = layer.getClosestWire(crosspoint);
115 return wire;
116}
117
118void CDCBadWireCollectorModule::buildEfficiencies(std::vector<unsigned short> wireHits, const Helix helixFit)
119{
121 for (const CDCWireLayer& wireLayer : wireTopology.getWireLayers()) {
122 const double radiusofLayer = wireLayer.getRefCylindricalR();
123 //simple extrapolation of fit
124 const double arcLength = helixFit.getArcLength2DAtCylindricalR(radiusofLayer);
125 const B2Vector3D xyz = B2Vector3D(helixFit.getPositionAtArcLength2D(arcLength));
126 if (!xyz.X()) continue;
127 const CDCWire& wireIntersected = getIntersectingWire(xyz, wireLayer, helixFit);
128 unsigned short crossedWire = wireIntersected.getEWire();
129 unsigned short crossedCWire = wireIntersected.getNeighborCW()->getEWire();
130 unsigned short crossedCCWire = wireIntersected.getNeighborCCW()->getEWire();
131
132 if (find(wireHits.begin(), wireHits.end(), crossedWire) != wireHits.end()
133 || find(wireHits.begin(), wireHits.end(), crossedCWire) != wireHits.end()
134 || find(wireHits.begin(), wireHits.end(), crossedCCWire) != wireHits.end())
135 isFound = true;
136 else
137 isFound = false;
138
139 wireID = wireIntersected.getIWire();
140 layerID = wireIntersected.getICLayer();
141 z = xyz.Z();
142 getObjectPtr<TTree>("efftree")->Fill();
143 }
144}
145
146
147
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition B2Vector3.h:435
DataType X() const
access variable X (= .at(0) without boundary check)
Definition B2Vector3.h:431
double m_minimumNDF
minimum NDF required for track
std::string m_effTreeName
Name of efficiency tree for the output file.
std::string m_cdcTrackVectorName
Belle2::CDCTrack vectorpointer name.
TrackFindingCDC::StoreWrappedObjPtr< std::vector< TrackFindingCDC::CDCTrack > > m_CDCTracks
CDC tracks.
StoreArray< TrackFitResult > m_TrackFitResults
Track fit results.
std::string m_cdcHitArrayName
Belle2::CDCHit StoreArray name.
unsigned short wireID
wireID for hit-level wire monitoring
void collect() override
Event action, collect information for calibration.
const TrackFindingCDC::CDCWire & getIntersectingWire(const B2Vector3D &xyz, const TrackFindingCDC::CDCWireLayer &layer, const Helix &helixFit) const
extrapolates the helix fit to a given layer and finds the wire which it would be hitting
void buildEfficiencies(std::vector< unsigned short > wireHits, const Helix helixFit)
Build efficiency.
std::string m_trackArrayName
Belle2::Track StoreArray name.
void prepare() override
Initializes the Module.
void finish() override
Termination action.
std::string m_trackFitResultArrayName
Belle2::TrackFitResult StoreArray name.
unsigned short layerID
layerID for hit-level wire monitoring
double m_minimumPt
minimum pt required for track
float z
z of hit fot hit-level wire monitoring
bool isFound
flag for a hit that has been found near a track as expected by extrapolation
StoreArray< CDCHit > m_CDCHits
CDC hits.
Helix parameter class.
Definition Helix.h:48
void registerObject(std::string name, T *obj)
Register object with a name, takes ownership, do not access the pointer beyond prepare()
CalibrationCollectorModule()
Constructor. Sets the default prefix for calibration dataobjects.
T * getObjectPtr(std::string name)
Calls the CalibObjManager to get the requested stored collector data.
static const ChargedStable muon
muon particle
Definition Const.h:660
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
Class representing a three dimensional reconstructed hit.
Class representing a sequence of three dimensional reconstructed hits.
Definition CDCTrack.h:41
Class representing a sense wire layer in the central drift chamber.
Class representing the sense wire arrangement in the whole of the central drift chamber.
const std::vector< Belle2::TrackFindingCDC::CDCWireLayer > & getWireLayers() const
Getter for the underlying storing layer vector.
static CDCWireTopology & getInstance()
Getter for the singleton instance of the wire topology.
Class representing a sense wire in the central drift chamber.
Definition CDCWire.h:58
Vector2D getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
Definition CDCWire.h:192
MayBePtr< const CDCWire > getNeighborCCW() const
Gives the closest neighbor in the counterclockwise direction - always exists.
Definition CDCWire.cc:159
IWire getIWire() const
Getter for the wire id within its layer.
Definition CDCWire.h:146
unsigned short getEWire() const
Getter for the encoded wire number.
Definition CDCWire.h:131
ILayer getICLayer() const
Getter for the continuous layer id ranging from 0 - 55.
Definition CDCWire.h:150
MayBePtr< const CDCWire > getNeighborCW() const
Gives the closest neighbor in the clockwise direction - always exists.
Definition CDCWire.cc:164
double norm() const
Calculates the length of the vector.
Definition Vector2D.h:175
Values of the result of a track fit with a given particle hypothesis.
Helix getHelix() const
Conversion to framework Helix (without covariance).
float getNDF() const
Getter for number of degrees of freedom of the track fit.
double getPValue() const
Getter for Chi2 Probability of the track fit.
double getD0() const
Getter for d0.
double getTransverseMomentum() const
Getter for the absolute value of the transverse momentum at the perigee.
double getZ0() const
Getter for z0.
Class that bundles various TrackFitResults.
Definition Track.h:25
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for the fit hypothesis with the closest mass.
Definition Track.cc:104
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition B2Vector3.h:516
HepGeom::Vector3D< double > Vector3D
3D Vector
Definition Cell.h:34
Abstract base class for different kinds of events.