KaliVeda
Toolkit for HIC analysis
KVEventMixer.h
1 #ifndef KVEventMixer_H
2 #define KVEventMixer_H
3 
4 #include <vector>
5 #include <deque>
6 
263 template<typename ParticleInfoStruct, int NumBins = 1>
265  struct event {
266  std::vector<ParticleInfoStruct> particles;
267 
268  event() = default;
269  event(event&&) = default;
270  event(const event&) = default;
271  event(const ParticleInfoStruct& p)
272  {
273  add(p);
274  }
275  void add(const ParticleInfoStruct& p)
276  {
277  particles.push_back(p);
278  }
279  };
280 
281  struct bin_data {
282  std::deque<event> partA_events;
283  std::deque<event> partB_events;
284  };
285  bin_data bins[NumBins];
286 
287  // number of events used for decorrelation (event mixing)
288  typename std::deque<event>::size_type decor_events = 10;
289 
290 public:
296  KVEventMixer(typename std::deque<event>::size_type number_of_events_to_mix = 10)
297  : decor_events{number_of_events_to_mix}
298  {}
299 
378  template<typename TreatCorPairFunc, typename TreatNCorPairFunc, typename partA_iterator, typename partB_iterator>
379  void ProcessEvent(int bin_number, partA_iterator iter_A, partB_iterator iter_B, TreatCorPairFunc TreatCorPair, TreatNCorPairFunc TreatNCorPair)
380  {
381  int n_partA(0), n_partB(0);
382 
383  for (auto& partA : iter_A) {
384  // store partA in new correlated event in list
385  ++n_partA;
386  if (n_partA == 1) bins[bin_number].partA_events.push_back(ParticleInfoStruct(partA));
387  else bins[bin_number].partA_events.back().add(ParticleInfoStruct(partA));
388 
389  for (auto& partB : iter_B) {
390  if (n_partA == 1) { // each partA will loop over all partB, only add partB event once!
391  // store partB in new correlated event in list
392  ++n_partB;
393  if (n_partB == 1) bins[bin_number].partB_events.push_back(ParticleInfoStruct(partB));
394  else bins[bin_number].partB_events.back().add(ParticleInfoStruct(partB));
395  }
396  TreatCorPair(bin_number, partA, partB);
397  }
398  }
399  if (!n_partA) {
400  // treat events with no A particles, which may still have B particles
401  // in this case the B particles should be added to the mixing buffers
402  for (auto& partB : iter_B) {
403  // store partB in new correlated event in list
404  ++n_partB;
405  if (n_partB == 1) bins[bin_number].partB_events.push_back(ParticleInfoStruct(partB));
406  else bins[bin_number].partB_events.back().add(ParticleInfoStruct(partB));
407  }
408  }
409 
410  // DECORRELATION
411  if (n_partA
412  &&
413  ((bins[bin_number].partB_events.size() == decor_events && !n_partB)
414  || bins[bin_number].partB_events.size() == (decor_events + 1) && n_partB)) {
415  // uncorrelated spectra using each partA of this event and all partB in each of last decor_events
416  for (auto& partA : iter_A) {
417  for (int i = 0; i < decor_events; ++i) {
418  auto& e = bins[bin_number].partB_events[i];
419  for (auto& partB : e.particles) {
420  TreatNCorPair(bin_number, partA, partB);
421  }
422  }
423  }
424  }
425  if (n_partB &&
426  ((bins[bin_number].partA_events.size() == decor_events && !n_partA)
427  || bins[bin_number].partA_events.size() == (decor_events + 1) && n_partA)) {
428  // uncorrelated spectra using each partB of this event and all partA in each of last decor_events
429  for (auto& partB : iter_B) {
430  for (int i = 0; i < decor_events; ++i) {
431  auto& e = bins[bin_number].partA_events[i];
432  for (auto& partA : e.particles) {
433  TreatNCorPair(bin_number, partB, partA);
434  }
435  }
436  }
437  }
438 
439  // keep only last decor_events events in lists
440  if (bins[bin_number].partA_events.size() > decor_events) {
441  // remove oldest (first) event
442  bins[bin_number].partA_events.pop_front();
443  }
444  if (bins[bin_number].partB_events.size() > decor_events) {
445  // remove oldest (first) event
446  bins[bin_number].partB_events.pop_front();
447  }
448 
449  }
450 };
451 #endif // KVEventMixer_H
452 
#define e(i)
winID h TVirtualViewer3D TVirtualGLPainter p
Generic event mixing algorithm for two-particle correlation studies.
Definition: KVEventMixer.h:264
bin_data bins[NumBins]
Definition: KVEventMixer.h:285
KVEventMixer(typename std::deque< event >::size_type number_of_events_to_mix=10)
Definition: KVEventMixer.h:296
void ProcessEvent(int bin_number, partA_iterator iter_A, partB_iterator iter_B, TreatCorPairFunc TreatCorPair, TreatNCorPairFunc TreatNCorPair)
Event-by-event processing function.
Definition: KVEventMixer.h:379
std::deque< event >::size_type decor_events
Definition: KVEventMixer.h:288
std::deque< event > partB_events
Definition: KVEventMixer.h:283
std::deque< event > partA_events
Definition: KVEventMixer.h:282
std::vector< ParticleInfoStruct > particles
Definition: KVEventMixer.h:266
void add(const ParticleInfoStruct &p)
Definition: KVEventMixer.h:275
event(event &&)=default
event(const event &)=default
event(const ParticleInfoStruct &p)
Definition: KVEventMixer.h:271