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