CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include "Validation/RPCRecHits/interface/RPCPointVsRecHit.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 "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00008 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00009 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00010 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00011 
00012 using namespace std;
00013 
00014 typedef MonitorElement* MEP;
00015 
00016 RPCPointVsRecHit::RPCPointVsRecHit(const edm::ParameterSet& pset)
00017 {
00018   refHitLabel_ = pset.getParameter<edm::InputTag>("refHit");
00019   recHitLabel_ = pset.getParameter<edm::InputTag>("recHit");
00020 
00021   dbe_ = edm::Service<DQMStore>().operator->();
00022   if ( !dbe_ )
00023   {
00024     edm::LogError("RPCPointVsRecHit") << "No DQMStore instance\n";
00025     return;
00026   }
00027 
00028   // Book MonitorElements
00029   const std::string subDir = pset.getParameter<std::string>("subDir");
00030   h_.bookHistograms(dbe_, subDir);
00031 }
00032 
00033 RPCPointVsRecHit::~RPCPointVsRecHit()
00034 {
00035 }
00036 
00037 void RPCPointVsRecHit::beginJob()
00038 {
00039 }
00040 
00041 void RPCPointVsRecHit::endJob()
00042 {
00043 }
00044 
00045 void RPCPointVsRecHit::analyze(const edm::Event& event, const edm::EventSetup& eventSetup)
00046 {
00047   if ( !dbe_ )
00048   {
00049     edm::LogError("RPCPointVsRecHit") << "No DQMStore instance\n";
00050     return;
00051   }
00052 
00053   // Get the RPC Geometry
00054   edm::ESHandle<RPCGeometry> rpcGeom;
00055   eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
00056 
00057   // Retrieve RefHits from the event
00058   edm::Handle<RPCRecHitCollection> refHitHandle;
00059   if ( !event.getByLabel(refHitLabel_, refHitHandle) )
00060   {
00061     edm::LogInfo("RPCPointVsRecHit") << "Cannot find reference hit collection\n";
00062     return;
00063   }
00064 
00065   // Retrieve RecHits from the event
00066   edm::Handle<RPCRecHitCollection> recHitHandle;
00067   if ( !event.getByLabel(recHitLabel_, recHitHandle) )
00068   {
00069     edm::LogInfo("RPCPointVsRecHit") << "Cannot find recHit collection\n";
00070     return;
00071   }
00072 
00073   typedef RPCRecHitCollection::const_iterator RecHitIter;
00074 
00075   // Loop over refHits, fill histograms which does not need associations
00076   int nRefHitBarrel = 0, nRefHitEndcap = 0;
00077   for ( RecHitIter refHitIter = refHitHandle->begin();
00078         refHitIter != refHitHandle->end(); ++refHitIter )
00079   {
00080     const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
00081     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
00082     if ( !roll ) continue;
00083 
00084     const int region = roll->id().region();
00085     const int ring = roll->id().ring();
00086     //const int sector = roll->id().sector();
00087     const int station = roll->id().station();
00088     //const int layer = roll->id().layer();
00089     //const int subSector = roll->id().subsector();
00090 
00091     if ( region == 0 )
00092     {
00093       h_.refHitOccupancyBarrel_wheel->Fill(ring);
00094       h_.refHitOccupancyBarrel_station->Fill(station);
00095       h_.refHitOccupancyBarrel_wheel_station->Fill(ring, station);
00096     }
00097     else
00098     {
00099       h_.refHitOccupancyEndcap_disk->Fill(region*station);
00100       h_.refHitOccupancyEndcap_disk_ring->Fill(region*station, ring);
00101     }
00102 
00103   }
00104   h_.nRefHitBarrel->Fill(nRefHitBarrel);
00105   h_.nRefHitEndcap->Fill(nRefHitEndcap);
00106 
00107   // Loop over recHits, fill histograms which does not need associations
00108   int sumClusterSizeBarrel = 0, sumClusterSizeEndcap = 0;
00109   int nRecHitBarrel = 0, nRecHitEndcap = 0;
00110   for ( RecHitIter recHitIter = recHitHandle->begin();
00111         recHitIter != recHitHandle->end(); ++recHitIter )
00112   {
00113     const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
00114     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
00115     if ( !roll ) continue;
00116 
00117     const int region = roll->id().region();
00118     const int ring = roll->id().ring();
00119     //const int sector = roll->id().sector();
00120     const int station = (roll->id().station());
00121     //const int layer = roll->id().layer();
00122     //const int subSector = roll->id().subsector();
00123 
00124     h_.clusterSize->Fill(recHitIter->clusterSize());
00125 
00126     if ( region == 0 )
00127     {
00128       ++nRecHitBarrel;
00129       sumClusterSizeBarrel += recHitIter->clusterSize();
00130       h_.clusterSizeBarrel->Fill(recHitIter->clusterSize());
00131       h_.recHitOccupancyBarrel_wheel->Fill(ring);
00132       h_.recHitOccupancyBarrel_station->Fill(station);
00133       h_.recHitOccupancyBarrel_wheel_station->Fill(ring, station);
00134     }
00135     else
00136     {
00137       ++nRecHitEndcap;
00138       sumClusterSizeEndcap += recHitIter->clusterSize();
00139       h_.clusterSizeEndcap->Fill(recHitIter->clusterSize());
00140       h_.recHitOccupancyEndcap_disk->Fill(region*station);
00141       h_.recHitOccupancyEndcap_disk_ring->Fill(ring, region*station);
00142     }
00143 
00144   }
00145   const double nRecHit = nRecHitBarrel+nRecHitEndcap;
00146   h_.nRecHitBarrel->Fill(nRecHitBarrel);
00147   h_.nRecHitEndcap->Fill(nRecHitEndcap);
00148   if ( nRecHit > 0 )
00149   {
00150     const int sumClusterSize = sumClusterSizeBarrel+sumClusterSizeEndcap;
00151     h_.avgClusterSize->Fill(double(sumClusterSize)/nRecHit);
00152 
00153     if ( nRecHitBarrel > 0 )
00154     {
00155       h_.avgClusterSizeBarrel->Fill(double(sumClusterSizeBarrel)/nRecHitBarrel);
00156     }
00157     if ( nRecHitEndcap > 0 )
00158     {
00159       h_.avgClusterSizeEndcap->Fill(double(sumClusterSizeEndcap)/nRecHitEndcap);
00160     }
00161   }
00162 
00163   // Start matching RefHits to RecHits
00164   typedef std::map<RecHitIter, RecHitIter> RecToRecHitMap;
00165   RecToRecHitMap refToRecHitMap;
00166 
00167   for ( RecHitIter refHitIter = refHitHandle->begin();
00168         refHitIter != refHitHandle->end(); ++refHitIter )
00169   {
00170     const RPCDetId refDetId = static_cast<const RPCDetId>(refHitIter->rpcId());
00171     const RPCRoll* refRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(refDetId));
00172     if ( !refRoll ) continue;
00173 
00174     const double refX = refHitIter->localPosition().x();
00175 
00176     for ( RecHitIter recHitIter = recHitHandle->begin();
00177           recHitIter != recHitHandle->end(); ++recHitIter )
00178     {
00179       const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
00180       const RPCRoll* recRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(recDetId));
00181       if ( !recRoll ) continue;
00182 
00183       if ( refDetId != recDetId ) continue;
00184 
00185       const double recX = recHitIter->localPosition().x();
00186       const double newDx = fabs(recX - refX);
00187 
00188       // Associate RefHit to RecHit
00189       RecToRecHitMap::const_iterator prevRefToReco = refToRecHitMap.find(refHitIter);
00190       if ( prevRefToReco == refToRecHitMap.end() )
00191       {
00192         refToRecHitMap.insert(std::make_pair(refHitIter, recHitIter));
00193       }
00194       else
00195       {
00196         const double oldDx = fabs(prevRefToReco->second->localPosition().x() - refX);
00197 
00198         if ( newDx < oldDx )
00199         {
00200           refToRecHitMap[refHitIter] = recHitIter;
00201         }
00202       }
00203     }
00204   }
00205 
00206   // Now we have refHit-recHit mapping
00207   // So we can fill up relavant histograms
00208   for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
00209         match != refToRecHitMap.end(); ++match )
00210   {
00211     RecHitIter refHitIter = match->first;
00212     RecHitIter recHitIter = match->second;
00213 
00214     const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
00215     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00216 
00217     const int region = roll->id().region();
00218     const int ring = roll->id().ring();
00219     //const int sector = roll->id().sector();
00220     const int station = roll->id().station();
00221     //const int layer = roll->id().layer();
00222     //const int subsector = roll->id().subsector();
00223 
00224     const double refX = refHitIter->localPosition().x();
00225     const double recX = recHitIter->localPosition().x();
00226     const double errX = sqrt(recHitIter->localPositionError().xx());
00227     const double dX = recX - refX;
00228     const double pull = errX == 0 ? -999 : dX/errX;
00229 
00230     //const GlobalPoint refPos = roll->toGlobal(refHitIter->localPosition());
00231     //const GlobalPoint recPos = roll->toGlobal(recHitIter->localPosition());
00232 
00233     if ( region == 0 )
00234     {
00235       h_.resBarrel->Fill(dX);
00236       h_.pullBarrel->Fill(pull);
00237       h_.matchOccupancyBarrel_wheel->Fill(ring);
00238       h_.matchOccupancyBarrel_station->Fill(station);
00239       h_.matchOccupancyBarrel_wheel_station->Fill(ring, station);
00240 
00241       h_.res_wheel_res->Fill(ring, dX);
00242       h_.res_station_res->Fill(station, dX);
00243       h_.pull_wheel_pull->Fill(ring, pull);
00244       h_.pull_station_pull->Fill(station, pull);
00245     }
00246     else
00247     {
00248       h_.resEndcap->Fill(dX);
00249       h_.pullEndcap->Fill(pull);
00250       h_.matchOccupancyEndcap_disk->Fill(region*station);
00251       h_.matchOccupancyEndcap_disk_ring->Fill(region*station, ring);
00252 
00253       h_.res_disk_res->Fill(region*station, dX);
00254       h_.res_ring_res->Fill(ring, dX);
00255       h_.pull_disk_pull->Fill(region*station, pull);
00256       h_.pull_ring_pull->Fill(ring, pull);
00257     }
00258   }
00259 
00260 /*
00261   // Find Lost hits
00262   for ( RecHitIter refHitIter = refHitHandle->begin();
00263         refHitIter != refHitHandle->end(); ++refHitIter )
00264   {
00265     const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
00266     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00267 
00268     const int region = roll->id().region();
00269     const int ring = roll->id().ring();
00270     //const int sector = roll->id().sector();
00271     const int station = roll->id().station();
00272     //const int layer = roll->id().layer();
00273     //const int subsector = roll->id().subsector();
00274 
00275     bool matched = false;
00276     for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
00277           match != refToRecHitMap.end(); ++match )
00278     {
00279       if ( refHitIter == match->first )
00280       {
00281         matched = true;
00282         break;
00283       }
00284     }
00285 
00286     if ( !matched )
00287     {
00288       if ( region == 0 )
00289       {
00290         h_.nUrefHitOccupancyBarrel_wheel->Fill(ring);
00291         h_.nUrefHitOccupancyBarrel_wheel_ring->Fill(ring, station);
00292       }
00293       else
00294       {
00295         h_.nUnMatchedRefHit_disk->Fill(region*station);
00296         h_.nUnMatchedRefHit_disk_ring->Fill(region*station, ring);
00297       }
00298     }
00299   }
00300 */
00301 
00302   // Find Noisy hits
00303   for ( RecHitIter recHitIter = recHitHandle->begin();
00304         recHitIter != recHitHandle->end(); ++recHitIter )
00305   {
00306     const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
00307     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00308 
00309     const int region = roll->id().region();
00310     const int ring = roll->id().ring();
00311     //const int sector = roll->id().sector();
00312     const int station = roll->id().station();
00313     //const int layer = roll->id().layer();
00314     //const int subsector = roll->id().subsector();
00315 
00316     bool matched = false;
00317     for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
00318           match != refToRecHitMap.end(); ++match )
00319     {
00320       if ( recHitIter == match->second )
00321       {
00322         matched = true;
00323         break;
00324       }
00325     }
00326 
00327     if ( !matched )
00328     {
00329       if ( region == 0 )
00330       {
00331         h_.umOccupancyBarrel_wheel->Fill(ring);
00332         h_.umOccupancyBarrel_station->Fill(station);
00333         h_.umOccupancyBarrel_wheel_station->Fill(ring, station);
00334       }
00335       else
00336       {
00337         h_.umOccupancyEndcap_disk->Fill(region*station);
00338         h_.umOccupancyEndcap_disk_ring->Fill(region*station, ring);
00339       }
00340 
00341       //const GlobalPoint pos = roll->toGlobal(recHitIter->localPosition());
00342       //h_[HName::NoisyHitEta]->Fill(pos.eta());
00343     }
00344   }
00345 }
00346 
00347 DEFINE_FWK_MODULE(RPCPointVsRecHit);
00348