Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-07-21 01:09:43

0001 // myFunctions.C contains various functions required by makePlots.C
0002 // for making plots of root file output from CSCValidation
0003 // Original author: Andy Kubik (NWU)
0004 // - Updated by many people over the past 15 years
0005 // - This version from Sicheng Wang (UCSB) Jul-2022
0006 // - Please contact CSC DPG for current status - 12.07.2022
0007 
0008 void drawColoredChamberLines(int station, int nchamber1[4][36]);
0009 
0010 TFile *OpenFiles(std::string path) {
0011   TFile *f;
0012   f = new TFile(path.c_str(), "READ");
0013   return f;
0014 }
0015 
0016 void printEmptyChambers(std::string histoname, std::string oname, TFile *f) {
0017   TH2I *plot = (TH2I *)f->Get(histoname.c_str());
0018   std::string endcap, chamber;
0019   int limitr, limitc;
0020   std::vector<string> deadchambers;
0021 
0022   for (int e = 0; e < 2; e++) {
0023     for (int s = 0; s < 4; s++) {
0024       if (s == 0)
0025         limitr = 4;
0026       if (s == 1 || s == 2)
0027         limitr = 2;
0028       if (s == 3)
0029         limitr = 1;
0030       for (int r = 0; r < limitr; r++) {
0031         if (s == 0)
0032           limitc = 36;
0033         if (s != 0 && r == 0)
0034           limitc = 18;
0035         if (s != 0 && r == 1)
0036           limitc = 36;
0037         for (int c = 0; c < limitc; c++) {
0038           int type = 0;
0039           if (s == 0 && r == 0)
0040             type = 2;
0041           else if (s == 0 && r == 1)
0042             type = 3;
0043           else if (s == 0 && r == 2)
0044             type = 4;
0045           else if (s == 0 && r == 3)
0046             type = 1;
0047           else
0048             type = (s + 1) * 2 + (r + 1);
0049           if (e == 0)
0050             type = type + 10;
0051           if (e == 1)
0052             type = 11 - type;
0053           int bin = plot->GetBin((c + 1), type);
0054           float content = plot->GetBinContent(bin);
0055           std::ostringstream oss;
0056           if (e == 0)
0057             endcap = "+";
0058           if (e == 1)
0059             endcap = "-";
0060           oss << "ME " << endcap << (s + 1) << "/" << (r + 1) << "/" << (c + 1);
0061           chamber = oss.str();
0062           if (content == 0) {
0063             if (oname == "wire digis" && (s == 0 && r == 3))
0064               continue;
0065             else
0066               deadchambers.push_back(chamber);
0067           }
0068         }
0069       }
0070     }
0071   }
0072 
0073   int n_dc = deadchambers.size();
0074   ofstream file;
0075   file.open("deadchamberlist.txt", ios::app);
0076   file << "Chambers with missing " << oname << "...\n" << endl;
0077   if (n_dc > 0) {
0078     for (int n = 0; n < n_dc; n++) {
0079       file << deadchambers[n] << endl;
0080     }
0081   }
0082   file << "\n\n\n\n";
0083   file.close();
0084 }
0085 
0086 void make1DPlot(std::string histoname, TFile *f1, std::string histotitle, int statoption, std::string savename) {
0087   TH1F *h1 = (TH1F *)f1->Get(histoname.c_str());
0088 
0089   TCanvas *c = new TCanvas("c", "my canvas", 1);
0090 
0091   if (h1) {
0092     if (statoption == 0)
0093       gStyle->SetOptStat(kFALSE);
0094     else
0095       gStyle->SetOptStat(statoption);
0096     gStyle->SetHistFillColor(92);
0097     gStyle->SetFrameFillColor(4000);
0098     gStyle->SetTitleW(0.7);
0099     gStyle->SetTitleH(0.07);
0100     gPad->SetFillColor(4000);
0101     c->SetFillStyle(4000);
0102     gStyle->SetStatColor(0);
0103     gStyle->SetTitleFillColor(0);
0104     h1->UseCurrentStyle();
0105 
0106     h1->SetTitle(histotitle.c_str());
0107     h1->GetXaxis()->SetLabelSize(0.04);
0108     h1->GetYaxis()->SetLabelSize(0.04);
0109     h1->GetXaxis()->SetTitleOffset(0.7);
0110     h1->GetXaxis()->SetTitleSize(0.06);
0111     h1->GetYaxis()->SetTitleSize(0.06);
0112     h1->GetYaxis()->CenterTitle(kTRUE);
0113     h1->GetXaxis()->SetNdivisions(208, kTRUE);
0114 
0115     h1->Draw();
0116 
0117     c->Update();
0118     c->Print(savename.c_str(), "png");
0119   }
0120   delete c;
0121 }
0122 
0123 void make1DPlot(std::string histoname,
0124                 TFile *f1,
0125                 std::string histotitle,
0126                 std::string xtitle,
0127                 std::string ytitle,
0128                 int statoption,
0129                 std::string savename) {
0130   TH1F *h1 = (TH1F *)f1->Get(histoname.c_str());
0131 
0132   TCanvas *c = new TCanvas("c", "my canvas", 1);
0133 
0134   if (h1) {
0135     if (statoption == 0)
0136       gStyle->SetOptStat(kFALSE);
0137     else
0138       gStyle->SetOptStat(statoption);
0139     gStyle->SetHistFillColor(92);
0140     gStyle->SetFrameFillColor(4000);
0141     gStyle->SetTitleW(0.7);
0142     gStyle->SetTitleH(0.07);
0143     gPad->SetFillColor(4000);
0144     c->SetFillStyle(4000);
0145     gStyle->SetStatColor(0);
0146     gStyle->SetTitleFillColor(0);
0147     h1->UseCurrentStyle();
0148 
0149     h1->SetTitle(histotitle.c_str());
0150     h1->GetXaxis()->SetLabelSize(0.04);
0151     h1->GetYaxis()->SetLabelSize(0.04);
0152     h1->GetXaxis()->SetTitle(xtitle.c_str());
0153     h1->GetYaxis()->SetTitle(ytitle.c_str());
0154     h1->GetXaxis()->SetTitleOffset(0.85);
0155     h1->GetYaxis()->SetTitleOffset(0.85);
0156     h1->GetXaxis()->SetTitleSize(0.05);
0157     h1->GetYaxis()->SetTitleSize(0.05);
0158     h1->GetYaxis()->CenterTitle(kTRUE);
0159     h1->GetXaxis()->SetNdivisions(208, kTRUE);
0160 
0161     h1->Draw();
0162 
0163     c->Update();
0164     c->Print(savename.c_str(), "png");
0165   }
0166   delete c;
0167 }
0168 
0169 void make2DPlot(std::string histoname, TFile *f1, std::string histotitle, int statoption, std::string savename) {
0170   TH2F *h1 = (TH2F *)f1->Get(histoname.c_str());
0171 
0172   TCanvas *c = new TCanvas("c", "my canvas", 1);
0173 
0174   if (h1) {
0175     if (statoption == 0)
0176       gStyle->SetOptStat(kFALSE);
0177     else
0178       gStyle->SetOptStat(statoption);
0179     gStyle->SetHistFillColor(92);
0180     gStyle->SetFrameFillColor(4000);
0181     gStyle->SetTitleW(0.7);
0182     gStyle->SetTitleH(0.07);
0183     gPad->SetFillColor(4000);
0184     c->SetFillStyle(4000);
0185     gStyle->SetStatColor(0);
0186     gStyle->SetTitleFillColor(0);
0187     h1->UseCurrentStyle();
0188 
0189     h1->SetTitle(histotitle.c_str());
0190     h1->GetXaxis()->SetLabelSize(0.04);
0191     h1->GetYaxis()->SetLabelSize(0.04);
0192     h1->GetXaxis()->SetTitleOffset(0.7);
0193     h1->GetXaxis()->SetTitleSize(0.06);
0194     h1->GetXaxis()->SetNdivisions(208, kTRUE);
0195 
0196     h1->Draw();
0197 
0198     c->Update();
0199     c->Print(savename.c_str(), "png");
0200   }
0201   delete c;
0202 }
0203 
0204 void make2DPlot(std::string histoname,
0205                 TFile *f1,
0206                 std::string histotitle,
0207                 std::string xtitle,
0208                 std::string ytitle,
0209                 int statoption,
0210                 std::string savename) {
0211   TH2F *h1 = (TH2F *)f1->Get(histoname.c_str());
0212 
0213   TCanvas *c = new TCanvas("c", "my canvas", 1);
0214 
0215   if (h1) {
0216     if (statoption == 0)
0217       gStyle->SetOptStat(kFALSE);
0218     else
0219       gStyle->SetOptStat(statoption);
0220     gStyle->SetHistFillColor(92);
0221     gStyle->SetFrameFillColor(4000);
0222     gStyle->SetTitleW(0.7);
0223     gStyle->SetTitleH(0.07);
0224     gPad->SetFillColor(4000);
0225     c->SetFillStyle(4000);
0226     gStyle->SetStatColor(0);
0227     gStyle->SetTitleFillColor(0);
0228     h1->UseCurrentStyle();
0229 
0230     h1->SetTitle(histotitle.c_str());
0231     h1->GetXaxis()->SetTitle(xtitle.c_str());
0232     h1->GetYaxis()->SetTitle(ytitle.c_str());
0233     h1->GetXaxis()->SetLabelSize(0.04);
0234     h1->GetYaxis()->SetLabelSize(0.04);
0235     h1->GetXaxis()->SetTitleOffset(0.85);
0236     h1->GetYaxis()->SetTitleOffset(0.85);
0237     h1->GetXaxis()->SetTitleSize(0.05);
0238     h1->GetYaxis()->SetTitleSize(0.05);
0239     h1->GetYaxis()->CenterTitle(kTRUE);
0240     h1->GetXaxis()->SetNdivisions(208, kTRUE);
0241 
0242     h1->Draw();
0243 
0244     c->Update();
0245     c->Print(savename.c_str(), "png");
0246   }
0247   delete c;
0248 }
0249 
0250 void makeProfile(std::string histoname, TFile *f1, std::string histotitle, int statoption, std::string savename) {
0251   TProfile *h1 = (TProfile *)f1->Get(histoname.c_str());
0252 
0253   TCanvas *c = new TCanvas("c", "my canvas", 1);
0254 
0255   if (h1) {
0256     if (statoption == 0)
0257       gStyle->SetOptStat(kFALSE);
0258     else
0259       gStyle->SetOptStat(statoption);
0260     gStyle->SetHistFillColor(92);
0261     gStyle->SetFrameFillColor(4000);
0262     gStyle->SetTitleW(0.7);
0263     gStyle->SetTitleH(0.07);
0264     gPad->SetFillColor(4000);
0265     c->SetFillStyle(4000);
0266     gStyle->SetStatColor(0);
0267     gStyle->SetTitleFillColor(0);
0268     h1->UseCurrentStyle();
0269 
0270     h1->GetYaxis()->SetRangeUser(h1->GetYmin(), h1->GetYmax());
0271     h1->SetTitle(histotitle.c_str());
0272     h1->GetXaxis()->SetLabelSize(0.04);
0273     h1->GetYaxis()->SetLabelSize(0.04);
0274     h1->GetXaxis()->SetTitleOffset(0.7);
0275     h1->GetXaxis()->SetTitleSize(0.06);
0276     h1->GetXaxis()->SetNdivisions(208, kTRUE);
0277 
0278     h1->Draw();
0279 
0280     c->Update();
0281     c->Print(savename.c_str(), "png");
0282   }
0283   delete c;
0284 }
0285 void makeProfile(std::string histoname,
0286                  TFile *f1,
0287                  std::string histotitle,
0288                  std::string xtitle,
0289                  std::string ytitle,
0290                  int statoption,
0291                  std::string savename) {
0292   TProfile *h1 = (TProfile *)f1->Get(histoname.c_str());
0293 
0294   TCanvas *c = new TCanvas("c", "my canvas", 1);
0295 
0296   if (h1) {
0297     if (statoption == 0)
0298       gStyle->SetOptStat(kFALSE);
0299     else
0300       gStyle->SetOptStat(statoption);
0301     gStyle->SetHistFillColor(92);
0302     gStyle->SetFrameFillColor(4000);
0303     gStyle->SetTitleW(0.7);
0304     gStyle->SetTitleH(0.07);
0305     gPad->SetFillColor(4000);
0306     c->SetFillStyle(4000);
0307     gStyle->SetStatColor(0);
0308     gStyle->SetTitleFillColor(0);
0309     h1->UseCurrentStyle();
0310 
0311     h1->GetYaxis()->SetRangeUser(h1->GetYmin(), h1->GetYmax());
0312     h1->SetTitle(histotitle.c_str());
0313     h1->GetXaxis()->SetTitle(xtitle.c_str());
0314     h1->GetYaxis()->SetTitle(ytitle.c_str());
0315     h1->GetXaxis()->SetLabelSize(0.04);
0316     h1->GetYaxis()->SetLabelSize(0.04);
0317     h1->GetXaxis()->SetTitleOffset(0.85);
0318     h1->GetYaxis()->SetTitleOffset(0.85);
0319     h1->GetXaxis()->SetTitleSize(0.05);
0320     h1->GetYaxis()->SetTitleSize(0.05);
0321     h1->GetYaxis()->CenterTitle(kTRUE);
0322     h1->GetXaxis()->SetNdivisions(208, kTRUE);
0323 
0324     h1->Draw();
0325 
0326     c->Update();
0327     c->Print(savename.c_str(), "png");
0328   }
0329   delete c;
0330 }
0331 
0332 void makeCSCOccupancy(std::string histoname, TFile *f1, std::string histotitle, std::string savename) {
0333   TH1F *h1 = (TH1F *)f1->Get(histoname.c_str());
0334 
0335   TCanvas *c = new TCanvas("c", "my canvas", 1);
0336 
0337   if (h1) {
0338     gStyle->SetOptStat(kFALSE);
0339     gStyle->SetHistFillColor(92);
0340     gStyle->SetFrameFillColor(4000);
0341     gStyle->SetTitleW(0.7);
0342     gStyle->SetTitleH(0.07);
0343     gPad->SetFillColor(4000);
0344     c->SetFillStyle(4000);
0345     gStyle->SetStatColor(0);
0346     gStyle->SetTitleFillColor(0);
0347     h1->UseCurrentStyle();
0348 
0349     h1->SetTitle(histotitle.c_str());
0350     h1->GetXaxis()->SetLabelSize(0.04);
0351     h1->GetYaxis()->SetLabelSize(0.04);
0352     h1->GetXaxis()->SetTitleOffset(0.7);
0353     h1->GetXaxis()->SetTitleSize(0.06);
0354     h1->GetXaxis()->SetNdivisions(208, kTRUE);
0355 
0356     h1->GetXaxis()->SetBinLabel(2, "Total Events");
0357     h1->GetXaxis()->SetBinLabel(4, "# Events with Wires");
0358     h1->GetXaxis()->SetBinLabel(6, "# Events with Strips");
0359     h1->GetXaxis()->SetBinLabel(8, "# Events with Wires&Strips");
0360     h1->GetXaxis()->SetBinLabel(10, "# Events with Rechits");
0361     h1->GetXaxis()->SetBinLabel(12, "# Events with Segments");
0362     h1->GetXaxis()->SetBinLabel(14, "Events Rejected");
0363 
0364     h1->Draw();
0365 
0366     c->Update();
0367     c->Print(savename.c_str(), "png");
0368   }
0369 
0370   delete c;
0371 }
0372 
0373 void make1DPlot2(std::string histoname1,
0374                  std::string histoname2,
0375                  int statoption,
0376                  TFile *f1,
0377                  std::string t1,
0378                  std::string t2,
0379                  std::string savename) {
0380   // use this if you want two plots on one canvas
0381 
0382   TH1F *a1 = (TH1F *)f1->Get(histoname1.c_str());
0383   TH1F *b1 = (TH1F *)f1->Get(histoname2.c_str());
0384 
0385   TCanvas *c = new TCanvas("c", "my canvas", 1);
0386   c->Divide(1, 2);
0387 
0388   if (a1) {
0389     c->cd(1);
0390     if (statoption == 0)
0391       gStyle->SetOptStat(kFALSE);
0392     else
0393       gStyle->SetOptStat(statoption);
0394     gStyle->SetHistFillColor(92);
0395     gStyle->SetFrameFillColor(4000);
0396     gStyle->SetTitleW(0.4);
0397     gStyle->SetTitleH(0.09);
0398     gStyle->SetStatColor(0);
0399     gStyle->SetTitleFillColor(0);
0400     gPad->SetFillColor(4000);
0401     c->SetFillStyle(4000);
0402     a1->UseCurrentStyle();
0403     a1->SetTitle(t1.c_str());
0404     a1->GetXaxis()->SetLabelSize(0.06);
0405     a1->GetYaxis()->SetLabelSize(0.06);
0406     a1->GetXaxis()->SetTitleOffset(0.7);
0407     a1->GetXaxis()->SetTitleSize(0.06);
0408     a1->GetXaxis()->SetNdivisions(208, kTRUE);
0409     a1->Draw();
0410   }
0411 
0412   if (b1) {
0413     gStyle->SetHistFillColor(72);
0414     b1->UseCurrentStyle();
0415 
0416     //t2 = t2 + " (run " + run + ")";
0417     b1->SetTitle(t2.c_str());
0418     b1->GetXaxis()->SetLabelSize(0.06);
0419     b1->GetYaxis()->SetLabelSize(0.06);
0420     b1->GetXaxis()->SetTitleOffset(0.7);
0421     b1->GetXaxis()->SetTitleSize(0.06);
0422     b1->GetXaxis()->SetNdivisions(508, kTRUE);
0423     c->cd(2);
0424     b1->Draw();
0425   }
0426 
0427   c->Update();
0428   c->Print(savename.c_str(), "png");
0429   delete c;
0430 }
0431 
0432 void makeEffGif(std::string histoname, TFile *f1, std::string histotitle, std::string savename) {
0433   TH1F *ho = (TH1F *)f1->Get(histoname.c_str());
0434 
0435   TCanvas *c = new TCanvas("c", "my canvas", 1);
0436 
0437   TH1F *hn = new TH1F("tmp", histotitle.c_str(), 20, 0.5, 20.5);
0438 
0439   if (ho) {
0440     float Num = 1;
0441     float Den = 1;
0442     for (int i = 0; i < 20; i++) {
0443       Num = ho->GetBinContent(i + 1);
0444       Den = ho->GetBinContent(i + 21);
0445       //getEfficiency(Num, Den, eff);
0446       float Eff = 0.;
0447       float EffE = 0.;
0448       if (fabs(Den) > 0.000000001) {
0449         Eff = Num / Den;
0450         if (Num < Den) {
0451           EffE = sqrt((1. - Eff) * Eff / Den);
0452         }
0453       }
0454       hn->SetBinContent(i + 1, Eff);
0455       hn->SetBinError(i + 1, EffE);
0456     }
0457 
0458     gStyle->SetOptStat(kFALSE);
0459     gStyle->SetHistFillColor(92);
0460     gStyle->SetFrameFillColor(4000);
0461     gStyle->SetTitleW(0.7);
0462     gStyle->SetTitleH(0.07);
0463     gPad->SetFillColor(4000);
0464     gStyle->SetStatColor(0);
0465     gStyle->SetTitleFillColor(0);
0466     c->SetFillStyle(4000);
0467     hn->UseCurrentStyle();
0468 
0469     hn->SetTitle(histotitle.c_str());
0470     hn->GetXaxis()->SetLabelSize(0.04);
0471     hn->GetYaxis()->SetLabelSize(0.04);
0472     hn->GetXaxis()->SetTitleOffset(0.7);
0473     hn->GetXaxis()->SetTitleSize(0.06);
0474     hn->GetXaxis()->SetNdivisions(208, kTRUE);
0475     hn->GetYaxis()->SetRangeUser(0.5, 1.1);
0476     hn->SetMarkerStyle(6);
0477     hn->GetXaxis()->SetBinLabel(1, "ME +1/1b");
0478     hn->GetXaxis()->SetBinLabel(2, "ME +1/2");
0479     hn->GetXaxis()->SetBinLabel(3, "ME +1/3");
0480     hn->GetXaxis()->SetBinLabel(4, "ME +1/1a");
0481     hn->GetXaxis()->SetBinLabel(5, "ME +2/1");
0482     hn->GetXaxis()->SetBinLabel(6, "ME +2/2");
0483     hn->GetXaxis()->SetBinLabel(7, "ME +3/1");
0484     hn->GetXaxis()->SetBinLabel(8, "ME +3/2");
0485     hn->GetXaxis()->SetBinLabel(9, "ME +4/1");
0486     hn->GetXaxis()->SetBinLabel(10, "ME +4/2");
0487     hn->GetXaxis()->SetBinLabel(11, "ME -1/1b");
0488     hn->GetXaxis()->SetBinLabel(12, "ME -1/2");
0489     hn->GetXaxis()->SetBinLabel(13, "ME -1/3");
0490     hn->GetXaxis()->SetBinLabel(14, "ME -1/1a");
0491     hn->GetXaxis()->SetBinLabel(15, "ME -2/1");
0492     hn->GetXaxis()->SetBinLabel(16, "ME -2/2");
0493     hn->GetXaxis()->SetBinLabel(17, "ME -3/1");
0494     hn->GetXaxis()->SetBinLabel(18, "ME -3/2");
0495     hn->GetXaxis()->SetBinLabel(19, "ME -4/1");
0496     hn->GetXaxis()->SetBinLabel(20, "ME -4/2");
0497     hn->Draw();
0498     c->Update();
0499     c->Print(savename.c_str(), "png");
0500   }
0501   delete c;
0502   delete hn;
0503 }
0504 
0505 void Draw2DProfile(std::string histoname, TFile *f1, std::string title, std::string option, std::string savename) {
0506   TProfile2D *test = (TProfile2D *)f1->Get(histoname.c_str());
0507   TH2D *plot = test->ProjectionXY("test2", option.c_str());
0508 
0509   if (plot) {
0510     TCanvas *c = new TCanvas("c", "my canvas", 1);
0511     gStyle->SetPalette(1, 0);
0512     gPad->SetFillColor(4000);
0513     c->SetFillStyle(4000);
0514     gStyle->SetStatColor(0);
0515     gStyle->SetTitleFillColor(0);
0516     plot->SetStats(kFALSE);
0517     plot->GetYaxis()->SetBinLabel(1, "ME- 4/1");
0518     plot->GetYaxis()->SetBinLabel(2, "ME- 3/2");
0519     plot->GetYaxis()->SetBinLabel(3, "ME- 3/1");
0520     plot->GetYaxis()->SetBinLabel(4, "ME- 2/2");
0521     plot->GetYaxis()->SetBinLabel(5, "ME- 2/1");
0522     plot->GetYaxis()->SetBinLabel(6, "ME- 1/3");
0523     plot->GetYaxis()->SetBinLabel(7, "ME- 1/2");
0524     plot->GetYaxis()->SetBinLabel(8, "ME- 1/1b");
0525     plot->GetYaxis()->SetBinLabel(9, "ME- 1/1a");
0526     plot->GetYaxis()->SetBinLabel(10, "ME+ 1/1a");
0527     plot->GetYaxis()->SetBinLabel(11, "ME+ 1/1b");
0528     plot->GetYaxis()->SetBinLabel(12, "ME+ 1/2");
0529     plot->GetYaxis()->SetBinLabel(13, "ME+ 1/3");
0530     plot->GetYaxis()->SetBinLabel(14, "ME+ 2/1");
0531     plot->GetYaxis()->SetBinLabel(15, "ME+ 2/2");
0532     plot->GetYaxis()->SetBinLabel(16, "ME+ 3/1");
0533     plot->GetYaxis()->SetBinLabel(17, "ME+ 3/2");
0534     plot->GetYaxis()->SetBinLabel(18, "ME+ 4/1");
0535 
0536     plot->SetTitle(title.c_str());
0537 
0538     for (int i = 1; i < 37; i++) {
0539       ostringstream oss1;
0540       oss1 << i;
0541       string ch = oss1.str();
0542       plot->GetXaxis()->SetBinLabel(i, ch.c_str());
0543     }
0544 
0545     c->SetRightMargin(0.12);
0546     plot->GetYaxis()->SetNdivisions(20, kFALSE);
0547     plot->GetXaxis()->SetNdivisions(36, kFALSE);
0548     plot->GetXaxis()->SetTitle("Chamber #");
0549     c->SetGrid();
0550 
0551     plot->Draw("colz");
0552     c->Update();
0553     c->Print(savename.c_str(), "png");
0554     delete c;
0555   }
0556 }
0557 
0558 void Draw2DEfficiency(std::string histo, TFile *f1, std::string title, std::string savename) {
0559   TCanvas *c = new TCanvas("c", "my canvas", 1);
0560   gStyle->SetPalette(1, 0);
0561   gPad->SetFillColor(4000);
0562   c->SetFillStyle(4000);
0563   gStyle->SetStatColor(0);
0564   gStyle->SetTitleFillColor(0);
0565   gStyle->SetOptStat(10);
0566 
0567   TH2F *num = (TH2F *)f1->Get(histo.c_str());
0568   TH2F *denom = (TH2F *)f1->Get("Efficiency/hEffDenominator");
0569   if (histo.find("Tight") != std::string::npos)
0570     denom = (TH2F *)f1->Get("Efficiency/hEffDenominatorTight");
0571 
0572   TH2F *plot = new TH2F("plot", title.c_str(), 36, 0.5, 36.5, 20, 0.5, 20.5);
0573 
0574   if (num && denom)
0575     plot->Divide(num, denom, 1., 1., "B");
0576 
0577   //plot->SetStats(kFALSE);
0578 
0579   plot->GetYaxis()->SetBinLabel(1, "ME- 4/2");  //jun28
0580   plot->GetYaxis()->SetBinLabel(2, "ME- 4/1");
0581   plot->GetYaxis()->SetBinLabel(3, "ME- 3/2");
0582   plot->GetYaxis()->SetBinLabel(4, "ME- 3/1");
0583   plot->GetYaxis()->SetBinLabel(5, "ME- 2/2");
0584   plot->GetYaxis()->SetBinLabel(6, "ME- 2/1");
0585   plot->GetYaxis()->SetBinLabel(10, "ME- 1/1a");
0586   plot->GetYaxis()->SetBinLabel(7, "ME- 1/3");
0587   plot->GetYaxis()->SetBinLabel(8, "ME- 1/2");
0588   plot->GetYaxis()->SetBinLabel(9, "ME- 1/1b");
0589   plot->GetYaxis()->SetBinLabel(12, "ME+ 1/1b");
0590   plot->GetYaxis()->SetBinLabel(13, "ME+ 1/2");
0591   plot->GetYaxis()->SetBinLabel(14, "ME+ 1/3");
0592   plot->GetYaxis()->SetBinLabel(11, "ME+ 1/1a");
0593   plot->GetYaxis()->SetBinLabel(15, "ME+ 2/1");
0594   plot->GetYaxis()->SetBinLabel(16, "ME+ 2/2");
0595   plot->GetYaxis()->SetBinLabel(17, "ME+ 3/1");
0596   plot->GetYaxis()->SetBinLabel(18, "ME+ 3/2");
0597   plot->GetYaxis()->SetBinLabel(19, "ME+ 4/1");
0598   plot->GetYaxis()->SetBinLabel(20, "ME+ 4/2");  //jun28
0599 
0600   for (int i = 1; i < 37; i++) {
0601     ostringstream oss1;
0602     oss1 << i;
0603     string ch = oss1.str();
0604     plot->GetXaxis()->SetBinLabel(i, ch.c_str());
0605   }
0606 
0607   c->SetRightMargin(0.12);
0608 
0609   plot->GetYaxis()->SetNdivisions(20, kFALSE);
0610   plot->GetXaxis()->SetNdivisions(36, kFALSE);
0611 
0612   plot->GetXaxis()->SetTitle("Chamber #");
0613 
0614   c->SetGrid();
0615 
0616   plot->Draw("COLZ");
0617 
0618   c->Update();
0619   c->Print(savename.c_str(), "png");
0620   delete c;
0621   delete plot;
0622 }
0623 
0624 void Draw2DTempPlot(std::string histo, TFile *f1, bool includeME11, std::string savename, bool hasLabels = false) {
0625   TCanvas *c = new TCanvas("c", "my canvas", 1);
0626   gStyle->SetPalette(1, 0);
0627   gPad->SetFillColor(4000);
0628   c->SetFillStyle(4000);
0629   gStyle->SetStatColor(0);
0630   gStyle->SetTitleFillColor(0);
0631   gStyle->SetOptStat(10);
0632 
0633   TH2I *plot = (TH2I *)f1->Get(histo.c_str());
0634 
0635   //plot->SetStats(kFALSE);
0636 
0637   if (!hasLabels) {
0638     if (includeME11) {
0639       plot->GetYaxis()->SetBinLabel(1, "ME- 4/2");
0640       plot->GetYaxis()->SetBinLabel(2, "ME- 4/1");
0641       plot->GetYaxis()->SetBinLabel(3, "ME- 3/2");
0642       plot->GetYaxis()->SetBinLabel(4, "ME- 3/1");
0643       plot->GetYaxis()->SetBinLabel(5, "ME- 2/2");
0644       plot->GetYaxis()->SetBinLabel(6, "ME- 2/1");
0645       plot->GetYaxis()->SetBinLabel(10, "ME- 1/1a");
0646       plot->GetYaxis()->SetBinLabel(7, "ME- 1/3");
0647       plot->GetYaxis()->SetBinLabel(8, "ME- 1/2");
0648       plot->GetYaxis()->SetBinLabel(9, "ME- 1/1b");
0649       plot->GetYaxis()->SetBinLabel(12, "ME+ 1/1b");
0650       plot->GetYaxis()->SetBinLabel(13, "ME+ 1/2");
0651       plot->GetYaxis()->SetBinLabel(14, "ME+ 1/3");
0652       plot->GetYaxis()->SetBinLabel(11, "ME+ 1/1a");
0653       plot->GetYaxis()->SetBinLabel(15, "ME+ 2/1");
0654       plot->GetYaxis()->SetBinLabel(16, "ME+ 2/2");
0655       plot->GetYaxis()->SetBinLabel(17, "ME+ 3/1");
0656       plot->GetYaxis()->SetBinLabel(18, "ME+ 3/2");
0657       plot->GetYaxis()->SetBinLabel(19, "ME+ 4/1");
0658       plot->GetYaxis()->SetBinLabel(20, "ME+ 4/2");
0659     } else {
0660       plot->GetYaxis()->SetBinLabel(1, "ME- 4/1");
0661       plot->GetYaxis()->SetBinLabel(2, "ME- 3/2");
0662       plot->GetYaxis()->SetBinLabel(3, "ME- 3/1");
0663       plot->GetYaxis()->SetBinLabel(4, "ME- 2/2");
0664       plot->GetYaxis()->SetBinLabel(5, "ME- 2/1");
0665       plot->GetYaxis()->SetBinLabel(6, "ME- 1/3");
0666       plot->GetYaxis()->SetBinLabel(7, "ME- 1/2");
0667       plot->GetYaxis()->SetBinLabel(8, "ME- 1/1b");
0668       plot->GetYaxis()->SetBinLabel(9, "ME- 1/1a");
0669       plot->GetYaxis()->SetBinLabel(10, "ME+ 1/1a");
0670       plot->GetYaxis()->SetBinLabel(11, "ME+ 1/1b");
0671       plot->GetYaxis()->SetBinLabel(12, "ME+ 1/2");
0672       plot->GetYaxis()->SetBinLabel(13, "ME+ 1/3");
0673       plot->GetYaxis()->SetBinLabel(14, "ME+ 2/1");
0674       plot->GetYaxis()->SetBinLabel(15, "ME+ 2/2");
0675       plot->GetYaxis()->SetBinLabel(16, "ME+ 3/1");
0676       plot->GetYaxis()->SetBinLabel(17, "ME+ 3/2");
0677       plot->GetYaxis()->SetBinLabel(18, "ME+ 4/1");
0678     }
0679 
0680     for (int i = 1; i < 37; i++) {
0681       ostringstream oss1;
0682       oss1 << i;
0683       string ch = oss1.str();
0684       plot->GetXaxis()->SetBinLabel(i, ch.c_str());
0685     }
0686 
0687     plot->GetYaxis()->SetNdivisions(20, kFALSE);
0688     plot->GetXaxis()->SetNdivisions(36, kFALSE);
0689 
0690     plot->GetXaxis()->SetTitle("Chamber #");
0691 
0692     c->SetGrid();
0693   }
0694 
0695   c->SetRightMargin(0.12);
0696   plot->Draw("COLZ");
0697 
0698   c->Update();
0699   c->Print(savename.c_str(), "png");
0700   delete c;
0701 }
0702 
0703 void Draw2DTempPlot2(std::string histo, TFile *f1, bool includeME11, std::string savename) {
0704   TCanvas *c = new TCanvas("c", "my canvas", 1);
0705   gStyle->SetPalette(1, 0);
0706   gPad->SetFillColor(4000);
0707   c->SetFillStyle(4000);
0708   gStyle->SetStatColor(0);
0709   gStyle->SetTitleFillColor(0);
0710 
0711   TH2F *plot = (TH2F *)f1->Get(histo.c_str());
0712 
0713   plot->SetStats(kFALSE);
0714 
0715   if (includeME11) {
0716     plot->GetYaxis()->SetBinLabel(1, "ME- 4/2");
0717     plot->GetYaxis()->SetBinLabel(2, "ME- 4/1");
0718     plot->GetYaxis()->SetBinLabel(3, "ME- 3/2");
0719     plot->GetYaxis()->SetBinLabel(4, "ME- 3/1");
0720     plot->GetYaxis()->SetBinLabel(5, "ME- 2/2");
0721     plot->GetYaxis()->SetBinLabel(6, "ME- 2/1");
0722     plot->GetYaxis()->SetBinLabel(10, "ME- 1/1a");
0723     plot->GetYaxis()->SetBinLabel(7, "ME- 1/3");
0724     plot->GetYaxis()->SetBinLabel(8, "ME- 1/2");
0725     plot->GetYaxis()->SetBinLabel(9, "ME- 1/1b");
0726     plot->GetYaxis()->SetBinLabel(12, "ME+ 1/1b");
0727     plot->GetYaxis()->SetBinLabel(13, "ME+ 1/2");
0728     plot->GetYaxis()->SetBinLabel(14, "ME+ 1/3");
0729     plot->GetYaxis()->SetBinLabel(11, "ME+ 1/1a");
0730     plot->GetYaxis()->SetBinLabel(15, "ME+ 2/1");
0731     plot->GetYaxis()->SetBinLabel(16, "ME+ 2/2");
0732     plot->GetYaxis()->SetBinLabel(17, "ME+ 3/1");
0733     plot->GetYaxis()->SetBinLabel(18, "ME+ 3/2");
0734     plot->GetYaxis()->SetBinLabel(19, "ME+ 4/1");
0735     plot->GetYaxis()->SetBinLabel(20, "ME+ 4/2");
0736   } else {
0737     plot->GetYaxis()->SetBinLabel(1, "ME- 4/1");
0738     plot->GetYaxis()->SetBinLabel(2, "ME- 3/2");
0739     plot->GetYaxis()->SetBinLabel(3, "ME- 3/1");
0740     plot->GetYaxis()->SetBinLabel(4, "ME- 2/2");
0741     plot->GetYaxis()->SetBinLabel(5, "ME- 2/1");
0742     plot->GetYaxis()->SetBinLabel(6, "ME- 1/3");
0743     plot->GetYaxis()->SetBinLabel(7, "ME- 1/2");
0744     plot->GetYaxis()->SetBinLabel(8, "ME- 1/1b");
0745     plot->GetYaxis()->SetBinLabel(9, "ME- 1/1a");
0746     plot->GetYaxis()->SetBinLabel(10, "ME+ 1/1a");
0747     plot->GetYaxis()->SetBinLabel(11, "ME+ 1/1b");
0748     plot->GetYaxis()->SetBinLabel(12, "ME+ 1/2");
0749     plot->GetYaxis()->SetBinLabel(13, "ME+ 1/3");
0750     plot->GetYaxis()->SetBinLabel(14, "ME+ 2/1");
0751     plot->GetYaxis()->SetBinLabel(15, "ME+ 2/2");
0752     plot->GetYaxis()->SetBinLabel(16, "ME+ 3/1");
0753     plot->GetYaxis()->SetBinLabel(17, "ME+ 3/2");
0754     plot->GetYaxis()->SetBinLabel(18, "ME+ 4/1");
0755   }
0756 
0757   for (int i = 1; i < 37; i++) {
0758     ostringstream oss1;
0759     oss1 << i;
0760     string ch = oss1.str();
0761     plot->GetXaxis()->SetBinLabel(i, ch.c_str());
0762   }
0763 
0764   c->SetRightMargin(0.12);
0765 
0766   plot->GetYaxis()->SetNdivisions(20, kFALSE);
0767   plot->GetXaxis()->SetNdivisions(36, kFALSE);
0768 
0769   plot->GetXaxis()->SetTitle("Chamber #");
0770 
0771   c->SetGrid();
0772 
0773   plot->Draw("COLZ");
0774 
0775   c->Update();
0776   c->Print(savename.c_str(), "png");
0777   delete c;
0778 }
0779 
0780 void GlobalPosfromTree(
0781     std::string graphname, TFile *f1, int endcap, int station, std::string type, std::string savename) {
0782   TTree *t1;
0783   TBranch *b1;
0784   struct posRecord {
0785     int endcap;
0786     int station;
0787     int ring;
0788     int chamber;
0789     int layer;
0790     float localx;
0791     float localy;
0792     float globalx;
0793     float globaly;
0794   } points;
0795 
0796   if (type == "rechit") {
0797     t1 = (TTree *)f1->Get("recHits/rHPositions");
0798     b1 = t1->GetBranch("rHpos");
0799     b1->SetAddress(&points);
0800   }
0801 
0802   if (type == "segment") {
0803     t1 = (TTree *)f1->Get("Segments/segPositions");
0804     b1 = t1->GetBranch("segpos");
0805     b1->SetAddress(&points);
0806   }
0807 
0808   int n1 = (int)t1->GetEntries();
0809   const int nevents1 = n1;
0810   TVectorF globx1(nevents1);
0811   TVectorF globy1(nevents1);
0812   int nstation1 = 0;
0813   const int num_of_rings = 4;
0814   const int num_of_chambers = 36;
0815   int nchamber1[num_of_rings][num_of_chambers];
0816   for (int i = 0; i < num_of_rings; i++) {
0817     for (int j = 0; j < num_of_chambers; j++) {
0818       nchamber1[i][j] = 0;
0819     }
0820   }
0821 
0822   for (int i = 0; i < nevents1; i++) {
0823     b1->GetEntry(i);
0824     if (points.station == station && points.endcap == endcap) {
0825       globx1[nstation1] = points.globalx;
0826       globy1[nstation1] = points.globaly;
0827       nstation1++;
0828       nchamber1[points.ring - 1][points.chamber - 1]++;
0829     }
0830   }
0831 
0832   TCanvas *c = new TCanvas("c", "my canvas", 1);
0833   c->SetCanvasSize(700, 700);
0834   //TGraph *graph1 = new TGraph(nstation1,globx1,globy1);
0835   TGraph *graph1 = new TGraph(globx1, globy1);
0836 
0837   std::string name1 = graphname;
0838 
0839   gStyle->SetPalette(1, 0);
0840   gStyle->SetTitleW(0.9);
0841   gStyle->SetTitleH(0.1);
0842   gStyle->SetStatColor(0);
0843   gStyle->SetTitleFillColor(0);
0844   gPad->SetFillColor(4000);
0845   c->SetFillStyle(4000);
0846 
0847   //asking to show the total number of entries for rechit and seg plots
0848   //i.e. SetOptStat(10), returns 0 entries for some reason
0849   gStyle->SetOptStat(0);
0850 
0851   graph1->GetXaxis()->SetLimits(-720, 720);
0852   graph1->GetYaxis()->SetLimits(-720, 720);
0853   graph1->GetXaxis()->SetRangeUser(-720, 720);
0854   graph1->GetYaxis()->SetRangeUser(-720, 720);
0855 
0856   graph1->SetTitle(name1.c_str());
0857   graph1->UseCurrentStyle();
0858   graph1->Draw("AP");
0859 
0860   //  drawChamberLines(station);
0861   drawColoredChamberLines(station, nchamber1);
0862 
0863   c->Print(savename.c_str(), "png");
0864   delete c;
0865 
0866 }  // end GlobalPosfromTree
0867 
0868 void GlobalPosfromChain(std::string graphname,
0869                         TChain *ch1,
0870                         int endcap,
0871                         int station,
0872                         std::string type,
0873                         std::string savename,
0874                         const int maxNumPoints = 10'000'000) {
0875   struct posRecord {
0876     int endcap;
0877     int station;
0878     int ring;
0879     int chamber;
0880     int layer;
0881     float localx;
0882     float localy;
0883     float globalx;
0884     float globaly;
0885   } points;
0886 
0887   if (type == "rechit")
0888     ch1->SetBranchAddress("rHpos", &points);
0889   else if (type == "segment")
0890     ch1->SetBranchAddress("segpos", &points);
0891 
0892   int n1 = ch1->GetEntries();
0893   const int nevents1 = TMath::Min(n1, maxNumPoints);
0894   TVectorF globx1(nevents1);
0895   TVectorF globy1(nevents1);
0896   int nstation1 = 0;
0897   const int num_of_rings = 4;
0898   const int num_of_chambers = 36;
0899   int nchamber1[num_of_rings][num_of_chambers];
0900   for (int i = 0; i < num_of_rings; i++) {
0901     for (int j = 0; j < num_of_chambers; j++) {
0902       nchamber1[i][j] = 0;
0903     }
0904   }
0905 
0906   for (int i = 0; i < nevents1; i++) {
0907     ch1->GetEntry(i);
0908     if (points.station == station && points.endcap == endcap) {
0909       globx1[nstation1] = points.globalx;
0910       globy1[nstation1] = points.globaly;
0911       nstation1++;
0912       nchamber1[points.ring - 1][points.chamber - 1]++;
0913     }
0914   }
0915 
0916   TCanvas *c = new TCanvas("c", "my canvas", 1);
0917   c->SetCanvasSize(700, 700);
0918   gStyle->SetPalette(1, 0);
0919   gStyle->SetTitleW(0.9);
0920   gStyle->SetTitleH(0.1);
0921   gStyle->SetStatColor(0);
0922   gStyle->SetTitleFillColor(0);
0923   gPad->SetFillColor(4000);
0924   c->SetFillStyle(4000);
0925 
0926   //asking to show the total number of entries for rechit and seg plots
0927   //i.e. SetOptStat(10), returns 0 entries for some reason
0928   gStyle->SetOptStat(0);
0929 
0930   TGraph *graph1 = new TGraph(globx1, globy1);
0931   std::string name1 = graphname;
0932   graph1->GetXaxis()->SetLimits(-720, 720);
0933   graph1->GetYaxis()->SetLimits(-720, 720);
0934   graph1->GetXaxis()->SetRangeUser(-720, 720);
0935   graph1->GetYaxis()->SetRangeUser(-720, 720);
0936 
0937   graph1->SetTitle(name1.c_str());
0938   graph1->UseCurrentStyle();
0939   graph1->Draw("AP");
0940 
0941   drawColoredChamberLines(station, nchamber1);
0942 
0943   c->Print(savename.c_str(), "png");
0944 
0945 }  // end GlobalPosfromChain
0946 
0947 void drawChamberLines(int station) {
0948   gStyle->SetLineWidth(2);
0949   float pi = 3.14159;
0950   TVector3 x(0, 0, 1);
0951   int linecolor = 1;
0952   //for alternating colors, set 2 diff colors here
0953   int lc1 = 1;
0954   int lc2 = 1;
0955 
0956   if (station == 1) {
0957     TVector3 p1(101, 9.361, 0);
0958     TVector3 p2(101, -9.361, 0);
0959     TVector3 p3(260, -22.353, 0);
0960     TVector3 p4(260, 22.353, 0);
0961 
0962     TLine *line1;
0963     TLine *line2;
0964     TLine *line3;
0965     TLine *line4;
0966 
0967     for (int i = 0; i < 36; i++) {
0968       if (linecolor == lc1)
0969         linecolor = lc2;
0970       else
0971         linecolor = lc1;
0972 
0973       line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
0974       line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
0975       line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
0976       line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
0977       line1->SetLineColor(linecolor);
0978       line2->SetLineColor(linecolor);
0979       line3->SetLineColor(linecolor);
0980       line4->SetLineColor(linecolor);
0981 
0982       line1->Draw();
0983       line2->Draw();
0984       line3->Draw();
0985       line4->Draw();
0986 
0987       p1.Rotate(pi / 18, x);
0988       p2.Rotate(pi / 18, x);
0989       p3.Rotate(pi / 18, x);
0990       p4.Rotate(pi / 18, x);
0991     }
0992 
0993     TVector3 q1(281.49, 25.5, 0);
0994     TVector3 q2(281.49, -25.5, 0);
0995     TVector3 q3(455.99, -41.87, 0);
0996     TVector3 q4(455.99, 41.87, 0);
0997 
0998     for (int i = 0; i < 36; i++) {
0999       if (linecolor == lc2)
1000         linecolor = lc1;
1001       else
1002         linecolor = lc2;
1003 
1004       line1 = new TLine(q1(0), q1(1), q2(0), q2(1));
1005       line2 = new TLine(q2(0), q2(1), q3(0), q3(1));
1006       line3 = new TLine(q3(0), q3(1), q4(0), q4(1));
1007       line4 = new TLine(q4(0), q4(1), q1(0), q1(1));
1008 
1009       line1->SetLineColor(linecolor);
1010       line2->SetLineColor(linecolor);
1011       line3->SetLineColor(linecolor);
1012       line4->SetLineColor(linecolor);
1013 
1014       line1->Draw();
1015       line2->Draw();
1016       line3->Draw();
1017       line4->Draw();
1018 
1019       q1.Rotate(pi / 18, x);
1020       q2.Rotate(pi / 18, x);
1021       q3.Rotate(pi / 18, x);
1022       q4.Rotate(pi / 18, x);
1023     }
1024 
1025     TVector3 r1(511.99, 31.7, 0);
1026     TVector3 r2(511.99, -31.7, 0);
1027     TVector3 r3(676.15, -46.05, 0);
1028     TVector3 r4(676.15, 46.05, 0);
1029 
1030     for (int i = 0; i < 36; i++) {
1031       if (linecolor == lc1)
1032         linecolor = lc2;
1033       else
1034         linecolor = lc1;
1035 
1036       line1 = new TLine(r1(0), r1(1), r2(0), r2(1));
1037       line2 = new TLine(r2(0), r2(1), r3(0), r3(1));
1038       line3 = new TLine(r3(0), r3(1), r4(0), r4(1));
1039       line4 = new TLine(r4(0), r4(1), r1(0), r1(1));
1040       line1->SetLineColor(linecolor);
1041       line2->SetLineColor(linecolor);
1042       line3->SetLineColor(linecolor);
1043       line4->SetLineColor(linecolor);
1044 
1045       line1->Draw();
1046       line2->Draw();
1047       line3->Draw();
1048       line4->Draw();
1049 
1050       r1.Rotate(pi / 18, x);
1051       r2.Rotate(pi / 18, x);
1052       r3.Rotate(pi / 18, x);
1053       r4.Rotate(pi / 18, x);
1054     }
1055   }
1056 
1057   if (station == 2) {
1058     TVector3 p1(146.9, 27.0, 0);
1059     TVector3 p2(146.9, -27.0, 0);
1060     TVector3 p3(336.56, -62.855, 0);
1061     TVector3 p4(336.56, 62.855, 0);
1062 
1063     p1.Rotate(pi / 36, x);
1064     p2.Rotate(pi / 36, x);
1065     p3.Rotate(pi / 36, x);
1066     p4.Rotate(pi / 36, x);
1067 
1068     TLine *line1;
1069     TLine *line2;
1070     TLine *line3;
1071     TLine *line4;
1072 
1073     for (int i = 0; i < 36; i++) {
1074       if (linecolor == lc1)
1075         linecolor = lc2;
1076       else
1077         linecolor = lc1;
1078 
1079       line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
1080       line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
1081       line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
1082       line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
1083       line1->SetLineColor(linecolor);
1084       line2->SetLineColor(linecolor);
1085       line3->SetLineColor(linecolor);
1086       line4->SetLineColor(linecolor);
1087 
1088       line1->Draw();
1089       line2->Draw();
1090       line3->Draw();
1091       line4->Draw();
1092 
1093       p1.Rotate(pi / 9, x);
1094       p2.Rotate(pi / 9, x);
1095       p3.Rotate(pi / 9, x);
1096       p4.Rotate(pi / 9, x);
1097     }
1098 
1099     TVector3 q1(364.02, 33.23, 0);
1100     TVector3 q2(364.02, -33.23, 0);
1101     TVector3 q3(687.08, -63.575, 0);
1102     TVector3 q4(687.08, 63.575, 0);
1103 
1104     for (int i = 0; i < 36; i++) {
1105       if (linecolor == lc2)
1106         linecolor = lc1;
1107       else
1108         linecolor = lc2;
1109 
1110       line1 = new TLine(q1(0), q1(1), q2(0), q2(1));
1111       line2 = new TLine(q2(0), q2(1), q3(0), q3(1));
1112       line3 = new TLine(q3(0), q3(1), q4(0), q4(1));
1113       line4 = new TLine(q4(0), q4(1), q1(0), q1(1));
1114       line1->SetLineColor(linecolor);
1115       line2->SetLineColor(linecolor);
1116       line3->SetLineColor(linecolor);
1117       line4->SetLineColor(linecolor);
1118 
1119       line1->Draw();
1120       line2->Draw();
1121       line3->Draw();
1122       line4->Draw();
1123 
1124       q1.Rotate(pi / 18, x);
1125       q2.Rotate(pi / 18, x);
1126       q3.Rotate(pi / 18, x);
1127       q4.Rotate(pi / 18, x);
1128     }
1129   }
1130 
1131   if (station == 3) {
1132     TVector3 p1(166.89, 30.7, 0);
1133     TVector3 p2(166.89, -30.7, 0);
1134     TVector3 p3(336.59, -62.855, 0);
1135     TVector3 p4(336.59, 62.855, 0);
1136 
1137     p1.Rotate(pi / 36, x);
1138     p2.Rotate(pi / 36, x);
1139     p3.Rotate(pi / 36, x);
1140     p4.Rotate(pi / 36, x);
1141 
1142     TLine *line1;
1143     TLine *line2;
1144     TLine *line3;
1145     TLine *line4;
1146 
1147     for (int i = 0; i < 36; i++) {
1148       if (linecolor == lc1)
1149         linecolor = lc2;
1150       else
1151         linecolor = lc1;
1152 
1153       line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
1154       line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
1155       line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
1156       line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
1157       line1->SetLineColor(linecolor);
1158       line2->SetLineColor(linecolor);
1159       line3->SetLineColor(linecolor);
1160       line4->SetLineColor(linecolor);
1161 
1162       line1->Draw();
1163       line2->Draw();
1164       line3->Draw();
1165       line4->Draw();
1166 
1167       p1.Rotate(pi / 9, x);
1168       p2.Rotate(pi / 9, x);
1169       p3.Rotate(pi / 9, x);
1170       p4.Rotate(pi / 9, x);
1171     }
1172 
1173     TVector3 q1(364.02, 33.23, 0);
1174     TVector3 q2(364.02, -33.23, 0);
1175     TVector3 q3(687.08, -63.575, 0);
1176     TVector3 q4(687.08, 63.575, 0);
1177 
1178     for (int i = 0; i < 36; i++) {
1179       if (linecolor == lc2)
1180         linecolor = lc1;
1181       else
1182         linecolor = lc2;
1183 
1184       line1 = new TLine(q1(0), q1(1), q2(0), q2(1));
1185       line2 = new TLine(q2(0), q2(1), q3(0), q3(1));
1186       line3 = new TLine(q3(0), q3(1), q4(0), q4(1));
1187       line4 = new TLine(q4(0), q4(1), q1(0), q1(1));
1188       line1->SetLineColor(linecolor);
1189       line2->SetLineColor(linecolor);
1190       line3->SetLineColor(linecolor);
1191       line4->SetLineColor(linecolor);
1192 
1193       line1->Draw();
1194       line2->Draw();
1195       line3->Draw();
1196       line4->Draw();
1197 
1198       q1.Rotate(pi / 18, x);
1199       q2.Rotate(pi / 18, x);
1200       q3.Rotate(pi / 18, x);
1201       q4.Rotate(pi / 18, x);
1202     }
1203   }
1204 
1205   if (station == 4) {
1206     TVector3 p1(186.99, 34.505, 0);
1207     TVector3 p2(186.99, -34.505, 0);
1208     TVector3 p3(336.41, -62.825, 0);
1209     TVector3 p4(336.41, 62.825, 0);
1210 
1211     p1.Rotate(pi / 36, x);
1212     p2.Rotate(pi / 36, x);
1213     p3.Rotate(pi / 36, x);
1214     p4.Rotate(pi / 36, x);
1215 
1216     TLine *line1;
1217     TLine *line2;
1218     TLine *line3;
1219     TLine *line4;
1220 
1221     for (int i = 0; i < 36; i++) {
1222       if (linecolor == lc1)
1223         linecolor = lc2;
1224       else
1225         linecolor = lc1;
1226 
1227       line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
1228       line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
1229       line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
1230       line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
1231       line1->SetLineColor(linecolor);
1232       line2->SetLineColor(linecolor);
1233       line3->SetLineColor(linecolor);
1234       line4->SetLineColor(linecolor);
1235 
1236       line1->Draw();
1237       line2->Draw();
1238       line3->Draw();
1239       line4->Draw();
1240 
1241       p1.Rotate(pi / 9, x);
1242       p2.Rotate(pi / 9, x);
1243       p3.Rotate(pi / 9, x);
1244       p4.Rotate(pi / 9, x);
1245     }
1246   }
1247 }
1248 
1249 void compare1DPlot(
1250     std::string histoname, TFile *f1, TFile *f2, std::string histotitle, int statoption, std::string savename) {
1251   // used to compare two of the same histogram from different releases/runs/etc
1252 
1253   TH1F *h2 = (TH1F *)f1->Get(histoname.c_str());
1254   TH1F *h1 = (TH1F *)f2->Get(histoname.c_str());
1255 
1256   TCanvas *c = new TCanvas("c", "my canvas", 1);
1257 
1258   if (h1 && h2) {
1259     gStyle->SetHistFillColor(92);
1260     gStyle->SetFrameFillColor(4000);
1261     gStyle->SetTitleW(0.5);
1262     gStyle->SetTitleH(0.07);
1263     gStyle->SetStatColor(0);
1264     gStyle->SetTitleFillColor(0);
1265     gPad->SetFillColor(4000);
1266     c->SetFillStyle(4000);
1267     gStyle->SetOptStat(statoption);
1268     h1->UseCurrentStyle();
1269     h2->UseCurrentStyle();
1270     h2->SetFillColor(52);
1271 
1272     h1->SetTitle(histotitle.c_str());
1273     h1->GetXaxis()->SetLabelSize(0.04);
1274     h1->GetYaxis()->SetLabelSize(0.04);
1275     h1->GetXaxis()->SetTitleOffset(0.7);
1276     h1->GetXaxis()->SetTitleSize(0.06);
1277     h1->GetXaxis()->SetNdivisions(208, kTRUE);
1278 
1279     TLegend *leg = new TLegend(0.79, 0.74, 0.89, 0.84);
1280     leg->AddEntry(h1, "ref", "f");
1281     leg->AddEntry(h2, "new", "l");
1282 
1283     h1->Draw();
1284     h2->Draw("same e");
1285     leg->Draw();
1286   }
1287 
1288   c->Update();
1289   c->Print(savename.c_str(), "png");
1290   delete c;
1291 }
1292 
1293 void compareEffGif(std::string histoname, TFile *f1, TFile *f2, std::string histotitle, std::string savename) {
1294   TH1F *h1 = (TH1F *)f1->Get(histoname.c_str());
1295   TH1F *h2 = (TH1F *)f2->Get(histoname.c_str());
1296 
1297   TCanvas *c = new TCanvas("c", "my canvas", 1);
1298 
1299   TH1F *hn1 = new TH1F("tmp1", histotitle.c_str(), 20, 0.5, 20.5);
1300   TH1F *hn2 = new TH1F("tmp2", histotitle.c_str(), 20, 0.5, 20.5);
1301 
1302   if (h1 && h2) {
1303     float Num = 1;
1304     float Den = 1;
1305     for (int i = 0; i < 20; i++) {
1306       Num = h1->GetBinContent(i + 1);
1307       Den = h1->GetBinContent(i + 21);
1308       //getEfficiency(Num, Den, eff);
1309       float Eff = 0.;
1310       float EffE = 0.;
1311       if (fabs(Den) > 0.000000001) {
1312         Eff = Num / Den;
1313         if (Num < Den) {
1314           EffE = sqrt((1. - Eff) * Eff / Den);
1315         }
1316       }
1317       hn1->SetBinContent(i + 1, Eff);
1318       hn1->SetBinError(i + 1, EffE);
1319     }
1320 
1321     Num = 1;
1322     Den = 1;
1323     for (int i = 0; i < 20; i++) {
1324       Num = h2->GetBinContent(i + 1);
1325       Den = h2->GetBinContent(i + 21);
1326       //getEfficiency(Num, Den, eff);
1327       float Eff = 0.;
1328       float EffE = 0.;
1329       if (fabs(Den) > 0.000000001) {
1330         Eff = Num / Den;
1331         if (Num < Den) {
1332           EffE = sqrt((1. - Eff) * Eff / Den);
1333         }
1334       }
1335       hn2->SetBinContent(i + 1, Eff);
1336       hn2->SetBinError(i + 1, EffE);
1337     }
1338 
1339     gStyle->SetOptStat(kFALSE);
1340     gStyle->SetHistFillColor(92);
1341     gStyle->SetFrameFillColor(4000);
1342     gStyle->SetTitleW(0.7);
1343     gStyle->SetTitleH(0.07);
1344     gPad->SetFillColor(4000);
1345     gStyle->SetStatColor(0);
1346     gStyle->SetTitleFillColor(0);
1347     c->SetFillStyle(4000);
1348     hn1->UseCurrentStyle();
1349 
1350     hn1->SetTitle(histotitle.c_str());
1351     hn1->GetXaxis()->SetLabelSize(0.04);
1352     hn1->GetYaxis()->SetLabelSize(0.04);
1353     hn1->GetXaxis()->SetTitleOffset(0.7);
1354     hn1->GetXaxis()->SetTitleSize(0.06);
1355     hn1->GetXaxis()->SetNdivisions(208, kTRUE);
1356     hn1->GetYaxis()->SetRangeUser(0.5, 1.1);
1357     hn1->SetMarkerStyle(6);
1358     hn1->SetMarkerColor(kBlue);
1359     hn2->SetMarkerStyle(6);
1360     hn2->SetMarkerColor(kRed);
1361     hn1->GetXaxis()->SetBinLabel(1, "ME +1/1b");
1362     hn1->GetXaxis()->SetBinLabel(2, "ME +1/2");
1363     hn1->GetXaxis()->SetBinLabel(3, "ME +1/3");
1364     hn1->GetXaxis()->SetBinLabel(4, "ME +1/1a");
1365     hn1->GetXaxis()->SetBinLabel(5, "ME +2/1");
1366     hn1->GetXaxis()->SetBinLabel(6, "ME +2/2");
1367     hn1->GetXaxis()->SetBinLabel(7, "ME +3/1");
1368     hn1->GetXaxis()->SetBinLabel(8, "ME +3/2");
1369     hn1->GetXaxis()->SetBinLabel(9, "ME +4/1");
1370     hn1->GetXaxis()->SetBinLabel(10, "ME +4/2");
1371     hn1->GetXaxis()->SetBinLabel(11, "ME -1/1b");
1372     hn1->GetXaxis()->SetBinLabel(12, "ME -1/2");
1373     hn1->GetXaxis()->SetBinLabel(13, "ME -1/3");
1374     hn1->GetXaxis()->SetBinLabel(14, "ME -1/1a");
1375     hn1->GetXaxis()->SetBinLabel(15, "ME -2/1");
1376     hn1->GetXaxis()->SetBinLabel(16, "ME -2/2");
1377     hn1->GetXaxis()->SetBinLabel(17, "ME -3/1");
1378     hn1->GetXaxis()->SetBinLabel(18, "ME -3/2");
1379     hn1->GetXaxis()->SetBinLabel(19, "ME -4/1");
1380     hn1->GetXaxis()->SetBinLabel(20, "ME -4/2");
1381 
1382     TLegend *leg = new TLegend(0.79, 0.79, 0.89, 0.89);
1383     leg->AddEntry(hn1, "new", "p");
1384     leg->AddEntry(hn2, "ref", "p");
1385 
1386     hn1->Draw();
1387     hn2->Draw("same");
1388     leg->Draw();
1389     c->Update();
1390     c->Print(savename.c_str(), "png");
1391   }
1392   delete c;
1393   delete hn1;
1394   delete hn2;
1395 }
1396 
1397 void GlobalPosfromTreeCompare(
1398     std::string graphname, TFile *f1, TFile *f2, int endcap, int station, std::string type, std::string savename) {
1399   struct posRecord {
1400     int endcap;
1401     int station;
1402     int ring;
1403     int chamber;
1404     int layer;
1405     float localx;
1406     float localy;
1407     float globalx;
1408     float globaly;
1409   } points1, points2;
1410 
1411   TTree *t1;
1412   TTree *t2;
1413   TBranch *b1;
1414   TBranch *b2;
1415 
1416   if (type == "rechit") {
1417     t1 = (TTree *)f1->Get("recHits/rHPositions");
1418     t2 = (TTree *)f2->Get("recHits/rHPositions");
1419     b1 = t1->GetBranch("rHpos");
1420     b2 = t2->GetBranch("rHpos");
1421     b1->SetAddress(&points1);
1422     b2->SetAddress(&points2);
1423   }
1424 
1425   if (type == "segment") {
1426     t1 = (TTree *)f1->Get("Segments/segPositions");
1427     t2 = (TTree *)f2->Get("Segments/segPositions");
1428     b1 = t1->GetBranch("segpos");
1429     b2 = t2->GetBranch("segpos");
1430     b1->SetAddress(&points1);
1431     b2->SetAddress(&points2);
1432   }
1433 
1434   int n1 = (int)t1->GetEntries();
1435   int n2 = (int)t2->GetEntries();
1436 
1437   const int nevents1 = n1;
1438   const int nevents2 = n2;
1439 
1440   float globx1[nevents1];
1441   float globy1[nevents1];
1442   float globx2[nevents2];
1443   float globy2[nevents2];
1444   int nstation1 = 0;
1445   int nstation2 = 0;
1446 
1447   for (int i = 0; i < nevents1; i++) {
1448     b1->GetEntry(i);
1449     if (points1.station == station && points1.endcap == endcap) {
1450       globx1[nstation1] = points1.globalx;
1451       globy1[nstation1] = points1.globaly;
1452       nstation1++;
1453     }
1454   }
1455   for (int i = 0; i < nevents2; i++) {
1456     b2->GetEntry(i);
1457     if (points2.station == station && points2.endcap == endcap) {
1458       globx2[nstation2] = points2.globalx;
1459       globy2[nstation2] = points2.globaly;
1460       nstation2++;
1461     }
1462   }
1463 
1464   std::string name1 = graphname + " (New)";
1465   std::string name2 = graphname + " (Ref)";
1466   TCanvas *c = new TCanvas("c", "my canvas", 1);
1467   c->SetCanvasSize(1300, 700);
1468   c->Divide(2, 1);
1469   TGraph *graph1 = new TGraph(nstation1, globx1, globy1);
1470   TGraph *graph2 = new TGraph(nstation2, globx2, globy2);
1471 
1472   gStyle->SetTitleW(0.6);
1473   gStyle->SetTitleH(0.1);
1474   gStyle->SetStatColor(0);
1475   gStyle->SetTitleFillColor(0);
1476   gStyle->SetOptStat(10);
1477 
1478   c->cd(1);
1479   graph1->SetTitle(name1.c_str());
1480   graph1->UseCurrentStyle();
1481   drawChamberLines(station);
1482   graph1->Draw("AP");
1483   c->cd(2);
1484   graph2->SetTitle(name2.c_str());
1485   graph2->UseCurrentStyle();
1486   drawChamberLines(station);
1487   graph2->Draw("AP");
1488 
1489   //c->Update();
1490   c->Print(savename.c_str(), "png");
1491   delete c;
1492 }
1493 
1494 void NikolaiPlots(TFile *f_in, int flag) {
1495   gROOT->SetStyle("Plain");  // to get rid of gray color of pad and have it white
1496   gStyle->SetPalette(1, 0);  //
1497 
1498   std::ostringstream ss, ss1;
1499 
1500   std::string folder;
1501   std::string input_histName, input_title_X, input_title_Y, slice_title_X;
1502   Int_t ny;
1503   Float_t ylow, yhigh;
1504   std::string result_histName, result_histTitle, result_title_Y, result_histNameEntries, result_histTitleEntries;
1505 
1506   if (flag == 1) {  // gas gain results
1507     folder = "GasGain/";
1508 
1509     input_histName = "gas_gain_rechit_adc_3_3_sum_location_ME_";
1510     input_title_X = "Location=(layer-1)*nsegm+segm";
1511     input_title_Y = "3X3 ADC Sum";
1512 
1513     slice_title_X = "3X3 ADC Sum Location";
1514 
1515     ny = 30;
1516     ylow = 1.0;
1517     yhigh = 31.0;
1518     result_histName = "mean_gas_gain_vs_location_csc_ME_";
1519     result_histTitle = "Mean 3X3 ADC Sum";
1520     result_title_Y = "Location=(layer-1)*nsegm+segm";
1521 
1522     result_histNameEntries = "entries_gas_gain_vs_location_csc_ME_";
1523     result_histTitleEntries = "Entries 3X3 ADC Sum";
1524   }
1525 
1526   if (flag == 2) {  // AFEB timing results
1527     folder = "AFEBTiming/";
1528 
1529     input_histName = "afeb_time_bin_vs_afeb_occupancy_ME_";
1530     input_title_X = "AFEB";
1531     input_title_Y = "Time Bin";
1532 
1533     slice_title_X = "AFEB";
1534 
1535     ny = 42;
1536     ylow = 1.0;
1537     yhigh = 42.0;
1538     result_histName = "mean_afeb_time_bin_vs_afeb_csc_ME_";
1539     result_histTitle = "AFEB Mean Time Bin";
1540     result_title_Y = "AFEB";
1541 
1542     result_histNameEntries = "entries_afeb_time_bin_vs_afeb_csc_ME_";
1543     result_histTitleEntries = "Entries AFEB Time Bin";
1544   }
1545 
1546   if (flag == 3) {  // Comparator timing results
1547     folder = "CompTiming/";
1548 
1549     input_histName = "comp_time_bin_vs_cfeb_occupancy_ME_";
1550     input_title_X = "CFEB";
1551     input_title_Y = "Time Bin";
1552 
1553     slice_title_X = "CFEB";
1554 
1555     ny = 5;
1556     ylow = 1.0;
1557     yhigh = 6.0;
1558     result_histName = "mean_comp_time_bin_vs_cfeb_csc_ME_";
1559     result_histTitle = "Comparator Mean Time Bin";
1560     result_title_Y = "CFEB";
1561 
1562     result_histNameEntries = "entries_comp_time_bin_vs_cfeb_csc_ME_";
1563     result_histTitleEntries = "Entries Comparator Time Bin";
1564   }
1565 
1566   if (flag == 4) {  // Strip ADC timing results
1567     folder = "ADCTiming/";
1568 
1569     input_histName = "adc_3_3_weight_time_bin_vs_cfeb_occupancy_ME_";
1570     input_title_X = "CFEB";
1571     input_title_Y = "Time Bin";
1572 
1573     slice_title_X = "CFEB";
1574 
1575     ny = 5;
1576     ylow = 1.0;
1577     yhigh = 6.0;
1578     result_histName = "mean_adc_time_bin_vs_cfeb_csc_ME_";
1579     result_histTitle = "ADC 3X3 Mean Time Bin";
1580     result_title_Y = "CFEB";
1581 
1582     result_histNameEntries = "entries_adc_time_bin_vs_cfeb_csc_ME_";
1583     result_histTitleEntries = "Entries ADC 3X3 Time Bin";
1584   }
1585 
1586   std::vector<std::string> xTitle;
1587   xTitle.push_back("ME+1/1 CSC");
1588   xTitle.push_back("ME+1/2 CSC");
1589   xTitle.push_back("ME+1/3 CSC");
1590   xTitle.push_back("ME+2/1 CSC");
1591   xTitle.push_back("ME+2/2 CSC");
1592   xTitle.push_back("ME+3/1 CSC");
1593   xTitle.push_back("ME+3/2 CSC");
1594   xTitle.push_back("ME+4/1 CSC");
1595   xTitle.push_back("ME+4/2 CSC");
1596   xTitle.push_back("ME-1/1 CSC");
1597   xTitle.push_back("ME-1/2 CSC");
1598   xTitle.push_back("ME-1/3 CSC");
1599   xTitle.push_back("ME-2/1 CSC");
1600   xTitle.push_back("ME-2/2 CSC");
1601   xTitle.push_back("ME-3/1 CSC");
1602   xTitle.push_back("ME-3/2 CSC");
1603   xTitle.push_back("ME-4/1 CSC");
1604   xTitle.push_back("ME-4/2 CSC");
1605 
1606   TH2F *h2[500];
1607   TH2F *h;
1608   Int_t esr[18] = {111, 112, 113, 121, 122, 131, 132, 141, 142, 211, 212, 213, 221, 222, 231, 232, 241, 242};
1609   Int_t entries[18] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1610   Int_t k = 0;
1611   TCanvas *c1 = new TCanvas("c1", "canvas");
1612   c1->cd();
1613 
1614   //if(flag==2) { // adding special case for AFEB timing
1615   ss.str("");
1616   ss << "mean_afeb_time_bin_vs_csc_ME";
1617   ss1.str("");
1618   ss1 << "Mean AFEB time bin vs CSC and ME";
1619   gStyle->SetOptStat(0);
1620   TH2F *hb = new TH2F(ss.str().c_str(), ss1.str().c_str(), 36, 1.0, 37.0, 18, 1.0, 19.0);
1621   hb->SetStats(kFALSE);
1622   hb->GetXaxis()->SetTitle("CSC #");
1623   hb->GetZaxis()->SetLabelSize(0.03);
1624   hb->SetOption("COLZ");
1625 
1626   hb->GetYaxis()->SetBinLabel(1, "ME- 4/2");
1627   hb->GetYaxis()->SetBinLabel(2, "ME- 4/1");
1628   hb->GetYaxis()->SetBinLabel(3, "ME- 3/2");
1629   hb->GetYaxis()->SetBinLabel(4, "ME- 3/1");
1630   hb->GetYaxis()->SetBinLabel(5, "ME- 2/2");
1631   hb->GetYaxis()->SetBinLabel(6, "ME- 2/1");
1632   hb->GetYaxis()->SetBinLabel(7, "ME- 1/3");
1633   hb->GetYaxis()->SetBinLabel(8, "ME- 1/2");
1634   hb->GetYaxis()->SetBinLabel(9, "ME- 1/1");
1635   hb->GetYaxis()->SetBinLabel(10, "ME+ 1/1");
1636   hb->GetYaxis()->SetBinLabel(11, "ME+ 1/2");
1637   hb->GetYaxis()->SetBinLabel(12, "ME+ 1/3");
1638   hb->GetYaxis()->SetBinLabel(13, "ME+ 2/1");
1639   hb->GetYaxis()->SetBinLabel(14, "ME+ 2/2");
1640   hb->GetYaxis()->SetBinLabel(15, "ME+ 3/1");
1641   hb->GetYaxis()->SetBinLabel(16, "ME+ 3/2");
1642   hb->GetYaxis()->SetBinLabel(17, "ME+ 4/1");
1643   hb->GetYaxis()->SetBinLabel(18, "ME+ 4/2");
1644   //}
1645 
1646   for (Int_t jesr = 0; jesr < 18; jesr++) {
1647     ss.str("");
1648     ss << result_histName.c_str() << esr[jesr];
1649     ss1.str("");
1650     ss1 << result_histTitle;
1651     TH2F *h = new TH2F(ss.str().c_str(), ss1.str().c_str(), 40, 0.0, 40.0, ny, ylow, yhigh);
1652     h->SetStats(kFALSE);
1653     h->GetXaxis()->SetTitle(xTitle[jesr].c_str());
1654     h->GetYaxis()->SetTitle(result_title_Y.c_str());
1655     h->GetZaxis()->SetLabelSize(0.03);
1656     h->SetOption("COLZ");
1657 
1658     ss.str("");
1659     ss << result_histNameEntries.c_str() << esr[jesr];
1660     ss1.str("");
1661     ss1 << result_histTitleEntries;
1662     TH2F *hentr = new TH2F(ss.str().c_str(), ss1.str().c_str(), 40, 0.0, 40.0, ny, ylow, yhigh);
1663     hentr->SetStats(kFALSE);
1664     hentr->GetXaxis()->SetTitle(xTitle[jesr].c_str());
1665     hentr->GetYaxis()->SetTitle(result_title_Y.c_str());
1666     hentr->GetZaxis()->SetLabelSize(0.03);
1667     hentr->SetOption("COLZ");
1668 
1669     //TH2F* ha;
1670 
1671     if (flag == 2) {  // adding special cases for AFEB timing
1672       ss.str("");
1673       ss << "normal_afeb_time_bin_vs_csc_ME_" << esr[jesr];
1674       ss1.str("");
1675       ss1 << "Normalized AFEB time bin, %";
1676       //TH2F *ha=new TH2F(ss.str().c_str(),ss1.str().c_str(),40,0.0,40.0,16,0.0,16.0);
1677       //ha->SetStats(kFALSE);
1678       //ha->GetXaxis()->SetTitle(xTitle[jesr].c_str());
1679       //ha->GetYaxis()->SetTitle("Time Bin");
1680       //ha->GetZaxis()->SetLabelSize(0.03);
1681       //ha->SetOption("COLZ");
1682     }
1683 
1684     for (Int_t csc = 1; csc < 37; csc++) {
1685       Int_t idchamber = esr[jesr] * 100 + csc;
1686       ss.str("");
1687       ss << folder.c_str() << input_histName.c_str() << idchamber;
1688       f_in->cd();
1689       TH2F *h2[1];
1690       h2[k] = (TH2F *)f_in->Get(ss.str().c_str());
1691       if (h2[k] != NULL) {
1692         // saving original, adding X,Y titles, color and "BOX" option
1693         h2[k]->GetXaxis()->SetTitle(input_title_X.c_str());
1694         h2[k]->GetYaxis()->SetTitle(input_title_Y.c_str());
1695         h2[k]->GetYaxis()->SetTitleOffset(1.2);
1696         h2[k]->SetFillColor(4);
1697         h2[k]->SetOption("BOX");
1698         gStyle->SetOptStat(1001111);
1699 
1700         // saving Y projection of the whole 2D hist for given chamber
1701         ss.str("");
1702         ss << input_histName.c_str() << idchamber << "_Y_all";
1703         TH1D *h1d = h2[k]->ProjectionY(ss.str().c_str(), 1, h2[k]->GetNbinsX(), "");
1704         h1d->GetYaxis()->SetTitle("Entries");
1705         h1d->GetYaxis()->SetTitleOffset(1.2);
1706         gStyle->SetOptStat(1001111);
1707 
1708         if (flag == 2 && h1d->GetEntries() > 0) {  // adding spec. case for afeb timing
1709           Float_t entr = h1d->GetEntries();
1710           for (Int_t m = 1; m < h1d->GetNbinsX(); m++) {
1711             Float_t w = h1d->GetBinContent(m);
1712             w = 100.0 * w / entr;
1713             //ha->SetBinContent(csc+1,m,w);
1714           }
1715           Float_t mean = h1d->GetMean();
1716           Int_t me;
1717           if (jesr < 9)
1718             me = 10 + jesr;
1719           if (jesr > 8)
1720             me = 18 - jesr;
1721           hb->SetBinContent(csc, me, mean);
1722         }
1723         delete h1d;
1724 
1725         // saving slices, finding MEAN in each slice, fill 2D hist
1726         for (Int_t j = 1; j <= h2[k]->GetNbinsX(); j++) {
1727           Int_t n = j;
1728           ss.str("");
1729           ss << input_histName.c_str() << idchamber << "_Y_" << n;
1730           TH1D *h1d = h2[k]->ProjectionY(ss.str().c_str(), j, j, "");
1731           if (h1d->GetEntries() > 0) {
1732             Float_t mean = h1d->GetMean();
1733             Float_t entr = h1d->GetEntries();
1734             entries[jesr] = entries[jesr] + 1;
1735             h->SetBinContent(csc + 1, j, mean);
1736             hentr->SetBinContent(csc + 1, j, entr);
1737             ss.str("");
1738             ss << slice_title_X << " " << n;
1739             h1d->GetXaxis()->SetTitle(ss.str().c_str());
1740             h1d->GetYaxis()->SetTitle("Entries");
1741             h1d->GetYaxis()->SetTitleOffset(1.2);
1742             gStyle->SetOptStat(1001111);
1743           }
1744           delete h1d;
1745         }
1746       }
1747     }
1748     if (entries[jesr] > 0) {
1749       h->SetStats(kFALSE);
1750       hentr->SetStats(kFALSE);
1751       c1->Update();
1752 
1753       // printing
1754 
1755       h->Draw();
1756       ss.str("");
1757       ss << result_histName.c_str() << esr[jesr] << ".png";
1758       c1->Print(ss.str().c_str(), "png");
1759 
1760       hentr->Draw();
1761       ss.str("");
1762       ss << result_histNameEntries.c_str() << esr[jesr] << ".png";
1763       c1->Print(ss.str().c_str(), "png");
1764     }
1765     delete h;
1766     delete hentr;
1767     //if(flag==2) delete ha;
1768   }
1769   if (flag == 2) {
1770     hb->Draw();
1771     ss.str("");
1772     ss << "mean_afeb_time_bin_vs_csc_ME"
1773        << ".png";
1774     c1->Print(ss.str().c_str(), "png");
1775 
1776     c1->Update();
1777     //delete hb;
1778   }
1779   delete hb;
1780   delete c1;
1781 }
1782 
1783 void drawColoredChamberLines(int station, int nchamber1[4][36]) {
1784   // thanks to Luca Sabbatini for this coe
1785   const int maxRingIdxOfRelevance = 2;
1786   const int maxChamberIdxOfRelevance = 35;
1787   const int totalNumberOfChambersOfRelevance = 540;
1788 
1789   Int_t thisRingIdx = 0;
1790   Int_t numChambersInRing = 0;
1791 
1792   float nchamber1Avg = 0.;
1793   float thisRingNchamber1Avg = 0;
1794   float thisRingNchamber1Max = 0;
1795   // Note that thisRingNchamber1Min is only the minumum *non-zero*
1796   // occupancy among all the cmabers for the given ring
1797   float thisRingNchamber1Min = 0;
1798   Int_t thisRingNchamber1Base = 0;
1799 
1800   // rFloatRGB, gFloatRGB, bFloatRGB, are from the RGB color space;
1801   // all three range between [0,1]
1802   // hFloatHLS, lFloatHLS, sFloatHLS, are from the HLS color space;
1803   // lFloatHLS and sFloatHLS range between [0,1], while hFloatHLS
1804   // ranges between [0,360]
1805   Float_t rFloatRGB = 0.;
1806   Float_t gFloatRGB = 0.;
1807   Float_t bFloatRGB = 0.;
1808   Float_t hFloatHLS = 0.;
1809   Float_t lFloatHLS = 0.5;
1810   Float_t sFloatHLS = 1.0;
1811   TColor tempColor;
1812 
1813   // compute average chamber occupancy over all CSCs
1814   for (int i = 0; i < maxRingIdxOfRelevance + 1; i++) {
1815     for (int j = 0; j < maxChamberIdxOfRelevance + 1; j++) {
1816       nchamber1Avg += nchamber1[i][j];
1817     }
1818   }
1819   nchamber1Avg = nchamber1Avg / totalNumberOfChambersOfRelevance;
1820 
1821   Float_t myFavoriteLineWidth = 2.0;
1822   gStyle->SetLineWidth(myFavoriteLineWidth);
1823   float pi = 3.14159;
1824   TVector3 x(0, 0, 1);
1825   int linecolor = 1;
1826 
1827   // emptyLineColor is the color of the outline of empty chambers.
1828   // if emptyLineColor is negative, no outline is drawn at all for
1829   // that chamber.
1830   Int_t emptyLineColor = kYellow;
1831 
1832   // note that these can be greater than 360 because I have included
1833   // a line down below that performs a modulus operation: %360, which
1834   // ensures that the resulting hue will indeed be with [0,360]
1835   //
1836   // Hue:    0   30      60      120     180     240 270 300     360
1837   //         |   |       |       |       |       |   |   |       |
1838   // Color: Red Orange Yellow   Green   Cyan  Blue Vilet Magenta Red
1839   Float_t lineHueMin = 240;
1840   Float_t lineHueMax = 360;
1841 
1842   TLine *line1;
1843   TLine *line2;
1844   TLine *line3;
1845   TLine *line4;
1846 
1847   if (station == 1) {
1848     // station 1, ring 1 (inner-most ring)
1849     thisRingIdx = 0;
1850     numChambersInRing = 36;
1851     TVector3 p1(101, 9.361, 0);
1852     TVector3 p2(101, -9.361, 0);
1853     TVector3 p3(260, -22.353, 0);
1854     TVector3 p4(260, 22.353, 0);
1855 
1856     // compute thisRingNchamber1Min, thisRingNchamber1Max,
1857     //  thisRingNchamber1Avg and thisRingNchamber1Base
1858     thisRingNchamber1Avg = 0.;
1859     thisRingNchamber1Max = 0.;
1860     for (int j = 0; j < numChambersInRing; j++) {
1861       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
1862       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
1863         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
1864       }
1865     }
1866     thisRingNchamber1Min = thisRingNchamber1Max;
1867     for (int j = 0; j < numChambersInRing; j++) {
1868       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
1869           nchamber1[thisRingIdx][j] != 0) {
1870         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
1871       }
1872     }
1873     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
1874     thisRingNchamber1Base = thisRingNchamber1Min;
1875 
1876     for (int i = 0; i < numChambersInRing; i++) {
1877       // set the line color
1878       if (nchamber1[thisRingIdx][i] != 0) {
1879         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
1880           hFloatHLS =
1881               int((nchamber1[0][i] - thisRingNchamber1Base) / (thisRingNchamber1Max - thisRingNchamber1Base) *  //
1882                       (lineHueMax - lineHueMin) +
1883                   lineHueMin) %
1884               360;
1885         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
1886         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
1887       } else if (emptyLineColor >= 0) {
1888         linecolor = emptyLineColor;
1889       }
1890 
1891       // draw the chamber outline using the line color (so long
1892       // as the the chamber isn't empty *and* the user did not
1893       // set a negative line color for empty chambers)
1894       if ((nchamber1[thisRingIdx][i] != 0) ||  //
1895           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
1896         line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
1897         line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
1898         line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
1899         line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
1900         line1->SetLineColor(linecolor);
1901         line2->SetLineColor(linecolor);
1902         line3->SetLineColor(linecolor);
1903         line4->SetLineColor(linecolor);
1904 
1905         line1->Draw();
1906         line2->Draw();
1907         line3->Draw();
1908         line4->Draw();
1909       }
1910 
1911       // Rotate coordinate by 1 chamber
1912       p1.Rotate(2 * pi / numChambersInRing, x);
1913       p2.Rotate(2 * pi / numChambersInRing, x);
1914       p3.Rotate(2 * pi / numChambersInRing, x);
1915       p4.Rotate(2 * pi / numChambersInRing, x);
1916     }
1917 
1918     // station 1, ring 2 (middle-ring)
1919     thisRingIdx = 1;
1920     numChambersInRing = 36;
1921     TVector3 q1(281.49, 25.5, 0);
1922     TVector3 q2(281.49, -25.5, 0);
1923     TVector3 q3(455.99, -41.87, 0);
1924     TVector3 q4(455.99, 41.87, 0);
1925 
1926     thisRingNchamber1Avg = 0.;
1927     thisRingNchamber1Max = 0.;
1928     for (int j = 0; j < numChambersInRing; j++) {
1929       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
1930       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
1931         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
1932       }
1933     }
1934     thisRingNchamber1Min = thisRingNchamber1Max;
1935     for (int j = 0; j < numChambersInRing; j++) {
1936       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
1937           nchamber1[thisRingIdx][j] != 0) {
1938         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
1939       }
1940     }
1941     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
1942     thisRingNchamber1Base = thisRingNchamber1Min;
1943 
1944     for (int i = 0; i < numChambersInRing; i++) {
1945       if (nchamber1[thisRingIdx][i] != 0) {
1946         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
1947           hFloatHLS = int((nchamber1[thisRingIdx][i] - thisRingNchamber1Base) /
1948                               (thisRingNchamber1Max - thisRingNchamber1Base) *  //
1949                               (lineHueMax - lineHueMin) +
1950                           lineHueMin) %
1951                       360;
1952         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
1953         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
1954       } else if (emptyLineColor >= 0) {
1955         linecolor = emptyLineColor;
1956       }
1957 
1958       if ((nchamber1[thisRingIdx][i] != 0) ||  //
1959           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
1960         line1 = new TLine(q1(0), q1(1), q2(0), q2(1));
1961         line2 = new TLine(q2(0), q2(1), q3(0), q3(1));
1962         line3 = new TLine(q3(0), q3(1), q4(0), q4(1));
1963         line4 = new TLine(q4(0), q4(1), q1(0), q1(1));
1964         line1->SetLineColor(linecolor);
1965         line2->SetLineColor(linecolor);
1966         line3->SetLineColor(linecolor);
1967         line4->SetLineColor(linecolor);
1968 
1969         line1->Draw();
1970         line2->Draw();
1971         line3->Draw();
1972         line4->Draw();
1973 
1974         int chamberNum = i + 1;
1975         char chStr[3];
1976         sprintf(chStr, "%d", chamberNum);
1977         TLatex l;
1978         l.SetTextAlign(22);
1979         l.SetTextSize(0.02);
1980         float r = sqrt(q3(0) * q3(0) + q3(1) * q3(1));
1981         float theta = atan2(q3(1), q3(0));
1982         r = r + 25;
1983         theta = pi / numChambersInRing + theta;
1984         float xpos = r * cos(theta);
1985         float ypos = r * sin(theta);
1986         l.DrawLatex(xpos, ypos, chStr);
1987       }
1988       q1.Rotate(2 * pi / numChambersInRing, x);
1989       q2.Rotate(2 * pi / numChambersInRing, x);
1990       q3.Rotate(2 * pi / numChambersInRing, x);
1991       q4.Rotate(2 * pi / numChambersInRing, x);
1992     }
1993 
1994     // station 1, ring 3 (outer-most ring)
1995     thisRingIdx = 2;
1996     numChambersInRing = 36;
1997     TVector3 r1(511.99, 31.7, 0);
1998     TVector3 r2(511.99, -31.7, 0);
1999     TVector3 r3(676.15, -46.05, 0);
2000     TVector3 r4(676.15, 46.05, 0);
2001 
2002     thisRingNchamber1Avg = 0.;
2003     thisRingNchamber1Max = 0.;
2004     for (int j = 0; j < numChambersInRing; j++) {
2005       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
2006       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
2007         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
2008       }
2009     }
2010     thisRingNchamber1Min = thisRingNchamber1Max;
2011     for (int j = 0; j < numChambersInRing; j++) {
2012       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
2013           nchamber1[thisRingIdx][j] != 0) {
2014         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
2015       }
2016     }
2017     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
2018     thisRingNchamber1Base = thisRingNchamber1Min;
2019 
2020     for (int i = 0; i < numChambersInRing; i++) {
2021       if (nchamber1[thisRingIdx][i] != 0) {
2022         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
2023           hFloatHLS = int((nchamber1[thisRingIdx][i] - thisRingNchamber1Base) /
2024                               (thisRingNchamber1Max - thisRingNchamber1Base) *  //
2025                               (lineHueMax - lineHueMin) +
2026                           lineHueMin) %
2027                       360;
2028         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
2029         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
2030       } else if (emptyLineColor >= 0) {
2031         linecolor = emptyLineColor;
2032       }
2033 
2034       if ((nchamber1[thisRingIdx][i] != 0) ||  //
2035           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
2036         line1 = new TLine(r1(0), r1(1), r2(0), r2(1));
2037         line2 = new TLine(r2(0), r2(1), r3(0), r3(1));
2038         line3 = new TLine(r3(0), r3(1), r4(0), r4(1));
2039         line4 = new TLine(r4(0), r4(1), r1(0), r1(1));
2040         line1->SetLineColor(linecolor);
2041         line2->SetLineColor(linecolor);
2042         line3->SetLineColor(linecolor);
2043         line4->SetLineColor(linecolor);
2044 
2045         line1->Draw();
2046         line2->Draw();
2047         line3->Draw();
2048         line4->Draw();
2049         int chamberNum = i + 1;
2050         char chStr[3];
2051         sprintf(chStr, "%d", chamberNum);
2052         TLatex l;
2053         l.SetTextAlign(22);
2054         l.SetTextSize(0.02);
2055         float r = sqrt(r3(0) * r3(0) + r3(1) * r3(1));
2056         float theta = atan2(r3(1), r3(0));
2057         r = r + 25;
2058         theta = pi / numChambersInRing + theta;
2059         float xpos = r * cos(theta);
2060         float ypos = r * sin(theta);
2061         l.DrawLatex(xpos, ypos, chStr);
2062       }
2063       r1.Rotate(2 * pi / numChambersInRing, x);
2064       r2.Rotate(2 * pi / numChambersInRing, x);
2065       r3.Rotate(2 * pi / numChambersInRing, x);
2066       r4.Rotate(2 * pi / numChambersInRing, x);
2067     }
2068   }
2069 
2070   if (station == 2) {
2071     // station 2, ring 1 (inner ring)
2072     thisRingIdx = 0;
2073     numChambersInRing = 18;
2074     TVector3 p1(146.9, 27.0, 0);
2075     TVector3 p2(146.9, -27.0, 0);
2076     TVector3 p3(336.56, -62.855, 0);
2077     TVector3 p4(336.56, 62.855, 0);
2078 
2079     // must "pre-rotate" by one-fourth of a chamber
2080     p1.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2081     p2.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2082     p3.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2083     p4.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2084 
2085     thisRingNchamber1Avg = 0.;
2086     thisRingNchamber1Max = 0.;
2087     for (int j = 0; j < numChambersInRing; j++) {
2088       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
2089       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
2090         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
2091       }
2092     }
2093     thisRingNchamber1Min = thisRingNchamber1Max;
2094     for (int j = 0; j < numChambersInRing; j++) {
2095       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
2096           nchamber1[thisRingIdx][j] != 0) {
2097         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
2098       }
2099     }
2100     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
2101     thisRingNchamber1Base = thisRingNchamber1Min;
2102 
2103     for (int i = 0; i < numChambersInRing; i++) {
2104       if (nchamber1[thisRingIdx][i] != 0) {
2105         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
2106           hFloatHLS =
2107               int((nchamber1[0][i] - thisRingNchamber1Base) / (thisRingNchamber1Max - thisRingNchamber1Base) *  //
2108                       (lineHueMax - lineHueMin) +
2109                   lineHueMin) %
2110               360;
2111         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
2112         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
2113       } else if (emptyLineColor >= 0) {
2114         linecolor = emptyLineColor;
2115       }
2116 
2117       if ((nchamber1[thisRingIdx][i] != 0) ||  //
2118           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
2119         line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
2120         line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
2121         line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
2122         line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
2123         line1->SetLineColor(linecolor);
2124         line2->SetLineColor(linecolor);
2125         line3->SetLineColor(linecolor);
2126         line4->SetLineColor(linecolor);
2127 
2128         line1->Draw();
2129         line2->Draw();
2130         line3->Draw();
2131         line4->Draw();
2132         int chamberNum = i + 1;
2133         char chStr[3];
2134         sprintf(chStr, "%d", chamberNum);
2135         TLatex l;
2136         l.SetTextAlign(22);
2137         l.SetTextSize(0.02);
2138         float r = sqrt(p3(0) * p3(0) + p3(1) * p3(1));
2139         float theta = atan2(p3(1), p3(0));
2140         r = r + 10;
2141         theta = pi / numChambersInRing + theta;
2142         float xpos = r * cos(theta);
2143         float ypos = r * sin(theta);
2144         l.DrawLatex(xpos, ypos, chStr);
2145       }
2146       p1.Rotate(2 * pi / numChambersInRing, x);
2147       p2.Rotate(2 * pi / numChambersInRing, x);
2148       p3.Rotate(2 * pi / numChambersInRing, x);
2149       p4.Rotate(2 * pi / numChambersInRing, x);
2150     }
2151 
2152     // station 2, ring 2 (outer ring)
2153     thisRingIdx = 1;
2154     numChambersInRing = 36;
2155     TVector3 q1(364.02, 33.23, 0);
2156     TVector3 q2(364.02, -33.23, 0);
2157     TVector3 q3(687.08, -63.575, 0);
2158     TVector3 q4(687.08, 63.575, 0);
2159 
2160     thisRingNchamber1Avg = 0.;
2161     thisRingNchamber1Max = 0.;
2162     for (int j = 0; j < numChambersInRing; j++) {
2163       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
2164       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
2165         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
2166       }
2167     }
2168     thisRingNchamber1Min = thisRingNchamber1Max;
2169     for (int j = 0; j < numChambersInRing; j++) {
2170       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
2171           nchamber1[thisRingIdx][j] != 0) {
2172         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
2173       }
2174     }
2175     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
2176     thisRingNchamber1Base = thisRingNchamber1Min;
2177 
2178     for (int i = 0; i < numChambersInRing; i++) {
2179       if (nchamber1[thisRingIdx][i] != 0) {
2180         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
2181           hFloatHLS = int((nchamber1[thisRingIdx][i] - thisRingNchamber1Base) /
2182                               (thisRingNchamber1Max - thisRingNchamber1Base) *  //
2183                               (lineHueMax - lineHueMin) +
2184                           lineHueMin) %
2185                       360;
2186         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
2187         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
2188       } else if (emptyLineColor >= 0) {
2189         linecolor = emptyLineColor;
2190       }
2191 
2192       if ((nchamber1[thisRingIdx][i] != 0) ||  //
2193           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
2194         line1 = new TLine(q1(0), q1(1), q2(0), q2(1));
2195         line2 = new TLine(q2(0), q2(1), q3(0), q3(1));
2196         line3 = new TLine(q3(0), q3(1), q4(0), q4(1));
2197         line4 = new TLine(q4(0), q4(1), q1(0), q1(1));
2198         line1->SetLineColor(linecolor);
2199         line2->SetLineColor(linecolor);
2200         line3->SetLineColor(linecolor);
2201         line4->SetLineColor(linecolor);
2202 
2203         line1->Draw();
2204         line2->Draw();
2205         line3->Draw();
2206         line4->Draw();
2207         int chamberNum = i + 1;
2208         char chStr[3];
2209         sprintf(chStr, "%d", chamberNum);
2210         TLatex l;
2211         l.SetTextAlign(22);
2212         l.SetTextSize(0.02);
2213         float r = sqrt(q3(0) * q3(0) + q3(1) * q3(1));
2214         float theta = atan2(q3(1), q3(0));
2215         r = r + 25;
2216         theta = pi / numChambersInRing + theta;
2217         float xpos = r * cos(theta);
2218         float ypos = r * sin(theta);
2219         l.DrawLatex(xpos, ypos, chStr);
2220       }
2221       q1.Rotate(2 * pi / numChambersInRing, x);
2222       q2.Rotate(2 * pi / numChambersInRing, x);
2223       q3.Rotate(2 * pi / numChambersInRing, x);
2224       q4.Rotate(2 * pi / numChambersInRing, x);
2225     }
2226   }
2227 
2228   if (station == 3) {
2229     // station 3, ring 1 (inner ring)
2230     thisRingIdx = 0;
2231     numChambersInRing = 18;
2232     TVector3 p1(166.89, 30.7, 0);
2233     TVector3 p2(166.89, -30.7, 0);
2234     TVector3 p3(336.59, -62.855, 0);
2235     TVector3 p4(336.59, 62.855, 0);
2236 
2237     // must "pre-rotate" by one-fourth of a chamber
2238     p1.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2239     p2.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2240     p3.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2241     p4.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2242 
2243     TLine *line1;
2244     TLine *line2;
2245     TLine *line3;
2246     TLine *line4;
2247 
2248     thisRingNchamber1Avg = 0.;
2249     thisRingNchamber1Max = 0.;
2250     for (int j = 0; j < numChambersInRing; j++) {
2251       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
2252       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
2253         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
2254       }
2255     }
2256     thisRingNchamber1Min = thisRingNchamber1Max;
2257     for (int j = 0; j < numChambersInRing; j++) {
2258       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
2259           nchamber1[thisRingIdx][j] != 0) {
2260         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
2261       }
2262     }
2263     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
2264     thisRingNchamber1Base = thisRingNchamber1Min;
2265 
2266     for (int i = 0; i < numChambersInRing; i++) {
2267       if (nchamber1[thisRingIdx][i] != 0) {
2268         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
2269           hFloatHLS =
2270               int((nchamber1[0][i] - thisRingNchamber1Base) / (thisRingNchamber1Max - thisRingNchamber1Base) *  //
2271                       (lineHueMax - lineHueMin) +
2272                   lineHueMin) %
2273               360;
2274         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
2275         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
2276       } else if (emptyLineColor >= 0) {
2277         linecolor = emptyLineColor;
2278       }
2279 
2280       if ((nchamber1[thisRingIdx][i] != 0) ||  //
2281           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
2282         line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
2283         line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
2284         line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
2285         line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
2286         line1->SetLineColor(linecolor);
2287         line2->SetLineColor(linecolor);
2288         line3->SetLineColor(linecolor);
2289         line4->SetLineColor(linecolor);
2290 
2291         line1->Draw();
2292         line2->Draw();
2293         line3->Draw();
2294         line4->Draw();
2295         int chamberNum = i + 1;
2296         char chStr[3];
2297         sprintf(chStr, "%d", chamberNum);
2298         TLatex l;
2299         l.SetTextAlign(22);
2300         l.SetTextSize(0.02);
2301         float r = sqrt(p3(0) * p3(0) + p3(1) * p3(1));
2302         float theta = atan2(p3(1), p3(0));
2303         r = r + 10;
2304         theta = pi / numChambersInRing + theta;
2305         float xpos = r * cos(theta);
2306         float ypos = r * sin(theta);
2307         l.DrawLatex(xpos, ypos, chStr);
2308       }
2309       p1.Rotate(2 * pi / numChambersInRing, x);
2310       p2.Rotate(2 * pi / numChambersInRing, x);
2311       p3.Rotate(2 * pi / numChambersInRing, x);
2312       p4.Rotate(2 * pi / numChambersInRing, x);
2313     }
2314 
2315     // station 3, ring 2 (outer ring)
2316     thisRingIdx = 1;
2317     numChambersInRing = 36;
2318     TVector3 q1(364.02, 33.23, 0);
2319     TVector3 q2(364.02, -33.23, 0);
2320     TVector3 q3(687.08, -63.575, 0);
2321     TVector3 q4(687.08, 63.575, 0);
2322 
2323     thisRingNchamber1Avg = 0.;
2324     thisRingNchamber1Max = 0.;
2325     for (int j = 0; j < numChambersInRing; j++) {
2326       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
2327       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
2328         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
2329       }
2330     }
2331     thisRingNchamber1Min = thisRingNchamber1Max;
2332     for (int j = 0; j < numChambersInRing; j++) {
2333       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
2334           nchamber1[thisRingIdx][j] != 0) {
2335         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
2336       }
2337     }
2338     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
2339     thisRingNchamber1Base = thisRingNchamber1Min;
2340 
2341     for (int i = 0; i < numChambersInRing; i++) {
2342       if (nchamber1[thisRingIdx][i] != 0) {
2343         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
2344           hFloatHLS = int((nchamber1[thisRingIdx][i] - thisRingNchamber1Base) /
2345                               (thisRingNchamber1Max - thisRingNchamber1Base) *  //
2346                               (lineHueMax - lineHueMin) +
2347                           lineHueMin) %
2348                       360;
2349         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
2350         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
2351       } else if (emptyLineColor >= 0) {
2352         linecolor = emptyLineColor;
2353       }
2354 
2355       if ((nchamber1[thisRingIdx][i] != 0) ||  //
2356           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
2357         line1 = new TLine(q1(0), q1(1), q2(0), q2(1));
2358         line2 = new TLine(q2(0), q2(1), q3(0), q3(1));
2359         line3 = new TLine(q3(0), q3(1), q4(0), q4(1));
2360         line4 = new TLine(q4(0), q4(1), q1(0), q1(1));
2361         line1->SetLineColor(linecolor);
2362         line2->SetLineColor(linecolor);
2363         line3->SetLineColor(linecolor);
2364         line4->SetLineColor(linecolor);
2365 
2366         line1->Draw();
2367         line2->Draw();
2368         line3->Draw();
2369         line4->Draw();
2370         int chamberNum = i + 1;
2371         char chStr[3];
2372         sprintf(chStr, "%d", chamberNum);
2373         TLatex l;
2374         l.SetTextAlign(22);
2375         l.SetTextSize(0.02);
2376         float r = sqrt(q3(0) * q3(0) + q3(1) * q3(1));
2377         float theta = atan2(q3(1), q3(0));
2378         r = r + 25;
2379         theta = pi / numChambersInRing + theta;
2380         float xpos = r * cos(theta);
2381         float ypos = r * sin(theta);
2382         l.DrawLatex(xpos, ypos, chStr);
2383       }
2384       q1.Rotate(2 * pi / numChambersInRing, x);
2385       q2.Rotate(2 * pi / numChambersInRing, x);
2386       q3.Rotate(2 * pi / numChambersInRing, x);
2387       q4.Rotate(2 * pi / numChambersInRing, x);
2388     }
2389   }
2390 
2391   if (station == 4) {
2392     // station 4, ring 1 (the only ring on station 4... so far)
2393     thisRingIdx = 0;
2394     numChambersInRing = 18;
2395     TVector3 p1(186.99, 34.505, 0);
2396     TVector3 p2(186.99, -34.505, 0);
2397     TVector3 p3(336.41, -62.825, 0);
2398     TVector3 p4(336.41, 62.825, 0);
2399 
2400     // must "pre-rotate" by one-fourth of a chamber
2401     p1.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2402     p2.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2403     p3.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2404     p4.Rotate((1 / 4.) * 2 * pi / numChambersInRing, x);
2405 
2406     TLine *line1;
2407     TLine *line2;
2408     TLine *line3;
2409     TLine *line4;
2410 
2411     thisRingNchamber1Avg = 0.;
2412     thisRingNchamber1Max = 0.;
2413     for (int j = 0; j < numChambersInRing; j++) {
2414       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
2415       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
2416         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
2417       }
2418     }
2419     thisRingNchamber1Min = thisRingNchamber1Max;
2420     for (int j = 0; j < numChambersInRing; j++) {
2421       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
2422           nchamber1[thisRingIdx][j] != 0) {
2423         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
2424       }
2425     }
2426     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
2427     thisRingNchamber1Base = thisRingNchamber1Min;
2428 
2429     for (int i = 0; i < numChambersInRing; i++) {
2430       if (nchamber1[thisRingIdx][i] != 0) {
2431         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
2432           hFloatHLS =
2433               int((nchamber1[0][i] - thisRingNchamber1Base) / (thisRingNchamber1Max - thisRingNchamber1Base) *  //
2434                       (lineHueMax - lineHueMin) +
2435                   lineHueMin) %
2436               360;
2437         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
2438         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
2439       } else if (emptyLineColor >= 0) {
2440         linecolor = emptyLineColor;
2441       }
2442 
2443       if ((nchamber1[thisRingIdx][i] != 0) ||  //
2444           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
2445         line1 = new TLine(p1(0), p1(1), p2(0), p2(1));
2446         line2 = new TLine(p2(0), p2(1), p3(0), p3(1));
2447         line3 = new TLine(p3(0), p3(1), p4(0), p4(1));
2448         line4 = new TLine(p4(0), p4(1), p1(0), p1(1));
2449         line1->SetLineColor(linecolor);
2450         line2->SetLineColor(linecolor);
2451         line3->SetLineColor(linecolor);
2452         line4->SetLineColor(linecolor);
2453 
2454         line1->Draw();
2455         line2->Draw();
2456         line3->Draw();
2457         line4->Draw();
2458         int chamberNum = i + 1;
2459         char chStr[3];
2460         sprintf(chStr, "%d", chamberNum);
2461         TLatex l;
2462         l.SetTextAlign(22);
2463         l.SetTextSize(0.02);
2464         float r = sqrt(p3(0) * p3(0) + p3(1) * p3(1));
2465         float theta = atan2(p3(1), p3(0));
2466         r = r + 10;
2467         theta = pi / numChambersInRing + theta;
2468         float xpos = r * cos(theta);
2469         float ypos = r * sin(theta);
2470         l.DrawLatex(xpos, ypos, chStr);
2471       }
2472       p1.Rotate(2 * pi / numChambersInRing, x);
2473       p2.Rotate(2 * pi / numChambersInRing, x);
2474       p3.Rotate(2 * pi / numChambersInRing, x);
2475       p4.Rotate(2 * pi / numChambersInRing, x);
2476     }
2477 
2478     // station 4, ring 2 (outer ring) (This is just a copy of the ME3/2 code)
2479     thisRingIdx = 1;
2480     numChambersInRing = 36;
2481     TVector3 q1(364.02, 33.23, 0);
2482     TVector3 q2(364.02, -33.23, 0);
2483     TVector3 q3(687.08, -63.575, 0);
2484     TVector3 q4(687.08, 63.575, 0);
2485 
2486     thisRingNchamber1Avg = 0.;
2487     thisRingNchamber1Max = 0.;
2488     for (int j = 0; j < numChambersInRing; j++) {
2489       thisRingNchamber1Avg += nchamber1[thisRingIdx][j];
2490       if (thisRingNchamber1Max < nchamber1[thisRingIdx][j]) {
2491         thisRingNchamber1Max = nchamber1[thisRingIdx][j];
2492       }
2493     }
2494     thisRingNchamber1Min = thisRingNchamber1Max;
2495     for (int j = 0; j < numChambersInRing; j++) {
2496       if (thisRingNchamber1Min > nchamber1[thisRingIdx][j] &&  //
2497           nchamber1[thisRingIdx][j] != 0) {
2498         thisRingNchamber1Min = nchamber1[thisRingIdx][j];
2499       }
2500     }
2501     thisRingNchamber1Avg = thisRingNchamber1Avg / numChambersInRing;
2502     thisRingNchamber1Base = thisRingNchamber1Min;
2503 
2504     for (int i = 0; i < numChambersInRing; i++) {
2505       if (nchamber1[thisRingIdx][i] != 0) {
2506         if ((thisRingNchamber1Max - thisRingNchamber1Base) != 0)
2507           hFloatHLS = int((nchamber1[thisRingIdx][i] - thisRingNchamber1Base) /
2508                               (thisRingNchamber1Max - thisRingNchamber1Base) *  //
2509                               (lineHueMax - lineHueMin) +
2510                           lineHueMin) %
2511                       360;
2512         tempColor.HLS2RGB(hFloatHLS, lFloatHLS, sFloatHLS, rFloatRGB, gFloatRGB, bFloatRGB);
2513         linecolor = tempColor.GetColor(rFloatRGB, gFloatRGB, bFloatRGB);
2514       } else if (emptyLineColor >= 0) {
2515         linecolor = emptyLineColor;
2516       }
2517 
2518       if ((nchamber1[thisRingIdx][i] != 0) ||  //
2519           (nchamber1[thisRingIdx][i] == 0 && emptyLineColor >= 0)) {
2520         line1 = new TLine(q1(0), q1(1), q2(0), q2(1));
2521         line2 = new TLine(q2(0), q2(1), q3(0), q3(1));
2522         line3 = new TLine(q3(0), q3(1), q4(0), q4(1));
2523         line4 = new TLine(q4(0), q4(1), q1(0), q1(1));
2524         line1->SetLineColor(linecolor);
2525         line2->SetLineColor(linecolor);
2526         line3->SetLineColor(linecolor);
2527         line4->SetLineColor(linecolor);
2528 
2529         line1->Draw();
2530         line2->Draw();
2531         line3->Draw();
2532         line4->Draw();
2533         int chamberNum = i + 1;
2534         char chStr[3];
2535         sprintf(chStr, "%d", chamberNum);
2536         TLatex l;
2537         l.SetTextAlign(22);
2538         l.SetTextSize(0.02);
2539         float r = sqrt(q3(0) * q3(0) + q3(1) * q3(1));
2540         float theta = atan2(q3(1), q3(0));
2541         r = r + 25;
2542         theta = pi / numChambersInRing + theta;
2543         float xpos = r * cos(theta);
2544         float ypos = r * sin(theta);
2545         l.DrawLatex(xpos, ypos, chStr);
2546       }
2547       q1.Rotate(2 * pi / numChambersInRing, x);
2548       q2.Rotate(2 * pi / numChambersInRing, x);
2549       q3.Rotate(2 * pi / numChambersInRing, x);
2550       q4.Rotate(2 * pi / numChambersInRing, x);
2551     }
2552   }
2553 }