CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
PFCandidateMixer Class Reference

#include <MyAna/PFCandidateMixer/src/PFCandidateMixer.cc>

Inheritance diagram for PFCandidateMixer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PFCandidateMixer (const edm::ParameterSet &)
 
 ~PFCandidateMixer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void beginJob ()
 
virtual void endJob ()
 
void mix (edm::Event &iEvent, const edm::Handle< reco::TrackCollection > &trackCol, const edm::Handle< reco::MuonCollection > &muonCol, const edm::Handle< reco::GsfElectronCollection > &electronCol, const reco::PFCandidateCollection &pfIn1, const reco::PFCandidateCollection &pfIn2)
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 

Private Attributes

edm::InputTag _col1
 
edm::InputTag _col2
 
edm::InputTag _electronCol
 
edm::InputTag _muonCol
 
edm::InputTag _trackCol
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 52 of file PFCandidateMixer.cc.

Constructor & Destructor Documentation

PFCandidateMixer::PFCandidateMixer ( const edm::ParameterSet iConfig)
explicit

Definition at line 85 of file PFCandidateMixer.cc.

References _electronCol, _muonCol, edm::InputTag::label(), and edm::ProductRegistryHelper::produces().

85  :
86  _col1(iConfig.getUntrackedParameter<edm::InputTag>("col1") ),
87  _col2(iConfig.getUntrackedParameter<edm::InputTag>("col2") ),
88  _trackCol(iConfig.getUntrackedParameter<edm::InputTag>("trackCol") ),
89  _muonCol(iConfig.getUntrackedParameter<edm::InputTag>("muons") ),
90  _electronCol(iConfig.getUntrackedParameter<edm::InputTag>("gsfElectrons"))
91 {
92  produces< std::vector< reco::PFCandidate > >();
93 
94  if(!_electronCol.label().empty())
96 #if 0
97  if(!_muonCol.label().empty())
99 #endif
100 }
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag _electronCol
edm::InputTag _col2
edm::InputTag _muonCol
TypeLabelItem const & produces()
declare what type of product will make and with which optional label
edm::InputTag _col1
std::string const & label() const
Definition: InputTag.h:42
edm::InputTag _trackCol
PFCandidateMixer::~PFCandidateMixer ( )

Definition at line 102 of file PFCandidateMixer.cc.

103 {
104 
105  // do anything here that needs to be done at desctruction time
106  // (e.g. close files, deallocate resources etc.)
107 
108 }

Member Function Documentation

void PFCandidateMixer::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 268 of file PFCandidateMixer.cc.

269 {
270 }
void PFCandidateMixer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 274 of file PFCandidateMixer.cc.

274  {
275 }
void PFCandidateMixer::mix ( edm::Event iEvent,
const edm::Handle< reco::TrackCollection > &  trackCol,
const edm::Handle< reco::MuonCollection > &  muonCol,
const edm::Handle< reco::GsfElectronCollection > &  electronCol,
const reco::PFCandidateCollection pfIn1,
const reco::PFCandidateCollection pfIn2 
)
private

Definition at line 142 of file PFCandidateMixer.cc.

References gather_cfg::cout, reco::deltaR(), reco::PFCandidate::e, edm::helper::Filler< Map >::fill(), newFWLiteAna::found, edm::Event::getProvenance(), i, edm::helper::Filler< Map >::insert(), edm::HandleBase::isValid(), edm::Provenance::moduleLabel(), edm::Provenance::processName(), edm::Provenance::productInstanceName(), edm::Event::put(), L1Trigger_dataformats::reco, GlobalPosition_Frontier_DevDB_cff::tag, and makeHLTPrescaleTable::values.

Referenced by produce().

