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;
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",
"");
112 m_HeventT0_0 =
new TH1D(
"m_HeventT0_0",
"collision time before track number request;t0[ns]", 200, -100, 100);
113 m_HeventT0_1 =
new TH1D(
"m_HeventT0_1",
"collision time after track number request;t0[ns]", 200, -100, 100);
114 m_HnumTrack =
new TH1I(
"m_HnnumTrack",
"Number of Track;nTrack", 30, 0, 30);
116 m_HnKLMHit2dOfTrack =
new TH1I(
"m_HnKLMHit2dOfTrack",
"Number of KLMHit2d belong to recTrack;num of KLMHit2d", 20, 0, 20);
118 m_HpositionDiff =
new TH1D(
"m_HpositionDiff",
"Dist between extHit and KLMHit2d;dist", 160, 0, 8);
119 m_HpositionXDiff =
new TH1D(
"m_HpositionXDiff",
"DistX between extHit and KLMHit2d;distX", 100, 0, 5);
120 m_HpositionYDiff =
new TH1D(
"m_HpositionYDiff",
"DistY between extHit and KLMHit2d;distY", 100, 0, 5);
121 m_HpositionZDiff =
new TH1D(
"m_HpositionZDiff",
"DistZ between extHit and KLMHit2d;distZ", 100, 0, 5);
123 m_HflyTimeB =
new TH2D(
"m_HflyTimeB",
"flyTime;flyTime(wet)/ns;Layer", 40, 0, 20, 20, 0, 20);
124 m_HflyTimeE =
new TH2D(
"m_HflyTimeE",
"flyTime;flyTime(wet)/ns;Layer", 40, 0, 20, 20, 0, 20);
126 m_HnumDigit_rpc =
new TH1I(
"m_HnumDigit_rpc",
"Number of digit per bklmHit1d (RPC);number of digit", 15, 0, 15);
127 m_HnumDigit_scint =
new TH1I(
"m_HnumDigit_scint",
"Number of digit per bklmHit1d (scint);number of digit", 15, 0, 15);
128 m_HnumDigit_scint_end =
new TH1I(
"m_HnumDigit_scint_end",
"Number of eklmDigit per eklmHit2d (scint);number of eklmDigit", 15, 0,
158 if (!
m_eventT0->hasTemporaryEventT0(Const::EDetector::CDC))
160 const auto bestCDCEvtT0C =
m_eventT0->getBestCDCTemporaryEventT0();
161 m_Event.t0 = bestCDCEvtT0C->eventT0;
163 double Uncertainty =
m_eventT0->getEventT0Uncertainty();
168 int runId = eventMetaData->getRun();
169 int evtId = eventMetaData->getEvent();
176 unsigned n_track = inputList->getListSize();
179 B2DEBUG(20,
"No necessary tracks in" <<
LogVar(
"run", runId) <<
LogVar(
"event", evtId));
183 B2DEBUG(20,
"debug info for" <<
LogVar(
"run", runId) <<
LogVar(
"event", evtId) <<
LogVar(
"number of rec tracks", n_track));
189 B2DEBUG(20,
"Collect :: Track loop begins.");
192 for (
unsigned iT = 0; iT < n_track; ++iT) {
194 const Particle* particle = inputList->getParticle(iT);
195 const Track* track = particle->getTrack();
198 double T_Charge = particle->getCharge();
199 m_Event.Track_Charge = T_Charge;
207 B2DEBUG(20,
"Track" <<
LogVar(
"exthits", extHits.
size())
208 <<
LogVar(
"KLMHit2d", klmHit2ds.size()));
209 if (klmHit2ds.size() < 2)
215 B2DEBUG(20,
"Collect :: extHits loop begins.");
216 for (
const ExtHit& eHit : extHits) {
217 if (eHit.getStatus() != EXT_EXIT)
221 if (eHit.isBackwardPropagated())
225 bool bklmCover = (eHit.getDetectorID() == Const::EDetector::BKLM);
226 bool eklmCover = (eHit.getDetectorID() == Const::EDetector::EKLM);
227 if (!bklmCover && !eklmCover)
230 int copyId = eHit.getCopyID();
231 int tFor, tSec, tLay, tPla, tStr;
244 B2DEBUG(20,
"Collect :: Assign elementNum based on copyId for extHits." <<
LogVar(
"Sub from elementNumber",
245 tSub) <<
LogVar(
"bklmCover", bklmCover) <<
LogVar(
"eklmCover", eklmCover));
252 unsigned int tModule =
m_elementNum->moduleNumber(tSub, tFor, tSec, tLay);
253 m_vExtHits_RPC.insert(std::pair<unsigned int, ExtHit>(tModule, eHit));
255 unsigned int tChannel =
m_elementNum->channelNumber(tSub, tFor, tSec, tLay, tPla, tStr);
258 m_vExtHits.insert(std::pair<unsigned int, ExtHit>(tChannel, eHit));
265 unsigned int tChannel =
m_elementNum->channelNumber(tSub, tFor, tSec, tLay, tPla, tStr);
268 m_vExtHits.insert(std::pair<unsigned int, ExtHit>(tChannel, eHit));
284 const HepGeom::Transform3D* tr;
288 for (
const KLMHit2d& hit2d : klmHit2ds) {
292 unsigned nDigit = digits.size();
295 B2FATAL(
"Wrong number of related KLMDigits.");
297 if (!digits[0]->isGood() || !digits[1]->isGood())
300 for (
const KLMDigit& digitHit : digits) {
301 m_Event.channelId = digitHit.getUniqueChannelID();
307 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
309 const ExtHit& entryHit = *(pair_extHits.first);
310 const ExtHit& exitHit = *(pair_extHits.second);
315 ROOT::Math::XYZVector positionGlobal_digit = hit2d.getPosition();
316 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_digit;
321 hitGlobal_extHit.setX(positionGlobal_extHit.X() /
Unit::mm * CLHEP::mm);
322 hitGlobal_extHit.setY(positionGlobal_extHit.Y() /
Unit::mm * CLHEP::mm);
323 hitGlobal_extHit.setZ(positionGlobal_extHit.Z() /
Unit::mm * CLHEP::mm);
325 hitLocal_extHit = (*tr) * hitGlobal_extHit;
328 m_Event.recTime = digitHit.getTime();
329 m_Event.eDep = digitHit.getEnergyDeposit();
330 m_Event.nPE = digitHit.getNPhotoelectrons();
331 m_Event.isGood = digitHit.isGood();
332 m_Event.getADCcount = digitHit.getCharge();
342 double stripWidtm_HZ, stripWidtm_HPhi;
348 if (hit2d.isOutOfTime())
352 if (bklmHit1ds.
size() != 2)
355 ROOT::Math::XYZVector positionGlobal_hit2d = hit2d.getPosition();
356 const bklm::Module* corMod =
m_geoParB->findModule(hit2d.getSection(), hit2d.getSector(), hit2d.getLayer());
360 for (
const BKLMHit1d& hit1d : bklmHit1ds) {
363 if (digits.size() > 3)
366 for (
const KLMDigit& digitHit : digits) {
367 if (digitHit.inRPC() || !digitHit.isGood())
370 unsigned int channelId_digit = digitHit.getUniqueChannelID();
375 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
377 const ExtHit& entryHit = *(pair_extHits.first);
378 const ExtHit& exitHit = *(pair_extHits.second);
380 m_Event.inRPC = digitHit.inRPC();
384 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_hit2d;
385 B2DEBUG(20,
LogVar(
"Distance between digit and hit2d", positionGlobal_diff.R()));
388 const CLHEP::Hep3Vector positionLocal_extHit = corMod->
globalToLocal(CLHEP::Hep3Vector(
389 positionGlobal_extHit.X(), positionGlobal_extHit.Y(), positionGlobal_extHit.Z()),
true);
390 const CLHEP::Hep3Vector positionLocal_hit2d = corMod->
globalToLocal(CLHEP::Hep3Vector(
391 positionGlobal_hit2d.X(), positionGlobal_hit2d.Y(), positionGlobal_hit2d.Z()),
true);
392 const CLHEP::Hep3Vector diffLocal = positionLocal_extHit - positionLocal_hit2d;
393 if (fabs(diffLocal.z()) > stripWidtm_HZ || fabs(diffLocal.y()) > stripWidtm_HPhi)
396 double propaLength = corMod->
getPropagationDistance(positionLocal_extHit, digitHit.getStrip(), digitHit.isPhiReadout());
399 m_Event.recTime = digitHit.getTime();
401 m_Event.eDep = digitHit.getEnergyDeposit();
402 m_Event.nPE = digitHit.getNPhotoelectrons();
403 m_Event.channelId = channelId_digit;
404 m_Event.isGood = digitHit.isGood();
405 m_Event.getADCcount = digitHit.getCharge();
421 if (hit2d.isOutOfTime())
424 if (bklmHit1ds.
size() != 2)
427 ROOT::Math::XYZVector positionGlobal_hit2d = hit2d.getPosition();
428 const bklm::Module* corMod =
m_geoParB->findModule(hit2d.getSection(), hit2d.getSector(), hit2d.getLayer());
432 for (
const BKLMHit1d& hit1d : bklmHit1ds) {
435 if (digits.size() > 5)
438 for (
const KLMDigit& digitHit : digits) {
439 unsigned int channelId_digit = digitHit.getUniqueChannelID();
440 m_Event.inRPC = digitHit.inRPC();
443 unsigned int tModule =
m_elementNum->moduleNumber(digitHit.getSubdetector(), digitHit.getSection(), digitHit.getSector(),
444 digitHit.getLayer());
447 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
449 const ExtHit& entryHit = *(pair_extHits.first);
450 const ExtHit& exitHit = *(pair_extHits.second);
454 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_hit2d;
455 B2DEBUG(20,
LogVar(
"Distance between digit and hit2d", positionGlobal_diff.R()));
458 const CLHEP::Hep3Vector positionLocal_extHit = corMod->
globalToLocal(CLHEP::Hep3Vector(
459 positionGlobal_extHit.X(), positionGlobal_extHit.Y(), positionGlobal_extHit.Z()),
true);
460 const CLHEP::Hep3Vector positionLocal_hit2d = corMod->
globalToLocal(CLHEP::Hep3Vector(
461 positionGlobal_hit2d.X(), positionGlobal_hit2d.Y(), positionGlobal_hit2d.Z()),
true);
462 const CLHEP::Hep3Vector diffLocal = positionLocal_extHit - positionLocal_hit2d;
463 if (fabs(diffLocal.z()) > stripWidtm_HZ || fabs(diffLocal.y()) > stripWidtm_HPhi)
467 double propaLength = propaLengthV3[2 - int(hit1d.isPhiReadout())];
470 m_Event.recTime = digitHit.getTime();
472 m_Event.eDep = digitHit.getEnergyDeposit();
473 m_Event.nPE = digitHit.getNPhotoelectrons();
474 m_Event.channelId = channelId_digit;
488 ExtHit* entryHit =
nullptr;
489 ExtHit* exitHit =
nullptr;
490 std::multimap<unsigned int, ExtHit>::iterator it, itlow, itup;
491 itlow = v_ExtHits.lower_bound(channelID);
492 itup = v_ExtHits.upper_bound(channelID);
493 for (it = itlow; it != itup; ++it) {
494 if (entryHit ==
nullptr) {
495 entryHit = &(it->second);
496 }
else if ((it->second).getTOF() < entryHit->
getTOF()) {
497 entryHit = &(it->second);
499 if (exitHit ==
nullptr) {
500 exitHit = &(it->second);
501 }
else if ((it->second).getTOF() > exitHit->
getTOF()) {
502 exitHit = &(it->second);
505 std::pair<ExtHit*, ExtHit*> p_extHits = std::make_pair(entryHit, exitHit);
511 double diffM = pDiff.R();
512 double diffX = pDiff.X();
513 double diffY = pDiff.Y();
514 double diffZ = pDiff.Z();
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.
void registerObject(const std::string &name, T *obj)
Register object with a name, takes ownership, do not access the pointer beyond prepare()
T * getObjectPtr(const std::string &name)
Calls the CalibObjManager to get the requested stored collector data.
CalibrationCollectorModule()
Constructor. Sets the default prefix for calibration dataobjects.
@ 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.
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).
static const KLMElementNumbers & Instance()
Instantiation.
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.
virtual ~KLMTimeCollectorModule() override
Destructor.
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.
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]
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.