CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Validation/MuonRPCDigis/src/RPCDigiValid.cc

Go to the documentation of this file.
00001 #include "Validation/MuonRPCDigis/interface/RPCDigiValid.h"
00002 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00003 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00004 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00005 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00006 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00007 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00008 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00009 
00010 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00011 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00012 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00013 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00014 #include "DQMServices/Core/interface/DQMStore.h"
00015 
00016 using namespace std;
00017 using namespace edm;
00018 
00019 RPCDigiValid::RPCDigiValid(const ParameterSet& ps):dbe_(0){
00020     
00021   digiLabel = ps.getUntrackedParameter<std::string>("digiLabel");
00022   outputFile_ = ps.getUntrackedParameter<string>("outputFile", "rpcDigiValidPlots.root");
00023   dbe_ = Service<DQMStore>().operator->();
00024   
00025   if ( dbe_ ) {
00026     dbe_->setCurrentFolder("RPCDigisV/RPCDigis");
00027     
00028     xyview = dbe_->book2D("X Vs Y View","X Vs Y View",1000, -700., 700., 1000, -700., 700.);
00029     rzview = dbe_->book2D("R Vs Z View","X Vs Y View",1000, -1100., 1100.,1000,0., 700.);
00030     Res  = dbe_->book1D("Digi SimHit difference", "Digi SimHit Difference", 300, -8, 8);
00031     ResWmin2 = dbe_->book1D("W-2 Residuals", "Residuals for Wheel -2", 300, -8, 8);
00032     ResWmin1 = dbe_->book1D("W-1 Residuals", "Residuals for Wheel -1", 300, -8, 8);
00033     ResWzer0 = dbe_->book1D("W 0 Residuals", "Residuals for Wheel 0", 300, -8, 8);
00034     ResWplu1 = dbe_->book1D("W+1 Residuals", "Residuals for Wheel +1", 300, -8, 8);
00035     ResWplu2 = dbe_->book1D("W+2 Residuals", "Residuals for Wheel +2", 300, -8, 8);
00036 
00037     BxDist = dbe_->book1D("Bunch Crossing", "Bunch Crossing", 20, -9.5, 9.5);
00038     StripProf = dbe_->book1D("Strip Profile", "Strip Profile", 100, 0, 100);
00039   }
00040 }
00041 
00042 RPCDigiValid::~RPCDigiValid(){}
00043 
00044 void RPCDigiValid::beginJob(){}
00045 
00046 void RPCDigiValid::endJob() {
00047  if ( outputFile_.size() != 0 && dbe_ ) dbe_->save(outputFile_);
00048 }
00049 
00050 void RPCDigiValid::analyze(const Event& event, const EventSetup& eventSetup){
00051 
00052   //  cout << endl <<"--- [RPCDigiQuality] Analysing Event: #Run: " << event.id().run()
00053   //       << " #Event: " << event.id().event() << endl;
00054   
00055   // Get the RPC Geometry
00056   edm::ESHandle<RPCGeometry> rpcGeom;
00057   eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
00058   
00059   edm::Handle<PSimHitContainer> simHit;
00060   event.getByLabel("g4SimHits", "MuonRPCHits", simHit);
00061   
00062   edm::Handle<RPCDigiCollection> rpcDigis;
00063   event.getByLabel(digiLabel, rpcDigis);
00064 
00065   // Loop on simhits
00066   PSimHitContainer::const_iterator simIt;
00067 
00068   //loop over Simhit
00069   std::map<RPCDetId, std::vector<double> > allsims;
00070 
00071   for (simIt = simHit->begin(); simIt != simHit->end(); simIt++) {
00072     RPCDetId Rsid = (RPCDetId)(*simIt).detUnitId();
00073     const RPCRoll* soll = dynamic_cast<const RPCRoll* >( rpcGeom->roll(Rsid));
00074     int ptype = simIt->particleType();
00075 
00076     //    std::cout <<"This is a Simhit with Parent "<<ptype<<std::endl;
00077     if (ptype == 13 || ptype == -13) {
00078       std::vector<double> buff;
00079       if (allsims.find(Rsid) != allsims.end() ){
00080         buff= allsims[Rsid];
00081       }
00082       buff.push_back(simIt->localPosition().x());
00083       allsims[Rsid]=buff;
00084     }
00085     GlobalPoint p=soll->toGlobal(simIt->localPosition());
00086     /*
00087     std::cout <<"Muon Position phi="<<p.phi()
00088             <<" R="<<p.perp()
00089               <<" z="<<p.z()<<std::endl;
00090     */
00091     xyview->Fill(p.x(),p.y());
00092     rzview->Fill(p.z(),p.perp());
00093 
00094   }
00095   //loop over Digis
00096   RPCDigiCollection::DigiRangeIterator detUnitIt;
00097   for (detUnitIt=rpcDigis->begin(); detUnitIt!=rpcDigis->end();++detUnitIt){
00098     const RPCDetId Rsid = (*detUnitIt).first;
00099     const RPCRoll* roll = dynamic_cast<const RPCRoll* >( rpcGeom->roll(Rsid));
00100     const RPCDigiCollection::Range& range = (*detUnitIt).second;
00101     std::vector<double> sims;
00102     if (allsims.find(Rsid) != allsims.end() ){
00103       sims = allsims[Rsid];
00104     }
00105     int ndigi=0;
00106     for (RPCDigiCollection::const_iterator digiIt = range.first;
00107          digiIt != range.second; ++digiIt){
00108       StripProf->Fill(digiIt->strip());
00109       BxDist->Fill(digiIt->bx());
00110       ndigi++;
00111     }
00112     
00113 
00114     //    std::cout<<" Number of Digi "<<ndigi<<" for "<<Rsid<<std::endl;
00115 
00116     if (sims.size() == 1 &&  ndigi == 1){
00117       double dis = roll->centreOfStrip(range.first->strip()).x()-sims[0];
00118       Res->Fill(dis);   
00119       
00120       if (Rsid.region() == 0 ){
00121         if (Rsid.ring() == -2)
00122           ResWmin2->Fill(dis);
00123         else if (Rsid.ring() == -1)
00124           ResWmin1->Fill(dis);
00125         else if (Rsid.ring() == 0)
00126           ResWzer0->Fill(dis);
00127         else if (Rsid.ring() == 1)
00128           ResWplu1->Fill(dis);
00129         else if (Rsid.ring() == 2)
00130           ResWplu2->Fill(dis);
00131       }
00132     }
00133   }
00134 }
00135