Belle II Software  release-06-02-00
TRGGRL.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 #define TRG_SHORT_NAMES
10 #define TRGGRL_SHORT_NAMES
11 
12 #include <fstream>
13 #include "framework/datastore/StoreArray.h"
14 #include "trg/trg/Utilities.h"
15 #include "trg/grl/TRGGRL.h"
16 #include "trg/cdc/TRGCDC.h"
17 #include "trg/cdc/TRGCDCTrack.h"
18 #include "trg/ecl/dataobjects/TRGECLCluster.h"
19 #include "trg/ecl/TrgEclCluster.h"
20 #include <math.h>
21 #include <TFile.h>
22 #include <TTree.h>
23 #include <framework/logging/Logger.h>
24 
25 # define M_PI 3.14159265358979323846
26 
27 using namespace std;
28 
29 namespace Belle2 {
35  TRGGRL*
36  TRGGRL::_grl = 0;
37 
38  string
39  TRGGRL::name(void) const
40  {
41  return "TRGGRL";
42  }
43 
44  string
45  TRGGRL::version(void) const
46  {
47  return string("TRGGRL 0.01");
48  }
49 
50  TRGGRL*
51  TRGGRL::getTRGGRL(const string& configFile,
52  unsigned simulationMode,
53  unsigned fastSimulationMode,
54  unsigned firmwareSimulationMode)
55  {
56  if (_grl) {
57  //delete _grl;
58  _grl = 0;
59  }
60 
61  if (configFile != "good-bye") {
62  _grl = new TRGGRL(configFile,
63  simulationMode,
64  fastSimulationMode,
65  firmwareSimulationMode);
66  } else {
67  B2DEBUG(100, "TRGGRL::getTRGGRL ... good-bye");
68  _grl = 0;
69  }
70 
71  return _grl;
72  }
73 
74  TRGGRL*
75  TRGGRL::getTRGGRL(void)
76  {
77  if (! _grl)
78  B2WARNING("TRGGRL::getTRGGRL !!! TRGGRL is not created yet");
79  return _grl;
80  }
81 
82  TRGGRL::TRGGRL(const string& configFile,
83  unsigned simulationMode,
84  unsigned fastSimulationMode,
85  unsigned firmwareSimulationMode)
86  : _debugLevel(0),
87  _configFilename(configFile),
88  _simulationMode(simulationMode),
89  _fastSimulationMode(fastSimulationMode),
90  _firmwareSimulationMode(firmwareSimulationMode),
91  _clock(Belle2_GDL::GDLSystemClock)
92  {
93 
94  B2DEBUG(100, "TRGGRL ... TRGGRL initializing with " << _configFilename
95  << " mode=0x" << hex << _simulationMode << dec);
96 
97  initialize();
98 
99  B2DEBUG(100, "TRGGRL ... TRGGRL created with " << _configFilename);
100  }
101 
102  void
104  {
105 
106  m_file = new TFile("trggrl.root", "RECREATE");
107  h1 = new TTree("h1", "h1");
108 
109  h1->Branch("3d", &x0, "3d");
110  h1->Branch("dr", &x1, "dr");
111  h1->Branch("dz", &x2, "dz");
112  h1->Branch("poe", &x3, "poe");
113  h1->Branch("z0", &x4, "z0");
114  h1->Branch("pt", &x5, "pt");
115  h1->Branch("pz", &x6, "pz");
116  h1->Branch("e", &x7, "e");
117 
118  configure();
119  }
120 
121  void
123  {
124  }
125 
126  void
127  TRGGRL::dump(const string& msg) const
128  {
129 
130  if (msg != "") B2DEBUG(100, "dump nothing...");
131 
132  }
133 
134  void
136  {
137  }
138 
139  void
141  {
142  }
143 
144  void
146  {
147 
148  matchList.clear();
149  matchList3D.clear();
150 
151  B2DEBUG(100, "do nothing...");
152 
153  }
154 
156  {
157  h1->Write();
158  m_file->Write();
159  m_file->Close();
160  clear();
161  }
162 
163  void
165  {
166 
168  vector<TRGCDCTrack*> trackList = _cdc->getTrackList2D();
169  vector<TRGCDCTrack*> trackList3D = _cdc->getTrackList3D();
170  StoreArray<TRGECLCluster> ClusterArray;
171 
172  unsigned n_track = trackList.size();
173  unsigned n_track3D = trackList3D.size();
174  unsigned n_cluster = ClusterArray.getEntries();
175 
176 // if (TRGDebug::level() > 2) cout <<"yt_grl "<< n_cluster << " " << n_track << endl;
177 
178  for (unsigned i = 0; i < n_track; i++) {
179  // vector<TRGGRLMatch *> match_i;
180  if (n_cluster == 0) break;
181  else if (n_cluster == 1) {
182  TRGGRLMatch* match = new TRGGRLMatch(trackList[i], ClusterArray[0], 0);
183  matchList.push_back(match);
184  } else if (n_cluster > 1) {
185  int best_j = 0; double old_dr = 99999;
186  for (unsigned j = 0; j < n_cluster; j++) {
187  TRGGRLMatch* match = new TRGGRLMatch(trackList[i], ClusterArray[j], 0);
188  if (match->getDr() < old_dr) {best_j = j; old_dr = match->getDr();}
189  }
190  TRGGRLMatch* match = new TRGGRLMatch(trackList[i], ClusterArray[best_j], 0);
191  matchList.push_back(match);
192  }
193  }
194 
195  for (unsigned i = 0; i < n_track3D; i++) {
196  // vector<TRGGRLMatch *> match_i;
197  if (n_cluster == 0) break;
198  else if (n_cluster == 1) {
199  TRGGRLMatch* match = new TRGGRLMatch(trackList3D[i], ClusterArray[0], 1);
200  matchList.push_back(match);
201  } else if (n_cluster > 1) {
202  int best_j = 0; double old_dr = 99999;
203  for (unsigned j = 0; j < n_cluster; j++) {
204  TRGGRLMatch* match = new TRGGRLMatch(trackList3D[i], ClusterArray[j], 0);
205  if (match->getDr() < old_dr) {best_j = j; old_dr = match->getDr();}
206  }
207  TRGGRLMatch* match = new TRGGRLMatch(trackList3D[i], ClusterArray[best_j], 0);
208  matchList3D.push_back(match);
209  }
210  }
211 
212  //-----Fill tree
213  for (unsigned i = 0; i < matchList.size(); i++) {
214  TRGGRLMatch& match = * matchList[i];
215 
216  x0 = match.getMatch3D();
217  x1 = match.getDr();
218  x2 = match.getDz();
219  x3 = match.getPoe();
220  x4 = match.getCenter_z0();
221  x5 = match.getCenter_pt();
222  x6 = match.getCenter_pz();
223  x7 = match.getCluster_e();
224  h1->Fill();
225  }
226 
227  for (unsigned i = 0; i < matchList3D.size(); i++) {
228  TRGGRLMatch& match = * matchList3D[i];
229 
230  x0 = match.getMatch3D();
231  x1 = match.getDr();
232  x2 = match.getDz();
233  x3 = match.getPoe();
234  x4 = match.getCenter_z0();
235  x5 = match.getCenter_pt();
236  x6 = match.getCenter_pz();
237  x7 = match.getCluster_e();
238  h1->Fill();
239  }
240 
241  //--------------------------------------
242 
243 
244  const bool fast = (_simulationMode & 1);
245  const bool firm = (_simulationMode & 2);
246  if (fast)
247  fastSimulation();
248  if (firm)
250  }
251 
252  void
254  {
255  }
256 
257  void
259  {
260  }
261 
262  void
264  {
265  }
266  /*
267  bool
268  TRGGRL::barrel_matching_2D(TRGCDCTrack * track, TRGECLCluster * cluster){
269 
270  //-- track/TRGCDC information
271  const TRGCDCHelix & helix = track->helix();
272  double pt = track->pt();
273  double center_x = helix.center().x(), center_y = helix.center().y(), center_z = helix.center().z();
274  double r = sqrt(center_x*center_x + center_y*center_y);//helix.radius();
275  double phi = atan2(center_y, center_x) ;
276 
277  //-- cluster/TRGECL information
278  double cluster_x = cluster->getPositionX(), cluster_y = cluster->getPositionY(), cluster_z = cluster->getPositionZ();
279  double cluster_e = cluster->getEnergyDep();
280  double R = sqrt(cluster_x*cluster_x + cluster_y*cluster_y);
281  double D = sqrt(cluster_x*cluster_x + cluster_y*cluster_y + cluster_z*cluster_z);
282  double re_scaled_p = pt*D/R;
283 
284  //-- calculation
285 
286  double theta0 = acos(R/(2*r)) + phi;
287  double theta1 = 2*phi - theta0;
288 
289  double ex_x0 = R*cos(theta0), ex_y0 = R*sin(theta0), ex_x1 = R*cos(theta1), ex_y1 = R*sin(theta1);
290 
291  double dr0 = sqrt( (ex_x0-cluster_x)*(ex_x0-cluster_x) + (ex_y0-cluster_y)*(ex_y0-cluster_y) );
292  double dr1 = sqrt( (ex_x1-cluster_x)*(ex_x1-cluster_x) + (ex_y1-cluster_y)*(ex_y1-cluster_y) );
293  double dr = (dr0 < dr1) ? dr0 : dr1;
294 
295  if (TRGDebug::level() > 1) printf("%s %f %f %f %f %f %f %f \n","dump! ",dr,dr0,dr1,pt,re_scaled_p,cluster_e,re_scaled_p/cluster_e);
296 
297  if (TRGDebug::level() > 1 && dr > 30) {
298  cout << " " << endl;
299  cout << "double center_x = " << center_x << ";" <<endl;
300  cout << "double center_y = " << center_y << ";" <<endl;
301  cout << "double center_z = " << center_z << ";" <<endl;
302  cout << "double radius = " << r << ";" <<endl;
303  cout << "double pt = " << pt << ";" <<endl;
304  cout << "double cluster_x = " << cluster_x << ";" <<endl;
305  cout << "double cluster_y = " << cluster_y << ";" <<endl;
306  cout << "double ex_x0 = " << ex_x0 << ";" <<endl;
307  cout << "double ex_y0 = " << ex_y0 << ";" <<endl;
308  cout << "double ex_x1 = " << ex_x1 << ";" <<endl;
309  cout << "double ex_y1 = " << ex_y1 << ";" <<endl;
310  }
311 
312  return true;
313  }
314  */
315 
316 
317 
319 } // namespace Belle2
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:69
A class to represent a matching candidate in TRGGRL A matching candidate consists of a TRGCDCTrack an...
Definition: TRGGRLMatch.h:24
a class for TRGGRL
Definition: TRGGRL.h:43
unsigned _simulationMode
Simulation mode.
Definition: TRGGRL.h:150
std::string _configFilename
root file name.
Definition: TRGGRL.h:147
std::vector< TRGGRLMatch * > matchList
Vector which stores list of TRGGRLMatch without 3D information.
Definition: TRGGRL.h:188
double x5
Temporary variables to make tree in root files.
Definition: TRGGRL.h:178
std::vector< TRGGRLMatch * > matchList3D
Vector which stores list of TRGGRLMatch with 3D information.
Definition: TRGGRL.h:190
double x3
Temporary variables to make tree in root files.
Definition: TRGGRL.h:174
TFile * m_file
root file
Definition: TRGGRL.h:162
TTree * h1
root tree
Definition: TRGGRL.h:165
double x7
Temporary variables to make tree in root files.
Definition: TRGGRL.h:182
double x1
Temporary variables to make tree in root files.
Definition: TRGGRL.h:170
double x2
Temporary variables to make tree in root files.
Definition: TRGGRL.h:172
double x6
Temporary variables to make tree in root files.
Definition: TRGGRL.h:180
double x0
Temporary variables to make tree in root files.
Definition: TRGGRL.h:168
double x4
Temporary variables to make tree in root files.
Definition: TRGGRL.h:176
void configure(void)
configures trigger modules for firmware simulation.
Definition: TRGGRL.cc:263
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
void fastClear(void)
clears TRGGRL information.
Definition: TRGGRL.cc:140
void terminate(void)
terminates when run is finished
Definition: TRGGRL.cc:122
std::vector< TRGCDCTrack * > getTrackList3D(void)
returns 3D track list (fitted).
Definition: TRGCDC.cc:210
void initialize(void)
initializes GRL.
Definition: TRGGRL.cc:103
void dump(const std::string &message) const
dumps debug information.
Definition: TRGGRL.cc:127
std::vector< TRGCDCTrack * > getTrackList2D(void)
returns 2D track list (no fit).
Definition: TRGCDC.cc:198
void update(bool mcAnalysis=true)
updates TRGGRL information.
Definition: TRGGRL.cc:145
void fastSimulation(void)
Fast simulation.
Definition: TRGGRL.cc:253
void simulate(void)
fast trigger simulation.
Definition: TRGGRL.cc:164
void clear(void)
clears all TRGGRL information.
Definition: TRGGRL.cc:135
void firmwareSimulation(void)
Firmware simulation.
Definition: TRGGRL.cc:258
virtual ~TRGGRL()
Destructor.
Definition: TRGGRL.cc:155
Abstract base class for different kinds of events.