Back to home page

sPhenix code displayed by LXR

 
 

    


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

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