Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:00

0001 #include <fstream>
0002 #include <math.h>
0003 #include <algorithm>
0004 #include <cassert>
0005 
0006 #include <TMath.h>
0007 
0008 #include "Riostream.h"
0009 #include "TSystem.h"
0010 #include "TDatime.h"
0011 #include "TApplication.h"
0012 #include "TStyle.h"
0013 #include "TColor.h"
0014 #include "TF1.h"
0015 #include "TPad.h"
0016 #include "TMarker.h"
0017 #include "TFrame.h"
0018 #include "TGResourcePool.h"
0019 #include "TGCanvas.h"
0020 #include "TGraphErrors.h"
0021 #include "TText.h"
0022 #include "TImage.h"
0023 #include "TAttImage.h"
0024 
0025 #include "MusEcalGUI.hh"
0026 #include "../../interface/MEGeom.h"
0027 #include "MEVarVector.hh"
0028 #include "MEEBDisplay.hh"
0029 #include "MEEEDisplay.hh"
0030 #include "MEPlotWindow.hh"
0031 #include "MERunPanel.hh"
0032 #include "MEChanPanel.hh"
0033 #include "MELeafPanel.hh"
0034 #include "MEMultiVarPanel.hh"
0035 #include "MERun.hh"
0036 #include "MERunManager.hh"
0037 #include "../../interface/MEChannel.h"
0038 
0039 ClassImp(MusEcalGUI);
0040 
0041 MusEcalGUI::MusEcalGUI(const TGWindow* p, UInt_t w, UInt_t h, int type, int color)
0042     : TGMainFrame(p, w, h), MECanvasHolder(), MusEcal(type, color) {
0043   // init
0044   _isGUI = true;
0045   _debug = false;
0046   _ihtype = iMAP;
0047   _icateg = 0;
0048   _ihist = ME::iAPD_MEAN;
0049   _normalize = false;
0050   _historyType = iHistoryVsTime;
0051   _fRunPanel = 0;
0052   _fChanPanel = 0;
0053   _fLeafPanel = 0;
0054   _fMultiVarPanel = 0;
0055   _psdir = TString(std::getenv("MEPSDIR")) + "/";
0056 
0057   // layouts and menus
0058   cout << "Setup main window" << endl;
0059   setupMainWindow();
0060   cout << "done." << endl;
0061 
0062   // create the run panel
0063   cout << "Create Run panel" << endl;
0064   createRunPanel();
0065   cout << "done." << endl;
0066 
0067   // configure and book histograms
0068   cout << "Configure histograms" << endl;
0069   histConfig();
0070   cout << "done." << endl;
0071 
0072   cout << "Book histograms" << endl;
0073   bookHistograms();
0074   cout << "done." << endl;
0075 
0076   // fill histograms
0077   cout << "Fill histograms" << endl;
0078   fillHistograms();
0079   cout << "done." << endl;
0080 
0081   // default drawings
0082 
0083   cout << "Default drawings" << endl;
0084   drawHist(1);
0085   //  historyPlot(true);
0086   //  leafPlot(1);
0087   cout << "done." << endl;
0088 }
0089 
0090 // get vectors -- version with std::vectors
0091 bool MusEcalGUI::getTimeVector(vector<ME::Time>& time) {
0092   if (_leaf == 0)
0093     return false;
0094   time.clear();
0095   MEVarVector* apdVector_ = curMgr()->apdVector(_leaf);
0096   apdVector_->getTime(time);
0097   return true;
0098 }
0099 
0100 bool MusEcalGUI::getHistoryVector(vector<ME::Time>& time,
0101                                   vector<float>& val,
0102                                   vector<bool>& flag,
0103                                   vector<float>& eval,
0104                                   bool& b_,
0105                                   float& miny,
0106                                   float& maxy) {
0107   if (_leaf == 0) {
0108     cout << "Please select a channel first " << endl;
0109     return false;
0110   }
0111   int ig_;
0112   TString varName_;
0113   TString str_, str0_;
0114   if (_type == ME::iLaser) {
0115     ig_ = MusEcal::iGVar[_var];
0116     varName_ = MusEcal::historyVarName[_var];
0117   } else if (_type == ME::iTestPulse) {
0118     ig_ = MusEcal::iGTPVar[_var];
0119     varName_ = MusEcal::historyTPVarName[_var];
0120   } else
0121     return false;
0122   MEChannel* leaf_ = _leaf;
0123   if (ig_ < _ig) {
0124     leaf_ = _leaf->getAncestor(ig_);
0125   }
0126   //  cout << "History plot for var=" << varName_
0127   //       << " and channel " << leaf_->oneLine() << endl;
0128 
0129   MEChannel* pnleaf_ = _leaf;
0130   MEChannel* mtqleaf_ = _leaf;
0131   if (_leaf->ig() > ME::iLMModule) {
0132     while (pnleaf_->ig() != ME::iLMModule) {
0133       pnleaf_ = pnleaf_->m();
0134     }
0135   }
0136   if (_leaf->ig() > ME::iLMRegion) {
0137     while (mtqleaf_->ig() != ME::iLMRegion) {
0138       mtqleaf_ = mtqleaf_->m();
0139     }
0140   }
0141 
0142   val.clear();
0143   eval.clear();
0144   flag.clear();
0145   vector<float> rms;
0146   vector<float> nevt;
0147   vector<bool> flag_;
0148   b_ = true;
0149   miny = 999999;
0150   maxy = -999999;
0151 
0152   getTimeVector(time);
0153   MEVarVector* apdVector_ = curMgr()->apdVector(leaf_);
0154   MEVarVector* pnaVector_ = curMgr()->pnVector(pnleaf_, 0);
0155   MEVarVector* pnbVector_ = curMgr()->pnVector(pnleaf_, 1);
0156   MEVarVector* mtqVector_ = curMgr()->mtqVector(mtqleaf_);
0157 
0158   if (_type == ME::iLaser) {
0159     TString str0_("APD-"), str1_("PN-");
0160     if (_var == MusEcal::iNLS) {
0161       cout << varName_ << ": not implemented yet" << endl;
0162       return false;
0163     } else if (_var == MusEcal::iCorNLS) {
0164       cout << varName_ << ": not implemented yet" << endl;
0165       return false;
0166     } else if (_var == MusEcal::iAPD) {
0167       apdVector_->getValAndFlag(ME::iAPD_RMS, time, rms, flag_);
0168       apdVector_->getValAndFlag(ME::iAPD_MEAN, time, val, flag);
0169       str_ = str0_ + ME::APDPrimVar[ME::iAPD_MEAN];
0170       if (hist_nbin(str_) != 0) {
0171         b_ = false;
0172         miny = hist_min(str_);
0173         maxy = hist_max(str_);
0174       }
0175     } else if (_var == MusEcal::iAPDTime) {
0176       apdVector_->getValAndFlag(ME::iAPD_TIME_RMS, time, rms, flag_);
0177       apdVector_->getValAndFlag(ME::iAPD_TIME_MEAN, time, val, flag);
0178       TString str_ = str0_ + ME::APDPrimVar[ME::iAPD_TIME_MEAN];
0179       if (hist_nbin(str_) != 0) {
0180         b_ = false;
0181         miny = hist_min(str_);
0182         maxy = hist_max(str_);
0183       }
0184     } else if (_var == MusEcal::iAPDoPNA) {
0185       apdVector_->getValAndFlag(ME::iAPD_OVER_PNA_MEAN, time, val, flag);
0186       apdVector_->getValAndFlag(ME::iAPD_OVER_PNA_RMS, time, rms, flag);
0187       TString str_ = str0_ + ME::APDPrimVar[ME::iAPD_OVER_PNA_MEAN];
0188       if (hist_nbin(str_) != 0) {
0189         b_ = false;
0190         miny = hist_min(str_);
0191         maxy = hist_max(str_);
0192       }
0193     } else if (_var == MusEcal::iAPDoPNB) {
0194       apdVector_->getValAndFlag(ME::iAPD_OVER_PNB_MEAN, time, val, flag);
0195       apdVector_->getValAndFlag(ME::iAPD_OVER_PNB_RMS, time, rms, flag);
0196       TString str_ = str0_ + ME::APDPrimVar[ME::iAPD_OVER_PNB_MEAN];
0197       if (hist_nbin(str_) != 0) {
0198         b_ = false;
0199         miny = hist_min(str_);
0200         maxy = hist_max(str_);
0201       }
0202     } else if (_var == MusEcal::iAPDoPN) {
0203       apdVector_->getValAndFlag(ME::iAPD_OVER_PN_MEAN, time, val, flag);
0204       apdVector_->getValAndFlag(ME::iAPD_OVER_PN_RMS, time, rms, flag);
0205       TString str_ = str0_ + ME::APDPrimVar[ME::iAPD_OVER_PN_MEAN];
0206       if (hist_nbin(str_) != 0) {
0207         b_ = false;
0208         miny = hist_min(str_);
0209         maxy = hist_max(str_);
0210       }
0211     } else if (_var == MusEcal::iPNA) {
0212       pnaVector_->getValAndFlag(ME::iPN_MEAN, time, val, flag);
0213       pnaVector_->getValAndFlag(ME::iPN_RMS, time, rms, flag);
0214       //      TString str_=str1_+ME::PNPrimVar[ME::iPN_MEAN];
0215     } else if (_var == MusEcal::iPNB) {
0216       pnbVector_->getValAndFlag(ME::iPN_MEAN, time, val, flag);
0217       pnbVector_->getValAndFlag(ME::iPN_RMS, time, rms, flag);
0218     } else if (_var == MusEcal::iPNBoPNA) {
0219       pnaVector_->getValAndFlag(ME::iPNA_OVER_PNB_MEAN, time, val, flag);
0220       //      TString str_=str1_+ME::PNPrimVar[ME::iPN_MEAN];
0221     } else if (_var == MusEcal::iAlphaBeta) {
0222       vector<float> alpha_, beta_;
0223       vector<bool> flaga_, flagb_;
0224       apdVector_->getValAndFlag(ME::iAPD_ALPHA, time, alpha_, flaga_);
0225       apdVector_->getValAndFlag(ME::iAPD_BETA, time, beta_, flagb_);
0226       for (unsigned int iab = 0; iab < time.size(); iab++) {
0227         val.push_back(alpha_[iab] * beta_[iab]);
0228         flag.push_back(flaga_[iab] && flagb_[iab]);
0229       }
0230     } else if (_var == MusEcal::iAlphaBeta_used) {
0231       cout << varName_ << ": not implemented" << endl;
0232       return false;
0233     } else if (_var == MusEcal::iShapeCor) {
0234       cout << varName_ << ": not implemented yet" << endl;
0235       return false;
0236     } else if (_var == MusEcal::iMTQTrise) {
0237       mtqVector_->getValAndFlag(ME::iMTQ_RISE, time, val, flag);
0238       TString str_ = str0_ + ME::MTQPrimVar[ME::iMTQ_RISE];
0239       if (hist_nbin(str_) != 0) {
0240         b_ = false;
0241         miny = hist_min(str_);
0242         maxy = hist_max(str_);
0243       }
0244 
0245       //cout << varName_ << ": not implemented yet" << endl;
0246       //return false;
0247     } else if (_var == MusEcal::iMTQAmpl) {
0248       mtqVector_->getValAndFlag(ME::iMTQ_AMPL, time, val, flag);
0249       TString str_ = str0_ + ME::MTQPrimVar[ME::iMTQ_AMPL];
0250       if (hist_nbin(str_) != 0) {
0251         b_ = false;
0252         miny = hist_min(str_);
0253         maxy = hist_max(str_);
0254       }
0255 
0256       //cout << varName_ << ": not implemented yet" << endl;
0257       //return false;
0258 
0259     } else if (_var == MusEcal::iMTQFwhm) {
0260       mtqVector_->getValAndFlag(ME::iMTQ_FWHM, time, val, flag);
0261       TString str_ = str0_ + ME::MTQPrimVar[ME::iMTQ_AMPL];
0262       if (hist_nbin(str_) != 0) {
0263         b_ = false;
0264         miny = hist_min(str_);
0265         maxy = hist_max(str_);
0266       }
0267       // cout << varName_ << ": not implemented yet" << endl;
0268       //return false;
0269     } else if (_var == MusEcal::iMTQFw20) {
0270       mtqVector_->getValAndFlag(ME::iMTQ_FW20, time, val, flag);
0271       TString str_ = str0_ + ME::MTQPrimVar[ME::iMTQ_AMPL];
0272       if (hist_nbin(str_) != 0) {
0273         b_ = false;
0274         miny = hist_min(str_);
0275         maxy = hist_max(str_);
0276       }
0277       //cout << varName_ << ": not implemented yet" << endl;
0278       //return false;
0279     } else if (_var == MusEcal::iMTQFw80) {
0280       mtqVector_->getValAndFlag(ME::iMTQ_FW80, time, val, flag);
0281       TString str_ = str0_ + ME::MTQPrimVar[ME::iMTQ_AMPL];
0282       if (hist_nbin(str_) != 0) {
0283         b_ = false;
0284         miny = hist_min(str_);
0285         maxy = hist_max(str_);
0286       }
0287       //cout << varName_ << ": not implemented yet" << endl;
0288       //return false;
0289     } else if (_var == MusEcal::iMTQTime) {
0290       mtqVector_->getValAndFlag(ME::iMTQ_TIME, time, val, flag);
0291       TString str_ = str0_ + ME::MTQPrimVar[ME::iMTQ_AMPL];
0292       if (hist_nbin(str_) != 0) {
0293         b_ = false;
0294         miny = hist_min(str_);
0295         maxy = hist_max(str_);
0296       }
0297       //      cout << varName_ << ": not implemented yet" << endl;
0298       //return false;
0299     }
0300   } else if (_type == ME::iTestPulse) {
0301     TString str0_("TPAPD-"), str1_("TPPN-");
0302     if (_var == MusEcal::iTPAPD_0) {
0303       cout << varName_ << ": not implemented yet" << endl;
0304       return false;
0305     } else if (_var == MusEcal::iTPAPD_1) {
0306       cout << varName_ << ": not implemented yet" << endl;
0307       return false;
0308     } else if (_var == MusEcal::iTPAPD_2) {
0309       cout << varName_ << ": not implemented yet" << endl;
0310       return false;
0311     }
0312     if (_var == MusEcal::iTPPNA_0) {
0313       cout << varName_ << ": not implemented yet" << endl;
0314       return false;
0315     } else if (_var == MusEcal::iTPPNA_1) {
0316       cout << varName_ << ": not implemented yet" << endl;
0317       return false;
0318     }
0319     if (_var == MusEcal::iTPPNB_0) {
0320       cout << varName_ << ": not implemented yet" << endl;
0321       return false;
0322     } else if (_var == MusEcal::iTPPNB_1) {
0323       cout << varName_ << ": not implemented yet" << endl;
0324       return false;
0325     }
0326   }
0327 
0328   assert(val.size() == time.size());
0329   assert(flag.size() == time.size());
0330   if (eval.size() == 0 && rms.size() != 0) {
0331     assert(rms.size() == time.size());
0332     for (unsigned int itime = 0; itime < time.size(); itime++) {
0333       float eval_ = 100000.;
0334       if (nevt.size() == time.size()) {
0335         float nevt_ = nevt[itime];
0336         if (nevt_ > 0)
0337           eval_ = rms[itime] / sqrt(nevt_);
0338       } else {
0339         eval_ = rms[itime];
0340       }
0341       eval.push_back(eval_);
0342     }
0343   }
0344   return true;
0345 }
0346 
0347 // get vectors -- version with C-style vectors
0348 bool MusEcalGUI::getHistoryVector(
0349     unsigned int& nrun, float* x, float* y, float* ex, float* ey, bool* ok, float& normy, float& miny, float& maxy) {
0350   vector<ME::Time> time;
0351   vector<float> val;
0352   vector<float> eval;
0353   vector<bool> flag;
0354   miny = 999999;
0355   maxy = -999999;
0356   bool b_(true);
0357   bool ok_ = getHistoryVector(time, val, flag, eval, b_, miny, maxy);
0358   if (!ok_)
0359     return false;
0360 
0361   nrun = time.size();
0362   if (nrun < 2) {
0363     cout << "Not enough runs for an history plot, nrun=" << nrun << endl;
0364     return false;
0365   }
0366 
0367   normy = 0;
0368   int ngood_ = 0;
0369   for (unsigned int irun = 0; irun < nrun; irun++) {
0370     float dt_ = ME::timeDiff(time[irun], _time, ME::iHour);
0371     float val_ = val[irun];
0372     bool flag_ = flag[irun];
0373     float eval_ = 0.;
0374     if (eval.size() == time.size())
0375       eval_ = eval[irun];
0376     x[irun] = dt_;
0377     y[irun] = val_;
0378     ex[irun] = 0;
0379     ey[irun] = eval_;
0380     ok[irun] = flag_;
0381     if (flag_) {
0382       ngood_++;
0383       normy += val_;
0384     }
0385     if (b_) {
0386       if (val_ > maxy)
0387         maxy = val_;
0388       if (val_ < miny)
0389         miny = val_;
0390     }
0391   }
0392   if (b_)
0393     maxy *= 1.2;
0394   if (ngood_ > 0)
0395     normy /= ngood_;
0396   return true;
0397 }
0398 
0399 void MusEcalGUI::historyPlot(int opt) {
0400   TString WName_ = "History";
0401   MEPlotWindow* win_ = getWindow(WName_, opt, 800, 450);
0402   if (win_ == 0)
0403     return;
0404   _curPad = win_->getPad();
0405   _curPad->cd();
0406 
0407   unsigned int nrun = 1000;
0408   float x[nrun];
0409   float y[nrun];
0410   float ex[nrun];
0411   float ey[nrun];
0412   bool ok[nrun];
0413   float miny;
0414   float maxy;
0415   float normy;
0416   if (!getHistoryVector(nrun, x, y, ex, ey, ok, normy, miny, maxy))
0417     return;
0418 
0419   float minx = x[0];
0420   float maxx = x[nrun - 1];
0421   float rangex = maxx - minx;
0422   minx -= 0.05 * rangex;
0423   maxx += 0.05 * rangex;
0424 
0425   if (_normalize) {
0426     assert(normy != 0);
0427     for (unsigned ii = 0; ii < nrun; ii++) {
0428       y[ii] /= normy;
0429       ey[ii] /= normy;
0430     }
0431     miny /= normy;
0432     maxy /= normy;
0433   }
0434 
0435   TString titleX;
0436   TString titleY;
0437   TString titleM;
0438   TString titleW;
0439   titleW = ME::type[_type];
0440   if (_type == ME::iLaser) {
0441     titleW += ".";
0442     titleW += ME::color[_color];
0443     titleW += ".";
0444     titleW += MusEcal::historyVarName[_var];
0445     titleY = MusEcal::historyVarName[_var];
0446   } else if (_type == ME::iTestPulse) {
0447     titleW += ".";
0448     titleW += MusEcal::historyTPVarName[_var];
0449     titleY = MusEcal::historyTPVarName[_var];
0450   }
0451   titleW += ".";
0452   titleW += _leaf->oneWord();
0453   titleW += ".";
0454   MERun* run_ = _runMgr.begin()->second->curRun();
0455   //  assert( run_!=0 );
0456   if (run_ == 0) {
0457     cout << "Warning -- no run available ";
0458     return;
0459   }
0460   titleW += run_->rundir();
0461 
0462   if (_normalize)
0463     titleW += ".normalized";
0464   titleM = titleW;
0465   titleM.ReplaceAll(".", " ");
0466   titleW += ".history";
0467 
0468   if (_historyType == iHistoryVsTime) {
0469     titleW += ".vs.time";
0470 
0471     TString GraphOpt("LPSame");
0472     titleX = "time (in hours, relative to current run)";
0473 
0474     //  float xcur;
0475     float markerSize = 0;
0476     int markerStyle = 1;
0477     int markerColor = kBlack;
0478     int lineWidth = 1;
0479     int lineColor = kBlue;
0480 
0481     int ncol = gStyle->GetNumberOfColors();
0482 
0483     vector<TMarker*> markers;
0484     for (unsigned ii = 0; ii < nrun; ii++) {
0485       float f = float(ii) / float(nrun);
0486       int jj = (int)(f * ncol);
0487       if (jj < 1)
0488         jj = 1;
0489       int icol = gStyle->GetColorPalette(jj);
0490       int mstyle;
0491       if (ok[ii]) {
0492         mstyle = 20;
0493       } else {
0494         mstyle = 24;
0495       }
0496 
0497       TMarker* marker = new TMarker(x[ii], y[ii], mstyle);
0498 
0499       marker->SetMarkerSize(0.8);
0500       marker->SetMarkerColor(icol);
0501       markers.push_back(marker);
0502     }
0503 
0504     TH1* hdum = (TH1*)gROOT->FindObject("href");
0505     if (hdum != 0)
0506       delete hdum;
0507     TH1* _href = new TH1F("href", "href", 100, minx, maxx);
0508 
0509     setHistoStyle(_href);
0510 
0511     _href->SetMinimum(miny);
0512     _href->SetMaximum(maxy);
0513     _href->SetStats(kFALSE);
0514     _href->SetTitle(titleM);
0515     _href->GetXaxis()->SetTitle(titleX);
0516     _href->GetYaxis()->SetTitle(titleY);
0517     _href->Draw();
0518     drawHistoryGraph(
0519         nrun, x, y, ex, ey, ok, markerStyle, markerSize, markerColor, lineWidth, lineColor, GraphOpt.Data());
0520     win_->setCurHist(_href);
0521     _curPad->SetCrosshair(1);
0522     _curPad->SetGridx(0);
0523     _curPad->SetGridy(1);
0524 
0525     for (unsigned ii = 0; ii < nrun; ii++) {
0526       markers[ii]->Draw();
0527     }
0528   } else if (_historyType == iHistoryProjection) {
0529     titleW += ".projection";
0530 
0531     bool automaticScale(false);
0532 
0533     float _miny = miny;
0534     float _maxy = maxy;
0535     if (automaticScale) {
0536       float a = 0;
0537       float a2 = 0;
0538       int n = 0;
0539       for (unsigned ii = 0; ii < nrun; ii++) {
0540         if (!ok[ii])
0541           continue;
0542         a += y[ii];
0543         a2 += y[ii] * y[ii];
0544         n++;
0545       }
0546       a /= n;
0547       a2 /= n;
0548 
0549       float rms = a2 - a * a;
0550       if (rms > 0) {
0551         rms = sqrt(rms);
0552         _miny = a - 10 * rms;
0553         _maxy = a + 6 * rms;
0554       }
0555     }
0556 
0557     TString hname = MusEcal::historyVarName[_var];
0558     hname += ", projection";
0559     TH1* _href = new TH1F(hname, hname, 200, _miny, _maxy);
0560     setHistoStyle(_href);
0561     _href->SetTitle(titleM);
0562     _href->SetStats(kTRUE);
0563     for (unsigned ii = 0; ii < nrun; ii++) {
0564       if (!ok[ii])
0565         continue;
0566       _href->Fill(y[ii]);
0567     }
0568     _href->Draw();
0569 
0570     //       l = new TLine( xcur, _href->GetMinimum(),
0571     //           xcur, _href->GetMaximum() );
0572     //       l->SetLineStyle(2);
0573     //       l->SetLineColor(kRed);
0574     //       l->Draw();
0575 
0576     win_->setCurHist(_href);
0577     _curPad->SetCrosshair(0);
0578     _curPad->SetGridx(0);
0579     _curPad->SetGridy(1);
0580   }
0581 
0582   _curPad->Modified();
0583   _curPad->Update();
0584 
0585   win_->setPrintName(_psdir + titleW + ".ps");
0586   win_->write();
0587 }
0588 
0589 void MusEcalGUI::multiVarPlot(int opt) {
0590   if (_leaf == 0)
0591     return;
0592   TString WName_ = "MultiVar";
0593 
0594   MEPlotWindow* win_ = getWindow(WName_, opt, 700, 700);
0595   if (win_ == 0)
0596     return;
0597   _curPad = win_->getPad();
0598   _curPad->cd();
0599 
0600   vector<ME::Time> time;
0601   if (!getTimeVector(time))
0602     return;
0603   unsigned int nrun = time.size();
0604   float x[nrun];
0605   float ex[nrun];
0606   for (unsigned int irun = 0; irun < nrun; irun++) {
0607     float dt_ = ME::timeDiff(time[irun], _time, ME::iHour);
0608     x[irun] = dt_;
0609     ex[irun] = 0;
0610   }
0611   float minx = x[0];
0612   float maxx = x[nrun - 1];
0613   float rangex = maxx - minx;
0614   minx -= 0.05 * rangex;
0615   maxx += 0.05 * rangex;
0616 
0617   unsigned nplot = 0;
0618   unsigned nvar(0);
0619   if (_type == ME::iLaser)
0620     nvar = MusEcal::iSizeLV;
0621   else
0622     nvar = MusEcal::iSizeTPV;
0623   vector<int> varZoom(nvar);
0624   vector<TString> varName(nvar);
0625   vector<float> varNorm(nvar);
0626   vector<int> varColor(nvar);
0627   for (unsigned var = 0; var < nvar; var++) {
0628     if (_type == ME::iLaser) {
0629       varZoom[var] = MusEcal::historyVarZoom[_type][var];
0630       varName[var] = MusEcal::historyVarName[var];
0631       varColor[var] = MusEcal::historyVarColor[var];
0632     } else if (_type == ME::iTestPulse) {
0633       varZoom[var] = MusEcal::historyTPVarZoom[var];
0634       varName[var] = MusEcal::historyTPVarName[var];
0635       varColor[var] = MusEcal::historyTPVarColor[var];
0636     } else {
0637       abort();
0638     }
0639     if (varZoom[var] != MusEcal::iZero)
0640       nplot++;
0641   }
0642   float y[nplot][nrun];
0643   float ey[nplot][nrun];
0644   bool ok[nplot][nrun];
0645   unsigned iplot = 0;
0646   unsigned plottedVar[nplot];
0647   int curVar_ = _var;
0648   for (unsigned var = 0; var < nvar; var++) {
0649     if (varZoom[var] == MusEcal::iZero)
0650       continue;
0651 
0652     for (unsigned ii = 0; ii < nrun; ii++) {
0653       y[iplot][ii] = 0;
0654       ey[iplot][ii] = 0;
0655       ok[iplot][ii] = true;
0656     }
0657 
0658     float norm(0);
0659     float miny(0);
0660     float maxy(0);
0661 
0662     setVar(var);
0663     assert(getHistoryVector(nrun, x, y[iplot], ex, ey[iplot], ok[iplot], norm, miny, maxy));
0664 
0665     if (var == MusEcal::iNLS || var == MusEcal::iCorNLS)
0666       norm = 1;
0667 
0668     float zr = MusEcal::zoomRange[varZoom[var]];
0669 
0670     float yy(0);
0671     for (unsigned ii = 0; ii < nrun; ii++) {
0672       yy = y[iplot][ii];
0673 
0674       yy = (yy - norm) / norm / zr;
0675       if (yy > 1)
0676         yy = 1;
0677       if (yy < -1)
0678         yy = -1;
0679 
0680       yy += 2 * (nplot - iplot) - 1;
0681 
0682       y[iplot][ii] = yy;
0683       ey[iplot][ii] = 0;  // fixme!
0684       plottedVar[iplot] = var;
0685     }
0686     iplot++;
0687   }
0688   setVar(curVar_);
0689   float miny = 0;
0690   float maxy = 2 * nplot;
0691 
0692   //
0693   // OK, all is set, now plotting
0694   //
0695   TString titleX;
0696   TString titleY;
0697   TString titleM;
0698   TString titleW;
0699 
0700   titleW = ME::type[_type];
0701   if (_type == ME::iLaser) {
0702     titleW += ".";
0703     titleW += ME::color[_color];
0704   }
0705   titleW += ".";
0706   titleW += _leaf->oneWord();
0707   titleW += ".";
0708   MERun* run_ = _runMgr.begin()->second->curRun();
0709   assert(run_ != 0);
0710   titleW += run_->rundir();
0711   titleM = titleW;
0712   titleM.ReplaceAll(".", " ");
0713   titleW += ".multiVar";
0714 
0715   titleX = "time (in hours, relative to current run)";
0716 
0717   TString hname("_multivar");
0718   TH1* hdum = (TH1*)gROOT->FindObject(hname);
0719   if (hdum)
0720     delete hdum;
0721   hdum = new TH1F(hname, hname, 100, minx, maxx);
0722 
0723   setHistoStyle(hdum);
0724 
0725   hdum->SetMinimum(miny);
0726   hdum->SetMaximum(maxy);
0727   hdum->SetStats(kFALSE);
0728 
0729   TAxis* ax = hdum->GetXaxis();
0730   TAxis* ay = hdum->GetYaxis();
0731   ax->SetTitle(titleX);
0732   ay->SetLabelFont(0);
0733   ay->SetLabelSize(0);
0734   ay->SetTitleFont(0);
0735   ay->SetTitleSize(0);
0736   ay->SetNdivisions(2 * nplot, true);
0737   hdum->SetTitle(titleM);
0738   hdum->Draw();
0739 
0740   _curPad->SetCrosshair(1);
0741   _curPad->SetGridx(0);
0742   _curPad->SetGridy(0);
0743 
0744   //   if( _drawIntervals )
0745   //     {
0746   //       unsigned int t0_   = _runMgr[_type]->curRun()->t();
0747 
0748   //       bool usetimestamp = (_historyPlot == iHistoryVsTimeStamp);
0749   //       MEIntervals* intervals_ = mtqIntervals( _type );
0750   //       drawIntervals( intervals_, miny, maxy, usetimestamp, t0_ );
0751   //     }
0752 
0753   for (unsigned iplot = 0; iplot < nplot; iplot++) {
0754     TLine* line = new TLine(minx, 2 * (nplot - iplot) - 1, maxx, 2 * (nplot - iplot) - 1);
0755     line->SetLineWidth(1);
0756     line->SetLineColor(kBlack);
0757     line->Draw("Same");
0758 
0759     int icol = varColor[plottedVar[iplot]];
0760     float markerSize = 0.3;
0761     int markerStyle = 1;
0762     int markerColor = icol;
0763     int lineWidth = 2;
0764     int lineColor = icol;
0765     drawHistoryGraph(
0766         nrun, x, y[iplot], ex, ey[iplot], ok[iplot], markerStyle, markerSize, markerColor, lineWidth, lineColor);
0767 
0768     //      TText* text = new TText( first_run - 0.75*( last_run-minx ),
0769     //                 2*(nplot-iplot)-1+0.5,  varName[ plottedVar[iplot] ]  );
0770     TText* text = new TText(minx + 0.05 * (maxx - minx), 2 * (nplot - iplot) - 1 + 0.5, varName[plottedVar[iplot]]);
0771     text->SetTextAlign(11);  // 10*left-ajusted + bottom-ajusted
0772     text->SetTextFont(132);
0773     text->SetTextSizePixels(20);
0774     text->Draw("Same");
0775 
0776     //      TText* text2 = new TText( maxx - 0.5*(maxx - last_run ),
0777     //              2*(nplot-iplot)-1+0.5,  zoomName[ varZoom[ plottedVar[iplot] ] ]  );
0778     TText* text2 = new TText(
0779         maxx - 0.05 * (maxx - minx), 2 * (nplot - iplot) - 1 + 0.5, MusEcal::zoomName[varZoom[plottedVar[iplot]]]);
0780     text2->SetTextAlign(31);  // 10*right-ajusted + bottom-ajusted
0781     text2->SetTextFont(132);
0782     text2->SetTextSizePixels(18);
0783     text2->Draw("Same");
0784     {
0785       TLine* line = new TLine(minx, 2 * (nplot - iplot), maxx, 2 * (nplot - iplot));
0786       line->SetLineWidth(2);
0787       line->SetLineColor(kBlack);
0788       line->Draw("Same");
0789     }
0790   }
0791   TLine* line = new TLine(minx, 0, maxx, 0);
0792   line->SetLineWidth(2);
0793   line->SetLineColor(kBlack);
0794   line->Draw("Same");
0795 
0796   gPad->Modified();
0797   gPad->Update();
0798 
0799   win_->setPrintName(_psdir + titleW + ".ps");
0800   win_->write();
0801 }
0802 
0803 void MusEcalGUI::leafPlot(int opt) {
0804   if (_leaf == 0)
0805     return;
0806   MEChannel* curLeaf_ = _leaf;
0807   //  MEChannel* mother_  = _leaf->m();
0808   MEChannel* mother_ = _leaf;
0809   if (mother_ == 0)
0810     return;
0811   int iG = mother_->ig();
0812   bool doZoom = true;
0813   if (iG < ME::iLMRegion) {
0814     cout << "Already at Laser Monitoring Region level" << endl;
0815     doZoom = false;
0816   } else if (_type == ME::iTestPulse) {
0817     if (iG >= MusEcal::iGTPVar[_var])
0818       doZoom = false;
0819   } else {
0820     if (iG >= MusEcal::iGVar[_var])
0821       doZoom = false;
0822   }
0823 
0824   TString WName_ = "Leaf";
0825   if (!doZoom) {
0826     if (_window.count(WName_) != 0)
0827       delete _window[WName_];
0828     historyPlot(2);
0829     return;
0830   }
0831   MEPlotWindow* win_ = getWindow(WName_, opt, 800, 800);
0832   if (win_ == 0)
0833     return;
0834   _curPad = win_->getPad();
0835   _curPad->cd();
0836 
0837   unsigned int nrun = 1000;
0838   float x[nrun];
0839   float y[nrun];
0840   float ex[nrun];
0841   float ey[nrun];
0842   bool ok[nrun];
0843   float miny;
0844   float maxy;
0845   float normy;
0846   if (!getHistoryVector(nrun, x, y, ex, ey, ok, normy, miny, maxy))
0847     return;
0848 
0849   unsigned nl = 0;
0850   unsigned nc = 0;
0851   unsigned nplot = mother_->n();
0852   if (nplot <= 5) {
0853     nc = 1;
0854     nl = nplot;
0855   } else if (nplot <= 10) {
0856     nc = 2;
0857     nl = (nplot + 1) / 2;
0858   } else if (nplot == 25) {
0859     nc = 5;
0860     nl = 5;
0861   } else {
0862     cout << "--- Number of plots not supported : " << nplot << endl;
0863     return;
0864   }
0865 
0866   TString titleX;
0867   TString titleY;
0868   TString titleM;
0869   TString titleW;
0870   //titleX = "time (in hours from first run)";
0871 
0872   TString varName;
0873   int varColor;
0874   titleW = ME::type[_type];
0875   if (_type == ME::iLaser) {
0876     varName = MusEcal::historyVarName[_var];
0877     varColor = MusEcal::historyVarColor[_var];
0878     titleW += ".";
0879     titleW += ME::color[_color];
0880   } else if (_type == ME::iTestPulse) {
0881     varName = MusEcal::historyTPVarName[_var];
0882     varColor = MusEcal::historyTPVarColor[_var];
0883   } else {
0884     abort();
0885   }
0886   titleW += ".";
0887   titleW += varName;
0888   titleY += varName;
0889   titleY += ", ";
0890   if (_zoom == MusEcal::iZero) {
0891     _zoom = MusEcal::iThirtyPercent;
0892   }
0893   titleY += MusEcal::zoomName[_zoom];
0894 
0895   titleW += ".";
0896   titleW += mother_->oneWord();
0897   titleW += ".";
0898   MERun* run_ = _runMgr.begin()->second->curRun();
0899   assert(run_ != 0);
0900   titleW += run_->rundir();
0901   titleM = titleW;
0902   titleM.ReplaceAll(".", " ");
0903   titleW += ".leaf";
0904   win_->setPrintName(_psdir + titleW + ".ps");
0905 
0906   int tx100_ = ((int)(100 * (x[nrun - 1] - x[0])));
0907   int hrs_ = tx100_ / 100;
0908   int min_ = ((tx100_ % 100) * 60) / 100;
0909 
0910   titleM += " (";
0911   titleM += hrs_;
0912   titleM += " hrs ";
0913   titleM += min_;
0914   titleM += " min)";
0915 
0916   _curPad->SetCrosshair(1);
0917   _curPad->SetGridx(0);
0918   _curPad->SetGridy(0);
0919   float xxmin = 0;
0920   float xxmax = (float)nc;
0921   float yymin = 0;
0922   float yymax = (float)(2 * nl);
0923 
0924   TString hname("leaf_");
0925   TH1* hdum = (TH1*)gROOT->FindObject(hname);
0926   if (hdum)
0927     delete hdum;
0928 
0929   TH1* _href = new TH1F(hname, hname, 100, xxmin, xxmax);
0930   setHistoStyle(_href);
0931   _href->SetMinimum(yymin);
0932   _href->SetMaximum(yymax);
0933   _href->SetStats(kFALSE);
0934   win_->setCurHist(_href);
0935 
0936   TAxis* ax = _href->GetXaxis();
0937   TAxis* ay = _href->GetYaxis();
0938   ax->SetTitle(titleX);
0939   ax->SetLabelFont(0);
0940   ax->SetLabelSize(0);
0941   ax->SetTitleFont(0);
0942   ax->SetTitleSize(0);
0943   ax->SetNdivisions(nc, true);
0944   ay->SetTitle(titleY);
0945   ay->SetLabelFont(0);
0946   ay->SetLabelSize(0);
0947   ay->SetNdivisions(2 * nl, true);
0948   _href->SetTitle(titleM);
0949   _href->Draw();
0950 
0951   gPad->Modified();
0952   gPad->Update();
0953 
0954   float zr = MusEcal::zoomRange[_zoom];
0955   for (unsigned iplot = 0; iplot < nplot; iplot++) {
0956     int ic = iplot / nl;
0957     int il = iplot % nl;
0958 
0959     //
0960     // get the vectors
0961     //
0962     MEChannel* leaf_ = mother_->d(iplot);
0963     TString oneWord_;
0964     oneWord_ += leaf_->id();
0965 
0966     _leaf = leaf_;
0967     //      cout << leaf_->oneLine() << endl;
0968     if (!getHistoryVector(nrun, x, y, ex, ey, ok, normy, miny, maxy))
0969       continue;
0970     unsigned int nrun_ = 1000;
0971     assert(nrun < nrun_);
0972     float x_[nrun_];
0973     float y_[nrun_];
0974     float ex_[nrun_];
0975     float ey_[nrun_];
0976     bool ok_[nrun_];
0977     float norm_(0);
0978     float miny_(1000000);
0979     float maxy_(0);
0980     int n_(0);
0981     for (unsigned ii = 0; ii < nrun; ii++) {
0982       ex_[ii] = 0.;
0983       ey_[ii] = 0.;
0984       x_[ii] = (x[ii] - x[0]) / (x[nrun - 1] - x[0]);
0985       y_[ii] = 0.;
0986       ok_[ii] = ok[ii];
0987       if (ok_[ii]) {
0988         if (y[ii] < miny_)
0989           miny_ = y[ii];
0990         if (y[ii] > maxy_)
0991           maxy_ = y[ii];
0992         norm_ += y[ii];
0993         n_++;
0994       }
0995     }
0996     if (n_ > 0)
0997       norm_ /= n_;
0998     nrun_ = nrun;
0999     for (unsigned ii = 0; ii < nrun; ii++) {
1000       float yy = y[ii];
1001 
1002       yy = (yy - norm_) / norm_ / zr;
1003       if (yy > 1)
1004         yy = 1;
1005       if (yy < -1)
1006         yy = -1;
1007       yy += (2 * il + 1);
1008 
1009       x_[ii] += ic;
1010       y_[ii] = yy;
1011     }
1012 
1013     TLine* baseline = new TLine(ic, 2 * il + 1, ic + 1, 2 * il + 1);
1014     baseline->SetLineWidth(1);
1015     baseline->SetLineColor(kBlack);
1016     baseline->Draw("Same");
1017 
1018     int icol = varColor;
1019     float markerSize = 0.3;
1020     int markerStyle = 1;
1021     int markerColor = icol;
1022     int lineWidth = 2;
1023     int lineColor = icol;
1024 
1025     drawHistoryGraph(nrun_, x_, y_, ex_, ey_, ok_, markerStyle, markerSize, markerColor, lineWidth, lineColor);
1026 
1027     TText* text = new TText(ic + 0.97,     // 95% of 1
1028                             2 * il + 1.7,  // 85% of 2
1029                             oneWord_);
1030     text->SetTextAlign(31);  // 10*right-ajusted + bottom-ajusted
1031     text->SetTextFont(132);
1032     int txtsize = (18 * 4) / nl;  // proportional to the number of line, 18 when nl=4
1033     text->SetTextSizePixels(txtsize);
1034     text->Draw("Same");
1035 
1036     TLine* line[4];
1037     line[0] = new TLine(ic, 2 * il, ic + 1, 2 * il);
1038     line[1] = new TLine(ic + 1, 2 * il, ic + 1, 2 * (il + 1));
1039     line[2] = new TLine(ic + 1, 2 * (il + 1), ic, 2 * (il + 1));
1040     line[3] = new TLine(ic, 2 * (il + 1), ic, 2 * il);
1041     for (int kk = 0; kk < 4; kk++) {
1042       line[kk]->SetLineWidth(2);
1043       line[kk]->SetLineColor(kBlack);
1044       line[kk]->Draw("Same");
1045     }
1046     gPad->Modified();
1047     gPad->Update();
1048   }
1049 
1050   _leaf = curLeaf_;
1051 
1052   gPad->Modified();
1053   gPad->Update();
1054 
1055   win_->write();
1056 }
1057 
1058 void MusEcalGUI::welcome() {
1059   TString str_ = "Welcome";
1060   if (_window.count(str_) != 0)
1061     return;
1062   _window[str_] =
1063       new MEPlotWindow(gClient->GetRoot(),
1064                        this,
1065                        str_,
1066                        fCanvas->GetWw(),
1067                        fCanvas->GetWh(),
1068                        "MusEcal - Monitoring and Useful Survey of Ecal",
1069                        "Visit our Twiki page at https://twiki.cern.ch/twiki/bin/view/CMS/EcalLaserMonitoring",
1070                        "MusEcal Version 2.0",
1071                        "J. Malcles & G. Hamel de Monchenault, CEA-Saclay");
1072   _window[str_]->ShowWelcome(true);
1073 }
1074 
1075 MusEcalGUI::~MusEcalGUI() { ClearWelcome(); }
1076 
1077 void MusEcalGUI::exitProg() {
1078   cout << "Exiting MusEcalGUI. Take Care." << endl;
1079   gApplication->Terminate(0);
1080 }
1081 
1082 void MusEcalGUI::setPxAndPy(int px, int py) {
1083   if (_debug)
1084     cout << "MusEcalGUI: Entering setPxAndPy " << endl;
1085 
1086   MECanvasHolder::setPxAndPy(px, py);
1087 }
1088 
1089 void MusEcalGUI::windowClicked(MEPlotWindow* win) {
1090   float x, y;
1091   win->getCurXY(x, y);
1092   int ix = static_cast<int>(x > 0 ? x + 0.5 : x - 0.5);
1093   int iy = static_cast<int>(x > 0 ? y + 0.5 : y - 0.5);
1094   if (win->name() == TString("History")) {
1095     float dt_ = x;
1096     ME::Time t_ = ME::time(dt_, _time, ME::iHour);
1097     setTime(t_);
1098     return;
1099   }
1100   if (win->name() == TString("Leaf")) {
1101     int nl = (int)((win->curHist()->GetMaximum() + 0.00001) / 2);
1102     int ic = (int)x;
1103     int il = (int)y;
1104     il /= 2;
1105     cout << "nl/ic/il " << nl << "/" << x << "/" << y << endl;
1106     int iplot = nl * ic + il;
1107     cout << "iplot= " << iplot << endl;
1108     _leaf = _leaf->d(iplot);
1109     _leaf->print(cout);
1110     leafPlot();
1111     return;
1112   }
1113   if (win->name().Contains("_sel")) {
1114     int lmr_;
1115     if (win->name().Contains("LMR_")) {
1116       int ieta = ix;
1117       int iphi = iy;
1118       lmr_ = MEEBGeom::lmr(ieta, iphi);
1119       if (lmr_ < 1 || lmr_ > 72)
1120         return;
1121 
1122     } else {
1123       int iX = ix / 5;
1124       int iY = iy / 5;
1125       if (win->name().Contains("LMM_")) {
1126         int lm = MEEBGeom::lm_channel(iX, iY);
1127         _leaf = _leaf->getAncestor(ME::iSector)->getDescendant(ME::iLMModule, lm);
1128       } else if (win->name().Contains("SC_")) {
1129         int sc = MEEBGeom::tt_channel(iX, iY);
1130         _leaf = _leaf->getAncestor(ME::iSector)->getDescendant(ME::iSuperCrystal, sc);
1131       } else if (win->name().Contains("C_") || win->name() == TString("EBLocal")) {
1132         _ig = ME::iCrystal;
1133         int cr = MEEBGeom::crystal_channel(ix, iy);
1134         _leaf = _leaf->getAncestor(ME::iSector)->getDescendant(ME::iCrystal, cr);
1135       }
1136       cout << _leaf->oneWord() << endl;
1137       lmr_ = _leaf->getAncestor(ME::iLMRegion)->id();
1138       cout << "lmr_/_lmr " << lmr_ << "/" << _lmr << endl;
1139     }
1140     if (lmr_ != _lmr) {
1141       setChannel(runMgr(lmr_)->tree()->getFirstDescendant(ME::iCrystal));
1142     } else {
1143       cout << "OK" << endl;
1144       fillEBLocalHistograms();
1145       drawHist();
1146       historyPlot();
1147     }
1148     delete win;
1149     return;
1150   }
1151 }
1152 
1153 void MusEcalGUI::HandleFileMenu(Int_t id) {
1154   if (id == 0) {
1155     exitProg();
1156     return;
1157   }
1158   if (id == 1) {
1159     dumpVector(ME::iAPD_MEAN);
1160     return;
1161   }
1162   if (id == 3) {
1163     createRunPanel();
1164     return;
1165   }
1166   if (id == 4) {
1167     welcome();
1168     return;
1169   }
1170 }
1171 
1172 void MusEcalGUI::HandleHistMenu(Int_t id) {
1173   if (id == -1000) {
1174     // produce animated gif files
1175     drawAPDAnim(1);
1176     return;
1177   }
1178   int kk = id / 1000000;
1179   if (kk > 0) {
1180     int ihtype_ = id % 1000000;
1181     if (_ihtype != ihtype_) {
1182       _ihtype = ihtype_;
1183       drawAPDHist();
1184     }
1185     return;
1186   }
1187   if (_type == ME::iLaser) {
1188     // APD? PN? MTQ?
1189     int icateg = id / 1000;
1190     id = id % 1000;
1191     _icateg = icateg;
1192 
1193     // color?
1194     int icol = id / 100;
1195     assert(icol == _color);
1196     id = id % 100;
1197 
1198     // histogram?
1199     _ihist = id;
1200 
1201     drawHist(1);
1202   } else if (_type == ME::iTestPulse) {
1203     // APD? PN?
1204     int icateg = id / 1000;
1205     id = id % 1000;
1206     _icateg = icateg;
1207 
1208     _ihist = id;
1209     drawHist(1);
1210   }
1211 }
1212 
1213 void MusEcalGUI::HandleHistoryMenu(Int_t id) {
1214   if (id < 0) {
1215     if (id == -1000) {
1216       createLeafPanel();
1217       return;
1218     }
1219     if (id == -2000) {
1220       createMultiVarPanel();
1221       return;
1222     }
1223     if (id == -101) {
1224       cout << "History Plots: Projection" << endl;
1225       _historyType = iHistoryProjection;
1226     } else if (id == -100) {
1227       cout << "History Plots: versus time (hours since current Run/Sequence)" << endl;
1228       _historyType = iHistoryVsTime;
1229     } else if (id == -10) {
1230       if (!_normalize) {
1231         cout << "History Plots: normalized to full range " << endl;
1232         _normalize = true;
1233       } else {
1234         cout << "History plots: unnormalized " << endl;
1235         _normalize = false;
1236       }
1237     }
1238     historyPlot(1);
1239     return;
1240   }
1241   if (_type == ME::iLaser) {
1242     // color?
1243     int icol = id / 100;
1244     assert(icol == _color);
1245     id = id % 100;
1246 
1247     // variable?
1248     _var = id;
1249 
1250     historyPlot(1);
1251   } else if (_type == ME::iTestPulse) {
1252     // variable?
1253     _var = id;
1254 
1255     historyPlot(1);
1256   } else {
1257     cout << "Not implemented yet" << endl;
1258   }
1259 }
1260 
1261 void MusEcalGUI::HandleChannelMenu(Int_t id) {
1262   if (id == 60000) {
1263     createChanPanel();
1264     // one level up
1265     return;
1266   }
1267 
1268   if (id == 50000) {
1269     oneLevelUp();
1270     // one level up
1271     return;
1272   }
1273 
1274   if (id / 10000 == 1) {
1275     int icr_ = id % 10000;
1276     if (curMgr() == 0) {
1277       cout << "Warning -- current manager is not present " << endl;
1278       return;
1279     }
1280     setChannel(curMgr()->tree()->getDescendant(ME::iCrystal, icr_));
1281     return;
1282   }
1283 
1284   if (id / 1000 == 1) {
1285     int ilmr_ = id % 1000;
1286     if (runMgr(ilmr_) == 0) {
1287       cout << "Warning -- LMR" << ilmr_ << " is not present" << endl;
1288       return;
1289     }
1290     setChannel(runMgr(ilmr_)->tree()->getFirstDescendant(ME::iCrystal));
1291     return;
1292   }
1293 
1294   if (id < 0 || id > ME::iSizeG)
1295     return;
1296 
1297   MEPlotWindow* win_(0);
1298   if (id == ME::iLMRegion) {
1299     win_ = new MEPlotWindow(gClient->GetRoot(), this, "LMR_sel", 450, 700);
1300     assert(_febgeom != 0);
1301     TH2* h_ = (TH2*)_febgeom->Get("eb_lmr");
1302     assert(h_ != 0);
1303     TPad* pad_ = (TPad*)win_->getPad();
1304     pad_->cd();
1305     TString title_ = "Double Click on LM Region";
1306     h_->SetTitle(title_);
1307     h_->SetStats(kFALSE);
1308     h_->Draw("COLZ");
1309     MEEBDisplay::drawEBGlobal();
1310     win_->setCurHist(h_);
1311     pad_->Modified();
1312     pad_->Update();
1313   } else {
1314     _ig = id;
1315     TString str_ = ME::granularity[_ig];
1316     str_ += "_sel";
1317     win_ = new MEPlotWindow(gClient->GetRoot(), this, str_, 700, 450, "Channel Selection");
1318     assert(_febgeom != 0);
1319     TString hname_ = "eb_loc";
1320     TString cr_str_ = "_cr";
1321     if (ME::useElectronicNumbering)
1322       cr_str_ = "_elecr";
1323     switch (id) {
1324       case ME::iLMModule:
1325         hname_ += "_lmmod";
1326         break;
1327       case ME::iSuperCrystal:
1328         hname_ += "_tt";
1329         break;
1330       case ME::iCrystal:
1331         hname_ += cr_str_;
1332         break;
1333       default:
1334         return;
1335     }
1336     TH2* h_ = (TH2*)_febgeom->Get(hname_);
1337     assert(h_ != 0);
1338     TPad* pad_ = (TPad*)win_->getPad();
1339     pad_->cd();
1340     TString title_ = "Double Click to select -- ";
1341     title_ += _leaf->oneWord(ME::iSector);
1342     h_->SetTitle(title_);
1343     h_->SetStats(kFALSE);
1344     h_->Draw("COLZ");
1345     MEEBDisplay::drawEBLocal();
1346     win_->setCurHist(h_);
1347     pad_->Modified();
1348     pad_->Update();
1349   }
1350 }
1351 
1352 void MusEcalGUI::drawHist(int opt) {
1353   if (_icateg == 0) {
1354     drawAPDHist(opt);
1355   } else if (_icateg == 1) {
1356     drawPNHist(opt);
1357   } else if (_icateg == 2) {
1358     drawMTQHist(opt);
1359   }
1360 }
1361 
1362 void MusEcalGUI::drawAPDHist(int opt) {
1363   TString str_;
1364   TH2* h2_;
1365   TH1* h1_;
1366   TString WName_;
1367   TString title_;
1368   MEPlotWindow* win_;
1369 
1370   TString varName_;
1371   if (_type == ME::iLaser) {
1372     varName_ = ME::APDPrimVar[_ihist];
1373     str_ = "APD-";
1374   } else if (_type == ME::iTestPulse) {
1375     varName_ = ME::TPAPDPrimVar[_ihist];
1376     str_ = "TPAPD-";
1377   }
1378   str_ += varName_;
1379 
1380   if (isBarrel()) {
1381     // the full barrel 2D
1382     WName_ = "EB_2D";
1383     win_ = getWindow(WName_, opt, 450, 700);
1384     if (win_ != 0) {
1385       _curPad = win_->getPad();
1386       _curPad->cd();
1387 
1388       h2_ = (TH2*)_eb_m[str_];
1389       assert(h2_ != 0);
1390       h2_->Draw("COLZ");
1391       MEEBDisplay::drawEBGlobal();
1392       _window[WName_]->setCurHist(h2_);
1393       _curPad->Modified();
1394       _curPad->Update();
1395 
1396       title_ = h2_->GetTitle();
1397       title_.ReplaceAll(" ", ".");
1398       title_ += ".2D";
1399       win_->setPrintName(_psdir + title_ + ".ps");
1400       win_->write();
1401     }
1402     // the full barrel 1D
1403     WName_ = "EB_1D";
1404     win_ = getWindow(WName_, opt, 900, 300);
1405     if (win_ != 0) {
1406       _curPad = win_->getPad();
1407       _curPad->cd();
1408 
1409       TString ext_ = "_1D";
1410       h1_ = (TH1*)_eb_m[str_ + ext_];
1411       assert(h1_ != 0);
1412       h1_->Draw();
1413       float max_ = h1_->GetMaximum();
1414       float min_ = h1_->GetMinimum();
1415       float x_ = -0.5;
1416       for (int ilmr = 1; ilmr <= 72; ilmr++) {
1417         if (ilmr != 1 && (ilmr - 1) % 2 == 0)
1418           x_ += 800 / 25;
1419         if ((ilmr - 1) % 2 == 1)
1420           x_ += 900 / 25;
1421         if (ilmr == 1)
1422           continue;
1423         TLine* l = new TLine(x_, min_ + 0.01 * (max_ - min_), x_, max_ - 0.01 * (max_ - min_));
1424         if ((ilmr - 1) % 2 == 0) {
1425           l->SetLineColor(kRed);
1426           l->SetLineWidth(2);
1427         } else {
1428           l->SetLineColor(kGreen);
1429         }
1430         l->Draw("Same");
1431 
1432         if ((ilmr - 1) % 2 == 0)
1433           continue;
1434         TText* text_ = new TText(x_, min_ + 0.80 * (max_ - min_), ME::smName(ilmr));
1435         text_->SetTextSize(0.05);
1436         text_->SetTextAngle(90);
1437         text_->SetTextAlign(12);
1438         text_->Draw("Same");
1439       }
1440       h1_->Draw("Same");
1441 
1442       win_->setCurHist(h1_);
1443       _curPad->Modified();
1444       _curPad->Update();
1445 
1446       title_ = h1_->GetTitle();
1447       title_.ReplaceAll(" ", ".");
1448       title_ += ".1D";
1449       win_->setPrintName(_psdir + title_ + ".ps");
1450       win_->write();
1451     }
1452   } else {
1453     // the full endcap 2D
1454     WName_ = "EE_2D";
1455     win_ = getWindow(WName_, opt, 350, 600);
1456     if (win_ != 0) {
1457       _curPad = win_->getPad();
1458       _curPad->cd();
1459 
1460       h2_ = (TH2*)_ee_m[str_];
1461       assert(h2_ != 0);
1462       h2_->Draw("COLZ");
1463       MEEEDisplay::drawEEGlobal();
1464 
1465       _window[WName_]->setCurHist(h2_);
1466 
1467       _curPad->Modified();
1468       _curPad->Update();
1469 
1470       title_ = h2_->GetTitle();
1471       title_.ReplaceAll(" ", ".");
1472       title_ += ".2D";
1473       win_->setPrintName(_psdir + title_ + ".ps");
1474       win_->write();
1475     }
1476   }
1477 
1478   if (isBarrel()) {
1479     // then the current super-module
1480     WName_ = "EBLocal";
1481     win_ = getWindow(WName_, opt, 700, 450);
1482     if (win_ != 0) {
1483       _curPad = (TPad*)win_->getPad();
1484       _curPad->cd();
1485       TString ext_;
1486       if (_ihtype == iMAP) {
1487         _curPad->SetGridx(0);
1488         _curPad->SetGridy(0);
1489         h2_ = (TH2*)_eb_loc_m[str_ + ext_];
1490         assert(h2_ != 0);
1491         win_->setCurHist(h2_);
1492         h2_->Draw("COLZ");
1493         MEEBDisplay::drawEBLocal();
1494         title_ = h2_->GetTitle();
1495         title_.ReplaceAll(" ", ".");
1496         title_ += ".MAP";
1497       } else if (_ihtype == iHIST) {
1498         _curPad->SetGridx(1);
1499         _curPad->SetGridy(0);
1500         ext_ = "_HIST";
1501         if (_eb_loc_m.count(str_ + ext_) == 0)
1502           return;
1503         h1_ = (TH1*)_eb_loc_m[str_ + ext_];
1504         if (h1_ == 0)
1505           return;
1506         win_->setCurHist(h1_);
1507         h1_->Draw();
1508         ext_ += "_sel";
1509         h1_ = (TH1*)_eb_loc_m[str_ + ext_];
1510         h1_->Draw("Same");
1511         title_ = h1_->GetTitle();
1512         title_.ReplaceAll(" ", ".");
1513         title_ += ".HIST";
1514       } else if (_ihtype == iVS_CHANNEL) {
1515         _curPad->SetGridx(1);
1516         _curPad->SetGridy(1);
1517         ext_ = "_VS_CHANNEL";
1518         if (_eb_loc_m.count(str_ + ext_) == 0)
1519           return;
1520         h1_ = (TH1*)_eb_loc_m[str_ + ext_];
1521         if (h1_ == 0)
1522           return;
1523         win_->setCurHist(h1_);
1524         h1_->Draw();
1525         ext_ += "_sel";
1526         h1_ = (TH1*)_eb_loc_m[str_ + ext_];
1527         h1_->Draw("Same");
1528         title_ = h1_->GetTitle();
1529         title_.ReplaceAll(" ", ".");
1530         title_ += ".VS_CHANNEL";
1531       }
1532       _curPad->Modified();
1533       _curPad->Update();
1534 
1535       win_->setPrintName(_psdir + title_ + ".ps");
1536       win_->write();
1537     }
1538   } else {
1539     int isect = _leaf->getAncestor(ME::iSector)->id();
1540     if (isect > 9)
1541       isect -= 9;
1542     // then the current super-module
1543     WName_ = "EELocal";
1544     win_ = getWindow(WName_, opt, 450, 450);
1545     if (win_ != 0) {
1546       _curPad = (TPad*)win_->getPad();
1547       _curPad->cd();
1548       TString ext_;
1549       if (_ihtype == iMAP) {
1550         _curPad->SetGridx(0);
1551         _curPad->SetGridy(0);
1552         TString str__ = str_ + ext_;
1553         str__ += "_";
1554         str__ += isect;
1555         h2_ = (TH2*)_ee_loc_m[str__];
1556         if (h2_ == 0) {
1557           cout << str__ << endl;
1558           return;
1559         }
1560         //        assert( h2_!=0 );
1561         win_->setCurHist(h2_);
1562         h2_->Draw("COLZ");
1563         MEEEDisplay::drawEELocal(isect);
1564         title_ = h2_->GetTitle();
1565         title_.ReplaceAll(" ", ".");
1566         title_ += ".MAP";
1567       } else if (_ihtype == iHIST) {
1568         _curPad->SetGridx(1);
1569         _curPad->SetGridy(0);
1570         ext_ = "_HIST";
1571         TString str__ = str_;
1572         str__ += "_";
1573         str__ += isect;
1574         str__ += ext_;
1575         cout << "IHIST " << str__ << endl;
1576         if (_ee_loc_m.count(str__) == 0)
1577           return;
1578         h1_ = (TH1*)_ee_loc_m[str__];
1579         if (h1_ == 0)
1580           return;
1581         win_->setCurHist(h1_);
1582         h1_->Draw();
1583         ext_ += "_sel";
1584         h1_ = (TH1*)_ee_loc_m[str__];
1585         h1_->Draw("Same");
1586         title_ = h1_->GetTitle();
1587         title_.ReplaceAll(" ", ".");
1588         title_ += ".HIST";
1589       } else if (_ihtype == iVS_CHANNEL) {
1590         _curPad->SetGridx(1);
1591         _curPad->SetGridy(1);
1592         ext_ = "_VS_CHANNEL";
1593         TString str__ = str_;
1594         str__ += "_";
1595         str__ += isect;
1596         str__ += ext_;
1597         cout << "VS_CHANNEL " << str__ << endl;
1598         if (_ee_loc_m.count(str__) == 0)
1599           return;
1600         h1_ = (TH1*)_ee_loc_m[str__];
1601         if (h1_ == 0)
1602           return;
1603         win_->setCurHist(h1_);
1604         h1_->Draw();
1605         ext_ += "_sel";
1606         h1_ = (TH1*)_ee_loc_m[str__];
1607         h1_->Draw("Same");
1608         title_ = h1_->GetTitle();
1609         title_.ReplaceAll(" ", ".");
1610         title_ += ".VS_CHANNEL";
1611       }
1612       _curPad->Modified();
1613       _curPad->Update();
1614 
1615       win_->setPrintName(_psdir + title_ + ".ps");
1616       win_->write();
1617     }
1618   }
1619 }
1620 
1621 void MusEcalGUI::drawPNHist(int opt) {
1622   TString str_;
1623   TH1* h1_;
1624   TString WName_;
1625   TString title_;
1626   MEPlotWindow* win_;
1627 
1628   TString varName_;
1629   if (_type == ME::iLaser) {
1630     varName_ = ME::PNPrimVar[_ihist];
1631     str_ = "PN-";
1632   } else if (_type == ME::iTestPulse) {
1633     varName_ = ME::TPPNPrimVar[_ihist];
1634     str_ = "TPPN-";
1635   }
1636   str_ += varName_;
1637 
1638   // the full barrel 1D
1639   WName_ = "EB_PN";
1640   win_ = getWindow(WName_, opt, 900, 300);
1641   if (win_ != 0) {
1642     _curPad = win_->getPad();
1643     _curPad->cd();
1644     h1_ = (TH1*)_eb_m[str_];
1645     assert(h1_ != 0);
1646     float max_ = h1_->GetMaximum();
1647     float min_ = h1_->GetMinimum();
1648     h1_->SetMaximum(max_);  // !!!
1649     h1_->Draw();
1650     float x_ = -0.5;
1651     for (int ilmr = 1; ilmr <= 72; ilmr++) {
1652       if (ilmr != 1 && (ilmr - 1) % 2 == 0)
1653         x_ += 8;
1654       if ((ilmr - 1) % 2 == 1)
1655         x_ += 10;
1656       if (ilmr == 1)
1657         continue;
1658       TLine* l = new TLine(x_, min_ + 0.01 * (max_ - min_), x_, max_ - 0.01 * (max_ - min_));
1659       if ((ilmr - 1) % 2 == 0) {
1660         l->SetLineColor(kRed);
1661         l->SetLineWidth(2);
1662       } else {
1663         l->SetLineColor(kGreen);
1664       }
1665       l->Draw("Same");
1666 
1667       if ((ilmr - 1) % 2 == 0)
1668         continue;
1669       TText* text_ = new TText(x_, min_ + 0.80 * (max_ - min_), ME::smName(ilmr));
1670       text_->SetTextSize(0.05);
1671       text_->SetTextAngle(90);
1672       text_->SetTextAlign(12);
1673       text_->Draw("Same");
1674     }
1675     h1_->Draw("Same");
1676 
1677     win_->setCurHist(h1_);
1678     _curPad->Modified();
1679     _curPad->Update();
1680 
1681     title_ = h1_->GetTitle();
1682     title_.ReplaceAll(" ", ".");
1683     title_ += ".GLOBAL";
1684     win_->setPrintName(_psdir + title_ + ".ps");
1685     win_->write();
1686   }
1687 
1688   // then the current super-module
1689   WName_ = "EBLocal_PN";
1690   win_ = getWindow(WName_, opt, 700, 450);
1691   if (win_ != 0) {
1692     _curPad = (TPad*)win_->getPad();
1693     _curPad->cd();
1694     _curPad->SetGridx(1);
1695     _curPad->SetGridy(1);
1696     TString ext_ = "_LOCAL";
1697     if (_eb_loc_m.count(str_ + ext_) == 0)
1698       return;
1699     h1_ = (TH1*)_eb_loc_m[str_ + ext_];
1700     if (h1_ == 0)
1701       return;
1702     win_->setCurHist(h1_);
1703     h1_->Draw();
1704     title_ = h1_->GetTitle();
1705     title_.ReplaceAll(" ", ".");
1706     title_ += ".LOCAL";
1707     _curPad->Modified();
1708     _curPad->Update();
1709 
1710     win_->setPrintName(_psdir + title_ + ".ps");
1711     win_->write();
1712   }
1713 }
1714 
1715 void MusEcalGUI::drawMTQHist(int opt) {
1716   //   TString str_;
1717   //   TH1* h1_;
1718   //   TString WName_;
1719   //   TString title_;
1720   //   MEPlotWindow* win_;
1721 
1722   //   TString varName_;
1723   //   varName_=ME::PNPrimVar[_ihist];
1724   //   str_="MTQ-";
1725 
1726   //   str_+=varName_;
1727 
1728   //   // the full barrel 1D
1729   //   WName_ = "EB_MTQ";
1730   //   win_ = getWindow( WName_, opt, 900, 300 );
1731   //   if( win_!=0 )
1732   //     {
1733   //       _curPad = win_->getPad();
1734   //       _curPad->cd();
1735   //       h1_ = (TH1*) _eb_m[str_];
1736   //       assert( h1_!=0 );
1737   //       float max_ = h1_->GetMaximum();
1738   //       float min_ = h1_->GetMinimum();
1739   //       h1_->SetMaximum(max_); // !!!
1740   //       h1_->Draw();
1741   //       float x_=-0.5;
1742   //       for( int ilmr=1; ilmr<=72; ilmr++ )
1743   //    {
1744   //      if( ilmr!=1 && (ilmr-1)%2==0 ) x_+=8;
1745   //      if( (ilmr-1)%2==1 )             x_+=10;
1746   //      if( ilmr==1 ) continue;
1747   //      TLine* l = new TLine( x_, min_+0.01*(max_-min_),
1748   //                x_, max_-0.01*(max_-min_) );
1749   //      if( (ilmr-1)%2==0 )
1750   //        {
1751   //          l->SetLineColor(kRed);
1752   //          l->SetLineWidth(2);
1753   //        }
1754   //      else
1755   //        {
1756   //          l->SetLineColor(kGreen);
1757   //        }
1758   //      l->Draw("Same");
1759 
1760   //      if( (ilmr-1)%2==0 ) continue;
1761   //      TText* text_ = new TText( x_, min_+0.80*(max_-min_), ME::smName( ilmr ) );
1762   //      text_->SetTextSize(0.05);
1763   //      text_->SetTextAngle(90);
1764   //      text_->SetTextAlign(12);
1765   //      text_->Draw("Same");
1766   //    }
1767   //       h1_->Draw("Same");
1768 
1769   //       win_->setCurHist( h1_ );
1770   //       _curPad->Modified();
1771   //       _curPad->Update();
1772 
1773   //       title_ = h1_->GetTitle();
1774   //       title_.ReplaceAll(" ",".");
1775   //       title_+=".GLOBAL";
1776   //       win_->setPrintName( _psdir+title_+".ps" );
1777   //       win_->write();
1778   //     }
1779 
1780   //   // then the current super-module
1781   //   WName_ = "EBLocal_PN";
1782   //   win_ = getWindow( WName_, opt, 700, 450 );
1783   //   if( win_!=0 )
1784   //     {
1785   //       _curPad = (TPad*) win_->getPad();
1786   //       _curPad->cd();
1787   //       _curPad->SetGridx(1);
1788   //       _curPad->SetGridy(1);
1789   //       TString ext_="_LOCAL";
1790   //       if( _eb_loc_m.count( str_+ext_ )==0 ) return;
1791   //       h1_ = (TH1*) _eb_loc_m[str_+ext_];
1792   //       if( h1_==0 ) return;
1793   //       win_->setCurHist( h1_ );
1794   //       h1_->Draw();
1795   //       title_ = h1_->GetTitle();
1796   //       title_.ReplaceAll(" ",".");
1797   //       title_+=".LOCAL";
1798   //       _curPad->Modified();
1799   //       _curPad->Update();
1800 
1801   //       win_->setPrintName( _psdir+title_+".ps" );
1802   //       win_->write();
1803   //     }
1804 
1805   cout << "drawMTQHist not implemented yet " << endl;
1806 }
1807 
1808 // FIXME! this is a test
1809 void MusEcalGUI::drawAPDAnim(int opt) {
1810   TString str_;
1811   TH2* h2_;
1812   //  TH1* h1_;
1813   TString WName_;
1814   TString title_;
1815   MEPlotWindow* win_;
1816 
1817   // FIXME!!!!
1818   TString fname_(std::getenv("MESTORE"));
1819   fname_ += "/EBGlobalHist.root";
1820   FILE* test;
1821   //  cout << fname_ << endl;
1822   test = fopen(fname_, "r");
1823   if (test == 0) {
1824     cout << "Histogam file not present: ";
1825     cout << "please run bin/createEBGlobalHistFile first";
1826     cout << endl;
1827     return;
1828   }
1829   fclose(test);
1830   TFile* file = TFile::Open(fname_);
1831   assert(file != 0);
1832 
1833   TString varName_;
1834   if (_type == ME::iLaser) {
1835     varName_ = ME::APDPrimVar[_ihist];
1836     str_ = "APD-";
1837   } else if (_type == ME::iTestPulse) {
1838     varName_ = ME::TPAPDPrimVar[_ihist];
1839     str_ = "TPAPD-";
1840   }
1841   str_ += varName_;
1842 
1843   // the full barrel 2D
1844   WName_ = "EB_ANIM";
1845   win_ = getWindow(WName_, opt, 450, 700);
1846   if (win_ != 0) {
1847     _curPad = win_->getPad();
1848     _curPad->cd();
1849 
1850     int ii = 0;
1851     while (1) {
1852       ii++;
1853       TString hname_ = str_;
1854       hname_ += ";";
1855       hname_ += ii;
1856       h2_ = (TH2*)file->Get(hname_);
1857       if (h2_ == 0)
1858         break;
1859       h2_->Draw("COLZ");
1860       MEEBDisplay::drawEBGlobal();
1861       _window[WName_]->setCurHist(h2_);
1862       _curPad->Modified();
1863       _curPad->Update();
1864 
1865       title_ = str_;
1866       //      title_ += ".gif+50";
1867       //      title_ = h2_->GetTitle();
1868       //      title_.ReplaceAll(" ",".");
1869       //      title_+=".ANIM";
1870       win_->setPrintName(_psdir + title_ + ".gif+50");
1871       win_->write();
1872       //      string dum;
1873       //      cin >> dum;
1874     }
1875   }
1876 
1877   file->Close();
1878   setTime(_time);
1879 
1880   //   // the full barrel 1D
1881   //   WName_ = "EB_1D";
1882   //   win_ = getWindow( WName_, opt, 900, 300 );
1883   //   if( win_!=0 )
1884   //     {
1885   //       _curPad =  win_->getPad();
1886   //       _curPad->cd();
1887 
1888   //       TString ext_="_1D";
1889   //       h1_ = (TH1*) _eb_m[str_+ext_];
1890   //       assert( h1_!=0 );
1891   //       h1_->Draw();
1892   //       float max_ = h1_->GetMaximum();
1893   //       float min_ = h1_->GetMinimum();
1894   //       float x_=-0.5;
1895   //       for( int ilmr=1; ilmr<=72; ilmr++ )
1896   //    {
1897   //      if( ilmr!=1 && (ilmr-1)%2==0 ) x_+=800/25;
1898   //      if( (ilmr-1)%2==1 )             x_+=900/25;
1899   //      if( ilmr==1 ) continue;
1900   //      TLine* l = new TLine( x_, min_+0.01*(max_-min_),
1901   //                x_, max_-0.01*(max_-min_) );
1902   //      if( (ilmr-1)%2==0 )
1903   //        {
1904   //          l->SetLineColor(kRed);
1905   //          l->SetLineWidth(2);
1906   //        }
1907   //      else
1908   //        {
1909   //          l->SetLineColor(kGreen);
1910   //        }
1911   //      l->Draw("Same");
1912 
1913   //      if( (ilmr-1)%2==0 ) continue;
1914   //      TText* text_ = new TText( x_, min_+0.80*(max_-min_), ME::smName( ilmr ) );
1915   //      text_->SetTextSize(0.05);
1916   //      text_->SetTextAngle(90);
1917   //      text_->SetTextAlign(12);
1918   //      text_->Draw("Same");
1919   //    }
1920   //       h1_->Draw("Same");
1921 
1922   //       win_->setCurHist( h1_ );
1923   //       _curPad->Modified();
1924   //       _curPad->Update();
1925 
1926   //       title_ = h1_->GetTitle();
1927   //       title_.ReplaceAll(" ",".");
1928   //       title_+=".1D";
1929   //       win_->setPrintName( _psdir+title_ );
1930   //       win_->write();
1931   //     }
1932 
1933   //   // then the current super-module
1934   //   WName_ = "EBLocal";
1935   //   win_ = getWindow( WName_, opt, 700, 450 );
1936   //   if( win_!=0 )
1937   //     {
1938   //       _curPad = (TPad*) win_->getPad();
1939   //       _curPad->cd();
1940   //       TString ext_;
1941   //       if( _ihtype==iMAP )
1942   //    {
1943   //      _curPad->SetGridx(0);
1944   //      _curPad->SetGridy(0);
1945   //      h2_ = (TH2*) _eb_loc_m[str_+ext_];
1946   //      assert( h2_!=0 );
1947   //      win_->setCurHist( h2_ );
1948   //      h2_->Draw("COLZ");
1949   //      MEEBDisplay::drawEBLocal();
1950   //      title_ = h2_->GetTitle();
1951   //      title_.ReplaceAll(" ",".");
1952   //      title_+=".MAP";
1953   //    }
1954   //       else if( _ihtype==iHIST )
1955   //    {
1956   //      _curPad->SetGridx(1);
1957   //      _curPad->SetGridy(0);
1958   //      ext_="_HIST";
1959   //      if( _eb_loc_m.count( str_+ext_ )==0 ) return;
1960   //      h1_ = (TH1*) _eb_loc_m[str_+ext_];
1961   //      if( h1_==0 ) return;
1962   //      win_->setCurHist( h1_ );
1963   //      h1_->Draw();
1964   //      ext_+="_sel";
1965   //      h1_ = (TH1*) _eb_loc_m[str_+ext_];
1966   //      h1_->Draw("Same");
1967   //      title_ = h1_->GetTitle();
1968   //      title_.ReplaceAll(" ",".");
1969   //      title_+=".HIST";
1970   //    }
1971   //       else if( _ihtype==iVS_CHANNEL )
1972   //    {
1973   //      _curPad->SetGridx(1);
1974   //      _curPad->SetGridy(1);
1975   //      ext_="_VS_CHANNEL";
1976   //      if( _eb_loc_m.count( str_+ext_ )==0 ) return;
1977   //      h1_ = (TH1*) _eb_loc_m[str_+ext_];
1978   //      if( h1_==0 ) return;
1979   //      win_->setCurHist( h1_ );
1980   //      h1_->Draw();
1981   //      ext_+="_sel";
1982   //      h1_ = (TH1*) _eb_loc_m[str_+ext_];
1983   //      h1_->Draw("Same");
1984   //      title_ = h1_->GetTitle();
1985   //      title_.ReplaceAll(" ",".");
1986   //      title_+=".VS_CHANNEL";
1987   //    }
1988   //       _curPad->Modified();
1989   //       _curPad->Update();
1990 
1991   //       win_->setPrintName( _psdir+title_ );
1992   //       win_->write();
1993   //     }
1994 }
1995 
1996 void MusEcalGUI::createRunPanel() {
1997   delete _fRunPanel;
1998   _fRunPanel = new MERunPanel(gClient->GetRoot(), this, 600, 300);
1999 }
2000 
2001 void MusEcalGUI::createChanPanel(bool ifexists) {
2002   if (ifexists && _fChanPanel == 0)
2003     return;
2004   delete _fChanPanel;
2005   _fChanPanel = new MEChanPanel(gClient->GetRoot(), this, 400, 150);
2006 }
2007 
2008 void MusEcalGUI::createLeafPanel() {
2009   delete _fLeafPanel;
2010   _fLeafPanel = new MELeafPanel(gClient->GetRoot(), this, 400, 150);
2011 }
2012 
2013 void MusEcalGUI::createMultiVarPanel() {
2014   delete _fMultiVarPanel;
2015   _fMultiVarPanel = new MEMultiVarPanel(gClient->GetRoot(), this, 400, 150);
2016 }
2017 
2018 void MusEcalGUI::refresh() {
2019   MusEcal::refresh();
2020   fillHistograms();
2021   drawAPDHist();
2022   drawPNHist();
2023   historyPlot();
2024 }
2025 
2026 void MusEcalGUI::setType(int type, int color) {
2027   MusEcal::setType(type, color);
2028   refresh();
2029 }
2030 
2031 void MusEcalGUI::setLMRegion(int lmr) {
2032   MusEcal::setLMRegion(lmr);
2033   setLMRMenu();
2034 }
2035 
2036 void MusEcalGUI::setTime(ME::Time time) {
2037   MusEcal::setTime(time);
2038   refresh();
2039 }
2040 
2041 void MusEcalGUI::setChannel(MEChannel* leaf) {
2042   MusEcal::setChannel(leaf);
2043 
2044   if (isBarrel()) {
2045     cout << "GHM !!!! call to fillEBLocalHistogram !!! " << endl;
2046     fillEBLocalHistograms();
2047   } else {
2048     cout << "GHM !!!! call to fillEELocalHistogram !!! " << endl;
2049     fillEELocalHistograms();
2050   }
2051 
2052   cout << "....Done !!! " << endl;
2053 
2054   drawAPDHist();
2055   historyPlot();
2056 }
2057 
2058 void MusEcalGUI::drawHistoryGraph(unsigned int n,
2059                                   float* x,
2060                                   float* y,
2061                                   float* ex,
2062                                   float* ey,
2063                                   bool* ok,
2064                                   int markerStyle,
2065                                   float markerSize,
2066                                   int markerColor,
2067                                   int lineWidth,
2068                                   int lineColor,
2069                                   const char* graphOpt) {
2070   int nn = 0;
2071   float xx[n];
2072   float yy[n];
2073   float exx[n];
2074   float eyy[n];
2075   float ok_(true);
2076 
2077   for (unsigned int ii = 0; ii < n; ii++) {
2078     if (ok != 0) {
2079       ok_ = ok[ii];
2080     } else {
2081       ok_ = true;
2082     }
2083     if (ok_) {
2084       xx[nn] = x[ii];
2085       yy[nn] = y[ii];
2086       if (ex != 0) {
2087         exx[nn] = ex[ii];
2088         eyy[nn] = ey[ii];
2089       } else {
2090         exx[nn] = 0;
2091         eyy[nn] = 0;
2092       }
2093       nn++;
2094     }
2095     if (!ok_ || ii == n - 1) {
2096       if (nn != 0) {
2097         TGraph* gr = new TGraphErrors(nn, xx, yy, exx, eyy);
2098         gr->SetMarkerStyle(markerStyle);
2099         gr->SetMarkerSize(markerSize);
2100         gr->SetMarkerColor(markerColor);
2101         gr->SetLineWidth(lineWidth);
2102         gr->SetLineColor(lineColor);
2103         gr->Draw(graphOpt);
2104       }
2105       nn = 0;
2106     }
2107   }
2108 }
2109 
2110 void MusEcalGUI::setLMRMenu() {
2111   TGMenuEntry* lmrentry_ = f_Channel_Menu->GetEntry("LMR");
2112   if (lmrentry_ != 0) {
2113     // cleanup the LMR menu
2114     for (unsigned int ii = 0; ii < f_tree_menu.size(); ii++) {
2115       delete f_tree_menu[ii];
2116     }
2117     f_tree_menu.clear();
2118     f_Channel_Menu->DeleteEntry(lmrentry_);
2119     //      delete lmrentry_;
2120   }
2121   TGPopupMenu* menu_ = new TGPopupMenu(gClient->GetRoot());
2122   f_Channel_Menu->AddPopup("LMR", menu_);
2123 
2124   MEChannel* tree_ = curMgr()->tree();
2125   for (unsigned int ii = 0; ii < tree_->n(); ii++) {
2126     MEChannel* lmm_ = tree_->d(ii);
2127     TGPopupMenu* menu1_ = new TGPopupMenu(gClient->GetRoot());
2128     f_tree_menu.push_back(menu1_);
2129     menu_->AddPopup(lmm_->oneLine(), menu1_);
2130     for (unsigned int jj = 0; jj < lmm_->n(); jj++) {
2131       MEChannel* sc_ = lmm_->d(jj);
2132       TGPopupMenu* menu2_ = new TGPopupMenu(gClient->GetRoot());
2133       f_tree_menu.push_back(menu2_);
2134       menu2_->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleChannelMenu(Int_t)");
2135       menu1_->AddPopup(sc_->oneWord(), menu2_);
2136       for (unsigned int kk = 0; kk < sc_->n(); kk++) {
2137         MEChannel* c_ = sc_->d(kk);
2138         menu2_->AddEntry(c_->oneWord(), 10000 + c_->id());
2139       }
2140     }
2141   }
2142 }
2143 
2144 void MusEcalGUI::setupMainWindow() {
2145   UInt_t h = GetHeight();
2146   UInt_t w = GetWidth();
2147   const UInt_t LimSmallScreen = 800;
2148   const UInt_t hlow = 75;
2149   const UInt_t wminus = 180;
2150   UInt_t hless = h - hlow;
2151 
2152   fL2 = new TGLayoutHints(kLHintsCenterX | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5);
2153   if (h > LimSmallScreen) {
2154     fL1 = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 0);
2155     fL5 = new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 5, 5, 5, 5);
2156     fLb = new TGLayoutHints(kLHintsLeft, 5, 5, 5, 5);
2157   } else {
2158     fL1 = new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0);
2159     fL5 = new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 0, 0, 0, 0);
2160     fLb = new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0);
2161   }
2162   fL8 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5);
2163 
2164   fHFrame1 = new TGHorizontalFrame(this, w, hless);
2165   fVFrame = new TGVerticalFrame(fHFrame1, wminus - 10, hless);
2166   fHFrame1->AddFrame(fVFrame, fLb);
2167 
2168   fMenuDock = new TGDockableFrame(this);
2169   AddFrame(fMenuDock, new TGLayoutHints(kLHintsExpandX, 0, 0, 1, 0));
2170   fMenuDock->SetWindowName("MusEcal Menu");
2171 
2172   fMenuBarLayout = new TGLayoutHints(kLHintsTop | kLHintsExpandX);
2173   fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
2174 
2175   //
2176   // File menu
2177   //
2178   f_File_Menu = new TGPopupMenu(gClient->GetRoot());
2179   f_File_Menu->AddEntry("D&ump Vector to Ascii File", 1);
2180   f_File_Menu->AddSeparator();
2181   f_File_Menu->AddEntry("R&un Panel", 3);
2182   f_File_Menu->AddSeparator();
2183   f_File_Menu->AddEntry("W&elcome", 4);
2184   f_File_Menu->AddSeparator();
2185   f_File_Menu->AddEntry("E&xit", 0);
2186   f_File_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleFileMenu(Int_t)");
2187 
2188   //
2189   // Histogram menu
2190   //
2191   f_Hist_Menu = new TGPopupMenu(gClient->GetRoot());
2192   f_Hist_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2193   f_Laser_Menu = new TGPopupMenu(gClient->GetRoot());
2194   f_Laser_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2195   f_APD_Menu = new TGPopupMenu(gClient->GetRoot());
2196   f_APD_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2197   f_PN_Menu = new TGPopupMenu(gClient->GetRoot());
2198   f_PN_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2199   f_MTQ_Menu = new TGPopupMenu(gClient->GetRoot());
2200   f_MTQ_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2201   for (int icol = 0; icol < ME::iSizeC; icol++) {
2202     f_APD_Hist_Menu[icol] = new TGPopupMenu(gClient->GetRoot());
2203     f_APD_Hist_Menu[icol]->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2204     for (int ii = 0; ii < ME::iSizeAPD; ii++) {
2205       int jj = 100 * icol + ii;
2206       f_APD_Hist_Menu[icol]->AddEntry(ME::APDPrimVar[ii], jj);
2207       if (_type != ME::iLaser || _color != icol)
2208         f_APD_Hist_Menu[icol]->DisableEntry(jj);
2209     }
2210     f_APD_Menu->AddPopup(ME::color[icol], f_APD_Hist_Menu[icol]);
2211 
2212     f_PN_Hist_Menu[icol] = new TGPopupMenu(gClient->GetRoot());
2213     f_PN_Hist_Menu[icol]->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2214     for (int ii = 0; ii < ME::iSizePN; ii++) {
2215       int jj = 1000 + 100 * icol + ii;
2216       f_PN_Hist_Menu[icol]->AddEntry(ME::PNPrimVar[ii], jj);
2217       if (_type != ME::iLaser || _color != icol)
2218         f_PN_Hist_Menu[icol]->DisableEntry(jj);
2219     }
2220     f_PN_Menu->AddPopup(ME::color[icol], f_PN_Hist_Menu[icol]);
2221 
2222     f_MTQ_Hist_Menu[icol] = new TGPopupMenu(gClient->GetRoot());
2223     f_MTQ_Hist_Menu[icol]->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2224     for (int ii = 0; ii < ME::iSizeMTQ; ii++) {
2225       int jj = 2000 + 100 * icol + ii;
2226       f_MTQ_Hist_Menu[icol]->AddEntry(ME::MTQPrimVar[ii], jj);
2227       if (_type != ME::iLaser || _color != icol)
2228         f_MTQ_Hist_Menu[icol]->DisableEntry(jj);
2229     }
2230     f_MTQ_Menu->AddPopup(ME::color[icol], f_MTQ_Hist_Menu[icol]);
2231   }
2232   f_Laser_Menu->AddPopup("APD", f_APD_Menu);
2233   f_Laser_Menu->AddPopup("PN", f_PN_Menu);
2234   f_Laser_Menu->AddPopup("MTQ", f_MTQ_Menu);
2235   f_Hist_Menu->AddPopup("Laser", f_Laser_Menu);
2236 
2237   f_TP_Menu = new TGPopupMenu(gClient->GetRoot());
2238   f_TP_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2239   f_TPAPD_Hist_Menu = new TGPopupMenu(gClient->GetRoot());
2240   f_TPAPD_Hist_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2241   for (int ii = 0; ii < ME::iSizeTPAPD; ii++) {
2242     int jj = ii;
2243     f_TPAPD_Hist_Menu->AddEntry(ME::TPAPDPrimVar[ii], jj);
2244     if (_type != ME::iTestPulse)
2245       f_TPAPD_Hist_Menu->DisableEntry(jj);
2246   }
2247 
2248   f_TPPN_Hist_Menu = new TGPopupMenu(gClient->GetRoot());
2249   f_TPPN_Hist_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistMenu(Int_t)");
2250   for (int ii = 0; ii < ME::iSizeTPPN; ii++) {
2251     int jj = 1000 + ii;
2252     f_TPPN_Hist_Menu->AddEntry(ME::TPPNPrimVar[ii], jj);
2253     if (_type != ME::iTestPulse)
2254       f_TPPN_Hist_Menu->DisableEntry(jj);
2255   }
2256   f_TP_Menu->AddPopup("APD", f_TPAPD_Hist_Menu);
2257   f_TP_Menu->AddPopup("PN", f_TPPN_Hist_Menu);
2258   f_Hist_Menu->AddPopup("Test Pulse", f_TP_Menu);
2259 
2260   f_Hist_Menu->AddSeparator();
2261   f_Hist_Menu->AddEntry("Histogram", 1000000 + iHIST);
2262   f_Hist_Menu->AddEntry("vs Channel-ID", 1000000 + iVS_CHANNEL);
2263   f_Hist_Menu->AddEntry("Map", 1000000 + iMAP);
2264 
2265   f_Hist_Menu->AddSeparator();
2266   f_Hist_Menu->AddEntry("Animation", -1000);
2267 
2268   //
2269   // Channel menu
2270   //
2271   f_Channel_Menu = new TGPopupMenu(gClient->GetRoot());
2272   f_Channel_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleChannelMenu(Int_t)");
2273   f_Channel_Menu->AddEntry("Laser Monitoring Region", ME::iLMRegion);
2274   f_Channel_Menu->AddEntry("Laser Monitoring Module", ME::iLMModule);
2275   f_Channel_Menu->AddEntry("Super Crystal", ME::iSuperCrystal);
2276   f_Channel_Menu->AddEntry("Crystal", ME::iCrystal);
2277 
2278   f_Channel_Menu->AddSeparator();
2279   f_Channel_Menu->AddEntry("One Level Up", 50000);
2280 
2281   f_Channel_Menu->AddSeparator();
2282 
2283   f_Channel_Menu->AddEntry("Channel panel", 60000);
2284 
2285   f_Channel_Menu->AddSeparator();
2286 
2287   map<TString, TGPopupMenu*> _menu;
2288   TString str_ = "ECAL";
2289   _menu[str_] = new TGPopupMenu(gClient->GetRoot());
2290   for (int ireg = 0; ireg < ME::iSizeE; ireg++) {
2291     TString str1_ = str_ + "_";
2292     str1_ += ME::region[ireg];
2293     _menu[str1_] = new TGPopupMenu(gClient->GetRoot());
2294     _menu[str_]->AddPopup(ME::region[ireg], _menu[str1_]);
2295     MEChannel* tree_ = ME::regTree(ireg);
2296     for (unsigned int ii = 0; ii < tree_->n(); ii++) {
2297       MEChannel* sect_ = tree_->d(ii);
2298       int isect_ = sect_->id();
2299       TString str2_ = str1_ + "_";
2300       str2_ += ii;
2301       _menu[str2_] = new TGPopupMenu(gClient->GetRoot());
2302       _menu[str2_]->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleChannelMenu(Int_t)");
2303       _menu[str1_]->AddPopup(ME::smName(ireg, isect_), _menu[str2_]);
2304       for (unsigned int jj = 0; jj < sect_->n(); jj++) {
2305         MEChannel* lmr_ = sect_->d(jj);
2306         int ilmr_ = lmr_->id();
2307         TString str3_ = lmr_->oneLine();
2308         _menu[str2_]->AddEntry(str3_, 1000 + ilmr_);
2309       }
2310     }
2311   }
2312   f_Channel_Menu->AddPopup(str_, _menu[str_]);
2313   setLMRMenu();
2314 
2315   //
2316   // History menu
2317   //
2318   f_History_Menu = new TGPopupMenu(gClient->GetRoot());
2319   f_History_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistoryMenu(Int_t)");
2320   f_History_L_Menu = new TGPopupMenu(gClient->GetRoot());
2321   f_History_L_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistoryMenu(Int_t)");
2322 
2323   for (int icol = 0; icol < ME::iSizeC; icol++) {
2324     f_History_LV_Menu[icol] = new TGPopupMenu(gClient->GetRoot());
2325     f_History_LV_Menu[icol]->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistoryMenu(Int_t)");
2326     for (int ii = 0; ii < MusEcal::iSizeLV; ii++) {
2327       int jj = 100 * icol + ii;
2328       f_History_LV_Menu[icol]->AddEntry(MusEcal::historyVarName[ii], jj);
2329       if (_type != ME::iLaser || _color != icol)
2330         f_History_LV_Menu[icol]->DisableEntry(jj);
2331     }
2332     f_History_L_Menu->AddPopup(ME::color[icol], f_History_LV_Menu[icol]);
2333   }
2334 
2335   f_History_Menu->AddPopup("Laser", f_History_L_Menu);
2336 
2337   f_History_TPV_Menu = new TGPopupMenu(gClient->GetRoot());
2338   f_History_TPV_Menu->Connect("Activated(Int_t)", "MusEcalGUI", this, "HandleHistoryMenu(Int_t)");
2339   for (int ii = 0; ii < MusEcal::iSizeTPV; ii++) {
2340     int jj = ii;
2341     f_History_TPV_Menu->AddEntry(MusEcal::historyTPVarName[ii], jj);
2342     if (_type != ME::iTestPulse)
2343       f_History_TPV_Menu->DisableEntry(jj);
2344   }
2345   f_History_Menu->AddPopup("TestPulse", f_History_TPV_Menu);
2346 
2347   f_History_Menu->AddSeparator();
2348   f_History_Menu->AddEntry("Normalized (toggle)", -10);
2349   f_History_Menu->AddSeparator();
2350   f_History_Menu->AddEntry("vs Time (hrs)", -100);
2351   f_History_Menu->AddEntry("Projection", -101);
2352   f_History_Menu->AddSeparator();
2353   f_History_Menu->AddEntry("Multi-Var", -2000);
2354   f_History_Menu->AddEntry("Leaf", -1000);
2355 
2356   fMenuDock->EnableUndock(kTRUE);
2357   fMenuDock->EnableHide(kTRUE);
2358 
2359   fMenuBar = new TGMenuBar(fMenuDock, 1, 1, kHorizontalFrame);
2360   fMenuBar->AddPopup("&MusEcal", f_File_Menu, fMenuBarItemLayout);
2361   fMenuBar->AddPopup("&Histograms", f_Hist_Menu, fMenuBarItemLayout);
2362   fMenuBar->AddPopup("&Channels", f_Channel_Menu, fMenuBarItemLayout);
2363   fMenuBar->AddPopup("&Histories", f_History_Menu, fMenuBarItemLayout);
2364 
2365   fMenuDock->AddFrame(fMenuBar, fMenuBarLayout);
2366 
2367   fEcanvas = new MEClickableCanvas("Ecanvas", fHFrame1, w - wminus, hless, this);
2368 
2369   fHFrame1->AddFrame(fEcanvas, fL1);
2370   fHFrame2 = new TGHorizontalFrame(this, w, 65);
2371 
2372   AddFrame(fHFrame1, fL2);
2373   AddFrame(fHFrame2, fL5);
2374 
2375   TString windowname = "MusEcal";
2376   SetWindowName(windowname);
2377 
2378   MapSubwindows();
2379   Resize(GetDefaultSize());
2380 
2381   SetWMPosition(2, 2);
2382   MapWindow();
2383 
2384   SetCanvas(fEcanvas->GetCanvas(), "MusEcal - Main Window", "", "", "");
2385 
2386   //  welcome();
2387   ShowWelcome(true);
2388 
2389   cout << "... and now enjoy the GUI!" << endl;
2390 }
2391 
2392 MEPlotWindow* MusEcalGUI::getWindow(TString WName_, int opt, int w, int h) {
2393   if (opt != 0) {
2394     if (opt == 2 && _window.count(WName_) != 0) {
2395       delete _window[WName_];
2396       _window[WName_] = 0;
2397     }
2398     if (_window.count(WName_) == 0 || _window[WName_] == 0) {
2399       _window[WName_] = new MEPlotWindow(gClient->GetRoot(), this, WName_, w, h);
2400     }
2401   }
2402   if (_window.count(WName_) != 0) {
2403     return _window[WName_];
2404   }
2405   return 0;
2406 }