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

Constructor & Destructor Documentation

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

Definition at line 29 of file QGLikelihoodDBWriter.cc.

29 {}

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 27 of file QGLikelihoodDBWriter.cc.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 52 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.

52  {
53 
54  QGLikelihoodObject *payload = new QGLikelihoodObject();
55  payload->data.clear();
56 
57  // Get the ROOT files and the keys to the histogram
58  TFile *f = TFile::Open(edm::FileInPath(inputRootFile.c_str()).fullPath().c_str());
59  TList *keys = f->GetListOfKeys();
60  if(!keys){
61  edm::LogError("NoKeys") << "There are no keys in the input file." << std::endl;
62  return;
63  }
64 
65  // Loop over directories/histograms
66  TIter nextdir(keys);
67  TKey *keydir;
68  while((keydir = (TKey*)nextdir())){
69  TDirectory *dir = (TDirectory*)keydir->ReadObj() ;
70  TIter nexthist(dir->GetListOfKeys());
71  TKey *keyhist;
72  while((keyhist = (TKey*)nexthist())){
73 
74  float ptMin, ptMax, rhoMin, rhoMax, etaMin, etaMax;
75  int varIndex, qgIndex;
76 
77  std::string histname = keyhist->GetName();
78  std::string histname_ = keyhist->GetName();
79 
80  // First check the variable name, and use index in same order as RecoJets/JetProducers/plugins/QGTagger.cc:73
81  if(extractString("nPFCand_QC_ptCutJet0", histname)) varIndex = 0;
82  else if(extractString("ptD_QCJet0", histname)) varIndex = 1;
83  else if(extractString("axis2_QCJet0", histname)) varIndex = 2;
84  else continue;
85 
86  // Check pseudorapidity range
87  if(extractString("_F", histname)){ etaMin = 2.5; etaMax = 4.7;}
88  else { etaMin = 0.;etaMax = 2.5;}
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  // Access the pt information
96  extractString("pt", histname);
97  ptMin = std::atof(histname.substr(0, histname.find("_")).c_str());
98  extractString("_", histname);
99  ptMax = std::atof(histname.substr(0, histname.find("rho")).c_str());
100 
101  if(etaMin == 2.5 && ptMin > 128) continue; //In forward use one bin for 127->2000
102  if(etaMin == 2.5 && ptMin == 127) ptMax = 4000;
103 
104  // Access the rho information
105  extractString("rho", histname);
106  rhoMin = std::atof(histname.c_str());
107  rhoMax = rhoMin + 1.; // WARNING: Check if this is still valid when changed to fixedGrid rho (try to move it in the name...)
108 
109  // Print out for debugging
110  char buff[1000];
111  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", histname_.c_str(), varIndex, qgIndex, etaMin, etaMax, ptMin, ptMax, rhoMin, rhoMax );
112  edm::LogVerbatim("HistName") << buff << std::endl;
113 
114  // Define category parameters
116  category.RhoMin = rhoMin;
117  category.RhoMax = rhoMax;
118  category.PtMin = ptMin;
119  category.PtMax = ptMax;
120  category.EtaMin = etaMin;
121  category.EtaMax = etaMax;
122  category.QGIndex = qgIndex;
123  category.VarIndex = varIndex;
124 
125  // Get TH1
126  TH1* th1hist = (TH1*) keyhist->ReadObj();
127 
128  // In the future, this part will (preferably) move to the making of the root files
129  if(th1hist->GetEntries()<50 ) th1hist->Rebin(5); // try to make it more stable
130  else if(th1hist->GetEntries()<500 ) th1hist->Rebin(2); // try to make it more stable
131  th1hist->Scale(1./th1hist->Integral("width"));
132 
133  // Transform ROOT TH1 to QGLikelihoodObject (same indexing)
134  QGLikelihoodObject::Histogram histogram(th1hist->GetNbinsX(), th1hist->GetXaxis()->GetBinLowEdge(1), th1hist->GetXaxis()->GetBinUpEdge(th1hist->GetNbinsX()));
135  for(int ibin = 0; ibin <= th1hist->GetNbinsX() + 1; ++ibin){
136  histogram.setBinContent(ibin, th1hist->GetBinContent(ibin));
137  }
138 
139  // Add this entry with its category parameters, histogram and mean
141  entry.category = category;
142  entry.histogram = histogram;
143  entry.mean = th1hist->GetMean();
144  payload->data.push_back(entry);
145  }
146  }
147 
148  // Define the valid range, if no category is found within these bounds a warning will be thrown
149  payload->qgValidRange.RhoMin = 0;
150  payload->qgValidRange.RhoMax = 46;
151  payload->qgValidRange.EtaMin = 0;
152  payload->qgValidRange.EtaMax = 4.7;
153  payload->qgValidRange.PtMin = 20;
154  payload->qgValidRange.PtMax = 4000;
155  payload->qgValidRange.QGIndex = -1;
156  payload->qgValidRange.VarIndex = -1;
157 
158  // Now write it into the DB
159  edm::LogInfo("UserOutput") << "Opening PoolDBOutputService" << std::endl;
160 
162  if(s.isAvailable()){
163  edm::LogInfo("UserOutput") << "Setting up payload with " << payload->data.size() << " entries and tag " << payloadTag << std::endl;
165  else s->appendSinceTime<QGLikelihoodObject>(payload, 111, payloadTag);
166  }
167  edm::LogInfo("UserOutput") << "Wrote in CondDB QGLikelihood payload label: " << payloadTag << std::endl;
168 }
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 28 of file QGLikelihoodDBWriter.cc.

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

Definition at line 43 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob().

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

Member Data Documentation

std::string QGLikelihoodDBWriter::inputRootFile
private

Definition at line 33 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().

std::string QGLikelihoodDBWriter::payloadTag
private

Definition at line 34 of file QGLikelihoodDBWriter.cc.

Referenced by beginJob(), and QGLikelihoodDBWriter().