//
// Pibero Djawotho <pibero@indiana.edu>
// Indiana University
// 20 May 2007
//
// StEventMixer.cxx
//
// Event mixing class for background subtraction in e+e- pair production.
// This class is fashioned after the NA49 event mixer:
//
// http://na49info.cern.ch/na49/Software/minidst/ana/html/T49Mixing.html
//

// C++ STL
#include <iostream>

// ROOT includes
#include "TRandom.h"

// Local includes
#include "Event.h"
#include "StEventMixer.h"

ClassImp(StEventMixer);

void StEventMixer::addEvent(Event* event)
{
  int refmult = event->refMult();

  if (refmult >= MAX_REFMULT) {
    cout << "Warning: refmult = " << refmult << " exceeds " << MAX_REFMULT-1 << endl;
    return;
  }

  mEvents[refmult].push_back(new Event(*event));

  if (mEvents[refmult].size() > MAX_EVENTS) {
    delete mEvents[refmult].front();
    mEvents[refmult].pop_front();
  }
}

Event* StEventMixer::getEvent(int refmult)
{
  if (refmult >= MAX_REFMULT) return 0;
  int i = gRandom->Integer(mEvents[refmult].size());
  return mEvents[refmult][i];
}
