From 73fea7d02e922806a4bc2d327c93ee9d5b1ff9d8 Mon Sep 17 00:00:00 2001 From: Thomas Schuh Date: Mon, 20 Apr 2020 14:43:17 +0100 Subject: [PATCH 1/2] DTC debugged, Lost stubs product added, Analyzer to study DTC performance added. --- L1Trigger/TrackerDTC/BuildFile.xml | 14 +- L1Trigger/TrackerDTC/interface/DTC.h | 22 +- L1Trigger/TrackerDTC/interface/Module.h | 21 +- L1Trigger/TrackerDTC/interface/Settings.h | 148 ++++- .../TrackerDTC/interface/SettingsHybrid.h | 34 +- L1Trigger/TrackerDTC/interface/SettingsTMTT.h | 2 +- L1Trigger/TrackerDTC/interface/Stub.h | 6 +- .../TrackerDTC/interface/TTDTCConverter.h | 15 +- L1Trigger/TrackerDTC/plugins/Analyzer.cc | 508 ++++++++++++++++++ L1Trigger/TrackerDTC/plugins/BuildFile.xml | 7 +- L1Trigger/TrackerDTC/plugins/Producer.cc | 94 +--- .../python/Analyzer_Customize_cff.py | 10 + .../python/Analyzer_Defaults_cfi.py | 29 + L1Trigger/TrackerDTC/python/Analyzer_cff.py | 7 + .../TrackerDTC/python/Format_Hybrid_cfi.py | 14 +- .../python/Producer_Customize_cff.py | 6 +- .../python/Producer_Defaults_cfi.py | 9 +- L1Trigger/TrackerDTC/python/Producer_cff.py | 3 +- L1Trigger/TrackerDTC/src/DTC.cc | 150 +++--- L1Trigger/TrackerDTC/src/Module.cc | 40 +- L1Trigger/TrackerDTC/src/Settings.cc | 76 ++- L1Trigger/TrackerDTC/src/SettingsHybrid.cc | 37 +- L1Trigger/TrackerDTC/src/Stub.cc | 14 +- L1Trigger/TrackerDTC/test/test_cfg.py | 99 ++-- 24 files changed, 1011 insertions(+), 354 deletions(-) create mode 100644 L1Trigger/TrackerDTC/plugins/Analyzer.cc create mode 100644 L1Trigger/TrackerDTC/python/Analyzer_Customize_cff.py create mode 100644 L1Trigger/TrackerDTC/python/Analyzer_Defaults_cfi.py create mode 100644 L1Trigger/TrackerDTC/python/Analyzer_cff.py diff --git a/L1Trigger/TrackerDTC/BuildFile.xml b/L1Trigger/TrackerDTC/BuildFile.xml index 371b3e95dad5b..44fcee99a80e4 100644 --- a/L1Trigger/TrackerDTC/BuildFile.xml +++ b/L1Trigger/TrackerDTC/BuildFile.xml @@ -1,16 +1,4 @@ - - - - - - - - - - - - - + diff --git a/L1Trigger/TrackerDTC/interface/DTC.h b/L1Trigger/TrackerDTC/interface/DTC.h index aa4a0a4fb8795..f49ad66708e28 100644 --- a/L1Trigger/TrackerDTC/interface/DTC.h +++ b/L1Trigger/TrackerDTC/interface/DTC.h @@ -21,25 +21,35 @@ namespace trackerDTC { typedef std::vector Stubsss; public: - DTC(Settings* settings, int nStubs); + DTC(Settings* settings, int dtcId, const std::vector>& modules); ~DTC() {} - // convert and assign TTStubRef to DTC routing block channel - void consume(const std::vector& ttStubRefStream, Module* module); - // board level routing in two steps and product filling - void produce(TTDTC& product, int dtcId); + // board level routing in two steps and products filling + void produce(TTDTC& accepted, TTDTC& lost); private: // router step 1: merges stubs of all modules connected to one routing block into one stream - void merge(Stubss& inputs, Stubs& output); + void merge(Stubss& inputs, Stubs& output, Stubs& lost); // router step 2: merges stubs of all routing blocks and splits stubs into one stream per overlapping region void split(Stubss& inputs, Stubss& outputs); + // conversion from Stubss to TTDTC + void produce(const Stubss& stubss, TTDTC& product); // pop_front function which additionally returns copy of deleted front Stub* pop_front(Stubs& stubs); // helper class to store configurations Settings* settings_; + // outer tracker detector region [0-8] + int region_; + // outer tracker dtc id in region [0-23] + int board_; + // container of modules connected to this DTC + std::vector modules_; // container of stubs on this DTC std::vector stubs_; + // input stubs organised in routing blocks [0..1] and channel [0..35] + Stubsss input_; + // lost stubs organised in dtc output channel [0..1] + Stubss lost_; }; } // namespace trackerDTC diff --git a/L1Trigger/TrackerDTC/interface/Module.h b/L1Trigger/TrackerDTC/interface/Module.h index 0caa1c217e8da..3a2de190cfbc4 100644 --- a/L1Trigger/TrackerDTC/interface/Module.h +++ b/L1Trigger/TrackerDTC/interface/Module.h @@ -3,37 +3,28 @@ #include "DataFormats/DetId/interface/DetId.h" #include "DataFormats/Math/interface/deltaPhi.h" -#include "L1Trigger/TrackerDTC/interface/Settings.h" +#include "L1Trigger/TrackerDTC/interface/SettingsHybrid.h" #include namespace trackerDTC { + class Settings; + // representation of an outer tracker sensormodule class Module { friend class Stub; public: - Module(Settings* settings, const ::DetId& detId, int modId); + Module(Settings* settings, const ::DetId& detId, int dtcId); ~Module() {} - // track trigger dtc id [0-215] - int dtcId() const { return dtcId_; } - // DTC module id [0-71] - int dtcChannelId() const { return dtcChannelId_; } - private: // handles 2 pi overflow double deltaPhi(double phi) { return reco::deltaPhi(phi, 0.); } - // track trigger dtc id [0-215] - int dtcId_; - // DTC module id [0-71] - int dtcChannelId_; - // outer tracker dtc routing block id [0-1] - int blockId_; - // routing block channel id [0-35] - int blockChannelId_; + // detector region [0-8] + int region_; // +z or -z bool side_; // barrel or endcap diff --git a/L1Trigger/TrackerDTC/interface/Settings.h b/L1Trigger/TrackerDTC/interface/Settings.h index e0de7e6fbf071..8d413477b8293 100644 --- a/L1Trigger/TrackerDTC/interface/Settings.h +++ b/L1Trigger/TrackerDTC/interface/Settings.h @@ -13,16 +13,17 @@ #include "CondFormats/SiPhase2TrackerObjects/interface/TrackerDetToDTCELinkCablingMap.h" #include "DetectorDescription/Core/interface/DDCompactView.h" #include "L1Trigger/TrackTrigger/interface/TTStubAlgorithm.h" + #include "L1Trigger/TrackerDTC/interface/SettingsHybrid.h" #include "L1Trigger/TrackerDTC/interface/SettingsTMTT.h" +#include "L1Trigger/TrackerDTC/interface/Module.h" #include #include +#include namespace trackerDTC { - class Module; - // stores, calculates and provides run-time constants class Settings { friend class SettingsHybrid; @@ -51,11 +52,7 @@ namespace trackerDTC { void setProcessHistory(const edm::ProcessHistory& processHistory); // check current coniguration consistency with input configuration void checkConfiguration(); - // convert cabling map - void convertCablingMap(); - // store converted tracker geometry - void setModules(std::vector& modules); - // convert data fromat specific stuff + // convert ES Products into handy objects void beginRun(); // convert DetId to module id [0:15551] int modId(const ::DetId& detId) const; @@ -64,88 +61,173 @@ namespace trackerDTC { // ED parameter - edm::InputTag inputTagTTStubDetSetVec() const { return inputTagTTStubDetSetVec_; } - edm::ESInputTag inputTagMagneticField() const { return inputTagMagneticField_; } - edm::ESInputTag inputTagTrackerGeometry() const { return inputTagTrackerGeometry_; } - edm::ESInputTag inputTagTrackerTopology() const { return inputTagTrackerTopology_; } - edm::ESInputTag inputTagCablingMap() const { return inputTagCablingMap_; } - edm::ESInputTag inputTagTTStubAlgorithm() const { return inputTagTTStubAlgorithm_; } - edm::ESInputTag inputTagGeometryConfiguration() const { return inputTagGeometryConfiguration_; } - std::string productBranch() const { return productBranch_; } - std::string dataFormat() const { return dataFormat_; } + const edm::InputTag& inputTagTTStubDetSetVec() const { return inputTagTTStubDetSetVec_; } + const edm::ESInputTag& inputTagMagneticField() const { return inputTagMagneticField_; } + const edm::ESInputTag& inputTagTrackerGeometry() const { return inputTagTrackerGeometry_; } + const edm::ESInputTag& inputTagTrackerTopology() const { return inputTagTrackerTopology_; } + const edm::ESInputTag& inputTagCablingMap() const { return inputTagCablingMap_; } + const edm::ESInputTag& inputTagTTStubAlgorithm() const { return inputTagTTStubAlgorithm_; } + const edm::ESInputTag& inputTagGeometryConfiguration() const { return inputTagGeometryConfiguration_; } + const std::string& productBranchAccepted() const { return productBranchAccepted_; } + const std::string& productBranchLost() const { return productBranchLost_; } + const std::string& dataFormat() const { return dataFormat_; } + // tk layout det id minus DetSetVec->detId int offsetDetIdDSV() const { return offsetDetIdDSV_; } + // tk layout det id minus TrackerTopology lower det id int offsetDetIdTP() const { return offsetDetIdTP_; } + // hybrid format specific configurations SettingsHybrid* hybrid() const { return hybrid_.get(); } + // tmtt format specific configurations SettingsTMTT* tmtt() const { return tmtt_.get(); } + // offset in layer ids between barrel layer and endcap disks int offsetLayerDisks() const { return offsetLayerDisks_; } + // offset between 0 and smallest layer id (barrel layer 1) int offsetLayerId() const { return offsetLayerId_; } // Router parameter + // enables emulation of truncation bool enableTruncation() const { return enableTruncation_; } + // time multiplexed period of track finding processor int tmpTFP() const { return tmpTFP_; } + // needed gap between events of emp-infrastructure firmware int numFramesInfra() const { return numFramesInfra_; } + // number of systiloic arrays in stub router firmware int numRoutingBlocks() const { return numRoutingBlocks_; } + // fifo depth in stub router firmware int sizeStack() const { return sizeStack_; } // Converter parameter + // number of row bits used in look up table int widthRowLUT() const { return widthRowLUT_; } + // number of bits used for stub qOverPt. lut addr is col + bend = 11 => 1 BRAM -> 18 bits for min and max val -> 9 int widthQoverPt() const { return widthQoverPt_; } // Tracker parameter + // number of regions a reconstructable particles may cross int numOverlappingRegions() const { return numOverlappingRegions_; } + // number of phi slices the outer tracker readout is organized in int numRegions() const { return numRegions_; } + // number of DTC boards used to readout a detector region int numDTCsPerRegion() const { return numDTCsPerRegion_; } + // max number of sensor modules connected to one DTC board int numModulesPerDTC() const { return numModulesPerDTC_; } + // number of bits used for internal stub bend int widthBend() const { return widthBend_; } + // number of bits used for internal stub column int widthCol() const { return widthCol_; } + // number of bits used for internal stub row int widthRow() const { return widthRow_; } + // precision of internal stub bend in pitch units double baseBend() const { return baseBend_; } + // precision of internal stub column in pitch units double baseCol() const { return baseCol_; } + // precision of internal stub row in pitch units double baseRow() const { return baseRow_; } + // used stub bend uncertainty in pitch units double bendCut() const { return bendCut_; } + // LHC bunch crossing rate in MHz double freqLHC() const { return freqLHC_; } // format specific router parameter + // cut on stub eta double maxEta() const { return maxEta_; } + // cut on stub pt, also defines region overlap shape in GeV double minPt() const { return minPt_; } + // critical radius defining region overlap shape in cm double chosenRofPhi() const { return chosenRofPhi_; } + // tmtt: number of detector layers a reconstructbale particle may cross + // hybrid: max number of detector layer connected to one DTC int numLayers() const { return numLayers_; } // f/w parameter + // magnetic field f/w value in T double bField() const { return bField_; } + // Analzyer + + // open and analyze TrackingParticles, original TTStubs and Association between them + bool useMCTruth() const { return useMCTruth_; } + // tag of AssociationMap between TTCluster and TrackingParticles + const edm::InputTag& inputTagTTClusterAssMap() const { return inputTagTTClusterAssMap_; } + // label of DTC producer + const std::string& producerLabel() const { return producerLabel_; } + + // TP + + // pt cut in GeV + double tpMinPt() const { return tpMinPt_; } + // eta cut + double tpMaxEta() const { return tpMaxEta_; } + // cut on vertex pos r in cm + double tpMaxVertR() const { return tpMaxVertR_; } + // cut on vertex pos z in cm + double tpMaxVertZ() const { return tpMaxVertZ_; } + // cut on impact parameter in cm + double tpMaxD0() const { return tpMaxD0_; } + // required number of associated layers to a TP to consider it reconstruct-able + int tpMinLayers() const { return tpMinLayers_; } + // required number of associated ps layers to a TP to consider it reconstruct-able + int tpMinLayersPS() const { return tpMinLayersPS_; } + // derived Router parameter + // total number of outer tracker DTCs int numDTCs() const { return numDTCs_; } + // number of DTCs connected to one TFP (48) + int numDTCsPerTFP() const { return numDTCsPerTFP_; } + // total number of max possible outer tracker modules (72 per DTC) int numModules() const { return numModules_; } + // number of inputs per systolic arrays in dtc firmware int numModulesPerRoutingBlock() const { return numModulesPerRoutingBlock_; } + // max number of incomming stubs per packet (emp limit not cic limit) int maxFramesChannelInput() const { return maxFramesChannelInput_; } + // max number out outgoing stubs per packet int maxFramesChannelOutput() const { return maxFramesChannelOutput_; } // derived Converter parameter + // number of bits used for internal stub r - ChosenRofPhi int widthR() const { return widthR_; } + // number of bits used for internal stub phi w.r.t. region centre int widthPhi() const { return widthPhi_; } + // number of bits used for internal stub z int widthZ() const { return widthZ_; } + // number of merged rows for look up int numMergedRows() const { return numMergedRows_; } + // number of bits used for stub layer id int widthLayer() const { return widthLayer_; } + // number of bits used for phi of row slope int widthM() const { return widthM_; } + // number of bits used for phi or row intercept int widthC() const { return widthC_; } + // number of bits used for internal stub eta int widthEta() const { return widthEta_; } + // converts GeV in 1/cm + double invPtToDphi() const { return invPtToDphi_; } + // range of internal stub q over pt double rangeQoverPt() const { return rangeQoverPt_; } + // cut on stub cot double maxCot() const { return maxCot_; } + // cut on stub q over pt double maxQoverPt() const { return maxQoverPt_; } + // region size in rad double baseRegion() const { return baseRegion_; } + // internal stub q over pt precision in 1 /cm double baseQoverPt() const { return baseQoverPt_; } + // internal stub r precision in cm double baseR() const { return baseR_; } + // internal stub z precision in cm double baseZ() const { return baseZ_; } + // internal stub phi precision in rad double basePhi() const { return basePhi_; } + // phi of row slope precision in rad / pitch unit double baseM() const { return baseM_; } + // phi of row intercept precision in rad double baseC() const { return baseC_; } // event setup @@ -155,7 +237,7 @@ namespace trackerDTC { // derived event setup - const std::vector<::DetId>& cablingMap() const { return cablingMap_; } + // check if TrackerGeometry is supported bool configurationSupported() const { return configurationSupported_; } private: @@ -172,7 +254,8 @@ namespace trackerDTC { const edm::ParameterSet paramsTracker_; const edm::ParameterSet paramsFW_; const edm::ParameterSet paramsFormat_; - + const edm::ParameterSet paramsAnalyzer_; + const edm::ParameterSet paramsTP_; // ED parameter const edm::InputTag inputTagTTStubDetSetVec_; @@ -186,7 +269,8 @@ namespace trackerDTC { const std::string supportedTrackerXMLPath_; const std::string supportedTrackerXMLFile_; const std::vector supportedTrackerXMLVersions_; - const std::string productBranch_; + const std::string productBranchAccepted_; + const std::string productBranchLost_; // "Hybrid" and "TMTT" format supported const std::string dataFormat_; // tk layout det id minus DetSetVec->detId @@ -278,10 +362,28 @@ namespace trackerDTC { // max number of detector layer connected to one DTC (hybrid) number of detector layers a reconstructbale particle may cross (tmtt) const int numLayers_; + // Analzyer + + const bool useMCTruth_; + const edm::InputTag inputTagTTClusterAssMap_; + const std::string producerLabel_; + + // TP + + const double tpMinPt_; + const double tpMaxEta_; + const double tpMaxVertR_; + const double tpMaxVertZ_; + const double tpMaxD0_; + const int tpMinLayers_; + const int tpMinLayersPS_; + // derived router parameter // total number of outer tracker DTCs int numDTCs_; + // number of DTCs connected to one TFP (48) + int numDTCsPerTFP_; // total number of max possible outer tracker modules (72 per DTC) int numModules_; // number of inputs per systolic arrays in dtc firmware @@ -309,6 +411,8 @@ namespace trackerDTC { int widthC_; // number of bits used for internal stub eta int widthEta_; + // converts GeV in 1/cm + double invPtToDphi_; // range of internal stub q over pt double rangeQoverPt_; // cut on stub cot @@ -342,8 +446,10 @@ namespace trackerDTC { // derived event setup - // index = track trigger module id [0-15551], value = det id - std::vector<::DetId> cablingMap_; + // value = track trigger module id [0-15551], key = det id + std::unordered_map<::DetId, int> cablingMap_; + // collection of outer tracker sensor modules + std::vector modules_; // collection of outer tracker sensor modules organised in DTCS [0-215][0-71] std::vector> dtcModules_; // true if tracker geometry and bfield is supported diff --git a/L1Trigger/TrackerDTC/interface/SettingsHybrid.h b/L1Trigger/TrackerDTC/interface/SettingsHybrid.h index 51af6035395af..166b60f63c1ce 100644 --- a/L1Trigger/TrackerDTC/interface/SettingsHybrid.h +++ b/L1Trigger/TrackerDTC/interface/SettingsHybrid.h @@ -36,9 +36,9 @@ namespace trackerDTC { int widthZ(SensorType type) const { return widthsZ_[type]; } int widthAlpha(SensorType type) const { return widthsAlpha_[type]; } int widthBend(SensorType type) const { return widthsBend_[type]; } - std::vector numRingsPS() const { return numRingsPS_; } - std::vector layerRs() const { return layerRs_; } - std::vector diskZs() const { return diskZs_; } + const std::vector& numRingsPS() const { return numRingsPS_; } + const std::vector& layerRs() const { return layerRs_; } + const std::vector& diskZs() const { return diskZs_; } // derived format specific parameter @@ -50,16 +50,16 @@ namespace trackerDTC { // derived TTStubalgo parameter - std::vector numTiltedLayerRings() const { return numTiltedLayerRings_; } - std::vector windowSizeBarrelLayers() const { return windowSizeBarrelLayers_; } - std::vector > windowSizeTiltedLayerRings() const { return windowSizeTiltedLayerRings_; } - std::vector > windowSizeEndcapDisksRings() const { return windowSizeEndcapDisksRings_; } + const std::vector& numTiltedLayerRings() const { return numTiltedLayerRings_; } + const std::vector& windowSizeBarrelLayers() const { return windowSizeBarrelLayers_; } + const std::vector>& windowSizeTiltedLayerRings() const { return windowSizeTiltedLayerRings_; } + const std::vector>& windowSizeEndcapDisksRings() const { return windowSizeEndcapDisksRings_; } // Hybrid specific encodings - std::vector > layerIdEncodings() const { return layerIdEncodings_; } - std::vector > bendEncodingsPS() const { return bendEncodingsPS_; } - std::vector > bendEncodings2S() const { return bendEncodings2S_; } + const std::vector>& layerIdEncodings() const { return layerIdEncodings_; } + const std::vector>& bendEncodingsPS() const { return bendEncodingsPS_; } + const std::vector>& bendEncodings2S() const { return bendEncodings2S_; } double disk2SR(int disk, int index) const { return disk2SRs_.at(disk).at(index); } private: @@ -119,25 +119,25 @@ namespace trackerDTC { // number of padded 0s in output data format for (barrelPS, barrel2S, diskPS, disk2S) std::vector numsUnusedBits_; // center radius of outer tracker endcap 2S diks strips - std::vector > disk2SRs_; + std::vector> disk2SRs_; // derived TTStubalgo parameter std::vector numTiltedLayerRings_; std::vector windowSizeBarrelLayers_; - std::vector > windowSizeTiltedLayerRings_; - std::vector > windowSizeEndcapDisksRings_; + std::vector> windowSizeTiltedLayerRings_; + std::vector> windowSizeEndcapDisksRings_; // Hybrid specific encodings // outer index = dtc id, inner index = encoded layer id, value = decoded layer id - std::vector > layerIdEncodings_; + std::vector> layerIdEncodings_; // outer index = max window size in half strip units, inner index = decoded bend, value = encoded bend for PS modules - std::vector > bendEncodingsPS_; + std::vector> bendEncodingsPS_; // outer index = max window size in half strip units, inner index = decoded bend, value = encoded bend for 2S modules - std::vector > bendEncodings2S_; + std::vector> bendEncodings2S_; }; } // namespace trackerDTC -#endif +#endif \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/interface/SettingsTMTT.h b/L1Trigger/TrackerDTC/interface/SettingsTMTT.h index 9d097e148c549..3f677750ccaf6 100644 --- a/L1Trigger/TrackerDTC/interface/SettingsTMTT.h +++ b/L1Trigger/TrackerDTC/interface/SettingsTMTT.h @@ -75,4 +75,4 @@ namespace trackerDTC { } // namespace trackerDTC -#endif +#endif \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/interface/Stub.h b/L1Trigger/TrackerDTC/interface/Stub.h index 384b3c0fccac1..7fab1217a277d 100644 --- a/L1Trigger/TrackerDTC/interface/Stub.h +++ b/L1Trigger/TrackerDTC/interface/Stub.h @@ -24,14 +24,12 @@ namespace trackerDTC { bool valid() const { return valid_; } // stub bend in quarter pitch units int bend() const { return bend_; } - // outer tracker dtc routing block id [0-1] - int blockId() const; - // outer tracker dtc routing block channel id [0-35] - int channelId() const; // bit accurate representation of Stub TTDTC::BV frame(int region) const; // checks stubs region assignment bool inRegion(int region) const; + double r() const { return r_; } + double phi() const { return phi_; } private: // truncates double precision to f/w integer equivalent diff --git a/L1Trigger/TrackerDTC/interface/TTDTCConverter.h b/L1Trigger/TrackerDTC/interface/TTDTCConverter.h index 1b622a71d2de5..fb16f212eefb9 100644 --- a/L1Trigger/TrackerDTC/interface/TTDTCConverter.h +++ b/L1Trigger/TrackerDTC/interface/TTDTCConverter.h @@ -31,10 +31,12 @@ GlobalPoint TTDTCConverter(trackerDTC::Settings* settings, const TTDTC::Frame& f const std::vector& diskZs = format->diskZs(); const std::vector& layerRs = format->layerRs(); - const DetId detId = frame.first->getDetId(); + const DetId detId(frame.first->getDetId() + settings->offsetDetIdDSV()); const bool barrel = detId.subdetId() == StripSubdetector::TOB; const bool psModule = trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP; const int layerId = barrel ? trackerTopology->layer(detId) : trackerTopology->tidWheel(detId) + 10; + const GeomDetUnit* det = trackerGeometry->idToDetUnit(detId); + const bool side = det->position().z() >= 0.; trackerDTC::SettingsHybrid::SensorType type; if (barrel && psModule) @@ -52,16 +54,19 @@ GlobalPoint TTDTCConverter(trackerDTC::Settings* settings, const TTDTC::Frame& f bv >>= format->widthPhi(type); double z = (bv.val(format->widthZ(type), 0, true) + .5) * format->baseZ(type); bv >>= format->widthZ(type); - double r = (bv.val(format->widthR(type), 0, true) + .5) * format->baseR(type); + double r = (bv.val(format->widthR(type), 0, barrel) + .5) * format->baseR(type); - r += barrel ? layerRs.at(layerId - 1) : 0.; - z += barrel ? 0. : diskZs.at(layerId - 11); + if (barrel) { + r += layerRs.at(layerId - settings->offsetLayerId()); + } else { + z += diskZs.at(layerId - settings->offsetLayerId() - settings->offsetLayerDisks()) * (side ? 1. : -1.); + } phi = reco::deltaPhi(phi + region * settings->baseRegion(), 0.); if (type == trackerDTC::SettingsHybrid::disk2S) { r = bv.val(format->widthR(type)); - r = format->disk2SR(layerId - 11, (int)r); + r = format->disk2SR(layerId - settings->offsetLayerId() - settings->offsetLayerDisks(), (int)r); } p = GlobalPoint(GlobalPoint::Cylindrical(r, phi, z)); diff --git a/L1Trigger/TrackerDTC/plugins/Analyzer.cc b/L1Trigger/TrackerDTC/plugins/Analyzer.cc new file mode 100644 index 0000000000000..711f08b3ef887 --- /dev/null +++ b/L1Trigger/TrackerDTC/plugins/Analyzer.cc @@ -0,0 +1,508 @@ +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/GenericHandle.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ServiceRegistry/interface/Service.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/EDGetToken.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "FWCore/Utilities/interface/Exception.h" +#include "CommonTools/UtilAlgos/interface/TFileService.h" +#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h" +#include "Geometry/Records/interface/TrackerTopologyRcd.h" +#include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" +#include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h" +#include "Geometry/CommonTopologies/interface/PixelTopology.h" +#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" +#include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" +#include "SimTracker/Common/interface/TrackingParticleSelector.h" +#include "DataFormats/TrackerCommon/interface/TrackerTopology.h" +#include "DataFormats/DetId/interface/DetId.h" +#include "DataFormats/Math/interface/deltaPhi.h" +#include "DataFormats/Common/interface/Ptr.h" +#include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +#include "DataFormats/L1TrackTrigger/interface/TTDTC.h" +#include "DataFormats/GeometryVector/interface/GlobalPoint.h" +#include "DataFormats/GeometrySurface/interface/Plane.h" +#include "DataFormats/SiStripDetId/interface/StripSubdetector.h" + +#include "L1Trigger/TrackerDTC/interface/Settings.h" +#include "L1Trigger/TrackerDTC/interface/TTDTCConverter.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace edm; + +namespace trackerDTC { + + // mc truth types + typedef TTClusterAssociationMap TTClusterAssMap; + typedef edm::Ptr TPPtr; + // stub resolution plots helper + enum Resolution { R, Phi, Z, NumResolution }; + constexpr initializer_list AllResolution = {R, Phi, Z}; + constexpr auto NameResolution = {"R", "Phi", "Z"}; + inline string name(Resolution r) { return string(*(NameResolution.begin() + r)); } + // max tracking efficiency plots helper + enum Efficiency { Phi0, Pt, InvPt, D0, Z0, Eta, NumEfficiency }; + constexpr initializer_list AllEfficiency = {Phi0, Pt, InvPt, D0, Z0, Eta}; + constexpr auto NameEfficiency = {"Phi0", "Pt", "InvPt", "D0", "Z0", "Eta"}; + inline string name(Efficiency e) { return string(*(NameEfficiency.begin() + e)); } + + /*! \class trackerDTC::Analyzer + * \brief Class to analyze hardware like structured TTStub Collection used by Track Trigger emulators + * \author Thomas Schuh + * \date 2020, Apr + */ + class Analyzer : public one::EDAnalyzer { + public: + Analyzer(const ParameterSet& iConfig); + void beginJob() override {} + void beginRun(const Run& iEvent, const EventSetup& iSetup) override; + void analyze(const Event& iEvent, const EventSetup& iSetup) override; + void endRun(const Run& iEvent, const EventSetup& iSetup) override {} + void endJob() override; + + private: + // associate TPPtr with TTStubRef + void assoc(const Handle&, const Handle&, map>&); + // organize reconstrucable TrackingParticles used for efficiency measurements + void convert(const map>&, map>&); + // checks if a stub selection is considered reconstructable + bool reconstructable(const set& ttStubRefs) const; + // checks if TrackingParticle is selected for efficiency measurements + bool select(const TrackingParticle& tp) const; + // fills kinematic tp histograms + void fill(const TPPtr& tpPtr, const vector th1fs) const; + // analyze DTC products and find still reconstrucable TrackingParticles + void analyzeStubs(const TTDTC*, const TTDTC*, const map>&, map>&); + // fill stub related histograms + void analyzeStream(const TTDTC::Stream& stream, int region, int& sum, TH2F* th2f); + // returns global stub position + GlobalPoint stubPos(const TTStubRef& ttStubRef) const; + // handles 2 pi overflow + double deltaPhi(double lhs, double rhs = 0.) { return reco::deltaPhi(lhs, rhs); } + // analyze survived TPs + void analyzeTPs(const map>& mapTPsStubs); + // prints out MC summary + void endJobMC(); + // prints out DTC summary + void endJobDTC(); + + // ed input tokens + + EDGetTokenT getTokenTTDTCAccepted_; + EDGetTokenT getTokenTTDTCLost_; + EDGetTokenT getTokenTTStubDetSetVec_; + EDGetTokenT getTokenTTClusterAssMap_; + + // es input tokens + + ESGetToken getTokenTrackerGeometry_; + ESGetToken getTokenTrackerTopology_; + + // stores, calculates and provides run-time constants + Settings settings_; + // selector to partly select TPs for efficiency measurements + TrackingParticleSelector tpSelector_; + + // Histograms + + TProfile* profMC_; + TProfile* profDTC_; + TProfile* profChannel_; + TH1F* hisChannel_; + TH2F* hisRZStubs_; + TH2F* hisRZStubsLost_; + TH2F* hisRZStubsEff_; + vector hisResolution_; + vector profResolution_; + vector hisEff_; + vector hisEffMC_; + vector eff_; + + // printout + stringstream log_; + }; + + Analyzer::Analyzer(const ParameterSet& iConfig) : settings_(iConfig) { + usesResource("TFileService"); + // book in- and output ED products + getTokenTTDTCAccepted_ = consumes(InputTag(settings_.producerLabel(), settings_.productBranchAccepted())); + getTokenTTDTCLost_ = consumes(InputTag(settings_.producerLabel(), settings_.productBranchLost())); + if (settings_.useMCTruth()) { + getTokenTTStubDetSetVec_ = consumes(settings_.inputTagTTStubDetSetVec()); + getTokenTTClusterAssMap_ = consumes(settings_.inputTagTTClusterAssMap()); + } + // book ES products + getTokenTrackerGeometry_ = esConsumes( + settings_.inputTagTrackerGeometry()); + getTokenTrackerTopology_ = + esConsumes(settings_.inputTagTrackerTopology()); + // configuring track particle selector + const double ptMin = settings_.tpMinPt(); + constexpr double ptMax = 9999999999.; + const double etaMax = settings_.tpMaxEta(); + const double tip = settings_.tpMaxVertR(); + const double lip = settings_.tpMaxVertZ(); + constexpr int minHit = 0; + constexpr bool signalOnly = true; + constexpr bool intimeOnly = true; + constexpr bool chargedOnly = true; + constexpr bool stableOnly = false; + tpSelector_ = TrackingParticleSelector( + ptMin, ptMax, -etaMax, etaMax, tip, lip, minHit, signalOnly, intimeOnly, chargedOnly, stableOnly); + // book histograms + Service fs; + TFileDirectory dir; + // mc + dir = fs->mkdir("MC"); + profMC_ = dir.make("Counts", ";", 4, 0.5, 4.5); + profMC_->GetXaxis()->SetBinLabel(1, "Stubs"); + profMC_->GetXaxis()->SetBinLabel(2, "Matched Stubs"); + profMC_->GetXaxis()->SetBinLabel(3, "reco TPs"); + profMC_->GetXaxis()->SetBinLabel(4, "eff TPs"); + constexpr array binsEff{{9 * 8, 10, 16, 10, 30, 24}}; + constexpr array, NumEfficiency> rangesEff{ + {{-M_PI, M_PI}, {0., 100.}, {-1. / 3., 1. / 3.}, {-5., 5.}, {-15., 15.}, {-2.4, 2.4}}}; + if (settings_.useMCTruth()) { + hisEffMC_.reserve(NumEfficiency); + for (Efficiency e : AllEfficiency) + hisEffMC_.emplace_back( + dir.make(("HisTP" + name(e)).c_str(), ";", binsEff[e], rangesEff[e].first, rangesEff[e].second)); + } + // dtc + dir = fs->mkdir("DTC"); + profDTC_ = dir.make("Counts", ";", 3, 0.5, 3.5); + profDTC_->GetXaxis()->SetBinLabel(1, "Stubs"); + profDTC_->GetXaxis()->SetBinLabel(2, "Lost Stubs"); + profDTC_->GetXaxis()->SetBinLabel(3, "TPs"); + // channel occupancy + constexpr int maxOcc = 180; + const int numChannels = settings_.numDTCs(); + hisChannel_ = dir.make("Channel Occupancy", ";", maxOcc, -.5, maxOcc - .5); + profChannel_ = dir.make("Channel Occupancy", ";", numChannels, -.5, numChannels - .5); + // max tracking efficiencies + if (settings_.useMCTruth()) { + hisEff_.reserve(NumEfficiency); + for (Efficiency e : AllEfficiency) + hisEff_.emplace_back( + dir.make(("HisTP" + name(e)).c_str(), ";", binsEff[e], rangesEff[e].first, rangesEff[e].second)); + dir = fs->mkdir("DTC/Effi"); + eff_.reserve(NumEfficiency); + for (Efficiency e : AllEfficiency) + eff_.emplace_back( + dir.make(("Eff" + name(e)).c_str(), ";", binsEff[e], rangesEff[e].first, rangesEff[e].second)); + } + // lost stub fraction in r-z + dir = fs->mkdir("DTC/Loss"); + constexpr int bins = 400; + constexpr double maxZ = 300.; + constexpr double maxR = 120.; + hisRZStubs_ = dir.make("RZ Stubs", ";;", bins, -maxZ, maxZ, bins, 0., maxR); + hisRZStubsLost_ = dir.make("RZ Stubs Lost", ";;", bins, -maxZ, maxZ, bins, 0., maxR); + hisRZStubsEff_ = dir.make("RZ Stubs Eff", ";;", bins, -maxZ, maxZ, bins, 0., maxR); + // stub parameter resolutions + dir = fs->mkdir("DTC/Res"); + constexpr array ranges{{.2, .0001, .5}}; + constexpr int binsHis = 100; + hisResolution_.reserve(NumResolution); + profResolution_.reserve(NumResolution); + for (Resolution r : AllResolution) { + hisResolution_.emplace_back(dir.make(("HisRes" + name(r)).c_str(), ";", binsHis, -ranges[r], ranges[r])); + profResolution_.emplace_back( + dir.make(("ProfRes" + name(r)).c_str(), ";;", bins, -maxZ, maxZ, bins, 0., maxR)); + } + // log config + log_.setf(ios::fixed, ios::floatfield); + log_.precision(4); + } + + void Analyzer::beginRun(const Run& iEvent, const EventSetup& iSetup) { + // read in detector parameter + settings_.setTrackerGeometry(&iSetup.getData(getTokenTrackerGeometry_)); + settings_.setTrackerTopology(&iSetup.getData(getTokenTrackerTopology_)); + } + + void Analyzer::analyze(const Event& iEvent, const EventSetup& iSetup) { + // read in TrackingParticle + map> mapAllStubsTPs; + if (settings_.useMCTruth()) { + Handle handleTTStubDetSetVec; + iEvent.getByToken(getTokenTTStubDetSetVec_, handleTTStubDetSetVec); + Handle handleTTClusterAssMap; + iEvent.getByToken(getTokenTTClusterAssMap_, handleTTClusterAssMap); + // associate TPPtr with TTStubRef + map> mapAllTPsAllStubs; + assoc(handleTTStubDetSetVec, handleTTClusterAssMap, mapAllTPsAllStubs); + // organize reconstrucable TrackingParticles used for efficiency measurements + convert(mapAllTPsAllStubs, mapAllStubsTPs); + } + // read in dtc products + Handle handleTTDTCAccepted; + iEvent.getByToken(getTokenTTDTCAccepted_, handleTTDTCAccepted); + Handle handleTTDTCLost; + iEvent.getByToken(getTokenTTDTCLost_, handleTTDTCLost); + map> mapTPsTTStubs; + // analyze DTC products and find still reconstrucable TrackingParticles + analyzeStubs(handleTTDTCAccepted.product(), handleTTDTCLost.product(), mapAllStubsTPs, mapTPsTTStubs); + // analyze survived TPs + analyzeTPs(mapTPsTTStubs); + } + + void Analyzer::endJob() { + // create r-z stub fraction plot + TH2F th2f("", ";;", 400, -300, 300., 400, 0., 120.); + th2f.Add(hisRZStubsLost_); + th2f.Add(hisRZStubs_); + hisRZStubsEff_->Add(hisRZStubsLost_); + hisRZStubsEff_->Divide(&th2f); + // create efficieny plots + if (settings_.useMCTruth()) { + for (Efficiency e : AllEfficiency) { + eff_[e]->SetPassedHistogram(*hisEff_[e], "f"); + eff_[e]->SetTotalHistogram(*hisEffMC_[e], "f"); + } + } + // printout MC summary + endJobMC(); + // printout DTC summary + endJobDTC(); + log_ << "=============================================================" << endl; + LogPrint("L1Trigger/TrackerDTC") << log_.str(); + } + + // associate TPPtr with TTStubRef + void Analyzer::assoc(const Handle& handleTTStubDetSetVec, + const Handle& handleTTClusterAssMap, + map>& mapTPsStubs) { + int nStubs(0); + int nStubsMatched(0); + for (TTStubDetSetVec::const_iterator ttModule = handleTTStubDetSetVec->begin(); + ttModule != handleTTStubDetSetVec->end(); + ttModule++) { + nStubs += ttModule->size(); + for (TTStubDetSet::const_iterator ttStub = ttModule->begin(); ttStub != ttModule->end(); ttStub++) { + set tpPtrs; + for (unsigned int iClus = 0; iClus < 2; iClus++) { + const vector& assocPtrs = handleTTClusterAssMap->findTrackingParticlePtrs(ttStub->clusterRef(iClus)); + copy_if(assocPtrs.begin(), assocPtrs.end(), inserter(tpPtrs, tpPtrs.begin()), [](const TPPtr& tpPtr) { + return tpPtr.isNonnull(); + }); + } + for (const TPPtr& tpPtr : tpPtrs) + mapTPsStubs[tpPtr].emplace(makeRefTo(handleTTStubDetSetVec, ttStub)); + if (!tpPtrs.empty()) + nStubsMatched++; + } + } + profMC_->Fill(1, nStubs / (double)settings_.numRegions()); + profMC_->Fill(2, nStubsMatched / (double)settings_.numRegions()); + } + + // organize reconstrucable TrackingParticles used for efficiency measurements + void Analyzer::convert(const map>& mapTPsStubs, map>& mapStubsTPs) { + int nTPsReco(0); + int nTPsEff(0); + for (const pair>& mapTPStubs : mapTPsStubs) { + if (!reconstructable(mapTPStubs.second)) + continue; + nTPsReco++; + const bool useForAlgEff = select(*mapTPStubs.first.get()); + if (useForAlgEff) { + nTPsEff++; + fill(mapTPStubs.first, hisEffMC_); + for (const TTStubRef& ttStubRef : mapTPStubs.second) + mapStubsTPs[ttStubRef].insert(mapTPStubs.first); + } + } + profMC_->Fill(3, nTPsReco); + profMC_->Fill(4, nTPsEff); + } + + // checks if a stub selection is considered reconstructable + bool Analyzer::reconstructable(const set& ttStubRefs) const { + const TrackerGeometry* trackerGeometry = settings_.trackerGeometry(); + const TrackerTopology* trackerTopology = settings_.trackerTopology(); + set hitPattern; + set hitPatternPS; + for (const TTStubRef& ttStubRef : ttStubRefs) { + const DetId detId = ttStubRef->getDetId(); + const bool barrel = detId.subdetId() == StripSubdetector::TOB; + const bool psModule = trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP; + const int layerId = barrel ? trackerTopology->layer(detId) : trackerTopology->tidWheel(detId) + 10; + hitPattern.insert(layerId); + if (psModule) + hitPatternPS.insert(layerId); + } + return (int)hitPattern.size() >= settings_.tpMinLayers() && (int)hitPatternPS.size() >= settings_.tpMinLayersPS(); + } + + // checks if TrackingParticle is selected for efficiency measurements + bool Analyzer::select(const TrackingParticle& tp) const { + const bool selected = tpSelector_(tp); + const double cot = sinh(tp.eta()); + const double s = sin(tp.phi()); + const double c = cos(tp.phi()); + const TrackingParticle::Point& v = tp.vertex(); + const double z0 = v.z() - (v.x() * c + v.y() * s) * cot; + const double d0 = v.x() * s - v.y() * c; + return selected && (fabs(d0) < settings_.tpMaxD0()) && (fabs(z0) < settings_.tpMaxVertZ()); + } + + // fills kinematic tp histograms + void Analyzer::fill(const TPPtr& tpPtr, const vector th1fs) const { + const double s = sin(tpPtr->phi()); + const double c = cos(tpPtr->phi()); + const TrackingParticle::Point& v = tpPtr->vertex(); + const vector x = {tpPtr->phi(), + tpPtr->pt(), + tpPtr->charge() / tpPtr->pt(), + v.x() * s - v.y() * c, + v.z() - (v.x() * c + v.y() * s) * sinh(tpPtr->eta()), + tpPtr->eta()}; + for (Efficiency e : AllEfficiency) + th1fs[e]->Fill(x[e]); + } + + // analyze DTC products and find still reconstrucable TrackingParticles + void Analyzer::analyzeStubs(const TTDTC* accepted, + const TTDTC* lost, + const map>& mapStubsTPs, + map>& mapTPsStubs) { + for (int region = 0; region < settings_.numRegions(); region++) { + int nStubs(0); + int nLost(0); + for (int channel = 0; channel < settings_.numDTCsPerTFP(); channel++) { + const TTDTC::Stream& stream = accepted->stream(region, channel); + hisChannel_->Fill(stream.size()); + profChannel_->Fill(region * settings_.numDTCsPerTFP() + channel, stream.size()); + for (const TTDTC::Frame& frame : stream) { + if (frame.first.isNull()) + continue; + const auto it = mapStubsTPs.find(frame.first); + if (it == mapStubsTPs.end()) + continue; + for (const TPPtr& tp : it->second) + mapTPsStubs[tp].insert(frame.first); + } + analyzeStream(stream, region, nStubs, hisRZStubs_); + analyzeStream(lost->stream(region, channel), region, nLost, hisRZStubsLost_); + } + profDTC_->Fill(1, nStubs); + profDTC_->Fill(2, nLost); + } + } + + // fill stub related histograms + void Analyzer::analyzeStream(const TTDTC::Stream& stream, int region, int& sum, TH2F* th2f) { + for (const TTDTC::Frame& frame : stream) { + if (frame.first.isNull()) + continue; + sum++; + const GlobalPoint& pos = TTDTCConverter(&settings_, frame, region); + const GlobalPoint& ttPos = stubPos(frame.first); + const vector resolutions = { + ttPos.perp() - pos.perp(), deltaPhi(ttPos.phi() - pos.phi()), ttPos.z() - pos.z()}; + for (Resolution r : AllResolution) { + hisResolution_[r]->Fill(resolutions[r]); + profResolution_[r]->Fill(ttPos.z(), ttPos.perp(), abs(resolutions[r])); + } + th2f->Fill(ttPos.z(), ttPos.perp()); + } + } + + // returns global stub position + GlobalPoint Analyzer::stubPos(const TTStubRef& ttStubRef) const { + const TrackerGeometry* trackerGeometry = settings_.trackerGeometry(); + const DetId detId = ttStubRef->getDetId() + settings_.offsetDetIdDSV(); + const GeomDetUnit* det = trackerGeometry->idToDetUnit(detId); + const PixelTopology* topol = + dynamic_cast(&(dynamic_cast(det)->specificTopology())); + const Plane& plane = dynamic_cast(det)->surface(); + const MeasurementPoint& mp = ttStubRef->clusterRef(0)->findAverageLocalCoordinatesCentered(); + return plane.toGlobal(topol->localPosition(mp)); + } + + // analyze survived TPs + void Analyzer::analyzeTPs(const map>& mapTPsStubs) { + int nTPs(0); + for (const pair>& mapTPStubs : mapTPsStubs) { + if (!reconstructable(mapTPStubs.second)) + continue; + nTPs++; + fill(mapTPStubs.first, hisEff_); + } + profDTC_->Fill(3, nTPs); + } + + // prints out MC summary + void Analyzer::endJobMC() { + const double numStubs = profMC_->GetBinContent(1); + const double numStubsMatched = profMC_->GetBinContent(2); + const double numTPsReco = profMC_->GetBinContent(3); + const double numTPsEff = profMC_->GetBinContent(4); + const double errStubs = profMC_->GetBinError(1); + const double errStubsMatched = profMC_->GetBinError(2); + const double errTPsReco = profMC_->GetBinError(3); + const double errTPsEff = profMC_->GetBinError(4); + const vector nums = {numStubs, numStubsMatched, numTPsReco, numTPsEff}; + const vector errs = {errStubs, errStubsMatched, errTPsReco, errTPsEff}; + const int wNums = ceil(log10(*max_element(nums.begin(), nums.end()))) + 5; + const int wErrs = ceil(log10(*max_element(errs.begin(), errs.end()))) + 5; + log_ << "=============================================================" << endl; + log_ << " MC SUMMARY " << endl; + log_ << "number of stubs per TFP = " << setw(wNums) << numStubs << " +- " << setw(wErrs) << errStubs + << endl; + log_ << "number of matched stubs per TFP = " << setw(wNums) << numStubsMatched << " +- " << setw(wErrs) + << errStubsMatched << endl; + log_ << "number of TPs per TFP = " << setw(wNums) << numTPsReco << " +- " << setw(wErrs) << errTPsReco + << endl; + log_ << "number of TPs for eff per TFP = " << setw(wNums) << numTPsEff << " +- " << setw(wErrs) << errTPsEff + << endl; + } + + // prints out DTC summary + void Analyzer::endJobDTC() { + const double numStubs = profDTC_->GetBinContent(1); + const double numStubsLost = profDTC_->GetBinContent(2); + const double numTPs = profDTC_->GetBinContent(3); + const double errStubs = profDTC_->GetBinError(1); + const double errStubsLost = profDTC_->GetBinError(2); + const double totalTPs = profMC_->GetBinContent(4); + const double eff = numTPs / totalTPs; + const double errEff = sqrt(eff * (1. - eff) / totalTPs); + const vector nums = {numStubs, numStubsLost}; + const vector errs = {errStubs, errStubsLost}; + const int wNums = ceil(log10(*max_element(nums.begin(), nums.end()))) + 5; + const int wErrs = ceil(log10(*max_element(errs.begin(), errs.end()))) + 5; + log_ << "=============================================================" << endl; + log_ << " DTC SUMMARY " << endl; + log_ << "number of stubs per TFP = " << setw(wNums) << numStubs << " +- " << setw(wErrs) << errStubs << endl; + log_ << "number of lost stubs per TFP = " << setw(wNums) << numStubsLost << " +- " << setw(wErrs) << errStubsLost + << endl; + log_ << " max tracking efficiency = " << setw(wNums) << eff << " +- " << setw(wErrs) << errEff << endl; + } + +} // namespace trackerDTC + +DEFINE_FWK_MODULE(trackerDTC::Analyzer); \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/plugins/BuildFile.xml b/L1Trigger/TrackerDTC/plugins/BuildFile.xml index 7e24483f2e0d4..bb78c98e34f27 100644 --- a/L1Trigger/TrackerDTC/plugins/BuildFile.xml +++ b/L1Trigger/TrackerDTC/plugins/BuildFile.xml @@ -1,3 +1,4 @@ - - - + + + + \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/plugins/Producer.cc b/L1Trigger/TrackerDTC/plugins/Producer.cc index 0263a973060ed..0322a181969c4 100644 --- a/L1Trigger/TrackerDTC/plugins/Producer.cc +++ b/L1Trigger/TrackerDTC/plugins/Producer.cc @@ -20,15 +20,14 @@ #include "DataFormats/L1TrackTrigger/interface/TTDTC.h" #include "DetectorDescription/Core/interface/DDCompactView.h" #include "L1Trigger/TrackTrigger/interface/TTStubAlgorithm_official.h" -#include "L1Trigger/TrackTrigger/interface/TTStubAlgorithm_official.h" #include "L1Trigger/TrackTrigger/interface/TTStubAlgorithmRecord.h" #include "L1Trigger/TrackerDTC/interface/Settings.h" #include "L1Trigger/TrackerDTC/interface/Module.h" #include "L1Trigger/TrackerDTC/interface/DTC.h" -#include #include +#include #include #include @@ -51,14 +50,12 @@ namespace trackerDTC { void beginRun(const Run&, const EventSetup&) override; void produce(Event&, const EventSetup&) override; void endJob() {} - // helper class to store configurations Settings settings_; - // collection of outer tracker sensor modules - std::vector modules_; // ED in- and output tokens EDGetTokenT getTokenTTStubDetSetVec_; - EDPutTokenT putTokenTTDTC_; + EDPutTokenT putTokenTTDTCAccepted_; + EDPutTokenT putTokenTTDTCLost_; // ES tokens ESGetToken, TTStubAlgorithmRecord> getTokenTTStubAlgorithm_; ESGetToken getTokenMagneticField_; @@ -71,7 +68,8 @@ namespace trackerDTC { Producer::Producer(const ParameterSet& iConfig) : settings_(iConfig) { // book in- and output ED products getTokenTTStubDetSetVec_ = consumes(settings_.inputTagTTStubDetSetVec()); - putTokenTTDTC_ = produces(settings_.productBranch()); + putTokenTTDTCAccepted_ = produces(settings_.productBranchAccepted()); + putTokenTTDTCLost_ = produces(settings_.productBranchLost()); // book ES products getTokenTTStubAlgorithm_ = esConsumes, TTStubAlgorithmRecord, Transition::BeginRun>( @@ -98,86 +96,52 @@ namespace trackerDTC { settings_.setTTStubAlgorithm(iSetup.getHandle(getTokenTTStubAlgorithm_)); settings_.setGeometryConfiguration(iSetup.getHandle(getTokenGeometryConfiguration_)); settings_.setProcessHistory(iRun.processHistory()); - // convert data fromat specific stuff - settings_.beginRun(); // check coniguration settings_.checkConfiguration(); if (!settings_.configurationSupported()) return; - // convert cabling map - settings_.convertCablingMap(); - // convert outer tracker geometry - const vector& cablingMap = settings_.cablingMap(); - auto acc = [](int& sum, const DetId& detId) { return sum += !detId.null(); }; - const int numModules = accumulate(cablingMap.begin(), cablingMap.end(), 0, acc); - modules_.reserve(numModules); - int modId(0); - for (const DetId& detId : cablingMap) { - if (!detId.null()) - modules_.emplace_back(&settings_, detId, modId); - modId++; - } - settings_.setModules(modules_); + // convert ES Products into handy objects + settings_.beginRun(); } void Producer::produce(Event& iEvent, const EventSetup& iSetup) { - // empty DTC product - TTDTC product(settings_.numRegions(), settings_.numOverlappingRegions(), settings_.numDTCsPerRegion()); - + // empty DTC products + TTDTC productAccepted(settings_.numRegions(), settings_.numOverlappingRegions(), settings_.numDTCsPerRegion()); + TTDTC productLost(settings_.numRegions(), settings_.numOverlappingRegions(), settings_.numDTCsPerRegion()); if (settings_.configurationSupported()) { // read in stub collection Handle handleTTStubDetSetVec; iEvent.getByToken(getTokenTTStubDetSetVec_, handleTTStubDetSetVec); - // apply cabling map - auto acc = [](int& sum, const TTStubDetSet* module) { return sum += module ? module->size() : 0; }; - vector> ttDTCs(settings_.numDTCs(), - vector(settings_.numModulesPerDTC(), nullptr)); - TTStubDetSetVec::const_iterator ttModule; - for (ttModule = handleTTStubDetSetVec->begin(); ttModule != handleTTStubDetSetVec->end(); ttModule++) { + vector>> ttDTCs(settings_.numDTCs(), + vector>(settings_.numModulesPerDTC())); + for (TTStubDetSetVec::const_iterator module = handleTTStubDetSetVec->begin(); + module != handleTTStubDetSetVec->end(); + module++) { // DetSetVec->detId + 1 = tk layout det id - const DetId detId = ttModule->detId() + settings_.offsetDetIdDSV(); + const DetId detId = module->detId() + settings_.offsetDetIdDSV(); // outer tracker module id [0-15551] - const int modId = settings_.modId(detId); + int modId = settings_.modId(detId); // outer tracker dtc id [0-215] const int dtcId = modId / settings_.numModulesPerDTC(); // outer tracker dtc channel id [0-71] const int channelId = modId % settings_.numModulesPerDTC(); - ttDTCs[dtcId][channelId] = &*ttModule; + vector& ttModule = ttDTCs[dtcId][channelId]; + ttModule.reserve(module->size()); + for (TTStubDetSet::const_iterator ttStub = module->begin(); ttStub != module->end(); ttStub++) + ttModule.emplace_back(makeRefTo(handleTTStubDetSetVec, ttStub)); } - - // read in and convert event content - int dtcId(0); - for (const vector& ttDTC : ttDTCs) { - // get modules connected to this dtc - const vector modules = settings_.modules(dtcId); - // count number of stubs on this dtc - const int nSubs = accumulate(ttDTC.begin(), ttDTC.end(), 0, acc); + // board level processing + for (int dtcId = 0; dtcId < settings_.numDTCs(); dtcId++) { // create single outer tracker DTC board - DTC dtc(&settings_, nSubs); - // fill incoming stubs over all channel - int channelId(0); - for (const TTStubDetSet* ttModule : ttDTC) { - // create TTStubRefs from one module - vector ttStubRefs; - if (ttModule) { - ttStubRefs.reserve(ttModule->size()); - for (TTStubDetSet::const_iterator ttStub = ttModule->begin(); ttStub != ttModule->end(); ttStub++) - ttStubRefs.emplace_back(makeRefTo(handleTTStubDetSetVec, ttStub)); - // truncate incoming stubs if desired - if (settings_.enableTruncation()) - ttStubRefs.resize(std::min((int)ttStubRefs.size(), settings_.maxFramesChannelInput())); - } - // fill incoming stubs of this channel - dtc.consume(ttStubRefs, modules.at(channelId++)); - } - // route stubs and fill product - dtc.produce(product, dtcId++); + DTC dtc(&settings_, dtcId, ttDTCs[dtcId]); + // route stubs and fill products + dtc.produce(productAccepted, productLost); } } - - // store ED product - iEvent.emplace(putTokenTTDTC_, move(product)); + // store ED products + iEvent.emplace(putTokenTTDTCAccepted_, move(productAccepted)); + iEvent.emplace(putTokenTTDTCLost_, move(productLost)); } } // namespace trackerDTC diff --git a/L1Trigger/TrackerDTC/python/Analyzer_Customize_cff.py b/L1Trigger/TrackerDTC/python/Analyzer_Customize_cff.py new file mode 100644 index 0000000000000..e84740ff620df --- /dev/null +++ b/L1Trigger/TrackerDTC/python/Analyzer_Customize_cff.py @@ -0,0 +1,10 @@ +import FWCore.ParameterSet.Config as cms + +def useTMTT(process): + from L1Trigger.TrackerDTC.Producer_Defaults_cfi import TrackerDTCProducer_params + from L1Trigger.TrackerDTC.Format_TMTT_cfi import TrackerDTCFormat_params + from L1Trigger.TrackerDTC.Analyzer_Defaults_cfi import TrackerDTCAnalyzer_params + TrackerDTCProducer_params.ParamsED.DataFormat = "TMTT" + TrackerDTCAnalyzer_params.ParamsTP.MinPt = cms.double( 3. ) + process.TrackerDTCAnalyzer = cms.EDAnalyzer('trackerDTC::Analyzer', TrackerDTCAnalyzer_params, TrackerDTCProducer_params, TrackerDTCFormat_params) + return process \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/python/Analyzer_Defaults_cfi.py b/L1Trigger/TrackerDTC/python/Analyzer_Defaults_cfi.py new file mode 100644 index 0000000000000..4c31477c450b8 --- /dev/null +++ b/L1Trigger/TrackerDTC/python/Analyzer_Defaults_cfi.py @@ -0,0 +1,29 @@ +import FWCore.ParameterSet.Config as cms + +TrackerDTCAnalyzer_params = cms.PSet ( + + #=== ED parameter + + ParamsAnalyzer = cms.PSet ( + ProducerLabel = cms.string( "TrackerDTCProducer" ), # label of DTC producer + InputTagTTClusterAssMap = cms.InputTag( "TTClusterAssociatorFromPixelDigis", "ClusterAccepted" ), # tag of AssociationMap between TTCluster and TrackingParticles + UseMCTruth = cms.bool ( True ) # open and analyze TrackingParticles, original TTStubs and Association between them + ), + + #=== Cuts on MC truth particles (i.e., tracking particles) used for tracking efficiency measurements. And Rules for deciding when a reconstructed L1 track matches a MC truth particle (i.e. tracking particle) + + ParamsTP = cms.PSet ( + MinPt = cms.double( 2. ), # pt cut in GeV + MaxEta = cms.double( 2.4 ), # eta cut + MaxVertR = cms.double( 1. ), # cut on vertex pos r in cm + MaxVertZ = cms.double( 30. ), # cut on vertex pos z in cm + MaxD0 = cms.double( 5. ), # cut on impact parameter in cm + MinLayers = cms.int32 ( 4 ), # required number of associated layers to a TP to consider it reconstruct-able + MinLayersPS = cms.int32 ( 0 ), # required number of associated ps layers to a TP to consider it reconstruct-able + MatchedLayers = cms.int32 ( 4 ), # required number of layers a found track has to have in common with a TP to consider it matched to it + MatchedLayersPS = cms.int32 ( 0 ), # required number of ps layers a found track has to have in common with a TP to consider it matched to it + UnMatchedStubs = cms.int32 ( 1 ), # allowed number of stubs a found track may have not in common with its matched TP + UnMatchedStubsPS = cms.int32 ( 0 ) # allowed number of PS stubs a found track may have not in common with its matched TP + ) + +) diff --git a/L1Trigger/TrackerDTC/python/Analyzer_cff.py b/L1Trigger/TrackerDTC/python/Analyzer_cff.py new file mode 100644 index 0000000000000..544e43c52da41 --- /dev/null +++ b/L1Trigger/TrackerDTC/python/Analyzer_cff.py @@ -0,0 +1,7 @@ +import FWCore.ParameterSet.Config as cms + +from L1Trigger.TrackerDTC.Analyzer_Defaults_cfi import TrackerDTCAnalyzer_params +from L1Trigger.TrackerDTC.Producer_Defaults_cfi import TrackerDTCProducer_params +from L1Trigger.TrackerDTC.Format_Hybrid_cfi import TrackerDTCFormat_params + +TrackerDTCAnalyzer = cms.EDAnalyzer('trackerDTC::Analyzer', TrackerDTCAnalyzer_params, TrackerDTCProducer_params, TrackerDTCFormat_params) \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/python/Format_Hybrid_cfi.py b/L1Trigger/TrackerDTC/python/Format_Hybrid_cfi.py index 5399d834b64b1..f3d8a53c9c138 100644 --- a/L1Trigger/TrackerDTC/python/Format_Hybrid_cfi.py +++ b/L1Trigger/TrackerDTC/python/Format_Hybrid_cfi.py @@ -32,14 +32,14 @@ RangesZ = cms.vdouble( 240., 240., 7.5, 7.5 ), # range in stub z which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) RangesAlpha = cms.vdouble( 0., 0., 0., 1024. ), # range in stub row which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) - LayerRs = cms.vdouble( 24.8656, 37.1678, 52.2700, 68.7000, 86.0000, 110.8000 ), # mean radius of outer tracker barrel layer - DiskZs = cms.vdouble( 131.1800, 155.0000, 185.3400, 221.6190, 265.0000 ), # mean z of outer tracker endcap disks + LayerRs = cms.vdouble( 24.9316, 37.1777, 52.2656, 68.7598, 86.0156, 108.3105 ), # mean radius of outer tracker barrel layer + DiskZs = cms.vdouble( 131.1914, 154.9805, 185.3320, 221.6016, 265.0195 ), # mean z of outer tracker endcap disks Disk2SRsSet = cms.VPSet( # center radius of outer tracker endcap 2S diks strips - cms.PSet( Disk2SRs = cms.vdouble( 66.7345, 71.7345, 77.5056, 82.5056, 84.8444, 89.8444, 95.7515, 100.7515, 102.475, 107.475 ) ), # disk 1 - cms.PSet( Disk2SRs = cms.vdouble( 66.7345, 71.7345, 77.5056, 82.5056, 84.8444, 89.8444, 95.7515, 100.7515, 102.475, 107.475 ) ), # disk 2 - cms.PSet( Disk2SRs = cms.vdouble( 65.1317, 70.1317, 75.6300, 80.6300, 83.9293, 88.9293, 94.6316, 99.6316, 102.475, 107.475 ) ), # disk 3 - cms.PSet( Disk2SRs = cms.vdouble( 65.1317, 70.1317, 75.6300, 80.6300, 83.9293, 88.9293, 94.6316, 99.6316, 102.475, 107.475 ) ), # disk 4 - cms.PSet( Disk2SRs = cms.vdouble( 65.1317, 70.1317, 75.6300, 80.6300, 83.9293, 88.9293, 94.6316, 99.6316, 102.475, 107.475 ) ) # disk 5 + cms.PSet( Disk2SRs = cms.vdouble( 66.4391, 71.4391, 76.2750, 81.2750, 82.9550, 87.9550, 93.8150, 98.8150, 99.8160, 104.8160 ) ), # disk 1 + cms.PSet( Disk2SRs = cms.vdouble( 66.4391, 71.4391, 76.2750, 81.2750, 82.9550, 87.9550, 93.8150, 98.8150, 99.8160, 104.8160 ) ), # disk 2 + cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ), # disk 3 + cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ), # disk 4 + cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ) # disk 5 ) ) diff --git a/L1Trigger/TrackerDTC/python/Producer_Customize_cff.py b/L1Trigger/TrackerDTC/python/Producer_Customize_cff.py index ef21e9521002b..b2a8db0c6453d 100644 --- a/L1Trigger/TrackerDTC/python/Producer_Customize_cff.py +++ b/L1Trigger/TrackerDTC/python/Producer_Customize_cff.py @@ -1,6 +1,10 @@ +import FWCore.ParameterSet.Config as cms + def useTMTT(process): from L1Trigger.TrackerDTC.Producer_Defaults_cfi import TrackerDTCProducer_params from L1Trigger.TrackerDTC.Format_TMTT_cfi import TrackerDTCFormat_params + from L1Trigger.TrackerDTC.Analyzer_Defaults_cfi import TrackerDTCAnalyzer_params TrackerDTCProducer_params.ParamsED.DataFormat = "TMTT" - process.TrackerDTCProducer = cms.EDProducer('trackerDTC::Producer', TrackerDTCProducer_params, TrackerDTCFormat_params ) + TrackerDTCAnalyzer_params.ParamsTP.MinPt = cms.double( 3. ) + process.TrackerDTCProducer = cms.EDProducer('trackerDTC::Producer', TrackerDTCProducer_params, TrackerDTCFormat_params, TrackerDTCAnalyzer_params) return process \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/python/Producer_Defaults_cfi.py b/L1Trigger/TrackerDTC/python/Producer_Defaults_cfi.py index 63b230bc5e557..7b5040487868d 100644 --- a/L1Trigger/TrackerDTC/python/Producer_Defaults_cfi.py +++ b/L1Trigger/TrackerDTC/python/Producer_Defaults_cfi.py @@ -6,7 +6,8 @@ ParamsED = cms.PSet ( InputTagTTStubDetSetVec = cms.InputTag ( "TTStubsFromPhase2TrackerDigis", "StubAccepted" ), # - ProductBranch = cms.string ( "StubAccepted" ), # + ProductBranchAccepted = cms.string ( "StubAccepted" ), # + ProductBranchLost = cms.string ( "StubLost" ), # InputTagMagneticField = cms.ESInputTag( "VolumeBasedMagneticFieldESProducer", "" ), # InputTagTrackerGeometry = cms.ESInputTag( "trackerGeometry", "" ), # InputTagTrackerTopology = cms.ESInputTag( "trackerTopology", "" ), # @@ -22,7 +23,7 @@ OffsetDetIdTP = cms.int32 ( -1 ), # tk layout det id minus TrackerTopology lower det id OffsetLayerDisks = cms.int32 ( 10 ), # offset in layer ids between barrel layer and endcap disks OffsetLayerId = cms.int32 ( 1 ), # offset between 0 and smallest layer id (barrel layer 1) - CheckHistory = cms.bool ( False ), # + CheckHistory = cms.bool ( False ), # ProcessName = cms.string ( "HLT" ), # ProductLabel = cms.string ( "XMLIdealGeometryESSource" ) # ), @@ -30,7 +31,7 @@ #=== router parameter ParamsRouter = cms.PSet ( - EnableTruncation = cms.bool ( False ), # enables emulation of truncation + EnableTruncation = cms.bool ( True ), # enables emulation of truncation FreqDTC = cms.double( 360. ), # Frequency in MHz, has to be integer multiple of FreqLHC TMP_TFP = cms.int32 ( 18 ), # time multiplexed period of track finding processor NumFramesInfra = cms.int32 ( 6 ), # needed gap between events of emp-infrastructure firmware @@ -74,4 +75,4 @@ MaxPitch = cms.double( .01 ) # max strip/pixel pitch of outer tracker sensors in cm ) -) +) \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/python/Producer_cff.py b/L1Trigger/TrackerDTC/python/Producer_cff.py index 48c076bd455c7..a5404d898b809 100644 --- a/L1Trigger/TrackerDTC/python/Producer_cff.py +++ b/L1Trigger/TrackerDTC/python/Producer_cff.py @@ -8,5 +8,6 @@ from L1Trigger.TrackerDTC.Producer_Defaults_cfi import TrackerDTCProducer_params from L1Trigger.TrackerDTC.Format_Hybrid_cfi import TrackerDTCFormat_params +from L1Trigger.TrackerDTC.Analyzer_Defaults_cfi import TrackerDTCAnalyzer_params -TrackerDTCProducer = cms.EDProducer('trackerDTC::Producer', TrackerDTCProducer_params, TrackerDTCFormat_params ) \ No newline at end of file +TrackerDTCProducer = cms.EDProducer('trackerDTC::Producer', TrackerDTCProducer_params, TrackerDTCFormat_params, TrackerDTCAnalyzer_params) \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/src/DTC.cc b/L1Trigger/TrackerDTC/src/DTC.cc index aa6a860b6b810..ef8907d784fa0 100644 --- a/L1Trigger/TrackerDTC/src/DTC.cc +++ b/L1Trigger/TrackerDTC/src/DTC.cc @@ -4,77 +4,87 @@ #include #include +#include +#include +#include +#include using namespace std; using namespace edm; namespace trackerDTC { - DTC::DTC(Settings* settings, int nStubs) : settings_(settings) { stubs_.reserve(nStubs); } - - // convert and assign TTStubRef to DTC routing block channel - void DTC::consume(const vector& ttStubRefStream, Module* module) { - for (const TTStubRef& ttStubRef : ttStubRefStream) - stubs_.emplace_back(settings_, module, ttStubRef); + DTC::DTC(Settings* settings, int dtcId, const std::vector>& modules) + : settings_(settings), + region_(dtcId / settings_->numDTCsPerRegion()), + board_(dtcId % settings_->numDTCsPerRegion()), + modules_(settings_->modules(dtcId)), + input_(settings_->numRoutingBlocks(), Stubss(settings_->numModulesPerRoutingBlock())), + lost_(settings_->numOverlappingRegions()) { + // count number of stubs on this dtc + auto acc = [](int& sum, const vector& module) { return sum += module.size(); }; + const int nStubs = accumulate(modules.begin(), modules.end(), 0, acc); + stubs_.reserve(nStubs); + // convert and assign Stubs to DTC routing block channel + for (int modId = 0; modId < settings_->numModulesPerDTC(); modId++) { + const vector& ttStubRefs = modules[modId]; + if (ttStubRefs.empty()) + continue; + // Module which produced this ttStubRefs + Module* module = modules_.at(modId); + // DTC routing block id [0-1] + const int blockId = modId / settings_->numModulesPerRoutingBlock(); + // DTC routing blockc channel id [0-35] + const int channelId = modId % settings_->numModulesPerRoutingBlock(); + // convert TTStubs and fill input channel + Stubs& stubs = input_[blockId][channelId]; + for (const TTStubRef& ttStubRef : ttStubRefs) { + stubs_.emplace_back(settings_, module, ttStubRef); + Stub& stub = stubs_.back(); + if (stub.valid()) + // passed pt and eta cut + stubs.push_back(&stub); + } + // sort stubs by bend + sort(stubs.begin(), stubs.end(), [](Stub* lhs, Stub* rhs) { return abs(lhs->bend()) < abs(rhs->bend()); }); + // truncate stubs if desired + if (!settings_->enableTruncation() || (int)stubs.size() <= settings_->maxFramesChannelInput()) + continue; + // begin of truncated stubs + const auto limit = next(stubs.begin(), settings_->maxFramesChannelInput()); + // copy truncated stubs into lost output channel + for (int region = 0; region < settings_->numOverlappingRegions(); region++) + copy_if( + limit, stubs.end(), back_inserter(lost_[region]), [region](Stub* stub) { return stub->inRegion(region); }); + // remove truncated stubs form input channel + stubs.erase(limit, stubs.end()); + } } - // board level routing in two steps and product filling - void DTC::produce(TTDTC& product, int dtcId) { - stubs_.shrink_to_fit(); - // outer tracker detector region [0-8] - const int region = dtcId / settings_->numDTCsPerRegion(); - // outer tracker dtc id in region [0-23] - const int board = dtcId % settings_->numDTCsPerRegion(); - // empty input, intermediate and output container - Stubsss moduleStubs(settings_->numRoutingBlocks(), Stubss(settings_->numModulesPerRoutingBlock())); - Stubss blockStubs(settings_->numRoutingBlocks()); - Stubss regionStubs(settings_->numOverlappingRegions()); - - // fill input - for (Stub& stub : stubs_) - if (stub.valid()) // pt and eta cut - moduleStubs[stub.blockId()][stub.channelId()].push_back(&stub); - - // sort stubs by bend - for (auto& block : moduleStubs) - for (auto& channel : block) - sort(channel.begin(), channel.end(), [](Stub* lhs, Stub* rhs) { return abs(lhs->bend()) < abs(rhs->bend()); }); - + // board level routing in two steps and products filling + void DTC::produce(TTDTC& productAccepted, TTDTC& productLost) { // router step 1: merges stubs of all modules connected to one routing block into one stream + Stubs lost; + Stubss blockStubs(settings_->numRoutingBlocks()); for (int routingBlock = 0; routingBlock < settings_->numRoutingBlocks(); routingBlock++) - merge(moduleStubs[routingBlock], blockStubs[routingBlock]); - + merge(input_[routingBlock], blockStubs[routingBlock], lost); + // copy lost stubs during merge into lost output channel + for (int region = 0; region < settings_->numOverlappingRegions(); region++) + copy_if(lost.begin(), lost.end(), back_inserter(lost_[region]), [region](Stub* stub) { + return stub->inRegion(region); + }); // router step 2: merges stubs of all routing blocks and splits stubs into one stream per overlapping region + Stubss regionStubs(settings_->numOverlappingRegions()); split(blockStubs, regionStubs); - - // fill product - for (int channel = 0; channel < settings_->numOverlappingRegions(); channel++) { - Stubs& stubs = regionStubs[channel]; - // truncate if desired - if (settings_->enableTruncation()) - stubs.resize(min((int)stubs.size(), settings_->maxFramesChannelOutput())); - // remove all gaps between end and last stub - for (auto it = stubs.end(); it != stubs.begin();) - it = (*--it) ? stubs.begin() : stubs.erase(it); - // convert to TTDTC::Stream - TTDTC::Stream stream; - stream.reserve(stubs.size()); - for (const Stub* stub : stubs) { - if (stub) - stream.emplace_back(stub->ttStubRef(), stub->frame(channel)); - else - // use default constructed TTDTC::Pair to represent gaps - stream.emplace_back(); - } - product.setStream(region, board, channel, stream); - } + // fill products + produce(regionStubs, productAccepted); + produce(lost_, productLost); } // router step 1: merges stubs of all modules connected to one routing block into one stream - void DTC::merge(Stubss& inputs, Stubs& output) { + void DTC::merge(Stubss& inputs, Stubs& output, Stubs& lost) { // for each input one fifo Stubss stacks(inputs.size()); - // clock accurate firmware emulation, each while trip describes one clock tick while (!all_of(inputs.begin(), inputs.end(), [](const Stubs& channel) { return channel.empty(); }) or !all_of(stacks.begin(), stacks.end(), [](const Stubs& channel) { return channel.empty(); })) { @@ -88,11 +98,10 @@ namespace trackerDTC { if (stub) { if (settings_->enableTruncation() && (int)stack.size() == settings_->sizeStack() - 1) // kill current first stub when fifo overflows - stack.pop_front(); + lost.push_back(pop_front(stack)); stack.push_back(stub); } } - // route stub from a fifo to output if possible bool nothingToRoute(true); for (int iInput = inputs.size() - 1; iInput >= 0; iInput--) { @@ -104,25 +113,46 @@ namespace trackerDTC { // only one stub can be routed to output per clock tick break; } - // each clock tick output will grow by one, if no stub is available then by a gap if (nothingToRoute) output.push_back(nullptr); } + // truncate if desired + if (settings_->enableTruncation() && (int)output.size() > settings_->maxFramesChannelOutput()) { + const auto limit = next(output.begin(), settings_->maxFramesChannelOutput()); + copy_if(limit, output.end(), back_inserter(lost), [](Stub* stub) { return stub; }); + output.erase(limit, output.end()); + } + // remove all gaps between end and last stub + for (auto it = output.end(); it != output.begin();) + it = (*--it) ? output.begin() : output.erase(it); } // router step 2: merges stubs of all routing blocks and splits stubs into one stream per overlapping region void DTC::split(Stubss& inputs, Stubss& outputs) { int region(0); - auto regionMask = [region](Stub* stub) { return stub->inRegion(region) ? stub : nullptr; }; + auto regionMask = [®ion](Stub* stub) { return stub && stub->inRegion(region) ? stub : nullptr; }; for (Stubs& output : outputs) { // copy of masked inputs for each output Stubss streams(inputs.size()); int i(0); for (Stubs& input : inputs) transform(input.begin(), input.end(), back_inserter(streams[i++]), regionMask); - merge(streams, output); - region++; + merge(streams, output, lost_[region++]); + } + } + + // conversion from Stubss to TTDTC + void DTC::produce(const Stubss& stubss, TTDTC& product) { + int channel(0); + auto toFrame = [&channel](Stub* stub) { + return stub ? make_pair(stub->ttStubRef(), stub->frame(channel)) : TTDTC::Frame(); + }; + for (const Stubs& stubs : stubss) { + TTDTC::Stream stream; + stream.reserve(stubs.size()); + transform(stubs.begin(), stubs.end(), back_inserter(stream), toFrame); + product.setStream(region_, board_, channel++, stream); } } diff --git a/L1Trigger/TrackerDTC/src/Module.cc b/L1Trigger/TrackerDTC/src/Module.cc index 596623d6a245d..512ee1c97cf1a 100644 --- a/L1Trigger/TrackerDTC/src/Module.cc +++ b/L1Trigger/TrackerDTC/src/Module.cc @@ -1,4 +1,5 @@ #include "L1Trigger/TrackerDTC/interface/Module.h" +#include "L1Trigger/TrackerDTC/interface/Settings.h" #include "DataFormats/TrackerCommon/interface/TrackerTopology.h" #include "DataFormats/GeometryVector/interface/GlobalPoint.h" #include "DataFormats/GeometrySurface/interface/Plane.h" @@ -15,29 +16,22 @@ using namespace edm; namespace trackerDTC { - Module::Module(Settings* settings, const DetId& detId, int modId) - : dtcId_(modId / settings->numModulesPerDTC()), - dtcChannelId_(modId % settings->numModulesPerDTC()), - blockId_(dtcChannelId_ / settings->numModulesPerRoutingBlock()), - blockChannelId_(dtcChannelId_ % settings->numModulesPerRoutingBlock()) { - // detector region [0-8] - const int region = modId / (settings->numModulesPerDTC() * settings->numDTCsPerRegion()); - + Module::Module(Settings* settings, const DetId& detId, int dtcId) { const TrackerGeometry* trackerGeometry = settings->trackerGeometry(); const TrackerTopology* trackerTopology = settings->trackerTopology(); - const GeomDetUnit* det0 = trackerGeometry->idToDetUnit(detId); - const GlobalPoint pos0 = GlobalPoint(det0->position()); - const GlobalPoint pos1 = - GlobalPoint(trackerGeometry->idToDetUnit(trackerTopology->partnerDetId(detId))->position()); const PixelTopology* topol = dynamic_cast(&(dynamic_cast(det0)->specificTopology())); const Plane& plane = dynamic_cast(det0)->surface(); - + const GlobalPoint pos0 = GlobalPoint(det0->position()); + const GlobalPoint pos1 = + GlobalPoint(trackerGeometry->idToDetUnit(trackerTopology->partnerDetId(detId))->position()); + // detector region_ [0-8] + region_ = dtcId / settings->numDTCsPerRegion(); // module radius in cm R_ = pos0.perp(); - // module phi w.r.t. detector region centre in rad - Phi_ = deltaPhi(pos0.phi() - (region + .5) * settings->baseRegion()); + // module phi w.r.t. detector region_ centre in rad + Phi_ = deltaPhi(pos0.phi() - (region_ + .5) * settings->baseRegion()); // module z in cm Z_ = pos0.z(); // sensor separation in cm @@ -50,7 +44,7 @@ namespace trackerDTC { numColumns_ = topol->ncolumns(); // number of rows [2S=8*127,PS=8*120] numRows_ = topol->nrows(); - side_ = pos0.z() > 0.; + side_ = pos0.z() >= 0.; flipped_ = pos0.mag() > pos1.mag(); barrel_ = detId.subdetId() == StripSubdetector::TOB; // module tilt measured w.r.t. beam axis (0=barrel), tk layout measures w.r.t. radial axis @@ -61,8 +55,8 @@ namespace trackerDTC { // cosinus of module tilt measured w.r.t. beam axis (+-1=endcap), tk layout measures w.r.t. radial axis cos_ = cos(tilt_); // layer id [1-6,11-15] - layerId_ = barrel_ ? trackerTopology->layer(detId) : trackerTopology->tidWheel(detId) + 10; - + layerId_ = + barrel_ ? trackerTopology->layer(detId) : trackerTopology->tidWheel(detId) + settings->offsetLayerDisks(); // TTStub row needs flip of sign signRow_ = signbit(deltaPhi(plane.rotation().x().phi() - pos0.phi())); // TTStub col needs flip of sign @@ -70,9 +64,9 @@ namespace trackerDTC { // TTStub bend needs flip of sign signBend_ = barrel_ || (!barrel_ && side_); + // sets hybrid specific member if (settings->dataFormat() != "Hybrid") return; - // gettings hybrid config SettingsHybrid* format = settings->hybrid(); const vector& numRingsPS = format->numRingsPS(); @@ -85,7 +79,6 @@ namespace trackerDTC { const vector >& bendEncodingsPS = format->bendEncodingsPS(); const vector >& bendEncodings2S = format->bendEncodings2S(); const vector >& layerIdEncodings = format->layerIdEncodings(); - // determing sensor type const bool psModule = trackerGeometry->getDetectorType(detId) == TrackerGeometry::ModuleType::Ph2PSP; if (barrel_ && psModule) @@ -119,10 +112,11 @@ namespace trackerDTC { // r and z offsets offsetR_ = barrel_ ? layerRs.at(layerId_ - settings->offsetLayerId()) : 0.; offsetZ_ = barrel_ ? 0. : diskZs.at(layerId_ - settings->offsetLayerId() - settings->offsetLayerDisks()); + if (!side_) + offsetZ_ *= -1.; // layer id encoding - const int dtcId = modId / settings->numModulesPerDTC(); - const vector& layerIdEncoding = layerIdEncodings.at(dtcId); + const vector& layerIdEncoding = layerIdEncodings.at(dtcId % settings->numDTCsPerRegion()); layerId_ = distance(layerIdEncoding.begin(), find(layerIdEncoding.begin(), layerIdEncoding.end(), layerId_)); } -} // namespace trackerDTC +} // namespace trackerDTC \ No newline at end of file diff --git a/L1Trigger/TrackerDTC/src/Settings.cc b/L1Trigger/TrackerDTC/src/Settings.cc index 4d9eb3887778b..bf77efc39af6b 100644 --- a/L1Trigger/TrackerDTC/src/Settings.cc +++ b/L1Trigger/TrackerDTC/src/Settings.cc @@ -14,7 +14,8 @@ #include #include #include -#include +#include +#include using namespace std; using namespace edm; @@ -29,6 +30,8 @@ namespace trackerDTC { paramsTracker_(iConfig.getParameter("ParamsTracker")), paramsFW_(iConfig.getParameter("ParamsFW")), paramsFormat_(iConfig.getParameter("ParamsFormat")), + paramsAnalyzer_(iConfig.getParameter("ParamsAnalyzer")), + paramsTP_(iConfig.getParameter("ParamsTP")), // ED parameter inputTagTTStubDetSetVec_(paramsED_.getParameter("InputTagTTStubDetSetVec")), inputTagMagneticField_(paramsED_.getParameter("InputTagMagneticField")), @@ -41,7 +44,8 @@ namespace trackerDTC { supportedTrackerXMLPath_(paramsED_.getParameter("SupportedTrackerXMLPath")), supportedTrackerXMLFile_(paramsED_.getParameter("SupportedTrackerXMLFile")), supportedTrackerXMLVersions_(paramsED_.getParameter>("SupportedTrackerXMLVersions")), - productBranch_(paramsED_.getParameter("ProductBranch")), + productBranchAccepted_(paramsED_.getParameter("ProductBranchAccepted")), + productBranchLost_(paramsED_.getParameter("ProductBranchLost")), dataFormat_(paramsED_.getParameter("DataFormat")), offsetDetIdDSV_(paramsED_.getParameter("OffsetDetIdDSV")), offsetDetIdTP_(paramsED_.getParameter("OffsetDetIdTP")), @@ -85,9 +89,22 @@ namespace trackerDTC { maxEta_(paramsFormat_.getParameter("MaxEta")), minPt_(paramsFormat_.getParameter("MinPt")), chosenRofPhi_(paramsFormat_.getParameter("ChosenRofPhi")), - numLayers_(paramsFormat_.getParameter("NumLayers")) { + numLayers_(paramsFormat_.getParameter("NumLayers")), + // Analyzer + useMCTruth_(paramsAnalyzer_.getParameter("UseMCTruth")), + inputTagTTClusterAssMap_(paramsAnalyzer_.getParameter("InputTagTTClusterAssMap")), + producerLabel_(paramsAnalyzer_.getParameter("ProducerLabel")), + // TP + tpMinPt_(paramsTP_.getParameter("MinPt")), + tpMaxEta_(paramsTP_.getParameter("MaxEta")), + tpMaxVertR_(paramsTP_.getParameter("MaxVertR")), + tpMaxVertZ_(paramsTP_.getParameter("MaxVertZ")), + tpMaxD0_(paramsTP_.getParameter("MaxD0")), + tpMinLayers_(paramsTP_.getParameter("MinLayers")), + tpMinLayersPS_(paramsTP_.getParameter("MinLayersPS")) { // derived Router parameter numDTCs_ = numRegions_ * numDTCsPerRegion_; + numDTCsPerTFP_ = numDTCsPerRegion_ * numOverlappingRegions_; numModules_ = numRegions_ * numDTCsPerRegion_ * numModulesPerDTC_; numModulesPerRoutingBlock_ = numModulesPerDTC_ / numRoutingBlocks_; @@ -98,7 +115,8 @@ namespace trackerDTC { numMergedRows_ = pow(2, widthRow_ - widthRowLUT_); maxCot_ = sinh(maxEta_); - rangeQoverPt_ = speedOfLight_ * bField_ / minPt_ / 1000.; + invPtToDphi_ = speedOfLight_ * bField_ / 2000.; + rangeQoverPt_ = 2. * invPtToDphi_ / minPt_; widthLayer_ = ceil(log2(numLayers_)); @@ -135,8 +153,7 @@ namespace trackerDTC { trackerTopology_ = nullptr; magneticField_ = nullptr; // derived event setup - cablingMap_ = vector(numModules_); - dtcModules_ = vector>(numDTCs_, vector(numModulesPerDTC_, nullptr)); + dtcModules_ = vector>(numDTCs_); configurationSupported_ = true; } @@ -228,16 +245,9 @@ namespace trackerDTC { hybrid_->checkConfiguration(this); } - // convert data fromat specific stuff + // convert ES Products into handy objects void Settings::beginRun() { - if (dataFormat_ == "Hybrid") { - hybrid_->createEncodingsBend(this); - hybrid_->createEncodingsLayer(this); - } - } - - // convert cabling map - void Settings::convertCablingMap() { + // convert cabling map // DTC product used to convert between different dtc id schemes TTDTC ttDTC(numRegions_, numOverlappingRegions_, numDTCsPerRegion_); // module counter for each DTC @@ -259,33 +269,43 @@ namespace trackerDTC { // track trigger module id [0-15551] const int ModId = dtcId * numModulesPerDTC_ + modId; // store connection between global module id and detId - cablingMap_[ModId] = detId; + cablingMap_.emplace(detId, ModId); // check configuration - if (modId++ == numModulesPerDTC_) { + if (modId++ > numModulesPerDTC_) { cms::Exception exception("overflow"); - exception << "Cabling map connects more than " << numModulesPerDTC_ << " modules to DTC " << dtcId << "."; + exception << "Cabling map connects more than " << numModulesPerDTC_ << " modules to a DTC."; exception.addContext("trackerDTC::Settings::convertCablingMap"); throw exception; } } - } - - // set converted tracker geometry - void Settings::setModules(std::vector& modules) { - for (Module& module : modules) - dtcModules_[module.dtcId()][module.dtcChannelId()] = &module; + // hybrid specific conversions + if (dataFormat_ == "Hybrid") { + hybrid_->createEncodingsBend(this); + hybrid_->createEncodingsLayer(this); + } + //convert tracker geometry + for (int dtcId = 0; dtcId < numDTCs_; dtcId++) + dtcModules_[dtcId] = vector(modIds.at(dtcId), nullptr); + modules_.reserve(cablingMap_.size()); + for (const pair& map : cablingMap_) { + const int dtcId = map.second / numModulesPerDTC_; + const int modId = map.second % numModulesPerDTC_; + modules_.emplace_back(this, map.first, dtcId); + dtcModules_[dtcId][modId] = &modules_.back(); + } } // convert DetId to module id [0:15551] int Settings::modId(const DetId& detId) const { - const int modId = distance(cablingMap_.begin(), find(cablingMap_.begin(), cablingMap_.end(), detId)); - if (modId == numModules_) { - cms::Exception exception("LogicError", "Unknown DetID received from TTStub."); + unordered_map::const_iterator it = cablingMap_.find(detId); + if (it == cablingMap_.end()) { + cms::Exception exception("LogicError"); + exception << "Unknown DetID (" << detId << ") received from TTStub."; exception.addAdditionalInfo("Please check consistency between chosen cabling map and chosen tracker geometry."); exception.addContext("trackerDTC::Settings::modId"); throw exception; } - return modId; + return it->second; } // collection of modules connected to a specific dtc diff --git a/L1Trigger/TrackerDTC/src/SettingsHybrid.cc b/L1Trigger/TrackerDTC/src/SettingsHybrid.cc index d6c820de4b6cf..7813b258a5b32 100644 --- a/L1Trigger/TrackerDTC/src/SettingsHybrid.cc +++ b/L1Trigger/TrackerDTC/src/SettingsHybrid.cc @@ -15,7 +15,8 @@ #include #include #include -#include +#include +#include using namespace std; using namespace edm; @@ -75,6 +76,7 @@ namespace trackerDTC { basesR_.reserve(numSensorTypes); for (int type = 0; type < numSensorTypes; type++) basesR_.push_back(rangesR_[type] / pow(2., widthsR_[type])); + basesR_[disk2S] = 1.; basesPhi_.reserve(numSensorTypes); for (int type = 0; type < numSensorTypes; type++) @@ -100,6 +102,8 @@ namespace trackerDTC { settings->baseR_ = *min_element(basesR_.begin(), basesR_.end(), comp); settings->basePhi_ = *min_element(basesPhi_.begin(), basesPhi_.end(), comp); settings->baseQoverPt_ = settings->rangeQoverPt_ / pow(2., settings->widthQoverPt_); + + layerIdEncodings_.reserve(settings->numDTCsPerRegion_); } // check current coniguration consistency with input configuration @@ -132,28 +136,25 @@ namespace trackerDTC { } void SettingsHybrid::createEncodingsLayer(Settings* settings) { - layerIdEncodings_.reserve(settings->numDTCs_); - for (int dtcId = 0; dtcId < settings->numDTCs_; dtcId++) { - auto begin = next(settings->cablingMap_.begin(), dtcId * settings->numModulesPerDTC_); - auto end = next(begin, settings->numModulesPerDTC_); - auto last = find_if(begin, end, [](const DetId& detId) { return detId.null(); }); - if (last < end) - end = last; - // assess layerIds connected to this DTC - set layerIds; - for (auto it = begin; it < end; it++) - layerIds.insert(it->subdetId() == StripSubdetector::TOB - ? settings->trackerTopology_->layer(*it) - : settings->trackerTopology_->tidWheel(*it) + settings->offsetLayerDisks_); + const TrackerTopology* trackerTopology = settings->trackerTopology_; + // assess layerIds connected to each DTC per region, accumulated over all regions + vector> layerIdEncodings(settings->numDTCsPerRegion_); + for (const pair& map : settings->cablingMap_) { + const bool barrel = map.first.subdetId() == StripSubdetector::TOB; + const int layerId = barrel ? trackerTopology->layer(map.first) : trackerTopology->tidWheel(map.first) + 10; + const int dtcId = (map.second / settings->numModulesPerDTC_) % settings->numDTCsPerRegion_; + layerIdEncodings[dtcId].insert(layerId); + } + for (const set& layerIdEncoding : layerIdEncodings) { // check configuration - if ((int)layerIds.size() > settings->numLayers_) { + if ((int)layerIdEncoding.size() > settings->numLayers_) { cms::Exception exception("overflow"); - exception << "Cabling map connects more than " << settings->numLayers_ << " layers to DTC " << dtcId << "."; - exception.addContext("trackerDTC::SettingsHybrid::beginRun"); + exception << "Cabling map connects more than " << settings->numLayers_ << " layers to a DTC."; + exception.addContext("trackerDTC::SettingsHybrid::createEncodingsLayer"); throw exception; } // index = decoded layerId, value = encoded layerId - layerIdEncodings_.emplace_back(layerIds.begin(), layerIds.end()); + layerIdEncodings_.emplace_back(layerIdEncoding.begin(), layerIdEncoding.end()); } } diff --git a/L1Trigger/TrackerDTC/src/Stub.cc b/L1Trigger/TrackerDTC/src/Stub.cc index 1040a091d3703..5596b0ebc60eb 100644 --- a/L1Trigger/TrackerDTC/src/Stub.cc +++ b/L1Trigger/TrackerDTC/src/Stub.cc @@ -120,12 +120,14 @@ namespace trackerDTC { return; // stub r w.r.t. an offset in cm - r_ -= module->offsetR_; + r_ -= module->offsetR_ - settings_->chosenRofPhi(); // stub z w.r.t. an offset in cm z_ -= module->offsetZ_; - if (module->type_ == SettingsHybrid::disk2S) + if (module->type_ == SettingsHybrid::disk2S) { // decoded r - r_ = (module->decodedR_ + .5) * settings_->hybrid()->baseR(module->type_); + r_ = module->decodedR_ + (module->side_ ? -col_ : (col_ + module->numColumns_ / 2)); + r_ = (r_ + 0.5) * settings_->hybrid()->baseR(module->type_); + } // decode bend const vector& bendEncoding = module->bendEncoding_; @@ -138,12 +140,6 @@ namespace trackerDTC { return settings_->dataFormat() == "Hybrid" ? formatHybrid(region) : formatTMTT(region); } - // outer tracker dtc routing block id [0-1] - int Stub::blockId() const { return module_->blockId_; } - - // outer tracker dtc routing block channel id [0-35] - int Stub::channelId() const { return module_->blockChannelId_; } - // returns true if stub belongs to region bool Stub::inRegion(int region) const { return find(regions_.begin(), regions_.end(), region) != regions_.end(); } diff --git a/L1Trigger/TrackerDTC/test/test_cfg.py b/L1Trigger/TrackerDTC/test/test_cfg.py index 51e020112874d..8d46b9ca00672 100644 --- a/L1Trigger/TrackerDTC/test/test_cfg.py +++ b/L1Trigger/TrackerDTC/test/test_cfg.py @@ -5,86 +5,79 @@ ################################################################################################# import FWCore.ParameterSet.Config as cms -import FWCore.ParameterSet.VarParsing as VarParsing process = cms.Process( "Demo" ) - process.load( 'Configuration.Geometry.GeometryExtended2026D49Reco_cff' ) process.load( 'Configuration.Geometry.GeometryExtended2026D49_cff' ) process.load( 'Configuration.StandardSequences.MagneticField_cff' ) process.load( 'Configuration.StandardSequences.FrontierConditions_GlobalTag_cff' ) process.load( 'Configuration.StandardSequences.L1TrackTrigger_cff' ) +process.load( "FWCore.MessageLogger.MessageLogger_cfi" ) from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag( process.GlobalTag, 'auto:phase2_realistic', '' ) -# uncomment next 8 lines to use local cabling map -#process.load("CondCore.CondDB.CondDB_cfi") -#process.CondDB.connect = 'sqlite_file:__PATH_TO_DB__/__FILE_NAME__.db' -#process.PoolDBESSource = cms.ESSource( -# "PoolDBESSource", process.CondDB, toGet = cms.VPSet( cms.PSet( -# record = cms.string( 'TrackerDetToDTCELinkCablingMapRcd' ), -# tag = cms.string( "__CHOSEN_TAG__" ) -#) ) ) -#process.es_prefer_local_TrackerDetToDTCELinkCablingMapRcd = cms.ESPrefer( "PoolDBESSource", "" ) +#--- Load code that produces DTCStubs +process.load( 'L1Trigger.TrackerDTC.Producer_cff' ) +process.produce = cms.Path( process.TrackerDTCProducer ) +#from L1Trigger.TrackerDTC.Producer_Customize_cff import useTMTT +#useTMTT(process) -process.load( "FWCore.MessageLogger.MessageLogger_cfi" ) +#--- Load code that analyzes DTCStubs +process.load( 'L1Trigger.TrackerDTC.Analyzer_cff' ) +process.analyze = cms.Path( process.TrackerDTCAnalyzer ) +#from L1Trigger.TrackerDTC.Analyzer_Customize_cff import useTMTT +#useTMTT(process) -options = VarParsing.VarParsing( 'analysis' ) +process.schedule = cms.Schedule( process.produce, process.analyze ) +import FWCore.ParameterSet.VarParsing as VarParsing +options = VarParsing.VarParsing( 'analysis' ) #--- Specify input MC -options.register( 'inputMC', +Samples = { '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/0330453B-9B8E-CA41-88B0-A047B68D1AF9.root', - VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "Files to be processed" -) - + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/02180D14-024D-ED46-9899-B275EADB82CE.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/0207F436-9BAC-904D-B86A-C2CE18CC2A46.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/01323A12-1A0B-AE43-B7AB-BAAE294E4EFA.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/D87319E3-F541-5840-AA58-10F84ACE1523.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/D7384F02-54C2-AB49-AEF3-E4E7303541CA.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/D3629C85-EA34-C147-AC4D-939C41DEC68A.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/D253E174-69A1-A544-9719-0D9BFDAD5320.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/D0D41CBC-08BA-E14E-8FE9-BD982CC6CA95.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/CD22CEB0-26EE-3147-8076-82926A26FAD4.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/CB67FBC0-0BF9-BE4E-A6D6-1388B2B2D2BF.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/CB36BB1A-67D7-C04D-ADB9-50DEB9B49E73.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C9DEB7AA-E520-8C4C-AE74-A482BF59B048.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C8ABAD54-6291-FA44-92E1-5BEECB1D6793.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C74CD357-330E-E442-8F9F-C060CA44964A.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C6BD36D2-79B9-2142-9A17-1CCC4FA2DDF1.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C5DE1FC8-F963-7641-8020-451DB641C609.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C57720E8-F837-0448-8483-D06474BB316B.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C41FF339-435A-EC4A-A830-3D9DB7630B0A.root', + '/store/relval/CMSSW_11_1_0_pre1/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU25ns_110X_mcRun4_realistic_v2_2026D49PU200_ext1-v1/20000/C38AE82D-587E-C34B-89DC-FBAE92696270.root' +} +options.register( 'inputMC', Samples, VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.string, "Files to be processed" ) #--- Specify number of events to process. options.register( 'Events',100,VarParsing.VarParsing.multiplicity.singleton, VarParsing.VarParsing.varType.int, "Number of Events to analyze" ) - -#--- Specify whether to output a GEN-SIM-DIGI-RAW dataset containing the DTCStub Collections. -options.register( 'outputDataset' ,0 ,VarParsing.VarParsing.multiplicity.singleton ,VarParsing.VarParsing.varType.int, "Create GEN-SIM-DIGI-RAW dataset containing DTCStub Collections" ) - options.parseArguments() -#--- input and output - process.options = cms.untracked.PSet( wantSummary = cms.untracked.bool(False) ) - process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(options.Events) ) - process.source = cms.Source( "PoolSource", fileNames = cms.untracked.vstring( options.inputMC ), secondaryFileNames = cms.untracked.vstring(), duplicateCheckMode = cms.untracked.string( 'noDuplicateCheck' ) ) - process.Timing = cms.Service( "Timing", summaryOnly = cms.untracked.bool( True ) ) +process.TFileService = cms.Service( "TFileService", fileName = cms.string( "Hist.root" ) ) -#--- Load code that produces DTCStubs -process.load( 'L1Trigger.TrackerDTC.Producer_cff' ) - -process.p = cms.Path( process.TrackerDTCProducer ) - -# Optionally create output GEN-SIM-DIGI-RAW dataset containing DTC TTStub Collections. -if options.outputDataset == 1: - - # Write output dataset - process.load( 'Configuration.EventContent.EventContent_cff' ) - - process.writeDataset = cms.OutputModule( - "PoolOutputModule", - splitLevel = cms.untracked.int32( 0 ), - eventAutoFlushCompressedSize = cms.untracked.int32( 5242880 ), - outputCommands = process.RAWSIMEventContent.outputCommands, - fileName = cms.untracked.string( 'output_dataset.root' ), ## ADAPT IT ## - dataset = cms.untracked.PSet( - filterName = cms.untracked.string(''), - dataTier = cms.untracked.string( 'GEN-SIM' ) - ) - ) - # Include DTC TTStub Collections - process.writeDataset.outputCommands.append( 'keep *_TrackerDTCProducer_StubAccepted_*' ) - process.pd = cms.EndPath( process.writeDataset ) - - process.schedule = cms.Schedule( process.p, process.pd ) +# uncomment next 8 lines to use local cabling map +#process.load("CondCore.CondDB.CondDB_cfi") +#process.CondDB.connect = 'sqlite_file:__PATH_TO_DB__/__FILE_NAME__.db' +#process.PoolDBESSource = cms.ESSource( +# "PoolDBESSource", process.CondDB, toGet = cms.VPSet( cms.PSet( +# record = cms.string( 'TrackerDetToDTCELinkCablingMapRcd' ), +# tag = cms.string( "__CHOSEN_TAG__" ) +#) ) ) +#process.es_prefer_local_TrackerDetToDTCELinkCablingMapRcd = cms.ESPrefer( "PoolDBESSource", "" ) \ No newline at end of file From c7442dfeb3d7132930cb6d2f7acfeb24a18e11e8 Mon Sep 17 00:00:00 2001 From: Thomas Schuh Date: Wed, 29 Apr 2020 14:06:56 +0100 Subject: [PATCH 2/2] Some dtcId conversion functions added to TTDTC. --- DataFormats/L1TrackTrigger/interface/TTDTC.h | 83 ++++++++++++-------- DataFormats/L1TrackTrigger/src/TTDTC.cc | 67 +++++++++++----- 2 files changed, 100 insertions(+), 50 deletions(-) diff --git a/DataFormats/L1TrackTrigger/interface/TTDTC.h b/DataFormats/L1TrackTrigger/interface/TTDTC.h index 76e461db4753d..a8c4a1fc8d54e 100644 --- a/DataFormats/L1TrackTrigger/interface/TTDTC.h +++ b/DataFormats/L1TrackTrigger/interface/TTDTC.h @@ -16,59 +16,80 @@ */ class TTDTC { public: - // outer tracker DTC types - typedef std::bitset BV; // bit accurate Stub - typedef std::pair Frame; // TTStub with bit accurate Stub - typedef std::vector Stream; // stub collection transported over an optical link between DTC and TFP - typedef std::vector Streams; // collection of optical links + // bit accurate Stub + typedef std::bitset BV; + // TTStub with bit accurate Stub + typedef std::pair Frame; + // stub collection transported over an optical link between DTC and TFP + typedef std::vector Stream; + // collection of optical links + typedef std::vector Streams; + +private: + // number of ATCA slots per shelf + static constexpr int numSlots_ = 12; public: TTDTC() {} - TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion); - ~TTDTC() {} - // Access to product configurations - int numRegions() const; - int numDTCBoards() const; - int numDTCChannel() const; - int numTFPChannel() const; - + // number of phi slices the outer tracker readout is organized in [default 9] + int numRegions() const { return numRegions_; } + // number of DTC boards used to readout a detector region [default 24] + int numDTCBoards() const { return numDTCsPerRegion_; } + // number of regions a reconstructable particle may cross [default 2] + int numDTCChannel() const { return numOverlappingRegions_; } + // number of DTC boards connected to one TFP [default 48] + int numTFPChannel() const { return numDTCsPerTFP_; } + // all regions [default 0..8] + const std::vector& tfpRegions() const { return regions_; } + // all TFP channel [default 0..47] + const std::vector& tfpChannels() const { return channels_; } // write one specific stream of TTStubRefs using DTC identifier (region[0-8], board[0-23], channel[0-1]) // dtcRegions aka detector regions are defined by tk layout void setStream(int dtcRegion, int dtcBoard, int dtcChannel, const Stream& stream); - - // all TFP identifier (region[0-8], channel[0-47]) - std::vector tfpRegions() const; - std::vector tfpChannels() const; - // read one specific stream of TTStubRefs using TFP identifier (region[0-8], channel[0-47]) // tfpRegions aka processing regions are rotated by -0.5 region width w.r.t detector regions const Stream& stream(int tfpRegion, int tfpChannel) const; - + // total number of frames + int size() const; + // total number of stubs + int nStubs() const; + // total number of gaps + int nGaps() const; // converts dtc id into tk layout scheme int tkLayoutId(int dtcId) const; - // converts tk layout id into dtc id int dtcId(int tkLayoutId) const; + // converts TFP identifier (region[0-8], channel[0-47]) into dtcId [0-215] + int dtcId(int tfpRegion, int tfpChannel) const; + // checks if given dtcId is connected to PS or 2S sensormodules + bool psModlue(int dtcId) const; + // checks if given dtcId is connected to -z (false) or +z (true) + bool side(int dtcId) const; + // ATCA slot number [0-11] of given dtcId + int slot(int dtcId) const; private: // converts DTC identifier (region[0-8], board[0-23], channel[0-1]) into allStreams_ index [0-431] int index(int dtcRegion, int dtcBoard, int dtcChannel) const; - // converts TFP identifier (region[0-8], channel[0-47]) into allStreams_ index [0-431] int index(int tfpRegion, int tfpChannel) const; - -private: - static constexpr int numSlots_ = 12; // number of ATCA slots per shelf - - int numRegions_; // number of phi slices the outer tracker readout is organized in [default 9] - int numOverlappingRegions_; // number of regions a reconstructable particle may cross [default 2] - int numDTCsPerRegion_; // number of DTC boards used to readout a detector region [default 24] - int numDTCsPerTFP_; // number of DTC boards connected to one TFP [default 48] - - Streams streams_; // collection of all optical links between DTC and TFP [default 432 links] + // number of phi slices the outer tracker readout is organized in [default 9] + int numRegions_; + // number of regions a reconstructable particle may cross [default 2] + int numOverlappingRegions_; + // number of DTC boards used to readout a detector region [default 24] + int numDTCsPerRegion_; + // number of DTC boards connected to one TFP [default 48] + int numDTCsPerTFP_; + // all regions [default 0..8] + std::vector regions_; + // all TFP channel [default 0..47] + std::vector channels_; + // collection of all optical links between DTC and TFP [default 432 links] + Streams streams_; }; #endif \ No newline at end of file diff --git a/DataFormats/L1TrackTrigger/src/TTDTC.cc b/DataFormats/L1TrackTrigger/src/TTDTC.cc index d482792ac7d39..29152e8217a07 100644 --- a/DataFormats/L1TrackTrigger/src/TTDTC.cc +++ b/DataFormats/L1TrackTrigger/src/TTDTC.cc @@ -11,13 +11,12 @@ TTDTC::TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion) numOverlappingRegions_(numOverlappingRegions), numDTCsPerRegion_(numDTCsPerRegion), numDTCsPerTFP_(numOverlappingRegions * numDTCsPerRegion), - streams_(numRegions_ * numDTCsPerRegion_ * numOverlappingRegions_) {} - -// Access to product configurations -int TTDTC::numRegions() const { return numRegions_; } -int TTDTC::numDTCBoards() const { return numDTCsPerRegion_; } -int TTDTC::numDTCChannel() const { return numOverlappingRegions_; } -int TTDTC::numTFPChannel() const { return numDTCsPerTFP_; } + regions_(numRegions_), + channels_(numDTCsPerRegion_ * numOverlappingRegions_), + streams_(numRegions_ * channels_.size()) { + iota(regions_.begin(), regions_.end(), 0); + iota(channels_.begin(), channels_.end(), 0); +} // write one specific stream of TTStubRefs using DTC identifier (region[0-8], board[0-23], channel[0-1]) // dtcRegions aka detector regions are defined by tk layout @@ -43,18 +42,6 @@ void TTDTC::setStream(int dtcRegion, int dtcBoard, int dtcChannel, const Stream& streams_[index(dtcRegion, dtcBoard, dtcChannel)] = move(stream); } -// all TFP identifier (region[0-8], channel[0-47]) -vector TTDTC::tfpRegions() const { - vector vec(numRegions_); - iota(vec.begin(), vec.end(), 0); - return vec; -} -vector TTDTC::tfpChannels() const { - vector vec(numDTCsPerTFP_); - iota(vec.begin(), vec.end(), 0); - return vec; -} - // read one specific stream of TTStubRefs using TFP identifier (region[0-8], channel[0-47]) // tfpRegions aka processing regions are rotated by -0.5 region width w.r.t detector regions const TTDTC::Stream& TTDTC::stream(int tfpRegion, int tfpChannel) const { @@ -75,6 +62,30 @@ const TTDTC::Stream& TTDTC::stream(int tfpRegion, int tfpChannel) const { return streams_.at(index(tfpRegion, tfpChannel)); } +// total number of frames +int TTDTC::size() const { + auto all = [](int& sum, const Stream& stream) { return sum += stream.size(); }; + return accumulate(streams_.begin(), streams_.end(), 0, all); +} + +// total number of stubs +int TTDTC::nStubs() const { + auto stubs = [](int& sum, const Frame& frame) { return sum += frame.first.isNonnull(); }; + int n(0); + for (const Stream& stream : streams_) + n += accumulate(stream.begin(), stream.end(), 0, stubs); + return n; +} + +// total number of gaps +int TTDTC::nGaps() const { + auto gaps = [](int& sum, const Frame& frame) { return sum += frame.first.isNull(); }; + int n(0); + for (const Stream& stream : streams_) + n += accumulate(stream.begin(), stream.end(), 0, gaps); + return n; +} + // converts dtc id into tk layout scheme int TTDTC::tkLayoutId(int dtcId) const { // check argument @@ -107,6 +118,24 @@ int TTDTC::dtcId(int tkLayoutId) const { return region * numDTCsPerRegion_ + side * numSlots_ + slot; } +// converts TFP identifier (region[0-8], channel[0-47]) into dtc id +int TTDTC::dtcId(int tfpRegion, int tfpChannel) const { return index(tfpRegion, tfpChannel) / numOverlappingRegions_; } + +// checks if given DTC id is connected to PS or 2S sensormodules +bool TTDTC::psModlue(int dtcId) const { + // from tklayout: first 3 are 10 gbps PS, next 3 are 5 gbps PS and residual 6 are 5 gbps 2S modules + return slot(dtcId) < numSlots_ / 2; +} + +// checks if given dtcId is connected to -z (false) or +z (true) +bool TTDTC::side(int dtcId) const { + const int side = (dtcId % numDTCsPerRegion_) / numSlots_; + // from tkLayout: first 12 +z, next 12 -z + return side == 0; +} +// ATCA slot number [0-11] of given dtcId +int TTDTC::slot(int dtcId) const { return dtcId % numSlots_; } + // converts DTC identifier (region[0-8], board[0-23], channel[0-1]) into streams_ index [0-431] int TTDTC::index(int dtcRegion, int dtcBoard, int dtcChannel) const { return (dtcRegion * numDTCsPerRegion_ + dtcBoard) * numOverlappingRegions_ + dtcChannel;