Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:14:42

0001 // $Id: $
0002 
0003 /*!
0004  * \file Draw.C
0005  * \brief 
0006  * \author Jin Huang <jhuang@bnl.gov>
0007  * \version $Revision:   $
0008  * \date $Date: $
0009  */
0010 
0011 #include <TFile.h>
0012 #include <TGraphErrors.h>
0013 #include <TLatex.h>
0014 #include <TLine.h>
0015 #include <TString.h>
0016 #include <TTree.h>
0017 #include <cassert>
0018 #include <cmath>
0019 #include "SaveCanvas.C"
0020 #include "SetOKStyle.C"
0021 using namespace std;
0022 
0023 //#include "Prototype3_DSTReader.h"
0024 
0025 TFile *_file0 = NULL;
0026 TTree *T = NULL;
0027 TString cuts = "";
0028 double beam_momentum_selection = -16;
0029 
0030 void DrawPrototype3EMCalTower(                                                                                                                    //
0031     const TString infile = "/phenix/u/jinhuang/links/sPHENIX_work/Prototype_2017/Production_0216_UpdateCalib/beam_00003672-0000_DSTReader.root",  //
0032     bool plot_all = false, const double momentum = -16)
0033 {
0034   beam_momentum_selection = momentum;
0035 
0036   SetOKStyle();
0037   gStyle->SetOptStat(0);
0038   gStyle->SetOptFit(1111);
0039   TVirtualFitter::SetDefaultFitter("Minuit2");
0040   gSystem->Load("libg4eval.so");
0041   gSystem->Load("libqa_modules.so");
0042   gSystem->Load("libPrototype3.so");
0043 
0044   //  gROOT->LoadMacro("Prototype3_DSTReader.C+");
0045 
0046   if (!_file0)
0047   {
0048     TString chian_str = infile;
0049     chian_str.ReplaceAll("ALL", "*");
0050 
0051     TChain *t = new TChain("T");
0052     const int n = t->Add(chian_str);
0053 
0054     cout << "Loaded " << n << " root files with " << chian_str << endl;
0055     assert(n > 0);
0056 
0057     T = t;
0058 
0059     _file0 = new TFile;
0060     _file0->SetName(infile);
0061   }
0062 
0063   assert(_file0);
0064 
0065   T->SetAlias("ActiveTower_LG",
0066               "TOWER_LG_CEMC[].get_binphi()<8 && TOWER_LG_CEMC[].get_bineta()<8");
0067   T->SetAlias("EnergySum_LG",
0068               "1*Sum$(TOWER_LG_CEMC[].get_energy() * ActiveTower_LG)");
0069 
0070   T->SetAlias("ActiveTower_HG",
0071               "TOWER_HG_CEMC[].get_binphi()<8 && TOWER_HG_CEMC[].get_bineta()<8");
0072   T->SetAlias("EnergySum_HG",
0073               "1*Sum$(TOWER_HG_CEMC[].get_energy() * ActiveTower_HG)");
0074 
0075   //  T->SetAlias("C2_Inner_e", "1*TOWER_RAW_C2[0].energy");
0076   T->SetAlias("C2_Inner_e", "1*(TOWER_CALIB_C2[2].energy)");
0077   T->SetAlias("C2_Outer_e", "1*(TOWER_CALIB_C2[3].energy)");
0078   T->SetAlias("C2_Sum_e", "C2_Inner_e + C2_Outer_e");
0079   T->SetAlias("C1", "0 + TOWER_CALIB_C1[0].energy");
0080 
0081   //  "TOWER_CALIB_CEMC.energy * ( Sum$( TOWER_CALIB_CEMC.get_column()==2 && TOWER_CALIB_CEMC.get_row()==1
0082 
0083   T->SetAlias("Average_column",
0084               "Sum$(TOWER_CALIB_CEMC.get_column() * TOWER_CALIB_CEMC.get_energy())/Sum$(TOWER_CALIB_CEMC.get_energy())");
0085   T->SetAlias("Average_row",
0086               "Sum$(TOWER_CALIB_CEMC.get_row() * TOWER_CALIB_CEMC.get_energy())/Sum$(TOWER_CALIB_CEMC.get_energy())");
0087 
0088   T->SetAlias("Average_HODO_VERTICAL",
0089               "Sum$(TOWER_CALIB_HODO_VERTICAL.towerid * (abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))/Sum$((abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) * abs(TOWER_CALIB_HODO_VERTICAL.energy))");
0090   T->SetAlias("Valid_HODO_VERTICAL",
0091               "Sum$(abs(TOWER_CALIB_HODO_VERTICAL.energy)>30) > 0");
0092 
0093   T->SetAlias("Average_HODO_HORIZONTAL",
0094               "Sum$(TOWER_CALIB_HODO_HORIZONTAL.towerid * (abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))/Sum$((abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) * abs(TOWER_CALIB_HODO_HORIZONTAL.energy))");
0095   T->SetAlias("Valid_HODO_HORIZONTAL",
0096               "Sum$(abs(TOWER_CALIB_HODO_HORIZONTAL.energy)>30) > 0");
0097 
0098   T->SetAlias("No_Triger_VETO",
0099               "Sum$(abs(TOWER_RAW_TRIGGER_VETO.energy)>15)==0");
0100 
0101   T->SetAlias("Energy_Sum_col1_row2_3x3",
0102               "Sum$( (abs(TOWER_CALIB_CEMC.get_column()-1)<=1 && abs(TOWER_CALIB_CEMC.get_row()-2)<=1 ) * TOWER_CALIB_CEMC.get_energy())");
0103   T->SetAlias("Energy_Sum_col1_row2_5x5",
0104               "Sum$( (abs(TOWER_CALIB_CEMC.get_column()-1)<=2 && abs(TOWER_CALIB_CEMC.get_row()-2)<=2 ) * TOWER_CALIB_CEMC.get_energy())");
0105   T->SetAlias("Energy_Sum_col2_row2_5x5",
0106               "Sum$( (abs(TOWER_CALIB_CEMC.get_column()-2)<=2 && abs(TOWER_CALIB_CEMC.get_row()-2)<=2 ) * TOWER_CALIB_CEMC.get_energy())");
0107   T->SetAlias("Energy_Sum_CEMC", "1*Sum$(TOWER_CALIB_CEMC.get_energy())");
0108   T->SetAlias("Energy_Sum_RAW_CEMC", "1*Sum$(TOWER_RAW_CEMC.get_energy())");
0109 
0110   // 12 GeV calibration
0111   //  EDM=9.83335e-18    STRATEGY= 1      ERROR MATRIX ACCURATE
0112   //EXT PARAMETER                                   STEP         FIRST
0113   //NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
0114   //1  p0           1.19768e+01   7.30605e-02   3.76799e-05   4.24290e-09
0115   //2  p1           8.71776e+00   6.82987e-02   3.52240e-05   6.80808e-08
0116 
0117   //    T->SetAlias("Energy_Sum_Hadron_CEMC",
0118   //        "1*Sum$(TOWER_CALIB_CEMC.get_energy())"); // full bias
0119   T->SetAlias("Energy_Sum_Hadron_CEMC",
0120               "1.14*12./8.71776e+00*Sum$(TOWER_CALIB_CEMC.get_energy())");  // full bias
0121                                                                             //  T->SetAlias("Energy_Sum_Hadron_CEMC",
0122                                                                             //      "1.14*12./8.71776e+00*(16./6.93250e+00)*(28/33.3405)*Sum$(TOWER_CALIB_CEMC.get_energy())"); // half-gain bias
0123   T->SetAlias("CEMC_MIP", "Energy_Sum_Hadron_CEMC<0.7");
0124 
0125   // 12 GeV calibration
0126   //  FCN=9.63681 FROM HESSE     STATUS=OK             14 CALLS          56 TOTAL
0127   //                      EDM=1.49963e-17    STRATEGY= 1      ERROR MATRIX ACCURATE
0128   //   EXT PARAMETER                                   STEP         FIRST
0129   //   NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
0130   //    1  p0           9.50430e+00   8.42691e-02   3.83666e-06   1.41105e-08
0131   //    2  p1           6.99727e+00   1.06583e-01   4.85258e-06   5.85631e-08
0132 
0133   //  T->SetAlias("Energy_Sum_Hadron_HCALIN",
0134   //      "1*Sum$(TOWER_CALIB_LG_HCALIN.get_energy())");
0135   //  T->SetAlias("HCALIN_MIP", "Energy_Sum_Hadron_HCALIN<0.5");
0136   //  T->SetAlias("Energy_Sum_Hadron_HCALOUT",
0137   //      "1*Sum$(TOWER_CALIB_LG_HCALOUT.get_energy())");
0138   T->SetAlias("Energy_Sum_Hadron_HCALIN",
0139               "12./6.99727e+00*Sum$(TOWER_CALIB_LG_HCALIN.get_energy())");
0140   T->SetAlias("HCALIN_MIP", "Energy_Sum_Hadron_HCALIN<0.5");
0141   T->SetAlias("Energy_Sum_Hadron_HCALOUT",
0142               "12./9.50430e+00*Sum$(TOWER_CALIB_LG_HCALOUT.get_energy())");
0143 
0144   T->SetAlias("MIP_Count_Col2",
0145               "Sum$( abs( TOWER_RAW_CEMC.get_energy() )>20 && abs( TOWER_RAW_CEMC.get_energy() )<200 && TOWER_CALIB_CEMC.get_column() == 2 )");
0146   T->SetAlias("Pedestal_Count_AllCEMC",
0147               "Sum$( abs( TOWER_RAW_CEMC.get_energy() )<20)");
0148 
0149   //
0150   TCut event_sel = "1*1";
0151 
0152   if (plot_all)
0153   {
0154     //      event_sel = "1*1";
0155     //      cuts = "_all_event";
0156     //      event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL";
0157     //      cuts = "_Valid_HODO";
0158     event_sel =
0159         "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO";
0160     cuts = "_Valid_HODO_Trigger_VETO";
0161   }
0162   else
0163   {
0164     if (0)
0165     {  // energy selection
0166       event_sel = Form("(beam_MTNRG_GeV == %f)", beam_momentum_selection);
0167       cuts = Form("_%.0fGeV", beam_momentum_selection);
0168 
0169       cout << "Build event selection of " << (const char *) event_sel
0170            << endl;
0171 
0172       T->Draw(">>EventListRunCut", event_sel);
0173       TEventList *elist = gDirectory->GetObjectChecked("EventListRunCut",
0174                                                        "TEventList");
0175       cout << elist->GetN() << " / " << T->GetEntriesFast()
0176            << " events selected" << endl;
0177       T->SetEventList(elist);
0178     }
0179 
0180     //      event_sel = "1*1";
0181     //      cuts = "_all_event";
0182     //      event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL";
0183     //      cuts = "_Valid_HODO";
0184     event_sel =
0185         "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO";
0186     cuts = "_Valid_HODO_Trigger_VETO";
0187 
0188     //      event_sel =
0189     //          event_sel
0190     //              + "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO  && (C2_Sum_e<50)";
0191     //      cuts = cuts + "_Valid_HODO_Trigger_VETO_C2_Sum_Hadron";
0192 
0193     //      event_sel =
0194     //          event_sel
0195     //              + "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && No_Triger_VETO && CEMC_MIP && (C2_Sum_e<100)";
0196     //      cuts = cuts + "_Valid_HODO_Trigger_VETO_CEMC_MIP_C2_Sum_Hadron";
0197 
0198     //      event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && (MIP_Count_Col2 == 8) && (Pedestal_Count_AllCEMC >= 64 - 8)";
0199     //      cuts = "_Valid_HODO_MIP_Col2_PedestalOther";
0200 
0201     //      event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && Average_HODO_VERTICAL>1.5 && Average_HODO_VERTICAL<4.5 && Average_HODO_HORIZONTAL>3.5 && Average_HODO_HORIZONTAL<6.5";
0202     //      cuts = "_Valid_HODO_center_col1_row2";
0203 
0204     //      event_sel =
0205     //          "C2_Inner_e>100 && Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && Average_HODO_HORIZONTAL>1.5 && Average_HODO_HORIZONTAL<4.5 && Average_HODO_VERTICAL>3.5 && Average_HODO_VERTICAL<6.5";
0206     //      cuts = "_Valid_HODO_center_col1_row2_C2";
0207 
0208     //      event_sel = "abs(Average_column - 1)<.5 && abs(Average_row - 2) < .5";
0209     //      cuts = "_tower_center_col1_row2";
0210     //      event_sel = "Valid_HODO_HORIZONTAL && Valid_HODO_VERTICAL && abs(C2_Inner_e)<10";
0211     //      cuts = "_Valid_HODO_VetoC2";
0212   }
0213 
0214   cout << "Build event selection of " << (const char *) event_sel << endl;
0215 
0216   T->Draw(">>EventList", event_sel);
0217   TEventList *elist = gDirectory->GetObjectChecked("EventList", "TEventList");
0218   cout << elist->GetN() << " / " << T->GetEntriesFast() << " events selected"
0219        << endl;
0220 
0221   T->SetEventList(elist);
0222 
0223   //  int rnd = rand();
0224   //  gDirectory->mkdir(Form("dir_%d", rnd));
0225   //  gDirectory->cd(Form("dir_%d", rnd));
0226   //  if (plot_all)
0227   //    EMCDistribution_SUM("Energy_Sum_col1_row2_5x5");
0228 
0229   int rnd = rand();
0230   gDirectory->mkdir(Form("dir_%d", rnd));
0231   gDirectory->cd(Form("dir_%d", rnd));
0232   if (plot_all)
0233     EMCDistribution_ShowShape("C1");
0234 
0235   int rnd = rand();
0236   gDirectory->mkdir(Form("dir_%d", rnd));
0237   gDirectory->cd(Form("dir_%d", rnd));
0238   if (plot_all)
0239     EMCDistribution_SUM("Energy_Sum_CEMC", "C1");
0240   int rnd = rand();
0241   gDirectory->mkdir(Form("dir_%d", rnd));
0242   gDirectory->cd(Form("dir_%d", rnd));
0243   //  if (plot_all)
0244   EMCDistribution_SUM_RawADC("Energy_Sum_RAW_CEMC", "C2_Sum_e");
0245 
0246   int rnd = rand();
0247   gDirectory->mkdir(Form("dir_%d", rnd));
0248   gDirectory->cd(Form("dir_%d", rnd));
0249   if (plot_all)
0250     EMCDistribution_SUM("Energy_Sum_col2_row2_5x5", "C2_Sum_e");
0251 
0252   int rnd = rand();
0253   gDirectory->mkdir(Form("dir_%d", rnd));
0254   gDirectory->cd(Form("dir_%d", rnd));
0255   if (plot_all)
0256     EMCDistribution_HCalCalibration();
0257 
0258   int rnd = rand();
0259   gDirectory->mkdir(Form("dir_%d", rnd));
0260   gDirectory->cd(Form("dir_%d", rnd));
0261   if (plot_all)
0262     EMCDistribution_Fast();
0263 
0264   int rnd = rand();
0265   gDirectory->mkdir(Form("dir_%d", rnd));
0266   gDirectory->cd(Form("dir_%d", rnd));
0267   if (plot_all)
0268     EMCDistribution_Fast("RAW");
0269   //
0270   //  int rnd = rand();
0271   //  gDirectory->mkdir(Form("dir_%d", rnd));
0272   //  gDirectory->cd(Form("dir_%d", rnd));
0273   //  if (plot_all)
0274   //    EMCDistribution_PeakSample_Fast();
0275 
0276   int rnd = rand();
0277   gDirectory->mkdir(Form("dir_%d", rnd));
0278   gDirectory->cd(Form("dir_%d", rnd));
0279   if (plot_all)
0280     EMCDistribution_Fast("CALIB", true);
0281 
0282   int rnd = rand();
0283   gDirectory->mkdir(Form("dir_%d", rnd));
0284   gDirectory->cd(Form("dir_%d", rnd));
0285   if (plot_all)
0286     EMCDistribution_ADC();
0287 
0288   //  if (!plot_all)
0289   //    T->Process("Prototype3_DSTReader.C+",
0290   //        TString(_file0->GetName())
0291   //            + TString("_DrawPrototype3EMCalTower_Prototype3_DSTReader") + cuts
0292   //            + TString(".dat"));
0293 }
0294 
0295 void EMCDistribution_HCalCalibration()
0296 {
0297   gStyle->SetOptStat(0);
0298   gStyle->SetOptFit(1111);
0299 
0300   TH1F *h1_HCalOut = new TH1F("h1_HCalOut",
0301                               "(CEMC MIP && HCal_{IN} MIP);EMCal + HCal_{IN} + HCal_{OUT} (GeV)", 100,
0302                               0, abs(beam_momentum_selection) * 2.);
0303 
0304   TH2 *h2_HCalOut_HCalIn =
0305       new TH2F("h2_HCalOut_HCalIn",
0306                "Energy Balance HCal_{OUT} and HCal_{IN} (CEMC MIP && NOT HCal_{IN} MIP);(HCal_{OUT} - HCal_{IN})/HCal Sum;EMCal + HCal_{IN} + HCal_{OUT} (GeV)",
0307                10, -1, 1, 100, 0, abs(beam_momentum_selection) * 2.);
0308 
0309   TH2 *h2_HCal_EMCal =
0310       new TH2F("h2_HCal_EMCal",
0311                "Energy Balance HCal_{SUM} and EMCal (NOT CEMC MIP);(HCal_{SUM} - EMCal)/Sum;EMCal + HCal_{IN} + HCal_{OUT} (GeV)",
0312                10, -1, 1, 100, 0, abs(beam_momentum_selection) * 2.);
0313 
0314   TText *t;
0315   TCanvas *c1 = new TCanvas("EMCDistribution_HCalCalibration" + cuts,
0316                             "EMCDistribution_HCalCalibration" + cuts, 1800, 600);
0317   c1->Divide(3, 1);
0318   int idx = 1;
0319   TPad *p;
0320 
0321   p = (TPad *) c1->cd(idx++);
0322   c1->Update();
0323 
0324   T->Draw(
0325       "Energy_Sum_Hadron_CEMC + Energy_Sum_Hadron_HCALIN + Energy_Sum_Hadron_HCALOUT:(Energy_Sum_Hadron_HCALOUT - Energy_Sum_Hadron_HCALIN)/(Energy_Sum_Hadron_HCALIN+Energy_Sum_Hadron_HCALOUT)>>h2_HCalOut_HCalIn",
0326       "(!HCALIN_MIP) && CEMC_MIP", "goff");
0327   h2_HCalOut_HCalIn->FitSlicesY();
0328 
0329   TH1 *h2_HCalOut_HCalIn_1 = (TH1 *) gDirectory->GetObjectChecked(
0330       "h2_HCalOut_HCalIn_1", "TH1D");
0331   assert(h2_HCalOut_HCalIn_1);
0332   h2_HCalOut_HCalIn_1->SetMarkerStyle(kFullCircle);
0333 
0334   TF1 *f_HCalOut_HCalIn = new TF1("f_HCalOut_HCalIn",
0335                                   "[0] * (x+1)/2 + [1]*(1-x)/2", -.8, 0.8);
0336   f_HCalOut_HCalIn->SetLineColor(kMagenta);
0337   f_HCalOut_HCalIn->SetLineWidth(3);
0338   h2_HCalOut_HCalIn_1->Fit(f_HCalOut_HCalIn, "MR0");
0339 
0340   h2_HCalOut_HCalIn->DrawClone("colz");
0341   h2_HCalOut_HCalIn_1->DrawClone("SAME");
0342   f_HCalOut_HCalIn->DrawClone("same");
0343 
0344   p = (TPad *) c1->cd(idx++);
0345   c1->Update();
0346 
0347   T->Draw(
0348       "Energy_Sum_Hadron_CEMC + Energy_Sum_Hadron_HCALIN + Energy_Sum_Hadron_HCALOUT:(Energy_Sum_Hadron_HCALIN + Energy_Sum_Hadron_HCALOUT - Energy_Sum_Hadron_CEMC)/(Energy_Sum_Hadron_CEMC + Energy_Sum_Hadron_HCALIN + Energy_Sum_Hadron_HCALOUT)>>h2_HCal_EMCal",
0349       "! CEMC_MIP", "goff");
0350   h2_HCal_EMCal->FitSlicesY();
0351 
0352   TH1 *h2_HCal_EMCal_1 = (TH1 *) gDirectory->GetObjectChecked(
0353       "h2_HCal_EMCal_1", "TH1D");
0354   assert(h2_HCal_EMCal_1);
0355   h2_HCal_EMCal_1->SetMarkerStyle(kFullCircle);
0356 
0357   TF1 *f_HCal_EMCal = new TF1("f_HCal_EMCal", "[0] * (x+1)/2 + [1]*(1-x)/2",
0358                               -.8, 0.8);
0359   f_HCal_EMCal->SetLineColor(kMagenta);
0360   f_HCal_EMCal->SetLineWidth(3);
0361   h2_HCal_EMCal_1->Fit(f_HCal_EMCal, "MR0");
0362 
0363   h2_HCal_EMCal->DrawClone("colz");
0364   h2_HCal_EMCal_1->DrawClone("SAME");
0365   f_HCal_EMCal->DrawClone("same");
0366 
0367   p = (TPad *) c1->cd(idx++);
0368   c1->Update();
0369 
0370   T->Draw(
0371       "Energy_Sum_Hadron_CEMC + Energy_Sum_Hadron_HCALIN + Energy_Sum_Hadron_HCALOUT>>h1_HCalOut",
0372       "HCALIN_MIP && CEMC_MIP", "goff");
0373 
0374   TH1 *h2_HCal_EMCal_ProjY = (TH1 *) h2_HCal_EMCal->ProjectionY(
0375                                                       "h2_HCal_EMCal_ProjY", 2, 9)
0376                                  ->DrawClone();
0377   TH1 *h2_HCalOut_HCalIn_ProjY = (TH1 *) h2_HCalOut_HCalIn->ProjectionY(
0378                                                               "h2_HCalOut_HCalIn_ProjY")
0379                                      ->DrawClone("same");
0380   h1_HCalOut->Draw("same");
0381 
0382   h2_HCal_EMCal_ProjY->SetTitle(
0383       "Red: 3 Calo shower, Blue: MIP EMCal, Green: MIP EMCal & HCal_{IN}");
0384 
0385   h2_HCal_EMCal_ProjY->SetLineColor(kRed + 2);
0386   h2_HCal_EMCal_ProjY->SetLineWidth(3);
0387   h2_HCalOut_HCalIn_ProjY->SetLineColor(kBlue + 2);
0388   h2_HCalOut_HCalIn_ProjY->SetLineWidth(2);
0389   h1_HCalOut->SetLineColor(kGreen + 3);
0390   h1_HCalOut->SetLineWidth(3);
0391 
0392   SaveCanvas(c1,
0393              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
0394 }
0395 
0396 void EMCDistribution_ShowShape(TString CherenkovSignal = "C2_Inner",
0397                                const double che_cut = 10)
0398 {
0399   TString cut_pass = CherenkovSignal + Form(">%.1f", che_cut);
0400   TString cut_rej = CherenkovSignal + Form("<%.1f", che_cut);
0401 
0402   const double event_pass = T->GetEntries(cut_pass);
0403   const double event_rej = T->GetEntries(cut_rej);
0404 
0405   TH2 *EnergyDist_pass = new TH2F("EnergyDist_pass",
0406                                   cut_pass + ";Column;Row;<Energy> / Event / Tower", 8, -.5, 7.5, 8, -.5,
0407                                   7.5);
0408   TH2 *EnergyDist_rej = new TH2F("EnergyDist_rej",
0409                                  cut_rej + ";Column;Row;<Energy> / Event / Tower", 8, -.5, 7.5, 8, -.5,
0410                                  7.5);
0411   TH2 *Hodoscope_dist = new TH2F("Hodoscope_dist",
0412                                  cut_rej + ";7 - Horizontal Hodoscope (5 mm);7 - Vertical Hodoscope (5 mm); Event / finger^2", 8, -.5, 7.5, 8, -.5,
0413                                  7.5);
0414 
0415   TH1 *Che_full = new TH1F("Che_full",
0416                            ";" + CherenkovSignal + " Signal (ADC);Count / bin", 200, 0, 2000);
0417   TH1 *Che_pass = new TH1F("Che_pass",
0418                            ";" + CherenkovSignal + " Signal (ADC);Count / bin", 200, 0, 2000);
0419   TH1 *Che_rej = new TH1F("Che_rej",
0420                           ";" + CherenkovSignal + " Signal (ADC);Count / bin", 200, 0, 2000);
0421 
0422   Che_full->SetLineColor(kBlue + 3);
0423   Che_full->SetLineWidth(2);
0424   Che_pass->SetLineColor(kGreen + 3);
0425   Che_pass->SetLineWidth(2);
0426   Che_pass->SetFillColor(kGreen + 3);
0427   Che_pass->SetFillStyle(1);
0428   Che_rej->SetLineColor(kBlue + 3);
0429   Che_rej->SetLineWidth(2);
0430   Che_rej->SetFillColor(kBlue + 3);
0431   Che_rej->SetFillStyle(1);
0432 
0433   T->Draw(
0434       "TOWER_CALIB_CEMC[].get_binphi():TOWER_CALIB_CEMC[].get_bineta()>>EnergyDist_pass",
0435       Form("(%s) * (TOWER_CALIB_CEMC[].get_energy())", cut_pass.Data()),
0436       "goff");
0437   T->Draw(
0438       "TOWER_CALIB_CEMC[].get_binphi():TOWER_CALIB_CEMC[].get_bineta()>>EnergyDist_rej",
0439       Form("(%s) * (TOWER_CALIB_CEMC[].get_energy())", cut_rej.Data()), "goff");
0440   T->Draw(
0441       "7 - Average_HODO_VERTICAL:7 - Average_HODO_HORIZONTAL>>Hodoscope_dist", "1", "goff");
0442 
0443   T->Draw(CherenkovSignal + ">>Che_full", NULL, "goff");
0444   T->Draw(CherenkovSignal + ">>Che_pass", cut_pass, "goff");
0445   T->Draw(CherenkovSignal + ">>Che_rej", cut_rej, "goff");
0446 
0447   EnergyDist_pass->Scale(1. / event_pass);
0448   EnergyDist_rej->Scale(1. / event_rej);
0449 
0450   TText *t;
0451   TCanvas *c1 = new TCanvas("EMCDistribution_ShowShape" + cuts,
0452                             "EMCDistribution_ShowShape" + cuts, 1100, 950);
0453   c1->Divide(2, 2);
0454   int idx = 1;
0455   TPad *p;
0456 
0457   p = (TPad *) c1->cd(idx++);
0458   c1->Update();
0459   p->SetLogy();
0460   p->SetGridx(0);
0461   p->SetGridy(0);
0462 
0463   Che_full->DrawClone();
0464   Che_pass->DrawClone("same");
0465   Che_rej->DrawClone("same");
0466 
0467   p = (TPad *) c1->cd(idx++);
0468   c1->Update();
0469   //  p->SetLogy();
0470 
0471   EnergyDist_pass->DrawClone("colz");
0472 
0473   p = (TPad *) c1->cd(idx++);
0474   c1->Update();
0475   //  p->SetLogy();
0476   //  p->SetGridx(0);
0477   //  p->SetGridy(0);
0478 
0479   EnergyDist_rej->DrawClone("colz");
0480 
0481   p = (TPad *) c1->cd(idx++);
0482   c1->Update();
0483   //  p->SetLogy();
0484   //  p->SetGridx(0);
0485   //  p->SetGridy(0);
0486 
0487   Hodoscope_dist->DrawClone("colz");
0488 
0489   SaveCanvas(c1,
0490              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
0491 }
0492 
0493 void EMCDistribution_SUM(TString sTOWER = "Energy_Sum_col1_row2_5x5",
0494                          TString CherenkovSignal = "C2_Inner")
0495 {
0496   TH1 *EnergySum_LG_full = new TH1F("EnergySum_LG_full",
0497                                     ";Full range Tower Energy Sum (GeV);Count / bin", 900, 0, 120);
0498   TH1 *EnergySum_LG = new TH1F("EnergySum_LG",
0499                                ";Full range Tower Energy Sum (GeV);Count / bin", 900, 0, 120);
0500   //  TH1 * EnergySum_HG = new TH1F("EnergySum_HG",
0501   //      ";Low range Tower Energy Sum (ADC);Count / bin", 50, 0, 500);
0502 
0503   TH1 *C2_Inner_full = new TH1F("C2_Inner_full",
0504                                 CherenkovSignal + ";Cherenkov Signal (ADC);Count / bin", 1000, 0, 2000);
0505   TH1 *C2_Inner = new TH1F("C2_Inner",
0506                            CherenkovSignal + ";Cherenkov Inner Signal (ADC);Count / bin", 200, 0,
0507                            2000);
0508 
0509   EnergySum_LG_full->SetLineColor(kBlue + 3);
0510   EnergySum_LG_full->SetLineWidth(2);
0511 
0512   EnergySum_LG->SetLineColor(kGreen + 3);
0513   EnergySum_LG->SetLineWidth(3);
0514   EnergySum_LG->SetMarkerColor(kGreen + 3);
0515 
0516   C2_Inner_full->SetLineColor(kBlue + 3);
0517   C2_Inner_full->SetLineWidth(2);
0518 
0519   C2_Inner->SetLineColor(kGreen + 3);
0520   C2_Inner->SetLineWidth(3);
0521   C2_Inner->SetMarkerColor(kGreen + 3);
0522 
0523   TCut c2 = CherenkovSignal + ">240";
0524 
0525   T->Draw(sTOWER + ">>EnergySum_LG_full", "", "goff");
0526   T->Draw(sTOWER + ">>EnergySum_LG", c2, "goff");
0527   T->Draw(CherenkovSignal + ">>C2_Inner_full", "", "goff");
0528   T->Draw(CherenkovSignal + ">>C2_Inner", c2, "goff");
0529 
0530   TText *t;
0531   TCanvas *c1 = new TCanvas(
0532       "EMCDistribution_SUM_" + sTOWER + "_" + CherenkovSignal + cuts,
0533       "EMCDistribution_SUM_" + sTOWER + "_" + CherenkovSignal + cuts, 1800,
0534       600);
0535   c1->Divide(3, 1);
0536   int idx = 1;
0537   TPad *p;
0538 
0539   p = (TPad *) c1->cd(idx++);
0540   c1->Update();
0541   p->SetLogy();
0542   p->SetGridx(0);
0543   p->SetGridy(0);
0544 
0545   C2_Inner_full->DrawClone();
0546   C2_Inner->DrawClone("same");
0547 
0548   p = (TPad *) c1->cd(idx++);
0549   c1->Update();
0550   p->SetLogy();
0551   p->SetGridx(0);
0552   p->SetGridy(0);
0553 
0554   TH1 *h = (TH1 *) EnergySum_LG_full->DrawClone();
0555   h->GetXaxis()->SetRangeUser(0, h->GetMean() + 5 * h->GetRMS());
0556   (TH1 *) EnergySum_LG->DrawClone("same");
0557 
0558   p = (TPad *) c1->cd(idx++);
0559   c1->Update();
0560   //  p->SetLogy();
0561   p->SetGridx(0);
0562   p->SetGridy(0);
0563 
0564   TH1 *h_full = (TH1 *) EnergySum_LG_full->DrawClone();
0565   TH1 *h = (TH1 *) EnergySum_LG->DrawClone("same");
0566 
0567   TF1 *fgaus_g = new TF1("fgaus_LG_g", "gaus", h->GetMean() - 1 * h->GetRMS(),
0568                          h->GetMean() + 4 * h->GetRMS());
0569   fgaus_g->SetParameters(1, h->GetMean() - 2 * h->GetRMS(),
0570                          h->GetMean() + 2 * h->GetRMS());
0571   h->Fit(fgaus_g, "MR0N");
0572 
0573   TF1 *fgaus = new TF1("fgaus_LG", "gaus",
0574                        fgaus_g->GetParameter(1) - 1 * fgaus_g->GetParameter(2),
0575                        fgaus_g->GetParameter(1) + 4 * fgaus_g->GetParameter(2));
0576   fgaus->SetParameters(fgaus_g->GetParameter(0), fgaus_g->GetParameter(1),
0577                        fgaus_g->GetParameter(2));
0578   h->Fit(fgaus, "MR");
0579 
0580   h->Sumw2();
0581   h_full->Sumw2();
0582   h_full->GetXaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(),
0583                                    h->GetMean() + 4 * h->GetRMS());
0584 
0585   h->SetLineWidth(2);
0586   h->SetMarkerStyle(kFullCircle);
0587 
0588   h_full->SetTitle(
0589       Form("#DeltaE/<E> = %.1f%%",
0590            100 * fgaus->GetParameter(2) / fgaus->GetParameter(1)));
0591 
0592   //  p = (TPad *) c1->cd(idx++);
0593   //  c1->Update();
0594   //  p->SetLogy();
0595   //  p->SetGridx(0);
0596   //  p->SetGridy(0);
0597   //
0598   //  TH1 * h = (TH1 *) EnergySum_LG->DrawClone();
0599   //  h->GetXaxis()->SetRangeUser(0,500);
0600   //  h->SetLineWidth(2);
0601   //  h->SetLineColor(kBlue + 3);
0602   ////  h->Sumw2();
0603   //  h->GetXaxis()->SetRangeUser(0, h->GetMean() + 5 * h->GetRMS());
0604   //
0605   //  p = (TPad *) c1->cd(idx++);
0606   //  c1->Update();
0607   ////  p->SetLogy();
0608   //  p->SetGridx(0);
0609   //  p->SetGridy(0);
0610   //
0611   //  TH1 * h = (TH1 *) EnergySum_LG->DrawClone();
0612   //  h->GetXaxis()->SetRangeUser(0,500);
0613   //
0614   //  TF1 * fgaus = new TF1("fgaus_HG", "gaus", 0, 100);
0615   //  fgaus->SetParameters(1, h->GetMean() - 2 * h->GetRMS(),
0616   //      h->GetMean() + 2 * h->GetRMS());
0617   //  h->Fit(fgaus, "M");
0618   //
0619   //  h->Sumw2();
0620   //  h->GetXaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(),
0621   //      h->GetMean() + 4 * h->GetRMS());
0622   //
0623   //  h->SetLineWidth(2);
0624   //  h->SetMarkerStyle(kFullCircle);
0625   //
0626   //  h->SetTitle(
0627   //      Form("#DeltaE/<E> = %.1f%%",
0628   //          100 * fgaus->GetParameter(2) / fgaus->GetParameter(1)));
0629 
0630   SaveCanvas(c1,
0631              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
0632 }
0633 
0634 void EMCDistribution_SUM_RawADC(TString sTOWER = "Energy_Sum_col1_row2_5x5",
0635                                 TString CherenkovSignal = "C2_Inner")
0636 {
0637   TH1 *EnergySum_LG_full = new TH1F("EnergySum_LG_full",
0638                                     ";Tower Energy Sum (ADC);Count / bin", 260, -100, 2500);
0639   TH1 *EnergySum_LG = new TH1F("EnergySum_LG",
0640                                ";Tower Energy Sum (ADC);Count / bin", 260, -100, 2500);
0641   //  TH1 * EnergySum_HG = new TH1F("EnergySum_HG",
0642   //      ";Low range Tower Energy Sum (ADC);Count / bin", 50, 0, 500);
0643 
0644   TH1 *C2_Inner_full = new TH1F("C2_Inner_full",
0645                                 CherenkovSignal + ";Cherenkov Signal (ADC);Count / bin", 1000, 0, 2000);
0646   TH1 *C2_Inner = new TH1F("C2_Inner",
0647                            CherenkovSignal + ";Cherenkov Inner Signal (ADC);Count / bin", 1000, 0, 2000);
0648 
0649   EnergySum_LG_full->SetLineColor(kBlue + 3);
0650   EnergySum_LG_full->SetLineWidth(2);
0651 
0652   EnergySum_LG->SetLineColor(kGreen + 3);
0653   EnergySum_LG->SetLineWidth(3);
0654   EnergySum_LG->SetMarkerColor(kGreen + 3);
0655 
0656   C2_Inner_full->SetLineColor(kBlue + 3);
0657   C2_Inner_full->SetLineWidth(2);
0658 
0659   C2_Inner->SetLineColor(kGreen + 3);
0660   C2_Inner->SetLineWidth(3);
0661   C2_Inner->SetMarkerColor(kGreen + 3);
0662 
0663   TCut c2 = CherenkovSignal + ">240";
0664 
0665   T->Draw(sTOWER + ">>EnergySum_LG_full", "", "goff");
0666   T->Draw(sTOWER + ">>EnergySum_LG", c2, "goff");
0667   T->Draw(CherenkovSignal + ">>C2_Inner_full", "", "goff");
0668   T->Draw(CherenkovSignal + ">>C2_Inner", c2, "goff");
0669 
0670   TText *t;
0671   TCanvas *c1 = new TCanvas(
0672       "EMCDistribution_SUM_RawADC_" + sTOWER + "_" + CherenkovSignal + cuts,
0673       "EMCDistribution_SUM_RawADC_" + sTOWER + "_" + CherenkovSignal + cuts, 1800,
0674       600);
0675   c1->Divide(3, 1);
0676   int idx = 1;
0677   TPad *p;
0678 
0679   p = (TPad *) c1->cd(idx++);
0680   c1->Update();
0681   p->SetLogy();
0682   p->SetGridx(0);
0683   p->SetGridy(0);
0684 
0685   C2_Inner_full->DrawClone();
0686   C2_Inner->DrawClone("same");
0687 
0688   p = (TPad *) c1->cd(idx++);
0689   c1->Update();
0690   p->SetLogy();
0691   p->SetGridx(0);
0692   p->SetGridy(0);
0693 
0694   TH1 *h = (TH1 *) EnergySum_LG_full->DrawClone();
0695   //  h->GetXaxis()->SetRangeUser(0, h->GetMean() + 5 * h->GetRMS());
0696   (TH1 *) EnergySum_LG->DrawClone("same");
0697 
0698   p = (TPad *) c1->cd(idx++);
0699   c1->Update();
0700   //  p->SetLogy();
0701   p->SetGridx(0);
0702   p->SetGridy(0);
0703 
0704   TH1 *h_full = (TH1 *) EnergySum_LG_full->DrawClone();
0705   TH1 *h = (TH1 *) EnergySum_LG->DrawClone("same");
0706 
0707   TF1 *fgaus_g = new TF1("fgaus_LG_g", "gaus", h->GetMean() - 1 * h->GetRMS(),
0708                          h->GetMean() + 4 * h->GetRMS());
0709   fgaus_g->SetParameters(1, h->GetMean() - 2 * h->GetRMS(),
0710                          h->GetMean() + 2 * h->GetRMS());
0711   h->Fit(fgaus_g, "MR0N");
0712 
0713   TF1 *fgaus = new TF1("fgaus_LG", "gaus",
0714                        fgaus_g->GetParameter(1) - 1 * fgaus_g->GetParameter(2),
0715                        fgaus_g->GetParameter(1) + 4 * fgaus_g->GetParameter(2));
0716   fgaus->SetParameters(fgaus_g->GetParameter(0), fgaus_g->GetParameter(1),
0717                        fgaus_g->GetParameter(2));
0718   h->Fit(fgaus, "MR");
0719 
0720   h->Sumw2();
0721   h_full->Sumw2();
0722   h_full->GetXaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(),
0723                                    h->GetMean() + 4 * h->GetRMS());
0724 
0725   h->SetLineWidth(2);
0726   h->SetMarkerStyle(kFullCircle);
0727 
0728   h_full->SetTitle(
0729       Form("#DeltaE/<E> = %.1f%%",
0730            100 * fgaus->GetParameter(2) / fgaus->GetParameter(1)));
0731 
0732   //  p = (TPad *) c1->cd(idx++);
0733   //  c1->Update();
0734   //  p->SetLogy();
0735   //  p->SetGridx(0);
0736   //  p->SetGridy(0);
0737   //
0738   //  TH1 * h = (TH1 *) EnergySum_LG->DrawClone();
0739   //  h->GetXaxis()->SetRangeUser(0,500);
0740   //  h->SetLineWidth(2);
0741   //  h->SetLineColor(kBlue + 3);
0742   ////  h->Sumw2();
0743   //  h->GetXaxis()->SetRangeUser(0, h->GetMean() + 5 * h->GetRMS());
0744   //
0745   //  p = (TPad *) c1->cd(idx++);
0746   //  c1->Update();
0747   ////  p->SetLogy();
0748   //  p->SetGridx(0);
0749   //  p->SetGridy(0);
0750   //
0751   //  TH1 * h = (TH1 *) EnergySum_LG->DrawClone();
0752   //  h->GetXaxis()->SetRangeUser(0,500);
0753   //
0754   //  TF1 * fgaus = new TF1("fgaus_HG", "gaus", 0, 100);
0755   //  fgaus->SetParameters(1, h->GetMean() - 2 * h->GetRMS(),
0756   //      h->GetMean() + 2 * h->GetRMS());
0757   //  h->Fit(fgaus, "M");
0758   //
0759   //  h->Sumw2();
0760   //  h->GetXaxis()->SetRangeUser(h->GetMean() - 4 * h->GetRMS(),
0761   //      h->GetMean() + 4 * h->GetRMS());
0762   //
0763   //  h->SetLineWidth(2);
0764   //  h->SetMarkerStyle(kFullCircle);
0765   //
0766   //  h->SetTitle(
0767   //      Form("#DeltaE/<E> = %.1f%%",
0768   //          100 * fgaus->GetParameter(2) / fgaus->GetParameter(1)));
0769 
0770   SaveCanvas(c1,
0771              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
0772 }
0773 
0774 void EMCDistribution_Fast(TString gain = "CALIB", bool full_gain = false)
0775 {
0776   TString hname = "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts;
0777 
0778   TH2 *h2 = NULL;
0779   if (gain.Contains("CALIB"))
0780   {
0781     if (full_gain)
0782     {
0783       h2 = new TH2F(hname,
0784                     Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 100, .05,
0785                     25, 64, -.5, 63.5);
0786       QAHistManagerDef::useLogBins(h2->GetXaxis());
0787     }
0788     else
0789     {
0790       h2 = new TH2F(hname,
0791                     Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 260, -.2,
0792                     5, 64, -.5, 63.5);
0793     }
0794     T->Draw(
0795         "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain + "_CEMC[].get_binphi():TOWER_" + gain + "_CEMC[].get_energy()>>" + hname, "", "goff");
0796   }
0797   else if (gain.Contains("RAW"))
0798   {
0799     if (full_gain)
0800     {
0801       h2 = new TH2F(hname,
0802                     Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 100,
0803                     .05 * 100, 25 * 100, 64, -.5, 63.5);
0804       QAHistManagerDef::useLogBins(h2->GetXaxis());
0805     }
0806     else
0807     {
0808       h2 = new TH2F(hname,
0809                     Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 260,
0810                     -.2 * 100, 5 * 100, 64, -.5, 63.5);
0811     }
0812     T->Draw(
0813         "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain + "_CEMC[].get_binphi():TOWER_" + gain + "_CEMC[].get_energy()>>" + hname, "", "goff");
0814   }
0815 
0816   TText *t;
0817   TCanvas *c1 = new TCanvas(
0818       "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts,
0819       "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts,
0820       1800, 950);
0821   c1->Divide(8, 8, 0., 0.01);
0822   int idx = 1;
0823   TPad *p;
0824 
0825   for (int iphi = 8 - 1; iphi >= 0; iphi--)
0826   {
0827     for (int ieta = 0; ieta < 8; ieta++)
0828     {
0829       p = (TPad *) c1->cd(idx++);
0830       c1->Update();
0831 
0832       p->SetLogy();
0833       if (full_gain)
0834       {
0835         p->SetLogx();
0836       }
0837       p->SetGridx(0);
0838       p->SetGridy(0);
0839 
0840       TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(full_gain ? "_FullGain" : "");
0841 
0842       TH1 *h = h2->ProjectionX(hname, ieta + 8 * iphi + 1,
0843                                ieta + 8 * iphi + 1);  // axis bin number is encoded as ieta+8*iphi+1
0844 
0845       h->SetLineWidth(0);
0846       h->SetLineColor(kBlue + 3);
0847       h->SetFillColor(kBlue + 3);
0848 
0849       h->GetXaxis()->SetTitleSize(.09);
0850       h->GetXaxis()->SetLabelSize(.08);
0851       h->GetYaxis()->SetLabelSize(.08);
0852 
0853       h->Draw();
0854 
0855       if (full_gain)
0856         h->Fit("x*gaus", "M");
0857       else
0858         h->Fit("landau", "M");
0859 
0860       double peak = -1;
0861 
0862       TF1 *fit = ((TF1 *) (h->GetListOfFunctions()->At(0)));
0863       if (fit)
0864       {
0865         fit->SetLineColor(kRed);
0866         peak = fit->GetParameter(1);
0867       }
0868 
0869       cout << Form("Finished <Col%d Row%d> = %.1f", ieta, iphi, peak)
0870            << endl;
0871 
0872       TText *t = new TText(.9, .9,
0873                            Form("<Col%d Row%d> = %.1f", ieta, iphi, peak));
0874       t->SetTextAlign(33);
0875       t->SetTextSize(.15);
0876       t->SetNDC();
0877       t->Draw();
0878     }
0879   }
0880 
0881   SaveCanvas(c1,
0882              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
0883 }
0884 
0885 void EMCDistribution_PeakSample_Fast(bool full_gain = false)
0886 {
0887   const TString gain = "RAW";
0888 
0889   TString hname = "EMCDistribution_" + gain + TString(full_gain ? "_FullGain" : "") + cuts;
0890 
0891   TH2 *h2 = NULL;
0892   {
0893     if (full_gain)
0894     {
0895       h2 = new TH2F(hname,
0896                     Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 100,
0897                     .05 * 100, 25 * 100, 64, -.5, 63.5);
0898       QAHistManagerDef::useLogBins(h2->GetXaxis());
0899     }
0900     else
0901     {
0902       h2 = new TH2F(hname,
0903                     Form(";Calibrated Tower Energy Sum (ADC);Count / bin"), 260,
0904                     -.2 * 100, 5 * 100, 64, -.5, 63.5);
0905     }
0906     T->Draw(
0907         "TOWER_" + gain + "_CEMC[].get_bineta() + 8* TOWER_" + gain + "_CEMC[].get_binphi():(TOWER_RAW_CEMC[].signal_samples[10] - TOWER_RAW_CEMC[].signal_samples[0])*(-1)>>" + hname, "", "goff");
0908   }
0909 
0910   TText *t;
0911   TCanvas *c1 = new TCanvas(
0912       "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "") + cuts,
0913       "EMCDistribution_PeakSample_Fast_" + TString(full_gain ? "_FullGain" : "") + cuts, 1800, 950);
0914   c1->Divide(8, 8, 0., 0.01);
0915   int idx = 1;
0916   TPad *p;
0917 
0918   for (int iphi = 8 - 1; iphi >= 0; iphi--)
0919   {
0920     for (int ieta = 0; ieta < 8; ieta++)
0921     {
0922       p = (TPad *) c1->cd(idx++);
0923       c1->Update();
0924 
0925       p->SetLogy();
0926       if (full_gain)
0927       {
0928         p->SetLogx();
0929       }
0930       p->SetGridx(0);
0931       p->SetGridy(0);
0932 
0933       TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(full_gain ? "_FullGain" : "");
0934 
0935       TH1 *h = h2->ProjectionX(hname, ieta + 8 * iphi + 1,
0936                                ieta + 8 * iphi + 1);  // axis bin number is encoded as ieta+8*iphi+1
0937 
0938       h->SetLineWidth(0);
0939       h->SetLineColor(kBlue + 3);
0940       h->SetFillColor(kBlue + 3);
0941 
0942       h->GetXaxis()->SetTitleSize(.09);
0943       h->GetXaxis()->SetLabelSize(.08);
0944       h->GetYaxis()->SetLabelSize(.08);
0945 
0946       h->Draw();
0947 
0948       if (full_gain)
0949         h->Fit("x*gaus", "M");
0950       else
0951         h->Fit("landau", "M");
0952 
0953       double peak = -1;
0954 
0955       TF1 *fit = ((TF1 *) (h->GetListOfFunctions()->At(0)));
0956       if (fit)
0957       {
0958         fit->SetLineColor(kRed);
0959         peak = fit->GetParameter(1);
0960       }
0961 
0962       cout << Form("Finished <Col%d Row%d> = %.1f", ieta, iphi, peak)
0963            << endl;
0964 
0965       TText *t = new TText(.9, .9,
0966                            Form("<Col%d Row%d> = %.1f", ieta, iphi, peak));
0967       t->SetTextAlign(33);
0968       t->SetTextSize(.15);
0969       t->SetNDC();
0970       t->Draw();
0971     }
0972   }
0973 
0974   SaveCanvas(c1,
0975              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
0976 }
0977 
0978 void EMCDistribution(TString gain = "CALIB", bool log_scale = false)
0979 {
0980   TText *t;
0981   TCanvas *c1 = new TCanvas(
0982       "EMCDistribution_" + gain + TString(log_scale ? "_Log" : "") + cuts,
0983       "EMCDistribution_" + gain + TString(log_scale ? "_Log" : "") + cuts, 1800,
0984       1000);
0985   c1->Divide(8, 8, 0., 0.01);
0986   int idx = 1;
0987   TPad *p;
0988 
0989   for (int iphi = 8 - 1; iphi >= 0; iphi--)
0990   {
0991     for (int ieta = 0; ieta < 8; ieta++)
0992     {
0993       p = (TPad *) c1->cd(idx++);
0994       c1->Update();
0995 
0996       p->SetLogy();
0997       p->SetGridx(0);
0998       p->SetGridy(0);
0999 
1000       TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(log_scale ? "_Log" : "");
1001 
1002       TH1 *h = NULL;
1003 
1004       if (log_scale)
1005         h = new TH1F(hname,
1006                      Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 300,
1007                      5e-3, 3096);
1008       else
1009         //            h = new TH1F(hname,
1010         //                Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 196,
1011         //                1900, 2096);
1012         h = new TH1F(hname,
1013                      Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 596,
1014                      -96, 500);
1015 
1016       h->SetLineWidth(0);
1017       h->SetLineColor(kBlue + 3);
1018       h->SetFillColor(kBlue + 3);
1019       h->GetXaxis()->SetTitleSize(.09);
1020       h->GetXaxis()->SetLabelSize(.08);
1021       h->GetYaxis()->SetLabelSize(.08);
1022 
1023       if (log_scale)
1024         QAHistManagerDef::useLogBins(h->GetXaxis());
1025 
1026       T->Draw(
1027           "TOWER_" + gain + "_CEMC[].get_energy_power_law_exp()>>" + hname,
1028           Form(
1029               "TOWER_%s_CEMC[].get_bineta()==%d && TOWER_%s_CEMC[].get_binphi()==%d",
1030               gain.Data(), ieta, gain.Data(), iphi),
1031           "");
1032 
1033       TText *t = new TText(.9, .9, Form("Col%d Row%d", ieta, iphi));
1034       t->SetTextAlign(33);
1035       t->SetTextSize(.15);
1036       t->SetNDC();
1037       t->Draw();
1038 
1039       //          return;
1040     }
1041   }
1042 
1043   SaveCanvas(c1,
1044              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
1045 }
1046 
1047 void EMCDistribution_ADC(bool log_scale = true)
1048 {
1049   TString gain = "RAW";
1050 
1051   TText *t;
1052   TCanvas *c1 = new TCanvas(
1053       "EMCDistribution_ADC_" + gain + TString(log_scale ? "_Log" : "") + cuts,
1054       "EMCDistribution_ADC_" + gain + TString(log_scale ? "_Log" : "") + cuts,
1055       1800, 1000);
1056   c1->Divide(8, 8, 0., 0.01);
1057   int idx = 1;
1058   TPad *p;
1059 
1060   for (int iphi = 8 - 1; iphi >= 0; iphi--)
1061   {
1062     for (int ieta = 0; ieta < 8; ieta++)
1063     {
1064       p = (TPad *) c1->cd(idx++);
1065       c1->Update();
1066 
1067       if (log_scale)
1068       {
1069         p->SetLogz();
1070       }
1071       p->SetGridx(0);
1072       p->SetGridy(0);
1073 
1074       TString hname = Form("hEnergy_ieta%d_iphi%d", ieta, iphi) + TString(log_scale ? "_Log" : "");
1075 
1076       TH1 *h = NULL;
1077 
1078       if (log_scale)
1079         h = new TH2F(hname,
1080                      Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 24, -.5,
1081                      23.5,
1082                      //                128+64, 0, 3096);
1083                      4098, -1, 4097);
1084       //          else
1085       //            h = new TH2F(hname,
1086       //                Form(";Calibrated Tower Energy Sum (GeV);Count / bin"), 100,
1087       //                -.050, .5,128,0,2048);
1088 
1089       h->SetLineWidth(0);
1090       h->SetLineColor(kBlue + 3);
1091       h->SetFillColor(kBlue + 3);
1092       h->GetXaxis()->SetTitleSize(.09);
1093       h->GetXaxis()->SetLabelSize(.08);
1094       h->GetYaxis()->SetLabelSize(.08);
1095       h->GetYaxis()->SetRangeUser(0, 4096);
1096 
1097       //          if (log_scale)
1098       //            QAHistManagerDef::useLogBins(h->GetYaxis());
1099 
1100       TString sdraw = "TOWER_" + gain + "_CEMC[].signal_samples[]:fmod(Iteration$,24)>>" + hname;
1101       TString scut =
1102           Form(
1103               "TOWER_%s_CEMC[].get_bineta()==%d && TOWER_%s_CEMC[].get_binphi()==%d",
1104               gain.Data(), ieta, gain.Data(), iphi);
1105 
1106       cout << "T->Draw(\"" << sdraw << "\",\"" << scut << "\");" << endl;
1107 
1108       T->Draw(sdraw, scut, "colz");
1109 
1110       TText *t = new TText(.9, .9, Form("Col%d Row%d", ieta, iphi));
1111       t->SetTextAlign(33);
1112       t->SetTextSize(.15);
1113       t->SetNDC();
1114       t->Draw();
1115 
1116       //          return;
1117     }
1118   }
1119 
1120   SaveCanvas(c1,
1121              TString(_file0->GetName()) + TString("_DrawPrototype3EMCalTower_") + TString(c1->GetName()), false);
1122 }