int
QAG4SimulationCalorimeter::Init_Tower(PHCompositeNode *topNode)
{

  Fun4AllHistoManager *hm = QAHistManagerDef::getHistoManager();
  assert(hm);

  TH1F *h = new TH1F(TString(get_histo_prefix()) + "_Tower_1x1", //
  TString(_calo_name) + " 1x1 tower;1x1 TOWER Energy (GeV)", 100, 9e-4, 100);
  QAHistManagerDef::useLogBins(h->GetXaxis());
  hm->registerHisto(h);

  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_Tower_1x1_max", //
          TString(_calo_name)
              + " 1x1 tower max per event;1x1 tower max per event (GeV)", 5000,
          0, 50));

  h = new TH1F(TString(get_histo_prefix()) + "_Tower_2x2", //
  TString(_calo_name) + " 2x2 tower;2x2 TOWER Energy (GeV)", 100, 9e-4, 100);
  QAHistManagerDef::useLogBins(h->GetXaxis());
  hm->registerHisto(h);
  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_Tower_2x2_max", //
          TString(_calo_name)
              + " 2x2 tower max per event;2x2 tower max per event (GeV)", 5000,
          0, 50));

  h = new TH1F(TString(get_histo_prefix()) + "_Tower_3x3", //
  TString(_calo_name) + " 3x3 tower;3x3 TOWER Energy (GeV)", 100, 9e-4, 100);
  QAHistManagerDef::useLogBins(h->GetXaxis());
  hm->registerHisto(h);
  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_Tower_3x3_max", //
          TString(_calo_name)
              + " 3x3 tower max per event;3x3 tower max per event (GeV)", 5000,
          0, 50));

  h = new TH1F(TString(get_histo_prefix()) + "_Tower_4x4", //
  TString(_calo_name) + " 4x4 tower;4x4 TOWER Energy (GeV)", 100, 9e-4, 100);
  QAHistManagerDef::useLogBins(h->GetXaxis());
  hm->registerHisto(h);
  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_Tower_4x4_max", //
          TString(_calo_name)
              + " 4x4 tower max per event;4x4 tower max per event (GeV)", 5000,
          0, 50));

  h = new TH1F(TString(get_histo_prefix()) + "_Tower_5x5", //
  TString(_calo_name) + " 5x5 tower;5x5 TOWER Energy (GeV)", 100, 9e-4, 100);
  QAHistManagerDef::useLogBins(h->GetXaxis());
  hm->registerHisto(h);
  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_Tower_5x5_max", //
          TString(_calo_name)
              + " 5x5 tower max per event;5x5 tower max per event (GeV)", 5000,
          0, 50));

  return Fun4AllReturnCodes::EVENT_OK;
}
int
Proto2ShowerCalib::Init(PHCompositeNode *topNode)
{

  _ievent = 0;

  cout << "Proto2ShowerCalib::get_HistoManager - Making PHTFileServer "
      << _filename << endl;
  PHTFileServer::get().open(_filename, "RECREATE");

  fdata.open(_filename + ".dat", std::fstream::out);

  Fun4AllHistoManager *hm = get_HistoManager();
  assert(hm);

  TH2F * hCheck_Cherenkov = new TH2F("hCheck_Cherenkov", "hCheck_Cherenkov",
      1000, -2000, 2000, 5, .5, 5.5);
  hCheck_Cherenkov->GetYaxis()->SetBinLabel(1, "C1");
  hCheck_Cherenkov->GetYaxis()->SetBinLabel(2, "C2 in");
  hCheck_Cherenkov->GetYaxis()->SetBinLabel(3, "C2 out");
  hCheck_Cherenkov->GetYaxis()->SetBinLabel(4, "C2 sum");
  hm->registerHisto(hCheck_Cherenkov);

  TH1F * hNormalization = new TH1F("hNormalization", "hNormalization", 10, .5,
      10.5);
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(1, "ALL");
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(2, "C2-e");
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(3, "C2-h");
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(4, "trigger_veto_pass");
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(5, "valid_hodo_h");
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(6, "valid_hodo_v");
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(7, "good_e");
  hCheck_Cherenkov->GetXaxis()->SetBinLabel(8, "good_h");
  hm->registerHisto(hNormalization);

  hm->registerHisto(new TH1F("hCheck_Veto", "hCheck_Veto", 1000, -500, 500));
  hm->registerHisto(
      new TH1F("hCheck_Hodo_H", "hCheck_Hodo_H", 1000, -500, 500));
  hm->registerHisto(
      new TH1F("hCheck_Hodo_V", "hCheck_Hodo_V", 1000, -500, 500));

  hm->registerHisto(new TH1F("hBeam_Mom", "hBeam_Mom", 1200, -120, 120));

  hm->registerHisto(new TH2F("hEoP", "hEoP", 1000, 0, 1.5, 120, .5, 120.5));

  hm->registerHisto(new TH1F("hTemperature", "hTemperature", 500, 0, 50));

  // help index files with TChain
  TTree * T = new TTree("T", "T");
  assert(T);
  hm->registerHisto(T);

  T->Branch("info", &_eval_run);
  T->Branch("shower", &_shower);
  if(_fill_time_samples) T->Branch("time", &_time_samples);  

  return Fun4AllReturnCodes::EVENT_OK;
}
int
QAG4SimulationCalorimeter::Init_G4Hit(PHCompositeNode *topNode)
{

  Fun4AllHistoManager *hm = QAHistManagerDef::getHistoManager();
  assert(hm);

  hm->registerHisto(
      new TH2F(TString(get_histo_prefix()) + "_G4Hit_RZ", //
      TString(_calo_name) + " RZ projection;Z (cm);R (cm)", 1200, -300, 300,
          600, -000, 300));

  hm->registerHisto(
      new TH2F(TString(get_histo_prefix()) + "_G4Hit_XY", //
      TString(_calo_name) + " XY projection;X (cm);Y (cm)", 1200, -300, 300,
          1200, -300, 300));

  hm->registerHisto(
      new TH2F(TString(get_histo_prefix()) + "_G4Hit_LateralTruthProjection", //
          TString(_calo_name)
              + " shower lateral projection (last primary);Polar direction (cm);Azimuthal direction (cm)",
          200, -30, 30, 200, -30, 30));

  hm->registerHisto(new TH1F(TString(get_histo_prefix()) + "_G4Hit_SF", //
  TString(_calo_name) + " sampling fraction;Sampling fraction", 1000, 0, .2));

  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_G4Hit_VSF", //
          TString(_calo_name)
              + " visible sampling fraction;Visible sampling fraction", 1000, 0,
          .2));

  TH1F * h =
      new TH1F(TString(get_histo_prefix()) + "_G4Hit_HitTime", //
          TString(_calo_name)
              + " hit time (edep weighting);Hit time - T0 (ns);Geant4 energy density",
          1000, 0.5, 10000);
  QAHistManagerDef::useLogBins(h->GetXaxis());
  hm->registerHisto(h);

  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_G4Hit_FractionTruthEnergy", //
          TString(_calo_name)
              + " fraction truth energy ;G4 energy (active + absorber) / total truth energy",
          1000, 0, 1));

  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_G4Hit_FractionEMVisibleEnergy", //
          TString(_calo_name)
              + " fraction visible energy from EM; visible energy from e^{#pm} / total visible energy",
          100, 0, 1));

  return Fun4AllReturnCodes::EVENT_OK;
}
int
QAG4SimulationCalorimeter::Init_Cluster(PHCompositeNode *topNode)
{

  Fun4AllHistoManager *hm = QAHistManagerDef::getHistoManager();
  assert(hm);

  hm->registerHisto(
      new TH1F(TString(get_histo_prefix()) + "_Cluster_BestMatchERatio", //
          TString(_calo_name)
              + " best matched cluster E/E_{Truth};E_{Cluster}/E_{Truth}", 150,
          0, 1.5));

  hm->registerHisto(
      new TH2F(TString(get_histo_prefix()) + "_Cluster_LateralTruthProjection", //
          TString(_calo_name)
              + " best cluster lateral projection (last primary);Polar direction (cm);Azimuthal direction (cm)",
          200, -15, 15, 200, -15, 15));

  return Fun4AllReturnCodes::EVENT_OK;
}
int
QAG4SimulationCalorimeter::Init(PHCompositeNode *topNode)
{

  Fun4AllHistoManager *hm = QAHistManagerDef::getHistoManager();
  assert(hm);
  TH1D * h = new TH1D(TString(get_histo_prefix()) + "_Normalization", //
  TString(_calo_name) + " Normalization;Items;Count", 10, .5, 10.5);
  int i = 1;
  h->GetXaxis()->SetBinLabel(i++, "Event");
  h->GetXaxis()->SetBinLabel(i++, "G4Hit Active");
  h->GetXaxis()->SetBinLabel(i++, "G4Hit Absor.");
  h->GetXaxis()->SetBinLabel(i++, "Tower");
  h->GetXaxis()->SetBinLabel(i++, "Tower Hit");
  h->GetXaxis()->SetBinLabel(i++, "Cluster");
  h->GetXaxis()->LabelsOption("v");
  hm->registerHisto(h);

  if (flag(kProcessG4Hit))
    {

      if (verbosity >= 1)
        cout << "QAG4SimulationCalorimeter::Init - Process sampling fraction"
            << endl;
      Init_G4Hit(topNode);
    }
  if (flag(kProcessTower))
    {
      if (verbosity >= 1)
        cout << "QAG4SimulationCalorimeter::Init - Process tower occupancies"
            << endl;
      Init_Tower(topNode);
    }
  if (flag(kProcessCluster))
    {
      if (verbosity >= 1)
        cout << "QAG4SimulationCalorimeter::Init - Process tower occupancies"
            << endl;
      Init_Cluster(topNode);
    }

  return Fun4AllReturnCodes::EVENT_OK;
}