Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:40

0001 #include "DQMOffline/Muon/interface/MuonIdDQM.h"
0002 
0003 MuonIdDQM::MuonIdDQM(const edm::ParameterSet& iConfig)
0004     : trackingGeomToken_(esConsumes<GlobalTrackingGeometry, GlobalTrackingGeometryRecord>()) {
0005   inputMuonCollection_ = consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("inputMuonCollection"));
0006   inputDTRecSegment4DCollection_ =
0007       consumes<DTRecSegment4DCollection>(iConfig.getParameter<edm::InputTag>("inputDTRecSegment4DCollection"));
0008   inputCSCSegmentCollection_ =
0009       consumes<CSCSegmentCollection>(iConfig.getParameter<edm::InputTag>("inputCSCSegmentCollection"));
0010   useTrackerMuons_ = iConfig.getUntrackedParameter<bool>("useTrackerMuons");
0011   useGlobalMuons_ = iConfig.getUntrackedParameter<bool>("useGlobalMuons");
0012   useTrackerMuonsNotGlobalMuons_ = iConfig.getUntrackedParameter<bool>("useTrackerMuonsNotGlobalMuons");
0013   useGlobalMuonsNotTrackerMuons_ = iConfig.getUntrackedParameter<bool>("useGlobalMuonsNotTrackerMuons");
0014   baseFolder_ = iConfig.getUntrackedParameter<std::string>("baseFolder");
0015 }
0016 
0017 MuonIdDQM::~MuonIdDQM() {}
0018 
0019 void MuonIdDQM::bookHistograms(DQMStore::IBooker& ibooker,
0020                                edm::Run const& /*iRun*/,
0021                                edm::EventSetup const& /* iSetup */) {
0022   char name[100], title[200];
0023 
0024   ibooker.cd();
0025   ibooker.setCurrentFolder(baseFolder_);
0026   // trackerMuon == 0; globalMuon == 1; trackerMuon && !globalMuon == 2; globalMuon && !trackerMuon == 3
0027 
0028   hSegmentIsAssociatedBool = ibooker.book1D("hSegmentIsAssociatedBool", "Segment Is Associated Boolean", 2, -0.5, 1.5);
0029 
0030   for (unsigned int i = 0; i < 4; i++) {
0031     if ((i == 0 && !useTrackerMuons_) || (i == 1 && !useGlobalMuons_))
0032       continue;
0033     if ((i == 2 && !useTrackerMuonsNotGlobalMuons_) || (i == 3 && !useGlobalMuonsNotTrackerMuons_))
0034       continue;
0035     if (i == 0)
0036       ibooker.setCurrentFolder(baseFolder_ + "/TrackerMuons");
0037     if (i == 1)
0038       ibooker.setCurrentFolder(baseFolder_ + "/GlobalMuons");
0039     if (i == 2)
0040       ibooker.setCurrentFolder(baseFolder_ + "/TrackerMuonsNotGlobalMuons");
0041     if (i == 3)
0042       ibooker.setCurrentFolder(baseFolder_ + "/GlobalMuonsNotTrackerMuons");
0043 
0044     hNumChambers[i] = ibooker.book1D("hNumChambers", "Number of Chambers", 17, -0.5, 16.5);
0045     hNumMatches[i] = ibooker.book1D("hNumMatches", "Number of Matches", 11, -0.5, 10.5);
0046     hNumChambersNoRPC[i] = ibooker.book1D("hNumChambersNoRPC", "Number of Chambers No RPC", 11, -0.5, 10.5);
0047 
0048     // by station
0049     for (int station = 0; station < 4; ++station) {
0050       sprintf(name, "hDT%iNumSegments", station + 1);
0051       sprintf(title, "DT Station %i Number of Segments (No Arbitration)", station + 1);
0052       hDTNumSegments[i][station] = ibooker.book1D(name, title, 11, -0.5, 10.5);
0053 
0054       sprintf(name, "hDT%iDx", station + 1);
0055       sprintf(title, "DT Station %i Delta X", station + 1);
0056       hDTDx[i][station] = ibooker.book1D(name, title, 100, -100., 100.);
0057 
0058       sprintf(name, "hDT%iPullx", station + 1);
0059       sprintf(title, "DT Station %i Pull X", station + 1);
0060       hDTPullx[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0061 
0062       sprintf(name, "hDT%iDdXdZ", station + 1);
0063       sprintf(title, "DT Station %i Delta DxDz", station + 1);
0064       hDTDdXdZ[i][station] = ibooker.book1D(name, title, 100, -1., 1.);
0065 
0066       sprintf(name, "hDT%iPulldXdZ", station + 1);
0067       sprintf(title, "DT Station %i Pull DxDz", station + 1);
0068       hDTPulldXdZ[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0069 
0070       if (station < 3) {
0071         sprintf(name, "hDT%iDy", station + 1);
0072         sprintf(title, "DT Station %i Delta Y", station + 1);
0073         hDTDy[i][station] = ibooker.book1D(name, title, 100, -150., 150.);
0074 
0075         sprintf(name, "hDT%iPully", station + 1);
0076         sprintf(title, "DT Station %i Pull Y", station + 1);
0077         hDTPully[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0078 
0079         sprintf(name, "hDT%iDdYdZ", station + 1);
0080         sprintf(title, "DT Station %i Delta DyDz", station + 1);
0081         hDTDdYdZ[i][station] = ibooker.book1D(name, title, 100, -2., 2.);
0082 
0083         sprintf(name, "hDT%iPulldYdZ", station + 1);
0084         sprintf(title, "DT Station %i Pull DyDz", station + 1);
0085         hDTPulldYdZ[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0086       }
0087 
0088       sprintf(name, "hCSC%iNumSegments", station + 1);
0089       sprintf(title, "CSC Station %i Number of Segments (No Arbitration)", station + 1);
0090       hCSCNumSegments[i][station] = ibooker.book1D(name, title, 11, -0.5, 10.5);
0091 
0092       sprintf(name, "hCSC%iDx", station + 1);
0093       sprintf(title, "CSC Station %i Delta X", station + 1);
0094       hCSCDx[i][station] = ibooker.book1D(name, title, 100, -50., 50.);
0095 
0096       sprintf(name, "hCSC%iPullx", station + 1);
0097       sprintf(title, "CSC Station %i Pull X", station + 1);
0098       hCSCPullx[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0099 
0100       sprintf(name, "hCSC%iDdXdZ", station + 1);
0101       sprintf(title, "CSC Station %i Delta DxDz", station + 1);
0102       hCSCDdXdZ[i][station] = ibooker.book1D(name, title, 100, -1., 1.);
0103 
0104       sprintf(name, "hCSC%iPulldXdZ", station + 1);
0105       sprintf(title, "CSC Station %i Pull DxDz", station + 1);
0106       hCSCPulldXdZ[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0107 
0108       sprintf(name, "hCSC%iDy", station + 1);
0109       sprintf(title, "CSC Station %i Delta Y", station + 1);
0110       hCSCDy[i][station] = ibooker.book1D(name, title, 100, -50., 50.);
0111 
0112       sprintf(name, "hCSC%iPully", station + 1);
0113       sprintf(title, "CSC Station %i Pull Y", station + 1);
0114       hCSCPully[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0115 
0116       sprintf(name, "hCSC%iDdYdZ", station + 1);
0117       sprintf(title, "CSC Station %i Delta DyDz", station + 1);
0118       hCSCDdYdZ[i][station] = ibooker.book1D(name, title, 100, -1., 1.);
0119 
0120       sprintf(name, "hCSC%iPulldYdZ", station + 1);
0121       sprintf(title, "CSC Station %i Pull DyDz", station + 1);
0122       hCSCPulldYdZ[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0123     }  // station
0124   }
0125 }
0126 
0127 void MuonIdDQM::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0128   using namespace edm;
0129   using namespace reco;
0130 
0131   iEvent.getByToken(inputMuonCollection_, muonCollectionH_);
0132   iEvent.getByToken(inputDTRecSegment4DCollection_, dtSegmentCollectionH_);
0133   iEvent.getByToken(inputCSCSegmentCollection_, cscSegmentCollectionH_);
0134 
0135   geometry_ = iSetup.getHandle(trackingGeomToken_);
0136 
0137   for (MuonCollection::const_iterator muon = muonCollectionH_->begin(); muon != muonCollectionH_->end(); ++muon) {
0138     // trackerMuon == 0; globalMuon == 1; trackerMuon && !globalMuon == 2; globalMuon && !trackerMuon == 3
0139     for (unsigned int i = 0; i < 4; i++) {
0140       if (i == 0 && (!useTrackerMuons_ || !muon->isTrackerMuon()))
0141         continue;
0142       if (i == 1 && (!useGlobalMuons_ || !muon->isGlobalMuon()))
0143         continue;
0144       if (i == 2 && (!useTrackerMuonsNotGlobalMuons_ || (!(muon->isTrackerMuon() && !muon->isGlobalMuon()))))
0145         continue;
0146       if (i == 3 && (!useGlobalMuonsNotTrackerMuons_ || (!(muon->isGlobalMuon() && !muon->isTrackerMuon()))))
0147         continue;
0148 
0149       hNumChambers[i]->Fill(muon->numberOfChambers());
0150       hNumMatches[i]->Fill(muon->numberOfMatches(Muon::SegmentAndTrackArbitration));
0151       hNumChambersNoRPC[i]->Fill(muon->numberOfChambersCSCorDT());
0152 
0153       // by station
0154       for (int station = 0; station < 4; ++station) {
0155         // only fill num segments if we crossed (or nearly crossed) a chamber
0156         if (muon->trackX(station + 1, MuonSubdetId::DT, Muon::NoArbitration) < 900000)
0157           hDTNumSegments[i][station]->Fill(muon->numberOfSegments(station + 1, MuonSubdetId::DT, Muon::NoArbitration));
0158         Fill(hDTDx[i][station], muon->dX(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
0159         Fill(hDTPullx[i][station], muon->pullX(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
0160         Fill(hDTDdXdZ[i][station], muon->dDxDz(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
0161         Fill(hDTPulldXdZ[i][station],
0162              muon->pullDxDz(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
0163 
0164         if (station < 3) {
0165           Fill(hDTDy[i][station], muon->dY(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
0166           Fill(hDTPully[i][station],
0167                muon->pullY(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
0168           Fill(hDTDdYdZ[i][station], muon->dDyDz(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
0169           Fill(hDTPulldYdZ[i][station],
0170                muon->pullDyDz(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
0171         }
0172 
0173         // only fill num segments if we crossed (or nearly crossed) a chamber
0174         if (muon->trackX(station + 1, MuonSubdetId::CSC, Muon::NoArbitration) < 900000)
0175           hCSCNumSegments[i][station]->Fill(
0176               muon->numberOfSegments(station + 1, MuonSubdetId::CSC, Muon::NoArbitration));
0177         Fill(hCSCDx[i][station], muon->dX(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
0178         Fill(hCSCPullx[i][station],
0179              muon->pullX(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
0180         Fill(hCSCDdXdZ[i][station], muon->dDxDz(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
0181         Fill(hCSCPulldXdZ[i][station],
0182              muon->pullDxDz(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
0183         Fill(hCSCDy[i][station], muon->dY(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
0184         Fill(hCSCPully[i][station],
0185              muon->pullY(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
0186         Fill(hCSCDdYdZ[i][station], muon->dDyDz(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
0187         Fill(hCSCPulldYdZ[i][station],
0188              muon->pullDyDz(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
0189       }
0190     }
0191   }  // muon
0192 
0193   for (DTRecSegment4DCollection::const_iterator segment = dtSegmentCollectionH_->begin();
0194        segment != dtSegmentCollectionH_->end();
0195        ++segment) {
0196     LocalPoint segmentLocalPosition = segment->localPosition();
0197     LocalVector segmentLocalDirection = segment->localDirection();
0198     LocalError segmentLocalPositionError = segment->localPositionError();
0199     LocalError segmentLocalDirectionError = segment->localDirectionError();
0200     bool segmentFound = false;
0201 
0202     for (MuonCollection::const_iterator muon = muonCollectionH_->begin(); muon != muonCollectionH_->end(); ++muon) {
0203       if (!muon->isMatchesValid())
0204         continue;
0205 
0206       for (std::vector<MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
0207            chamberMatch != muon->matches().end();
0208            ++chamberMatch) {
0209         for (std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
0210              segmentMatch != chamberMatch->segmentMatches.end();
0211              ++segmentMatch) {
0212           if (fabs(segmentMatch->x - segmentLocalPosition.x()) < 1E-6 &&
0213               fabs(segmentMatch->y - segmentLocalPosition.y()) < 1E-6 &&
0214               fabs(segmentMatch->dXdZ - segmentLocalDirection.x() / segmentLocalDirection.z()) < 1E-6 &&
0215               fabs(segmentMatch->dYdZ - segmentLocalDirection.y() / segmentLocalDirection.z()) < 1E-6 &&
0216               fabs(segmentMatch->xErr - sqrt(segmentLocalPositionError.xx())) < 1E-6 &&
0217               fabs(segmentMatch->yErr - sqrt(segmentLocalPositionError.yy())) < 1E-6 &&
0218               fabs(segmentMatch->dXdZErr - sqrt(segmentLocalDirectionError.xx())) < 1E-6 &&
0219               fabs(segmentMatch->dYdZErr - sqrt(segmentLocalDirectionError.yy())) < 1E-6) {
0220             segmentFound = true;
0221             break;
0222           }
0223         }  // segmentMatch
0224         if (segmentFound)
0225           break;
0226       }  // chamberMatch
0227       if (segmentFound)
0228         break;
0229     }  // muon
0230 
0231     if (segmentFound)
0232       hSegmentIsAssociatedBool->Fill(1.);
0233     else
0234       hSegmentIsAssociatedBool->Fill(0.);
0235   }  // dt segment
0236 
0237   for (CSCSegmentCollection::const_iterator segment = cscSegmentCollectionH_->begin();
0238        segment != cscSegmentCollectionH_->end();
0239        ++segment) {
0240     LocalPoint segmentLocalPosition = segment->localPosition();
0241     LocalVector segmentLocalDirection = segment->localDirection();
0242     LocalError segmentLocalPositionError = segment->localPositionError();
0243     LocalError segmentLocalDirectionError = segment->localDirectionError();
0244     bool segmentFound = false;
0245 
0246     for (MuonCollection::const_iterator muon = muonCollectionH_->begin(); muon != muonCollectionH_->end(); ++muon) {
0247       if (!muon->isMatchesValid())
0248         continue;
0249 
0250       for (std::vector<MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
0251            chamberMatch != muon->matches().end();
0252            ++chamberMatch) {
0253         for (std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
0254              segmentMatch != chamberMatch->segmentMatches.end();
0255              ++segmentMatch) {
0256           if (fabs(segmentMatch->x - segmentLocalPosition.x()) < 1E-6 &&
0257               fabs(segmentMatch->y - segmentLocalPosition.y()) < 1E-6 &&
0258               fabs(segmentMatch->dXdZ - segmentLocalDirection.x() / segmentLocalDirection.z()) < 1E-6 &&
0259               fabs(segmentMatch->dYdZ - segmentLocalDirection.y() / segmentLocalDirection.z()) < 1E-6 &&
0260               fabs(segmentMatch->xErr - sqrt(segmentLocalPositionError.xx())) < 1E-6 &&
0261               fabs(segmentMatch->yErr - sqrt(segmentLocalPositionError.yy())) < 1E-6 &&
0262               fabs(segmentMatch->dXdZErr - sqrt(segmentLocalDirectionError.xx())) < 1E-6 &&
0263               fabs(segmentMatch->dYdZErr - sqrt(segmentLocalDirectionError.yy())) < 1E-6) {
0264             segmentFound = true;
0265             break;
0266           }
0267         }  // segmentMatch
0268         if (segmentFound)
0269           break;
0270       }  // chamberMatch
0271       if (segmentFound)
0272         break;
0273     }  // muon
0274 
0275     if (segmentFound)
0276       hSegmentIsAssociatedBool->Fill(1.);
0277     else
0278       hSegmentIsAssociatedBool->Fill(0.);
0279   }  // csc segment
0280 }
0281 
0282 void MuonIdDQM::Fill(MonitorElement* me, float f) {
0283   if (fabs(f) > 900000)
0284     return;
0285   //if (fabs(f) < 1E-8) return;
0286   me->Fill(f);
0287 }
0288 
0289 //define this as a plug-in
0290 DEFINE_FWK_MODULE(MuonIdDQM);