CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoMuon/MuonIsolation/plugins/JetExtractor.cc

Go to the documentation of this file.
00001 #include "JetExtractor.h"
00002 
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "DataFormats/TrackReco/interface/Track.h"
00006 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "Utilities/Timing/interface/TimingReport.h"
00010 
00011 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00012 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00013 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00014 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00015 #include "DataFormats/JetReco/interface/CaloJet.h"
00016 
00017 #include "MagneticField/Engine/interface/MagneticField.h"
00018 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00019 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00020 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00021 
00022 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00023 
00024 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00025 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
00026 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00027 
00028 #include "DataFormats/Math/interface/deltaR.h"
00029 
00030 
00031 using namespace edm;
00032 using namespace std;
00033 using namespace reco;
00034 using namespace muonisolation;
00035 using reco::isodeposit::Direction;
00036 
00037 JetExtractor::JetExtractor(const ParameterSet& par) :
00038   theJetCollectionLabel(par.getParameter<edm::InputTag>("JetCollectionLabel")),
00039   thePropagatorName(par.getParameter<std::string>("PropagatorName")),
00040   theThreshold(par.getParameter<double>("Threshold")),
00041   theDR_Veto(par.getParameter<double>("DR_Veto")),
00042   theDR_Max(par.getParameter<double>("DR_Max")),
00043   theExcludeMuonVeto(par.getParameter<bool>("ExcludeMuonVeto")),
00044   theService(0),
00045   theAssociator(0),
00046   thePrintTimeReport(par.getUntrackedParameter<bool>("PrintTimeReport"))
00047 {
00048   ParameterSet serviceParameters = par.getParameter<ParameterSet>("ServiceParameters");
00049   theService = new MuonServiceProxy(serviceParameters);
00050 
00051   theAssociatorParameters = new TrackAssociatorParameters(par.getParameter<edm::ParameterSet>("TrackAssociatorParameters"));
00052   theAssociator = new TrackDetectorAssociator();
00053 }
00054 
00055 JetExtractor::~JetExtractor(){
00056   if (thePrintTimeReport) TimingReport::current()->dump(std::cout);
00057   if (theAssociatorParameters) delete theAssociatorParameters;
00058   if (theService) delete theService;
00059   if (theAssociator) delete theAssociator;
00060 }
00061 
00062 void JetExtractor::fillVetos(const edm::Event& event, const edm::EventSetup& eventSetup, const TrackCollection& muons)
00063 {
00064 //   LogWarning("JetExtractor")
00065 //     <<"fillVetos does nothing now: IsoDeposit provides enough functionality\n"
00066 //     <<"to remove a deposit at/around given (eta, phi)";
00067 
00068 }
00069 
00070 IsoDeposit JetExtractor::deposit( const Event & event, const EventSetup& eventSetup, const Track & muon) const
00071 {
00072 
00073   theService->update(eventSetup);
00074   theAssociator->setPropagator(&*(theService->propagator(thePropagatorName)));
00075  
00076   typedef IsoDeposit::Veto Veto;
00077   IsoDeposit::Direction muonDir(muon.eta(), muon.phi());
00078   
00079   IsoDeposit depJet(muonDir);
00080 
00081   edm::ESHandle<MagneticField> bField;
00082   eventSetup.get<IdealMagneticFieldRecord>().get(bField);
00083 
00084 
00085   reco::TransientTrack tMuon(muon, &*bField);
00086   FreeTrajectoryState iFTS = tMuon.initialFreeState();
00087   TrackDetMatchInfo mInfo = theAssociator->associate(event, eventSetup, iFTS, *theAssociatorParameters);
00088 
00089   reco::isodeposit::Direction vetoDirection(mInfo.trkGlobPosAtHcal.eta(), mInfo.trkGlobPosAtHcal.phi());
00090   depJet.setVeto(Veto(vetoDirection, theDR_Veto));
00091 
00092 
00093   edm::Handle<CaloJetCollection> caloJetsH;
00094   event.getByLabel(theJetCollectionLabel, caloJetsH);
00095 
00096   //use calo towers    
00097   CaloJetCollection::const_iterator jetCI = caloJetsH->begin();
00098   for (; jetCI != caloJetsH->end(); ++jetCI){
00099     double deltar0 = reco::deltaR(muon,*jetCI);
00100     if (deltar0>theDR_Max) continue;
00101     if (jetCI->et() < theThreshold ) continue;
00102 
00103     //should I make a separate config option for this?
00104     std::vector<CaloTowerPtr> jetConstituents = jetCI->getCaloConstituents();
00105 
00106     std::vector<DetId>::const_iterator crossedCI =  mInfo.crossedTowerIds.begin();
00107     std::vector<CaloTowerPtr>::const_iterator jetTowCI = jetConstituents.begin();
00108     
00109     double sumEtExcluded = 0;
00110     for (;jetTowCI != jetConstituents.end(); ++ jetTowCI){
00111       bool isExcluded = false;
00112       double deltaRLoc = reco::deltaR(vetoDirection, *jetCI);
00113       if (deltaRLoc < theDR_Veto){
00114         isExcluded = true;
00115       }
00116       for(; ! isExcluded && crossedCI != mInfo.crossedTowerIds.end(); ++crossedCI){
00117         if (crossedCI->rawId() == (*jetTowCI)->id().rawId()){
00118           isExcluded = true;
00119         }
00120       }
00121       if (isExcluded) sumEtExcluded += (*jetTowCI)->et();
00122     }
00123     if (theExcludeMuonVeto){
00124       if (jetCI->et() - sumEtExcluded < theThreshold ) continue;
00125     }
00126 
00127     double depositEt = jetCI->et();
00128     if (theExcludeMuonVeto) depositEt = depositEt - sumEtExcluded;
00129 
00130     reco::isodeposit::Direction jetDir(jetCI->eta(), jetCI->phi());
00131     depJet.addDeposit(jetDir, depositEt);
00132     
00133   }
00134 
00135   std::vector<const CaloTower*>::const_iterator crossedCI =  mInfo.crossedTowers.begin();
00136   double muSumEt = 0;
00137   for (; crossedCI != mInfo.crossedTowers.end(); ++crossedCI){
00138     muSumEt += (*crossedCI)->et();
00139   }
00140   depJet.addCandEnergy(muSumEt);
00141 
00142   return depJet;
00143 
00144 }
00145