CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
lsbs_cert.cc File Reference
#include <Riostream.h>
#include <TDirectory.h>
#include <TFile.h>
#include <TROOT.h>
#include <TStyle.h>
#include <TKey.h>
#include <TH1.h>
#include <TH2.h>
#include <TH2D.h>
#include <TCanvas.h>
#include <TGraph.h>
#include <TPaveStats.h>
#include <TText.h>
#include <TLegend.h>
#include <string.h>
#include <utility>
#include <vector>
#include <sstream>
#include <algorithm>
#include <TString.h>
#include <TColor.h>

Go to the source code of this file.

Functions

bool check_isgood (vector< int > &ls_badlist, int ls)
 
void check_offset (string filename, string iDir, string plot, float limit_min, float limit_max, vector< int > &badLS)
 
void check_sigma (string filename, string iDir, string plot, float limit_err, vector< int > &badLS)
 
void Cleaning (vector< int > &)
 
int getplot (string filename, string iDir, string strplot, TH1F &plot)
 
string ListOut (vector< int > &)
 
void lsbs_cert (string filename)
 
int main (int argc, char *argv[])
 
int nlumis (string filename)
 
string runnum_str (string filename)
 
void vector_AND (vector< int > &, vector< int >)
 

Variables

bool debug = false
 
int numlumis = -1
 

Function Documentation

bool check_isgood ( vector< int > &  ls_badlist,
int  ls 
)

Definition at line 278 of file lsbs_cert.cc.

References i.

Referenced by lsbs_cert().

279 {
280  //check if this LS is found in the BAD list
281  for ( unsigned int i = 0; i < ls_badlist.size() ; i++ )
282  {
283  if ( ls == ls_badlist[i] ) return false;
284  }
285  return true;
286 }
int i
Definition: DBlmapReader.cc:9
void check_offset ( string  filename,
string  iDir,
string  plot,
float  limit_min,
float  limit_max,
vector< int > &  badLS 
)

Definition at line 243 of file lsbs_cert.cc.

References getplot(), i, and relativeConstraints::value.

Referenced by lsbs_cert().

244 {
245  TH1F checkPlot;
246  if ( getplot ( filename , iDir , plot , checkPlot ) < 0 ) return;
247 
248 
249  //look at each LS, save the bad one
250  for ( int i = 1; i <= checkPlot.GetNbinsX() ; i++ )
251  {
252  float value = checkPlot.GetBinContent( i );
253  if ( value < limit_min || value > limit_max )
254  {
255  badLS.push_back( (int)checkPlot.GetBinCenter( i ) );
256  }
257  }
258 }
int i
Definition: DBlmapReader.cc:9
int getplot(string filename, string iDir, string strplot, TH1F &plot)
Definition: lsbs_cert.cc:332
tuple filename
Definition: lut2db_cfg.py:20
void check_sigma ( string  filename,
string  iDir,
string  plot,
float  limit_err,
vector< int > &  badLS 
)

Definition at line 261 of file lsbs_cert.cc.

References getplot(), i, and relativeConstraints::value.

Referenced by lsbs_cert().

262 {
263  TH1F checkPlot;
264  if ( getplot ( filename , iDir , plot , checkPlot ) < 0 ) return;
265 
266  //look at each LS
267  for ( int i = 1; i <= checkPlot.GetNbinsX() ; i++ )
268  {
269  float value = checkPlot.GetBinError( i );
270  if ( value > limit_err )
271  {
272  badLS.push_back( (int)checkPlot.GetBinCenter( i ) );
273  }
274  }
275 
276 }
int i
Definition: DBlmapReader.cc:9
int getplot(string filename, string iDir, string strplot, TH1F &plot)
Definition: lsbs_cert.cc:332
tuple filename
Definition: lut2db_cfg.py:20
void Cleaning ( vector< int > &  LSlist)
int getplot ( string  filename,
string  iDir,
string  strplot,
TH1F &  plot 
)

Definition at line 332 of file lsbs_cert.cc.

References dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, debug, dir, NULL, and runnum_str().

Referenced by check_offset(), and check_sigma().

333 {
334  string run = runnum_str( filename );
335  if (debug) std::cout << filename.c_str() << endl;
336 
337  TFile* file = TFile::Open(filename.c_str());
338  if (!file->IsOpen()) {
339  cerr << "Failed to open " << filename << endl;
340  return -1;
341  }
342 
343  string dir = "DQMData/Run " + run + "/AlcaBeamMonitor/Run summary/" + iDir;
344 
345  file->cd( dir.c_str() );
346 
347  string theplot = strplot + ";1";
348  TH1F* thisplot;
349  gDirectory->GetObject ( theplot.c_str() , thisplot );
350 
351  if ( !thisplot )
352  {
353  std::cout << "Error: plot " << dir << "/" << theplot.c_str() << " not found!" << endl;
354  return -2;
355  }
356 
357  plot = *thisplot;
358  thisplot = NULL;
359  delete thisplot;
360 
361  return 0;
362 }
string runnum_str(string filename)
Definition: ls_cert.cc:493
#define NULL
Definition: scimark2.h:8
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
#define debug
Definition: MEtoEDMFormat.h:34
string ListOut ( vector< int > &  LSlist)
void lsbs_cert ( string  filename)

