File indexing completed on 2024-04-06 11:57:53
0001 #include <cstdlib>
0002 #include <cstdio>
0003 #include <fstream>
0004 #include <iostream>
0005 #include <assert.h>
0006 using namespace std;
0007
0008 #include <math.h>
0009 #include <TStyle.h>
0010
0011 #include "TImage.h"
0012 #include "TAttImage.h"
0013
0014 #include "MECanvasHolder.hh"
0015
0016 ClassImp(MECanvasHolder);
0017
0018 MECanvasHolder::MECanvasHolder()
0019 : fCanvas(0), fWelcomePave(0), fWelcomeState(true), fWelcomeTitle(0), fWelcomeL0(0), _h(0), _scale(1), _refw(1092) {}
0020
0021 MECanvasHolder::~MECanvasHolder() { ClearWelcome(); }
0022
0023 void MECanvasHolder::CanvasModified() {
0024
0025 TPad* pad = (TPad*)gPad;
0026 fCanvas->cd();
0027 fCanvas->Modified();
0028 fCanvas->Update();
0029 pad->cd();
0030 }
0031
0032 void MECanvasHolder::ClearWelcome() {
0033 if (fWelcomePave) {
0034 delete fWelcomePave;
0035 fWelcomePave = 0;
0036 gPad->Clear();
0037 }
0038 }
0039
0040 void MECanvasHolder::SetCanvas(
0041 TCanvas* canvas, const char* textTL, const char* textBL, const char* textTR, const char* textBR) {
0042 assert(canvas != 0);
0043
0044 fCanvas = canvas;
0045 fCanvas->Clear();
0046 fTopXGen = fCanvas->GetWindowTopX();
0047 fTopYGen = fCanvas->GetWindowTopY();
0048
0049
0050 fWidthGen = fCanvas->GetWw();
0051 fHeigthGen = fCanvas->GetWh();
0052
0053
0054
0055 if (fWidthGen != 0) {
0056 _scale = fWidthGen / _refw;
0057 }
0058 _scale = 1;
0059
0060
0061 Color_t fColCan = 45;
0062 Style_t fStyleCan = 1001;
0063 Color_t fStyleHistColor = 45;
0064 Color_t fStyleTitleColor = 1;
0065 Color_t fStyleTFColor = 191;
0066 Color_t fStyleTTextColor = 1;
0067 Style_t fStylePad1 = 1001;
0068 Int_t fPadLogX = 0;
0069 Int_t fPadLogY = 0;
0070 Color_t fColFrame = 18;
0071 Color_t fColPad1 = 30;
0072
0073 TString fStringTL(textTL);
0074 TString fStringBL(
0075 textBL);
0076 TString fStringTR(textTR);
0077 TString fStringBR(textBR);
0078
0079 double fXTexTL = 0.02;
0080 double fYTexTL = 0.975;
0081 double fXTexBL = 0.02;
0082 double fYTexBL = 0.01;
0083 double fXTexBR = 0.65;
0084 double fYTexBR = 0.01;
0085 double fXTexTR = 0.65;
0086 double fYTexTR = 0.975;
0087
0088 Font_t fFontTex = 132;
0089 Float_t fSizeTex = 0.02;
0090
0091 Short_t fBszCan = 4;
0092 Short_t fBszPad = 6;
0093 Width_t fWidthTex = 2;
0094
0095 double fEmptyX = _scale * 0.005;
0096 double fEmptyY = _scale * 0.03;
0097 double wpad = _scale * 0.5 * (1.0 - 4 * fEmptyX);
0098 double fXLowPad1 = fEmptyX;
0099 double fXUpPad1 = fXLowPad1 + wpad;
0100 double fXLowPad2 = fXUpPad1 + 2 * fEmptyX;
0101 double fXUpPad2 = fXLowPad2 + wpad;
0102 double fYLowPad = fEmptyY;
0103 double fYUpPad = 1.0 - fEmptyY;
0104
0105 fCanvas->SetEditable();
0106 fCanvas->Range(0, 0, 1, 1);
0107 fCanvas->SetFillColor(fColCan);
0108 fCanvas->SetFillStyle(fStyleCan);
0109 fCanvas->SetBorderSize(fBszCan);
0110 gStyle->SetOptStat(1111);
0111 gStyle->SetStatFont(22);
0112 gStyle->SetStatColor(18);
0113 if (fHeigthGen >= 700) {
0114 gStyle->SetStatH(0.1);
0115 gStyle->SetTitleSize(0.01);
0116 } else {
0117 gStyle->SetStatH(_scale * 0.15);
0118 gStyle->SetTitleSize(_scale * 0.015);
0119 }
0120 gStyle->SetTitleFillColor(fStyleTFColor);
0121 gStyle->SetTitleTextColor(fStyleTTextColor);
0122 gStyle->SetTitleW(_scale * 0.76);
0123 gStyle->SetHistFillColor(fStyleHistColor);
0124 gStyle->SetTitleFont(22);
0125 gStyle->SetTitleColor(173);
0126 gStyle->SetTitleFillColor(18);
0127 gStyle->SetTitleColor(fStyleTitleColor);
0128 gStyle->SetTitleTextColor(46);
0129 gStyle->SetLabelSize(_scale * 0.02, "XYZ");
0130
0131 fTexTL = new TLatex(fXTexTL, fYTexTL, fStringTL.Data());
0132 fTexTR = new TLatex(fXTexTR, fYTexTR, fStringTR.Data());
0133 fTexBL = new TLatex(fXTexBL, fYTexBL, fStringBL.Data());
0134 fTexBR = new TLatex(fXTexBR, fYTexBR, fStringBR.Data());
0135
0136
0137 fTexTL->SetTextFont(fFontTex);
0138 fTexTL->SetTextSize(fSizeTex);
0139 fTexTL->SetLineWidth(fWidthTex);
0140 fTexBL->SetTextFont(fFontTex);
0141 fTexBL->SetTextSize(fSizeTex);
0142 fTexBL->SetLineWidth(fWidthTex);
0143 fTexBR->SetTextFont(fFontTex);
0144 fTexBR->SetTextSize(fSizeTex);
0145 fTexBR->SetLineWidth(fWidthTex);
0146 fTexTR->SetTextFont(fFontTex);
0147 fTexTR->SetTextSize(fSizeTex);
0148 fTexTR->SetLineWidth(fWidthTex);
0149 fCanvas->cd();
0150 fTexTL->Draw();
0151 fTexBL->Draw();
0152 fTexBR->Draw();
0153 fTexTR->Draw();
0154
0155
0156 fCanvas->cd();
0157 fPad = new TPad("LeftPad", "Left pad", fXLowPad1, fYLowPad, fXUpPad2, fYUpPad);
0158 fPad->SetNumber(1);
0159 fPad->SetFillColor(fColPad1);
0160 fPad->SetFillStyle(fStylePad1);
0161 fPad->SetBorderSize(fBszPad);
0162 fPad->SetGridx();
0163 fPad->SetGridy();
0164 fPad->SetLogx(fPadLogX);
0165 fPad->SetLogy(fPadLogY);
0166 fPad->SetFrameFillColor(fColFrame);
0167 fPad->SetFillStyle(fStylePad1);
0168 fPad->Draw();
0169 fPad->cd();
0170
0171 setSessionStyle();
0172 ShowWelcome(false);
0173 }
0174
0175 void MECanvasHolder::ShowWelcome(bool image) {
0176 gPad->Clear();
0177 if (image) {
0178 TString imgpath = TString(std::getenv("MECONFIG"));
0179 TImage* img = TImage::Open(imgpath + "/LVB.jpg");
0180 assert(img != 0);
0181
0182 TText* ttext1 = new TText(450, 500, "MusEcal");
0183 ttext1->SetTextSize(0.5);
0184 ttext1->SetTextColor(kRed);
0185 ttext1->SetTextFont(62);
0186 img->SetImageQuality(TAttImage::kImgBest);
0187 img->DrawText(ttext1, 450, 500);
0188 TText* ttext2 = new TText(450, 800, "ECAL Laser Monitoring");
0189 ttext2->SetTextSize(0.3);
0190 ttext2->SetTextColor(kRed);
0191 ttext2->SetTextFont(62);
0192 img->DrawText(ttext2, 450, 800);
0193 img->Draw("xxx");
0194 img->SetEditable(kTRUE);
0195 }
0196 gPad->Modified();
0197 gPad->Update();
0198 }
0199
0200 void MECanvasHolder::setSessionStyle() {
0201
0202 gStyle->SetFrameBorderMode(0);
0203 gStyle->SetCanvasBorderMode(0);
0204 gStyle->SetPadBorderMode(0);
0205 gStyle->SetPadColor(0);
0206 gStyle->SetCanvasColor(0);
0207 gStyle->SetTitleBorderSize(0);
0208
0209
0210
0211
0212
0213 gStyle->SetPaperSize(20, 26);
0214
0215 gStyle->SetPadTopMargin(_scale * 0.10);
0216 gStyle->SetPadRightMargin(_scale * 0.165);
0217 gStyle->SetPadBottomMargin(_scale * 0.15);
0218 gStyle->SetPadLeftMargin(_scale * 0.135);
0219
0220
0221 gStyle->SetTextFont(132);
0222 gStyle->SetTextSize(0.08);
0223 gStyle->SetLabelFont(132, "x");
0224 gStyle->SetLabelFont(132, "y");
0225 gStyle->SetLabelFont(132, "z");
0226 gStyle->SetTitleFont(132, "x");
0227 gStyle->SetTitleFont(132, "y");
0228 gStyle->SetTitleFont(132, "z");
0229 gStyle->SetTitleFont(132);
0230 gStyle->SetLabelSize(_scale * 0.05, "x");
0231 gStyle->SetLabelOffset(_scale * 0.01, "x");
0232 gStyle->SetTitleOffset(_scale * 1, "x");
0233 gStyle->SetTitleSize(_scale * 0.06, "x");
0234 gStyle->SetLabelSize(_scale * 0.05, "y");
0235 gStyle->SetLabelOffset(_scale * 0.01, "y");
0236 gStyle->SetTitleSize(_scale * 0.06, "y");
0237 gStyle->SetTitleOffset(_scale * 1, "y");
0238 gStyle->SetLabelSize(_scale * 0.05, "z");
0239 gStyle->SetLabelOffset(_scale * 0.01, "z");
0240 gStyle->SetTitleSize(_scale * 0.06, "z");
0241 gStyle->SetTitleOffset(_scale * 1, "z");
0242
0243
0244
0245 gStyle->SetHistLineWidth(2);
0246 gStyle->SetLineStyleString(2, "[12 12]");
0247
0248
0249
0250 gStyle->SetOptStat(111111);
0251 gStyle->SetOptFit(0);
0252
0253
0254
0255
0256
0257
0258
0259 gStyle->SetPalette(1);
0260
0261
0262 const int ncol = 60;
0263 gStyle->SetNumberContours(ncol);
0264
0265 fCanvas->SetFillColor(kYellow);
0266 fCanvas->SetGridx(0);
0267 fCanvas->SetGridx(1);
0268
0269 fPad->SetFillColor(kWhite);
0270 fPad->SetGridx(0);
0271 fPad->SetGridy(0);
0272 fPad->SetCrosshair(0);
0273 fPad->SetFrameFillColor(kWhite);
0274 }
0275
0276 void MECanvasHolder::setHistoStyle(TH1* h) {
0277 if (h == 0)
0278 return;
0279
0280 h->SetLineColor(4);
0281 h->SetLineWidth(1);
0282 h->SetFillColor(38);
0283 TAxis* axis[3];
0284 axis[0] = h->GetXaxis();
0285 axis[1] = h->GetYaxis();
0286 axis[2] = h->GetZaxis();
0287 for (int ii = 0; ii < 3; ii++) {
0288 TAxis* a = axis[ii];
0289 if (!a)
0290 continue;
0291 a->SetLabelFont(132);
0292 a->SetLabelOffset(0.005);
0293 a->SetLabelSize(0.04);
0294 a->SetTitleFont(132);
0295 a->SetTitleOffset(1);
0296 a->SetTitleSize(0.04);
0297 }
0298 h->SetStats(kTRUE);
0299 }
0300
0301 void MECanvasHolder::SetDate() {
0302
0303 const Int_t cent = 100;
0304 Int_t date, time;
0305 Int_t day, month, year;
0306 Int_t hour, minute, second;
0307 TDatime td;
0308 date = td.GetDate();
0309 time = td.GetTime();
0310
0311 day = date % cent;
0312 date /= cent;
0313 month = date % cent;
0314 date /= cent;
0315 year = date;
0316 second = time % cent;
0317 time /= cent;
0318 minute = time % cent;
0319 time /= cent;
0320 hour = time;
0321
0322 fDate = " ";
0323 fDate += day;
0324 fDate.Append(" / ");
0325 fDate += month;
0326 fDate.Append(" / ");
0327 fDate += year;
0328 fDate.Append(" ");
0329
0330 fTime = "";
0331 fTime += hour;
0332 fTime.Append('_');
0333 fTime += minute;
0334 }
0335
0336 void MECanvasHolder::setPxAndPy(int px, int py) {
0337 _px = px;
0338 _py = py;
0339 _x = 0;
0340 _y = 0;
0341 if (_h != 0) {
0342 TString objectInfo;
0343 objectInfo = _h->GetObjectInfo(_px, _py);
0344
0345
0346
0347
0348
0349
0350 int istart1 = objectInfo.Index("(x=");
0351 int iend1 = istart1 + 3;
0352 int istart2 = objectInfo.Index(", y=");
0353 int iend2 = istart2 + 4;
0354 int istart3 = objectInfo.Index(", binx=");
0355
0356 _x = TString(objectInfo(iend1, istart2 - iend1)).Atof();
0357 _y = TString(objectInfo(iend2, istart3 - iend2)).Atof();
0358
0359
0360 }
0361 }
0362
0363 void MECanvasHolder::setPad() {
0364 if (fPad == 0)
0365 return;
0366 fPad->cd();
0367 }
0368
0369 void MECanvasHolder::setHessPalette() {
0370 const int nfix = 5;
0371
0372 const float Pi = acos(-1.);
0373
0374 const int ninter = 10;
0375 int nstep = ninter + 1;
0376 double step = Pi / nstep;
0377
0378 const int ncoltot = (nfix - 1) * ninter + nfix;
0379
0380 TColor* myCol;
0381 Int_t palette[ncoltot];
0382 for (int i = 0; i < ncoltot; i++)
0383 palette[i] = 1;
0384
0385
0386 int colfix[nfix] = {1, 4, 2, 5, 10};
0387
0388 int colOff7 = 4300;
0389 int icol = colOff7;
0390
0391 float red, green, blue;
0392
0393 int ifix = 0;
0394 for (int ii = 0; ii < nfix; ii++) {
0395 TString myColName("myHessCol_");
0396 myColName += icol;
0397 TColor* theCol = (TColor*)gROOT->GetColor(colfix[ii]);
0398 theCol->GetRGB(red, green, blue);
0399 myCol = new TColor(icol, red, green, blue, myColName);
0400 cout << "ifix " << ifix << " r/g/b " << red << "/" << green << "/" << blue << endl;
0401 palette[ifix] = icol++;
0402 ifix += nstep;
0403 }
0404
0405 float r1, g1, b1;
0406 float r2, g2, b2;
0407 int ifix1 = 0;
0408 int ifix2 = 0;
0409 for (int ii = 0; ii < nfix - 1; ii++) {
0410 ifix2 = ifix1 + nstep;
0411
0412 int icol1 = palette[ifix1];
0413 int icol2 = palette[ifix2];
0414 TColor* col1 = gROOT->GetColor(icol1);
0415 col1->Print();
0416 col1->GetRGB(r1, g1, b1);
0417 TColor* col2 = gROOT->GetColor(icol2);
0418 col2->Print();
0419 col2->GetRGB(r2, g2, b2);
0420
0421 ifix = ifix1;
0422 double x = -Pi / 2.;
0423 for (int istep = 0; istep < ninter; istep++) {
0424 x += step;
0425 ifix++;
0426
0427 double sinx = sin(x);
0428 red = 0.5 * ((r2 - r1) * sinx + (r1 + r2));
0429 green = 0.5 * ((g2 - g1) * sinx + (g1 + g2));
0430 blue = 0.5 * ((b2 - b1) * sinx + (b1 + b2));
0431
0432 TString myColName("myHessCol_");
0433 myColName += icol;
0434 myCol = new TColor(icol, red, green, blue, myColName);
0435 cout << "ifix " << ifix << " r/g/b " << red << "/" << green << "/" << blue << endl;
0436 palette[ifix] = icol++;
0437 }
0438
0439 ifix1 = ifix2;
0440 }
0441
0442 gStyle->SetPalette(ncoltot, palette);
0443 }