CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/TopQuarkAnalysis/TopEventProducers/src/StEvtSolutionMaker.cc

Go to the documentation of this file.
00001 //
00002 // $Id: StEvtSolutionMaker.cc,v 1.9 2008/02/17 11:09:40 rwolf Exp $
00003 //
00004 
00005 #include <memory>
00006 
00007 #include "TopQuarkAnalysis/TopEventProducers/interface/StEvtSolutionMaker.h"
00008 
00009 StEvtSolutionMaker::StEvtSolutionMaker(const edm::ParameterSet& iConfig) 
00010 {
00011   // configurables
00012   electronSrc_    = iConfig.getParameter<edm::InputTag>("electronSource");
00013   muonSrc_        = iConfig.getParameter<edm::InputTag>("muonSource");
00014   metSrc_         = iConfig.getParameter<edm::InputTag>("metSource");
00015   jetSrc_         = iConfig.getParameter<edm::InputTag>("jetSource");
00016   leptonFlavour_  = iConfig.getParameter< std::string >("leptonFlavour");
00017   jetCorrScheme_  = iConfig.getParameter<int>          ("jetCorrectionScheme");
00018   //jetInput_        = iConfig.getParameter< std::string >        ("jetInput");
00019   doKinFit_       = iConfig.getParameter< bool >       ("doKinFit");
00020   addLRJetComb_   = iConfig.getParameter< bool >       ("addLRJetComb");
00021   maxNrIter_      = iConfig.getParameter< int >        ("maxNrIter");
00022   maxDeltaS_      = iConfig.getParameter< double >     ("maxDeltaS");
00023   maxF_           = iConfig.getParameter< double >     ("maxF");
00024   jetParam_       = iConfig.getParameter<int>          ("jetParametrisation");
00025   lepParam_       = iConfig.getParameter<int>          ("lepParametrisation");
00026   metParam_       = iConfig.getParameter<int>          ("metParametrisation");
00027   constraints_    = iConfig.getParameter< std::vector<int> > ("constraints");
00028   matchToGenEvt_  = iConfig.getParameter< bool >        ("matchToGenEvt");
00029   
00030   // define kinfitter
00031   if(doKinFit_){
00032     myKinFitter = new StKinFitter(jetParam_, lepParam_, metParam_, maxNrIter_, maxDeltaS_, maxF_, constraints_);
00033   }
00034   // define what will be produced
00035   produces<std::vector<StEvtSolution> >();
00036 }
00037 
00038 StEvtSolutionMaker::~StEvtSolutionMaker() 
00039 {
00040   if (doKinFit_) delete myKinFitter;
00041 }
00042 
00043 void StEvtSolutionMaker::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00044 {
00045   //
00046   //  TopObject Selection
00047   //
00048   
00049   // select lepton (the TtLepton vectors are, for the moment, sorted on pT)
00050   bool leptonFound = false;
00051   edm::Handle<std::vector<pat::Muon> > muons;
00052   if(leptonFlavour_ == "muon"){
00053     iEvent.getByLabel(muonSrc_, muons);
00054     if( muons->size() > 0 ) leptonFound = true;
00055   }
00056   edm::Handle<std::vector<pat::Electron> > electrons;
00057   if(leptonFlavour_ == "electron"){
00058     iEvent.getByLabel(electronSrc_, electrons);
00059     if( electrons->size() > 0 ) leptonFound = true;
00060   }
00061   
00062   // select MET (TopMET vector is sorted on ET)
00063   bool metFound = false;
00064   edm::Handle<std::vector<pat::MET> > mets;
00065   iEvent.getByLabel(metSrc_, mets);
00066   if( mets->size() > 0 ) metFound = true;
00067   
00068   // select Jets
00069   bool jetsFound = false;
00070   edm::Handle<std::vector<pat::Jet> > jets;
00071   iEvent.getByLabel(jetSrc_, jets);
00072   unsigned int maxJets=2;//this has to become a custom-defined parameter (we may want 2 or 3 jets)
00073   if (jets->size() >= 2) jetsFound = true;
00074   
00075   std::vector<StEvtSolution> *evtsols = new std::vector<StEvtSolution>();
00076   if(leptonFound && metFound && jetsFound){
00077     std::cout<<"constructing solutions"<<std::endl;
00078     for (unsigned int b=0; b<maxJets; b++) {
00079       for (unsigned int l=0; l<maxJets; l++) {
00080         if(b!=l){  // to avoid double counting
00081           StEvtSolution asol;
00082           asol.setJetCorrectionScheme(jetCorrScheme_);
00083           if(leptonFlavour_ == "muon")     asol.setMuon(muons, 0);
00084           if(leptonFlavour_ == "electron") asol.setElectron(electrons, 0);
00085           asol.setNeutrino(mets, 0);
00086           asol.setBottom(jets, b);
00087           asol.setLight(jets, l);
00088           
00089           if(doKinFit_) asol = myKinFitter->addKinFitInfo(&asol);
00090           
00091           /* to be adapted to ST (Andrea)
00092              if(addLRJetComb_){
00093              asol.setPtrueCombExist(jetCombProbs[m].getPTrueCombExist(&afitsol));
00094              asol.setPtrueBJetSel(jetCombProbs[m].getPTrueBJetSel(&afitsol));
00095              asol.setPtrueBhadrSel(jetCombProbs[m].getPTrueBhadrSel(&afitsol));
00096              asol.setPtrueJetComb(afitsol.getPtrueCombExist()*afitsol.getPtrueBJetSel()*afitsol.getPtrueBhadrSel());
00097              }
00098           */
00099           evtsols->push_back(asol);
00100         }
00101       }
00102     }
00103     
00104     // if asked for, match the event solutions to the gen Event
00105     if(matchToGenEvt_){
00106       /*
00107         edm::Handle<StGenEvent> genEvt;
00108         iEvent.getByLabel ("genEvt",genEvt);
00109         double bestSolDR = 9999.;
00110         int bestSol = 0;
00111         for(size_t s=0; s<evtsols->size(); s++) {
00112         (*evtsols)[s].setGenEvt(genEvt->particles());
00113         vector<double> bm = BestMatch((*evtsols)[s], false); //false to use DR, true SpaceAngles
00114         (*evtsols)[s].setSumDeltaRjp(bm[0]); // dRBB + dRLL
00115         (*evtsols)[s].setChangeBL((int) bm[1]); // has swapped or not
00116         (*evtsols)[s].setDeltaRB(bm[2]);
00117         (*evtsols)[s].setDeltaRL(bm[3]);
00118         if(bm[0]<bestSolDR) { bestSolDR =  bm[0]; bestSol = s; }
00119         }
00120         (*evtsols)[bestSol].setBestSol(true);
00121       */
00122     }
00123     
00124     //store the vector of solutions to the event     
00125     std::auto_ptr<std::vector<StEvtSolution> > pOut(evtsols);
00126     iEvent.put(pOut);
00127   }
00128   else
00129     {
00130       
00131       std::cout<<"@@@ No calibrated solutions built, because:  " << std::endl;;
00132       if(jets->size()<maxJets)                                    std::cout<<"@ nr jets = " << jets->size() << " < " << maxJets <<std::endl;
00133       if(leptonFlavour_ == "muon" && !leptonFound)                std::cout<<"@ no good muon candidate"<<std::endl;
00134       if(leptonFlavour_ == "electron" && !leptonFound)             std::cout<<"@ no good electron candidate"<<std::endl;
00135       if(mets->size() == 0)                                       std::cout<<"@ no MET reconstruction"<<std::endl;
00136       
00137       StEvtSolution asol;
00138       evtsols->push_back(asol);
00139       std::auto_ptr<std::vector<StEvtSolution> > pOut(evtsols);
00140       iEvent.put(pOut);
00141     }
00142 }