46 bufferAlreadySet(
false),
48 thePixelThreshold( conf.
getParameter<
int>(
"ChannelThreshold") ),
49 theSeedThreshold( conf.
getParameter<
int>(
"SeedThreshold") ),
50 theClusterThreshold( conf.
getParameter<
double>(
"ClusterThreshold") ),
51 theConversionFactor( conf.
getParameter<
int>(
"VCaltoElectronGain") ),
52 theOffset( conf.
getParameter<
int>(
"VCaltoElectronOffset") ),
53 theStackADC_( conf.
exists(
"AdcFullScaleStack") ? conf.
getParameter<
int>(
"AdcFullScaleStack") : 255 ),
54 theFirstStack_( conf.
exists(
"FirstStackLayer") ? conf.
getParameter<
int>(
"FirstStackLayer") : 5 ),
55 theElectronPerADCGain_( conf.
exists(
"ElectronPerADCGain") ? conf.
getParameter<
double>(
"ElectronPerADCGain") : 135. ),
56 theNumOfRows(0), theNumOfCols(0), detid_(0),
59 doSplitClusters( conf.
getParameter<
bool>(
"SplitClusters") )
61 theBuffer.setSize( theNumOfRows, theNumOfCols );
76 int nrows = topol.
nrows();
82 if ( nrows > theBuffer.rows() ||
83 ncols > theBuffer.columns() )
91 theBuffer.setSize(nrows,ncols);
92 bufferAlreadySet =
true;
107 const std::vector<short>& badChannels,
110 typename T::const_iterator
begin = input.begin();
111 typename T::const_iterator
end = input.end();
117 if ( !
setup(pixDet) )
120 detid_ = input.detId();
124 copy_to_buffer(begin, end);
128 for (
unsigned int i = 0;
i < theSeeds.size();
i++)
133 if ( theBuffer(theSeeds[
i]) >= theSeedThreshold )
140 if ( cluster.
charge() >= theClusterThreshold)
152 clear_buffer(begin, end);
169 theBuffer.set_adc( di->row(), di->column(), 0 );
177 for(
int i = 0;
i < ci->size(); ++
i)
181 theBuffer.set_adc( pixel.
x, pixel.
y, 0 );
191 #ifdef PIXELREGRESSION 192 static std::atomic<int> s_ic=0;
199 memset(electron, 0,
sizeof(electron));
200 if ( doMissCalibrate ) {
201 (*theSiPixelGainCalibrationService_).calibrate(detid_,begin,end,theConversionFactor, theOffset,electron);
206 auto adc = di->adc();
207 const float gain = theElectronPerADCGain_;
209 electron[
i] =
int(
adc * gain + pedestal);
210 if (layer>=theFirstStack_) {
211 if (theStackADC_==1&&
adc==1) {
212 electron[
i] =
int(255*135);
214 if (theStackADC_>1&&theStackADC_!=255&&
adc>=1){
215 const float gain = theElectronPerADCGain_;
216 electron[
i] =
int((
adc-1) * gain * 255/
float(theStackADC_-1));
221 assert(i==(end-begin));
225 #ifdef PIXELREGRESSION 226 static std::atomic<int> eqD=0;
230 int col = di->column();
231 int adc = electron[i++];
232 #ifdef PIXELREGRESSION 233 int adcOld = calibrate(di->adc(),
col,row);
235 if (adc!=adcOld)
std::cout <<
"VI " << eqD <<
' '<< ic <<
' '<< end-begin <<
' '<< i <<
' '<< di->adc() <<
' ' << adc <<
' '<< adcOld << std::endl;
else ++eqD;
237 if ( adc >= thePixelThreshold) {
238 theBuffer.set_adc( row, col, adc);
242 assert(i==(end-begin));
251 for(
int i = 0;
i < ci->size(); ++
i) {
257 if ( adc >= thePixelThreshold) {
258 theBuffer.add_adc( row, col, adc);
274 if ( doMissCalibrate )
278 if ( !theSiPixelGainCalibrationService_->isDead(detid_,col,row) &&
279 !theSiPixelGainCalibrationService_->isNoisy(detid_,col,row) )
290 float DBgain = theSiPixelGainCalibrationService_->getGain(detid_, col, row);
291 float DBpedestal = theSiPixelGainCalibrationService_->getPedestal(detid_, col, row) * DBgain;
298 float vcal = adc * DBgain - DBpedestal;
313 electrons =
int( vcal * theConversionFactor + theOffset);
319 const float gain = theElectronPerADCGain_;
321 electrons =
int(adc * gain + pedestal);
322 if (layer>=theFirstStack_) {
323 if (theStackADC_==1&&adc==1)
325 electrons =
int(255*135);
327 if (theStackADC_>1&&theStackADC_!=255&&adc>=1)
329 const float gain = theElectronPerADCGain_;
330 electrons =
int((adc-1) * gain * 255/
float(theStackADC_-1));
348 stack<SiPixelCluster::PixelPos, vector<SiPixelCluster::PixelPos> > dead_pixel_stack;
367 seed_adc = theBuffer(pix.
row(), pix.
col());
368 theBuffer.set_adc( pix, 1);
372 acluster.
add(pix, seed_adc);
375 bool dead_flag =
false;
376 while ( ! acluster.
empty())
379 auto curInd = acluster.
top(); acluster.
pop();
380 for (
auto c =
std::max(0,
int(acluster.
y[curInd])-1);
c <
std::min(
int(acluster.
y[curInd])+2,theBuffer.columns()) ; ++
c) {
381 for (
auto r =
std::max(0,
int(acluster.
x[curInd])-1);
r <
std::min(
int(acluster.
x[curInd])+2,theBuffer.rows()); ++
r) {
382 if ( theBuffer(
r,
c) >= thePixelThreshold) {
384 if (!acluster.
add( newpix, theBuffer(
r,
c)))
goto endClus;
385 theBuffer.set_adc( newpix, 1);
423 if (dead_flag && doSplitClusters)
427 bool have_second_cluster =
false;
428 while ( !dead_pixel_stack.empty() )
432 theBuffer.set_adc(deadpix, 1);
438 if ( second_cluster.
charge() >= theClusterThreshold &&
439 first_cluster.
charge() >= theClusterThreshold )
442 have_second_cluster =
true;
447 const std::vector<SiPixelCluster::Pixel>& branch_pixels = second_cluster.
pixels();
448 for (
unsigned int i = 0;
i<branch_pixels.size();
i++)
450 int temp_x = branch_pixels[
i].x;
451 int temp_y = branch_pixels[
i].y;
452 int temp_adc = branch_pixels[
i].adc;
454 cluster.
add(newpix, temp_adc);}
458 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
T getUntrackedParameter(std::string const &, T const &) const
void push_back(data_type const &d)
virtual int nrows() const =0
PixelThresholdClusterizer(edm::ParameterSet const &conf)
SiPixelCluster make_cluster(const SiPixelCluster::PixelPos &pix, edmNew::DetSetVector< SiPixelCluster >::FastFiller &output)
The actual clustering algorithm: group the neighboring pixels around the seed.
bool exists(std::string const ¶meterName) const
checks if a parameter exists
def setup(process, global_tag, zero_tesla=False)
unsigned int layer() const
layer id
static std::string const input
void clusterizeDetUnitT(const T &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::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) ...
bool add(SiPixelCluster::PixelPos const &p, UShort const iadc)
constexpr int col() const
edmNew::DetSet< SiPixelCluster >::const_iterator ClusterIterator
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.
virtual int ncolumns() const =0
bool setup(const PixelGeomDetUnit *pixDet)
Private helper methods:
int calibrate(int adc, int col, int row)
constexpr int row() const
const std::vector< Pixel > pixels() const
void copy_to_buffer(DigiIterator begin, DigiIterator end)
Copy adc counts from PixelDigis into the buffer, identify seeds.