CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
TestHistoMgr Class Reference

#include <TestHistoMgr.h>

Public Member Functions

bool addHisto1 (TH1F *ih)
 
bool addHisto2 (TH2F *ih)
 
bool addHistoProf1 (TProfile *ih)
 
bool addHistoProf2 (TProfile2D *ih)
 
TH1F * getHisto1 (int ih)
 
TH1F * getHisto1FromSecondFile (const char *hnam)
 
TH2F * getHisto2 (int ih)
 
TProfile * getHistoProf1 (int ih)
 
TProfile2D * getHistoProf2 (int ih)
 
void openSecondFile (const std::string &name)
 
void printComparisonResult (int ih)
 
void save (const std::string &name)
 
 TestHistoMgr ()
 
 ~TestHistoMgr ()
 

Private Attributes

std::unique_ptr< TFile > theFileRef
 
mihp1 theHistoProfs1
 
mihp2 theHistoProfs2
 
mih1 theHistos1
 
mih2 theHistos2
 

Detailed Description

Definition at line 22 of file TestHistoMgr.h.

Constructor & Destructor Documentation

TestHistoMgr::TestHistoMgr ( )

Definition at line 18 of file TestHistoMgr.cc.

19 {
20  // pi_aida::Proxy_Selector::setHistogramType(pi_aida::Histogram_Native);
21 }
TestHistoMgr::~TestHistoMgr ( )

Definition at line 24 of file TestHistoMgr.cc.

References theHistoProfs1, theHistoProfs2, theHistos1, and theHistos2.

25 {
26  for(auto& it: theHistos1){
27  delete it.second;
28  }
29  for(auto& it: theHistos2){
30  delete it.second;
31  }
32  for(auto& it: theHistoProfs1){
33  delete it.second;
34  }
35  for(auto& it: theHistoProfs2){
36  delete it.second;
37  }
38 }
mihp2 theHistoProfs2
Definition: TestHistoMgr.h:49
mihp1 theHistoProfs1
Definition: TestHistoMgr.h:48

Member Function Documentation

bool TestHistoMgr::addHisto1 ( TH1F *  ih)

Definition at line 122 of file TestHistoMgr.cc.

References theHistos1.

123 {
124  int ih = atoi(sih->GetName());
125  theHistos1[ih] = sih;
126  edm::LogInfo("MaterialBudget") << "TestHistoMgr: addHisto1: " << ih << " = " << sih->GetTitle();
127  return true;
128 }
bool TestHistoMgr::addHisto2 ( TH2F *  ih)

Definition at line 130 of file TestHistoMgr.cc.

References theHistos2.

131 {
132  int ih = atoi(sih->GetName());
133  theHistos2[ih] = sih;
134  return true;
135 }
bool TestHistoMgr::addHistoProf1 ( TProfile *  ih)

Definition at line 138 of file TestHistoMgr.cc.

References theHistoProfs1.

139 {
140  int ih = atoi(sih->GetName());
141  theHistoProfs1[ih] = sih;
142  edm::LogInfo("MaterialBudget") << "TestHistoMgr: addHistoProf1: " << ih << " = " << sih->GetTitle();
143  return true;
144 }
mihp1 theHistoProfs1
Definition: TestHistoMgr.h:48
bool TestHistoMgr::addHistoProf2 ( TProfile2D *  ih)

Definition at line 146 of file TestHistoMgr.cc.

References theHistoProfs2.

147 {
148  int ih = atoi(sih->GetName());
149  theHistoProfs2[ih] = sih;
150  edm::LogInfo("MaterialBudget") << "TestHistoMgr: addHistoProf2: " << ih << " = " << sih->GetTitle();
151  return true;
152 }
mihp2 theHistoProfs2
Definition: TestHistoMgr.h:49
TH1F * TestHistoMgr::getHisto1 ( int  ih)

Definition at line 155 of file TestHistoMgr.cc.

References cppFunctionSkipper::exception, and theHistos1.

