CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/HLTrigger/HLTfilters/src/HLTDoublet.cc

Go to the documentation of this file.
00001 
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "HLTrigger/HLTfilters/interface/HLTDoublet.h"
00014 
00015 #include "DataFormats/Common/interface/Handle.h"
00016 
00017 #include "DataFormats/Common/interface/Ref.h"
00018 #include "DataFormats/HLTReco/interface/TriggerFilterObjectWithRefs.h"
00019 
00020 #include "DataFormats/Candidate/interface/Particle.h"
00021 
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 
00024 #include<cmath>
00025 
00026 //
00027 // constructors and destructor
00028 //
00029 template<typename T1, typename T2>
00030 HLTDoublet<T1,T2>::HLTDoublet(const edm::ParameterSet& iConfig) : HLTFilter(iConfig), 
00031   originTag1_(iConfig.template getParameter<edm::InputTag>("originTag1")),
00032   originTag2_(iConfig.template getParameter<edm::InputTag>("originTag2")),
00033   inputTag1_(iConfig.template getParameter<edm::InputTag>("inputTag1")),
00034   inputTag2_(iConfig.template getParameter<edm::InputTag>("inputTag2")),
00035   triggerType1_(iConfig.template getParameter<int>("triggerType1")),
00036   triggerType2_(iConfig.template getParameter<int>("triggerType2")),
00037   min_Dphi_ (iConfig.template getParameter<double>("MinDphi")),
00038   max_Dphi_ (iConfig.template getParameter<double>("MaxDphi")),
00039   min_Deta_ (iConfig.template getParameter<double>("MinDeta")),
00040   max_Deta_ (iConfig.template getParameter<double>("MaxDeta")),
00041   min_Minv_ (iConfig.template getParameter<double>("MinMinv")),
00042   max_Minv_ (iConfig.template getParameter<double>("MaxMinv")),
00043   min_DelR_ (iConfig.template getParameter<double>("MinDelR")),
00044   max_DelR_ (iConfig.template getParameter<double>("MaxDelR")),
00045   min_Pt_   (iConfig.template getParameter<double>("MinPt")),
00046   max_Pt_   (iConfig.template getParameter<double>("MaxPt")),
00047   min_N_    (iConfig.template getParameter<int>("MinN")),
00048   label_    (iConfig.getParameter<std::string>("@module_label")),
00049   coll1_(),
00050   coll2_()
00051 {
00052 
00053    // same collections to be compared?
00054    same_ = (inputTag1_.encode()==inputTag2_.encode());
00055 
00056    cutdphi_ = (min_Dphi_ <= max_Dphi_); // cut active?
00057    cutdeta_ = (min_Deta_ <= max_Deta_); // cut active?
00058    cutminv_ = (min_Minv_ <= max_Minv_); // cut active?
00059    cutdelr_ = (min_DelR_ <= max_DelR_); // cut active?
00060    cutpt_   = (min_Pt_   <= max_Pt_  ); // cut active?
00061 
00062    LogDebug("") << "InputTags and cuts : " 
00063                 << inputTag1_.encode() << " " << inputTag2_.encode()
00064                 << triggerType1_ << " " << triggerType2_
00065                 << " Dphi [" << min_Dphi_ << " " << max_Dphi_ << "]"
00066                 << " Deta [" << min_Deta_ << " " << max_Deta_ << "]"
00067                 << " Minv [" << min_Minv_ << " " << max_Minv_ << "]"
00068                 << " DelR [" << min_DelR_ << " " << max_DelR_ << "]"
00069                 << " Pt   [" << min_Pt_   << " " << max_Pt_   << "]"
00070                 << " MinN =" << min_N_
00071                 << " same/dphi/deta/minv/delr/pt "
00072                 << same_
00073                 << cutdphi_ << cutdeta_ << cutminv_ << cutdelr_ << cutpt_;
00074 }
00075 
00076 template<typename T1, typename T2>
00077 HLTDoublet<T1,T2>::~HLTDoublet()
00078 {
00079 }
00080 template<typename T1, typename T2>
00081 void
00082 HLTDoublet<T1,T2>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00083   edm::ParameterSetDescription desc;
00084   makeHLTFilterDescription(desc);
00085   desc.add<edm::InputTag>("originTag1",edm::InputTag("hltOriginal1"));
00086   desc.add<edm::InputTag>("originTag2",edm::InputTag("hltOriginal2"));
00087   desc.add<edm::InputTag>("inputTag1",edm::InputTag("hltFiltered1"));
00088   desc.add<edm::InputTag>("inputTag2",edm::InputTag("hltFiltered22"));
00089   desc.add<int>("triggerType1",0);
00090   desc.add<int>("triggerType2",0);
00091   desc.add<double>("MinDphi",+1.0);
00092   desc.add<double>("MaxDphi",-1.0);
00093   desc.add<double>("MinDeta",+1.0);
00094   desc.add<double>("MaxDeta",-1.0);
00095   desc.add<double>("MinMinv",+1.0);
00096   desc.add<double>("MaxMinv",-1.0);
00097   desc.add<double>("MinDelR",+1.0);
00098   desc.add<double>("MaxDelR",-1.0);
00099   desc.add<double>("MinPt"  ,+1.0);
00100   desc.add<double>("MaxPt"  ,-1.0);
00101   desc.add<int>("MinN",1);
00102   descriptions.add(std::string("hlt")+std::string(typeid(HLTDoublet<T1,T2>).name()),desc);
00103 }
00104 
00105 //
00106 // member functions
00107 //
00108 
00109 // ------------ method called to produce the data  ------------
00110 template<typename T1, typename T2>
00111 bool
00112 HLTDoublet<T1,T2>::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs & filterproduct)
00113 {
00114    using namespace std;
00115    using namespace edm;
00116    using namespace reco;
00117    using namespace trigger;
00118 
00119    // All HLT filters must create and fill an HLT filter object,
00120    // recording any reconstructed physics objects satisfying (or not)
00121    // this HLT filter, and place it in the Event.
00122 
00123    bool accept(false);
00124 
00125    LogVerbatim("HLTDoublet") << " XXX " << label_ << " 0 " << std::endl;
00126 
00127    // get hold of pre-filtered object collections
00128    Handle<TriggerFilterObjectWithRefs> coll1,coll2;
00129    if (iEvent.getByLabel (inputTag1_,coll1) && iEvent.getByLabel (inputTag2_,coll2)) {
00130      coll1_.clear();
00131      coll1->getObjects(triggerType1_,coll1_);
00132      const size_type n1(coll1_.size());
00133      coll2_.clear();
00134      coll2->getObjects(triggerType2_,coll2_);
00135      const size_type n2(coll2_.size());
00136 
00137      if (saveTags()) {
00138        InputTag tagOld;
00139        filterproduct.addCollectionTag(originTag1_);
00140        LogVerbatim("HLTDoublet") << " XXX " << label_ << " 1a " << originTag1_.encode() << std::endl;
00141        tagOld=InputTag();
00142        for (size_type i1=0; i1!=n1; ++i1) {
00143          const ProductID pid(coll1_[i1].id());
00144          const string&    label(iEvent.getProvenance(pid).moduleLabel());
00145          const string& instance(iEvent.getProvenance(pid).productInstanceName());
00146          const string&  process(iEvent.getProvenance(pid).processName());
00147          InputTag tagNew(InputTag(label,instance,process));
00148          if (tagOld.encode()!=tagNew.encode()) {
00149            filterproduct.addCollectionTag(tagNew);
00150            tagOld=tagNew;
00151            LogVerbatim("HLTDoublet") << " XXX " << label_ << " 1b " << tagNew.encode() << std::endl;
00152          }
00153        }
00154        filterproduct.addCollectionTag(originTag2_);
00155        LogVerbatim("HLTDoublet") << " XXX " << label_ << " 2a " << originTag2_.encode() << std::endl;
00156        tagOld=InputTag();
00157        for (size_type i2=0; i2!=n2; ++i2) {
00158          const ProductID pid(coll2_[i2].id());
00159          const string&    label(iEvent.getProvenance(pid).moduleLabel());
00160          const string& instance(iEvent.getProvenance(pid).productInstanceName());
00161          const string&  process(iEvent.getProvenance(pid).processName());
00162          InputTag tagNew(InputTag(label,instance,process));
00163          if (tagOld.encode()!=tagNew.encode()) {
00164            filterproduct.addCollectionTag(tagNew);
00165            tagOld=tagNew;
00166            LogVerbatim("HLTDoublet") << " XXX " << label_ << " 2b " << tagNew.encode() << std::endl;
00167          }
00168        }
00169      }
00170 
00171      int n(0);
00172      T1Ref r1;
00173      T2Ref r2;
00174      Particle::LorentzVector p1,p2,p;
00175      for (unsigned int i1=0; i1!=n1; i1++) {
00176        r1=coll1_[i1];
00177        p1=r1->p4();
00178        unsigned int I(0);
00179        if (same_) {I=i1+1;}
00180        for (unsigned int i2=I; i2!=n2; i2++) {
00181          r2=coll2_[i2];
00182          p2=r2->p4();
00183 
00184          double Dphi(std::abs(p1.phi()-p2.phi()));
00185          if (Dphi>M_PI) Dphi=2.0*M_PI-Dphi;
00186          
00187          double Deta(std::abs(p1.eta()-p2.eta()));
00188          
00189          p=p1+p2;
00190          double Minv(std::abs(p.mass()));
00191          double Pt(p.pt());
00192 
00193          double DelR(sqrt(Dphi*Dphi+Deta*Deta));
00194          
00195          if ( ( (!cutdphi_) || ((min_Dphi_<=Dphi) && (Dphi<=max_Dphi_)) ) &&
00196               ( (!cutdeta_) || ((min_Deta_<=Deta) && (Deta<=max_Deta_)) ) &&
00197               ( (!cutminv_) || ((min_Minv_<=Minv) && (Minv<=max_Minv_)) ) &&
00198               ( (!cutdelr_) || ((min_DelR_<=DelR) && (DelR<=max_DelR_)) ) &&
00199               ( (!cutpt_  ) || ((min_Pt_  <=Pt  ) && (Pt  <=max_Pt_  )) ) ) {
00200            n++;
00201            filterproduct.addObject(triggerType1_,r1);
00202            filterproduct.addObject(triggerType2_,r2);
00203          }
00204          
00205        }
00206      }
00207      // filter decision
00208      accept = (n>=min_N_);
00209    }
00210 
00211    return accept;
00212 }