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));
247 bool crossed =
false;
253 unsigned int tModule =
m_elementNum->moduleNumber(tSub, tFor, tSec, tLay);
254 m_vExtHits_RPC.insert(std::pair<unsigned int, ExtHit>(tModule, eHit));
256 unsigned int tChannel =
m_elementNum->channelNumber(tSub, tFor, tSec, tLay, tPla, tStr);
259 m_vExtHits.insert(std::pair<unsigned int, ExtHit>(tChannel, eHit));
266 unsigned int tChannel =
m_elementNum->channelNumber(tSub, tFor, tSec, tLay, tPla, tStr);
269 m_vExtHits.insert(std::pair<unsigned int, ExtHit>(tChannel, eHit));
285 const HepGeom::Transform3D* tr;
289 for (
const KLMHit2d& hit2d : klmHit2ds) {
293 unsigned nDigit = digits.size();
296 B2FATAL(
"Wrong number of related KLMDigits.");
298 if (!digits[0]->isGood() || !digits[1]->isGood())
302 m_Event.channelId = digitHit.getUniqueChannelID();
308 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
310 ExtHit& entryHit = *(pair_extHits.first);
311 ExtHit& exitHit = *(pair_extHits.second);
316 ROOT::Math::XYZVector positionGlobal_digit = hit2d.getPosition();
317 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_digit;
322 hitGlobal_extHit.setX(positionGlobal_extHit.X() /
Unit::mm * CLHEP::mm);
323 hitGlobal_extHit.setY(positionGlobal_extHit.Y() /
Unit::mm * CLHEP::mm);
324 hitGlobal_extHit.setZ(positionGlobal_extHit.Z() /
Unit::mm * CLHEP::mm);
326 hitLocal_extHit = (*tr) * hitGlobal_extHit;
329 m_Event.recTime = digitHit.getTime();
330 m_Event.eDep = digitHit.getEnergyDeposit();
331 m_Event.nPE = digitHit.getNPhotoelectrons();
332 m_Event.isGood = digitHit.isGood();
333 m_Event.getADCcount = digitHit.getCharge();
343 double stripWidtm_HZ, stripWidtm_HPhi;
349 if (hit2d.isOutOfTime())
353 if (bklmHit1ds.
size() != 2)
356 ROOT::Math::XYZVector positionGlobal_hit2d = hit2d.getPosition();
357 const bklm::Module* corMod =
m_geoParB->findModule(hit2d.getSection(), hit2d.getSector(), hit2d.getLayer());
361 for (
const BKLMHit1d& hit1d : bklmHit1ds) {
364 if (digits.size() > 3)
367 for (
const KLMDigit& digitHit : digits) {
368 if (digitHit.inRPC() || !digitHit.isGood())
371 unsigned int channelId_digit = digitHit.getUniqueChannelID();
376 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
378 ExtHit& entryHit = *(pair_extHits.first);
379 ExtHit& exitHit = *(pair_extHits.second);
381 m_Event.inRPC = digitHit.inRPC();
385 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_hit2d;
386 B2DEBUG(20,
LogVar(
"Distance between digit and hit2d", positionGlobal_diff.R()));
389 const CLHEP::Hep3Vector positionLocal_extHit = corMod->
globalToLocal(CLHEP::Hep3Vector(
390 positionGlobal_extHit.X(), positionGlobal_extHit.Y(), positionGlobal_extHit.Z()),
true);
391 const CLHEP::Hep3Vector positionLocal_hit2d = corMod->
globalToLocal(CLHEP::Hep3Vector(
392 positionGlobal_hit2d.X(), positionGlobal_hit2d.Y(), positionGlobal_hit2d.Z()),
true);
393 const CLHEP::Hep3Vector diffLocal = positionLocal_extHit - positionLocal_hit2d;
394 if (fabs(diffLocal.z()) > stripWidtm_HZ || fabs(diffLocal.y()) > stripWidtm_HPhi)
397 double propaLength = corMod->
getPropagationDistance(positionLocal_extHit, digitHit.getStrip(), digitHit.isPhiReadout());
400 m_Event.recTime = digitHit.getTime();
402 m_Event.eDep = digitHit.getEnergyDeposit();
403 m_Event.nPE = digitHit.getNPhotoelectrons();
404 m_Event.channelId = channelId_digit;
405 m_Event.isGood = digitHit.isGood();
406 m_Event.getADCcount = digitHit.getCharge();
422 if (hit2d.isOutOfTime())
425 if (bklmHit1ds.
size() != 2)
428 ROOT::Math::XYZVector positionGlobal_hit2d = hit2d.getPosition();
429 const bklm::Module* corMod =
m_geoParB->findModule(hit2d.getSection(), hit2d.getSector(), hit2d.getLayer());
433 for (
const BKLMHit1d& hit1d : bklmHit1ds) {
436 if (digits.size() > 5)
439 for (
const KLMDigit& digitHit : digits) {
440 unsigned int channelId_digit = digitHit.getUniqueChannelID();
441 m_Event.inRPC = digitHit.inRPC();
444 unsigned int tModule =
m_elementNum->moduleNumber(digitHit.getSubdetector(), digitHit.getSection(), digitHit.getSector(),
445 digitHit.getLayer());
448 if (pair_extHits.first ==
nullptr || pair_extHits.second ==
nullptr)
450 ExtHit& entryHit = *(pair_extHits.first);
451 ExtHit& exitHit = *(pair_extHits.second);
455 ROOT::Math::XYZVector positionGlobal_diff = positionGlobal_extHit - positionGlobal_hit2d;
456 B2DEBUG(20,
LogVar(
"Distance between digit and hit2d", positionGlobal_diff.R()));
459 const CLHEP::Hep3Vector positionLocal_extHit = corMod->
globalToLocal(CLHEP::Hep3Vector(
460 positionGlobal_extHit.X(), positionGlobal_extHit.Y(), positionGlobal_extHit.Z()),
true);
461 const CLHEP::Hep3Vector positionLocal_hit2d = corMod->
globalToLocal(CLHEP::Hep3Vector(
462 positionGlobal_hit2d.X(), positionGlobal_hit2d.Y(), positionGlobal_hit2d.Z()),
true);
463 const CLHEP::Hep3Vector diffLocal = positionLocal_extHit - positionLocal_hit2d;
464 if (fabs(diffLocal.z()) > stripWidtm_HZ || fabs(diffLocal.y()) > stripWidtm_HPhi)
468 double propaLength = propaLengthV3[2 - int(hit1d.isPhiReadout())];
471 m_Event.recTime = digitHit.getTime();
473 m_Event.eDep = digitHit.getEnergyDeposit();
474 m_Event.nPE = digitHit.getNPhotoelectrons();
475 m_Event.channelId = channelId_digit;
489 ExtHit* entryHit =
nullptr;
490 ExtHit* exitHit =
nullptr;
491 std::multimap<unsigned int, ExtHit>::iterator it, itlow, itup;
492 itlow = v_ExtHits.lower_bound(channelID);
493 itup = v_ExtHits.upper_bound(channelID);
494 for (it = itlow; it != itup; ++it) {
495 if (entryHit ==
nullptr) {
496 entryHit = &(it->second);
497 }
else if ((it->second).getTOF() < entryHit->
getTOF()) {
498 entryHit = &(it->second);
500 if (exitHit ==
nullptr) {
501 exitHit = &(it->second);
502 }
else if ((it->second).getTOF() > exitHit->
getTOF()) {
503 exitHit = &(it->second);
506 std::pair<ExtHit*, ExtHit*> p_extHits = std::make_pair(entryHit, exitHit);
512 double diffM = pDiff.R();
513 double diffX = pDiff.X();
514 double diffY = pDiff.Y();
515 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(std::string name, T *obj)
Register object with a name, takes ownership, do not access the pointer beyond prepare()
CalibrationCollectorModule()
Constructor. Sets the default prefix for calibration dataobjects.
T * getObjectPtr(std::string name)
Calls the CalibObjManager to get the requested stored collector data.
@ 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.
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]
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.