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
65 changes: 65 additions & 0 deletions include/MEventTypeClassifier.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* MEventTypeClassifier.h
*
* Copyright (C) by Andreas Zoglauer, WingYeung Ma.
* All rights reserved.
*
* Please see the source-file for the copyright-notice.
*
*/


#ifndef __MEventTypeClassifier__
#define __MEventTypeClassifier__


////////////////////////////////////////////////////////////////////////////////


// Standard libs:
#include <cstdint>

// ROOT libs:

// MEGAlib libs:
#include "MGlobal.h"

// Nuclearizer libs:
#include "MReadOutAssembly.h"

// Forward declarations:


////////////////////////////////////////////////////////////////////////////////


//! Determines the event type (ETYPE) of an event from its strip hits and veto flags
class MEventTypeClassifier
{
// public interface:
public:
//! Default constructor
MEventTypeClassifier() {}
//! Default destructor
virtual ~MEventTypeClassifier() {}

//! Return the event type 0x00-0x0C of the event:
//! If the event has an on-board event type, return it unchanged, otherwise determine it:
//! 0x00-0x02 multi-detector Compton, single-detector Compton, single site, without veto,
//! 0x03-0x05 the same with guard ring veto
//! 0x09-0x0B the same with (soft) shield veto,
//! and 0x0C for a guard ring veto without any strip hit
static uint8_t Classify(MReadOutAssembly* Event);


#ifdef ___CLING___
public:
ClassDef(MEventTypeClassifier, 0) // Determines the FEE event type of an event
#endif

};

#endif


////////////////////////////////////////////////////////////////////////////////
10 changes: 10 additions & 0 deletions include/MReadOutAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ class MReadOutAssembly : public MReadOutSequence
//! Get the shield veto flag
bool GetShieldVeto() const { return m_ShieldVeto; }

//! Set the event type (ETYPE)
void SetOnboardEventType(unsigned int EventType) { m_OnboardEventType = EventType; }
//! Get the event type (ETYPE), g_UnsignedIntNotDefined if not available
unsigned int GetOnboardEventType() const { return m_OnboardEventType; }
//! Return true if the event type (ETYPE) is available
bool HasOnboardEventType() const { return m_OnboardEventType != g_UnsignedIntNotDefined; }

//! Set the triggered flag
void SetTrigger(bool Trigger = true) { m_Trigger = Trigger; }
//! Return the trigger flag
Expand Down Expand Up @@ -372,6 +379,9 @@ class MReadOutAssembly : public MReadOutSequence
//! Shield veto flag
bool m_ShieldVeto;

//! event type (ETYPE), g_UnsignedIntNotDefined if not available
unsigned int m_OnboardEventType;

//! Trigger flag of this event
bool m_Trigger;

Expand Down
119 changes: 119 additions & 0 deletions src/MEventTypeClassifier.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*
* MEventTypeClassifier.cxx
*
*
* Copyright (C) by Andreas Zoglauer, WingYeung Ma.
* All rights reserved.
*
*
* This code implementation is the intellectual property of
* Andreas Zoglauer.
*
* By copying, distributing or modifying the Program (or any work
* based on the Program) you indicate your acceptance of this statement,
* and all its terms.
*
*/


////////////////////////////////////////////////////////////////////////////////
//
// MEventTypeClassifier
//
////////////////////////////////////////////////////////////////////////////////


// Include the header:
#include "MEventTypeClassifier.h"

// Standard libs:
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

// ROOT libs:

// MEGAlib libs:

// Nuclearizer libs:
#include "MStripHit.h"


////////////////////////////////////////////////////////////////////////////////


#ifdef ___CLING___
ClassImp(MEventTypeClassifier)
#endif


////////////////////////////////////////////////////////////////////////////////


