45 conf_(conf), bufferAlreadySet(
false), theNumOfRows(0), theNumOfCols(0), detid_(0)
49 conf_.getParameter<
int>(
"ChannelThreshold");
51 conf_.getParameter<
int>(
"SeedThreshold");
53 conf_.getParameter<
double>(
"ClusterThreshold");
55 conf_.getParameter<
int>(
"VCaltoElectronGain");
57 conf_.getParameter<
int>(
"VCaltoElectronOffset");
58 if ( conf_.exists(
"AdcFullScaleStack") ) theStackADC_=conf_.getParameter<
int>(
"AdcFullScaleStack");
61 if ( conf_.exists(
"FirstStackLayer") ) theFirstStack_=conf_.getParameter<
int>(
"FirstStackLayer");
66 doMissCalibrate=conf_.getUntrackedParameter<
bool>(
"MissCalibrate",
true);
67 doSplitClusters = conf.
getParameter<
bool>(
"SplitClusters");
68 theBuffer.setSize( theNumOfRows, theNumOfCols );
83 int nrows = topol.
nrows();
89 if ( nrows > theBuffer.rows() ||
90 ncols > theBuffer.columns() )
98 theBuffer.setSize(nrows,ncols);
99 bufferAlreadySet =
true;
113 const std::vector<short>& badChannels,
123 if ( !
setup(pixDet) )
126 detid_ = input.
detId();
130 copy_to_buffer(begin, end);
140 for (
unsigned int i = 0;
i < theSeeds.size();
i++)
145 if ( theBuffer(theSeeds[
i]) >= theSeedThreshold )
152 if ( cluster.
charge() >= theClusterThreshold)
164 clear_buffer(begin, end);
181 theBuffer.set_adc( di->row(), di->column(), 0 );
196 if ( doMissCalibrate ) {
197 (*theSiPixelGainCalibrationService_).calibrate(detid_,begin,end,theConversionFactor, theOffset,electron);
202 auto adc = di->adc();
203 const float gain = 135.;
205 electron[
i] = int(
adc * gain + pedestal);
206 if (layer>=theFirstStack_) {
207 if (theStackADC_==1&&
adc==1) {
208 electron[
i] = int(255*135);
210 if (theStackADC_>1&&theStackADC_!=255&&
adc>=1){
211 const float gain = 135.;
212 electron[
i] = int((
adc-1) * gain * 255/
float(theStackADC_-1));
217 assert(i==(end-begin));
221 #ifdef PIXELREGRESSION
226 int col = di->column();
227 int adc = electron[i++];
228 #ifdef PIXELREGRESSION
229 int adcOld = calibrate(di->adc(),
col,row);
231 if (adc!=adcOld)
std::cout <<
"VI " << eqD <<
' '<< ic <<
' '<< end-begin <<
' '<< i <<
' '<< di->adc() <<
' ' << adc <<
' '<< adcOld << std::endl;
else ++eqD;
233 if ( adc >= thePixelThreshold) {
234 theBuffer.set_adc( row, col, adc);
238 assert(i==(end-begin));
251 if ( doMissCalibrate )
255 if ( !theSiPixelGainCalibrationService_->isDead(detid_,col,row) &&
256 !theSiPixelGainCalibrationService_->isNoisy(detid_,col,row) )
267 float DBgain = theSiPixelGainCalibrationService_->getGain(detid_, col, row);
268 float DBpedestal = theSiPixelGainCalibrationService_->getPedestal(detid_, col, row) * DBgain;
275 float vcal = adc * DBgain - DBpedestal;
290 electrons = int( vcal * theConversionFactor + theOffset);
296 const float gain = 135.;
298 electrons = int(adc * gain + pedestal);
299 if (layer>=theFirstStack_) {
300 if (theStackADC_==1&&adc==1)
302 electrons = int(255*135);
304 if (theStackADC_>1&&theStackADC_!=255&&adc>=1)
306 const float gain = 135.;
307 electrons = int((adc-1) * gain * 255/
float(theStackADC_-1));
318 struct AccretionCluster {
319 typedef unsigned short UShort;
326 unsigned int isize=0;
330 UShort
top()
const {
return curr;}
331 void pop() { ++curr;}
332 bool empty() {
return curr==isize;}
335 if (isize==MAXSIZE)
return false;
357 stack<SiPixelCluster::PixelPos, vector<SiPixelCluster::PixelPos> > dead_pixel_stack;
376 seed_adc = theBuffer(pix.
row(), pix.
col());
377 theBuffer.set_adc( pix, 1);
380 AccretionCluster acluster;
381 acluster.add(pix, seed_adc);
384 bool dead_flag =
false;
385 while ( ! acluster.empty())
388 auto curInd = acluster.top(); acluster.pop();
389 for (
auto c =
std::max(0,
int(acluster.y[curInd])-1);
c <
std::min(
int(acluster.y[curInd])+2,theBuffer.columns()) ; ++
c) {
390 for (
auto r =
std::max(0,
int(acluster.x[curInd])-1);
r <
std::min(
int(acluster.x[curInd])+2,theBuffer.rows()); ++
r) {
391 if ( theBuffer(
r,
c) >= thePixelThreshold) {
393 if (!acluster.add( newpix, theBuffer(
r,
c)))
goto endClus;
394 theBuffer.set_adc( newpix, 1);
429 SiPixelCluster cluster(acluster.isize,acluster.adc, acluster.x,acluster.y, acluster.xmin,acluster.ymin);
432 if (dead_flag && doSplitClusters)
436 bool have_second_cluster =
false;
437 while ( !dead_pixel_stack.empty() )
441 theBuffer.set_adc(deadpix, 1);
447 if ( second_cluster.
charge() >= theClusterThreshold &&
448 first_cluster.
charge() >= theClusterThreshold )
451 have_second_cluster =
true;
456 const std::vector<SiPixelCluster::Pixel>& branch_pixels = second_cluster.
pixels();
457 for (
unsigned int i = 0;
i<branch_pixels.size();
i++)
459 int temp_x = branch_pixels[
i].x;
460 int temp_y = branch_pixels[
i].y;
461 int temp_adc = branch_pixels[
i].adc;
463 cluster.
add(newpix, temp_adc);}
467 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.