Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:56

0001 #include <iostream>
0002 #include <cassert>
0003 #include <iostream>
0004 #include <fstream>
0005 using namespace std;
0006 
0007 #include "MusEcal.hh"
0008 #include "../../interface/MEChannel.h"
0009 #include "MERun.hh"
0010 #include "MERunManager.hh"
0011 #include "MEVarVector.hh"
0012 #include "MECanvasHolder.hh"
0013 #include "../../interface/MEGeom.h"
0014 
0015 #include <TMath.h>
0016 
0017 ClassImp(MusEcal);
0018 
0019 bool MusEcal::verbose = true;
0020 
0021 TString MusEcal::historyVarTitle[MusEcal::iSizeLV] = {"Normalized LASER Signal",
0022                                                       "Corrected Normalized LASER Signal",
0023                                                       "Ratio APD over PNA",
0024                                                       "Ratio APD over PNB",
0025                                                       "Ratio APD over PN",
0026                                                       "APD",
0027                                                       "APD Time",
0028                                                       "Normalization PNA",
0029                                                       "Normalization PNB",
0030                                                       "Ratio PNB over PNA",
0031                                                       "Time Rise = alpha*beta",
0032                                                       "alpha*beta (used)",
0033                                                       "Shape Correction",
0034                                                       "MATACQ Time Rise",
0035                                                       "MATACQ Amplitude",
0036                                                       "MATACQ Full Width at Half Maximum",
0037                                                       "MATACQ Full Width at 20\%",
0038                                                       "MATACQ Full Width at 80\%",
0039                                                       "MATACQ Time"};
0040 
0041 TString MusEcal::historyVarName[MusEcal::iSizeLV] = {"NLS",
0042                                                      "CorNLS",
0043                                                      "APDoPNA",
0044                                                      "APDoPNB",
0045                                                      "APDoPN",
0046                                                      "APD",
0047                                                      "APDTime",
0048                                                      "PNA",
0049                                                      "PNB",
0050                                                      "PNBoPNA",
0051                                                      "alpha*beta",
0052                                                      "alpha*beta used",
0053                                                      "Shape Correction",
0054                                                      "MATACQ time rise",
0055                                                      "MATACQ amplitude",
0056                                                      "MATACQ fwhm",
0057                                                      "MATACQ fw20",
0058                                                      "MATACQ fw80",
0059                                                      "MATACQ time"};
0060 
0061 int MusEcal::iGVar[MusEcal::iSizeLV] = {
0062     ME::iCrystal,   // NLS
0063     ME::iCrystal,   // CorNLS
0064     ME::iCrystal,   // APDoPNA
0065     ME::iCrystal,   // APDoPNB
0066     ME::iCrystal,   // APDoPN
0067     ME::iCrystal,   // APD
0068     ME::iCrystal,   // APDTime
0069     ME::iLMModule,  // PNA
0070     ME::iLMModule,  // PNB
0071     ME::iLMModule,  // PNBoPNA
0072     ME::iCrystal,   // alpha*beta
0073     ME::iCrystal,   // alpha*beta used
0074     ME::iCrystal,   // shape correction
0075     ME::iLMRegion,  // MATACQ time rise
0076     ME::iLMRegion,  // MATACQ amplitude
0077     ME::iLMRegion,  // MATACQ fwhm
0078     ME::iLMRegion,  // MATACQ fw20
0079     ME::iLMRegion,  // MATACQ fw80
0080     ME::iLMRegion   // MATACQ time
0081 };
0082 
0083 int MusEcal::historyVarZoom[ME::iSizeC][MusEcal::iSizeLV] = {{
0084                                                                  MusEcal::iZero,           // NLS
0085                                                                  MusEcal::iZero,           // CorNLS
0086                                                                  MusEcal::iZero,           // APDoPNA
0087                                                                  MusEcal::iZero,           // APDoPNB
0088                                                                  MusEcal::iZero,           // APDoPN
0089                                                                  MusEcal::iThirtyPercent,  // APD
0090                                                                  MusEcal::iTenPercent,     // APDTime
0091                                                                  MusEcal::iZero,           // PNA
0092                                                                  MusEcal::iZero,           // PNB
0093                                                                  MusEcal::iZero,           // PNBoPNA
0094                                                                  MusEcal::iTenPercent,     // AlphaBeta
0095                                                                  MusEcal::iZero,           // AlphaBeta used
0096                                                                  MusEcal::iZero,           // Shape correction
0097                                                                  MusEcal::iZero,           // MTQ_Trise
0098                                                                  MusEcal::iZero,           // MTQ_Ampl
0099                                                                  MusEcal::iZero,           // MTQ_Fwhm
0100                                                                  MusEcal::iZero,           // MTQ_Fw20
0101                                                                  MusEcal::iZero,           // MTQ_Fw80
0102                                                                  MusEcal::iZero            // MTQ_time
0103                                                              },
0104                                                              {
0105                                                                  MusEcal::iZero,           // NLS
0106                                                                  MusEcal::iZero,           // CorNLS
0107                                                                  MusEcal::iZero,           // APDoPNA
0108                                                                  MusEcal::iZero,           // APDoPNB
0109                                                                  MusEcal::iZero,           // APDoPN
0110                                                                  MusEcal::iThirtyPercent,  // APD
0111                                                                  MusEcal::iTenPercent,     // APDTime
0112                                                                  MusEcal::iZero,           // PNA
0113                                                                  MusEcal::iZero,           // PNB
0114                                                                  MusEcal::iZero,           // PNBoPNA
0115                                                                  MusEcal::iTenPercent,     // AlphaBeta
0116                                                                  MusEcal::iZero,           // AlphaBeta used
0117                                                                  MusEcal::iZero,           // Shape correction
0118                                                                  MusEcal::iZero,           // MTQ_Trise
0119                                                                  MusEcal::iZero,           // MTQ_Ampl
0120                                                                  MusEcal::iZero,           // MTQ_Fwhm
0121                                                                  MusEcal::iZero,           // MTQ_Fw20
0122                                                                  MusEcal::iZero,           // MTQ_Fw80
0123                                                                  MusEcal::iZero            // MTQ_time
0124                                                              }};
0125 
0126 int MusEcal::historyVarColor[MusEcal::iSizeLV] = {
0127     kBlue,     // NLS
0128     kRed,      // CorNLS
0129     kBlue,     // APDoPNA
0130     kBlue,     // APDoPNB
0131     kBlue,     // APDoPN
0132     kBlue,     // APD
0133     kBlue,     // APDTime
0134     kRed,      // PNA
0135     kRed,      // PNB
0136     kRed,      // PNBoPNA
0137     kMagenta,  // AlphaBeta
0138     kMagenta,  // AlphaBeta used
0139     kMagenta,  // Shape correction
0140     kGreen,    // MTQ_Trise
0141     kGreen,    // MTQ_Ampl
0142     kGreen,    // MTQ_Fwhm
0143     kGreen,    // MTQ_Fw20
0144     kGreen,    // MTQ_Fw80
0145     kGreen     // MTQ_time
0146 };
0147 
0148 TString MusEcal::historyTPVarName[MusEcal::iSizeTPV] = {"Test-Pulse APD gain 0",
0149                                                         "Test-Pulse APD gain 1",
0150                                                         "Test-Pulse APD gain 2",
0151                                                         "Test-Pulse PNA gain 0",
0152                                                         "Test-Pulse PNA gain 1",
0153                                                         "Test-Pulse PNB gain 0",
0154                                                         "Test-Pulse PNB gain 1"};
0155 
0156 TString MusEcal::historyTPVarTitle[MusEcal::iSizeTPV] = {"Test-Pulse APD for Gain 0",
0157                                                          "Test-Pulse APD for Gain 1",
0158                                                          "Test-Pulse APD for Gain 2",
0159                                                          "Test-Pulse PNA for Gain 0",
0160                                                          "Test-Pulse PNA for Gain 1",
0161                                                          "Test-Pulse PNB for Gain 0",
0162                                                          "Test-Pulse PNB for Gain 1"};
0163 
0164 int MusEcal::iGTPVar[MusEcal::iSizeTPV] = {
0165     ME::iCrystal,   // Test-Pulse APD gain 0
0166     ME::iCrystal,   // Test-Pulse APD gain 1
0167     ME::iCrystal,   // Test-Pulse APD gain 2
0168     ME::iLMModule,  // Test-Pulse PNA gain 0
0169     ME::iLMModule,  // Test-Pulse PNA gain 1
0170     ME::iLMModule,  // Test-Pulse PNB gain 0
0171     ME::iLMModule   // Test-Pulse PNB gain 1
0172 };
0173 
0174 int MusEcal::historyTPVarColor[MusEcal::iSizeTPV] = {kCyan, kCyan + 150, kBlue, kBlue, kRed, kRed + 150, kRed + 100};
0175 
0176 int MusEcal::historyTPVarZoom[MusEcal::iSizeTPV] = {MusEcal::iThreePerMil,
0177                                                     MusEcal::iThreePerMil,
0178                                                     MusEcal::iThreePerMil,
0179                                                     MusEcal::iZero,
0180                                                     MusEcal::iZero,
0181                                                     MusEcal::iZero,
0182                                                     MusEcal::iZero};
0183 
0184 TString MusEcal::zoomName[MusEcal::iZero] = {"Range +/- 100%",
0185                                              "Range +/- 50%",
0186                                              "Range +/- 30%",
0187                                              "Range +/- 10%",
0188                                              "Range +/- 5%",
0189                                              "Range +/- 3%",
0190                                              "Range +/- 1%",
0191                                              "Range +/- 0.5%",
0192                                              "Range +/- 0.3%",
0193                                              "Range +/- 0.1%"};
0194 
0195 double MusEcal::zoomRange[MusEcal::iZero] = {1., 0.5, 0.3, 0.1, 0.05, 0.03, 0.01, 0.005, 0.003, 0.001};
0196 
0197 int MusEcal::firstRun = 0;
0198 int MusEcal::lastRun = 999999;
0199 
0200 MusEcal::MusEcal(int type, int color) {
0201   if (verbose)
0202     cout << "Welcome to MusEcal" << endl;
0203 
0204   // set type and color
0205   setType(type, color);
0206 
0207   // set default crystal: first crystal of the first monitoring region
0208   // leaf: selected first crystal by default
0209 
0210   _lmr = -1;
0211 
0212   map<TString, MERunManager*>::iterator it = _runMgr.begin();
0213   for (; it != _runMgr.end(); ++it) {
0214     MERunManager* mgr_ = it->second;
0215     if (mgr_->size() == 0)
0216       continue;
0217     int ilmr = mgr_->LMRegion();
0218     setLMRegion(ilmr);
0219     break;
0220   }
0221   assert(it != _runMgr.end());
0222 
0223   setChannel(ME::iCrystal, 0, 0, false);
0224 
0225   // set default time
0226   setDefaultTime();
0227 
0228   // set default variable
0229   setVar();
0230 
0231   // no debug by default
0232   _debug = true;
0233 
0234   // no GUI by default
0235   _isGUI = false;
0236 
0237   // histograms
0238   _histoBooked = false;
0239   _ebHistoBooked = false;
0240   _eeHistoBooked = false;
0241   _seq_t = 0;
0242 
0243   if (verbose)
0244     cout << "Enjoy!" << endl;
0245 }
0246 
0247 MusEcal::~MusEcal() {}
0248 
0249 void MusEcal::setType(int type, int color) {
0250   _type = type;
0251   if (verbose)
0252     cout << "Current type is: " << ME::type[_type] << endl;
0253 
0254   if (_type == ME::iLaser) {
0255     // default color
0256     _color = color;
0257     if (verbose)
0258       cout << "Current color is: " << ME::color[_color] << endl;
0259   }
0260 
0261   // Barrel: Laser monitoring regions between 1 and 92
0262   for (unsigned int lmr = 1; lmr <= 92; lmr++) {
0263     TString str_ = MusEcal::mgrName(lmr, _type, _color);
0264     if (_runMgr.count(str_) == 0) {
0265       MERunManager* runMgr_ = new MERunManager(lmr, _type, _color);
0266       if (runMgr_->size() == 0) {
0267         delete runMgr_;
0268         continue;
0269       }
0270       _runMgr[str_] = runMgr_;
0271     }
0272   }
0273 }
0274 
0275 void MusEcal::setLMRegion(int lmr) {
0276   if (lmr == _lmr)
0277     return;
0278   if (curMgr() != 0)
0279     curMgr()->refresh();
0280 
0281   _lmr = lmr;
0282   cout << "Current Laser monitoring region is: "
0283        //       << MusEcal::mgrName( _lmr, _type, _color )
0284        << _lmr << " (" << ME::smName(_lmr) << ")" << endl;
0285 
0286   // filling maps
0287   curMgr()->fillMaps();
0288 }
0289 
0290 //
0291 // access to run managers
0292 //
0293 MERunManager* MusEcal::runMgr(int lmr, int type, int color) {
0294   TString str_ = MusEcal::mgrName(lmr, type, color);
0295   if (_runMgr.count(str_) == 0) {
0296     //      cout << "Non existent Run manager" << endl;
0297     return 0;
0298   } else
0299     return _runMgr[str_];
0300 }
0301 
0302 void MusEcal::setTime(ME::Time time) {
0303   time_t t = time;
0304   if (verbose)
0305     cout << "Reference date: " << ctime(&t);
0306   map<TString, MERunManager*>::iterator it = _runMgr.begin();
0307   unsigned int currun_(0);
0308   unsigned int curlb_(0);
0309   for (; it != _runMgr.end(); ++it) {
0310     MERunManager* mgr_ = it->second;
0311     bool ok = mgr_->setCurrentRun(time);
0312     short int sign_(0);
0313     vector<ME::Time> dtvec;
0314     int nmaxlb = 7;
0315     if (ok) {
0316       MERun* run_ = mgr_->curRun();
0317       if (currun_ == 0) {
0318         currun_ = run_->run();
0319         curlb_ = run_->lb();
0320       }
0321       if (run_->run() != currun_)
0322         ok = false;
0323       else if (run_->lb() < curlb_ || run_->lb() > curlb_ + nmaxlb)
0324         ok = false;
0325       else {
0326         curlb_ = run_->lb();
0327         ME::Time t_ = run_->time();
0328         dtvec = ME::timeDiff(t_, time, sign_);
0329         if (dtvec[ME::iDay] != 0)
0330           ok = false;
0331         else if (dtvec[ME::iHour] != 0)
0332           ok = false;
0333         else if (dtvec[ME::iMinute] > 30)
0334           ok = false;
0335       }
0336     }
0337     if (!ok) {
0338       mgr_->setNoCurrent();
0339     }
0340     if (verbose) {
0341       int lmr_ = mgr_->LMRegion();
0342       cout << "LMR=" << lmr_ << " (" << ME::smName(lmr_) << ")";
0343       if (ok) {
0344         cout << " --> " << mgr_->curRun()->header().rundir << " d=" << dtvec[ME::iDay] << "/"
0345              << " h=" << dtvec[ME::iHour] << "/"
0346              << " m=" << dtvec[ME::iMinute] << "/"
0347              << " s=" << dtvec[ME::iSecond];
0348         if (sign_ != 0)
0349           cout << ((sign_ > 0) ? " in future" : " -------");
0350       } else {
0351         cout << "--> not in sequence ";
0352       }
0353       cout << endl;
0354     }
0355   }
0356   //  _time = time;
0357   //  _time = _runMgr.begin()->second->curRun()->time();
0358   _time = runMgr()->curRun()->time();
0359 }
0360 
0361 bool MusEcal::nextSequence() {
0362   // fixme: this assumes that the current LMR is always present
0363   //  MERunManager* mgr_ = _runMgr.begin()->second;
0364   MERunManager* mgr_ = runMgr();
0365   MusEcal::RunIterator it = mgr_->cur();
0366   if (it == mgr_->end())
0367     return false;
0368   ++it;
0369   if (it == mgr_->end())
0370     return false;
0371   ME::Time time = it->first;
0372   setTime(time);
0373   return true;
0374 }
0375 
0376 void MusEcal::setRunAndSequence(unsigned int irun, int iseq) {
0377   MERunManager* mgr_ = _runMgr.begin()->second;
0378   // MERunManager* mgr_ = runMgr();
0379   MusEcal::RunIterator runit = mgr_->it();
0380   for (; runit != mgr_->end(); ++runit) {
0381     MERun* run_ = runit->second;
0382     if (run_->run() == irun)
0383       iseq--;
0384     if (iseq == 0)
0385       break;
0386   }
0387   ME::Time time = runit->second->time();
0388   setTime(time);
0389 }
0390 
0391 void MusEcal::setDefaultTime() {
0392   MERunManager* mgr_ = _runMgr.begin()->second;
0393   // MERunManager* mgr_ = runMgr();
0394   MERun* run_ = mgr_->firstRun();
0395   if (run_ == 0) {
0396     cout << "run pointer is null " << endl;
0397     return;
0398   }
0399   ME::Time time = run_->time();
0400   setTime(time);
0401 }
0402 
0403 void MusEcal::dumpVector(int ivar) {
0404   // dummy !!!
0405   //  cout << "Dump current vector as ascii file" << endl;
0406   if (_leaf == 0) {
0407     cout << "Please select a channel first " << endl;
0408     return;
0409   }
0410   // test
0411   MEChannel* leaf_ = _leaf;
0412   MEVarVector* apdVector_ = curMgr()->apdVector(leaf_);
0413   vector<ME::Time> time;
0414   vector<float> val;
0415   vector<bool> flag;
0416   int ii = ivar;
0417   apdVector_->getTimeValAndFlag(ii, time, val, flag);
0418   unsigned int nrun = time.size();
0419   //  cout << endl;
0420   //  cout << leaf_->oneLine() << endl;
0421   for (unsigned int irun = 0; irun < nrun; irun++) {
0422     float dt_ = ME::timeDiff(time[irun], _time, ME::iHour);
0423     float val_ = val[irun];
0424     bool flag_ = flag[irun];
0425     TString str_ = ME::APDPrimVar[ii];
0426     time_t t = time[irun];
0427     struct tm* tb;
0428     tb = localtime(&t);
0429     //      cout << ctime(&t);
0430     int mon_ = tb->tm_mon + 1;
0431     int day_ = tb->tm_mday;
0432     int hr_ = tb->tm_hour + 1;
0433     int min_ = tb->tm_min;
0434     int sec_ = tb->tm_sec;
0435     cout << tb->tm_year + 1900 << "/";
0436     if (mon_ < 10)
0437       cout << "0";
0438     cout << mon_ << "/";
0439     if (day_ < 10)
0440       cout << "0";
0441     cout << day_ << "-";
0442     if (hr_ < 10)
0443       cout << "0";
0444     cout << hr_ << ":";
0445     if (min_ < 10)
0446       cout << "0";
0447     cout << min_ << ":";
0448     if (sec_ < 10)
0449       cout << "0";
0450     cout << sec_;
0451     cout << "\tt(sec)=" << t;
0452     cout << "\tdt(hrs)=" << dt_;
0453     cout << "\t\t" << str_ << "=" << val_ << "\tok=" << flag_ << endl;
0454   }
0455 }
0456 
0457 void MusEcal::setChannel(int ig, int ix, int iy, bool useGlobal) {
0458   int reg_(0);
0459   int sect_(0);
0460   int dcc_(0);
0461   int side_(0);
0462   ME::regionAndSector(_lmr, reg_, sect_, dcc_, side_);
0463   MEChannel* leaf_(0);
0464   if (reg_ == ME::iEBM || reg_ == ME::iEBP) {
0465     if (!useGlobal) {
0466       if (_lmr < 0)
0467         _lmr = 1;
0468       MEEBGeom::EtaPhiCoord etaphi_ = MEEBGeom::globalCoord(sect_, ix, iy);
0469       ix = etaphi_.first;
0470       iy = etaphi_.second;
0471     }
0472     // FIXME: ONLY BARREL FOR THE MOMENT
0473     assert(ix != 0 && std::abs(ix) <= 85);
0474     assert(iy >= 1 && iy <= 360);
0475     if (ix < 0)
0476       reg_ = ME::iEBM;
0477     if (ix > 0)
0478       reg_ = ME::iEBP;
0479     leaf_ = ME::regTree(reg_)->getChannel(ig, ix, iy);
0480   } else {
0481     if (!useGlobal) {
0482       leaf_ = ME::regTree(reg_)->getDescendant(ME::iLMRegion, _lmr)->getFirstDescendant(ME::iCrystal);
0483 
0484     } else {
0485       leaf_ = ME::regTree(reg_)->getChannel(ig, ix, iy);
0486     }
0487   }
0488   assert(leaf_ != 0);
0489   setChannel(leaf_);
0490 }
0491 
0492 void MusEcal::setChannel(MEChannel* leaf) {
0493   if (leaf == 0) {
0494     cout << "Wrong selection of channel" << endl;
0495     return;
0496   }
0497   if (leaf->ig() < ME::iLMRegion)
0498     return;
0499   int lmr_ = leaf->getAncestor(ME::iLMRegion)->id();
0500   if (lmr_ != _lmr)
0501     setLMRegion(lmr_);
0502   _leaf = leaf;
0503   cout << "\nCurrent channel: " << _leaf->oneLine() << endl;
0504 }
0505 
0506 void MusEcal::oneLevelUp() {
0507   MEChannel* leaf_ = _leaf->m();
0508   if (leaf_->ig() < ME::iLMRegion) {
0509     cout << "Already at Laser Monitoring Region level" << endl;
0510     return;
0511   }
0512   setChannel(leaf_);
0513 }
0514 
0515 void MusEcal::refresh() {}
0516 
0517 bool MusEcal::isBarrel() {
0518   int reg_ = ME::ecalRegion(_lmr);
0519   return (reg_ == ME::iEBM || reg_ == ME::iEBP);
0520 }
0521 
0522 void MusEcal::bookHistograms() {
0523   if (_histoBooked)
0524     return;
0525 
0526   if (!_ebHistoBooked) {
0527     cout << "Book histograms for barrel" << endl;
0528     bookEBAPDHistograms();
0529     bookEBPNHistograms();
0530     _ebHistoBooked = true;
0531   }
0532   if (!_eeHistoBooked) {
0533     cout << "Book histograms for endcaps" << endl;
0534     bookEEAPDHistograms();
0535     _eeHistoBooked = true;
0536   }
0537   _histoBooked = _ebHistoBooked && _eeHistoBooked;
0538 
0539   if (_seq_t == 0) {
0540     _seq_t = new TTree("Sequences", "Sequences");
0541     _seq_t->Branch("run", &_seq_run, "run/I");
0542     _seq_t->Branch("lb", &_seq_lb, "lb/I");
0543     _seq_t->Branch("tbeg", &_seq_tbeg, "tbeg/I");
0544     _seq_t->Branch("tlmr", &_seq_tlmr, "tlmr[92]/I");
0545 
0546     _seq_t->SetBranchAddress("run", &_seq_run);
0547     _seq_t->SetBranchAddress("lb", &_seq_lb);
0548     _seq_t->SetBranchAddress("tbeg", &_seq_tbeg);
0549     _seq_t->SetBranchAddress("tlmr", &_seq_tlmr);
0550   }
0551 }
0552 
0553 void MusEcal::histConfig() {
0554   //
0555   // if there is a config file, modify the specified histogram limits
0556   //
0557 
0558   TString fileroot = TString(std::getenv("MECONFIG"));
0559   fileroot += "/";
0560   fileroot += TString(std::getenv("MEPERIOD"));
0561   TString ext_[2] = {"EB", "EE"};
0562 
0563   for (int ii = 0; ii < 2; ii++) {
0564     TString filename = fileroot;
0565     filename += "_";
0566     filename += ext_[ii];
0567     filename += ".config";
0568 
0569     FILE* test;
0570     test = fopen(filename, "r");
0571     char c;
0572     if (test) {
0573       std::ifstream fin(filename);
0574       fclose(test);
0575       while ((c = fin.peek()) != EOF) {
0576         TString ss;
0577         fin >> ss;
0578         int nbin;
0579         fin >> nbin;
0580         float min;
0581         fin >> min;
0582         float max;
0583         fin >> max;
0584 
0585         if (ii == 0) {
0586           _eb_nbin[ss] = nbin;
0587           _eb_min[ss] = min;
0588           _eb_max[ss] = max;
0589         } else {
0590           _ee_nbin[ss] = nbin;
0591           _ee_min[ss] = min;
0592           _ee_max[ss] = max;
0593         }
0594       }
0595     } else
0596       cout << "WARNING -- Histogram Configuration File " << filename << " NOT FOUND " << endl;
0597     //  abort();
0598   }
0599 }
0600 
0601 int MusEcal::hist_nbin(TString& str) {
0602   if (isBarrel()) {
0603     if (_eb_nbin.count(str) != 0)
0604       return _eb_nbin[str];
0605   } else {
0606     if (_ee_nbin.count(str) != 0)
0607       return _ee_nbin[str];
0608   }
0609   return 0;
0610 }
0611 
0612 float MusEcal::hist_min(TString& str) {
0613   assert(hist_nbin(str) != 0);
0614   if (isBarrel())
0615     return _eb_min[str];
0616   else
0617     return _ee_min[str];
0618 }
0619 
0620 float MusEcal::hist_max(TString& str) {
0621   assert(hist_nbin(str) != 0);
0622   if (isBarrel())
0623     return _eb_max[str];
0624   else
0625     return _ee_max[str];
0626 }
0627 
0628 void MusEcal::bookEBAPDHistograms() {
0629   _febgeom = TFile::Open(ME::path() + "geom/ebgeom.root");
0630   assert(_febgeom != 0);
0631   _eb_h = (TH2*)_febgeom->Get("eb");
0632   _eb_h->SetStats(kFALSE);
0633   _eb_h->GetXaxis()->SetTitle("ieta");
0634   _eb_h->GetXaxis()->CenterTitle();
0635   _eb_h->GetYaxis()->SetTitle("iphi");
0636   _eb_h->GetYaxis()->CenterTitle();
0637 
0638   _eb_loc_h = (TH2*)_febgeom->Get("eb_loc");
0639   _eb_loc_h->SetStats(kFALSE);
0640   _eb_loc_h->GetXaxis()->SetTitle("ix");
0641   _eb_loc_h->GetXaxis()->CenterTitle();
0642   _eb_loc_h->GetYaxis()->SetTitle("iy");
0643   _eb_loc_h->GetYaxis()->CenterTitle();
0644 
0645   TH2* h2_;
0646   TH1* h1_;
0647 
0648   int type = _type;
0649   //  for( int type=ME::iLaser; type<=ME::iTestPulse; type++ )
0650   {
0651     unsigned size_(0);
0652     TString str0_;
0653     if (type == ME::iLaser) {
0654       size_ = ME::iSizeAPD;
0655       str0_ = "APD-";
0656     } else if (type == ME::iTestPulse) {
0657       size_ = ME::iSizeTPAPD;
0658       str0_ = "TPAPD-";
0659     }
0660     for (unsigned int ii = 0; ii < size_; ii++) {
0661       TString varName_;
0662       if (type == ME::iLaser)
0663         varName_ = ME::APDPrimVar[ii];
0664       else if (type == ME::iTestPulse)
0665         varName_ = ME::TPAPDPrimVar[ii];
0666       TString str_ = str0_ + varName_;
0667       h2_ = (TH2*)_eb_h->Clone(str_);
0668       _eb_m[str_] = h2_;
0669       if (_eb_nbin.count(str_) != 0) {
0670         h2_->SetMinimum(_eb_min[str_]);
0671         h2_->SetMaximum(_eb_max[str_]);
0672       }
0673       h2_ = (TH2*)_eb_loc_h->Clone(str_ + "_loc");
0674       _eb_loc_m[str_] = h2_;
0675       if (_eb_nbin.count(str_) != 0) {
0676         h2_->SetMinimum(_eb_min[str_]);
0677         h2_->SetMaximum(_eb_max[str_]);
0678       }
0679 
0680       TString ext_ = "_1D";
0681       h1_ = new TH1F(str_ + ext_, varName_, 2448, -0.5, 2447.5);
0682       MECanvasHolder::setHistoStyle(h1_);
0683       h1_->SetStats(kFALSE);
0684       h1_->GetXaxis()->SetTitle("SC number (LM numbering)");
0685       h1_->GetYaxis()->SetTitle(ME::APDPrimVar[ii]);
0686       if (_eb_nbin.count(str_) != 0) {
0687         h1_->SetMinimum(_eb_min[str_]);
0688         h1_->SetMaximum(1.1 * _eb_max[str_]);
0689       }
0690       _eb_m[str_ + ext_] = h1_;
0691 
0692       ext_ = "_VS_CHANNEL";
0693       h1_ = new TH1F(str_ + ext_, varName_, 900, -0.5, 899.5);
0694       MECanvasHolder::setHistoStyle(h1_);
0695       h1_->SetStats(kFALSE);
0696       h1_->GetXaxis()->SetTitle("Channel number (LM numbering)");
0697       h1_->GetYaxis()->SetTitle(ME::APDPrimVar[ii]);
0698       if (_eb_nbin.count(str_) != 0) {
0699         h1_->SetMinimum(_eb_min[str_]);
0700         h1_->SetMaximum(1.1 * _eb_max[str_]);
0701       }
0702       _eb_loc_m[str_ + ext_] = h1_;
0703       ext_ += "_sel";
0704       h1_ = (TH1*)h1_->Clone(str_ + ext_);
0705       h1_->SetLineColor(kRed);
0706       h1_->SetFillColor(46);
0707       _eb_loc_m[str_ + ext_] = h1_;
0708 
0709       if (_eb_nbin.count(str_) != 0) {
0710         ext_ = "_HIST";
0711         h1_ = new TH1F(str_ + ext_, varName_, _eb_nbin[str_], _eb_min[str_], _eb_max[str_]);
0712         MECanvasHolder::setHistoStyle(h1_);
0713         _eb_loc_m[str_ + ext_] = h1_;
0714         ext_ += "_sel";
0715         h1_ = (TH1*)h1_->Clone(str_ + ext_);
0716         h1_->SetLineColor(kRed);
0717         h1_->SetFillColor(46);
0718         _eb_loc_m[str_ + ext_] = h1_;
0719       }
0720     }
0721   }
0722 }
0723 
0724 void MusEcal::bookEEAPDHistograms() {
0725   _feegeom = TFile::Open(ME::path() + "geom/eegeom.root");
0726   assert(_feegeom != 0);
0727   _ee_h = (TH2*)_feegeom->Get("ee");
0728   _ee_h->SetStats(kFALSE);
0729   _ee_h->GetXaxis()->SetTitle("ix");
0730   _ee_h->GetXaxis()->CenterTitle();
0731   _ee_h->GetYaxis()->SetTitle("iy");
0732   _ee_h->GetYaxis()->CenterTitle();
0733 
0734   _ee_loc_h[0] = 0;
0735   for (int isect = 1; isect <= 9; isect++) {
0736     TString sect_("ee_S");
0737     sect_ += isect;
0738     _ee_loc_h[isect] = (TH2*)_feegeom->Get(sect_);
0739     _ee_loc_h[isect]->SetStats(kFALSE);
0740     _ee_loc_h[isect]->GetXaxis()->SetTitle("ix");
0741     _ee_loc_h[isect]->GetXaxis()->CenterTitle();
0742     _ee_loc_h[isect]->GetYaxis()->SetTitle("iy");
0743     _ee_loc_h[isect]->GetYaxis()->CenterTitle();
0744   }
0745 
0746   // get the master tree for EE-plus (sectors 1 to 9)
0747   MEChannel* tree = ME::regTree(ME::iEEP);
0748 
0749   TH2* h2_;
0750   TH1* h1_;
0751 
0752   int type = _type;
0753   //  for( int type=ME::iLaser; type<=ME::iTestPulse; type++ )
0754   unsigned size_(0);
0755   TString str0_;
0756   if (type == ME::iLaser) {
0757     size_ = ME::iSizeAPD;
0758     str0_ = "APD-";
0759   } else if (type == ME::iTestPulse) {
0760     size_ = ME::iSizeTPAPD;
0761     str0_ = "TPAPD-";
0762   }
0763   for (unsigned int ii = 0; ii < size_; ii++) {
0764     TString varName_;
0765     if (type == ME::iLaser)
0766       varName_ = ME::APDPrimVar[ii];
0767     else if (type == ME::iTestPulse)
0768       varName_ = ME::TPAPDPrimVar[ii];
0769     TString str_ = str0_ + varName_;
0770     h2_ = (TH2*)_ee_h->Clone(str_);
0771     _ee_m[str_] = h2_;
0772     if (_ee_nbin.count(str_) != 0) {
0773       h2_->SetMinimum(_ee_min[str_]);
0774       h2_->SetMaximum(_ee_max[str_]);
0775     }
0776     for (int isect = 1; isect <= 9; isect++) {
0777       TString str__ = str_;
0778       str__ += "_";
0779       str__ += isect;
0780       h2_ = (TH2*)_ee_loc_h[isect]->Clone(str__ + "_loc");
0781       _ee_loc_m[str__] = h2_;
0782       if (_ee_nbin.count(str_) != 0) {
0783         h2_->SetMinimum(_ee_min[str_]);
0784         h2_->SetMaximum(_ee_max[str_]);
0785       }
0786 
0787       TString ext_ = "_VS_CHANNEL";
0788 
0789       // trick to get the correct number of bins...
0790       MEChannel* tree_ = tree->getDescendant(ME::iSector, isect);
0791       vector<MEChannel*> vec_;
0792       tree_->getListOfDescendants(ME::iCrystal, vec_);
0793       int nbin_ = vec_.size();
0794       float xmin_ = -0.5;
0795       float xmax_ = nbin_ - 0.5;
0796 
0797       h1_ = new TH1F(str__ + ext_, varName_, nbin_, xmin_, xmax_);
0798       MECanvasHolder::setHistoStyle(h1_);
0799       h1_->SetStats(kFALSE);
0800       h1_->GetXaxis()->SetTitle("Channel number (LM numbering)");
0801       h1_->GetYaxis()->SetTitle(ME::APDPrimVar[ii]);
0802       if (_ee_nbin.count(str_) != 0) {
0803         h1_->SetMinimum(_ee_min[str_]);
0804         h1_->SetMaximum(1.1 * _ee_max[str_]);
0805       }
0806       _ee_loc_m[str__ + ext_] = h1_;
0807       ext_ += "_sel";
0808       h1_ = (TH1*)h1_->Clone(str__ + ext_);
0809       h1_->SetLineColor(kRed);
0810       h1_->SetFillColor(46);
0811       _ee_loc_m[str__ + ext_] = h1_;
0812 
0813       if (_ee_nbin.count(str_) != 0) {
0814         ext_ = "_HIST";
0815         h1_ = new TH1F(str__ + ext_, varName_, _ee_nbin[str_], _ee_min[str_], _ee_max[str_]);
0816         MECanvasHolder::setHistoStyle(h1_);
0817         _ee_loc_m[str__ + ext_] = h1_;
0818         ext_ += "_sel";
0819         h1_ = (TH1*)h1_->Clone(str__ + ext_);
0820         h1_->SetLineColor(kRed);
0821         h1_->SetFillColor(46);
0822         _ee_loc_m[str__ + ext_] = h1_;
0823       }
0824     }
0825 
0826     TString ext_ = "_1D";
0827     h1_ = new TH1F(str_ + ext_, varName_, 624, -0.5, 623.5);
0828     MECanvasHolder::setHistoStyle(h1_);
0829     h1_->SetStats(kFALSE);
0830     h1_->GetXaxis()->SetTitle("SC number (LM numbering)");
0831     h1_->GetYaxis()->SetTitle(ME::APDPrimVar[ii]);
0832     if (_ee_nbin.count(str_) != 0) {
0833       h1_->SetMinimum(_ee_min[str_]);
0834       h1_->SetMaximum(1.1 * _ee_max[str_]);
0835     }
0836     _ee_m[str_ + ext_] = h1_;
0837   }
0838 }
0839 
0840 void MusEcal::bookEBPNHistograms() {
0841   TH1* h1_;
0842 
0843   int type = _type;
0844   //  for( int type=ME::iLaser; type<=ME::iTestPulse; type++ )
0845   {
0846     unsigned size_(0);
0847     TString str0_;
0848     if (type == ME::iLaser) {
0849       size_ = ME::iSizePN;
0850       str0_ = "PN-";
0851     } else if (type == ME::iTestPulse) {
0852       size_ = ME::iSizeTPPN;
0853       str0_ = "TPPN-";
0854     }
0855     for (unsigned int ii = 0; ii < size_; ii++) {
0856       TString varName_, str_;
0857       if (type == ME::iLaser)
0858         varName_ = ME::PNPrimVar[ii];
0859       else if (type == ME::iTestPulse)
0860         varName_ = ME::TPPNPrimVar[ii];
0861       str_ = str0_ + varName_;
0862 
0863       // global histogram
0864       h1_ = new TH1F(str_, varName_, 648, -0.5, 647.5);
0865       MECanvasHolder::setHistoStyle(h1_);
0866       h1_->SetStats(kFALSE);
0867       h1_->GetXaxis()->SetTitle("PN number (LM numbering)");
0868       h1_->GetYaxis()->SetTitle(varName_);
0869       if (_ee_nbin.count(str_) != 0) {
0870         h1_->SetMinimum(_ee_min[str_]);
0871         h1_->SetMaximum(1.1 * _ee_max[str_]);
0872       }
0873       _eb_m[str_] = h1_;
0874 
0875       // local histogram
0876       TString ext_ = "_LOCAL";
0877       h1_ = new TH1F(str_ + ext_, varName_, 18, -0.5, 17.5);
0878       MECanvasHolder::setHistoStyle(h1_);
0879       h1_->SetStats(kFALSE);
0880       h1_->GetXaxis()->SetTitle("PN number (LM numbering)");
0881       h1_->GetYaxis()->SetTitle(varName_);
0882       if (_ee_nbin.count(str_) != 0) {
0883         h1_->SetMinimum(_ee_min[str_]);
0884         h1_->SetMaximum(1.1 * _ee_max[str_]);
0885       }
0886       _eb_loc_m[str_ + ext_] = h1_;
0887     }
0888   }
0889 }
0890 void MusEcal::bookEEPNHistograms() {}
0891 
0892 void MusEcal::fillHistograms() {
0893   if (!_histoBooked)
0894     bookHistograms();
0895   fillEBGlobalHistograms();
0896   fillEEGlobalHistograms();
0897   if (isBarrel()) {
0898     fillEBLocalHistograms();
0899   } else {
0900     fillEELocalHistograms();
0901   }
0902 }
0903 
0904 void MusEcal::fillEBGlobalHistograms() {
0905   if (!_histoBooked)
0906     bookHistograms();
0907   cout << "Filling EB Global Histograms";
0908   // cleaning
0909   for (map<TString, TH1*>::iterator it = _eb_m.begin(); it != _eb_m.end(); ++it) {
0910     it->second->Reset();
0911   }
0912 
0913   // filling the 2D histogram
0914   //  for( int ilmr=1; ilmr<=72; ilmr++ )
0915   TString rundir_;
0916   MERunManager* firstMgr_ = _runMgr.begin()->second;
0917   if (firstMgr_ != 0) {
0918     MERun* firstRun_ = firstMgr_->curRun();
0919     if (firstRun_ != 0) {
0920       rundir_ += firstRun_->rundir();
0921     }
0922   }
0923   TString titleW;
0924 
0925   titleW = ME::type[_type];
0926   if (_type == ME::iLaser) {
0927     titleW += " ";
0928     titleW += ME::color[_color];
0929   }
0930   titleW += " ECAL Barrel";
0931   titleW += " APD XXXXX";
0932   titleW += " ";
0933   titleW += rundir_;
0934 
0935   unsigned size_(0);
0936   TString str0_;
0937   int table_(0);
0938 
0939   vector<MEChannel*> vec;
0940   for (int ism = 1; ism <= 36; ism++) {
0941     cout << "." << flush;
0942     int idcc = MEEBGeom::dccFromSm(ism);
0943     int ilmr;
0944     MERunManager* mgr_;
0945     MERun* run_;
0946     for (int side = 0; side < 2; side++) {
0947       ilmr = ME::lmr(idcc, side);
0948       mgr_ = runMgr(ilmr);
0949       if (mgr_ == 0)
0950         continue;
0951       run_ = mgr_->curRun();
0952       if (run_ == 0)
0953         continue;
0954 
0955       // first APD
0956       if (_type == ME::iLaser) {
0957         size_ = ME::iSizeAPD;
0958         str0_ = "APD-";
0959         table_ = ME::iLmfLaserPrim;
0960       } else if (_type == ME::iTestPulse) {
0961         size_ = ME::iSizeTPAPD;
0962         str0_ = "TPAPD-";
0963         table_ = ME::iLmfTestPulsePrim;
0964       }
0965 
0966       vec.clear();
0967       mgr_->tree()->getListOfChannels(vec);
0968       for (unsigned int jj = 0; jj < size_; jj++) {
0969         TString varName_;
0970         if (_type == ME::iLaser) {
0971           varName_ = ME::APDPrimVar[jj];
0972         } else if (_type == ME::iTestPulse) {
0973           varName_ = ME::TPAPDPrimVar[jj];
0974         }
0975         for (unsigned int ii = 0; ii < vec.size(); ii++) {
0976           MEChannel* leaf_ = vec[ii];
0977           int ieta = leaf_->ix();
0978           int iphi = leaf_->iy();
0979           MEEBGeom::XYCoord ixy = MEEBGeom::localCoord(ieta, iphi);
0980           int ix = ixy.first;
0981           int iy = ixy.second;
0982           float val = run_->getVal(table_, jj, ix, iy);
0983           TString str_ = str0_ + varName_;
0984           TH2* h2_;
0985           h2_ = (TH2*)_eb_m[str_];
0986           TString title_ = titleW;
0987           title_.ReplaceAll("XXXXX", str_);
0988           h2_->SetTitle(title_);
0989           h2_->Fill(ieta, iphi, val);
0990           TH1* h1_;
0991           TString ext_ = "_1D";
0992           h1_ = (TH1*)_eb_m[str_ + ext_];
0993           h1_->SetTitle(title_);
0994           int ival = ii + ((ilmr - 1) / 2) * 1700;
0995           if (side == 1)
0996             ival += 900;
0997           h1_->Fill(ival / 25, val / 25);
0998         }
0999       }
1000 
1001       // then PNs
1002       if (_type == ME::iLaser) {
1003         size_ = ME::iSizePN;
1004         str0_ = "PN-";
1005         table_ = ME::iLmfLaserPnPrim;
1006       } else if (_type == ME::iTestPulse) {
1007         size_ = ME::iSizeTPPN;
1008         str0_ = "TPPN-";
1009         table_ = ME::iLmfTestPulsePnPrim;
1010       }
1011       vec.clear();
1012       mgr_->tree()->getListOfDescendants(ME::iLMModule, vec);
1013       for (unsigned int jj = 0; jj < size_; jj++) {
1014         TString varName_;
1015         if (_type == ME::iLaser) {
1016           varName_ = ME::PNPrimVar[jj];
1017         } else if (_type == ME::iTestPulse) {
1018           varName_ = ME::TPPNPrimVar[jj];
1019         }
1020         for (unsigned int ii = 0; ii < vec.size(); ii++) {
1021           MEChannel* leaf_ = vec[ii];
1022           int ilm = leaf_->id();
1023           TString str_ = str0_ + varName_;
1024           TH1* h1_;
1025           h1_ = (TH1*)_eb_m[str_];
1026           TString title_ = titleW;
1027           title_.ReplaceAll("APD", "PN");
1028           title_.ReplaceAll("XXXXX", str_);
1029           h1_->SetTitle(title_);
1030           for (int ipn = 0; ipn < 2; ipn++) {
1031             float val = run_->getVal(table_, jj, ilm, ipn);
1032             int ival = 2 * ((ilm - 1) / 2) + ipn + ((ilmr - 1) / 2) * 18;
1033             if (ilm % 2 == 0)
1034               ival += 10;
1035             h1_->Fill(ival, val);
1036           }
1037         }
1038       }
1039     }
1040   }
1041   cout << " Done." << endl;
1042 }
1043 
1044 void MusEcal::fillEBLocalHistograms() {
1045   if (!_histoBooked)
1046     bookHistograms();
1047   cout << "Filling EB Local Histograms";
1048   for (map<TString, TH1*>::iterator it = _eb_loc_m.begin(); it != _eb_loc_m.end(); ++it) {
1049     it->second->Reset();
1050   }
1051   MERunManager* mgr = curMgr();
1052   if (mgr == 0)
1053     return;
1054   MERun* run_ = mgr->curRun();
1055   TString rundir = "No Data";
1056   if (run_ != 0)
1057     rundir = run_->rundir();
1058 
1059   TString titleW;
1060   titleW = ME::type[_type];
1061   if (_type == ME::iLaser) {
1062     titleW += " ";
1063     titleW += ME::color[_color];
1064   }
1065   titleW += " ";
1066   titleW += "YYYYY";
1067   titleW += " APD XXXXX";
1068   titleW += " ";
1069   titleW += rundir;
1070   TString title_;
1071 
1072   MEChannel* l_[2] = {0, 0};
1073   l_[0] = mgr->tree();
1074   l_[1] = _leaf;
1075 
1076   unsigned size_(0);
1077   TString str0_;
1078   int table_(0);
1079 
1080   if (_type == ME::iLaser) {
1081     size_ = ME::iSizeAPD;
1082     str0_ = "APD-";
1083     table_ = ME::iLmfLaserPrim;
1084   } else if (_type == ME::iTestPulse) {
1085     size_ = ME::iSizeTPAPD;
1086     str0_ = "TPAPD-";
1087     table_ = ME::iLmfTestPulsePrim;
1088   }
1089 
1090   for (unsigned int jj = 0; jj < size_; jj++) {
1091     TString varName_;
1092     if (_type == ME::iLaser) {
1093       varName_ = ME::APDPrimVar[jj];
1094     } else if (_type == ME::iTestPulse) {
1095       varName_ = ME::TPAPDPrimVar[jj];
1096     }
1097     TH2* h2_(0);
1098     TH1* h1_[2] = {0, 0};
1099     TH1* h1_chan[2] = {0, 0};
1100     TString str_ = str0_ + varName_;
1101     h2_ = (TH2*)_eb_loc_m[str_];
1102     title_ = titleW;
1103     title_.ReplaceAll("XXXXX", varName_);
1104     //  title_.ReplaceAll("YYYYY",_leaf->oneWord( ME::iLMRegion ) );
1105     title_.ReplaceAll("YYYYY", _leaf->oneWord());
1106     h2_->SetTitle(title_);
1107 
1108     title_ = titleW;
1109     title_.ReplaceAll("XXXXX", varName_);
1110     title_.ReplaceAll("YYYYY", _leaf->oneWord());
1111     TString ext_ = "_HIST";
1112     if (_eb_loc_m.count(str_ + ext_) != 0) {
1113       h1_[0] = (TH1*)_eb_loc_m[str_ + ext_];
1114       h1_[0]->SetTitle(title_);
1115       ext_ += "_sel";
1116       h1_[1] = (TH1*)_eb_loc_m[str_ + ext_];
1117       h1_[1]->SetTitle(title_);
1118     }
1119 
1120     ext_ = "_VS_CHANNEL";
1121     h1_chan[0] = (TH1*)_eb_loc_m[str_ + ext_];
1122     h1_chan[0]->SetTitle(title_);
1123     ext_ += "_sel";
1124     h1_chan[1] = (TH1*)_eb_loc_m[str_ + ext_];
1125     h1_chan[1]->SetTitle(title_);
1126 
1127     if (run_ != 0) {
1128       vector<MEChannel*> vec[2];
1129       l_[0]->getListOfChannels(vec[0]);
1130       l_[1]->getListOfChannels(vec[1]);
1131       for (unsigned int ii = 0; ii < vec[0].size(); ii++) {
1132         MEChannel* leaf_ = vec[0][ii];
1133         int ieta = leaf_->ix();
1134         int iphi = leaf_->iy();
1135         MEEBGeom::XYCoord ixy = MEEBGeom::localCoord(ieta, iphi);
1136         int ix = ixy.first;
1137         int iy = ixy.second;
1138         float val = run_->getVal(table_, jj, ix, iy);
1139         if (h1_chan[0] != 0)
1140           h1_chan[0]->Fill(ii, val);
1141         if (h1_[0] != 0)
1142           h1_[0]->Fill(val);
1143         vector<MEChannel*>::iterator it_ = find(vec[1].begin(), vec[1].end(), leaf_);
1144         if (it_ != vec[1].end()) {
1145           if (h1_chan[1] != 0)
1146             h1_chan[1]->Fill(ii, val);
1147           if (h1_[1] != 0)
1148             h1_[1]->Fill(val);
1149           // test
1150           if (_leaf->ig() > ME::iLMRegion) {
1151             TAxis* xaxis_ = h2_->GetXaxis();
1152             TAxis* yaxis_ = h2_->GetYaxis();
1153             int a1_ = xaxis_->GetFirst();
1154             int a2_ = xaxis_->GetLast();
1155             int b1_ = yaxis_->GetFirst();
1156             int b2_ = yaxis_->GetLast();
1157             float max_ = h2_->GetMaximum();
1158             for (int ix_ = -1; ix_ >= xaxis_->GetBinCenter(a1_); ix_--) {
1159               h2_->Fill(ix_, iy, max_);
1160             }
1161             for (int ix_ = 85; ix_ <= xaxis_->GetBinCenter(a2_); ix_++) {
1162               h2_->Fill(ix_, iy, max_);
1163             }
1164             for (int iy_ = -1; iy_ >= yaxis_->GetBinCenter(b1_); iy_--) {
1165               h2_->Fill(ix, iy_, max_);
1166             }
1167             for (int iy_ = 20; iy_ <= yaxis_->GetBinCenter(b2_); iy_++) {
1168               h2_->Fill(ix, iy_, max_);
1169             }
1170           }
1171         }
1172 
1173         h2_->Fill(ix, iy, val);
1174       }
1175     }
1176   }
1177   // Now PN
1178   if (_type == ME::iLaser) {
1179     size_ = ME::iSizePN;
1180     str0_ = "PN-";
1181     table_ = ME::iLmfLaserPnPrim;
1182   } else if (_type == ME::iTestPulse) {
1183     size_ = ME::iSizeTPPN;
1184     str0_ = "TPPN-";
1185     table_ = ME::iLmfTestPulsePnPrim;
1186   }
1187 
1188   for (unsigned int jj = 0; jj < size_; jj++) {
1189     TString varName_;
1190     if (_type == ME::iLaser) {
1191       varName_ = ME::PNPrimVar[jj];
1192     } else if (_type == ME::iTestPulse) {
1193       varName_ = ME::TPPNPrimVar[jj];
1194     }
1195     TH1* h1_;
1196     TString str_ = str0_ + varName_;
1197     TString ext_ = "_LOCAL";
1198     h1_ = (TH1*)_eb_loc_m[str_ + ext_];
1199     title_ = titleW;
1200     title_.ReplaceAll("APD", "PN");
1201     title_.ReplaceAll("XXXXX", varName_);
1202     title_.ReplaceAll("YYYYY", _leaf->oneWord(ME::iLMRegion));
1203     h1_->SetTitle(title_);
1204 
1205     if (run_ != 0) {
1206       vector<MEChannel*> vec;
1207       mgr->tree()->getListOfDescendants(ME::iLMModule, vec);
1208       for (unsigned int ii = 0; ii < vec.size(); ii++) {
1209         MEChannel* leaf_ = vec[ii];
1210         int ilm = leaf_->id();
1211         for (int ipn = 0; ipn < 2; ipn++) {
1212           float val = run_->getVal(table_, jj, ilm, ipn);
1213           int ival = 2 * ((ilm - 1) / 2) + ipn;
1214           if (ilm % 2 == 0)
1215             ival += 10;
1216           h1_->Fill(ival, val);
1217         }
1218       }
1219     }
1220   }
1221   cout << "...Done." << endl;
1222 }
1223 
1224 void MusEcal::fillEEGlobalHistograms() {
1225   if (!_histoBooked)
1226     bookHistograms();
1227   cout << "Filling EE Global Histograms";
1228   // cleaning
1229   for (map<TString, TH1*>::iterator it = _ee_m.begin(); it != _ee_m.end(); ++it) {
1230     it->second->Reset();
1231   }
1232 
1233   // filling the 2D histogram
1234   TString rundir_;
1235   MERunManager* firstMgr_ = _runMgr.begin()->second;
1236   if (firstMgr_ != 0) {
1237     MERun* firstRun_ = firstMgr_->curRun();
1238     if (firstRun_ != 0) {
1239       rundir_ += firstRun_->rundir();
1240     }
1241   }
1242   TString titleW;
1243 
1244   titleW = ME::type[_type];
1245   if (_type == ME::iLaser) {
1246     titleW += " ";
1247     titleW += ME::color[_color];
1248   }
1249   titleW += " ECAL EndCap";
1250   titleW += " APD XXXXX";
1251   titleW += " ";
1252   titleW += rundir_;
1253 
1254   unsigned size_(0);
1255   TString str0_;
1256   int table_(0);
1257 
1258   vector<MEChannel*> vec;
1259   int ilmr, ireg, idcc, isect, side;
1260   for (ilmr = 73; ilmr <= 92; ilmr++) {
1261     cout << "." << flush;
1262     int iz = 1;
1263     if (ilmr > 82)
1264       iz = -1;
1265     ME::regionAndSector(ilmr, ireg, isect, idcc, side);
1266     MERunManager* mgr_;
1267     MERun* run_;
1268     mgr_ = runMgr(ilmr);
1269     if (mgr_ == 0)
1270       continue;
1271     //    int ism = MEEEGeom::smFromDcc( idcc );
1272     run_ = mgr_->curRun();
1273     if (run_ == 0)
1274       continue;
1275 
1276     // first APD
1277     if (_type == ME::iLaser) {
1278       size_ = ME::iSizeAPD;
1279       str0_ = "APD-";
1280       table_ = ME::iLmfLaserPrim;
1281     } else if (_type == ME::iTestPulse) {
1282       size_ = ME::iSizeTPAPD;
1283       str0_ = "TPAPD-";
1284       table_ = ME::iLmfTestPulsePrim;
1285     }
1286 
1287     vec.clear();
1288     mgr_->tree()->getListOfChannels(vec);
1289 
1290     for (unsigned int jj = 0; jj < size_; jj++) {
1291       TString varName_;
1292       if (_type == ME::iLaser) {
1293         varName_ = ME::APDPrimVar[jj];
1294       } else if (_type == ME::iTestPulse) {
1295         varName_ = ME::TPAPDPrimVar[jj];
1296       }
1297       TString str_ = str0_ + varName_;
1298       TH2* h2_;
1299       h2_ = (TH2*)_ee_m[str_];
1300       if (h2_ == 0) {
1301         cout << "non existing histogram " << str_ << endl;
1302         continue;
1303       }
1304       TString title_ = titleW;
1305       title_.ReplaceAll("XXXXX", str_);
1306       h2_->SetTitle(title_);
1307       TH1* h1_;
1308       TString ext_ = "_1D";
1309       h1_ = (TH1*)_ee_m[str_ + ext_];
1310       if (h1_ == 0) {
1311         cout << "non existing histogram " << str_ << endl;
1312         continue;
1313       }
1314       h1_->SetTitle(title_);
1315 
1316       for (unsigned int ii = 0; ii < vec.size(); ii++) {
1317         MEChannel* leaf_ = vec[ii];
1318         int ix = leaf_->ix();
1319         int iy = leaf_->iy();
1320         float val = run_->getVal(table_, jj, ix, iy);
1321         h2_->Fill(ix, iz * iy, val);
1322       }
1323     }
1324 
1325     //       // then PNs
1326     //       if( _type==ME::iLaser )
1327     //  {
1328     //    size_=ME::iSizePN;
1329     //    str0_="PN-";
1330     //    table_=ME::iLmfLaserPnPrim;
1331     //  }
1332     //       else if( _type==ME::iTestPulse )
1333     //  {
1334     //    size_=ME::iSizeTPPN;
1335     //    str0_="TPPN-";
1336     //    table_=ME::iLmfTestPulsePnPrim;
1337     //  }
1338     //       vec.clear();
1339     //       mgr_->tree()->getListOfDescendants( ME::iLMModule, vec );
1340     //       for( unsigned int jj=0; jj<size_; jj++ )
1341     //  {
1342     //    TString varName_;
1343     //    if( _type==ME::iLaser )
1344     //      {
1345     //        varName_=ME::PNPrimVar[jj];
1346     //      }
1347     //    else if( _type==ME::iTestPulse )
1348     //      {
1349     //        varName_=ME::TPPNPrimVar[jj];
1350     //      }
1351     //    for( unsigned int ii=0; ii<vec.size(); ii++ )
1352     //      {
1353     //        MEChannel* leaf_ = vec[ii];
1354     //        int ilm = leaf_->id();
1355     //        TString str_=str0_+varName_;
1356     //        TH1* h1_;
1357     //        h1_ = (TH1*) _ee_m[str_];
1358     //        TString title_ = titleW;
1359     //        title_.ReplaceAll("APD","PN");
1360     //        title_.ReplaceAll("XXXXX",str_);
1361     //        h1_->SetTitle(title_);
1362     //        for( int ipn=0; ipn<2; ipn++ )
1363     //      {
1364     //        float val = run_->getVal( table_, jj, ilm, ipn );
1365     //        int ival = 2*((ilm-1)/2) + ipn + ((ilmr-1)/2)*18;
1366     //        if( ilm%2==0 ) ival+=10;
1367     //        h1_->Fill( ival, val );
1368     //      }
1369     //      }
1370     //  }
1371   }
1372   cout << " Done." << endl;
1373 }
1374 
1375 void MusEcal::fillEELocalHistograms() {
1376   if (!_histoBooked)
1377     bookHistograms();
1378   if (isBarrel())
1379     return;
1380   //  int reg_= ME::ecalRegion( _lmr );
1381   //  int iz=1;
1382   //  if( reg_==ME::iEEM ) iz=-1;
1383 
1384   cout << "Filling EE Local Histograms";
1385   for (map<TString, TH1*>::iterator it = _ee_loc_m.begin(); it != _ee_loc_m.end(); ++it) {
1386     it->second->Reset();
1387   }
1388   MERunManager* mgr = curMgr();
1389   if (mgr == 0)
1390     return;
1391   MERun* run_ = mgr->curRun();
1392   TString rundir = "No Data";
1393   if (run_ != 0)
1394     rundir = run_->rundir();
1395 
1396   TString titleW;
1397   titleW = ME::type[_type];
1398   if (_type == ME::iLaser) {
1399     titleW += " ";
1400     titleW += ME::color[_color];
1401   }
1402   titleW += " ";
1403   titleW += "YYYYY";
1404   titleW += " APD XXXXX";
1405   titleW += " ";
1406   titleW += rundir;
1407   TString title_;
1408 
1409   cout << "GHM DBG -- " << titleW << endl;
1410 
1411   unsigned size_(0);
1412   TString str0_;
1413   int table_(0);
1414 
1415   if (_type == ME::iLaser) {
1416     size_ = ME::iSizeAPD;
1417     str0_ = "APD-";
1418     table_ = ME::iLmfLaserPrim;
1419   } else if (_type == ME::iTestPulse) {
1420     size_ = ME::iSizeTPAPD;
1421     str0_ = "TPAPD-";
1422     table_ = ME::iLmfTestPulsePrim;
1423   }
1424 
1425   cout << "GHM DBG -- " << _leaf->oneLine() << endl;
1426 
1427   MEChannel* l_[2] = {0, 0};
1428   l_[1] = _leaf;
1429   //  l_[0] = mgr->tree();
1430   l_[0] = _leaf->getAncestor(ME::iSector);
1431 
1432   int isect = l_[0]->id();
1433   if (isect > 9)
1434     isect -= 9;
1435   cout << "GHM DBG isect= " << isect << endl;
1436 
1437   for (unsigned int jj = 0; jj < size_; jj++) {
1438     TString varName_;
1439     if (_type == ME::iLaser) {
1440       varName_ = ME::APDPrimVar[jj];
1441     } else if (_type == ME::iTestPulse) {
1442       varName_ = ME::TPAPDPrimVar[jj];
1443     }
1444     TH2* h2_(0);
1445     TH1* h1_[2] = {0, 0};
1446     TH1* h1_chan[2] = {0, 0};
1447     TString str_ = str0_;
1448     str_ += varName_;
1449     str_ += "_";
1450     str_ += isect;
1451     h2_ = (TH2*)_ee_loc_m[str_];
1452     title_ = titleW;
1453     title_.ReplaceAll("XXXXX", varName_);
1454     //  title_.ReplaceAll("YYYYY",_leaf->oneWord( ME::iLMRegion ) );
1455     title_.ReplaceAll("YYYYY", _leaf->oneWord());
1456     h2_->SetTitle(title_);
1457 
1458     title_ = titleW;
1459     title_.ReplaceAll("XXXXX", varName_);
1460     title_.ReplaceAll("YYYYY", _leaf->oneWord());
1461     TString ext_ = "_HIST";
1462     if (_ee_loc_m.count(str_ + ext_) != 0) {
1463       h1_[0] = (TH1*)_ee_loc_m[str_ + ext_];
1464       h1_[0]->SetTitle(title_);
1465       ext_ += "_sel";
1466       h1_[1] = (TH1*)_ee_loc_m[str_ + ext_];
1467       h1_[1]->SetTitle(title_);
1468     }
1469 
1470     ext_ = "_VS_CHANNEL";
1471     if (_ee_loc_m.count(str_ + ext_) != 0) {
1472       h1_chan[0] = (TH1*)_ee_loc_m[str_ + ext_];
1473       h1_chan[0]->SetTitle(title_);
1474       ext_ += "_sel";
1475       h1_chan[1] = (TH1*)_ee_loc_m[str_ + ext_];
1476       h1_chan[1]->SetTitle(title_);
1477     }
1478 
1479     if (run_ != 0) {
1480       vector<MEChannel*> vec[2];
1481       l_[0]->getListOfChannels(vec[0]);
1482       l_[1]->getListOfChannels(vec[1]);
1483       for (unsigned int ii = 0; ii < vec[0].size(); ii++) {
1484         MEChannel* leaf_ = vec[0][ii];
1485         //        int ieta = leaf_->ix();
1486         //        int iphi = leaf_->iy();
1487         //        MEEBGeom::XYCoord ixy = MEEBGeom::localCoord( ieta, iphi );
1488         int ix = leaf_->ix();
1489         int iy = leaf_->iy();
1490         float val = run_->getVal(table_, jj, ix, iy);
1491         if (h1_chan[0] != 0)
1492           h1_chan[0]->Fill(ii, val);
1493         if (h1_[0] != 0)
1494           h1_[0]->Fill(val);
1495         vector<MEChannel*>::iterator it_ = find(vec[1].begin(), vec[1].end(), leaf_);
1496         if (it_ != vec[1].end()) {
1497           if (h1_chan[1] != 0)
1498             h1_chan[1]->Fill(ii, val);
1499           if (h1_[1] != 0)
1500             h1_[1]->Fill(val);
1501           // test
1502           //          if(_leaf->ig()>ME::iLMRegion )
1503           //            {
1504           //              TAxis* xaxis_ = h2_->GetXaxis();
1505           //              TAxis* yaxis_ = h2_->GetYaxis();
1506           //              int a1_ = xaxis_->GetFirst();
1507           //              int a2_ = xaxis_->GetLast();
1508           //              int b1_ = yaxis_->GetFirst();
1509           //              int b2_ = yaxis_->GetLast();
1510           //              float max_ = h2_->GetMaximum();
1511           //              for( int ix_=-1; ix_>=xaxis_->GetBinCenter(a1_); ix_-- )
1512           //            {
1513           //              h2_->Fill( ix_, iy, max_ );
1514           //            }
1515           //              for( int ix_=85; ix_<=xaxis_->GetBinCenter(a2_); ix_++ )
1516           //            {
1517           //              h2_->Fill( ix_, iy, max_ );
1518           //            }
1519           //              for( int iy_=-1; iy_>=yaxis_->GetBinCenter(b1_); iy_-- )
1520           //            {
1521           //              h2_->Fill( ix, iy_, max_ );
1522           //            }
1523           //              for( int iy_=20; iy_<=yaxis_->GetBinCenter(b2_); iy_++ )
1524           //            {
1525           //              h2_->Fill( ix, iy_, max_ );
1526           //            }
1527           //            }
1528         }
1529 
1530         //        cout << "GHM DBG ix/iy " << ix << "/" << iy << "/" << val << endl;
1531         h2_->Fill(ix, iy, val);
1532       }
1533     }
1534   }
1535   // Now PN
1536   if (_type == ME::iLaser) {
1537     size_ = ME::iSizePN;
1538     str0_ = "PN-";
1539     table_ = ME::iLmfLaserPnPrim;
1540   } else if (_type == ME::iTestPulse) {
1541     size_ = ME::iSizeTPPN;
1542     str0_ = "TPPN-";
1543     table_ = ME::iLmfTestPulsePnPrim;
1544   }
1545 
1546   for (unsigned int jj = 0; jj < size_; jj++) {
1547     TString varName_;
1548     if (_type == ME::iLaser) {
1549       varName_ = ME::PNPrimVar[jj];
1550     } else if (_type == ME::iTestPulse) {
1551       varName_ = ME::TPPNPrimVar[jj];
1552     }
1553     TH1* h1_;
1554     TString str_ = str0_ + varName_;
1555     TString ext_ = "_LOCAL";
1556     h1_ = (TH1*)_eb_loc_m[str_ + ext_];
1557     title_ = titleW;
1558     title_.ReplaceAll("APD", "PN");
1559     title_.ReplaceAll("XXXXX", varName_);
1560     title_.ReplaceAll("YYYYY", _leaf->oneWord(ME::iLMRegion));
1561     h1_->SetTitle(title_);
1562 
1563     if (run_ != 0) {
1564       vector<MEChannel*> vec;
1565       mgr->tree()->getListOfDescendants(ME::iLMModule, vec);
1566       for (unsigned int ii = 0; ii < vec.size(); ii++) {
1567         MEChannel* leaf_ = vec[ii];
1568         int ilm = leaf_->id();
1569         for (int ipn = 0; ipn < 2; ipn++) {
1570           float val = run_->getVal(table_, jj, ilm, ipn);
1571           int ival = 2 * ((ilm - 1) / 2) + ipn;
1572           if (ilm % 2 == 0)
1573             ival += 10;
1574           h1_->Fill(ival, val);
1575         }
1576       }
1577     }
1578   }
1579 
1580   //   for( map<TString,TH1*>::iterator it=_ee_loc_m.begin();
1581   //        it!=_ee_loc_m.end(); ++it )
1582   //     {
1583   //       cout << "ee_loc_m " << it->first << endl;
1584   //     }
1585   cout << "...Done." << endl;
1586 }
1587 
1588 void MusEcal::writeGlobalHistograms() {
1589   map<TString, TH1*>::iterator it;
1590   for (it = _eb_m.begin(); it != _eb_m.end(); ++it) {
1591     it->second->Write();
1592   }
1593   for (it = _ee_m.begin(); it != _ee_m.end(); ++it) {
1594     it->second->Write();
1595   }
1596 }
1597 
1598 TString MusEcal::mgrName(int lmr, int type, int color) {
1599   TString out_;
1600   out_ += type;
1601   out_ += "_";
1602   out_ += color;
1603   out_ += "_";
1604   if (lmr < 10)
1605     out_ += "0";
1606   out_ += lmr;
1607   return out_;
1608 }