CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
TopProjector< Top, Bottom > Class Template Reference

#include <TopProjector.h>

Inheritance diagram for TopProjector< Top, Bottom >:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Types

typedef std::vector< Bottom > BottomCollection
 
typedef edm::Handle
< std::vector< Bottom > > 
BottomHandle
 
typedef edm::Ptr< Bottom > BottomPtr
 
typedef std::vector< Top > TopCollection
 
typedef edm::Handle
< std::vector< Top > > 
TopHandle
 
- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 

Public Member Functions

void produce (edm::Event &, const edm::EventSetup &)
 
 TopProjector (const edm::ParameterSet &)
 
 ~TopProjector ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

void maskAncestors (const reco::CandidatePtrVector &ancestors, std::vector< bool > &masked) const
 
void printAncestors (const reco::CandidatePtrVector &ancestors, const edm::Handle< std::vector< Bottom > > &allPFCandidates) const
 
void processCollection (const edm::Handle< std::vector< Top > > &handle, const edm::Handle< std::vector< Bottom > > &allPFCandidates, std::vector< bool > &masked, const char *objectName, const edm::Event &iEvent) const
 
void ptrToAncestor (reco::CandidatePtr candRef, reco::CandidatePtrVector &ancestors, const edm::ProductID &ancestorsID, const edm::Event &iEvent) const
 

Private Attributes

bool enable_
 enable? if not, all candidates in the bottom collection are copied to the output collection More...
 
edm::InputTag inputTagBottom_
 input tag for the masked collection. More...
 
edm::InputTag inputTagTop_
 input tag for the top (masking) collection More...
 
std::string name_
 name of the top projection More...
 
bool verbose_
 verbose ? More...
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

template<class Top, class Bottom>
class TopProjector< Top, Bottom >

Author
Colin Bernet
Date
february 2008

Definition at line 37 of file TopProjector.h.

Member Typedef Documentation

template<class Top , class Bottom >
typedef std::vector<Bottom> TopProjector< Top, Bottom >::BottomCollection

Definition at line 43 of file TopProjector.h.

template<class Top , class Bottom >
typedef edm::Handle< std::vector<Bottom> > TopProjector< Top, Bottom >::BottomHandle

Definition at line 44 of file TopProjector.h.

template<class Top , class Bottom >
typedef edm::Ptr<Bottom> TopProjector< Top, Bottom >::BottomPtr

Definition at line 45 of file TopProjector.h.

template<class Top , class Bottom >
typedef std::vector<Top> TopProjector< Top, Bottom >::TopCollection

Definition at line 41 of file TopProjector.h.

template<class Top , class Bottom >
typedef edm::Handle< std::vector<Top> > TopProjector< Top, Bottom >::TopHandle

Definition at line 42 of file TopProjector.h.

Constructor & Destructor Documentation

template<class Top , class Bottom >
TopProjector< Top, Bottom >::TopProjector ( const edm::ParameterSet iConfig)

Definition at line 103 of file TopProjector.h.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), TopProjector< Top, Bottom >::inputTagBottom_, TopProjector< Top, Bottom >::inputTagTop_, TopProjector< Top, Bottom >::name_, and TopProjector< Top, Bottom >::verbose_.

