10#include <klm/modules/KLMTimeCollector/KLMTimeCollectorModule.h>
13#include <klm/dataobjects/bklm/BKLMHit1d.h>
14#include <klm/dataobjects/KLMDigit.h>
15#include <klm/dataobjects/KLMElementNumbers.h>
16#include <klm/dataobjects/KLMMuidLikelihood.h>
19#include <analysis/dataobjects/Particle.h>
20#include <analysis/dataobjects/ParticleList.h>
21#include <framework/dataobjects/EventT0.h>
22#include <framework/gearbox/Unit.h>
23#include <framework/logging/Logger.h>
24#include <mdst/dataobjects/Track.h>
25#include <tracking/dataobjects/ExtHit.h>
34using namespace Belle2::bklm;
35using namespace Belle2::EKLM;
43 m_TransformData(nullptr),
44 m_HeventT0_0(nullptr),
45 m_HeventT0_1(nullptr),
47 m_HnKLMHit2dOfTrack(nullptr),
48 m_HpositionDiff{nullptr},
49 m_HpositionXDiff(nullptr),
50 m_HpositionYDiff(nullptr),
51 m_HpositionZDiff(nullptr),
54 m_HnumDigit_scint_end(nullptr),
55 m_HnumDigit_scint(nullptr),
56 m_HnumDigit_rpc(nullptr),
59 setDescription(
"Module for KLM time calibration (data collection).");
65 "Whether to ignore ExtHits with backward propagation.",
false);
87 m_outTree =
new TTree(
"time_calibration_data",
"");
101 registerObject<TTree>(
"time_calibration_data",
m_outTree);
104 m_HeventT0_0 =
new TH1D(
"m_HeventT0_0",
"collision time before track number request;t0[ns]", 200, -100, 100);
105 m_HeventT0_1 =
new TH1D(
"m_HeventT0_1",
"collision time after track number request;t0[ns]", 200, -100, 100);
106 m_HnumTrack =
new TH1I(
"m_HnnumTrack",
"Number of Track;nTrack", 30, 0, 30);
108 m_HnKLMHit2dOfTrack =
new TH1I(
"m_HnKLMHit2dOfTrack",
"Number of KLMHit2d belong to recTrack;num of KLMHit2d", 20, 0, 20);
110 m_HpositionDiff =
new TH1D(
"m_HpositionDiff",
"Dist between extHit and KLMHit2d;dist", 160, 0, 8);
111 m_HpositionXDiff =
new TH1D(
"m_HpositionXDiff",
"DistX between extHit and KLMHit2d;distX", 100, 0, 5);
112 m_HpositionYDiff =
new TH1D(
"m_HpositionYDiff",
"DistY between extHit and KLMHit2d;distY", 100, 0, 5);
113 m_HpositionZDiff =
new TH1D(
"m_HpositionZDiff",
"DistZ between extHit and KLMHit2d;distZ", 100, 0, 5);
115 m_HflyTimeB =
new TH2D(
"m_HflyTimeB",
"flyTime;flyTime(wet)/ns;Layer", 40, 0, 20, 20, 0, 20);
116 m_HflyTimeE =
new TH2D(
"m_HflyTimeE",
"flyTime;flyTime(wet)/ns;Layer", 40, 0, 20, 20, 0, 20);
118 m_HnumDigit_rpc =
new TH1I(
"m_HnumDigit_rpc",
"Number of digit per bklmHit1d (RPC);number of digit", 15, 0, 15);
119 m_HnumDigit_scint =
new TH1I(
"m_HnumDigit_scint",
"Number of digit per bklmHit1d (scint);number of digit", 15, 0, 15);
120 m_HnumDigit_scint_end =
new TH1I(
"m_HnumDigit_scint_end",
"Number of eklmDigit per eklmHit2d (scint);number of eklmDigit", 15, 0,
150 if (!
m_eventT0->hasTemporaryEventT0(Const::EDetector::CDC))
152 const auto bestCDCEvtT0C =
m_eventT0->getBestCDCTemporaryEventT0();
157 int runId = eventMetaData->getRun();
158 int evtId = eventMetaData->getEvent();
160 getObjectPtr<TH1D>(
"m_HevtT0_0")->Fill(
m_Event.
t0);
163 unsigned n_track = inputList->getListSize();
166 B2DEBUG(20,
"No necessary tracks in" <<
LogVar(
"run", runId) <<
LogVar(
"event", evtId));
170 B2DEBUG(20,
"debug info for" <<
LogVar(
"run", runId) <<
LogVar(
"event", evtId) <<
LogVar(
"number of rec tracks", n_track));
172 getObjectPtr<TH1D>(
"m_HevtT0_1")->Fill(
m_Event.
t0);
173 getObjectPtr<TH1I>(
"m_HnTrack")->Fill(n_track);
176 B2DEBUG(20,
"Collect :: Track loop begins.");
179 for (
unsigned iT = 0; iT < n_track; ++iT) {
181 const Particle* particle = inputList->getParticle(iT);
182 const Track* track = particle->getTrack();
188 getObjectPtr<TH1I>(
"m_HnKLMHit2d")->Fill(
int(klmHit2ds.size()));
190 B2DEBUG(20,
"Track" <<
LogVar(
"exthits", extHits.
size())
191 <<
LogVar(
"KLMHit2d", klmHit2ds.size()));
192 if (klmHit2ds.size() < 2)
198 B2DEBUG(20,
"Collect :: extHits loop begins.");
199 for (
const ExtHit& eHit : extHits) {
200 if (eHit.getStatus() != EXT_EXIT)
204 if (eHit.isBackwardPropagated())
208 bool bklmCover = (eHit.getDetectorID() == Const::EDetector::BKLM);
209 bool eklmCover = (eHit.getDetectorID() == Const::EDetector::EKLM);
210 if (!bklmCover && !eklmCover)
213 int copyId = eHit.getCopyID();
214 int tFor, tSec, tLay, tPla, tStr;
227 B2DEBUG(20,
"Collect :: Assign elementNum based on copyId for extHits." <<
LogVar(
"Sub from elementNumber",
228 tSub) <<
LogVar(
"bklmCover", bklmCover) <<
LogVar(
"eklmCover", eklmCover));
230 bool crossed =
false;
237 m_vExtHits_RPC.insert(std::pair<unsigned int, ExtHit>(tModule, eHit));
242 m_vExtHits.insert(std::pair<unsigned int, ExtHit>(tChannel, eHit));
252 m_vExtHits.insert(std::pair<unsigned int, ExtHit>(tChannel, eHit));
268 const HepGeom::Transform3D* tr;
272 for (
const KLMHit2d& hit2d : klmHit2ds) {
276 unsigned nDigit = digits.size();
277 getObjectPtr<TH1I>(
"m_HnDigit_scint_end")->Fill(nDigit);
279 B2FATAL(
"Wrong number of related KLMDigits.");
281 if (!digits[0]->isGood() || !digits[1]->isGood())
291 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
293 ExtHit& entryHit = *(pair_extHits.first);
294 ExtHit& exitHit = *(pair_extHits.second);
299 ROOT::Math::XYZVector positionGlobal_digit = hit2d.getPosition();
300 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_digit;
305 hitGlobal_extHit.setX(positionGlobal_extHit.X() /
Unit::mm * CLHEP::mm);
306 hitGlobal_extHit.setY(positionGlobal_extHit.Y() /
Unit::mm * CLHEP::mm);
307 hitGlobal_extHit.setZ(positionGlobal_extHit.Z() /
Unit::mm * CLHEP::mm);
309 hitLocal_extHit = (*tr) * hitGlobal_extHit;
316 getObjectPtr<TH2D>(
"m_HfTimeE")->Fill(
m_Event.
flyTime, digitHit.getLayer());
317 getObjectPtr<TTree>(
"time_calibration_data")->Fill();
324 double stripWidtm_HZ, stripWidtm_HPhi;
330 if (hit2d.isOutOfTime())
334 if (bklmHit1ds.
size() != 2)
337 ROOT::Math::XYZVector positionGlobal_hit2d = hit2d.getPosition();
342 for (
const BKLMHit1d& hit1d : bklmHit1ds) {
344 getObjectPtr<TH1I>(
"m_HnDigit_scint")->Fill(digits.size());
345 if (digits.size() > 3)
348 for (
const KLMDigit& digitHit : digits) {
349 if (digitHit.inRPC() || !digitHit.isGood())
357 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
359 ExtHit& entryHit = *(pair_extHits.first);
360 ExtHit& exitHit = *(pair_extHits.second);
366 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_hit2d;
367 B2DEBUG(20,
LogVar(
"Distance between digit and hit2d", positionGlobal_diff.R()));
370 const CLHEP::Hep3Vector positionLocal_extHit = corMod->
globalToLocal(CLHEP::Hep3Vector(
371 positionGlobal_extHit.X(), positionGlobal_extHit.Y(), positionGlobal_extHit.Z()),
true);
372 const CLHEP::Hep3Vector positionLocal_hit2d = corMod->
globalToLocal(CLHEP::Hep3Vector(
373 positionGlobal_hit2d.X(), positionGlobal_hit2d.Y(), positionGlobal_hit2d.Z()),
true);
374 const CLHEP::Hep3Vector diffLocal = positionLocal_extHit - positionLocal_hit2d;
375 if (fabs(diffLocal.z()) > stripWidtm_HZ || fabs(diffLocal.y()) > stripWidtm_HPhi)
378 double propaLength = corMod->
getPropagationDistance(positionLocal_extHit, digitHit.getStrip(), digitHit.isPhiReadout());
387 getObjectPtr<TH2D>(
"m_HfTimeB")->Fill(
m_Event.
flyTime, digitHit.getLayer());
388 getObjectPtr<TTree>(
"time_calibration_data")->Fill();
401 if (hit2d.isOutOfTime())
404 if (bklmHit1ds.
size() != 2)
407 ROOT::Math::XYZVector positionGlobal_hit2d = hit2d.getPosition();
412 for (
const BKLMHit1d& hit1d : bklmHit1ds) {
414 getObjectPtr<TH1I>(
"m_HnDigit_rpc")->Fill(digits.size());
415 if (digits.size() > 5)
418 for (
const KLMDigit& digitHit : digits) {
423 unsigned int tModule =
m_elementNum->
moduleNumber(digitHit.getSubdetector(), digitHit.getSection(), digitHit.getSector(),
424 digitHit.getLayer());
427 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
429 ExtHit& entryHit = *(pair_extHits.first);
430 ExtHit& exitHit = *(pair_extHits.second);
434 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_hit2d;
435 B2DEBUG(20,
LogVar(
"Distance between digit and hit2d", positionGlobal_diff.R()));
438 const CLHEP::Hep3Vector positionLocal_extHit = corMod->
globalToLocal(CLHEP::Hep3Vector(
439 positionGlobal_extHit.X(), positionGlobal_extHit.Y(), positionGlobal_extHit.Z()),
true);
440 const CLHEP::Hep3Vector positionLocal_hit2d = corMod->
globalToLocal(CLHEP::Hep3Vector(
441 positionGlobal_hit2d.X(), positionGlobal_hit2d.Y(), positionGlobal_hit2d.Z()),
true);
442 const CLHEP::Hep3Vector diffLocal = positionLocal_extHit - positionLocal_hit2d;
443 if (fabs(diffLocal.z()) > stripWidtm_HZ || fabs(diffLocal.y()) > stripWidtm_HPhi)
447 double propaLength = propaLengthV3[2 - int(hit1d.isPhiReadout())];
456 getObjectPtr<TH2D>(
"m_HfTimeB")->Fill(
m_Event.
flyTime, digitHit.getLayer());
457 getObjectPtr<TTree>(
"time_calibration_data")->Fill();
466 ExtHit* entryHit =
nullptr;
467 ExtHit* exitHit =
nullptr;
468 std::multimap<unsigned int, ExtHit>::iterator it, itlow, itup;
469 itlow = v_ExtHits.lower_bound(channelID);
470 itup = v_ExtHits.upper_bound(channelID);
471 for (it = itlow; it != itup; ++it) {
472 if (entryHit ==
nullptr) {
473 entryHit = &(it->second);
474 }
else if ((it->second).getTOF() < entryHit->
getTOF()) {
475 entryHit = &(it->second);
477 if (exitHit ==
nullptr) {
478 exitHit = &(it->second);
479 }
else if ((it->second).getTOF() > exitHit->
getTOF()) {
480 exitHit = &(it->second);
483 std::pair<ExtHit*, ExtHit*> p_extHits = std::make_pair(entryHit, exitHit);
489 double diffM = pDiff.R();
490 double diffX = pDiff.X();
491 double diffY = pDiff.Y();
492 double diffZ = pDiff.Z();
493 getObjectPtr<TH1D>(
"m_HposiDiff")->Fill(diffM);
494 getObjectPtr<TH1D>(
"m_HposiXDiff")->Fill(diffX);
495 getObjectPtr<TH1D>(
"m_HposiYDiff")->Fill(diffY);
496 getObjectPtr<TH1D>(
"m_HposiZDiff")->Fill(diffZ);
static void channelNumberToElementNumbers(KLMChannelNumber channel, int *section, int *sector, int *layer, int *plane, int *strip)
Get element numbers by channel number.
Store one reconstructed BKLM 1D hit as a ROOT object.
Calibration collector module base class.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
static const EKLMElementNumbers & Instance()
Instantiation.
void stripNumberToElementNumbers(int stripGlobal, int *section, int *layer, int *sector, int *plane, int *strip) const
Get element numbers by strip global number.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
double getStripLength(int strip) const
Get strip length.
Store one Ext hit as a ROOT object.
ROOT::Math::XYZVector getPosition() const
Get position of this extrapolation hit.
double getTOF() const
Get time of flight from the point of closest approach near the origin to this hit.
@ c_Normal
Normally operating channel.
KLM digit (class representing a digitized hit in RPCs or scintillators).
unsigned int getUniqueChannelID() const override
Get unique channel identifier.
KLMChannelNumber channelNumber(int subdetector, int section, int sector, int layer, int plane, int strip) const
Get channel number.
static const KLMElementNumbers & Instance()
Instantiation.
KLMModuleNumber moduleNumber(int subdetector, int section, int sector, int layer) const
Get module number.
Class to store the likelihoods from KLM with additional information related to the extrapolation.
bool isExtrapolatedEndcapLayerCrossed(int layer) const
Check whether the given EKLM layer is crossed during extrapolation.
bool isExtrapolatedBarrelLayerCrossed(int layer) const
Check whether the given BKLM layer is crossed during extrapolation.
TH1D * m_HeventT0_1
Event T0 distribution after track selection.
StoreObjPtr< EventT0 > m_eventT0
Event T0 array.
const bklm::GeometryPar * m_geoParB
BKLM geometry parameters.
std::pair< ExtHit *, ExtHit * > matchExt(KLMChannelNumber channelID, std::multimap< unsigned int, ExtHit > &)
Match KLM hit and extHit.
std::multimap< unsigned int, ExtHit > m_vExtHits
Map for handle the extHit related to scint.
EKLM::TransformData * m_TransformData
Transformation data.
TTree * m_outTree
Data collection tree.
TH1I * m_HnumTrack
Number of tracks.
KLMTimeCollectorModule()
Constructor.
TH1I * m_HnumDigit_scint_end
EKLM parts.
TH1I * m_HnKLMHit2dOfTrack
Number of KLM hits related to track.
TH2D * m_HflyTimeB
Particle flying time versus detector layers (for BKLM).
TH1I * m_HnumDigit_scint
BKLM scitillator part.
TH1D * m_HpositionZDiff
Difference between global and local position (Z).
DBObjPtr< KLMChannelStatus > m_channelStatus
Channel status.
void collect() override
Event action, collect information for calibration.
virtual ~KLMTimeCollectorModule()
Destructor.
KLMTimeAlgorithm::Event m_Event
Time calibration data event.
void collectRPC(RelationVector< KLMHit2d > &)
Collect hits information for RPC of BKLM.
StoreArray< Track > m_tracks
Global tracks.
bool m_IgnoreBackwardPropagation
Whether to ignore ExtHits with backward propagation.
TH1D * m_HpositionXDiff
Difference between global and local position (X).
std::multimap< unsigned int, ExtHit > m_vExtHits_RPC
Map for handle the extHit related to RPC.
void collectScint(RelationVector< KLMHit2d > &)
Collect hits information for scintillator of BKLM.
TH1I * m_HnumDigit_rpc
BKLM RPC part.
void prepare() override
Initializes the module.
const EKLM::GeometryData * m_geoParE
EKLM geometry parameters.
void finish() override
Termination action.
TH1D * m_HeventT0_0
Event T0 distribution before track selection.
void storeDistDiff(ROOT::Math::XYZVector &)
Save position difference between matched kLMHit and ExtHit.
const KLMElementNumbers * m_elementNum
KLM element numbers.
TH1D * m_HpositionYDiff
Difference between global and local position (Y).
bool m_useEvtT0
Use event T0 or not.
void collectScintEnd(const RelationVector< KLMHit2d > &)
Collect hits information for scintillator of EKLM.
TH1D * m_HpositionDiff
Difference between global and local position.
TH2D * m_HflyTimeE
Particle flying time versus detector layers (for EKLM).
std::string m_inputListName
Input partilce list name.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Class to store reconstructed particles.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
Type-safe access to single objects in the data store.
Class that bundles various TrackFitResults.
static const double mm
[millimeters]
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
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.
const CLHEP::Hep3Vector getPropagationDistance(const CLHEP::Hep3Vector &) const
Convert local coordinates to signal-propagation distance (cm).
double getZStripWidth() const
Get z-strip width.
bool isFlipped() const
Determine if this module is flipped by 180 degrees about z axis within its air gap.
Class to store variables with their name which were sent to the logging service.
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.
uint16_t KLMChannelNumber
Channel number.
Abstract base class for different kinds of events.
double flyTime
Particle flying time.
double diffDistX
Global position difference between klmHit2d and ExtHit (X).
double t0
EventT0 for the digit.
int channelId
Unique channel id Barral and endcap merged.
bool inRPC
BKLM RPC flag, used for testing and not necessary.
double eDep
Collect energy eV.
double diffDistY
Global position difference between klmHit2d and ExtHit (Y).
double diffDistZ
Global position difference between klmHit2d and ExtHit (Z).
double dist
Propagation distance from hit to FEE.
double nPE
Number of photon electron.
double recTime
Recosntruction time respected to the trigger time.
bool isFlipped
If phi and z plane flipped, used for testing and not necessary.