CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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),
19  _prefix(dtca._prefix){ }
20 
22 
23  if(this != &dtca) {
24  _file = dtca._file;
25  _runnumber = dtca._runnumber;
26  _module = dtca._module;
27  _path = dtca._path;
28  _prefix = dtca._prefix;
29  }
30  return *this;
31 }
32 
35 void CommonAnalyzer::setModule(const char* mod) { _module = mod; }
36 void CommonAnalyzer::setPath(const char* path) { _path = path; }
38 
41 const std::string& CommonAnalyzer::getPath() const {return _path;}
43 
44 TObject* CommonAnalyzer::getObject(const char* name) const {
45 
46  TObject* obj = 0;
47 
48  std::string fullpath = _module + "/" + _path;
49  if(_file) {
50  bool ok = _file->cd(fullpath.c_str());
51  if(ok && gDirectory) {
52  obj = gDirectory->Get(name);
53  }
54  }
55  return obj;
56 
57 }
58 
59 TNamed* CommonAnalyzer::getObjectWithSuffix(const char* name, const char* suffix) const {
60 
61  TNamed* obj = (TNamed*)getObject(name);
62 
63  if(obj) {
64  if(!strstr(obj->GetTitle(),"run")) {
65  char htitle[300];
66  sprintf(htitle,"%s %s run %s",obj->GetTitle(),suffix,_runnumber.c_str());
67  obj->SetTitle(htitle);
68  }
69  }
70  return obj;
71 
72 }
73 
74 const std::vector<unsigned int> CommonAnalyzer::getRunList() const {
75 
76  std::vector<unsigned int> runlist;
77 
78  std::string fullpath = _module + "/" + _path;
79  if(_file) {
80  bool ok = _file->cd(fullpath.c_str());
81  if(ok && gDirectory) {
82  TList* keys = gDirectory->GetListOfKeys();
83  TListIter it(keys);
84  TKey* key=0;
85  while((key=(TKey*)it.Next())) {
86  std::cout << key->GetName() << std::endl;
87  TClass cl(key->GetClassName());
88  if (cl.InheritsFrom("TDirectory") && strstr(key->GetName(),"run_") != 0 ) {
89  unsigned int run;
90  sscanf(key->GetName(),"run_%u",&run);
91  runlist.push_back(run);
92  }
93  }
94 
95  }
96  }
97  // sort(runlist);
98  return runlist;
99 
100 }
101 
102 TH1F* CommonAnalyzer::getBinomialRatio(const CommonAnalyzer& denom, const char* name, const int rebin) const {
103 
104  TH1F* den = (TH1F*)denom.getObject(name);
105  TH1F* num = (TH1F*)getObject(name);
106  TH1F* ratio =0;
107 
108  if(den!=0 && num!=0) {
109 
110  TH1F* denreb=den;
111  TH1F* numreb=num;
112  if(rebin>0) {
113  denreb = (TH1F*)den->Rebin(rebin,"denrebinned");
114  numreb = (TH1F*)num->Rebin(rebin,"numrebinned");
115  }
116 
117  ratio = new TH1F(*numreb);
118  ratio->SetDirectory(0);
119  ratio->Reset();
120  ratio->Sumw2();
121  ratio->Divide(numreb,denreb,1,1,"B");
122  delete denreb;
123  delete numreb;
124  }
125 
126  return ratio;
127 }
TH1F * getBinomialRatio(const CommonAnalyzer &denom, const char *name, const int rebin=-1) const
const std::string & getRunNumber() const
TNamed * getObjectWithSuffix(const char *name, const char *suffix="") const
std::string _prefix
void setRunNumber(const char *run)
TObject * getObject(const char *name) const
std::string _runnumber
const std::string & getPath() const
tuple runlist
Definition: lumiPlot.py:292
std::string _module
void setModule(const char *mod)
const std::string & getPrefix() const
CommonAnalyzer & operator=(const CommonAnalyzer &dtca)
std::string _path
void setPath(const char *path)
CommonAnalyzer(TFile *file, const char *run, const char *mod, const char *path="", const char *prefix="")
const std::vector< unsigned int > getRunList() const
const std::string & getModule() const
void setFile(TFile *file)
list key
Definition: combine.py:13
tuple cout
Definition: gather_cfg.py:121
void setPrefix(const char *prefix)
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4