16 #include "TGraphErrors.h"
24 #include "TVirtualPad.h"
26 #include "TObjArray.h"
27 #include "TObjString.h"
32 TStyle* theStyle=
new TStyle();
33 theStyle->SetOptStat(0);
35 theStyle->SetOptStat(0);
36 theStyle->SetOptFit(111);
37 theStyle->SetStatFont(12);
38 theStyle->SetStatBorderSize(1);
39 theStyle->SetCanvasColor(0);
40 theStyle->SetCanvasBorderMode(0);
41 theStyle->SetPadBorderMode(0);
42 theStyle->SetPadColor(0);
43 theStyle->SetLineWidth(1);
44 theStyle->SetLineStyle(2);
45 theStyle->SetPalette(1);
46 theStyle->SetMarkerStyle(20);
47 theStyle->SetMarkerColor(2);
48 theStyle->SetLabelSize(0.05,
"y");
49 theStyle->SetLabelSize(0.04,
"x");
50 theStyle->SetTitleFontSize(0.2);
51 theStyle->SetTitleW(0.9);
52 theStyle->SetTitleH(0.06);
53 theStyle->SetPadLeftMargin(0.12);
54 theStyle->SetPadTopMargin(0.13);
58 void HDQMInspector::setDB(
const std::string & DBName,
const std::string & DBTag,
const std::string & DBauth)
67 std::cout <<
"Name of DB = "<< DBName << std::endl;
68 std::cout <<
"DBTag = "<< DBTag << std::endl;
69 std::cout <<
"DBauth = "<< DBauth << std::endl;
74 fOutFile =
new TFile(
"historicDQM.root",
"RECREATE" );
76 std::cerr <<
"ERROR: cannot open output file" << std::endl;
92 std::cout <<
"creating connection" << std::endl;
94 std::cout <<
"connection created" << std::endl;
108 for (std::string::const_iterator Pos = ListItems.begin(); Pos != ListItems.end(); ) {
111 std::string Remainder(Pos, ListItems.end());
115 std::string
Entry = Remainder.substr(0, Remainder.find(
","));
118 if ( Entry.find(
"-") ) {
121 int const FirstRun = atoi( Entry.substr(0, Entry.find(
"-")).c_str() );
122 int const LastRun = atoi( Entry.substr(Entry.find(
"-")+1).c_str() );
125 if (FirstRun > LastRun) {
126 std::cerr <<
"ERROR: FirstRun > LastRun in blackList" << std::endl;
131 for (
int i = FirstRun;
i <= LastRun; ++
i) {
137 blackList.push_back( atoi(Entry.c_str()) );
142 if (Pos != ListItems.end()) {
158 for (std::string::const_iterator Pos = ListItems.begin(); Pos != ListItems.end(); ) {
161 std::string Remainder(Pos, ListItems.end());
165 std::string
Entry = Remainder.substr(0, Remainder.find(
","));
168 if ( Entry.find(
"-") ) {
171 int const FirstRun = atoi( Entry.substr(0, Entry.find(
"-")).c_str() );
172 int const LastRun = atoi( Entry.substr(Entry.find(
"-")+1).c_str() );
175 if (FirstRun > LastRun) {
176 std::cerr <<
"ERROR: FirstRun > LastRun in WhiteList" << std::endl;
181 for (
int i = FirstRun;
i <= LastRun; ++
i) {
187 whiteList.push_back( atoi(Entry.c_str()) );
192 if (Pos != ListItems.end()) {
206 std::ifstream listFile;
207 listFile.open(listFileName.c_str());
208 std::string listString;
210 std::cout <<
"Warning: list file" << listFileName <<
" not found" << std::endl;
213 while( !listFile.eof() ) {
223 if( pos != std::string::npos ) {
224 listString.erase(pos);
226 std::cout <<
"whiteList = " << listString << std::endl;
236 if (std::binary_search(vList.begin(), vList.end(),
run)) {
238 std::cout <<
"\n Run "<< run <<
" is listed !!\n" << std::endl;
251 while((reference =
Iterator->next())) {
270 std::vector<unsigned int>::iterator iter;
276 std::cout <<
"firstRun (" << firstRun <<
") > last iov ("<<
iovList.back()<<
")"<<std::endl;
282 if (*iter>lastRun) last = *(iter-1);
291 std::cout <<
"setting Range firstRun (" << first <<
") - lastRun ("<<last<<
")"<<std::endl;
298 const int logy,
const std::string Conditions, std::string
const& Labels,
const unsigned int nRuns,
int const UseYRange,
double const& YMin,
double const& YMax)
301 unsigned int iovListSize =
iovList.size();
307 if (iovListSize>=nRuns) {
308 first =
iovList.at(iovListSize-nRuns);
315 createTrend(ListItems,CanvasName,logy,Conditions,Labels,first,last, UseYRange, YMin, YMax);
320 void HDQMInspector::createTrend(std::string ListItems, std::string CanvasName,
int logy, std::string Conditions, std::string
const& Labels,
unsigned int firstRun,
unsigned int lastRun,
int const UseYRange,
double const& YMin,
double const& YMax)
322 std::cout <<
"\n****************\nCreateTrend\n****************\n" << std::endl;
323 std::cout <<
"ListItems : " << ListItems << std::endl;
324 std::cout <<
"Conditions : " << Conditions << std::endl;
330 std::vector<DetIdItemList> vDetIdItemListCut;
338 std::cout <<
"firstRun " << firstRun <<
" lastRun " << lastRun << std::endl;
344 while((reference =
Iterator->next())) {
355 if(vDetIdItemListCut.size()){
356 for(
size_t ij=0;ij!=vDetIdItemListCut.size();++ij){
357 vDetIdItemListCut[ij].values=reference->
getSummaryObj(vDetIdItemListCut[ij].
detid, vDetIdItemListCut[ij].items);
371 std::cout << ListItems <<
" run " <<
vRun_.back() <<
" values \n" ;
373 for(
size_t i=0;
i<detiditemlist.
items.size();++
i) {
382 plot(nPads, CanvasName, logy, Labels, UseYRange, YMin, YMax);
386 std::cout <<
"\n****** Ignore this error *****\n" << std::endl;
388 std::cout <<
"\n******************************\n" << std::endl;
391 void HDQMInspector::plot(
size_t& nPads, std::string CanvasName,
int logy, std::string
const& Labels,
int const UseYRange,
double const YMin,
double const YMax)
393 std::cout <<
"\n********\nplot\n*****\n"<< std::endl;
397 double *
X, *Y, *EX, *EY, *YCumul;
398 X=
new double[
vRun_.size()];
399 Y=
new double[
vRun_.size()];
400 EX=
new double[
vRun_.size()];
401 EY=
new double[
vRun_.size()];
402 YCumul=
new double[
vRun_.size()];
410 sprintf(name,
"%d",(
int) clock());
411 CanvasName=std::string(name);
414 std::string rootCName = CanvasName;
415 rootCName.replace(rootCName.find(
"."),rootCName.size()-rootCName.find(
"."),
"");
417 C=
new TCanvas(rootCName.c_str(),
"");
418 int ndiv=(int)
sqrt(nPads);
419 C->Divide(ndiv,nPads/ndiv+ (nPads%ndiv?1:0));
432 std::vector<TGraphErrors*> VectorOfGraphs;
433 std::vector<std::string> VectorOfDetNames;
442 std::stringstream ss;
448 VectorOfDetNames.push_back(
"???" );
492 if (
j == 0 ) YCumul[
j] = Y[
j];
493 else YCumul[
j] = Y[
j] + YCumul[
j-1];
507 if (UseYRange != 0) {
508 for (
size_t iRun = 0; iRun !=
vRun_.size(); ++iRun) {
509 if (UseYRange % 2 == 1 && Y[iRun] < YMin) {
513 if (UseYRange >= 2 && Y[iRun] > YMax) {
520 graph =
new TGraphErrors((
int)
vRun_.size(),
X,Y,EX,EY);
523 for (
size_t ipt = 0; ipt !=
vRun_.size(); ++ipt) {
532 if( ((Y[ipt] == -10 || Y[ipt] == -9999 || Y[ipt] == -999 || Y[ipt] == -99) &&
fSkip99s) || (Y[ipt] == 0 &&
fSkip0s) ) {
536 graph->RemovePoint(iptTGraph);
546 graph->SetTitle(ss.str().c_str());
547 if (UseYRange % 2 == 1) {
548 graph->SetMinimum(YMin);
550 if (UseYRange >= 2) {
551 graph->SetMaximum(YMax);
555 graph->SetName(ss.str().c_str());
556 graph->GetXaxis()->SetTitle(
"Run number");
560 VectorOfGraphs.push_back(graph);
569 if (itemForIntegration)
571 std::stringstream ss2; std::stringstream ss3; std::stringstream ss4;
574 ss2 << title <<
"_Integral";
575 ss3 << title <<
"_Integrated.gif";
576 ss4 << title <<
"_Integrated.root";
578 TCanvas* C2 =
new TCanvas(ss2.str().c_str(),
"");
579 TGraphErrors* graph2 =
new TGraphErrors((
int)
vRun_.size(),
X,YCumul,EX,EX);
580 graph2->SetTitle(ss2.str().c_str());
581 graph2->SetMarkerColor(1);
583 graph2->SetName(ss2.str().c_str());
584 graph2->GetXaxis()->SetTitle(
"Run number");
587 C2->SaveAs(ss3.str().c_str());
588 C2->SaveAs(ss4.str().c_str());
595 C->SaveAs(CanvasName.c_str());
603 if (VectorOfGraphs.size() > 1) {
606 TLegend OverlayLegend(0.80,0.35,0.99,0.65);
613 TCanvas DeanCan(
"DeanCan",
"DeanCan");
614 TVirtualPad* VPad = DeanCan.cd();
615 VPad->SetRightMargin(0.21);
616 VPad->SetTopMargin(0.13);
619 TString
const LNames = Labels;
620 TObjArray* MyArrayPtr = LNames.Tokenize(
",");
622 MyArrayPtr->SetOwner(kTRUE);
623 for(
int i = 0;
i <= MyArrayPtr->GetLast(); ++
i ) {
624 if(
i <
int(VectorOfDetNames.size()) ) {
625 VectorOfDetNames[
i] = ((TObjString*) MyArrayPtr->At(
i) )->GetString().Data();
628 MyArrayPtr->Delete();
633 for (
size_t i = 0;
i != VectorOfGraphs.size(); ++
i) {
636 TString MyTitle = VectorOfGraphs[
i]->GetTitle();
637 std::cout <<
"dhidas " << MyTitle <<
" : " << VectorOfDetNames[
i] << std::endl;
638 MyTitle.ReplaceAll(VectorOfDetNames[
i]+
"_",
"");
639 MyTitle.ReplaceAll(
"_"+VectorOfDetNames[
i],
"");
640 MyTitle.ReplaceAll(VectorOfDetNames[i],
"");
641 std::cout <<
"dhidas " << MyTitle << std::endl;
642 VectorOfGraphs[
i]->SetTitle( MyTitle );
645 OverlayLegend.AddEntry(VectorOfGraphs[i], VectorOfDetNames[i].c_str(),
"p");
656 VectorOfGraphs[
i]->SetMarkerStyle(20+i);
657 VectorOfGraphs[
i]->SetMarkerColor(2+i);
660 VectorOfGraphs[0]->SetMinimum((min)-((max)-(min))/5.);
661 VectorOfGraphs[0]->SetMaximum((max)+((max)-(min))/5.);
662 if (UseYRange % 2 == 1) {
663 VectorOfGraphs[0]->SetMinimum(YMin);
665 if (UseYRange >= 2) {
666 VectorOfGraphs[0]->SetMaximum(YMax);
671 VectorOfGraphs[0]->Draw(
"Ap");
672 for (
size_t i = 1;
i != VectorOfGraphs.size(); ++
i) {
673 VectorOfGraphs[
i]->Draw(
"p");
675 OverlayLegend.Draw(
"same");
677 DeanCan.SaveAs(CanvasName.replace(CanvasName.find(
"."),CanvasName.size()-CanvasName.find(
"."),
"_Overlay.gif").c_str());
681 for (
size_t i = 0;
i != VectorOfGraphs.size(); ++
i) {
682 delete VectorOfGraphs[
i];
695 while( loc != std::string::npos ) {
696 setItems(ListItems.substr(oldloc,loc-oldloc));
698 loc=ListItems.find(
",", oldloc );
702 setItems(ListItems.substr(oldloc,loc-oldloc));
710 char delimiters[128]=
"><=+-*/&|() ";
711 char copyConditions[1024];
712 sprintf(copyConditions,
"%s",Conditions.c_str());
713 pch = strtok (copyConditions,delimiters);
717 std::string itemD(pch);
718 detiditemlist.
detid=atol(itemD.substr(0,itemD.find(
fSep)).c_str());
719 detiditemlist.
items.push_back(itemD.substr(itemD.find(
fSep)+
fSep.size()));
721 std::cout <<
"Found a Condition " << detiditemlist.
items.back() <<
" for detId " << detiditemlist.
detid << std::endl;
724 if(vdetIdItemList.size())
725 if(vdetIdItemList.back().detid==detiditemlist.
detid)
726 vdetIdItemList.back().items.insert(vdetIdItemList.back().items.end(),detiditemlist.
items.begin(),detiditemlist.
items.end());
728 vdetIdItemList.push_back(detiditemlist);
730 vdetIdItemList.push_back(detiditemlist);
732 pch = strtok (
NULL,delimiters);
739 char cConditions[1024];
740 char singleCondition[1024];
743 sprintf(cConditions,
"%s",Conditions.c_str());
745 std::cout <<
"Conditions " << cConditions << std::endl;
747 for(
size_t ic=0;ic<vdetIdItemList.size();++ic)
748 for(
size_t jc=0;jc<vdetIdItemList[ic].items.size();++jc){
751 sprintf(condCVal,
"%f",vdetIdItemList[ic].
values[jc]);
752 sprintf(singleCondition,
"%d%s%s",vdetIdItemList[ic].
detid,
fSep.c_str(),vdetIdItemList[ic].items[jc].c_str());
755 char* fpos = strstr(cConditions,singleCondition);
757 strncpy(fpos,condCVal,strlen(condCVal));
758 memset(fpos+strlen(condCVal),
' ',strlen(singleCondition)-strlen(condCVal));
763 std::string stringToEvaluate;
765 pch = strtok (cConditions,
" ");
767 stringToEvaluate.append(pch);
768 pch = strtok (
NULL,
" ");
775 std::cout <<
"Conditions After SubStitution " << stringToEvaluate << std::endl;
777 TFormula Formula(
"condition", stringToEvaluate.c_str());
778 resultdbl = Formula.Eval(0);
780 std::cout <<
"Result " << resultdbl << std::endl;
791 detiditemlist.
detid=atol(itemD.substr(0,itemD.find(
fSep)).c_str());
793 std::string item=itemD.substr(itemD.find(
fSep)+
fSep.size());
794 detiditemlist.
items.push_back(item);
797 std::cout <<
"Found new item " << detiditemlist.
items.back() <<
" for detid " << detiditemlist.
detid << std::endl;
799 if(item.find(
"mean")!=std::string::npos){
800 detiditemlist.
items.push_back(item.replace(item.find(
"mean"),4,
"rms"));
802 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
803 detiditemlist.
items.push_back(item.replace(item.find(
"rms"),3,
"entries"));
805 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
807 else if(item.find(
"landauPeak")!=std::string::npos){
808 detiditemlist.
items.push_back(item.replace(item.find(
"landauPeak"),10,
"landauPeakErr"));
810 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
812 else if(item.find(
"gaussMean")!=std::string::npos){
813 detiditemlist.
items.push_back(item.replace(item.find(
"gaussMean"),9,
"gaussSigma"));
815 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
836 double*
y = g->GetY();
837 int locmax = TMath::LocMax(n,y);
846 double*
y = g->GetY();
847 int locmin = TMath::LocMin(n,y);
double findGraphMin(TGraphErrors *)
void createTrendLastRuns(const std::string ListItems, const std::string CanvasName="", const int logy=0, const std::string Conditions="", std::string const &Labels="", const unsigned int nRuns=10, int const UseYRange=0, double const &YMin=999999, double const &YMax=-999999)
double findGraphMax(TGraphErrors *)
std::vector< std::string > vlistItems_
std::vector< std::string > items
std::vector< unsigned int > iovList
std::vector< unsigned int > whiteList
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
void setItems(std::string)
void setBlackList(std::string const &ListItems)
bool isListed(unsigned int run, std::vector< unsigned int > &vList)
const T & max(const T &a, const T &b)
void createTrend(const std::string ListItems, const std::string CanvasName="", const int logy=0, const std::string Conditions="", std::string const &Labels="", const unsigned int firstRun=1, const unsigned int lastRun=0xFFFFFFFE, int const UseYRange=0, double const &YMin=999999, double const &YMax=-999999)
void setWhiteList(std::string const &ListItems)
void unpackConditions(std::string &, std::vector< DetIdItemList > &)
std::vector< float > values
std::vector< unsigned int > blackList
std::string readListFromFile(const std::string &listFileName)
bool ApplyConditions(std::string &, std::vector< DetIdItemList > &)
const HDQMInspectorConfigBase * fHDQMInspectorConfig
bool computeIntegral(const std::string &in) const
bool setRange(unsigned int &firstRun, unsigned int &lastRun)
virtual std::string translateDetId(const uint32_t) const =0
pure virtual method that convert a DetId to a string
std::vector< float > vSummary_
std::vector< float > getSummaryObj(uint32_t &detID, std::vector< std::string > list) const
std::vector< unsigned int > vdetId_
size_t unpackItems(std::string &)
void setDB(const std::string &DBName, const std::string &DBTag, const std::string &DBauth="")
std::vector< DetIdItemList > vDetIdItemList_
CondCachedIter< HDQMSummary > * Iterator
void plot(size_t &nPads, std::string CanvasName, int logy=0, std::string const &Labels="", int const UseYRange=0, double const XMin=999999, double const YMin=-999999)
std::vector< unsigned int > vRun_