uint8_t MEventTypeClassifier::Classify(MReadOutAssembly* Event)
{
// Event types from COSI-ICD-011 (FEE), Table 36:
// 0x00 Multi-detector Compton, no veto 0x03 / 0x06 / 0x09 the same with GR / hard shield / soft shield veto
// 0x01 Single-detector Compton, no veto 0x04 / 0x07 / 0x0A the same with GR / hard shield / soft shield veto
// 0x02 Single site, no veto 0x05 / 0x08 / 0x0B the same with GR / hard shield / soft shield veto
// 0x0C GR event

if (Event->HasOnboardEventType() == true) {
return (uint8_t) Event->GetOnboardEventType();
}

set<int> Detectors;
vector<int> LVStrips;
vector<int> HVStrips;

for (unsigned int h = 0; h < Event->GetNStripHits(); ++h) {

MStripHit* Hit = Event->GetStripHit(h);
if (Hit->IsGuardRing() == true) continue;

if (Hit->IsNearestNeighbor() == true) continue;

Detectors.insert(Hit->GetDetectorID());

if (Hit->IsLowVoltageStrip() == true) {
LVStrips.push_back(Hit->GetStripID());
} else {
HVStrips.push_back(Hit->GetStripID());
}

}

// A guard ring veto without any strip hit is a GR event
if (Detectors.empty() == true && Event->GetGuardRingVeto() == true) {
return 0x0C;
}

// Category: 0 = multi-detector, 1 = single-detector Compton, 2 = single site
uint8_t Category = 2;
if (Detectors.size() >= 2) {
Category = 0;
} else if (Detectors.size() == 1) {
bool HasComptonGap = false;
for (vector<int>* Strips : { &LVStrips, &HVStrips }) {
sort(Strips->begin(), Strips->end());
for (size_t s = 1; s < Strips->size(); ++s) {
if ((*Strips)[s] - (*Strips)[s-1] >= 3) {
HasComptonGap = true;
}
}
}
if (HasComptonGap == true) Category = 1;
}

if (Event->GetGuardRingVeto() == true) {
return 0x03 + Category;
} else if (Event->GetShieldVeto() == true) {
return 0x09 + Category;
}
return Category;
}


// MEventTypeClassifier.cxx: the end...
////////////////////////////////////////////////////////////////////////////////
4 changes: 3 additions & 1 deletion src/MFITSWriterL1a.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// MEGAlib libs:
#include "MStripHit.h"
#include "MStreams.h"
#include "MEventTypeClassifier.h"

using namespace std;
using namespace CCfits;
Expand Down Expand Up @@ -166,6 +167,7 @@ bool MFITSWriterL1a::Create(const MString& FileName)
m_Table->addKey("CREATOR", "Nuclearizer", "Software that create 1st the file");
m_Table->addKey("PROCVER", "00.00.00.00", "Processing version"); // MM.XX.YY.NN; ICD reserves MM=00 for development/testing
m_Table->addKey("CALDBVER", "cs20230401", "CALDB index version used"); // provisional value per ICD until first CALDB ingestion
m_Table->addKey("TLM2FITS", "TBD", "Telemetry converter FITS version"); // TODO: TBD
m_Table->addKey("SEQPNUM", 0, "Times the dataset has been processed");
m_Table->addKey("ORIGIN", "SSL", "Origin of the FITS files");

Expand Down Expand Up @@ -222,7 +224,7 @@ bool MFITSWriterL1a::Write(MReadOutAssembly* Event)

m_BatchTIME.push_back(time);
m_BatchEVENTID.push_back((uint32_t)Event->GetID());
m_BatchEVENTTYPE.push_back(0); // TODO
m_BatchEVENTTYPE.push_back(MEventTypeClassifier::Classify(Event));
m_BatchNUMSTRIPHIT.push_back(nStripHits);
m_BatchHITTYPE.push_back(hittype);
m_BatchDETID.push_back(detid);
Expand Down
7 changes: 6 additions & 1 deletion src/MModuleLoaderMeasurementsFITS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,18 @@ bool MModuleLoaderMeasurementsFITS::AnalyzeEvent(MReadOutAssembly* Event)

// Extract event-level data
double eventTime = m_BatchTIME[idx];
// uint8_t eventType = m_BatchEVENTTYPE[idx]; //unused variable
uint8_t eventType = m_BatchEVENTTYPE[idx];
uint8_t numStripHit = m_BatchNUMSTRIPHIT[idx];

// Set event-level properties
Event->SetID(static_cast<unsigned long>(m_BatchEVENTID[idx]));
Event->SetTimeRTS(eventTime); // Mission time in seconds since Jan 1, 2025

// determine guard-ring, hard shield, and soft shield vetoes from event types
Event->SetGuardRingVeto((eventType >= 0x03 && eventType <= 0x05) || eventType == 0x0C);
Event->SetShieldVeto(eventType >= 0x06 && eventType <= 0x0B);
Event->SetOnboardEventType(eventType);

