KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVEventMixer.h
Go to the documentation of this file.
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  // keep only last decor_events events in lists
411  if (bins[bin_number].partA_events.size() > decor_events) {
412  // remove oldest (first) event
413  bins[bin_number].partA_events.pop_front();
414  }
415  if (bins[bin_number].partB_events.size() > decor_events) {
416  // remove oldest (first) event
417  bins[bin_number].partB_events.pop_front();
418  }
419 
420  // DECORRELATION
421  if (n_partA && bins[bin_number].partB_events.size() == decor_events) {
422  // uncorrelated spectra using each partA of this event and all partB in each of last decor_events
423  for (auto& partA : iter_A) {
424  for (auto& e : bins[bin_number].partB_events) {
425  for (auto& partB : e.particles) {
426  TreatNCorPair(bin_number, partA, partB);
427  }
428  }
429  }
430  }
431  if (n_partB && bins[bin_number].partA_events.size() == decor_events) {
432  // uncorrelated spectra using each partB of this event and all partA in each of last decor_events
433  for (auto& partB : iter_B) {
434  for (auto& e : bins[bin_number].partA_events) {
435  for (auto& partA : e.particles) {
436  TreatNCorPair(bin_number, partB, partA);
437  }
438  }
439  }
440  }
441 
442  }
443 };
444 #endif // KVEventMixer_H
445 
#define e(i)
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