CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoParticleFlow/PFProducer/plugins/PFBlockProducer.cc

Go to the documentation of this file.
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   // use configuration file to setup input/output collection names
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   inputTagPFClustersHFEM_ 
00066     = iConfig.getParameter<InputTag>("PFClustersHFEM");
00067 
00068   inputTagPFClustersHFHAD_ 
00069     = iConfig.getParameter<InputTag>("PFClustersHFHAD");
00070 
00071   inputTagPFClustersPS_ 
00072     = iConfig.getParameter<InputTag>("PFClustersPS");
00073 
00074   useEGPhotons_ = iConfig.getParameter<bool>("useEGPhotons");
00075   
00076   if(useEGPhotons_) {
00077     inputTagEGPhotons_
00078       = iConfig.getParameter<InputTag>("EGPhotons");
00079   }
00080 
00081   verbose_ = 
00082     iConfig.getUntrackedParameter<bool>("verbose",false);
00083 
00084   bool debug_ = 
00085     iConfig.getUntrackedParameter<bool>("debug",false);
00086 
00087   usePFatHLT_ = iConfig.getParameter<bool>("usePFatHLT");
00088 
00089   useNuclear_ = iConfig.getParameter<bool>("useNuclear");
00090 
00091   useConversions_ = iConfig.getParameter<bool>("useConversions");
00092   
00093   useConvBremGsfTracks_ = iConfig.getParameter<bool>("useConvBremGsfTracks");
00094 
00095   bool useConvBremPFRecTracks = iConfig.getParameter<bool>("useConvBremPFRecTracks");
00096 
00097   useV0_ = iConfig.getParameter<bool>("useV0");
00098 
00099   produces<reco::PFBlockCollection>();
00100   
00101 
00102   
00103   // particle flow parameters  -----------------------------------
00104 
00105   std::vector<double> DPtovPtCut 
00106      = iConfig.getParameter<std::vector<double> >("pf_DPtoverPt_Cut");   
00107 
00108   std::vector<unsigned> NHitCut 
00109      = iConfig.getParameter<std::vector<unsigned> >("pf_NHit_Cut");   
00110 
00111   bool useIterTracking
00112     = iConfig.getParameter<bool>("useIterTracking");
00113 
00114   int nuclearInteractionsPurity
00115     = iConfig.getParameter<unsigned>("nuclearInteractionsPurity");
00116 
00117   // if first parameter 0, deactivated 
00118   std::vector<double> EGPhotonSelectionCuts ;
00119 
00120   if (useEGPhotons_)
00121     EGPhotonSelectionCuts = iConfig.getParameter<std::vector<double> >("PhotonSelectionCuts");   
00122 
00123 
00124   if (useNuclear_){
00125     if (nuclearInteractionsPurity > 3 || nuclearInteractionsPurity < 1)  {
00126       nuclearInteractionsPurity = 1;
00127       edm::LogInfo("PFBlockProducer")  << "NI purity not properly implemented. Set it to the strongest level " << nuclearInteractionsPurity << endl;
00128     }
00129     vector<string> securityLevel;
00130     securityLevel.push_back("isNucl"); securityLevel.push_back("isNucl && isNuclLoose");  securityLevel.push_back("isNucl && isNuclLoose && isNuclKink"); 
00131     edm::LogInfo("PFBlockProducer")  << "NI interactions are corrected in PFlow for " << securityLevel[nuclearInteractionsPurity-1].c_str() << endl;
00132   }
00133 
00134 
00135   pfBlockAlgo_.setParameters( DPtovPtCut,
00136                               NHitCut,
00137                               useConvBremPFRecTracks,
00138                               useIterTracking,
00139                               nuclearInteractionsPurity,
00140                               useEGPhotons_,
00141                               EGPhotonSelectionCuts );
00142   
00143   pfBlockAlgo_.setDebug(debug_);
00144 
00145 }
00146 
00147 
00148 
00149 PFBlockProducer::~PFBlockProducer() { }
00150 
00151 
00152 
00153 void 
00154 PFBlockProducer::beginJob() { }
00155 
00156 void 
00157 PFBlockProducer::beginRun(edm::Run & run, 
00158                           const edm::EventSetup & es) { }
00159 
00160 
00161 void 
00162 PFBlockProducer::produce(Event& iEvent, 
00163                          const EventSetup& iSetup) {
00164   
00165   LogDebug("PFBlockProducer")<<"START event: "<<iEvent.id().event()
00166                              <<" in run "<<iEvent.id().run()<<endl;
00167   
00168   
00169   // get rectracks
00170   
00171   Handle< reco::PFRecTrackCollection > recTracks;
00172   
00173   // LogDebug("PFBlockProducer")<<"get reco tracks"<<endl;
00174   bool found = iEvent.getByLabel(inputTagRecTracks_, recTracks);
00175     
00176   if(!found )
00177     LogError("PFBlockProducer")<<" cannot get rectracks: "
00178                                <<inputTagRecTracks_<<endl;
00179 
00180 
00181 
00182   // get GsfTracks 
00183   Handle< reco::GsfPFRecTrackCollection > GsfrecTracks;
00184 
00185   if(!usePFatHLT_) {
00186     found = iEvent.getByLabel(inputTagGsfRecTracks_,GsfrecTracks);
00187 
00188     if(!found )
00189       LogError("PFBlockProducer")<<" cannot get Gsfrectracks: "
00190                                  << inputTagGsfRecTracks_ <<endl;
00191   }
00192 
00193   // get ConvBremGsfTracks 
00194   Handle< reco::GsfPFRecTrackCollection > convBremGsfrecTracks;
00195 
00196   if(useConvBremGsfTracks_) {
00197     found = iEvent.getByLabel(inputTagConvBremGsfRecTracks_,convBremGsfrecTracks);
00198 
00199     if(!found )
00200       LogError("PFBlockProducer")<<" cannot get ConvBremGsfrectracks: "
00201                                  << inputTagConvBremGsfRecTracks_ <<endl;
00202   }
00203 
00204   // get recmuons
00205   Handle< reco::MuonCollection > recMuons;
00206 
00207   // LogDebug("PFBlockProducer")<<"get reco muons"<<endl;
00208   //if(!usePFatHLT_) {
00209   found = iEvent.getByLabel(inputTagRecMuons_, recMuons);
00210   
00211     //if(!found )
00212     //  LogError("PFBlockProducer")<<" cannot get recmuons: "
00213     //                   <<inputTagRecMuons_<<endl;
00214 
00215   // get PFNuclearInteractions
00216   //}
00217   //---------- Gouzevitch
00218   //  Handle< reco::PFNuclearInteractionCollection > pfNuclears; 
00219   Handle< reco::PFDisplacedTrackerVertexCollection > pfNuclears; 
00220 
00221   if( useNuclear_ ) {
00222 
00223     found = iEvent.getByLabel(inputTagPFNuclear_, pfNuclears);
00224     if(!found )
00225       LogError("PFBlockProducer")<<" cannot get PFNuclearInteractions : "
00226                                <<inputTagPFNuclear_<<endl;
00227   }
00228 
00229 
00230 
00231  
00232   // get conversions
00233   Handle< reco::PFConversionCollection > pfConversions;
00234   if( useConversions_ ) {
00235     found = iEvent.getByLabel(inputTagPFConversions_, pfConversions);
00236     
00237     if(!found )
00238       LogError("PFBlockProducer")<<" cannot get PFConversions : "
00239                                  <<inputTagPFConversions_<<endl;
00240   }
00241   
00242 
00243   // get V0s
00244   Handle< reco::PFV0Collection > pfV0;
00245   if( useV0_ ) {
00246     found = iEvent.getByLabel(inputTagPFV0_, pfV0);
00247     
00248     if(!found )
00249       LogError("PFBlockProducer")<<" cannot get PFV0 : "
00250                                  <<inputTagPFV0_<<endl;
00251   }
00252 
00253 
00254   
00255   // get ECAL, HCAL and PS clusters
00256   
00257   
00258   Handle< reco::PFClusterCollection > clustersECAL;
00259   found = iEvent.getByLabel(inputTagPFClustersECAL_, 
00260                             clustersECAL);      
00261   if(!found )
00262     LogError("PFBlockProducer")<<" cannot get ECAL clusters: "
00263                                <<inputTagPFClustersECAL_<<endl;
00264     
00265   
00266   Handle< reco::PFClusterCollection > clustersHCAL;
00267   found = iEvent.getByLabel(inputTagPFClustersHCAL_, 
00268                             clustersHCAL);      
00269   if(!found )
00270     LogError("PFBlockProducer")<<" cannot get HCAL clusters: "
00271                                <<inputTagPFClustersHCAL_<<endl;
00272     
00273   Handle< reco::PFClusterCollection > clustersHFEM;
00274   found = iEvent.getByLabel(inputTagPFClustersHFEM_, 
00275                             clustersHFEM);      
00276   if(!found )
00277     LogError("PFBlockProducer")<<" cannot get HFEM clusters: "
00278                                <<inputTagPFClustersHFEM_<<endl;
00279     
00280   Handle< reco::PFClusterCollection > clustersHFHAD;
00281   found = iEvent.getByLabel(inputTagPFClustersHFHAD_, 
00282                             clustersHFHAD);      
00283   if(!found )
00284     LogError("PFBlockProducer")<<" cannot get HFHAD clusters: "
00285                                <<inputTagPFClustersHFHAD_<<endl;
00286     
00287 
00288   Handle< reco::PFClusterCollection > clustersPS;
00289   found = iEvent.getByLabel(inputTagPFClustersPS_, 
00290                             clustersPS);      
00291   if(!found )
00292     LogError("PFBlockProducer")<<" cannot get PS clusters: "
00293                                <<inputTagPFClustersPS_<<endl;
00294 
00295   // dummy. Not used in the full framework 
00296   Handle< reco::PFRecTrackCollection > nuclearRecTracks;
00297 
00298   
00299   Handle< reco::PhotonCollection >  egPhotons;
00300   found = iEvent.getByLabel(inputTagEGPhotons_,
00301                             egPhotons);
00302 
00303   if(!found && useEGPhotons_ )
00304     LogError("PFBlockProducer")<<" cannot get photons" 
00305                                << inputTagEGPhotons_ << endl;
00306 
00307   if( usePFatHLT_  ) {
00308      pfBlockAlgo_.setInput( recTracks,          
00309                             recMuons,
00310                            clustersECAL,
00311                            clustersHCAL,
00312                            clustersHFEM,
00313                            clustersHFHAD,
00314                            clustersPS );
00315   } else { 
00316     pfBlockAlgo_.setInput( recTracks, 
00317                            GsfrecTracks,
00318                            convBremGsfrecTracks,
00319                            recMuons, 
00320                            pfNuclears,
00321                            nuclearRecTracks,
00322                            pfConversions,
00323                            pfV0,
00324                            clustersECAL,
00325                            clustersHCAL,
00326                            clustersHFEM,
00327                            clustersHFHAD,
00328                            clustersPS,
00329                            egPhotons);
00330   }
00331   pfBlockAlgo_.findBlocks();
00332   
00333   if(verbose_) {
00334     ostringstream  str;
00335     str<<pfBlockAlgo_<<endl;
00336     LogInfo("PFBlockProducer") << str.str()<<endl;
00337   }    
00338   
00339   auto_ptr< reco::PFBlockCollection > 
00340     pOutputBlockCollection( pfBlockAlgo_.transferBlocks() ); 
00341   
00342   
00343   iEvent.put(pOutputBlockCollection);
00344   
00345   LogDebug("PFBlockProducer")<<"STOP event: "<<iEvent.id().event()
00346                              <<" in run "<<iEvent.id().run()<<endl;
00347 }