CMS 3D CMS Logo

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