Definition at line 52 of file lsbs_cert.cc.

References check_isgood(), check_offset(), check_sigma(), gather_cfg::cout, i, geometryCSVtoXML::line, ListOut(), python.rootplot.utilities::ls(), prof2calltree::namefile, nlumis(), numlumis, EdgesToViz::outfile, plotResiduals::plot(), runnum_str(), and vector_AND().

Referenced by main().

53 {
54  void check_offset ( string filename , string iDir , string plot , float limit_min , float limit_max , vector <int>& );
55  void check_sigma ( string filename , string iDir , string plot , float limit_err , vector <int>& );
56  bool check_isgood ( vector<int> & , int ls ); //check if this LS is good
57 
58  //presets
59  numlumis = -1;
60 
61  float limit_x = 0.002;
62  float limit_y = 0.002;
63  float limit_z = 0.5;
64  float limit_dx = 0.002;
65  float limit_dy = 0.002;
66  float limit_dz = 0.5;
67  float limit_errdx = 0.002;
68  float limit_errdy = 0.002;
69  float limit_errdz = 0.5;
70 
71 
72  //LS certification
73  vector <int> ls_x_bad;
74  vector <int> ls_y_bad;
75  vector <int> ls_z_bad;
76 
77  vector <int> ls_xsc_bad;
78  vector <int> ls_ysc_bad;
79  vector <int> ls_zsc_bad;
80 
81  vector <int> ls_dx_bad;
82  vector <int> ls_dy_bad;
83  vector <int> ls_dz_bad;
84 
85  vector <int> ls_dxsc_bad;
86  vector <int> ls_dysc_bad;
87  vector <int> ls_dzsc_bad;
88 
89  vector <int> ls_errdx_bad;
90  vector <int> ls_errdy_bad;
91  vector <int> ls_errdz_bad;
92 
93  vector <int> ls_errdxsc_bad;
94  vector <int> ls_errdysc_bad;
95  vector <int> ls_errdzsc_bad;
96 
97  vector <int> ls_good;
98  vector <int> ls_bad;
99 
100  //beamspot vs primary vertex
101  check_offset ( filename, "Validation" , "hxLumibased PrimaryVertex-DataBase" , -limit_x , limit_x , ls_x_bad );
102  check_offset ( filename, "Validation" , "hyLumibased PrimaryVertex-DataBase" , -limit_y , limit_y , ls_y_bad );
103  check_offset ( filename, "Validation" , "hzLumibased PrimaryVertex-DataBase" , -limit_z , limit_z , ls_z_bad );
104 
105  //beamspot vs scalers
106  check_offset ( filename, "Validation" , "hxLumibased Scalers-DataBase fit" , -limit_x , limit_x , ls_xsc_bad );
107  check_offset ( filename, "Validation" , "hyLumibased Scalers-DataBase fit" , -limit_y , limit_y , ls_ysc_bad );
108  check_offset ( filename, "Validation" , "hzLumibased Scalers-DataBase fit" , -limit_z , limit_z , ls_zsc_bad );
109 
110  check_offset ( filename, "Debug" , "hsigmaXLumibased PrimaryVertex-DataBase fit" , -limit_dx , limit_dx , ls_dx_bad );
111  check_offset ( filename, "Debug" , "hsigmaYLumibased PrimaryVertex-DataBase fit" , -limit_dy , limit_dy , ls_dy_bad );
112  check_offset ( filename, "Debug" , "hsigmaZLumibased PrimaryVertex-DataBase fit" , -limit_dz , limit_dz , ls_dz_bad );
113 
114  check_offset ( filename, "Validation" , "hsigmaXLumibased Scalers-DataBase fit" , -limit_dx , limit_dx , ls_dxsc_bad );
115  check_offset ( filename, "Validation" , "hsigmaYLumibased Scalers-DataBase fit" , -limit_dy , limit_dy , ls_dysc_bad );
116  check_offset ( filename, "Validation" , "hsigmaZLumibased Scalers-DataBase fit" , -limit_dz , limit_dz , ls_dzsc_bad );
117 
118  check_sigma ( filename, "Debug" , "hsigmaXLumibased PrimaryVertex-DataBase fit" , limit_errdx , ls_errdx_bad );
119  check_sigma ( filename, "Debug" , "hsigmaYLumibased PrimaryVertex-DataBase fit" , limit_errdy , ls_errdy_bad );
120  check_sigma ( filename, "Debug" , "hsigmaZLumibased PrimaryVertex-DataBase fit" , limit_errdz , ls_errdz_bad );
121 
122  check_sigma ( filename, "Validation" , "hsigmaXLumibased Scalers-DataBase fit" , limit_errdx , ls_errdxsc_bad );
123  check_sigma ( filename, "Validation" , "hsigmaYLumibased Scalers-DataBase fit" , limit_errdy , ls_errdysc_bad );
124  check_sigma ( filename, "Validation" , "hsigmaZLumibased Scalers-DataBase fit" , limit_errdz , ls_errdzsc_bad );
125 
126  //BAD LS only if bad in both histos (wrt PV, Scalers)
127  vector_AND ( ls_x_bad , ls_xsc_bad );
128  vector_AND ( ls_y_bad , ls_ysc_bad );
129  vector_AND ( ls_z_bad , ls_zsc_bad );
130  vector_AND ( ls_dx_bad , ls_dxsc_bad );
131  vector_AND ( ls_dy_bad , ls_dysc_bad );
132  vector_AND ( ls_dz_bad , ls_dzsc_bad );
133  vector_AND ( ls_errdx_bad , ls_errdxsc_bad );
134  vector_AND ( ls_errdy_bad , ls_errdysc_bad );
135  vector_AND ( ls_errdz_bad , ls_errdzsc_bad );
136 
137  //good LS = all LS minus BAD LS
138  for ( int i = 1; i <= nlumis ( filename ) ; i++ )
139  {
140  if ( !check_isgood ( ls_x_bad , i ) && !check_isgood ( ls_xsc_bad , i ) )
141  {
142  ls_bad.push_back ( i );
143  continue;
144  }
145  else
146  if ( !check_isgood ( ls_y_bad , i ) && !check_isgood ( ls_ysc_bad , i ) )
147  {
148  ls_bad.push_back ( i );
149  continue;
150  }
151  else
152  if ( !check_isgood ( ls_z_bad , i ) && !check_isgood ( ls_zsc_bad , i ) )
153  {
154  ls_bad.push_back ( i );
155  continue;
156  }
157  else
158  if ( !check_isgood ( ls_dx_bad , i ) && !check_isgood ( ls_dxsc_bad , i ) )
159  {
160  ls_bad.push_back ( i );
161  continue;
162  }
163  else
164  if ( !check_isgood ( ls_dy_bad , i ) && !check_isgood ( ls_dysc_bad , i ) )
165  {
166  ls_bad.push_back ( i );
167  continue;
168  }
169  else
170  if ( !check_isgood ( ls_dz_bad , i ) && !check_isgood ( ls_dzsc_bad , i ) )
171  {
172  ls_bad.push_back ( i );
173  continue;
174  }
175  else
176  if ( !check_isgood ( ls_errdx_bad , i ) && !check_isgood ( ls_errdxsc_bad , i ) )
177  {
178  ls_bad.push_back ( i );
179  continue;
180  }
181  else
182  if ( !check_isgood ( ls_errdy_bad , i ) && !check_isgood ( ls_errdysc_bad , i ) )
183  {
184  ls_bad.push_back ( i );
185  continue;
186  }
187  else
188  if ( !check_isgood ( ls_errdz_bad , i ) && !check_isgood ( ls_errdzsc_bad , i ) )
189  {
190  ls_bad.push_back ( i );
191  continue;
192  }
193 
194  //check also that LS is not missing!!!
195  ls_good.push_back( i );
196  }
197 
198  ofstream outfile;
199  string namefile = "Certification_BS_run_" + runnum_str( filename ) + ".txt";
200  outfile.open(namefile.c_str());
201  outfile << "Lumibased BeamSpot Calibration Certification for run " << runnum_str( filename ) << ":" << endl << endl;
202 
203  char line[2000];
204  sprintf( line, " GOOD Lumisections (values within limits): %s" , ListOut( ls_good ).c_str() );
205  outfile << line << endl;
206 
207  if ( ls_bad.size() > 0 )
208  {
209  sprintf( line, " BAD Lumisections (values outside limits): %s" , ListOut( ls_bad ).c_str() );
210  outfile << line << endl;
211 
212  sprintf( line, " --- histogram name --- --- bad lumisection list(*) ---" );
213  outfile << line << endl;
214  sprintf( line, " hxLumibased PrimaryVertex-DataBase (mean): %s" , ListOut( ls_x_bad ).c_str() );
215  if ( ls_x_bad.size() > 0 ) outfile << line << endl;
216  sprintf( line, " hyLumibased PrimaryVertex-DataBase (mean): %s" , ListOut( ls_y_bad ).c_str() );
217  if ( ls_y_bad.size() > 0 ) outfile << line << endl;
218  sprintf( line, " hzLumibased PrimaryVertex-DataBase (mean): %s" , ListOut( ls_z_bad ).c_str() );
219  if ( ls_z_bad.size() > 0 ) outfile << line << endl;
220 
221  sprintf( line, " hsigmaXLumibased PrimaryVertex-DataBase fit (mean): %s" , ListOut( ls_dx_bad ).c_str() );
222  if ( ls_dx_bad.size() > 0 ) outfile << line << endl;
223  sprintf( line, " hsigmaYLumibased PrimaryVertex-DataBase fit (mean): %s" , ListOut( ls_dy_bad ).c_str() );
224  if ( ls_dy_bad.size() > 0 ) outfile << line << endl;
225  sprintf( line, " hsigmaZLumibased PrimaryVertex-DataBase fit (mean): %s" , ListOut( ls_dz_bad ).c_str() );
226  if ( ls_dz_bad.size() > 0 ) outfile << line << endl;
227 
228  sprintf( line, " hsigmaXLumibased PrimaryVertex-DataBase fit (error): %s" , ListOut( ls_errdx_bad ).c_str() );
229  if ( ls_errdx_bad.size() > 0 ) outfile << line << endl;
230  sprintf( line, " hsigmaYLumibased PrimaryVertex-DataBase fit (error): %s" , ListOut( ls_errdy_bad ).c_str() );
231  if ( ls_errdy_bad.size() > 0 ) outfile << line << endl;
232  sprintf( line, " hsigmaZLumibased PrimaryVertex-DataBase fit (error): %s" , ListOut( ls_errdz_bad ).c_str() );
233  if ( ls_errdz_bad.size() > 0 ) outfile << line << endl;
234 
235  sprintf( line, " (*) also bad in the corresponding 'Scalers-Database fit' histograms" );
236  outfile << line << endl;
237  }
238 
239  outfile.close();
240  std::cout << "Lumibased BeamSpot Calibration Certification summary saved in " << namefile << endl;
241 }
int i
Definition: DBlmapReader.cc:9
string runnum_str(string filename)
Definition: ls_cert.cc:493
void vector_AND(vector< int > &, vector< int >)
Definition: lsbs_cert.cc:412
list outfile
Definition: EdgesToViz.py:91
string ListOut(vector< int > &LSlist)
Definition: ls_cert.cc:521
int numlumis
Definition: ls_cert.cc:26
int nlumis(string filename)
Definition: ls_cert.cc:433
tuple filename
Definition: lut2db_cfg.py:20
bool check_isgood(vector< int > &ls_badlist, int ls)
Definition: lsbs_cert.cc:278
tuple cout
Definition: gather_cfg.py:121
void check_offset(string filename, string iDir, string plot, float limit_min, float limit_max, vector< int > &badLS)
Definition: lsbs_cert.cc:243
void check_sigma(string filename, string iDir, string plot, float limit_err, vector< int > &badLS)
Definition: lsbs_cert.cc:261
int main ( int  argc,
char *  argv[] 
)

