CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
SiStripLorentzAnglePCLHarvester Class Reference

#include <CalibTracker/SiStripLorentzAngle/plugins/SiStripLorentzAnglePCLHarvester.cc>

Inheritance diagram for SiStripLorentzAnglePCLHarvester:
DQMEDHarvester edm::one::EDProducer< edm::EndLuminosityBlockProducer, edm::EndRunProducer, edm::EndProcessBlockProducer, edm::one::WatchLuminosityBlocks, edm::one::WatchRuns, edm::one::SharedResources, edm::Accumulator > edm::one::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

void beginRun (const edm::Run &, const edm::EventSetup &) override
 
 SiStripLorentzAnglePCLHarvester (const edm::ParameterSet &)
 
 ~SiStripLorentzAnglePCLHarvester () override=default
 
- Public Member Functions inherited from DQMEDHarvester
void accumulate (edm::Event const &ev, edm::EventSetup const &es) final
 
void beginJob () override
 
void beginLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &) final
 
void beginRun (edm::Run const &run, edm::EventSetup const &) override
 
virtual void dqmAnalyze (DQMStore::IBooker &, DQMStore::IGetter &, edm::Event const &, edm::EventSetup const &)
 
 DQMEDHarvester (edm::ParameterSet const &iConfig)
 
 DQMEDHarvester ()
 
