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 <<
'_'
98 Tag& operator()(
const S&
s) {
103 const std::stringstream& sstr()
const {
109 return GetModule(p.
GetPMT());
125 template<
class Component>
126 const mdet::Module& GetModule(
const Component& c)
const {
127 return c.GetModule();
130 std::stringstream fStream;
137 template<
class T1,
class T2>
139 static void Constraints(T1
a, T2
b) {
144 void(*p)(T1,T2) = Constraints;
152 template<
class StringContainer>
153 void PrintPlots(
const TCanvas& c,
const StringContainer& sc,
const Tag& t)
160 typedef typename StringContainer::value_type
S;
161 CanCopy<S, std::string>();
162 const std::string& n = t.sstr().str();
163 for (
typename StringContainer::const_iterator i = sc.begin(), e = sc.end(); i != e; ++i)
164 c.Print((n + *i).c_str());
203 struct OwnerVector :
public std::vector<T*> {
204 void operator()(
const T *
const t)
const {
208 typedef typename OwnerVector<T>::const_iterator It;
209 typedef const OwnerVector<T>& ConstRef;
213 std::for_each<It,ConstRef>(this->begin(), this->end(), *
this);
223 template<
class Container>
224 struct TotalPulseFunctor {
225 TotalPulseFunctor(
const Container& pulses,
double ux,
double uy) :
226 fPulses(pulses), fUnitX(ux), fUnitY(uy), fAbs(false) { }
227 double operator()(
double t)
const {
228 double totalSignal = 0;
230 for (
typename Container::const_iterator p = fPulses.begin(), e = fPulses.end(); p != e; ++
p)
231 totalSignal += p->TimeSpaceEvaluate(t);
233 totalSignal =
std::abs(totalSignal);
236 double operator()(
double *x,
double * )
const {
238 return (*
this)(x[0] * fUnitX) / fUnitY;
240 const Container& fPulses;
247 template<
class Functor>
248 struct ProxyFunctor {
249 ProxyFunctor(
const Functor& func,
double ux,
double uy) :
250 fFunctor(func), fUnitX(ux), fUnitY(uy) {}
251 double operator()(
double *x,
double * )
const {
252 return fFunctor(x[0] * fUnitX) / fUnitY;
254 const Functor& fFunctor;
260 struct PulseFunctor {
262 fPulse(&spe), fUnitX(ux), fUnitY(uy) {}
265 fPhotoEquivalent(&pe), fUnitX(ux), fUnitY(uy) {}
266 double operator()(
double *x,
double * )
const {
267 return fPulse->TimeSpaceEvaluate(x[0] * fUnitX) / fUnitY;
276 struct ThresholdFunctor {
277 ThresholdFunctor(
double t,
double uy) :
278 fThreshold(t), fUnitY(uy) {}
279 double operator()(
double * x = 0,
double *p = 0)
const {
288 return fThreshold / fUnitY;
295 struct TGraphFunctor {
296 TGraphFunctor(
const TGraph&
g) : fGraph(g) {}
297 double operator()(
double *x,
double * )
const {
298 return fGraph.Eval(x[0]);
300 const TGraph& fGraph;
304 struct DerivativeFunctor {
305 DerivativeFunctor(
const TF1& f,
double s = 1.0) : fF1(f), fScale(s) { }
306 double operator()(
double *x,
double * )
const {
307 return fScale * fF1.Derivative(x[0]);
315 struct TraceFunctor {
316 TraceFunctor(
const T& t,
double m,
double ux,
double uy) :
317 fTrace(t), fMinTime(m), fUnitX(ux), fUnitY(uy), fBinning(t.GetBinning()), fAbs(false) {}
318 double operator()(
double *x,
double * )
const {
319 return ((*
this)(x[0] * fUnitX)) / fUnitY;
321 double operator()(
double t)
const {
324 double timeOffset = t - fMinTime;
327 double maxOffset = fTrace.GetSize() * fBinning;
328 if (timeOffset > maxOffset)
331 typedef typename T::SizeType Size;
339 Size leftBin =
static_cast<Size
>(timeOffset / fBinning);
340 Size rightBin = leftBin + 1;
341 double leftOffset = fBinning * leftBin;
342 double rightOffset = fBinning * rightBin;
343 double leftValue = fTrace[ leftBin ];
344 double rightValue = fTrace[ rightBin ];
345 double res = leftValue + (rightValue-leftValue) * (timeOffset - leftOffset) / (rightOffset - leftOffset);
362 namespace MdCounterSimulatorAG {
365 MdCounterSimulator::kSimulationTypeTags[] = {
"FromMEvent",
"FromMEventSimulatedScint"};
368 MdCounterSimulator::kIntegratorSimulationTypeTags[] = {
"StepByStep",
"Simplified"};
370 MdCounterSimulator::MdCounterSimulator() :
397 LoadConfig(config,
"plotFileExtensions", exts,
".eps .root");
398 typedef boost::char_separator<std::string::value_type> Sep;
399 typedef boost::tokenizer<Sep> Tokenizer;
401 Tokenizer tokens(exts, sep);
406 std::vector<ParticleType> particleTypesDefault;
414 std::vector<ParticleType> particleTypes;
415 LoadConfig(config,
"allowedParticleTypes", particleTypes, particleTypesDefault);
419 fLog(
"No particle types indicated: allowing'em all", 1);
490 Option_t *axis=
"XYZ";
491 Float_t margin = 0.15;
494 fStyle->SetCanvasBorderMode(0);
495 fStyle->SetCanvasColor(0);
497 fStyle->SetTickLength( 0.01,
"XYZ" );
498 fStyle->SetLabelFont( font , axis);
499 fStyle->SetLabelSize( fsize, axis);
500 fStyle->SetLabelOffset( 0.005, axis);
501 fStyle->SetTitleFont( font , axis);
502 fStyle->SetTitleSize( fsize, axis);
503 fStyle->SetTitleOffset( 1.0, axis);
504 fStyle->SetTitleXOffset( 1.5 );
505 fStyle->SetTitleYOffset( 2.5 );
506 fStyle->SetTitleAlign( 22 );
507 fStyle->SetTitleBorderSize( 0 );
508 fStyle->SetTitleColor( 1, axis );
509 fStyle->SetTitleFillColor( 0 );
513 fStyle->SetTitleY( 1-margin/2 );
514 fStyle->SetTitleTextColor( kBlue );
522 fStyle->SetPadBottomMargin(margin);
523 fStyle->SetPadLeftMargin (margin);
524 fStyle->SetPadRightMargin (margin);
525 fStyle->SetPadTopMargin (margin);
526 fStyle->SetPadBorderMode( 0 );
527 fStyle->SetPadBorderSize( 0 );
529 fStyle->SetPadGridX(
false);
530 fStyle->SetPadGridY(
false);
531 fStyle->SetPadTickX(
true);
532 fStyle->SetPadTickY(
false);
534 fStyle->SetFrameBorderMode( 0 );
535 fStyle->SetFrameBorderSize( 0 );
536 fStyle->SetFrameFillColor( 0 );
537 fStyle->SetFrameFillStyle( 1 );
538 fStyle->SetFrameLineColor( 0 );
539 fStyle->SetFrameLineStyle( 0 );
540 fStyle->SetFrameLineWidth( 0 );
567 INFO(
"RunFromMEvent");
571 fLog(
"The event time for simulation ", 2)(mEventTime);
572 const mdet::MDetector& detector = det::Detector::GetInstance().GetMDetector();
583 if (
is->HasSimData()) {
601 INFO(
"Event without MEvent: nothing to be done.");
619 INFO(
"RunFromMEventScintillatorSimulated");
623 const utl::TimeStamp& mEventTime =
event.GetSEvent().GetHeader().GetTime();
624 fLog(
"The event time for SiPM-simulation ", 2)(mEventTime);
625 const mdet::MDetector& detector = det::Detector::GetInstance().GetMDetector();
632 std::cout <<
"SD trigger found for counter " << ic->GetId() <<
" at T1 " << T1/
utl::ns <<
"ns " << std::endl;
633 std::cout <<
"Trigger is T" << triggerFound <<
"\n";
636 std::cout <<
"XXX NO SD trigger found for counter " << ic->GetId() <<
" but used anyway" << std::endl;
639 std::cout <<
"XXX NO SD trigger found for counter " << ic->GetId() << std::endl;
640 ic->SetRejected(
"SD associated un-triggered");
651 if (
is->HasSimData()) {
657 photon != lastPhoton; ++photon) {
661 bool isSiPM = module.
IsSiPM();
667 finalPixId = pixel.
GetId();
670 finalPixId = dst.
GetId();
673 signalsMap[ finalPixId ].fPulses.push_back(spe);
680 finalPixId = sipm.
GetId();
682 signalsMap[ finalPixId ].fSiPMPulses.push_back(pe);
698 INFO(
"Event without MEvent: nothing to be done.");
711 bool isSiPM = module.
IsSiPM();
718 sm[ pixel.
GetId() ].fScintSimData = &ssd;
721 sm[ sipm.
GetId() ].fScintSimData = &ssd;
725 const unsigned int particleTabLogLevel = 3;
726 std::unique_ptr<utl::TabularStream> particleTab;
728 Init(particleTab, 8);
741 const unsigned int speTabLogLevel = 4;
742 std::unique_ptr<utl::TabularStream> speTab;
757 unsigned int nHit = 0;
759 i != sse ||
fLog(
"", 2); ++i) {
784 const unsigned int hitLogLevel = 33;
786 fLog(
"Track begin in scint", hitLogLevel)
793 fLog(
"Track end in scint", hitLogLevel)
802 const double trackLen = track.
GetLength();
820 const double onScint =
utl::Distance(trackMiddle, targetPlane);
824 const double pathLen = onScint + onManifold;
840 const double hitDepth = module.
GetDepth(hitPoint);
855 for (
unsigned int n = 0; n < nSPE; ++n) {
857 double delay = pathDelay;
865 delay += particleDelay;
877 finalPixId = pixel.
GetId();
881 finalPixId = dst.
GetId();
884 sm[ finalPixId ].fPulses.push_back(spe);
891 finalPixId = sipm.
GetId();
894 sm[ finalPixId ].fSiPMPulses.push_back(pe);
919 fLog(
"Particle missing the scintillator after hit", 1)(nHit);
927 fLog(
"Impinging particles information:", particleTabLogLevel);
928 fLog(particleTab->Str(), particleTabLogLevel);
934 fLog(
"Generated spe information:", speTabLogLevel);
935 fLog(speTab->Str(), speTabLogLevel);
963 fLog(
"Trace size", 2)(nBinsTrace);
965 if (si.
fPulses.empty() && ! isAnalogicTrace) {
966 fLog(
"No pulses and other sim data found for channel", 1)(channel.
GetId());
968 for (
unsigned int i = 0; i < nBinsTrace; ++i)
978 std::unique_ptr<utl::TabularStream> spanTable;
979 const unsigned int pulseSpanLogLevel = 3;
987 unsigned int nSPE = 0;
988 for (PulseContainer::const_iterator p = si.
fPulses.begin(), e = si.
fPulses.end(); p != e; ++
p) {
989 minTimePreFE = std::min(minTimePreFE, p->LowerLimit());
990 maxTimePreFE =
std::max(maxTimePreFE, p->UpperLimit());
999 double analogicTraceStartTime = 0;
1000 double analogicTraceEndTime = 0;
1001 if (isAnalogicTrace) {
1002 analogicTraceStartTime = (si.
fScintSimData->GetAnalogicTraceStartTime() - eventTime).GetInterval();
1005 minTimePreFE = std::min(minTimePreFE, analogicTraceStartTime);
1006 maxTimePreFE =
std::max(maxTimePreFE, analogicTraceEndTime);
1009 const double pulseTimeSpan = maxTimePreFE - minTimePreFE;
1016 fLog(
"SPE pulses and other signals span:", pulseSpanLogLevel);
1017 fLog(spanTable->Str(), pulseSpanLogLevel);
1020 TotalPulseFunctor<PulseContainer> totalPulsePreFrontEnd(si.
fPulses,
1023 fLog(
"Applying FFT...", 3);
1031 fLog(
"Discretizing total pulses. Number of samples:", 3,
false);
1034 double time = minTimePreFE + i * binning;
1035 double value = totalPulsePreFrontEnd(time);
1036 if (isAnalogicTrace) {
1038 if (analogicTraceStartTime <= time && time <= analogicTraceEndTime) {
1040 double delta = time - analogicTraceStartTime;
1050 fLog(
"Applying transfer function in frequency spectrum.", 3);
1053 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
1054 TVectorD freqArray(nFreq);
1055 TVectorD ampArray(nFreq);
1056 TVectorD phaArray(nFreq);
1057 TVectorD preFFT(nFreq);
1058 TVectorD postFFT(nFreq);
1059 fLog(
"Generating frequency response.", 3);
1060 const unsigned int tabFFTLogLevel = 4;
1061 std::unique_ptr<utl::TabularStream> tabFFT;
1062 if (fLog.GetLevel() >= tabFFTLogLevel) {
1074 fLog(tabFFT->Str(), tabFFTLogLevel);
1077 double freq = fft.GetFrequencyOfBin(freqBin);
1082 freqTrace[ freqBin ] *=
c;
1087 ampArray(freqBin) = amp;
1088 phaArray(freqBin) = pha;
1089 preFFT(freqBin) = preAmp;
1092 fLog(
"Obtaining the amplified pulses in time-space...", 3);
1094 const TimeTrace& totalPulsePostFrontEndTrace = fft.GetConstTimeSeries();
1118 const double minTimePostFE = minTimePreFE + shift;
1119 const double maxTimePostFE = maxTimePreFE + shift;
1122 TraceFunctor<TimeTrace> totalPulsePostFrontEnd(totalPulsePostFrontEndTrace,
1127 fLog(
"Creating discriminator object.", 3);
1129 totalPulsePostFrontEnd,
1134 const unsigned int rootLogLevel = 4;
1135 if (fLog.GetLevel() >= rootLogLevel) {
1140 fLog(
"Incoming pulse never at threshold level.", rootLogLevel);
1141 fLog(
"Incoming pulse at threshold level at ", rootLogLevel,
false);
1142 for (ItRoot i = b; i != e; ++i) {
1145 fLog(
".", rootLogLevel);
1148 fLog(
"Creating sampler object.", 3);
1156 std::vector<double> sampleTimes;
1158 fLog(
"Sampling pulses.", 3);
1159 const double startTime = traceStart.
GetInterval();
1160 const double stopTime = startTime +
1168 if (startTime < minTimePostFE) {
1170 fLog(
"Samples false in the range", 4)
1174 (
"as no signal in it.");
1176 fLog(
"Samples:", 4);
1180 for (
double sampleTime = startTime; trace.
GetSize() < nBinsTrace ||
fLog(
'\n', 4)(sampleTime);
1181 sampleTime += sRate) {
1184 if (sampleTime < minTimePostFE || maxTimePostFE < sampleTime) {
1190 double o = discriminator(sampleTime);
1196 sampleTimes.push_back(sampleTime);
1198 if (maxTimePostFE < stopTime) {
1200 fLog(
"Samples false in the range ", 4)
1204 (
"as no signal in it.");
1226 fLog(
"Generating plots.", 3);
1228 std::stringstream canvasName;
1233 TCanvas canvas(canvasName.str().c_str() ,
"Total SPE pulses", 200, 10, 700, 500);
1236 canvas.SetBorderMode(0);
1237 canvas.SetFillColor(0);
1238 canvas.SetFrameBorderMode(0);
1243 std::stringstream totalPulseNamePre;
1244 totalPulseNamePre <<
"totalPulsePre_"
1248 TF1 totalPulseFunPre(totalPulseNamePre.str().c_str(),
1249 & totalPulsePreFrontEnd,
1253 totalPulseFunPre.SetLineColor(kRed);
1254 totalPulseFunPre.SetLineWidth(2);
1255 totalPulseFunPre.SetLineStyle(1);
1257 totalPulseFunPre.SetFillColor(canvas.GetFillColor());
1258 totalPulseFunPre.Draw(
"X+");
1261 unsigned int nPulse = 0;
1263 OwnerVector<PulseFunctor> pFunctors;
1264 OwnerVector<TF1> pFunctions;
1265 pFunctors.reserve(si.
fPulses.size());
1266 pFunctions.reserve(si.
fPulses.size());
1267 for (PulseContainer::const_iterator p = si.
fPulses.begin(), pe = si.
fPulses.end(); p != pe; ++
p) {
1269 std::stringstream pulseName;
1270 pulseName <<
"pulse_" << nPulse++ <<
"_"
1274 TF1* pulseFun =
new TF1(pulseName.str().c_str(),
1278 pulseFun->SetLineColor(kBlack);
1279 pulseFun->SetLineWidth(1);
1280 pulseFun->SetLineStyle(2);
1282 pulseFun->Draw(
"same");
1283 pFunctors.push_back(pulse);
1284 pFunctions.push_back(pulseFun);
1286 std::stringstream
s;
1287 s <<
"spe " << nPulse <<
" " << channel.GetIdMessage();
1288 Dump(*pulseFun, s.str());
1291 totalPulseFunPre.SetTitle(
"SPEs");
1292 totalPulseFunPre.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1296 std::stringstream
s;
1297 s <<
"total_pre " << channel.GetIdMessage();
1298 Dump(totalPulseFunPre, s.str());
1303 fLog(
"Generating after-front-end total pulse.", 3);
1306 const float rightMargin = 0.2;
1308 TPad pad1(
"pad1",
"", 0, 0, 1, 1);
1309 pad1.SetFrameBorderMode(0);
1310 pad1.SetFillColor(0);
1311 pad1.SetRightMargin(rightMargin);
1323 fLog(
"Total pulse.", 3);
1324 std::stringstream totalPulseNamePost;
1325 totalPulseNamePost <<
"totalPulsePost_"
1329 TF1 totalPulseFunPost(totalPulseNamePost.str().c_str(),
1330 & totalPulsePostFrontEnd,
1334 totalPulseFunPost.SetLineColor(kBlack);
1335 totalPulseFunPost.SetLineWidth(2);
1336 totalPulseFunPost.SetLineStyle(1);
1337 totalPulseFunPost.SetFillColor(canvas.GetFillColor());
1339 totalPulseFunPost.GetYaxis()->SetTitleOffset(1.2);
1340 totalPulseFunPost.Draw();
1343 fLog(
"Discrimination level [", 3)
1346 TF1 thresFun(
"Discrimination level",
1351 thresFun.SetLineColor(kBlack);
1352 thresFun.SetLineStyle(2);
1353 thresFun.SetLineWidth(1);
1355 thresFun.SetFillColor(canvas.GetFillColor());
1356 thresFun.Draw(
"same");
1359 fLog(
"Discriminator output.", 3);
1361 TPad pad2(
"pad2",
"", 0, 0, 1, 1);
1362 pad2.SetRightMargin(rightMargin);
1363 pad2.SetFillStyle(0);
1364 pad2.SetFillColor(0);
1365 pad2.SetFrameFillStyle(4000);
1366 pad2.SetFrameBorderMode(0);
1367 pad2.SetFrameFillColor(0);
1370 ProxyFunctor<mdet::Channel::Discriminator> discriminatorFunctor(
1372 TF1 discrimFun(
"Discriminator output",
1373 & discriminatorFunctor,
1377 discrimFun.SetLineColor(kBlue);
1379 discrimFun.SetLineStyle(2);
1380 discrimFun.SetLineWidth(1);
1381 discrimFun.SetFillColor(canvas.GetFillColor());
1383 discrimFun.GetYaxis()->SetNdivisions(4);
1385 discrimFun.GetYaxis()->SetTitleOffset(1.4);
1408 discrimFun.Draw(
"Y+");
1410 discrimFun.GetXaxis()->SetLabelSize(0);
1419 const double trueLevel = discrimFun.GetMaximum();
1421 TVectorD samplesArray(nBinsTrace);
1424 for (
unsigned int i = 0; i < nBinsTrace; ++i)
1425 samplesArray[i] = trace[i] ? trueLevel : 0;
1443 TVectorD sampleTimes_vec;
1444 sampleTimes_vec.Use(sampleTimes.size(),&(sampleTimes[0]));
1445 TGraph samples(sampleTimes_vec, samplesArray);
1446 samples.SetMarkerColor(kRed);
1447 samples.SetMarkerStyle(kFullSquare);
1448 samples.SetFillStyle(0);
1449 samples.SetFillColor(canvas.GetFillColor());
1450 samples.SetLineColor(canvas.GetFillColor());
1453 totalPulseFunPost.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1454 totalPulseFunPost.GetYaxis()->SetTitle(
1456 discrimFun.GetYaxis()->SetTitle(
1463 leg.SetNColumns( 3 );
1464 leg.SetEntrySeparation( 0.8 );
1469 leg.SetY1NDC( 1 -
fStyle->GetPadTopMargin() );
1471 leg.SetBorderSize( 0 );
1472 leg.SetTextFont(
fStyle->GetTitleFont() );
1473 leg.SetTextSize(
fStyle->GetTitleSize()+0.01 );
1475 leg.AddEntry(&totalPulseFunPost,
"Analogical pulse",
"L");
1476 leg.AddEntry(&discrimFun,
"Discriminator pulse",
"L");
1477 leg.AddEntry(&samples,
"Digital samples",
"P");
1478 leg.SetFillColor(canvas.GetFillColor());
1482 std::stringstream
s;
1483 s <<
"total_post " << channel.GetIdMessage();
1484 Dump(totalPulseFunPost, s.str());
1490 totalPulsePreFrontEnd.fAbs =
true;
1491 totalPulsePostFrontEnd.fAbs =
true;
1495 const double minTimeMin = std::min(minTimePreFE, minTimePostFE) /
fUnits.
GetTimeUnit();
1497 fLog(
"Generating input/output comparison plot.", 3);
1499 TPad pad3(
"pad3",
"", 0, 0, 1, 1);
1500 pad3.SetFillColor(0);
1508 totalPulseFunPre.SetTitle(
"I/O");
1509 totalPulseFunPre.SetRange(minTimeMin, maxTimeMax);
1510 totalPulseFunPre.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1511 totalPulseFunPre.GetYaxis()->SetTitle(
1513 totalPulseFunPre.Draw();
1514 TPad pad4(
"pad4",
"", 0, 0, 1, 1);
1515 pad4.SetFillStyle(0);
1516 pad4.SetFillColor(0);
1517 pad4.SetFrameFillStyle(4000);
1518 pad4.SetFrameBorderMode(0);
1519 pad4.SetFrameFillColor(0);
1522 totalPulseFunPost.SetRange(minTimeMin, maxTimeMax);
1523 totalPulseFunPost.GetYaxis()->SetTitle(
1525 totalPulseFunPost.Draw(
"Y+");
1531 fLog(
"Generating frequency response plots.", 3);
1535 TGraph ampFreqResponse(freqArray, ampArray);
1536 ampFreqResponse.SetMarkerStyle(21);
1537 ampFreqResponse.Draw(
"AP");
1538 ampFreqResponse.SetTitle(
"Front-end transfer function amplitude response");
1540 ampFreqResponse.GetYaxis()->SetTitle(
1549 canvas.SetLogy(kFALSE);
1550 TGraph phaFreqResponse(freqArray, phaArray);
1551 phaFreqResponse.SetMarkerStyle(21);
1552 phaFreqResponse.Draw(
"AP");
1553 phaFreqResponse.SetTitle(
"Front-end transfer function phase response");
1555 phaFreqResponse.GetYaxis()->SetTitle((
"Phase (" +
fUnits.
GetAngleName() +
")").c_str());
1561 if (phaFreqResponse.GetN() > 1) {
1563 TGraphFunctor phaFreRespFunctor(phaFreqResponse);
1564 const double bFreq = phaFreqResponse.GetX()[0];
1565 const double eFreq = phaFreqResponse.GetX()[phaFreqResponse.GetN() - 1];
1566 TF1 phaFreqRespTF1(
"Phase", &phaFreRespFunctor, bFreq, eFreq, 1,
"");
1568 phaFreqRespTF1.SetLineStyle(2);
1570 double factor = -1.0;
1585 DerivativeFunctor derivative(phaFreqRespTF1, factor);
1586 TF1 delayRespTF1(
"Delay", &derivative, bFreq, eFreq, 1,
"");
1588 delayRespTF1.SetLineStyle(1);
1589 TPad pad5(
"pad5",
"", 0, 0, 1, 1);
1590 pad5.SetFillColor(0);
1591 pad5.SetFrameBorderMode(0);
1594 pad5.SetLogx(kTRUE);
1595 pad5.SetLogy(kFALSE);
1598 phaFreqRespTF1.Draw();
1599 TPad pad6(
"pad6",
"", 0, 0, 1, 1);
1600 pad6.SetFillStyle(0);
1601 pad6.SetFillColor(0);
1602 pad6.SetFrameFillStyle(4000);
1603 pad6.SetFrameBorderMode(0);
1604 pad6.SetFrameFillColor(0);
1605 pad6.SetLogx(kTRUE);
1606 pad6.SetLogy(kFALSE);
1609 delayRespTF1.Draw(
"Y+");
1610 phaFreqRespTF1.SetTitle(
"Phase and group delay");
1612 phaFreqRespTF1.GetYaxis()->SetTitle((
"Phase (" +
fUnits.
GetAngleName() +
")").c_str());
1613 delayRespTF1.GetYaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
1614 TLegend leg(0.65, 0.70, 0.85, 0.9);
1615 leg.AddEntry(&phaFreqRespTF1,
"Phase response");
1616 leg.AddEntry(&delayRespTF1,
"Group delay");
1627 TGraph fftPlotPre(freqArray, preFFT);
1628 fftPlotPre.SetMarkerStyle(21);
1629 fftPlotPre.SetMarkerColor(kBlue);
1630 fftPlotPre.Draw(
"AP");
1631 fftPlotPre.SetTitle(
"Fourier amplitude spectrum prior front-end");
1642 TGraph fftPlotPost(freqArray, postFFT);
1643 fftPlotPost.SetMarkerStyle(21);
1644 fftPlotPost.SetMarkerColor(kRed);
1645 fftPlotPost.Draw(
"AP");
1646 fftPlotPost.SetTitle(
"Fourier amplitude spectrum after front-end.");
1679 double& minTimePreFE,
1680 double& maxTimePreFE,
1681 double& analogicTraceStartTime,
1682 double& analogicTraceEndTime)
1689 traceAnalogical.ClearTrace();
1694 fLog(
"Trace size", 2)(nBinsTrace);
1697 if (si.
fSiPMPulses.empty() && ! isAnalogicTrace) {
1698 fLog(
"No pulses and other sim data found for channel", 1)(channel.
GetId());
1699 for (
unsigned int i = 0; i < nBinsTrace; ++i)
1708 const double pulseTimeSpan = maxTimePreFE-minTimePreFE;
1715 TimeTrace totalPulsePostDiscriminatorTrace;
1717 ApplyCITIROCTransfer(channel, si, pulseTimeSpan, minTimePreFE, analogicTraceStartTime, analogicTraceEndTime,
1718 totalPulsePostFrontEndTrace, totalPulsePostDiscriminatorTrace, traceAnalogical);
1724 SampleTrace(minTimePreFE, maxTimePreFE, pulseTimeSpan /
fNDiscretization, frontEnd, traceStart, totalPulsePostDiscriminatorTrace, trace);
1727 totalPulsePostFrontEndTrace, totalPulsePostDiscriminatorTrace, trace);
1739 double& analogicTraceStartTime,
double& analogicTraceEndTime){
1745 analogicTraceStartTime = 0;
1746 analogicTraceEndTime = 0;
1748 std::unique_ptr<utl::TabularStream> spanTable;
1749 const unsigned int pulseSpanLogLevel = 3;
1757 unsigned int nPE = 0;
1759 minTimePreFE = std::min(minTimePreFE, p->LowerLimit());
1760 maxTimePreFE =
std::max(maxTimePreFE, p->UpperLimit());
1769 if (isAnalogicTrace) {
1770 analogicTraceStartTime = (si.
fScintSimData->GetAnalogicTraceStartTime() - eventTime).GetInterval();
1773 minTimePreFE = std::min(minTimePreFE, analogicTraceStartTime);
1774 maxTimePreFE =
std::max(maxTimePreFE, analogicTraceEndTime);
1777 const double pulseTimeSpan = maxTimePreFE - minTimePreFE;
1784 fLog(
"PE pulses and other signals span:", pulseSpanLogLevel);
1785 fLog(spanTable->Str(), pulseSpanLogLevel);
1787 return pulseTimeSpan;
1798 double analogicTraceStartTime,
double analogicTraceEndTime,
TimeTrace& totalPulsePostFrontEndTrace,
1801 TotalPulseFunctor<SiPMPulseContainer> totalPulsePreFrontEnd(si.
fSiPMPulses,
1806 fLog(
"Applying FFT...", 3);
1818 fLog(
"Discretizing total pulses. Number of samples:", 3,
false);
1821 double time = minTimePreFE + i * binning;
1822 double value = totalPulsePreFrontEnd(time);
1823 if (isAnalogicTrace) {
1825 if (analogicTraceStartTime <= time && time <= analogicTraceEndTime) {
1827 double delta = time - analogicTraceStartTime;
1841 fLog(
"Applying transfer function in frequency spectrum.", 3);
1844 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
1846 fLog(
"Generating frequency response.", 3);
1847 const unsigned int tabFFTLogLevel = 4;
1848 std::unique_ptr<utl::TabularStream> tabFFT;
1861 fLog(tabFFT->Str(), tabFFTLogLevel);
1866 freqTrace[ freqBin ] *=
c;
1869 fLog(
"Obtaining the amplified pulses in time-space...", 3);
1878 double discriminatorOuput = channel.
ComputeDiscriminator(totalPulsePostFrontEndTrace[timeBin], binning);
1879 totalPulsePostDiscriminatorTrace.
PushBack(discriminatorOuput);
1893 fLog(
"Creating sampler object.", 3);
1898 std::vector<double> sampleTimes;
1900 fLog(
"Sampling pulses.", 3);
1901 const double startTime = traceStart.
GetInterval();
1902 const double stopTime = startTime +
1905 if (startTime < minTimePostFE) {
1906 fLog(
"Samples false in the range", 4)
1910 (
"as no signal in it.");
1912 fLog(
"Samples:", 4);
1914 for (
double sampleTime = startTime; trace.
GetSize() < nBinsTrace ||
fLog(
'\n', 4)(sampleTime);
1915 sampleTime += sRate) {
1918 if (sampleTime < minTimePostFE || maxTimePostFE < sampleTime) {
1921 int bin = (int)((sampleTime-minTimePostFE)/binning);
1922 double o = totalPulsePostDiscriminatorTrace[bin];
1928 sampleTimes.push_back(sampleTime);
1931 if (maxTimePostFE < stopTime) {
1933 fLog(
"Samples false in the range ", 4)
1937 (
"as no signal in it.");
1956 unsigned short limit = std::min(width+bin, (
int)trace.
GetSize());
1958 for(
short i = bin; i<limit; i++){
1976 TVectorD analogicalTime(traceAnalogical.
GetSize());
1977 TVectorD traceAnalogicalVec(traceAnalogical.
GetSize());
1978 TVectorD totalPulsePostFrontEndVec(traceAnalogical.
GetSize());
1979 TVectorD totalPulsePostDiscriminatorVec(traceAnalogical.
GetSize());
1982 TVectorD digitalTime(trace.
GetSize());
1983 TVectorD traceFPGA(trace.
GetSize());
1986 const double discriminatorHiLevel = 3.0;
1988 for(
unsigned int i=0; i<traceAnalogical.
GetSize(); i++){
1989 analogicalTime[i] = (i*binning + minTimePreFE);
1990 traceAnalogicalVec[i] = -1*traceAnalogical[i];
1991 totalPulsePostFrontEndVec[i] = totalPulsePostFrontEndTrace[i];
1992 totalPulsePostDiscriminatorVec[i] = totalPulsePostDiscriminatorTrace[i];
1995 for(
unsigned int i=0; i<trace.
GetSize(); i++){
1996 digitalTime[i] = (i*sRate + traceStartTime);
1997 traceFPGA[i] = ((double)trace[i]*discriminatorHiLevel);
2001 fLog(
"Generating plots.", 3);
2003 std::stringstream canvasName;
2008 TCanvas canvas(canvasName.str().c_str() ,
"Channel Output", 200, 10, 700, 500);
2011 canvas.SetBorderMode(0);
2012 canvas.SetFillColor(0);
2013 canvas.SetFrameBorderMode(0);
2017 TGraph totalPulsePrePlot(analogicalTime, traceAnalogicalVec);
2018 totalPulsePrePlot.SetLineWidth(3);
2019 totalPulsePrePlot.SetLineColor(kBlue);
2021 TGraph pulsePostFrontEndPlot(analogicalTime, totalPulsePostFrontEndVec);
2022 pulsePostFrontEndPlot.SetLineWidth(3);
2023 pulsePostFrontEndPlot.SetLineColor(kOrange);
2025 TGraph pulsePostDiscriminatorPlot(analogicalTime, totalPulsePostDiscriminatorVec);
2026 pulsePostDiscriminatorPlot.SetLineWidth(3);
2027 pulsePostDiscriminatorPlot.SetLineColor(kBlack);
2029 TGraph pulsePostFPGAPlot(digitalTime, traceFPGA);
2030 pulsePostFPGAPlot.SetMarkerColor(kRed);
2031 pulsePostFPGAPlot.SetMarkerStyle(29);
2032 pulsePostFPGAPlot.SetMarkerSize(1.2);
2034 pulsePostFPGAPlot.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
2039 pulsePostFPGAPlot.Draw(
"AP");
2040 pulsePostFrontEndPlot.Draw(
"SAME");
2041 totalPulsePrePlot.Draw(
"SAME");
2042 pulsePostDiscriminatorPlot.Draw(
"SAME");
2045 leg.SetNColumns( 3 );
2046 leg.SetEntrySeparation( 0.8 );
2051 leg.SetY1NDC( 1 -
fStyle->GetPadTopMargin() );
2053 leg.SetBorderSize( 0 );
2054 leg.SetTextFont(
fStyle->GetTitleFont() );
2055 leg.SetTextSize(
fStyle->GetTitleSize()+0.01 );
2057 leg.AddEntry(&totalPulsePrePlot,
"SiPM pulse",
"L");
2058 leg.AddEntry(&pulsePostFrontEndPlot,
"Fast Shaper output",
"L");
2059 leg.AddEntry(&pulsePostDiscriminatorPlot,
"Discriminator output",
"L");
2060 leg.AddEntry(&pulsePostFPGAPlot,
"FPGA samples",
"P");
2061 leg.SetFillColor(canvas.GetFillColor());
2086 std::vector<utl::TraceD> analogicalTraces,
2090 double& minTimePreFE,
2091 double& maxTimePreFE)
2099 traceIntegratorA.ClearTrace();
2100 traceIntegratorB.ClearTrace();
2101 traceIntegratorA.
SetBinning(sRateIntegrator);
2102 traceIntegratorB.
SetBinning(sRateIntegrator);
2105 fLog(
"Trace size", 2)(nBinsTrace);
2106 if (analogicalTraces.empty()) {
2107 fLog(
"No pulses data for this module", 2)(module.
GetId());
2108 for (
unsigned int i = 0; i < nBinsTrace; ++i){
2114 for(
unsigned int i = 0; i<analogicalTraces.size(); i++){
2116 fLog(
"Channel traces are corrupted", 1)(module.
GetId());
2132 ApplyBackEndTransfer(backEnd, maxTimePreFE, minTimePreFE, traceAfterADCLowGain, traceAfterADCHighGain, totalAnalogicalInput, analogicalTraces);
2140 SampleTraceADC(minTimePreFE, maxTimePreFE, frontEnd, traceStart, traceAfterADCLowGain, traceAfterADCHighGain, traceIntegratorA, traceIntegratorB);
2142 frontEnd, totalAnalogicalInput, traceAfterADCLowGain, traceAfterADCHighGain, traceIntegratorA, traceIntegratorB);
2155 TimeTrace& traceAfterADCLowGain,
TimeTrace& traceAfterADCHighGain, TVectorD& totalAnalogicalInput,
const std::vector<utl::TraceD> analogicalTraces){
2157 fLog(
"Applying FFT Integrator...", 3);
2165 int nroChannels = analogicalTraces.size();
2166 double nroOfAdders = nroChannels/numberOfChannelsToGroup;
2168 std::vector<TimeTrace> tracesPostFirstAdder;
2169 for (
int adder = 0; adder < nroOfAdders; adder++) {
2171 int fromChannel = adder*numberOfChannelsToGroup;
2172 int toChannel = (adder+1)*numberOfChannelsToGroup;
2173 toChannel = std::min(toChannel, nroChannels);
2174 fLog(
"Adding pulses. From/To channel:", 3)(fromChannel)(toChannel);
2183 for (
int channel = fromChannel; channel < toChannel; channel++) {
2184 value += analogicalTraces[channel][i];
2187 totalAnalogicalInput[i] += value;
2192 fLog(
"Obtaining the amplified pulses in time-space...", 3);
2200 for(
unsigned int adder = 0; adder < tracesPostFirstAdder.size(); adder++){
2219 tracePreHGChannel.
PushBack(tracePreLGChannel[i]);
2252 TimeTrace& traceAfterADCLowGain,
TimeTrace& traceAfterADCHighGain, TVectorD& totalAnalogicalInput,
const std::vector<utl::TraceD> analogicalTraces){
2253 fLog(
"Applying FFT Integrator...", 3);
2260 int nroChannels = analogicalTraces.size();
2269 for (
int channel = 0; channel < nroChannels; channel++) {
2270 value += analogicalTraces[channel][i];
2273 totalAnalogicalInput[i] += value;
2304 fLog(
"Applying transfer function in frequency space.",3);
2307 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
2309 fLog(
"Generating frequency response.",3);
2310 const unsigned int tabFFTLogLevel = 4;
2311 std::unique_ptr<utl::TabularStream> tabFFT;
2324 fLog(tabFFT->Str(),tabFFTLogLevel);
2331 freqTrace[freqBin] *=
c;
2346 fLog(
"Applying transfer function in frequency space.",3);
2350 const double freqBinning = fft.GetConstFrequencySpectrum().GetBinning();
2353 fLog(
"Generating frequency response.",3);
2354 const unsigned int tabFFTLogLevel = 4;
2355 std::unique_ptr<utl::TabularStream> tabFFT;
2368 fLog(tabFFT->Str(),tabFFTLogLevel);
2375 freqTraceHG.
PushBack(freqTrace[freqBin]*cHG);
2376 freqTrace[freqBin] *= cLG;
2397 fLog(
"Sampling pulses.", 3);
2398 const double startTime = traceStart.
GetInterval();
2399 const double stopTime = startTime + sRate * nBinsTrace;
2401 if (startTime + delayBinaryADC < minTimePostFE) {
2402 fLog(
"Samples false in the range", 4)
2406 (
"as no signal in it.");
2408 fLog(
"Samples:", 4);
2410 double chargeLG = 0.0;
2411 double chargeHG = 0.0;
2414 for (
double sampleTime = startTime; traceIntegratorA.
GetSize() < nBinsTrace ||
fLog(
'\n', 4)(sampleTime);
2415 sampleTime += sRate) {
2417 unsigned short adcLG;
2418 unsigned short adcHG;
2420 if (sampleTime < minTimePostFE + delayBinaryADC || maxTimePostFE + delayBinaryADC < sampleTime) {
2425 int bin = (int)((sampleTime-minTimePostFE-delayBinaryADC)/binning);
2426 double signal1 = traceAfterADCLowGain[bin];
2427 double signal2 = traceAfterADCHighGain[bin];
2430 chargeLG += adcLG-offsetLG;
2431 chargeHG += adcHG-offsetHG;
2444 if (maxTimePostFE < stopTime) {
2446 fLog(
"Samples false in the range ", 4)
2450 (
"as no signal in it.");
2458 TVectorD& traceAnalogical,
TimeTrace& traceIntegratorAAmplifier,
TimeTrace& traceIntegratorBAmplifier,
2466 TVectorD traceIntegratorAVec(traceIntegratorA.
GetSize());
2467 TVectorD traceIntegratorBVec(traceIntegratorB.
GetSize());
2468 TVectorD traceIntegratorAVecAnalog(traceIntegratorAAmplifier.
GetSize());
2469 TVectorD traceIntegratorBVecAnalog(traceIntegratorBAmplifier.
GetSize());
2470 TVectorD analogicalTime(traceAnalogical.GetNoElements());
2471 TVectorD digitalTime(traceIntegratorA.
GetSize());
2475 for(
int i=0; i<traceAnalogical.GetNoElements(); i++){
2476 analogicalTime[i] = (i*binning + minTimePreFE);
2477 traceIntegratorAVecAnalog[i] = (double)traceIntegratorAAmplifier[i];
2478 traceIntegratorBVecAnalog[i] = (double)traceIntegratorBAmplifier[i];
2481 for(
unsigned int i=0; i<traceIntegratorA.
GetSize(); i++){
2482 digitalTime[i] = (i*sRate + traceStartTime);
2483 traceIntegratorAVec[i] = ((double)traceIntegratorA[i]);
2484 traceIntegratorBVec[i] = ((double)traceIntegratorB[i]);
2488 fLog(
"Generating plots.", 3);
2490 std::stringstream canvasName;
2495 TCanvas canvas(canvasName.str().c_str() ,
"Integrator", 200, 10, 700, 500);
2498 canvas.SetBorderMode(0);
2499 canvas.SetFillColor(0);
2500 canvas.SetFrameBorderMode(0);
2504 TGraph inputSiPM(analogicalTime, traceAnalogical);
2505 inputSiPM.SetLineWidth(3);
2506 inputSiPM.SetLineColor(kBlue);
2508 TGraph traceIntegratorAPlot(digitalTime, traceIntegratorAVec);
2509 traceIntegratorAPlot.SetLineWidth(3);
2510 traceIntegratorAPlot.SetLineColor(kRed);
2511 traceIntegratorAPlot.SetMarkerStyle(31);
2513 TGraph traceIntegratorBPlot(digitalTime, traceIntegratorBVec);
2514 traceIntegratorBPlot.SetLineWidth(3);
2515 traceIntegratorBPlot.SetLineColor(kOrange);
2516 traceIntegratorBPlot.SetMarkerStyle(31);
2518 TGraph traceIntegratorAAnalogPlot(analogicalTime, traceIntegratorAVecAnalog);
2519 traceIntegratorAAnalogPlot.SetLineWidth(3);
2520 traceIntegratorAAnalogPlot.SetLineColor(kRed);
2521 traceIntegratorAAnalogPlot.SetMarkerStyle(31);
2523 TGraph traceIntegratorBAnalogPlot(analogicalTime, traceIntegratorBVecAnalog);
2524 traceIntegratorBAnalogPlot.SetLineWidth(3);
2525 traceIntegratorBAnalogPlot.SetLineColor(kOrange);
2526 traceIntegratorBAnalogPlot.SetMarkerStyle(31);
2528 traceIntegratorBPlot.GetXaxis()->SetTitle((
"Time (" +
fUnits.
GetTimeName() +
")").c_str());
2529 traceIntegratorBPlot.GetYaxis()->SetTitle(
"Signal (ADC Counts)");
2533 traceIntegratorBPlot.Draw(
"APL");
2534 traceIntegratorAPlot.Draw(
"SAMEPL");
2535 inputSiPM.Draw(
"SAME");
2536 traceIntegratorAAnalogPlot.Draw(
"SAME");
2537 traceIntegratorBAnalogPlot.Draw(
"SAME");
2540 leg.SetNColumns( 3 );
2541 leg.SetEntrySeparation( 0.8 );
2546 leg.SetY1NDC( 1 -
fStyle->GetPadTopMargin() );
2548 leg.SetBorderSize( 0 );
2549 leg.SetTextFont(
fStyle->GetTitleFont() );
2550 leg.SetTextSize(
fStyle->GetTitleSize()+0.01 );
2552 leg.AddEntry(&inputSiPM,
"SiPM input",
"L");
2553 leg.AddEntry(&traceIntegratorAPlot,
"ADC LG",
"L");
2554 leg.AddEntry(&traceIntegratorBPlot,
"ADC HG",
"L");
2555 leg.SetFillColor(canvas.GetFillColor());
2580 bool isSiPM = module.
IsSiPM();
2582 for (SignalsMap::const_iterator i = sm.begin(), fpe = sm.end(); i != fpe; ++i) {
2583 SignalsMap::key_type pixelId = i->first;
2594 fLog(
"Simulating PMT-electronic channel:", 2)(channel.
GetId())(
"...");
2605 fLog(
"Trace start at", 3)(start)(
"...");
2607 fLog(
"Total analog particle pulse over-threshold time span", 3)
2618 std::vector<utl::TraceD> analogicalTraces;
2619 double minTimePreFE;
2620 double maxTimePreFE;
2621 double analogicTraceStartTime;
2622 double analogicTraceEndTime;
2625 for (SignalsMap::const_iterator i = sm.begin(), fpe = sm.end(); i != fpe; ++i) {
2626 double minTimeSignal;
2627 double maxTimeSignal;
2628 double analogicTraceStartTimePEs;
2629 double analogicTraceEndTimePEs;
2630 GetPulseTimeSpan(i->second, eventTime, minTimeSignal , maxTimeSignal , analogicTraceStartTimePEs , analogicTraceEndTimePEs);
2631 minTimePreFE = std::min(minTimePreFE, minTimeSignal);
2632 maxTimePreFE =
std::max(maxTimePreFE, maxTimeSignal);
2633 analogicTraceStartTime = std::min(analogicTraceStartTime, analogicTraceStartTimePEs);
2634 analogicTraceEndTime =
std::max(analogicTraceEndTime, analogicTraceEndTimePEs);
2637 for (SignalsMap::const_iterator i = sm.begin(), fpe = sm.end(); i != fpe; ++i) {
2638 SignalsMap::key_type pixelId = i->first;
2643 fLog(
"Simulating SiPM-electronic channel:", 2)(channel.
GetId())(
"...");
2653 startTimeTrace = start;
2654 fLog(
"Trace start at", 3)(start)(
"...");
2655 ProcessPulses(channel, i->
second, trace, traceAnalogical, span, start - eventTime, minTimePreFE, maxTimePreFE, analogicTraceStartTime, analogicTraceEndTime);
2657 fLog(
"Total analog particle pulse over-threshold time span", 2)
2660 analogicalTraces.push_back(traceAnalogical);
2675 if(analogicalTraces.size()>0){
2686 fLog(
"Generating integrator traces", 2);
2687 ProcessPulsesIntegrator(module, analogicalTraces, traceIntegratorA, traceIntegratorB, startTimeTrace - eventTime, minTimePreFE, maxTimePreFE);
2704 ERROR(
"SEvent does not exist.");
2712 std::ostringstream message;
2713 message <<
"partner station with id " << partnerId <<
"was not found in SEvent\n";
2719 const sdet::Station& detStation = det::Detector::GetInstance().GetSDetector().GetStation(sStation);
2735 std::cout <<
"IsT1 " << trig.IsT1() <<
" - " <<
"IsT2 " << trig.IsT2() << std::endl;
2737 if (!(trig.IsT2() || trig.IsT1()))
2744 if (trigTime < firstT1Sd) {
2745 std::cout <<
"There is a previous trigger\n";
2746 firstT1Sd = trigTime;
2748 std::cout <<
"Trigger time: " << trigTime << std::endl;
2757 utl::TimeStamp eventTime =
event.GetSEvent().GetHeader().GetTime();
2763 firstT1Sd = eventTime;
2768 TstartTrace = firstT1Sd - shift;
2770 T1 = TstartTrace - eventTime;
2771 std::cout <<
"eventTime " << eventTime << std::endl;
2772 std::cout <<
"T1 " << T1 << std::endl;
2773 std::cout <<
"firstT1Sd " << firstT1Sd << std::endl;
2774 std::cout <<
"TstartTrace " << TstartTrace << std::endl;
2775 std::cout <<
"shift " << shift << std::endl;
2780 const int mId = mIt->GetId();
2794 if (!mIt->HasChannel(ch->GetId()))
2795 mIt->MakeChannel(ch->GetId());
2810 fun.GetRange(min, max);
2816 double xWhole = min + i * stepWhole;
2817 double xWindow = min + i * stepWindow;
2821 << fun.Eval(xWhole) <<
'\t'
2823 << fun.Eval(xWindow)
2837 std::stringstream fmt;
2838 for(
unsigned int i = 0; i < nCol; ++i)
2847 fLog.ApplyConfigurationOn(*pt);
const Point & GetEnd() const
Return the final point.
bool fTogglePlotFftPostAmp
AtThresholdConstIterator AtThresholdBegin() const
Begin iterator over times.
unsigned int fStepSPE
Step size for spe iteration.
virtual void InjectDigitalNoise(const mdet::Module &module, mevt::Module &evtModule)
const BackEndSiPM & GetBackEndSiPM() const
virtual VModule::ResultFlag SimulatePulses(const mdet::Scintillator &scint, const mevt::ScintillatorSimData &ssd, mevt::ScintillatorSimData &ssd_nonconst, SignalsMap &sm)
Perform the simulation given the particles in the scintillator.
double GetAmplitude2() const
Station Level Simulated Data
void MakeChannel(const int cId)
const std::string & GetElectricResistanceName() const
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
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
virtual void ApplyCITIROCTransfer(const mdet::ChannelSiPM &channel, const SignalInformation &si, const double pulseTimeSpan, double minTimePreFE, double analogicTraceStartTime, double analogicTraceEndTime, TimeTrace &totalPulsePostFrontEndTrace, TimeTrace &totalPulsePostDiscriminatorTrace, utl::TraceD &traceAnalogical)
const Pixel & GetPixel(int pId) const
bool IntersectedBy(const utl::Line &line) const
Answers if line crosses the body of the Scintillator.
const Counter & GetCounter() const
The parent counter.
boost::indirect_iterator< InternalConstParticleIterator, const utl::Particle & > ConstParticleIterator
bool HasStation(const int stationId) const
Check whether station exists.
double GetSampleTimeADC() const
ADC Sample Time and delay.
unsigned int fNBinsHistograms
Number of bins for histograms.
utl::MessageLoggerConfig fLog
Output messages handler.
const TimeInterval & GetTime() const
Arrival time delay at the ground.
double GetFallTime3() const
Detector description interface for Station-related data.
Report success to RunController.
double GetHighGainAmplifierOffset() const
bool HasIntegratorBTrace() const
static EnumType Create(const int k)
int version of the overloaded creation method.
double ComputeDiscriminator(double signal, double deltaTime) const
double GetLengthUnit() const
bool fTogglePlotchannelPulses
double GetFallTime2() const
unsigned int ComputeSPENumber(double x, double l, double e) const
Computes a number of SPE given the impinging distance, the length of the track and the energy of the ...
ChannelGroup::ConstIterator ChannelConstIterator
Convenience typedef for const iterator over the contained mdet::Channel instances.
unsigned int fNDiscretization
Discretization over the continuous functions.
static const char *const kSimulationTypeTags[]
Tags for the types of simulation.
short GetInjectDigitalNoiseBin() const
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)
Interface class to access to the SD part of an event.
Describes a particle for Simulation.
unsigned short GetADCBaseLineFluctuationLG() const
Noise injection for binary and ADC channels.
virtual void SampleTrace(double minTimePostFE, double maxTimePostFE, double binning, const mdet::FrontEndSiPM &frontEnd, const utl::TimeInterval &traceStart, TimeTrace &totalPulsePostDiscriminatorTrace, utl::TraceB &trace)
double GetFallTime1() const
double ApplySaturation(double value, TransferStep step) const
int GetTriggerTimeFromSD(evt::Event &, const mdet::Counter &, mevt::MEvent::CounterIterator, double &)
Retrieve T1 time from associated SD tank.
void AddSPEPulse(const double mu, const double sigma, const double amplitude, const int destPixelId)
const std::string & GetLengthName() const
double fPulseSampleWindow
Define the length of the window within which the pulse is sampled.
unsigned int fNumPlotPoints
Number of points to be used in plotting (theoretically) continuous functions.
bool fIncludeBaseLineFluctuationIntegrator
To simulate baseline fluctuation in the integrator output.
unsigned int fRunNumber
Tracks the number of runs.
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.
PhotonTimeContainer::const_iterator ConstPhotonTimeIterator
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Local system based on position and configured rotations.
unsigned short GetInjectDigitalNoiseWidth() const
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)
double GetBinning() const
size of one slot
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)
const Fiber & GetFiberFor(const Component &c) const
Linking between fibers, scintillators, channels and pixels.
#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.
bool fGeneratePreFETotalPulseOutput
To include the total pulse prior front-end in the output file.
Electronic front-end for the modules.
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)
VModule::ResultFlag RunFromMEventScintillatorSimulated(evt::Event &e)
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.
const std::string & GetAlgorithmName() const
double GetStartTime() const
bool fToggleTransferPhaseResponse
VModule::ResultFlag Run(evt::Event &e)
Run: invoked once per event.
std::map< int, SignalInformation > SignalsMap
Map associating the information with IDs (meant to be from pixel's).
unsigned int fMinSPE
Minimum number of spe (inclusive).
Detector associated to muon detector hierarchy.
double Distance(const Line &line1, const Line &line2)
void SetElectricCurrentDefault(const double unit, const std::string &name)
double GetLength() const
Return the length of the segment (ie the distance between begin and end).
Electronic front-end for the modules.
double GetLowGainAmplifierOffset() const
A TimeStamp holds GPS second and nanosecond for some event.
const SiPMArray & GetSiPMArray() const
utl::TraceD & GetAnalogicTrace()
Return the trace of current pulse signal prior to the electronic amplification stage.
Actual muon-sensitive objects.
std::string fPulseFilename
Pulse output file filename.
std::vector< std::string > fPlotFileExtensions
File extensions for plots (dot included).
bool fInjectNoiseBinary
To inject noise in binary traces.
Sampler MakeSampler() const
Create a new sampler object.
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
ChannelConstIterator ChannelsBegin() const
Begin iterator over the contained channels.
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.
Class describing a Plane object.
C< F > & GetFrequencySpectrum()
read out the frequency spectrum (write access)
utl::UnitsConfig fUnits
Units configuration.
double GetX(const CoordinateSystemPtr &coordinateSystem) const
unsigned int fNRepetitions
Repetitions for in-module loop.
std::vector< double >::size_type SizeType
const PMT & GetPMT() const
bool fForcedSDTrigger
Ignore WCD trigger condition.
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.
PhotonTimeIterator PhotonTimesBegin()
double GetRiseTime() 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)
double abs(const SVector< n, T > &v)
virtual void ProcessPulses(const mdet::Channel &c, const SignalInformation &signalInfo, utl::TraceB &trace, double &span, const utl::TimeInterval &traceStart, const utl::TimeStamp &eventTime)
Process: analyze, electronic simulation and sampling.
virtual void ApplyTransferBlock(utl::FFTDataContainer< utl::Trace, TimeTrace::ValueType, FrequencyTrace::ValueType > &fft, const mdet::BackEndSiPM &backEnd, BackEndSiPM::TransferStep step)
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
VModule::ResultFlag Finish()
Finish: invoked at end of the run (NOT end of the event)
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
const Point & GetBegin() const
Return the initial point.
void SetLengthDefault(const double unit, const std::string &name)
Channel & GetChannel(const int cId)
virtual double GetPulseTimeSpan(const SignalInformation &si, const utl::TimeStamp &eventTime, double &minTimePreFE, double &maxTimePreFE, double &analogicTraceStartTime, double &analogicTraceEndTime)
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.
double GetElectricCurrentUnit() const
class to format data in tabular form
IntegratorSimulationType fIntegratorSimType
Type of integrator simulation. Step by step simulates the complete transfer functions and applies sat...
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.
utl::TraceUSI & GetIntegratorATrace()
bool HasIntegratorATrace() const
bool HasChannel(const int cId) const
void MakeIntegratorATrace()
void SetTimeDefault(const double unit, const std::string &name)
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)
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.
bool fIgnoreCrossTalk
Ignore cross-talk effects.
double GetInterval() const
Get the time interval as a double (in Auger base units)
Root detector of the muon detector hierarchy.
VModule::ResultFlag Init()
Initialize: invoked at beginning of run (NOT beginning of event)
bool fToggleTransferAmpResponse
const std::string & GetElectricCurrentName() const
static const char *const kIntegratorSimulationTypeTags[]
Tags for the types of integrator simulation.
void SetBinning(const double binning)
double GetY(const CoordinateSystemPtr &coordinateSystem) const
constexpr double kSpeedOfLight
Template class for a data container that offers and takes both time series and corresponding frequenc...
Scintillator level simulation data.
A TimeInterval is used to represent time elapsed between two events.
ResultFlag
Flag returned by module methods to the RunController.
VModule::ResultFlag RunFromMEvent(evt::Event &e)
Run for the eFromEvent enumeration.
double GetWeight() const
Particle weight (assigned by shower generator thinning algorithms)
double GetFADCBinSize() const
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)
std::set< ParticleType > fAllowedParticleTypes
Particle types that are considered to generate signal, if empty then every kind of particle is allowe...
InternalCounterCollection::ComponentIterator CounterIterator
utl::Segment ComputeIntersectionWith(const utl::Line &line) const
Computes the intersection of line within the Scintillator.
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
double GetElectricResistanceUnit() const
AtThresholdConstIterator AtThresholdEnd() const
End iterator over times.
const FrontEndSiPM & GetFrontEndSiPM() const
PhotonTimeIterator PhotonTimesEnd()
const Module & GetModule() const
Retrieve the parent mdet::Module.
void SetElectricPotentialDefault(const double unit, const std::string &name)
struct particle_info particle[80]
Channel level event data.
bool fPlotTransferPhaseResponse
InternalScintillatorCollection::ComponentIterator ScintillatorIterator
double GetDepth() const
The depth of the origin of the module. This quantity is positive for an underground module...
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
TriggerTimeIterator TriggerTimesEnd() const
End of simulated local trigger times list.
const std::string & GetTimeName() const
const Point & GetPosition() const
Position of the particle.
Report failure to RunController, causing RunController to terminate execution.
CounterConstIterator CountersEnd() const
ParticleIterator ParticlesEnd()
std::ofstream fPulseFile
Associated stream.
SimulationType fSimType
Type of simulation.
PE MakePEAt(double t) const
Constructs an PE according to this SiPM characteristics.
unsigned int GetFADCTraceLength() const
double ComputeDecayDelay() const
Computes a delay due to decay process.
sevt::StationSimData & GetSimData()
Get simulated data at station level.
bool fPlotTransferAmpResponse
void MakeIntegratorBTrace()
const std::string & GetFrequencyName() const
double ComputeDecayDelay() const
Computes a delay due to decay process.
int GetId() const
The id of this component.
unsigned int fMaxSPE
Maximum number of spe (inclusive).
double GetAmplitude1() const
bool fGeneratePostFETotalPulseOutput
To include the total pulse after front-end in the output file.
unsigned int fNPulseSamples
Number of samples to use in the output files for pulses.
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.
const std::string & GetElectricPotentialName() const
ParticleIterator ParticlesBegin()
double GetTimeUnit() const
utl::TraceUSI & GetIntegratorBTrace()
double GetAmplitude3() const
double GetZ(const CoordinateSystemPtr &coordinateSystem) const
const Module & GetModule() const
The module to which this FrontEnd belongs.
Optical mdet::Fiber used to conect mdet::Scintillator to mdet::Pixel.
double mod(const double d, const double periode)
const Scintillator & GetScintillator(int sId) const
Direct accesor by id.
unsigned short GetADCBaseLineFluctuationHG() const
bool HasAnalogicTrace() const
const Counter & GetCounter(int id) const
Retrieve Counter by id.
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
const Vector & GetDirection() const
Unit vector giving particle direction.
SPE MakeSPEAt(const double t) const
Constructs an SPE according to this pixel's characteristics.
const std::string & GetAngleName() const
double GetThreshold() const
Discrimination threshold.
Root of the Muon event hierarchy.
bool fGenerateSPEPulseOutput
To include individual pulses samples in the output file.
ChannelConstIterator ChannelsEnd() const
End iterator over the contained channels.
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)
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)
const Vector & GetDirection() const
Return the (normalized) direction vector.
double GetRefractionIndex() const
The refraction (or refractive) index of the fiber.
unsigned short GetInjectDigitalNoiseChannel() const
double GetOnManifoldLength() const
The length of the fiber along the path that joins the scintillator to its pixel on the PMT...
A segment joins two points.
void Dump(const TF1 &fun, const std::string &suffix)
Helper to dump a TF1 to the configured file.