Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:23

0001 // system includes
0002 #include <memory>
0003 #include <string>
0004 #include <iostream>
0005 #include <fstream>
0006 #include <limits>
0007 #include <map>
0008 
0009 // user includes
0010 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0011 #include "CondFormats/SiPixelObjects/interface/SiPixelDynamicInefficiency.h"
0012 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
0013 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
0014 #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
0015 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0016 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0025 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0026 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0027 
0028 class SiPixelDynamicInefficiencyDB : public edm::one::EDAnalyzer<> {
0029 public:
0030   explicit SiPixelDynamicInefficiencyDB(const edm::ParameterSet& conf);
0031 
0032   ~SiPixelDynamicInefficiencyDB() override;
0033   void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0034 
0035 private:
0036   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tkTopoToken_;
0037   edm::ParameterSet conf_;
0038   std::string recordName_;
0039 
0040   typedef std::vector<edm::ParameterSet> Parameters;
0041   Parameters thePixelGeomFactors_;
0042   Parameters theColGeomFactors_;
0043   Parameters theChipGeomFactors_;
0044   Parameters thePUEfficiency_;
0045   double theInstLumiScaleFactor_;
0046 };
0047 
0048 using namespace std;
0049 using namespace edm;
0050 
0051 //Constructor
0052 
0053 SiPixelDynamicInefficiencyDB::SiPixelDynamicInefficiencyDB(edm::ParameterSet const& conf)
0054     : tkTopoToken_(esConsumes()), conf_(conf) {
0055   recordName_ = conf_.getUntrackedParameter<std::string>("record", "SiPixelDynamicInefficiencyRcd");
0056   thePixelGeomFactors_ = conf_.getUntrackedParameter<Parameters>("thePixelGeomFactors");
0057   theColGeomFactors_ = conf_.getUntrackedParameter<Parameters>("theColGeomFactors");
0058   theChipGeomFactors_ = conf_.getUntrackedParameter<Parameters>("theChipGeomFactors");
0059   thePUEfficiency_ = conf_.getUntrackedParameter<Parameters>("thePUEfficiency");
0060   theInstLumiScaleFactor_ = conf_.getUntrackedParameter<double>("theInstLumiScaleFactor");
0061 }
0062 
0063 // Virtual destructor needed.
0064 SiPixelDynamicInefficiencyDB::~SiPixelDynamicInefficiencyDB() = default;
0065 
0066 // Analyzer: Functions that gets called by framework every event
0067 
0068 void SiPixelDynamicInefficiencyDB::analyze(const edm::Event& e, const edm::EventSetup& es) {
0069   SiPixelDynamicInefficiency DynamicInefficiency;
0070 
0071   //Retrieve tracker topology from geometry
0072   const TrackerTopology* const tTopo = &es.getData(tkTopoToken_);
0073 
0074   uint32_t max = numeric_limits<uint32_t>::max();
0075   uint32_t mask;
0076   uint32_t layer, LAYER = 0;
0077   uint32_t ladder, LADDER = 0;
0078   uint32_t module, MODULE = 0;
0079   uint32_t side, SIDE = 0;
0080   uint32_t disk, DISK = 0;
0081   uint32_t blade, BLADE = 0;
0082   uint32_t panel, PANEL = 0;
0083 
0084   //Put BPix masks
0085   mask = tTopo->pxbDetId(max, LADDER, MODULE).rawId();
0086   DynamicInefficiency.putDetIdmask(mask);
0087   mask = tTopo->pxbDetId(LAYER, max, MODULE).rawId();
0088   DynamicInefficiency.putDetIdmask(mask);
0089   mask = tTopo->pxbDetId(LAYER, LADDER, max).rawId();
0090   DynamicInefficiency.putDetIdmask(mask);
0091   //Put FPix masks
0092   mask = tTopo->pxfDetId(max, DISK, BLADE, PANEL, MODULE).rawId();
0093   DynamicInefficiency.putDetIdmask(mask);
0094   mask = tTopo->pxfDetId(SIDE, max, BLADE, PANEL, MODULE).rawId();
0095   DynamicInefficiency.putDetIdmask(mask);
0096   mask = tTopo->pxfDetId(SIDE, DISK, max, PANEL, MODULE).rawId();
0097   DynamicInefficiency.putDetIdmask(mask);
0098   mask = tTopo->pxfDetId(SIDE, DISK, BLADE, max, MODULE).rawId();
0099   DynamicInefficiency.putDetIdmask(mask);
0100   mask = tTopo->pxfDetId(SIDE, DISK, BLADE, PANEL, max).rawId();
0101   DynamicInefficiency.putDetIdmask(mask);
0102 
0103   //Put PixelGeomFactors
0104   for (Parameters::iterator it = thePixelGeomFactors_.begin(); it != thePixelGeomFactors_.end(); ++it) {
0105     string det = it->getParameter<string>("det");
0106     it->exists("layer") ? layer = it->getParameter<unsigned int>("layer") : layer = LAYER;
0107     it->exists("ladder") ? ladder = it->getParameter<unsigned int>("ladder") : ladder = LADDER;
0108     it->exists("module") ? module = it->getParameter<unsigned int>("module") : module = MODULE;
0109     it->exists("side") ? side = it->getParameter<unsigned int>("side") : side = SIDE;
0110     it->exists("disk") ? disk = it->getParameter<unsigned int>("disk") : disk = DISK;
0111     it->exists("blade") ? blade = it->getParameter<unsigned int>("blade") : blade = BLADE;
0112     it->exists("panel") ? panel = it->getParameter<unsigned int>("panel") : panel = PANEL;
0113     double factor = it->getParameter<double>("factor");
0114     if (det == "bpix") {
0115       DetId detID = tTopo->pxbDetId(layer, ladder, module);
0116       edm::LogPrint("SiPixelDynamicInefficiencyDB") << "Putting Pixel geom BPix layer " << layer << " ladder " << ladder
0117                                                     << " module " << module << " factor " << factor << std::endl;
0118       DynamicInefficiency.putPixelGeomFactor(detID.rawId(), factor);
0119     } else if (det == "fpix") {
0120       DetId detID = tTopo->pxfDetId(side, disk, blade, panel, module);
0121       edm::LogPrint("SiPixelDynamicInefficiencyDB")
0122           << "Putting Pixel geom FPix side " << side << " disk " << disk << " blade " << blade << " panel " << panel
0123           << " module " << module << " factor " << factor << std::endl;
0124       DynamicInefficiency.putPixelGeomFactor(detID.rawId(), factor);
0125     } else
0126       edm::LogError("SiPixelDynamicInefficiencyDB")
0127           << "SiPixelDynamicInefficiencyDB input detector part is neither bpix nor fpix" << std::endl;
0128   }
0129 
0130   //Put ColumnGeomFactors
0131   for (Parameters::iterator it = theColGeomFactors_.begin(); it != theColGeomFactors_.end(); ++it) {
0132     string det = it->getParameter<string>("det");
0133     it->exists("layer") ? layer = it->getParameter<unsigned int>("layer") : layer = LAYER;
0134     it->exists("ladder") ? ladder = it->getParameter<unsigned int>("ladder") : ladder = LADDER;
0135     it->exists("module") ? module = it->getParameter<unsigned int>("module") : module = MODULE;
0136     it->exists("side") ? side = it->getParameter<unsigned int>("side") : side = SIDE;
0137     it->exists("disk") ? disk = it->getParameter<unsigned int>("disk") : disk = DISK;
0138     it->exists("blade") ? blade = it->getParameter<unsigned int>("blade") : blade = BLADE;
0139     it->exists("panel") ? panel = it->getParameter<unsigned int>("panel") : panel = PANEL;
0140     double factor = it->getParameter<double>("factor");
0141     if (det == "bpix") {
0142       DetId detID = tTopo->pxbDetId(layer, ladder, module);
0143       edm::LogPrint("SiPixelDynamicInefficiencyDB")
0144           << "Putting Column geom BPix layer " << layer << " ladder " << ladder << " module " << module << " factor "
0145           << factor << std::endl;
0146       DynamicInefficiency.putColGeomFactor(detID.rawId(), factor);
0147     } else if (det == "fpix") {
0148       DetId detID = tTopo->pxfDetId(side, disk, blade, panel, module);
0149       edm::LogPrint("SiPixelDynamicInefficiencyDB")
0150           << "Putting Column geom FPix side " << side << " disk " << disk << " blade " << blade << " panel " << panel
0151           << " module " << module << " factor " << factor << std::endl;
0152       DynamicInefficiency.putColGeomFactor(detID.rawId(), factor);
0153     } else
0154       edm::LogError("SiPixelDynamicInefficiencyDB")
0155           << "SiPixelDynamicInefficiencyDB input detector part is neither bpix nor fpix" << std::endl;
0156   }
0157 
0158   //Put ChipGeomFactors
0159   for (Parameters::iterator it = theChipGeomFactors_.begin(); it != theChipGeomFactors_.end(); ++it) {
0160     string det = it->getParameter<string>("det");
0161     it->exists("layer") ? layer = it->getParameter<unsigned int>("layer") : layer = LAYER;
0162     it->exists("ladder") ? ladder = it->getParameter<unsigned int>("ladder") : ladder = LADDER;
0163     it->exists("module") ? module = it->getParameter<unsigned int>("module") : module = MODULE;
0164     it->exists("side") ? side = it->getParameter<unsigned int>("side") : side = SIDE;
0165     it->exists("disk") ? disk = it->getParameter<unsigned int>("disk") : disk = DISK;
0166     it->exists("blade") ? blade = it->getParameter<unsigned int>("blade") : blade = BLADE;
0167     it->exists("panel") ? panel = it->getParameter<unsigned int>("panel") : panel = PANEL;
0168     double factor = it->getParameter<double>("factor");
0169     if (det == "bpix") {
0170       DetId detID = tTopo->pxbDetId(layer, ladder, module);
0171       edm::LogPrint("SiPixelDynamicInefficiencyDB") << "Putting Chip geom BPix layer " << layer << " ladder " << ladder
0172                                                     << " module " << module << " factor " << factor << std::endl;
0173       DynamicInefficiency.putChipGeomFactor(detID.rawId(), factor);
0174     } else if (det == "fpix") {
0175       DetId detID = tTopo->pxfDetId(side, disk, blade, panel, module);
0176       edm::LogPrint("SiPixelDynamicInefficiencyDB")
0177           << "Putting Chip geom FPix side " << side << " disk " << disk << " blade " << blade << " panel " << panel
0178           << " module " << module << " factor " << factor << std::endl;
0179       DynamicInefficiency.putChipGeomFactor(detID.rawId(), factor);
0180     } else
0181       edm::LogError("SiPixelDynamicInefficiencyDB")
0182           << "SiPixelDynamicInefficiencyDB input detector part is neither bpix nor fpix" << std::endl;
0183   }
0184 
0185   //Put PUFactors
0186   for (Parameters::iterator it = thePUEfficiency_.begin(); it != thePUEfficiency_.end(); ++it) {
0187     string det = it->getParameter<string>("det");
0188     it->exists("layer") ? layer = it->getParameter<unsigned int>("layer") : layer = LAYER;
0189     it->exists("ladder") ? ladder = it->getParameter<unsigned int>("ladder") : ladder = LADDER;
0190     it->exists("module") ? module = it->getParameter<unsigned int>("module") : module = MODULE;
0191     it->exists("side") ? side = it->getParameter<unsigned int>("side") : side = SIDE;
0192     it->exists("disk") ? disk = it->getParameter<unsigned int>("disk") : disk = DISK;
0193     it->exists("blade") ? blade = it->getParameter<unsigned int>("blade") : blade = BLADE;
0194     it->exists("panel") ? panel = it->getParameter<unsigned int>("panel") : panel = PANEL;
0195     std::vector<double> factor = it->getParameter<std::vector<double> >("factor");
0196     if (det == "bpix") {
0197       DetId detID = tTopo->pxbDetId(layer, ladder, module);
0198       edm::LogPrint("SiPixelDynamicInefficiencyDB")
0199           << "Putting PU efficiency BPix layer " << layer << " ladder " << ladder << " module " << module
0200           << " factor size " << factor.size() << std::endl;
0201       DynamicInefficiency.putPUFactor(detID.rawId(), factor);
0202     } else if (det == "fpix") {
0203       DetId detID = tTopo->pxfDetId(side, disk, blade, panel, module);
0204       edm::LogPrint("SiPixelDynamicInefficiencyDB")
0205           << "Putting PU efficiency FPix side " << side << " disk " << disk << " blade " << blade << " panel " << panel
0206           << " module " << module << " factor size " << factor.size() << std::endl;
0207       DynamicInefficiency.putPUFactor(detID.rawId(), factor);
0208     }
0209   }
0210   //Put theInstLumiScaleFactor
0211   DynamicInefficiency.puttheInstLumiScaleFactor(theInstLumiScaleFactor_);
0212 
0213   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0214   if (mydbservice.isAvailable()) {
0215     try {
0216       if (mydbservice->isNewTagRequest(recordName_)) {
0217         mydbservice->createOneIOV<SiPixelDynamicInefficiency>(
0218             DynamicInefficiency, mydbservice->beginOfTime(), recordName_);
0219       } else {
0220         mydbservice->appendOneIOV<SiPixelDynamicInefficiency>(
0221             DynamicInefficiency, mydbservice->currentTime(), recordName_);
0222       }
0223     } catch (const cond::Exception& er) {
0224       edm::LogError("SiPixelDynamicInefficiencyDB") << er.what() << std::endl;
0225     } catch (const std::exception& er) {
0226       edm::LogError("SiPixelDynamicInefficiencyDB") << "caught std::exception " << er.what() << std::endl;
0227     } catch (...) {
0228       edm::LogError("SiPixelDynamicInefficiencyDB") << "Funny error" << std::endl;
0229     }
0230   } else {
0231     edm::LogError("SiPixelDynamicInefficiencyDB") << "Service is unavailable" << std::endl;
0232   }
0233 }
0234 DEFINE_FWK_MODULE(SiPixelDynamicInefficiencyDB);