Skip to content

Instantly share code, notes, and snippets.

@betatim
Created August 12, 2013 12:21
Show Gist options
  • Save betatim/6210361 to your computer and use it in GitHub Desktop.
Save betatim/6210361 to your computer and use it in GitHub Desktop.
inline void channel_neighbours(const LHCb::VPChannelID& seedChannel,
Pix* adjecent,
std::bitset<9>& adjecent_set) {
// Loop over the possible positions in the 3x3 cluster
// around the seedChannel
int pixY = (seedChannel).pixel_hp();
int pixX = (seedChannel).pixel_lp();
int chip = (seedChannel).chip();
// hardcoded for the compact VP design
// number of chips in a ladder and
// number of pixels per chip
const int Nchips(3);
const int Npixels(256);
// this code assumes the six chips are numbered like this
// |-----|
// |0|1|2|
// |-----|
// |3|4|5|
// |-----|
// so 0 borders 1 and 1 borders 0 and 2, together they
// form a ladder, between 0 and 1 and between 1 and 2
// pixels on the edge are "long" pixels
double ypos(0.5);
for (int iy=-1; iy<2; iy++) {
double xpos(0.5);
for (int ix=-1; ix<2; ix++) {
// indecies of this pixel
int ix_ = pixX + ix;
int iy_ = pixY + iy;
// initial guess is that of the seed
int c(chip);
bool islong(false);
// fell off the side of the chip
if (ix_ < 0) {
// on the first chip of the ladder
// so there are no neighbours
if ((chip == 0) || (chip == 3)) {
continue;
}
// there is a neighbour
else {
c -= 1;
ix_ = Npixels-1;
}
}
else if (ix_ > Npixels-1) {
// on the last chip of the ladder
// so there are no neighbours
if ((chip == 2) || (chip == 5)) {
continue;
}
// there is a neighbour
else {
c += 1;
ix_ = 0;
}
}
// too low or too high in y
if ((iy_ < 0) || (iy_ >= Npixels)) {
continue;
}
// Figure out if it is a long pixel
if (((ix_ == 0) && (c%Nchips != 0)) ||
((ix_ == 255) && (c%Nchips != Nchips-1))) {
islong = true;
}
if (islong) {
xpos += 0.5;
}
const int idx = (ix+1) + 3*(iy+1);
LHCb::VPChannelID neig_channel(seedChannel);
neig_channel.setChip(c);
neig_channel.setPixel_lp(ix_);
neig_channel.setPixel_hp(iy_);
Pix neighbour;
neighbour.channel = neig_channel;
neighbour.x = xpos;
neighbour.y = ypos;
neighbour.islong = islong;
adjecent[idx] = neighbour;
adjecent_set.set(idx);
if (islong) {
xpos += 0.5;
}
xpos += 1.;
}
// after the x loop
ypos += 1.;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment