CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/HLTrigger/JetMET/src/HLTRHemisphere.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00002 #include "HLTrigger/JetMET/interface/HLTRHemisphere.h"
00003 
00004 #include "DataFormats/Common/interface/Handle.h"
00005 
00006 #include "DataFormats/Common/interface/Ref.h"
00007 
00008 #include "DataFormats/JetReco/interface/CaloJet.h"
00009 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00010 
00011 #include "DataFormats/METReco/interface/CaloMET.h"
00012 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00013 
00014 
00015 #include "FWCore/Framework/interface/MakerMacros.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 #include "TVector3.h"
00019 #include "TLorentzVector.h"
00020 
00021 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 
00025 #include<vector>
00026 
00027 //
00028 // constructors and destructor
00029 //
00030 HLTRHemisphere::HLTRHemisphere(const edm::ParameterSet& iConfig) :
00031   inputTag_    (iConfig.getParameter<edm::InputTag>("inputTag")),
00032   min_Jet_Pt_  (iConfig.getParameter<double>       ("minJetPt" )),
00033   max_Eta_     (iConfig.getParameter<double>       ("maxEta" )),
00034   max_NJ_      (iConfig.getParameter<int>          ("maxNJ" )),
00035   accNJJets_   (iConfig.getParameter<bool>         ("acceptNJ" ))
00036 {
00037    LogDebug("") << "Input/minJetPt/maxEta/maxNJ/acceptNJ : "
00038                 << inputTag_.encode() << " "
00039                 << min_Jet_Pt_ << "/"
00040                 << max_Eta_ << "/"
00041                 << max_NJ_ << "/"
00042                 << accNJJets_ << ".";
00043 
00044    //register your products
00045    produces<std::vector<math::XYZTLorentzVector> >();
00046 }
00047 
00048 HLTRHemisphere::~HLTRHemisphere()
00049 {
00050 }
00051 
00052 void
00053 HLTRHemisphere::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00054   edm::ParameterSetDescription desc;
00055   desc.add<edm::InputTag>("inputTag",edm::InputTag("hltMCJetCorJetIcone5HF07"));
00056   desc.add<double>("minJetPt",30.0);
00057   desc.add<double>("maxEta",3.0);
00058   desc.add<int>("maxNJ",7);
00059   desc.add<bool>("acceptNJ",true);
00060   descriptions.add("hltRHemisphere",desc);
00061 }
00062 
00063 //
00064 // member functions
00065 //
00066 
00067 // ------------ method called to produce the data  ------------
00068 bool 
00069 HLTRHemisphere::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00070 {
00071    using namespace std;
00072    using namespace edm;
00073    using namespace reco;
00074    using namespace math;
00075 
00076    // get hold of collection of objects
00077    Handle<CaloJetCollection> jets;
00078    iEvent.getByLabel (inputTag_,jets);
00079 
00080    // The output Collection
00081    std::auto_ptr<vector<math::XYZTLorentzVector> > Hemispheres(new vector<math::XYZTLorentzVector> );
00082 
00083    // look at all objects, check cuts and add to filter object
00084    int n(0);
00085    reco::CaloJetCollection JETS;
00086    CaloJetCollection::const_iterator i ( jets->begin() );
00087    for (unsigned int i=0; i<jets->size(); i++) {
00088      if(fabs(jets->at(i).eta()) < max_Eta_ && jets->at(i).pt() >= min_Jet_Pt_){
00089        JETS.push_back(jets->at(i));
00090        n++;
00091      }
00092    }
00093 
00094   if(n<2){
00095     return false; //need at least 2 jets to build the hemispheres
00096   }
00097 
00098   if(n>max_NJ_ && max_NJ_!=-1){
00099     iEvent.put(Hemispheres);
00100     return accNJJets_; // 
00101   }
00102   unsigned int N_comb(1); // compute the number of combinations of jets possible
00103   for(unsigned int i = 0; i < JETS.size(); i++){
00104     N_comb *= 2;                
00105   }
00106   //Make the hemispheres
00107   XYZTLorentzVector j1R(0.1, 0., 0., 0.1);
00108   XYZTLorentzVector j2R(0.1, 0., 0., 0.1);
00109   double M_minR = 9999999999.0;
00110   unsigned int j_count;
00111   for (unsigned int i = 0; i < N_comb; i++) {       
00112     XYZTLorentzVector j_temp1, j_temp2;
00113     unsigned int itemp = i;
00114     j_count = N_comb/2;
00115     int count = 0;
00116     while (j_count > 0) {
00117       if (itemp/j_count == 1){
00118         j_temp1 += JETS.at(count).p4();
00119       } else {
00120         j_temp2 += JETS.at(count).p4();
00121       }
00122       itemp -= j_count * (itemp/j_count);
00123       j_count /= 2;
00124       count++;
00125     }
00126     double M_temp = j_temp1.M2() + j_temp2.M2();
00127     if (M_temp < M_minR) {
00128       M_minR = M_temp;
00129       j1R = j_temp1; 
00130       j2R = j_temp2; 
00131     }
00132   }
00133 
00134   Hemispheres->push_back(j1R);
00135   Hemispheres->push_back(j2R);
00136 
00137   iEvent.put(Hemispheres);
00138   return true;
00139 }
00140 
00141 DEFINE_FWK_MODULE(HLTRHemisphere);