// Loop through strip hits and create MStripHit objects
for (uint8_t hitIdx = 0; hitIdx < numStripHit; ++hitIdx) {
// Extract hit data from arrays
Expand Down
12 changes: 10 additions & 2 deletions src/MModuleLoaderMeasurementsL0.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ MModuleLoaderMeasurementsL0::~MModuleLoaderMeasurementsL0()

bool MModuleLoaderMeasurementsL0::Initialize()
{
if (m_InFile.is_open()) m_InFile.close();
m_InFile.clear();
m_StripMapLoaded = false;
m_PacketsRead = 0;

if (m_FileName == "") {
Expand Down Expand Up @@ -319,6 +322,11 @@ bool MModuleLoaderMeasurementsL0::ReadNextPacket(MReadOutAssembly* Event)
MTime gpsTime((long int)pktSeconds, pktNanoseconds);
Event->SetTimeRTS(Event->ComputeRTSfromGPSTime(gpsTime));

// event types distinguish guard-ring, hard shield, and soft shield vetoes.
Event->SetGuardRingVeto((etype >= 0x03 && etype <= 0x05) || etype == 0x0C);
Event->SetShieldVeto(etype >= 0x06 && etype <= 0x0B);
Event->SetOnboardEventType(etype);

// Decode the bit-packed HIT_DATA into individual MStripHit objects on the event
if (DecodeHitData(hitData, hits, Event) == false) {
return false;
Expand Down Expand Up @@ -370,9 +378,9 @@ bool MModuleLoaderMeasurementsL0::DecodeHitData(const std::vector<uint8_t>& hitD
tac = br.ReadBits(10);
isNeighbor = true;
} else if (hitType == 0x2) {
// Guard ring: 5 + 14 + 1(pad) = 20 more bits
// Guard ring: 5-bit strip id + 14-bit energy + 1 pad bit.
if (br.BitsRemaining() < 20) break;
stripID = br.ReadBits(5);
stripID = 2048 + br.ReadBits(5);
adc = br.ReadBits(14);
(void)br.ReadBits(1); // pad
isGuardRing = true;
Expand Down
14 changes: 11 additions & 3 deletions src/MModuleSaverMeasurementsFITS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ using namespace std;
#include "MPhysicalEventHit.h"
#include "MComptonEvent.h"
#include "MPhotoEvent.h"
#include "MEventTypeClassifier.h"


////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -212,7 +213,7 @@ bool MModuleSaverMeasurementsFITS::CreateFITSFile(MString FileName)
{"TIME", "1D", "s", "Mission Time in sec since 01 Jan 2025 00:00:00", false},
{"EVENTID", "1J", "", "Event ID, unique number that starts at 1 each day", false},
{"EVENTTYPE", "1B", "", "Type of event", true },
{"EVENTCLASS", "1B", "", "0=Compton, 1=photoabsor, 2=charge particle, 4=pair, 5=unknown", false},
{"EVENTCLASS", "1B", "", "0=Compton, 1=photoabsor, 2=tracked Compton, 3=charge particle, 4=pair, 5=unknown", false},
{"NUMHIT", "1B", "", "Number of Hits", false},
{"STATTEST", "8E", "", "Statistical Test", true },
{"VETO", "1B", "", "Veto flag: 0=none, 1=hard ACD veto, 2=soft ACD veto, 3=guard ring veto", true },
Expand Down Expand Up @@ -352,14 +353,21 @@ bool MModuleSaverMeasurementsFITS::AnalyzeEvent(MReadOutAssembly* Event)
}

// Event-level metadata defaults
uint8_t eventType = 0; // TODO: 0 = unknown/default
uint8_t eventType = MEventTypeClassifier::Classify(Event);

// EVENTCLASS per HEASARC Tech Agreement v1.1
// 0 = Compton, 1 = photoabsorption, 2 = tracked Compton, 3 = charge particle, 4 = pair, 5 = unknown.
uint8_t eventClass = 5; // 5 = unknown
uint32_t eventID = (uint32_t)Event->GetID();

uint8_t veto = Event->IsVeto() ? 1 : 0;
// VETO: 0 = none, 1 = hard ACD veto, 2 = soft ACD veto, 3 = guard ring veto
// Hard and soft shield veto are told apart by the event type (0x06-0x08 hard, 0x09-0x0B soft)
uint8_t veto = 0;
if (Event->GetGuardRingVeto() == true) {
veto = 3;
} else if (Event->GetShieldVeto() == true) {
veto = (eventType >= 0x06 && eventType <= 0x08) ? 1 : 2;
}
std::string quality_flag;

// L2: fixed-length 10 hit arrays, zero-padded
Expand Down
Loading
Loading