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)
 
static void prevalidate (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 318 of file TopProjector.h.

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

319  {
320 
321  for(unsigned i=0; i<ancestors.size(); i++) {
322  unsigned index = ancestors[i].key();
323  assert( index<masked.size() );
324 
325  // if(verbose_) {
326  // ProductID id = ancestors[i].id();
327  // std::cout<<"\tmasking "<<index<<", ancestor "<<id<<"/"<<index<<std::endl;
328  // }
329  masked[index] = true;
330  }
331 }
int i
Definition: DBlmapReader.cc:9
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:73
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 257 of file TopProjector.h.

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

258  {
259 
260 
261  std::vector<Bottom> pfs = *allPFCandidates;
262 
263  for(unsigned i=0; i<ancestors.size(); i++) {
264 
265  edm::ProductID id = ancestors[i].id();
266  assert( id == allPFCandidates.id() );
267 
268  unsigned index = ancestors[i].key();
269  assert( index < pfs.size() );
270 
271  std::cout<<"\t\t"<<pfs[index]<<std::endl;
272  }
273 }
int i
Definition: DBlmapReader.cc:9
size_type size() const
Size of the RefVector.
Definition: PtrVectorBase.h:73
ProductID id() const
Definition: HandleBase.cc:15
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:56
tuple cout
Definition: gather_cfg.py:121
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 212 of file TopProjector.h.

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

216  {
217 
218  if( tops.isValid() && bottoms.isValid() ) {
219  const std::vector<Top>& topCollection = *tops;
220 
221  if(verbose_)
222  std::cout<<"******* TopProjector "<<objectName
223  <<" size = "<<topCollection.size()<<" ******** "<<std::endl;
224 
225  for(unsigned i=0; i<topCollection.size(); i++) {
226 
227 
228  edm::Ptr<Top> ptr( tops, i);
229  reco::CandidatePtr basePtr( ptr );
230 
231 
232  reco::CandidatePtrVector ancestors;
233  ptrToAncestor( basePtr,
234  ancestors,
235  bottoms.id(),
236  iEvent );
237 
238  if(verbose_) {
239 /* std::cout<<"\t"<<objectName<<" "<<i */
240 /* <<" pt,eta,phi = " */
241 /* <<basePtr->pt()<<"," */
242 /* <<basePtr->eta()<<"," */
243 /* <<basePtr->phi()<<std::endl; */
244 
245  std::cout<<"\t"<<topCollection[i]<<std::endl;
246  printAncestors( ancestors, bottoms );
247  }
248 
249  maskAncestors( ancestors, masked );
250  }
251  }
252 
253 }
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:56
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:279
tuple cout
Definition: gather_cfg.py:121
void maskAncestors(const reco::CandidatePtrVector &ancestors, std::vector< bool > &masked) const
Definition: TopProjector.h:318
void printAncestors(const reco::CandidatePtrVector &ancestors, const edm::Handle< std::vector< Bottom > > &allPFCandidates) const
Definition: TopProjector.h:257
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().

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

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 
140 
141 
142  // Access the collection to
143  // be masked by the other ones
144  BottomHandle bottoms;
145  iEvent.getByLabel( inputTagBottom_, bottoms );
146 
147 /* if( !bottoms.isValid() ) { */
148 /* std::ostringstream err; */
149 /* err<<"The bottom collection must be supplied."<<std::endl */
150 /* <<"It is now set to : "<<inputTagBottom_<<std::endl; */
151 /* edm::LogError("PFPAT")<<err.str(); */
152 /* throw cms::Exception( "MissingProduct", err.str()); */
153 /* } */
154 
155 
156  if(verbose_) {
157  const edm::Provenance& topProv = iEvent.getProvenance(tops.id());
158  const edm::Provenance& bottomProv = iEvent.getProvenance(bottoms.id());
159 
160  std::cout<<"Top projector: event "<<iEvent.id().event()<<std::endl;
161  std::cout<<"Inputs --------------------"<<std::endl;
162  std::cout<<"Top : "
163  <<tops.id()<<"\t"<<tops->size()<<std::endl
164  <<topProv.branchDescription()<<std::endl
165  <<"Bottom : "
166  <<bottoms.id()<<"\t"<<bottoms->size()<<std::endl
167  <<bottomProv.branchDescription()<<std::endl;
168  }
169 
170 
171  // output collection of objects,
172  // selected from the Bottom collection
173 
174  std::auto_ptr< BottomCollection >
175  pBottomOutput( new BottomCollection );
176 
177  // mask for each bottom object.
178  // at the beginning, all bottom objects are unmasked.
179  std::vector<bool> masked( bottoms->size(), false);
180 
181  if( enable_ )
182  processCollection( tops, bottoms, masked, name_.c_str(), iEvent );
183 
184  const BottomCollection& inCands = *bottoms;
185 
186  if(verbose_)
187  std::cout<<" Remaining candidates in the bottom collection ------ "<<std::endl;
188 
189  for(unsigned i=0; i<inCands.size(); i++) {
190 
191  if(masked[i]) {
192  if(verbose_)
193  std::cout<<"X "<<i<<" "<<inCands[i]<<std::endl;
194  continue;
195  }
196  else {
197  if(verbose_)
198  std::cout<<"O "<<i<<" "<<inCands[i]<<std::endl;
199 
200  pBottomOutput->push_back( inCands[i] );
201  BottomPtr motherPtr( bottoms, i );
202  pBottomOutput->back().setSourceCandidatePtr(motherPtr);
203  }
204  }
205 
206  iEvent.put( pBottomOutput );
207 }
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:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
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:212
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:121
edm::Ptr< Bottom > BottomPtr
Definition: TopProjector.h:45
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:60
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 279 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().

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

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 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().