CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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/TrackingHit/interface/PSimHitContainer.h"
00008 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00009 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00010 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00011 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00012 
00013 using namespace std;
00014 
00015 typedef MonitorElement* MEP;
00016 
00017 RPCRecHitValid::RPCRecHitValid(const edm::ParameterSet& pset)
00018 {
00019   rootFileName_ = pset.getUntrackedParameter<string>("rootFileName", "");
00020   simHitLabel_ = pset.getParameter<edm::InputTag>("simHit");
00021   recHitLabel_ = pset.getParameter<edm::InputTag>("recHit");
00022 
00023   isStandAloneMode_ = pset.getUntrackedParameter<bool>("standAloneMode", false);
00024 
00025   dbe_ = edm::Service<DQMStore>().operator->();
00026   if ( !dbe_ )
00027   {
00028     edm::LogError("RPCRecHitValid") << "No DQMStore instance\n";
00029     return;
00030   }
00031 
00032   // Book MonitorElements
00033   const std::string subDir = pset.getParameter<std::string>("subDir");
00034   h_.bookHistograms(dbe_, subDir);
00035 }
00036 
00037 RPCRecHitValid::~RPCRecHitValid()
00038 {
00039   if ( dbe_ )
00040   {
00041     if ( !rootFileName_.empty() ) dbe_->save(rootFileName_);
00042   }
00043 }
00044 
00045 void RPCRecHitValid::beginJob()
00046 {
00047 }
00048 
00049 void RPCRecHitValid::endJob()
00050 {
00051 }
00052 
00053 void RPCRecHitValid::analyze(const edm::Event& event, const edm::EventSetup& eventSetup)
00054 {
00055   if ( !dbe_ )
00056   {
00057     edm::LogError("RPCRecHitValid") << "No DQMStore instance\n";
00058     return;
00059   }
00060 
00061   // Get the RPC Geometry
00062   edm::ESHandle<RPCGeometry> rpcGeom;
00063   eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
00064 
00065   // Retrieve SimHits from the event
00066   edm::Handle<edm::PSimHitContainer> simHitHandle;
00067   if ( !event.getByLabel(simHitLabel_, simHitHandle) )
00068   {
00069     edm::LogInfo("RPCRecHitValid") << "Cannot find simHit collection\n";
00070     return;
00071   }
00072 
00073   // Retrieve RecHits from the event
00074   edm::Handle<RPCRecHitCollection> recHitHandle;
00075   if ( !event.getByLabel(recHitLabel_, recHitHandle) )
00076   {
00077     edm::LogInfo("RPCRecHitValid") << "Cannot find recHit collection\n";
00078     return;
00079   }
00080 
00081   typedef edm::PSimHitContainer::const_iterator SimHitIter;
00082   typedef RPCRecHitCollection::const_iterator RecHitIter;
00083 
00084   // Loop over simHits, fill histograms which does not need associations
00085   for ( SimHitIter simHitIter = simHitHandle->begin();
00086         simHitIter != simHitHandle->end(); ++simHitIter )
00087   {
00088     if ( abs(simHitIter->particleType()) != 13 ) continue;
00089 
00090     const RPCDetId detId = static_cast<const RPCDetId>(simHitIter->detUnitId());
00091     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
00092     if ( !roll ) continue;
00093 
00094     const int region = roll->id().region();
00095     const int ring = roll->id().ring();
00096     //const int sector = roll->id().sector();
00097     const int station = roll->id().station();
00098     //const int layer = roll->id().layer();
00099     //const int subSector = roll->id().subsector();
00100 
00101     if ( region == 0 ) 
00102     {
00103       h_.nRefHit_W->Fill(ring);
00104       h_.nRefHit_WvsR->Fill(ring, station);
00105     }
00106     else 
00107     {
00108       h_.nRefHit_D->Fill(region*station);
00109       h_.nRefHit_DvsR->Fill(region*station, ring);
00110     }
00111 
00112     const GlobalPoint pos = roll->toGlobal(simHitIter->localPosition());
00113   }
00114 
00115   // Loop over recHits, fill histograms which does not need associations
00116   for ( RecHitIter recHitIter = recHitHandle->begin();
00117         recHitIter != recHitHandle->end(); ++recHitIter )
00118   {
00119     const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
00120     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
00121     if ( !roll ) continue;
00122 
00123     const int region = roll->id().region();
00124     const int ring = roll->id().ring();
00125     //const int sector = roll->id().sector();
00126     const int station = roll->id().station();
00127     //const int layer = roll->id().layer();
00128     //const int subSector = roll->id().subsector();
00129 
00130     h_.clusterSize->Fill(recHitIter->clusterSize());
00131 
00132     if ( region == 0 ) 
00133     {
00134       h_.nRecHit_W->Fill(ring);
00135       h_.nRecHit_WvsR->Fill(ring, station);
00136     }
00137     else
00138     {
00139       h_.nRecHit_D->Fill(region*station);
00140       h_.nRecHit_DvsR->Fill(ring, region*station);
00141     }
00142 
00143     const GlobalPoint pos = roll->toGlobal(recHitIter->localPosition());
00144   }
00145 
00146   // Start matching SimHits to RecHits
00147   typedef std::map<SimHitIter, RecHitIter> SimToRecHitMap;
00148   SimToRecHitMap simToRecHitMap;
00149 
00150   for ( SimHitIter simHitIter = simHitHandle->begin();
00151         simHitIter != simHitHandle->end(); ++simHitIter )
00152   {
00153     if ( abs(simHitIter->particleType()) != 13 ) continue;
00154 
00155     const RPCDetId simDetId = static_cast<const RPCDetId>(simHitIter->detUnitId());
00156     const RPCRoll* simRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(simDetId));
00157     if ( !simRoll ) continue;
00158 
00159     const double simX = simHitIter->localPosition().x();
00160 
00161     for ( RecHitIter recHitIter = recHitHandle->begin();
00162           recHitIter != recHitHandle->end(); ++recHitIter )
00163     {
00164       const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
00165       const RPCRoll* recRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(recDetId));
00166       if ( !recRoll ) continue;
00167 
00168       if ( simDetId != recDetId ) continue;
00169 
00170       const double recX = recHitIter->localPosition().x();
00171       const double newDx = fabs(recX - simX);
00172 
00173       // Associate SimHit to RecHit
00174       SimToRecHitMap::const_iterator prevSimToReco = simToRecHitMap.find(simHitIter);
00175       if ( prevSimToReco == simToRecHitMap.end() )
00176       {
00177         simToRecHitMap.insert(std::make_pair(simHitIter, recHitIter));
00178       }
00179       else
00180       {
00181         const double oldDx = fabs(prevSimToReco->second->localPosition().x() - simX);
00182 
00183         if ( newDx < oldDx )
00184         {
00185           simToRecHitMap[simHitIter] = recHitIter;
00186         }
00187       }
00188     }
00189   }
00190 
00191   // Now we have simHit-recHit mapping
00192   // So we can fill up relavant histograms
00193   for ( SimToRecHitMap::const_iterator match = simToRecHitMap.begin();
00194         match != simToRecHitMap.end(); ++match )
00195   {
00196     SimHitIter simHitIter = match->first;
00197     RecHitIter recHitIter = match->second;
00198 
00199     const RPCDetId detId = static_cast<const RPCDetId>(simHitIter->detUnitId());
00200     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00201 
00202     const int region = roll->id().region();
00203     const int ring = roll->id().ring();
00204     //const int sector = roll->id().sector();
00205     const int station = roll->id().station();
00206     //const int layer = roll->id().layer();
00207     //const int subsector = roll->id().subsector();
00208 
00209     const double simX = simHitIter->localPosition().x();
00210     const double recX = recHitIter->localPosition().x();
00211     const double errX = recHitIter->localPositionError().xx();
00212     const double dX = recX - simX;
00213     const double pull = errX == 0 ? -999 : dX/errX;
00214   
00215     const GlobalPoint simPos = roll->toGlobal(simHitIter->localPosition());
00216     const GlobalPoint recPos = roll->toGlobal(recHitIter->localPosition());
00217 
00218     if ( region == 0 )
00219     {
00220       h_.res_W->Fill(dX);
00221       h_.pull_W->Fill(pull);
00222       h_.nMatchedRefHit_W->Fill(ring);
00223       h_.nMatchedRefHit_WvsR->Fill(ring, station);
00224 
00225       h_.res2_W->Fill(ring, dX);
00226       h_.pull2_W->Fill(ring, pull);
00227     }
00228     else
00229     {
00230       h_.res_D->Fill(dX);
00231       h_.pull_D->Fill(pull);
00232       h_.nMatchedRefHit_D->Fill(region*station);
00233       h_.nMatchedRefHit_DvsR->Fill(region*station, ring);
00234 
00235       h_.res2_D->Fill(region*station, dX);
00236       h_.pull2_D->Fill(region*station, pull);
00237     }
00238 
00239   }
00240 
00241   // Find Lost hits
00242   for ( SimHitIter simHitIter = simHitHandle->begin();
00243         simHitIter != simHitHandle->end(); ++simHitIter )
00244   {
00245     const RPCDetId detId = static_cast<const RPCDetId>(simHitIter->detUnitId());
00246     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00247 
00248     const int region = roll->id().region();
00249     const int ring = roll->id().ring();
00250     //const int sector = roll->id().sector();
00251     const int station = roll->id().station();
00252     //const int layer = roll->id().layer();
00253     //const int subsector = roll->id().subsector();
00254 
00255     bool matched = false;
00256     for ( SimToRecHitMap::const_iterator match = simToRecHitMap.begin();
00257           match != simToRecHitMap.end(); ++match )
00258     {
00259       if ( simHitIter == match->first )
00260       {
00261         matched = true;
00262         break;
00263       }
00264     }
00265 
00266     if ( !matched )
00267     {
00268       if ( region == 0 )
00269       {
00270         h_.nUnMatchedRefHit_W->Fill(ring);
00271         h_.nUnMatchedRefHit_WvsR->Fill(ring, station);
00272       }
00273       else
00274       {
00275         h_.nUnMatchedRefHit_D->Fill(region*station);
00276         h_.nUnMatchedRefHit_DvsR->Fill(region*station, ring);
00277       }
00278     }
00279   }
00280 
00281   // Find Noisy hits
00282   for ( RecHitIter recHitIter = recHitHandle->begin();
00283         recHitIter != recHitHandle->end(); ++recHitIter )
00284   {
00285     const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
00286     const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
00287 
00288     const int region = roll->id().region();
00289     const int ring = roll->id().ring();
00290     //const int sector = roll->id().sector();
00291     const int station = roll->id().station();
00292     //const int layer = roll->id().layer();
00293     //const int subsector = roll->id().subsector();
00294 
00295     bool matched = false;
00296     for ( SimToRecHitMap::const_iterator match = simToRecHitMap.begin();
00297           match != simToRecHitMap.end(); ++match )
00298     {
00299       if ( recHitIter == match->second )
00300       {
00301         matched = true;
00302         break;
00303       }
00304     }
00305 
00306     if ( !matched )
00307     {
00308       if ( region == 0 ) 
00309       {
00310         h_.nUnMatchedRecHit_W->Fill(ring);
00311         h_.nUnMatchedRecHit_WvsR->Fill(ring, station);
00312       }
00313       else
00314       {
00315         h_.nUnMatchedRecHit_D->Fill(region*station);
00316         h_.nUnMatchedRecHit_DvsR->Fill(region*station, ring);
00317       }
00318 
00319       const GlobalPoint pos = roll->toGlobal(recHitIter->localPosition());
00320 //      h_[HName::NoisyHitEta]->Fill(pos.eta());
00321     }
00322   }
00323 }
00324 
00325 DEFINE_FWK_MODULE(RPCRecHitValid);
00326