Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:55

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   summary_->setBinLabel(LOOSEBAD, "loose shower mismatch", 1);
0060 
0061   errorSummaryNum_ = ibooker.book1D("errorSummaryNum",
0062                                     summaryTitle_.c_str(),
0063                                     numErrBins_,
0064                                     1,
0065                                     numErrBins_ + 1);  // range to match bin numbering
0066   errorSummaryNum_->setBinLabel(RBXRANGE, "BX range mismatch", 1);
0067   errorSummaryNum_->setBinLabel(RNSHOWER, "shower collection size mismatch", 1);
0068   errorSummaryNum_->setBinLabel(RSHOWER, "mismatching showers", 1);
0069   errorSummaryNum_->setBinLabel(RNOMINAL, "nominal shower mismatch", 1);
0070   errorSummaryNum_->setBinLabel(RTIGHT, "tight shower mismatch", 1);
0071   errorSummaryNum_->setBinLabel(RLOOSE, "loose shower mismatch", 1);
0072 
0073   // Change the label for those bins that will be ignored
0074   for (int i = 1; i <= errorSummaryNum_->getNbinsX(); i++) {
0075     if (incBin_[i] == false) {
0076       errorSummaryNum_->setBinLabel(i, "Ignored", 1);
0077     }
0078   }
0079   // Setting canExtend to false is needed to get the correct behaviour when running multithreaded.
0080   // Otherwise, when merging the histgrams of the threads, TH1::Merge sums bins that have the same label in one bin.
0081   // This needs to come after the calls to setBinLabel.
0082   errorSummaryNum_->getTH1F()->GetXaxis()->SetCanExtend(false);
0083 
0084   errorSummaryDen_ = ibooker.book1D(
0085       "errorSummaryDen", "denominators", numErrBins_, 1, numErrBins_ + 1);  // range to match bin numbering
0086   errorSummaryDen_->setBinLabel(RBXRANGE, "# events", 1);
0087   errorSummaryDen_->setBinLabel(RNSHOWER, "# shower collections", 1);
0088   for (int i = RSHOWER; i <= errorSummaryDen_->getNbinsX(); ++i) {
0089     errorSummaryDen_->setBinLabel(i, "# showers", 1);
0090   }
0091   // Needed for correct histogram summing in multithreaded running.
0092   errorSummaryDen_->getTH1F()->GetXaxis()->SetCanExtend(false);
0093 
0094   showerColl1BxRange_ =
0095       ibooker.book1D("showerBxRangeColl1", (showerColl1Title_ + " mismatching BX range").c_str(), 11, -5.5, 5.5);
0096   showerColl1BxRange_->setAxisTitle("BX range", 1);
0097   showerColl1nShowers_ =
0098       ibooker.book1D("nShowerColl1", (showerColl1Title_ + " mismatching shower multiplicity").c_str(), 37, -0.5, 36.5);
0099   showerColl1nShowers_->setAxisTitle("Shower multiplicity", 1);
0100   showerColl1ShowerTypeVsBX_ = ibooker.book2D("showerColl1ShowerTypeVsBX",
0101                                               showerColl1Title_ + " mismatching shower type occupancy per BX",
0102                                               7,
0103                                               -3.5,
0104                                               3.5,
0105                                               3,
0106                                               1,
0107                                               4);
0108   showerColl1ShowerTypeVsBX_->setAxisTitle("BX", 1);
0109   showerColl1ShowerTypeVsBX_->setAxisTitle("Shower type", 2);
0110   showerColl1ShowerTypeVsBX_->setBinLabel(IDX_LOOSE_SHOWER, "TwoLoose", 2);
0111   showerColl1ShowerTypeVsBX_->setBinLabel(IDX_TIGHT_SHOWER, "OneTight", 2);
0112   showerColl1ShowerTypeVsBX_->setBinLabel(IDX_NOMINAL_SHOWER, "OneNominal", 2);
0113 
0114   showerColl2BxRange_ =
0115       ibooker.book1D("showerBxRangeColl2", (showerColl2Title_ + " mismatching BX range").c_str(), 11, -5.5, 5.5);
0116   showerColl2BxRange_->setAxisTitle("BX range", 1);
0117   showerColl2nShowers_ =
0118       ibooker.book1D("nShowerColl2", (showerColl2Title_ + " mismatching shower multiplicity").c_str(), 37, -0.5, 36.5);
0119   showerColl2nShowers_->setAxisTitle("Shower multiplicity", 1);
0120   showerColl2ShowerTypeVsBX_ = ibooker.book2D("showerColl2ShowerTypeVsBX",
0121                                               showerColl2Title_ + " mismatching shower type occupancy per BX",
0122                                               7,
0123                                               -3.5,
0124                                               3.5,
0125                                               3,
0126                                               1,
0127                                               4);
0128   showerColl2ShowerTypeVsBX_->setAxisTitle("BX", 1);
0129   showerColl2ShowerTypeVsBX_->setAxisTitle("Shower type", 2);
0130   showerColl2ShowerTypeVsBX_->setBinLabel(IDX_LOOSE_SHOWER, "TwoLoose", 2);
0131   showerColl2ShowerTypeVsBX_->setBinLabel(IDX_TIGHT_SHOWER, "OneTight", 2);
0132   showerColl2ShowerTypeVsBX_->setBinLabel(IDX_NOMINAL_SHOWER, "OneNominal", 2);
0133 }
0134 
0135 void L1TStage2MuonShowerComp::analyze(const edm::Event& e, const edm::EventSetup& c) {
0136   if (verbose_) {
0137     edm::LogInfo("L1TStage2MuonShowerComp") << "L1TStage2MuonShowerComp: analyze..." << std::endl;
0138   }
0139 
0140   edm::Handle<l1t::MuonShowerBxCollection> showerBxColl1;
0141   edm::Handle<l1t::MuonShowerBxCollection> showerBxColl2;
0142   e.getByToken(showerToken1_, showerBxColl1);
0143   e.getByToken(showerToken2_, showerBxColl2);
0144 
0145   errorSummaryDen_->Fill(RBXRANGE);
0146   int bxRange1 = showerBxColl1->getLastBX() - showerBxColl1->getFirstBX() + 1;
0147   int bxRange2 = showerBxColl2->getLastBX() - showerBxColl2->getFirstBX() + 1;
0148   if (bxRange1 != bxRange2) {
0149     summary_->Fill(BXRANGEBAD);
0150     if (incBin_[RBXRANGE])
0151       errorSummaryNum_->Fill(RBXRANGE);
0152     int bx;
0153     for (bx = showerBxColl1->getFirstBX(); bx <= showerBxColl1->getLastBX(); ++bx) {
0154       showerColl1BxRange_->Fill(bx);
0155     }
0156     for (bx = showerBxColl2->getFirstBX(); bx <= showerBxColl2->getLastBX(); ++bx) {
0157       showerColl2BxRange_->Fill(bx);
0158     }
0159   } else {
0160     summary_->Fill(BXRANGEGOOD);
0161   }
0162 
0163   for (int iBx = showerBxColl1->getFirstBX(); iBx <= showerBxColl1->getLastBX(); ++iBx) {
0164     // don't analyse if this BX does not exist in the second collection
0165     if (iBx < showerBxColl2->getFirstBX() || iBx > showerBxColl2->getLastBX()) {
0166       continue;
0167     }
0168 
0169     l1t::MuonShowerBxCollection::const_iterator showerIt1;
0170     l1t::MuonShowerBxCollection::const_iterator showerIt2;
0171 
0172     errorSummaryDen_->Fill(RNSHOWER);
0173     // check number of showers
0174     if (showerBxColl1->size(iBx) != showerBxColl2->size(iBx)) {
0175       summary_->Fill(NSHOWERBAD);
0176       if (incBin_[RNSHOWER]) {
0177         errorSummaryNum_->Fill(RNSHOWER);
0178       }
0179       showerColl1nShowers_->Fill(showerBxColl1->size(iBx));
0180       showerColl2nShowers_->Fill(showerBxColl2->size(iBx));
0181 
0182       if (showerBxColl1->size(iBx) > showerBxColl2->size(iBx)) {
0183         showerIt1 = showerBxColl1->begin(iBx) + showerBxColl2->size(iBx);
0184         for (; showerIt1 != showerBxColl1->end(iBx); ++showerIt1) {
0185           if (showerIt1->isOneNominalInTime()) {
0186             showerColl1ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0187           }
0188           if (showerIt1->isOneTightInTime()) {
0189             showerColl1ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0190           }
0191           if (showerIt1->isTwoLooseDiffSectorsInTime()) {
0192             showerColl1ShowerTypeVsBX_->Fill(IDX_LOOSE_SHOWER, iBx);
0193           }
0194         }
0195       } else {
0196         showerIt2 = showerBxColl2->begin(iBx) + showerBxColl1->size(iBx);
0197         for (; showerIt2 != showerBxColl2->end(iBx); ++showerIt2) {
0198           if (showerIt2->isOneNominalInTime()) {
0199             showerColl2ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0200           }
0201           if (showerIt2->isOneTightInTime()) {
0202             showerColl2ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0203           }
0204           if (showerIt2->isTwoLooseDiffSectorsInTime()) {
0205             showerColl2ShowerTypeVsBX_->Fill(IDX_LOOSE_SHOWER, iBx);
0206           }
0207         }
0208       }
0209     } else {
0210       summary_->Fill(NSHOWERGOOD);
0211     }
0212 
0213     showerIt1 = showerBxColl1->begin(iBx);
0214     showerIt2 = showerBxColl2->begin(iBx);
0215     while (showerIt1 != showerBxColl1->end(iBx) && showerIt2 != showerBxColl2->end(iBx)) {
0216       summary_->Fill(SHOWERALL);
0217       for (int i = RSHOWER; i <= numErrBins_; ++i) {
0218         errorSummaryDen_->Fill(i);
0219       }
0220 
0221       bool showerMismatch = false;     // All shower mismatches
0222       bool showerSelMismatch = false;  // Muon mismatches excluding ignored bins
0223       if (showerIt1->isOneNominalInTime() != showerIt2->isOneNominalInTime()) {
0224         showerMismatch = true;
0225         summary_->Fill(NOMINALBAD);
0226         if (incBin_[RNOMINAL]) {
0227           showerSelMismatch = true;
0228           errorSummaryNum_->Fill(RNOMINAL);
0229         }
0230       }
0231       if (showerIt1->isOneTightInTime() != showerIt2->isOneTightInTime()) {
0232         showerMismatch = true;
0233         summary_->Fill(TIGHTBAD);
0234         if (incBin_[RTIGHT]) {
0235           showerSelMismatch = true;
0236           errorSummaryNum_->Fill(RTIGHT);
0237         }
0238       }
0239 
0240       if (incBin_[RSHOWER] && showerSelMismatch) {
0241         errorSummaryNum_->Fill(RSHOWER);
0242       }
0243 
0244       if (showerMismatch) {
0245         if (showerIt1->isOneNominalInTime()) {
0246           showerColl1ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0247         }
0248         if (showerIt1->isOneTightInTime()) {
0249           showerColl1ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0250         }
0251         if (showerIt1->isTwoLooseDiffSectorsInTime()) {
0252           showerColl1ShowerTypeVsBX_->Fill(IDX_LOOSE_SHOWER, iBx);
0253         }
0254 
0255         if (showerIt2->isOneNominalInTime()) {
0256           showerColl2ShowerTypeVsBX_->Fill(IDX_NOMINAL_SHOWER, iBx);
0257         }
0258         if (showerIt2->isOneTightInTime()) {
0259           showerColl2ShowerTypeVsBX_->Fill(IDX_TIGHT_SHOWER, iBx);
0260         }
0261         if (showerIt2->isTwoLooseDiffSectorsInTime()) {
0262           showerColl2ShowerTypeVsBX_->Fill(IDX_LOOSE_SHOWER, iBx);
0263         }
0264       } else {
0265         summary_->Fill(SHOWERGOOD);
0266       }
0267 
0268       ++showerIt1;
0269       ++showerIt2;
0270     }
0271   }
0272 }