00001 #include "RecoParticleFlow/PFProducer/interface/PFProducer.h"
00002 #include "RecoParticleFlow/PFAlgo/interface/PFAlgo.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h"
00005 #include "RecoParticleFlow/PFClusterTools/interface/PFClusterCalibration.h"
00006
00007
00008 #include <sstream>
00009
00010 using namespace std;
00011
00012 using namespace boost;
00013
00014 using namespace edm;
00015
00016
00017
00018 PFProducer::PFProducer(const edm::ParameterSet& iConfig) {
00019
00020
00021 bool newCalib =
00022 iConfig.getParameter<bool>("pf_newCalib");
00023
00024
00025 shared_ptr<pftools::PFClusterCalibration>
00026 clusterCalibration( new pftools::PFClusterCalibration() );
00027
00028
00029 double lowEP0
00030 = iConfig.getParameter<double>("pfcluster_lowEP0");
00031 double lowEP1
00032 = iConfig.getParameter<double>("pfcluster_lowEP1");
00033 double globalP0
00034 = iConfig.getParameter<double>("pfcluster_globalP0");
00035 double globalP1
00036 = iConfig.getParameter<double>("pfcluster_globalP1");
00037
00038 clusterCalibration->setCorrections(lowEP0, lowEP1, globalP0, globalP1);
00039
00040 unsigned int allowNegative
00041 = iConfig.getParameter<unsigned int>("pfcluster_allowNegative");
00042 clusterCalibration->setAllowNegativeEnergy(allowNegative);
00043
00044 unsigned int doCorrection
00045 = iConfig.getParameter<unsigned int>("pfcluster_doCorrection");
00046 clusterCalibration->setDoCorrection(doCorrection);
00047
00048 double barrelEta
00049 = iConfig.getParameter<double>("pfcluster_barrelEndcapEtaDiv");
00050 clusterCalibration->setBarrelBoundary(barrelEta);
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 std::vector<std::string>* names = clusterCalibration->getKnownSectorNames();
00062 for(std::vector<std::string>::iterator i = names->begin(); i != names->end(); ++i) {
00063 std::string sector = *i;
00064 std::vector<double> params
00065 = iConfig.getParameter<std::vector<double> >(sector);
00066 clusterCalibration->setEvolutionParameters(sector, params);
00067 }
00068
00069
00070 unsigned int doEtaCorrection = iConfig.getParameter<unsigned int>("pfcluster_doEtaCorrection");
00071 clusterCalibration->setDoEtaCorrection(doEtaCorrection);
00072
00073 std::vector<double> etaCorrectionParams =
00074 iConfig.getParameter<std::vector<double> >("pfcluster_etaCorrection");
00075 clusterCalibration->setEtaCorrectionParameters(etaCorrectionParams);
00076
00077
00078
00079
00080
00081
00082 inputTagBlocks_
00083 = iConfig.getParameter<InputTag>("blocks");
00084
00085
00086 produces<reco::PFCandidateCollection>();
00087
00088
00089 double nSigmaECAL
00090 = iConfig.getParameter<double>("pf_nsigma_ECAL");
00091 double nSigmaHCAL
00092 = iConfig.getParameter<double>("pf_nsigma_HCAL");
00093
00094
00095 double e_slope
00096 = iConfig.getParameter<double>("pf_calib_ECAL_slope");
00097 double e_offset
00098 = iConfig.getParameter<double>("pf_calib_ECAL_offset");
00099
00100 double eh_eslope
00101 = iConfig.getParameter<double>("pf_calib_ECAL_HCAL_eslope");
00102 double eh_hslope
00103 = iConfig.getParameter<double>("pf_calib_ECAL_HCAL_hslope");
00104 double eh_offset
00105 = iConfig.getParameter<double>("pf_calib_ECAL_HCAL_offset");
00106
00107 double h_slope
00108 = iConfig.getParameter<double>("pf_calib_HCAL_slope");
00109 double h_offset
00110 = iConfig.getParameter<double>("pf_calib_HCAL_offset");
00111 double h_damping
00112 = iConfig.getParameter<double>("pf_calib_HCAL_damping");
00113
00114
00115 double chi2EcalGSF
00116 = iConfig.getParameter<double>("final_chi2cut_gsfecal");
00117 double chi2EcalBrem
00118 = iConfig.getParameter<double>("final_chi2cut_bremecal");
00119 double chi2HcalGSF
00120 = iConfig.getParameter<double>("final_chi2cut_gsfhcal");
00121 double chi2HcalBrem
00122 = iConfig.getParameter<double>("final_chi2cut_bremhcal");
00123 double chi2PsGSF
00124 = iConfig.getParameter<double>("final_chi2cut_gsfps");
00125 double chi2PsBrem
00126 = iConfig.getParameter<double>("final_chi2cut_bremps");
00127
00128
00129 double mvaEleCut
00130 = iConfig.getParameter<double>("pf_electron_mvaCut");
00131 bool usePFElectrons
00132 = iConfig.getParameter<bool>("usePFElectrons");
00133 string mvaWeightFileEleID
00134 = iConfig.getParameter<string>("pf_electronID_mvaWeightFile");
00135 edm::FileInPath path_mvaWeightFileEleID( mvaWeightFileEleID.c_str() );
00136
00137
00138
00139 bool usePFConversions
00140 = iConfig.getParameter<bool>("usePFConversions");
00141
00142
00143
00144
00145 shared_ptr<PFEnergyCalibration>
00146 calibration( new PFEnergyCalibration( e_slope,
00147 e_offset,
00148 eh_eslope,
00149 eh_hslope,
00150 eh_offset,
00151 h_slope,
00152 h_offset,
00153 h_damping ) );
00154
00155 bool clusterRecovery
00156 = iConfig.getParameter<bool>("pf_clusterRecovery");
00157
00158 double mvaCut = iConfig.getParameter<double>("pf_mergedPhotons_mvaCut");
00159 string mvaWeightFile
00160 = iConfig.getParameter<string>("pf_mergedPhotons_mvaWeightFile");
00161 edm::FileInPath path_mvaWeightFile( mvaWeightFile.c_str() );
00162 double PSCut = iConfig.getParameter<double>("pf_mergedPhotons_PSCut");
00163
00164 int algoType
00165 = iConfig.getParameter<unsigned>("algoType");
00166
00167 switch(algoType) {
00168 case 0:
00169 pfAlgo_.reset( new PFAlgo);
00170 break;
00171 default:
00172 assert(0);
00173 }
00174
00175 pfAlgo_->setParameters( nSigmaECAL,
00176 nSigmaHCAL,
00177 calibration,
00178 clusterCalibration,
00179 newCalib,
00180 clusterRecovery,
00181 PSCut,
00182 mvaCut,
00183 path_mvaWeightFile.fullPath().c_str() );
00184
00185
00186 pfAlgo_->setPFEleParameters(chi2EcalGSF,
00187 chi2EcalBrem,
00188 chi2HcalGSF,
00189 chi2HcalBrem,
00190 chi2PsGSF,
00191 chi2PsBrem,
00192 mvaEleCut,
00193 path_mvaWeightFileEleID.fullPath(),
00194 usePFElectrons);
00195
00196 pfAlgo_->setPFConversionParameters(usePFConversions);
00197
00198
00199 verbose_ =
00200 iConfig.getUntrackedParameter<bool>("verbose",false);
00201
00202 bool debug_ =
00203 iConfig.getUntrackedParameter<bool>("debug",false);
00204
00205 pfAlgo_->setDebug( debug_ );
00206
00207 }
00208
00209
00210
00211 PFProducer::~PFProducer() {}
00212
00213
00214 void PFProducer::beginJob(const edm::EventSetup & es) {}
00215
00216
00217 void PFProducer::produce(Event& iEvent,
00218 const EventSetup& iSetup) {
00219
00220 LogDebug("PFProducer")<<"START event: "
00221 <<iEvent.id().event()
00222 <<" in run "<<iEvent.id().run()<<endl;
00223
00224
00225
00226
00227 Handle< reco::PFBlockCollection > blocks;
00228
00229 LogDebug("PFBlock")<<"getting blocks"<<endl;
00230 bool found = iEvent.getByLabel( inputTagBlocks_, blocks );
00231
00232 if(!found ) {
00233
00234 ostringstream err;
00235 err<<"cannot find blocks: "<<inputTagBlocks_;
00236 LogError("PFSimParticleProducer")<<err.str()<<endl;
00237
00238 throw cms::Exception( "MissingProduct", err.str());
00239 }
00240
00241
00242 LogDebug("PFProducer")<<"particle flow is starting"<<endl;
00243
00244 assert( blocks.isValid() );
00245
00246 pfAlgo_->reconstructParticles( blocks );
00247
00248
00249 if(verbose_) {
00250 ostringstream str;
00251 str<<(*pfAlgo_)<<endl;
00252 LogInfo("PFProducer") <<str.str()<<endl;
00253 }
00254
00255 auto_ptr< reco::PFCandidateCollection >
00256 pOutputCandidateCollection( pfAlgo_->transferCandidates() );
00257
00258 LogDebug("PFProducer")<<"particle flow: putting products in the event"<<endl;
00259 if ( verbose_ ) std::cout <<"particle flow: putting products in the event. Here the full list"<<endl;
00260 int nC=0;
00261 for( reco::PFCandidateCollection::const_iterator itCand = (*pOutputCandidateCollection).begin(); itCand != (*pOutputCandidateCollection).end(); itCand++) {
00262 nC++;
00263 if (verbose_ ) std::cout << nC << ")" << (*itCand).particleId() << std::endl;
00264
00265 }
00266
00267 iEvent.put(pOutputCandidateCollection);
00268 }
00269