CMS 3D CMS Logo

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 <cstring>
#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

◆ check_isgood()

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

Definition at line 251 of file lsbs_cert.cc.

References mps_fire::i, and relval_nano::ls.

Referenced by lsbs_cert().

251  {
252  //check if this LS is found in the BAD list
253  for (unsigned int i = 0; i < ls_badlist.size(); i++) {
254  if (ls == ls_badlist[i])
255  return false;
256  }
257  return true;
258 }

◆ check_offset()

void check_offset ( string  filename,
string  iDir,
string  plot,
float  limit_min,
float  limit_max,
vector< int > &  badLS 
)

Definition at line 223 of file lsbs_cert.cc.

References corrVsCorr::filename, getplot(), mps_fire::i, and plotFactory::plot.

Referenced by lsbs_cert().

223  {
224  TH1F checkPlot;
225  if (getplot(filename, iDir, plot, checkPlot) < 0)
226  return;
227 
228  //look at each LS, save the bad one
229  for (int i = 1; i <= checkPlot.GetNbinsX(); i++) {
230  float value = checkPlot.GetBinContent(i);
231  if (value < limit_min || value > limit_max) {
232  badLS.push_back((int)checkPlot.GetBinCenter(i));
233  }
234  }
235 }
Definition: value.py:1
int getplot(string filename, string iDir, string strplot, TH1F &plot)
Definition: lsbs_cert.cc:297

◆ check_sigma()

void check_sigma ( string  filename,
string  iDir,
string  plot,
float  limit_err,
vector< int > &  badLS 
)

Definition at line 237 of file lsbs_cert.cc.

References corrVsCorr::filename, getplot(), mps_fire::i, and plotFactory::plot.

Referenced by lsbs_cert().

237  {
238  TH1F checkPlot;
239  if (getplot(filename, iDir, plot, checkPlot) < 0)
240  return;
241 
242  //look at each LS
243  for (int i = 1; i <= checkPlot.GetNbinsX(); i++) {
244  float value = checkPlot.GetBinError(i);
245  if (value > limit_err) {
246  badLS.push_back((int)checkPlot.GetBinCenter(i));
247  }
248  }
249 }
Definition: value.py:1
int getplot(string filename, string iDir, string strplot, TH1F &plot)
Definition: lsbs_cert.cc:297

◆ Cleaning()

void Cleaning ( vector< int > &  LSlist)

Definition at line 328 of file lsbs_cert.cc.

Referenced by ListOut().

328  {
329  if (LSlist.empty())
330  return;
331 
332  //cleaning: keep only 1st and last lumisection in the range
333  int refLS = LSlist[0];
334  for (unsigned int at = 1; at < LSlist.size() - 1; at++) {
335  //delete LSnums in between a single continuous range
336  if (refLS + 1 == LSlist[at] && LSlist[at] + 1 == LSlist[at + 1]) {
337  refLS = LSlist[at];
338  LSlist[at] = -1;
339  } else {
340  refLS = LSlist[at];
341  }
342  }
343 }

◆ getplot()

int getplot ( string  filename,
string  iDir,
string  strplot,
TH1F &  plot 
)

Definition at line 297 of file lsbs_cert.cc.

References DMR_cfg::cerr, gather_cfg::cout, debug, DeadROC_duringRun::dir, geometryDiff::file, corrVsCorr::filename, plotFactory::plot, writedatasetfile::run, and runnum_str().

Referenced by check_offset(), and check_sigma().

297  {
298  string run = runnum_str(filename);
299  if (debug)
300  std::cout << filename.c_str() << endl;
301 
302  TFile* file = TFile::Open(filename.c_str());
303  if (!file->IsOpen()) {
304  cerr << "Failed to open " << filename << endl;
305  return -1;
306  }
307 
308  string dir = "DQMData/Run " + run + "/AlcaBeamMonitor/Run summary/" + iDir;
309 
310  file->cd(dir.c_str());
311 
312  string theplot = strplot + ";1";
313  TH1F* thisplot;
314  gDirectory->GetObject(theplot.c_str(), thisplot);
315 
316  if (!thisplot) {
317  std::cout << "Error: plot " << dir << "/" << theplot.c_str() << " not found!" << endl;
318  return -2;
319  }
320 
321  plot = *thisplot;
322  thisplot = nullptr;
323  delete thisplot;
324 
325  return 0;
326 }
string runnum_str(string filename)
Definition: lsbs_cert.cc:295
bool debug
Definition: lsbs_cert.cc:26

◆ ListOut()

string ListOut ( vector< int > &  LSlist)

Definition at line 345 of file lsbs_cert.cc.

References Cleaning().

Referenced by lsbs_cert().

345  {
346  Cleaning(LSlist);
347 
348  string strout = "";
349  bool rangeset = false;
350  for (unsigned int at = 0; at < LSlist.size(); at++) {
351  if (LSlist[at] != -1) {
352  if (at > 0 && LSlist[at - 1] != -1)
353  strout += ",";
354  stringstream lsnum;
355  lsnum << LSlist[at];
356  strout += lsnum.str();
357  rangeset = false;
358  }
359  if (LSlist[at] == -1 && !rangeset) {
360  strout += "-";
361  rangeset = true;
362  }
363  }
364 
365  return strout;
366 }
void Cleaning(vector< int > &)
Definition: lsbs_cert.cc:328

◆ lsbs_cert()

void lsbs_cert ( string  filename)

Definition at line 52 of file lsbs_cert.cc.

References check_isgood(), check_offset(), check_sigma(), gather_cfg::cout, corrVsCorr::filename, mps_fire::i, mps_splice::line, ListOut(), relval_nano::ls, nlumis(), numlumis, PixelBaryCentreAnalyzer_cfg::outfile, plotFactory::plot, runnum_str(), and vector_AND().

