CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/HLTriggerOffline/Tau/src/HLTTauRefCombiner.cc

Go to the documentation of this file.
00001 #include "HLTriggerOffline/Tau/interface/HLTTauRefCombiner.h"
00002 #include "Math/GenVector/VectorUtil.h"
00003 
00004 
00005 
00006 using namespace edm;
00007 using namespace std;
00008 
00009 HLTTauRefCombiner::HLTTauRefCombiner(const edm::ParameterSet& iConfig)
00010 {
00011   inputColl_   = iConfig.getParameter< std::vector<InputTag> >("InputCollections");
00012   matchDeltaR_ = iConfig.getParameter<double>("MatchDeltaR");
00013   outName_     = iConfig.getParameter<string>("OutputCollection");
00014 
00015   produces<LorentzVectorCollection> ( outName_);
00016 }
00017 
00018 HLTTauRefCombiner::~HLTTauRefCombiner(){ }
00019 
00020 void HLTTauRefCombiner::produce(edm::Event& iEvent, const edm::EventSetup& iES)
00021 {
00022     auto_ptr<LorentzVectorCollection> out_product(new LorentzVectorCollection);
00023 
00024     //Create The Handles..
00025     std::vector< Handle<LorentzVectorCollection> > handles;
00026 
00027     bool allCollectionsExist = true;
00028     //Map the Handles to the collections if all collections exist
00029     for(size_t i = 0;i<inputColl_.size();++i)
00030       {
00031         edm::Handle<LorentzVectorCollection> tmp;
00032         if(iEvent.getByLabel(inputColl_[i],tmp))
00033           {
00034             handles.push_back(tmp);
00035           }
00036         else
00037           {
00038             allCollectionsExist = false;
00039           }
00040 
00041       }
00042 
00043     //The reference output object collection will be the first one..
00044     if(allCollectionsExist)
00045       {
00046         //loop on the first collection
00047         for(size_t i = 0; i < (handles[0])->size();++i)
00048           {
00049             bool MatchedObj = true;
00050 
00051             //get reference Vector
00052             const LorentzVector lvRef = (*(handles[0]))[i];
00053             
00054             //Loop on all other collections and match
00055                 for(size_t j = 1; j < handles.size();++j)
00056                   {
00057                     if(!match(lvRef,*(handles[j])))
00058                       MatchedObj = false;
00059 
00060                   }
00061                 
00062                 //If the Object is Matched Everywhere store
00063                 if(MatchedObj)
00064                   {
00065                     out_product->push_back(lvRef);
00066                   }
00067 
00068 
00069           }
00070 
00071         //Put product to file
00072         iEvent.put(out_product,outName_);
00073 
00074       }
00075     
00076     
00077 
00078 
00079 }
00080 
00081 
00082 
00083 bool 
00084 HLTTauRefCombiner::match(const LorentzVector& lv,const LorentzVectorCollection& lvcol)
00085 {
00086  bool matched=false;
00087 
00088  if(lvcol.size()>0)
00089   for(LorentzVectorCollection::const_iterator it = lvcol.begin();it!=lvcol.end();++it)
00090    {
00091           double delta = ROOT::Math::VectorUtil::DeltaR(lv,*it);
00092           if(delta<matchDeltaR_)
00093             {
00094               matched=true;
00095              
00096             }
00097    }
00098 
00099 
00100 
00101  return matched;
00102 }