Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:05

0001 #include "HitCountNtuple.h"
0002 
0003 #include <g4main/PHG4HitContainer.h>
0004 #include <g4main/PHG4Hit.h>
0005 
0006 #include <fun4all/Fun4AllHistoManager.h>
0007 
0008 #include <phool/getClass.h>
0009 
0010 #include <TFile.h>
0011 #include <TH1.h>
0012 #include <TH2.h>
0013 #include <TNtuple.h>
0014 
0015 #include <boost/foreach.hpp>
0016 
0017 #include<sstream>
0018 
0019 using namespace std;
0020 
0021 HitCountNtuple::HitCountNtuple(const std::string &name, const std::string &filename):
0022   SubsysReco( name ),
0023   nblocks(0),
0024   hm(NULL),
0025   _filename(filename),
0026   ntup(NULL),
0027   outfile(NULL)
0028 {}
0029 
0030 HitCountNtuple::~HitCountNtuple()
0031 {
0032   //  delete ntup;
0033   delete hm;
0034 } 
0035 
0036 
0037 int
0038 HitCountNtuple::Init( PHCompositeNode* )
0039 {
0040   ostringstream hname, htit;
0041   hm = new  Fun4AllHistoManager(Name());
0042   outfile = new TFile(_filename.c_str(), "RECREATE");
0043   //ntup = new TNtuple("hitntup", "G4Hits", "detid:layer:x0:y0:z0:x1:y1:z1:edep");
0044   ntupe = new TNtuple("hitcnt", "NHits", "cemc:cemc_abs:ihcal:ihcal_abs:ohcal:ohcal_abs");
0045  //  ntup->SetDirectory(0);
0046   return 0;
0047 }
0048 
0049 int
0050 HitCountNtuple::process_event( PHCompositeNode* topNode )
0051 {
0052   set<string>::const_iterator iter;
0053   vector<TH1 *>::const_iterator eiter;
0054   float ntvar[6]={0};
0055   PHG4HitContainer *hits = nullptr;
0056   string nodename[6] = {"G4HIT_CEMC", "G4HIT_ABSORBER_CEMC",
0057             "G4HIT_HCALIN", "G4HIT_ABSORBER_HCALIN",
0058             "G4HIT_HCALOUT", "G4HIT_ABSORBER_HCALOUT"};
0059 
0060   for (int i=0; i<6; i++)
0061   {
0062   hits = findNode::getClass<PHG4HitContainer>(topNode,nodename[i]);
0063 
0064   if (hits)
0065     {
0066       //          double numhits = hits->size();
0067       //          nhits[i]->Fill(numhits);
0068       ntvar[i] = hits->size();
0069     }
0070   }
0071   ntupe->Fill(ntvar);
0072   return 0;
0073 }
0074 
0075 int
0076 HitCountNtuple::End(PHCompositeNode * topNode)
0077 {
0078   outfile->cd();
0079   //  ntup->Write();
0080   ntupe->Write();
0081   outfile->Write();
0082   outfile->Close();
0083   delete outfile;
0084   hm->dumpHistos(_filename, "UPDATE");
0085   return 0;
0086 }
0087 
0088 void
0089 HitCountNtuple::AddNode(const std::string &name, const int detid)
0090 {
0091  _node_postfix.insert(name);
0092  _detid[name] = detid;
0093  return;
0094 }