<commit_before>/** Copyright (C) 2016, 2017 European Spallation Source ERIC */

#include <multigrid/mgmesytec/EfuCenterMass.h>
#include <test/TestBase.h>

using namespace Multigrid;

class EfuCenterMassTest : public TestBase {
protected:
  EfuCenterMass efu;
  virtual void SetUp() {
    efu.mappings.add_bus(BusGeometry());
  }
  virtual void TearDown() {
  }
};

TEST_F(EfuCenterMassTest, DefaultConstructed) {
  EXPECT_FALSE(efu.event_good());
}

TEST_F(EfuCenterMassTest, WireOnly) {
  Hit wire_hit;
  wire_hit.adc = 10;
  wire_hit.channel = 7;
  EXPECT_TRUE(efu.mappings.isWire(wire_hit.bus, wire_hit.channel));
  efu.ingest(wire_hit);
  EXPECT_FALSE(efu.event_good());
  EXPECT_EQ(efu.x(), efu.mappings.x(wire_hit.bus, wire_hit.channel));
  EXPECT_EQ(efu.z(), efu.mappings.z(wire_hit.bus, wire_hit.channel));
}

TEST_F(EfuCenterMassTest, GridOnly) {
  Hit grid_hit;
  grid_hit.adc = 10;
  grid_hit.channel = 90;
  EXPECT_TRUE(efu.mappings.isGrid(grid_hit.bus, grid_hit.channel));
  efu.ingest(grid_hit);
  EXPECT_FALSE(efu.event_good());
  EXPECT_EQ(efu.y(), efu.mappings.y(grid_hit.bus, grid_hit.channel));
}

TEST_F(EfuCenterMassTest, WireAndGrid) {
  Hit wire_hit;
  wire_hit.adc = 10;
  wire_hit.channel = 7;
  EXPECT_TRUE(efu.mappings.isWire(wire_hit.bus, wire_hit.channel));
  efu.ingest(wire_hit);

  Hit grid_hit;
  grid_hit.adc = 10;
  grid_hit.channel = 90;
  EXPECT_TRUE(efu.mappings.isGrid(grid_hit.bus, grid_hit.channel));
  efu.ingest(grid_hit);

  ASSERT_TRUE(efu.event_good());

  EXPECT_EQ(efu.x(), efu.mappings.x(wire_hit.bus, wire_hit.channel));
  EXPECT_EQ(efu.y(), efu.mappings.y(grid_hit.bus, grid_hit.channel));
  EXPECT_EQ(efu.z(), efu.mappings.z(wire_hit.bus, wire_hit.channel));
}

TEST_F(EfuCenterMassTest, HighestAdcWire) {
  Hit hit1;
  hit1.channel = 10;
  hit1.adc = 10;
  efu.ingest(hit1);
  EXPECT_EQ(efu.x(), efu.mappings.x(hit1.bus, hit1.channel));

  Hit hit2;
  hit2.channel = 25;
  hit2.adc = 10;
  efu.ingest(hit2);
  EXPECT_EQ(efu.x(), 0);
<commit_msg>added unit test for EfuCenterMass::ingest(vector of hits)<commit_after>/** Copyright (C) 2016, 2017 European Spallation Source ERIC */

#include <multigrid/mgmesytec/EfuCenterMass.h>
#include <test/TestBase.h>

using namespace Multigrid;

class EfuCenterMassTest : public TestBase {
protected:
  EfuCenterMass efu;
  virtual void SetUp() {
    efu.mappings.add_bus(BusGeometry());
  }
  virtual void TearDown() {
  }
};

TEST_F(EfuCenterMassTest, DefaultConstructed) {
  EXPECT_FALSE(efu.event_good());
}

TEST_F(EfuCenterMassTest, WireOnly) {
  Hit wire_hit;
  wire_hit.adc = 10;
  wire_hit.channel = 7;
  EXPECT_TRUE(efu.mappings.isWire(wire_hit.bus, wire_hit.channel));
  efu.ingest(wire_hit);
  EXPECT_FALSE(efu.event_good());
  EXPECT_EQ(efu.x(), efu.mappings.x(wire_hit.bus, wire_hit.channel));
  EXPECT_EQ(efu.z(), efu.mappings.z(wire_hit.bus, wire_hit.channel));
}

TEST_F(EfuCenterMassTest, GridOnly) {
  Hit grid_hit;
  grid_hit.adc = 10;
  grid_hit.channel = 90;
  EXPECT_TRUE(efu.mappings.isGrid(grid_hit.bus, grid_hit.channel));
  efu.ingest(grid_hit);
  EXPECT_FALSE(efu.event_good());
  EXPECT_EQ(efu.y(), efu.mappings.y(grid_hit.bus, grid_hit.channel));
}

TEST_F(EfuCenterMassTest, WireAndGrid) {
  Hit wire_hit;
  wire_hit.adc = 10;
  wire_hit.channel = 7;
  EXPECT_TRUE(efu.mappings.isWire(wire_hit.bus, wire_hit.channel));
  efu.ingest(wire_hit);

  Hit grid_hit;
  grid_hit.adc = 10;
  grid_hit.channel = 90;
  EXPECT_TRUE(efu.mappings.isGrid(grid_hit.bus, grid_hit.channel));
  efu.ingest(grid_hit);

  ASSERT_TRUE(efu.event_good());

  EXPECT_EQ(efu.x(), efu.mappings.x(wire_hit.bus, wire_hit.channel));
  EXPECT_EQ(efu.y(), efu.mappings.y(grid_hit.bus, grid_hit.channel));
  EXPECT_EQ(efu.z(), efu.mappings.z(wire_hit.bus, wire_hit.channel));
}

TEST_F(EfuCenterMassTest, Ingest) {
  Hit hit1, hit2;
  hit1.channel = 10;
  hit1.adc = 10;
  hit2.channel = 20;
  hit2.adc = 20;
  std::vector<Hit> hits = {hit1, hit2};

  auto ingested = efu.ingest(hits);
  EXPECT_EQ(ingested, 2);

  hit1.external_trigger = 7; // Just need != 0 in this test
  hits = {hit1, hit2};
  ingested = efu.ingest(hits);
  EXPECT_EQ(ingested, 1);
}

TEST_F(EfuCenterMassTest, HighestAdcWire) {
  Hit hit1;
  hit1.channel = 10;
  hit1.adc = 10;
  efu.ingest(hit1);
  EXPECT_EQ(efu.x(), efu.mappings.x(hit1.bus, hit1.channel));

  Hit hit2;
  hit2.channel = 25;
  hit2.adc = 10;
  efu.ingest(hit2);
  EXPECT_EQ(efu.x(), 0);

{'fraction_non_alphanumeric': 0.15123386914195155, 'fraction_numerical': 0.02377179080824089, 'mean_word_length': 4.790301441677588, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7553316', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1896, 'n_words': 277}