Belle II Software  release-08-01-10
TRGCDCTSFDQMModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 //---------------------------------------------------------------
9 // $Id$
10 //---------------------------------------------------------------
11 // Filename : TRGCDCTSFModule.cc
12 // Section : TRG CDCTSF
13 // Owner :
14 // Email :
15 //---------------------------------------------------------------
16 // Description : A trigger module for TRG CDCTSF
17 //---------------------------------------------------------------
18 // 1.00 : 2017/05/08 : First version
19 //---------------------------------------------------------------
20 #include <trg/cdc/modules/trgcdctsfDQM/TRGCDCTSFDQMModule.h>
21 
22 #include <framework/dataobjects/EventMetaData.h>
23 #include <framework/datastore/StoreObjPtr.h>
24 #include <framework/datastore/StoreArray.h>
25 
26 #include <TDirectory.h>
27 #include <TPostScript.h>
28 #include <TCanvas.h>
29 #include <TStyle.h>
30 #include <iostream>
31 
32 using namespace std;
33 using namespace Belle2;
34 
35 REG_MODULE(TRGCDCTSFDQM);
36 
37 
38 TRGCDCTSFDQMModule::TRGCDCTSFDQMModule() : HistoModule()
39 {
40 
41  setDescription("DQM for CDCTSF Trigger system");
43 
44  addParam("TSFMOD", m_TSFMOD,
45  "TSF module number",
46  0);
47  addParam("generatePostscript", m_generatePostscript,
48  "Genarete postscript file or not",
49  false);
50  addParam("postScriptName", m_postScriptName,
51  "postscript file name",
52  string("gdldqm.ps"));
53 
54 
55 }
56 
58 {
59  oldDir = gDirectory;
60  dirDQM = NULL;
61  //dirDQM = oldDir->mkdir("TRGCDCTSF");
62  if (!oldDir->Get("TRGCDCTSF"))dirDQM = oldDir->mkdir("TRGCDCTSF");
63  else dirDQM = (TDirectory*)oldDir->Get("TRGCDCTSF");
64  dirDQM->cd();
65  //Total number of TSF hits per event in each superlayer
66  h_nhit = new TH1I(Form("hCDCTSF_nhit_mod%d", m_TSFMOD), Form("nhit_mod%d", m_TSFMOD), 16, 0, 16);
67  h_nhit->SetTitle(Form("Exp%d Run%d SuperLayer%d", _exp, _run, m_TSFMOD));
68  h_nhit->GetXaxis()->SetTitle("Total number of TSF hits/event");
69  //Total number of hits in each TSF
70  h_nhit_tsf = new TH1I(Form("hCDCTSF_nhit_tsf_mod%d", m_TSFMOD), Form("nhit_tsf_mod%d", m_TSFMOD), 200, 0, 200);
71  h_nhit_tsf->SetTitle(Form("Exp%d Run%d SuperLayer%d", _exp, _run, m_TSFMOD));
72  h_nhit_tsf->GetXaxis()->SetTitle("TSF ID");
73  h_nhit_tsf->GetYaxis()->SetTitle("Total number of hits");
74  //Validity of hits in each super layer
75  h_valid = new TH1I(Form("hCDCTSF_valid_mod%d", m_TSFMOD), Form("valid__mod%d", m_TSFMOD), 10, 0, 10);
76  h_valid->SetTitle(Form("Exp%d Run%d SuperLayer%d", _exp, _run, m_TSFMOD));
77  h_valid->GetXaxis()->SetTitle("Validity");
78  h_valid->GetYaxis()->SetTitle("#of tsf hits");
79  //Timing of hits in each super layer
80  h_timing = new TH1I(Form("hCDCTSF_timing_mod%d", m_TSFMOD), Form("timing__mod%d", m_TSFMOD), 520, -5, 515);
81  h_timing->SetTitle(Form("Exp%d Run%d SuperLayer%d", _exp, _run, m_TSFMOD));
82  h_timing->GetXaxis()->SetTitle("Timing");
83  h_timing->GetYaxis()->SetTitle("#of tsf hits");
84  oldDir->cd();
85 }
86 
88 {
89 
90  dirDQM->cd();
91 
92  h_nhit->Reset();
93  h_nhit_tsf->Reset();
94 
95  oldDir->cd();
96 }
97 
99 {
100 
102  _exp = bevt->getExperiment();
103  _run = bevt->getRun();
104 
105  // calls back the defineHisto() function, but the HistoManager module has to be in the path
106  REG_HISTOGRAM
107 
108  char c_name[100];
109  sprintf(c_name, "TRGCDCTSFUnpackerStore%d", m_TSFMOD);
110  entAry.isRequired(c_name);
111  if (!entAry || !entAry.getEntries()) return;
112 
113 }
114 
116 {
117  dirDQM->cd();
118 
119  //Draw and save histograms
120  if (m_generatePostscript) {
121  gStyle->SetOptStat(0);
122  TCanvas c1("c1", "", 0, 0, 500, 300);
123  c1.cd();
124 
125  TPostScript* ps_nhit = new TPostScript((m_postScriptName + ".tsf_total_nhit_superlayer" + to_string(m_TSFMOD) + ".ps").c_str(),
126  112);
127  h_nhit->Draw();
128  c1.Update();
129  ps_nhit->Close();
130 
131  TPostScript* ps_nhit_tsf = new TPostScript((m_postScriptName + ".tsf_nhit_superlayer" + to_string(m_TSFMOD) + ".ps").c_str(), 112);
132  h_nhit_tsf->Draw();
133  c1.Update();
134  ps_nhit_tsf->Close();
135 
136  }
137 
138  oldDir->cd();
139 }
140 
142 {
143 
144  dirDQM->cd();
145 
146 
147  //Fill
148  int nhit = 0;
149  for (int ii = 0; ii < entAry.getEntries(); ii++) {
150  nhit += entAry[ii]->m_netfhit;
151  }
152  h_nhit->Fill(nhit);
153 
154  /* cppcheck-suppress variableScope */
155  int id;
156  /* cppcheck-suppress variableScope */
157  int v ;
158  /* cppcheck-suppress variableScope */
159  int rt;
160  for (int ii = 0; ii < entAry.getEntries(); ii++) {
161  id = entAry[ii]->m_trackerhit0id;
162  v = entAry[ii]->m_trackerhit0v;
163  rt = entAry[ii]->m_trackerhit0rt;
164  if (v != 0) {
165  h_nhit_tsf->Fill(id);
166  h_valid->Fill(v);
167  h_timing->Fill(rt);
168  }
169  id = entAry[ii]->m_trackerhit1id;
170  v = entAry[ii]->m_trackerhit1v;
171  rt = entAry[ii]->m_trackerhit1rt;
172  if (v != 0) {
173  h_nhit_tsf->Fill(id);
174  h_valid->Fill(v);
175  h_timing->Fill(rt);
176  }
177  id = entAry[ii]->m_trackerhit2id;
178  v = entAry[ii]->m_trackerhit2v;
179  rt = entAry[ii]->m_trackerhit2rt;
180  if (v != 0) {
181  h_nhit_tsf->Fill(id);
182  h_valid->Fill(v);
183  h_timing->Fill(rt);
184  }
185  id = entAry[ii]->m_trackerhit3id;
186  v = entAry[ii]->m_trackerhit3v;
187  rt = entAry[ii]->m_trackerhit3rt;
188  if (v != 0) {
189  h_nhit_tsf->Fill(id);
190  h_valid->Fill(v);
191  h_timing->Fill(rt);
192  }
193  id = entAry[ii]->m_trackerhit4id;
194  v = entAry[ii]->m_trackerhit4v;
195  rt = entAry[ii]->m_trackerhit4rt;
196  if (v != 0) {
197  h_nhit_tsf->Fill(id);
198  h_valid->Fill(v);
199  h_timing->Fill(rt);
200  }
201  id = entAry[ii]->m_trackerhit5id;
202  v = entAry[ii]->m_trackerhit5v;
203  rt = entAry[ii]->m_trackerhit5rt;
204  if (v != 0) {
205  h_nhit_tsf->Fill(id);
206  h_valid->Fill(v);
207  h_timing->Fill(rt);
208  }
209  id = entAry[ii]->m_trackerhit6id;
210  v = entAry[ii]->m_trackerhit6v;
211  rt = entAry[ii]->m_trackerhit6rt;
212  if (v != 0) {
213  h_nhit_tsf->Fill(id);
214  h_valid->Fill(v);
215  h_timing->Fill(rt);
216  }
217  id = entAry[ii]->m_trackerhit7id;
218  v = entAry[ii]->m_trackerhit7v;
219  rt = entAry[ii]->m_trackerhit7rt;
220  if (v != 0) {
221  h_nhit_tsf->Fill(id);
222  h_valid->Fill(v);
223  h_timing->Fill(rt);
224  }
225  id = entAry[ii]->m_trackerhit8id;
226  v = entAry[ii]->m_trackerhit8v;
227  rt = entAry[ii]->m_trackerhit8rt;
228  if (v != 0) {
229  h_nhit_tsf->Fill(id);
230  h_valid->Fill(v);
231  h_timing->Fill(rt);
232  }
233  id = entAry[ii]->m_trackerhit9id;
234  v = entAry[ii]->m_trackerhit9v;
235  rt = entAry[ii]->m_trackerhit9rt;
236  if (v != 0) {
237  h_nhit_tsf->Fill(id);
238  h_valid->Fill(v);
239  h_timing->Fill(rt);
240  }
241 
242  // to fill 5 more TS for 15 TS version, only for TSF 1,3,5
243  if (entAry[ii]->m_N2DTS == 10) continue;
244 
245  id = entAry[ii]->m_trackerhit10id;
246  v = entAry[ii]->m_trackerhit10v;
247  rt = entAry[ii]->m_trackerhit10rt;
248  if (v != 0) {
249  h_nhit_tsf->Fill(id);
250  h_valid->Fill(v);
251  h_timing->Fill(rt);
252  }
253  id = entAry[ii]->m_trackerhit11id;
254  v = entAry[ii]->m_trackerhit11v;
255  rt = entAry[ii]->m_trackerhit11rt;
256  if (v != 0) {
257  h_nhit_tsf->Fill(id);
258  h_valid->Fill(v);
259  h_timing->Fill(rt);
260  }
261  id = entAry[ii]->m_trackerhit12id;
262  v = entAry[ii]->m_trackerhit12v;
263  rt = entAry[ii]->m_trackerhit12rt;
264  if (v != 0) {
265  h_nhit_tsf->Fill(id);
266  h_valid->Fill(v);
267  h_timing->Fill(rt);
268  }
269  id = entAry[ii]->m_trackerhit13id;
270  v = entAry[ii]->m_trackerhit13v;
271  rt = entAry[ii]->m_trackerhit13rt;
272  if (v != 0) {
273  h_nhit_tsf->Fill(id);
274  h_valid->Fill(v);
275  h_timing->Fill(rt);
276  }
277  id = entAry[ii]->m_trackerhit14id;
278  v = entAry[ii]->m_trackerhit14v;
279  rt = entAry[ii]->m_trackerhit14rt;
280  if (v != 0) {
281  h_nhit_tsf->Fill(id);
282  h_valid->Fill(v);
283  h_timing->Fill(rt);
284  }
285 
286 
287  }
288 
289  oldDir->cd();
290 
291 }
292 
293 
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
TH1I * h_valid
Valid type of TSF hits in each superlayer.
StoreArray< TRGCDCTSFUnpackerStore > entAry
TSF data store.
unsigned _exp
experiment number
virtual void initialize() override
initialize
TDirectory * oldDir
TDirectories.
virtual void event() override
Event.
TH1I * h_timing
Timing of TSF hits in each superlayer.
virtual void endRun() override
End Run.
TH1I * h_nhit_tsf
Total number of hits in each TSF.
int m_TSFMOD
TSF module number.
virtual void beginRun() override
begin Run
TDirectory * dirDQM
TDirectories.
std::string m_postScriptName
name of ps file
TH1I * h_nhit
Total number of TSF hits per event in each superlayer.
virtual void defineHisto() override
Define Histogram.
bool m_generatePostscript
flag to save ps file
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.