CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
QGLikelihoodDBWriter Class Reference
Inheritance diagram for QGLikelihoodDBWriter:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void endJob () override
 
 QGLikelihoodDBWriter (const edm::ParameterSet &)
 
 ~QGLikelihoodDBWriter () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () 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 &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
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
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
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

bool getVectorFromFile (TFile *, std::vector< float > &, const TString &)
 
QGLikelihoodObject::Histogram transformToHistogramObject (TH1 *)
 
void tryToMerge (std::map< std::vector< int >, QGLikelihoodCategory > &, std::map< std::vector< int >, TH1 * > &, std::vector< int > &, int)
 

Private Attributes

std::string inputRootFile
 
std::string payloadTag
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 24 of file QGLikelihoodDBWriter.cc.

Constructor & Destructor Documentation

◆ QGLikelihoodDBWriter()

QGLikelihoodDBWriter::QGLikelihoodDBWriter ( const edm::ParameterSet pSet)

◆ ~QGLikelihoodDBWriter()

QGLikelihoodDBWriter::~QGLikelihoodDBWriter ( )
inlineoverride

Definition at line 30 of file QGLikelihoodDBWriter.cc.

30 {}

Member Function Documentation

◆ analyze()

void QGLikelihoodDBWriter::analyze ( const edm::Event ,
const edm::EventSetup  
)
inlineoverridevirtual

Implements edm::EDAnalyzer.

Definition at line 28 of file QGLikelihoodDBWriter.cc.

28 {}

◆ beginJob()

void QGLikelihoodDBWriter::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 106 of file QGLikelihoodDBWriter.cc.

106  {
108  payload->data.clear();
109 
110  // Get the ROOT file
111  TFile* f = TFile::Open(edm::FileInPath(inputRootFile.c_str()).fullPath().c_str());
112 
113  // The ROOT file contains the binning for each variable, needed to set up the binning grid
114  std::map<TString, std::vector<float>> gridOfBins;
115  for (const TString& binVariable : {"eta", "pt", "rho"}) {
116  if (!getVectorFromFile(f, gridOfBins[binVariable], binVariable + "Bins")) {
117  edm::LogError("NoBins") << "Missing bin information for " << binVariable << " in input file" << std::endl;
118  return;
119  }
120  }
121 
122  // Get pdf's from file and associate them to a QGLikelihoodCategory
123  // Some pdf's in the ROOT-file are copies from each other, with the same title: those are merged bins in pt and rho
124  // Here we do not store the copies, but try to extend the range of the neighbouring category (will result in less comparisons during application phase)
125  std::map<std::vector<int>, TH1*> pdfs;
126  std::map<std::vector<int>, QGLikelihoodCategory> categories;
127  for (const TString& type : {"gluon", "quark"}) {
128  int qgIndex = (type == "gluon"); // Keep numbering same as in RecoJets/JetAlgorithms/src/QGLikelihoodCalculator.cc
129  for (const TString& likelihoodVar : {"mult", "ptD", "axis2"}) {
130  int varIndex =
131  (likelihoodVar == "mult"
132  ? 0
133  : (likelihoodVar == "ptD" ? 1 : 2)); // Keep order same as in RecoJets/JetProducers/plugins/QGTagger.cc
134  for (int i = 0; i < (int)gridOfBins["eta"].size() - 1; ++i) {
135  for (int j = 0; j < (int)gridOfBins["pt"].size() - 1; ++j) {
136  for (int k = 0; k < (int)gridOfBins["rho"].size() - 1; ++k) {
138  category.EtaMin = gridOfBins["eta"][i];
139  category.EtaMax = gridOfBins["eta"][i + 1];
140  category.PtMin = gridOfBins["pt"][j];
141  category.PtMax = gridOfBins["pt"][j + 1];
142  category.RhoMin = gridOfBins["rho"][k];
143  category.RhoMax = gridOfBins["rho"][k + 1];
144  category.QGIndex = qgIndex;
145  category.VarIndex = varIndex;
146 
147  TString key =
148  TString::Format(likelihoodVar + "/" + likelihoodVar + "_" + type + "_eta%d_pt%d_rho%d", i, j, k);
149  TH1* pdf = (TH1*)f->Get(key);
150  if (!pdf) {
151  edm::LogError("NoPDF") << "Could not found pdf with key " << key << " in input file" << std::endl;
152  return;
153  }
154 
155  std::vector<int> binNumbers = {qgIndex, varIndex, i, j, k};
156  pdfs[binNumbers] = pdf;
157  categories[binNumbers] = category;
158 
159  tryToMerge(categories, pdfs, binNumbers, 4);
160  }
161  for (int k = 0; k < (int)gridOfBins["rho"].size() - 1; ++k) {
162  std::vector<int> binNumbers = {qgIndex, varIndex, i, j, k};
163  tryToMerge(categories, pdfs, binNumbers, 3);
164  }
165  }
166  for (int j = 0; j < (int)gridOfBins["pt"].size() - 1; ++j) {
167  for (int k = 0; k < (int)gridOfBins["rho"].size() - 1; ++k) {
168  std::vector<int> binNumbers = {qgIndex, varIndex, i, j, k};
169  tryToMerge(categories, pdfs, binNumbers, 2);
170  }
171  }
172  }
173  }
174  }
175 
176  // Write all categories with their histograms to file
177  int i = 0;
178  for (const auto& category : categories) {
180  entry.category = category.second;
181  entry.histogram = transformToHistogramObject(pdfs[category.first]);
182  entry.mean =
183  0; // not used by the algorithm, is an old data member used in the past, but DB objects are not allowed to change
184  payload->data.push_back(entry);
185 
186  char buff[1000];
187  sprintf(buff,
188  "%6d) var=%1d\t\tqg=%1d\t\teta={%5.2f,%5.2f}\t\tpt={%8.2f,%8.2f}\t\trho={%6.2f,%8.2f}",
189  i++,
190  category.second.VarIndex,
191  category.second.QGIndex,
192  category.second.EtaMin,
193  category.second.EtaMax,
194  category.second.PtMin,
195  category.second.PtMax,
196  category.second.RhoMin,
197  category.second.RhoMax);
198  edm::LogVerbatim("HistName") << buff << std::endl;
199  }
200 
201  // Define the valid range, if no category is found within these bounds a warning will be thrown
202  payload->qgValidRange.EtaMin = gridOfBins["eta"].front();
203  payload->qgValidRange.EtaMax = gridOfBins["eta"].back();
204  payload->qgValidRange.PtMin = gridOfBins["pt"].front();
205  payload->qgValidRange.PtMax = gridOfBins["pt"].back();
206  payload->qgValidRange.RhoMin = gridOfBins["rho"].front();
207  payload->qgValidRange.RhoMax = gridOfBins["rho"].back();
208  payload->qgValidRange.QGIndex = -1;
209  payload->qgValidRange.VarIndex = -1;
210 
211  // Now write it into the DB
212  edm::LogInfo("UserOutput") << "Opening PoolDBOutputService" << std::endl;
213 
215  if (s.isAvailable()) {
216  edm::LogInfo("UserOutput") << "Setting up payload with " << payload->data.size() << " entries and tag "
217  << payloadTag << std::endl;
218  if (s->isNewTagRequest(payloadTag))
219  s->createNewIOV<QGLikelihoodObject>(payload, s->beginOfTime(), s->endOfTime(), payloadTag);
220  else
221  s->appendSinceTime<QGLikelihoodObject>(payload, 111, payloadTag);
222  }
223  edm::LogInfo("UserOutput") << "Wrote in CondDB QGLikelihood payload label: " << payloadTag << std::endl;
224 }

