Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:22:52

0001 #include "boost/program_options.hpp"
0002 #include "boost/tokenizer.hpp"
0003 #include "TROOT.h"
0004 #include "TTree.h"
0005 #include "TFile.h"
0006 #include "TStyle.h"
0007 #include "TCanvas.h"
0008 #include "TH1F.h"
0009 #include "TH2F.h"
0010 #include "TGraph.h"
0011 #include "TLine.h"
0012 #include "TPad.h"
0013 #include <iostream>
0014 #include <fstream>
0015 #include <string>
0016 #include <vector>
0017 #include <cfloat>
0018 
0019 using namespace std;
0020 using namespace boost;
0021 
0022 class RootPlot {
0023 public:
0024   static const int DEFAULT_AXIS = 111;
0025   static const int TIME_AXIS = 222;
0026 
0027   RootPlot(string type, string format, string file, float hmin = 0., float hmax = 0.) {
0028     m_isInit = false;
0029     m_type = type;
0030     m_outputFormat = format;
0031     m_outputFile = file + "." + format;
0032     m_outputRoot = file + ".root";
0033     m_title = "rootplot Plot";
0034     m_xtitle = "X";
0035     m_ytitle = "Y";
0036     m_xAxisType = DEFAULT_AXIS;
0037     m_debug = 1;
0038     m_T0 = TDatime(2005, 01, 01, 00, 00, 00);
0039     m_hmin = hmin;
0040     m_hmax = hmax;
0041   };
0042 
0043   ~RootPlot(){};
0044 
0045   void init() {
0046     m_nbins[0] = m_nbins[1] = 100;
0047     m_mins[0] = m_mins[1] = FLT_MAX;
0048     m_maxs[0] = m_maxs[1] = FLT_MIN;
0049     m_data[0] = 0;
0050     m_data[1] = 0;
0051     m_data[2] = 0;
0052     m_data[3] = 0;
0053     m_data[4] = 0;
0054 
0055     gROOT->SetStyle("Plain");
0056     gStyle->SetOptStat(111111);
0057     gStyle->SetOptFit();
0058     gStyle->SetPalette(1, nullptr);
0059 
0060     int pCol[2] = {2, 3};
0061     if ((m_type == "Map" || m_type == "EBEEMap") && (TString(m_title).Contains("status"))) {
0062       gStyle->SetPalette(2, pCol);
0063     }
0064 
0065     m_rootfile = new TFile(m_outputRoot.c_str(), "RECREATE");
0066     m_tree = new TTree("t1", "rootplot tree");
0067 
0068     if (m_type == "TH1F") {
0069       m_nfields = 1;
0070       m_tree->Branch("x", &m_data[0], "x/F");
0071     } else if (m_type == "TH2F") {
0072       m_nfields = 2;
0073       m_tree->Branch("x", &m_data[0], "x/F");
0074       m_tree->Branch("y", &m_data[1], "y/F");
0075     } else if (m_type == "TGraph") {
0076       m_nfields = 2;
0077       m_tree->Branch("x", &m_data[0], "x/F");
0078       m_tree->Branch("y", &m_data[1], "y/F");
0079     } else if (m_type == "Map") {
0080       m_nfields = 2;
0081       m_tree->Branch("x", &m_data[0], "x/F");  // channel number
0082       m_tree->Branch("y", &m_data[1], "y/F");  // variable var
0083     } else if (m_type == "EBEEMap") {
0084       m_nfields = 5;
0085       m_tree->Branch("ism_z", &m_data[0], "ism_z/F");      // SM number (EB), z (EE)
0086       m_tree->Branch("chnum_x", &m_data[1], "chnum_x/F");  // channel number (EB) , x (EE)
0087       m_tree->Branch("var", &m_data[2], "var/F");          // variable var
0088       m_tree->Branch("null_y", &m_data[3], "z/F");         // null value (EB), y (EE)
0089       m_tree->Branch("isEB", &m_data[4], "isEB/F");        // 1 (EB), 0 (EE)
0090     }
0091   };
0092 
0093   void setTitle(string title) { m_title = title; }
0094   void setXTitle(string xtitle) { m_xtitle = xtitle; }
0095   void setYTitle(string ytitle) { m_ytitle = ytitle; }
0096   void setDebug(int debug) { m_debug = debug; }
0097   void setXAxisType(int code) { m_xAxisType = code; }
0098 
0099   void parseAndFill(std::string str) {
0100     if (!m_isInit) {
0101       this->init();
0102       m_isInit = true;
0103     }
0104 
0105     if (str[0] == '#') {
0106       // skip header
0107       return;
0108     }
0109 
0110     if (m_debug) {
0111       cout << "[data] " << flush;
0112     }
0113 
0114     typedef boost::tokenizer<boost::escaped_list_separator<char> > tokenizer;
0115     escaped_list_separator<char> sep('\\', ' ', '\"');
0116     tokenizer tokens(str, sep);
0117     float datum;
0118     int cnt = 0;
0119 
0120     for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
0121       if (cnt > m_nfields) {
0122         continue;
0123       }
0124 
0125       if (m_debug) {
0126         cout << "<" << *tok_iter << ">" << flush;
0127       }
0128 
0129       if (m_xAxisType == TIME_AXIS && cnt == 0) {
0130         TDatime d((*tok_iter).c_str());
0131         datum = (Float_t)(d.Convert() - m_T0.Convert());
0132       } else {
0133         datum = atof((*tok_iter).c_str());
0134       }
0135 
0136       if (m_type != "EBEEMap") {
0137         if (datum < m_mins[cnt]) {
0138           m_mins[cnt] = datum;
0139         }
0140         if (datum > m_maxs[cnt]) {
0141           m_maxs[cnt] = datum;
0142         }
0143       }
0144 
0145       m_data[cnt] = datum;
0146 
0147       cnt++;
0148     }
0149 
0150     if (m_debug) {
0151       cout << endl;
0152     }
0153     m_tree->Fill();
0154   };
0155 
0156   void draw() {
0157     for (int i = 0; i < m_nfields; i++) {
0158       if (m_mins[i] == m_maxs[i]) {
0159         m_mins[i] -= m_mins[i] * (0.05);
0160         m_maxs[i] += m_mins[i] * (0.05);
0161       }
0162     }
0163 
0164     if (m_debug) {
0165       cout << "[draw()]:" << endl;
0166       cout << "  m_type:          " << m_type << endl;
0167       cout << "  m_outputFormat:  " << m_outputFormat << endl;
0168       cout << "  m_outputFile:    " << m_outputFile << endl;
0169       cout << "  m_outputRoot:    " << m_outputRoot << endl;
0170       cout << "  m_title:         " << m_title << endl;
0171       cout << "  m_xtitle:        " << m_xtitle << endl;
0172       cout << "  m_ytitle:        " << m_ytitle << endl;
0173       cout << "  m_xAxisType:     " << m_xAxisType << endl;
0174       cout << "  m_nfields:       " << m_nfields << endl;
0175       cout << "  m_nbins[]:       " << m_nbins[0] << " " << m_nbins[1] << endl;
0176       cout << "  m_mins[]:        " << m_mins[0] << " " << m_mins[1] << endl;
0177       cout << "  m_maxs[]:        " << m_maxs[0] << " " << m_maxs[1] << endl;
0178     }
0179 
0180     m_tree->Write();
0181 
0182     //std::cout << "m_type = " << m_type << std::endl;
0183 
0184     if (m_type == "TH1F") {
0185       this->drawTH1F();
0186     } else if (m_type == "TH2F") {
0187       this->drawTH2F();
0188     } else if (m_type == "TGraph") {
0189       this->drawTGraph();
0190     } else if (m_type == "Map") {
0191       this->drawMap();
0192     } else if (m_type == "EBEEMap") {
0193       this->drawEBEEMap();
0194     }
0195 
0196     m_isInit = false;
0197   };
0198 
0199   void drawTH1F() {
0200     TCanvas c1("c1", "rootplot", 200, 10, 450, 300);
0201     c1.SetGrid();
0202 
0203     if ((TString(m_title).Contains("status"))) {
0204       m_mins[0] = -0.001;
0205       m_maxs[0] = 1.001;
0206     }
0207 
0208     TH1F* plot = new TH1F("rootplot", m_title.c_str(), m_nbins[0], m_mins[0], m_maxs[0]);
0209     plot->GetXaxis()->SetTitle(m_xtitle.c_str());
0210     plot->GetYaxis()->SetTitle(m_ytitle.c_str());
0211 
0212     if (m_xAxisType == TIME_AXIS) {
0213       TAxis* axis = plot->GetXaxis();
0214       setTimeAxis(axis);
0215     }
0216 
0217     m_tree->Draw("x >> rootplot");
0218 
0219     plot->Draw();
0220     c1.Print(m_outputFile.c_str(), m_outputFormat.c_str());
0221 
0222     plot->Write();
0223   };
0224 
0225   void drawTH2F() {
0226     TCanvas c1("c1", "rootplot", 200, 10, 600, 400);
0227     c1.SetGrid();
0228 
0229     TH2F* plot =
0230         new TH2F("rootplot", m_title.c_str(), m_nbins[0], m_mins[0], m_maxs[0], m_nbins[1], m_mins[1], m_maxs[1]);
0231     plot->GetXaxis()->SetTitle(m_xtitle.c_str());
0232     plot->GetYaxis()->SetTitle(m_ytitle.c_str());
0233 
0234     if (m_xAxisType == TIME_AXIS) {
0235       TAxis* axis = plot->GetXaxis();
0236       setTimeAxis(axis);
0237     }
0238 
0239     m_tree->Draw("x:y >> rootplot");
0240 
0241     plot->Draw();
0242     c1.Print(m_outputFile.c_str(), m_outputFormat.c_str());
0243 
0244     plot->Write();
0245   }
0246 
0247   void drawTGraph() {
0248     TCanvas c1("c1", "rootplot", 200, 10, 600, 400);
0249     c1.SetGrid();
0250 
0251     Int_t n = (Int_t)m_tree->GetEntries();
0252     TGraph* plot = new TGraph(n);
0253 
0254     Float_t x, y;
0255     m_tree->SetBranchAddress("x", &x);
0256     m_tree->SetBranchAddress("y", &y);
0257     for (Int_t i = 0; i < n; i++) {
0258       m_tree->GetEntry(i);
0259       plot->SetPoint(i, x, y);
0260     }
0261 
0262     if (m_xAxisType == TIME_AXIS) {
0263       TAxis* axis = plot->GetXaxis();
0264       setTimeAxis(axis);
0265     }
0266 
0267     plot->SetTitle(m_title.c_str());
0268     plot->GetXaxis()->SetTitle(m_xtitle.c_str());
0269     plot->GetYaxis()->SetTitle(m_ytitle.c_str());
0270     plot->SetMarkerStyle(21);
0271     plot->Draw("AP");
0272 
0273     c1.Print(m_outputFile.c_str(), m_outputFormat.c_str());
0274     plot->Write();
0275   };
0276 
0277   void drawMap() {
0278     gStyle->SetOptStat(0);
0279 
0280     const Int_t csize = 250;
0281     TCanvas c1("c1", "rootplot", Int_t(85. / 20. * csize), csize);
0282     TH2F* plot = new TH2F("rootplot", m_title.c_str(), 85, 0.0001, 85.0001, 20, 0.0001, 20.0001);
0283     plot->GetXaxis()->SetTitle(m_xtitle.c_str());
0284     plot->GetYaxis()->SetTitle(m_ytitle.c_str());
0285 
0286     Float_t x, y;
0287     m_tree->SetBranchAddress("x", &x);
0288     m_tree->SetBranchAddress("y", &y);
0289 
0290     // now fill the map...
0291     Int_t n = (Int_t)m_tree->GetEntries();
0292     for (Int_t i = 0; i < n; i++) {
0293       m_tree->GetEntry(i);
0294       //      while(x>1700) x-=1700;
0295       Float_t xmap = Float_t(Int_t(x - 1) / 20) + 1;
0296       Float_t ymap = Float_t(Int_t(x - 1) % 20) + 1;
0297       plot->Fill(xmap, ymap, y);
0298     }
0299 
0300     // draw the map
0301     plot->SetTitle(m_title.c_str());
0302     if ((TString(m_title).Contains("status"))) {
0303       plot->SetMinimum(-0.001);
0304       plot->SetMaximum(1.001);
0305     } else if (!(m_hmin == 0 && m_hmax == 0)) {
0306       plot->SetMinimum(m_hmin);
0307       plot->SetMaximum(m_hmax);
0308     }
0309 
0310     plot->GetXaxis()->SetTitle("#phi");
0311     plot->GetYaxis()->SetTitle("#eta");
0312     plot->GetZaxis()->SetTitle(m_ytitle.c_str());
0313     plot->GetXaxis()->SetNdivisions(17);
0314     plot->GetYaxis()->SetNdivisions(4);
0315     c1.SetGridx();
0316     c1.SetGridy();
0317     plot->Draw("colz");
0318 
0319     // and draw the grid upon the map...
0320     TH2C* labelGrid = new TH2C("labelGrid", "label grid for SM", 85, 0., 85., 20, 0., 20.);
0321     for (Int_t i = 0; i < 68; i++) {
0322       Float_t X = (i / 4) * 5 + 2;
0323       Float_t Y = (i % 4) * 5 + 2;
0324       labelGrid->Fill(X, Y, i + 1);
0325     }
0326     labelGrid->SetMinimum(0.1);
0327     labelGrid->SetMarkerSize(4);
0328     labelGrid->Draw("text,same");
0329 
0330     c1.Print(m_outputFile.c_str(), m_outputFormat.c_str());
0331     plot->Write();
0332   };
0333 
0334   void drawEBEEMap() {
0335     const Int_t csize = 900;
0336 
0337     TCanvas c1("c1", "rootplot", csize, csize);
0338     TPad p1("EBPad", "EBPad", 0., 0.5, 1., 1.);
0339     p1.Draw();
0340     TPad p2("EEPlusPad", "EEPlusPad", 0., 0., 0.48, 0.5);
0341     p2.Draw();
0342     TPad p3("EEPlusPad", "EEPlusPad", 0.50, 0., 0.98, 0.5);
0343     p3.Draw();
0344 
0345     //EB
0346     TH2F* EBPlot = new TH2F("rootplotEB", m_title.c_str(), 360, 0., 360., 170, -85., 85.);
0347     EBPlot->GetXaxis()->SetTitle("i#phi");
0348     EBPlot->GetYaxis()->SetTitle("i#eta");
0349     EBPlot->GetZaxis()->SetTitle(m_ytitle.c_str());
0350     EBPlot->GetXaxis()->SetNdivisions(18, kFALSE);
0351     EBPlot->GetYaxis()->SetNdivisions(2);
0352 
0353     //EE+
0354     TH2F* EEPlot_plus = new TH2F("rootplotEE+", m_title.c_str(), 100, 0., 100., 100, 0., 100.);
0355     EEPlot_plus->GetXaxis()->SetTitle("ix");
0356     EEPlot_plus->GetYaxis()->SetTitleOffset(1.3);
0357     EEPlot_plus->GetYaxis()->SetTitle("iy");
0358     EEPlot_plus->GetZaxis()->SetTitle(m_ytitle.c_str());
0359     EEPlot_plus->GetXaxis()->SetNdivisions(10, kTRUE);
0360     EEPlot_plus->GetYaxis()->SetNdivisions(10);
0361 
0362     //EE-
0363     TH2F* EEPlot_minus = new TH2F("rootplotEE-", m_title.c_str(), 100, 0., 100., 100, 0., 100.);
0364     EEPlot_minus->GetXaxis()->SetTitle("ix");
0365     EEPlot_minus->GetYaxis()->SetTitle("iy");
0366     EEPlot_minus->GetYaxis()->SetTitleOffset(1.3);
0367     EEPlot_minus->GetZaxis()->SetTitle(m_ytitle.c_str());
0368     EEPlot_minus->GetXaxis()->SetNdivisions(10, kTRUE);
0369     EEPlot_minus->GetYaxis()->SetNdivisions(10);
0370 
0371     Float_t chnum_x, var, ism_z, isEB, null_y;
0372     m_tree->SetBranchAddress("ism_z", &ism_z);
0373     m_tree->SetBranchAddress("chnum_x", &chnum_x);
0374     m_tree->SetBranchAddress("var", &var);
0375     m_tree->SetBranchAddress("isEB", &isEB);
0376     m_tree->SetBranchAddress("null_y", &null_y);
0377 
0378     // now fill the maps...
0379     Int_t n = (Int_t)m_tree->GetEntries();
0380     for (Int_t i = 0; i < n; i++) {
0381       m_tree->GetEntry(i);
0382 
0383       if (isEB) {
0384         Float_t iex = -1;
0385         Float_t ipx = -1;
0386         for (unsigned int i = 1; i <= 36; i++) {
0387           if (i == ism_z) {
0388             Float_t ie = Float_t(Int_t(chnum_x - 1) / 20) + 1;
0389             Float_t ip = Float_t(Int_t(chnum_x - 1) % 20) + 1;
0390 
0391             if (ism_z <= 18) {
0392               iex = ie - 1;
0393               ipx = (20 - ip) + 20 * (ism_z - 1);
0394             } else {
0395               iex = -1 * ie;
0396               ipx = ip + 20 * (ism_z - 19) - 1;
0397             }
0398 
0399             EBPlot->Fill(ipx, iex, var);
0400           }
0401         }
0402       }  //end loop on EB
0403 
0404       //assuming: if not EB, it's EE (TODO: check strings)...
0405       else {
0406         //EE+
0407         if (ism_z == 1)
0408           EEPlot_plus->Fill(chnum_x - 0.5, null_y - 0.5, var);
0409         //EE-
0410         if (ism_z == -1)
0411           EEPlot_minus->Fill(chnum_x - 0.5, null_y - 0.5, var);
0412       }  //end loop on EE
0413 
0414     }  //end loop on entries
0415 
0416     // draw the map
0417     //setting
0418     gStyle->SetOptStat("e");
0419     gStyle->SetPaintTextFormat("+g");
0420 
0421     EBPlot->SetTitle(m_title.c_str());
0422     EEPlot_plus->SetTitle(m_title.c_str());
0423     EEPlot_minus->SetTitle(m_title.c_str());
0424 
0425     if ((TString(m_title).Contains("status"))) {
0426       EBPlot->SetMinimum(-0.001);
0427       EBPlot->SetMaximum(1.001);
0428       EEPlot_plus->SetMinimum(-0.001);
0429       EEPlot_plus->SetMaximum(1.001);
0430       EEPlot_minus->SetMinimum(-0.001);
0431       EEPlot_minus->SetMaximum(1.001);
0432 
0433     } else if (!(m_hmin == 0 && m_hmax == 0)) {
0434       EBPlot->SetMinimum(m_hmin);
0435       EBPlot->SetMaximum(m_hmax);
0436       EEPlot_plus->SetMinimum(m_hmin);
0437       EEPlot_plus->SetMaximum(m_hmax);
0438       EEPlot_minus->SetMinimum(m_hmin);
0439       EEPlot_minus->SetMaximum(m_hmax);
0440     }
0441 
0442     p1.cd();
0443     gPad->SetGridx();
0444     gPad->SetGridy();
0445     EBPlot->Draw("colz");
0446 
0447     // and draw the grid upon the map...
0448     TH2C* labelGrid = new TH2C("labelGrid", "label grid for SM", 18, 0., 360., 2, -85., 85.);
0449     for (Int_t sm = 1; sm <= 36; sm++) {
0450       int X = (sm <= 18) ? sm : sm - 18;
0451       int Y = (sm <= 18) ? 2 : 1;
0452       double posSM = (sm <= 18) ? sm : -1 * (sm - 18);
0453       labelGrid->SetBinContent(X, Y, posSM);
0454     }
0455     labelGrid->SetMarkerSize(2);
0456     labelGrid->Draw("text,same");
0457 
0458     c1.Print(m_outputFile.c_str(), m_outputFormat.c_str());
0459     EBPlot->Write();
0460 
0461     //END OF EBPLOT
0462 
0463     int ixSectorsEE[202] = {
0464         61, 61, 60, 60, 59, 59, 58, 58, 57, 57, 55, 55, 45, 45, 43, 43, 42, 42, 41, 41,  40,  40,  39,  39, 40, 40,
0465         41, 41, 42, 42, 43, 43, 45, 45, 55, 55, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61,  0,   100, 100, 97, 97, 95,
0466         95, 92, 92, 87, 87, 85, 85, 80, 80, 75, 75, 65, 65, 60, 60, 40, 40, 35, 35, 25,  25,  20,  20,  15, 15, 13,
0467         13, 8,  8,  5,  5,  3,  3,  0,  0,  3,  3,  5,  5,  8,  8,  13, 13, 15, 15, 20,  20,  25,  25,  35, 35, 40,
0468         40, 60, 60, 65, 65, 75, 75, 80, 80, 85, 85, 87, 87, 92, 92, 95, 95, 97, 97, 100, 100, 0,   61,  65, 65, 70,
0469         70, 80, 80, 90, 90, 92, 0,  61, 65, 65, 90, 90, 97, 0,  57, 60, 60, 65, 65, 70,  70,  75,  75,  80, 80, 0,
0470         50, 50, 0,  43, 40, 40, 35, 35, 30, 30, 25, 25, 20, 20, 0,  39, 35, 35, 10, 10,  3,   0,   39,  35, 35, 30,
0471         30, 20, 20, 10, 10, 8,  0,  45, 45, 40, 40, 35, 35, 0,  55, 55, 60, 60, 65, 65};
0472 
0473     int iySectorsEE[202] = {
0474         50, 55,  55, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 60, 60,  59,  59, 58, 58, 57, 57, 55, 55, 45, 45, 43,
0475         43, 42,  42, 41, 41, 40, 40, 39, 39, 40, 40, 41, 41, 42, 42,  43,  43, 45, 45, 50, 0,  50, 60, 60, 65, 65,
0476         75, 75,  80, 80, 85, 85, 87, 87, 92, 92, 95, 95, 97, 97, 100, 100, 97, 97, 95, 95, 92, 92, 87, 87, 85, 85,
0477         80, 80,  75, 75, 65, 65, 60, 60, 40, 40, 35, 35, 25, 25, 20,  20,  15, 15, 13, 13, 8,  8,  5,  5,  3,  3,
0478         0,  0,   3,  3,  5,  5,  8,  8,  13, 13, 15, 15, 20, 20, 25,  25,  35, 35, 40, 40, 50, 0,  45, 45, 40, 40,
0479         35, 35,  30, 30, 25, 25, 0,  50, 50, 55, 55, 60, 60, 0,  60,  60,  65, 65, 70, 70, 75, 75, 85, 85, 87, 0,
0480         61, 100, 0,  60, 60, 65, 65, 70, 70, 75, 75, 85, 85, 87, 0,   50,  50, 55, 55, 60, 60, 0,  45, 45, 40, 40,
0481         35, 35,  30, 30, 25, 25, 0,  39, 30, 30, 15, 15, 5,  0,  39,  30,  30, 15, 15, 5};
0482 
0483     //grid
0484     TH2C labelGrid1("labelGrid1", "label grid for EE -", 10, 0., 100., 10, 0., 100.);
0485     for (int i = 1; i <= 10; i++) {
0486       for (int j = 1; j <= 10; j++) {
0487         labelGrid1.SetBinContent(i, j, -10);
0488       }
0489     }
0490 
0491     labelGrid1.SetBinContent(2, 5, -3);
0492     labelGrid1.SetBinContent(2, 7, -2);
0493     labelGrid1.SetBinContent(4, 9, -1);
0494     labelGrid1.SetBinContent(7, 9, -9);
0495     labelGrid1.SetBinContent(9, 7, -8);
0496     labelGrid1.SetBinContent(9, 5, -7);
0497     labelGrid1.SetBinContent(8, 3, -6);
0498     labelGrid1.SetBinContent(6, 2, -5);
0499     labelGrid1.SetBinContent(3, 3, -4);
0500     labelGrid1.SetMarkerSize(2);
0501     labelGrid1.SetMinimum(-9.01);
0502     labelGrid1.SetMaximum(-0.01);
0503 
0504     TH2C labelGrid2("labelGrid2", "label grid for EE +", 10, 0., 100., 10, 0., 100.);
0505 
0506     for (int i = 1; i <= 10; i++) {
0507       for (int j = 1; j <= 10; j++) {
0508         labelGrid2.SetBinContent(i, j, -10);
0509       }
0510     }
0511 
0512     labelGrid2.SetBinContent(2, 5, +3);
0513     labelGrid2.SetBinContent(2, 7, +2);
0514     labelGrid2.SetBinContent(4, 9, +1);
0515     labelGrid2.SetBinContent(7, 9, +9);
0516     labelGrid2.SetBinContent(9, 7, +8);
0517     labelGrid2.SetBinContent(9, 5, +7);
0518     labelGrid2.SetBinContent(8, 3, +6);
0519     labelGrid2.SetBinContent(5, 2, +5);
0520     labelGrid2.SetBinContent(3, 3, +4);
0521 
0522     labelGrid2.SetMarkerSize(2);
0523     labelGrid2.SetMinimum(+0.01);
0524     labelGrid2.SetMaximum(+9.01);
0525 
0526     //EE+
0527     p2.cd();
0528     gPad->SetGridx();
0529     gPad->SetGridy();
0530     EEPlot_plus->Draw("colz");
0531     labelGrid2.Draw("text,same");
0532 
0533     //drawing sector grid
0534 
0535     TLine l;
0536     l.SetLineWidth(1);
0537     for (int i = 0; i < 201; i = i + 1) {
0538       if ((ixSectorsEE[i] != 0 || iySectorsEE[i] != 0) && (ixSectorsEE[i + 1] != 0 || iySectorsEE[i + 1] != 0)) {
0539         l.DrawLine(ixSectorsEE[i], iySectorsEE[i], ixSectorsEE[i + 1], iySectorsEE[i + 1]);
0540       }
0541     }
0542 
0543     //EE-
0544     p3.cd();
0545     gPad->SetGridx();
0546     gPad->SetGridy();
0547     EEPlot_minus->Draw("colz");
0548     labelGrid1.Draw("text,same");
0549 
0550     //drawing sector grid
0551     for (int i = 0; i < 201; i = i + 1) {
0552       if ((ixSectorsEE[i] != 0 || iySectorsEE[i] != 0) && (ixSectorsEE[i + 1] != 0 || iySectorsEE[i + 1] != 0)) {
0553         l.DrawLine(ixSectorsEE[i], iySectorsEE[i], ixSectorsEE[i + 1], iySectorsEE[i + 1]);
0554       }
0555     }
0556 
0557     //drawing everything & printing
0558     c1.Print(m_outputFile.c_str(), m_outputFormat.c_str());
0559   };
0560 
0561   void setTimeAxis(TAxis* axis) {
0562     axis->SetTimeOffset(m_T0.Convert());
0563     axis->SetTimeDisplay(1);
0564     axis->SetTimeFormat("#splitline{%d/%m}{%H:%M:%S}");
0565     axis->SetLabelOffset(0.02);
0566     axis->SetLabelSize(0.03);
0567   }
0568 
0569 private:
0570   RootPlot(){};  // hidden default constructor
0571 
0572   bool m_isInit;
0573   TFile* m_rootfile;
0574   TTree* m_tree;
0575   string m_type;
0576   string m_outputFormat;
0577   string m_outputFile;
0578   string m_outputRoot;
0579   string m_title;
0580   string m_xtitle;
0581   string m_ytitle;
0582   float m_hmin;
0583   float m_hmax;
0584   int m_xAxisType;
0585   int m_debug;
0586   int m_nfields;
0587   int m_nbins[2];
0588   float m_mins[2];
0589   float m_maxs[2];
0590   Float_t m_data[5];
0591 
0592   TDatime m_T0;
0593 };
0594 
0595 void arg_error(string msg) {
0596   cerr << "ERROR:  " << msg << endl;
0597   cerr << "Use 'ECALrootPlotter -h' for help" << endl;
0598   exit(1);
0599 }
0600 
0601 int main(int argc, char* argv[]) {
0602   // Parse command line
0603   program_options::options_description desc("options");
0604   program_options::options_description visible(
0605       "Usage:  ECALrootPlotter [options] [Plot Type] [Output Format] [Output File] \noptions");
0606   visible.add_options()("time,t", "X axis takes time values")(
0607       "file,f", program_options::value<string>(), "input file name")(
0608       "title,T", program_options::value<string>(), "Set plot title")(
0609       "xtitle,X", program_options::value<string>(), "X axis title")(
0610       "ytitle,Y", program_options::value<string>(), "Y axis title")("debug", "Print debug information")("help,h",
0611                                                                                                         "help message");
0612   program_options::options_description hidden("argument");
0613   hidden.add_options()("type", program_options::value<string>(), "Type of ROOT plot")(
0614       "format", program_options::value<string>(), "Output format")(
0615       "output", program_options::value<string>(), "Output file")("hmin", program_options::value<float>(), "histo_min")(
0616       "hmax", program_options::value<float>(), "histo_max");
0617   desc.add(visible).add(hidden);
0618   program_options::positional_options_description pd;
0619   pd.add("type", 1);
0620   pd.add("format", 1);
0621   pd.add("output", 1);
0622   pd.add("hmin", 1);
0623   pd.add("hmax", 1);
0624   program_options::variables_map vm;
0625   try {
0626     program_options::store(program_options::command_line_parser(argc, argv).options(desc).positional(pd).run(), vm);
0627     program_options::notify(vm);
0628   } catch (const program_options::error& e) {
0629     cerr << e.what() << endl;
0630     return 1;
0631   }
0632 
0633   if (vm.count("help")) {
0634     cout << visible << endl;
0635     return 0;
0636   }
0637 
0638   string type, outputFile, outputFormat;
0639   string file = "";
0640   string title = "";
0641   string xtitle = "";
0642   string ytitle = "";
0643   float histo_min = 0;
0644   float histo_max = 0;
0645   int axisCode = RootPlot::DEFAULT_AXIS;
0646   int debug = 0;
0647 
0648   if (vm.count("type")) {
0649     type = vm["type"].as<string>();
0650     if (type != "TH1F" && type != "TH2F" && type != "TGraph" && type != "Map" && type != "EBEEMap") {
0651       cerr << "ERROR:  Plot type " << type << " is not valid." << endl;
0652       arg_error(
0653           "Valid types are:\n"
0654           "  'TH1F'   (1 col data)\n"
0655           "  'TH2F'   (2 col data)\n"
0656           "  'TGraph' (2 col data)\n"
0657           "  'Map'    (2 col data)\n"
0658           "  'EBEEMap'  (5 col data)\n");
0659     }
0660   } else {
0661     arg_error(
0662         "type is required.\n"
0663         "Valid types are:\n"
0664         "  'TH1F'   (1 col data)\n"
0665         "  'TH2F'   (2 col data)\n"
0666         "  'TGraph' (2 col data)\n"
0667         "  'Map'    (2 col data)\n"
0668         "  'EBEEMap'  (5 col data)");
0669   }
0670   if (vm.count("format")) {
0671     outputFormat = vm["format"].as<string>();
0672   } else {
0673     arg_error("format is required");
0674   }
0675   if (vm.count("output")) {
0676     outputFile = vm["output"].as<string>();
0677   } else {
0678     arg_error("output is required");
0679   }
0680   if (vm.count("hmin")) {
0681     histo_min = vm["hmin"].as<float>();
0682   }
0683   if (vm.count("hmax")) {
0684     histo_max = vm["hmax"].as<float>();
0685   }
0686   if (vm.count("file")) {
0687     file = vm["file"].as<string>();
0688   }
0689 
0690   if (vm.count("time")) {
0691     axisCode = RootPlot::TIME_AXIS;
0692   }
0693   if (vm.count("title")) {
0694     title = vm["title"].as<string>();
0695   }
0696   if (vm.count("xtitle")) {
0697     xtitle = vm["xtitle"].as<string>();
0698   }
0699   if (vm.count("ytitle")) {
0700     ytitle = vm["ytitle"].as<string>();
0701   }
0702   if (vm.count("debug")) {
0703     debug = 1;
0704   }
0705 
0706   string path = "";
0707   if ((int)file.find('/') >= 0) {
0708     path = file.substr(0, file.rfind('/'));
0709   }
0710   outputFile = path + "/" + outputFile;
0711 
0712   // substitute _ with spaces
0713   size_t t;
0714   while ((t = title.find('_')) != string::npos)
0715     title[t] = ' ';
0716   while ((t = xtitle.find('_')) != string::npos)
0717     xtitle[t] = ' ';
0718   while ((t = ytitle.find('_')) != string::npos)
0719     ytitle[t] = ' ';
0720 
0721   if (debug) {
0722     cout << "Debug info:    " << endl;
0723     cout << "  type:        " << type << endl;
0724     cout << "  format:      " << outputFormat << endl;
0725     cout << "  output:      " << outputFile << endl;
0726     cout << "  axisCode:    " << axisCode << endl;
0727     cout << "  title:       " << title << endl;
0728     cout << "  xtitle:      " << xtitle << endl;
0729     cout << "  ytitle:      " << ytitle << endl;
0730     cout << "  map min:     " << histo_min << endl;
0731     cout << "  map max:     " << histo_max << endl;
0732     cout << "  input:       " << file << endl;
0733   }
0734 
0735   // Read data from stdin
0736   try {
0737     RootPlot rootplot(type, outputFormat, outputFile, histo_min, histo_max);
0738     rootplot.setXAxisType(axisCode);
0739     rootplot.setTitle(title);
0740     rootplot.setXTitle(xtitle);
0741     rootplot.setYTitle(ytitle);
0742     rootplot.setDebug(debug);
0743 
0744     string line;
0745 
0746     ifstream* finput = (ifstream*)&cin;
0747     if (file.length() > 0) {
0748       finput = new ifstream(file.c_str());
0749     }
0750     while (getline(*finput, line) && finput->good() && !finput->eof()) {
0751       rootplot.parseAndFill(line);
0752     }
0753 
0754     if (finput->bad() || !finput->eof()) {
0755       cerr << "Input error." << endl;
0756     }
0757 
0758     finput->close();
0759 
0760     if (file.length() > 0) {
0761       delete finput;
0762     }
0763     rootplot.draw();
0764 
0765   } catch (std::exception& e) {
0766     cerr << "ERROR:  " << e.what() << endl;
0767   }
0768 }