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