CMS 3D CMS Logo

GlobalRecHitsProducer.cc

Go to the documentation of this file.
00001 
00010 #include "Validation/GlobalRecHits/interface/GlobalRecHitsProducer.h"
00011 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00012 
00013 GlobalRecHitsProducer::GlobalRecHitsProducer(const edm::ParameterSet& iPSet) :
00014   fName(""), verbosity(0), frequency(0), label(""), getAllProvenances(false),
00015   printProvenanceInfo(false), count(0)
00016 {
00017   std::string MsgLoggerCat = "GlobalRecHitsProducer_GlobalRecHitsProducer";
00018 
00019   // get information from parameter set
00020   fName = iPSet.getUntrackedParameter<std::string>("Name");
00021   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
00022   frequency = iPSet.getUntrackedParameter<int>("Frequency");
00023   label = iPSet.getParameter<std::string>("Label");
00024   edm::ParameterSet m_Prov =
00025     iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
00026   getAllProvenances = 
00027     m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
00028   printProvenanceInfo = 
00029     m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
00030 
00031   //get Labels to use to extract information
00032   ECalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalEBSrc");
00033   ECalUncalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalUncalEBSrc");
00034   ECalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalEESrc");
00035   ECalUncalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalUncalEESrc");
00036   ECalESSrc_ = iPSet.getParameter<edm::InputTag>("ECalESSrc");
00037   HCalSrc_ = iPSet.getParameter<edm::InputTag>("HCalSrc");
00038   SiStripSrc_ = iPSet.getParameter<edm::InputTag>("SiStripSrc"); 
00039   SiPxlSrc_ = iPSet.getParameter<edm::InputTag>("SiPxlSrc");
00040   MuDTSrc_ = iPSet.getParameter<edm::InputTag>("MuDTSrc");
00041   MuDTSimSrc_ = iPSet.getParameter<edm::InputTag>("MuDTSimSrc");
00042   MuCSCSrc_ = iPSet.getParameter<edm::InputTag>("MuCSCSrc");
00043   MuRPCSrc_ = iPSet.getParameter<edm::InputTag>("MuRPCSrc");
00044   MuRPCSimSrc_ = iPSet.getParameter<edm::InputTag>("MuRPCSimSrc");
00045 
00046   conf_ = iPSet;
00047 
00048   // use value of first digit to determine default output level (inclusive)
00049   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
00050   verbosity %= 10;
00051 
00052   // create persistent object
00053   produces<PGlobalRecHit>(label);
00054 
00055   // print out Parameter Set information being used
00056   if (verbosity >= 0) {
00057     edm::LogInfo(MsgLoggerCat) 
00058       << "\n===============================\n"
00059       << "Initialized as EDProducer with parameter values:\n"
00060       << "    Name           = " << fName << "\n"
00061       << "    Verbosity      = " << verbosity << "\n"
00062       << "    Frequency      = " << frequency << "\n"
00063       << "    Label          = " << label << "\n"
00064       << "    GetProv        = " << getAllProvenances << "\n"
00065       << "    PrintProv      = " << printProvenanceInfo << "\n"
00066       << "    ECalEBSrc      = " << ECalEBSrc_.label() 
00067       << ":" << ECalEBSrc_.instance() << "\n"
00068       << "    ECalUncalEBSrc = " << ECalUncalEBSrc_.label() 
00069       << ":" << ECalUncalEBSrc_.instance() << "\n"
00070       << "    ECalEESrc      = " << ECalEESrc_.label() 
00071       << ":" << ECalUncalEESrc_.instance() << "\n"
00072       << "    ECalUncalEESrc = " << ECalUncalEESrc_.label() 
00073       << ":" << ECalEESrc_.instance() << "\n"
00074       << "    ECalESSrc      = " << ECalESSrc_.label() 
00075       << ":" << ECalESSrc_.instance() << "\n"
00076       << "    HCalSrc        = " << HCalSrc_.label() 
00077       << ":" << HCalSrc_.instance() << "\n"
00078       << "    SiStripSrc     = " << SiStripSrc_.label() 
00079       << ":" << SiStripSrc_.instance() << "\n" 
00080       << "    SiPixelSrc     = " << SiPxlSrc_.label()
00081       << ":" << SiPxlSrc_.instance() << "\n"
00082       << "    MuDTSrc        = " << MuDTSrc_.label()
00083       << ":" << MuDTSrc_.instance() << "\n"
00084       << "    MuDTSimSrc     = " << MuDTSimSrc_.label()
00085       << ":" << MuDTSimSrc_.instance() << "\n"
00086       << "    MuCSCSrc       = " << MuCSCSrc_.label()
00087       << ":" << MuCSCSrc_.instance() << "\n"
00088       << "    MuRPCSrc       = " << MuRPCSrc_.label()
00089       << ":" << MuRPCSrc_.instance() << "\n"
00090       << "    MuRPCSimSrc    = " << MuRPCSimSrc_.label()
00091       << ":" << MuRPCSimSrc_.instance() << "\n"
00092       << "===============================\n";
00093   }
00094 }
00095 
00096 GlobalRecHitsProducer::~GlobalRecHitsProducer() 
00097 {
00098 }
00099 
00100 void GlobalRecHitsProducer::beginJob(const edm::EventSetup& iSetup)
00101 {
00102   std::string MsgLoggerCat = "GlobalRecHitsProducer_beginJob";
00103 
00104   // clear storage vectors
00105   clear();
00106   return;
00107 }
00108 
00109 void GlobalRecHitsProducer::endJob()
00110 {
00111   std::string MsgLoggerCat = "GlobalRecHitsProducer_endJob";
00112   if (verbosity >= 0)
00113     edm::LogInfo(MsgLoggerCat) 
00114       << "Terminating having processed " << count << " events.";
00115   return;
00116 }
00117 
00118 void GlobalRecHitsProducer::produce(edm::Event& iEvent, 
00119                                   const edm::EventSetup& iSetup)
00120 {
00121   std::string MsgLoggerCat = "GlobalRecHitsProducer_produce";
00122 
00123   // keep track of number of events processed
00124   ++count;
00125 
00126   // get event id information
00127   int nrun = iEvent.id().run();
00128   int nevt = iEvent.id().event();
00129 
00130   if (verbosity > 0) {
00131     edm::LogInfo(MsgLoggerCat)
00132       << "Processing run " << nrun << ", event " << nevt
00133       << " (" << count << " events total)";
00134   } else if (verbosity == 0) {
00135     if (nevt%frequency == 0 || nevt == 1) {
00136       edm::LogInfo(MsgLoggerCat)
00137         << "Processing run " << nrun << ", event " << nevt
00138         << " (" << count << " events total)";
00139     }
00140   }
00141 
00142   // clear event holders
00143   clear();
00144 
00145   // look at information available in the event
00146   if (getAllProvenances) {
00147 
00148     std::vector<const edm::Provenance*> AllProv;
00149     iEvent.getAllProvenance(AllProv);
00150 
00151     if (verbosity >= 0)
00152       edm::LogInfo(MsgLoggerCat)
00153         << "Number of Provenances = " << AllProv.size();
00154 
00155     if (printProvenanceInfo && (verbosity >= 0)) {
00156       TString eventout("\nProvenance info:\n");      
00157 
00158       for (unsigned int i = 0; i < AllProv.size(); ++i) {
00159         eventout += "\n       ******************************";
00160         eventout += "\n       Module       : ";
00161         //eventout += (AllProv[i]->product).moduleLabel();
00162         eventout += AllProv[i]->moduleLabel();
00163         eventout += "\n       ProductID    : ";
00164         //eventout += (AllProv[i]->product).productID_.id_;
00165         eventout += AllProv[i]->productID().id();
00166         eventout += "\n       ClassName    : ";
00167         //eventout += (AllProv[i]->product).fullClassName_;
00168         eventout += AllProv[i]->className();
00169         eventout += "\n       InstanceName : ";
00170         //eventout += (AllProv[i]->product).productInstanceName_;
00171         eventout += AllProv[i]->productInstanceName();
00172         eventout += "\n       BranchName   : ";
00173         //eventout += (AllProv[i]->product).branchName_;
00174         eventout += AllProv[i]->branchName();
00175       }
00176       eventout += "\n       ******************************\n";
00177       edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00178       printProvenanceInfo = false;
00179     }
00180     getAllProvenances = false;
00181   }
00182 
00183   // call fill functions
00184   // gather Ecal information from event
00185   fillECal(iEvent, iSetup);
00186   // gather Hcal information from event
00187   fillHCal(iEvent, iSetup);
00188   // gather Track information from event
00189   fillTrk(iEvent, iSetup);
00190   // gather Muon information from event
00191   fillMuon(iEvent, iSetup);
00192 
00193   if (verbosity > 0)
00194     edm::LogInfo (MsgLoggerCat)
00195       << "Done gathering data from event.";
00196 
00197   // produce object to put into event
00198   std::auto_ptr<PGlobalRecHit> pOut(new PGlobalRecHit);
00199 
00200   if (verbosity > 2)
00201     edm::LogInfo (MsgLoggerCat)
00202       << "Saving event contents:";
00203 
00204   // call store functions
00205   // store ECal information in produce
00206   storeECal(*pOut);
00207   // store HCal information in produce
00208   storeHCal(*pOut);
00209   // store Track information in produce
00210   storeTrk(*pOut);
00211   // store Muon information in produce
00212   storeMuon(*pOut);
00213 
00214   // store information in event
00215   iEvent.put(pOut,label);
00216 
00217   return;
00218 }
00219 
00220 void GlobalRecHitsProducer::fillECal(edm::Event& iEvent, 
00221                                      const edm::EventSetup& iSetup)
00222 {
00223   std::string MsgLoggerCat = "GlobalRecHitsProducer_fillECal";
00224 
00225   TString eventout;
00226   if (verbosity > 0)
00227     eventout = "\nGathering info:";  
00228 
00229   // extract crossing frame from event
00230   //edm::Handle<CrossingFrame> crossingFrame;
00231   edm::Handle<CrossingFrame<PCaloHit> > crossingFrame;
00232   //iEvent.getByType(crossingFrame);
00233   //if (!crossingFrame.isValid()) {
00234   //  edm::LogWarning(MsgLoggerCat)
00235   //    << "Unable to find crossingFrame in event!";
00236   //  return;
00237   //}
00238 
00240   //extract EB information
00242   edm::Handle<EBUncalibratedRecHitCollection> EcalUncalibRecHitEB;
00243   iEvent.getByLabel(ECalUncalEBSrc_, EcalUncalibRecHitEB);
00244   if (!EcalUncalibRecHitEB.isValid()) {
00245     edm::LogWarning(MsgLoggerCat)
00246       << "Unable to find EcalUncalRecHitEB in event!";
00247     return;
00248   }  
00249 
00250   edm::Handle<EBRecHitCollection> EcalRecHitEB;
00251   iEvent.getByLabel(ECalEBSrc_, EcalRecHitEB);
00252   if (!EcalRecHitEB.isValid()) {
00253     edm::LogWarning(MsgLoggerCat)
00254       << "Unable to find EcalRecHitEB in event!";
00255     return;
00256   }  
00257 
00258   // loop over simhits
00259   const std::string barrelHitsName("EcalHitsEB");
00260   iEvent.getByLabel("mix",barrelHitsName,crossingFrame);
00261   if (!crossingFrame.isValid()) {
00262     edm::LogWarning(MsgLoggerCat)
00263       << "Unable to find cal barrel crossingFrame in event!";
00264     return;
00265   }
00266   //std::auto_ptr<MixCollection<PCaloHit> >
00267   //  barrelHits(new MixCollection<PCaloHit>
00268   //           (crossingFrame.product(), barrelHitsName));
00269   std::auto_ptr<MixCollection<PCaloHit> >
00270     barrelHits(new MixCollection<PCaloHit>(crossingFrame.product()));  
00271 
00272   // keep track of sum of simhit energy in each crystal
00273   MapType ebSimMap;
00274   for (MixCollection<PCaloHit>::MixItr hitItr 
00275          = barrelHits->begin();
00276        hitItr != barrelHits->end();
00277        ++hitItr) {
00278     
00279     EBDetId ebid = EBDetId(hitItr->id());
00280     
00281     uint32_t crystid = ebid.rawId();
00282     ebSimMap[crystid] += hitItr->energy();
00283   }
00284   
00285   int nEBRecHits = 0;
00286   // loop over RecHits
00287   const EBUncalibratedRecHitCollection *EBUncalibRecHit = 
00288     EcalUncalibRecHitEB.product();
00289   const EBRecHitCollection *EBRecHit = EcalRecHitEB.product();
00290 
00291   for (EcalUncalibratedRecHitCollection::const_iterator uncalibRecHit =
00292          EBUncalibRecHit->begin();
00293        uncalibRecHit != EBUncalibRecHit->end();
00294        ++uncalibRecHit) {
00295 
00296     EBDetId EBid = EBDetId(uncalibRecHit->id());
00297 
00298     EcalRecHitCollection::const_iterator myRecHit = EBRecHit->find(EBid);
00299 
00300     if (myRecHit != EBRecHit->end()) {
00301       ++nEBRecHits;
00302       EBRE.push_back(myRecHit->energy());
00303       EBSHE.push_back(ebSimMap[EBid.rawId()]);
00304     }
00305   }
00306                                                                        
00307   if (verbosity > 1) {
00308     eventout += "\n          Number of EBRecHits collected:............ ";
00309     eventout += nEBRecHits;
00310   }
00311 
00313   //extract EE information
00315   edm::Handle<EEUncalibratedRecHitCollection> EcalUncalibRecHitEE;
00316   iEvent.getByLabel(ECalUncalEESrc_, EcalUncalibRecHitEE);
00317   if (!EcalUncalibRecHitEE.isValid()) {
00318     edm::LogWarning(MsgLoggerCat)
00319       << "Unable to find EcalUncalRecHitEE in event!";
00320     return;
00321   }  
00322 
00323   edm::Handle<EERecHitCollection> EcalRecHitEE;
00324   iEvent.getByLabel(ECalEESrc_, EcalRecHitEE);
00325   if (!EcalRecHitEE.isValid()) {
00326     edm::LogWarning(MsgLoggerCat)
00327       << "Unable to find EcalRecHitEE in event!";
00328     return;
00329   }  
00330 
00331   // loop over simhits
00332   const std::string endcapHitsName("EcalHitsEE");
00333   iEvent.getByLabel("mix",endcapHitsName,crossingFrame);
00334   if (!crossingFrame.isValid()) {
00335     edm::LogWarning(MsgLoggerCat)
00336       << "Unable to find cal endcap crossingFrame in event!";
00337     return;
00338   }
00339   //std::auto_ptr<MixCollection<PCaloHit> >
00340   //  endcapHits(new MixCollection<PCaloHit>
00341   //           (crossingFrame.product(), endcapHitsName));
00342   std::auto_ptr<MixCollection<PCaloHit> >
00343     endcapHits(new MixCollection<PCaloHit>(crossingFrame.product()));  
00344 
00345   // keep track of sum of simhit energy in each crystal
00346   MapType eeSimMap;
00347   for (MixCollection<PCaloHit>::MixItr hitItr 
00348          = endcapHits->begin();
00349        hitItr != endcapHits->end();
00350        ++hitItr) {
00351     
00352     EEDetId eeid = EEDetId(hitItr->id());
00353     
00354     uint32_t crystid = eeid.rawId();
00355     eeSimMap[crystid] += hitItr->energy();
00356   }
00357   
00358   int nEERecHits = 0;
00359   // loop over RecHits
00360   const EEUncalibratedRecHitCollection *EEUncalibRecHit = 
00361     EcalUncalibRecHitEE.product();
00362   const EERecHitCollection *EERecHit = EcalRecHitEE.product();
00363 
00364   for (EcalUncalibratedRecHitCollection::const_iterator uncalibRecHit =
00365          EEUncalibRecHit->begin();
00366        uncalibRecHit != EEUncalibRecHit->end();
00367        ++uncalibRecHit) {
00368 
00369     EEDetId EEid = EEDetId(uncalibRecHit->id());
00370 
00371     EcalRecHitCollection::const_iterator myRecHit = EERecHit->find(EEid);
00372 
00373     if (myRecHit != EERecHit->end()) {
00374       ++nEERecHits;
00375       EERE.push_back(myRecHit->energy());
00376       EESHE.push_back(eeSimMap[EEid.rawId()]);
00377     }
00378   }
00379                                                                          
00380   if (verbosity > 1) {
00381     eventout += "\n          Number of EERecHits collected:............ ";
00382     eventout += nEERecHits;
00383   }
00384 
00386   //extract ES information
00388   edm::Handle<ESRecHitCollection> EcalRecHitES;
00389   iEvent.getByLabel(ECalESSrc_, EcalRecHitES);
00390   if (!EcalRecHitES.isValid()) {
00391     edm::LogWarning(MsgLoggerCat)
00392       << "Unable to find EcalRecHitES in event!";
00393     return;
00394   }  
00395 
00396   // loop over simhits
00397   const std::string preshowerHitsName("EcalHitsES");
00398   iEvent.getByLabel("mix",preshowerHitsName,crossingFrame);
00399   if (!crossingFrame.isValid()) {
00400     edm::LogWarning(MsgLoggerCat)
00401       << "Unable to find cal preshower crossingFrame in event!";
00402     return;
00403   }
00404   //std::auto_ptr<MixCollection<PCaloHit> >
00405   //  preshowerHits(new MixCollection<PCaloHit>
00406   //           (crossingFrame.product(), preshowerHitsName));
00407   std::auto_ptr<MixCollection<PCaloHit> >
00408     preshowerHits(new MixCollection<PCaloHit>(crossingFrame.product()));  
00409 
00410   // keep track of sum of simhit energy in each crystal
00411   MapType esSimMap;
00412   for (MixCollection<PCaloHit>::MixItr hitItr 
00413          = preshowerHits->begin();
00414        hitItr != preshowerHits->end();
00415        ++hitItr) {
00416     
00417     ESDetId esid = ESDetId(hitItr->id());
00418     
00419     uint32_t crystid = esid.rawId();
00420     esSimMap[crystid] += hitItr->energy();
00421   }
00422   
00423   int nESRecHits = 0;
00424   // loop over RecHits
00425   const ESRecHitCollection *ESRecHit = EcalRecHitES.product();
00426   for (EcalRecHitCollection::const_iterator recHit =
00427          ESRecHit->begin();
00428        recHit != ESRecHit->end();
00429        ++recHit) {
00430 
00431     ESDetId ESid = ESDetId(recHit->id());
00432 
00433     ++nESRecHits;
00434     ESRE.push_back(recHit->energy());
00435     ESSHE.push_back(esSimMap[ESid.rawId()]);
00436   }
00437                                                                       
00438   if (verbosity > 1) {
00439     eventout += "\n          Number of ESRecHits collected:............ ";
00440     eventout += nESRecHits;
00441   }
00442 
00443   if (verbosity > 0)
00444     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00445 
00446   return;
00447 }
00448 
00449 void GlobalRecHitsProducer::storeECal(PGlobalRecHit& product)
00450 {
00451   std::string MsgLoggerCat = "GlobalRecHitsProducer_storeECal";
00452 
00453   if (verbosity > 2) {
00454     TString eventout("\n         nEBRecHits     = ");
00455     eventout += EBRE.size();
00456     for (unsigned int i = 0; i < EBRE.size(); ++i) {
00457       eventout += "\n      (RE, SHE) = (";
00458       eventout += EBRE[i];
00459       eventout += ", ";
00460       eventout += EBSHE[i];
00461       eventout += ")";
00462     }
00463     eventout += "\n         nEERecHits     = ";
00464     eventout += EERE.size();
00465     for (unsigned int i = 0; i < EERE.size(); ++i) {
00466       eventout += "\n      (RE, SHE) = (";
00467       eventout += EERE[i];
00468       eventout += ", ";
00469       eventout += EESHE[i];
00470       eventout += ")";
00471     }
00472     eventout += "\n         nESRecHits     = ";
00473     eventout += ESRE.size();
00474     for (unsigned int i = 0; i < ESRE.size(); ++i) {
00475       eventout += "\n      (RE, SHE) = (";
00476       eventout += ESRE[i];
00477       eventout += ", ";
00478       eventout += ESSHE[i];
00479       eventout += ")";
00480     }
00481     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00482   }
00483 
00484   product.putEBCalRecHits(EBRE,EBSHE);
00485   product.putEECalRecHits(EERE,EESHE);
00486   product.putESCalRecHits(ESRE,ESSHE);
00487 
00488   return;
00489 }
00490 
00491 void GlobalRecHitsProducer::fillHCal(edm::Event& iEvent, 
00492                                    const edm::EventSetup& iSetup)
00493 {
00494   std::string MsgLoggerCat = "GlobalRecHitsProducer_fillHCal";
00495 
00496   TString eventout;
00497   if (verbosity > 0)
00498     eventout = "\nGathering info:";  
00499 
00500   // get geometry
00501   edm::ESHandle<CaloGeometry> geometry;
00502   iSetup.get<CaloGeometryRecord>().get(geometry);
00503   if (!geometry.isValid()) {
00504     edm::LogWarning(MsgLoggerCat)
00505       << "Unable to find CaloGeometry in event!";
00506     return;
00507   }
00508 
00510   // extract simhit info
00512   edm::Handle<edm::PCaloHitContainer> hcalHits;
00513   iEvent.getByLabel(HCalSrc_,hcalHits);
00514   if (!hcalHits.isValid()) {
00515     edm::LogWarning(MsgLoggerCat)
00516       << "Unable to find hcalHits in event!";
00517     return;
00518   }  
00519   const edm::PCaloHitContainer *simhitResult = hcalHits.product();
00520   
00521   MapType fHBEnergySimHits;
00522   MapType fHEEnergySimHits;
00523   MapType fHOEnergySimHits;
00524   MapType fHFEnergySimHits;
00525   for (std::vector<PCaloHit>::const_iterator simhits = simhitResult->begin();
00526        simhits != simhitResult->end();
00527        ++simhits) {
00528     
00529     HcalDetId detId(simhits->id());
00530     uint32_t cellid = detId.rawId();
00531 
00532     if (detId.subdet() == sdHcalBrl){  
00533       fHBEnergySimHits[cellid] += simhits->energy(); 
00534     }
00535     if (detId.subdet() == sdHcalEC){  
00536       fHEEnergySimHits[cellid] += simhits->energy(); 
00537     }    
00538     if (detId.subdet() == sdHcalOut){  
00539       fHOEnergySimHits[cellid] += simhits->energy(); 
00540     }    
00541     if (detId.subdet() == sdHcalFwd){  
00542       fHFEnergySimHits[cellid] += simhits->energy(); 
00543     }    
00544   }
00545 
00546   // max values to be used (HO is found in HB)
00547   Double_t maxHBEnergy = 0.;
00548   Double_t maxHEEnergy = 0.;
00549   Double_t maxHOEnergy = 0.;
00550   Double_t maxHFEnergy = 0.;
00551 
00552   Double_t maxHBPhi = -1000.;
00553   Double_t maxHEPhi = -1000.;
00554   Double_t maxHOPhi = -1000.;
00555   Double_t maxHFPhi = -1000.;
00556 
00557   Double_t maxHBEta = -1000.;
00558   Double_t maxHEEta = -1000.;
00559   Double_t maxHOEta = -1000.;
00560   Double_t maxHFEta = -1000.;
00561 
00562   Double_t PI = 3.141592653589;
00563 
00565   // get HBHE information
00567   std::vector<edm::Handle<HBHERecHitCollection> > hbhe;
00568   iEvent.getManyByType(hbhe);
00569   if (!hbhe[0].isValid()) {
00570     edm::LogWarning(MsgLoggerCat)
00571       << "Unable to find any HBHERecHitCollections in event!";
00572     return;
00573   } 
00574   std::vector<edm::Handle<HBHERecHitCollection> >::iterator ihbhe;
00575      
00576   int iHB = 0;
00577   int iHE = 0; 
00578   for (ihbhe = hbhe.begin(); ihbhe != hbhe.end(); ++ihbhe) {
00579 
00580     // find max values
00581     for (HBHERecHitCollection::const_iterator jhbhe = (*ihbhe)->begin();
00582          jhbhe != (*ihbhe)->end(); ++jhbhe) {
00583 
00584       HcalDetId cell(jhbhe->id());
00585       
00586       if (cell.subdet() == sdHcalBrl) {
00587         
00588         const CaloCellGeometry* cellGeometry =
00589           geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00590         double fEta = cellGeometry->getPosition().eta () ;
00591         double fPhi = cellGeometry->getPosition().phi () ;
00592         if ( (jhbhe->energy()) > maxHBEnergy ) {
00593           maxHBEnergy = jhbhe->energy();
00594           maxHOEnergy = maxHBEnergy;
00595           maxHBPhi = fPhi;
00596           maxHOPhi = maxHBPhi;
00597           maxHBEta = fEta;
00598           maxHOEta = maxHBEta;
00599         }         
00600       }
00601         
00602       if (cell.subdet() == sdHcalEC) {
00603         
00604         const CaloCellGeometry* cellGeometry =
00605           geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00606         double fEta = cellGeometry->getPosition().eta () ;
00607         double fPhi = cellGeometry->getPosition().phi () ;
00608         if ( (jhbhe->energy()) > maxHEEnergy ) {
00609           maxHEEnergy = jhbhe->energy();
00610           maxHEPhi = fPhi;
00611           maxHEEta = fEta;
00612         }         
00613       }
00614     } // end find max values
00615 
00616     for (HBHERecHitCollection::const_iterator jhbhe = (*ihbhe)->begin();
00617          jhbhe != (*ihbhe)->end(); ++jhbhe) {
00618 
00619       HcalDetId cell(jhbhe->id());
00620       
00621       if (cell.subdet() == sdHcalBrl) {
00622 
00623         ++iHB;
00624 
00625         const CaloCellGeometry* cellGeometry =
00626           geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00627         double fEta = cellGeometry->getPosition().eta () ;
00628         double fPhi = cellGeometry->getPosition().phi () ;
00629 
00630         float deltaphi = maxHBPhi - fPhi;
00631         if (fPhi > maxHBPhi) { deltaphi = fPhi - maxHBPhi;}
00632         if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00633         float deltaeta = fEta - maxHBEta;
00634         Double_t r = sqrt(deltaeta * deltaeta + deltaphi * deltaphi);
00635 
00636         HBCalREC.push_back(jhbhe->energy());
00637         HBCalR.push_back(r);
00638         HBCalSHE.push_back(fHBEnergySimHits[cell.rawId()]);
00639       }
00640 
00641       if (cell.subdet() == sdHcalEC) {
00642 
00643         ++iHE;
00644 
00645         const CaloCellGeometry* cellGeometry =
00646           geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00647         double fEta = cellGeometry->getPosition().eta () ;
00648         double fPhi = cellGeometry->getPosition().phi () ;
00649 
00650         float deltaphi = maxHEPhi - fPhi;
00651         if (fPhi > maxHEPhi) { deltaphi = fPhi - maxHEPhi;}
00652         if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00653         float deltaeta = fEta - maxHEEta;
00654         Double_t r = sqrt(deltaeta * deltaeta + deltaphi * deltaphi);
00655 
00656         HECalREC.push_back(jhbhe->energy());
00657         HECalR.push_back(r);
00658         HECalSHE.push_back(fHEEnergySimHits[cell.rawId()]);
00659       }
00660     }
00661   } // end loop through collection
00662 
00663                                                                       
00664   if (verbosity > 1) {
00665     eventout += "\n          Number of HBRecHits collected:............ ";
00666     eventout += iHB;
00667   }
00668   
00669   if (verbosity > 1) {
00670     eventout += "\n          Number of HERecHits collected:............ ";
00671     eventout += iHE;
00672   }
00673 
00675   // get HF information
00677   std::vector<edm::Handle<HFRecHitCollection> > hf;
00678   iEvent.getManyByType(hf);
00679   if (!hf[0].isValid()) {
00680     edm::LogWarning(MsgLoggerCat)
00681       << "Unable to find any HFRecHitCollections in event!";
00682     return;
00683   } 
00684   std::vector<edm::Handle<HFRecHitCollection> >::iterator ihf;
00685      
00686   int iHF = 0; 
00687   for (ihf = hf.begin(); ihf != hf.end(); ++ihf) {
00688 
00689     // find max values
00690     for (HFRecHitCollection::const_iterator jhf = (*ihf)->begin();
00691          jhf != (*ihf)->end(); ++jhf) {
00692 
00693       HcalDetId cell(jhf->id());
00694       
00695       if (cell.subdet() == sdHcalFwd) {
00696         
00697         const CaloCellGeometry* cellGeometry =
00698           geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00699         double fEta = cellGeometry->getPosition().eta () ;
00700         double fPhi = cellGeometry->getPosition().phi () ;
00701         if ( (jhf->energy()) > maxHFEnergy ) {
00702           maxHFEnergy = jhf->energy();
00703           maxHFPhi = fPhi;
00704           maxHFEta = fEta;
00705         }         
00706       }
00707     } // end find max values
00708 
00709     for (HFRecHitCollection::const_iterator jhf = (*ihf)->begin();
00710          jhf != (*ihf)->end(); ++jhf) {
00711 
00712       HcalDetId cell(jhf->id());
00713       
00714       if (cell.subdet() == sdHcalFwd) {
00715 
00716         ++iHF;
00717 
00718         const CaloCellGeometry* cellGeometry =
00719           geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00720         double fEta = cellGeometry->getPosition().eta () ;
00721         double fPhi = cellGeometry->getPosition().phi () ;
00722 
00723         float deltaphi = maxHBPhi - fPhi;
00724         if (fPhi > maxHFPhi) { deltaphi = fPhi - maxHFPhi;}
00725         if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00726         float deltaeta = fEta - maxHFEta;
00727         Double_t r = sqrt(deltaeta * deltaeta + deltaphi * deltaphi);
00728 
00729         HFCalREC.push_back(jhf->energy());
00730         HFCalR.push_back(r);
00731         HFCalSHE.push_back(fHFEnergySimHits[cell.rawId()]);
00732       }
00733     }
00734   } // end loop through collection
00735 
00736   if (verbosity > 1) {
00737     eventout += "\n          Number of HFDigis collected:.............. ";
00738     eventout += iHF;
00739   }
00740 
00742   // get HO information
00744   std::vector<edm::Handle<HORecHitCollection> > ho;
00745   iEvent.getManyByType(ho);
00746   if (!ho[0].isValid()) {
00747     edm::LogWarning(MsgLoggerCat)
00748       << "Unable to find any HORecHitCollections in event!";
00749     return;
00750   } 
00751   std::vector<edm::Handle<HORecHitCollection> >::iterator iho;
00752      
00753   int iHO = 0; 
00754   for (iho = ho.begin(); iho != ho.end(); ++iho) {
00755 
00756     for (HORecHitCollection::const_iterator jho = (*iho)->begin();
00757          jho != (*iho)->end(); ++jho) {
00758 
00759       HcalDetId cell(jho->id());
00760       
00761       if (cell.subdet() == sdHcalOut) {
00762 
00763         ++iHO;
00764 
00765         const CaloCellGeometry* cellGeometry =
00766           geometry->getSubdetectorGeometry (cell)->getGeometry (cell) ;
00767         double fEta = cellGeometry->getPosition().eta () ;
00768         double fPhi = cellGeometry->getPosition().phi () ;
00769 
00770         float deltaphi = maxHOPhi - fPhi;
00771         if (fPhi > maxHOPhi) { deltaphi = fPhi - maxHOPhi;}
00772         if (deltaphi > PI) { deltaphi = 2.0 * PI - deltaphi;}
00773         float deltaeta = fEta - maxHOEta;
00774         Double_t r = sqrt(deltaeta * deltaeta + deltaphi * deltaphi);
00775 
00776         HOCalREC.push_back(jho->energy());
00777         HOCalR.push_back(r);
00778         HOCalSHE.push_back(fHOEnergySimHits[cell.rawId()]);
00779       }
00780     }
00781   } // end loop through collection
00782 
00783   if (verbosity > 1) {
00784     eventout += "\n          Number of HODigis collected:.............. ";
00785     eventout += iHO;
00786   }
00787 
00788   if (verbosity > 0)
00789     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00790 
00791   return;
00792 }
00793 
00794 void GlobalRecHitsProducer::storeHCal(PGlobalRecHit& product)
00795 {
00796   std::string MsgLoggerCat = "GlobalRecHitsProducer_storeHCal";
00797 
00798   if (verbosity > 2) {
00799     TString eventout("\n         nHBRecHits     = ");
00800     eventout += HBCalREC.size();
00801     for (unsigned int i = 0; i < HBCalREC.size(); ++i) {
00802       eventout += "\n      (REC, R, SHE) = (";
00803       eventout += HBCalREC[i];
00804       eventout += ", ";
00805       eventout += HBCalR[i];
00806       eventout += ", ";
00807       eventout += HBCalSHE[i];
00808       eventout += ")";
00809     }
00810     eventout += "\n         nHERecHits     = ";
00811     eventout += HECalREC.size();
00812     for (unsigned int i = 0; i < HECalREC.size(); ++i) {
00813       eventout += "\n      (REC, R, SHE) = (";
00814       eventout += HECalREC[i];
00815       eventout += ", ";
00816       eventout += HECalR[i];
00817       eventout += ", ";
00818       eventout += HECalSHE[i];
00819       eventout += ")";
00820     }
00821     eventout += "\n         nHFRecHits     = ";
00822     eventout += HFCalREC.size();
00823     for (unsigned int i = 0; i < HFCalREC.size(); ++i) {
00824       eventout += "\n      (REC, R, SHE) = (";
00825       eventout += HFCalREC[i];
00826       eventout += ", ";
00827       eventout += HFCalR[i];
00828       eventout += ", ";
00829       eventout += HFCalSHE[i];
00830       eventout += ")";
00831     }
00832     eventout += "\n         nHORecHits     = ";
00833     eventout += HOCalREC.size();
00834     for (unsigned int i = 0; i < HOCalREC.size(); ++i) {
00835       eventout += "\n      (REC, R, SHE) = (";
00836       eventout += HOCalREC[i];
00837       eventout += ", ";
00838       eventout += HOCalR[i];
00839       eventout += ", ";
00840       eventout += HOCalSHE[i];
00841       eventout += ")";
00842     }
00843 
00844     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00845   }
00846 
00847   product.putHBCalRecHits(HBCalREC,HBCalR,HBCalSHE);
00848   product.putHECalRecHits(HECalREC,HECalR,HECalSHE);
00849   product.putHOCalRecHits(HOCalREC,HOCalR,HOCalSHE);
00850   product.putHFCalRecHits(HFCalREC,HFCalR,HFCalSHE);
00851 
00852   return;
00853 }
00854 
00855 void GlobalRecHitsProducer::fillTrk(edm::Event& iEvent, 
00856                                    const edm::EventSetup& iSetup)
00857 {
00858   std::string MsgLoggerCat = "GlobalRecHitsProducer_fillTrk";
00859 
00860   TString eventout;
00861   if (verbosity > 0)
00862     eventout = "\nGathering info:";  
00863 
00864   // get strip information
00865   edm::Handle<SiStripMatchedRecHit2DCollection> rechitsmatched;
00866   iEvent.getByLabel(SiStripSrc_, rechitsmatched);
00867   if (!rechitsmatched.isValid()) {
00868     edm::LogWarning(MsgLoggerCat)
00869       << "Unable to find stripmatchedrechits in event!";
00870     return;
00871   }  
00872 
00873   TrackerHitAssociator associate(iEvent,conf_);
00874 
00875   edm::ESHandle<TrackerGeometry> pDD;
00876   iSetup.get<TrackerDigiGeometryRecord>().get(pDD);
00877   if (!pDD.isValid()) {
00878     edm::LogWarning(MsgLoggerCat)
00879       << "Unable to find TrackerDigiGeometry in event!";
00880     return;
00881   }
00882   const TrackerGeometry &tracker(*pDD);
00883 
00884   int nStripBrl = 0, nStripFwd = 0;
00885 
00886   // loop over det units
00887   for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin();
00888        it != pDD->dets().end(); ++it) {
00889     
00890     uint32_t myid = ((*it)->geographicalId()).rawId();
00891     DetId detid = ((*it)->geographicalId());
00892 
00893     //loop over rechits-matched in the same subdetector
00894     SiStripMatchedRecHit2DCollection::range 
00895       rechitmatchedRange = rechitsmatched->get(detid);
00896     SiStripMatchedRecHit2DCollection::const_iterator 
00897       rechitmatchedRangeIteratorBegin = rechitmatchedRange.first;
00898     SiStripMatchedRecHit2DCollection::const_iterator 
00899       rechitmatchedRangeIteratorEnd   = rechitmatchedRange.second;
00900     SiStripMatchedRecHit2DCollection::const_iterator 
00901       itermatched = rechitmatchedRangeIteratorBegin;
00902     int numrechitmatched = 
00903       rechitmatchedRangeIteratorEnd - rechitmatchedRangeIteratorBegin;
00904    
00905     if (numrechitmatched > 0) {
00906 
00907       for ( itermatched = rechitmatchedRangeIteratorBegin; 
00908             itermatched != rechitmatchedRangeIteratorEnd;
00909             ++itermatched) {
00910 
00911         SiStripMatchedRecHit2D const rechit = *itermatched;
00912         LocalPoint position = rechit.localPosition();
00913         
00914         float mindist = 999999.;
00915         float distx = 999999.;
00916         float disty = 999999.;
00917         float dist = 999999.;
00918         std::pair<LocalPoint,LocalVector> closestPair;
00919         matched.clear();
00920         
00921         float rechitmatchedx = position.x();
00922         float rechitmatchedy = position.y();
00923 
00924         matched = associate.associateHit(rechit);
00925 
00926         if (!matched.empty()) {
00927           //project simhit;
00928           const GluedGeomDet* gluedDet = 
00929             (const GluedGeomDet*)tracker.idToDet(rechit.geographicalId());
00930           const StripGeomDetUnit* partnerstripdet =
00931             (StripGeomDetUnit*) gluedDet->stereoDet();
00932           std::pair<LocalPoint,LocalVector> hitPair;
00933           
00934           for(std::vector<PSimHit>::const_iterator m = matched.begin(); 
00935               m != matched.end(); m++){
00936             //project simhit;
00937             hitPair = projectHit((*m),partnerstripdet,gluedDet->surface());
00938             distx = fabs(rechitmatchedx - hitPair.first.x());
00939             disty = fabs(rechitmatchedy - hitPair.first.y());
00940             dist = sqrt(distx*distx+disty*disty);
00941 
00942             if(dist < mindist){
00943               mindist = dist;
00944               closestPair = hitPair;
00945             }
00946           }
00947           
00948           // get TIB
00949           if (detid.subdetId() == sdSiTIB) {
00950 
00951             TIBDetId tibid(myid);
00952             ++nStripBrl;
00953 
00954             if (tibid.layer() == 1) {
00955               TIBL1RX.push_back(rechitmatchedx);
00956               TIBL1RY.push_back(rechitmatchedy);
00957               TIBL1SX.push_back(closestPair.first.x());
00958               TIBL1SY.push_back(closestPair.first.y());
00959             }
00960             if (tibid.layer() == 2) {
00961               TIBL2RX.push_back(rechitmatchedx);
00962               TIBL2RY.push_back(rechitmatchedy);
00963               TIBL2SX.push_back(closestPair.first.x());
00964               TIBL2SY.push_back(closestPair.first.y());
00965             }   
00966             if (tibid.layer() == 3) {
00967               TIBL3RX.push_back(rechitmatchedx);
00968               TIBL3RY.push_back(rechitmatchedy);
00969               TIBL3SX.push_back(closestPair.first.x());
00970               TIBL3SY.push_back(closestPair.first.y());
00971             }
00972             if (tibid.layer() == 4) {
00973               TIBL4RX.push_back(rechitmatchedx);
00974               TIBL4RY.push_back(rechitmatchedy);
00975               TIBL4SX.push_back(closestPair.first.x());
00976               TIBL4SY.push_back(closestPair.first.y());
00977             }
00978           }
00979     
00980           // get TOB
00981           if (detid.subdetId() == sdSiTOB) {
00982 
00983             TOBDetId tobid(myid);
00984             ++nStripBrl;
00985 
00986             if (tobid.layer() == 1) {
00987               TOBL1RX.push_back(rechitmatchedx);
00988               TOBL1RY.push_back(rechitmatchedy);
00989               TOBL1SX.push_back(closestPair.first.x());
00990               TOBL1SY.push_back(closestPair.first.y());
00991             }
00992             if (tobid.layer() == 2) {
00993               TOBL2RX.push_back(rechitmatchedx);
00994               TOBL2RY.push_back(rechitmatchedy);
00995               TOBL2SX.push_back(closestPair.first.x());
00996               TOBL2SY.push_back(closestPair.first.y());
00997             }   
00998             if (tobid.layer() == 3) {
00999               TOBL3RX.push_back(rechitmatchedx);
01000               TOBL3RY.push_back(rechitmatchedy);
01001               TOBL3SX.push_back(closestPair.first.x());
01002               TOBL3SY.push_back(closestPair.first.y());
01003             }
01004             if (tobid.layer() == 4) {
01005               TOBL4RX.push_back(rechitmatchedx);
01006               TOBL4RY.push_back(rechitmatchedy);
01007               TOBL4SX.push_back(closestPair.first.x());
01008               TOBL4SY.push_back(closestPair.first.y());
01009             }
01010           }
01011 
01012           // get TID
01013           if (detid.subdetId() == sdSiTID) {
01014 
01015             TIDDetId tidid(myid);
01016             ++nStripFwd;
01017 
01018             if (tidid.wheel() == 1) {
01019               TIDW1RX.push_back(rechitmatchedx);
01020               TIDW1RY.push_back(rechitmatchedy);
01021               TIDW1SX.push_back(closestPair.first.x());
01022               TIDW1SY.push_back(closestPair.first.y());
01023             }
01024             if (tidid.wheel() == 2) {
01025               TIDW2RX.push_back(rechitmatchedx);
01026               TIDW2RY.push_back(rechitmatchedy);
01027               TIDW2SX.push_back(closestPair.first.x());
01028               TIDW2SY.push_back(closestPair.first.y());
01029             }   
01030             if (tidid.wheel() == 3) {
01031               TIDW3RX.push_back(rechitmatchedx);
01032               TIDW3RY.push_back(rechitmatchedy);
01033               TIDW3SX.push_back(closestPair.first.x());
01034               TIDW3SY.push_back(closestPair.first.y());
01035             }
01036           }
01037 
01038           // get TEC
01039           if (detid.subdetId() == sdSiTEC) {
01040 
01041             TECDetId tecid(myid);
01042             ++nStripFwd;
01043 
01044             if (tecid.wheel() == 1) {
01045               TECW1RX.push_back(rechitmatchedx);
01046               TECW1RY.push_back(rechitmatchedy);
01047               TECW1SX.push_back(closestPair.first.x());
01048               TECW1SY.push_back(closestPair.first.y());
01049             }
01050             if (tecid.wheel() == 2) {
01051               TECW2RX.push_back(rechitmatchedx);
01052               TECW2RY.push_back(rechitmatchedy);
01053               TECW2SX.push_back(closestPair.first.x());
01054               TECW2SY.push_back(closestPair.first.y());
01055             }   
01056             if (tecid.wheel() == 3) {
01057               TECW3RX.push_back(rechitmatchedx);
01058               TECW3RY.push_back(rechitmatchedy);
01059               TECW3SX.push_back(closestPair.first.x());
01060               TECW3SY.push_back(closestPair.first.y());
01061             }
01062             if (tecid.wheel() == 4) {
01063               TECW4RX.push_back(rechitmatchedx);
01064               TECW4RY.push_back(rechitmatchedy);
01065               TECW4SX.push_back(closestPair.first.x());
01066               TECW4SY.push_back(closestPair.first.y());
01067             }
01068             if (tecid.wheel() == 5) {
01069               TECW5RX.push_back(rechitmatchedx);
01070               TECW5RY.push_back(rechitmatchedy);
01071               TECW5SX.push_back(closestPair.first.x());
01072               TECW5SY.push_back(closestPair.first.y());
01073             }   
01074             if (tecid.wheel() == 6) {
01075               TECW6RX.push_back(rechitmatchedx);
01076               TECW6RY.push_back(rechitmatchedy);
01077               TECW6SX.push_back(closestPair.first.x());
01078               TECW6SY.push_back(closestPair.first.y());
01079             }
01080             if (tecid.wheel() == 7) {
01081               TECW7RX.push_back(rechitmatchedx);
01082               TECW7RY.push_back(rechitmatchedy);
01083               TECW7SX.push_back(closestPair.first.x());
01084               TECW7SY.push_back(closestPair.first.y());
01085             }   
01086             if (tecid.wheel() == 8) {
01087               TECW8RX.push_back(rechitmatchedx);
01088               TECW8RY.push_back(rechitmatchedy);
01089               TECW8SX.push_back(closestPair.first.x());
01090               TECW8SY.push_back(closestPair.first.y());
01091             }
01092           }
01093 
01094         } // end if matched empty
01095       }
01096     }
01097   } // end loop over det units
01098                                                                       
01099   if (verbosity > 1) {
01100     eventout += "\n          Number of BrlStripRecHits collected:...... ";
01101     eventout += nStripBrl;
01102   }
01103 
01104   if (verbosity > 1) {
01105     eventout += "\n          Number of FrwdStripRecHits collected:..... ";
01106     eventout += nStripFwd;
01107   }
01108 
01109   // get pixel information
01110   //Get RecHits
01111   edm::Handle<SiPixelRecHitCollection> recHitColl;
01112   iEvent.getByLabel(SiPxlSrc_, recHitColl);
01113   if (!recHitColl.isValid()) {
01114     edm::LogWarning(MsgLoggerCat)
01115       << "Unable to find SiPixelRecHitCollection in event!";
01116     return;
01117   }  
01118   
01119   //Get event setup
01120   edm::ESHandle<TrackerGeometry> geom;
01121   iSetup.get<TrackerDigiGeometryRecord>().get(geom); 
01122   if (!geom.isValid()) {
01123     edm::LogWarning(MsgLoggerCat)
01124       << "Unable to find TrackerDigiGeometry in event!";
01125     return;
01126   }
01127   //const TrackerGeometry& theTracker(*geom);
01128 
01129   int nPxlBrl = 0, nPxlFwd = 0;    
01130   //iterate over detunits
01131   for (TrackerGeometry::DetContainer::const_iterator it = geom->dets().begin();
01132        it != geom->dets().end(); ++it) {
01133 
01134     uint32_t myid = ((*it)->geographicalId()).rawId();
01135     DetId detId = ((*it)->geographicalId());
01136     int subid = detId.subdetId();
01137     
01138     if (! ((subid == sdPxlBrl) || (subid == sdPxlFwd))) continue;
01139     
01140     //const PixelGeomDetUnit * theGeomDet = 
01141     //  dynamic_cast<const PixelGeomDetUnit*>(theTracker.idToDet(detId) );
01142     
01143     SiPixelRecHitCollection::range pixelrechitRange = 
01144       (recHitColl.product())->get(detId);
01145     SiPixelRecHitCollection::const_iterator pixelrechitRangeIteratorBegin = 
01146       pixelrechitRange.first;
01147     SiPixelRecHitCollection::const_iterator pixelrechitRangeIteratorEnd = 
01148       pixelrechitRange.second;
01149     SiPixelRecHitCollection::const_iterator pixeliter = 
01150       pixelrechitRangeIteratorBegin;
01151     std::vector<PSimHit> matched;
01152     
01153     //----Loop over rechits for this detId
01154     for ( ; pixeliter != pixelrechitRangeIteratorEnd; ++pixeliter) {
01155 
01156       matched.clear();
01157       matched = associate.associateHit(*pixeliter);
01158       
01159       if ( !matched.empty() ) {
01160 
01161         float closest = 9999.9;
01162         //std::vector<PSimHit>::const_iterator closestit = matched.begin();
01163         LocalPoint lp = pixeliter->localPosition();
01164         float rechit_x = lp.x();
01165         float rechit_y = lp.y();
01166 
01167         float sim_x = 0.;
01168         float sim_y = 0.;
01169         
01170         //loop over sim hits and fill closet
01171         for (std::vector<PSimHit>::const_iterator m = matched.begin(); 
01172              m != matched.end(); ++m) {
01173 
01174           float sim_x1 = (*m).entryPoint().x();
01175           float sim_x2 = (*m).exitPoint().x();
01176           float sim_xpos = 0.5*(sim_x1+sim_x2);
01177           
01178           float sim_y1 = (*m).entryPoint().y();
01179           float sim_y2 = (*m).exitPoint().y();
01180           float sim_ypos = 0.5*(sim_y1+sim_y2);
01181           
01182           float x_res = fabs(sim_xpos - rechit_x);
01183           float y_res = fabs(sim_ypos - rechit_y);
01184           
01185           float dist = sqrt(x_res*x_res + y_res*y_res);
01186           
01187           if ( dist < closest ) {
01188             closest = dist;
01189             sim_x = sim_xpos;
01190             sim_y = sim_ypos;
01191           }
01192         } // end sim hit loop
01193         
01194         // get Barrel pixels
01195         if (subid == sdPxlBrl) {
01196           PXBDetId bdetid(myid);
01197           ++nPxlBrl;
01198 
01199           if (bdetid.layer() == 1) {
01200             BRL1RX.push_back(rechit_x);
01201             BRL1RY.push_back(rechit_y);
01202             BRL1SX.push_back(sim_x);
01203             BRL1SY.push_back(sim_y);      
01204           }
01205           if (bdetid.layer() == 2) {
01206             BRL2RX.push_back(rechit_x);
01207             BRL2RY.push_back(rechit_y);
01208             BRL2SX.push_back(sim_x);
01209             BRL2SY.push_back(sim_y);              
01210           }
01211           if (bdetid.layer() == 3) {
01212             BRL3RX.push_back(rechit_x);
01213             BRL3RY.push_back(rechit_y);
01214             BRL3SX.push_back(sim_x);
01215             BRL3SY.push_back(sim_y);              
01216           }
01217         }
01218 
01219         // get Forward pixels
01220         if (subid == sdPxlFwd) {
01221           PXFDetId fdetid(myid);
01222           ++nPxlFwd;
01223 
01224           if (fdetid.disk() == 1) {
01225             if (fdetid.side() == 1) {
01226               FWD1nRX.push_back(rechit_x);
01227               FWD1nRY.push_back(rechit_y);
01228               FWD1nSX.push_back(sim_x);
01229               FWD1nSY.push_back(sim_y);   
01230             }
01231             if (fdetid.side() == 2) {
01232               FWD1pRX.push_back(rechit_x);
01233               FWD1pRY.push_back(rechit_y);
01234               FWD1pSX.push_back(sim_x);
01235               FWD1pSY.push_back(sim_y);
01236             }
01237           }
01238           if (fdetid.disk() == 2) {
01239             if (fdetid.side() == 1) {
01240               FWD2nRX.push_back(rechit_x);
01241               FWD2nRY.push_back(rechit_y);
01242               FWD2nSX.push_back(sim_x);
01243               FWD2nSY.push_back(sim_y);
01244             }
01245             if (fdetid.side() == 2) {
01246               FWD2pRX.push_back(rechit_x);
01247               FWD2pRY.push_back(rechit_y);
01248               FWD2pSX.push_back(sim_x);
01249               FWD2pSY.push_back(sim_y);
01250             }
01251           }
01252         }      
01253       } // end matched emtpy
01254     } // <-----end rechit loop 
01255   } // <------ end detunit loop  
01256 
01257                      
01258   if (verbosity > 1) {
01259     eventout += "\n          Number of BrlPixelRecHits collected:...... ";
01260     eventout += nPxlBrl;
01261   }
01262 
01263   if (verbosity > 1) {
01264     eventout += "\n          Number of FrwdPixelRecHits collected:..... ";
01265     eventout += nPxlFwd;
01266   }
01267 
01268   if (verbosity > 0)
01269     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01270 
01271   return;
01272 }
01273 
01274 void GlobalRecHitsProducer::storeTrk(PGlobalRecHit& product)
01275 {
01276   std::string MsgLoggerCat = "GlobalRecHitsProducer_storeTrk";
01277 
01278   if (verbosity > 2) {
01279     
01280     // strip output
01281     TString eventout("\n         nTIBL1     = ");
01282     eventout += TIBL1RX.size();
01283     for (unsigned int i = 0; i < TIBL1RX.size(); ++i) {
01284       eventout += "\n      (RX, RY, SX, SY) = (";
01285       eventout += TIBL1RX[i];
01286       eventout += ", ";
01287       eventout += TIBL1RY[i];
01288       eventout += ", ";
01289       eventout += TIBL1SX[i];
01290       eventout += ", ";
01291       eventout += TIBL1SY[i];
01292       eventout += ")";
01293     }
01294     eventout += "\n         nTIBL2     = ";
01295     eventout += TIBL2RX.size();
01296     for (unsigned int i = 0; i < TIBL2RX.size(); ++i) {
01297       eventout += "\n      (RX, RY, SX, SY) = (";
01298       eventout += TIBL2RX[i];
01299       eventout += ", ";
01300       eventout += TIBL2RY[i];
01301       eventout += ", ";
01302       eventout += TIBL2SX[i];
01303       eventout += ", ";
01304       eventout += TIBL2SY[i];
01305       eventout += ")";
01306     }
01307     eventout += "\n         nTIBL3     = ";
01308     eventout += TIBL3RX.size();
01309     for (unsigned int i = 0; i < TIBL3RX.size(); ++i) {
01310       eventout += "\n      (RX, RY, SX, SY) = (";
01311       eventout += TIBL3RX[i];
01312       eventout += ", ";
01313       eventout += TIBL3RY[i];
01314       eventout += ", ";
01315       eventout += TIBL3SX[i];
01316       eventout += ", ";
01317       eventout += TIBL3SY[i];
01318       eventout += ")";
01319     }
01320     eventout += "\n         nTIBL4     = ";
01321     eventout += TIBL4RX.size();
01322     for (unsigned int i = 0; i < TIBL4RX.size(); ++i) {
01323       eventout += "\n      (RX, RY, SX, SY) = (";
01324       eventout += TIBL4RX[i];
01325       eventout += ", ";
01326       eventout += TIBL4RY[i];
01327       eventout += ", ";
01328       eventout += TIBL4SX[i];
01329       eventout += ", ";
01330       eventout += TIBL4SY[i];
01331       eventout += ")";
01332     }
01333     eventout += "\n         nTOBL1     = ";
01334     eventout += TOBL1RX.size();
01335     for (unsigned int i = 0; i < TOBL1RX.size(); ++i) {
01336       eventout += "\n      (RX, RY, SX, SY) = (";
01337       eventout += TOBL1RX[i];
01338       eventout += ", ";
01339       eventout += TOBL1RY[i];
01340       eventout += ", ";
01341       eventout += TOBL1SX[i];
01342       eventout += ", ";
01343       eventout += TOBL1SY[i];
01344       eventout += ")";
01345     }
01346     eventout += "\n         nTOBL2     = ";
01347     eventout += TOBL2RX.size();
01348     for (unsigned int i = 0; i < TOBL2RX.size(); ++i) {
01349       eventout += "\n      (RX, RY, SX, SY) = (";
01350       eventout += TOBL2RX[i];
01351       eventout += ", ";
01352       eventout += TOBL2RY[i];
01353       eventout += ", ";
01354       eventout += TOBL2SX[i];
01355       eventout += ", ";
01356       eventout += TOBL2SY[i];
01357       eventout += ")";
01358     }
01359     eventout += "\n         nTOBL3     = ";
01360     eventout += TOBL3RX.size();
01361     for (unsigned int i = 0; i < TOBL3RX.size(); ++i) {
01362       eventout += "\n      (RX, RY, SX, SY) = (";
01363       eventout += TOBL3RX[i];
01364       eventout += ", ";
01365       eventout += TOBL3RY[i];
01366       eventout += ", ";
01367       eventout += TOBL3SX[i];
01368       eventout += ", ";
01369       eventout += TOBL3SY[i];
01370       eventout += ")";
01371     }
01372     eventout += "\n         nTOBL4     = ";
01373     eventout += TOBL4RX.size();
01374     for (unsigned int i = 0; i < TOBL4RX.size(); ++i) {
01375       eventout += "\n      (RX, RY, SX, SY) = (";
01376       eventout += TOBL4RX[i];
01377       eventout += ", ";
01378       eventout += TOBL4RY[i];
01379       eventout += ", ";
01380       eventout += TOBL4SX[i];
01381       eventout += ", ";
01382       eventout += TOBL4SY[i];
01383       eventout += ")";
01384     }
01385     eventout += "\n         nTIDW1     = ";
01386     eventout += TIDW1RX.size();
01387     for (unsigned int i = 0; i < TIDW1RX.size(); ++i) {
01388       eventout += "\n      (RX, RY, SX, SY) = (";
01389       eventout += TIDW1RX[i];
01390       eventout += ", ";
01391       eventout += TIDW1RY[i];
01392       eventout += ", ";
01393       eventout += TIDW1SX[i];
01394       eventout += ", ";
01395       eventout += TIDW1SY[i];
01396       eventout += ")";
01397     }
01398     eventout += "\n         nTIDW2     = ";
01399     eventout += TIDW2RX.size();
01400     for (unsigned int i = 0; i < TIDW2RX.size(); ++i) {
01401       eventout += "\n      (RX, RY, SX, SY) = (";
01402       eventout += TIDW2RX[i];
01403       eventout += ", ";
01404       eventout += TIDW2RY[i];
01405       eventout += ", ";
01406       eventout += TIDW2SX[i];
01407       eventout += ", ";
01408       eventout += TIDW2SY[i];
01409       eventout += ")";
01410     }
01411     eventout += "\n         nTIDW3     = ";
01412     eventout += TIDW3RX.size();
01413     for (unsigned int i = 0; i < TIDW3RX.size(); ++i) {
01414       eventout += "\n      (RX, RY, SX, SY) = (";
01415       eventout += TIDW3RX[i];
01416       eventout += ", ";
01417       eventout += TIDW3RY[i];
01418       eventout += ", ";
01419       eventout += TIDW3SX[i];
01420       eventout += ", ";
01421       eventout += TIDW3SY[i];
01422       eventout += ")";
01423     }
01424     eventout += "\n         nTECW1     = ";
01425     eventout += TECW1RX.size();
01426     for (unsigned int i = 0; i < TECW1RX.size(); ++i) {
01427       eventout += "\n      (RX, RY, SX, SY) = (";
01428       eventout += TECW1RX[i];
01429       eventout += ", ";
01430       eventout += TECW1RY[i];
01431       eventout += ", ";
01432       eventout += TECW1SX[i];
01433       eventout += ", ";
01434       eventout += TECW1SY[i];
01435       eventout += ")";
01436     }
01437     eventout += "\n         nTECW2     = ";
01438     eventout += TECW2RX.size();
01439     for (unsigned int i = 0; i < TECW2RX.size(); ++i) {
01440       eventout += "\n      (RX, RY, SX, SY) = (";
01441       eventout += TECW2RX[i];
01442       eventout += ", ";
01443       eventout += TECW2RY[i];
01444       eventout += ", ";
01445       eventout += TECW2SX[i];
01446       eventout += ", ";
01447       eventout += TECW2SY[i];
01448       eventout += ")";
01449     }
01450     eventout += "\n         nTECW3     = ";
01451     eventout += TECW3RX.size();
01452     for (unsigned int i = 0; i < TECW3RX.size(); ++i) {
01453       eventout += "\n      (RX, RY, SX, SY) = (";
01454       eventout += TECW3RX[i];
01455       eventout += ", ";
01456       eventout += TECW3RY[i];
01457       eventout += ", ";
01458       eventout += TECW3SX[i];
01459       eventout += ", ";
01460       eventout += TECW3SY[i];
01461       eventout += ")";
01462     }
01463     eventout += "\n         nTECW4     = ";
01464     eventout += TECW4RX.size();
01465     for (unsigned int i = 0; i < TECW4RX.size(); ++i) {
01466       eventout += "\n      (RX, RY, SX, SY) = (";
01467       eventout += TECW4RX[i];
01468       eventout += ", ";
01469       eventout += TECW4RY[i];
01470       eventout += ", ";
01471       eventout += TECW4SX[i];
01472       eventout += ", ";
01473       eventout += TECW4SY[i];
01474       eventout += ")";
01475     }
01476     eventout += "\n         nTECW5     = ";
01477     eventout += TECW5RX.size();
01478     for (unsigned int i = 0; i < TECW5RX.size(); ++i) {
01479       eventout += "\n      (RX, RY, SX, SY) = (";
01480       eventout += TECW5RX[i];
01481       eventout += ", ";
01482       eventout += TECW5RY[i];
01483       eventout += ", ";
01484       eventout += TECW5SX[i];
01485       eventout += ", ";
01486       eventout += TECW5SY[i];
01487       eventout += ")";
01488     }
01489     eventout += "\n         nTECW6     = ";
01490     eventout += TECW6RX.size();
01491     for (unsigned int i = 0; i < TECW6RX.size(); ++i) {
01492       eventout += "\n      (RX, RY, SX, SY) = (";
01493       eventout += TECW6RX[i];
01494       eventout += ", ";
01495       eventout += TECW6RY[i];
01496       eventout += ", ";
01497       eventout += TECW6SX[i];
01498       eventout += ", ";
01499       eventout += TECW6SY[i];
01500       eventout += ")";
01501     }
01502     eventout += "\n         nTECW7     = ";
01503     eventout += TECW7RX.size();
01504     for (unsigned int i = 0; i < TECW7RX.size(); ++i) {
01505       eventout += "\n      (RX, RY, SX, SY) = (";
01506       eventout += TECW7RX[i];
01507       eventout += ", ";
01508       eventout += TECW7RY[i];
01509       eventout += ", ";
01510       eventout += TECW7SX[i];
01511       eventout += ", ";
01512       eventout += TECW7SY[i];
01513       eventout += ")";
01514     }
01515     eventout += "\n         nTECW8     = ";
01516     eventout += TECW8RX.size();
01517     for (unsigned int i = 0; i < TECW8RX.size(); ++i) {
01518       eventout += "\n      (RX, RY, SX, SY) = (";
01519       eventout += TECW8RX[i];
01520       eventout += ", ";
01521       eventout += TECW8RY[i];
01522       eventout += ", ";
01523       eventout += TECW8SX[i];
01524       eventout += ", ";
01525       eventout += TECW8SY[i];
01526       eventout += ")";
01527     }
01528 
01529     // pixel output
01530     eventout += "\n         nBRL1     = ";
01531     eventout += BRL1RX.size();
01532     for (unsigned int i = 0; i < BRL1RX.size(); ++i) {
01533       eventout += "\n      (RX, RY, SX, SY) = (";
01534       eventout += BRL1RX[i];
01535       eventout += ", ";
01536       eventout += BRL1RY[i];
01537       eventout += ", ";
01538       eventout += BRL1SX[i];
01539       eventout += ", ";
01540       eventout += BRL1SY[i];
01541       eventout += ")";
01542     } 
01543     eventout += "\n         nBRL2     = ";
01544     eventout += BRL2RX.size();
01545     for (unsigned int i = 0; i < BRL2RX.size(); ++i) {
01546       eventout += "\n      (RX, RY, SX, SY) = (";
01547       eventout += BRL2RX[i];
01548       eventout += ", ";
01549       eventout += BRL2RY[i];
01550       eventout += ", ";
01551       eventout += BRL2SX[i];
01552       eventout += ", ";
01553       eventout += BRL2SY[i];
01554       eventout += ")";
01555     } 
01556     eventout += "\n         nBRL3     = ";
01557     eventout += BRL3RX.size();
01558     for (unsigned int i = 0; i < BRL3RX.size(); ++i) {
01559       eventout += "\n      (RX, RY, SX, SY) = (";
01560       eventout += BRL3RX[i];
01561       eventout += ", ";
01562       eventout += BRL3RY[i];
01563       eventout += ", ";
01564       eventout += BRL3SX[i];
01565       eventout += ", ";
01566       eventout += BRL3SY[i];
01567       eventout += ")";
01568     }    
01569     eventout += "\n         nFWD1p     = ";
01570     eventout += FWD1pRX.size();
01571     for (unsigned int i = 0; i < FWD1pRX.size(); ++i) {
01572       eventout += "\n      (RX, RY, SX, SY) = (";
01573       eventout += FWD1pRX[i];
01574       eventout += ", ";
01575       eventout += FWD1pRY[i];
01576       eventout += ", ";
01577       eventout += FWD1pSX[i];
01578       eventout += ", ";
01579       eventout += FWD1pSY[i];
01580       eventout += ")";
01581     } 
01582     eventout += "\n         nFWD1n     = ";
01583     eventout += FWD1nRX.size();
01584     for (unsigned int i = 0; i < FWD1nRX.size(); ++i) {
01585       eventout += "\n      (RX, RY, SX, SY) = (";
01586       eventout += FWD1nRX[i];
01587       eventout += ", ";
01588       eventout += FWD1nRY[i];
01589       eventout += ", ";
01590       eventout += FWD1nSX[i];
01591       eventout += ", ";
01592       eventout += FWD1nSY[i];
01593       eventout += ")";
01594     } 
01595     eventout += "\n         nFWD2p     = ";
01596     eventout += FWD2pRX.size();
01597     for (unsigned int i = 0; i < FWD2pRX.size(); ++i) {
01598       eventout += "\n      (RX, RY, SX, SY) = (";
01599       eventout += FWD2pRX[i];
01600       eventout += ", ";
01601       eventout += FWD2pRY[i];
01602       eventout += ", ";
01603       eventout += FWD2pSX[i];
01604       eventout += ", ";
01605       eventout += FWD2pSY[i];
01606       eventout += ")";
01607     }
01608     eventout += "\n         nFWD2p     = ";
01609     eventout += FWD2nRX.size();
01610     for (unsigned int i = 0; i < FWD2nRX.size(); ++i) {
01611       eventout += "\n      (RX, RY, SX, SY) = (";
01612       eventout += FWD2nRX[i];
01613       eventout += ", ";
01614       eventout += FWD2nRY[i];
01615       eventout += ", ";
01616       eventout += FWD2nSX[i];
01617       eventout += ", ";
01618       eventout += FWD2nSY[i];
01619       eventout += ")";
01620     } 
01621 
01622     edm::LogInfo(MsgLoggerCat) << eventout << "\n";  
01623   }
01624 
01625   // strip output
01626   product.putTIBL1RecHits(TIBL1RX,TIBL1RY,TIBL1SX,TIBL1SY);
01627   product.putTIBL2RecHits(TIBL2RX,TIBL2RY,TIBL2SX,TIBL2SY);
01628   product.putTIBL3RecHits(TIBL3RX,TIBL3RY,TIBL3SX,TIBL3SY);
01629   product.putTIBL4RecHits(TIBL4RX,TIBL4RY,TIBL4SX,TIBL4SY);
01630   product.putTOBL1RecHits(TOBL1RX,TOBL1RY,TOBL1SX,TOBL1SY);
01631   product.putTOBL2RecHits(TOBL2RX,TOBL2RY,TOBL2SX,TOBL2SY);
01632   product.putTOBL3RecHits(TOBL3RX,TOBL3RY,TOBL3SX,TOBL3SY);
01633   product.putTOBL4RecHits(TOBL4RX,TOBL4RY,TOBL4SX,TOBL4SY);
01634   product.putTIDW1RecHits(TIDW1RX,TIDW1RY,TIDW1SX,TIDW1SY);
01635   product.putTIDW2RecHits(TIDW2RX,TIDW2RY,TIDW2SX,TIDW2SY);
01636   product.putTIDW3RecHits(TIDW3RX,TIDW3RY,TIDW3SX,TIDW3SY);
01637   product.putTECW1RecHits(TECW1RX,TECW1RY,TECW1SX,TECW1SY);
01638   product.putTECW2RecHits(TECW2RX,TECW2RY,TECW2SX,TECW2SY);
01639   product.putTECW3RecHits(TECW3RX,TECW3RY,TECW3SX,TECW3SY);
01640   product.putTECW4RecHits(TECW4RX,TECW4RY,TECW4SX,TECW4SY);
01641   product.putTECW5RecHits(TECW5RX,TECW5RY,TECW5SX,TECW5SY);
01642   product.putTECW6RecHits(TECW6RX,TECW6RY,TECW6SX,TECW6SY);  
01643   product.putTECW7RecHits(TECW7RX,TECW7RY,TECW7SX,TECW7SY);
01644   product.putTECW8RecHits(TECW8RX,TECW8RY,TECW8SX,TECW8SY);  
01645 
01646   // pixel output
01647   product.putBRL1RecHits(BRL1RX,BRL1RY,BRL1SX,BRL1SY);
01648   product.putBRL2RecHits(BRL2RX,BRL2RY,BRL2SX,BRL2SY);
01649   product.putBRL3RecHits(BRL3RX,BRL3RY,BRL3SX,BRL3SY);
01650   product.putFWD1pRecHits(FWD1pRX,FWD1pRY,FWD1pSX,FWD1pSY);
01651   product.putFWD1nRecHits(FWD1nRX,FWD1nRY,FWD1nSX,FWD1nSY);
01652   product.putFWD2pRecHits(FWD2pRX,FWD2pRY,FWD2pSX,FWD2pSY);
01653   product.putFWD2nRecHits(FWD2nRX,FWD2nRY,FWD2nSX,FWD2nSY);
01654 
01655   return;
01656 }
01657 
01658 void GlobalRecHitsProducer::fillMuon(edm::Event& iEvent, 
01659                                    const edm::EventSetup& iSetup)
01660 {
01661   std::string MsgLoggerCat = "GlobalRecHitsProducer_fillMuon";
01662   
01663   TString eventout;
01664   if (verbosity > 0)
01665     eventout = "\nGathering info:";  
01666 
01667   // get DT information
01668   edm::ESHandle<DTGeometry> dtGeom;
01669   iSetup.get<MuonGeometryRecord>().get(dtGeom);
01670   if (!dtGeom.isValid()) {
01671     edm::LogWarning(MsgLoggerCat)
01672       << "Unable to find DTMuonGeometryRecord in event!";
01673     return;
01674   }  
01675 
01676   edm::Handle<edm::PSimHitContainer> dtsimHits;
01677   iEvent.getByLabel(MuDTSimSrc_, dtsimHits);
01678   if (!dtsimHits.isValid()) {
01679     edm::LogWarning(MsgLoggerCat)
01680       << "Unable to find dtsimHits in event!";
01681     return;
01682   } 
01683 
01684   std::map<DTWireId, edm::PSimHitContainer> simHitsPerWire =
01685     DTHitQualityUtils::mapSimHitsPerWire(*(dtsimHits.product()));
01686 
01687   edm::Handle<DTRecHitCollection> dtRecHits;
01688   iEvent.getByLabel(MuDTSrc_, dtRecHits);
01689   if (!dtRecHits.isValid()) {
01690     edm::LogWarning(MsgLoggerCat)
01691       << "Unable to find dtRecHits in event!";
01692     return;
01693   }   
01694 
01695   std::map<DTWireId, std::vector<DTRecHit1DPair> > recHitsPerWire =
01696     map1DRecHitsPerWire(dtRecHits.product());
01697 
01698 
01699   int nDt = compute(dtGeom.product(), simHitsPerWire, recHitsPerWire, 1);
01700                                                                     
01701   if (verbosity > 1) {
01702     eventout += "\n          Number of DtMuonRecHits collected:........ ";
01703     eventout += nDt;
01704   }
01705 
01706   // get CSC Strip information
01707   // get map of sim hits
01708   theMap.clear();
01709   //edm::Handle<CrossingFrame> cf;
01710   edm::Handle<CrossingFrame<PSimHit> > cf;
01711   //iEvent.getByType(cf);
01712   //if (!cf.isValid()) {
01713   //  edm::LogWarning(MsgLoggerCat)
01714   //    << "Unable to find CrossingFrame in event!";
01715   //  return;
01716   //}    
01717   //MixCollection<PSimHit> simHits(cf.product(), "MuonCSCHits");
01718   iEvent.getByLabel("mix","MuonCSCHits",cf);
01719   if (!cf.isValid()) {
01720     edm::LogWarning(MsgLoggerCat)
01721       << "Unable to find muo CSC  crossingFrame in event!";
01722     return;
01723   }
01724   MixCollection<PSimHit> simHits(cf.product());
01725 
01726   // arrange the hits by detUnit
01727   for(MixCollection<PSimHit>::MixItr hitItr = simHits.begin();
01728       hitItr != simHits.end(); ++hitItr)
01729   {
01730     theMap[hitItr->detUnitId()].push_back(*hitItr);
01731   }  
01732 
01733   // get geometry
01734   edm::ESHandle<CSCGeometry> hGeom;
01735   iSetup.get<MuonGeometryRecord>().get(hGeom);
01736   if (!hGeom.isValid()) {
01737     edm::LogWarning(MsgLoggerCat)
01738       << "Unable to find CSCMuonGeometryRecord in event!";
01739     return;
01740   }    
01741   const CSCGeometry *theCSCGeometry = &*hGeom;
01742 
01743   // get rechits
01744   edm::Handle<CSCRecHit2DCollection> hRecHits;
01745   iEvent.getByLabel(MuCSCSrc_, hRecHits);
01746   if (!hRecHits.isValid()) {
01747     edm::LogWarning(MsgLoggerCat)
01748       << "Unable to find CSC RecHits in event!";
01749     return;
01750   }    
01751   const CSCRecHit2DCollection *cscRecHits = hRecHits.product();
01752 
01753   int nCSC = 0;
01754   for (CSCRecHit2DCollection::const_iterator recHitItr = cscRecHits->begin();
01755        recHitItr != cscRecHits->end(); ++recHitItr) {
01756 
01757     int detId = (*recHitItr).cscDetId().rawId();
01758  
01759     edm::PSimHitContainer simHits;   
01760     std::map<int, edm::PSimHitContainer>::const_iterator mapItr = 
01761       theMap.find(detId);
01762     if (mapItr != theMap.end()) {
01763       simHits = mapItr->second;
01764     }
01765 
01766     if (simHits.size() == 1) {
01767       ++nCSC;
01768 
01769       const GeomDetUnit* detUnit = 
01770         theCSCGeometry->idToDetUnit(CSCDetId(detId));
01771       const CSCLayer *layer = dynamic_cast<const CSCLayer *>(detUnit); 
01772 
01773      int chamberType = layer->chamber()->specs()->chamberType();
01774       plotResolution(simHits[0], *recHitItr, layer, chamberType);
01775     }
01776   }
01777                                                 
01778   if (verbosity > 1) {
01779     eventout += "\n          Number of CSCRecHits collected:........... ";
01780     eventout += nCSC;
01781   }
01782 
01783   // get RPC information
01784   std::map<double, int> mapsim, maprec;
01785   std::map<int, double> nmapsim, nmaprec;
01786 
01787   edm::ESHandle<RPCGeometry> rpcGeom;
01788   iSetup.get<MuonGeometryRecord>().get(rpcGeom);
01789   if (!rpcGeom.isValid()) {
01790     edm::LogWarning(MsgLoggerCat)
01791       << "Unable to find RPCMuonGeometryRecord in event!";
01792     return;
01793   }  
01794 
01795   edm::Handle<edm::PSimHitContainer> simHit;
01796   iEvent.getByLabel(MuRPCSimSrc_, simHit);
01797   if (!simHit.isValid()) {
01798     edm::LogWarning(MsgLoggerCat)
01799       << "Unable to find RPCSimHit in event!";
01800     return;
01801   }    
01802 
01803   edm::Handle<RPCRecHitCollection> recHit;
01804   iEvent.getByLabel(MuRPCSrc_, recHit);
01805   if (!simHit.isValid()) {
01806     edm::LogWarning(MsgLoggerCat)
01807       << "Unable to find RPCRecHit in event!";
01808     return;
01809   } 
01810 
01811   int nRPC = 0;
01812   RPCRecHitCollection::const_iterator recIt;
01813   int nrec = 0;
01814   for (recIt = recHit->begin(); recIt != recHit->end(); ++recIt) {
01815     RPCDetId Rid = (RPCDetId)(*recIt).rpcId();
01816     const RPCRoll *roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(Rid));
01817     if (roll->isForward()) {
01818 
01819       if (verbosity > 1) {
01820         eventout += "\n          Number of RPCRecHits collected:........... ";
01821         eventout += nRPC;
01822       }
01823       
01824       if (verbosity > 0)
01825         edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01826       return;
01827     }
01828     nrec = nrec + 1;
01829     LocalPoint rhitlocal = (*recIt).localPosition();
01830     double rhitlocalx = rhitlocal.x();
01831     maprec[rhitlocalx] = nrec; 
01832   }
01833 
01834   int i = 0;
01835   for (std::map<double,int>::iterator iter = maprec.begin();
01836        iter != maprec.end(); ++iter) {
01837     i = i + 1;
01838     nmaprec[i] = (*iter).first;
01839   }
01840                   
01841   edm::PSimHitContainer::const_iterator simIt;
01842   int nsim = 0;
01843   for (simIt = simHit->begin(); simIt != simHit->end(); simIt++) {
01844     int ptype = (*simIt).particleType();
01845     //RPCDetId Rsid = (RPCDetId)(*simIt).detUnitId();
01846     if (ptype == 13 || ptype == -13) {
01847       nsim = nsim + 1;
01848       LocalPoint shitlocal = (*simIt).localPosition();
01849       double shitlocalx = shitlocal.x();
01850       mapsim[shitlocalx] = nsim;
01851     }
01852   }
01853 
01854   i = 0;
01855   for (std::map<double,int>::iterator iter = mapsim.begin();
01856        iter != mapsim.end(); ++iter) {
01857     i = i + 1;
01858     nmapsim[i] = (*iter).first;
01859   }
01860 
01861   if (nsim == nrec) {
01862     for (int r = 0; r < nsim; r++) {
01863       ++nRPC;
01864       RPCRHX.push_back(nmaprec[r+1]);
01865       RPCSHX.push_back(nmapsim[r+1]);
01866     }
01867   }
01868                                                                   
01869   if (verbosity > 1) {
01870     eventout += "\n          Number of RPCRecHits collected:........... ";
01871     eventout += nRPC;
01872   }
01873 
01874   if (verbosity > 0)
01875     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01876   
01877   return;
01878 }
01879 
01880 void GlobalRecHitsProducer::storeMuon(PGlobalRecHit& product)
01881 {
01882   std::string MsgLoggerCat = "GlobalRecHitsProducer_storeMuon";
01883 
01884   if (verbosity > 2) {
01885 
01886     // dt output
01887     TString eventout("\n         nDT     = ");
01888     eventout += DTRHD.size();
01889     for (unsigned int i = 0; i < DTRHD.size(); ++i) {
01890       eventout += "\n      (RHD, SHD) = (";
01891       eventout += DTRHD[i];
01892       eventout += ", ";
01893       eventout += DTSHD[i];
01894       eventout += ")";
01895     }
01896 
01897     // CSC Strip
01898     eventout += "\n         nCSC     = ";
01899     eventout += CSCRHPHI.size();
01900     for (unsigned int i = 0; i < CSCRHPHI.size(); ++i) {
01901       eventout += "\n      (rhphi, rhperp, shphi) = (";
01902       eventout += CSCRHPHI[i];
01903       eventout += ", ";
01904       eventout += CSCRHPERP[i];
01905       eventout += ", ";
01906       eventout += CSCSHPHI[i];
01907       eventout += ")";
01908     }    
01909 
01910     // RPC
01911     eventout += "\n         nRPC     = ";
01912     eventout += RPCRHX.size();
01913     for (unsigned int i = 0; i < RPCRHX.size(); ++i) {
01914       eventout += "\n      (rhx, shx) = (";
01915       eventout += RPCRHX[i];
01916       eventout += ", ";
01917       eventout += RPCSHX[i];
01918       eventout += ")";
01919     }    
01920 
01921     edm::LogInfo(MsgLoggerCat) << eventout << "\n";  
01922   }
01923   
01924   product.putDTRecHits(DTRHD,DTSHD);
01925 
01926   product.putCSCRecHits(CSCRHPHI,CSCRHPERP,CSCSHPHI);
01927 
01928   product.putRPCRecHits(RPCRHX,RPCSHX);
01929 
01930   return;
01931 }
01932 
01933 void GlobalRecHitsProducer::clear()
01934 {
01935   std::string MsgLoggerCat = "GlobalRecHitsProducer_clear";
01936 
01937   if (verbosity > 0)
01938     edm::LogInfo(MsgLoggerCat)
01939       << "Clearing event holders"; 
01940 
01941   // reset electromagnetic info
01942   // EE info
01943   EERE.clear(); 
01944   EESHE.clear(); 
01945   // EB info
01946   EBRE.clear();  
01947   EBSHE.clear();
01948   // ES info
01949   ESRE.clear();
01950   ESSHE.clear();
01951 
01952   // reset HCal Info
01953   HBCalREC.clear();
01954   HBCalR.clear();
01955   HBCalSHE.clear();
01956   HECalREC.clear();
01957   HECalR.clear();
01958   HECalSHE.clear();
01959   HOCalREC.clear();
01960   HOCalR.clear();
01961   HOCalSHE.clear();
01962   HFCalREC.clear();
01963   HFCalR.clear();
01964   HFCalSHE.clear();  
01965 
01966   // reset Track Info
01967   TIBL1RX.clear(); 
01968   TIBL2RX.clear(); 
01969   TIBL3RX.clear(); 
01970   TIBL4RX.clear();
01971   TIBL1RY.clear(); 
01972   TIBL2RY.clear(); 
01973   TIBL3RY.clear(); 
01974   TIBL4RY.clear();
01975   TIBL1SX.clear(); 
01976   TIBL2SX.clear(); 
01977   TIBL3SX.clear(); 
01978   TIBL4SX.clear();
01979   TIBL1SY.clear(); 
01980   TIBL2SY.clear(); 
01981   TIBL3SY.clear(); 
01982   TIBL4SY.clear();  
01983 
01984   TOBL1RX.clear(); 
01985   TOBL2RX.clear(); 
01986   TOBL3RX.clear(); 
01987   TOBL4RX.clear();
01988   TOBL1RY.clear(); 
01989   TOBL2RY.clear(); 
01990   TOBL3RY.clear(); 
01991   TOBL4RY.clear();
01992   TOBL1SX.clear(); 
01993   TOBL2SX.clear(); 
01994   TOBL3SX.clear(); 
01995   TOBL4SX.clear();
01996   TOBL1SY.clear(); 
01997   TOBL2SY.clear(); 
01998   TOBL3SY.clear(); 
01999   TOBL4SY.clear();  
02000 
02001   TIDW1RX.clear(); 
02002   TIDW2RX.clear(); 
02003   TIDW3RX.clear(); 
02004   TIDW1RY.clear(); 
02005   TIDW2RY.clear(); 
02006   TIDW3RY.clear(); 
02007   TIDW1SX.clear(); 
02008   TIDW2SX.clear(); 
02009   TIDW3SX.clear();
02010   TIDW1SY.clear(); 
02011   TIDW2SY.clear(); 
02012   TIDW3SY.clear();  
02013 
02014   TECW1RX.clear();  
02015   TECW2RX.clear();  
02016   TECW3RX.clear();  
02017   TECW4RX.clear();  
02018   TECW5RX.clear();  
02019   TECW6RX.clear();  
02020   TECW7RX.clear();  
02021   TECW8RX.clear();  
02022   TECW1RY.clear();  
02023   TECW2RY.clear();  
02024   TECW3RY.clear();  
02025   TECW4RY.clear();  
02026   TECW5RY.clear();  
02027   TECW6RY.clear();  
02028   TECW7RY.clear();  
02029   TECW8RY.clear();  
02030   TECW1SX.clear();  
02031   TECW2SX.clear();  
02032   TECW3SX.clear();  
02033   TECW4SX.clear();  
02034   TECW5SX.clear();  
02035   TECW6SX.clear();  
02036   TECW7SX.clear();  
02037   TECW8SX.clear();  
02038   TECW1SY.clear();  
02039   TECW2SY.clear();  
02040   TECW3SY.clear();  
02041   TECW4SY.clear();  
02042   TECW5SY.clear();  
02043   TECW6SY.clear();  
02044   TECW7SY.clear();  
02045   TECW8SY.clear();  
02046 
02047   BRL1RX.clear();
02048   BRL1RY.clear();
02049   BRL1SX.clear();
02050   BRL1SY.clear();
02051   BRL2RX.clear();
02052   BRL2RY.clear();
02053   BRL2SX.clear();
02054   BRL2SY.clear();
02055   BRL3RX.clear();
02056   BRL3RY.clear();
02057   BRL3SX.clear();
02058   BRL3SY.clear();
02059 
02060   FWD1pRX.clear();
02061   FWD1pRY.clear();
02062   FWD1pSX.clear();
02063   FWD1pSY.clear();
02064   FWD1nRX.clear();
02065   FWD1nRY.clear();
02066   FWD1nSX.clear();
02067   FWD1nSY.clear();
02068   FWD2pRX.clear();
02069   FWD2pRY.clear();
02070   FWD2pSX.clear();
02071   FWD2pSY.clear();
02072   FWD2nRX.clear();
02073   FWD2nRY.clear();
02074   FWD2nSX.clear();
02075   FWD2nSY.clear();
02076 
02077   //muon clear
02078   DTRHD.clear();
02079   DTSHD.clear();
02080 
02081   CSCRHPHI.clear();
02082   CSCRHPERP.clear();
02083   CSCSHPHI.clear();
02084 
02085   RPCRHX.clear();
02086   RPCSHX.clear();
02087 
02088   return;
02089 }
02090 
02091 //needed by to do the residual for matched hits in SiStrip
02092 std::pair<LocalPoint,LocalVector> 
02093 GlobalRecHitsProducer::projectHit(const PSimHit& hit, 
02094                                   const StripGeomDetUnit* stripDet,
02095                                   const BoundPlane& plane) 
02096 {
02097   
02098   const StripTopology& topol = stripDet->specificTopology();
02099   GlobalPoint globalpos= stripDet->surface().toGlobal(hit.localPosition());
02100   LocalPoint localHit = plane.toLocal(globalpos);
02101   //track direction
02102   LocalVector locdir=hit.localDirection();
02103   //rotate track in new frame
02104   
02105   GlobalVector globaldir= stripDet->surface().toGlobal(locdir);
02106   LocalVector dir=plane.toLocal(globaldir);
02107   float scale = -localHit.z() / dir.z();
02108   
02109   LocalPoint projectedPos = localHit + scale*dir;
02110     
02111   float selfAngle = topol.stripAngle( topol.strip( hit.localPosition()));
02112 
02113   // vector along strip in hit frame 
02114   LocalVector stripDir( sin(selfAngle), cos(selfAngle), 0); 
02115   
02116   LocalVector 
02117     localStripDir(plane.toLocal(stripDet->surface().toGlobal(stripDir)));
02118   
02119   return std::pair<LocalPoint,LocalVector>( projectedPos, localStripDir);
02120 }
02121 
02122 // Return a map between DTRecHit1DPair and wireId
02123 std::map<DTWireId, std::vector<DTRecHit1DPair> >
02124 GlobalRecHitsProducer::map1DRecHitsPerWire(const DTRecHitCollection* 
02125                                            dt1DRecHitPairs) {
02126   std::map<DTWireId, std::vector<DTRecHit1DPair> > ret;
02127   
02128   for(DTRecHitCollection::const_iterator rechit = dt1DRecHitPairs->begin();
02129       rechit != dt1DRecHitPairs->end(); rechit++) {
02130     ret[(*rechit).wireId()].push_back(*rechit);
02131   }
02132   
02133   return ret;
02134 }
02135 
02136 // Compute SimHit distance from wire (cm)
02137 float GlobalRecHitsProducer::simHitDistFromWire(const DTLayer* layer,
02138                                                 DTWireId wireId,
02139                                                 const PSimHit& hit) {
02140   float xwire = layer->specificTopology().wirePosition(wireId.wire());
02141   LocalPoint entryP = hit.entryPoint();
02142   LocalPoint exitP = hit.exitPoint();
02143   float xEntry = entryP.x()-xwire;
02144   float xExit  = exitP.x()-xwire;
02145 
02146   //FIXME: check...  
02147   return fabs(xEntry - (entryP.z()*(xExit-xEntry))/(exitP.z()-entryP.z()));
02148 }
02149 
02150 // Find the RecHit closest to the muon SimHit
02151 template  <typename type>
02152 const type* 
02153 GlobalRecHitsProducer::findBestRecHit(const DTLayer* layer,
02154                                       DTWireId wireId,
02155                                       const std::vector<type>& recHits,
02156                                       const float simHitDist) {
02157   float res = 99999;
02158   const type* theBestRecHit = 0;
02159   // Loop over RecHits within the cell
02160   for(typename std::vector<type>::const_iterator recHit = recHits.begin();
02161       recHit != recHits.end();
02162       recHit++) {
02163     float distTmp = recHitDistFromWire(*recHit, layer);
02164     if(fabs(distTmp-simHitDist) < res) {
02165       res = fabs(distTmp-simHitDist);
02166       theBestRecHit = &(*recHit);
02167     }
02168   } // End of loop over RecHits within the cell
02169   
02170   return theBestRecHit;
02171 }
02172 
02173 // Compute the distance from wire (cm) of a hits in a DTRecHit1DPair
02174 float 
02175 GlobalRecHitsProducer::recHitDistFromWire(const DTRecHit1DPair& hitPair, 
02176                                           const DTLayer* layer) {
02177   // Compute the rechit distance from wire
02178   return fabs(hitPair.localPosition(DTEnums::Left).x() -
02179               hitPair.localPosition(DTEnums::Right).x())/2.;
02180 }
02181 
02182 // Compute the distance from wire (cm) of a hits in a DTRecHit1D
02183 float 
02184 GlobalRecHitsProducer::recHitDistFromWire(const DTRecHit1D& recHit, 
02185                                           const DTLayer* layer) {
02186   return fabs(recHit.localPosition().x() - 
02187               layer->specificTopology().wirePosition(recHit.wireId().wire()));
02188 }
02189 
02190 template  <typename type>
02191 int GlobalRecHitsProducer::compute(const DTGeometry *dtGeom,
02192                                    std::map<DTWireId, std::vector<PSimHit> > 
02193                                    simHitsPerWire,
02194                                    std::map<DTWireId, std::vector<type> > 
02195                                    recHitsPerWire,
02196                                    int step) {
02197 
02198   int nDt = 0;
02199   // Loop over cells with a muon SimHit
02200   for(std::map<DTWireId, std::vector<PSimHit> >::const_iterator wireAndSHits = 
02201         simHitsPerWire.begin();
02202       wireAndSHits != simHitsPerWire.end();
02203       wireAndSHits++) {
02204     DTWireId wireId = (*wireAndSHits).first;
02205     std::vector<PSimHit> simHitsInCell = (*wireAndSHits).second;
02206     
02207     // Get the layer
02208     const DTLayer* layer = dtGeom->layer(wireId);
02209     
02210     // Look for a mu hit in the cell
02211     const PSimHit* muSimHit = DTHitQualityUtils::findMuSimHit(simHitsInCell);
02212     if (muSimHit==0) {
02213       continue; // Skip this cell
02214     }
02215 
02216     // Find the distance of the simhit from the wire
02217     float simHitWireDist = simHitDistFromWire(layer, wireId, *muSimHit);
02218     // Skip simhits out of the cell
02219     if(simHitWireDist>2.1) {
02220       continue; // Skip this cell
02221     }
02222     //GlobalPoint simHitGlobalPos = layer->toGlobal(muSimHit->localPosition());
02223 
02224     // Look for RecHits in the same cell
02225     if(recHitsPerWire.find(wireId) == recHitsPerWire.end()) {
02226       continue; // No RecHit found in this cell
02227     } else {
02228 
02229       // vector<type> recHits = (*wireAndRecHits).second;
02230       std::vector<type> recHits = recHitsPerWire[wireId];
02231          
02232       // Find the best RecHit
02233       const type* theBestRecHit = 
02234         findBestRecHit(layer, wireId, recHits, simHitWireDist);
02235  
02236       float recHitWireDist =  recHitDistFromWire(*theBestRecHit, layer);
02237       
02238       ++nDt;
02239 
02240       DTRHD.push_back(recHitWireDist);
02241       DTSHD.push_back(simHitWireDist);
02242       
02243     } // find rechits
02244   } // loop over simhits
02245 
02246   return nDt;
02247 }
02248 
02249 void 
02250 GlobalRecHitsProducer::plotResolution(const PSimHit & simHit, 
02251                                       const CSCRecHit2D & recHit,
02252                                       const CSCLayer * layer, 
02253                                       int chamberType) {
02254   GlobalPoint simHitPos = layer->toGlobal(simHit.localPosition());
02255   GlobalPoint recHitPos = layer->toGlobal(recHit.localPosition());
02256   
02257   CSCRHPHI.push_back(recHitPos.phi());
02258   CSCRHPERP.push_back(recHitPos.perp());
02259   CSCSHPHI.push_back(simHitPos.phi());
02260 }
02261 
02262 //define this as a plug-in
02263 //DEFINE_FWK_MODULE(GlobalRecHitsProducer);

Generated on Tue Jun 9 17:49:23 2009 for CMSSW by  doxygen 1.5.4