17 #include "TGraphErrors.h"
25 #include "TVirtualPad.h"
27 #include "TObjArray.h"
28 #include "TObjString.h"
33 TStyle* theStyle=
new TStyle();
34 theStyle->SetOptStat(0);
36 theStyle->SetOptStat(0);
37 theStyle->SetOptFit(111);
38 theStyle->SetStatFont(12);
39 theStyle->SetStatBorderSize(1);
40 theStyle->SetCanvasColor(0);
41 theStyle->SetCanvasBorderMode(0);
42 theStyle->SetPadBorderMode(0);
43 theStyle->SetPadColor(0);
44 theStyle->SetLineWidth(1);
45 theStyle->SetLineStyle(2);
46 theStyle->SetPalette(1);
47 theStyle->SetMarkerStyle(20);
48 theStyle->SetMarkerColor(2);
49 theStyle->SetLabelSize(0.05,
"y");
50 theStyle->SetLabelSize(0.04,
"x");
51 theStyle->SetTitleFontSize(0.2);
52 theStyle->SetTitleW(0.9);
53 theStyle->SetTitleH(0.06);
54 theStyle->SetPadLeftMargin(0.12);
55 theStyle->SetPadTopMargin(0.13);
68 std::cout <<
"Name of DB = "<< DBName << std::endl;
69 std::cout <<
"DBTag = "<< DBTag << std::endl;
70 std::cout <<
"DBauth = "<< DBauth << std::endl;
75 fOutFile =
new TFile(
"historicDQM.root",
"RECREATE" );
77 std::cerr <<
"ERROR: cannot open output file" << std::endl;
93 std::cout <<
"creating connection" << std::endl;
95 std::cout <<
"connection created" << std::endl;
109 for (std::string::const_iterator Pos = ListItems.begin(); Pos != ListItems.end(); ) {
119 if ( Entry.find(
"-") ) {
122 int const FirstRun = atoi( Entry.substr(0, Entry.find(
"-")).c_str() );
123 int const LastRun = atoi( Entry.substr(Entry.find(
"-")+1).c_str() );
126 if (FirstRun > LastRun) {
127 std::cerr <<
"ERROR: FirstRun > LastRun in blackList" << std::endl;
132 for (
int i = FirstRun;
i <= LastRun; ++
i) {
138 blackList.push_back( atoi(Entry.c_str()) );
143 if (Pos != ListItems.end()) {
159 for (std::string::const_iterator Pos = ListItems.begin(); Pos != ListItems.end(); ) {
169 if ( Entry.find(
"-") ) {
172 int const FirstRun = atoi( Entry.substr(0, Entry.find(
"-")).c_str() );
173 int const LastRun = atoi( Entry.substr(Entry.find(
"-")+1).c_str() );
176 if (FirstRun > LastRun) {
177 std::cerr <<
"ERROR: FirstRun > LastRun in WhiteList" << std::endl;
182 for (
int i = FirstRun;
i <= LastRun; ++
i) {
188 whiteList.push_back( atoi(Entry.c_str()) );
193 if (Pos != ListItems.end()) {
207 std::ifstream listFile;
208 listFile.open(listFileName.c_str());
211 std::cout <<
"Warning: list file" << listFileName <<
" not found" << std::endl;
214 while( !listFile.eof() ) {
224 if( pos != std::string::npos ) {
225 listString.erase(pos);
227 std::cout <<
"whiteList = " << listString << std::endl;
237 if (std::binary_search(vList.begin(), vList.end(),
run)) {
239 std::cout <<
"\n Run "<< run <<
" is listed !!\n" << std::endl;
252 while((reference =
Iterator->next())) {
271 std::vector<unsigned int>::iterator
iter;
277 std::cout <<
"firstRun (" << firstRun <<
") > last iov ("<<
iovList.back()<<
")"<<std::endl;
283 if (*iter>lastRun) last = *(iter-1);
292 std::cout <<
"setting Range firstRun (" << first <<
") - lastRun ("<<last<<
")"<<std::endl;
299 const int logy,
const std::string Conditions,
std::string const& Labels,
const unsigned int nRuns,
int const UseYRange,
double const& YMin,
double const& YMax)
302 unsigned int iovListSize =
iovList.size();
308 if (iovListSize>=nRuns) {
309 first =
iovList.at(iovListSize-nRuns);
316 createTrend(ListItems,CanvasName,logy,Conditions,Labels,first,last, UseYRange, YMin, YMax);
323 std::cout <<
"\n****************\nCreateTrend\n****************\n" << std::endl;
324 std::cout <<
"ListItems : " << ListItems << std::endl;
325 std::cout <<
"Conditions : " << Conditions << std::endl;
331 std::vector<DetIdItemList> vDetIdItemListCut;
339 std::cout <<
"firstRun " << firstRun <<
" lastRun " << lastRun << std::endl;
345 while((reference =
Iterator->next())) {
356 if(vDetIdItemListCut.size()){
357 for(
size_t ij=0;ij!=vDetIdItemListCut.size();++ij){
358 vDetIdItemListCut[ij].values=reference->
getSummaryObj(vDetIdItemListCut[ij].
detid, vDetIdItemListCut[ij].items);
372 std::cout << ListItems <<
" run " <<
vRun_.back() <<
" values \n" ;
374 for(
size_t i=0;
i<detiditemlist.
items.size();++
i) {
383 plot(nPads, CanvasName, logy, Labels, UseYRange, YMin, YMax);
387 std::cout <<
"\n****** Ignore this error *****\n" << std::endl;
389 std::cout <<
"\n******************************\n" << std::endl;
394 std::cout <<
"\n********\nplot\n*****\n"<< std::endl;
398 double *
X, *Y, *EX, *EY, *YCumul;
399 X=
new double[
vRun_.size()];
400 Y=
new double[
vRun_.size()];
401 EX=
new double[
vRun_.size()];
402 EY=
new double[
vRun_.size()];
403 YCumul=
new double[
vRun_.size()];
411 sprintf(name,
"%d",(
int) clock());
416 rootCName.replace(rootCName.find(
"."),rootCName.size()-rootCName.find(
"."),
"");
418 C=
new TCanvas(rootCName.c_str(),
"");
419 int ndiv=(int)
sqrt(nPads);
420 C->Divide(ndiv,nPads/ndiv+ (nPads%ndiv?1:0));
433 std::vector<TGraphErrors*> VectorOfGraphs;
434 std::vector<std::string> VectorOfDetNames;
443 std::stringstream
ss;
449 VectorOfDetNames.push_back(
"???" );
493 if (
j == 0 ) YCumul[
j] = Y[
j];
494 else YCumul[
j] = Y[
j] + YCumul[
j-1];
508 if (UseYRange != 0) {
509 for (
size_t iRun = 0; iRun !=
vRun_.size(); ++iRun) {
510 if (UseYRange % 2 == 1 && Y[iRun] < YMin) {
514 if (UseYRange >= 2 && Y[iRun] > YMax) {
521 graph =
new TGraphErrors((
int)
vRun_.size(),
X,Y,EX,EY);
524 for (
size_t ipt = 0; ipt !=
vRun_.size(); ++ipt) {
533 if( ((Y[ipt] == -10 || Y[ipt] == -9999 || Y[ipt] == -999 || Y[ipt] == -99) &&
fSkip99s) || (Y[ipt] == 0 &&
fSkip0s) ) {
537 graph->RemovePoint(iptTGraph);
547 graph->SetTitle(ss.str().c_str());
548 if (UseYRange % 2 == 1) {
549 graph->SetMinimum(YMin);
551 if (UseYRange >= 2) {
552 graph->SetMaximum(YMax);
556 graph->SetName(ss.str().c_str());
557 graph->GetXaxis()->SetTitle(
"Run number");
561 VectorOfGraphs.push_back(graph);
570 if (itemForIntegration)
572 std::stringstream ss2; std::stringstream ss3; std::stringstream ss4;
575 ss2 << title <<
"_Integral";
576 ss3 << title <<
"_Integrated.gif";
577 ss4 << title <<
"_Integrated.root";
579 TCanvas* C2 =
new TCanvas(ss2.str().c_str(),
"");
580 TGraphErrors* graph2 =
new TGraphErrors((
int)
vRun_.size(),
X,YCumul,EX,EX);
581 graph2->SetTitle(ss2.str().c_str());
582 graph2->SetMarkerColor(1);
584 graph2->SetName(ss2.str().c_str());
585 graph2->GetXaxis()->SetTitle(
"Run number");
588 C2->SaveAs(ss3.str().c_str());
589 C2->SaveAs(ss4.str().c_str());
596 C->SaveAs(CanvasName.c_str());
604 if (VectorOfGraphs.size() > 1) {
607 TLegend OverlayLegend(0.80,0.35,0.99,0.65);
614 TCanvas DeanCan(
"DeanCan",
"DeanCan");
615 TVirtualPad* VPad = DeanCan.cd();
616 VPad->SetRightMargin(0.21);
617 VPad->SetTopMargin(0.13);
620 TString
const LNames = Labels;
621 TObjArray* MyArrayPtr = LNames.Tokenize(
",");
623 MyArrayPtr->SetOwner(kTRUE);
624 for(
int i = 0;
i <= MyArrayPtr->GetLast(); ++
i ) {
625 if(
i <
int(VectorOfDetNames.size()) ) {
626 VectorOfDetNames[
i] = ((TObjString*) MyArrayPtr->At(
i) )->GetString().Data();
629 MyArrayPtr->Delete();
634 for (
size_t i = 0;
i != VectorOfGraphs.size(); ++
i) {
637 TString MyTitle = VectorOfGraphs[
i]->GetTitle();
638 std::cout <<
"dhidas " << MyTitle <<
" : " << VectorOfDetNames[
i] << std::endl;
639 MyTitle.ReplaceAll(VectorOfDetNames[
i]+
"_",
"");
640 MyTitle.ReplaceAll(
"_"+VectorOfDetNames[
i],
"");
641 MyTitle.ReplaceAll(VectorOfDetNames[i],
"");
642 std::cout <<
"dhidas " << MyTitle << std::endl;
643 VectorOfGraphs[
i]->SetTitle( MyTitle );
646 OverlayLegend.AddEntry(VectorOfGraphs[i], VectorOfDetNames[i].c_str(),
"p");
657 VectorOfGraphs[
i]->SetMarkerStyle(20+i);
658 VectorOfGraphs[
i]->SetMarkerColor(2+i);
661 VectorOfGraphs[0]->SetMinimum((min)-((max)-(min))/5.);
662 VectorOfGraphs[0]->SetMaximum((max)+((max)-(min))/5.);
663 if (UseYRange % 2 == 1) {
664 VectorOfGraphs[0]->SetMinimum(YMin);
666 if (UseYRange >= 2) {
667 VectorOfGraphs[0]->SetMaximum(YMax);
672 VectorOfGraphs[0]->Draw(
"Ap");
673 for (
size_t i = 1;
i != VectorOfGraphs.size(); ++
i) {
674 VectorOfGraphs[
i]->Draw(
"p");
676 OverlayLegend.Draw(
"same");
678 DeanCan.SaveAs(CanvasName.replace(CanvasName.find(
"."),CanvasName.size()-CanvasName.find(
"."),
"_Overlay.gif").c_str());
682 for (
size_t i = 0;
i != VectorOfGraphs.size(); ++
i) {
683 delete VectorOfGraphs[
i];
696 while( loc != std::string::npos ) {
697 setItems(ListItems.substr(oldloc,loc-oldloc));
699 loc=ListItems.find(
",", oldloc );
703 setItems(ListItems.substr(oldloc,loc-oldloc));
711 char delimiters[128]=
"><=+-*/&|() ";
712 char copyConditions[1024];
713 sprintf(copyConditions,
"%s",Conditions.c_str());
714 pch = strtok (copyConditions,delimiters);
719 detiditemlist.
detid=atol(itemD.substr(0,itemD.find(
fSep)).c_str());
720 detiditemlist.
items.push_back(itemD.substr(itemD.find(
fSep)+
fSep.size()));
722 std::cout <<
"Found a Condition " << detiditemlist.
items.back() <<
" for detId " << detiditemlist.
detid << std::endl;
725 if(vdetIdItemList.size())
726 if(vdetIdItemList.back().detid==detiditemlist.
detid)
727 vdetIdItemList.back().items.insert(vdetIdItemList.back().items.end(),detiditemlist.
items.begin(),detiditemlist.
items.end());
729 vdetIdItemList.push_back(detiditemlist);
731 vdetIdItemList.push_back(detiditemlist);
733 pch = strtok (
NULL,delimiters);
740 char cConditions[1024];
741 char singleCondition[1024];
744 sprintf(cConditions,
"%s",Conditions.c_str());
746 std::cout <<
"Conditions " << cConditions << std::endl;
748 for(
size_t ic=0;ic<vdetIdItemList.size();++ic)
749 for(
size_t jc=0;jc<vdetIdItemList[ic].items.size();++jc){
752 sprintf(condCVal,
"%f",vdetIdItemList[ic].
values[jc]);
753 sprintf(singleCondition,
"%d%s%s",vdetIdItemList[ic].
detid,
fSep.c_str(),vdetIdItemList[ic].items[jc].c_str());
756 char* fpos = strstr(cConditions,singleCondition);
758 strncpy(fpos,condCVal,strlen(condCVal));
759 memset(fpos+strlen(condCVal),
' ',strlen(singleCondition)-strlen(condCVal));
766 pch = strtok (cConditions,
" ");
768 stringToEvaluate.append(pch);
769 pch = strtok (
NULL,
" ");
776 std::cout <<
"Conditions After SubStitution " << stringToEvaluate << std::endl;
778 TFormula Formula(
"condition", stringToEvaluate.c_str());
779 resultdbl = Formula.Eval(0);
781 std::cout <<
"Result " << resultdbl << std::endl;
792 detiditemlist.
detid=atol(itemD.substr(0,itemD.find(
fSep)).c_str());
795 detiditemlist.
items.push_back(item);
798 std::cout <<
"Found new item " << detiditemlist.
items.back() <<
" for detid " << detiditemlist.
detid << std::endl;
800 if(item.find(
"mean")!=std::string::npos){
801 detiditemlist.
items.push_back(item.replace(item.find(
"mean"),4,
"rms"));
803 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
804 detiditemlist.
items.push_back(item.replace(item.find(
"rms"),3,
"entries"));
806 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
808 else if(item.find(
"landauPeak")!=std::string::npos){
809 detiditemlist.
items.push_back(item.replace(item.find(
"landauPeak"),10,
"landauPeakErr"));
811 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
813 else if(item.find(
"gaussMean")!=std::string::npos){
814 detiditemlist.
items.push_back(item.replace(item.find(
"gaussMean"),9,
"gaussSigma"));
816 std::cout <<
"Found new item " << detiditemlist.
items.back() << std::endl;
837 double*
y = g->GetY();
838 int locmax = TMath::LocMax(n,y);
848 double*
y = g->GetY();
849 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)
std::vector< float > getSummaryObj(uint32_t &detID, const std::vector< std::string > &list) const
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< 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_