7 bool greaterByEnergy(
const std::pair<unsigned,double>&
a,
8 const std::pair<unsigned,double>&
b) {
9 return a.second > b.second;
16 std::vector<bool>& mask ) {
19 std::vector<std::pair<unsigned,double> > ordered_hits;
20 ordered_hits.reserve(input->size());
21 for(
unsigned i = 0;
i < input->size(); ++
i ) {
22 std::pair<unsigned,double> val = std::make_pair(
i,input->at(
i).energy());
23 auto pos = std::upper_bound(ordered_hits.begin(),ordered_hits.end(),
24 val, greaterByEnergy);
25 ordered_hits.insert(pos,val);
28 for(
const auto& idx_e : ordered_hits ) {
29 if( !mask[idx_e.first] )
continue;
30 const unsigned idx = idx_e.first;
32 int layer = rechit.
layer();
37 int ieta = theHcalDetId.
ieta();
38 int iphi = theHcalDetId.iphi();
39 int ihpd = 0, irbx = 0;
42 ihpd = ( ieta < 0 ? -iphi : iphi );
43 irbx = ( ieta < 0 ? -(iphi+5)/4 : (iphi+5)/4 );
46 ihpd = ( ieta < 0 ? -(iphi+1)/2-100 : (iphi+1)/2+100 );
47 irbx = ( ieta < 0 ? -(iphi+5)/4-20 : (iphi+5)/4+20 );
54 irbx = ( irbx < 0 ? -1 : 1 );
57 irbx = ( irbx < 0 ? -21 : 21 );
62 _hpds[ihpd].push_back(idx);
63 _rbxs[irbx].push_back(idx);
67 double totalEta = 0., totalEtaW = 0., totalPhi = 0., totalPhiW = 0.,
69 double totalEta2 = 1E-9, totalEta2W = 1E-9, totalPhi2 = 1E-9,
70 totalPhi2W = 1E-9, totalEnergy2 = 1E-9;
71 unsigned nSeeds = 0, nSeeds0 = 0;
72 std::unordered_map<int, std::vector<unsigned> > theHPDs;
73 std::unordered_multimap<double, unsigned> theEnergies;
74 for(
const auto& itrbx :
_rbxs ) {
75 if( (
std::abs(itrbx.first)<20 && itrbx.second.size() > 30 ) ||
76 (
std::abs(itrbx.first)>20 && itrbx.second.size() > 30 ) ) {
77 const std::vector<unsigned>&
rechits = itrbx.second;
80 totalEta = totalEtaW = totalPhi = totalPhiW = totalEnergy = 0.;
81 totalEta2 = totalEta2W = totalPhi2 = totalPhi2W = totalEnergy2 = 1
e-9;
82 nSeeds = nSeeds0 = rechits.size();
83 for(
unsigned jh = 0; jh < rechits.size(); ++jh ) {
89 for(
auto k : neighbours4 ) {
90 auto const & neighbour = (*input)[
k];
91 if( neighbour.energy() > rechit.
energy() ) {
96 if( neighbour.energy() > 0.4 ) ++nN;
99 if ( isASeed && !nN ) --nSeeds0;
102 int iphi = theHcalDetId.
iphi();
103 switch( rechit.
layer() ) {
105 theHPDs[iphi].push_back(rechits[jh]);
108 theHPDs[(iphi-1)/2].push_back(rechits[jh]);
113 const double rhenergy = rechit.
energy();
115 const double rhphi2 = rhphi*rhphi;
117 const double rheta2 = rheta*rheta;
118 theEnergies.emplace(rhenergy,rechits[jh]);
119 totalEnergy += rhenergy;
121 totalPhiW +=
std::abs(rhphi)*rhenergy;
123 totalEtaW += rheta*rhenergy;
124 totalEnergy2 += rhenergy*rhenergy;
126 totalPhi2W += rhphi2*rhenergy;
128 totalEta2W += rheta2*rhenergy;
130 totalPhi /= rechits.size();
131 totalEta /= rechits.size();
132 totalPhiW /= totalEnergy;
133 totalEtaW /= totalEnergy;
134 totalPhi2 /= rechits.size();
135 totalEta2 /= rechits.size();
136 totalPhi2W /= totalEnergy;
137 totalEta2W /= totalEnergy;
138 totalPhi2 =
std::sqrt(totalPhi2 - totalPhi*totalPhi);
139 totalEta2 =
std::sqrt(totalEta2 - totalEta*totalEta);
140 totalPhi2W =
std::sqrt(totalPhi2W - totalPhiW*totalPhi2);
141 totalEta2W =
std::sqrt(totalEta2W - totalEtaW*totalEtaW);
142 totalEnergy /= rechits.size();
143 totalEnergy2 /= rechits.size();
144 totalEnergy2 =
std::sqrt(totalEnergy2 - totalEnergy*totalEnergy);
147 for(
const auto& itHPD : theHPDs ) {
148 int hpdN = itHPD.first;
149 const std::vector<unsigned>& hpdHits = itHPD.second;
150 if( (
std::abs(hpdN) < 100 && hpdHits.size() > 14 ) ||
151 (
std::abs(hpdN) > 100 && hpdHits.size() > 14 ) ) ++nHPD15;
156 for(
const auto& itEn : theEnergies ) {
159 mask[itEn.second] =
false;
160 }
else if ( nn == 5 ) {
161 threshold = itEn.first*5;
162 mask[itEn.second] =
false;
164 if( itEn.first < threshold ) mask[itEn.second] =
false;
173 std::unordered_map<int,std::vector<unsigned> >::iterator neighbour1;
174 std::unordered_map<int,std::vector<unsigned> >::iterator neighbour2;
175 std::unordered_map<int,std::vector<unsigned> >::iterator neighbour0;
176 std::unordered_map<int,std::vector<unsigned> >::iterator neighbour3;
177 unsigned size1 = 0, size2 = 0;
178 for(
const auto& ithpd :
_hpds ) {
179 const std::vector<unsigned>&
rechits = ithpd.second;
183 for(
const unsigned rhidx : rechits ) {
185 const double e = rechit.
energy();
188 theEnergies.emplace(rechit.
energy(),rhidx);
190 totalEnergy /= rechits.size();
191 totalEnergy2 /= rechits.size();
192 totalEnergy2 =
std::sqrt(totalEnergy2 - totalEnergy*totalEnergy);
194 const int thehpd = ithpd.first;
197 neighbour1 = ( thehpd > 0 ? _hpds.find(72) : _hpds.find(-72) );
200 neighbour2 = ( thehpd > 0 ? _hpds.find(1) : _hpds.find(-1) );
203 neighbour1 = ( thehpd > 0 ? _hpds.find(136) : _hpds.find(-136) );
206 neighbour2 = ( thehpd > 0 ? _hpds.find(101) : _hpds.find(-101) );
209 neighbour1 = ( thehpd > 0 ? _hpds.find(thehpd-1) : _hpds.find(thehpd+1) );
210 neighbour2 = ( thehpd > 0 ? _hpds.find(thehpd+1) : _hpds.find(thehpd-1) );
213 if( neighbour1 != _hpds.end() ) {
214 const int nb1 = neighbour1->first;
217 neighbour0 = ( nb1 > 0 ? _hpds.find(72) : _hpds.find(-72) );
220 neighbour0 = ( nb1 > 0 ? _hpds.find(136) : _hpds.find(-136) );
223 neighbour0 = ( nb1 > 0 ? _hpds.find(nb1-1) : _hpds.find(nb1+1) );
227 neighbour0 = _hpds.end();
230 if( neighbour2 != _hpds.end() ) {
231 const int nb2 = neighbour2->first;
234 neighbour3 = ( nb2 > 0 ? _hpds.find(1) : _hpds.find(-1) );
237 neighbour3 = ( nb2 > 0 ? _hpds.find(101) : _hpds.find(-101) );
240 neighbour3 = ( nb2 > 0 ? _hpds.find(nb2+1) : _hpds.find(nb2-1) );
244 neighbour3 = _hpds.end();
247 size1 = neighbour1 != _hpds.end() ? neighbour1->second.size() : 0;
248 size2 = neighbour2 != _hpds.end() ? neighbour2->second.size() : 0;
250 if ( (
abs(neighbour1->first) > 100 && neighbour1->second.size() > 15 ) ||
251 (
abs(neighbour1->first) < 100 && neighbour1->second.size() > 12 ) )
252 size1 = neighbour0 != _hpds.end() ? neighbour0->second.size() : 0;
255 if ( (
abs(neighbour2->first) > 100 && neighbour2->second.size() > 15 ) ||
256 (
abs(neighbour2->first) < 100 && neighbour2->second.size() > 12 ) )
257 size2 = neighbour3 != _hpds.end() ? neighbour3->second.size() : 0;
259 if( (
std::abs(ithpd.first) > 100 && ithpd.second.size() > 15 ) ||
260 (
std::abs(ithpd.first) < 100 && ithpd.second.size() > 12 ) ) {
261 if( (
double)(size1+size2)/(
float)ithpd.second.size() < 1.0 ) {
264 for(
const auto& itEn : theEnergies ) {
266 mask[itEn.second] =
false;
267 }
else if ( nn == 5 ) {
268 threshold = itEn.first*2.5;
269 mask[itEn.second] =
false;
271 if( itEn.first < threshold ) mask[itEn.second] =
false;
unsigned detId() const
rechit detId
Geom::Phi< T > phi() const
void clean(const edm::Handle< reco::PFRecHitCollection > &input, std::vector< bool > &mask)
PositionType const & position() const
rechit cell centre x, y, z
static std::string const input
PFLayer::Layer layer() const
rechit layer
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
int ieta() const
get the cell ieta
Abs< T >::type abs(const T &t)
float energy() const
rechit energy
std::unordered_map< int, std::vector< unsigned > > _hpds
std::unordered_map< int, std::vector< unsigned > > _rbxs
int iphi() const
get the cell iphi
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
Neighbours neighbours4() const