CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const 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
 
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)
 
 ~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
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > 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
 
bool registeredToConsumeMany (TypeID const &, 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::ESRecordsToProxyIndices 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,
LumiCorrectionsRcd
lumiCorrectionsToken_
 
const std::vector< int > modVeto_
 
edm::EDGetTokenT
< reco::PixelClusterCounts
pccToken_
 
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
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
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< B > consumes (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 ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
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 () noexcept
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
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) and Chris Palmer (capal.nosp@m.mer@.nosp@m.cern..nosp@m.ch)


Definition at line 34 of file RawPCCProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 58 of file RawPCCProducer.cc.

References applyCorr_, csvOutLabel_, edm::ParameterSet::getParameter(), HLT_FULL_cff::InputTag, modVeto_, pccToken_, saveCSVFile_, AlCaHLTBitMon_QueryRunRegistry::string, and takeAverageValue_.

59  : lumiCorrectionsToken_(esConsumes<edm::Transition::EndLuminosityBlock>()),
60  putToken_{produces<LumiInfo, edm::Transition::EndLuminosityBlock>(
61  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
62  .getUntrackedParameter<std::string>("outputProductName", "alcaLumi"))},
63  takeAverageValue_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
64  .getUntrackedParameter<std::string>("OutputValue", std::string("Totals"))},
65  modVeto_{
66  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::vector<int>>("modVeto")},
67  csvOutLabel_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
68  .getUntrackedParameter<std::string>("label", std::string("rawPCC.csv"))},
69  saveCSVFile_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
70  .getUntrackedParameter<bool>("saveCSVFile", false)},
71  applyCorr_{iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters")
72  .getUntrackedParameter<bool>("ApplyCorrections", false)} {
73  auto pccSource =
74  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("inputPccLabel");
75  auto prodInst =
76  iConfig.getParameter<edm::ParameterSet>("RawPCCProducerParameters").getParameter<std::string>("ProdInst");
77 
78  pccToken_ = consumes<reco::PixelClusterCounts, edm::InLumi>(edm::InputTag(pccSource, prodInst));
79 }
const edm::ESGetToken< LumiCorrections, LumiCorrectionsRcd > lumiCorrectionsToken_
const std::string csvOutLabel_
const std::string takeAverageValue_
const bool applyCorr_
const edm::EDPutTokenT< LumiInfo > putToken_
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const std::vector< int > modVeto_
const bool saveCSVFile_
edm::EDGetTokenT< reco::PixelClusterCounts > pccToken_
RawPCCProducer::~RawPCCProducer ( )
override

Definition at line 82 of file RawPCCProducer.cc.

82 {}

Member Function Documentation

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

Definition at line 88 of file RawPCCProducer.cc.

References applyCorr_, makePileupJSON::bx, csvOutLabel_, edm::LuminosityBlock::emplace(), patZpeak::events, fileLock_, spr::find(), edm::LuminosityBlock::getByToken(), edm::EventSetup::getData(), mps_fire::i, 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(), and takeAverageValue_.

