52 #include "TDirectory.h" 97 desc.setComment(
"EDAnalyzer to create SiPixelGainCalibration payloads by rejecting noisy and dead ones");
98 desc.addUntracked<
bool>(
"debug",
false);
99 desc.addUntracked<
int>(
"insertNoisyPixelsInDB", 1);
100 desc.addUntracked<
std::string>(
"record",
"SiPixelGainCalibrationOfflineRcd");
107 SiPixelGainCalibrationOfflineService_(iConfig, consumesCollector()),
108 SiPixelGainCalibrationForHLTService_(iConfig, consumesCollector()),
109 noisypixellist_(iConfig.getUntrackedParameter<
std::
string>(
"noisyPixelList",
"noisypixel.txt")),
110 insertnoisypixelsindb_(iConfig.getUntrackedParameter<
int>(
"insertNoisyPixelsInDB", 1)),
111 record_(iConfig.getUntrackedParameter<
std::
string>(
"record",
"SiPixelGainCalibrationOfflineRcd")),
128 <<
"=>=>=>=> Starting the function fillDatabase()" << endl;
130 if (
record_ !=
"SiPixelGainCalibrationOfflineRcd" &&
record_ !=
"SiPixelGainCalibrationForHLTRcd") {
132 <<
record_ <<
" : this record can't be used !" << std::endl;
134 <<
"Please select SiPixelGainCalibrationForHLTRcd or SiPixelGainCalibrationOfflineRcd" << std::endl;
139 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
141 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd")
146 edm::LogInfo(
"SiPixelCondObjOfflineBuilder") <<
" There are " << pDD->
dets().size() <<
" detectors" << std::endl;
148 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd") {
153 }
else if (
record_ ==
"SiPixelGainCalibrationForHLTRcd") {
169 <<
"New payload will have pedlow,hi " <<
pedlow_ <<
"," <<
pedhi_ <<
" and gainlow,hi " <<
gainlow_ <<
"," 171 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
174 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd")
184 bool willNoisyPixBeInserted;
188 willNoisyPixBeInserted =
false;
189 for (TrackerGeometry::DetContainer::const_iterator
mod = pDD->
dets().begin();
mod != pDD->
dets().end();
mod++) {
191 if (dynamic_cast<PixelGeomDetUnit const*>((*
mod)) !=
nullptr)
194 willNoisyPixBeInserted =
true;
198 if (!willNoisyPixBeInserted)
200 <<
"All Noisy Pixels in detid " <<
it->first
201 <<
"won't be inserted, check the TrackerGeometry you are using !! You are missing some modules" << endl;
205 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> Starting Loop over all modules" << endl;
208 for (TrackerGeometry::DetContainer::const_iterator
it = pDD->
dets().begin();
it != pDD->
dets().end();
it++) {
210 if (dynamic_cast<PixelGeomDetUnit const*>((*
it)) !=
nullptr)
216 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> We are in module " <<
detid << endl;
221 int nrows = topol.
nrows();
225 float gainforthiscol[2];
226 float pedforthiscol[2];
228 int nrowsrocsplit = 0;
229 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
231 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd")
234 std::vector<char> theSiPixelGainCalibrationGainPerColPedPerPixel;
235 std::vector<char> theSiPixelGainCalibrationPerCol;
238 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> Starting Loop for each rows/cols " << endl;
240 for (
int icol = 0; icol <=
ncols - 1; icol++) {
242 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> Starting a new column" << endl;
244 nusedrows[0] = nusedrows[1] = 0;
245 gainforthiscol[0] = gainforthiscol[1] = 0;
246 pedforthiscol[0] = pedforthiscol[1] = 0;
248 for (
int jrow = 0; jrow <= nrows - 1; jrow++) {
251 <<
"=>=>=>=> We are in col,row " << icol <<
"," << jrow << endl;
255 size_t iglobalrow = 0;
256 int noisyPixInRow = 0;
257 if (jrow > nrowsrocsplit) {
262 bool isPixelDeadOld =
false;
263 bool isColumnDeadOld =
false;
267 bool isPixelNoisyOld =
false;
268 bool isColumnNoisyOld =
false;
269 bool isPixelNoisyNew =
false;
270 bool isColumnNoisyNew =
false;
272 bool isColumnDead =
false;
273 bool isColumnNoisy =
false;
274 bool isPixelDead =
false;
275 bool isPixelNoisy =
false;
278 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> Trying to get gain/ped " << endl;
281 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd") {
287 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd") {
291 if (!isColumnDeadOld && !isColumnNoisyOld) {
292 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
294 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd") {
299 if (!isPixelDeadOld && !isPixelNoisyOld)
300 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
304 <<
"Problem trying to catch gain/ped from DETID " <<
detid <<
" @ col,row " << icol <<
"," << jrow
311 <<
"=>=>=>=> Found gain " << gainforthiscol[iglobalrow] <<
" and ped " << pedforthiscol[iglobalrow]
318 for (
unsigned int i = 0;
i < (
it->second).
size();
i++)
320 isPixelNoisyNew =
true;
322 isColumnDead = isColumnDeadOld;
323 isPixelDead = isPixelDeadOld;
327 if (noisyPixInRow == nrowsrocsplit)
328 isColumnNoisyNew =
true;
331 isColumnNoisy = isColumnNoisyOld;
332 isPixelNoisy = isPixelNoisyOld;
334 isPixelNoisy = isPixelNoisyNew;
335 isColumnNoisy = isColumnNoisyNew;
337 isPixelNoisy = isPixelNoisyNew || isPixelNoisyOld;
338 isColumnNoisy = isColumnNoisyNew || isColumnNoisyOld;
343 <<
"Inserting a noisy pixel in " <<
detid <<
" at col,row " << icol <<
"," << jrow << endl;
346 <<
"Inserting a noisy column in " <<
detid <<
" at col,row " << icol <<
"," << jrow << endl;
353 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> Now Starting to fill the DB" << endl;
359 <<
"=>=>=>=> Filling Pixel Level Calibration" << endl;
362 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd") {
365 else if (isPixelNoisy)
372 if ((jrow + 1) % nrowsrocsplit == 0) {
375 <<
"=>=>=>=> Filling Column Level Calibration" << endl;
378 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
380 theSiPixelGainCalibrationGainPerColPedPerPixel);
381 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd")
383 }
else if (isColumnNoisy) {
384 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
386 theSiPixelGainCalibrationGainPerColPedPerPixel);
387 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd")
390 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd")
392 gainforthiscol[iglobalrow], nrowsrocsplit, theSiPixelGainCalibrationGainPerColPedPerPixel);
393 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd")
395 pedforthiscol[iglobalrow], gainforthiscol[iglobalrow], theSiPixelGainCalibrationPerCol);
401 <<
"=>=>=>=> This pixel is finished inserting" << endl;
407 <<
"=>=>=>=> This column is finished inserting" << endl;
412 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> Loop over rows/cols is finished" << endl;
414 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd") {
416 theSiPixelGainCalibrationGainPerColPedPerPixel.end());
419 <<
"warning: detid already exists for Offline (gain per col, ped per pixel) calibration database" 422 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd") {
424 theSiPixelGainCalibrationPerCol.end());
427 <<
"warning: detid already exists for HLT (gain per col, ped per col) calibration database" << std::endl;
431 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"=>=>=>=> This detid is finished inserting" << endl;
435 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
" --- writing to DB!" << std::endl;
441 if (
record_ ==
"SiPixelGainCalibrationOfflineRcd") {
443 <<
"now doing SiPixelGainCalibrationOfflineRcd payload..." << std::endl;
444 if (mydbservice->
isNewTagRequest(
"SiPixelGainCalibrationOfflineRcd")) {
452 if (
record_ ==
"SiPixelGainCalibrationForHLTRcd") {
454 <<
"now doing SiPixelGainCalibrationForHLTRcd payload..." << std::endl;
465 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
" ---> SUMMARY :" << std::endl;
467 <<
" File had " <<
nnoisyininput <<
" noisy pixels" << std::endl;
469 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
" DB has now " << nnoisy <<
" noisy pixels" << std::endl;
470 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
" DB has now " << ndead <<
" dead pixels" << std::endl;
481 <<
"If you don't want to insert noisy pixel flag, disable it using tag insertNoisyPixelsInDB " << std::endl;
488 edm::LogPrint(
"SiPixelGainCalibrationRejectNoisyAndDead") <<
"opened" << endl;
490 while (
in.getline(linetmp, 200)) {
492 if (
line.Contains(
"OFFLINE")) {
493 line.Remove(0,
line.First(
",") + 9);
494 TString detidstring =
line;
495 detidstring.Remove(
line.First(
" "),
line.Sizeof());
497 line.Remove(0,
line.First(
",") + 20);
500 line.Remove(0,
line.First(
",") + 1);
502 row.Remove(
line.First(
" "),
line.Sizeof());
505 <<
"Found noisy pixel in DETID " << detidstring <<
" col,row " <<
col <<
"," << row << std::endl;
508 std::vector<std::pair<int, int> > tempvec;
512 std::pair<int, int> temppair(
col.Atoi(), row.Atoi());
513 tempvec.push_back(temppair);
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
bool isNoisyColumn(const uint32_t &detID, const int &col, const int &row) override
const int insertnoisypixelsindb_
const std::string noisypixellist_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > pddToken_
virtual int ncolumns() const =0
float getPedestal(const uint32_t &detID, const int &col, const int &row) override
cond::Time_t beginOfTime() const
double getGainLow() override
virtual int nrows() const =0
std::unique_ptr< SiPixelGainCalibrationOffline > theGainCalibrationDbInputOffline_
std::map< int, std::vector< std::pair< int, int > > > noisypixelkeeper
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Log< level::Error, false > LogError
std::pair< ContainerIterator, ContainerIterator > Range
double getGainHigh() override
~SiPixelGainCalibrationRejectNoisyAndDead() override
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
U second(std::pair< T, U > const &p)
void appendOneIOV(const T &payload, cond::Time_t sinceTime, const std::string &recordName)
std::map< int, std::vector< std::pair< int, int > > > insertednoisypixel
std::unique_ptr< SiPixelGainCalibrationForHLT > theGainCalibrationDbInputForHLT_
float getGain(const uint32_t &detID, const int &col, const int &row) override
bool isNewTagRequest(const std::string &recordName)
double getPedLow() override
cond::Time_t currentTime() const
SiPixelGainCalibrationForHLTService SiPixelGainCalibrationForHLTService_
void setESObjects(const edm::EventSetup &es) override
void analyze(const edm::Event &, const edm::EventSetup &) override
bool isDeadColumn(const uint32_t &detID, const int &col, const int &row) override
bool isDead(const uint32_t &detID, const int &col, const int &row) override
#define DEFINE_FWK_MODULE(type)
Log< level::Warning, true > LogPrint
SiPixelGainCalibrationOfflineService SiPixelGainCalibrationOfflineService_
bool isNoisy(const uint32_t &detID, const int &col, const int &row) override
Log< level::Info, false > LogInfo
double getPedHigh() override
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
const std::string record_
bool isDeadColumn(const uint32_t &detID, const int &col, const int &row) override
void fillDatabase(const edm::EventSetup &)
bool isNoisyColumn(const uint32_t &detID, const int &col, const int &row) override
float getPedestal(const uint32_t &detID, const int &col, const int &row) override
T mod(const T &a, const T &b)
SiPixelGainCalibrationRejectNoisyAndDead(const edm::ParameterSet &)
float getGain(const uint32_t &detID, const int &col, const int &row) override