2 #include <TDirectory.h>
12 #include <TPaveStats.h>
34 char* cpixel = argv[1];
38 float threshold_pixel = 0;
39 sscanf(cpixel,
"%f", &threshold_pixel);
41 sscanf(cthr,
"%f", &threshold);
43 std::cout <<
"ready to run ls_cert: pixel thr " << threshold_pixel <<
" threshold " << threshold <<
" filename "
44 << filename << std::endl;
46 ls_cert(threshold_pixel, threshold, filename);
49 std::cout <<
"Too few arguments: " << argc << std::endl;
60 vector<pair<
string, vector<float> > >&,
61 vector<pair<
string, vector<float> > >&,
62 vector<pair<
string, vector<float> > >&);
69 vector<pair<
string, vector<float> > >&,
70 vector<pair<
string, vector<float> > >&,
71 vector<pair<
string, vector<float> > >&);
77 vector<string> cert_strip;
78 vector<string> cert_track;
79 vector<string> cert_pixel;
82 vector<pair<string, vector<float> > > gLS_strip;
83 vector<pair<string, vector<float> > > gLS_track;
84 vector<pair<string, vector<float> > > gLS_pixel;
87 vector<pair<string, vector<float> > > bLS_strip;
88 vector<pair<string, vector<float> > > bLS_track;
89 vector<pair<string, vector<float> > > bLS_pixel;
92 vector<pair<string, vector<float> > > mLS_strip;
93 vector<pair<string, vector<float> > > mLS_track;
94 vector<pair<string, vector<float> > > mLS_pixel;
96 ls_cert_type(
"SiStrip", threshold, filename, cert_strip, gLS_strip, bLS_strip, mLS_strip);
97 ls_cert_type(
"Tracking", threshold, filename, cert_track, gLS_track, bLS_track, mLS_track);
98 ls_cert_type(
"Pixel", threshold_pixel, filename, cert_pixel, gLS_pixel, bLS_pixel, mLS_pixel);
101 string namefile =
"Certification_run_" +
runnum_str(filename) +
".txt";
102 outfile.open(namefile.c_str());
103 outfile <<
"Lumisection Certification (GOOD: >= " << threshold_pixel <<
" [Pixel]; >= " << threshold
104 <<
" [SiStrip,Tracking] "
105 <<
", otherwise BAD):" << endl
107 outfile <<
"GOOD Lumisections:" << endl;
109 for (
int ityp = 0; ityp < 4; ityp++) {
110 sprintf(line,
" Pixel %*sSummary: %s", 13, cert_pixel[ityp].c_str(), gLS_pixel[ityp].
first.c_str());
111 outfile << line << endl;
113 for (
int ityp = 0; ityp < 4; ityp++) {
114 sprintf(line,
" SiStrip %*sSummary: %s", 13, cert_strip[ityp].c_str(), gLS_strip[ityp].
first.c_str());
115 outfile << line << endl;
117 for (
int ityp = 0; ityp < 1; ityp++) {
118 sprintf(line,
" Tracking %*sSummary: %s", 13, cert_track[ityp].c_str(), gLS_track[ityp].
first.c_str());
119 outfile << line << endl;
122 outfile <<
"\nBAD Lumisections:" << endl;
123 for (
int ityp = 0; ityp < 4; ityp++) {
124 sprintf(line,
" Pixel %*sSummary: %s", 13, cert_pixel[ityp].c_str(), bLS_pixel[ityp].
first.c_str());
125 outfile << line << endl;
127 for (
int ityp = 0; ityp < 4; ityp++) {
128 sprintf(line,
" SiStrip %*sSummary: %s", 13, cert_strip[ityp].c_str(), bLS_strip[ityp].
first.c_str());
129 outfile << line << endl;
131 for (
int ityp = 0; ityp < 1; ityp++) {
132 sprintf(line,
" Tracking %*sSummary: %s", 13, cert_track[ityp].c_str(), bLS_track[ityp].
first.c_str());
133 outfile << line << endl;
136 outfile <<
"\nMISSING Lumisections:" << endl;
137 for (
int ityp = 0; ityp < 4; ityp++) {
138 sprintf(line,
" Pixel %*sSummary: %s", 13, cert_pixel[ityp].c_str(), mLS_pixel[ityp].
first.c_str());
139 outfile << line << endl;
141 for (
int ityp = 0; ityp < 4; ityp++) {
142 sprintf(line,
" SiStrip %*sSummary: %s", 13, cert_strip[ityp].c_str(), mLS_strip[ityp].
first.c_str());
143 outfile << line << endl;
145 for (
int ityp = 0; ityp < 1; ityp++) {
146 sprintf(line,
" Tracking %*sSummary: %s", 13, cert_track[ityp].c_str(), mLS_track[ityp].
first.c_str());
147 outfile << line << endl;
151 std::cout <<
"Lumisection Certification summary saved in " << namefile << std::endl;
153 cert_plot(threshold_pixel, threshold, filename, cert_strip, cert_track, cert_pixel, gLS_strip, gLS_track, gLS_pixel);
159 vector<string>& cert,
160 vector<pair<
string, vector<float> > >& gLS,
161 vector<pair<
string, vector<float> > >& bLS,
162 vector<pair<
string, vector<float> > >& mLS) {
169 std::cout << filename.c_str() << std::endl;
174 TFile*
file = TFile::Open(filename.c_str());
175 if (!file->IsOpen()) {
176 std::cerr <<
"Failed to open " << filename << std::endl;
180 string dir =
"DQMData/Run " + run +
"/" + iDir;
181 topDir =
dynamic_cast<TDirectory*
>(file->Get(dir.c_str()));
184 std::cout << topDir->GetTitle() << std::endl;
189 TIter
next(topDir->GetListOfKeys());
191 while ((key = dynamic_cast<TKey*>(
next()))) {
192 string clName(key->GetClassName());
193 if (clName ==
"TDirectoryFile") {
194 TDirectory* curr_dir =
dynamic_cast<TDirectory*
>(key->ReadObj());
195 string name = curr_dir->GetName();
196 if (name ==
"Run summary")
198 name = name.substr(name.find(
'-') + 1);
199 float temp1 = atof(name.c_str());
203 sort(ls.begin(), ls.end());
204 int vecsize = ls.size();
209 Float_t* lsd =
new Float_t[vecsize];
211 Float_t**
v =
new Float_t*[4];
212 for (
int k = 0;
k < 4;
k++) {
213 v[
k] =
new Float_t[vecsize];
217 string certflag[4] = {
"DAQSummary",
"DCSSummary",
"reportSummary",
"CertificationSummary"};
218 string certflagPrint[4] = {
"DAQ",
"DCS",
"DQM",
"Certification"};
221 if (iDir ==
"SiStrip" || iDir ==
"Pixel")
224 if (iDir ==
"Tracking") {
225 certflag[0] =
"CertificationSummary";
226 certflagPrint[0] =
"Certification";
227 certflag[1] =
"reportSummary";
228 certflagPrint[1] =
"DQM";
231 for (
int icert_type = 0; icert_type < smax; icert_type++) {
232 cert.push_back(certflagPrint[icert_type]);
236 std::cout << gDirectory->GetName() << std::endl;
238 for (
int i = 0;
i < vecsize;
i++) {
240 lsdir << dir <<
"/By Lumi Section " << ls[
i] <<
"-" << ls[
i] <<
"/EventInfo";
242 std::cout << lsdir.str().c_str() << std::endl;
243 float templs = ls[
i];
245 TDirectory* tempDir =
dynamic_cast<TDirectory*
>(file->Get(lsdir.str().c_str()));
247 TIter nextTemp(tempDir->GetListOfKeys());
249 while ((keyTemp = dynamic_cast<TKey*>(nextTemp()))) {
250 float tempvalue = -1.;
251 string classname(keyTemp->GetClassName());
253 string sflag = keyTemp->GetName();
254 string tempname = sflag.substr(sflag.find(
"f=") + 2);
255 size_t pos1 = tempname.find(
'<');
256 size_t pos2 = sflag.find_first_of(
'>');
257 string detvalue = tempname.substr(0, pos1);
258 string typecert = sflag.substr(1, pos2 - 1);
260 std::cout << typecert.c_str() << std::endl;
261 tempvalue = atof(detvalue.c_str());
263 for (
int j = 0;
j < smax;
j++) {
264 if (strstr(typecert.c_str(), certflag[
j].c_str()) !=
nullptr)
267 std::cout <<
"Entering value " << tempvalue <<
" " << v[
j][
i] <<
" for " << certflag[
j].c_str()
274 int nLS_run =
nlumis(filename);
276 for (
int iS = 0; iS < smax; iS++) {
279 vector<int> missingLS;
280 vector<float> allLSthr;
283 for (
int iLS = 0; iLS < vecsize; iLS++) {
284 if (v[iS][iLS] >= threshold)
285 goodLS.push_back(lsd[iLS]);
286 else if (v[iS][iLS] > -1)
287 badLS.push_back(lsd[iLS]);
291 for (
int i_ls = 1; i_ls <= nLS_run; i_ls++) {
292 for (
int j = last_idx;
j < vecsize;
j++) {
293 if (lsd[
j] == i_ls) {
296 allLSthr.push_back(0.00001);
298 allLSthr.push_back(v[iS][
j]);
303 missingLS.push_back(i_ls);
304 allLSthr.push_back(-1);
314 string goodList =
ListOut(goodLS);
315 string badList =
ListOut(badLS);
316 string missingList =
ListOut(missingLS);
319 gLS.push_back(make_pair(goodList, allLSthr));
320 bLS.push_back(make_pair(badList, allLSthr));
321 mLS.push_back(make_pair(missingList, allLSthr));
328 vector<string>& cert_strip,
329 vector<string>& cert_track,
330 vector<string>& cert_pixel,
331 vector<pair<
string, vector<float> > >& LS_strip,
332 vector<pair<
string, vector<float> > >& LS_track,
333 vector<pair<
string, vector<float> > >& LS_pixel) {
334 int nLumiSections =
nlumis(filename);
336 char plottitles[200];
337 sprintf(plottitles,
"Lumisection Certification: Run %s;Luminosity Section;",
runnum_str(filename).c_str());
338 TH2D*
cert_plot =
new TH2D(
"cert_plot", plottitles, nLumiSections, 1, nLumiSections + 1, 5, 1, 6);
339 cert_plot->SetStats(
false);
341 for (
int ityp = 0; ityp < 4; ityp++) {
342 sprintf(label,
"SiStrip %s", cert_strip[ityp].c_str());
343 cert_plot->GetYaxis()->SetBinLabel(5 - ityp, label);
345 for (
unsigned int idx = 0; idx < LS_strip[ityp].second.size(); idx++)
346 if (LS_strip[ityp].
second[idx] > -1)
347 cert_plot->SetBinContent(idx + 1, 5 - ityp, LS_strip[ityp].
second[idx]);
349 for (
int ityp = 0; ityp < 1; ityp++) {
350 sprintf(label,
"Tracking %s", cert_track[ityp].c_str());
351 cert_plot->GetYaxis()->SetBinLabel(1 - ityp, label);
352 for (
unsigned int idx = 0; idx < LS_track[ityp].second.size(); idx++)
353 if (LS_track[ityp].
second[idx] > -1)
354 cert_plot->SetBinContent(idx + 1, 1 - ityp, LS_track[ityp].
second[idx]);
357 const Int_t colNum = 20;
359 float rgb[colNum][3];
361 for (Int_t
i = 0;
i < colNum;
i++) {
369 rgb[
i][0] = 0.80 + (0.98 - 0.80) / (col_thr - 1) *
i;
370 rgb[
i][1] = 0.00 + (0.79 - 0.00) / (col_thr - 1) *
i;
374 palette[
i] = 9001 +
i;
376 TColor* color = gROOT->GetColor(9001 +
i);
378 color =
new TColor(9001 +
i, 0, 0, 0,
"");
379 color->SetRGB(rgb[
i][0], rgb[i][1], rgb[i][2]);
381 gStyle->SetPalette(colNum, palette);
382 gROOT->SetStyle(
"Plain");
384 TCanvas* cc =
new TCanvas(
"name",
"title", 1000, 600);
385 cert_plot->Draw(
"colz");
386 gPad->SetLeftMargin(0.17);
387 string plotfilename =
"Certification_run_" +
runnum_str(filename) +
".png";
388 cc->Print(plotfilename.c_str());
392 TH2D* cert_plot_pixel =
new TH2D(
"cert_plot_pixel", plottitles, nLumiSections, 1, nLumiSections + 1, 4, 1, 5);
393 cert_plot_pixel->SetStats(
false);
395 for (
int ityp = 0; ityp < 4; ityp++) {
396 sprintf(label,
"Pixel %s", cert_pixel[ityp].c_str());
397 cert_plot_pixel->GetYaxis()->SetBinLabel(4 - ityp, label);
399 for (
unsigned int idx = 0; idx < LS_pixel[ityp].second.size(); idx++)
400 if (LS_pixel[ityp].
second[idx] > -1)
401 cert_plot_pixel->SetBinContent(idx + 1, 4 - ityp, LS_pixel[ityp].
second[idx]);
404 int col_thr_pixel = colNum * threshold_pixel;
406 for (Int_t
i = 0;
i < colNum;
i++) {
407 if (
i >= col_thr_pixel) {
414 rgb[
i][0] = 0.80 + (0.98 - 0.80) / (col_thr - 1) *
i;
415 rgb[
i][1] = 0.00 + (0.79 - 0.00) / (col_thr - 1) *
i;
419 palette[
i] = 10001 +
i;
421 TColor* color = gROOT->GetColor(10001 +
i);
423 color =
new TColor(10001 +
i, 0, 0, 0,
"");
424 color->SetRGB(rgb[
i][0], rgb[i][1], rgb[i][2]);
426 gStyle->SetPalette(colNum, palette);
427 gROOT->SetStyle(
"Plain");
429 cert_plot_pixel->Draw(
"colz");
431 string plotfilename_pixel =
"Certification_run_" +
runnum_str(filename) +
"_pixel.png";
432 cc->Print(plotfilename_pixel.c_str());
444 TFile*
file = TFile::Open(filename.c_str());
445 if (!file->IsOpen()) {
446 std::cerr <<
"Failed to open " << filename << std::endl;
453 bool isHIRun =
false;
454 if (filename.find(
"HIRun") != string::npos)
459 string EventInfoDir =
"DQMData/Run " + run +
"/SiStrip/Run summary/EventInfo";
460 TDirectory* rsEventInfoDir =
dynamic_cast<TDirectory*
>(file->Get(EventInfoDir.c_str()));
461 rsEventInfoDir->cd();
462 TIter eiKeys(rsEventInfoDir->GetListOfKeys());
464 while ((eiKey = dynamic_cast<TKey*>(eiKeys()))) {
467 string sflag = eiKey->GetName();
468 string tempname = sflag.substr(sflag.find(
"i=") + 2);
469 size_t pos1 = tempname.find(
'<');
470 size_t pos2 = sflag.find_first_of(
'>');
471 string detvalue = tempname.substr(0, pos1);
472 string numlumisec = sflag.substr(1, pos2 - 1);
473 if (numlumisec == (
string)
"iLumiSection") {
481 string EventInfoDirHist =
"DQMData/Run " + run +
"/Info/Run summary/EventInfo/ProcessedLS";
482 TH1F* allLS = (TH1F*)file->Get(EventInfoDirHist.c_str());
497 int refLS = LSlist[0];
498 for (
unsigned int at = 1; at < LSlist.size() - 1; at++) {
500 if (refLS + 1 == LSlist[at] && LSlist[at] + 1 == LSlist[at + 1]) {
511 bool rangeset =
false;
513 for (
unsigned int at = 0; at < LSlist.size(); at++) {
514 if (LSlist[at] != -1) {
515 if (at > 0 && LSlist[at - 1] != -1)
519 strout += lsnum.str();
522 if (LSlist[at] == -1 && !rangeset) {
void Cleaning(vector< int > &LSlist)
string runnum_str(string filename)
void cert_plot(float threshold_pixel, float threshold, string filename, vector< string > &cert_strip, vector< string > &cert_track, vector< string > &cert_pixel, vector< pair< string, vector< float > > > &LS_strip, vector< pair< string, vector< float > > > &LS_track, vector< pair< string, vector< float > > > &LS_pixel)
U second(std::pair< T, U > const &p)
void ls_cert(float threshold_pixel, float threshold, string filename)
tuple key
prepare the HTCondor submission files and eventually submit them
string ListOut(vector< int > &LSlist)
int nlumis(string filename)
void ls_cert_type(string iDir, float threshold, string filename, vector< string > &cert, vector< pair< string, vector< float > > > &gLS, vector< pair< string, vector< float > > > &bLS, vector< pair< string, vector< float > > > &mLS)