103  :
104  enable_(iConfig.getParameter<bool>("enable")) {
105 
106  verbose_ = iConfig.getUntrackedParameter<bool>("verbose",false);
107  name_ = iConfig.getUntrackedParameter<std::string>("name","No Name");
108  inputTagTop_ = iConfig.getParameter<edm::InputTag>("topCollection");
109  inputTagBottom_ = iConfig.getParameter<edm::InputTag>("bottomCollection");
110 
111  // will produce a collection of the unmasked candidates in the
112  // bottom collection
113  produces< std::vector<Bottom> >();
114 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::InputTag inputTagTop_
input tag for the top (masking) collection
Definition: TopProjector.h:93
bool verbose_
verbose ?
Definition: TopProjector.h:87
bool enable_
enable? if not, all candidates in the bottom collection are copied to the output collection ...
Definition: TopProjector.h:84
edm::InputTag inputTagBottom_
input tag for the masked collection.
Definition: TopProjector.h:96
std::string name_
name of the top projection
Definition: TopProjector.h:90
template<class Top , class Bottom >
TopProjector< Top, Bottom >::~TopProjector ( )
inline

Definition at line 49 of file TopProjector.h.

49 {};

Member Function Documentation

template<class Top , class Bottom >
void TopProjector< Top, Bottom >::maskAncestors ( const reco::CandidatePtrVector ancestors,
std::vector< bool > &  masked 
) const
private

ancestors is a RefToBase vector. For each object in this vector get the index and set the corresponding slot to true in the masked vector

Definition at line 321 of file TopProjector.h.

References i, getHLTprescales::index, and edm::PtrVectorBase::size().

322  {
323 
324  for(unsigned i=0; i<ancestors.size(); i++) {
325  unsigned index = ancestors[i].key();
326  assert( index<masked.size() );
327 
328  // if(verbose_) {
329  // ProductID id = ancestors[i].id();
330  // std::cout<<"\tmasking "<<index<<", ancestor "<<id<<"/"<<index<<std::endl;
331  // }
332  masked[index] = true;
333  }
334 }
int i
Definition: DBlmapReader.cc:9
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:72
template<class Top , class Bottom >
void TopProjector< Top, Bottom >::printAncestors ( const reco::CandidatePtrVector ancestors,
const edm::Handle< std::vector< Bottom > > &  allPFCandidates 
) const
private

Definition at line 260 of file TopProjector.h.

References gather_cfg::cout, i, edm::PtrVectorBase::id(), getHLTprescales::index, and edm::PtrVectorBase::size().

261  {
262 
263 
264  std::vector<Bottom> pfs = *allPFCandidates;
265 
266  for(unsigned i=0; i<ancestors.size(); i++) {
267 
268  edm::ProductID id = ancestors[i].id();
269  assert( id == allPFCandidates.id() );
270 
271  unsigned index = ancestors[i].key();
272  assert( index < pfs.size() );
273 
274  std::cout<<"\t\t"<<pfs[index]<<std::endl;
275  }
276 }
int i
Definition: DBlmapReader.cc:9
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:72
ProductID id() const
Definition: HandleBase.cc:15
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:55
tuple cout
Definition: gather_cfg.py:41
template<class Top , class Bottom >
void TopProjector< Top, Bottom >::processCollection ( const edm::Handle< std::vector< Top > > &  handle,
const edm::Handle< std::vector< Bottom > > &  allPFCandidates,
std::vector< bool > &  masked,
const char *  objectName,
const edm::Event iEvent 
) const
private

Definition at line 215 of file TopProjector.h.

References gather_cfg::cout, i, edm::PtrVectorBase::id(), iEvent, and benchmark_cfg::topCollection.

219  {
220 
221  if( tops.isValid() && bottoms.isValid() ) {
222  const std::vector<Top>& topCollection = *tops;
223 
224  if(verbose_)
225  std::cout<<"******* TopProjector "<<objectName
226  <<" size = "<<topCollection.size()<<" ******** "<<std::endl;
227 
228  for(unsigned i=0; i<topCollection.size(); i++) {
229 
230 
231  edm::Ptr<Top> ptr( tops, i);
232  reco::CandidatePtr basePtr( ptr );
233 
234 
235  reco::CandidatePtrVector ancestors;
236  ptrToAncestor( basePtr,
237  ancestors,
238  bottoms.id(),
239  iEvent );
240 
241  if(verbose_) {
242 /* std::cout<<"\t"<<objectName<<" "<<i */
243 /* <<" pt,eta,phi = " */
244 /* <<basePtr->pt()<<"," */
245 /* <<basePtr->eta()<<"," */
246 /* <<basePtr->phi()<<std::endl; */
247 
248  std::cout<<"\t"<<topCollection[i]<<std::endl;
249  printAncestors( ancestors, bottoms );
250  }
251 
252  maskAncestors( ancestors, masked );
253  }
254  }
255 
256 }
int i
Definition: DBlmapReader.cc:9
tuple topCollection
bool verbose_
verbose ?
Definition: TopProjector.h:87
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:55
int iEvent
Definition: GenABIO.cc:243
void ptrToAncestor(reco::CandidatePtr candRef, reco::CandidatePtrVector &ancestors, const edm::ProductID &ancestorsID, const edm::Event &iEvent) const
Definition: TopProjector.h:282
tuple cout
Definition: gather_cfg.py:41
void maskAncestors(const reco::CandidatePtrVector &ancestors, std::vector< bool > &masked) const
Definition: TopProjector.h:321
void printAncestors(const reco::CandidatePtrVector &ancestors, const edm::Handle< std::vector< Bottom > > &allPFCandidates) const
Definition: TopProjector.h:260
template<class Top , class Bottom >
void TopProjector< Top, Bottom >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDProducer.

Definition at line 118 of file TopProjector.h.

References edm::Provenance::branchDescription(), gather_cfg::cout, edm::EventID::event(), edm::Event::getByLabel(), edm::Event::getProvenance(), i, edm::EventBase::id(), edm::HandleBase::id(), iEvent, and edm::Event::put().

119  {
120 
121  if( verbose_)
122  std::cout<<"Event -------------------- "<<iEvent.id().event()<<std::endl;
123 
124  // get the various collections
125 
126  // Access the masking collection
127  TopHandle tops;
128  iEvent.getByLabel( inputTagTop_, tops );
129 
130 
131 /* if( !tops.isValid() ) { */
132 /* std::ostringstream err; */
133 /* err<<"The top collection must be supplied."<<std::endl */
134 /* <<"It is now set to : "<<inputTagTop_<<std::endl; */
135 /* edm::LogError("PFPAT")<<err.str(); */
136 /* throw cms::Exception( "MissingProduct", err.str()); */
137 /* } */
138 
139  edm::ProductID topsID = tops.id();
140 
141 
142 
143  // Access the collection to
144  // be masked by the other ones
145  BottomHandle bottoms;
146  iEvent.getByLabel( inputTagBottom_, bottoms );
147 
148 /* if( !bottoms.isValid() ) { */
149 /* std::ostringstream err; */
150 /* err<<"The bottom collection must be supplied."<<std::endl */
151 /* <<"It is now set to : "<<inputTagBottom_<<std::endl; */
152 /* edm::LogError("PFPAT")<<err.str(); */
153 /* throw cms::Exception( "MissingProduct", err.str()); */
154 /* } */
155 
156  edm::ProductID bottomsID = bottoms.id();
157 
158 
159  if(verbose_) {
160  const edm::Provenance& topProv = iEvent.getProvenance(tops.id());
161  const edm::Provenance& bottomProv = iEvent.getProvenance(bottoms.id());
162 
163  std::cout<<"Top projector: event "<<iEvent.id().event()<<std::endl;
164  std::cout<<"Inputs --------------------"<<std::endl;
165  std::cout<<"Top : "
166  <<tops.id()<<"\t"<<tops->size()<<std::endl
167  <<topProv.branchDescription()<<std::endl
168  <<"Bottom : "
169  <<bottoms.id()<<"\t"<<bottoms->size()<<std::endl
170  <<bottomProv.branchDescription()<<std::endl;
171  }
172 
173 
174  // output collection of objects,
175  // selected from the Bottom collection
176 
177  std::auto_ptr< BottomCollection >
178  pBottomOutput( new BottomCollection );
179 
180  // mask for each bottom object.
181  // at the beginning, all bottom objects are unmasked.
182  std::vector<bool> masked( bottoms->size(), false);
183 
184  if( enable_ )
185  processCollection( tops, bottoms, masked, name_.c_str(), iEvent );
186 
187  const BottomCollection& inCands = *bottoms;
188 
189  if(verbose_)
190  std::cout<<" Remaining candidates in the bottom collection ------ "<<std::endl;
191 
192  for(unsigned i=0; i<inCands.size(); i++) {
193 
194  if(masked[i]) {
195  if(verbose_)
196  std::cout<<"X "<<i<<" "<<inCands[i]<<std::endl;
197  continue;
198  }
199  else {
200  if(verbose_)
201  std::cout<<"O "<<i<<" "<<inCands[i]<<std::endl;
202 
203  pBottomOutput->push_back( inCands[i] );
204  BottomPtr motherPtr( bottoms, i );
205  pBottomOutput->back().setSourceCandidatePtr(motherPtr);
206  }
207  }
208 
209  iEvent.put( pBottomOutput );
210 }
EventNumber_t event() const
Definition: EventID.h:44
int i
Definition: DBlmapReader.cc:9
edm::Handle< std::vector< Top > > TopHandle
Definition: TopProjector.h:42
std::vector< Bottom > BottomCollection
Definition: TopProjector.h:43
edm::InputTag inputTagTop_
input tag for the top (masking) collection
Definition: TopProjector.h:93
bool verbose_
verbose ?
Definition: TopProjector.h:87
bool enable_
enable? if not, all candidates in the bottom collection are copied to the output collection ...
Definition: TopProjector.h:84
int iEvent
Definition: GenABIO.cc:243
edm::Handle< std::vector< Bottom > > BottomHandle
Definition: TopProjector.h:44
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
void processCollection(const edm::Handle< std::vector< Top > > &handle, const edm::Handle< std::vector< Bottom > > &allPFCandidates, std::vector< bool > &masked, const char *objectName, const edm::Event &iEvent) const
Definition: TopProjector.h:215
BranchDescription const & branchDescription() const
Definition: Provenance.h:46
edm::InputTag inputTagBottom_
input tag for the masked collection.
Definition: TopProjector.h:96
std::string name_
name of the top projection
Definition: TopProjector.h:90
edm::EventID id() const
Definition: EventBase.h:56
tuple cout
Definition: gather_cfg.py:41
edm::Ptr< Bottom > BottomPtr
Definition: TopProjector.h:45
ProductIndex id() const
Definition: ProductID.h:39
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:61
template<class Top , class Bottom >
void TopProjector< Top, Bottom >::ptrToAncestor ( reco::CandidatePtr  candRef,
reco::CandidatePtrVector ancestors,
const edm::ProductID ancestorsID,
const edm::Event iEvent 
) const
private

fills ancestors with ptrs to the PFCandidates that in one way or another contribute to the candidate pointed to by candPtr

Definition at line 282 of file TopProjector.h.

References edm::Provenance::branchDescription(), gather_cfg::cout, edm::Event::getProvenance(), i, edm::Ptr< T >::id(), edm::Ptr< T >::key(), and edm::PtrVector< T >::push_back().

285  {
286 
287 
288  unsigned nSources = candPtr->numberOfSourceCandidatePtrs();
289 
290  if(verbose_) {
291  const edm::Provenance& hereProv = iEvent.getProvenance(candPtr.id());
292 
293  std::cout<<"going down from "<<candPtr.id()
294  <<"/"<<candPtr.key()<<" #mothers "<<nSources
295  <<" ancestor id "<<ancestorsID<<std::endl
296  <<hereProv.branchDescription()<<std::endl;
297  }
298 
299  for(unsigned i=0; i<nSources; i++) {
300 
301  reco::CandidatePtr mother = candPtr->sourceCandidatePtr(i);
302  if( verbose_ ) {
303 /* const Provenance& motherProv = iEvent.getProvenance(mother.id()); */
304  std::cout<<" mother id "<<mother.id()<<std::endl;
305  }
306  if( mother.id() != ancestorsID ) {
307  // the mother is not yet at lowest level
308  ptrToAncestor( mother, ancestors, ancestorsID, iEvent );
309  }
310  else {
311  // adding mother to the list of ancestors
312  ancestors.push_back( mother );
313  }
314  }
315 }
int i
Definition: DBlmapReader.cc:9
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:135
bool verbose_
verbose ?
Definition: TopProjector.h:87
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:168
void ptrToAncestor(reco::CandidatePtr candRef, reco::CandidatePtrVector &ancestors, const edm::ProductID &ancestorsID, const edm::Event &iEvent) const
Definition: TopProjector.h:282
BranchDescription const & branchDescription() const
Definition: Provenance.h:46
tuple cout
Definition: gather_cfg.py:41
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:61

Member Data Documentation

template<class Top , class Bottom >
bool TopProjector< Top, Bottom >::enable_
private

enable? if not, all candidates in the bottom collection are copied to the output collection

Definition at line 84 of file TopProjector.h.

template<class Top , class Bottom >
edm::InputTag TopProjector< Top, Bottom >::inputTagBottom_
private

input tag for the masked collection.

Definition at line 96 of file TopProjector.h.

Referenced by TopProjector< Top, Bottom >::TopProjector().

template<class Top , class Bottom >
edm::InputTag TopProjector< Top, Bottom >::inputTagTop_
private

input tag for the top (masking) collection

Definition at line 93 of file TopProjector.h.

Referenced by TopProjector< Top, Bottom >::TopProjector().

template<class Top , class Bottom >
std::string TopProjector< Top, Bottom >::name_
private

name of the top projection

Definition at line 90 of file TopProjector.h.

Referenced by Config.Process::fillProcessDesc(), and TopProjector< Top, Bottom >::TopProjector().

template<class Top , class Bottom >
bool TopProjector< Top, Bottom >::verbose_
private

verbose ?

Definition at line 87 of file TopProjector.h.

Referenced by TopProjector< Top, Bottom >::TopProjector().