File indexing completed on 2024-04-06 12:06:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <memory>
0022 #include <atomic>
0023
0024
0025 #include "FWCore/Utilities/interface/EDGetToken.h"
0026 #include "FWCore/Framework/interface/Frameworkfwd.h"
0027 #include "FWCore/Framework/interface/global/EDFilter.h"
0028
0029 #include "FWCore/Framework/interface/Event.h"
0030 #include "FWCore/Framework/interface/MakerMacros.h"
0031
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033
0034 #include "FWCore/Utilities/interface/InputTag.h"
0035
0036 #include "DataFormats/Common/interface/DetSetVector.h"
0037 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0038
0039 #include "DQM/SiStripCommon/interface/APVShotFinder.h"
0040 #include "DQM/SiStripCommon/interface/APVShot.h"
0041
0042 #include "DPGAnalysis/SiStripTools/interface/EventWithHistory.h"
0043 #include "DPGAnalysis/SiStripTools/interface/APVCyclePhaseCollection.h"
0044
0045
0046 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0047 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0048 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0049 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0050
0051
0052
0053
0054
0055
0056 class APVShotsFilter : public edm::global::EDFilter<> {
0057 public:
0058 explicit APVShotsFilter(const edm::ParameterSet&);
0059 ~APVShotsFilter() override;
0060
0061 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0062
0063 private:
0064 bool filter(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0065 void endJob() override;
0066
0067
0068
0069 edm::EDGetTokenT<EventWithHistory> heToken_;
0070 edm::EDGetTokenT<APVCyclePhaseCollection> apvphaseToken_;
0071 edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> > digisToken_;
0072
0073 const bool _selectAPVshots;
0074
0075 const bool _zs;
0076 mutable std::atomic<int> _nevents;
0077
0078
0079 const bool _useCabling;
0080 const edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> _detCablingToken;
0081 };
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094 APVShotsFilter::APVShotsFilter(const edm::ParameterSet& iConfig)
0095 : _selectAPVshots(iConfig.getUntrackedParameter<bool>("selectAPVshots", true)),
0096 _zs(iConfig.getUntrackedParameter<bool>("zeroSuppressed", true)),
0097 _nevents(0),
0098 _useCabling(iConfig.getUntrackedParameter<bool>("useCabling", true)),
0099 _detCablingToken(_useCabling ? decltype(_detCablingToken){esConsumes()} : decltype(_detCablingToken){}) {
0100
0101 edm::InputTag digicollection = iConfig.getParameter<edm::InputTag>("digiCollection");
0102 edm::InputTag historyProduct = iConfig.getParameter<edm::InputTag>("historyProduct");
0103 edm::InputTag apvphasecoll = iConfig.getParameter<edm::InputTag>("apvPhaseCollection");
0104
0105 heToken_ = consumes<EventWithHistory>(historyProduct);
0106 apvphaseToken_ = consumes<APVCyclePhaseCollection>(apvphasecoll);
0107 digisToken_ = consumes<edm::DetSetVector<SiStripDigi> >(digicollection);
0108 }
0109
0110 APVShotsFilter::~APVShotsFilter() {
0111
0112
0113 }
0114
0115
0116
0117
0118
0119
0120 bool APVShotsFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0121 using namespace edm;
0122
0123 const SiStripDetCabling* _detCabling = nullptr;
0124 if (_useCabling) {
0125
0126 _detCabling = &iSetup.getData(_detCablingToken);
0127 }
0128 _nevents++;
0129
0130 edm::Handle<EventWithHistory> he;
0131 iEvent.getByToken(heToken_, he);
0132
0133 edm::Handle<APVCyclePhaseCollection> apvphase;
0134 iEvent.getByToken(apvphaseToken_, apvphase);
0135
0136 edm::Handle<edm::DetSetVector<SiStripDigi> > digis;
0137 iEvent.getByToken(digisToken_, digis);
0138
0139
0140 int nshots = 0;
0141 std::vector<int> nshotsperFed;
0142
0143 const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
0144 const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
0145 const uint16_t lNumFeds = (siStripFedIdMax - siStripFedIdMin) + 1;
0146 if (_useCabling) {
0147 nshotsperFed.resize(lNumFeds, 0);
0148 }
0149
0150 APVShotFinder apvsf(*digis, _zs);
0151 const std::vector<APVShot>& shots = apvsf.getShots();
0152
0153 for (std::vector<APVShot>::const_iterator shot = shots.begin(); shot != shots.end(); ++shot) {
0154 if (!shot->isGenuine())
0155 continue;
0156 ++nshots;
0157
0158
0159 uint32_t det = shot->detId();
0160 if (_useCabling) {
0161 int apvPair = shot->apvNumber() / 2;
0162 LogDebug("APVShotsFilter") << apvPair;
0163
0164 const FedChannelConnection& theConn = _detCabling->getConnection(det, apvPair);
0165
0166 int lChannelId = -1;
0167 int thelFEDId = -1;
0168 if (theConn.isConnected()) {
0169 lChannelId = theConn.fedCh();
0170 thelFEDId = theConn.fedId();
0171 } else {
0172 edm::LogWarning("APVShotsFilter") << "connection of det " << det << " APV pair " << apvPair << " not found";
0173 }
0174 LogDebug("APVShotsFilter") << thelFEDId << " " << lChannelId;
0175
0176 const std::vector<const FedChannelConnection*>& conns = _detCabling->getConnections(det);
0177
0178 if (conns.empty())
0179 continue;
0180 uint16_t lFedId = 0;
0181 for (uint32_t ch = 0; ch < conns.size(); ch++) {
0182 if (conns[ch] && conns[ch]->isConnected()) {
0183 LogDebug("APVShotsFilter") << *(conns[ch]);
0184 LogDebug("APVShotsFilter") << "Ready for FED id " << ch;
0185 lFedId = conns[ch]->fedId();
0186 LogDebug("APVShotsFilter") << "obtained FED id " << ch << " " << lFedId;
0187
0188
0189 if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX) {
0190 edm::LogWarning("APVShotsFilter") << lFedId << " for detid " << det << " connection " << ch;
0191 continue;
0192 } else
0193 break;
0194 }
0195 }
0196 if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX) {
0197 edm::LogWarning("APVShotsFilter") << lFedId << "found for detid " << det;
0198 continue;
0199 }
0200
0201 if (lFedId != thelFEDId) {
0202 edm::LogWarning("APVShotsFilter") << " Mismatch in FED id for det " << det << " APV pair " << apvPair << " : "
0203 << lFedId << " vs " << thelFEDId;
0204 }
0205
0206
0207
0208
0209 LogDebug("APVShotsFilter") << " ready to be filled with " << thelFEDId << " " << lChannelId;
0210 LogDebug("APVShotsFilter") << " filled with " << thelFEDId << " " << lChannelId;
0211 }
0212 }
0213
0214 bool foundAPVshots = (nshots > 0);
0215 bool pass = (_selectAPVshots ? foundAPVshots : !foundAPVshots);
0216 return pass;
0217 }
0218
0219
0220 void APVShotsFilter::endJob() { edm::LogInfo("APVShotsFilter") << _nevents.load() << " analyzed events"; }
0221
0222
0223 void APVShotsFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0224
0225
0226 edm::ParameterSetDescription desc;
0227 desc.setUnknown();
0228 descriptions.addDefault(desc);
0229 }
0230
0231 DEFINE_FWK_MODULE(APVShotsFilter);