Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions AtMap/AtTpcMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,49 @@ XYPoint AtTpcMap::CalcPadCenter(Int_t PadRef)
Float_t y = (AtPadCoord[PadRef][0][1] + AtPadCoord[PadRef][1][1] + AtPadCoord[PadRef][2][1]) / 3.;
return {x, y};
}

Int_t AtTpcMap::InhibitBeamPads(TString beamPadsFilePath)
{
std::ifstream beamPadsFile(beamPadsFilePath.Data());
std::string line;

if (!beamPadsFile.is_open()) {
std::cerr << "Failed to open file: " << beamPadsFilePath.Data() << std::endl;
return -1;
}

// Skip header line.
std::getline(beamPadsFile, line);

// Variables where to read the lines.
int cobo{}, asad{}, aget{}, channel{};

int beamPadCount{};
while (std::getline(beamPadsFile, line)) {
std::stringstream ss(line);
std::string entry;

std::getline(ss, entry, ',');
cobo = std::stoi(entry);

std::getline(ss, entry, ',');
asad = std::stoi(entry);

std::getline(ss, entry, ',');
aget = std::stoi(entry);

std::getline(ss, entry, ',');
channel = std::stoi(entry);

AtPadReference ref = {cobo, asad, aget, channel};
InhibitPad(ref, AtMap::InhibitType::kXTalk);

beamPadCount++;
}

LOG(info) << cYELLOW << beamPadCount << " beam pads have been inhibited." << cNORMAL;

return beamPadCount;
}

