CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

virtual void analyze (const edm::Event &, const edm::EventSetup &) override
 
virtual void beginJob () override
 
virtual void endJob () override
 
 QGLikelihoodDBWriter (const edm::ParameterSet &)
 
 ~QGLikelihoodDBWriter ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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

Definition at line 24 of file QGLikelihoodDBWriter.cc.

Constructor & Destructor Documentation

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

Definition at line 30 of file QGLikelihoodDBWriter.cc.

30 {}

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 28 of file QGLikelihoodDBWriter.cc.

28 {}
void QGLikelihoodDBWriter::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 89 of file QGLikelihoodDBWriter.cc.

References cond::service::PoolDBOutputService::appendSinceTime(), cond::service::PoolDBOutputService::beginOfTime(), ecalBxOrbitNumberGrapher_cfg::categories, QGLikelihoodObject::Entry::category, python.rootplot.argparse::category, cond::service::PoolDBOutputService::createNewIOV(), QGLikelihoodObject::data, cond::service::PoolDBOutputService::endOfTime(), QGLikelihoodCategory::EtaMax, QGLikelihoodCategory::EtaMin, f, contentValuesFiles::fullPath, getVectorFromFile(), QGLikelihoodObject::Entry::histogram, i, inputRootFile, edm::Service< T >::isAvailable(), cond::service::PoolDBOutputService::isNewTagRequest(), j, relval_steps::k, relval_steps::key, QGLikelihoodObject::Entry::mean, payloadTag, QGLikelihoodCategory::PtMax, QGLikelihoodCategory::PtMin, QGLikelihoodCategory::QGIndex, QGLikelihoodObject::qgValidRange, QGLikelihoodCategory::RhoMax, QGLikelihoodCategory::RhoMin, alignCSCRings::s, findQualityFiles::size, transformToHistogramObject(), tryToMerge(), and QGLikelihoodCategory::VarIndex.

