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 delete match;
188 }
189 TRGGRLMatch* match = new TRGGRLMatch(trackList[i], ClusterArray[best_j], 0);
190 matchList.push_back(match);
191 }
192 }
193
194 for (unsigned i = 0; i < n_track3D; i++) {
195 // vector<TRGGRLMatch *> match_i;
196 if (n_cluster == 0) break;
197 else if (n_cluster == 1) {
198 TRGGRLMatch* match = new TRGGRLMatch(trackList3D[i], ClusterArray[0], 1);
199 matchList.push_back(match);
200 } else {
201 int best_j = 0; double old_dr = 99999;
202 for (unsigned j = 0; j < n_cluster; j++) {
203 TRGGRLMatch* match = new TRGGRLMatch(trackList3D[i], ClusterArray[j], 0);
204 if (match->getDr() < old_dr) {best_j = j; old_dr = match->getDr();}
205 delete match;
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)
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: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:253
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:258
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.