CMS 3D CMS Logo

MuonProducer.cc

Go to the documentation of this file.
00001 
00009 #include "RecoMuon/MuonIdentification/plugins/MuonProducer.h"
00010 
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 
00016 #include "DataFormats/MuonReco/interface/Muon.h"
00017 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00018 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00019 
00020 // tmp
00021 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00022 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00023 #include "DataFormats/TrackReco/interface/Track.h"
00024 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00025 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00026 
00027 
00028 using namespace edm;
00029 
00031 MuonProducer::MuonProducer(const ParameterSet& pSet){
00032 
00033   theLinksCollectionLabel = pSet.getParameter<InputTag>("InputObjects");
00034 
00035   setAlias(pSet.getParameter<std::string>("@module_label"));
00036   produces<reco::MuonCollection>().setBranchAlias(theAlias + "s");
00037 }
00038 
00040 MuonProducer::~MuonProducer(){
00041 
00042 }
00043 
00044 void MuonProducer::printTrackRecHits(const reco::Track &track, 
00045                                      ESHandle<GlobalTrackingGeometry> trackingGeometry) const{
00046 
00047   const std::string metname = "Muon|RecoMuon|MuonIdentification|MuonProducer";
00048 
00049   LogTrace(metname) << "Valid RecHits: "<<track.found() << " invalid RecHits: " << track.lost();
00050   
00051   int i = 0;
00052   for(trackingRecHit_iterator recHit = track.recHitsBegin(); recHit != track.recHitsEnd(); ++recHit)
00053     if((*recHit)->isValid()){
00054       const GeomDet* geomDet = trackingGeometry->idToDet((*recHit)->geographicalId());
00055       double r = geomDet->surface().position().perp();
00056       double z = geomDet->toGlobal((*recHit)->localPosition()).z();
00057       LogTrace(metname) << i++ <<" r: "<< r <<" z: "<<z <<" "<<geomDet->toGlobal((*recHit)->localPosition())
00058                         <<std::endl;
00059     }
00060 }
00061 
00062 
00063 
00065 void MuonProducer::produce(Event& event, const EventSetup& eventSetup){
00066 
00067    const std::string metname = "Muon|RecoMuon|MuonIdentification|MuonProducer";
00068 
00069    // the muon collection, it will be loaded in the event
00070    std::auto_ptr<reco::MuonCollection> muonCollection(new reco::MuonCollection());
00071    
00072 
00073    Handle<reco::MuonTrackLinksCollection> linksCollection; 
00074    event.getByLabel(theLinksCollectionLabel,linksCollection);
00075 
00076    if(linksCollection->empty()) {
00077      event.put(muonCollection);
00078      return;
00079    }
00080    
00081 
00082    // Global Tracking Geometry
00083    ESHandle<GlobalTrackingGeometry> trackingGeometry; 
00084    eventSetup.get<GlobalTrackingGeometryRecord>().get(trackingGeometry); 
00085    
00086    for(reco::MuonTrackLinksCollection::const_iterator links = linksCollection->begin();
00087        links != linksCollection->end(); ++links){
00088 
00089      // some temporary print-out
00090      LogTrace(metname) << "trackerTrack";
00091      printTrackRecHits(*(links->trackerTrack()),trackingGeometry);
00092      LogTrace(metname) << "standAloneTrack";
00093      printTrackRecHits(*(links->standAloneTrack()),trackingGeometry);
00094      LogTrace(metname) << "globalTrack";
00095      printTrackRecHits(*(links->globalTrack()),trackingGeometry);
00096     
00097      // Fill the muon 
00098      reco::Muon muon;
00099      muon.setStandAlone(links->standAloneTrack());
00100      muon.setTrack(links->trackerTrack());
00101      muon.setCombined(links->globalTrack());
00102      
00103      // FIXME: can this break in case combined info cannot be added to some tracks?
00104      muon.setCharge(links->globalTrack()->charge());
00105 
00106      //FIXME: E = sqrt(p^2 + m^2), where m == 0.105658369(9)GeV 
00107      double energy = sqrt(links->globalTrack()->p() * links->globalTrack()->p() + 0.011163691);
00108      math::XYZTLorentzVector p4(links->globalTrack()->px(),
00109                                 links->globalTrack()->py(),
00110                                 links->globalTrack()->pz(),
00111                                 energy);
00112 
00113      muon.setP4(p4);
00114      muon.setVertex(links->globalTrack()->vertex());
00115        
00116     muonCollection->push_back(muon);
00117      
00118    }
00119 
00120    event.put(muonCollection);
00121 }

Generated on Tue Jun 9 17:44:18 2009 for CMSSW by  doxygen 1.5.4