CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQMOffline/Muon/src/MuonIdDQM.cc

Go to the documentation of this file.
00001 #include "DQMOffline/Muon/interface/MuonIdDQM.h"
00002 
00003 MuonIdDQM::MuonIdDQM(const edm::ParameterSet& iConfig)
00004 {
00005    inputMuonCollection_ = iConfig.getParameter<edm::InputTag>("inputMuonCollection");
00006    inputDTRecSegment4DCollection_ = iConfig.getParameter<edm::InputTag>("inputDTRecSegment4DCollection");
00007    inputCSCSegmentCollection_ = iConfig.getParameter<edm::InputTag>("inputCSCSegmentCollection");
00008    useTrackerMuons_ = iConfig.getUntrackedParameter<bool>("useTrackerMuons");
00009    useGlobalMuons_ = iConfig.getUntrackedParameter<bool>("useGlobalMuons");
00010    useTrackerMuonsNotGlobalMuons_ = iConfig.getUntrackedParameter<bool>("useTrackerMuonsNotGlobalMuons");
00011    useGlobalMuonsNotTrackerMuons_ = iConfig.getUntrackedParameter<bool>("useGlobalMuonsNotTrackerMuons");
00012    baseFolder_ = iConfig.getUntrackedParameter<std::string>("baseFolder");
00013 
00014    dbe_ = 0;
00015    dbe_ = edm::Service<DQMStore>().operator->();
00016 }
00017 
00018 MuonIdDQM::~MuonIdDQM() {}
00019 
00020 void 
00021 MuonIdDQM::beginJob()
00022 {
00023    char name[100], title[200];
00024 
00025    // trackerMuon == 0; globalMuon == 1; trackerMuon && !globalMuon == 2; globalMuon && !trackerMuon == 3
00026    for (unsigned int i = 0; i < 4; i++) {
00027       if ((i == 0 && ! useTrackerMuons_) || (i == 1 && ! useGlobalMuons_)) continue;
00028       if ((i == 2 && ! useTrackerMuonsNotGlobalMuons_) || (i == 3 && ! useGlobalMuonsNotTrackerMuons_)) continue;
00029       if (i == 0) dbe_->setCurrentFolder(baseFolder_+"/TrackerMuons");
00030       if (i == 1) dbe_->setCurrentFolder(baseFolder_+"/GlobalMuons");
00031       if (i == 2) dbe_->setCurrentFolder(baseFolder_+"/TrackerMuonsNotGlobalMuons");
00032       if (i == 3) dbe_->setCurrentFolder(baseFolder_+"/GlobalMuonsNotTrackerMuons");
00033 
00034       hNumChambers[i] = dbe_->book1D("hNumChambers", "Number of Chambers", 11, -0.5, 10.5);
00035       hNumMatches[i] = dbe_->book1D("hNumMatches", "Number of Matches", 11, -0.5, 10.5);
00036 
00037       // by station
00038       for(int station = 0; station < 4; ++station)
00039       {
00040          sprintf(name, "hDT%iNumSegments", station+1);
00041          sprintf(title, "DT Station %i Number of Segments (No Arbitration)", station+1);
00042          hDTNumSegments[i][station] = dbe_->book1D(name, title, 11, -0.5, 10.5);
00043 
00044          sprintf(name, "hDT%iDx", station+1);
00045          sprintf(title, "DT Station %i Delta X", station+1);
00046          hDTDx[i][station] = dbe_->book1D(name, title, 100, -100., 100.);
00047 
00048          sprintf(name, "hDT%iPullx", station+1);
00049          sprintf(title, "DT Station %i Pull X", station+1);
00050          hDTPullx[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00051 
00052          sprintf(name, "hDT%iDdXdZ", station+1);
00053          sprintf(title, "DT Station %i Delta DxDz", station+1);
00054          hDTDdXdZ[i][station] = dbe_->book1D(name, title, 100, -1., 1.);
00055 
00056          sprintf(name, "hDT%iPulldXdZ", station+1);
00057          sprintf(title, "DT Station %i Pull DxDz", station+1);
00058          hDTPulldXdZ[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00059 
00060          if (station < 3) {
00061             sprintf(name, "hDT%iDy", station+1);
00062             sprintf(title, "DT Station %i Delta Y", station+1);
00063             hDTDy[i][station] = dbe_->book1D(name, title, 100, -150., 150.);
00064 
00065             sprintf(name, "hDT%iPully", station+1);
00066             sprintf(title, "DT Station %i Pull Y", station+1);
00067             hDTPully[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00068 
00069             sprintf(name, "hDT%iDdYdZ", station+1);
00070             sprintf(title, "DT Station %i Delta DyDz", station+1);
00071             hDTDdYdZ[i][station] = dbe_->book1D(name, title, 100, -2., 2.);
00072 
00073             sprintf(name, "hDT%iPulldYdZ", station+1);
00074             sprintf(title, "DT Station %i Pull DyDz", station+1);
00075             hDTPulldYdZ[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00076          }
00077 
00078          sprintf(name, "hCSC%iNumSegments", station+1);
00079          sprintf(title, "CSC Station %i Number of Segments (No Arbitration)", station+1);
00080          hCSCNumSegments[i][station] = dbe_->book1D(name, title, 11, -0.5, 10.5);
00081 
00082          sprintf(name, "hCSC%iDx", station+1);
00083          sprintf(title, "CSC Station %i Delta X", station+1);
00084          hCSCDx[i][station] = dbe_->book1D(name, title, 100, -50., 50.);
00085 
00086          sprintf(name, "hCSC%iPullx", station+1);
00087          sprintf(title, "CSC Station %i Pull X", station+1);
00088          hCSCPullx[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00089 
00090          sprintf(name, "hCSC%iDdXdZ", station+1);
00091          sprintf(title, "CSC Station %i Delta DxDz", station+1);
00092          hCSCDdXdZ[i][station] = dbe_->book1D(name, title, 100, -1., 1.);
00093 
00094          sprintf(name, "hCSC%iPulldXdZ", station+1);
00095          sprintf(title, "CSC Station %i Pull DxDz", station+1);
00096          hCSCPulldXdZ[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00097 
00098          sprintf(name, "hCSC%iDy", station+1);
00099          sprintf(title, "CSC Station %i Delta Y", station+1);
00100          hCSCDy[i][station] = dbe_->book1D(name, title, 100, -50., 50.);
00101 
00102          sprintf(name, "hCSC%iPully", station+1);
00103          sprintf(title, "CSC Station %i Pull Y", station+1);
00104          hCSCPully[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00105 
00106          sprintf(name, "hCSC%iDdYdZ", station+1);
00107          sprintf(title, "CSC Station %i Delta DyDz", station+1);
00108          hCSCDdYdZ[i][station] = dbe_->book1D(name, title, 100, -1., 1.);
00109 
00110          sprintf(name, "hCSC%iPulldYdZ", station+1);
00111          sprintf(title, "CSC Station %i Pull DyDz", station+1);
00112          hCSCPulldYdZ[i][station] = dbe_->book1D(name, title, 100, -20., 20.);
00113       }// station
00114    }
00115 
00116    dbe_->setCurrentFolder(baseFolder_);
00117    hSegmentIsAssociatedBool = dbe_->book1D("hSegmentIsAssociatedBool", "Segment Is Associated Boolean", 2, -0.5, 1.5);
00118 }
00119 
00120 void
00121 MuonIdDQM::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00122 {
00123    using namespace edm;
00124    using namespace reco;
00125 
00126    iEvent.getByLabel(inputMuonCollection_, muonCollectionH_);
00127    iEvent.getByLabel(inputDTRecSegment4DCollection_, dtSegmentCollectionH_);
00128    iEvent.getByLabel(inputCSCSegmentCollection_, cscSegmentCollectionH_);
00129    iSetup.get<GlobalTrackingGeometryRecord>().get(geometry_);
00130 
00131    for(MuonCollection::const_iterator muon = muonCollectionH_->begin();
00132          muon != muonCollectionH_->end(); ++muon)
00133    {
00134       // trackerMuon == 0; globalMuon == 1; trackerMuon && !globalMuon == 2; globalMuon && !trackerMuon == 3
00135       for (unsigned int i = 0; i < 4; i++) {
00136          if (i == 0 && (! useTrackerMuons_ || ! muon->isTrackerMuon())) continue;
00137          if (i == 1 && (! useGlobalMuons_ || ! muon->isGlobalMuon())) continue;
00138          if (i == 2 && (! useTrackerMuonsNotGlobalMuons_ || (! (muon->isTrackerMuon() && ! muon->isGlobalMuon())))) continue;
00139          if (i == 3 && (! useGlobalMuonsNotTrackerMuons_ || (! (muon->isGlobalMuon() && ! muon->isTrackerMuon())))) continue;
00140 
00141          hNumChambers[i]->Fill(muon->numberOfChambers());
00142          hNumMatches[i]->Fill(muon->numberOfMatches(Muon::SegmentAndTrackArbitration));
00143 
00144          // by station
00145          for(int station = 0; station < 4; ++station)
00146          {
00147             // only fill num segments if we crossed (or nearly crossed) a chamber
00148             if (muon->trackX(station+1, MuonSubdetId::DT, Muon::NoArbitration) < 900000)
00149                hDTNumSegments[i][station]->Fill(muon->numberOfSegments(station+1, MuonSubdetId::DT, Muon::NoArbitration));
00150             Fill(hDTDx[i][station], muon->dX(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
00151             Fill(hDTPullx[i][station], muon->pullX(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
00152             Fill(hDTDdXdZ[i][station], muon->dDxDz(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
00153             Fill(hDTPulldXdZ[i][station], muon->pullDxDz(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
00154 
00155             if (station < 3) {
00156                Fill(hDTDy[i][station], muon->dY(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
00157                Fill(hDTPully[i][station], muon->pullY(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
00158                Fill(hDTDdYdZ[i][station], muon->dDyDz(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration));
00159                Fill(hDTPulldYdZ[i][station], muon->pullDyDz(station+1, MuonSubdetId::DT, Muon::SegmentAndTrackArbitration, true));
00160             }
00161 
00162             // only fill num segments if we crossed (or nearly crossed) a chamber
00163             if (muon->trackX(station+1, MuonSubdetId::CSC, Muon::NoArbitration) < 900000)
00164                hCSCNumSegments[i][station]->Fill(muon->numberOfSegments(station+1, MuonSubdetId::CSC, Muon::NoArbitration));
00165             Fill(hCSCDx[i][station], muon->dX(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
00166             Fill(hCSCPullx[i][station], muon->pullX(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
00167             Fill(hCSCDdXdZ[i][station], muon->dDxDz(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
00168             Fill(hCSCPulldXdZ[i][station], muon->pullDxDz(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
00169             Fill(hCSCDy[i][station], muon->dY(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
00170             Fill(hCSCPully[i][station], muon->pullY(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
00171             Fill(hCSCDdYdZ[i][station], muon->dDyDz(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration));
00172             Fill(hCSCPulldYdZ[i][station], muon->pullDyDz(station+1, MuonSubdetId::CSC, Muon::SegmentAndTrackArbitration, true));
00173          }
00174       }
00175    }// muon
00176 
00177    for(DTRecSegment4DCollection::const_iterator segment = dtSegmentCollectionH_->begin();
00178          segment != dtSegmentCollectionH_->end(); ++segment)
00179    {
00180       LocalPoint  segmentLocalPosition       = segment->localPosition();
00181       LocalVector segmentLocalDirection      = segment->localDirection();
00182       LocalError  segmentLocalPositionError  = segment->localPositionError();
00183       LocalError  segmentLocalDirectionError = segment->localDirectionError();
00184       bool segmentFound = false;
00185 
00186       for(MuonCollection::const_iterator muon = muonCollectionH_->begin();
00187             muon != muonCollectionH_->end(); ++muon)
00188       {
00189          if (! muon->isMatchesValid())
00190             continue;
00191 
00192          for(std::vector<MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
00193                chamberMatch != muon->matches().end(); ++chamberMatch) {
00194             for(std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
00195                   segmentMatch != chamberMatch->segmentMatches.end(); ++segmentMatch)
00196             {
00197                if (fabs(segmentMatch->x       - segmentLocalPosition.x()                           ) < 1E-6 &&
00198                    fabs(segmentMatch->y       - segmentLocalPosition.y()                           ) < 1E-6 &&
00199                    fabs(segmentMatch->dXdZ    - segmentLocalDirection.x()/segmentLocalDirection.z()) < 1E-6 &&
00200                    fabs(segmentMatch->dYdZ    - segmentLocalDirection.y()/segmentLocalDirection.z()) < 1E-6 &&
00201                    fabs(segmentMatch->xErr    - sqrt(segmentLocalPositionError.xx())               ) < 1E-6 &&
00202                    fabs(segmentMatch->yErr    - sqrt(segmentLocalPositionError.yy())               ) < 1E-6 &&
00203                    fabs(segmentMatch->dXdZErr - sqrt(segmentLocalDirectionError.xx())              ) < 1E-6 &&
00204                    fabs(segmentMatch->dYdZErr - sqrt(segmentLocalDirectionError.yy())              ) < 1E-6)
00205                {
00206                   segmentFound = true;
00207                   break;
00208                }
00209             }// segmentMatch
00210             if (segmentFound) break;
00211          }// chamberMatch
00212          if (segmentFound) break;
00213       }// muon
00214 
00215       if (segmentFound)
00216          hSegmentIsAssociatedBool->Fill(1.);
00217       else
00218          hSegmentIsAssociatedBool->Fill(0.);
00219    }// dt segment
00220 
00221    for(CSCSegmentCollection::const_iterator segment = cscSegmentCollectionH_->begin();
00222          segment != cscSegmentCollectionH_->end(); ++segment)
00223    {
00224       LocalPoint  segmentLocalPosition       = segment->localPosition();
00225       LocalVector segmentLocalDirection      = segment->localDirection();
00226       LocalError  segmentLocalPositionError  = segment->localPositionError();
00227       LocalError  segmentLocalDirectionError = segment->localDirectionError();
00228       bool segmentFound = false;
00229 
00230       for(MuonCollection::const_iterator muon = muonCollectionH_->begin();
00231             muon != muonCollectionH_->end(); ++muon)
00232       {
00233          if (! muon->isMatchesValid())
00234             continue;
00235 
00236          for(std::vector<MuonChamberMatch>::const_iterator chamberMatch = muon->matches().begin();
00237                chamberMatch != muon->matches().end(); ++chamberMatch) {
00238             for(std::vector<MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
00239                   segmentMatch != chamberMatch->segmentMatches.end(); ++segmentMatch)
00240             {
00241                if (fabs(segmentMatch->x       - segmentLocalPosition.x()                           ) < 1E-6 &&
00242                    fabs(segmentMatch->y       - segmentLocalPosition.y()                           ) < 1E-6 &&
00243                    fabs(segmentMatch->dXdZ    - segmentLocalDirection.x()/segmentLocalDirection.z()) < 1E-6 &&
00244                    fabs(segmentMatch->dYdZ    - segmentLocalDirection.y()/segmentLocalDirection.z()) < 1E-6 &&
00245                    fabs(segmentMatch->xErr    - sqrt(segmentLocalPositionError.xx())               ) < 1E-6 &&
00246                    fabs(segmentMatch->yErr    - sqrt(segmentLocalPositionError.yy())               ) < 1E-6 &&
00247                    fabs(segmentMatch->dXdZErr - sqrt(segmentLocalDirectionError.xx())              ) < 1E-6 &&
00248                    fabs(segmentMatch->dYdZErr - sqrt(segmentLocalDirectionError.yy())              ) < 1E-6)
00249                {
00250                   segmentFound = true;
00251                   break;
00252                }
00253             }// segmentMatch
00254             if (segmentFound) break;
00255          }// chamberMatch
00256          if (segmentFound) break;
00257       }// muon
00258 
00259       if (segmentFound)
00260          hSegmentIsAssociatedBool->Fill(1.);
00261       else
00262          hSegmentIsAssociatedBool->Fill(0.);
00263    }// csc segment
00264 }
00265 
00266 void 
00267 MuonIdDQM::endJob() {}
00268 
00269 void MuonIdDQM::Fill(MonitorElement* me, float f) {
00270    if (fabs(f) > 900000) return;
00271    //if (fabs(f) < 1E-8) return;
00272    me->Fill(f);
00273 }
00274 
00275 //define this as a plug-in
00276 DEFINE_FWK_MODULE(MuonIdDQM);