CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Validation/GlobalRecHits/src/GlobalRecHitsAnalyzer.cc

Go to the documentation of this file.
00001 
00010 using namespace std;
00011 #include "Validation/GlobalRecHits/interface/GlobalRecHitsAnalyzer.h"
00012 #include "DQMServices/Core/interface/DQMStore.h"
00013 #include "DQMServices/Core/interface/MonitorElement.h"
00014 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00015 
00016 GlobalRecHitsAnalyzer::GlobalRecHitsAnalyzer(const edm::ParameterSet& iPSet) :
00017   fName(""), verbosity(0), frequency(0), label(""), getAllProvenances(false),
00018   printProvenanceInfo(false), count(0)
00019 {
00020   std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_GlobalRecHitsAnalyzer";
00021 
00022   // get information from parameter set
00023   fName = iPSet.getUntrackedParameter<std::string>("Name");
00024   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
00025   frequency = iPSet.getUntrackedParameter<int>("Frequency");
00026   edm::ParameterSet m_Prov =
00027     iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
00028   getAllProvenances = 
00029     m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
00030   printProvenanceInfo = 
00031     m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
00032   hitsProducer = iPSet.getParameter<std::string>("hitsProducer");
00033 
00034   //get Labels to use to extract information
00035   ECalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalEBSrc");
00036   ECalUncalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalUncalEBSrc");
00037   ECalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalEESrc");
00038   ECalUncalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalUncalEESrc");
00039   ECalESSrc_ = iPSet.getParameter<edm::InputTag>("ECalESSrc");
00040   HCalSrc_ = iPSet.getParameter<edm::InputTag>("HCalSrc");
00041   SiStripSrc_ = iPSet.getParameter<edm::InputTag>("SiStripSrc"); 
00042   SiPxlSrc_ = iPSet.getParameter<edm::InputTag>("SiPxlSrc");
00043   MuDTSrc_ = iPSet.getParameter<edm::InputTag>("MuDTSrc");
00044   MuDTSimSrc_ = iPSet.getParameter<edm::InputTag>("MuDTSimSrc");
00045   MuCSCSrc_ = iPSet.getParameter<edm::InputTag>("MuCSCSrc");
00046   MuRPCSrc_ = iPSet.getParameter<edm::InputTag>("MuRPCSrc");
00047   MuRPCSimSrc_ = iPSet.getParameter<edm::InputTag>("MuRPCSimSrc");
00048 
00049   conf_ = iPSet;
00050 
00051   // use value of first digit to determine default output level (inclusive)
00052   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
00053   verbosity %= 10;
00054 
00055   // create persistent object
00056   // produces<PGlobalRecHit>(label);
00057 
00058   // print out Parameter Set information being used
00059   if (verbosity >= 0) {
00060     edm::LogInfo(MsgLoggerCat) 
00061       << "\n===============================\n"
00062       << "Initialized as EDProducer with parameter values:\n"
00063       << "    Name           = " << fName << "\n"
00064       << "    Verbosity      = " << verbosity << "\n"
00065       << "    Frequency      = " << frequency << "\n"
00066       << "    GetProv        = " << getAllProvenances << "\n"
00067       << "    PrintProv      = " << printProvenanceInfo << "\n"
00068       << "    ECalEBSrc      = " << ECalEBSrc_.label() 
00069       << ":" << ECalEBSrc_.instance() << "\n"
00070       << "    ECalUncalEBSrc = " << ECalUncalEBSrc_.label() 
00071       << ":" << ECalUncalEBSrc_.instance() << "\n"
00072       << "    ECalEESrc      = " << ECalEESrc_.label() 
00073       << ":" << ECalUncalEESrc_.instance() << "\n"
00074       << "    ECalUncalEESrc = " << ECalUncalEESrc_.label() 
00075       << ":" << ECalEESrc_.instance() << "\n"
00076       << "    ECalESSrc      = " << ECalESSrc_.label() 
00077       << ":" << ECalESSrc_.instance() << "\n"
00078       << "    HCalSrc        = " << HCalSrc_.label() 
00079       << ":" << HCalSrc_.instance() << "\n"
00080       << "    SiStripSrc     = " << SiStripSrc_.label() 
00081       << ":" << SiStripSrc_.instance() << "\n" 
00082       << "    SiPixelSrc     = " << SiPxlSrc_.label()
00083       << ":" << SiPxlSrc_.instance() << "\n"
00084       << "    MuDTSrc        = " << MuDTSrc_.label()
00085       << ":" << MuDTSrc_.instance() << "\n"
00086       << "    MuDTSimSrc     = " << MuDTSimSrc_.label()
00087       << ":" << MuDTSimSrc_.instance() << "\n"
00088       << "    MuCSCSrc       = " << MuCSCSrc_.label()
00089       << ":" << MuCSCSrc_.instance() << "\n"
00090       << "    MuRPCSrc       = " << MuRPCSrc_.label()
00091       << ":" << MuRPCSrc_.instance() << "\n"
00092       << "    MuRPCSimSrc    = " << MuRPCSimSrc_.label()
00093       << ":" << MuRPCSimSrc_.instance() << "\n"
00094       << "===============================\n";
00095   }
00096   //Put in analyzer stuff here....
00097 
00098   dbe = 0;
00099   dbe = edm::Service<DQMStore>().operator->();
00100   if (dbe) {
00101     if (verbosity > 0 ) {
00102       dbe->setVerbose(1);
00103     } else {
00104       dbe->setVerbose(0);
00105     }
00106   }
00107   if (dbe) {
00108     if (verbosity > 0 ) dbe->showDirStructure();
00109   }
00110 
00111   Char_t hname[100];
00112   Char_t htitle[100];
00113   
00114   //monitor elements 
00115   
00116   //Si Strip
00117   if(dbe) {
00118     string SiStripString[19] = {"TECW1", "TECW2", "TECW3", "TECW4", "TECW5", 
00119                                 "TECW6", "TECW7", "TECW8", "TIBL1", "TIBL2", 
00120                                 "TIBL3", "TIBL4", "TIDW1", "TIDW2", "TIDW3", 
00121                                 "TOBL1", "TOBL2", "TOBL3", "TOBL4"};
00122     for(int i = 0; i<19; ++i) {
00123       mehSiStripn[i]=0;
00124       mehSiStripResX[i]=0;
00125       mehSiStripResY[i]=0;
00126     }
00127     string hcharname, hchartitle;
00128     dbe->setCurrentFolder("GlobalRecHitsV/SiStrips");
00129     for(int amend = 0; amend < 19; ++amend) { 
00130       hcharname = "hSiStripn_"+SiStripString[amend];
00131       hchartitle= SiStripString[amend]+"  rechits";
00132       sprintf(hname, hcharname.c_str());
00133       sprintf(htitle, hchartitle.c_str());
00134       mehSiStripn[amend] = dbe->book1D(hname,htitle,200,0.,200.);
00135       mehSiStripn[amend]->setAxisTitle("Number of hits in "+
00136                                        SiStripString[amend],1);
00137       mehSiStripn[amend]->setAxisTitle("Count",2);
00138       hcharname = "hSiStripResX_"+SiStripString[amend];
00139       hchartitle= SiStripString[amend]+" rechit x resolution";
00140       sprintf(hname, hcharname.c_str());
00141       sprintf(htitle, hchartitle.c_str());
00142       mehSiStripResX[amend] = dbe->book1D(hname,htitle,200,-0.02,.02);
00143       mehSiStripResX[amend]->setAxisTitle("X-resolution in "
00144                                           +SiStripString[amend],1);
00145       mehSiStripResX[amend]->setAxisTitle("Count",2);
00146       hcharname = "hSiStripResY_"+SiStripString[amend];
00147       hchartitle= SiStripString[amend]+" rechit y resolution";
00148       sprintf(hname, hcharname.c_str());
00149       sprintf(htitle, hchartitle.c_str());
00150       mehSiStripResY[amend] = dbe->book1D(hname,htitle,200,-0.02,.02);
00151       mehSiStripResY[amend]->setAxisTitle("Y-resolution in "+
00152                                           SiStripString[amend],1);
00153       mehSiStripResY[amend]->setAxisTitle("Count",2);
00154     }
00155     
00156     
00157     //HCal
00158     //string hcharname, hchartitle;
00159     string HCalString[4]={"HB", "HE", "HF", "HO"};
00160     float HCalnUpper[4]={3000.,3000.,3000.,3000.}; 
00161     float HCalnLower[4]={0.,0.,0.,0.};
00162     for(int j =0; j <4; ++j) {
00163       mehHcaln[j]=0;
00164       mehHcalRes[j]=0;
00165     }
00166     
00167     dbe->setCurrentFolder("GlobalRecHitsV/HCals");
00168     for(int amend = 0; amend < 4; ++amend) {
00169       hcharname = "hHcaln_"+HCalString[amend];
00170       hchartitle= HCalString[amend]+"  rechits";
00171       sprintf(hname, hcharname.c_str());
00172       sprintf(htitle, hchartitle.c_str());
00173       mehHcaln[amend] = dbe->book1D(hname,htitle, 1000, HCalnLower[amend], 
00174                                     HCalnUpper[amend]);
00175       mehHcaln[amend]->setAxisTitle("Number of RecHits",1);
00176       mehHcaln[amend]->setAxisTitle("Count",2);
00177       hcharname = "hHcalRes_"+HCalString[amend];
00178       hchartitle= HCalString[amend]+"  rechit resolution";
00179       sprintf(hname, hcharname.c_str());
00180       sprintf(htitle, hchartitle.c_str());
00181       mehHcalRes[amend] = dbe->book1D(hname,htitle, 25, -2., 2.);
00182       mehHcalRes[amend]->setAxisTitle("RecHit E - SimHit E",1);
00183       mehHcalRes[amend]->setAxisTitle("Count",2);
00184     }
00185     
00186     
00187     //Ecal
00188     string ECalString[3] = {"EB","EE", "ES"}; 
00189     int ECalnBins[3] = {1000,3000,150};
00190     float ECalnUpper[3] = {20000., 62000., 3000.};
00191     float ECalnLower[3] = {0., 0., 0.};
00192     int ECalResBins[3] = {200,200,200};
00193     float ECalResUpper[3] = {1., 0.3, .0002};
00194     float ECalResLower[3] = {-1., -0.3, -.0002};
00195     for(int i =0; i<3; ++i) {
00196       mehEcaln[i]=0;
00197       mehEcalRes[i]=0;
00198     }
00199     dbe->setCurrentFolder("GlobalRecHitsV/ECals");
00200     
00201     for(int amend = 0; amend < 3; ++amend) {
00202       hcharname = "hEcaln_"+ECalString[amend];
00203       hchartitle= ECalString[amend]+"  rechits";
00204       sprintf(hname, hcharname.c_str());
00205       sprintf(htitle, hchartitle.c_str());
00206       mehEcaln[amend] = dbe->book1D(hname,htitle, ECalnBins[amend], 
00207                                     ECalnLower[amend], ECalnUpper[amend]);
00208       mehEcaln[amend]->setAxisTitle("Number of RecHits",1);
00209       mehEcaln[amend]->setAxisTitle("Count",2);
00210       hcharname = "hEcalRes_"+ECalString[amend];
00211       hchartitle= ECalString[amend]+"  rechit resolution";
00212       sprintf(hname, hcharname.c_str());
00213       sprintf(htitle, hchartitle.c_str());
00214       mehEcalRes[amend] = dbe->book1D(hname,htitle,ECalResBins[amend], 
00215                                       ECalResLower[amend], 
00216                                       ECalResUpper[amend]);
00217       mehEcalRes[amend]->setAxisTitle("RecHit E - SimHit E",1);
00218       mehEcalRes[amend]->setAxisTitle("Count",2);
00219     }
00220     
00221     //Si Pixels
00222     string SiPixelString[7] = {"BRL1", "BRL2", "BRL3", "FWD1n", "FWD1p", 
00223                                "FWD2n", "FWD2p"};
00224     for(int j =0; j<7; ++j) {
00225       mehSiPixeln[j]=0;
00226       mehSiPixelResX[j]=0;
00227       mehSiPixelResY[j]=0;
00228     }
00229     
00230     dbe->setCurrentFolder("GlobalRecHitsV/SiPixels");
00231     for(int amend = 0; amend < 7; ++amend) {
00232       hcharname = "hSiPixeln_"+SiPixelString[amend];
00233       hchartitle= SiPixelString[amend]+" rechits";
00234       sprintf(hname, hcharname.c_str());
00235       sprintf(htitle, hchartitle.c_str());
00236       mehSiPixeln[amend] = dbe->book1D(hname,htitle,200,0.,200.);
00237       mehSiPixeln[amend]->setAxisTitle("Number of hits in "+
00238                                        SiPixelString[amend],1);
00239       mehSiPixeln[amend]->setAxisTitle("Count",2);
00240       hcharname = "hSiPixelResX_"+SiPixelString[amend];
00241       hchartitle= SiPixelString[amend]+" rechit x resolution";
00242       sprintf(hname, hcharname.c_str());
00243       sprintf(htitle, hchartitle.c_str());
00244       mehSiPixelResX[amend] = dbe->book1D(hname,htitle,200,-0.02,.02);
00245       mehSiPixelResX[amend]->setAxisTitle("X-resolution in "+
00246                                           SiPixelString[amend],1);
00247       mehSiPixelResX[amend]->setAxisTitle("Count",2);
00248       hcharname = "hSiPixelResY_"+SiPixelString[amend];
00249       hchartitle= SiPixelString[amend]+" rechit y resolution";
00250       
00251       sprintf(hname, hcharname.c_str());
00252       sprintf(htitle, hchartitle.c_str());
00253       mehSiPixelResY[amend] = dbe->book1D(hname,htitle,200,-0.02,.02);
00254       mehSiPixelResY[amend]->setAxisTitle("Y-resolution in "+
00255                                           SiPixelString[amend],1);
00256       mehSiPixelResY[amend]->setAxisTitle("Count",2);
00257     }
00258  
00259     //Muons 
00260     dbe->setCurrentFolder("GlobalRecHitsV/Muons");
00261     
00262     mehDtMuonn = 0;
00263     mehCSCn = 0;
00264     mehRPCn = 0;
00265     
00266     string n_List[3] = {"hDtMuonn", "hCSCn", "hRPCn"};
00267     string hist_string[3] = {"Dt", "CSC", "RPC"};
00268     
00269     for(int amend=0; amend<3; ++amend) {
00270       hchartitle = hist_string[amend]+" rechits";
00271       sprintf(hname, n_List[amend].c_str());
00272       sprintf(htitle, hchartitle.c_str());
00273       if(amend==0) {
00274         mehDtMuonn=dbe->book1D(hname,htitle,50, 0., 500.);
00275         mehDtMuonn->setAxisTitle("Number of Rechits",1);
00276         mehDtMuonn->setAxisTitle("Count",2);
00277       }
00278       if(amend==1) {
00279         mehCSCn=dbe->book1D(hname,htitle,50, 0., 500.);
00280         mehCSCn->setAxisTitle("Number of Rechits",1);
00281         mehCSCn->setAxisTitle("Count",2);
00282       }
00283       if(amend==2){
00284         mehRPCn=dbe->book1D(hname,htitle,50, 0., 500.);
00285         mehRPCn->setAxisTitle("Number of Rechits",1);
00286         mehRPCn->setAxisTitle("Count",2);
00287       }
00288     }
00289     
00290     mehDtMuonRes=0;
00291     mehCSCResRDPhi=0;
00292     mehRPCResX=0;
00293     
00294     sprintf(hname, "hDtMuonRes");
00295     sprintf(htitle, "DT wire distance resolution");
00296     mehDtMuonRes = dbe->book1D(hname, htitle, 200, -0.2, 0.2);
00297     sprintf(hname, "CSCResRDPhi");
00298     sprintf(htitle, "CSC perp*dphi resolution");
00299     mehCSCResRDPhi = dbe->book1D(hname, htitle, 200, -0.2, 0.2);
00300     sprintf(hname,"hRPCResX");
00301     sprintf(htitle, "RPC rechits x resolution");
00302     mehRPCResX = dbe->book1D(hname, htitle, 50, -5., 5.);
00303   } 
00304 }
00305 
00306 GlobalRecHitsAnalyzer::~GlobalRecHitsAnalyzer() {}
00307 
00308 void GlobalRecHitsAnalyzer::beginJob()
00309 {
00310   return;
00311 }
00312 
00313 void GlobalRecHitsAnalyzer::endJob()
00314 {
00315   std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_endJob";
00316   if (verbosity >= 0)
00317     edm::LogInfo(MsgLoggerCat) 
00318       << "Terminating having processed " << count << " events.";
00319   return;
00320 }
00321 
00322 void GlobalRecHitsAnalyzer::analyze(const edm::Event& iEvent, 
00323                                     const edm::EventSetup& iSetup)
00324 {
00325   std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_analyze";
00326   
00327   // keep track of number of events processed
00328   ++count;
00329   
00330   // get event id information
00331   int nrun = iEvent.id().run();
00332   int nevt = iEvent.id().event();
00333   
00334   if (verbosity > 0) {
00335     edm::LogInfo(MsgLoggerCat)
00336       << "Processing run " << nrun << ", event " << nevt
00337       << " (" << count << " events total)";
00338   } else if (verbosity == 0) {
00339     if (nevt%frequency == 0 || nevt == 1) {
00340       edm::LogInfo(MsgLoggerCat)
00341         << "Processing run " << nrun << ", event " << nevt
00342         << " (" << count << " events total)";
00343     }
00344   }
00345   
00346   // look at information available in the event
00347   if (getAllProvenances) {
00348     
00349     std::vector<const edm::Provenance*> AllProv;
00350     iEvent.getAllProvenance(AllProv);
00351     
00352     if (verbosity >= 0)
00353       edm::LogInfo(MsgLoggerCat)
00354         << "Number of Provenances = " << AllProv.size();
00355     
00356     if (printProvenanceInfo && (verbosity >= 0)) {
00357       TString eventout("\nProvenance info:\n");      
00358       
00359       for (unsigned int i = 0; i < AllProv.size(); ++i) {
00360         eventout += "\n       ******************************";
00361         eventout += "\n       Module       : ";
00362         eventout += AllProv[i]->moduleLabel();
00363         eventout += "\n       ProductID    : ";
00364         eventout += AllProv[i]->productID().id();
00365         eventout += "\n       ClassName    : ";
00366         eventout += AllProv[i]->className();
00367         eventout += "\n       InstanceName : ";
00368         eventout += AllProv[i]->productInstanceName();
00369         eventout += "\n       BranchName   : ";
00370         eventout += AllProv[i]->branchName();
00371       }
00372       eventout += "\n       ******************************\n";
00373       edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00374       printProvenanceInfo = false;
00375     }
00376     getAllProvenances = false;
00377   }
00378   
00379   // call fill functions
00380   // gather Ecal information from event
00381   fillECal(iEvent, iSetup);
00382   // gather Hcal information from event
00383   fillHCal(iEvent, iSetup);
00384   // gather Track information from event
00385   fillTrk(iEvent, iSetup);
00386   // gather Muon information from event
00387   fillMuon(iEvent, iSetup);
00388   
00389   if (verbosity > 0)
00390     edm::LogInfo (MsgLoggerCat)
00391       << "Done gathering data from event.";
00392   
00393   return;
00394 }
00395 
00396 void GlobalRecHitsAnalyzer::fillECal(const edm::Event& iEvent, 
00397                                      const edm::EventSetup& iSetup)
00398 {
00399   std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillECal";
00400   
00401   TString eventout;
00402   if (verbosity > 0)
00403     eventout = "\nGathering info:";  
00404   
00405   // extract crossing frame from event
00406   edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
00407   
00409   //extract EB information
00411   edm::Handle<EBUncalibratedRecHitCollection> EcalUncalibRecHitEB;
00412   iEvent.getByLabel(ECalUncalEBSrc_, EcalUncalibRecHitEB);
00413   bool validUncalibRecHitEB = true;
00414   if (!EcalUncalibRecHitEB.isValid()) {
00415     LogDebug(MsgLoggerCat)
00416       << "Unable to find EcalUncalRecHitEB in event!";
00417     validUncalibRecHitEB = false;
00418   }  
00419   
00420   edm::Handle<EBRecHitCollection> EcalRecHitEB;
00421   iEvent.getByLabel(ECalEBSrc_, EcalRecHitEB);
00422   bool validRecHitEB = true;
00423   if (!EcalRecHitEB.isValid()) {
00424     LogDebug(MsgLoggerCat)
00425       << "Unable to find EcalRecHitEB in event!";
00426     validRecHitEB = false;
00427   }  
00428 
00429   // loop over simhits
00430   const std::string barrelHitsName(hitsProducer+"EcalHitsEB");
00431   iEvent.getByLabel("mix",barrelHitsName,crossingFrame);
00432   bool validXFrame = true;
00433   if (!crossingFrame.isValid()) {
00434     LogDebug(MsgLoggerCat)
00435       << "Unable to find cal barrel crossingFrame in event!";
00436     validXFrame = false;
00437   }
00438 
00439   MapType ebSimMap;
00440   if (validXFrame) {
00441     std::auto_ptr<MixCollection<PCaloHit> >
00442       barrelHits(new MixCollection<PCaloHit>(crossingFrame.product()));  
00443     
00444     // keep track of sum of simhit energy in each crystal
00445     for (MixCollection<PCaloHit>::MixItr hitItr 
00446            = barrelHits->begin();
00447          hitItr != barrelHits->end();
00448          ++hitItr) {
00449       
00450       EBDetId ebid = EBDetId(hitItr->id());
00451       
00452       uint32_t crystid = ebid.rawId();
00453       ebSimMap[crystid] += hitItr->energy();
00454     }
00455   }  
00456 
00457   int nEBRecHits = 0;
00458   // loop over RecHits
00459   if (validUncalibRecHitEB && validRecHitEB) {
00460     const EBUncalibratedRecHitCollection *EBUncalibRecHit = 
00461       EcalUncalibRecHitEB.product();
00462     const EBRecHitCollection *EBRecHit = EcalRecHitEB.product();
00463   
00464     for (EcalUncalibratedRecHitCollection::const_iterator uncalibRecHit =
00465            EBUncalibRecHit->begin();
00466          uncalibRecHit != EBUncalibRecHit->end();
00467          ++uncalibRecHit) {
00468       
00469       EBDetId EBid = EBDetId(uncalibRecHit->id());
00470       
00471       EcalRecHitCollection::const_iterator myRecHit = EBRecHit->find(EBid);
00472       
00473       if (myRecHit != EBRecHit->end()) {
00474         ++nEBRecHits;
00475         mehEcalRes[1]->Fill(myRecHit->energy()-ebSimMap[EBid.rawId()]);
00476       }
00477     }
00478     
00479     if (verbosity > 1) {
00480       eventout += "\n          Number of EBRecHits collected:............ ";
00481       eventout += nEBRecHits;
00482     }
00483     mehEcaln[1]->Fill((float)nEBRecHits); 
00484   }
00485 
00487   //extract EE information
00489   edm::Handle<EEUncalibratedRecHitCollection> EcalUncalibRecHitEE;
00490   iEvent.getByLabel(ECalUncalEESrc_, EcalUncalibRecHitEE);
00491   bool validuncalibRecHitEE = true;
00492   if (!EcalUncalibRecHitEE.isValid()) {
00493     LogDebug(MsgLoggerCat)
00494       << "Unable to find EcalUncalRecHitEE in event!";
00495     validuncalibRecHitEE = false;
00496   }  
00497   
00498   edm::Handle<EERecHitCollection> EcalRecHitEE;
00499   iEvent.getByLabel(ECalEESrc_, EcalRecHitEE);
00500   bool validRecHitEE = true;
00501   if (!EcalRecHitEE.isValid()) {
00502     LogDebug(MsgLoggerCat)
00503       << "Unable to find EcalRecHitEE in event!";
00504     validRecHitEE = false;
00505   }  
00506   
00507   // loop over simhits
00508   const std::string endcapHitsName(hitsProducer+"EcalHitsEE");
00509   iEvent.getByLabel("mix",endcapHitsName,crossingFrame);
00510   validXFrame = true;
00511   if (!crossingFrame.isValid()) {
00512     LogDebug(MsgLoggerCat)
00513       << "Unable to find cal endcap crossingFrame in event!";
00514     validXFrame = false;
00515   }
00516 
00517   MapType eeSimMap;
00518   if (validXFrame) {
00519     std::auto_ptr<MixCollection<PCaloHit> >
00520       endcapHits(new MixCollection<PCaloHit>(crossingFrame.product()));  
00521     
00522     // keep track of sum of simhit energy in each crystal
00523     for (MixCollection<PCaloHit>::MixItr hitItr 
00524            = endcapHits->begin();
00525          hitItr != endcapHits->end();
00526          ++hitItr) {
00527       
00528       EEDetId eeid = EEDetId(hitItr->id());
00529       
00530       uint32_t crystid = eeid.rawId();
00531       eeSimMap[crystid] += hitItr->energy();
00532     }
00533   }    
00534 
00535   int nEERecHits = 0;
00536   if (validuncalibRecHitEE && validRecHitEE) {
00537     // loop over RecHits
00538     const EEUncalibratedRecHitCollection *EEUncalibRecHit = 
00539       EcalUncalibRecHitEE.product();
00540     const EERecHitCollection *EERecHit = EcalRecHitEE.product();
00541     
00542     for (EcalUncalibratedRecHitCollection::const_iterator uncalibRecHit =
00543            EEUncalibRecHit->begin();
00544          uncalibRecHit != EEUncalibRecHit->end();
00545          ++uncalibRecHit) {
00546       
00547       EEDetId EEid = EEDetId(uncalibRecHit->id());
00548       
00549       EcalRecHitCollection::const_iterator myRecHit = EERecHit->find(EEid);
00550       
00551       if (myRecHit != EERecHit->end()) {
00552         ++nEERecHits;
00553         mehEcalRes[0]->Fill(myRecHit->energy()-eeSimMap[EEid.rawId()]);
00554       }
00555     }
00556     
00557     if (verbosity > 1) {
00558       eventout += "\n          Number of EERecHits collected:............ ";
00559       eventout += nEERecHits;
00560     }
00561     mehEcaln[0]->Fill((float)nEERecHits);
00562   }    
00563 
00565   //extract ES information
00567   edm::Handle<ESRecHitCollection> EcalRecHitES;
00568   iEvent.getByLabel(ECalESSrc_, EcalRecHitES);
00569   bool validRecHitES = true;
00570   if (!EcalRecHitES.isValid()) {
00571     LogDebug(MsgLoggerCat)
00572       << "Unable to find EcalRecHitES in event!";
00573     validRecHitES = false;
00574   }  
00575 
00576   // loop over simhits
00577   const std::string preshowerHitsName(hitsProducer+"EcalHitsES");
00578   iEvent.getByLabel("mix",preshowerHitsName,crossingFrame);
00579   validXFrame = true;
00580   if (!crossingFrame.isValid()) {
00581     LogDebug(MsgLoggerCat)
00582       << "Unable to find cal preshower crossingFrame in event!";
00583     validXFrame = false;
00584   }
00585 
00586   MapType esSimMap;
00587   if (validXFrame) {
00588     std::auto_ptr<MixCollection<PCaloHit> >
00589       preshowerHits(new MixCollection<PCaloHit>(crossingFrame.product()));  
00590     
00591     // keep track of sum of simhit energy in each crystal
00592     for (MixCollection<PCaloHit>::MixItr hitItr 
00593            = preshowerHits->begin();
00594          hitItr != preshowerHits->end();
00595          ++hitItr) {
00596       
00597       ESDetId esid = ESDetId(hitItr->id());
00598       
00599       uint32_t crystid = esid.rawId();
00600       esSimMap[crystid] += hitItr->energy();
00601     }
00602   }
00603 
00604   int nESRecHits = 0;
00605   if (validRecHitES) {
00606     // loop over RecHits
00607     const ESRecHitCollection *ESRecHit = EcalRecHitES.product();
00608     for (EcalRecHitCollection::const_iterator recHit =
00609            ESRecHit->begin();
00610          recHit != ESRecHit->end();
00611          ++recHit) {
00612       
00613       ESDetId ESid = ESDetId(recHit->id());
00614       
00615       ++nESRecHits;
00616       mehEcalRes[2]->Fill(recHit->energy()-esSimMap[ESid.rawId()]);
00617     }
00618     
00619     if (verbosity > 1) {
00620       eventout += "\n          Number of ESRecHits collected:............ ";
00621       eventout += nESRecHits;
00622     }
00623     mehEcaln[2]->Fill(float(nESRecHits));
00624   }
00625 
00626   if (verbosity > 0)
00627     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00628   
00629   return;
00630 }
00631 
00632 void GlobalRecHitsAnalyzer::fillHCal(const edm::Event& iEvent, 
00633                                      const edm::EventSetup& iSetup)
00634 {
00635   std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillHCal";
00636   
00637   TString eventout;
00638   if (verbosity > 0)
00639     eventout = "\nGathering info:";  
00640   
00641   // get geometry
00642   edm::ESHandle<CaloGeometry> geometry;
00643   iSetup.get<CaloGeometryRecord>().get(geometry);
00644   if (!geometry.isValid()) {
00645     edm::LogWarning(MsgLoggerCat)
00646       << "Unable to find CaloGeometry in event!";
00647     return;
00648   }
00649   
00650   // iterator to access containers
00651   edm::PCaloHitContainer::const_iterator itHit;
00652   
00654   // extract simhit info
00656   edm::Handle<edm::PCaloHitContainer> hcalHits;
00657   iEvent.getByLabel(HCalSrc_,hcalHits);
00658   bool validhcalHits = true;
00659   if (!hcalHits.isValid()) {
00660     LogDebug(MsgLoggerCat)
00661       << "Unable to find hcalHits in event!";
00662     validhcalHits = false;
00663   }  
00664 
00665   MapType fHBEnergySimHits;
00666   MapType fHEEnergySimHits;
00667   MapType fHOEnergySimHits;
00668   MapType fHFEnergySimHits;
00669   if (validhcalHits) {
00670     const edm::PCaloHitContainer *simhitResult = hcalHits.product();
00671   
00672     for (std::vector<PCaloHit>::const_iterator simhits = simhitResult->begin();
00673          simhits != simhitResult->end();
00674          ++simhits) {
00675       
00676       HcalDetId detId(simhits->id());
00677       uint32_t cellid = detId.rawId();
00678       
00679       if (detId.subdet() == sdHcalBrl){  
00680         fHBEnergySimHits[cellid] += simhits->energy(); 
00681       }
00682       if (detId.subdet() == sdHcalEC){  
00683         fHEEnergySimHits[cellid] += simhits->energy(); 
00684       }    
00685       if (detId.subdet() == sdHcalOut){  
00686         fHOEnergySimHits[cellid] += simhits->energy(); 
00687       }    
00688       if (detId.subdet() == sdHcalFwd){  
00689         fHFEnergySimHits[cellid] += simhits->energy(); 
00690       }    
00691     }
00692   }
00693 
00694   // max values to be used (HO is found in HB)
00695   Double_t maxHBEnergy = 0.;
00696   Double_t maxHEEnergy = 0.;
00697   Double_t maxHOEnergy = 0.;
00698   Double_t maxHFEnergy = 0.;
00699   
00700   Double_t maxHBPhi = -1000.;
00701   Double_t maxHEPhi = -1000.;
00702   Double_t maxHOPhi = -1000.;
00703   Double_t maxHFPhi = -1000.;
00704   
00705   Double_t maxHBEta = -1000.;
00706   Double_t maxHEEta = -1000.;
00707   Double_t maxHOEta = -1000.;
00708   
00709   Double_t PI = 3.141592653589;
00710   
00712   // get HBHE information
00714   std::vector<edm::Handle<HBHERecHitCollection> > hbhe;
00715   iEvent.getManyByType(hbhe);
00716   bool validHBHE = true;
00717   if (!hbhe[0].isValid()) {
00718     LogDebug(MsgLoggerCat)
00719       << "Unable to find any HBHERecHitCollections in event!";
00720     validHBHE = false;
00721   } 
00722 
00723   if (validHBHE) {
00724     std::vector<edm::Handle<HBHERecHitCollection> >::iterator ihbhe;
00725     
00726     int iHB = 0;
00727     int iHE = 0; 
00728     for (ihbhe = hbhe.begin(); ihbhe != hbhe.end(); ++ihbhe) {
00729       
00730       // find max values
00731       for (HBHERecHitCollection::const_iterator jhbhe = (*ihbhe)->begin();
00732            jhbhe != (*ihbhe)->end(); ++jhbhe) {
00733         
00734         HcalDetId cell(jhbhe->id());
00735         
00736         if (cell.subdet() == sdHcalBrl) {
00737           
00738           const CaloCellGeometry* cellGeometry =
00739             geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00740           double fEta = cellGeometry->getPosition().eta () ;
00741           double fPhi = cellGeometry->getPosition().phi () ;
00742           if ( (jhbhe->energy()) > maxHBEnergy ) {
00743             maxHBEnergy = jhbhe->energy();
00744             maxHOEnergy = maxHBEnergy;
00745             maxHBPhi = fPhi;
00746             maxHOPhi = maxHBPhi;
00747             maxHBEta = fEta;
00748             maxHOEta = maxHBEta;
00749           }       
00750         }
00751       
00752         if (cell.subdet() == sdHcalEC) {
00753           
00754           const CaloCellGeometry* cellGeometry =
00755             geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00756           double fEta = cellGeometry->getPosition().eta () ;
00757           double fPhi = cellGeometry->getPosition().phi () ;
00758           if ( (jhbhe->energy()) > maxHEEnergy ) {
00759             maxHEEnergy = jhbhe->energy();
00760             maxHEPhi = fPhi;
00761             maxHEEta = fEta;
00762           }       
00763         }
00764       } // end find max values
00765       
00766       for (HBHERecHitCollection::const_iterator jhbhe = (*ihbhe)->begin();
00767            jhbhe != (*ihbhe)->end(); ++jhbhe) {
00768         
00769         HcalDetId cell(jhbhe->id());
00770         
00771         if (cell.subdet() == sdHcalBrl) {
00772           
00773           ++iHB;
00774           
00775           const CaloCellGeometry* cellGeometry =
00776             geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00777           double fPhi = cellGeometry->getPosition().phi () ;
00778           
00779           float deltaphi = maxHBPhi - fPhi;
00780           if (fPhi > maxHBPhi) { deltaphi = fPhi - maxHBPhi;}
00781           if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00782           
00783           mehHcalRes[0]->Fill(jhbhe->energy() - 
00784                               fHBEnergySimHits[cell.rawId()]);
00785         }
00786         
00787         if (cell.subdet() == sdHcalEC) {
00788           
00789           ++iHE;
00790           
00791           const CaloCellGeometry* cellGeometry =
00792             geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00793           double fPhi = cellGeometry->getPosition().phi () ;
00794           
00795           float deltaphi = maxHEPhi - fPhi;
00796           if (fPhi > maxHEPhi) { deltaphi = fPhi - maxHEPhi;}
00797           if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00798           mehHcalRes[1]->Fill(jhbhe->energy() - 
00799                               fHEEnergySimHits[cell.rawId()]);
00800         }
00801       }
00802     } // end loop through collection
00803   
00804     
00805     if (verbosity > 1) {
00806       eventout += "\n          Number of HBRecHits collected:............ ";
00807       eventout += iHB;
00808     }
00809     
00810     if (verbosity > 1) {
00811       eventout += "\n          Number of HERecHits collected:............ ";
00812       eventout += iHE;
00813     }
00814     mehHcaln[0]->Fill((float)iHB);
00815     mehHcaln[1]->Fill((float)iHE);
00816   }
00817 
00819   // get HF information
00821   std::vector<edm::Handle<HFRecHitCollection> > hf;
00822   iEvent.getManyByType(hf);
00823   bool validHF = true;
00824   if (!hf[0].isValid()) {
00825     LogDebug(MsgLoggerCat)
00826       << "Unable to find any HFRecHitCollections in event!";
00827     validHF = false;
00828   } 
00829   if (validHF) {
00830     std::vector<edm::Handle<HFRecHitCollection> >::iterator ihf;
00831     
00832     int iHF = 0; 
00833     for (ihf = hf.begin(); ihf != hf.end(); ++ihf) {
00834       
00835       // find max values
00836       for (HFRecHitCollection::const_iterator jhf = (*ihf)->begin();
00837            jhf != (*ihf)->end(); ++jhf) {
00838         
00839         HcalDetId cell(jhf->id());
00840         
00841         if (cell.subdet() == sdHcalFwd) {
00842           
00843           const CaloCellGeometry* cellGeometry =
00844             geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00845           double fPhi = cellGeometry->getPosition().phi () ;
00846           if ( (jhf->energy()) > maxHFEnergy ) {
00847             maxHFEnergy = jhf->energy();
00848             maxHFPhi = fPhi;
00849           }       
00850         }
00851       } // end find max values
00852       
00853       for (HFRecHitCollection::const_iterator jhf = (*ihf)->begin();
00854            jhf != (*ihf)->end(); ++jhf) {
00855         
00856         HcalDetId cell(jhf->id());
00857         
00858         if (cell.subdet() == sdHcalFwd) {
00859           
00860           ++iHF;
00861           
00862           const CaloCellGeometry* cellGeometry =
00863             geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00864           double fPhi = cellGeometry->getPosition().phi () ;
00865           
00866           float deltaphi = maxHBPhi - fPhi;
00867           if (fPhi > maxHFPhi) { deltaphi = fPhi - maxHFPhi;}
00868           if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00869           
00870           mehHcalRes[2]->Fill(jhf->energy()-fHFEnergySimHits[cell.rawId()]);
00871         }
00872       }
00873     } // end loop through collection
00874     
00875     if (verbosity > 1) {
00876       eventout += "\n          Number of HFDigis collected:.............. ";
00877       eventout += iHF;
00878     }
00879     mehHcaln[2]->Fill((float)iHF);
00880   }    
00881 
00883   // get HO information
00885   std::vector<edm::Handle<HORecHitCollection> > ho;
00886   iEvent.getManyByType(ho);
00887   bool validHO = true;
00888   if (!ho[0].isValid()) {
00889     LogDebug(MsgLoggerCat)
00890       << "Unable to find any HORecHitCollections in event!";
00891     validHO = false;
00892   } 
00893 
00894   if (validHO) {
00895     std::vector<edm::Handle<HORecHitCollection> >::iterator iho;
00896     
00897     int iHO = 0; 
00898     for (iho = ho.begin(); iho != ho.end(); ++iho) {
00899       
00900       for (HORecHitCollection::const_iterator jho = (*iho)->begin();
00901            jho != (*iho)->end(); ++jho) {
00902         
00903         HcalDetId cell(jho->id());
00904         
00905         if (cell.subdet() == sdHcalOut) {
00906           
00907           ++iHO;
00908           
00909           const CaloCellGeometry* cellGeometry =
00910             geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00911           double fPhi = cellGeometry->getPosition().phi () ;
00912           
00913           float deltaphi = maxHOPhi - fPhi;
00914           if (fPhi > maxHOPhi) { deltaphi = fPhi - maxHOPhi;}
00915           if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00916           mehHcalRes[3]->Fill(jho->energy()-fHOEnergySimHits[cell.rawId()]);
00917         }
00918       }
00919     } // end loop through collection
00920     
00921     if (verbosity > 1) {
00922       eventout += "\n          Number of HODigis collected:.............. ";
00923       eventout += iHO;
00924     }
00925     mehHcaln[3]->Fill((float)iHO);
00926   }
00927 
00928   if (verbosity > 0)
00929     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00930   
00931   return;
00932 }
00933 
00934 void GlobalRecHitsAnalyzer::fillTrk(const edm::Event& iEvent, 
00935                                     const edm::EventSetup& iSetup)
00936 {
00937   std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillTrk";
00938   
00939   TString eventout;
00940   if (verbosity > 0)
00941     eventout = "\nGathering info:";  
00942   
00943   // get strip information
00944   edm::Handle<SiStripMatchedRecHit2DCollection> rechitsmatched;
00945   iEvent.getByLabel(SiStripSrc_, rechitsmatched);
00946   bool validstrip = true;
00947   if (!rechitsmatched.isValid()) {
00948     LogDebug(MsgLoggerCat)
00949       << "Unable to find stripmatchedrechits in event!";
00950     validstrip = false;
00951   }  
00952   
00953   TrackerHitAssociator associate(iEvent,conf_);
00954   
00955   edm::ESHandle<TrackerGeometry> pDD;
00956   iSetup.get<TrackerDigiGeometryRecord>().get(pDD);
00957   if (!pDD.isValid()) {
00958     edm::LogWarning(MsgLoggerCat)
00959       << "Unable to find TrackerDigiGeometry in event!";
00960     return;
00961   }
00962   const TrackerGeometry &tracker(*pDD);
00963   
00964   if (validstrip) {
00965     int nStripBrl = 0, nStripFwd = 0;
00966     
00967     // loop over det units
00968     for (TrackerGeometry::DetContainer::const_iterator it = 
00969            pDD->dets().begin();
00970          it != pDD->dets().end(); ++it) {
00971       
00972       uint32_t myid = ((*it)->geographicalId()).rawId();
00973       DetId detid = ((*it)->geographicalId());
00974       
00975       //loop over rechits-matched in the same subdetector
00976       SiStripMatchedRecHit2DCollection::const_iterator rechitmatchedMatch = rechitsmatched->find(detid);
00977       
00978       if (rechitmatchedMatch != rechitsmatched->end()) {
00979         SiStripMatchedRecHit2DCollection::DetSet rechitmatchedRange = *rechitmatchedMatch;
00980         SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitmatchedRangeIteratorBegin = rechitmatchedRange.begin();
00981         SiStripMatchedRecHit2DCollection::DetSet::const_iterator rechitmatchedRangeIteratorEnd   = rechitmatchedRange.end();
00982         SiStripMatchedRecHit2DCollection::DetSet::const_iterator itermatched = rechitmatchedRangeIteratorBegin;
00983         
00984         for ( itermatched = rechitmatchedRangeIteratorBegin; 
00985               itermatched != rechitmatchedRangeIteratorEnd;
00986               ++itermatched) {
00987           
00988           SiStripMatchedRecHit2D const rechit = *itermatched;
00989           LocalPoint position = rechit.localPosition();
00990           
00991           float mindist = 999999.;
00992           float distx = 999999.;
00993           float disty = 999999.;
00994           float dist = 999999.;
00995           std::pair<LocalPoint,LocalVector> closestPair;
00996           matched.clear();
00997           
00998           float rechitmatchedx = position.x();
00999           float rechitmatchedy = position.y();
01000           
01001           matched = associate.associateHit(rechit);
01002           
01003           if (!matched.empty()) {
01004             //project simhit;
01005             const GluedGeomDet* gluedDet = 
01006               (const GluedGeomDet*)tracker.idToDet(rechit.geographicalId());
01007             const StripGeomDetUnit* partnerstripdet =
01008               (StripGeomDetUnit*) gluedDet->stereoDet();
01009             std::pair<LocalPoint,LocalVector> hitPair;
01010             
01011             for(std::vector<PSimHit>::const_iterator m = matched.begin(); 
01012                 m != matched.end(); m++){
01013               //project simhit;
01014               hitPair = projectHit((*m),partnerstripdet,gluedDet->surface());
01015               distx = fabs(rechitmatchedx - hitPair.first.x());
01016               disty = fabs(rechitmatchedy - hitPair.first.y());
01017               dist = sqrt(distx*distx+disty*disty);
01018               
01019               if(dist < mindist){
01020                 mindist = dist;
01021                 closestPair = hitPair;
01022               }
01023             }
01024             
01025             // get TIB
01026             if (detid.subdetId() == sdSiTIB) {
01027               
01028               TIBDetId tibid(myid);
01029               ++nStripBrl;
01030               
01031               if (tibid.layer() == 1) {
01032                 mehSiStripResX[8]->Fill(rechitmatchedx-closestPair.first.x());
01033                 mehSiStripResY[8]->Fill(rechitmatchedy-closestPair.first.y());
01034               }
01035               if (tibid.layer() == 2) {
01036                 mehSiStripResX[9]->Fill(rechitmatchedx-closestPair.first.x());
01037                 mehSiStripResY[9]->Fill(rechitmatchedy-closestPair.first.y());
01038               } 
01039               if (tibid.layer() == 3) {
01040                 mehSiStripResX[10]->Fill(rechitmatchedx-closestPair.first.x());
01041                 mehSiStripResY[10]->Fill(rechitmatchedy-closestPair.first.y());
01042                 
01043               }
01044               if (tibid.layer() == 4) {
01045                 mehSiStripResX[11]->Fill(rechitmatchedx-closestPair.first.x());
01046                 mehSiStripResY[11]->Fill(rechitmatchedy-closestPair.first.y());
01047               }
01048             }
01049             
01050             // get TOB
01051             if (detid.subdetId() == sdSiTOB) {
01052               
01053               TOBDetId tobid(myid);
01054               ++nStripBrl;
01055               
01056               if (tobid.layer() == 1) {
01057                 mehSiStripResX[15]->Fill(rechitmatchedx-closestPair.first.x());
01058                 mehSiStripResY[15]->Fill(rechitmatchedy-closestPair.first.y());
01059               }
01060               if (tobid.layer() == 2) {
01061                 mehSiStripResX[16]->Fill(rechitmatchedx-closestPair.first.x());
01062                 mehSiStripResY[16]->Fill(rechitmatchedy-closestPair.first.y());
01063               } 
01064               if (tobid.layer() == 3) {
01065                 mehSiStripResX[17]->Fill(rechitmatchedx-closestPair.first.x());
01066                 mehSiStripResY[17]->Fill(rechitmatchedy-closestPair.first.y());
01067               }
01068               if (tobid.layer() == 4) {
01069                 mehSiStripResX[18]->Fill(rechitmatchedx-closestPair.first.x());
01070                 mehSiStripResY[18]->Fill(rechitmatchedy-closestPair.first.y());
01071               }
01072             }
01073             
01074             // get TID
01075             if (detid.subdetId() == sdSiTID) {
01076               
01077               TIDDetId tidid(myid);
01078               ++nStripFwd;
01079               
01080               if (tidid.wheel() == 1) {
01081                 mehSiStripResX[12]->Fill(rechitmatchedx-closestPair.first.x());
01082                 mehSiStripResY[12]->Fill(rechitmatchedy-closestPair.first.y());
01083               }
01084               if (tidid.wheel() == 2) {
01085                 mehSiStripResX[13]->Fill(rechitmatchedx-closestPair.first.x());
01086                 mehSiStripResY[13]->Fill(rechitmatchedy-closestPair.first.y());
01087               } 
01088               if (tidid.wheel() == 3) {
01089                 mehSiStripResX[14]->Fill(rechitmatchedx-closestPair.first.x());
01090                 mehSiStripResY[14]->Fill(rechitmatchedy-closestPair.first.y());
01091               }
01092             }
01093             
01094             // get TEC
01095             if (detid.subdetId() == sdSiTEC) {
01096               
01097               TECDetId tecid(myid);
01098               ++nStripFwd;
01099               
01100               if (tecid.wheel() == 1) {
01101                 mehSiStripResX[0]->Fill(rechitmatchedx-closestPair.first.x());
01102                 mehSiStripResY[0]->Fill(rechitmatchedy-closestPair.first.y());
01103               }
01104               if (tecid.wheel() == 2) {
01105                 mehSiStripResX[1]->Fill(rechitmatchedx-closestPair.first.x());
01106                 mehSiStripResY[1]->Fill(rechitmatchedy-closestPair.first.y());
01107               } 
01108               if (tecid.wheel() == 3) {
01109                 mehSiStripResX[2]->Fill(rechitmatchedx-closestPair.first.x());
01110                 mehSiStripResY[2]->Fill(rechitmatchedy-closestPair.first.y());
01111               }
01112               if (tecid.wheel() == 4) {
01113                 mehSiStripResX[3]->Fill(rechitmatchedx-closestPair.first.x());
01114                 mehSiStripResY[3]->Fill(rechitmatchedy-closestPair.first.y());
01115                 
01116               }
01117               if (tecid.wheel() == 5) {
01118                 mehSiStripResX[4]->Fill(rechitmatchedx-closestPair.first.x());
01119                 mehSiStripResY[4]->Fill(rechitmatchedy-closestPair.first.y());
01120               } 
01121               if (tecid.wheel() == 6) {
01122                 mehSiStripResX[5]->Fill(rechitmatchedx-closestPair.first.x());
01123                 mehSiStripResY[5]->Fill(rechitmatchedy-closestPair.first.y());
01124               }
01125               if (tecid.wheel() == 7) {
01126                 mehSiStripResX[6]->Fill(rechitmatchedx-closestPair.first.x());
01127                 mehSiStripResY[6]->Fill(rechitmatchedy-closestPair.first.y());
01128               } 
01129               if (tecid.wheel() == 8) {
01130                 mehSiStripResX[7]->Fill(rechitmatchedx-closestPair.first.x());
01131                 mehSiStripResY[7]->Fill(rechitmatchedy-closestPair.first.y()); 
01132               }
01133             }
01134             
01135           } // end if matched empty
01136         }
01137       }
01138     } // end loop over det units
01139                                                                       
01140     if (verbosity > 1) {
01141       eventout += "\n          Number of BrlStripRecHits collected:...... ";
01142       eventout += nStripBrl;
01143     }
01144     
01145     for(int i =8; i<12; ++i)
01146       {mehSiStripn[i]->Fill((float)nStripBrl);}
01147     for(int i =16; i<19; ++i)
01148       {mehSiStripn[i]->Fill((float)nStripBrl);}
01149     
01150     if (verbosity > 1) {
01151       eventout += "\n          Number of FrwdStripRecHits collected:..... ";
01152       eventout += nStripFwd;
01153     }
01154     for(int i =0; i<8; ++i)
01155       {mehSiStripn[i]->Fill((float)nStripFwd);}
01156     for(int i =12; i<16; ++i)
01157       {mehSiStripn[i]->Fill((float)nStripFwd);}
01158   }
01159 
01160   // get pixel information
01161   //Get RecHits
01162   edm::Handle<SiPixelRecHitCollection> recHitColl;
01163   iEvent.getByLabel(SiPxlSrc_, recHitColl);
01164   bool validpixel = true;
01165   if (!recHitColl.isValid()) {
01166     LogDebug(MsgLoggerCat)
01167       << "Unable to find SiPixelRecHitCollection in event!";
01168     validpixel = false;
01169   }  
01170   
01171   //Get event setup
01172   edm::ESHandle<TrackerGeometry> geom;
01173   iSetup.get<TrackerDigiGeometryRecord>().get(geom); 
01174   if (!geom.isValid()) {
01175     edm::LogWarning(MsgLoggerCat)
01176       << "Unable to find TrackerDigiGeometry in event!";
01177     return;
01178   }
01179 
01180   if (validpixel) {
01181     int nPxlBrl = 0, nPxlFwd = 0;    
01182     //iterate over detunits
01183     for (TrackerGeometry::DetContainer::const_iterator it = 
01184            geom->dets().begin();
01185          it != geom->dets().end(); ++it) {
01186       
01187       uint32_t myid = ((*it)->geographicalId()).rawId();
01188       DetId detId = ((*it)->geographicalId());
01189       int subid = detId.subdetId();
01190       
01191       if (! ((subid == sdPxlBrl) || (subid == sdPxlFwd))) continue;
01192       
01193       SiPixelRecHitCollection::const_iterator pixeldet = recHitColl->find(detId);
01194       if (pixeldet == recHitColl->end()) continue;
01195       SiPixelRecHitCollection::DetSet pixelrechitRange = *pixeldet;
01196       SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorBegin = pixelrechitRange.begin();
01197       SiPixelRecHitCollection::DetSet::const_iterator pixelrechitRangeIteratorEnd   = pixelrechitRange.end();
01198       SiPixelRecHitCollection::DetSet::const_iterator pixeliter = pixelrechitRangeIteratorBegin;
01199 
01200       
01201       std::vector<PSimHit> matched;
01202       
01203       //----Loop over rechits for this detId
01204       for ( ; pixeliter != pixelrechitRangeIteratorEnd; ++pixeliter) {
01205         
01206         matched.clear();
01207         matched = associate.associateHit(*pixeliter);
01208         
01209         if ( !matched.empty() ) {
01210           
01211           float closest = 9999.9;
01212           LocalPoint lp = pixeliter->localPosition();
01213           float rechit_x = lp.x();
01214           float rechit_y = lp.y();
01215           
01216           float sim_x = 0.;
01217           float sim_y = 0.;
01218           
01219           //loop over sim hits and fill closet
01220           for (std::vector<PSimHit>::const_iterator m = matched.begin(); 
01221                m != matched.end(); ++m) {
01222             
01223             float sim_x1 = (*m).entryPoint().x();
01224             float sim_x2 = (*m).exitPoint().x();
01225             float sim_xpos = 0.5*(sim_x1+sim_x2);
01226             
01227             float sim_y1 = (*m).entryPoint().y();
01228             float sim_y2 = (*m).exitPoint().y();
01229             float sim_ypos = 0.5*(sim_y1+sim_y2);
01230             
01231             float x_res = fabs(sim_xpos - rechit_x);
01232             float y_res = fabs(sim_ypos - rechit_y);
01233             
01234             float dist = sqrt(x_res*x_res + y_res*y_res);
01235             
01236             if ( dist < closest ) {
01237               closest = dist;
01238               sim_x = sim_xpos;
01239               sim_y = sim_ypos;
01240             }
01241           } // end sim hit loop
01242           
01243           // get Barrel pixels ***************Pixel STuff******************
01244           if (subid == sdPxlBrl) {
01245             PXBDetId bdetid(myid);
01246             ++nPxlBrl;
01247             
01248             if (bdetid.layer() == 1) {
01249               mehSiPixelResX[0]->Fill(rechit_x-sim_x);
01250               mehSiPixelResY[0]->Fill(rechit_y-sim_y); 
01251               
01252             }
01253             if (bdetid.layer() == 2) {
01254               mehSiPixelResX[1]->Fill(rechit_x-sim_x);
01255               mehSiPixelResY[1]->Fill(rechit_y-sim_y); 
01256             }
01257             if (bdetid.layer() == 3) {
01258               mehSiPixelResX[2]->Fill(rechit_x-sim_x);
01259               mehSiPixelResY[2]->Fill(rechit_y-sim_y); 
01260             }
01261           }
01262           
01263           // get Forward pixels
01264           if (subid == sdPxlFwd) {
01265             PXFDetId fdetid(myid);
01266             ++nPxlFwd;
01267             
01268             if (fdetid.disk() == 1) {
01269               if (fdetid.side() == 1) {
01270                 mehSiPixelResX[3]->Fill(rechit_x-sim_x);
01271                 mehSiPixelResY[3]->Fill(rechit_y-sim_y);
01272               }
01273               if (fdetid.side() == 2) {
01274                 mehSiPixelResX[4]->Fill(rechit_x-sim_x);
01275                 mehSiPixelResY[4]->Fill(rechit_y-sim_y); 
01276               }
01277             }
01278             if (fdetid.disk() == 2) {
01279               if (fdetid.side() == 1) {
01280                 mehSiPixelResX[5]->Fill(rechit_x-sim_x);
01281                 mehSiPixelResY[5]->Fill(rechit_y-sim_y);
01282               }
01283               if (fdetid.side() == 2) {
01284                 mehSiPixelResX[6]->Fill(rechit_x-sim_x);
01285                 mehSiPixelResY[6]->Fill(rechit_y-sim_y); 
01286               }
01287             }
01288           }      
01289         } // end matched emtpy
01290       } // <-----end rechit loop 
01291     } // <------ end detunit loop  
01292     
01293     
01294     if (verbosity > 1) {
01295       eventout += "\n          Number of BrlPixelRecHits collected:...... ";
01296       eventout += nPxlBrl;
01297     }
01298     for(int i=0; i<3; ++i) {
01299       mehSiPixeln[i]->Fill((float)nPxlBrl);
01300     }
01301     
01302     if (verbosity > 1) {
01303       eventout += "\n          Number of FrwdPixelRecHits collected:..... ";
01304       eventout += nPxlFwd;
01305     }
01306     
01307     for(int i=3; i<7; ++i) {
01308       mehSiPixeln[i]->Fill((float)nPxlFwd);
01309     }
01310   }
01311    
01312   if (verbosity > 0)
01313     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01314   
01315   return;
01316 }
01317 
01318 void GlobalRecHitsAnalyzer::fillMuon(const edm::Event& iEvent, 
01319                                      const edm::EventSetup& iSetup)
01320 {
01321   std::string MsgLoggerCat = "GlobalRecHitsAnalyzer_fillMuon";
01322   
01323   TString eventout;
01324   if (verbosity > 0)
01325     eventout = "\nGathering info:";  
01326 
01327   // get DT information
01328   edm::ESHandle<DTGeometry> dtGeom;
01329   iSetup.get<MuonGeometryRecord>().get(dtGeom);
01330   if (!dtGeom.isValid()) {
01331     edm::LogWarning(MsgLoggerCat)
01332       << "Unable to find DTMuonGeometryRecord in event!";
01333     return;
01334   }  
01335 
01336   edm::Handle<edm::PSimHitContainer> dtsimHits;
01337   iEvent.getByLabel(MuDTSimSrc_, dtsimHits);
01338   bool validdtsim = true;
01339   if (!dtsimHits.isValid()) {
01340     LogDebug(MsgLoggerCat)
01341       << "Unable to find dtsimHits in event!";
01342     validdtsim = false;
01343   } 
01344 
01345   edm::Handle<DTRecHitCollection> dtRecHits;
01346   iEvent.getByLabel(MuDTSrc_, dtRecHits);
01347   bool validdtrec = true;
01348   if (!dtRecHits.isValid()) {
01349     LogDebug(MsgLoggerCat)
01350       << "Unable to find dtRecHits in event!";
01351     validdtrec = false;
01352   }   
01353     
01354   if (validdtsim && validdtrec) {
01355 
01356     std::map<DTWireId, edm::PSimHitContainer> simHitsPerWire =
01357       DTHitQualityUtils::mapSimHitsPerWire(*(dtsimHits.product()));
01358 
01359     std::map<DTWireId, std::vector<DTRecHit1DPair> > recHitsPerWire =
01360       map1DRecHitsPerWire(dtRecHits.product());
01361 
01362     int nDt = compute(dtGeom.product(), simHitsPerWire, recHitsPerWire, 1);
01363     
01364     if (verbosity > 1) {
01365       eventout += "\n          Number of DtMuonRecHits collected:........ ";
01366       eventout += nDt;
01367     }
01368     mehDtMuonn->Fill(float(nDt));
01369   }
01370 
01371   // get CSC Strip information
01372   // get map of sim hits
01373   theMap.clear();
01374   edm::Handle<CrossingFrame<PSimHit> > cf;
01375 
01376   iEvent.getByLabel("mix",hitsProducer+"MuonCSCHits",cf);
01377   bool validXFrame = true;
01378   if (!cf.isValid()) {
01379     LogDebug(MsgLoggerCat)
01380       << "Unable to find muo CSC crossingFrame in event!";
01381     validXFrame = false;
01382   }
01383   if (validXFrame) {
01384     MixCollection<PSimHit> simHits(cf.product());
01385     
01386     // arrange the hits by detUnit
01387     for(MixCollection<PSimHit>::MixItr hitItr = simHits.begin();
01388         hitItr != simHits.end(); ++hitItr) {
01389       theMap[hitItr->detUnitId()].push_back(*hitItr);
01390     }  
01391   }
01392 
01393   // get geometry
01394   edm::ESHandle<CSCGeometry> hGeom;
01395   iSetup.get<MuonGeometryRecord>().get(hGeom);
01396   if (!hGeom.isValid()) {
01397     edm::LogWarning(MsgLoggerCat)
01398       << "Unable to find CSCMuonGeometryRecord in event!";
01399     return;
01400   }    
01401   const CSCGeometry *theCSCGeometry = &*hGeom;
01402 
01403   // get rechits
01404   edm::Handle<CSCRecHit2DCollection> hRecHits;
01405   iEvent.getByLabel(MuCSCSrc_, hRecHits);
01406   bool validCSC = true;
01407   if (!hRecHits.isValid()) {
01408     LogDebug(MsgLoggerCat)
01409       << "Unable to find CSC RecHits in event!";
01410     validCSC = false;
01411   }    
01412 
01413   if (validCSC) {
01414     const CSCRecHit2DCollection *cscRecHits = hRecHits.product();
01415     
01416     int nCSC = 0;
01417     for (CSCRecHit2DCollection::const_iterator recHitItr = cscRecHits->begin();
01418          recHitItr != cscRecHits->end(); ++recHitItr) {
01419       
01420       int detId = (*recHitItr).cscDetId().rawId();
01421       
01422       edm::PSimHitContainer simHits;   
01423       std::map<int, edm::PSimHitContainer>::const_iterator mapItr = 
01424         theMap.find(detId);
01425       if (mapItr != theMap.end()) {
01426         simHits = mapItr->second;
01427       }
01428       
01429       if (simHits.size() == 1) {
01430         ++nCSC;
01431         
01432         const GeomDetUnit* detUnit = 
01433           theCSCGeometry->idToDetUnit(CSCDetId(detId));
01434         const CSCLayer *layer = dynamic_cast<const CSCLayer *>(detUnit); 
01435         
01436         int chamberType = layer->chamber()->specs()->chamberType();
01437         plotResolution(simHits[0], *recHitItr, layer, chamberType);
01438       }
01439     }
01440     
01441     if (verbosity > 1) {
01442       eventout += "\n          Number of CSCRecHits collected:........... ";
01443       eventout += nCSC;
01444     }
01445     mehCSCn->Fill((float)nCSC);
01446   }
01447 
01448   // get RPC information
01449   std::map<double, int> mapsim, maprec;
01450   std::map<int, double> nmapsim, nmaprec;
01451 
01452   edm::ESHandle<RPCGeometry> rpcGeom;
01453   iSetup.get<MuonGeometryRecord>().get(rpcGeom);
01454   if (!rpcGeom.isValid()) {
01455     edm::LogWarning(MsgLoggerCat)
01456       << "Unable to find RPCMuonGeometryRecord in event!";
01457     return;
01458   }  
01459 
01460   edm::Handle<edm::PSimHitContainer> simHit;
01461   iEvent.getByLabel(MuRPCSimSrc_, simHit);
01462   bool validrpcsim = true;
01463   if (!simHit.isValid()) {
01464     LogDebug(MsgLoggerCat)
01465       << "Unable to find RPCSimHit in event!";
01466     validrpcsim = false;
01467   }    
01468 
01469   edm::Handle<RPCRecHitCollection> recHit;
01470   iEvent.getByLabel(MuRPCSrc_, recHit);
01471   bool validrpc = true;
01472   if (!simHit.isValid()) {
01473     LogDebug(MsgLoggerCat)
01474       << "Unable to find RPCRecHit in event!";
01475     validrpc = false;
01476   } 
01477 
01478   if (validrpc) {
01479     int nRPC = 0;
01480     RPCRecHitCollection::const_iterator recIt;
01481     int nrec = 0;
01482     for (recIt = recHit->begin(); recIt != recHit->end(); ++recIt) {
01483       RPCDetId Rid = (RPCDetId)(*recIt).rpcId();
01484       const RPCRoll *roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(Rid));
01485       if (roll->isForward()) {
01486         
01487         if (verbosity > 1) {
01488           eventout += 
01489             "\n          Number of RPCRecHits collected:........... ";
01490           eventout += nRPC;
01491         }
01492         
01493         if (verbosity > 0)
01494           edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01495         return;
01496       }
01497       nrec = nrec + 1;
01498       LocalPoint rhitlocal = (*recIt).localPosition();
01499       double rhitlocalx = rhitlocal.x();
01500       maprec[rhitlocalx] = nrec; 
01501     }
01502     
01503     int i = 0;
01504     for (std::map<double,int>::iterator iter = maprec.begin();
01505          iter != maprec.end(); ++iter) {
01506       i = i + 1;
01507       nmaprec[i] = (*iter).first;
01508     }
01509     
01510     int nsim = 0;
01511     if (validrpcsim) {
01512       edm::PSimHitContainer::const_iterator simIt;
01513       for (simIt = simHit->begin(); simIt != simHit->end(); simIt++) {
01514         int ptype = (*simIt).particleType();
01515         if (ptype == 13 || ptype == -13) {
01516           nsim = nsim + 1;
01517           LocalPoint shitlocal = (*simIt).localPosition();
01518           double shitlocalx = shitlocal.x();
01519           mapsim[shitlocalx] = nsim;
01520         }
01521       }
01522       
01523       i = 0;
01524       for (std::map<double,int>::iterator iter = mapsim.begin();
01525            iter != mapsim.end(); ++iter) {
01526         i = i + 1;
01527         nmapsim[i] = (*iter).first;
01528       }
01529     }
01530 
01531     if (nsim == nrec) {
01532       for (int r = 0; r < nsim; r++) {
01533         ++nRPC;
01534         mehRPCResX->Fill(nmaprec[r+1]-nmapsim[r+1]);
01535       }
01536     }
01537                                                                   
01538     if (verbosity > 1) {
01539       eventout += "\n          Number of RPCRecHits collected:........... ";
01540       eventout += nRPC;
01541     }
01542     mehRPCn->Fill((float)nRPC);
01543   }
01544 
01545   if (verbosity > 0)
01546     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01547   
01548   return;
01549 }
01550 
01551 //needed by to do the residual for matched hits in SiStrip
01552 std::pair<LocalPoint,LocalVector> 
01553 GlobalRecHitsAnalyzer::projectHit(const PSimHit& hit, 
01554                                   const StripGeomDetUnit* stripDet,
01555                                   const BoundPlane& plane) 
01556 {
01557   
01558   const StripTopology& topol = stripDet->specificTopology();
01559   GlobalPoint globalpos= stripDet->surface().toGlobal(hit.localPosition());
01560   LocalPoint localHit = plane.toLocal(globalpos);
01561   //track direction
01562   LocalVector locdir=hit.localDirection();
01563   //rotate track in new frame
01564   
01565   GlobalVector globaldir= stripDet->surface().toGlobal(locdir);
01566   LocalVector dir=plane.toLocal(globaldir);
01567   float scale = -localHit.z() / dir.z();
01568   
01569   LocalPoint projectedPos = localHit + scale*dir;
01570     
01571   float selfAngle = topol.stripAngle( topol.strip( hit.localPosition()));
01572 
01573   // vector along strip in hit frame 
01574   LocalVector stripDir( sin(selfAngle), cos(selfAngle), 0); 
01575   
01576   LocalVector 
01577     localStripDir(plane.toLocal(stripDet->surface().toGlobal(stripDir)));
01578   
01579   return std::pair<LocalPoint,LocalVector>( projectedPos, localStripDir);
01580 }
01581 
01582 // Return a map between DTRecHit1DPair and wireId
01583 std::map<DTWireId, std::vector<DTRecHit1DPair> >
01584 GlobalRecHitsAnalyzer::map1DRecHitsPerWire(const DTRecHitCollection* 
01585                                            dt1DRecHitPairs) {
01586   std::map<DTWireId, std::vector<DTRecHit1DPair> > ret;
01587   
01588   for(DTRecHitCollection::const_iterator rechit = dt1DRecHitPairs->begin();
01589       rechit != dt1DRecHitPairs->end(); rechit++) {
01590     ret[(*rechit).wireId()].push_back(*rechit);
01591   }
01592   
01593   return ret;
01594 }
01595 
01596 // Compute SimHit distance from wire (cm)
01597 float GlobalRecHitsAnalyzer::simHitDistFromWire(const DTLayer* layer,
01598                                                 DTWireId wireId,
01599                                                 const PSimHit& hit) {
01600   float xwire = layer->specificTopology().wirePosition(wireId.wire());
01601   LocalPoint entryP = hit.entryPoint();
01602   LocalPoint exitP = hit.exitPoint();
01603   float xEntry = entryP.x()-xwire;
01604   float xExit  = exitP.x()-xwire;
01605 
01606   //FIXME: check...  
01607   return fabs(xEntry - (entryP.z()*(xExit-xEntry))/(exitP.z()-entryP.z()));
01608 }
01609 
01610 // Find the RecHit closest to the muon SimHit
01611 template  <typename type>
01612 const type* 
01613 GlobalRecHitsAnalyzer::findBestRecHit(const DTLayer* layer,
01614                                       DTWireId wireId,
01615                                       const std::vector<type>& recHits,
01616                                       const float simHitDist) {
01617   float res = 99999;
01618   const type* theBestRecHit = 0;
01619   // Loop over RecHits within the cell
01620   for(typename std::vector<type>::const_iterator recHit = recHits.begin();
01621       recHit != recHits.end();
01622       recHit++) {
01623     float distTmp = recHitDistFromWire(*recHit, layer);
01624     if(fabs(distTmp-simHitDist) < res) {
01625       res = fabs(distTmp-simHitDist);
01626       theBestRecHit = &(*recHit);
01627     }
01628   } // End of loop over RecHits within the cell
01629   
01630   return theBestRecHit;
01631 }
01632 
01633 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
01634 float 
01635 GlobalRecHitsAnalyzer::recHitDistFromWire(const DTRecHit1DPair& hitPair, 
01636                                           const DTLayer* layer) {
01637   // Compute the rechit distance from wire
01638   return fabs(hitPair.localPosition(DTEnums::Left).x() -
01639               hitPair.localPosition(DTEnums::Right).x())/2.;
01640 }
01641 
01642 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
01643 float 
01644 GlobalRecHitsAnalyzer::recHitDistFromWire(const DTRecHit1D& recHit, 
01645                                           const DTLayer* layer) {
01646   return fabs(recHit.localPosition().x() - 
01647               layer->specificTopology().wirePosition(recHit.wireId().wire()));
01648 }
01649 
01650 template  <typename type>
01651 int GlobalRecHitsAnalyzer::compute(const DTGeometry *dtGeom,
01652                                    std::map<DTWireId, std::vector<PSimHit> > 
01653                                    simHitsPerWire,
01654                                    std::map<DTWireId, std::vector<type> > 
01655                                    recHitsPerWire,
01656                                    int step) {
01657 
01658   int nDt = 0;
01659   // Loop over cells with a muon SimHit
01660   for(std::map<DTWireId, std::vector<PSimHit> >::const_iterator wireAndSHits = 
01661         simHitsPerWire.begin();
01662       wireAndSHits != simHitsPerWire.end();
01663       wireAndSHits++) {
01664     DTWireId wireId = (*wireAndSHits).first;
01665     std::vector<PSimHit> simHitsInCell = (*wireAndSHits).second;
01666     
01667     // Get the layer
01668     const DTLayer* layer = dtGeom->layer(wireId);
01669     
01670     // Look for a mu hit in the cell
01671     const PSimHit* muSimHit = DTHitQualityUtils::findMuSimHit(simHitsInCell);
01672     if (muSimHit==0) {
01673       continue; // Skip this cell
01674     }
01675 
01676     // Find the distance of the simhit from the wire
01677     float simHitWireDist = simHitDistFromWire(layer, wireId, *muSimHit);
01678     // Skip simhits out of the cell
01679     if(simHitWireDist>2.1) {
01680       continue; // Skip this cell
01681     }
01682 
01683     // Look for RecHits in the same cell
01684     if(recHitsPerWire.find(wireId) == recHitsPerWire.end()) {
01685       continue; // No RecHit found in this cell
01686     } else {
01687 
01688       std::vector<type> recHits = recHitsPerWire[wireId];
01689          
01690       // Find the best RecHit
01691       const type* theBestRecHit = 
01692         findBestRecHit(layer, wireId, recHits, simHitWireDist);
01693  
01694       float recHitWireDist =  recHitDistFromWire(*theBestRecHit, layer);
01695       
01696       ++nDt;
01697 
01698       mehDtMuonRes->Fill(recHitWireDist-simHitWireDist);
01699       
01700     } // find rechits
01701   } // loop over simhits
01702 
01703   return nDt;
01704 }
01705 
01706 void 
01707 GlobalRecHitsAnalyzer::plotResolution(const PSimHit & simHit, 
01708                                       const CSCRecHit2D & recHit,
01709                                       const CSCLayer * layer, 
01710                                       int chamberType) {
01711   GlobalPoint simHitPos = layer->toGlobal(simHit.localPosition());
01712   GlobalPoint recHitPos = layer->toGlobal(recHit.localPosition());
01713   
01714   mehCSCResRDPhi->Fill(recHitPos.phi()-simHitPos.phi());
01715 }
01716