virtual void dqmEndLuminosityBlock (DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
 
virtual void dqmEndRun (DQMStore::IBooker &, DQMStore::IGetter &, edm::Run const &, edm::EventSetup const &)
 
void endLuminosityBlock (edm::LuminosityBlock const &, edm::EventSetup const &) final
 
void endLuminosityBlockProduce (edm::LuminosityBlock &lumi, edm::EventSetup const &es) final
 
void endProcessBlockProduce (edm::ProcessBlock &) final
 
void endRun (edm::Run const &, edm::EventSetup const &) override
 
void endRunProduce (edm::Run &run, edm::EventSetup const &es) final
 
 ~DQMEDHarvester () override=default
 
- Public Member Functions inherited from edm::one::EDProducer< edm::EndLuminosityBlockProducer, edm::EndRunProducer, edm::EndProcessBlockProducer, edm::one::WatchLuminosityBlocks, edm::one::WatchRuns, edm::one::SharedResources, edm::Accumulator >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
- Static Public Member Functions inherited from edm::one::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

void dqmEndJob (DQMStore::IBooker &, DQMStore::IGetter &) override
 
void endRun (const edm::Run &, const edm::EventSetup &) override
 
std::string getStem (const std::string &histoName, bool isFolder)
 

Private Attributes

const SiStripLorentzAnglecurrentLorentzAngle_
 
const bool debug_
 
const std::string dqmDir_
 
const std::vector< double > fitRange_
 
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecordgeomEsToken_
 
SiStripLorentzAngleCalibrationHistograms iHists_
 
const edm::ESGetToken< SiStripLatency, SiStripLatencyRcdlatencyToken_
 
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecordmagneticFieldToken_
 
bool mismatchedBField_
 
bool mismatchedLatency_
 
const std::string recordName_
 
const edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleDepRcdsiStripLAEsToken_
 
std::pair< double, double > theFitRange_ {0., 0.}
 
float theMagField_ {0.f}
 
std::unique_ptr< TrackerTopologytheTrackerTopology_
 
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcdtopoEsTokenBR_
 
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcdtopoEsTokenER_
 

Static Private Attributes

static constexpr float teslaToInverseGeV_ = 2.99792458e-3f
 

Additional Inherited Members

- Public Types inherited from DQMEDHarvester
typedef dqm::harvesting::DQMStore DQMStore
 
typedef dqm::harvesting::MonitorElement MonitorElement
 
- Public Types inherited from edm::one::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 
- Protected Attributes inherited from DQMEDHarvester
DQMStoredqmstore_
 
edm::GetterOfProducts< DQMTokenjobmegetter_
 
edm::EDPutTokenT< DQMTokenjobToken_
 
edm::GetterOfProducts< DQMTokenlumimegetter_
 
edm::EDPutTokenT< DQMTokenlumiToken_
 
edm::GetterOfProducts< DQMTokenrunmegetter_
 
edm::EDPutTokenT< DQMTokenrunToken_
 

Detailed Description

Description: reads the intermediate ALCAPROMPT DQMIO-like dataset and performs the fitting of the SiStrip Lorentz Angle in the Prompt Calibration Loop

Definition at line 46 of file SiStripLorentzAnglePCLHarvester.cc.

Constructor & Destructor Documentation

◆ SiStripLorentzAnglePCLHarvester()

SiStripLorentzAnglePCLHarvester::SiStripLorentzAnglePCLHarvester ( const edm::ParameterSet iConfig)

Definition at line 87 of file SiStripLorentzAnglePCLHarvester.cc.

88  : geomEsToken_(esConsumes<edm::Transition::BeginRun>()),
89  topoEsTokenBR_(esConsumes<edm::Transition::BeginRun>()),
90  topoEsTokenER_(esConsumes<edm::Transition::EndRun>()),
91  latencyToken_(esConsumes<edm::Transition::BeginRun>()),
92  siStripLAEsToken_(esConsumes<edm::Transition::BeginRun>()),
93  magneticFieldToken_(esConsumes<edm::Transition::BeginRun>()),
94  mismatchedBField_{false},
95  mismatchedLatency_{false},
96  debug_(iConfig.getParameter<bool>("debugMode")),
97  dqmDir_(iConfig.getParameter<std::string>("dqmDir")),
98  fitRange_(iConfig.getParameter<std::vector<double>>("fitRange")),
99  recordName_(iConfig.getParameter<std::string>("record")) {
100  // initialize the fit range
101  if (fitRange_.size() == 2) {
102  theFitRange_.first = fitRange_[0];
103  theFitRange_.second = fitRange_[1];
104  } else {
105  throw cms::Exception("SiStripLorentzAnglePCLHarvester") << "Too many fit range parameters specified";
106  }
107 
108  // first ensure DB output service is available
110  if (!poolDbService.isAvailable())
111  throw cms::Exception("SiStripLorentzAnglePCLHarvester") << "PoolDBService required";
112 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomEsToken_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenBR_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
bool isAvailable() const
Definition: Service.h:40
const edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleDepRcd > siStripLAEsToken_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenER_
const edm::ESGetToken< SiStripLatency, SiStripLatencyRcd > latencyToken_

◆ ~SiStripLorentzAnglePCLHarvester()

SiStripLorentzAnglePCLHarvester::~SiStripLorentzAnglePCLHarvester ( )
overridedefault

Member Function Documentation

◆ beginRun()

void SiStripLorentzAnglePCLHarvester::beginRun ( const edm::Run iRun,
const edm::EventSetup iSetup 
)
override

Definition at line 115 of file SiStripLorentzAnglePCLHarvester.cc.

References SiStripLorentzAngleCalibrationHistograms::apvmode_, siStripLACalibration::apvModeAsString(), SiStripLorentzAngleCalibrationHistograms::bfield_, currentLorentzAngle_, siStripLACalibration::fieldAsString(), relativeConstraints::geom, geomEsToken_, edm::EventSetup::getData(), SiStripLorentzAngle::getLorentzAngle(), iHists_, MagneticField::inverseBzAtOriginInGeV(), SiStripLorentzAngleCalibrationHistograms::la_db_, latencyToken_, magneticFieldToken_, mismatchedBField_, mismatchedLatency_, siStripLACalibration::moduleLocationType(), SiStripLorentzAngleCalibrationHistograms::moduleLocationType_, siStripLAEsToken_, teslaToInverseGeV_, theMagField_, and topoEsTokenBR_.

115  {
116  // geometry
117  const TrackerGeometry* geom = &iSetup.getData(geomEsToken_);
118  const TrackerTopology* tTopo = &iSetup.getData(topoEsTokenBR_);
119 
120  const MagneticField* magField = &iSetup.getData(magneticFieldToken_);
122 
123  // B-field value
124  // inverseBzAtOriginInGeV() returns the inverse of field z component for this map in GeV
125  // for the conversion please consult https://github.com/cms-sw/cmssw/blob/master/MagneticField/Engine/src/MagneticField.cc#L17
126  // theInverseBzAtOriginInGeV = 1.f / (at0z * 2.99792458e-3f);
127  // ==> at0z = 1.f / (theInverseBzAtOriginInGeV * 2.99792458e-3f)
128 
130 
131  if (iHists_.bfield_.empty()) {
133  } else {
135  mismatchedBField_ = true;
136  }
137  }
138 
139  const SiStripLatency* apvlat = &iSetup.getData(latencyToken_);
140  if (iHists_.apvmode_.empty()) {
142  } else {
144  mismatchedLatency_ = true;
145  }
146  }
147 
148  auto dets = geom->detsTIB();
149  dets.insert(dets.end(), geom->detsTID().begin(), geom->detsTID().end());
150  dets.insert(dets.end(), geom->detsTOB().begin(), geom->detsTOB().end());
151  dets.insert(dets.end(), geom->detsTEC().begin(), geom->detsTEC().end());
152 
153  for (auto det : dets) {
154  auto detid = det->geographicalId().rawId();
155  const StripGeomDetUnit* stripDet = dynamic_cast<const StripGeomDetUnit*>(geom->idToDet(det->geographicalId()));
156  if (stripDet) {
159  }
160  }
161 }
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomEsToken_
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
float inverseBzAtOriginInGeV() const
The inverse of field z component for this map in GeV.
Definition: MagneticField.h:52
SiStripLorentzAngleCalibrationHistograms iHists_
const std::string fieldAsString(const float &inputField)
const std::string apvModeAsString(const SiStripLatency *latency)
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenBR_
float getLorentzAngle(const uint32_t &) const
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldToken_
const SiStripLorentzAngle * currentLorentzAngle_
std::string moduleLocationType(const uint32_t &mod, const TrackerTopology *tTopo)
Generates a module location type string based on the detector ID and topology information.
const edm::ESGetToken< SiStripLorentzAngle, SiStripLorentzAngleDepRcd > siStripLAEsToken_
const edm::ESGetToken< SiStripLatency, SiStripLatencyRcd > latencyToken_