References myMessageLogger_cff::categories, taus_updatedMVAIds_cff::category, mps_splice::entry, f, contentValuesFiles::fullPath, getVectorFromFile(), mps_fire::i, inputRootFile, createfilelist::int, dqmiolumiharvest::j, dqmdumpme::k, crabWrapper::key, jets_cff::payload, payloadTag, alignCSCRings::s, findQualityFiles::size, transformToHistogramObject(), and tryToMerge().

◆ endJob()

void QGLikelihoodDBWriter::endJob ( void  )
inlineoverridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 29 of file QGLikelihoodDBWriter.cc.

29 {}

◆ getVectorFromFile()

bool QGLikelihoodDBWriter::getVectorFromFile ( TFile *  f,
std::vector< float > &  vector,
const TString &  name 
)
private

Definition at line 49 of file QGLikelihoodDBWriter.cc.

49  {
50  TVectorT<float>* tVector = nullptr;
51  f->GetObject(name, tVector);
52  if (!tVector)
53  return false;
54  for (int i = 0; i < tVector->GetNoElements(); ++i)
55  vector.push_back((*tVector)[i]);
56  return true;
57 }

References f, mps_fire::i, Skims_PA_cff::name, and trackerHitRTTI::vector.

Referenced by beginJob().

◆ transformToHistogramObject()

QGLikelihoodObject::Histogram QGLikelihoodDBWriter::transformToHistogramObject ( TH1 *  th1)
private

Definition at line 60 of file QGLikelihoodDBWriter.cc.

60  {
62  th1->GetNbinsX(), th1->GetXaxis()->GetBinLowEdge(1), th1->GetXaxis()->GetBinUpEdge(th1->GetNbinsX()));
63  for (int ibin = 0; ibin <= th1->GetNbinsX() + 1; ++ibin)
64  histogram.setBinContent(ibin, th1->GetBinContent(ibin));
65  return histogram;
66 }

References PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::setBinContent().

Referenced by beginJob().

◆ tryToMerge()

void QGLikelihoodDBWriter::tryToMerge ( std::map< std::vector< int >, QGLikelihoodCategory > &  categories,
std::map< std::vector< int >, TH1 * > &  pdfs,
std::vector< int > &  binNumbers,
int  index 
)
private

