CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
RawPCCProducer Class Reference
Inheritance diagram for RawPCCProducer:
edm::global::EDProducer< edm::EndLuminosityBlockProducer > edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 RawPCCProducer (const edm::ParameterSet &)
 
 ~RawPCCProducer () override
 
- Public Member Functions inherited from edm::global::EDProducer< edm::EndLuminosityBlockProducer >
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () 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)
 

Private Member Functions

void globalEndLuminosityBlockProduce (edm::LuminosityBlock &lumiSeg, const edm::EventSetup &iSetup) const final
 
void produce (edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const final
 

Private Attributes

const bool applyCorr_
 
const std::string csvOutLabel_
 
std::mutex fileLock_
 
const edm::ESGetToken< LumiCorrections, LumiCorrectionsRcdlumiCorrectionsToken_
 
const std::vector< int > modVeto_
 
edm::EDGetTokenT< reco::PixelClusterCountspccToken_
 
const edm::EDPutTokenT< LumiInfoputToken_
 
const bool saveCSVFile_
 
const std::string takeAverageValue_
 

Additional Inherited Members

- Public Types inherited from edm::global::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
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- 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)
 

Detailed Description


class: RawPCCProducer.cc

description: Creates a LumiInfo object that will contain the luminosity per bunch crossing, along with the total luminosity and the statistical error.

authors:Sam Higginbotham (shigg.nosp@m.inb@.nosp@m.cern..nosp@m.ch), Chris Palmer (capal.nosp@m.mer@.nosp@m.cern..nosp@m.ch), Jose Benitez (jose..nosp@m.beni.nosp@m.tez@c.nosp@m.ern..nosp@m.ch)


Definition at line 34 of file RawPCCProducer.cc.

Constructor & Destructor Documentation

◆ RawPCCProducer()

RawPCCProducer::RawPCCProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 64 of file RawPCCProducer.cc.

65  : pccToken_(consumes<reco::PixelClusterCounts, edm::InLumi>(edm::InputTag(
66  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("inputPccLabel"),
67  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("ProdInst")))),
68  lumiCorrectionsToken_(esConsumes<edm::Transition::EndLuminosityBlock>()),
69  modVeto_(
70  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::vector<int>>("modVeto")),
71  applyCorr_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
72  .getUntrackedParameter<bool>("ApplyCorrections", false)),
73  takeAverageValue_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
74  .getUntrackedParameter<std::string>("OutputValue", std::string("Average"))),
75  putToken_(produces<LumiInfo, edm::Transition::EndLuminosityBlock>(
76  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
77  .getUntrackedParameter<std::string>("outputProductName", "alcaLumi"))),
78  saveCSVFile_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
79  .getUntrackedParameter<bool>("saveCSVFile", false)),
80  csvOutLabel_(iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
81  .getUntrackedParameter<std::string>("label", std::string("rawPCC.csv"))) {}
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const edm::ESGetToken< LumiCorrections, LumiCorrectionsRcd > lumiCorrectionsToken_
const std::string csvOutLabel_
const std::string takeAverageValue_
T getUntrackedParameter(std::string const &, T const &) const
const bool applyCorr_
const edm::EDPutTokenT< LumiInfo > putToken_
const std::vector< int > modVeto_
const bool saveCSVFile_
edm::EDGetTokenT< reco::PixelClusterCounts > pccToken_

◆ ~RawPCCProducer()

RawPCCProducer::~RawPCCProducer ( )
override

Definition at line 84 of file RawPCCProducer.cc.

84 {}

Member Function Documentation

◆ globalEndLuminosityBlockProduce()

void RawPCCProducer::globalEndLuminosityBlockProduce ( edm::LuminosityBlock lumiSeg,
const edm::EventSetup iSetup 
) const
finalprivate

read input , clusters per module per bx

Apply the module veto

Compute average number of clusters per event

Lumi saved in the LuminosityBlocks

Definition at line 90 of file RawPCCProducer.cc.

