CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lheh5.cc
Go to the documentation of this file.
2 
3 namespace lheh5 {
4 
5  inline std::ostream& operator<<(std::ostream& os, Particle const& p) {
6  os << "\tpx: " << p.px << " py: " << p.py << " pz: " << p.pz << " e: " << p.e << "\n";
7  return os;
8  }
9 
10  inline std::ostream& operator<<(std::ostream& os, EventHeader const& eh) {
11  os << "\tnparticles: " << eh.nparticles << " procid: " << eh.pid << " weight: " << eh.weight
12  << " trials: " << eh.trials << "\n";
13  os << "\tscale: " << eh.scale << " rscale: " << eh.rscale << " fscale: " << eh.fscale << " aqed: " << eh.aqed
14  << " aqcd: " << eh.aqcd << "\n";
15  os << "\tnpLO: " << eh.npLO << " npNLO: " << eh.npNLO << "\n";
16  return os;
17  }
18 
19  Particle Events::mkParticle(size_t idx) const {
20  return {_vid[idx],
21  _vstatus[idx],
22  _vmother1[idx],
23  _vmother2[idx],
24  _vcolor1[idx],
25  _vcolor2[idx],
26  _vpx[idx],
27  _vpy[idx],
28  _vpz[idx],
29  _ve[idx],
30  _vm[idx],
31  _vlifetime[idx],
32  _vspin[idx]};
33  }
34 
35  std::vector<Particle> Events::mkEvent(size_t ievent) const {
36  std::vector<Particle> _E;
37  // NOTE we need to subtract the particle offset here as the
38  // particle properties run from 0 and not the global index when using batches
39  for (size_t id = _vstart[ievent] - _particle_offset; id < _vend[ievent] - _particle_offset; ++id) {
40  _E.push_back(mkParticle(id));
41  }
42 
43  // Make sure beam particles are ordered according to convention i.e. first particle has positive z-momentum
44  if (_E[0].pz < 0) {
45  std::swap<Particle>(_E[0], _E[1]);
46  }
47 
48  return _E;
49  }
50 
52  return {
54  _vpid[iev],
55  _vweight[iev],
56  _vtrials[iev],
57  _vscale[iev],
58  _vrscale[iev],
59  _vfscale[iev],
60  _vaqed[iev],
61  _vaqcd[iev],
62  _vnpLO[iev],
63  _vnpNLO[iev],
64  };
65  }
66 
67  // Read function, returns an Events struct
68  Events readEvents(HighFive::Group& g_index,
69  HighFive::Group& g_particle,
70  HighFive::Group& g_event,
71  size_t first_event,
72  size_t n_events) {
73  // Lookup
74  std::vector<size_t> _vstart, _vend;
75  // Particles
76  std::vector<int> _vid, _vstatus, _vmother1, _vmother2, _vcolor1, _vcolor2;
77  std::vector<double> _vpx, _vpy, _vpz, _ve, _vm, _vlifetime, _vspin;
78  // Event info
79  std::vector<int> _vnparticles, _vpid, _vnpLO, _vnpNLO;
80  std::vector<size_t> _vtrials;
81  std::vector<double> _vweight, _vscale, _vrscale, _vfscale, _vaqed, _vaqcd;
82 
83  //double starttime, endtime;
84  //starttime = MPI_Wtime();
85  // Lookup
86  HighFive::DataSet _start = g_index.getDataSet("start");
87  HighFive::DataSet _end = g_index.getDataSet("end");
88  // Particles
89  HighFive::DataSet _id = g_particle.getDataSet("id");
90  HighFive::DataSet _status = g_particle.getDataSet("status");
91  HighFive::DataSet _mother1 = g_particle.getDataSet("mother1");
92  HighFive::DataSet _mother2 = g_particle.getDataSet("mother2");
93  HighFive::DataSet _color1 = g_particle.getDataSet("color1");
94  HighFive::DataSet _color2 = g_particle.getDataSet("color2");
95  HighFive::DataSet _px = g_particle.getDataSet("px");
96  HighFive::DataSet _py = g_particle.getDataSet("py");
97  HighFive::DataSet _pz = g_particle.getDataSet("pz");
98  HighFive::DataSet _e = g_particle.getDataSet("e");
99  HighFive::DataSet _m = g_particle.getDataSet("m");
100  HighFive::DataSet _lifetime = g_particle.getDataSet("lifetime");
101  HighFive::DataSet _spin = g_particle.getDataSet("spin");
102  // Event info
103  HighFive::DataSet _nparticles = g_event.getDataSet("nparticles");
104  HighFive::DataSet _pid = g_event.getDataSet("pid");
105  HighFive::DataSet _weight = g_event.getDataSet("weight");
106  HighFive::DataSet _trials = g_event.getDataSet("trials");
107  HighFive::DataSet _scale = g_event.getDataSet("scale");
108  HighFive::DataSet _rscale = g_event.getDataSet("rscale");
109  HighFive::DataSet _fscale = g_event.getDataSet("fscale");
110  HighFive::DataSet _aqed = g_event.getDataSet("aqed");
111  HighFive::DataSet _aqcd = g_event.getDataSet("aqcd");
112  HighFive::DataSet _npLO = g_event.getDataSet("npLO");
113  HighFive::DataSet _npNLO = g_event.getDataSet("npNLO");
114 
115  //endtime = MPI_Wtime();
116  //printf("DS took %f seconds\n", endtime-starttime);
117  std::vector<size_t> offset_e = {first_event};
118  std::vector<size_t> readsize_e = {n_events};
119  //_vstart.reserve(n_events);
120  //_vend.reserve(n_events);
121 
122  _start.select(offset_e, readsize_e).read(_vstart);
123  _end.select(offset_e, readsize_e).read(_vend);
124  std::vector<size_t> offset_p = {_vstart.front()};
125  std::vector<size_t> readsize_p = {_vend.back() - _vstart.front()};
126 
127  int RESP = _vend.back() - _vstart.front();
128  _vid.reserve(RESP);
129  _vstatus.reserve(RESP);
130  _vmother1.reserve(RESP);
131  _vmother2.reserve(RESP);
132  _vcolor1.reserve(RESP);
133  _vcolor2.reserve(RESP);
134  _vpx.reserve(RESP);
135  _vpy.reserve(RESP);
136  _vpz.reserve(RESP);
137  _ve.reserve(RESP);
138  _vm.reserve(RESP);
139  _vlifetime.reserve(RESP);
140  _vspin.reserve(RESP);
141 
142  _vnparticles.reserve(n_events);
143  _vpid.reserve(n_events);
144  _vweight.reserve(n_events);
145  _vtrials.reserve(n_events);
146  _vscale.reserve(n_events);
147  _vrscale.reserve(n_events);
148  _vfscale.reserve(n_events);
149  _vaqed.reserve(n_events);
150  _vaqcd.reserve(n_events);
151  _vnpLO.reserve(n_events);
152  _vnpNLO.reserve(n_events);
153 
154  //starttime = MPI_Wtime();
155  // This is using HighFive's read
156  _id.select(offset_p, readsize_p).read(_vid);
157  _status.select(offset_p, readsize_p).read(_vstatus);
158  _mother1.select(offset_p, readsize_p).read(_vmother1);
159  _mother2.select(offset_p, readsize_p).read(_vmother2);
160  _color1.select(offset_p, readsize_p).read(_vcolor1);
161  _color2.select(offset_p, readsize_p).read(_vcolor2);
162  _px.select(offset_p, readsize_p).read(_vpx);
163  _py.select(offset_p, readsize_p).read(_vpy);
164  _pz.select(offset_p, readsize_p).read(_vpz);
165  _e.select(offset_p, readsize_p).read(_ve);
166  _m.select(offset_p, readsize_p).read(_vm);
167  _lifetime.select(offset_p, readsize_p).read(_vlifetime);
168  _spin.select(offset_p, readsize_p).read(_vspin);
169 
170  //endtime = MPI_Wtime();
171  //printf("SELP took %f seconds\n", endtime-starttime);
172  //starttime = MPI_Wtime();
173  _nparticles.select(offset_e, readsize_e).read(_vnparticles);
174  _pid.select(offset_e, readsize_e).read(_vpid);
175  _weight.select(offset_e, readsize_e).read(_vweight);
176  _trials.select(offset_e, readsize_e).read(_vtrials);
177  _scale.select(offset_e, readsize_e).read(_vscale);
178  _rscale.select(offset_e, readsize_e).read(_vrscale);
179  _fscale.select(offset_e, readsize_e).read(_vfscale);
180  _aqed.select(offset_e, readsize_e).read(_vaqed);
181  _aqcd.select(offset_e, readsize_e).read(_vaqcd);
182  _npLO.select(offset_e, readsize_e).read(_vnpLO);
183  _npNLO.select(offset_e, readsize_e).read(_vnpNLO);
184  //endtime = MPI_Wtime();
185  //printf("SELE took %f seconds\n", endtime-starttime);
186 
187  return {
188  std::move(_vstart), std::move(_vend), std::move(_vid), std::move(_vstatus), std::move(_vmother1),
189  std::move(_vmother2), std::move(_vcolor1), std::move(_vcolor2), std::move(_vpx), std::move(_vpy),
190  std::move(_vpz), std::move(_ve), std::move(_vm), std::move(_vlifetime), std::move(_vspin),
191  std::move(_vnparticles), std::move(_vpid), std::move(_vweight), std::move(_vtrials), std::move(_vscale),
192  std::move(_vrscale), std::move(_vfscale), std::move(_vaqed), std::move(_vaqcd), std::move(_vnpLO),
193  std::move(_vnpNLO), offset_p[0],
194  };
195  }
196 
197  Particle Events2::mkParticle(size_t idx) const {
198  return {_vid[idx],
199  _vstatus[idx],
200  _vmother1[idx],
201  _vmother2[idx],
202  _vcolor1[idx],
203  _vcolor2[idx],
204  _vpx[idx],
205  _vpy[idx],
206  _vpz[idx],
207  _ve[idx],
208  _vm[idx],
209  _vlifetime[idx],
210  _vspin[idx]};
211  }
212 
213  std::vector<Particle> Events2::mkEvent(size_t ievent) const {
214  std::vector<Particle> _E;
215  // NOTE we need to subtract the particle offset here as the
216  // particle properties run from 0 and not the global index when using batches
217  size_t partno = _vstart[ievent] - _particle_offset;
218  for (int id = 0; id < _vnparticles[ievent]; ++id) {
219  _E.push_back(mkParticle(partno));
220  partno++;
221  }
222 
223  // Make sure beam particles are ordered according to convention i.e. first particle has positive z-momentum
224  if (_E[0].pz < 0) {
225  std::swap<Particle>(_E[0], _E[1]);
226  }
227 
228  return _E;
229  }
230 
232  return {
233  _vnparticles[iev],
234  _vpid[iev],
235  _vweight[iev],
236  _vtrials[iev],
237  _vscale[iev],
238  _vrscale[iev],
239  _vfscale[iev],
240  _vaqed[iev],
241  _vaqcd[iev],
242  npLO,
243  npNLO,
244  };
245  }
246 
247  // Read function, returns an Events struct --- this is for the new structure
249  HighFive::Group& g_particle, HighFive::Group& g_event, size_t first_event, size_t n_events, int npLO, int npNLO) {
250  // Lookup
251  std::vector<size_t> _vstart;
252  // Particles
253  std::vector<int> _vid, _vstatus, _vmother1, _vmother2, _vcolor1, _vcolor2;
254  std::vector<double> _vpx, _vpy, _vpz, _ve, _vm, _vlifetime, _vspin;
255  // Event info
256  std::vector<int> _vnparticles, _vpid;
257  std::vector<size_t> _vtrials;
258  std::vector<double> _vweight, _vscale, _vrscale, _vfscale, _vaqed, _vaqcd;
259 
260  //double starttime, endtime;
261  // Lookup
262  HighFive::DataSet _start = g_event.getDataSet("start");
263  // Particles
264  HighFive::DataSet _id = g_particle.getDataSet("id");
265  HighFive::DataSet _status = g_particle.getDataSet("status");
266  HighFive::DataSet _mother1 = g_particle.getDataSet("mother1");
267  HighFive::DataSet _mother2 = g_particle.getDataSet("mother2");
268  HighFive::DataSet _color1 = g_particle.getDataSet("color1");
269  HighFive::DataSet _color2 = g_particle.getDataSet("color2");
270  HighFive::DataSet _px = g_particle.getDataSet("px");
271  HighFive::DataSet _py = g_particle.getDataSet("py");
272  HighFive::DataSet _pz = g_particle.getDataSet("pz");
273  HighFive::DataSet _e = g_particle.getDataSet("e");
274  HighFive::DataSet _m = g_particle.getDataSet("m");
275  HighFive::DataSet _lifetime = g_particle.getDataSet("lifetime");
276  HighFive::DataSet _spin = g_particle.getDataSet("spin");
277  // Event info
278  HighFive::DataSet _nparticles = g_event.getDataSet("nparticles");
279  HighFive::DataSet _pid = g_event.getDataSet("pid");
280  HighFive::DataSet _weight = g_event.getDataSet("weight");
281  HighFive::DataSet _trials = g_event.getDataSet("trials");
282  HighFive::DataSet _scale = g_event.getDataSet("scale");
283  HighFive::DataSet _rscale = g_event.getDataSet("rscale");
284  HighFive::DataSet _fscale = g_event.getDataSet("fscale");
285  HighFive::DataSet _aqed = g_event.getDataSet("aqed");
286  HighFive::DataSet _aqcd = g_event.getDataSet("aqcd");
287 
288  std::vector<size_t> offset_e = {first_event};
289  std::vector<size_t> readsize_e = {n_events};
290 
291  // We now know the first event to read
292  _start.select(offset_e, readsize_e).read(_vstart);
293 
294  // That's the first particle
295  std::vector<size_t> offset_p = {_vstart.front()};
296  // The last particle is last entry in start + nparticles of that event
297  _vnparticles.reserve(n_events);
298  _nparticles.select(offset_e, readsize_e).read(_vnparticles);
299 
300  size_t RESP = _vstart.back() - _vstart.front() + _vnparticles.back();
301  std::vector<size_t> readsize_p = {RESP};
302 
303  _vid.reserve(RESP);
304  _vstatus.reserve(RESP);
305  _vmother1.reserve(RESP);
306  _vmother2.reserve(RESP);
307  _vcolor1.reserve(RESP);
308  _vcolor2.reserve(RESP);
309  _vpx.reserve(RESP);
310  _vpy.reserve(RESP);
311  _vpz.reserve(RESP);
312  _ve.reserve(RESP);
313  _vm.reserve(RESP);
314  _vlifetime.reserve(RESP);
315  _vspin.reserve(RESP);
316 
317  _vpid.reserve(n_events);
318  _vweight.reserve(n_events);
319  _vtrials.reserve(n_events);
320  _vscale.reserve(n_events);
321  _vrscale.reserve(n_events);
322  _vfscale.reserve(n_events);
323  _vaqed.reserve(n_events);
324  _vaqcd.reserve(n_events);
325 
326  // This is using HighFive's read
327  _id.select(offset_p, readsize_p).read(_vid);
328  _status.select(offset_p, readsize_p).read(_vstatus);
329  _mother1.select(offset_p, readsize_p).read(_vmother1);
330  _mother2.select(offset_p, readsize_p).read(_vmother2);
331  _color1.select(offset_p, readsize_p).read(_vcolor1);
332  _color2.select(offset_p, readsize_p).read(_vcolor2);
333  _px.select(offset_p, readsize_p).read(_vpx);
334  _py.select(offset_p, readsize_p).read(_vpy);
335  _pz.select(offset_p, readsize_p).read(_vpz);
336  _e.select(offset_p, readsize_p).read(_ve);
337  _m.select(offset_p, readsize_p).read(_vm);
338  _lifetime.select(offset_p, readsize_p).read(_vlifetime);
339  _spin.select(offset_p, readsize_p).read(_vspin);
340 
341  _pid.select(offset_e, readsize_e).read(_vpid);
342  _weight.select(offset_e, readsize_e).read(_vweight);
343  _trials.select(offset_e, readsize_e).read(_vtrials);
344  _scale.select(offset_e, readsize_e).read(_vscale);
345  _rscale.select(offset_e, readsize_e).read(_vrscale);
346  _fscale.select(offset_e, readsize_e).read(_vfscale);
347  _aqed.select(offset_e, readsize_e).read(_vaqed);
348  _aqcd.select(offset_e, readsize_e).read(_vaqcd);
349 
350  return {
351  std::move(_vstart),
352  std::move(_vid),
353  std::move(_vstatus),
354  std::move(_vmother1),
355  std::move(_vmother2),
356  std::move(_vcolor1),
357  std::move(_vcolor2),
358  std::move(_vpx),
359  std::move(_vpy),
360  std::move(_vpz),
361  std::move(_ve),
362  std::move(_vm),
363  std::move(_vlifetime),
364  std::move(_vspin),
365  std::move(_vnparticles),
366  std::move(_vpid),
367  std::move(_vweight),
368  std::move(_vtrials),
369  std::move(_vscale),
370  std::move(_vrscale),
371  std::move(_vfscale),
372  std::move(_vaqed),
373  std::move(_vaqcd),
374  npLO,
375  npNLO,
376  offset_p[0],
377  };
378  }
379 
380 } // namespace lheh5
std::vector< Particle > mkEvent(size_t ievent) const
Definition: lheh5.cc:213
std::vector< double > _vpx
Definition: lheh5.h:54
double fscale
Definition: lheh5.h:36
double pz
Definition: lheh5.h:18
std::vector< int > _vnparticles
Definition: lheh5.h:98
std::vector< double > _vpy
Definition: lheh5.h:55
EventHeader mkEventHeader(int ievent) const
Definition: lheh5.cc:51
std::vector< size_t > _vtrials
Definition: lheh5.h:101
std::vector< double > _vlifetime
Definition: lheh5.h:59
std::vector< double > _vlifetime
Definition: lheh5.h:95
std::vector< int > _vid
Definition: lheh5.h:84
std::vector< double > _vaqcd
Definition: lheh5.h:106
uint16_t *__restrict__ id
std::vector< double > _vrscale
Definition: lheh5.h:103
std::vector< double > _vpx
Definition: lheh5.h:90
double px
Definition: lheh5.h:18
std::vector< double > _vscale
Definition: lheh5.h:102
std::vector< size_t > _vstart
Definition: lheh5.h:45
std::vector< Particle > mkEvent(size_t ievent) const
Definition: lheh5.cc:35
std::vector< int > _vcolor2
Definition: lheh5.h:53
Events readEvents(HighFive::Group &g_index, HighFive::Group &g_particle, HighFive::Group &g_event, size_t first_event, size_t n_events)
Definition: lheh5.cc:68
std::vector< double > _vaqcd
Definition: lheh5.h:70
double scale
Definition: lheh5.h:34
std::vector< size_t > _vstart
Definition: lheh5.h:82
std::vector< int > _vcolor1
Definition: lheh5.h:52
std::vector< int > _vmother2
Definition: lheh5.h:51
double weight
Definition: lheh5.h:32
size_t _particle_offset
Definition: lheh5.h:109
double aqed
Definition: lheh5.h:37
std::vector< double > _vm
Definition: lheh5.h:58
std::vector< double > _vweight
Definition: lheh5.h:64
std::vector< double > _vaqed
Definition: lheh5.h:69
std::vector< size_t > _vend
Definition: lheh5.h:46
EventHeader mkEventHeader(int ievent) const
Definition: lheh5.cc:231
std::vector< int > _vnpNLO
Definition: lheh5.h:72
std::vector< double > _vpz
Definition: lheh5.h:56
std::vector< double > _vspin
Definition: lheh5.h:96
std::vector< double > _vm
Definition: lheh5.h:94
std::vector< double > _vspin
Definition: lheh5.h:60
std::vector< int > _vstatus
Definition: lheh5.h:49
std::vector< double > _vpy
Definition: lheh5.h:91
def move
Definition: eostools.py:511
std::vector< int > _vnpLO
Definition: lheh5.h:71
std::vector< int > _vnparticles
Definition: lheh5.h:62
std::vector< int > _vstatus
Definition: lheh5.h:85
std::vector< int > _vmother2
Definition: lheh5.h:87
std::vector< double > _vfscale
Definition: lheh5.h:104
size_t _particle_offset
Definition: lheh5.h:73
std::vector< double > _ve
Definition: lheh5.h:57
std::vector< int > _vid
Definition: lheh5.h:48
std::vector< int > _vpid
Definition: lheh5.h:63
double rscale
Definition: lheh5.h:35
std::vector< double > _vaqed
Definition: lheh5.h:105
size_t trials
Definition: lheh5.h:33
std::vector< size_t > _vtrials
Definition: lheh5.h:65
std::vector< double > _vpz
Definition: lheh5.h:92
std::ostream & operator<<(std::ostream &os, Particle const &p)
Definition: lheh5.cc:5
std::vector< double > _vfscale
Definition: lheh5.h:68
Particle mkParticle(size_t idx) const
Definition: lheh5.cc:19
std::vector< double > _ve
Definition: lheh5.h:93
std::vector< double > _vrscale
Definition: lheh5.h:67
std::vector< int > _vcolor2
Definition: lheh5.h:89
double py
Definition: lheh5.h:18
Particle mkParticle(size_t idx) const
Definition: lheh5.cc:197
double e
Definition: lheh5.h:18
double aqcd
Definition: lheh5.h:38
std::vector< double > _vscale
Definition: lheh5.h:66
std::vector< int > _vmother1
Definition: lheh5.h:86
std::vector< int > _vcolor1
Definition: lheh5.h:88
std::vector< int > _vpid
Definition: lheh5.h:99
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int iev
std::vector< int > _vmother1
Definition: lheh5.h:50
std::vector< double > _vweight
Definition: lheh5.h:100