Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AnaRealDst.cc
Go to the documentation of this file.
1 #include <iomanip>
2 #include <TFile.h>
3 #include <TTree.h>
4 #include <TH1D.h>
5 #include <TCanvas.h>
6 #include <interface_main/SQRun.h>
10 #include <phool/PHNodeIterator.h>
11 #include <phool/PHIODataNode.h>
12 #include <phool/getClass.h>
13 #include <geom_svc/GeomSvc.h>
14 #include <UtilAna/UtilSQHit.h>
15 #include "AnaRealDst.h"
16 using namespace std;
17 
18 const vector<string> AnaRealDst::list_det_name = { "H1T", "H1B", "H2T", "H2B" };
19 
21 {
23 }
24 
26 {
27  f_out = new TFile("output.root", "RECREATE");
28  tree = new TTree("tree", "Created by AnaRealDst");
29  tree->Branch("det_name", &b_det_name, "det_name/C");
30  tree->Branch("det" , &b_det , "det/I");
31  tree->Branch("ele" , &b_ele , "ele/I");
32  tree->Branch("time" , &b_time , "time/D");
33 
34  ostringstream oss;
35  GeomSvc* geom = GeomSvc::instance();
36  for (unsigned int i_det = 0; i_det < list_det_name.size(); i_det++) {
37  string name = list_det_name[i_det];
38  int id = geom->getDetectorID(name);
39  if (id <= 0) {
40  cerr << "!ERROR! AnaRealDst::InitRun(): Invalid ID (" << id << "). Probably the detector name that you specified in 'list_det_name' (" << name << ") is not valid. Abort." << endl;
41  exit(1);
42  }
43  list_det_id.push_back(id);
44  int n_ele = geom->getPlaneNElements(id);
45  cout << " " << setw(6) << name << " = " << id << endl;
46 
47  oss.str("");
48  oss << "h1_ele_" << name;
49  h1_ele[i_det] = new TH1D(oss.str().c_str(), "", n_ele, 0.5, n_ele+0.5);
50  oss.str("");
51  oss << name << ";Element ID;Hit count";
52  h1_ele[i_det]->SetTitle(oss.str().c_str());
53 
54  oss.str("");
55  oss << "h1_nhit_" << name;
56  h1_nhit[i_det] = new TH1D(oss.str().c_str(), "", 10, -0.5, 9.5);
57  oss.str("");
58  oss << name << ";N of hits/plane/event;Hit count";
59  h1_nhit[i_det]->SetTitle(oss.str().c_str());
60  }
61 
63 }
64 
66 {
67  SQEvent* event = findNode::getClass<SQEvent >(topNode, "SQEvent");
68  SQHitVector* hit_vec = findNode::getClass<SQHitVector>(topNode, "SQHitVector");
69  if (!event || !hit_vec) return Fun4AllReturnCodes::ABORTEVENT;
70  //int spill_id = event->get_spill_id();
71  //int event_id = event->get_event_id();
72 
76  if (! event->get_trigger(SQEvent::NIM2)) {
78  }
79 
80  static int did_h3t = 0;
81  static int did_h3b = 0;
82  if (did_h3t == 0) {
83  GeomSvc* geom = GeomSvc::instance();
84  did_h3t = geom->getDetectorID("H3T");
85  did_h3b = geom->getDetectorID("H3B");
86  cout << "H3T = " << did_h3t << ", H3B = " << did_h3b << endl;
87  }
88 
89  shared_ptr<SQHitVector> hv_h3t(UtilSQHit::FindHits(hit_vec, did_h3t));
90  shared_ptr<SQHitVector> hv_h3b(UtilSQHit::FindHits(hit_vec, did_h3b));
91  if (hv_h3t->size() + hv_h3b->size() != 1) return Fun4AllReturnCodes::EVENT_OK;
92 
96  for (unsigned int i_det = 0; i_det < list_det_name.size(); i_det++) {
97  strncpy(b_det_name, list_det_name[i_det].c_str(), sizeof(b_det_name));
98  b_det = list_det_id[i_det];
99  shared_ptr<SQHitVector> hv(UtilSQHit::FindHits(hit_vec, b_det));
100  for (SQHitVector::ConstIter it = hv->begin(); it != hv->end(); it++) {
101  b_ele = (*it)->get_element_id();
102  b_time = (*it)->get_tdc_time ();
103  tree->Fill();
104 
105  h1_ele[i_det]->Fill(b_ele);
106  }
107  h1_nhit[i_det]->Fill(hv->size());
108  }
109 
111 }
112 
114 {
115  ostringstream oss;
116  TCanvas* c1 = new TCanvas("c1", "");
117  c1->SetGrid();
118  for (unsigned int i_det = 0; i_det < list_det_id.size(); i_det++) {
119  h1_ele[i_det]->Draw();
120  oss.str("");
121  oss << h1_ele[i_det]->GetName() << ".png";
122  c1->SaveAs(oss.str().c_str());
123 
124  h1_nhit[i_det]->Draw();
125  oss.str("");
126  oss << h1_nhit[i_det]->GetName() << ".png";
127  c1->SaveAs(oss.str().c_str());
128  }
129  delete c1;
130 
131  f_out->cd();
132  f_out->Write();
133  f_out->Close();
134 
136 }
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
int End(PHCompositeNode *topNode)
Called at the end of all processing.
Definition: AnaRealDst.cc:113
int Init(PHCompositeNode *topNode)
Definition: AnaRealDst.cc:20
int InitRun(PHCompositeNode *topNode)
Definition: AnaRealDst.cc:25
An SQ interface class to hold a list of SQHit objects.
Definition: SQHitVector.h:32
An SQ interface class to hold one event header.
Definition: SQEvent.h:17
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:211
int getDetectorID(const std::string &detectorName) const
Get the plane position.
Definition: GeomSvc.h:184
int process_event(PHCompositeNode *topNode)
Definition: AnaRealDst.cc:65
int getPlaneNElements(int detectorID)
Definition: GeomSvc.h:208
SQHitVector * FindHits(const SQHitVector *vec_in, const std::string det_name)
Extract a set of hits that are of the given detector (det_name).
Definition: UtilSQHit.cc:15
TCanvas * c1
Definition: Fun4SimTree.C:5