Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:  CondTools/SiPhase2Tracker
0004 // Class:    SiPhase2OuterTrackerLorentzAngleWriter
0005 //
0006 /**\class SiPhase2OuterTrackerLorentzAngleWriter SiPhase2OuterTrackerLorentzAngleWriter.cc CondTools/SiPhase2Tracker/plugins/SiPhase2OuterTrackerLorentzAngleWriter.cc
0007 
0008  Description: Put the values of the Lorentz angle for Phase-2 Outer Tracker detId in as database file
0009 
0010  Implementation:
0011      [Notes on implementation]
0012      
0013 */
0014 //
0015 // Original Author:  Marco Musich
0016 //         Created:  Mon, 18 May 2020 18:00:00 GMT
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 #include <iostream>
0023 #include <string>
0024 #include <unordered_map>
0025 
0026 // user include files
0027 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0028 #include "CondFormats/DataRecord/interface/SiPhase2OuterTrackerLorentzAngleRcd.h"
0029 #include "CondFormats/SiPhase2TrackerObjects/interface/SiPhase2OuterTrackerLorentzAngle.h"
0030 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0031 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0032 #include "FWCore/Framework/interface/Event.h"
0033 #include "FWCore/Framework/interface/Frameworkfwd.h"
0034 #include "FWCore/Framework/interface/MakerMacros.h"
0035 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0037 #include "FWCore/ServiceRegistry/interface/Service.h"
0038 #include "FWCore/Utilities/interface/InputTag.h"
0039 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0040 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0041 
0042 //
0043 // class declaration
0044 //
0045 
0046 class SiPhase2OuterTrackerLorentzAngleWriter : public edm::one::EDAnalyzer<> {
0047 public:
0048   explicit SiPhase2OuterTrackerLorentzAngleWriter(const edm::ParameterSet&);
0049   ~SiPhase2OuterTrackerLorentzAngleWriter() override;
0050 
0051   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052 
0053 private:
0054   void analyze(const edm::Event&, const edm::EventSetup&) override;
0055 
0056   // ----------member data ---------------------------
0057   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0058   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0059   std::string m_record;
0060   std::string m_tag;
0061   float m_value;
0062 };
0063 
0064 //
0065 // constructors and destructor
0066 //
0067 SiPhase2OuterTrackerLorentzAngleWriter::SiPhase2OuterTrackerLorentzAngleWriter(const edm::ParameterSet& iConfig)
0068     : topoToken_(esConsumes()),
0069       geomToken_(esConsumes()),
0070       m_record(iConfig.getParameter<std::string>("record")),
0071       m_tag(iConfig.getParameter<std::string>("tag")),
0072       m_value(iConfig.getParameter<double>("value")) {}
0073 
0074 SiPhase2OuterTrackerLorentzAngleWriter::~SiPhase2OuterTrackerLorentzAngleWriter() {
0075   edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
0076       << "SiPhase2OuterTrackerLorentzAngleWriter::~SiPhase2OuterTrackerLorentzAngleWriter" << std::endl;
0077 }
0078 
0079 //
0080 // member functions
0081 //
0082 
0083 // ------------ method called for each event  ------------
0084 void SiPhase2OuterTrackerLorentzAngleWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0085   using Phase2TrackerGeomDetUnit = PixelGeomDetUnit;
0086   using namespace edm;
0087   edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
0088       << "SiPhase2OuterTrackerLorentzAngleWriter::analyze " << std::endl;
0089 
0090   // Database services (write)
0091   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0092   if (!mydbservice.isAvailable()) {
0093     edm::LogWarning("SiPhase2OuterTrackerLorentzAngleWriter") << "Service is unavailable" << std::endl;
0094     return;
0095   }
0096 
0097   std::string tag = mydbservice->tag(m_record);
0098   unsigned int irun = iEvent.id().run();
0099   edm::LogVerbatim("SiPhase2OuterTrackerLorentzAngleWriter") << "Writing on tag : " << tag << std::endl;
0100   edm::LogVerbatim("SiPhase2OuterTrackerLorentzAngleWriter") << "Usinng as IOV run : " << irun << std::endl;
0101 
0102   // map to be filled
0103   std::unordered_map<unsigned int, float> detsLAtoDB;
0104 
0105   // Retrieve tracker topology from geometry
0106   const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
0107 
0108   // Retrieve old style tracker geometry from geometry
0109   const TrackerGeometry* pDD = &iSetup.getData(geomToken_);
0110   edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
0111       << " There are " << pDD->detUnits().size() << " modules in this geometry." << std::endl;
0112 
0113   for (auto const& det_u : pDD->detUnits()) {
0114     const DetId detid = det_u->geographicalId();
0115     uint32_t rawId = detid.rawId();
0116     int subid = detid.subdetId();
0117     if (detid.det() == DetId::Detector::Tracker) {
0118       const Phase2TrackerGeomDetUnit* pixdet = dynamic_cast<const Phase2TrackerGeomDetUnit*>(det_u);
0119       assert(pixdet);
0120       LogDebug("SiPhase2OuterTrackerLorentzAngleWriter") << rawId << " is a " << subid << " det" << std::endl;
0121       if (subid == StripSubdetector::TOB || subid == StripSubdetector::TID) {
0122         LogDebug("SiPhase2OuterTrackerLorentzAngleWriter")
0123             << "subdetector ID:" << subid << " layer:" << tTopo->layer(detid) << std::endl;
0124         detsLAtoDB[rawId] = m_value;
0125       }
0126     }
0127   }
0128 
0129   edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter")
0130       << " There are " << detsLAtoDB.size() << " OT Lorentz Angle values assigned" << std::endl;
0131 
0132   // SiPhase2OuterTrackerLorentzAngle object
0133   auto lorentzAngle = std::make_unique<SiPhase2OuterTrackerLorentzAngle>();
0134   lorentzAngle->putLorentzAngles(detsLAtoDB);
0135   edm::LogInfo("SiPhase2OuterTrackerLorentzAngleWriter") << "currentTime " << mydbservice->currentTime() << std::endl;
0136   mydbservice->writeOneIOV(*lorentzAngle, mydbservice->currentTime(), m_record);
0137 }
0138 
0139 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0140 void SiPhase2OuterTrackerLorentzAngleWriter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0141   edm::ParameterSetDescription desc;
0142   desc.setComment("Module to write SiPhase2OuterTrackerLorentzAngle Payloads");
0143   desc.add<std::string>("record", "SiPhase2OuterTrackerLorentzAngleRcd")->setComment("record to write");
0144   desc.add<std::string>("tag", "SiPhase2OuterTrackerLorentzAngle")->setComment("tag to write");
0145   desc.add<double>("value", 0.07)->setComment("value to be put in the payload");
0146   descriptions.addWithDefaultLabel(desc);
0147 }
0148 
0149 //define this as a plug-in
0150 DEFINE_FWK_MODULE(SiPhase2OuterTrackerLorentzAngleWriter);