46 thePixelThreshold( conf.
getParameter<
int>(
"ChannelThreshold") ),
47 theSeedThreshold( conf.
getParameter<
int>(
"SeedThreshold") ),
48 theClusterThreshold( conf.
getParameter<
int>(
"ClusterThreshold") ),
49 theClusterThreshold_L1( conf.
getParameter<
int>(
"ClusterThreshold_L1") ),
50 theConversionFactor( conf.
getParameter<
int>(
"VCaltoElectronGain") ),
51 theConversionFactor_L1( conf.
getParameter<
int>(
"VCaltoElectronGain_L1") ),
52 theOffset( conf.
getParameter<
int>(
"VCaltoElectronOffset") ),
53 theOffset_L1( conf.
getParameter<
int>(
"VCaltoElectronOffset_L1") ),
54 theElectronPerADCGain( conf.
getParameter<
double>(
"ElectronPerADCGain") ),
55 doPhase2Calibration( conf.
getParameter<
bool>(
"Phase2Calibration") ),
56 thePhase2ReadoutMode( conf.
getParameter<
int>(
"Phase2ReadoutMode") ),
57 thePhase2DigiBaseline( conf.
getParameter<
double>(
"Phase2DigiBaseline") ),
58 thePhase2KinkADC( conf.
getParameter<
int>(
"Phase2KinkADC") ),
59 theNumOfRows(0), theNumOfCols(0), theDetid(0),
61 doMissCalibrate( conf.
getParameter<
bool>(
"MissCalibrate") ),
62 doSplitClusters( conf.
getParameter<
bool>(
"SplitClusters") )
64 theBuffer.setSize( theNumOfRows, theNumOfCols );
73 desc.
add<
int>(
"ChannelThreshold", 1000);
74 desc.
add<
bool>(
"MissCalibrate",
true);
75 desc.
add<
bool>(
"SplitClusters",
false);
76 desc.
add<
int>(
"VCaltoElectronGain", 65);
77 desc.
add<
int>(
"VCaltoElectronGain_L1", 65);
78 desc.
add<
int>(
"VCaltoElectronOffset", -414);
79 desc.
add<
int>(
"VCaltoElectronOffset_L1", -414);
80 desc.
add<
int>(
"SeedThreshold", 1000);
81 desc.
add<
int>(
"ClusterThreshold_L1", 4000);
82 desc.
add<
int>(
"ClusterThreshold", 4000);
83 desc.
add<
double>(
"ElectronPerADCGain", 135.);
84 desc.
add<
bool>(
"Phase2Calibration",
false);
85 desc.
add<
int>(
"Phase2ReadoutMode", -1);
86 desc.
add<
double>(
"Phase2DigiBaseline", 1200.);
87 desc.
add<
int>(
"Phase2KinkADC", 8);
100 int nrows = topol.
nrows();
103 theNumOfRows = nrows;
104 theNumOfCols =
ncols;
106 if ( nrows > theBuffer.rows() ||
107 ncols > theBuffer.columns() )
115 theBuffer.setSize(nrows,ncols);
131 const std::vector<short>& badChannels,
134 typename T::const_iterator
begin = input.begin();
135 typename T::const_iterator
end = input.end();
141 if ( !
setup(pixDet) )
144 theDetid = input.detId();
147 auto clusterThreshold = theClusterThreshold;
149 if (theLayer==1) clusterThreshold = theClusterThreshold_L1;
153 copy_to_buffer(begin, end);
155 assert(output.
empty());
158 for (
unsigned int i = 0;
i < theSeeds.size();
i++)
163 if ( theBuffer(theSeeds[
i]) >= theSeedThreshold )
170 if ( cluster.
charge() >= clusterThreshold)
186 clear_buffer(begin, end);
203 theBuffer.set_adc( di->row(), di->column(), 0 );
211 for(
int i = 0;
i < ci->size(); ++
i)
215 theBuffer.set_adc( pixel.
x, pixel.
y, 0 );
225 #ifdef PIXELREGRESSION 226 static std::atomic<int> s_ic=0;
233 memset(electron, 0,
sizeof(electron));
235 if (doPhase2Calibration) {
238 electron[
i] = calibrate(di->adc(), di->column(), di->row());
241 assert(i==(end-begin));
245 if ( doMissCalibrate ) {
247 (*theSiPixelGainCalibrationService_).calibrate(theDetid,begin,end,theConversionFactor_L1, theOffset_L1,electron);
249 (*theSiPixelGainCalibrationService_).calibrate(theDetid,begin,end,theConversionFactor, theOffset, electron);
253 const float gain = theElectronPerADCGain;
255 auto adc = di->adc();
257 electron[
i] =
int(
adc * gain + pedestal);
260 assert(i==(end-begin));
265 #ifdef PIXELREGRESSION 266 static std::atomic<int> eqD=0;
270 int col = di->column();
271 int adc = electron[i++];
273 #ifdef PIXELREGRESSION 274 int adcOld = calibrate(di->adc(),
col,row);
276 if (adc!=adcOld)
std::cout <<
"VI " << eqD <<
' '<< ic <<
' '<< end-begin <<
' '<< i <<
' '<< di->adc() <<
' ' << adc <<
' '<< adcOld << std::endl;
else ++eqD;
284 if ( adc >= thePixelThreshold) {
285 theBuffer.set_adc( row, col, adc);
289 assert(i==(end-begin));
298 for(
int i = 0;
i < ci->size(); ++
i) {
304 if ( adc >= thePixelThreshold) {
305 theBuffer.add_adc( row, col, adc);
319 if (doPhase2Calibration) {
321 const float gain = theElectronPerADCGain;
322 int p2rm = (thePhase2ReadoutMode < -1 ? -1 : thePhase2ReadoutMode);
325 electrons =
int(adc * gain);
328 if (adc < thePhase2KinkADC) {
329 electrons =
int((adc - 0.5) * gain);
332 const int dualslopeparam = (thePhase2ReadoutMode < 10 ? thePhase2ReadoutMode : 10);
333 const int dualslope =
int(dualslopeparam <= 1 ? 1. :
pow(2, dualslopeparam-1));
334 adc -= (thePhase2KinkADC-1);
336 adc += (thePhase2KinkADC-1);
337 electrons =
int((adc - 0.5 * dualslope) * gain);
339 electrons +=
int(thePhase2DigiBaseline);
346 if ( doMissCalibrate )
350 if ( !theSiPixelGainCalibrationService_->isDead(theDetid,col,row) &&
351 !theSiPixelGainCalibrationService_->isNoisy(theDetid,col,row) )
362 float DBgain = theSiPixelGainCalibrationService_->getGain(theDetid, col, row);
363 float pedestal = theSiPixelGainCalibrationService_->getPedestal(theDetid, col, row);
364 float DBpedestal = pedestal * DBgain;
370 float vcal = adc * DBgain - DBpedestal;
386 electrons =
int( vcal * theConversionFactor_L1 + theOffset_L1);
388 electrons =
int( vcal * theConversionFactor + theOffset);
396 const float gain = theElectronPerADCGain;
398 electrons =
int(adc * gain + pedestal);
414 stack<SiPixelCluster::PixelPos, vector<SiPixelCluster::PixelPos> > dead_pixel_stack;
433 seed_adc = theBuffer(pix.
row(), pix.
col());
434 theBuffer.set_adc( pix, 1);
438 acluster.
add(pix, seed_adc);
441 bool dead_flag =
false;
442 while ( ! acluster.
empty())
445 auto curInd = acluster.
top(); acluster.
pop();
446 for (
auto c =
std::max(0,
int(acluster.
y[curInd])-1);
c <
std::min(
int(acluster.
y[curInd])+2,theBuffer.columns()) ; ++
c) {
447 for (
auto r =
std::max(0,
int(acluster.
x[curInd])-1);
r <
std::min(
int(acluster.
x[curInd])+2,theBuffer.rows()); ++
r) {
448 if ( theBuffer(
r,
c) >= thePixelThreshold) {
450 if (!acluster.
add( newpix, theBuffer(
r,
c)))
goto endClus;
451 theBuffer.set_adc( newpix, 1);
489 if (dead_flag && doSplitClusters)
492 auto clusterThreshold = theClusterThreshold;
493 if (theLayer==1) clusterThreshold = theClusterThreshold_L1;
497 bool have_second_cluster =
false;
498 while ( !dead_pixel_stack.empty() )
502 theBuffer.set_adc(deadpix, 1);
508 if ( second_cluster.
charge() >= clusterThreshold &&
509 first_cluster.
charge() >= clusterThreshold )
512 have_second_cluster =
true;
517 const std::vector<SiPixelCluster::Pixel>& branch_pixels = second_cluster.
pixels();
518 for (
unsigned int i = 0;
i<branch_pixels.size();
i++)
520 int temp_x = branch_pixels[
i].x;
521 int temp_y = branch_pixels[
i].y;
522 int temp_adc = branch_pixels[
i].adc;
524 cluster.
add(newpix, temp_adc);}
528 if ( first_cluster.
charge() >= clusterThreshold && have_second_cluster)
void clusterizeDetUnitT(const T &input, const PixelGeomDetUnit *pixDet, const TrackerTopology *tTopo, 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...
T getParameter(std::string const &) const
void push_back(data_type const &d)
virtual int nrows() const =0
static void fillPSetDescription(edm::ParameterSetDescription &desc)
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.
def setup(process, global_tag, zero_tesla=False)
static std::string const input
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
edm::DetSet< PixelDigi >::const_iterator DigiIterator
void add(const PixelPos &pix, int adc)
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool add(SiPixelCluster::PixelPos const &p, UShort const iadc)
constexpr int col() const
unsigned int pxbLayer(const DetId &id) 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:
~PixelThresholdClusterizer() override
int calibrate(int adc, int col, int row)
Power< A, B >::type pow(const A &a, const B &b)
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.