11 #include "cdc/modules/cdcCosmicAnalysis/CDCCosmicAnalysisModule.h"
12 #include <framework/geometry/BFieldManager.h>
13 #include <framework/gearbox/Const.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/datastore/RelationArray.h>
17 #include <framework/dataobjects/EventMetaData.h>
19 #include <mdst/dataobjects/TrackFitResult.h>
20 #include <mdst/dataobjects/Track.h>
21 #include <tracking/dataobjects/RecoTrack.h>
23 #include <Math/ProbFuncMathCore.h>
43 setDescription(
"Module for harvesting parameters of the two half (up/down) of a cosmic track for performance study");
44 setPropertyFlags(c_ParallelProcessingCertified);
45 addParam(
"RecoTracksColName", m_recoTrackArrayName,
"Name of collectrion hold RecoTracks", std::string(
""));
46 addParam(
"Output", m_outputFileName,
"output file name",
string(
"twotracks.root"));
47 addParam(
"EventT0Extraction", m_eventT0Extraction,
"use event t0 extract t0 or not",
true);
48 addParam(
"treeName", m_treeName,
"Output tree name",
string(
"tree"));
49 addParam(
"phi0InRad", m_phi0InRad,
"Phi0 in unit of radian, true: rad, false: deg",
true);
50 addParam(
"StoreTrackParErrors", m_storeTrackParErrors,
51 "Store Track Parameter errors (true) or not (false)",
false);
54 CDCCosmicAnalysisModule::~CDCCosmicAnalysisModule()
57 void CDCCosmicAnalysisModule::initialize()
63 RelationArray relRecoTrackTrack(recoTracks, storeTrack, m_relRecoTrackTrackName);
65 m_recoTrackArrayName = recoTracks.getName();
66 m_trackFitResultArrayName = storeTrackFitResults.getName();
67 m_relRecoTrackTrackName = relRecoTrackTrack.
getName();
69 tfile =
new TFile(m_outputFileName.c_str(),
"RECREATE");
71 tree =
new TTree(m_treeName.c_str(), m_treeName.c_str());
72 tree->Branch(
"run", &run,
"run/I");
73 tree->Branch(
"evtT0", &evtT0,
"evtT0/D");
74 tree->Branch(
"charge", &charge,
"charge/S");
76 tree->Branch(
"Pval1", &Pval1,
"Pval1/D");
77 tree->Branch(
"ndf1", &ndf1,
"ndf1/D");
78 tree->Branch(
"Pt1", &Pt1,
"Pt1/D");
79 tree->Branch(
"D01", &D01,
"D01/D");
80 tree->Branch(
"Phi01", &Phi01,
"Phi01/D");
82 tree->Branch(
"Z01", &Z01,
"Z01/D");
83 tree->Branch(
"tanLambda1", &tanLambda1,
"tanLambda1/D");
84 tree->Branch(
"posSeed1",
"TVector3", &posSeed1);
85 tree->Branch(
"Omega1", &Omega1,
"Omega1/D");
86 tree->Branch(
"Mom1",
"TVector3", &Mom1);
88 tree->Branch(
"Pval2", &Pval2,
"Pval2/D");
89 tree->Branch(
"ndf2", &ndf2,
"ndf2/D");
90 tree->Branch(
"Pt2", &Pt2,
"Pt2/D");
91 tree->Branch(
"D02", &D02,
"D02/D");
92 tree->Branch(
"Phi02", &Phi02,
"Phi02/D");
94 tree->Branch(
"Z02", &Z02,
"Z02/D");
95 tree->Branch(
"tanLambda2", &tanLambda2,
"tanLambda2/D");
96 tree->Branch(
"posSeed2",
"TVector3", &posSeed2);
97 tree->Branch(
"Omega2", &Omega2,
"Omega2/D");
98 tree->Branch(
"Mom2",
"TVector3", &Mom2);
100 if (m_storeTrackParErrors) {
101 tree->Branch(
"eD01", &eD01,
"eD01/D");
102 tree->Branch(
"ePhi01", &ePhi01,
"ePhi01/D");
103 tree->Branch(
"eOm1", &eOm1,
"eOm1/D");
104 tree->Branch(
"eZ01", &eZ01,
"eZ01/D");
105 tree->Branch(
"etanL1", &etanL1,
"etanL1/D");
107 tree->Branch(
"eD02", &eD02,
"eD02/D");
108 tree->Branch(
"ePhi02", &ePhi02,
"ePhi02/D");
109 tree->Branch(
"eOm2", &eOm2,
"eOm2/D");
110 tree->Branch(
"eZ02", &eZ02,
"eZ02/D");
111 tree->Branch(
"etanL2", &etanL2,
"etanL2/D");
116 void CDCCosmicAnalysisModule::beginRun()
119 B2Vector3D bfield = BFieldManager::getFieldInTesla(pos);
120 if (bfield.
Z() > 0.5) {
122 B2INFO(
"CDCCosmicAnalysis: Magnetic field is ON");
125 B2INFO(
"CDCCosmicAnalysis: Magnetic field is OFF");
127 B2INFO(
"CDCCosmicAnalysis: BField at (0,0,0) = " << bfield.
Mag());
130 void CDCCosmicAnalysisModule::event()
135 const RelationArray relTrackTrack(recoTracks, storeTrack, m_relRecoTrackTrackName);
139 run = eventMetaData->getRun();
142 if (m_eventT0Extraction) {
144 if (m_eventTimeStoreObject.isValid() && m_eventTimeStoreObject->hasEventT0()) {
145 evtT0 = m_eventTimeStoreObject->getEventT0();
156 bool up(
false), down(
false);
157 for (
int i = 0; i < nTr; ++i) {
162 B2WARNING(
"There is no track fit result for muon hypothesis; try with the closest mass hypothesis...");
165 B2WARNING(
"There is also no track fit reslt for the other mass hypothesis");
171 B2WARNING(
"Can not access RecoTrack of this Belle2::Track");
178 double ndf = fs->
getNdf();
183 double TrPval = std::max(0., ROOT::Math::chisquared_cdf_c(Chi2, ndf));
184 double Phi0 = fitresult->
getPhi0();
185 if (m_phi0InRad ==
false) {
190 if ((posSeed.Y() > 0 && !up) ||
191 (up && posSeed.Y()*posSeed1.Y() > 0 && ndf > ndf1)) {
194 D01 = fitresult->
getD0();
198 if (m_phi0InRad ==
false) {
199 ePhi01 *= 180 / M_PI;
205 Z01 = fitresult->
getZ0();
215 if ((posSeed.Y() < 0 && !down) ||
216 (down && posSeed.Y()*posSeed2.Y() > 0 && ndf > ndf2)) {
219 D02 = fitresult->
getD0();
223 if (m_phi0InRad ==
false) {
224 ePhi02 *= 180 / M_PI;
229 Z02 = fitresult->
getZ0();
239 if (m_bField && charge1 * charge2 == 0)
return;
240 if (charge1 * charge2 >= 0 && up && down) {
247 void CDCCosmicAnalysisModule::endRun()
251 void CDCCosmicAnalysisModule::terminate()