Go to the documentation of this file.00001 #include "FastSimulation/ParticleFlow/plugins/FSPFProducer.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004
00005 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00006 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00007 #include "DataFormats/Math/interface/LorentzVector.h"
00008
00009 using namespace std;
00010 using namespace edm;
00011 using namespace reco;
00012
00013
00014 FSPFProducer::FSPFProducer(const edm::ParameterSet& iConfig) {
00015
00016 labelPFCandidateCollection_ = iConfig.getParameter < edm::InputTag > ("pfCandidates");
00017
00018 pfPatchInHF = iConfig.getParameter<bool>("pfPatchInHF");
00019 EM_HF_ScaleFactor = iConfig.getParameter< std::vector <double> >("EM_HF_ScaleFactor");
00020 HF_Ratio = iConfig.getParameter<double>("HF_Ratio");
00021 par1 = iConfig.getParameter<double>("par1");
00022 par2 = iConfig.getParameter<double>("par2");
00023 barrel_th = iConfig.getParameter<double>("barrel_th");
00024 endcap_th = iConfig.getParameter<double>("endcap_th");
00025 middle_th = iConfig.getParameter<double>("middle_th");
00026
00027 produces<reco::PFCandidateCollection>();
00028
00029 }
00030
00031 FSPFProducer::~FSPFProducer() {}
00032
00033 void
00034 FSPFProducer::produce(Event& iEvent,
00035 const EventSetup& iSetup) {
00036
00037 Handle < reco::PFCandidateCollection > pfCandidates;
00038 iEvent.getByLabel (labelPFCandidateCollection_, pfCandidates);
00039
00040 auto_ptr< reco::PFCandidateCollection > pOutputCandidateCollection(new PFCandidateCollection);
00041
00042
00043
00044
00045
00046
00047
00048 double theNeutralFraction, px, py, pz, en;
00049 int n_hadron_HF = 0;
00050 int n_em_HF = 0;
00051 int vEta=-1;
00052 reco::PFCandidateCollection::const_iterator itCand = pfCandidates->begin();
00053 reco::PFCandidateCollection::const_iterator itCandEnd = pfCandidates->end();
00054 for( ; itCand != itCandEnd; itCand++) {
00055
00056
00057 if(itCand->particleId() == reco::PFCandidate::h){
00058 theNeutralFraction = par1 - par2*itCand->energy();
00059 if(theNeutralFraction > 0.){
00060 px = theNeutralFraction*itCand->px();
00061 py = theNeutralFraction*itCand->py();
00062 pz = theNeutralFraction*itCand->pz();
00063 en = sqrt(px*px + py*py + pz*pz);
00064 if (en > energy_threshold(itCand->eta())) {
00065
00066 math::XYZTLorentzVector momentum(px,py,pz,en);
00067 reco::PFCandidate FakeNeutralHadron(0, momentum, reco::PFCandidate::h0);
00068 pOutputCandidateCollection->push_back(FakeNeutralHadron);
00069 }
00070 }
00071 }
00072
00073
00074 if(itCand->particleId() == reco::PFCandidate::egamma_HF){
00075 if (pfPatchInHF) {
00076 n_em_HF++;
00077
00078 if(fabs(itCand->eta())< 4.) vEta = 0;
00079 else if(fabs(itCand->eta())<= 5.) vEta = 1;
00080
00081 if (vEta==0 || vEta==1) {
00082
00083 px = EM_HF_ScaleFactor[vEta]*itCand->px();
00084 py = EM_HF_ScaleFactor[vEta]*itCand->py();
00085 pz = EM_HF_ScaleFactor[vEta]*itCand->pz();
00086 en = sqrt(px*px + py*py + pz*pz);
00087 math::XYZTLorentzVector momentum(px,py,pz,en);
00088 reco::PFCandidate EMHF(itCand->charge(), momentum, reco::PFCandidate::egamma_HF);
00089 if(en>0.) pOutputCandidateCollection->push_back(EMHF);
00090 }
00091 } else pOutputCandidateCollection->push_back(*itCand);
00092 }
00093
00094 else if(itCand->particleId() == reco::PFCandidate::h_HF){
00095 if (pfPatchInHF) {
00096
00097 n_hadron_HF++;
00098 if(n_em_HF < (n_hadron_HF*HF_Ratio)) pOutputCandidateCollection->push_back(*itCand);
00099 } else pOutputCandidateCollection->push_back(*itCand);
00100 }
00101
00102 else pOutputCandidateCollection->push_back(*itCand);
00103
00104 }
00105 iEvent.put(pOutputCandidateCollection);
00106 }
00107
00108 double FSPFProducer::energy_threshold(double eta) {
00109 if (eta<0) eta = -eta;
00110 if (eta < 1.6) return barrel_th;
00111 else if (eta < 1.8) return middle_th;
00112 else return endcap_th;
00113 }
00114
00115
00116
00117 DEFINE_FWK_MODULE (FSPFProducer);