Definition at line 37 of file lsbs_cert.cc.

References gather_cfg::cout, lut2db_cfg::filename, and lsbs_cert().

37  {
38 
39  if(argc==2) {
40  char* filename = argv[1];
41 
42  std::cout << "ready to run lsbs filename " << filename << std::endl;
43 
44  lsbs_cert(filename);
45 
46  }
47  else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
48  return 0;
49 
50 }
void lsbs_cert(string filename)
Definition: lsbs_cert.cc:52
tuple argc
Definition: dir2webdir.py:41
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
int nlumis ( string  filename)
string runnum_str ( string  filename)
void vector_AND ( vector< int > &  bad_def,
vector< int >  bad_sc 
)

Definition at line 412 of file lsbs_cert.cc.

References i, j, and groupFilesInBlocks::temp.

Referenced by lsbs_cert().

413 {
414  vector <int> temp;
415 
416  int def_size = bad_def.size();
417  for ( int i = 0; i < def_size; i++ )
418  for ( unsigned int j = 0; j < bad_sc.size(); j++ )
419  if ( bad_def[ i ] == bad_sc[ j ] )
420  {
421  temp.push_back( bad_def[ i ] );
422  break;
423  }
424 
425  bad_def = temp;
426 }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9

Variable Documentation

bool debug = false

Definition at line 26 of file lsbs_cert.cc.

int numlumis = -1

Definition at line 27 of file lsbs_cert.cc.