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>
22 using namespace Belle2::bklm;
23 using namespace CLHEP;
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 efficieny 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)) {
242 std::list<KLMHit2d*>::iterator j;
244 for (j = m_hits.begin(); j != m_hits.end(); ++j) {
245 (*j)->isOnStaTrack(
true);
257 for (j = m_hits.begin(); j != m_hits.end(); ++j) {
259 closestTrack->
addBKLMHit((*j), 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 oldDistance = INFINITY;
352 double oldAngle = INFINITY;
353 closestTrack =
nullptr;
357 ROOT::Math::XYZVector hitPosition = bklmHits[0]->getPosition();
358 TVector3 firstBKLMHitPosition(hitPosition.X(), hitPosition.Y(), hitPosition.Z());
361 TVector3 pos(0, 0, 0);
362 TVector3 mom(0, 0, 0);
368 state.getPosMomCov(pos, mom, cov);
369 if (mom.Y() * pos.Y() < 0)
370 { state = track.getMeasuredStateOnPlaneFromFirstHit(); }
372 const TVector3& distanceVec = firstBKLMHitPosition - pos;
373 state.extrapolateToPoint(firstBKLMHitPosition);
374 double newDistance = distanceVec.Mag2();
379 double angle = trkVec.Angle(mom);
382 if (newDistance < oldDistance) {
383 oldDistance = newDistance;
384 closestTrack = &track;
411 std::set<int> m_pointUsed;
423 for (
const KLMHit2d& hit2D : relatedHit2D) {
424 if (hit2D.getLayer() > iLayer + 1)
426 if (hit2D.getLayer() < iLayer + 1)
430 if (iLayer != 0 && cnt2 < 1)
432 if (iLayer != 14 && cnt1 < 1)
436 int minPhiStrip = module->getPhiStripMin();
437 int maxPhiStrip = module->getPhiStripMax();
438 int minZStrip = module->getZStripMin();
439 int maxZStrip = module->getZStripMax();
441 CLHEP::Hep3Vector local = module->getLocalPosition(minPhiStrip, minZStrip);
442 CLHEP::Hep3Vector local2 = module->getLocalPosition(maxPhiStrip, maxZStrip);
443 float minLocalY, maxLocalY;
444 float minLocalZ, maxLocalZ;
445 if (local[1] > local2[1]) {
446 maxLocalY = local[1];
447 minLocalY = local2[1];
449 maxLocalY = local2[1];
450 minLocalY = local[1];
452 if (local[2] > local2[2]) {
453 maxLocalZ = local[2];
454 minLocalZ = local2[2];
456 maxLocalZ = local2[2];
457 minLocalZ = local[2];
470 float reflocalY = trkPar[0] + trkPar[1] * reflocalX;
471 float reflocalZ = trkPar[2] + trkPar[3] * reflocalX;
476 Hep3Vector reflocal(reflocalX, reflocalY, reflocalZ);
478 Hep3Vector global(0, 0, 0);
480 global = module->localToGlobal(reflocal);
482 float localY = module->globalToLocal(global)[1];
483 float localZ = module->globalToLocal(global)[2];
487 if (localY > minLocalY && localY < maxLocalY && localZ > minLocalZ && localZ < maxLocalZ) {
489 bool m_iffound =
false;
490 m_total[iSection][iSector]->Fill(iLayer + 1);
494 for (
int he = 0; he <
hits2D.getEntries(); ++he) {
497 if (
hits2D[he]->isOutOfTime())
500 if (m_pointUsed.find(he) != m_pointUsed.end())
509 m_pointUsed.insert(he);
513 m_pass[iSection][iSector]->Fill(iLayer + 1);
514 m_passYX->Fill(global[0], global[1]);
515 m_passYZ->Fill(global[2], global[1]);
520 m_effiVsLayer[iSection][iSector]->Fill(m_iffound, iLayer + 1);
542 if (hit->getSection() == section && hit->getSector() == iSector + 1 && hit->getLayer() == iLayer + 1)
549 if (hit->getSection() == section && hit->getSector() == iSector + 1)
559 double x, y, z, dy, dz;
564 TVectorD m_SectorPar = track->getLocalTrackParam();
570 CLHEP::Hep3Vector globalPos(hit->getPositionX(), hit->getPositionY(),
571 hit->getPositionZ());
576 y = m_SectorPar[ 0 ] + x * m_SectorPar[ 1 ];
577 z = m_SectorPar[ 2 ] + x * m_SectorPar[ 3 ];
582 double distance =
sqrt(dy * dy + dz * dz);
588 error =
sqrt(pow(hit_localPhiErr, 2) +
589 pow(hit_localZErr, 2));
592 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]
Efficieny 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
Efficieny at global position Y vs X.
bool m_studyEffi
option for efficieny 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 efficieny 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
Efficieny 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.
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.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
#StateOnPlane with additional covariance matrix.
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
double sqrt(double a)
sqrt for double
Abstract base class for different kinds of events.