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>
22using namespace Belle2::bklm;
35 m_runTotalEventsWithTracks(0)
37 for (
int i = 0; i < 8; ++i) {
45 setDescription(
"Perform standard-alone straight line tracking for BKLM");
48 "[degree], match BKLMTrack to RecoTrack; angle between them is required to be smaller than (default 10)",
double(10.0));
50 "[cm], During efficiency calculation, distance between track and 2dhit must be smaller than (default 10)",
double(10.0));
52 "[sigma], During efficiency calculation, uncertainty of 2dhit must be smaller than (default 5); ",
double(5));
54 ", During track finding, a good track after initial seed hits must be larger than is (default 2); ",
unsigned(2));
56 ", During track finding, a good track after initial seed hits must be smaller than is (default 60); ",
unsigned(60));
58 "[bool], do the BKLMTrack fitting in global system (multi-sectors track) or local system (sector by sector) (default is false, local sys.)",
60 addParam(
"StudyEffiMode",
m_studyEffi,
"[bool], run in efficiency study mode (default is false)",
false);
61 addParam(
"outputName",
m_outPath,
"[string], output file name containing efficiencies plots ", std::string(
"bklmEffi.root"));
80 B2INFO(
"BKLMTrackingModule:: this module is running in efficiency study mode!");
84 std::string labelFB[2] = {
"BB",
"BF"};
90 m_totalYX =
new TH2F(
"totalYX",
" denominator Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
91 m_passYX =
new TH2F(
"passYX",
" numerator Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
92 m_totalYZ =
new TH2F(
"totalYZ",
" denominator Y vs. Z", gNbin, gmin, gmax, gNbin, gmin, gmax);
93 m_passYZ =
new TH2F(
"passYZ",
" numerator Y vs. Z", gNbin, gmin, gmax, gNbin, gmin, gmax);
94 m_effiYX =
new TH2F(
"effiYX",
" effi. Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
95 m_effiYZ =
new TH2F(
"effiYZ",
" effi. Y vs. X", gNbin, gmin, gmax, gNbin, gmin, gmax);
96 m_effiYX->GetXaxis()->SetTitle(
"x (cm)");
97 m_effiYX->GetYaxis()->SetTitle(
"y (cm)");
98 m_effiYZ->GetXaxis()->SetTitle(
"z (cm)");
99 m_effiYZ->GetYaxis()->SetTitle(
"y (cm)");
100 for (
int iF = 0; iF < 2; iF++) {
101 for (
int iS = 0; iS < 8; iS++) {
102 hname.Form(
"effi_%s%i", labelFB[iF].c_str(), iS);
103 m_effiVsLayer[iF][iS] =
new TEfficiency(hname, hname, Nbin, 0, 16);
104 hname.Form(
"total_%s%i", labelFB[iF].c_str(), iS);
105 m_total[iF][iS] =
new TH1F(hname, hname, Nbin, 0, 16);
106 hname.Form(
"pass_%s%i", labelFB[iF].c_str(), iS);
107 m_pass[iF][iS] =
new TH1F(hname, hname, Nbin, 0, 16);
116 m_runNumber.push_back((
int)eventMetaData->getRun());
124 bool thereIsATrack =
false;
129 thereIsATrack =
true;
131 for (
int iSection = 0; iSection < 2; iSection++) {
132 for (
int iSector = 0; iSector < 8; iSector++) {
133 for (
int iLayer = 0; iLayer < 15; iLayer++) {
136 thereIsATrack =
true;
163 if (
hits2D.getEntries() < 1)
166 for (
int j = 0; j <
hits2D.getEntries(); j++) {
169 hits2D[j]->isOnStaTrack(
false);
173 for (
int hi = 0; hi <
hits2D.getEntries() - 1; ++hi) {
181 if (
hits2D[hi]->isOnStaTrack())
183 if (
hits2D[hi]->isOutOfTime())
185 for (
int hj = hi + 1; hj <
hits2D.getEntries(); ++hj) {
187 if (
hits2D[hj]->isOnStaTrack())
189 if (
hits2D[hj]->isOutOfTime())
194 std::abs(
hits2D[hi]->getLayer() -
hits2D[hj]->getLayer()) < 3)
197 std::list<KLMHit2d*> sectorHitList;
201 std::list<KLMHit2d*> seed;
202 seed.push_back(
hits2D[hi]);
203 seed.push_back(
hits2D[hj]);
205 for (
int ho = 0; ho <
hits2D.getEntries(); ++ho) {
208 if (ho == hi || ho == hj)
214 if (
hits2D[ho]->isOnStaTrack())
220 if (
hits2D[ho]->isOutOfTime())
222 sectorHitList.push_back(
hits2D[ho]);
231 std::list<KLMHit2d*> m_hits;
232 if (m_finder->
filter(seed, sectorHitList, m_hits)) {
244 hit2d->isOnStaTrack(
true);
258 closestTrack->
addBKLMHit(hit2d, sortingParameter, RecoHitInformation::OriginTrackFinder::c_LocalTrackFinder);
280 for (
long unsigned int i = 0; i <
m_runNumber.size(); i++) {
282 B2INFO(
"BKLMTrackingModule:: run " <<
m_runNumber.at(i) <<
" --> " << ratio * 100 <<
"% of events has 1+ BKLMTracks");
286 for (
int iF = 0; iF < 2; iF++) {
287 for (
int iS = 0; iS < 8; iS++) {
294 for (
int i = 0; i <
m_totalYX->GetNbinsX(); i++) {
295 for (
int j = 0; j <
m_totalYX->GetNbinsY(); j++) {
296 float num =
m_passYX->GetBinContent(i + 1, j + 1);
297 float denom =
m_totalYX->GetBinContent(i + 1, j + 1);
299 m_effiYX->SetBinContent(i + 1, j + 1, num / denom);
300 m_effiYX->SetBinError(i + 1, j + 1,
sqrt(num * (denom - num) / (denom * denom * denom)));
302 m_effiYX->SetBinContent(i + 1, j + 1, 0);
303 m_effiYX->SetBinError(i + 1, j + 1, 0);
306 num =
m_passYZ->GetBinContent(i + 1, j + 1);
307 denom =
m_totalYZ->GetBinContent(i + 1, j + 1);
309 m_effiYZ->SetBinContent(i + 1, j + 1, num / denom);
310 m_effiYZ->SetBinError(i + 1, j + 1,
sqrt(num * (denom - num) / (denom * denom * denom)));
312 m_effiYZ->SetBinContent(i + 1, j + 1, 0);
313 m_effiYZ->SetBinError(i + 1, j + 1, 0);
342 if (bklmHits.
size() < 1) {
343 B2INFO(
"BKLMTrackingModule::something is wrong! there is BKLMTrack but no bklmHits");
347 B2INFO(
"BKLMTrackingModule::there is no recoTrack");
350 double oldDistanceSq = INFINITY;
351 double oldAngle = INFINITY;
352 closestTrack =
nullptr;
356 TVector3 firstBKLMHitPosition(bklmHits[0]->
getPosition().X(),
375 genfit::MeasuredStateOnPlane state = track.getMeasuredStateOnPlaneFromLastHit();
377 state.getPosMomCov(pos, mom, cov);
378 if (mom.Y() * pos.Y() < 0) {
379 state = track.getMeasuredStateOnPlaneFromFirstHit();
381 const TVector3& distanceVec = firstBKLMHitPosition - pos;
382 state.extrapolateToPoint(firstBKLMHitPosition);
383 double newDistanceSq = distanceVec.Mag2();
384 double angle = bklmTrkVec.Angle(mom);
387 if (newDistanceSq < oldDistanceSq) {
388 oldDistanceSq = newDistanceSq;
389 closestTrack = &track;
399 }
catch (genfit::Exception& e) {
415 std::set<int> m_pointUsed;
427 for (
const KLMHit2d& hit2D : relatedHit2D) {
428 if (hit2D.getLayer() > iLayer + 1)
430 if (hit2D.getLayer() < iLayer + 1)
434 if (iLayer != 0 && cnt2 < 1)
436 if (iLayer != 14 && cnt1 < 1)
440 int minPhiStrip = module->getPhiStripMin();
441 int maxPhiStrip = module->getPhiStripMax();
442 int minZStrip = module->getZStripMin();
443 int maxZStrip = module->getZStripMax();
445 CLHEP::Hep3Vector local = module->getLocalPosition(minPhiStrip, minZStrip);
446 CLHEP::Hep3Vector local2 = module->getLocalPosition(maxPhiStrip, maxZStrip);
447 float minLocalY, maxLocalY;
448 float minLocalZ, maxLocalZ;
449 if (local[1] > local2[1]) {
450 maxLocalY = local[1];
451 minLocalY = local2[1];
453 maxLocalY = local2[1];
454 minLocalY = local[1];
456 if (local[2] > local2[2]) {
457 maxLocalZ = local[2];
458 minLocalZ = local2[2];
460 maxLocalZ = local2[2];
461 minLocalZ = local[2];
474 float reflocalY = trkPar[0] + trkPar[1] * reflocalX;
475 float reflocalZ = trkPar[2] + trkPar[3] * reflocalX;
480 Hep3Vector reflocal(reflocalX, reflocalY, reflocalZ);
482 Hep3Vector global(0, 0, 0);
484 global = module->localToGlobal(reflocal);
486 float localY = module->globalToLocal(global)[1];
487 float localZ = module->globalToLocal(global)[2];
491 if (localY > minLocalY && localY < maxLocalY && localZ > minLocalZ && localZ < maxLocalZ) {
493 bool m_iffound =
false;
494 m_total[iSection][iSector]->Fill(iLayer + 1);
498 for (
int he = 0; he <
hits2D.getEntries(); ++he) {
501 if (
hits2D[he]->isOutOfTime())
504 if (m_pointUsed.find(he) != m_pointUsed.end())
513 m_pointUsed.insert(he);
517 m_pass[iSection][iSector]->Fill(iLayer + 1);
518 m_passYX->Fill(global[0], global[1]);
519 m_passYZ->Fill(global[2], global[1]);
524 m_effiVsLayer[iSection][iSector]->Fill(m_iffound, iLayer + 1);
546 if (hit->getSection() == section && hit->getSector() == iSector + 1 && hit->getLayer() == iLayer + 1)
553 if (hit->getSection() == section && hit->getSector() == iSector + 1)
563 double x, y, z, dy, dz;
568 TVectorD m_SectorPar = track->getLocalTrackParam();
574 CLHEP::Hep3Vector globalPos(hit->getPositionX(), hit->getPositionY(),
575 hit->getPositionZ());
580 y = m_SectorPar[ 0 ] + x * m_SectorPar[ 1 ];
581 z = m_SectorPar[ 2 ] + x * m_SectorPar[ 3 ];
586 double distance =
sqrt(dy * dy + dz * dz);
592 error =
sqrt(pow(hit_localPhiErr, 2) +
593 pow(hit_localZErr, 2));
596 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.
int getSector() const
Get sector number.
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.
int getEntries() const
Get the number of objects in the array.
Type-safe access to single objects in the data store.
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
double getActiveMiddleRadius(int section, int sector, int layer) const
Get the radial midpoint of the detector module's active volume of specified layer.
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.
#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.