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
 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
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

bool extractString (std::string, std::string &)
 

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 53 of file QGLikelihoodDBWriter.cc.

References cond::service::PoolDBOutputService::appendSinceTime(), cond::service::PoolDBOutputService::beginOfTime(), QGLikelihoodObject::Entry::category, python.rootplot.argparse::category, cond::service::PoolDBOutputService::createNewIOV(), QGLikelihoodObject::data, dir, cond::service::PoolDBOutputService::endOfTime(), QGLikelihoodCategory::EtaMax, QGLikelihoodCategory::EtaMin, extractString(), f, contentValuesFiles::fullPath, QGLikelihoodObject::Entry::histogram, inputRootFile, edm::Service< T >::isAvailable(), cond::service::PoolDBOutputService::isNewTagRequest(), relativeConstraints::keys, QGLikelihoodObject::Entry::mean, payloadTag, QGLikelihoodCategory::PtMax, QGLikelihoodCategory::PtMin, PtMinSelector_cfg::ptMin, QGLikelihoodCategory::QGIndex, QGLikelihoodObject::qgValidRange, QGLikelihoodCategory::RhoMax, QGLikelihoodCategory::RhoMin, alignCSCRings::s, PhysicsTools::Calibration::Histogram< Value_t, Axis_t >::setBinContent(), AlCaHLTBitMon_QueryRunRegistry::string, and QGLikelihoodCategory::VarIndex.

