Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-26 03:15:53

0001 #include "FWCore/Framework/interface/ConsumesCollector.h"
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/Utilities/interface/EDGetToken.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 
0012 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0013 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
0014 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0015 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
0016 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
0017 #include "DataFormats/CSCDigi/interface/CSCCLCTPreTriggerDigiCollection.h"
0018 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0019 #include "DataFormats/CSCDigi/interface/CSCShowerDigiCollection.h"
0020 #include "DataFormats/MuonDetId/interface/CSCTriggerNumbering.h"
0021 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0022 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0023 #include "EventFilter/CSCRawToDigi/interface/CSCDigiToRawAccept.h"
0024 
0025 #include <memory>
0026 #include <iostream>
0027 
0028 class CSCPackerUnpackerUnitTest : public edm::one::EDAnalyzer<> {
0029 public:
0030   explicit CSCPackerUnpackerUnitTest(const edm::ParameterSet&);
0031   ~CSCPackerUnpackerUnitTest() override {}
0032 
0033   void analyze(const edm::Event&, const edm::EventSetup&) override;
0034 
0035   // Fill parameters descriptions
0036   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0037 
0038 private:
0039   void analyzeChamber(const CSCDetId& cscId,
0040                       const CSCWireDigiCollection& wd,
0041                       const CSCWireDigiCollection& wdu,
0042                       const CSCStripDigiCollection& sd,
0043                       const CSCStripDigiCollection& sdu,
0044                       const CSCComparatorDigiCollection& cd,
0045                       const CSCComparatorDigiCollection& cdu,
0046                       const CSCALCTDigiCollection& alct,
0047                       const CSCCLCTDigiCollection& clct,
0048                       const CSCCLCTPreTriggerDigiCollection& pre,
0049                       const CSCCorrelatedLCTDigiCollection& lct,
0050                       const CSCShowerDigiCollection* showers) const;
0051 
0052   // the return value indicates the number of failed tests
0053   unsigned analyzeALCT(const CSCDetId& cscDetId,
0054                        const CSCWireDigiCollection& wires,
0055                        const CSCWireDigiCollection& wires_unpacked,
0056                        const CSCALCTDigiCollection& alcts) const;
0057   unsigned analyzeCLCT(const CSCDetId& cscDetId,
0058                        const CSCComparatorDigiCollection& comparators,
0059                        const CSCComparatorDigiCollection& comparators_unpacked,
0060                        const CSCCLCTDigiCollection& clcts) const;
0061   unsigned analyzePreCLCT(const CSCDetId& cscDetId,
0062                           const CSCStripDigiCollection& strips,
0063                           const CSCStripDigiCollection& strips_unpacked,
0064                           const CSCCLCTPreTriggerDigiCollection& preclcts) const;
0065 
0066   // helper functions
0067   template <typename DIGICollection>
0068   unsigned nDigis(const CSCDetId& cscId, const DIGICollection& digis) const;
0069 
0070   template <typename DIGICollection>
0071   unsigned nDigisLayer(const CSCDetId& cscId, const DIGICollection& digis) const;
0072 
0073   unsigned nDigisCFEB(const CSCDetId& cscId, const CSCStripDigiCollection& digis, int cfeb) const;
0074 
0075   unsigned nDigisCFEBLayer(const CSCDetId& cscId, const CSCStripDigiCollection& digis, int cfeb) const;
0076 
0077   unsigned getNCFEBs(unsigned type) const;
0078 
0079   int alctWindowMin_;
0080   int alctWindowMax_;
0081   int clctWindowMin_;
0082   int clctWindowMax_;
0083   int preTriggerWindowMin_;
0084   int preTriggerWindowMax_;
0085   unsigned formatVersion_;
0086   bool packEverything_;
0087   bool usePreTriggers_;
0088   bool useCSCShowers_;
0089   bool packByCFEB_;
0090   bool testALCT_;
0091   bool testCLCT_;
0092   bool testPreCLCT_;
0093 
0094   edm::EDGetTokenT<CSCWireDigiCollection> wd_token_;
0095   edm::EDGetTokenT<CSCWireDigiCollection> wd_unpacked_token_;
0096   edm::EDGetTokenT<CSCStripDigiCollection> sd_token_;
0097   edm::EDGetTokenT<CSCStripDigiCollection> sd_unpacked_token_;
0098   edm::EDGetTokenT<CSCComparatorDigiCollection> cd_token_;
0099   edm::EDGetTokenT<CSCComparatorDigiCollection> cd_unpacked_token_;
0100   edm::EDGetTokenT<CSCALCTDigiCollection> al_token_;
0101   edm::EDGetTokenT<CSCCLCTDigiCollection> cl_token_;
0102   edm::EDGetTokenT<CSCCLCTPreTriggerDigiCollection> clpre_token_;
0103   edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> co_token_;
0104   edm::EDGetTokenT<CSCShowerDigiCollection> shower_token;
0105 };
0106 
0107 CSCPackerUnpackerUnitTest::CSCPackerUnpackerUnitTest(const edm::ParameterSet& conf)
0108     : alctWindowMin_(conf.getParameter<int>("alctWindowMin")),
0109       alctWindowMax_(conf.getParameter<int>("alctWindowMax")),
0110       clctWindowMin_(conf.getParameter<int>("clctWindowMin")),
0111       clctWindowMax_(conf.getParameter<int>("clctWindowMax")),
0112       preTriggerWindowMin_(conf.getParameter<int>("preTriggerWindowMin")),
0113       preTriggerWindowMax_(conf.getParameter<int>("preTriggerWindowMax")),
0114       formatVersion_(conf.getParameter<unsigned>("formatVersion")),
0115       packEverything_(conf.getParameter<bool>("packEverything")),
0116       usePreTriggers_(conf.getParameter<bool>("usePreTriggers")),
0117       useCSCShowers_(conf.getParameter<bool>("useCSCShowers")),
0118       packByCFEB_(conf.getParameter<bool>("packByCFEB")),
0119       testALCT_(conf.getParameter<bool>("testALCT")),
0120       testCLCT_(conf.getParameter<bool>("testCLCT")),
0121       testPreCLCT_(conf.getParameter<bool>("testPreCLCT")),
0122       wd_token_(consumes<CSCWireDigiCollection>(conf.getParameter<edm::InputTag>("wireTag"))),
0123       wd_unpacked_token_(consumes<CSCWireDigiCollection>(conf.getParameter<edm::InputTag>("wireUnpackedTag"))),
0124       sd_token_(consumes<CSCStripDigiCollection>(conf.getParameter<edm::InputTag>("stripTag"))),
0125       sd_unpacked_token_(consumes<CSCStripDigiCollection>(conf.getParameter<edm::InputTag>("stripUnpackedTag"))),
0126       cd_token_(consumes<CSCComparatorDigiCollection>(conf.getParameter<edm::InputTag>("comparatorTag"))),
0127       cd_unpacked_token_(
0128           consumes<CSCComparatorDigiCollection>(conf.getParameter<edm::InputTag>("comparatorUnpackedTag"))),
0129       al_token_(consumes<CSCALCTDigiCollection>(conf.getParameter<edm::InputTag>("alctTag"))),
0130       cl_token_(consumes<CSCCLCTDigiCollection>(conf.getParameter<edm::InputTag>("clctTag"))),
0131       clpre_token_(consumes<CSCCLCTPreTriggerDigiCollection>(conf.getParameter<edm::InputTag>("clctpreTag"))),
0132       co_token_(consumes<CSCCorrelatedLCTDigiCollection>(conf.getParameter<edm::InputTag>("corrclctTag"))) {
0133   if (useCSCShowers_) {
0134     shower_token = consumes<CSCShowerDigiCollection>(conf.getParameter<edm::InputTag>("showerDigiTag"));
0135   }
0136 }
0137 
0138 void CSCPackerUnpackerUnitTest::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0139   edm::ParameterSetDescription desc;
0140   // digi collections
0141   desc.add<edm::InputTag>("wireTag", edm::InputTag("simMuonCSCDigis", "MuonCSCWireDigi"));
0142   desc.add<edm::InputTag>("stripTag", edm::InputTag("simMuonCSCDigis", "MuonCSCStripDigi"));
0143   desc.add<edm::InputTag>("comparatorTag", edm::InputTag("simMuonCSCDigis", "MuonCSCComparatorDigi"));
0144   // DAQ collections
0145   desc.add<edm::InputTag>("wireUnpackedTag", edm::InputTag("muonCSCDigis", "MuonCSCWireDigi"));
0146   desc.add<edm::InputTag>("stripUnpackedTag", edm::InputTag("muonCSCDigis", "MuonCSCStripDigi"));
0147   desc.add<edm::InputTag>("comparatorUnpackedTag", edm::InputTag("muonCSCDigis", "MuonCSCComparatorDigi"));
0148   // trigger collections
0149   desc.add<edm::InputTag>("alctTag", edm::InputTag("simCscTriggerPrimitiveDigis"));
0150   desc.add<edm::InputTag>("clctTag", edm::InputTag("simCscTriggerPrimitiveDigis"));
0151   desc.add<edm::InputTag>("clctpreTag", edm::InputTag("simCscTriggerPrimitiveDigis"));
0152   desc.add<edm::InputTag>("corrclctTag", edm::InputTag("simCscTriggerPrimitiveDigis"));
0153   desc.add<edm::InputTag>("showerDigiTag", edm::InputTag("simCscTriggerPrimitiveDigis"));
0154   // readout windows
0155   desc.add<int32_t>("alctWindowMin", -3);
0156   desc.add<int32_t>("alctWindowMax", 3);
0157   desc.add<int32_t>("clctWindowMin", -3);
0158   desc.add<int32_t>("clctWindowMax", 3);
0159   desc.add<int32_t>("preTriggerWindowMin", -3);
0160   desc.add<int32_t>("preTriggerWindowMax", 1);
0161   desc.add<unsigned int>("formatVersion", 2005);
0162   // enable functions
0163   desc.add<bool>("testALCT", true);
0164   desc.add<bool>("testCLCT", true);
0165   desc.add<bool>("testPreCLCT", true);
0166   desc.add<bool>("usePreTriggers", true);
0167   desc.add<bool>("packEverything", false);
0168   desc.add<bool>("useCSCShowers", false);
0169   desc.add<bool>("packByCFEB", true);
0170   descriptions.add("cscPackerUnpackerUnitTestDef", desc);
0171 }
0172 
0173 void CSCPackerUnpackerUnitTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0174   // handles, tokens
0175   edm::Handle<CSCWireDigiCollection> wires;
0176   iEvent.getByToken(wd_token_, wires);
0177 
0178   edm::Handle<CSCWireDigiCollection> wires_unpacked;
0179   iEvent.getByToken(wd_unpacked_token_, wires_unpacked);
0180 
0181   edm::Handle<CSCStripDigiCollection> strips;
0182   iEvent.getByToken(sd_token_, strips);
0183 
0184   edm::Handle<CSCStripDigiCollection> strips_unpacked;
0185   iEvent.getByToken(sd_unpacked_token_, strips_unpacked);
0186 
0187   edm::Handle<CSCComparatorDigiCollection> comparators;
0188   iEvent.getByToken(cd_token_, comparators);
0189 
0190   edm::Handle<CSCComparatorDigiCollection> comparators_unpacked;
0191   iEvent.getByToken(cd_unpacked_token_, comparators_unpacked);
0192 
0193   edm::Handle<CSCALCTDigiCollection> alcts;
0194   iEvent.getByToken(al_token_, alcts);
0195 
0196   edm::Handle<CSCCLCTDigiCollection> clcts;
0197   iEvent.getByToken(cl_token_, clcts);
0198 
0199   edm::Handle<CSCCLCTPreTriggerDigiCollection> preclcts;
0200   iEvent.getByToken(clpre_token_, preclcts);
0201 
0202   edm::Handle<CSCCorrelatedLCTDigiCollection> lcts;
0203   iEvent.getByToken(co_token_, lcts);
0204 
0205   const CSCShowerDigiCollection* cscShowerDigisPtr = nullptr;
0206   if (useCSCShowers_) {
0207     cscShowerDigisPtr = &iEvent.get(shower_token);
0208   }
0209 
0210   const int min_endcap = CSCDetId::minEndcapId();
0211   const int max_endcap = CSCDetId::maxEndcapId();
0212   const int min_station = CSCDetId::minStationId();
0213   const int max_station = CSCDetId::maxStationId();
0214   const int min_sector = CSCTriggerNumbering::minTriggerSectorId();
0215   const int max_sector = CSCTriggerNumbering::maxTriggerSectorId();
0216   const int min_subsector = CSCTriggerNumbering::minTriggerSubSectorId();
0217   const int max_subsector = CSCTriggerNumbering::maxTriggerSubSectorId();
0218   const int min_chamber = CSCTriggerNumbering::minTriggerCscId();
0219   const int max_chamber = CSCTriggerNumbering::maxTriggerCscId();
0220 
0221   for (int endc = min_endcap; endc <= max_endcap; endc++) {
0222     for (int stat = min_station; stat <= max_station; stat++) {
0223       int numsubs = ((stat == 1) ? max_subsector : 1);
0224       for (int sect = min_sector; sect <= max_sector; sect++) {
0225         for (int subs = min_subsector; subs <= numsubs; subs++) {
0226           for (int cham = min_chamber; cham <= max_chamber; cham++) {
0227             int ring = CSCTriggerNumbering::ringFromTriggerLabels(stat, cham);
0228 
0229             // actual chamber number =/= trigger chamber number
0230             int chid = CSCTriggerNumbering::chamberFromTriggerLabels(sect, subs, stat, cham);
0231 
0232             // 0th layer means whole chamber.
0233             CSCDetId cscDetId(endc, stat, ring, chid, 0);
0234 
0235             analyzeChamber(cscDetId,
0236                            *wires,
0237                            *wires_unpacked,
0238                            *strips,
0239                            *strips_unpacked,
0240                            *comparators,
0241                            *comparators_unpacked,
0242                            *alcts,
0243                            *clcts,
0244                            *preclcts,
0245                            *lcts,
0246                            cscShowerDigisPtr);
0247           }
0248         }
0249       }
0250     }
0251   }
0252 }
0253 
0254 void CSCPackerUnpackerUnitTest::analyzeChamber(const CSCDetId& cscDetId,
0255                                                const CSCWireDigiCollection& wires,
0256                                                const CSCWireDigiCollection& wires_unpacked,
0257                                                const CSCStripDigiCollection& strips,
0258                                                const CSCStripDigiCollection& strips_unpacked,
0259                                                const CSCComparatorDigiCollection& comparators,
0260                                                const CSCComparatorDigiCollection& comparators_unpacked,
0261                                                const CSCALCTDigiCollection& alcts,
0262                                                const CSCCLCTDigiCollection& clcts,
0263                                                const CSCCLCTPreTriggerDigiCollection& preclcts,
0264                                                const CSCCorrelatedLCTDigiCollection& lcts,
0265                                                const CSCShowerDigiCollection* showers) const {
0266   if (testALCT_) {
0267     const unsigned nFailedTestsALCT = analyzeALCT(cscDetId, wires, wires_unpacked, alcts);
0268     if (nFailedTestsALCT) {
0269       edm::LogWarning("CSCPackerUnpackerUnitTest")
0270           << nFailedTestsALCT << " ALCT test(s) failed in " << cscDetId.chamberName();
0271     }
0272   }
0273 
0274   if (testCLCT_) {
0275     const unsigned nFailedTestsCLCT = analyzeCLCT(cscDetId, comparators, comparators_unpacked, clcts);
0276     if (nFailedTestsCLCT) {
0277       edm::LogWarning("CSCPackerUnpackerUnitTest")
0278           << nFailedTestsCLCT << " CLCT test(s) failed in " << cscDetId.chamberName();
0279     }
0280   }
0281 
0282   if (testPreCLCT_) {
0283     const unsigned nFailedTestsPreCLCT = analyzePreCLCT(cscDetId, strips, strips_unpacked, preclcts);
0284     if (nFailedTestsPreCLCT) {
0285       edm::LogWarning("CSCPackerUnpackerUnitTest")
0286           << nFailedTestsPreCLCT << " PreCLCT test(s) failed in " << cscDetId.chamberName();
0287     }
0288   }
0289 }
0290 
0291 unsigned CSCPackerUnpackerUnitTest::analyzeALCT(const CSCDetId& cscDetId,
0292                                                 const CSCWireDigiCollection& wires,
0293                                                 const CSCWireDigiCollection& wires_unpacked,
0294                                                 const CSCALCTDigiCollection& alcts) const {
0295   unsigned numWireDigis = nDigis(cscDetId, wires);
0296   // no simulated wire digis means that all tests pass
0297   if (numWireDigis == 0) {
0298     return 0;
0299   }
0300 
0301   // readout condition for wires: L1A + ALCT
0302   bool hasALCT =
0303       CSCDigiToRawAccept::accept(cscDetId, alcts, alctWindowMin_, alctWindowMax_, CSCConstants::ALCT_CENTRAL_BX);
0304 
0305   unsigned numWireDigisUnpacked = nDigis(cscDetId, wires_unpacked);
0306 
0307   unsigned testsFailed = 0;
0308 
0309   // these tests are only done when the trigger/pretriggers are enabled
0310   if (!packEverything_ and usePreTriggers_) {
0311     // test 1: check that an ALCT in this chamber kept the wire digis
0312     if (hasALCT) {
0313       if (numWireDigisUnpacked == 0) {
0314         testsFailed++;
0315         edm::LogWarning("analyzeALCT::Test1Failure") << "hasALCT " << hasALCT << " numWireDigisUnpacked "
0316                                                      << numWireDigisUnpacked << " " << cscDetId.chamberName();
0317       }
0318     }
0319 
0320     // test 2: check no wire digis were kept if there was no ALCT
0321     if (numWireDigisUnpacked != 0) {
0322       if (!hasALCT) {
0323         testsFailed++;
0324         edm::LogWarning("analyzeALCT::Test2Failure") << "hasALCT " << hasALCT << " numWireDigisUnpacked "
0325                                                      << numWireDigisUnpacked << " " << cscDetId.chamberName();
0326       }
0327     }
0328   }
0329 
0330   // test 3: count the number of wire digis before and after unpacking
0331   if (numWireDigis < numWireDigisUnpacked) {
0332     testsFailed++;
0333     edm::LogWarning("analyzeALCT::Test3Failure") << "numWireDigis " << numWireDigis << " numWireDigisUnpacked "
0334                                                  << numWireDigisUnpacked << " " << cscDetId.chamberName();
0335   }
0336 
0337   return testsFailed;
0338 }
0339 
0340 unsigned CSCPackerUnpackerUnitTest::analyzeCLCT(const CSCDetId& cscDetId,
0341                                                 const CSCComparatorDigiCollection& comparators,
0342                                                 const CSCComparatorDigiCollection& comparators_unpacked,
0343                                                 const CSCCLCTDigiCollection& clcts) const {
0344   unsigned numCompDigis = nDigis(cscDetId, comparators);
0345   // no simulated comparator digis means that all tests pass
0346   if (numCompDigis == 0) {
0347     return 0;
0348   }
0349 
0350   // readout condition for comparators in (O)TMB; L1A + CLCT
0351   bool hasCLCT =
0352       CSCDigiToRawAccept::accept(cscDetId, clcts, clctWindowMin_, clctWindowMax_, CSCConstants::CLCT_CENTRAL_BX);
0353 
0354   unsigned numCompDigisUnpacked = nDigis(cscDetId, comparators_unpacked);
0355 
0356   unsigned testsFailed = 0;
0357 
0358   // these tests are only done when the trigger/pretriggers are enabled
0359   if (!packEverything_ and usePreTriggers_) {
0360     // test 1: check that an CLCT in this chamber kept the comp digis
0361     if (hasCLCT) {
0362       if (numCompDigisUnpacked == 0) {
0363         testsFailed++;
0364         edm::LogWarning("analyzeCLCT::Test1Failure") << "hasCLCT " << hasCLCT << " numCompDigisUnpacked "
0365                                                      << numCompDigisUnpacked << " " << cscDetId.chamberName();
0366       }
0367     }
0368 
0369     // test 2: check no comp digis were kept if there was no CLCT
0370     if (numCompDigisUnpacked != 0) {
0371       if (!hasCLCT) {
0372         testsFailed++;
0373         edm::LogWarning("analyzeCLCT::Test2Failure") << "hasCLCT " << hasCLCT << " numCompDigisUnpacked "
0374                                                      << numCompDigisUnpacked << " " << cscDetId.chamberName();
0375       }
0376     }
0377   }
0378 
0379   // test 3: count the number of comp digis before and after unpacking
0380   if (numCompDigis < numCompDigisUnpacked) {
0381     testsFailed++;
0382     edm::LogWarning("analyzeCLCT::Test3Failure") << "numCompDigis " << numCompDigis << " numCompDigisUnpacked "
0383                                                  << numCompDigisUnpacked << " " << cscDetId.chamberName();
0384   }
0385 
0386   return testsFailed;
0387 }
0388 
0389 unsigned CSCPackerUnpackerUnitTest::analyzePreCLCT(const CSCDetId& cscDetId,
0390                                                    const CSCStripDigiCollection& strips,
0391                                                    const CSCStripDigiCollection& strips_unpacked,
0392                                                    const CSCCLCTPreTriggerDigiCollection& preclcts) const {
0393   unsigned numStripDigis = nDigis(cscDetId, strips);
0394   // no simulated strip digis means that all tests pass
0395   if (numStripDigis == 0) {
0396     return 0;
0397   }
0398 
0399   // determine where the pretriggers are
0400   std::vector<bool> preTriggerInCFEB;
0401   preTriggerInCFEB.resize(CSCConstants::MAX_CFEBS_RUN2);
0402 
0403   // readout condition for strips: L1A + preCLCT in CFEB
0404   bool hasPreCLCT = CSCDigiToRawAccept::accept(
0405       cscDetId, preclcts, preTriggerWindowMin_, preTriggerWindowMax_, CSCConstants::CLCT_CENTRAL_BX, preTriggerInCFEB);
0406 
0407   unsigned testsFailed = 0;
0408 
0409   unsigned nStripDigisUnpacked = nDigis(cscDetId, strips_unpacked);
0410 
0411   // these tests are only done when the trigger/pretriggers are enabled
0412   if (!packEverything_ and usePreTriggers_) {
0413     // Test when NOT packing by CFEB
0414     if (!packByCFEB_) {
0415       // test 1: check that a PreCLCT in this chamber kept the strip digis
0416       if (hasPreCLCT) {
0417         if (nStripDigisUnpacked == 0) {
0418           testsFailed++;
0419           edm::LogWarning("analyzePreCLCT::Test1Failure") << "preTrigger " << hasPreCLCT << " nStripDigisUnpacked "
0420                                                           << nStripDigisUnpacked << " " << cscDetId.chamberName();
0421         }
0422       }
0423 
0424       // test 2: check no strip digis were kept if there was no PreCLCT
0425       if (nStripDigisUnpacked != 0) {
0426         if (!hasPreCLCT) {
0427           testsFailed++;
0428           edm::LogWarning("analyzePreCLCT::Test2Failure") << "preTrigger " << hasPreCLCT << " nStripDigisUnpacked "
0429                                                           << nStripDigisUnpacked << " " << cscDetId.chamberName();
0430         }
0431       }
0432     }
0433 
0434     // Test when packing by CFEBs
0435     else {
0436       // tests are performed for each CFEB
0437       for (unsigned i = 0; i < CSCConstants::MAX_CFEBS_RUN2; i++) {
0438         // only do the tests for the CFEBs in this chamber (4,5,7)
0439         if (i >= getNCFEBs(cscDetId.iChamberType() - 1))
0440           continue;
0441 
0442         unsigned nStripDigisUnpackedCFEB = nDigisCFEB(cscDetId, strips_unpacked, i);
0443 
0444         // test 1: check that a PreCLCT in this chamber kept the strip digis
0445         if (preTriggerInCFEB[i]) {
0446           if (nStripDigisUnpackedCFEB == 0) {
0447             testsFailed++;
0448             edm::LogWarning("analyzePreCLCT::Test1Failure")
0449                 << "CFEB " << i << "preTriggerInCFEB " << preTriggerInCFEB[i] << " nStripDigisUnpackedCFEB "
0450                 << nStripDigisUnpackedCFEB << " " << cscDetId.chamberName();
0451           }
0452         }
0453 
0454         // test 2: check no strip digis were kept if there was no PreCLCT
0455         if (nStripDigisUnpackedCFEB != 0) {
0456           if (!preTriggerInCFEB[i]) {
0457             testsFailed++;
0458             edm::LogWarning("analyzePreCLCT::Test2Failure")
0459                 << "CFEB " << i << "preTriggerInCFEB " << preTriggerInCFEB[i] << " nStripDigisUnpackedCFEB "
0460                 << nStripDigisUnpackedCFEB << " " << cscDetId.chamberName();
0461           }
0462         }
0463       }
0464     }
0465   }
0466 
0467   return testsFailed;
0468 }
0469 
0470 template <typename DIGICollection>
0471 unsigned CSCPackerUnpackerUnitTest::nDigis(const CSCDetId& detid, const DIGICollection& digis) const {
0472   unsigned nDigis = 0;
0473   for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
0474     CSCDetId ldetid(detid.endcap(), detid.station(), detid.ring(), detid.chamber(), i_layer + 1);
0475     nDigis += nDigisLayer(ldetid, digis);
0476 
0477     if (detid.station() == 1 and detid.ring() == 1) {
0478       CSCDetId ldetid_me1a(detid.endcap(), detid.station(), 4, detid.chamber(), i_layer + 1);
0479       nDigis += nDigisLayer(ldetid_me1a, digis);
0480     }
0481   }
0482   return nDigis;
0483 }
0484 
0485 template <typename DIGICollection>
0486 unsigned CSCPackerUnpackerUnitTest::nDigisLayer(const CSCDetId& cscId, const DIGICollection& digis) const {
0487   unsigned nDigis = 0;
0488   auto digiRange = digis.get(cscId);
0489   for (auto digiItr = digiRange.first; digiItr != digiRange.second; ++digiItr) {
0490     nDigis++;
0491   }
0492   return nDigis;
0493 }
0494 
0495 unsigned CSCPackerUnpackerUnitTest::nDigisCFEB(const CSCDetId& detid,
0496                                                const CSCStripDigiCollection& digis,
0497                                                int cfeb) const {
0498   unsigned nDigis = 0;
0499 
0500   for (int i_layer = 0; i_layer < CSCConstants::NUM_LAYERS; i_layer++) {
0501     // ME1/A case
0502     if (detid.station() == 1 and detid.ring() == 1 and cfeb >= 4) {
0503       CSCDetId ldetid(detid.endcap(), detid.station(), 4, detid.chamber(), i_layer + 1);
0504       nDigis += nDigisCFEBLayer(ldetid, digis, cfeb);
0505     }
0506     // all other cases
0507     else {
0508       CSCDetId ldetid(detid.endcap(), detid.station(), detid.ring(), detid.chamber(), i_layer + 1);
0509       nDigis += nDigisCFEBLayer(ldetid, digis, cfeb);
0510     }
0511   }
0512   return nDigis;
0513 }
0514 
0515 unsigned CSCPackerUnpackerUnitTest::nDigisCFEBLayer(const CSCDetId& cscId,
0516                                                     const CSCStripDigiCollection& digis,
0517                                                     int cfeb) const {
0518   unsigned nDigis = 0;
0519   auto digiRange = digis.get(cscId);
0520   for (auto digiItr = digiRange.first; digiItr != digiRange.second; ++digiItr) {
0521     CSCStripDigi digi = *digiItr;
0522     int cfb = digi.getCFEB();
0523     if (cscId.station() == 1 and cscId.ring() == 4) {
0524       cfb += CSCConstants::NUM_CFEBS_ME1B;
0525     }
0526     if (cfeb == cfb) {
0527       nDigis++;
0528     }
0529   }
0530   return nDigis;
0531 }
0532 
0533 unsigned CSCPackerUnpackerUnitTest::getNCFEBs(unsigned type) const {
0534   const unsigned cfebs[10] = {CSCConstants::NUM_CFEBS_ME1A_UNGANGED,
0535                               CSCConstants::NUM_CFEBS_ME11_UNGANGED,
0536                               CSCConstants::NUM_CFEBS_ME12,
0537                               CSCConstants::NUM_CFEBS_ME13,
0538                               CSCConstants::NUM_CFEBS_ME21,
0539                               CSCConstants::NUM_CFEBS_ME22,
0540                               CSCConstants::NUM_CFEBS_ME31,
0541                               CSCConstants::NUM_CFEBS_ME32,
0542                               CSCConstants::NUM_CFEBS_ME41,
0543                               CSCConstants::NUM_CFEBS_ME42};
0544   return cfebs[type];
0545 }
0546 
0547 //define this as a plug-in
0548 DEFINE_FWK_MODULE(CSCPackerUnpackerUnitTest);