Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-16 06:12:41

0001 #include "DQM/L1TMonitor/interface/L1TStage2MuonShowerComp.h"
0002 
0003 L1TStage2MuonShowerComp::L1TStage2MuonShowerComp(const edm::ParameterSet& ps)
0004     : showerToken1_(consumes<l1t::MuonShowerBxCollection>(ps.getParameter<edm::InputTag>("muonShowerCollection1"))),
0005       showerToken2_(consumes<l1t::MuonShowerBxCollection>(ps.getParameter<edm::InputTag>("muonShowerCollection2"))),
0006       monitorDir_(ps.getUntrackedParameter<std::string>("monitorDir")),
0007       showerColl1Title_(ps.getUntrackedParameter<std::string>("muonShowerCollection1Title")),
0008       showerColl2Title_(ps.getUntrackedParameter<std::string>("muonShowerCollection2Title")),
0009       summaryTitle_(ps.getUntrackedParameter<std::string>("summaryTitle")),
0010       ignoreBin_(ps.getUntrackedParameter<std::vector<int>>("ignoreBin")),
0011       verbose_(ps.getUntrackedParameter<bool>("verbose")) {
0012   // First include all bins
0013   for (int i = 1; i <= numErrBins_; i++) {
0014     incBin_[i] = true;
0015   }
0016   // Then check the list of bins to ignore
0017   for (const auto& i : ignoreBin_) {
0018     if (i > 0 && i <= numErrBins_) {
0019       incBin_[i] = false;
0020     }
0021   }
0022 }
0023 
0024 L1TStage2MuonShowerComp::~L1TStage2MuonShowerComp() {}
0025 
0026 void L1TStage2MuonShowerComp::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0027   edm::ParameterSetDescription desc;
0028   desc.add<edm::InputTag>("muonShowerCollection1")->setComment("L1T Muon Shower collection 1");
0029   desc.add<edm::InputTag>("muonShowerCollection2")->setComment("L1T Muon Shower collection 2");
0030   desc.addUntracked<std::string>("monitorDir", "")
0031       ->setComment("Target directory in the DQM file. Will be created if not existing.");
0032   desc.addUntracked<std::string>("muonShowerCollection1Title", "Muon Shower collection 1")
0033       ->setComment("Histogram title for first collection.");
0034   desc.addUntracked<std::string>("muonShowerCollection2Title", "Muon Shower collection 2")
0035       ->setComment("Histogram title for second collection.");
0036   desc.addUntracked<std::string>("summaryTitle", "Summary")->setComment("Title of summary histogram.");
0037   desc.addUntracked<std::vector<int>>("ignoreBin", std::vector<int>())->setComment("List of bins to ignore");
0038   desc.addUntracked<bool>("verbose", false);
0039   descriptions.add("l1tStage2MuonShowerComp", desc);
0040 }
0041 
0042 void L1TStage2MuonShowerComp::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run&, const edm::EventSetup&) {
0043   // Subsystem Monitoring and Muon Shower Output
0044   ibooker.setCurrentFolder(monitorDir_);
0045 
0046   summary_ = ibooker.book1D("summary",
0047                             summaryTitle_.c_str(),
0048                             numSummaryBins_,
0049                             1,
0050                             numSummaryBins_ + 1);  // range to match bin numbering
0051   summary_->setBinLabel(BXRANGEGOOD, "BX range match", 1);
0052   summary_->setBinLabel(BXRANGEBAD, "BX range mismatch", 1);
0053   summary_->setBinLabel(NSHOWERGOOD, "shower collection size match", 1);
0054   summary_->setBinLabel(NSHOWERBAD, "shower collection size mismatch", 1);
0055   summary_->setBinLabel(SHOWERALL, "# showers", 1);
0056   summary_->setBinLabel(SHOWERGOOD, "# matching showers", 1);
0057   summary_->setBinLabel(NOMINALBAD, "nominal shower mismatch", 1);
0058   summary_->setBinLabel(TIGHTBAD, "tight shower mismatch", 1);
0059 
0060   errorSummaryNum_ = ibooker.book1D("errorSummaryNum",
0061                                     summaryTitle_.c_str(),
0062                                     numErrBins_,
0063                                     1,
0064                                     numErrBins_ + 1);  // range to match bin numbering
0065   errorSummaryNum_->setBinLabel(RBXRANGE, "BX range mismatch", 1);
0066   errorSummaryNum_->setBinLabel(RNSHOWER, "shower collection size mismatch", 1);
0067   errorSummaryNum_->setBinLabel(RSHOWER, "mismatching showers", 1);
0068   errorSummaryNum_->setBinLabel(RNOMINAL, "nominal shower mismatch", 1);
0069   errorSummaryNum_->setBinLabel(RTIGHT, "tight shower mismatch", 1);
0070 
0071   // Change the label for those bins that will be ignored
0072   for (int i = 1; i <= errorSummaryNum_->getNbinsX(); i++) {
0073     if (incBin_[i] == false) {
0074       errorSummaryNum_->setBinLabel(i, "Ignored", 1);
0075     }
0076   }
0077   // Setting canExtend to false is needed to get the correct behaviour when running multithreaded.
0078   // Otherwise, when merging the histgrams of the threads, TH1::Merge sums bins that have the same label in one bin.
0079   // This needs to come after the calls to setBinLabel.
0080   errorSummaryNum_->getTH1F()->GetXaxis()->SetCanExtend(false);
0081 
0082   errorSummaryDen_ = ibooker.book1D(
0083       "errorSummaryDen", "denominators", numErrBins_, 1, numErrBins_ + 1);  // range to match bin numbering
0084   errorSummaryDen_->setBinLabel(RBXRANGE, "# events", 1);
0085   errorSummaryDen_->setBinLabel(RNSHOWER, "# shower collections", 1);
0086   for (int i = RSHOWER; i <= errorSummaryDen_->getNbinsX(); ++i) {
0087     errorSummaryDen_->setBinLabel(i, "# showers", 1);
0088   }
0089   // Needed for correct histogram summing in multithreaded running.
0090   errorSummaryDen_->getTH1F()->GetXaxis()->SetCanExtend(false);
0091 
0092   showerColl1BxRange_ =
0093       ibooker.book1D("showerBxRangeColl1", (showerColl1Title_ + " mismatching BX range").c_str(), 11, -5.5, 5.5);
0094   showerColl1BxRange_->setAxisTitle("BX range", 1);
0095   showerColl1nShowers_ =
0096       ibooker.book1D("nShowerColl1", (showerColl1Title_ + " mismatching shower multiplicity").c_str(), 37, -0.5, 36.5);
0097   showerColl1nShowers_->setAxisTitle("Shower multiplicity", 1);
0098   showerColl1ShowerTypeVsBX_ = ibooker.book2D("showerColl1ShowerTypeVsBX",
0099                                               showerColl1Title_ + " mismatching shower type occupancy per BX",
0100                                               7,
0101                                               -3.5,
0102                                               3.5,
0103                                               2,
0104                                               1,
0105                                               3);
0106   showerColl1ShowerTypeVsBX_->setAxisTitle("BX", 1);
0107   showerColl1ShowerTypeVsBX_->setAxisTitle("Shower type", 2);
0108   showerColl1ShowerTypeVsBX_->setBinLabel(IDX_TIGHT_SHOWER, "Tight", 2);
0109   showerColl1ShowerTypeVsBX_->setBinLabel(IDX_NOMINAL_SHOWER, "Nominal", 2);
0110 
0111   showerColl2BxRange_ =
0112       ibooker.book1D("showerBxRangeColl2", (showerColl2Title_ + " mismatching BX range").c_str(), 11, -5.5, 5.5);
0113   showerColl2BxRange_->setAxisTitle("BX range", 1);
0114   showerColl2nShowers_ =
0115       ibooker.book1D("nShowerColl2", (showerColl2Title_ + " mismatching shower multiplicity").c_str(), 37, -0.5, 36.5);
0116   showerColl2nShowers_->setAxisTitle("Shower multiplicity", 1);
0117   showerColl2ShowerTypeVsBX_ = ibooker.book2D("showerColl2ShowerTypeVsBX",
0118                                               showerColl2Title_ + " mismatching shower type occupancy per BX",
0119                                               7,
0120                                               -3.5,
0121                                               3.5,
0122                                               2,
0123                                               1,
0124                                               3);
0125   showerColl2ShowerTypeVsBX_->setAxisTitle("BX", 1);
0126   showerColl2ShowerTypeVsBX_->setAxisTitle("Shower type", 2);
0127   showerColl2ShowerTypeVsBX_->setBinLabel(IDX_TIGHT_SHOWER, "Tight", 2);
0128   showerColl2ShowerTypeVsBX_->setBinLabel(IDX_NOMINAL_SHOWER, "Nominal", 2);
0129 }
0130 
0131 void L1TStage2MuonShowerComp::analyze(const edm::Event& e, const edm::EventSetup& c) {
0132   if (verbose_) {
0133     edm::LogInfo("L1TStage2MuonShowerComp") << "L1TStage2MuonShowerComp: analyze..." << std::endl;
0134   }
0135 
0136   edm::Handle<l1t::MuonShowerBxCollection> showerBxColl1;
0137   edm::Handle<l1t::MuonShowerBxCollection> showerBxColl2;
0138   e.getByToken(showerToken1_, showerBxColl1);
0139   e.getByToken(showerToken2_, showerBxColl2);
0140 
0141   errorSummaryDen_->Fill(RBXRANGE);
0142   int bxRange1 = showerBxColl1->getLastBX() - showerBxColl1->getFirstBX() + 1;
0143   int bxRange2 = showerBxColl2->getLastBX() - showerBxColl2->getFirstBX() + 1;
0144   if (bxRange1 != bxRange2) {
0145     summary_->Fill(BXRANGEBAD);
0146     if (incBin_[RBXRANGE])
0147       errorSummaryNum_->Fill(RBXRANGE);
0148     int bx;
0149     for (bx = showerBxColl1->getFirstBX(); bx <= showerBxColl1->getLastBX(); ++bx) {
0150       showerColl1BxRange_->Fill(bx);
0151     }
0152     for (bx = showerBxColl2->getFirstBX(); bx <= showerBxColl2->getLastBX(); ++bx) {
0153       showerColl2BxRange_->Fill(bx);
0154     }
0155   } else {
0156     summary_->Fill(BXRANGEGOOD);
0157   }
0158 
0159   for (int iBx = showerBxColl1->getFirstBX(); iBx <= showerBxColl1->getLastBX(); ++iBx) {
0160     // don't analyse if this BX does not exist in the second collection
0161     if (iBx < showerBxColl2->getFirstBX() || iBx > showerBxColl2->getLastBX()) {
0162       continue;
0163     }
0164 
0165     l1t::MuonShowerBxCollection::const_iterator showerIt1;
0166     l1t::MuonShowerBxCollection::const_iterator showerIt2;
0167 
0168     errorSummaryDen_->Fill(RNSHOWER);
0169     // check number of showers
0170     if (showerBxColl1->size(iBx) != showerBxColl2->size(iBx)) {
0171       summary_->Fill(NSHOWERBAD);
0172       if (incBin_[RNSHOWER]) {
0173         errorSummaryNum_->Fill(RNSHOWER);
0174       }
0175       showerColl1nShowers_->Fill(showerBxColl1->size(iBx));
0176       showerColl2nShowers_->Fill(showerBxColl2->size(iBx));
0177 
0178       if (showerBxColl1->size(iBx) > showerBxColl2->size(iBx)) {
0179         showerIt1 = showerBxColl1->begin(iBx) + showerBxColl2->size(iBx);
0180         for (; showerIt1 != showerBxColl1->end(iBx); ++showerIt1) {
0181           if (showerIt1->isOneNominalInTime()) {
0182             showerColl1ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0183           }
0184           if (showerIt1->isOneTightInTime()) {
0185             showerColl1ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0186           }
0187         }
0188       } else {
0189         showerIt2 = showerBxColl2->begin(iBx) + showerBxColl1->size(iBx);
0190         for (; showerIt2 != showerBxColl2->end(iBx); ++showerIt2) {
0191           if (showerIt2->isOneNominalInTime()) {
0192             showerColl2ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0193           }
0194           if (showerIt2->isOneTightInTime()) {
0195             showerColl2ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0196           }
0197         }
0198       }
0199     } else {
0200       summary_->Fill(NSHOWERGOOD);
0201     }
0202 
0203     showerIt1 = showerBxColl1->begin(iBx);
0204     showerIt2 = showerBxColl2->begin(iBx);
0205     while (showerIt1 != showerBxColl1->end(iBx) && showerIt2 != showerBxColl2->end(iBx)) {
0206       summary_->Fill(SHOWERALL);
0207       for (int i = RSHOWER; i <= numErrBins_; ++i) {
0208         errorSummaryDen_->Fill(i);
0209       }
0210 
0211       bool showerMismatch = false;     // All shower mismatches
0212       bool showerSelMismatch = false;  // Muon mismatches excluding ignored bins
0213       if (showerIt1->isOneNominalInTime() != showerIt2->isOneNominalInTime()) {
0214         showerMismatch = true;
0215         summary_->Fill(NOMINALBAD);
0216         if (incBin_[RNOMINAL]) {
0217           showerSelMismatch = true;
0218           errorSummaryNum_->Fill(RNOMINAL);
0219         }
0220       }
0221       if (showerIt1->isOneTightInTime() != showerIt2->isOneTightInTime()) {
0222         showerMismatch = true;
0223         summary_->Fill(TIGHTBAD);
0224         if (incBin_[RTIGHT]) {
0225           showerSelMismatch = true;
0226           errorSummaryNum_->Fill(RTIGHT);
0227         }
0228       }
0229 
0230       if (incBin_[RSHOWER] && showerSelMismatch) {
0231         errorSummaryNum_->Fill(RSHOWER);
0232       }
0233 
0234       if (showerMismatch) {
0235         if (showerIt1->isOneNominalInTime()) {
0236           showerColl1ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0237         }
0238         if (showerIt1->isOneTightInTime()) {
0239           showerColl1ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0240         }
0241 
0242         if (showerIt2->isOneNominalInTime()) {
0243           showerColl2ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0244         }
0245         if (showerIt2->isOneTightInTime()) {
0246           showerColl2ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0247         }
0248       } else {
0249         summary_->Fill(SHOWERGOOD);
0250       }
0251 
0252       ++showerIt1;
0253       ++showerIt2;
0254     }
0255   }
0256 }