ClassImp(AtTpcMap)
2 changes: 2 additions & 0 deletions AtMap/AtTpcMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class AtTpcMap : public AtMap {
virtual ROOT::Math::XYPoint CalcPadCenter(Int_t PadRef) override;
virtual Int_t BinToPad(Int_t binval) override { return binval - 1; };

Int_t InhibitBeamPads(TString beamPadsFilePath);

ClassDefOverride(AtTpcMap, 1);

protected:
Expand Down
53 changes: 53 additions & 0 deletions AtMap/AtTpcMapTest.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "AtTpcMap.h"

#include <FairLogger.h>

#include <TString.h>

#include <gtest/gtest.h>

TEST(AtTpcMapTest, TEST_InhibitBeamPads_RCNP)
{
// Construct an AtTpcMap object, parse the RCNP mapping and parse the beam pad list.
TString dir = getenv("VMCWORKDIR");
TString scriptFile = "rcnp_map_size.xml";
TString mapDir = dir + "/scripts/" + scriptFile;
TString beamPadsFile = "BeamPads_RCNP.csv";
TString beamPadsDir = dir + "/scripts/" + beamPadsFile;
AtTpcMap *map = new AtTpcMap();
map->ParseXMLMap(mapDir.Data());
map->GeneratePadPlane();
Int_t inhibitedPadsCount = map->InhibitBeamPads(beamPadsDir);

// Check all pads and count how many are actually inhibited.
Int_t actuallyInhibitedPadsCount{};
for (int i = 0; i < map->GetNumPads(); i++)
if (map->IsInhibited(i) == AtMap::InhibitType::kXTalk)
actuallyInhibitedPadsCount++;

EXPECT_EQ(inhibitedPadsCount, actuallyInhibitedPadsCount);
ASSERT_TRUE(inhibitedPadsCount > 0);
}

TEST(AtTpcMapTest, TEST_InhibitBeamPads_e23031)
{
// Construct an AtTpcMap object, parse the e23031 mapping and parse the beam pad list.
TString dir = getenv("VMCWORKDIR");
TString scriptFile = "e23031_pad_map_size.xml";
TString mapDir = dir + "/scripts/" + scriptFile;
TString beamPadsFile = "BeamPads_e23031.csv";
TString beamPadsDir = dir + "/scripts/" + beamPadsFile;
AtTpcMap *map = new AtTpcMap();
map->ParseXMLMap(mapDir.Data());
map->GeneratePadPlane();
Int_t inhibitedPadsCount = map->InhibitBeamPads(beamPadsDir);

// Check all pads and count how many are actually inhibited.
Int_t actuallyInhibitedPadsCount{};
for (int i = 0; i < map->GetNumPads(); i++)
if (map->IsInhibited(i) == AtMap::InhibitType::kXTalk)
actuallyInhibitedPadsCount++;

EXPECT_EQ(inhibitedPadsCount, actuallyInhibitedPadsCount);
ASSERT_TRUE(inhibitedPadsCount > 0);
}
9 changes: 9 additions & 0 deletions AtMap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ Set(DEPENDENCIES
ATTPCROOT::AtData
)

set(TEST_SRCS
AtTpcMapTest.cxx
)

attpcroot_generate_tests(${LIBRARY_NAME}Tests
SRCS ${TEST_SRCS}
DEPS ${LIBRARY_NAME}
)

generate_target_and_root_library(${LIBRARY_NAME}
LINKDEF ${LINKDEF}
SRCS ${SRCS}
Expand Down
4 changes: 4 additions & 0 deletions AtUnpack/AtHDFUnpacker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ void AtHDFUnpacker::processPad(std::size_t ipad)
std::vector<int16_t> rawadc = pad_raw_data(ipad);
AtPadReference PadRef = {rawadc[0], rawadc[1], rawadc[2], rawadc[3]};

// If this pad was inhibited, skip it.
if (fMap->IsInhibited(PadRef) != AtMap::InhibitType::kNone)
return;

auto pad = createPadAndSetIsAux(PadRef);
setDimensions(pad);
setAdc(pad, rawadc);
Expand Down
32 changes: 32 additions & 0 deletions macro/tests/AT-TPC/plotBeamPads.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
void plotBeamPads()
{
// Construct an AtTpcMap object, parse the mapping and parse the beam pad list.
TString dir = getenv("VMCWORKDIR");
//TString scriptFile = "rcnp_map_size.xml";
TString scriptFile = "e23031_pad_map_size.xml";
TString mapDir = dir + "/scripts/" + scriptFile;
//TString beamPadsFile = "BeamPads_RCNP.csv";
TString beamPadsFile = "BeamPads_e23031.csv";
TString beamPadsDir = dir + "/scripts/" + beamPadsFile;
AtTpcMap *map = new AtTpcMap();
map->ParseXMLMap(mapDir.Data());
map->InhibitBeamPads(beamPadsDir);

// Generate padplane and get the TH2Poly from it.
map->GeneratePadPlane();
TH2Poly *padPlane = map->GetPadPlane();

// Check all pads and count how many are actually inhibited.
Int_t actuallyInhibitedPadsCount{};
for (int i = 0; i < map->GetNumPads(); i++)
if (map->IsInhibited(i) == AtMap::InhibitType::kXTalk) {
auto position = map->CalcPadCenter(i);
padPlane->Fill(position.X(), position.Y(), 1);
}
// Create TCanvas and draw the padplane.
TCanvas *cPadPlane = new TCanvas();
padPlane->Draw("COL L1");
padPlane->SetMinimum(1.0);
padPlane->GetXaxis()->SetTitle("x [mm]");
padPlane->GetYaxis()->SetTitle("y [mm]");
}
139 changes: 139 additions & 0 deletions scripts/BeamPads_RCNP.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
CoboID,AsadID,AgetID,ChannelID,PadID
2,1,3,48,133
2,0,3,53,134
2,1,3,50,135
2,0,3,40,136
2,0,3,38,137
2,1,3,39,138
2,0,3,15,139
2,1,3,33,140
2,1,3,5,141
2,0,3,24,142
2,1,3,13,143
2,1,3,1,144
2,1,3,10,145
2,1,3,26,146
2,1,3,21,147
0,0,3,34,148
0,1,3,25,149
0,0,3,26,150
0,1,3,33,151
0,2,3,20,152
0,2,3,9,153
0,2,3,25,154
0,2,3,2,155
0,2,3,12,156
0,2,3,6,157
0,3,3,23,158
0,2,3,34,159
0,3,3,14,160
0,3,3,37,161
0,2,3,40,162
0,3,3,39,163
0,2,3,51,164
0,2,3,49,165
0,3,3,52,166
2,1,3,35,432
2,1,3,12,434
2,1,3,31,435
2,1,3,19,436
2,1,3,9,437
2,1,3,15,438
2,1,3,28,439
9,2,0,27,440
0,0,2,28,441
0,0,3,62,442
0,0,3,58,443
0,0,3,38,444
0,0,3,36,445
0,0,3,24,446
0,1,3,23,447
0,1,3,35,448
0,1,3,37,449
0,1,3,61,450
0,1,3,57,451
0,1,2,27,452
5,1,0,28,453
0,2,3,14,454
0,2,3,27,455
0,2,3,10,456
0,2,3,18,457
0,2,3,13,458
0,2,3,32,459
0,2,3,36,461
0,0,2,30,732
0,0,3,55,733
0,0,3,40,735
0,0,3,28,738
0,1,3,39,740
0,1,3,54,741
0,1,2,29,743
4,0,2,60,5253
2,0,3,52,5254
4,0,2,62,5255
2,0,3,63,5256
2,0,3,59,5257
4,0,1,10,5258
2,0,2,0,5259
4,0,1,13,5260
4,0,1,21,5261
2,0,3,66,5262
4,0,1,24,5263
4,0,2,64,5264
1,3,2,44,5265
1,3,2,42,5266
1,3,2,47,5267
1,2,2,62,5268
1,2,2,60,5269
1,1,2,59,5270
1,1,2,61,5271
1,0,2,46,5272
1,0,2,43,5273
1,0,2,41,5274
3,1,2,63,5275
3,1,1,23,5276
3,1,1,20,5277
0,3,3,65,5278
3,1,1,12,5279
0,3,3,67,5280
0,3,3,60,5281
3,1,1,10,5282
0,3,3,64,5283
3,1,2,61,5284
3,1,2,59,5285
0,3,3,53,5286
4,0,0,13,5552
1,3,3,62,5554
4,0,1,46,5555
1,3,3,9,5556
4,0,1,48,5557
4,0,1,50,5558
1,2,3,47,5559
1,2,2,34,5560
1,2,3,49,5561
1,2,3,51,5562
1,2,2,32,5563
1,2,3,55,5564
1,2,2,28,5565
1,1,3,61,5566
1,2,3,62,5567
1,1,2,27,5568
1,1,3,54,5569
1,1,3,50,5570
1,1,2,31,5571
1,1,3,48,5572
1,1,2,33,5573
3,1,1,51,5574
1,1,3,46,5575
3,1,1,49,5576
1,0,3,10,5577
1,0,3,61,5578
3,1,1,47,5579
3,1,0,12,5581
1,2,3,13,5852
1,2,3,15,5853
1,2,3,4,5855
1,1,3,16,5858
1,1,3,3,5860
1,1,3,14,5861
1,1,3,12,5863
Loading