9 #include "cdc/modules/cdcCosmicAnalysis/CDCCosmicAnalysisModule.h"
10 #include <framework/geometry/BFieldManager.h>
11 #include <framework/gearbox/Const.h>
12 #include <framework/datastore/RelationArray.h>
14 #include <Math/ProbFuncMathCore.h>
34 setDescription(
"Module for harvesting parameters of the two half (up/down) of a cosmic track for performance study");
35 setPropertyFlags(c_ParallelProcessingCertified);
36 addParam(
"RecoTracksColName", m_recoTrackArrayName,
"Name of collectrion hold RecoTracks", std::string(
""));
37 addParam(
"Output", m_outputFileName,
"output file name",
string(
"twotracks.root"));
38 addParam(
"EventT0Extraction", m_eventT0Extraction,
"use event t0 extract t0 or not",
true);
39 addParam(
"treeName", m_treeName,
"Output tree name",
string(
"tree"));
40 addParam(
"phi0InRad", m_phi0InRad,
"Phi0 in unit of radian, true: rad, false: deg",
true);
41 addParam(
"StoreTrackParErrors", m_storeTrackParErrors,
42 "Store Track Parameter errors (true) or not (false)",
false);
45 CDCCosmicAnalysisModule::~CDCCosmicAnalysisModule()
48 void CDCCosmicAnalysisModule::initialize()
51 m_Tracks.isRequired(m_trackArrayName);
52 m_RecoTracks.isRequired(m_recoTrackArrayName);
53 m_TrackFitResults.isRequired(m_trackFitResultArrayName);
54 RelationArray relRecoTrackTrack(m_RecoTracks, m_Tracks, m_relRecoTrackTrackName);
56 m_relRecoTrackTrackName = relRecoTrackTrack.
getName();
58 tfile =
new TFile(m_outputFileName.c_str(),
"RECREATE");
60 tree =
new TTree(m_treeName.c_str(), m_treeName.c_str());
61 tree->Branch(
"run", &run,
"run/I");
62 tree->Branch(
"evtT0", &evtT0,
"evtT0/D");
63 tree->Branch(
"charge", &charge,
"charge/S");
65 tree->Branch(
"Pval1", &Pval1,
"Pval1/D");
66 tree->Branch(
"ndf1", &ndf1,
"ndf1/D");
67 tree->Branch(
"Pt1", &Pt1,
"Pt1/D");
68 tree->Branch(
"D01", &D01,
"D01/D");
69 tree->Branch(
"Phi01", &Phi01,
"Phi01/D");
71 tree->Branch(
"Z01", &Z01,
"Z01/D");
72 tree->Branch(
"tanLambda1", &tanLambda1,
"tanLambda1/D");
73 tree->Branch(
"posSeed1",
"TVector3", &posSeed1);
74 tree->Branch(
"Omega1", &Omega1,
"Omega1/D");
75 tree->Branch(
"Mom1",
"TVector3", &Mom1);
77 tree->Branch(
"Pval2", &Pval2,
"Pval2/D");
78 tree->Branch(
"ndf2", &ndf2,
"ndf2/D");
79 tree->Branch(
"Pt2", &Pt2,
"Pt2/D");
80 tree->Branch(
"D02", &D02,
"D02/D");
81 tree->Branch(
"Phi02", &Phi02,
"Phi02/D");
83 tree->Branch(
"Z02", &Z02,
"Z02/D");
84 tree->Branch(
"tanLambda2", &tanLambda2,
"tanLambda2/D");
85 tree->Branch(
"posSeed2",
"TVector3", &posSeed2);
86 tree->Branch(
"Omega2", &Omega2,
"Omega2/D");
87 tree->Branch(
"Mom2",
"TVector3", &Mom2);
89 if (m_storeTrackParErrors) {
90 tree->Branch(
"eD01", &eD01,
"eD01/D");
91 tree->Branch(
"ePhi01", &ePhi01,
"ePhi01/D");
92 tree->Branch(
"eOm1", &eOm1,
"eOm1/D");
93 tree->Branch(
"eZ01", &eZ01,
"eZ01/D");
94 tree->Branch(
"etanL1", &etanL1,
"etanL1/D");
96 tree->Branch(
"eD02", &eD02,
"eD02/D");
97 tree->Branch(
"ePhi02", &ePhi02,
"ePhi02/D");
98 tree->Branch(
"eOm2", &eOm2,
"eOm2/D");
99 tree->Branch(
"eZ02", &eZ02,
"eZ02/D");
100 tree->Branch(
"etanL2", &etanL2,
"etanL2/D");
105 void CDCCosmicAnalysisModule::beginRun()
108 B2Vector3D bfield = BFieldManager::getFieldInTesla(pos);
109 if (bfield.
Z() > 0.5) {
111 B2INFO(
"CDCCosmicAnalysis: Magnetic field is ON");
114 B2INFO(
"CDCCosmicAnalysis: Magnetic field is OFF");
116 B2INFO(
"CDCCosmicAnalysis: BField at (0,0,0) = " << bfield.
Mag());
119 void CDCCosmicAnalysisModule::event()
121 if (m_EventMetaData.isValid())
122 run = m_EventMetaData->getRun();
125 if (m_eventT0Extraction) {
127 if (m_eventTimeStoreObject.isValid() && m_eventTimeStoreObject->hasEventT0()) {
128 evtT0 = m_eventTimeStoreObject->getEventT0();
135 int nTr = m_Tracks.getEntries();
139 bool up(
false), down(
false);
140 for (
int i = 0; i < nTr; ++i) {
145 B2WARNING(
"There is no track fit result for muon hypothesis; try with the closest mass hypothesis...");
148 B2WARNING(
"There is also no track fit reslt for the other mass hypothesis");
154 B2WARNING(
"Can not access RecoTrack of this Belle2::Track");
161 double ndf = fs->
getNdf();
166 double TrPval = std::max(0., ROOT::Math::chisquared_cdf_c(Chi2, ndf));
167 double Phi0 = fitresult->
getPhi0();
168 if (m_phi0InRad ==
false) {
173 if ((posSeed.Y() > 0 && !up) ||
174 (up && posSeed.Y()*posSeed1.Y() > 0 && ndf > ndf1)) {
177 D01 = fitresult->
getD0();
181 if (m_phi0InRad ==
false) {
182 ePhi01 *= 180 / M_PI;
188 Z01 = fitresult->
getZ0();
198 if ((posSeed.Y() < 0 && !down) ||
199 (down && posSeed.Y()*posSeed2.Y() > 0 && ndf > ndf2)) {
202 D02 = fitresult->
getD0();
206 if (m_phi0InRad ==
false) {
207 ePhi02 *= 180 / M_PI;
212 Z02 = fitresult->
getZ0();
222 if (m_bField && charge1 * charge2 == 0)
return;
223 if (charge1 * charge2 >= 0 && up && down) {
230 void CDCCosmicAnalysisModule::endRun()
234 void CDCCosmicAnalysisModule::terminate()
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Analysis module for CDC CR data.
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...
TVector3 getPositionSeed() const
Return the position seed stored in the reco track. ATTENTION: This is not the fitted position.
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.
Values of the result of a track fit with a given particle hypothesis.
TMatrixDSym getCovariance5() const
Getter for covariance matrix of perigee parameters in matrix form.
short getChargeSign() const
Return track charge (1 or -1).
double getOmega() const
Getter for omega.
TVector3 getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
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 * getTrackFitResult(const Const::ChargedStable &chargedStable) const
Access to TrackFitResults.
const TrackFitResult * getTrackFitResultWithClosestMass(const Const::ChargedStable &requestedType) const
Return the track fit for a fit hypothesis with the closest mass.
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.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.