CMS 3D CMS Logo

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