CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BTagValidator.cc
Go to the documentation of this file.
1 
14 
15 // root include files
16 #include "TClass.h"
17 #include "TDirectory.h"
18 #include "TH1.h"
19 #include "TH2.h"
20 #include "TH3.h"
21 #include "TString.h"
22 
25 
29 
30 //
31 // constructors and destructor
32 //
34 
35 
36  algorithm_ = iConfig.getParameter<std::string>( "algorithm" );
37  rootFile_ = iConfig.getParameter<std::string>( "rootfile" );
38  DQMFile_ = iConfig.getParameter<std::string>( "DQMFile" );
39  TString tversion(edm::getReleaseVersion());
40  tversion = tversion.Remove(0,1);
41  tversion = tversion.Remove(tversion.Length()-1,tversion.Length());
42  DQMFile_ = std::string(tversion)+"_"+DQMFile_;
43  histogramList_ = iConfig.getParameter<vstring>( "histogramList" );
44  referenceFilename_ = iConfig.getParameter<std::string>( "referenceFilename" );
45  doCompare_ = iConfig.getParameter<bool>( "compareHistograms");
46 }
47 
48 
50 
51 }
52 
53 
54 //
55 // member functions
56 //
57 
58 // ------------ method called to for each event ------------
59 void
61 { }
62 
63 
64 void
66 {
67  // Validation section
68  TObject * tObject ;
69 
70  // DQM element
71  MonitorElement* monElement ;
72  MonitorElement* monElementRes;
73 
74  TFile * file = new TFile ( TString ( rootFile_ ) ) ;
75 
76  // comparison
77  HistoCompare hcompare;
78 
79  if (doCompare_) hcompare.SetReferenceFilename(TString(referenceFilename_) );
80 
81  file->cd();
82 
83  // get hold of back-end interface
85 
86  dbe->setCurrentFolder( "RecoBV/"+algorithm_ );
87 
88  for (std::size_t i=0; i<histogramList_.size(); ++i) {
89 
90  tObject = gDirectory->Get( TString( histogramList_[i] ) ) ;
91 
92  if ( tObject == 0 )
93  throw cms::Exception("BTagValidator") << "Histogram " << histogramList_[i] << " was not produced in the analysis. ";
94 
95  if ( tObject->IsA()->InheritsFrom( "TH1" ) ) {
96 
97  TH1 * histogram = (TH1*) tObject ;
98 
99  TH1* hresiduals = 0;
100 
101  if (doCompare_)
102  hresiduals = hcompare.Compare(histogram, "/DQMData/"+TString(algorithm_)+"/"+TString(histogram->GetName()) );
103 
104  file->cd();
105 
106  monElement = dbe->book1D (
107  std::string( histogram->GetName() ),
108  std::string( histogram->GetTitle() ),
109  histogram->GetXaxis()->GetNbins(),
110  histogram->GetXaxis()->GetXmin(),
111  histogram->GetXaxis()->GetXmax()
112  );
113 
114  monElement->setAxisTitle( std::string ( histogram->GetXaxis()->GetTitle()) , 1);
115  monElement->setAxisTitle( std::string ( histogram->GetYaxis()->GetTitle()) , 2);
116 
117 
118  for(Int_t x=0; x<histogram->GetXaxis()->GetNbins(); x++) {
119  monElement->setBinContent ( x, histogram->GetBinContent( x ) ) ;
120  monElement->setBinError ( x, histogram->GetBinError( x ) ) ;
121  }
122 
123  if (doCompare_ && hresiduals!= 0 ) {
124  monElementRes = dbe->book1D (
125  std::string( hresiduals->GetName() ),
126  std::string( hresiduals->GetTitle() ),
127  hresiduals->GetXaxis()->GetNbins(),
128  hresiduals->GetXaxis()->GetXmin(),
129  hresiduals->GetXaxis()->GetXmax()
130  );
131 
132 
133  for(Int_t x=0; x<hresiduals->GetXaxis()->GetNbins(); x++) {
134  monElementRes->setBinContent ( x, hresiduals->GetBinContent( x ) ) ;
135  monElementRes->setBinError ( x, hresiduals->GetBinError( x ) ) ;
136  }
137  }
138  }
139  else if ( tObject->IsA()->InheritsFrom( "TH2" ) ) {
140 
141  TH2 * histogram = (TH2*) tObject ;
142 
143  monElement = dbe->book2D (
144  std::string( histogram->GetName() ),
145  std::string( histogram->GetTitle() ),
146  histogram->GetXaxis()->GetNbins(),
147  histogram->GetXaxis()->GetXmin(),
148  histogram->GetXaxis()->GetXmax(),
149  histogram->GetYaxis()->GetNbins(),
150  histogram->GetYaxis()->GetXmin(),
151  histogram->GetYaxis()->GetXmax()
152  );
153 
154  monElement->setAxisTitle( std::string ( histogram->GetXaxis()->GetTitle()) , 1);
155  monElement->setAxisTitle( std::string ( histogram->GetYaxis()->GetTitle()) , 2);
156 
157  for(Int_t x=0; x<histogram->GetXaxis()->GetNbins(); x++)
158  for(Int_t y=0; y<histogram->GetYaxis()->GetNbins(); y++) {
159  monElement->setBinContent ( x, y, histogram->GetBinContent( x, y ) ) ;
160  monElement->setBinError ( x, y, histogram->GetBinError( x, y ) ) ;
161  }
162  }
163  else if ( tObject->IsA()->InheritsFrom( "TH3" ) ) {
164 
165  TH3 * histogram = (TH3*) tObject ;
166 
167  monElement = dbe->book3D (
168  std::string( histogram->GetName() ),
169  std::string( histogram->GetTitle() ),
170  histogram->GetXaxis()->GetNbins(),
171  histogram->GetXaxis()->GetXmin(),
172  histogram->GetXaxis()->GetXmax(),
173  histogram->GetYaxis()->GetNbins(),
174  histogram->GetYaxis()->GetXmin(),
175  histogram->GetYaxis()->GetXmax(),
176  histogram->GetZaxis()->GetNbins(),
177  histogram->GetZaxis()->GetXmin(),
178  histogram->GetZaxis()->GetXmax()
179  );
180 
181  monElement->setAxisTitle( std::string ( histogram->GetXaxis()->GetTitle()) , 1);
182  monElement->setAxisTitle( std::string ( histogram->GetYaxis()->GetTitle()) , 2);
183 
184  for(Int_t x=0; x<histogram->GetXaxis()->GetNbins(); x++)
185  for(Int_t y=0; y<histogram->GetYaxis()->GetNbins(); y++)
186  for(Int_t z=0; z<histogram->GetZaxis()->GetNbins(); z++) {
187  monElement->setBinContent ( x, y, z, histogram->GetBinContent( x, y, z ) ) ;
188  monElement->setBinError ( x, y, z, histogram->GetBinError( x, y, z ) ) ;
189  }
190  }
191  }
192 
193  dbe->showDirStructure() ;
194  dbe->save(DQMFile_) ;
195  file->Close() ;
196 
197 }
198 
199 //define this as a plug-in
virtual void analyze(const edm::Event &, const edm::EventSetup &)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
MonitorElement * book3D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ)
Book 3D histogram.
Definition: DQMStore.cc:979
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::string algorithm_
Definition: BTagValidator.h:49
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2113
double double double z
int iEvent
Definition: GenABIO.cc:243
vstring histogramList_
Definition: BTagValidator.h:53
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
std::string rootFile_
Definition: BTagValidator.h:50
void SetReferenceFilename(TString filename)
Definition: HistoCompare.h:35
std::string getReleaseVersion()
BTagValidator(const edm::ParameterSet &)
std::vector< std::string > vstring
Definition: BTagValidator.h:47
std::string DQMFile_
Definition: BTagValidator.h:51
std::string referenceFilename_
Definition: BTagValidator.h:52
void showDirStructure(void) const
Definition: DQMStore.cc:2761
virtual void endJob()
x
Definition: VDTMath.h:216
TH1 * Compare(TH1 *h, TString hname)
Definition: HistoCompare.cc:44
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429