89  {
90  QGLikelihoodObject *payload = new QGLikelihoodObject();
91  payload->data.clear();
92 
93  // Get the ROOT file
94  TFile *f = TFile::Open(edm::FileInPath(inputRootFile.c_str()).fullPath().c_str());
95 
96  // The ROOT file contains the binning for each variable, needed to set up the binning grid
97  std::map<TString, std::vector<float>> gridOfBins;
98  for(TString binVariable : {"eta", "pt", "rho"}){
99  if(!getVectorFromFile(f, gridOfBins[binVariable], binVariable + "Bins")){
100  edm::LogError("NoBins") << "Missing bin information for " << binVariable << " in input file" << std::endl;
101  return;
102  }
103  }
104 
105  // Get pdf's from file and associate them to a QGLikelihoodCategory
106  // Some pdf's in the ROOT-file are copies from each other, with the same title: those are merged bins in pt and rho
107  // 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)
108  std::map<std::vector<int>, TH1*> pdfs;
109  std::map<std::vector<int>, QGLikelihoodCategory> categories;
110  for(TString type : {"gluon","quark"}){
111  int qgIndex = (type == "gluon"); // Keep numbering same as in RecoJets/JetAlgorithms/src/QGLikelihoodCalculator.cc
112  for(TString likelihoodVar : {"mult","ptD","axis2"}){
113  int varIndex = (likelihoodVar == "mult" ? 0 : (likelihoodVar == "ptD" ? 1 : 2)); // Keep order same as in RecoJets/JetProducers/plugins/QGTagger.cc
114  for(int i = 0; i < (int)gridOfBins["eta"].size() - 1; ++i){
115  for(int j = 0; j < (int)gridOfBins["pt"].size() - 1; ++j){
116  for(int k = 0; k < (int)gridOfBins["rho"].size() - 1; ++k){
117 
119  category.EtaMin = gridOfBins["eta"][i];
120  category.EtaMax = gridOfBins["eta"][i+1];
121  category.PtMin = gridOfBins["pt"][j];
122  category.PtMax = gridOfBins["pt"][j+1];
123  category.RhoMin = gridOfBins["rho"][k];
124  category.RhoMax = gridOfBins["rho"][k+1];
125  category.QGIndex = qgIndex;
126  category.VarIndex = varIndex;
127 
128  TString key = TString::Format(likelihoodVar + "/" + likelihoodVar + "_" + type + "_eta%d_pt%d_rho%d", i, j, k);
129  TH1* pdf = (TH1*) f->Get(key);
130  if(!pdf){
131  edm::LogError("NoPDF") << "Could not found pdf with key " << key << " in input file" << std::endl;
132  return;
133  }
134 
135  std::vector<int> binNumbers = {qgIndex, varIndex, i,j,k};
136  pdfs[binNumbers] = pdf;
137  categories[binNumbers] = category;
138 
139  tryToMerge(categories, pdfs, binNumbers, 4);
140  }
141  for(int k = 0; k < (int)gridOfBins["rho"].size() - 1; ++k){
142  std::vector<int> binNumbers = {qgIndex, varIndex, i,j,k};
143  tryToMerge(categories, pdfs, binNumbers, 3);
144  }
145  }
146  for(int j = 0; j < (int)gridOfBins["pt"].size() - 1; ++j){
147  for(int k = 0; k < (int)gridOfBins["rho"].size() - 1; ++k){
148  std::vector<int> binNumbers = {qgIndex, varIndex, i,j,k};
149  tryToMerge(categories, pdfs, binNumbers, 2);
150  }
151  }
152  }
153  }
154  }
155 
156 
157  // Write all categories with their histograms to file
158  int i = 0;
159  for(auto category : categories){
161  entry.category = category.second;
162  entry.histogram = transformToHistogramObject(pdfs[category.first]);
163  entry.mean = 0; // not used by the algorithm, is an old data member used in the past, but DB objects are not allowed to change
164  payload->data.push_back(entry);
165 
166  char buff[1000];
167  sprintf(buff, "%6d) var=%1d\t\tqg=%1d\t\teta={%5.2f,%5.2f}\t\tpt={%8.2f,%8.2f}\t\trho={%6.2f,%8.2f}", i++,
168  category.second.VarIndex, category.second.QGIndex, category.second.EtaMin, category.second.EtaMax,
169  category.second.PtMin, category.second.PtMax, category.second.RhoMin, category.second.RhoMax);
170  edm::LogVerbatim("HistName") << buff << std::endl;
171  }
172 
173  // Define the valid range, if no category is found within these bounds a warning will be thrown
174  payload->qgValidRange.EtaMin = gridOfBins["eta"].front();
175  payload->qgValidRange.EtaMax = gridOfBins["eta"].back();
176  payload->qgValidRange.PtMin = gridOfBins["pt"].front();
177  payload->qgValidRange.PtMax = gridOfBins["pt"].back();
178  payload->qgValidRange.RhoMin = gridOfBins["rho"].front();
179  payload->qgValidRange.RhoMax = gridOfBins["rho"].back();
180  payload->qgValidRange.QGIndex = -1;
181  payload->qgValidRange.VarIndex = -1;
182 
183  // Now write it into the DB
184  edm::LogInfo("UserOutput") << "Opening PoolDBOutputService" << std::endl;
185 
187  if(s.isAvailable()){
188  edm::LogInfo("UserOutput") << "Setting up payload with " << payload->data.size() << " entries and tag " << payloadTag << std::endl;
190  else s->appendSinceTime<QGLikelihoodObject>(payload, 111, payloadTag);
191  }
192  edm::LogInfo("UserOutput") << "Wrote in CondDB QGLikelihood payload label: " << payloadTag << std::endl;
193 }
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
QGLikelihoodCategory category
QGLikelihoodCategory qgValidRange
void tryToMerge(std::map< std::vector< int >, QGLikelihoodCategory > &, std::map< std::vector< int >, TH1 * > &, std::vector< int > &, int)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
QGLikelihoodObject containing valid range and entries with category and histogram (mean is not used a...
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
int j
Definition: DBlmapReader.cc:9
QGLikelihoodObject::Histogram transformToHistogramObject(TH1 *)
double f[11][100]
Category structure: ranges associated with QGLikelihood histograms.
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
std::vector< Entry > data
bool getVectorFromFile(TFile *, std::vector< float > &, const TString &)
tuple size
Write out results.
virtual void QGLikelihoodDBWriter::endJob ( void  )
inlineoverridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 29 of file QGLikelihoodDBWriter.cc.

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

Definition at line 48 of file QGLikelihoodDBWriter.cc.

References i.

Referenced by beginJob().

48  {
49  TVectorT<float> *tVector = nullptr;
50  f->GetObject(name, tVector);
51  if(!tVector) return false;
52  for(int i = 0; i < tVector->GetNoElements(); ++i) vector.push_back((*tVector)[i]);
53  return true;
54 }
int i
Definition: DBlmapReader.cc:9
double f[11][100]
QGLikelihoodObject::Histogram QGLikelihoodDBWriter::transformToHistogramObject ( TH1 *  th1)
private

Definition at line 58 of file QGLikelihoodDBWriter.cc.

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

Referenced by beginJob().

58  {
59  QGLikelihoodObject::Histogram histogram(th1->GetNbinsX(), th1->GetXaxis()->GetBinLowEdge(1), th1->GetXaxis()->GetBinUpEdge(th1->GetNbinsX()));
60  for(int ibin = 0; ibin <= th1->GetNbinsX() + 1; ++ibin) histogram.setBinContent(ibin, th1->GetBinContent(ibin));
61  return histogram;
62 }
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 66 of file QGLikelihoodDBWriter.cc.

References ecalBxOrbitNumberGrapher_cfg::categories, HLT_25ns14e33_v3_cff::EtaMax, Gflash::EtaMin, and HLT_25ns14e33_v1_cff::PtMin.

Referenced by beginJob().

66  {
67  if(!pdfs[binNumbers]) return;
68  std::vector<int> neighbour = binNumbers;
69  do {
70  if(--(neighbour[index]) < 0) return;
71  } while (!pdfs[neighbour]);
72  if(TString(pdfs[binNumbers]->GetTitle()) != TString(pdfs[neighbour]->GetTitle())) return;
73  if(index != 4 && categories[neighbour].RhoMax != categories[binNumbers].RhoMax) return;
74  if(index != 4 && categories[neighbour].RhoMin != categories[binNumbers].RhoMin) return;
75  if(index != 3 && categories[neighbour].PtMax != categories[binNumbers].PtMax) return;
76  if(index != 3 && categories[neighbour].PtMin != categories[binNumbers].PtMin) return;
77  if(index != 2 && categories[neighbour].EtaMax != categories[binNumbers].EtaMax) return;
78  if(index != 2 && categories[neighbour].EtaMin != categories[binNumbers].EtaMin) return;
79 
80  if(index == 4) categories[neighbour].RhoMax = categories[binNumbers].RhoMax;
81  if(index == 3) categories[neighbour].PtMax = categories[binNumbers].PtMax;
82  if(index == 2) categories[neighbour].EtaMax = categories[binNumbers].EtaMax;
83  pdfs.erase(binNumbers);
84  categories.erase(binNumbers);
85 }
const double EtaMin[kNumberCalorimeter]

Member Data Documentation

std::string QGLikelihoodDBWriter::inputRootFile
private

Definition at line 36 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().

std::string QGLikelihoodDBWriter::payloadTag
private

Definition at line 36 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().