10 #include <klm/modules/KLMDQM2/KLMDQM2Module.h>
11 #include <mdst/dataobjects/Track.h>
14 #include <TDirectory.h>
17 #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 dduring 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 efficiences = MatchedDigits/AllExtits.
59 addParam(
"MuonListName", m_MuonListName,
"Muon list name.",
60 std::string(
"mu+:all"));
61 addParam(
"AllowedDistance1D", m_AllowedDistance1D,
62 "Maximal distance in the units of strip number from ExtHit to "
63 "matching KLMDigit.",
double(8));
64 addParam(
"MinimalMatchingDigits", m_MinimalMatchingDigits,
65 "Minimal number of matching digits.", 0);
66 addParam(
"MinimalMatchingDigitsOuterLayers",
67 m_MinimalMatchingDigitsOuterLayers,
68 "Minimal number of matching digits in outer layers.", 0);
69 addParam(
"MinimalMomentumNoOuterLayers", m_MinimalMomentumNoOuterLayers,
70 "Minimal momentum in case there are no hits in outer layers.", 0.0);
71 addParam(
"RemoveUnusedMuons", m_RemoveUnusedMuons,
72 "Whether to remove unused muons.",
false);
73 addParam(
"IgnoreBackwardPropagation", m_IgnoreBackwardPropagation,
74 "Whether to ignore ExtHits with backward propagation.",
false);
75 setPropertyFlags(c_ParallelProcessingCertified);
76 addParam(
"histogramDirectoryName", m_HistogramDirectoryName,
77 "Directory for KLM DQM histograms in ROOT file.",
78 std::string(
"KLMEfficiencyDQM"));
93 TDirectory::TContext context{gDirectory, newDirectory};
103 "Matched Hits in BKLM Plane",
109 "All ExtHits in BKLM Plane",
117 "Matched Hits in EKLM Plane",
123 "All ExtHits in EKLM Plane",
137 "Matched Hits in BKLM Sector",
138 BKLMMaxSectors, 0.5, 0.5 + BKLMMaxSectors);
143 "All ExtHits in BKLM Sector",
144 BKLMMaxSectors, 0.5, 0.5 + BKLMMaxSectors);
151 "Matched Hits in EKLM Sector",
152 EKLMMaxSectors, 0.5, EKLMMaxSectors + 0.5);
157 "All ExtHits in EKLM Sector",
158 EKLMMaxSectors, 0.5, EKLMMaxSectors + 0.5);
198 unsigned int nMuons =
m_MuonList->getListSize();
199 for (
unsigned int i = 0; i < nMuons; ++i) {
228 }
catch (
const std::out_of_range&) {
237 struct HitData* hitData)
244 if (digit.isMultiStrip())
246 if (!(digit.getSubdetector() == hitData->subdetector &&
247 digit.getSection() == hitData->section &&
248 digit.getLayer() == hitData->layer &&
249 digit.getSector() == hitData->sector &&
250 digit.getPlane() == hitData->plane))
253 hitData->digit = &digit;
260 std::map<KLMPlaneNumber, struct HitData>& hitMap,
263 std::map<KLMPlaneNumber, struct HitData>::iterator it;
264 it = hitMap.find(planeGlobal);
269 if (it == hitMap.end()) {
270 hitMap.insert(std::pair<KLMPlaneNumber, struct HitData>(
271 planeGlobal, *hitData));
276 const Particle* muon, TH1F* matchedHitsBKLM, TH1F* allExtHitsBKLM,
277 TH1F* matchedHitsEKLM, TH1F* allExtHitsEKLM, TH1F* matchedHitsBKLMSec, TH1F* allExtHitsBKLMSec,
278 TH1F* matchedHitsEKLMSec, TH1F* allExtHitsEKLMSec)
280 const int nExtrapolationLayers =
282 const Track* track = muon->getTrack();
284 std::map<KLMPlaneNumber, struct HitData> selectedHits;
285 std::map<KLMPlaneNumber, struct HitData>::iterator it;
288 struct HitData hitData, hitDataPrevious;
289 TVector3 extHitPosition;
290 CLHEP::Hep3Vector extHitPositionCLHEP, localPosition;
292 int extHitLayer[nExtrapolationLayers] = {0};
293 int digitLayer[nExtrapolationLayers] = {0};
294 hitDataPrevious.subdetector = -1;
295 for (
const ExtHit& hit : extHits) {
302 if (hit.getStatus() != EXT_EXIT)
311 if (hit.isBackwardPropagated())
316 hitData.digit =
nullptr;
317 if (hit.getDetectorID() == Const::EDetector::EKLM) {
318 int stripGlobal = hit.getCopyID();
321 stripGlobal, &hitData.section, &hitData.layer, &hitData.sector,
322 &hitData.plane, &hitData.strip);
324 hitData.section, hitData.sector, hitData.layer,
325 hitData.plane, hitData.strip);
328 B2FATAL(
"Incomplete KLM channel status data.");
331 hitData.subdetector, hitData.layer);
332 extHitLayer[layer - 1]++;
334 hitData.section, hitData.sector, hitData.layer,
336 addHit(selectedHits, planeGlobal, &hitData);
338 }
else if (hit.getDetectorID() == Const::EDetector::BKLM) {
339 int moduleNumber = hit.getCopyID();
342 moduleNumber, &hitData.section, &hitData.sector, &hitData.layer);
349 moduleNumber, &hitData.section, &hitData.sector, &hitData.layer,
350 &hitData.plane, &hitData.strip);
352 hitData.section, hitData.sector, hitData.layer,
353 hitData.plane, hitData.strip);
356 B2FATAL(
"Incomplete KLM channel status data.");
359 hitData.subdetector, hitData.layer);
360 extHitLayer[layer - 1]++;
362 hitData.section, hitData.sector, hitData.layer,
364 addHit(selectedHits, planeGlobal, &hitData);
368 extHitPosition = hit.getPosition();
369 extHitPositionCLHEP.setX(extHitPosition.X());
370 extHitPositionCLHEP.setY(extHitPosition.Y());
371 extHitPositionCLHEP.setZ(extHitPosition.Z());
375 localPosition = module->globalToLocal(extHitPositionCLHEP);
377 hitData.strip = module->getZStrip(localPosition);
384 if (hitData.subdetector == hitDataPrevious.subdetector &&
385 hitData.section == hitDataPrevious.section &&
386 hitData.sector == hitDataPrevious.sector &&
387 hitData.layer == hitDataPrevious.layer)
389 std::memcpy(&hitDataPrevious, &hitData,
sizeof(
struct HitData));
392 hitData.section, hitData.sector, hitData.layer, hitData.plane,
393 hitData.strip,
false)) {
395 hitData.section, hitData.sector, hitData.layer,
396 hitData.plane, hitData.strip);
399 B2FATAL(
"Incomplete KLM channel status data.");
402 hitData.subdetector, hitData.layer);
403 extHitLayer[layer - 1]++;
404 hitData.localPosition = localPosition.z();
406 hitData.section, hitData.sector, hitData.layer,
408 addHit(selectedHits, planeGlobal, &hitData);
412 hitData.strip = module->getPhiStrip(localPosition);
415 hitData.section, hitData.sector, hitData.layer, hitData.plane,
416 hitData.strip,
false)) {
418 hitData.section, hitData.sector, hitData.layer,
419 hitData.plane, hitData.strip);
422 B2FATAL(
"Incomplete KLM channel status data.");
425 hitData.subdetector, hitData.layer);
426 extHitLayer[layer - 1]++;
427 hitData.localPosition = localPosition.y();
429 hitData.section, hitData.sector, hitData.layer,
431 addHit(selectedHits, planeGlobal, &hitData);
440 std::map<int, int>::iterator it2;
441 for (it = selectedHits.begin(); it != selectedHits.end(); ++it) {
443 if (it->second.digit !=
nullptr) {
446 it->second.subdetector, it->second.layer);
447 digitLayer[layer - 1]++;
453 for (it = selectedHits.begin(); it != selectedHits.end(); ++it) {
454 int matchingDigits = 0;
455 int matchingDigitsOuterLayers = 0;
456 int extHitsOuterLayers = 0;
458 it->second.subdetector, it->second.layer) - 1;
459 for (
int i = 0; i < nExtrapolationLayers; ++i) {
461 matchingDigits += digitLayer[i];
463 matchingDigitsOuterLayers += digitLayer[i];
464 extHitsOuterLayers += extHitLayer[i];
494 allExtHitsEKLM->Fill(planeNum);
495 allExtHitsEKLMSec->Fill(sectorNum);
496 if (it->second.digit) {
497 matchedHitsEKLM->Fill(planeNum);
498 matchedHitsEKLMSec->Fill(sectorNum);
505 it->second.section, it->second.sector, it->second.layer);
507 allExtHitsBKLM->Fill(layerGlobal);
508 allExtHitsBKLMSec->Fill(sectorGlobal);
509 if (it->second.digit) {
510 matchedHitsBKLM->Fill(layerGlobal);
511 matchedHitsBKLMSec->Fill(sectorGlobal);
514 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).
Additional Module for KLMDQM plots after HLT filters.
TH1F * m_MatchedHitsBKLMSector
Matched hits in sector for BKLM.
TH1F * m_MatchedHitsEKLM
Matched hits in plane for EKLM.
virtual void endRun() override
Called if the current run ends.
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.
virtual void terminate() override
Called at the end of the event processing.
TH1F * m_AllExtHitsBKLMSector
Extrapolated hits in sector for BKLM.
double m_MinimalMomentumNoOuterLayers
Minimal momentum in case there are no hits in outer layers.
const KLMElementNumbers * m_ElementNumbers
KLM element numbers.
const EKLMElementNumbers * m_eklmElementNumbers
Element numbers.
void findMatchingDigit(struct HitData *hitData)
Find matching digit.
TH1F * m_AllExtHitsEKLMSector
Extrapolated hits in sector for EKLM.
TH1F * m_MatchedHitsBKLM
Matched hits in plane for BKLM.
virtual void event() override
Selection for mumu_tight_skim, then DQM plot filling
StoreObjPtr< ParticleList > m_MuonList
Muons.
virtual void initialize() override
Register input and output data.
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.
virtual void beginRun() override
Called when entering a new run.
~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.
Class to store reconstructed particles.
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.
#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.