CMS 3D CMS Logo

Public Member Functions | Private Attributes

ObjectViewMatcher< T1, T2 > Class Template Reference

Inheritance diagram for ObjectViewMatcher< T1, T2 >:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

void endJob ()
 ObjectViewMatcher (const edm::ParameterSet &iConfig)
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
virtual ~ObjectViewMatcher ()

Private Attributes

double deltaRMax_
std::string moduleLabel_
unsigned int nObjectsMatch_
unsigned int nObjectsTot_
StringCutObjectSelector< T1, true > objCut_
StringCutObjectSelector< T2, true > objMatchCut_
edm::InputTag srcCands_
std::vector< edm::InputTagsrcObjects_

Detailed Description

template<typename T1, typename T2>
class ObjectViewMatcher< T1, T2 >

Definition at line 51 of file ObjectViewMatcher.cc.


Constructor & Destructor Documentation

template<typename T1 , typename T2 >
ObjectViewMatcher< T1, T2 >::ObjectViewMatcher ( const edm::ParameterSet iConfig)

Definition at line 86 of file ObjectViewMatcher.cc.

  : srcCands_    (iConfig.getParameter<edm::InputTag>         ("srcObject"))
  , srcObjects_ (iConfig.getParameter<std::vector<edm::InputTag> >("srcObjectsToMatch"))
  , deltaRMax_  (iConfig.getParameter<double>                ("deltaRMax"))
  , moduleLabel_(iConfig.getParameter<std::string>                ("@module_label"))
  , objCut_(iConfig.existsAs<std::string>("srcObjectSelection") ? iConfig.getParameter<std::string>("srcObjectSelection") : "", true)
  ,objMatchCut_(iConfig.existsAs<std::string>("srcObjectsToMatchSelection") ? iConfig.getParameter<std::string>("srcObjectsToMatchSelection") : "", true)
  , nObjectsTot_(0)
  , nObjectsMatch_(0)
{
  produces<std::vector<T1> >();
}
template<typename T1 , typename T2 >
ObjectViewMatcher< T1, T2 >::~ObjectViewMatcher ( ) [virtual]

Definition at line 102 of file ObjectViewMatcher.cc.

{}

Member Function Documentation

template<typename T1 , typename T2 >
void ObjectViewMatcher< T1, T2 >::endJob ( void  ) [virtual]

Reimplemented from edm::EDProducer.

Definition at line 160 of file ObjectViewMatcher.cc.

References gather_cfg::cout.

{
  std::stringstream ss;
  ss<<"nObjectsTot="<<nObjectsTot_<<" nObjectsMatched="<<nObjectsMatch_
    <<" fObjectsMatch="<<100.*(nObjectsMatch_/(double)nObjectsTot_)<<"%\n";
  std::cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++"
           <<"\n"<<moduleLabel_<<"(ObjectViewMatcher) SUMMARY:\n"<<ss.str()
           <<"++++++++++++++++++++++++++++++++++++++++++++++++++"
           << std::endl;
}
template<typename T1 , typename T2 >
void ObjectViewMatcher< T1, T2 >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [virtual]

Implements edm::EDProducer.

Definition at line 112 of file ObjectViewMatcher.cc.

References reco::deltaR(), deltaR(), edm::Event::getByLabel(), VarParsing::obj, and edm::Event::put().

{
  std::auto_ptr<std::vector<T1> > cleanObjects(new std::vector<T1 >);

  edm::Handle<edm::View<T1> > candidates;
  iEvent.getByLabel(srcCands_,candidates);
  
  bool* isMatch = new bool[candidates->size()];
  for (unsigned int iObject=0;iObject<candidates->size();iObject++) isMatch[iObject] = false;
  
  for (unsigned int iSrc=0;iSrc<srcObjects_.size();iSrc++) {
    edm::Handle<edm::View<T2> > objects;
    iEvent.getByLabel(srcObjects_[iSrc],objects);
   
    if(objects->size()==0) continue;
 
    for (unsigned int iObject=0;iObject<candidates->size();iObject++) {
      const T1& candidate = candidates->at(iObject);
      if (!objCut_(candidate)) continue;


      for (unsigned int iObj=0;iObj<objects->size();iObj++) {
        const T2& obj = objects->at(iObj);
        if (!objMatchCut_(obj)) continue;
        double deltaR = reco::deltaR(candidate,obj);
        if (deltaR<deltaRMax_)  isMatch[iObject] = true;
      }
    } 
  }
  

  
  unsigned int counter=0;
  typename edm::View<T1>::const_iterator tIt, endcands = candidates->end();
  for (tIt = candidates->begin(); tIt != endcands; ++tIt, ++counter) {
    if(isMatch[counter]) cleanObjects->push_back( *tIt );  
  }

  nObjectsTot_  +=candidates->size();
  nObjectsMatch_+=cleanObjects->size();

  delete [] isMatch;  
  iEvent.put(cleanObjects);
}

Member Data Documentation

template<typename T1 , typename T2 >
double ObjectViewMatcher< T1, T2 >::deltaRMax_ [private]

Definition at line 66 of file ObjectViewMatcher.cc.

template<typename T1 , typename T2 >
std::string ObjectViewMatcher< T1, T2 >::moduleLabel_ [private]

Definition at line 68 of file ObjectViewMatcher.cc.

template<typename T1 , typename T2 >
unsigned int ObjectViewMatcher< T1, T2 >::nObjectsMatch_ [private]

Definition at line 75 of file ObjectViewMatcher.cc.

template<typename T1 , typename T2 >
unsigned int ObjectViewMatcher< T1, T2 >::nObjectsTot_ [private]

Definition at line 74 of file ObjectViewMatcher.cc.

template<typename T1 , typename T2 >
StringCutObjectSelector<T1,true> ObjectViewMatcher< T1, T2 >::objCut_ [private]

Definition at line 70 of file ObjectViewMatcher.cc.

template<typename T1 , typename T2 >
StringCutObjectSelector<T2,true> ObjectViewMatcher< T1, T2 >::objMatchCut_ [private]

Definition at line 71 of file ObjectViewMatcher.cc.

template<typename T1 , typename T2 >
edm::InputTag ObjectViewMatcher< T1, T2 >::srcCands_ [private]

Definition at line 64 of file ObjectViewMatcher.cc.

template<typename T1 , typename T2 >
std::vector<edm::InputTag> ObjectViewMatcher< T1, T2 >::srcObjects_ [private]

Definition at line 65 of file ObjectViewMatcher.cc.