Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-05-05 02:47:22

0001 // -*- C++ -*-
0002 //
0003 // Package:    InsertNoisyPixelsInDB
0004 // Class:      InsertNoisyPixelsInDB
0005 //
0006 /**\class InsertNoisyPixelsInDB InsertNoisyPixelsInDB.cc CondTools/InsertNoisyPixelsInDB/src/InsertNoisyPixelsInDB.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Romain Rougny
0015 //         Created:  Tue Feb  3 15:18:02 CET 2009
0016 // $Id: SiPixelGainCalibrationRejectNoisyAndDead.cc,v 1.5 2009/10/21 15:53:42 heyburn Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <fstream>
0022 #include <map>
0023 #include <memory>
0024 #include <sys/stat.h>
0025 #include <utility>
0026 #include <vector>
0027 
0028 // user include files
0029 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationForHLTService.h"
0030 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationOfflineService.h"
0031 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationService.h"
0032 #include "CalibTracker/SiPixelESProducers/interface/SiPixelGainCalibrationServiceBase.h"
0033 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0034 #include "CondFormats/SiPixelObjects/interface/SiPixelCalibConfiguration.h"
0035 #include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibration.h"
0036 #include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationForHLT.h"
0037 #include "CondFormats/SiPixelObjects/interface/SiPixelGainCalibrationOffline.h"
0038 #include "FWCore/Framework/interface/Event.h"
0039 #include "FWCore/Framework/interface/Frameworkfwd.h"
0040 #include "FWCore/Framework/interface/MakerMacros.h"
0041 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0042 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0043 #include "FWCore/ServiceRegistry/interface/Service.h"
0044 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0045 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0046 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0047 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0048 
0049 // ROOT includes
0050 #include "TH2F.h"
0051 #include "TFile.h"
0052 #include "TDirectory.h"
0053 #include "TKey.h"
0054 #include "TString.h"
0055 #include "TList.h"
0056 
0057 class SiPixelGainCalibrationRejectNoisyAndDead : public edm::one::EDAnalyzer<> {
0058 public:
0059   explicit SiPixelGainCalibrationRejectNoisyAndDead(const edm::ParameterSet&);
0060   ~SiPixelGainCalibrationRejectNoisyAndDead() override;
0061 
0062   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0063 
0064 private:
0065   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> pddToken_;
0066   SiPixelGainCalibrationOfflineService SiPixelGainCalibrationOfflineService_;
0067   std::unique_ptr<SiPixelGainCalibrationOffline> theGainCalibrationDbInputOffline_;
0068 
0069   SiPixelGainCalibrationForHLTService SiPixelGainCalibrationForHLTService_;
0070   std::unique_ptr<SiPixelGainCalibrationForHLT> theGainCalibrationDbInputForHLT_;
0071 
0072   void analyze(const edm::Event&, const edm::EventSetup&) override;
0073 
0074   std::map<int, std::vector<std::pair<int, int> > > noisypixelkeeper;
0075   std::map<int, std::vector<std::pair<int, int> > > insertednoisypixel;
0076   int nnoisyininput;
0077 
0078   void fillDatabase(const edm::EventSetup&);
0079   void getNoisyPixels();
0080 
0081   // ----------member data ---------------------------
0082   const std::string noisypixellist_;
0083   const int insertnoisypixelsindb_;
0084   const std::string record_;
0085   const bool DEBUG;
0086   float pedlow_;
0087   float pedhi_;
0088   float gainlow_;
0089   float gainhi_;
0090 };
0091 
0092 using namespace edm;
0093 using namespace std;
0094 
0095 void SiPixelGainCalibrationRejectNoisyAndDead::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0096   edm::ParameterSetDescription desc;
0097   desc.setComment("EDAnalyzer to create SiPixelGainCalibration payloads by rejecting noisy and dead ones");
0098   desc.addUntracked<bool>("debug", false);
0099   desc.addUntracked<int>("insertNoisyPixelsInDB", 1);
0100   desc.addUntracked<std::string>("record", "SiPixelGainCalibrationOfflineRcd");
0101   desc.addUntracked<std::string>("noisyPixelList", "noisypixel.txt");
0102   descriptions.addWithDefaultLabel(desc);
0103 }
0104 
0105 SiPixelGainCalibrationRejectNoisyAndDead::SiPixelGainCalibrationRejectNoisyAndDead(const edm::ParameterSet& iConfig)
0106     : pddToken_(esConsumes()),
0107       SiPixelGainCalibrationOfflineService_(iConfig, consumesCollector()),
0108       SiPixelGainCalibrationForHLTService_(iConfig, consumesCollector()),
0109       noisypixellist_(iConfig.getUntrackedParameter<std::string>("noisyPixelList", "noisypixel.txt")),
0110       insertnoisypixelsindb_(iConfig.getUntrackedParameter<int>("insertNoisyPixelsInDB", 1)),
0111       record_(iConfig.getUntrackedParameter<std::string>("record", "SiPixelGainCalibrationOfflineRcd")),
0112       DEBUG(iConfig.getUntrackedParameter<bool>("debug", false)) {
0113   //now do what ever initialization is needed
0114 }
0115 
0116 SiPixelGainCalibrationRejectNoisyAndDead::~SiPixelGainCalibrationRejectNoisyAndDead() = default;
0117 
0118 // ------------ method called to for each event  ------------
0119 void SiPixelGainCalibrationRejectNoisyAndDead::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0120   if (insertnoisypixelsindb_ != 0)
0121     getNoisyPixels();
0122   fillDatabase(iSetup);
0123 }
0124 
0125 void SiPixelGainCalibrationRejectNoisyAndDead::fillDatabase(const edm::EventSetup& iSetup) {
0126   if (DEBUG)
0127     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0128         << "=>=>=>=> Starting the function fillDatabase()" << endl;
0129 
0130   if (record_ != "SiPixelGainCalibrationOfflineRcd" && record_ != "SiPixelGainCalibrationForHLTRcd") {
0131     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0132         << record_ << " : this record  can't be used !" << std::endl;
0133     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0134         << "Please select SiPixelGainCalibrationForHLTRcd or SiPixelGainCalibrationOfflineRcd" << std::endl;
0135     return;
0136   }
0137 
0138   //Get the Calibration Data
0139   if (record_ == "SiPixelGainCalibrationOfflineRcd")
0140     SiPixelGainCalibrationOfflineService_.setESObjects(iSetup);
0141   if (record_ == "SiPixelGainCalibrationForHLTRcd")
0142     SiPixelGainCalibrationForHLTService_.setESObjects(iSetup);
0143 
0144   //Get list of ideal detids
0145   const TrackerGeometry* pDD = &iSetup.getData(pddToken_);
0146   edm::LogInfo("SiPixelCondObjOfflineBuilder") << " There are " << pDD->dets().size() << " detectors" << std::endl;
0147 
0148   if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0149     pedlow_ = SiPixelGainCalibrationOfflineService_.getPedLow();
0150     pedhi_ = SiPixelGainCalibrationOfflineService_.getPedHigh();
0151     gainlow_ = SiPixelGainCalibrationOfflineService_.getGainLow();
0152     gainhi_ = SiPixelGainCalibrationOfflineService_.getGainHigh();
0153   } else if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0154     pedlow_ = SiPixelGainCalibrationForHLTService_.getPedLow();
0155     pedhi_ = SiPixelGainCalibrationForHLTService_.getPedHigh();
0156     gainlow_ = SiPixelGainCalibrationForHLTService_.getGainLow();
0157     gainhi_ = SiPixelGainCalibrationForHLTService_.getGainHigh();
0158   }
0159   if (gainlow_ < 0)
0160     gainlow_ = 0;
0161   if (gainhi_ > 21)
0162     gainhi_ = 21;
0163   if (pedlow_ < -100)
0164     pedlow_ = -100;
0165   if (pedhi_ > 300)
0166     pedhi_ = 300;
0167 
0168   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0169       << "New payload will have pedlow,hi " << pedlow_ << "," << pedhi_ << " and gainlow,hi " << gainlow_ << ","
0170       << gainhi_ << endl;
0171   if (record_ == "SiPixelGainCalibrationOfflineRcd")
0172     theGainCalibrationDbInputOffline_ =
0173         std::make_unique<SiPixelGainCalibrationOffline>(pedlow_, pedhi_, gainlow_, gainhi_);
0174   if (record_ == "SiPixelGainCalibrationForHLTRcd")
0175     theGainCalibrationDbInputForHLT_ =
0176         std::make_unique<SiPixelGainCalibrationForHLT>(pedlow_, pedhi_, gainlow_, gainhi_);
0177 
0178   int nnoisy = 0;
0179   int ndead = 0;
0180 
0181   int detid = 0;
0182 
0183   //checking for noisy pixels that won't be inserted ...
0184   bool willNoisyPixBeInserted;
0185   for (std::map<int, std::vector<std::pair<int, int> > >::const_iterator it = noisypixelkeeper.begin();
0186        it != noisypixelkeeper.end();
0187        it++) {
0188     willNoisyPixBeInserted = false;
0189     for (TrackerGeometry::DetContainer::const_iterator mod = pDD->dets().begin(); mod != pDD->dets().end(); mod++) {
0190       detid = 0;
0191       if (dynamic_cast<PixelGeomDetUnit const*>((*mod)) != nullptr)
0192         detid = ((*mod)->geographicalId()).rawId();
0193       if (detid == it->first) {
0194         willNoisyPixBeInserted = true;
0195         break;
0196       }
0197     }
0198     if (!willNoisyPixBeInserted)
0199       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0200           << "All Noisy Pixels in detid " << it->first
0201           << "won't be inserted, check the TrackerGeometry you are using !! You are missing some modules" << endl;
0202   }
0203 
0204   if (DEBUG)
0205     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Starting Loop over all modules" << endl;
0206 
0207   //Looping over all modules
0208   for (TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++) {
0209     detid = 0;
0210     if (dynamic_cast<PixelGeomDetUnit const*>((*it)) != nullptr)
0211       detid = ((*it)->geographicalId()).rawId();
0212     if (detid == 0)
0213       continue;
0214 
0215     if (DEBUG)
0216       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> We are in module " << detid << endl;
0217 
0218     // Get the module sizes
0219     const PixelGeomDetUnit* pixDet = dynamic_cast<const PixelGeomDetUnit*>((*it));
0220     const PixelTopology& topol = pixDet->specificTopology();
0221     int nrows = topol.nrows();     // rows in x
0222     int ncols = topol.ncolumns();  // cols in y
0223 
0224     float ped;
0225     float gainforthiscol[2];
0226     float pedforthiscol[2];
0227     int nusedrows[2];
0228     int nrowsrocsplit;
0229     if (record_ == "SiPixelGainCalibrationOfflineRcd")
0230       nrowsrocsplit = theGainCalibrationDbInputOffline_->getNumberOfRowsToAverageOver();
0231     if (record_ == "SiPixelGainCalibrationForHLTRcd")
0232       nrowsrocsplit = theGainCalibrationDbInputForHLT_->getNumberOfRowsToAverageOver();
0233 
0234     std::vector<char> theSiPixelGainCalibrationGainPerColPedPerPixel;
0235     std::vector<char> theSiPixelGainCalibrationPerCol;
0236 
0237     if (DEBUG)
0238       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Starting Loop for each rows/cols " << endl;
0239 
0240     for (int icol = 0; icol <= ncols - 1; icol++) {
0241       if (DEBUG)
0242         edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Starting a new column" << endl;
0243 
0244       nusedrows[0] = nusedrows[1] = 0;
0245       gainforthiscol[0] = gainforthiscol[1] = 0;
0246       pedforthiscol[0] = pedforthiscol[1] = 0;
0247 
0248       for (int jrow = 0; jrow <= nrows - 1; jrow++) {
0249         if (DEBUG)
0250           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0251               << "=>=>=>=> We are in col,row " << icol << "," << jrow << endl;
0252 
0253         ped = 0;
0254 
0255         size_t iglobalrow = 0;
0256         int noisyPixInRow = 0;
0257         if (jrow > nrowsrocsplit) {
0258           iglobalrow = 1;
0259           noisyPixInRow = 0;
0260         }
0261 
0262         bool isPixelDeadOld = false;
0263         bool isColumnDeadOld = false;
0264         //  bool isPixelDeadNew = false;
0265         //  bool isColumnDeadNew = false;
0266 
0267         bool isPixelNoisyOld = false;
0268         bool isColumnNoisyOld = false;
0269         bool isPixelNoisyNew = false;
0270         bool isColumnNoisyNew = false;
0271 
0272         bool isColumnDead = false;
0273         bool isColumnNoisy = false;
0274         bool isPixelDead = false;
0275         bool isPixelNoisy = false;
0276 
0277         if (DEBUG)
0278           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Trying to get gain/ped " << endl;
0279 
0280         try {
0281           if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0282             isPixelDeadOld = SiPixelGainCalibrationOfflineService_.isDead(detid, icol, jrow);
0283             isPixelNoisyOld = SiPixelGainCalibrationOfflineService_.isNoisy(detid, icol, jrow);
0284             isColumnDeadOld = SiPixelGainCalibrationOfflineService_.isNoisyColumn(detid, icol, jrow);
0285             isColumnNoisyOld = SiPixelGainCalibrationOfflineService_.isDeadColumn(detid, icol, jrow);
0286           }
0287           if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0288             isColumnDeadOld = SiPixelGainCalibrationForHLTService_.isNoisyColumn(detid, icol, jrow);
0289             isColumnNoisyOld = SiPixelGainCalibrationForHLTService_.isDeadColumn(detid, icol, jrow);
0290           }
0291           if (!isColumnDeadOld && !isColumnNoisyOld) {
0292             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0293               gainforthiscol[iglobalrow] = SiPixelGainCalibrationOfflineService_.getGain(detid, icol, jrow);
0294             if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0295               gainforthiscol[iglobalrow] = SiPixelGainCalibrationForHLTService_.getGain(detid, icol, jrow);
0296               pedforthiscol[iglobalrow] = SiPixelGainCalibrationForHLTService_.getPedestal(detid, icol, jrow);
0297             }
0298           }
0299           if (!isPixelDeadOld && !isPixelNoisyOld)
0300             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0301               ped = SiPixelGainCalibrationOfflineService_.getPedestal(detid, icol, jrow);
0302         } catch (const std::exception& er) {
0303           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0304               << "Problem trying to catch gain/ped from DETID " << detid << " @ col,row " << icol << "," << jrow
0305               << endl;
0306         }
0307         //edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")<<"For DetId "<<detid<<" we found gain : "<<gain<<", pedestal : "<<ped<<std::endl;
0308 
0309         if (DEBUG)
0310           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0311               << "=>=>=>=> Found gain " << gainforthiscol[iglobalrow] << " and ped " << pedforthiscol[iglobalrow]
0312               << endl;
0313 
0314         //Check if pixel is in new noisy list
0315         for (std::map<int, std::vector<std::pair<int, int> > >::const_iterator it = noisypixelkeeper.begin();
0316              it != noisypixelkeeper.end();
0317              it++)
0318           for (unsigned int i = 0; i < (it->second).size(); i++)
0319             if (it->first == detid && (it->second.at(i)).first == icol && (it->second.at(i)).second == jrow)
0320               isPixelNoisyNew = true;
0321 
0322         isColumnDead = isColumnDeadOld;
0323         isPixelDead = isPixelDeadOld;
0324 
0325         if (isPixelNoisyNew)
0326           noisyPixInRow++;
0327         if (noisyPixInRow == nrowsrocsplit)
0328           isColumnNoisyNew = true;
0329 
0330         if (insertnoisypixelsindb_ == 0) {
0331           isColumnNoisy = isColumnNoisyOld;
0332           isPixelNoisy = isPixelNoisyOld;
0333         } else if (insertnoisypixelsindb_ == 1) {
0334           isPixelNoisy = isPixelNoisyNew;
0335           isColumnNoisy = isColumnNoisyNew;
0336         } else if (insertnoisypixelsindb_ == 2) {
0337           isPixelNoisy = isPixelNoisyNew || isPixelNoisyOld;
0338           isColumnNoisy = isColumnNoisyNew || isColumnNoisyOld;
0339         }
0340 
0341         if (isPixelNoisy)
0342           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0343               << "Inserting a noisy pixel in " << detid << " at col,row " << icol << "," << jrow << endl;
0344         if (isColumnNoisy)
0345           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0346               << "Inserting a noisy column in " << detid << " at col,row " << icol << "," << jrow << endl;
0347         if (isPixelNoisy)
0348           nnoisy++;
0349         if (isPixelDead)
0350           ndead++;
0351 
0352         if (DEBUG)
0353           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Now Starting to fill the DB" << endl;
0354 
0355         //**********  Fill the new DB !!
0356 
0357         if (DEBUG)
0358           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0359               << "=>=>=>=> Filling Pixel Level Calibration" << endl;
0360 
0361         //Set Pedestal
0362         if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0363           if (isPixelDead)
0364             theGainCalibrationDbInputOffline_->setDeadPixel(theSiPixelGainCalibrationGainPerColPedPerPixel);
0365           else if (isPixelNoisy)
0366             theGainCalibrationDbInputOffline_->setNoisyPixel(theSiPixelGainCalibrationGainPerColPedPerPixel);
0367           else
0368             theGainCalibrationDbInputOffline_->setDataPedestal(ped, theSiPixelGainCalibrationGainPerColPedPerPixel);
0369         }
0370 
0371         //Set Gain
0372         if ((jrow + 1) % nrowsrocsplit == 0) {
0373           if (DEBUG)
0374             edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0375                 << "=>=>=>=> Filling Column Level Calibration" << endl;
0376 
0377           if (isColumnDead) {
0378             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0379               theGainCalibrationDbInputOffline_->setDeadColumn(nrowsrocsplit,
0380                                                                theSiPixelGainCalibrationGainPerColPedPerPixel);
0381             if (record_ == "SiPixelGainCalibrationForHLTRcd")
0382               theGainCalibrationDbInputForHLT_->setDeadColumn(nrowsrocsplit, theSiPixelGainCalibrationPerCol);
0383           } else if (isColumnNoisy) {
0384             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0385               theGainCalibrationDbInputOffline_->setNoisyColumn(nrowsrocsplit,
0386                                                                 theSiPixelGainCalibrationGainPerColPedPerPixel);
0387             if (record_ == "SiPixelGainCalibrationForHLTRcd")
0388               theGainCalibrationDbInputForHLT_->setNoisyColumn(nrowsrocsplit, theSiPixelGainCalibrationPerCol);
0389           } else {
0390             if (record_ == "SiPixelGainCalibrationOfflineRcd")
0391               theGainCalibrationDbInputOffline_->setDataGain(
0392                   gainforthiscol[iglobalrow], nrowsrocsplit, theSiPixelGainCalibrationGainPerColPedPerPixel);
0393             if (record_ == "SiPixelGainCalibrationForHLTRcd")
0394               theGainCalibrationDbInputForHLT_->setData(
0395                   pedforthiscol[iglobalrow], gainforthiscol[iglobalrow], theSiPixelGainCalibrationPerCol);
0396           }
0397         }
0398 
0399         if (DEBUG)
0400           edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0401               << "=>=>=>=> This pixel is finished inserting" << endl;
0402 
0403       }  //end of loop over rows
0404 
0405       if (DEBUG)
0406         edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0407             << "=>=>=>=> This column is finished inserting" << endl;
0408 
0409     }  //end of loop over col
0410 
0411     if (DEBUG)
0412       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> Loop over rows/cols is finished" << endl;
0413 
0414     if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0415       SiPixelGainCalibrationOffline::Range offlinerange(theSiPixelGainCalibrationGainPerColPedPerPixel.begin(),
0416                                                         theSiPixelGainCalibrationGainPerColPedPerPixel.end());
0417       if (!theGainCalibrationDbInputOffline_->put(detid, offlinerange, ncols))
0418         edm::LogError("SiPixelGainCalibrationAnalysis")
0419             << "warning: detid already exists for Offline (gain per col, ped per pixel) calibration database"
0420             << std::endl;
0421     }
0422     if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0423       SiPixelGainCalibrationOffline::Range hltrange(theSiPixelGainCalibrationPerCol.begin(),
0424                                                     theSiPixelGainCalibrationPerCol.end());
0425       if (!theGainCalibrationDbInputForHLT_->put(detid, hltrange, ncols))
0426         edm::LogError("SiPixelGainCalibrationAnalysis")
0427             << "warning: detid already exists for HLT (gain per col, ped per col) calibration database" << std::endl;
0428     }
0429 
0430     if (DEBUG)
0431       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "=>=>=>=> This detid is finished inserting" << endl;
0432 
0433   }  //end of loop over Detids
0434 
0435   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " --- writing to DB!" << std::endl;
0436   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0437   if (!mydbservice.isAvailable()) {
0438     edm::LogError("db service unavailable");
0439     return;
0440   } else {
0441     if (record_ == "SiPixelGainCalibrationOfflineRcd") {
0442       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0443           << "now doing SiPixelGainCalibrationOfflineRcd payload..." << std::endl;
0444       if (mydbservice->isNewTagRequest("SiPixelGainCalibrationOfflineRcd")) {
0445         mydbservice->createOneIOV<SiPixelGainCalibrationOffline>(
0446             *theGainCalibrationDbInputOffline_, mydbservice->beginOfTime(), "SiPixelGainCalibrationOfflineRcd");
0447       } else {
0448         mydbservice->appendOneIOV<SiPixelGainCalibrationOffline>(
0449             *theGainCalibrationDbInputOffline_, mydbservice->currentTime(), "SiPixelGainCalibrationOfflineRcd");
0450       }
0451     }
0452     if (record_ == "SiPixelGainCalibrationForHLTRcd") {
0453       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0454           << "now doing SiPixelGainCalibrationForHLTRcd payload..." << std::endl;
0455       if (mydbservice->isNewTagRequest("SiPixelGainCalibrationForHLTRcd")) {
0456         mydbservice->createOneIOV<SiPixelGainCalibrationForHLT>(
0457             *theGainCalibrationDbInputForHLT_, mydbservice->beginOfTime(), "SiPixelGainCalibrationForHLTRcd");
0458       } else {
0459         mydbservice->appendOneIOV<SiPixelGainCalibrationForHLT>(
0460             *theGainCalibrationDbInputForHLT_, mydbservice->currentTime(), "SiPixelGainCalibrationForHLTRcd");
0461       }
0462     }
0463   }
0464 
0465   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " ---> SUMMARY :" << std::endl;
0466   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0467       << " File had   " << nnoisyininput << " noisy pixels" << std::endl;
0468 
0469   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " DB has now " << nnoisy << " noisy pixels" << std::endl;
0470   edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << " DB has now " << ndead << " dead pixels" << std::endl;
0471 }
0472 
0473 void SiPixelGainCalibrationRejectNoisyAndDead::getNoisyPixels() {
0474   nnoisyininput = 0;
0475 
0476   ifstream in;
0477   struct stat Stat;
0478   if (stat(noisypixellist_.c_str(), &Stat)) {
0479     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "No file named " << noisypixellist_ << std::endl;
0480     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0481         << "If you don't want to insert noisy pixel flag, disable it using tag insertNoisyPixelsInDB " << std::endl;
0482     return;
0483   }
0484 
0485   in.open(noisypixellist_.c_str());
0486   if (in.is_open()) {
0487     TString line;
0488     edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead") << "opened" << endl;
0489     char linetmp[201];
0490     while (in.getline(linetmp, 200)) {
0491       line = linetmp;
0492       if (line.Contains("OFFLINE")) {
0493         line.Remove(0, line.First(",") + 9);
0494         TString detidstring = line;
0495         detidstring.Remove(line.First(" "), line.Sizeof());
0496 
0497         line.Remove(0, line.First(",") + 20);
0498         TString col = line;
0499         col.Remove(line.First(","), line.Sizeof());
0500         line.Remove(0, line.First(",") + 1);
0501         TString row = line;
0502         row.Remove(line.First(" "), line.Sizeof());
0503 
0504         edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")
0505             << "Found noisy pixel in DETID " << detidstring << " col,row " << col << "," << row << std::endl;
0506         nnoisyininput++;
0507 
0508         std::vector<std::pair<int, int> > tempvec;
0509         if (noisypixelkeeper.find(detidstring.Atoi()) != noisypixelkeeper.end())
0510           tempvec = (noisypixelkeeper.find(detidstring.Atoi()))->second;
0511 
0512         std::pair<int, int> temppair(col.Atoi(), row.Atoi());
0513         tempvec.push_back(temppair);
0514         noisypixelkeeper[detidstring.Atoi()] = tempvec;
0515       }
0516     }
0517   }
0518   /*
0519   for(std::map <int,std::vector<std::pair<int,int> > >::const_iterator it=noisypixelkeeper.begin();it!=noisypixelkeeper.end();it++) 
0520     for(int i=0;i<(it->second).size();i++)
0521       edm::LogPrint("SiPixelGainCalibrationRejectNoisyAndDead")<<it->first<<"  "<<(it->second.at(i)).first<<"  "<<(it->second.at(i)).second<<std::endl;
0522   */
0523 }
0524 
0525 //define this as a plug-in
0526 DEFINE_FWK_MODULE(SiPixelGainCalibrationRejectNoisyAndDead);