5 #include <sevt/SEvent.h>
6 #include <sevt/Station.h>
7 #include <sevt/StationTriggerData.h>
8 #include <sevt/StationSimData.h>
9 #include <sdet/SDetector.h>
11 #include <mdet/MDetector.h>
12 #include <mdet/Counter.h>
13 #include <mdet/Module.h>
14 #include <mdet/Scintillator.h>
15 #include <mdet/Fiber.h>
17 #include <mdet/FrontEnd.h>
18 #include <mdet/Pixel.h>
19 #include <mdet/SiPMArray.h>
20 #include <mdet/FrontEndSiPM.h>
21 #include <mdet/SiPM.h>
22 #include <mdet/ChannelSiPM.h>
24 #include <mevt/MEvent.h>
25 #include <mevt/Counter.h>
26 #include <mevt/Module.h>
27 #include <mevt/Scintillator.h>
28 #include <mevt/ScintillatorSimData.h>
30 #include <utl/Particle.h>
31 #include <utl/PhysicalConstants.h>
32 #include <utl/Trace.h>
33 #include <utl/RandomEngine.h>
34 #include <utl/FFTDataContainer.h>
35 #include <utl/AugerUnits.h>
36 #include <utl/MathConstants.h>
37 #include <utl/ConsecutiveEnumFactory.h>
38 #include <utl/Branch.h>
39 #include <utl/ConfigUtils.h>
40 #include <utl/TimeStamp.h>
41 #include <utl/TimeInterval.h>
42 #include <utl/TabularStream.h>
43 #include <utl/Segment.h>
44 #include <utl/Plane.h>
45 #include <utl/Point.h>
46 #include <utl/GeometryUtilities.h>
48 #include <fwk/CentralConfig.h>
49 #include <fwk/RandomEngineRegistry.h>
51 #include <CLHEP/Random/RandFlat.h>
62 #include <boost/algorithm/minmax_element.hpp>
63 #include <boost/tokenizer.hpp>
87 template<
class Component>
88 Tag(
const std::string& prefix,
const Component&
c) {
91 fStream << prefix <<
'_'
93 << mod.
GetId() <<
'_';
94 if( prefix !=
"outcomeIntegrator" )
95 fStream << c.GetId() <<
'_';
99 Tag& operator()(
const S&
s) {
104 const std::stringstream& sstr()
const {
110 return GetModule(p.
GetPMT());
126 template<
class Component>
127 const mdet::Module& GetModule(
const Component& c)
const {
128 return c.GetModule();
131 std::stringstream fStream;
138 template<
class T1,
class T2>
140 static void Constraints(T1
a, T2
b) {
145 void(*p)(T1,T2) = Constraints;
153 template<
class StringContainer>
154 void PrintPlots(
const TCanvas& c,
const StringContainer& sc,
const Tag& t)
161 typedef typename StringContainer::value_type
S;
162 CanCopy<S, std::string>();
163 const std::string& n = t.sstr().str();
164 for (
typename StringContainer::const_iterator i = sc.begin(), e = sc.end(); i != e; ++i)
165 c.Print((n + *i).c_str());
204 struct OwnerVector :
public std::vector<T*> {
205 void operator()(
const T *
const t)
const {
209 typedef typename OwnerVector<T>::const_iterator It;
210 typedef const OwnerVector<T>& ConstRef;
214 std::for_each<It,ConstRef>(this->begin(), this->end(), *
this);
224 template<
class Container>
225 struct TotalPulseFunctor {
226 TotalPulseFunctor(
const Container& pulses,
double ux,
double uy) :
227 fPulses(pulses), fUnitX(ux), fUnitY(uy), fAbs(false) { }
228 double operator()(
double t)
const {
229 double totalSignal = 0;
231 for (
typename Container::const_iterator p = fPulses.begin(), e = fPulses.end(); p != e; ++
p)
232 totalSignal += p->TimeSpaceEvaluate(t);
234 totalSignal =
std::abs(totalSignal);
237 double operator()(
double *x,
double * )
const {
239 return (*
this)(x[0] * fUnitX) / fUnitY;
241 const Container& fPulses;
248 template<
class Functor>
249 struct ProxyFunctor {
250 ProxyFunctor(
const Functor& func,
double ux,
double uy) :
251 fFunctor(func), fUnitX(ux), fUnitY(uy) {}
252 double operator()(
double *x,
double * )
const {
253 return fFunctor(x[0] * fUnitX) / fUnitY;
255 const Functor& fFunctor;
261 struct PulseFunctor {
263 fPulse(&spe), fUnitX(ux), fUnitY(uy) {}
266 fPhotoEquivalent(&pe), fUnitX(ux), fUnitY(uy) {}
267 double operator()(
double *x,
double * )
const {
268 return fPulse->TimeSpaceEvaluate(x[0] * fUnitX) / fUnitY;
277 struct ThresholdFunctor {
278 ThresholdFunctor(
double t,
double uy) :
279 fThreshold(t), fUnitY(uy) {}
280 double operator()(
double * x = 0,
double *p = 0)
const {
289 return fThreshold / fUnitY;
296 struct TGraphFunctor {
297 TGraphFunctor(
const TGraph&
g) : fGraph(g) {}
298 double operator()(
double *x,
double * )
const {
299 return fGraph.Eval(x[0]);
301 const TGraph& fGraph;
305 struct DerivativeFunctor {
306 DerivativeFunctor(
const TF1& f,
double s = 1.0) : fF1(f), fScale(s) { }
307 double operator()(
double *x,
double * )
const {
308 return fScale * fF1.Derivative(x[0]);
316 struct TraceFunctor {
317 TraceFunctor(
const T& t,
double m,
double ux,
double uy) :
318 fTrace(t), fMinTime(m), fUnitX(ux), fUnitY(uy), fBinning(t.GetBinning()), fAbs(false) {}
319 double operator()(
double *x,
double * )
const {
320 return ((*
this)(x[0] * fUnitX)) / fUnitY;
322 double operator()(
double t)
const {
325 double timeOffset = t - fMinTime;
328 double maxOffset = fTrace.GetSize() * fBinning;
329 if (timeOffset > maxOffset)
332 typedef typename T::SizeType Size;
340 Size leftBin =
static_cast<Size
>(timeOffset / fBinning);
341 Size rightBin = leftBin + 1;
342 double leftOffset = fBinning * leftBin;
343 double rightOffset = fBinning * rightBin;
344 double leftValue = fTrace[ leftBin ];
345 double rightValue = fTrace[ rightBin ];
346 double res = leftValue + (rightValue-leftValue) * (timeOffset - leftOffset) / (rightOffset - leftOffset);
363 namespace MdOptoElectronicSimulatorAG {
366 MdOptoElectronicSimulator::kSimulationTypeTags[] = {
"FromMEvent",
"FromMEventSimulatedScint"};
369 MdOptoElectronicSimulator::kIntegratorSimulationTypeTags[] = {
"StepByStep",
"Simplified"};
371 MdOptoElectronicSimulator::MdOptoElectronicSimulator() :
398 LoadConfig(config,
"plotFileExtensions", exts,
".eps .root");
399 typedef boost::char_separator<std::string::value_type> Sep;
400 typedef boost::tokenizer<Sep> Tokenizer;
402 Tokenizer tokens(exts, sep);
407 std::vector<ParticleType> particleTypesDefault;
415 std::vector<ParticleType> particleTypes;
416 LoadConfig(config,
"allowedParticleTypes", particleTypes, particleTypesDefault);
420 fLog(
"No particle types indicated: allowing'em all", 1);
485 Option_t *axis=
"XYZ";
486 Float_t margin = 0.15;
489 fStyle->SetCanvasBorderMode(0);
490 fStyle->SetCanvasColor(0);
492 fStyle->SetTickLength( 0.01,
"XYZ" );
493 fStyle->SetLabelFont( font , axis);
494 fStyle->SetLabelSize( fsize, axis);
495 fStyle->SetLabelOffset( 0.005, axis);
496 fStyle->SetTitleFont( font , axis);
497 fStyle->SetTitleSize( fsize, axis);
498 fStyle->SetTitleOffset( 1.0, axis);
499 fStyle->SetTitleXOffset( 1.5 );
500 fStyle->SetTitleYOffset( 2.5 );
501 fStyle->SetTitleAlign( 22 );
502 fStyle->SetTitleBorderSize( 0 );
503 fStyle->SetTitleColor( 1, axis );
504 fStyle->SetTitleFillColor( 0 );
508 fStyle->SetTitleY( 1-margin/2 );
509 fStyle->SetTitleTextColor( kBlue );
517 fStyle->SetPadBottomMargin(margin);
518 fStyle->SetPadLeftMargin (margin);
519 fStyle->SetPadRightMargin (margin);
520 fStyle->SetPadTopMargin (margin);
521 fStyle->SetPadBorderMode( 0 );
522 fStyle->SetPadBorderSize( 0 );
524 fStyle->SetPadGridX(
false);
525 fStyle->SetPadGridY(
false);
526 fStyle->SetPadTickX(
true);
527 fStyle->SetPadTickY(
false);
529 fStyle->SetFrameBorderMode( 0 );
530 fStyle->SetFrameBorderSize( 0 );
531 fStyle->SetFrameFillColor( 0 );
532 fStyle->SetFrameFillStyle( 1 );
533 fStyle->SetFrameLineColor( 0 );
534 fStyle->SetFrameLineStyle( 0 );
535 fStyle->SetFrameLineWidth( 0 );
565 double deltaLatch = 0;
566 const utl::TimeStamp& mEventTime =
event.GetSEvent().GetHeader().GetTime();
567 fLog(
"The event time for SiPM/PMT simulation ", 2)(mEventTime);
568 const mdet::MDetector& detector = det::Detector::GetInstance().GetMDetector();
576 ic->SetT1(deltaLatch);
582 ic->SetRejected(
"SD associated un-triggered");
588 if (!ic->HasModule(mmDet->GetId()))
589 ic->MakeModule(mmDet->GetId());
601 if (
is->HasSimData()) {
607 photon != lastPhoton; ++photon) {
618 finalPixId = pixel.
GetId();
621 signalsMap[ finalPixId ].fPulses.push_back(spe);
629 signalsMap[ sipm.
GetId() ].fSiPMPulses.push_back(pe);
644 INFO(
"Event without MEvent: nothing to be done.");
673 fLog(
"Trace size", 2)(nBinsTrace);
676 fLog(
"No pulses and other sim data found for channel", 1)(channel.
GetId());
678 for (
unsigned int i = 0; i < nBinsTrace; ++i)
688 std::unique_ptr<utl::TabularStream> spanTable;
689 const unsigned int pulseSpanLogLevel = 3;
697 unsigned int nSPE = 0;
698 for (PulseContainer::const_iterator p = si.
fPulses.begin(), e = si.
fPulses.end(); p != e; ++
p) {
699 minTimePreFE = std::min(minTimePreFE, p->LowerLimit());
700 maxTimePreFE =
std::max(maxTimePreFE, p->UpperLimit());
710 const double pulseTimeSpan = maxTimePreFE - minTimePreFE;
717 fLog(
"SPE pulses and other signals span:", pulseSpanLogLevel);
718 fLog(spanTable->Str(), pulseSpanLogLevel);
723 fLog(
"Applying FFT...", 3);
731 fLog(
"Discretizing total pulses. Number of samples:", 3,
false);
734 double time = minTimePreFE + i * binning;
735 double value = totalPulsePreFrontEnd(time);
741 fLog(
"Applying transfer function in frequency spectrum.", 3);
744 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
745 TVectorD freqArray(nFreq);
746 TVectorD ampArray(nFreq);
747 TVectorD phaArray(nFreq);
748 TVectorD preFFT(nFreq);
749 TVectorD postFFT(nFreq);
750 fLog(
"Generating frequency response.", 3);
751 const unsigned int tabFFTLogLevel = 4;
752 std::unique_ptr<utl::TabularStream> tabFFT;
753 if (fLog.GetLevel() >= tabFFTLogLevel) {
765 fLog(tabFFT->Str(), tabFFTLogLevel);
768 double freq = fft.GetFrequencyOfBin(freqBin);
773 freqTrace[ freqBin ] *=
c;
778 ampArray(freqBin) = amp;
779 phaArray(freqBin) = pha;
780 preFFT(freqBin) = preAmp;
783 fLog(
"Obtaining the amplified pulses in time-space...", 3);
785 const TimeTrace& totalPulsePostFrontEndTrace = fft.GetConstTimeSeries();
809 const double minTimePostFE = minTimePreFE + shift;
810 const double maxTimePostFE = maxTimePreFE + shift;
813 TraceFunctor<TimeTrace> totalPulsePostFrontEnd(totalPulsePostFrontEndTrace,
818 fLog(
"Creating discriminator object.", 3);
820 totalPulsePostFrontEnd,
825 const unsigned int rootLogLevel = 4;
826 if (fLog.GetLevel() >= rootLogLevel) {
831 fLog(
"Incoming pulse never at threshold level.", rootLogLevel);
832 fLog(
"Incoming pulse at threshold level at ", rootLogLevel,
false);
833 for (ItRoot i = b; i != e; ++i) {
836 fLog(
".", rootLogLevel);
839 fLog(
"Creating sampler object.", 3);
847 std::vector<double> sampleTimes;
848 fLog(
"Sampling pulses.", 3);
859 if (startTime < minTimePostFE) {
861 fLog(
"Samples false in the range", 4)
865 (
"as no signal in it.");
871 for (
double sampleTime = startTime; trace.
GetSize() < nBinsTrace ||
fLog(
'\n', 4);
872 sampleTime += sRate, bin++) {
875 if (sampleTime < minTimePostFE || maxTimePostFE < sampleTime) {
881 double o = discriminator(sampleTime);
887 sampleTimes.push_back(sampleTime);
889 if (maxTimePostFE < stopTime) {
891 fLog(
"Samples false in the range ", 4)
895 (
"as no signal in it.");
917 fLog(
"Generating plots.", 3);
919 std::stringstream canvasName;
924 TCanvas canvas(canvasName.str().c_str() ,
"Total SPE pulses", 200, 10, 700, 500);
927 canvas.SetBorderMode(0);
928 canvas.SetFillColor(0);
929 canvas.SetFrameBorderMode(0);
934 std::stringstream totalPulseNamePre;
935 totalPulseNamePre <<
"totalPulsePre_"
939 TF1 totalPulseFunPre(totalPulseNamePre.str().c_str(),
940 & totalPulsePreFrontEnd,
944 totalPulseFunPre.SetLineColor(kRed);
945 totalPulseFunPre.SetLineWidth(2);
946 totalPulseFunPre.SetLineStyle(1);
948 totalPulseFunPre.SetFillColor(canvas.GetFillColor());
949 totalPulseFunPre.Draw(
"X+");
952 unsigned int nPulse = 0;
954 OwnerVector<PulseFunctor> pFunctors;
955 OwnerVector<TF1> pFunctions;
956 pFunctors.reserve(si.
fPulses.size());
957 pFunctions.reserve(si.
fPulses.size());
958 for (PulseContainer::const_iterator p = si.
fPulses.begin(), pe = si.
fPulses.end(); p != pe; ++
p) {
960 std::stringstream pulseName;
961 pulseName <<
"pulse_" << nPulse++ <<
"_"
965 TF1* pulseFun =
new TF1(pulseName.str().c_str(),
969 pulseFun->SetLineColor(kBlack);
970 pulseFun->SetLineWidth(1);
971 pulseFun->SetLineStyle(2);
973 pulseFun->Draw(
"same");
974 pFunctors.push_back(pulse);
975 pFunctions.push_back(pulseFun);
978 s <<
"spe " << nPulse <<
" " << channel.GetIdMessage();
979 Dump(*pulseFun, s.str());
982 totalPulseFunPre.SetTitle(
"SPEs");
983 totalPulseFunPre.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
988 s <<
"total_pre " << channel.GetIdMessage();
989 Dump(totalPulseFunPre, s.str());
994 fLog(
"Generating after-front-end total pulse.", 3);
997 const float rightMargin = 0.2;
999 TPad pad1(
"pad1",
"", 0, 0, 1, 1);
1000 pad1.SetFrameBorderMode(0);
1001 pad1.SetFillColor(0);
1002 pad1.SetRightMargin(rightMargin);
1014 fLog(
"Total pulse.", 3);
1015 std::stringstream totalPulseNamePost;
1016 totalPulseNamePost <<
"totalPulsePost_"
1020 TF1 totalPulseFunPost(totalPulseNamePost.str().c_str(),
1021 & totalPulsePostFrontEnd,
1025 totalPulseFunPost.SetLineColor(kBlack);
1026 totalPulseFunPost.SetLineWidth(2);
1027 totalPulseFunPost.SetLineStyle(1);
1028 totalPulseFunPost.SetFillColor(canvas.GetFillColor());
1030 totalPulseFunPost.GetYaxis()->SetTitleOffset(1.2);
1031 totalPulseFunPost.Draw();
1034 fLog(
"Discrimination level [", 3)
1037 TF1 thresFun(
"Discrimination level",
1042 thresFun.SetLineColor(kBlack);
1043 thresFun.SetLineStyle(2);
1044 thresFun.SetLineWidth(1);
1046 thresFun.SetFillColor(canvas.GetFillColor());
1047 thresFun.Draw(
"same");
1050 fLog(
"Discriminator output.", 3);
1052 TPad pad2(
"pad2",
"", 0, 0, 1, 1);
1053 pad2.SetRightMargin(rightMargin);
1054 pad2.SetFillStyle(0);
1055 pad2.SetFillColor(0);
1056 pad2.SetFrameFillStyle(4000);
1057 pad2.SetFrameBorderMode(0);
1058 pad2.SetFrameFillColor(0);
1061 ProxyFunctor<mdet::Channel::Discriminator> discriminatorFunctor(
1063 TF1 discrimFun(
"Discriminator output",
1064 & discriminatorFunctor,
1068 discrimFun.SetLineColor(kBlue);
1070 discrimFun.SetLineStyle(2);
1071 discrimFun.SetLineWidth(1);
1072 discrimFun.SetFillColor(canvas.GetFillColor());
1074 discrimFun.GetYaxis()->SetNdivisions(4);
1076 discrimFun.GetYaxis()->SetTitleOffset(1.4);
1099 discrimFun.Draw(
"Y+");
1101 discrimFun.GetXaxis()->SetLabelSize(0);
1110 const double trueLevel = discrimFun.GetMaximum();
1112 TVectorD samplesArray(nBinsTrace);
1115 for (
unsigned int i = 0; i < nBinsTrace; ++i)
1116 samplesArray[i] = trace[i] ? trueLevel : 0;
1134 TVectorD sampleTimes_vec;
1135 sampleTimes_vec.Use(sampleTimes.size(),&(sampleTimes[0]));
1136 TGraph samples(sampleTimes_vec, samplesArray);
1137 samples.SetMarkerColor(kRed);
1138 samples.SetMarkerStyle(kFullCircle);
1139 samples.SetMarkerSize(1);
1140 samples.SetFillStyle(0);
1141 samples.SetFillColor(canvas.GetFillColor());
1142 samples.SetLineColor(canvas.GetFillColor());
1145 totalPulseFunPost.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1146 totalPulseFunPost.GetYaxis()->SetTitle(
1148 discrimFun.GetYaxis()->SetTitle(
1155 leg.SetNColumns( 3 );
1156 leg.SetEntrySeparation( 0.8 );
1159 leg.SetX1NDC( 0.1 );
1160 leg.SetX2NDC( 0.9 );
1161 leg.SetY1NDC( 1 -
fStyle->GetPadTopMargin() );
1163 leg.SetBorderSize( 0 );
1164 leg.SetTextFont(
fStyle->GetTitleFont() );
1165 leg.SetTextSize(
fStyle->GetTitleSize()+0.01 );
1167 leg.AddEntry(&totalPulseFunPost,
"PMT",
"L");
1168 leg.AddEntry(&discrimFun,
"Discrim.",
"L");
1169 leg.AddEntry(&samples,
"Binary",
"P");
1170 leg.SetFillColor(canvas.GetFillColor());
1174 std::stringstream
s;
1175 s <<
"total_post " << channel.GetIdMessage();
1176 Dump(totalPulseFunPost, s.str());
1182 totalPulsePreFrontEnd.fAbs =
true;
1183 totalPulsePostFrontEnd.fAbs =
true;
1187 const double minTimeMin = std::min(minTimePreFE, minTimePostFE) /
fUnits.
GetTimeUnit();
1189 fLog(
"Generating input/output comparison plot.", 3);
1191 TPad pad3(
"pad3",
"", 0, 0, 1, 1);
1192 pad3.SetFillColor(0);
1200 totalPulseFunPre.SetTitle(
"I/O");
1201 totalPulseFunPre.SetRange(minTimeMin, maxTimeMax);
1202 totalPulseFunPre.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1203 totalPulseFunPre.GetYaxis()->SetTitle(
1205 totalPulseFunPre.Draw();
1206 TPad pad4(
"pad4",
"", 0, 0, 1, 1);
1207 pad4.SetFillStyle(0);
1208 pad4.SetFillColor(0);
1209 pad4.SetFrameFillStyle(4000);
1210 pad4.SetFrameBorderMode(0);
1211 pad4.SetFrameFillColor(0);
1214 totalPulseFunPost.SetRange(minTimeMin, maxTimeMax);
1215 totalPulseFunPost.GetYaxis()->SetTitle(
1217 totalPulseFunPost.Draw(
"Y+");
1223 fLog(
"Generating frequency response plots.", 3);
1227 TGraph ampFreqResponse(freqArray, ampArray);
1228 ampFreqResponse.SetMarkerStyle(21);
1229 ampFreqResponse.Draw(
"AP");
1230 ampFreqResponse.SetTitle(
"Front-end transfer function amplitude response");
1232 ampFreqResponse.GetYaxis()->SetTitle(
1241 canvas.SetLogy(kFALSE);
1242 TGraph phaFreqResponse(freqArray, phaArray);
1243 phaFreqResponse.SetMarkerStyle(21);
1244 phaFreqResponse.Draw(
"AP");
1245 phaFreqResponse.SetTitle(
"Front-end transfer function phase response");
1247 phaFreqResponse.GetYaxis()->SetTitle((
"Phase (" +
fUnits.
GetAngleName() +
")").c_str());
1253 if (phaFreqResponse.GetN() > 1) {
1255 TGraphFunctor phaFreRespFunctor(phaFreqResponse);
1256 const double bFreq = phaFreqResponse.GetX()[0];
1257 const double eFreq = phaFreqResponse.GetX()[phaFreqResponse.GetN() - 1];
1258 TF1 phaFreqRespTF1(
"Phase", &phaFreRespFunctor, bFreq, eFreq, 1,
"");
1260 phaFreqRespTF1.SetLineStyle(2);
1262 double factor = -1.0;
1277 DerivativeFunctor derivative(phaFreqRespTF1, factor);
1278 TF1 delayRespTF1(
"Delay", &derivative, bFreq, eFreq, 1,
"");
1280 delayRespTF1.SetLineStyle(1);
1281 TPad pad5(
"pad5",
"", 0, 0, 1, 1);
1282 pad5.SetFillColor(0);
1283 pad5.SetFrameBorderMode(0);
1286 pad5.SetLogx(kTRUE);
1287 pad5.SetLogy(kFALSE);
1290 phaFreqRespTF1.Draw();
1291 TPad pad6(
"pad6",
"", 0, 0, 1, 1);
1292 pad6.SetFillStyle(0);
1293 pad6.SetFillColor(0);
1294 pad6.SetFrameFillStyle(4000);
1295 pad6.SetFrameBorderMode(0);
1296 pad6.SetFrameFillColor(0);
1297 pad6.SetLogx(kTRUE);
1298 pad6.SetLogy(kFALSE);
1301 delayRespTF1.Draw(
"Y+");
1302 phaFreqRespTF1.SetTitle(
"Phase and group delay");
1304 phaFreqRespTF1.GetYaxis()->SetTitle((
"Phase (" +
fUnits.
GetAngleName() +
")").c_str());
1305 delayRespTF1.GetYaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1306 TLegend leg(0.65, 0.70, 0.85, 0.9);
1307 leg.AddEntry(&phaFreqRespTF1,
"Phase response");
1308 leg.AddEntry(&delayRespTF1,
"Group delay");
1319 TGraph fftPlotPre(freqArray, preFFT);
1320 fftPlotPre.SetMarkerStyle(21);
1321 fftPlotPre.SetMarkerColor(kBlue);
1322 fftPlotPre.Draw(
"AP");
1323 fftPlotPre.SetTitle(
"Fourier amplitude spectrum prior front-end");
1334 TGraph fftPlotPost(freqArray, postFFT);
1335 fftPlotPost.SetMarkerStyle(21);
1336 fftPlotPost.SetMarkerColor(kRed);
1337 fftPlotPost.Draw(
"AP");
1338 fftPlotPost.SetTitle(
"Fourier amplitude spectrum after front-end.");
1371 double& minTimePreFE,
1372 double& maxTimePreFE
1380 traceAnalogical.
Clear();
1385 fLog(
"Trace size", 2)(nBinsTrace);
1389 fLog(
"No pulses and other sim data found for channel", 1)(channel.
GetId());
1390 for (
unsigned int i = 0; i < nBinsTrace; ++i)
1399 const double pulseTimeSpan = maxTimePreFE-minTimePreFE;
1405 TimeTrace totalPulsePostDiscriminatorTrace;
1408 totalPulsePostFrontEndTrace, totalPulsePostDiscriminatorTrace, traceAnalogical);
1413 SampleTrace(minTimePreFE, maxTimePreFE, pulseTimeSpan /
fNDiscretization, frontEnd, traceStart, totalPulsePostDiscriminatorTrace, trace);
1417 totalPulsePostFrontEndTrace, totalPulsePostDiscriminatorTrace, trace);
1437 std::unique_ptr<utl::TabularStream> spanTable;
1438 const unsigned int pulseSpanLogLevel = 3;
1446 unsigned int nPE = 0;
1448 minTimePreFE = std::min(minTimePreFE, p->LowerLimit());
1449 maxTimePreFE =
std::max(maxTimePreFE, p->UpperLimit());
1460 const double pulseTimeSpan = maxTimePreFE - minTimePreFE;
1467 fLog(
"PE pulses and other signals span:", pulseSpanLogLevel);
1468 fLog(spanTable->Str(), pulseSpanLogLevel);
1470 return pulseTimeSpan;
1484 TotalPulseFunctor<SiPMPulseContainer> totalPulsePreFrontEnd(si.
fSiPMPulses,
1490 fLog(
"Applying FFT...", 3);
1502 fLog(
"Discretizing total pulses. Number of samples:", 3,
false);
1505 double time = minTimePreFE + i * binning;
1506 double value = totalPulsePreFrontEnd(time);
1516 fLog(
"Applying transfer function in frequency spectrum.", 3);
1519 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
1521 fLog(
"Generating frequency response.", 3);
1522 const unsigned int tabFFTLogLevel = 4;
1523 std::unique_ptr<utl::TabularStream> tabFFT;
1524 if (fLog.GetLevel() >= tabFFTLogLevel) {
1536 fLog(tabFFT->Str(), tabFFTLogLevel);
1541 freqTrace[ freqBin ] *=
c;
1544 fLog(
"Obtaining the amplified pulses in time-space...", 3);
1553 double discriminatorOuput = channel.
ComputeDiscriminator(totalPulsePostFrontEndTrace[timeBin], binning);
1554 totalPulsePostDiscriminatorTrace.
PushBack(discriminatorOuput);
1568 fLog(
"Creating sampler object.", 3);
1573 std::vector<double> sampleTimes;
1575 fLog(
"Sampling pulses.", 3);
1584 if (startTime < minTimePostFE) {
1585 fLog(
"Samples false in the range (startTime < minTimePostFE)", 4)
1589 (
"as no signal in it.");
1593 for (
double sampleTime = startTime; trace.
GetSize() < nBinsTrace ||
fLog(
'\n', 4);
1594 sampleTime += sRate) {
1597 if (sampleTime < minTimePostFE || maxTimePostFE < sampleTime) {
1600 int bin = (int)((sampleTime-minTimePostFE)/binning);
1601 double o = totalPulsePostDiscriminatorTrace[bin];
1607 sampleTimes.push_back(sampleTime);
1610 if (maxTimePostFE < stopTime) {
1612 fLog(
"Samples false in the range (maxTimePostFE < stopTime) ", 4)
1616 (
"as no signal in it.");
1635 unsigned short limit = std::min(width+bin, (
int)trace.
GetSize());
1637 for(
short i = bin; i<limit; i++){
1655 TVectorD analogicalTime(traceAnalogical.
GetSize());
1656 TVectorD traceAnalogicalVec(traceAnalogical.
GetSize());
1657 TVectorD totalPulsePostFrontEndVec(traceAnalogical.
GetSize());
1658 TVectorD totalPulsePostDiscriminatorVec(traceAnalogical.
GetSize());
1660 TVectorD digitalTime(trace.
GetSize());
1661 TVectorD traceFPGA(trace.
GetSize());
1664 const double discriminatorHiLevel = 3.0;
1665 const double scaleFactor = 50.0;
1667 for(
unsigned int i=0; i<traceAnalogical.
GetSize(); i++){
1668 analogicalTime[i] = (i*binning + minTimePreFE);
1675 for(
unsigned int i=0; i<trace.
GetSize(); i++){
1676 digitalTime[i] = (i*sRate) + traceStartTime;
1680 fLog(
"Generating plots.", 3);
1682 std::stringstream canvasName;
1687 TCanvas canvas(canvasName.str().c_str() ,
"Channel Output", 200, 10, 700, 500);
1690 canvas.SetBorderMode(0);
1691 canvas.SetFillColor(0);
1692 canvas.SetFrameBorderMode(0);
1696 TGraph totalPulsePrePlot(analogicalTime, traceAnalogicalVec);
1697 totalPulsePrePlot.SetLineWidth(3);
1698 totalPulsePrePlot.SetLineColor(kBlue);
1700 TGraph pulsePostFrontEndPlot(analogicalTime, totalPulsePostFrontEndVec);
1701 pulsePostFrontEndPlot.SetLineWidth(3);
1702 pulsePostFrontEndPlot.SetLineColor(kOrange);
1704 TGraph pulsePostDiscriminatorPlot(analogicalTime, totalPulsePostDiscriminatorVec);
1705 pulsePostDiscriminatorPlot.SetLineWidth(3);
1706 pulsePostDiscriminatorPlot.SetLineColor(kBlack);
1708 TGraph pulsePostFPGAPlot(digitalTime, traceFPGA);
1709 pulsePostFPGAPlot.SetMarkerColor(kRed);
1710 pulsePostFPGAPlot.SetMarkerStyle(kFullCircle);
1711 pulsePostFPGAPlot.SetMarkerSize(1);
1712 pulsePostFPGAPlot.SetTitle(
"");
1714 pulsePostFPGAPlot.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1719 pulsePostFPGAPlot.Draw(
"AP");
1720 pulsePostFrontEndPlot.Draw(
"SAME");
1721 totalPulsePrePlot.Draw(
"SAME");
1722 pulsePostDiscriminatorPlot.Draw(
"SAME");
1724 pulsePostFPGAPlot.GetXaxis()->SetRangeUser(minTimePreFE-50,minTimePreFE+150);
1728 leg.SetNColumns( 2 );
1729 leg.SetEntrySeparation( 0.8 );
1732 leg.SetX1NDC( 0.1 );
1733 leg.SetX2NDC( 0.9 );
1734 leg.SetY1NDC( 1 -
fStyle->GetPadTopMargin() );
1736 leg.SetBorderSize( 0 );
1737 leg.SetTextFont(
fStyle->GetTitleFont() );
1738 leg.SetTextSize(
fStyle->GetTitleSize()+0.01 );
1740 leg.AddEntry(&totalPulsePrePlot,
"SiPM (#times50)",
"L");
1741 leg.AddEntry(&pulsePostFrontEndPlot,
"Shaper",
"L");
1742 leg.AddEntry(&pulsePostDiscriminatorPlot,
"Discrim. (/50)",
"L");
1743 leg.AddEntry(&pulsePostFPGAPlot,
"Binary ",
"P");
1744 leg.SetFillColor(canvas.GetFillColor());
1761 std::vector<utl::TraceD> analogicalTraces,
1765 double& minTimePreFE,
1766 double& maxTimePreFE)
1774 traceIntegratorA.
Clear();
1775 traceIntegratorB.
Clear();
1776 traceIntegratorA.
SetBinning(sRateIntegrator);
1777 traceIntegratorB.
SetBinning(sRateIntegrator);
1780 fLog(
"Trace size", 2)(nBinsTrace);
1781 if (analogicalTraces.empty()) {
1782 fLog(
"No pulses data for this module", 2)(module.
GetId());
1783 for (
unsigned int i = 0; i < nBinsTrace; ++i){
1789 for(
unsigned int i = 0; i<analogicalTraces.size(); i++){
1791 fLog(
"Channel traces are corrupted", 1)(module.
GetId());
1804 ApplyBackEndTransfer(backEnd, maxTimePreFE, minTimePreFE, traceAfterADCLowGain, traceAfterADCHighGain, totalAnalogicalInput, analogicalTraces);
1812 SampleTraceADC(minTimePreFE, maxTimePreFE, frontEnd, traceStart, traceAfterADCLowGain, traceAfterADCHighGain, traceIntegratorA, traceIntegratorB);
1820 frontEnd, totalAnalogicalInput, traceAfterADCLowGain, traceAfterADCHighGain, traceIntegratorA, traceIntegratorB, frontEnd.
GetDelayBinaryADC());
1832 TimeTrace& traceAfterADCLowGain,
TimeTrace& traceAfterADCHighGain, TVectorD& totalAnalogicalInput,
const std::vector<utl::TraceD> analogicalTraces){
1834 fLog(
"Applying FFT Integrator...", 3);
1842 int nroChannels = analogicalTraces.size();
1843 double nroOfAdders = nroChannels/numberOfChannelsToGroup;
1845 std::vector<TimeTrace> tracesPostFirstAdder;
1846 for (
int adder = 0; adder < nroOfAdders; adder++) {
1848 int fromChannel = adder*numberOfChannelsToGroup;
1849 int toChannel = (adder+1)*numberOfChannelsToGroup;
1850 toChannel = std::min(toChannel, nroChannels);
1851 fLog(
"Adding pulses. From/To channel:", 3)(fromChannel)(toChannel);
1860 for (
int channel = fromChannel; channel < toChannel; channel++) {
1861 value += analogicalTraces[channel][i];
1864 totalAnalogicalInput[i] += value;
1869 fLog(
"Obtaining the amplified pulses in time-space...", 3);
1877 for(
unsigned int adder = 0; adder < tracesPostFirstAdder.size(); adder++){
1896 tracePreHGChannel.
PushBack(tracePreLGChannel[i]);
1925 TimeTrace& traceAfterADCLowGain,
TimeTrace& traceAfterADCHighGain, TVectorD& totalAnalogicalInput,
const std::vector<utl::TraceD> analogicalTraces){
1926 fLog(
"Applying FFT Integrator...", 3);
1933 int nroChannels = analogicalTraces.size();
1942 for (
int channel = 0; channel < nroChannels; channel++) {
1943 value += analogicalTraces[channel][i];
1946 totalAnalogicalInput[i] += value;
1976 fLog(
"Applying transfer function in frequency space.",3);
1979 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
1981 fLog(
"Generating frequency response.",3);
1982 const unsigned int tabFFTLogLevel = 4;
1983 std::unique_ptr<utl::TabularStream> tabFFT;
1996 fLog(tabFFT->Str(),tabFFTLogLevel);
2003 freqTrace[freqBin] *=
c;
2016 fLog(
"Applying transfer function in frequency space.",3);
2020 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
2023 fLog(
"Generating frequency response.",3);
2024 const unsigned int tabFFTLogLevel = 4;
2025 std::unique_ptr<utl::TabularStream> tabFFT;
2038 fLog(tabFFT->Str(),tabFFTLogLevel);
2044 freqTraceHG.
PushBack(freqTrace[freqBin]*cHG);
2045 freqTrace[freqBin] *= cLG;
2065 fLog(
"ADC analogical pulses (HG/LG).", 3);
2074 if (startTime + delayBinaryADC < minTimePostFE) {
2075 fLog(
"No signal in the range", 4)
2081 fLog(
"ADC High/Low gain channels:", 4);
2088 for (
double sampleTime = startTime; traceIntegratorA.
GetSize() < nBinsTrace ||
fLog(
'\n', 4)(sampleTime);
2089 sampleTime += sRate) {
2091 unsigned short adcLG;
2092 unsigned short adcHG;
2094 if (sampleTime < minTimePostFE + delayBinaryADC || maxTimePostFE + delayBinaryADC < sampleTime) {
2099 int bin = (int)((sampleTime-minTimePostFE-delayBinaryADC)/binning);
2100 double signal1 = traceAfterADCLowGain[bin];
2101 double signal2 = traceAfterADCHighGain[bin];
2118 if (maxTimePostFE + delayBinaryADC < stopTime) {
2120 fLog(
"Samples false in the range ", 4)
2124 (
"as no signal in it.");
2130 TVectorD& traceAnalogical,
TimeTrace& traceIntegratorAAmplifier,
TimeTrace& traceIntegratorBAmplifier,
2138 TVectorD traceIntegratorAVec(traceIntegratorA.
GetSize());
2139 TVectorD traceIntegratorBVec(traceIntegratorB.
GetSize());
2140 TVectorD traceIntegratorAVecAnalog(traceIntegratorAAmplifier.
GetSize());
2141 TVectorD traceIntegratorBVecAnalog(traceIntegratorBAmplifier.
GetSize());
2142 TVectorD analogicalTime(traceAnalogical.GetNoElements());
2143 TVectorD digitalTime(traceIntegratorA.
GetSize());
2147 for (
int i=0; i<traceAnalogical.GetNoElements(); i++){
2148 analogicalTime[i] = (i*binning + minTimePreFE +
delay);
2149 double signal1 = (double)traceIntegratorAAmplifier[i];
2150 double signal2 = (double)traceIntegratorBAmplifier[i];
2153 traceIntegratorAVecAnalog[i] = adcLG;
2154 traceIntegratorBVecAnalog[i] = adcHG;
2157 for (
unsigned int i=0; i<traceIntegratorA.
GetSize(); i++){
2158 digitalTime[i] = (i*sRate + traceStartTime);
2159 traceIntegratorAVec[i] = ((double)traceIntegratorA[i]);
2160 traceIntegratorBVec[i] = ((double)traceIntegratorB[i]);
2163 fLog(
"Generating plots.", 3);
2165 std::stringstream canvasName;
2170 TCanvas canvas(canvasName.str().c_str() ,
"Integrator", 200, 10, 700, 500);
2173 canvas.SetBorderMode(0);
2174 canvas.SetFillColor(0);
2175 canvas.SetFrameBorderMode(0);
2179 TGraph traceIntegratorAPlot(digitalTime, traceIntegratorAVec);
2182 traceIntegratorAPlot.SetMarkerStyle(kFullCircle);
2183 traceIntegratorAPlot.SetMarkerColor(kRed);
2184 traceIntegratorAPlot.SetMarkerSize(1);
2186 TGraph traceIntegratorBPlot(digitalTime, traceIntegratorBVec);
2189 traceIntegratorBPlot.SetMarkerStyle(kFullCircle);
2190 traceIntegratorBPlot.SetMarkerColor(kOrange);
2191 traceIntegratorBPlot.SetMarkerSize(1);
2192 traceIntegratorBPlot.SetTitle(
"");
2194 TGraph traceIntegratorAAnalogPlot(analogicalTime, traceIntegratorAVecAnalog);
2195 traceIntegratorAAnalogPlot.SetLineWidth(3);
2196 traceIntegratorAAnalogPlot.SetLineColor(kRed);
2199 TGraph traceIntegratorBAnalogPlot(analogicalTime, traceIntegratorBVecAnalog);
2200 traceIntegratorBAnalogPlot.SetLineWidth(3);
2201 traceIntegratorBAnalogPlot.SetLineColor(kOrange);
2204 traceIntegratorBPlot.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
2205 traceIntegratorBPlot.GetYaxis()->SetTitle(
"Signal (ADC Counts)");
2209 traceIntegratorBPlot.Draw(
"AP");
2210 traceIntegratorAPlot.Draw(
"SAME P");
2211 traceIntegratorAAnalogPlot.Draw(
"SAME");
2212 traceIntegratorBAnalogPlot.Draw(
"SAME");
2214 traceIntegratorBPlot.GetXaxis()->SetRangeUser(minTimePreFE+delay-200,minTimePreFE+delay+200);
2217 leg.SetNColumns( 2 );
2218 leg.SetEntrySeparation( 0.8 );
2219 leg.SetX1NDC( 0.10 );
2220 leg.SetX2NDC( 0.90 );
2221 leg.SetY1NDC( 1 -
fStyle->GetPadTopMargin() );
2223 leg.SetBorderSize( 0 );
2224 leg.SetTextFont(
fStyle->GetTitleFont() );
2225 leg.SetTextSize(
fStyle->GetTitleSize()+0.01 );
2226 leg.AddEntry(&traceIntegratorAAnalogPlot,
"Analogue Low Gain",
"L");
2227 leg.AddEntry(&traceIntegratorBAnalogPlot,
"Analogue High Gain",
"L");
2228 leg.AddEntry(&traceIntegratorAPlot,
"FPGA Sample",
"P");
2229 leg.AddEntry(&traceIntegratorBPlot,
"FPGA Sample",
"P");
2230 leg.SetFillColor(canvas.GetFillColor());
2246 if ( !module.
IsSiPM() ) {
2247 for (SignalsMap::const_iterator i = sm.begin(), fpe = sm.end(); i != fpe; ++i) {
2248 SignalsMap::key_type pixelId = i->first;
2257 fLog(
"Simulating PMT-electronic channel:", 2)(channel.
GetId())(
"...");
2268 fLog(
"Trace start at", 3)(start)(
"...");
2270 fLog(
"Total analog particle pulse over-threshold time span", 3)
2280 std::vector<utl::TraceD> analogicalTraces;
2288 for (SignalsMap::const_iterator i = sm.begin(), fpe = sm.end(); i != fpe; ++i) {
2289 double minTimeSignal;
2290 double maxTimeSignal;
2293 minTimePreFE = std::min(minTimePreFE, minTimeSignal);
2294 maxTimePreFE =
std::max(maxTimePreFE, maxTimeSignal);
2298 for (SignalsMap::const_iterator i = sm.begin(), fpe = sm.end(); i != fpe; ++i) {
2299 SignalsMap::key_type pixelId = i->first;
2304 fLog(
"Simulating SiPM-electronic channel:", 2)(channel.
GetId())(
"...");
2317 startTimeTrace = start;
2319 fLog(
"Trace start at", 3)(start)(
"...");
2320 ProcessPulses(channel, i->
second, trace, traceAnalogical, span, start - eventTime, minTimePreFE, maxTimePreFE);
2322 fLog(
"Total analog particle pulse over-threshold time span", 2)
2325 analogicalTraces.push_back(traceAnalogical);
2337 if (analogicalTraces.size()>0){
2347 fLog(
"Generating integrator traces", 2);
2348 ProcessPulsesIntegrator(module, analogicalTraces, traceIntegratorA, traceIntegratorB, startTimeTrace - eventTime, minTimePreFE, maxTimePreFE);
2380 template<
class FrontEndType>
2388 for (
typename FrontEndType::ChannelConstIterator ch = frontEnd.ChannelsBegin(), ec = frontEnd.ChannelsEnd(); ch != ec; ++ch) {
2389 if (!mIt->HasChannel(ch->GetId()))
2390 mIt->MakeChannel(ch->GetId());
2401 ERROR(
"SEvent does not exist.");
2409 std::ostringstream message;
2410 message <<
"partner station with id " << partnerId <<
"was not found in SEvent\n";
2416 const sdet::Station& detStation = det::Detector::GetInstance().GetSDetector().GetStation(sStation);
2432 firstT1Sd = trigTime;
2446 if (!(trig.IsT2() || trig.IsT1()))
2453 if (trigTime < firstT1Sd) {
2455 firstT1Sd = trigTime;
2479 utl::TimeStamp eventTime =
event.GetSEvent().GetHeader().GetTime();
2489 TLatch = firstT1Sd - shift;
2491 deltaLatch = TLatch - eventTime;
2494 int binTrgStop = int((firstT1Sd-eventTime)/detStation.
GetFADCBinSize());
2509 tab << firstT1Sd - eventTime <<
utl::endc;
2516 std::cout << tab << std::endl;
2521 const int mId = mIt->GetId();
2543 fun.GetRange(min, max);
2549 double xWhole = min + i * stepWhole;
2550 double xWindow = min + i * stepWindow;
2554 << fun.Eval(xWhole) <<
'\t'
2556 << fun.Eval(xWindow)
2570 std::stringstream fmt;
2571 for(
unsigned int i = 0; i < nCol; ++i)
2580 fLog.ApplyConfigurationOn(*pt);
AtThresholdConstIterator AtThresholdBegin() const
Begin iterator over times.
bool IsTimeOverThresholdDeconvoluted() const
Time Over Threshold deconvoluted.
const BackEndSiPM & GetBackEndSiPM() const
std::string fPulseFilename
Pulse output file filename.
double GetAmplitude2() const
Station Level Simulated Data
void MakeChannel(const int cId)
virtual void SampleTrace(double minTimePostFE, double maxTimePostFE, double binning, const mdet::FrontEndSiPM &frontEnd, const utl::TimeInterval &traceStart, TimeTrace &totalPulsePostDiscriminatorTrace, utl::TraceB &trace)
const std::string & GetElectricResistanceName() const
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
int GetId() const
Get the station Id.
utl::TimeStamp GetTraceStartTime() const
Return the timestamp associated with the start of the trace. The timestamp of the first bin of the tr...
CounterConstIterator CountersBegin() const
bool fGenerateSPEPulseOutput
To include individual pulses samples in the output file.
const Pixel & GetPixel(int pId) const
unsigned int fNPulseSamples
Number of samples to use in the output files for pulses.
const Counter & GetCounter() const
The parent counter.
bool HasStation(const int stationId) const
Check whether station exists.
double GetSampleTimeADC() const
ADC Sample Time and delay.
double GetFallTime3() const
Detector description interface for Station-related data.
Report success to RunController.
double GetHighGainAmplifierOffset() const
utl::MessageLoggerConfig fLog
Output messages handler.
bool HasIntegratorBTrace() const
static EnumType Create(const int k)
int version of the overloaded creation method.
double ComputeDiscriminator(double signal, double deltaTime) const
double GetFallTime2() const
VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
virtual void ApplyBackEndTransfer(const mdet::BackEndSiPM &backEnd, const double maxTimePreFE, const double minTimePreFE, TimeTrace &traceAfterADCLowGain, TimeTrace &traceAfterADCHighGain, TVectorD &totalAnalogicalInput, const std::vector< utl::TraceD > traceAnalogical)
short GetInjectDigitalNoiseBin() const
Interface class to access to the SD part of an event.
bool fIncludeBaseLineFluctuationIntegrator
To simulate baseline fluctuation in the integrator output.
unsigned short GetADCBaseLineFluctuationLG() const
Noise injection for binary and ADC channels.
double GetFallTime1() const
double ApplySaturation(double value, TransferStep step) const
void AddSPEPulse(const double mu, const double sigma, const double amplitude, const int destPixelId)
bool fPlotTransferPhaseResponse
virtual void ProcessPulses(const mdet::Channel &c, const SignalInformation &signalInfo, utl::TraceB &trace, double &span, const utl::TimeInterval &traceStart)
Process: analyze, electronic simulation and sampling.
VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
double GetAngleUnit() const
const FrontEndSiPM & GetFrontEnd() const
The shared common-to-all-ChannelSiPMs electronic frontend of this ChannelSiPM.
bool is(const double a, const double b)
unsigned int GetPostT1BufferLength() const
Number of bins of the post-T1 buffer.
virtual void InjectDigitalNoise(const mdet::Module &module, mevt::Module &evtModule)
PhotonTimeContainer::const_iterator ConstPhotonTimeIterator
utl::UnitsConfig fUnits
Units configuration.
unsigned short GetInjectDigitalNoiseWidth() const
double fPulseSampleWindow
Define the length of the window within which the pulse is sampled.
#define INFO(message)
Macro for logging informational messages.
double ComputeSignalShift() const
Computes a signal shift value according this Channel's characteristics (and, particularly, to the distribution of these values).
const Channel & GetChannelFor(const Component &c) const
Returns the associated mdet::Channel.
std::complex< double > ComputeTransfer(double freq, TransferStep step) const
double GetDelayBinaryADC() const
Helper class encapsulating the discriminator response logic.
const FrontEnd & GetFrontEnd() const
The shared common-to-all-channels electronic frontend of this channel.
virtual void ApplyCITIROCTransfer(const mdet::ChannelSiPM &channel, const SignalInformation &si, const double pulseTimeSpan, double minTimePreFE, TimeTrace &totalPulsePostFrontEndTrace, TimeTrace &totalPulsePostDiscriminatorTrace, utl::TraceD &traceAnalogical)
Electronic front-end for the modules.
unsigned int GetPreT1BufferLength() const
Number of bins of the (cyclic) pre-T1 buffer.
Encapsulates the sampling logic.
Sampler MakeSampler() const
Create a new sampler object.
double GetStartTime() const
unsigned int fStepSPE
Step size for spe iteration.
ModuleConstIterator ModulesEnd() const
Begin iterator for the Modules contained in the Counter.
virtual VModule::ResultFlag SimulateElectronics(mevt::Module &evtModule, const mdet::Module &module, const SignalsMap &sm, const utl::TimeStamp &eventTime)
Peform the simulation of the electronics response.
Detector associated to muon detector hierarchy.
void SetElectricCurrentDefault(const double unit, const std::string &name)
Electronic front-end for the modules.
IntegratorSimulationType fIntegratorSimType
Type of integrator simulation. Step by step simulates the complete transfer functions and applies sat...
double GetLowGainAmplifierOffset() const
A TimeStamp holds GPS second and nanosecond for some event.
const SiPMArray & GetSiPMArray() const
std::map< int, SignalInformation > SignalsMap
Map associating the information with IDs (meant to be from pixel's).
~MdOptoElectronicSimulator()
Actual muon-sensitive objects.
Sampler MakeSampler() const
Create a new sampler object.
virtual void ApplyTransferBlock(utl::FFTDataContainer< utl::Trace, TimeTrace::ValueType, FrequencyTrace::ValueType > &fft, const mdet::BackEndSiPM &backEnd, BackEndSiPM::TransferStep step)
sevt::StationTriggerData & GetTriggerData(const utl::TimeStamp &time)
Get simulated TriggerData.
const SiPM & GetSiPM(const int pId) const
Class representing a document branch.
short GetNumberOfChannelsToGroup() const
class to hold data at Station level
bool IsT1Threshold() const
T1 threshold.
bool fTogglePlotFftPostAmp
const SiPM & GetSiPMFor(const Component &c) const
Returns the associated mdet::SiPM.
const Pixel & ComputePulseDestination(const Pixel &src) const
Computes a destination pixel according to crosstalk effect.
bool HasSimData() const
Check whether station simulated data exists.
unsigned int fMaxSPE
Maximum number of spe (inclusive).
C< F > & GetFrequencySpectrum()
read out the frequency spectrum (write access)
std::vector< std::string > fPlotFileExtensions
File extensions for plots (dot included).
std::vector< std::complex< double > >::size_type SizeType
const PMT & GetPMT() const
bool fPlotTransferAmpResponse
void Configure(const utl::Branch &config)
Configure units (values and defaults) given a branch.
std::complex< double > ComputeTransfer(double freq) const
Computes the circuit transfer function at the given frequency.
unsigned int fMinSPE
Minimum number of spe (inclusive).
bool fInjectNoiseBinary
To inject noise in binary traces.
PhotonTimeIterator PhotonTimesBegin()
double GetRiseTime() const
double abs(const SVector< n, T > &v)
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Encapsulates the sampling logic.
const unsigned int & GetLevel() const
Retrieve (read-only) the current level of verbosity.
decltype(std::begin(boost::adaptors::keys(TriggerGPSMap()))) typedef TriggerTimeIterator
void SetLengthDefault(const double unit, const std::string &name)
Channel & GetChannel(const int cId)
unsigned int fNRepetitions
Repetitions for in-module loop.
C< T > & GetTimeSeries()
read out the time series (write access)
double GetAmplitude() const
void Configure(const Branch &config)
int GetAssociatedTankId() const
Retrieve the id of the associated surface tank.
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
constexpr double megahertz
void SetTraceStartTime(mevt::Counter::ModuleIterator mIt, const FrontEndType &frontEnd, const utl::TimeStamp &eventTime, const double &deltaLatch)
unsigned int GetPreT1BufferLength() const
Number of bins of the (cyclic) pre-T1 buffer.
int GetTriggerTimeFromSD(evt::Event &, const mdet::Counter &, mevt::MEvent::CounterIterator, double &)
Retrieve T1 time from associated SD tank.
double GetElectricCurrentUnit() const
bool fGeneratePreFETotalPulseOutput
To include the total pulse prior front-end in the output file.
class to format data in tabular form
std::complex< double > ComputeTransfer(double freq) const
Computes the circuit transfer function at the given frequency.
void SetFrequencyDefault(const double unit, const std::string &name)
s<< "id="<< GetId()<< " [";for(It i=GetIdsMap().begin(), e=GetIdsMap().end();i!=e;++i) s<< " "<< i-> first<< "="<< i-> second
#define WARNING(message)
Macro for logging warning messages.
double GetElectricPotentialUnit() const
const Pixel & GetPixelFor(const Component &c) const
Returns the associated mdet::Pixel.
unsigned int GetPostT1BufferLength() const
Number of bins of the post-T1 buffer.
bool IsT2Threshold() const
T2 threshold.
utl::TraceUSI & GetIntegratorATrace()
bool HasIntegratorATrace() const
bool HasChannel(const int cId) const
void MakeIntegratorATrace()
void SetTimeDefault(const double unit, const std::string &name)
const FrontEnd & GetFrontEnd() const
InternalModuleCollection::ComponentIterator ModuleIterator
TriggerTimeIterator TriggerTimesBegin() const
Beginning of simulated local trigger times list.
RawRootsContainer::const_iterator AtThresholdConstIterator
Iterator over the times when the input signal reaches the threshold level.
Station & GetStation(const int stationId)
retrieve station by id throw utl::NonExistentComponentException if n.a.
double GetInterval() const
Get the time interval as a double (in Auger base units)
Root detector of the muon detector hierarchy.
bool IsMultiplicityOfPositiveSteps() const
const std::string & GetElectricCurrentName() const
bool IsTimeOverThreshold() const
T1 TOT is always promoted to T2 TOT.
void SetBinning(const double binning)
Template class for a data container that offers and takes both time series and corresponding frequenc...
Scintillator level simulation data.
virtual void SampleTraceADC(const double minTimePostFE, const double maxTimePostFE, const mdet::FrontEndSiPM &frontEnd, const utl::TimeInterval &traceStart, TimeTrace &traceAfterADCLowGain, TimeTrace &traceAfterADCHighGain, utl::TraceUSI &traceIntegratorA, utl::TraceUSI &traceIntegratorB)
A TimeInterval is used to represent time elapsed between two events.
bool fToggleTransferPhaseResponse
ResultFlag
Flag returned by module methods to the RunController.
double GetFADCBinSize() const
std::ofstream fPulseFile
Associated stream.
void AddPEPulse(const double t0, const double a1, const double a2, const double a3, const double timeRise, const double timeFall1, const double timeFall2, const double timeFall3, const int destPixelId)
InternalCounterCollection::ComponentIterator CounterIterator
virtual double GetPulseTimeSpan(const SignalInformation &si, double &minTimePreFE, double &maxTimePreFE)
double GetPhotonTime(const PhotonTime &photon) const
double GetOverThresholdTimeSpan() const
Return the total time span over the discrimination threshold.
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
unsigned short GetADCCounts(double value) const
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
Station Trigger Data description
void Dump(const TF1 &fun, const std::string &suffix)
Helper to dump a TF1 to the configured file.
double GetElectricResistanceUnit() const
AtThresholdConstIterator AtThresholdEnd() const
End iterator over times.
const FrontEndSiPM & GetFrontEndSiPM() const
PhotonTimeIterator PhotonTimesEnd()
void SetElectricPotentialDefault(const double unit, const std::string &name)
Channel level event data.
InternalScintillatorCollection::ComponentIterator ScintillatorIterator
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
ModuleConstIterator ModulesBegin() const
Begin iterator for the Modules contained in the Counter.
TriggerTimeIterator TriggerTimesEnd() const
End of simulated local trigger times list.
const std::string & GetTimeName() const
Report failure to RunController, causing RunController to terminate execution.
CounterConstIterator CountersEnd() const
unsigned int fNBinsHistograms
Number of bins for histograms.
virtual void ProcessPulsesIntegrator(const mdet::Module &module, std::vector< utl::TraceD > analogicalTraces, utl::TraceUSI &traceIntegratorA, utl::TraceUSI &traceIntegratorB, const utl::TimeInterval &traceStart, double &minTimePreFE, double &maxTimePreFE)
PE MakePEAt(double t) const
Constructs an PE according to this SiPM characteristics.
unsigned int GetFADCTraceLength() const
virtual void ApplyBackEndTransferWStepSaturation(const mdet::BackEndSiPM &backEnd, const double maxTimePreFE, const double minTimePreFE, TimeTrace &traceAfterADCLowGain, TimeTrace &traceAfterADCHighGain, TVectorD &totalAnalogicalInput, const std::vector< utl::TraceD > traceAnalogical)
ModuleGroup::ConstIterator ModuleConstIterator
Convenience typedef for const iterator over the contained Module instances.
sevt::StationSimData & GetSimData()
Get simulated data at station level.
unsigned int fRunNumber
Tracks the number of runs.
virtual void PlotChannel(const double traceStartTime, const double minTimePreFE, const double binning, const mdet::ChannelSiPM &channel, utl::TraceD &traceAnalogical, TimeTrace &totalPulsePostFrontEndTrace, TimeTrace &totalPulsePostDiscriminatorTrace, utl::TraceB &trace)
void MakeIntegratorBTrace()
const std::string & GetFrequencyName() const
int GetId() const
The id of this component.
double GetAmplitude1() const
std::set< ParticleType > fAllowedParticleTypes
Particle types that are considered to generate signal, if empty then every kind of particle is allowe...
const std::string & GetElectricPotentialName() const
double GetTimeUnit() const
utl::TraceUSI & GetIntegratorBTrace()
double GetAmplitude3() const
const Module & GetModule() const
The module to which this FrontEnd belongs.
double mod(const double d, const double periode)
const Scintillator & GetScintillator(int sId) const
Direct accesor by id.
bool fIgnoreCrossTalk
Ignore cross-talk effects.
unsigned short GetADCBaseLineFluctuationHG() const
const Counter & GetCounter(int id) const
Retrieve Counter by id.
bool fTogglePlotchannelPulses
void PushBack(const T &value)
Insert a single value at the end.
const Module & GetModule() const
The module to which this FrontEndSiPM belongs.
#define ERROR(message)
Macro for logging error messages.
double GetFrequencyUnit() const
SPE MakeSPEAt(const double t) const
Constructs an SPE according to this pixel's characteristics.
unsigned int fNDiscretization
Discretization over the continuous functions.
const std::string & GetAngleName() const
double GetThreshold() const
Discrimination threshold.
bool fForcedSDTrigger
Ignore WCD trigger condition.
Root of the Muon event hierarchy.
unsigned int fNumPlotPoints
Number of points to be used in plotting (theoretically) continuous functions.
virtual void ApplyTransferBlocks(utl::FFTDataContainer< utl::Trace, TimeTrace::ValueType, FrequencyTrace::ValueType > &fft, utl::FFTDataContainer< utl::Trace, TimeTrace::ValueType, FrequencyTrace::ValueType > &fftHG, const mdet::BackEndSiPM &backEnd)
const ChannelSiPM & GetChannelSiPMFor(const Component &c) const
Returns the associated mdet::ChannelSiPM.
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
unsigned short GetInjectDigitalNoiseChannel() const
virtual void PlotIntegrator(const double traceStartTime, const double minTimePreFE, const double binning, const mdet::FrontEndSiPM &frontEnd, TVectorD &traceAnalogical, TimeTrace &traceIntegratorAAmplifier, TimeTrace &traceIntegratorBAmplifier, utl::TraceUSI &traceIntegratorA, utl::TraceUSI &traceIntegratorB, const double delay)
bool fGeneratePostFETotalPulseOutput
To include the total pulse after front-end in the output file.
VModule::ResultFlag Run(evt::Event &e)
Run: invoked once per event.
bool fToggleTransferAmpResponse
static const char *const kIntegratorSimulationTypeTags[]
Tags for the types of integrator simulation.
VModule::ResultFlag OptoElectronics(evt::Event &e)