◆ dqmEndJob()

void SiStripLorentzAnglePCLHarvester::dqmEndJob ( DQMStore::IBooker iBooker,
DQMStore::IGetter iGetter 
)
overrideprivatevirtual

Implements DQMEDHarvester.

Definition at line 171 of file SiStripLorentzAnglePCLHarvester.cc.

References funct::abs(), mixOne_premix_on_sim_cfi::accumulator, SiStripLorentzAngleCalibrationHistograms::apvmode_, SiStripLorentzAngleCalibrationHistograms::bfield_, dqm::implementation::IBooker::book2D(), dqm::implementation::IBooker::bookProfile(), dqm::implementation::NavigatorBase::cd(), currentLorentzAngle_, cond::service::PoolDBOutputService::currentTime(), debug_, dqmDir_, cppFunctionSkipper::exception, Exception, f, spr::find(), siStripLACalibration::fitFunction(), dqm-mbProfile::format, dqm::implementation::IGetter::get(), SiStripLorentzAngle::getLorentzAngle(), getStem(), dqm::impl::MonitorElement::getTH2F(), SiStripLorentzAngleCalibrationHistograms::h2_, SiStripLorentzAngleCalibrationHistograms::h2_byLayerDiff_, SiStripLorentzAngleCalibrationHistograms::h2_byLayerLA_, LaserClient_cfi::high, trackingPlots::hp, iHists_, edm::Service< T >::isAvailable(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, MainPageGenerator::l, SiStripLorentzAngleCalibrationHistograms::la_db_, label, nano_mu_digi_cff::layer, hgcalTBTopologyTester_cfi::layers, siStripLACalibration::locationTypeIndex(), LogDebug, LogTrace, LaserClient_cfi::low, DiMuonMassBiasClient_cfi::MEtoHarvest, mismatchedBField_, mismatchedLatency_, SiStripLorentzAngleCalibrationHistograms::modtypes_, edm::one::EDProducerBase::moduleDescription(), SiStripLorentzAngleCalibrationHistograms::moduleLocationType_, EcalCalibMonitorClient_cfi::moduleName, nlayers, SiStripLorentzAngleCalibrationHistograms::nlayers_, SiStripLorentzAngleCalibrationHistograms::p_, recordName_, dqm::impl::MonitorElement::setBinContent(), dqm::implementation::NavigatorBase::setCurrentFolder(), AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, theFitRange_, theMagField_, cms::Exception::what(), and cond::service::PoolDBOutputService::writeOneIOV().

171  {
172  if (mismatchedBField_) {
173  throw cms::Exception("SiStripLorentzAnglePCLHarvester") << "Trying to harvest runs with different B-field values!";
174  }
175 
176  if (mismatchedLatency_) {
177  throw cms::Exception("SiStripLorentzAnglePCLHarvester") << "Trying to harvest runs with diffent APV modes!";
178  }
179 
180  // go in the right directory
181  iGetter.cd();
182  std::string bvalue = (iHists_.bfield_ == "3.8") ? "B-ON" : "B-OFF";
183  std::string folderToHarvest = fmt::format("{}/{}_{}", dqmDir_, bvalue, iHists_.apvmode_);
184  edm::LogPrint(moduleDescription().moduleName()) << "Harvesting in " << folderToHarvest;
185  iGetter.setCurrentFolder(folderToHarvest);
186 
187  // fill in the module types
188  iHists_.nlayers_["TIB"] = 4;
189  iHists_.nlayers_["TOB"] = 6;
190  iHists_.modtypes_.push_back("s");
191  iHists_.modtypes_.push_back("a");
192 
193  std::vector<std::string> MEtoHarvest = {"tanthcosphtrk_nstrip",
194  "thetatrk_nstrip",
195  "tanthcosphtrk_var2",
196  "tanthcosphtrk_var3",
197  "thcosphtrk_var2",
198  "thcosphtrk_var3"};
199 
200  // prepare the histograms to be harvested
201  for (auto& layers : iHists_.nlayers_) {
202  std::string subdet = layers.first;
203  for (int l = 1; l <= layers.second; ++l) {
204  for (auto& t : iHists_.modtypes_) {
205  // do not fill stereo where there aren't
206  if (l > 2 && t == "s")
207  continue;
208  std::string locationtype = Form("%s_L%d%s", subdet.c_str(), l, t.c_str());
209  for (const auto& toHarvest : MEtoHarvest) {
210  const char* address = Form(
211  "%s/%s/L%d/%s_%s", folderToHarvest.c_str(), subdet.c_str(), l, locationtype.c_str(), toHarvest.c_str());
212 
213  LogDebug(moduleDescription().moduleName()) << "harvesting at: " << address << std::endl;
214 
215  iHists_.h2_[Form("%s_%s", locationtype.c_str(), toHarvest.c_str())] = iGetter.get(address);
216  if (iHists_.h2_[Form("%s_%s", locationtype.c_str(), toHarvest.c_str())] == nullptr) {
218  << "could not retrieve: " << Form("%s_%s", locationtype.c_str(), toHarvest.c_str());
219  }
220  }
221  }
222  }
223  }
224 
225  // book the summary output histograms
226  iBooker.setCurrentFolder(fmt::format("{}Harvesting/LorentzAngleMaps", dqmDir_));
227 
228  // Define a lambda function to extract the second element and add it to the accumulator
229  auto sumValues = [](int accumulator, const std::pair<std::string, int>& element) {
230  return accumulator + element.second;
231  };
232 
233  // Use std::accumulate to sum the values
234  int totalLayers = std::accumulate(iHists_.nlayers_.begin(), iHists_.nlayers_.end(), 0, sumValues);
235 
236  // Lambda expression to set bin labels for a TH2F histogram
237  auto setHistoLabels = [](TH2F* histogram, const std::map<std::string, int>& nlayers) {
238  // Set common options
239  histogram->SetOption("colz1"); // don't fill empty bins
240  histogram->SetStats(false);
241  histogram->GetYaxis()->SetLabelSize(0.05);
242  histogram->GetXaxis()->SetLabelSize(0.05);
243 
244  // Set bin labels for the X-axis
245  histogram->GetXaxis()->SetBinLabel(1, "r-#phi");
246  histogram->GetXaxis()->SetBinLabel(2, "stereo");
247 
248  // Set bin labels for the Y-axis
249  int binCounter = 1;
250  for (const auto& subdet : {"TIB", "TOB"}) {
251  for (int layer = 1; layer <= nlayers.at(subdet); ++layer) {
252  std::string label = Form("%s L%d", subdet, layer);
253  histogram->GetYaxis()->SetBinLabel(binCounter++, label.c_str());
254  }
255  }
256  histogram->GetXaxis()->LabelsOption("h");
257  };
258 
259  std::string d_name = "h2_byLayerSiStripLA";
260  std::string d_text = "SiStrip tan#theta_{LA}/B;module type (r-#phi/stereo);layer number;tan#theta_{LA}/B [1/T]";
262  iBooker.book2D(d_name.c_str(), d_text.c_str(), 2, -0.5, 1.5, totalLayers, -0.5, totalLayers - 0.5);
263 
264  setHistoLabels(iHists_.h2_byLayerLA_->getTH2F(), iHists_.nlayers_);
265 
266  d_name = "h2_byLayerSiStripLADiff";
267  d_text = "SiStrip #Delta#mu_{H}/#mu_{H};module type (r-#phi/stereo);ladder number;#Delta#mu_{H}/#mu_{H} [%%]";
269  iBooker.book2D(d_name.c_str(), d_text.c_str(), 2, -0.5, 1.5, totalLayers, -0.5, totalLayers - 0.5);
270 
271  setHistoLabels(iHists_.h2_byLayerDiff_->getTH2F(), iHists_.nlayers_);
272 
273  // prepare the profiles
274  for (const auto& ME : iHists_.h2_) {
275  if (!ME.second)
276  continue;
277  // draw colored 2D plots
278  ME.second->setOption("colz");
279  TProfile* hp = (TProfile*)ME.second->getTH2F()->ProfileX();
280  iBooker.setCurrentFolder(folderToHarvest + "/" + getStem(ME.first, /* isFolder = */ true));
281  iHists_.p_[hp->GetName()] = iBooker.bookProfile(hp->GetName(), hp);
282  iHists_.p_[hp->GetName()]->setAxisTitle(ME.second->getAxisTitle(2), 2);
283  delete hp;
284  }
285 
286  if (iHists_.p_.empty()) {
287  edm::LogError(moduleDescription().moduleName()) << "None of the input histograms could be retrieved. Aborting";
288  return;
289  }
290 
291  std::map<std::string, std::pair<double, double>> LAMap_;
292 
293  // do the fits
294  for (const auto& prof : iHists_.p_) {
295  //fit only this type of profile
296  if ((prof.first).find("thetatrk_nstrip") != std::string::npos) {
297  // Create the TF1 function
298 
299  // fitting range (take full axis by default)
300  double low = prof.second->getAxisMin(1);
301  double high = prof.second->getAxisMax(1);
302  if (theFitRange_.first > theFitRange_.second) {
303  low = theFitRange_.first;
304  high = theFitRange_.second;
305  }
306 
307  TF1* fitFunc = new TF1("fitFunc", siStripLACalibration::fitFunction, low, high, 3);
308 
309  // Fit the function to the data
310  prof.second->getTProfile()->Fit(fitFunc, "F"); // "F" option performs a least-squares fit
311 
312  // Get the fit results
313  Double_t a_fit = fitFunc->GetParameter(0);
314  Double_t thetaL_fit = fitFunc->GetParameter(1);
315  Double_t b_fit = fitFunc->GetParameter(2);
316 
317  Double_t a_fitError = fitFunc->GetParError(0);
318  Double_t thetaL_fitError = fitFunc->GetParError(1);
319  Double_t b_fitError = fitFunc->GetParError(2);
320 
321  if (debug_) {
323  << prof.first << " fit result: "
324  << " a=" << a_fit << " +/ " << a_fitError << " theta_L=" << thetaL_fit << " +/- " << thetaL_fitError
325  << " b=" << b_fit << " +/- " << b_fitError;
326  }
327 
328  LAMap_[getStem(prof.first, /* isFolder = */ false)] = std::make_pair(thetaL_fit, thetaL_fitError);
329  }
330  }
331 
332  if (debug_) {
333  for (const auto& element : LAMap_) {
335  << element.first << " thetaLA = " << element.second.first << "+/-" << element.second.second;
336  }
337  }
338 
339  // now prepare the output LA
340  std::shared_ptr<SiStripLorentzAngle> OutLorentzAngle = std::make_shared<SiStripLorentzAngle>();
341 
342  bool isPayloadChanged{false};
343  std::vector<std::pair<int, int>> treatedIndices;
344  for (const auto& loc : iHists_.moduleLocationType_) {
345  if (debug_) {
346  edm::LogInfo(moduleDescription().moduleName()) << "modId: " << loc.first << " " << loc.second;
347  }
348 
349  if (!(loc.second).empty() && theMagField_ != 0.f) {
350  OutLorentzAngle->putLorentzAngle(loc.first, std::abs(LAMap_[loc.second].first / theMagField_));
351  } else {
352  OutLorentzAngle->putLorentzAngle(loc.first, iHists_.la_db_[loc.first]);
353  }
354 
355  // if the location is not assigned (e.g. TID or TEC) continue
356  if ((loc.second).empty()) {
357  continue;
358  }
359 
360  const auto& index2D = siStripLACalibration::locationTypeIndex(loc.second);
361  LogDebug("SiStripLorentzAnglePCLHarvester")
362  << loc.first << " : " << loc.second << " index: " << index2D.first << "-" << index2D.second << std::endl;
363 
364  // check if the location exists, otherwise throw!
365  if (index2D != std::make_pair(-1, -1)) {
366  // Check if index2D is in treatedIndices
367  // Do not fill the control plots more than necessary (i.e. 1 entry per "partition")
368  auto it = std::find(treatedIndices.begin(), treatedIndices.end(), index2D);
369  if (it == treatedIndices.end()) {
370  // control plots
371  LogTrace("SiStripLorentzAnglePCLHarvester") << "accepted " << loc.first << " : " << loc.second << " bin ("
372  << index2D.first << "," << index2D.second << ")";
373 
374  const auto& outputLA = OutLorentzAngle->getLorentzAngle(loc.first);
375  const auto& inputLA = currentLorentzAngle_->getLorentzAngle(loc.first);
376 
377  LogTrace("SiStripLorentzAnglePCLHarvester") << "inputLA: " << inputLA << " outputLA: " << outputLA;
378 
379  iHists_.h2_byLayerLA_->setBinContent(index2D.first, index2D.second, outputLA);
380 
381  float deltaMuHoverMuH = (inputLA != 0.f) ? (inputLA - outputLA) / inputLA : 0.f;
382  iHists_.h2_byLayerDiff_->setBinContent(index2D.first, index2D.second, deltaMuHoverMuH * 100.f);
383  treatedIndices.emplace_back(index2D);
384 
385  // Check if the delta is different from zero
386  // if none of the locations has a non-zero diff
387  // will not write out the payload.
388  if (deltaMuHoverMuH != 0.f) {
389  isPayloadChanged = true;
390  LogDebug("SiStripLorentzAnglePCLHarvester")
391  << "accepted " << loc.first << " : " << loc.second << " bin (" << index2D.first << "," << index2D.second
392  << ") " << deltaMuHoverMuH;
393  }
394 
395  } // if the index has not been treated already
396  } else {
397  throw cms::Exception("SiStripLorentzAnglePCLHarvester")
398  << "Trying to fill an inexistent module location from " << loc.second << "!";
399  } //
400  } // ends loop on location types
401 
402  if (isPayloadChanged) {
403  // fill the DB object record
405  if (mydbservice.isAvailable()) {
406  try {
407  mydbservice->writeOneIOV(*OutLorentzAngle, mydbservice->currentTime(), recordName_);
408  } catch (const cond::Exception& er) {
409  edm::LogError("SiStripLorentzAngleDB") << er.what();
410  } catch (const std::exception& er) {
411  edm::LogError("SiStripLorentzAngleDB") << "caught std::exception " << er.what();
412  }
413  } else {
414  edm::LogError("SiStripLorentzAngleDB") << "Service is unavailable!";
415  }
416  } else {
417  edm::LogPrint("SiStripLorentzAngleDB")
418  << "****** WARNING ******\n* " << __PRETTY_FUNCTION__
419  << "\n* There is no new valid measurement to append!\n* Will NOT update the DB!\n*********************";
420  }
421 }
Base exception class for the object to relational access.
Definition: Exception.h:11
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
ModuleDescription const & moduleDescription() const
double fitFunction(double *x, double *par)
Log< level::Error, false > LogError
std::pair< int, int > locationTypeIndex(const std::string &locType)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
#define LogTrace(id)
Definition: ME.h:11
char const * label
std::map< std::string, dqm::reco::MonitorElement * > p_
SiStripLorentzAngleCalibrationHistograms iHists_
std::map< std::string, dqm::reco::MonitorElement * > h2_
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
double f[11][100]
Log< level::Warning, true > LogPrint
Log< level::Info, false > LogInfo
float getLorentzAngle(const uint32_t &) const
std::string getStem(const std::string &histoName, bool isFolder)
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
const SiStripLorentzAngle * currentLorentzAngle_
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:712
bool isAvailable() const
Definition: Service.h:40
char const * what() const noexcept override
Definition: Exception.cc:107
#define LogDebug(id)

◆ endRun()

void SiStripLorentzAnglePCLHarvester::endRun ( const edm::Run run,
const edm::EventSetup isetup 
)
overrideprivate

Definition at line 164 of file SiStripLorentzAnglePCLHarvester.cc.

References edm::EventSetup::getData(), theTrackerTopology_, and topoEsTokenER_.

164  {
165  if (!theTrackerTopology_) {
166  theTrackerTopology_ = std::make_unique<TrackerTopology>(isetup.getData(topoEsTokenER_));
167  }
168 }
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::unique_ptr< TrackerTopology > theTrackerTopology_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoEsTokenER_

◆ fillDescriptions()

void SiStripLorentzAnglePCLHarvester::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 447 of file SiStripLorentzAnglePCLHarvester.cc.

References edm::ConfigurationDescriptions::addWithDefaultLabel(), submitPVResolutionJobs::desc, and AlCaHLTBitMon_QueryRunRegistry::string.

447  {
449  desc.setComment("Harvester module of the SiStrip Lorentz Angle PCL monitoring workflow");
450  desc.add<bool>("debugMode", false)->setComment("determines if it's in debug mode");
451  desc.add<std::string>("dqmDir", "AlCaReco/SiStripLorentzAngle")->setComment("the directory of PCL Worker output");
452  desc.add<std::vector<double>>("fitRange", {0., 0.})->setComment("range of depths to perform the LA fit");
453  desc.add<std::string>("record", "SiStripLorentzAngleRcd")->setComment("target DB record");
454  descriptions.addWithDefaultLabel(desc);
455 }
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)

