9#include <cdc/modules/cdcCrossTalkAdder/CDCCrossTalkAdderModule.h>
11#include <framework/datastore/RelationIndex.h>
12#include <framework/logging/Logger.h>
14#include <cdc/dataobjects/CDCSimHit.h>
15#include <mdst/dataobjects/MCParticle.h>
28 setDescription(
"Overlays signal-induced asic cross-talk to CDCHits.");
47 if ((*m_xTalkFromDB).isValid()) {
49 B2FATAL(
"CDCCrossTalkLibrary invalid!");
53 if ((*m_fEElectronicsFromDB).isValid()) {
57 B2FATAL(
"CDCCrossTalkAdder:: CDCFEElectronics not valid!");
63 map<WireID, XTalkInfo> xTalkMap;
64 map<WireID, XTalkInfo> xTalkMap1;
65 map<WireID, XTalkInfo>::iterator iterXTalkMap1;
68 int OriginalNoOfHits =
m_hits.getEntries();
69 B2DEBUG(
m_debugLevel,
"\n \n" <<
"#CDCHits " << OriginalNoOfHits);
70 for (
const auto& aHit :
m_hits) {
72 B2WARNING(
"2nd TDC hit found, but not ready for it!");
76 short tdcCount = aHit.getTDCCount();
77 short adcCount = aHit.getADCCount();
78 short tot = aHit.getTOT();
81 const vector<pair<short, asicChannel>> xTalks = (*m_xTalkFromDB)->getLibraryCrossTalk(channel, tdcCount, adcCount, tot);
83 int nXTalks = xTalks.size();
84 for (
int i = 0; i < nXTalks; ++i) {
85 const unsigned short tdcCount4XTalk = xTalks[i].second.TDC;
87 B2DEBUG(
m_debugLevel,
"\n" <<
" signal: " << channel <<
" " << tdcCount <<
" " << adcCount <<
" " << tot);
89 B2DEBUG(
m_debugLevel,
"xtalk: " << xTalks[i].first <<
" " << tdcCount4XTalk <<
" " << xTalks[i].second.ADC <<
" " <<
90 xTalks[i].second.TOT);
97 if (LLOfTDC <= tdcCount4XTalk && tdcCount4XTalk <= ULOfTDC) {
98 const unsigned short status = 0;
99 xTalkMap.insert(make_pair(widx,
XTalkInfo(tdcCount4XTalk, xTalks[i].second.ADC, xTalks[i].second.TOT, status)));
109 B2DEBUG(
m_debugLevel,
"#xtalk hits: " << xTalkMap.size());
110 for (
const auto& aHit : xTalkMap) {
113 iterXTalkMap1 = xTalkMap1.find(wid);
114 unsigned short tdcCount = aHit.second.m_tdc;
115 unsigned short adcCount = aHit.second.m_adc;
116 unsigned short tot = aHit.second.m_tot;
117 unsigned short status = aHit.second.m_status;
119 if (iterXTalkMap1 == xTalkMap1.end()) {
120 xTalkMap1.insert(make_pair(wid,
XTalkInfo(tdcCount, adcCount, tot, status)));
123 if (tdcCount < iterXTalkMap1->second.m_tdc) {
124 iterXTalkMap1->second.m_tdc = tdcCount;
125 B2DEBUG(
m_debugLevel,
"TDC-count of current xtalk: " << tdcCount);
127 iterXTalkMap1->second.m_adc += adcCount;
128 iterXTalkMap1->second.m_tot += tot;
133 B2DEBUG(
m_debugLevel,
"#xtalk1 hits: " << xTalkMap1.size());
134 for (
const auto& aX : xTalkMap1) {
136 const unsigned short tdc4Bg = aX.second.m_tdc;
137 const unsigned short adc4Bg = aX.second.m_adc;
138 const unsigned short tot4Bg = aX.second.m_tot;
139 const unsigned short status4Bg = aX.second.m_status;
141 for (
int iHit = 0; iHit < OriginalNoOfHits; ++iHit) {
143 if (aH.
getID() != aX.first.getEWire()) {
149 const unsigned short tot4Sg = aH.
getTOT();
155 if (tdc4Sg < tdc4Bg) {
159 for (
int i = relSimHits.size() - 1; i >= 0; --i) {
160 relSimHits.remove(i);
163 for (
int i = relMCParticles.size() - 1; i >= 0; --i) {
164 relMCParticles.remove(i);
174 unsigned short s1 = tdc4Sg;
175 unsigned short s2 = tdc4Bg;
176 unsigned short w1 = tot4Sg;
177 unsigned short w2 = tot4Bg;
178 if (tdc4Sg < tdc4Bg) {
186 const unsigned short e1 = s1 - w1;
187 const unsigned short e2 = s2 - w2;
190 double pulseW = w1 + w2;
193 }
else if (e1 <= s2) {
206 m_hits.appendNew(tdc4Bg, adc4Bg, aX.first, status4Bg, tot4Bg);
207 B2DEBUG(
m_debugLevel,
"appended tdc,adc,tot,wid,status= " << tdc4Bg <<
" " << adc4Bg <<
" " << tot4Bg <<
" " << aX.first <<
" " <<
211 B2DEBUG(
m_debugLevel,
"original #hits, #hits= " << OriginalNoOfHits <<
" " <<
m_hits.getEntries());
218 B2DEBUG(
m_debugLevel,
"L1TRGLatency= " << el1TrgLatency);
223 int mode = (fp.getBoardID() == -1) ? 1 : 0;
224 int iNBoards =
static_cast<int>(c_nBoards);
228 for (
int bdi = 1; bdi < iNBoards; ++bdi) {
240 int bdi = fpp.getBoardID();
241 if (mode == 0 && bdi == 0)
continue;
242 if (mode == 1 && bdi == -1)
continue;
243 if (bdi < 0 || bdi >= iNBoards) B2FATAL(
"Invalid no. of FEE board!");
253 for (
int bdi = 1; bdi < iNBoards; ++bdi) {
int m_debugLevel
Debug level.
bool m_includeEarlyXTalks
Flag to switch on/off xtalks earlier than the hit.
unsigned short m_widthOfTimeWindow[c_nBoards]
Width of time window.
std::string m_inputCDCHitsName
Input array name.
DBObjPtr< CDCCrossTalkLibrary > * m_xTalkFromDB
Pointer to cross-talk from DB.
float m_uprEdgeOfTimeWindow[c_nBoards]
Upper edge of time-window.
void initialize() override
Initialize variables.
void event() override
Event func.
StoreArray< CDCHit > m_hits
CDCHit array.
CDCCrossTalkAdderModule()
Constructor.
bool m_issue2ndHitWarning
Flag to switch on/off a warning on the 2nd TDC hit.
float m_lowEdgeOfTimeWindow[c_nBoards]
Lower edge of time-window.
DBArray< CDCFEElectronics > * m_fEElectronicsFromDB
Pointer to FE electronics params.
CDC::CDCGeometryPar * m_cdcgp
Cached Pointer to CDCGeometryPar.
void setFEElectronics()
Set FEE parameters (from DB)
double m_invOfTDCBinWidth
Inv.
Database object for Fron-endt electronics params.
Class containing the result of the unpacker in raw data and the result of the digitizer in simulation...
void setTDCCount(short tdcCount)
Setter for TDC count.
short getTDCCount() const
Getter for TDC count.
void setTOT(unsigned short tot)
Setter for TOT.
unsigned short getID() const
Getter for encoded wire number.
unsigned short getStatus() const
Getter for CDCHit status.
void setADCCount(unsigned short adcCount)
Setter for ADC count.
unsigned short getADCCount() const
Getter for integrated charge.
unsigned short getTOT() const
Getter for TOT.
void setStatus(unsigned short status)
Setter for CDCHit status.
unsigned short getBoardID(const WireID &wID) const
Returns frontend board id. corresponding to the wire id.
const WireID getWireID(unsigned short bd, unsigned short ch) const
Returns wire id. corresponding to the board-and-cannel ids.
double getTdcBinWidth() const
Return TDC bin width (nsec).
float getT0(const WireID &wireID) const
Returns t0 parameter of the specified sense wire.
double getMeanT0() const
Returns the mean t0 over all wires.
bool isBadWire(const WireID &wid)
Inquire if the wire is totally-dead.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
unsigned short getChannelID(const WireID &wID) const
Returns frontend channel id. corresponding to the wire id.
void addCallback(std::function< void(const std::string &)> callback, bool onDestruction=false)
Add a callback method.
Class for accessing arrays of objects in the database.
Class for accessing objects in the database.
A Class to store the Monte Carlo particle information.
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...
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
Class to identify a wire inside the CDC.
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.
Abstract base class for different kinds of events.
Structure for saving the x-talk information.