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
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () 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
 
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::vector< ModuleDescription const * > &modules, 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
 
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 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
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::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
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<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)
 

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 57 of file RawPCCProducer.cc.

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

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

Definition at line 80 of file RawPCCProducer.cc.

80 {}

Member Function Documentation

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

Definition at line 86 of file RawPCCProducer.cc.

References applyCorr_, csvOutLabel_, DEFINE_FWK_MODULE, edm::LuminosityBlock::emplace(), PatBasicFWLiteAnalyzer::events, fileLock_, spr::find(), objects.autophobj::float, edm::EventSetup::get(), edm::LuminosityBlock::getByToken(), LumiCorrections::getCorrectionsBX(), mps_fire::i, createfilelist::int, CommonMethods::lock(), edm::LuminosityBlockBase::luminosityBlock(), modVeto_, eostools::move(), LumiConstants::numBX, pccToken_, edm::Handle< T >::product(), edm::ESHandle< 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_.

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

Member Data Documentation

const bool RawPCCProducer::applyCorr_
private

Definition at line 53 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

const std::string RawPCCProducer::csvOutLabel_
private

Definition at line 49 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

std::mutex RawPCCProducer::fileLock_
mutableprivate

Definition at line 50 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

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

Definition at line 47 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 44 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce().

const bool RawPCCProducer::saveCSVFile_
private

Definition at line 51 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().

const std::string RawPCCProducer::takeAverageValue_
private

Definition at line 45 of file RawPCCProducer.cc.

Referenced by globalEndLuminosityBlockProduce(), and RawPCCProducer().