◆ getStem()

std::string SiStripLorentzAnglePCLHarvester::getStem ( const std::string &  histoName,
bool  isFolder 
)
private

Definition at line 424 of file SiStripLorentzAnglePCLHarvester.cc.

References HltBtagPostValidation_cff::histoName, convertSQLitetoXML_cfg::output, AlCaHLTBitMon_QueryRunRegistry::string, and unpackBuffers-CaloStage2::token.

Referenced by dqmEndJob().

424  {
425  std::vector<std::string> tokens;
426 
428  // Create a string stream from the input string
429  std::istringstream iss(histoName);
430 
432  while (std::getline(iss, token, '_')) {
433  // Add each token to the vector
434  tokens.push_back(token);
435  }
436 
437  if (isFolder) {
438  output = tokens[0] + "/" + tokens[1];
439  output.pop_back();
440  } else {
441  output = tokens[0] + "_" + tokens[1];
442  }
443  return output;
444 }
Definition: output.py:1

Member Data Documentation

◆ currentLorentzAngle_

const SiStripLorentzAngle* SiStripLorentzAnglePCLHarvester::currentLorentzAngle_
private

Definition at line 82 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun(), and dqmEndJob().

◆ debug_

const bool SiStripLorentzAnglePCLHarvester::debug_
private

