46 conf_(conf), bufferAlreadySet(
false), theNumOfRows(0), theNumOfCols(0), detid_(0)
50 conf_.getParameter<
int>(
"ChannelThreshold");
52 conf_.getParameter<
int>(
"SeedThreshold");
54 conf_.getParameter<
double>(
"ClusterThreshold");
56 conf_.getParameter<
int>(
"VCaltoElectronGain");
58 conf_.getParameter<
int>(
"VCaltoElectronOffset");
59 if ( conf_.exists(
"AdcFullScaleStack") ) theStackADC_=conf_.getParameter<
int>(
"AdcFullScaleStack");
62 if ( conf_.exists(
"FirstStackLayer") ) theFirstStack_=conf_.getParameter<
int>(
"FirstStackLayer");
67 doMissCalibrate=conf_.getUntrackedParameter<
bool>(
"MissCalibrate",
true);
68 doSplitClusters = conf.
getParameter<
bool>(
"SplitClusters");
69 theBuffer.setSize( theNumOfRows, theNumOfCols );
84 int nrows = topol.
nrows();
90 if ( nrows > theBuffer.rows() ||
91 ncols > theBuffer.columns() )
99 theBuffer.setSize(nrows,ncols);
100 bufferAlreadySet =
true;
114 const std::vector<short>& badChannels,
124 if ( !
setup(pixDet) )
127 detid_ = input.
detId();
131 copy_to_buffer(begin, end);
135 for (
unsigned int i = 0;
i < theSeeds.size();
i++)
140 if ( theBuffer(theSeeds[
i]) >= theSeedThreshold )
147 if ( cluster.
charge() >= theClusterThreshold)
159 clear_buffer(begin, end);
176 theBuffer.set_adc( di->row(), di->column(), 0 );
185 #ifdef PIXELREGRESSION
186 static std::atomic<int> s_ic=0;
193 if ( doMissCalibrate ) {
194 (*theSiPixelGainCalibrationService_).calibrate(detid_,begin,end,theConversionFactor, theOffset,electron);
199 auto adc = di->adc();
200 const float gain = 135.;
202 electron[
i] = int(
adc * gain + pedestal);
203 if (layer>=theFirstStack_) {
204 if (theStackADC_==1&&
adc==1) {
205 electron[
i] = int(255*135);
207 if (theStackADC_>1&&theStackADC_!=255&&
adc>=1){
208 const float gain = 135.;
209 electron[
i] = int((
adc-1) * gain * 255/
float(theStackADC_-1));
214 assert(i==(end-begin));
218 #ifdef PIXELREGRESSION
219 static std::atomic<int> eqD=0;
223 int col = di->column();
224 int adc = electron[i++];
225 #ifdef PIXELREGRESSION
226 int adcOld = calibrate(di->adc(),
col,row);
228 if (adc!=adcOld)
std::cout <<
"VI " << eqD <<
' '<< ic <<
' '<< end-begin <<
' '<< i <<
' '<< di->adc() <<
' ' << adc <<
' '<< adcOld << std::endl;
else ++eqD;
230 if ( adc >= thePixelThreshold) {
231 theBuffer.set_adc( row, col, adc);
235 assert(i==(end-begin));
248 if ( doMissCalibrate )
252 if ( !theSiPixelGainCalibrationService_->isDead(detid_,col,row) &&
253 !theSiPixelGainCalibrationService_->isNoisy(detid_,col,row) )
264 float DBgain = theSiPixelGainCalibrationService_->getGain(detid_, col, row);
265 float DBpedestal = theSiPixelGainCalibrationService_->getPedestal(detid_, col, row) * DBgain;
272 float vcal = adc * DBgain - DBpedestal;
287 electrons = int( vcal * theConversionFactor + theOffset);
293 const float gain = 135.;
295 electrons = int(adc * gain + pedestal);
296 if (layer>=theFirstStack_) {
297 if (theStackADC_==1&&adc==1)
299 electrons = int(255*135);
301 if (theStackADC_>1&&theStackADC_!=255&&adc>=1)
303 const float gain = 135.;
304 electrons = int((adc-1) * gain * 255/
float(theStackADC_-1));
315 struct AccretionCluster {
316 typedef unsigned short UShort;
323 unsigned int isize=0;
327 UShort top()
const {
return curr;}
328 void pop() { ++curr;}
329 bool empty() {
return curr==isize;}
332 if (isize==MAXSIZE)
return false;
354 stack<SiPixelCluster::PixelPos, vector<SiPixelCluster::PixelPos> > dead_pixel_stack;
373 seed_adc = theBuffer(pix.
row(), pix.
col());
374 theBuffer.set_adc( pix, 1);
377 AccretionCluster acluster;
378 acluster.add(pix, seed_adc);
381 bool dead_flag =
false;
382 while ( ! acluster.empty())
385 auto curInd = acluster.top(); acluster.pop();
386 for (
auto c =
std::max(0,
int(acluster.y[curInd])-1);
c <
std::min(
int(acluster.y[curInd])+2,theBuffer.columns()) ; ++
c) {
387 for (
auto r =
std::max(0,
int(acluster.x[curInd])-1);
r <
std::min(
int(acluster.x[curInd])+2,theBuffer.rows()); ++
r) {
388 if ( theBuffer(
r,
c) >= thePixelThreshold) {
390 if (!acluster.add( newpix, theBuffer(
r,
c)))
goto endClus;
391 theBuffer.set_adc( newpix, 1);
426 SiPixelCluster cluster(acluster.isize,acluster.adc, acluster.x,acluster.y, acluster.xmin,acluster.ymin);
429 if (dead_flag && doSplitClusters)
433 bool have_second_cluster =
false;
434 while ( !dead_pixel_stack.empty() )
438 theBuffer.set_adc(deadpix, 1);
444 if ( second_cluster.
charge() >= theClusterThreshold &&
445 first_cluster.
charge() >= theClusterThreshold )
448 have_second_cluster =
true;
453 const std::vector<SiPixelCluster::Pixel>& branch_pixels = second_cluster.
pixels();
454 for (
unsigned int i = 0;
i<branch_pixels.size();
i++)
456 int temp_x = branch_pixels[
i].x;
457 int temp_y = branch_pixels[
i].y;
458 int temp_adc = branch_pixels[
i].adc;
460 cluster.
add(newpix, temp_adc);}
464 if ( first_cluster.
charge() >= theClusterThreshold && have_second_cluster)
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
void push_back(data_type const &d)
void clusterizeDetUnit(const edm::DetSet< PixelDigi > &input, const PixelGeomDetUnit *pixDet, const std::vector< short > &badChannels, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)
Cluster pixels. This method operates on a matrix of pixels and finds the largest contiguous cluster a...
PixelThresholdClusterizer(edm::ParameterSet const &conf)
det_id_type detId() const
SiPixelCluster make_cluster(const SiPixelCluster::PixelPos &pix, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)
The actual clustering algorithm: group the neighboring pixels around the seed.
virtual int ncolumns() const =0
virtual int nrows() const =0
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
unsigned int layer() const
layer id
static std::string const input
~PixelThresholdClusterizer()
edm::DetSet< PixelDigi >::const_iterator DigiIterator
void add(const PixelPos &pix, int adc)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
void clear_buffer(DigiIterator begin, DigiIterator end)
Clear the internal buffer array.
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
Pixel cluster – collection of neighboring pixels above threshold.
bool setup(const PixelGeomDetUnit *pixDet)
Private helper methods:
int calibrate(int adc, int col, int row)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
const std::vector< Pixel > pixels() const
void copy_to_buffer(DigiIterator begin, DigiIterator end)
Copy adc counts from PixelDigis into the buffer, identify seeds.