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),
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  return getList("run");
77 
78 }
79 
80 const std::vector<unsigned int> CommonAnalyzer::getFillList() const {
81 
82  return getList("fill");
83 
84 }
85 
86 const std::vector<unsigned int> CommonAnalyzer::getList(const char* what) const {
87 
88  std::vector<unsigned int> runlist;
89  char searchstring[100];
90  char decodestring[100];
91  sprintf(searchstring,"%s_",what);
92  sprintf(decodestring,"%s_%%u",what);
93 
94  std::string fullpath = _module + "/" + _path;
95  if(_file) {
96  bool ok = _file->cd(fullpath.c_str());
97  if(ok && gDirectory) {
98  TList* keys = gDirectory->GetListOfKeys();
99  TListIter it(keys);
100  TKey* key=0;
101  while((key=(TKey*)it.Next())) {
102  std::cout << key->GetName() << std::endl;
103  TClass cl(key->GetClassName());
104  if (cl.InheritsFrom("TDirectory") && strstr(key->GetName(),searchstring) != 0 ) {
105  unsigned int run;
106  sscanf(key->GetName(),decodestring,&run);
107  runlist.push_back(run);
108  }
109  }
110 
111  }
112  }
113  // sort(runlist);
114  return runlist;
115 
116 }
117 
118 TH1F* CommonAnalyzer::getBinomialRatio(const CommonAnalyzer& denom, const char* name, const int rebin) const {
119 
120  TH1F* den = (TH1F*)denom.getObject(name);
121  TH1F* num = (TH1F*)getObject(name);
122  TH1F* ratio =0;
123 
124  if(den!=0 && num!=0) {
125 
126  TH1F* denreb=den;
127  TH1F* numreb=num;
128  if(rebin>0) {
129  denreb = (TH1F*)den->Rebin(rebin,"denrebinned");
130  numreb = (TH1F*)num->Rebin(rebin,"numrebinned");
131  }
132 
133  ratio = new TH1F(*numreb);
134  ratio->SetDirectory(0);
135  ratio->Reset();
136  ratio->Sumw2();
137  ratio->Divide(numreb,denreb,1,1,"B");
138  delete denreb;
139  delete numreb;
140  }
141 
142  return ratio;
143 }
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
std::string _module
void setModule(const char *mod)
const std::string & getPrefix() const
CommonAnalyzer & operator=(const CommonAnalyzer &dtca)
std::string _path
const std::vector< unsigned int > getList(const char *what) const
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)
void setPrefix(const char *prefix)
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
const std::vector< unsigned int > getFillList() const