Definition at line 71 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by dqmEndJob().

◆ dqmDir_

const std::string SiStripLorentzAnglePCLHarvester::dqmDir_
private

Definition at line 74 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by dqmEndJob().

◆ fitRange_

const std::vector<double> SiStripLorentzAnglePCLHarvester::fitRange_
private

Definition at line 75 of file SiStripLorentzAnglePCLHarvester.cc.

◆ geomEsToken_

const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> SiStripLorentzAnglePCLHarvester::geomEsToken_
private

Definition at line 60 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun().

◆ iHists_

SiStripLorentzAngleCalibrationHistograms SiStripLorentzAnglePCLHarvester::iHists_
private

Definition at line 72 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun(), and dqmEndJob().

◆ latencyToken_

const edm::ESGetToken<SiStripLatency, SiStripLatencyRcd> SiStripLorentzAnglePCLHarvester::latencyToken_
private

Definition at line 62 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun().

◆ magneticFieldToken_

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> SiStripLorentzAnglePCLHarvester::magneticFieldToken_
private

Definition at line 64 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun().

◆ mismatchedBField_

bool SiStripLorentzAnglePCLHarvester::mismatchedBField_
private

Definition at line 68 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun(), and dqmEndJob().

◆ mismatchedLatency_

bool SiStripLorentzAnglePCLHarvester::mismatchedLatency_
private

