10#include <klm/modules/KLMDQM2/KLMDQM2Module.h>
13#include <mdst/dataobjects/Track.h>
16#include <TDirectory.h>
19#include <CLHEP/Vector/ThreeVector.h>
40 m_GeometryBKLM{nullptr},
41 m_MatchedHitsBKLM{nullptr},
42 m_AllExtHitsBKLM{nullptr},
43 m_MatchedHitsEKLM{nullptr},
44 m_AllExtHitsEKLM{nullptr},
45 m_MatchedHitsBKLMSector{nullptr},
46 m_AllExtHitsBKLMSector{nullptr},
47 m_MatchedHitsEKLMSector{nullptr},
48 m_AllExtHitsEKLMSector{nullptr}
51 setDescription(R
"DOC(Additional Module for KLMDQM plots after HLT filters
53 An additional module developed to display plane efficiencies for the KLM during runs (i.e. for online analyses).
54 This module would be called after HLT filter in order to use mumu-tight skim to select reasonable events.
55 The output histograms would be plane efficiencies = MatchedDigits/AllExtits.
60 std::string(
"mu+:all"));
62 "Maximal distance in the units of strip number from ExtHit to "
63 "matching KLMDigit (not for multi-strip hits).",
double(8));
65 "Minimal number of matching digits.", 0);
66 addParam(
"MinimalMatchingDigitsOuterLayers",
68 "Minimal number of matching digits in outer layers.", 0);
70 "Minimal momentum in case there are no hits in outer layers.", 0.0);
72 "Whether to remove unused muons.",
false);
74 "Whether to ignore ExtHits with backward propagation.",
false);
77 "Directory for KLM DQM histograms in ROOT file.",
78 std::string(
"KLMEfficiencyDQM"));
80 "Software Trigger for event selection",
81 std::string(
"software_trigger_cut&skim&accept_mumutight"));
93 TDirectory::TContext context{gDirectory, newDirectory};
103 "Matched Hits in BKLM Plane",
108 "All ExtHits in BKLM Plane",
115 "Matched Hits in EKLM Plane",
120 "All ExtHits in EKLM Plane",
133 "Matched Hits in BKLM Sector",
134 BKLMMaxSectors, 0.5, 0.5 + BKLMMaxSectors);
138 "All ExtHits in BKLM Sector",
139 BKLMMaxSectors, 0.5, 0.5 + BKLMMaxSectors);
145 "Matched Hits in EKLM Sector",
146 EKLMMaxSectors, 0.5, EKLMMaxSectors + 0.5);
150 "All ExtHits in EKLM Sector",
151 EKLMMaxSectors, 0.5, EKLMMaxSectors + 0.5);
185 unsigned int nMuons =
m_MuonList->getListSize();
186 for (
unsigned int i = 0; i < nMuons; ++i) {
214 }
catch (
const std::out_of_range&) {
226 if (!(digit.getSubdetector() == hitData->
subdetector &&
227 digit.getSection() == hitData->
section &&
228 digit.getLayer() == hitData->
layer &&
229 digit.getSector() == hitData->
sector &&
230 digit.getPlane() == hitData->
plane))
234 double stripPosition = digit.getStrip();
237 if (digit.isMultiStrip()) {
239 stripPosition = 0.5 * (digit.getLastStrip() + digit.getStrip());
240 allowedDistance1D *= (digit.getLastStrip() - digit.getStrip() + 1);
242 if (fabs(stripPosition - hitData->
strip) < allowedDistance1D) {
243 hitData->
digit = &digit;
250 std::map<KLMPlaneNumber, struct HitData>& hitMap,
253 std::map<KLMPlaneNumber, struct HitData>::iterator it;
254 it = hitMap.find(planeGlobal);
259 if (it == hitMap.end()) {
260 hitMap.insert(std::pair<KLMPlaneNumber, struct HitData>(
261 planeGlobal, *hitData));
266 const Particle* muon, TH1F* matchedHitsBKLM, TH1F* allExtHitsBKLM,
267 TH1F* matchedHitsEKLM, TH1F* allExtHitsEKLM, TH1F* matchedHitsBKLMSec, TH1F* allExtHitsBKLMSec,
268 TH1F* matchedHitsEKLMSec, TH1F* allExtHitsEKLMSec)
270 const int nExtrapolationLayers =
274 std::map<KLMPlaneNumber, struct HitData> selectedHits;
275 std::map<KLMPlaneNumber, struct HitData>::iterator it;
278 struct HitData hitData, hitDataPrevious;
279 ROOT::Math::XYZVector extHitPosition;
280 CLHEP::Hep3Vector extHitPositionCLHEP, localPosition;
282 int extHitLayer[nExtrapolationLayers] = {0};
283 int digitLayer[nExtrapolationLayers] = {0};
287 hitDataPrevious.
sector = -1;
288 hitDataPrevious.
layer = -1;
289 for (
const ExtHit& hit : extHits) {
296 if (hit.getStatus() != EXT_EXIT)
305 if (hit.isBackwardPropagated())
310 hitData.
digit =
nullptr;
311 if (hit.getDetectorID() == Const::EDetector::EKLM) {
312 int stripGlobal = hit.getCopyID();
322 B2FATAL(
"Incomplete KLM channel status data.");
326 extHitLayer[layer - 1]++;
330 addHit(selectedHits, planeGlobal, &hitData);
332 }
else if (hit.getDetectorID() == Const::EDetector::BKLM) {
333 int moduleNumber = hit.getCopyID();
350 B2FATAL(
"Incomplete KLM channel status data.");
354 extHitLayer[layer - 1]++;
358 addHit(selectedHits, planeGlobal, &hitData);
362 extHitPosition = hit.getPosition();
363 extHitPositionCLHEP.setX(extHitPosition.X());
364 extHitPositionCLHEP.setY(extHitPosition.Y());
365 extHitPositionCLHEP.setZ(extHitPosition.Z());
369 localPosition = module->globalToLocal(extHitPositionCLHEP);
371 hitData.
strip = module->getZStrip(localPosition);
383 std::memcpy(&hitDataPrevious, &hitData,
sizeof(
struct HitData));
387 hitData.
strip,
false)) {
393 B2FATAL(
"Incomplete KLM channel status data.");
397 extHitLayer[layer - 1]++;
402 addHit(selectedHits, planeGlobal, &hitData);
406 hitData.
strip = module->getPhiStrip(localPosition);
410 hitData.
strip,
false)) {
416 B2FATAL(
"Incomplete KLM channel status data.");
420 extHitLayer[layer - 1]++;
425 addHit(selectedHits, planeGlobal, &hitData);
434 for (it = selectedHits.begin(); it != selectedHits.end(); ++it) {
436 if (it->second.digit !=
nullptr) {
439 it->second.subdetector, it->second.layer);
440 digitLayer[layer - 1]++;
446 for (it = selectedHits.begin(); it != selectedHits.end(); ++it) {
447 int matchingDigits = 0;
448 int matchingDigitsOuterLayers = 0;
449 int extHitsOuterLayers = 0;
451 it->second.subdetector, it->second.layer) - 1;
452 for (
int i = 0; i < nExtrapolationLayers; ++i) {
454 matchingDigits += digitLayer[i];
456 matchingDigitsOuterLayers += digitLayer[i];
457 extHitsOuterLayers += extHitLayer[i];
487 allExtHitsEKLM->Fill(planeNum);
488 allExtHitsEKLMSec->Fill(sectorNum);
489 if (it->second.digit) {
490 matchedHitsEKLM->Fill(planeNum);
491 matchedHitsEKLMSec->Fill(sectorNum);
498 it->second.section, it->second.sector, it->second.layer);
500 allExtHitsBKLM->Fill(layerGlobal);
501 allExtHitsBKLMSec->Fill(sectorGlobal);
502 if (it->second.digit) {
503 matchedHitsBKLM->Fill(layerGlobal);
504 matchedHitsBKLMSec->Fill(sectorGlobal);
507 B2FATAL(
"Had a hit that didn't come from BKLM or EKLM?");
static void channelNumberToElementNumbers(KLMChannelNumber channel, int *section, int *sector, int *layer, int *plane, int *strip)
Get element numbers by channel number.
static bool checkChannelNumber(int section, int sector, int layer, int plane, int strip, bool fatalError=true)
Check channel number.
@ c_FirstRPCLayer
First RPC layer.
static constexpr int getMaximalSectorNumber()
Get maximal sector number (1-based).
static void moduleNumberToElementNumbers(KLMModuleNumber module, int *section, int *sector, int *layer)
Get element numbers by module number.
static constexpr int getMaximalSectorGlobalNumber()
Get maximal sector global number.
static int layerGlobalNumber(int section, int sector, int layer)
Get layer global number.
void stripNumberToElementNumbers(int stripGlobal, int *section, int *layer, int *sector, int *plane, int *strip) const
Get element numbers by strip global number.
static constexpr int getMaximalSectorNumber()
Get maximal sector number.
int planeNumber(int section, int layer, int sector, int plane) const
Get plane number.
static constexpr int getMaximalSectorGlobalNumberKLMOrder()
Get maximal sector global number with KLM ordering (section, sector).
Store one Ext hit as a ROOT object.
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
ChannelStatus
Channel status.
@ c_Normal
Normally operating channel.
@ c_Unknown
Unknown status (no data).
TH1F * m_MatchedHitsBKLMSector
Matched hits in sector for BKLM.
TH1F * m_MatchedHitsEKLM
Matched hits in plane for EKLM.
const bklm::GeometryPar * m_GeometryBKLM
BKLM geometry.
void addHit(std::map< KLMPlaneNumber, struct HitData > &hitMap, KLMPlaneNumber planeGlobal, struct HitData *hitData)
Add hit to map.
StoreArray< KLMDigit > m_Digits
KLM digits.
DBObjPtr< KLMChannelStatus > m_ChannelStatus
Channel status.
TH1F * m_AllExtHitsBKLMSector
Extrapolated hits in sector for BKLM.
virtual void initialize() override
Register input and output data.
double m_MinimalMomentumNoOuterLayers
Minimal momentum in case there are no hits in outer layers.
bool m_RemoveUnusedMuons
Whether to remove unused muons.
virtual void event() override
Selection for mumu_tight_skim, then DQM plot filling
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
virtual void endRun() override
Called if the current run ends.
const EKLMElementNumbers * m_eklmElementNumbers
EKLM element numbers.
virtual void terminate() override
Called at the end of the event processing.
void findMatchingDigit(struct HitData *hitData)
Find matching digit.
std::string m_SoftwareTriggerName
Software Trigger Name.
TH1F * m_AllExtHitsEKLMSector
Extrapolated hits in sector for EKLM.
TH1F * m_MatchedHitsBKLM
Matched hits in plane for BKLM.
StoreObjPtr< ParticleList > m_MuonList
Muons.
virtual void beginRun() override
Called when entering a new run.
bool m_IgnoreBackwardPropagation
Whether to ignore ExtHits with backward propagation.
double m_AllowedDistance1D
Maximal distance in the units of strip number from ExtHit to matching KLMDigit.
KLMDQM2Module()
Constructor: Sets the description, the properties and the parameters of the module.
~KLMDQM2Module()
Destructor.
TH1F * m_AllExtHitsBKLM
Extrapolated hits in plane for BKLM.
TH1F * m_MatchedHitsEKLMSector
Matched hits in sector for EKLM.
const int m_PlaneNumBKLM
Number of layers/planes for BKLM.
int m_MinimalMatchingDigitsOuterLayers
Minimal number of matching digits in outer layers.
std::string m_MuonListName
Muon list name.
int m_MinimalMatchingDigits
Minimal number of matching digits.
StoreObjPtr< SoftwareTriggerResult > m_softwareTriggerResult
Trigger Information.
const int m_PlaneNumEKLM
Number of layers/planes for EKLM.
TH1F * m_AllExtHitsEKLM
Extrapolated hits in plane for EKLM.
bool collectDataTrack(const Particle *muon, TH1F *matchedHitsBKLM, TH1F *allExtHitsBKLM, TH1F *matchedHitsEKLM, TH1F *allExtHitsEKLM, TH1F *matchedHitsBKLMSec, TH1F *allExtHitsBKLMSec, TH1F *matchedHitsEKLMSec, TH1F *allExtHitsEKLMSec)
Collect the data for one muon.
bool triggerFlag()
Uses TrigResult along with desired software cut to determine whether histograms are filled or not for...
std::string m_HistogramDirectoryName
Directory for KLM DQM histograms in ROOT file.
void defineHisto() override
Definition of the histograms.
KLM digit (class representing a digitized hit in RPCs or scintillators).
KLMChannelNumber channelNumberBKLM(int section, int sector, int layer, int plane, int strip) const
Get channel number for BKLM.
KLMPlaneNumber planeNumberEKLM(int section, int sector, int layer, int plane) const
Get channel number for EKLM.
int getExtrapolationLayer(int subdetector, int layer) const
Get extrapolation layer number (BKLM - from 1 to 15, EKLM - from 16 to 29).
KLMPlaneNumber planeNumberBKLM(int section, int sector, int layer, int plane) const
Get plane number for BKLM.
static constexpr int getMaximalExtrapolationLayer()
Get maximal extrapolation layer.
KLMChannelNumber channelNumberEKLM(int section, int sector, int layer, int plane, int strip) const
Get channel number for EKLM.
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.
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
double getP() const
Returns momentum magnitude (same as getMomentumMagnitude but with shorter name)
Class for type safe access to objects that are referred to in relations.
Class that bundles various TrackFitResults.
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.
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.
uint16_t KLMPlaneNumber
Plane number.
@ c_accept
Accept this event.
Abstract base class for different kinds of events.
int subdetector
Subdetector.
double localPosition
Local coordinate.
const KLMDigit * digit
Digit.
const ExtHit * hit
Extrapolation hit.