10#include <klm/bklm/modules/bklmTracking/BKLMTrackingModule.h>
13#include <klm/bklm/geometry/GeometryPar.h>
14#include <klm/bklm/modules/bklmTracking/BKLMTrackFinder.h>
17#include <framework/dataobjects/EventMetaData.h>
18#include <framework/datastore/StoreObjPtr.h>
19#include <framework/logging/Logger.h>
20#include <framework/utilities/MathHelpers.h>
23using namespace Belle2::bklm;
38 for (
int i = 0; i < 8; ++i) {
46 setDescription(
"Perform standard-alone straight line tracking for BKLM");
49 "[degree], match BKLMTrack to RecoTrack; angle between them is required to be smaller than (default 10)",
double(10.0));
51 "[cm], During efficiency calculation, distance between track and 2dhit must be smaller than (default 10)",
double(10.0));
53 "[sigma], During efficiency calculation, uncertainty of 2dhit must be smaller than (default 5); ",
double(5));
55 ", During track finding, a good track after initial seed hits must be larger than is (default 2); ",
unsigned(2));
57 ", During track finding, a good track after initial seed hits must be smaller than is (default 60); ",
unsigned(60));
59 "[bool], do the BKLMTrack fitting in global system (multi-sectors track) or local system (sector by sector) (default is false, local sys.)",
61 addParam(
"StudyEffiMode",
m_studyEffi,
"[bool], run in efficiency study mode (default is false)",
false);
62 addParam(
"outputName",
m_outPath,
"[string], output file name containing efficiencies plots ", std::string(
"bklmEffi.root"));
81 B2INFO(
"BKLMTrackingModule:: this module is running in efficiency study mode!");
85 std::string labelFB[2] = {
"BB",
"BF"};
91 m_totalYX =
new TH2F(
"totalYX",
" denominator Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
92 m_passYX =
new TH2F(
"passYX",
" numerator Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
93 m_totalYZ =
new TH2F(
"totalYZ",
" denominator Y vs. Z", gNbin, gmin, gmax, gNbin, gmin, gmax);
94 m_passYZ =
new TH2F(
"passYZ",
" numerator Y vs. Z", gNbin, gmin, gmax, gNbin, gmin, gmax);
95 m_effiYX =
new TH2F(
"effiYX",
" effi. Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
96 m_effiYZ =
new TH2F(
"effiYZ",
" effi. Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
97 m_effiYX->GetXaxis()->SetTitle(
"x (cm)");
98 m_effiYX->GetYaxis()->SetTitle(
"y (cm)");
99 m_effiYZ->GetXaxis()->SetTitle(
"z (cm)");
100 m_effiYZ->GetYaxis()->SetTitle(
"y (cm)");
101 for (
int iF = 0; iF < 2; iF++) {
102 for (
int iS = 0; iS < 8; iS++) {
103 hname.Form(
"effi_%s%i", labelFB[iF].c_str(), iS);
104 m_effiVsLayer[iF][iS] =
new TEfficiency(hname, hname, Nbin, 0, 16);
105 hname.Form(
"total_%s%i", labelFB[iF].c_str(), iS);
106 m_total[iF][iS] =
new TH1F(hname, hname, Nbin, 0, 16);
107 hname.Form(
"pass_%s%i", labelFB[iF].c_str(), iS);
108 m_pass[iF][iS] =
new TH1F(hname, hname, Nbin, 0, 16);
117 m_runNumber.push_back((
int)eventMetaData->getRun());
125 bool thereIsATrack =
false;
130 thereIsATrack =
true;
132 for (
int iSection = 0; iSection < 2; iSection++) {
133 for (
int iSector = 0; iSector < 8; iSector++) {
134 for (
int iLayer = 0; iLayer < 15; iLayer++) {
137 thereIsATrack =
true;
164 if (
hits2D.getEntries() < 1)
167 for (
int j = 0; j <
hits2D.getEntries(); j++) {
170 hits2D[j]->isOnStaTrack(
false);
174 for (
int hi = 0; hi <
hits2D.getEntries() - 1; ++hi) {
182 if (
hits2D[hi]->isOnStaTrack())
184 if (
hits2D[hi]->isOutOfTime())
186 for (
int hj = hi + 1; hj <
hits2D.getEntries(); ++hj) {
188 if (
hits2D[hj]->isOnStaTrack())
190 if (
hits2D[hj]->isOutOfTime())
195 std::abs(
hits2D[hi]->getLayer() -
hits2D[hj]->getLayer()) < 3)
198 std::list<KLMHit2d*> sectorHitList;
202 std::list<KLMHit2d*> seed;
203 seed.push_back(
hits2D[hi]);
204 seed.push_back(
hits2D[hj]);
206 for (
int ho = 0; ho <
hits2D.getEntries(); ++ho) {
209 if (ho == hi || ho == hj)
215 if (
hits2D[ho]->isOnStaTrack())
221 if (
hits2D[ho]->isOutOfTime())
223 sectorHitList.push_back(
hits2D[ho]);
232 std::list<KLMHit2d*> m_hits;
233 if (m_finder->
filter(seed, sectorHitList, m_hits)) {
245 hit2d->isOnStaTrack(
true);
259 closestTrack->
addBKLMHit(hit2d, sortingParameter, RecoHitInformation::OriginTrackFinder::c_LocalTrackFinder);
281 for (
long unsigned int i = 0; i <
m_runNumber.size(); i++) {
283 B2INFO(
"BKLMTrackingModule:: run " <<
m_runNumber.at(i) <<
" --> " << ratio * 100 <<
"% of events has 1+ BKLMTracks");
287 for (
int iF = 0; iF < 2; iF++) {
288 for (
int iS = 0; iS < 8; iS++) {
295 for (
int i = 0; i <
m_totalYX->GetNbinsX(); i++) {
296 for (
int j = 0; j <
m_totalYX->GetNbinsY(); j++) {
297 float num =
m_passYX->GetBinContent(i + 1, j + 1);
298 float denom =
m_totalYX->GetBinContent(i + 1, j + 1);
300 m_effiYX->SetBinContent(i + 1, j + 1, num / denom);
301 m_effiYX->SetBinError(i + 1, j + 1,
sqrt(num * (denom - num) / (denom * denom * denom)));
303 m_effiYX->SetBinContent(i + 1, j + 1, 0);
304 m_effiYX->SetBinError(i + 1, j + 1, 0);
307 num =
m_passYZ->GetBinContent(i + 1, j + 1);
308 denom =
m_totalYZ->GetBinContent(i + 1, j + 1);
310 m_effiYZ->SetBinContent(i + 1, j + 1, num / denom);
311 m_effiYZ->SetBinError(i + 1, j + 1,
sqrt(num * (denom - num) / (denom * denom * denom)));
313 m_effiYZ->SetBinContent(i + 1, j + 1, 0);
314 m_effiYZ->SetBinError(i + 1, j + 1, 0);
343 if (bklmHits.
size() < 1) {
344 B2INFO(
"BKLMTrackingModule::something is wrong! there is BKLMTrack but no bklmHits");
348 B2INFO(
"BKLMTrackingModule::there is no recoTrack");
351 double oldDistanceSq = INFINITY;
352 double oldAngle = INFINITY;
353 closestTrack =
nullptr;
357 TVector3 firstBKLMHitPosition(bklmHits[0]->
getPosition().X(),
376 genfit::MeasuredStateOnPlane state = track.getMeasuredStateOnPlaneFromLastHit();
378 state.getPosMomCov(pos, mom, cov);
379 if (mom.Y() * pos.Y() < 0) {
380 state = track.getMeasuredStateOnPlaneFromFirstHit();
382 const TVector3& distanceVec = firstBKLMHitPosition - pos;
383 state.extrapolateToPoint(firstBKLMHitPosition);
384 double newDistanceSq = distanceVec.Mag2();
385 double angle = bklmTrkVec.Angle(mom);
388 if (newDistanceSq < oldDistanceSq) {
389 oldDistanceSq = newDistanceSq;
390 closestTrack = &track;
400 }
catch (genfit::Exception& e) {
416 std::set<int> m_pointUsed;
420 B2DEBUG(10,
"BKLMTracking:generateEffi: " << iSection <<
" " << iSector <<
" " << iLayer);
430 for (
const KLMHit2d& hit2D : relatedHit2D) {
431 if (hit2D.getLayer() > iLayer + 1)
433 if (hit2D.getLayer() < iLayer + 1)
435 if (hit2D.getLayer() == iLayer + 1) {
436 B2DEBUG(10,
"generateEffi: Hit info. Secti/sector/Lay = " << hit2D.getSection()
437 <<
"/" << hit2D.getSector() - 1 <<
"/" << hit2D.getLayer() - 1);
438 B2DEBUG(11,
"generateEffi: Hit info. x/y/z = " << hit2D.getPositionX()
439 <<
"/" << hit2D.getPositionY() <<
"/" << hit2D.getPositionZ());
443 if (iLayer != 0 && cnt2 < 1)
445 if (iLayer != 14 && cnt1 < 1)
449 int minPhiStrip =
module->getPhiStripMin();
450 int maxPhiStrip =
module->getPhiStripMax();
451 int minZStrip =
module->getZStripMin();
452 int maxZStrip =
module->getZStripMax();
454 CLHEP::Hep3Vector local =
module->getLocalPosition(minPhiStrip, minZStrip);
455 CLHEP::Hep3Vector local2 =
module->getLocalPosition(maxPhiStrip, maxZStrip);
456 float minLocalY, maxLocalY;
457 float minLocalZ, maxLocalZ;
458 if (local[1] > local2[1]) {
459 maxLocalY = local[1];
460 minLocalY = local2[1];
462 maxLocalY = local2[1];
463 minLocalY = local[1];
465 if (local[2] > local2[2]) {
466 maxLocalZ = local[2];
467 minLocalZ = local2[2];
469 maxLocalZ = local2[2];
470 minLocalZ = local[2];
478 float reflocalX = fabs(
m_GeoPar->getActiveMiddleRadius(iSection, iSector + 1,
479 iLayer + 1) -
m_GeoPar->getActiveMiddleRadius(iSection, iSector + 1, 1));
483 float reflocalY = trkPar[0] + trkPar[1] * reflocalX;
484 float reflocalZ = trkPar[2] + trkPar[3] * reflocalX;
489 Hep3Vector reflocal(reflocalX, reflocalY, reflocalZ);
491 Hep3Vector global(0, 0, 0);
492 module = m_GeoPar->findModule(iSection, iSector + 1, iLayer + 1);
493 global =
module->localToGlobal(reflocal);
495 float localY =
module->globalToLocal(global)[1];
496 float localZ =
module->globalToLocal(global)[2];
498 B2DEBUG(10,
"BKLM:generateEffi: RefLocal " << reflocalX <<
" " << reflocalY <<
" " << reflocalZ);
499 B2DEBUG(10,
"BKLM:generateEffi: Global " << global[0] <<
" " << global[1] <<
" " << global[2]);
500 B2DEBUG(10,
"BKLM:generateEffi: Local " << 0 <<
" " << localY <<
" " << localZ);
505 if (localY > minLocalY && localY < maxLocalY && localZ > minLocalZ && localZ < maxLocalZ) {
507 bool m_iffound =
false;
508 m_total[iSection][iSector]->Fill(iLayer + 1);
512 for (
int he = 0; he <
hits2D.getEntries(); ++he) {
515 if (
hits2D[he]->isOutOfTime())
518 if (m_pointUsed.find(he) != m_pointUsed.end())
523 B2DEBUG(10,
"BKLM Dist = " << distance <<
", error = " << error);
526 B2DEBUG(10,
"BKLMTracking:generateEffi: Hit found!");;
529 m_pointUsed.insert(he);
533 m_pass[iSection][iSector]->Fill(iLayer + 1);
534 m_passYX->Fill(global[0], global[1]);
535 m_passYZ->Fill(global[2], global[1]);
540 m_effiVsLayer[iSection][iSector]->Fill(m_iffound, iLayer + 1);
579 double x, y, z, dy, dz;
584 TVectorD m_SectorPar = track->getLocalTrackParam();
596 y = m_SectorPar[ 0 ] + x * m_SectorPar[ 1 ];
597 z = m_SectorPar[ 2 ] + x * m_SectorPar[ 3 ];
602 double distance =
sqrt(dy * dy + dz * dz);
611 sigma = distance / error;
bool filter(const std::list< KLMHit2d * > &seed, std::list< KLMHit2d * > &hits, std::list< KLMHit2d * > &track)
find associated hits and do fit.
void registerFitter(BKLMTrackFitter *fitter)
Register a fitter if not constructed with one.
void setGlobalFit(bool localOrGlobal)
set the fitting mode, local system or global system
CLHEP::HepVector getTrackParamSector()
Get track parameters in the sector locan system, y = p0 + p1 * x, z = p2 + p3 *x, where the first lay...
float getChi2()
Chi square of the fit.
bool isGood()
Is fit good.
CLHEP::HepSymMatrix getTrackParamSectorErr()
Get invariance matrix of track parameters in the sector local system, where the first layer of the se...
int getNumHit()
number of the hits on this track
CLHEP::HepSymMatrix getTrackParamErr()
Get invariance matrix of track parameters in the global system.
CLHEP::HepVector getTrackParam()
Get track parameters in the global system. y = p0 + p1 * x; y = p2 + p3 * z, if in local sector fit m...
bool isValid()
Is fit valid.
Store one BKLM Track as a ROOT object.
void setIsValid(const bool valid)
set the fit valid status
void setTrackChi2(const float chi2)
Set the fitted chi2 of the track.
void setLocalTrackParam(const CLHEP::HepVector &trkPar)
Set track parameters in the sector local system, where the first layer of the sector is used as refer...
void setTrackParamErr(const CLHEP::HepSymMatrix &trkParErr)
Set invariance matrix of track parameters in the global system.
void setNumHitOnTrack(const int NumHit)
Set the number of 2d hits on the track.
TVectorD getTrackParam()
Get track parameters in the global system. y = p0 + p1 * x; z = p2 + p3 * x.
void setIsGood(const bool good)
set the fit good status
void setLocalTrackParamErr(const CLHEP::HepSymMatrix &trkParErr)
Set invariance matrix of track parameters in the sector local system, where the first layer of the se...
void setTrackParam(const CLHEP::HepVector &trkPar)
Set track parameters in the global system. y = p0 + p1 * x; z = p2 + p3 * x.
bool m_MatchToRecoTrack
whether match BKLMTrack to RecoTrack
~BKLMTrackingModule()
Destructor.
TEfficiency * m_effiVsLayer[2][8]
Efficiency of each layer.
std::vector< int > m_runNumber
run number
bool findClosestRecoTrack(BKLMTrack *bklmTrk, RecoTrack *&closestTrack)
find the closest RecoTrack, match BKLMTrack to RecoTrack, if the matched RecoTrack is found,...
TH2F * m_passYZ
passed event at global position Y vs Z
TH2F * m_effiYX
Efficiency at global position Y vs X.
bool m_studyEffi
option for efficiency study mode, in this mode, the layer under study should not be used in tracking
double m_maxSigma
maximum sigma for hit acceptance during efficiency calculation
double m_maxAngleRequired
angle required between RecoTrack and BKLMTrack, if openangle is larger than m_maxAngleRequired,...
double distanceToHit(BKLMTrack *track, KLMHit2d *hit, double &error, double &sigma)
calculate distance from track to hit
void initialize() override
Initialize at start of job.
unsigned int m_minHitList
minimum number of hits in sector for track finder to run (-2 from initial seed)
std::string m_outPath
output file name containing efficiencies plots
void event() override
Unpack one event and create digits.
void endRun() override
end run stuff
StoreArray< RecoTrack > recoTracks
RecoTrack StoreArray.
void runTracking(int mode, int section, int sector, int layer)
run the track finding and fitting
void terminate() override
Terminate at the end of job.
bklm::GeometryPar * m_GeoPar
bklm GeometryPar
TH1F * m_pass[2][8]
Numerator of each layer.
TH2F * m_totalYX
total event at global position Y vs X
StoreArray< RecoHitInformation > recoHitInformation
RecoHitInformation StoreArray.
int m_runTotalEventsWithTracks
total number of processed events in the run with at lease one BKLMTrack
void beginRun() override
begin run stuff
double m_maxDistance
maximum distance required between track and KLMHit2d to be accepted for efficiency calculation
StoreArray< KLMHit2d > hits2D
KLMHit2d StoreArray.
TFile * m_file
TFile that store efficiency plots.
std::vector< int > m_totalEvents
total number of processed events
bool isLayerUnderStudy(int section, int iSector, int iLayer, KLMHit2d *hit)
judge whether the current layer is understudy
TH1F * m_total[2][8]
Denominator of each layer.
StoreArray< BKLMTrack > m_storeTracks
BKLMTrack StoreArray.
bool m_globalFit
do the BKLMTrack fitting in global system (multi-sectors track) or local system (sector by sector)
unsigned int m_maxHitList
max number of hits in sector for track finder to run
std::vector< int > m_totalEventsWithTracks
total number of processed events with at least one BKLMTrack
TH2F * m_effiYZ
Efficiency at global position Y vs Z.
bool isSectorUnderStudy(int section, int iSector, KLMHit2d *hit)
judge whether the hits come from the sctor understudy
static bool sortByLayer(KLMHit2d *hit1, KLMHit2d *hit2)
my defined sort function using layer number
TH2F * m_totalYZ
total event at global position Y vs Z
bool sameSector(KLMHit2d *hit1, KLMHit2d *hit2)
Judge if two hits come from the same sector.
BKLMTrackingModule()
Constructor.
int m_runTotalEvents
total number of processed events in the run
TH2F * m_passYX
passed event at global position Y vs X
void generateEffi(int section, int sector, int layer)
calculate efficiency
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
int getLayer() const
Get layer number.
int getSection() const
Get section number.
float getPositionZ() const
Get hit global position z coordinate.
int getSector() const
Get sector number.
float getPositionX() const
Get hit global position x coordinate.
float getPositionY() const
Get hit global position y coordinate.
void setDescription(const std::string &description)
Sets the description of the module.
This is the Reconstruction Event-Data Model Track.
bool addBKLMHit(const UsedBKLMHit *bklmHit, const unsigned int sortingParameter, OriginTrackFinder foundByTrackFinder=OriginTrackFinder::c_undefinedTrackFinder)
Adds a bklm hit with the given information to the reco track.
unsigned int getNumberOfTotalHits() const
Return the number of cdc + svd + pxd + bklm + eklm hits.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Type-safe access to single objects in the data store.
static GeometryPar * instance(void)
Static method to get a reference to the singleton GeometryPar instance.
Define the geometry of a BKLM module Each sector [octant] contains Modules.
const CLHEP::Hep3Vector globalToLocal(const CLHEP::Hep3Vector &v, bool reco=false) const
Transform space-point within this module from global to local coordinates.
double getPhiStripWidth() const
Get phi-strip width.
double getZStripWidth() const
Get z-strip width.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
constexpr T square(const T &x)
Calculate the square of the input.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
double sqrt(double a)
sqrt for double
ExpRunEvt getPosition(const std::vector< Evt > &events, double tEdge)
Get the exp-run-evt number from the event time [hours].
Abstract base class for different kinds of events.