Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OnlMonTrigSig.cc
Go to the documentation of this file.
1 #include <iomanip>
3 #include <TH2D.h>
7 #include <phool/PHNodeIterator.h>
8 #include <phool/PHIODataNode.h>
9 #include <phool/getClass.h>
10 #include <geom_svc/GeomSvc.h>
11 #include <UtilAna/UtilHist.h>
12 #include "OnlMonServer.h"
13 #include "OnlMonTrigSig.h"
14 using namespace std;
15 
16 // BeforeInhNIM
17 // BeforeInhMatrix
18 // AfterInhNIM
19 // AfterInhMatrix
20 // BOS (ch = ?)
21 // EOS (ch = ?)
22 // L1 (ch = ?)
23 // RF (ch = 0-8 on v1495)
24 // STOP (ch = 0-8 on v1495)
25 // L1PXtp
26 // L1PXtn
27 // L1PXbp
28 // L1PXbn
29 // L1NIMxt
30 // L1NIMxb
31 // L1NIMyt
32 // L1NIMyb
33 
35 {
36  NumCanvases(3);
37  Name("OnlMonTrigSig");
38  Title("Trigger Signal");
39 }
40 
42 {
44 }
45 
47 {
48  const double DT = 40/9.0; // 4/9 ns per single count of Taiwan TDC
49  const int NT = 100;
50  const double T0 = 100.5*DT;
51  const double T1 = 200.5*DT;
52  h2_bi_fpga = new TH2D("h2_bi_fpga", "FPGA Before Inhibit;tdcTime;", NT, T0, T1, 5, 0.5, 5.5);
53  h2_ai_fpga = new TH2D("h2_ai_fpga", "FPGA After Inhibit;tdcTime;", NT, T0, T1, 5, 0.5, 5.5);
54  h2_bi_nim = new TH2D("h2_bi_nim" , "NIM Before Inhibit;tdcTime;", NT, T0, T1, 5, 0.5, 5.5);
55  h2_ai_nim = new TH2D("h2_ai_nim" , "NIM After Inhibit;tdcTime;", NT, T0, T1, 5, 0.5, 5.5);
56  for (int ii = 1; ii <= 5; ii++) {
57  ostringstream oss;
58  oss << "FPGA " << ii;
59  h2_bi_fpga->GetYaxis()->SetBinLabel(ii, oss.str().c_str());
60  h2_ai_fpga->GetYaxis()->SetBinLabel(ii, oss.str().c_str());
61  oss.str("");
62  oss << "NIM " << ii;
63  h2_bi_nim->GetYaxis()->SetBinLabel(ii, oss.str().c_str());
64  h2_ai_nim->GetYaxis()->SetBinLabel(ii, oss.str().c_str());
65  }
66 
67  const double DT2 = 1.0; // 1 ns per single count of v1495 TDC
68  const int NT2 = 2000;
69  const double T02 = 0.5*DT2;
70  const double T12 = (NT2+0.5)*DT2;
71  h2_rf = new TH2D("h2_rf" , "RF on v1495;tdcTime;", NT2, T02, T12, 9, 0.5, 9.5);
72  h2_stop = new TH2D("h2_stop" , "STOP on v1495;tdcTime;", NT2, T02, T12, 9, 0.5, 9.5);
73  for (int ii = 1; ii <= 9; ii++) {
74  ostringstream oss;
75  oss << "Board " << ii;
76  h2_rf ->GetYaxis()->SetBinLabel(ii, oss.str().c_str());
77  h2_stop->GetYaxis()->SetBinLabel(ii, oss.str().c_str());
78  }
79 
80  RegisterHist(h2_bi_fpga);
81  RegisterHist(h2_ai_fpga);
82  RegisterHist(h2_bi_nim );
83  RegisterHist(h2_ai_nim );
84  RegisterHist(h2_rf );
85  RegisterHist(h2_stop );
86 
88 }
89 
91 {
92  SQEvent* event_header = findNode::getClass<SQEvent >(topNode, "SQEvent");
93  SQHitVector* hit_vec = findNode::getClass<SQHitVector>(topNode, "SQHitVector");
94  SQHitVector* trig_hit_vec = findNode::getClass<SQHitVector>(topNode, "SQTriggerHitVector");
95  if (!event_header || !hit_vec || !trig_hit_vec) return Fun4AllReturnCodes::ABORTEVENT;
96 
97  GeomSvc* geom = GeomSvc::instance();
98 
99  for (SQHitVector::ConstIter it = hit_vec->begin(); it != hit_vec->end(); it++) {
100  int det_id = (*it)->get_detector_id();
101  int ele_id = (*it)->get_element_id ();
102  double time = (*it)->get_tdc_time ();
103  if (det_id == geom->getDetectorID("BeforeInhNIM" )) h2_bi_nim ->Fill(time, ele_id);
104  else if (det_id == geom->getDetectorID("BeforeInhMatrix")) h2_bi_fpga->Fill(time, ele_id);
105  else if (det_id == geom->getDetectorID("AfterInhNIM" )) h2_ai_nim ->Fill(time, ele_id);
106  else if (det_id == geom->getDetectorID("AfterInhMatrix" )) h2_ai_fpga->Fill(time, ele_id);
107  }
108 
109  for (SQHitVector::ConstIter it = trig_hit_vec->begin(); it != trig_hit_vec->end(); it++) {
110  int det_id = (*it)->get_detector_id();
111  int ele_id = (*it)->get_element_id ();
112  double time = (*it)->get_tdc_time ();
113  if (det_id == geom->getDetectorID("RF" )) h2_rf ->Fill(time, ele_id);
114  else if (det_id == geom->getDetectorID("STOP")) h2_stop->Fill(time, ele_id);
115  }
116 
118 }
119 
121 {
123 }
124 
126 {
127  h2_bi_fpga = (TH2*)FindMonHist("h2_bi_fpga");
128  h2_ai_fpga = (TH2*)FindMonHist("h2_ai_fpga");
129  h2_bi_nim = (TH2*)FindMonHist("h2_bi_nim" );
130  h2_ai_nim = (TH2*)FindMonHist("h2_ai_nim" );
131  h2_rf = (TH2*)FindMonHist("h2_rf" );
132  h2_stop = (TH2*)FindMonHist("h2_stop" );
133  return (h2_bi_fpga && h2_ai_fpga && h2_bi_nim && h2_ai_nim && h2_rf && h2_stop ? 0 : 1);
134 }
135 
137 {
138  UtilHist::AutoSetRangeX(h2_bi_fpga);
139  UtilHist::AutoSetRangeX(h2_ai_fpga);
140  UtilHist::AutoSetRangeX(h2_bi_nim );
141  UtilHist::AutoSetRangeX(h2_ai_nim );
142  UtilHist::AutoSetRangeX(h2_rf );
143  UtilHist::AutoSetRangeX(h2_stop );
144 
145  OnlMonCanvas* can0 = GetCanvas(0);
146  TPad* pad0 = can0->GetMainPad();
147  pad0->SetGrid();
148  pad0->Divide(1, 2);
149  pad0->cd(1); DrawTH2WithPeakPos(h2_bi_fpga);
150  pad0->cd(2); DrawTH2WithPeakPos(h2_ai_fpga);
151  //can0->SetStatus(OnlMonCanvas::OK);
152 
153  OnlMonCanvas* can1 = GetCanvas(1);
154  TPad* pad1 = can1->GetMainPad();
155  pad1->SetGrid();
156  pad1->Divide(1, 2);
157  pad1->cd(1); DrawTH2WithPeakPos(h2_bi_nim);
158  pad1->cd(2); DrawTH2WithPeakPos(h2_ai_nim);
159  //can1->SetStatus(OnlMonCanvas::OK);
160 
161  OnlMonCanvas* can2 = GetCanvas(2);
162  TPad* pad2 = can2->GetMainPad();
163  pad2->SetGrid();
164  pad2->Divide(1, 2);
165  pad2->cd(1); DrawTH2WithPeakPos(h2_rf );
166  pad2->cd(2); DrawTH2WithPeakPos(h2_stop);
167  //can2->SetStatus(OnlMonCanvas::OK);
168 
169  return 0;
170 }
171 
172 void OnlMonTrigSig::DrawTH2WithPeakPos(TH2* h2, const double cont_min)
173 {
174  h2->Draw("colz");
175  int ny = h2->GetNbinsY();
176  for (int iy = 1; iy <= ny; iy++) {
177  TH1* h1 = h2->ProjectionX("h1_draw_th2", iy, iy);
178  ostringstream oss;
179  if (h1->GetMaximum() >= cont_min) {
180  oss << "Peak @ " << h1->GetXaxis()->GetBinCenter(h1->GetMaximumBin());
181  } else {
182  oss << "No sizable peak";
183  }
184  TText* text = new TText();
185  text->SetNDC(true);
186  text->SetTextAlign(22);
187  text->DrawText(0.3, 0.1+(iy-0.5)*0.8/ny, oss.str().c_str());
188  // The y-position above assumes that the top & bottom margins are 0.1 each.
189  }
190 }
void AutoSetRangeX(TH2 *h2, const int margin_lo=5, const int margin_hi=5)
Definition: UtilHist.cc:29
std::vector< SQHit * >::const_iterator ConstIter
Definition: SQHitVector.h:37
int InitRunOnlMon(PHCompositeNode *topNode)
int InitOnlMon(PHCompositeNode *topNode)
int ProcessEventOnlMon(PHCompositeNode *topNode)
int EndOnlMon(PHCompositeNode *topNode)
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
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