CMS 3D CMS Logo

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 
20  return {std::move(_vid[idx]),
26  std::move(_vpx[idx]),
27  std::move(_vpy[idx]),
28  std::move(_vpz[idx]),
29  std::move(_ve[idx]),
30  std::move(_vm[idx]),
32  std::move(_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 {
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 
198  return {std::move(_vid[idx]),
204  std::move(_vpx[idx]),
205  std::move(_vpy[idx]),
206  std::move(_vpz[idx]),
207  std::move(_ve[idx]),
208  std::move(_vm[idx]),
210  std::move(_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 {
234  std::move(_vpid[iev]),
240  std::move(_vaqed[iev]),
241  std::move(_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
iev
const HitContainer *__restrict__ const TkSoA *__restrict__ const Quality *__restrict__ const CAHitNtupletGeneratorKernelsGPU::HitToTuple *__restrict__ uint32_t int iev
Definition: CAHitNtupletGeneratorKernelsImpl.h:544
lheh5::Events2::npNLO
int npNLO
Definition: lheh5.h:108
lheh5::Events::_vstatus
std::vector< int > _vstatus
Definition: lheh5.h:49
lheh5
Definition: lheh5.h:14
lheh5::Events2::_vtrials
std::vector< size_t > _vtrials
Definition: lheh5.h:101
lheh5::Events2::_vcolor1
std::vector< int > _vcolor1
Definition: lheh5.h:88
lheh5::Events::_vnpLO
std::vector< int > _vnpLO
Definition: lheh5.h:71
lheh5::Events::_ve
std::vector< double > _ve
Definition: lheh5.h:57
lheh5::Events::_vnparticles
std::vector< int > _vnparticles
Definition: lheh5.h:62
lheh5::Events::_vpid
std::vector< int > _vpid
Definition: lheh5.h:63
lheh5::Events2::_vpx
std::vector< double > _vpx
Definition: lheh5.h:90
lheh5::Events2::_vnparticles
std::vector< int > _vnparticles
Definition: lheh5.h:98
lheh5::Events::mkEventHeader
EventHeader mkEventHeader(int ievent) const
Definition: lheh5.cc:51
lheh5::Events::_particle_offset
size_t _particle_offset
Definition: lheh5.h:73
lheh5::Events2::_vaqcd
std::vector< double > _vaqcd
Definition: lheh5.h:106
lheh5::Events2::_vid
std::vector< int > _vid
Definition: lheh5.h:84
lheh5::Events2::_vweight
std::vector< double > _vweight
Definition: lheh5.h:100
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
lheh5::Events::_vtrials
std::vector< size_t > _vtrials
Definition: lheh5.h:65
lheh5::Events::_vid
std::vector< int > _vid
Definition: lheh5.h:48
lheh5::Events2::_particle_offset
size_t _particle_offset
Definition: lheh5.h:109
lheh5::Events::_vfscale
std::vector< double > _vfscale
Definition: lheh5.h:68
lheh5::Events::mkEvent
std::vector< Particle > mkEvent(size_t ievent) const
Definition: lheh5.cc:35
lheh5::Events2::_vlifetime
std::vector< double > _vlifetime
Definition: lheh5.h:95
lheh5::EventHeader::weight
double weight
Definition: lheh5.h:32
lheh5.h
lheh5::Events2::_vm
std::vector< double > _vm
Definition: lheh5.h:94
lheh5::Events2::mkParticle
Particle mkParticle(size_t idx) const
Definition: lheh5.cc:197
lheh5::Events2::_vscale
std::vector< double > _vscale
Definition: lheh5.h:102
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
lheh5::Events::_vscale
std::vector< double > _vscale
Definition: lheh5.h:66
EcalDumpRaw_cfi.first_event
first_event
Definition: EcalDumpRaw_cfi.py:25
lheh5::Events2
Definition: lheh5.h:80
lheh5::Events2::_vpy
std::vector< double > _vpy
Definition: lheh5.h:91
lheh5::Events::_vrscale
std::vector< double > _vrscale
Definition: lheh5.h:67
hgcalDigitizer_cfi._m
_m
Definition: hgcalDigitizer_cfi.py:209
lheh5::Events::_vmother1
std::vector< int > _vmother1
Definition: lheh5.h:50
lheh5::Events2::_vspin
std::vector< double > _vspin
Definition: lheh5.h:96
lheh5::EventHeader::npLO
int npLO
Definition: lheh5.h:39
lheh5::Events2::_vstart
std::vector< size_t > _vstart
Definition: lheh5.h:82
lheh5::EventHeader
Definition: lheh5.h:28
lheh5::EventHeader::npNLO
int npNLO
Definition: lheh5.h:40
lheh5::Events::_vpx
std::vector< double > _vpx
Definition: lheh5.h:54
lheh5::Events2::npLO
int npLO
Definition: lheh5.h:107
lheh5::Events2::_vstatus
std::vector< int > _vstatus
Definition: lheh5.h:85
lheh5::Events::mkParticle
Particle mkParticle(size_t idx) const
Definition: lheh5.cc:19
lheh5::Events::_vpy
std::vector< double > _vpy
Definition: lheh5.h:55
lheh5::Events::_vstart
std::vector< size_t > _vstart
Definition: lheh5.h:45
lheh5::EventHeader::trials
size_t trials
Definition: lheh5.h:33
lheh5::Events2::_vmother2
std::vector< int > _vmother2
Definition: lheh5.h:87
lheh5::Events2::_ve
std::vector< double > _ve
Definition: lheh5.h:93
lheh5::Events::_vcolor2
std::vector< int > _vcolor2
Definition: lheh5.h:53
lheh5::Events::_vaqcd
std::vector< double > _vaqcd
Definition: lheh5.h:70
lheh5::Events2::mkEventHeader
EventHeader mkEventHeader(int ievent) const
Definition: lheh5.cc:231
lheh5::Events2::_vfscale
std::vector< double > _vfscale
Definition: lheh5.h:104
lheh5::Events::_vlifetime
std::vector< double > _vlifetime
Definition: lheh5.h:59
lheh5::operator<<
std::ostream & operator<<(std::ostream &os, Particle const &p)
Definition: lheh5.cc:5
lheh5::EventHeader::pid
int pid
Definition: lheh5.h:31
lheh5::readEvents
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
lheh5::Events2::_vmother1
std::vector< int > _vmother1
Definition: lheh5.h:86
eostools.move
def move(src, dest)
Definition: eostools.py:511
lheh5::Events::_vmother2
std::vector< int > _vmother2
Definition: lheh5.h:51
lheh5::EventHeader::nparticles
int nparticles
Definition: lheh5.h:30
lheh5::Events
Definition: lheh5.h:43
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
lheh5::Events::_vcolor1
std::vector< int > _vcolor1
Definition: lheh5.h:52
lheh5::Events::_vaqed
std::vector< double > _vaqed
Definition: lheh5.h:69
lheh5::Events2::_vaqed
std::vector< double > _vaqed
Definition: lheh5.h:105
lheh5::Events::_vend
std::vector< size_t > _vend
Definition: lheh5.h:46
Particle
Definition: Particle.py:1
lheh5::Events2::_vcolor2
std::vector< int > _vcolor2
Definition: lheh5.h:89
lheh5::Events2::_vpid
std::vector< int > _vpid
Definition: lheh5.h:99
lheh5::Events::_vnpNLO
std::vector< int > _vnpNLO
Definition: lheh5.h:72
lheh5::EventHeader::aqed
double aqed
Definition: lheh5.h:37
lheh5::EventHeader::scale
double scale
Definition: lheh5.h:34
lheh5::Events2::_vpz
std::vector< double > _vpz
Definition: lheh5.h:92
lheh5::Events::_vm
std::vector< double > _vm
Definition: lheh5.h:58
lheh5::Events::_vspin
std::vector< double > _vspin
Definition: lheh5.h:60
lheh5::Events::_vweight
std::vector< double > _vweight
Definition: lheh5.h:64
lheh5::Events::_vpz
std::vector< double > _vpz
Definition: lheh5.h:56
lheh5::EventHeader::aqcd
double aqcd
Definition: lheh5.h:38
lheh5::EventHeader::fscale
double fscale
Definition: lheh5.h:36
lheh5::EventHeader::rscale
double rscale
Definition: lheh5.h:35
lheh5::Events2::mkEvent
std::vector< Particle > mkEvent(size_t ievent) const
Definition: lheh5.cc:213
lheh5::Events2::_vrscale
std::vector< double > _vrscale
Definition: lheh5.h:103