143 {
144  using namespace edm;
145  using namespace reco;
146 
147  std::vector<const reco::PFCandidateCollection*> colVec;
148 
149  colVec.push_back(&pfIn1);
150  colVec.push_back(&pfIn2);
151 
152  std::auto_ptr<std::vector< reco::PFCandidate > > pOut(new std::vector< reco::PFCandidate > );
153 
154  std::vector<const reco::PFCandidateCollection*>::iterator itCol= colVec.begin();
155  std::vector<const reco::PFCandidateCollection*>::iterator itColE= colVec.end();
156 
157  std::map<reco::GsfElectronRef, reco::PFCandidatePtr> electronCandidateMap;
158 
159  int iCol = 0;
160  for (;itCol!=itColE; ++itCol){
161  PFCandidateConstIterator it = (*itCol)->begin();
162  PFCandidateConstIterator itE = (*itCol)->end();
163  for (;it!=itE;++it) {
164  edm::Ptr<reco::PFCandidate> candPtr(*itCol, it - (*itCol)->begin());
165  reco::PFCandidate cand(*it);
166  //reco::PFCandidate cand(candPtr); // This breaks the output module, I'm not sure why
167 
168  //const bool isphoton = cand.particleId() == reco::PFCandidate::gamma && cand.mva_nothing_gamma()>0.;
169  const bool iselectron = cand.particleId() == reco::PFCandidate::e;
170  //const bool hasNonNullMuonRef = cand.muonRef().isNonnull();
171 
172  // if it is an electron. Find the GsfElectron with the same GsfTrack
173  if (electronCol.isValid() && iselectron) {
174  const reco::GsfTrackRef& gsfTrackRef(cand.gsfTrackRef());
175  GsfElectronEqual myEqual(gsfTrackRef);
176  std::vector<reco::GsfElectron>::const_iterator itcheck=find_if(electronCol->begin(), electronCol->end(), myEqual);
177  if(itcheck==electronCol->end())
178  throw cms::Exception("PFCandidateMixer") << "GsfElectron for candidate not found!";
179 
180  reco::GsfElectronRef electronRef(electronCol, itcheck - electronCol->begin());
181  cand.setGsfElectronRef(electronRef);
182  cand.setSuperClusterRef(electronRef->superCluster());
183  electronCandidateMap[electronRef] = candPtr;
184  }
185 
186  // TODO: Do the same for muons -- see PFLinker.cc, we just don't have the MuonToMuonMap available.
187  // But it might work with the pure muons collections as well.
188 
189  size_t i = 0;
190  bool found = false;
191  double minDR = 9999.;
192  int iMinDr = -1;
193  if (it->trackRef().isNonnull()) {
194  for ( i = 0 ; i < trackCol->size(); ++i){
195  if ( reco::deltaR( *(it->trackRef()), (*trackCol)[i] )<0.001 ) {
196  found = true;
197  break;
198  }
199  double dr = reco::deltaR( *(it->trackRef()), (*trackCol)[i] );
200  if ( dr < minDR) {
201  iMinDr = i;
202  minDR = dr;
203  }
204  }
205  }
206  if ( found ){ // ref was found, overwrite in PFCand
207  reco::TrackRef trref(trackCol,i);
208  cand.setTrackRef(trref);
209  //std::cout << " YY track ok"<<std::endl;
210 
211  } else { // keep orginall ref
212  if (it->trackRef().isNonnull()) {
213  std::cout << " XXXXXXXXXXX track not found "
214  << " col " << iCol
215  << " ch " << it->charge()
216  << " id " << it->pdgId()
217  << " pt " << it->pt()
218  << " track: eta " << it->trackRef()->eta()
219  << " pt: " << it->trackRef()->pt()
220  << " charge: " << it->trackRef()->charge()
221  << std::endl;
222  std::cout << " minDR=" << minDR << std::endl;
223  if ( iMinDr >= 0 ) {
224  std::cout
225  << " closest track pt=" << (*trackCol)[iMinDr].pt()
226  << " ch=" << (*trackCol)[iMinDr].charge()
227  << std::endl;
228  }
229  edm::Provenance prov=iEvent.getProvenance(it->trackRef().id());
231  std::cout << " trackref in PFCand came from: " << tag.encode() << std::endl;
232  }
233  }
234  pOut->push_back(cand);
235  }
236  ++iCol;
237  }
238 
240 
241  // Now fixup the references and write the valuemap
242  if(electronCol.isValid())
243  {
244  std::vector<reco::PFCandidatePtr> values(electronCol->size());
245  for(unsigned int i = 0; i < electronCol->size(); ++i)
246  {
247  edm::Ref<reco::GsfElectronCollection> objRef(electronCol, i);
248  std::map<reco::GsfElectronRef, reco::PFCandidatePtr>::const_iterator iter = electronCandidateMap.find(objRef);
249 
250  reco::PFCandidatePtr candPtr;
251  if(iter != electronCandidateMap.end())
252  candPtr = reco::PFCandidatePtr(newColl, iter->second.key());
253  values[i] = candPtr;
254  }
255 
256  std::auto_ptr<edm::ValueMap<reco::PFCandidatePtr> > pfMap_p(new edm::ValueMap<reco::PFCandidatePtr>());
258  filler.insert(electronCol, values.begin(), values.end());
259  filler.fill();
260  iEvent.put(pfMap_p, "electrons");
261  }
262 
263  // TODO: Do the same for muons
264 }
int i
Definition: DBlmapReader.cc:9
PFCandidateCollection::const_iterator PFCandidateConstIterator
iterator
std::string const & processName() const
Definition: Provenance.h:63
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
bool isValid() const
Definition: HandleBase.h:76
std::string const & moduleLabel() const
Definition: Provenance.h:62
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:35
tuple cout
Definition: gather_cfg.py:121
std::string const & productInstanceName() const
Definition: Provenance.h:64
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:68
void PFCandidateMixer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 117 of file PFCandidateMixer.cc.

