Back to home page

sPhenix code displayed by LXR

 
 

    


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

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