CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/HLTrigger/HLTfilters/src/HLTDoubletDZ.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00002 #include "HLTrigger/HLTfilters/interface/HLTDoubletDZ.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 
00009 #include "DataFormats/Candidate/interface/Particle.h"
00010 
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 
00013 #include "DataFormats/Math/interface/deltaR.h"
00014 
00015 #include<cmath>
00016 
00017 //
00018 // constructors and destructor
00019 //
00020 template<typename T1, typename T2>
00021 HLTDoubletDZ<T1,T2>::HLTDoubletDZ(const edm::ParameterSet& iConfig) : HLTFilter(iConfig),
00022   originTag1_(iConfig.template getParameter<edm::InputTag>("originTag1")),
00023   originTag2_(iConfig.template getParameter<edm::InputTag>("originTag2")),
00024   inputTag1_(iConfig.template getParameter<edm::InputTag>("inputTag1")),
00025   inputTag2_(iConfig.template getParameter<edm::InputTag>("inputTag2")),
00026   triggerType1_(iConfig.template getParameter<int>("triggerType1")),
00027   triggerType2_(iConfig.template getParameter<int>("triggerType2")),
00028   minDR_ (iConfig.template getParameter<double>("MinDR")),
00029   maxDZ_ (iConfig.template getParameter<double>("MaxDZ")),
00030   min_N_    (iConfig.template getParameter<int>("MinN")),
00031   label_    (iConfig.getParameter<std::string>("@module_label")),
00032   coll1_(),
00033   coll2_()
00034 {
00035    // same collections to be compared?
00036    same_ = (inputTag1_.encode()==inputTag2_.encode());
00037 }
00038 
00039 template<typename T1, typename T2>
00040 HLTDoubletDZ<T1,T2>::~HLTDoubletDZ()
00041 {
00042 }
00043 
00044 template<typename T1, typename T2>
00045 void
00046 HLTDoubletDZ<T1,T2>::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00047   edm::ParameterSetDescription desc;
00048   makeHLTFilterDescription(desc);
00049   desc.add<edm::InputTag>("originTag1",edm::InputTag("hltOriginal1"));
00050   desc.add<edm::InputTag>("originTag2",edm::InputTag("hltOriginal2"));
00051   desc.add<edm::InputTag>("inputTag1",edm::InputTag("hltFiltered1"));
00052   desc.add<edm::InputTag>("inputTag2",edm::InputTag("hltFiltered2"));
00053   desc.add<int>("triggerType1",0);
00054   desc.add<int>("triggerType2",0);
00055   desc.add<double>("MinDR",-1.0);
00056   desc.add<double>("MaxDZ",0.2);
00057   desc.add<int>("MinN",1);
00058   descriptions.add(std::string("hlt")+std::string(typeid(HLTDoubletDZ<T1,T2>).name()),desc);
00059 }
00060 
00061 // ------------ method called to produce the data  ------------
00062 template<typename T1, typename T2>
00063 bool
00064 HLTDoubletDZ<T1,T2>::hltFilter(edm::Event& iEvent, const edm::EventSetup& iSetup, trigger::TriggerFilterObjectWithRefs & filterproduct)
00065 {
00066    using namespace std;
00067    using namespace edm;
00068    using namespace reco;
00069    using namespace trigger;
00070 
00071    // All HLT filters must create and fill an HLT filter object,
00072    // recording any reconstructed physics objects satisfying (or not)
00073    // this HLT filter, and place it in the Event.
00074 
00075    bool accept(false);
00076 
00077    LogVerbatim("HLTDoubletDZ") << " XXX " << label_ << " 0 " << std::endl;
00078 
00079    // get hold of pre-filtered object collections
00080    Handle<TriggerFilterObjectWithRefs> coll1,coll2;
00081    if (iEvent.getByLabel (inputTag1_,coll1) && iEvent.getByLabel (inputTag2_,coll2)) {
00082      coll1_.clear();
00083      coll1->getObjects(triggerType1_,coll1_);
00084      const size_type n1(coll1_.size());
00085      coll2_.clear();
00086      coll2->getObjects(triggerType2_,coll2_);
00087      const size_type n2(coll2_.size());
00088 
00089      if (saveTags()) {
00090        InputTag tagOld;
00091        filterproduct.addCollectionTag(originTag1_);
00092        LogVerbatim("HLTDoubletDZ") << " XXX " << label_ << " 1a " << originTag1_.encode() << std::endl;
00093        tagOld=InputTag();
00094        for (size_type i1=0; i1!=n1; ++i1) {
00095          const ProductID pid(coll1_[i1].id());
00096          const string&    label(iEvent.getProvenance(pid).moduleLabel());
00097          const string& instance(iEvent.getProvenance(pid).productInstanceName());
00098          const string&  process(iEvent.getProvenance(pid).processName());
00099          InputTag tagNew(InputTag(label,instance,process));
00100          if (tagOld.encode()!=tagNew.encode()) {
00101            filterproduct.addCollectionTag(tagNew);
00102            tagOld=tagNew;
00103            LogVerbatim("HLTDoubletDZ") << " XXX " << label_ << " 1b " << tagNew.encode() << std::endl;
00104          }
00105        }
00106        filterproduct.addCollectionTag(originTag1_);
00107        LogVerbatim("HLTDoubletDZ") << " XXX " << label_ << " 2a " << originTag2_.encode() << std::endl;
00108        tagOld=InputTag();
00109        for (size_type i2=0; i2!=n2; ++i2) {
00110          const ProductID pid(coll2_[i2].id());
00111          const string&    label(iEvent.getProvenance(pid).moduleLabel());
00112          const string& instance(iEvent.getProvenance(pid).productInstanceName());
00113          const string&  process(iEvent.getProvenance(pid).processName());
00114          InputTag tagNew(InputTag(label,instance,process));
00115          if (tagOld.encode()!=tagNew.encode()) {
00116            filterproduct.addCollectionTag(tagNew);
00117            tagOld=tagNew;
00118            LogVerbatim("HLTDoubletDZ") << " XXX " << label_ << " 2b " << tagNew.encode() << std::endl;
00119          }
00120        }
00121      }
00122 
00123      int n(0);
00124      T1Ref r1;
00125      T2Ref r2;
00126      Particle::LorentzVector p1,p2,p;
00127      for (unsigned int i1=0; i1!=n1; i1++) {
00128        r1=coll1_[i1];
00129        const reco::Candidate& candidate1(*r1);
00130        unsigned int I(0);
00131        if (same_) {I=i1+1;}
00132        for (unsigned int i2=I; i2!=n2; i2++) {
00133          r2=coll2_[i2];
00134          if (r1->superCluster().isNonnull() && r2->superCluster().isNonnull()) {
00135            if (r1->superCluster() == r2->superCluster()) continue;
00136          }
00137          const reco::Candidate& candidate2(*r2);
00138          if ( reco::deltaR(candidate1, candidate2) < minDR_ ) continue;
00139          if ( std::abs(candidate1.vz()-candidate2.vz()) > maxDZ_ ) continue;
00140          n++;
00141          filterproduct.addObject(triggerType1_,r1);
00142          filterproduct.addObject(triggerType2_,r2);
00143        }
00144      }
00145      // filter decision
00146      accept = accept || (n>=min_N_);
00147    }
00148 
00149    return accept;
00150 }