From edfbf92343624d7669cab3495698f712f5a1b7be Mon Sep 17 00:00:00 2001 From: Pieter David Date: Wed, 31 Mar 2021 16:39:39 +0200 Subject: [PATCH 1/5] remove ShallowEventRun from strip gains PCL worker sequence --- .../SiStripChannelGain/interface/SiStripGainsPCLWorker.h | 3 --- .../SiStripChannelGain/src/SiStripGainsPCLWorker.cc | 6 ------ .../python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py | 5 +---- .../python/ALCARECOPromptCalibProdSiStripGains_cff.py | 5 +---- 4 files changed, 2 insertions(+), 17 deletions(-) diff --git a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h index 3281c2e576e0a..1f55d8be84690 100644 --- a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h +++ b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h @@ -113,7 +113,6 @@ class SiStripGainsPCLWorker : public DQMGlobalEDAnalyzer > TrigTech_token_; edm::EDGetTokenT > trackchi2ndof_token_; edm::EDGetTokenT > trackp_token_; edm::EDGetTokenT > trackpt_token_; @@ -143,8 +142,6 @@ class SiStripGainsPCLWorker : public DQMGlobalEDAnalyzer gainToken_; edm::ESGetToken qualityToken_; - std::string EventPrefix_; //(""); - std::string EventSuffix_; //(""); std::string TrackPrefix_; //("track"); std::string TrackSuffix_; //(""); std::string CalibPrefix_; //("GainCalibration"); diff --git a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc index e10d14d05da40..fe6d3a06f0961 100644 --- a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc +++ b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc @@ -80,12 +80,6 @@ SiStripGainsPCLWorker::SiStripGainsPCLWorker(const edm::ParameterSet& iConfig) { gainusedTick_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "gainusedTick" + CalibSuffix_)); - edm::ParameterSet evtinfo_pset = iConfig.getUntrackedParameter("evtinfo"); - label = evtinfo_pset.getUntrackedParameter("label"); - EventPrefix_ = evtinfo_pset.getUntrackedParameter("prefix"); - EventSuffix_ = evtinfo_pset.getUntrackedParameter("suffix"); - TrigTech_token_ = consumes>(edm::InputTag(label, EventPrefix_ + "TrigTech" + EventSuffix_)); - edm::ParameterSet track_pset = iConfig.getUntrackedParameter("tracks"); label = track_pset.getUntrackedParameter("label"); TrackPrefix_ = track_pset.getUntrackedParameter("prefix"); diff --git a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py index 191c7acee4697..6b1f0aa834d3e 100644 --- a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py +++ b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py @@ -70,13 +70,11 @@ # ------------------------------------------------------------------------------ # Get the information you need from the tracks, calibTree-style to have no code difference -from CalibTracker.SiStripCommon.ShallowEventDataProducer_cfi import shallowEventRun from CalibTracker.SiStripCommon.ShallowTracksProducer_cfi import shallowTracks from CalibTracker.SiStripCommon.ShallowGainCalibration_cfi import shallowGainCalibration -ALCARECOShallowEventRunAAG = shallowEventRun.clone() ALCARECOShallowTracksAAG = shallowTracks.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefitAAG')) ALCARECOShallowGainCalibrationAAG = shallowGainCalibration.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefitAAG')) -ALCARECOShallowSequenceAAG = cms.Sequence(ALCARECOShallowEventRunAAG*ALCARECOShallowTracksAAG*ALCARECOShallowGainCalibrationAAG) +ALCARECOShallowSequenceAAG = cms.Sequence(ALCARECOShallowTracksAAG*ALCARECOShallowGainCalibrationAAG) # ------------------------------------------------------------------------------ # This is the module actually doing the calibration @@ -86,7 +84,6 @@ ALCARECOSiStripCalibAAG.DQMdir = cms.untracked.string('AlCaReco/SiStripGainsAAG') ALCARECOSiStripCalibAAG.calibrationMode = cms.untracked.string('AagBunch') ALCARECOSiStripCalibAAG.gain.label = cms.untracked.string('ALCARECOShallowGainCalibrationAAG') -ALCARECOSiStripCalibAAG.evtinfo.label = cms.untracked.string('ALCARECOShallowEventRunAAG') ALCARECOSiStripCalibAAG.tracks.label = cms.untracked.string('ALCARECOShallowTracksAAG') # ---------------------------------------------------------------------------- diff --git a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py index 5f39af2ae57ee..2f8a1fa8123bc 100644 --- a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py +++ b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py @@ -69,13 +69,11 @@ # ------------------------------------------------------------------------------ # Get the information you need from the tracks, calibTree-style to have no code difference -from CalibTracker.SiStripCommon.ShallowEventDataProducer_cfi import shallowEventRun from CalibTracker.SiStripCommon.ShallowTracksProducer_cfi import shallowTracks from CalibTracker.SiStripCommon.ShallowGainCalibration_cfi import shallowGainCalibration -ALCARECOShallowEventRun = shallowEventRun.clone() ALCARECOShallowTracks = shallowTracks.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefit')) ALCARECOShallowGainCalibration = shallowGainCalibration.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefit')) -ALCARECOShallowSequence = cms.Sequence(ALCARECOShallowEventRun*ALCARECOShallowTracks*ALCARECOShallowGainCalibration) +ALCARECOShallowSequence = cms.Sequence(ALCARECOShallowTracks*ALCARECOShallowGainCalibration) # ------------------------------------------------------------------------------ # This is the module actually doing the calibration @@ -85,7 +83,6 @@ ALCARECOSiStripCalib.DQMdir = cms.untracked.string('AlCaReco/SiStripGains') ALCARECOSiStripCalib.calibrationMode = cms.untracked.string('StdBunch') ALCARECOSiStripCalib.gain.label = cms.untracked.string('ALCARECOShallowGainCalibration') -ALCARECOSiStripCalib.evtinfo.label = cms.untracked.string('ALCARECOShallowEventRun') ALCARECOSiStripCalib.tracks.label = cms.untracked.string('ALCARECOShallowTracks') # ---------------------------------------------------------------------------- From fb51bd9d063e49415e0f93447fd1d229ba9d1678 Mon Sep 17 00:00:00 2001 From: Pieter David Date: Thu, 1 Apr 2021 14:19:05 +0200 Subject: [PATCH 2/5] Strips G2 PCL without shallow tracks, first take (compiling) --- .../interface/SiStripGainsPCLWorker.h | 35 +- .../python/SiStripGainsPCLWorker_cfi.py | 14 +- .../src/SiStripGainsPCLWorker.cc | 512 ++++++++---------- ...ARECOPromptCalibProdSiStripGainsAAG_cff.py | 23 +- ...ALCARECOPromptCalibProdSiStripGains_cff.py | 21 +- 5 files changed, 256 insertions(+), 349 deletions(-) diff --git a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h index 1f55d8be84690..c3aef2499eb5e 100644 --- a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h +++ b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h @@ -13,6 +13,7 @@ // A. Di Mattia (PCL multi stream processing and monitoring) // M. Delcourt (monitoring) // M. Musich (migration to thread-safe DQMStore access) +// P. David (merge ShallowGainCalibration with SiStripGainsPCLWorker) // // Created: Wed, 12 Apr 2017 14:46:48 GMT // @@ -111,42 +112,14 @@ class SiStripGainsPCLWorker : public DQMGlobalEDAnalyzer VChargeHisto; /*!< Charge monitor plots to be output */ - //Data members for processing - - edm::EDGetTokenT > trackchi2ndof_token_; - edm::EDGetTokenT > trackp_token_; - edm::EDGetTokenT > trackpt_token_; - edm::EDGetTokenT > tracketa_token_; - edm::EDGetTokenT > trackphi_token_; - edm::EDGetTokenT > trackhitsvalid_token_; - edm::EDGetTokenT > trackalgo_token_; - edm::EDGetTokenT > trackindex_token_; - edm::EDGetTokenT > rawid_token_; - edm::EDGetTokenT > localdirx_token_; - edm::EDGetTokenT > localdiry_token_; - edm::EDGetTokenT > localdirz_token_; - edm::EDGetTokenT > firststrip_token_; - edm::EDGetTokenT > nstrips_token_; - edm::EDGetTokenT > saturation_token_; - edm::EDGetTokenT > overlapping_token_; - edm::EDGetTokenT > farfromedge_token_; - edm::EDGetTokenT > charge_token_; - edm::EDGetTokenT > path_token_; - edm::EDGetTokenT > chargeoverpath_token_; - edm::EDGetTokenT > amplitude_token_; - edm::EDGetTokenT > gainused_token_; - edm::EDGetTokenT > gainusedTick_token_; + edm::EDGetTokenT> m_tracks_token; + edm::EDGetTokenT m_association_token; edm::ESGetToken tTopoToken_; - edm::ESGetToken tkGeomToken_; + edm::ESGetToken tkGeomTokenBR_, tkGeomToken_; edm::ESGetToken gainToken_; edm::ESGetToken qualityToken_; - std::string TrackPrefix_; //("track"); - std::string TrackSuffix_; //(""); - std::string CalibPrefix_; //("GainCalibration"); - std::string CalibSuffix_; //(""); - // maps histograms index to topology std::map theTopologyMap; }; diff --git a/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py b/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py index cf71afd80c963..dff525f9166ab 100644 --- a/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py +++ b/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py @@ -12,17 +12,5 @@ DQMdir = cms.untracked.string('AlCaReco/SiStripGains'), calibrationMode = cms.untracked.string('StdBunch'), ChargeHisto = cms.untracked.vstring('TIB','TIB_layer_1','TOB','TOB_layer_1','TIDminus','TIDplus','TECminus','TECplus','TEC_thin','TEC_thick'), - gain = cms.untracked.PSet(label = cms.untracked.string('shallowGainCalibration'), - prefix = cms.untracked.string("GainCalibration"), - suffix = cms.untracked.string('') - ), - evtinfo = cms.untracked.PSet(label = cms.untracked.string('shallowEventRun'), - prefix = cms.untracked.string(""), - suffix = cms.untracked.string('') - ), - tracks = cms.untracked.PSet(label = cms.untracked.string('shallowTracks'), - prefix = cms.untracked.string("track"), - suffix = cms.untracked.string('') - ) + tracks=cms.InputTag("generalTracks",""), ) - diff --git a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc index fe6d3a06f0961..dee3eb1703419 100644 --- a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc +++ b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc @@ -50,52 +50,12 @@ SiStripGainsPCLWorker::SiStripGainsPCLWorker(const edm::ParameterSet& iConfig) { dqm_tag_.push_back("IsoMuon0T"); // statistic collection from Isolated Muon @ 0 T dqm_tag_.push_back("Harvest"); // statistic collection: Harvest - // configure token for gathering the ntuple variables - edm::ParameterSet swhallowgain_pset = iConfig.getUntrackedParameter("gain"); - - std::string label = swhallowgain_pset.getUntrackedParameter("label"); - CalibPrefix_ = swhallowgain_pset.getUntrackedParameter("prefix"); - CalibSuffix_ = swhallowgain_pset.getUntrackedParameter("suffix"); - - trackindex_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "trackindex" + CalibSuffix_)); - rawid_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "rawid" + CalibSuffix_)); - localdirx_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "localdirx" + CalibSuffix_)); - localdiry_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "localdiry" + CalibSuffix_)); - localdirz_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "localdirz" + CalibSuffix_)); - firststrip_token_ = - consumes>(edm::InputTag(label, CalibPrefix_ + "firststrip" + CalibSuffix_)); - nstrips_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "nstrips" + CalibSuffix_)); - saturation_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "saturation" + CalibSuffix_)); - overlapping_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "overlapping" + CalibSuffix_)); - farfromedge_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "farfromedge" + CalibSuffix_)); - charge_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "charge" + CalibSuffix_)); - path_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "path" + CalibSuffix_)); -#ifdef ExtendedCALIBTree - chargeoverpath_token_ = - consumes>(edm::InputTag(label, CalibPrefix_ + "chargeoverpath" + CalibSuffix_)); -#endif - amplitude_token_ = - consumes>(edm::InputTag(label, CalibPrefix_ + "amplitude" + CalibSuffix_)); - gainused_token_ = consumes>(edm::InputTag(label, CalibPrefix_ + "gainused" + CalibSuffix_)); - gainusedTick_token_ = - consumes>(edm::InputTag(label, CalibPrefix_ + "gainusedTick" + CalibSuffix_)); - - edm::ParameterSet track_pset = iConfig.getUntrackedParameter("tracks"); - label = track_pset.getUntrackedParameter("label"); - TrackPrefix_ = track_pset.getUntrackedParameter("prefix"); - TrackSuffix_ = track_pset.getUntrackedParameter("suffix"); - - trackchi2ndof_token_ = consumes>(edm::InputTag(label, TrackPrefix_ + "chi2ndof" + TrackSuffix_)); - trackp_token_ = consumes>(edm::InputTag(label, TrackPrefix_ + "momentum" + TrackSuffix_)); - trackpt_token_ = consumes>(edm::InputTag(label, TrackPrefix_ + "pt" + TrackSuffix_)); - tracketa_token_ = consumes>(edm::InputTag(label, TrackPrefix_ + "eta" + TrackSuffix_)); - trackphi_token_ = consumes>(edm::InputTag(label, TrackPrefix_ + "phi" + TrackSuffix_)); - trackhitsvalid_token_ = - consumes>(edm::InputTag(label, TrackPrefix_ + "hitsvalid" + TrackSuffix_)); - trackalgo_token_ = consumes>(edm::InputTag(label, TrackPrefix_ + "algo" + TrackSuffix_)); + m_tracks_token = consumes>(iConfig.getParameter("tracks")); + m_association_token = consumes(iConfig.getParameter("tracks")); tTopoToken_ = esConsumes(); - tkGeomToken_ = esConsumes(); + tkGeomTokenBR_ = esConsumes(); + tkGeomToken_ = esConsumes<>(); gainToken_ = esConsumes(); qualityToken_ = esConsumes(); } @@ -108,7 +68,7 @@ void SiStripGainsPCLWorker::dqmBeginRun(edm::Run const& run, static constexpr float defaultGainTick = 690. / 640.; // fills the APV collections at each begin run - const TrackerGeometry* bareTkGeomPtr = &iSetup.getData(tkGeomToken_); + const TrackerGeometry* bareTkGeomPtr = &iSetup.getData(tkGeomTokenBR_); checkBookAPVColls(bareTkGeomPtr, histograms); const auto gainHandle = iSetup.getHandle(gainToken_); @@ -151,6 +111,63 @@ void SiStripGainsPCLWorker::dqmBeginRun(edm::Run const& run, } } +namespace { + struct HitCluster { + uint32_t det; + const SiStripCluster* strip; + const SiPixelCluster* pixel; + HitCluster(uint32_t detId, const SiStripCluster* strip, const SiPixelCluster* pixel) + : det(detId), strip(strip), pixel(pixel) {} + }; + std::vector getClusters(const TrackingRecHit* hit) { + const auto simple1d = dynamic_cast(hit); + const auto simple = dynamic_cast(hit); + const auto matched = dynamic_cast(hit); + const auto pixel = dynamic_cast(hit); + std::vector clusters; + if (matched) { + clusters.emplace_back(matched->monoId(), &matched->monoCluster(), nullptr); + clusters.emplace_back(matched->stereoId(), &matched->stereoCluster(), nullptr); + } else if (simple) { + clusters.emplace_back(simple->geographicalId().rawId(), simple->cluster().get(), nullptr); + } else if (simple1d) { + clusters.emplace_back(simple1d->geographicalId().rawId(), simple1d->cluster().get(), nullptr); + } else if (pixel) { + clusters.emplace_back(pixel->geographicalId().rawId(), nullptr, pixel->cluster().get()); + } + return clusters; + } + + bool isFarFromBorder(const TrajectoryStateOnSurface& trajState, uint32_t detId, const TrackerGeometry* tGeom) { + const auto gdu = tGeom->idToDetUnit(detId); + if ((!dynamic_cast(gdu)) && (!dynamic_cast(gdu))) { + edm::LogWarning("SiStripGainCalibTableProducer") + << "DetId " << detId << " does not seem to belong to the tracker"; + return false; + } + const auto plane = gdu->surface(); + const auto trapBounds = dynamic_cast(&plane.bounds()); + const auto rectBounds = dynamic_cast(&plane.bounds()); + + static constexpr double distFromBorder = 1.0; + double halfLength = 0.; + if (trapBounds) { + halfLength = trapBounds->parameters()[3]; + } else if (rectBounds) { + halfLength = .5 * gdu->surface().bounds().length(); + } else { + return false; + } + + const auto pos = trajState.localPosition(); + const auto posError = trajState.localError().positionError(); + if (std::abs(pos.y()) + posError.yy() >= (halfLength - distFromBorder)) + return false; + + return true; + } +} // namespace + //********************************************************************************// // ------------ method called for each event ------------ void SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, @@ -164,88 +181,13 @@ void SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, edm::LogInfo("SiStripGainsPCLWorker") << "Processing run " << runnumber << " and event " << eventnumber << std::endl; const TrackerTopology* topo = &iSetup.getData(tTopoToken_); + const TrackerGeometry* tGeom = &iSetup.getData(tkGeomToken_); - // ***************************** - // * Event data handles - // ***************************** - - //Event data - - // Track data - Handle> handle01; - iEvent.getByToken(trackchi2ndof_token_, handle01); - auto trackchi2ndof = handle01.product(); - - Handle> handle02; - iEvent.getByToken(trackp_token_, handle02); - auto trackp = handle02.product(); - - Handle> handle03; - iEvent.getByToken(tracketa_token_, handle03); - auto tracketa = handle03.product(); - - Handle> handle04; - iEvent.getByToken(trackhitsvalid_token_, handle04); - auto trackhitsvalid = handle04.product(); - - Handle> handle05; - iEvent.getByToken(trackalgo_token_, handle05); - auto trackalgo = handle05.product(); - - // CalibTree data - Handle> handle06; - iEvent.getByToken(trackindex_token_, handle06); - auto trackindex = handle06.product(); - - Handle> handle07; - iEvent.getByToken(rawid_token_, handle07); - auto rawid = handle07.product(); - - Handle> handle08; - iEvent.getByToken(firststrip_token_, handle08); - auto firststrip = handle08.product(); - - Handle> handle09; - iEvent.getByToken(nstrips_token_, handle09); - auto nstrips = handle09.product(); - - Handle> handle10; - iEvent.getByToken(saturation_token_, handle10); - auto saturation = handle10.product(); - - Handle> handle11; - iEvent.getByToken(overlapping_token_, handle11); - auto overlapping = handle11.product(); - - Handle> handle12; - iEvent.getByToken(farfromedge_token_, handle12); - auto farfromedge = handle12.product(); - - Handle> handle13; - iEvent.getByToken(charge_token_, handle13); - auto charge = handle13.product(); - - Handle> handle14; - iEvent.getByToken(path_token_, handle14); - auto path = handle14.product(); - -#ifdef ExtendedCALIBTree - Handle> handle15; - iEvent.getByToken(chargeoverpath_token_, handle15); - auto chargeoverpath = handle15.product(); -#endif - - Handle> handle16; - iEvent.getByToken(amplitude_token_, handle16); - auto amplitude = handle16.product(); - - Handle> handle17; - iEvent.getByToken(gainused_token_, handle17); - auto gainused = handle17.product(); - - Handle> handle18; - iEvent.getByToken(gainusedTick_token_, handle18); - auto gainusedTick = handle18.product(); + // Event data handles + edm::Handle> tracks; + iEvent.getByToken(m_tracks_token, tracks); + edm::Handle trajTrackAssociations; + iEvent.getByToken(m_association_token, trajTrackAssociations); for (const auto& elem : theTopologyMap) { LogDebug("SiStripGainsPCLWorker") << elem.first << " - " << elem.second.m_string << " " @@ -257,166 +199,188 @@ void SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, int elepos = statCollectionFromMode(m_calibrationMode.c_str()); - histograms.EventStats->Fill(0., 0., 1); - histograms.EventStats->Fill(1., 0., trackp->size()); - histograms.EventStats->Fill(2., 0., charge->size()); - - unsigned int FirstAmplitude = 0; - for (unsigned int i = 0; i < charge->size(); i++) { - FirstAmplitude += (*nstrips)[i]; - int TI = (*trackindex)[i]; + std::size_t nStoredClusters{0}; + for (const auto& assoc : *trajTrackAssociations) { + const auto traj = assoc.key.get(); + const auto track = assoc.val.get(); - if ((*tracketa)[TI] < MinTrackEta) - continue; - if ((*tracketa)[TI] > MaxTrackEta) - continue; - if ((*trackp)[TI] < MinTrackMomentum) - continue; - if ((*trackp)[TI] > MaxTrackMomentum) - continue; - if ((*trackhitsvalid)[TI] < MinTrackHits) - continue; - if ((*trackchi2ndof)[TI] > MaxTrackChiOverNdf) - continue; - if ((*trackalgo)[TI] > MaxTrackingIteration) + if ((track->eta() < MinTrackEta) || (track->eta() > MaxTrackEta) || (track->p() < MinTrackMomentum) || + (track->p() > MaxTrackMomentum) || (track->numberOfValidHits() < MinTrackHits) || + ((track->chi2() / track->ndof()) > MaxTrackChiOverNdf) || (track->algo() > MaxTrackingIteration)) continue; - std::shared_ptr APV = histograms.APVsColl.at( - ((*rawid)[i] << 4) | - ((*firststrip)[i] / - 128)); //works for both strip and pixel thanks to firstStrip encoding for pixel in the calibTree - - if (APV->SubDet > 2 && (*farfromedge)[i] == false) - continue; - if (APV->SubDet > 2 && (*overlapping)[i] == true) - continue; - if (APV->SubDet > 2 && (*saturation)[i] && !AllowSaturation) - continue; - if (APV->SubDet > 2 && (*nstrips)[i] > MaxNrStrips) - continue; + int iCluster{-1}; + for (const auto& meas : traj->measurements()) { + const auto& trajState = meas.updatedState(); + if (!trajState.isValid()) + continue; - int Charge = 0; - if (APV->SubDet > 2 && (useCalibration || !FirstSetOfConstants)) { - bool Saturation = false; - for (unsigned int s = 0; s < (*nstrips)[i]; s++) { - int StripCharge = (*amplitude)[FirstAmplitude - (*nstrips)[i] + s]; - if (useCalibration && !FirstSetOfConstants) { - StripCharge = (int)(StripCharge * (APV->PreviousGain / APV->CalibGain)); - } else if (useCalibration) { - StripCharge = (int)(StripCharge / APV->CalibGain); - } else if (!FirstSetOfConstants) { - StripCharge = (int)(StripCharge * APV->PreviousGain); + // there can be 2 (stereo module), 1 (no stereo module), or 0 (no pixel or strip hit) clusters + auto clusters = getClusters(meas.recHit()->hit()); + nStoredClusters += clusters.size(); + for (const auto hitCluster : clusters) { + ++iCluster; + bool saturation = false; + bool overlapping = false; + unsigned int charge = 0; + int firstStrip = 0; + unsigned int nStrips = 0; + if (hitCluster.strip) { + const auto& ampls = hitCluster.strip->amplitudes(); + firstStrip = hitCluster.strip->firstStrip(); + nStrips = ampls.size(); + charge = hitCluster.strip->charge(); + saturation = std::any_of(ampls.begin(), ampls.end(), [](uint8_t amp) { return amp >= 254; }); + + overlapping = (((firstStrip % 128) == 0) || ((firstStrip / 128) != ((firstStrip + int(nStrips)) / 128)) || + (((firstStrip + int(nStrips)) % 128) == 127)); + } else if (hitCluster.pixel) { + const auto& ampls = hitCluster.pixel->pixelADC(); + const int firstRow = hitCluster.pixel->minPixelRow(); + const int firstCol = hitCluster.pixel->minPixelCol(); + firstStrip = ((firstRow / 80) << 3 | (firstCol / 52)) * 128; //Hack to save the APVId + nStrips = 0; + for (const auto amp : ampls) { + charge += amp; + if (amp >= 254) + saturation = true; + } } - if (StripCharge > 1024) { - StripCharge = 255; - Saturation = true; - } else if (StripCharge > 254) { - StripCharge = 254; - Saturation = true; - } - Charge += StripCharge; - } - if (Saturation && !AllowSaturation) - continue; - } else if (APV->SubDet > 2) { - Charge = (*charge)[i]; - } else { - Charge = (*charge)[i] / 265.0; //expected scale factor between pixel and strip charge - } + // works for both strip and pixel thanks to firstStrip encoding for pixel above, as in the calibTree + std::shared_ptr APV = histograms.APVsColl.at((hitCluster.det << 4) | (firstStrip / 128)); - double ClusterChargeOverPath = ((double)Charge) / (*path)[i]; - if (APV->SubDet > 2) { - if (Validation) { - ClusterChargeOverPath /= (*gainused)[i]; - } - if (OldGainRemoving) { - ClusterChargeOverPath *= (*gainused)[i]; - } - } + const auto farFromEdge = (hitCluster.strip ? isFarFromBorder(trajState, hitCluster.det, tGeom) : true); + if ((APV->SubDet > 2) && + ((!farFromEdge) || overlapping || (saturation && !AllowSaturation) || (nStrips > MaxNrStrips))) + continue; - // keep processing of pixel cluster charge until here - if (APV->SubDet <= 2) - continue; + int clusterCharge = 0; + if (APV->SubDet > 2) { // strip + if (useCalibration || !FirstSetOfConstants) { + saturation = false; + for (const auto origCharge : hitCluster.strip->amplitudes()) { + int stripCharge; + if (useCalibration) { + if (FirstSetOfConstants) { + stripCharge = int(origCharge / APV->CalibGain); + } else { + stripCharge = int(origCharge * (APV->PreviousGain / APV->CalibGain)); + } + } else { + if (FirstSetOfConstants) { + stripCharge = origCharge; + } else { + stripCharge = int(origCharge * APV->PreviousGain); + } + } + if (stripCharge > 1024) { + stripCharge = 255; + saturation = true; + } else if (stripCharge > 254) { + stripCharge = 254; + saturation = true; + } + clusterCharge += stripCharge; + } + if (saturation && !AllowSaturation) + continue; + } else { + clusterCharge = charge; + } + } else { // pixel + clusterCharge = charge / 265.0; //expected scale factor between pixel and strip charge + } - // real histogram for calibration - histograms.Charge_Vs_Index[elepos]->Fill(APV->Index, ClusterChargeOverPath); - LogDebug("SiStripGainsPCLWorker") << " for mode " << m_calibrationMode << "\n" - << " i " << i << " useCalibration " << useCalibration << " FirstSetOfConstants " - << FirstSetOfConstants << " APV->PreviousGain " << APV->PreviousGain - << " APV->CalibGain " << APV->CalibGain << " APV->DetId " << APV->DetId - << " APV->Index " << APV->Index << " Charge " << Charge << " Path " << (*path)[i] - << " ClusterChargeOverPath " << ClusterChargeOverPath << std::endl; - - // Fill monitoring histograms - int mCharge1 = 0; - int mCharge2 = 0; - int mCharge3 = 0; - int mCharge4 = 0; - if (APV->SubDet > 2) { - for (unsigned int s = 0; s < (*nstrips)[i]; s++) { - int StripCharge = (*amplitude)[FirstAmplitude - (*nstrips)[i] + s]; - if (StripCharge > 1024) - StripCharge = 255; - else if (StripCharge > 254) - StripCharge = 254; - mCharge1 += StripCharge; - mCharge2 += StripCharge; - mCharge3 += StripCharge; - mCharge4 += StripCharge; - } - // Revome gains for monitoring - mCharge2 *= (*gainused)[i]; // remove G2 - mCharge3 *= (*gainusedTick)[i]; // remove G1 - mCharge4 *= ((*gainused)[i] * (*gainusedTick)[i]); // remove G1 and G2 - } + const auto trackDir = trajState.localDirection(); + const auto path = (10. * APV->Thickness) / std::abs(trackDir.z() / trackDir.mag()); + double ClusterChargeOverPath = ((double)clusterCharge) / path; + if (APV->SubDet > 2) { + if (Validation) { + ClusterChargeOverPath /= APV->PreviousGain; + } + if (OldGainRemoving) { + ClusterChargeOverPath *= APV->PreviousGain; + } + } else { + // keep processing of pixel cluster charge until here + continue; + } - LogDebug("SiStripGainsPCLWorker") << " full charge " << mCharge1 << " remove G2 " << mCharge2 << " remove G1 " - << mCharge3 << " remove G1*G2 " << mCharge4 << std::endl; - - auto indices = APVGain::FetchIndices(theTopologyMap, (*rawid)[i], topo); - - for (auto m : indices) - histograms.Charge_1[elepos][m]->Fill(((double)mCharge1) / (*path)[i]); - for (auto m : indices) - histograms.Charge_2[elepos][m]->Fill(((double)mCharge2) / (*path)[i]); - for (auto m : indices) - histograms.Charge_3[elepos][m]->Fill(((double)mCharge3) / (*path)[i]); - for (auto m : indices) - histograms.Charge_4[elepos][m]->Fill(((double)mCharge4) / (*path)[i]); - - if (APV->SubDet == StripSubdetector::TIB) { - histograms.Charge_Vs_PathlengthTIB[elepos]->Fill((*path)[i], Charge); // TIB - - } else if (APV->SubDet == StripSubdetector::TOB) { - histograms.Charge_Vs_PathlengthTOB[elepos]->Fill((*path)[i], Charge); // TOB - - } else if (APV->SubDet == StripSubdetector::TID) { - if (APV->Eta < 0) { - histograms.Charge_Vs_PathlengthTIDM[elepos]->Fill((*path)[i], Charge); - } // TID minus - else if (APV->Eta > 0) { - histograms.Charge_Vs_PathlengthTIDP[elepos]->Fill((*path)[i], Charge); - } // TID plus - - } else if (APV->SubDet == StripSubdetector::TEC) { - if (APV->Eta < 0) { - if (APV->Thickness < 0.04) { - histograms.Charge_Vs_PathlengthTECM1[elepos]->Fill((*path)[i], Charge); - } // TEC minus, type 1 - else if (APV->Thickness > 0.04) { - histograms.Charge_Vs_PathlengthTECM2[elepos]->Fill((*path)[i], Charge); - } // TEC minus, type 2 - } else if (APV->Eta > 0) { - if (APV->Thickness < 0.04) { - histograms.Charge_Vs_PathlengthTECP1[elepos]->Fill((*path)[i], Charge); - } // TEC plus, type 1 - else if (APV->Thickness > 0.04) { - histograms.Charge_Vs_PathlengthTECP2[elepos]->Fill((*path)[i], Charge); - } // TEC plus, type 2 + // real histogram for calibration + histograms.Charge_Vs_Index[elepos]->Fill(APV->Index, ClusterChargeOverPath); + LogDebug("SiStripGainsPCLWorker") + << " for mode " << m_calibrationMode << "\n" + << " i " << iCluster << " useCalibration " << useCalibration << " FirstSetOfConstants " + << FirstSetOfConstants << " APV->PreviousGain " << APV->PreviousGain << " APV->CalibGain " << APV->CalibGain + << " APV->DetId " << APV->DetId << " APV->Index " << APV->Index << " Charge " << clusterCharge << " Path " + << path << " ClusterChargeOverPath " << ClusterChargeOverPath << std::endl; + + // Fill monitoring histograms + int mCharge1 = 0; + for (const auto sCharge : hitCluster.strip->amplitudes()) { + if (sCharge > 254) { + mCharge1 += 254; + } else { + mCharge1 += sCharge; + } + } + // Revome gains for monitoring + int mCharge2 = mCharge1 * APV->PreviousGain; // remove G2 + int mCharge3 = mCharge1 * APV->PreviousGainTick; // remove G1 + int mCharge4 = mCharge1 * APV->PreviousGain * APV->PreviousGainTick; // remove G1 and G2 + + LogDebug("SiStripGainsPCLWorker") << " full charge " << mCharge1 << " remove G2 " << mCharge2 << " remove G1 " + << mCharge3 << " remove G1*G2 " << mCharge4 << std::endl; + + auto indices = APVGain::FetchIndices(theTopologyMap, hitCluster.det, topo); + + for (auto m : indices) + histograms.Charge_1[elepos][m]->Fill(((double)mCharge1) / path); + for (auto m : indices) + histograms.Charge_2[elepos][m]->Fill(((double)mCharge2) / path); + for (auto m : indices) + histograms.Charge_3[elepos][m]->Fill(((double)mCharge3) / path); + for (auto m : indices) + histograms.Charge_4[elepos][m]->Fill(((double)mCharge4) / path); + + if (APV->SubDet == StripSubdetector::TIB) { + histograms.Charge_Vs_PathlengthTIB[elepos]->Fill(path, clusterCharge); // TIB + + } else if (APV->SubDet == StripSubdetector::TOB) { + histograms.Charge_Vs_PathlengthTOB[elepos]->Fill(path, clusterCharge); // TOB + + } else if (APV->SubDet == StripSubdetector::TID) { + if (APV->Eta < 0) { + histograms.Charge_Vs_PathlengthTIDM[elepos]->Fill(path, clusterCharge); + } // TID minus + else if (APV->Eta > 0) { + histograms.Charge_Vs_PathlengthTIDP[elepos]->Fill(path, clusterCharge); + } // TID plus + + } else if (APV->SubDet == StripSubdetector::TEC) { + if (APV->Eta < 0) { + if (APV->Thickness < 0.04) { + histograms.Charge_Vs_PathlengthTECM1[elepos]->Fill(path, clusterCharge); + } // TEC minus, type 1 + else if (APV->Thickness > 0.04) { + histograms.Charge_Vs_PathlengthTECM2[elepos]->Fill(path, clusterCharge); + } // TEC minus, type 2 + } else if (APV->Eta > 0) { + if (APV->Thickness < 0.04) { + histograms.Charge_Vs_PathlengthTECP1[elepos]->Fill(path, clusterCharge); + } // TEC plus, type 1 + else if (APV->Thickness > 0.04) { + histograms.Charge_Vs_PathlengthTECP2[elepos]->Fill(path, clusterCharge); + } // TEC plus, type 2 + } + } } } + } - } // END OF ON-CLUSTER LOOP + histograms.EventStats->Fill(0., 0., 1); + histograms.EventStats->Fill(1., 0., tracks->size()); + histograms.EventStats->Fill(2., 0., nStoredClusters); //LogDebug("SiStripGainsPCLWorker")<<" for mode"<< m_calibrationMode // <<" entries in histogram:"<< histograms.Charge_Vs_Index[elepos].getEntries() diff --git a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py index 6b1f0aa834d3e..9dde4ff8f48f7 100644 --- a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py +++ b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGainsAAG_cff.py @@ -68,23 +68,15 @@ offlineBeamSpot + ALCARECOCalibrationTracksRefitAAG ) -# ------------------------------------------------------------------------------ -# Get the information you need from the tracks, calibTree-style to have no code difference -from CalibTracker.SiStripCommon.ShallowTracksProducer_cfi import shallowTracks -from CalibTracker.SiStripCommon.ShallowGainCalibration_cfi import shallowGainCalibration -ALCARECOShallowTracksAAG = shallowTracks.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefitAAG')) -ALCARECOShallowGainCalibrationAAG = shallowGainCalibration.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefitAAG')) -ALCARECOShallowSequenceAAG = cms.Sequence(ALCARECOShallowTracksAAG*ALCARECOShallowGainCalibrationAAG) - # ------------------------------------------------------------------------------ # This is the module actually doing the calibration -from CalibTracker.SiStripChannelGain.SiStripGainsPCLWorker_cfi import SiStripGainsPCLWorker -ALCARECOSiStripCalibAAG = SiStripGainsPCLWorker.clone() -ALCARECOSiStripCalibAAG.FirstSetOfConstants = cms.untracked.bool(False) -ALCARECOSiStripCalibAAG.DQMdir = cms.untracked.string('AlCaReco/SiStripGainsAAG') -ALCARECOSiStripCalibAAG.calibrationMode = cms.untracked.string('AagBunch') -ALCARECOSiStripCalibAAG.gain.label = cms.untracked.string('ALCARECOShallowGainCalibrationAAG') -ALCARECOSiStripCalibAAG.tracks.label = cms.untracked.string('ALCARECOShallowTracksAAG') +from CalibTracker.SiStripChannelGain.SiStripGainsPCLWorker_cfi import SiStripGainsPCLWorker +ALCARECOSiStripCalibAAG = SiStripGainsPCLWorker.clone( + tracks = cms.InputTag('ALCARECOCalibrationTracksRefitAAG'), + FirstSetOfConstants = cms.untracked.bool(False), + DQMdir = cms.untracked.string('AlCaReco/SiStripGainsAAG'), + calibrationMode = cms.untracked.string('AagBunch') + ) # ---------------------------------------------------------------------------- @@ -101,7 +93,6 @@ seqALCARECOPromptCalibProdSiStripGainsAAG = cms.Sequence( ALCARECOCalMinBiasFilterForSiStripGainsAAG * ALCARECOTrackFilterRefitAAG * - ALCARECOShallowSequenceAAG * ALCARECOSiStripCalibAAG * MEtoEDMConvertSiStripGainsAAG ) diff --git a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py index 2f8a1fa8123bc..9ff51194bf1fc 100644 --- a/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py +++ b/Calibration/TkAlCaRecoProducers/python/ALCARECOPromptCalibProdSiStripGains_cff.py @@ -67,23 +67,15 @@ offlineBeamSpot + ALCARECOCalibrationTracksRefit ) -# ------------------------------------------------------------------------------ -# Get the information you need from the tracks, calibTree-style to have no code difference -from CalibTracker.SiStripCommon.ShallowTracksProducer_cfi import shallowTracks -from CalibTracker.SiStripCommon.ShallowGainCalibration_cfi import shallowGainCalibration -ALCARECOShallowTracks = shallowTracks.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefit')) -ALCARECOShallowGainCalibration = shallowGainCalibration.clone(Tracks=cms.InputTag('ALCARECOCalibrationTracksRefit')) -ALCARECOShallowSequence = cms.Sequence(ALCARECOShallowTracks*ALCARECOShallowGainCalibration) - # ------------------------------------------------------------------------------ # This is the module actually doing the calibration from CalibTracker.SiStripChannelGain.SiStripGainsPCLWorker_cfi import SiStripGainsPCLWorker -ALCARECOSiStripCalib = SiStripGainsPCLWorker.clone() -ALCARECOSiStripCalib.FirstSetOfConstants = cms.untracked.bool(False) -ALCARECOSiStripCalib.DQMdir = cms.untracked.string('AlCaReco/SiStripGains') -ALCARECOSiStripCalib.calibrationMode = cms.untracked.string('StdBunch') -ALCARECOSiStripCalib.gain.label = cms.untracked.string('ALCARECOShallowGainCalibration') -ALCARECOSiStripCalib.tracks.label = cms.untracked.string('ALCARECOShallowTracks') +ALCARECOSiStripCalib = SiStripGainsPCLWorker.clone( + tracks = cms.InputTag('ALCARECOCalibrationTracksRefit'), + FirstSetOfConstants = cms.untracked.bool(False), + DQMdir = cms.untracked.string('AlCaReco/SiStripGains'), + calibrationMode = cms.untracked.string('StdBunch') + ) # ---------------------------------------------------------------------------- # **************************************************************************** @@ -102,7 +94,6 @@ seqALCARECOPromptCalibProdSiStripGains = cms.Sequence( ALCARECOCalMinBiasFilterForSiStripGains * ALCARECOTrackFilterRefit * - ALCARECOShallowSequence * ALCARECOSiStripCalib * MEtoEDMConvertSiStripGains ) From 7769b40e46a04d6821c10adb8de56bb7dacb5a16 Mon Sep 17 00:00:00 2001 From: Pieter David Date: Mon, 12 Apr 2021 12:36:14 +0200 Subject: [PATCH 3/5] overlapping as in master branch --- CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc index dee3eb1703419..a8c2aa514f11b 100644 --- a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc +++ b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc @@ -232,7 +232,8 @@ void SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, charge = hitCluster.strip->charge(); saturation = std::any_of(ampls.begin(), ampls.end(), [](uint8_t amp) { return amp >= 254; }); - overlapping = (((firstStrip % 128) == 0) || ((firstStrip / 128) != ((firstStrip + int(nStrips)) / 128)) || + overlapping = (((firstStrip % 128) == 0) || + (((firstStrip / 128) != ((firstStrip + int(nStrips)) / 128)) && ((firstStrip / 128) < 5)) || (((firstStrip + int(nStrips)) % 128) == 127)); } else if (hitCluster.pixel) { const auto& ampls = hitCluster.pixel->pixelADC(); From bdb19a4a6d1e4ccee3332688b12674921ab48cd9 Mon Sep 17 00:00:00 2001 From: Pieter David Date: Mon, 26 Apr 2021 11:03:56 +0200 Subject: [PATCH 4/5] Fix 'overlapping' --- CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc index a8c2aa514f11b..19f1a36c6123b 100644 --- a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc +++ b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc @@ -232,9 +232,7 @@ void SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, charge = hitCluster.strip->charge(); saturation = std::any_of(ampls.begin(), ampls.end(), [](uint8_t amp) { return amp >= 254; }); - overlapping = (((firstStrip % 128) == 0) || - (((firstStrip / 128) != ((firstStrip + int(nStrips)) / 128)) && ((firstStrip / 128) < 5)) || - (((firstStrip + int(nStrips)) % 128) == 127)); + overlapping = (((firstStrip % 128) == 0) || ((firstStrip / 128) != ((firstStrip + int(nStrips)) / 128))); } else if (hitCluster.pixel) { const auto& ampls = hitCluster.pixel->pixelADC(); const int firstRow = hitCluster.pixel->minPixelRow(); From 760741afea43f649166521f0f4927f30e7ccdc73 Mon Sep 17 00:00:00 2001 From: Pieter David Date: Mon, 26 Apr 2021 15:23:43 +0200 Subject: [PATCH 5/5] Count actually used clusters --- CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc index 19f1a36c6123b..d1510a53ad69d 100644 --- a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc +++ b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc @@ -217,7 +217,6 @@ void SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, // there can be 2 (stereo module), 1 (no stereo module), or 0 (no pixel or strip hit) clusters auto clusters = getClusters(meas.recHit()->hit()); - nStoredClusters += clusters.size(); for (const auto hitCluster : clusters) { ++iCluster; bool saturation = false; @@ -304,6 +303,7 @@ void SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, // keep processing of pixel cluster charge until here continue; } + ++nStoredClusters; // real histogram for calibration histograms.Charge_Vs_Index[elepos]->Fill(APV->Index, ClusterChargeOverPath);