156 {
157  TH1F* his = nullptr;
158 
159  mih1::const_iterator ite = theHistos1.find( ih );
160  if( ite != theHistos1.end() ) {
161  his = (*ite).second;
162  } else {
163  edm::LogError("MaterialBudget") << "TestHistoMgr: getHisto1 Histogram does not exist " << ih;
164  std::exception();
165  }
166  return his;
167 }
TH1F * TestHistoMgr::getHisto1FromSecondFile ( const char *  hnam)

Definition at line 209 of file TestHistoMgr.cc.

References cppFunctionSkipper::exception, and theFileRef.

Referenced by printComparisonResult().

210 {
211  TH1F* his = new TH1F();
212  if( !theFileRef ){
213  edm::LogError("MaterialBudget") << "TestHistoMgr: Second file not yet opened ";
214  std::exception();
215  } else{
216  his = (TH1F*)(*theFileRef).Get(hnam);
217  }
218 
219  if( !his ) {
220  edm::LogError("MaterialBudget") << "TestHistoMgr: FATAL ERROR Histogram does not exist in second file " << hnam;
221  theFileRef->ls();
222  std::exception();
223  }
224  return his;
225 }
std::unique_ptr< TFile > theFileRef
Definition: TestHistoMgr.h:51
TH2F * TestHistoMgr::getHisto2 ( int  ih)

Definition at line 169 of file TestHistoMgr.cc.

References cppFunctionSkipper::exception, and theHistos2.

170 {
171  TH2F* his = nullptr;
172  mih2::const_iterator ite = theHistos2.find( ih );
173  if( ite != theHistos2.end() ) {
174  his = (*ite).second;
175  } else {
176  edm::LogError("MaterialBudget") << "TestHistoMgr: getHisto2 Histogram does not exist " << ih;
177  std::exception();
178  }
179  return his;
180 }
TProfile * TestHistoMgr::getHistoProf1 ( int  ih)

Definition at line 182 of file TestHistoMgr.cc.

References cppFunctionSkipper::exception, and theHistoProfs1.

183 {
184  TProfile* his = nullptr;
185  mihp1::const_iterator ite = theHistoProfs1.find( ih );
186  if( ite != theHistoProfs1.end() ) {
187  his = (*ite).second;
188  } else {
189  edm::LogError("MaterialBudget") << "TestHistoMgr: Profile Histogram 1D does not exist " << ih;
190  std::exception();
191  }
192  return his;
193 }
mihp1 theHistoProfs1
Definition: TestHistoMgr.h:48
TProfile2D * TestHistoMgr::getHistoProf2 ( int  ih)

Definition at line 196 of file TestHistoMgr.cc.

References cppFunctionSkipper::exception, and theHistoProfs2.

197 {
198  TProfile2D* his = nullptr;
199  mihp2::const_iterator ite = theHistoProfs2.find( ih );
200  if( ite != theHistoProfs2.end() ) {
201  his = (*ite).second;
202  } else {
203  edm::LogError("MaterialBudget") << "TestHistoMgr: Profile Histogram 2D does not exist " << ih;
204  std::exception();
205  }
206  return his;
207 }
mihp2 theHistoProfs2
Definition: TestHistoMgr.h:49
void TestHistoMgr::openSecondFile ( const std::string &  name)

Definition at line 69 of file TestHistoMgr.cc.

References theFileRef.

70 {
71 
72  theFileRef = std::make_unique<TFile>(name.c_str());
73 
74 }
std::unique_ptr< TFile > theFileRef
Definition: TestHistoMgr.h:51
void TestHistoMgr::printComparisonResult ( int  ih)

Definition at line 77 of file TestHistoMgr.cc.

References mixOne_premix_on_sim_cfi::comparator, gather_cfg::cout, getHisto1FromSecondFile(), and mps_fire::result.

