Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mbdAnalysis.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file mbdAnalysis.cc
1 //#include <bbc/BbcPmtContainerV1.h>
2 //#include <bbc/BbcGeom.h>
3 #include <bbc/MbdOut.h>
4 #include <bbc/MbdPmtContainer.h>
5 #include <bbc/MbdGeom.h>
6 #include <bbc/MbdPmtHit.h>
7 #include <phool/getClass.h>
8 
10 
11 //Fun4All
13 #include <fun4all/Fun4AllServer.h>
15 #include <phool/PHCompositeNode.h>
16 #include <phool/getClass.h>
17 #include <phool/phool.h>
18 #include <ffaobjects/EventHeader.h>
19 
20 //ROOT stuff
21 #include <TH1F.h>
22 #include <TH2F.h>
23 #include <TH3F.h>
24 #include <TFile.h>
25 #include <TLorentzVector.h>
26 #include <TTree.h>
27 
28 #include "mbdAnalysis.h"
29 
31 
32 #include <phool/PHCompositeNode.h>
33 
34 //____________________________________________________________________________..
36  SubsysReco(name)
37 {
38  std::cout << "mbdAnalysis::mbdAnalysis(const std::string &name) Calling ctor" << std::endl;
39 }
40 
41 //____________________________________________________________________________..
43 {
44  std::cout << "mbdAnalysis::~mbdAnalysis() Calling dtor" << std::endl;
45 }
46 
47 //____________________________________________________________________________..
49 {
50 
51  out = new TFile("output.root","RECREATE");
52 
53  T = new TTree("T","T");
54 // T -> Branch("adc",&adc);
55 // T -> Branch("tdc0",&tdc0);
56 // T -> Branch("tdc1",&tdc1);
57  T -> Branch("pmtcharge",&pmtcharge);
58  T -> Branch("pmttime",&pmttime);
59  T -> Branch("pmtx",&pmtx);
60  T -> Branch("pmty",&pmty);
61  T -> Branch("pmtz",&pmtz);
62  T -> Branch("pmtr",&pmtr);
63  T -> Branch("pmtphi",&pmtphi);
64 
65 
66 
68 }
69 
70 //____________________________________________________________________________..
72 {
73  std::cout << "mbdAnalysis::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
75 }
76 
77 //____________________________________________________________________________..
79 {
80 
81  //tower information
82  //mbdinfo
83  //these two lines copied directly from wiki:
84  //PHNodeIterator iter(topNode);
85  //PHCompositeNode *mbdNode = dynamic_cast<PHCompositeNode *>(iter.findFirst("PHCompositeNode", "MBD"));
86  //MbdOut *mbdout = findNode::getClass<MbdOut>(mbdNode, "MbdOut");
87 
88  MbdPmtContainer *mbdpmts = findNode::getClass<MbdPmtContainer>(topNode,"MbdPmtContainer"); // mbd info
89  if(!mbdpmts)
90  {
91  std::cout << "makeMBDTrees::process_event: Could not find MbdPmtContainer, aborting" << std::endl;
93  }
94 
95  //MbdGeom *mbdGeom = new MbdGeom();
96  MbdGeom *mbdgeom = findNode::getClass<MbdGeom>(topNode, "MbdGeom");
97 
98 
99 
100 
101  int nPMTs = mbdpmts -> get_npmt(); //size (should always be 128)
102  for(int i = 0; i < nPMTs; i++)
103  {
104  //short pmtID = mbdTowerContainer -> get_pmt(i);
105  MbdPmtHit* mbdpmt = mbdpmts -> get_pmt(i); // grab 1 pmt (changed from pmtID)
106 
107  //float pmtadc = mbdpmts -> get_adc(i); // grab adc from the ith pmt in mbdpmts
108  //std::cout << "adc for tower i: " << i << " is: " <<pmtadc << std::endl;
109 
110  // pmtadc = mbdpmts -> get_adc(mbdpmt);
111  //std::cout << "adc for tower mbdpmt: " << mbdpmt << " is: " <<pmtadc << std::endl;
112  //int pmtch = mbdpmt->get_pmtch(); //pmt charge
113  float charge = mbdpmt->get_q(); //pmt charge
114  float time = mbdpmt->get_time(); //pmt charge
115  //std::cout << " pmt channel number: " << pmtch << "; pmtcharge: " << charge <<"; pmttime: "<< time << std::endl;
116 
117  pmttime.push_back(charge);
118  pmtcharge.push_back(time);
119  /*
120  adc.push_back(pmtadc);
121  float pmttdc0 = mbdpmts -> get_tdc0(i);
122  std::cout << "pmttdc0: " << pmttdc0 << std::endl;
123  tdc0.push_back(pmttdc0);
124  float pmttdc1 = mbdpmts -> get_tdc1(i);
125  tdc1.push_back(pmttdc1);
126 */
127 // according to the wiki https://wiki.sphenix.bnl.gov/index.php/MBD_DST_Output these should be get_x(i) rather tahn
128 // get_x(mbdpmt
129  pmtx.push_back(mbdgeom->get_x(i));
130  pmty.push_back(mbdgeom->get_y(i));
131  pmtz.push_back(mbdgeom->get_z(i));
132  pmtr.push_back(mbdgeom->get_r(i));
133  pmtphi.push_back(mbdgeom->get_phi(i));
134 
135  std::cout << "phi angle of pmt is mbdgeom->get_phi(i)): " << mbdgeom->get_phi(i) << std::endl;
136  }
137 
138  T -> Fill();
139 
140 
142 }
143 
144 //____________________________________________________________________________..
146 {
147  std::cout << "mbdAnalysis::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
149 }
150 
151 //____________________________________________________________________________..
152 int mbdAnalysis::EndRun(const int runnumber)
153 {
154  std::cout << "mbdAnalysis::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
156 }
157 
158 //____________________________________________________________________________..
159 int mbdAnalysis::End(PHCompositeNode *topNode)
160 {
161  std::cout << "mbdAnalysis::End(PHCompositeNode *topNode) This is the End..." << std::endl;
162  out -> cd();
163  T -> Write();
164  out -> Close();
166 }
167 
168 //____________________________________________________________________________..
170 {
171  // adc.clear();
172  //tdc0.clear();
173  //tdc1.clear();
174  pmtcharge.clear();
175  pmttime.clear();
176  pmtx.clear();
177  pmty.clear();
178  pmtz.clear();
179  pmtr.clear();
180  pmtphi.clear();
181 
182 
184 }
185 
186 //____________________________________________________________________________..
187 void mbdAnalysis::Print(const std::string &what) const
188 {
189  std::cout << "mbdAnalysis::Print(const std::string &what) const Printing info for " << what << std::endl;
190 }