Definition at line 69 of file QGLikelihoodDBWriter.cc.

72  {
73  if (!pdfs[binNumbers])
74  return;
75  std::vector<int> neighbour = binNumbers;
76  do {
77  if (--(neighbour[index]) < 0)
78  return;
79  } while (!pdfs[neighbour]);
80  if (TString(pdfs[binNumbers]->GetTitle()) != TString(pdfs[neighbour]->GetTitle()))
81  return;
82  if (index != 4 && categories[neighbour].RhoMax != categories[binNumbers].RhoMax)
83  return;
84  if (index != 4 && categories[neighbour].RhoMin != categories[binNumbers].RhoMin)
85  return;
86  if (index != 3 && categories[neighbour].PtMax != categories[binNumbers].PtMax)
87  return;
88  if (index != 3 && categories[neighbour].PtMin != categories[binNumbers].PtMin)
89  return;
90  if (index != 2 && categories[neighbour].EtaMax != categories[binNumbers].EtaMax)
91  return;
92  if (index != 2 && categories[neighbour].EtaMin != categories[binNumbers].EtaMin)
93  return;
94 
95  if (index == 4)
96  categories[neighbour].RhoMax = categories[binNumbers].RhoMax;
97  if (index == 3)
98  categories[neighbour].PtMax = categories[binNumbers].PtMax;
99  if (index == 2)
100  categories[neighbour].EtaMax = categories[binNumbers].EtaMax;
101  pdfs.erase(binNumbers);
102  categories.erase(binNumbers);
103 }

References myMessageLogger_cff::categories, MonitorTrackInnerTrackMuons_cff::EtaMax, MonitorTrackInnerTrackMuons_cff::EtaMin, electronDQMIsoDist_cfi::PtMax, HLT_FULL_cff::PtMin, and HLT_FULL_cff::RhoMax.

Referenced by beginJob().

Member Data Documentation

◆ inputRootFile

std::string QGLikelihoodDBWriter::inputRootFile
private

Definition at line 39 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().

◆ payloadTag

std::string QGLikelihoodDBWriter::payloadTag
private

Definition at line 39 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().

taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
mps_fire.i
i
Definition: mps_fire.py:428
myMessageLogger_cff.categories
categories
Definition: myMessageLogger_cff.py:10
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
mps_splice.entry
entry
Definition: mps_splice.py:68
electronDQMIsoDist_cfi.PtMax
PtMax
Definition: electronDQMIsoDist_cfi.py:51
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
QGLikelihoodObject::Entry
Definition: QGLikelihoodObject.h:25
QGLikelihoodDBWriter::transformToHistogramObject
QGLikelihoodObject::Histogram transformToHistogramObject(TH1 *)
Definition: QGLikelihoodDBWriter.cc:60
edm::FileInPath
Definition: FileInPath.h:64
alignCSCRings.s
s
Definition: alignCSCRings.py:92
HLT_FULL_cff.PtMin
PtMin
Definition: HLT_FULL_cff.py:9904
jets_cff.payload
payload
Definition: jets_cff.py:32
dqmdumpme.k
k
Definition: dqmdumpme.py:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
QGLikelihoodDBWriter::tryToMerge
void tryToMerge(std::map< std::vector< int >, QGLikelihoodCategory > &, std::map< std::vector< int >, TH1 * > &, std::vector< int > &, int)
Definition: QGLikelihoodDBWriter.cc:69
QGLikelihoodCategory
Category structure: ranges associated with QGLikelihood histograms.
Definition: QGLikelihoodObject.h:9
QGLikelihoodDBWriter::getVectorFromFile
bool getVectorFromFile(TFile *, std::vector< float > &, const TString &)
Definition: QGLikelihoodDBWriter.cc:49
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
edm::Service< cond::service::PoolDBOutputService >
createfilelist.int
int
Definition: createfilelist.py:10
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
PhysicsTools::Calibration::Histogram< float >
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
MonitorTrackInnerTrackMuons_cff.EtaMin
EtaMin
Definition: MonitorTrackInnerTrackMuons_cff.py:64
MonitorTrackInnerTrackMuons_cff.EtaMax
EtaMax
Definition: MonitorTrackInnerTrackMuons_cff.py:64
QGLikelihoodDBWriter::inputRootFile
std::string inputRootFile
Definition: QGLikelihoodDBWriter.cc:39
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
QGLikelihoodObject
QGLikelihoodObject containing valid range and entries with category and histogram (mean is not used a...
Definition: QGLikelihoodObject.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
QGLikelihoodDBWriter::payloadTag
std::string payloadTag
Definition: QGLikelihoodDBWriter.cc:39
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
crabWrapper.key
key
Definition: crabWrapper.py:19
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
HLT_FULL_cff.RhoMax
RhoMax
Definition: HLT_FULL_cff.py:70861