35 float expectedADC,
int sizeY,
int sizeX,
float jetZOverRho);
37 float expectedADC,
int sizeY,
38 int sizeX,
float jetZOverRho,
39 unsigned int nSplitted);
41 const std::vector<float>& distanceMap);
43 const std::vector<std::vector<float> >& distanceMap);
45 const std::vector<std::vector<float> >& distanceMap);
47 const std::vector<std::vector<float> >& distanceMap);
66 ptMin_(iConfig.getParameter<double>(
"ptMin")),
67 deltaR_(iConfig.getParameter<double>(
"deltaRmax")),
70 iConfig.getParameter<
edm::InputTag>(
"pixelClusters"))),
72 iConfig.getParameter<
edm::InputTag>(
"vertices"))),
74 iConfig.getParameter<
edm::InputTag>(
"cores"))),
75 forceXError_(iConfig.getParameter<double>(
"forceXError")),
76 forceYError_(iConfig.getParameter<double>(
"forceYError")),
82 produces<edmNew::DetSetVector<SiPixelCluster> >();
113 auto output = std::make_unique<edmNew::DetSetVector<SiPixelCluster>>();
116 inputPixelClusters->begin();
117 for (; detIt != inputPixelClusters->end(); detIt++) {
122 for (
auto cluster = detset.
begin();
123 cluster != detset.
end(); cluster++) {
125 bool hasBeenSplit =
false;
126 bool shouldBeSplit =
false;
132 for (
unsigned int ji = 0; ji < cores->size(); ji++) {
133 if ((*cores)[ji].pt() >
ptMin_) {
145 std::sqrt((1.3
f*1.3
f) + (1.9f*1.9f) * jetZOverRho*jetZOverRho);
146 if (expSizeY < 1.f) expSizeY = 1.f;
147 float expSizeX = 1.5f;
156 (aCluster.
sizeX() > expSizeX + 1 ||
157 aCluster.
sizeY() > expSizeY + 1)) {
158 shouldBeSplit =
true;
160 std::cout <<
"Trying to split: charge and deltaR " 161 << aCluster.
charge() <<
" " 163 << aCluster.
sizeX() <<
" " << aCluster.
sizeY()
164 <<
" exp. size (x,y) " 165 << expSizeX <<
" " << expSizeY
166 <<
" detid " << detIt->id() << std::endl;
168 std::cout <<
"jetZOverRho=" << jetZOverRho << std::endl;
170 if (
split(aCluster,
filler, expCharge, expSizeY, expSizeX,
206 std::vector<SiPixelCluster> sp =
207 fittingSplit(aCluster, expectedADC, sizeY, sizeX, jetZOverRho,
208 std::floor(aCluster.
charge() / expectedADC + 0.5f));
211 for (
unsigned int i = 0;
i < sp.size();
i++) {
213 std::push_heap(filler.
begin(),filler.
end(),
217 return (!sp.empty());
222 const std::vector<float>& distanceMap) {
225 for (
unsigned int i = 0;
i < distanceMap.size();
i++) {
226 float dist = distanceMap[
i];
227 if (dist < minDist) {
228 secondMinDist = minDist;
230 }
else if (dist < secondMinDist) {
231 secondMinDist = dist;
234 return std::pair<float, float>(minDist, secondMinDist);
238 const std::vector<std::vector<float> >& distanceMap) {
239 std::multimap<float, int> scores;
240 for (
unsigned int j = 0; j < distanceMap.size(); j++) {
242 scores.insert(std::pair<float, int>(d.second - d.first, j));
248 const std::vector<std::vector<float> >& distanceMap) {
249 std::multimap<float, int> scores;
250 for (
unsigned int j = 0; j < distanceMap.size(); j++) {
252 scores.insert(std::pair<float, int>(-d.second, j));
258 const std::vector<std::vector<float> >& distanceMap) {
259 std::multimap<float, int> scores;
260 for (
unsigned int j = 0; j < distanceMap.size(); j++) {
262 scores.insert(std::pair<float, int>(-d.first, j));
269 float jetZOverRho,
unsigned int nSplitted) {
270 std::vector<SiPixelCluster>
output;
272 unsigned int meanExp = nSplitted;
274 output.push_back(aCluster);
278 std::vector<float> clx(meanExp);
279 std::vector<float> cly(meanExp);
280 std::vector<float> cls(meanExp);
281 std::vector<float> oldclx(meanExp);
282 std::vector<float> oldcly(meanExp);
283 std::vector<SiPixelCluster::Pixel> originalpixels = aCluster.
pixels();
284 std::vector<std::pair<int, SiPixelCluster::Pixel> > pixels;
285 for (
unsigned int j = 0; j < originalpixels.size(); j++) {
288 if (sub < 1) sub = 1;
289 int perDiv = originalpixels[j].adc / sub;
291 std::cout <<
"Splitting " << j <<
" in [ " << pixels.size() <<
" , " 292 << pixels.size() + sub <<
" ], expected numb of clusters: " 293 << meanExp <<
" original pixel (x,y) " 294 << originalpixels[j].x <<
" " << originalpixels[j].y
295 <<
" sub " << sub << std::endl;
296 for (
int k = 0;
k < sub;
k++) {
297 if (
k == sub - 1) perDiv = originalpixels[j].adc - perDiv *
k;
299 originalpixels[j].
y, perDiv)));
302 std::vector<int> clusterForPixel(pixels.size());
304 for (
unsigned int j = 0; j < meanExp; j++) {
307 clx[j] = originalpixels[0].x + j;
308 cly[j] = originalpixels[0].y + j;
312 int remainingSteps = 100;
313 while (!stop && remainingSteps > 0) {
316 std::vector<std::vector<float> > distanceMapX(originalpixels.size(),
317 std::vector<float>(meanExp));
318 std::vector<std::vector<float> > distanceMapY(originalpixels.size(),
319 std::vector<float>(meanExp));
320 std::vector<std::vector<float> > distanceMap(originalpixels.size(),
321 std::vector<float>(meanExp));
322 for (
unsigned int j = 0; j < originalpixels.size(); j++) {
324 std::cout <<
"Original Pixel pos " << j <<
" " << pixels[j].second.x <<
" " 325 << pixels[j].second.y << std::endl;
326 for (
unsigned int i = 0;
i < meanExp;
i++) {
327 distanceMapX[j][
i] = 1.f * originalpixels[j].x - clx[
i];
328 distanceMapY[j][
i] = 1.f * originalpixels[j].y - cly[
i];
331 if (
std::abs(distanceMapX[j][
i]) > sizeX/2.f) {
332 dist += (
std::abs(distanceMapX[j][i]) - sizeX/2.f + 1.f) *
333 (
std::abs(distanceMapX[j][i]) - sizeX/2.f + 1.f);
336 (2.f*distanceMapX[j][
i]/
sizeX)*(2.
f*distanceMapX[j][i]/sizeX);
339 if (
std::abs(distanceMapY[j][i]) > sizeY/2.f) {
340 dist += 1.f * (
std::abs(distanceMapY[j][i]) - sizeY/2.f + 1.f) *
341 (
std::abs(distanceMapY[j][i]) - sizeY/2.f + 1.f);
343 dist += 1.f * (2.f*distanceMapY[j][
i]/
sizeY) *
344 (2.
f*distanceMapY[j][i]/sizeY);
346 distanceMap[j][
i] =
sqrt(dist);
348 std::cout <<
"Cluster " << i <<
" Original Pixel " << j
349 <<
" distances: " << distanceMapX[j][
i] <<
" " 350 << distanceMapY[j][
i] <<
" " << distanceMap[j][
i]
357 std::multimap<float, int> scores;
364 std::vector<float> weightOfPixel(pixels.size());
365 for (std::multimap<float, int>::iterator it = scores.begin();
366 it != scores.end(); it++) {
367 int pixel_index = it->second;
369 std::cout <<
"Original Pixel " << pixel_index <<
" with score " << it->first << std::endl;
371 int subpixel_counter = 0;
372 for (
auto subpixel = pixels.begin(); subpixel != pixels.end();
373 ++subpixel, ++subpixel_counter) {
374 if (subpixel->first > pixel_index) {
376 }
else if (subpixel->first != pixel_index) {
381 for (
unsigned int subcluster_index = 0;
382 subcluster_index < meanExp; subcluster_index++) {
384 (cls[subcluster_index] - expectedADC) /
387 float clQest = 1.f / (1.f +
std::exp(nsig)) + 1
e-6
f;
388 float clDest = 1.f / (distanceMap[pixel_index][subcluster_index] + 0.05f);
391 std::cout <<
" Q: " << clQest <<
" D: " << clDest <<
" " 392 << distanceMap[pixel_index][subcluster_index] << std::endl;
393 float est = clQest * clDest;
395 cl = subcluster_index;
399 cls[
cl] += subpixel->second.adc;
400 clusterForPixel[subpixel_counter] =
cl;
401 weightOfPixel[subpixel_counter] = maxEst;
403 std::cout <<
"Pixel weight j cl " << weightOfPixel[subpixel_counter]
404 <<
" " << subpixel_counter
405 <<
" " << cl << std::endl;
411 for (
unsigned int subcluster_index = 0;
412 subcluster_index < meanExp; subcluster_index++) {
413 if (
std::abs(clx[subcluster_index] - oldclx[subcluster_index]) > 0.01f)
415 if (
std::abs(cly[subcluster_index] - oldcly[subcluster_index]) > 0.01f)
417 oldclx[subcluster_index] = clx[subcluster_index];
418 oldcly[subcluster_index] = cly[subcluster_index];
419 clx[subcluster_index] = 0;
420 cly[subcluster_index] = 0;
421 cls[subcluster_index] = 1
e-99;
423 for (
unsigned int pixel_index = 0;
424 pixel_index < pixels.size(); pixel_index++) {
425 if (clusterForPixel[pixel_index] < 0)
continue;
427 std::cout <<
"j " << pixel_index <<
" x " << pixels[pixel_index].second.x <<
" * y " 428 << pixels[pixel_index].second.y <<
" * ADC " 429 << pixels[pixel_index].second.adc <<
" * W " 430 << weightOfPixel[pixel_index] << std::endl;
431 clx[clusterForPixel[pixel_index]] += pixels[pixel_index].second.x * pixels[pixel_index].second.adc;
432 cly[clusterForPixel[pixel_index]] += pixels[pixel_index].second.y * pixels[pixel_index].second.adc;
433 cls[clusterForPixel[pixel_index]] += pixels[pixel_index].second.adc;
435 for (
unsigned int subcluster_index = 0;
436 subcluster_index < meanExp; subcluster_index++) {
437 if (cls[subcluster_index] != 0) {
438 clx[subcluster_index] /= cls[subcluster_index];
439 cly[subcluster_index] /= cls[subcluster_index];
442 std::cout <<
"Center for cluster " << subcluster_index <<
" x,y " 443 << clx[subcluster_index] <<
" " 444 << cly[subcluster_index] << std::endl;
445 cls[subcluster_index] = 0;
450 std::vector<std::vector<SiPixelCluster::Pixel> > pixelsForCl(meanExp);
451 for (
int cl = 0;
cl < (
int)meanExp;
cl++) {
452 for (
unsigned int j = 0; j < pixels.size(); j++) {
453 if (clusterForPixel[j] ==
cl and
454 pixels[j].
second.adc != 0) {
458 for (
unsigned int k = j + 1;
k < pixels.size();
k++) {
460 and pixels[
k].second.x == pixels[j].second.x
461 and pixels[
k].second.y == pixels[j].second.y
462 and clusterForPixel[
k] ==
cl) {
464 std::cout <<
"Resetting all sub-pixel for location " 465 << pixels[
k].second.x <<
", " << pixels[
k].second.y
466 <<
" at index " <<
k <<
" associated to cl " 467 << clusterForPixel[
k] << std::endl;
468 pixels[j].second.adc += pixels[
k].second.adc;
469 pixels[
k].second.adc = 0;
472 for (
unsigned int p = 0;
p < pixels.size(); ++
p)
474 std::cout <<
"index, x, y, ADC: " <<
p <<
", " 475 << pixels[
p].second.x <<
", " << pixels[
p].second.y
476 <<
", " << pixels[
p].second.adc
477 <<
" associated to cl " << clusterForPixel[
p] << std::endl
478 <<
"Adding pixel " << pixels[j].second.x <<
", " << pixels[j].second.y
479 <<
" to cluster " <<
cl << std::endl;
480 pixelsForCl[
cl].push_back(pixels[j].
second);
489 for (
int cl = 0;
cl < (
int)meanExp;
cl++) {
491 for (
unsigned int j = 0; j < pixelsForCl[
cl].size(); j++) {
493 pixelsForCl[cl][j].
y);
495 std::cout << pixelsForCl[
cl][j].x <<
"," << pixelsForCl[
cl][j].y <<
"|";
497 output.emplace_back(newpix, pixelsForCl[cl][j].
adc);
499 output.back().add(newpix, pixelsForCl[cl][j].
adc);
503 if (!pixelsForCl[cl].
empty()) {
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
void push_back(data_type const &d)
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
const_iterator end(bool update=false) const
virtual double pz() const =0
z coordinate of momentum vector
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void setSplitClusterErrorY(float erry)
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > pixelClusters_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
bool split(const SiPixelCluster &aCluster, edmNew::DetSetVector< SiPixelCluster >::FastFiller &filler, float expectedADC, int sizeY, int sizeX, float jetZOverRho)
std::vector< Vertex > VertexCollection
collection of Vertex objects
std::multimap< float, int > distScore(const std::vector< std::vector< float > > &distanceMap)
edm::EDGetTokenT< reco::VertexCollection > vertices_
id_type id(size_t cell) const
const Plane & surface() const
The nominal surface of the GeomDet.
const Point & position() const
position
edm::EDGetTokenT< edm::View< reco::Candidate > > cores_
U second(std::pair< T, U > const &p)
virtual double py() const =0
y coordinate of momentum vector
#define DEFINE_FWK_MODULE(type)
bool SortPixels(const SiPixelCluster::Pixel &i, const SiPixelCluster::Pixel &j)
std::vector< SiPixelCluster > fittingSplit(const SiPixelCluster &aCluster, float expectedADC, int sizeY, int sizeX, float jetZOverRho, unsigned int nSplitted)
Abs< T >::type abs(const T &t)
JetCoreClusterSplitter(const edm::ParameterSet &iConfig)
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
virtual VLocalValues localParametersV(const SiPixelCluster &cluster, const GeomDetUnit &gd) const
void setSplitClusterErrorX(float errx)
std::pair< float, float > closestClusters(const std::vector< float > &distanceMap)
const GeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual Vector momentum() const =0
spatial momentum vector
ESHandle< TrackerGeometry > geometry
Pixel cluster – collection of neighboring pixels above threshold.
const GeomDet * idToDet(DetId) const override
std::multimap< float, int > secondDistDiffScore(const std::vector< std::vector< float > > &distanceMap)
virtual double px() const =0
x coordinate of momentum vector
std::multimap< float, int > secondDistScore(const std::vector< std::vector< float > > &distanceMap)
T const * product() const
const std::vector< Pixel > pixels() const
const_iterator begin(bool update=false) const
~JetCoreClusterSplitter() override