CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RunHistogramManager.cc
Go to the documentation of this file.
6 #include "TH1F.h"
7 #include "TH2F.h"
8 #include "TProfile.h"
9 #include "TProfile2D.h"
10 
12 
14 
15 /*
16 void BaseHistoParams::beginRun(const edm::Run& iRun, TFileDirectory& subrun) {
17 
18  beginRun(iRun.run(),subrun);
19 
20 }
21 */
22 
23 
24 
26  _fillHistograms(fillHistograms),
27  _histograms(),
28  _conditionsInRunToken(iC.consumes<edm::ConditionsInRunBlock,edm::InRun>(edm::InputTag("conditionsInEdm"))) {}
29 
31  _fillHistograms(fillHistograms),
32  _histograms(),
33  _conditionsInRunToken(iC.consumes<edm::ConditionsInRunBlock,edm::InRun>(edm::InputTag("conditionsInEdm"))) {}
34 
35 TH1F** RunHistogramManager::makeTH1F(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
36 
37  TH1F** pointer =new TH1F*(0);
38 
39  BaseHistoParams* hp = new HistoParams<TH1F>(pointer,"TH1F",name,title,nbinx,xmin,xmax);
40  _histograms.push_back(hp);
41 
42  LogDebug("TH1Fmade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
43 
44  return pointer;
45 
46 }
47 
49 
50  for(std::vector<BaseHistoParams*>::const_iterator hp=_histograms.begin();hp!=_histograms.end();++hp) {
51 
52  delete *hp;
53 
54  }
55  LogDebug("Destructor") << "All BaseHistoParams destroyed ";
56 
57 }
58 
59 TProfile** RunHistogramManager::makeTProfile(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax) {
60 
61  TProfile** pointer =new TProfile*(0);
62 
63  BaseHistoParams* hp = new HistoParams<TProfile>(pointer,"TProfile",name,title,nbinx,xmin,xmax);
64  _histograms.push_back(hp);
65 
66  LogDebug("TProfilemade") << "Histogram " << name << " " << title << " pre-booked:" << _histograms.size();
67 
68  return pointer;
69 
70 }
71 
72 TH2F** RunHistogramManager::makeTH2F(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax ) {
73 
74  TH2F** pointer = new TH2F*(0);
75 
76  BaseHistoParams* hp = new HistoParams<TH2F>(pointer,"TH2F",name,title,nbinx,xmin,xmax,nbiny,ymin,ymax);
77  _histograms.push_back(hp);
78 
79  LogDebug("TH2Fmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
80 
81  return pointer;
82 }
83 
84 TProfile2D** RunHistogramManager::makeTProfile2D(const char* name, const char* title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax ) {
85 
86  TProfile2D** pointer = new TProfile2D*(0);
87 
88  BaseHistoParams* hp = new HistoParams<TProfile2D>(pointer,"TProfile2D",name,title,nbinx,xmin,xmax,nbiny,ymin,ymax);
89  _histograms.push_back(hp);
90 
91  LogDebug("TProfile2Dmade") << "Histogram " << name << " " << title << " pre-booked :" << _histograms.size();
92 
93  return pointer;
94 }
95 
97 
99  beginRun(iRun, tfserv->tFileDirectory());
100 
101 }
102 
104 
105  if(!_fillHistograms) {
106  beginRun(iRun.run(),subdir);
107  }
108  else {
109  unsigned int fillnum = 0;
110 
113 
114  if(!cirb.failedToGet() && cirb.isValid()) fillnum=cirb->lhcFillNumber;
115 
116  beginRun(fillnum,subdir);
117  }
118 }
119 
120 void RunHistogramManager::beginRun(const unsigned int irun) {
121 
123  beginRun(irun, tfserv->tFileDirectory());
124 
125 }
126 
127 void RunHistogramManager::beginRun(const unsigned int irun, TFileDirectory& subdir) {
128 
129  // create/go to the run subdirectory
130 
131  char fillrun[30];
132 
133  if(!_fillHistograms) {
134  sprintf(fillrun,"%s","run");
135  }
136  else {
137  sprintf(fillrun,"%s","fill");
138  }
139 
140  char dirname[300];
141  sprintf(dirname,"%s_%d",fillrun,irun);
142  TFileDirectory subrun = subdir.mkdir(dirname);
143 
144  // loop on the histograms and update the pointer references
145 
146  for(unsigned int ih=0;ih<_histograms.size();++ih) {
147 
148  _histograms[ih]->beginRun(irun,subrun,fillrun);
149 
150  }
151 }
152 
#define LogDebug(id)
edm::EDGetTokenT< edm::ConditionsInRunBlock > _conditionsInRunToken
RunNumber_t run() const
Definition: RunBase.h:42
TFileDirectory & tFileDirectory()
Definition: TFileService.h:42
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:253
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
RunHistogramManager(edm::ConsumesCollector &&iC, const bool fillHistograms=false)
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
std::vector< BaseHistoParams * > _histograms
bool isValid() const
Definition: HandleBase.h:75
bool failedToGet() const
Definition: HandleBase.h:79
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
TProfile2D ** makeTProfile2D(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax)
void beginRun(const edm::Run &iRun)
TH2F ** makeTH2F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax, const unsigned int nbiny, const double ymin, const double ymax)
Definition: Run.h:41