53  {
54 
55  QGLikelihoodObject *payload = new QGLikelihoodObject();
56  payload->data.clear();
57 
58  // Get the ROOT file and the vectors with binning information
59  TFile *f = TFile::Open(edm::FileInPath(inputRootFile.c_str()).fullPath().c_str());
60  TVectorT<float> *etaBins; f->GetObject("etaBins", etaBins);
61  TVectorT<float> *ptBinsC; f->GetObject("ptBinsC", ptBinsC);
62  TVectorT<float> *ptBinsF; f->GetObject("ptBinsF", ptBinsF);
63  TVectorT<float> *rhoBins; f->GetObject("rhoBins", rhoBins);
64 
65  // Get keys to the histograms
66  TList *keys = f->GetListOfKeys();
67  if(!keys){
68  edm::LogError("NoKeys") << "There are no keys in the input file." << std::endl;
69  return;
70  }
71 
72  // Loop over directories/histograms
73  TIter nextdir(keys);
74  TKey *keydir;
75  while((keydir = (TKey*)nextdir())){
76  if(!keydir->IsFolder()) continue;
77  TDirectory *dir = (TDirectory*)keydir->ReadObj() ;
78  TIter nexthist(dir->GetListOfKeys());
79  TKey *keyhist;
80  while((keyhist = (TKey*)nexthist())){
81  std::string histname = keyhist->GetName();
82  int varIndex, qgIndex;
83 
84  // First check the variable name, and use index in same order as RecoJets/JetProducers/plugins/QGTagger.cc:73
85  if(extractString("mult", histname)) varIndex = 0;
86  else if(extractString("ptD", histname)) varIndex = 1;
87  else if(extractString("axis2", histname)) varIndex = 2;
88  else continue;
89 
90  // Check quark or gluon
91  if(extractString("quark", histname)) qgIndex = 0;
92  else if(extractString("gluon", histname)) qgIndex = 1;
93  else continue;
94 
95  // Get eta, pt and rho ranges
96  extractString("eta-", histname);
97  int etaBin = std::atoi(histname.substr(0, histname.find("_")).c_str());
98  extractString("pt-", histname);
99  int ptBin = std::atoi(histname.substr(0, histname.find("_")).c_str());
100  extractString("rho-", histname);
101  int rhoBin = std::atoi(histname.substr(0, histname.find("_")).c_str());
102 
103  float etaMin = (*etaBins)[etaBin];
104  float etaMax = (*etaBins)[etaBin+1];
105  TVectorT<float> *ptBins = (etaBin == 0? ptBinsC : ptBinsF);
106  float ptMin = (*ptBins)[ptBin];
107  float ptMax = (*ptBins)[ptBin+1];
108  float rhoMin = (*rhoBins)[rhoBin];
109  float rhoMax = (*rhoBins)[rhoBin+1];
110 
111  // Print out for debugging
112  char buff[1000];
113  sprintf(buff, "%50s : var=%1d, qg=%1d, etaMin=%6.2f, etaMax=%6.2f, ptMin=%8.2f, ptMax=%8.2f, rhoMin=%6.2f, rhoMax=%6.2f", keyhist->GetName(), varIndex, qgIndex, etaMin, etaMax, ptMin, ptMax, rhoMin, rhoMax );
114  edm::LogVerbatim("HistName") << buff << std::endl;
115 
116  // Define category parameters
118  category.RhoMin = rhoMin;
119  category.RhoMax = rhoMax;
120  category.PtMin = ptMin;
121  category.PtMax = ptMax;
122  category.EtaMin = etaMin;
123  category.EtaMax = etaMax;
124  category.QGIndex = qgIndex;
125  category.VarIndex = varIndex;
126 
127  // Get TH1
128  TH1* th1hist = (TH1*) keyhist->ReadObj();
129 
130  // Transform ROOT TH1 to QGLikelihoodObject (same indexing)
131  QGLikelihoodObject::Histogram histogram(th1hist->GetNbinsX(), th1hist->GetXaxis()->GetBinLowEdge(1), th1hist->GetXaxis()->GetBinUpEdge(th1hist->GetNbinsX()));
132  for(int ibin = 0; ibin <= th1hist->GetNbinsX() + 1; ++ibin){
133  histogram.setBinContent(ibin, th1hist->GetBinContent(ibin));
134  }
135 
136  // Add this entry with its category parameters, histogram and mean
138  entry.category = category;
139  entry.histogram = histogram;
140  entry.mean = th1hist->GetMean();
141  payload->data.push_back(entry);
142  }
143  }
144  // Define the valid range, if no category is found within these bounds a warning will be thrown
145  payload->qgValidRange.RhoMin = rhoBins->Min();
146  payload->qgValidRange.RhoMax = rhoBins->Max();
147  payload->qgValidRange.EtaMin = etaBins->Min();
148  payload->qgValidRange.EtaMax = etaBins->Max();
149  payload->qgValidRange.PtMin = ptBinsC->Min();
150  payload->qgValidRange.PtMax = ptBinsC->Max();
151  payload->qgValidRange.QGIndex = -1;
152  payload->qgValidRange.VarIndex = -1;
153 
154  // Now write it into the DB
155  edm::LogInfo("UserOutput") << "Opening PoolDBOutputService" << std::endl;
156 
158  if(s.isAvailable()){
159  edm::LogInfo("UserOutput") << "Setting up payload with " << payload->data.size() << " entries and tag " << payloadTag << std::endl;
161  else s->appendSinceTime<QGLikelihoodObject>(payload, 111, payloadTag);
162  }
163  edm::LogInfo("UserOutput") << "Wrote in CondDB QGLikelihood payload label: " << payloadTag << std::endl;
164 }
QGLikelihoodCategory category
QGLikelihoodCategory qgValidRange
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
QGLikelihoodObject containing valid range and entries with category, histogram and mean...
bool isNewTagRequest(const std::string &recordName)
bool extractString(std::string, std::string &)
bool isAvailable() const
Definition: Service.h:46
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
dbl *** dir
Definition: mlp_gen.cc:35
virtual void QGLikelihoodDBWriter::endJob ( void  )
inlineoverridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 29 of file QGLikelihoodDBWriter.cc.

29 {}
bool QGLikelihoodDBWriter::extractString ( std::string  mySubstring,
std::string &  myString 
)
private

Definition at line 44 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob().

44  {
45  size_t subStringPos = myString.find(mySubstring);
46  if(subStringPos != std::string::npos){
47  myString = myString.substr(subStringPos + mySubstring.length(), std::string::npos);
48  return true;
49  } else return false;
50 }

Member Data Documentation

std::string QGLikelihoodDBWriter::inputRootFile
private

Definition at line 34 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().

std::string QGLikelihoodDBWriter::payloadTag
private

Definition at line 35 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().