References _col1, _col2, _electronCol, _muonCol, _trackCol, edm::Event::getByLabel(), edm::InputTag::label(), and mix().

118 {
119  const bool muonColGiven = !_muonCol.label().empty();
120  const bool electronColGiven = !_electronCol.label().empty();
121 
125  iEvent.getByLabel( _trackCol, trackCol);
126 
127  if(muonColGiven)
128  if(!iEvent.getByLabel(_muonCol, muonCol))
129  throw cms::Exception("PFCandidateMixer") << "Muon Collection not found!";
130  if(electronColGiven)
131  if(!iEvent.getByLabel(_electronCol, electronCol))
132  throw cms::Exception("PFCandidateMixer") << "GsfElectron Collection not found!";
133 
136  iEvent.getByLabel(_col1, pfIn1);
137  iEvent.getByLabel(_col2, pfIn2);
138 
139  mix(iEvent, trackCol, muonCol, electronCol, *pfIn1, *pfIn2);
140 }
edm::InputTag _electronCol
edm::InputTag _col2
edm::InputTag _muonCol
edm::InputTag _col1
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
std::string const & label() const
Definition: InputTag.h:42
edm::InputTag _trackCol
void mix(edm::Event &iEvent, const edm::Handle< reco::TrackCollection > &trackCol, const edm::Handle< reco::MuonCollection > &muonCol, const edm::Handle< reco::GsfElectronCollection > &electronCol, const reco::PFCandidateCollection &pfIn1, const reco::PFCandidateCollection &pfIn2)

Member Data Documentation

edm::InputTag PFCandidateMixer::_col1
private

Definition at line 64 of file PFCandidateMixer.cc.

Referenced by produce().

edm::InputTag PFCandidateMixer::_col2
private

Definition at line 65 of file PFCandidateMixer.cc.

Referenced by produce().

edm::InputTag PFCandidateMixer::_electronCol
private

Definition at line 69 of file PFCandidateMixer.cc.

Referenced by PFCandidateMixer(), and produce().

edm::InputTag PFCandidateMixer::_muonCol
private

Definition at line 68 of file PFCandidateMixer.cc.

Referenced by PFCandidateMixer(), and produce().

edm::InputTag PFCandidateMixer::_trackCol
private

Definition at line 67 of file PFCandidateMixer.cc.

Referenced by produce().