1 #ifndef GUARD_HCALTESTUTILS_H
2 #define GUARD_HCALTESTUTILS_H
4 #define UTILS_ETAMIN -44.5
5 #define UTILS_ETAMAX 44.5
6 #define UTILS_PHIMIN -0.5
7 #define UTILS_PHIMAX 73.5
60 if (!dbe_)
return NULL;
61 std::stringstream
title;
62 title <<process.c_str()<<rootfolder.c_str()<<
"/"<<name.c_str();
68 if (verb)
std::cout <<
"SORRY, COULD NOT FIND HISTOGRAM NAMED ["<< title.str().c_str()<<
"]"<<std::endl;
73 std::cout <<
"Found '" << title.str().c_str() <<
"'" << std::endl;
75 std::stringstream clonehisto;
78 clonehisto<<
"ME "<<name.c_str();
79 TH1F *
out =
dynamic_cast<TH1F*
>(me->
getTH1F()->Clone(clonehisto.str().c_str()));
87 if (!dbe_)
return NULL;
88 std::stringstream
title;
89 title <<process.c_str()<<rootfolder.c_str()<<
"/"<<name.c_str();
95 if (verb)
std::cout <<
"SORRY, COULD NOT FIND HISTOGRAM NAMED ["<< title.str().c_str()<<
"]"<<std::endl;
100 std::cout <<
"Found '" << title.str().c_str() <<
"'" << std::endl;
102 std::stringstream clonehisto;
105 clonehisto<<
"ME "<<name.c_str();
106 TH2F *
out =
dynamic_cast<TH2F*
>(me->
getTH2F()->Clone(clonehisto.str().c_str()));
115 if (!dbe_)
return NULL;
116 std::stringstream
title;
117 title <<process.c_str()<<rootfolder.c_str()<<
"/"<<name.c_str();
123 if (verb)
std::cout <<
"SORRY, COULD NOT FIND HISTOGRAM NAMED ["<< title.str().c_str()<<
"]"<<std::endl;
128 std::cout <<
"Found '" << title.str().c_str() <<
"'" << std::endl;
130 std::stringstream clonehisto;
133 clonehisto<<
"ME "<<name.c_str();
134 TH3F *
out =
dynamic_cast<TH3F*
>(me->
getTH3F()->Clone(clonehisto.str().c_str()));
142 if (!dbe_)
return NULL;
143 std::stringstream
title;
144 title <<process.c_str()<<rootfolder.c_str()<<
"/"<<name.c_str();
150 if (verb)
std::cout <<
"SORRY, COULD NOT FIND HISTOGRAM NAMED ["<< title.str().c_str()<<
"]"<<std::endl;
155 std::cout <<
"Found '" << title.str().c_str() <<
"'" << std::endl;
157 std::stringstream clonehisto;
160 clonehisto<<
"ME "<<name.c_str();
161 TProfile *
out =
dynamic_cast<TProfile*
>(me->
getTProfile()->Clone(clonehisto.str().c_str()));
169 if (!dbe_)
return NULL;
170 std::stringstream
title;
171 title <<process.c_str()<<rootfolder.c_str()<<
"/"<<name.c_str();
177 if (verb)
std::cout <<
"SORRY, COULD NOT FIND HISTOGRAM NAMED ["<< title.str().c_str()<<
"]"<<std::endl;
182 std::cout <<
"Found '" << title.str().c_str() <<
"'" << std::endl;
184 std::stringstream clonehisto;
187 clonehisto<<
"ME "<<name.c_str();
188 TProfile2D *
out =
dynamic_cast<TProfile2D*
>(me->
getTProfile2D()->Clone(clonehisto.str().c_str()));
196 template <
class myHist>
199 bool verb,
bool clone)
203 myHist* theHist=
getAnyHisto(hist, name, process,
"Hcal",dbe_, verb, clone);
208 template <
class myHist>
211 bool verb,
bool clone)
221 if (!dbe_)
return NULL;
223 std::stringstream clonehisto;
224 std::stringstream
title;
225 title <<process.c_str()<<rootfolder.c_str()<<
"/"<<name.c_str();
232 if (verb)
std::cout <<
"SORRY, COULD NOT FIND HISTOGRAM NAMED ["<< title.str().c_str()<<
"]"<<std::endl;
237 std::cout <<
"Found '" << title.str().c_str() <<
"'" << std::endl;
240 clonehisto<<
"ME "<<name.c_str();
247 std::string
histtype = hist->ClassName();
250 if (histtype==
"TH1F")
253 if (clone) out =
dynamic_cast<TH1F*
>(me->
getTH1F()->Clone(clonehisto.str().c_str()));
255 if (verb)
std::cout <<
"Got histogram! Max = "<<out->GetMaximum()<<std::endl;
256 return dynamic_cast<myHist*
>(
out);
260 else if (histtype==
"TH2F")
263 if (clone) out =
dynamic_cast<TH2F*
>(me->
getTH2F()->Clone(clonehisto.str().c_str()));
266 if (verb)
std::cout <<
"Got histogram! Max = "<<out->GetMaximum()<<std::endl;
267 return dynamic_cast<myHist*
>(
out);
271 else if (histtype==
"TH3F")
274 if (clone) out =
dynamic_cast<TH3F*
>(me->
getTH3F()->Clone(clonehisto.str().c_str()));
276 return dynamic_cast<myHist*
>(
out);
280 else if (histtype==
"TProfile")
283 if (clone) out =
dynamic_cast<TProfile*
>(me->
getTProfile()->Clone(clonehisto.str().c_str()));
285 return dynamic_cast<myHist*
>(
out);
289 else if (histtype==
"TProfile2D")
292 if (clone) out =
dynamic_cast<TProfile2D*
>(me->
getTProfile2D()->Clone(clonehisto.str().c_str()));
294 return dynamic_cast<myHist*
>(
out);
302 std::cout<<
"' of type '"<<histtype<<
"'"<<std::endl;
309 std::cout <<
"<HcalHistUtils::getAnyHisto> YOU SHOULD NEVER SEE THIS MESSAGE!"<<std::endl;
318 template <
class myHist>
320 const char* xlab,
const char* ylab,
int debug )
335 std::string
name = (std::string)hist->GetTitle();
336 if (debug>9)
std::cout <<
"NAME = ["<<name<<
"]"<<std::endl;
337 for (
unsigned int i = 0;
i < name.size(); ++
i ) {
338 if ( name.substr(
i, 6) ==
" - Run" ){
339 name.replace(
i, name.size()-
i,
"");
341 if ( name.substr(
i, 4) ==
"_Run" ){
342 name.replace(
i, name.size()-
i,
"");
344 if ( name.substr(
i, 5) ==
"__Run" ){
345 name.replace(
i, name.size()-
i,
"");
348 if (name.substr(
i,1) ==
"(" || name.substr(
i,1)==
")")
349 name.replace(
i,1,
"_");
350 else if (name.substr(
i,1)==
",")
351 name.replace(
i,1,
"_");
352 else if (name.substr(
i,1)==
"<")
353 name.replace(
i,1,
"_lt_");
354 else if (name.substr(
i,1)==
">")
355 name.replace(
i,1,
"_gt_");
356 else if (name.substr(
i,1)==
"+")
357 name.replace(
i,1,
"_plus_");
358 else if (name.substr(
i,1)==
"#")
359 name.replace(
i,1,
"");
360 else if (name.substr(
i,1)==
"/")
361 name.replace(
i,1,
"_div_");
366 if(runNo>-1) sprintf(dest,
"%s - Run %d",name.c_str(),runNo);
367 else sprintf(dest,
"%s",name.c_str());
377 title = title+
"_tmb";
383 for (
unsigned int i = 0;
i < title.size(); ++
i ) {
384 if ( title.substr(
i, 1) ==
" " ){
385 title.replace(
i, 1,
"_");
387 if ( title.substr(
i, 1) ==
"#" ){
388 title.replace(
i, 1,
"N");
390 if ( title.substr(
i, 1) ==
"-" ){
391 title.replace(
i, 1,
"_");
393 if ( title.substr(
i, 1) ==
"&" ){
394 title.replace(
i, 1,
"_and_");
396 if ( title.substr(
i, 1) ==
"("
397 || title.substr(
i, 1) ==
")"
399 title.replace(
i, 1,
"_");
401 if ( title.substr(
i,1) ==
"="){
402 title.replace(
i,1,
"_");
406 std::string outName = title+
".gif";
407 std::string saveName = htmlDir + outName;
411 TCanvas*
can =
new TCanvas(dest,dest, xwid, ywid);
416 hist->SetXTitle(xlab);
417 hist->SetYTitle(ylab);
418 std::string
histtype=hist->ClassName();
422 if (((std::string)hist->GetOption())==
"col" ||
423 ((std::string)hist->GetOption())==
"colz")
424 hist->SetStats(
false);
428 hist->Draw(hist->GetOption());
432 if (histtype==
"TH2F")
434 TAxis *xaxis = hist->GetXaxis();
435 TAxis *yaxis=hist->GetYaxis();
443 for (
int xx=
int(xaxis->GetXmin());
444 xx<=int(xaxis->GetXmax()); ++xx)
446 if (xx<-42 || xx >= 42)
continue;
447 vert =
new TLine(xx+0.5,0.5,xx+0.5,72.5);
451 vert->SetLineStyle(3);
455 for (
int yy=
int(yaxis->GetXmin()); yy<int(yaxis->GetXmax());++yy)
458 horiz =
new TLine(-41.5,yy+0.5,41.5,yy+0.5);
460 horiz =
new TLine(-39.5,yy+0.5,39.5,yy+0.5);
462 horiz =
new TLine(-20.5,yy+0.5,20.5,yy+0.5);
465 horiz->SetLineStyle(3);
471 can->SaveAs(saveName.c_str());
485 template <
class myHist>
487 const char* xlab,
const char* ylab,
488 int width, ofstream& htmlFile,
499 std::string
histtype=hist->ClassName();
502 if (histtype==
"TH2F" && ((std::string)hist->GetOption())==
"")
504 hist->SetOption(
"colz");
511 std::string imgName =
getAnyIMG(runNo,hist,2,htmlDir,xlab,ylab,
debug);
514 if (imgName.size() != 0 )
518 htmlFile <<
"<td align=\"center\"><a href=\"" <<imgName<<
"\"><img src=\""<<imgName<<
"\" width=600 height=360\"></a><br>"<<hist->GetName()<<
"</td>"<<std::endl;
522 htmlFile <<
"<td align=\"center\"><img src=\"" <<
" " <<
"\"></td>" << std::endl;
528 htmlFile<<
"<td align=\"center\"><br><br> Histogram does not exist in ROOT file!<br>Diagnostic flag may be off.<br>(This may be normal in online running.)</td>"<<std::endl;
TProfile * getTProfile(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
TProfile2D * getTProfile2D(void) const
myHist * getAnyHisto(myHist *hist, std::string name, std::string process, DQMStore *dbe_, bool verb, bool clone)
TH3F * getTH3F(void) const
void htmlAnyHisto(int runNo, myHist *hist, const char *xlab, const char *ylab, int width, ofstream &htmlFile, std::string htmlDir, int debug=0)
TH3F * getTH3F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
TH1F * getTH1F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
TProfile2D * getTProfile2D(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. "my/long/dir/my_histo")
TH1F * getTH1F(void) const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
TProfile * getTProfile(void) const
TH2F * getTH2F(std::string name, std::string process, std::string rootfolder, DQMStore *dbe_, bool verb, bool clone)
TH2F * getTH2F(void) const
std::string getAnyIMG(int runNo, myHist *hist, int size, std::string htmlDir, const char *xlab, const char *ylab, int debug)
tuple size
Write out results.