CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoMET/METProducers/src/METProducer.cc

Go to the documentation of this file.
00001 // File: METProducer.cc 
00002 // Description:  see METProducer.h
00003 // Author: R. Cavanaugh, The University of Florida
00004 // Creation Date:  20.04.2006.
00005 //
00006 //--------------------------------------------
00007 // Modification by R. Remington on 10/21/08
00008 // Added globalThreshold input Parameter to impose on each tower in tower collection
00009 // that is looped over by the CaloSpecificAlgo.  This is in order to fulfill Scheme B threhsolds...   
00010 // Modified:     12.13.2008 by R.Cavanaugh, UIC/Fermilab
00011 // Description:  include Particle Flow MET
00012 // Modified:     12.12.2008  by R. Remington, UFL
00013 // Description:  include TCMET , move alg_.run() inside of relevant if-statements, and add METSignficance algorithm to METtype="CaloMET" cases
00014 
00015 #include <memory>
00016 #include "RecoMET/METProducers/interface/METProducer.h"
00017 #include "RecoMET/METAlgorithms/interface/SignCaloSpecificAlgo.h"
00018 #include "RecoMET/METAlgorithms/interface/SignAlgoResolutions.h"
00019 #include "RecoMET/METAlgorithms/interface/CaloSpecificAlgo.h"
00020 #include "RecoMET/METAlgorithms/interface/GenSpecificAlgo.h"
00021 #include "RecoMET/METAlgorithms/interface/TCMETAlgo.h"
00022 #include "RecoMET/METAlgorithms/interface/PFSpecificAlgo.h"
00023 #include "RecoMET/METAlgorithms/interface/PFClusterSpecificAlgo.h"
00024 #include "DataFormats/JetReco/interface/CaloJet.h"
00025 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00026 #include "DataFormats/METReco/interface/CommonMETData.h"
00027 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00028 #include "DataFormats/Candidate/interface/Particle.h"
00029 #include "DataFormats/Candidate/interface/Candidate.h"
00030 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00031 #include "DataFormats/Common/interface/View.h"
00032 
00033 using namespace edm;
00034 using namespace std;
00035 using namespace reco;
00036 
00037 namespace cms 
00038 {
00039   //--------------------------------------------------------------------------
00040   // Constructor : used to fill the parameters from the configuration file
00041   // Currently there are only two defined parameters:
00042   // 1. src = the label of the input data product (which must derive from 
00043   //    Candidate)
00044   // 2. METType = the type of to produce into the event.  currently there are
00045   //    only two types of MET defined: (1) MET from calorimetery (and so 
00046   //    contains extra information specific to calorimetery) and (2) the 
00047   //    default MET which contains only generic information.  Additional
00048   //    MET types will appear (such as GenMET) in the future.  (All "types"
00049   //    of MET inherit from RecoCandidate and merely extend that class with
00050   //    extra information)
00051   //-----------------------------------
00052   METProducer::METProducer(const edm::ParameterSet& iConfig) : alg_() , resolutions_(0), tcmetalgorithm(0) 
00053   {
00054     inputLabel = iConfig.getParameter<edm::InputTag>("src");
00055     inputType  = iConfig.getParameter<std::string>("InputType");
00056     METtype    = iConfig.getParameter<std::string>("METType");
00057     alias      = iConfig.getParameter<std::string>("alias");
00058     globalThreshold = iConfig.getParameter<double>("globalThreshold");
00059     calculateSignificance_ = false ;
00060 
00061     if( METtype == "CaloMET" ) 
00062       {
00063         noHF = iConfig.getParameter<bool>("noHF");
00064         produces<CaloMETCollection>().setBranchAlias(alias.c_str()); 
00065         calculateSignificance_ = iConfig.getParameter<bool>("calculateSignificance");
00066       }
00067     else if( METtype == "GenMET" )  
00068       {
00069         onlyFiducial = iConfig.getParameter<bool>("onlyFiducialParticles");
00070         usePt      = iConfig.getUntrackedParameter<bool>("usePt",false);
00071         produces<GenMETCollection>().setBranchAlias(alias.c_str());
00072       }
00073     else if( METtype == "PFMET" )
00074       {
00075         produces<PFMETCollection>().setBranchAlias(alias.c_str()); 
00076 
00077         calculateSignificance_ = iConfig.getParameter<bool>("calculateSignificance");
00078 
00079         if(calculateSignificance_){
00080             jetsLabel_ = iConfig.getParameter<edm::InputTag>("jets");
00081         }
00082 
00083       }
00084     else if( METtype == "PFClusterMET" )
00085       {
00086         produces<PFClusterMETCollection>().setBranchAlias(alias.c_str()); 
00087       }
00088     else if (METtype == "TCMET" )
00089       {
00090         produces<METCollection>().setBranchAlias(alias.c_str());
00091 
00092         int rfType_               = iConfig.getParameter<int>("rf_type");
00093         bool correctShowerTracks_ = iConfig.getParameter<bool>("correctShowerTracks"); 
00094 
00095         if(correctShowerTracks_){
00096           // use 'shower' and 'noshower' response functions
00097           myResponseFunctionType = 0;
00098         }else{
00099           
00100           if( rfType_ == 1 ){
00101             // use response function 'fit'
00102             myResponseFunctionType = 1;
00103           }
00104           else if( rfType_ == 2 ){
00105             // use response function 'mode'
00106             myResponseFunctionType = 2;
00107           }
00108         }
00109         tcmetalgorithm = new TCMETAlgo();
00110         tcmetalgorithm->configure(iConfig, myResponseFunctionType );
00111       }
00112     else                            
00113       produces<METCollection>().setBranchAlias(alias.c_str()); 
00114 
00115     if (calculateSignificance_ && ( METtype == "CaloMET" || METtype == "PFMET")){
00116         resolutions_ = new metsig::SignAlgoResolutions(iConfig);
00117         
00118     }
00119   }
00120   //--------------------------------------------------------------------------
00121 
00122   //--------------------------------------------------------------------------
00123   // Default Constructor
00124   //-----------------------------------
00125   METProducer::METProducer() : alg_() 
00126   {
00127     tcmetalgorithm = 0; // why does this constructor exist?
00128     produces<METCollection>(); 
00129   }
00130   //--------------------------------------------------------------------------
00131 
00132   //--------------------------------------------------------------------------
00133   // Default Destructor
00134   //-----------------------------------
00135   METProducer::~METProducer() { delete tcmetalgorithm;}
00136   //--------------------------------------------------------------------------
00137 
00138   //--------------------------------------------------------------------------
00139   // Run Algorithm and put results into event
00140   //-----------------------------------
00141   void METProducer::produce(Event& event, const EventSetup& setup) 
00142   {
00143 
00144     //-----------------------------------
00145     // Step A: Get Inputs.  Create an empty collection of candidates
00146     edm::Handle<edm::View<Candidate> > input;
00147     event.getByLabel(inputLabel,input);
00148     //-----------------------------------
00149     // Step B: Create an empty MET struct output.
00150     CommonMETData output;
00151     /*
00152     //-----------------------------------
00153     // Step C: Convert input source to type CandidateCollection
00154     const RefToBaseVector<Candidate> inputCol = inputHandle->refVector();
00155     const CandidateCollection *input = (const CandidateCollection *)inputCol.product();
00156     */
00157     //-----------------------------------
00158     // Step C2: Invoke the MET algorithm, which runs on any CandidateCollection input. 
00159 
00160     //    alg_.run(input, &output, globalThreshold);   // No need to run this for all METTypes!
00161  
00162     //-----------------------------------
00163     // Step D: Invoke the specific "afterburner", which adds information
00164     //         depending on the input type, given via the config parameter.
00165     //         Also, after the specific algorithm has been called, store
00166     //         the output into the Event.
00167 
00168     if( METtype == "CaloMET" ) 
00169     {
00170       //Run Basic MET Algorithm
00171       alg_.run(input, &output, globalThreshold);
00172 
00173       // Run CaloSpecific Algorithm
00174       CaloSpecificAlgo calospecalgo;
00175       CaloMET calomet = calospecalgo.addInfo(input,output,noHF, globalThreshold);
00176 
00177       //Run algorithm to calculate CaloMET Significance and add to the MET Object
00178       if( calculateSignificance_ ) 
00179       {
00180           SignCaloSpecificAlgo signcalospecalgo;
00181           //metsig::SignAlgoResolutions resolutions(conf_);
00182           
00183           signcalospecalgo.calculateBaseCaloMET(input,output,*resolutions_,noHF,globalThreshold);
00184           calomet.SetMetSignificance( signcalospecalgo.getSignificance() );
00185           calomet.setSignificanceMatrix(signcalospecalgo.getSignificanceMatrix());
00186         }
00187       //Store CaloMET object in CaloMET collection 
00188       std::auto_ptr<CaloMETCollection> calometcoll;
00189       calometcoll.reset(new CaloMETCollection);
00190       calometcoll->push_back( calomet ) ;
00191       event.put( calometcoll );  
00192       
00193     }
00194     //-----------------------------------
00195     else if( METtype == "TCMET" )
00196       {
00197         std::auto_ptr<METCollection> tcmetcoll;
00198         tcmetcoll.reset(new METCollection);
00199         tcmetcoll->push_back( tcmetalgorithm->CalculateTCMET(event, setup ) ) ;
00200         event.put( tcmetcoll );
00201       }
00202     //----------------------------------
00203     else if( METtype == "PFMET" )
00204       {
00205         alg_.run(input, &output, globalThreshold);
00206         PFSpecificAlgo pf;
00207         std::auto_ptr<PFMETCollection> pfmetcoll;
00208         pfmetcoll.reset (new PFMETCollection);
00209         
00210         // add resolutions and calculate significance
00211         if( calculateSignificance_ )
00212           {
00213             //metsig::SignAlgoResolutions resolutions(conf_);
00214             edm::Handle<edm::View<reco::PFJet> > jets;
00215             event.getByLabel(jetsLabel_,jets);
00216             pf.runSignificance(*resolutions_, jets);
00217           }
00218         pfmetcoll->push_back( pf.addInfo(input, output) );
00219         event.put( pfmetcoll );
00220       }
00221     //----------------------------------
00222     else if( METtype == "PFClusterMET" )
00223       {
00224         alg_.run(input, &output, globalThreshold);
00225         PFClusterSpecificAlgo pfcluster;
00226         std::auto_ptr<PFClusterMETCollection> pfclustermetcoll;
00227         pfclustermetcoll.reset (new PFClusterMETCollection);
00228         
00229         pfclustermetcoll->push_back( pfcluster.addInfo(input, output) );
00230         event.put( pfclustermetcoll );
00231       }
00232     //-----------------------------------
00233     else if( METtype == "GenMET" ) 
00234     {
00235       GenSpecificAlgo gen;
00236       std::auto_ptr<GenMETCollection> genmetcoll;
00237       genmetcoll.reset (new GenMETCollection);
00238       genmetcoll->push_back( gen.addInfo(input, &output, globalThreshold, onlyFiducial, usePt) );
00239       event.put( genmetcoll );
00240     }
00241     else
00242       {
00243       alg_.run(input, &output, globalThreshold); 
00244       LorentzVector p4( output.mex, output.mey, 0.0, output.met);
00245       Point vtx(0,0,0);
00246       MET met( output.sumet, p4, vtx );
00247       std::auto_ptr<METCollection> metcoll;
00248       metcoll.reset(new METCollection);
00249       metcoll->push_back( met );
00250       event.put( metcoll );
00251     }
00252     //-----------------------------------
00253   }
00254   //--------------------------------------------------------------------------
00255 }