Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-11 04:33:27

0001 #include "Validation/MuonIdentification/interface/MuonIdVal.h"
0002 
0003 MuonIdVal::MuonIdVal(const edm::ParameterSet &ps)
0004     : trackingGeomToken_(esConsumes<GlobalTrackingGeometry, GlobalTrackingGeometryRecord>()) {
0005   iConfig = ps;
0006   inputMuonCollection_ = iConfig.getParameter<edm::InputTag>("inputMuonCollection");
0007   inputDTRecSegment4DCollection_ = iConfig.getParameter<edm::InputTag>("inputDTRecSegment4DCollection");
0008   inputCSCSegmentCollection_ = iConfig.getParameter<edm::InputTag>("inputCSCSegmentCollection");
0009   inputMuonTimeExtraValueMap_ = iConfig.getParameter<edm::InputTag>("inputMuonTimeExtraValueMap");
0010   inputMuonCosmicCompatibilityValueMap_ = iConfig.getParameter<edm::InputTag>("inputMuonCosmicCompatibilityValueMap");
0011   inputMuonShowerInformationValueMap_ = iConfig.getParameter<edm::InputTag>("inputMuonShowerInformationValueMap");
0012   useTrackerMuons_ = iConfig.getUntrackedParameter<bool>("useTrackerMuons");
0013   useGlobalMuons_ = iConfig.getUntrackedParameter<bool>("useGlobalMuons");
0014   useTrackerMuonsNotGlobalMuons_ = iConfig.getUntrackedParameter<bool>("useTrackerMuonsNotGlobalMuons");
0015   useGlobalMuonsNotTrackerMuons_ = iConfig.getUntrackedParameter<bool>("useGlobalMuonsNotTrackerMuons");
0016   makeEnergyPlots_ = iConfig.getUntrackedParameter<bool>("makeEnergyPlots");
0017   makeTimePlots_ = iConfig.getUntrackedParameter<bool>("makeTimePlots");
0018   make2DPlots_ = iConfig.getUntrackedParameter<bool>("make2DPlots");
0019   makeAllChamberPlots_ = iConfig.getUntrackedParameter<bool>("makeAllChamberPlots");
0020   makeCosmicCompatibilityPlots_ = iConfig.getUntrackedParameter<bool>("makeCosmicCompatibilityPlots");
0021   makeShowerInformationPlots_ = iConfig.getUntrackedParameter<bool>("makeShowerInformationPlots");
0022   baseFolder_ = iConfig.getUntrackedParameter<std::string>("baseFolder");
0023 
0024   inputMuonCollectionToken_ = consumes<reco::MuonCollection>(inputMuonCollection_);
0025   inputDTRecSegment4DCollectionToken_ = consumes<DTRecSegment4DCollection>(inputDTRecSegment4DCollection_);
0026   inputCSCSegmentCollectionToken_ = consumes<CSCSegmentCollection>(inputCSCSegmentCollection_);
0027   inputMuonTimeExtraValueMapCombToken_ =
0028       consumes<reco::MuonTimeExtraMap>(edm::InputTag(inputMuonTimeExtraValueMap_.label(), "combined"));
0029   inputMuonTimeExtraValueMapDTToken_ =
0030       consumes<reco::MuonTimeExtraMap>(edm::InputTag(inputMuonTimeExtraValueMap_.label(), "csc"));
0031   inputMuonTimeExtraValueMapCSCToken_ =
0032       consumes<reco::MuonTimeExtraMap>(edm::InputTag(inputMuonTimeExtraValueMap_.label(), "dt"));
0033   inputMuonCosmicCompatibilityValueMapToken_ =
0034       consumes<edm::ValueMap<reco::MuonCosmicCompatibility>>(inputMuonCosmicCompatibilityValueMap_);
0035   inputMuonShowerInformationValueMapToken_ =
0036       consumes<edm::ValueMap<reco::MuonShower>>(inputMuonShowerInformationValueMap_);
0037 
0038   subsystemname_ = iConfig.getUntrackedParameter<std::string>("subSystemFolder", "YourSubsystem");
0039 }
0040 
0041 MuonIdVal::~MuonIdVal() {}
0042 
0043 void MuonIdVal::bookHistograms(DQMStore::IBooker &ibooker, const edm::Run &, const edm::EventSetup &) {
0044   char name[100], title[200];
0045   ibooker.setCurrentFolder(baseFolder_);
0046 
0047   // trackerMuon == 0; globalMuon == 1; trackerMuon && !globalMuon == 2;
0048   // globalMuon && !trackerMuon == 3
0049   for (unsigned int i = 0; i < 4; i++) {
0050     if ((i == 0 && !useTrackerMuons_) || (i == 1 && !useGlobalMuons_))
0051       continue;
0052     if ((i == 2 && !useTrackerMuonsNotGlobalMuons_) || (i == 3 && !useGlobalMuonsNotTrackerMuons_))
0053       continue;
0054     if (i == 0)
0055       ibooker.setCurrentFolder(baseFolder_ + "/TrackerMuons");
0056     if (i == 1)
0057       ibooker.setCurrentFolder(baseFolder_ + "/GlobalMuons");
0058     if (i == 2)
0059       ibooker.setCurrentFolder(baseFolder_ + "/TrackerMuonsNotGlobalMuons");
0060     if (i == 3)
0061       ibooker.setCurrentFolder(baseFolder_ + "/GlobalMuonsNotTrackerMuons");
0062 
0063     if (makeEnergyPlots_) {
0064       hEnergyEMBarrel[i] = ibooker.book1D("hEnergyEMBarrel", "Energy in ECAL Barrel", 100, -0.5, 2.);
0065       hEnergyHABarrel[i] = ibooker.book1D("hEnergyHABarrel", "Energy in HCAL Barrel", 100, -4., 12.);
0066       hEnergyHO[i] = ibooker.book1D("hEnergyHO", "Energy HO", 100, -2., 5.);
0067       hEnergyEMEndcap[i] = ibooker.book1D("hEnergyEMEndcap", "Energy in ECAL Endcap", 100, -0.5, 2.);
0068       hEnergyHAEndcap[i] = ibooker.book1D("hEnergyHAEndcap", "Energy in HCAL Endcap", 100, -4., 12.);
0069     }
0070 
0071     if (makeTimePlots_) {
0072       hMuonTimeNDOF[i] = ibooker.book1D("hMuonTimeNDOF", "MuonTime NDOF", 52, -1.5, 50.5);
0073       hMuonTimeTimeAtIpInOut[i] = ibooker.book1D("hMuonTimeTimeAtIpInOut", "MuonTime TimeAtIpInOut", 100, -20., 20.);
0074       hMuonTimeTimeAtIpInOutErr[i] =
0075           ibooker.book1D("hMuonTimeTimeAtIpInOutErr", "MuonTime TimeAtIpInOutErr", 100, 0., 8.);
0076       hMuonTimeTimeAtIpOutIn[i] = ibooker.book1D("hMuonTimeTimeAtIpOutIn", "MuonTime TimeAtIpOutIn", 100, -1., 75.);
0077       hMuonTimeTimeAtIpOutInErr[i] =
0078           ibooker.book1D("hMuonTimeTimeAtIpOutInErr", "MuonTime TimeAtIpOutInErr", 100, 0., 8.);
0079       hMuonTimeExtraCombinedNDOF[i] =
0080           ibooker.book1D("hMuonTimeExtraCombinedNDOF", "MuonTimeExtra Combined NDOF", 52, -1.5, 50.5);
0081       hMuonTimeExtraCombinedTimeAtIpInOut[i] =
0082           ibooker.book1D("hMuonTimeExtraCombinedTimeAtIpInOut", "MuonTimeExtra Combined TimeAtIpInOut", 100, -20., 20.);
0083       hMuonTimeExtraCombinedTimeAtIpInOutErr[i] = ibooker.book1D(
0084           "hMuonTimeExtraCombinedTimeAtIpInOutErr", "MuonTimeExtra Combined TimeAtIpInOutErr", 100, 0., 8.);
0085       hMuonTimeExtraCombinedTimeAtIpOutIn[i] =
0086           ibooker.book1D("hMuonTimeExtraCombinedTimeAtIpOutIn", "MuonTimeExtra Combined TimeAtIpOutIn", 100, -1., 75.);
0087       hMuonTimeExtraCombinedTimeAtIpOutInErr[i] = ibooker.book1D(
0088           "hMuonTimeExtraCombinedTimeAtIpOutInErr", "MuonTimeExtra Combined TimeAtIpOutInErr", 100, 0., 8.);
0089       hMuonTimeExtraCSCNDOF[i] = ibooker.book1D("hMuonTimeExtraCSCNDOF", "MuonTimeExtra CSC NDOF", 52, -1.5, 50.5);
0090       hMuonTimeExtraCSCTimeAtIpInOut[i] =
0091           ibooker.book1D("hMuonTimeExtraCSCTimeAtIpInOut", "MuonTimeExtra CSC TimeAtIpInOut", 100, -20., 20.);
0092       hMuonTimeExtraCSCTimeAtIpInOutErr[i] =
0093           ibooker.book1D("hMuonTimeExtraCSCTimeAtIpInOutErr", "MuonTimeExtra CSC TimeAtIpInOutErr", 100, 0., 8.);
0094       hMuonTimeExtraCSCTimeAtIpOutIn[i] =
0095           ibooker.book1D("hMuonTimeExtraCSCTimeAtIpOutIn", "MuonTimeExtra CSC TimeAtIpOutIn", 100, -1., 75.);
0096       hMuonTimeExtraCSCTimeAtIpOutInErr[i] =
0097           ibooker.book1D("hMuonTimeExtraCSCTimeAtIpOutInErr", "MuonTimeExtra CSC TimeAtIpOutInErr", 100, 0., 8.);
0098       hMuonTimeExtraDTNDOF[i] = ibooker.book1D("hMuonTimeExtraDTNDOF", "MuonTimeExtra DT NDOF", 52, -1.5, 50.5);
0099       hMuonTimeExtraDTTimeAtIpInOut[i] =
0100           ibooker.book1D("hMuonTimeExtraDTTimeAtIpInOut", "MuonTimeExtra DT TimeAtIpInOut", 100, -20., 20.);
0101       hMuonTimeExtraDTTimeAtIpInOutErr[i] =
0102           ibooker.book1D("hMuonTimeExtraDTTimeAtIpInOutErr", "MuonTimeExtra DT TimeAtIpInOutErr", 100, 0., 8.);
0103       hMuonTimeExtraDTTimeAtIpOutIn[i] =
0104           ibooker.book1D("hMuonTimeExtraDTTimeAtIpOutIn", "MuonTimeExtra DT TimeAtIpOutIn", 100, -1., 75.);
0105       hMuonTimeExtraDTTimeAtIpOutInErr[i] =
0106           ibooker.book1D("hMuonTimeExtraDTTimeAtIpOutInErr", "MuonTimeExtra DT TimeAtIpOutInErr", 100, 0., 8.);
0107     }
0108 
0109     hCaloCompat[i] = ibooker.book1D("hCaloCompat", "Calo Compatibility", 101, -0.05, 1.05);
0110     hSegmentCompat[i] = ibooker.book1D("hSegmentCompat", "Segment Compatibility", 101, -0.05, 1.05);
0111     if (make2DPlots_)
0112       hCaloSegmentCompat[i] = ibooker.book2D(
0113           "hCaloSegmentCompat", "Calo Compatibility vs. Segment Compatibility", 101, -0.05, 1.05, 101, -0.05, 1.05);
0114     hMuonQualityTrkRelChi2[i] = ibooker.book1D("hMuonQualityTrkRelChi2", "MuonQuality TrkRelChi2", 100, 0., 1.5);
0115     hMuonQualityStaRelChi2[i] = ibooker.book1D("hMuonQualityStaRelChi2", "MuonQuality StaRelChi2", 100, 0., 3.);
0116     hMuonQualityTrkKink[i] = ibooker.book1D("hMuonQualityTrkKink", "MuonQuality TrkKink", 100, 0., 150.);
0117     hGlobalMuonPromptTightBool[i] =
0118         ibooker.book1D("hGlobalMuonPromptTightBool", "GlobalMuonPromptTight Boolean", 2, -0.5, 1.5);
0119     hTMLastStationLooseBool[i] = ibooker.book1D("hTMLastStationLooseBool", "TMLastStationLoose Boolean", 2, -0.5, 1.5);
0120     hTMLastStationTightBool[i] = ibooker.book1D("hTMLastStationTightBool", "TMLastStationTight Boolean", 2, -0.5, 1.5);
0121     hTM2DCompatibilityLooseBool[i] =
0122         ibooker.book1D("hTM2DCompatibilityLooseBool", "TM2DCompatibilityLoose Boolean", 2, -0.5, 1.5);
0123     hTM2DCompatibilityTightBool[i] =
0124         ibooker.book1D("hTM2DCompatibilityTightBool", "TM2DCompatibilityTight Boolean", 2, -0.5, 1.5);
0125     hTMOneStationLooseBool[i] = ibooker.book1D("hTMOneStationLooseBool", "TMOneStationLoose Boolean", 2, -0.5, 1.5);
0126     hTMOneStationTightBool[i] = ibooker.book1D("hTMOneStationTightBool", "TMOneStationTight Boolean", 2, -0.5, 1.5);
0127     hTMLastStationOptimizedLowPtLooseBool[i] = ibooker.book1D(
0128         "hTMLastStationOptimizedLowPtLooseBool", "TMLastStationOptimizedLowPtLoose Boolean", 2, -0.5, 1.5);
0129     hTMLastStationOptimizedLowPtTightBool[i] = ibooker.book1D(
0130         "hTMLastStationOptimizedLowPtTightBool", "TMLastStationOptimizedLowPtTight Boolean", 2, -0.5, 1.5);
0131     hGMTkChiCompatibilityBool[i] =
0132         ibooker.book1D("hGMTkChiCompatibilityBool", "GMTkChiCompatibility Boolean", 2, -0.5, 1.5);
0133     hGMStaChiCompatibilityBool[i] =
0134         ibooker.book1D("hGMStaChiCompatibilityBool", "GMStaChiCompatibility Boolean", 2, -0.5, 1.5);
0135     hGMTkKinkTightBool[i] = ibooker.book1D("hGMTkKinkTightBool", "GMTkKinkTight Boolean", 2, -0.5, 1.5);
0136     hTMLastStationAngLooseBool[i] =
0137         ibooker.book1D("hTMLastStationAngLooseBool", "TMLastStationAngLoose Boolean", 2, -0.5, 1.5);
0138     hTMLastStationAngTightBool[i] =
0139         ibooker.book1D("hTMLastStationAngTightBool", "TMLastStationAngTight Boolean", 2, -0.5, 1.5);
0140     hTMOneStationAngLooseBool[i] =
0141         ibooker.book1D("hTMOneStationAngLooseBool", "TMOneStationAngLoose Boolean", 2, -0.5, 1.5);
0142     hTMOneStationAngTightBool[i] =
0143         ibooker.book1D("hTMOneStationAngTightBool", "TMOneStationAngTight Boolean", 2, -0.5, 1.5);
0144     hTMLastStationOptimizedBarrelLowPtLooseBool[i] = ibooker.book1D(
0145         "hTMLastStationOptimizedBarrelLowPtLooseBool", "TMLastStationOptimizedBarrelLowPtLoose Boolean", 2, -0.5, 1.5);
0146     hTMLastStationOptimizedBarrelLowPtTightBool[i] = ibooker.book1D(
0147         "hTMLastStationOptimizedBarrelLowPtTightBool", "TMLastStationOptimizedBarrelLowPtTight Boolean", 2, -0.5, 1.5);
0148 
0149     if (makeCosmicCompatibilityPlots_) {
0150       hCombinedCosmicCompat[i] =
0151           ibooker.book1D("hCombinedCosmicCompat", "hCombinedCosmicCompatibility float", 40, 0., 10.);
0152       hTimeCosmicCompat[i] = ibooker.book1D("hTimeCosmicCompat", "hTimeCosmicCompatibility float", 6, 0., 3.);
0153       hB2BCosmicCompat[i] = ibooker.book1D("hB2BCosmicCompat", "Number of back-to-back partners", 10, 0, 10);
0154       hOverlapCosmicCompat[i] = ibooker.book1D("hOverlapCosmicCompat", "Overlap between muons and 1Leg", 2, 0, 2);
0155     }
0156 
0157     // by station
0158     for (int station = 0; station < 4; ++station) {
0159       if (makeShowerInformationPlots_) {
0160         sprintf(name, "hMuonShowerSizeT%i", station + 1);
0161         sprintf(title, "Station %i Transverse Cluster Size", station + 1);
0162         hMuonShowerSizeT[i][station] = ibooker.book1D(name, title, 1000, 0, 500);
0163         sprintf(name, "hMuonShowerDeltaR%i", station + 1);
0164         sprintf(title, "Station %i DeltaR", station + 1);
0165         hMuonShowerDeltaR[i][station] = ibooker.book1D(name, title, 5000, 0, 0.5);
0166         sprintf(name, "hMuonAllHits%i", station + 1);
0167         sprintf(title, "Station %i Number of 1D DT or 2D CSC RecHits", station + 1);
0168         hMuonAllHits[i][station] = ibooker.book1D(name, title, 400, 0, 400);
0169         sprintf(name, "hMuonHitsFromSegments%i", station + 1);
0170         sprintf(title, "Station %i Hits used by 4D DT or 3D CSC Segments", station + 1);
0171         hMuonHitsFromSegments[i][station] = ibooker.book1D(name, title, 400, 0, 400);
0172         sprintf(name, "hMuonUncorrelatedHits%i", station + 1);
0173         sprintf(title, "Station %i Uncorrelated Hits", station + 1);
0174         hMuonUncorrelatedHits[i][station] = ibooker.book1D(name, title, 400, 0, 400);
0175       }
0176 
0177       sprintf(name, "hDT%iPullxPropErr", station + 1);
0178       sprintf(title, "DT Station %i Pull X w/ Propagation Error Only", station + 1);
0179       hDTPullxPropErr[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0180 
0181       sprintf(name, "hDT%iPulldXdZPropErr", station + 1);
0182       sprintf(title, "DT Station %i Pull DxDz w/ Propagation Error Only", station + 1);
0183       hDTPulldXdZPropErr[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0184 
0185       if (station < 3) {
0186         sprintf(name, "hDT%iPullyPropErr", station + 1);
0187         sprintf(title, "DT Station %i Pull Y w/ Propagation Error Only", station + 1);
0188         hDTPullyPropErr[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0189 
0190         sprintf(name, "hDT%iPulldYdZPropErr", station + 1);
0191         sprintf(title, "DT Station %i Pull DyDz w/ Propagation Error Only", station + 1);
0192         hDTPulldYdZPropErr[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0193       }
0194 
0195       sprintf(name, "hDT%iDistWithSegment", station + 1);
0196       sprintf(title, "DT Station %i Dist When There Is A Segment", station + 1);
0197       hDTDistWithSegment[i][station] = ibooker.book1D(name, title, 100, -140., 30.);
0198 
0199       sprintf(name, "hDT%iDistWithNoSegment", station + 1);
0200       sprintf(title, "DT Station %i Dist When There Is No Segment", station + 1);
0201       hDTDistWithNoSegment[i][station] = ibooker.book1D(name, title, 100, -140., 30.);
0202 
0203       sprintf(name, "hDT%iPullDistWithSegment", station + 1);
0204       sprintf(title, "DT Station %i Pull Dist When There Is A Segment", station + 1);
0205       hDTPullDistWithSegment[i][station] = ibooker.book1D(name, title, 100, -140., 30.);
0206 
0207       sprintf(name, "hDT%iPullDistWithNoSegment", station + 1);
0208       sprintf(title, "DT Station %i Pull Dist When There Is No Segment", station + 1);
0209       hDTPullDistWithNoSegment[i][station] = ibooker.book1D(name, title, 100, -140., 30.);
0210 
0211       sprintf(name, "hCSC%iPullxPropErr", station + 1);
0212       sprintf(title, "CSC Station %i Pull X w/ Propagation Error Only", station + 1);
0213       hCSCPullxPropErr[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0214 
0215       sprintf(name, "hCSC%iPulldXdZPropErr", station + 1);
0216       sprintf(title, "CSC Station %i Pull DxDz w/ Propagation Error Only", station + 1);
0217       hCSCPulldXdZPropErr[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0218 
0219       sprintf(name, "hCSC%iPullyPropErr", station + 1);
0220       sprintf(title, "CSC Station %i Pull Y w/ Propagation Error Only", station + 1);
0221       hCSCPullyPropErr[i][station] = ibooker.book1D(name, title, 100, -20., 20.);
0222 
0223       sprintf(name, "hCSC%iPulldYdZPropErr", station + 1);
0224       sprintf(title, "CSC Station %i Pull DyDz w/ Propagation Error Only", station + 1);
0225       hCSCPulldYdZPropErr[i][station] = ibooker.book1D(name, title, 100, -50., 50.);
0226 
0227       sprintf(name, "hCSC%iDistWithSegment", station + 1);
0228       sprintf(title, "CSC Station %i Dist When There Is A Segment", station + 1);
0229       hCSCDistWithSegment[i][station] = ibooker.book1D(name, title, 100, -70., 20.);
0230 
0231       sprintf(name, "hCSC%iDistWithNoSegment", station + 1);
0232       sprintf(title, "CSC Station %i Dist When There Is No Segment", station + 1);
0233       hCSCDistWithNoSegment[i][station] = ibooker.book1D(name, title, 100, -70., 20.);
0234 
0235       sprintf(name, "hCSC%iPullDistWithSegment", station + 1);
0236       sprintf(title, "CSC Station %i Pull Dist When There Is A Segment", station + 1);
0237       hCSCPullDistWithSegment[i][station] = ibooker.book1D(name, title, 100, -70., 20.);
0238 
0239       sprintf(name, "hCSC%iPullDistWithNoSegment", station + 1);
0240       sprintf(title, "CSC Station %i Pull Dist When There Is No Segment", station + 1);
0241       hCSCPullDistWithNoSegment[i][station] = ibooker.book1D(name, title, 100, -70., 20.);
0242     }  // station
0243   }
0244 
0245   if (make2DPlots_) {
0246     ibooker.setCurrentFolder(baseFolder_);
0247     hSegmentIsAssociatedRZ =
0248         ibooker.book2D("hSegmentIsAssociatedRZ", "R-Z of Associated Segments", 2140, -1070., 1070., 850, 0., 850.);
0249     hSegmentIsAssociatedXY =
0250         ibooker.book2D("hSegmentIsAssociatedXY", "X-Y of Associated Segments", 1700, -850., 850., 1700, -850., 850.);
0251     hSegmentIsNotAssociatedRZ = ibooker.book2D(
0252         "hSegmentIsNotAssociatedRZ", "R-Z of Not Associated Segments", 2140, -1070., 1070., 850, 0., 850.);
0253     hSegmentIsNotAssociatedXY = ibooker.book2D(
0254         "hSegmentIsNotAssociatedXY", "X-Y of Not Associated Segments", 1700, -850., 850., 1700, -850., 850.);
0255     hSegmentIsBestDrAssociatedRZ = ibooker.book2D("hSegmentIsBestDrAssociatedRZ",
0256                                                   "R-Z of Best in Station by #DeltaR Associated Segments",
0257                                                   2140,
0258                                                   -1070.,
0259                                                   1070.,
0260                                                   850,
0261                                                   0.,
0262                                                   850.);
0263     hSegmentIsBestDrAssociatedXY = ibooker.book2D("hSegmentIsBestDrAssociatedXY",
0264                                                   "X-Y of Best in Station by #DeltaR Associated Segments",
0265                                                   1700,
0266                                                   -850.,
0267                                                   850.,
0268                                                   1700,
0269                                                   -850.,
0270                                                   850.);
0271     hSegmentIsBestDrNotAssociatedRZ = ibooker.book2D("hSegmentIsBestDrNotAssociatedRZ",
0272                                                      "R-Z of Best in Station by #DeltaR Not Associated Segments",
0273                                                      2140,
0274                                                      -1070.,
0275                                                      1070.,
0276                                                      850,
0277                                                      0.,
0278                                                      850.);
0279     hSegmentIsBestDrNotAssociatedXY = ibooker.book2D("hSegmentIsBestDrNotAssociatedXY",
0280                                                      "X-Y of Best in Station by #DeltaR Not Associated Segments",
0281                                                      1700,
0282                                                      -850.,
0283                                                      850.,
0284                                                      1700,
0285                                                      -850.,
0286                                                      850.);
0287   }
0288 
0289   if (useTrackerMuons_ && makeAllChamberPlots_) {
0290     ibooker.setCurrentFolder(baseFolder_ + "/TrackerMuons");
0291 
0292     // by chamber
0293     for (int station = 0; station < 4; ++station) {
0294       // DT wheels: -2 -> 2
0295       for (int wheel = 0; wheel < 5; ++wheel) {
0296         // DT sectors: 1 -> 14
0297         for (int sector = 0; sector < 14; ++sector) {
0298           sprintf(name, "hDTChamberDx_%i_%i_%i", station + 1, wheel - 2, sector + 1);
0299           sprintf(title, "DT Chamber Delta X: Station %i Wheel %i Sector %i", station + 1, wheel - 2, sector + 1);
0300           hDTChamberDx[station][wheel][sector] = ibooker.book1D(name, title, 100, -100., 100.);
0301 
0302           if (station < 3) {
0303             sprintf(name, "hDTChamberDy_%i_%i_%i", station + 1, wheel - 2, sector + 1);
0304             sprintf(title, "DT Chamber Delta Y: Station %i Wheel %i Sector %i", station + 1, wheel - 2, sector + 1);
0305             hDTChamberDy[station][wheel][sector] = ibooker.book1D(name, title, 100, -150., 150.);
0306           }
0307 
0308           sprintf(name, "hDTChamberEdgeXWithSegment_%i_%i_%i", station + 1, wheel - 2, sector + 1);
0309           sprintf(title,
0310                   "DT Chamber Edge X When There Is A Segment: Station %i Wheel "
0311                   "%i Sector %i",
0312                   station + 1,
0313                   wheel - 2,
0314                   sector + 1);
0315           hDTChamberEdgeXWithSegment[station][wheel][sector] = ibooker.book1D(name, title, 100, -140., 30.);
0316 
0317           sprintf(name, "hDTChamberEdgeXWithNoSegment_%i_%i_%i", station + 1, wheel - 2, sector + 1);
0318           sprintf(title,
0319                   "DT Chamber Edge X When There Is No Segment: Station %i "
0320                   "Wheel %i Sector %i",
0321                   station + 1,
0322                   wheel - 2,
0323                   sector + 1);
0324           hDTChamberEdgeXWithNoSegment[station][wheel][sector] = ibooker.book1D(name, title, 100, -140., 30.);
0325 
0326           sprintf(name, "hDTChamberEdgeYWithSegment_%i_%i_%i", station + 1, wheel - 2, sector + 1);
0327           sprintf(title,
0328                   "DT Chamber Edge Y When There Is A Segment: Station %i Wheel "
0329                   "%i Sector %i",
0330                   station + 1,
0331                   wheel - 2,
0332                   sector + 1);
0333           hDTChamberEdgeYWithSegment[station][wheel][sector] = ibooker.book1D(name, title, 100, -140., 30.);
0334 
0335           sprintf(name, "hDTChamberEdgeYWithNoSegment_%i_%i_%i", station + 1, wheel - 2, sector + 1);
0336           sprintf(title,
0337                   "DT Chamber Edge Y When There Is No Segment: Station %i "
0338                   "Wheel %i Sector %i",
0339                   station + 1,
0340                   wheel - 2,
0341                   sector + 1);
0342           hDTChamberEdgeYWithNoSegment[station][wheel][sector] = ibooker.book1D(name, title, 100, -140., 30.);
0343         }  // sector
0344       }  // wheel
0345 
0346       // CSC endcaps: 1 -> 2
0347       for (int endcap = 0; endcap < 2; ++endcap) {
0348         // CSC rings: 1 -> 4
0349         for (int ring = 0; ring < 4; ++ring) {
0350           // CSC chambers: 1 -> 36
0351           for (int chamber = 0; chamber < 36; ++chamber) {
0352             sprintf(name, "hCSCChamberDx_%i_%i_%i_%i", endcap + 1, station + 1, ring + 1, chamber + 1);
0353             sprintf(title,
0354                     "CSC Chamber Delta X: Endcap %i Station %i Ring %i Chamber %i",
0355                     endcap + 1,
0356                     station + 1,
0357                     ring + 1,
0358                     chamber + 1);
0359             hCSCChamberDx[endcap][station][ring][chamber] = ibooker.book1D(name, title, 100, -50., 50.);
0360 
0361             sprintf(name, "hCSCChamberDy_%i_%i_%i_%i", endcap + 1, station + 1, ring + 1, chamber + 1);
0362             sprintf(title,
0363                     "CSC Chamber Delta Y: Endcap %i Station %i Ring %i Chamber %i",
0364                     endcap + 1,
0365                     station + 1,
0366                     ring + 1,
0367                     chamber + 1);
0368             hCSCChamberDy[endcap][station][ring][chamber] = ibooker.book1D(name, title, 100, -50., 50.);
0369 
0370             sprintf(name, "hCSCChamberEdgeXWithSegment_%i_%i_%i_%i", endcap + 1, station + 1, ring + 1, chamber + 1);
0371             sprintf(title,
0372                     "CSC Chamber Edge X When There Is A Segment: Endcap %i "
0373                     "Station %i Ring %i Chamber %i",
0374                     endcap + 1,
0375                     station + 1,
0376                     ring + 1,
0377                     chamber + 1);
0378             hCSCChamberEdgeXWithSegment[endcap][station][ring][chamber] = ibooker.book1D(name, title, 100, -70., 20.);
0379 
0380             sprintf(name, "hCSCChamberEdgeXWithNoSegment_%i_%i_%i_%i", endcap + 1, station + 1, ring + 1, chamber + 1);
0381             sprintf(title,
0382                     "CSC Chamber Edge X When There Is No Segment: Endcap %i "
0383                     "Station %i Ring %i Chamber %i",
0384                     endcap + 1,
0385                     station + 1,
0386                     ring + 1,
0387                     chamber + 1);
0388             hCSCChamberEdgeXWithNoSegment[endcap][station][ring][chamber] = ibooker.book1D(name, title, 100, -70., 20.);
0389 
0390             sprintf(name, "hCSCChamberEdgeYWithSegment_%i_%i_%i_%i", endcap + 1, station + 1, ring + 1, chamber + 1);
0391             sprintf(title,
0392                     "CSC Chamber Edge Y When There Is A Segment: Endcap %i "
0393                     "Station %i Ring %i Chamber %i",
0394                     endcap + 1,
0395                     station + 1,
0396                     ring + 1,
0397                     chamber + 1);
0398             hCSCChamberEdgeYWithSegment[endcap][station][ring][chamber] = ibooker.book1D(name, title, 100, -70., 20.);
0399 
0400             sprintf(name, "hCSCChamberEdgeYWithNoSegment_%i_%i_%i_%i", endcap + 1, station + 1, ring + 1, chamber + 1);
0401             sprintf(title,
0402                     "CSC Chamber Edge Y When There Is No Segment: Endcap %i "
0403                     "Station %i Ring %i Chamber %i",
0404                     endcap + 1,
0405                     station + 1,
0406                     ring + 1,
0407                     chamber + 1);
0408             hCSCChamberEdgeYWithNoSegment[endcap][station][ring][chamber] = ibooker.book1D(name, title, 100, -70., 20.);
0409           }  // chamber
0410         }  // ring
0411       }  // endcap
0412     }  // station
0413   }
0414 }
0415 
0416 void MuonIdVal::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0417   using namespace edm;
0418   using namespace reco;
0419 
0420   iEvent.getByToken(inputMuonCollectionToken_, muonCollectionH_);
0421   iEvent.getByToken(inputDTRecSegment4DCollectionToken_, dtSegmentCollectionH_);
0422   iEvent.getByToken(inputCSCSegmentCollectionToken_, cscSegmentCollectionH_);
0423   iEvent.getByToken(inputMuonTimeExtraValueMapCombToken_, combinedMuonTimeExtraValueMapH_);
0424   iEvent.getByToken(inputMuonTimeExtraValueMapCSCToken_, cscMuonTimeExtraValueMapH_);
0425   iEvent.getByToken(inputMuonTimeExtraValueMapDTToken_, dtMuonTimeExtraValueMapH_);
0426   iEvent.getByToken(inputMuonShowerInformationValueMapToken_, muonShowerInformationValueMapH_);
0427   iEvent.getByToken(inputMuonCosmicCompatibilityValueMapToken_, muonCosmicCompatibilityValueMapH_);
0428 
0429   geometry_ = iSetup.getHandle(trackingGeomToken_);
0430 
0431   unsigned int muonIdx = 0;
0432   for (MuonCollection::const_iterator muon = muonCollectionH_->begin(); muon != muonCollectionH_->end(); ++muon) {
0433     // trackerMuon == 0; globalMuon == 1; trackerMuon && !globalMuon == 2;
0434     // globalMuon && !trackerMuon == 3
0435     for (unsigned int i = 0; i < 4; i++) {
0436       if (i == 0 && (!useTrackerMuons_ || !muon->isTrackerMuon()))
0437         continue;
0438       if (i == 1 && (!useGlobalMuons_ || !muon->isGlobalMuon()))
0439         continue;
0440       if (i == 2 && (!useTrackerMuonsNotGlobalMuons_ || (!(muon->isTrackerMuon() && !muon->isGlobalMuon()))))
0441         continue;
0442       if (i == 3 && (!useGlobalMuonsNotTrackerMuons_ || (!(muon->isGlobalMuon() && !muon->isTrackerMuon()))))
0443         continue;
0444 
0445       if (makeEnergyPlots_ && muon->isEnergyValid()) {
0446         // EM
0447         if (fabs(muon->eta()) > 1.479)
0448           hEnergyEMEndcap[i]->Fill(muon->calEnergy().em);
0449         else
0450           hEnergyEMBarrel[i]->Fill(muon->calEnergy().em);
0451         // HAD
0452         if (fabs(muon->eta()) > 1.4)
0453           hEnergyHAEndcap[i]->Fill(muon->calEnergy().had);
0454         else
0455           hEnergyHABarrel[i]->Fill(muon->calEnergy().had);
0456         // HO
0457         if (fabs(muon->eta()) < 1.26)
0458           hEnergyHO[i]->Fill(muon->calEnergy().ho);
0459       }
0460 
0461       if (makeTimePlots_) {
0462         if (muon->isTimeValid()) {
0463           hMuonTimeNDOF[i]->Fill(muon->time().nDof);
0464           hMuonTimeTimeAtIpInOut[i]->Fill(muon->time().timeAtIpInOut);
0465           hMuonTimeTimeAtIpInOutErr[i]->Fill(muon->time().timeAtIpInOutErr);
0466           hMuonTimeTimeAtIpOutIn[i]->Fill(muon->time().timeAtIpOutIn);
0467           hMuonTimeTimeAtIpOutInErr[i]->Fill(muon->time().timeAtIpOutInErr);
0468         }
0469 
0470         MuonRef muonRef(muonCollectionH_, muonIdx);
0471         MuonTimeExtra combinedMuonTimeExtra = (*combinedMuonTimeExtraValueMapH_)[muonRef];
0472         MuonTimeExtra cscMuonTimeExtra = (*cscMuonTimeExtraValueMapH_)[muonRef];
0473         MuonTimeExtra dtMuonTimeExtra = (*dtMuonTimeExtraValueMapH_)[muonRef];
0474 
0475         hMuonTimeExtraCombinedNDOF[i]->Fill(combinedMuonTimeExtra.nDof());
0476         hMuonTimeExtraCombinedTimeAtIpInOut[i]->Fill(combinedMuonTimeExtra.timeAtIpInOut());
0477         hMuonTimeExtraCombinedTimeAtIpInOutErr[i]->Fill(combinedMuonTimeExtra.timeAtIpInOutErr());
0478         hMuonTimeExtraCombinedTimeAtIpOutIn[i]->Fill(combinedMuonTimeExtra.timeAtIpOutIn());
0479         hMuonTimeExtraCombinedTimeAtIpOutInErr[i]->Fill(combinedMuonTimeExtra.timeAtIpOutInErr());
0480         hMuonTimeExtraCSCNDOF[i]->Fill(cscMuonTimeExtra.nDof());
0481         hMuonTimeExtraCSCTimeAtIpInOut[i]->Fill(cscMuonTimeExtra.timeAtIpInOut());
0482         hMuonTimeExtraCSCTimeAtIpInOutErr[i]->Fill(cscMuonTimeExtra.timeAtIpInOutErr());
0483         hMuonTimeExtraCSCTimeAtIpOutIn[i]->Fill(cscMuonTimeExtra.timeAtIpOutIn());
0484         hMuonTimeExtraCSCTimeAtIpOutInErr[i]->Fill(cscMuonTimeExtra.timeAtIpOutInErr());
0485         hMuonTimeExtraDTNDOF[i]->Fill(dtMuonTimeExtra.nDof());
0486         hMuonTimeExtraDTTimeAtIpInOut[i]->Fill(dtMuonTimeExtra.timeAtIpInOut());
0487         hMuonTimeExtraDTTimeAtIpInOutErr[i]->Fill(dtMuonTimeExtra.timeAtIpInOutErr());
0488         hMuonTimeExtraDTTimeAtIpOutIn[i]->Fill(dtMuonTimeExtra.timeAtIpOutIn());
0489         hMuonTimeExtraDTTimeAtIpOutInErr[i]->Fill(dtMuonTimeExtra.timeAtIpOutInErr());
0490       }
0491 
0492       if (muon->isCaloCompatibilityValid())
0493         hCaloCompat[i]->Fill(muon->caloCompatibility());
0494       hSegmentCompat[i]->Fill(muon::segmentCompatibility(*muon));
0495       if (make2DPlots_ && muon->isCaloCompatibilityValid())
0496         hCaloSegmentCompat[i]->Fill(muon->caloCompatibility(), muon::segmentCompatibility(*muon));
0497       if (muon->isQualityValid()) {
0498         hMuonQualityTrkRelChi2[i]->Fill(muon->combinedQuality().trkRelChi2);
0499         hMuonQualityStaRelChi2[i]->Fill(muon->combinedQuality().staRelChi2);
0500         hMuonQualityTrkKink[i]->Fill(muon->combinedQuality().trkKink);
0501       }
0502       hGlobalMuonPromptTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::GlobalMuonPromptTight));
0503       hTMLastStationLooseBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMLastStationLoose));
0504       hTMLastStationTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMLastStationTight));
0505       hTM2DCompatibilityLooseBool[i]->Fill(muon::isGoodMuon(*muon, muon::TM2DCompatibilityLoose));
0506       hTM2DCompatibilityTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::TM2DCompatibilityTight));
0507       hTMOneStationLooseBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMOneStationLoose));
0508       hTMOneStationTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMOneStationTight));
0509       hTMLastStationOptimizedLowPtLooseBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMLastStationOptimizedLowPtLoose));
0510       hTMLastStationOptimizedLowPtTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMLastStationOptimizedLowPtTight));
0511       hGMTkChiCompatibilityBool[i]->Fill(muon::isGoodMuon(*muon, muon::GMTkChiCompatibility));
0512       hGMStaChiCompatibilityBool[i]->Fill(muon::isGoodMuon(*muon, muon::GMStaChiCompatibility));
0513       hGMTkKinkTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::GMTkKinkTight));
0514       hTMLastStationAngLooseBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMLastStationAngLoose));
0515       hTMLastStationAngTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMLastStationAngTight));
0516       hTMOneStationAngLooseBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMOneStationAngLoose));
0517       hTMOneStationAngTightBool[i]->Fill(muon::isGoodMuon(*muon, muon::TMOneStationAngTight));
0518       hTMLastStationOptimizedBarrelLowPtLooseBool[i]->Fill(
0519           muon::isGoodMuon(*muon, muon::TMLastStationOptimizedBarrelLowPtLoose));
0520       hTMLastStationOptimizedBarrelLowPtTightBool[i]->Fill(
0521           muon::isGoodMuon(*muon, muon::TMLastStationOptimizedBarrelLowPtTight));
0522 
0523       if (makeCosmicCompatibilityPlots_) {
0524         MuonRef muonRef(muonCollectionH_, muonIdx);
0525         MuonCosmicCompatibility muonCosmicCompatibility = (*muonCosmicCompatibilityValueMapH_)[muonRef];
0526         hCombinedCosmicCompat[i]->Fill(muonCosmicCompatibility.cosmicCompatibility);
0527         hTimeCosmicCompat[i]->Fill(muonCosmicCompatibility.timeCompatibility);
0528         hB2BCosmicCompat[i]->Fill(muonCosmicCompatibility.backToBackCompatibility);
0529         hOverlapCosmicCompat[i]->Fill(muonCosmicCompatibility.overlapCompatibility);
0530       }
0531 
0532       // by station
0533       for (int station = 0; station < 4; ++station) {
0534         if (makeShowerInformationPlots_) {
0535           MuonRef muonRef(muonCollectionH_, muonIdx);
0536           MuonShower muonShowerInformation = (*muonShowerInformationValueMapH_)[muonRef];
0537 
0538           hMuonShowerSizeT[i][station]->Fill((muonShowerInformation.stationShowerSizeT).at(station));
0539           hMuonShowerDeltaR[i][station]->Fill((muonShowerInformation.stationShowerDeltaR.at(station)));
0540           hMuonAllHits[i][station]->Fill((muonShowerInformation.nStationHits.at(station)));
0541           hMuonHitsFromSegments[i][station]->Fill((muonShowerInformation.nStationCorrelatedHits.at(station)));
0542           hMuonUncorrelatedHits[i][station]->Fill((muonShowerInformation.nStationHits.at(station)) -
0543                                                   muonShowerInformation.nStationCorrelatedHits.at(station));
0544         }
0545 
0546         Fill(hDTPullxPropErr[i][station],
0547              muon->pullX(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, false));
0548         Fill(hDTPulldXdZPropErr[i][station],
0549              muon->pullDxDz(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, false));
0550 
0551         if (station < 3) {
0552           Fill(hDTPullyPropErr[i][station],
0553                muon->pullY(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, false));
0554           Fill(hDTPulldYdZPropErr[i][station],
0555                muon->pullDyDz(station + 1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, false));
0556         }
0557 
0558         float distance = muon->trackDist(station + 1, MuonSubdetId::DT);
0559         float error = muon->trackDistErr(station + 1, MuonSubdetId::DT);
0560         if (error == 0)
0561           error = 0.000001;
0562 
0563         if (muon->numberOfSegments(station + 1, MuonSubdetId::DT, Muon::NoArbitration) > 0) {
0564           Fill(hDTDistWithSegment[i][station], distance);
0565           Fill(hDTPullDistWithSegment[i][station], distance / error);
0566         } else {
0567           Fill(hDTDistWithNoSegment[i][station], distance);
0568           Fill(hDTPullDistWithNoSegment[i][station], distance / error);
0569         }
0570 
0571         Fill(hCSCPullxPropErr[i][station],
0572              muon->pullX(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, false));
0573         Fill(hCSCPulldXdZPropErr[i][station],
0574              muon->pullDxDz(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, false));
0575         Fill(hCSCPullyPropErr[i][station],
0576              muon->pullY(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, false));
0577         Fill(hCSCPulldYdZPropErr[i][station],
0578              muon->pullDyDz(station + 1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, false));
0579 
0580         distance = muon->trackDist(station + 1, MuonSubdetId::CSC);
0581         error = muon->trackDistErr(station + 1, MuonSubdetId::CSC);
0582         if (error == 0)
0583           error = 0.000001;
0584 
0585         if (muon->numberOfSegments(station + 1, MuonSubdetId::CSC, Muon::NoArbitration) > 0) {
0586           Fill(hCSCDistWithSegment[i][station], distance);
0587           Fill(hCSCPullDistWithSegment[i][station], distance / error);
0588         } else {
0589           Fill(hCSCDistWithNoSegment[i][station], distance);
0590           Fill(hCSCPullDistWithNoSegment[i][station], distance / error);
0591         }
0592       }  // station
0593     }
0594 
0595     if (!useTrackerMuons_ || !muon->isTrackerMuon())
0596       continue;
0597     if (makeAllChamberPlots_) {
0598       // by chamber
0599       for (std::vector<MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
0600            chamberMatch != muon->matches().end();
0601            ++chamberMatch) {
0602         int station = chamberMatch->station();
0603 
0604         if (chamberMatch->detector() == MuonSubdetId::DT) {
0605           DTChamberId dtId(chamberMatch->id.rawId());
0606           int wheel = dtId.wheel();
0607           int sector = dtId.sector();
0608 
0609           if (chamberMatch->segmentMatches.empty()) {
0610             Fill(hDTChamberEdgeXWithNoSegment[station - 1][wheel + 2][sector - 1], chamberMatch->edgeX);
0611             Fill(hDTChamberEdgeYWithNoSegment[station - 1][wheel + 2][sector - 1], chamberMatch->edgeY);
0612           } else {
0613             Fill(hDTChamberEdgeXWithSegment[station - 1][wheel + 2][sector - 1], chamberMatch->edgeX);
0614             Fill(hDTChamberEdgeYWithSegment[station - 1][wheel + 2][sector - 1], chamberMatch->edgeY);
0615 
0616             for (std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
0617                  segmentMatch != chamberMatch->segmentMatches.end();
0618                  ++segmentMatch) {
0619               if (segmentMatch->isMask(MuonSegmentMatch::BestInChamberByDR)) {
0620                 Fill(hDTChamberDx[station - 1][wheel + 2][sector - 1], chamberMatch->x - segmentMatch->x);
0621                 if (station < 4)
0622                   Fill(hDTChamberDy[station - 1][wheel + 2][sector - 1], chamberMatch->y - segmentMatch->y);
0623                 break;
0624               }
0625             }  // segmentMatch
0626           }
0627 
0628           continue;
0629         }
0630 
0631         if (chamberMatch->detector() == MuonSubdetId::CSC) {
0632           CSCDetId cscId(chamberMatch->id.rawId());
0633           int endcap = cscId.endcap();
0634           int ring = cscId.ring();
0635           int chamber = cscId.chamber();
0636 
0637           if (chamberMatch->segmentMatches.empty()) {
0638             Fill(hCSCChamberEdgeXWithNoSegment[endcap - 1][station - 1][ring - 1][chamber - 1], chamberMatch->edgeX);
0639             Fill(hCSCChamberEdgeYWithNoSegment[endcap - 1][station - 1][ring - 1][chamber - 1], chamberMatch->edgeY);
0640           } else {
0641             Fill(hCSCChamberEdgeXWithSegment[endcap - 1][station - 1][ring - 1][chamber - 1], chamberMatch->edgeX);
0642             Fill(hCSCChamberEdgeYWithSegment[endcap - 1][station - 1][ring - 1][chamber - 1], chamberMatch->edgeY);
0643 
0644             for (std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
0645                  segmentMatch != chamberMatch->segmentMatches.end();
0646                  ++segmentMatch) {
0647               if (segmentMatch->isMask(MuonSegmentMatch::BestInChamberByDR)) {
0648                 Fill(hCSCChamberDx[endcap - 1][station - 1][ring - 1][chamber - 1], chamberMatch->x - segmentMatch->x);
0649                 Fill(hCSCChamberDy[endcap - 1][station - 1][ring - 1][chamber - 1], chamberMatch->y - segmentMatch->y);
0650                 break;
0651               }
0652             }  // segmentMatch
0653           }
0654         }
0655       }  // chamberMatch
0656     }
0657     ++muonIdx;
0658   }  // muon
0659 
0660   if (!make2DPlots_)
0661     return;
0662 
0663   for (DTRecSegment4DCollection::const_iterator segment = dtSegmentCollectionH_->begin();
0664        segment != dtSegmentCollectionH_->end();
0665        ++segment) {
0666     LocalPoint segmentLocalPosition = segment->localPosition();
0667     LocalVector segmentLocalDirection = segment->localDirection();
0668     LocalError segmentLocalPositionError = segment->localPositionError();
0669     LocalError segmentLocalDirectionError = segment->localDirectionError();
0670     const GeomDet *segmentGeomDet = geometry_->idToDet(segment->geographicalId());
0671     GlobalPoint segmentGlobalPosition = segmentGeomDet->toGlobal(segment->localPosition());
0672     bool segmentFound = false;
0673     bool segmentBestDrFound = false;
0674 
0675     for (MuonCollection::const_iterator muon = muonCollectionH_->begin(); muon != muonCollectionH_->end(); ++muon) {
0676       if (!muon->isMatchesValid())
0677         continue;
0678 
0679       for (std::vector<MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
0680            chamberMatch != muon->matches().end();
0681            ++chamberMatch) {
0682         for (std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
0683              segmentMatch != chamberMatch->segmentMatches.end();
0684              ++segmentMatch) {
0685           if (fabs(segmentMatch->x - segmentLocalPosition.x()) < 1E-6 &&
0686               fabs(segmentMatch->y - segmentLocalPosition.y()) < 1E-6 &&
0687               fabs(segmentMatch->dXdZ - segmentLocalDirection.x() / segmentLocalDirection.z()) < 1E-6 &&
0688               fabs(segmentMatch->dYdZ - segmentLocalDirection.y() / segmentLocalDirection.z()) < 1E-6 &&
0689               fabs(segmentMatch->xErr - sqrt(segmentLocalPositionError.xx())) < 1E-6 &&
0690               fabs(segmentMatch->yErr - sqrt(segmentLocalPositionError.yy())) < 1E-6 &&
0691               fabs(segmentMatch->dXdZErr - sqrt(segmentLocalDirectionError.xx())) < 1E-6 &&
0692               fabs(segmentMatch->dYdZErr - sqrt(segmentLocalDirectionError.yy())) < 1E-6) {
0693             segmentFound = true;
0694             if (segmentMatch->isMask(reco::MuonSegmentMatch::BestInStationByDR))
0695               segmentBestDrFound = true;
0696             break;
0697           }
0698         }  // segmentMatch
0699         if (segmentFound)
0700           break;
0701       }  // chamberMatch
0702       if (segmentFound)
0703         break;
0704     }  // muon
0705 
0706     if (segmentFound) {
0707       hSegmentIsAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0708       hSegmentIsAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0709 
0710       if (segmentBestDrFound) {
0711         hSegmentIsBestDrAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0712         hSegmentIsBestDrAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0713       }
0714     } else {
0715       hSegmentIsNotAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0716       hSegmentIsNotAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0717       hSegmentIsBestDrNotAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0718       hSegmentIsBestDrNotAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0719     }
0720   }  // dt segment
0721 
0722   for (CSCSegmentCollection::const_iterator segment = cscSegmentCollectionH_->begin();
0723        segment != cscSegmentCollectionH_->end();
0724        ++segment) {
0725     LocalPoint segmentLocalPosition = segment->localPosition();
0726     LocalVector segmentLocalDirection = segment->localDirection();
0727     LocalError segmentLocalPositionError = segment->localPositionError();
0728     LocalError segmentLocalDirectionError = segment->localDirectionError();
0729     const GeomDet *segmentGeomDet = geometry_->idToDet(segment->geographicalId());
0730     GlobalPoint segmentGlobalPosition = segmentGeomDet->toGlobal(segment->localPosition());
0731     bool segmentFound = false;
0732     bool segmentBestDrFound = false;
0733 
0734     for (MuonCollection::const_iterator muon = muonCollectionH_->begin(); muon != muonCollectionH_->end(); ++muon) {
0735       if (!muon->isMatchesValid())
0736         continue;
0737 
0738       for (std::vector<MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
0739            chamberMatch != muon->matches().end();
0740            ++chamberMatch) {
0741         for (std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
0742              segmentMatch != chamberMatch->segmentMatches.end();
0743              ++segmentMatch) {
0744           if (fabs(segmentMatch->x - segmentLocalPosition.x()) < 1E-6 &&
0745               fabs(segmentMatch->y - segmentLocalPosition.y()) < 1E-6 &&
0746               fabs(segmentMatch->dXdZ - segmentLocalDirection.x() / segmentLocalDirection.z()) < 1E-6 &&
0747               fabs(segmentMatch->dYdZ - segmentLocalDirection.y() / segmentLocalDirection.z()) < 1E-6 &&
0748               fabs(segmentMatch->xErr - sqrt(segmentLocalPositionError.xx())) < 1E-6 &&
0749               fabs(segmentMatch->yErr - sqrt(segmentLocalPositionError.yy())) < 1E-6 &&
0750               fabs(segmentMatch->dXdZErr - sqrt(segmentLocalDirectionError.xx())) < 1E-6 &&
0751               fabs(segmentMatch->dYdZErr - sqrt(segmentLocalDirectionError.yy())) < 1E-6) {
0752             segmentFound = true;
0753             if (segmentMatch->isMask(reco::MuonSegmentMatch::BestInStationByDR))
0754               segmentBestDrFound = true;
0755             break;
0756           }
0757         }  // segmentMatch
0758         if (segmentFound)
0759           break;
0760       }  // chamberMatch
0761       if (segmentFound)
0762         break;
0763     }  // muon
0764 
0765     if (segmentFound) {
0766       hSegmentIsAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0767       hSegmentIsAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0768 
0769       if (segmentBestDrFound) {
0770         hSegmentIsBestDrAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0771         hSegmentIsBestDrAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0772       }
0773     } else {
0774       hSegmentIsNotAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0775       hSegmentIsNotAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0776       hSegmentIsBestDrNotAssociatedRZ->Fill(segmentGlobalPosition.z(), segmentGlobalPosition.perp());
0777       hSegmentIsBestDrNotAssociatedXY->Fill(segmentGlobalPosition.x(), segmentGlobalPosition.y());
0778     }
0779   }  // csc segment
0780 }
0781 
0782 void MuonIdVal::Fill(MonitorElement *me, float f) {
0783   if (fabs(f) > 900000)
0784     return;
0785   // if (fabs(f) < 1E-8) return;
0786   me->Fill(f);
0787 }
0788 
0789 // define this as a plug-in
0790 DEFINE_FWK_MODULE(MuonIdVal);