CMS 3D CMS Logo

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