Definition at line 69 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun(), and dqmEndJob().

◆ recordName_

const std::string SiStripLorentzAnglePCLHarvester::recordName_
private

Definition at line 76 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by dqmEndJob().

◆ siStripLAEsToken_

const edm::ESGetToken<SiStripLorentzAngle, SiStripLorentzAngleDepRcd> SiStripLorentzAnglePCLHarvester::siStripLAEsToken_
private

Definition at line 63 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun().

◆ teslaToInverseGeV_

constexpr float SiStripLorentzAnglePCLHarvester::teslaToInverseGeV_ = 2.99792458e-3f
staticprivate

Definition at line 79 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun().

◆ theFitRange_

std::pair<double, double> SiStripLorentzAnglePCLHarvester::theFitRange_ {0., 0.}
private

Definition at line 80 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by dqmEndJob().

◆ theMagField_

float SiStripLorentzAnglePCLHarvester::theMagField_ {0.f}
private

Definition at line 77 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun(), and dqmEndJob().

◆ theTrackerTopology_

std::unique_ptr<TrackerTopology> SiStripLorentzAnglePCLHarvester::theTrackerTopology_
private

Definition at line 83 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by endRun().

◆ topoEsTokenBR_

const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> SiStripLorentzAnglePCLHarvester::topoEsTokenBR_
private

Definition at line 61 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by beginRun().

◆ topoEsTokenER_

const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> SiStripLorentzAnglePCLHarvester::topoEsTokenER_
private

Definition at line 61 of file SiStripLorentzAnglePCLHarvester.cc.

Referenced by endRun().