9 #include "cdc/modules/cdcCalibrationCollector/CDCCalibrationCollector.h"
10 #include <cdc/translators/RealisticTDCCountTranslator.h>
11 #include <framework/datastore/RelationArray.h>
13 #include <tracking/trackFindingCDC/eventdata/hits/CDCWireHit.h>
14 #include <tracking/trackFindingCDC/topology/CDCWireTopology.h>
16 #include <genfit/TrackPoint.h>
17 #include <genfit/KalmanFitterInfo.h>
18 #include <genfit/MeasurementOnPlane.h>
19 #include <genfit/MeasuredStateOnPlane.h>
21 #include <Math/ProbFuncMathCore.h>
23 #include <cdc/dataobjects/WireID.h>
24 #include <cdc/geometry/CDCGeometryPar.h>
32 using namespace TrackFindingCDC;
40 setDescription(
"Collector module for cdc calibration");
41 setPropertyFlags(c_ParallelProcessingCertified);
42 addParam(
"recoTracksColName", m_recoTrackArrayName,
"Name of collection hold genfit::Track", std::string(
""));
43 addParam(
"bField", m_bField,
"If true -> #Params ==5 else #params ==4 for calculate P-Val",
false);
44 addParam(
"calExpectedDriftTime", m_calExpectedDriftTime,
"if true module will calculate expected drift time, it take a time",
46 addParam(
"storeTrackParams", m_storeTrackParams,
"Store Track Parameter or not, it will be multicount for each hit",
false);
47 addParam(
"eventT0Extraction", m_eventT0Extraction,
"use event t0 extract t0 or not",
true);
48 addParam(
"minimumPt", m_minimumPt,
"Tracks with tranverse momentum smaller than this value will not used", 0.15);
49 addParam(
"minimumNDF", m_minimumNDF,
"Discard tracks whose degree-of-freedom below this value", 5.);
50 addParam(
"isCosmic", m_isCosmic,
"True when we process cosmic events, else False (collision)", m_isCosmic);
51 addParam(
"effStudy", m_effStudy,
"When true module collects info only necessary for wire eff study",
false);
60 m_Tracks.isRequired(m_trackArrayName);
61 m_RecoTracks.isRequired(m_recoTrackArrayName);
62 m_TrackFitResults.isRequired(m_trackFitResultArrayName);
63 m_CDCHits.isRequired(m_cdcHitArrayName);
64 m_CDCTracks.isRequired(m_cdcTrackVectorName);
65 RelationArray relRecoTrackTrack(m_RecoTracks, m_Tracks, m_relRecoTrackTrackName);
67 m_relRecoTrackTrackName = relRecoTrackTrack.
getName();
70 auto m_tree =
new TTree(m_treeName.c_str(),
"tree for cdc calibration");
71 m_tree->Branch<Float_t>(
"x_mea", &x_mea);
72 m_tree->Branch<Float_t>(
"x_u", &x_u);
73 m_tree->Branch<Float_t>(
"x_b", &x_b);
74 m_tree->Branch<Float_t>(
"alpha", &alpha);
75 m_tree->Branch<Float_t>(
"theta", &theta);
76 m_tree->Branch<Float_t>(
"t", &t);
77 m_tree->Branch<UShort_t>(
"adc", &adc);
79 m_tree->Branch<UChar_t>(
"lay", &lay);
80 m_tree->Branch<Float_t>(
"weight", &weight);
81 m_tree->Branch<UShort_t>(
"IWire", &IWire);
82 m_tree->Branch<Float_t>(
"Pval", &Pval);
83 m_tree->Branch<Float_t>(
"ndf", &ndf);
84 if (m_storeTrackParams) {
85 m_tree->Branch<Float_t>(
"d0", &d0);
86 m_tree->Branch<Float_t>(
"z0", &z0);
87 m_tree->Branch<Float_t>(
"phi0", &phi0);
88 m_tree->Branch<Float_t>(
"tanL", &tanL);
89 m_tree->Branch<Float_t>(
"omega", &omega);
92 if (m_calExpectedDriftTime) {
93 m_tree->Branch<Float_t>(
"t_fit", &t_fit);
96 registerObject<TTree>(
"tree", m_tree);
99 auto m_efftree =
new TTree(m_effTreeName.c_str(),
"tree for wire efficiency");
100 m_efftree->Branch<
unsigned short>(
"layerID", &layerID);
101 m_efftree->Branch<
unsigned short>(
"wireID", &wireID);
102 m_efftree->Branch<
float>(
"z", &z);
103 m_efftree->Branch<
bool>(
"isFound", &isFound);
105 registerObject<TTree>(
"efftree", m_efftree);
108 auto m_hNDF =
new TH1F(
"hNDF",
"NDF of fitted track;NDF;Tracks", 71, -1, 70);
109 auto m_hPval =
new TH1F(
"hPval",
"p-values of tracks;pVal;Tracks", 1000, 0, 1);
110 auto m_hEventT0 =
new TH1F(
"hEventT0",
"Event T0", 1000, -100, 100);
111 auto m_hNTracks =
new TH1F(
"hNTracks",
"Number of tracks", 50, 0, 10);
112 auto m_hOccupancy =
new TH1F(
"hOccupancy",
"occupancy", 100, 0, 1.0);
114 registerObject<TH1F>(
"hNDF", m_hNDF);
115 registerObject<TH1F>(
"hPval", m_hPval);
116 registerObject<TH1F>(
"hEventT0", m_hEventT0);
117 registerObject<TH1F>(
"hNTracks", m_hNTracks);
118 registerObject<TH1F>(
"hOccupancy", m_hOccupancy);
123 const RelationArray relTrackTrack(m_RecoTracks, m_Tracks, m_relRecoTrackTrackName);
130 if (m_eventT0Extraction) {
132 if (m_eventTimeStoreObject.isValid() && m_eventTimeStoreObject->hasEventT0()) {
133 evtT0 = m_eventTimeStoreObject->getEventT0();
134 getObjectPtr<TH1F>(
"hEventT0")->Fill(evtT0);
141 std::vector<unsigned short> wiresInCDCTrack;
143 for (
CDCTrack& cdcTrack : *m_CDCTracks) {
145 unsigned short eWireID = cdcHit.getWire().getEWire();
146 wiresInCDCTrack.push_back(eWireID);
151 const int nTr = m_Tracks.getEntries();
154 for (
int i = 0; i < nTr; ++i) {
157 if (!fitresult)
continue;
160 if (fabs(charge) > 0) {
168 getObjectPtr<TH1F>(
"hNTracks")->Fill(nCTracks);
171 const int nHits = m_CDCHits.getEntries();
172 const int nWires = 14336;
173 float oc =
static_cast<float>(nHits) /
static_cast<float>(nWires);
174 getObjectPtr<TH1F>(
"hOccupancy")->Fill(oc);
176 for (
int i = 0; i < nTr; ++i) {
180 B2WARNING(
"No track fit result found.");
186 B2WARNING(
"Can not access RecoTrack of this Belle2::Track");
196 getObjectPtr<TH1F>(
"hPval")->Fill(Pval);
197 getObjectPtr<TH1F>(
"hNDF")->Fill(ndf);
198 B2DEBUG(99,
"ndf = " << ndf);
199 B2DEBUG(99,
"Pval = " << Pval);
201 if (ndf < m_minimumNDF)
continue;
203 Pval = std::max(0., ROOT::Math::chisquared_cdf_c(Chi2, ndf));
206 d0 = fitresult->
getD0();
207 z0 = fitresult->
getZ0();
210 phi0 = fitresult->
getPhi0() * 180 / M_PI;
214 if (m_isCosmic ==
true && phi0 > 0.0)
continue;
222 B2ERROR(
"Exception when harvest information from recotrack: " << e.what());
227 if (fitresult->
getD0() > 2 || fitresult->
getZ0() > 5)
continue;
229 buildEfficiencies(wiresInCDCTrack, helixFit);
241 B2DEBUG(99,
"start collect hit");
246 const genfit::TrackPoint* tp = track->getCreatedTrackPoint(track->getRecoHitInformation(hit));
248 lay = hit->getICLayer();
249 IWire = hit->getIWire();
250 adc = hit->getADCCount();
251 unsigned short tdc = hit->getTDCCount();
252 WireID wireid(lay, IWire);
254 if (!kfi) {B2DEBUG(199,
"No Fitter Info: Layer " << hit->getICLayer());
continue;}
255 for (
unsigned int iMeas = 0; iMeas < kfi->getNumMeasurements(); ++iMeas) {
259 const TVector3 pocaOnWire = mop.getPlane()->getO();
260 const TVector3 pocaOnTrack = mop.getPlane()->getU();
261 const TVector3 pocaMom = mop.getMom();
262 alpha = cdcgeo.
getAlpha(pocaOnWire, pocaMom) ;
264 x_mea = kfi->getMeasurementOnPlane(iMeas)->getState()(0);
274 if (fabs(alpha) > M_PI / 2) {
278 x_mea = copysign(x_mea, x_b);
283 B2DEBUG(99,
"x_unbiased " << x_u <<
" |left_right " << lr);
284 if (m_calExpectedDriftTime) { t_fit = cdcgeo.
getDriftTime(abs(x_u), lay, lr, alpha , theta);}
288 t = tdcTrans->
getDriftTime(tdc, wireid, mop.getTime(), pocaOnWire.Z(), adc);
289 getObjectPtr<TTree>(
"tree")->Fill();
297 const Helix& helixFit)
const
303 const CDCWire& oneWire = layer.getWire(1);
305 double arcLength = helixFit.getArcLength2DAtCylindricalR(newR);
306 TVector3 xyzOnWire = helixFit.getPositionAtArcLength2D(arcLength);
310 const CDCWire& wire = layer.getClosestWire(crosspoint);
319 const double radiusofLayer = wireLayer.getRefCylindricalR();
321 const double arcLength = helixFit.getArcLength2DAtCylindricalR(radiusofLayer);
322 const TVector3 xyz = helixFit.getPositionAtArcLength2D(arcLength);
323 if (!xyz.x())
continue;
324 const CDCWire& wireIntersected = getIntersectingWire(xyz, wireLayer, helixFit);
325 unsigned short crossedWire = wireIntersected.
getEWire();
326 unsigned short crossedCWire = wireIntersected.
getNeighborCW()->getEWire();
327 unsigned short crossedCCWire = wireIntersected.
getNeighborCCW()->getEWire();
329 if (find(wireHits.begin(), wireHits.end(), crossedWire) != wireHits.end()
330 || find(wireHits.begin(), wireHits.end(), crossedCWire) != wireHits.end()
331 || find(wireHits.begin(), wireHits.end(), crossedCCWire) != wireHits.end())
336 wireID = wireIntersected.
getIWire();
339 getObjectPtr<TTree>(
"efftree")->Fill();
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
Collect hit information for cdc calibration with CAF.
void harvest(Belle2::RecoTrack *track)
collect hit information of fitted track.
const TrackFindingCDC::CDCWire & getIntersectingWire(const TVector3 &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 collect() override
Event action, collect information for calibration.
virtual ~CDCCalibrationCollectorModule()
Destructor.
void buildEfficiencies(std::vector< unsigned short > wireHits, const Helix helixFit)
fills efficiency objects
void prepare() override
Initializes the Module.
void finish() override
Termination action.
The Class for CDC Geometry Parameters.
double getAlpha(const TVector3 &posOnWire, const TVector3 &momentum) const
Returns track incident angle in rphi plane (alpha in rad.).
double getOutgoingAlpha(const double alpha) const
Converts incoming- to outgoing-alpha.
unsigned short getOutgoingLR(const unsigned short lr, const double alpha) const
Converts incoming-lr to outgoing-lr.
double getOutgoingTheta(const double alpha, const double theta) const
Converts incoming- to outgoing-theta.
double getTheta(const TVector3 &momentum) const
Returns track incident angle (theta in rad.).
double getDriftTime(double dist, unsigned short layer, unsigned short lr, double alpha, double theta) const
Return the drift time to the sense wire.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
Translator mirroring the realistic Digitization.
double getDriftTime(unsigned short tdcCount, const WireID &wireID, double timeOfFlightEstimator, double z, unsigned short adcCount) override
Get Drift time.
Calibration collector module base class.
static const ChargedStable muon
muon particle
This is the Reconstruction Event-Data Model Track.
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...
Low-level class to create/modify relations between StoreArrays.
TO * getRelatedTo(const std::string &name="", const std::string &namedRelation="") const
Get the object to which this object has a relation.
const std::string & getName() const
Return name under which the object is saved in the DataStore.
Class representing a three dimensional reconstructed hit.
Class representing a sequence of three dimensional reconstructed hits.
Class representating a sense wire layer in the central drift chamber.
Class representating 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.
Class representing a sense wire in the central drift chamber.
Vector2D getWirePos2DAtZ(const double z) const
Gives the xy projected position of the wire at the given z coordinate.
MayBePtr< const CDCWire > getNeighborCCW() const
Gives the closest neighbor in the counterclockwise direction - always exists.
IWire getIWire() const
Getter for the wire id within its layer.
unsigned short getEWire() const
Getter for the encoded wire number.
ILayer getICLayer() const
Getter for the continious layer id ranging from 0 - 55.
MayBePtr< const CDCWire > getNeighborCW() const
Gives the closest neighbor in the clockwise direction - always exists.
double norm() const
Calculates the length of the vector.
Values of the result of a track fit with a given particle hypothesis.
Helix getHelix() const
Conversion to framework Helix (without covariance).
short getChargeSign() const
Return track charge (1 or -1).
double getOmega() const
Getter for omega.
double getD0() const
Getter for d0.
double getTransverseMomentum() const
Getter for the absolute value of the transverse momentum at the perigee.
double getTanLambda() const
Getter for tanLambda.
double getZ0() const
Getter for z0.
double getPhi0() const
Getter for phi0.
Class that bundles various TrackFitResults.
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
Class to identify a wire inside the CDC.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Class where important numbers and properties of a fit can be stored.
double getChi2() const
Get chi^2 of the fit.
double getNdf() const
Get the degrees of freedom of the fit.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
const MeasuredStateOnPlane & getFittedState(bool biased=true) const override
Get unbiased or biased (default) smoothed state.
std::vector< double > getWeights() const
Get weights of measurements.
#StateOnPlane with additional covariance matrix.
Object containing AbsMeasurement and AbsFitterInfo objects.
KalmanFitterInfo * getKalmanFitterInfo(const AbsTrackRep *rep=nullptr) const
Helper to avoid casting.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
HepGeom::Vector3D< double > Vector3D
3D Vector
Abstract base class for different kinds of events.
Defines for I/O streams used for error and debug printing.