Referenced by main().

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

◆ main()

int main ( int  argc,
char *  argv[] 
)

===============================================================================================================================================================================================


variant2: for each run define phi-averaged A for normalization channel (Dref,16) and then, divide Rijk on it, i.e. get RRijk




















































































eta=27

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=19

eta=17

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=20

eta=19

eta=18

eta=27 L1=1

eta=25 L1=1

eta=23 L1=1

eta=22 L1=1

eta=21 L1=1

eta=29 L1=1

eta=26 L1=1

eta=24 L1=1

eta=20 L1=1

eta=19 L1=1

eta=18 L1=1

eta=17 L1=1

eta=28 L7=1

eta=27 L7=1

eta=25 L7=1

eta=23 L7=1

eta=22 L7=1

eta=21 L7=1

eta=26 L7=1

eta=24 L7=1

eta=20 L7=1

eta=19 L7=1

eta=18 L7=1

eta=17 L7=1

eta=27

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=19

eta=17

eta=25

eta=23

eta=22

eta=21

eta=26

eta=24

eta=20

eta=19

eta=18

eta=27 L1=1

eta=25 L1=1

eta=23 L1=1

eta=22 L1=1

eta=21 L1=1

eta=26 L1=1

eta=24 L1=1

eta=20 L1=1

eta=19 L1=1

eta=18 L1=1

eta=17 L1=1

eta=28 L7=1

eta=27 L7=1

eta=25 L7=1

eta=23 L7=1

eta=22 L7=1

eta=21 L7=1

eta=26 L7=1

eta=24 L7=1

eta=20 L7=1

eta=19 L7=1

eta=18 L7=1

eta=17 L7=1

eta=27

eta=28

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:







Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Sticking ADC counts in neughbouring TS for HB:

Sticking ADC counts in neughbouring TS for HE:

RBX:

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:





Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

errA with average Amplitudes

Summed Amplitude Plots:





Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

Summed Amplitude Plots:

RBX:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Prepare maps of good/bad channels:

Definition at line 37 of file lsbs_cert.cc.

References dir2webdir::argc, GCPpyPlots::argv, gather_cfg::cout, corrVsCorr::filename, and lsbs_cert().

37  {
38  if (argc == 2) {
39  char* filename = argv[1];
40 
41  std::cout << "ready to run lsbs filename " << filename << std::endl;
42 
44 
45  } else {
46  std::cout << "Too few arguments: " << argc << std::endl;
47  return -1;
48  }
49  return 0;
50 }
void lsbs_cert(string filename)
Definition: lsbs_cert.cc:52

◆ nlumis()

int nlumis ( string  filename)

Definition at line 260 of file lsbs_cert.cc.

References DMR_cfg::cerr, make_classfiles::classname, geometryDiff::file, corrVsCorr::filename, numlumis, writedatasetfile::run, and runnum_str().

Referenced by lsbs_cert().

260  {
261  if (numlumis > -1)
262  return numlumis;
263 
264  TFile* file = TFile::Open(filename.c_str());
265  if (!file->IsOpen()) {
266  cerr << "Failed to open " << filename << endl;
267  return -1;
268  }
269 
270  string run = runnum_str(filename);
271  string EventInfoDir = "DQMData/Run " + run + "/SiStrip/Run summary/EventInfo";
272  TDirectory* rsEventInfoDir = dynamic_cast<TDirectory*>(file->Get(EventInfoDir.c_str()));
273  rsEventInfoDir->cd();
274  TIter eiKeys(rsEventInfoDir->GetListOfKeys());
275  TKey* eiKey;
276  while ((eiKey = dynamic_cast<TKey*>(eiKeys()))) {
277  string classname(eiKey->GetClassName());
278  if (classname == "TObjString") {
279  string sflag = eiKey->GetName();
280  string tempname = sflag.substr(sflag.find("i=") + 2);
281  size_t pos1 = tempname.find('<');
282  size_t pos2 = sflag.find_first_of('>');
283  string detvalue = tempname.substr(0, pos1);
284  string numlumisec = sflag.substr(1, pos2 - 1);
285  if (numlumisec == (string) "iLumiSection") {
286  numlumis = atoi(detvalue.c_str());
287  break;
288  }
289  }
290  }
291 
292  return numlumis;
293 }
int numlumis
Definition: lsbs_cert.cc:27
string runnum_str(string filename)
Definition: lsbs_cert.cc:295

◆ runnum_str()

string runnum_str ( string  filename)

Definition at line 295 of file lsbs_cert.cc.

References corrVsCorr::filename.

Referenced by getplot(), lsbs_cert(), and nlumis().

295 { return filename.substr(filename.find("_R000") + 5, 6); }

◆ vector_AND()

void vector_AND ( vector< int > &  bad_def,
vector< int >  bad_sc 
)

Definition at line 368 of file lsbs_cert.cc.

References mps_fire::i, dqmiolumiharvest::j, and groupFilesInBlocks::temp.

Referenced by lsbs_cert().

368  {
369  vector<int> temp;
370 
371  int def_size = bad_def.size();
372  for (int i = 0; i < def_size; i++)
373  for (unsigned int j = 0; j < bad_sc.size(); j++)
374  if (bad_def[i] == bad_sc[j]) {
375  temp.push_back(bad_def[i]);
376  break;
377  }
378 
379  bad_def = temp;
380 }

Variable Documentation

◆ debug

bool debug = false

Definition at line 26 of file lsbs_cert.cc.

Referenced by getplot().

◆ numlumis

int numlumis = -1

Definition at line 27 of file lsbs_cert.cc.

Referenced by lsbs_cert(), and nlumis().