CMS 3D CMS Logo

CommonAnalyzer.cc
Go to the documentation of this file.
1 #include <iostream>
3 #include "TFile.h"
4 #include "TDirectory.h"
5 #include "TObject.h"
6 #include "TH1F.h"
7 #include "TNamed.h"
8 #include "TList.h"
9 #include "TKey.h"
10 #include "TClass.h"
11 #include <string>
12 #include <vector>
13 
14 CommonAnalyzer::CommonAnalyzer(TFile* file, const char* run, const char* mod, const char* path, const char* prefix)
15  : _file(file), _runnumber(run), _module(mod), _path(path), _prefix(prefix) {}
16 
18  : _file(dtca._file), _runnumber(dtca._runnumber), _module(dtca._module), _path(dtca._path), _prefix(dtca._prefix) {}
19 
21  if (this != &dtca) {
22  _file = dtca._file;
23  _runnumber = dtca._runnumber;
24  _module = dtca._module;
25  _path = dtca._path;
26  _prefix = dtca._prefix;
27  }
28  return *this;
29 }
30 
33 void CommonAnalyzer::setModule(const char* mod) { _module = mod; }
34 void CommonAnalyzer::setPath(const char* path) { _path = path; }
36 
38 const std::string& CommonAnalyzer::getModule() const { return _module; }
39 const std::string& CommonAnalyzer::getPath() const { return _path; }
40 const std::string& CommonAnalyzer::getPrefix() const { return _prefix; }
41 
42 TObject* CommonAnalyzer::getObject(const char* name) const {
43  TObject* obj = nullptr;
44 
46  if (_file) {
47  bool ok = _file->cd(fullpath.c_str());
48  if (ok && gDirectory) {
49  obj = gDirectory->Get(name);
50  }
51  }
52  return obj;
53 }
54 
55 TNamed* CommonAnalyzer::getObjectWithSuffix(const char* name, const char* suffix) const {
56  TNamed* obj = (TNamed*)getObject(name);
57 
58  if (obj) {
59  if (!strstr(obj->GetTitle(), "run")) {
60  char htitle[300];
61  sprintf(htitle, "%s %s run %s", obj->GetTitle(), suffix, _runnumber.c_str());
62  obj->SetTitle(htitle);
63  }
64  }
65  return obj;
66 }
67 
68 const std::vector<unsigned int> CommonAnalyzer::getRunList() const { return getList("run"); }
69 
70 const std::vector<unsigned int> CommonAnalyzer::getFillList() const { return getList("fill"); }
71 
72 const std::vector<unsigned int> CommonAnalyzer::getList(const char* what) const {
73  std::vector<unsigned int> runlist;
74  char searchstring[100];
75  char decodestring[100];
76  sprintf(searchstring, "%s_", what);
77  sprintf(decodestring, "%s_%%u", what);
78 
80  if (_file) {
81  bool ok = _file->cd(fullpath.c_str());
82  if (ok && gDirectory) {
83  TList* keys = gDirectory->GetListOfKeys();
84  TListIter it(keys);
85  TKey* key = nullptr;
86  while ((key = (TKey*)it.Next())) {
87  std::cout << key->GetName() << std::endl;
88  TClass cl(key->GetClassName());
89  if (cl.InheritsFrom("TDirectory") && strstr(key->GetName(), searchstring) != nullptr) {
90  unsigned int run;
91  sscanf(key->GetName(), decodestring, &run);
92  runlist.push_back(run);
93  }
94  }
95  }
96  }
97  // sort(runlist);
98  return runlist;
99 }
100 
101 TH1F* CommonAnalyzer::getBinomialRatio(const CommonAnalyzer& denom, const char* name, const int rebin) const {
102  TH1F* den = (TH1F*)denom.getObject(name);
103  TH1F* num = (TH1F*)getObject(name);
104  TH1F* ratio = nullptr;
105 
106  if (den != nullptr && num != nullptr) {
107  TH1F* denreb = den;
108  TH1F* numreb = num;
109  if (rebin > 0) {
110  denreb = (TH1F*)den->Rebin(rebin, "denrebinned");
111  numreb = (TH1F*)num->Rebin(rebin, "numrebinned");
112  }
113 
114  ratio = new TH1F(*numreb);
115  ratio->SetDirectory(nullptr);
116  ratio->Reset();
117  ratio->Sumw2();
118  ratio->Divide(numreb, denreb, 1, 1, "B");
119  delete denreb;
120  delete numreb;
121  }
122 
123  return ratio;
124 }
reco_skim_cfg_mod.fullpath
fullpath
Definition: reco_skim_cfg_mod.py:202
makePileupJSON.denom
denom
Definition: makePileupJSON.py:146
CommonAnalyzer.h
CommonAnalyzer::getObject
TObject * getObject(const char *name) const
Definition: CommonAnalyzer.cc:42
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
gather_cfg.cout
cout
Definition: gather_cfg.py:144
CommonAnalyzer::getPath
const std::string & getPath() const
Definition: CommonAnalyzer.cc:39
CommonAnalyzer::setPrefix
void setPrefix(const char *prefix)
Definition: CommonAnalyzer.cc:35
CommonAnalyzer::getPrefix
const std::string & getPrefix() const
Definition: CommonAnalyzer.cc:40
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
CommonAnalyzer::operator=
CommonAnalyzer & operator=(const CommonAnalyzer &dtca)
Definition: CommonAnalyzer.cc:20
CommonAnalyzer::_runnumber
std::string _runnumber
Definition: CommonAnalyzer.h:42
CommonAnalyzer
Definition: CommonAnalyzer.h:12
createPayload.suffix
suffix
Definition: createPayload.py:281
CommonAnalyzer::setModule
void setModule(const char *mod)
Definition: CommonAnalyzer.cc:33
GetRecoTauVFromDQM_MC_cff.cl
cl
Definition: GetRecoTauVFromDQM_MC_cff.py:38
CommonAnalyzer::getBinomialRatio
TH1F * getBinomialRatio(const CommonAnalyzer &denom, const char *name, const int rebin=-1) const
Definition: CommonAnalyzer.cc:101
CommonAnalyzer::_module
std::string _module
Definition: CommonAnalyzer.h:43
CommonAnalyzer::setRunNumber
void setRunNumber(const char *run)
Definition: CommonAnalyzer.cc:31
CommonAnalyzer::getFillList
const std::vector< unsigned int > getFillList() const
Definition: CommonAnalyzer.cc:70
CommonAnalyzer::setPath
void setPath(const char *path)
Definition: CommonAnalyzer.cc:34
particleFlowDisplacedVertex_cfi.ratio
ratio
Definition: particleFlowDisplacedVertex_cfi.py:93
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
CommonAnalyzer::setFile
void setFile(TFile *file)
Definition: CommonAnalyzer.cc:32
CommonAnalyzer::getModule
const std::string & getModule() const
Definition: CommonAnalyzer.cc:38
geometryDiff.file
file
Definition: geometryDiff.py:13
CommonAnalyzer::getList
const std::vector< unsigned int > getList(const char *what) const
Definition: CommonAnalyzer.cc:72
test_db_connect.runlist
runlist
Definition: test_db_connect.py:20
CommonAnalyzer::getObjectWithSuffix
TNamed * getObjectWithSuffix(const char *name, const char *suffix="") const
Definition: CommonAnalyzer.cc:55
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:33
CommonAnalyzer::_path
std::string _path
Definition: CommonAnalyzer.h:44
CommonAnalyzer::getRunList
const std::vector< unsigned int > getRunList() const
Definition: CommonAnalyzer.cc:68
writedatasetfile.run
run
Definition: writedatasetfile.py:27
CommonAnalyzer::CommonAnalyzer
CommonAnalyzer(TFile *file, const char *run, const char *mod, const char *path="", const char *prefix="")
Definition: CommonAnalyzer.cc:14
CommonAnalyzer::_prefix
std::string _prefix
Definition: CommonAnalyzer.h:45
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
CommonAnalyzer::_file
TFile * _file
Definition: CommonAnalyzer.h:41
crabWrapper.key
key
Definition: crabWrapper.py:19
hcallasereventfilter2012_cfi.prefix
prefix
Definition: hcallasereventfilter2012_cfi.py:10
CommonAnalyzer::getRunNumber
const std::string & getRunNumber() const
Definition: CommonAnalyzer.cc:37