2 #include <TDirectory.h> 12 #include <TPaveStats.h> 35 char* cpixel = argv[1];
39 float threshold_pixel = 0;
40 sscanf(cpixel,
"%f",&threshold_pixel);
42 sscanf(cthr,
"%f",&threshold);
44 std::cout <<
"ready to run ls_cert: pixel thr " << threshold_pixel
45 <<
" threshold " << threshold
46 <<
" filename " << filename << std::endl;
48 ls_cert(threshold_pixel,threshold,filename);
51 else {
std::cout <<
"Too few arguments: " << argc << std::endl;
return -1; }
58 void ls_cert_type (
string iDir ,
float threshold ,
string filename , vector <string>& , vector<pair<
string,vector<float> > >& , vector<pair<
string,vector<float> > >& , vector<pair<
string,vector<float> > >& );
59 void cert_plot (
float threshold_pixel ,
float threshold ,
string filename ,
60 vector <string>& , vector <string>& , vector <string>& , vector<pair<
string,vector<float> > >& , vector<pair<
string,vector<float> > >& , vector<pair<
string,vector<float> > >& );
66 vector <string> cert_strip;
67 vector <string> cert_track;
68 vector <string> cert_pixel;
71 vector < pair < string,vector <float> > > gLS_strip;
72 vector < pair < string,vector <float> > > gLS_track;
73 vector < pair < string,vector <float> > > gLS_pixel;
76 vector < pair < string,vector <float> > > bLS_strip;
77 vector < pair < string,vector <float> > > bLS_track;
78 vector < pair < string,vector <float> > > bLS_pixel;
81 vector < pair < string,vector <float> > > mLS_strip;
82 vector < pair < string,vector <float> > > mLS_track;
83 vector < pair < string,vector <float> > > mLS_pixel;
85 ls_cert_type(
"SiStrip" , threshold , filename , cert_strip , gLS_strip , bLS_strip , mLS_strip );
86 ls_cert_type(
"Tracking" , threshold , filename , cert_track , gLS_track , bLS_track , mLS_track );
87 ls_cert_type(
"Pixel" , threshold_pixel , filename , cert_pixel , gLS_pixel , bLS_pixel , mLS_pixel );
90 string namefile =
"Certification_run_" +
runnum_str( filename ) +
".txt";
91 outfile.open(namefile.c_str());
92 outfile <<
"Lumisection Certification (GOOD: >= " << threshold_pixel <<
" [Pixel]; >= " << threshold <<
" [SiStrip,Tracking] " 93 <<
", otherwise BAD):" << endl << endl;
94 outfile <<
"GOOD Lumisections:" << endl;
96 for (
int ityp = 0; ityp < 4; ityp++)
98 sprintf( line,
" Pixel %*sSummary: %s" , 13 , cert_pixel[ityp].c_str() , gLS_pixel[ityp].
first.c_str() );
99 outfile << line << endl;
101 for (
int ityp = 0; ityp < 4; ityp++)
103 sprintf( line,
" SiStrip %*sSummary: %s" , 13 , cert_strip[ityp].c_str() , gLS_strip[ityp].
first.c_str() );
104 outfile << line << endl;
106 for (
int ityp = 0; ityp < 1; ityp++)
108 sprintf( line,
" Tracking %*sSummary: %s" , 13 , cert_track[ityp].c_str() , gLS_track[ityp].
first.c_str() );
109 outfile << line << endl;
112 outfile <<
"\nBAD Lumisections:" << endl;
113 for (
int ityp = 0; ityp < 4; ityp++)
115 sprintf( line,
" Pixel %*sSummary: %s" , 13 , cert_pixel[ityp].c_str() , bLS_pixel[ityp].
first.c_str() );
116 outfile << line << endl;
118 for (
int ityp = 0; ityp < 4; ityp++)
120 sprintf( line,
" SiStrip %*sSummary: %s" , 13 , cert_strip[ityp].c_str() , bLS_strip[ityp].
first.c_str() );
121 outfile << line << endl;
123 for (
int ityp = 0; ityp < 1; ityp++)
125 sprintf( line,
" Tracking %*sSummary: %s" , 13 , cert_track[ityp].c_str() , bLS_track[ityp].
first.c_str() );
126 outfile << line << endl;
129 outfile <<
"\nMISSING Lumisections:" << endl;
130 for (
int ityp = 0; ityp < 4; ityp++)
132 sprintf( line,
" Pixel %*sSummary: %s" , 13 , cert_pixel[ityp].c_str() , mLS_pixel[ityp].
first.c_str() );
133 outfile << line << endl;
135 for (
int ityp = 0; ityp < 4; ityp++)
137 sprintf( line,
" SiStrip %*sSummary: %s" , 13 , cert_strip[ityp].c_str() , mLS_strip[ityp].
first.c_str() );
138 outfile << line << endl;
140 for (
int ityp = 0; ityp < 1; ityp++)
142 sprintf( line,
" Tracking %*sSummary: %s" , 13 , cert_track[ityp].c_str() , mLS_track[ityp].
first.c_str() );
143 outfile << line << endl;
147 std::cout <<
"Lumisection Certification summary saved in " << namefile << std::endl;
149 cert_plot ( threshold_pixel , threshold , filename , cert_strip , cert_track , cert_pixel , gLS_strip , gLS_track , gLS_pixel );
152 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 )
159 if (debug)
std::cout << filename.c_str() << std::endl;
164 TFile*
file = TFile::Open(filename.c_str());
165 if (!file->IsOpen()) {
166 std::cerr <<
"Failed to open " << filename << std::endl;
170 string dir =
"DQMData/Run " + run +
"/" + iDir;
171 topDir =
dynamic_cast<TDirectory*
>( file->Get(dir.c_str()));
173 if (debug)
std::cout << topDir->GetTitle() << std::endl;
178 TIter
next(topDir->GetListOfKeys());
180 while ( (key = dynamic_cast<TKey*>(
next())) ) {
181 string clName(key->GetClassName());
182 if (clName ==
"TDirectoryFile") {
183 TDirectory *curr_dir =
dynamic_cast<TDirectory*
>(key->ReadObj());
184 string name = curr_dir->GetName();
185 if (name ==
"Run summary")
continue;
186 name = name.substr(name.find(
"-")+1);
187 float temp1 = atof(name.c_str());
191 sort(ls.begin(),ls.end());
192 int vecsize = ls.size();
197 Float_t * lsd =
new Float_t[vecsize];
199 Float_t **
v =
new Float_t*[4];
200 for(
int k=0;
k<4;
k++) {
201 v[
k] =
new Float_t[vecsize];
205 string certflag[4] = {
"DAQSummary",
"DCSSummary",
"reportSummary",
"CertificationSummary"};
206 string certflagPrint[4] = {
"DAQ",
"DCS",
"DQM",
"Certification"};
209 if ( iDir ==
"SiStrip" || iDir ==
"Pixel" ) smax = 4;
211 if ( iDir ==
"Tracking" )
213 certflag[0] =
"CertificationSummary";
214 certflagPrint[0] =
"Certification";
215 certflag[1] =
"reportSummary";
216 certflagPrint[1] =
"DQM";
219 for (
int icert_type = 0; icert_type < smax; icert_type++)
221 cert.push_back( certflagPrint[icert_type] );
224 if (debug)
std::cout << gDirectory->GetName() << std::endl;
226 for (
int i=0;
i < vecsize;
i++){
228 lsdir << dir <<
"/By Lumi Section " << ls[
i] <<
"-"<<ls[
i]<<
"/EventInfo";
229 if (debug)
std::cout << lsdir.str().c_str() << std::endl;
230 float templs = ls[
i];
232 TDirectory *tempDir =
dynamic_cast<TDirectory*
>( file->Get(lsdir.str().c_str()));
235 TIter nextTemp(tempDir->GetListOfKeys());
237 while ( (keyTemp = dynamic_cast<TKey*>(nextTemp())) ) {
238 float tempvalue = -1.;
239 string classname(keyTemp->GetClassName());
241 string sflag = keyTemp->GetName();
242 string tempname = sflag.substr(sflag.find(
"f=")+2);
243 size_t pos1 = tempname.find(
"<");
244 size_t pos2 = sflag.find_first_of(
">");
245 string detvalue = tempname.substr(0,pos1);
246 string typecert = sflag.substr(1,pos2-1);
247 if (debug)
std::cout << typecert.c_str() << std::endl;
248 tempvalue = atof(detvalue.c_str());
250 for (j=0; j<smax; j++){
251 if ( strstr(typecert.c_str(),certflag[j].c_str())!=
nullptr)
253 if (debug)
std::cout <<
"Entering value " << tempvalue <<
" " << v[j][
i] <<
" for " << certflag[j].c_str() << std::endl;
260 int nLS_run =
nlumis ( filename );
262 for (
int iS = 0; iS < smax; iS++)
267 vector<int> missingLS;
268 vector<float> allLSthr;
271 for (
int iLS = 0; iLS < vecsize; iLS++)
273 if ( v[iS][iLS] >= threshold )
274 goodLS.push_back(lsd[iLS]);
276 if ( v[iS][iLS] > -1 )
277 badLS.push_back(lsd[iLS]);
281 for (
int i_ls = 1; i_ls <= nLS_run; i_ls++)
283 for (
int j = last_idx; j < vecsize; j++)
285 if ( lsd[j] == i_ls )
288 if ( v[iS][j] == 0 ) allLSthr.push_back(0.00001);
290 allLSthr.push_back(v[iS][j]);
296 missingLS.push_back(i_ls);
297 allLSthr.push_back(-1);
307 string goodList =
ListOut( goodLS );
308 string badList =
ListOut( badLS );
309 string missingList =
ListOut( missingLS );
312 gLS.push_back ( make_pair ( goodList , allLSthr ) );
313 bLS.push_back ( make_pair ( badList , allLSthr ) );
314 mLS.push_back ( make_pair ( missingList , allLSthr ) );
319 vector <string>& cert_pixel , vector<pair<
string,vector<float> > >& LS_strip , vector<pair<
string,vector<float> > >& LS_track ,
320 vector<pair<
string,vector<float> > >& LS_pixel )
322 int nLumiSections =
nlumis( filename );
324 char plottitles[200];
325 sprintf( plottitles ,
"Lumisection Certification: Run %s;Luminosity Section;" ,
runnum_str( filename ).c_str() );
326 TH2D *
cert_plot =
new TH2D(
"cert_plot" , plottitles , nLumiSections , 1 , nLumiSections + 1 , 5 , 1 , 6 );
327 cert_plot->SetStats(
false);
329 for (
int ityp = 0; ityp < 4; ityp++)
331 sprintf( label ,
"SiStrip %s" , cert_strip[ityp].c_str() );
332 cert_plot->GetYaxis()->SetBinLabel( 5 - ityp , label );
334 for (
unsigned int idx = 0;
idx < LS_strip[ityp].second.size() ;
idx++)
335 if ( LS_strip[ityp].
second[
idx] > -1 ) cert_plot->SetBinContent(
idx+1, 5 - ityp, LS_strip[ityp].
second[
idx]);
337 for (
int ityp = 0; ityp < 1; ityp++)
339 sprintf( label ,
"Tracking %s" , cert_track[ityp].c_str() );
340 cert_plot->GetYaxis()->SetBinLabel( 1 - ityp , label );
341 for (
unsigned int idx = 0;
idx < LS_track[ityp].second.size() ;
idx++)
342 if ( LS_track[ityp].
second[
idx] > -1 ) cert_plot->SetBinContent(
idx+1, 1 - ityp, LS_track[ityp].
second[
idx]);
345 const Int_t colNum = 20;
346 Int_t palette[colNum];
347 float rgb[colNum][3];
349 for (Int_t
i=0;
i<colNum;
i++)
361 rgb[
i][0] = 0.80 + ( 0.98 - 0.80 ) / ( col_thr - 1 ) *
i ;
362 rgb[
i][1] = 0.00 + ( 0.79 - 0.00 ) / ( col_thr - 1 ) *
i ;
368 TColor *
color = gROOT->GetColor(9001+
i);
369 if (!color) color =
new TColor(9001 +
i, 0, 0, 0,
"");
370 color->SetRGB(rgb[
i][0], rgb[i][1], rgb[i][2]);
372 gStyle->SetPalette(colNum,palette);
373 gROOT->SetStyle(
"Plain");
375 TCanvas *cc =
new TCanvas(
"name" ,
"title" , 1000 , 600 );
376 cert_plot->Draw(
"colz");
377 gPad->SetLeftMargin(0.17);
378 string plotfilename =
"Certification_run_" +
runnum_str( filename ) +
".png";
379 cc->Print( plotfilename.c_str() );
384 TH2D *cert_plot_pixel =
new TH2D(
"cert_plot_pixel" , plottitles , nLumiSections , 1 , nLumiSections + 1 , 4 , 1 , 5 );
385 cert_plot_pixel->SetStats(
false);
387 for (
int ityp = 0; ityp < 4; ityp++)
389 sprintf( label ,
"Pixel %s" , cert_pixel[ityp].c_str() );
390 cert_plot_pixel->GetYaxis()->SetBinLabel( 4 - ityp , label );
392 for (
unsigned int idx = 0;
idx < LS_pixel[ityp].second.size() ;
idx++)
393 if ( LS_pixel[ityp].
second[
idx] > -1 ) cert_plot_pixel->SetBinContent(
idx+1, 4 - ityp, LS_pixel[ityp].
second[
idx]);
396 int col_thr_pixel = colNum * threshold_pixel;
398 for (Int_t
i=0;
i<colNum;
i++)
400 if (
i >= col_thr_pixel )
410 rgb[
i][0] = 0.80 + ( 0.98 - 0.80 ) / ( col_thr - 1 ) *
i ;
411 rgb[
i][1] = 0.00 + ( 0.79 - 0.00 ) / ( col_thr - 1 ) *
i ;
415 palette[
i] = 10001+
i;
417 TColor *
color = gROOT->GetColor(10001+
i);
418 if (!color) color =
new TColor(10001 +
i, 0, 0, 0,
"");
419 color->SetRGB(rgb[
i][0], rgb[i][1], rgb[i][2]);
421 gStyle->SetPalette(colNum,palette);
422 gROOT->SetStyle(
"Plain");
424 cert_plot_pixel->Draw(
"colz");
426 string plotfilename_pixel =
"Certification_run_" +
runnum_str( filename ) +
"_pixel.png";
427 cc->Print( plotfilename_pixel.c_str() );
441 TFile*
file = TFile::Open(filename.c_str());
442 if (!file->IsOpen()) {
443 std::cerr <<
"Failed to open " << filename << std::endl;
450 bool isHIRun =
false;
451 if ( filename.find (
"HIRun" ) != string::npos )
457 string EventInfoDir =
"DQMData/Run " + run +
"/SiStrip/Run summary/EventInfo";
458 TDirectory *rsEventInfoDir =
dynamic_cast<TDirectory*
>( file->Get(EventInfoDir.c_str()));
459 rsEventInfoDir->cd();
460 TIter eiKeys(rsEventInfoDir->GetListOfKeys());
462 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" )
475 numlumis = atoi( detvalue.c_str() );
484 string EventInfoDirHist =
"DQMData/Run " + run +
"/Info/Run summary/EventInfo/ProcessedLS";
485 TH1F* allLS = (TH1F*) file->Get( EventInfoDirHist.c_str() );
495 return filename.substr(filename.find(
"_R000")+5, 6);
500 if ( LSlist.empty() )
return;
503 int refLS = LSlist[0];
504 for (
unsigned int at = 1; at < LSlist.size() - 1; at++)
507 if ( refLS + 1 == LSlist[at] && LSlist[at] + 1 == LSlist[at+1] )
525 bool rangeset =
false;
527 for (
unsigned int at = 0; at < LSlist.size(); at++)
529 if ( LSlist[at] != -1 )
531 if ( at > 0 && LSlist[at-1] != -1 ) strout +=
",";
534 strout += lsnum.str();
537 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)
int main(int argc, char *argv[])
U second(std::pair< T, U > const &p)
void ls_cert(float threshold_pixel, float threshold, string filename)
string ListOut(vector< int > &LSlist)
int nlumis(string filename)
def rgb(r, g, b, maximum=1.)
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)