//
// Pibero Djawotho <pibero@indiana.edu>
// Indiana University
// Nov 18 2007
//

// C++ STL
#include <iostream>
using namespace std;

// Local
#include "Upsilon.hh"
#include "StHeavyTrigger.h"

Upsilon ups;

ClassImp(StHeavyTrigger);

bool StHeavyTrigger::isHT(int ht) const
{
  for (int i = 0; i < NPATCHES; ++i)
    if (mHT[i] > ht)
      return true;
  return false;
}

bool StHeavyTrigger::isHTW(int htw) const
{
  for (int i = 0; i < 150; ++i)
    if (mHT[i] > htw)
      return true;
  return false;
}

bool StHeavyTrigger::isHTE(int hte) const
{
  for (int i = 150; i < NPATCHES; ++i)
    if (mHT[i] > hte)
      return true;
  return false;
}

bool StHeavyTrigger::isHTTP(int ht, int tp) const
{
  for (int i = 0; i < NPATCHES; ++i)
    if (mHT[i] > ht && mTP[i] > tp)
      return true;
  return false;
}

bool StHeavyTrigger::isTrigger(int id) const
{
  // 2006 trigger ids
  switch (id) {
  case 117201:			// bemc-http-mb
    return isHTTP(12, 17);

  case 117211:			// bemc-ht2-mb
  case 117212:			// bemc-ht2-mb-emul
    return isHT(22);

  case 127212:			// bemc-ht2-mb-emul (east & west thresholds differ)
    return isHTE(22) && isHTW(24);

  case 127213:			// bemc-ht2-mb-emul
    return isHT(24);

  case 137213:			// bemc-ht2-mb-emul
  case 137822:			// bemc-http-mb-fast
  case 137586:			// bemc-http
    return isHTTP(16, 19);

#if 0
    // Upsilon 2006 p+p
  case 117602: return isHTTP(12, 17) && ups.run(mTriggerData, mBemcData);
  case 137603: return isHTTP(16, 19) && ups.run(mTriggerData, mBemcData);
#endif

    // Upsilon 2007 Au+Au
  case 200601:
  case 200602: return isHT(18) && ups.run(mTriggerData, mBemcData);


    // Upsilon 2008 d+Au
  case 210601: return  ups.run(mTriggerData, mBemcData);


    // 	BEMC-HT2 2008 d+Au
  case 210521: return  ups.run(mTriggerData, mBemcData);

  default:
    cout << "Trigger " << id << " not implemented" << endl;
    exit(1);
  }
}
