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/trackingUtilities/eventdata/hits/CDCWireHit.h>
12#include <cdc/topology/CDCWireTopology.h>
13#include <cdc/dataobjects/WireID.h>
14
15#include <TH1F.h>
16
17//using namespace std;
18using namespace Belle2;
19using namespace CDC;
20using namespace TrackingUtilities;
21
22
23REG_MODULE(CDCBadWireCollector);
24
25
27{
28 setDescription("Collector module for cdc calibration");
29 setPropertyFlags(c_ParallelProcessingCertified); // specify this flag if you need parallel processing
30 addParam("minimumPt", m_minimumPt, "Tracks with tranverse momentum smaller than this value will not used", 1.0);
31 addParam("minimumNDF", m_minimumNDF, "Discard tracks whose degree-of-freedom below this value", 5.);
32}
33
37
39{
40 m_Tracks.isRequired(m_trackArrayName);
42 m_CDCHits.isRequired(m_cdcHitArrayName);
44
45 auto m_efftree = new TTree(m_effTreeName.c_str(), "tree for wire efficiency");
46 m_efftree->Branch<unsigned short>("layerID", &layerID);
47 m_efftree->Branch<unsigned short>("wireID", &wireID);
48 m_efftree->Branch<float>("z", &z);
49 m_efftree->Branch<bool>("isFound", &isFound);
50 registerObject<TTree>("efftree", m_efftree);
51
52 auto m_hNDF = new TH1F("hNDF", "NDF of fitted track;NDF;Tracks", 71, -1, 70);
53 auto m_hPval = new TH1F("hPval", "p-values of tracks;pVal;Tracks", 1000, 0, 1);
54
55 registerObject<TH1F>("hNDF", m_hNDF);
56 registerObject<TH1F>("hPval", m_hPval);
57}
58
60{
61 // Collects the WireID and Layer of every hit in this event
62 // Used in wire efficiency building
63 std::vector<unsigned short> wiresInCDCTrack;
64
65 for (CDCTrack& cdcTrack : *m_CDCTracks) {
66 for (CDCRecoHit3D& cdcHit : cdcTrack) {
67 unsigned short eWireID = cdcHit.getWire().getEWire();
68 wiresInCDCTrack.push_back(eWireID);
69 }
70 }
71 // WireID collection finished
72 const int nTr = m_Tracks.getEntries();
73 for (int i = 0; i < nTr; ++i) {
74 const Belle2::Track* b2track = m_Tracks[i];
76 if (!fitresult) {
77 B2WARNING("No track fit result found.");
78 continue;
79 }
80
81 double ndf = fitresult->getNDF();
82 double pval = fitresult->getPValue();
83 double pt = fitresult->getTransverseMomentum();
84 double d0 = fitresult->getD0();
85 double z0 = fitresult->getZ0();
86 getObjectPtr<TH1F>("hPval")->Fill(pval);
87 getObjectPtr<TH1F>("hNDF")->Fill(ndf);
88
89 // Cut on NDF, Pt
90 if (ndf < m_minimumNDF) continue;
91 if (pt < m_minimumPt) continue;
92
93 // Request tracks coming from IP
94 if (d0 > 2 || z0 > 5) continue;
95
96 const Helix helixFit = fitresult->getHelix();
97 buildEfficiencies(wiresInCDCTrack, helixFit);
98 }
99}
100
102const CDCWire& CDCBadWireCollectorModule::getIntersectingWire(const ROOT::Math::XYZVector& xyz, const CDCWireLayer& layer,
103 const Helix& helixFit) const
104{
105 ROOT::Math::XYZVector crosspoint;
106 if (layer.isAxial())
107 crosspoint = xyz;
108 else {
109 const CDCWire& oneWire = layer.getWire(1);
110 double newR = oneWire.getWirePos2DAtZ(xyz.Z()).R();
111 double arcLength = helixFit.getArcLength2DAtCylindricalR(newR);
112 crosspoint = helixFit.getPositionAtArcLength2D(arcLength);
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{
120 static const CDCWireTopology& wireTopology = CDCWireTopology::getInstance();
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 ROOT::Math::XYZVector xyz = 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
double m_minimumNDF
minimum NDF required for track
std::string m_effTreeName
Name of efficiency tree for the output file.
TrackingUtilities::StoreWrappedObjPtr< std::vector< TrackingUtilities::CDCTrack > > m_CDCTracks
CDC tracks.
std::string m_cdcTrackVectorName
Belle2::CDCTrack vectorpointer name.
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.
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
const CDCWire & getIntersectingWire(const ROOT::Math::XYZVector &xyz, const CDCWireLayer &layer, const Helix &helixFit) const
extrapolates the helix fit to a given layer and finds the wire which it would be hitting
bool isFound
flag for a hit that has been found near a track as expected by extrapolation
StoreArray< CDCHit > m_CDCHits
CDC hits.
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< 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:50
TrackingUtilities::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:138
ROOT::Math::XYVector getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
Definition CDCWire.h:184
unsigned short getEWire() const
Getter for the encoded wire number.
Definition CDCWire.h:123
ILayer getICLayer() const
Getter for the continuous layer id ranging from 0 - 55.
Definition CDCWire.h:142
TrackingUtilities::MayBePtr< const CDCWire > getNeighborCW() const
Gives the closest neighbor in the clockwise direction - always exists.
Definition CDCWire.cc:164
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
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
Class representing a three dimensional reconstructed hit.
Class representing a sequence of three dimensional reconstructed hits.
Definition CDCTrack.h:39
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
Abstract base class for different kinds of events.