CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Validation/GlobalHits/src/GlobalHitsProducer.cc

Go to the documentation of this file.
00001 
00010 #include "Validation/GlobalHits/interface/GlobalHitsProducer.h"
00011 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00012 
00013 GlobalHitsProducer::GlobalHitsProducer(const edm::ParameterSet& iPSet) :
00014   fName(""), verbosity(0), frequency(0), vtxunit(0), label(""), 
00015   getAllProvenances(false), printProvenanceInfo(false), nRawGenPart(0), 
00016   //ECalEBSrc_(""), ECalEESrc_(""), ECalESSrc_(""), HCalSrc_(""),
00017   //PxlBrlLowSrc_(""), PxlBrlHighSrc_(""), PxlFwdLowSrc_(""),
00018   //PxlFwdHighSrc_(""), SiTIBLowSrc_(""), SiTIBHighSrc_(""),
00019   //SiTOBLowSrc_(""), SiTOBHighSrc_(""), SiTIDLowSrc_(""), 
00020   //SiTIDHighSrc_(""), SiTECLowSrc_(""), SiTECHighSrc_(""),
00021   //MuonDtSrc_(""), MuonCscSrc_(""), MuonRpcSrc_(""), 
00022   count(0)
00023 {
00024   std::string MsgLoggerCat = "GlobalHitsProducer_GlobalHitsProducer";
00025 
00026   // get information from parameter set
00027   fName = iPSet.getUntrackedParameter<std::string>("Name");
00028   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
00029   frequency = iPSet.getUntrackedParameter<int>("Frequency");
00030   vtxunit = iPSet.getUntrackedParameter<int>("VtxUnit");
00031   label = iPSet.getParameter<std::string>("Label");
00032   edm::ParameterSet m_Prov =
00033     iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
00034   getAllProvenances = 
00035     m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
00036   printProvenanceInfo = 
00037     m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
00038 
00039   //get Labels to use to extract information
00040   PxlBrlLowSrc_ = iPSet.getParameter<edm::InputTag>("PxlBrlLowSrc");
00041   PxlBrlHighSrc_ = iPSet.getParameter<edm::InputTag>("PxlBrlHighSrc");
00042   PxlFwdLowSrc_ = iPSet.getParameter<edm::InputTag>("PxlFwdLowSrc");
00043   PxlFwdHighSrc_ = iPSet.getParameter<edm::InputTag>("PxlFwdHighSrc");
00044 
00045   SiTIBLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTIBLowSrc");
00046   SiTIBHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTIBHighSrc");
00047   SiTOBLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTOBLowSrc");
00048   SiTOBHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTOBHighSrc");
00049   SiTIDLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTIDLowSrc");
00050   SiTIDHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTIDHighSrc");
00051   SiTECLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTECLowSrc");
00052   SiTECHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTECHighSrc");
00053 
00054   MuonCscSrc_ = iPSet.getParameter<edm::InputTag>("MuonCscSrc");
00055   MuonDtSrc_ = iPSet.getParameter<edm::InputTag>("MuonDtSrc");
00056   MuonRpcSrc_ = iPSet.getParameter<edm::InputTag>("MuonRpcSrc");
00057 
00058   ECalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalEBSrc");
00059   ECalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalEESrc");
00060   ECalESSrc_ = iPSet.getParameter<edm::InputTag>("ECalESSrc");
00061 
00062   HCalSrc_ = iPSet.getParameter<edm::InputTag>("HCalSrc");
00063 
00064   // use value of first digit to determine default output level (inclusive)
00065   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
00066   verbosity %= 10;
00067 
00068   // create persistent object
00069   produces<PGlobalSimHit>(label);
00070 
00071   // print out Parameter Set information being used
00072   if (verbosity >= 0) {
00073     edm::LogInfo(MsgLoggerCat) 
00074       << "\n===============================\n"
00075       << "Initialized as EDProducer with parameter values:\n"
00076       << "    Name          = " << fName << "\n"
00077       << "    Verbosity     = " << verbosity << "\n"
00078       << "    Frequency     = " << frequency << "\n"
00079       << "    VtxUnit       = " << vtxunit << "\n"
00080       << "    Label         = " << label << "\n"
00081       << "    GetProv       = " << getAllProvenances << "\n"
00082       << "    PrintProv     = " << printProvenanceInfo << "\n"
00083       << "    PxlBrlLowSrc  = " << PxlBrlLowSrc_.label() 
00084       << ":" << PxlBrlLowSrc_.instance() << "\n"
00085       << "    PxlBrlHighSrc = " << PxlBrlHighSrc_.label() 
00086       << ":" << PxlBrlHighSrc_.instance() << "\n"
00087       << "    PxlFwdLowSrc  = " << PxlFwdLowSrc_.label() 
00088       << ":" << PxlBrlLowSrc_.instance() << "\n"
00089       << "    PxlFwdHighSrc = " << PxlFwdHighSrc_.label() 
00090       << ":" << PxlBrlHighSrc_.instance() << "\n"
00091       << "    SiTIBLowSrc   = " << SiTIBLowSrc_.label() 
00092       << ":" << SiTIBLowSrc_.instance() << "\n"
00093       << "    SiTIBHighSrc  = " << SiTIBHighSrc_.label() 
00094       << ":" << SiTIBHighSrc_.instance() << "\n"
00095       << "    SiTOBLowSrc   = " << SiTOBLowSrc_.label() 
00096       << ":" << SiTOBLowSrc_.instance() << "\n"
00097       << "    SiTOBHighSrc  = " << SiTOBHighSrc_.label() 
00098       << ":" << SiTOBHighSrc_.instance() << "\n"
00099       << "    SiTIDLowSrc   = " << SiTIDLowSrc_.label() 
00100       << ":" << SiTIDLowSrc_.instance() << "\n"
00101       << "    SiTIDHighSrc  = " << SiTIDHighSrc_.label() 
00102       << ":" << SiTIDHighSrc_.instance() << "\n"
00103       << "    SiTECLowSrc   = " << SiTECLowSrc_.label() 
00104       << ":" << SiTECLowSrc_.instance() << "\n"
00105       << "    SiTECHighSrc  = " << SiTECHighSrc_.label() 
00106       << ":" << SiTECHighSrc_.instance() << "\n"
00107       << "    MuonCscSrc    = " << MuonCscSrc_.label() 
00108       << ":" << MuonCscSrc_.instance() << "\n"
00109       << "    MuonDtSrc     = " << MuonDtSrc_.label() 
00110       << ":" << MuonDtSrc_.instance() << "\n"
00111       << "    MuonRpcSrc    = " << MuonRpcSrc_.label() 
00112       << ":" << MuonRpcSrc_.instance() << "\n"
00113       << "    ECalEBSrc     = " << ECalEBSrc_.label() 
00114       << ":" << ECalEBSrc_.instance() << "\n"
00115       << "    ECalEESrc     = " << ECalEESrc_.label() 
00116       << ":" << ECalEESrc_.instance() << "\n"
00117       << "    ECalESSrc     = " << ECalESSrc_.label() 
00118       << ":" << ECalESSrc_.instance() << "\n"
00119       << "    HCalSrc       = " << HCalSrc_.label() 
00120       << ":" << HCalSrc_.instance() << "\n"
00121       << "===============================\n";
00122   }
00123 
00124   // migrated here from beginJob
00125   clear();
00126 
00127 }
00128 
00129 GlobalHitsProducer::~GlobalHitsProducer() 
00130 {
00131 }
00132 
00133 void GlobalHitsProducer::beginJob( void )
00134 {
00135   return;
00136 }
00137 
00138 void GlobalHitsProducer::endJob()
00139 {
00140   std::string MsgLoggerCat = "GlobalHitsProducer_endJob";
00141   if (verbosity >= 0)
00142     edm::LogInfo(MsgLoggerCat) 
00143       << "Terminating having processed " << count << " events.";
00144   return;
00145 }
00146 
00147 void GlobalHitsProducer::produce(edm::Event& iEvent, 
00148                                const edm::EventSetup& iSetup)
00149 {
00150   std::string MsgLoggerCat = "GlobalHitsProducer_produce";
00151 
00152   // keep track of number of events processed
00153   ++count;
00154 
00155   // get event id information
00156   int nrun = iEvent.id().run();
00157   int nevt = iEvent.id().event();
00158 
00159   if (verbosity > 0) {
00160     edm::LogInfo(MsgLoggerCat)
00161       << "Processing run " << nrun << ", event " << nevt
00162       << " (" << count << " events total)";
00163   } else if (verbosity == 0) {
00164     if (nevt%frequency == 0 || nevt == 1) {
00165       edm::LogInfo(MsgLoggerCat)
00166         << "Processing run " << nrun << ", event " << nevt
00167         << " (" << count << " events total)";
00168     }
00169   }
00170 
00171   // clear event holders
00172   clear();
00173 
00174   // look at information available in the event
00175   if (getAllProvenances) {
00176 
00177     std::vector<const edm::Provenance*> AllProv;
00178     iEvent.getAllProvenance(AllProv);
00179 
00180     if (verbosity >= 0)
00181       edm::LogInfo(MsgLoggerCat)
00182         << "Number of Provenances = " << AllProv.size();
00183 
00184     if (printProvenanceInfo && (verbosity >= 0)) {
00185       TString eventout("\nProvenance info:\n");      
00186 
00187       for (unsigned int i = 0; i < AllProv.size(); ++i) {
00188         eventout += "\n       ******************************";
00189         eventout += "\n       Module       : ";
00190         eventout += AllProv[i]->moduleLabel();
00191         eventout += "\n       ProductID    : ";
00192         eventout += AllProv[i]->productID().id();
00193         eventout += "\n       ClassName    : ";
00194         eventout += AllProv[i]->className();
00195         eventout += "\n       InstanceName : ";
00196         eventout += AllProv[i]->productInstanceName();
00197         eventout += "\n       BranchName   : ";
00198         eventout += AllProv[i]->branchName();
00199       }
00200       eventout += "\n       ******************************\n";
00201       edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00202       printProvenanceInfo = false;
00203     }
00204     getAllProvenances = false;
00205   }
00206 
00207   // call fill functions
00208   //gather G4MC information from event
00209   fillG4MC(iEvent);
00210   // gather Tracker information from event
00211   fillTrk(iEvent,iSetup);
00212   // gather muon information from event
00213   fillMuon(iEvent, iSetup);
00214   // gather Ecal information from event
00215   fillECal(iEvent, iSetup);
00216   // gather Hcal information from event
00217   fillHCal(iEvent, iSetup);
00218 
00219   if (verbosity > 0)
00220     edm::LogInfo (MsgLoggerCat)
00221       << "Done gathering data from event.";
00222 
00223   // produce object to put into event
00224   std::auto_ptr<PGlobalSimHit> pOut(new PGlobalSimHit);
00225 
00226   if (verbosity > 2)
00227     edm::LogInfo (MsgLoggerCat)
00228       << "Saving event contents:";
00229 
00230   // call store functions
00231   // store G4MC information in product
00232   storeG4MC(*pOut);
00233   // store Tracker information in produce
00234   storeTrk(*pOut);
00235   // store Muon information in produce
00236   storeMuon(*pOut);
00237   // store ECal information in produce
00238   storeECal(*pOut);
00239   // store HCal information in produce
00240   storeHCal(*pOut);
00241 
00242   // store information in event
00243   iEvent.put(pOut,label);
00244 
00245   return;
00246 }
00247 
00248 //==================fill and store functions================================
00249 void GlobalHitsProducer::fillG4MC(edm::Event& iEvent)
00250 {
00251 
00252   std::string MsgLoggerCat = "GlobalHitsProducer_fillG4MC";
00253  
00254   TString eventout;
00255   if (verbosity > 0)
00256     eventout = "\nGathering info:";
00257 
00259   // get MC information
00261   edm::Handle<edm::HepMCProduct> HepMCEvt;
00262   std::vector<edm::Handle<edm::HepMCProduct> > AllHepMCEvt;
00263   iEvent.getManyByType(AllHepMCEvt);
00264 
00265   // loop through products and extract VtxSmearing if available. Any of them
00266   // should have the information needed
00267   for (unsigned int i = 0; i < AllHepMCEvt.size(); ++i) {
00268     HepMCEvt = AllHepMCEvt[i];
00269     if ((HepMCEvt.provenance()->product()).moduleLabel() == "VtxSmeared")
00270       break;
00271   }
00272 
00273   if (!HepMCEvt.isValid()) {
00274     edm::LogWarning(MsgLoggerCat)
00275       << "Unable to find HepMCProduct in event!";
00276     return;
00277   } else {
00278     eventout += "\n          Using HepMCProduct: ";
00279     eventout += (HepMCEvt.provenance()->product()).moduleLabel();
00280   }
00281   const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
00282   nRawGenPart = MCEvt->particles_size();
00283 
00284   if (verbosity > 1) {
00285     eventout += "\n          Number of Raw Particles collected:......... ";
00286     eventout += nRawGenPart;
00287   }  
00288 
00290   // get G4Vertex information
00292   // convert unit stored in SimVertex to mm
00293   float unit = 0.;
00294   if (vtxunit == 0) unit = 1.;  // already in mm
00295   if (vtxunit == 1) unit = 10.; // stored in cm, convert to mm
00296 
00297   edm::Handle<edm::SimVertexContainer> G4VtxContainer;
00298   iEvent.getByType(G4VtxContainer);
00299   if (!G4VtxContainer.isValid()) {
00300     edm::LogWarning(MsgLoggerCat)
00301       << "Unable to find SimVertex in event!";
00302     return;
00303   }
00304   int i = 0;
00305   edm::SimVertexContainer::const_iterator itVtx;
00306   for (itVtx = G4VtxContainer->begin(); itVtx != G4VtxContainer->end(); 
00307        ++itVtx) {
00308     
00309     ++i;
00310 
00311     const math::XYZTLorentzVector G4Vtx1(itVtx->position().x(),
00312                                          itVtx->position().y(),
00313                                          itVtx->position().z(),
00314                                          itVtx->position().e());
00315     double G4Vtx[4];
00316     G4Vtx1.GetCoordinates(G4Vtx);
00317 
00318     G4VtxX.push_back((G4Vtx[0]*unit)/micrometer);
00319     G4VtxY.push_back((G4Vtx[1]*unit)/micrometer);
00320     G4VtxZ.push_back((G4Vtx[2]*unit)/millimeter);
00321   }
00322 
00323   if (verbosity > 1) {
00324     eventout += "\n          Number of G4Vertices collected:............ ";
00325     eventout += i;
00326   }  
00327 
00329   // get G4Track information
00331   edm::Handle<edm::SimTrackContainer> G4TrkContainer;
00332   iEvent.getByType(G4TrkContainer);
00333   if (!G4TrkContainer.isValid()) {
00334     edm::LogWarning(MsgLoggerCat)
00335       << "Unable to find SimTrack in event!";
00336     return;
00337   }
00338   i = 0;
00339   edm::SimTrackContainer::const_iterator itTrk;
00340   for (itTrk = G4TrkContainer->begin(); itTrk != G4TrkContainer->end(); 
00341        ++itTrk) {
00342 
00343     ++i;
00344 
00345     const math::XYZTLorentzVector G4Trk1(itTrk->momentum().x(),
00346                                          itTrk->momentum().y(),
00347                                          itTrk->momentum().z(),
00348                                          itTrk->momentum().e());
00349     double G4Trk[4];
00350     G4Trk1.GetCoordinates(G4Trk);
00351 
00352     G4TrkPt.push_back(sqrt(G4Trk[0]*G4Trk[0]+G4Trk[1]*G4Trk[1])); //GeV
00353     G4TrkE.push_back(G4Trk[3]);                                   //GeV
00354   } 
00355 
00356   if (verbosity > 1) {
00357     eventout += "\n          Number of G4Tracks collected:.............. ";
00358     eventout += i;
00359   }  
00360 
00361   if (verbosity > 0)
00362     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00363 
00364   return;
00365 }
00366 
00367 void GlobalHitsProducer::storeG4MC(PGlobalSimHit& product)
00368 {
00369   std::string MsgLoggerCat = "GlobalHitsProducer_storeG4MC";
00370 
00371   if (verbosity > 2) {
00372     TString eventout("\n       nRawGenPart        = ");
00373     eventout += nRawGenPart;
00374     eventout += "\n       nG4Vtx             = ";
00375     eventout += G4VtxX.size();
00376     for (unsigned int i = 0; i < G4VtxX.size(); ++i) {
00377       eventout += "\n          (x,y,z)         = (";
00378       eventout += G4VtxX[i];
00379       eventout += ", ";
00380       eventout += G4VtxY[i];
00381       eventout += ", ";
00382       eventout += G4VtxZ[i];
00383       eventout += ")";      
00384     }
00385     eventout += "\n       nG4Trk             = ";
00386     eventout += G4TrkPt.size();
00387     for (unsigned int i = 0; i < G4TrkPt.size(); ++i) {
00388       eventout += "\n          (pt,e)          = (";
00389       eventout += G4TrkPt[i];
00390       eventout += ", ";
00391       eventout += G4TrkE[i];
00392       eventout += ")";
00393     }    
00394     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00395   } // end verbose output
00396 
00397   product.putRawGenPart(nRawGenPart);
00398   product.putG4Vtx(G4VtxX, G4VtxY, G4VtxZ);
00399   product.putG4Trk(G4TrkPt, G4TrkE);
00400 
00401   return;
00402 }
00403 
00404 void GlobalHitsProducer::fillTrk(edm::Event& iEvent, 
00405                                 const edm::EventSetup& iSetup)
00406 {
00407   std::string MsgLoggerCat = "GlobalHitsProducer_fillTrk";
00408 
00409   TString eventout;
00410   if (verbosity > 0)
00411     eventout = "\nGathering info:";  
00412   
00413   // access the tracker geometry
00414   edm::ESHandle<TrackerGeometry> theTrackerGeometry;
00415   iSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
00416   if (!theTrackerGeometry.isValid()) {
00417     edm::LogWarning(MsgLoggerCat)
00418       << "Unable to find TrackerDigiGeometryRecord in event!";
00419     return;
00420   }
00421   const TrackerGeometry& theTracker(*theTrackerGeometry);
00422     
00423   // iterator to access containers
00424   edm::PSimHitContainer::const_iterator itHit;
00425 
00427   // get Pixel Barrel information
00429   edm::PSimHitContainer thePxlBrlHits;
00430   // extract low container
00431   edm::Handle<edm::PSimHitContainer> PxlBrlLowContainer;
00432   iEvent.getByLabel(PxlBrlLowSrc_,PxlBrlLowContainer);
00433   if (!PxlBrlLowContainer.isValid()) {
00434     edm::LogWarning(MsgLoggerCat)
00435       << "Unable to find TrackerHitsPixelBarrelLowTof in event!";
00436     return;
00437   }
00438   // extract high container
00439   edm::Handle<edm::PSimHitContainer> PxlBrlHighContainer;
00440   iEvent.getByLabel(PxlBrlHighSrc_,PxlBrlHighContainer);
00441   if (!PxlBrlHighContainer.isValid()) {
00442     edm::LogWarning(MsgLoggerCat)
00443       << "Unable to find TrackerHitsPixelBarrelHighTof in event!";
00444     return;
00445   }
00446   // place both containers into new container
00447   thePxlBrlHits.insert(thePxlBrlHits.end(),PxlBrlLowContainer->begin(),
00448                        PxlBrlLowContainer->end());
00449   thePxlBrlHits.insert(thePxlBrlHits.end(),PxlBrlHighContainer->begin(),
00450                        PxlBrlHighContainer->end());
00451 
00452   // cycle through new container
00453   int i = 0, j = 0;
00454   for (itHit = thePxlBrlHits.begin(); itHit != thePxlBrlHits.end(); ++itHit) {
00455 
00456     ++i;
00457 
00458     // create a DetId from the detUnitId
00459     DetId theDetUnitId(itHit->detUnitId());
00460     int detector = theDetUnitId.det();
00461     int subdetector = theDetUnitId.subdetId();
00462 
00463     // check that expected detector is returned
00464     if ((detector == dTrk) && (subdetector == sdPxlBrl)) {
00465 
00466       // get the GeomDetUnit from the geometry using theDetUnitID
00467       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
00468 
00469       if (!theDet) {
00470         edm::LogWarning(MsgLoggerCat)
00471           << "Unable to get GeomDetUnit from PxlBrlHits for Hit " << i;
00472         continue;
00473       }
00474 
00475       ++j;
00476 
00477       // get the Surface of the hit (knows how to go from local <-> global)
00478       const BoundPlane& bSurface = theDet->surface();
00479 
00480       // gather necessary information
00481       PxlBrlToF.push_back(itHit->tof());
00482       PxlBrlR.push_back(bSurface.toGlobal(itHit->localPosition()).perp());
00483       PxlBrlPhi.push_back(bSurface.toGlobal(itHit->localPosition()).phi());
00484       PxlBrlEta.push_back(bSurface.toGlobal(itHit->localPosition()).eta());
00485 
00486     } else {
00487       edm::LogWarning(MsgLoggerCat)
00488         << "PxlBrl PSimHit " << i 
00489         << " is expected to be (det,subdet) = (" 
00490         << dTrk << "," << sdPxlBrl
00491         << "); value returned is: ("
00492         << detector << "," << subdetector << ")";
00493       continue;
00494     } // end detector type check
00495   } // end loop through PxlBrl Hits
00496 
00497   if (verbosity > 1) {
00498     eventout += "\n          Number of Pixel Barrel Hits collected:..... ";
00499     eventout += j;
00500   }  
00501   
00503   // get Pixel Forward information
00505   edm::PSimHitContainer thePxlFwdHits;
00506   // extract low container
00507   edm::Handle<edm::PSimHitContainer> PxlFwdLowContainer;
00508   iEvent.getByLabel(PxlFwdLowSrc_,PxlFwdLowContainer);
00509   if (!PxlFwdLowContainer.isValid()) {
00510     edm::LogWarning(MsgLoggerCat)
00511       << "Unable to find TrackerHitsPixelEndcapLowTof in event!";
00512     return;
00513   }
00514   // extract high container
00515   edm::Handle<edm::PSimHitContainer> PxlFwdHighContainer;
00516   iEvent.getByLabel(PxlFwdHighSrc_,PxlFwdHighContainer);
00517   if (!PxlFwdHighContainer.isValid()) {
00518     edm::LogWarning("GlobalHitsProducer_fillTrk")
00519       << "Unable to find TrackerHitsPixelEndcapHighTof in event!";
00520     return;
00521   }
00522   // place both containers into new container
00523   thePxlFwdHits.insert(thePxlFwdHits.end(),PxlFwdLowContainer->begin(),
00524                        PxlFwdLowContainer->end());
00525   thePxlFwdHits.insert(thePxlFwdHits.end(),PxlFwdHighContainer->begin(),
00526                        PxlFwdHighContainer->end());
00527 
00528   // cycle through new container
00529   i = 0; j = 0;
00530   for (itHit = thePxlFwdHits.begin(); itHit != thePxlFwdHits.end(); ++itHit) {
00531 
00532     ++i;
00533 
00534     // create a DetId from the detUnitId
00535     DetId theDetUnitId(itHit->detUnitId());
00536     int detector = theDetUnitId.det();
00537     int subdetector = theDetUnitId.subdetId();
00538 
00539     // check that expected detector is returned
00540     if ((detector == dTrk) && (subdetector == sdPxlFwd)) {
00541 
00542       // get the GeomDetUnit from the geometry using theDetUnitID
00543       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
00544 
00545       if (!theDet) {
00546         edm::LogWarning(MsgLoggerCat)
00547           << "Unable to get GeomDetUnit from PxlFwdHits for Hit " << i;;
00548         continue;
00549       }
00550 
00551       ++j;
00552 
00553       // get the Surface of the hit (knows how to go from local <-> global)
00554       const BoundPlane& bSurface = theDet->surface();
00555 
00556       // gather necessary information
00557       PxlFwdToF.push_back(itHit->tof());
00558       PxlFwdZ.push_back(bSurface.toGlobal(itHit->localPosition()).z());
00559       PxlFwdPhi.push_back(bSurface.toGlobal(itHit->localPosition()).phi());
00560       PxlFwdEta.push_back(bSurface.toGlobal(itHit->localPosition()).eta());
00561     } else {
00562       edm::LogWarning(MsgLoggerCat)
00563         << "PxlFwd PSimHit " << i 
00564         << " is expected to be (det,subdet) = (" 
00565         << dTrk << "," << sdPxlFwd
00566         << "); value returned is: ("
00567         << detector << "," << subdetector << ")";
00568       continue;
00569     } // end detector type check
00570   } // end loop through PxlFwd Hits
00571 
00572   if (verbosity > 1) {
00573     eventout += "\n          Number of Pixel Forward Hits collected:.... ";
00574     eventout += j;
00575   }  
00576 
00578   // get Silicon Barrel information
00580   edm::PSimHitContainer theSiBrlHits;
00581   // extract TIB low container
00582   edm::Handle<edm::PSimHitContainer> SiTIBLowContainer;
00583   iEvent.getByLabel(SiTIBLowSrc_,SiTIBLowContainer);
00584   if (!SiTIBLowContainer.isValid()) {
00585     edm::LogWarning(MsgLoggerCat)
00586       << "Unable to find TrackerHitsTIBLowTof in event!";
00587     return;
00588   }
00589   // extract TIB high container
00590   edm::Handle<edm::PSimHitContainer> SiTIBHighContainer;
00591   iEvent.getByLabel(SiTIBHighSrc_,SiTIBHighContainer);
00592   if (!SiTIBHighContainer.isValid()) {
00593     edm::LogWarning(MsgLoggerCat)
00594       << "Unable to find TrackerHitsTIBHighTof in event!";
00595     return;
00596   }
00597   // extract TOB low container
00598   edm::Handle<edm::PSimHitContainer> SiTOBLowContainer;
00599   iEvent.getByLabel(SiTOBLowSrc_,SiTOBLowContainer);
00600   if (!SiTOBLowContainer.isValid()) {
00601     edm::LogWarning(MsgLoggerCat)
00602       << "Unable to find TrackerHitsTOBLowTof in event!";
00603     return;
00604   }
00605   // extract TOB high container
00606   edm::Handle<edm::PSimHitContainer> SiTOBHighContainer;
00607   iEvent.getByLabel(SiTOBHighSrc_,SiTOBHighContainer);
00608   if (!SiTOBHighContainer.isValid()) {
00609     edm::LogWarning(MsgLoggerCat)
00610       << "Unable to find TrackerHitsTOBHighTof in event!";
00611     return;
00612   }
00613   // place all containers into new container
00614   theSiBrlHits.insert(theSiBrlHits.end(),SiTIBLowContainer->begin(),
00615                        SiTIBLowContainer->end());
00616   theSiBrlHits.insert(theSiBrlHits.end(),SiTIBHighContainer->begin(),
00617                        SiTIBHighContainer->end());
00618   theSiBrlHits.insert(theSiBrlHits.end(),SiTOBLowContainer->begin(),
00619                        SiTOBLowContainer->end());
00620   theSiBrlHits.insert(theSiBrlHits.end(),SiTOBHighContainer->begin(),
00621                        SiTOBHighContainer->end());
00622 
00623   // cycle through new container
00624   i = 0; j = 0;
00625   for (itHit = theSiBrlHits.begin(); itHit != theSiBrlHits.end(); ++itHit) {
00626 
00627     ++i;
00628 
00629     // create a DetId from the detUnitId
00630     DetId theDetUnitId(itHit->detUnitId());
00631     int detector = theDetUnitId.det();
00632     int subdetector = theDetUnitId.subdetId();
00633 
00634     // check that expected detector is returned
00635     if ((detector == dTrk) && 
00636         ((subdetector == sdSiTIB) ||
00637          (subdetector == sdSiTOB))) {
00638 
00639       // get the GeomDetUnit from the geometry using theDetUnitID
00640       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
00641 
00642       if (!theDet) {
00643         edm::LogWarning(MsgLoggerCat)
00644           << "Unable to get GeomDetUnit from SiBrlHits for Hit " << i;
00645         continue;
00646       }
00647 
00648       ++j;
00649 
00650       // get the Surface of the hit (knows how to go from local <-> global)
00651       const BoundPlane& bSurface = theDet->surface();
00652 
00653       // gather necessary information
00654       SiBrlToF.push_back(itHit->tof());
00655       SiBrlR.push_back(bSurface.toGlobal(itHit->localPosition()).perp());
00656       SiBrlPhi.push_back(bSurface.toGlobal(itHit->localPosition()).phi());
00657       SiBrlEta.push_back(bSurface.toGlobal(itHit->localPosition()).eta());
00658     } else {
00659       edm::LogWarning(MsgLoggerCat)
00660         << "SiBrl PSimHit " << i 
00661         << " is expected to be (det,subdet) = (" 
00662         << dTrk << "," << sdSiTIB
00663         << " || " << sdSiTOB << "); value returned is: ("
00664         << detector << "," << subdetector << ")";
00665       continue;
00666     } // end detector type check
00667   } // end loop through SiBrl Hits
00668 
00669   if (verbosity > 1) {
00670     eventout += "\n          Number of Silicon Barrel Hits collected:... ";
00671     eventout += j;
00672   }  
00673 
00675   // get Silicon Forward information
00677   edm::PSimHitContainer theSiFwdHits;
00678   // extract TID low container
00679   edm::Handle<edm::PSimHitContainer> SiTIDLowContainer;
00680   iEvent.getByLabel(SiTIDLowSrc_,SiTIDLowContainer);
00681   if (!SiTIDLowContainer.isValid()) {
00682     edm::LogWarning(MsgLoggerCat)
00683       << "Unable to find TrackerHitsTIDLowTof in event!";
00684     return;
00685   }
00686   // extract TID high container
00687   edm::Handle<edm::PSimHitContainer> SiTIDHighContainer;
00688   iEvent.getByLabel(SiTIDHighSrc_,SiTIDHighContainer);
00689   if (!SiTIDHighContainer.isValid()) {
00690     edm::LogWarning("GlobalHitsProducer_fillTrk")
00691       << "Unable to find TrackerHitsTIDHighTof in event!";
00692     return;
00693   }
00694   // extract TEC low container
00695   edm::Handle<edm::PSimHitContainer> SiTECLowContainer;
00696   iEvent.getByLabel(SiTECLowSrc_,SiTECLowContainer);
00697   if (!SiTECLowContainer.isValid()) {
00698     edm::LogWarning(MsgLoggerCat)
00699       << "Unable to find TrackerHitsTECLowTof in event!";
00700     return;
00701   }
00702   // extract TEC high container
00703   edm::Handle<edm::PSimHitContainer> SiTECHighContainer;
00704   iEvent.getByLabel(SiTECHighSrc_,SiTECHighContainer);
00705   if (!SiTECHighContainer.isValid()) {
00706     edm::LogWarning(MsgLoggerCat)
00707       << "Unable to find TrackerHitsTECHighTof in event!";
00708     return;
00709   }
00710   // place all containers into new container
00711   theSiFwdHits.insert(theSiFwdHits.end(),SiTIDLowContainer->begin(),
00712                        SiTIDLowContainer->end());
00713   theSiFwdHits.insert(theSiFwdHits.end(),SiTIDHighContainer->begin(),
00714                        SiTIDHighContainer->end());
00715   theSiFwdHits.insert(theSiFwdHits.end(),SiTECLowContainer->begin(),
00716                        SiTECLowContainer->end());
00717   theSiFwdHits.insert(theSiFwdHits.end(),SiTECHighContainer->begin(),
00718                        SiTECHighContainer->end());
00719 
00720   // cycle through container
00721   i = 0; j = 0;
00722   for (itHit = theSiFwdHits.begin(); itHit != theSiFwdHits.end(); ++itHit) {
00723 
00724     ++i;
00725 
00726     // create a DetId from the detUnitId
00727     DetId theDetUnitId(itHit->detUnitId());
00728     int detector = theDetUnitId.det();
00729     int subdetector = theDetUnitId.subdetId();
00730 
00731     // check that expected detector is returned 
00732     if ((detector == dTrk) && 
00733         ((subdetector == sdSiTID) ||
00734          (subdetector == sdSiTEC))) {
00735       
00736       // get the GeomDetUnit from the geometry using theDetUnitID
00737       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
00738       
00739       if (!theDet) {
00740         edm::LogWarning(MsgLoggerCat)
00741           << "Unable to get GeomDetUnit from SiFwdHits Hit " << i;
00742         return;
00743       }
00744       
00745       ++j;
00746 
00747       // get the Surface of the hit (knows how to go from local <-> global)
00748       const BoundPlane& bSurface = theDet->surface();
00749       
00750       // gather necessary information
00751       SiFwdToF.push_back(itHit->tof());
00752       SiFwdZ.push_back(bSurface.toGlobal(itHit->localPosition()).z());
00753       SiFwdPhi.push_back(bSurface.toGlobal(itHit->localPosition()).phi());
00754       SiFwdEta.push_back(bSurface.toGlobal(itHit->localPosition()).eta());
00755     } else {
00756       edm::LogWarning(MsgLoggerCat)
00757         << "SiFwd PSimHit " << i 
00758         << " is expected to be (det,subdet) = (" 
00759         << dTrk << "," << sdSiTOB
00760         << " || " << sdSiTEC << "); value returned is: ("
00761         << detector << "," << subdetector << ")";
00762       continue;
00763     } // end check detector type
00764   } // end loop through SiFwd Hits
00765 
00766   if (verbosity > 1) {
00767     eventout += "\n          Number of Silicon Forward Hits collected:.. ";
00768     eventout += j;
00769   }  
00770 
00771   if (verbosity > 0)
00772     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00773 
00774   return;
00775 }
00776 
00777 void GlobalHitsProducer::storeTrk(PGlobalSimHit& product)
00778 {
00779   std::string MsgLoggerCat = "GlobalHitsProducer_storeTrk";
00780 
00781   if (verbosity > 2) {
00782     TString eventout("\n       nPxlBrlHits        = ");
00783     eventout += PxlBrlToF.size();
00784     for (unsigned int i = 0; i < PxlBrlToF.size(); ++i) {
00785       eventout += "\n          (tof,r,phi,eta) = (";
00786       eventout += PxlBrlToF[i];
00787       eventout += ", ";
00788       eventout += PxlBrlR[i];
00789       eventout += ", ";
00790       eventout += PxlBrlPhi[i];
00791       eventout += ", ";
00792       eventout += PxlBrlEta[i];
00793       eventout += ")";      
00794     } // end PxlBrl output
00795     eventout += "\n       nPxlFwdHits        = ";
00796     eventout += PxlFwdToF.size();
00797     for (unsigned int i = 0; i < PxlFwdToF.size(); ++i) {
00798       eventout += "\n          (tof,z,phi,eta) = (";
00799       eventout += PxlFwdToF[i];
00800       eventout += ", ";
00801       eventout += PxlFwdZ[i];
00802       eventout += ", ";
00803       eventout += PxlFwdPhi[i];
00804       eventout += ", ";
00805       eventout += PxlFwdEta[i];
00806       eventout += ")";      
00807     } // end PxlFwd output
00808     eventout += "\n       nSiBrlHits         = ";
00809     eventout += SiBrlToF.size();
00810     for (unsigned int i = 0; i < SiBrlToF.size(); ++i) {
00811       eventout += "\n          (tof,r,phi,eta) = (";
00812       eventout += SiBrlToF[i];
00813       eventout += ", ";
00814       eventout += SiBrlR[i];
00815       eventout += ", ";
00816       eventout += SiBrlPhi[i];
00817       eventout += ", ";
00818       eventout += SiBrlEta[i];
00819       eventout += ")";      
00820     } // end SiBrl output
00821     eventout += "\n       nSiFwdHits         = ";
00822     eventout += SiFwdToF.size();
00823     for (unsigned int i = 0; i < SiFwdToF.size(); ++i) {
00824       eventout += "\n          (tof,z,phi,eta) = (";
00825       eventout += SiFwdToF[i];
00826       eventout += ", ";
00827       eventout += SiFwdZ[i];
00828       eventout += ", ";
00829       eventout += SiFwdPhi[i];
00830       eventout += ", ";
00831       eventout += SiFwdEta[i];
00832       eventout += ")";      
00833     } // end SiFwd output
00834     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
00835   } // end verbose output
00836 
00837   product.putPxlBrlHits(PxlBrlToF,PxlBrlR,PxlBrlPhi,PxlBrlEta);
00838   product.putPxlFwdHits(PxlFwdToF,PxlFwdZ,PxlFwdPhi,PxlFwdEta);
00839   product.putSiBrlHits(SiBrlToF,SiBrlR,SiBrlPhi,SiBrlEta);
00840   product.putSiFwdHits(SiFwdToF,SiFwdZ,SiFwdPhi,SiFwdEta);
00841 
00842   return;
00843 }
00844 
00845 void GlobalHitsProducer::fillMuon(edm::Event& iEvent, 
00846                                  const edm::EventSetup& iSetup)
00847 {
00848   std::string MsgLoggerCat = "GlobalHitsProducer_fillMuon";
00849 
00850   TString eventout;
00851   if (verbosity > 0)
00852     eventout = "\nGathering info:";  
00853 
00854   // iterator to access containers
00855   edm::PSimHitContainer::const_iterator itHit;
00856 
00857   //int i = 0, j = 0;
00859   // access the CSC Muon
00861   // access the CSC Muon geometry
00862   edm::ESHandle<CSCGeometry> theCSCGeometry;
00863   iSetup.get<MuonGeometryRecord>().get(theCSCGeometry);
00864   if (!theCSCGeometry.isValid()) {
00865     edm::LogWarning(MsgLoggerCat)
00866       << "Unable to find MuonGeometryRecord for the CSCGeometry in event!";
00867     return;
00868   }
00869   const CSCGeometry& theCSCMuon(*theCSCGeometry);
00870 
00871   // get Muon CSC information
00872   edm::Handle<edm::PSimHitContainer> MuonCSCContainer;
00873   iEvent.getByLabel(MuonCscSrc_,MuonCSCContainer);
00874   if (!MuonCSCContainer.isValid()) {
00875     edm::LogWarning(MsgLoggerCat)
00876       << "Unable to find MuonCSCHits in event!";
00877     return;
00878   }
00879 
00880   // cycle through container
00881   int i = 0, j = 0;
00882   for (itHit = MuonCSCContainer->begin(); itHit != MuonCSCContainer->end(); 
00883        ++itHit) {
00884 
00885     ++i;
00886 
00887     // create a DetId from the detUnitId
00888     DetId theDetUnitId(itHit->detUnitId());
00889     int detector = theDetUnitId.det();
00890     int subdetector = theDetUnitId.subdetId();
00891 
00892     // check that expected detector is returned
00893     if ((detector == dMuon) && 
00894         (subdetector == sdMuonCSC)) {
00895 
00896       // get the GeomDetUnit from the geometry using theDetUnitID
00897       const GeomDetUnit *theDet = theCSCMuon.idToDetUnit(theDetUnitId);
00898     
00899       if (!theDet) {
00900         edm::LogWarning(MsgLoggerCat)
00901           << "Unable to get GeomDetUnit from theCSCMuon for hit " << i;
00902         continue;
00903       }
00904      
00905       ++j;
00906 
00907       // get the Surface of the hit (knows how to go from local <-> global)
00908       const BoundPlane& bSurface = theDet->surface();
00909     
00910       // gather necessary information
00911       MuonCscToF.push_back(itHit->tof());
00912       MuonCscZ.push_back(bSurface.toGlobal(itHit->localPosition()).z());
00913       MuonCscPhi.push_back(bSurface.toGlobal(itHit->localPosition()).phi());
00914       MuonCscEta.push_back(bSurface.toGlobal(itHit->localPosition()).eta());
00915     } else {
00916       edm::LogWarning(MsgLoggerCat)
00917         << "MuonCsc PSimHit " << i 
00918         << " is expected to be (det,subdet) = (" 
00919         << dMuon << "," << sdMuonCSC
00920         << "); value returned is: ("
00921         << detector << "," << subdetector << ")";
00922       continue;
00923     } // end detector type check
00924   } // end loop through CSC Hits
00925 
00926   if (verbosity > 1) {
00927     eventout += "\n          Number of CSC muon Hits collected:......... ";
00928     eventout += j;
00929   }  
00930 
00931   //i = 0, j = 0;
00933   // access the DT Muon
00935   // access the DT Muon geometry
00936   edm::ESHandle<DTGeometry> theDTGeometry;
00937   iSetup.get<MuonGeometryRecord>().get(theDTGeometry);
00938   if (!theDTGeometry.isValid()) {
00939     edm::LogWarning(MsgLoggerCat)
00940       << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
00941     return;
00942   }
00943   const DTGeometry& theDTMuon(*theDTGeometry);
00944 
00945   // get Muon DT information
00946   edm::Handle<edm::PSimHitContainer> MuonDtContainer;
00947   iEvent.getByLabel(MuonDtSrc_,MuonDtContainer);
00948   if (!MuonDtContainer.isValid()) {
00949     edm::LogWarning(MsgLoggerCat)
00950       << "Unable to find MuonDTHits in event!";
00951     return;
00952   }
00953 
00954   // cycle through container
00955   i = 0, j = 0;
00956   for (itHit = MuonDtContainer->begin(); itHit != MuonDtContainer->end(); 
00957        ++itHit) {
00958 
00959     ++i;
00960 
00961     // create a DetId from the detUnitId
00962     DetId theDetUnitId(itHit->detUnitId());
00963     int detector = theDetUnitId.det();
00964     int subdetector = theDetUnitId.subdetId();
00965 
00966     // check that expected detector is returned
00967     if ((detector == dMuon) && 
00968         (subdetector == sdMuonDT)) {
00969 
00970       // CSC uses wires and layers rather than the full detID
00971       // get the wireId
00972       DTWireId wireId(itHit->detUnitId());
00973 
00974       // get the DTLayer from the geometry using the wireID
00975       const DTLayer *theDet = theDTMuon.layer(wireId.layerId());
00976 
00977       if (!theDet) {
00978         edm::LogWarning(MsgLoggerCat)
00979           << "Unable to get GeomDetUnit from theDtMuon for hit " << i;
00980         continue;
00981       }
00982      
00983       ++j;
00984 
00985       // get the Surface of the hit (knows how to go from local <-> global)
00986       const BoundPlane& bSurface = theDet->surface();
00987     
00988       // gather necessary information
00989       MuonDtToF.push_back(itHit->tof());
00990       MuonDtR.push_back(bSurface.toGlobal(itHit->localPosition()).perp());
00991       MuonDtPhi.push_back(bSurface.toGlobal(itHit->localPosition()).phi());
00992       MuonDtEta.push_back(bSurface.toGlobal(itHit->localPosition()).eta());
00993     } else {
00994       edm::LogWarning(MsgLoggerCat)
00995         << "MuonDt PSimHit " << i 
00996         << " is expected to be (det,subdet) = (" 
00997         << dMuon << "," << sdMuonDT
00998         << "); value returned is: ("
00999         << detector << "," << subdetector << ")";
01000       continue;
01001     } // end detector type check
01002   } // end loop through DT Hits
01003 
01004   if (verbosity > 1) {
01005     eventout += "\n          Number of DT muon Hits collected:.......... ";
01006     eventout += j;
01007   } 
01008 
01009   //i = 0, j = 0;
01010   //int RPCBrl = 0, RPCFwd = 0;
01012   // access the RPC Muon
01014   // access the RPC Muon geometry
01015   edm::ESHandle<RPCGeometry> theRPCGeometry;
01016   iSetup.get<MuonGeometryRecord>().get(theRPCGeometry);
01017   if (!theRPCGeometry.isValid()) {
01018     edm::LogWarning(MsgLoggerCat)
01019       << "Unable to find MuonGeometryRecord for the RPCGeometry in event!";
01020     return;
01021   }
01022   const RPCGeometry& theRPCMuon(*theRPCGeometry);
01023 
01024   // get Muon RPC information
01025   edm::Handle<edm::PSimHitContainer> MuonRPCContainer;
01026   iEvent.getByLabel(MuonRpcSrc_,MuonRPCContainer);
01027   if (!MuonRPCContainer.isValid()) {
01028     edm::LogWarning(MsgLoggerCat)
01029       << "Unable to find MuonRPCHits in event!";
01030     return;
01031   }
01032 
01033   // cycle through container
01034   i = 0, j = 0;
01035   int RPCBrl =0, RPCFwd = 0;
01036   for (itHit = MuonRPCContainer->begin(); itHit != MuonRPCContainer->end(); 
01037        ++itHit) {
01038 
01039     ++i;
01040 
01041     // create a DetID from the detUnitId
01042     DetId theDetUnitId(itHit->detUnitId());
01043     int detector = theDetUnitId.det();
01044     int subdetector = theDetUnitId.subdetId();
01045 
01046     // check that expected detector is returned
01047     if ((detector == dMuon) && 
01048         (subdetector == sdMuonRPC)) {
01049       
01050       // get an RPCDetID from the detUnitID
01051       RPCDetId RPCId(itHit->detUnitId());      
01052 
01053       // find the region of the RPC hit
01054       int region = RPCId.region();
01055 
01056       // get the GeomDetUnit from the geometry using the RPCDetId
01057       const GeomDetUnit *theDet = theRPCMuon.idToDetUnit(theDetUnitId);
01058 
01059       if (!theDet) {
01060         edm::LogWarning(MsgLoggerCat)
01061           << "Unable to get GeomDetUnit from theRPCMuon for hit " << i;
01062         continue;
01063       }
01064 
01065       ++j;
01066 
01067       // get the Surface of the hit (knows how to go from local <-> global)
01068       const BoundPlane& bSurface = theDet->surface();
01069     
01070       // gather necessary information
01071       if ((region == sdMuonRPCRgnFwdp) || (region == sdMuonRPCRgnFwdn)) {
01072         ++RPCFwd;
01073 
01074         MuonRpcFwdToF.push_back(itHit->tof());
01075         MuonRpcFwdZ.push_back(bSurface.toGlobal(itHit->localPosition()).z());
01076         MuonRpcFwdPhi.
01077           push_back(bSurface.toGlobal(itHit->localPosition()).phi());
01078         MuonRpcFwdEta.
01079           push_back(bSurface.toGlobal(itHit->localPosition()).eta());
01080       } else if (region == sdMuonRPCRgnBrl) {
01081         ++RPCBrl;
01082 
01083         MuonRpcBrlToF.push_back(itHit->tof());
01084         MuonRpcBrlR.
01085           push_back(bSurface.toGlobal(itHit->localPosition()).perp());
01086         MuonRpcBrlPhi.
01087           push_back(bSurface.toGlobal(itHit->localPosition()).phi());
01088         MuonRpcBrlEta.
01089           push_back(bSurface.toGlobal(itHit->localPosition()).eta());   
01090       } else {
01091         edm::LogWarning(MsgLoggerCat)
01092           << "Invalid region for RPC Muon hit" << i;
01093         continue;
01094       } // end check of region
01095     } else {
01096       edm::LogWarning(MsgLoggerCat)
01097         << "MuonRpc PSimHit " << i 
01098         << " is expected to be (det,subdet) = (" 
01099         << dMuon << "," << sdMuonRPC
01100         << "); value returned is: ("
01101         << detector << "," << subdetector << ")";
01102       continue;
01103     } // end detector type check
01104   } // end loop through RPC Hits
01105 
01106   if (verbosity > 1) {
01107     eventout += "\n          Number of RPC muon Hits collected:......... ";
01108     eventout += j;
01109     eventout += "\n                    RPC Barrel muon Hits:............ ";
01110     eventout += RPCBrl;
01111     eventout += "\n                    RPC Forward muon Hits:........... ";
01112     eventout += RPCFwd;    
01113   }  
01114 
01115   if (verbosity > 0)
01116     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01117 
01118   return;
01119 }
01120 
01121 void GlobalHitsProducer::storeMuon(PGlobalSimHit& product)
01122 {
01123   std::string MsgLoggerCat = "GlobalHitsProducer_storeMuon";
01124 
01125   if (verbosity > 2) {
01126     TString eventout("\n       nMuonCSCHits       = ");
01127     eventout += MuonCscToF.size();
01128     for (unsigned int i = 0; i < MuonCscToF.size(); ++i) {
01129       eventout += "\n          (tof,z,phi,eta) = (";
01130       eventout += MuonCscToF[i];
01131       eventout += ", ";
01132       eventout += MuonCscZ[i];
01133       eventout += ", ";
01134       eventout += MuonCscPhi[i];
01135       eventout += ", ";
01136       eventout += MuonCscEta[i];
01137       eventout += ")";      
01138     } // end MuonCsc output
01139     eventout += "\n       nMuonDtHits        = ";
01140     eventout += MuonDtToF.size();
01141     for (unsigned int i = 0; i < MuonDtToF.size(); ++i) {
01142       eventout += "\n          (tof,r,phi,eta) = (";
01143       eventout += MuonDtToF[i];
01144       eventout += ", ";
01145       eventout += MuonDtR[i];
01146       eventout += ", ";
01147       eventout += MuonDtPhi[i];
01148       eventout += ", ";
01149       eventout += MuonDtEta[i];
01150       eventout += ")";      
01151     } // end MuonDt output
01152     eventout += "\n       nMuonRpcBrlHits    = ";
01153     eventout += MuonRpcBrlToF.size();
01154     for (unsigned int i = 0; i < MuonRpcBrlToF.size(); ++i) {
01155       eventout += "\n          (tof,r,phi,eta) = (";
01156       eventout += MuonRpcBrlToF[i];
01157       eventout += ", ";
01158       eventout += MuonRpcBrlR[i];
01159       eventout += ", ";
01160       eventout += MuonRpcBrlPhi[i];
01161       eventout += ", ";
01162       eventout += MuonRpcBrlEta[i];
01163       eventout += ")";      
01164     } // end MuonRpcBrl output
01165     eventout += "\n       nMuonRpcFwdHits    = ";
01166     eventout += MuonRpcFwdToF.size();
01167     for (unsigned int i = 0; i < MuonRpcFwdToF.size(); ++i) {
01168       eventout += "\n          (tof,z,phi,eta) = (";
01169       eventout += MuonRpcFwdToF[i];
01170       eventout += ", ";
01171       eventout += MuonRpcFwdZ[i];
01172       eventout += ", ";
01173       eventout += MuonRpcFwdPhi[i];
01174       eventout += ", ";
01175       eventout += MuonRpcFwdEta[i]; 
01176       eventout += ")";      
01177     } // end MuonRpcFwd output
01178     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01179   } // end verbose output
01180 
01181   product.putMuonCscHits(MuonCscToF,MuonCscZ,MuonCscPhi,MuonCscEta);
01182   product.putMuonDtHits(MuonDtToF,MuonDtR,MuonDtPhi,MuonDtEta);
01183   product.putMuonRpcBrlHits(MuonRpcBrlToF,MuonRpcBrlR,MuonRpcBrlPhi,
01184                              MuonRpcBrlEta);
01185   product.putMuonRpcFwdHits(MuonRpcFwdToF,MuonRpcFwdZ,MuonRpcFwdPhi,
01186                              MuonRpcFwdEta);
01187 
01188   return;
01189 }
01190 
01191 void GlobalHitsProducer::fillECal(edm::Event& iEvent, 
01192                                 const edm::EventSetup& iSetup)
01193 {
01194   std::string MsgLoggerCat = "GlobalHitsProducer_fillECal";
01195 
01196   TString eventout;
01197   if (verbosity > 0)
01198     eventout = "\nGathering info:";  
01199   
01200   // access the calorimeter geometry
01201   edm::ESHandle<CaloGeometry> theCaloGeometry;
01202   iSetup.get<CaloGeometryRecord>().get(theCaloGeometry);
01203   if (!theCaloGeometry.isValid()) {
01204     edm::LogWarning(MsgLoggerCat)
01205       << "Unable to find CaloGeometryRecord in event!";
01206     return;
01207   }
01208   const CaloGeometry& theCalo(*theCaloGeometry);
01209     
01210   // iterator to access containers
01211   edm::PCaloHitContainer::const_iterator itHit;
01212 
01214   // get  ECal information
01216   edm::PCaloHitContainer theECalHits;
01217   // extract EB container
01218   edm::Handle<edm::PCaloHitContainer> EBContainer;
01219   iEvent.getByLabel(ECalEBSrc_,EBContainer);
01220   if (!EBContainer.isValid()) {
01221     edm::LogWarning(MsgLoggerCat)
01222       << "Unable to find EcalHitsEB in event!";
01223     return;
01224   }
01225   // extract EE container
01226   edm::Handle<edm::PCaloHitContainer> EEContainer;
01227   iEvent.getByLabel(ECalEESrc_,EEContainer);
01228   if (!EEContainer.isValid()) {
01229     edm::LogWarning(MsgLoggerCat)
01230       << "Unable to find EcalHitsEE in event!";
01231     return;
01232   }
01233   // place both containers into new container
01234   theECalHits.insert(theECalHits.end(),EBContainer->begin(),
01235                        EBContainer->end());
01236   theECalHits.insert(theECalHits.end(),EEContainer->begin(),
01237                        EEContainer->end());
01238 
01239   // cycle through new container
01240   int i = 0, j = 0;
01241   for (itHit = theECalHits.begin(); itHit != theECalHits.end(); ++itHit) {
01242 
01243     ++i;
01244 
01245     // create a DetId from the detUnitId
01246     DetId theDetUnitId(itHit->id());
01247     int detector = theDetUnitId.det();
01248     int subdetector = theDetUnitId.subdetId();
01249 
01250     // check that expected detector is returned
01251     if ((detector == dEcal) && 
01252         ((subdetector == sdEcalBrl) ||
01253          (subdetector == sdEcalFwd))) {
01254 
01255       // get the Cell geometry
01256       const CaloCellGeometry *theDet = theCalo.
01257         getSubdetectorGeometry(theDetUnitId)->getGeometry(theDetUnitId);
01258 
01259       if (!theDet) {
01260         edm::LogWarning(MsgLoggerCat)
01261           << "Unable to get CaloCellGeometry from ECalHits for Hit " << i;
01262         continue;
01263       }
01264 
01265       ++j;
01266 
01267       // get the global position of the cell
01268       const GlobalPoint& globalposition = theDet->getPosition();
01269 
01270       // gather necessary information
01271       ECalE.push_back(itHit->energy());
01272       ECalToF.push_back(itHit->time());
01273       ECalPhi.push_back(globalposition.phi());
01274       ECalEta.push_back(globalposition.eta());
01275 
01276     } else {
01277       edm::LogWarning(MsgLoggerCat)
01278         << "ECal PCaloHit " << i 
01279         << " is expected to be (det,subdet) = (" 
01280         << dEcal << "," << sdEcalBrl
01281         << " || " << sdEcalFwd << "); value returned is: ("
01282         << detector << "," << subdetector << ")";
01283       continue;
01284     } // end detector type check
01285   } // end loop through ECal Hits
01286 
01287   if (verbosity > 1) {
01288     eventout += "\n          Number of ECal Hits collected:............. ";
01289     eventout += j;
01290   }  
01291 
01293   // Get Preshower information
01295   // extract PreShower container
01296   edm::Handle<edm::PCaloHitContainer> PreShContainer;
01297   iEvent.getByLabel(ECalESSrc_,PreShContainer);
01298   if (!PreShContainer.isValid()) {
01299     edm::LogWarning(MsgLoggerCat)
01300       << "Unable to find EcalHitsES in event!";
01301     return;
01302   }
01303 
01304   // cycle through container
01305   i = 0, j = 0;
01306   for (itHit = PreShContainer->begin(); 
01307        itHit != PreShContainer->end(); ++itHit) {
01308 
01309     ++i;
01310 
01311     // create a DetId from the detUnitId
01312     DetId theDetUnitId(itHit->id());
01313     int detector = theDetUnitId.det();
01314     int subdetector = theDetUnitId.subdetId();
01315 
01316     // check that expected detector is returned
01317     if ((detector == dEcal) && 
01318         (subdetector == sdEcalPS)) {
01319 
01320       // get the Cell geometry
01321       const CaloCellGeometry *theDet = theCalo.
01322         getSubdetectorGeometry(theDetUnitId)->getGeometry(theDetUnitId);
01323 
01324       if (!theDet) {
01325         edm::LogWarning(MsgLoggerCat)
01326           << "Unable to get CaloCellGeometry from PreShContainer for Hit " 
01327           << i;
01328         continue;
01329       }
01330 
01331       ++j;
01332 
01333       // get the global position of the cell
01334       const GlobalPoint& globalposition = theDet->getPosition();
01335 
01336       // gather necessary information
01337       PreShE.push_back(itHit->energy());
01338       PreShToF.push_back(itHit->time());
01339       PreShPhi.push_back(globalposition.phi());
01340       PreShEta.push_back(globalposition.eta());
01341 
01342     } else {
01343       edm::LogWarning(MsgLoggerCat)
01344         << "PreSh PCaloHit " << i 
01345         << " is expected to be (det,subdet) = (" 
01346         << dEcal << "," << sdEcalPS
01347         << "); value returned is: ("
01348         << detector << "," << subdetector << ")";
01349       continue;
01350     } // end detector type check
01351   } // end loop through PreShower Hits
01352 
01353   if (verbosity > 1) {
01354     eventout += "\n          Number of PreSh Hits collected:............ ";
01355     eventout += j;
01356   }  
01357 
01358   if (verbosity > 0)
01359     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01360 
01361   return;
01362 }
01363 
01364 void GlobalHitsProducer::storeECal(PGlobalSimHit& product)
01365 {
01366   std::string MsgLoggerCat = "GlobalHitsProducer_storeECal";
01367 
01368   if (verbosity > 2) {
01369     TString eventout("\n       nECalHits          = ");
01370     eventout += ECalE.size();
01371     for (unsigned int i = 0; i < ECalE.size(); ++i) {
01372       eventout += "\n          (e,tof,phi,eta) = (";
01373       eventout += ECalE[i];
01374       eventout += ", ";
01375       eventout += ECalToF[i];
01376       eventout += ", ";
01377       eventout += ECalPhi[i];
01378       eventout += ", ";
01379       eventout += ECalEta[i];  
01380       eventout += ")";   
01381     } // end ECal output
01382     eventout += "\n       nPreShHits         = ";
01383     eventout += PreShE.size();
01384     for (unsigned int i = 0; i < PreShE.size(); ++i) {
01385       eventout += "\n          (e,tof,phi,eta) = (";
01386       eventout += PreShE[i];
01387       eventout += ", ";
01388       eventout += PreShToF[i];
01389       eventout += ", ";
01390       eventout += PreShPhi[i];
01391       eventout += ", ";
01392       eventout += PreShEta[i]; 
01393       eventout += ")";    
01394     } // end PreShower output
01395     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01396   } // end verbose output
01397 
01398   product.putECalHits(ECalE,ECalToF,ECalPhi,ECalEta);
01399   product.putPreShHits(PreShE,PreShToF,PreShPhi,PreShEta);
01400 
01401   return;
01402 }
01403 
01404 void GlobalHitsProducer::fillHCal(edm::Event& iEvent, 
01405                                 const edm::EventSetup& iSetup)
01406 {
01407   std::string MsgLoggerCat = "GlobalHitsProducer_fillHCal";
01408 
01409   TString eventout;
01410   if (verbosity > 0)
01411     eventout = "\nGathering info:";  
01412   
01413   // access the calorimeter geometry
01414   edm::ESHandle<CaloGeometry> theCaloGeometry;
01415   iSetup.get<CaloGeometryRecord>().get(theCaloGeometry);
01416   if (!theCaloGeometry.isValid()) {
01417     edm::LogWarning(MsgLoggerCat)
01418       << "Unable to find CaloGeometryRecord in event!";
01419     return;
01420   }
01421   const CaloGeometry& theCalo(*theCaloGeometry);
01422     
01423   // iterator to access containers
01424   edm::PCaloHitContainer::const_iterator itHit;
01425 
01427   // get  HCal information
01429   // extract HCal container
01430   edm::Handle<edm::PCaloHitContainer> HCalContainer;
01431   iEvent.getByLabel(HCalSrc_,HCalContainer);
01432   if (!HCalContainer.isValid()) {
01433     edm::LogWarning(MsgLoggerCat)
01434       << "Unable to find HCalHits in event!";
01435     return;
01436   }
01437 
01438   // cycle through container
01439   int i = 0, j = 0;
01440   for (itHit = HCalContainer->begin(); 
01441        itHit != HCalContainer->end(); ++itHit) {
01442 
01443     ++i;
01444 
01445     // create a DetId from the detUnitId
01446     DetId theDetUnitId(itHit->id());
01447     int detector = theDetUnitId.det();
01448     int subdetector = theDetUnitId.subdetId();
01449 
01450     // check that expected detector is returned
01451     if ((detector == dHcal) && 
01452         ((subdetector == sdHcalBrl) ||
01453          (subdetector == sdHcalEC) ||
01454          (subdetector == sdHcalOut) ||
01455          (subdetector == sdHcalFwd))) {
01456 
01457       // get the Cell geometry
01458       const CaloCellGeometry *theDet = theCalo.
01459         getSubdetectorGeometry(theDetUnitId)->getGeometry(theDetUnitId);
01460 
01461       if (!theDet) {
01462         edm::LogWarning(MsgLoggerCat)
01463           << "Unable to get CaloCellGeometry from HCalContainer for Hit " << i;
01464         continue;
01465       }
01466 
01467       ++j;
01468 
01469       // get the global position of the cell
01470       const GlobalPoint& globalposition = theDet->getPosition();
01471 
01472       // gather necessary information
01473       HCalE.push_back(itHit->energy());
01474       HCalToF.push_back(itHit->time());
01475       HCalPhi.push_back(globalposition.phi());
01476       HCalEta.push_back(globalposition.eta());
01477 
01478     } else {
01479       edm::LogWarning(MsgLoggerCat)
01480         << "HCal PCaloHit " << i 
01481         << " is expected to be (det,subdet) = (" 
01482         << dHcal << "," << sdHcalBrl
01483         << " || " << sdHcalEC << " || " << sdHcalOut << " || " << sdHcalFwd
01484         << "); value returned is: ("
01485         << detector << "," << subdetector << ")";
01486       continue;
01487     } // end detector type check
01488   } // end loop through HCal Hits
01489 
01490   if (verbosity > 1) {
01491     eventout += "\n          Number of HCal Hits collected:............. ";
01492     eventout += j;
01493   }  
01494 
01495   if (verbosity > 0)
01496     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01497 
01498   return;
01499 }
01500 
01501 void GlobalHitsProducer::storeHCal(PGlobalSimHit& product)
01502 {
01503   std::string MsgLoggerCat = "GlobalHitsProducer_storeHCal";
01504 
01505   if (verbosity > 2) {
01506     TString eventout("\n       nHCalHits          = ");
01507     eventout += HCalE.size();
01508     for (unsigned int i = 0; i < HCalE.size(); ++i) {
01509       eventout += "\n          (e,tof,phi,eta) = (";
01510       eventout += HCalE[i];
01511       eventout += ", ";
01512       eventout += HCalToF[i];
01513       eventout += ", ";
01514       eventout += HCalPhi[i];
01515       eventout += ", ";
01516       eventout += HCalEta[i];  
01517       eventout += ")";      
01518     } // end HCal output
01519     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
01520   } // end verbose output
01521 
01522   product.putHCalHits(HCalE,HCalToF,HCalPhi,HCalEta);
01523 
01524   return;
01525 }
01526 
01527 void GlobalHitsProducer::clear()
01528 {
01529   std::string MsgLoggerCat = "GlobalHitsProducer_clear";
01530 
01531   if (verbosity > 0)
01532     edm::LogInfo(MsgLoggerCat)
01533       << "Clearing event holders"; 
01534 
01535   // reset G4MC info
01536   nRawGenPart = 0;
01537   G4VtxX.clear();
01538   G4VtxY.clear();
01539   G4VtxZ.clear();
01540   G4TrkPt.clear();
01541   G4TrkE.clear();
01542 
01543   // reset electromagnetic info
01544   // reset ECal info
01545   ECalE.clear();
01546   ECalToF.clear();
01547   ECalPhi.clear();
01548   ECalEta.clear();
01549   // reset Preshower info
01550   PreShE.clear();
01551   PreShToF.clear();
01552   PreShPhi.clear();
01553   PreShEta.clear();
01554 
01555   // reset hadronic info
01556   // reset HCal info
01557   HCalE.clear();
01558   HCalToF.clear();
01559   HCalPhi.clear();
01560   HCalEta.clear();
01561 
01562   // reset tracker info
01563   // reset Pixel info
01564   PxlBrlToF.clear(); 
01565   PxlBrlR.clear(); 
01566   PxlBrlPhi.clear(); 
01567   PxlBrlEta.clear(); 
01568   PxlFwdToF.clear(); 
01569   PxlFwdZ.clear();
01570   PxlFwdPhi.clear(); 
01571   PxlFwdEta.clear();
01572   // reset strip info
01573   SiBrlToF.clear(); 
01574   SiBrlR.clear(); 
01575   SiBrlPhi.clear(); 
01576   SiBrlEta.clear(); 
01577   SiFwdToF.clear(); 
01578   SiFwdZ.clear();
01579   SiFwdPhi.clear(); 
01580   SiFwdEta.clear();
01581 
01582   // reset muon info
01583   // reset muon DT info
01584   MuonDtToF.clear(); 
01585   MuonDtR.clear();
01586   MuonDtPhi.clear();
01587   MuonDtEta.clear();
01588   // reset muon CSC info
01589   MuonCscToF.clear(); 
01590   MuonCscZ.clear();
01591   MuonCscPhi.clear();
01592   MuonCscEta.clear();
01593   // rest muon RPC info
01594   MuonRpcBrlToF.clear(); 
01595   MuonRpcBrlR.clear();
01596   MuonRpcBrlPhi.clear();
01597   MuonRpcBrlEta.clear(); 
01598   MuonRpcFwdToF.clear(); 
01599   MuonRpcFwdZ.clear();
01600   MuonRpcFwdPhi.clear();
01601   MuonRpcFwdEta.clear();
01602 
01603   return;
01604 }