References applyCorr_, nano_mu_digi_cff::bx, csvOutLabel_, edm::LuminosityBlock::emplace(), events, fileLock_, spr::find(), nano_mu_digi_cff::float, edm::EventSetup::getData(), edm::LuminosityBlock::getHandle(), mps_fire::i, createfilelist::int, CommonMethods::lock(), lumiCorrectionsToken_, edm::LuminosityBlockBase::luminosityBlock(), modVeto_, eostools::move(), LumiConstants::numBX, pccToken_, edm::Handle< T >::product(), putToken_, reco::PixelClusterCounts::readCounts(), reco::PixelClusterCounts::readEvents(), reco::PixelClusterCounts::readModID(), edm::LuminosityBlockBase::run(), saveCSVFile_, LumiInfo::setErrorLumiAllBX(), LumiInfo::setInstLumiAllBX(), LumiInfo::setTotalInstLumi(), LumiInfo::setTotalInstStatError(), mathSSE::sqrt(), takeAverageValue_, and to_string().

91  {
92  //The total raw luminosity from the pixel clusters - not scaled
93  float totalLumi = 0.0;
94  //the statistical error on the lumi - large num ie sqrt(N)
95  float statErrOnLumi = 0.0;
96 
97  //new vector containing clusters per bxid
98  std::vector<int> clustersPerBXOutput(LumiConstants::numBX, 0);
99  //new vector containing clusters per bxid with afterglow corrections
100  std::vector<float> corrClustersPerBXOutput(LumiConstants::numBX, 0);
101 
105  const edm::Handle<reco::PixelClusterCounts> pccHandle = lumiSeg.getHandle(pccToken_);
106  const reco::PixelClusterCounts& inputPcc = *(pccHandle.product());
107  //vector with Module IDs 1-1 map to bunch x-ing in clusers
108  auto modID = inputPcc.readModID();
109  //vector with total events at each bxid.
110  auto events = inputPcc.readEvents();
111  //cluster counts per module per bx
112  auto clustersPerBXInput = inputPcc.readCounts();
113 
117  std::vector<int> goodMods;
118  for (unsigned int i = 0; i < modID.size(); i++) {
119  if (std::find(modVeto_.begin(), modVeto_.end(), modID.at(i)) == modVeto_.end()) {
120  goodMods.push_back(i);
121  }
122  }
123  for (int bx = 0; bx < int(LumiConstants::numBX); bx++) {
124  for (unsigned int i = 0; i < goodMods.size(); i++) {
125  clustersPerBXOutput.at(bx) += clustersPerBXInput.at(goodMods.at(i) * int(LumiConstants::numBX) + bx);
126  }
127  }
128 
132  std::vector<float> correctionScaleFactors;
133  if (applyCorr_) {
134  const auto pccCorrections = &iSetup.getData(lumiCorrectionsToken_);
135  correctionScaleFactors = pccCorrections->getCorrectionsBX();
136  } else {
137  correctionScaleFactors.resize(LumiConstants::numBX, 1.0);
138  }
139 
140  for (unsigned int i = 0; i < clustersPerBXOutput.size(); i++) {
141  if (events.at(i) != 0) {
142  corrClustersPerBXOutput[i] = clustersPerBXOutput[i] * correctionScaleFactors[i];
143  } else {
144  corrClustersPerBXOutput[i] = 0.0;
145  }
146  totalLumi += corrClustersPerBXOutput[i];
147  statErrOnLumi += float(events[i]);
148  }
149 
150  std::vector<float> errorPerBX; //Stat error (or number of events)
151  errorPerBX.assign(events.begin(), events.end());
152 
156  if (takeAverageValue_ == "Average") {
157  unsigned int NActiveBX = 0;
158  for (int bx = 0; bx < int(LumiConstants::numBX); bx++) {
159  if (events[bx] > 0) {
160  NActiveBX++;
161  corrClustersPerBXOutput[bx] /= float(events[bx]);
162  errorPerBX[bx] = 1 / sqrt(float(events[bx]));
163  }
164  }
165  if (statErrOnLumi != 0) {
166  totalLumi = totalLumi / statErrOnLumi * float(NActiveBX);
167  statErrOnLumi = 1 / sqrt(statErrOnLumi) * totalLumi;
168  }
169  }
170 
173  LumiInfo outputLumiInfo;
174  outputLumiInfo.setTotalInstLumi(totalLumi);
175  outputLumiInfo.setTotalInstStatError(statErrOnLumi);
176  outputLumiInfo.setErrorLumiAllBX(errorPerBX);
177  outputLumiInfo.setInstLumiAllBX(corrClustersPerBXOutput);
178  lumiSeg.emplace(putToken_, std::move(outputLumiInfo));
179 
180  //Lumi saved in the csv file
181  if (saveCSVFile_) {
182  std::lock_guard<std::mutex> lock(fileLock_);
183  std::ofstream csfile(csvOutLabel_, std::ios_base::app);
184  csfile << std::to_string(lumiSeg.run()) << ",";
185  csfile << std::to_string(lumiSeg.luminosityBlock()) << ",";
186  csfile << std::to_string(totalLumi);
187 
188  for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++)
189  csfile << "," << std::to_string(corrClustersPerBXOutput[bx]);
190  csfile << std::endl;
191 
192  csfile.close();
193  }
194 }
const edm::ESGetToken< LumiCorrections, LumiCorrectionsRcd > lumiCorrectionsToken_
std::vector< int > const & readModID() const
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const std::string csvOutLabel_
T const * product() const
Definition: Handle.h:70
static const unsigned int numBX
Definition: LumiConstants.h:8
void setInstLumiAllBX(std::vector< float > &instLumiByBX)
Definition: LumiInfo.cc:31
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const std::string takeAverageValue_
static std::string to_string(const XMLCh *ch)
std::vector< int > const & readEvents() const
T sqrt(T t)
Definition: SSEVec.h:23
void setTotalInstLumi(float totalLumi)
Definition: LumiInfo.h:122
const bool applyCorr_
std::vector< int > const & readCounts() const
const edm::EDPutTokenT< LumiInfo > putToken_
void emplace(EDPutTokenT< PROD > token, Args &&... args)
puts a new product
std::mutex fileLock_
void setTotalInstStatError(float statError)
Definition: LumiInfo.h:126
const std::vector< int > modVeto_
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
void setErrorLumiAllBX(std::vector< float > &errLumiByBX)
Definition: LumiInfo.cc:35
const bool saveCSVFile_
LuminosityBlockNumber_t luminosityBlock() const
int events
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< reco::PixelClusterCounts > pccToken_

◆ produce()

void RawPCCProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
finalprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 87 of file RawPCCProducer.cc.

87 {}

Member Data Documentation

◆ applyCorr_

const bool RawPCCProducer::applyCorr_
private

Definition at line 50 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ csvOutLabel_

const std::string RawPCCProducer::csvOutLabel_
private

Definition at line 59 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ fileLock_

std::mutex RawPCCProducer::fileLock_
mutableprivate

Definition at line 60 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ lumiCorrectionsToken_

const edm::ESGetToken<LumiCorrections, LumiCorrectionsRcd> RawPCCProducer::lumiCorrectionsToken_
private

Definition at line 46 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ modVeto_

const std::vector<int> RawPCCProducer::modVeto_
private

Definition at line 48 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ pccToken_

edm::EDGetTokenT<reco::PixelClusterCounts> RawPCCProducer::pccToken_
private

Definition at line 44 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ putToken_

const edm::EDPutTokenT<LumiInfo> RawPCCProducer::putToken_
private

Definition at line 55 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ saveCSVFile_

const bool RawPCCProducer::saveCSVFile_
private

Definition at line 58 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

◆ takeAverageValue_

const std::string RawPCCProducer::takeAverageValue_
private

Definition at line 52 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().