89  {
90  float totalLumi = 0.0; //The total raw luminosity from the pixel clusters - not scaled
91  float statErrOnLumi = 0.0; //the statistical error on the lumi - large num ie sqrt(N)
92 
93  //new vector containing clusters per bxid
94  std::vector<int> clustersPerBXOutput(LumiConstants::numBX, 0);
95  //new vector containing clusters per bxid with afterglow corrections
96  std::vector<float> corrClustersPerBXOutput(LumiConstants::numBX, 0);
97 
98  //The indicies of all the good modules - not vetoed
99  std::vector<int> goodMods;
100 
102  lumiSeg.getByToken(pccToken_, pccHandle);
103 
104  const reco::PixelClusterCounts& inputPcc = *(pccHandle.product());
105 
106  //vector with Module IDs 1-1 map to bunch x-ing in clusers
107  auto modID = inputPcc.readModID();
108  //vector with total events at each bxid.
109  auto events = inputPcc.readEvents();
110  auto clustersPerBXInput = inputPcc.readCounts();
111 
112  //making list of modules to sum over
113  for (unsigned int i = 0; i < modID.size(); i++) {
114  if (std::find(modVeto_.begin(), modVeto_.end(), modID.at(i)) == modVeto_.end()) {
115  goodMods.push_back(i);
116  }
117  }
118 
119  //summing over good modules only
120  for (int bx = 0; bx < int(LumiConstants::numBX); bx++) {
121  for (unsigned int i = 0; i < goodMods.size(); i++) {
122  clustersPerBXOutput.at(bx) += clustersPerBXInput.at(goodMods.at(i) * int(LumiConstants::numBX) + bx);
123  }
124  }
125 
126  std::vector<float> correctionScaleFactors;
127  if (applyCorr_) {
128  //Get PCC corrections from the event setup through a token
129  const auto pccCorrections = &iSetup.getData(lumiCorrectionsToken_);
130  correctionScaleFactors = pccCorrections->getCorrectionsBX();
131  } else {
132  correctionScaleFactors.resize(LumiConstants::numBX, 1.0);
133  }
134 
135  for (unsigned int i = 0; i < clustersPerBXOutput.size(); i++) {
136  if (events.at(i) != 0) {
137  corrClustersPerBXOutput[i] = clustersPerBXOutput[i] * correctionScaleFactors[i];
138  } else {
139  corrClustersPerBXOutput[i] = 0.0;
140  }
141  totalLumi += corrClustersPerBXOutput[i];
142  statErrOnLumi += float(events[i]);
143  }
144 
145  std::vector<float> errorPerBX; //Stat error (or number of events)
146  errorPerBX.assign(events.begin(), events.end());
147 
148  if (takeAverageValue_ == "Average") {
149  unsigned int NActiveBX = 0;
150  for (int bx = 0; bx < int(LumiConstants::numBX); bx++) {
151  if (events[bx] > 0) {
152  NActiveBX++;
153  // Counting where events are will only work
154  // for ZeroBias or AlwaysTrue triggers.
155  // Random triggers will get all BXs.
156  corrClustersPerBXOutput[bx] /= float(events[bx]);
157  errorPerBX[bx] = 1 / sqrt(float(events[bx]));
158  }
159  }
160  if (statErrOnLumi != 0) {
161  totalLumi = totalLumi / statErrOnLumi * float(NActiveBX);
162  statErrOnLumi = 1 / sqrt(statErrOnLumi) * totalLumi;
163  }
164  }
165 
166  LumiInfo outputLumiInfo;
167 
168  outputLumiInfo.setTotalInstLumi(totalLumi);
169  outputLumiInfo.setTotalInstStatError(statErrOnLumi);
170 
171  outputLumiInfo.setErrorLumiAllBX(errorPerBX);
172  outputLumiInfo.setInstLumiAllBX(corrClustersPerBXOutput);
173 
174  if (saveCSVFile_) {
175  std::lock_guard<std::mutex> lock(fileLock_);
176  std::ofstream csfile(csvOutLabel_, std::ios_base::app);
177  csfile << std::to_string(lumiSeg.run()) << ",";
178  csfile << std::to_string(lumiSeg.luminosityBlock()) << ",";
179  csfile << std::to_string(totalLumi);
180 
181  if (totalLumi > 0) {
182  for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++) {
183  csfile << "," << std::to_string(corrClustersPerBXOutput[bx]);
184  }
185  csfile << std::endl;
186  } else if (totalLumi < 0) {
187  edm::LogInfo("WARNING") << "WHY IS LUMI NEGATIVE?!?!?!? " << totalLumi;
188  }
189 
190  csfile.close();
191  }
192  lumiSeg.emplace(putToken_, std::move(outputLumiInfo));
193 }
const edm::ESGetToken< LumiCorrections, LumiCorrectionsRcd > lumiCorrectionsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::string csvOutLabel_
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
void emplace(EDPutTokenT< PROD > token, Args &&...args)
puts a new product
const std::string takeAverageValue_
LuminosityBlockNumber_t luminosityBlock() const
bool getData(T &iHolder) const
Definition: EventSetup.h:128
std::vector< int > const & readCounts() const
T sqrt(T t)
Definition: SSEVec.h:19
void setTotalInstLumi(float totalLumi)
Definition: LumiInfo.h:122
std::vector< int > const & readModID() const
def move
Definition: eostools.py:511
const bool applyCorr_
RunNumber_t run() const
const edm::EDPutTokenT< LumiInfo > putToken_
Log< level::Info, false > LogInfo
T const * product() const
Definition: Handle.h:70
std::mutex fileLock_
void setTotalInstStatError(float statError)
Definition: LumiInfo.h:126
const std::vector< int > modVeto_
tuple events
Definition: patZpeak.py:20
void setErrorLumiAllBX(std::vector< float > &errLumiByBX)
Definition: LumiInfo.cc:35
const bool saveCSVFile_
std::vector< int > const & readEvents() const
edm::EDGetTokenT< reco::PixelClusterCounts > pccToken_
void RawPCCProducer::produce ( edm::StreamID  ,
edm::Event iEvent,
const edm::EventSetup iSetup 
) const
finalprivatevirtual

Implements edm::global::EDProducerBase.

Definition at line 85 of file RawPCCProducer.cc.

85 {}

Member Data Documentation

const bool RawPCCProducer::applyCorr_
private

Definition at line 54 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

const std::string RawPCCProducer::csvOutLabel_
private

Definition at line 50 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

std::mutex RawPCCProducer::fileLock_
mutableprivate

Definition at line 51 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

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

Definition at line 44 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

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

Definition at line 48 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

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

Definition at line 43 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

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

Definition at line 45 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

const bool RawPCCProducer::saveCSVFile_
private

Definition at line 52 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

const std::string RawPCCProducer::takeAverageValue_
private

Definition at line 46 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().