78 {
79 
80 #ifdef StatTesting
81 
82  TH1F* histo2 = getHisto1FromSecondFile(histo1->GetName());
83 
84  StatisticsTesting::StatisticsComparator< StatisticsTesting::Chi2ComparisonAlgorithm > comparator;
85 
86 #ifdef PI121
87 
88  qStatisticsTesting::ComparisonResult result = comparator.compare(*histo1, *histo2);
89 
90 #else
91 
92  double result = comparator.compare(*histo1, *histo2);
93 
94 #endif
95 
96  // ---------------------------------------------------------
97  // Do something with (e.g. print out) the result of the test
98  // ---------------------------------------------------------
99  edm::LogInfo << "TestHistoMgr: Result of the Chi2 Statistical Test: " << histo1->GetName();
100 #ifdef PI121
101  << " distance = " << result.distance() << std::endl
102  << " ndf = " << result.ndf() << std::endl
103  << " p-value = " << result.quality() << std::endl
104 #else
105  << " p-value = " << result << std::endl
106  #endif
107  << "---------------- exampleReadXML ENDS ------------------ "
108  << std::endl;
109 #ifdef PI121
110  std::cout << "[OVAL]: HISTO_QUALITY " << histo1->GetName() <<" " << result.quality() << std::endl;
111  #else
112  std::cout << "[OVAL]: HISTO_QUALITY " << histo1->GetName() <<" " << result << std::endl;
113  #endif
114  std::cout << std::endl << " mean= " << histo1->GetMean() << " " << histo1->GetName() << " " << histo1->GetTitle() << std::endl;
115  std::cout << " rms= " << histo1->GetRMS() << " " << histo1->GetName() << " " << histo1->GetTitle() << std::endl;
116 
117 #else
118 #endif
119 }
TH1F * getHisto1FromSecondFile(const char *hnam)
void TestHistoMgr::save ( const std::string &  name)

Definition at line 41 of file TestHistoMgr.cc.

References groupFilesInBlocks::fout, theHistoProfs1, theHistoProfs2, theHistos1, and theHistos2.

42 {
43 
44  edm::LogInfo("MaterialBudget") << "TestHistoMgr: Save user histos";
45 
46  TFile fout(name.c_str(),"recreate");
47 
48  // write out the histos
49  mih1::const_iterator ite1;
50  mih2::const_iterator ite2;
51  mihp1::const_iterator itep1;
52  mihp2::const_iterator itep2;
53 
54  for( ite1 = theHistos1.begin(); ite1 != theHistos1.end(); ite1++ ){
55  ((*ite1).second)->Write();
56  }
57  for( ite2 = theHistos2.begin(); ite2 != theHistos2.end(); ite2++ ){
58  ((*ite2).second)->Write();
59  }
60  for( itep1 = theHistoProfs1.begin(); itep1 != theHistoProfs1.end(); itep1++ ){
61  ((*itep1).second)->Write();
62  }
63  for( itep2 = theHistoProfs2.begin(); itep2 != theHistoProfs2.end(); itep2++ ){
64  ((*itep2).second)->Write();
65  }
66 
67 }
mihp2 theHistoProfs2
Definition: TestHistoMgr.h:49
mihp1 theHistoProfs1
Definition: TestHistoMgr.h:48

Member Data Documentation

std::unique_ptr<TFile> TestHistoMgr::theFileRef
private

Definition at line 51 of file TestHistoMgr.h.

Referenced by getHisto1FromSecondFile(), and openSecondFile().

mihp1 TestHistoMgr::theHistoProfs1
private

Definition at line 48 of file TestHistoMgr.h.

Referenced by addHistoProf1(), getHistoProf1(), save(), and ~TestHistoMgr().

mihp2 TestHistoMgr::theHistoProfs2
private

Definition at line 49 of file TestHistoMgr.h.

Referenced by addHistoProf2(), getHistoProf2(), save(), and ~TestHistoMgr().

mih1 TestHistoMgr::theHistos1
private

Definition at line 46 of file TestHistoMgr.h.

Referenced by addHisto1(), getHisto1(), save(), and ~TestHistoMgr().

mih2 TestHistoMgr::theHistos2
private

Definition at line 47 of file TestHistoMgr.h.

Referenced by addHisto2(), getHisto2(), save(), and ~TestHistoMgr().