Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OnlMonHodo.cc
Go to the documentation of this file.
1 #include <iomanip>
3 #include <TH1D.h>
4 #include <TH2D.h>
5 #include <TProfile.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/UtilHist.h>
15 #include "OnlMonServer.h"
16 #include "OnlMonHodo.h"
17 using namespace std;
18 
19 OnlMonHodo::OnlMonHodo(const HodoType_t type) : m_type(type)
20 {
21  NumCanvases(2);
22  switch (m_type) {
23  case H1X: Name("OnlMonHodoH1X" ); Title("Hodo: H1X" ); break;
24  case H2X: Name("OnlMonHodoH2X" ); Title("Hodo: H2X" ); break;
25  case H3X: Name("OnlMonHodoH3X" ); Title("Hodo: H3X" ); break;
26  case H4X: Name("OnlMonHodoH4X" ); Title("Hodo: H4X" ); break;
27  case H1Y: Name("OnlMonHodoH1Y" ); Title("Hodo: H1Y" ); break;
28  case H2Y: Name("OnlMonHodoH2Y" ); Title("Hodo: H2Y" ); break;
29  case H4Y1: Name("OnlMonHodoH4Y1"); Title("Hodo: H4Y1"); break;
30  case H4Y2: Name("OnlMonHodoH4Y2"); Title("Hodo: H4Y2"); break;
31  case DP1T: Name("OnlMonHodoDP1T"); Title("Hodo: DP1T"); break;
32  case DP1B: Name("OnlMonHodoDP1B"); Title("Hodo: DP1B"); break;
33  case DP2T: Name("OnlMonHodoDP2T"); Title("Hodo: DP2T"); break;
34  case DP2B: Name("OnlMonHodoDP2B"); Title("Hodo: DP2B"); break;
35  }
36 }
37 
39 {
41 }
42 
44 {
45  const double DT = 20/9.0; // 4/9 ns per single count of Taiwan TDC
46  int NT = 700;
47  double T0 = 200.5*DT;
48  double T1 = 900.5*DT;
49  switch (m_type) {
50  case H1X: SetDet("H1T" ,"H1B" ); break;
51  case H2X: SetDet("H2T" ,"H2B" ); break;
52  case H3X: SetDet("H3T" ,"H3B" ); break;
53  case H4X: SetDet("H4T" ,"H4B" ); break;
54  case H1Y: SetDet("H1L" ,"H1R" ); break;
55  case H2Y: SetDet("H2L" ,"H2R" ); break;
56  case H4Y1: SetDet("H4Y1L","H4Y1R"); break;
57  case H4Y2: SetDet("H4Y2L","H4Y2R"); break;
58  case DP1T: SetDet("DP1TL","DP1TR"); break;
59  case DP1B: SetDet("DP1BL","DP1BR"); break;
60  case DP2T: SetDet("DP2TL","DP2TR"); break;
61  case DP2B: SetDet("DP2BL","DP2BR"); break;
62 // case DP1T: SetDet("DP1TL","DP1TR"); NT=200; T0=300.5*DT; T1=500.5*DT; break;
63 // case DP1B: SetDet("DP1BL","DP1BR"); NT=200; T0=300.5*DT; T1=500.5*DT; break;
64 // case DP2T: SetDet("DP2TL","DP2TR"); NT=200; T0=300.5*DT; T1=500.5*DT; break;
65 // case DP2B: SetDet("DP2BL","DP2BR"); NT=200; T0=300.5*DT; T1=500.5*DT; break;
66  }
67 
68  GeomSvc* geom = GeomSvc::instance();
69  ostringstream oss;
70  for (unsigned int i_det = 0; i_det < N_DET; i_det++) {
71  string name = list_det_name[i_det];
72  int det_id = list_det_id [i_det];
73  int n_ele = geom->getPlaneNElements(det_id);
74  if (det_id <= 0 || n_ele <= 0) {
75  cout << "OnlMonHodo::InitRunOnlMon(): Invalid det_id or n_ele: "
76  << det_id << " " << n_ele << " at name = " << name << "." << endl;
78  }
79 
80  oss.str("");
81  oss << "h1_ele_" << i_det;
82  h1_ele[i_det] = new TH1D(oss.str().c_str(), "", n_ele, 0.5, n_ele+0.5);
83  oss.str("");
84  oss << name << ";Element ID;Hit count";
85  h1_ele[i_det]->SetTitle(oss.str().c_str());
86 
87  oss.str("");
88  oss << "h1_ele_in_" << i_det;
89  h1_ele_in[i_det] = new TH1D(oss.str().c_str(), "", n_ele, 0.5, n_ele+0.5);
90  oss.str("");
91  oss << name << ";Element ID;In-time hit count";
92  h1_ele_in[i_det]->SetTitle(oss.str().c_str());
93 
94  oss.str("");
95  oss << "h1_time_" << i_det;
96  h1_time[i_det] = new TH1D(oss.str().c_str(), "", NT, T0, T1);
97  oss.str("");
98  oss << name << ";tdcTime;Hit count";
99  h1_time[i_det]->SetTitle(oss.str().c_str());
100 
101  oss.str("");
102  oss << "h1_time_in_" << i_det;
103  h1_time_in[i_det] = new TH1D(oss.str().c_str(), "", NT, T0, T1);
104  oss.str("");
105  oss << name << ";tdcTime;In-time hit count";
106  h1_time_in[i_det]->SetTitle(oss.str().c_str());
107 
108  oss.str("");
109  oss << "h2_time_ele_" << i_det;
110  h2_time_ele[i_det] = new TH2D(oss.str().c_str(), "", n_ele, 0.5, n_ele+0.5, NT, T0, T1);
111  oss.str("");
112  oss << name << ";Element ID;tdcTime;Hit count";
113  h2_time_ele[i_det]->SetTitle(oss.str().c_str());
114 
115  RegisterHist(h1_ele [i_det]);
116  RegisterHist(h1_ele_in [i_det]);
117  RegisterHist(h1_time [i_det]);
118  RegisterHist(h1_time_in [i_det]);
119  RegisterHist(h2_time_ele[i_det]);
120  }
121 
123 }
124 
126 {
127  SQEvent* event_header = findNode::getClass<SQEvent >(topNode, "SQEvent");
128  SQHitVector* hit_vec = findNode::getClass<SQHitVector>(topNode, "SQHitVector");
129  if (!event_header || !hit_vec) return Fun4AllReturnCodes::ABORTEVENT;
130 
131  for (SQHitVector::ConstIter it = hit_vec->begin(); it != hit_vec->end(); it++) {
132  int det_id = (*it)->get_detector_id();
133  for (int i_det = 0; i_det < N_DET; i_det++) {
134  if (list_det_id[i_det] != det_id) continue;
135  int ele = (*it)->get_element_id();
136  double time = (*it)->get_tdc_time ();
137  h1_ele [i_det]->Fill(ele );
138  h1_time [i_det]->Fill(time);
139  h2_time_ele[i_det]->Fill(ele, time);
140  if ((*it)->is_in_time()) {
141  h1_ele_in [i_det]->Fill(ele );
142  h1_time_in[i_det]->Fill(time);
143  }
144  }
145  }
146 
148 }
149 
151 {
153 }
154 
156 {
157  ostringstream oss;
158  for (int i_det = 0; i_det < N_DET; i_det++) {
159  oss.str("");
160  oss << "h1_ele_" << i_det;
161  h1_ele[i_det] = FindMonHist(oss.str().c_str());
162  if (! h1_ele[i_det]) return 1;
163  oss.str("");
164  oss << "h1_ele_in_" << i_det;
165  h1_ele_in[i_det] = FindMonHist(oss.str().c_str());
166  if (! h1_ele_in[i_det]) return 1;
167  oss.str("");
168  oss << "h1_time_" << i_det;
169  h1_time[i_det] = FindMonHist(oss.str().c_str());
170  if (! h1_time[i_det]) return 1;
171  oss.str("");
172  oss << "h1_time_in_" << i_det;
173  h1_time_in[i_det] = FindMonHist(oss.str().c_str());
174  if (! h1_time_in[i_det]) return 1;
175  oss.str("");
176  oss << "h2_time_ele_" << i_det;
177  h2_time_ele[i_det] = (TH2*)FindMonHist(oss.str().c_str());
178  if (! h2_time_ele[i_det]) return 1;
179  }
180  return 0;
181 }
182 
184 {
185  OnlMonCanvas* can0 = GetCanvas(0);
187  TPad* pad0 = can0->GetMainPad();
188  pad0->SetGrid();
189  pad0->Divide(2, 2);
190  bool empty_ele = false;
191  for (int i_det = 0; i_det < N_DET; i_det++) {
192  pad0->cd(2*i_det+1);
193  h1_ele[i_det]->SetLineColor(kBlack);
194  h1_ele[i_det]->Draw();
195  h1_ele_in[i_det]->SetLineColor(kBlue);
196  h1_ele_in[i_det]->SetFillColor(kBlue-7);
197  h1_ele_in[i_det]->Draw("same");
198  if (h1_ele[i_det]->GetMinimum() == 0) empty_ele = true;
199 
200  pad0->cd(2*i_det+2);
201  UtilHist::AutoSetRangeY(h2_time_ele[i_det]);
202  h2_time_ele[i_det]->Draw("colz");
203  ostringstream oss;
204  oss << "pr_" << h2_time_ele[i_det]->GetName();
205  TProfile* pr = h2_time_ele[i_det]->ProfileX(oss.str().c_str()); // , 1, -1, "s");
206  pr->SetLineColor(kBlack);
207  pr->Draw("E1same");
208  }
209  if (empty_ele) {
211  can0->AddMessage("No-hit element.");
212  }
213 
214  OnlMonCanvas* can1 = GetCanvas(1);
215  //can1->SetStatus(OnlMonCanvas::OK);
216  TPad* pad1 = can1->GetMainPad();
217  pad1->SetGrid();
218  pad1->Divide(1, 2);
219  for (int i_det = 0; i_det < N_DET; i_det++) {
220  pad1->cd(i_det+1);
221  UtilHist::AutoSetRange(h1_time[i_det]);
222  //h1_time[i_det]->GetXaxis()->SetRangeUser(400, 1050);
223  h1_time[i_det]->SetLineColor(kBlack);
224  h1_time[i_det]->Draw();
225  h1_time_in[i_det]->SetLineColor(kBlue);
226  h1_time_in[i_det]->SetFillColor(kBlue-7);
227  h1_time_in[i_det]->Draw("same");
228  }
229 
230  return 0;
231 }
232 
233 void OnlMonHodo::SetDet(const char* det0, const char* det1)
234 {
235  list_det_name[0] = det0;
236  list_det_name[1] = det1;
237  GeomSvc* geom = GeomSvc::instance();
238  for (int ii = 0; ii < N_DET; ii++) {
239  list_det_id[ii] = geom->getDetectorID(list_det_name[ii]);
240  }
241 }
int NumCanvases()
Definition: OnlMonClient.h:101
static const int N_DET
Definition: OnlMonHodo.h:8
void AutoSetRange(TH1 *h1, const int margin_lo=5, const int margin_hi=5)
Adjust the axis range via &quot;h1-&gt;GetXaxis()-&gt;SetRange(bin_lo, bin_hi)&quot; to zoom up non-empty bins...
Definition: UtilHist.cc:17
int ProcessEventOnlMon(PHCompositeNode *topNode)
Definition: OnlMonHodo.cc:125
OnlMonCanvas * GetCanvas(const int num=0)
int InitOnlMon(PHCompositeNode *topNode)
Definition: OnlMonHodo.cc:38
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
int EndOnlMon(PHCompositeNode *topNode)
Definition: OnlMonHodo.cc:150
void SetStatus(const MonStatus_t stat)
Definition: OnlMonCanvas.h:42
void RegisterHist(TH1 *h1, const HistMode_t mode=MODE_ADD)
std::string Title()
Definition: OnlMonClient.h:73
virtual const std::string Name() const
Returns the name of this module.
Definition: Fun4AllBase.h:23
int InitRunOnlMon(PHCompositeNode *topNode)
Definition: OnlMonHodo.cc:43
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
void AutoSetRangeY(TH2 *h2, const int margin_lo=5, const int margin_hi=5)
Definition: UtilHist.cc:43
TPad * GetMainPad()
Definition: OnlMonCanvas.cc:74
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:211
int getDetectorID(const std::string &detectorName) const
Get the plane position.
Definition: GeomSvc.h:184
OnlMonHodo(const HodoType_t type)
Definition: OnlMonHodo.cc:19
TH1 * FindMonHist(const std::string name, const bool non_null=true)
int getPlaneNElements(int detectorID)
Definition: GeomSvc.h:208
void AddMessage(const char *msg)
Definition: OnlMonCanvas.cc:50
int FindAllMonHist()
Definition: OnlMonHodo.cc:155
int DrawMonitor()
Definition: OnlMonHodo.cc:183