Belle II Software development
CDCDigitizerModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <cdc/modules/cdcDigitizer/CDCDigitizerModule.h>
10#include <cdc/modules/cdcDigitizer/EDepInGas.h>
11#include <cdc/utilities/ClosestApproach.h>
12
13#include <framework/datastore/RelationArray.h>
14#include <framework/gearbox/Unit.h>
15#include <framework/logging/Logger.h>
16
17#include <TRandom.h>
18#include <map>
19#include <utility>
20
21using namespace std;
22using namespace Belle2;
23using namespace CDC;
24
25// register module
26REG_MODULE(CDCDigitizer);
31 m_tdcResol(0.9825), m_driftV(4.0e-3),
32 m_driftVInv(250.0), m_propSpeedInv(27.25), m_align(true)
33{
34 // Set description
35 setDescription("Creates CDCHits from CDCSimHits.");
37
38 // Add parameters
39 // I/O
40 addParam("InputCDCSimHitsName", m_inputCDCSimHitsName, "Name of input array. Should consist of CDCSimHits.", string(""));
41 addParam("OutputCDCHitsName", m_outputCDCHitsName, "Name of output array. Will consist of CDCHits.", string(""));
42 addParam("OutputCDCHitsName4Trg", m_outputCDCHitsName4Trg,
43 "Name of output array for trigger. Can contain several hits per wire, "
44 "if they correspond to different time windows of 32ns.",
45 string("CDCHits4Trg"));
46
47 //Relations
48 addParam("MCParticlesToCDCSimHitsName", m_MCParticlesToSimHitsName,
49 "Name of relation between MCParticles and CDCSimHits used", string(""));
50 addParam("CDCSimHistToCDCHitsName", m_SimHitsTOCDCHitsName,
51 "Name of relation between the CDCSimHits and the CDCHits used", string(""));
52 addParam("OptionalFirstMCParticlesToHitsName", m_OptionalFirstMCParticlesToHitsName,
53 "Optional name of relation between the first MCParticles and CDCHits used", string("FirstMatchedParticles"));
54 addParam("OptionalAllMCParticlesToHitsName", m_OptionalAllMCParticlesToHitsName,
55 "Optional name of relation between all MCParticles and CDCHits used", string("AllMatchedParticles"));
56
57
58 //Parameters for Digitization
59 addParam("UseSimpleDigitization", m_useSimpleDigitization,
60 "If true, a simple x-t with a constant velocity is used for the drift-length to -time conversion", false);
61
62 //float Gauss Parameters
63 addParam("Fraction", m_fraction, "Fraction of first Gaussian used to smear drift length in cm", 1.0);
64 addParam("Mean1", m_mean1, "Mean value of first Gaussian used to smear drift length in cm", 0.0000);
65 addParam("Resolution1", m_resolution1, "Resolution of first Gaussian used to smear drift length in cm", 0.0130);
66 addParam("Mean2", m_mean2, "Mean value of second Gaussian used to smear drift length in cm", 0.0000);
67 addParam("Resolution2", m_resolution2, "Resolution of second Gaussian used to smear drift length in cm", 0.0000);
68
69 //Switch to control smearing
70 addParam("DoSmearing", m_doSmearing,
71 "If false, drift length will not be smeared.", true);
72
73 addParam("DoAlphaCorrection", m_alphaCorrection,
74 "If true, some hits will be removed for better charge asymmetry simulation.", false);
75
76 addParam("TrigTimeJitter", m_trigTimeJitter,
77 "Magnitude (w) of trigger timing jitter (ns). The trigger timing is randuminzed uniformly in a time window of [-w/2, +w/2].",
78 0.);
79 //Switches to control time information handling
80 addParam("AddTimeWalk", m_addTimeWalk, "A switch for time-walk (pulse-heght dep. delay); true: on; false: off", true);
81 addParam("AddInWirePropagationDelay", m_addInWirePropagationDelay,
82 "A switch used to control adding propagation delay in the wire into the final drift time or not; this is for signal hits.", true);
83 addParam("AddInWirePropagationDelay4Bg", m_addInWirePropagationDelay4Bg,
84 "The same switch but for beam bg. hits.", true);
85 addParam("AddTimeOfFlight", m_addTimeOfFlight,
86 "A switch used to control adding time of flight into the final drift time or not; this is for signal hits.", true);
87 addParam("AddTimeOfFlight4Bg", m_addTimeOfFlight4Bg,
88 "The same switch but for beam bg. hits.", true);
89 addParam("OutputNegativeDriftTime", m_outputNegativeDriftTime, "Output hits with negative drift time", true);
90 addParam("Output2ndHit", m_output2ndHit,
91 "Output the 2nd hit if exists in the time window. Note that it is not well-simulated at all, partly because no cross-talk betw. channels is simulated.",
92 false);
93 //Switch to control sense wire sag
94 addParam("CorrectForWireSag", m_correctForWireSag,
95 "A switch for sense wire sag effect; true: drift-time is calculated with the sag taken into account; false: not. Here, sag means the perturbative part which corresponds to alignment in case of wire-position. The main part (corresponding to design+displacement in wire-position) is taken into account in FullSim; you can control it via CDCJobCntlParModifier.",
96 true);
97 //Switch for negative-t0 wires
98 addParam("TreatNegT0WiresAsGood", m_treatNegT0WiresAsGood, "Treat wires with negative t0 (calibrated) as good wire4s.", true);
99
100 //Threshold
101 addParam("TDCThreshold4Outer", m_tdcThreshold4Outer,
102 "TDC threshold (dE in eV) for Layers#8-56. The value corresponds to He-C2H6 gas", 250.);
103 addParam("TDCThreshold4Inner", m_tdcThreshold4Inner,
104 "Same as TDCThreshold4Outer but for Layers#0-7,", 150.);
105 addParam("EDepInGasMode", m_eDepInGasMode,
106 "Mode for extracting energy deposit in gas from energy deposit in gas+wire; =0: scaling using electron density; 1: scaling using most probab. energy deposit; 2: similar to 2 but slightly different; 3: extraction based on probability; 4: regeneration following probability",
107 0);
108
109 //ADC Threshold
110 addParam("ADCThreshold", m_adcThreshold,
111 "Threshold for ADC-count (in unit of count). ADC-count < threshold is treated as count=0.", 2);
112 addParam("tMin", m_tMin, "Lower edge of time window in ns; valid only for UseDB4FEE=false", -100.);
113 addParam("tMaxOuter", m_tMaxOuter, "Upper edge of time window in ns for the normal-cell layers; valid only for UseDB4FEE=false",
114 500.);
115 addParam("tMaxInner", m_tMaxInner, "Upper edge of time window in ns for the small-cell layers; valid only for UseDB4FEE=false",
116 300.);
117
118 //Switch for database
119 addParam("UseDB4FEE", m_useDB4FEE, "Fetch and use FEE params. from database or not", true);
120 addParam("UseDB4EDepToADC", m_useDB4EDepToADC, "Uuse edep-to-ADC conversion params. from database or not", true);
121 addParam("UseDB4RunGain", m_useDB4RunGain, "Fetch and use run gain from database or not", true);
122 addParam("OverallGainFactor", m_overallGainFactor, "Overall gain factor for adjustment", 1.0);
123
124 //Switch for synchronization
125 addParam("Synchronization", m_synchronization, "Synchronize timing with other sub-detectors", m_synchronization);
126 addParam("Randomization", m_randomization, "Randomize timing with other sub-detectors; valid only for Synchronization=false",
128 addParam("OffsetForGetTriggerBin", m_offsetForTriggerBin, "Input to getCDCTriggerBin(offset), either of 0,1,2 or 3",
130 addParam("TrgTimingOffsetInCount", m_trgTimingOffsetInCount,
131 "L1 trigger timing offset in count, [0,7] in a trigger bin. The default value is from exp14, while the value from exp12 is 2. This run dependence may be taken into account later if needed",
133 addParam("ShiftOfTimeWindowIn32Count", m_shiftOfTimeWindowIn32Count,
134 "Shift of time window in 32count for synchronization (L1 timing=0)", m_shiftOfTimeWindowIn32Count);
135
136 //Some FEE params.
137 addParam("TDCThresholdOffset", m_tdcThresholdOffset, "Offset for TDC (digital) threshold (mV)", 3828.);
138 addParam("AnalogGain", m_analogGain, "Analog gain (V/pC)", 1.09);
139 addParam("DigitalGain", m_digitalGain, "Digital gain (V/pC)", 7.);
140 addParam("ADCBinWidth", m_adcBinWidth, "ADC bin width (mV)", 2.);
141
142 addParam("AddFudgeFactorForSigma", m_addFudgeFactorForSigma,
143 "Additional fudge factor for space resol. (common to all cells)", 1.);
144 addParam("SpaceChargeEffect", m_spaceChargeEffect, "Switch for space charge effect", true);
145 addParam("DegOfSPEOnThreshold", m_degOfSPEOnThreshold,
146 "Degree of space charge effect on timing threshold; specify the range [0,1]; =1: full effect on threshold; =0: no effect",
148
149 addParam("AddXTalk", m_addXTalk, "A switch for crosstalk; true: on; false: off", true);
150 addParam("Issue2ndHitWarning", m_issue2ndHitWarning, "=true: issue a warning when a 2nd TDC hit is found.", true);
151 addParam("IncludeEarlyXTalks", m_includeEarlyXTalks, "=true: include earlier x-talks as well than the signal hit in question.",
152 true);
153 addParam("DebugLevel", m_debugLevel, "Debug level; 20-29 are usable.", 20);
154 addParam("DebugLevel4XTalk", m_debugLevel4XTalk, "Debug level for crosstalk; 20-29 are usable.", 21);
155
156 //Gain smearing
157 addParam("GasGainSmearing", m_gasGainSmearing, "Switch for gas gain smearing for ADC simulation; true: on; false: off",
159 addParam("EffWForGasGainSmearing", m_effWForGasGainSmearing,
160 "Effective energy (keV) needed for one electron production for gas gain smearing; average for alpha- and beta-sources.",
162 addParam("ThetaOfPolyaFunction", m_thetaOfPolya, "Theta of Polya function for gas gain smearing", m_thetaOfPolya);
163 addParam("ExtraADCSmearing", m_extraADCSmearing, "Switch for extra ADC smearing; true: on; false: off", m_extraADCSmearing);
164
165 // Switch for optional relations
166 addParam("MatchAllMCParticles", m_matchAllMCParticles, "Switch to store all MCRelations that produced a SimHit", false);
167 addParam("MatchFirstMCParticles", m_matchFirstMCParticles,
168 "Switch to store all MCRelations for the first three SimHits instead of only the first", false);
169
170}
171
173{
175 m_simClockState.isOptional();
176
177 // Register the arrays in the DataStore, that are to be added in this module.
178 m_cdcHits.registerInDataStore(m_outputCDCHitsName);
179 m_simHits.registerRelationTo(m_cdcHits);
180 m_mcParticles.registerRelationTo(m_cdcHits);
183
184 // Arrays for trigger.
185 m_cdcHits4Trg.registerInDataStore(m_outputCDCHitsName4Trg);
186 m_simHits.registerRelationTo(m_cdcHits4Trg);
187 m_mcParticles.registerRelationTo(m_cdcHits4Trg);
188
190 CDCGeometryPar& cdcgp = *m_cdcgp;
194 m_driftV = cdcgp.getNominalDriftV();
195 m_driftVInv = 1. / m_driftV;
196 m_propSpeedInv = 1. / cdcgp.getNominalPropSpeed();
198 m_totalFudgeFactor = m_cdcgp->getFudgeFactorForSigma(2);
200 B2DEBUG(m_debugLevel, "totalFugeF in Digi= " << m_totalFudgeFactor);
201
202 if (m_useDB4FEE) {
204 if ((*m_fEElectronicsFromDB).isValid()) {
205 (*m_fEElectronicsFromDB).addCallback(this, &CDCDigitizerModule::setFEElectronics);
207 } else {
208 B2FATAL("CDCDigitizer:: CDCFEElectronics not valid !");
209 }
210 }
211
212 if (m_useDB4RunGain) {
214 if ((*m_runGainFromDB).isValid()) {
215 (*m_runGainFromDB).addCallback(this, &CDCDigitizerModule::setSemiTotalGain);
216 } else {
217 B2FATAL("CDCDedxRunGain invalid!");
218 }
219
221 if ((*m_gain0FromDB).isValid()) {
222 (*m_gain0FromDB).addCallback(this, &CDCDigitizerModule::setSemiTotalGain);
223 } else {
224 B2FATAL("CDCDedxScaleFactor invalid!");
225 }
226
228 if ((*m_wireGainFromDB).isValid()) {
229 (*m_wireGainFromDB).addCallback(this, &CDCDigitizerModule::setSemiTotalGain);
231 } else {
232 B2FATAL("CDCDedxWireGain invalid!");
233 }
234 }
235
236 if (m_addXTalk) {
238 if ((*m_xTalkFromDB).isValid()) {
239 } else {
240 B2FATAL("CDCCrossTalkLibrary invalid!");
241 }
242 }
243
245 if ((*m_corrToThresholdFromDB).isValid()) {
246 } else {
247 B2FATAL("CDCCorrToThresholds invalid!");
248 }
249
250 if (m_alphaCorrection) {
251 if (!m_alphaScaleFactorsFromDB.isValid()) {
252 B2FATAL("CDCAlphaScaleFactorForAsymmetry invalid!");
253 }
254 }
255
256 if (m_useDB4EDepToADC) {
257 ushort firstLayerOffset = m_cdcgp->getOffsetOfFirstLayer();
258 if (m_cdcgp->getEDepToADCMainFactor(firstLayerOffset, 0) == 0.) {
259 B2FATAL("CDCEDepToADCConversion payloads are unavailable!");
260 }
261 }
262
263 // Set timing sim. mode
264 if (m_useDB4FEE) {
265 if (m_synchronization) { // synchronization
266 m_tSimMode = 0;
267 } else {
268 if (m_randomization) { // radomization
269 m_tSimMode = 1;
270 } else {
271 m_tSimMode = 2; // old sim.
272 }
273 }
274 } else {
275 m_tSimMode = 3; // old sim. w/o relying on fee db
276 }
277 B2DEBUG(m_debugLevel, "timing sim. mode= " << m_tSimMode);
278 if (m_tSimMode < 0 || m_tSimMode > 3) B2FATAL("invalid timing sim. mode= " << m_tSimMode);
279}
280
282{
283 // Get SimHit array, MCParticle array, and relation between the two.
284 RelationArray mcParticlesToCDCSimHits(m_mcParticles, m_simHits); //RelationArray created by CDC SensitiveDetector
285
286
287 //--- Start Digitization --------------------------------------------------------------------------------------------
288 // Merge the hits in the same cell and save them into CDC signal map.
289
290 // Define signal map
291 map<WireID, SignalInfo> signalMap;
292 map<WireID, SignalInfo>::iterator iterSignalMap;
293 // Define adc map
294 map<WireID, unsigned short> adcMap;
295 map<WireID, unsigned short>::iterator iterADCMap;
296
297 // signal map for trigger
298 map<pair<WireID, unsigned>, SignalInfo> signalMapTrg;
299 map<pair<WireID, unsigned>, SignalInfo>::iterator iterSignalMapTrg;
300
301 // signal map for all MCParticles: Wire <-> MCArrayIndex
302 map<WireID, std::set<int>> particleMap;
303 map<WireID, std::set<int>>::iterator iterParticleMap;
304
305
306 // Set time window per event
307 if (m_tSimMode == 0 || m_tSimMode == 1) {
308 int trigBin = 0;
309 if (m_simClockState.isValid()) {
310 trigBin = m_simClockState->getCDCTriggerBin(m_offsetForTriggerBin);
311 } else {
312 if (m_tSimMode == 0) {
313 B2DEBUG(m_debugLevel, "SimClockState unavailable so switched the mode from synchro to random.");
314 m_tSimMode = 1;
315 }
316 trigBin = gRandom->Integer(4);
317 }
318 if (trigBin < 0 || trigBin > 3) B2ERROR("Invalid trigger bin; must be an integer [0,3]!");
319 unsigned short offs = 8 * trigBin + m_trgTimingOffsetInCount;
320 B2DEBUG(m_debugLevel, "tSimMode,trigBin,offs= " << m_tSimMode << " " << trigBin << " " << offs);
321
322 //TODO: simplify the following 7 lines and setFEElectronics()
323 for (unsigned short bd = 1; bd < c_nBoards; ++bd) {
324 const short tMaxInCount = 32 * (m_shiftOfTimeWindowIn32Count - m_trgDelayInCount[bd]) - offs;
325 const short tMinInCount = tMaxInCount - 32 * m_widthOfTimeWindowInCount[bd];
326 B2DEBUG(m_debugLevel, bd << " " << tMinInCount << " " << tMaxInCount);
327 m_uprEdgeOfTimeWindow[bd] = m_tdcBinWidth * tMaxInCount;
328 m_lowEdgeOfTimeWindow[bd] = m_tdcBinWidth * tMinInCount;
329 }
330 }
331
332 // Set trigger timing jitter for this event
333 double trigTiming = m_trigTimeJitter == 0. ? 0. : m_trigTimeJitter * (gRandom->Uniform() - 0.5);
334
335 // Loop over all hits
336 int nHits = m_simHits.getEntries();
337 B2DEBUG(m_debugLevel, "Number of CDCSimHits in the current event: " << nHits);
338 for (int iHits = 0; iHits < nHits; ++iHits) {
339 // Get a hit
340 m_aCDCSimHit = m_simHits[iHits];
341
342 // Hit geom. info
343 m_wireID = m_aCDCSimHit->getWireID();
344 if (m_wireID.getISuperLayer() < m_cdcgp->getOffsetOfFirstSuperLayer()) {
345 B2FATAL("SimHit with wireID " << m_wireID << " is in CDC SuperLayer: " << m_wireID.getISuperLayer() << " which should not happen.");
346 }
347
348 m_posFlag = m_aCDCSimHit->getLeftRightPassageRaw();
349 m_boardID = m_cdcgp->getBoardID(m_wireID);
350 m_posWire = m_aCDCSimHit->getPosWire();
351 m_posTrack = m_aCDCSimHit->getPosTrack();
352 m_momentum = m_aCDCSimHit->getMomentum();
353 m_flightTime = m_aCDCSimHit->getFlightTime();
354 m_globalTime = m_aCDCSimHit->getGlobalTime();
355 m_driftLength = m_aCDCSimHit->getDriftLength() * Unit::cm;
356
357 //include alignment effects
358 //basically align flag should be always on since on/off is controlled by the input alignment.xml file itself.
359 m_align = true;
360
361 B2Vector3D bwpAlign = m_cdcgp->wireBackwardPosition(m_wireID, CDCGeometryPar::c_Aligned);
362 B2Vector3D fwpAlign = m_cdcgp->wireForwardPosition(m_wireID, CDCGeometryPar::c_Aligned);
363
364 B2Vector3D bwp = m_cdcgp->wireBackwardPosition(m_wireID);
365 B2Vector3D fwp = m_cdcgp->wireForwardPosition(m_wireID);
366
367 //skip correction for wire-position alignment if unnecessary
368 if ((bwpAlign - bwp).Mag() == 0. && (fwpAlign - fwp).Mag() == 0.) m_align = false;
369
371
372 bwp = bwpAlign;
373 fwp = fwpAlign;
374
376 double zpos = m_posWire.Z();
377 double bckYSag = bwp.Y();
378 double forYSag = fwp.Y();
379
380 CDCGeometryPar::EWirePosition set = CDCGeometryPar::c_Aligned;
381 const int layerID = m_wireID.getICLayer();
382 const int wireID = m_wireID.getIWire();
383 m_cdcgp->getWireSagEffect(set, layerID, wireID, zpos, bckYSag, forYSag);
384 bwp.SetY(bckYSag);
385 fwp.SetY(forYSag);
386 }
387
388 const B2Vector3D L = 5. * m_momentum.Unit(); //(cm) tentative
389 B2Vector3D posIn = m_posTrack - L;
390 B2Vector3D posOut = m_posTrack + L;
391 B2Vector3D posTrack = m_posTrack;
392 B2Vector3D posWire = m_posWire;
393
394 m_driftLength = ClosestApproach(bwp, fwp, posIn, posOut, posTrack, posWire);
395 m_posTrack = posTrack;
396 m_posWire = posWire;
397
398 double deltaTime = 0.; //tentative (probably ok...)
399 m_flightTime += deltaTime;
400 m_globalTime += deltaTime;
401 m_posFlag = m_cdcgp->getNewLeftRightRaw(m_posWire, m_posTrack, m_momentum);
402 }
403
404 // Calculate measurement time.
405 // Smear drift length
406 double hitDriftLength = m_driftLength;
407 double dDdt = getdDdt(hitDriftLength);
408 if (m_doSmearing) {
409 hitDriftLength = smearDriftLength(hitDriftLength, dDdt);
410 }
411
412 //set flags
413 bool addTof = m_addTimeOfFlight4Bg;
414 bool addDelay = m_addInWirePropagationDelay4Bg;
415 if (m_aCDCSimHit->getBackgroundTag() == 0) {
416 addTof = m_addTimeOfFlight;
418 }
419 double hitDriftTime = getDriftTime(hitDriftLength, addTof, addDelay);
420
421 //add randamized event time for a beam bg. hit
422 if (m_aCDCSimHit->getBackgroundTag() != 0) {
423 hitDriftTime += m_globalTime - m_flightTime;
424 }
425
426 //add trigger timing jitter
427 hitDriftTime += trigTiming;
428
429 //apply time window cut
430 double tMin = m_tMin;
431 double tMax = m_tMaxOuter;
432 if (m_wireID.getISuperLayer() == 0) tMax = m_tMaxInner;
433 if (m_tSimMode <= 2) {
436 }
437 if (hitDriftTime < tMin || hitDriftTime > tMax) continue;
438
439 //Sum ADC count
440 const double stepLength = m_aCDCSimHit->getStepLength() * Unit::cm;
441 const double costh = m_momentum.Z() / m_momentum.Mag();
442 double hitdE = m_aCDCSimHit->getEnergyDep();
443 if (m_cdcgp->getMaterialDefinitionMode() != 2) { // for non wire-by-wire mode
444 static EDepInGas& edpg = EDepInGas::getInstance();
445 hitdE = edpg.getEDepInGas(m_eDepInGasMode, m_aCDCSimHit->getPDGCode(), m_momentum.Mag(), stepLength, hitdE);
446 }
447
448 double convFactorForThreshold = 1;
449 //TODO: modify the following function so that it can output timing signal in Volt in future
450 unsigned short adcCount = 0;
451 makeSignalsAfterShapers(m_wireID, hitdE, stepLength, costh, adcCount, convFactorForThreshold);
452 const unsigned short adcTh = m_useDB4FEE ? m_adcThresh[m_boardID] : m_adcThreshold;
453
454 if (adcCount < adcTh) adcCount = 0;
455 iterADCMap = adcMap.find(m_wireID);
456 if (iterADCMap == adcMap.end()) {
457 adcMap.insert(make_pair(m_wireID, adcCount));
458 } else {
459 iterADCMap->second += adcCount;
460 }
461
462 //Apply energy threshold
463 // If hitdE < dEThreshold, the hit is ignored
464 double dEThreshold = 0.;
466 dEThreshold = m_tdcThresh[m_boardID] / convFactorForThreshold * Unit::keV;
467 } else {
468 dEThreshold = (m_wireID.getISuperLayer() == 0) ? m_tdcThreshold4Inner : m_tdcThreshold4Outer;
469 dEThreshold *= Unit::eV;
470 }
471 dEThreshold *= (*m_corrToThresholdFromDB)->getParam(m_wireID.getICLayer());
472 B2DEBUG(m_debugLevel, "hitdE,dEThreshold,driftLength " << hitdE << " " << dEThreshold << " " << hitDriftLength);
473
474 if (hitdE < dEThreshold) {
475 B2DEBUG(m_debugLevel, "Below Ethreshold: " << hitdE << " " << dEThreshold);
476 continue;
477 }
478
479 // add one hit per trigger time window to the trigger signal map
480 unsigned short trigWindow = floor((hitDriftTime - tMin) * m_tdcBinWidthInv / 32);
481 iterSignalMapTrg = signalMapTrg.find(make_pair(m_wireID, trigWindow));
482 if (iterSignalMapTrg == signalMapTrg.end()) {
483 signalMapTrg.insert(make_pair(make_pair(m_wireID, trigWindow),
484 SignalInfo(iHits, hitDriftTime, adcCount)));
485 } else {
486 if (hitDriftTime < iterSignalMapTrg->second.m_driftTime) {
487 iterSignalMapTrg->second.m_driftTime = hitDriftTime;
488 iterSignalMapTrg->second.m_simHitIndex = iHits;
489 }
490 iterSignalMapTrg->second.m_charge += adcCount;
491 }
492
493 // Reject totally-dead wire; to be replaced by isDeadWire() in future
494 // N.B. The following lines for badwire must be after the above lines for trigger because badwires are different between trigger and tracking.
495 // Badwires for trigger are taken into account separately in the tsim module
496 if (m_cdcgp->isBadWire(m_wireID)) {
497 continue;
498 }
499 // Reject partly-dead wire as well
500 double eff = 1.;
501 if (m_cdcgp->isDeadWire(m_wireID, eff)) {
502 if (eff < gRandom->Uniform()) continue;
503 }
504
505 // For TOT simulation, calculate drift length from In to the wire, and Out to the wire. The calculation is apprximate ignoring wire sag (this would be ok because TOT simulation is not required to be so accurate).
506 const double a = bwpAlign.X();
507 const double b = bwpAlign.Y();
508 const double c = bwpAlign.Z();
509 const B2Vector3D fmbAlign = fwpAlign - bwpAlign;
510 const double lmn = 1. / fmbAlign.Mag();
511 const double l = fmbAlign.X() * lmn;
512 const double m = fmbAlign.Y() * lmn;
513 const double n = fmbAlign.Z() * lmn;
514
515 double dx = m_aCDCSimHit->getPosIn().X() - a;
516 double dy = m_aCDCSimHit->getPosIn().Y() - b;
517 double dz = m_aCDCSimHit->getPosIn().Z() - c;
518 double sub = l * dx + m * dy + n * dz;
519 const double driftLFromIn = sqrt(dx * dx + dy * dy + dz * dz - sub * sub);
520
521 dx = m_aCDCSimHit->getPosOut().X() - a;
522 dy = m_aCDCSimHit->getPosOut().Y() - b;
523 dz = m_aCDCSimHit->getPosOut().Z() - c;
524 sub = l * dx + m * dy + n * dz;
525 const double driftLFromOut = sqrt(dx * dx + dy * dy + dz * dz - sub * sub);
526
527 const double maxDriftL = std::max(driftLFromIn, driftLFromOut);
528 const double minDriftL = m_driftLength;
529 B2DEBUG(m_debugLevel, "driftLFromIn= " << driftLFromIn << " driftLFromOut= " << driftLFromOut << " minDriftL= " << minDriftL <<
530 " maxDriftL= "
531 <<
532 maxDriftL << "m_driftLength= " << m_driftLength);
533
534 iterSignalMap = signalMap.find(m_wireID);
535
537 iterParticleMap = particleMap.find(m_wireID);
538 RelationVector<MCParticle> rels = m_aCDCSimHit->getRelationsFrom<MCParticle>();
539
540 int mcIndex = -1;
541 if (rels.size() != 0) {
542 if (rels.weight(0) > 0) {
543 const MCParticle* mcparticle = rels[0];
544 mcIndex = int(mcparticle->getIndex());
545 }
546 }
547
548 if (mcIndex >= 0) {
549 if (iterParticleMap == particleMap.end()) {
550 std::set<int> vecmc = {mcIndex};
551 particleMap.insert(make_pair(m_wireID, vecmc));
552 } else {
553 iterParticleMap->second.insert(mcIndex);
554 }
555 }
556 }
557
558 if (iterSignalMap == signalMap.end()) {
559 // new entry
560 signalMap.insert(make_pair(m_wireID, SignalInfo(iHits, hitDriftTime, adcCount, maxDriftL, minDriftL)));
561 B2DEBUG(m_debugLevel, "Creating new Signal with encoded wire number: " << m_wireID);
562 } else {
563 // ... smallest drift time has to be checked, ...
564 if (hitDriftTime < iterSignalMap->second.m_driftTime) {
565 iterSignalMap->second.m_driftTime3 = iterSignalMap->second.m_driftTime2;
566 iterSignalMap->second.m_simHitIndex3 = iterSignalMap->second.m_simHitIndex2;
567 iterSignalMap->second.m_driftTime2 = iterSignalMap->second.m_driftTime;
568 iterSignalMap->second.m_simHitIndex2 = iterSignalMap->second.m_simHitIndex;
569 iterSignalMap->second.m_driftTime = hitDriftTime;
570 iterSignalMap->second.m_simHitIndex = iHits;
571 B2DEBUG(m_debugLevel, "hitDriftTime of current Signal: " << hitDriftTime << ", hitDriftLength: " << hitDriftLength);
572 } else if (hitDriftTime < iterSignalMap->second.m_driftTime2) {
573 iterSignalMap->second.m_driftTime3 = iterSignalMap->second.m_driftTime2;
574 iterSignalMap->second.m_simHitIndex3 = iterSignalMap->second.m_simHitIndex2;
575 iterSignalMap->second.m_driftTime2 = hitDriftTime;
576 iterSignalMap->second.m_simHitIndex2 = iHits;
577 } else if (hitDriftTime < iterSignalMap->second.m_driftTime3) {
578 iterSignalMap->second.m_driftTime3 = hitDriftTime;
579 iterSignalMap->second.m_simHitIndex3 = iHits;
580 }
581 // ... total charge has to be updated.
582 iterSignalMap->second.m_charge += adcCount;
583
584 // set max and min driftLs
585 if (iterSignalMap->second.m_maxDriftL < maxDriftL) iterSignalMap->second.m_maxDriftL = maxDriftL;
586 if (iterSignalMap->second.m_minDriftL > minDriftL) iterSignalMap->second.m_minDriftL = minDriftL;
587 B2DEBUG(m_debugLevel, "maxDriftL in struct= " << iterSignalMap->second.m_maxDriftL << "minDriftL in struct= " <<
588 iterSignalMap->second.m_minDriftL);
589 }
590
591 } // end loop over SimHits.
592
593 //--- Now Store the results into CDCHits and
594 // create corresponding relations between SimHits and CDCHits.
595
596 unsigned int iCDCHits = 0;
597 RelationArray cdcSimHitsToCDCHits(m_simHits, m_cdcHits); //SimHit<->CDCHit
598 RelationArray mcParticlesToCDCHits(m_mcParticles, m_cdcHits); //MCParticle<->CDCHit
599
600 for (iterSignalMap = signalMap.begin(); iterSignalMap != signalMap.end(); ++iterSignalMap) {
601
602 //add time-walk (here for simplicity)
603 iterADCMap = adcMap.find(iterSignalMap->first);
604 unsigned short adcCount = iterADCMap != adcMap.end() ? iterADCMap->second : 0;
605
606 if (m_addTimeWalk) {
607 B2DEBUG(m_debugLevel, "timewalk= " << m_cdcgp->getTimeWalk(iterSignalMap->first, adcCount));
608 iterSignalMap->second.m_driftTime += m_cdcgp->getTimeWalk(iterSignalMap->first, adcCount);
609 }
610
611 //remove negative drift time (TDC) upon request
613 iterSignalMap->second.m_driftTime < 0.) {
614 continue;
615 }
616
617 //apply correction on alpha, to calibrate the charge asymmetry at hit-level
618 if (m_alphaCorrection) {
619 int iHits = iterSignalMap->second.m_simHitIndex;
620 m_aCDCSimHit = m_simHits[iHits];
621 m_posWire = m_aCDCSimHit->getPosWire();
622 m_momentum = m_aCDCSimHit->getMomentum();
623 int iLayer = m_aCDCSimHit->getWireID().getICLayer();
624 double alpha = m_cdcgp->getAlpha(m_posWire, m_momentum);
625
626 double Scale = m_alphaScaleFactorsFromDB->getScaleFactor(iLayer, alpha);
627 double random = gRandom->Uniform();
628 if ((Scale < 1) && (alpha > 0)) {
629 if (random > Scale) continue ; // remove this hit
630 }
631 if ((Scale > 1) && (alpha < 0)) {
632 if (random > 1. / Scale) continue ; // remove this hit
633 }
634 }
635
636 //N.B. No bias (+ or -0.5 count) is introduced on average in digitization by the real TDC (info. from KEK electronics division). So round off (t0 - drifttime) below.
637 unsigned short tdcCount = static_cast<unsigned short>((getPositiveT0(iterSignalMap->first) - iterSignalMap->second.m_driftTime) *
638 m_tdcBinWidthInv + 0.5);
639
640 //calculate tot; hard-coded currently
641 double deltaDL = iterSignalMap->second.m_maxDriftL - iterSignalMap->second.m_minDriftL;
642 if (deltaDL < 0.) {
643 B2DEBUG(m_debugLevel, "negative deltaDL= " << deltaDL);
644 deltaDL = 0.;
645 }
646 const unsigned short boardID = m_cdcgp->getBoardID(iterSignalMap->first);
647 unsigned short tot = std::min(std::round(5.92749 * deltaDL + 2.59706), static_cast<double>(m_widthOfTimeWindowInCount[boardID]));
648 if (m_adcThresh[boardID] > 0) {
649 tot = std::min(static_cast<int>(tot), static_cast<int>(adcCount / m_adcThresh[boardID]));
650 }
651
652 CDCHit* firstHit = m_cdcHits.appendNew(tdcCount, adcCount, iterSignalMap->first, 0, tot);
653 //set a relation: CDCSimHit -> CDCHit
654 cdcSimHitsToCDCHits.add(iterSignalMap->second.m_simHitIndex, iCDCHits);
655
656 //set a relation: MCParticle -> CDCHit
657 RelationVector<MCParticle> rels = m_simHits[iterSignalMap->second.m_simHitIndex]->getRelationsFrom<MCParticle>();
658 if (rels.size() != 0) {
659 //assumption: only one MCParticle
660 const MCParticle* mcparticle = rels[0];
661 double weight = rels.weight(0);
662 mcparticle->addRelationTo(firstHit, weight);
663 }
664
665 // Set relations to all particles that created a SimHit
667 iterParticleMap = particleMap.find(iterSignalMap->first);
668 if (iterParticleMap != particleMap.end()) {
669 std::set<int> vv = iterParticleMap->second;
670 for (std::set<int>::iterator it = vv.begin(); it != vv.end(); ++it) {
671 // set all relations
672 int idx = *it;
673 MCParticle* part = m_mcParticles[idx - 1];
675 }
676 }
677 }
678
679 //set all relations to first hit if requested but dont create additional hits!
680 // relation 1
681 if (m_matchFirstMCParticles > 0) {
682 if (iterSignalMap->second.m_simHitIndex >= 0) {
683 RelationVector<MCParticle> rels1 = m_simHits[iterSignalMap->second.m_simHitIndex]->getRelationsFrom<MCParticle>();
684 if (rels1.size() != 0) {
685 //assumption: only one MCParticle
686 const MCParticle* mcparticle = rels1[0];
687 double weight = rels1.weight(0);
688 mcparticle->addRelationTo(firstHit, weight, m_OptionalFirstMCParticlesToHitsName);
689 }
690 }
691
692 // relation 2
693 if (iterSignalMap->second.m_simHitIndex2 >= 0) {
694 RelationVector<MCParticle> rels2 = m_simHits[iterSignalMap->second.m_simHitIndex2]->getRelationsFrom<MCParticle>();
695 if (rels2.size() != 0) {
696 //assumption: only one MCParticle
697 const MCParticle* mcparticle = rels2[0];
698 double weight = rels2.weight(0);
699 mcparticle->addRelationTo(firstHit, weight, m_OptionalFirstMCParticlesToHitsName);
700 }
701 }
702
703 // relation 3
704 if (iterSignalMap->second.m_simHitIndex3 >= 0) {
705 RelationVector<MCParticle> rels3 = m_simHits[iterSignalMap->second.m_simHitIndex3]->getRelationsFrom<MCParticle>();
706 if (rels3.size() != 0) {
707 //assumption: only one MCParticle
708 const MCParticle* mcparticle = rels3[0];
709 double weight = rels3.weight(0);
710 mcparticle->addRelationTo(firstHit, weight, m_OptionalFirstMCParticlesToHitsName);
711 }
712 }
713
714
715 }
716
717 //Set 2nd-hit related things if it exists
718 if (m_output2ndHit && iterSignalMap->second.m_simHitIndex2 >= 0) {
719 unsigned short tdcCount2 = static_cast<unsigned short>((getPositiveT0(iterSignalMap->first) - iterSignalMap->second.m_driftTime2) *
720 m_tdcBinWidthInv + 0.5);
721 if (tdcCount2 != tdcCount) {
722 CDCHit* secondHit = m_cdcHits.appendNew(tdcCount2, adcCount, iterSignalMap->first, 0, tot);
723 secondHit->set2ndHitFlag();
724 secondHit->setOtherHitIndices(firstHit);
725
726 //set a relation: CDCSimHit -> CDCHit
727 ++iCDCHits;
728 cdcSimHitsToCDCHits.add(iterSignalMap->second.m_simHitIndex2, iCDCHits);
729
730 //set a relation: MCParticle -> CDCHit
731 rels = m_simHits[iterSignalMap->second.m_simHitIndex2]->getRelationsFrom<MCParticle>();
732 if (rels.size() != 0) {
733 //assumption: only one MCParticle
734 const MCParticle* mcparticle = rels[0];
735 double weight = rels.weight(0);
736 mcparticle->addRelationTo(secondHit, weight);
737 }
738 } else { //Check the 3rd hit when tdcCount = tdcCount2
739 if (iterSignalMap->second.m_simHitIndex3 >= 0) {
740 unsigned short tdcCount3 = static_cast<unsigned short>((getPositiveT0(iterSignalMap->first) - iterSignalMap->second.m_driftTime3) *
741 m_tdcBinWidthInv + 0.5);
742 if (tdcCount3 != tdcCount) {
743 CDCHit* secondHit = m_cdcHits.appendNew(tdcCount3, adcCount, iterSignalMap->first, 0, tot);
744 secondHit->set2ndHitFlag();
745 secondHit->setOtherHitIndices(firstHit);
746
747 //set a relation: CDCSimHit -> CDCHit
748 ++iCDCHits;
749 cdcSimHitsToCDCHits.add(iterSignalMap->second.m_simHitIndex3, iCDCHits);
750
751 //set a relation: MCParticle -> CDCHit
752 rels = m_simHits[iterSignalMap->second.m_simHitIndex3]->getRelationsFrom<MCParticle>();
753 if (rels.size() != 0) {
754 //assumption: only one MCParticle
755 const MCParticle* mcparticle = rels[0];
756 double weight = rels.weight(0);
757 mcparticle->addRelationTo(secondHit, weight);
758 }
759 }
760 }
761 } //end of checking tdcCount 1=2 ?
762 } //end of 2nd hit setting
763
764 ++iCDCHits;
765 }
766
767 //Add crosstalk
768 if (m_addXTalk) addXTalk();
769
770 // Store the results with trigger time window in a separate array
771 // with corresponding relations.
772 for (iterSignalMapTrg = signalMapTrg.begin(); iterSignalMapTrg != signalMapTrg.end(); ++iterSignalMapTrg) {
773 unsigned short adcCount = iterSignalMapTrg->second.m_charge;
774 unsigned short tdcCount =
775 static_cast<unsigned short>((getPositiveT0(iterSignalMapTrg->first.first) -
776 iterSignalMapTrg->second.m_driftTime) * m_tdcBinWidthInv + 0.5);
777 const CDCHit* cdcHit = m_cdcHits4Trg.appendNew(tdcCount, adcCount, iterSignalMapTrg->first.first);
778
779 // relations
780 m_simHits[iterSignalMapTrg->second.m_simHitIndex]->addRelationTo(cdcHit);
781 RelationVector<MCParticle> rels = m_simHits[iterSignalMapTrg->second.m_simHitIndex]->getRelationsFrom<MCParticle>();
782 if (rels.size() != 0) {
783 //assumption: only one MCParticle
784 const MCParticle* mcparticle = rels[0];
785 double weight = rels.weight(0);
786 mcparticle->addRelationTo(cdcHit, weight);
787 }
788 }
789}
790
791double CDCDigitizerModule::smearDriftLength(const double driftLength, const double dDdt)
792{
793 double mean = 0.;
794 double resolution;
795
797 if (gRandom->Uniform() <= m_fraction) {
798 mean = m_mean1;
799 resolution = m_resolution1;
800 } else {
801 mean = m_mean2;
802 resolution = m_resolution2;
803 }
804 } else {
805 const unsigned short leftRight = m_posFlag;
806 double alpha = m_cdcgp->getAlpha(m_posWire, m_momentum);
807 double theta = m_cdcgp->getTheta(m_momentum);
808 resolution = m_cdcgp->getSigma(driftLength, m_wireID.getICLayer(), leftRight, alpha, theta);
809 resolution *= m_totalFudgeFactor;
810 }
811
812 //subtract resol. due to digitization, which'll be added later in the digitization
813
814 double diff = resolution - dDdt * m_tdcResol;
815 if (diff > 0.) {
816 resolution = sqrt(diff * (resolution + dDdt * m_tdcResol));
817 } else {
818 resolution = 0.;
819 }
820
821 // Smear drift length
822 double newDL = gRandom->Gaus(driftLength + mean, resolution);
823 while (newDL <= 0.) newDL = gRandom->Gaus(driftLength + mean, resolution);
824
825 return newDL;
826}
827
828
829double CDCDigitizerModule::getdDdt(const double driftL)
830{
831 //---------------------------------------------------------------------------------
832 // Calculates the 1'st derivative: dD/dt, where D: drift length before smearing; t: drift time
833 //---------------------------------------------------------------------------------
834
835 double dDdt = m_driftV;
836
838 const unsigned short layer = m_wireID.getICLayer();
839 const unsigned short leftRight = m_posFlag;
840 double alpha = m_cdcgp->getAlpha(m_posWire, m_momentum);
841 double theta = m_cdcgp->getTheta(m_momentum);
842 double t = m_cdcgp->getDriftTime(driftL, layer, leftRight, alpha, theta);
843 dDdt = m_cdcgp->getDriftV(t, layer, leftRight, alpha, theta);
844 }
845
846 return dDdt;
847}
848
849
850double CDCDigitizerModule::getDriftTime(const double driftLength, const bool addTof, const bool addDelay)
851{
852 //---------------------------------------------------------------------------------
853 // Method returning electron drift time (parameters: position in cm)
854 // T(drift) = TOF + T(true drift time) + T(propagation delay in wire) - T(event),
855 // T(event) is a timing of event, which includes a time jitter due to
856 // the trigger system.
857 //---------------------------------------------------------------------------------
858
859 double driftT = 0.;
860
862 driftT = (driftLength / Unit::cm) * m_driftVInv;
863 } else {
864 const unsigned short layer = m_wireID.getICLayer();
865 const unsigned short leftRight = m_posFlag;
866 double alpha = m_cdcgp->getAlpha(m_posWire, m_momentum);
867 double theta = m_cdcgp->getTheta(m_momentum);
868 driftT = m_cdcgp->getDriftTime(driftLength, layer, leftRight, alpha, theta);
869 }
870
871 if (addTof) {
872 driftT += m_flightTime; // in ns
873 }
874
875 if (addDelay) {
876 //calculate signal propagation length in the wire
877 CDCGeometryPar::EWirePosition set = m_align ? CDCGeometryPar::c_Aligned : CDCGeometryPar::c_Base;
878 B2Vector3D backWirePos = m_cdcgp->wireBackwardPosition(m_wireID, set);
879
880 double propLength = (m_posWire - backWirePos).Mag();
881 //TODO: replace the following with cached reference
882 if (m_gcp->getSenseWireZposMode() == 1) {
883 const unsigned short layer = m_wireID.getICLayer();
884 propLength += m_cdcgp->getBwdDeltaZ(layer);
885 }
886
888 driftT += (propLength / Unit::cm) * m_propSpeedInv;
889 } else {
890 const unsigned short layer = m_wireID.getICLayer();
891 driftT += (propLength / Unit::cm) * m_cdcgp->getPropSpeedInv(layer);
892 }
893 }
894
895 return driftT;
896}
897
898
899void CDCDigitizerModule::makeSignalsAfterShapers(const WireID& wid, double dEinGeV, double dx, double costh,
900 unsigned short& adcCount, double& convFactorForThreshold)
901{
902 static double conv00 = (100.0 / 3.2); //keV -> coun (original from some test beam results)
903 convFactorForThreshold = conv00;
904 adcCount = 0;
905 if (dEinGeV <= 0. || dx <= 0.) return;
906
907 const unsigned short layer = wid.getICLayer();
908 const unsigned short cell = wid.getIWire();
909 double dEInkeV = dEinGeV / Unit::keV;
910
911 double conv = conv00;
913 if (m_useDB4EDepToADC) {
914 conv = m_cdcgp->getEDepToADCConvFactor(layer, cell, dEInkeV, dx, costh);
915 double conv0 = m_cdcgp->getEDepToADCMainFactor(layer, cell, costh);
916 convFactorForThreshold = (conv0 + m_degOfSPEOnThreshold * (conv - conv0));
917 }
918 } else {
919 if (m_useDB4EDepToADC) conv = m_cdcgp->getEDepToADCMainFactor(layer, cell, costh);
920 convFactorForThreshold = conv;
921 }
922
923 if (convFactorForThreshold > 0.) {
924 convFactorForThreshold *= getSemiTotalGain(layer, cell);
925 } else {
926 convFactorForThreshold = conv00;
927 }
928
929 if (m_gasGainSmearing) {
930 const int nElectrons = std::round(dEInkeV / m_effWForGasGainSmearing);
931 double relGain = 0;
932 if (20 <= nElectrons) {
933 relGain = std::max(0., gRandom->Gaus(1., sqrt(1. / (nElectrons * (1. + m_thetaOfPolya)))));
934 } else if (1 <= nElectrons) {
935 for (int i = 1; i <= nElectrons; ++i) {
936 relGain += Polya();
937 }
938 relGain /= nElectrons;
939 } else {
940 relGain = 1;
941 }
942 conv *= relGain;
943 }
944
945 if (m_extraADCSmearing) {
946 conv *= max(0., gRandom->Gaus(1., m_cdcgp->getEDepToADCSigma(layer, cell)));
947 }
948
949 conv *= getSemiTotalGain(layer, cell);
950
951 //The ADCcount is obtained by rounding-up (measured voltage)/bin in real ADC. This is true both for pedestal and signal voltages, so the pedestal-subtracted ADCcount (simulated here) is rounded.
952 adcCount = static_cast<unsigned short>(std::round(conv * dEInkeV));
953 return;
954}
955
956
957double CDCDigitizerModule::Polya(double xmax)
958{
959 double x = 0;
960 double y = 1;
961 double fx = 0;
962 double urndm[2];
963 static double ymax = pow(m_thetaOfPolya, m_thetaOfPolya) * exp(-m_thetaOfPolya);
964 while (y > fx) {
965 gRandom->RndmArray(2, urndm);
966 x = xmax * urndm[0];
967 double a = (1 + m_thetaOfPolya) * x;
968 fx = pow(a, m_thetaOfPolya) * exp(-a);
969 y = ymax * urndm[1];
970 }
971 return x;
972}
973
974
975// Set FEE parameters (from DB)
977{
978 const double& off = m_tdcThresholdOffset;
979 const double& gA = m_analogGain;
980 const double& gD = m_digitalGain;
981 const double& adcBW = m_adcBinWidth;
982 const double convF = gA / gD / adcBW;
983 const double el1TrgLatency = m_cdcgp->getMeanT0(); // ns
984 B2DEBUG(m_debugLevel, "L1TRGLatency= " << el1TrgLatency);
985 const double c = 32. * m_tdcBinWidth;
986
987 if (!m_fEElectronicsFromDB) B2FATAL("No FEEElectronics dbobject!");
988 const CDCFEElectronics& fp = *((*m_fEElectronicsFromDB)[0]);
989 int mode = (fp.getBoardID() == -1) ? 1 : 0;
990 int iNBoards = static_cast<int>(c_nBoards);
991
992 //set typical values for all channels first if mode=1
993 if (mode == 1) {
994 for (int bdi = 1; bdi < iNBoards; ++bdi) {
995 m_uprEdgeOfTimeWindow[bdi] = el1TrgLatency - c * (fp.getTrgDelay() + 1);
996 if (m_uprEdgeOfTimeWindow[bdi] < 0.) B2FATAL("CDCDigitizer: Upper edge of time window < 0!");
997 m_lowEdgeOfTimeWindow[bdi] = m_uprEdgeOfTimeWindow[bdi] - c * (fp.getWidthOfTimeWindow() + 1);
998 if (m_lowEdgeOfTimeWindow[bdi] > 0.) B2FATAL("CDCDigitizer: Lower edge of time window > 0!");
999 m_adcThresh[bdi] = fp.getADCThresh();
1000 m_tdcThresh[bdi] = convF * (off - fp.getTDCThreshInMV());
1001 m_widthOfTimeWindowInCount[bdi] = fp.getWidthOfTimeWindow() + 1;
1002 m_trgDelayInCount [bdi] = fp.getTrgDelay();
1003 }
1004 }
1005
1006 //overwrite values for specific channels if mode=1
1007 //set typical values for all channels if mode=0
1008 for (const auto& fpp : (*m_fEElectronicsFromDB)) {
1009 int bdi = fpp.getBoardID();
1010 if (mode == 0 && bdi == 0) continue; //bdi=0 is dummy (not used)
1011 if (mode == 1 && bdi == -1) continue; //skip typical case
1012 if (bdi < 0 || bdi >= iNBoards) B2FATAL("CDCDigitizer:: Invalid no. of FEE board!");
1013 m_uprEdgeOfTimeWindow[bdi] = el1TrgLatency - c * (fpp.getTrgDelay() + 1);
1014 if (m_uprEdgeOfTimeWindow[bdi] < 0.) B2FATAL("CDCDigitizer: Upper edge of time window < 0!");
1015 m_lowEdgeOfTimeWindow[bdi] = m_uprEdgeOfTimeWindow[bdi] - c * (fpp.getWidthOfTimeWindow() + 1);
1016 if (m_lowEdgeOfTimeWindow[bdi] > 0.) B2FATAL("CDCDigitizer: Lower edge of time window > 0!");
1017 m_adcThresh[bdi] = fpp.getADCThresh();
1018 m_tdcThresh[bdi] = convF * (off - fpp.getTDCThreshInMV());
1019 m_widthOfTimeWindowInCount[bdi] = fpp.getWidthOfTimeWindow() + 1;
1020 m_trgDelayInCount [bdi] = fpp.getTrgDelay();
1021 }
1022
1023 //debug
1024 B2DEBUG(m_debugLevel, "mode= " << mode);
1025 for (int bdi = 1; bdi < iNBoards; ++bdi) {
1026 B2DEBUG(m_debugLevel, bdi << " " << m_lowEdgeOfTimeWindow[bdi] << " " << m_uprEdgeOfTimeWindow[bdi] << " " << m_adcThresh[bdi] <<
1027 " " <<
1028 m_tdcThresh[bdi]);
1029 }
1030}
1031
1032// Set Run-gain (from DB)
1034{
1035 B2DEBUG(m_debugLevel, " ");
1036
1037 //read individual wire gains
1038 const int nLyrs = c_maxNSenseLayers;
1039 B2DEBUG(m_debugLevel, "nLyrs= " << nLyrs);
1040 int nGoodL[nLyrs] = {};
1041 float wgL[nLyrs] = {};
1042 int nGoodSL[c_nSuperLayers] = {};
1043 float wgSL[c_nSuperLayers] = {};
1044 int nGoodAll = 0;
1045 float wgAll = 0;
1046 int iw = -1;
1047 for (int lyr = 0; lyr < nLyrs; ++lyr) {
1048 int nWs = m_cdcgp->nWiresInLayer(lyr);
1049 for (int w = 0; w < nWs; ++w) {
1050 ++iw;
1051 float wg = (*m_wireGainFromDB)->getWireGain(iw);
1052 m_semiTotalGain[lyr][w] = wg;
1053 if (wg > 0) {
1054 ++nGoodL[lyr];
1055 wgL[lyr] += wg;
1056 WireID wid(lyr, w);
1057 ++nGoodSL[wid.getISuperLayer()];
1058 wgSL[wid.getISuperLayer()] += wg;
1059 ++nGoodAll;
1060 wgAll += wg;
1061 }
1062 }
1063 }
1064
1065 //calculate mean gain per layer
1066 for (int lyr = 0; lyr < nLyrs; ++lyr) {
1067 if (nGoodL[lyr] > 0) wgL[lyr] /= nGoodL[lyr];
1068 B2DEBUG(m_debugLevel, "lyr,ngood,gain= " << lyr << " " << nGoodL[lyr] << " " << wgL[lyr]);
1069 }
1070 //calculate mean gain per superlayer
1071 for (unsigned int sl = 0; sl < c_nSuperLayers; ++sl) {
1072 if (nGoodSL[sl] > 0) wgSL[sl] /= nGoodSL[sl];
1073 B2DEBUG(m_debugLevel, "slyr,ngood,gain= " << sl << " " << nGoodSL[sl] << " " << wgSL[sl]);
1074 }
1075
1076
1077 //calculate mean gain over all wires
1078 if (nGoodAll > 0) {
1079 wgAll /= nGoodAll;
1080 } else {
1081 B2FATAL("No good wires !");
1082 }
1083 B2DEBUG(m_debugLevel, "ngoodAll,gain= " << nGoodAll << " " << wgAll);
1084
1085 //set gain also for bad/dead wires (bad/dead in terms of dE/dx pid)
1086 for (int lyr = 0; lyr < nLyrs; ++lyr) {
1087 int nWs = m_cdcgp->nWiresInLayer(lyr);
1088 for (int w = 0; w < nWs; ++w) {
1089 if (m_semiTotalGain[lyr][w] <= 0) {
1090 if (wgL[lyr] > 0) {
1091 m_semiTotalGain[lyr][w] = wgL[lyr];
1092 } else {
1093 WireID wid(lyr, w);
1094 m_semiTotalGain[lyr][w] = wgSL[wid.getISuperLayer()];
1095 }
1096 }
1097 }
1098 }
1099
1100 //check if all gains > 0
1101 for (int lyr = 0; lyr < nLyrs; ++lyr) {
1102 int nWs = m_cdcgp->nWiresInLayer(lyr);
1103 for (int w = 0; w < nWs; ++w) {
1104 if (m_semiTotalGain[lyr][w] <= 0) {
1105 B2WARNING("Gain for lyr and wire " << lyr << " " << w << "not > 0. Strange! Replace it with " << wgAll << ".");
1106 m_semiTotalGain[lyr][w] = wgAll;
1107 }
1108 }
1109 }
1110
1111//multiply common factor for all wires
1112 m_runGain = (*m_runGainFromDB)->getRunGain();
1113 double cgain = (*m_gain0FromDB)->getScaleFactor();
1114 B2DEBUG(m_debugLevel, "runGain, sf= " << m_runGain << " " << cgain);
1115 cgain *= m_runGain * m_overallGainFactor;
1116 for (int lyr = 0; lyr < nLyrs; ++lyr) {
1117 int nWs = m_cdcgp->nWiresInLayer(lyr);
1118 for (int w = 0; w < nWs; ++w) {
1119 m_semiTotalGain[lyr][w] *= cgain;
1120 B2DEBUG(m_debugLevel, "lyr,wire,gain= " << lyr << " " << w << " " << m_semiTotalGain[lyr][w]);
1121 }
1122 }
1123}
1124
1125
1127{
1128 map<WireID, XTalkInfo> xTalkMap;
1129 map<WireID, XTalkInfo> xTalkMap1;
1130 map<WireID, XTalkInfo>::iterator iterXTalkMap1;
1131
1132 // Loop over all cdc hits to create a xtalk map
1133 int OriginalNoOfHits = m_cdcHits.getEntries();
1134 B2DEBUG(m_debugLevel4XTalk, "\n \n" << "#CDCHits " << OriginalNoOfHits);
1135 for (const auto& aHit : m_cdcHits) {
1136 if (m_issue2ndHitWarning && aHit.is2ndHit()) {
1137 B2WARNING("2nd TDC hit found, but not ready for it!");
1138 }
1139 WireID wid(aHit.getID());
1140 short tdcCount = aHit.getTDCCount();
1141 short adcCount = aHit.getADCCount();
1142 short tot = aHit.getTOT();
1143 short board = m_cdcgp->getBoardID(wid);
1144 short channel = m_cdcgp->getChannelID(wid);
1145 const vector<pair<short, asicChannel>> xTalks = (*m_xTalkFromDB)->getLibraryCrossTalk(channel, tdcCount, adcCount, tot);
1146
1147 int nXTalks = xTalks.size();
1148 for (int i = 0; i < nXTalks; ++i) {
1149 const unsigned short tdcCount4XTalk = xTalks[i].second.TDC;
1150 if (i == 0) {
1151 B2DEBUG(m_debugLevel4XTalk, "\n" << " signal: " << channel << " " << tdcCount << " " << adcCount << " " << tot);
1152 }
1153 B2DEBUG(m_debugLevel4XTalk, "xtalk: " << xTalks[i].first << " " << tdcCount4XTalk << " " << xTalks[i].second.ADC << " " <<
1154 xTalks[i].second.TOT);
1155 WireID widx = m_cdcgp->getWireID(board, xTalks[i].first);
1156 if (!m_cdcgp->isBadWire(widx)) { // for non-bad wire
1157 if (m_includeEarlyXTalks || (xTalks[i].second.TDC <= tdcCount)) {
1158 const double t0 = getPositiveT0(widx);
1159 const double ULOfTDC = (t0 - m_lowEdgeOfTimeWindow[board]) * m_tdcBinWidthInv;
1160 const double LLOfTDC = (t0 - m_uprEdgeOfTimeWindow[board]) * m_tdcBinWidthInv;
1161 if (LLOfTDC <= tdcCount4XTalk && tdcCount4XTalk <= ULOfTDC) {
1162 const unsigned short status = 0;
1163 xTalkMap.insert(make_pair(widx, XTalkInfo(tdcCount4XTalk, xTalks[i].second.ADC, xTalks[i].second.TOT, status)));
1164 }
1165 }
1166 }
1167 } //end of xtalk loop
1168 } //end of cdc hit loop
1169
1170 //Loop over all xtalk hits to creat a new xtalk map with only the fastest hits kept (approx.)
1171 B2DEBUG(m_debugLevel4XTalk, "#xtalk hits: " << xTalkMap.size());
1172 for (const auto& aHit : xTalkMap) {
1173 WireID wid = aHit.first;
1174
1175 iterXTalkMap1 = xTalkMap1.find(wid);
1176 unsigned short tdcCount = aHit.second.m_tdc;
1177 unsigned short adcCount = aHit.second.m_adc;
1178 unsigned short tot = aHit.second.m_tot;
1179 unsigned short status = aHit.second.m_status;
1180
1181 if (iterXTalkMap1 == xTalkMap1.end()) { // new entry
1182 xTalkMap1.insert(make_pair(wid, XTalkInfo(tdcCount, adcCount, tot, status)));
1183 } else { // not new; check if fastest
1184 if (tdcCount < iterXTalkMap1->second.m_tdc) {
1185 iterXTalkMap1->second.m_tdc = tdcCount;
1186 B2DEBUG(m_debugLevel4XTalk, "TDC-count of current xtalk: " << tdcCount);
1187 }
1188 iterXTalkMap1->second.m_adc += adcCount;
1189 iterXTalkMap1->second.m_tot += tot; // approx.
1190 }
1191 } // end of xtalk loop
1192
1193 //add xtalk in the same way as the beam bg. overlay
1194 B2DEBUG(m_debugLevel4XTalk, "#xtalk1 hits: " << xTalkMap1.size());
1195 for (const auto& aX : xTalkMap1) {
1196 bool append = true;
1197 const unsigned short tdc4Bg = aX.second.m_tdc;
1198 const unsigned short adc4Bg = aX.second.m_adc;
1199 const unsigned short tot4Bg = aX.second.m_tot;
1200 const unsigned short status4Bg = aX.second.m_status;
1201
1202 for (int iHit = 0; iHit < OriginalNoOfHits; ++iHit) {
1203 CDCHit& aH = *(m_cdcHits[iHit]);
1204 if (aH.getID() != aX.first.getEWire()) { //wire id unmatched
1205 continue;
1206 } else { //wire id matched
1207 append = false;
1208 const unsigned short tdc4Sg = aH.getTDCCount();
1209 const unsigned short adc4Sg = aH.getADCCount();
1210 const unsigned short tot4Sg = aH.getTOT();
1211
1212 // If the BG hit is faster than the true hit, the TDC count is replaced, and
1213 // the relations are removed. ADC counts are summed up.
1214 if (tdc4Sg < tdc4Bg) {
1215 aH.setTDCCount(tdc4Bg);
1216 aH.setStatus(status4Bg);
1217 auto relSimHits = aH.getRelationsFrom<CDCSimHit>();
1218 for (int i = relSimHits.size() - 1; i >= 0; --i) {
1219 relSimHits.remove(i);
1220 }
1221 auto relMCParticles = aH.getRelationsFrom<MCParticle>();
1222 for (int i = relMCParticles.size() - 1; i >= 0; --i) {
1223 relMCParticles.remove(i);
1224 }
1225 }
1226
1227 aH.setADCCount(adc4Sg + adc4Bg);
1228
1229 //Set TOT for signal+background case. It is assumed that the start timing
1230 //of a pulse (input to ADC) is given by the TDC-count. This is an
1231 //approximation because analog (for ADC) and digital (for TDC) parts are
1232 //different in the front-end electronics.
1233 unsigned short s1 = tdc4Sg; //start time of 1st pulse
1234 unsigned short s2 = tdc4Bg; //start time of 2nd pulse
1235 unsigned short w1 = tot4Sg; //its width
1236 unsigned short w2 = tot4Bg; //its width
1237 if (tdc4Sg < tdc4Bg) {
1238 s1 = tdc4Bg;
1239 w1 = tot4Bg;
1240 s2 = tdc4Sg;
1241 w2 = tot4Sg;
1242 }
1243 w1 *= 32;
1244 w2 *= 32;
1245 const unsigned short e1 = s1 - w1; //end time of 1st pulse
1246 const unsigned short e2 = s2 - w2; //end time of 2nd pulse
1247
1248 double pulseW = w1 + w2;
1249 if (e1 <= e2) {
1250 pulseW = w1;
1251 } else if (e1 <= s2) {
1252 pulseW = s1 - e2;
1253 }
1254
1255 unsigned short board = m_cdcgp->getBoardID(aX.first);
1256 aH.setTOT(std::min(std::round(pulseW / 32.), static_cast<double>(m_widthOfTimeWindowInCount[board])));
1257 B2DEBUG(m_debugLevel4XTalk, "replaced tdc,adc,tot,wid,status= " << aH.getTDCCount() << " " << aH.getADCCount() << " " << aH.getTOT()
1258 <<
1259 " " << aH.getID() << " " << aH.getStatus());
1260 break;
1261 }
1262 } //end of cdc hit loop
1263
1264 if (append) {
1265 m_cdcHits.appendNew(tdc4Bg, adc4Bg, aX.first, status4Bg, tot4Bg);
1266 B2DEBUG(m_debugLevel4XTalk, "appended tdc,adc,tot,wid,status= " << tdc4Bg << " " << adc4Bg << " " << tot4Bg << " " << aX.first <<
1267 " " <<
1268 status4Bg);
1269 }
1270 } //end of x-talk loop
1271 B2DEBUG(m_debugLevel4XTalk, "original #hits, #hits= " << OriginalNoOfHits << " " << m_cdcHits.getEntries());
1272}
1273
1274
1276{
1277 double t0 = m_cdcgp->getT0(wid);
1278 if (t0 <= 0 && m_treatNegT0WiresAsGood) t0 = m_cdcgp->getMeanT0();
1279 return t0;
1280}
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition B2Vector3.h:435
DataType X() const
access variable X (= .at(0) without boundary check)
Definition B2Vector3.h:431
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition B2Vector3.h:433
DataType Mag() const
The magnitude (rho in spherical coordinate system).
Definition B2Vector3.h:159
void SetY(DataType y)
set Y/2nd-coordinate
Definition B2Vector3.h:459
bool m_alphaCorrection
Switch for alpha correction.
double m_tdcThreshold4Inner
TDC threshold for inner layers in unit of eV.
double m_driftV
Nominal drift velocity (in cm/ns)
double Polya(double xmax=10)
Generate random number according to Polya distribution.
unsigned short m_boardID
FEE board ID.
int m_eDepInGasMode
Mode for extracting dE(gas) from dE(gas+wire)
double m_tMaxInner
Upper edge of time window in ns for the inner layers.
double getdDdt(double driftLength)
The method to get dD/dt.
bool m_outputNegativeDriftTime
A switch to output negative drift time to CDCHit.
unsigned short m_widthOfTimeWindowInCount[c_nBoards]
Width of time window.
bool m_extraADCSmearing
Switch for extra ADC smearing.
bool m_includeEarlyXTalks
Flag to switch on/off xtalks earlier than the hit.
void makeSignalsAfterShapers(const WireID &wid, double edep, double dx, double costh, unsigned short &adcCount, double &convFactorForThreshold)
Function to write ADC-count and conversion factor for threshold.
int m_trgTimingOffsetInCount
Trigger timing offset in unit of count.
bool m_addInWirePropagationDelay4Bg
A switch used to control adding propagation delay into the total drift time or not for beam bg.
double getSemiTotalGain(int clayer, int cell) const
Return semi-total gain of the specified wire.
bool m_useDB4RunGain
Fetch run gain from DB.
DBObjPtr< CDCCrossTalkLibrary > * m_xTalkFromDB
Pointer to cross-talk from DB.
double m_analogGain
analog gain (V/pC)
double m_tdcBinWidthInv
m_tdcBinWidth^-1 (in ns^-1)
float m_uprEdgeOfTimeWindow[c_nBoards]
Upper edge of time-window.
double m_tMin
Lower edge of time window in ns.
bool m_output2ndHit
A switch to output 2nd hit.
int m_adcThreshold
Threshold for ADC in unit of count.
double m_resolution2
Resolution of the second Gaussian used to smear drift length.
bool m_addTimeOfFlight
A switch used to control adding time of flight into the total drift time or not.
double m_trigTimeJitter
Magnitude of trigger timing jitter (ns).
void initialize() override
Initialize variables, print info, and start CPU clock.
double smearDriftLength(double driftLength, double dDdt)
Method used to smear the drift length.
std::string m_MCParticlesToSimHitsName
Relation for origin of incoming SimHits.
double m_digitalGain
digital gain (V/pC)
double m_totalFudgeFactor
total fudge factor for space resol.
std::string m_OptionalAllMCParticlesToHitsName
Relation name for optional matching of all MCParticles.
bool m_addInWirePropagationDelay
A switch used to control adding propagation delay into the total drift time or not.
bool m_align
A switch to control alignment.
void event() override
Actual digitization of all hits in the CDC.
unsigned short m_trgDelayInCount[c_nBoards]
Trigger delay in frontend electronics in count.
double m_globalTime
global time of this hit
bool m_doSmearing
A switch to control drift length smearing.
std::string m_inputCDCSimHitsName
Input array name.
DBObjPtr< CDCDedxWireGain > * m_wireGainFromDB
Pointer to wire gain from DB.
B2Vector3D m_posWire
wire position of this hit
bool m_addTimeOfFlight4Bg
A switch used to control adding time of flight into the total drift time or not for beam bg.
bool m_addXTalk
Flag to switch on/off crosstalk.
bool m_addTimeWalk
A switch used to control adding time-walk delay into the total drift time or not.
bool m_treatNegT0WiresAsGood
A switch for negative-t0 wires.
double m_addFudgeFactorForSigma
additional fudge factor for space resol.
bool m_matchAllMCParticles
A switch to match all particles to a hit, regardless whether they produced a hit or not.
bool m_useDB4EDepToADC
Fetch edep-to-ADC conversion params.
std::string m_SimHitsTOCDCHitsName
Relation for outgoing CDCHits.
int m_offsetForTriggerBin
Input to getCDCTriggerBin(offset)
void setSemiTotalGain()
Set semi-total gain (from DB)
double m_driftLength
drift length of this hit
double m_tdcResol
TDC resolution (in ns)
int m_tSimMode
Timing simulation mode.
bool m_useDB4FEE
Fetch FEE params from DB.
double m_adcBinWidth
ADC bin width (mV)
double m_thetaOfPolya
theta of Polya function for gas gain smearing
bool m_matchFirstMCParticles
A switch to match first three MCParticles, not just the one with smallest drift time.
bool m_spaceChargeEffect
Space charge effect.
double m_driftVInv
m_driftV^-1 (in ns/cm)
StoreArray< CDCSimHit > m_simHits
CDCSimHit array.
DBObjPtr< CDCCorrToThresholds > * m_corrToThresholdFromDB
Pointer to threshold correction from DB.
std::string m_OptionalFirstMCParticlesToHitsName
Relation name for optional matching of up to first three MCParticles.
StoreArray< CDCHit > m_cdcHits4Trg
CDCHit4trg array.
float m_semiTotalGain[c_maxNSenseLayers][c_maxNDriftCells]
total gain per wire
DBObjPtr< CDCDedxRunGain > * m_runGainFromDB
Pointer to run gain from DB.
double m_degOfSPEOnThreshold
Degree of space charge effect on timing threshold.
bool m_randomization
Flag to switch on/off timing randomization.
CDCSimHit * m_aCDCSimHit
Pointer to CDCSimHit.
WireID m_wireID
WireID of this hit.
DBObjPtr< CDCDedxScaleFactor > * m_gain0FromDB
Pointer to overall gain factor from DB.
double m_effWForGasGainSmearing
Effective energy (keV) for one electron prod.
bool m_issue2ndHitWarning
Flag to switch on/off a warning on the 2nd TDC hit.
double getPositiveT0(const WireID &)
Modify t0 for negative-t0 case.
double m_tdcThreshold4Outer
TDC threshold for outer layers in unit of eV.
double m_tdcThresholdOffset
Offset for TDC(digital) threshold (mV)
double m_fraction
Fraction of the first Gaussian used to smear drift length.
int m_debugLevel4XTalk
Debug level for crosstalk.
int m_shiftOfTimeWindowIn32Count
Shift of time window for synchronization in 32count.
unsigned short m_posFlag
left or right flag of this hit
std::string m_outputCDCHitsName4Trg
Output array name for trigger.
StoreArray< CDCHit > m_cdcHits
CDCHit array.
double m_mean1
Mean value of the first Gaussian used to smear drift length.
bool m_synchronization
Flag to switch on/off timing synchronization.
float m_lowEdgeOfTimeWindow[c_nBoards]
Lower edge of time-window.
double getDriftTime(double driftLength, bool addTof, bool addDelay)
The method to get drift time based on drift length.
std::string m_outputCDCHitsName
Output array name.
float m_tdcThresh[c_nBoards]
Threshold for timing-signal.
B2Vector3D m_momentum
3-momentum of this hit
StoreArray< MCParticle > m_mcParticles
Set edep-to-ADC conversion params.
bool m_gasGainSmearing
Switch for gas gain smearing.
double m_tMaxOuter
Upper edge of time window in ns for the outer layers.
DBArray< CDCFEElectronics > * m_fEElectronicsFromDB
Pointer to FE electronics params.
double m_resolution1
Resolution of the first Gaussian used to smear drift length.
B2Vector3D m_posTrack
track position of this hit
bool m_useSimpleDigitization
Use float Gaussian Smearing instead of proper digitization.
CDC::CDCGeometryPar * m_cdcgp
Cached Pointer to CDCGeometryPar.
double m_overallGainFactor
Overall gain factor.
void setFEElectronics()
Set FEE parameters (from DB)
double m_mean2
Mean value of the second Gaussian used to smear drift length.
OptionalDBObjPtr< CDCAlphaScaleFactorForAsymmetry > m_alphaScaleFactorsFromDB
the ratio of data to MC, for eff(alpha<0)/eff(alpha>0).
double m_tdcBinWidth
Width of a TDC bin (in ns)
CDC::CDCGeoControlPar * m_gcp
Cached pointer to CDCGeoControlPar.
bool m_correctForWireSag
A switch to control wire sag.
StoreObjPtr< SimClockState > m_simClockState
generated hardware clock state
double m_flightTime
flight time of this hit
float m_adcThresh[c_nBoards]
Threshold for FADC.
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...
Definition CDCHit.h:40
void setTDCCount(short tdcCount)
Setter for TDC count.
Definition CDCHit.h:128
void set2ndHitFlag()
Setter for 2nd hit flag.
Definition CDCHit.h:113
short getTDCCount() const
Getter for TDC count.
Definition CDCHit.h:219
void setTOT(unsigned short tot)
Setter for TOT.
Definition CDCHit.h:160
unsigned short getID() const
Getter for encoded wire number.
Definition CDCHit.h:193
unsigned short getStatus() const
Getter for CDCHit status.
Definition CDCHit.h:199
void setADCCount(unsigned short adcCount)
Setter for ADC count.
Definition CDCHit.h:135
unsigned short getADCCount() const
Getter for integrated charge.
Definition CDCHit.h:230
unsigned short getTOT() const
Getter for TOT.
Definition CDCHit.h:248
void setOtherHitIndices(CDCHit *otherHit)
Setter for the other hit indices.
Definition CDCHit.h:147
void setStatus(unsigned short status)
Setter for CDCHit status.
Definition CDCHit.h:106
Example Detector.
Definition CDCSimHit.h:21
static CDCGeoControlPar & getInstance()
Static method to get a reference to the CDCGeoControlPar instance.
The Class for CDC Geometry Parameters.
double getNominalPropSpeed() const
Return the nominal propagation speed of the sense wire (default: 27.25 cm/nsec).
EWirePosition
Wire position set.
double getTdcBinWidth() const
Return TDC bin width (nsec).
double getNominalDriftV() const
Return the nominal drift velocity of He-ethane gas (default: 4.0x10^-3 cm/nsec).
static CDCGeometryPar & Instance(const CDCGeometry *=nullptr)
Static method to get a reference to the CDCGeometryPar instance.
The Class for Energy deposit in the gas.
Definition EDepInGas.h:20
static EDepInGas & getInstance()
Static method to get a reference to the EDepInGas instance.
Definition EDepInGas.cc:21
double getEDepInGas(int mode, int pdg, double p, double dx, double e3) const
Return the energy deosite in the gas.
Definition EDepInGas.cc:135
Class for accessing arrays of objects in the database.
Definition DBArray.h:26
Class for accessing objects in the database.
Definition DBObjPtr.h:21
@ c_WriteOut
Object/array should be saved by output modules.
Definition DataStore.h:70
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition DataStore.h:59
A Class to store the Monte Carlo particle information.
Definition MCParticle.h:32
int getIndex() const
Get 1-based index of the particle in the corresponding MCParticle list.
Definition MCParticle.h:219
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition Module.cc:208
Module()
Constructor.
Definition Module.cc:30
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition Module.h:80
Low-level class to create/modify relations between StoreArrays.
void add(index_type from, index_type to, weight_type weight=1.0)
Add a new element to the relation.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
float weight(int index) const
Get weight with index.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
RelationVector< FROM > getRelationsFrom(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from another store array to this object.
static const double keV
[kiloelectronvolt]
Definition Unit.h:113
static const double eV
[electronvolt]
Definition Unit.h:112
static const double cm
Standard units with the value = 1.
Definition Unit.h:47
Class to identify a wire inside the CDC.
Definition WireID.h:34
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition WireID.cc:24
unsigned short getIWire() const
Getter for wire within the layer.
Definition WireID.h:145
unsigned short getISuperLayer() const
Getter for Super-Layer.
Definition WireID.h:130
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition B2Vector3.h:516
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28
double ClosestApproach(const B2Vector3D &bwp, const B2Vector3D &fwp, const B2Vector3D &posIn, const B2Vector3D &posOut, B2Vector3D &hitPosition, B2Vector3D &wirePosition)
Returns a closest distance between a track and a wire.
Abstract base class for different kinds of events.
STL namespace.
Structure for saving the signal information.
Structure for saving the x-talk information.