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 "TrackingTools/TransientTrack/interface/TransientTrack.h"
00023 #include "TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
00024 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00025
00026 #include "PhysicsTools/Utilities/interface/deltaR.h"
00027
00028 using namespace edm;
00029 using namespace std;
00030 using namespace reco;
00031 using namespace muonisolation;
00032 using reco::isodeposit::Direction;
00033
00034 JetExtractor::JetExtractor(const ParameterSet& par) :
00035 theJetCollectionLabel(par.getParameter<edm::InputTag>("JetCollectionLabel")),
00036 thePropagatorName(par.getParameter<std::string>("PropagatorName")),
00037 theThreshold(par.getParameter<double>("Threshold")),
00038 theDR_Veto(par.getParameter<double>("DR_Veto")),
00039 theDR_Max(par.getParameter<double>("DR_Max")),
00040 theExcludeMuonVeto(par.getParameter<bool>("ExcludeMuonVeto")),
00041 theAssociator(0),
00042 thePropagator(0),
00043 thePrintTimeReport(par.getUntrackedParameter<bool>("PrintTimeReport"))
00044 {
00045 theAssociatorParameters = new TrackAssociatorParameters(par.getParameter<edm::ParameterSet>("TrackAssociatorParameters"));
00046 theAssociator = new TrackDetectorAssociator();
00047 }
00048
00049 JetExtractor::~JetExtractor(){
00050 if (thePrintTimeReport) TimingReport::current()->dump(std::cout);
00051 if (theAssociatorParameters) delete theAssociatorParameters;
00052 if (theAssociator) delete theAssociator;
00053 if (thePropagator) delete thePropagator;
00054 }
00055
00056 void JetExtractor::fillVetos(const edm::Event& event, const edm::EventSetup& eventSetup, const TrackCollection& muons)
00057 {
00058
00059
00060
00061
00062 }
00063
00064 IsoDeposit JetExtractor::deposit( const Event & event, const EventSetup& eventSetup, const Track & muon) const
00065 {
00066 if (thePropagator == 0){
00067 ESHandle<Propagator> prop;
00068 eventSetup.get<TrackingComponentsRecord>().get(thePropagatorName, prop);
00069 thePropagator = prop->clone();
00070 theAssociator->setPropagator(thePropagator);
00071 }
00072
00073 typedef IsoDeposit::Veto Veto;
00074 IsoDeposit::Direction muonDir(muon.eta(), muon.phi());
00075
00076 IsoDeposit depJet(muonDir);
00077
00078 edm::ESHandle<MagneticField> bField;
00079 eventSetup.get<IdealMagneticFieldRecord>().get(bField);
00080
00081
00082 reco::TransientTrack tMuon(muon, &*bField);
00083 FreeTrajectoryState iFTS = tMuon.initialFreeState();
00084 TrackDetMatchInfo mInfo = theAssociator->associate(event, eventSetup, iFTS, *theAssociatorParameters);
00085
00086 reco::isodeposit::Direction vetoDirection(mInfo.trkGlobPosAtHcal.eta(), mInfo.trkGlobPosAtHcal.phi());
00087 depJet.setVeto(Veto(vetoDirection, theDR_Veto));
00088
00089
00090 edm::Handle<CaloJetCollection> caloJetsH;
00091 event.getByLabel(theJetCollectionLabel, caloJetsH);
00092
00093
00094 CaloJetCollection::const_iterator jetCI = caloJetsH->begin();
00095 for (; jetCI != caloJetsH->end(); ++jetCI){
00096 double deltar0 = reco::deltaR(muon,*jetCI);
00097 if (deltar0>theDR_Max) continue;
00098 if (jetCI->et() < theThreshold ) continue;
00099
00100
00101 std::vector<CaloTowerPtr> jetConstituents = jetCI->getCaloConstituents();
00102
00103 std::vector<DetId>::const_iterator crossedCI = mInfo.crossedTowerIds.begin();
00104 std::vector<CaloTowerPtr>::const_iterator jetTowCI = jetConstituents.begin();
00105
00106 double sumEtExcluded = 0;
00107 for (;jetTowCI != jetConstituents.end(); ++ jetTowCI){
00108 bool isExcluded = false;
00109 double deltaRLoc = reco::deltaR(vetoDirection, *jetCI);
00110 if (deltaRLoc < theDR_Veto){
00111 isExcluded = true;
00112 }
00113 for(; ! isExcluded && crossedCI != mInfo.crossedTowerIds.end(); ++crossedCI){
00114 if (crossedCI->rawId() == (*jetTowCI)->id().rawId()){
00115 isExcluded = true;
00116 }
00117 }
00118 if (isExcluded) sumEtExcluded += (*jetTowCI)->et();
00119 }
00120 if (theExcludeMuonVeto){
00121 if (jetCI->et() - sumEtExcluded < theThreshold ) continue;
00122 }
00123
00124 double depositEt = jetCI->et();
00125 if (theExcludeMuonVeto) depositEt = depositEt - sumEtExcluded;
00126
00127 reco::isodeposit::Direction jetDir(jetCI->eta(), jetCI->phi());
00128 depJet.addDeposit(jetDir, depositEt);
00129
00130 }
00131
00132 std::vector<const CaloTower*>::const_iterator crossedCI = mInfo.crossedTowers.begin();
00133 double muSumEt = 0;
00134 for (; crossedCI != mInfo.crossedTowers.end(); ++crossedCI){
00135 muSumEt += (*crossedCI)->et();
00136 }
00137 depJet.addCandEnergy(muSumEt);
00138
00139 return depJet;
00140
00141 }
00142