17 #define INIT_ENTRY(name) {#name,name}
21 std::vector<unsigned> _id;
22 std::vector<unsigned> _size;
26 QuickUnion(
const unsigned NBranches) {
28 _id.resize(NBranches);
29 _size.resize(NBranches);
30 for(
unsigned i = 0;
i < NBranches; ++
i ) {
36 int count()
const {
return _count; }
38 unsigned find(
unsigned p) {
39 while( p != _id[p] ) {
46 bool connected(
unsigned p,
unsigned q) {
return find(p) ==
find(q); }
48 void unite(
unsigned p,
unsigned q) {
49 unsigned rootP =
find(p);
50 unsigned rootQ =
find(q);
53 if(_size[rootP] < _size[rootQ] ) {
54 _id[rootP] = rootQ; _size[rootQ] += _size[rootP];
56 _id[rootQ] = rootP; _size[rootP] += _size[rootQ];
86 for(
unsigned i = 0;
i < rowsize; ++
i ) {
87 for(
unsigned j = 0;
j < rowsize; ++
j ) {
95 for(
const auto& conf : confs ) {
100 size_t split = linkTypeStr.find(
':');
101 if( split == std::string::npos ) {
103 <<
"\"" << linkTypeStr <<
"\" is not a valid link type definition."
104 <<
" This string should have the form \"linkFrom:linkTo\"";
106 std::string link1(prefix+linkTypeStr.substr(0,split));
107 std::string link2(prefix+linkTypeStr.substr(split+1,std::string::npos));
110 <<
"One of \"" << link1 <<
"\" or \"" << link2
111 <<
"\" are invalid block element types!";
122 const bool useKDTree = conf.getParameter<
bool>(
"useKDTree");
135 for(
const auto& conf : confs ) {
148 cout<<
"~PFBlockAlgo - number of remaining elements: "
155 for(
const auto& kdtree :
_kdtrees ) {
166 for(
unsigned i = 0;
i < elem_size; ++
i ) {
167 for(
unsigned j = 0;
j < elem_size; ++
j ) {
168 if( qu.connected(
i,
j) ||
j ==
i )
continue;
187 std::unordered_multimap<unsigned,unsigned> blocksmap(
elements_.size());
188 std::vector<unsigned>
keys;
192 while( key != qu.find(key) ) key = qu.find(key);
193 auto pos = std::lower_bound(keys.begin(),keys.end(),
key);
194 if( pos == keys.end() || *pos !=
key ) {
195 keys.insert(pos,key);
197 blocksmap.emplace(key,
i);
202 for(
auto key : keys ) {
204 auto range = blocksmap.equal_range(key);
205 auto& the_block =
blocks_->back();
207 the_block.addElement(
p1);
208 const unsigned block_size = blocksmap.count(key) + 1;
210 std::unordered_map<std::pair<unsigned int,unsigned int>,
PFBlockLink >
links(
min(1000000u,block_size*block_size));
211 auto itr = range.first;
213 for( ; itr != range.second; ++itr ) {
217 the_block.addElement(
p2);
218 linktest = PFBlock::LINKTEST_RECHIT;
223 links.emplace( std::make_pair(
p1->index(),
p2->index()) ,
225 p1->index(),
p2->index() ) );
237 const std::unordered_map<std::pair<unsigned int,unsigned int>,
PFBlockLink>&
links )
const {
243 unsigned elsize = els.
size();
245 for(
unsigned i1=0; i1<elsize; ++i1 ) {
246 for(
unsigned i2=0; i2<i1; ++i2 ) {
255 = PFBlock::LINKTEST_RECHIT;
259 const auto link_itr =
links.find(std::make_pair(i2,i1));
260 if( link_itr !=
links.end() ) {
261 dist = link_itr->second.dist();
262 linktest = link_itr->second.test();
269 const auto minmax = std::minmax(type1,type2);
270 const unsigned index = rowsize*minmax.second + minmax.first;
273 if (bTestLink)
link( & els[i1], & els[i2], linktype, linktest, dist);
280 cout <<
"Setting link between elements " << i1 <<
" and " << i2
281 <<
" of dist =" << dist <<
" computed from link test "
298 const unsigned index = rowsize*
std::max(type1,type2) +
std::min(type1,type2);
308 double& dist)
const {
311 linktest = PFBlock::LINKTEST_RECHIT;
315 const unsigned index = rowsize*
std::max(type1,type2) +
std::min(type1,type2);
317 std::cout <<
" PFBlockAlgo links type1 " << type1
318 <<
" type2 " << type2 << std::endl;
327 importer->updateEventSetup(es);
336 ranges_.fill(std::make_pair(0,0));
338 for(
const auto& importer : _importers ) {
343 [](
const auto&
a,
const auto&
b) {
return a->type() <
b->type(); } );
353 ranges_[current_type].first = 0;
357 if( the_type != current_type ) {
360 current_type = the_type;
368 for (ElementList::iterator it =
elements_.begin();
370 for(
const auto& kdtree : _kdtrees ) {
371 if( (*it)->type() == kdtree->targetType() ) {
372 kdtree->insertTargetElt(it->get());
374 if( (*it)->type() == kdtree->fieldType() ) {
375 kdtree->insertFieldClusterElt(it->get());
383 if(! out)
return out;
385 out<<
"====== Particle Flow Block Algorithm ======= ";
387 out<<
"number of unassociated elements : "<<a.
elements_.size()<<endl;
392 out<<
"\t"<<**ie <<endl;
398 const std::auto_ptr< reco::PFBlockCollection >&
blocks
402 out<<
"blocks already transfered"<<endl;
405 out<<
"number of blocks : "<<blocks->size()<<endl;
409 ib != blocks->end(); ++
ib) {
const std::auto_ptr< reco::PFBlockCollection > & blocks() const
Abstract base class for a PFBlock element (track, cluster...)
std::vector< LinkTestPtr > _linkTests
const std::unordered_map< std::string, reco::PFBlockElement::Type > _elementTypes
ElementList::const_iterator IEC
const edm::OwnVector< reco::PFBlockElement > & elements() const
std::auto_ptr< reco::PFBlockCollection > blocks_
const LinkData & linkData() const
std::ostream & operator<<(std::ostream &out, const ALILine &li)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
void setLink(unsigned i1, unsigned i2, double dist, LinkData &linkData, LinkTest test=LINKTEST_RECHIT) const
void link(const reco::PFBlockElement *el1, const reco::PFBlockElement *el2, PFBlockLink::Type &linktype, reco::PFBlock::LinkTest &linktest, double &dist) const
check whether 2 elements are linked. Returns distance and linktype
std::vector< KDTreePtr > _kdtrees
void updateEventSetup(const edm::EventSetup &)
void setImporters(const std::vector< edm::ParameterSet > &, edm::ConsumesCollector &)
std::vector< PFBlock > PFBlockCollection
collection of PFBlock objects
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
void packLinks(reco::PFBlock &block, const std::unordered_map< std::pair< unsigned int, unsigned int >, PFBlockLink > &links) const
reco::PFBlockCollection::const_iterator IBC
bool linkPrefilter(const reco::PFBlockElement *last, const reco::PFBlockElement *next) const
Avoid to check links when not useful.
void findBlocks()
build blocks
Type
possible types. WARNING: have a look at PFBlockElement
std::vector< ElementList::value_type::pointer > bare_elements_
volatile std::atomic< bool > shutdown_flag false
void buildElements(const edm::Event &)
unsigned int _linkTestSquare[reco::PFBlockElement::kNBETypes][reco::PFBlockElement::kNBETypes]
bool debug_
if true, debug printouts activated
void setLinkers(const std::vector< edm::ParameterSet > &)
T get(const Candidate &c)
std::vector< ImporterPtr > _importers