CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Validation/RPCRecHits/src/RPCRecHitValid.cc

Go to the documentation of this file.
00001 #include "Validation/RPCRecHits/interface/RPCRecHitValid.h"
00002 #include "FWCore/Framework/interface/MakerMacros.h"
00003 
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00008 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00009 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00010 #include "DataFormats/TrackReco/interface/Track.h"
00011 #include "DataFormats/MuonReco/interface/Muon.h"
00012 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00013 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00014 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00015 #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
00016 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00017 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00018 #include "Geometry/RPCGeometry/interface/RPCRollSpecs.h"
00019 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00020 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
00021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00022 
00023 using namespace std;
00024 
00025 typedef MonitorElement* MEP;
00026 
00027 RPCRecHitValid::RPCRecHitValid(const edm::ParameterSet& pset)
00028 {
00029   simHitLabel_ = pset.getParameter<edm::InputTag>("simHit");
00030   recHitLabel_ = pset.getParameter<edm::InputTag>("recHit");
00031   simTrackLabel_ = pset.getParameter<edm::InputTag>("simTrack");
00032   muonLabel_ = pset.getParameter<edm::InputTag>("muon");
00033   dbe_ = edm::Service<DQMStore>().operator->();
00034   if ( !dbe_ )
00035   {
00036     edm::LogError("RPCRecHitValid") << "No DQMStore instance\n";
00037     return;
00038   }
00039 
00040   // Book MonitorElements
00041   subDir_ = pset.getParameter<std::string>("subDir");
00042   h_.bookHistograms(dbe_, subDir_);
00043 
00044   // SimHit plots, not compatible to RPCPoint-RPCRecHit comparison
00045   dbe_->setCurrentFolder(subDir_+"/HitProperty");
00046   h_simTrackPType = dbe_->book1D("SimHitPType", "SimHit particle type", 11, 0, 11);
00047   h_simTrackPType->getTH1()->SetMinimum(0);
00048   if ( TH1* h = h_simTrackPType->getTH1() )
00049   {
00050     h->GetXaxis()->SetBinLabel(1 , "#mu^{-}");
00051     h->GetXaxis()->SetBinLabel(2 , "#mu^{+}");
00052     h->GetXaxis()->SetBinLabel(3 , "e^{-}"  );
00053     h->GetXaxis()->SetBinLabel(4 , "e^{+}"  );
00054     h->GetXaxis()->SetBinLabel(5 , "#pi^{+}");
00055     h->GetXaxis()->SetBinLabel(6 , "#pi^{-}");
00056     h->GetXaxis()->SetBinLabel(7 , "K^{+}"  );
00057     h->GetXaxis()->SetBinLabel(8 , "K^{-}"  );
00058     h->GetXaxis()->SetBinLabel(9 , "p^{+}"  );
00059     h->GetXaxis()->SetBinLabel(10, "p^{-}"  );
00060     h->GetXaxis()->SetBinLabel(11, "Other"  );
00061   }
00062 
00063   dbe_->setCurrentFolder(subDir_+"/Track");
00064 
00065   h_nRPCHitPerSimMuon        = dbe_->book1D("NRPCHitPerSimMuon"       , "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
00066   h_nRPCHitPerSimMuonBarrel  = dbe_->book1D("NRPCHitPerSimMuonBarrel" , "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
00067   h_nRPCHitPerSimMuonOverlap = dbe_->book1D("NRPCHitPerSimMuonOverlap", "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
00068   h_nRPCHitPerSimMuonEndcap  = dbe_->book1D("NRPCHitPerSimMuonEndcap" , "Number of RPC SimHit per SimMuon", 11, -0.5, 10.5);
00069 
00070   h_nRPCHitPerRecoMuon        = dbe_->book1D("NRPCHitPerRecoMuon"       , "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
00071   h_nRPCHitPerRecoMuonBarrel  = dbe_->book1D("NRPCHitPerRecoMuonBarrel" , "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
00072   h_nRPCHitPerRecoMuonOverlap = dbe_->book1D("NRPCHitPerRecoMuonOverlap", "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
00073   h_nRPCHitPerRecoMuonEndcap  = dbe_->book1D("NRPCHitPerRecoMuonEndcap" , "Number of RPC RecHit per RecoMuon", 11, -0.5, 10.5);
00074 
00075   h_nRPCHitPerSimMuon        ->getTH1()->SetMinimum(0);
00076   h_nRPCHitPerSimMuonBarrel  ->getTH1()->SetMinimum(0);
00077   h_nRPCHitPerSimMuonOverlap ->getTH1()->SetMinimum(0);
00078   h_nRPCHitPerSimMuonEndcap  ->getTH1()->SetMinimum(0);
00079                              
00080   h_nRPCHitPerRecoMuon       ->getTH1()->SetMinimum(0);
00081   h_nRPCHitPerRecoMuonBarrel ->getTH1()->SetMinimum(0);
00082   h_nRPCHitPerRecoMuonOverlap->getTH1()->SetMinimum(0);
00083   h_nRPCHitPerRecoMuonEndcap ->getTH1()->SetMinimum(0);
00084 
00085   float ptBins[] = {0, 1, 2, 5, 10, 20, 30, 50, 100, 200, 300, 500};
00086   const int nPtBins = sizeof(ptBins)/sizeof(float)-1;
00087   h_simMuonBarrel_pt   = dbe_->book1D("SimMuonBarrel_pt"  , "SimMuon RPCHit in Barrel  p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00088   h_simMuonOverlap_pt  = dbe_->book1D("SimMuonOverlap_pt" , "SimMuon RPCHit in Overlap p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00089   h_simMuonEndcap_pt   = dbe_->book1D("SimMuonEndcap_pt"  , "SimMuon RPCHit in Endcap  p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00090   h_simMuonNoRPC_pt    = dbe_->book1D("SimMuonNoRPC_pt" , "SimMuon without RPCHit p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00091   h_simMuonBarrel_eta  = dbe_->book1D("SimMuonBarrel_eta" , "SimMuon RPCHit in Barrel  #eta;#eta", 50, -2.5, 2.5);
00092   h_simMuonOverlap_eta = dbe_->book1D("SimMuonOverlap_eta", "SimMuon RPCHit in Overlap #eta;#eta", 50, -2.5, 2.5);
00093   h_simMuonEndcap_eta  = dbe_->book1D("SimMuonEndcap_eta" , "SimMuon RPCHit in Endcap  #eta;#eta", 50, -2.5, 2.5);
00094   h_simMuonNoRPC_eta   = dbe_->book1D("SimMuonNoRPC_eta", "SimMuon without RPCHit #eta;#eta", 50, -2.5, 2.5);
00095   h_simMuonBarrel_phi  = dbe_->book1D("SimMuonBarrel_phi" , "SimMuon RPCHit in Barrel  #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00096   h_simMuonOverlap_phi = dbe_->book1D("SimMuonOverlap_phi", "SimMuon RPCHit in Overlap #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00097   h_simMuonEndcap_phi  = dbe_->book1D("SimMuonEndcap_phi" , "SimMuon RPCHit in Endcap  #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00098   h_simMuonNoRPC_phi   = dbe_->book1D("SimMuonNoRPC_phi", "SimMuon without RPCHit #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00099 
00100   h_recoMuonBarrel_pt   = dbe_->book1D("RecoMuonBarrel_pt"  , "RecoMuon RPCHit in Barrel  p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00101   h_recoMuonOverlap_pt  = dbe_->book1D("RecoMuonOverlap_pt" , "RecoMuon RPCHit in Overlap p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00102   h_recoMuonEndcap_pt   = dbe_->book1D("RecoMuonEndcap_pt"  , "RecoMuon RPCHit in Endcap  p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00103   h_recoMuonNoRPC_pt    = dbe_->book1D("RecoMuonNoRPC_pt" , "RecoMuon without RPCHit p_{T};p_{T} [GeV/c^{2}]", nPtBins, ptBins);
00104   h_recoMuonBarrel_eta  = dbe_->book1D("RecoMuonBarrel_eta" , "RecoMuon RPCHit in Barrel  #eta;#eta", 50, -2.5, 2.5);
00105   h_recoMuonOverlap_eta = dbe_->book1D("RecoMuonOverlap_eta", "RecoMuon RPCHit in Overlap #eta;#eta", 50, -2.5, 2.5);
00106   h_recoMuonEndcap_eta  = dbe_->book1D("RecoMuonEndcap_eta" , "RecoMuon RPCHit in Endcap  #eta;#eta", 50, -2.5, 2.5);
00107   h_recoMuonNoRPC_eta   = dbe_->book1D("RecoMuonNoRPC_eta", "RecoMuon without RPCHit #eta;#eta", 50, -2.5, 2.5);
00108   h_recoMuonBarrel_phi  = dbe_->book1D("RecoMuonBarrel_phi" , "RecoMuon RPCHit in Barrel  #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00109   h_recoMuonOverlap_phi = dbe_->book1D("RecoMuonOverlap_phi", "RecoMuon RPCHit in Overlap #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00110   h_recoMuonEndcap_phi  = dbe_->book1D("RecoMuonEndcap_phi" , "RecoMuon RPCHit in Endcap  #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00111   h_recoMuonNoRPC_phi   = dbe_->book1D("RecoMuonNoRPC_phi", "RecoMuon without RPCHit #phi;#phi", 36, -TMath::Pi(), TMath::Pi());
00112 
00113   h_simMuonBarrel_pt   ->getTH1()->SetMinimum(0);
00114   h_simMuonOverlap_pt  ->getTH1()->SetMinimum(0);
00115   h_simMuonEndcap_pt   ->getTH1()->SetMinimum(0);
00116   h_simMuonNoRPC_pt    ->getTH1()->SetMinimum(0);
00117   h_simMuonBarrel_eta  ->getTH1()->SetMinimum(0);
00118   h_simMuonOverlap_eta ->getTH1()->SetMinimum(0);
00119   h_simMuonEndcap_eta  ->getTH1()->SetMinimum(0);
00120   h_simMuonNoRPC_eta   ->getTH1()->SetMinimum(0);
00121   h_simMuonBarrel_phi  ->getTH1()->SetMinimum(0);
00122   h_simMuonOverlap_phi ->getTH1()->SetMinimum(0);
00123   h_simMuonEndcap_phi  ->getTH1()->SetMinimum(0);
00124   h_simMuonNoRPC_phi   ->getTH1()->SetMinimum(0);
00125                        
00126   h_recoMuonBarrel_pt  ->getTH1()->SetMinimum(0);
00127   h_recoMuonOverlap_pt ->getTH1()->SetMinimum(0);
00128   h_recoMuonEndcap_pt  ->getTH1()->SetMinimum(0);
00129   h_recoMuonNoRPC_pt   ->getTH1()->SetMinimum(0);
00130   h_recoMuonBarrel_eta ->getTH1()->SetMinimum(0);
00131   h_recoMuonOverlap_eta->getTH1()->SetMinimum(0);
00132   h_recoMuonEndcap_eta ->getTH1()->SetMinimum(0);
00133   h_recoMuonNoRPC_eta  ->getTH1()->SetMinimum(0);
00134   h_recoMuonBarrel_phi ->getTH1()->SetMinimum(0);
00135   h_recoMuonOverlap_phi->getTH1()->SetMinimum(0);
00136   h_recoMuonEndcap_phi ->getTH1()->SetMinimum(0);
00137   h_recoMuonNoRPC_phi  ->getTH1()->SetMinimum(0);
00138 
00139   dbe_->setCurrentFolder(subDir_+"/Occupancy");
00140 
00141   h_eventCount = dbe_->book1D("EventCount", "Event count", 3, 1, 4);
00142   h_eventCount->getTH1()->SetMinimum(0);
00143   if ( h_eventCount )
00144   {
00145     TH1* h = h_eventCount->getTH1();
00146     h->GetXaxis()->SetBinLabel(1, "eventBegin");
00147     h->GetXaxis()->SetBinLabel(2, "eventEnd");
00148     h->GetXaxis()->SetBinLabel(3, "run");
00149   }
00150 
00151   h_refPunchOccupancyBarrel_wheel   = dbe_->book1D("RefPunchOccupancyBarrel_wheel"  , "RefPunchthrough occupancy", 5, -2.5, 2.5);
00152   h_refPunchOccupancyEndcap_disk    = dbe_->book1D("RefPunchOccupancyEndcap_disk"   , "RefPunchthrough occupancy", 9, -4.5, 4.5);
00153   h_refPunchOccupancyBarrel_station = dbe_->book1D("RefPunchOccupancyBarrel_station", "RefPunchthrough occupancy", 4,  0.5, 4.5);
00154   h_recPunchOccupancyBarrel_wheel   = dbe_->book1D("RecPunchOccupancyBarrel_wheel"  , "Punchthrough recHit occupancy", 5, -2.5, 2.5);
00155   h_recPunchOccupancyEndcap_disk    = dbe_->book1D("RecPunchOccupancyEndcap_disk"   , "Punchthrough recHit occupancy", 9, -4.5, 4.5);
00156   h_recPunchOccupancyBarrel_station = dbe_->book1D("RecPunchOccupancyBarrel_station", "Punchthrough recHit occupancy", 4,  0.5, 4.5);
00157 
00158   h_refPunchOccupancyBarrel_wheel   ->getTH1()->SetMinimum(0);
00159   h_refPunchOccupancyEndcap_disk    ->getTH1()->SetMinimum(0);
00160   h_refPunchOccupancyBarrel_station ->getTH1()->SetMinimum(0);
00161   h_recPunchOccupancyBarrel_wheel   ->getTH1()->SetMinimum(0);
00162   h_recPunchOccupancyEndcap_disk    ->getTH1()->SetMinimum(0);
00163   h_recPunchOccupancyBarrel_station ->getTH1()->SetMinimum(0);
00164 
00165   h_refPunchOccupancyBarrel_wheel_station = dbe_->book2D("RefPunchOccupancyBarrel_wheel_station", "RefPunchthrough occupancy", 5, -2.5, 2.5, 4, 0.5, 4.5);
00166   h_refPunchOccupancyEndcap_disk_ring     = dbe_->book2D("RefPunchOccupancyEndcap_disk_ring"    , "RefPunchthrough occupancy", 9, -4.5, 4.5, 4, 0.5, 4.5);
00167   h_recPunchOccupancyBarrel_wheel_station = dbe_->book2D("RecPunchOccupancyBarrel_wheel_station", "Punchthrough recHit occupancy", 5, -2.5, 2.5, 4, 0.5, 4.5);
00168   h_recPunchOccupancyEndcap_disk_ring     = dbe_->book2D("RecPunchOccupancyEndcap_disk_ring"    , "Punchthrough recHit occupancy", 9, -4.5, 4.5, 4, 0.5, 4.5);
00169 
00170   h_refPunchOccupancyBarrel_wheel_station->getTH2F()->SetOption("COLZ");
00171   h_refPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetOption("COLZ");
00172   h_recPunchOccupancyBarrel_wheel_station->getTH2F()->SetOption("COLZ");
00173   h_recPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetOption("COLZ");
00174 
00175   h_refPunchOccupancyBarrel_wheel_station->getTH2F()->SetContour(10);
00176   h_refPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetContour(10);
00177   h_recPunchOccupancyBarrel_wheel_station->getTH2F()->SetContour(10);
00178   h_recPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetContour(10);
00179 
00180   h_refPunchOccupancyBarrel_wheel_station->getTH2F()->SetStats(0);
00181   h_refPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetStats(0);
00182   h_recPunchOccupancyBarrel_wheel_station->getTH2F()->SetStats(0);
00183   h_recPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetStats(0);
00184 
00185   h_refPunchOccupancyBarrel_wheel_station->getTH2F()->SetMinimum(0);
00186   h_refPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetMinimum(0);
00187   h_recPunchOccupancyBarrel_wheel_station->getTH2F()->SetMinimum(0);
00188   h_recPunchOccupancyEndcap_disk_ring    ->getTH2F()->SetMinimum(0);
00189 
00190   for ( int i=1; i<=5; ++i )
00191   {
00192     TString binLabel = Form("Wheel %d", i-3);
00193     h_refPunchOccupancyBarrel_wheel->getTH1()->GetXaxis()->SetBinLabel(i, binLabel);
00194     h_refPunchOccupancyBarrel_wheel_station->getTH2F()->GetXaxis()->SetBinLabel(i, binLabel);
00195     h_recPunchOccupancyBarrel_wheel->getTH1()->GetXaxis()->SetBinLabel(i, binLabel);
00196     h_recPunchOccupancyBarrel_wheel_station->getTH2F()->GetXaxis()->SetBinLabel(i, binLabel);
00197   }
00198 
00199   for ( int i=1; i<=9; ++i )
00200   {
00201     TString binLabel = Form("Disk %d", i-5);
00202     h_refPunchOccupancyEndcap_disk  ->getTH1()->GetXaxis()->SetBinLabel(i, binLabel);
00203     h_refPunchOccupancyEndcap_disk_ring  ->getTH2F()->GetXaxis()->SetBinLabel(i, binLabel);
00204     h_recPunchOccupancyEndcap_disk  ->getTH1()->GetXaxis()->SetBinLabel(i, binLabel);
00205     h_recPunchOccupancyEndcap_disk_ring  ->getTH2F()->GetXaxis()->SetBinLabel(i, binLabel);
00206   }
00207 
00208   for ( int i=1; i<=4; ++i )
00209   {
00210     TString binLabel = Form("Station %d", i);
00211     h_refPunchOccupancyBarrel_station  ->getTH1()->GetXaxis()->SetBinLabel(i, binLabel);
00212     h_refPunchOccupancyBarrel_wheel_station  ->getTH2F()->GetYaxis()->SetBinLabel(i, binLabel);
00213     h_recPunchOccupancyBarrel_station  ->getTH1()->GetXaxis()->SetBinLabel(i, binLabel);
00214     h_recPunchOccupancyBarrel_wheel_station  ->getTH2F()->GetYaxis()->SetBinLabel(i, binLabel);
00215   }
00216 
00217   for ( int i=1; i<=4; ++i )
00218   {
00219     TString binLabel = Form("Ring %d", i);
00220     h_refPunchOccupancyEndcap_disk_ring  ->getTH2F()->GetYaxis()->SetBinLabel(i, binLabel);
00221     h_recPunchOccupancyEndcap_disk_ring  ->getTH2F()->GetYaxis()->SetBinLabel(i, binLabel);
00222   }
00223 }
00224 
00225 RPCRecHitValid::~RPCRecHitValid()
00226 {
00227 }
00228 
00229 void RPCRecHitValid::beginJob()
00230 {
00231 }
00232 
00233 void RPCRecHitValid::endJob()
00234 {
00235 }
00236 
00237 void RPCRecHitValid::beginRun(const edm::Run& run, const edm::EventSetup& eventSetup)
00238 {
00239   if ( !dbe_ ) return;
00240   h_eventCount->Fill(3);
00241 
00242   // Book roll-by-roll histograms
00243   edm::ESHandle<RPCGeometry> rpcGeom;
00244   eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
00245 
00246   int nRPCRollBarrel = 0, nRPCRollEndcap = 0;
00247 
00248   TrackingGeometry::DetContainer rpcDets = rpcGeom->dets();
00249   for ( TrackingGeometry::DetContainer::const_iterator detIter = rpcDets.begin();
00250         detIter != rpcDets.end(); ++detIter )
00251   {
00252     RPCChamber* rpcCh = dynamic_cast<RPCChamber*>(*detIter);
00253     if ( !rpcCh ) continue;
00254 
00255     std::vector<const RPCRoll*> rolls = rpcCh->rolls();
00256     for ( std::vector<const RPCRoll*>::const_iterator rollIter = rolls.begin();
00257           rollIter != rolls.end(); ++rollIter )
00258     {
00259       const RPCRoll* roll = *rollIter;
00260       if ( !roll ) continue;
00261 
00262       //RPCGeomServ rpcSrv(roll->id());
00263       const int rawId = roll->geographicalId().rawId();
00264       //if ( !roll->specs()->isRPC() ) { cout << "\nNoRPC : " << rpcSrv.name() << ' ' << rawId << endl; continue; }
00265 
00266       if ( roll->isBarrel() )
00267       {
00268         detIdToIndexMapBarrel_[rawId] = nRPCRollBarrel;
00269         //rollIdToNameMapBarrel_[rawId] = rpcSrv.name();
00270         ++nRPCRollBarrel;
00271       }
00272       else
00273       {
00274         detIdToIndexMapEndcap_[rawId] = nRPCRollEndcap;
00275         //rollIdToNameMapEndcap_[rawId] = rpcSrv.name();
00276         ++nRPCRollEndcap;
00277       }
00278     }
00279   }
00280 
00281   dbe_->setCurrentFolder(subDir_+"/Occupancy");
00282   h_matchOccupancyBarrel_detId = dbe_->book1D("MatchOccupancyBarrel_detId", "Matched hit occupancy;roll index (can be arbitrary)", nRPCRollBarrel, 0, nRPCRollBarrel);
00283   h_matchOccupancyEndcap_detId = dbe_->book1D("MatchOccupancyEndcap_detId", "Matched hit occupancy;roll index (can be arbitrary)", nRPCRollEndcap, 0, nRPCRollEndcap);
00284   h_refOccupancyBarrel_detId = dbe_->book1D("RefOccupancyBarrel_detId", "Reference hit occupancy;roll index (can be arbitrary)", nRPCRollBarrel, 0, nRPCRollBarrel);
00285   h_refOccupancyEndcap_detId = dbe_->book1D("RefOccupancyEndcap_detId", "Reference hit occupancy;roll index (can be arbitrary)", nRPCRollEndcap, 0, nRPCRollEndcap);
00286   h_noiseOccupancyBarrel_detId = dbe_->book1D("NoiseOccupancyBarrel_detId", "Noise occupancy;roll index (can be arbitrary)", nRPCRollBarrel, 0, nRPCRollBarrel);
00287   h_noiseOccupancyEndcap_detId = dbe_->book1D("NoiseOccupancyEndcap_detId", "Noise occupancy;roll index (can be arbitrary)", nRPCRollEndcap, 0, nRPCRollEndcap);
00288 
00289   h_matchOccupancyBarrel_detId->getTH1()->SetMinimum(0);
00290   h_matchOccupancyEndcap_detId->getTH1()->SetMinimum(0);
00291   h_refOccupancyBarrel_detId  ->getTH1()->SetMinimum(0);
00292   h_refOccupancyEndcap_detId  ->getTH1()->SetMinimum(0);
00293   h_noiseOccupancyBarrel_detId->getTH1()->SetMinimum(0);
00294   h_noiseOccupancyEndcap_detId->getTH1()->SetMinimum(0);
00295 
00296   h_rollAreaBarrel_detId = dbe_->bookProfile("RollAreaBarrel_detId", "Roll area;roll index;Area", nRPCRollBarrel, 0., 1.*nRPCRollBarrel, 0., 1e5);
00297   h_rollAreaEndcap_detId = dbe_->bookProfile("RollAreaEndcap_detId", "Roll area;roll index;Area", nRPCRollEndcap, 0., 1.*nRPCRollEndcap, 0., 1e5);
00298 
00299   for ( map<int, int>::const_iterator iter = detIdToIndexMapBarrel_.begin();
00300         iter != detIdToIndexMapBarrel_.end(); ++iter )
00301   {
00302     const int rawId = iter->first;
00303     const int index = iter->second;
00304 
00305     const RPCDetId rpcDetId = static_cast<const RPCDetId>(rawId);
00306     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(rpcDetId));
00307 
00308     //RPCGeomServ rpcSrv(roll->id());
00309     //if ( !roll->specs()->isRPC() ) { cout << "\nNoRPC : " << rpcSrv.name() << ' ' << rawId << endl; continue; }
00310 
00311     const StripTopology& topol = roll->specificTopology();
00312     const double area = topol.stripLength()*topol.nstrips()*topol.pitch();
00313 
00314     h_rollAreaBarrel_detId->Fill(index, area);
00315   }
00316 
00317   for ( map<int, int>::const_iterator iter = detIdToIndexMapEndcap_.begin();
00318         iter != detIdToIndexMapEndcap_.end(); ++iter )
00319   {
00320     const int rawId = iter->first;
00321     const int index = iter->second;
00322 
00323     const RPCDetId rpcDetId = static_cast<const RPCDetId>(rawId);
00324     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(rpcDetId));
00325 
00326     //RPCGeomServ rpcSrv(roll->id());
00327     //if ( !roll->specs()->isRPC() ) { cout << "\nNoRPC : " << rpcSrv.name() << ' ' << rawId << endl; continue; }
00328 
00329     const StripTopology& topol = roll->specificTopology();
00330     const double area = topol.stripLength()*topol.nstrips()*topol.pitch();
00331 
00332     h_rollAreaEndcap_detId->Fill(index, area);
00333   }
00334 }
00335 
00336 void RPCRecHitValid::endRun(const edm::Run& run, const edm::EventSetup& eventSetup)
00337 {
00338   if ( !dbe_ ) return;
00339 
00340 }
00341 
00342 void RPCRecHitValid::analyze(const edm::Event& event, const edm::EventSetup& eventSetup)
00343 {
00344   if ( !dbe_ ) return;
00345   h_eventCount->Fill(1);
00346 
00347   // Get the RPC Geometry
00348   edm::ESHandle<RPCGeometry> rpcGeom;
00349   eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
00350 
00351   // Retrieve SimHits from the event
00352   edm::Handle<edm::PSimHitContainer> simHitHandle;
00353   if ( !event.getByLabel(simHitLabel_, simHitHandle) )
00354   {
00355     edm::LogInfo("RPCRecHitValid") << "Cannot find simHit collection\n";
00356     return;
00357   }
00358 
00359   // Retrieve RecHits from the event
00360   edm::Handle<RPCRecHitCollection> recHitHandle;
00361   if ( !event.getByLabel(recHitLabel_, recHitHandle) )
00362   {
00363     edm::LogInfo("RPCRecHitValid") << "Cannot find recHit collection\n";
00364     return;
00365   }
00366 
00367   // Get SimTracks
00368   edm::Handle<edm::View<TrackingParticle> > simTrackHandle;
00369   if ( !event.getByLabel(simTrackLabel_, simTrackHandle) )
00370   {
00371     edm::LogInfo("RPCRecHitValid") << "Cannot find simTrack collection\n";
00372     return;
00373   }
00374 
00375   // Get RecoMuons
00376   edm::Handle<edm::View<reco::Muon> > muonHandle;
00377   if ( !event.getByLabel(muonLabel_, muonHandle) )
00378   {
00379     edm::LogInfo("RPCRecHitValid") << "Cannot find muon collection\n";
00380     return;
00381   }
00382 
00383   typedef edm::PSimHitContainer::const_iterator SimHitIter;
00384   typedef RPCRecHitCollection::const_iterator RecHitIter;
00385 
00386   std::vector<const PSimHit*> muonSimHits;
00387   std::vector<const PSimHit*> pthrSimHits;
00388   for ( edm::View<TrackingParticle>::const_iterator simTrack = simTrackHandle->begin();
00389         simTrack != simTrackHandle->end(); ++simTrack )
00390   {
00391     if ( simTrack->pt() < 1.0 or simTrack->p() < 2.5 ) continue; // globalMuon acceptance
00392 
00393     bool hasRPCHit = false;
00394     if ( abs(simTrack->pdgId()) == 13 )
00395     {
00396       int nRPCHitBarrel = 0;
00397       int nRPCHitEndcap = 0;
00398 
00399       for ( SimHitIter simHit = simTrack->pSimHit_begin();
00400             simHit != simTrack->pSimHit_end(); ++simHit )
00401       {
00402         const DetId detId(simHit->detUnitId());
00403         if ( detId.det() != DetId::Muon or detId.subdetId() != MuonSubdetId::RPC ) continue;
00404         const RPCDetId rpcDetId = static_cast<const RPCDetId>(simHit->detUnitId());
00405         const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(rpcDetId));
00406         if ( !roll ) continue;
00407 
00408         if ( rpcDetId.region() == 0 ) ++nRPCHitBarrel;
00409         else ++nRPCHitEndcap;
00410 
00411         muonSimHits.push_back(&*simHit);
00412       }
00413 
00414       const int nRPCHit = nRPCHitBarrel+nRPCHitEndcap;
00415       hasRPCHit = nRPCHit > 0;
00416       h_nRPCHitPerSimMuon->Fill(nRPCHit);
00417       if ( nRPCHitBarrel and nRPCHitEndcap )
00418       {
00419         h_nRPCHitPerSimMuonOverlap->Fill(nRPCHit);
00420         h_simMuonOverlap_pt->Fill(simTrack->pt());
00421         h_simMuonOverlap_eta->Fill(simTrack->eta());
00422         h_simMuonOverlap_phi->Fill(simTrack->phi());
00423       }
00424       else if ( nRPCHitBarrel )
00425       {
00426         h_nRPCHitPerSimMuonBarrel->Fill(nRPCHit);
00427         h_simMuonBarrel_pt->Fill(simTrack->pt());
00428         h_simMuonBarrel_eta->Fill(simTrack->eta());
00429         h_simMuonBarrel_phi->Fill(simTrack->phi());
00430       }
00431       else if ( nRPCHitEndcap )
00432       {
00433         h_nRPCHitPerSimMuonEndcap->Fill(nRPCHit);
00434         h_simMuonEndcap_pt->Fill(simTrack->pt());
00435         h_simMuonEndcap_eta->Fill(simTrack->eta());
00436         h_simMuonEndcap_phi->Fill(simTrack->phi());
00437       }
00438       else
00439       {
00440         h_simMuonNoRPC_pt->Fill(simTrack->pt());
00441         h_simMuonNoRPC_eta->Fill(simTrack->eta());
00442         h_simMuonNoRPC_phi->Fill(simTrack->phi());
00443       }
00444     }
00445     else
00446     {
00447       int nRPCHit = 0;
00448       for ( SimHitIter simHit = simTrack->pSimHit_begin();
00449             simHit != simTrack->pSimHit_end(); ++simHit )
00450       {
00451         const DetId detId(simHit->detUnitId());
00452         if ( detId.det() != DetId::Muon or detId.subdetId() != MuonSubdetId::RPC ) continue;
00453         const RPCDetId rpcDetId = static_cast<const RPCDetId>(simHit->detUnitId());
00454         const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(rpcDetId()));
00455         if ( !roll ) continue;
00456 
00457         ++nRPCHit;
00458         pthrSimHits.push_back(&*simHit);
00459       }
00460       hasRPCHit = nRPCHit > 0;
00461     }
00462 
00463     if ( hasRPCHit )
00464     {
00465       switch ( simTrack->pdgId() )
00466       {
00467         case    13: h_simTrackPType->Fill( 0); break;
00468         case   -13: h_simTrackPType->Fill( 1); break;
00469         case    11: h_simTrackPType->Fill( 2); break;
00470         case   -11: h_simTrackPType->Fill( 3); break;
00471         case   211: h_simTrackPType->Fill( 4); break;
00472         case  -211: h_simTrackPType->Fill( 5); break;
00473         case   321: h_simTrackPType->Fill( 6); break;
00474         case  -321: h_simTrackPType->Fill( 7); break;
00475         case  2212: h_simTrackPType->Fill( 8); break;
00476         case -2212: h_simTrackPType->Fill( 9); break;
00477         default:    h_simTrackPType->Fill(10); break;
00478       }
00479     }
00480   }
00481 
00482   // Loop over muon simHits, fill histograms which does not need associations
00483   int nRefHitBarrel = 0, nRefHitEndcap = 0;
00484   for ( std::vector<const PSimHit*>::const_iterator simHitP = muonSimHits.begin();
00485         simHitP != muonSimHits.end(); ++simHitP )
00486   {
00487     const PSimHit* simHit = *simHitP;
00488     const RPCDetId detId = static_cast<const RPCDetId>(simHit->detUnitId());
00489     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00490 
00491     const int region = roll->id().region();
00492     const int ring = roll->id().ring();
00493     //const int sector = roll->id().sector();
00494     const int station = roll->id().station();
00495     //const int layer = roll->id().layer();
00496     //const int subSector = roll->id().subsector();
00497 
00498     if ( region == 0 )
00499     {
00500       ++nRefHitBarrel;
00501       h_.refHitOccupancyBarrel_wheel->Fill(ring);
00502       h_.refHitOccupancyBarrel_station->Fill(station);
00503       h_.refHitOccupancyBarrel_wheel_station->Fill(ring, station);
00504 
00505       h_refOccupancyBarrel_detId->Fill(detIdToIndexMapBarrel_[simHit->detUnitId()]);
00506     }
00507     else
00508     {
00509       ++nRefHitEndcap;
00510       h_.refHitOccupancyEndcap_disk->Fill(region*station);
00511       h_.refHitOccupancyEndcap_disk_ring->Fill(region*station, ring);
00512 
00513       h_refOccupancyEndcap_detId->Fill(detIdToIndexMapEndcap_[simHit->detUnitId()]);
00514     }
00515   }
00516 
00517   // Loop over punch-through simHits, fill histograms which does not need associations
00518   for ( std::vector<const PSimHit*>::const_iterator simHitP = pthrSimHits.begin();
00519         simHitP != pthrSimHits.end(); ++simHitP )
00520   {
00521     const PSimHit* simHit = *simHitP;
00522     const RPCDetId detId = static_cast<const RPCDetId>(simHit->detUnitId());
00523     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
00524 
00525     const int region = roll->id().region();
00526     const int ring = roll->id().ring();
00527     //const int sector = roll->id().sector();
00528     const int station = roll->id().station();
00529     //const int layer = roll->id().layer();
00530     //const int subSector = roll->id().subsector();
00531 
00532     if ( region == 0 )
00533     {
00534       ++nRefHitBarrel;
00535       h_refPunchOccupancyBarrel_wheel->Fill(ring);
00536       h_refPunchOccupancyBarrel_station->Fill(station);
00537       h_refPunchOccupancyBarrel_wheel_station->Fill(ring, station);
00538 
00539       h_refOccupancyBarrel_detId->Fill(detIdToIndexMapBarrel_[simHit->detUnitId()]);
00540     }
00541     else
00542     {
00543       ++nRefHitEndcap;
00544       h_refPunchOccupancyEndcap_disk->Fill(region*station);
00545       h_refPunchOccupancyEndcap_disk_ring->Fill(region*station, ring);
00546 
00547       h_refOccupancyEndcap_detId->Fill(detIdToIndexMapEndcap_[simHit->detUnitId()]);
00548     }
00549   }
00550   h_.nRefHitBarrel->Fill(nRefHitBarrel);
00551   h_.nRefHitEndcap->Fill(nRefHitEndcap);
00552 
00553   // Loop over recHits, fill histograms which does not need associations
00554   int sumClusterSizeBarrel = 0, sumClusterSizeEndcap = 0;
00555   int nRecHitBarrel = 0, nRecHitEndcap = 0;
00556   for ( RecHitIter recHitIter = recHitHandle->begin();
00557         recHitIter != recHitHandle->end(); ++recHitIter )
00558   {
00559     const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
00560     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
00561     if ( !roll ) continue;
00562 
00563     const int region = roll->id().region();
00564     const int ring = roll->id().ring();
00565     //const int sector = roll->id().sector();
00566     const int station = roll->id().station();
00567     //const int layer = roll->id().layer();
00568     //const int subSector = roll->id().subsector();
00569 
00570     h_.clusterSize->Fill(recHitIter->clusterSize());
00571 
00572     if ( region == 0 )
00573     {
00574       ++nRecHitBarrel;
00575       sumClusterSizeBarrel += recHitIter->clusterSize();
00576       h_.clusterSizeBarrel->Fill(recHitIter->clusterSize());
00577       h_.recHitOccupancyBarrel_wheel->Fill(ring);
00578       h_.recHitOccupancyBarrel_station->Fill(station);
00579       h_.recHitOccupancyBarrel_wheel_station->Fill(ring, station);
00580     }
00581     else
00582     {
00583       ++nRecHitEndcap;
00584       sumClusterSizeEndcap += recHitIter->clusterSize();
00585       h_.clusterSizeEndcap->Fill(recHitIter->clusterSize());
00586       h_.recHitOccupancyEndcap_disk->Fill(region*station);
00587       h_.recHitOccupancyEndcap_disk_ring->Fill(region*station, ring);
00588     }
00589 
00590   }
00591   const double nRecHit = nRecHitBarrel+nRecHitEndcap;
00592   h_.nRecHitBarrel->Fill(nRecHitBarrel);
00593   h_.nRecHitEndcap->Fill(nRecHitEndcap);
00594   if ( nRecHit > 0 )
00595   {
00596     const int sumClusterSize = sumClusterSizeBarrel+sumClusterSizeEndcap;
00597     h_.avgClusterSize->Fill(double(sumClusterSize)/nRecHit);
00598 
00599     if ( nRecHitBarrel > 0 )
00600     {
00601       h_.avgClusterSizeBarrel->Fill(double(sumClusterSizeBarrel)/nRecHitBarrel);
00602     }
00603     if ( nRecHitEndcap > 0 )
00604     {
00605       h_.avgClusterSizeEndcap->Fill(double(sumClusterSizeEndcap)/nRecHitEndcap);
00606     }
00607   }
00608 
00609   // Start matching SimHits to RecHits
00610   typedef std::map<const PSimHit*, RecHitIter> SimToRecHitMap;
00611   SimToRecHitMap simToRecHitMap;
00612 
00613   for ( std::vector<const PSimHit*>::const_iterator simHitP = muonSimHits.begin();
00614         simHitP != muonSimHits.end(); ++simHitP )
00615   {
00616     const PSimHit* simHit = *simHitP;
00617     const RPCDetId simDetId = static_cast<const RPCDetId>(simHit->detUnitId());
00618     //const RPCRoll* simRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(simDetId));
00619 
00620     const double simX = simHit->localPosition().x();
00621 
00622     for ( RecHitIter recHitIter = recHitHandle->begin();
00623           recHitIter != recHitHandle->end(); ++recHitIter )
00624     {
00625       const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
00626       const RPCRoll* recRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(recDetId));
00627       if ( !recRoll ) continue;
00628 
00629       if ( simDetId != recDetId ) continue;
00630 
00631       const double recX = recHitIter->localPosition().x();
00632       const double newDx = fabs(recX - simX);
00633 
00634       // Associate SimHit to RecHit
00635       SimToRecHitMap::const_iterator prevSimToReco = simToRecHitMap.find(simHit);
00636       if ( prevSimToReco == simToRecHitMap.end() )
00637       {
00638         simToRecHitMap.insert(std::make_pair(simHit, recHitIter));
00639       }
00640       else
00641       {
00642         const double oldDx = fabs(prevSimToReco->second->localPosition().x() - simX);
00643 
00644         if ( newDx < oldDx )
00645         {
00646           simToRecHitMap[simHit] = recHitIter;
00647         }
00648       }
00649     }
00650   }
00651 
00652   // Now we have simHit-recHit mapping
00653   // So we can fill up relavant histograms
00654   int nMatchHitBarrel = 0, nMatchHitEndcap = 0;
00655   for ( SimToRecHitMap::const_iterator match = simToRecHitMap.begin();
00656         match != simToRecHitMap.end(); ++match )
00657   {
00658     const PSimHit* simHit = match->first;
00659     RecHitIter recHitIter = match->second;
00660 
00661     const RPCDetId detId = static_cast<const RPCDetId>(simHit->detUnitId());
00662     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00663 
00664     const int region = roll->id().region();
00665     const int ring = roll->id().ring();
00666     //const int sector = roll->id().sector();
00667     const int station = roll->id().station();
00668     //const int layer = roll->id().layer();
00669     //const int subsector = roll->id().subsector();
00670 
00671     const double simX = simHit->localPosition().x();
00672     const double recX = recHitIter->localPosition().x();
00673     const double errX = sqrt(recHitIter->localPositionError().xx());
00674     const double dX = recX - simX;
00675     const double pull = errX == 0 ? -999 : dX/errX;
00676 
00677     //const GlobalPoint simPos = roll->toGlobal(simHitIter->localPosition());
00678     //const GlobalPoint recPos = roll->toGlobal(recHitIter->localPosition());
00679 
00680     if ( region == 0 )
00681     {
00682       ++nMatchHitBarrel;
00683       h_.resBarrel->Fill(dX);
00684       h_.pullBarrel->Fill(pull);
00685       h_.matchOccupancyBarrel_wheel->Fill(ring);
00686       h_.matchOccupancyBarrel_station->Fill(station);
00687       h_.matchOccupancyBarrel_wheel_station->Fill(ring, station);
00688 
00689       h_.res_wheel_res->Fill(ring, dX);
00690       h_.res_station_res->Fill(station, dX);
00691       h_.pull_wheel_pull->Fill(ring, pull);
00692       h_.pull_station_pull->Fill(station, pull);
00693 
00694       h_matchOccupancyBarrel_detId->Fill(detIdToIndexMapBarrel_[detId.rawId()]);
00695     }
00696     else
00697     {
00698       ++nMatchHitEndcap;
00699       h_.resEndcap->Fill(dX);
00700       h_.pullEndcap->Fill(pull);
00701       h_.matchOccupancyEndcap_disk->Fill(region*station);
00702       h_.matchOccupancyEndcap_disk_ring->Fill(region*station, ring);
00703 
00704       h_.res_disk_res->Fill(region*station, dX);
00705       h_.res_ring_res->Fill(ring, dX);
00706       h_.pull_disk_pull->Fill(region*station, pull);
00707       h_.pull_ring_pull->Fill(ring, pull);
00708 
00709       h_matchOccupancyEndcap_detId->Fill(detIdToIndexMapEndcap_[detId.rawId()]);
00710     }
00711 
00712   }
00713   h_.nMatchHitBarrel->Fill(nMatchHitBarrel);
00714   h_.nMatchHitEndcap->Fill(nMatchHitEndcap);
00715 
00716   // Reco Muon hits
00717   for ( edm::View<reco::Muon>::const_iterator muon = muonHandle->begin();
00718         muon != muonHandle->end(); ++muon )
00719   {
00720     if ( !muon->isGlobalMuon() ) continue;
00721 
00722     int nRPCHitBarrel = 0;
00723     int nRPCHitEndcap = 0;
00724 
00725     const reco::TrackRef glbTrack = muon->globalTrack();
00726     for ( trackingRecHit_iterator recHit = glbTrack->recHitsBegin();
00727           recHit != glbTrack->recHitsEnd(); ++recHit )
00728     {
00729       if ( !(*recHit)->isValid() ) continue;
00730       const DetId detId = (*recHit)->geographicalId();
00731       if ( detId.det() != DetId::Muon or detId.subdetId() != MuonSubdetId::RPC ) continue;
00732       const RPCDetId rpcDetId = static_cast<const RPCDetId>(detId);
00733 
00734       if ( rpcDetId.region() == 0 ) ++nRPCHitBarrel;
00735       else ++nRPCHitEndcap;
00736     }
00737 
00738     const int nRPCHit = nRPCHitBarrel + nRPCHitEndcap;
00739     h_nRPCHitPerRecoMuon->Fill(nRPCHit);
00740     if ( nRPCHitBarrel and nRPCHitEndcap )
00741     {
00742       h_nRPCHitPerRecoMuonOverlap->Fill(nRPCHit);
00743       h_recoMuonOverlap_pt->Fill(muon->pt());
00744       h_recoMuonOverlap_eta->Fill(muon->eta());
00745       h_recoMuonOverlap_phi->Fill(muon->phi());
00746     }
00747     else if ( nRPCHitBarrel )
00748     {
00749       h_nRPCHitPerRecoMuonBarrel->Fill(nRPCHit);
00750       h_recoMuonBarrel_pt->Fill(muon->pt());
00751       h_recoMuonBarrel_eta->Fill(muon->eta());
00752       h_recoMuonBarrel_phi->Fill(muon->phi());
00753     }
00754     else if ( nRPCHitEndcap )
00755     {
00756       h_nRPCHitPerRecoMuonEndcap->Fill(nRPCHit);
00757       h_recoMuonEndcap_pt->Fill(muon->pt());
00758       h_recoMuonEndcap_eta->Fill(muon->eta());
00759       h_recoMuonEndcap_phi->Fill(muon->phi());
00760     }
00761     else
00762     {
00763       h_recoMuonNoRPC_pt->Fill(muon->pt());
00764       h_recoMuonNoRPC_eta->Fill(muon->eta());
00765       h_recoMuonNoRPC_phi->Fill(muon->phi());
00766     }
00767   }
00768 
00769   // Find Non-muon hits
00770   for ( RecHitIter recHitIter = recHitHandle->begin();
00771         recHitIter != recHitHandle->end(); ++recHitIter )
00772   {
00773     const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
00774     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00775 
00776     const int region = roll->id().region();
00777     const int ring = roll->id().ring();
00778     //const int sector = roll->id().sector();
00779     const int station = roll->id().station();
00780     //const int layer = roll->id().layer();
00781     //const int subsector = roll->id().subsector();
00782 
00783     bool matched = false;
00784     for ( SimToRecHitMap::const_iterator match = simToRecHitMap.begin();
00785           match != simToRecHitMap.end(); ++match )
00786     {
00787       if ( recHitIter == match->second )
00788       {
00789         matched = true;
00790         break;
00791       }
00792     }
00793 
00794     if ( !matched )
00795     {
00796       // FIXME : kept for backward compatibility //
00797       if ( region == 0 )
00798       {
00799         h_.umOccupancyBarrel_wheel->Fill(ring);
00800         h_.umOccupancyBarrel_station->Fill(station);
00801         h_.umOccupancyBarrel_wheel_station->Fill(ring, station);
00802       }
00803       else
00804       {
00805         h_.umOccupancyEndcap_disk->Fill(region*station);
00806         h_.umOccupancyEndcap_disk_ring->Fill(region*station, ring);
00807       }
00808       // End of FIXME //
00809 
00810       int nPunchMatched = 0;
00811       // Check if this recHit came from non-muon simHit
00812       for ( std::vector<const PSimHit*>::const_iterator pthrSimHitP = pthrSimHits.begin();
00813             pthrSimHitP != pthrSimHits.end(); ++pthrSimHitP )
00814       {
00815         const PSimHit* simHit = *pthrSimHitP;
00816         const int absSimHitPType = abs(simHit->particleType());
00817         if ( absSimHitPType == 13 ) continue;
00818 
00819         const RPCDetId simDetId = static_cast<const RPCDetId>(simHit->detUnitId());
00820         if ( simDetId == detId ) ++nPunchMatched;
00821       }
00822 
00823       if ( nPunchMatched > 0 )
00824       {
00825         if ( region == 0 )
00826         {
00827           h_recPunchOccupancyBarrel_wheel->Fill(ring);
00828           h_recPunchOccupancyBarrel_station->Fill(station);
00829           h_recPunchOccupancyBarrel_wheel_station->Fill(ring, station);
00830         }
00831         else
00832         {
00833           h_recPunchOccupancyEndcap_disk->Fill(region*station);
00834           h_recPunchOccupancyEndcap_disk_ring->Fill(region*station, ring);
00835         }
00836       }
00837     }
00838   }
00839 
00840   // Find noise recHits : RecHits without SimHit match
00841   for ( RecHitIter recHitIter = recHitHandle->begin();
00842         recHitIter != recHitHandle->end(); ++recHitIter )
00843   {
00844     const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
00845     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(recDetId));
00846 
00847     const int region = roll->id().region();
00848     //    const int ring = roll->id().ring(); // UNUSED VARIABLE
00849     //const int sector = roll->id().sector();
00850     //    const int station = roll->id().station(); // UNUSED VARIABLE
00851     //const int layer = roll->id().layer();
00852     //const int subsector = roll->id().subsector();
00853 
00854     const double recX = recHitIter->localPosition().x();
00855     const double recErrX = sqrt(recHitIter->localPositionError().xx());
00856 
00857     bool matched = false;
00858     for ( SimHitIter simHitIter = simHitHandle->begin();
00859           simHitIter != simHitHandle->end(); ++simHitIter )
00860     {
00861       const RPCDetId simDetId = static_cast<const RPCDetId>(simHitIter->detUnitId());
00862       const RPCRoll* simRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(simDetId));
00863       if ( !simRoll ) continue;
00864 
00865       if ( simDetId != recDetId ) continue;
00866 
00867       const double simX = simHitIter->localPosition().x();
00868       const double dX = fabs(recX-simX);
00869 
00870       if ( dX/recErrX < 5 )
00871       {
00872         matched = true;
00873         break;
00874       }
00875     }
00876 
00877     if ( !matched )
00878     {
00879       if ( region == 0 )
00880       {
00881         h_noiseOccupancyBarrel_detId->Fill(detIdToIndexMapBarrel_[recDetId.rawId()]);
00882       }
00883       else
00884       {
00885         h_noiseOccupancyEndcap_detId->Fill(detIdToIndexMapEndcap_[recDetId.rawId()]);
00886       }
00887     }
00888   }
00889 
00890   h_eventCount->Fill(2);
00891 }
00892 
00893 DEFINE_FWK_MODULE(RPCRecHitValid);
00894