CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTrigger/JetMET/src/HLTRFilter.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00002 #include "HLTrigger/JetMET/interface/HLTRFilter.h"
00003 
00004 #include "DataFormats/Common/interface/Handle.h"
00005 
00006 #include "DataFormats/Common/interface/Ref.h"
00007 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00008 #include "DataFormats/HLTReco/interface/TriggerTypeDefs.h"
00009 
00010 #include "DataFormats/JetReco/interface/CaloJet.h"
00011 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
00012 
00013 #include "DataFormats/METReco/interface/CaloMET.h"
00014 #include "DataFormats/METReco/interface/CaloMETCollection.h"
00015 
00016 
00017 #include "FWCore/Framework/interface/MakerMacros.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 
00020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00022 #include "FWCore/Utilities/interface/InputTag.h"
00023 
00024 #include "TVector3.h"
00025 #include "TLorentzVector.h"
00026 //
00027 // constructors and destructor
00028 //
00029 HLTRFilter::HLTRFilter(const edm::ParameterSet& iConfig) :
00030   inputTag_    (iConfig.getParameter<edm::InputTag>("inputTag")),
00031   inputMetTag_ (iConfig.getParameter<edm::InputTag>("inputMetTag")),
00032   min_R_       (iConfig.getParameter<double>       ("minR"   )),
00033   min_MR_      (iConfig.getParameter<double>       ("minMR"   )),
00034   DoRPrime_    (iConfig.getParameter<bool>       ("doRPrime"   )),
00035   accept_NJ_    (iConfig.getParameter<bool>       ("acceptNJ"   ))
00036 
00037 {
00038    LogDebug("") << "Inputs/minR/minMR/doRPrime/acceptNJ : "
00039                 << inputTag_.encode() << " "
00040                 << inputMetTag_.encode() << " "
00041                 << min_R_ << " "
00042                 << min_MR_ << " "
00043                 << DoRPrime_ << " "
00044                 << accept_NJ_ << ".";
00045 
00046    //register your products
00047    produces<trigger::TriggerFilterObjectWithRefs>();
00048 }
00049 
00050 HLTRFilter::~HLTRFilter()
00051 {
00052 }
00053 
00054 void
00055 HLTRFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00056   edm::ParameterSetDescription desc;
00057   desc.add<edm::InputTag>("inputTag",edm::InputTag("hltRHemisphere"));
00058   desc.add<edm::InputTag>("inputMetTag",edm::InputTag("hltMet"));
00059   desc.add<double>("minR",0.3);
00060   desc.add<double>("minMR",100.0);
00061   desc.add<bool>("doRPrime",false);
00062   desc.add<bool>("acceptNJ",true);
00063   descriptions.add("hltRFilter",desc);
00064 }
00065 
00066 //
00067 // member functions
00068 //
00069 
00070 // ------------ method called to produce the data  ------------
00071 bool 
00072 HLTRFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
00073 {
00074    using namespace std;
00075    using namespace edm;
00076    using namespace reco;
00077    using namespace trigger;
00078 
00079    // The filter object
00080    auto_ptr<TriggerFilterObjectWithRefs>
00081      filterobject (new TriggerFilterObjectWithRefs(path(),module()));
00082 
00083    // get hold of collection of objects
00084    Handle< vector<math::XYZTLorentzVector> > hemispheres;
00085    iEvent.getByLabel (inputTag_,hemispheres);
00086 
00087    // get hold of the MET Collection
00088    Handle<CaloMETCollection> inputMet;
00089    iEvent.getByLabel(inputMetTag_,inputMet);  
00090 
00091    iEvent.put(filterobject);
00092 
00093    // check the the input collections are available
00094    if (not hemispheres.isValid() or not inputMet.isValid())
00095      return false;
00096 
00097    if(hemispheres->size() ==0){  // the Hemisphere Maker will produce an empty collection of hemispheres if the number of jets in the
00098      return accept_NJ_;   // event is greater than the maximum number of jets
00099    }
00100 
00101    //***********************************
00102    //Calculate R or R prime
00103 
00104    TLorentzVector j1R(hemispheres->at(0).x(),hemispheres->at(0).y(),hemispheres->at(0).z(),hemispheres->at(0).t());
00105    TLorentzVector j2R(hemispheres->at(1).x(),hemispheres->at(1).y(),hemispheres->at(1).z(),hemispheres->at(1).t());
00106    TLorentzVector j1Rp(hemispheres->at(2).x(),hemispheres->at(2).y(),hemispheres->at(2).z(),hemispheres->at(2).t());
00107    TLorentzVector j2Rp(hemispheres->at(3).x(),hemispheres->at(3).y(),hemispheres->at(3).z(),hemispheres->at(3).t());
00108 
00109    if(j1R.Pt() > 0.1) { // some good R combination was found
00110 
00111      j1R.SetPtEtaPhiM(j1R.Pt(),j1R.Eta(),j1R.Phi(),0.0);
00112      j2R.SetPtEtaPhiM(j2R.Pt(),j2R.Eta(),j2R.Phi(),0.0);
00113   
00114      if(j2R.Pt() > j1R.Pt()){
00115        TLorentzVector temp = j1R;
00116        j1R = j2R;
00117        j2R = temp;
00118      }
00119   
00120      double num = j1R.P()-j2R.P();
00121      double den = j1R.Pz()-j2R.Pz();
00122      if(fabs(num)<fabs(den)) {
00123 
00124        //now we can calculate MTR
00125        TVector3 met;
00126        met.SetPtEtaPhi((inputMet->front()).pt(),0.0,(inputMet->front()).phi());
00127        double MTR = sqrt(0.5*(met.Mag()*(j1R.Pt()+j2R.Pt()) - met.Dot(j1R.Vect()+j2R.Vect())));
00128 
00129        //calculate MR
00130        double MR=0;
00131        double temp = (j1R.P()*j2R.Pz()-j2R.P()*j1R.Pz())*(j1R.P()*j2R.Pz()-j2R.P()*j1R.Pz());
00132        temp /= (j1R.Pz()-j2R.Pz())*(j1R.Pz()-j2R.Pz())-(j1R.P()-j2R.P())*(j1R.P()-j2R.P());    
00133        MR = 2.*sqrt(temp);
00134        if(MR>=min_MR_ && float(MTR)/float(MR)>=min_R_) return true;
00135      }
00136    }
00137 
00138    if(j1Rp.Pt() > 0.1) { // some good R' combination was found  
00139      
00140      j1Rp.SetPtEtaPhiM(j1Rp.Pt(),j1Rp.Eta(),j1Rp.Phi(),0.0);
00141      j2Rp.SetPtEtaPhiM(j2Rp.Pt(),j2Rp.Eta(),j2Rp.Phi(),0.0);
00142 
00143      if(j2Rp.Pt() > j1Rp.Pt()){
00144        TLorentzVector temp = j1Rp;
00145        j1Rp = j2Rp;
00146        j2Rp = temp;
00147      }
00148 
00149      double num = j1Rp.P()-j2Rp.P();
00150      double den = j1Rp.Pz()-j2Rp.Pz();
00151      if(fabs(num)>fabs(den)) {
00152        //now we can calculate MTR
00153 
00154        TVector3 met;
00155        met.SetPtEtaPhi((inputMet->front()).pt(),0.0,(inputMet->front()).phi());
00156        double MTR = sqrt(0.5*(met.Mag()*(j1Rp.Pt()+j2Rp.Pt()) - met.Dot(j1Rp.Vect()+j2Rp.Vect())));
00157 
00158        double jaP = j1Rp.Pt()*j1Rp.Pt() +j1Rp.Pz()*j2Rp.Pz()-j1Rp.P()*j2Rp.P();
00159        double jbP = j2Rp.Pt()*j2Rp.Pt() +j1Rp.Pz()*j2Rp.Pz()-j1Rp.P()*j2Rp.P();
00160        jbP *= -1.;
00161        double den = sqrt((j1Rp.P()-j2Rp.P())*(j1Rp.P()-j2Rp.P())-(j1Rp.Pz()-j2Rp.Pz())*(j1Rp.Pz()-j2Rp.Pz()));
00162        
00163        jaP /= den;
00164        jbP /= den;
00165     
00166        double temp = jaP*met.Dot(j2Rp.Vect())/met.Mag() + jbP*met.Dot(j1Rp.Vect())/met.Mag();
00167        temp = temp*temp;
00168     
00169        den = (met.Dot(j1Rp.Vect()+j2Rp.Vect())/met.Mag())*(met.Dot(j1Rp.Vect()+j2Rp.Vect())/met.Mag())-(jaP-jbP)*(jaP-jbP);
00170     
00171        if(den <= 0.0) return false;
00172        
00173        temp /= den;
00174        temp = 2.*sqrt(temp);
00175        
00176        double bR = (jaP-jbP)/(met.Dot(j1Rp.Vect()+j2Rp.Vect())/met.Mag());
00177        double gR = 1./sqrt(1.-bR*bR);
00178     
00179        temp *= gR;
00180 
00181        double MRp = temp;
00182 
00183        if(MRp>=min_MR_ && float(MTR)/float(MRp)>=min_R_) return true;
00184      }
00185    }
00186 
00187    // filter decision
00188    return false;
00189 }
00190 
00191 DEFINE_FWK_MODULE(HLTRFilter);
00192