10#include <ecl/modules/eclCRFinder/ECLCRFinderModule.h>
13#include <ecl/dataobjects/ECLCalDigit.h>
14#include <ecl/dataobjects/ECLConnectedRegion.h>
15#include <ecl/geometry/ECLNeighbours.h>
18#include <framework/gearbox/Unit.h>
19#include <framework/logging/Logger.h>
20#include <mdst/dataobjects/EventLevelClusteringInfo.h>
39 m_eclConnectedRegions(eclConnectedRegionArrayName()), m_eventLevelClusteringInfo(eventLevelClusteringInfoName())
51 addParam(
"timeCut0",
m_timeCut[0],
"Seed time cut (negative values for residual cut).", 99999.);
52 addParam(
"timeCut1",
m_timeCut[1],
"Growth time cut (negative values for residual cut).", 99999.);
53 addParam(
"timeCut2",
m_timeCut[2],
"Digit time cut (negative values for residual cut).", 99999.);
60 addParam(
"mapType0",
m_mapType[0],
"Map type for seed crystals.", std::string(
"N"));
61 addParam(
"mapType1",
m_mapType[1],
"Map type for growth crystals.", std::string(
"N"));
63 "Map parameter for seed crystals (radius (type=R), integer (for type=N) or fraction (for type=MC)).", 1.0);
65 "Map parameter for growth crystals (radius (type=R), integer (for type=N) or fraction (for type=MC)).", 1.0);
77 B2DEBUG(200,
"ECLCRFinderModule::initialize()");
90 " must be larger or equal than m_energyCut[1]=" <<
m_energyCut[1]);
92 " must be larger or equal than m_energyCut[2]=" <<
m_energyCut[2]);
96 B2FATAL(
"ECLCRFinderModule::initialize(): m_timeCut[0] must be less or equal than m_timeCut[1].");
98 B2FATAL(
"ECLCRFinderModule::initialize(): m_timeCut[1] must be less or equal than m_timeCut[2].");
122 B2DEBUG(200,
"ECLCRFinderModule::event()");
143 const double energy = eclCalDigit.getEnergy();
144 const double time = eclCalDigit.getTime();
145 const double timeresolution = eclCalDigit.getTimeResolution();
146 const int cellid = eclCalDigit.getCellId();
147 const bool fitfailed = eclCalDigit.isFailedFit();
149 double timeresidual = 999.;
150 if (!fitfailed and fabs(timeresolution) > 1e-9) {
151 timeresidual = time / timeresolution;
164 B2DEBUG(250,
"ECLCRFinderModule::event(), adding 'all digit' cellid = " << cellid <<
" " << energy <<
" " << time <<
" " <<
175 B2DEBUG(250,
"ECLCRFinderModule::event(), adding 'growth digit' cellid = " << cellid <<
" " << energy <<
" " << time <<
" " <<
187 B2DEBUG(250,
"ECLCRFinderModule::event(), adding 'seed digit' cellid = " << cellid <<
" " << energy <<
" " << time <<
" " <<
196 std::vector<int> connectedRegions_AB_flattened =
flattenVector(connectedRegions_AB);
201 std::vector<int> connectedRegions_ABB_flattened =
flattenVector(connectedRegions_ABB);
202 std::vector<int> ABB =
oneHotVector(connectedRegions_ABB_flattened, AB.size());
208 std::vector<std::set<int>> connectedRegionsMerged_ABBC_sets =
mergeVectorsUsingSets(connectedRegions_ABBC);
211 unsigned int connectedRegionID = 0;
212 for (
const auto& xcr : connectedRegionsMerged_ABBC_sets) {
218 aCR->setCRId(connectedRegionID);
232 B2DEBUG(200,
"ECLCRFinderModule::endRun()");
238 B2DEBUG(200,
"ECLCRFinderModule::terminate()");
247 for (
const auto& neighbour :
m_neighbourMaps[maptype]->getNeighbours(cellid1)) {
248 if (neighbour == cellid2)
return true;
256 for (
const auto& B : A) {
257 C.insert(C.end(), B.begin(), B.end());
259 std::sort(C.begin(), C.end());
260 C.erase(std::unique(C.begin(), C.end()), C.end());
266 std::vector<int> C(n, 0);
268 if (x >= 0 && x < n) {
279 std::vector< std::set<int> > output;
281 for (
auto& vec : A) {
282 std::set<int> s(vec.begin(), vec.end());
285 for (
auto it = output.begin(); it != output.end();) {
287 std::set_intersection(it->begin(), it->end(), s.begin(), s.end(),
291 s.insert(it->begin(), it->end());
292 it = output.erase(it);
304 std::vector<std::vector<int>> connectedRegions;
306 for (
unsigned int i = 0; i < A.size(); ++i) {
308 std::vector<int> region;
311 for (
unsigned int j = 0; j < B.size(); ++j) {
317 std::sort(region.begin(), region.end());
318 region.erase(unique(region.begin(), region.end()), region.end());
319 connectedRegions.push_back(region);
323 return connectedRegions;
double m_mapPar[2]
Parameters for neighbour maps.
virtual const char * eventLevelClusteringInfoName() const
Name to be used for default option: EventLevelClusteringInfo.
bool areNeighbours(const int cellid1, const int cellid2, const int maptype)
Check if two crystals are neighbours.
std::vector< int > m_cellIdToDigitVec
cellid -> above threshold digits.
virtual ~ECLCRFinderModule()
Destructor.
ECLCRFinderModule()
Constructor.
StoreArray< ECLConnectedRegion > m_eclConnectedRegions
Store array: ECLConnectedRegion.
double m_timeCut[3]
Time cut for seed, neighbours, ...
std::vector< int > oneHotVector(std::vector< int > &A, const int n)
Convert vector of cell ids to 0/1 vectors from 1-8737.
std::vector< int > m_cellIdToGrowthVec
cellid -> growth digits.
virtual void initialize() override
Initialize.
std::map< int, int > m_cellIdToTempCRIdMap
cellid -> temporary CR.
double m_energyCut[3]
Energy cut for seed, neighbours, ...
std::vector< int > m_cellIdToCheckVec
Digit vectors.
virtual void event() override
Event.
std::vector< int > m_cellIdToSeedVec
cellid -> seed digit.
virtual void endRun() override
End run.
std::vector< int > flattenVector(std::vector< std::vector< int > > &A)
Convert vector of vectors to one long vector.
virtual void terminate() override
Terminate (close ROOT files here if you have opened any).
std::vector< int > m_cellIdToTempCRIdVec
Connected Region map.
int m_skipFailedTimeFitDigits
Handling of digits with failed time fits.
std::vector< int > m_calDigitStoreArrPosition
vector (ECLElementNumbers::c_NCrystals + 1 entries) with cell id to store array positions
virtual void beginRun() override
Begin.
std::vector< std::vector< int > > getConnectedRegions(const std::vector< int > &A, const std::vector< int > &B, const int maptype)
Get all connected regions.
std::vector< std::set< int > > mergeVectorsUsingSets(std::vector< std::vector< int > > &A)
Find all lists of cell-ids that share at least one cell.
virtual const char * eclConnectedRegionArrayName() const
Name to be used for default option: ECLConnectedRegions.
std::vector< ECL::ECLNeighbours * > m_neighbourMaps
Neighbour maps.
virtual const char * eclCalDigitArrayName() const
Name to be used for default or PureCsI option: ECLCalDigits.
std::string m_mapType[2]
Neighbour map types.
double m_timeCut_maxEnergy[3]
Time cut is only applied below this energy, ...
StoreObjPtr< EventLevelClusteringInfo > m_eventLevelClusteringInfo
Store object pointer: EventLevelClusteringInfo.
StoreArray< ECLCalDigit > m_eclCalDigits
Store array: ECLCalDigit.
Class to get the neighbours for a given cell id.
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
static const double MeV
[megaelectronvolt]
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
int intersect(const TRGCDCLpar &lp1, const TRGCDCLpar &lp2, CLHEP::HepVector &v1, CLHEP::HepVector &v2)
intersection
Abstract base class for different kinds of events.