9#include <top/modules/TOPInterimFENtuple/TOPInterimFENtupleModule.h>
11#include <framework/datastore/StoreObjPtr.h>
12#include <framework/datastore/StoreArray.h>
14#include <framework/dataobjects/EventMetaData.h>
15#include <top/dataobjects/TOPDigit.h>
16#include <top/dataobjects/TOPRawDigit.h>
17#include <top/dataobjects/TOPRawWaveform.h>
18#include <top/dataobjects/TOPInterimFEInfo.h>
19#include <top/dataobjects/TOPProductionEventDebug.h>
20#include <rawdata/dataobjects/RawTOP.h>
49 setDescription(
"Create ntuple mainly from TOPDigit with double pulse identification. "
50 "Data taken with both InterimFE FW and production FW are available. (since Jan, 2017)");
57 "set true when you require both of double calibration pulses for reference timing. You need to enable offline feature extraction.",
68 "acceptable DeltaT shift from the noinal value before calibration [ns]",
71 "slot number where a global reference asic exists. slot01-asic0 (pixelId=1-8) is default.", 1);
73 "asic number defined as int((pixelId-1)/8) of a global reference asic", 0);
75 addParam(
"timePerWin",
m_timePerWin,
"time interval of a single window (=64 samples) [ns]", (
float)23.581939);
101 m_tree =
new TTree(
"tree",
"TTree for generator output");
103 std::ostringstream nModuleStr;
104 nModuleStr <<
"[" << c_NModule <<
"]";
109 std::string(std::string(
"eventNumCopper") + nModuleStr.str() +
"/i").c_str());
111 std::string(std::string(
"ttuTime") + nModuleStr.str() +
"/i").c_str());
113 std::string(std::string(
"ttcTime") + nModuleStr.str() +
"/i").c_str());
135 std::ostringstream brstr[2];
136 brstr[0] <<
"winNumList[nHit][" << c_NWindow <<
"]/S";
139 brstr[1] <<
"waveform[nHit][" << c_NWaveformSample <<
"]/S";
176 for (
int iSlot = 0 ; iSlot < c_NModule ; iSlot++) {
182 short trigCtime = -1;
183 for (
auto& rawTOP : rawTOPs) {
184 if (iSlotTTC >= c_NModule) {
185 B2WARNING(
"too many TTC information");
189 m_ttuTime[iSlotTTC] = rawTOP.GetTTUtime(0);
190 m_ttcTime[iSlotTTC] = rawTOP.GetTTCtime(0);
193 trigCtime = ((((long)
m_ttcTime[iSlotTTC] + (
long)(
m_ttuTime[iSlotTTC] - 1524741300) * 127216000) % 11520) % 3840) % 1284;
197 std::map<short, short> nHitOfflineFEMap;
198 static std::set<short> noisyChannelBlackListSet;
199 UInt_t EventNum = EventMetaDataPtr->getEvent();
202 for (
const auto& digit : digits) {
204 if (
m_nHit >= c_NMaxHitEvent) {
205 B2WARNING(
"TOPInterimFENtuple : too many hits found (>=" << c_NMaxHitEvent
206 <<
"), EventNo = " << EventNum <<
", no more hits are recorded.");
228 for (
int iWindow = 0 ; iWindow < c_NWindow ; iWindow++)
230 for (
int iSample = 0 ; iSample < c_NWaveformSample ; iSample++)
235 if (nHitOfflineFEMap.count(globalChannelId) == 0) nHitOfflineFEMap[globalChannelId] = 0;
236 else if (nHitOfflineFEMap[globalChannelId] > c_NMaxHitPerChannel) {
237 if (noisyChannelBlackListSet.count(globalChannelId) == 0) {
239 noisyChannelBlackListSet.insert(globalChannelId);
240 B2WARNING(
"TOPInterimFENtuple : noisy channel with too many hits (slotNum="
241 << (globalChannelId / c_NPixelPerModule + 1) <<
", pixelId = "
242 << (globalChannelId / c_NPixelPerModule + 1) <<
") ");
247 const auto* rawDigit = digit.getRelated<
TOPRawDigit>();
258 if (rawDigit->isMadeOffline()) {
261 nHitOfflineFEMap[globalChannelId]++;
267 unsigned nSampleWfm = waveform->getSize();
268 unsigned nSample = TMath::Min((UShort_t)nSampleWfm, (UShort_t)c_NWaveformSample);
269 if (nSample > c_NWaveformSample)
270 B2WARNING(
"TOPInterimFENtuple: too many waveform samples in TOPRawWaveform : " << nSampleWfm <<
", only first " << nSample <<
272 for (
unsigned iSample = 0 ; iSample < nSample ; iSample++)
278 for (
const auto& window : waveform->getStorageWindows()) {
279 if (iWin < c_NWindow)
282 B2WARNING(
"TOPInterimFENtuple: too many windows were found");
291 B2WARNING(
"TOPInterimFENtuple : no TOPRawDigit object found!");
299 for (
int iHit = 0 ; iHit <
m_nHit ; iHit++) {
301 short globalChannelId =
m_pixelId[iHit] - 1 + (
m_slotNum[iHit] - 1) * c_NPixelPerModule;
307 for (
const auto& info : infos) {
316 for (
const auto& prodDebug : prodDebugs) {
343 std::map<short, short> iRefHitMap;
344 for (
int iHit = 0 ; iHit <
m_nHit ; iHit++) {
347 if (iRefHitMap.count(reducedPixelId) > 0)
continue;
350 iRefHitMap[reducedPixelId] = iHit;
354 std::vector<short> iHitVec;
355 iHitVec.push_back(iHit);
356 for (
int jHit = iHit + 1 ; jHit <
m_nHit ; jHit++) {
358 if (
m_isCalCh[jHit] && jReducedPixelId == reducedPixelId) iHitVec.push_back(jHit);
362 for (
unsigned int iVec = 0 ; iVec < iHitVec.size() ; iVec++) {
363 int jHit = iHitVec[iVec];
364 for (
unsigned int jVec = iVec + 1 ; jVec < iHitVec.size() ; jVec++) {
365 int kHit = iHitVec[jVec];
371 iRefHitMap[reducedPixelId] = jHit;
382 iRefHitMap[reducedPixelId] = kHit;
394 for (
int iHit = 0 ; iHit <
m_nHit ; iHit++) {
396 if (iRefHitMap.count(reducedPixelId) > 0) {
397 int iRef = iRefHitMap[reducedPixelId];
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
void setDescription(const std::string &description)
Sets the description of the module.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Accessor to arrays stored in the data store.
Type-safe access to single objects in the data store.
unsigned short m_scrodCtime[c_NTotalScrod]
ctime recorded in scrod header
bool m_useDoublePulse
set true when you require both of double calibration pulses for reference timing
float m_calibrationPulseInterval
nominal DeltaT value (time interval of two calibration signals) in a unit of ns
short m_nWaveform
m_waveforms in TOPInterimFEInfo, # of waveformes
short m_nFEHeader
m_FEHeaders in TOPInterimFEInfo, the total # of FE headers found
short m_winNumList[c_NMaxHitEvent][c_NWindow]
list of window numbers for recorded waveform, valid only when waveform analysis is enabled
float m_integral[c_NMaxHitEvent]
"m_integral" in TOPDigit, but not available
unsigned m_eventNum
event number taken from EventMetaData
short m_slotNum[c_NMaxHitEvent]
"m_moduleID" in TOPDigit, slot number
short m_channelId[c_NMaxHitEvent]
"m_channel" in TOPDigit
short m_winNum[c_NMaxHitEvent]
"m_window" in TOPRawDigit
int m_globalRefSlotNum
slot number used to define "global" reference timing (a single reference timing in an event for all t...
short m_waveformStartSample[c_NMaxHitEvent]
start sample number of waveform segment (only for production FW)
unsigned short m_eventNumberByte[c_NTotalScrod]
least significant byte of FE event number
float m_calibrationPulseIntervalRange
tolerable shift of DeltaT from its nominal before calibration in a unit of ns
unsigned short m_sample[c_NMaxHitEvent]
(m_rawTDC+m_winNum*64)%256, for time base correction
unsigned short m_peakSample[c_NMaxHitEvent]
sample number for peak
float m_calibrationPulseThreshold2
minimum pulse height for the secon calibration pulse to be qualified as calibration signals
int m_nDebugInfo
number of ProductionEventDebug (in a unit of number of boardstack)
float m_refTime[c_NMaxHitEvent]
time of the first calibration signal as reference timing.
int m_nHit
number of hits for the event
unsigned m_errorFlag
m_errorFlags in TOPInterimFEInfo, defined in the TOPInterimFEInfo.h
float m_height[c_NMaxHitEvent]
"m_pulseHeight" in new TOPDigit (update at May, 2017)
short m_trigWinNum[c_NMaxHitEvent]
"m_lastWriteAddr" in TOPRawDigit, window # when trigger is issued
unsigned short m_eventQueuDepth[c_NTotalScrod]
trigger FIRO queue depth
char m_offlineFlag[c_NMaxHitEvent]
=-1 if the channel does not have waveform information, =0 when the hit comes from online FE,...
short m_revo9Counter[c_NMaxHitEvent]
"m_revo9Counter" in TOPRawDigit
float m_width[c_NMaxHitEvent]
"m_pulseWidth" in TOPDigit, full width at half maximum of the pulse, converted into unit of samples f...
short m_eventWinNum[c_NMaxHitEvent]
"m_firstWindow" in TOPDigit
unsigned m_eventErrorFlag
m_errorFlags in EventMetaData, 0x1 : CRC error
float m_time[c_NMaxHitEvent]
time in a unit of ns, defined as m_rawTime+64*m_winNum.
short m_waveform[c_NMaxHitEvent][c_NWaveformSample]
waveform from TOPRawWaveform, if not exist, filled with -32767
unsigned m_ttuTime[c_NModule]
counter for TTclock, stored in COPPER
short m_pixelId[c_NMaxHitEvent]
"m_pixelID" in TOPDigit
float m_timePerWin
time interval of onw window (=64 samples) [ns]
unsigned m_calibrationChannel
asic channel number where the calibration pulses are routed
short m_nHitOfflineFE[c_NMaxHitEvent]
number of hits for each pixel
float m_calibrationPulseThreshold1
minimum pulse height for the first calibration pulse to be qualified as calibration signals
unsigned char m_hitQuality[c_NMaxHitEvent]
"m_quality" in TOPDigit, =0:junk, =1:good, =2:charge sharing, =3:cross talk, =4:cal.
bool m_windowsInOrder[c_NMaxHitEvent]
"areWindowsInOrder()" ; false if the window number of all (4) windows taken from TOPRawWaveform::getR...
unsigned m_eventNumCopper[c_NModule]
event number stored in COPPER
int m_globalRefAsicNum
asic number used to define "global" reference timing.
float m_globalRefTime
refTime of the specific asic, which is specified by parameters "globalRefSlotNum" and "globalRefAsicN...
unsigned short m_phase[c_NTotalScrod]
event phase
unsigned short m_asicMask[c_NTotalScrod]
asic mask bit pattern
float m_rawTime[c_NMaxHitEvent]
"m_rawTime" [0-256] in new TOPDigit (update at May, 2017) in sample(time bin) unit
bool m_isCalCh[c_NMaxHitEvent]
true if the hit is in the calibration channel
unsigned m_ttcTime[c_NModule]
counter for TTclock, stored in COPPER
bool m_isReallyJunk[c_NMaxHitEvent]
true if pedestal jump or other invalid hit is detected, not saved
short m_nEmptyFEHeader
m_emptyFEHeaders in TOPInterimFEInfo, the total # of empty FE headers
unsigned short m_nWaveformSample[c_NMaxHitEvent]
number of waveform samples
bool m_saveWaveform
set true when you want to save waveform data
Class to store unpacked raw data (hits in feature-extraction format) It provides also calculation of ...
@ c_Interim
from interim feature extraction
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.
void getReferenceTiming()
Find reference timing.
virtual ~TOPInterimFENtupleModule()
Destructor.
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
TOPInterimFENtupleModule()
Constructor.
virtual void defineHisto() override
Module funcions to define histograms.
Abstract base class for different kinds of events.