00001 #include "RecoParticleFlow/PFProducer/plugins/PFBlockProducer.h"
00002
00003 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyCalibration.h"
00004 #include "RecoParticleFlow/PFClusterTools/interface/PFEnergyResolution.h"
00005
00006 #include "DataFormats/ParticleFlowReco/interface/PFLayer.h"
00007 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
00008 #include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h"
00009 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertexFwd.h"
00010 #include "DataFormats/ParticleFlowReco/interface/PFDisplacedVertex.h"
00011 #include "DataFormats/ParticleFlowReco/interface/PFConversionFwd.h"
00012 #include "DataFormats/ParticleFlowReco/interface/PFConversion.h"
00013 #include "DataFormats/ParticleFlowReco/interface/PFV0Fwd.h"
00014 #include "DataFormats/ParticleFlowReco/interface/PFV0.h"
00015
00016 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00017 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
00018
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 #include "FWCore/Utilities/interface/Exception.h"
00023 #include "FWCore/Framework/interface/EventSetup.h"
00024
00025 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00026
00027 #include "FWCore/ParameterSet/interface/FileInPath.h"
00028
00029 #include <set>
00030
00031 using namespace std;
00032 using namespace edm;
00033
00034 PFBlockProducer::PFBlockProducer(const edm::ParameterSet& iConfig) {
00035
00036
00037
00038 inputTagRecTracks_
00039 = iConfig.getParameter<InputTag>("RecTracks");
00040
00041 inputTagGsfRecTracks_
00042 = iConfig.getParameter<InputTag>("GsfRecTracks");
00043
00044 inputTagConvBremGsfRecTracks_
00045 = iConfig.getParameter<InputTag>("ConvBremGsfRecTracks");
00046
00047 inputTagRecMuons_
00048 = iConfig.getParameter<InputTag>("RecMuons");
00049
00050 inputTagPFNuclear_
00051 = iConfig.getParameter<InputTag>("PFNuclear");
00052
00053 inputTagPFConversions_
00054 = iConfig.getParameter<InputTag>("PFConversions");
00055
00056 inputTagPFV0_
00057 = iConfig.getParameter<InputTag>("PFV0");
00058
00059 inputTagPFClustersECAL_
00060 = iConfig.getParameter<InputTag>("PFClustersECAL");
00061
00062 inputTagPFClustersHCAL_
00063 = iConfig.getParameter<InputTag>("PFClustersHCAL");
00064
00065 inputTagPFClustersHO_
00066 = iConfig.getParameter<InputTag>("PFClustersHO");
00067
00068 inputTagPFClustersHFEM_
00069 = iConfig.getParameter<InputTag>("PFClustersHFEM");
00070
00071 inputTagPFClustersHFHAD_
00072 = iConfig.getParameter<InputTag>("PFClustersHFHAD");
00073
00074 inputTagPFClustersPS_
00075 = iConfig.getParameter<InputTag>("PFClustersPS");
00076
00077 useEGPhotons_ = iConfig.getParameter<bool>("useEGPhotons");
00078
00079 if(useEGPhotons_) {
00080 inputTagEGPhotons_
00081 = iConfig.getParameter<InputTag>("EGPhotons");
00082 }
00083
00084 verbose_ =
00085 iConfig.getUntrackedParameter<bool>("verbose",false);
00086
00087 bool debug_ =
00088 iConfig.getUntrackedParameter<bool>("debug",false);
00089
00090 usePFatHLT_ = iConfig.getParameter<bool>("usePFatHLT");
00091
00092 useNuclear_ = iConfig.getParameter<bool>("useNuclear");
00093
00094 useConversions_ = iConfig.getParameter<bool>("useConversions");
00095
00096 useConvBremGsfTracks_ = iConfig.getParameter<bool>("useConvBremGsfTracks");
00097
00098 bool useConvBremPFRecTracks = iConfig.getParameter<bool>("useConvBremPFRecTracks");
00099
00100 useV0_ = iConfig.getParameter<bool>("useV0");
00101
00102 useHO_= iConfig.getParameter<bool>("useHO");
00103
00104 produces<reco::PFBlockCollection>();
00105
00106
00107 useKDTreeTrackEcalLinker_ = iConfig.getParameter<bool>("useKDTreeTrackEcalLinker");
00108
00109
00110
00111
00112 std::vector<double> DPtovPtCut
00113 = iConfig.getParameter<std::vector<double> >("pf_DPtoverPt_Cut");
00114 if (DPtovPtCut.size()!=5)
00115 {
00116 edm::LogError("MisConfiguration")<<" vector pf_DPtoverPt_Cut has to be of size 5";
00117 throw;
00118 }
00119
00120 std::vector<unsigned> NHitCut
00121 = iConfig.getParameter<std::vector<unsigned> >("pf_NHit_Cut");
00122 if (NHitCut.size()!=5)
00123 {
00124 edm::LogError("MisConfiguration")<<" vector pf_NHit_Cut has to be of size 5";
00125 throw;
00126 }
00127
00128 bool useIterTracking
00129 = iConfig.getParameter<bool>("useIterTracking");
00130
00131 int nuclearInteractionsPurity
00132 = iConfig.getParameter<unsigned>("nuclearInteractionsPurity");
00133
00134
00135 std::vector<double> EGPhotonSelectionCuts ;
00136
00137 if (useEGPhotons_)
00138 EGPhotonSelectionCuts = iConfig.getParameter<std::vector<double> >("PhotonSelectionCuts");
00139
00140
00141 if (useNuclear_){
00142 if (nuclearInteractionsPurity > 3 || nuclearInteractionsPurity < 1) {
00143 nuclearInteractionsPurity = 1;
00144 edm::LogInfo("PFBlockProducer") << "NI purity not properly implemented. Set it to the strongest level " << nuclearInteractionsPurity << endl;
00145 }
00146 vector<string> securityLevel;
00147 securityLevel.push_back("isNucl"); securityLevel.push_back("isNucl && isNuclLoose"); securityLevel.push_back("isNucl && isNuclLoose && isNuclKink");
00148 edm::LogInfo("PFBlockProducer") << "NI interactions are corrected in PFlow for " << securityLevel[nuclearInteractionsPurity-1].c_str() << endl;
00149 }
00150
00151
00152 pfBlockAlgo_.setParameters( DPtovPtCut,
00153 NHitCut,
00154 useConvBremPFRecTracks,
00155 useIterTracking,
00156 nuclearInteractionsPurity,
00157 useEGPhotons_,
00158 EGPhotonSelectionCuts );
00159
00160 pfBlockAlgo_.setDebug(debug_);
00161
00162
00163 pfBlockAlgo_.setUseOptimization(useKDTreeTrackEcalLinker_);
00164
00165
00166
00167 pfBlockAlgo_.setHOTag(useHO_);
00168
00169 }
00170
00171
00172
00173 PFBlockProducer::~PFBlockProducer() { }
00174
00175
00176
00177 void
00178 PFBlockProducer::beginJob() { }
00179
00180 void
00181 PFBlockProducer::beginRun(edm::Run & run,
00182 const edm::EventSetup & es) { }
00183
00184
00185 void
00186 PFBlockProducer::produce(Event& iEvent,
00187 const EventSetup& iSetup) {
00188
00189 LogDebug("PFBlockProducer")<<"START event: "<<iEvent.id().event()
00190 <<" in run "<<iEvent.id().run()<<endl;
00191
00192
00193
00194
00195 Handle< reco::PFRecTrackCollection > recTracks;
00196
00197
00198 bool found = iEvent.getByLabel(inputTagRecTracks_, recTracks);
00199
00200 if(!found )
00201 LogError("PFBlockProducer")<<" cannot get rectracks: "
00202 <<inputTagRecTracks_<<endl;
00203
00204
00205
00206
00207 Handle< reco::GsfPFRecTrackCollection > GsfrecTracks;
00208
00209 if(!usePFatHLT_) {
00210 found = iEvent.getByLabel(inputTagGsfRecTracks_,GsfrecTracks);
00211
00212 if(!found )
00213 LogError("PFBlockProducer")<<" cannot get Gsfrectracks: "
00214 << inputTagGsfRecTracks_ <<endl;
00215 }
00216
00217
00218 Handle< reco::GsfPFRecTrackCollection > convBremGsfrecTracks;
00219
00220 if(useConvBremGsfTracks_) {
00221 found = iEvent.getByLabel(inputTagConvBremGsfRecTracks_,convBremGsfrecTracks);
00222
00223 if(!found )
00224 LogError("PFBlockProducer")<<" cannot get ConvBremGsfrectracks: "
00225 << inputTagConvBremGsfRecTracks_ <<endl;
00226 }
00227
00228
00229 Handle< reco::MuonCollection > recMuons;
00230
00231
00232
00233 found = iEvent.getByLabel(inputTagRecMuons_, recMuons);
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 Handle< reco::PFDisplacedTrackerVertexCollection > pfNuclears;
00244
00245 if( useNuclear_ ) {
00246
00247 found = iEvent.getByLabel(inputTagPFNuclear_, pfNuclears);
00248 if(!found )
00249 LogError("PFBlockProducer")<<" cannot get PFNuclearInteractions : "
00250 <<inputTagPFNuclear_<<endl;
00251 }
00252
00253
00254 Handle< reco::PFConversionCollection > pfConversions;
00255 if( useConversions_ ) {
00256 found = iEvent.getByLabel(inputTagPFConversions_, pfConversions);
00257
00258 if(!found )
00259 LogError("PFBlockProducer")<<" cannot get PFConversions : "
00260 <<inputTagPFConversions_<<endl;
00261 }
00262
00263
00264
00265 Handle< reco::PFV0Collection > pfV0;
00266 if( useV0_ ) {
00267 found = iEvent.getByLabel(inputTagPFV0_, pfV0);
00268
00269 if(!found )
00270 LogError("PFBlockProducer")<<" cannot get PFV0 : "
00271 <<inputTagPFV0_<<endl;
00272 }
00273
00274
00275
00276
00277
00278
00279 Handle< reco::PFClusterCollection > clustersECAL;
00280 found = iEvent.getByLabel(inputTagPFClustersECAL_,
00281 clustersECAL);
00282 if(!found )
00283 LogError("PFBlockProducer")<<" cannot get ECAL clusters: "
00284 <<inputTagPFClustersECAL_<<endl;
00285
00286
00287 Handle< reco::PFClusterCollection > clustersHCAL;
00288 found = iEvent.getByLabel(inputTagPFClustersHCAL_,
00289 clustersHCAL);
00290 if(!found )
00291 LogError("PFBlockProducer")<<" cannot get HCAL clusters: "
00292 <<inputTagPFClustersHCAL_<<endl;
00293
00294 Handle< reco::PFClusterCollection > clustersHO;
00295 if (useHO_) {
00296 found = iEvent.getByLabel(inputTagPFClustersHO_,
00297 clustersHO);
00298 if(!found )
00299 LogError("PFBlockProducer")<<" cannot get HO clusters: "
00300 <<inputTagPFClustersHO_<<endl;
00301 }
00302
00303 Handle< reco::PFClusterCollection > clustersHFEM;
00304 found = iEvent.getByLabel(inputTagPFClustersHFEM_,
00305 clustersHFEM);
00306 if(!found )
00307 LogError("PFBlockProducer")<<" cannot get HFEM clusters: "
00308 <<inputTagPFClustersHFEM_<<endl;
00309
00310 Handle< reco::PFClusterCollection > clustersHFHAD;
00311 found = iEvent.getByLabel(inputTagPFClustersHFHAD_,
00312 clustersHFHAD);
00313 if(!found )
00314 LogError("PFBlockProducer")<<" cannot get HFHAD clusters: "
00315 <<inputTagPFClustersHFHAD_<<endl;
00316
00317
00318 Handle< reco::PFClusterCollection > clustersPS;
00319 found = iEvent.getByLabel(inputTagPFClustersPS_,
00320 clustersPS);
00321 if(!found )
00322 LogError("PFBlockProducer")<<" cannot get PS clusters: "
00323 <<inputTagPFClustersPS_<<endl;
00324
00325
00326 Handle< reco::PFRecTrackCollection > nuclearRecTracks;
00327
00328
00329 Handle< reco::PhotonCollection > egPhotons;
00330 found = iEvent.getByLabel(inputTagEGPhotons_,
00331 egPhotons);
00332
00333 if(!found && useEGPhotons_ )
00334 LogError("PFBlockProducer")<<" cannot get photons"
00335 << inputTagEGPhotons_ << endl;
00336
00337 if( usePFatHLT_ ) {
00338 pfBlockAlgo_.setInput( recTracks,
00339 recMuons,
00340 clustersECAL,
00341 clustersHCAL,
00342 clustersHO,
00343 clustersHFEM,
00344 clustersHFHAD,
00345 clustersPS);
00346 } else {
00347 pfBlockAlgo_.setInput( recTracks,
00348 GsfrecTracks,
00349 convBremGsfrecTracks,
00350 recMuons,
00351 pfNuclears,
00352 nuclearRecTracks,
00353 pfConversions,
00354 pfV0,
00355 clustersECAL,
00356 clustersHCAL,
00357 clustersHO,
00358 clustersHFEM,
00359 clustersHFHAD,
00360 clustersPS,
00361 egPhotons);
00362 }
00363 pfBlockAlgo_.findBlocks();
00364
00365 if(verbose_) {
00366 ostringstream str;
00367 str<<pfBlockAlgo_<<endl;
00368 LogInfo("PFBlockProducer") << str.str()<<endl;
00369 }
00370
00371 auto_ptr< reco::PFBlockCollection >
00372 pOutputBlockCollection( pfBlockAlgo_.transferBlocks() );
00373
00374 iEvent.put(pOutputBlockCollection);
00375
00376 LogDebug("PFBlockProducer")<<"STOP event: "<<iEvent.id().event()
00377 <<" in run "<<iEvent.id().run()<<endl;
00378 }