CMS 3D CMS Logo

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

Go to the documentation of this file.
00001  /* 
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2009/12/14 22:25:01 $
00005  *  $Revision: 1.3 $
00006  *  \author D. Pagano - Dip. Fis. Nucl. e Teo. & INFN Pavia
00007  */
00008 
00009 #include "Validation/RPCRecHits/interface/RPCRecHitValid.h"
00010 
00011 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00012 
00013 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00014 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00015 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00016 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00017 
00018 #include "FWCore/Framework/interface/MakerMacros.h"
00019 #include "FWCore/Framework/interface/Frameworkfwd.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 
00024 using namespace std;
00025 using namespace edm;
00026  
00027   
00028 RPCRecHitValid::RPCRecHitValid(const ParameterSet& pset){
00029   rootFileName = pset.getUntrackedParameter<string>("rootFileName", "rpcRecHitValidPlots.root");
00030   //simHitLabel = pset.getUntrackedParameter<string>("g4SimHits", "MuonRPCHits");
00031   //recHitLabel = pset.getUntrackedParameter<string>("recHitLabel", "RPCRecHitProducer");
00032   dbe_ = Service<DQMStore>().operator->();
00033   
00034   if ( dbe_ ) {
00035 
00036     Rechisto   = dbe_->book1D("RecHits", "RPC RecHits", 300, -150, 150);
00037     Simhisto   = dbe_->book1D("SimHits", "Simulated Hits", 300, -150, 150);
00038     Pulls      = dbe_->book1D("Global Pulls", "RPC Global Pulls", 100, -4,4);
00039     ClSize     = dbe_->book1D("Global ClSize", "Global Cluster Size", 10, 0, 10);
00040     res1cl     = dbe_->book1D("Residuals CS = 1", "Residuals for ClSize = 1", 300, -8, 8);
00041 
00042 //     dbe_->setCurrentFolder("Residuals");
00043 //     Res  = dbe_->book1D("Global Residuals", "Global Residuals", 300, -8, 8);
00044 //     ResWmin2 = dbe_->book1D("W-2 Residuals", "Residuals for Wheel -2", 300, -8, 8);
00045 //     ResWmin1 = dbe_->book1D("W-1 Residuals", "Residuals for Wheel -1", 300, -8, 8);
00046 //     ResWzer0 = dbe_->book1D("W 0 Residuals", "Residuals for Wheel 0", 300, -8, 8);
00047 //     ResWplu1 = dbe_->book1D("W+1 Residuals", "Residuals for Wheel +1", 300, -8, 8);
00048 //     ResWplu2 = dbe_->book1D("W+2 Residuals", "Residuals for Wheel +2", 300, -8, 8);
00049 //     ResS1    = dbe_->book1D("Sector 1 Residuals", "Sector 1 Residuals", 300, -8, 8);
00050 //     ResS3    = dbe_->book1D("Sector 3 Residuals", "Sector 3 Residuals", 300, -8, 8);
00051 
00052     dbe_->setCurrentFolder("Residuals and Occupancy");
00053     occRB1IN   = dbe_->book1D("RB1 IN Occupancy", "RB1 IN Occupancy", 100, 0, 100);
00054     occRB1OUT   = dbe_->book1D("RB1 OUT Occupancy", "RB1 OUT Occupancy", 100, 0, 100);
00055 
00056     //    dbe_->setCurrentFolder("Residuals");
00057     Res  = dbe_->book1D("Global Residuals", "Global Residuals", 300, -8, 8);
00058     ResWmin2 = dbe_->book1D("W-2 Residuals", "Residuals for Wheel -2", 300, -8, 8);
00059     ResWmin1 = dbe_->book1D("W-1 Residuals", "Residuals for Wheel -1", 300, -8, 8);
00060     ResWzer0 = dbe_->book1D("W 0 Residuals", "Residuals for Wheel 0", 300, -8, 8);
00061     ResWplu1 = dbe_->book1D("W+1 Residuals", "Residuals for Wheel +1", 300, -8, 8);
00062     ResWplu2 = dbe_->book1D("W+2 Residuals", "Residuals for Wheel +2", 300, -8, 8);
00063     ResS1    = dbe_->book1D("Sector 1 Residuals", "Sector 1 Residuals", 300, -8, 8);
00064     ResS3    = dbe_->book1D("Sector 3 Residuals", "Sector 3 Residuals", 300, -8, 8);
00065 
00066 
00067 
00068 
00069   }  
00070 }
00071 
00072 void RPCRecHitValid::beginJob() {}
00073 
00074 // Destructor
00075 RPCRecHitValid::~RPCRecHitValid(){
00076 }
00077 
00078 void RPCRecHitValid::endJob() {
00079  if ( rootFileName.size() != 0 && dbe_ ) dbe_->save(rootFileName);
00080 }
00081 
00082 
00083 
00084 void RPCRecHitValid::analyze(const Event & event, const EventSetup& eventSetup){
00085   
00086   // Get the RPC Geometry
00087   ESHandle<RPCGeometry> rpcGeom;
00088   eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
00089   
00090   Handle<PSimHitContainer> simHit;
00091   event.getByLabel("g4SimHits", "MuonRPCHits", simHit);
00092   std::map<double, int> mapsim;
00093   std::map<int, double> nmapsim;
00094   std::map<double, int> simWmin2;
00095   std::map<double, int> simWmin1;
00096   std::map<double, int> simWzer0;
00097   std::map<double, int> simWplu1;
00098   std::map<double, int> simWplu2;
00099   std::map<double, int> simS1;
00100   std::map<double, int> simS3;
00101   std::map<int, double> nsimWmin2;
00102   std::map<int, double> nsimWmin1;
00103   std::map<int, double> nsimWzer0;
00104   std::map<int, double> nsimWplu1;
00105   std::map<int, double> nsimWplu2;
00106   std::map<int, double> nsimS1;
00107   std::map<int, double> nsimS3;
00108 
00109   Handle<RPCRecHitCollection> recHit;
00110   event.getByLabel("rpcRecHits", recHit);
00111   std::map<double, int> maprec;
00112   std::map<int, double> nmaprec;
00113   std::map<double, double> nmaperr;
00114   std::map<int, double> nmapres;
00115     
00116   std::map<double, int> maprecCL1;
00117   std::map<int, double> nmaprecCL1;
00118 
00119   std::map<double, int> recWmin2;
00120   std::map<double, int> recWmin1;
00121   std::map<double, int> recWzer0;
00122   std::map<double, int> recWplu1;
00123   std::map<double, int> recWplu2;
00124   std::map<double, int> recS1;
00125   std::map<double, int> recS3;
00126   std::map<int, double> nrecWmin2;
00127   std::map<int, double> nrecWmin1;
00128   std::map<int, double> nrecWzer0;
00129   std::map<int, double> nrecWplu1;
00130   std::map<int, double> nrecWplu2;
00131   std::map<int, double> nrecS1;
00132   std::map<int, double> nrecS3;
00133   std::map<double, double> errWmin2;
00134   std::map<double, double> errWmin1;
00135   std::map<double, double> errWzer0;
00136   std::map<double, double> errWplu1;
00137   std::map<double, double> errWplu2;
00138   
00139 
00140   // Loop on rechits
00141   RPCRecHitCollection::const_iterator recIt;
00142   int nrec = 0; 
00143   int nrecCL1 = 0;
00144   int nrecmin2 = 0;
00145   int nrecmin1 = 0;
00146   int nreczer0 = 0;
00147   int nrecplu1 = 0;
00148   int nrecplu2 = 0;
00149   int nrecS1c = 0;
00150   int nrecS3c = 0;
00151   
00152   for (recIt = recHit->begin(); recIt != recHit->end(); recIt++) {
00153     RPCDetId Rid = (RPCDetId)(*recIt).rpcId();
00154     const RPCRoll* roll = dynamic_cast<const RPCRoll* >( rpcGeom->roll(Rid));
00155     if((roll->isForward())) return;
00156     int clsize = (*recIt).clusterSize();
00157     int fstrip = (*recIt).firstClusterStrip();
00158     
00159     nrec = nrec + 1;
00160     LocalPoint rhitlocal = (*recIt).localPosition();
00161     LocalError locerr = (*recIt).localPositionError(); 
00162     double rhitlocalx = rhitlocal.x();
00163     double rhiterrx = locerr.xx();
00164     Rechisto->Fill(rhitlocalx);
00165     int wheel = roll->id().ring();
00166     int sector = roll->id().sector(); 
00167     int station = roll->id().station();
00168     int k = roll->id().layer();
00169     //    int s = roll->id().subsector();
00170 
00171     //-----CLSIZE = 1------------
00172     if (clsize == 1) {
00173       maprecCL1[rhitlocalx] = nrec;
00174       nrecCL1 = nrecCL1 + 1;
00175     }
00176     //-----------------------------
00177 
00178     ClSize->Fill(clsize); //Global Cluster Size
00179     
00180     
00181     // occupancy
00182     for (int occ = 0; occ < clsize; occ++) {
00183       int occup = fstrip + occ;
00184       if (station == 1 && k == 1) {
00185         occRB1IN->Fill(occup);
00186       }
00187       if (station == 1 && k == 2) {
00188         occRB1OUT->Fill(occup);
00189       }
00190     }      
00191     
00192 
00193     maprec[rhitlocalx] = nrec;
00194     nmaperr[rhitlocalx] = rhiterrx;
00195     
00196     //-------PHI-------------------
00197     if(sector == 1) {
00198       recS1[rhitlocalx] = nrec;
00199       nrecS1c = nrecS1c + 1;
00200     }
00201     if(sector == 3) {
00202       recS3[rhitlocalx] = nrec;
00203       nrecS3c = nrecS3c + 1;
00204     }
00205     //----------------------------
00206        
00207     if(wheel == -2) {
00208       recWmin2[rhitlocalx] = nrec;
00209       errWmin2[rhitlocalx] = rhiterrx;
00210       nrecmin2 = nrecmin2 + 1;
00211     }
00212     if(wheel == -1) {
00213       recWmin1[rhitlocalx] = nrec;
00214       errWmin1[rhitlocalx] = rhiterrx;
00215       nrecmin1 = nrecmin1 + 1;
00216     }
00217     if(wheel == 0) {
00218       recWzer0[rhitlocalx] = nrec;
00219       errWzer0[rhitlocalx] = rhiterrx;
00220       nreczer0 = nreczer0 + 1;
00221     }
00222     if(wheel == 1) {
00223       recWplu1[rhitlocalx] = nrec;
00224       errWplu1[rhitlocalx] = rhiterrx;
00225       nrecplu1 = nrecplu1 + 1;
00226     }
00227     if(wheel == 2) {
00228       recWplu2[rhitlocalx] = nrec;
00229       errWplu2[rhitlocalx] = rhiterrx;
00230       nrecplu2 = nrecplu2 + 1;
00231     }
00232   }
00233   //cout << " --> Found " << nrec << " rechit in event " << event.id().event() << endl;
00234    
00235   // Global rechit mapping
00236   int i = 0;
00237   for (map<double, int>::iterator iter = maprec.begin(); iter != maprec.end(); iter++) {
00238     i = i + 1;
00239     nmaprec[i] = (*iter).first;
00240   }
00241   // CL = 1 rechit mapping
00242   i = 0;
00243   for (map<double, int>::iterator iter = maprecCL1.begin(); iter != maprecCL1.end(); iter++) {
00244     i = i + 1;
00245     nmaprecCL1[i] = (*iter).first;
00246   }
00247   // Wheel -2 rechit mapping
00248   i = 0;
00249   for (map<double, int>::iterator iter = recWmin2.begin(); iter != recWmin2.end(); iter++) {
00250     i = i + 1;
00251     nrecWmin2[i] = (*iter).first;
00252   }  
00253   // Wheel -1 rechit mapping
00254   i = 0;
00255   for (map<double, int>::iterator iter = recWmin1.begin(); iter != recWmin1.end(); iter++) {
00256     i = i + 1;
00257     nrecWmin1[i] = (*iter).first;
00258   }
00259   // Wheel 0 rechit mapping
00260   i = 0;
00261   for (map<double, int>::iterator iter = recWzer0.begin(); iter != recWzer0.end(); iter++) {
00262     i = i + 1;
00263     nrecWzer0[i] = (*iter).first;
00264   }
00265   // Wheel +1 rechit mapping
00266   i = 0;
00267   for (map<double, int>::iterator iter = recWplu1.begin(); iter != recWplu1.end(); iter++) {
00268     i = i + 1;
00269     nrecWplu1[i] = (*iter).first;
00270   }
00271   // Wheel +2 rechit mapping
00272   i = 0;
00273   for (map<double, int>::iterator iter = recWplu2.begin(); iter != recWplu2.end(); iter++) {
00274     i = i + 1;
00275     nrecWplu2[i] = (*iter).first;
00276   }
00277   // Sector 1 rechit mapping
00278   i = 0;
00279   for (map<double, int>::iterator iter = recS1.begin(); iter != recS1.end(); iter++) {
00280     i = i + 1;
00281     nrecS1[i] = (*iter).first;
00282   }
00283   // Sector 3 rechit mapping
00284   i = 0;
00285   for (map<double, int>::iterator iter = recS3.begin(); iter != recS3.end(); iter++) {
00286     i = i + 1;
00287     nrecS3[i] = (*iter).first;
00288   }
00289 
00290   
00291   // Loop on simhits
00292   PSimHitContainer::const_iterator simIt;
00293   int nsim = 0;
00294   int nsimmin2 = 0;
00295   int nsimmin1 = 0;
00296   int nsimzer0 = 0;
00297   int nsimplu1 = 0;
00298   int nsimplu2 = 0;
00299   int nsimS1c = 0;
00300   int nsimS3c = 0;
00301 
00302   for (simIt = simHit->begin(); simIt != simHit->end(); simIt++) {
00303     int ptype = (*simIt).particleType();
00304     RPCDetId Rsid = (RPCDetId)(*simIt).detUnitId();
00305     const RPCRoll* roll = dynamic_cast<const RPCRoll* >( rpcGeom->roll(Rsid));
00306     int Swheel = roll->id().ring();
00307     int Ssector = roll->id().sector();
00308         
00309     // selection of muon hits 
00310     if (ptype == 13 || ptype == -13) {
00311       nsim = nsim + 1;
00312       LocalPoint shitlocal = (*simIt).localPosition();
00313       double shitlocalx = shitlocal.x();
00314       Simhisto->Fill(shitlocalx);      
00315 
00316       mapsim[shitlocalx] = nsim;
00317 
00318       //----PHI------------------------
00319       if(Ssector == 1) {
00320         simS1[shitlocalx] = nsim;
00321         nsimS1c = nsimS1c + 1;
00322       }
00323       if(Ssector == 3) {
00324         simS3[shitlocalx] = nsim;
00325         nsimS3c = nsimS3c + 1;
00326       }
00327       //--------------------------------
00328 
00329 
00330       if(Swheel == -2) {
00331         simWmin2[shitlocalx] = nsim;
00332         nsimmin2 = nsimmin2 + 1;
00333       }
00334       if(Swheel == -1) {
00335         simWmin1[shitlocalx] = nsim;
00336         nsimmin1 = nsimmin1 + 1;
00337       }
00338       if(Swheel == 0) {
00339         simWzer0[shitlocalx] = nsim;
00340         nsimzer0 = nsimzer0 + 1;
00341       }
00342       if(Swheel == 1) {
00343         simWplu1[shitlocalx] = nsim;
00344         nsimplu1 = nsimplu1 + 1;
00345       }
00346       if(Swheel == 2) {
00347         simWplu2[shitlocalx] = nsim;
00348         nsimplu2 = nsimplu2 + 1;
00349       }
00350      
00351     }
00352   }
00353   //cout << " --> Found " << nsim <<" simhits in event " << event.id().event() << endl;
00354 
00355   // Global simhit mapping
00356   i = 0;
00357   for (map<double, int>::iterator iter = mapsim.begin(); iter != mapsim.end(); iter++) {
00358     i = i + 1;
00359     nmapsim[i] = (*iter).first;
00360   }
00361   // Wheel -2 simhit mapping
00362   i = 0;
00363   for (map<double, int>::iterator iter = simWmin2.begin(); iter != simWmin2.end(); iter++) {
00364     i = i + 1;
00365     nsimWmin2[i] = (*iter).first;
00366   }
00367   // Wheel -1 simhit mapping
00368   i = 0;
00369   for (map<double, int>::iterator iter = simWmin1.begin(); iter != simWmin1.end(); iter++) {
00370     i = i + 1;
00371     nsimWmin1[i] = (*iter).first;
00372   }
00373   // Wheel 0 simhit mapping
00374   i = 0;
00375   for (map<double, int>::iterator iter = simWzer0.begin(); iter != simWzer0.end(); iter++) {
00376     i = i + 1;
00377     nsimWzer0[i] = (*iter).first;
00378   }
00379   // Wheel +1 simhit mapping
00380   i = 0;
00381   for (map<double, int>::iterator iter = simWplu1.begin(); iter != simWplu1.end(); iter++) {
00382     i = i + 1;
00383     nsimWplu1[i] = (*iter).first;
00384   }
00385   // Wheel +2 simhit mapping
00386   i = 0;
00387   for (map<double, int>::iterator iter = simWplu2.begin(); iter != simWplu2.end(); iter++) {
00388     i = i + 1;
00389     nsimWplu2[i] = (*iter).first;
00390   }
00391   // Sector 1 simhit mapping
00392   i = 0;
00393   for (map<double, int>::iterator iter = simS1.begin(); iter != simS1.end(); iter++) {
00394     i = i + 1;
00395     nsimS1[i] = (*iter).first;
00396   }
00397   // Sector 3 simhit mapping
00398   i = 0;
00399   for (map<double, int>::iterator iter = simS3.begin(); iter != simS3.end(); iter++) {
00400     i = i + 1;
00401     nsimS3[i] = (*iter).first;
00402   }
00403 
00404   // Compute residuals 
00405   double res,resmin2,resmin1,reszer0,resplu1,resplu2,resS1,resS3;
00406   if (nsim == nrec) {
00407     for (int r=0; r<nsim; r++) {
00408       res = nmapsim[r+1] - nmaprec[r+1];
00409       nmapres[r+1] = res;
00410       Res->Fill(res);
00411     }
00412   }
00413   if (nsim == nrecCL1) {
00414    for (int r=0; r<nsim; r++) {
00415      res = nmapsim[r+1] - nmaprecCL1[r+1];
00416      //cout << nmapsim[r+1] << " " << nmaprecCL1[r+1] << endl;
00417      if (abs(res) < 3) {
00418        res1cl->Fill(res);
00419      }
00420    }
00421  }
00422   if (nsimmin2 == nrecmin2) {
00423     for (int r=0; r<nsimmin2; r++) {
00424       resmin2 = nsimWmin2[r+1] - nrecWmin2[r+1];
00425       ResWmin2->Fill(resmin2);
00426     }
00427   }
00428   if (nsimmin1 == nrecmin1) {
00429     for (int r=0; r<nsimmin1; r++) {
00430       resmin1 = nsimWmin1[r+1] - nrecWmin1[r+1];
00431       ResWmin1->Fill(resmin1);
00432     }
00433   }
00434   if (nsimzer0 == nreczer0) {
00435     for (int r=0; r<nsimzer0; r++) {
00436       reszer0 = nsimWzer0[r+1] - nrecWzer0[r+1];
00437       ResWzer0->Fill(reszer0);
00438     }
00439   }
00440   if (nsimplu1 == nrecplu1) {
00441     for (int r=0; r<nsimplu1; r++) {
00442       resplu1 = nsimWplu1[r+1] - nrecWplu1[r+1];
00443       ResWplu1->Fill(resplu1);
00444     }
00445   }
00446   if (nsimplu2 == nrecplu2) {
00447     for (int r=0; r<nsimplu2; r++) {
00448       resplu2 = nsimWplu2[r+1] - nrecWplu2[r+1];
00449       ResWplu2->Fill(resplu2);
00450     }
00451   }
00452   if (nsimS1c == nrecS1c) {
00453     for (int r=0; r<nsimS1c; r++) {
00454       resS1 = nsimS1[r+1] - nrecS1[r+1];
00455       ResS1->Fill(resS1);
00456     }
00457   }
00458   if (nsimS3c == nrecS3c) {
00459     for (int r=0; r<nsimS3c; r++) {
00460       resS3 = nsimS3[r+1] - nrecS3[r+1];
00461       ResS3->Fill(resS3);
00462     }
00463   }
00464 
00465 
00466   // compute Pulls 
00467   double pull;
00468   if (nsim == nrec) {
00469     for (int r=0; r<nsim; r++) {
00470       pull = nmapres[r+1] / nmaperr[nmaprec[r+1]];
00471       Pulls->Fill(pull);
00472     }
00473   }
00474 }
00475 
00476