9#include <cdc/modules/cdcCrossTalkAdder/CDCCrossTalkAdderModule.h>
11#include <framework/logging/Logger.h>
13#include <cdc/dataobjects/CDCSimHit.h>
14#include <mdst/dataobjects/MCParticle.h>
27 setDescription(
"Overlays signal-induced asic cross-talk to CDCHits.");
46 if ((*m_xTalkFromDB).isValid()) {
48 B2FATAL(
"CDCCrossTalkLibrary invalid!");
52 if ((*m_fEElectronicsFromDB).isValid()) {
56 B2FATAL(
"CDCCrossTalkAdder:: CDCFEElectronics not valid!");
62 map<WireID, XTalkInfo> xTalkMap;
63 map<WireID, XTalkInfo> xTalkMap1;
67 int OriginalNoOfHits =
m_hits.getEntries();
68 B2DEBUG(
m_debugLevel,
"\n \n" <<
"#CDCHits " << OriginalNoOfHits);
69 for (
const auto& aHit :
m_hits) {
71 B2WARNING(
"2nd TDC hit found, but not ready for it!");
75 short tdcCount = aHit.getTDCCount();
76 short adcCount = aHit.getADCCount();
77 short tot = aHit.getTOT();
78 short board =
m_cdcgp->getBoardID(wid);
79 short channel =
m_cdcgp->getChannelID(wid);
80 const vector<pair<short, asicChannel>> xTalks = (*m_xTalkFromDB)->getLibraryCrossTalk(channel, tdcCount, adcCount, tot);
82 int nXTalks = xTalks.size();
83 for (
int i = 0; i < nXTalks; ++i) {
84 const unsigned short tdcCount4XTalk = xTalks[i].second.TDC;
86 B2DEBUG(
m_debugLevel,
"\n" <<
" signal: " << channel <<
" " << tdcCount <<
" " << adcCount <<
" " << tot);
88 B2DEBUG(
m_debugLevel,
"xtalk: " << xTalks[i].first <<
" " << tdcCount4XTalk <<
" " << xTalks[i].second.ADC <<
" " <<
89 xTalks[i].second.TOT);
91 if (!
m_cdcgp->isBadWire(widx)) {
93 const double t0 =
m_cdcgp->getT0(widx);
96 if (LLOfTDC <= tdcCount4XTalk && tdcCount4XTalk <= ULOfTDC) {
97 const unsigned short status = 0;
98 xTalkMap.insert(make_pair(widx,
XTalkInfo(tdcCount4XTalk, xTalks[i].second.ADC, xTalks[i].second.TOT, status)));
108 B2DEBUG(
m_debugLevel,
"#xtalk hits: " << xTalkMap.size());
109 for (
const auto& aHit : xTalkMap) {
112 iterXTalkMap1 = xTalkMap1.find(wid);
113 unsigned short tdcCount = aHit.second.m_tdc;
114 unsigned short adcCount = aHit.second.m_adc;
115 unsigned short tot = aHit.second.m_tot;
116 unsigned short status = aHit.second.m_status;
118 if (iterXTalkMap1 == xTalkMap1.end()) {
119 xTalkMap1.insert(make_pair(wid,
XTalkInfo(tdcCount, adcCount, tot, status)));
122 if (tdcCount < iterXTalkMap1->second.m_tdc) {
123 iterXTalkMap1->second.m_tdc = tdcCount;
124 B2DEBUG(
m_debugLevel,
"TDC-count of current xtalk: " << tdcCount);
126 iterXTalkMap1->second.m_adc += adcCount;
127 iterXTalkMap1->second.m_tot += tot;
132 B2DEBUG(
m_debugLevel,
"#xtalk1 hits: " << xTalkMap1.size());
133 for (
const auto& aX : xTalkMap1) {
135 const unsigned short tdc4Bg = aX.second.m_tdc;
136 const unsigned short adc4Bg = aX.second.m_adc;
137 const unsigned short tot4Bg = aX.second.m_tot;
138 const unsigned short status4Bg = aX.second.m_status;
140 for (
int iHit = 0; iHit < OriginalNoOfHits; ++iHit) {
142 if (aH.
getID() != aX.first.getEWire()) {
148 const unsigned short tot4Sg = aH.
getTOT();
154 if (tdc4Sg < tdc4Bg) {
158 for (
int i = relSimHits.size() - 1; i >= 0; --i) {
159 relSimHits.remove(i);
162 for (
int i = relMCParticles.size() - 1; i >= 0; --i) {
163 relMCParticles.remove(i);
173 unsigned short s1 = tdc4Sg;
174 unsigned short s2 = tdc4Bg;
175 unsigned short w1 = tot4Sg;
176 unsigned short w2 = tot4Bg;
177 if (tdc4Sg < tdc4Bg) {
185 const unsigned short e1 = s1 - w1;
186 const unsigned short e2 = s2 - w2;
189 double pulseW = w1 + w2;
192 }
else if (e1 <= s2) {
196 unsigned short board =
m_cdcgp->getBoardID(aX.first);
205 m_hits.appendNew(tdc4Bg, adc4Bg, aX.first, status4Bg, tot4Bg);
206 B2DEBUG(
m_debugLevel,
"appended tdc,adc,tot,wid,status= " << tdc4Bg <<
" " << adc4Bg <<
" " << tot4Bg <<
" " << aX.first <<
" " <<
210 B2DEBUG(
m_debugLevel,
"original #hits, #hits= " << OriginalNoOfHits <<
" " <<
m_hits.getEntries());
216 const double el1TrgLatency =
m_cdcgp->getMeanT0();
217 B2DEBUG(
m_debugLevel,
"L1TRGLatency= " << el1TrgLatency);
218 const double c = 32. *
m_cdcgp->getTdcBinWidth();
222 int mode = (fp.getBoardID() == -1) ? 1 : 0;
223 int iNBoards =
static_cast<int>(c_nBoards);
227 for (
int bdi = 1; bdi < iNBoards; ++bdi) {
239 int bdi = fpp.getBoardID();
240 if (mode == 0 && bdi == 0)
continue;
241 if (mode == 1 && bdi == -1)
continue;
242 if (bdi < 0 || bdi >= iNBoards) B2FATAL(
"Invalid no. of FEE board!");
252 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.
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
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.