Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OnlMonCham.cc
Go to the documentation of this file.
1 #include <iomanip>
3 #include <TH1D.h>
4 #include <interface_main/SQRun.h>
8 #include <phool/PHNodeIterator.h>
9 #include <phool/PHIODataNode.h>
10 #include <phool/getClass.h>
11 #include <geom_svc/GeomSvc.h>
12 #include <UtilAna/UtilHist.h>
13 #include "OnlMonServer.h"
14 #include "OnlMonCham.h"
15 using namespace std;
16 
17 OnlMonCham::OnlMonCham(const ChamType_t type) : m_type(type)
18 {
19  NumCanvases(2);
20  switch (m_type) {
21  case D0 : Name("OnlMonChamD0" ); Title("Chamber: D0" ); break;
22  case D1 : Name("OnlMonChamD1" ); Title("Chamber: D1" ); break;
23  case D2 : Name("OnlMonChamD2" ); Title("Chamber: D2" ); break;
24  case D3p: Name("OnlMonChamD3p"); Title("Chamber: D3p"); break;
25  case D3m: Name("OnlMonChamD3m"); Title("Chamber: D3m"); break;
26  }
27 }
28 
30 {
32 }
33 
35 {
36  const double DT = 40/9.0; // 4/9 ns per single count of Taiwan TDC
37  int NT = 150;
38  double T0 = 110.5*DT;
39  double T1 = 260.5*DT;
40 
41  GeomSvc* geom = GeomSvc::instance();
42  string name_regex = "";
43  switch (m_type) {
44  case D0 : name_regex = "^D0" ; break;
45  case D1 : name_regex = "^D1" ; break;
46  case D2 : name_regex = "^D2" ; NT=150; T0=100.5*DT; T1=250.5*DT; break;
47  case D3p: name_regex = "^D3p"; NT=150; T0=100.5*DT; T1=250.5*DT; break;
48  case D3m: name_regex = "^D3m"; NT=150; T0=100.5*DT; T1=250.5*DT; break;
49  }
50  vector<int> list_det_id = geom->getDetectorIDs(name_regex);
51  if (list_det_id.size() == 0) {
52  cout << "OnlMonCham::InitRunOnlMon(): Found no ID for '" << name_regex << "'." << endl;
54  }
55  m_pl0 = list_det_id[0];
56 
57  ostringstream oss;
58  for (int pl = 0; pl < N_PL; pl++) {
59  string name = geom->getDetectorName (m_pl0 + pl);
60  int n_ele = geom->getPlaneNElements(m_pl0 + pl);
61  oss.str("");
62  oss << "h1_ele_" << pl;
63  h1_ele[pl] = new TH1D(oss.str().c_str(), "", n_ele, 0.5, n_ele+0.5);
64  oss.str("");
65  oss << name << ";Element ID;Hit count";
66  h1_ele[pl]->SetTitle(oss.str().c_str());
67 
68  oss.str("");
69  oss << "h1_time_" << pl;
70  h1_time[pl] = new TH1D(oss.str().c_str(), "", NT, T0, T1);
71 
72  oss.str("");
73  oss << name << ";tdcTime;Hit count";
74  h1_time[pl]->SetTitle(oss.str().c_str());
75 
76  RegisterHist(h1_ele [pl]);
77  RegisterHist(h1_time[pl]);
78  }
79 
81 }
82 
84 {
85  SQEvent* event_header = findNode::getClass<SQEvent >(topNode, "SQEvent");
86  SQHitVector* hit_vec = findNode::getClass<SQHitVector>(topNode, "SQHitVector");
87  if (!event_header || !hit_vec) return Fun4AllReturnCodes::ABORTEVENT;
88 
89  for (SQHitVector::ConstIter it = hit_vec->begin(); it != hit_vec->end(); it++) {
90  int pl = (*it)->get_detector_id() - m_pl0;
91  if (pl < 0 || pl >= N_PL) continue;
92  h1_ele [pl]->Fill((*it)->get_element_id());
93  h1_time[pl]->Fill((*it)->get_tdc_time ());
94  }
95 
97 }
98 
100 {
102 }
103 
105 {
106  ostringstream oss;
107  for (int pl = 0; pl < N_PL; pl++) {
108  oss.str("");
109  oss << "h1_ele_" << pl;
110  h1_ele[pl] = FindMonHist(oss.str().c_str());
111  if (! h1_ele[pl]) return 1;
112  oss.str("");
113  oss << "h1_time_" << pl;
114  h1_time[pl] = FindMonHist(oss.str().c_str());
115  if (! h1_time[pl]) return 1;
116  }
117  return 0;
118 }
119 
121 {
122  OnlMonCanvas* can0 = GetCanvas(0);
123  TPad* pad0 = can0->GetMainPad();
124  pad0->SetGrid();
125  pad0->Divide(2, 3);
126  for (int pl = 0; pl < N_PL; pl++) {
127  pad0->cd(pl+1);
128  h1_ele[pl]->Draw();
129  }
130  //can0->SetStatus(OnlMonCanvas::OK);
131 
132  OnlMonCanvas* can1 = GetCanvas(1);
133  TPad* pad1 = can1->GetMainPad();
134  pad1->SetGrid();
135  pad1->Divide(2, 3);
136  for (int pl = 0; pl < N_PL; pl++) {
137  pad1->cd(pl+1);
138  UtilHist::AutoSetRange(h1_time[pl]);
139  h1_time[pl]->Draw();
140  }
141  //can1->SetStatus(OnlMonCanvas::OK);
142 
143  return 0;
144 }
int NumCanvases()
Definition: OnlMonClient.h:101
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
std::string getDetectorName(const int &detectorID) const
Definition: GeomSvc.h:188
OnlMonCanvas * GetCanvas(const int num=0)
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
OnlMonCham(const ChamType_t type)
Definition: OnlMonCham.cc:17
void RegisterHist(TH1 *h1, const HistMode_t mode=MODE_ADD)
std::string Title()
Definition: OnlMonClient.h:73
int InitOnlMon(PHCompositeNode *topNode)
Definition: OnlMonCham.cc:29
int FindAllMonHist()
Definition: OnlMonCham.cc:104
virtual const std::string Name() const
Returns the name of this module.
Definition: Fun4AllBase.h:23
int EndOnlMon(PHCompositeNode *topNode)
Definition: OnlMonCham.cc:99
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
std::vector< int > getDetectorIDs(std::string pattern)
Definition: GeomSvc.cxx:724
int InitRunOnlMon(PHCompositeNode *topNode)
Definition: OnlMonCham.cc:34
TPad * GetMainPad()
Definition: OnlMonCanvas.cc:74
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:211
static const int N_PL
Definition: OnlMonCham.h:8
TH1 * FindMonHist(const std::string name, const bool non_null=true)
int getPlaneNElements(int detectorID)
Definition: GeomSvc.h:208
int ProcessEventOnlMon(PHCompositeNode *topNode)
Definition: OnlMonCham.cc:83
int DrawMonitor()
Definition: OnlMonCham.cc:120