2 #include <TDirectory.h>
12 #include <TPaveStats.h>
33 string ListOut ( vector<int> & );
34 void vector_AND ( vector<int> & , vector<int> );
42 std::cout <<
"ready to run lsbs filename " << filename << std::endl;
47 else {
std::cout <<
"Too few arguments: " << argc << std::endl;
return -1; }
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>& );
61 float limit_x = 0.002;
62 float limit_y = 0.002;
64 float limit_dx = 0.002;
65 float limit_dy = 0.002;
67 float limit_errdx = 0.002;
68 float limit_errdy = 0.002;
69 float limit_errdz = 0.5;
73 vector <int> ls_x_bad;
74 vector <int> ls_y_bad;
75 vector <int> ls_z_bad;
77 vector <int> ls_xsc_bad;
78 vector <int> ls_ysc_bad;
79 vector <int> ls_zsc_bad;
81 vector <int> ls_dx_bad;
82 vector <int> ls_dy_bad;
83 vector <int> ls_dz_bad;
85 vector <int> ls_dxsc_bad;
86 vector <int> ls_dysc_bad;
87 vector <int> ls_dzsc_bad;
89 vector <int> ls_errdx_bad;
90 vector <int> ls_errdy_bad;
91 vector <int> ls_errdz_bad;
93 vector <int> ls_errdxsc_bad;
94 vector <int> ls_errdysc_bad;
95 vector <int> ls_errdzsc_bad;
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 );
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 );
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 );
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 );
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 );
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 );
138 for (
int i = 1;
i <=
nlumis ( filename ) ;
i++ )
140 if ( !check_isgood ( ls_x_bad ,
i ) && !
check_isgood ( ls_xsc_bad ,
i ) )
142 ls_bad.push_back (
i );
146 if ( !check_isgood ( ls_y_bad ,
i ) && !check_isgood ( ls_ysc_bad ,
i ) )
148 ls_bad.push_back (
i );
152 if ( !check_isgood ( ls_z_bad ,
i ) && !check_isgood ( ls_zsc_bad ,
i ) )
154 ls_bad.push_back (
i );
158 if ( !check_isgood ( ls_dx_bad ,
i ) && !check_isgood ( ls_dxsc_bad ,
i ) )
160 ls_bad.push_back (
i );
164 if ( !check_isgood ( ls_dy_bad ,
i ) && !check_isgood ( ls_dysc_bad ,
i ) )
166 ls_bad.push_back (
i );
170 if ( !check_isgood ( ls_dz_bad ,
i ) && !check_isgood ( ls_dzsc_bad ,
i ) )
172 ls_bad.push_back (
i );
176 if ( !check_isgood ( ls_errdx_bad ,
i ) && !check_isgood ( ls_errdxsc_bad ,
i ) )
178 ls_bad.push_back (
i );
182 if ( !check_isgood ( ls_errdy_bad ,
i ) && !check_isgood ( ls_errdysc_bad ,
i ) )
184 ls_bad.push_back (
i );
188 if ( !check_isgood ( ls_errdz_bad ,
i ) && !check_isgood ( ls_errdzsc_bad ,
i ) )
190 ls_bad.push_back (
i );
195 ls_good.push_back(
i );
200 outfile.open(namefile.c_str());
201 outfile <<
"Lumibased BeamSpot Calibration Certification for run " <<
runnum_str( filename ) <<
":" << endl << endl;
204 sprintf( line,
" GOOD Lumisections (values within limits): %s" ,
ListOut( ls_good ).c_str() );
205 outfile << line << endl;
207 if ( ls_bad.size() > 0 )
209 sprintf( line,
" BAD Lumisections (values outside limits): %s" ,
ListOut( ls_bad ).c_str() );
210 outfile << line << endl;
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;
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;
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;
235 sprintf( line,
" (*) also bad in the corresponding 'Scalers-Database fit' histograms" );
236 outfile << line << endl;
240 std::cout <<
"Lumibased BeamSpot Calibration Certification summary saved in " << namefile << endl;
246 if (
getplot ( filename , iDir , plot , checkPlot ) < 0 )
return;
250 for (
int i = 1;
i <= checkPlot.GetNbinsX() ;
i++ )
252 float value = checkPlot.GetBinContent(
i );
253 if ( value < limit_min || value > limit_max )
255 badLS.push_back( (
int)checkPlot.GetBinCenter(
i ) );
264 if (
getplot ( filename , iDir , plot , checkPlot ) < 0 )
return;
267 for (
int i = 1;
i <= checkPlot.GetNbinsX() ;
i++ )
269 float value = checkPlot.GetBinError(
i );
270 if ( value > limit_err )
272 badLS.push_back( (
int)checkPlot.GetBinCenter(
i ) );
281 for (
unsigned int i = 0;
i < ls_badlist.size() ;
i++ )
283 if ( ls == ls_badlist[
i] )
return false;
293 TFile*
file = TFile::Open(filename.c_str());
294 if (!file->IsOpen()) {
295 cerr <<
"Failed to open " << filename << endl;
300 string EventInfoDir =
"DQMData/Run " + run +
"/SiStrip/Run summary/EventInfo";
301 TDirectory *rsEventInfoDir =
dynamic_cast<TDirectory*
>( file->Get(EventInfoDir.c_str()));
302 rsEventInfoDir->cd();
303 TIter eiKeys(rsEventInfoDir->GetListOfKeys());
305 while ( (eiKey = dynamic_cast<TKey*>(eiKeys())) )
307 string classname(eiKey->GetClassName());
308 if (classname==
"TObjString" )
310 string sflag = eiKey->GetName();
311 string tempname = sflag.substr(sflag.find(
"i=")+2);
312 size_t pos1 = tempname.find(
"<");
313 size_t pos2 = sflag.find_first_of(
">");
314 string detvalue = tempname.substr(0,pos1);
315 string numlumisec = sflag.substr(1,pos2-1);
316 if ( numlumisec.c_str() == (
string)
"iLumiSection" )
318 numlumis = atoi( detvalue.c_str() );
329 return filename.substr(filename.find(
"_R000")+5, 6);
332 int getplot(
string filename ,
string iDir ,
string strplot , TH1F&
plot )
337 TFile* file = TFile::Open(filename.c_str());
338 if (!file->IsOpen()) {
339 cerr <<
"Failed to open " << filename << endl;
343 string dir =
"DQMData/Run " + run +
"/AlcaBeamMonitor/Run summary/" + iDir;
345 file->cd( dir.c_str() );
347 string theplot = strplot +
";1";
349 gDirectory->GetObject ( theplot.c_str() , thisplot );
353 std::cout <<
"Error: plot " << dir <<
"/" << theplot.c_str() <<
" not found!" << endl;
366 if ( LSlist.size() == 0 )
return;
369 int refLS = LSlist[0];
370 for (
unsigned int at = 1;
at < LSlist.size() - 1;
at++)
373 if ( refLS + 1 == LSlist[
at] && LSlist[
at] + 1 == LSlist[
at+1] )
385 string ListOut(vector<int> &LSlist)
391 bool rangeset =
false;
392 for (
unsigned int at = 0;
at < LSlist.size();
at++)
394 if ( LSlist[
at] != -1 )
396 if (
at > 0 && LSlist[
at-1] != -1 ) strout +=
",";
399 strout += lsnum.str();
402 if ( LSlist[
at] == -1 && !rangeset )
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 ] )
421 temp.push_back( bad_def[
i ] );
void Cleaning(vector< int > &LSlist)
void lsbs_cert(string filename)
string runnum_str(string filename)
void vector_AND(vector< int > &, vector< int >)
int main(int argc, char **argv)
string ListOut(vector< int > &LSlist)
int getplot(string filename, string iDir, string strplot, TH1F &plot)
int nlumis(string filename)
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)