From 3597b340c379703df90bbb1e65e2cbe3df653a78 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 28 Sep 2018 16:24:40 +0100 Subject: [PATCH 001/140] ++ --- src/ants2.pro | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ants2.pro b/src/ants2.pro index 363a11a8..519b9204 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -4,10 +4,10 @@ ANTS2_MINOR = 12 #Optional libraries #CONFIG += ants2_cuda #enable CUDA support - need NVIDIA GPU and drivers (CUDA toolkit) installed! -CONFIG += ants2_flann #enable FLANN (fast neighbour search) library: see https://github.com/mariusmuja/flann -CONFIG += ants2_fann #enables FANN (fast neural network) library: see https://github.com/libfann/fann +#CONFIG += ants2_flann #enable FLANN (fast neighbour search) library: see https://github.com/mariusmuja/flann +#CONFIG += ants2_fann #enables FANN (fast neural network) library: see https://github.com/libfann/fann CONFIG += ants2_eigen3 #use Eigen3 library instead of ROOT for linear algebra - highly recommended! Installation requires only to copy files! -CONFIG += ants2_RootServer #enable cern CERN ROOT html server +#CONFIG += ants2_RootServer #enable cern CERN ROOT html server #CONFIG += ants2_Python #enable Python scripting #CONFIG += ants2_NCrystal #enable NCrystal library (neutron scattering) @@ -725,8 +725,8 @@ RC_FILE = myapp.rc #---Optimization of compilation--- win32 { #uncomment the next two lines to disable optimization during compilation. It will drastically shorten compilation time, but there are performance loss, especially strong for LRF computation - QMAKE_CXXFLAGS_RELEASE -= -O2 - QMAKE_CXXFLAGS_RELEASE *= -Od + #QMAKE_CXXFLAGS_RELEASE -= -O2 + #QMAKE_CXXFLAGS_RELEASE *= -Od } linux-g++ || unix { QMAKE_CXXFLAGS += -march=native From e435dfe35a7b36115ee1840d182def0b26035995 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 29 Sep 2018 23:38:23 +0100 Subject: [PATCH 002/140] starting optical override overhaul --- src/ants2.pro | 23 +- src/common/aopticaloverride.cpp | 67 ++++- src/common/aopticaloverride.h | 13 +- src/gui/MainWindowTools/MainWindowTests.cpp | 3 - .../aopticaloverridedialog.cpp | 95 +++++++ .../MainWindowTools/aopticaloverridedialog.h | 46 ++++ .../MainWindowTools/aopticaloverridedialog.ui | 250 ++++++++++++++++++ src/gui/mainwindow.cpp | 20 ++ src/gui/mainwindow.h | 2 + src/gui/mainwindow.ui | 19 +- src/modules/amaterialparticlecolection.cpp | 8 + src/modules/amaterialparticlecolection.h | 2 + src/modules/phscatclaudiomodel.cpp | 181 ------------- src/modules/phscatclaudiomodel.h | 15 -- 14 files changed, 521 insertions(+), 223 deletions(-) create mode 100644 src/gui/MainWindowTools/aopticaloverridedialog.cpp create mode 100644 src/gui/MainWindowTools/aopticaloverridedialog.h create mode 100644 src/gui/MainWindowTools/aopticaloverridedialog.ui diff --git a/src/ants2.pro b/src/ants2.pro index 519b9204..58e30618 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -9,7 +9,9 @@ ANTS2_MINOR = 12 CONFIG += ants2_eigen3 #use Eigen3 library instead of ROOT for linear algebra - highly recommended! Installation requires only to copy files! #CONFIG += ants2_RootServer #enable cern CERN ROOT html server #CONFIG += ants2_Python #enable Python scripting -#CONFIG += ants2_NCrystal #enable NCrystal library (neutron scattering) +#CONFIG += ants2_NCrystal #enable NCrystal library (neutron scattering): see https://github.com/mctools/ncrystal + +# You may need to modify paths CERN ROOT and the enabled libraries! See the corresponding sections below DEBUG_VERBOSITY = 1 # 0 - debug messages suppressed, 1 - normal, 2 - normal + file/line information # after a change, qmake and rebuild (or qmake + make any change in main.cpp to trigger recompilation) @@ -236,12 +238,6 @@ message("--> Compiling without GUI") CONFIG -= ants2_GUI } -#Options to be in effect only during compilation for docker -Ants2Docker { -message("--> Compiling for docker") -CONFIG += ants2_docker -} - #---ANTS2 files--- SOURCES += main.cpp \ common/jsonparser.cpp \ @@ -351,7 +347,8 @@ SOURCES += main.cpp \ common/agammarandomgenerator.cpp \ Net/agridrunner.cpp \ Net/aremoteserverrecord.cpp \ - common/atrackbuildoptions.cpp + common/atrackbuildoptions.cpp \ + gui/MainWindowTools/aopticaloverridedialog.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -475,7 +472,8 @@ HEADERS += common/CorrelationFilters.h \ scriptmode/awebserverinterface.h \ Net/agridrunner.h \ Net/aremoteserverrecord.h \ - common/atrackbuildoptions.h + common/atrackbuildoptions.h \ + gui/MainWindowTools/aopticaloverridedialog.h # --- SIM --- ants2_SIM { @@ -725,8 +723,8 @@ RC_FILE = myapp.rc #---Optimization of compilation--- win32 { #uncomment the next two lines to disable optimization during compilation. It will drastically shorten compilation time, but there are performance loss, especially strong for LRF computation - #QMAKE_CXXFLAGS_RELEASE -= -O2 - #QMAKE_CXXFLAGS_RELEASE *= -Od + QMAKE_CXXFLAGS_RELEASE -= -O2 + QMAKE_CXXFLAGS_RELEASE *= -Od } linux-g++ || unix { QMAKE_CXXFLAGS += -march=native @@ -794,3 +792,6 @@ unix { QMAKE_PRE_LINK = $$quote(cp -rf \"$${fromdir}\" \"$${todir}\"$$escape_expand(\n\t)) } #------------ + +FORMS += \ + gui/MainWindowTools/aopticaloverridedialog.ui diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index bbebdd41..2e208169 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -19,6 +19,13 @@ #include "TH1I.h" #include "TH1.h" +#include +#include +#include +#include +#include +#include + void AOpticalOverride::writeToJson(QJsonObject &json) { json["Model"] = getType(); @@ -33,6 +40,16 @@ bool AOpticalOverride::readFromJson(QJsonObject &json) return true; } +#include +QWidget *AOpticalOverride::getEditWidget() +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + f->setMinimumHeight(100); + + return f; +} + void AOpticalOverride::RandomDir(TRandom2 *RandGen, APhoton *Photon) { //Sphere function of Root: @@ -238,8 +255,6 @@ AOpticalOverride *OpticalOverrideFactory(QString model, AMaterialParticleCollect return new BasicOpticalOverride(MatCollection, MatFrom, MatTo); if (model == "SimplisticSpectral_model") return new SpectralBasicOpticalOverride(MatCollection, MatFrom, MatTo); - else if (model == "Claudio_Model_V1") - return new PhScatClaudioModelV1(MatCollection, MatFrom, MatTo); else if (model == "Claudio_Model_V2") return new PhScatClaudioModelV2(MatCollection, MatFrom, MatTo); else if (model == "Claudio_Model_V2d1") @@ -250,13 +265,26 @@ AOpticalOverride *OpticalOverrideFactory(QString model, AMaterialParticleCollect return new PhScatClaudioModelV2(MatCollection, MatFrom, MatTo); else if (model == "DielectricToMetal") return new ScatterOnMetal(MatCollection, MatFrom, MatTo); - else if (model=="FS_NP" || model=="Neves_model") + else if (model == "FS_NP" || model=="Neves_model") return new FSNPOpticalOverride(MatCollection, MatFrom, MatTo); - else if (model=="SurfaceWLS") + else if (model == "SurfaceWLS") return new AWaveshifterOverride(MatCollection, MatFrom, MatTo); return NULL; //undefined override type! } +const QStringList GetListOvAvailableOverrides() +{ + QStringList l; + + l << "Simplistic_model" + << "SimplisticSpectral_model" + << "Claudio_Model_V2d2" + << "DielectricToMetal" + << "FS_NP" + << "SurfaceWLS"; + + return l; +} AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) { @@ -408,7 +436,36 @@ bool FSNPOpticalOverride::readFromJson(QJsonObject &json) return true; } else - return false; + return false; +} + +#include "amessage.h" +QWidget *FSNPOpticalOverride::getEditWidget() +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QHBoxLayout* l = new QHBoxLayout(f); + QLabel* lab = new QLabel("Albedo:"); + l->addWidget(lab); + QLineEdit* le = new QLineEdit(QString::number(Albedo)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + val->setBottom(0); + //val->setTop(1.0); //Qt(5.8.0) BUG: check does not work + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, + [le, f, this]() + { + if (le->text().toDouble()>1.0) + {le->setText("1.0"); message("Max albedo is 1.0", f);} + this->Albedo = le->text().toDouble(); + } + ); + l->addWidget(le); + + return f; } AWaveshifterOverride::AWaveshifterOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo, int ReemissionModel) diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 4422e711..a02c609c 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -4,12 +4,17 @@ #include #include +class AOpticalOverride; class APhoton; class AMaterialParticleCollection; class TRandom2; class TH1I; class QJsonObject; class TH1D; +class QWidget; + +AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); +const QStringList GetListOvAvailableOverrides(); class AOpticalOverride { @@ -37,6 +42,8 @@ class AOpticalOverride void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} + virtual QWidget* getEditWidget(); + // read-out variables for standalone checker only (not multithreaded) ScatterStatusEnum Status; // type of interaction which happened - use in 1 thread only! @@ -77,7 +84,7 @@ class FSNPOpticalOverride : public AOpticalOverride FSNPOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo, double albedo) : AOpticalOverride(MatCollection, MatFrom, MatTo), Albedo(albedo) {} FSNPOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) - : AOpticalOverride(MatCollection, MatFrom, MatTo) {Albedo = 1;} + : AOpticalOverride(MatCollection, MatFrom, MatTo) {Albedo = 0.95;} virtual ~FSNPOpticalOverride() {} virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved @@ -90,6 +97,8 @@ class FSNPOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); + virtual QWidget* getEditWidget(); + //-- parameters -- double Albedo; }; @@ -158,6 +167,4 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride double effectiveWaveIndex; }; -AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); - #endif // OPTICALOVERRIDECLASS_H diff --git a/src/gui/MainWindowTools/MainWindowTests.cpp b/src/gui/MainWindowTools/MainWindowTests.cpp index 6c168c10..805210be 100644 --- a/src/gui/MainWindowTools/MainWindowTests.cpp +++ b/src/gui/MainWindowTools/MainWindowTests.cpp @@ -269,9 +269,6 @@ AOpticalOverride* InitOverride(Ui::MainWindow *ui, AMaterialParticleCollection& case 2: sc = new PhScatClaudioModelV2(&MatCol, 0, 1); break; - case 3: - sc = new PhScatClaudioModelV1(&MatCol, 0, 1); - break; default: message("Unexpected scattering model index"); exit(666); diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp new file mode 100644 index 00000000..b3ec8844 --- /dev/null +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -0,0 +1,95 @@ +#include "aopticaloverridedialog.h" +#include "ui_aopticaloverridedialog.h" +#include "aopticaloverride.h" +#include "amaterialparticlecolection.h" + +#include +#include + +AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, + int matFrom, int matTo, QWidget *parent) : + QDialog(parent), ui(new Ui::AOpticalOverrideDialog), + MatCollection(MatCollection), matFrom(matFrom), matTo(matTo), matNames(MatCollection->getListOfMaterialNames()) +{ + ui->setupUi(this); + ui->pbInterceptorForEnter->setVisible(false); + ui->pbInterceptorForEnter->setDefault(true); + setWindowTitle("Photon tracing rules for material interface"); + + ui->leMatFrom->setText(matNames.at(matFrom)); + ui->leMatTo->setText(matNames.at(matTo)); + ui->cobType->addItem("No special rule"); + QStringList avOv = GetListOvAvailableOverrides(); + ui->cobType->addItems(avOv); + + AOpticalOverride* ov = (*MatCollection)[matFrom]->OpticalOverrides[matTo]; + if (ov) + { + ovLocal = OpticalOverrideFactory( ov->getType(), MatCollection, matFrom, matTo); + QJsonObject json; ov->writeToJson(json); ovLocal->readFromJson(json); + } + + updateGui(); +} + +AOpticalOverrideDialog::~AOpticalOverrideDialog() +{ + delete ui; +} + +void AOpticalOverrideDialog::updateGui() +{ + if (customWidget) + { + QVBoxLayout* l = static_cast(layout()); + l->removeWidget(customWidget); + delete customWidget; customWidget = 0; + } + + if (ovLocal) + { + ui->frNoOverride->setVisible(false); + ui->pbTestOverride->setVisible(true); + + QStringList avOv = GetListOvAvailableOverrides(); + int index = avOv.indexOf(ovLocal->getType()); //TODO -> if not found? + ui->cobType->setCurrentIndex(index+1); + + QVBoxLayout* l = static_cast(layout()); + customWidget = ovLocal->getEditWidget(); + l->insertWidget(customWidgetPositionInLayout, customWidget); + } + else + { + ui->frNoOverride->setVisible(true); + ui->pbTestOverride->setVisible(false); + } +} + +void AOpticalOverrideDialog::on_pbAccept_clicked() +{ + delete (*MatCollection)[matFrom]->OpticalOverrides[matTo]; + (*MatCollection)[matFrom]->OpticalOverrides[matTo] = ovLocal; + accept(); +} + +void AOpticalOverrideDialog::on_pbCancel_clicked() +{ + delete ovLocal; ovLocal = 0; + reject(); +} + +void AOpticalOverrideDialog::on_cobType_activated(int index) +{ + delete ovLocal; ovLocal = 0; + + if (index != 0) + ovLocal = OpticalOverrideFactory(ui->cobType->currentText(), MatCollection, matFrom, matTo); + + updateGui(); +} + +void AOpticalOverrideDialog::on_pbTestOverride_clicked() +{ + +} diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.h b/src/gui/MainWindowTools/aopticaloverridedialog.h new file mode 100644 index 00000000..9cd767fc --- /dev/null +++ b/src/gui/MainWindowTools/aopticaloverridedialog.h @@ -0,0 +1,46 @@ +#ifndef AOPTICALOVERRIDEDIALOG_H +#define AOPTICALOVERRIDEDIALOG_H + +#include +#include + +namespace Ui { +class AOpticalOverrideDialog; +} + +class AOpticalOverride; +class AMaterialParticleCollection; + +class AOpticalOverrideDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, int matFrom, int matTo, QWidget *parent = 0); + ~AOpticalOverrideDialog(); + +private slots: + void on_pbAccept_clicked(); + + void on_pbCancel_clicked(); + + void on_cobType_activated(int index); + + void on_pbTestOverride_clicked(); + +private: + Ui::AOpticalOverrideDialog *ui; + AOpticalOverride ** pOV; + AOpticalOverride * ovLocal = 0; + AMaterialParticleCollection* MatCollection; + int matFrom; + int matTo; + QStringList matNames; //need? + + int customWidgetPositionInLayout = 5; + QWidget* customWidget = 0; + + void updateGui(); +}; + +#endif // AOPTICALOVERRIDEDIALOG_H diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.ui b/src/gui/MainWindowTools/aopticaloverridedialog.ui new file mode 100644 index 00000000..cc9e08ff --- /dev/null +++ b/src/gui/MainWindowTools/aopticaloverridedialog.ui @@ -0,0 +1,250 @@ + + + AOpticalOverrideDialog + + + + 0 + 0 + 457 + 462 + + + + Dialog + + + + + + + + Interface from: + + + + + + + true + + + + + + + to: + + + + + + + true + + + + + + + + + Qt::Horizontal + + + + + + + + + Selected type: + + + Qt::AlignCenter + + + + + + + + + + 100 + 0 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 100 + + + + QFrame::Box + + + QFrame::Raised + + + + + + Special rules are not defined for this interface: + + + Qt::AlignCenter + + + + + + + using Fresnel and Snell laws + + + Qt::AlignCenter + + + + + + + + + + Test override + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 150 + 31 + + + + + 75 + true + + + + Accept changes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 150 + 31 + + + + + 75 + true + + + + Cancel changes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + ... + + + + + + + + diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 7dcbe096..07139fe4 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -861,6 +861,25 @@ void MainWindow::on_pbOverride_clicked() ui->lwMaterials->setCurrentRow(i); } +#include "aopticaloverridedialog.h" +void MainWindow::on_pbEditOverride_clicked() +{ + int From = ui->cobMaterialForOverrides->currentIndex(); + int To = ui->cobMaterialTo->currentIndex(); + + AOpticalOverrideDialog d(MpCollection, From, To, this); + int res = d.exec(); + if (res == 1) + { + ReconstructDetector(true); + + on_pbRefreshOverrides_clicked(); + int i = ui->lwMaterials->currentRow(); + UpdateMaterialListEdit(); //to update (*) status + ui->lwMaterials->setCurrentRow(i); + } +} + void MainWindow::on_pbRefreshOverrides_clicked() { //qDebug() << "->Updating overrides indication"; @@ -5344,3 +5363,4 @@ void MainWindow::on_ledSphericalPMAngle_editingFinished() on_pbUpdatePMproperties_clicked(); } + diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 5dd71efb..8c5d0d59 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -644,6 +644,8 @@ private slots: void on_cobSurfaceWLS_Model_activated(int index); + void on_pbEditOverride_clicked(); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 00e095f7..dff9021c 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -6304,6 +6304,19 @@ materials + + + + 179 + 164 + 75 + 23 + + + + PushButton + + lwOverrides lwMaterials pbStartMaterialInspector @@ -6322,6 +6335,7 @@ materials cobOpticalOverrideModel label_149 pbRefreshOverrides + pbEditOverride @@ -14702,11 +14716,6 @@ multiply to loaded data V2 - - - V1 - - diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index fad2d502..9c869c74 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -77,6 +77,14 @@ QString AMaterialParticleCollection::getMaterialName(int matIndex) return MaterialCollectionData.at(matIndex)->name; } +const QStringList AMaterialParticleCollection::getListOfMaterialNames() const +{ + QStringList l; + for (AMaterial* m : MaterialCollectionData) + l << m->name; + return l; +} + int AMaterialParticleCollection::getParticleId(QString name) const { for (int i=0; iv); // photon direction - //qDebug() << "Photon direction (i,j,k):"<getRefractiveIndex(Photon->waveIndex); - double Rindex2 = (*MatCollection)[MatTo]->getRefractiveIndex(Photon->waveIndex); - //qDebug() << "Refractive indices from and to:" << Rindex1 << Rindex2; - - double costi = - GlobalNormal * K; // global angle of incidence - //qDebug() << "costi:"< 0) ? GnFunc(costi) : 1.0; // shadowing fuction -// qDebug() << "gni:"<waveIndex, costi); // relative intensity of the specular spike - //qDebug() << "lambda:"<Rndm() < lambda || sigma_alpha == 0) - { - // If the random number is larger than lambda the light will be scattered - //according to the local normal. If the sigma_alpha is zero there is no specular lobe - Status = SpikeReflection; - costl = costi; - costr = costi; - weight_microfacet = gni; - gnr = gni; - } - else - { - Status = LobeReflection; - - double alpha_WRM = SlopeAngle(RandGen->Rndm()); // Sampling of the slope angle - double phi_alpha_WRM = 2.0*3.1415926535*RandGen->Rndm(); - - //Set the Components of the Global Normal - double CosAlpha_WRM = cos(alpha_WRM); - double SinAlpha_WRM = sin(alpha_WRM); - - //The local angle - ScatNormal.SetX(SinAlpha_WRM * (cos(phi_alpha_WRM))); - ScatNormal.SetY(SinAlpha_WRM * (sin(phi_alpha_WRM))); - ScatNormal.SetZ(CosAlpha_WRM); - ScatNormal.RotateUz(GlobalNormal); - - //The local angle - costl = - K * ScatNormal; - - //The reflection angle - costr = 2*costl*CosAlpha_WRM-costi; //angle between the global normal and the viewing direction - gnr = GnFunc(costr); - - if(costl < 0 ) - weight_microfacet = 0; - else - weight_microfacet = gni*costl/(costi*CosAlpha_WRM); - } - } - while( RandGen->Rndm()*1.5 > weight_microfacet); - - //The polarization of the incident photon - //G4ThreeVector A_trans = OldMomentum.cross(theScatNormal); //Measuring the Polarization - //A_trans = A_trans.unit(); - - double E1_perp = sqrt(2.0)/2.0;//OldPolarization * A_trans; - //G4ThreeVector E1pp = E1_perp * A_trans; - //G4ThreeVector E1pl = OldPolarization - E1pp; - double E1_parl = E1_perp;//E1pl.mag(); - - double Amp_perp = Fresnel(E1_perp, 0, costl, Rindex1, Rindex2); - double Amp_parl = Fresnel(0, E1_parl, costl, Rindex1, Rindex2); - double Amp_tot = (Amp_perp+Amp_parl)*gnr; - - //G4ThreeVector A_paral; - - if (RandGen->Rndm()SimStat->OverrideClaudioSpec++; - } - else - { - Status = LambertianReflection; //The computation of the diffuse direction direction - double gnd; - double flag_ready = 0; - do - { - //the New Momentum - double sintdsqquared = RandGen->Rndm(); - double sintd = sqrt(sintdsqquared); - double costd = sqrt(1.0-sintdsqquared); - double phid = 2.0 * 3.1415926535 * RandGen->Rndm(); - - K.SetX(sintd*(cos(phid))); - K.SetY(sintd*(sin(phid))); - K.SetZ(costd); - K.RotateUz(ScatNormal); - - costr = GlobalNormal*K; - double sintr = sqrt(1.0-costr*costr); - if (costr > 0) - gnd = GnFunc(costr); - else - gnd = 0; - - double sintinter = Rindex1*sintr/Rindex2; - if(sintinter<1) - { - double costiter = std::sqrt(1.-sintinter*sintinter); - double Fres_Term = 1 - Fresnel(sqrt(2.0)/2, sqrt(2.0)/2, costiter, Rindex2, Rindex1); - flag_ready = 1; - if (RandGen->Rndm() > albedo*Fres_Term) - { - Status = Absorption; - Photon->SimStat->OverrideClaudioAbs++; - return Absorbed; - } - } - } - while (sigma_alpha> 0 && RandGen->Rndm() > gnd || flag_ready == 0); - - //The diffuse lobe will be randomly polarized - //A_trans = NewMomentum.cross(theScatNormal); - //A_trans = A_trans.unit(); - //A_paral = NewMomentum.cross(A_trans); - //A_paral = A_paral.unit(); - //G4double ThetaPolar = twopi*G4UniformRand(); - //NewPolarization = cos(ThetaPolar)*A_paral + sin(ThetaPolar)*A_trans; - Photon->SimStat->OverrideClaudioLamb++; - } - - Photon->v[0] = K.X(); - Photon->v[1] = K.Y(); - Photon->v[2] = K.Z(); - //qDebug() << "---"<<(int)Status<v); // photon direction diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index ebd56f88..ca29d1a3 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -78,19 +78,4 @@ class PhScatClaudioModelV2d2 : public PhScatClaudioModelV2 virtual QString getReportLine(); }; -class PhScatClaudioModelV1 : public PhScatClaudioModel -{ -public: - PhScatClaudioModelV1(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) - : PhScatClaudioModel(MatCollection, MatFrom, MatTo) {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); - virtual QString getType() const {return "Claudio_Model_V1";} - virtual QString getReportLine(); - -protected: - virtual double GnFunc(double cost); - virtual double SlopeAngle(double random_num); -}; - - #endif // PHSCATCLAUDIOMODEL_H From 72180300a40bcd4c4efd5094382bacf75099118e Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 00:27:30 +0100 Subject: [PATCH 003/140] ++ --- src/common/aopticaloverride.cpp | 63 ++++++++++++++++++- src/common/aopticaloverride.h | 8 ++- .../aopticaloverridedialog.cpp | 11 ++++ .../MainWindowTools/aopticaloverridedialog.h | 3 - 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 2e208169..e39eaa6f 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -5,6 +5,7 @@ #include "ajsontools.h" #include "afiletools.h" #include "asimulationstatistics.h" +#include "amessage.h" //GUI? #ifdef SIM #include "phscatclaudiomodel.h" @@ -25,6 +26,7 @@ #include #include #include +#include void AOpticalOverride::writeToJson(QJsonObject &json) { @@ -249,6 +251,66 @@ bool BasicOpticalOverride::readFromJson(QJsonObject &json) return true; } +QWidget *BasicOpticalOverride::getEditWidget() +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QHBoxLayout* hl = new QHBoxLayout(f); + QVBoxLayout* l = new QVBoxLayout(); + QLabel* lab = new QLabel("Absorption:"); + l->addWidget(lab); + lab = new QLabel("Specular reflection:"); + l->addWidget(lab); + lab = new QLabel("Scattering:"); + l->addWidget(lab); + hl->addLayout(l); + l = new QVBoxLayout(); + QLineEdit* le = new QLineEdit(QString::number(probLoss)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + val->setBottom(0); + //val->setTop(1.0); //Qt(5.8.0) BUG: check does not work + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probLoss = le->text().toDouble(); } ); + l->addWidget(le); + le = new QLineEdit(QString::number(probRef)); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probRef = le->text().toDouble(); } ); + l->addWidget(le); + le = new QLineEdit(QString::number(probDiff)); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probDiff = le->text().toDouble(); } ); + l->addWidget(le); + hl->addLayout(l); + l = new QVBoxLayout(); + lab = new QLabel(""); + l->addWidget(lab); + lab = new QLabel(""); + l->addWidget(lab); + QComboBox* com = new QComboBox(); + com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); + com->setCurrentIndex(scatterModel); + //QObject::connect(com, &QComboBox::activated, [com, this](int index) { this->scatterModel = index; } ); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->scatterModel = index; } ); + l->addWidget(com); + hl->addLayout(l); + + return f; +} + +const QString BasicOpticalOverride::checkValidity() const +{ + if (probLoss<0 || probLoss>1.0) return "Absorption probability should be within [0, 1.0]"; + if (probRef <0 || probRef >1.0) return "Reflection probability should be within [0, 1.0]"; + if (probDiff<0 || probDiff>1.0) return "Scattering probability should be within [0, 1.0]"; + + if (probLoss + probRef + probDiff > 1.0) return "Sum of all process probabilities cannot exceed 1.0"; + + return ""; +} + AOpticalOverride *OpticalOverrideFactory(QString model, AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) { if (model == "Simplistic_model") @@ -439,7 +501,6 @@ bool FSNPOpticalOverride::readFromJson(QJsonObject &json) return false; } -#include "amessage.h" QWidget *FSNPOpticalOverride::getEditWidget() { QFrame* f = new QFrame(); diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index a02c609c..20947507 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -44,6 +44,8 @@ class AOpticalOverride virtual QWidget* getEditWidget(); + virtual const QString checkValidity() const {return "";} //TODO after all are done, make = 0 + // read-out variables for standalone checker only (not multithreaded) ScatterStatusEnum Status; // type of interaction which happened - use in 1 thread only! @@ -72,6 +74,10 @@ class BasicOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); + virtual QWidget* getEditWidget() override; + + virtual const QString checkValidity() const override; + double probLoss = 0; //probability of absorption double probRef = 0; //probability of specular reflection double probDiff = 0; //probability of scattering @@ -97,7 +103,7 @@ class FSNPOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); - virtual QWidget* getEditWidget(); + virtual QWidget* getEditWidget() override; //-- parameters -- double Albedo; diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index b3ec8844..4836e6de 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -2,6 +2,7 @@ #include "ui_aopticaloverridedialog.h" #include "aopticaloverride.h" #include "amaterialparticlecolection.h" +#include "amessage.h"; #include #include @@ -68,6 +69,16 @@ void AOpticalOverrideDialog::updateGui() void AOpticalOverrideDialog::on_pbAccept_clicked() { + if (ovLocal) + { + QString err = ovLocal->checkValidity(); + if (!err.isEmpty()) + { + message(err, this); + return; + } + } + delete (*MatCollection)[matFrom]->OpticalOverrides[matTo]; (*MatCollection)[matFrom]->OpticalOverrides[matTo] = ovLocal; accept(); diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.h b/src/gui/MainWindowTools/aopticaloverridedialog.h index 9cd767fc..1d90a7fb 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.h +++ b/src/gui/MainWindowTools/aopticaloverridedialog.h @@ -21,11 +21,8 @@ class AOpticalOverrideDialog : public QDialog private slots: void on_pbAccept_clicked(); - void on_pbCancel_clicked(); - void on_cobType_activated(int index); - void on_pbTestOverride_clicked(); private: From a41fc76eac0ca9745adbc5ba0ee7891af496a228 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 01:01:27 +0100 Subject: [PATCH 004/140] ++ --- src/common/aopticaloverride.cpp | 15 ++++++------ src/common/aopticaloverride.h | 2 ++ src/modules/scatteronmetal.cpp | 41 +++++++++++++++++++++++++++++++++ src/modules/scatteronmetal.h | 7 +++++- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index e39eaa6f..b5a02afd 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -516,19 +516,18 @@ QWidget *FSNPOpticalOverride::getEditWidget() //val->setTop(1.0); //Qt(5.8.0) BUG: check does not work val->setDecimals(6); le->setValidator(val); - QObject::connect(le, &QLineEdit::editingFinished, - [le, f, this]() - { - if (le->text().toDouble()>1.0) - {le->setText("1.0"); message("Max albedo is 1.0", f);} - this->Albedo = le->text().toDouble(); - } - ); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->Albedo = le->text().toDouble(); } ); l->addWidget(le); return f; } +const QString FSNPOpticalOverride::checkValidity() const +{ + if (Albedo<0 || Albedo>1.0) return "Albedo should be within [0, 1.0]"; + return ""; +} + AWaveshifterOverride::AWaveshifterOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo, int ReemissionModel) : AOpticalOverride(MatCollection, MatFrom, MatTo), ReemissionModel(ReemissionModel) { diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 20947507..28a38a38 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -105,6 +105,8 @@ class FSNPOpticalOverride : public AOpticalOverride virtual QWidget* getEditWidget() override; + virtual const QString checkValidity() const override; + //-- parameters -- double Albedo; }; diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index 30d77ad1..64d24248 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -48,6 +48,47 @@ bool ScatterOnMetal::readFromJson(QJsonObject &json) return true; } +#include +#include +#include +#include +#include +#include +QWidget *ScatterOnMetal::getEditWidget() +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QHBoxLayout* hl = new QHBoxLayout(f); + QVBoxLayout* l = new QVBoxLayout(); + QLabel* lab = new QLabel("Refractive index, real:"); + l->addWidget(lab); + lab = new QLabel("Refractive index, imaginary:"); + l->addWidget(lab); + hl->addLayout(l); + l = new QVBoxLayout(); + QLineEdit* le = new QLineEdit(QString::number(RealN)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + //val->setBottom(0); + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->RealN = le->text().toDouble(); } ); + l->addWidget(le); + le = new QLineEdit(QString::number(ImaginaryN)); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->ImaginaryN = le->text().toDouble(); } ); + l->addWidget(le); + hl->addLayout(l); + + return f; +} + +const QString ScatterOnMetal::checkValidity() const +{ + return ""; +} + AOpticalOverride::OpticalOverrideResultEnum ScatterOnMetal::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) { double CosTheta = Photon->v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2]; diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index 257fb5c9..956479a6 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -25,8 +25,13 @@ class ScatterOnMetal : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); + virtual QWidget* getEditWidget() override; + + virtual const QString checkValidity() const override; + //data - double RealN, ImaginaryN; + double RealN = 1.07; + double ImaginaryN = 0.6; private: double calculateReflectivity(double CosTheta, double RealN, double ImaginaryN, int waveIndex); From 1cde5dc2455e243d17dc066044d01584b6889911 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 10:51:32 +0100 Subject: [PATCH 005/140] ++ --- .../aopticaloverridedialog.cpp | 2 +- .../MainWindowTools/aopticaloverridedialog.ui | 2 +- src/modules/phscatclaudiomodel.cpp | 67 +++++++++++++++++++ src/modules/phscatclaudiomodel.h | 14 ++-- 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 4836e6de..81e9c38f 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -2,7 +2,7 @@ #include "ui_aopticaloverridedialog.h" #include "aopticaloverride.h" #include "amaterialparticlecolection.h" -#include "amessage.h"; +#include "amessage.h" #include #include diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.ui b/src/gui/MainWindowTools/aopticaloverridedialog.ui index cc9e08ff..d7d693cc 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.ui +++ b/src/gui/MainWindowTools/aopticaloverridedialog.ui @@ -7,7 +7,7 @@ 0 0 457 - 462 + 376 diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 857b03f5..139f28f4 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -65,6 +65,73 @@ bool PhScatClaudioModel::readFromJson(QJsonObject &json) return true; } +#include +#include +#include +#include +#include +#include +#include +QWidget *PhScatClaudioModel::getEditWidget() +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QHBoxLayout* hl = new QHBoxLayout(f); + QVBoxLayout* l = new QVBoxLayout(); + QLabel* lab = new QLabel("Sigma alpha:"); + l->addWidget(lab); + lab = new QLabel("Sigma spike:"); + l->addWidget(lab); + lab = new QLabel("Albedo:"); + l->addWidget(lab); + lab = new QLabel("Hight distribution:"); + l->addWidget(lab); + lab = new QLabel("Slope distribution:"); + l->addWidget(lab); + hl->addLayout(l); + l = new QVBoxLayout(); + QLineEdit* le = new QLineEdit(QString::number(sigma_alpha)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + val->setBottom(0); + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->sigma_alpha = le->text().toDouble(); } ); + l->addWidget(le); + le = new QLineEdit(QString::number(sigma_h)); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->sigma_h = le->text().toDouble(); } ); + l->addWidget(le); + le = new QLineEdit(QString::number(albedo)); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->albedo = le->text().toDouble(); } ); + l->addWidget(le); + QComboBox* com = new QComboBox(); + com->addItems(QStringList({"empirical", "gaussian", "exponential"})); + com->setCurrentIndex(HeightDistribution); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->HeightDistribution = static_cast(index); } ); + l->addWidget(com); + com = new QComboBox(); + com->addItems(QStringList({"trowbridgereitz", "cooktorrance", "bivariatecauchy"})); + com->setCurrentIndex(SlopeDistribution); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->SlopeDistribution = static_cast(index); } ); + l->addWidget(com); + hl->addLayout(l); + + return f; +} + +const QString PhScatClaudioModel::checkValidity() const +{ + if (sigma_alpha < 0) return "sigma alpha should be >= 0"; + if (sigma_h < 0) return "sigma h should be >= 0"; + if (albedo < 0 || albedo > 1.0) return "albedo should be within [0, 1.0] range"; + if (HeightDistribution < 0 || HeightDistribution > 2) return "hight distribution model can be 0, 1 or 2"; + if (SlopeDistribution < 0 || SlopeDistribution > 2) return "slope distribution model can be 0, 1 or 2"; + return ""; +} + double PhScatClaudioModel::SpikeIntensity(int iWave, double costi) { if (HeightDistribution == empirical) // for the empirical function observed by C. Silva diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index ca29d1a3..442eb946 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -28,12 +28,16 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); + virtual QWidget* getEditWidget() override; + + virtual const QString checkValidity() const override; + // interface properties - double sigma_alpha; // r.m.s. (or similar) of the slope distribution - double sigma_h; // r.m.s (or similar) of the height distribution - double albedo; // multiple diffuse albedo - HeightDistrEnum HeightDistribution; // model for heights distribution - SlopeDistrEnum SlopeDistribution; // model for distribution of slopes + double sigma_alpha = 0.18; // r.m.s. (or similar) of the slope distribution + double sigma_h = 1.0; // r.m.s (or similar) of the height distribution + double albedo = 0.97; // multiple diffuse albedo + HeightDistrEnum HeightDistribution = empirical; // model for heights distribution + SlopeDistrEnum SlopeDistribution = trowbridgereitz; // model for distribution of slopes protected: double SpikeIntensity(int iWave, double costi); From e2f20b4a0ca23758662f28edcfcf5a1e31e67a94 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 11:22:16 +0100 Subject: [PATCH 006/140] ++ --- src/common/aopticaloverride.cpp | 56 +++++++++++++++++++++++++++++++++ src/common/aopticaloverride.h | 8 +++++ 2 files changed, 64 insertions(+) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index b5a02afd..50fd6a1f 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include void AOpticalOverride::writeToJson(QJsonObject &json) { @@ -870,3 +872,57 @@ const QString SpectralBasicOpticalOverride::loadData(const QString &fileName) return ""; } + +void SpectralBasicOpticalOverride::loadSpectralData() +{ + QString fileName = QFileDialog::getOpenFileName(0, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", "", "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + + QVector< QVector* > vec; + vec << &Wave << &ProbLoss << &ProbRef << &ProbDiff; + QString err = LoadDoubleVectorsFromFile(fileName, vec); + if (!err.isEmpty()) message(err, 0); +} + +QWidget *SpectralBasicOpticalOverride::getEditWidget() +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QVBoxLayout* vl = new QVBoxLayout(f); + QHBoxLayout* l = new QHBoxLayout(); + QLabel* lab = new QLabel("Absorption, reflection and scattering:"); + l->addWidget(lab); + QPushButton* pb = new QPushButton("Load"); + QObject::connect(pb, &QPushButton::clicked, [this] {loadSpectralData();}); + l->addWidget(pb); + vl->addLayout(l); + l = new QHBoxLayout(); + lab = new QLabel("Scattering model:"); + l->addWidget(lab); + QComboBox* com = new QComboBox(); + com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); + com->setCurrentIndex(scatterModel); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->scatterModel = index; } ); + l->addWidget(com); + vl->addLayout(l); + l = new QHBoxLayout(); + lab = new QLabel("For photons with WaveIndex=-1, assume wavelength of:"); + l->addWidget(lab); + QLineEdit* le = new QLineEdit(QString::number(effectiveWavelength)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + val->setBottom(0); + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->effectiveWavelength = le->text().toDouble(); } ); + l->addWidget(le); + vl->addLayout(l); + + return f; +} + +const QString SpectralBasicOpticalOverride::checkValidity() const +{ + return "aaaaaaaaaahaaa"; +} diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 28a38a38..f02885a3 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -164,6 +164,11 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride virtual void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; const QString loadData(const QString& fileName); + virtual QWidget* getEditWidget() override; + + virtual const QString checkValidity() const override; + + //parameters QVector Wave; QVector ProbLoss; //probability of absorption QVector ProbLossBinned; //probability of absorption @@ -173,6 +178,9 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride QVector ProbDiffBinned; //probability of scattering double effectiveWavelength = 500; //if waveIndex of photon is -1, index correspinding to this wavelength will be used double effectiveWaveIndex; + +private: + void loadSpectralData(); }; #endif // OPTICALOVERRIDECLASS_H From a5831b0c0625c85266f668d890e093ad359d8b96 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 11:27:29 +0100 Subject: [PATCH 007/140] ++ --- src/common/aopticaloverride.cpp | 16 ++++++++-------- src/common/aopticaloverride.h | 10 +++++----- .../MainWindowTools/aopticaloverridedialog.cpp | 2 +- src/modules/phscatclaudiomodel.cpp | 2 +- src/modules/phscatclaudiomodel.h | 2 +- src/modules/scatteronmetal.cpp | 2 +- src/modules/scatteronmetal.h | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 50fd6a1f..b30709f4 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -45,7 +45,7 @@ bool AOpticalOverride::readFromJson(QJsonObject &json) } #include -QWidget *AOpticalOverride::getEditWidget() +QWidget *AOpticalOverride::getEditWidget(QWidget *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -253,7 +253,7 @@ bool BasicOpticalOverride::readFromJson(QJsonObject &json) return true; } -QWidget *BasicOpticalOverride::getEditWidget() +QWidget *BasicOpticalOverride::getEditWidget(QWidget*) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -503,7 +503,7 @@ bool FSNPOpticalOverride::readFromJson(QJsonObject &json) return false; } -QWidget *FSNPOpticalOverride::getEditWidget() +QWidget *FSNPOpticalOverride::getEditWidget(QWidget *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -873,18 +873,18 @@ const QString SpectralBasicOpticalOverride::loadData(const QString &fileName) return ""; } -void SpectralBasicOpticalOverride::loadSpectralData() +void SpectralBasicOpticalOverride::loadSpectralData(QWidget* caller) { - QString fileName = QFileDialog::getOpenFileName(0, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", "", "Data files (*.dat *.txt);;All files (*)"); + QString fileName = QFileDialog::getOpenFileName(caller, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", "", "Data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; QVector< QVector* > vec; vec << &Wave << &ProbLoss << &ProbRef << &ProbDiff; QString err = LoadDoubleVectorsFromFile(fileName, vec); - if (!err.isEmpty()) message(err, 0); + if (!err.isEmpty()) message(err, caller); } -QWidget *SpectralBasicOpticalOverride::getEditWidget() +QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -894,7 +894,7 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget() QLabel* lab = new QLabel("Absorption, reflection and scattering:"); l->addWidget(lab); QPushButton* pb = new QPushButton("Load"); - QObject::connect(pb, &QPushButton::clicked, [this] {loadSpectralData();}); + QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); l->addWidget(pb); vl->addLayout(l); l = new QHBoxLayout(); diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index f02885a3..f7265bcd 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -42,7 +42,7 @@ class AOpticalOverride void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} - virtual QWidget* getEditWidget(); + virtual QWidget* getEditWidget(QWidget* caller); virtual const QString checkValidity() const {return "";} //TODO after all are done, make = 0 @@ -74,7 +74,7 @@ class BasicOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); - virtual QWidget* getEditWidget() override; + virtual QWidget* getEditWidget(QWidget *caller) override; virtual const QString checkValidity() const override; @@ -103,7 +103,7 @@ class FSNPOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); - virtual QWidget* getEditWidget() override; + virtual QWidget* getEditWidget(QWidget* caller) override; virtual const QString checkValidity() const override; @@ -164,7 +164,7 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride virtual void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; const QString loadData(const QString& fileName); - virtual QWidget* getEditWidget() override; + virtual QWidget* getEditWidget(QWidget* caller) override; virtual const QString checkValidity() const override; @@ -180,7 +180,7 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride double effectiveWaveIndex; private: - void loadSpectralData(); + void loadSpectralData(QWidget *caller); }; #endif // OPTICALOVERRIDECLASS_H diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 81e9c38f..e872fef0 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -57,7 +57,7 @@ void AOpticalOverrideDialog::updateGui() ui->cobType->setCurrentIndex(index+1); QVBoxLayout* l = static_cast(layout()); - customWidget = ovLocal->getEditWidget(); + customWidget = ovLocal->getEditWidget(this); l->insertWidget(customWidgetPositionInLayout, customWidget); } else diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 139f28f4..522c25f1 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -72,7 +72,7 @@ bool PhScatClaudioModel::readFromJson(QJsonObject &json) #include #include #include -QWidget *PhScatClaudioModel::getEditWidget() +QWidget *PhScatClaudioModel::getEditWidget(QWidget *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index 442eb946..bec2846c 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -28,7 +28,7 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); - virtual QWidget* getEditWidget() override; + virtual QWidget* getEditWidget(QWidget* caller) override; virtual const QString checkValidity() const override; diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index 64d24248..b8fa3a3c 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -54,7 +54,7 @@ bool ScatterOnMetal::readFromJson(QJsonObject &json) #include #include #include -QWidget *ScatterOnMetal::getEditWidget() +QWidget *ScatterOnMetal::getEditWidget(QWidget *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index 956479a6..b763e974 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -25,7 +25,7 @@ class ScatterOnMetal : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); - virtual QWidget* getEditWidget() override; + virtual QWidget* getEditWidget(QWidget* caller) override; virtual const QString checkValidity() const override; From ec277c139d81e6386aa358bb672859013e7249eb Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 13:33:48 +0100 Subject: [PATCH 008/140] ++ --- src/common/aopticaloverride.cpp | 40 ++++++++++++++++++++++++++++-- src/common/aopticaloverride.h | 12 ++++++--- src/modules/phscatclaudiomodel.cpp | 19 ++++++++------ src/modules/phscatclaudiomodel.h | 3 ++- src/modules/scatteronmetal.cpp | 17 ++++++++----- src/modules/scatteronmetal.h | 3 ++- 6 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index b30709f4..811922f4 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -5,7 +5,6 @@ #include "ajsontools.h" #include "afiletools.h" #include "asimulationstatistics.h" -#include "amessage.h" //GUI? #ifdef SIM #include "phscatclaudiomodel.h" @@ -20,6 +19,7 @@ #include "TH1I.h" #include "TH1.h" +#ifdef GUI #include #include #include @@ -29,6 +29,8 @@ #include #include #include +#include "amessage.h" +#endif void AOpticalOverride::writeToJson(QJsonObject &json) { @@ -44,6 +46,7 @@ bool AOpticalOverride::readFromJson(QJsonObject &json) return true; } +#ifdef GUI #include QWidget *AOpticalOverride::getEditWidget(QWidget *) { @@ -53,6 +56,7 @@ QWidget *AOpticalOverride::getEditWidget(QWidget *) return f; } +#endif void AOpticalOverride::RandomDir(TRandom2 *RandGen, APhoton *Photon) { @@ -253,6 +257,7 @@ bool BasicOpticalOverride::readFromJson(QJsonObject &json) return true; } +#ifdef GUI QWidget *BasicOpticalOverride::getEditWidget(QWidget*) { QFrame* f = new QFrame(); @@ -301,6 +306,7 @@ QWidget *BasicOpticalOverride::getEditWidget(QWidget*) return f; } +#endif const QString BasicOpticalOverride::checkValidity() const { @@ -503,6 +509,7 @@ bool FSNPOpticalOverride::readFromJson(QJsonObject &json) return false; } +#ifdef GUI QWidget *FSNPOpticalOverride::getEditWidget(QWidget *) { QFrame* f = new QFrame(); @@ -523,6 +530,7 @@ QWidget *FSNPOpticalOverride::getEditWidget(QWidget *) return f; } +#endif const QString FSNPOpticalOverride::checkValidity() const { @@ -884,6 +892,7 @@ void SpectralBasicOpticalOverride::loadSpectralData(QWidget* caller) if (!err.isEmpty()) message(err, caller); } +#ifdef GUI QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller) { QFrame* f = new QFrame(); @@ -894,8 +903,15 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller) QLabel* lab = new QLabel("Absorption, reflection and scattering:"); l->addWidget(lab); QPushButton* pb = new QPushButton("Load"); + pb->setToolTip("Every line of the file should contain 4 numbers:\nwavelength[nm] absorption_prob[0..1] reflection_prob[0..1] scattering_prob[0..1]"); QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); l->addWidget(pb); + pb = new QPushButton("Show"); + //QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); + l->addWidget(pb); + pb = new QPushButton("Binned"); + //QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); + l->addWidget(pb); vl->addLayout(l); l = new QHBoxLayout(); lab = new QLabel("Scattering model:"); @@ -917,12 +933,32 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller) le->setValidator(val); QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->effectiveWavelength = le->text().toDouble(); } ); l->addWidget(le); + lab = new QLabel("nm"); + l->addWidget(lab); vl->addLayout(l); return f; } +#endif const QString SpectralBasicOpticalOverride::checkValidity() const { - return "aaaaaaaaaahaaa"; + //checking spectrum + if (Wave.size() == 0) return "Spectral data are not defined"; + if (Wave.size() != ProbLoss.size() || Wave.size() != ProbRef.size() || Wave.size() != ProbDiff.size()) return "Spectral data do not match in size"; + for (int i=0; i 1.0) return "absorption probability has to be in the range of [0, 1.0]"; + if (ProbDiff.at(i) < 0 || ProbDiff.at(i) > 1.0) return "scattering probability has to be in the range of [0, 1.0]"; + if (ProbRef.at(i) < 0 || ProbRef.at(i) > 1.0) return "scattering probability has to be in the range of [0, 1.0]"; + double sum = ProbLoss.at(i) + ProbRef.at(i) + ProbDiff.at(i); + if (sum > 1.0) return QString("Sum of probabilities is larger than 1.0 for wavelength of %1 nm").arg(Wave.at(i)); + } + if (scatterModel < 0 || scatterModel > 2) return "unknown scattering model"; + + //TODO check effective wavelength + //TODO check binned + + return ""; } diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index f7265bcd..e88c1b1a 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -42,8 +42,9 @@ class AOpticalOverride void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} +#ifdef GUI virtual QWidget* getEditWidget(QWidget* caller); - +#endif virtual const QString checkValidity() const {return "";} //TODO after all are done, make = 0 // read-out variables for standalone checker only (not multithreaded) @@ -74,8 +75,9 @@ class BasicOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); +#ifdef GUI virtual QWidget* getEditWidget(QWidget *caller) override; - +#endif virtual const QString checkValidity() const override; double probLoss = 0; //probability of absorption @@ -103,8 +105,9 @@ class FSNPOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); +#ifdef GUI virtual QWidget* getEditWidget(QWidget* caller) override; - +#endif virtual const QString checkValidity() const override; //-- parameters -- @@ -164,8 +167,9 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride virtual void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; const QString loadData(const QString& fileName); +#ifdef GUI virtual QWidget* getEditWidget(QWidget* caller) override; - +#endif virtual const QString checkValidity() const override; //parameters diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 522c25f1..07be7aa7 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -10,6 +10,16 @@ #include "TRandom2.h" #include "TVector3.h" +#ifdef GUI +#include +#include +#include +#include +#include +#include +#include +#endif + #define MODEL_VERSION 3 void PhScatClaudioModel::printConfiguration(int iWave) @@ -65,13 +75,7 @@ bool PhScatClaudioModel::readFromJson(QJsonObject &json) return true; } -#include -#include -#include -#include -#include -#include -#include +#ifdef GUI QWidget *PhScatClaudioModel::getEditWidget(QWidget *) { QFrame* f = new QFrame(); @@ -121,6 +125,7 @@ QWidget *PhScatClaudioModel::getEditWidget(QWidget *) return f; } +#endif const QString PhScatClaudioModel::checkValidity() const { diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index bec2846c..5f22f610 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -28,8 +28,9 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); +#ifdef GUI virtual QWidget* getEditWidget(QWidget* caller) override; - +#endif virtual const QString checkValidity() const override; // interface properties diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index b8fa3a3c..216125b2 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -9,6 +9,15 @@ #include "TComplex.h" #include "TRandom2.h" +#ifdef GUI +#include +#include +#include +#include +#include +#include +#endif + void ScatterOnMetal::printConfiguration(int /*iWave*/) { qDebug() << "-------Configuration:-------"; @@ -48,12 +57,7 @@ bool ScatterOnMetal::readFromJson(QJsonObject &json) return true; } -#include -#include -#include -#include -#include -#include +#ifdef GUI QWidget *ScatterOnMetal::getEditWidget(QWidget *) { QFrame* f = new QFrame(); @@ -83,6 +87,7 @@ QWidget *ScatterOnMetal::getEditWidget(QWidget *) return f; } +#endif const QString ScatterOnMetal::checkValidity() const { diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index b763e974..c20e04af 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -25,8 +25,9 @@ class ScatterOnMetal : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); +#ifdef GUI virtual QWidget* getEditWidget(QWidget* caller) override; - +#endif virtual const QString checkValidity() const override; //data From 54fb187f4e0f8b3accc5a88a84889847c2339ee2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 17:57:14 +0100 Subject: [PATCH 009/140] ++ --- src/common/aopticaloverride.cpp | 92 +++++++++++++++++-- src/common/aopticaloverride.h | 24 +++-- .../aopticaloverridedialog.cpp | 8 +- .../MainWindowTools/aopticaloverridedialog.h | 6 +- src/gui/graphwindowclass.cpp | 8 ++ src/gui/graphwindowclass.h | 1 + src/gui/mainwindow.cpp | 2 +- src/modules/amaterialparticlecolection.cpp | 14 +++ src/modules/amaterialparticlecolection.h | 4 + src/modules/phscatclaudiomodel.cpp | 4 +- src/modules/phscatclaudiomodel.h | 4 +- src/modules/scatteronmetal.cpp | 4 +- src/modules/scatteronmetal.h | 4 +- 13 files changed, 141 insertions(+), 34 deletions(-) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 811922f4..3533d976 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -48,7 +48,7 @@ bool AOpticalOverride::readFromJson(QJsonObject &json) #ifdef GUI #include -QWidget *AOpticalOverride::getEditWidget(QWidget *) +QWidget *AOpticalOverride::getEditWidget(QWidget *, GraphWindowClass *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -258,7 +258,7 @@ bool BasicOpticalOverride::readFromJson(QJsonObject &json) } #ifdef GUI -QWidget *BasicOpticalOverride::getEditWidget(QWidget*) +QWidget *BasicOpticalOverride::getEditWidget(QWidget*, GraphWindowClass *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -299,7 +299,6 @@ QWidget *BasicOpticalOverride::getEditWidget(QWidget*) QComboBox* com = new QComboBox(); com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); com->setCurrentIndex(scatterModel); - //QObject::connect(com, &QComboBox::activated, [com, this](int index) { this->scatterModel = index; } ); QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->scatterModel = index; } ); l->addWidget(com); hl->addLayout(l); @@ -308,7 +307,7 @@ QWidget *BasicOpticalOverride::getEditWidget(QWidget*) } #endif -const QString BasicOpticalOverride::checkValidity() const +const QString BasicOpticalOverride::checkOverrideData() const { if (probLoss<0 || probLoss>1.0) return "Absorption probability should be within [0, 1.0]"; if (probRef <0 || probRef >1.0) return "Reflection probability should be within [0, 1.0]"; @@ -510,7 +509,7 @@ bool FSNPOpticalOverride::readFromJson(QJsonObject &json) } #ifdef GUI -QWidget *FSNPOpticalOverride::getEditWidget(QWidget *) +QWidget *FSNPOpticalOverride::getEditWidget(QWidget *, GraphWindowClass *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -532,7 +531,7 @@ QWidget *FSNPOpticalOverride::getEditWidget(QWidget *) } #endif -const QString FSNPOpticalOverride::checkValidity() const +const QString FSNPOpticalOverride::checkOverrideData() const { if (Albedo<0 || Albedo>1.0) return "Albedo should be within [0, 1.0]"; return ""; @@ -881,6 +880,7 @@ const QString SpectralBasicOpticalOverride::loadData(const QString &fileName) return ""; } +#ifdef GUI void SpectralBasicOpticalOverride::loadSpectralData(QWidget* caller) { QString fileName = QFileDialog::getOpenFileName(caller, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", "", "Data files (*.dat *.txt);;All files (*)"); @@ -892,8 +892,80 @@ void SpectralBasicOpticalOverride::loadSpectralData(QWidget* caller) if (!err.isEmpty()) message(err, caller); } +#include "TMultiGraph.h" +#include "TGraph.h" +#include "graphwindowclass.h" +void SpectralBasicOpticalOverride::showLoaded(GraphWindowClass* GraphWindow) +{ + QVector Fr; + for (int i=0; iConstructTGraph(Wave, ProbLoss, "Absorption", "Wavelength, nm", "", 2, 20, 1, 2); + mg->Add(gLoss, "LP"); + TGraph* gRef = GraphWindow->ConstructTGraph(Wave, ProbRef, "Specular reflection", "Wavelength, nm", "", 4, 21, 1, 4); + mg->Add(gRef, "LP"); + TGraph* gDiff = GraphWindow->ConstructTGraph(Wave, ProbDiff, "Diffuse scattering", "Wavelength, nm", "", 7, 22, 1, 7); + mg->Add(gDiff, "LP"); + TGraph* gFr = GraphWindow->ConstructTGraph(Wave, Fr, "Fresnel", "Wavelength, nm", "", 1, 24, 1, 1, 1, 1); + mg->Add(gFr, "LP"); + + mg->SetMinimum(0); + GraphWindow->Draw(mg, "apl"); + mg->GetXaxis()->SetTitle("Wavelength, nm"); + mg->GetYaxis()->SetTitle("Probability"); + GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); +} + +void SpectralBasicOpticalOverride::showBinned(QWidget *widget, GraphWindowClass *GraphWindow) +{ + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + //TODO run checker + + if (!bWR) + { + QString s = "Simulation is configured as not wavelength-resolved\n"; + s += "All photons will have the same properties:\n"; + s +=QString("Absorption: %1").arg(probLoss) + "\n"; + s +=QString("Specular reflection: %1").arg(probRef) + "\n"; + s +=QString("Scattering: %1").arg(probDiff); + message(s, widget); + return; + } + + QVector waveIndex; + for (int i=0; i Fr; + for (int i=0; iConstructTGraph(waveIndex, ProbLossBinned, "Loss", "Wave index", "Loss", 2, 20, 1, 2); + mg->Add(gLoss, "LP"); + TGraph* gRef = GraphWindow->ConstructTGraph(waveIndex, ProbRefBinned, "Specular reflection", "Wave index", "Reflection", 4, 21, 1, 4); + mg->Add(gRef, "LP"); + TGraph* gDiff = GraphWindow->ConstructTGraph(waveIndex, ProbDiffBinned, "Diffuse scattering", "Wave index", "Scatter", 7, 22, 1, 7); + mg->Add(gDiff, "LP"); + TGraph* gFr = GraphWindow->ConstructTGraph(waveIndex, Fr, "Fresnel", "Wave index", "", 1, 24, 1, 1, 1, 1); + mg->Add(gFr, "LP"); + + mg->SetMinimum(0); + GraphWindow->Draw(mg, "apl"); + mg->GetXaxis()->SetTitle("Wave index"); + mg->GetYaxis()->SetTitle("Probability"); + GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); +} +#endif + #ifdef GUI -QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller) +QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -907,10 +979,10 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller) QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); l->addWidget(pb); pb = new QPushButton("Show"); - //QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, this] {showLoaded(GraphWindow);}); l->addWidget(pb); pb = new QPushButton("Binned"); - //QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); + QObject::connect(pb, &QPushButton::clicked, [caller, GraphWindow, this] {showBinned(caller, GraphWindow);}); l->addWidget(pb); vl->addLayout(l); l = new QHBoxLayout(); @@ -941,7 +1013,7 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller) } #endif -const QString SpectralBasicOpticalOverride::checkValidity() const +const QString SpectralBasicOpticalOverride::checkOverrideData() const { //checking spectrum if (Wave.size() == 0) return "Spectral data are not defined"; diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index e88c1b1a..2b5ee2d5 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -12,6 +12,8 @@ class TH1I; class QJsonObject; class TH1D; class QWidget; +class TObject; +class GraphWindowClass; AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); const QStringList GetListOvAvailableOverrides(); @@ -43,9 +45,9 @@ class AOpticalOverride void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} #ifdef GUI - virtual QWidget* getEditWidget(QWidget* caller); + virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow); #endif - virtual const QString checkValidity() const {return "";} //TODO after all are done, make = 0 + virtual const QString checkOverrideData() const {return "";} //TODO after all are done, make = 0 // read-out variables for standalone checker only (not multithreaded) ScatterStatusEnum Status; // type of interaction which happened - use in 1 thread only! @@ -55,7 +57,6 @@ class AOpticalOverride int MatFrom, MatTo; // material index of material before(from) and after(to) the optical interface void RandomDir(TRandom2* RandGen, APhoton* Photon); - }; class BasicOpticalOverride : public AOpticalOverride @@ -76,9 +77,9 @@ class BasicOpticalOverride : public AOpticalOverride virtual bool readFromJson(QJsonObject &json); #ifdef GUI - virtual QWidget* getEditWidget(QWidget *caller) override; + virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkValidity() const override; + virtual const QString checkOverrideData() const override; double probLoss = 0; //probability of absorption double probRef = 0; //probability of specular reflection @@ -106,9 +107,9 @@ class FSNPOpticalOverride : public AOpticalOverride virtual bool readFromJson(QJsonObject &json); #ifdef GUI - virtual QWidget* getEditWidget(QWidget* caller) override; + virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkValidity() const override; + virtual const QString checkOverrideData() const override; //-- parameters -- double Albedo; @@ -168,9 +169,10 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride const QString loadData(const QString& fileName); #ifdef GUI - virtual QWidget* getEditWidget(QWidget* caller) override; + virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkValidity() const override; + + virtual const QString checkOverrideData() const override; //parameters QVector Wave; @@ -184,7 +186,11 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride double effectiveWaveIndex; private: +#ifdef GUI void loadSpectralData(QWidget *caller); + void showLoaded(GraphWindowClass *GraphWindow); + void showBinned(QWidget *widget, GraphWindowClass *GraphWindow); +#endif }; #endif // OPTICALOVERRIDECLASS_H diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index e872fef0..cabedba5 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -8,8 +8,8 @@ #include AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, - int matFrom, int matTo, QWidget *parent) : - QDialog(parent), ui(new Ui::AOpticalOverrideDialog), + int matFrom, int matTo, GraphWindowClass * GraphWindow, QWidget * parent) : + QDialog(parent), ui(new Ui::AOpticalOverrideDialog), GraphWindow(GraphWindow), MatCollection(MatCollection), matFrom(matFrom), matTo(matTo), matNames(MatCollection->getListOfMaterialNames()) { ui->setupUi(this); @@ -57,7 +57,7 @@ void AOpticalOverrideDialog::updateGui() ui->cobType->setCurrentIndex(index+1); QVBoxLayout* l = static_cast(layout()); - customWidget = ovLocal->getEditWidget(this); + customWidget = ovLocal->getEditWidget(this, GraphWindow); l->insertWidget(customWidgetPositionInLayout, customWidget); } else @@ -71,7 +71,7 @@ void AOpticalOverrideDialog::on_pbAccept_clicked() { if (ovLocal) { - QString err = ovLocal->checkValidity(); + QString err = ovLocal->checkOverrideData(); if (!err.isEmpty()) { message(err, this); diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.h b/src/gui/MainWindowTools/aopticaloverridedialog.h index 1d90a7fb..182402ad 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.h +++ b/src/gui/MainWindowTools/aopticaloverridedialog.h @@ -10,13 +10,14 @@ class AOpticalOverrideDialog; class AOpticalOverride; class AMaterialParticleCollection; +class GraphWindowClass; class AOpticalOverrideDialog : public QDialog { Q_OBJECT public: - explicit AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, int matFrom, int matTo, QWidget *parent = 0); + explicit AOpticalOverrideDialog(AMaterialParticleCollection* MatCollection, int matFrom, int matTo, GraphWindowClass* GraphWindow, QWidget* parent); ~AOpticalOverrideDialog(); private slots: @@ -26,7 +27,8 @@ private slots: void on_pbTestOverride_clicked(); private: - Ui::AOpticalOverrideDialog *ui; + Ui::AOpticalOverrideDialog * ui; + GraphWindowClass * GraphWindow; AOpticalOverride ** pOV; AOpticalOverride * ovLocal = 0; AMaterialParticleCollection* MatCollection; diff --git a/src/gui/graphwindowclass.cpp b/src/gui/graphwindowclass.cpp index 8dcf7340..2886f14a 100644 --- a/src/gui/graphwindowclass.cpp +++ b/src/gui/graphwindowclass.cpp @@ -1433,6 +1433,14 @@ void GraphWindowClass::DrawStrOpt(TObject *obj, QString options, bool DoUpdate) Draw(obj, options.toLatin1().data(), DoUpdate, false); } +void GraphWindowClass::onDrawRequest(TObject *obj, const QString options, bool transferOwnership, bool focusWindow) +{ + if (focusWindow) + Draw(obj, options.toLatin1().data(), true, transferOwnership); + else + DrawWithoutFocus(obj, options.toLatin1().data(), true, transferOwnership); +} + void SetMarkerAttributes(TAttMarker* m, const QVariantList& vl) { m->SetMarkerColor(vl.at(0).toInt()); diff --git a/src/gui/graphwindowclass.h b/src/gui/graphwindowclass.h index 568c5740..951b8f89 100644 --- a/src/gui/graphwindowclass.h +++ b/src/gui/graphwindowclass.h @@ -177,6 +177,7 @@ public slots: QVector Get2DArray(); //for temporary script command void DrawStrOpt(TObject* obj, QString options = "", bool DoUpdate = true); + void onDrawRequest(TObject* obj, const QString options, bool transferOwnership, bool focusWindow); bool DrawTree(TTree* tree, const QString& what, const QString& cond, const QString& how, const QVariantList binsAndRanges = QVariantList(), const QVariantList markersAndLines = QVariantList(), QString *result = 0); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 07139fe4..399d7715 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -867,7 +867,7 @@ void MainWindow::on_pbEditOverride_clicked() int From = ui->cobMaterialForOverrides->currentIndex(); int To = ui->cobMaterialTo->currentIndex(); - AOpticalOverrideDialog d(MpCollection, From, To, this); + AOpticalOverrideDialog d(MpCollection, From, To, GraphWindow, this); int res = d.exec(); if (res == 1) { diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index 9c869c74..b48f998a 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -46,6 +46,20 @@ void AMaterialParticleCollection::SetWave(bool wavelengthResolved, double waveFr WaveNodes = waveNodes; } +void AMaterialParticleCollection::GetWave(bool &wavelengthResolved, double &waveFrom, double &waveTo, double &waveStep, int &waveNodes) const +{ + wavelengthResolved = WavelengthResolved; + waveFrom = WaveFrom; + waveTo = WaveTo; + waveStep = WaveStep; + waveNodes = WaveNodes; +} + +bool AMaterialParticleCollection::IsWaveResolved() const +{ + return WavelengthResolved; +} + void AMaterialParticleCollection::UpdateRuntimePropertiesAndWavelengthBinning(GeneralSimSettings *SimSet, TRandom2* RandGen, int numThreads) { AMaterialParticleCollection::SetWave(SimSet->fWaveResolved, SimSet->WaveFrom, SimSet->WaveTo, SimSet->WaveStep, SimSet->WaveNodes); diff --git a/src/modules/amaterialparticlecolection.h b/src/modules/amaterialparticlecolection.h index 82edbf00..7d93ffe2 100644 --- a/src/modules/amaterialparticlecolection.h +++ b/src/modules/amaterialparticlecolection.h @@ -82,6 +82,10 @@ class AMaterialParticleCollection : public QObject bool readFromJson(QJsonObject &json); void AddNewMaterial(QJsonObject &json); + //general purpose requests + void GetWave(bool& wavelengthResolved, double& waveFrom, double& waveTo, double& waveStep, int& waveNodes) const; + bool IsWaveResolved() const; + public: void ConvertToStandardWavelengthes(QVector *sp_x, QVector *sp_y, QVector *y); int FindCreateParticle(QString Name, AParticle::ParticleType Type, int Charge, double Mass, bool fOnlyFind = false); diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 07be7aa7..03d42423 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -76,7 +76,7 @@ bool PhScatClaudioModel::readFromJson(QJsonObject &json) } #ifdef GUI -QWidget *PhScatClaudioModel::getEditWidget(QWidget *) +QWidget *PhScatClaudioModel::getEditWidget(QWidget *, GraphWindowClass *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -127,7 +127,7 @@ QWidget *PhScatClaudioModel::getEditWidget(QWidget *) } #endif -const QString PhScatClaudioModel::checkValidity() const +const QString PhScatClaudioModel::checkOverrideData() const { if (sigma_alpha < 0) return "sigma alpha should be >= 0"; if (sigma_h < 0) return "sigma h should be >= 0"; diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index 5f22f610..cc772bba 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -29,9 +29,9 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! virtual bool readFromJson(QJsonObject &json); #ifdef GUI - virtual QWidget* getEditWidget(QWidget* caller) override; + virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkValidity() const override; + virtual const QString checkOverrideData() const override; // interface properties double sigma_alpha = 0.18; // r.m.s. (or similar) of the slope distribution diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index 216125b2..f4892c76 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -58,7 +58,7 @@ bool ScatterOnMetal::readFromJson(QJsonObject &json) } #ifdef GUI -QWidget *ScatterOnMetal::getEditWidget(QWidget *) +QWidget *ScatterOnMetal::getEditWidget(QWidget *, GraphWindowClass *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); @@ -89,7 +89,7 @@ QWidget *ScatterOnMetal::getEditWidget(QWidget *) } #endif -const QString ScatterOnMetal::checkValidity() const +const QString ScatterOnMetal::checkOverrideData() const { return ""; } diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index c20e04af..c4a67032 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -26,9 +26,9 @@ class ScatterOnMetal : public AOpticalOverride virtual bool readFromJson(QJsonObject &json); #ifdef GUI - virtual QWidget* getEditWidget(QWidget* caller) override; + virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkValidity() const override; + virtual const QString checkOverrideData() const override; //data double RealN = 1.07; From 5117ed9389cadf9afe65a68c6f03c60a6fdc3a8b Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 22:38:12 +0100 Subject: [PATCH 010/140] ++ --- src/common/aopticaloverride.cpp | 176 +++++++++++++++++- src/common/aopticaloverride.h | 19 +- .../aopticaloverridedialog.cpp | 4 +- 3 files changed, 195 insertions(+), 4 deletions(-) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 3533d976..8613dd70 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -30,6 +30,8 @@ #include #include #include "amessage.h" +#include "TGraph.h" +#include "graphwindowclass.h" #endif void AOpticalOverride::writeToJson(QJsonObject &json) @@ -341,7 +343,7 @@ AOpticalOverride *OpticalOverrideFactory(QString model, AMaterialParticleCollect return NULL; //undefined override type! } -const QStringList GetListOvAvailableOverrides() +const QStringList ListOvAllOpticalOverrideTypes() { QStringList l; @@ -723,6 +725,178 @@ bool AWaveshifterOverride::readFromJson(QJsonObject &json) return true; } +#ifdef GUI +QWidget *AWaveshifterOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QVBoxLayout* vl = new QVBoxLayout(f); + QHBoxLayout* l = new QHBoxLayout(); + QLabel* lab = new QLabel("Reemission generation:"); + l->addWidget(lab); + QComboBox* com = new QComboBox(); + com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); + com->setCurrentIndex(ReemissionModel); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->ReemissionModel = index; } ); + l->addWidget(com); + vl->addLayout(l); + l = new QHBoxLayout(); + QVBoxLayout* vv = new QVBoxLayout(); + lab = new QLabel("Reemission probability:"); + vv->addWidget(lab); + lab = new QLabel("Emission spectrum:"); + vv->addWidget(lab); + l->addLayout(vv); + vv = new QVBoxLayout(); + QPushButton* pb = new QPushButton("Load"); + pb->setToolTip("Every line of the file should contain 2 numbers:\nwavelength[nm] reemission_probability[0..1]"); + QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadReemissionProbability(caller);}); + vv->addWidget(pb); + pb = new QPushButton("Load"); + pb->setToolTip("Every line of the file should contain 2 numbers:\nwavelength[nm] relative_intencity[>=0]"); + QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadEmissionSpectrum(caller);}); + vv->addWidget(pb); + l->addLayout(vv); + vv = new QVBoxLayout(); + pb = new QPushButton("Show"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showReemissionProbability(GraphWindow, caller);}); + vv->addWidget(pb); + pb = new QPushButton("Show"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showEmissionSpectrum(GraphWindow, caller);}); + vv->addWidget(pb); + l->addLayout(vv); + vv = new QVBoxLayout(); + pb = new QPushButton("Binned"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedReemissionProbability(GraphWindow, caller);}); + vv->addWidget(pb); + pb = new QPushButton("Binned"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedEmissionSpectrum(GraphWindow, caller);}); + vv->addWidget(pb); + l->addLayout(vv); + vl->addLayout(l); + lab = new QLabel("If simulation is NOT wavelength-resolved, this override does nothing!"); + lab->setAlignment(Qt::AlignCenter); + vl->addWidget(lab); + + return f; +} +#endif + +#ifdef GUI +void AWaveshifterOverride::loadReemissionProbability(QWidget* caller) +{ + QString fileName = QFileDialog::getOpenFileName(caller, "Load reemission probability", "", "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + QVector X, Y; + int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); + if (ret == 0) + { + ReemissionProbability_lambda = X; + ReemissionProbability = Y; + } +} + +void AWaveshifterOverride::loadEmissionSpectrum(QWidget *caller) +{ + QString fileName = QFileDialog::getOpenFileName(caller, "Load emission spectrum", "", "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + QVector X, Y; + int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); + if (ret == 0) + { + EmissionSpectrum_lambda = X; + EmissionSpectrum = Y; + } +} + +void AWaveshifterOverride::showReemissionProbability(GraphWindowClass *GraphWindow, QWidget* caller) +{ + if (ReemissionProbability_lambda.isEmpty()) + { + message("No data were loaded", caller); + return; + } + TGraph* gr = GraphWindow->MakeGraph(&ReemissionProbability_lambda, &ReemissionProbability, 4, "Wavelength, nm", "Reemission probability", 20, 1, 0, 0, "", true); + gr->SetTitle("Reemission probability"); + gr->SetMinimum(0); + GraphWindow->Draw(gr, "apl"); +} + +void AWaveshifterOverride::showEmissionSpectrum(GraphWindowClass *GraphWindow, QWidget *caller) +{ + if (EmissionSpectrum_lambda.isEmpty()) + { + message("No data were loaded", caller); + return; + } + TGraph* gr = GraphWindow->MakeGraph(&EmissionSpectrum_lambda, &EmissionSpectrum, 2, "Wavelength, nm", "Relative intensity, a.u.", 20, 1, 0, 0, "", true); + gr->SetTitle("Emission spectrum"); + gr->SetMinimum(0); + GraphWindow->Draw(gr, "apl"); +} + +void AWaveshifterOverride::showBinnedReemissionProbability(GraphWindowClass *GraphWindow, QWidget *caller) +{ + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + //TODO run checker + + if (!bWR) + { + message("Simulation is NOT wavelength resolved, override is inactive!", caller); + return; + } + + QVector waveIndex; + for (int i=0; iConstructTGraph(waveIndex, ReemissionProbabilityBinned, "Reemission probability (binned)", "Wave index", "Reemission probability, a.u.", 2, 20, 1, 2); + gr->SetMinimum(0); + GraphWindow->Draw(gr, "apl"); +} + +void AWaveshifterOverride::showBinnedEmissionSpectrum(GraphWindowClass *GraphWindow, QWidget *caller) +{ + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + //TODO run checker + + if (!bWR) + { + message("Simulation is NOT wavelength resolved, override is inactive!", caller); + return; + } + + double integral = Spectrum->ComputeIntegral(); + if (integral <= 0) + { + message("Binned emission spectrum: integral <=0, override will report an error!", caller); + return; + } + + TH1D* SpectrumCopy = new TH1D(*Spectrum); + SpectrumCopy->SetTitle("Binned emission spectrum"); + SpectrumCopy->GetXaxis()->SetTitle("Wave index"); + SpectrumCopy->GetYaxis()->SetTitle("Relative intensity, a.u."); + GraphWindow->Draw(SpectrumCopy, "hist"); +} +#endif + +const QString AWaveshifterOverride::checkOverrideData() const +{ + return ""; +} + // ---------------- SpectralSimplistic ------------------- SpectralBasicOpticalOverride::SpectralBasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) : BasicOpticalOverride(MatCollection, MatFrom, MatTo, 0,0,0, 1), effectiveWavelength(500) diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 2b5ee2d5..19947cbc 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -15,8 +15,9 @@ class QWidget; class TObject; class GraphWindowClass; +//modify these two functions if you want to register a new override type! AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); -const QStringList GetListOvAvailableOverrides(); +const QStringList ListOvAllOpticalOverrideTypes(); class AOpticalOverride { @@ -36,6 +37,7 @@ class AOpticalOverride virtual void printConfiguration(int iWave) = 0; virtual QString getType() const = 0; virtual QString getReportLine() = 0; // for GUI: reports override status "to material blabla (#id): properies" + //TODO: initializeWaveResolved() -> no need to transfer data, MatCollection knows the settings virtual void initializeWaveResolved(bool /*bWaveResolved*/, double /*waveFrom*/, double /*waveStep*/, int /*waveNodes*/) {} //override if override has wavelength-resolved data // save/load config @@ -132,6 +134,11 @@ class AWaveshifterOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); +#ifdef GUI + virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; +#endif + virtual const QString checkOverrideData() const override; + //-- parameters -- int ReemissionModel = 1; //0-isotropic (4Pi), 1-Lamb back (2Pi), 2-Lamb forward (2Pi) QVector ReemissionProbability_lambda; @@ -146,6 +153,16 @@ class AWaveshifterOverride : public AOpticalOverride double WaveFrom; double WaveStep; int WaveNodes; + +private: +#ifdef GUI + void loadReemissionProbability(QWidget *caller); + void loadEmissionSpectrum(QWidget *caller); + void showReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); + void showEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); + void showBinnedReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); + void showBinnedEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); +#endif }; class SpectralBasicOpticalOverride : public BasicOpticalOverride diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index cabedba5..85de7fd1 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -20,7 +20,7 @@ AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * Mat ui->leMatFrom->setText(matNames.at(matFrom)); ui->leMatTo->setText(matNames.at(matTo)); ui->cobType->addItem("No special rule"); - QStringList avOv = GetListOvAvailableOverrides(); + QStringList avOv = ListOvAllOpticalOverrideTypes(); ui->cobType->addItems(avOv); AOpticalOverride* ov = (*MatCollection)[matFrom]->OpticalOverrides[matTo]; @@ -52,7 +52,7 @@ void AOpticalOverrideDialog::updateGui() ui->frNoOverride->setVisible(false); ui->pbTestOverride->setVisible(true); - QStringList avOv = GetListOvAvailableOverrides(); + QStringList avOv = ListOvAllOpticalOverrideTypes(); int index = avOv.indexOf(ovLocal->getType()); //TODO -> if not found? ui->cobType->setCurrentIndex(index+1); From 735ab9df3436fbacd682120e888c6764d229cdda Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 23:01:52 +0100 Subject: [PATCH 011/140] ++ --- src/common/aopticaloverride.cpp | 34 ++++++++++++++++++++---------- src/common/aopticaloverride.h | 10 ++++----- src/modules/phscatclaudiomodel.cpp | 2 +- src/modules/phscatclaudiomodel.h | 2 +- src/modules/scatteronmetal.cpp | 2 +- src/modules/scatteronmetal.h | 2 +- 6 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 8613dd70..715b15d0 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -309,7 +309,7 @@ QWidget *BasicOpticalOverride::getEditWidget(QWidget*, GraphWindowClass *) } #endif -const QString BasicOpticalOverride::checkOverrideData() const +const QString BasicOpticalOverride::checkOverrideData() { if (probLoss<0 || probLoss>1.0) return "Absorption probability should be within [0, 1.0]"; if (probRef <0 || probRef >1.0) return "Reflection probability should be within [0, 1.0]"; @@ -533,7 +533,7 @@ QWidget *FSNPOpticalOverride::getEditWidget(QWidget *, GraphWindowClass *) } #endif -const QString FSNPOpticalOverride::checkOverrideData() const +const QString FSNPOpticalOverride::checkOverrideData() { if (Albedo<0 || Albedo>1.0) return "Albedo should be within [0, 1.0]"; return ""; @@ -819,8 +819,7 @@ void AWaveshifterOverride::showReemissionProbability(GraphWindowClass *GraphWind message("No data were loaded", caller); return; } - TGraph* gr = GraphWindow->MakeGraph(&ReemissionProbability_lambda, &ReemissionProbability, 4, "Wavelength, nm", "Reemission probability", 20, 1, 0, 0, "", true); - gr->SetTitle("Reemission probability"); + TGraph* gr = GraphWindow->ConstructTGraph(ReemissionProbability_lambda, ReemissionProbability, "Reemission probability", "Wavelength, nm", "Reemission probability, a.u.", 2, 20, 1, 2, 2); gr->SetMinimum(0); GraphWindow->Draw(gr, "apl"); } @@ -832,8 +831,10 @@ void AWaveshifterOverride::showEmissionSpectrum(GraphWindowClass *GraphWindow, Q message("No data were loaded", caller); return; } - TGraph* gr = GraphWindow->MakeGraph(&EmissionSpectrum_lambda, &EmissionSpectrum, 2, "Wavelength, nm", "Relative intensity, a.u.", 20, 1, 0, 0, "", true); - gr->SetTitle("Emission spectrum"); + TGraph* gr = GraphWindow->ConstructTGraph(EmissionSpectrum_lambda, EmissionSpectrum, + "Emission spectrum", "Wavelength, nm", "Relative intensity, a.u.", + 4, 20, 1, + 4, 2); gr->SetMinimum(0); GraphWindow->Draw(gr, "apl"); } @@ -856,7 +857,10 @@ void AWaveshifterOverride::showBinnedReemissionProbability(GraphWindowClass *Gra QVector waveIndex; for (int i=0; iConstructTGraph(waveIndex, ReemissionProbabilityBinned, "Reemission probability (binned)", "Wave index", "Reemission probability, a.u.", 2, 20, 1, 2); + TGraph* gr = GraphWindow->ConstructTGraph(waveIndex, ReemissionProbabilityBinned, + "Reemission probability (binned)", "Wave index", "Reemission probability, a.u.", + 2, 20, 1, + 2, 2); gr->SetMinimum(0); GraphWindow->Draw(gr, "apl"); } @@ -886,14 +890,22 @@ void AWaveshifterOverride::showBinnedEmissionSpectrum(GraphWindowClass *GraphWin TH1D* SpectrumCopy = new TH1D(*Spectrum); SpectrumCopy->SetTitle("Binned emission spectrum"); - SpectrumCopy->GetXaxis()->SetTitle("Wave index"); + SpectrumCopy->GetXaxis()->SetTitle("Wavelength, nm"); SpectrumCopy->GetYaxis()->SetTitle("Relative intensity, a.u."); - GraphWindow->Draw(SpectrumCopy, "hist"); + GraphWindow->Draw(SpectrumCopy, "hist"); //gets ownership of the copy } #endif -const QString AWaveshifterOverride::checkOverrideData() const +const QString AWaveshifterOverride::checkOverrideData() { + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + if (bWR && Spectrum->ComputeIntegral() <= 0) + return "Binned emission spectrum: integral should be > 0"; return ""; } @@ -1187,7 +1199,7 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller, GraphWindo } #endif -const QString SpectralBasicOpticalOverride::checkOverrideData() const +const QString SpectralBasicOpticalOverride::checkOverrideData() { //checking spectrum if (Wave.size() == 0) return "Spectral data are not defined"; diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 19947cbc..9ad8ecc6 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -49,7 +49,7 @@ class AOpticalOverride #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow); #endif - virtual const QString checkOverrideData() const {return "";} //TODO after all are done, make = 0 + virtual const QString checkOverrideData() {return "";} //TODO after all are done, make = 0 // read-out variables for standalone checker only (not multithreaded) ScatterStatusEnum Status; // type of interaction which happened - use in 1 thread only! @@ -81,7 +81,7 @@ class BasicOpticalOverride : public AOpticalOverride #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkOverrideData() const override; + virtual const QString checkOverrideData() override; double probLoss = 0; //probability of absorption double probRef = 0; //probability of specular reflection @@ -111,7 +111,7 @@ class FSNPOpticalOverride : public AOpticalOverride #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkOverrideData() const override; + virtual const QString checkOverrideData() override; //-- parameters -- double Albedo; @@ -137,7 +137,7 @@ class AWaveshifterOverride : public AOpticalOverride #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkOverrideData() const override; + virtual const QString checkOverrideData() override; //-- parameters -- int ReemissionModel = 1; //0-isotropic (4Pi), 1-Lamb back (2Pi), 2-Lamb forward (2Pi) @@ -189,7 +189,7 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkOverrideData() const override; + virtual const QString checkOverrideData() override; //parameters QVector Wave; diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 03d42423..6df6031c 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -127,7 +127,7 @@ QWidget *PhScatClaudioModel::getEditWidget(QWidget *, GraphWindowClass *) } #endif -const QString PhScatClaudioModel::checkOverrideData() const +const QString PhScatClaudioModel::checkOverrideData() { if (sigma_alpha < 0) return "sigma alpha should be >= 0"; if (sigma_h < 0) return "sigma h should be >= 0"; diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index cc772bba..7647a3b4 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -31,7 +31,7 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkOverrideData() const override; + virtual const QString checkOverrideData() override; // interface properties double sigma_alpha = 0.18; // r.m.s. (or similar) of the slope distribution diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index f4892c76..338a7c3c 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -89,7 +89,7 @@ QWidget *ScatterOnMetal::getEditWidget(QWidget *, GraphWindowClass *) } #endif -const QString ScatterOnMetal::checkOverrideData() const +const QString ScatterOnMetal::checkOverrideData() { return ""; } diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index c4a67032..3ebb4e86 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -28,7 +28,7 @@ class ScatterOnMetal : public AOpticalOverride #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif - virtual const QString checkOverrideData() const override; + virtual const QString checkOverrideData() override; //data double RealN = 1.07; From 0d76891fbd0b60e0ee2aa3791745b524c6a52b76 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 30 Sep 2018 23:14:17 +0100 Subject: [PATCH 012/140] ++ --- src/common/aopticaloverride.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 715b15d0..031befca 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -898,6 +898,16 @@ void AWaveshifterOverride::showBinnedEmissionSpectrum(GraphWindowClass *GraphWin const QString AWaveshifterOverride::checkOverrideData() { + if (ReemissionProbability_lambda.isEmpty()) + return "Reemission probability not loaded"; + if (ReemissionProbability_lambda.size() != ReemissionProbability.size()) + return "Mismatch in reemission probability data"; + + if (EmissionSpectrum_lambda.isEmpty()) + return "Emission spectrum not loaded"; + if (EmissionSpectrum_lambda.size() != EmissionSpectrum.size()) + return "Mismatch in emission spectrum data"; + bool bWR; double WaveFrom, WaveTo, WaveStep; int WaveNodes; From c145b473abc142ccc52d7989361f2e3ba45250e0 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 10:31:26 +0100 Subject: [PATCH 013/140] experimental: sinhle thread script override test --- .../aopticaloverridescriptinterface.cpp | 20 ++++ .../aopticaloverridescriptinterface.h | 32 +++++++ .../ascriptopticaloverride.cpp | 91 +++++++++++++++++++ src/OpticalOverrides/ascriptopticaloverride.h | 44 +++++++++ src/ants2.pro | 9 +- src/common/aopticaloverride.cpp | 7 +- src/common/aopticaloverride.h | 1 + 7 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 src/OpticalOverrides/aopticaloverridescriptinterface.cpp create mode 100644 src/OpticalOverrides/aopticaloverridescriptinterface.h create mode 100644 src/OpticalOverrides/ascriptopticaloverride.cpp create mode 100644 src/OpticalOverrides/ascriptopticaloverride.h diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp new file mode 100644 index 00000000..d189fc12 --- /dev/null +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -0,0 +1,20 @@ +#include "aopticaloverridescriptinterface.h" + +AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() +{ + +} + +void AOpticalOverrideScriptInterface::configure(TRandom2 *randGen, APhoton *photon, const double *normalVector) +{ + RandGen = randGen; + Photon = photon; + NormalVector = normalVector; + + ReturnResult = AOpticalOverride::NotTriggered; +} + +void AOpticalOverrideScriptInterface::Absorb() +{ + ReturnResult = AOpticalOverride::Absorbed; +} diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h new file mode 100644 index 00000000..f794e6eb --- /dev/null +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -0,0 +1,32 @@ +#ifndef AOPTICALOVERRIDESCRIPTINTERFACE_H +#define AOPTICALOVERRIDESCRIPTINTERFACE_H + +#include "ascriptinterface.h" +#include "aopticaloverride.h" + +#include + +class TRandom2; +class APhoton; + +class AOpticalOverrideScriptInterface : public AScriptInterface +{ + Q_OBJECT +public: + AOpticalOverrideScriptInterface(); + + void configure(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector); + AOpticalOverride::OpticalOverrideResultEnum getResult() const {return ReturnResult;} + +public slots: + void Absorb(); + +private: + TRandom2 * RandGen; + APhoton * Photon; + const double * NormalVector; + + AOpticalOverride::OpticalOverrideResultEnum ReturnResult; //{NotTriggered, Absorbed, Forward, Back, _Error_}; +}; + +#endif // AOPTICALOVERRIDESCRIPTINTERFACE_H diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp new file mode 100644 index 00000000..08c61cae --- /dev/null +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -0,0 +1,91 @@ +#include "ascriptopticaloverride.h" +#include "amaterialparticlecolection.h" + +#include "aopticaloverridescriptinterface.h" + +#include +#include +#include //? + + +#include "coreinterfaces.h" +AScriptOpticalOverride::AScriptOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) + : AOpticalOverride(MatCollection, MatFrom, MatTo) +{ + //to transfer away + ScriptEngine = new QScriptEngine(); //mem leak + qDebug() << "Registering script interface"; + interfaceObject = new AOpticalOverrideScriptInterface(); //mem leak + QScriptValue obj = ScriptEngine->newQObject(interfaceObject, QScriptEngine::QtOwnership); + ScriptEngine->globalObject().setProperty("photon", obj); + //coreObj = new AInterfaceToCore(this); + //QScriptValue coreVal = engine->newQObject(coreObj, QScriptEngine::QtOwnership); + //QString coreName = "core"; + //coreObj->setObjectName(coreName); + //engine->globalObject().setProperty(coreName, coreVal); + //interfaces.append(coreObj); + //registering math module + AInterfaceToMath* mathObj = new AInterfaceToMath(0); + QScriptValue mathVal = ScriptEngine->newQObject(mathObj, QScriptEngine::QtOwnership); +// mathObj->setObjectName(mathName); + ScriptEngine->globalObject().setProperty("math", mathVal); + //interfaces.append(mathObj); //SERVICE OBJECT IS FIRST in interfaces! +} + +void AScriptOpticalOverride::initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) +{ + //external script engine will have interface already registered +} + +AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +{ + //qDebug() << "Configuring script interface"; + interfaceObject->configure(RandGen, Photon, NormalVector); + //qDebug() << "Evaluating script"; + //QScriptValue res = + ScriptEngine->evaluate(Script); + //qDebug() << "eval result:" << res.toString()<<"Photon status:"<getResult(); + return interfaceObject->getResult(); +} + +void AScriptOpticalOverride::printConfiguration(int) +{ + qDebug() << "-------Configuration:-------"; + qDebug() << "Script:"; + qDebug() << Script; + qDebug() << "----------------------------"; +} + +QString AScriptOpticalOverride::getReportLine() +{ + return QString("to %1 -> Custom script").arg( (*MatCollection)[MatTo]->name ); +} + +void AScriptOpticalOverride::writeToJson(QJsonObject &json) +{ + AOpticalOverride::writeToJson(json); + + json["Script"] = Script; +} + +bool AScriptOpticalOverride::readFromJson(QJsonObject &json) +{ + QString type = json["Model"].toString(); + if (type != getType()) return false; //file for wrong model! + + Script = json["Script"].toString(); + return true; +} + +#ifdef GUI +QWidget *AScriptOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) +{ + return AOpticalOverride::getEditWidget(caller, GraphWindow); +} +#endif + +const QString AScriptOpticalOverride::checkOverrideData() +{ + if (Script.isEmpty()) return "Script not defined!"; + return ""; +} diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h new file mode 100644 index 00000000..3c8f6f9b --- /dev/null +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -0,0 +1,44 @@ +#ifndef ASCRIPTOPTICALOVERRIDE_H +#define ASCRIPTOPTICALOVERRIDE_H + +#include "aopticaloverride.h" + +#include + +//to move away +class QScriptEngine; +class AOpticalOverrideScriptInterface; + +class AScriptOpticalOverride : public AOpticalOverride +{ +public: + //AScriptOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); + AScriptOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); + virtual ~AScriptOpticalOverride() {} + + //TODO transfer to a separate entry, external pointer to ScriptEngine + void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; + + virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved + + virtual void printConfiguration(int iWave) override; + virtual QString getType() const override {return "CustomScript";} + virtual QString getReportLine() override; + + virtual void writeToJson(QJsonObject &json) override; + virtual bool readFromJson(QJsonObject &json) override; + +#ifdef GUI + virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; +#endif + virtual const QString checkOverrideData() override; + +private: + QString Script = "photon.Absorb()"; + + //will be moved to a separate class and made thread-safe + QScriptEngine* ScriptEngine; + AOpticalOverrideScriptInterface* interfaceObject; +}; + +#endif // ASCRIPTOPTICALOVERRIDE_H diff --git a/src/ants2.pro b/src/ants2.pro index 58e30618..a8088932 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -348,7 +348,9 @@ SOURCES += main.cpp \ Net/agridrunner.cpp \ Net/aremoteserverrecord.cpp \ common/atrackbuildoptions.cpp \ - gui/MainWindowTools/aopticaloverridedialog.cpp + gui/MainWindowTools/aopticaloverridedialog.cpp \ + OpticalOverrides/aopticaloverridescriptinterface.cpp \ + OpticalOverrides/ascriptopticaloverride.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -473,7 +475,9 @@ HEADERS += common/CorrelationFilters.h \ Net/agridrunner.h \ Net/aremoteserverrecord.h \ common/atrackbuildoptions.h \ - gui/MainWindowTools/aopticaloverridedialog.h + gui/MainWindowTools/aopticaloverridedialog.h \ + OpticalOverrides/aopticaloverridescriptinterface.h \ + OpticalOverrides/ascriptopticaloverride.h # --- SIM --- ants2_SIM { @@ -688,6 +692,7 @@ INCLUDEPATH += gui/GraphWindowTools INCLUDEPATH += gui/MainWindowTools INCLUDEPATH += SplineLibrary +INCLUDEPATH += OpticalOverrides INCLUDEPATH += modules INCLUDEPATH += modules/lrf_v2 INCLUDEPATH += modules/lrf_v3 diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 031befca..b677a179 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -9,6 +9,7 @@ #ifdef SIM #include "phscatclaudiomodel.h" #include "scatteronmetal.h" +#include "ascriptopticaloverride.h" #endif #include @@ -340,6 +341,9 @@ AOpticalOverride *OpticalOverrideFactory(QString model, AMaterialParticleCollect return new FSNPOpticalOverride(MatCollection, MatFrom, MatTo); else if (model == "SurfaceWLS") return new AWaveshifterOverride(MatCollection, MatFrom, MatTo); + else if (model == "CustomScript") + return new AScriptOpticalOverride(MatCollection, MatFrom, MatTo); + return NULL; //undefined override type! } @@ -352,7 +356,8 @@ const QStringList ListOvAllOpticalOverrideTypes() << "Claudio_Model_V2d2" << "DielectricToMetal" << "FS_NP" - << "SurfaceWLS"; + << "SurfaceWLS" + << "CustomScript"; return l; } diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 9ad8ecc6..09d75bb4 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -83,6 +83,7 @@ class BasicOpticalOverride : public AOpticalOverride #endif virtual const QString checkOverrideData() override; + //--parameters-- double probLoss = 0; //probability of absorption double probRef = 0; //probability of specular reflection double probDiff = 0; //probability of scattering From 060264bcbb48f51f115ced7091d2d46166951bfc Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 11:22:41 +0100 Subject: [PATCH 014/140] ++ --- .../aopticaloverridescriptinterface.cpp | 39 +++++++++++++++++++ .../aopticaloverridescriptinterface.h | 8 +++- src/OpticalOverrides/ascriptopticaloverride.h | 4 +- src/common/aphoton.h | 17 ++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index d189fc12..8a785b3f 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -1,5 +1,7 @@ #include "aopticaloverridescriptinterface.h" +#include "aphoton.h" + AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() { @@ -11,10 +13,47 @@ void AOpticalOverrideScriptInterface::configure(TRandom2 *randGen, APhoton *phot Photon = photon; NormalVector = normalVector; + //if script did not modify any photon properties, this will be the result: + bResultAlreadySet = true; ReturnResult = AOpticalOverride::NotTriggered; } +AOpticalOverride::OpticalOverrideResultEnum AOpticalOverrideScriptInterface::getResult() const +{ + if (bResultAlreadySet) return ReturnResult; + + Photon->ensureUnitaryLength(); + double sum = 0; + for (int i=0; i<3; i++) + sum += Photon->v[i] * NormalVector[i]; + if (sum < 0) + return AOpticalOverride::Back; + else return AOpticalOverride::Forward; +} + void AOpticalOverrideScriptInterface::Absorb() { ReturnResult = AOpticalOverride::Absorbed; + bResultAlreadySet = true; +} + +void AOpticalOverrideScriptInterface::Fresnel() +{ + bResultAlreadySet = true; + ReturnResult = AOpticalOverride::NotTriggered; +} + +void AOpticalOverrideScriptInterface::TransmissionDirect() +{ + bResultAlreadySet = true; + ReturnResult = AOpticalOverride::Forward; +} + +#include +void AOpticalOverrideScriptInterface::SetDirection(double vx, double vy, double vz) +{ + Photon->v[0] = vx; + Photon->v[1] = vy; + Photon->v[2] = vz; + bResultAlreadySet = false; } diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index f794e6eb..095d18ad 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -16,16 +16,22 @@ class AOpticalOverrideScriptInterface : public AScriptInterface AOpticalOverrideScriptInterface(); void configure(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector); - AOpticalOverride::OpticalOverrideResultEnum getResult() const {return ReturnResult;} + AOpticalOverride::OpticalOverrideResultEnum getResult() const; public slots: void Absorb(); + void Fresnel(); + //void TransmissionSnell(); //check was meddled + void TransmissionDirect(); //check was meddled + + void SetDirection(double vx, double vy, double vz); private: TRandom2 * RandGen; APhoton * Photon; const double * NormalVector; + bool bResultAlreadySet; AOpticalOverride::OpticalOverrideResultEnum ReturnResult; //{NotTriggered, Absorbed, Forward, Back, _Error_}; }; diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index 3c8f6f9b..93a28bfe 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -34,7 +34,9 @@ class AScriptOpticalOverride : public AOpticalOverride virtual const QString checkOverrideData() override; private: - QString Script = "photon.Absorb()"; + QString Script = "photon.SetDirection(0, 0, 1)"; + //QString Script = "photon.Fresnel()"; + //QString Script = "photon.Absorb()"; //will be moved to a separate class and made thread-safe QScriptEngine* ScriptEngine; diff --git a/src/common/aphoton.h b/src/common/aphoton.h index a34ce2d1..de13bec8 100644 --- a/src/common/aphoton.h +++ b/src/common/aphoton.h @@ -1,6 +1,8 @@ #ifndef APHOTON #define APHOTON +#include + class ASimulationStatistics; class APhoton @@ -40,6 +42,21 @@ class APhoton SimStat = CopyFrom->SimStat; } + + void ensureUnitaryLength() + { + double mod; + for (int i=0; i<3; i++) + mod += ( v[i] * v[i] ); + mod = sqrt(mod); + + if (mod != 0) + for (int i=0; i<3; i++) v[i] /= mod; + else + { + v[0] = 0; v[1] = 0; v[2] = 1.0; + } + } }; #endif // APHOTON From 642c16d61448ded8af0b05e9d0c1b1ef6c7b672f Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 11:56:49 +0100 Subject: [PATCH 015/140] ++ --- .../ascriptopticaloverride.cpp | 44 ++++++++++++++++++- src/OpticalOverrides/ascriptopticaloverride.h | 4 ++ src/gui/mainwindow.cpp | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 08c61cae..800960ab 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -78,14 +78,54 @@ bool AScriptOpticalOverride::readFromJson(QJsonObject &json) } #ifdef GUI -QWidget *AScriptOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) +#include +//#include +#include +#include +#include +QWidget *AScriptOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *) { - return AOpticalOverride::getEditWidget(caller, GraphWindow); + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QVBoxLayout* l = new QVBoxLayout(f); + QLabel* lab = new QLabel(""); + l->addWidget(lab); + QPushButton* pb = new QPushButton("Load / Edit script"); + QObject::connect(pb, &QPushButton::clicked, [caller, this] {openScriptWindow(caller);}); + l->addWidget(pb); + lab = new QLabel(""); + l->addWidget(lab); + + return f; } #endif const QString AScriptOpticalOverride::checkOverrideData() { if (Script.isEmpty()) return "Script not defined!"; + + //TODO check syntax! + return ""; } + +#ifdef GUI +#include "ascriptwindow.h" +#include "ajavascriptmanager.h" +#include "globalsettingsclass.h" +#include "TRandom2.h" +void AScriptOpticalOverride::openScriptWindow(QWidget *parent) +{ + QString example = "photon.Absorbed()"; + + TRandom2* RandGen = new TRandom2(); //leak! + AJavaScriptManager* sm = new AJavaScriptManager(RandGen); //leak! + AScriptWindow* sw = new AScriptWindow(sm, new GlobalSettingsClass(0), true, parent); //leak! + sw->ConfigureForLightMode(&Script, "Optical override: custom script", example); + + //sw->SetInterfaceObject(0); + sw->SetInterfaceObject(interfaceObject, "photon"); //steals ownership! + sw->show(); +} +#endif diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index 93a28bfe..cf51fe0c 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -41,6 +41,10 @@ class AScriptOpticalOverride : public AOpticalOverride //will be moved to a separate class and made thread-safe QScriptEngine* ScriptEngine; AOpticalOverrideScriptInterface* interfaceObject; + +#ifdef GUI + void openScriptWindow(QWidget* parent); +#endif }; #endif // ASCRIPTOPTICALOVERRIDE_H diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 399d7715..47151332 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -959,7 +959,7 @@ void MainWindow::on_pbRefreshOverrides_clicked() } else { - message("Unknown override model: "+model, this); + //message("Unknown override model: "+model, this); ui->cobOpticalOverrideModel->setCurrentIndex(0); } } From 5f99e87d46fe56ae2414b825079de66989803c0c Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 12:03:53 +0100 Subject: [PATCH 016/140] ++ --- src/OpticalOverrides/ascriptopticaloverride.cpp | 10 ++++++++++ src/common/aphoton.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 800960ab..6def9665 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -115,6 +115,7 @@ const QString AScriptOpticalOverride::checkOverrideData() #include "ajavascriptmanager.h" #include "globalsettingsclass.h" #include "TRandom2.h" +#include "aphoton.h" void AScriptOpticalOverride::openScriptWindow(QWidget *parent) { QString example = "photon.Absorbed()"; @@ -124,6 +125,15 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) AScriptWindow* sw = new AScriptWindow(sm, new GlobalSettingsClass(0), true, parent); //leak! sw->ConfigureForLightMode(&Script, "Optical override: custom script", example); + double vx[3]; + vx[0] = 0; vx[1] = 0; vx[3] = 1; + double r[3]; + r[0] = 0; r[1] = 0; r[2] = 0; + APhoton phot(vx, r, -1, 0); + double normal[3]; + normal[0] = 0; normal[1] = 0; normal[2] = 1.0; + interfaceObject->configure(RandGen, &phot, normal); + //sw->SetInterfaceObject(0); sw->SetInterfaceObject(interfaceObject, "photon"); //steals ownership! sw->show(); diff --git a/src/common/aphoton.h b/src/common/aphoton.h index de13bec8..839728fc 100644 --- a/src/common/aphoton.h +++ b/src/common/aphoton.h @@ -9,7 +9,7 @@ class APhoton { public: APhoton() : fSkipThisPhoton(false), SimStat(0) {} - APhoton(double* xyz, double* Vxyz, int waveIndex=0, double time=0) : + APhoton(double* xyz, double* Vxyz, int waveIndex=-1, double time=0) : time(time), waveIndex(waveIndex), scint_type(0), fSkipThisPhoton(false), SimStat(0) { r[0]=xyz[0]; r[1]=xyz[1]; r[2]=xyz[2]; From dd75455eef73b5d31fc0fa90f8a450f1505e13b9 Mon Sep 17 00:00:00 2001 From: vovasolo Date: Mon, 1 Oct 2018 13:26:16 +0100 Subject: [PATCH 017/140] Added more fatures to docker image in ants2.pro --- src/ants2.pro | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/ants2.pro b/src/ants2.pro index 519b9204..f8d40e76 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -11,6 +11,14 @@ CONFIG += ants2_eigen3 #use Eigen3 library instead of ROOT for linear algeb #CONFIG += ants2_Python #enable Python scripting #CONFIG += ants2_NCrystal #enable NCrystal library (neutron scattering) +#Optional features enabled in Docker version +ants2_docker { + CONFIG += ants2_flann #enable FLANN (fast neighbour search) library: see https://github.com/mariusmuja/flann + CONFIG += ants2_fann #enables FANN (fast neural network) library: see https://github.com/libfann/fann + CONFIG += ants2_RootServer #enable cern CERN ROOT html server + CONFIG += ants2_Python #enable Python scripting +} + DEBUG_VERBOSITY = 1 # 0 - debug messages suppressed, 1 - normal, 2 - normal + file/line information # after a change, qmake and rebuild (or qmake + make any change in main.cpp to trigger recompilation) @@ -193,11 +201,19 @@ ants2_Python{ LIBS += -LC:/PythonQt3.2/lib -lPythonQt } linux-g++ || unix { - LIBS += $$system(python3.5-config --libs) - QMAKE_CXXFLAGS += $$system(python3.5-config --includes) - - INCLUDEPATH += /home/andr/Work/PythonQt/src - LIBS += -L/home/andr/Work/PythonQt/lib -lPythonQt + ants2_docker { + LIBS += $$system(python3-config --libs) + QMAKE_CXXFLAGS += $$system(python3-config --includes) + + INCLUDEPATH += /usr/include/PythonQt5/ + LIBS += -lPythonQt-Qt5-Python3.6 + } else { + LIBS += $$system(python3.5-config --libs) + QMAKE_CXXFLAGS += $$system(python3.5-config --includes) + + INCLUDEPATH += /home/andr/Work/PythonQt/src + LIBS += -L/home/andr/Work/PythonQt/lib -lPythonQt + } } HEADERS += scriptmode/apythonscriptmanager.h From 5e6e7df8202555b74f2bc33a28abbe5a1a6d9f7b Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 16:56:19 +0100 Subject: [PATCH 018/140] ++ --- .../aopticaloverridescriptinterface.cpp | 7 +-- .../aopticaloverridescriptinterface.h | 6 +- .../ascriptopticaloverride.cpp | 46 +++++++------- src/OpticalOverrides/ascriptopticaloverride.h | 17 +++--- src/ants2.pro | 6 +- src/common/aopticaloverride.cpp | 33 +++++----- src/common/aopticaloverride.h | 20 ++++-- src/common/atracerstateful.cpp | 42 +++++++++++++ src/common/atracerstateful.h | 33 ++++++++++ src/gui/MainWindowTools/MainWindowTests.cpp | 17 ++++-- src/modules/amaterialparticlecolection.cpp | 35 +++++++++++ src/modules/amaterialparticlecolection.h | 4 ++ src/modules/aphotontracer.cpp | 6 +- src/modules/aphotontracer.h | 4 +- src/modules/phscatclaudiomodel.cpp | 61 ++++++++++--------- src/modules/phscatclaudiomodel.h | 9 +-- src/modules/scatteronmetal.cpp | 5 +- src/modules/scatteronmetal.h | 3 +- 18 files changed, 245 insertions(+), 109 deletions(-) create mode 100644 src/common/atracerstateful.cpp create mode 100644 src/common/atracerstateful.h diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index 8a785b3f..f0fa409b 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -1,15 +1,15 @@ #include "aopticaloverridescriptinterface.h" - #include "aphoton.h" +#include + AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() { } -void AOpticalOverrideScriptInterface::configure(TRandom2 *randGen, APhoton *photon, const double *normalVector) +void AOpticalOverrideScriptInterface::configure(APhoton *photon, const double *normalVector) { - RandGen = randGen; Photon = photon; NormalVector = normalVector; @@ -49,7 +49,6 @@ void AOpticalOverrideScriptInterface::TransmissionDirect() ReturnResult = AOpticalOverride::Forward; } -#include void AOpticalOverrideScriptInterface::SetDirection(double vx, double vy, double vz) { Photon->v[0] = vx; diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 095d18ad..4e4745e6 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -4,9 +4,6 @@ #include "ascriptinterface.h" #include "aopticaloverride.h" -#include - -class TRandom2; class APhoton; class AOpticalOverrideScriptInterface : public AScriptInterface @@ -15,7 +12,7 @@ class AOpticalOverrideScriptInterface : public AScriptInterface public: AOpticalOverrideScriptInterface(); - void configure(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector); + void configure(APhoton *Photon, const double *NormalVector); AOpticalOverride::OpticalOverrideResultEnum getResult() const; public slots: @@ -27,7 +24,6 @@ public slots: void SetDirection(double vx, double vy, double vz); private: - TRandom2 * RandGen; APhoton * Photon; const double * NormalVector; diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 6def9665..ed679dc4 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -1,5 +1,6 @@ #include "ascriptopticaloverride.h" #include "amaterialparticlecolection.h" +#include "atracerstateful.h" #include "aopticaloverridescriptinterface.h" @@ -12,39 +13,24 @@ AScriptOpticalOverride::AScriptOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) : AOpticalOverride(MatCollection, MatFrom, MatTo) { - //to transfer away - ScriptEngine = new QScriptEngine(); //mem leak - qDebug() << "Registering script interface"; - interfaceObject = new AOpticalOverrideScriptInterface(); //mem leak - QScriptValue obj = ScriptEngine->newQObject(interfaceObject, QScriptEngine::QtOwnership); - ScriptEngine->globalObject().setProperty("photon", obj); - //coreObj = new AInterfaceToCore(this); - //QScriptValue coreVal = engine->newQObject(coreObj, QScriptEngine::QtOwnership); - //QString coreName = "core"; - //coreObj->setObjectName(coreName); - //engine->globalObject().setProperty(coreName, coreVal); - //interfaces.append(coreObj); - //registering math module - AInterfaceToMath* mathObj = new AInterfaceToMath(0); - QScriptValue mathVal = ScriptEngine->newQObject(mathObj, QScriptEngine::QtOwnership); -// mathObj->setObjectName(mathName); - ScriptEngine->globalObject().setProperty("math", mathVal); - //interfaces.append(mathObj); //SERVICE OBJECT IS FIRST in interfaces! + interfaceObject = new AOpticalOverrideScriptInterface(); + interfaceObject->setObjectName("photon"); } +AScriptOpticalOverride::~AScriptOpticalOverride() {} + void AScriptOpticalOverride::initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) { //external script engine will have interface already registered } -AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { //qDebug() << "Configuring script interface"; - interfaceObject->configure(RandGen, Photon, NormalVector); + interfaceObject->configure(Photon, NormalVector); //qDebug() << "Evaluating script"; - //QScriptValue res = - ScriptEngine->evaluate(Script); - //qDebug() << "eval result:" << res.toString()<<"Photon status:"<getResult(); + Resources.evaluateScript(Script); + qDebug() << "Photon status:"<getResult(); return interfaceObject->getResult(); } @@ -77,6 +63,18 @@ bool AScriptOpticalOverride::readFromJson(QJsonObject &json) return true; } +QObject* AScriptOpticalOverride::generateInterfaceScriptObject() +{ + interfaceObject = new AOpticalOverrideScriptInterface(); + interfaceObject->setObjectName("photon"); + return interfaceObject; +} + +void AScriptOpticalOverride::assignInterfaceScriptObject(QObject *obj) +{ + interfaceObject = static_cast(obj); +} + #ifdef GUI #include //#include @@ -132,7 +130,7 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) APhoton phot(vx, r, -1, 0); double normal[3]; normal[0] = 0; normal[1] = 0; normal[2] = 1.0; - interfaceObject->configure(RandGen, &phot, normal); + interfaceObject->configure(&phot, normal); //sw->SetInterfaceObject(0); sw->SetInterfaceObject(interfaceObject, "photon"); //steals ownership! diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index cf51fe0c..9d4c0423 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -12,14 +12,13 @@ class AOpticalOverrideScriptInterface; class AScriptOpticalOverride : public AOpticalOverride { public: - //AScriptOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); AScriptOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); - virtual ~AScriptOpticalOverride() {} + virtual ~AScriptOpticalOverride(); //TODO transfer to a separate entry, external pointer to ScriptEngine void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave) override; virtual QString getType() const override {return "CustomScript";} @@ -28,19 +27,19 @@ class AScriptOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json) override; virtual bool readFromJson(QJsonObject &json) override; + virtual bool isRequireScriptEngine() const override {return true;} + virtual QObject* generateInterfaceScriptObject() override; + virtual void assignInterfaceScriptObject(QObject * obj) override; + #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; #endif virtual const QString checkOverrideData() override; private: - QString Script = "photon.SetDirection(0, 0, 1)"; - //QString Script = "photon.Fresnel()"; - //QString Script = "photon.Absorb()"; + QString Script = "photon.Absorb()"; - //will be moved to a separate class and made thread-safe - QScriptEngine* ScriptEngine; - AOpticalOverrideScriptInterface* interfaceObject; + AOpticalOverrideScriptInterface* interfaceObject = 0; #ifdef GUI void openScriptWindow(QWidget* parent); diff --git a/src/ants2.pro b/src/ants2.pro index a8088932..5cca2bb4 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -350,7 +350,8 @@ SOURCES += main.cpp \ common/atrackbuildoptions.cpp \ gui/MainWindowTools/aopticaloverridedialog.cpp \ OpticalOverrides/aopticaloverridescriptinterface.cpp \ - OpticalOverrides/ascriptopticaloverride.cpp + OpticalOverrides/ascriptopticaloverride.cpp \ + common/atracerstateful.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -477,7 +478,8 @@ HEADERS += common/CorrelationFilters.h \ common/atrackbuildoptions.h \ gui/MainWindowTools/aopticaloverridedialog.h \ OpticalOverrides/aopticaloverridescriptinterface.h \ - OpticalOverrides/ascriptopticaloverride.h + OpticalOverrides/ascriptopticaloverride.h \ + common/atracerstateful.h # --- SIM --- ants2_SIM { diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index b677a179..2898ddee 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -5,6 +5,7 @@ #include "ajsontools.h" #include "afiletools.h" #include "asimulationstatistics.h" +#include "atracerstateful.h" #ifdef SIM #include "phscatclaudiomodel.h" @@ -84,9 +85,9 @@ BasicOpticalOverride::BasicOpticalOverride(AMaterialParticleCollection *MatColle BasicOpticalOverride::BasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) : AOpticalOverride(MatCollection, MatFrom, MatTo) {} -AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { - double rnd = RandGen->Rndm(); + double rnd = Resources.RandGen->Rndm(); // surface loss? rnd -= probLoss; @@ -123,7 +124,7 @@ AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(TRan { case 0: //4Pi scattering // qDebug()<<"4Pi scatter"; - RandomDir(RandGen, Photon); + RandomDir(Resources.RandGen, Photon); // qDebug()<<"New direction:"<v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -161,7 +162,7 @@ AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(TRan double norm2; do { - RandomDir(RandGen, Photon); + RandomDir(Resources.RandGen, Photon); Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -362,7 +363,7 @@ const QStringList ListOvAllOpticalOverrideTypes() return l; } -AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { // Angular reflectance: fraction of light reflected at the interface bewteen // medium 1 and medium 2 assuming non-polarized incident light: @@ -401,7 +402,7 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(TRand } // if random[0,1]Rndm() < fresnelUnpolarR) + if (Resources.RandGen->Rndm() < fresnelUnpolarR) { //qDebug()<<"Override: specular reflection"; //rotating the vector: K = K - 2*(NK)*N @@ -412,7 +413,7 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(TRand } // if random[0,1]>albedo kill photon else do diffuse reflection - if (RandGen->Rndm() > Albedo) + if (Resources.RandGen->Rndm() > Albedo) { //qDebug()<<"Override: absorption"; Status = Absorption; @@ -424,7 +425,7 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(TRand double norm2; do { - RandomDir(RandGen, Photon); + RandomDir(Resources.RandGen, Photon); Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -583,7 +584,7 @@ void AWaveshifterOverride::initializeWaveResolved(bool bWaveResolved, double wav } } -AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { //currently assuming there is no scattering on original wavelength - only reemission or absorption @@ -597,7 +598,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(TRan } double prob = ReemissionProbabilityBinned.at(Photon->waveIndex); // probability of reemission - if (RandGen->Rndm() < prob) + if (Resources.RandGen->Rndm() < prob) { //triggered! @@ -624,7 +625,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(TRan if (ReemissionModel == 0) { - RandomDir(RandGen, Photon); + RandomDir(Resources.RandGen, Photon); //enering new volume or backscattering? //normal is in the positive direction in respect to the original direction! if (Photon->v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2] < 0) @@ -644,7 +645,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(TRan // qDebug()<<"2Pi lambertian scattering backward"; do { - RandomDir(RandGen, Photon); + RandomDir(Resources.RandGen, Photon); Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -660,7 +661,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(TRan // qDebug()<<"2Pi lambertian scattering forward"; do { - RandomDir(RandGen, Photon); + RandomDir(Resources.RandGen, Photon); Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -943,7 +944,7 @@ SpectralBasicOpticalOverride::SpectralBasicOpticalOverride(AMaterialParticleColl ProbDiff << 0; } -AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { int waveIndex = Photon->waveIndex; if (waveIndex == -1) waveIndex = effectiveWaveIndex; @@ -952,7 +953,7 @@ AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calcul probDiff = ProbDiffBinned.at(waveIndex); probRef = ProbRefBinned.at(waveIndex); - return BasicOpticalOverride::calculate(RandGen, Photon, NormalVector); + return BasicOpticalOverride::calculate(Resources, Photon, NormalVector); } void SpectralBasicOpticalOverride::printConfiguration(int /*iWave*/) diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 09d75bb4..8ef331c2 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -13,7 +13,9 @@ class QJsonObject; class TH1D; class QWidget; class TObject; +class QObject; class GraphWindowClass; +class ATracerStateful; //modify these two functions if you want to register a new override type! AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); @@ -22,7 +24,7 @@ const QStringList ListOvAllOpticalOverrideTypes(); class AOpticalOverride { public: - //the status for photon tracing: + //return status for photon tracing: enum OpticalOverrideResultEnum {NotTriggered, Absorbed, Forward, Back, _Error_}; //detailed status for statistics only: enum ScatterStatusEnum {SpikeReflection, LobeReflection, LambertianReflection, Absorption, Transmission, ErrorDetected}; @@ -32,7 +34,7 @@ class AOpticalOverride : MatCollection(MatCollection), MatFrom(MatFrom), MatTo(MatTo) {} virtual ~AOpticalOverride() {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector) = 0; //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) = 0; //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave) = 0; virtual QString getType() const = 0; @@ -44,8 +46,14 @@ class AOpticalOverride virtual void writeToJson(QJsonObject &json); virtual bool readFromJson(QJsonObject &json); + //next one is used by MatCollection when a material is removed void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} + //next three methods are only for the script-based model + virtual bool isRequireScriptEngine() const {return false;} + virtual QObject* generateInterfaceScriptObject() {return 0;} + virtual void assignInterfaceScriptObject(QObject *) {} + #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow); #endif @@ -68,7 +76,7 @@ class BasicOpticalOverride : public AOpticalOverride BasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); virtual ~BasicOpticalOverride() {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave); virtual QString getType() const {return "Simplistic_model";} @@ -99,7 +107,7 @@ class FSNPOpticalOverride : public AOpticalOverride : AOpticalOverride(MatCollection, MatFrom, MatTo) {Albedo = 0.95;} virtual ~FSNPOpticalOverride() {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave); virtual QString getType() const {return "FS_NP";} @@ -125,7 +133,7 @@ class AWaveshifterOverride : public AOpticalOverride virtual ~AWaveshifterOverride(); void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave); virtual QString getType() const {return "SurfaceWLS";} @@ -173,7 +181,7 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride SpectralBasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo, int ScatterModel, double EffWave); virtual ~SpectralBasicOpticalOverride() {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave) override; virtual QString getType() const override {return "SimplisticSpectral_model";} diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp new file mode 100644 index 00000000..a4e4fb3d --- /dev/null +++ b/src/common/atracerstateful.cpp @@ -0,0 +1,42 @@ +#include "atracerstateful.h" +#include "amaterialparticlecolection.h" +//#include "coreinterfaces.h" + +#include +#include +#include + +#include "TRandom2.h" + +ATracerStateful::~ATracerStateful() +{ + delete ScriptEngine; ScriptEngine = 0; + qDebug() << "Deleting" << interfaces.size() << "ov script interface(s)"; + for (QObject* o : interfaces) delete o; + interfaces.clear(); +} + +void ATracerStateful::evaluateScript(const QString &Script) +{ + qDebug() << "Script:"<evaluate(Script); + qDebug() << "eval result:" << res.toString(); +} + +void ATracerStateful::registerAllInterfaceObjects(AMaterialParticleCollection *MPcollection) +{ + MPcollection->registerOpticalOverrideScriptInterfaces(*this); +} + +void ATracerStateful::registerInterfaceObject(QObject *interfaceObj) +{ + if (!ScriptEngine) + { + qDebug() << "Creating script engine"; + ScriptEngine = new QScriptEngine(); + } + + QScriptValue val = ScriptEngine->newQObject(interfaceObj, QScriptEngine::QtOwnership); + ScriptEngine->globalObject().setProperty(interfaceObj->objectName(), val); + interfaces << interfaceObj; +} diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h new file mode 100644 index 00000000..07b04b6f --- /dev/null +++ b/src/common/atracerstateful.h @@ -0,0 +1,33 @@ +#ifndef ATRACERSTATEFUL_H +#define ATRACERSTATEFUL_H + +class TRandom2; +class QScriptEngine; +class QObject; +class AMaterialParticleCollection; + +#include + +//random generator is external +//script engine is owned by this class, but created only if needed (there are script overrides) + +class ATracerStateful +{ +public: + ~ATracerStateful(); + + void evaluateScript(const QString& Script); + + void registerAllInterfaceObjects(AMaterialParticleCollection* MPcollection); + + //called by MPcollection + void registerInterfaceObject(QObject* interfaceObj); + + TRandom2 * RandGen = 0; + QScriptEngine * ScriptEngine = 0; + +private: + QVector interfaces; +}; + +#endif // ATRACERSTATEFUL_H diff --git a/src/gui/MainWindowTools/MainWindowTests.cpp b/src/gui/MainWindowTools/MainWindowTests.cpp index 805210be..42243f5b 100644 --- a/src/gui/MainWindowTools/MainWindowTests.cpp +++ b/src/gui/MainWindowTools/MainWindowTests.cpp @@ -17,6 +17,7 @@ #include "atrackrecords.h" #include "aenergydepositioncell.h" #include "amessage.h" +#include "atracerstateful.h" #include "TVirtualGeoTrack.h" #include "TLegend.h" @@ -357,13 +358,15 @@ void MainWindow::on_pbCSMtestmany_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); + ATracerStateful Resources; + Resources.RandGen = Detector->RandGen; for (int i=0; isbST_number->value(); i++) { ph.v[0] = PhotDir.X(); //old has output direction after full cycle! ph.v[1] = PhotDir.Y(); ph.v[2] = PhotDir.Z(); ph.waveIndex = -1; - ov->calculate(Detector->RandGen, &ph, N); + ov->calculate(Resources, &ph, N); Color_t col; Int_t type; @@ -465,6 +468,8 @@ void MainWindow::on_pbST_uniform_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); + ATracerStateful Resources; + Resources.RandGen = Detector->RandGen; for (int i=0; icalculate(Detector->RandGen, &ph, N); + ov->calculate(Resources, &ph, N); if (ov->Status == AOpticalOverride::Absorption) { @@ -543,6 +548,8 @@ void MainWindow::on_pbST_RvsAngle_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); + ATracerStateful Resources; + Resources.RandGen = Detector->RandGen; for (int iA=0; iA<91; iA++) //cycle by angle of incidence { double angle = iA; @@ -563,7 +570,7 @@ void MainWindow::on_pbST_RvsAngle_clicked() ph.v[1] = K[1]; ph.v[2] = K[2]; ph.waveIndex = -1; - ov->calculate(Detector->RandGen, &ph, N); + ov->calculate(Resources, &ph, N); switch (ov->Status) { @@ -615,6 +622,8 @@ static QVector vParam, vTot, vSpike, vLobe, vDiff, vDir; static QString parName; void MainWindow::on_pbST_ReflectionVsParameter_clicked() { + ATracerStateful Resources; + Resources.RandGen = Detector->RandGen; //input string processing QString inS = ui->leST_Parameter->text().simplified(); QStringList inL = inS.split(",", QString::SkipEmptyParts); @@ -781,7 +790,7 @@ void MainWindow::on_pbST_ReflectionVsParameter_clicked() ph.v[1] = K[1]; ph.v[2] = K[2]; ph.waveIndex = -1; - ov->calculate(Detector->RandGen, &ph, N); + ov->calculate(Resources, &ph, N); switch (ov->Status) { diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index b48f998a..34dccd8a 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -4,6 +4,8 @@ #include "aopticaloverride.h" #include "ajsontools.h" #include "acommonfunctions.h" +#include "atracerstateful.h" + #include #include #include @@ -76,6 +78,39 @@ void AMaterialParticleCollection::updateRandomGenForThread(int ID, TRandom2* Ran MaterialCollectionData[imat]->UpdateRandGen(ID, RandGen); } +#include +void AMaterialParticleCollection::registerOpticalOverrideScriptInterfaces(ATracerStateful &record) +{ + qDebug() << "Registering ov for the thread..."; + QMap RegisteredTypes; + for (AMaterial* mat : MaterialCollectionData) + { + for (AOpticalOverride* ov : mat->OpticalOverrides) + if (ov) + { + if (!ov->isRequireScriptEngine()) continue; + + QString type = ov->getType(); + qDebug() << " Found override:" << mat->name << ov->getReportLine(); + + if (RegisteredTypes.contains(type)) + { + qDebug() << " Type already registered"; + ov->assignInterfaceScriptObject(RegisteredTypes.value(type)); + qDebug() << " Assigned interface object:" << RegisteredTypes.value(type); + } + else + { + qDebug() << " Type not yet registered"; + QObject* obj = ov->generateInterfaceScriptObject(); + qDebug() << " Registering interface object" << obj << obj->objectName(); + record.registerInterfaceObject(obj); + RegisteredTypes.insert(type, obj); + } + } + } +} + void AMaterialParticleCollection::getFirstOverridenMaterial(int &ifrom, int &ito) { for (ifrom=0; ifrom class GeneralSimSettings; +class ATracerStateful; class AMaterialParticleCollection : public QObject { @@ -37,6 +38,9 @@ class AMaterialParticleCollection : public QObject void UpdateRuntimePropertiesAndWavelengthBinning(GeneralSimSettings *SimSet, TRandom2 *RandGen, int numThreads = 1); void updateRandomGenForThread(int ID, TRandom2 *RandGen); + //for script-based optical overrides initialize script units in ScriptEngine + void registerOpticalOverrideScriptInterfaces(ATracerStateful& record); + //info requests //materials AMaterial* operator[](int i) {return MaterialCollectionData[i]; } //get pointer to material with index i diff --git a/src/modules/aphotontracer.cpp b/src/modules/aphotontracer.cpp index b9a5c038..da0b44cb 100644 --- a/src/modules/aphotontracer.cpp +++ b/src/modules/aphotontracer.cpp @@ -31,6 +31,10 @@ APhotonTracer::APhotonTracer(TGeoManager *geoManager, TRandom2 *RandomGenerator, fGridShiftOn = false; fBuildTracks = false; p = new APhoton(); + + //for transfer to overrides + ResourcesForOverrides.RandGen = RandGen; + ResourcesForOverrides.registerAllInterfaceObjects(MaterialCollection); } APhotonTracer::~APhotonTracer() @@ -228,7 +232,7 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) //qDebug() << "Overrides defined! Model = "<getType(); N = navigator->FindNormal(kFALSE); fHaveNormal = true; - AOpticalOverride::OpticalOverrideResultEnum result = ov->calculate(RandGen, p, N); + AOpticalOverride::OpticalOverrideResultEnum result = ov->calculate(ResourcesForOverrides, p, N); switch (result) { diff --git a/src/modules/aphotontracer.h b/src/modules/aphotontracer.h index 81294cd3..101958cb 100644 --- a/src/modules/aphotontracer.h +++ b/src/modules/aphotontracer.h @@ -2,6 +2,7 @@ #define APHOTONTRACER_H #include "aphotonhistorylog.h" +#include "atracerstateful.h" #include #include "TMathBase.h" @@ -37,7 +38,7 @@ class APhotonTracer void setMaxTracks(int maxTracks) {MaxTracks = maxTracks;} -private: +private: TRandom2* RandGen; TGeoManager* GeoManager; TGeoNavigator *navigator; @@ -48,6 +49,7 @@ class APhotonTracer QVector* Tracks; TrackHolderClass* track; QVector PhLog; + ATracerStateful ResourcesForOverrides; int MaxTracks = 10; int PhotonTracksAdded = 0; diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 6df6031c..9729d278 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -2,6 +2,7 @@ #include "amaterialparticlecolection.h" #include "aphoton.h" #include "asimulationstatistics.h" +#include "atracerstateful.h" #include #include @@ -195,7 +196,7 @@ double PhScatClaudioModelV2::GnFunc(double cost) return 0; } -AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(TRandom2 *RandGen, APhoton *Photon, const double* NormalVector) +AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(ATracerStateful &Resources, APhoton *Photon, const double* NormalVector) { TVector3 K(Photon->v); // photon direction //qDebug() << "Photon direction (i,j,k):"<Rndm() < lambda || sigma_alpha == 0) + if (Resources.RandGen->Rndm() < lambda || sigma_alpha == 0) { Status = SpikeReflection; costl = costi; @@ -248,8 +249,8 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(TRan } Status = LobeReflection; - double alpha_WRM = SlopeAngle(RandGen->Rndm()); // Sampling of the slope angle - double phi_alpha_WRM = 2.0 * 3.1415926535 * RandGen->Rndm(); + double alpha_WRM = SlopeAngle(Resources.RandGen->Rndm()); // Sampling of the slope angle + double phi_alpha_WRM = 2.0 * 3.1415926535 * Resources.RandGen->Rndm(); // Set the Components of the Global Normal double CosAlpha_WRM = cos(alpha_WRM); @@ -275,7 +276,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(TRan // qDebug() << "new weight microfacet:"<< weight_microfacet; } - while ( RandGen->Rndm()*1.5 > weight_microfacet ); + while ( Resources.RandGen->Rndm()*1.5 > weight_microfacet ); } @@ -294,7 +295,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(TRan // qDebug() << "Amp_total"<Rndm() < Amp_tot) + if( Resources.RandGen->Rndm() < Amp_tot) { //Computation of the new momentum and the new polarization for the reflected photon (specular lobe or specular spike) K = 2.0 * costl * ScatNormal + K; @@ -315,7 +316,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(TRan double Fres_Term = 0; do { - if ( RandGen->Rndm() > albedo) + if ( Resources.RandGen->Rndm() > albedo) { Status = Absorption; Photon->SimStat->OverrideClaudioAbs++; @@ -326,10 +327,10 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(TRan Fres_Term = 0; gnd = 0; - double sintdsqquared = RandGen->Rndm(); + double sintdsqquared = Resources.RandGen->Rndm(); double sintd = sqrt(sintdsqquared); double costd = sqrt(1.0 - sintdsqquared); - double phid = 2.0 * 3.1415926535 * RandGen->Rndm(); + double phid = 2.0 * 3.1415926535 * Resources.RandGen->Rndm(); double sintinter = Rindex1*sintd/Rindex2; double costiter = 0; @@ -346,7 +347,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(TRan gnd = GnFunc( GlobalNormal * K ); } } - while(sigma_alpha>0 && RandGen->Rndm() > gnd*Fres_Term); + while(sigma_alpha>0 && Resources.RandGen->Rndm() > gnd*Fres_Term); // //The diffuse lobe will be randomly polarized // A_trans = NewMomentum.cross(theScatNormal); @@ -369,7 +370,7 @@ QString PhScatClaudioModelV2::getReportLine() return PhScatClaudioModel::getReportLine()+"_v2"; } -AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { TVector3 K(Photon->v); // photon direction //qDebug() << "Photon direction (i,j,k):"<Rndm() < lambda || sigma_alpha == 0) + if (Resources.RandGen->Rndm() < lambda || sigma_alpha == 0) { Status = SpikeReflection; costl = costi; @@ -422,8 +423,8 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(TR } Status = LobeReflection; - double alpha_WRM = SlopeAngle(RandGen->Rndm()); // Sampling of the slope angle - double phi_alpha_WRM = 2.0 * 3.1415926535 * RandGen->Rndm(); + double alpha_WRM = SlopeAngle(Resources.RandGen->Rndm()); // Sampling of the slope angle + double phi_alpha_WRM = 2.0 * 3.1415926535 * Resources.RandGen->Rndm(); // Set the Components of the Global Normal double CosAlpha_WRM = cos(alpha_WRM); @@ -449,7 +450,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(TR // qDebug() << "new weight microfacet:"<< weight_microfacet; } - while ( RandGen->Rndm()*1.5 > weight_microfacet ); + while ( Resources.RandGen->Rndm()*1.5 > weight_microfacet ); } @@ -468,7 +469,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(TR // qDebug() << "Amp_total"<Rndm() < Amp_tot) + if( Resources.RandGen->Rndm() < Amp_tot) { //Computation of the new momentum and the new polarization for the reflected photon (specular lobe or specular spike) K = 2.0 * costl * ScatNormal + K; @@ -489,7 +490,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(TR double Fres_Term = 0; do { - if ( RandGen->Rndm() > albedo) + if ( Resources.RandGen->Rndm() > albedo) { Status = Absorption; Photon->SimStat->OverrideClaudioAbs++; @@ -500,10 +501,10 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(TR Fres_Term = 0; gnd = 0; - double sintdsqquared = RandGen->Rndm(); + double sintdsqquared = Resources.RandGen->Rndm(); double sintd = sqrt(sintdsqquared); double costd = sqrt(1.0 - sintdsqquared); - double phid = 2.0 * 3.1415926535 * RandGen->Rndm(); + double phid = 2.0 * 3.1415926535 * Resources.RandGen->Rndm(); double sintinter = Rindex2*sintd/Rindex1; //DIF from V2 double costiter = 0; @@ -521,7 +522,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(TR gnd = GnFunc( GlobalNormal * K ); //new fix for diff phots leak } } - while(sigma_alpha>0 && RandGen->Rndm()Rndm()>gnd ); //DIF from V2 +++ ExtraFix: before gnd*Fres_Term ExtraExtra - leak fix + while(sigma_alpha>0 && Resources.RandGen->Rndm()Rndm()>gnd ); //DIF from V2 +++ ExtraFix: before gnd*Fres_Term ExtraExtra - leak fix // //The diffuse lobe will be randomly polarized // A_trans = NewMomentum.cross(theScatNormal); @@ -545,7 +546,7 @@ QString PhScatClaudioModelV2d2::getReportLine() return PhScatClaudioModel::getReportLine()+"_v2.2"; } -AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { TVector3 K(Photon->v); // photon direction //qDebug() << "Photon direction (i,j,k):"<Rndm() < lambda || sigma_alpha == 0) + if (Resources.RandGen->Rndm() < lambda || sigma_alpha == 0) { Status = SpikeReflection; costl = costi; @@ -598,8 +599,8 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(TR } Status = LobeReflection; - double alpha_WRM = SlopeAngle(RandGen->Rndm()); // Sampling of the slope angle - double phi_alpha_WRM = 2.0 * 3.1415926535 * RandGen->Rndm(); + double alpha_WRM = SlopeAngle(Resources.RandGen->Rndm()); // Sampling of the slope angle + double phi_alpha_WRM = 2.0 * 3.1415926535 * Resources.RandGen->Rndm(); // Set the Components of the Global Normal double CosAlpha_WRM = cos(alpha_WRM); @@ -625,7 +626,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(TR // qDebug() << "new weight microfacet:"<< weight_microfacet; } - while ( RandGen->Rndm()*1.5 > weight_microfacet ); + while ( Resources.RandGen->Rndm()*1.5 > weight_microfacet ); } @@ -644,7 +645,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(TR // qDebug() << "Amp_total"<Rndm() < Amp_tot) + if( Resources.RandGen->Rndm() < Amp_tot) { //Computation of the new momentum and the new polarization for the reflected photon (specular lobe or specular spike) K = 2.0 * costl * ScatNormal + K; @@ -665,7 +666,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(TR double Fres_Term = 0; do { - if ( RandGen->Rndm() > albedo) + if ( Resources.RandGen->Rndm() > albedo) { Status = Absorption; Photon->SimStat->OverrideClaudioAbs++; @@ -676,10 +677,10 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(TR Fres_Term = 0; //gnd = 0; - double sintdsqquared = RandGen->Rndm(); + double sintdsqquared = Resources.RandGen->Rndm(); double sintd = sqrt(sintdsqquared); double costd = sqrt(1.0 - sintdsqquared); - double phid = 2.0 * 3.1415926535 * RandGen->Rndm(); + double phid = 2.0 * 3.1415926535 * Resources.RandGen->Rndm(); double sintinter = Rindex2*sintd/Rindex1; //DIF from V2 double costiter = 0; @@ -697,7 +698,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(TR //gnd = 1; } } - while(sigma_alpha>0 && RandGen->Rndm() < Fres_Term); //DIF from V2 +++ ExtraFix: before gnd*Fres_Term + while(sigma_alpha>0 && Resources.RandGen->Rndm() < Fres_Term); //DIF from V2 +++ ExtraFix: before gnd*Fres_Term // //The diffuse lobe will be randomly polarized // A_trans = NewMomentum.cross(theScatNormal); diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index 7647a3b4..1e9c48a4 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -6,6 +6,7 @@ class TRandom2; class APhoton; class QJsonObject; +class ATracerStateful; enum HeightDistrEnum {empirical, gaussian, exponential}; enum SlopeDistrEnum {trowbridgereitz, cooktorrance, bivariatecauchy}; @@ -17,7 +18,7 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! PhScatClaudioModel(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : AOpticalOverride(MatCollection, MatFrom, MatTo) {} // main method: - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector) = 0; + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) = 0; //unitary vectors! iWave - photon wave index, -1 if no wave-resolved virtual void printConfiguration(int iWave); @@ -54,7 +55,7 @@ class PhScatClaudioModelV2 : public PhScatClaudioModel public: PhScatClaudioModelV2(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModel(MatCollection, MatFrom, MatTo) {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); virtual QString getType() const {return "Claudio_Model_V2";} virtual QString getReportLine(); @@ -68,7 +69,7 @@ class PhScatClaudioModelV2d1 : public PhScatClaudioModelV2 public: PhScatClaudioModelV2d1(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModelV2(MatCollection, MatFrom, MatTo) {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); virtual QString getType() const {return "Claudio_Model_V2d1";} virtual QString getReportLine(); }; @@ -78,7 +79,7 @@ class PhScatClaudioModelV2d2 : public PhScatClaudioModelV2 public: PhScatClaudioModelV2d2(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModelV2(MatCollection, MatFrom, MatTo) {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); virtual QString getType() const {return "Claudio_Model_V2d2";} virtual QString getReportLine(); }; diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index 338a7c3c..51c54855 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -2,6 +2,7 @@ #include "amaterialparticlecolection.h" #include "aphoton.h" #include "asimulationstatistics.h" +#include "atracerstateful.h" #include #include @@ -94,7 +95,7 @@ const QString ScatterOnMetal::checkOverrideData() return ""; } -AOpticalOverride::OpticalOverrideResultEnum ScatterOnMetal::calculate(TRandom2 *RandGen, APhoton *Photon, const double *NormalVector) +AOpticalOverride::OpticalOverrideResultEnum ScatterOnMetal::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { double CosTheta = Photon->v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2]; @@ -116,7 +117,7 @@ AOpticalOverride::OpticalOverrideResultEnum ScatterOnMetal::calculate(TRandom2 * double Refl = calculateReflectivity(CosTheta, RealN, ImaginaryN, Photon->waveIndex); //qDebug() << "Dielectric-metal override: Cos theta="<Rndm() > Refl ) + if ( Resources.RandGen->Rndm() > Refl ) { //Absorption //qDebug() << "Override: Loss on metal"; diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index 3ebb4e86..b6792204 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -7,6 +7,7 @@ class APhoton; class TRandom2; class AMaterialParticleCollection; class QJsonObject; +class ATracerStateful; class ScatterOnMetal : public AOpticalOverride { @@ -15,7 +16,7 @@ class ScatterOnMetal : public AOpticalOverride : AOpticalOverride(MatCollection, MatFrom, MatTo) {} virtual ~ScatterOnMetal() {} - virtual OpticalOverrideResultEnum calculate(TRandom2* RandGen, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave); virtual QString getType() const {return "DielectricToMetal";} From 81304905f45e74c17d32fbc65c2c848ce806d2c4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 17:19:34 +0100 Subject: [PATCH 019/140] ++ --- .../ascriptopticaloverride.cpp | 28 ++++++------------- src/OpticalOverrides/ascriptopticaloverride.h | 9 +----- src/common/aopticaloverride.h | 5 ---- src/common/atracerstateful.cpp | 14 ++++++---- src/common/atracerstateful.h | 11 ++++---- src/modules/amaterialparticlecolection.cpp | 27 +++++++++--------- 6 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index ed679dc4..b0b0c7ae 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -11,27 +11,18 @@ #include "coreinterfaces.h" AScriptOpticalOverride::AScriptOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) - : AOpticalOverride(MatCollection, MatFrom, MatTo) -{ - interfaceObject = new AOpticalOverrideScriptInterface(); - interfaceObject->setObjectName("photon"); -} + : AOpticalOverride(MatCollection, MatFrom, MatTo) {} AScriptOpticalOverride::~AScriptOpticalOverride() {} -void AScriptOpticalOverride::initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) -{ - //external script engine will have interface already registered -} - AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { //qDebug() << "Configuring script interface"; - interfaceObject->configure(Photon, NormalVector); + Resources.interfaceObject->configure(Photon, NormalVector); //qDebug() << "Evaluating script"; Resources.evaluateScript(Script); - qDebug() << "Photon status:"<getResult(); - return interfaceObject->getResult(); + qDebug() << "Photon status:"<getResult(); + return Resources.interfaceObject->getResult(); } void AScriptOpticalOverride::printConfiguration(int) @@ -63,18 +54,13 @@ bool AScriptOpticalOverride::readFromJson(QJsonObject &json) return true; } -QObject* AScriptOpticalOverride::generateInterfaceScriptObject() +AOpticalOverrideScriptInterface *AScriptOpticalOverride::generateInterfaceScriptObject() { - interfaceObject = new AOpticalOverrideScriptInterface(); + AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); interfaceObject->setObjectName("photon"); return interfaceObject; } -void AScriptOpticalOverride::assignInterfaceScriptObject(QObject *obj) -{ - interfaceObject = static_cast(obj); -} - #ifdef GUI #include //#include @@ -130,6 +116,8 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) APhoton phot(vx, r, -1, 0); double normal[3]; normal[0] = 0; normal[1] = 0; normal[2] = 1.0; + + AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); interfaceObject->configure(&phot, normal); //sw->SetInterfaceObject(0); diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index 9d4c0423..1c9f10a6 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -15,9 +15,6 @@ class AScriptOpticalOverride : public AOpticalOverride AScriptOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); virtual ~AScriptOpticalOverride(); - //TODO transfer to a separate entry, external pointer to ScriptEngine - void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved virtual void printConfiguration(int iWave) override; @@ -27,9 +24,7 @@ class AScriptOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json) override; virtual bool readFromJson(QJsonObject &json) override; - virtual bool isRequireScriptEngine() const override {return true;} - virtual QObject* generateInterfaceScriptObject() override; - virtual void assignInterfaceScriptObject(QObject * obj) override; + AOpticalOverrideScriptInterface* generateInterfaceScriptObject(); #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; @@ -39,8 +34,6 @@ class AScriptOpticalOverride : public AOpticalOverride private: QString Script = "photon.Absorb()"; - AOpticalOverrideScriptInterface* interfaceObject = 0; - #ifdef GUI void openScriptWindow(QWidget* parent); #endif diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 8ef331c2..69befdc5 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -49,11 +49,6 @@ class AOpticalOverride //next one is used by MatCollection when a material is removed void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} - //next three methods are only for the script-based model - virtual bool isRequireScriptEngine() const {return false;} - virtual QObject* generateInterfaceScriptObject() {return 0;} - virtual void assignInterfaceScriptObject(QObject *) {} - #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow); #endif diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index a4e4fb3d..fa84715b 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -1,6 +1,6 @@ #include "atracerstateful.h" #include "amaterialparticlecolection.h" -//#include "coreinterfaces.h" +#include "aopticaloverridescriptinterface.h" #include #include @@ -11,9 +11,11 @@ ATracerStateful::~ATracerStateful() { delete ScriptEngine; ScriptEngine = 0; - qDebug() << "Deleting" << interfaces.size() << "ov script interface(s)"; - for (QObject* o : interfaces) delete o; - interfaces.clear(); + if (interfaceObject) + { + qDebug() << "Deleting ov script interface"; + delete interfaceObject; + } } void ATracerStateful::evaluateScript(const QString &Script) @@ -28,7 +30,7 @@ void ATracerStateful::registerAllInterfaceObjects(AMaterialParticleCollection *M MPcollection->registerOpticalOverrideScriptInterfaces(*this); } -void ATracerStateful::registerInterfaceObject(QObject *interfaceObj) +void ATracerStateful::registerInterfaceObject(AOpticalOverrideScriptInterface *interfaceObj) { if (!ScriptEngine) { @@ -38,5 +40,5 @@ void ATracerStateful::registerInterfaceObject(QObject *interfaceObj) QScriptValue val = ScriptEngine->newQObject(interfaceObj, QScriptEngine::QtOwnership); ScriptEngine->globalObject().setProperty(interfaceObj->objectName(), val); - interfaces << interfaceObj; + interfaceObject = interfaceObj; } diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h index 07b04b6f..a71b2a91 100644 --- a/src/common/atracerstateful.h +++ b/src/common/atracerstateful.h @@ -1,12 +1,13 @@ #ifndef ATRACERSTATEFUL_H #define ATRACERSTATEFUL_H +#include + class TRandom2; class QScriptEngine; class QObject; class AMaterialParticleCollection; - -#include +class AOpticalOverrideScriptInterface; //random generator is external //script engine is owned by this class, but created only if needed (there are script overrides) @@ -21,13 +22,11 @@ class ATracerStateful void registerAllInterfaceObjects(AMaterialParticleCollection* MPcollection); //called by MPcollection - void registerInterfaceObject(QObject* interfaceObj); + void registerInterfaceObject(AOpticalOverrideScriptInterface *interfaceObj); TRandom2 * RandGen = 0; QScriptEngine * ScriptEngine = 0; - -private: - QVector interfaces; + AOpticalOverrideScriptInterface* interfaceObject = 0; }; #endif // ATRACERSTATEFUL_H diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index 34dccd8a..2a752261 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -78,34 +78,33 @@ void AMaterialParticleCollection::updateRandomGenForThread(int ID, TRandom2* Ran MaterialCollectionData[imat]->UpdateRandGen(ID, RandGen); } -#include +#include "ascriptopticaloverride.h" +#include "aopticaloverridescriptinterface.h" void AMaterialParticleCollection::registerOpticalOverrideScriptInterfaces(ATracerStateful &record) { qDebug() << "Registering ov for the thread..."; - QMap RegisteredTypes; + AOpticalOverrideScriptInterface* interfaceObj = 0; for (AMaterial* mat : MaterialCollectionData) { for (AOpticalOverride* ov : mat->OpticalOverrides) if (ov) { - if (!ov->isRequireScriptEngine()) continue; + AScriptOpticalOverride* sov = dynamic_cast(ov); + if (!sov) continue; - QString type = ov->getType(); - qDebug() << " Found override:" << mat->name << ov->getReportLine(); + qDebug() << " Found script override:" << mat->name << ov->getReportLine(); - if (RegisteredTypes.contains(type)) + if (interfaceObj) { - qDebug() << " Type already registered"; - ov->assignInterfaceScriptObject(RegisteredTypes.value(type)); - qDebug() << " Assigned interface object:" << RegisteredTypes.value(type); + qDebug() << " Interface object already registered"; + qDebug() << " Assigned interface object:" << interfaceObj; } else { - qDebug() << " Type not yet registered"; - QObject* obj = ov->generateInterfaceScriptObject(); - qDebug() << " Registering interface object" << obj << obj->objectName(); - record.registerInterfaceObject(obj); - RegisteredTypes.insert(type, obj); + qDebug() << " Interface object not yet registered"; + interfaceObj = sov->generateInterfaceScriptObject(); + qDebug() << " Registering interface object" << interfaceObj << interfaceObj->objectName(); + record.registerInterfaceObject(interfaceObj); } } } From 7351dd9afd921ad27ba05de18bbc22e62d5248c3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 17:56:55 +0100 Subject: [PATCH 020/140] ++ --- .../aopticaloverridescriptinterface.cpp | 5 +-- .../ascriptopticaloverride.cpp | 37 ++++++++++++------- src/OpticalOverrides/ascriptopticaloverride.h | 2 - src/gui/ascriptwindow.cpp | 4 ++ 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index f0fa409b..c48ef6db 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -3,10 +3,7 @@ #include -AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() -{ - -} +AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() {} void AOpticalOverrideScriptInterface::configure(APhoton *photon, const double *normalVector) { diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index b0b0c7ae..c8c200c1 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -1,15 +1,25 @@ #include "ascriptopticaloverride.h" #include "amaterialparticlecolection.h" #include "atracerstateful.h" - #include "aopticaloverridescriptinterface.h" +#ifdef GUI +#include "ascriptwindow.h" +#include "ajavascriptmanager.h" +#include "globalsettingsclass.h" +#include "TRandom2.h" +#include "aphoton.h" +#include +#include +#include +#include +#include +#include +#endif + #include #include -#include //? - -#include "coreinterfaces.h" AScriptOpticalOverride::AScriptOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) : AOpticalOverride(MatCollection, MatFrom, MatTo) {} @@ -62,11 +72,6 @@ AOpticalOverrideScriptInterface *AScriptOpticalOverride::generateInterfaceScript } #ifdef GUI -#include -//#include -#include -#include -#include QWidget *AScriptOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *) { QFrame* f = new QFrame(); @@ -95,11 +100,6 @@ const QString AScriptOpticalOverride::checkOverrideData() } #ifdef GUI -#include "ascriptwindow.h" -#include "ajavascriptmanager.h" -#include "globalsettingsclass.h" -#include "TRandom2.h" -#include "aphoton.h" void AScriptOpticalOverride::openScriptWindow(QWidget *parent) { QString example = "photon.Absorbed()"; @@ -119,9 +119,18 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); interfaceObject->configure(&phot, normal); + interfaceObject->setObjectName("photon"); //sw->SetInterfaceObject(0); sw->SetInterfaceObject(interfaceObject, "photon"); //steals ownership! + sw->setWindowModality(Qt::ApplicationModal); sw->show(); + + while (sw->isVisible()) + { + QCoreApplication::processEvents(); + QThread::usleep(200); + } + qDebug() << "exit script:"< -//to move away -class QScriptEngine; class AOpticalOverrideScriptInterface; class AScriptOpticalOverride : public AOpticalOverride diff --git a/src/gui/ascriptwindow.cpp b/src/gui/ascriptwindow.cpp index 417bb9ec..14123369 100644 --- a/src/gui/ascriptwindow.cpp +++ b/src/gui/ascriptwindow.cpp @@ -373,6 +373,8 @@ void AScriptWindow::HighlightErrorLine(int line) void AScriptWindow::WriteToJson() { + if (bLightMode) return; + QJsonObject* ScriptWindowJsonPtr = 0; if ( ScriptLanguage == _JavaScript_) ScriptWindowJsonPtr = &GlobSet->ScriptWindowJson; else if ( ScriptLanguage == _PythonScript_) ScriptWindowJsonPtr = &GlobSet->PythonScriptWindowJson; @@ -403,6 +405,8 @@ void AScriptWindow::WriteToJson(QJsonObject& json) void AScriptWindow::ReadFromJson() { + if (bLightMode) return; + QJsonObject* ScriptWindowJsonPtr = 0; if ( ScriptLanguage == _JavaScript_) ScriptWindowJsonPtr = &GlobSet->ScriptWindowJson; else if ( ScriptLanguage == _PythonScript_) ScriptWindowJsonPtr = &GlobSet->PythonScriptWindowJson; From ae5933f8a4408bdb7c27eb807a5074454c8dcc0e Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 18:07:43 +0100 Subject: [PATCH 021/140] ++ --- .../MainWindowTools/aopticaloverridedialog.ui | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.ui b/src/gui/MainWindowTools/aopticaloverridedialog.ui index d7d693cc..d93acbca 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.ui +++ b/src/gui/MainWindowTools/aopticaloverridedialog.ui @@ -13,7 +13,25 @@ Dialog + + Qt::LeftToRight + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + @@ -67,14 +85,26 @@ - + - 100 - 0 + 200 + 26 + + + 16777215 + 16777215 + + + + + 75 + true + + @@ -128,8 +158,14 @@ - + + + + 200 + 0 + + Test override From 1053222ee2cd2a7aa325f248df36a900bfa23e96 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 1 Oct 2018 19:08:21 +0100 Subject: [PATCH 022/140] ++ --- src/ants2.pro | 9 +- .../aopticaloverridedialog.cpp | 5 +- .../MainWindowTools/aopticaloverridedialog.h | 2 + .../aopticaloverridetester.cpp | 130 ++++ .../MainWindowTools/aopticaloverridetester.h | 36 ++ .../MainWindowTools/aopticaloverridetester.ui | 608 ++++++++++++++++++ src/gui/mainwindow.ui | 2 +- 7 files changed, 787 insertions(+), 5 deletions(-) create mode 100644 src/gui/MainWindowTools/aopticaloverridetester.cpp create mode 100644 src/gui/MainWindowTools/aopticaloverridetester.h create mode 100644 src/gui/MainWindowTools/aopticaloverridetester.ui diff --git a/src/ants2.pro b/src/ants2.pro index 5cca2bb4..e702401f 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -351,7 +351,8 @@ SOURCES += main.cpp \ gui/MainWindowTools/aopticaloverridedialog.cpp \ OpticalOverrides/aopticaloverridescriptinterface.cpp \ OpticalOverrides/ascriptopticaloverride.cpp \ - common/atracerstateful.cpp + common/atracerstateful.cpp \ + gui/MainWindowTools/aopticaloverridetester.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -479,7 +480,8 @@ HEADERS += common/CorrelationFilters.h \ gui/MainWindowTools/aopticaloverridedialog.h \ OpticalOverrides/aopticaloverridescriptinterface.h \ OpticalOverrides/ascriptopticaloverride.h \ - common/atracerstateful.h + common/atracerstateful.h \ + gui/MainWindowTools/aopticaloverridetester.h # --- SIM --- ants2_SIM { @@ -801,4 +803,5 @@ unix { #------------ FORMS += \ - gui/MainWindowTools/aopticaloverridedialog.ui + gui/MainWindowTools/aopticaloverridedialog.ui \ + gui/MainWindowTools/aopticaloverridetester.ui diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 85de7fd1..7369473a 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -3,6 +3,7 @@ #include "aopticaloverride.h" #include "amaterialparticlecolection.h" #include "amessage.h" +#include "aopticaloverridetester.h" #include #include @@ -31,6 +32,8 @@ AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * Mat } updateGui(); + + TesterWindow = new AOpticalOverrideTester(GraphWindow, MatCollection, matFrom, matTo, this); } AOpticalOverrideDialog::~AOpticalOverrideDialog() @@ -102,5 +105,5 @@ void AOpticalOverrideDialog::on_cobType_activated(int index) void AOpticalOverrideDialog::on_pbTestOverride_clicked() { - + TesterWindow->show(); } diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.h b/src/gui/MainWindowTools/aopticaloverridedialog.h index 182402ad..f14e12be 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.h +++ b/src/gui/MainWindowTools/aopticaloverridedialog.h @@ -11,6 +11,7 @@ class AOpticalOverrideDialog; class AOpticalOverride; class AMaterialParticleCollection; class GraphWindowClass; +class AOpticalOverrideTester; class AOpticalOverrideDialog : public QDialog { @@ -35,6 +36,7 @@ private slots: int matFrom; int matTo; QStringList matNames; //need? + AOpticalOverrideTester* TesterWindow; int customWidgetPositionInLayout = 5; QWidget* customWidget = 0; diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp new file mode 100644 index 00000000..019ac346 --- /dev/null +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -0,0 +1,130 @@ +#include "aopticaloverridetester.h" +#include "ui_aopticaloverridetester.h" +#include "amessage.h" +#include "amaterialparticlecolection.h" +#include "aopticaloverride.h" +#include "aphoton.h" +#include "atracerstateful.h" +#include "graphwindowclass.h" +#include "asimulationstatistics.h" + +#include +#include +#include +#include + +#include "TVector3.h" +#include "TRandom2.h" +#include "TLegend.h" + +AOpticalOverrideTester::AOpticalOverrideTester(GraphWindowClass* GraphWindow, AMaterialParticleCollection* MPcollection, int matFrom, int matTo, QWidget *parent) : + QMainWindow(parent), ui(new Ui::AOpticalOverrideTester), + MPcollection(MPcollection), MatFrom(matFrom), MatTo(matTo), + GraphWindow(GraphWindow) +{ + ui->setupUi(this); + + ov = (*MPcollection)[matFrom]->OpticalOverrides.at(matTo); + + QDoubleValidator* dv = new QDoubleValidator(this); + dv->setNotation(QDoubleValidator::ScientificNotation); + QList list = this->findChildren(); + foreach(QLineEdit *w, list) if (w->objectName().startsWith("led")) w->setValidator(dv); +} + +AOpticalOverrideTester::~AOpticalOverrideTester() +{ + delete ui; +} + +void AOpticalOverrideTester::on_pbDirectionHelp_clicked() +{ + QString s = "Vectors are not necessary normalized to unity (automatic when used)\n\n" + "Note that in overrides caluclations" + "normal of the surface is always oriented" + "in the direction away from the incoming photon"; +} + +#include "TGraph.h" +void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() +{ + int num = ui->sbST_number->value(); + QVector Spike(91, 0), Lobe(91, 0), Diffuse(91, 0), Total(91, 0), Angle; + double N[3], K[3]; + N[0] = 0; + N[1] = 0; + N[2] = 1.0; + + APhoton ph; + ph.SimStat = new ASimulationStatistics(); + + ATracerStateful Resources; + Resources.RandGen = new TRandom2(); //leak! + + for (int iA=0; iA<91; iA++) //cycle by angle of incidence + { + double angle = iA; + if (angle == 90) angle = 89.9; + Angle.append(angle); + //angle->photon direction + double cosA = cos(3.1415926535*angle/180.0); + double sinA = sin(3.1415926535*angle/180.0); + for (int i=0; icalculate(Resources, &ph, N); + + switch (ov->Status) + { + case AOpticalOverride::Absorption: continue; break; + case AOpticalOverride::SpikeReflection: Spike[iA]++; break; + case AOpticalOverride::LobeReflection: Lobe[iA]++; break; + case AOpticalOverride::LambertianReflection: Diffuse[iA]++; break; + default: + qCritical()<<"Unknown process!"; + exit(666); + } + } + Spike[iA] /= num; + Lobe[iA] /= num; + Diffuse[iA] /= num; + Total[iA] = Spike[iA]+Lobe[iA]+Diffuse[iA]; + } + + TGraph *gS, *gL, *gD, *gT; + gT = GraphWindow->MakeGraph(&Angle, &Total, 2, "Angle", "", 0, 1, 1, 2, "", true); + gT->SetMinimum(0); + gT->SetTitle("Total"); + gS = GraphWindow->MakeGraph(&Angle, &Spike, 1, "Angle", "", 0, 1, 1, 1, "", true); + gS->SetTitle("Spike"); + gL = GraphWindow->MakeGraph(&Angle, &Lobe, 3, "Angle", "", 0, 1, 1, 1, "", true); + gL->SetTitle("Lobe"); + gD = GraphWindow->MakeGraph(&Angle, &Diffuse, 4, "Angle", "", 0, 1, 1, 1, "", true); + gD->SetTitle("Diffuse"); + + GraphWindow->Draw(gT, "AL"); + GraphWindow->Draw(gS, "Lsame"); + GraphWindow->Draw(gL, "Lsame"); + GraphWindow->Draw(gD, "Lsame"); + + TLegend *leg = new TLegend(0.1, 0.7, 0.3, 0.9); + leg->SetFillColor(0); + //leg->SetHeader("test legend"); + leg->AddEntry(gT, "Total", "lp"); + leg->AddEntry(gS, "Spike", "lp"); + leg->AddEntry(gL, "Lobe", "lp"); + leg->AddEntry(gD, "Diffuse", "lp"); + GraphWindow->Draw(leg, "same"); + + delete ph.SimStat; +} + diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h new file mode 100644 index 00000000..112a1794 --- /dev/null +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -0,0 +1,36 @@ +#ifndef AOPTICALOVERRIDETESTER_H +#define AOPTICALOVERRIDETESTER_H + +#include + +namespace Ui { +class AOpticalOverrideTester; +} + +class AMaterialParticleCollection; +class AOpticalOverride; +class GraphWindowClass; + +class AOpticalOverrideTester : public QMainWindow +{ + Q_OBJECT + +public: + explicit AOpticalOverrideTester(GraphWindowClass *GraphWindow, AMaterialParticleCollection *MPcollection, int matFrom, int matTo, QWidget *parent = 0); + ~AOpticalOverrideTester(); + +private slots: + void on_pbDirectionHelp_clicked(); + + void on_pbST_RvsAngle_clicked(); + +private: + Ui::AOpticalOverrideTester *ui; + AMaterialParticleCollection* MPcollection; + int MatFrom; + int MatTo; + AOpticalOverride* ov; + GraphWindowClass* GraphWindow; +}; + +#endif // AOPTICALOVERRIDETESTER_H diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui new file mode 100644 index 00000000..bd6b7a94 --- /dev/null +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -0,0 +1,608 @@ + + + AOpticalOverrideTester + + + + 0 + 0 + 401 + 478 + + + + MainWindow + + + + + + + + + + + Can be any values: Unitary vector is calculated automatically + + + Surface normal: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Can be any values: Unitary vector is calculated automatically + + + Photon direction: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + i: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + i: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + false + + + + + + + 1 + + + + + + + + + + + j: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + j: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 0 + + + false + + + + + + + 0 + + + + + + + + + + + k: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + k: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 1 + + + false + + + + + + + -1 + + + + + + + + + + 25 + 16777215 + + + + ? + + + + + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Set angle to + + + + + + + + 75 + 16777215 + + + + 45 + + + + + + + degrees + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Number of photons: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 1000000 + + + 1000 + + + + + + + Photon wavelength: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 176 + + + + + + + nm + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Refractive index + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + from: + + + + + + + + 75 + 16777215 + + + + 1.69 + + + + + + + to: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 1.66 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + 75 + true + + + + Reflection vs angle of incidence + + + + + + + + 75 + true + + + + Trace photons + + + + + + + Lambertian distribution for incoming photons! + + + Diffuse irradiation test + + + + + + + Absorption/Spike/Lobe/Lambert: counts and fractions + + + Qt::AlignCenter + + + + + + + + + + + + Show tracks + + + + + + + + All tracks + + + + + Only Spike + + + + + Only Lobe + + + + + Only Lamb + + + + + None + + + + + + + + Histogram: cos to degrees + + + true + + + + + + + + + Qt::Horizontal + + + + + + + + + + 25 + 16777215 + + + + ? + + + + + + + n2, 1.4, 2, 0.05 + + + + + + + Reflection vs parameter + + + + + + + + + + + + Use given photon dir + + + + + Isotropic irradiation + + + + + Diffuse irradiation + + + + + + + + + Show sum reflection + + + + + Show diffuse + + + + + Show spike+lobe + + + + + Show spike + + + + + Show lobe + + + + + + + + + + + + 0 + 0 + 401 + 21 + + + + + + + diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index dff9021c..2544528d 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 0 + 3 From 7185f47b8b7c37c7e5ddeb337039bdfd77fef964 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 2 Oct 2018 00:55:59 +0100 Subject: [PATCH 023/140] ++ --- .../aopticaloverridescriptinterface.cpp | 54 +++++++++++++--- .../aopticaloverridescriptinterface.h | 16 +++-- .../ascriptopticaloverride.cpp | 10 +-- src/ants2.pro | 3 +- src/common/aopticaloverride.cpp | 30 +++------ src/common/aphoton.cpp | 62 +++++++++++++++++++ src/common/aphoton.h | 51 +++------------ .../aopticaloverridetester.cpp | 47 +++++++------- .../MainWindowTools/aopticaloverridetester.h | 5 ++ src/modules/phscatclaudiomodel.cpp | 6 +- 10 files changed, 174 insertions(+), 110 deletions(-) create mode 100644 src/common/aphoton.cpp diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index c48ef6db..51eb1824 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -5,45 +5,83 @@ AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() {} -void AOpticalOverrideScriptInterface::configure(APhoton *photon, const double *normalVector) +void AOpticalOverrideScriptInterface::configure(TRandom2 * randGen, APhoton *photon, const double *normalVector) { + RandGen = randGen; Photon = photon; NormalVector = normalVector; - //if script did not modify any photon properties, this will be the result: + //if script did not modify any photon properties, assuming override is skipped (doing Fresnel): bResultAlreadySet = true; ReturnResult = AOpticalOverride::NotTriggered; + Status = AOpticalOverride::Fresnel; } -AOpticalOverride::OpticalOverrideResultEnum AOpticalOverrideScriptInterface::getResult() const +AOpticalOverride::OpticalOverrideResultEnum AOpticalOverrideScriptInterface::getResult(AOpticalOverride::ScatterStatusEnum& status) { - if (bResultAlreadySet) return ReturnResult; + if (bResultAlreadySet) + { + status = Status; + return ReturnResult; + } - Photon->ensureUnitaryLength(); + Photon->EnsureUnitaryLength(); double sum = 0; for (int i=0; i<3; i++) sum += Photon->v[i] * NormalVector[i]; + + qDebug() << "New Dir"<v[0]<v[1]<v[2]; + qDebug() << "sum"<v[i]; + for (int i=0; i<3; i++) Photon->v[i] -= 2.0*NK*NormalVector[i]; + + //Photon->SimStat->OverrideSimplisticReflection++; + Status = AOpticalOverride::SpikeReflection; + ReturnResult = AOpticalOverride::Back; + bResultAlreadySet = true; +} + +void AOpticalOverrideScriptInterface::Uniform() +{ + Photon->RandomDir(RandGen); + bResultAlreadySet = false; } void AOpticalOverrideScriptInterface::SetDirection(double vx, double vy, double vz) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 4e4745e6..c8dfb798 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -12,23 +12,29 @@ class AOpticalOverrideScriptInterface : public AScriptInterface public: AOpticalOverrideScriptInterface(); - void configure(APhoton *Photon, const double *NormalVector); - AOpticalOverride::OpticalOverrideResultEnum getResult() const; + void configure(TRandom2 * RandGen, APhoton *Photon, const double *NormalVector); + AOpticalOverride::OpticalOverrideResultEnum getResult(AOpticalOverride::ScatterStatusEnum& status); public slots: void Absorb(); - void Fresnel(); - //void TransmissionSnell(); //check was meddled - void TransmissionDirect(); //check was meddled + void Fresnel(); //ToDo: meddling test! + //void TransmissionSnell(); //ToDo: meddling test! + void TransmissionDirect(); //ToDo: meddling test! + void SpecularReflection(); //ToDo: meddling test! + void Uniform(); //ToDo: meddling test! + //void LambertBack(); //ToDo: meddling test! + //void LambertForward(); //ToDo: meddling test! void SetDirection(double vx, double vy, double vz); private: + TRandom2 * RandGen; APhoton * Photon; const double * NormalVector; bool bResultAlreadySet; AOpticalOverride::OpticalOverrideResultEnum ReturnResult; //{NotTriggered, Absorbed, Forward, Back, _Error_}; + AOpticalOverride::ScatterStatusEnum Status; }; #endif // AOPTICALOVERRIDESCRIPTINTERFACE_H diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index c8c200c1..5e8879c9 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -28,11 +28,11 @@ AScriptOpticalOverride::~AScriptOpticalOverride() {} AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { //qDebug() << "Configuring script interface"; - Resources.interfaceObject->configure(Photon, NormalVector); + Resources.interfaceObject->configure(Resources.RandGen, Photon, NormalVector); //qDebug() << "Evaluating script"; Resources.evaluateScript(Script); - qDebug() << "Photon status:"<getResult(); - return Resources.interfaceObject->getResult(); + qDebug() << "Photon result:"<getResult(Status)<<"Status"<getResult(Status); } void AScriptOpticalOverride::printConfiguration(int) @@ -118,7 +118,7 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) normal[0] = 0; normal[1] = 0; normal[2] = 1.0; AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); - interfaceObject->configure(&phot, normal); + interfaceObject->configure(RandGen, &phot, normal); interfaceObject->setObjectName("photon"); //sw->SetInterfaceObject(0); @@ -131,6 +131,6 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) QCoreApplication::processEvents(); QThread::usleep(200); } - qDebug() << "exit script:"< 0.25) - { - a = RandGen->Rndm() - 0.5; - b = RandGen->Rndm() - 0.5; - r2 = a*a + b*b; - } - Photon->v[2] = ( -1.0 + 8.0 * r2 ); - double scale = 8.0 * TMath::Sqrt(0.25 - r2); - Photon->v[0] = a*scale; - Photon->v[1] = b*scale; -} - BasicOpticalOverride::BasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo, double probLoss, double probRef, double probDiff, int scatterModel) : AOpticalOverride(MatCollection, MatFrom, MatTo), probLoss(probLoss), probRef(probRef), probDiff(probDiff), scatterModel(scatterModel) {} @@ -124,7 +108,7 @@ AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(ATra { case 0: //4Pi scattering // qDebug()<<"4Pi scatter"; - RandomDir(Resources.RandGen, Photon); + Photon->RandomDir(Resources.RandGen); // qDebug()<<"New direction:"<RandomDir(Resources.RandGen); Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -162,7 +146,7 @@ AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(ATra double norm2; do { - RandomDir(Resources.RandGen, Photon); + Photon->RandomDir(Resources.RandGen); Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -425,7 +409,7 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATrac double norm2; do { - RandomDir(Resources.RandGen, Photon); + Photon->RandomDir(Resources.RandGen); Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -625,7 +609,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra if (ReemissionModel == 0) { - RandomDir(Resources.RandGen, Photon); + Photon->RandomDir(Resources.RandGen); //enering new volume or backscattering? //normal is in the positive direction in respect to the original direction! if (Photon->v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2] < 0) @@ -645,7 +629,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra // qDebug()<<"2Pi lambertian scattering backward"; do { - RandomDir(Resources.RandGen, Photon); + Photon->RandomDir(Resources.RandGen); Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } @@ -661,7 +645,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra // qDebug()<<"2Pi lambertian scattering forward"; do { - RandomDir(Resources.RandGen, Photon); + Photon->RandomDir(Resources.RandGen); Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; } diff --git a/src/common/aphoton.cpp b/src/common/aphoton.cpp new file mode 100644 index 00000000..ae6054a1 --- /dev/null +++ b/src/common/aphoton.cpp @@ -0,0 +1,62 @@ +#include "aphoton.h" + +#include "TRandom2.h" +#include "TMath.h" + +APhoton::APhoton() {} + +APhoton::APhoton(double *xyz, double *Vxyz, int waveIndex, double time) : + time(time), waveIndex(waveIndex), scint_type(0) +{ + r[0]=xyz[0]; r[1]=xyz[1]; r[2]=xyz[2]; + v[0]=Vxyz[0]; v[1]=Vxyz[1]; v[2]=Vxyz[2]; +} + +void APhoton::CopyFrom(const APhoton *CopyFrom) +{ + r[0] = CopyFrom->r[0]; + r[1] = CopyFrom->r[1]; + r[2] = CopyFrom->r[2]; + + v[0] = CopyFrom->v[0]; + v[1] = CopyFrom->v[1]; + v[2] = CopyFrom->v[2]; + + time = CopyFrom->time; + waveIndex = CopyFrom->waveIndex; + scint_type = CopyFrom->scint_type; + fSkipThisPhoton = CopyFrom->fSkipThisPhoton; + + SimStat = CopyFrom->SimStat; +} + +void APhoton::EnsureUnitaryLength() +{ + double mod; + for (int i=0; i<3; i++) + mod += ( v[i] * v[i] ); + mod = TMath::Sqrt(mod); + + if (mod != 0) + for (int i=0; i<3; i++) v[i] /= mod; + else + { + v[0] = 0; v[1] = 0; v[2] = 1.0; + } +} + +void APhoton::RandomDir(TRandom2 *RandGen) +{ + //Sphere function of Root: + double a = 0, b = 0, r2 = 1.0; + while (r2 > 0.25) + { + a = RandGen->Rndm() - 0.5; + b = RandGen->Rndm() - 0.5; + r2 = a*a + b*b; + } + v[2] = ( -1.0 + 8.0 * r2 ); + double scale = 8.0 * TMath::Sqrt(0.25 - r2); + v[0] = a*scale; + v[1] = b*scale; +} diff --git a/src/common/aphoton.h b/src/common/aphoton.h index 839728fc..83641774 100644 --- a/src/common/aphoton.h +++ b/src/common/aphoton.h @@ -1,62 +1,27 @@ #ifndef APHOTON #define APHOTON -#include - class ASimulationStatistics; +class TRandom2; class APhoton { public: - APhoton() : fSkipThisPhoton(false), SimStat(0) {} - APhoton(double* xyz, double* Vxyz, int waveIndex=-1, double time=0) : - time(time), waveIndex(waveIndex), scint_type(0), fSkipThisPhoton(false), SimStat(0) - { - r[0]=xyz[0]; r[1]=xyz[1]; r[2]=xyz[2]; - v[0]=Vxyz[0]; v[1]=Vxyz[1]; v[2]=Vxyz[2]; - } + APhoton(); + APhoton(double* xyz, double* Vxyz, int waveIndex=-1, double time=0); double r[3]; //position double v[3]; //direction (must be already normalized to unit vector!!!) double time; //time stamp int waveIndex; //wavelength is always binned during simulations int scint_type; //1 - primary //2 - secondary // 0 - undefined - bool fSkipThisPhoton; //flag to skip this photon due to e.g. direction check - - ASimulationStatistics* SimStat; - - void CopyFrom(const APhoton* CopyFrom) - { - r[0] = CopyFrom->r[0]; - r[1] = CopyFrom->r[1]; - r[2] = CopyFrom->r[2]; - - v[0] = CopyFrom->v[0]; - v[1] = CopyFrom->v[1]; - v[2] = CopyFrom->v[2]; - - time = CopyFrom->time; - waveIndex = CopyFrom->waveIndex; - scint_type = CopyFrom->scint_type; - fSkipThisPhoton = CopyFrom->fSkipThisPhoton; - - SimStat = CopyFrom->SimStat; - } + bool fSkipThisPhoton = false; //flag to skip this photon due to e.g. direction check - void ensureUnitaryLength() - { - double mod; - for (int i=0; i<3; i++) - mod += ( v[i] * v[i] ); - mod = sqrt(mod); + ASimulationStatistics* SimStat = 0; - if (mod != 0) - for (int i=0; i<3; i++) v[i] /= mod; - else - { - v[0] = 0; v[1] = 0; v[2] = 1.0; - } - } + void CopyFrom(const APhoton* CopyFrom); + void EnsureUnitaryLength(); + void RandomDir(TRandom2* RandGen); }; #endif // APHOTON diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 019ac346..ac00c999 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -3,6 +3,7 @@ #include "amessage.h" #include "amaterialparticlecolection.h" #include "aopticaloverride.h" +#include "aopticaloverridescriptinterface.h" #include "aphoton.h" #include "atracerstateful.h" #include "graphwindowclass.h" @@ -15,7 +16,9 @@ #include "TVector3.h" #include "TRandom2.h" +#include "TGraph.h" #include "TLegend.h" +#include "TMath.h" AOpticalOverrideTester::AOpticalOverrideTester(GraphWindowClass* GraphWindow, AMaterialParticleCollection* MPcollection, int matFrom, int matTo, QWidget *parent) : QMainWindow(parent), ui(new Ui::AOpticalOverrideTester), @@ -30,11 +33,19 @@ AOpticalOverrideTester::AOpticalOverrideTester(GraphWindowClass* GraphWindow, AM dv->setNotation(QDoubleValidator::ScientificNotation); QList list = this->findChildren(); foreach(QLineEdit *w, list) if (w->objectName().startsWith("led")) w->setValidator(dv); + + RandGen = new TRandom2(); + Resources.RandGen = RandGen; + AOpticalOverrideScriptInterface* obj = new AOpticalOverrideScriptInterface(); + obj->setObjectName("photon"); + Resources.registerInterfaceObject(obj); } AOpticalOverrideTester::~AOpticalOverrideTester() { delete ui; + + delete RandGen; } void AOpticalOverrideTester::on_pbDirectionHelp_clicked() @@ -45,10 +56,9 @@ void AOpticalOverrideTester::on_pbDirectionHelp_clicked() "in the direction away from the incoming photon"; } -#include "TGraph.h" void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() { - int num = ui->sbST_number->value(); + int numPhotons = ui->sbST_number->value(); QVector Spike(91, 0), Lobe(91, 0), Diffuse(91, 0), Total(91, 0), Angle; double N[3], K[3]; N[0] = 0; @@ -58,45 +68,39 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); - ATracerStateful Resources; - Resources.RandGen = new TRandom2(); //leak! - for (int iA=0; iA<91; iA++) //cycle by angle of incidence { double angle = iA; if (angle == 90) angle = 89.9; Angle.append(angle); //angle->photon direction - double cosA = cos(3.1415926535*angle/180.0); - double sinA = sin(3.1415926535*angle/180.0); - for (int i=0; icalculate(Resources, &ph, N); switch (ov->Status) - { + { case AOpticalOverride::Absorption: continue; break; case AOpticalOverride::SpikeReflection: Spike[iA]++; break; case AOpticalOverride::LobeReflection: Lobe[iA]++; break; - case AOpticalOverride::LambertianReflection: Diffuse[iA]++; break; - default: - qCritical()<<"Unknown process!"; - exit(666); - } - } - Spike[iA] /= num; - Lobe[iA] /= num; - Diffuse[iA] /= num; + case AOpticalOverride::LambertianReflection: Diffuse[iA]++; break; //TODO what about scrip override? + default: ; + } + } + Spike[iA] /= numPhotons; + Lobe[iA] /= numPhotons; + Diffuse[iA] /= numPhotons; Total[iA] = Spike[iA]+Lobe[iA]+Diffuse[iA]; } @@ -118,7 +122,6 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() TLegend *leg = new TLegend(0.1, 0.7, 0.3, 0.9); leg->SetFillColor(0); - //leg->SetHeader("test legend"); leg->AddEntry(gT, "Total", "lp"); leg->AddEntry(gS, "Spike", "lp"); leg->AddEntry(gL, "Lobe", "lp"); diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 112a1794..7c18a512 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -1,6 +1,8 @@ #ifndef AOPTICALOVERRIDETESTER_H #define AOPTICALOVERRIDETESTER_H +#include "atracerstateful.h" + #include namespace Ui { @@ -10,6 +12,7 @@ class AOpticalOverrideTester; class AMaterialParticleCollection; class AOpticalOverride; class GraphWindowClass; +class TRandom2; class AOpticalOverrideTester : public QMainWindow { @@ -31,6 +34,8 @@ private slots: int MatTo; AOpticalOverride* ov; GraphWindowClass* GraphWindow; + TRandom2* RandGen; + ATracerStateful Resources; }; #endif // AOPTICALOVERRIDETESTER_H diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 9729d278..cb53cf6a 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -244,7 +244,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(ATra counter--; if (counter == 0) { - Status = ErrorDetected; + Status = Error; return _Error_; } @@ -418,7 +418,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(AT counter--; if (counter == 0) { - Status = ErrorDetected; + Status = Error; return _Error_; } @@ -594,7 +594,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(AT counter--; if (counter == 0) { - Status = ErrorDetected; + Status = Error; return _Error_; } From d710ecd3a0056f887ee8fa0d9cc902131f3c4b2c Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 2 Oct 2018 00:59:23 +0100 Subject: [PATCH 024/140] ++ --- src/common/aopticaloverride.h | 6 ++---- src/gui/mainwindow.ui | 2 +- src/modules/amaterialparticlecolection.cpp | 5 ++--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 69befdc5..3698bfe9 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -26,8 +26,8 @@ class AOpticalOverride public: //return status for photon tracing: enum OpticalOverrideResultEnum {NotTriggered, Absorbed, Forward, Back, _Error_}; - //detailed status for statistics only: - enum ScatterStatusEnum {SpikeReflection, LobeReflection, LambertianReflection, Absorption, Transmission, ErrorDetected}; + //detailed status for statistics only - used by override tester only + enum ScatterStatusEnum {SpikeReflection, LobeReflection, LambertianReflection, Absorption, Transmission, Error, UnclassifiedReflection, Empty, Fresnel}; AOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) @@ -60,8 +60,6 @@ class AOpticalOverride protected: AMaterialParticleCollection* MatCollection; int MatFrom, MatTo; // material index of material before(from) and after(to) the optical interface - - void RandomDir(TRandom2* RandGen, APhoton* Photon); }; class BasicOpticalOverride : public AOpticalOverride diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 2544528d..dff9021c 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 3 + 0 diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index 2a752261..4f3d0b93 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -5,6 +5,8 @@ #include "ajsontools.h" #include "acommonfunctions.h" #include "atracerstateful.h" +#include "ascriptopticaloverride.h" +#include "aopticaloverridescriptinterface.h" #include #include @@ -78,11 +80,8 @@ void AMaterialParticleCollection::updateRandomGenForThread(int ID, TRandom2* Ran MaterialCollectionData[imat]->UpdateRandGen(ID, RandGen); } -#include "ascriptopticaloverride.h" -#include "aopticaloverridescriptinterface.h" void AMaterialParticleCollection::registerOpticalOverrideScriptInterfaces(ATracerStateful &record) { - qDebug() << "Registering ov for the thread..."; AOpticalOverrideScriptInterface* interfaceObj = 0; for (AMaterial* mat : MaterialCollectionData) { From 2f62558081f603450dce45f80a0b7ced36cef598 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 2 Oct 2018 01:25:18 +0100 Subject: [PATCH 025/140] ++ --- .../aopticaloverridescriptinterface.cpp | 1 + .../ascriptopticaloverride.cpp | 7 ------ src/OpticalOverrides/ascriptopticaloverride.h | 2 -- src/common/atracerstateful.cpp | 22 ++++++++++------- src/common/atracerstateful.h | 2 +- src/modules/amaterialparticlecolection.cpp | 24 +++---------------- src/modules/amaterialparticlecolection.h | 4 ++-- src/modules/aphotontracer.cpp | 2 +- 8 files changed, 21 insertions(+), 43 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index 51eb1824..2d496c32 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -25,6 +25,7 @@ AOpticalOverride::OpticalOverrideResultEnum AOpticalOverrideScriptInterface::get return ReturnResult; } + qDebug() << "New Dir before"<v[0]<v[1]<v[2]; Photon->EnsureUnitaryLength(); double sum = 0; for (int i=0; i<3; i++) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 5e8879c9..6f670b21 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -64,13 +64,6 @@ bool AScriptOpticalOverride::readFromJson(QJsonObject &json) return true; } -AOpticalOverrideScriptInterface *AScriptOpticalOverride::generateInterfaceScriptObject() -{ - AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); - interfaceObject->setObjectName("photon"); - return interfaceObject; -} - #ifdef GUI QWidget *AScriptOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *) { diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index 78d6d1aa..257fc718 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -22,8 +22,6 @@ class AScriptOpticalOverride : public AOpticalOverride virtual void writeToJson(QJsonObject &json) override; virtual bool readFromJson(QJsonObject &json) override; - AOpticalOverrideScriptInterface* generateInterfaceScriptObject(); - #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; #endif diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index fa84715b..36c7eeb0 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -25,20 +25,24 @@ void ATracerStateful::evaluateScript(const QString &Script) qDebug() << "eval result:" << res.toString(); } -void ATracerStateful::registerAllInterfaceObjects(AMaterialParticleCollection *MPcollection) +void ATracerStateful::generateScriptInfrastructureIfNeeded(AMaterialParticleCollection *MPcollection) { - MPcollection->registerOpticalOverrideScriptInterfaces(*this); -} + bool bInUse = MPcollection->isScriptOpticalOverrideDefined(); -void ATracerStateful::registerInterfaceObject(AOpticalOverrideScriptInterface *interfaceObj) -{ - if (!ScriptEngine) + if (bInUse) { qDebug() << "Creating script engine"; ScriptEngine = new QScriptEngine(); + + interfaceObject = new AOpticalOverrideScriptInterface(); + qDebug() << "Created interface object:"<setObjectName("photon"); + QScriptValue val = ScriptEngine->newQObject(interfaceObject, QScriptEngine::QtOwnership); + ScriptEngine->globalObject().setProperty(interfaceObject->objectName(), val); } +} + +void ATracerStateful::registerInterfaceObject(AOpticalOverrideScriptInterface *interfaceObj) +{ - QScriptValue val = ScriptEngine->newQObject(interfaceObj, QScriptEngine::QtOwnership); - ScriptEngine->globalObject().setProperty(interfaceObj->objectName(), val); - interfaceObject = interfaceObj; } diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h index a71b2a91..dac6b8a0 100644 --- a/src/common/atracerstateful.h +++ b/src/common/atracerstateful.h @@ -19,7 +19,7 @@ class ATracerStateful void evaluateScript(const QString& Script); - void registerAllInterfaceObjects(AMaterialParticleCollection* MPcollection); + void generateScriptInfrastructureIfNeeded(AMaterialParticleCollection* MPcollection); //called by MPcollection void registerInterfaceObject(AOpticalOverrideScriptInterface *interfaceObj); diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index 4f3d0b93..f3899b63 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -6,7 +6,6 @@ #include "acommonfunctions.h" #include "atracerstateful.h" #include "ascriptopticaloverride.h" -#include "aopticaloverridescriptinterface.h" #include #include @@ -80,33 +79,16 @@ void AMaterialParticleCollection::updateRandomGenForThread(int ID, TRandom2* Ran MaterialCollectionData[imat]->UpdateRandGen(ID, RandGen); } -void AMaterialParticleCollection::registerOpticalOverrideScriptInterfaces(ATracerStateful &record) +bool AMaterialParticleCollection::isScriptOpticalOverrideDefined() const { - AOpticalOverrideScriptInterface* interfaceObj = 0; for (AMaterial* mat : MaterialCollectionData) - { for (AOpticalOverride* ov : mat->OpticalOverrides) if (ov) { AScriptOpticalOverride* sov = dynamic_cast(ov); - if (!sov) continue; - - qDebug() << " Found script override:" << mat->name << ov->getReportLine(); - - if (interfaceObj) - { - qDebug() << " Interface object already registered"; - qDebug() << " Assigned interface object:" << interfaceObj; - } - else - { - qDebug() << " Interface object not yet registered"; - interfaceObj = sov->generateInterfaceScriptObject(); - qDebug() << " Registering interface object" << interfaceObj << interfaceObj->objectName(); - record.registerInterfaceObject(interfaceObj); - } + if (sov) return true; } - } + return false; } void AMaterialParticleCollection::getFirstOverridenMaterial(int &ifrom, int &ito) diff --git a/src/modules/amaterialparticlecolection.h b/src/modules/amaterialparticlecolection.h index f1df18e6..a62c32a2 100644 --- a/src/modules/amaterialparticlecolection.h +++ b/src/modules/amaterialparticlecolection.h @@ -38,8 +38,8 @@ class AMaterialParticleCollection : public QObject void UpdateRuntimePropertiesAndWavelengthBinning(GeneralSimSettings *SimSet, TRandom2 *RandGen, int numThreads = 1); void updateRandomGenForThread(int ID, TRandom2 *RandGen); - //for script-based optical overrides initialize script units in ScriptEngine - void registerOpticalOverrideScriptInterfaces(ATracerStateful& record); + //for script-based optical override initialization + bool isScriptOpticalOverrideDefined() const; //info requests //materials diff --git a/src/modules/aphotontracer.cpp b/src/modules/aphotontracer.cpp index da0b44cb..fd22dad0 100644 --- a/src/modules/aphotontracer.cpp +++ b/src/modules/aphotontracer.cpp @@ -34,7 +34,7 @@ APhotonTracer::APhotonTracer(TGeoManager *geoManager, TRandom2 *RandomGenerator, //for transfer to overrides ResourcesForOverrides.RandGen = RandGen; - ResourcesForOverrides.registerAllInterfaceObjects(MaterialCollection); + ResourcesForOverrides.generateScriptInfrastructureIfNeeded(MaterialCollection); } APhotonTracer::~APhotonTracer() From f5a6c7569838b9118e9a35553175d623276b094a Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 2 Oct 2018 12:16:54 +0100 Subject: [PATCH 026/140] ++ --- .../aopticaloverridescriptinterface.cpp | 7 +- .../aopticaloverridescriptinterface.h | 2 +- .../ascriptopticaloverride.cpp | 17 +- src/ants2.pro | 6 +- src/common/atracerstateful.cpp | 40 +++-- src/common/atracerstateful.h | 9 +- .../aopticaloverridetester.cpp | 4 +- src/gui/ascriptwindow.cpp | 3 +- src/scriptmode/ajavascriptmanager.cpp | 3 +- src/scriptmode/amathscriptinterface.cpp | 154 +++++++++++++++++ src/scriptmode/amathscriptinterface.h | 50 ++++++ src/scriptmode/ascriptinterfacefactory.h | 5 +- src/scriptmode/coreinterfaces.cpp | 163 ------------------ src/scriptmode/coreinterfaces.h | 42 ----- 14 files changed, 257 insertions(+), 248 deletions(-) create mode 100644 src/scriptmode/amathscriptinterface.cpp create mode 100644 src/scriptmode/amathscriptinterface.h diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index 2d496c32..f5256c8c 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -25,14 +25,13 @@ AOpticalOverride::OpticalOverrideResultEnum AOpticalOverrideScriptInterface::get return ReturnResult; } - qDebug() << "New Dir before"<v[0]<v[1]<v[2]; Photon->EnsureUnitaryLength(); double sum = 0; for (int i=0; i<3; i++) sum += Photon->v[i] * NormalVector[i]; - qDebug() << "New Dir"<v[0]<v[1]<v[2]; - qDebug() << "sum"<v[0]<v[1]<v[2]; + //qDebug() << "sum"<RandomDir(RandGen); bResultAlreadySet = false; diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index c8dfb798..58d01e00 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -21,7 +21,7 @@ public slots: //void TransmissionSnell(); //ToDo: meddling test! void TransmissionDirect(); //ToDo: meddling test! void SpecularReflection(); //ToDo: meddling test! - void Uniform(); //ToDo: meddling test! + void Isotropic(); //ToDo: meddling test! //void LambertBack(); //ToDo: meddling test! //void LambertForward(); //ToDo: meddling test! diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 6f670b21..af05ecbd 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -2,6 +2,7 @@ #include "amaterialparticlecolection.h" #include "atracerstateful.h" #include "aopticaloverridescriptinterface.h" +#include "amathscriptinterface.h" #ifdef GUI #include "ascriptwindow.h" @@ -27,12 +28,13 @@ AScriptOpticalOverride::~AScriptOpticalOverride() {} AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { - //qDebug() << "Configuring script interface"; - Resources.interfaceObject->configure(Resources.RandGen, Photon, NormalVector); - //qDebug() << "Evaluating script"; + //qDebug() << "Configuring script interfaces"; + Resources.overrideInterface->configure(Resources.RandGen, Photon, NormalVector); + Resources.mathInterface->setRandomGen(Resources.RandGen); + //qDebug() << "Evaluating script"; Resources.evaluateScript(Script); - qDebug() << "Photon result:"<getResult(Status)<<"Status"<getResult(Status); + //qDebug() << "Photon result:"<getResult(Status)<<"Status"<getResult(Status); } void AScriptOpticalOverride::printConfiguration(int) @@ -113,9 +115,10 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); interfaceObject->configure(RandGen, &phot, normal); interfaceObject->setObjectName("photon"); - - //sw->SetInterfaceObject(0); sw->SetInterfaceObject(interfaceObject, "photon"); //steals ownership! + AMathScriptInterface* math = new AMathScriptInterface(RandGen); + math->setObjectName("math"); + sw->SetInterfaceObject(math, "math"); //steals ownership! sw->setWindowModality(Qt::ApplicationModal); sw->show(); diff --git a/src/ants2.pro b/src/ants2.pro index 4e7e7930..cfd88782 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -353,7 +353,8 @@ SOURCES += main.cpp \ OpticalOverrides/ascriptopticaloverride.cpp \ common/atracerstateful.cpp \ gui/MainWindowTools/aopticaloverridetester.cpp \ - common/aphoton.cpp + common/aphoton.cpp \ + scriptmode/amathscriptinterface.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -482,7 +483,8 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/aopticaloverridescriptinterface.h \ OpticalOverrides/ascriptopticaloverride.h \ common/atracerstateful.h \ - gui/MainWindowTools/aopticaloverridetester.h + gui/MainWindowTools/aopticaloverridetester.h \ + scriptmode/amathscriptinterface.h # --- SIM --- ants2_SIM { diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index 36c7eeb0..5555ed2b 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -1,6 +1,7 @@ #include "atracerstateful.h" #include "amaterialparticlecolection.h" #include "aopticaloverridescriptinterface.h" +#include "amathscriptinterface.h" #include #include @@ -11,38 +12,41 @@ ATracerStateful::~ATracerStateful() { delete ScriptEngine; ScriptEngine = 0; - if (interfaceObject) + if (overrideInterface) { qDebug() << "Deleting ov script interface"; - delete interfaceObject; + delete overrideInterface; } } void ATracerStateful::evaluateScript(const QString &Script) { - qDebug() << "Script:"<evaluate(Script); - qDebug() << "eval result:" << res.toString(); + //qDebug() << "Script:"<evaluate(Script); + //qDebug() << "eval result:" << res.toString(); } void ATracerStateful::generateScriptInfrastructureIfNeeded(AMaterialParticleCollection *MPcollection) { bool bInUse = MPcollection->isScriptOpticalOverrideDefined(); - if (bInUse) - { - qDebug() << "Creating script engine"; - ScriptEngine = new QScriptEngine(); - - interfaceObject = new AOpticalOverrideScriptInterface(); - qDebug() << "Created interface object:"<setObjectName("photon"); - QScriptValue val = ScriptEngine->newQObject(interfaceObject, QScriptEngine::QtOwnership); - ScriptEngine->globalObject().setProperty(interfaceObject->objectName(), val); - } + if (bInUse) generateScriptInfrastructure(); } -void ATracerStateful::registerInterfaceObject(AOpticalOverrideScriptInterface *interfaceObj) +void ATracerStateful::generateScriptInfrastructure() { - + qDebug() << "Creating script engine"; + ScriptEngine = new QScriptEngine(); + + overrideInterface = new AOpticalOverrideScriptInterface(); + qDebug() << "Created interface object:"<setObjectName("photon"); + QScriptValue val = ScriptEngine->newQObject(overrideInterface, QScriptEngine::QtOwnership); + ScriptEngine->globalObject().setProperty(overrideInterface->objectName(), val); + + mathInterface = new AMathScriptInterface(RandGen); + mathInterface->setObjectName("math"); + val = ScriptEngine->newQObject(mathInterface, QScriptEngine::QtOwnership); + ScriptEngine->globalObject().setProperty(mathInterface->objectName(), val); } diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h index dac6b8a0..f4196e7b 100644 --- a/src/common/atracerstateful.h +++ b/src/common/atracerstateful.h @@ -8,6 +8,7 @@ class QScriptEngine; class QObject; class AMaterialParticleCollection; class AOpticalOverrideScriptInterface; +class AMathScriptInterface; //random generator is external //script engine is owned by this class, but created only if needed (there are script overrides) @@ -19,14 +20,14 @@ class ATracerStateful void evaluateScript(const QString& Script); - void generateScriptInfrastructureIfNeeded(AMaterialParticleCollection* MPcollection); + void generateScriptInfrastructureIfNeeded(AMaterialParticleCollection* MPcollection); //called by PhotonTracer (one per each thread!) - //called by MPcollection - void registerInterfaceObject(AOpticalOverrideScriptInterface *interfaceObj); + void generateScriptInfrastructure(); //can be use from outside to force generation (e.g. interface tester); RandGen should already be set! TRandom2 * RandGen = 0; QScriptEngine * ScriptEngine = 0; - AOpticalOverrideScriptInterface* interfaceObject = 0; + AOpticalOverrideScriptInterface* overrideInterface = 0; + AMathScriptInterface* mathInterface = 0; }; #endif // ATRACERSTATEFUL_H diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index ac00c999..8125b94c 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -36,9 +36,7 @@ AOpticalOverrideTester::AOpticalOverrideTester(GraphWindowClass* GraphWindow, AM RandGen = new TRandom2(); Resources.RandGen = RandGen; - AOpticalOverrideScriptInterface* obj = new AOpticalOverrideScriptInterface(); - obj->setObjectName("photon"); - Resources.registerInterfaceObject(obj); + Resources.generateScriptInfrastructure(); } AOpticalOverrideTester::~AOpticalOverrideTester() diff --git a/src/gui/ascriptwindow.cpp b/src/gui/ascriptwindow.cpp index 14123369..e78e3731 100644 --- a/src/gui/ascriptwindow.cpp +++ b/src/gui/ascriptwindow.cpp @@ -4,6 +4,7 @@ #include "atextedit.h" #include "localscriptinterfaces.h" #include "coreinterfaces.h" +#include "amathscriptinterface.h" #include "histgraphinterfaces.h" #include "interfacetoglobscript.h" #include "amessage.h" @@ -300,7 +301,7 @@ void AScriptWindow::SetInterfaceObject(QObject *interfaceObject, QString name) newFunctions << getListOfMethods(&core, "core", false); appendDeprecatedOrRemovedMethods(&core, "core"); - AInterfaceToMath math(0); //dummy to extract methods + AMathScriptInterface math(0); //dummy to extract methods QString mathName = (ScriptLanguage == _JavaScript_ ? "math" : "MATH"); fillHelper(&math, mathName); newFunctions << getListOfMethods(&math, mathName, false); diff --git a/src/scriptmode/ajavascriptmanager.cpp b/src/scriptmode/ajavascriptmanager.cpp index 1bb45d26..b87ee8d3 100644 --- a/src/scriptmode/ajavascriptmanager.cpp +++ b/src/scriptmode/ajavascriptmanager.cpp @@ -3,6 +3,7 @@ #include "ainterfacetomessagewindow.h" #endif #include "coreinterfaces.h" +#include "amathscriptinterface.h" #include "ascriptinterfacefactory.h" #include "ainterfacetomultithread.h" @@ -182,7 +183,7 @@ void AJavaScriptManager::SetInterfaceObject(QObject *interfaceObject, QString na engine->globalObject().setProperty(coreName, coreVal); interfaces.append(coreObj); //registering math module - QObject* mathObj = new AInterfaceToMath(RandGen); + QObject* mathObj = new AMathScriptInterface(RandGen); QScriptValue mathVal = engine->newQObject(mathObj, QScriptEngine::QtOwnership); QString mathName = "math"; mathObj->setObjectName(mathName); diff --git a/src/scriptmode/amathscriptinterface.cpp b/src/scriptmode/amathscriptinterface.cpp new file mode 100644 index 00000000..6bbaecc1 --- /dev/null +++ b/src/scriptmode/amathscriptinterface.cpp @@ -0,0 +1,154 @@ +#include "amathscriptinterface.h" + +#include "TRandom2.h" + +AMathScriptInterface::AMathScriptInterface(TRandom2* RandGen) +{ + Description = "Expanded math module; implemented using std and CERN ROOT functions"; + + this->RandGen = RandGen; + + H["random"] = "Returns a random number between 0 and 1.\nGenerator respects the seed set by SetSeed method of the sim module!"; + H["gauss"] = "Returns a random value sampled from Gaussian distribution with mean and sigma given by the user"; + H["poisson"] = "Returns a random value sampled from Poisson distribution with mean given by the user"; + H["maxwell"] = "Returns a random value sampled from maxwell distribution with Sqrt(kT/M) given by the user"; + H["exponential"] = "Returns a random value sampled from exponential decay with decay time given by the user"; +} + +void AMathScriptInterface::setRandomGen(TRandom2 *RandGen) +{ + this->RandGen = RandGen; +} + +double AMathScriptInterface::abs(double val) +{ + return std::abs(val); +} + +double AMathScriptInterface::acos(double val) +{ + return std::acos(val); +} + +double AMathScriptInterface::asin(double val) +{ + return std::asin(val); +} + +double AMathScriptInterface::atan(double val) +{ + return std::atan(val); +} + +double AMathScriptInterface::atan2(double y, double x) +{ + return std::atan2(y, x); +} + +double AMathScriptInterface::ceil(double val) +{ + return std::ceil(val); +} + +double AMathScriptInterface::cos(double val) +{ + return std::cos(val); +} + +double AMathScriptInterface::exp(double val) +{ + return std::exp(val); +} + +double AMathScriptInterface::floor(double val) +{ + return std::floor(val); +} + +double AMathScriptInterface::log(double val) +{ + return std::log(val); +} + +double AMathScriptInterface::max(double val1, double val2) +{ + return std::max(val1, val2); +} + +double AMathScriptInterface::min(double val1, double val2) +{ + return std::min(val1, val2); +} + +double AMathScriptInterface::pow(double val, double power) +{ + return std::pow(val, power); +} + +double AMathScriptInterface::sin(double val) +{ + return std::sin(val); +} + +double AMathScriptInterface::sqrt(double val) +{ + return std::sqrt(val); +} + +double AMathScriptInterface::tan(double val) +{ + return std::tan(val); +} + +double AMathScriptInterface::round(double val) +{ + int f = std::floor(val); + if (val>0) + { + if (val - f < 0.5) return f; + else return f+1; + } + else + { + if (val - f < 0.5 ) return f; + else return f+1; + } +} + +double AMathScriptInterface::random() +{ + if (!RandGen) return 0; + return RandGen->Rndm(); +} + +double AMathScriptInterface::gauss(double mean, double sigma) +{ + if (!RandGen) return 0; + return RandGen->Gaus(mean, sigma); +} + +double AMathScriptInterface::poisson(double mean) +{ + if (!RandGen) return 0; + return RandGen->Poisson(mean); +} + +double AMathScriptInterface::maxwell(double a) +{ + if (!RandGen) return 0; + + double v2 = 0; + for (int i=0; i<3; i++) + { + double v = RandGen->Gaus(0, a); + v *= v; + v2 += v; + } + return std::sqrt(v2); +} + +double AMathScriptInterface::exponential(double tau) +{ + if (!RandGen) return 0; + return RandGen->Exp(tau); +} diff --git a/src/scriptmode/amathscriptinterface.h b/src/scriptmode/amathscriptinterface.h new file mode 100644 index 00000000..a2fb0e64 --- /dev/null +++ b/src/scriptmode/amathscriptinterface.h @@ -0,0 +1,50 @@ +#ifndef AMATHSCRIPTINTERFACE_H +#define AMATHSCRIPTINTERFACE_H + +#include "ascriptinterface.h" + +#include + +class TRandom2; + +class AMathScriptInterface : public AScriptInterface +{ + Q_OBJECT + Q_PROPERTY(double pi READ pi) + double pi() const { return 3.141592653589793238462643383279502884; } + +public: + AMathScriptInterface(TRandom2* RandGen); + void setRandomGen(TRandom2* RandGen); + + virtual bool IsMultithreadCapable() const override {return true;} + +public slots: + double abs(double val); + double acos(double val); + double asin(double val); + double atan(double val); + double atan2(double y, double x); + double ceil(double val); + double cos(double val); + double exp(double val); + double floor(double val); + double log(double val); + double max(double val1, double val2); + double min(double val1, double val2); + double pow(double val, double power); + double sin(double val); + double sqrt(double val); + double tan(double val); + double round(double val); + double random(); + double gauss(double mean, double sigma); + double poisson(double mean); + double maxwell(double a); // a is sqrt(kT/m) + double exponential(double tau); + +private: + TRandom2* RandGen; +}; + +#endif // AMATHSCRIPTINTERFACE_H diff --git a/src/scriptmode/ascriptinterfacefactory.h b/src/scriptmode/ascriptinterfacefactory.h index b8cd7700..a0b85677 100644 --- a/src/scriptmode/ascriptinterfacefactory.h +++ b/src/scriptmode/ascriptinterfacefactory.h @@ -3,6 +3,7 @@ #include "ascriptinterface.h" #include "coreinterfaces.h" +#include "amathscriptinterface.h" #include "interfacetoglobscript.h" #include "scriptminimizer.h" #include "histgraphinterfaces.h" @@ -21,8 +22,8 @@ class AScriptInterfaceFactory const AInterfaceToCore* core = dynamic_cast(other); if (core) return new AInterfaceToCore(*core); - const AInterfaceToMath* math = dynamic_cast(other); - if (math) return new AInterfaceToMath(*math); + const AMathScriptInterface* math = dynamic_cast(other); + if (math) return new AMathScriptInterface(*math); const AInterfaceToConfig* config = dynamic_cast(other); if (config) return new AInterfaceToConfig(*config); diff --git a/src/scriptmode/coreinterfaces.cpp b/src/scriptmode/coreinterfaces.cpp index a1fde7e2..774e9c6d 100644 --- a/src/scriptmode/coreinterfaces.cpp +++ b/src/scriptmode/coreinterfaces.cpp @@ -6,8 +6,6 @@ #include "curvefit.h" #endif -#include "TRandom2.h" - #include #include #include @@ -21,8 +19,6 @@ #include #include -// ------------------- CORE ---------------------- - AInterfaceToCore::AInterfaceToCore(AScriptManager* ScriptManager) : ScriptManager(ScriptManager) { @@ -601,162 +597,3 @@ bool AInterfaceToCore::setCirrentDir(QString path) { return QDir::setCurrent(path); } -// ------------- End of CORE -------------- - -// ------------- MATH ------------ - -AInterfaceToMath::AInterfaceToMath(TRandom2* RandGen) -{ - Description = "Expanded math module; implemented using std and CERN ROOT functions"; - - //srand (time(NULL)); - this->RandGen = RandGen; - - H["random"] = "Returns a random number between 0 and 1.\nGenerator respects the seed set by SetSeed method of the sim module!"; - H["gauss"] = "Returns a random value sampled from Gaussian distribution with mean and sigma given by the user"; - H["poisson"] = "Returns a random value sampled from Poisson distribution with mean given by the user"; - H["maxwell"] = "Returns a random value sampled from maxwell distribution with Sqrt(kT/M) given by the user"; - H["exponential"] = "Returns a random value sampled from exponential decay with decay time given by the user"; -} - -void AInterfaceToMath::setRandomGen(TRandom2 *RandGen) -{ - this->RandGen = RandGen; -} - -double AInterfaceToMath::abs(double val) -{ - return std::abs(val); -} - -double AInterfaceToMath::acos(double val) -{ - return std::acos(val); -} - -double AInterfaceToMath::asin(double val) -{ - return std::asin(val); -} - -double AInterfaceToMath::atan(double val) -{ - return std::atan(val); -} - -double AInterfaceToMath::atan2(double y, double x) -{ - return std::atan2(y, x); -} - -double AInterfaceToMath::ceil(double val) -{ - return std::ceil(val); -} - -double AInterfaceToMath::cos(double val) -{ - return std::cos(val); -} - -double AInterfaceToMath::exp(double val) -{ - return std::exp(val); -} - -double AInterfaceToMath::floor(double val) -{ - return std::floor(val); -} - -double AInterfaceToMath::log(double val) -{ - return std::log(val); -} - -double AInterfaceToMath::max(double val1, double val2) -{ - return std::max(val1, val2); -} - -double AInterfaceToMath::min(double val1, double val2) -{ - return std::min(val1, val2); -} - -double AInterfaceToMath::pow(double val, double power) -{ - return std::pow(val, power); -} - -double AInterfaceToMath::sin(double val) -{ - return std::sin(val); -} - -double AInterfaceToMath::sqrt(double val) -{ - return std::sqrt(val); -} - -double AInterfaceToMath::tan(double val) -{ - return std::tan(val); -} - -double AInterfaceToMath::round(double val) -{ - int f = std::floor(val); - if (val>0) - { - if (val - f < 0.5) return f; - else return f+1; - } - else - { - if (val - f < 0.5 ) return f; - else return f+1; - } -} - -double AInterfaceToMath::random() -{ - //return rand()/(double)RAND_MAX; - - if (!RandGen) return 0; - return RandGen->Rndm(); -} - -double AInterfaceToMath::gauss(double mean, double sigma) -{ - if (!RandGen) return 0; - return RandGen->Gaus(mean, sigma); -} - -double AInterfaceToMath::poisson(double mean) -{ - if (!RandGen) return 0; - return RandGen->Poisson(mean); -} - -double AInterfaceToMath::maxwell(double a) -{ - if (!RandGen) return 0; - - double v2 = 0; - for (int i=0; i<3; i++) - { - double v = RandGen->Gaus(0, a); - v *= v; - v2 += v; - } - return std::sqrt(v2); -} - -double AInterfaceToMath::exponential(double tau) -{ - if (!RandGen) return 0; - return RandGen->Exp(tau); -} - -// ------------- End of MATH ------------- diff --git a/src/scriptmode/coreinterfaces.h b/src/scriptmode/coreinterfaces.h index 83f9d852..1308807b 100644 --- a/src/scriptmode/coreinterfaces.h +++ b/src/scriptmode/coreinterfaces.h @@ -8,7 +8,6 @@ #include class AScriptManager; -class TRandom2; class CurveFit; class AInterfaceToCore : public AScriptInterface @@ -89,45 +88,4 @@ public slots: }; -// ---- M A T H ---- -class AInterfaceToMath : public AScriptInterface -{ - Q_OBJECT - Q_PROPERTY(double pi READ pi) - double pi() const { return 3.141592653589793238462643383279502884; } - -public: - AInterfaceToMath(TRandom2* RandGen); - void setRandomGen(TRandom2* RandGen); - - virtual bool IsMultithreadCapable() const override {return true;} - -public slots: - double abs(double val); - double acos(double val); - double asin(double val); - double atan(double val); - double atan2(double y, double x); - double ceil(double val); - double cos(double val); - double exp(double val); - double floor(double val); - double log(double val); - double max(double val1, double val2); - double min(double val1, double val2); - double pow(double val, double power); - double sin(double val); - double sqrt(double val); - double tan(double val); - double round(double val); - double random(); - double gauss(double mean, double sigma); - double poisson(double mean); - double maxwell(double a); // a is sqrt(kT/m) - double exponential(double tau); - -private: - TRandom2* RandGen; -}; - #endif // COREINTERFACES_H From 4d97ff57dff43e26800a02731ad27f21fe416c9a Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 2 Oct 2018 13:15:27 +0100 Subject: [PATCH 027/140] ++ --- .../aopticaloverridescriptinterface.cpp | 68 +++++++++++++++++++ .../aopticaloverridescriptinterface.h | 13 +++- 2 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index f5256c8c..ba315f21 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -2,6 +2,9 @@ #include "aphoton.h" #include +#include + +#include "TMath.h" AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() {} @@ -84,6 +87,51 @@ void AOpticalOverrideScriptInterface::Isotropic() bResultAlreadySet = false; } +void AOpticalOverrideScriptInterface::LambertBack() +{ + double norm2; + do + { + Photon->RandomDir(RandGen); + for (int i=0; i<3; i++) Photon->v[i] -= NormalVector[i]; + norm2 = 0; + for (int i=0; i<3; i++) norm2 += Photon->v[i] * Photon->v[i]; + } + while (norm2 < 0.000001); + + double normInverted = 1.0/TMath::Sqrt(norm2); + for (int i=0; i<3; i++) Photon->v[i] *= normInverted; + Status = AOpticalOverride::LambertianReflection; + ReturnResult = AOpticalOverride::Back; + bResultAlreadySet = true; +} + +void AOpticalOverrideScriptInterface::LambertForward() +{ + double norm2; + do + { + Photon->RandomDir(RandGen); + for (int i=0; i<3; i++) Photon->v[i] += NormalVector[i]; + norm2 = 0; + for (int i=0; i<3; i++) norm2 += Photon->v[i] * Photon->v[i]; + } + while (norm2 < 0.000001); + + double normInverted = 1.0/TMath::Sqrt(norm2); + for (int i=0; i<3; i++) Photon->v[i] *= normInverted; + Status = AOpticalOverride::Transmission; + ReturnResult = AOpticalOverride::Forward; + bResultAlreadySet = true; +} + +QVariant AOpticalOverrideScriptInterface::GetDirection() +{ + QVariantList vl; + vl << Photon->v[0] << Photon->v[1] << Photon->v[2]; + return vl; +} + void AOpticalOverrideScriptInterface::SetDirection(double vx, double vy, double vz) { Photon->v[0] = vx; @@ -91,3 +139,23 @@ void AOpticalOverrideScriptInterface::SetDirection(double vx, double vy, double Photon->v[2] = vz; bResultAlreadySet = false; } + +void AOpticalOverrideScriptInterface::SetTime(double time) +{ + Photon->time = time; +} + +void AOpticalOverrideScriptInterface::AddTime(double dt) +{ + Photon->time += dt; +} + +void AOpticalOverrideScriptInterface::Report(const QString text) +{ + qDebug() << text; +} + +double AOpticalOverrideScriptInterface::GetTime() +{ + return Photon->time; +} diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 58d01e00..600dffcb 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -4,6 +4,8 @@ #include "ascriptinterface.h" #include "aopticaloverride.h" +#include + class APhoton; class AOpticalOverrideScriptInterface : public AScriptInterface @@ -22,11 +24,18 @@ public slots: void TransmissionDirect(); //ToDo: meddling test! void SpecularReflection(); //ToDo: meddling test! void Isotropic(); //ToDo: meddling test! - //void LambertBack(); //ToDo: meddling test! - //void LambertForward(); //ToDo: meddling test! + void LambertBack(); //ToDo: meddling test! + void LambertForward(); //ToDo: meddling test! + QVariant GetDirection(); void SetDirection(double vx, double vy, double vz); + double GetTime(); + void SetTime(double time); + void AddTime(double dt); + + void Report(const QString text); + private: TRandom2 * RandGen; APhoton * Photon; From 9cc08d5ff523fd98ecb54a94d550f3dfa319f8f5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 11:48:21 +0100 Subject: [PATCH 028/140] remove old GUI for opt override --- .../ascriptopticaloverride.cpp | 12 +- src/OpticalOverrides/ascriptopticaloverride.h | 6 +- src/ants2.pro | 20 +- src/common/aopticaloverride.cpp | 107 +- src/common/aopticaloverride.h | 48 +- src/gui/MainWindowTools/MainWindowInits.cpp | 7 +- src/gui/MainWindowTools/MainWindowMenu.cpp | 2 +- .../MainWindowParticleSimulation.cpp | 2 +- src/gui/MainWindowTools/MainWindowTests.cpp | 5 - .../Reconstruction_Init.cpp | 4 +- src/gui/gainevaluatorwindowclass.cpp | 4 +- src/gui/guiutils.cpp | 40 +- src/gui/guiutils.h | 12 +- src/gui/mainwindow.cpp | 527 +------- src/gui/mainwindow.h | 43 +- src/gui/mainwindow.ui | 1182 ++--------------- src/gui/materialinspectorwindow.cpp | 2 +- src/modules/phscatclaudiomodel.cpp | 36 +- src/modules/phscatclaudiomodel.h | 23 +- src/modules/scatteronmetal.cpp | 20 +- src/modules/scatteronmetal.h | 12 +- 21 files changed, 269 insertions(+), 1845 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index af05ecbd..84ad816b 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -37,17 +37,9 @@ AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(AT return Resources.overrideInterface->getResult(Status); } -void AScriptOpticalOverride::printConfiguration(int) +const QString AScriptOpticalOverride::getReportLine() const { - qDebug() << "-------Configuration:-------"; - qDebug() << "Script:"; - qDebug() << Script; - qDebug() << "----------------------------"; -} - -QString AScriptOpticalOverride::getReportLine() -{ - return QString("to %1 -> Custom script").arg( (*MatCollection)[MatTo]->name ); + return QString(); } void AScriptOpticalOverride::writeToJson(QJsonObject &json) diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index 257fc718..2f7e3f1c 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -15,9 +15,9 @@ class AScriptOpticalOverride : public AOpticalOverride virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual void printConfiguration(int iWave) override; - virtual QString getType() const override {return "CustomScript";} - virtual QString getReportLine() override; + virtual const QString getType() const override {return "CustomScript";} + virtual const QString getAbbreviation() const override {return "JS";} + virtual const QString getReportLine() const override; virtual void writeToJson(QJsonObject &json) override; virtual bool readFromJson(QJsonObject &json) override; diff --git a/src/ants2.pro b/src/ants2.pro index cfd88782..983354a6 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -348,11 +348,9 @@ SOURCES += main.cpp \ Net/agridrunner.cpp \ Net/aremoteserverrecord.cpp \ common/atrackbuildoptions.cpp \ - gui/MainWindowTools/aopticaloverridedialog.cpp \ OpticalOverrides/aopticaloverridescriptinterface.cpp \ OpticalOverrides/ascriptopticaloverride.cpp \ common/atracerstateful.cpp \ - gui/MainWindowTools/aopticaloverridetester.cpp \ common/aphoton.cpp \ scriptmode/amathscriptinterface.cpp @@ -479,11 +477,9 @@ HEADERS += common/CorrelationFilters.h \ Net/agridrunner.h \ Net/aremoteserverrecord.h \ common/atrackbuildoptions.h \ - gui/MainWindowTools/aopticaloverridedialog.h \ OpticalOverrides/aopticaloverridescriptinterface.h \ OpticalOverrides/ascriptopticaloverride.h \ common/atracerstateful.h \ - gui/MainWindowTools/aopticaloverridetester.h \ scriptmode/amathscriptinterface.h # --- SIM --- @@ -599,8 +595,9 @@ ants2_GUI { gui/MainWindowTools/slabdelegate.cpp \ gui/aremotewindow.cpp \ gui/MainWindowTools/atrackdrawdialog.cpp \ - gui/aserverdelegate.cpp - + gui/aserverdelegate.cpp \ + gui/MainWindowTools/aopticaloverridedialog.cpp \ + gui/MainWindowTools/aopticaloverridetester.cpp HEADERS += gui/mainwindow.h \ gui/materialinspectorwindow.h \ @@ -657,7 +654,9 @@ HEADERS += gui/mainwindow.h \ gui/awebsocketserverdialog.h \ gui/aremotewindow.h \ gui/MainWindowTools/atrackdrawdialog.h \ - gui/aserverdelegate.h + gui/aserverdelegate.h \ + gui/MainWindowTools/aopticaloverridedialog.h \ + gui/MainWindowTools/aopticaloverridetester.h FORMS += gui/mainwindow.ui \ gui/materialinspectorwindow.ui \ @@ -687,7 +686,9 @@ FORMS += gui/mainwindow.ui \ gui/aneutroninfodialog.ui \ gui/awebsocketserverdialog.ui \ gui/aremotewindow.ui \ - gui/MainWindowTools/atrackdrawdialog.ui + gui/MainWindowTools/atrackdrawdialog.ui \ + gui/MainWindowTools/aopticaloverridedialog.ui \ + gui/MainWindowTools/aopticaloverridetester.ui INCLUDEPATH += gui INCLUDEPATH += gui/RasterWindow @@ -805,6 +806,3 @@ unix { } #------------ -FORMS += \ - gui/MainWindowTools/aopticaloverridedialog.ui \ - gui/MainWindowTools/aopticaloverridetester.ui diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 7befb1cd..009a1183 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -166,61 +166,32 @@ AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(ATra return NotTriggered; } -void BasicOpticalOverride::printConfiguration(int /*iWave*/) +const QString BasicOpticalOverride::getReportLine() const { - qDebug() << "-------Configuration:-------"; - qDebug() << "Absorption fraction:"<name; - QString s1; - s += "->"; - - double prob = probRef+probDiff+probLoss; - if (prob == 0) return s + " To be defined"; //not defined - shown during configuration phase only - double probFresnel = 1.0 - prob; - - if (probLoss>0) - { - s1.setNum(probLoss); - s += " Loss: "+s1+";"; - } - if (probRef>0) - { - s1.setNum(probRef); - s += " Spec: "+s1+";"; - } - if (probDiff>0) - { - s1.setNum(probDiff); - switch( scatterModel ) + double probFresnel = 1.0 - (probRef + probDiff + probLoss); + QString s; + if (probLoss > 0) s += QString("Abs %1 +").arg(probLoss); + if (probRef > 0) s += QString("Spec %1 +").arg(probRef); + if (probDiff > 0) + { + switch( scatterModel ) { case 0: - s += " Scat(4Pi): "; - break; + s += "Iso "; + break; case 1: - s += " Scat(Lamb_B): "; - break; + s += "Lamb_B "; + break; case 2: - s += " Scat(Lamb_F): "; - break; + s += "Lamb_F "; + break; } - s += s1; - } - - if (probFresnel>1e-10) - { - s1.setNum(probFresnel); - s += " Fresnel: "+s1; - } - - return s; + s += QString::number(probDiff); + s += " +"; + } + if (probFresnel > 1e-10) s += QString("Fres %1 +").arg(probFresnel); + s.chop(2); + return s; } void BasicOpticalOverride::writeToJson(QJsonObject &json) @@ -464,15 +435,7 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATrac // return Back; } -void FSNPOpticalOverride::printConfiguration(int /*iWave*/) -{ - qDebug() << "-------Configuration:-------"; - qDebug() << "FS_NP model"; - qDebug() << "Albedo:"<name; s += "->FS_NP model, albedo="+QString::number(Albedo); @@ -663,20 +626,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra return Absorbed; } -void AWaveshifterOverride::printConfiguration(int /*iWave*/) -{ - qDebug() << "-------Configuration:-------"; - qDebug() << "Surface wavelengthshifter override"; - QString str = "Reemission probabililty: "; - str += (ReemissionProbability_lambda.isEmpty() ? "not defined" : "defined"); - qDebug() << str; - str = "Emission spectrum: "; - str += (EmissionSpectrum_lambda.isEmpty() ? "not defined" : "defined"); - qDebug() << str; - qDebug() << "----------------------------"; -} - -QString AWaveshifterOverride::getReportLine() +const QString AWaveshifterOverride::getReportLine() const { QString s = "to " + (*MatCollection)[MatTo]->name; s += "->SurfaceWLS"; @@ -940,18 +890,7 @@ AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calcul return BasicOpticalOverride::calculate(Resources, Photon, NormalVector); } -void SpectralBasicOpticalOverride::printConfiguration(int /*iWave*/) -{ - qDebug() << "-------Configuration:-------"; - qDebug() << "Wavelength:"<name; s += "->"; diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 3698bfe9..dc5960bf 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -29,16 +29,16 @@ class AOpticalOverride //detailed status for statistics only - used by override tester only enum ScatterStatusEnum {SpikeReflection, LobeReflection, LambertianReflection, Absorption, Transmission, Error, UnclassifiedReflection, Empty, Fresnel}; - AOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : MatCollection(MatCollection), MatFrom(MatFrom), MatTo(MatTo) {} virtual ~AOpticalOverride() {} virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) = 0; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual void printConfiguration(int iWave) = 0; - virtual QString getType() const = 0; - virtual QString getReportLine() = 0; // for GUI: reports override status "to material blabla (#id): properies" + virtual const QString getType() const = 0; + virtual const QString getAbbreviation() const = 0; //for GUI: used to identify - must be short (<= 4 chars) - try to make unique + virtual const QString getReportLine() const = 0; // for GUI: used to reports override status (try to make as short as possible) + //TODO: initializeWaveResolved() -> no need to transfer data, MatCollection knows the settings virtual void initializeWaveResolved(bool /*bWaveResolved*/, double /*waveFrom*/, double /*waveStep*/, int /*waveNodes*/) {} //override if override has wavelength-resolved data @@ -52,7 +52,9 @@ class AOpticalOverride #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow); #endif - virtual const QString checkOverrideData() {return "";} //TODO after all are done, make = 0 + + //TODO after all are done, make = 0 + virtual const QString checkOverrideData() {return "";} //cannot be const - w.resolved needs rebin // read-out variables for standalone checker only (not multithreaded) ScatterStatusEnum Status; // type of interaction which happened - use in 1 thread only! @@ -69,15 +71,15 @@ class BasicOpticalOverride : public AOpticalOverride BasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); virtual ~BasicOpticalOverride() {} - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual void printConfiguration(int iWave); - virtual QString getType() const {return "Simplistic_model";} - virtual QString getReportLine(); + virtual const QString getType() const override {return "Simplistic_model";} + virtual const QString getAbbreviation() const override {return "Simp";} + virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json); - virtual bool readFromJson(QJsonObject &json); + virtual void writeToJson(QJsonObject &json) override; + virtual bool readFromJson(QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; @@ -100,15 +102,15 @@ class FSNPOpticalOverride : public AOpticalOverride : AOpticalOverride(MatCollection, MatFrom, MatTo) {Albedo = 0.95;} virtual ~FSNPOpticalOverride() {} - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual void printConfiguration(int iWave); - virtual QString getType() const {return "FS_NP";} - virtual QString getReportLine(); + virtual const QString getType() const override {return "FS_NP";} + virtual const QString getAbbreviation() const override {return "FSNP";} + virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json); - virtual bool readFromJson(QJsonObject &json); + virtual void writeToJson(QJsonObject &json) override; + virtual bool readFromJson(QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; @@ -128,9 +130,9 @@ class AWaveshifterOverride : public AOpticalOverride void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved - virtual void printConfiguration(int iWave); - virtual QString getType() const {return "SurfaceWLS";} - virtual QString getReportLine(); + virtual const QString getType() const override {return "SurfaceWLS";} + virtual const QString getAbbreviation() const override {return "WLS";} + virtual const QString getReportLine() const override; // save/load config is not used for this type! virtual void writeToJson(QJsonObject &json); @@ -176,9 +178,9 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual void printConfiguration(int iWave) override; - virtual QString getType() const override {return "SimplisticSpectral_model";} - virtual QString getReportLine() override; + virtual const QString getType() const override {return "SimplisticSpectral_model";} + virtual const QString getAbbreviation() const override {return "SiSp";} + virtual const QString getReportLine() const override; // save/load config is not used for this type! virtual void writeToJson(QJsonObject &json) override; diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 174b0700..14b6f45f 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -239,7 +239,7 @@ MainWindow::MainWindow(DetectorClass *Detector, ui->twSourcePhotonsParticles->setCurrentIndex(0); MainWindow::PointSource_InitTabWidget(); QList invis; - invis << ui->pbRefreshParticles << ui->pbOverride << ui->pbRefreshOverrides << ui->pbUpdatePreprocessingSettings + invis << ui->pbRefreshParticles << ui->pbRefreshOverrides << ui->pbUpdatePreprocessingSettings << ui->pbRefreshStack << ui->pbShowPMsArrayRegularData << ui->pbRefreshPMArrayData << ui->pbUpdateElectronics << ui->pbRefreshPMproperties << ui->pbUpdatePMproperties << ui->pbRefreshMaterials << ui->pbStopLoad << ui->pbGunRefreshparticles << ui->pbIndPMshowInfo << ui->pbUpdateToFixedZ << ui->pbUpdateSimConfig @@ -284,7 +284,7 @@ MainWindow::MainWindow(DetectorClass *Detector, { WindowNavigator->show(); fShowGeom = true; - AssureWidgetIsWithingVisibleArea(this); + GuiUtils::AssureWidgetIsWithinVisibleArea(this); } ui->actionSave_Load_windows_status_on_Exit_Init->setChecked(GlobSet->SaveLoadWindows); @@ -306,9 +306,6 @@ MainWindow::MainWindow(DetectorClass *Detector, GeometryWindow->ShowGeometry(false); if (!fShowGeom) GeometryWindow->hide(); - ui->cobScatteringModel->setCurrentIndex(1); //default to Lambertian back - ui->cobSSO_ScatterModel->setCurrentIndex(1); //default to Lambertian back - //MainWindow::on_pbRefreshOverrides_clicked(); //already in load detector MainWindow::updateCOBsWithPMtypeNames(); if (!fLoadedDefaultDetector) diff --git a/src/gui/MainWindowTools/MainWindowMenu.cpp b/src/gui/MainWindowTools/MainWindowMenu.cpp index 8bfeb358..77bbe50f 100644 --- a/src/gui/MainWindowTools/MainWindowMenu.cpp +++ b/src/gui/MainWindowTools/MainWindowMenu.cpp @@ -208,7 +208,7 @@ void readXYwindow(QString key, QMainWindow* w, bool fWH, QJsonObject &json) if (js.contains("maximized")) fMaxi = js["maximized"].toBool(); bool fVis = js["vis"].toBool(); - AssureWidgetIsWithingVisibleArea(w); + GuiUtils::AssureWidgetIsWithinVisibleArea(w); if (fVis || fMaxi) w->showNormal(); if (fMaxi) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index a7e2e115..f9e7f912 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -832,7 +832,7 @@ void MainWindow::updateActivityIndication() { double activity = ui->ledSourceActivity->text().toDouble(); QSize size(ui->lSourceActive->height(), ui->lSourceActive->height()); - QIcon wIcon = createColorCircleIcon(size, Qt::yellow); + QIcon wIcon = GuiUtils::createColorCircleIcon(size, Qt::yellow); if (activity == 0) ui->lSourceActive->setPixmap(wIcon.pixmap(16,16)); else ui->lSourceActive->setPixmap(QIcon().pixmap(16,16)); diff --git a/src/gui/MainWindowTools/MainWindowTests.cpp b/src/gui/MainWindowTools/MainWindowTests.cpp index 42243f5b..e6d4a6a3 100644 --- a/src/gui/MainWindowTools/MainWindowTests.cpp +++ b/src/gui/MainWindowTools/MainWindowTests.cpp @@ -337,9 +337,6 @@ void MainWindow::on_pbCSMtestmany_clicked() PhotDir = PhotDir.Unit(); //double K[3]; - //report configuration - ov->printConfiguration(-1); - //other inits tracks.clear(); double d = 0.5; //offset - for drawing only @@ -454,8 +451,6 @@ void MainWindow::on_pbST_uniform_clicked() //PhotDir = PhotDir.Unit(); double K[3]; - ov->printConfiguration(-1); - int abs, spike, lobe, lamb; abs = spike = lobe = lamb = 0; TH1D* hist1; diff --git a/src/gui/ReconstructionWindowTools/Reconstruction_Init.cpp b/src/gui/ReconstructionWindowTools/Reconstruction_Init.cpp index d92c111e..7595cace 100644 --- a/src/gui/ReconstructionWindowTools/Reconstruction_Init.cpp +++ b/src/gui/ReconstructionWindowTools/Reconstruction_Init.cpp @@ -83,10 +83,10 @@ ReconstructionWindow::ReconstructionWindow(QWidget *parent, MainWindow *mw, Even funcParams[2] = 1.0; funcParams[3] = 1.0; - RedIcon = createColorCircleIcon(ui->twOptions->iconSize(), Qt::red); + RedIcon = GuiUtils::createColorCircleIcon(ui->twOptions->iconSize(), Qt::red); ui->labDataIsMissing->setPixmap(RedIcon.pixmap(16,16)); ui->fNoData->setVisible(true); - YellowIcon = createColorCircleIcon(ui->twData->iconSize(), Qt::yellow); + YellowIcon = GuiUtils::createColorCircleIcon(ui->twData->iconSize(), Qt::yellow); ui->labUnassignedIcon->setPixmap(YellowIcon.pixmap(16,16)); ui->fNotAssignedPMs->setVisible(false); diff --git a/src/gui/gainevaluatorwindowclass.cpp b/src/gui/gainevaluatorwindowclass.cpp index dac59bc1..13e9885e 100644 --- a/src/gui/gainevaluatorwindowclass.cpp +++ b/src/gui/gainevaluatorwindowclass.cpp @@ -100,8 +100,8 @@ GainEvaluatorWindowClass::GainEvaluatorWindowClass(QWidget *parent, MainWindow * ui->tabwid4sets->resizeColumnsToContents(); //icons - RedIcon = createColorCircleIcon(ui->twAlgorithms->iconSize(), Qt::red); - GreenIcon = createColorCircleIcon(ui->twAlgorithms->iconSize(), Qt::green); + RedIcon = GuiUtils::createColorCircleIcon(ui->twAlgorithms->iconSize(), Qt::red); + GreenIcon = GuiUtils::createColorCircleIcon(ui->twAlgorithms->iconSize(), Qt::green); ui->labIconWarningCutOffs->setPixmap(RedIcon.pixmap(16,16)); //Graphics view diff --git a/src/gui/guiutils.cpp b/src/gui/guiutils.cpp index 679f267e..638101b9 100644 --- a/src/gui/guiutils.cpp +++ b/src/gui/guiutils.cpp @@ -8,14 +8,30 @@ #include #include -void SetWindowFont(QMainWindow *w, int ptsize) +void GuiUtils::SetWindowFont(QMainWindow *w, int ptsize) { QFont font = w->font(); font.setPointSize(ptsize); w->setFont(font); } -QIcon createColorCircleIcon(QSize size, Qt::GlobalColor color) +void GuiUtils::AssureWidgetIsWithinVisibleArea(QWidget *w) +{ + QList listScr = qApp->screens(); + bool bVis = false; + for (QScreen* scr : listScr) + { + QRect ts = scr->geometry(); + if (ts.contains(w->x(), w->y())) + { + bVis = true; + break; + } + } + if (!bVis) w->move(50,50); +} + +QIcon GuiUtils::createColorCircleIcon(QSize size, Qt::GlobalColor color) { QPixmap pm(size.width()-2, size.height()-2); pm.fill(Qt::transparent); @@ -26,9 +42,7 @@ QIcon createColorCircleIcon(QSize size, Qt::GlobalColor color) return QIcon(pm); } -TableDoubleDelegateClass::TableDoubleDelegateClass(QObject *parent) : QItemDelegate(parent) -{ -} +TableDoubleDelegateClass::TableDoubleDelegateClass(QObject *parent) : QItemDelegate(parent) {} QWidget *TableDoubleDelegateClass::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const { @@ -90,19 +104,3 @@ void myQGraphicsView::mouseReleaseEvent(QMouseEvent *event) if (CursorMode == 1) viewport()->setCursor(Qt::CrossCursor); } - -void AssureWidgetIsWithingVisibleArea(QWidget *w) -{ - QList listScr = qApp->screens(); - bool bVis = false; - for (QScreen* scr : listScr) - { - QRect ts = scr->geometry(); - if (ts.contains(w->x(), w->y())) - { - bVis = true; - break; - } - } - if (!bVis) w->move(50,50); -} diff --git a/src/gui/guiutils.h b/src/gui/guiutils.h index d3336b6e..6e151225 100644 --- a/src/gui/guiutils.h +++ b/src/gui/guiutils.h @@ -8,6 +8,13 @@ class QMainWindow; class QWheelEvent; class QGraphicsScene; +namespace GuiUtils +{ + void SetWindowFont(QMainWindow *w, int ptsize); + QIcon createColorCircleIcon(QSize size, Qt::GlobalColor color); + void AssureWidgetIsWithinVisibleArea(QWidget* w); +} + class myQGraphicsView : public QGraphicsView { Q_OBJECT @@ -39,9 +46,4 @@ class TableDoubleDelegateClass : public QItemDelegate const QModelIndex &/* index */) const; }; -void SetWindowFont(QMainWindow *w, int ptsize); -QIcon createColorCircleIcon(QSize size, Qt::GlobalColor color); - -void AssureWidgetIsWithingVisibleArea(QWidget* w); - #endif // GUIUTILS_H diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 47151332..06ccf013 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -552,14 +552,13 @@ void MainWindow::UpdateMaterialListEdit() //if there are overrides, add (*) bool fFound = false; for (int p=0; pLossOverride[p]>0 || (*MaterialCollection)[i]->ReflectionOverride[p]>0 || (*MaterialCollection)[i]->ScatterOverride[p]>0) if ( (*MpCollection)[i]->OpticalOverrides[p] ) { fFound = true; break; } - if (fFound) tmpStr += " (override)"; + if (fFound) tmpStr += " (ov)"; QListWidgetItem* pItem =new QListWidgetItem(tmpStr); if (GeometryWindow->isColorByMaterial()) @@ -721,146 +720,6 @@ void MainWindow::on_cbRingsArray_stateChanged(int arg1) ui->sbPMrings->setEnabled(arg1); } -void MainWindow::on_pbOverride_clicked() -{ - //qDebug() << "->Registering new override parameters"; - int From = ui->cobMaterialForOverrides->currentIndex(); - int To = ui->cobMaterialTo->currentIndex(); - - AOpticalOverride* ov = (*MpCollection)[From]->OpticalOverrides[To]; - - if (ov) //potential loss of data - { - AWaveshifterOverride* swo = dynamic_cast(ov); - if (swo) - if (!swo->ReemissionProbability_lambda.isEmpty() || !swo->EmissionSpectrum_lambda.isEmpty()) - { - QMessageBox msgBox; - msgBox.setText("Warning: configured emission probability and spectrum will be lost!"); - msgBox.setInformativeText("Continue?"); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); - if (ret == QMessageBox::Cancel) - { - on_pbRefreshOverrides_clicked(); - return; - } - } - - SpectralBasicOpticalOverride* sso = dynamic_cast(ov); - if (sso) - if (sso->Wave.size() > 1) - { - QMessageBox msgBox; - msgBox.setText("Warning: configured spectral data will be lost!"); - msgBox.setInformativeText("Continue?"); - msgBox.setIcon(QMessageBox::Warning); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); - if (ret == QMessageBox::Cancel) - { - on_pbRefreshOverrides_clicked(); - return; - } - } - - delete ov; - ov = 0; - } - - int Model = ui->cobOpticalOverrideModel->currentIndex(); - switch (Model) - { - case 0: //Override not defined - break; - case 1: //Simplistic model - { - double abs = ui->ledSimplisticAbs->text().toDouble(); - double spec = ui->ledSimplisticSpecular->text().toDouble(); - double scat = ui->ledSimplisticScatter->text().toDouble(); - int scatModel = ui->cobScatteringModel->currentIndex(); - ov = new BasicOpticalOverride(Detector->MpCollection, From, To, abs, spec, scat, scatModel); - break; - } - case 2: //Claudio's model - using version 2.2 - { - PhScatClaudioModelV2d2* cs = new PhScatClaudioModelV2d2(Detector->MpCollection, From, To); - cs->sigma_alpha = ui->ledSigmaAlpha->text().toDouble(); - cs->sigma_h = ui->ledSigmaSpike->text().toDouble(); - cs->albedo = ui->ledAlbedo->text().toDouble(); - switch(ui->conHeightModel->currentIndex()) - { - case 0: cs->HeightDistribution = empirical; break; - case 1: cs->HeightDistribution = gaussian; break; - case 2: cs->HeightDistribution = exponential; break; - default:; - } - switch(ui->cobSlopeModel->currentIndex()) - { - case 0: cs->SlopeDistribution = trowbridgereitz; break; - case 1: cs->SlopeDistribution = cooktorrance; break; - case 2: cs->SlopeDistribution = bivariatecauchy; break; - default:; - } - ov = cs; - break; - } - case 3: //Dielectric/Metal model - { - ScatterOnMetal* sm = new ScatterOnMetal(Detector->MpCollection, From, To); - sm->RealN = ui->ledRealN->text().toDouble(); - sm->ImaginaryN = ui->ledImaginaryN->text().toDouble(); - ov = sm; - break; - } - case 4: // FS_NP model - { - double albedo = ui->ledNevesAlbedo->text().toDouble(); - ov = new FSNPOpticalOverride(Detector->MpCollection, From, To, albedo); - break; - } - case 5: // Surface WLS - { - ui->cobSurfaceWLS_Model->setCurrentIndex(1); - ov = new AWaveshifterOverride(Detector->MpCollection, From, To, 1); - ui->pbSurfaceWLS_Show->setEnabled(false); - ui->pbSurfaceWLS_ShowSpec->setEnabled(false); - break; - } - case 6: // Simplistic spectral - { - ov = new SpectralBasicOpticalOverride(Detector->MpCollection, From, To, ui->cobSSO_ScatterModel->currentIndex(), ui->ledSSO_EffWave->text().toDouble()); - ui->pbSSO_Show->setEnabled(false); - ui->pbSSO_Binned->setEnabled(false); - break; - } - default: - { - qDebug() << "Not existent override model!"; - break; - } - } - -// if (ov) -// { -// qDebug() << "Override type selected:" <getType(); -// ov->printConfiguration(-1); -// } -// else qDebug() << "No override selected"; - - (*MpCollection)[From]->OpticalOverrides[To] = ov; - - ReconstructDetector(true); - - MainWindow::on_pbRefreshOverrides_clicked(); - int i = ui->lwMaterials->currentRow(); - MainWindow::UpdateMaterialListEdit(); //to update (*) status - ui->lwMaterials->setCurrentRow(i); -} - #include "aopticaloverridedialog.h" void MainWindow::on_pbEditOverride_clicked() { @@ -882,91 +741,28 @@ void MainWindow::on_pbEditOverride_clicked() void MainWindow::on_pbRefreshOverrides_clicked() { - //qDebug() << "->Updating overrides indication"; ui->lwOverrides->clear(); - int size = MpCollection->countMaterials(); + int numMat = MpCollection->countMaterials(); + int iMatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); + for (int iMatTo = 0; iMatTo < numMat; iMatTo++) + { + const AOpticalOverride* ov = (*MpCollection)[iMatFrom]->OpticalOverrides.at(iMatTo); + if (!ov) continue; - //updating text field - QString s; - bool flagEmpty = true; - for (int i=0; iOpticalOverrides.at(i) ) continue; - s = (*MpCollection)[MatFrom]->OpticalOverrides.at(i)->getReportLine(); - //qDebug() << s; + QString s = QString("->%1 = ").arg( (*MpCollection)[iMatTo]->name ); + s += ov->getAbbreviation(); + s += ": "; + s += ov->getReportLine(); ui->lwOverrides->addItem(s); - } - if (flagEmpty) ui->lwOverrides->addItem("Not defined"); - - //updating parameters area - if ( !(*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo) ) - ui->cobOpticalOverrideModel->setCurrentIndex(0); - else - { - QString model = (*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo)->getType(); - if (model == "Simplistic_model") - { - ui->cobOpticalOverrideModel->setCurrentIndex(1); - BasicOpticalOverride* ov = dynamic_cast( (*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo) ); - ui->ledSimplisticAbs->setText(QString::number(ov->probLoss)); - ui->ledSimplisticSpecular->setText(QString::number(ov->probRef)); - ui->ledSimplisticScatter->setText(QString::number(ov->probDiff)); - ui->cobScatteringModel->setCurrentIndex(ov->scatterModel); - } - else if (model.startsWith("Claudio_Model")) - { - ui->cobOpticalOverrideModel->setCurrentIndex(2); - PhScatClaudioModel* ov = dynamic_cast( (*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo) ); - ui->ledSigmaAlpha->setText(QString::number(ov->sigma_alpha)); - ui->ledSigmaSpike->setText(QString::number(ov->sigma_h)); - ui->ledAlbedo->setText(QString::number(ov->albedo)); - ui->conHeightModel->setCurrentIndex( (int)ov->HeightDistribution ); - ui->cobSlopeModel->setCurrentIndex( (int)ov->SlopeDistribution ); - } - else if (model == "DielectricToMetal") - { - ui->cobOpticalOverrideModel->setCurrentIndex(3); - ScatterOnMetal* ov = dynamic_cast( (*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo) ); - ui->ledRealN->setText(QString::number(ov->RealN)); - ui->ledImaginaryN->setText(QString::number(ov->ImaginaryN)); - } - else if (model=="FS_NP" || model=="Neves_model") - { - ui->cobOpticalOverrideModel->setCurrentIndex(4); - FSNPOpticalOverride* ov = dynamic_cast( (*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo) ); - ui->ledNevesAlbedo->setText(QString::number(ov->Albedo)); - } - else if (model == "SurfaceWLS") - { - ui->cobOpticalOverrideModel->setCurrentIndex(5); - AWaveshifterOverride* ov = dynamic_cast( (*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo) ); - ui->pbSurfaceWLS_Show->setEnabled(!ov->ReemissionProbability_lambda.isEmpty()); - ui->pbSurfaceWLS_ShowSpec->setEnabled(!ov->EmissionSpectrum_lambda.isEmpty()); - ui->cobSurfaceWLS_Model->setCurrentIndex(ov->ReemissionModel); - } - else if (model == "SimplisticSpectral_model") - { - ui->cobOpticalOverrideModel->setCurrentIndex(6); - SpectralBasicOpticalOverride* ov = dynamic_cast( (*MpCollection)[MatFrom]->OpticalOverrides.at(MatTo) ); - ui->pbSSO_Show->setEnabled(!ov->Wave.isEmpty()); - ui->pbSSO_Binned->setEnabled(!ov->Wave.isEmpty()); - ui->cobSSO_ScatterModel->setCurrentIndex(ov->scatterModel); - ui->ledSSO_EffWave->setText( QString::number(ov->effectiveWavelength) ); - } - else - { - //message("Unknown override model: "+model, this); - ui->cobOpticalOverrideModel->setCurrentIndex(0); - } - } + } } void MainWindow::on_pbStartMaterialInspector_clicked() { + int imat = ui->lwMaterials->currentRow(); + if (imat != -1) MIwindow->SetMaterial(imat); + MIwindow->showNormal(); MIwindow->raise(); MIwindow->activateWindow(); @@ -4395,48 +4191,6 @@ void MainWindow::on_pbUpdateElectronics_clicked() ReconstructDetector(true); //GUI update is triggered automatically } -void MainWindow::on_ledSimplisticAbs_editingFinished() -{ - double pLoss = ui->ledSimplisticAbs->text().toDouble(); - double pRef = ui->ledSimplisticSpecular->text().toDouble(); - double pDiff = ui->ledSimplisticScatter->text().toDouble(); - - if (pLoss+pRef+pDiff > 1.0) - { - ui->ledSimplisticAbs->setText(QString::number(1.0 - pRef - pDiff)); - message("Sum cannot exceed 1.0", this); - } - MainWindow::on_pbOverride_clicked(); -} - -void MainWindow::on_ledSimplisticSpecular_editingFinished() -{ - double pLoss = ui->ledSimplisticAbs->text().toDouble(); - double pRef = ui->ledSimplisticSpecular->text().toDouble(); - double pDiff = ui->ledSimplisticScatter->text().toDouble(); - - if (pLoss+pRef+pDiff > 1.0) - { - ui->ledSimplisticSpecular->setText(QString::number(1.0 - pLoss - pDiff)); - message("Sum cannot exceed 1.0", this); - } - MainWindow::on_pbOverride_clicked(); -} - -void MainWindow::on_ledSimplisticScatter_editingFinished() -{ - double pLoss = ui->ledSimplisticAbs->text().toDouble(); - double pRef = ui->ledSimplisticSpecular->text().toDouble(); - double pDiff = ui->ledSimplisticScatter->text().toDouble(); - - if (pLoss+pRef+pDiff > 1.0) - { - ui->ledSimplisticScatter->setText(QString::number(1.0 - pLoss - pRef)); - message("Sum cannot exceed 1.0", this); - } - MainWindow::on_pbOverride_clicked(); -} - void MainWindow::on_pbOverlay_clicked() { if (EventsDataHub->isEmpty()) @@ -4638,124 +4392,11 @@ void MainWindow::on_pbManuscriptExtractNames_clicked() MainWindow::on_pbReloadExpData_clicked(); } -void MainWindow::on_lwOverrides_itemClicked(QListWidgetItem* /*item*/) -{ - int row = ui->lwOverrides->currentRow(); - //if (ui->lwOverrides->currentItem()->text() == "Not defined") return; - - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int Mats = Detector->MpCollection->countMaterials(); - int counter = 0; - for (int iMat=0; iMatMpCollection)[MatFrom]->OpticalOverrides[iMat]; - if (!ov) continue; - if (counter == row) - { - ui->cobMaterialTo->setCurrentIndex(iMat); - MainWindow::on_pbRefreshOverrides_clicked(); - return; - } - counter++; - } -} - void MainWindow::setFloodZposition(double Z) { ui->ledScanFloodZ->setText(QString::number(Z)); } -void MainWindow::on_pbSurfaceWLS_Show_clicked() -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - AWaveshifterOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - auto gr = GraphWindow->MakeGraph(&ov->ReemissionProbability_lambda, &ov->ReemissionProbability, 4, "Wavelength, nm", "Probability [0,1]", 20, 1, 0, 0, "", true); - gr->SetTitle("Reemission probability in 2Pi"); - gr->SetMinimum(0); - - GraphWindow->Draw(gr, "apl"); -} - -void MainWindow::on_cobSurfaceWLS_Model_activated(int index) -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - AWaveshifterOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - ov->ReemissionModel = index; - ReconstructDetector(); - //MainWindow::on_pbRefreshOverrides_clicked(); -} - -void MainWindow::on_pbSurfaceWLS_Load_clicked() -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - AWaveshifterOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load reemission probability", GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); - if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); - QVector X, Y; - int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); - if (ret == 0) - { - ov->ReemissionProbability_lambda = X; - ov->ReemissionProbability = Y; - ui->pbSurfaceWLS_Show->setEnabled(true); - } - ReconstructDetector(); - MainWindow::on_pbRefreshOverrides_clicked(); -} - -void MainWindow::on_pbSurfaceWLS_ShowSpec_clicked() -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - AWaveshifterOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - auto gr = GraphWindow->MakeGraph(&ov->EmissionSpectrum_lambda, &ov->EmissionSpectrum, 2, "Wavelength, nm", "Relative intensity, a.u.", 20, 1, 0, 0, "", true); - gr->SetTitle("Emission spectrum"); - gr->SetMinimum(0); - - GraphWindow->Draw(gr, "apl"); -} - -void MainWindow::on_pbSurfaceWLS_LoadSpec_clicked() -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - AWaveshifterOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load emission spectrum", GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); - if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); - QVector X, Y; - int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); - if (ret == 0) - { - ov->EmissionSpectrum_lambda = X; - ov->EmissionSpectrum = Y; - ui->pbSurfaceWLS_ShowSpec->setEnabled(true); - } - ReconstructDetector(); - MainWindow::on_pbRefreshOverrides_clicked(); -} - void MainWindow::on_pbUpdatePreprocessingSettings_clicked() { writeLoadExpDataConfigToJson(Detector->PreprocessingJson); @@ -5200,120 +4841,6 @@ void MainWindow::on_actionServer_settings_triggered() GlobSetWindow->show(); } -void MainWindow::on_pbSSO_Load_clicked() -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - SpectralBasicOpticalOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - QString fileName = QFileDialog::getOpenFileName(this, "Load spectral data (Wave,Loss,Ref,Scatter)", GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); - if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); - - const QString err = ov->loadData(fileName); - if (err.isEmpty()) - { - ReconstructDetector(); - on_pbRefreshOverrides_clicked(); - } - else message(err, this); -} - - -#include "TMultiGraph.h" -void MainWindow::on_pbSSO_Show_clicked() -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - SpectralBasicOpticalOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - QVector Fr; - for (int i=0; iWave.size(); i++) - Fr << (1.0 - ov->ProbLoss.at(i) - ov->ProbRef.at(i) - ov->ProbDiff.at(i)); - - TMultiGraph* mg = new TMultiGraph(); - TGraph* gLoss = GraphWindow->ConstructTGraph(ov->Wave, ov->ProbLoss, "Loss", "Wavelength, nm", "", 2, 20, 1, 2); - mg->Add(gLoss, "LP"); - TGraph* gRef = GraphWindow->ConstructTGraph(ov->Wave, ov->ProbRef, "Specular reflection", "Wavelength, nm", "", 4, 21, 1, 4); - mg->Add(gRef, "LP"); - TGraph* gDiff = GraphWindow->ConstructTGraph(ov->Wave, ov->ProbDiff, "Diffuse scattering", "Wavelength, nm", "", 7, 22, 1, 7); - mg->Add(gDiff, "LP"); - TGraph* gFr = GraphWindow->ConstructTGraph(ov->Wave, Fr, "Fresnel", "Wavelength, nm", "", 1, 24, 1, 1, 1, 1); - mg->Add(gFr, "LP"); - - mg->SetMinimum(0); - GraphWindow->Draw(mg, "apl"); - mg->GetXaxis()->SetTitle("Wavelength, nm"); - mg->GetYaxis()->SetTitle("Probability"); - GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); -} - -void MainWindow::on_pbSSO_Binned_clicked() -{ - if (!ui->cbWaveResolved->isChecked()) - { - message("Activate wavelength-resolved simulation option!", this); - return; - } - - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - SpectralBasicOpticalOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - ov->initializeWaveResolved(true, WaveFrom, WaveStep, WaveNodes); - - QVector waveIndex; - for (int i=0; i Fr; - for (int i=0; iProbLossBinned.at(i) - ov->ProbRefBinned.at(i) - ov->ProbDiffBinned.at(i)); - - TMultiGraph* mg = new TMultiGraph(); - TGraph* gLoss = GraphWindow->ConstructTGraph(waveIndex, ov->ProbLossBinned, "Loss", "Wave index", "Loss", 2, 20, 1, 2); - mg->Add(gLoss, "LP"); - TGraph* gRef = GraphWindow->ConstructTGraph(waveIndex, ov->ProbRefBinned, "Specular reflection", "Wave index", "Reflection", 4, 21, 1, 4); - mg->Add(gRef, "LP"); - TGraph* gDiff = GraphWindow->ConstructTGraph(waveIndex, ov->ProbDiffBinned, "Diffuse scattering", "Wave index", "Scatter", 7, 22, 1, 7); - mg->Add(gDiff, "LP"); - TGraph* gFr = GraphWindow->ConstructTGraph(waveIndex, Fr, "Fresnel", "Wave index", "", 1, 24, 1, 1, 1, 1); - mg->Add(gFr, "LP"); - - mg->SetMinimum(0); - GraphWindow->Draw(mg, "apl"); - mg->GetXaxis()->SetTitle("Wave index"); - mg->GetYaxis()->SetTitle("Probability"); - GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); -} - -void MainWindow::on_cobSSO_ScatterModel_activated(int index) -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - SpectralBasicOpticalOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - ov->scatterModel = index; -} - -void MainWindow::on_ledSSO_EffWave_editingFinished() -{ - int MatFrom = ui->cobMaterialForOverrides->currentIndex(); - int MatTo = ui->cobMaterialTo->currentIndex(); - - SpectralBasicOpticalOverride* ov = dynamic_cast( (*Detector->MpCollection)[MatFrom]->OpticalOverrides[MatTo] ); - if (!ov) return; - - ov->effectiveWavelength = ui->ledSSO_EffWave->text().toDouble(); -} - void MainWindow::on_actionGrid_triggered() { RemoteWindow->show(); @@ -5364,3 +4891,27 @@ void MainWindow::on_ledSphericalPMAngle_editingFinished() on_pbUpdatePMproperties_clicked(); } +void MainWindow::on_lwOverrides_itemDoubleClicked(QListWidgetItem *) +{ + on_pbEditOverride_clicked(); +} + +void MainWindow::on_lwOverrides_itemSelectionChanged() +{ + int row = ui->lwOverrides->currentRow(); + + int MatFrom = ui->cobMaterialForOverrides->currentIndex(); + int Mats = Detector->MpCollection->countMaterials(); + int counter = 0; + for (int iMat=0; iMatMpCollection)[MatFrom]->OpticalOverrides[iMat]; + if (!ov) continue; + if (counter == row) + { + ui->cobMaterialTo->setCurrentIndex(iMat); + return; + } + counter++; + } +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 8c5d0d59..fd207cfe 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -234,7 +234,6 @@ private slots: void on_cbXbyYarray_stateChanged(int arg1); void on_cbRingsArray_stateChanged(int arg1); void on_pbRefreshOverrides_clicked(); - void on_pbOverride_clicked(); void on_pbStartMaterialInspector_clicked(); void on_pbAddparticleToActive_clicked(); void on_cobParticleToInspect_currentIndexChanged(int index); @@ -502,10 +501,6 @@ private slots: void on_cobXYtype_activated(int index); void on_cobTOP_activated(int index); void on_actionNew_detector_triggered(); - void on_pbSurfaceWLS_Show_clicked(); - void on_pbSurfaceWLS_Load_clicked(); - void on_pbSurfaceWLS_ShowSpec_clicked(); - void on_pbSurfaceWLS_LoadSpec_clicked(); void on_pbReloadTreeData_clicked(); void on_pbRenameSource_clicked(); void on_pbStopLoad_clicked(); @@ -539,9 +534,6 @@ private slots: void on_actionSave_Load_windows_status_on_Exit_Init_toggled(bool arg1); void on_pbShowEnergyDeposition_clicked(); void on_pbUpdateElectronics_clicked(); - void on_ledSimplisticAbs_editingFinished(); - void on_ledSimplisticSpecular_editingFinished(); - void on_ledSimplisticScatter_editingFinished(); void on_pbOverlay_clicked(); void on_pbScalePDE_clicked(); void on_pbLoadManifestFile_clicked(); @@ -555,8 +547,7 @@ private slots: void on_pbShowDetailedLog_clicked(); void on_pbCSMtestmany_clicked(); void on_pbST_showTracks_clicked(); - void on_pbST_AngleCos_clicked(); - void on_lwOverrides_itemClicked(QListWidgetItem *item); + void on_pbST_AngleCos_clicked(); void on_pbST_uniform_clicked(); void on_pbST_RvsAngle_clicked(); void on_pbST_ReflectionVsParameter_clicked(); @@ -597,54 +588,26 @@ private slots: void on_actionQuick_load_3_hovered(); void on_actionLoad_last_config_hovered(); void on_cobPartPerEvent_currentIndexChanged(int index); - void on_actionOpen_Python_window_triggered(); - void on_ledElNoiseSigma_Norm_editingFinished(); - void on_cbDarkCounts_Enable_toggled(bool checked); - void on_pbDarkCounts_Show_clicked(); - void on_pbDarkCounts_Load_clicked(); - void on_pbDarkCounts_Delete_clicked(); - void on_pushButton_clicked(); - void on_cobDarkCounts_Model_currentIndexChanged(int index); - void on_cobDarkCounts_LoadOptions_currentIndexChanged(int index); - void on_actionServer_window_triggered(); - void on_actionServer_settings_triggered(); - - void on_pbSSO_Load_clicked(); - - void on_pbSSO_Show_clicked(); - - void on_pbSSO_Binned_clicked(); - - void on_cobSSO_ScatterModel_activated(int index); - - void on_ledSSO_EffWave_editingFinished(); - void on_actionGrid_triggered(); - void on_pbOpenTrackProperties_Phot_clicked(); - void on_pbTrackOptionsGun_clicked(); - void on_pbTrackOptionsStack_clicked(); - void on_pbQEacceleratorWarning_clicked(); - void on_ledSphericalPMAngle_editingFinished(); - - void on_cobSurfaceWLS_Model_activated(int index); - void on_pbEditOverride_clicked(); + void on_lwOverrides_itemDoubleClicked(QListWidgetItem *item); + void on_lwOverrides_itemSelectionChanged(); public slots: void on_pbRebuildDetector_clicked(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index dff9021c..70c473ba 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -5310,7 +5310,7 @@ of the refracted beam: - Materials + Materials and optical overrides @@ -5357,25 +5357,12 @@ of the refracted beam: Qt::Vertical - - - - 403 - 6 - 130 - 16 - - - - has defined overrides: - - - 257 - 3 - 141 + 265 + 20 + 181 22 @@ -5386,19 +5373,6 @@ of the refracted beam: - - - - 200 - 40 - 150 - 23 - - - - ...register new overrides - - @@ -5416,926 +5390,160 @@ materials - 174 + 180 -2 - 79 + 351 20 - - - - - 75 - true - - - - Overrides - - - Qt::AlignCenter - - - - - - 2 - 18 - 166 - 137 - - - - Qt::CustomContextMenu - - - - - - 105 - 159 - 61 - 23 - - - - Remove - - - - - - 389 - 87 - 141 - 22 - - - - - - - 173 - 89 - 213 - 16 - - - - Override for interface with: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 265 - 113 - 269 - 73 - - - - - - - QFrame::StyledPanel - - - QFrame::Plain - - - 0 - - - - - - 6 - 10 - 256 - 51 - - - - Override not defined - - - Qt::AlignCenter - - - - - - - - -2 - 24 - 111 - 20 - - - - Specular reflection: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 18 - 3 - 91 - 20 - - - - Absorption: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 18 - 45 - 91 - 20 - - - - Scattering: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 175 - 47 - 86 - 20 - - - - Scattering options: 1) in 4Pi; 2) Lambertian backward; 3) Lambertian forward - - - - Isotropic - - - - - Lamb, back - - - - - Lamb, forw - - - - - - - 112 - 3 - 57 - 20 - - - - 0 - - - - - - 112 - 25 - 57 - 20 - - - - 0 - - - - - - 112 - 47 - 57 - 20 - - - - 0 - - - - - - - - 75 - 5 - 53 - 20 - - - - 0.18 - - - - - - 0 - 6 - 71 - 16 - - - - Sigma alpha: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 1 - 26 - 70 - 16 - - - - Sigma spike: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 10 - 46 - 61 - 16 - - - - Albedo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 75 - 25 - 53 - 20 - - - - 1 - - - - - - 75 - 45 - 53 - 20 - - - - 0.97 - - - - - - 160 - 17 - 101 - 22 - - - - Height distribution model - - - - Empirical - - - - - Gauss - - - - - Exponential - - - - - - - 160 - 38 - 101 - 22 - - - - Slope distribution model - - - - Trowbridgereitz - - - - - Cooktorrance - - - - - Bivariatecauchy - - - - - - - 132 - 21 - 23 - 13 - - - - HD: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 132 - 43 - 23 - 13 - - - - SD: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - false - - - - 170 - 30 - 81 - 22 - - - - - Polished - - - - - - - 170 - 10 - 81 - 16 - - - - Surface model: - - - - - - 12 - 15 - 61 - 16 - - - - Real N: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 77 - 13 - 51 - 20 - - - - Real part of the refractive index - - - 1.07 - - - - - - 77 - 40 - 51 - 20 - - - - Imaginary part of the refractive index - - - 0.6 - - - - - - 5 - 43 - 69 - 13 - - - - Imaginary N: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 56 - 28 - 71 - 16 - - - - Albedo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 137 - 27 - 53 - 20 - - - - 0.95 - - - - - - - - 137 - 19 - 60 - 23 - - - - Show - - - - - - 202 - 19 - 60 - 23 - - - - Load - - - - - - 10 - 20 - 123 - 20 - - - - reemission probability: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 3 - 45 - 121 - 20 - - - - Emission spectrum: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 202 - 45 - 60 - 23 - - - - Load - - - - - - 137 - 45 - 60 - 23 - - - - Show - - - - - - 9 - 4 - 121 - 20 - - - - Scattering options: 1) in 4Pi; 2) Lambertian backward; 3) Lambertian forward - - - - Isotropic - - - - - Lamb, back (2Pi) - - - - - Lamb, forw (2Pi) - - - - - - - - - 90 - 29 - 171 - 16 - - - - When wave not defined, assume - - - Qt::AlignCenter - - - - - false - - - - 100 - 4 - 75 - 23 - - - - Show - - - - - - 10 - 4 - 75 - 23 - - - - Format: Lines of Wavelength, ProbLoss, ProbReflection,ProbDiffuse - - - Load - - - - - - 7 - 46 - 82 - 20 - - - - Scattering options: 1) in 4Pi; 2) Lambertian backward; 3) Lambertian forward - - - - Isotropic - - - - - Lamb, back - - - - - Lamb, forw - - - - - - - 5 - 29 - 81 - 16 - - - - Diffuse type: - - - Qt::AlignCenter - - - - - - 149 - 46 - 50 - 20 - - - - 500 - - - - - - 204 - 49 - 29 - 13 - - - - nm - - - - - false - - - - 180 - 4 - 75 - 23 - - - - Binned - - - label_208 - pbSSO_Show - pbSSO_Load - label_238 - ledSSO_EffWave - label_241 - pbSSO_Binned - cobSSO_ScatterModel - + + + + + 75 + true + + + + Optical overrides (from -> to) + + + Qt::AlignCenter + - + - 213 - 145 - 52 - 10 + 2 + 18 + 166 + 137 - - Qt::Horizontal + + Qt::CustomContextMenu + + + Double-click to edit - + - 179 - 138 - 77 + 105 + 159 + 61 23 - - If override is notdefined, the optical photon behavior on the interface is defined by Fresnel equations + + Remove - - - Fresnel - - - - - Simplistic - - - - - Claudio's - - - - - OnMetal - - - - - FS_NP - - - - - WLS - - - - - SimpSpectral - - - + - 185 - 119 - 47 - 20 + 363 + 160 + 160 + 22 - - Model: - - 360 - 40 - 140 + 240 + 80 + 241 23 - ...refresh overrides + ...refresh override indication 175 - 26 + 66 359 - 60 + 89 + + Double-click to edit + - 179 - 164 - 75 + 185 + 160 + 171 23 - PushButton + Define / edit override to: + + + + + + 176 + 22 + 87 + 17 + + + + From material: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 180 + 48 + 171 + 16 + + + + List of defined overrides: + + + + + + 300 + 170 + 118 + 3 + + + + Qt::Horizontal + line_6 lwOverrides lwMaterials pbStartMaterialInspector label_28 line_12 - label_37 - pbOverride pbRefreshMaterials label_82 cobMaterialForOverrides pbRemoveMaterial cobMaterialTo - label_29 - swScatterModel - line_63 - cobOpticalOverrideModel - label_149 pbRefreshOverrides pbEditOverride + label_8 + label_15 @@ -17282,22 +16490,6 @@ on stack - - cobScatteringModel - activated(int) - pbOverride - click() - - - 497 - 257 - - - 294 - 118 - - - ledTimeOfOneMeasurement editingFinished() @@ -17362,118 +16554,6 @@ on stack - - cobOpticalOverrideModel - currentIndexChanged(int) - swScatterModel - setCurrentIndex(int) - - - 254 - 218 - - - 286 - 225 - - - - - cobOpticalOverrideModel - activated(int) - pbOverride - click() - - - 243 - 218 - - - 287 - 118 - - - - - ledSigmaAlpha - editingFinished() - pbOverride - click() - - - 390 - 215 - - - 289 - 118 - - - - - ledSigmaSpike - editingFinished() - pbOverride - click() - - - 396 - 235 - - - 306 - 118 - - - - - ledAlbedo - editingFinished() - pbOverride - click() - - - 386 - 255 - - - 297 - 118 - - - - - conHeightModel - activated(int) - pbOverride - click() - - - 480 - 229 - - - 318 - 118 - - - - - cobSlopeModel - activated(int) - pbOverride - click() - - - 510 - 250 - - - 321 - 118 - - - cobMaterialForOverrides activated(int) @@ -17522,54 +16602,6 @@ on stack - - ledRealN - editingFinished() - pbOverride - click() - - - 396 - 223 - - - 326 - 118 - - - - - ledImaginaryN - editingFinished() - pbOverride - click() - - - 373 - 250 - - - 310 - 118 - - - - - cobMetalSurfaceModel - activated(int) - pbOverride - click() - - - 472 - 242 - - - 262 - 118 - - - cbLimitNumberTreeEvents toggled(bool) @@ -19586,22 +18618,6 @@ on stack - - ledNevesAlbedo - editingFinished() - pbOverride - click() - - - 424 - 234 - - - 318 - 127 - - - ledElNoiseSigma_Stat editingFinished() diff --git a/src/gui/materialinspectorwindow.cpp b/src/gui/materialinspectorwindow.cpp index acfb298e..3e257af6 100644 --- a/src/gui/materialinspectorwindow.cpp +++ b/src/gui/materialinspectorwindow.cpp @@ -2477,7 +2477,7 @@ void MaterialInspectorWindow::FillNeutronTable() QPushButton* pbReaction = new QPushButton("Reactions"); l->addWidget(pbReaction); QLabel* lab = new QLabel(" "); - QIcon YellowIcon = createColorCircleIcon( QSize(12,12), ( absEl->DecayScenarios.isEmpty() ? Qt::white : Qt::green ) ); + QIcon YellowIcon = GuiUtils::createColorCircleIcon( QSize(12,12), ( absEl->DecayScenarios.isEmpty() ? Qt::white : Qt::green ) ); lab->setPixmap(YellowIcon.pixmap(16,16)); l->addWidget( lab ); w->setLayout(l); diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index cb53cf6a..1333c01d 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -23,29 +23,9 @@ #define MODEL_VERSION 3 -void PhScatClaudioModel::printConfiguration(int iWave) +const QString PhScatClaudioModel::getReportLine() const { - double Rindex1 = (*MatCollection)[MatFrom]->getRefractiveIndex(iWave); - double Rindex2 = (*MatCollection)[MatTo]->getRefractiveIndex(iWave); - - qDebug() << "-------Configuration:-------"; - qDebug() << "Model:"<convertWaveIndexToWavelength(iWave)<< "m"; - qDebug() << "----------------------------"; -} - -QString PhScatClaudioModel::getReportLine() -{ - QString s = "to " + (*MatCollection)[MatTo]->name; - QString s1; - s1.setNum(MatTo); - s += " ("+s1+") --> Claudio's model"; - return s; + return " v2"; } void PhScatClaudioModel::writeToJson(QJsonObject &json) @@ -365,9 +345,9 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(ATra return Back; } -QString PhScatClaudioModelV2::getReportLine() +const QString PhScatClaudioModelV2::getReportLine() const { - return PhScatClaudioModel::getReportLine()+"_v2"; + return " v2"; } AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) @@ -541,9 +521,9 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(AT return Back; } -QString PhScatClaudioModelV2d2::getReportLine() +const QString PhScatClaudioModelV2d2::getReportLine() const { - return PhScatClaudioModel::getReportLine()+"_v2.2"; + return " v2.2"; } AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) @@ -717,7 +697,7 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(AT return Back; } -QString PhScatClaudioModelV2d1::getReportLine() +const QString PhScatClaudioModelV2d1::getReportLine() const { - return PhScatClaudioModel::getReportLine()+"_v2.1"; + return " v2.1"; } diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index 1e9c48a4..458498a3 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -21,17 +21,18 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) = 0; //unitary vectors! iWave - photon wave index, -1 if no wave-resolved - virtual void printConfiguration(int iWave); - virtual QString getType() const = 0; - virtual QString getReportLine(); + //virtual const QString getType() const override = 0; + virtual const QString getAbbreviation() const override {return "Clau";} + virtual const QString getReportLine() const override; // save/load config - virtual void writeToJson(QJsonObject &json); - virtual bool readFromJson(QJsonObject &json); + virtual void writeToJson(QJsonObject &json) override; + virtual bool readFromJson(QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif + virtual const QString checkOverrideData() override; // interface properties @@ -56,8 +57,8 @@ class PhScatClaudioModelV2 : public PhScatClaudioModel PhScatClaudioModelV2(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModel(MatCollection, MatFrom, MatTo) {} virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); - virtual QString getType() const {return "Claudio_Model_V2";} - virtual QString getReportLine(); + virtual const QString getType() const override {return "Claudio_Model_V2";} + virtual const QString getReportLine() const override; protected: virtual double GnFunc(double cost); @@ -70,8 +71,8 @@ class PhScatClaudioModelV2d1 : public PhScatClaudioModelV2 PhScatClaudioModelV2d1(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModelV2(MatCollection, MatFrom, MatTo) {} virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); - virtual QString getType() const {return "Claudio_Model_V2d1";} - virtual QString getReportLine(); + virtual const QString getType() const override {return "Claudio_Model_V2d1";} + virtual const QString getReportLine() const; }; class PhScatClaudioModelV2d2 : public PhScatClaudioModelV2 @@ -80,8 +81,8 @@ class PhScatClaudioModelV2d2 : public PhScatClaudioModelV2 PhScatClaudioModelV2d2(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModelV2(MatCollection, MatFrom, MatTo) {} virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); - virtual QString getType() const {return "Claudio_Model_V2d2";} - virtual QString getReportLine(); + virtual const QString getType() const {return "Claudio_Model_V2d2";} + virtual const QString getReportLine() const; }; #endif // PHSCATCLAUDIOMODEL_H diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index 51c54855..179d5719 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -19,23 +19,11 @@ #include #endif -void ScatterOnMetal::printConfiguration(int /*iWave*/) +const QString ScatterOnMetal::getReportLine() const { - qDebug() << "-------Configuration:-------"; - qDebug() << "Model:"<name; - QString s1; - s1.setNum(MatTo); - s += " ("+s1+") --> Scatter on metal: "; - s += " n="+QString::number(RealN); - s += " k="+QString::number(ImaginaryN); + QString s; + s += "n = " + QString::number(RealN) + " "; + s += "k = " + QString::number(ImaginaryN); return s; } diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index b6792204..1d0499d5 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -18,22 +18,24 @@ class ScatterOnMetal : public AOpticalOverride virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved - virtual void printConfiguration(int iWave); - virtual QString getType() const {return "DielectricToMetal";} - virtual QString getReportLine(); + virtual const QString getType() const override {return "DielectricToMetal";} + virtual const QString getAbbreviation() const override {return "Met";} + virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json); - virtual bool readFromJson(QJsonObject &json); + virtual void writeToJson(QJsonObject &json) override; + virtual bool readFromJson(QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; #endif + virtual const QString checkOverrideData() override; //data double RealN = 1.07; double ImaginaryN = 0.6; + private: double calculateReflectivity(double CosTheta, double RealN, double ImaginaryN, int waveIndex); From ecca47380fba56d7afe59f771cc879cab321a1c7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 12:05:13 +0100 Subject: [PATCH 029/140] ++ --- .../ascriptopticaloverride.cpp | 4 +- src/OpticalOverrides/ascriptopticaloverride.h | 4 +- src/common/aopticaloverride.cpp | 38 +++++++------------ src/common/aopticaloverride.h | 32 ++++++++-------- src/modules/phscatclaudiomodel.cpp | 4 +- src/modules/phscatclaudiomodel.h | 24 ++++++------ src/modules/scatteronmetal.cpp | 4 +- src/modules/scatteronmetal.h | 6 +-- 8 files changed, 53 insertions(+), 63 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 84ad816b..183e443e 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -42,14 +42,14 @@ const QString AScriptOpticalOverride::getReportLine() const return QString(); } -void AScriptOpticalOverride::writeToJson(QJsonObject &json) +void AScriptOpticalOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); json["Script"] = Script; } -bool AScriptOpticalOverride::readFromJson(QJsonObject &json) +bool AScriptOpticalOverride::readFromJson(const QJsonObject &json) { QString type = json["Model"].toString(); if (type != getType()) return false; //file for wrong model! diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index 2f7e3f1c..d0e2188f 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -19,8 +19,8 @@ class AScriptOpticalOverride : public AOpticalOverride virtual const QString getAbbreviation() const override {return "JS";} virtual const QString getReportLine() const override; - virtual void writeToJson(QJsonObject &json) override; - virtual bool readFromJson(QJsonObject &json) override; + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 009a1183..37c9d2f8 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -36,14 +36,14 @@ #include "graphwindowclass.h" #endif -void AOpticalOverride::writeToJson(QJsonObject &json) +void AOpticalOverride::writeToJson(QJsonObject &json) const { json["Model"] = getType(); json["MatFrom"] = MatFrom; json["MatTo"] = MatTo; } -bool AOpticalOverride::readFromJson(QJsonObject &json) +bool AOpticalOverride::readFromJson(const QJsonObject &json) { QString type = json["Model"].toString(); if (type != getType()) return false; //file for wrong model! @@ -194,7 +194,7 @@ const QString BasicOpticalOverride::getReportLine() const return s; } -void BasicOpticalOverride::writeToJson(QJsonObject &json) +void BasicOpticalOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -204,7 +204,7 @@ void BasicOpticalOverride::writeToJson(QJsonObject &json) json["ScatMode"] = scatterModel; } -bool BasicOpticalOverride::readFromJson(QJsonObject &json) +bool BasicOpticalOverride::readFromJson(const QJsonObject &json) { QString type = json["Model"].toString(); if (type != getType()) return false; //file for wrong model! @@ -437,19 +437,17 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATrac const QString FSNPOpticalOverride::getReportLine() const { - QString s = "to " + (*MatCollection)[MatTo]->name; - s += "->FS_NP model, albedo="+QString::number(Albedo); - return s; + return QString("Albedo %1").arg(Albedo); } -void FSNPOpticalOverride::writeToJson(QJsonObject &json) +void FSNPOpticalOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); json["Albedo"] = Albedo; } -bool FSNPOpticalOverride::readFromJson(QJsonObject &json) +bool FSNPOpticalOverride::readFromJson(const QJsonObject &json) { QString type = json["Model"].toString(); if (type != getType()) return false; //file for wrong model! @@ -628,14 +626,10 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra const QString AWaveshifterOverride::getReportLine() const { - QString s = "to " + (*MatCollection)[MatTo]->name; - s += "->SurfaceWLS"; - if (ReemissionProbability_lambda.isEmpty() ) s += "; Prob: not set!"; - if (EmissionSpectrum_lambda.isEmpty() ) s += "; Spectrum not set!"; - return s; + return QString(); } -void AWaveshifterOverride::writeToJson(QJsonObject &json) +void AWaveshifterOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -648,7 +642,7 @@ void AWaveshifterOverride::writeToJson(QJsonObject &json) json["ReemissionModel"] = ReemissionModel; } -bool AWaveshifterOverride::readFromJson(QJsonObject &json) +bool AWaveshifterOverride::readFromJson(const QJsonObject &json) { //QString type = json["Model"].toString(); //if (type != getType()) return false; //file for wrong model! @@ -892,16 +886,10 @@ AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calcul const QString SpectralBasicOpticalOverride::getReportLine() const { - QString s = "to " + (*MatCollection)[MatTo]->name; - s += "->"; - - if (Wave.isEmpty()) return s + " To be defined"; //not defined - shown during configuration phase only - - s += " Spectral data with " + QString::number(Wave.size()) + " points"; - return s; + return QString("Spectral data with %1 points").arg(Wave.size()); } -void SpectralBasicOpticalOverride::writeToJson(QJsonObject &json) +void SpectralBasicOpticalOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -923,7 +911,7 @@ void SpectralBasicOpticalOverride::writeToJson(QJsonObject &json) json["Data"] = sp; } -bool SpectralBasicOpticalOverride::readFromJson(QJsonObject &json) +bool SpectralBasicOpticalOverride::readFromJson(const QJsonObject &json) { if (!AOpticalOverride::readFromJson(json)) return false; diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index dc5960bf..81322d8f 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -17,17 +17,18 @@ class QObject; class GraphWindowClass; class ATracerStateful; -//modify these two functions if you want to register a new override type! +// !!! +// modify these two functions if you want to register a new override type AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); const QStringList ListOvAllOpticalOverrideTypes(); +//base optical override class - all new overrides must inherit from it class AOpticalOverride { public: - //return status for photon tracing: - enum OpticalOverrideResultEnum {NotTriggered, Absorbed, Forward, Back, _Error_}; - //detailed status for statistics only - used by override tester only - enum ScatterStatusEnum {SpikeReflection, LobeReflection, LambertianReflection, Absorption, Transmission, Error, UnclassifiedReflection, Empty, Fresnel}; + enum OpticalOverrideResultEnum {NotTriggered, Absorbed, Forward, Back, _Error_}; //return status for photon tracing: + enum ScatterStatusEnum {SpikeReflection, LobeReflection, LambertianReflection, + Absorption, Transmission, Error, UnclassifiedReflection, Empty, Fresnel}; //detailed status for statistics only - used by override tester only AOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : MatCollection(MatCollection), MatFrom(MatFrom), MatTo(MatTo) {} @@ -43,8 +44,8 @@ class AOpticalOverride virtual void initializeWaveResolved(bool /*bWaveResolved*/, double /*waveFrom*/, double /*waveStep*/, int /*waveNodes*/) {} //override if override has wavelength-resolved data // save/load config - virtual void writeToJson(QJsonObject &json); - virtual bool readFromJson(QJsonObject &json); + virtual void writeToJson(QJsonObject &json) const; + virtual bool readFromJson(const QJsonObject &json); //next one is used by MatCollection when a material is removed void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} @@ -78,8 +79,8 @@ class BasicOpticalOverride : public AOpticalOverride virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) override; - virtual bool readFromJson(QJsonObject &json) override; + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; @@ -109,8 +110,8 @@ class FSNPOpticalOverride : public AOpticalOverride virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) override; - virtual bool readFromJson(QJsonObject &json) override; + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; @@ -135,12 +136,13 @@ class AWaveshifterOverride : public AOpticalOverride virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json); - virtual bool readFromJson(QJsonObject &json); + virtual void writeToJson(QJsonObject &json) const; + virtual bool readFromJson(const QJsonObject &json); #ifdef GUI virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; #endif + virtual const QString checkOverrideData() override; //-- parameters -- @@ -183,8 +185,8 @@ class SpectralBasicOpticalOverride : public BasicOpticalOverride virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) override; - virtual bool readFromJson(QJsonObject &json) override; + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; virtual void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; const QString loadData(const QString& fileName); diff --git a/src/modules/phscatclaudiomodel.cpp b/src/modules/phscatclaudiomodel.cpp index 1333c01d..ff7d813a 100644 --- a/src/modules/phscatclaudiomodel.cpp +++ b/src/modules/phscatclaudiomodel.cpp @@ -28,7 +28,7 @@ const QString PhScatClaudioModel::getReportLine() const return " v2"; } -void PhScatClaudioModel::writeToJson(QJsonObject &json) +void PhScatClaudioModel::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -39,7 +39,7 @@ void PhScatClaudioModel::writeToJson(QJsonObject &json) json["SDmodel"] = SlopeDistribution; } -bool PhScatClaudioModel::readFromJson(QJsonObject &json) +bool PhScatClaudioModel::readFromJson(const QJsonObject &json) { QString type = json["Model"].toString(); if (!type.startsWith("Claudio_Model")) diff --git a/src/modules/phscatclaudiomodel.h b/src/modules/phscatclaudiomodel.h index 458498a3..37abae10 100644 --- a/src/modules/phscatclaudiomodel.h +++ b/src/modules/phscatclaudiomodel.h @@ -17,8 +17,8 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! // constructor PhScatClaudioModel(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : AOpticalOverride(MatCollection, MatFrom, MatTo) {} - // main method: - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) = 0; + + //virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) = 0; //unitary vectors! iWave - photon wave index, -1 if no wave-resolved //virtual const QString getType() const override = 0; @@ -26,8 +26,8 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! virtual const QString getReportLine() const override; // save/load config - virtual void writeToJson(QJsonObject &json) override; - virtual bool readFromJson(QJsonObject &json) override; + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; @@ -56,13 +56,13 @@ class PhScatClaudioModelV2 : public PhScatClaudioModel public: PhScatClaudioModelV2(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModel(MatCollection, MatFrom, MatTo) {} - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; virtual const QString getType() const override {return "Claudio_Model_V2";} virtual const QString getReportLine() const override; protected: - virtual double GnFunc(double cost); - virtual double SlopeAngle(double random_num); + virtual double GnFunc(double cost) override; + virtual double SlopeAngle(double random_num) override; }; class PhScatClaudioModelV2d1 : public PhScatClaudioModelV2 @@ -70,9 +70,9 @@ class PhScatClaudioModelV2d1 : public PhScatClaudioModelV2 public: PhScatClaudioModelV2d1(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModelV2(MatCollection, MatFrom, MatTo) {} - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; virtual const QString getType() const override {return "Claudio_Model_V2d1";} - virtual const QString getReportLine() const; + virtual const QString getReportLine() const override; }; class PhScatClaudioModelV2d2 : public PhScatClaudioModelV2 @@ -80,9 +80,9 @@ class PhScatClaudioModelV2d2 : public PhScatClaudioModelV2 public: PhScatClaudioModelV2d2(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModelV2(MatCollection, MatFrom, MatTo) {} - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); - virtual const QString getType() const {return "Claudio_Model_V2d2";} - virtual const QString getReportLine() const; + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; + virtual const QString getType() const override {return "Claudio_Model_V2d2";} + virtual const QString getReportLine() const override; }; #endif // PHSCATCLAUDIOMODEL_H diff --git a/src/modules/scatteronmetal.cpp b/src/modules/scatteronmetal.cpp index 179d5719..ebf7c0c4 100644 --- a/src/modules/scatteronmetal.cpp +++ b/src/modules/scatteronmetal.cpp @@ -27,7 +27,7 @@ const QString ScatterOnMetal::getReportLine() const return s; } -void ScatterOnMetal::writeToJson(QJsonObject &json) +void ScatterOnMetal::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -35,7 +35,7 @@ void ScatterOnMetal::writeToJson(QJsonObject &json) json["ImaginaryN"] = ImaginaryN; } -bool ScatterOnMetal::readFromJson(QJsonObject &json) +bool ScatterOnMetal::readFromJson(const QJsonObject &json) { QString type = json["Model"].toString(); if (type != getType()) return false; //file for wrong model! diff --git a/src/modules/scatteronmetal.h b/src/modules/scatteronmetal.h index 1d0499d5..a02bb31f 100644 --- a/src/modules/scatteronmetal.h +++ b/src/modules/scatteronmetal.h @@ -16,15 +16,15 @@ class ScatterOnMetal : public AOpticalOverride : AOpticalOverride(MatCollection, MatFrom, MatTo) {} virtual ~ScatterOnMetal() {} - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved virtual const QString getType() const override {return "DielectricToMetal";} virtual const QString getAbbreviation() const override {return "Met";} virtual const QString getReportLine() const override; // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) override; - virtual bool readFromJson(QJsonObject &json) override; + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; From fc7689a2a27020df5199a9282eb3a54e90ecad2c Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 13:27:32 +0100 Subject: [PATCH 030/140] ++ --- src/gui/mainwindow.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++ src/gui/mainwindow.h | 2 ++ src/gui/mainwindow.ui | 16 ++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 06ccf013..5d2d0ed8 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4915,3 +4915,65 @@ void MainWindow::on_lwOverrides_itemSelectionChanged() counter++; } } + +static bool orDialogPositioned = false; +static QSize orDialogSize; +static QPoint orDialogPosition; +void MainWindow::on_pbShowOverrideMap_clicked() +{ + int numMat = MpCollection->countMaterials(); + + QDialog* d = new QDialog(this); + d->setWindowTitle("Optical override Vertical->Horizontal. Double click to define / edit override"); + QVBoxLayout* l = new QVBoxLayout(d); + QTableWidget* tw = new QTableWidget(numMat, numMat); + l->addWidget(tw); + + tw->setVerticalHeaderLabels(MpCollection->getListOfMaterialNames()); + tw->setHorizontalHeaderLabels(MpCollection->getListOfMaterialNames()); + + for (int ifrom = 0; ifrom < numMat; ifrom++) + for (int ito = 0; ito < numMat; ito++) + { + AOpticalOverride* ov = (*MpCollection)[ifrom]->OpticalOverrides.at(ito); + QString text; + if (ov) text = ov->getAbbreviation(); + QTableWidgetItem *it = new QTableWidgetItem(text); + it->setTextAlignment(Qt::AlignCenter); + if (ov) + { + it->setBackground(QBrush(Qt::lightGray)); + it->setToolTip(ov->getReportLine()); + } + it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + tw->setItem(ifrom, ito, it); + } + QObject::connect(tw, &QTableWidget::itemDoubleClicked, d, &QDialog::accept); + + if (orDialogPositioned) + { + d->resize(orDialogSize); + d->move(orDialogPosition); + } + + int res = d->exec(); + + if (res == QDialog::Accepted) + { + int from = tw->currentRow(); + int to = tw->currentColumn(); + + if (from > -1 && to > -1) + { + ui->cobMaterialForOverrides->setCurrentIndex(from); + ui->cobMaterialTo->setCurrentIndex(to); + on_pbEditOverride_clicked(); + } + } + + orDialogPositioned = true; + orDialogSize = d->size(); + orDialogPosition = d->pos(); + delete d; +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index fd207cfe..66f878f7 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -609,6 +609,8 @@ private slots: void on_lwOverrides_itemDoubleClicked(QListWidgetItem *item); void on_lwOverrides_itemSelectionChanged(); + void on_pbShowOverrideMap_clicked(); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 70c473ba..d125b835 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -5491,7 +5491,7 @@ materials 176 - 22 + 23 87 17 @@ -5529,6 +5529,19 @@ materials Qt::Horizontal + + + + 495 + 0 + 40 + 23 + + + + Map + + line_6 lwOverrides lwMaterials @@ -5544,6 +5557,7 @@ materials pbEditOverride label_8 label_15 + pbShowOverrideMap From 98a8a60218f88fd2ca6baf5c18def28d26fd0fd7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 15:35:07 +0100 Subject: [PATCH 031/140] ++ --- src/gui/MainWindowTools/MainWindowMenu.cpp | 22 ++++++++++++++++++++++ src/gui/mainwindow.cpp | 15 ++++++--------- src/gui/mainwindow.h | 4 ++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowMenu.cpp b/src/gui/MainWindowTools/MainWindowMenu.cpp index 77bbe50f..26fbb782 100644 --- a/src/gui/MainWindowTools/MainWindowMenu.cpp +++ b/src/gui/MainWindowTools/MainWindowMenu.cpp @@ -129,6 +129,8 @@ void MainWindow::on_actionReset_position_of_windows_triggered() GraphWindow->showNormal(); GraphWindow->raise(); } + + bOptOvDialogPositioned = false; } void addWindow(QString name, QMainWindow* w, QJsonObject &json) @@ -185,6 +187,13 @@ void MainWindow::on_actionSave_position_and_stratus_of_all_windows_triggered() js["h"] = ScriptWinH; json["Script"] = js; + QJsonObject jsOD; + jsOD["x"] = OptOvDialogPosition.x(); + jsOD["y"] = OptOvDialogPosition.y(); + jsOD["w"] = OptOvDialogSize.width(); + jsOD["h"] = OptOvDialogSize.height(); + json["OptOvDialog"] = jsOD; + //QString configDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)+"/ants2"; //if (!QDir(configDir).exists()) QDir().mkdir(configDir); QString fileName = GlobSet->ConfigDir + "/WindowConfig.ini"; @@ -254,6 +263,19 @@ void MainWindow::on_actionLoad_positions_and_status_of_all_windows_triggered() parseJson(js, "h", ScriptWinH); if (GenScriptWindow) recallGeometryOfLocalScriptWindow(); } + + if (json.contains("OptOvDialog")) + { + QJsonObject jsOD = json["OptOvDialog"].toObject(); + int x, y, w, h; + parseJson(jsOD, "x", x); + parseJson(jsOD, "y", y); + OptOvDialogPosition = QPoint(x, y); + parseJson(jsOD, "w", w); + parseJson(jsOD, "h", h); + OptOvDialogSize = QSize(w, h); + bOptOvDialogPositioned = true; + } } } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 5d2d0ed8..4c5e0b70 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4916,9 +4916,6 @@ void MainWindow::on_lwOverrides_itemSelectionChanged() } } -static bool orDialogPositioned = false; -static QSize orDialogSize; -static QPoint orDialogPosition; void MainWindow::on_pbShowOverrideMap_clicked() { int numMat = MpCollection->countMaterials(); @@ -4951,10 +4948,10 @@ void MainWindow::on_pbShowOverrideMap_clicked() } QObject::connect(tw, &QTableWidget::itemDoubleClicked, d, &QDialog::accept); - if (orDialogPositioned) + if (bOptOvDialogPositioned) { - d->resize(orDialogSize); - d->move(orDialogPosition); + d->resize(OptOvDialogSize); + d->move(OptOvDialogPosition); } int res = d->exec(); @@ -4972,8 +4969,8 @@ void MainWindow::on_pbShowOverrideMap_clicked() } } - orDialogPositioned = true; - orDialogSize = d->size(); - orDialogPosition = d->pos(); + bOptOvDialogPositioned = true; + OptOvDialogSize = d->size(); + OptOvDialogPosition = d->pos(); delete d; } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 66f878f7..d731974e 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -450,6 +450,10 @@ private slots: bool fStopLoadRequested; + bool bOptOvDialogPositioned = false; + QSize OptOvDialogSize; + QPoint OptOvDialogPosition; + void clearPreprocessingData(); void updateCOBsWithPMtypeNames(); void ViewChangeRelFactors(QString options); From 34a9a128d77e5a51e10ba6b7562d727c9da56fcc Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 16:34:52 +0100 Subject: [PATCH 032/140] ++ --- .../aopticaloverridescriptinterface.cpp | 7 +++ .../aopticaloverridescriptinterface.h | 19 +++++--- .../ascriptopticaloverride.cpp | 48 +++++++++++++------ src/OpticalOverrides/ascriptopticaloverride.h | 2 +- src/gui/ascriptwindow.cpp | 15 +++--- 5 files changed, 60 insertions(+), 31 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index ba315f21..1d480acc 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -69,6 +69,13 @@ void AOpticalOverrideScriptInterface::TransmissionDirect() bResultAlreadySet = true; } +QVariant AOpticalOverrideScriptInterface::GetNormal() +{ + QVariantList vl; + vl << NormalVector[0] << NormalVector[1] << NormalVector[2]; + return vl; +} + void AOpticalOverrideScriptInterface::SpecularReflection() { double NK = 0; diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 600dffcb..321e0dac 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -18,14 +18,19 @@ class AOpticalOverrideScriptInterface : public AScriptInterface AOpticalOverride::OpticalOverrideResultEnum getResult(AOpticalOverride::ScatterStatusEnum& status); public slots: + + //ToDo: meddling test! -> e.g. dir was changed and then Lambert called + void Absorb(); - void Fresnel(); //ToDo: meddling test! - //void TransmissionSnell(); //ToDo: meddling test! - void TransmissionDirect(); //ToDo: meddling test! - void SpecularReflection(); //ToDo: meddling test! - void Isotropic(); //ToDo: meddling test! - void LambertBack(); //ToDo: meddling test! - void LambertForward(); //ToDo: meddling test! + void SpecularReflection(); + void Isotropic(); + void LambertBack(); + void LambertForward(); + void Fresnel(); + //void TransmissionSnell(); + void TransmissionDirect(); + + QVariant GetNormal(); QVariant GetDirection(); void SetDirection(double vx, double vy, double vz); diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 183e443e..6871a1fc 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -8,6 +8,7 @@ #include "ascriptwindow.h" #include "ajavascriptmanager.h" #include "globalsettingsclass.h" +#include #include "TRandom2.h" #include "aphoton.h" #include @@ -59,19 +60,26 @@ bool AScriptOpticalOverride::readFromJson(const QJsonObject &json) } #ifdef GUI +#include QWidget *AScriptOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); QVBoxLayout* l = new QVBoxLayout(f); - QLabel* lab = new QLabel(""); - l->addWidget(lab); +// QLabel* lab = new QLabel(""); +// l->addWidget(lab); + QPlainTextEdit* pte = new QPlainTextEdit(); + pte->appendPlainText(Script); + pte->setReadOnly(true); + pte->setContextMenuPolicy(Qt::CustomContextMenu); + QObject::connect(pte, &QPlainTextEdit::customContextMenuRequested, [caller, pte, this] {openScriptWindow(caller); pte->clear(); pte->appendPlainText(Script);}); + l->addWidget(pte); QPushButton* pb = new QPushButton("Load / Edit script"); - QObject::connect(pb, &QPushButton::clicked, [caller, this] {openScriptWindow(caller);}); + QObject::connect(pb, &QPushButton::clicked, [caller, pte, this] {openScriptWindow(caller); pte->clear(); pte->appendPlainText(Script);}); l->addWidget(pb); - lab = new QLabel(""); - l->addWidget(lab); +// lab = new QLabel(""); +// l->addWidget(lab); return f; } @@ -87,22 +95,29 @@ const QString AScriptOpticalOverride::checkOverrideData() } #ifdef GUI -void AScriptOpticalOverride::openScriptWindow(QWidget *parent) +void AScriptOpticalOverride::openScriptWindow(QWidget *caller) { QString example = "photon.Absorbed()"; - TRandom2* RandGen = new TRandom2(); //leak! - AJavaScriptManager* sm = new AJavaScriptManager(RandGen); //leak! - AScriptWindow* sw = new AScriptWindow(sm, new GlobalSettingsClass(0), true, parent); //leak! + TRandom2* RandGen = new TRandom2(); + AJavaScriptManager* sm = new AJavaScriptManager(RandGen); + AScriptWindow* sw = new AScriptWindow(sm, new GlobalSettingsClass(0), true, caller); + sw->ConfigureForLightMode(&Script, "Optical override: custom script", example); - double vx[3]; - vx[0] = 0; vx[1] = 0; vx[3] = 1; + double v[3]; + v[0] = 0; + v[1] = 0; + v[2] = 1.0; double r[3]; - r[0] = 0; r[1] = 0; r[2] = 0; - APhoton phot(vx, r, -1, 0); + r[0] = 0; + r[1] = 0; + r[2] = 0; + APhoton phot(r, v, -1, 0); double normal[3]; - normal[0] = 0; normal[1] = 0; normal[2] = 1.0; + normal[0] = 0; + normal[1] = 0; + normal[2] = 1.0; AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); interfaceObject->configure(RandGen, &phot, normal); @@ -113,12 +128,15 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *parent) sw->SetInterfaceObject(math, "math"); //steals ownership! sw->setWindowModality(Qt::ApplicationModal); sw->show(); + GuiUtils::AssureWidgetIsWithinVisibleArea(sw); while (sw->isVisible()) { QCoreApplication::processEvents(); QThread::usleep(200); } - //qDebug() << "Script reports:"<TextEdit->insertPlainText(text); //} -void AScriptWindow::closeEvent(QCloseEvent* /*e*/) -{ -// qDebug() << "Script window: Close event"; -// if (ScriptManager->fEngineIsRunning) -// { -// e->ignore(); -// return; -// } +void AScriptWindow::closeEvent(QCloseEvent* e) +{ + QString Script = ScriptTabs[CurrentTab]->TextEdit->document()->toPlainText(); + //in light mode save the script directly + if (bLightMode && LightModeScript) *LightModeScript = Script; + + QMainWindow::closeEvent(e); } bool AScriptWindow::event(QEvent *e) From 0c501a87580d35422e54e8d9c60ff6c2d170f7dc Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 17:10:26 +0100 Subject: [PATCH 033/140] ++ --- .../ascriptopticaloverride.cpp | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 6871a1fc..48fec8dc 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -67,29 +67,36 @@ QWidget *AScriptOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass f->setFrameStyle(QFrame::Box); QVBoxLayout* l = new QVBoxLayout(f); -// QLabel* lab = new QLabel(""); -// l->addWidget(lab); QPlainTextEdit* pte = new QPlainTextEdit(); pte->appendPlainText(Script); + pte->moveCursor(QTextCursor::Start); + pte->ensureCursorVisible(); pte->setReadOnly(true); pte->setContextMenuPolicy(Qt::CustomContextMenu); - QObject::connect(pte, &QPlainTextEdit::customContextMenuRequested, [caller, pte, this] {openScriptWindow(caller); pte->clear(); pte->appendPlainText(Script);}); + QObject::connect(pte, &QPlainTextEdit::customContextMenuRequested, [caller, pte, this] + {openScriptWindow(caller); pte->clear(); pte->appendPlainText(Script); + pte->moveCursor(QTextCursor::Start); pte->ensureCursorVisible();}); l->addWidget(pte); QPushButton* pb = new QPushButton("Load / Edit script"); - QObject::connect(pb, &QPushButton::clicked, [caller, pte, this] {openScriptWindow(caller); pte->clear(); pte->appendPlainText(Script);}); + QObject::connect(pb, &QPushButton::clicked, [caller, pte, this] {openScriptWindow(caller); pte->clear(); pte->appendPlainText(Script); + pte->moveCursor(QTextCursor::Start); pte->ensureCursorVisible();}); l->addWidget(pb); -// lab = new QLabel(""); -// l->addWidget(lab); return f; } #endif +#include const QString AScriptOpticalOverride::checkOverrideData() { if (Script.isEmpty()) return "Script not defined!"; - //TODO check syntax! + QScriptSyntaxCheckResult check = QScriptEngine::checkSyntax(Script); + if (check.state() != QScriptSyntaxCheckResult::Valid) + { + int lineNumber = check.errorLineNumber(); + return QString("Syntax error at line %1").arg(lineNumber); + } return ""; } From 200b6c8d01765499726ba0e611cfefcbad1a0f62 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 17:25:03 +0100 Subject: [PATCH 034/140] ++ --- src/OpticalOverrides/ascriptopticaloverride.cpp | 8 ++++---- src/gui/ascriptwindow.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 48fec8dc..8e23138f 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -110,8 +110,6 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *caller) AJavaScriptManager* sm = new AJavaScriptManager(RandGen); AScriptWindow* sw = new AScriptWindow(sm, new GlobalSettingsClass(0), true, caller); - sw->ConfigureForLightMode(&Script, "Optical override: custom script", example); - double v[3]; v[0] = 0; v[1] = 0; @@ -129,10 +127,12 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *caller) AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); interfaceObject->configure(RandGen, &phot, normal); interfaceObject->setObjectName("photon"); - sw->SetInterfaceObject(interfaceObject, "photon"); //steals ownership! + sw->SetInterfaceObject(interfaceObject, "photon"); //takes ownership AMathScriptInterface* math = new AMathScriptInterface(RandGen); math->setObjectName("math"); - sw->SetInterfaceObject(math, "math"); //steals ownership! + sw->SetInterfaceObject(math, "math"); //takes ownership + + sw->ConfigureForLightMode(&Script, "Optical override: custom script", example); sw->setWindowModality(Qt::ApplicationModal); sw->show(); GuiUtils::AssureWidgetIsWithinVisibleArea(sw); diff --git a/src/gui/ascriptwindow.cpp b/src/gui/ascriptwindow.cpp index b4978efd..405146df 100644 --- a/src/gui/ascriptwindow.cpp +++ b/src/gui/ascriptwindow.cpp @@ -322,7 +322,7 @@ void AScriptWindow::SetInterfaceObject(QObject *interfaceObject, QString name) //completitionModel->setStringList(functions); //if standalone script, update the highlighter and tooltip - if (name.isEmpty()) UpdateAllTabs(); + if (bLightMode) UpdateAllTabs(); //special "needs" of particular interface objects if ( dynamic_cast(interfaceObject) || dynamic_cast(interfaceObject)) //"graph" or "hist" From 5f3615d597e1f05b6d930701f17593e189da6306 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 20:16:10 +0100 Subject: [PATCH 035/140] ++ --- .../aopticaloverridescriptinterface.cpp | 53 +++++++++++++++++-- .../aopticaloverridescriptinterface.h | 18 +++++-- .../ascriptopticaloverride.cpp | 6 +-- src/common/atracerstateful.cpp | 8 +-- src/common/atracerstateful.h | 4 +- .../aopticaloverridetester.cpp | 2 +- src/gui/mainwindow.ui | 2 +- src/modules/amaterialparticlecolection.h | 1 + 8 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index 1d480acc..b13ec397 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -1,18 +1,22 @@ #include "aopticaloverridescriptinterface.h" #include "aphoton.h" +#include "amaterialparticlecolection.h" #include #include #include "TMath.h" -AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface() {} +AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface(const AMaterialParticleCollection *MpCollection) : + AScriptInterface(), MPcollection(MpCollection) {} -void AOpticalOverrideScriptInterface::configure(TRandom2 * randGen, APhoton *photon, const double *normalVector) +void AOpticalOverrideScriptInterface::configure(TRandom2 * randGen, APhoton *photon, const double *normalVector, int MatFrom, int MatTo) { RandGen = randGen; Photon = photon; NormalVector = normalVector; + iMatFrom = MatFrom; + iMatTo = MatTo; //if script did not modify any photon properties, assuming override is skipped (doing Fresnel): bResultAlreadySet = true; @@ -62,6 +66,29 @@ void AOpticalOverrideScriptInterface::Fresnel() bResultAlreadySet = true; } +bool AOpticalOverrideScriptInterface::TryTransmissionSnell() +{ + double NK = 0; + for (int i=0; i<3; i++) NK += NormalVector[i] * Photon->v[i]; + double nFrom = (*MPcollection)[iMatFrom]->getRefractiveIndex(Photon->waveIndex); + double nTo = (*MPcollection)[iMatTo] ->getRefractiveIndex(Photon->waveIndex); + double nn = nFrom / nTo; + double UnderRoot = 1.0 - nn*nn*(1.0 - NK*NK); + if (UnderRoot < 0) + { + //conditions for total internal reflection + return false; + } + const double tmp = nn * NK - TMath::Sqrt(UnderRoot); + for (int i=0; i<3; i++) Photon->v[i] = -tmp * NormalVector[i] + nn * Photon->v[i]; + + ReturnResult = AOpticalOverride::Forward; + Status = AOpticalOverride::Transmission; + bResultAlreadySet = true; + + return true; +} + void AOpticalOverrideScriptInterface::TransmissionDirect() { ReturnResult = AOpticalOverride::Forward; @@ -157,7 +184,27 @@ void AOpticalOverrideScriptInterface::AddTime(double dt) Photon->time += dt; } -void AOpticalOverrideScriptInterface::Report(const QString text) +double AOpticalOverrideScriptInterface::getWaveIndex() +{ + return Photon->waveIndex; +} + +void AOpticalOverrideScriptInterface::setWaveIndex(int waveIndex) +{ + Photon->waveIndex = waveIndex; +} + +double AOpticalOverrideScriptInterface::getRefractiveIndexFrom() +{ + return (*MPcollection)[iMatFrom]->getRefractiveIndex(Photon->waveIndex); +} + +double AOpticalOverrideScriptInterface::GetRefractiveIndexTo() +{ + return (*MPcollection)[iMatTo]->getRefractiveIndex(Photon->waveIndex); +} + +void AOpticalOverrideScriptInterface::Console(const QString text) { qDebug() << text; } diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 321e0dac..2e375db5 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -7,14 +7,15 @@ #include class APhoton; +class AMaterialParticleCollection; class AOpticalOverrideScriptInterface : public AScriptInterface { Q_OBJECT public: - AOpticalOverrideScriptInterface(); + AOpticalOverrideScriptInterface(const AMaterialParticleCollection* MpCollection); - void configure(TRandom2 * RandGen, APhoton *Photon, const double *NormalVector); + void configure(TRandom2 * RandGen, APhoton *Photon, const double *NormalVector, int MatFrom, int MatTo); AOpticalOverride::OpticalOverrideResultEnum getResult(AOpticalOverride::ScatterStatusEnum& status); public slots: @@ -27,7 +28,7 @@ public slots: void LambertBack(); void LambertForward(); void Fresnel(); - //void TransmissionSnell(); + bool TryTransmissionSnell(); void TransmissionDirect(); QVariant GetNormal(); @@ -39,12 +40,21 @@ public slots: void SetTime(double time); void AddTime(double dt); - void Report(const QString text); + double getWaveIndex(); + void setWaveIndex(int waveIndex); + + double getRefractiveIndexFrom(); + double GetRefractiveIndexTo(); + + void Console(const QString text); private: + const AMaterialParticleCollection * MPcollection; TRandom2 * RandGen; APhoton * Photon; const double * NormalVector; + int iMatFrom; + int iMatTo; bool bResultAlreadySet; AOpticalOverride::OpticalOverrideResultEnum ReturnResult; //{NotTriggered, Absorbed, Forward, Back, _Error_}; diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 8e23138f..1b164cf2 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -30,7 +30,7 @@ AScriptOpticalOverride::~AScriptOpticalOverride() {} AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { //qDebug() << "Configuring script interfaces"; - Resources.overrideInterface->configure(Resources.RandGen, Photon, NormalVector); + Resources.overrideInterface->configure(Resources.RandGen, Photon, NormalVector, MatFrom, MatTo); Resources.mathInterface->setRandomGen(Resources.RandGen); //qDebug() << "Evaluating script"; Resources.evaluateScript(Script); @@ -124,8 +124,8 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *caller) normal[1] = 0; normal[2] = 1.0; - AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(); - interfaceObject->configure(RandGen, &phot, normal); + AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(MatCollection); + interfaceObject->configure(RandGen, &phot, normal, MatFrom, MatTo); interfaceObject->setObjectName("photon"); sw->SetInterfaceObject(interfaceObject, "photon"); //takes ownership AMathScriptInterface* math = new AMathScriptInterface(RandGen); diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index 5555ed2b..81a84ef7 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -27,19 +27,19 @@ void ATracerStateful::evaluateScript(const QString &Script) //qDebug() << "eval result:" << res.toString(); } -void ATracerStateful::generateScriptInfrastructureIfNeeded(AMaterialParticleCollection *MPcollection) +void ATracerStateful::generateScriptInfrastructureIfNeeded(const AMaterialParticleCollection *MPcollection) { bool bInUse = MPcollection->isScriptOpticalOverrideDefined(); - if (bInUse) generateScriptInfrastructure(); + if (bInUse) generateScriptInfrastructure(MPcollection); } -void ATracerStateful::generateScriptInfrastructure() +void ATracerStateful::generateScriptInfrastructure(const AMaterialParticleCollection *MPcollection) { qDebug() << "Creating script engine"; ScriptEngine = new QScriptEngine(); - overrideInterface = new AOpticalOverrideScriptInterface(); + overrideInterface = new AOpticalOverrideScriptInterface(MPcollection); qDebug() << "Created interface object:"<setObjectName("photon"); QScriptValue val = ScriptEngine->newQObject(overrideInterface, QScriptEngine::QtOwnership); diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h index f4196e7b..96a9806e 100644 --- a/src/common/atracerstateful.h +++ b/src/common/atracerstateful.h @@ -20,9 +20,9 @@ class ATracerStateful void evaluateScript(const QString& Script); - void generateScriptInfrastructureIfNeeded(AMaterialParticleCollection* MPcollection); //called by PhotonTracer (one per each thread!) + void generateScriptInfrastructureIfNeeded(const AMaterialParticleCollection* MPcollection); //called by PhotonTracer (one per each thread!) - void generateScriptInfrastructure(); //can be use from outside to force generation (e.g. interface tester); RandGen should already be set! + void generateScriptInfrastructure(const AMaterialParticleCollection *MPcollection); //can be use from outside to force generation (e.g. interface tester); RandGen should already be set! TRandom2 * RandGen = 0; QScriptEngine * ScriptEngine = 0; diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 8125b94c..fd5d0277 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -36,7 +36,7 @@ AOpticalOverrideTester::AOpticalOverrideTester(GraphWindowClass* GraphWindow, AM RandGen = new TRandom2(); Resources.RandGen = RandGen; - Resources.generateScriptInfrastructure(); + Resources.generateScriptInfrastructure(MPcollection); } AOpticalOverrideTester::~AOpticalOverrideTester() diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index d125b835..f2937265 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 0 + 3 diff --git a/src/modules/amaterialparticlecolection.h b/src/modules/amaterialparticlecolection.h index a62c32a2..279776e3 100644 --- a/src/modules/amaterialparticlecolection.h +++ b/src/modules/amaterialparticlecolection.h @@ -44,6 +44,7 @@ class AMaterialParticleCollection : public QObject //info requests //materials AMaterial* operator[](int i) {return MaterialCollectionData[i]; } //get pointer to material with index i + const AMaterial* operator[](int i) const {return MaterialCollectionData[i]; } //get pointer to material with index i int countMaterials() const {return MaterialCollectionData.size();} void getFirstOverridenMaterial(int &ifrom, int &ito); double convertWaveIndexToWavelength(int index) {return WaveFrom + WaveStep * index;} From 241c6197841882f03d85ad8977ee95dcf5a71c83 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 20:33:52 +0100 Subject: [PATCH 036/140] ++ --- .../aopticaloverridescriptinterface.cpp | 14 ++++++++++---- .../aopticaloverridescriptinterface.h | 6 ++++-- src/OpticalOverrides/ascriptopticaloverride.cpp | 10 +++------- src/OpticalOverrides/ascriptopticaloverride.h | 5 ++--- src/common/atracerstateful.cpp | 4 +++- src/common/atracerstateful.h | 1 + src/gui/MainWindowTools/MainWindowTests.cpp | 12 ++++-------- src/gui/MainWindowTools/aopticaloverridetester.cpp | 10 +++++----- src/gui/MainWindowTools/aopticaloverridetester.h | 2 +- src/modules/aphotontracer.cpp | 8 +++++--- src/modules/aphotontracer.h | 6 ++++-- 11 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index b13ec397..e0a8f3b2 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -7,12 +7,11 @@ #include "TMath.h" -AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface(const AMaterialParticleCollection *MpCollection) : - AScriptInterface(), MPcollection(MpCollection) {} +AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface(const AMaterialParticleCollection *MpCollection, TRandom2 *RandGen) : + AScriptInterface(), MPcollection(MpCollection), RandGen(RandGen) {} -void AOpticalOverrideScriptInterface::configure(TRandom2 * randGen, APhoton *photon, const double *normalVector, int MatFrom, int MatTo) +void AOpticalOverrideScriptInterface::configure(APhoton *photon, const double *normalVector, int MatFrom, int MatTo) { - RandGen = randGen; Photon = photon; NormalVector = normalVector; iMatFrom = MatFrom; @@ -204,6 +203,13 @@ double AOpticalOverrideScriptInterface::GetRefractiveIndexTo() return (*MPcollection)[iMatTo]->getRefractiveIndex(Photon->waveIndex); } +QVariant AOpticalOverrideScriptInterface::GetPosition() +{ + QVariantList vl; + vl << Photon->r[0] << Photon->r[1] << Photon->r[2]; + return vl; +} + void AOpticalOverrideScriptInterface::Console(const QString text) { qDebug() << text; diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 2e375db5..dc585949 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -13,9 +13,9 @@ class AOpticalOverrideScriptInterface : public AScriptInterface { Q_OBJECT public: - AOpticalOverrideScriptInterface(const AMaterialParticleCollection* MpCollection); + AOpticalOverrideScriptInterface(const AMaterialParticleCollection* MpCollection, TRandom2* RandGen); - void configure(TRandom2 * RandGen, APhoton *Photon, const double *NormalVector, int MatFrom, int MatTo); + void configure(APhoton *Photon, const double *NormalVector, int MatFrom, int MatTo); AOpticalOverride::OpticalOverrideResultEnum getResult(AOpticalOverride::ScatterStatusEnum& status); public slots: @@ -46,6 +46,8 @@ public slots: double getRefractiveIndexFrom(); double GetRefractiveIndexTo(); + QVariant GetPosition(); + void Console(const QString text); private: diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 1b164cf2..e57ca654 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -29,12 +29,8 @@ AScriptOpticalOverride::~AScriptOpticalOverride() {} AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { - //qDebug() << "Configuring script interfaces"; - Resources.overrideInterface->configure(Resources.RandGen, Photon, NormalVector, MatFrom, MatTo); - Resources.mathInterface->setRandomGen(Resources.RandGen); - //qDebug() << "Evaluating script"; + Resources.overrideInterface->configure(Photon, NormalVector, MatFrom, MatTo); Resources.evaluateScript(Script); - //qDebug() << "Photon result:"<getResult(Status)<<"Status"<getResult(Status); } @@ -124,8 +120,8 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *caller) normal[1] = 0; normal[2] = 1.0; - AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(MatCollection); - interfaceObject->configure(RandGen, &phot, normal, MatFrom, MatTo); + AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(MatCollection, RandGen); + interfaceObject->configure(&phot, normal, MatFrom, MatTo); interfaceObject->setObjectName("photon"); sw->SetInterfaceObject(interfaceObject, "photon"); //takes ownership AMathScriptInterface* math = new AMathScriptInterface(RandGen); diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index 2ddda5d1..ddc68f44 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -5,8 +5,6 @@ #include -class AOpticalOverrideScriptInterface; - class AScriptOpticalOverride : public AOpticalOverride { public: @@ -28,7 +26,8 @@ class AScriptOpticalOverride : public AOpticalOverride virtual const QString checkOverrideData() override; private: - QString Script = "photon.Absorb()"; + QString Script = "if (math.random() < 0.25) photon.LambertForward()\n" + "else photon.SpecularReflection()"; #ifdef GUI void openScriptWindow(QWidget* caller); diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index 81a84ef7..75169330 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -9,6 +9,8 @@ #include "TRandom2.h" +ATracerStateful::ATracerStateful(TRandom2 *RandGen) : RandGen(RandGen) {} + ATracerStateful::~ATracerStateful() { delete ScriptEngine; ScriptEngine = 0; @@ -39,7 +41,7 @@ void ATracerStateful::generateScriptInfrastructure(const AMaterialParticleCollec qDebug() << "Creating script engine"; ScriptEngine = new QScriptEngine(); - overrideInterface = new AOpticalOverrideScriptInterface(MPcollection); + overrideInterface = new AOpticalOverrideScriptInterface(MPcollection, RandGen); qDebug() << "Created interface object:"<setObjectName("photon"); QScriptValue val = ScriptEngine->newQObject(overrideInterface, QScriptEngine::QtOwnership); diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h index 96a9806e..107cf205 100644 --- a/src/common/atracerstateful.h +++ b/src/common/atracerstateful.h @@ -16,6 +16,7 @@ class AMathScriptInterface; class ATracerStateful { public: + ATracerStateful(TRandom2* RandGen); ~ATracerStateful(); void evaluateScript(const QString& Script); diff --git a/src/gui/MainWindowTools/MainWindowTests.cpp b/src/gui/MainWindowTools/MainWindowTests.cpp index e6d4a6a3..c0b875f2 100644 --- a/src/gui/MainWindowTools/MainWindowTests.cpp +++ b/src/gui/MainWindowTools/MainWindowTests.cpp @@ -355,8 +355,7 @@ void MainWindow::on_pbCSMtestmany_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); - ATracerStateful Resources; - Resources.RandGen = Detector->RandGen; + ATracerStateful Resources(Detector->RandGen); for (int i=0; isbST_number->value(); i++) { ph.v[0] = PhotDir.X(); //old has output direction after full cycle! @@ -463,8 +462,7 @@ void MainWindow::on_pbST_uniform_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); - ATracerStateful Resources; - Resources.RandGen = Detector->RandGen; + ATracerStateful Resources(Detector->RandGen); for (int i=0; iRandGen; + ATracerStateful Resources(Detector->RandGen); for (int iA=0; iA<91; iA++) //cycle by angle of incidence { double angle = iA; @@ -617,8 +614,7 @@ static QVector vParam, vTot, vSpike, vLobe, vDiff, vDir; static QString parName; void MainWindow::on_pbST_ReflectionVsParameter_clicked() { - ATracerStateful Resources; - Resources.RandGen = Detector->RandGen; + ATracerStateful Resources(Detector->RandGen); //input string processing QString inS = ui->leST_Parameter->text().simplified(); QStringList inL = inS.split(",", QString::SkipEmptyParts); diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index fd5d0277..fed5bc76 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -35,15 +35,15 @@ AOpticalOverrideTester::AOpticalOverrideTester(GraphWindowClass* GraphWindow, AM foreach(QLineEdit *w, list) if (w->objectName().startsWith("led")) w->setValidator(dv); RandGen = new TRandom2(); - Resources.RandGen = RandGen; - Resources.generateScriptInfrastructure(MPcollection); + Resources = new ATracerStateful(RandGen); + Resources->generateScriptInfrastructure(MPcollection); } AOpticalOverrideTester::~AOpticalOverrideTester() { - delete ui; - + delete Resources; delete RandGen; + delete ui; } void AOpticalOverrideTester::on_pbDirectionHelp_clicked() @@ -85,7 +85,7 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() ph.v[1] = K[1]; ph.v[2] = K[2]; ph.waveIndex = -1; //TODO wave res? - ov->calculate(Resources, &ph, N); + ov->calculate(*Resources, &ph, N); switch (ov->Status) { diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 7c18a512..48fd57ab 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -35,7 +35,7 @@ private slots: AOpticalOverride* ov; GraphWindowClass* GraphWindow; TRandom2* RandGen; - ATracerStateful Resources; + ATracerStateful* Resources; }; #endif // AOPTICALOVERRIDETESTER_H diff --git a/src/modules/aphotontracer.cpp b/src/modules/aphotontracer.cpp index fd22dad0..f9fa2dbb 100644 --- a/src/modules/aphotontracer.cpp +++ b/src/modules/aphotontracer.cpp @@ -9,6 +9,7 @@ #include "aphoton.h" #include "atrackrecords.h" #include "amonitor.h" +#include "atracerstateful.h" //Qt #include @@ -31,14 +32,15 @@ APhotonTracer::APhotonTracer(TGeoManager *geoManager, TRandom2 *RandomGenerator, fGridShiftOn = false; fBuildTracks = false; p = new APhoton(); + ResourcesForOverrides = new ATracerStateful(RandGen); //for transfer to overrides - ResourcesForOverrides.RandGen = RandGen; - ResourcesForOverrides.generateScriptInfrastructureIfNeeded(MaterialCollection); + ResourcesForOverrides->generateScriptInfrastructureIfNeeded(MaterialCollection); } APhotonTracer::~APhotonTracer() { + delete ResourcesForOverrides; delete p; } @@ -232,7 +234,7 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) //qDebug() << "Overrides defined! Model = "<getType(); N = navigator->FindNormal(kFALSE); fHaveNormal = true; - AOpticalOverride::OpticalOverrideResultEnum result = ov->calculate(ResourcesForOverrides, p, N); + AOpticalOverride::OpticalOverrideResultEnum result = ov->calculate(*ResourcesForOverrides, p, N); switch (result) { diff --git a/src/modules/aphotontracer.h b/src/modules/aphotontracer.h index 101958cb..c2913c4a 100644 --- a/src/modules/aphotontracer.h +++ b/src/modules/aphotontracer.h @@ -2,8 +2,9 @@ #define APHOTONTRACER_H #include "aphotonhistorylog.h" -#include "atracerstateful.h" + #include + #include "TMathBase.h" class APhoton; @@ -18,6 +19,7 @@ class TrackHolderClass; class TRandom2; class TGeoVolume; class AGridElementRecord; +class ATracerStateful; class APhotonTracer { @@ -49,7 +51,7 @@ class APhotonTracer QVector* Tracks; TrackHolderClass* track; QVector PhLog; - ATracerStateful ResourcesForOverrides; + ATracerStateful* ResourcesForOverrides; int MaxTracks = 10; int PhotonTracksAdded = 0; From c4e436a4de8efb6d3b485dcc03465c1166c19d4b Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 21:37:54 +0100 Subject: [PATCH 037/140] ++ --- .../aopticaloverridescriptinterface.cpp | 10 + .../aopticaloverridescriptinterface.h | 1 + .../aopticaloverridedialog.cpp | 10 +- .../MainWindowTools/aopticaloverridedialog.h | 5 +- .../aopticaloverridetester.cpp | 311 +++++++++++++++++- .../MainWindowTools/aopticaloverridetester.h | 16 +- .../MainWindowTools/aopticaloverridetester.ui | 92 +----- src/gui/mainwindow.cpp | 4 +- 8 files changed, 343 insertions(+), 106 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index e0a8f3b2..84e79b84 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -6,6 +6,7 @@ #include #include "TMath.h" +#include "TVector3.h" AOpticalOverrideScriptInterface::AOpticalOverrideScriptInterface(const AMaterialParticleCollection *MpCollection, TRandom2 *RandGen) : AScriptInterface(), MPcollection(MpCollection), RandGen(RandGen) {} @@ -102,6 +103,15 @@ QVariant AOpticalOverrideScriptInterface::GetNormal() return vl; } +double AOpticalOverrideScriptInterface::GetAngleWithNormal(bool inRadians) +{ + TVector3 N(NormalVector); + TVector3 P(Photon->v); + double angle = N.Angle(P); + if (inRadians) return angle; + else return 180.0/TMath::Pi()*angle; +} + void AOpticalOverrideScriptInterface::SpecularReflection() { double NK = 0; diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index dc585949..904bceef 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -32,6 +32,7 @@ public slots: void TransmissionDirect(); QVariant GetNormal(); + double GetAngleWithNormal(bool inRadians); QVariant GetDirection(); void SetDirection(double vx, double vy, double vz); diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 7369473a..b3347a85 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -4,13 +4,15 @@ #include "amaterialparticlecolection.h" #include "amessage.h" #include "aopticaloverridetester.h" +#include "graphwindowclass.h" +#include "geometrywindowclass.h" #include #include -AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, - int matFrom, int matTo, GraphWindowClass * GraphWindow, QWidget * parent) : - QDialog(parent), ui(new Ui::AOpticalOverrideDialog), GraphWindow(GraphWindow), +AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, int matFrom, int matTo, + GraphWindowClass * GraphWindow, GeometryWindowClass *GeometryWindow, QWidget * parent) : + QDialog(parent), ui(new Ui::AOpticalOverrideDialog), GraphWindow(GraphWindow), GeometryWindow(GeometryWindow), MatCollection(MatCollection), matFrom(matFrom), matTo(matTo), matNames(MatCollection->getListOfMaterialNames()) { ui->setupUi(this); @@ -33,7 +35,7 @@ AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * Mat updateGui(); - TesterWindow = new AOpticalOverrideTester(GraphWindow, MatCollection, matFrom, matTo, this); + TesterWindow = new AOpticalOverrideTester(&ovLocal, GraphWindow, GeometryWindow, MatCollection, matFrom, matTo, this); } AOpticalOverrideDialog::~AOpticalOverrideDialog() diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.h b/src/gui/MainWindowTools/aopticaloverridedialog.h index f14e12be..1ab7544a 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.h +++ b/src/gui/MainWindowTools/aopticaloverridedialog.h @@ -11,6 +11,7 @@ class AOpticalOverrideDialog; class AOpticalOverride; class AMaterialParticleCollection; class GraphWindowClass; +class GeometryWindowClass; class AOpticalOverrideTester; class AOpticalOverrideDialog : public QDialog @@ -18,7 +19,8 @@ class AOpticalOverrideDialog : public QDialog Q_OBJECT public: - explicit AOpticalOverrideDialog(AMaterialParticleCollection* MatCollection, int matFrom, int matTo, GraphWindowClass* GraphWindow, QWidget* parent); + explicit AOpticalOverrideDialog(AMaterialParticleCollection* MatCollection, int matFrom, int matTo, + GraphWindowClass* GraphWindow, GeometryWindowClass* GeometryWindow, QWidget* parent); ~AOpticalOverrideDialog(); private slots: @@ -30,6 +32,7 @@ private slots: private: Ui::AOpticalOverrideDialog * ui; GraphWindowClass * GraphWindow; + GeometryWindowClass* GeometryWindow; AOpticalOverride ** pOV; AOpticalOverride * ovLocal = 0; AMaterialParticleCollection* MatCollection; diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index fed5bc76..40080c7f 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -7,7 +7,9 @@ #include "aphoton.h" #include "atracerstateful.h" #include "graphwindowclass.h" +#include "geometrywindowclass.h" #include "asimulationstatistics.h" +#include "atrackrecords.h" #include #include @@ -19,16 +21,23 @@ #include "TGraph.h" #include "TLegend.h" #include "TMath.h" +#include "TH1D.h" +#include "TGeoManager.h" +#include "TVirtualGeoTrack.h" -AOpticalOverrideTester::AOpticalOverrideTester(GraphWindowClass* GraphWindow, AMaterialParticleCollection* MPcollection, int matFrom, int matTo, QWidget *parent) : +static QVector tracks; +static TVector3 NormViz; + +AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, + GraphWindowClass* GraphWindow, GeometryWindowClass* GeometryWindow, + AMaterialParticleCollection* MPcollection, int matFrom, int matTo, QWidget *parent) : QMainWindow(parent), ui(new Ui::AOpticalOverrideTester), MPcollection(MPcollection), MatFrom(matFrom), MatTo(matTo), - GraphWindow(GraphWindow) + pOV(ovLocal), + GraphWindow(GraphWindow), GeometryWindow(GeometryWindow) { ui->setupUi(this); - ov = (*MPcollection)[matFrom]->OpticalOverrides.at(matTo); - QDoubleValidator* dv = new QDoubleValidator(this); dv->setNotation(QDoubleValidator::ScientificNotation); QList list = this->findChildren(); @@ -56,6 +65,8 @@ void AOpticalOverrideTester::on_pbDirectionHelp_clicked() void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() { + if ( !testOverride() ) return; + int numPhotons = ui->sbST_number->value(); QVector Spike(91, 0), Lobe(91, 0), Diffuse(91, 0), Total(91, 0), Angle; double N[3], K[3]; @@ -85,9 +96,9 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() ph.v[1] = K[1]; ph.v[2] = K[2]; ph.waveIndex = -1; //TODO wave res? - ov->calculate(*Resources, &ph, N); + (*pOV)->calculate(*Resources, &ph, N); - switch (ov->Status) + switch ((*pOV)->Status) { case AOpticalOverride::Absorption: continue; break; case AOpticalOverride::SpikeReflection: Spike[iA]++; break; @@ -129,3 +140,291 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() delete ph.SimStat; } +void AOpticalOverrideTester::on_pbCSMtestmany_clicked() +{ + if ( !testOverride() ) return; + + //surface normal and photon direction + TVector3 SurfNorm(ui->ledST_si->text().toDouble(), + ui->ledST_sj->text().toDouble(), + ui->ledST_sk->text().toDouble()); + SurfNorm = SurfNorm.Unit(); + NormViz = SurfNorm; //visualization of tracks + SurfNorm = - SurfNorm; //In ANTS2 navigator provides normal in the opposite direction + double N[3]; + N[0] = SurfNorm.X(); + N[1] = SurfNorm.Y(); + N[2] = SurfNorm.Z(); + TVector3 PhotDir(ui->ledST_i->text().toDouble(), + ui->ledST_j->text().toDouble(), + ui->ledST_k->text().toDouble()); + PhotDir = PhotDir.Unit(); + + tracks.clear(); + double d = 0.5; //offset - for drawing only + tracks.append(TrackHolderClass(10, kRed)); //incoming photon track + tracks.last().Nodes.append(TrackNodeStruct(d, d ,d, 0)); + tracks.last().Nodes.append(TrackNodeStruct(d-PhotDir.X(), d-PhotDir.Y(), d-PhotDir.Z(), 0)); + + //preparing and running cycle with photons + int abs, spike, lobe, lamb; + abs = spike = lobe = lamb = 0; + TH1D* hist1; + bool fDegrees = ui->cbST_cosToDegrees->isChecked(); + if (fDegrees) hist1 = new TH1D("statScatter", "Angle_scattered", 100, 0, 0); + else hist1 = new TH1D("statScatter", "Cos_scattered", 100, 0, 0); + + APhoton ph; + ph.SimStat = new ASimulationStatistics(); + + for (int i=0; isbST_number->value(); i++) + { + ph.v[0] = PhotDir.X(); //old has output direction after full cycle! + ph.v[1] = PhotDir.Y(); + ph.v[2] = PhotDir.Z(); + ph.waveIndex = -1; + (*pOV)->calculate(*Resources, &ph, N); + + Color_t col; + Int_t type; + if ((*pOV)->Status == AOpticalOverride::Absorption) + { + abs++; + continue; + } + else if ((*pOV)->Status == AOpticalOverride::SpikeReflection) + { + spike++; + type = 0; + col = 6; //0,magenta for Spike + } + else if ((*pOV)->Status == AOpticalOverride::LobeReflection) + { + lobe++; + type = 1; + col = 7; //1,teal for Lobe + } + else if ((*pOV)->Status == AOpticalOverride::LambertianReflection) + { + lamb++; + type = 2; + col = 3; //2,grean for lambert + } + else + { + type = 666; + col = kBlue; //blue for error + } + + tracks.append(TrackHolderClass(type, col)); + tracks.last().Nodes.append(TrackNodeStruct(d,d,d, 0)); + tracks.last().Nodes.append(TrackNodeStruct(d+ph.v[0], d+ph.v[1], d+ph.v[2], 0)); + + double costr = -SurfNorm[0]*ph.v[0] -SurfNorm[1]*ph.v[1] -SurfNorm[2]*ph.v[2]; + + if (fDegrees) hist1->Fill(180.0/3.1415926535*acos(costr)); + else hist1->Fill(costr); + } + + qDebug() << "Here!"; + + //show cos angle hist + GraphWindow->Draw(hist1); + //show tracks + on_pbST_showTracks_clicked(); + //show stat of processes + int sum = abs + spike + lobe + lamb; + QString str = QString::number(abs) + "/" + + QString::number(spike) + "/" + + QString::number(lobe) + "/" + + QString::number(lamb); + if (sum>0) + { + str += " (" + QString::number(1.0*abs/sum, 'g', 3) + "/" + + QString::number(1.0*spike/sum, 'g', 3) + "/" + + QString::number(1.0*lobe/sum, 'g', 3) + "/" + + QString::number(1.0*lamb/sum, 'g', 3) + ")"; + } + ui->leST_out->setText(str); + delete ph.SimStat; +} + +void AOpticalOverrideTester::on_pbST_showTracks_clicked() +{ + if (tracks.isEmpty()) return; + int selector = ui->cobST_trackType->currentIndex() - 1; + if (selector == 3) return; //do not show any tracks + + gGeoManager->ClearTracks(); + GeometryWindow->ClearRootCanvas(); + //showing surface + Int_t track_index = gGeoManager->AddTrack(1,22); + TVirtualGeoTrack* track = gGeoManager->GetTrack(track_index); + double d = 0.5; + double f = 0.5; + + //surface normal + track->AddPoint(d, d, d, 0); + track->AddPoint(d+NormViz.X(), d+NormViz.Y(), d+NormViz.Z(), 0); + track->SetLineWidth(3); + track->SetLineColor(1); + //surf + track_index = gGeoManager->AddTrack(1,22); + track = gGeoManager->GetTrack(track_index); + TVector3 perp = NormViz.Orthogonal(); + perp.Rotate(0.25*3.1415926535, NormViz); + for (int i=0; i<5; i++) + { + track->AddPoint(d+f*perp.X(), d+f*perp.Y(), d+f*perp.Z(), 0); + perp.Rotate(0.5*3.1415926535, NormViz); + } + track->SetLineWidth(2); + track->SetLineColor(1); + + //photon tracks + int numTracks = 0; + for(int i = 1; i-1) //-1 - show all + if (selector != th->UserIndex) continue; + + track_index = gGeoManager->AddTrack(1,22); + track = gGeoManager->GetTrack(track_index); + track->SetLineColor(th->Color); + track->SetLineWidth(1); + for (int iNode=0; iNodeNodes.size(); iNode++) + track->AddPoint(th->Nodes[iNode].R[0], th->Nodes[iNode].R[1], th->Nodes[iNode].R[2], th->Nodes[iNode].Time); + } + //intitial photon track + track_index = gGeoManager->AddTrack(1,22); + track = gGeoManager->GetTrack(track_index); + TrackHolderClass* th = &tracks.first(); + track->SetLineColor(kRed); + track->SetLineWidth(2); + for (int iNode=0; iNodeNodes.size(); iNode++) + track->AddPoint(th->Nodes[iNode].R[0], th->Nodes[iNode].R[1], th->Nodes[iNode].R[2], th->Nodes[iNode].Time); + + GeometryWindow->show(); + GeometryWindow->DrawTracks(); +} + +bool AOpticalOverrideTester::testOverride() +{ + if ( !(*pOV) ) + { + message("Override not defined!", this); + return false; + } + + QString err = (*pOV)->checkOverrideData(); + if (!err.isEmpty()) + { + message("Override reports an error:\n" + err, this); + return false; + } + return true; +} + +void AOpticalOverrideTester::on_pbST_uniform_clicked() +{ + if ( !testOverride() ) return; + + TVector3 SurfNorm(ui->ledST_si->text().toDouble(), + ui->ledST_sj->text().toDouble(), + ui->ledST_sk->text().toDouble()); + SurfNorm = SurfNorm.Unit(); + SurfNorm = - SurfNorm; //In ANTS2 navigator provides normal in the opposite direction + double N[3]; + N[0] = SurfNorm.X(); + N[1] = SurfNorm.Y(); + N[2] = SurfNorm.Z(); + + double K[3]; + + int abs, spike, lobe, lamb; + abs = spike = lobe = lamb = 0; + TH1D* hist1; + bool fDegrees = ui->cbST_cosToDegrees->isChecked(); + if (fDegrees) hist1 = new TH1D("statScatter", "Angle_scattered", 100, 0, 0); + else hist1 = new TH1D("statScatter", "Cos_scattered", 100, 0, 0); + + int num = ui->sbST_number->value(); + + APhoton ph; + ph.SimStat = new ASimulationStatistics(); + + for (int i=0; iRndm(); + double angle = asin(sqrt(sin2angle)); + double yOff = cos(angle), zOff = -sin(angle); + N[0] = 0; N[1] = 0; N[2] = -1; // convention of photon tracer - normal is med1->med2 + K[0] = 0; K[1] = yOff; K[2] = zOff; // -z direction on xy plane (incidence angle from 90 to 0) + + ph.v[0] = K[0]; + ph.v[1] = K[1]; + ph.v[2] = K[2]; + ph.waveIndex = -1; + (*pOV)->calculate(*Resources, &ph, N); + + if ((*pOV)->Status == AOpticalOverride::Absorption) + { + abs++; + continue; + } + else if ((*pOV)->Status == AOpticalOverride::SpikeReflection) + spike++; + else if ((*pOV)->Status == AOpticalOverride::LobeReflection) + lobe++; + else if ((*pOV)->Status == AOpticalOverride::LambertianReflection) + lamb++; + else + { + qCritical()<<"Unknown process!"; + exit(666); + } + + double costr = -N[0]*K[0] -N[1]*K[1] -N[2]*K[2]; // after scatter, K will be in positive Z direction + if (fDegrees) hist1->Fill(180.0/3.1415926535*acos(costr)); + else hist1->Fill(costr); + } + + //show cos angle hist + GraphWindow->Draw(hist1); + + //show stat of processes + int sum = abs + spike + lobe + lamb; + QString str = "Scat probability: "+QString::number(1.0*(sum-abs)/num, 'g', 4) + " Processes:"+ + QString::number(abs) + "/" + + QString::number(spike) + "/" + + QString::number(lobe) + "/" + + QString::number(lamb); + if (sum>0) + { + str += " (" + QString::number(1.0*abs/sum, 'g', 3) + "/" + + QString::number(1.0*spike/sum, 'g', 3) + "/" + + QString::number(1.0*lobe/sum, 'g', 3) + "/" + + QString::number(1.0*lamb/sum, 'g', 3) + ")"; + } + ui->leST_out->setText(str); + delete ph.SimStat; +} + +void AOpticalOverrideTester::on_pbST_AngleCos_clicked() +{ + //vector photon dir + TVector3 ph(ui->ledST_i->text().toDouble(), ui->ledST_j->text().toDouble(), ui->ledST_k->text().toDouble()); + ph = ph.Unit(); + + //vector surface normal + TVector3 surf(-ui->ledST_si->text().toDouble(), -ui->ledST_sj->text().toDouble(), -ui->ledST_sk->text().toDouble()); + surf = surf.Unit(); + + double cos = ph*surf; + double ang = 180.0/3.1415926*acos(cos); + + ui->pbST_AngleCos->setText("Theta="+QString::number(ang, 'g', 3)+" cos="+QString::number(cos, 'g', 3)); +} diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 48fd57ab..3da1de37 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -12,6 +12,7 @@ class AOpticalOverrideTester; class AMaterialParticleCollection; class AOpticalOverride; class GraphWindowClass; +class GeometryWindowClass; class TRandom2; class AOpticalOverrideTester : public QMainWindow @@ -19,7 +20,7 @@ class AOpticalOverrideTester : public QMainWindow Q_OBJECT public: - explicit AOpticalOverrideTester(GraphWindowClass *GraphWindow, AMaterialParticleCollection *MPcollection, int matFrom, int matTo, QWidget *parent = 0); + explicit AOpticalOverrideTester(AOpticalOverride ** ovLocal, GraphWindowClass *GraphWindow, GeometryWindowClass* GeometryWindow, AMaterialParticleCollection *MPcollection, int matFrom, int matTo, QWidget *parent = 0); ~AOpticalOverrideTester(); private slots: @@ -27,15 +28,26 @@ private slots: void on_pbST_RvsAngle_clicked(); + void on_pbCSMtestmany_clicked(); + + void on_pbST_showTracks_clicked(); + + void on_pbST_uniform_clicked(); + + void on_pbST_AngleCos_clicked(); + private: Ui::AOpticalOverrideTester *ui; AMaterialParticleCollection* MPcollection; int MatFrom; int MatTo; - AOpticalOverride* ov; + AOpticalOverride ** pOV; GraphWindowClass* GraphWindow; + GeometryWindowClass* GeometryWindow; TRandom2* RandGen; ATracerStateful* Resources; + + bool testOverride(); }; #endif // AOPTICALOVERRIDETESTER_H diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index bd6b7a94..9cb2c16f 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -7,7 +7,7 @@ 0 0 401 - 478 + 369 @@ -500,96 +500,6 @@ - - - - Qt::Horizontal - - - - - - - - - - 25 - 16777215 - - - - ? - - - - - - - n2, 1.4, 2, 0.05 - - - - - - - Reflection vs parameter - - - - - - - - - - - - Use given photon dir - - - - - Isotropic irradiation - - - - - Diffuse irradiation - - - - - - - - - Show sum reflection - - - - - Show diffuse - - - - - Show spike+lobe - - - - - Show spike - - - - - Show lobe - - - - - - diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 4c5e0b70..167c0737 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -53,6 +53,7 @@ #include "ajavascriptmanager.h" #include "ascriptwindow.h" #include "aremotewindow.h" +#include "aopticaloverridedialog.h" //Qt #include @@ -720,13 +721,12 @@ void MainWindow::on_cbRingsArray_stateChanged(int arg1) ui->sbPMrings->setEnabled(arg1); } -#include "aopticaloverridedialog.h" void MainWindow::on_pbEditOverride_clicked() { int From = ui->cobMaterialForOverrides->currentIndex(); int To = ui->cobMaterialTo->currentIndex(); - AOpticalOverrideDialog d(MpCollection, From, To, GraphWindow, this); + AOpticalOverrideDialog d(MpCollection, From, To, GraphWindow, GeometryWindow, this); int res = d.exec(); if (res == 1) { From 4e28f2d704273db378c73000c9851eb02194bfe7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 3 Oct 2018 21:53:11 +0100 Subject: [PATCH 038/140] ++ --- src/gui/MainWindowTools/MainWindowTests.cpp | 689 -------- src/gui/mainwindow.h | 8 - src/gui/mainwindow.ui | 1552 ++----------------- 3 files changed, 159 insertions(+), 2090 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowTests.cpp b/src/gui/MainWindowTools/MainWindowTests.cpp index c0b875f2..a4488243 100644 --- a/src/gui/MainWindowTools/MainWindowTests.cpp +++ b/src/gui/MainWindowTools/MainWindowTests.cpp @@ -9,19 +9,11 @@ #include "eventsdataclass.h" #include "graphwindowclass.h" #include "globalsettingsclass.h" -#include "scatteronmetal.h" -#include "phscatclaudiomodel.h" #include "geometrywindowclass.h" -#include "aphoton.h" #include "acompton.h" -#include "atrackrecords.h" #include "aenergydepositioncell.h" #include "amessage.h" -#include "atracerstateful.h" -#include "TVirtualGeoTrack.h" -#include "TLegend.h" -#include "TGeoManager.h" #include "TMath.h" #include "TGraph.h" #include "TH1D.h" @@ -32,15 +24,10 @@ #include #include -static QVector tracks; -static TVector3 NormViz; - //#include "TBufferJSON.h" //#include "tmpobjhubclass.h" //#include "TAttMarker.h" -//#include "TH1D.h" -//#include "TGraph.h" void MainWindow::on_pobTest_clicked() { // double tau1 = 100.0; @@ -230,682 +217,6 @@ void MainWindow::on_pobTest_2_clicked() } */ -void MainWindow::on_pbST_AngleCos_clicked() -{ - //vector photon dir - TVector3 ph(ui->ledST_i->text().toDouble(), ui->ledST_j->text().toDouble(), ui->ledST_k->text().toDouble()); - ph = ph.Unit(); - - //vector surface normal - TVector3 surf(-ui->ledST_si->text().toDouble(), -ui->ledST_sj->text().toDouble(), -ui->ledST_sk->text().toDouble()); - surf = surf.Unit(); - - double cos = ph*surf; - double ang = 180.0/3.1415926*acos(cos); - - ui->pbST_AngleCos->setText("Theta="+QString::number(ang, 'g', 3)+" cos="+QString::number(cos, 'g', 3)); -} - -AOpticalOverride* InitOverride(Ui::MainWindow *ui, AMaterialParticleCollection& MatCol) -{ - MatCol.AddNewMaterial(true); - MatCol.AddNewMaterial(true); - MatCol[0]->n = ui->ledST_Ref1->text().toDouble(); - MatCol[1]->n = ui->ledST_Ref2->text().toDouble(); - double wave = ui->ledST_wave->text().toDouble(); - MatCol.SetWave(false, wave, wave, 0, 1); //conversion of iWave=-1 to wavelength will give wave - - if (ui->cobOverrideTesterModel->currentIndex() == 0) - { - //Claudio's model - PhScatClaudioModel* sc; - switch (ui->cobST_ClaudioModelVersion->currentIndex()) - { - case 0: - sc = new PhScatClaudioModelV2d2(&MatCol, 0, 1); - break; - case 1: - sc = new PhScatClaudioModelV2d1(&MatCol, 0, 1); - break; - case 2: - sc = new PhScatClaudioModelV2(&MatCol, 0, 1); - break; - default: - message("Unexpected scattering model index"); - exit(666); - } - - sc->sigma_alpha = ui->ledST_SigmaAlpha->text().toDouble(); - sc->sigma_h = ui->ledST_SigmaSpike->text().toDouble(); - sc->albedo = ui->ledST_albedo->text().toDouble(); - - switch(ui->conST_heightModel->currentIndex()) - { - case 0: sc->HeightDistribution = empirical; break; - case 1: sc->HeightDistribution = gaussian; break; - case 2: sc->HeightDistribution = exponential; break; - default: exit(-123); - } - switch(ui->cobST_slopeModel->currentIndex()) - { - case 0: sc->SlopeDistribution = trowbridgereitz; break; - case 1: sc->SlopeDistribution = cooktorrance; break; - case 2: sc->SlopeDistribution = bivariatecauchy; break; - default: exit(-123); - } - return sc; - } - else if (ui->cobOverrideTesterModel->currentIndex() == 1) - { - //DielectricToMetal model - ScatterOnMetal* sm = new ScatterOnMetal(&MatCol, 0, 1); - sm->RealN = ui->ledST_Ref2->text().toDouble(); - sm->ImaginaryN = ui->ledImNAfter->text().toDouble(); - return sm; - } - else - { - //FS_NP (Former Neves) model - FSNPOpticalOverride* nm = new FSNPOpticalOverride(&MatCol, 0, 1); - nm->Albedo = ui->ledST_AlbedoNeves->text().toDouble(); - return nm; - } -} - -void MainWindow::on_pbCSMtestmany_clicked() -{ - // Have to create a fake material collection with two materials - // to provide refractive indices and iwave->wavelength conversion to the override class - AMaterialParticleCollection MatCol; - //creating and filling override object and this fake material collection - AOpticalOverride* ov = InitOverride(ui, MatCol); - - //surface normal and photon direction - TVector3 SurfNorm(ui->ledST_si->text().toDouble(), - ui->ledST_sj->text().toDouble(), - ui->ledST_sk->text().toDouble()); - SurfNorm = SurfNorm.Unit(); - NormViz = SurfNorm; //visualization of tracks - SurfNorm = - SurfNorm; //In ANTS2 navigator provides normal in the opposite direction - double N[3]; - N[0] = SurfNorm.X(); - N[1] = SurfNorm.Y(); - N[2] = SurfNorm.Z(); - TVector3 PhotDir(ui->ledST_i->text().toDouble(), - ui->ledST_j->text().toDouble(), - ui->ledST_k->text().toDouble()); - PhotDir = PhotDir.Unit(); - //double K[3]; - - //other inits - tracks.clear(); - double d = 0.5; //offset - for drawing only - tracks.append(TrackHolderClass(10, kRed)); //incoming photon track - tracks.last().Nodes.append(TrackNodeStruct(d, d ,d, 0)); - tracks.last().Nodes.append(TrackNodeStruct(d-PhotDir.X(), d-PhotDir.Y(), d-PhotDir.Z(), 0)); - - //preparing and running cycle with photons - int abs, spike, lobe, lamb; - abs = spike = lobe = lamb = 0; - TH1D* hist1; - bool fDegrees = ui->cbST_cosToDegrees->isChecked(); - if (fDegrees) hist1 = new TH1D("statScatter", "Angle_scattered", 100, 0, 0); - else hist1 = new TH1D("statScatter", "Cos_scattered", 100, 0, 0); - - APhoton ph; - ph.SimStat = new ASimulationStatistics(); - - ATracerStateful Resources(Detector->RandGen); - for (int i=0; isbST_number->value(); i++) - { - ph.v[0] = PhotDir.X(); //old has output direction after full cycle! - ph.v[1] = PhotDir.Y(); - ph.v[2] = PhotDir.Z(); - ph.waveIndex = -1; - ov->calculate(Resources, &ph, N); - - Color_t col; - Int_t type; - if (ov->Status == AOpticalOverride::Absorption) - { - abs++; - continue; - } - else if (ov->Status == AOpticalOverride::SpikeReflection) - { - spike++; - type = 0; - col = 6; //0,magenta for Spike - } - else if (ov->Status == AOpticalOverride::LobeReflection) - { - lobe++; - type = 1; - col = 7; //1,teal for Lobe - } - else if (ov->Status == AOpticalOverride::LambertianReflection) - { - lamb++; - type = 2; - col = 3; //2,grean for lambert - } - else - { - type = 666; - col = kBlue; //blue for error - } - - tracks.append(TrackHolderClass(type, col)); - tracks.last().Nodes.append(TrackNodeStruct(d,d,d, 0)); - tracks.last().Nodes.append(TrackNodeStruct(d+ph.v[0], d+ph.v[1], d+ph.v[2], 0)); - - double costr = -SurfNorm[0]*ph.v[0] -SurfNorm[1]*ph.v[1] -SurfNorm[2]*ph.v[2]; - - if (fDegrees) hist1->Fill(180.0/3.1415926535*acos(costr)); - else hist1->Fill(costr); - } - //show cos angle hist - GraphWindow->Draw(hist1); - //show tracks - MainWindow::on_pbST_showTracks_clicked(); - //show stat of processes - int sum = abs + spike + lobe + lamb; - QString str = QString::number(abs) + "/" + - QString::number(spike) + "/" + - QString::number(lobe) + "/" + - QString::number(lamb); - if (sum>0) - { - str += " (" + QString::number(1.0*abs/sum, 'g', 3) + "/" + - QString::number(1.0*spike/sum, 'g', 3) + "/" + - QString::number(1.0*lobe/sum, 'g', 3) + "/" + - QString::number(1.0*lamb/sum, 'g', 3) + ")"; - } - ui->leST_out->setText(str); - delete ov; - delete ph.SimStat; -} - -void MainWindow::on_pbST_uniform_clicked() -{ - // Have to create a fake material collection with two materials - // to provide refractive indices and iwave->wavelength conversion to the override class - AMaterialParticleCollection MatCol; - //creating and filling override object and this fake material collection - AOpticalOverride* ov = InitOverride(ui, MatCol); - - TVector3 SurfNorm(ui->ledST_si->text().toDouble(), - ui->ledST_sj->text().toDouble(), - ui->ledST_sk->text().toDouble()); - SurfNorm = SurfNorm.Unit(); - SurfNorm = - SurfNorm; //In ANTS2 navigator provides normal in the opposite direction - double N[3]; - N[0] = SurfNorm.X(); - N[1] = SurfNorm.Y(); - N[2] = SurfNorm.Z(); - - //TVector3 PhotDir(ui->ledST_i->text().toDouble(), - // ui->ledST_j->text().toDouble(), - // ui->ledST_k->text().toDouble()); - //PhotDir = PhotDir.Unit(); - double K[3]; - - int abs, spike, lobe, lamb; - abs = spike = lobe = lamb = 0; - TH1D* hist1; - bool fDegrees = ui->cbST_cosToDegrees->isChecked(); - if (fDegrees) hist1 = new TH1D("statScatter", "Angle_scattered", 100, 0, 0); - else hist1 = new TH1D("statScatter", "Cos_scattered", 100, 0, 0); - - int num = ui->sbST_number->value(); - - APhoton ph; - ph.SimStat = new ASimulationStatistics(); - - ATracerStateful Resources(Detector->RandGen); - for (int i=0; iRandGen->Rndm(); - double angle = asin(sqrt(sin2angle)); - double yOff = cos(angle), zOff = -sin(angle); - N[0] = 0; N[1] = 0; N[2] = -1; // convention of photon tracer - normal is med1->med2 - K[0] = 0; K[1] = yOff; K[2] = zOff; // -z direction on xy plane (incidence angle from 90 to 0) - - - ph.v[0] = K[0]; - ph.v[1] = K[1]; - ph.v[2] = K[2]; - ph.waveIndex = -1; - ov->calculate(Resources, &ph, N); - - if (ov->Status == AOpticalOverride::Absorption) - { - abs++; - continue; - } - else if (ov->Status == AOpticalOverride::SpikeReflection) - spike++; - else if (ov->Status == AOpticalOverride::LobeReflection) - lobe++; - else if (ov->Status == AOpticalOverride::LambertianReflection) - lamb++; - else - { - qCritical()<<"Unknown process!"; - exit(666); - } - - double costr = -N[0]*K[0] -N[1]*K[1] -N[2]*K[2]; // after scatter, K will be in positive Z direction - if (fDegrees) hist1->Fill(180.0/3.1415926535*acos(costr)); - else hist1->Fill(costr); - } - - //show cos angle hist - GraphWindow->Draw(hist1); - - //show stat of processes - int sum = abs + spike + lobe + lamb; - QString str = "Scat probability: "+QString::number(1.0*(sum-abs)/num, 'g', 4) + " Processes:"+ - QString::number(abs) + "/" + - QString::number(spike) + "/" + - QString::number(lobe) + "/" + - QString::number(lamb); - if (sum>0) - { - str += " (" + QString::number(1.0*abs/sum, 'g', 3) + "/" + - QString::number(1.0*spike/sum, 'g', 3) + "/" + - QString::number(1.0*lobe/sum, 'g', 3) + "/" + - QString::number(1.0*lamb/sum, 'g', 3) + ")"; - } - ui->leST_out->setText(str); - delete ov; - delete ph.SimStat; -} - -void MainWindow::on_pbST_RvsAngle_clicked() -{ - // Have to create a fake material collection with two materials - // to provide refractive indices and iwave->wavelength conversion to the override class - AMaterialParticleCollection MatCol; - //creating and filling override object and this fake material collection - AOpticalOverride* ov = InitOverride(ui, MatCol); - - int num = ui->sbST_number->value(); - QVector Spike(91, 0), Lobe(91, 0), Diffuse(91, 0), Total(91, 0), Angle; - double N[3], K[3]; - N[0] = 0; - N[1] = 0; - N[2] = 1.0; - - APhoton ph; - ph.SimStat = new ASimulationStatistics(); - - ATracerStateful Resources(Detector->RandGen); - for (int iA=0; iA<91; iA++) //cycle by angle of incidence - { - double angle = iA; - if (angle == 90) angle = 89.9; - Angle.append(angle); - //angle->photon direction - double cosA = cos(3.1415926535*angle/180.0); - double sinA = sin(3.1415926535*angle/180.0); - for (int i=0; icalculate(Resources, &ph, N); - - switch (ov->Status) - { - case AOpticalOverride::Absorption: continue; break; - case AOpticalOverride::SpikeReflection: Spike[iA]++; break; - case AOpticalOverride::LobeReflection: Lobe[iA]++; break; - case AOpticalOverride::LambertianReflection: Diffuse[iA]++; break; - default: - qCritical()<<"Unknown process!"; - exit(666); - } - } - Spike[iA] /= num; - Lobe[iA] /= num; - Diffuse[iA] /= num; - Total[iA] = Spike[iA]+Lobe[iA]+Diffuse[iA]; - } - - TGraph *gS, *gL, *gD, *gT; - gT = GraphWindow->MakeGraph(&Angle, &Total, 2, "Angle", "", 0, 1, 1, 2, "", true); - gT->SetMinimum(0); - gT->SetTitle("Total"); - gS = GraphWindow->MakeGraph(&Angle, &Spike, 1, "Angle", "", 0, 1, 1, 1, "", true); - gS->SetTitle("Spike"); - gL = GraphWindow->MakeGraph(&Angle, &Lobe, 3, "Angle", "", 0, 1, 1, 1, "", true); - gL->SetTitle("Lobe"); - gD = GraphWindow->MakeGraph(&Angle, &Diffuse, 4, "Angle", "", 0, 1, 1, 1, "", true); - gD->SetTitle("Diffuse"); - - GraphWindow->Draw(gT, "AL"); - GraphWindow->Draw(gS, "Lsame"); - GraphWindow->Draw(gL, "Lsame"); - GraphWindow->Draw(gD, "Lsame"); - - TLegend *leg = new TLegend(0.1, 0.7, 0.3, 0.9); - leg->SetFillColor(0); - //leg->SetHeader("test legend"); - leg->AddEntry(gT, "Total", "lp"); - leg->AddEntry(gS, "Spike", "lp"); - leg->AddEntry(gL, "Lobe", "lp"); - leg->AddEntry(gD, "Diffuse", "lp"); - GraphWindow->Draw(leg, "same"); - - delete ov; - delete ph.SimStat; -} - -static QVector vParam, vTot, vSpike, vLobe, vDiff, vDir; -static QString parName; -void MainWindow::on_pbST_ReflectionVsParameter_clicked() -{ - ATracerStateful Resources(Detector->RandGen); - //input string processing - QString inS = ui->leST_Parameter->text().simplified(); - QStringList inL = inS.split(",", QString::SkipEmptyParts); - qDebug() << inL.size()< parameters; - //============== list of parameter names ============== - parameters << "n1" << "n2" << "alb" << "sigA" << "sigS" << "k2"; - parName = inL[0]; - if (!parameters.contains(parName)) - { - QString str; - for (int i=0; ito) - { - message("From is larger than To!", this); - return; - } - qDebug() << from << to << step; - int steps = (to-from)/step; - qDebug() << "Steps:"<wavelength conversion to the override class - AMaterialParticleCollection MatCol; - //creating and filling override object and this fake material collection - AOpticalOverride* ov = InitOverride(ui, MatCol); - - PhScatClaudioModel* ClaudMod = dynamic_cast(ov); - ScatterOnMetal* ScatOnMet = dynamic_cast(ov); - - TVector3 SurfNorm(ui->ledST_si->text().toDouble(), - ui->ledST_sj->text().toDouble(), - ui->ledST_sk->text().toDouble()); - SurfNorm = SurfNorm.Unit(); - SurfNorm = - SurfNorm; //In ANTS2 navigator provides normal in the opposite direction - double N[3]; - N[0] = SurfNorm.X(); - N[1] = SurfNorm.Y(); - N[2] = SurfNorm.Z(); - TVector3 PhotDir(ui->ledST_i->text().toDouble(), - ui->ledST_j->text().toDouble(), - ui->ledST_k->text().toDouble()); - PhotDir = PhotDir.Unit(); - double K[3]; - - int num = ui->sbST_number->value(); - vParam.clear(); - vSpike.clear(); - vLobe.clear(); - vTot.clear(); - vDiff.clear(); - vDir.clear(); - - APhoton ph; - ph.SimStat = new ASimulationStatistics(); - - for (int iS = 0; iSn = parVal; - else if (parName == "n2") - { - MatCol[1]->n = parVal; - if (ScatOnMet) ScatOnMet->RealN = parVal; - } - else if (parName == "alb") - { - if (ClaudMod) ClaudMod->albedo = parVal; - } - else if (parName == "sigA") - { - if (ClaudMod) ClaudMod->sigma_alpha = parVal; - } - else if (parName == "sigS") - { - if (ClaudMod) ClaudMod->sigma_h = parVal; - } - else if (parName == "k2") - { - if (ScatOnMet) ScatOnMet->ImaginaryN = parVal; - } - - for (int iphot=0; iphotcobST_PhotDirIso->currentIndex() ) - { - case 0: //given direction - K[0] = PhotDir.X(); - K[1] = PhotDir.Y(); - K[2] = PhotDir.Z(); - break; - case 1: //uniform distr - { - double a=0, b=0, r2=1; - while (r2 > 0.25) - { - a = Detector->RandGen->Rndm() - 0.5; - b = Detector->RandGen->Rndm() - 0.5; - r2 = a*a + b*b; - } - K[2] = ( -1.0 + 8.0 * r2 ); - double scale = 8.0 * TMath::Sqrt(0.25 - r2); - K[0] = a*scale; - K[1] = b*scale; - //accept only in the same direction (2Pi) as the normal of the surface (normal is already inverted - it points to the second material) - if (K[0]*N[0]+K[1]*N[1]+K[2]*N[2]<0) - { - K[0]=-K[0]; - K[1]=-K[1]; - K[2]=-K[2]; - } - break; - } - case 2: //diffuse (lambertian) distr - { - double sin2angle = Detector->RandGen->Rndm(); - double angle = asin(sqrt(sin2angle)); - double yOff = cos(angle), zOff = -sin(angle); - N[0] = 0; N[1] = 0; N[2] = -1; // convention of photon tracer - normal is med1->med2 - K[0] = 0; K[1] = yOff; K[2] = zOff; // -z direction on xy plane (incidence angle from 90 to 0) - break; - } - default: - message("Unknown type of photon irradiation!", this); - return; - } - - ph.v[0] = K[0]; - ph.v[1] = K[1]; - ph.v[2] = K[2]; - ph.waveIndex = -1; - ov->calculate(Resources, &ph, N); - - switch (ov->Status) - { - case AOpticalOverride::Absorption: continue; - case AOpticalOverride::SpikeReflection: vSpike[iS]++; vDir[iS]++; break; - case AOpticalOverride::LobeReflection: vLobe[iS]++; vDir[iS]++; break; - case AOpticalOverride::LambertianReflection: vDiff[iS]++; break; - default: - qCritical()<<"Unknown process!"; - exit(666); - } - vTot[iS]++; - } //end cycle by photons - vSpike.last() /= num; - vDir.last() /= num; - vLobe.last() /= num; - vDiff.last() /= num; - vTot.last() /= num; - } //end cycle by parameter steps - - on_cobST_ShowWhatRef_activated(ui->cobST_ShowWhatRef->currentIndex()); - - delete ov; - delete ph.SimStat; -} - -void MainWindow::on_pbST_VsParameterHelp_clicked() -{ - QString str = - "Format: Parameter_name, StartValue, EndValue, Step\n" - "Parameter names:\n" - "sigA - SigmaAlpha\n" - "sigS - SigmaSpike\n" - "alb - albedo\n" - "n1 - Refractive index 1\n" - "n2 - Refractive index 2\n" - "k2 - Imaginary part of refractive index 2\n"; - message(str, this); -} - -void MainWindow::on_cobST_ShowWhatRef_activated(int index) -{ - switch (index) - { - case 0: - GraphWindow->MakeGraph(&vParam, &vTot, 4, parName.toLocal8Bit().data(), "Sum reflectivity", 20, 1, 1, 1); - break; - case 1: - GraphWindow->MakeGraph(&vParam, &vDiff, 4, parName.toLocal8Bit().data(), "Diffuse reflectivity", 20, 1, 1, 1); - break; - case 2: - GraphWindow->MakeGraph(&vParam, &vDir, 4, parName.toLocal8Bit().data(), "Directed reflectivity", 20, 1, 1, 1); - break; - case 3: - GraphWindow->MakeGraph(&vParam, &vSpike, 4, parName.toLocal8Bit().data(), "Spike reflectivity", 20, 1, 1, 1); - break; - case 4: - GraphWindow->MakeGraph(&vParam, &vLobe, 4, parName.toLocal8Bit().data(), "Lobe reflectivity", 20, 1, 1, 1); - break; - default:; - } -} - -void MainWindow::on_pbST_showTracks_clicked() -{ - if (tracks.isEmpty()) return; - int selector = ui->cobST_trackType->currentIndex() - 1; - if (selector == 3) return; //do not show any tracks - - Detector->GeoManager->ClearTracks(); - GeometryWindow->ClearRootCanvas(); - //showing surface - Int_t track_index = Detector->GeoManager->AddTrack(1,22); - TVirtualGeoTrack* track = Detector->GeoManager->GetTrack(track_index); - double d = 0.5; - double f = 0.5; - - //surface normal - track->AddPoint(d, d, d, 0); - track->AddPoint(d+NormViz.X(), d+NormViz.Y(), d+NormViz.Z(), 0); - track->SetLineWidth(3); - track->SetLineColor(1); - //surf - track_index = Detector->GeoManager->AddTrack(1,22); - track = Detector->GeoManager->GetTrack(track_index); - TVector3 perp = NormViz.Orthogonal(); - perp.Rotate(0.25*3.1415926535, NormViz); - for (int i=0; i<5; i++) - { - track->AddPoint(d+f*perp.X(), d+f*perp.Y(), d+f*perp.Z(), 0); - perp.Rotate(0.5*3.1415926535, NormViz); - } - track->SetLineWidth(2); - track->SetLineColor(1); - - //photon tracks - int numTracks = 0; - for(int i = 1; i-1) //-1 - show all - if (selector != th->UserIndex) continue; - - track_index = Detector->GeoManager->AddTrack(1,22); - track = Detector->GeoManager->GetTrack(track_index); - track->SetLineColor(th->Color); - track->SetLineWidth(1); - for (int iNode=0; iNodeNodes.size(); iNode++) - track->AddPoint(th->Nodes[iNode].R[0], th->Nodes[iNode].R[1], th->Nodes[iNode].R[2], th->Nodes[iNode].Time); - } - //intitial photon track - track_index = Detector->GeoManager->AddTrack(1,22); - track = Detector->GeoManager->GetTrack(track_index); - TrackHolderClass* th = &tracks.first(); - track->SetLineColor(kRed); - track->SetLineWidth(2); - for (int iNode=0; iNodeNodes.size(); iNode++) - track->AddPoint(th->Nodes[iNode].R[0], th->Nodes[iNode].R[1], th->Nodes[iNode].R[2], th->Nodes[iNode].Time); - - GeometryWindow->show(); - ShowTracks(); -} - void MainWindow::on_pbShowComptonAngles_clicked() { int Maxi = ui->sbTmp->value(); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index d731974e..e4b1349b 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -549,14 +549,6 @@ private slots: void on_cobLoadDataType_customContextMenuRequested(const QPoint &pos); void on_pbManuscriptExtractNames_clicked(); void on_pbShowDetailedLog_clicked(); - void on_pbCSMtestmany_clicked(); - void on_pbST_showTracks_clicked(); - void on_pbST_AngleCos_clicked(); - void on_pbST_uniform_clicked(); - void on_pbST_RvsAngle_clicked(); - void on_pbST_ReflectionVsParameter_clicked(); - void on_pbST_VsParameterHelp_clicked(); - void on_cobST_ShowWhatRef_activated(int index); void on_actionGlobal_script_triggered(); void on_pbLockGui_clicked(); void on_pbUnlockGui_clicked(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index f2937265..fda7bc0a 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 3 + 0 @@ -12760,7 +12760,7 @@ multiply to loaded data - 1 + 2 @@ -12885,1294 +12885,172 @@ multiply to loaded data 338 32 121 - 16 - - - - Disabled = not defined - - - - - - 237 - 22 - 75 - 23 - - - - Update - - - - - - 80 - 80 - 121 - 16 - - - - Test photon generator: - - - - - - 200 - 78 - 81 - 22 - - - - 1 - - - 100000000 - - - - - - 400 - 78 - 101 - 21 - - - - Secondary - - - - - - 290 - 78 - 101 - 21 - - - - Primary - - - - - - 10 - 99 - 494 - 16 - - - - Qt::Horizontal - - - - - - 50 - 110 - 141 - 16 - - - - Refractive index (rebinned): - - - - - - 70 - 130 - 75 - 23 - - - - Show - - - - - - 340 - 130 - 75 - 23 - - - - Show - - - - - - 290 - 110 - 181 - 16 - - - - Attenuation coefficient (rebinned): - - - - - - - 20 - 100 - 491 - 16 - - - - Qt::Horizontal - - - - - - 20 - 390 - 491 - 16 - - - - Qt::Horizontal - - - - - - Overrides - - - - - 3 - 4 - 518 - 450 - - - - Optical override tester - - - - - 140 - 179 - 40 - 20 - - - - 1 - - - - - - 122 - 181 - 12 - 16 - - - - i: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - -9 - 179 - 110 - 16 - - - - Can be any values: Unitary vector is calculated automatically - - - Photon direction: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 210 - 179 - 40 - 20 - - - - 0 - - - - - - 193 - 181 - 12 - 16 - - - - j: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 280 - 179 - 40 - 20 - - - - 1 - - - - - - 261 - 180 - 15 - 16 - - - - k: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 20 - 242 - 231 - 23 - - - - - 75 - true - - - - Trace photons - - - - - - 13 - 273 - 331 - 16 - - - - Absorption/Spike/Lobe/Lambert: counts and fractions - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 21 - 293 - 481 - 20 - - - - - - - 20 - 317 - 131 - 23 - - - - Show tracks - - - - - - 160 - 318 - 151 - 22 - - - - - All tracks - - - - - Only Spike - - - - - Only Lobe - - - - - Only Lamb - - - - - None - - - - - - - 90 - 328 - 118 - 3 - - - - QFrame::Plain - - - Qt::Horizontal - - - - - - 330 - 320 - 161 - 17 - - - - Histogram: cos to degrees - - - true - - - - - - 10 - 470 - 490 - 3 - - - - Qt::Horizontal - - - - - - 10 - 150 - 490 - 3 - - - - Qt::Horizontal - - - - - - 122 - 159 - 12 - 16 - - - - i: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 210 - 157 - 40 - 20 - - - - 0 - - - - - - -9 - 159 - 110 - 16 - - - - Can be any values: Unitary vector is calculated automatically - - - Surface normal: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 280 - 157 - 40 - 20 - - - - -1 - - - - - - 140 - 157 - 40 - 20 - - - - 0 - - - - - - 261 - 158 - 15 - 16 - - - - k: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 193 - 159 - 12 - 16 - - - - j: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 330 - 157 - 3 - 42 - - - - Qt::Vertical - - - - - - 339 - 166 - 164 - 23 - - - - Theta=45 cos=0.707 - - - - - - 280 - 242 - 231 - 23 - - - - Lambertian distribution for incoming photons! - - - Diffuse irradiation test - - - - - - 270 - 360 - 240 - 23 - - - - Reflection vs parameter - - - - - - 120 - 400 - 201 - 20 - - - - n2, 1.4, 2, 0.05 - - - - - - 320 - 399 - 21 - 23 - - - - ? - - - - - - 360 - 370 - 5 - 60 - - - - QFrame::Plain - - - Qt::Vertical - - - - - - 141 - 206 - 81 - 22 - - - - 1000000 - - - 1000 - - - - - - 46 - 208 - 90 - 17 - - - - Use photons: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 12 - 230 - 490 - 10 - - - - QFrame::Sunken - - - 1 - - - Qt::Horizontal - - - - - - 10 - 350 - 490 - 3 - - - - Qt::Horizontal - - - - - - 20 - 360 - 230 - 23 - - - - - 75 - true - - - - Reflection vs angle of incidence - - - - - - 350 - 390 - 158 - 22 - - - - - Use given photon dir - - - - - Isotropic irradiation - - - - - Diffuse irradiation - - - - - - - 350 - 420 - 158 - 22 - - - - - Show sum reflection - - - - - Show diffuse - - - - - Show spike+lobe - - - - - Show spike - - - - - Show lobe - - - - - - - 300 - 377 - 5 - 30 - - - - QFrame::Plain - - - Qt::Vertical - - - - - - 195 - 11 - 161 - 22 - - - - - Claudio's - - - - - DielectricToMetal - - - - - FS_NP - - - - - - - 142 - 15 - 47 - 13 - - - - Model: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 10 - 37 - 499 - 76 - - - - QFrame::Box - - - 0 - - - - - - 326 - 3 - 131 - 22 - - - - - empirical - - - - - gauss - - - - - exponential - - - - - - - 0 - 4 - 87 - 16 - - - - sigmaAlpha: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 161 - 6 - 161 - 20 - - - - Height distribution model: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 160 - 27 - 161 - 20 - - - - Slope distribution model: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 326 - 26 - 131 - 22 - - - - - trowbridgereitz - - - - - cooktorrance - - - - - bivariatecauchy - - - - - - - 90 - 4 - 71 - 20 - - - - 0.18 - - - - - - 2 - 25 - 83 - 16 - - - - sigmaSpike: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 90 - 24 - 71 - 20 - - - - 1 - - - - - - 2 - 45 - 83 - 16 - - - - albedo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 90 - 44 - 71 - 20 - - - - 0.97 - - - - - - 326 - 49 - 131 - 22 - - - - - V2.2 - - - - - V2.1 - - - - - V2 - - - - - - - 220 - 48 - 100 - 20 - - - - - 75 - true - - - - Model version: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 27 - 26 - 320 - 20 - - - - Imaginary part of refractive index after the interface: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 350 - 27 - 60 - 20 - - - - 0.6 - - - - - - - - 184 - 28 - 61 - 16 - - - - Albedo: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 254 - 27 - 71 - 20 - - - - 0.95 - - - + 16 + + + + Disabled = not defined + - + - 494 - 124 - 47 - 13 + 237 + 22 + 75 + 23 - nm + Update - + - 324 - 121 + 80 + 80 121 16 - Photon wavelength: + Test photon generator: - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + 200 + 78 + 81 + 22 + + + + 1 + + + 100000000 - + - 449 - 121 - 41 - 20 + 400 + 78 + 101 + 21 - 176 + Secondary - + - 113 - 121 - 50 - 20 + 290 + 78 + 101 + 21 - 1.69 + Primary - + - 8 - 122 - 102 + 10 + 99 + 494 16 - - Refr index before: + + Qt::Horizontal - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + 50 + 110 + 141 + 16 + + + + Refractive index (rebinned): - + - 260 - 121 - 50 - 20 + 70 + 130 + 75 + 23 - 1.66 + Show - + - 156 - 121 - 101 - 20 + 340 + 130 + 75 + 23 - Refr index after: + Show - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + 290 + 110 + 181 + 16 + + + + Attenuation coefficient (rebinned): - line_68 - line_52 - line_53 - ledST_i - label_298 - label_299 - ledST_j - label_300 - ledST_k - label_301 - pbCSMtestmany - label_50 - leST_out - pbST_showTracks - cobST_trackType - cbST_cosToDegrees - line_54 - line_55 - label_308 - ledST_sj - label_309 - ledST_sk - ledST_si - label_310 - label_311 - line_58 - pbST_AngleCos - pbST_uniform - pbST_ReflectionVsParameter - leST_Parameter - pbST_VsParameterHelp - sbST_number - label_136 - line_65 - line_66 - pbST_RvsAngle - cobST_PhotDirIso - cobST_ShowWhatRef - cobOverrideTesterModel - label_282 - stackedWidget_3 - label_267 - label_307 - ledST_wave - ledST_Ref1 - label_303 - ledST_Ref2 - label_304 + + + + + 20 + 100 + 491 + 16 + + + + Qt::Horizontal + + + + + + 20 + 390 + 491 + 16 + + + + Qt::Horizontal + @@ -15487,8 +14365,8 @@ on stack click() - 226 - 540 + 224 + 518 280 @@ -16399,8 +15277,8 @@ on stack click() - 295 - 382 + 293 + 360 467 @@ -16415,8 +15293,8 @@ on stack click() - 181 - 474 + 179 + 452 460 @@ -16431,8 +15309,8 @@ on stack click() - 443 - 443 + 441 + 421 447 @@ -16447,8 +15325,8 @@ on stack click() - 443 - 472 + 441 + 450 500 @@ -16463,8 +15341,8 @@ on stack click() - 443 - 472 + 441 + 450 502 @@ -16479,8 +15357,8 @@ on stack click() - 295 - 382 + 293 + 360 464 @@ -16495,8 +15373,8 @@ on stack click() - 165 - 382 + 163 + 360 464 @@ -16511,8 +15389,8 @@ on stack click() - 319 - 442 + 317 + 420 510 @@ -16579,8 +15457,8 @@ on stack 102 - 422 - 118 + 426 + 180 @@ -16591,12 +15469,12 @@ on stack click() - 499 - 186 + 503 + 251 - 457 - 118 + 461 + 180 @@ -18143,8 +17021,8 @@ on stack setCurrentIndex(int) - 181 - 474 + 179 + 452 310 @@ -18175,8 +17053,8 @@ on stack click() - 251 - 472 + 249 + 450 498 @@ -18191,8 +17069,8 @@ on stack click() - 235 - 458 + 233 + 436 485 @@ -18207,8 +17085,8 @@ on stack click() - 235 - 496 + 233 + 474 499 @@ -18239,8 +17117,8 @@ on stack click() - 170 - 382 + 174 + 360 424 @@ -18255,8 +17133,8 @@ on stack setCurrentIndex(int) - 233 - 442 + 237 + 420 427 @@ -18271,8 +17149,8 @@ on stack click() - 392 - 479 + 390 + 457 486 @@ -18287,8 +17165,8 @@ on stack click() - 241 - 442 + 239 + 420 443 @@ -18440,118 +17318,6 @@ on stack - - ledST_si - editingFinished() - pbST_AngleCos - click() - - - 191 - 264 - - - 418 - 254 - - - - - ledST_sj - editingFinished() - pbST_AngleCos - click() - - - 261 - 264 - - - 448 - 254 - - - - - ledST_i - editingFinished() - pbST_AngleCos - click() - - - 191 - 286 - - - 420 - 254 - - - - - ledST_j - editingFinished() - pbST_AngleCos - click() - - - 261 - 286 - - - 420 - 254 - - - - - ledST_sk - editingFinished() - pbST_AngleCos - click() - - - 331 - 264 - - - 403 - 254 - - - - - cobOverrideTesterModel - activated(int) - stackedWidget_3 - setCurrentIndex(int) - - - 316 - 120 - - - 267 - 128 - - - - - ledST_k - editingFinished() - pbST_AngleCos - click() - - - 331 - 286 - - - 447 - 254 - - - cbHideStackText clicked() @@ -18639,8 +17405,8 @@ on stack click() - 251 - 495 + 249 + 473 412 @@ -18655,8 +17421,8 @@ on stack click() - 126 - 382 + 130 + 360 399 @@ -18671,8 +17437,8 @@ on stack click() - 288 - 474 + 292 + 452 434 From 3afb395d3a56dbdab1aa378b4e37b6b1aaa0741e Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 4 Oct 2018 11:13:06 +0100 Subject: [PATCH 039/140] ++ --- src/OpticalOverrides/aopticaloverridescriptinterface.cpp | 1 + src/OpticalOverrides/aopticaloverridescriptinterface.h | 5 +++++ src/ants2.pro | 2 +- src/common/atracerstateful.cpp | 2 ++ src/modules/aphotontracer.cpp | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index 84e79b84..9aedcfd6 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -147,6 +147,7 @@ void AOpticalOverrideScriptInterface::LambertBack() Status = AOpticalOverride::LambertianReflection; ReturnResult = AOpticalOverride::Back; bResultAlreadySet = true; + //emit requestAbort(); } void AOpticalOverrideScriptInterface::LambertForward() diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 904bceef..3747ccb0 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -5,6 +5,7 @@ #include "aopticaloverride.h" #include +#include class APhoton; class AMaterialParticleCollection; @@ -21,6 +22,7 @@ class AOpticalOverrideScriptInterface : public AScriptInterface public slots: //ToDo: meddling test! -> e.g. dir was changed and then Lambert called + //maybe implement abort and add it after directives -> tested: x2 slow down void Absorb(); void SpecularReflection(); @@ -62,6 +64,9 @@ public slots: bool bResultAlreadySet; AOpticalOverride::OpticalOverrideResultEnum ReturnResult; //{NotTriggered, Absorbed, Forward, Back, _Error_}; AOpticalOverride::ScatterStatusEnum Status; + +signals: + void requestAbort(const QScriptValue &result = QScriptValue()); }; #endif // AOPTICALOVERRIDESCRIPTINTERFACE_H diff --git a/src/ants2.pro b/src/ants2.pro index 983354a6..37c95564 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -1,6 +1,6 @@ #--------------ANTS2-------------- ANTS2_MAJOR = 4 -ANTS2_MINOR = 12 +ANTS2_MINOR = 13 #Optional libraries #CONFIG += ants2_cuda #enable CUDA support - need NVIDIA GPU and drivers (CUDA toolkit) installed! diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index 75169330..7f1b9584 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -47,6 +47,8 @@ void ATracerStateful::generateScriptInfrastructure(const AMaterialParticleCollec QScriptValue val = ScriptEngine->newQObject(overrideInterface, QScriptEngine::QtOwnership); ScriptEngine->globalObject().setProperty(overrideInterface->objectName(), val); + QObject::connect(overrideInterface, &AOpticalOverrideScriptInterface::requestAbort, ScriptEngine, &QScriptEngine::abortEvaluation, Qt::DirectConnection); + mathInterface = new AMathScriptInterface(RandGen); mathInterface->setObjectName("math"); val = ScriptEngine->newQObject(mathInterface, QScriptEngine::QtOwnership); diff --git a/src/modules/aphotontracer.cpp b/src/modules/aphotontracer.cpp index f9fa2dbb..75d7322e 100644 --- a/src/modules/aphotontracer.cpp +++ b/src/modules/aphotontracer.cpp @@ -234,6 +234,8 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) //qDebug() << "Overrides defined! Model = "<getType(); N = navigator->FindNormal(kFALSE); fHaveNormal = true; + const double* PhPos = navigator->GetCurrentPoint(); + for (int i=0; i<3; i++) p->r[i] = PhPos[i]; AOpticalOverride::OpticalOverrideResultEnum result = ov->calculate(*ResourcesForOverrides, p, N); switch (result) From 60873e933041a8081b122f7a436107635bdc4936 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 4 Oct 2018 16:44:08 +0100 Subject: [PATCH 040/140] ++ --- src/DATA/Neutrons/CrossSections/nonN14.txt | 970 +++++++++++++++ src/DATA/Neutrons/Reactions/N-14.json | 19 + .../abasicopticaloverride.cpp | 232 ++++ src/OpticalOverrides/abasicopticaloverride.h | 42 + .../aopticaloverridescriptinterface.h | 1 + src/OpticalOverrides/awaveshifteroverride.cpp | 389 ++++++ src/OpticalOverrides/awaveshifteroverride.h | 65 + src/OpticalOverrides/fsnpopticaloverride.cpp | 148 +++ src/OpticalOverrides/fsnpopticaloverride.h | 40 + .../phscatclaudiomodel.cpp | 0 .../phscatclaudiomodel.h | 0 .../scatteronmetal.cpp | 0 .../scatteronmetal.h | 0 .../spectralbasicopticaloverride.cpp | 313 +++++ .../spectralbasicopticaloverride.h | 60 + src/ants2.pro | 20 +- src/common/aopticaloverride.cpp | 1062 +---------------- src/common/aopticaloverride.h | 161 +-- src/modules/amaterialparticlecolection.cpp | 15 +- 19 files changed, 2315 insertions(+), 1222 deletions(-) create mode 100644 src/DATA/Neutrons/CrossSections/nonN14.txt create mode 100644 src/DATA/Neutrons/Reactions/N-14.json create mode 100644 src/OpticalOverrides/abasicopticaloverride.cpp create mode 100644 src/OpticalOverrides/abasicopticaloverride.h create mode 100644 src/OpticalOverrides/awaveshifteroverride.cpp create mode 100644 src/OpticalOverrides/awaveshifteroverride.h create mode 100644 src/OpticalOverrides/fsnpopticaloverride.cpp create mode 100644 src/OpticalOverrides/fsnpopticaloverride.h rename src/{modules => OpticalOverrides}/phscatclaudiomodel.cpp (100%) rename src/{modules => OpticalOverrides}/phscatclaudiomodel.h (100%) rename src/{modules => OpticalOverrides}/scatteronmetal.cpp (100%) rename src/{modules => OpticalOverrides}/scatteronmetal.h (100%) create mode 100644 src/OpticalOverrides/spectralbasicopticaloverride.cpp create mode 100644 src/OpticalOverrides/spectralbasicopticaloverride.h diff --git a/src/DATA/Neutrons/CrossSections/nonN14.txt b/src/DATA/Neutrons/CrossSections/nonN14.txt new file mode 100644 index 00000000..2ded8d74 --- /dev/null +++ b/src/DATA/Neutrons/CrossSections/nonN14.txt @@ -0,0 +1,970 @@ +#LIBRARY ENDF/B-VII.1 +#REACTION N-14(N,P)C-14,SIG +#NUCLEUS N-14 +#MF 3 +#MT 103 +#EN-MIN 1e-05 +#EN-MAX 1.5e+08 +#E,eV Sig,b Interpolation + 1E-05 91.901 Lin-Lin + 1.10304E-05 87.5035 Lin-Lin + 1.21669E-05 83.3164 Lin-Lin + 1.34206E-05 79.3296 Lin-Lin + 1.48034E-05 75.5336 Lin-Lin + 1.63286E-05 71.9193 Lin-Lin + 1.80111E-05 68.4779 Lin-Lin + 1.98669E-05 65.2011 Lin-Lin + 2.19139E-05 62.0812 Lin-Lin + 2.41719E-05 59.1106 Lin-Lin + 2.66625E-05 56.2821 Lin-Lin + 2.94097E-05 53.5889 Lin-Lin + 3.244E-05 51.0247 Lin-Lin + 3.57825E-05 48.5831 Lin-Lin + 3.94694E-05 46.2583 Lin-Lin + 4.35362E-05 44.0448 Lin-Lin + 4.80221E-05 41.9372 Lin-Lin + 5.29701E-05 39.9305 Lin-Lin + 5.8428E-05 38.0198 Lin-Lin + 6.44482E-05 36.2005 Lin-Lin + 7.10888E-05 34.4683 Lin-Lin + 7.84136E-05 32.819 Lin-Lin + 8.64931E-05 31.2485 Lin-Lin + 9.54051E-05 29.7533 Lin-Lin + 0.000105235 28.3296 Lin-Lin + 0.000116078 26.974 Lin-Lin + 0.000128039 25.6832 Lin-Lin + 0.000141232 24.4543 Lin-Lin + 0.000155784 23.2841 Lin-Lin + 0.000171835 22.1699 Lin-Lin + 0.00018954 21.1091 Lin-Lin + 0.00020907 20.099 Lin-Lin + 0.000230612 19.1373 Lin-Lin + 0.000254374 18.2215 Lin-Lin + 0.000280584 17.3496 Lin-Lin + 0.000309494 16.5194 Lin-Lin + 0.000341383 15.7289 Lin-Lin + 0.000376558 14.9763 Lin-Lin + 0.000415358 14.2597 Lin-Lin + 0.000458155 13.5773 Lin-Lin + 0.000505362 12.9276 Lin-Lin + 0.000557433 12.309 Lin-Lin + 0.000614869 11.7201 Lin-Lin + 0.000678223 11.1592 Lin-Lin + 0.000748105 10.6253 Lin-Lin + 0.000825188 10.1168 Lin-Lin + 0.000910213 9.63274 Lin-Lin + 0.001004 9.1718 Lin-Lin + 0.00110745 8.73292 Lin-Lin + 0.00122155 8.31505 Lin-Lin + 0.00134742 7.91717 Lin-Lin + 0.00148625 7.53832 Lin-Lin + 0.00163939 7.17761 Lin-Lin + 0.00180831 6.83416 Lin-Lin + 0.00199463 6.50714 Lin-Lin + 0.00220016 6.19577 Lin-Lin + 0.00242685 5.8993 Lin-Lin + 0.00267691 5.61701 Lin-Lin + 0.00295273 5.34823 Lin-Lin + 0.00325697 5.09232 Lin-Lin + 0.00359256 4.84865 Lin-Lin + 0.00396272 4.61664 Lin-Lin + 0.00437103 4.39573 Lin-Lin + 0.00482141 4.18539 Lin-Lin + 0.00531819 3.98512 Lin-Lin + 0.00586616 3.79443 Lin-Lin + 0.00647059 3.61286 Lin-Lin + 0.0071373 3.43998 Lin-Lin + 0.00787271 3.27538 Lin-Lin + 0.00868389 3.11865 Lin-Lin + 0.00957865 2.96942 Lin-Lin + 0.0105656 2.82733 Lin-Lin + 0.0116543 2.69204 Lin-Lin + 0.0128551 2.56323 Lin-Lin + 0.0141796 2.44058 Lin-Lin + 0.0156406 2.32379 Lin-Lin + 0.0172522 2.2126 Lin-Lin + 0.0190298 2.10672 Lin-Lin + 0.0209906 2.00592 Lin-Lin + 0.0231534 1.90993 Lin-Lin + 0.0252419 1.82921 Lin-Lin + 0.0253 1.82711 Lin-Lin + 0.0279068 1.73968 Lin-Lin + 0.0307823 1.65644 Lin-Lin + 0.033954 1.57717 Lin-Lin + 0.0374525 1.50171 Lin-Lin + 0.0413115 1.42985 Lin-Lin + 0.0455681 1.36145 Lin-Lin + 0.0502633 1.29632 Lin-Lin + 0.0554423 1.23433 Lin-Lin + 0.0611549 1.17533 Lin-Lin + 0.0674561 1.11916 Lin-Lin + 0.0744066 1.06569 Lin-Lin + 0.0820732 1.01477 Lin-Lin + 0.0905297 0.966269 Lin-Lin + 0.0998577 0.920073 Lin-Lin + 0.110147 0.876077 Lin-Lin + 0.121496 0.834181 Lin-Lin + 0.134014 0.79428 Lin-Lin + 0.147823 0.756272 Lin-Lin + 0.163054 0.720065 Lin-Lin + 0.179855 0.685588 Lin-Lin + 0.198386 0.652778 Lin-Lin + 0.218827 0.621554 Lin-Lin + 0.241375 0.591826 Lin-Lin + 0.266245 0.563522 Lin-Lin + 0.293678 0.536567 Lin-Lin + 0.323938 0.510869 Lin-Lin + 0.357316 0.486394 Lin-Lin + 0.394132 0.463117 Lin-Lin + 0.434743 0.440973 Lin-Lin + 0.479537 0.419884 Lin-Lin + 0.528947 0.399794 Lin-Lin + 0.583448 0.380692 Lin-Lin + 0.643565 0.362452 Lin-Lin + 0.709876 0.34508 Lin-Lin + 0.78302 0.32859 Lin-Lin + 0.8637 0.312856 Lin-Lin + 0.952693 0.297872 Lin-Lin + 1.05086 0.28364 Lin-Lin + 1.16731 0.269158 Lin-Lin + 1.28758 0.256251 Lin-Lin + 1.42025 0.244005 Lin-Lin + 1.56659 0.232327 Lin-Lin + 1.72801 0.221156 Lin-Lin + 1.90606 0.210584 Lin-Lin + 2.10245 0.200503 Lin-Lin + 2.31908 0.190942 Lin-Lin + 2.57595 0.181125 Lin-Lin + 2.84137 0.172508 Lin-Lin + 3.13414 0.164261 Lin-Lin + 3.45707 0.156345 Lin-Lin + 3.84017 0.148353 Lin-Lin + 4.26552 0.140759 Lin-Lin + 4.6723 0.134527 Lin-Lin + 5.18982 0.12759 Lin-Lin + 5.80533 0.120673 Lin-Lin + 6.49383 0.114085 Lin-Lin + 7.11311 0.108994 Lin-Lin + 7.84603 0.1038 Lin-Lin + 8.65446 0.0988191 Lin-Lin + 9.47932 0.0944249 Lin-Lin + 10.3833 0.090226 Lin-Lin + 11.3729 0.0861951 Lin-Lin + 12.4575 0.0823776 Lin-Lin + 13.5499 0.0789663 Lin-Lin + 14.8414 0.0754573 Lin-Lin + 16.1429 0.0723604 Lin-Lin + 17.4363 0.06961 Lin-Lin + 18.9653 0.0667419 Lin-Lin + 20.6284 0.0639926 Lin-Lin + 22.4374 0.0613481 Lin-Lin + 24.4049 0.0588385 Lin-Lin + 26.545 0.0563988 Lin-Lin + 28.8728 0.054083 Lin-Lin + 31.4047 0.0518549 Lin-Lin + 34.3979 0.0495383 Lin-Lin + 37.6782 0.0473344 Lin-Lin + 40.9823 0.0453839 Lin-Lin + 44.8884 0.0433601 Lin-Lin + 48.4851 0.0417287 Lin-Lin + 52.7368 0.0399977 Lin-Lin + 57.3614 0.0383552 Lin-Lin + 62.3915 0.0367736 Lin-Lin + 68.8201 0.0350119 Lin-Lin + 74.8551 0.0335686 Lin-Lin + 81.4192 0.0321873 Lin-Lin + 89.8084 0.0306432 Lin-Lin + 98.3681 0.0292807 Lin-Lin + 106.994 0.028067 Lin-Lin + 115.567 0.0269995 Lin-Lin + 128.368 0.0255974 Lin-Lin + 137.682 0.0247223 Lin-Lin + 149.756 0.0236879 Lin-Lin + 166.351 0.0224606 Lin-Lin + 179.671 0.0216086 Lin-Lin + 195.427 0.0207109 Lin-Lin + 212.564 0.0198496 Lin-Lin + 231.204 0.0190296 Lin-Lin + 256.826 0.0180408 Lin-Lin + 275.461 0.0174241 Lin-Lin + 299.617 0.0166951 Lin-Lin + 332.803 0.0158305 Lin-Lin + 359.47 0.0152296 Lin-Lin + 390.992 0.0145969 Lin-Lin + 425.279 0.0139899 Lin-Lin + 459.332 0.0134571 Lin-Lin + 510.234 0.0127594 Lin-Lin + 547.257 0.0123226 Lin-Lin + 599.416 0.0117669 Lin-Lin + 665.842 0.0111572 Lin-Lin + 719.158 0.0107339 Lin-Lin + 776.78 0.0103235 Lin-Lin + 856.818 0.00982436 Lin-Lin + 938.481 0.00938468 Lin-Lin + 1020.78 0.0089935 Lin-Lin + 1110.29 0.00861153 Lin-Lin + 1199.25 0.00827782 Lin-Lin + 1312.36 0.00790086 Lin-Lin + 1427.44 0.00756728 Lin-Lin + 1563.57 0.00721967 Lin-Lin + 1672.31 0.0069759 Lin-Lin + 1831.7 0.00665493 Lin-Lin + 2034.68 0.00630373 Lin-Lin + 2213.11 0.00603092 Lin-Lin + 2385.99 0.00579799 Lin-Lin + 2624.71 0.00551445 Lin-Lin + 2842.78 0.00528845 Lin-Lin + 3113.88 0.00504188 Lin-Lin + 3405.26 0.00481057 Lin-Lin + 3756.13 0.00456884 Lin-Lin + 4172.37 0.00432198 Lin-Lin + 4506.46 0.00414879 Lin-Lin + 4854.82 0.00398735 Lin-Lin + 5275.77 0.00381421 Lin-Lin + 5698.22 0.00366086 Lin-Lin + 6084.65 0.0035349 Lin-Lin + 6711.59 0.00335355 Lin-Lin + 7236.33 0.00322186 Lin-Lin + 7791.21 0.00309688 Lin-Lin + 8578.31 0.00294168 Lin-Lin + 9327.02 0.00281345 Lin-Lin + 10070.5 0.00270079 Lin-Lin + 11108.2 0.00256986 Lin-Lin + 12014.1 0.00246986 Lin-Lin + 13123.6 0.00236077 Lin-Lin + 14213.9 0.00226696 Lin-Lin + 15535.1 0.00216682 Lin-Lin + 17087.2 0.00206425 Lin-Lin + 18716.7 0.001971 Lin-Lin + 20000 0.0019048 Lin-Lin + 40000 0.00143768 Lin-Lin + 60000 0.00130063 Lin-Lin + 80000 0.00126262 Lin-Lin + 100705 0.00127164 Lin-Lin + 120823 0.00130787 Lin-Lin + 140954 0.00136421 Lin-Lin + 162257 0.00144169 Lin-Lin + 180000 0.0015192 Lin-Lin + 196777 0.00160382 Lin-Lin + 201411 0.00162995 Lin-Lin + 250000 0.00194513 Lin-Lin + 299941 0.00239008 Lin-Lin + 349915 0.00300706 Lin-Lin + 400000 0.00395354 Lin-Lin + 410000 0.0042326 Lin-Lin + 420000 0.00457932 Lin-Lin + 425000 0.0047914 Lin-Lin + 429000 0.00498753 Lin-Lin + 433200 0.00522686 Lin-Lin + 437000 0.00548208 Lin-Lin + 440000 0.00571747 Lin-Lin + 442000 0.00589506 Lin-Lin + 444000 0.00609269 Lin-Lin + 446000 0.00631413 Lin-Lin + 448000 0.00656367 Lin-Lin + 450000 0.00684827 Lin-Lin + 460000 0.00911647 Lin-Lin + 469945 0.0150599 Lin-Lin + 470000 0.0151228 Lin-Lin + 470104 0.0153632 Lin-Lin + 479947 0.0414037 Lin-Lin + 480000 0.0416194 Lin-Lin + 480125 0.0425177 Lin-Lin + 481750 0.0553299 Lin-Lin + 482000 0.0573944 Lin-Lin + 482250 0.0606689 Lin-Lin + 483938 0.0834161 Lin-Lin + 484000 0.0844295 Lin-Lin + 484125 0.0873128 Lin-Lin + 485969 0.132688 Lin-Lin + 486031 0.134868 Lin-Lin + 487875 0.218091 Lin-Lin + 488000 0.224043 Lin-Lin + 488500 0.25533 Lin-Lin + 489750 0.333653 Lin-Lin + 490000 0.348763 Lin-Lin + 490875 0.379469 Lin-Lin + 491000 0.382958 Lin-Lin + 491125 0.38194 Lin-Lin + 491750 0.372697 Lin-Lin + 492000 0.368343 Lin-Lin + 492500 0.34216 Lin-Lin + 493000 0.315143 Lin-Lin + 494000 0.251432 Lin-Lin + 495969 0.153311 Lin-Lin + 496031 0.150885 Lin-Lin + 497938 0.0976709 Lin-Lin + 498000 0.096126 Lin-Lin + 498125 0.0939994 Lin-Lin + 499969 0.0658337 Lin-Lin + 500028 0.0652409 Lin-Lin + 500882 0.0613194 Lin-Lin + 509954 0.0204478 Lin-Lin + 510000 0.0202915 Lin-Lin + 510084 0.0201571 Lin-Lin + 520000 0.0115317 Lin-Lin + 530000 0.00840668 Lin-Lin + 540000 0.00693305 Lin-Lin + 550000 0.00622363 Lin-Lin + 560000 0.00614714 Lin-Lin + 570000 0.00698515 Lin-Lin + 580000 0.00955758 Lin-Lin + 590000 0.0157781 Lin-Lin + 599162 0.028914 Lin-Lin + 600000 0.0301522 Lin-Lin + 602116 0.0371493 Lin-Lin + 609233 0.0607965 Lin-Lin + 610000 0.0634222 Lin-Lin + 611883 0.0771355 Lin-Lin + 620000 0.13666 Lin-Lin + 630000 0.246733 Lin-Lin + 635000 0.279083 Lin-Lin + 640039 0.275714 Lin-Lin + 645000 0.247019 Lin-Lin + 650000 0.21004 Lin-Lin + 655000 0.175523 Lin-Lin + 660000 0.146847 Lin-Lin + 680000 0.0798225 Lin-Lin + 700000 0.050587 Lin-Lin + 719891 0.0353516 Lin-Lin + 740000 0.0261544 Lin-Lin + 760000 0.020276 Lin-Lin + 780000 0.0163043 Lin-Lin + 800000 0.0135529 Lin-Lin + 820000 0.0116367 Lin-Lin + 840000 0.0103355 Lin-Lin + 860000 0.00952529 Lin-Lin + 880000 0.00915713 Lin-Lin + 900000 0.00925899 Lin-Lin + 910000 0.00952564 Lin-Lin + 920000 0.00998178 Lin-Lin + 930000 0.0106898 Lin-Lin + 940000 0.0117533 Lin-Lin + 950000 0.013353 Lin-Lin + 960000 0.0157982 Lin-Lin + 965000 0.017491 Lin-Lin + 970000 0.0196094 Lin-Lin + 975000 0.0222304 Lin-Lin + 980000 0.0253644 Lin-Lin + 985000 0.0287889 Lin-Lin + 990000 0.031766 Lin-Lin + 995000 0.0328734 Lin-Lin + 1E+06 0.0307386 Lin-Lin + 1.005E+06 0.0256444 Lin-Lin + 1.01E+06 0.0195871 Lin-Lin + 1.012E+06 0.0173325 Lin-Lin + 1.014E+06 0.0152808 Lin-Lin + 1.016E+06 0.0134568 Lin-Lin + 1.018E+06 0.0118637 Lin-Lin + 1.02E+06 0.0104973 Lin-Lin + 1.0393E+06 0.00463052 Lin-Lin + 1.04E+06 0.00442313 Lin-Lin + 1.045E+06 0.00400709 Lin-Lin + 1.05E+06 0.00377611 Lin-Lin + 1.055E+06 0.00366923 Lin-Lin + 1.06E+06 0.00364921 Lin-Lin + 1.065E+06 0.00369153 Lin-Lin + 1.07E+06 0.00377977 Lin-Lin + 1.075E+06 0.00390253 Lin-Lin + 1.08E+06 0.00405241 Lin-Lin + 1.085E+06 0.00422379 Lin-Lin + 1.09E+06 0.00441308 Lin-Lin + 1.0975E+06 0.0047268 Lin-Lin + 1.1025E+06 0.0049529 Lin-Lin + 1.105E+06 0.00506993 Lin-Lin + 1.11E+06 0.00532917 Lin-Lin + 1.112E+06 0.00544661 Lin-Lin + 1.12E+06 0.00599323 Lin-Lin + 1.1275E+06 0.00642765 Lin-Lin + 1.135E+06 0.00685869 Lin-Lin + 1.1425E+06 0.00733275 Lin-Lin + 1.15E+06 0.0078437 Lin-Lin + 1.1575E+06 0.008406 Lin-Lin + 1.1625E+06 0.0088117 Lin-Lin + 1.165E+06 0.00902221 Lin-Lin + 1.17E+06 0.00948287 Lin-Lin + 1.174E+06 0.00989215 Lin-Lin + 1.178E+06 0.0103555 Lin-Lin + 1.181E+06 0.0107597 Lin-Lin + 1.1838E+06 0.0112195 Lin-Lin + 1.1844E+06 0.011324 Lin-Lin + 1.1852E+06 0.011381 Lin-Lin + 1.1864E+06 0.0115949 Lin-Lin + 1.188E+06 0.0119378 Lin-Lin + 1.19E+06 0.0124273 Lin-Lin + 1.192E+06 0.0130169 Lin-Lin + 1.194E+06 0.0137528 Lin-Lin + 1.196E+06 0.0147053 Lin-Lin + 1.198E+06 0.0159815 Lin-Lin + 1.2E+06 0.0177594 Lin-Lin + 1.2025E+06 0.0218765 Lin-Lin + 1.205E+06 0.0260228 Lin-Lin + 1.20992E+06 0.0357907 Lin-Lin + 1.21E+06 0.0358659 Lin-Lin + 1.21016E+06 0.0357147 Lin-Lin + 1.215E+06 0.0281372 Lin-Lin + 1.22E+06 0.0209404 Lin-Lin + 1.225E+06 0.0181166 Lin-Lin + 1.23E+06 0.017099 Lin-Lin + 1.235E+06 0.0168289 Lin-Lin + 1.24E+06 0.0169191 Lin-Lin + 1.245E+06 0.0172127 Lin-Lin + 1.25E+06 0.0176385 Lin-Lin + 1.255E+06 0.0181655 Lin-Lin + 1.26E+06 0.0187795 Lin-Lin + 1.265E+06 0.0194785 Lin-Lin + 1.27E+06 0.0202675 Lin-Lin + 1.275E+06 0.0211577 Lin-Lin + 1.28E+06 0.0221688 Lin-Lin + 1.285E+06 0.023326 Lin-Lin + 1.29E+06 0.0246673 Lin-Lin + 1.295E+06 0.0262457 Lin-Lin + 1.3E+06 0.0281374 Lin-Lin + 1.305E+06 0.0304573 Lin-Lin + 1.31E+06 0.0333839 Lin-Lin + 1.315E+06 0.0372067 Lin-Lin + 1.32E+06 0.0424319 Lin-Lin + 1.325E+06 0.0499953 Lin-Lin + 1.33E+06 0.0617692 Lin-Lin + 1.33438E+06 0.0791321 Lin-Lin + 1.335E+06 0.0817094 Lin-Lin + 1.33875E+06 0.108725 Lin-Lin + 1.34E+06 0.1179 Lin-Lin + 1.34219E+06 0.144596 Lin-Lin + 1.345E+06 0.179059 Lin-Lin + 1.34938E+06 0.226298 Lin-Lin + 1.35E+06 0.232629 Lin-Lin + 1.3525E+06 0.223225 Lin-Lin + 1.355E+06 0.213287 Lin-Lin + 1.36E+06 0.171976 Lin-Lin + 1.362E+06 0.16075 Lin-Lin + 1.364E+06 0.153073 Lin-Lin + 1.366E+06 0.148487 Lin-Lin + 1.368E+06 0.146522 Lin-Lin + 1.37E+06 0.146818 Lin-Lin + 1.372E+06 0.149075 Lin-Lin + 1.374E+06 0.153103 Lin-Lin + 1.376E+06 0.158782 Lin-Lin + 1.378E+06 0.166032 Lin-Lin + 1.38E+06 0.174827 Lin-Lin + 1.385E+06 0.203277 Lin-Lin + 1.39E+06 0.240046 Lin-Lin + 1.395E+06 0.281436 Lin-Lin + 1.4E+06 0.318672 Lin-Lin + 1.402E+06 0.329489 Lin-Lin + 1.404E+06 0.33669 Lin-Lin + 1.406E+06 0.339666 Lin-Lin + 1.408E+06 0.338157 Lin-Lin + 1.41E+06 0.332241 Lin-Lin + 1.415E+06 0.302032 Lin-Lin + 1.4225E+06 0.238635 Lin-Lin + 1.425E+06 0.217311 Lin-Lin + 1.43E+06 0.17996 Lin-Lin + 1.435E+06 0.149497 Lin-Lin + 1.44E+06 0.1254 Lin-Lin + 1.445E+06 0.106513 Lin-Lin + 1.45E+06 0.091686 Lin-Lin + 1.455E+06 0.0799597 Lin-Lin + 1.46E+06 0.0705915 Lin-Lin + 1.465E+06 0.0630281 Lin-Lin + 1.47E+06 0.0568543 Lin-Lin + 1.475E+06 0.051762 Lin-Lin + 1.48E+06 0.047521 Lin-Lin + 1.485E+06 0.0439572 Lin-Lin + 1.49E+06 0.0409376 Lin-Lin + 1.495E+06 0.0383591 Lin-Lin + 1.5E+06 0.0361428 Lin-Lin + 1.505E+06 0.0342255 Lin-Lin + 1.51E+06 0.0325572 Lin-Lin + 1.515E+06 0.031099 Lin-Lin + 1.52E+06 0.0298179 Lin-Lin + 1.525E+06 0.0286878 Lin-Lin + 1.53E+06 0.0276877 Lin-Lin + 1.535E+06 0.0267986 Lin-Lin + 1.54E+06 0.0260075 Lin-Lin + 1.5475E+06 0.0249825 Lin-Lin + 1.555E+06 0.0240993 Lin-Lin + 1.5625E+06 0.0233625 Lin-Lin + 1.57E+06 0.0227303 Lin-Lin + 1.575E+06 0.0223754 Lin-Lin + 1.582E+06 0.0219696 Lin-Lin + 1.5925E+06 0.0215335 Lin-Lin + 1.595E+06 0.0214075 Lin-Lin + 1.605E+06 0.0200966 Lin-Lin + 1.61E+06 0.0197057 Lin-Lin + 1.63143E+06 0.0185917 Lin-Lin + 1.65E+06 0.0176549 Lin-Lin + 1.72E+06 0.0138411 Lin-Lin + 1.74E+06 0.0128151 Lin-Lin + 1.7525E+06 0.012228 Lin-Lin + 1.76E+06 0.0119364 Lin-Lin + 1.765E+06 0.0118116 Lin-Lin + 1.77E+06 0.011788 Lin-Lin + 1.775E+06 0.0119222 Lin-Lin + 1.78E+06 0.0122459 Lin-Lin + 1.79E+06 0.013184 Lin-Lin + 1.795E+06 0.0135098 Lin-Lin + 1.8E+06 0.0136461 Lin-Lin + 1.805E+06 0.0136355 Lin-Lin + 1.81E+06 0.0135397 Lin-Lin + 1.83E+06 0.0129722 Lin-Lin + 1.845E+06 0.0126272 Lin-Lin + 1.86E+06 0.0123762 Lin-Lin + 1.875E+06 0.0121951 Lin-Lin + 1.895E+06 0.0120291 Lin-Lin + 1.92E+06 0.0118961 Lin-Lin + 1.97E+06 0.011742 Lin-Lin + 2.02E+06 0.0116591 Lin-Lin + 2.0425E+06 0.011687 Lin-Lin + 2.06E+06 0.0117751 Lin-Lin + 2.07E+06 0.0118732 Lin-Lin + 2.08E+06 0.0120192 Lin-Lin + 2.09E+06 0.0122333 Lin-Lin + 2.1E+06 0.0125374 Lin-Lin + 2.11E+06 0.0129696 Lin-Lin + 2.12E+06 0.0135779 Lin-Lin + 2.13E+06 0.0144383 Lin-Lin + 2.14E+06 0.0156629 Lin-Lin + 2.15E+06 0.0174239 Lin-Lin + 2.16E+06 0.0199933 Lin-Lin + 2.17E+06 0.0237896 Lin-Lin + 2.18E+06 0.0294425 Lin-Lin + 2.19E+06 0.0377604 Lin-Lin + 2.2E+06 0.0492607 Lin-Lin + 2.21E+06 0.062588 Lin-Lin + 2.213E+06 0.066229 Lin-Lin + 2.215E+06 0.068397 Lin-Lin + 2.216E+06 0.0694113 Lin-Lin + 2.218E+06 0.0711324 Lin-Lin + 2.22E+06 0.0724846 Lin-Lin + 2.222E+06 0.0734272 Lin-Lin + 2.224E+06 0.0739371 Lin-Lin + 2.226E+06 0.0740053 Lin-Lin + 2.228E+06 0.0736457 Lin-Lin + 2.23E+06 0.0728825 Lin-Lin + 2.232E+06 0.0717574 Lin-Lin + 2.234E+06 0.0703194 Lin-Lin + 2.237E+06 0.067678 Lin-Lin + 2.24E+06 0.0646355 Lin-Lin + 2.246E+06 0.0581655 Lin-Lin + 2.25E+06 0.0537936 Lin-Lin + 2.26E+06 0.0441179 Lin-Lin + 2.27E+06 0.036625 Lin-Lin + 2.28E+06 0.0310582 Lin-Lin + 2.29E+06 0.0269317 Lin-Lin + 2.3E+06 0.0238337 Lin-Lin + 2.31E+06 0.0214639 Lin-Lin + 2.32E+06 0.0196164 Lin-Lin + 2.33E+06 0.01815 Lin-Lin + 2.34E+06 0.0169668 Lin-Lin + 2.35E+06 0.0159966 Lin-Lin + 2.36E+06 0.0151915 Lin-Lin + 2.37E+06 0.0145154 Lin-Lin + 2.38E+06 0.0139433 Lin-Lin + 2.39E+06 0.0134543 Lin-Lin + 2.4E+06 0.0130345 Lin-Lin + 2.42E+06 0.0129853 Lin-Lin + 2.44E+06 0.0136338 Lin-Lin + 2.46868E+06 0.0149952 Lin-Lin + 2.495E+06 0.016286 Lin-Lin + 2.52E+06 0.0176195 Lin-Lin + 2.54E+06 0.0187535 Lin-Lin + 2.58E+06 0.0212564 Lin-Lin + 2.63E+06 0.0292824 Lin-Lin + 2.65E+06 0.0372788 Lin-Lin + 2.67E+06 0.0496706 Lin-Lin + 2.69E+06 0.0671655 Lin-Lin + 2.7E+06 0.0785067 Lin-Lin + 2.71E+06 0.0921768 Lin-Lin + 2.718E+06 0.104296 Lin-Lin + 2.72E+06 0.107385 Lin-Lin + 2.73E+06 0.12013 Lin-Lin + 2.735E+06 0.124224 Lin-Lin + 2.74E+06 0.126319 Lin-Lin + 2.75E+06 0.122622 Lin-Lin + 2.76E+06 0.113491 Lin-Lin + 2.77E+06 0.0989211 Lin-Lin + 2.7875E+06 0.07171 Lin-Lin + 2.79E+06 0.067806 Lin-Lin + 2.8E+06 0.0547528 Lin-Lin + 2.82E+06 0.0400361 Lin-Lin + 2.84E+06 0.0330382 Lin-Lin + 2.86E+06 0.0290544 Lin-Lin + 2.88E+06 0.0268796 Lin-Lin + 2.892E+06 0.0264473 Lin-Lin + 2.90025E+06 0.0267963 Lin-Lin + 2.925E+06 0.0292599 Lin-Lin + 2.942E+06 0.0330411 Lin-Lin + 2.948E+06 0.0358249 Lin-Lin + 2.952E+06 0.03815 Lin-Lin + 2.95575E+06 0.0411879 Lin-Lin + 2.957E+06 0.0422818 Lin-Lin + 2.9585E+06 0.0462509 Lin-Lin + 2.95991E+06 0.0499958 Lin-Lin + 2.96E+06 0.050101 Lin-Lin + 2.96016E+06 0.0499617 Lin-Lin + 2.96594E+06 0.0380817 Lin-Lin + 2.96625E+06 0.0377166 Lin-Lin + 2.97E+06 0.0345163 Lin-Lin + 2.97031E+06 0.0344819 Lin-Lin + 2.98E+06 0.0345202 Lin-Lin + 3E+06 0.0308534 Lin-Lin + 3.02E+06 0.0303883 Lin-Lin + 3.06E+06 0.0299981 Lin-Lin + 3.09E+06 0.0301571 Lin-Lin + 3.12E+06 0.0305968 Lin-Lin + 3.18E+06 0.0328765 Lin-Lin + 3.28E+06 0.0369021 Lin-Lin + 3.42E+06 0.052067 Lin-Lin + 3.46E+06 0.0634388 Lin-Lin + 3.485E+06 0.0733906 Lin-Lin + 3.508E+06 0.0802986 Lin-Lin + 3.514E+06 0.0818106 Lin-Lin + 3.524E+06 0.0828839 Lin-Lin + 3.531E+06 0.0825032 Lin-Lin + 3.552E+06 0.0804324 Lin-Lin + 3.57E+06 0.0784098 Lin-Lin + 3.578E+06 0.078323 Lin-Lin + 3.587E+06 0.0797563 Lin-Lin + 3.59E+06 0.0803082 Lin-Lin + 3.6E+06 0.0810994 Lin-Lin + 3.61E+06 0.0802413 Lin-Lin + 3.62E+06 0.0786487 Lin-Lin + 3.63E+06 0.0767531 Lin-Lin + 3.64E+06 0.0734625 Lin-Lin + 3.65E+06 0.0691492 Lin-Lin + 3.66E+06 0.0651359 Lin-Lin + 3.67E+06 0.0624648 Lin-Lin + 3.68E+06 0.0620166 Lin-Lin + 3.69E+06 0.063548 Lin-Lin + 3.7E+06 0.0661785 Lin-Lin + 3.71E+06 0.069496 Lin-Lin + 3.72E+06 0.0730307 Lin-Lin + 3.73E+06 0.0762232 Lin-Lin + 3.7625E+06 0.0836325 Lin-Lin + 3.8E+06 0.0919692 Lin-Lin + 3.93E+06 0.115135 Lin-Lin + 3.94E+06 0.116817 Lin-Lin + 3.96E+06 0.119643 Lin-Lin + 3.98E+06 0.121172 Lin-Lin + 4E+06 0.121485 Lin-Lin + 4.025E+06 0.120472 Lin-Lin + 4.05E+06 0.118662 Lin-Lin + 4.1E+06 0.114079 Lin-Lin + 4.15E+06 0.10868 Lin-Lin + 4.2E+06 0.102811 Lin-Lin + 4.25E+06 0.0989553 Lin-Lin + 4.3E+06 0.097111 Lin-Lin + 4.35E+06 0.0896276 Lin-Lin + 4.4E+06 0.0714613 Lin-Lin + 4.45E+06 0.0605046 Lin-Lin + 4.5E+06 0.0572707 Lin-Lin + 4.55E+06 0.0620449 Lin-Lin + 4.6E+06 0.0546618 Lin-Lin + 4.65E+06 0.0449554 Lin-Lin + 4.7E+06 0.0339033 Lin-Lin + 4.735E+06 0.0462672 Lin-Lin + 4.75E+06 0.0422493 Lin-Lin + 4.8E+06 0.032377 Lin-Lin + 4.85E+06 0.0289343 Lin-Lin + 4.9E+06 0.0283413 Lin-Lin + 5E+06 0.0293306 Lin-Lin + 5.075E+06 0.0296848 Lin-Lin + 5.1E+06 0.0297752 Lin-Lin + 5.15E+06 0.0282077 Lin-Lin + 5.2E+06 0.0256133 Lin-Lin + 5.25E+06 0.0231994 Lin-Lin + 5.3E+06 0.0210454 Lin-Lin + 5.35E+06 0.0193669 Lin-Lin + 5.4E+06 0.0180938 Lin-Lin + 5.45E+06 0.0169642 Lin-Lin + 5.5E+06 0.0160878 Lin-Lin + 5.55E+06 0.0161168 Lin-Lin + 5.6E+06 0.016513 Lin-Lin + 5.675E+06 0.017444 Lin-Lin + 5.725E+06 0.0181312 Lin-Lin + 5.75E+06 0.0184914 Lin-Lin + 5.8E+06 0.0194331 Lin-Lin + 5.85E+06 0.0199349 Lin-Lin + 5.86179E+06 0.0198313 Lin-Lin + 5.8625E+06 0.019825 Lin-Lin + 5.9E+06 0.0189452 Lin-Lin + 5.95E+06 0.0171914 Lin-Lin + 6E+06 0.0153313 Lin-Lin + 6.05E+06 0.0130453 Lin-Lin + 6.1E+06 0.0131984 Lin-Lin + 6.15E+06 0.0147087 Lin-Lin + 6.2E+06 0.0168554 Lin-Lin + 6.25E+06 0.0192796 Lin-Lin + 6.3E+06 0.0218601 Lin-Lin + 6.35E+06 0.0227805 Lin-Lin + 6.39309E+06 0.0221041 Lin-Lin + 6.39375E+06 0.0220937 Lin-Lin + 6.4E+06 0.0219061 Lin-Lin + 6.45E+06 0.0195542 Lin-Lin + 6.5E+06 0.0158818 Lin-Lin + 6.54189E+06 0.0146168 Lin-Lin + 6.55E+06 0.014433 Lin-Lin + 6.6E+06 0.013919 Lin-Lin + 6.64832E+06 0.0143689 Lin-Lin + 6.65E+06 0.0143917 Lin-Lin + 6.7E+06 0.0150712 Lin-Lin + 6.72885E+06 0.0154736 Lin-Lin + 6.73943E+06 0.0156293 Lin-Lin + 6.75E+06 0.0157701 Lin-Lin + 6.8E+06 0.0163411 Lin-Lin + 6.84613E+06 0.016691 Lin-Lin + 6.84807E+06 0.0167064 Lin-Lin + 6.85E+06 0.0167124 Lin-Lin + 6.9E+06 0.0166749 Lin-Lin + 6.95E+06 0.0164254 Lin-Lin + 7E+06 0.0160809 Lin-Lin + 7.19926E+06 0.0143927 Lin-Lin + 7.34E+06 0.0132693 Lin-Lin + 7.4E+06 0.0131139 Lin-Lin + 7.5E+06 0.0131751 Lin-Lin + 7.6E+06 0.0143229 Lin-Lin + 7.60361E+06 0.0143726 Lin-Lin + 7.8E+06 0.0178226 Lin-Lin + 8E+06 0.0234293 Lin-Lin + 8.1E+06 0.0260383 Lin-Lin + 8.15E+06 0.0266061 Lin-Lin + 8.2E+06 0.0271722 Lin-Lin + 8.3E+06 0.0275218 Lin-Lin + 8.30177E+06 0.0275339 Lin-Lin + 8.6E+06 0.0278088 Lin-Lin + 8.7E+06 0.0290449 Lin-Lin + 8.79807E+06 0.0313124 Lin-Lin + 8.8E+06 0.0313631 Lin-Lin + 9E+06 0.0369841 Lin-Lin + 9.2E+06 0.043227 Lin-Lin + 9.2649E+06 0.0451712 Lin-Lin + 9.4E+06 0.0492425 Lin-Lin + 9.6E+06 0.0536966 Lin-Lin + 9.8E+06 0.0561029 Lin-Lin + 1E+07 0.0569959 Lin-Lin + 1.01411E+07 0.0577659 Lin-Lin + 1.02E+07 0.0580874 Lin-Lin + 1.02842E+07 0.0584186 Lin-Lin + 1.04E+07 0.0588745 Lin-Lin + 1.05467E+07 0.0593173 Lin-Lin + 1.06E+07 0.0594781 Lin-Lin + 1.07495E+07 0.0600939 Lin-Lin + 1.08E+07 0.0603017 Lin-Lin + 1.09524E+07 0.0609409 Lin-Lin + 1.1E+07 0.0611408 Lin-Lin + 1.11552E+07 0.06152 Lin-Lin + 1.12E+07 0.0616295 Lin-Lin + 1.1358E+07 0.0613362 Lin-Lin + 1.14E+07 0.0612583 Lin-Lin + 1.15608E+07 0.0605675 Lin-Lin + 1.16E+07 0.0603992 Lin-Lin + 1.17637E+07 0.0595945 Lin-Lin + 1.18E+07 0.0594158 Lin-Lin + 1.19665E+07 0.0587838 Lin-Lin + 1.2E+07 0.0586565 Lin-Lin + 1.21693E+07 0.057724 Lin-Lin + 1.22E+07 0.0575549 Lin-Lin + 1.23721E+07 0.0570961 Lin-Lin + 1.24E+07 0.0570217 Lin-Lin + 1.25749E+07 0.0561465 Lin-Lin + 1.26E+07 0.0560211 Lin-Lin + 1.27778E+07 0.0539379 Lin-Lin + 1.28E+07 0.0536773 Lin-Lin + 1.29806E+07 0.0515883 Lin-Lin + 1.3E+07 0.0513637 Lin-Lin + 1.31834E+07 0.0499939 Lin-Lin + 1.32E+07 0.04987 Lin-Lin + 1.33862E+07 0.0485167 Lin-Lin + 1.34E+07 0.0484167 Lin-Lin + 1.3589E+07 0.0470995 Lin-Lin + 1.36E+07 0.0470232 Lin-Lin + 1.37919E+07 0.0458006 Lin-Lin + 1.39864E+07 0.0445608 Lin-Lin + 1.4E+07 0.0444745 Lin-Lin + 1.41975E+07 0.0433361 Lin-Lin + 1.42E+07 0.0433218 Lin-Lin + 1.43978E+07 0.042302 Lin-Lin + 1.44E+07 0.0422907 Lin-Lin + 1.45E+07 0.041686 Lin-Lin + 1.46009E+07 0.0411127 Lin-Lin + 1.48E+07 0.039982 Lin-Lin + 1.5E+07 0.0388844 Lin-Lin + 1.52116E+07 0.0378259 Lin-Lin + 1.54262E+07 0.0367526 Lin-Lin + 1.55E+07 0.0363836 Lin-Lin + 1.57187E+07 0.035405 Lin-Lin + 1.59404E+07 0.0344125 Lin-Lin + 1.6E+07 0.0341459 Lin-Lin + 1.62257E+07 0.0332345 Lin-Lin + 1.64546E+07 0.0323102 Lin-Lin + 1.65E+07 0.0321271 Lin-Lin + 1.67328E+07 0.0312602 Lin-Lin + 1.69689E+07 0.0303811 Lin-Lin + 1.7E+07 0.0302652 Lin-Lin + 1.72398E+07 0.0294651 Lin-Lin + 1.74831E+07 0.0286538 Lin-Lin + 1.77297E+07 0.0278311 Lin-Lin + 1.79799E+07 0.0269967 Lin-Lin + 1.8E+07 0.0269295 Lin-Lin + 1.82539E+07 0.0262114 Lin-Lin + 1.85115E+07 0.0254833 Lin-Lin + 1.87726E+07 0.0247449 Lin-Lin + 1.9E+07 0.024102 Lin-Lin + 1.92681E+07 0.0234519 Lin-Lin + 1.95399E+07 0.0227925 Lin-Lin + 1.98156E+07 0.0221239 Lin-Lin + 2E+07 0.0216765 Lin-Lin + 2E+07 0 Lin-Lin + 2.02822E+07 0 Lin-Lin + 2.05683E+07 0 Lin-Lin + 2.08585E+07 0 Lin-Lin + 2.11528E+07 0 Lin-Lin + 2.14512E+07 0 Lin-Lin + 2.17538E+07 0 Lin-Lin + 2.20608E+07 0 Lin-Lin + 2.2372E+07 0 Lin-Lin + 2.26876E+07 0 Lin-Lin + 2.30077E+07 0 Lin-Lin + 2.33323E+07 0 Lin-Lin + 2.36615E+07 0 Lin-Lin + 2.39953E+07 0 Lin-Lin + 2.43338E+07 0 Lin-Lin + 2.46771E+07 0 Lin-Lin + 2.50253E+07 0 Lin-Lin + 2.53783E+07 0 Lin-Lin + 2.57364E+07 0 Lin-Lin + 2.60995E+07 0 Lin-Lin + 2.64677E+07 0 Lin-Lin + 2.68411E+07 0 Lin-Lin + 2.72198E+07 0 Lin-Lin + 2.76038E+07 0 Lin-Lin + 2.79932E+07 0 Lin-Lin + 2.83882E+07 0 Lin-Lin + 2.87887E+07 0 Lin-Lin + 2.91948E+07 0 Lin-Lin + 2.96067E+07 0 Lin-Lin + 3.00244E+07 0 Lin-Lin + 3.0448E+07 0 Lin-Lin + 3.08776E+07 0 Lin-Lin + 3.13132E+07 0 Lin-Lin + 3.1755E+07 0 Lin-Lin + 3.2203E+07 0 Lin-Lin + 3.26573E+07 0 Lin-Lin + 3.31181E+07 0 Lin-Lin + 3.35853E+07 0 Lin-Lin + 3.40591E+07 0 Lin-Lin + 3.45396E+07 0 Lin-Lin + 3.50269E+07 0 Lin-Lin + 3.55211E+07 0 Lin-Lin + 3.60222E+07 0 Lin-Lin + 3.65304E+07 0 Lin-Lin + 3.70458E+07 0 Lin-Lin + 3.75685E+07 0 Lin-Lin + 3.80985E+07 0 Lin-Lin + 3.8636E+07 0 Lin-Lin + 3.91811E+07 0 Lin-Lin + 3.97338E+07 0 Lin-Lin + 4.02944E+07 0 Lin-Lin + 4.08629E+07 0 Lin-Lin + 4.14394E+07 0 Lin-Lin + 4.2024E+07 0 Lin-Lin + 4.26169E+07 0 Lin-Lin + 4.32182E+07 0 Lin-Lin + 4.38279E+07 0 Lin-Lin + 4.44462E+07 0 Lin-Lin + 4.50733E+07 0 Lin-Lin + 4.57092E+07 0 Lin-Lin + 4.63541E+07 0 Lin-Lin + 4.7008E+07 0 Lin-Lin + 4.76712E+07 0 Lin-Lin + 4.83438E+07 0 Lin-Lin + 4.90258E+07 0 Lin-Lin + 4.97175E+07 0 Lin-Lin + 5.04189E+07 0 Lin-Lin + 5.11303E+07 0 Lin-Lin + 5.18516E+07 0 Lin-Lin + 5.25831E+07 0 Lin-Lin + 5.3325E+07 0 Lin-Lin + 5.40773E+07 0 Lin-Lin + 5.48402E+07 0 Lin-Lin + 5.56139E+07 0 Lin-Lin + 5.63986E+07 0 Lin-Lin + 5.71942E+07 0 Lin-Lin + 5.80011E+07 0 Lin-Lin + 5.88194E+07 0 Lin-Lin + 5.96493E+07 0 Lin-Lin + 6.04908E+07 0 Lin-Lin + 6.13442E+07 0 Lin-Lin + 6.22097E+07 0 Lin-Lin + 6.30874E+07 0 Lin-Lin + 6.39774E+07 0 Lin-Lin + 6.488E+07 0 Lin-Lin + 6.57954E+07 0 Lin-Lin + 6.67236E+07 0 Lin-Lin + 6.7665E+07 0 Lin-Lin + 6.86196E+07 0 Lin-Lin + 6.95877E+07 0 Lin-Lin + 7.05694E+07 0 Lin-Lin + 7.15651E+07 0 Lin-Lin + 7.25747E+07 0 Lin-Lin + 7.35986E+07 0 Lin-Lin + 7.4637E+07 0 Lin-Lin + 7.56899E+07 0 Lin-Lin + 7.67578E+07 0 Lin-Lin + 7.78407E+07 0 Lin-Lin + 7.89389E+07 0 Lin-Lin + 8.00526E+07 0 Lin-Lin + 8.1182E+07 0 Lin-Lin + 8.23273E+07 0 Lin-Lin + 8.34888E+07 0 Lin-Lin + 8.46667E+07 0 Lin-Lin + 8.58612E+07 0 Lin-Lin + 8.70725E+07 0 Lin-Lin + 8.8301E+07 0 Lin-Lin + 8.95467E+07 0 Lin-Lin + 9.08101E+07 0 Lin-Lin + 9.20912E+07 0 Lin-Lin + 9.33905E+07 0 Lin-Lin + 9.4708E+07 0 Lin-Lin + 9.60442E+07 0 Lin-Lin + 9.73992E+07 0 Lin-Lin + 9.87733E+07 0 Lin-Lin + 1.00167E+08 0 Lin-Lin + 1.0158E+08 0 Lin-Lin + 1.03013E+08 0 Lin-Lin + 1.04466E+08 0 Lin-Lin + 1.0594E+08 0 Lin-Lin + 1.07435E+08 0 Lin-Lin + 1.08951E+08 0 Lin-Lin + 1.10488E+08 0 Lin-Lin + 1.12047E+08 0 Lin-Lin + 1.13627E+08 0 Lin-Lin + 1.1523E+08 0 Lin-Lin + 1.16856E+08 0 Lin-Lin + 1.18505E+08 0 Lin-Lin + 1.20177E+08 0 Lin-Lin + 1.21872E+08 0 Lin-Lin + 1.23591E+08 0 Lin-Lin + 1.25335E+08 0 Lin-Lin + 1.27103E+08 0 Lin-Lin + 1.28897E+08 0 Lin-Lin + 1.30715E+08 0 Lin-Lin + 1.32559E+08 0 Lin-Lin + 1.34429E+08 0 Lin-Lin + 1.36326E+08 0 Lin-Lin + 1.38249E+08 0 Lin-Lin + 1.402E+08 0 Lin-Lin + 1.42178E+08 0 Lin-Lin + 1.44184E+08 0 Lin-Lin + 1.46218E+08 0 Lin-Lin + 1.48281E+08 0 Lin-Lin + 1.5E+08 0 Lin-Lin +#END + + + + + Page generated: 2018-10-04,14:27:33 by E4-Servlet on localhost [fwd:www-nds.iaea.org] + Project: "Multi-platform EXFOR-CINDA-ENDF", V.Zerkin, IAEA-NDS, 1999-2018 + Request from: ::1 [fwd:193.136.215.14, 172.68.102.32] diff --git a/src/DATA/Neutrons/Reactions/N-14.json b/src/DATA/Neutrons/Reactions/N-14.json new file mode 100644 index 00000000..f225c5a5 --- /dev/null +++ b/src/DATA/Neutrons/Reactions/N-14.json @@ -0,0 +1,19 @@ +{ +"DecayScenarios": [ + { + "Branching": 1, + "GeneratedParticles": [ + { + "Energy": 580, + "OpositeDirectionWithPrevious": false, + "Particle": { + "Charge": 1, + "Mass": 1, + "Name": "proton", + "Type": 1 + } + } + ] + } +] +} \ No newline at end of file diff --git a/src/OpticalOverrides/abasicopticaloverride.cpp b/src/OpticalOverrides/abasicopticaloverride.cpp new file mode 100644 index 00000000..6c2f6e50 --- /dev/null +++ b/src/OpticalOverrides/abasicopticaloverride.cpp @@ -0,0 +1,232 @@ +#include "abasicopticaloverride.h" + +#include "aphoton.h" +#include "amaterial.h" +#include "amaterialparticlecolection.h" +#include "atracerstateful.h" +#include "asimulationstatistics.h" + +#include + +#include "TMath.h" +#include "TRandom2.h" + +#ifdef GUI +#include +#include +#include +#include +#include +#include +#endif + +ABasicOpticalOverride::ABasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) + : AOpticalOverride(MatCollection, MatFrom, MatTo) {} + +AOpticalOverride::OpticalOverrideResultEnum ABasicOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) +{ + double rnd = Resources.RandGen->Rndm(); + + // surface loss? + rnd -= probLoss; + if (rnd<0) + { + // qDebug()<<"Override: surface loss!"; + Photon->SimStat->OverrideSimplisticAbsorption++; + Status = Absorption; + return Absorbed; + } + + // specular reflection? + rnd -= probRef; + if (rnd<0) + { + // qDebug()<<"Override: specular reflection!"; + //rotating the vector: K = K - 2*(NK)*N + double NK = NormalVector[0]*Photon->v[0]; NK += NormalVector[1]*Photon->v[1]; NK += NormalVector[2]*Photon->v[2]; + Photon->v[0] -= 2.0*NK*NormalVector[0]; Photon->v[1] -= 2.0*NK*NormalVector[1]; Photon->v[2] -= 2.0*NK*NormalVector[2]; + + Photon->SimStat->OverrideSimplisticReflection++; + Status = SpikeReflection; + return Back; + } + + // scattering? + rnd -= probDiff; + if (rnd<0) + { + // qDebug()<<"scattering triggered"; + Photon->SimStat->OverrideSimplisticScatter++; + + switch (scatterModel) + { + case 0: //4Pi scattering + // qDebug()<<"4Pi scatter"; + Photon->RandomDir(Resources.RandGen); + // qDebug()<<"New direction:"<v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2] < 0) + { + // qDebug()<<" scattering back"; + Status = LambertianReflection; + return Back; + } + // qDebug()<<" continuing to the next volume"; + Status = Transmission; + return Forward; + + case 1: //2Pi lambertian, remaining in the same volume (back scattering) + { + // qDebug()<<"2Pi lambertian scattering backward"; + double norm2; + do + { + Photon->RandomDir(Resources.RandGen); + Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; + norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; + } + while (norm2 < 0.000001); + + double normInverted = 1.0/TMath::Sqrt(norm2); + Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; + Status = LambertianReflection; + return Back; + } + case 2: //2Pi lambertian, scattering to the next volume + { + // qDebug()<<"2Pi lambertian scattering forward"; + double norm2; + do + { + Photon->RandomDir(Resources.RandGen); + Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; + norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; + } + while (norm2 < 0.000001); + + double normInverted = 1.0/TMath::Sqrt(norm2); + Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; + Status = Transmission; + return Forward; + } + } + } + + // overrides NOT triggered - what is left is covered by Fresnel in the tracker code + // qDebug()<<"Overrides did not trigger, using fresnel"; + Status = Transmission; + return NotTriggered; +} + +const QString ABasicOpticalOverride::getReportLine() const +{ + double probFresnel = 1.0 - (probRef + probDiff + probLoss); + QString s; + if (probLoss > 0) s += QString("Abs %1 +").arg(probLoss); + if (probRef > 0) s += QString("Spec %1 +").arg(probRef); + if (probDiff > 0) + { + switch( scatterModel ) + { + case 0: + s += "Iso "; + break; + case 1: + s += "Lamb_B "; + break; + case 2: + s += "Lamb_F "; + break; + } + s += QString::number(probDiff); + s += " +"; + } + if (probFresnel > 1e-10) s += QString("Fres %1 +").arg(probFresnel); + s.chop(2); + return s; +} + +void ABasicOpticalOverride::writeToJson(QJsonObject &json) const +{ + AOpticalOverride::writeToJson(json); + + json["Abs"] = probLoss; + json["Spec"] = probRef; + json["Scat"] = probDiff; + json["ScatMode"] = scatterModel; +} + +bool ABasicOpticalOverride::readFromJson(const QJsonObject &json) +{ + QString type = json["Model"].toString(); + if (type != getType()) return false; //file for wrong model! + + probLoss = json["Abs"].toDouble(); + probRef = json["Spec"].toDouble(); + probDiff = json["Scat"].toDouble(); + scatterModel = json["ScatMode"].toInt(); + return true; +} + +#ifdef GUI +QWidget *ABasicOpticalOverride::getEditWidget(QWidget*, GraphWindowClass *) +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QHBoxLayout* hl = new QHBoxLayout(f); + QVBoxLayout* l = new QVBoxLayout(); + QLabel* lab = new QLabel("Absorption:"); + l->addWidget(lab); + lab = new QLabel("Specular reflection:"); + l->addWidget(lab); + lab = new QLabel("Scattering:"); + l->addWidget(lab); + hl->addLayout(l); + l = new QVBoxLayout(); + QLineEdit* le = new QLineEdit(QString::number(probLoss)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + val->setBottom(0); + //val->setTop(1.0); //Qt(5.8.0) BUG: check does not work + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probLoss = le->text().toDouble(); } ); + l->addWidget(le); + le = new QLineEdit(QString::number(probRef)); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probRef = le->text().toDouble(); } ); + l->addWidget(le); + le = new QLineEdit(QString::number(probDiff)); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probDiff = le->text().toDouble(); } ); + l->addWidget(le); + hl->addLayout(l); + l = new QVBoxLayout(); + lab = new QLabel(""); + l->addWidget(lab); + lab = new QLabel(""); + l->addWidget(lab); + QComboBox* com = new QComboBox(); + com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); + com->setCurrentIndex(scatterModel); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->scatterModel = index; } ); + l->addWidget(com); + hl->addLayout(l); + + return f; +} +#endif + +const QString ABasicOpticalOverride::checkOverrideData() +{ + if (probLoss<0 || probLoss>1.0) return "Absorption probability should be within [0, 1.0]"; + if (probRef <0 || probRef >1.0) return "Reflection probability should be within [0, 1.0]"; + if (probDiff<0 || probDiff>1.0) return "Scattering probability should be within [0, 1.0]"; + + if (probLoss + probRef + probDiff > 1.0) return "Sum of all process probabilities cannot exceed 1.0"; + + return ""; +} diff --git a/src/OpticalOverrides/abasicopticaloverride.h b/src/OpticalOverrides/abasicopticaloverride.h new file mode 100644 index 00000000..cad1cc62 --- /dev/null +++ b/src/OpticalOverrides/abasicopticaloverride.h @@ -0,0 +1,42 @@ +#ifndef ABASICOPTICALOVERRIDE_H +#define ABASICOPTICALOVERRIDE_H + +#include "aopticaloverride.h" + +#include + +class AMaterialParticleCollection; +class ATracerStateful; +class APhoton; +class QJsonObject; +class GraphWindowClass; + +class ABasicOpticalOverride : public AOpticalOverride +{ +public: + ABasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); + virtual ~ABasicOpticalOverride() {} + + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved + + virtual const QString getType() const override {return "Simplistic_model";} + virtual const QString getAbbreviation() const override {return "Simp";} + virtual const QString getReportLine() const override; + + // save/load config is not used for this type! + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; + +#ifdef GUI + virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; +#endif + virtual const QString checkOverrideData() override; + + //--parameters-- + double probLoss = 0; //probability of absorption + double probRef = 0; //probability of specular reflection + double probDiff = 0; //probability of scattering + int scatterModel = 1; //0 - 4Pi, 1 - 2Pi back, 2 - 2Pi forward +}; + +#endif // ABASICOPTICALOVERRIDE_H diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.h b/src/OpticalOverrides/aopticaloverridescriptinterface.h index 3747ccb0..73ce28a2 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.h +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.h @@ -9,6 +9,7 @@ class APhoton; class AMaterialParticleCollection; +class TRandom2; class AOpticalOverrideScriptInterface : public AScriptInterface { diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp new file mode 100644 index 00000000..30396af1 --- /dev/null +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -0,0 +1,389 @@ +#include "awaveshifteroverride.h" +#include "aphoton.h" +#include "amaterial.h" +#include "amaterialparticlecolection.h" +#include "atracerstateful.h" +#include "asimulationstatistics.h" +#include "acommonfunctions.h" +#include "ajsontools.h" + +#include + +#include "TMath.h" +#include "TRandom2.h" +#include "TH1D.h" + +#ifdef GUI +#include "afiletools.h" +#include "graphwindowclass.h" +#include "amessage.h" +#include "TGraph.h" +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +AWaveshifterOverride::AWaveshifterOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) + : AOpticalOverride(MatCollection, MatFrom, MatTo) {} + +AWaveshifterOverride::~AWaveshifterOverride() +{ + if (Spectrum) delete Spectrum; +} + +void AWaveshifterOverride::initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) +{ + if (bWaveResolved) + { + WaveFrom = waveFrom; + WaveStep = waveStep; + WaveNodes = waveNodes; + + ConvertToStandardWavelengthes(&ReemissionProbability_lambda, &ReemissionProbability, WaveFrom, WaveStep, WaveNodes, &ReemissionProbabilityBinned); + + QVector y; + ConvertToStandardWavelengthes(&EmissionSpectrum_lambda, &EmissionSpectrum, WaveFrom, WaveStep, WaveNodes, &y); + TString name = "WLSEmSpec"; + name += MatFrom; + name += "to"; + name += MatTo; + if (Spectrum) delete Spectrum; + Spectrum = new TH1D(name,"", WaveNodes, WaveFrom, WaveFrom+WaveStep*WaveNodes); + for (int j = 1; jSetBinContent(j, y[j-1]); + Spectrum->GetIntegral(); //to make thread safe + } + else + { + ReemissionProbabilityBinned.clear(); + delete Spectrum; Spectrum = 0; + } +} + +AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) +{ + //currently assuming there is no scattering on original wavelength - only reemission or absorption + + if ( !Spectrum || //emission spectrum not defined + Photon->waveIndex == -1 || //or photon without wavelength + ReemissionProbabilityBinned.isEmpty() ) //or probability not defined + { + Status = Absorption; + Photon->SimStat->OverrideWLSabs++; + return Absorbed; + } + + double prob = ReemissionProbabilityBinned.at(Photon->waveIndex); // probability of reemission + if (Resources.RandGen->Rndm() < prob) + { + //triggered! + + //generating new wavelength and waveindex + double wavelength; + int waveIndex; + int attempts = -1; + do + { + attempts++; + if (attempts > 9) + { + Status = Absorption; + Photon->SimStat->OverrideWLSabs++; + return Absorbed; + } + wavelength = Spectrum->GetRandom(); + waveIndex = (wavelength - WaveFrom)/WaveStep; + } + while (waveIndex < Photon->waveIndex); //conserving energy + + Photon->waveIndex = waveIndex; + Photon->SimStat->OverrideWLSshift++; + + if (ReemissionModel == 0) + { + Photon->RandomDir(Resources.RandGen); + //enering new volume or backscattering? + //normal is in the positive direction in respect to the original direction! + if (Photon->v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2] < 0) + { + // qDebug()<<" scattering back"; + Status = LambertianReflection; + return Back; + } + // qDebug()<<" continuing to the next volume"; + Status = Transmission; + return Forward; + } + + double norm2 = 0; + if (ReemissionModel == 1) + { + // qDebug()<<"2Pi lambertian scattering backward"; + do + { + Photon->RandomDir(Resources.RandGen); + Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; + norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; + } + while (norm2 < 0.000001); + + double normInverted = 1.0/TMath::Sqrt(norm2); + Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; + Status = LambertianReflection; + + return Back; + } + + // qDebug()<<"2Pi lambertian scattering forward"; + do + { + Photon->RandomDir(Resources.RandGen); + Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; + norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; + } + while (norm2 < 0.000001); + + double normInverted = 1.0/TMath::Sqrt(norm2); + Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; + Status = Transmission; + return Forward; + } + + // else absorption + Status = Absorption; + Photon->SimStat->OverrideWLSabs++; + return Absorbed; +} + +const QString AWaveshifterOverride::getReportLine() const +{ + return QString(); +} + +void AWaveshifterOverride::writeToJson(QJsonObject &json) const +{ + AOpticalOverride::writeToJson(json); + + QJsonArray arRP; + writeTwoQVectorsToJArray(ReemissionProbability_lambda, ReemissionProbability, arRP); + json["ReemissionProbability"] = arRP; + QJsonArray arEm; + writeTwoQVectorsToJArray(EmissionSpectrum_lambda, EmissionSpectrum, arEm); + json["EmissionSpectrum"] = arEm; + json["ReemissionModel"] = ReemissionModel; +} + +bool AWaveshifterOverride::readFromJson(const QJsonObject &json) +{ + //QString type = json["Model"].toString(); + //if (type != getType()) return false; //file for wrong model! + if (!AOpticalOverride::readFromJson(json)) return false; + + QJsonArray arRP = json["ReemissionProbability"].toArray(); + readTwoQVectorsFromJArray(arRP, ReemissionProbability_lambda, ReemissionProbability); + QJsonArray arEm = json["EmissionSpectrum"].toArray(); + readTwoQVectorsFromJArray(arEm, EmissionSpectrum_lambda, EmissionSpectrum); + + ReemissionModel = 1; + parseJson(json, "ReemissionModel", ReemissionModel); + + return true; +} + +#ifdef GUI +QWidget *AWaveshifterOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QVBoxLayout* vl = new QVBoxLayout(f); + QHBoxLayout* l = new QHBoxLayout(); + QLabel* lab = new QLabel("Reemission generation:"); + l->addWidget(lab); + QComboBox* com = new QComboBox(); + com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); + com->setCurrentIndex(ReemissionModel); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->ReemissionModel = index; } ); + l->addWidget(com); + vl->addLayout(l); + l = new QHBoxLayout(); + QVBoxLayout* vv = new QVBoxLayout(); + lab = new QLabel("Reemission probability:"); + vv->addWidget(lab); + lab = new QLabel("Emission spectrum:"); + vv->addWidget(lab); + l->addLayout(vv); + vv = new QVBoxLayout(); + QPushButton* pb = new QPushButton("Load"); + pb->setToolTip("Every line of the file should contain 2 numbers:\nwavelength[nm] reemission_probability[0..1]"); + QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadReemissionProbability(caller);}); + vv->addWidget(pb); + pb = new QPushButton("Load"); + pb->setToolTip("Every line of the file should contain 2 numbers:\nwavelength[nm] relative_intencity[>=0]"); + QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadEmissionSpectrum(caller);}); + vv->addWidget(pb); + l->addLayout(vv); + vv = new QVBoxLayout(); + pb = new QPushButton("Show"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showReemissionProbability(GraphWindow, caller);}); + vv->addWidget(pb); + pb = new QPushButton("Show"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showEmissionSpectrum(GraphWindow, caller);}); + vv->addWidget(pb); + l->addLayout(vv); + vv = new QVBoxLayout(); + pb = new QPushButton("Binned"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedReemissionProbability(GraphWindow, caller);}); + vv->addWidget(pb); + pb = new QPushButton("Binned"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedEmissionSpectrum(GraphWindow, caller);}); + vv->addWidget(pb); + l->addLayout(vv); + vl->addLayout(l); + lab = new QLabel("If simulation is NOT wavelength-resolved, this override does nothing!"); + lab->setAlignment(Qt::AlignCenter); + vl->addWidget(lab); + + return f; +} +#endif + +#ifdef GUI +void AWaveshifterOverride::loadReemissionProbability(QWidget* caller) +{ + QString fileName = QFileDialog::getOpenFileName(caller, "Load reemission probability", "", "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + QVector X, Y; + int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); + if (ret == 0) + { + ReemissionProbability_lambda = X; + ReemissionProbability = Y; + } +} + +void AWaveshifterOverride::loadEmissionSpectrum(QWidget *caller) +{ + QString fileName = QFileDialog::getOpenFileName(caller, "Load emission spectrum", "", "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + QVector X, Y; + int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); + if (ret == 0) + { + EmissionSpectrum_lambda = X; + EmissionSpectrum = Y; + } +} + +void AWaveshifterOverride::showReemissionProbability(GraphWindowClass *GraphWindow, QWidget* caller) +{ + if (ReemissionProbability_lambda.isEmpty()) + { + message("No data were loaded", caller); + return; + } + TGraph* gr = GraphWindow->ConstructTGraph(ReemissionProbability_lambda, ReemissionProbability, "Reemission probability", "Wavelength, nm", "Reemission probability, a.u.", 2, 20, 1, 2, 2); + gr->SetMinimum(0); + GraphWindow->Draw(gr, "apl"); +} + +void AWaveshifterOverride::showEmissionSpectrum(GraphWindowClass *GraphWindow, QWidget *caller) +{ + if (EmissionSpectrum_lambda.isEmpty()) + { + message("No data were loaded", caller); + return; + } + TGraph* gr = GraphWindow->ConstructTGraph(EmissionSpectrum_lambda, EmissionSpectrum, + "Emission spectrum", "Wavelength, nm", "Relative intensity, a.u.", + 4, 20, 1, + 4, 2); + gr->SetMinimum(0); + GraphWindow->Draw(gr, "apl"); +} + +void AWaveshifterOverride::showBinnedReemissionProbability(GraphWindowClass *GraphWindow, QWidget *caller) +{ + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + //TODO run checker + + if (!bWR) + { + message("Simulation is NOT wavelength resolved, override is inactive!", caller); + return; + } + + QVector waveIndex; + for (int i=0; iConstructTGraph(waveIndex, ReemissionProbabilityBinned, + "Reemission probability (binned)", "Wave index", "Reemission probability, a.u.", + 2, 20, 1, + 2, 2); + gr->SetMinimum(0); + GraphWindow->Draw(gr, "apl"); +} + +void AWaveshifterOverride::showBinnedEmissionSpectrum(GraphWindowClass *GraphWindow, QWidget *caller) +{ + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + //TODO run checker + + if (!bWR) + { + message("Simulation is NOT wavelength resolved, override is inactive!", caller); + return; + } + + double integral = Spectrum->ComputeIntegral(); + if (integral <= 0) + { + message("Binned emission spectrum: integral <=0, override will report an error!", caller); + return; + } + + TH1D* SpectrumCopy = new TH1D(*Spectrum); + SpectrumCopy->SetTitle("Binned emission spectrum"); + SpectrumCopy->GetXaxis()->SetTitle("Wavelength, nm"); + SpectrumCopy->GetYaxis()->SetTitle("Relative intensity, a.u."); + GraphWindow->Draw(SpectrumCopy, "hist"); //gets ownership of the copy +} +#endif + +const QString AWaveshifterOverride::checkOverrideData() +{ + if (ReemissionProbability_lambda.isEmpty()) + return "Reemission probability not loaded"; + if (ReemissionProbability_lambda.size() != ReemissionProbability.size()) + return "Mismatch in reemission probability data"; + + if (EmissionSpectrum_lambda.isEmpty()) + return "Emission spectrum not loaded"; + if (EmissionSpectrum_lambda.size() != EmissionSpectrum.size()) + return "Mismatch in emission spectrum data"; + + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + if (bWR && Spectrum->ComputeIntegral() <= 0) + return "Binned emission spectrum: integral should be > 0"; + return ""; +} diff --git a/src/OpticalOverrides/awaveshifteroverride.h b/src/OpticalOverrides/awaveshifteroverride.h new file mode 100644 index 00000000..3df007b8 --- /dev/null +++ b/src/OpticalOverrides/awaveshifteroverride.h @@ -0,0 +1,65 @@ +#ifndef AWAVESHIFTEROVERRIDE_H +#define AWAVESHIFTEROVERRIDE_H + +#include "aopticaloverride.h" + +#include +#include + +class AMaterialParticleCollection; +class ATracerStateful; +class APhoton; +class QJsonObject; +class GraphWindowClass; +class TH1D; + +class AWaveshifterOverride : public AOpticalOverride +{ +public: + AWaveshifterOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); + virtual ~AWaveshifterOverride(); + + void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved + + virtual const QString getType() const override {return "SurfaceWLS";} + virtual const QString getAbbreviation() const override {return "WLS";} + virtual const QString getReportLine() const override; + + // save/load config is not used for this type! + virtual void writeToJson(QJsonObject &json) const; + virtual bool readFromJson(const QJsonObject &json); + +#ifdef GUI + virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; +#endif + + virtual const QString checkOverrideData() override; + + //-- parameters -- + int ReemissionModel = 1; //0-isotropic (4Pi), 1-Lamb back (2Pi), 2-Lamb forward (2Pi) + QVector ReemissionProbability_lambda; + QVector ReemissionProbability; + QVector ReemissionProbabilityBinned; + + QVector EmissionSpectrum_lambda; + QVector EmissionSpectrum; + TH1D* Spectrum = 0; + + //tmp parameters + double WaveFrom; + double WaveStep; + int WaveNodes; + +private: +#ifdef GUI + void loadReemissionProbability(QWidget *caller); + void loadEmissionSpectrum(QWidget *caller); + void showReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); + void showEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); + void showBinnedReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); + void showBinnedEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); +#endif +}; + +#endif // AWAVESHIFTEROVERRIDE_H diff --git a/src/OpticalOverrides/fsnpopticaloverride.cpp b/src/OpticalOverrides/fsnpopticaloverride.cpp new file mode 100644 index 00000000..d81ecb99 --- /dev/null +++ b/src/OpticalOverrides/fsnpopticaloverride.cpp @@ -0,0 +1,148 @@ +#include "fsnpopticaloverride.h" +#include "aphoton.h" +#include "amaterial.h" +#include "amaterialparticlecolection.h" +#include "atracerstateful.h" +#include "asimulationstatistics.h" + +#include + +#include "TMath.h" +#include "TRandom2.h" + +#ifdef GUI +#include +#include +#include +#include +#include +#endif + +AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) +{ + // Angular reflectance: fraction of light reflected at the interface bewteen + // medium 1 and medium 2 assuming non-polarized incident light: + // ==> Incident light goes from medium 1 (n1) into medium 2 (n2). + // ==> cos(0): perpendicular to the surface. + // ==> cos(Pi/2): grazing/parallel to the surface. + // NOTE that even if the incident light is not polarized (equal amounts of s- + // and p-), the reflected light may be polarized because different percentages + // of s-(perpendicular) and p-(parallel) polarized waves are/may be reflected. + + //refractive indexes of materials before and after the interface + double n1 = (*MatCollection)[MatFrom]->getRefractiveIndex(Photon->waveIndex); + double n2 = (*MatCollection)[MatTo]->getRefractiveIndex(Photon->waveIndex); + + //angle of incidence + double cos1 = 0; + for (int i=0; i<3; i++) + cos1 += NormalVector[i]*Photon->v[i]; + + //Calculating reflection probability + double fresnelUnpolarR; + double sin1sqr = 1.0 - cos1*cos1; + double nsqr = n2/n1; nsqr *= nsqr; + if (sin1sqr > nsqr) + fresnelUnpolarR = 1.0; + else + { + double f1 = nsqr * cos1; + double f2 = TMath::Sqrt( nsqr - sin1sqr ); + // p-polarized + double Rp12 = (f1-f2) / (f1+f2); Rp12 *= Rp12; + // s-polarized + double Rs12 = (cos1-f2) / (cos1+f2); Rs12 *= Rs12; + + fresnelUnpolarR = 0.5 * (Rp12+Rs12); + } + +// if random[0,1]Rndm() < fresnelUnpolarR) + { + //qDebug()<<"Override: specular reflection"; + //rotating the vector: K = K - 2*(NK)*N + Photon->v[0] -= 2.0*cos1*NormalVector[0]; Photon->v[1] -= 2.0*cos1*NormalVector[1]; Photon->v[2] -= 2.0*cos1*NormalVector[2]; + Status = SpikeReflection; + Photon->SimStat->OverrideFSNPspecular++; + return Back; + } + +// if random[0,1]>albedo kill photon else do diffuse reflection + if (Resources.RandGen->Rndm() > Albedo) + { + //qDebug()<<"Override: absorption"; + Status = Absorption; + Photon->SimStat->OverrideFSNPabs++; + return Absorbed; + } + + //qDebug() << "Override: Lambertian scattering"; + double norm2; + do + { + Photon->RandomDir(Resources.RandGen); + Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; + norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; + } + while (norm2 < 0.000001); + double normInverted = 1.0/TMath::Sqrt(norm2); + Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; + Status = LambertianReflection; + Photon->SimStat->OverrideFSNlambert++; + return Back; +} + +const QString FSNPOpticalOverride::getReportLine() const +{ + return QString("Albedo %1").arg(Albedo); +} + +void FSNPOpticalOverride::writeToJson(QJsonObject &json) const +{ + AOpticalOverride::writeToJson(json); + + json["Albedo"] = Albedo; +} + +bool FSNPOpticalOverride::readFromJson(const QJsonObject &json) +{ + QString type = json["Model"].toString(); + if (type != getType()) return false; //file for wrong model! + + if (json.contains("Albedo")) + { + Albedo = json["Albedo"].toDouble(); + return true; + } + else + return false; +} + +#ifdef GUI +QWidget *FSNPOpticalOverride::getEditWidget(QWidget *, GraphWindowClass *) +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QHBoxLayout* l = new QHBoxLayout(f); + QLabel* lab = new QLabel("Albedo:"); + l->addWidget(lab); + QLineEdit* le = new QLineEdit(QString::number(Albedo)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + val->setBottom(0); + //val->setTop(1.0); //Qt(5.8.0) BUG: check does not work + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->Albedo = le->text().toDouble(); } ); + l->addWidget(le); + + return f; +} +#endif + +const QString FSNPOpticalOverride::checkOverrideData() +{ + if (Albedo < 0 || Albedo > 1.0) return "Albedo should be within [0, 1.0]"; + return ""; +} diff --git a/src/OpticalOverrides/fsnpopticaloverride.h b/src/OpticalOverrides/fsnpopticaloverride.h new file mode 100644 index 00000000..0d082b6f --- /dev/null +++ b/src/OpticalOverrides/fsnpopticaloverride.h @@ -0,0 +1,40 @@ +#ifndef FSNPOPTICALOVERRIDE_H +#define FSNPOPTICALOVERRIDE_H + +#include "aopticaloverride.h" + +#include + +class AMaterialParticleCollection; +class ATracerStateful; +class APhoton; +class QJsonObject; +class GraphWindowClass; + +class FSNPOpticalOverride : public AOpticalOverride +{ +public: + FSNPOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) + : AOpticalOverride(MatCollection, MatFrom, MatTo) {} + virtual ~FSNPOpticalOverride() {} + + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved + + virtual const QString getType() const override {return "FS_NP";} + virtual const QString getAbbreviation() const override {return "FSNP";} + virtual const QString getReportLine() const override; + + // save/load config is not used for this type! + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; + +#ifdef GUI + virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; +#endif + virtual const QString checkOverrideData() override; + + //-- parameters -- + double Albedo = 0.95; +}; + +#endif // FSNPOPTICALOVERRIDE_H diff --git a/src/modules/phscatclaudiomodel.cpp b/src/OpticalOverrides/phscatclaudiomodel.cpp similarity index 100% rename from src/modules/phscatclaudiomodel.cpp rename to src/OpticalOverrides/phscatclaudiomodel.cpp diff --git a/src/modules/phscatclaudiomodel.h b/src/OpticalOverrides/phscatclaudiomodel.h similarity index 100% rename from src/modules/phscatclaudiomodel.h rename to src/OpticalOverrides/phscatclaudiomodel.h diff --git a/src/modules/scatteronmetal.cpp b/src/OpticalOverrides/scatteronmetal.cpp similarity index 100% rename from src/modules/scatteronmetal.cpp rename to src/OpticalOverrides/scatteronmetal.cpp diff --git a/src/modules/scatteronmetal.h b/src/OpticalOverrides/scatteronmetal.h similarity index 100% rename from src/modules/scatteronmetal.h rename to src/OpticalOverrides/scatteronmetal.h diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.cpp b/src/OpticalOverrides/spectralbasicopticaloverride.cpp new file mode 100644 index 00000000..2a554d27 --- /dev/null +++ b/src/OpticalOverrides/spectralbasicopticaloverride.cpp @@ -0,0 +1,313 @@ +#include "spectralbasicopticaloverride.h" + +#include "aphoton.h" +#include "amaterial.h" +#include "amaterialparticlecolection.h" +#include "atracerstateful.h" +#include "asimulationstatistics.h" +#include "acommonfunctions.h" +#include "ajsontools.h" + +#include +#include + +#include "TMath.h" +#include "TRandom2.h" +#include "TH1D.h" + +#ifdef GUI +#include "afiletools.h" +#include "graphwindowclass.h" +#include "amessage.h" +#include "TGraph.h" +#include "TMultiGraph.h" +#include +#include +#include +#include +#include +#include +#include +#include +#endif + +SpectralBasicOpticalOverride::SpectralBasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) + : ABasicOpticalOverride(MatCollection, MatFrom, MatTo) +{ + Wave << 500; + ProbLoss << 0; + ProbRef << 0; + ProbDiff << 0; +} + +AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) +{ + int waveIndex = Photon->waveIndex; + if (waveIndex == -1) waveIndex = effectiveWaveIndex; + + probLoss = ProbLossBinned.at(waveIndex); + probDiff = ProbDiffBinned.at(waveIndex); + probRef = ProbRefBinned.at(waveIndex); + + return ABasicOpticalOverride::calculate(Resources, Photon, NormalVector); +} + +const QString SpectralBasicOpticalOverride::getReportLine() const +{ + return QString("Spectral data with %1 points").arg(Wave.size()); +} + +void SpectralBasicOpticalOverride::writeToJson(QJsonObject &json) const +{ + AOpticalOverride::writeToJson(json); + + json["ScatMode"] = scatterModel; + json["EffWavelength"] = effectiveWavelength; + + if (Wave.size() != ProbLoss.size() || Wave.size() != ProbRef.size() || Wave.size() != ProbDiff.size()) + { + qWarning() << "Mismatch in data size for SpectralBasicOverride! skipping data!"; + return; + } + QJsonArray sp; + for (int i=0; i= waveNodes ) effectiveWaveIndex = waveNodes - 1; + //qDebug() << "Eff wave"< effectiveWavelength) break; + + //closest is i-1 or i + if (i != 0) + if ( fabs(Wave.at(i-1) - effectiveWavelength) < fabs(Wave.at(i) - effectiveWavelength) ) i--; + } + + //qDebug() << "Selected i = "<< i << "with wave"<(1, ProbLoss.at(i)); + ProbRefBinned = QVector(1, ProbRef.at(i)); + ProbDiffBinned = QVector(1, ProbDiff.at(i)); + //qDebug() << "LossRefDiff"<* > vec; + vec << &Wave << &ProbLoss << &ProbRef << &ProbDiff; + QString err = LoadDoubleVectorsFromFile(fileName, vec); + if (!err.isEmpty()) return err; + + for (int i=0; i 1.0) return QString("Sum of probabilities is larger than 1.0 for wavelength of ") + QString::number(Wave.at(i)) + " nm"; + } + + if (Wave.isEmpty()) + return "No data were read from the file!"; + + return ""; +} + +#ifdef GUI +void SpectralBasicOpticalOverride::loadSpectralData(QWidget* caller) +{ + QString fileName = QFileDialog::getOpenFileName(caller, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", "", "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + + QVector< QVector* > vec; + vec << &Wave << &ProbLoss << &ProbRef << &ProbDiff; + QString err = LoadDoubleVectorsFromFile(fileName, vec); + if (!err.isEmpty()) message(err, caller); +} + +void SpectralBasicOpticalOverride::showLoaded(GraphWindowClass* GraphWindow) +{ + QVector Fr; + for (int i=0; iConstructTGraph(Wave, ProbLoss, "Absorption", "Wavelength, nm", "", 2, 20, 1, 2); + mg->Add(gLoss, "LP"); + TGraph* gRef = GraphWindow->ConstructTGraph(Wave, ProbRef, "Specular reflection", "Wavelength, nm", "", 4, 21, 1, 4); + mg->Add(gRef, "LP"); + TGraph* gDiff = GraphWindow->ConstructTGraph(Wave, ProbDiff, "Diffuse scattering", "Wavelength, nm", "", 7, 22, 1, 7); + mg->Add(gDiff, "LP"); + TGraph* gFr = GraphWindow->ConstructTGraph(Wave, Fr, "Fresnel", "Wavelength, nm", "", 1, 24, 1, 1, 1, 1); + mg->Add(gFr, "LP"); + + mg->SetMinimum(0); + GraphWindow->Draw(mg, "apl"); + mg->GetXaxis()->SetTitle("Wavelength, nm"); + mg->GetYaxis()->SetTitle("Probability"); + GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); +} + +void SpectralBasicOpticalOverride::showBinned(QWidget *widget, GraphWindowClass *GraphWindow) +{ + bool bWR; + double WaveFrom, WaveTo, WaveStep; + int WaveNodes; + MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); + initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + //TODO run checker + + if (!bWR) + { + QString s = "Simulation is configured as not wavelength-resolved\n"; + s += "All photons will have the same properties:\n"; + s +=QString("Absorption: %1").arg(probLoss) + "\n"; + s +=QString("Specular reflection: %1").arg(probRef) + "\n"; + s +=QString("Scattering: %1").arg(probDiff); + message(s, widget); + return; + } + + QVector waveIndex; + for (int i=0; i Fr; + for (int i=0; iConstructTGraph(waveIndex, ProbLossBinned, "Loss", "Wave index", "Loss", 2, 20, 1, 2); + mg->Add(gLoss, "LP"); + TGraph* gRef = GraphWindow->ConstructTGraph(waveIndex, ProbRefBinned, "Specular reflection", "Wave index", "Reflection", 4, 21, 1, 4); + mg->Add(gRef, "LP"); + TGraph* gDiff = GraphWindow->ConstructTGraph(waveIndex, ProbDiffBinned, "Diffuse scattering", "Wave index", "Scatter", 7, 22, 1, 7); + mg->Add(gDiff, "LP"); + TGraph* gFr = GraphWindow->ConstructTGraph(waveIndex, Fr, "Fresnel", "Wave index", "", 1, 24, 1, 1, 1, 1); + mg->Add(gFr, "LP"); + + mg->SetMinimum(0); + GraphWindow->Draw(mg, "apl"); + mg->GetXaxis()->SetTitle("Wave index"); + mg->GetYaxis()->SetTitle("Probability"); + GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); +} +#endif + +#ifdef GUI +QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) +{ + QFrame* f = new QFrame(); + f->setFrameStyle(QFrame::Box); + + QVBoxLayout* vl = new QVBoxLayout(f); + QHBoxLayout* l = new QHBoxLayout(); + QLabel* lab = new QLabel("Absorption, reflection and scattering:"); + l->addWidget(lab); + QPushButton* pb = new QPushButton("Load"); + pb->setToolTip("Every line of the file should contain 4 numbers:\nwavelength[nm] absorption_prob[0..1] reflection_prob[0..1] scattering_prob[0..1]"); + QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); + l->addWidget(pb); + pb = new QPushButton("Show"); + QObject::connect(pb, &QPushButton::clicked, [GraphWindow, this] {showLoaded(GraphWindow);}); + l->addWidget(pb); + pb = new QPushButton("Binned"); + QObject::connect(pb, &QPushButton::clicked, [caller, GraphWindow, this] {showBinned(caller, GraphWindow);}); + l->addWidget(pb); + vl->addLayout(l); + l = new QHBoxLayout(); + lab = new QLabel("Scattering model:"); + l->addWidget(lab); + QComboBox* com = new QComboBox(); + com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); + com->setCurrentIndex(scatterModel); + QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->scatterModel = index; } ); + l->addWidget(com); + vl->addLayout(l); + l = new QHBoxLayout(); + lab = new QLabel("For photons with WaveIndex=-1, assume wavelength of:"); + l->addWidget(lab); + QLineEdit* le = new QLineEdit(QString::number(effectiveWavelength)); + QDoubleValidator* val = new QDoubleValidator(f); + val->setNotation(QDoubleValidator::StandardNotation); + val->setBottom(0); + val->setDecimals(6); + le->setValidator(val); + QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->effectiveWavelength = le->text().toDouble(); } ); + l->addWidget(le); + lab = new QLabel("nm"); + l->addWidget(lab); + vl->addLayout(l); + + return f; +} +#endif + +const QString SpectralBasicOpticalOverride::checkOverrideData() +{ + //checking spectrum + if (Wave.size() == 0) return "Spectral data are not defined"; + if (Wave.size() != ProbLoss.size() || Wave.size() != ProbRef.size() || Wave.size() != ProbDiff.size()) return "Spectral data do not match in size"; + for (int i=0; i 1.0) return "absorption probability has to be in the range of [0, 1.0]"; + if (ProbDiff.at(i) < 0 || ProbDiff.at(i) > 1.0) return "scattering probability has to be in the range of [0, 1.0]"; + if (ProbRef.at(i) < 0 || ProbRef.at(i) > 1.0) return "scattering probability has to be in the range of [0, 1.0]"; + double sum = ProbLoss.at(i) + ProbRef.at(i) + ProbDiff.at(i); + if (sum > 1.0) return QString("Sum of probabilities is larger than 1.0 for wavelength of %1 nm").arg(Wave.at(i)); + } + if (scatterModel < 0 || scatterModel > 2) return "unknown scattering model"; + + //TODO check effective wavelength + //TODO check binned + + return ""; +} diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.h b/src/OpticalOverrides/spectralbasicopticaloverride.h new file mode 100644 index 00000000..e70824d7 --- /dev/null +++ b/src/OpticalOverrides/spectralbasicopticaloverride.h @@ -0,0 +1,60 @@ +#ifndef SPECTRALBASICOPTICALOVERRIDE_H +#define SPECTRALBASICOPTICALOVERRIDE_H + +#include "aopticaloverride.h" +#include "abasicopticaloverride.h" + +#include +#include + +class AMaterialParticleCollection; +class ATracerStateful; +class APhoton; +class QJsonObject; +class GraphWindowClass; + +class SpectralBasicOpticalOverride : public ABasicOpticalOverride +{ +public: + SpectralBasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); + virtual ~SpectralBasicOpticalOverride() {} + + virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved + + virtual const QString getType() const override {return "SimplisticSpectral_model";} + virtual const QString getAbbreviation() const override {return "SiSp";} + virtual const QString getReportLine() const override; + + // save/load config is not used for this type! + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; + + virtual void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; + const QString loadData(const QString& fileName); + +#ifdef GUI + virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; +#endif + + virtual const QString checkOverrideData() override; + + //parameters + QVector Wave; + QVector ProbLoss; //probability of absorption + QVector ProbLossBinned; //probability of absorption + QVector ProbRef; //probability of specular reflection + QVector ProbRefBinned; //probability of specular reflection + QVector ProbDiff; //probability of scattering + QVector ProbDiffBinned; //probability of scattering + double effectiveWavelength = 500; //if waveIndex of photon is -1, index correspinding to this wavelength will be used + double effectiveWaveIndex; + +private: +#ifdef GUI + void loadSpectralData(QWidget *caller); + void showLoaded(GraphWindowClass *GraphWindow); + void showBinned(QWidget *widget, GraphWindowClass *GraphWindow); +#endif +}; + +#endif // SPECTRALBASICOPTICALOVERRIDE_H diff --git a/src/ants2.pro b/src/ants2.pro index 37c95564..d11e42a8 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -352,7 +352,11 @@ SOURCES += main.cpp \ OpticalOverrides/ascriptopticaloverride.cpp \ common/atracerstateful.cpp \ common/aphoton.cpp \ - scriptmode/amathscriptinterface.cpp + scriptmode/amathscriptinterface.cpp \ + OpticalOverrides/fsnpopticaloverride.cpp \ + OpticalOverrides/awaveshifteroverride.cpp \ + OpticalOverrides/spectralbasicopticaloverride.cpp \ + OpticalOverrides/abasicopticaloverride.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -480,7 +484,11 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/aopticaloverridescriptinterface.h \ OpticalOverrides/ascriptopticaloverride.h \ common/atracerstateful.h \ - scriptmode/amathscriptinterface.h + scriptmode/amathscriptinterface.h \ + OpticalOverrides/fsnpopticaloverride.h \ + OpticalOverrides/awaveshifteroverride.h \ + OpticalOverrides/spectralbasicopticaloverride.h \ + OpticalOverrides/abasicopticaloverride.h # --- SIM --- ants2_SIM { @@ -492,8 +500,8 @@ ants2_SIM { modules/photon_generator.cpp \ modules/s2_generator.cpp \ modules/simulationmanager.cpp \ - modules/phscatclaudiomodel.cpp \ - modules/scatteronmetal.cpp \ + OpticalOverrides/phscatclaudiomodel.cpp \ + OpticalOverrides/scatteronmetal.cpp \ modules/aphotontracer.cpp \ modules/acompton.cpp \ modules/ageometrytester.cpp @@ -513,8 +521,8 @@ ants2_SIM { modules/photon_generator.h \ modules/s2_generator.h \ modules/simulationmanager.h \ - modules/phscatclaudiomodel.h \ - modules/scatteronmetal.h \ + OpticalOverrides/phscatclaudiomodel.h \ + OpticalOverrides/scatteronmetal.h \ modules/aphotontracer.h \ modules/acompton.h \ modules/ageometrytester.h diff --git a/src/common/aopticaloverride.cpp b/src/common/aopticaloverride.cpp index 37c9d2f8..c489c5fa 100644 --- a/src/common/aopticaloverride.cpp +++ b/src/common/aopticaloverride.cpp @@ -7,18 +7,11 @@ #include "asimulationstatistics.h" #include "atracerstateful.h" -#ifdef SIM -#include "phscatclaudiomodel.h" -#include "scatteronmetal.h" -#include "ascriptopticaloverride.h" -#endif - #include #include #include "TMath.h" #include "TRandom2.h" -#include "TH1I.h" #include "TH1.h" #ifdef GUI @@ -51,236 +44,27 @@ bool AOpticalOverride::readFromJson(const QJsonObject &json) } #ifdef GUI -#include QWidget *AOpticalOverride::getEditWidget(QWidget *, GraphWindowClass *) { QFrame* f = new QFrame(); f->setFrameStyle(QFrame::Box); f->setMinimumHeight(100); - - return f; -} -#endif - -BasicOpticalOverride::BasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo, double probLoss, double probRef, double probDiff, int scatterModel) - : AOpticalOverride(MatCollection, MatFrom, MatTo), - probLoss(probLoss), probRef(probRef), probDiff(probDiff), scatterModel(scatterModel) {} - -BasicOpticalOverride::BasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) - : AOpticalOverride(MatCollection, MatFrom, MatTo) {} - -AOpticalOverride::OpticalOverrideResultEnum BasicOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) -{ - double rnd = Resources.RandGen->Rndm(); - - // surface loss? - rnd -= probLoss; - if (rnd<0) - { - // qDebug()<<"Override: surface loss!"; - Photon->SimStat->OverrideSimplisticAbsorption++; - Status = Absorption; - return Absorbed; - } - - // specular reflection? - rnd -= probRef; - if (rnd<0) - { - // qDebug()<<"Override: specular reflection!"; - //rotating the vector: K = K - 2*(NK)*N - double NK = NormalVector[0]*Photon->v[0]; NK += NormalVector[1]*Photon->v[1]; NK += NormalVector[2]*Photon->v[2]; - Photon->v[0] -= 2.0*NK*NormalVector[0]; Photon->v[1] -= 2.0*NK*NormalVector[1]; Photon->v[2] -= 2.0*NK*NormalVector[2]; - - Photon->SimStat->OverrideSimplisticReflection++; - Status = SpikeReflection; - return Back; - } - - // scattering? - rnd -= probDiff; - if (rnd<0) - { - // qDebug()<<"scattering triggered"; - Photon->SimStat->OverrideSimplisticScatter++; - - switch (scatterModel) - { - case 0: //4Pi scattering - // qDebug()<<"4Pi scatter"; - Photon->RandomDir(Resources.RandGen); - // qDebug()<<"New direction:"<v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2] < 0) - { - // qDebug()<<" scattering back"; - Status = LambertianReflection; - return Back; - } - // qDebug()<<" continuing to the next volume"; - Status = Transmission; - return Forward; - - case 1: //2Pi lambertian, remaining in the same volume (back scattering) - { - // qDebug()<<"2Pi lambertian scattering backward"; - double norm2; - do - { - Photon->RandomDir(Resources.RandGen); - Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; - norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; - } - while (norm2 < 0.000001); - - double normInverted = 1.0/TMath::Sqrt(norm2); - Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; - Status = LambertianReflection; - return Back; - } - case 2: //2Pi lambertian, scattering to the next volume - { - // qDebug()<<"2Pi lambertian scattering forward"; - double norm2; - do - { - Photon->RandomDir(Resources.RandGen); - Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; - norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; - } - while (norm2 < 0.000001); - - double normInverted = 1.0/TMath::Sqrt(norm2); - Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; - Status = Transmission; - return Forward; - } - } - } - - // overrides NOT triggered - what is left is covered by Fresnel in the tracker code - // qDebug()<<"Overrides did not trigger, using fresnel"; - Status = Transmission; - return NotTriggered; -} - -const QString BasicOpticalOverride::getReportLine() const -{ - double probFresnel = 1.0 - (probRef + probDiff + probLoss); - QString s; - if (probLoss > 0) s += QString("Abs %1 +").arg(probLoss); - if (probRef > 0) s += QString("Spec %1 +").arg(probRef); - if (probDiff > 0) - { - switch( scatterModel ) - { - case 0: - s += "Iso "; - break; - case 1: - s += "Lamb_B "; - break; - case 2: - s += "Lamb_F "; - break; - } - s += QString::number(probDiff); - s += " +"; - } - if (probFresnel > 1e-10) s += QString("Fres %1 +").arg(probFresnel); - s.chop(2); - return s; -} - -void BasicOpticalOverride::writeToJson(QJsonObject &json) const -{ - AOpticalOverride::writeToJson(json); - - json["Abs"] = probLoss; - json["Spec"] = probRef; - json["Scat"] = probDiff; - json["ScatMode"] = scatterModel; -} - -bool BasicOpticalOverride::readFromJson(const QJsonObject &json) -{ - QString type = json["Model"].toString(); - if (type != getType()) return false; //file for wrong model! - - probLoss = json["Abs"].toDouble(); - probRef = json["Spec"].toDouble(); - probDiff = json["Scat"].toDouble(); - scatterModel = json["ScatMode"].toInt(); - return true; -} - -#ifdef GUI -QWidget *BasicOpticalOverride::getEditWidget(QWidget*, GraphWindowClass *) -{ - QFrame* f = new QFrame(); - f->setFrameStyle(QFrame::Box); - - QHBoxLayout* hl = new QHBoxLayout(f); - QVBoxLayout* l = new QVBoxLayout(); - QLabel* lab = new QLabel("Absorption:"); - l->addWidget(lab); - lab = new QLabel("Specular reflection:"); - l->addWidget(lab); - lab = new QLabel("Scattering:"); - l->addWidget(lab); - hl->addLayout(l); - l = new QVBoxLayout(); - QLineEdit* le = new QLineEdit(QString::number(probLoss)); - QDoubleValidator* val = new QDoubleValidator(f); - val->setNotation(QDoubleValidator::StandardNotation); - val->setBottom(0); - //val->setTop(1.0); //Qt(5.8.0) BUG: check does not work - val->setDecimals(6); - le->setValidator(val); - QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probLoss = le->text().toDouble(); } ); - l->addWidget(le); - le = new QLineEdit(QString::number(probRef)); - le->setValidator(val); - QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probRef = le->text().toDouble(); } ); - l->addWidget(le); - le = new QLineEdit(QString::number(probDiff)); - le->setValidator(val); - QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->probDiff = le->text().toDouble(); } ); - l->addWidget(le); - hl->addLayout(l); - l = new QVBoxLayout(); - lab = new QLabel(""); - l->addWidget(lab); - lab = new QLabel(""); - l->addWidget(lab); - QComboBox* com = new QComboBox(); - com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); - com->setCurrentIndex(scatterModel); - QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->scatterModel = index; } ); - l->addWidget(com); - hl->addLayout(l); - return f; } #endif -const QString BasicOpticalOverride::checkOverrideData() -{ - if (probLoss<0 || probLoss>1.0) return "Absorption probability should be within [0, 1.0]"; - if (probRef <0 || probRef >1.0) return "Reflection probability should be within [0, 1.0]"; - if (probDiff<0 || probDiff>1.0) return "Scattering probability should be within [0, 1.0]"; - - if (probLoss + probRef + probDiff > 1.0) return "Sum of all process probabilities cannot exceed 1.0"; - - return ""; -} +#include "abasicopticaloverride.h" +#include "spectralbasicopticaloverride.h" +#include "fsnpopticaloverride.h" +#include "awaveshifteroverride.h" +#include "phscatclaudiomodel.h" +#include "scatteronmetal.h" +#include "ascriptopticaloverride.h" AOpticalOverride *OpticalOverrideFactory(QString model, AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) { if (model == "Simplistic_model") - return new BasicOpticalOverride(MatCollection, MatFrom, MatTo); + return new ABasicOpticalOverride(MatCollection, MatFrom, MatTo); if (model == "SimplisticSpectral_model") return new SpectralBasicOpticalOverride(MatCollection, MatFrom, MatTo); else if (model == "Claudio_Model_V2") @@ -317,833 +101,3 @@ const QStringList ListOvAllOpticalOverrideTypes() return l; } - -AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) -{ - // Angular reflectance: fraction of light reflected at the interface bewteen - // medium 1 and medium 2 assuming non-polarized incident light: - // ==> Incident light goes from medium 1 (n1) into medium 2 (n2). - // ==> cos(0): perpendicular to the surface. - // ==> cos(Pi/2): grazing/parallel to the surface. - // NOTE that even if the incident light is not polarized (equal amounts of s- - // and p-), the reflected light may be polarized because different percentages - // of s-(perpendicular) and p-(parallel) polarized waves are/may be reflected. - - //refractive indexes of materials before and after the interface - double n1 = (*MatCollection)[MatFrom]->getRefractiveIndex(Photon->waveIndex); - double n2 = (*MatCollection)[MatTo]->getRefractiveIndex(Photon->waveIndex); - - //angle of incidence - double cos1 = 0; - for (int i=0; i<3; i++) - cos1 += NormalVector[i]*Photon->v[i]; - - //Calculating reflection probability - double fresnelUnpolarR; - double sin1sqr = 1.0 - cos1*cos1; - double nsqr = n2/n1; nsqr *= nsqr; - if (sin1sqr > nsqr) - fresnelUnpolarR = 1.0; - else - { - double f1 = nsqr * cos1; - double f2 = TMath::Sqrt( nsqr - sin1sqr ); - // p-polarized - double Rp12 = (f1-f2) / (f1+f2); Rp12 *= Rp12; - // s-polarized - double Rs12 = (cos1-f2) / (cos1+f2); Rs12 *= Rs12; - - fresnelUnpolarR = 0.5 * (Rp12+Rs12); - } - -// if random[0,1]Rndm() < fresnelUnpolarR) - { - //qDebug()<<"Override: specular reflection"; - //rotating the vector: K = K - 2*(NK)*N - Photon->v[0] -= 2.0*cos1*NormalVector[0]; Photon->v[1] -= 2.0*cos1*NormalVector[1]; Photon->v[2] -= 2.0*cos1*NormalVector[2]; - Status = SpikeReflection; - Photon->SimStat->OverrideFSNPspecular++; - return Back; - } - -// if random[0,1]>albedo kill photon else do diffuse reflection - if (Resources.RandGen->Rndm() > Albedo) - { - //qDebug()<<"Override: absorption"; - Status = Absorption; - Photon->SimStat->OverrideFSNPabs++; - return Absorbed; - } - - //qDebug() << "Override: Lambertian scattering"; - double norm2; - do - { - Photon->RandomDir(Resources.RandGen); - Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; - norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; - } - while (norm2 < 0.000001); - double normInverted = 1.0/TMath::Sqrt(norm2); - Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; - Status = LambertianReflection; - Photon->SimStat->OverrideFSNlambert++; - return Back; - -// OLD MODEL -//first absorption check is made agains albedo, if failed - photon lost -//if angle of incidence is smaller than critical angle -> diffuse scattering -// else -> specular reflection -// if (RandGen->Rndm() > Albedo) -// { //absorption! -// Status = Absorption; -// return Absorbed; -// } - -// //critical angle check -// double NK = 0; -// for (int i=0; i<3; i++) -// NK += NormalVector[i]*PhotonDir[i]; // NK = cos of the angle of incidence = cos1 -// double sin1 = sqrt(1.0 - NK*NK); -// double sin2 = n1/n2 * sin1; - -// if (fabs(sin2)>1.0) -// { //total internal! -// // qDebug()<<"Override: specular reflection!"; -// //rotating the vector: K = K - 2*(NK)*N -// PhotonDir[0] -= 2.0*NK*NormalVector[0]; PhotonDir[1] -= 2.0*NK*NormalVector[1]; PhotonDir[2] -= 2.0*NK*NormalVector[2]; -// Status = SpikeReflection; -// return Back; -// } - -// //else diffuse -// // qDebug()<<"2Pi lambertian scattering backward"; -// double norm2; -// do -// { -// RandomDir(RandGen, PhotonDir); -// PhotonDir[0] -= NormalVector[0]; PhotonDir[1] -= NormalVector[1]; PhotonDir[2] -= NormalVector[2]; -// norm2 = PhotonDir[0]*PhotonDir[0] + PhotonDir[1]*PhotonDir[1] + PhotonDir[2]*PhotonDir[2]; -// } -// while (norm2 < 0.000001); - -// double normInverted = 1.0/TMath::Sqrt(norm2); -// PhotonDir[0] *= normInverted; PhotonDir[1] *= normInverted; PhotonDir[2] *= normInverted; -// // qDebug()<<"Photon dir after scatter:"<setFrameStyle(QFrame::Box); - - QHBoxLayout* l = new QHBoxLayout(f); - QLabel* lab = new QLabel("Albedo:"); - l->addWidget(lab); - QLineEdit* le = new QLineEdit(QString::number(Albedo)); - QDoubleValidator* val = new QDoubleValidator(f); - val->setNotation(QDoubleValidator::StandardNotation); - val->setBottom(0); - //val->setTop(1.0); //Qt(5.8.0) BUG: check does not work - val->setDecimals(6); - le->setValidator(val); - QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->Albedo = le->text().toDouble(); } ); - l->addWidget(le); - - return f; -} -#endif - -const QString FSNPOpticalOverride::checkOverrideData() -{ - if (Albedo<0 || Albedo>1.0) return "Albedo should be within [0, 1.0]"; - return ""; -} - -AWaveshifterOverride::AWaveshifterOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo, int ReemissionModel) - : AOpticalOverride(MatCollection, MatFrom, MatTo), ReemissionModel(ReemissionModel) -{ - Spectrum = 0; -} - -AWaveshifterOverride::~AWaveshifterOverride() -{ - if (Spectrum) delete Spectrum; -} - -void AWaveshifterOverride::initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) -{ - if (bWaveResolved) - { - WaveFrom = waveFrom; - WaveStep = waveStep; - WaveNodes = waveNodes; - - ConvertToStandardWavelengthes(&ReemissionProbability_lambda, &ReemissionProbability, WaveFrom, WaveStep, WaveNodes, &ReemissionProbabilityBinned); - - QVector y; - ConvertToStandardWavelengthes(&EmissionSpectrum_lambda, &EmissionSpectrum, WaveFrom, WaveStep, WaveNodes, &y); - TString name = "WLSEmSpec"; - name += MatFrom; - name += "to"; - name += MatTo; - if (Spectrum) delete Spectrum; - Spectrum = new TH1D(name,"", WaveNodes, WaveFrom, WaveFrom+WaveStep*WaveNodes); - for (int j = 1; jSetBinContent(j, y[j-1]); - Spectrum->GetIntegral(); //to make thread safe - } - else - { - ReemissionProbabilityBinned.clear(); - delete Spectrum; Spectrum = 0; - } -} - -AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) -{ - //currently assuming there is no scattering on original wavelength - only reemission or absorption - - if ( !Spectrum || //emission spectrum not defined - Photon->waveIndex == -1 || //or photon without wavelength - ReemissionProbabilityBinned.isEmpty() ) //or probability not defined - { - Status = Absorption; - Photon->SimStat->OverrideWLSabs++; - return Absorbed; - } - - double prob = ReemissionProbabilityBinned.at(Photon->waveIndex); // probability of reemission - if (Resources.RandGen->Rndm() < prob) - { - //triggered! - - //generating new wavelength and waveindex - double wavelength; - int waveIndex; - int attempts = -1; - do - { - attempts++; - if (attempts > 9) - { - Status = Absorption; - Photon->SimStat->OverrideWLSabs++; - return Absorbed; - } - wavelength = Spectrum->GetRandom(); - waveIndex = (wavelength - WaveFrom)/WaveStep; - } - while (waveIndex < Photon->waveIndex); //conserving energy - - Photon->waveIndex = waveIndex; - Photon->SimStat->OverrideWLSshift++; - - if (ReemissionModel == 0) - { - Photon->RandomDir(Resources.RandGen); - //enering new volume or backscattering? - //normal is in the positive direction in respect to the original direction! - if (Photon->v[0]*NormalVector[0] + Photon->v[1]*NormalVector[1] + Photon->v[2]*NormalVector[2] < 0) - { - // qDebug()<<" scattering back"; - Status = LambertianReflection; - return Back; - } - // qDebug()<<" continuing to the next volume"; - Status = Transmission; - return Forward; - } - - double norm2 = 0; - if (ReemissionModel == 1) - { - // qDebug()<<"2Pi lambertian scattering backward"; - do - { - Photon->RandomDir(Resources.RandGen); - Photon->v[0] -= NormalVector[0]; Photon->v[1] -= NormalVector[1]; Photon->v[2] -= NormalVector[2]; - norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; - } - while (norm2 < 0.000001); - - double normInverted = 1.0/TMath::Sqrt(norm2); - Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; - Status = LambertianReflection; - - return Back; - } - - // qDebug()<<"2Pi lambertian scattering forward"; - do - { - Photon->RandomDir(Resources.RandGen); - Photon->v[0] += NormalVector[0]; Photon->v[1] += NormalVector[1]; Photon->v[2] += NormalVector[2]; - norm2 = Photon->v[0]*Photon->v[0] + Photon->v[1]*Photon->v[1] + Photon->v[2]*Photon->v[2]; - } - while (norm2 < 0.000001); - - double normInverted = 1.0/TMath::Sqrt(norm2); - Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; - Status = Transmission; - return Forward; - } - - // else absorption - Status = Absorption; - Photon->SimStat->OverrideWLSabs++; - return Absorbed; -} - -const QString AWaveshifterOverride::getReportLine() const -{ - return QString(); -} - -void AWaveshifterOverride::writeToJson(QJsonObject &json) const -{ - AOpticalOverride::writeToJson(json); - - QJsonArray arRP; - writeTwoQVectorsToJArray(ReemissionProbability_lambda, ReemissionProbability, arRP); - json["ReemissionProbability"] = arRP; - QJsonArray arEm; - writeTwoQVectorsToJArray(EmissionSpectrum_lambda, EmissionSpectrum, arEm); - json["EmissionSpectrum"] = arEm; - json["ReemissionModel"] = ReemissionModel; -} - -bool AWaveshifterOverride::readFromJson(const QJsonObject &json) -{ - //QString type = json["Model"].toString(); - //if (type != getType()) return false; //file for wrong model! - if (!AOpticalOverride::readFromJson(json)) return false; - - QJsonArray arRP = json["ReemissionProbability"].toArray(); - readTwoQVectorsFromJArray(arRP, ReemissionProbability_lambda, ReemissionProbability); - QJsonArray arEm = json["EmissionSpectrum"].toArray(); - readTwoQVectorsFromJArray(arEm, EmissionSpectrum_lambda, EmissionSpectrum); - - ReemissionModel = 1; - parseJson(json, "ReemissionModel", ReemissionModel); - - return true; -} - -#ifdef GUI -QWidget *AWaveshifterOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) -{ - QFrame* f = new QFrame(); - f->setFrameStyle(QFrame::Box); - - QVBoxLayout* vl = new QVBoxLayout(f); - QHBoxLayout* l = new QHBoxLayout(); - QLabel* lab = new QLabel("Reemission generation:"); - l->addWidget(lab); - QComboBox* com = new QComboBox(); - com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); - com->setCurrentIndex(ReemissionModel); - QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->ReemissionModel = index; } ); - l->addWidget(com); - vl->addLayout(l); - l = new QHBoxLayout(); - QVBoxLayout* vv = new QVBoxLayout(); - lab = new QLabel("Reemission probability:"); - vv->addWidget(lab); - lab = new QLabel("Emission spectrum:"); - vv->addWidget(lab); - l->addLayout(vv); - vv = new QVBoxLayout(); - QPushButton* pb = new QPushButton("Load"); - pb->setToolTip("Every line of the file should contain 2 numbers:\nwavelength[nm] reemission_probability[0..1]"); - QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadReemissionProbability(caller);}); - vv->addWidget(pb); - pb = new QPushButton("Load"); - pb->setToolTip("Every line of the file should contain 2 numbers:\nwavelength[nm] relative_intencity[>=0]"); - QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadEmissionSpectrum(caller);}); - vv->addWidget(pb); - l->addLayout(vv); - vv = new QVBoxLayout(); - pb = new QPushButton("Show"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showReemissionProbability(GraphWindow, caller);}); - vv->addWidget(pb); - pb = new QPushButton("Show"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showEmissionSpectrum(GraphWindow, caller);}); - vv->addWidget(pb); - l->addLayout(vv); - vv = new QVBoxLayout(); - pb = new QPushButton("Binned"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedReemissionProbability(GraphWindow, caller);}); - vv->addWidget(pb); - pb = new QPushButton("Binned"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedEmissionSpectrum(GraphWindow, caller);}); - vv->addWidget(pb); - l->addLayout(vv); - vl->addLayout(l); - lab = new QLabel("If simulation is NOT wavelength-resolved, this override does nothing!"); - lab->setAlignment(Qt::AlignCenter); - vl->addWidget(lab); - - return f; -} -#endif - -#ifdef GUI -void AWaveshifterOverride::loadReemissionProbability(QWidget* caller) -{ - QString fileName = QFileDialog::getOpenFileName(caller, "Load reemission probability", "", "Data files (*.dat *.txt);;All files (*)"); - if (fileName.isEmpty()) return; - //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); - QVector X, Y; - int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); - if (ret == 0) - { - ReemissionProbability_lambda = X; - ReemissionProbability = Y; - } -} - -void AWaveshifterOverride::loadEmissionSpectrum(QWidget *caller) -{ - QString fileName = QFileDialog::getOpenFileName(caller, "Load emission spectrum", "", "Data files (*.dat *.txt);;All files (*)"); - if (fileName.isEmpty()) return; - //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); - QVector X, Y; - int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); - if (ret == 0) - { - EmissionSpectrum_lambda = X; - EmissionSpectrum = Y; - } -} - -void AWaveshifterOverride::showReemissionProbability(GraphWindowClass *GraphWindow, QWidget* caller) -{ - if (ReemissionProbability_lambda.isEmpty()) - { - message("No data were loaded", caller); - return; - } - TGraph* gr = GraphWindow->ConstructTGraph(ReemissionProbability_lambda, ReemissionProbability, "Reemission probability", "Wavelength, nm", "Reemission probability, a.u.", 2, 20, 1, 2, 2); - gr->SetMinimum(0); - GraphWindow->Draw(gr, "apl"); -} - -void AWaveshifterOverride::showEmissionSpectrum(GraphWindowClass *GraphWindow, QWidget *caller) -{ - if (EmissionSpectrum_lambda.isEmpty()) - { - message("No data were loaded", caller); - return; - } - TGraph* gr = GraphWindow->ConstructTGraph(EmissionSpectrum_lambda, EmissionSpectrum, - "Emission spectrum", "Wavelength, nm", "Relative intensity, a.u.", - 4, 20, 1, - 4, 2); - gr->SetMinimum(0); - GraphWindow->Draw(gr, "apl"); -} - -void AWaveshifterOverride::showBinnedReemissionProbability(GraphWindowClass *GraphWindow, QWidget *caller) -{ - bool bWR; - double WaveFrom, WaveTo, WaveStep; - int WaveNodes; - MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); - - //TODO run checker - - if (!bWR) - { - message("Simulation is NOT wavelength resolved, override is inactive!", caller); - return; - } - - QVector waveIndex; - for (int i=0; iConstructTGraph(waveIndex, ReemissionProbabilityBinned, - "Reemission probability (binned)", "Wave index", "Reemission probability, a.u.", - 2, 20, 1, - 2, 2); - gr->SetMinimum(0); - GraphWindow->Draw(gr, "apl"); -} - -void AWaveshifterOverride::showBinnedEmissionSpectrum(GraphWindowClass *GraphWindow, QWidget *caller) -{ - bool bWR; - double WaveFrom, WaveTo, WaveStep; - int WaveNodes; - MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); - - //TODO run checker - - if (!bWR) - { - message("Simulation is NOT wavelength resolved, override is inactive!", caller); - return; - } - - double integral = Spectrum->ComputeIntegral(); - if (integral <= 0) - { - message("Binned emission spectrum: integral <=0, override will report an error!", caller); - return; - } - - TH1D* SpectrumCopy = new TH1D(*Spectrum); - SpectrumCopy->SetTitle("Binned emission spectrum"); - SpectrumCopy->GetXaxis()->SetTitle("Wavelength, nm"); - SpectrumCopy->GetYaxis()->SetTitle("Relative intensity, a.u."); - GraphWindow->Draw(SpectrumCopy, "hist"); //gets ownership of the copy -} -#endif - -const QString AWaveshifterOverride::checkOverrideData() -{ - if (ReemissionProbability_lambda.isEmpty()) - return "Reemission probability not loaded"; - if (ReemissionProbability_lambda.size() != ReemissionProbability.size()) - return "Mismatch in reemission probability data"; - - if (EmissionSpectrum_lambda.isEmpty()) - return "Emission spectrum not loaded"; - if (EmissionSpectrum_lambda.size() != EmissionSpectrum.size()) - return "Mismatch in emission spectrum data"; - - bool bWR; - double WaveFrom, WaveTo, WaveStep; - int WaveNodes; - MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); - - if (bWR && Spectrum->ComputeIntegral() <= 0) - return "Binned emission spectrum: integral should be > 0"; - return ""; -} - -// ---------------- SpectralSimplistic ------------------- -SpectralBasicOpticalOverride::SpectralBasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) - : BasicOpticalOverride(MatCollection, MatFrom, MatTo, 0,0,0, 1), effectiveWavelength(500) -{ - Wave << 500; - ProbLoss << 0; - ProbRef << 0; - ProbDiff << 0; -} - -SpectralBasicOpticalOverride::SpectralBasicOpticalOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo, int ScatterModel, double EffWave) - : BasicOpticalOverride(MatCollection, MatFrom, MatTo, 0,0,0, ScatterModel), effectiveWavelength(EffWave) -{ - Wave << 500; - ProbLoss << 0; - ProbRef << 0; - ProbDiff << 0; -} - -AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) -{ - int waveIndex = Photon->waveIndex; - if (waveIndex == -1) waveIndex = effectiveWaveIndex; - - probLoss = ProbLossBinned.at(waveIndex); - probDiff = ProbDiffBinned.at(waveIndex); - probRef = ProbRefBinned.at(waveIndex); - - return BasicOpticalOverride::calculate(Resources, Photon, NormalVector); -} - -const QString SpectralBasicOpticalOverride::getReportLine() const -{ - return QString("Spectral data with %1 points").arg(Wave.size()); -} - -void SpectralBasicOpticalOverride::writeToJson(QJsonObject &json) const -{ - AOpticalOverride::writeToJson(json); - - json["ScatMode"] = scatterModel; - json["EffWavelength"] = effectiveWavelength; - - if (Wave.size() != ProbLoss.size() || Wave.size() != ProbRef.size() || Wave.size() != ProbDiff.size()) - { - qWarning() << "Mismatch in data size for SpectralBasicOverride! skipping data!"; - return; - } - QJsonArray sp; - for (int i=0; i= waveNodes ) effectiveWaveIndex = waveNodes - 1; - //qDebug() << "Eff wave"< effectiveWavelength) break; - - //closest is i-1 or i - if (i != 0) - if ( fabs(Wave.at(i-1) - effectiveWavelength) < fabs(Wave.at(i) - effectiveWavelength) ) i--; - } - - //qDebug() << "Selected i = "<< i << "with wave"<(1, ProbLoss.at(i)); - ProbRefBinned = QVector(1, ProbRef.at(i)); - ProbDiffBinned = QVector(1, ProbDiff.at(i)); - //qDebug() << "LossRefDiff"<* > vec; - vec << &Wave << &ProbLoss << &ProbRef << &ProbDiff; - QString err = LoadDoubleVectorsFromFile(fileName, vec); - if (!err.isEmpty()) return err; - - for (int i=0; i 1.0) return QString("Sum of probabilities is larger than 1.0 for wavelength of ") + QString::number(Wave.at(i)) + " nm"; - } - - if (Wave.isEmpty()) - return "No data were read from the file!"; - - return ""; -} - -#ifdef GUI -void SpectralBasicOpticalOverride::loadSpectralData(QWidget* caller) -{ - QString fileName = QFileDialog::getOpenFileName(caller, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", "", "Data files (*.dat *.txt);;All files (*)"); - if (fileName.isEmpty()) return; - - QVector< QVector* > vec; - vec << &Wave << &ProbLoss << &ProbRef << &ProbDiff; - QString err = LoadDoubleVectorsFromFile(fileName, vec); - if (!err.isEmpty()) message(err, caller); -} - -#include "TMultiGraph.h" -#include "TGraph.h" -#include "graphwindowclass.h" -void SpectralBasicOpticalOverride::showLoaded(GraphWindowClass* GraphWindow) -{ - QVector Fr; - for (int i=0; iConstructTGraph(Wave, ProbLoss, "Absorption", "Wavelength, nm", "", 2, 20, 1, 2); - mg->Add(gLoss, "LP"); - TGraph* gRef = GraphWindow->ConstructTGraph(Wave, ProbRef, "Specular reflection", "Wavelength, nm", "", 4, 21, 1, 4); - mg->Add(gRef, "LP"); - TGraph* gDiff = GraphWindow->ConstructTGraph(Wave, ProbDiff, "Diffuse scattering", "Wavelength, nm", "", 7, 22, 1, 7); - mg->Add(gDiff, "LP"); - TGraph* gFr = GraphWindow->ConstructTGraph(Wave, Fr, "Fresnel", "Wavelength, nm", "", 1, 24, 1, 1, 1, 1); - mg->Add(gFr, "LP"); - - mg->SetMinimum(0); - GraphWindow->Draw(mg, "apl"); - mg->GetXaxis()->SetTitle("Wavelength, nm"); - mg->GetYaxis()->SetTitle("Probability"); - GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); -} - -void SpectralBasicOpticalOverride::showBinned(QWidget *widget, GraphWindowClass *GraphWindow) -{ - bool bWR; - double WaveFrom, WaveTo, WaveStep; - int WaveNodes; - MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); - - //TODO run checker - - if (!bWR) - { - QString s = "Simulation is configured as not wavelength-resolved\n"; - s += "All photons will have the same properties:\n"; - s +=QString("Absorption: %1").arg(probLoss) + "\n"; - s +=QString("Specular reflection: %1").arg(probRef) + "\n"; - s +=QString("Scattering: %1").arg(probDiff); - message(s, widget); - return; - } - - QVector waveIndex; - for (int i=0; i Fr; - for (int i=0; iConstructTGraph(waveIndex, ProbLossBinned, "Loss", "Wave index", "Loss", 2, 20, 1, 2); - mg->Add(gLoss, "LP"); - TGraph* gRef = GraphWindow->ConstructTGraph(waveIndex, ProbRefBinned, "Specular reflection", "Wave index", "Reflection", 4, 21, 1, 4); - mg->Add(gRef, "LP"); - TGraph* gDiff = GraphWindow->ConstructTGraph(waveIndex, ProbDiffBinned, "Diffuse scattering", "Wave index", "Scatter", 7, 22, 1, 7); - mg->Add(gDiff, "LP"); - TGraph* gFr = GraphWindow->ConstructTGraph(waveIndex, Fr, "Fresnel", "Wave index", "", 1, 24, 1, 1, 1, 1); - mg->Add(gFr, "LP"); - - mg->SetMinimum(0); - GraphWindow->Draw(mg, "apl"); - mg->GetXaxis()->SetTitle("Wave index"); - mg->GetYaxis()->SetTitle("Probability"); - GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); -} -#endif - -#ifdef GUI -QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller, GraphWindowClass *GraphWindow) -{ - QFrame* f = new QFrame(); - f->setFrameStyle(QFrame::Box); - - QVBoxLayout* vl = new QVBoxLayout(f); - QHBoxLayout* l = new QHBoxLayout(); - QLabel* lab = new QLabel("Absorption, reflection and scattering:"); - l->addWidget(lab); - QPushButton* pb = new QPushButton("Load"); - pb->setToolTip("Every line of the file should contain 4 numbers:\nwavelength[nm] absorption_prob[0..1] reflection_prob[0..1] scattering_prob[0..1]"); - QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); - l->addWidget(pb); - pb = new QPushButton("Show"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, this] {showLoaded(GraphWindow);}); - l->addWidget(pb); - pb = new QPushButton("Binned"); - QObject::connect(pb, &QPushButton::clicked, [caller, GraphWindow, this] {showBinned(caller, GraphWindow);}); - l->addWidget(pb); - vl->addLayout(l); - l = new QHBoxLayout(); - lab = new QLabel("Scattering model:"); - l->addWidget(lab); - QComboBox* com = new QComboBox(); - com->addItem("Isotropic (4Pi)"); com->addItem("Lambertian, 2Pi back"); com->addItem("Lambertian, 2Pi forward"); - com->setCurrentIndex(scatterModel); - QObject::connect(com, static_cast(&QComboBox::activated), [this](int index) { this->scatterModel = index; } ); - l->addWidget(com); - vl->addLayout(l); - l = new QHBoxLayout(); - lab = new QLabel("For photons with WaveIndex=-1, assume wavelength of:"); - l->addWidget(lab); - QLineEdit* le = new QLineEdit(QString::number(effectiveWavelength)); - QDoubleValidator* val = new QDoubleValidator(f); - val->setNotation(QDoubleValidator::StandardNotation); - val->setBottom(0); - val->setDecimals(6); - le->setValidator(val); - QObject::connect(le, &QLineEdit::editingFinished, [le, this]() { this->effectiveWavelength = le->text().toDouble(); } ); - l->addWidget(le); - lab = new QLabel("nm"); - l->addWidget(lab); - vl->addLayout(l); - - return f; -} -#endif - -const QString SpectralBasicOpticalOverride::checkOverrideData() -{ - //checking spectrum - if (Wave.size() == 0) return "Spectral data are not defined"; - if (Wave.size() != ProbLoss.size() || Wave.size() != ProbRef.size() || Wave.size() != ProbDiff.size()) return "Spectral data do not match in size"; - for (int i=0; i 1.0) return "absorption probability has to be in the range of [0, 1.0]"; - if (ProbDiff.at(i) < 0 || ProbDiff.at(i) > 1.0) return "scattering probability has to be in the range of [0, 1.0]"; - if (ProbRef.at(i) < 0 || ProbRef.at(i) > 1.0) return "scattering probability has to be in the range of [0, 1.0]"; - double sum = ProbLoss.at(i) + ProbRef.at(i) + ProbDiff.at(i); - if (sum > 1.0) return QString("Sum of probabilities is larger than 1.0 for wavelength of %1 nm").arg(Wave.at(i)); - } - if (scatterModel < 0 || scatterModel > 2) return "unknown scattering model"; - - //TODO check effective wavelength - //TODO check binned - - return ""; -} diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 81322d8f..765e4f39 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -1,23 +1,17 @@ #ifndef OPTICALOVERRIDECLASS_H #define OPTICALOVERRIDECLASS_H -#include #include class AOpticalOverride; class APhoton; class AMaterialParticleCollection; -class TRandom2; -class TH1I; class QJsonObject; -class TH1D; -class QWidget; -class TObject; -class QObject; class GraphWindowClass; class ATracerStateful; +class QWidget; -// !!! +// ---- !!! ---- // modify these two functions if you want to register a new override type AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); const QStringList ListOvAllOpticalOverrideTypes(); @@ -65,155 +59,4 @@ class AOpticalOverride int MatFrom, MatTo; // material index of material before(from) and after(to) the optical interface }; -class BasicOpticalOverride : public AOpticalOverride -{ -public: - BasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo, double probLoss, double probRef, double probDiff, int scatterModel); - BasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); - virtual ~BasicOpticalOverride() {} - - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - - virtual const QString getType() const override {return "Simplistic_model";} - virtual const QString getAbbreviation() const override {return "Simp";} - virtual const QString getReportLine() const override; - - // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) const override; - virtual bool readFromJson(const QJsonObject &json) override; - -#ifdef GUI - virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; -#endif - virtual const QString checkOverrideData() override; - - //--parameters-- - double probLoss = 0; //probability of absorption - double probRef = 0; //probability of specular reflection - double probDiff = 0; //probability of scattering - int scatterModel = 1; //0 - 4Pi, 1 - 2Pi back, 2 - 2Pi forward -}; - -class FSNPOpticalOverride : public AOpticalOverride -{ -public: - FSNPOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo, double albedo) - : AOpticalOverride(MatCollection, MatFrom, MatTo), Albedo(albedo) {} - FSNPOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) - : AOpticalOverride(MatCollection, MatFrom, MatTo) {Albedo = 0.95;} - virtual ~FSNPOpticalOverride() {} - - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - - virtual const QString getType() const override {return "FS_NP";} - virtual const QString getAbbreviation() const override {return "FSNP";} - virtual const QString getReportLine() const override; - - // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) const override; - virtual bool readFromJson(const QJsonObject &json) override; - -#ifdef GUI - virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; -#endif - virtual const QString checkOverrideData() override; - - //-- parameters -- - double Albedo; -}; - -class AWaveshifterOverride : public AOpticalOverride -{ -public: - AWaveshifterOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo, int ReemissionModel = 1); - virtual ~AWaveshifterOverride(); - - void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved - - virtual const QString getType() const override {return "SurfaceWLS";} - virtual const QString getAbbreviation() const override {return "WLS";} - virtual const QString getReportLine() const override; - - // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) const; - virtual bool readFromJson(const QJsonObject &json); - -#ifdef GUI - virtual QWidget* getEditWidget(QWidget *caller, GraphWindowClass* GraphWindow) override; -#endif - - virtual const QString checkOverrideData() override; - - //-- parameters -- - int ReemissionModel = 1; //0-isotropic (4Pi), 1-Lamb back (2Pi), 2-Lamb forward (2Pi) - QVector ReemissionProbability_lambda; - QVector ReemissionProbability; - QVector ReemissionProbabilityBinned; - - QVector EmissionSpectrum_lambda; - QVector EmissionSpectrum; - TH1D* Spectrum; - - //tmp parameters - double WaveFrom; - double WaveStep; - int WaveNodes; - -private: -#ifdef GUI - void loadReemissionProbability(QWidget *caller); - void loadEmissionSpectrum(QWidget *caller); - void showReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); - void showEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); - void showBinnedReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); - void showBinnedEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); -#endif -}; - -class SpectralBasicOpticalOverride : public BasicOpticalOverride -{ -public: - SpectralBasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); - SpectralBasicOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo, int ScatterModel, double EffWave); - virtual ~SpectralBasicOpticalOverride() {} - - virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - - virtual const QString getType() const override {return "SimplisticSpectral_model";} - virtual const QString getAbbreviation() const override {return "SiSp";} - virtual const QString getReportLine() const override; - - // save/load config is not used for this type! - virtual void writeToJson(QJsonObject &json) const override; - virtual bool readFromJson(const QJsonObject &json) override; - - virtual void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; - const QString loadData(const QString& fileName); - -#ifdef GUI - virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow) override; -#endif - - virtual const QString checkOverrideData() override; - - //parameters - QVector Wave; - QVector ProbLoss; //probability of absorption - QVector ProbLossBinned; //probability of absorption - QVector ProbRef; //probability of specular reflection - QVector ProbRefBinned; //probability of specular reflection - QVector ProbDiff; //probability of scattering - QVector ProbDiffBinned; //probability of scattering - double effectiveWavelength = 500; //if waveIndex of photon is -1, index correspinding to this wavelength will be used - double effectiveWaveIndex; - -private: -#ifdef GUI - void loadSpectralData(QWidget *caller); - void showLoaded(GraphWindowClass *GraphWindow); - void showBinned(QWidget *widget, GraphWindowClass *GraphWindow); -#endif -}; - #endif // OPTICALOVERRIDECLASS_H diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index f3899b63..3d5fb4ae 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -682,6 +682,7 @@ void AMaterialParticleCollection::writeMaterialToJson(int imat, QJsonObject &jso MaterialCollectionData[imat]->writeToJson(json, this); } +#include "abasicopticaloverride.h" bool AMaterialParticleCollection::readFromJson(QJsonObject &json) { readParticleCollectionFromJson(json); @@ -743,15 +744,23 @@ bool AMaterialParticleCollection::readFromJson(QJsonObject &json) continue; } double Abs, Scat, Spec; - int ScatMode; + Abs = Scat = Spec = 0; + int ScatMode = 1; parseJson(jj, "Loss", Abs); parseJson(jj, "Ref", Spec); parseJson(jj, "Scat", Scat); parseJson(jj, "ScatModel", ScatMode); - BasicOpticalOverride* ov = new BasicOpticalOverride(this, MatFrom, MatTo, Abs, Spec, Scat, ScatMode ); + ABasicOpticalOverride* ov = new ABasicOpticalOverride(this, MatFrom, MatTo); if (!ov) qWarning() << MaterialCollectionData[MatFrom]->name << ": optical override load failed!"; - else MaterialCollectionData[MatFrom]->OpticalOverrides[MatTo] = ov; + else + { + MaterialCollectionData[MatFrom]->OpticalOverrides[MatTo] = ov; + ov->probLoss = Abs; + ov->probRef = Spec; + ov->probDiff = Scat; + ov->scatterModel = ScatMode; + } } } fLogLogInterpolation = false; From 9f2b27a266b577ec7d4d8ab2c265524c3d4f4b02 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 4 Oct 2018 18:42:27 +0100 Subject: [PATCH 041/140] ++ --- src/OpticalOverrides/ascriptopticaloverride.cpp | 5 +++++ src/OpticalOverrides/ascriptopticaloverride.h | 1 + src/common/aopticaloverride.h | 8 ++++---- src/gui/mainwindow.cpp | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index e57ca654..be77a12f 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -39,6 +39,11 @@ const QString AScriptOpticalOverride::getReportLine() const return QString(); } +const QString AScriptOpticalOverride::getLongReportLine() const +{ + return Script; +} + void AScriptOpticalOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); diff --git a/src/OpticalOverrides/ascriptopticaloverride.h b/src/OpticalOverrides/ascriptopticaloverride.h index ddc68f44..57c59839 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.h +++ b/src/OpticalOverrides/ascriptopticaloverride.h @@ -16,6 +16,7 @@ class AScriptOpticalOverride : public AOpticalOverride virtual const QString getType() const override {return "CustomScript";} virtual const QString getAbbreviation() const override {return "JS";} virtual const QString getReportLine() const override; + virtual const QString getLongReportLine() const; virtual void writeToJson(QJsonObject &json) const override; virtual bool readFromJson(const QJsonObject &json) override; diff --git a/src/common/aopticaloverride.h b/src/common/aopticaloverride.h index 765e4f39..68c0b977 100644 --- a/src/common/aopticaloverride.h +++ b/src/common/aopticaloverride.h @@ -16,7 +16,7 @@ class QWidget; AOpticalOverride* OpticalOverrideFactory(QString model, AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); const QStringList ListOvAllOpticalOverrideTypes(); -//base optical override class - all new overrides must inherit from it + class AOpticalOverride { public: @@ -33,6 +33,7 @@ class AOpticalOverride virtual const QString getType() const = 0; virtual const QString getAbbreviation() const = 0; //for GUI: used to identify - must be short (<= 4 chars) - try to make unique virtual const QString getReportLine() const = 0; // for GUI: used to reports override status (try to make as short as possible) + virtual const QString getLongReportLine() const {return getReportLine();} //for GUI: used in overlap map //TODO: initializeWaveResolved() -> no need to transfer data, MatCollection knows the settings virtual void initializeWaveResolved(bool /*bWaveResolved*/, double /*waveFrom*/, double /*waveStep*/, int /*waveNodes*/) {} //override if override has wavelength-resolved data @@ -41,15 +42,14 @@ class AOpticalOverride virtual void writeToJson(QJsonObject &json) const; virtual bool readFromJson(const QJsonObject &json); - //next one is used by MatCollection when a material is removed + //used by MatCollection when a material is removed: void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} #ifdef GUI virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow); #endif - //TODO after all are done, make = 0 - virtual const QString checkOverrideData() {return "";} //cannot be const - w.resolved needs rebin + virtual const QString checkOverrideData() = 0; //cannot be const - w.resolved needs rebin // read-out variables for standalone checker only (not multithreaded) ScatterStatusEnum Status; // type of interaction which happened - use in 1 thread only! diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 167c0737..68f9ded1 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4921,8 +4921,10 @@ void MainWindow::on_pbShowOverrideMap_clicked() int numMat = MpCollection->countMaterials(); QDialog* d = new QDialog(this); - d->setWindowTitle("Optical override Vertical->Horizontal. Double click to define / edit override"); + d->setWindowTitle("Map of optical overrides"); QVBoxLayout* l = new QVBoxLayout(d); + QLabel* lab = new QLabel("Override from (vertical) -> to (horizontal). Double click to define / edit override"); + l->addWidget(lab); QTableWidget* tw = new QTableWidget(numMat, numMat); l->addWidget(tw); @@ -4940,7 +4942,7 @@ void MainWindow::on_pbShowOverrideMap_clicked() if (ov) { it->setBackground(QBrush(Qt::lightGray)); - it->setToolTip(ov->getReportLine()); + it->setToolTip(ov->getLongReportLine()); } it->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); From ae7b37455bc06e6ea784cb9030e992617a912da8 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 5 Oct 2018 12:43:26 +0100 Subject: [PATCH 042/140] global settings are now singleton class --- .../ascriptopticaloverride.cpp | 3 +- src/OpticalOverrides/awaveshifteroverride.cpp | 4 +- src/ants2.pro | 12 +- src/common/aglobalsettings.cpp | 221 ++++++++++++++++ src/common/aglobalsettings.h | 99 +++++++ src/common/ajsontools.cpp | 4 +- src/common/ajsontools.h | 4 +- src/common/globalsettingsclass.cpp | 242 ------------------ src/common/globalsettingsclass.h | 86 ------- .../MainWindowDetectorConstructor.cpp | 35 +-- src/gui/MainWindowTools/MainWindowDiskIO.cpp | 13 +- src/gui/MainWindowTools/MainWindowInits.cpp | 13 +- src/gui/MainWindowTools/MainWindowMenu.cpp | 16 +- .../MainWindowParticleSimulation.cpp | 10 +- .../MainWindowPhotonSource.cpp | 4 +- src/gui/MainWindowTools/MainWindowTests.cpp | 4 +- src/gui/MainWindowTools/globalscript.cpp | 10 +- src/gui/MainWindowTools/mainwindowjson.cpp | 4 +- src/gui/MainWindowTools/pythonscript.cpp | 6 +- .../Reconstruction_NN.cpp | 6 +- .../reconstruction_diskio.cpp | 32 +-- src/gui/amatparticleconfigurator.cpp | 17 +- src/gui/amatparticleconfigurator.h | 4 +- src/gui/aremotewindow.cpp | 8 +- src/gui/ascriptexampleexplorer.cpp | 2 +- src/gui/ascriptwindow.cpp | 65 +++-- src/gui/ascriptwindow.h | 8 +- src/gui/awebsocketserverdialog.cpp | 22 +- src/gui/checkupwindowclass.cpp | 6 +- src/gui/detectoraddonswindow.cpp | 28 +- src/gui/exampleswindow.cpp | 28 +- src/gui/geometrywindowclass.cpp | 10 +- src/gui/globalsettingswindowclass.cpp | 200 ++++++++------- src/gui/globalsettingswindowclass.h | 4 - src/gui/graphwindowclass.cpp | 42 +-- src/gui/lrfwindow.cpp | 34 +-- src/gui/mainwindow.cpp | 114 ++++----- src/gui/mainwindow.h | 7 +- src/gui/materialinspectorwindow.cpp | 56 ++-- src/gui/outputwindow.cpp | 16 +- src/gui/reconstructionwindow.cpp | 40 +-- src/gui/windownavigatorclass.cpp | 10 +- src/main.cpp | 9 +- src/modules/lrf_v3/gui/alrfwindow.cpp | 36 +-- src/scriptmode/ainterfacetodeposcript.cpp | 5 +- src/scriptmode/ainterfacetodeposcript.h | 4 +- src/scriptmode/interfacetoglobscript.cpp | 1 - 47 files changed, 781 insertions(+), 823 deletions(-) create mode 100644 src/common/aglobalsettings.cpp create mode 100644 src/common/aglobalsettings.h delete mode 100644 src/common/globalsettingsclass.cpp delete mode 100644 src/common/globalsettingsclass.h diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index be77a12f..ab3be188 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -7,7 +7,6 @@ #ifdef GUI #include "ascriptwindow.h" #include "ajavascriptmanager.h" -#include "globalsettingsclass.h" #include #include "TRandom2.h" #include "aphoton.h" @@ -109,7 +108,7 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *caller) TRandom2* RandGen = new TRandom2(); AJavaScriptManager* sm = new AJavaScriptManager(RandGen); - AScriptWindow* sw = new AScriptWindow(sm, new GlobalSettingsClass(0), true, caller); + AScriptWindow* sw = new AScriptWindow(sm, true, caller); double v[3]; v[0] = 0; diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 30396af1..39500eeb 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -257,7 +257,7 @@ void AWaveshifterOverride::loadReemissionProbability(QWidget* caller) { QString fileName = QFileDialog::getOpenFileName(caller, "Load reemission probability", "", "Data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; - //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + //GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector X, Y; int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); if (ret == 0) @@ -271,7 +271,7 @@ void AWaveshifterOverride::loadEmissionSpectrum(QWidget *caller) { QString fileName = QFileDialog::getOpenFileName(caller, "Load emission spectrum", "", "Data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; - //GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + //GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector X, Y; int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); if (ret == 0) diff --git a/src/ants2.pro b/src/ants2.pro index d11e42a8..0a0fe1ee 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -7,7 +7,7 @@ ANTS2_MINOR = 13 #CONFIG += ants2_flann #enable FLANN (fast neighbour search) library: see https://github.com/mariusmuja/flann #CONFIG += ants2_fann #enables FANN (fast neural network) library: see https://github.com/libfann/fann CONFIG += ants2_eigen3 #use Eigen3 library instead of ROOT for linear algebra - highly recommended! Installation requires only to copy files! -#CONFIG += ants2_RootServer #enable cern CERN ROOT html server +CONFIG += ants2_RootServer #enable cern CERN ROOT html server #CONFIG += ants2_Python #enable Python scripting #CONFIG += ants2_NCrystal #enable NCrystal library (neutron scattering): see https://github.com/mctools/ncrystal @@ -244,7 +244,6 @@ SOURCES += main.cpp \ common/CorrelationFilters.cpp \ common/reconstructionsettings.cpp \ common/generalsimsettings.cpp \ - common/globalsettingsclass.cpp \ common/tmpobjhubclass.cpp \ common/ajsontools.cpp \ common/afiletools.cpp \ @@ -356,13 +355,13 @@ SOURCES += main.cpp \ OpticalOverrides/fsnpopticaloverride.cpp \ OpticalOverrides/awaveshifteroverride.cpp \ OpticalOverrides/spectralbasicopticaloverride.cpp \ - OpticalOverrides/abasicopticaloverride.cpp + OpticalOverrides/abasicopticaloverride.cpp \ + common/aglobalsettings.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ common/reconstructionsettings.h \ common/generalsimsettings.h \ - common/globalsettingsclass.h \ common/tmpobjhubclass.h \ common/agammarandomgenerator.h \ common/apositionenergyrecords.h \ @@ -488,7 +487,8 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/fsnpopticaloverride.h \ OpticalOverrides/awaveshifteroverride.h \ OpticalOverrides/spectralbasicopticaloverride.h \ - OpticalOverrides/abasicopticaloverride.h + OpticalOverrides/abasicopticaloverride.h \ + common/aglobalsettings.h # --- SIM --- ants2_SIM { @@ -743,7 +743,7 @@ RC_FILE = myapp.rc #---Optimization of compilation--- win32 { - #uncomment the next two lines to disable optimization during compilation. It will drastically shorten compilation time, but there are performance loss, especially strong for LRF computation + #when the next two lines are NOT commented, optimization during compilation is disabled. It will drastically shorten compilation time on MSVC2013, but there are performance loss, especially strong for LRF computation QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CXXFLAGS_RELEASE *= -Od } diff --git a/src/common/aglobalsettings.cpp b/src/common/aglobalsettings.cpp new file mode 100644 index 00000000..1fba3fd1 --- /dev/null +++ b/src/common/aglobalsettings.cpp @@ -0,0 +1,221 @@ +#include "aglobalsettings.h" +#include "ajsontools.h" +#include "anetworkmodule.h" +#include "ajavascriptmanager.h" +#include "amessage.h" +#include "ainterfacetogstylescript.h" + +#ifdef GUI +#include "globalsettingswindowclass.h" +#endif + +#include +#include +#include +#include +#include + +AGlobalSettings& AGlobalSettings::getInstance() +{ + static AGlobalSettings instance; + return instance; +} + +AGlobalSettings::AGlobalSettings() +{ + RecNumTreads = QThread::idealThreadCount() - 1; + if (RecNumTreads < 1) RecNumTreads = 1; + + //default font size +#ifdef Q_OS_LINUX // fix font size on Linux + FontSize = 8; +#else + FontSize = 8; +#endif + + //setting up directories +#ifdef WINDOWSBIN + QDir dir = QDir::current(); + dir.cdUp(); + AntsBaseDir = dir.absolutePath(); + QDir::setCurrent(AntsBaseDir); +#else + //base is suggested by Qt + "/ants2" + AntsBaseDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/ants2"; +#endif + + if (!QDir(AntsBaseDir).exists()) QDir().mkdir(AntsBaseDir); + QuicksaveDir = AntsBaseDir + "/Quicksave"; //dir for quicksave + if (!QDir(QuicksaveDir).exists()) QDir().mkdir(QuicksaveDir); + ExamplesDir = QDir::current().absolutePath() + "/EXAMPLES"; //dir where examples will be copied + ResourcesDir = QDir::current().absolutePath() + "/DATA";//dir where data will be copied + +#ifdef Q_OS_WIN32 + if (!QDir(ExamplesDir).exists()) //direct call of ants2.exe + { + QDir dir = QDir::current(); + dir.cdUp(); + QString candidate = dir.absolutePath() + "/EXAMPLES"; + if (QDir(candidate).exists()) ExamplesDir = candidate; + + candidate = dir.absolutePath() + "/DATA"; + if (QDir(candidate).exists()) ResourcesDir = candidate; + } +#endif + + TmpDir = AntsBaseDir + "/Tmp"; //dir for tmp saves + if (!QDir(TmpDir).exists()) QDir().mkdir(TmpDir); + QDir::setCurrent(TmpDir); + LastOpenDir = TmpDir; //setting current directory for load/save dialogs - LoadANTSconfiguration can override + ConfigDir = AntsBaseDir + "/Config"; //dir for ANTS2 settings + + //natutal abundances data default filename + MaterialsAndParticlesSettings["NaturalAbundanciesFileName"] = ResourcesDir+"/Neutrons/IsotopeNaturalAbundances.txt"; + MaterialsAndParticlesSettings["CrossSectionsDir"] = ResourcesDir+"/Neutrons/CrossSections"; + MaterialsAndParticlesSettings["EnableAutoLoad"] = true; + + //if exists,load file fith ANTS2 settings, otherwise create config dir + if (!QDir(ConfigDir).exists()) + { + qDebug() << "Config dir not found, skipping config load, creating new config dir" ; + QDir().mkdir(ConfigDir); //dir not found, skipping load config + } + else loadANTSconfiguration(); + +#ifdef GUI + if (!RootStyleScript.isEmpty()) + { + //running root TStyle script + AJavaScriptManager* SM = new AJavaScriptManager(0); + AInterfaceToGStyleScript* GStyleInterface = new AInterfaceToGStyleScript(); //deleted by the SM + SM->SetInterfaceObject(GStyleInterface); + SM->Evaluate(RootStyleScript); + SM->deleteLater(); + } +#endif +} + +void AGlobalSettings::writeToJson(QJsonObject &json) const +{ + QJsonObject js; + js["SaveLoadWindows"] = SaveLoadWindows; + js["ShowExamplesOnStart"] = ShowExamplesOnStart; + js["LastDir"] = LastOpenDir; + js["PMtypeLib"] = LibPMtypes; + js["MaterialLib"] = LibMaterials; + js["ParticleSourcesLib"] = LibParticleSources; + js["ScriptsLib"] = LibScripts; + js["FontSize"] = FontSize; + js["RootStyleScript"] = RootStyleScript; + js["OpenImageExternalEditor"] = fOpenImageExternalEditor; + js["TextLogPrecision"] = TextLogPrecision; + js["BinsX"] = BinsX; + js["BinsY"] = BinsY; + js["BinsZ"] = BinsZ; + js["FunctionPointsX"] = FunctionPointsX; + js["FunctionPointsY"] = FunctionPointsY; + js["NumSegments"] = NumSegments; + js["PerformAutomaticGeometryCheck"] = PerformAutomaticGeometryCheck; + js["NumThreads"] = NumThreads; + + js["MaterialsAndParticlesSettings"] = MaterialsAndParticlesSettings; + + js["RecTreeSave_IncludePMsignals"] = RecTreeSave_IncludePMsignals; + js["RecTreeSave_IncludeRho"] = RecTreeSave_IncludeRho; + js["RecTreeSave_IncludeTrue"] = RecTreeSave_IncludeTrue; + + js["SimTextSave_IncludeNumPhotons"] = SimTextSave_IncludeNumPhotons; + js["SimTextSave_IncludePositions"] = SimTextSave_IncludePositions; + + js["GlobScript"] = GlobScript; + js["ScriptWindowJson"] = ScriptWindowJson; + js["PythonScriptWindowJson"] = PythonScriptWindowJson; + js["DefaultFontSize_ScriptWindow"] = DefaultFontSize_ScriptWindow; + js["DefaultFontFamily_ScriptWindow"] = DefaultFontFamily_ScriptWindow; + js["DefaultFontWeight_ScriptWindow"] = DefaultFontWeight_ScriptWindow; + js["DefaultFontItalic_ScriptWindow"] = DefaultFontItalic_ScriptWindow; + + js["DefaultWebSocketPort"] = DefaultWebSocketPort; + js["DefaultWebSocketIP"] = DefaultWebSocketIP; + js["DefaultRootServerPort"] = DefaultRootServerPort; + js["RunRootServerOnStart"] = fRunRootServerOnStart; + js["ExternalJSROOT"] = ExternalJSROOT; + + js["RemoteServers"] = RemoteServers; + + json["ANTS2config"] = js; +} + +void AGlobalSettings::readFromJson(const QJsonObject &json) +{ + QJsonObject js = json["ANTS2config"].toObject(); + + parseJson(js, "SaveLoadWindows", SaveLoadWindows); + parseJson(js, "ShowExamplesOnStart", ShowExamplesOnStart); + parseJson(js, "LastDir", LastOpenDir); + parseJson(js, "PMtypeLib", LibPMtypes); + parseJson(js, "MaterialLib", LibMaterials); + parseJson(js, "ParticleSourcesLib", LibParticleSources); + parseJson(js, "ScriptsLib", LibScripts); + parseJson(js, "FontSize", FontSize); + parseJson(js, "RootStyleScript", RootStyleScript); + parseJson(js, "OpenImageExternalEditor", fOpenImageExternalEditor); + parseJson(js, "TextLogPrecision", TextLogPrecision); + parseJson(js, "BinsX", BinsX); + parseJson(js, "BinsY", BinsY); + parseJson(js, "BinsZ", BinsZ); + parseJson(js, "FunctionPointsX", FunctionPointsX); + parseJson(js, "FunctionPointsY", FunctionPointsY); + parseJson(js, "NumSegments", NumSegments); + parseJson(js, "NumThreads", NumThreads); + + parseJson(js, "RecTreeSave_IncludePMsignals", RecTreeSave_IncludePMsignals); + parseJson(js, "RecTreeSave_IncludeRho", RecTreeSave_IncludeRho); + parseJson(js, "RecTreeSave_IncludeTrue", RecTreeSave_IncludeTrue); + + parseJson(js, "SimTextSave_IncludeNumPhotons", SimTextSave_IncludeNumPhotons); + parseJson(js, "SimTextSave_IncludePositions", SimTextSave_IncludePositions); + + parseJson(js, "PerformAutomaticGeometryCheck", PerformAutomaticGeometryCheck); + + parseJson(js, "GlobScript", GlobScript); + if (js.contains("ScriptWindowJson")) + ScriptWindowJson = js["ScriptWindowJson"].toObject(); + if (js.contains("PythonScriptWindowJson")) + PythonScriptWindowJson = js["PythonScriptWindowJson"].toObject(); + + parseJson(js, "MaterialsAndParticlesSettings", MaterialsAndParticlesSettings); + + parseJson(js, "DefaultFontSize_ScriptWindow", DefaultFontSize_ScriptWindow); + parseJson(js, "DefaultFontFamily_ScriptWindow", DefaultFontFamily_ScriptWindow); + parseJson(js, "DefaultFontWeight_ScriptWindow", DefaultFontWeight_ScriptWindow); + parseJson(js, "DefaultFontItalic_ScriptWindow", DefaultFontItalic_ScriptWindow); + + //network + parseJson(js, "DefaultWebSocketPort", DefaultWebSocketPort); + parseJson(js, "DefaultWebSocketIP", DefaultWebSocketIP); + parseJson(js, "DefaultRootServerPort", DefaultRootServerPort); + parseJson(js, "RunRootServerOnStart", fRunRootServerOnStart); + + parseJson(js, "RemoteServers", RemoteServers); + + QString tmp; + parseJson(js, "ExternalJSROOT", tmp); + if (!tmp.isEmpty()) ExternalJSROOT = tmp; +} + +void AGlobalSettings::saveANTSconfiguration() const +{ + QString fileName = ConfigDir + "/config.ini"; + QJsonObject json; + writeToJson(json); + SaveJsonToFile(json, fileName); +} + +void AGlobalSettings::loadANTSconfiguration() +{ + QString fileName = ConfigDir + "/config.ini"; + QJsonObject json; + LoadJsonFromFile(json, fileName); + if (!json.isEmpty()) readFromJson(json); +} diff --git a/src/common/aglobalsettings.h b/src/common/aglobalsettings.h new file mode 100644 index 00000000..98f3b46e --- /dev/null +++ b/src/common/aglobalsettings.h @@ -0,0 +1,99 @@ +#ifndef AGLOBALSETTINGS_H +#define AGLOBALSETTINGS_H + +#include +#include + +class ANetworkModule; + +class AGlobalSettings final +{ +public: + static AGlobalSettings& getInstance(); + +private: + AGlobalSettings(); + ~AGlobalSettings() = default; + + AGlobalSettings(const AGlobalSettings&) = delete; // Copy ctor + AGlobalSettings(AGlobalSettings&&) = delete; // Move ctor + AGlobalSettings& operator=(const AGlobalSettings&) = delete;// Copy assign + AGlobalSettings& operator=(AGlobalSettings&&) = delete; // Move assign + +public: + void saveANTSconfiguration() const; + void loadANTSconfiguration(); + + void writeToJson(QJsonObject& json) const; + void readFromJson(const QJsonObject& json); + + void setNetworkModule(ANetworkModule* NetworkModule) {NetModule = NetworkModule;} + ANetworkModule* getNetworkModule() const {return NetModule;} + + QString AntsBaseDir; // QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)+"/ants2"; + QString ConfigDir; // AntsbaseDir + "/Config" + QString QuicksaveDir;// AntsbaseDir + "/Quicksave" + QString ExamplesDir; // AntsbaseDir + "/Examples" + QString ResourcesDir; // AntsbaseDir + "/Examples" + QString TmpDir; // AntsbaseDir + "/Tmp" + + QString LastOpenDir; // last open directory using save and load dialog + QString LibMaterials; + QString LibPMtypes; + QString LibParticleSources; + QString LibScripts; + + int FontSize = 8; + int TextLogPrecision = 4; + int BinsX = 100; + int BinsY = 100; + int BinsZ = 100; + int FunctionPointsX = 30; + int FunctionPointsY = 30; + int NumSegments = 20; // number of segments in drawing, e.g., round objects + + bool ShowExamplesOnStart = true; //pop-up examples window + bool SaveLoadWindows = true; //save windows on exit, load them on ANTS2 start + + int NumThreads = -1; //if not loaded -> -1 means use recommended settings + int RecNumTreads = 1; + + bool RecTreeSave_IncludePMsignals = true; + bool RecTreeSave_IncludeRho = true; + bool RecTreeSave_IncludeTrue = true; + + bool SimTextSave_IncludeNumPhotons = true; + bool SimTextSave_IncludePositions = true; + + bool PerformAutomaticGeometryCheck = true; + + bool fOpenImageExternalEditor = true; + + QJsonObject MaterialsAndParticlesSettings; + + QString RootStyleScript; + + //GlobScript + QString GlobScript; + QJsonObject ScriptWindowJson; + QJsonObject PythonScriptWindowJson; + int DefaultFontSize_ScriptWindow = 12; + QString DefaultFontFamily_ScriptWindow; //empty => Qt standard settings will be used + bool DefaultFontWeight_ScriptWindow = false; + bool DefaultFontItalic_ScriptWindow = false; + + //Network + int DefaultWebSocketPort = 1234; + QString DefaultWebSocketIP = "127.0.0.1"; + int DefaultRootServerPort = 8080; + bool fRunRootServerOnStart = false; + QString ExternalJSROOT = "https://root.cern/js/latest/"; + + //RemoteServers + QJsonObject RemoteServers; + +private: + ANetworkModule* NetModule; +}; + +#endif // AGLOBALSETTINGS_H diff --git a/src/common/ajsontools.cpp b/src/common/ajsontools.cpp index dff46e8d..b81d6daf 100644 --- a/src/common/ajsontools.cpp +++ b/src/common/ajsontools.cpp @@ -128,7 +128,7 @@ void JsonToComboBox(QJsonObject &json, QString key, QComboBox *qb) } #endif -bool LoadJsonFromFile(QJsonObject &json, QString fileName) +bool LoadJsonFromFile(QJsonObject &json, const QString &fileName) { QFile loadFile(fileName); if (loadFile.open(QIODevice::ReadOnly)) @@ -147,7 +147,7 @@ bool LoadJsonFromFile(QJsonObject &json, QString fileName) } } -bool SaveJsonToFile(QJsonObject &json, QString fileName) +bool SaveJsonToFile(const QJsonObject &json, const QString &fileName) { QJsonDocument saveDoc(json); diff --git a/src/common/ajsontools.h b/src/common/ajsontools.h index 585cb8d0..04586853 100644 --- a/src/common/ajsontools.h +++ b/src/common/ajsontools.h @@ -33,8 +33,8 @@ void readTwoQVectorsFromJArray(QJsonArray &ar, QVector &x, QVector > &xy, QJsonArray &ar); void read2DQVectorFromJArray(QJsonArray &ar, QVector > &xy); -bool LoadJsonFromFile(QJsonObject &json, QString fileName); -bool SaveJsonToFile(QJsonObject &json, QString fileName); +bool LoadJsonFromFile(QJsonObject &json, const QString& fileName); +bool SaveJsonToFile(const QJsonObject &json, const QString& fileName); bool writeTH1ItoJsonArr(TH1I *hist, QJsonArray &ja); bool writeTH1DtoJsonArr(TH1D* hist, QJsonArray &ja); diff --git a/src/common/globalsettingsclass.cpp b/src/common/globalsettingsclass.cpp deleted file mode 100644 index 9c04e2e5..00000000 --- a/src/common/globalsettingsclass.cpp +++ /dev/null @@ -1,242 +0,0 @@ -#include "globalsettingsclass.h" -#include "ajsontools.h" -#include "anetworkmodule.h" -#include "ajavascriptmanager.h" -#include "amessage.h" -#include "ainterfacetogstylescript.h" - -#ifdef GUI -#include "globalsettingswindowclass.h" -#endif - -#include -#include -#include -#include -#include - -GlobalSettingsClass::GlobalSettingsClass(ANetworkModule *NetModule) : NetModule(NetModule) -{ - RecNumTreads = QThread::idealThreadCount() - 1; - if (RecNumTreads < 1) RecNumTreads = 1; - - //default font size -#ifdef Q_OS_LINUX // fix font size on Linux - FontSize = 8; -#else - FontSize = 8; -#endif - - //setting up directories -#ifdef WINDOWSBIN - QDir dir = QDir::current(); - dir.cdUp(); - AntsBaseDir = dir.absolutePath(); - QDir::setCurrent(AntsBaseDir); -#else - //base is suggested by Qt + "/ants2" - AntsBaseDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/ants2"; -#endif - - if (!QDir(AntsBaseDir).exists()) QDir().mkdir(AntsBaseDir); -// qDebug() << "-base-"<SetInterfaceObject(GStyleInterface); -#endif - SM->Evaluate(RootStyleScript); - SM->deleteLater(); - } -} - -void GlobalSettingsClass::writeToJson(QJsonObject &json) -{ - QJsonObject js; - js["SaveLoadWindows"] = SaveLoadWindows; - js["ShowExamplesOnStart"] = ShowExamplesOnStart; - //js["AlwaysSaveOnExit"] = AlwaysSaveOnExit; - //js["NeverSaveOnExit"] = NeverSaveOnExit; - js["LastDir"] = LastOpenDir; - js["PMtypeLib"] = LibPMtypes; - js["MaterialLib"] = LibMaterials; - js["ParticleSourcesLib"] = LibParticleSources; - js["ScriptsLib"] = LibScripts; - //QFont font = this->font(); - //int size = font.pointSize(); - js["FontSize"] = FontSize; - js["RootStyleScript"] = RootStyleScript; - js["OpenImageExternalEditor"] = fOpenImageExternalEditor; - js["TextLogPrecision"] = TextLogPrecision; - js["BinsX"] = BinsX; - js["BinsY"] = BinsY; - js["BinsZ"] = BinsZ; - js["FunctionPointsX"] = FunctionPointsX; - js["FunctionPointsY"] = FunctionPointsY; - js["NumSegments"] = NumSegments; - js["PerformAutomaticGeometryCheck"] = PerformAutomaticGeometryCheck; - js["NumThreads"] = NumThreads; - - js["MaterialsAndParticlesSettings"] = MaterialsAndParticlesSettings; - - js["RecTreeSave_IncludePMsignals"] = RecTreeSave_IncludePMsignals; - js["RecTreeSave_IncludeRho"] = RecTreeSave_IncludeRho; - js["RecTreeSave_IncludeTrue"] = RecTreeSave_IncludeTrue; - - js["SimTextSave_IncludeNumPhotons"] = SimTextSave_IncludeNumPhotons; - js["SimTextSave_IncludePositions"] = SimTextSave_IncludePositions; - - js["GlobScript"] = GlobScript; - js["ScriptWindowJson"] = ScriptWindowJson; - js["PythonScriptWindowJson"] = PythonScriptWindowJson; - js["DefaultFontSize_ScriptWindow"] = DefaultFontSize_ScriptWindow; - js["DefaultFontFamily_ScriptWindow"] = DefaultFontFamily_ScriptWindow; - js["DefaultFontWeight_ScriptWindow"] = DefaultFontWeight_ScriptWindow; - js["DefaultFontItalic_ScriptWindow"] = DefaultFontItalic_ScriptWindow; - - js["DefaultWebSocketPort"] = DefaultWebSocketPort; - js["DefaultWebSocketIP"] = DefaultWebSocketIP; - js["DefaultRootServerPort"] = DefaultRootServerPort; - js["RunRootServerOnStart"] = fRunRootServerOnStart; - js["ExternalJSROOT"] = ExternalJSROOT; - - js["RemoteServers"] = RemoteServers; - - json["ANTS2config"] = js; -} - -void GlobalSettingsClass::readFromJson(QJsonObject &json) -{ - QJsonObject js = json["ANTS2config"].toObject(); - - parseJson(js, "SaveLoadWindows", SaveLoadWindows); - //parseJson(js, "AlwaysSaveOnExit", AlwaysSaveOnExit); - //parseJson(js, "NeverSaveOnExit", NeverSaveOnExit); - parseJson(js, "ShowExamplesOnStart", ShowExamplesOnStart); - parseJson(js, "LastDir", LastOpenDir); - parseJson(js, "PMtypeLib", LibPMtypes); - parseJson(js, "MaterialLib", LibMaterials); - parseJson(js, "ParticleSourcesLib", LibParticleSources); - parseJson(js, "ScriptsLib", LibScripts); - parseJson(js, "FontSize", FontSize); - parseJson(js, "RootStyleScript", RootStyleScript); - parseJson(js, "OpenImageExternalEditor", fOpenImageExternalEditor); - parseJson(js, "TextLogPrecision", TextLogPrecision); - parseJson(js, "BinsX", BinsX); - parseJson(js, "BinsY", BinsY); - parseJson(js, "BinsZ", BinsZ); - parseJson(js, "FunctionPointsX", FunctionPointsX); - parseJson(js, "FunctionPointsY", FunctionPointsY); - parseJson(js, "NumSegments", NumSegments); - parseJson(js, "NumThreads", NumThreads); - - parseJson(js, "RecTreeSave_IncludePMsignals", RecTreeSave_IncludePMsignals); - parseJson(js, "RecTreeSave_IncludeRho", RecTreeSave_IncludeRho); - parseJson(js, "RecTreeSave_IncludeTrue", RecTreeSave_IncludeTrue); - - parseJson(js, "SimTextSave_IncludeNumPhotons", SimTextSave_IncludeNumPhotons); - parseJson(js, "SimTextSave_IncludePositions", SimTextSave_IncludePositions); - - parseJson(js, "PerformAutomaticGeometryCheck", PerformAutomaticGeometryCheck); - - parseJson(js, "GlobScript", GlobScript); - if (js.contains("ScriptWindowJson")) - ScriptWindowJson = js["ScriptWindowJson"].toObject(); - if (js.contains("PythonScriptWindowJson")) - PythonScriptWindowJson = js["PythonScriptWindowJson"].toObject(); - - parseJson(js, "MaterialsAndParticlesSettings", MaterialsAndParticlesSettings); - - parseJson(js, "DefaultFontSize_ScriptWindow", DefaultFontSize_ScriptWindow); - parseJson(js, "DefaultFontFamily_ScriptWindow", DefaultFontFamily_ScriptWindow); - parseJson(js, "DefaultFontWeight_ScriptWindow", DefaultFontWeight_ScriptWindow); - parseJson(js, "DefaultFontItalic_ScriptWindow", DefaultFontItalic_ScriptWindow); - - //network - DefaultWebSocketPort = 1234; - DefaultWebSocketIP = "127.0.0.1"; - DefaultRootServerPort = 8080; - fRunRootServerOnStart = false; - ExternalJSROOT = "https://root.cern/js/latest/"; - parseJson(js, "DefaultWebSocketPort", DefaultWebSocketPort); - parseJson(js, "DefaultWebSocketIP", DefaultWebSocketIP); - parseJson(js, "DefaultRootServerPort", DefaultRootServerPort); - parseJson(js, "RunRootServerOnStart", fRunRootServerOnStart); - - parseJson(js, "RemoteServers", RemoteServers); - - QString tmp; - parseJson(js, "ExternalJSROOT", tmp); - if (!tmp.isEmpty()) ExternalJSROOT = tmp; -} - -void GlobalSettingsClass::SaveANTSconfiguration() -{ - QString fileName = ConfigDir + "/config.ini"; - QJsonObject json; - writeToJson(json); - SaveJsonToFile(json, fileName); -} - -void GlobalSettingsClass::LoadANTSconfiguration() -{ - QString fileName = ConfigDir + "/config.ini"; - QJsonObject json; - LoadJsonFromFile(json, fileName); - if (!json.isEmpty()) readFromJson(json); -} diff --git a/src/common/globalsettingsclass.h b/src/common/globalsettingsclass.h deleted file mode 100644 index e152d6b2..00000000 --- a/src/common/globalsettingsclass.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef GLOBALSETTINGSCLASS_H -#define GLOBALSETTINGSCLASS_H - -#include -#include - -class ANetworkModule; - -class GlobalSettingsClass -{ -public: - GlobalSettingsClass(ANetworkModule* NetModule); - - void SaveANTSconfiguration(); - void LoadANTSconfiguration(); - void writeToJson(QJsonObject& json); - void readFromJson(QJsonObject& json); - - QString AntsBaseDir; // QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)+"/ants2"; - QString ConfigDir; // AntsbaseDir + "/Config" - QString QuicksaveDir;// AntsbaseDir + "/Quicksave" - QString ExamplesDir; // AntsbaseDir + "/Examples" - QString ResourcesDir; // AntsbaseDir + "/Examples" - QString TmpDir; // AntsbaseDir + "/Tmp" - - QString LastOpenDir; // last open directory using save and load dialog - QString LibMaterials; - QString LibPMtypes; - QString LibParticleSources; - QString LibScripts; - - int FontSize = 8; - int TextLogPrecision = 4; - int BinsX = 100; - int BinsY = 100; - int BinsZ = 100; - int FunctionPointsX = 30; - int FunctionPointsY = 30; - int NumSegments = 20; // number of segments in drawing, e.g., round objects - - bool ShowExamplesOnStart = true; //pop-up examples window - bool SaveLoadWindows = true; //save windows on exit, load them on ANTS2 start - //bool AlwaysSaveOnExit; //save detector to QuickSave on exit, do not ask - //bool NeverSaveOnExit; //do not save detector on exit, do not ask - - int NumThreads = -1; //if not loaded -> -1 means use recommended settings - int RecNumTreads = 1; - - bool RecTreeSave_IncludePMsignals = true; - bool RecTreeSave_IncludeRho = true; - bool RecTreeSave_IncludeTrue = true; - - bool SimTextSave_IncludeNumPhotons = true; - bool SimTextSave_IncludePositions = true; - - bool PerformAutomaticGeometryCheck = true; - - bool fOpenImageExternalEditor = true; - - QJsonObject MaterialsAndParticlesSettings; - - QString RootStyleScript; - - //GlobScript - QString GlobScript; - QJsonObject ScriptWindowJson; - QJsonObject PythonScriptWindowJson; - int DefaultFontSize_ScriptWindow = 12; - QString DefaultFontFamily_ScriptWindow; //empty => Qt standard settings will be used - bool DefaultFontWeight_ScriptWindow = false; - bool DefaultFontItalic_ScriptWindow = false; - - //Network - int DefaultWebSocketPort = 1234; - QString DefaultWebSocketIP = "127.0.0.1"; - int DefaultRootServerPort = 8080; - bool fRunRootServerOnStart = false; - QString ExternalJSROOT; - - //RemoteServers - QJsonObject RemoteServers; - - ANetworkModule* NetModule; -}; - -#endif // GLOBALSETTINGSCLASS_H diff --git a/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp b/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp index 6ea493f6..e451a408 100644 --- a/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp +++ b/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp @@ -8,7 +8,7 @@ #include "reconstructionwindow.h" #include "gainevaluatorwindowclass.h" #include "detectorclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "materialinspectorwindow.h" #include "checkupwindowclass.h" #include "asandwich.h" @@ -55,9 +55,9 @@ bool MainWindow::startupDetector() { MainWindow::initDetectorSandwich(); //create detector sandwich control and link GUI signals/slots // qDebug() << "-->DetectorSandwich initialized"; - if (QFile(GlobSet->ExamplesDir + "/StartupDetector.json").exists()) + if (QFile(GlobSet.ExamplesDir + "/StartupDetector.json").exists()) { - Config->LoadConfig(GlobSet->ExamplesDir + "/StartupDetector.json"); + Config->LoadConfig(GlobSet.ExamplesDir + "/StartupDetector.json"); return true; } else @@ -254,7 +254,7 @@ void MainWindow::on_pbPositionScript_clicked() delete GenScriptWindow; GenScriptWindow = 0; AJavaScriptManager* jsm = new AJavaScriptManager(Detector->RandGen); - GenScriptWindow = new AScriptWindow(jsm, GlobSet, true, this); + GenScriptWindow = new AScriptWindow(jsm, true, this); int ul = ui->cobUpperLowerPMs->currentIndex(); QString title = QString("Position PMs: ") + ( ul == 0 ? "upper array" : "lower array" ); @@ -268,33 +268,6 @@ void MainWindow::on_pbPositionScript_clicked() recallGeometryOfLocalScriptWindow(); GenScriptWindow->show(); - -/* - extractGeometryOfLocalScriptWindow(); - if (GenScriptWindow) delete GenScriptWindow; - GenScriptWindow = new GenericScriptWindowClass(Detector->RandGen); - recallGeometryOfLocalScriptWindow(); - int ul = ui->cobUpperLowerPMs->currentIndex(); - - //configure the script window and engine - PMscriptInterface = new InterfaceToPMscript(); //deleted by the GenScriptWindow - GenScriptWindow->SetInterfaceObject(PMscriptInterface); - - GenScriptWindow->SetShowEvaluationResult(false); //do not show "undefined" - GenScriptWindow->SetExample("for (var i=0; i<3; i++) PM(i*60, (i-2)*60, 0, 0)"); - - QString s = (ul==0) ? "upper array":"lower array"; - GenScriptWindow->SetTitle("Position PMs: "+s); - - GenScriptWindow->SetScript(&Detector->PMarrays[ul].PositioningScript); - - GenScriptWindow->SetStarterDir(GlobSet->LibScripts); - - //define what to do on evaluation success - connect(GenScriptWindow, SIGNAL(success(QString)), this, SLOT(PMscriptSuccess())); - //if needed. connect signals of the interface object with the required slots of any ANTS2 objects - GenScriptWindow->show(); - */ } void MainWindow::PMscriptSuccess() diff --git a/src/gui/MainWindowTools/MainWindowDiskIO.cpp b/src/gui/MainWindowTools/MainWindowDiskIO.cpp index 7973f9de..e4ce9a5d 100644 --- a/src/gui/MainWindowTools/MainWindowDiskIO.cpp +++ b/src/gui/MainWindowTools/MainWindowDiskIO.cpp @@ -11,7 +11,7 @@ #include "detectorclass.h" #include "apmtype.h" #include "geometrywindowclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "asandwich.h" #include "ajsontools.h" #include "aenergydepositioncell.h" @@ -342,9 +342,10 @@ void MainWindow::on_pbLoadPMcenters_clicked() if (reg == 1) str = "Load PM center positions (X,Y) for "+str; else str = "Load PM center positions (X,Y,Z) for "+str; - QString fileName = QFileDialog::getOpenFileName(this, str, GlobSet->LastOpenDir, "ASCII files (*.dat *.txt);;All files (*.*)"); + AGlobalSettings& GlobSet = AGlobalSettings::getInstance(); + QString fileName = QFileDialog::getOpenFileName(this, str, GlobSet.LastOpenDir, "ASCII files (*.dat *.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); APmArrayData *PMar = &Detector->PMarrays[ul]; PMar->PositionsAnglesTypes.clear(); @@ -380,10 +381,10 @@ void MainWindow::on_pbSavePMcenters_clicked() if (A_Reg == 1) str = "Save PM center positions (X,Y) for "+str; else str = "Save PM center positions (X,Y,Z) for "+str; - QString fileName = QFileDialog::getSaveFileName(this, str, GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); + AGlobalSettings& GlobSet = AGlobalSettings::getInstance(); + QString fileName = QFileDialog::getSaveFileName(this, str, GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo file(fileName); if(file.suffix().isEmpty()) fileName += ".dat"; diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 14b6f45f..02c31656 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -21,7 +21,7 @@ #include "simulationmanager.h" #include "areconstructionmanager.h" #include "particlesourcesclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "globalsettingswindowclass.h" #include "aconfiguration.h" #include "amessage.h" @@ -50,11 +50,10 @@ MainWindow::MainWindow(DetectorClass *Detector, ASimulationManager *SimulationManager, AReconstructionManager *ReconstructionManager, ANetworkModule* Net, - TmpObjHubClass *TmpHub, - GlobalSettingsClass *GlobSet) : + TmpObjHubClass *TmpHub) : QMainWindow(), Detector(Detector), EventsDataHub(EventsDataHub), RootApp(RootApp), SimulationManager(SimulationManager), ReconstructionManager(ReconstructionManager), - NetModule(Net), TmpHub(TmpHub), GlobSet(GlobSet), + NetModule(Net), TmpHub(TmpHub), GlobSet(AGlobalSettings::getInstance()), ui(new Ui::MainWindow) { qDebug() << ">Main window constructor started"; @@ -264,7 +263,7 @@ MainWindow::MainWindow(DetectorClass *Detector, qDebug() << ">GUI initialized"; //change font size for all windows - if (this->font().pointSize() != GlobSet->FontSize) setFontSizeAllWindows(GlobSet->FontSize); + if (this->font().pointSize() != GlobSet.FontSize) setFontSizeAllWindows(GlobSet.FontSize); qDebug() << ">Font size adjusted"; //menu properties @@ -275,7 +274,7 @@ MainWindow::MainWindow(DetectorClass *Detector, ui->menuFile->setToolTipDuration(1000); bool fShowGeom; - if (GlobSet->SaveLoadWindows) + if (GlobSet.SaveLoadWindows) { MainWindow::on_actionLoad_positions_and_status_of_all_windows_triggered(); fShowGeom = GeometryWindow->isVisible(); @@ -286,7 +285,7 @@ MainWindow::MainWindow(DetectorClass *Detector, fShowGeom = true; GuiUtils::AssureWidgetIsWithinVisibleArea(this); } - ui->actionSave_Load_windows_status_on_Exit_Init->setChecked(GlobSet->SaveLoadWindows); + ui->actionSave_Load_windows_status_on_Exit_Init->setChecked(GlobSet.SaveLoadWindows); qDebug() << ">Init for Output window"; Owindow->InitWindow(); diff --git a/src/gui/MainWindowTools/MainWindowMenu.cpp b/src/gui/MainWindowTools/MainWindowMenu.cpp index 26fbb782..d5c89708 100644 --- a/src/gui/MainWindowTools/MainWindowMenu.cpp +++ b/src/gui/MainWindowTools/MainWindowMenu.cpp @@ -10,7 +10,7 @@ #include "graphwindowclass.h" #include "geometrywindowclass.h" #include "lrfwindow.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "detectoraddonswindow.h" #include "detectorclass.h" #include "ajsontools.h" @@ -196,7 +196,7 @@ void MainWindow::on_actionSave_position_and_stratus_of_all_windows_triggered() //QString configDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)+"/ants2"; //if (!QDir(configDir).exists()) QDir().mkdir(configDir); - QString fileName = GlobSet->ConfigDir + "/WindowConfig.ini"; + QString fileName = GlobSet.ConfigDir + "/WindowConfig.ini"; bool bOK = SaveJsonToFile(json, fileName); if (!bOK) message("Failed to save json to file: "+fileName, this); } @@ -229,7 +229,7 @@ void readXYwindow(QString key, QMainWindow* w, bool fWH, QJsonObject &json) void MainWindow::on_actionLoad_positions_and_status_of_all_windows_triggered() { - QString fileName = GlobSet->ConfigDir + "/WindowConfig.ini"; + QString fileName = GlobSet.ConfigDir + "/WindowConfig.ini"; if (QFile(fileName).exists()) { QJsonObject json; @@ -337,9 +337,9 @@ void MainWindow::CorrectPreprocessingAdds(QVector Pedestals) void MainWindow::on_actionSave_configuration_triggered() { QFileDialog fileDialog; - QString fileName = fileDialog.getSaveFileName(this, "Save configuration", GlobSet->LastOpenDir, "Json files (*.json)"); + QString fileName = fileDialog.getSaveFileName(this, "Save configuration", GlobSet.LastOpenDir, "Json files (*.json)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo file(fileName); if(file.suffix().isEmpty()) fileName += ".json"; ELwindow->SaveConfig(fileName); @@ -348,9 +348,9 @@ void MainWindow::on_actionSave_configuration_triggered() void MainWindow::on_actionLoad_configuration_triggered() { QFileDialog fileDialog; - QString fileName = fileDialog.getOpenFileName(this,"Load configuration", GlobSet->LastOpenDir, "All files (*.*)"); + QString fileName = fileDialog.getOpenFileName(this,"Load configuration", GlobSet.LastOpenDir, "All files (*.*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); bool bOK = Config->LoadConfig(fileName); if (!bOK) message(Config->ErrorString, this); if (GeometryWindow->isVisible()) GeometryWindow->ShowGeometry(); @@ -367,7 +367,7 @@ void MainWindow::on_actionNew_detector_triggered() int ret = msgBox.exec(); if (ret == QMessageBox::Cancel) return; - Config->LoadConfig(GlobSet->ExamplesDir + "/Simplest.json"); + Config->LoadConfig(GlobSet.ExamplesDir + "/Simplest.json"); if (ELwindow->isVisible()) ELwindow->hide(); if (GeometryWindow->isVisible()) GeometryWindow->ShowGeometry(false); } diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index f9e7f912..f03126ba 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -10,7 +10,7 @@ #include "graphwindowclass.h" #include "detectorclass.h" #include "checkupwindowclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "amaterialparticlecolection.h" #include "ageomarkerclass.h" #include "ajsontools.h" @@ -623,10 +623,10 @@ void MainWindow::on_cbLinkingOpposite_clicked(bool checked) void MainWindow::on_pbGunLoadSpectrum_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load energy spectrum", GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load energy spectrum", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); qDebug()<LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); int isource = ui->cobParticleSource->currentIndex(); ParticleSourceStructure* ps = ParticleSources->getSource(isource); @@ -911,7 +911,7 @@ void MainWindow::on_lwGunParticles_currentRowChanged(int /*currentRow*/) void MainWindow::on_pbSaveParticleSource_clicked() { - QString starter = (GlobSet->LibParticleSources.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibParticleSources; + QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; QString fileName = QFileDialog::getSaveFileName(this, "Export particle source", starter, "Json files (*.json)"); if (fileName.isEmpty()) return; QFileInfo file(fileName); @@ -933,7 +933,7 @@ void MainWindow::on_pbLoadParticleSource_clicked() int ret = msgBox.exec(); if (ret == QMessageBox::Cancel) return; - QString starter = (GlobSet->LibParticleSources.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibParticleSources; + QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; QString fileName = QFileDialog::getOpenFileName(this, "Import particle source", starter, "json files (*.json)"); if (fileName.isEmpty()) return; int iSource = ui->cobParticleSource->currentIndex(); diff --git a/src/gui/MainWindowTools/MainWindowPhotonSource.cpp b/src/gui/MainWindowTools/MainWindowPhotonSource.cpp index e35287f8..35955728 100644 --- a/src/gui/MainWindowTools/MainWindowPhotonSource.cpp +++ b/src/gui/MainWindowTools/MainWindowPhotonSource.cpp @@ -1,7 +1,7 @@ //ANTS2 modules and windows #include "mainwindow.h" #include "ui_mainwindow.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "ajsontools.h" #include "amessage.h" #include "simulationmanager.h" @@ -72,7 +72,7 @@ void MainWindow::SimGeneralConfigToJson(QJsonObject &jsonMaster) json["AcceleratorConfig"] = acjson; //DetStat binning - json["DetStatNumBins"] = GlobSet->BinsX; + json["DetStatNumBins"] = GlobSet.BinsX; //Sec scint options QJsonObject scjson; diff --git a/src/gui/MainWindowTools/MainWindowTests.cpp b/src/gui/MainWindowTools/MainWindowTests.cpp index a4488243..c8adeddf 100644 --- a/src/gui/MainWindowTools/MainWindowTests.cpp +++ b/src/gui/MainWindowTools/MainWindowTests.cpp @@ -8,7 +8,7 @@ #include "detectorclass.h" #include "eventsdataclass.h" #include "graphwindowclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "geometrywindowclass.h" #include "acompton.h" #include "aenergydepositioncell.h" @@ -261,7 +261,7 @@ void MainWindow::on_pbShowComptonEnergies_clicked() void MainWindow::on_pbCheckRandomGen_clicked() { - auto hist1 = new TH1D("Testrndm","uniform", GlobSet->BinsX, 0,1.); + auto hist1 = new TH1D("Testrndm","uniform", GlobSet.BinsX, 0,1.); for (int i=0; i<100000; i++) hist1->Fill(Detector->RandGen->Rndm()); GraphWindow->Draw(hist1); } diff --git a/src/gui/MainWindowTools/globalscript.cpp b/src/gui/MainWindowTools/globalscript.cpp index f9b7f3c8..556259a0 100644 --- a/src/gui/MainWindowTools/globalscript.cpp +++ b/src/gui/MainWindowTools/globalscript.cpp @@ -1,8 +1,8 @@ #include "ajavascriptmanager.h" #include "ui_mainwindow.h" +#include "aglobalsettings.h" #include "detectorclass.h" #include "eventsdataclass.h" -#include "globalsettingsclass.h" #include "interfacetoglobscript.h" #include "scriptminimizer.h" #include "histgraphinterfaces.h" @@ -43,7 +43,7 @@ void MainWindow::createScriptWindow() { QWidget* w = new QWidget(); AJavaScriptManager* SM = new AJavaScriptManager(Detector->RandGen); - ScriptWindow = new AScriptWindow(SM, GlobSet, false, w); //transfer ownership of SM + ScriptWindow = new AScriptWindow(SM, false, w); //transfer ownership of SM ScriptWindow->move(25,25); connect(ScriptWindow, &AScriptWindow::WindowShown, WindowNavigator, &WindowNavigatorClass::ShowWindowTriggered); connect(ScriptWindow, &AScriptWindow::WindowHidden, WindowNavigator, &WindowNavigatorClass::HideWindowTriggered); @@ -73,11 +73,11 @@ void MainWindow::createScriptWindow() QObject::connect(dat, SIGNAL(RequestEventsGuiUpdate()), Rwindow, SLOT(onRequestEventsGuiUpdate())); ScriptWindow->SetInterfaceObject(dat, "events"); - InterfaceToSim* sim = new InterfaceToSim(SimulationManager, EventsDataHub, Config, GlobSet->RecNumTreads); + InterfaceToSim* sim = new InterfaceToSim(SimulationManager, EventsDataHub, Config, GlobSet.RecNumTreads); QObject::connect(sim, SIGNAL(requestStopSimulation()), SimulationManager, SLOT(StopSimulation())); ScriptWindow->SetInterfaceObject(sim, "sim"); - InterfaceToReconstructor* rec = new InterfaceToReconstructor(ReconstructionManager, Config, EventsDataHub, TmpHub, GlobSet->RecNumTreads); + InterfaceToReconstructor* rec = new InterfaceToReconstructor(ReconstructionManager, Config, EventsDataHub, TmpHub, GlobSet.RecNumTreads); QObject::connect(rec, SIGNAL(RequestStopReconstruction()), ReconstructionManager, SLOT(requestStop())); QObject::connect(rec, SIGNAL(RequestUpdateGuiForManifest()), Rwindow, SLOT(onManifestItemsGuiUpdate())); ScriptWindow->SetInterfaceObject(rec, "rec"); @@ -114,7 +114,7 @@ void MainWindow::createScriptWindow() AInterfaceToPhotonScript* photon = new AInterfaceToPhotonScript(Config, EventsDataHub); ScriptWindow->SetInterfaceObject(photon, "photon"); - AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(Detector, GlobSet, EventsDataHub); + AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(Detector, EventsDataHub); ScriptWindow->SetInterfaceObject(depo, "depo"); #ifdef ANTS_FLANN diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 0367aba5..243157b2 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -1,4 +1,5 @@ #include "mainwindow.h" +#include "aglobalsettings.h" #include "ui_mainwindow.h" #include "detectorclass.h" #include "materialinspectorwindow.h" @@ -10,7 +11,6 @@ #include "ajsontools.h" #include "particlesourcesclass.h" #include "aparticleonstack.h" -#include "globalsettingsclass.h" #include "apmhub.h" #include "eventsdataclass.h" #include "tmpobjhubclass.h" @@ -51,7 +51,7 @@ bool MainWindow::readDetectorFromJson(QJsonObject &json) void MainWindow::onRequestDetectorGuiUpdate() { //qDebug() << "DetJson->DetGUI"; - Detector->GeoManager->SetNsegments(GlobSet->NumSegments); //lost because GeoManager is new + Detector->GeoManager->SetNsegments(GlobSet.NumSegments); //lost because GeoManager is new DoNotUpdateGeometry = true; //Particles diff --git a/src/gui/MainWindowTools/pythonscript.cpp b/src/gui/MainWindowTools/pythonscript.cpp index 6de8f151..ee283f29 100644 --- a/src/gui/MainWindowTools/pythonscript.cpp +++ b/src/gui/MainWindowTools/pythonscript.cpp @@ -3,7 +3,7 @@ #include "apythonscriptmanager.h" #include "detectorclass.h" #include "eventsdataclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "interfacetoglobscript.h" #include "ainterfacetomessagewindow.h" #include "scriptminimizer.h" @@ -61,11 +61,11 @@ void MainWindow::createPythonScriptWindow() QObject::connect(dat, SIGNAL(RequestEventsGuiUpdate()), Rwindow, SLOT(onRequestEventsGuiUpdate())); PythonScriptWindow->SetInterfaceObject(dat, "events"); - InterfaceToSim* sim = new InterfaceToSim(SimulationManager, EventsDataHub, Config, GlobSet->RecNumTreads); + InterfaceToSim* sim = new InterfaceToSim(SimulationManager, EventsDataHub, Config, GlobSet.RecNumTreads); QObject::connect(sim, SIGNAL(requestStopSimulation()), SimulationManager, SLOT(StopSimulation())); PythonScriptWindow->SetInterfaceObject(sim, "sim"); - InterfaceToReconstructor* rec = new InterfaceToReconstructor(ReconstructionManager, Config, EventsDataHub, TmpHub, GlobSet->RecNumTreads); + InterfaceToReconstructor* rec = new InterfaceToReconstructor(ReconstructionManager, Config, EventsDataHub, TmpHub, GlobSet.RecNumTreads); QObject::connect(rec, SIGNAL(RequestStopReconstruction()), ReconstructionManager, SLOT(requestStop())); QObject::connect(rec, SIGNAL(RequestUpdateGuiForManifest()), Rwindow, SLOT(onManifestItemsGuiUpdate())); PythonScriptWindow->SetInterfaceObject(rec, "rec"); diff --git a/src/gui/ReconstructionWindowTools/Reconstruction_NN.cpp b/src/gui/ReconstructionWindowTools/Reconstruction_NN.cpp index e9a5e52a..3cf737af 100644 --- a/src/gui/ReconstructionWindowTools/Reconstruction_NN.cpp +++ b/src/gui/ReconstructionWindowTools/Reconstruction_NN.cpp @@ -7,7 +7,7 @@ #include "graphwindowclass.h" #include "windownavigatorclass.h" #include "areconstructionmanager.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "apositionenergyrecords.h" #include "amessage.h" #include "graphwindowclass.h" @@ -78,8 +78,8 @@ void ReconstructionWindow::on_pbNNshowSpectrum_clicked() for (int i=0;i<100;i++) MyPalette[i] = FI+i; } - auto hist1D = new TH1D("NNtmp1","NN_distance", MW->GlobSet->BinsX, minD, maxD); - auto hist1D2 = new TH1D("NNtmp2","NN_distance", MW->GlobSet->BinsX, minD, maxD); + auto hist1D = new TH1D("NNtmp1","NN_distance", MW->GlobSet.BinsX, minD, maxD); + auto hist1D2 = new TH1D("NNtmp2","NN_distance", MW->GlobSet.BinsX, minD, maxD); for (int iev=0; ievReconstructionManager->KNNmodule->Filter.getAverageDist(iev); diff --git a/src/gui/ReconstructionWindowTools/reconstruction_diskio.cpp b/src/gui/ReconstructionWindowTools/reconstruction_diskio.cpp index eee6d723..13bd1761 100644 --- a/src/gui/ReconstructionWindowTools/reconstruction_diskio.cpp +++ b/src/gui/ReconstructionWindowTools/reconstruction_diskio.cpp @@ -5,7 +5,7 @@ #include "jsonparser.h" #include "eventsdataclass.h" #include "windownavigatorclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "detectorclass.h" #include "amessage.h" #include "globalsettingswindowclass.h" @@ -164,9 +164,9 @@ void ReconstructionWindow::on_pbSaveScanTree_clicked() return; } - QString fileName = QFileDialog::getSaveFileName(this, "Save sigma/distortion information", MW->GlobSet->LastOpenDir, "Root files (*.root)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save sigma/distortion information", MW->GlobSet.LastOpenDir, "Root files (*.root)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QString path = QFileInfo(fileName).absoluteDir().absolutePath(); QString suffix = QFileInfo(fileName).suffix(); @@ -207,9 +207,9 @@ void ReconstructionWindow::on_pbSaveReconstructionAsText_clicked() return; } - QString fileName = QFileDialog::getSaveFileName(this, "Save reconstruction data", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save reconstruction data", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QString path = QFileInfo(fileName).absoluteDir().absolutePath(); QString suffix = QFileInfo(fileName).suffix(); @@ -256,13 +256,13 @@ void ReconstructionWindow::on_pbSaveReconstructionAsRootTree_clicked() QCheckBox* cbSig = new QCheckBox("Include PM signals", &D); l->addWidget(cbSig); - cbSig->setChecked(MW->GlobSet->RecTreeSave_IncludePMsignals); + cbSig->setChecked(MW->GlobSet.RecTreeSave_IncludePMsignals); QCheckBox* cbRho = new QCheckBox("Include rho array (distance reconstructed->PM center)", &D); l->addWidget(cbRho); - cbRho->setChecked(MW->GlobSet->RecTreeSave_IncludeRho); + cbRho->setChecked(MW->GlobSet.RecTreeSave_IncludeRho); QCheckBox* cbTrue = new QCheckBox("Include true data for simulation/calibration datasets", &D); l->addWidget(cbTrue); - cbTrue->setChecked(MW->GlobSet->RecTreeSave_IncludeTrue); + cbTrue->setChecked(MW->GlobSet.RecTreeSave_IncludeTrue); QPushButton* pb = new QPushButton("Confirm", &D); l->addWidget(pb); @@ -275,15 +275,15 @@ void ReconstructionWindow::on_pbSaveReconstructionAsRootTree_clicked() if (D.result() == QDialog::Rejected) return; DontShowTodayOnSaveTree = (cbDont->isChecked()); - MW->GlobSet->RecTreeSave_IncludePMsignals = cbSig->isChecked(); - MW->GlobSet->RecTreeSave_IncludeRho = cbRho->isChecked(); - MW->GlobSet->RecTreeSave_IncludeTrue = cbTrue->isChecked(); + MW->GlobSet.RecTreeSave_IncludePMsignals = cbSig->isChecked(); + MW->GlobSet.RecTreeSave_IncludeRho = cbRho->isChecked(); + MW->GlobSet.RecTreeSave_IncludeTrue = cbTrue->isChecked(); MW->GlobSetWindow->updateGUI(); } - QString fileName = QFileDialog::getSaveFileName(this, "Save reconsruction data as Root Tree", MW->GlobSet->LastOpenDir, "Root files (*.root)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save reconsruction data as Root Tree", MW->GlobSet.LastOpenDir, "Root files (*.root)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QString path = QFileInfo(fileName).absoluteDir().absolutePath(); QString suffix = QFileInfo(fileName).suffix(); @@ -302,9 +302,9 @@ void ReconstructionWindow::on_pbSaveReconstructionAsRootTree_clicked() Name = path + "/" + Name + "."+suffix; bool ok = EventsDataHub->saveReconstructionAsTree(Name, MW->Detector->PMs, - MW->GlobSet->RecTreeSave_IncludePMsignals, - MW->GlobSet->RecTreeSave_IncludeRho, - MW->GlobSet->RecTreeSave_IncludeTrue, + MW->GlobSet.RecTreeSave_IncludePMsignals, + MW->GlobSet.RecTreeSave_IncludeRho, + MW->GlobSet.RecTreeSave_IncludeTrue, ig); if (!ok) { diff --git a/src/gui/amatparticleconfigurator.cpp b/src/gui/amatparticleconfigurator.cpp index fd03c904..1e9bbd3e 100644 --- a/src/gui/amatparticleconfigurator.cpp +++ b/src/gui/amatparticleconfigurator.cpp @@ -1,29 +1,30 @@ #include "amatparticleconfigurator.h" #include "ui_amatparticleconfigurator.h" #include "ajsontools.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "afiletools.h" #include #include #include -AMatParticleConfigurator::AMatParticleConfigurator(GlobalSettingsClass *GlobSet, QWidget *parent) : - QDialog(parent), ui(new Ui::AMatParticleConfigurator), GlobSet(GlobSet) +AMatParticleConfigurator::AMatParticleConfigurator(QWidget *parent) : + QDialog(parent), ui(new Ui::AMatParticleConfigurator) { ui->setupUi(this); ui->pbUpdateGlobSet->setVisible(false); ui->cobUnits->setCurrentIndex(1); - CrossSectionSystemDir = GlobSet->ResourcesDir + "/Neutrons/CrossSections"; + AGlobalSettings& GlobSet = AGlobalSettings::getInstance(); + CrossSectionSystemDir = GlobSet.ResourcesDir + "/Neutrons/CrossSections"; QDoubleValidator* val = new QDoubleValidator(this); val->setBottom(0); ui->ledMinEnergy->setValidator(val); ui->ledMaxEnergy->setValidator(val); - if (!GlobSet->MaterialsAndParticlesSettings.isEmpty()) - readFromJson(GlobSet->MaterialsAndParticlesSettings); + if (!GlobSet.MaterialsAndParticlesSettings.isEmpty()) + readFromJson(GlobSet.MaterialsAndParticlesSettings); } AMatParticleConfigurator::~AMatParticleConfigurator() @@ -117,7 +118,7 @@ double AMatParticleConfigurator::getMaxEnergy() const const QString AMatParticleConfigurator::getNatAbundFileName() const { - return GlobSet->ResourcesDir + "/Neutrons/IsotopeNaturalAbundances.txt"; + return AGlobalSettings::getInstance().ResourcesDir + "/Neutrons/IsotopeNaturalAbundances.txt"; } const QString AMatParticleConfigurator::getCrossSectionFirstDataDir() const @@ -192,7 +193,7 @@ void AMatParticleConfigurator::on_pbChangeDir_clicked() void AMatParticleConfigurator::on_pbUpdateGlobSet_clicked() { - writeToJson(GlobSet->MaterialsAndParticlesSettings); + writeToJson(AGlobalSettings::getInstance().MaterialsAndParticlesSettings); } #include diff --git a/src/gui/amatparticleconfigurator.h b/src/gui/amatparticleconfigurator.h index 53b6b7e1..1246424b 100644 --- a/src/gui/amatparticleconfigurator.h +++ b/src/gui/amatparticleconfigurator.h @@ -5,7 +5,6 @@ #include class QJsonObject; -class GlobalSettingsClass; namespace Ui { class AMatParticleConfigurator; @@ -16,7 +15,7 @@ class AMatParticleConfigurator : public QDialog Q_OBJECT public: - explicit AMatParticleConfigurator(GlobalSettingsClass *GlobSet, QWidget *parent = 0); + explicit AMatParticleConfigurator(QWidget *parent = 0); ~AMatParticleConfigurator(); const QString getElasticScatteringFileName(QString Element, QString Mass) const; @@ -53,7 +52,6 @@ private slots: private: Ui::AMatParticleConfigurator *ui; - GlobalSettingsClass* GlobSet; QString StarterDir; QString CrossSectionSystemDir; diff --git a/src/gui/aremotewindow.cpp b/src/gui/aremotewindow.cpp index fa017884..1ca99b67 100644 --- a/src/gui/aremotewindow.cpp +++ b/src/gui/aremotewindow.cpp @@ -5,7 +5,7 @@ #include "aserverdelegate.h" #include "mainwindow.h" #include "aconfiguration.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "amessage.h" #include "ajsontools.h" @@ -56,12 +56,12 @@ void ARemoteWindow::WriteConfig() for (ARemoteServerRecord* r : Records) ar << r->WriteToJson(); json["Servers"] = ar; - MW->GlobSet->RemoteServers = json; + MW->GlobSet.RemoteServers = json; } void ARemoteWindow::ReadConfig() { - QJsonObject& json = MW->GlobSet->RemoteServers; + QJsonObject& json = MW->GlobSet.RemoteServers; if (json.isEmpty()) return; Clear(); @@ -217,7 +217,7 @@ void ARemoteWindow::on_pbRateServers_clicked() { WriteConfig(); - const QString DefDet = MW->GlobSet->ExamplesDir + "/StartupDetector.json"; + const QString DefDet = MW->GlobSet.ExamplesDir + "/StartupDetector.json"; QJsonObject js; bool bOK = LoadJsonFromFile(js, DefDet); if (!bOK) diff --git a/src/gui/ascriptexampleexplorer.cpp b/src/gui/ascriptexampleexplorer.cpp index 72d21846..319d343b 100644 --- a/src/gui/ascriptexampleexplorer.cpp +++ b/src/gui/ascriptexampleexplorer.cpp @@ -1,7 +1,7 @@ #include "ascriptexampleexplorer.h" #include "ui_ascriptexampleexplorer.h" #include "ascriptexampledatabase.h" -#include "globalsettingsclass.h" +//#include "aglobalsettings.h" #include #include diff --git a/src/gui/ascriptwindow.cpp b/src/gui/ascriptwindow.cpp index 405146df..86497d0a 100644 --- a/src/gui/ascriptwindow.cpp +++ b/src/gui/ascriptwindow.cpp @@ -19,7 +19,7 @@ #include "apythonscriptmanager.h" #endif -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "afiletools.h" #include @@ -49,9 +49,9 @@ //#include #include -AScriptWindow::AScriptWindow(AScriptManager* ScriptManager, GlobalSettingsClass *GlobSet, bool LightMode, QWidget *parent) : +AScriptWindow::AScriptWindow(AScriptManager* ScriptManager, bool LightMode, QWidget *parent) : QMainWindow(parent), ScriptManager(ScriptManager), bLightMode(LightMode), - ui(new Ui::AScriptWindow) + ui(new Ui::AScriptWindow), GlobSet(AGlobalSettings::getInstance()) { if ( dynamic_cast(ScriptManager) ) { @@ -80,10 +80,9 @@ AScriptWindow::AScriptWindow(AScriptManager* ScriptManager, GlobalSettingsClass QObject::connect(ScriptManager, &AScriptManager::onAbort, this, &AScriptWindow::receivedOnAbort); QObject::connect(ScriptManager, &AScriptManager::onFinish, this, &AScriptWindow::receivedOnSuccess); - this->GlobSet = GlobSet; - ScriptManager->LibScripts = &GlobSet->LibScripts; - ScriptManager->LastOpenDir = &GlobSet->LastOpenDir; - ScriptManager->ExamplesDir = &GlobSet->ExamplesDir; + ScriptManager->LibScripts = &GlobSet.LibScripts; + ScriptManager->LastOpenDir = &GlobSet.LastOpenDir; + ScriptManager->ExamplesDir = &GlobSet.ExamplesDir; ShowEvalResult = true; ui->setupUi(this); @@ -377,8 +376,8 @@ void AScriptWindow::WriteToJson() if (bLightMode) return; QJsonObject* ScriptWindowJsonPtr = 0; - if ( ScriptLanguage == _JavaScript_) ScriptWindowJsonPtr = &GlobSet->ScriptWindowJson; - else if ( ScriptLanguage == _PythonScript_) ScriptWindowJsonPtr = &GlobSet->PythonScriptWindowJson; + if ( ScriptLanguage == _JavaScript_) ScriptWindowJsonPtr = &GlobSet.ScriptWindowJson; + else if ( ScriptLanguage == _PythonScript_) ScriptWindowJsonPtr = &GlobSet.PythonScriptWindowJson; if (!ScriptWindowJsonPtr) return; QJsonObject& json = *ScriptWindowJsonPtr; @@ -409,8 +408,8 @@ void AScriptWindow::ReadFromJson() if (bLightMode) return; QJsonObject* ScriptWindowJsonPtr = 0; - if ( ScriptLanguage == _JavaScript_) ScriptWindowJsonPtr = &GlobSet->ScriptWindowJson; - else if ( ScriptLanguage == _PythonScript_) ScriptWindowJsonPtr = &GlobSet->PythonScriptWindowJson; + if ( ScriptLanguage == _JavaScript_) ScriptWindowJsonPtr = &GlobSet.ScriptWindowJson; + else if ( ScriptLanguage == _PythonScript_) ScriptWindowJsonPtr = &GlobSet.PythonScriptWindowJson; if (!ScriptWindowJsonPtr) return; QJsonObject& json = *ScriptWindowJsonPtr; @@ -515,7 +514,7 @@ void AScriptWindow::on_pbRunScript_clicked() if (!bLightMode) { WriteToJson(); - GlobSet->SaveANTSconfiguration(); + GlobSet.saveANTSconfiguration(); } QString Script = ScriptTabs[CurrentTab]->TextEdit->document()->toPlainText(); @@ -625,7 +624,7 @@ void AScriptWindow::on_pbStop_clicked() void AScriptWindow::on_pbLoad_clicked() { - QString starter = (GlobSet->LibScripts.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibScripts; + QString starter = (GlobSet.LibScripts.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibScripts; QString fileName = QFileDialog::getOpenFileName(this, "Load script", starter, "Script files (*.txt *.js);;All files (*.*)"); //"" if (fileName.isEmpty()) return; @@ -702,7 +701,7 @@ void AScriptWindow::on_pbSave_clicked() void AScriptWindow::on_pbSaveAs_clicked() { if (ScriptTabs.isEmpty()) return; - QString starter = (GlobSet->LibScripts.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibScripts; + QString starter = (GlobSet.LibScripts.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibScripts; if (!ScriptTabs[CurrentTab]->FileName.isEmpty()) starter = ScriptTabs[CurrentTab]->FileName; QString fileName = QFileDialog::getSaveFileName(this,"Save script", starter, "Script files (*.txt *.js);;All files (*.*)"); if (fileName.isEmpty()) return; @@ -751,7 +750,7 @@ void AScriptWindow::on_pbExample_clicked() //reading example database QString target = (ScriptLanguage == _JavaScript_ ? "ScriptExamples.cfg" : "PythonScriptExamples.cfg"); - QString RecordsFilename = GlobSet->ExamplesDir + "/" + target; + QString RecordsFilename = GlobSet.ExamplesDir + "/" + target; //check it is found QFile file(RecordsFilename); if (!file.open(QIODevice::ReadOnly)) @@ -1133,7 +1132,7 @@ void AScriptWindow::receivedOnSuccess(QString eval) void AScriptWindow::onDefaulFontSizeChanged(int size) { - GlobSet->DefaultFontSize_ScriptWindow = size; + GlobSet.DefaultFontSize_ScriptWindow = size; for (AScriptWindowTabItem* tab : ScriptTabs) tab->TextEdit->SetFontSize(size); } @@ -1407,13 +1406,13 @@ void AScriptWindow::AddNewTab() //tab->TextEdit->functionList = functionList; UpdateTab(tab); - if (GlobSet->DefaultFontFamily_ScriptWindow.isEmpty()) + if (GlobSet.DefaultFontFamily_ScriptWindow.isEmpty()) { - tab->TextEdit->SetFontSize(GlobSet->DefaultFontSize_ScriptWindow); + tab->TextEdit->SetFontSize(GlobSet.DefaultFontSize_ScriptWindow); } else { - QFont font(GlobSet->DefaultFontFamily_ScriptWindow, GlobSet->DefaultFontSize_ScriptWindow, GlobSet->DefaultFontWeight_ScriptWindow, GlobSet->DefaultFontItalic_ScriptWindow); + QFont font(GlobSet.DefaultFontFamily_ScriptWindow, GlobSet.DefaultFontSize_ScriptWindow, GlobSet.DefaultFontWeight_ScriptWindow, GlobSet.DefaultFontItalic_ScriptWindow); tab->TextEdit->setFont(font); } @@ -1488,15 +1487,15 @@ void AScriptWindow::on_pbHelp_toggled(bool checked) void AScriptWindow::on_actionIncrease_font_size_triggered() { - onDefaulFontSizeChanged(++GlobSet->DefaultFontSize_ScriptWindow); + onDefaulFontSizeChanged(++GlobSet.DefaultFontSize_ScriptWindow); } void AScriptWindow::on_actionDecrease_font_size_triggered() { - if (GlobSet->DefaultFontSize_ScriptWindow<1) return; + if (GlobSet.DefaultFontSize_ScriptWindow<1) return; - onDefaulFontSizeChanged(--GlobSet->DefaultFontSize_ScriptWindow); - //qDebug() << "New font size:"<DefaultFontSize_ScriptWindow; + onDefaulFontSizeChanged(--GlobSet.DefaultFontSize_ScriptWindow); + //qDebug() << "New font size:"< @@ -1505,17 +1504,17 @@ void AScriptWindow::on_actionSelect_font_triggered() bool ok; QFont font = QFontDialog::getFont( &ok, - QFont(GlobSet->DefaultFontFamily_ScriptWindow, - GlobSet->DefaultFontSize_ScriptWindow, - GlobSet->DefaultFontWeight_ScriptWindow, - GlobSet->DefaultFontItalic_ScriptWindow), + QFont(GlobSet.DefaultFontFamily_ScriptWindow, + GlobSet.DefaultFontSize_ScriptWindow, + GlobSet.DefaultFontWeight_ScriptWindow, + GlobSet.DefaultFontItalic_ScriptWindow), this); if (!ok) return; - GlobSet->DefaultFontFamily_ScriptWindow = font.family(); - GlobSet->DefaultFontSize_ScriptWindow = font.pointSize(); - GlobSet->DefaultFontWeight_ScriptWindow = font.weight(); - GlobSet->DefaultFontItalic_ScriptWindow = font.italic(); + GlobSet.DefaultFontFamily_ScriptWindow = font.family(); + GlobSet.DefaultFontSize_ScriptWindow = font.pointSize(); + GlobSet.DefaultFontWeight_ScriptWindow = font.weight(); + GlobSet.DefaultFontItalic_ScriptWindow = font.italic(); for (AScriptWindowTabItem* tab : ScriptTabs) tab->TextEdit->setFont(font); @@ -1603,7 +1602,7 @@ void AScriptWindow::on_actionRemove_all_tabs_triggered() void AScriptWindow::on_actionStore_all_tabs_triggered() { if (ScriptTabs.isEmpty()) return; - QString starter = GlobSet->LastOpenDir; + QString starter = GlobSet.LastOpenDir; QString fileName = QFileDialog::getSaveFileName(this,"Save session", starter, "Json files (*.json);;All files (*.*)"); if (fileName.isEmpty()) return; @@ -1634,7 +1633,7 @@ void AScriptWindow::on_actionRestore_session_triggered() if (ret != QMessageBox::Yes) return; } - QString starter = GlobSet->LastOpenDir; + QString starter = GlobSet.LastOpenDir; QString fileName = QFileDialog::getOpenFileName(this, "Load script", starter, "Json files (*.json);;All files (*.*)"); if (fileName.isEmpty()) return; diff --git a/src/gui/ascriptwindow.h b/src/gui/ascriptwindow.h index fbc333df..1431c481 100644 --- a/src/gui/ascriptwindow.h +++ b/src/gui/ascriptwindow.h @@ -21,8 +21,8 @@ class TObject; class QThread; class AScriptManager; class AScriptWindowTabItem; -class GlobalSettingsClass; class QTextCursor; +class AGlobalSettings; namespace Ui { class AScriptWindow; @@ -33,7 +33,7 @@ class AScriptWindow : public QMainWindow Q_OBJECT public: - explicit AScriptWindow(AScriptManager *ScriptManager, GlobalSettingsClass* GlobSet, bool LightMode, QWidget *parent); + explicit AScriptWindow(AScriptManager *ScriptManager, bool LightMode, QWidget *parent); ~AScriptWindow(); void SetInterfaceObject(QObject *interfaceObject, QString name = ""); @@ -126,9 +126,7 @@ private slots: private: Ui::AScriptWindow *ui; - //QStringListModel* completitionModel; - GlobalSettingsClass* GlobSet; - + AGlobalSettings& GlobSet; ScriptLanguageEnum ScriptLanguage = _JavaScript_; int CurrentTab; diff --git a/src/gui/awebsocketserverdialog.cpp b/src/gui/awebsocketserverdialog.cpp index 36e046c4..adf3172b 100644 --- a/src/gui/awebsocketserverdialog.cpp +++ b/src/gui/awebsocketserverdialog.cpp @@ -1,7 +1,7 @@ #include "awebsocketserverdialog.h" #include "ui_awebsocketserverdialog.h" #include "mainwindow.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "anetworkmodule.h" #include "globalsettingswindowclass.h" #include "windownavigatorclass.h" @@ -17,15 +17,16 @@ AWebSocketServerDialog::AWebSocketServerDialog(MainWindow *MW) : setWindowTitle("ANTS2 servers"); updateNetGui(); - QObject::connect(MW->GlobSet->NetModule, &ANetworkModule::StatusChanged, this, &AWebSocketServerDialog::updateNetGui); - - QObject::connect(MW->GlobSet->NetModule, &ANetworkModule::ReportTextToGUI, this, &AWebSocketServerDialog::addText); + ANetworkModule* Net = MW->GlobSet.getNetworkModule(); + QObject::connect(Net, &ANetworkModule::StatusChanged, this, &AWebSocketServerDialog::updateNetGui); + QObject::connect(Net, &ANetworkModule::ReportTextToGUI, this, &AWebSocketServerDialog::addText); } void AWebSocketServerDialog::updateNetGui() { - bool bW = MW->GlobSet->NetModule->isWebSocketServerRunning(); - bool bJ = MW->GlobSet->NetModule->isRootServerRunning(); + ANetworkModule* Net = MW->GlobSet.getNetworkModule(); + bool bW = Net->isWebSocketServerRunning(); + bool bJ = Net->isRootServerRunning(); bool bbJ = false; #ifdef USE_ROOT_HTML bbJ = true; @@ -60,22 +61,23 @@ AWebSocketServerDialog::~AWebSocketServerDialog() void AWebSocketServerDialog::on_pbStartWS_clicked() { - MW->GlobSet->NetModule->StartWebSocketServer(QHostAddress(MW->GlobSet->DefaultWebSocketIP), MW->GlobSet->DefaultWebSocketPort); + MW->GlobSet.getNetworkModule()->StartWebSocketServer(QHostAddress(MW->GlobSet.DefaultWebSocketIP), MW->GlobSet.DefaultWebSocketPort); } void AWebSocketServerDialog::on_pbStopWS_clicked() { - MW->GlobSet->NetModule->StopWebSocketServer(); + + MW->GlobSet.getNetworkModule()->StopWebSocketServer(); } void AWebSocketServerDialog::on_pbStartJSR_clicked() { - MW->GlobSet->NetModule->StartRootHttpServer(MW->GlobSet->DefaultRootServerPort, MW->GlobSet->ExternalJSROOT); //does nothing if compilation flag is not set + MW->GlobSet.getNetworkModule()->StartRootHttpServer(MW->GlobSet.DefaultRootServerPort, MW->GlobSet.ExternalJSROOT); //does nothing if compilation flag is not set } void AWebSocketServerDialog::on_pbStopJSR_clicked() { - MW->GlobSet->NetModule->StopRootHttpServer(); + MW->GlobSet.getNetworkModule()->StopRootHttpServer(); } void AWebSocketServerDialog::on_pbSettings_clicked() diff --git a/src/gui/checkupwindowclass.cpp b/src/gui/checkupwindowclass.cpp index 980d2c13..706030e7 100644 --- a/src/gui/checkupwindowclass.cpp +++ b/src/gui/checkupwindowclass.cpp @@ -8,7 +8,7 @@ #include "materialinspectorwindow.h" #include "generalsimsettings.h" #include "particlesourcesclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include #include @@ -562,9 +562,9 @@ TriState AreaResponseCheckUpItem::doCheckUp() void CheckUpWindowClass::on_pbSaveOverlaps_clicked() { - QString fileName = QFileDialog::getSaveFileName(this, "Save overlaps as text", MW->GlobSet->LastOpenDir+"/Overlaps.txt", "Text files (*.txt)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save overlaps as text", MW->GlobSet.LastOpenDir+"/Overlaps.txt", "Text files (*.txt)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFile outputFile(fileName); outputFile.open(QIODevice::WriteOnly); diff --git a/src/gui/detectoraddonswindow.cpp b/src/gui/detectoraddonswindow.cpp index e1c5727b..b518fa4e 100644 --- a/src/gui/detectoraddonswindow.cpp +++ b/src/gui/detectoraddonswindow.cpp @@ -8,7 +8,7 @@ #include "ajavascriptmanager.h" #include "ascriptwindow.h" #include "detectorclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "ainterfacetoaddobjscript.h" #include "asandwich.h" #include "aslab.h" @@ -86,7 +86,7 @@ DetectorAddOnsWindow::DetectorAddOnsWindow(MainWindow *parent, DetectorClass *de QList list = this->findChildren(); foreach(QLineEdit *w, list) if (w->objectName().startsWith("led")) w->setValidator(dv); - ui->cbAutoCheck->setChecked( MW->GlobSet->PerformAutomaticGeometryCheck ); + ui->cbAutoCheck->setChecked( MW->GlobSet.PerformAutomaticGeometryCheck ); on_cbAutoCheck_stateChanged(111); } @@ -360,10 +360,10 @@ void DetectorAddOnsWindow::on_sbDummyType_valueChanged(int arg1) void DetectorAddOnsWindow::on_pbLoadDummyPMs_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load file with dummy PMs", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);; All files (*.*)"); + fileName = QFileDialog::getOpenFileName(this, "Load file with dummy PMs", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);; All files (*.*)"); //qDebug()<GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); Detector->PMdummies.resize(0); MW->LoadDummyPMs(fileName); ui->sbDummyPMindex->setValue(0); @@ -531,7 +531,7 @@ void DetectorAddOnsWindow::on_pbUseScriptToAddObj_clicked() delete MW->GenScriptWindow; MW->GenScriptWindow = 0; AJavaScriptManager* jsm = new AJavaScriptManager(MW->Detector->RandGen); - MW->GenScriptWindow = new AScriptWindow(jsm, MW->GlobSet, true, this); + MW->GenScriptWindow = new AScriptWindow(jsm, true, this); QString example = "ClearAll()\nfor (var i=0; i<3; i++)\n Box('Test'+i, 10,5,2, 0, 'PrScint', (i-1)*20,i*2,-i*5, 0,0,0)"; QString title = ( ObjectScriptTarget.isEmpty() ? "Add objects script" : QString("Add objects script. Script will be stored in object ") + ObjectScriptTarget ); @@ -580,7 +580,7 @@ void DetectorAddOnsWindow::on_pbUseScriptToAddObj_clicked() // MW->GenScriptWindow->SetTitle("Add objects script. Script will be stored in object "+ObjectScriptTarget); // MW->GenScriptWindow->SetScript(&Detector->AddObjPositioningScript); -// MW->GenScriptWindow->SetStarterDir(MW->GlobSet->LibScripts); +// MW->GenScriptWindow->SetStarterDir(MW->GlobSet.LibScripts); // connect(MW->GenScriptWindow, SIGNAL(success(QString)), this, SLOT(AddObjScriptSuccess())); // // AddObjScriptInterface->GeoObjects.clear(); @@ -606,12 +606,12 @@ void DetectorAddOnsWindow::ReportScriptError(QString ErrorMessage) void DetectorAddOnsWindow::on_pbSaveTGeo_clicked() { - QString starter = MW->GlobSet->LastOpenDir; + QString starter = MW->GlobSet.LastOpenDir; QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("gdml"); QString fileName = fileDialog->getSaveFileName(this, "Export detector geometry", starter, "GDML files (*.gdml);;Root files (*.root)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo fi(fileName); if (fi.suffix().isEmpty()) fileName += ".gdml"; @@ -901,9 +901,9 @@ void readGeoObjectTree(AGeoObject* obj, const TGeoNode* node, void DetectorAddOnsWindow::on_pmParseInGeometryFromGDML_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load GDML file", MW->GlobSet->LastOpenDir, "GDML files (*.gdml)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load GDML file", MW->GlobSet.LastOpenDir, "GDML files (*.gdml)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo fi(fileName); if (fi.suffix() != "gdml") { @@ -911,7 +911,7 @@ void DetectorAddOnsWindow::on_pmParseInGeometryFromGDML_clicked() return; } - MW->Config->LoadConfig(MW->GlobSet->ExamplesDir + "/Empty.json"); + MW->Config->LoadConfig(MW->GlobSet.ExamplesDir + "/Empty.json"); QString PMtemplate = ui->lePMtemplate->text(); if (Detector->GeoManager) delete Detector->GeoManager; @@ -1020,9 +1020,9 @@ void DetectorAddOnsWindow::on_pmParseInGeometryFromGDML_clicked() void DetectorAddOnsWindow::on_pbLoadTGeo_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load GDML file", MW->GlobSet->LastOpenDir, "GDML files (*.gdml)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load GDML file", MW->GlobSet.LastOpenDir, "GDML files (*.gdml)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo fi(fileName); if (fi.suffix() != "gdml") @@ -1076,7 +1076,7 @@ void DetectorAddOnsWindow::on_pbCheckGeometry_clicked() void DetectorAddOnsWindow::on_cbAutoCheck_clicked(bool checked) { - MW->GlobSet->PerformAutomaticGeometryCheck = checked; + MW->GlobSet.PerformAutomaticGeometryCheck = checked; if (!checked) MW->CheckUpWindow->hide(); } diff --git a/src/gui/exampleswindow.cpp b/src/gui/exampleswindow.cpp index a626fdd8..e163eea8 100644 --- a/src/gui/exampleswindow.cpp +++ b/src/gui/exampleswindow.cpp @@ -4,7 +4,7 @@ #include "windownavigatorclass.h" #include "geometrywindowclass.h" #include "reconstructionwindow.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "ajsontools.h" #include "amessage.h" #include "aconfiguration.h" @@ -36,9 +36,9 @@ ExamplesWindow::ExamplesWindow(QWidget *parent, MainWindow *mw) : Examples.resize(0); ListedExamples.resize(0); - ui->cbDoNotShowExamplesOnStart->setChecked(!MW->GlobSet->ShowExamplesOnStart); + ui->cbDoNotShowExamplesOnStart->setChecked(!MW->GlobSet.ShowExamplesOnStart); - QString fileName = MW->GlobSet->QuicksaveDir + "/QuickSave0.json"; + QString fileName = MW->GlobSet.QuicksaveDir + "/QuickSave0.json"; QString s = "Not available"; QFileInfo fi(fileName); if (fi.exists()) @@ -75,7 +75,7 @@ void ExamplesWindow::SaveConfig(QString fileName, bool DetConstructor, bool SimS void ExamplesWindow::on_cbDoNotShowExamplesOnStart_toggled(bool checked) { - MW->GlobSet->ShowExamplesOnStart = !checked; + MW->GlobSet.ShowExamplesOnStart = !checked; } bool ExamplesWindow::event(QEvent *event) @@ -96,7 +96,7 @@ bool ExamplesWindow::event(QEvent *event) void ExamplesWindow::BuildExampleRecord() { - QString fileName = MW->GlobSet->ExamplesDir + "/ExamplesTree.txt"; + QString fileName = MW->GlobSet.ExamplesDir + "/ExamplesTree.txt"; QFile file(fileName); if(!file.open(QIODevice::ReadOnly | QFile::Text)) { @@ -274,7 +274,7 @@ void ExamplesWindow::on_pbLoadExample_clicked() this->close(); MW->GeometryDrawDisabled = true; - QString filename = MW->GlobSet->ExamplesDir + "/" + Examples[ListedExamples[ExamplePointer]].filename; + QString filename = MW->GlobSet.ExamplesDir + "/" + Examples[ListedExamples[ExamplePointer]].filename; bool bOK = MW->Config->LoadConfig(filename); if (!bOK) message(MW->Config->ErrorString, MW); @@ -296,9 +296,9 @@ void ExamplesWindow::on_lwExample_doubleClicked(const QModelIndex &index) void ExamplesWindow::on_pbSaveSessings_clicked() { - QString fileName = QFileDialog::getSaveFileName(this,"Save configuration", MW->GlobSet->LastOpenDir, "Json files (*.json)"); + QString fileName = QFileDialog::getSaveFileName(this,"Save configuration", MW->GlobSet.LastOpenDir, "Json files (*.json)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo file(fileName); if(file.suffix().isEmpty()) fileName += ".json"; MW->ELwindow->SaveConfig(fileName, !ui->cbSkipDetectorConstructor->isChecked(), !ui->cbSkipSimConfig->isChecked(), !ui->cbSkipRecConfig->isChecked()); @@ -306,9 +306,9 @@ void ExamplesWindow::on_pbSaveSessings_clicked() void ExamplesWindow::on_pbLoadSettings_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load configuration", MW->GlobSet->LastOpenDir, "All files (*.*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load configuration", MW->GlobSet.LastOpenDir, "All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); MW->GeometryDrawDisabled = true; //-> bool bOK = MW->Config->LoadConfig(fileName, !ui->cbSkipDetectorConstructor->isChecked(), !ui->cbSkipSimConfig->isChecked(), !ui->cbSkipRecConfig->isChecked()); @@ -328,7 +328,7 @@ void ExamplesWindow::on_pbLoadLast_clicked() void ExamplesWindow::QuickLoad(int i, QWidget *parent) { - QString fileName = MW->GlobSet->QuicksaveDir + "/QuickSave" + QString::number(i) + ".json"; + QString fileName = MW->GlobSet.QuicksaveDir + "/QuickSave" + QString::number(i) + ".json"; if (!QFileInfo(fileName).exists()) { QString s; @@ -350,7 +350,7 @@ void ExamplesWindow::QuickLoad(int i, QWidget *parent) QString ExamplesWindow::getQuickSlotMessage(int i) { - QString fileName = MW->GlobSet->QuicksaveDir + "/QuickSave" + QString::number(i) + ".json"; + QString fileName = MW->GlobSet.QuicksaveDir + "/QuickSave" + QString::number(i) + ".json"; QString s; if (i==0) s = "Save on exit configuration file not found"; else s = "Quick save slot # " + QString::number(i) + " is empty"; @@ -377,7 +377,7 @@ void ExamplesWindow::on_pbQuickSave3_clicked() void ExamplesWindow::QuickSave(int i) { - QString fileName = MW->GlobSet->QuicksaveDir + "/QuickSave" + QString::number(i) + ".json"; + QString fileName = MW->GlobSet.QuicksaveDir + "/QuickSave" + QString::number(i) + ".json"; MW->ELwindow->SaveConfig(fileName); } @@ -443,7 +443,7 @@ void ExamplesWindow::on_actionQuick_load_3_hovered() void ExamplesWindow::on_actionCreate_new_detector_triggered() { - MW->Config->LoadConfig(MW->GlobSet->ExamplesDir + "/Simplest.json"); + MW->Config->LoadConfig(MW->GlobSet.ExamplesDir + "/Simplest.json"); hide(); if (MW->GeometryWindow->isVisible()) MW->GeometryWindow->ShowGeometry(false); } diff --git a/src/gui/geometrywindowclass.cpp b/src/gui/geometrywindowclass.cpp index e0ad6812..1eb4e78a 100644 --- a/src/gui/geometrywindowclass.cpp +++ b/src/gui/geometrywindowclass.cpp @@ -7,7 +7,7 @@ #include "windownavigatorclass.h" #include "detectorclass.h" #include "rasterwindowbaseclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "ajsontools.h" #include "amessage.h" @@ -425,7 +425,7 @@ void GeometryWindowClass::ShowGeometry(bool ActivateWindow, bool SAME, bool Colo //with or without activation (focussing) of this window if (ActivateWindow) ShowAndFocus(); //window is activated (focused) else SetAsActiveRootWindow(); //no activation in this mode - MW->Detector->GeoManager->SetNsegments(MW->GlobSet->NumSegments); + MW->Detector->GeoManager->SetNsegments(MW->GlobSet.NumSegments); int level = ui->sbLimitVisibility->value(); if (!ui->cbLimitVisibility->isChecked()) level = -1; MW->Detector->GeoManager->SetVisLevel(level); @@ -530,16 +530,16 @@ void GeometryWindowClass::on_pbSaveAs_clicked() { QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("png"); - QString fileName = fileDialog->getSaveFileName(this, "Save image as file", MW->GlobSet->LastOpenDir, "png (*.png);;gif (*.gif);;Jpg (*.jpg)"); + QString fileName = fileDialog->getSaveFileName(this, "Save image as file", MW->GlobSet.LastOpenDir, "png (*.png);;gif (*.gif);;Jpg (*.jpg)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo file(fileName); if(file.suffix().isEmpty()) fileName += ".png"; GeometryWindowClass::SaveAs(fileName); - if (MW->GlobSet->fOpenImageExternalEditor) QDesktopServices::openUrl(QUrl("file:"+fileName, QUrl::TolerantMode)); + if (MW->GlobSet.fOpenImageExternalEditor) QDesktopServices::openUrl(QUrl("file:"+fileName, QUrl::TolerantMode)); } void GeometryWindowClass::on_pbShowGLview_clicked() diff --git a/src/gui/globalsettingswindowclass.cpp b/src/gui/globalsettingswindowclass.cpp index 500782b7..226a6e2d 100644 --- a/src/gui/globalsettingswindowclass.cpp +++ b/src/gui/globalsettingswindowclass.cpp @@ -3,7 +3,7 @@ #include "mainwindow.h" #include "ajavascriptmanager.h" #include "ascriptwindow.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "detectorclass.h" #include "amessage.h" #include "anetworkmodule.h" @@ -23,7 +23,6 @@ GlobalSettingsWindowClass::GlobalSettingsWindowClass(MainWindow *parent) : ui(new Ui::GlobalSettingsWindowClass) { MW = parent; - GlobSet = MW->GlobSet; ui->setupUi(this); Qt::WindowFlags windowFlags = (Qt::Window | Qt::CustomizeWindowHint); @@ -32,10 +31,10 @@ GlobalSettingsWindowClass::GlobalSettingsWindowClass(MainWindow *parent) : this->setWindowFlags( windowFlags ); updateGUI(); - QObject::connect(GlobSet->NetModule, &ANetworkModule::StatusChanged, this, &GlobalSettingsWindowClass::updateNetGui); + QObject::connect(MW->GlobSet.getNetworkModule(), &ANetworkModule::StatusChanged, this, &GlobalSettingsWindowClass::updateNetGui); - if (GlobSet->fRunRootServerOnStart) - GlobSet->NetModule->StartRootHttpServer(GlobSet->DefaultRootServerPort, GlobSet->ExternalJSROOT); //does nothing if compilation flag is not set + if (MW->GlobSet.fRunRootServerOnStart) + MW->GlobSet.getNetworkModule()->StartRootHttpServer(MW->GlobSet.DefaultRootServerPort, MW->GlobSet.ExternalJSROOT); //does nothing if compilation flag is not set } GlobalSettingsWindowClass::~GlobalSettingsWindowClass() @@ -45,68 +44,70 @@ GlobalSettingsWindowClass::~GlobalSettingsWindowClass() void GlobalSettingsWindowClass::updateGUI() { - ui->leLibPMtypes->setText(GlobSet->LibPMtypes); - ui->leLibMaterials->setText(GlobSet->LibMaterials); - ui->leLibParticleSources->setText(GlobSet->LibParticleSources); - ui->leLibScripts->setText(GlobSet->LibScripts); + ui->leLibPMtypes->setText(MW->GlobSet.LibPMtypes); + ui->leLibMaterials->setText(MW->GlobSet.LibMaterials); + ui->leLibParticleSources->setText(MW->GlobSet.LibParticleSources); + ui->leLibScripts->setText(MW->GlobSet.LibScripts); - ui->leWorkingDir->setText(GlobSet->TmpDir); + ui->leWorkingDir->setText(MW->GlobSet.TmpDir); - ui->sbFontSize->setValue(GlobSet->FontSize); + ui->sbFontSize->setValue(MW->GlobSet.FontSize); - //ui->rbNever->setChecked(GlobSet->NeverSaveOnExit); - //ui->rbAlways->setChecked(GlobSet->AlwaysSaveOnExit); - //ui->rbAskMe->setChecked(!GlobSet->NeverSaveOnExit && !GlobSet->AlwaysSaveOnExit); + //ui->rbNever->setChecked(MW->GlobSet.NeverSaveOnExit); + //ui->rbAlways->setChecked(MW->GlobSet.AlwaysSaveOnExit); + //ui->rbAskMe->setChecked(!MW->GlobSet.NeverSaveOnExit && !MW->GlobSet.AlwaysSaveOnExit); - ui->cbOpenImageExternalEditor->setChecked(GlobSet->fOpenImageExternalEditor); + ui->cbOpenImageExternalEditor->setChecked(MW->GlobSet.fOpenImageExternalEditor); - ui->sbLogPrecision->setValue(GlobSet->TextLogPrecision); + ui->sbLogPrecision->setValue(MW->GlobSet.TextLogPrecision); - ui->sbNumBinsHistogramsX->setValue(GlobSet->BinsX); - ui->sbNumBinsHistogramsY->setValue(GlobSet->BinsY); - ui->sbNumBinsHistogramsZ->setValue(GlobSet->BinsZ); + ui->sbNumBinsHistogramsX->setValue(MW->GlobSet.BinsX); + ui->sbNumBinsHistogramsY->setValue(MW->GlobSet.BinsY); + ui->sbNumBinsHistogramsZ->setValue(MW->GlobSet.BinsZ); - ui->sbNumPointsFunctionX->setValue(GlobSet->FunctionPointsX); - ui->sbNumPointsFunctionY->setValue(GlobSet->FunctionPointsY); + ui->sbNumPointsFunctionX->setValue(MW->GlobSet.FunctionPointsX); + ui->sbNumPointsFunctionY->setValue(MW->GlobSet.FunctionPointsY); - ui->sbNumSegments->setValue(GlobSet->NumSegments); + ui->sbNumSegments->setValue(MW->GlobSet.NumSegments); - ui->sbNumTreads->setValue(GlobSet->NumThreads); - ui->sbRecNumTreads->setValue(GlobSet->RecNumTreads); + ui->sbNumTreads->setValue(MW->GlobSet.NumThreads); + ui->sbRecNumTreads->setValue(MW->GlobSet.RecNumTreads); - ui->cbSaveRecAsTree_IncludePMsignals->setChecked(GlobSet->RecTreeSave_IncludePMsignals); - ui->cbSaveRecAsTree_IncludeRho->setChecked(GlobSet->RecTreeSave_IncludeRho); - ui->cbSaveRecAsTree_IncludeTrue->setChecked(GlobSet->RecTreeSave_IncludeTrue); + ui->cbSaveRecAsTree_IncludePMsignals->setChecked(MW->GlobSet.RecTreeSave_IncludePMsignals); + ui->cbSaveRecAsTree_IncludeRho->setChecked(MW->GlobSet.RecTreeSave_IncludeRho); + ui->cbSaveRecAsTree_IncludeTrue->setChecked(MW->GlobSet.RecTreeSave_IncludeTrue); - ui->cbSaveSimAsText_IncludeNumPhotons->setChecked(GlobSet->SimTextSave_IncludeNumPhotons); - ui->cbSaveSimAsText_IncludePositions->setChecked(GlobSet->SimTextSave_IncludePositions); + ui->cbSaveSimAsText_IncludeNumPhotons->setChecked(MW->GlobSet.SimTextSave_IncludeNumPhotons); + ui->cbSaveSimAsText_IncludePositions->setChecked(MW->GlobSet.SimTextSave_IncludePositions); updateNetGui(); } void GlobalSettingsWindowClass::updateNetGui() { - ui->leWebSocketIP->setText(GlobSet->DefaultWebSocketIP); - ui->leWebSocketPort->setText(QString::number(GlobSet->DefaultWebSocketPort)); + ui->leWebSocketIP->setText(MW->GlobSet.DefaultWebSocketIP); + ui->leWebSocketPort->setText(QString::number(MW->GlobSet.DefaultWebSocketPort)); - bool fWebSocketRunning = GlobSet->NetModule->isWebSocketServerRunning(); + ANetworkModule* Net = MW->GlobSet.getNetworkModule(); + + bool fWebSocketRunning = Net->isWebSocketServerRunning(); ui->cbRunWebSocketServer->setChecked( fWebSocketRunning ); if (fWebSocketRunning) { - int port = GlobSet->NetModule->getWebSocketPort(); + int port = Net->getWebSocketPort(); ui->leWebSocketPort->setText(QString::number(port)); - ui->leWebSocketURL->setText(GlobSet->NetModule->getWebSocketServerURL()); + ui->leWebSocketURL->setText(Net->getWebSocketServerURL()); } - bool fRootServerRunning = GlobSet->NetModule->isRootServerRunning(); + bool fRootServerRunning = Net->isRootServerRunning(); ui->cbRunRootServer->setChecked( fRootServerRunning ); - ui->cbAutoRunRootServer->setChecked( GlobSet->fRunRootServerOnStart ); + ui->cbAutoRunRootServer->setChecked( MW->GlobSet.fRunRootServerOnStart ); #ifdef USE_ROOT_HTML if (fRootServerRunning) { - ui->leJSROOT->setText( GlobSet->NetModule->getJSROOTstring()); - int port = GlobSet->NetModule->getRootServerPort(); + ui->leJSROOT->setText( Net->getJSROOTstring()); + int port = Net->getRootServerPort(); QString sPort = QString::number(port); ui->leRootServerPort->setText(sPort); QString url = "http://localhost:" + sPort; @@ -134,10 +135,10 @@ void GlobalSettingsWindowClass::on_pbgStyleScript_clicked() delete MW->GenScriptWindow; MW->GenScriptWindow = 0; AJavaScriptManager* jsm = new AJavaScriptManager(MW->Detector->RandGen); - MW->GenScriptWindow = new AScriptWindow(jsm, GlobSet, true, this); + MW->GenScriptWindow = new AScriptWindow(jsm, true, this); QString example = QString(""); - MW->GenScriptWindow->ConfigureForLightMode(&GlobSet->RootStyleScript, + MW->GenScriptWindow->ConfigureForLightMode(&MW->GlobSet.RootStyleScript, "Script to set ROOT's gStyle", example); @@ -160,8 +161,8 @@ void GlobalSettingsWindowClass::on_pbgStyleScript_clicked() MW->GenScriptWindow->SetExample(""); MW->GenScriptWindow->SetShowEvaluationResult(false); //do not show "undefined" MW->GenScriptWindow->SetTitle("Script to set ROOT's gStyle"); - MW->GenScriptWindow->SetScript(&GlobSet->RootStyleScript); - MW->GenScriptWindow->SetStarterDir(MW->GlobSet->LibScripts); + MW->GenScriptWindow->SetScript(&MW->GlobSet.RootStyleScript); + MW->GenScriptWindow->SetStarterDir(MW->MW->GlobSet.LibScripts); //define what to do on evaluation success //connect(MW->GenScriptWindow, SIGNAL(success(QString)), this, SLOT(HolesScriptSuccess())); @@ -172,63 +173,63 @@ void GlobalSettingsWindowClass::on_pbgStyleScript_clicked() void GlobalSettingsWindowClass::on_pbChoosePMtypeLib_clicked() { - QString starter = (GlobSet->LibPMtypes.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibPMtypes; + QString starter = (MW->GlobSet.LibPMtypes.isEmpty()) ? MW->GlobSet.LastOpenDir : MW->GlobSet.LibPMtypes; QString dir = QFileDialog::getExistingDirectory(this, "Select directory for PM types",starter,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (dir.isEmpty()) return; - GlobSet->LibPMtypes = dir; + MW->GlobSet.LibPMtypes = dir; ui->leLibPMtypes->setText(dir); } void GlobalSettingsWindowClass::on_leLibPMtypes_editingFinished() { - GlobSet->LibPMtypes = ui->leLibPMtypes->text(); + MW->GlobSet.LibPMtypes = ui->leLibPMtypes->text(); } void GlobalSettingsWindowClass::on_pbChooseMaterialLib_clicked() { - QString starter = (GlobSet->LibMaterials.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibMaterials; + QString starter = (MW->GlobSet.LibMaterials.isEmpty()) ? MW->GlobSet.LastOpenDir : MW->GlobSet.LibMaterials; QString dir = QFileDialog::getExistingDirectory(this, "Select directory for materials",starter,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (dir.isEmpty()) return; - GlobSet->LibMaterials = dir; + MW->GlobSet.LibMaterials = dir; ui->leLibMaterials->setText(dir); } void GlobalSettingsWindowClass::on_leLibMaterials_editingFinished() { - GlobSet->LibMaterials = ui->leLibMaterials->text(); + MW->GlobSet.LibMaterials = ui->leLibMaterials->text(); } void GlobalSettingsWindowClass::on_pbChooseParticleSourcesLib_clicked() { - QString starter = (GlobSet->LibParticleSources.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibParticleSources; + QString starter = (MW->GlobSet.LibParticleSources.isEmpty()) ? MW->GlobSet.LastOpenDir : MW->GlobSet.LibParticleSources; QString dir = QFileDialog::getExistingDirectory(this, "Select directory for particle sources",starter,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (dir.isEmpty()) return; - GlobSet->LibParticleSources = dir; + MW->GlobSet.LibParticleSources = dir; ui->leLibParticleSources->setText(dir); } void GlobalSettingsWindowClass::on_leLibParticleSources_editingFinished() { - GlobSet->LibParticleSources = ui->leLibParticleSources->text(); + MW->GlobSet.LibParticleSources = ui->leLibParticleSources->text(); } void GlobalSettingsWindowClass::on_pbChooseScriptsLib_clicked() { - QString starter = (GlobSet->LibScripts.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibScripts; + QString starter = (MW->GlobSet.LibScripts.isEmpty()) ? MW->GlobSet.LastOpenDir : MW->GlobSet.LibScripts; QString dir = QFileDialog::getExistingDirectory(this, "Select directory for scripts",starter,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (dir.isEmpty()) return; - GlobSet->LibScripts = dir; + MW->GlobSet.LibScripts = dir; ui->leLibScripts->setText(dir); } void GlobalSettingsWindowClass::on_leLibScripts_editingFinished() { - GlobSet->LibScripts = ui->leLibScripts->text(); + MW->GlobSet.LibScripts = ui->leLibScripts->text(); } void GlobalSettingsWindowClass::on_pbChangeWorkingDir_clicked() { - QString starter = GlobSet->TmpDir; + QString starter = MW->GlobSet.TmpDir; QString dir = QFileDialog::getExistingDirectory(this, "Select working directory (temporary files are saved here)",starter,QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (dir.isEmpty()) return; - GlobSet->TmpDir = dir; - QDir::setCurrent(GlobSet->TmpDir); + MW->GlobSet.TmpDir = dir; + QDir::setCurrent(MW->GlobSet.TmpDir); ui->leWorkingDir->setText(dir); } void GlobalSettingsWindowClass::on_leWorkingDir_editingFinished() @@ -236,56 +237,56 @@ void GlobalSettingsWindowClass::on_leWorkingDir_editingFinished() QString dir = ui->leWorkingDir->text(); if ( QDir(dir).exists() ) { - GlobSet->TmpDir = dir; - QDir::setCurrent(GlobSet->TmpDir); + MW->GlobSet.TmpDir = dir; + QDir::setCurrent(MW->GlobSet.TmpDir); ui->leWorkingDir->setText(dir); } else { - ui->leWorkingDir->setText(GlobSet->TmpDir); + ui->leWorkingDir->setText(MW->GlobSet.TmpDir); message("Dir does not exists!", this); } } void GlobalSettingsWindowClass::on_sbFontSize_editingFinished() { - GlobSet->FontSize = ui->sbFontSize->value(); - MW->setFontSizeAllWindows(GlobSet->FontSize); + MW->GlobSet.FontSize = ui->sbFontSize->value(); + MW->setFontSizeAllWindows(MW->GlobSet.FontSize); } void GlobalSettingsWindowClass::on_rbAlways_toggled(bool /*checked*/) { - //GlobSet->AlwaysSaveOnExit = checked; + //MW->GlobSet.AlwaysSaveOnExit = checked; } void GlobalSettingsWindowClass::on_rbNever_toggled(bool /*checked*/) { - //GlobSet->NeverSaveOnExit = checked; + //MW->GlobSet.NeverSaveOnExit = checked; } void GlobalSettingsWindowClass::on_cbOpenImageExternalEditor_clicked(bool checked) { - GlobSet->fOpenImageExternalEditor = checked; + MW->GlobSet.fOpenImageExternalEditor = checked; } void GlobalSettingsWindowClass::on_sbLogPrecision_editingFinished() { - GlobSet->TextLogPrecision = ui->sbLogPrecision->value(); + MW->GlobSet.TextLogPrecision = ui->sbLogPrecision->value(); } void GlobalSettingsWindowClass::on_sbNumBinsHistogramsX_editingFinished() { - GlobSet->BinsX = ui->sbNumBinsHistogramsX->value(); + MW->GlobSet.BinsX = ui->sbNumBinsHistogramsX->value(); } void GlobalSettingsWindowClass::on_sbNumBinsHistogramsY_editingFinished() { - GlobSet->BinsY = ui->sbNumBinsHistogramsY->value(); + MW->GlobSet.BinsY = ui->sbNumBinsHistogramsY->value(); } void GlobalSettingsWindowClass::on_sbNumBinsHistogramsZ_editingFinished() { - GlobSet->BinsZ = ui->sbNumBinsHistogramsZ->value(); + MW->GlobSet.BinsZ = ui->sbNumBinsHistogramsZ->value(); } void GlobalSettingsWindowClass::on_pbChoosePMtypeLib_customContextMenuRequested(const QPoint &/*pos*/) @@ -318,19 +319,19 @@ void GlobalSettingsWindowClass::on_pbOpen_clicked() switch (ui->comboBox->currentIndex()) { case 0: - what = GlobSet->AntsBaseDir; + what = MW->GlobSet.AntsBaseDir; break; case 1: - what = GlobSet->ConfigDir; + what = MW->GlobSet.ConfigDir; break; case 2: - what = GlobSet->LibScripts; + what = MW->GlobSet.LibScripts; break; case 3: - what = GlobSet->LastOpenDir; + what = MW->GlobSet.LastOpenDir; break; case 4: - what = GlobSet->ExamplesDir; + what = MW->GlobSet.ExamplesDir; break; } QDesktopServices::openUrl(QUrl("file:///"+what, QUrl::TolerantMode)); @@ -338,19 +339,19 @@ void GlobalSettingsWindowClass::on_pbOpen_clicked() void GlobalSettingsWindowClass::on_sbNumSegments_editingFinished() { - GlobSet->NumSegments = ui->sbNumSegments->value(); - MW->Detector->GeoManager->SetNsegments(GlobSet->NumSegments); + MW->GlobSet.NumSegments = ui->sbNumSegments->value(); + MW->Detector->GeoManager->SetNsegments(MW->GlobSet.NumSegments); MW->GeometryWindow->ShowGeometry(false); } void GlobalSettingsWindowClass::on_sbNumPointsFunctionX_editingFinished() { - GlobSet->FunctionPointsX = ui->sbNumPointsFunctionX->value(); + MW->GlobSet.FunctionPointsX = ui->sbNumPointsFunctionX->value(); } void GlobalSettingsWindowClass::on_sbNumPointsFunctionY_editingFinished() { - GlobSet->FunctionPointsY = ui->sbNumPointsFunctionY->value(); + MW->GlobSet.FunctionPointsY = ui->sbNumPointsFunctionY->value(); } void GlobalSettingsWindowClass::on_sbNumTreads_valueChanged(int arg1) @@ -360,42 +361,43 @@ void GlobalSettingsWindowClass::on_sbNumTreads_valueChanged(int arg1) void GlobalSettingsWindowClass::on_sbNumTreads_editingFinished() { - GlobSet->NumThreads = ui->sbNumTreads->value(); + MW->GlobSet.NumThreads = ui->sbNumTreads->value(); } void GlobalSettingsWindowClass::on_cbSaveRecAsTree_IncludePMsignals_clicked(bool checked) { - GlobSet->RecTreeSave_IncludePMsignals = checked; + MW->GlobSet.RecTreeSave_IncludePMsignals = checked; } void GlobalSettingsWindowClass::on_cbSaveRecAsTree_IncludeRho_clicked(bool checked) { - GlobSet->RecTreeSave_IncludeRho = checked; + MW->GlobSet.RecTreeSave_IncludeRho = checked; } void GlobalSettingsWindowClass::on_cbSaveRecAsTree_IncludeTrue_clicked(bool checked) { - GlobSet->RecTreeSave_IncludeTrue = checked; + MW->GlobSet.RecTreeSave_IncludeTrue = checked; } void GlobalSettingsWindowClass::on_cbRunWebSocketServer_clicked(bool checked) { - GlobSet->NetModule->StopWebSocketServer(); + ANetworkModule* Net = MW->GlobSet.getNetworkModule(); + Net->StopWebSocketServer(); if (checked) - GlobSet->NetModule->StartWebSocketServer(QHostAddress(GlobSet->DefaultWebSocketIP), GlobSet->DefaultWebSocketPort); + Net->StartWebSocketServer(QHostAddress(MW->GlobSet.DefaultWebSocketIP), MW->GlobSet.DefaultWebSocketPort); } void GlobalSettingsWindowClass::on_leWebSocketPort_editingFinished() { - int oldp = GlobSet->DefaultWebSocketPort; + int oldp = MW->GlobSet.DefaultWebSocketPort; int newp = ui->leWebSocketPort->text().toInt(); if (oldp != newp) { - GlobSet->DefaultWebSocketPort = newp; + MW->GlobSet.DefaultWebSocketPort = newp; ui->cbRunWebSocketServer->setChecked(false); - GlobSet->DefaultWebSocketPort = newp; + MW->GlobSet.DefaultWebSocketPort = newp; ui->leWebSocketPort->setText(QString::number(newp)); } } @@ -403,47 +405,49 @@ void GlobalSettingsWindowClass::on_leWebSocketPort_editingFinished() void GlobalSettingsWindowClass::on_leWebSocketIP_editingFinished() { QString newIP = ui->leWebSocketIP->text(); - if (newIP == GlobSet->DefaultWebSocketIP) return; + if (newIP == MW->GlobSet.DefaultWebSocketIP) return; QHostAddress ip = QHostAddress(newIP); if (ip.isNull()) { - ui->leWebSocketIP->setText(GlobSet->DefaultWebSocketIP); + ui->leWebSocketIP->setText(MW->GlobSet.DefaultWebSocketIP); message("Bad format of IP: use, e.g., 127.0.0.1", this); } else { - GlobSet->DefaultWebSocketIP = newIP; + MW->GlobSet.DefaultWebSocketIP = newIP; ui->cbRunWebSocketServer->setChecked(false); } } void GlobalSettingsWindowClass::on_cbRunRootServer_clicked(bool checked) { + ANetworkModule* Net = MW->GlobSet.getNetworkModule(); + if (checked) - GlobSet->NetModule->StartRootHttpServer(GlobSet->DefaultRootServerPort, GlobSet->ExternalJSROOT); //does nothing if compilation flag is not set + Net->StartRootHttpServer(MW->GlobSet.DefaultRootServerPort, MW->GlobSet.ExternalJSROOT); //does nothing if compilation flag is not set else - GlobSet->NetModule->StopRootHttpServer(); + Net->StopRootHttpServer(); } void GlobalSettingsWindowClass::on_cbAutoRunRootServer_clicked() { - GlobSet->fRunRootServerOnStart = ui->cbAutoRunRootServer->isChecked(); + MW->GlobSet.fRunRootServerOnStart = ui->cbAutoRunRootServer->isChecked(); } void GlobalSettingsWindowClass::on_leRootServerPort_editingFinished() { - int oldp = GlobSet->DefaultRootServerPort; + int oldp = MW->GlobSet.DefaultRootServerPort; int newp = ui->leRootServerPort->text().toInt(); if (oldp == newp) return; - GlobSet->DefaultRootServerPort = newp; + MW->GlobSet.DefaultRootServerPort = newp; ui->cbRunRootServer->setChecked(false); } void GlobalSettingsWindowClass::on_leJSROOT_editingFinished() { - GlobSet->ExternalJSROOT = ui->leJSROOT->text(); + MW->GlobSet.ExternalJSROOT = ui->leJSROOT->text(); } void GlobalSettingsWindowClass::on_cbRunWebSocketServer_toggled(bool checked) @@ -453,10 +457,10 @@ void GlobalSettingsWindowClass::on_cbRunWebSocketServer_toggled(bool checked) void GlobalSettingsWindowClass::on_cbSaveSimAsText_IncludeNumPhotons_clicked(bool checked) { - GlobSet->SimTextSave_IncludeNumPhotons = checked; + MW->GlobSet.SimTextSave_IncludeNumPhotons = checked; } void GlobalSettingsWindowClass::on_cbSaveSimAsText_IncludePositions_clicked(bool checked) { - GlobSet->SimTextSave_IncludePositions = checked; + MW->GlobSet.SimTextSave_IncludePositions = checked; } diff --git a/src/gui/globalsettingswindowclass.h b/src/gui/globalsettingswindowclass.h index 5eea602f..3c255a14 100644 --- a/src/gui/globalsettingswindowclass.h +++ b/src/gui/globalsettingswindowclass.h @@ -4,7 +4,6 @@ #include class MainWindow; -class GlobalSettingsClass; class ANetworkModule; class AInterfaceToGStyleScript; @@ -110,10 +109,7 @@ private slots: private: Ui::GlobalSettingsWindowClass *ui; - MainWindow* MW; - GlobalSettingsClass* GlobSet; //just an alias, read from MW - }; #endif // GLOBALSETTINGSWINDOWCLASS_H diff --git a/src/gui/graphwindowclass.cpp b/src/gui/graphwindowclass.cpp index 2886f14a..8f0cf609 100644 --- a/src/gui/graphwindowclass.cpp +++ b/src/gui/graphwindowclass.cpp @@ -7,7 +7,7 @@ #include "mainwindow.h" #include "rasterwindowgraphclass.h" #include "windownavigatorclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "amessage.h" #include "afiletools.h" #include "shapeablerectitem.h" @@ -1419,7 +1419,7 @@ void GraphWindowClass::UpdateControls() void GraphWindowClass::DoSaveGraph(QString name) { - GraphWindowClass::SaveGraph(MW->GlobSet->LastOpenDir + "/" + name); + GraphWindowClass::SaveGraph(MW->GlobSet.LastOpenDir + "/" + name); } void GraphWindowClass::DrawStrOpt(TObject *obj, QString options, bool DoUpdate) @@ -2218,9 +2218,9 @@ void GraphWindowClass::ExportData(bool fUseBinCenters) QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("txt"); - QString fileName = fileDialog->getSaveFileName(this, "Export data to ascii file", MW->GlobSet->LastOpenDir+"/"+obj->GetName(), "Text files(*.txt)"); + QString fileName = fileDialog->getSaveFileName(this, "Export data to ascii file", MW->GlobSet.LastOpenDir+"/"+obj->GetName(), "Text files(*.txt)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); if (QFileInfo(fileName).suffix().isEmpty()) fileName += ".txt"; SaveDoubleVectorsToFile(fileName, &x, &y); } @@ -2247,9 +2247,9 @@ void GraphWindowClass::exportTextForTH2(TH2* h) QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("txt"); - QString fileName = fileDialog->getSaveFileName(this, "Export data to ascii file", MW->GlobSet->LastOpenDir+"/"+h->GetTitle(), "Text files(*.txt)"); + QString fileName = fileDialog->getSaveFileName(this, "Export data to ascii file", MW->GlobSet.LastOpenDir+"/"+h->GetTitle(), "Text files(*.txt)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); if (QFileInfo(fileName).suffix().isEmpty()) fileName += ".txt"; SaveDoubleVectorsToFile(fileName, &x, &y, &f); } @@ -2280,7 +2280,7 @@ void GraphWindowClass::on_actionSave_root_object_triggered() { QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("root"); - QString fileName = fileDialog->getSaveFileName(this, "Save TH1 histogram", MW->GlobSet->LastOpenDir, "Root files(*.root)"); + QString fileName = fileDialog->getSaveFileName(this, "Save TH1 histogram", MW->GlobSet.LastOpenDir, "Root files(*.root)"); if (fileName.isEmpty()) return; hist->SaveAs(fileName.toLatin1().data()); } @@ -2301,7 +2301,7 @@ void GraphWindowClass::on_actionSave_root_object_triggered() { QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("root"); - QString fileName = fileDialog->getSaveFileName(this, "Save TH2 histogram", MW->GlobSet->LastOpenDir, "Root files(*.root)"); + QString fileName = fileDialog->getSaveFileName(this, "Save TH2 histogram", MW->GlobSet.LastOpenDir, "Root files(*.root)"); if (fileName.isEmpty()) return; hist->SaveAs(fileName.toLatin1().data()); } @@ -2807,9 +2807,9 @@ void GraphWindowClass::on_lwBasket_customContextMenuRequested(const QPoint &pos) else if (selectedItem == appendTxt) { qDebug() << "Appending txt file as graph to basket"; - QString fileName = QFileDialog::getOpenFileName(this, "Append graph from ascii file to Basket", MW->GlobSet->LastOpenDir, "Data files (*.txt *.dat); All files (*.*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Append graph from ascii file to Basket", MW->GlobSet.LastOpenDir, "Data files (*.txt *.dat); All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QString name(QFileInfo(fileName).baseName()); QVector x, y; int res = LoadDoubleVectorsFromFile(fileName, &x, &y); @@ -2827,9 +2827,9 @@ void GraphWindowClass::on_lwBasket_customContextMenuRequested(const QPoint &pos) else if (selectedItem == appendTxtEr) { qDebug() << "Appending txt file as graph+errors to basket"; - QString fileName = QFileDialog::getOpenFileName(this, "Append graph from ascii file to Basket", MW->GlobSet->LastOpenDir, "Data files (*.txt *.dat); All files (*.*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Append graph from ascii file to Basket", MW->GlobSet.LastOpenDir, "Data files (*.txt *.dat); All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QString name(QFileInfo(fileName).baseName()); QVector x, y, err; int res = LoadDoubleVectorsFromFile(fileName, &x, &y, &err); @@ -3146,12 +3146,12 @@ void GraphWindowClass::on_actionSave_image_triggered() { QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("png"); - QString fileName = fileDialog->getSaveFileName(this, "Save image as file", MW->GlobSet->LastOpenDir, "png (*.png);;gif (*.gif);;Jpg (*.jpg)"); + QString fileName = fileDialog->getSaveFileName(this, "Save image as file", MW->GlobSet.LastOpenDir, "png (*.png);;gif (*.gif);;Jpg (*.jpg)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); GraphWindowClass::SaveGraph(fileName); - if (MW->GlobSet->fOpenImageExternalEditor) QDesktopServices::openUrl(QUrl("file:"+fileName, QUrl::TolerantMode)); + if (MW->GlobSet.fOpenImageExternalEditor) QDesktopServices::openUrl(QUrl("file:"+fileName, QUrl::TolerantMode)); } void GraphWindowClass::on_actionExport_data_as_text_triggered() @@ -3210,9 +3210,9 @@ void GraphWindowClass::SaveBasket() { qDebug() << "Saving basket"; - QString fileName = QFileDialog::getSaveFileName(this, "Save Basket objects to file", MW->GlobSet->LastOpenDir, "Root files (*.root)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save Basket objects to file", MW->GlobSet.LastOpenDir, "Root files (*.root)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); if(QFileInfo(fileName).suffix().isEmpty()) fileName += ".root"; QString str; @@ -3246,9 +3246,9 @@ void GraphWindowClass::SaveBasket() void GraphWindowClass::AppendBasket() { - QString fileName = QFileDialog::getOpenFileName(this, "Append objects from Basket file", MW->GlobSet->LastOpenDir, "Root files (*.root)"); + QString fileName = QFileDialog::getOpenFileName(this, "Append objects from Basket file", MW->GlobSet.LastOpenDir, "Root files (*.root)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); //if(QFileInfo(fileName).suffix().isEmpty()) fileName += ".root"; QByteArray ba = fileName.toLocal8Bit(); @@ -3358,9 +3358,9 @@ void GraphWindowClass::AppendBasket() void GraphWindowClass::AppendRootHistsOrGraphs() { - QString fileName = QFileDialog::getOpenFileName(this, "Append objects from ROOT file", MW->GlobSet->LastOpenDir, "Root files (*.root)"); + QString fileName = QFileDialog::getOpenFileName(this, "Append objects from ROOT file", MW->GlobSet.LastOpenDir, "Root files (*.root)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QByteArray ba = fileName.toLocal8Bit(); const char *c_str = ba.data(); diff --git a/src/gui/lrfwindow.cpp b/src/gui/lrfwindow.cpp index 1a72976b..00dfdb6a 100644 --- a/src/gui/lrfwindow.cpp +++ b/src/gui/lrfwindow.cpp @@ -9,7 +9,7 @@ #include "geometrywindowclass.h" #include "outputwindow.h" #include "eventsdataclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "ajsontools.h" #include "apositionenergyrecords.h" #include "windownavigatorclass.h" @@ -126,8 +126,8 @@ void LRFwindow::showLRF() json["Z"] = ui->ledZcenter->text().toDouble(); json["DZ"] = ui->ledZrange->text().toDouble(); json["EnergyScaling"] = ui->cbEnergyScalling->isChecked(); - json["FunctionPointsX"] = MW->GlobSet->FunctionPointsX; - json["FunctionPointsY"] = MW->GlobSet->FunctionPointsY; + json["FunctionPointsX"] = MW->GlobSet.FunctionPointsX; + json["FunctionPointsY"] = MW->GlobSet.FunctionPointsY; //json["Bins"] = ui->sbNumBins_2->value(); //json["ShowNodes"] = ui->cbShowNodePositions->isChecked(); @@ -269,9 +269,9 @@ void LRFwindow::SaveLRFDialog(QWidget* wid) QFileDialog *fileDialog = new QFileDialog; fileDialog->setDefaultSuffix("json"); - QString fileName = fileDialog->getSaveFileName(this, "Save LRF Block", MW->GlobSet->LastOpenDir, "json files(*.json);;all files(*.*)"); + QString fileName = fileDialog->getSaveFileName(this, "Save LRF Block", MW->GlobSet.LastOpenDir, "json files(*.json);;all files(*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); int iCur = SensLRF->getCurrentIterIndex(); if (iCur == -1) @@ -316,9 +316,9 @@ void LRFwindow::on_pbSaveIterations_clicked() return; } - QString fileName = QFileDialog::getSaveFileName(this, "Save all Iterations: provided name will be used to create a dir", MW->GlobSet->LastOpenDir, "json files(*.json);;all files(*.*)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save all Iterations: provided name will be used to create a dir", MW->GlobSet.LastOpenDir, "json files(*.json);;all files(*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo fi(fileName); QString dir = fi.baseName(); @@ -352,9 +352,9 @@ void LRFwindow::on_pbLoadLRFs_clicked() void LRFwindow::LoadLRFDialog(QWidget* wid) { - QStringList fileNames = QFileDialog::getOpenFileNames(this, "Load LRF Block", MW->GlobSet->LastOpenDir, "JSON files (*.json)"); + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Load LRF Block", MW->GlobSet.LastOpenDir, "JSON files (*.json)"); if (fileNames.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileNames.first()).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileNames.first()).absolutePath(); for (int ifile=0; ifileledZcenter->text().toDouble(); json["DZ"] = ui->ledZrange->text().toDouble(); json["EnergyScaling"] = ui->cbEnergyScalling->isChecked(); - json["FunctionPointsX"] = MW->GlobSet->FunctionPointsX; + json["FunctionPointsX"] = MW->GlobSet.FunctionPointsX; json["Bins"] = ui->sbNumBins_2->value(); json["ShowNodes"] = ui->cbShowNodePositions->isChecked(); @@ -838,7 +838,7 @@ void LRFwindow::on_pbAxial3DvsZ_clicked() double rr[3]; rr[0] = radius; rr[1] = 0; - int bins = MW->GlobSet->FunctionPointsX; + int bins = MW->GlobSet.FunctionPointsX; double stepZ = (z1-z0)/bins; for (int i=0; iGlobSet->FunctionPointsX; - int binsZ = MW->GlobSet->FunctionPointsY; + int binsR = MW->GlobSet.FunctionPointsX; + int binsZ = MW->GlobSet.FunctionPointsY; double stepR = (r1-r0)/binsR; double stepZ = (z1-z0)/binsZ; for (int ir=0; irsbPMnoButons->text(); - QString fileName = QFileDialog::getSaveFileName(this, "Save LRF # " +str+ " vs radius", MW->GlobSet->LastOpenDir, + QString fileName = QFileDialog::getSaveFileName(this, "Save LRF # " +str+ " vs radius", MW->GlobSet.LastOpenDir, "Text files (*.txt);;Data files (*.dat);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFile outputFile(fileName); outputFile.open(QIODevice::WriteOnly); @@ -1455,9 +1455,9 @@ void LRFwindow::on_pbTableToAxial_clicked() ui->cob2Dtype->setCurrentIndex(0); ui->cbMakePMGroup->setChecked(false); - QString fileName = QFileDialog::getOpenFileName(this, "LRF table file", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); + QString fileName = QFileDialog::getOpenFileName(this, "LRF table file", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - //MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + //MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo fi(fileName); QString ext = fi.suffix(); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 68f9ded1..6752e89e 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -28,7 +28,7 @@ #include "areconstructionmanager.h" #include "apmtype.h" #include "globalsettingswindowclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "aopticaloverride.h" #include "phscatclaudiomodel.h" #include "scatteronmetal.h" @@ -238,7 +238,7 @@ void MainWindow::closeEvent(QCloseEvent *event) qDebug() << "WriteConfig(); qDebug()<<"SaveANTSconfiguration(); + GlobSet.saveANTSconfiguration(); EventsDataHub->clear(); @@ -1405,13 +1405,13 @@ void MainWindow::on_pbLoadPDE_clicked() { QString fileName; if (ui->cobPMdeviceType->currentIndex() == 0) - fileName = QFileDialog::getOpenFileName(this, "Load quantum efficiency vs wavelength", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load quantum efficiency vs wavelength", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); else - fileName = QFileDialog::getOpenFileName(this, "Load photon detection efficiency vs wavelength", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load photon detection efficiency vs wavelength", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); //qDebug()<LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector x,y; LoadDoubleVectorsFromFile(fileName, &x, &y); @@ -1483,9 +1483,9 @@ void MainWindow::on_pbShowPDEbinned_clicked() void MainWindow::on_pbPMtypeLoadAngular_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load angular response (0 - 90 degrees)", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load angular response (0 - 90 degrees)", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector x,y; LoadDoubleVectorsFromFile(fileName, &x, &y); @@ -1581,9 +1581,9 @@ void MainWindow::on_ledMediumRefrIndex_editingFinished() void MainWindow::on_pbPMtypeLoadArea_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load area response", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load area response", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector< QVector > tmp; double xStep, yStep; @@ -2043,12 +2043,12 @@ void MainWindow::on_pbIndLoadDE_clicked() QString fileName; if (PMs->isSiPM(ipm)) - fileName = QFileDialog::getOpenFileName(this, "Load photon detection efficiency vs wavelength", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load photon detection efficiency vs wavelength", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); else - fileName = QFileDialog::getOpenFileName(this, "Load quantum efficiency vs wavelength", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load quantum efficiency vs wavelength", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector x,y; LoadDoubleVectorsFromFile(fileName, &x, &y); @@ -2102,9 +2102,9 @@ void MainWindow::on_pbAddPM_clicked() void MainWindow::on_pbIndLoadAngular_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load angular response (0 - 90 degrees)", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load angular response (0 - 90 degrees)", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector x,y; LoadDoubleVectorsFromFile(fileName, &x, &y); @@ -2202,9 +2202,9 @@ void MainWindow::on_ledIndMediumRefrIndex_editingFinished() void MainWindow::on_pbIndLoadArea_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load area response", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load area response", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); int ipm = ui->sbIndPMnumber->value(); QVector< QVector > tmp; @@ -2322,11 +2322,11 @@ void MainWindow::UpdatePreprocessingSettingsIndication() void MainWindow::LoadPMsignalsRequested() { - QStringList fileNames = QFileDialog::getOpenFileNames(this, "Load events from ascii file(s)", GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Load events from ascii file(s)", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); if (fileNames.isEmpty()) return; this->activateWindow(); this->raise(); - GlobSet->LastOpenDir = QFileInfo(fileNames.first()).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileNames.first()).absolutePath(); if (LoadedEventFiles.isEmpty()) MainWindow::ClearData(); // first load - make sure there is no data (e.g. sim events) else @@ -2510,10 +2510,10 @@ void MainWindow::DeleteLoadedEvents(bool KeepFileList) void MainWindow::on_pbPreprocessingLoad_clicked() { QString fileName = QFileDialog::getOpenFileName(this, - "Load preprocessing data (ignores first column with PM number)", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); + "Load preprocessing data (ignores first column with PM number)", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); MainWindow::LoadPreprocessingAddMulti(fileName); if (!EventsDataHub->Events.isEmpty()) ui->fReloadRequired->setVisible(true); @@ -2522,10 +2522,10 @@ void MainWindow::on_pbPreprocessingLoad_clicked() void MainWindow::on_pbPreprocessingSave_clicked() { QString fileName = QFileDialog::getSaveFileName(this, - "Save preprocessing data", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); + "Save preprocessing data", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); MainWindow::SavePreprocessingAddMulti(fileName); } @@ -2569,9 +2569,9 @@ void MainWindow::on_pbElGainLoadDistr_clicked() { int ipm = ui->sbElPMnumber->value(); QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load Single Photoelectron Pulse Height Spectrum", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load Single Photoelectron Pulse Height Spectrum", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector x, y; bool error = MainWindow::LoadSPePHSfile(fileName, &x, &y); @@ -2801,9 +2801,9 @@ void MainWindow::on_cbEnableADC_toggled(bool checked) void MainWindow::on_pbScanDistrLoad_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load custom distribution", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load custom distribution", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); MainWindow::LoadScanPhotonDistribution(fileName); MainWindow::on_pbUpdateSimConfig_clicked(); @@ -2856,9 +2856,9 @@ void MainWindow::on_pbSecScintShowProfile_clicked() void MainWindow::on_pbSecScintLoadProfile_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load custom distribution", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load custom distribution", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); MainWindow::LoadSecScintTheta(fileName); } @@ -2924,9 +2924,9 @@ void MainWindow::on_pbConfigureAddOns_clicked() void MainWindow::LoadSimTreeRequested() { - QStringList fileNames = QFileDialog::getOpenFileNames(this, "Load/Append simulation data from Root tree", GlobSet->LastOpenDir, "Root files (*.root)"); + QStringList fileNames = QFileDialog::getOpenFileNames(this, "Load/Append simulation data from Root tree", GlobSet.LastOpenDir, "Root files (*.root)"); if (fileNames.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileNames.first()).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileNames.first()).absolutePath(); if (LoadedTreeFiles.isEmpty()) MainWindow::ClearData(); //clear ascii loaded data or sim if present else @@ -3280,11 +3280,11 @@ void MainWindow::CalculateIndividualQEPDE() void MainWindow::on_pbLoadRelQEfactors_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load relative QE / PDE factors", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load relative QE / PDE factors", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); qDebug()<LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); Detector->PMs->setDoPHS( true ); @@ -3305,11 +3305,11 @@ void MainWindow::on_pbLoadRelQEfactors_clicked() void MainWindow::on_pbLoadRelELfactors_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load relative strength of electronic channels", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load relative strength of electronic channels", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); qDebug()<LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); Detector->PMs->setDoPHS( true ); @@ -3427,9 +3427,9 @@ void MainWindow::SaveSimulationDataTree() message("No data to save!", this); return; } - QString fileName = QFileDialog::getSaveFileName(this, "Save simulation data as Root Tree", GlobSet->LastOpenDir, "Root files (*.root)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save simulation data as Root Tree", GlobSet.LastOpenDir, "Root files (*.root)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); if(QFileInfo(fileName).suffix().isEmpty()) fileName += ".root"; bool ok = EventsDataHub->saveSimulationAsTree(fileName); @@ -3443,12 +3443,12 @@ void MainWindow::SaveSimulationDataAsText() message("No data to save!", this); return; } - QString fileName = QFileDialog::getSaveFileName(this, "Save simulation data as text file", GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save simulation data as text file", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); if(QFileInfo(fileName).suffix().isEmpty()) fileName += ".dat"; - bool ok = EventsDataHub->saveSimulationAsText(fileName, GlobSet->SimTextSave_IncludeNumPhotons, GlobSet->SimTextSave_IncludePositions); + bool ok = EventsDataHub->saveSimulationAsText(fileName, GlobSet.SimTextSave_IncludeNumPhotons, GlobSet.SimTextSave_IncludePositions); if (!ok) message("Error writing to file!", this); } @@ -3775,7 +3775,7 @@ void MainWindow::startSimulation(QJsonObject &json) { WindowNavigator->BusyOn(); //go busy mode, most of gui controls disabled ui->pbStopScan->setEnabled(true); - SimulationManager->StartSimulation(json, GlobSet->NumThreads, true); + SimulationManager->StartSimulation(json, GlobSet.NumThreads, true); } void MainWindow::simulationFinished() @@ -3834,7 +3834,7 @@ void MainWindow::simulationFinished() SimulationManager->Tracks.clear(); //to avoid delete content int numTracks = 0; - for (int iTr=0; iTrTrackInfo.size() /* && numTracksMaxNumberOfTracks */; iTr++) + for (int iTr=0; iTrTrackInfo.size() /* && numTracksTrackInfo.at(iTr); TGeoTrack* track = new TGeoTrack(1, th->UserIndex); @@ -3931,7 +3931,7 @@ void MainWindow::on_pbTrackStack_clicked() { const TrackHolderClass* th = pss->tracks[iTr]; - //if (numTracksMaxNumberOfTracks) + //if (numTracksUserIndex); track->SetLineColor(th->Color); @@ -4026,7 +4026,7 @@ void MainWindow::on_pbGDML_clicked() void MainWindow::on_pbSavePMtype_clicked() { - QString starter = (GlobSet->LibPMtypes.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibPMtypes; + QString starter = (GlobSet.LibPMtypes.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibPMtypes; starter += "/PMtype_"+ui->lePMtypeName->text(); QFileDialog fileDialog; @@ -4049,7 +4049,7 @@ void MainWindow::on_pbSavePMtype_clicked() void MainWindow::on_pbLoadPMtype_clicked() { - QString starter = (GlobSet->LibPMtypes.isEmpty()) ? GlobSet->LastOpenDir : GlobSet->LibPMtypes; + QString starter = (GlobSet.LibPMtypes.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibPMtypes; QFileDialog fileDialog; QString fileName = fileDialog.getOpenFileName(this, "Load PM type properties", starter, "Json files (*.json);; All files (*.*)"); if (fileName.isEmpty()) return; @@ -4094,9 +4094,9 @@ void MainWindow::on_pbLoadPMtype_clicked() void MainWindow::on_pbLoadNodes_clicked() { QFileDialog fileDialog; - QString fileName = fileDialog.getOpenFileName(this, "Load custom nodes", GlobSet->LastOpenDir, "Text files (*.txt);; All files (*.*)"); + QString fileName = fileDialog.getOpenFileName(this, "Load custom nodes", GlobSet.LastOpenDir, "Text files (*.txt);; All files (*.*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector x, y, z; int err = LoadDoubleVectorsFromFile(fileName, &x, &y, &z); @@ -4127,7 +4127,7 @@ void MainWindow::on_pbRunNodeScript_clicked() delete GenScriptWindow; GenScriptWindow = 0; AJavaScriptManager* jsm = new AJavaScriptManager(Detector->RandGen); - GenScriptWindow = new AScriptWindow(jsm, GlobSet, true, this); + GenScriptWindow = new AScriptWindow(jsm, true, this); GenScriptWindow->ConfigureForLightMode(&NodesScript, "Custom nodes", "clear();\nfor (var i=0; i<5; i++)\n node(i*10, (i-2)*20, 0)\n\nnode(40, -20, 0)"); NodesScriptInterface = new InterfaceToNodesScript(CustomScanNodes); @@ -4158,7 +4158,7 @@ void MainWindow::on_actionOpen_settings_triggered() void MainWindow::on_actionSave_Load_windows_status_on_Exit_Init_toggled(bool arg1) { - GlobSet->SaveLoadWindows = arg1; + GlobSet.SaveLoadWindows = arg1; } void MainWindow::on_pbUpdateElectronics_clicked() @@ -4199,9 +4199,9 @@ void MainWindow::on_pbOverlay_clicked() return; } - QString fileName = QFileDialog::getOpenFileName(this, "Overlay simulation data with data from an ASCII file", GlobSet->LastOpenDir, "All file (*.*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Overlay simulation data with data from an ASCII file", GlobSet.LastOpenDir, "All file (*.*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); WindowNavigator->BusyOn(); bool ok = EventsDataHub->overlayAsciiFile(fileName, ui->cbApplyAddMultiplyPreprocess->isChecked(), Detector->PMs); @@ -4215,11 +4215,11 @@ void MainWindow::on_pbOverlay_clicked() void MainWindow::on_pbLoadManifestFile_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load manifest file", GlobSet->LastOpenDir, "Text files (*.txt);;All files (*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load manifest file", GlobSet.LastOpenDir, "Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; //this->activateWindow(); //this->raise(); - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); ui->leManifestFile->setText(fileName); ui->cbLoadedDataHasPosition->setChecked(false); @@ -4550,7 +4550,7 @@ void MainWindow::on_pbShowMCcrosstalk_clicked() PMs->prepareMCcrosstalk(); int ipm = ui->sbElPMnumber->value(); - TH1I* hist = new TH1I("aa", "Test custom sampling", GlobSet->BinsX, 0, 0); + TH1I* hist = new TH1I("aa", "Test custom sampling", GlobSet.BinsX, 0, 0); for (int i=0; i<1000000; i++) hist->Fill(PMs->at(ipm).MCsampl->sample(Detector->RandGen)+1); @@ -4561,9 +4561,9 @@ void MainWindow::on_pbLoadMCcrosstalk_clicked() { int ipm = ui->sbElPMnumber->value(); QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load MC cross-talk distribution\nFile should contain a single column of values, starting with the probability for single event.\nData may be not normalized.", GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Load MC cross-talk distribution\nFile should contain a single column of values, starting with the probability for single event.\nData may be not normalized.", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector v; bool error = LoadDoubleVectorsFromFile(fileName, &v); @@ -4725,9 +4725,9 @@ void MainWindow::on_pbDarkCounts_Load_clicked() return; } - const QString fileName = QFileDialog::getOpenFileName(this, QString("Load generation distribution for PM #").arg(ipm), GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + const QString fileName = QFileDialog::getOpenFileName(this, QString("Load generation distribution for PM #").arg(ipm), GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); if (fileName.isEmpty()) return; - GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector x; int res = LoadDoubleVectorsFromFile(fileName, &x); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index e4b1349b..1b576572 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -10,6 +10,7 @@ // forward declarations class AConfiguration; +class AGlobalSettings; struct AEnergyDepositionCell; class GeoMarkerClass; class AParticleOnStack; @@ -35,7 +36,6 @@ class TH1I; class ParticleSourcesClass; class WindowNavigatorClass; class GeometryWindowAddOn; -class GlobalSettingsClass; class GlobalSettingsWindowClass; class GainEvaluatorWindowClass; class TApplication; @@ -78,8 +78,7 @@ class MainWindow : public QMainWindow ASimulationManager *SimulationManager, AReconstructionManager *ReconstructionManager, ANetworkModule *Net, - TmpObjHubClass *TmpHub, - GlobalSettingsClass *GlobSet); + TmpObjHubClass *TmpHub); ~MainWindow(); // Pointers to external resources @@ -94,7 +93,7 @@ class MainWindow : public QMainWindow AReconstructionManager *ReconstructionManager = 0; ANetworkModule* NetModule = 0; TmpObjHubClass *TmpHub = 0; - GlobalSettingsClass* GlobSet = 0; + AGlobalSettings& GlobSet; // ANTS2 windows GraphWindowClass *GraphWindow = 0; diff --git a/src/gui/materialinspectorwindow.cpp b/src/gui/materialinspectorwindow.cpp index 3e257af6..296d1d58 100644 --- a/src/gui/materialinspectorwindow.cpp +++ b/src/gui/materialinspectorwindow.cpp @@ -7,7 +7,7 @@ #include "windownavigatorclass.h" #include "outputwindow.h" #include "detectorclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "ajsontools.h" #include "afiletools.h" #include "amessage.h" @@ -95,7 +95,7 @@ MaterialInspectorWindow::MaterialInspectorWindow(QWidget* parent, MainWindow *mw "Import the file by clicking \"Import from XCOM\" button."; ui->pbImportXCOM->setToolTip(str); - OptionsConfigurator = new AMatParticleConfigurator(MW->GlobSet, this); + OptionsConfigurator = new AMatParticleConfigurator(this); QPixmap pm(QSize(16,16)); @@ -534,10 +534,10 @@ void MaterialInspectorWindow::on_pbUpdateTmpMaterial_clicked() void MaterialInspectorWindow::on_pbLoadDeDr_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load dE/dr data", MW->GlobSet->LastOpenDir, "Data files (*.dat)"); + fileName = QFileDialog::getOpenFileName(this, "Load dE/dr data", MW->GlobSet.LastOpenDir, "Data files (*.dat)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; @@ -607,10 +607,10 @@ void MaterialInspectorWindow::on_pbLoadThisScenarioCrossSection_clicked() { QString fileName; fileName = QFileDialog::getOpenFileName(this, "Load mass interaction coefficient data.\n" - "The file should contain 4 colums: energy[keV], photoelectric_data[cm2/g], compton_data[cm2/g], pair_production_data[cm2/g]", MW->GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files(*)"); + "The file should contain 4 colums: energy[keV], photoelectric_data[cm2/g], compton_data[cm2/g], pair_production_data[cm2/g]", MW->GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files(*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; int particleId = ui->cobParticle->currentIndex(); @@ -665,10 +665,10 @@ void MaterialInspectorWindow::on_ledIntEnergyRes_editingFinished() void MaterialInspectorWindow::on_pbImportStoppingPowerFromTrim_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Import stopping power data from a Trim file", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Import stopping power data from a Trim file", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); //qDebug()<GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); int particleId = ui->cobParticle->currentIndex(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; @@ -846,9 +846,9 @@ void MaterialInspectorWindow::on_pbImportStoppingPowerFromTrim_clicked() void MaterialInspectorWindow::on_pbImportXCOM_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Import partial interaction coefficients from an XCOM file", MW->GlobSet->LastOpenDir, "Text and data files (*.dat *.txt);;All files (*)"); + fileName = QFileDialog::getOpenFileName(this, "Import partial interaction coefficients from an XCOM file", MW->GlobSet.LastOpenDir, "Text and data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFile file(fileName); if(!file.open(QIODevice::ReadOnly | QFile::Text)) @@ -1054,10 +1054,10 @@ void MaterialInspectorWindow::AddMatToCobs(QString str) void MaterialInspectorWindow::on_pbLoadPrimSpectrum_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load primary scintillation spectrum", MW->GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); + fileName = QFileDialog::getOpenFileName(this, "Load primary scintillation spectrum", MW->GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; LoadDoubleVectorsFromFile(fileName, &tmpMaterial.PrimarySpectrum_lambda, &tmpMaterial.PrimarySpectrum); //cleans previous data @@ -1132,10 +1132,10 @@ void MaterialInspectorWindow::ConvertToStandardWavelengthes(QVector* sp_ void MaterialInspectorWindow::on_pbLoadSecSpectrum_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load secondary scintillation spectrum", MW->GlobSet->LastOpenDir, "Data files (*.dat);;All files (*.*)"); + fileName = QFileDialog::getOpenFileName(this, "Load secondary scintillation spectrum", MW->GlobSet.LastOpenDir, "Data files (*.dat);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; LoadDoubleVectorsFromFile(fileName, &tmpMaterial.SecondarySpectrum_lambda, &tmpMaterial.SecondarySpectrum); //cleans previous data @@ -1179,10 +1179,10 @@ void MaterialInspectorWindow::on_pbDeleteSecSpectrum_clicked() void MaterialInspectorWindow::on_pbLoadNlambda_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load refractive index data", MW->GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); + fileName = QFileDialog::getOpenFileName(this, "Load refractive index data", MW->GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; LoadDoubleVectorsFromFile(fileName, &tmpMaterial.nWave_lambda, &tmpMaterial.nWave); //cleans previous data too @@ -1226,10 +1226,10 @@ void MaterialInspectorWindow::on_pbDeleteNlambda_clicked() void MaterialInspectorWindow::on_pbLoadABSlambda_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load exponential bulk absorption data", MW->GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); + fileName = QFileDialog::getOpenFileName(this, "Load exponential bulk absorption data", MW->GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; LoadDoubleVectorsFromFile(fileName, &tmpMaterial.absWave_lambda, &tmpMaterial.absWave); //cleans previous data too @@ -1278,10 +1278,10 @@ void MaterialInspectorWindow::on_pbShowReemProbLambda_clicked() void MaterialInspectorWindow::on_pbLoadReemisProbLambda_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load reemission probability vs wavelength", MW->GlobSet->LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); + fileName = QFileDialog::getOpenFileName(this, "Load reemission probability vs wavelength", MW->GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); AMaterial& tmpMaterial = MW->MpCollection->tmpMaterial; LoadDoubleVectorsFromFile(fileName, &tmpMaterial.reemisProbWave_lambda, &tmpMaterial.reemisProbWave); //cleans previous data too @@ -1705,7 +1705,7 @@ void MaterialInspectorWindow::on_actionSave_material_triggered() return; } - QString starter = (MW->GlobSet->LibMaterials.isEmpty()) ? MW->GlobSet->LastOpenDir : MW->GlobSet->LibMaterials; + QString starter = (MW->GlobSet.LibMaterials.isEmpty()) ? MW->GlobSet.LastOpenDir : MW->GlobSet.LibMaterials; int imat = ui->cobActiveMaterials->currentIndex(); if (imat == -1) starter += "/Material_"; else starter += "/Material_"+(*Detector->MpCollection)[imat]->name; @@ -1723,7 +1723,7 @@ void MaterialInspectorWindow::on_actionSave_material_triggered() void MaterialInspectorWindow::on_actionLoad_material_triggered() { - QString starter = (MW->GlobSet->LibMaterials.isEmpty()) ? MW->GlobSet->LastOpenDir : MW->GlobSet->LibMaterials; + QString starter = (MW->GlobSet.LibMaterials.isEmpty()) ? MW->GlobSet.LastOpenDir : MW->GlobSet.LibMaterials; QString fileName = QFileDialog::getOpenFileName(this, "Load material", starter, "Material files (*mat *.json);;All files (*.*)"); if (fileName.isEmpty()) return; @@ -2163,7 +2163,7 @@ bool MaterialInspectorWindow::autoLoadCrossSection(ANeutronInteractionElement *e int MaterialInspectorWindow::autoLoadReaction(ANeutronInteractionElement& element) { - QString fileName = QString("%1/Neutrons/Reactions/%2-%3.json").arg(MW->GlobSet->ResourcesDir).arg(element.Name).arg(element.Mass); + QString fileName = QString("%1/Neutrons/Reactions/%2-%3.json").arg(MW->GlobSet.ResourcesDir).arg(element.Name).arg(element.Mass); // qDebug() << "Is there file for reaction? "<GlobSet->MaterialsAndParticlesSettings.isEmpty()) + if (MW->GlobSet.MaterialsAndParticlesSettings.isEmpty()) on_actionNeutrons_triggered(); // qDebug() << "Element#"<GlobSet->LastOpenDir, "Data files (*.txt *.dat); All files (*.*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load " + target + " cross-section data for " + isotope, MW->GlobSet.LastOpenDir, "Data files (*.txt *.dat); All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); doLoadCrossSection(element, fileName); FillNeutronTable(); @@ -2937,7 +2937,7 @@ void MaterialInspectorWindow::on_pbPriT_test_clicked() void MaterialInspectorWindow::on_actionNeutrons_triggered() { - OptionsConfigurator->setStarterDir(MW->GlobSet->LastOpenDir); + OptionsConfigurator->setStarterDir(MW->GlobSet.LastOpenDir); OptionsConfigurator->showNormal(); } @@ -2958,7 +2958,7 @@ void MaterialInspectorWindow::on_pbShowNcmat_clicked() void MaterialInspectorWindow::on_pbLoadNcmat_clicked() { QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load NCrystal ncmat file", MW->GlobSet->LastOpenDir, "Ncmat files (*.ncmat)"); + fileName = QFileDialog::getOpenFileName(this, "Load NCrystal ncmat file", MW->GlobSet.LastOpenDir, "Ncmat files (*.ncmat)"); if (fileName.isEmpty()) return; #ifdef __USE_ANTS_NCRYSTAL__ diff --git a/src/gui/outputwindow.cpp b/src/gui/outputwindow.cpp index 797cb7a8..deccbd30 100644 --- a/src/gui/outputwindow.cpp +++ b/src/gui/outputwindow.cpp @@ -11,7 +11,7 @@ #include "eventsdataclass.h" #include "detectorclass.h" #include "dynamicpassiveshandler.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "apositionenergyrecords.h" #include "amessage.h" #include "apmgroupsmanager.h" @@ -327,13 +327,13 @@ void OutputWindow::showParticleHistString(int iRec, int level) if (m != 0) s += " ->"; int MatId = h->Deposition[m].MaterialId; s += " " + (*MW->MpCollection)[MatId]->name +"_"; - s += QString::number(h->Deposition[m].Distance, 'g', MW->GlobSet->TextLogPrecision)+"_mm"; + s += QString::number(h->Deposition[m].Distance, 'g', MW->GlobSet.TextLogPrecision)+"_mm"; double depo = h->Deposition[m].DepositedEnergy; if (depo>0) { s += "_"; s += ""; - s += QString::number(depo, 'g', MW->GlobSet->TextLogPrecision); + s += QString::number(depo, 'g', MW->GlobSet.TextLogPrecision); s += ""; s += "_keV"; TotalEnergyDeposited += depo; @@ -396,7 +396,7 @@ void OutputWindow::ShowEventHistoryLog() addParticleHistoryLogLine(i, 0); } s = "---------------------\n"; - s += "Total energy deposited: " + QString::number(TotalEnergyDeposited, 'g', MW->GlobSet->TextLogPrecision) + " keV\n"; + s += "Total energy deposited: " + QString::number(TotalEnergyDeposited, 'g', MW->GlobSet.TextLogPrecision) + " keV\n"; s += "=====================\n"; //SetTab(0); ui->pteOut->appendPlainText(s); @@ -913,7 +913,7 @@ void OutputWindow::ShowOneEventLog(int iev) if (!isVisible()) show(); raise(); - int precision = MW->GlobSet->TextLogPrecision; + int precision = MW->GlobSet.TextLogPrecision; QString str = "Event# " + QString::number(iev); if (!EventsDataHub->isScanEmpty()) @@ -1001,7 +1001,7 @@ void OutputWindow::on_pbShowSumSignals_clicked() } bool fGood = ui->cbOnlyGood->isChecked(); - auto hist1D = new TH1F("SumSig","Distribution of sum signal", MW->GlobSet->BinsX, 0,0); + auto hist1D = new TH1F("SumSig","Distribution of sum signal", MW->GlobSet.BinsX, 0,0); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) hist1D->SetBit(TH1::kCanRebin); #endif @@ -1047,7 +1047,7 @@ void OutputWindow::on_pbShowSignals_clicked() TString title = "Distribution of signal for PM# "; title += ipm; - auto hist1D = new TH1F("Sig", title, MW->GlobSet->BinsX, 0,0); + auto hist1D = new TH1F("Sig", title, MW->GlobSet.BinsX, 0,0); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) hist1D->SetBit(TH1::kCanRebin); #endif @@ -1080,7 +1080,7 @@ void OutputWindow::on_pbAverageSignals_clicked() } bool fGood = ui->cbOnlyGood->isChecked(); - auto hist1D = new TH1F("MaxSigDist","Distribution of max signal", MW->GlobSet->BinsX, 0,0); + auto hist1D = new TH1F("MaxSigDist","Distribution of max signal", MW->GlobSet.BinsX, 0,0); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) hist1D->SetBit(TH1::kCanRebin); #endif diff --git a/src/gui/reconstructionwindow.cpp b/src/gui/reconstructionwindow.cpp index 2b963d45..7e4df834 100644 --- a/src/gui/reconstructionwindow.cpp +++ b/src/gui/reconstructionwindow.cpp @@ -21,7 +21,7 @@ #include "eventsdataclass.h" #include "dynamicpassiveshandler.h" #include "areconstructionmanager.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "arootlineconfigurator.h" #include "ageomarkerclass.h" #include "apositionenergyrecords.h" @@ -209,7 +209,7 @@ void ReconstructionWindow::UpdateStatusAllEvents() if (EventsDataHub->isEmpty()) return; - ReconstructionManager->filterEvents(MW->Config->JSON, MW->GlobSet->NumThreads); + ReconstructionManager->filterEvents(MW->Config->JSON, MW->GlobSet.NumThreads); // qDebug() << " Found good events:"<countGoodEvents(); //qDebug() << "Update done"; } @@ -648,10 +648,10 @@ void ReconstructionWindow::on_pbCutOffsLoad_clicked() { QString fileName = QFileDialog::getOpenFileName(this, "Load individual cut-offs (ignores first column with PM number)", - MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); + MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); LoadIndividualCutOffs(fileName); UpdateStatusAllEvents(); @@ -679,10 +679,10 @@ void ReconstructionWindow::LoadIndividualCutOffs(QString fileName) void ReconstructionWindow::on_pbCutOffsSave_clicked() { QString fileName = QFileDialog::getSaveFileName(this, - "Save individual cut-offs", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); + "Save individual cut-offs", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); ReconstructionWindow::SaveIndividualCutOffs(fileName); } @@ -725,7 +725,7 @@ void ReconstructionWindow::on_pbShowSumSignal_clicked() int totNumEvents = EventsDataHub->Events.size(); if ( totNumEvents == 0) return; - auto hist1D = new TH1D("haSumSign","Sum signal",MW->GlobSet->BinsX, 0,0); + auto hist1D = new TH1D("haSumSign","Sum signal",MW->GlobSet.BinsX, 0,0); hist1D->SetXTitle("Sum signal"); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) @@ -806,12 +806,12 @@ void ReconstructionWindow::ShowIndividualSpectrum(bool focus) max = PMgroups->getCutOffMax(thisipm, CurrentGroup); if ( min==-1.0e10 || max==1.0e10) - hist1D = new TH1D("haIndSpect", name, MW->GlobSet->BinsX, 0,0); + hist1D = new TH1D("haIndSpect", name, MW->GlobSet.BinsX, 0,0); else - hist1D = new TH1D("haIndSpect", name, MW->GlobSet->BinsX, min,max); + hist1D = new TH1D("haIndSpect", name, MW->GlobSet.BinsX, min,max); } else - hist1D = new TH1D("haIndSpect", name, MW->GlobSet->BinsX, 0,0); + hist1D = new TH1D("haIndSpect", name, MW->GlobSet.BinsX, 0,0); hist1D->SetXTitle("Signal"); @@ -1198,7 +1198,7 @@ void ReconstructionWindow::ShowEnergySpectrum() return; } - auto hist1D = new TH1D("hist1ShEnSp","Energy spectrum", MW->GlobSet->BinsX, 0, 0); + auto hist1D = new TH1D("hist1ShEnSp","Energy spectrum", MW->GlobSet.BinsX, 0, 0); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) hist1D->SetBit(TH1::kCanRebin); @@ -1254,7 +1254,7 @@ void ReconstructionWindow::ShowChi2Spectrum() return; } - auto hist1D = new TH1D("hist1Chi2Dis","Chi2 distribution", MW->GlobSet->BinsX, 0, 0); + auto hist1D = new TH1D("hist1Chi2Dis","Chi2 distribution", MW->GlobSet.BinsX, 0, 0); hist1D->SetXTitle("Chi2"); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) hist1D->SetBit(TH1::kCanRebin); @@ -2292,9 +2292,9 @@ void ReconstructionWindow::on_pbFindNextPMinGains_clicked() void ReconstructionWindow::on_pbSaveGains_clicked() { - QString fileName = QFileDialog::getSaveFileName(this, "Save gains", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save gains", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo file(fileName); if(file.suffix().isEmpty()) fileName += ".dat"; QFile outputFile(fileName); @@ -2318,10 +2318,10 @@ void ReconstructionWindow::on_pbSaveGains_clicked() void ReconstructionWindow::on_pbLoadGains_clicked() { - QString fileName = QFileDialog::getOpenFileName(this, "Load gains", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); + QString fileName = QFileDialog::getOpenFileName(this, "Load gains", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*.*)"); // qDebug()<GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector num, gain; LoadDoubleVectorsFromFile(fileName, &num, &gain); //cleans previous data @@ -3377,7 +3377,7 @@ void ReconstructionWindow::on_pbLoadEnergySpectrum_clicked() return; } - auto hist1D = new TH1D("hist1ShLoEnSp","True/loaded energy", MW->GlobSet->BinsX, 0, 0); + auto hist1D = new TH1D("hist1ShLoEnSp","True/loaded energy", MW->GlobSet.BinsX, 0, 0); hist1D->SetXTitle("True or loaded energy"); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) hist1D->SetBit(TH1::kCanRebin); @@ -4553,9 +4553,9 @@ void ReconstructionWindow::on_pbExportData_clicked() if (EventsDataHub->Events.isEmpty()) return; if (EventsDataHub->isReconstructionDataEmpty()) return; - QString fileName = QFileDialog::getSaveFileName(this, "Export data", MW->GlobSet->LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); + QString fileName = QFileDialog::getSaveFileName(this, "Export data", MW->GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFile outFile( fileName ); outFile.open(QIODevice::WriteOnly); @@ -5697,7 +5697,7 @@ void ReconstructionWindow::ReconstructAll(bool fShow) ui->pbStopReconstruction->setEnabled(true); qApp->processEvents(); - MW->ReconstructionManager->reconstructAll(MW->Config->JSON, MW->GlobSet->NumThreads, fShow); + MW->ReconstructionManager->reconstructAll(MW->Config->JSON, MW->GlobSet.NumThreads, fShow); //will generate signal when finished and trigger onReconstructionFinished(bool fSuccess) } diff --git a/src/gui/windownavigatorclass.cpp b/src/gui/windownavigatorclass.cpp index 5af65658..4b49d70d 100644 --- a/src/gui/windownavigatorclass.cpp +++ b/src/gui/windownavigatorclass.cpp @@ -10,7 +10,7 @@ #include "geometrywindowclass.h" #include "exampleswindow.h" #include "gainevaluatorwindowclass.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "ascriptwindow.h" #include "detectoraddonswindow.h" @@ -76,10 +76,10 @@ void WindowNavigatorClass::SetupWindowsTaskbar() QWinJumpList* jumplist = new QWinJumpList(this); //QString configDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)+"/ants2"; - jumplist->tasks()->addLink(QString("Base dir"), QDir::toNativeSeparators(MW->GlobSet->AntsBaseDir)); - jumplist->tasks()->addLink(QString("Last working dir"), QDir::toNativeSeparators(MW->GlobSet->LastOpenDir)); - if (!MW->GlobSet->LibScripts.isEmpty()) - jumplist->tasks()->addLink(QString("Script dir"), QDir::toNativeSeparators(MW->GlobSet->LibScripts)); + jumplist->tasks()->addLink(QString("Base dir"), QDir::toNativeSeparators(MW->GlobSet.AntsBaseDir)); + jumplist->tasks()->addLink(QString("Last working dir"), QDir::toNativeSeparators(MW->GlobSet.LastOpenDir)); + if (!MW->GlobSet.LibScripts.isEmpty()) + jumplist->tasks()->addLink(QString("Script dir"), QDir::toNativeSeparators(MW->GlobSet.LibScripts)); //jumplist->tasks()->addSeparator(); jumplist->tasks()->setVisible(true); diff --git a/src/main.cpp b/src/main.cpp index e2c815a0..6c0596bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,7 @@ #include "histgraphinterfaces.h" #include "ainterfacetottree.h" #include "scriptminimizer.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "afiletools.h" #include "aqtmessageredirector.h" #include "particlesourcesclass.h" @@ -139,7 +139,8 @@ int main(int argc, char *argv[]) QObject::connect(&ReconstructionManager, &AReconstructionManager::UpdateReady, &Network, &ANetworkModule::ProgressReport ); qDebug() << "Network module created"; - GlobalSettingsClass GlobSet(&Network); + AGlobalSettings& GlobSet = AGlobalSettings::getInstance(); + GlobSet.setNetworkModule(&Network); if (GlobSet.NumThreads == -1) GlobSet.NumThreads = GlobSet.RecNumTreads; qDebug() << "Global settings object created"; @@ -153,7 +154,7 @@ int main(int argc, char *argv[]) { //GUI application qDebug() << "Creating MainWindow"; - MainWindow w(&Detector, &EventsDataHub, &RootApp, &SimulationManager, &ReconstructionManager, &Network, &TmpHub, &GlobSet); //Network - still need to set script manager! + MainWindow w(&Detector, &EventsDataHub, &RootApp, &SimulationManager, &ReconstructionManager, &Network, &TmpHub); //Network - still need to set script manager! qDebug() << "Showing MainWindow"; w.show(); @@ -266,7 +267,7 @@ int main(int argc, char *argv[]) SM.SetInterfaceObject(tree, "tree"); AInterfaceToPhotonScript* photon = new AInterfaceToPhotonScript(&Config, &EventsDataHub); SM.SetInterfaceObject(photon, "photon"); - AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(&Detector, &GlobSet, &EventsDataHub); + AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(&Detector, &EventsDataHub); SM.SetInterfaceObject(depo, "depo"); AInterfaceToMultiThread* threads = new AInterfaceToMultiThread(&SM); SM.SetInterfaceObject(threads, "threads"); diff --git a/src/modules/lrf_v3/gui/alrfwindow.cpp b/src/modules/lrf_v3/gui/alrfwindow.cpp index ecdfa162..8d9c0f62 100644 --- a/src/modules/lrf_v3/gui/alrfwindow.cpp +++ b/src/modules/lrf_v3/gui/alrfwindow.cpp @@ -21,7 +21,7 @@ #include "geometrywindowclass.h" #include "apmgroupsmanager.h" #include "ajsontools.h" -#include "globalsettingsclass.h" +#include "aglobalsettings.h" #include "graphwindowclass.h" #include "windownavigatorclass.h" #include "aconfiguration.h" @@ -535,9 +535,9 @@ void ALrfWindow::onRecipeContextMenuActionCopyToEditor() void ALrfWindow::onRecipeContextMenuActionSave() { - QString file_name = QFileDialog::getSaveFileName(this, "Save recipe", mw->GlobSet->LastOpenDir, "json files(*.json);;all files(*)"); + QString file_name = QFileDialog::getSaveFileName(this, "Save recipe", mw->GlobSet.LastOpenDir, "json files(*.json);;all files(*)"); if (file_name.isEmpty()) return; - mw->GlobSet->LastOpenDir = QFileInfo(file_name).dir().absolutePath(); + mw->GlobSet.LastOpenDir = QFileInfo(file_name).dir().absolutePath(); QJsonDocument doc(repo->toJson(tw_recipes->getSelectedRecipeId())); QFile save_file(file_name); @@ -588,9 +588,9 @@ void ALrfWindow::onVersionContextMenuActionSetAsSecondary() void ALrfWindow::onVersionContextMenuActionSave() { - QString file_name = QFileDialog::getSaveFileName(this, "Save version", mw->GlobSet->LastOpenDir, "json files(*.json);;all files(*)"); + QString file_name = QFileDialog::getSaveFileName(this, "Save version", mw->GlobSet.LastOpenDir, "json files(*.json);;all files(*)"); if (file_name.isEmpty()) return; - mw->GlobSet->LastOpenDir = QFileInfo(file_name).dir().absolutePath(); + mw->GlobSet.LastOpenDir = QFileInfo(file_name).dir().absolutePath(); QJsonDocument doc(repo->toJson(tw_recipes->getSelectedRecipeId(), tw_recipes->getSelectedVersionId())); QFile save_file(file_name); @@ -723,9 +723,9 @@ void ALrfWindow::on_pbSTOP_clicked() void ALrfWindow::on_pb_save_repository_clicked() { - QString file_name = QFileDialog::getSaveFileName(this, "Save repository", mw->GlobSet->LastOpenDir, "json files(*.json);;all files(*)"); + QString file_name = QFileDialog::getSaveFileName(this, "Save repository", mw->GlobSet.LastOpenDir, "json files(*.json);;all files(*)"); if (file_name.isEmpty()) return; - mw->GlobSet->LastOpenDir = QFileInfo(file_name).dir().absolutePath(); + mw->GlobSet.LastOpenDir = QFileInfo(file_name).dir().absolutePath(); QJsonDocument doc(repo->toJson()); QFile save_file(file_name); @@ -739,9 +739,9 @@ void ALrfWindow::on_pb_save_repository_clicked() void ALrfWindow::on_pb_load_repository_clicked() { - QStringList file_names = QFileDialog::getOpenFileNames(this, "Append repository", mw->GlobSet->LastOpenDir, "json files (*.json);;all files(*)"); + QStringList file_names = QFileDialog::getOpenFileNames(this, "Append repository", mw->GlobSet.LastOpenDir, "json files (*.json);;all files(*)"); if(file_names.isEmpty()) return; - mw->GlobSet->LastOpenDir = QFileInfo(file_names.first()).absolutePath(); + mw->GlobSet.LastOpenDir = QFileInfo(file_names.first()).absolutePath(); for (int ifile = 0; ifile < file_names.size(); ifile++) { QString file_name = file_names[ifile]; @@ -763,9 +763,9 @@ void ALrfWindow::on_pb_load_repository_clicked() void ALrfWindow::on_pb_save_current_clicked() { - QString file_name = QFileDialog::getSaveFileName(this, "Save current lrfs", mw->GlobSet->LastOpenDir, "json files(*.json);;all files(*)"); + QString file_name = QFileDialog::getSaveFileName(this, "Save current lrfs", mw->GlobSet.LastOpenDir, "json files(*.json);;all files(*)"); if (file_name.isEmpty()) return; - mw->GlobSet->LastOpenDir = QFileInfo(file_name).dir().absolutePath(); + mw->GlobSet.LastOpenDir = QFileInfo(file_name).dir().absolutePath(); QJsonDocument doc(repo->toJson(repo->getCurrentRecipeID())); QFile save_file(file_name); @@ -779,9 +779,9 @@ void ALrfWindow::on_pb_save_current_clicked() void ALrfWindow::on_pb_load_current_clicked() { - QStringList file_names = QFileDialog::getOpenFileNames(this, "Append repository and set as current", mw->GlobSet->LastOpenDir, "json files (*.json);;all files(*)"); + QStringList file_names = QFileDialog::getOpenFileNames(this, "Append repository and set as current", mw->GlobSet.LastOpenDir, "json files (*.json);;all files(*)"); if(file_names.isEmpty()) return; - mw->GlobSet->LastOpenDir = QFileInfo(file_names.first()).absolutePath(); + mw->GlobSet.LastOpenDir = QFileInfo(file_names.first()).absolutePath(); for (int ifile = 0; ifile < file_names.size(); ifile++) { QString file_name = file_names[ifile]; @@ -827,7 +827,7 @@ void ALrfWindow::on_pb_show_radial_clicked() json["Z"] = led_zcenter->text().toDouble(); json["DZ"] = led_zrange->text().toDouble(); json["EnergyScaling"] = cb_UseEventEnergy->isChecked(); - json["FunctionPointsX"] = mw->GlobSet->FunctionPointsX; + json["FunctionPointsX"] = mw->GlobSet.FunctionPointsX; json["Bins"] = sbDataBins->value(); json["ShowNodes"] = false;//ui->cbShowNodePositions->isChecked(); @@ -881,8 +881,8 @@ void ALrfWindow::on_pb_show_xy_clicked() json["Z"] = led_zcenter->text().toDouble(); json["DZ"] = led_zrange->text().toDouble(); json["EnergyScaling"] = cb_UseEventEnergy->isChecked(); - json["FunctionPointsX"] = mw->GlobSet->FunctionPointsX; - json["FunctionPointsY"] = mw->GlobSet->FunctionPointsY; + json["FunctionPointsX"] = mw->GlobSet.FunctionPointsX; + json["FunctionPointsY"] = mw->GlobSet.FunctionPointsY; json["Bins"] = sbDataBins->value(); //json["ShowNodes"] = ui->cbShowNodePositions->isChecked(); @@ -1074,10 +1074,10 @@ void ALrfWindow::on_pbExportLrfVsRadial_clicked() if(!doLrfRadialProfile(Rad, LRF)) return; QString str = sbPM->text(); - QString fileName = QFileDialog::getSaveFileName(this, "Save LRF # " +str+ " vs radius", mw->GlobSet->LastOpenDir, + QString fileName = QFileDialog::getSaveFileName(this, "Save LRF # " +str+ " vs radius", mw->GlobSet.LastOpenDir, "Text files (*.txt);;Data files (*.dat);;All files (*.*)"); if (fileName.isEmpty()) return; - mw->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + mw->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFile outputFile(fileName); outputFile.open(QIODevice::WriteOnly); if(!outputFile.isOpen()) { diff --git a/src/scriptmode/ainterfacetodeposcript.cpp b/src/scriptmode/ainterfacetodeposcript.cpp index c0824184..b80b77dc 100644 --- a/src/scriptmode/ainterfacetodeposcript.cpp +++ b/src/scriptmode/ainterfacetodeposcript.cpp @@ -4,7 +4,6 @@ #include "aparticleonstack.h" #include "simulationmanager.h" #include "asandwich.h" -#include "globalsettingsclass.h" #include "atrackrecords.h" #include @@ -13,8 +12,8 @@ #include "TGeoTrack.h" #include "TGeoManager.h" -AInterfaceToDepoScript::AInterfaceToDepoScript(DetectorClass *Detector, GlobalSettingsClass *GlobSet, EventsDataClass* EventsDataHub) - : Detector(Detector), GlobSet(GlobSet), EventsDataHub(EventsDataHub) +AInterfaceToDepoScript::AInterfaceToDepoScript(DetectorClass *Detector, EventsDataClass* EventsDataHub) + : Detector(Detector), EventsDataHub(EventsDataHub) { H["ClearStack"] = "Clear particle stack"; H["AddParticleToStack"] = "Add a particle (or several identical particles) to the stack"; diff --git a/src/scriptmode/ainterfacetodeposcript.h b/src/scriptmode/ainterfacetodeposcript.h index e3afe902..f6193f90 100644 --- a/src/scriptmode/ainterfacetodeposcript.h +++ b/src/scriptmode/ainterfacetodeposcript.h @@ -8,7 +8,6 @@ #include class EventsDataClass; -class GlobalSettingsClass; struct AEnergyDepositionCell; class AParticleOnStack; @@ -38,12 +37,11 @@ class AInterfaceToDepoScript : public AScriptInterface { Q_OBJECT public: - AInterfaceToDepoScript(DetectorClass* Detector, GlobalSettingsClass* GlobSet, EventsDataClass* EventsDataHub); + AInterfaceToDepoScript(DetectorClass* Detector, EventsDataClass* EventsDataHub); ~AInterfaceToDepoScript(); private: DetectorClass* Detector; - GlobalSettingsClass* GlobSet; EventsDataClass* EventsDataHub; QVector ParticleStack; diff --git a/src/scriptmode/interfacetoglobscript.cpp b/src/scriptmode/interfacetoglobscript.cpp index 1b2a5f09..7696b4c8 100644 --- a/src/scriptmode/interfacetoglobscript.cpp +++ b/src/scriptmode/interfacetoglobscript.cpp @@ -7,7 +7,6 @@ #include "atrackrecords.h" #include "sensorlrfs.h" #include "alrfmoduleselector.h" -#include "globalsettingsclass.h" #include "ajsontools.h" #include "apmtype.h" #include "aconfiguration.h" From 581e8aab511c87103c49244479edd7504d9a87bf Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 5 Oct 2018 13:50:33 +0100 Subject: [PATCH 043/140] move aopticaloverride files to dedicated directory; made initializeWave to use MatCollection data --- .../aopticaloverride.cpp | 0 .../aopticaloverride.h | 2 +- src/OpticalOverrides/awaveshifteroverride.cpp | 36 +++++++------------ src/OpticalOverrides/awaveshifteroverride.h | 3 +- .../spectralbasicopticaloverride.cpp | 11 ++++-- .../spectralbasicopticaloverride.h | 3 +- src/ants2.pro | 4 +-- src/modules/amaterialparticlecolection.cpp | 9 ++--- src/modules/amaterialparticlecolection.h | 4 +-- 9 files changed, 30 insertions(+), 42 deletions(-) rename src/{common => OpticalOverrides}/aopticaloverride.cpp (100%) rename src/{common => OpticalOverrides}/aopticaloverride.h (93%) diff --git a/src/common/aopticaloverride.cpp b/src/OpticalOverrides/aopticaloverride.cpp similarity index 100% rename from src/common/aopticaloverride.cpp rename to src/OpticalOverrides/aopticaloverride.cpp diff --git a/src/common/aopticaloverride.h b/src/OpticalOverrides/aopticaloverride.h similarity index 93% rename from src/common/aopticaloverride.h rename to src/OpticalOverrides/aopticaloverride.h index 68c0b977..3d9780f5 100644 --- a/src/common/aopticaloverride.h +++ b/src/OpticalOverrides/aopticaloverride.h @@ -36,7 +36,7 @@ class AOpticalOverride virtual const QString getLongReportLine() const {return getReportLine();} //for GUI: used in overlap map //TODO: initializeWaveResolved() -> no need to transfer data, MatCollection knows the settings - virtual void initializeWaveResolved(bool /*bWaveResolved*/, double /*waveFrom*/, double /*waveStep*/, int /*waveNodes*/) {} //override if override has wavelength-resolved data + virtual void initializeWaveResolved() {} //override if override has wavelength-resolved data // save/load config virtual void writeToJson(QJsonObject &json) const; diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 39500eeb..92685b95 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -36,14 +36,14 @@ AWaveshifterOverride::~AWaveshifterOverride() if (Spectrum) delete Spectrum; } -void AWaveshifterOverride::initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) +void AWaveshifterOverride::initializeWaveResolved() { - if (bWaveResolved) - { - WaveFrom = waveFrom; - WaveStep = waveStep; - WaveNodes = waveNodes; + bool bWavelengthResolved; + double waveTo; + MatCollection->GetWave(bWavelengthResolved, WaveFrom, waveTo, WaveStep, WaveNodes); + if (bWavelengthResolved) + { ConvertToStandardWavelengthes(&ReemissionProbability_lambda, &ReemissionProbability, WaveFrom, WaveStep, WaveNodes, &ReemissionProbabilityBinned); QVector y; @@ -310,15 +310,11 @@ void AWaveshifterOverride::showEmissionSpectrum(GraphWindowClass *GraphWindow, Q void AWaveshifterOverride::showBinnedReemissionProbability(GraphWindowClass *GraphWindow, QWidget *caller) { - bool bWR; - double WaveFrom, WaveTo, WaveStep; - int WaveNodes; - MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + initializeWaveResolved(); //TODO run checker - if (!bWR) + if ( !MatCollection->IsWaveResolved() ) { message("Simulation is NOT wavelength resolved, override is inactive!", caller); return; @@ -336,15 +332,11 @@ void AWaveshifterOverride::showBinnedReemissionProbability(GraphWindowClass *Gra void AWaveshifterOverride::showBinnedEmissionSpectrum(GraphWindowClass *GraphWindow, QWidget *caller) { - bool bWR; - double WaveFrom, WaveTo, WaveStep; - int WaveNodes; - MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + initializeWaveResolved(); //TODO run checker - if (!bWR) + if ( !MatCollection->IsWaveResolved() ) { message("Simulation is NOT wavelength resolved, override is inactive!", caller); return; @@ -377,13 +369,9 @@ const QString AWaveshifterOverride::checkOverrideData() if (EmissionSpectrum_lambda.size() != EmissionSpectrum.size()) return "Mismatch in emission spectrum data"; - bool bWR; - double WaveFrom, WaveTo, WaveStep; - int WaveNodes; - MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + initializeWaveResolved(); - if (bWR && Spectrum->ComputeIntegral() <= 0) + if (MatCollection->IsWaveResolved() && Spectrum->ComputeIntegral() <= 0) return "Binned emission spectrum: integral should be > 0"; return ""; } diff --git a/src/OpticalOverrides/awaveshifteroverride.h b/src/OpticalOverrides/awaveshifteroverride.h index 3df007b8..505350c6 100644 --- a/src/OpticalOverrides/awaveshifteroverride.h +++ b/src/OpticalOverrides/awaveshifteroverride.h @@ -19,7 +19,7 @@ class AWaveshifterOverride : public AOpticalOverride AWaveshifterOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo); virtual ~AWaveshifterOverride(); - void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; + void initializeWaveResolved() override; virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector); //unitary vectors! iWave = -1 if not wavelength-resolved virtual const QString getType() const override {return "SurfaceWLS";} @@ -46,7 +46,6 @@ class AWaveshifterOverride : public AOpticalOverride QVector EmissionSpectrum; TH1D* Spectrum = 0; - //tmp parameters double WaveFrom; double WaveStep; int WaveNodes; diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.cpp b/src/OpticalOverrides/spectralbasicopticaloverride.cpp index 2a554d27..21d8fa13 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.cpp +++ b/src/OpticalOverrides/spectralbasicopticaloverride.cpp @@ -43,7 +43,7 @@ SpectralBasicOpticalOverride::SpectralBasicOpticalOverride(AMaterialParticleColl AOpticalOverride::OpticalOverrideResultEnum SpectralBasicOpticalOverride::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { int waveIndex = Photon->waveIndex; - if (waveIndex == -1) waveIndex = effectiveWaveIndex; + if (!bWaveResolved || waveIndex == -1) waveIndex = effectiveWaveIndex; //guard: if not resolved, script ovberride can in principle assign index != -1 probLoss = ProbLossBinned.at(waveIndex); probDiff = ProbDiffBinned.at(waveIndex); @@ -105,8 +105,12 @@ bool SpectralBasicOpticalOverride::readFromJson(const QJsonObject &json) return true; } -void SpectralBasicOpticalOverride::initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) +void SpectralBasicOpticalOverride::initializeWaveResolved() { + double waveFrom, waveTo, waveStep; + int waveNodes; + MatCollection->GetWave(bWaveResolved, waveFrom, waveTo, waveStep, waveNodes); + if (bWaveResolved) { ConvertToStandardWavelengthes(&Wave, &ProbLoss, waveFrom, waveStep, waveNodes, &ProbLossBinned); @@ -201,7 +205,8 @@ void SpectralBasicOpticalOverride::showBinned(QWidget *widget, GraphWindowClass double WaveFrom, WaveTo, WaveStep; int WaveNodes; MatCollection->GetWave(bWR, WaveFrom, WaveTo, WaveStep, WaveNodes); - initializeWaveResolved(bWR, WaveFrom, WaveStep, WaveNodes); + + initializeWaveResolved(); //TODO run checker diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.h b/src/OpticalOverrides/spectralbasicopticaloverride.h index e70824d7..976a2b26 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.h +++ b/src/OpticalOverrides/spectralbasicopticaloverride.h @@ -29,7 +29,7 @@ class SpectralBasicOpticalOverride : public ABasicOpticalOverride virtual void writeToJson(QJsonObject &json) const override; virtual bool readFromJson(const QJsonObject &json) override; - virtual void initializeWaveResolved(bool bWaveResolved, double waveFrom, double waveStep, int waveNodes) override; + virtual void initializeWaveResolved() override; const QString loadData(const QString& fileName); #ifdef GUI @@ -48,6 +48,7 @@ class SpectralBasicOpticalOverride : public ABasicOpticalOverride QVector ProbDiffBinned; //probability of scattering double effectiveWavelength = 500; //if waveIndex of photon is -1, index correspinding to this wavelength will be used double effectiveWaveIndex; + bool bWaveResolved; private: #ifdef GUI diff --git a/src/ants2.pro b/src/ants2.pro index 0a0fe1ee..ca8bcde5 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -256,7 +256,7 @@ SOURCES += main.cpp \ common/apmarraydata.cpp \ common/aqtmessageredirector.cpp \ common/ageoobject.cpp \ - common/aopticaloverride.cpp \ + OpticalOverrides/aopticaloverride.cpp \ modules/detectorclass.cpp \ modules/eventsdataclass.cpp \ modules/dynamicpassiveshandler.cpp \ @@ -376,7 +376,7 @@ HEADERS += common/CorrelationFilters.h \ common/apmposangtyperecord.h \ common/apmarraydata.h \ common/ageoobject.h \ - common/aopticaloverride.h \ + OpticalOverrides/aopticaloverride.h \ modules/detectorclass.h \ modules/particlesourcesclass.h \ modules/flatfield.h \ diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index 3d5fb4ae..3fa31884 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -58,11 +58,6 @@ void AMaterialParticleCollection::GetWave(bool &wavelengthResolved, double &wave waveNodes = WaveNodes; } -bool AMaterialParticleCollection::IsWaveResolved() const -{ - return WavelengthResolved; -} - void AMaterialParticleCollection::UpdateRuntimePropertiesAndWavelengthBinning(GeneralSimSettings *SimSet, TRandom2* RandGen, int numThreads) { AMaterialParticleCollection::SetWave(SimSet->fWaveResolved, SimSet->WaveFrom, SimSet->WaveTo, SimSet->WaveStep, SimSet->WaveNodes); @@ -405,7 +400,7 @@ void AMaterialParticleCollection::UpdateWaveResolvedProperties(int imat) for (int ior=0; iorOpticalOverrides.size(); ior++) if (MaterialCollectionData[imat]->OpticalOverrides[ior]) - MaterialCollectionData[imat]->OpticalOverrides[ior]->initializeWaveResolved(true, WaveFrom, WaveStep, WaveNodes); + MaterialCollectionData[imat]->OpticalOverrides[ior]->initializeWaveResolved(); } else { @@ -427,7 +422,7 @@ void AMaterialParticleCollection::UpdateWaveResolvedProperties(int imat) for (int ior=0; iorOpticalOverrides.size(); ior++) if (MaterialCollectionData[imat]->OpticalOverrides[ior]) - MaterialCollectionData[imat]->OpticalOverrides[ior]->initializeWaveResolved(false, 0, 1, 1); + MaterialCollectionData[imat]->OpticalOverrides[ior]->initializeWaveResolved(); } } diff --git a/src/modules/amaterialparticlecolection.h b/src/modules/amaterialparticlecolection.h index 279776e3..15a3ba9e 100644 --- a/src/modules/amaterialparticlecolection.h +++ b/src/modules/amaterialparticlecolection.h @@ -88,8 +88,8 @@ class AMaterialParticleCollection : public QObject void AddNewMaterial(QJsonObject &json); //general purpose requests - void GetWave(bool& wavelengthResolved, double& waveFrom, double& waveTo, double& waveStep, int& waveNodes) const; - bool IsWaveResolved() const; + void GetWave(bool& wavelengthResolved, double& waveFrom, double& waveTo, double& waveStep, int& waveNodes) const; + bool IsWaveResolved() const {return WavelengthResolved;} public: void ConvertToStandardWavelengthes(QVector *sp_x, QVector *sp_y, QVector *y); From d6412c67e0dec7e492d94499da67246c1ee9c96a Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 5 Oct 2018 15:43:10 +0100 Subject: [PATCH 044/140] overrides are checked before sim start --- src/OpticalOverrides/aopticaloverride.h | 9 +++++++-- src/modules/amaterialparticlecolection.cpp | 13 +++++++++++++ src/modules/amaterialparticlecolection.h | 1 + src/modules/simulationmanager.cpp | 3 +++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverride.h b/src/OpticalOverrides/aopticaloverride.h index 3d9780f5..5624be4f 100644 --- a/src/OpticalOverrides/aopticaloverride.h +++ b/src/OpticalOverrides/aopticaloverride.h @@ -35,25 +35,30 @@ class AOpticalOverride virtual const QString getReportLine() const = 0; // for GUI: used to reports override status (try to make as short as possible) virtual const QString getLongReportLine() const {return getReportLine();} //for GUI: used in overlap map - //TODO: initializeWaveResolved() -> no need to transfer data, MatCollection knows the settings + //called automatically before sim start virtual void initializeWaveResolved() {} //override if override has wavelength-resolved data // save/load config virtual void writeToJson(QJsonObject &json) const; virtual bool readFromJson(const QJsonObject &json); - //used by MatCollection when a material is removed: + //used by MatCollection when a material is removed void updateMatIndices(int iMatFrom, int iMatTo) {MatFrom = iMatFrom; MatTo = iMatTo;} #ifdef GUI + // returns a GUI widget to show / edit parameters virtual QWidget* getEditWidget(QWidget* caller, GraphWindowClass* GraphWindow); #endif + //called on editing end (widget above) and before sim start to avoid miss-configurations virtual const QString checkOverrideData() = 0; //cannot be const - w.resolved needs rebin // read-out variables for standalone checker only (not multithreaded) ScatterStatusEnum Status; // type of interaction which happened - use in 1 thread only! + //misc + int getMaterialTo() const {return MatTo;} + protected: AMaterialParticleCollection* MatCollection; int MatFrom, MatTo; // material index of material before(from) and after(to) the optical interface diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index 3fa31884..b77a3d38 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -68,6 +68,19 @@ void AMaterialParticleCollection::UpdateRuntimePropertiesAndWavelengthBinning(Ge } } +const QString AMaterialParticleCollection::CheckOverrides() +{ + for (AMaterial* mat : MaterialCollectionData) + for (AOpticalOverride* ov : mat->OpticalOverrides) + if (ov) + { + QString err = ov->checkOverrideData(); + if ( !err.isEmpty()) + return QString("Error in optical override from %1 to %2:\n").arg(mat->name).arg(getMaterialName(ov->getMaterialTo())) + err; + } + return QString(); +} + void AMaterialParticleCollection::updateRandomGenForThread(int ID, TRandom2* RandGen) { for (int imat = 0; imat < MaterialCollectionData.size(); imat++) diff --git a/src/modules/amaterialparticlecolection.h b/src/modules/amaterialparticlecolection.h index 15a3ba9e..6bd6436d 100644 --- a/src/modules/amaterialparticlecolection.h +++ b/src/modules/amaterialparticlecolection.h @@ -36,6 +36,7 @@ class AMaterialParticleCollection : public QObject //hopefully we will get rid of the RandGen after update in NCrystal void UpdateRuntimePropertiesAndWavelengthBinning(GeneralSimSettings *SimSet, TRandom2 *RandGen, int numThreads = 1); + const QString CheckOverrides(); void updateRandomGenForThread(int ID, TRandom2 *RandGen); //for script-based optical override initialization diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 39063823..aabea100 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -131,6 +131,9 @@ bool ASimulatorRunner::setup(QJsonObject &json, int threadCount) //qDebug() << "Updating MaterialColecftion module according to sim settings"; detector->MpCollection->UpdateRuntimePropertiesAndWavelengthBinning(&simSettings, detector->RandGen, threadCount); //update wave-resolved properties of materials and runtime properties for neutrons + ErrorString = detector->MpCollection->CheckOverrides(); + if (!ErrorString.isEmpty()) return false; + clearWorkers(); //just rebuild them all everytime, it's easier for(int i = 0; i < threadCount; i++) From eceb57b20a7ba52bae1de20e18e6e8c88fa432cd Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 5 Oct 2018 16:05:55 +0100 Subject: [PATCH 045/140] simplified override type names; load knows current directory --- src/OpticalOverrides/abasicopticaloverride.h | 2 +- src/OpticalOverrides/aopticaloverride.cpp | 22 +++++++------------ src/OpticalOverrides/awaveshifteroverride.cpp | 14 +++++++----- src/OpticalOverrides/fsnpopticaloverride.h | 2 +- src/OpticalOverrides/phscatclaudiomodel.h | 2 +- .../spectralbasicopticaloverride.cpp | 6 ++++- .../spectralbasicopticaloverride.h | 2 +- .../MainWindowTools/aopticaloverridedialog.ui | 2 +- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/OpticalOverrides/abasicopticaloverride.h b/src/OpticalOverrides/abasicopticaloverride.h index cad1cc62..5d65bdce 100644 --- a/src/OpticalOverrides/abasicopticaloverride.h +++ b/src/OpticalOverrides/abasicopticaloverride.h @@ -19,7 +19,7 @@ class ABasicOpticalOverride : public AOpticalOverride virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual const QString getType() const override {return "Simplistic_model";} + virtual const QString getType() const override {return "Simplistic";} virtual const QString getAbbreviation() const override {return "Simp";} virtual const QString getReportLine() const override; diff --git a/src/OpticalOverrides/aopticaloverride.cpp b/src/OpticalOverrides/aopticaloverride.cpp index c489c5fa..4dd9164e 100644 --- a/src/OpticalOverrides/aopticaloverride.cpp +++ b/src/OpticalOverrides/aopticaloverride.cpp @@ -63,21 +63,15 @@ QWidget *AOpticalOverride::getEditWidget(QWidget *, GraphWindowClass *) AOpticalOverride *OpticalOverrideFactory(QString model, AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) { - if (model == "Simplistic_model") + if (model == "Simplistic" || model == "Simplistic_model") return new ABasicOpticalOverride(MatCollection, MatFrom, MatTo); - if (model == "SimplisticSpectral_model") + if (model == "SimplisticSpectral" || model == "SimplisticSpectral_model") return new SpectralBasicOpticalOverride(MatCollection, MatFrom, MatTo); - else if (model == "Claudio_Model_V2") - return new PhScatClaudioModelV2(MatCollection, MatFrom, MatTo); - else if (model == "Claudio_Model_V2d1") - return new PhScatClaudioModelV2d1(MatCollection, MatFrom, MatTo); - else if (model == "Claudio_Model_V2d2") + else if (model == "ClaudioModel" || model == "Claudio_Model_V2d2") return new PhScatClaudioModelV2d2(MatCollection, MatFrom, MatTo); - else if (model == "Claudio_Model") //compatibility - return new PhScatClaudioModelV2(MatCollection, MatFrom, MatTo); else if (model == "DielectricToMetal") return new ScatterOnMetal(MatCollection, MatFrom, MatTo); - else if (model == "FS_NP" || model=="Neves_model") + else if (model == "FSNP" || model == "FS_NP" || model=="Neves_model") return new FSNPOpticalOverride(MatCollection, MatFrom, MatTo); else if (model == "SurfaceWLS") return new AWaveshifterOverride(MatCollection, MatFrom, MatTo); @@ -91,11 +85,11 @@ const QStringList ListOvAllOpticalOverrideTypes() { QStringList l; - l << "Simplistic_model" - << "SimplisticSpectral_model" - << "Claudio_Model_V2d2" + l << "Simplistic" + << "SimplisticSpectral" + << "FSNP" << "DielectricToMetal" - << "FS_NP" + << "ClaudioModel" << "SurfaceWLS" << "CustomScript"; diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 92685b95..1c5681ff 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -17,7 +17,8 @@ #include "afiletools.h" #include "graphwindowclass.h" #include "amessage.h" -#include "TGraph.h" +#include "aglobalsettings.h" +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include "TGraph.h" #endif AWaveshifterOverride::AWaveshifterOverride(AMaterialParticleCollection *MatCollection, int MatFrom, int MatTo) @@ -255,9 +257,10 @@ QWidget *AWaveshifterOverride::getEditWidget(QWidget *caller, GraphWindowClass * #ifdef GUI void AWaveshifterOverride::loadReemissionProbability(QWidget* caller) { - QString fileName = QFileDialog::getOpenFileName(caller, "Load reemission probability", "", "Data files (*.dat *.txt);;All files (*)"); + AGlobalSettings& GlobSet = AGlobalSettings::getInstance(); + QString fileName = QFileDialog::getOpenFileName(caller, "Load reemission probability", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; - //GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector X, Y; int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); if (ret == 0) @@ -269,9 +272,10 @@ void AWaveshifterOverride::loadReemissionProbability(QWidget* caller) void AWaveshifterOverride::loadEmissionSpectrum(QWidget *caller) { - QString fileName = QFileDialog::getOpenFileName(caller, "Load emission spectrum", "", "Data files (*.dat *.txt);;All files (*)"); + AGlobalSettings& GlobSet = AGlobalSettings::getInstance(); + QString fileName = QFileDialog::getOpenFileName(caller, "Load emission spectrum", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; - //GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector X, Y; int ret = LoadDoubleVectorsFromFile(fileName, &X, &Y); if (ret == 0) diff --git a/src/OpticalOverrides/fsnpopticaloverride.h b/src/OpticalOverrides/fsnpopticaloverride.h index 0d082b6f..a44e0fe2 100644 --- a/src/OpticalOverrides/fsnpopticaloverride.h +++ b/src/OpticalOverrides/fsnpopticaloverride.h @@ -20,7 +20,7 @@ class FSNPOpticalOverride : public AOpticalOverride virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual const QString getType() const override {return "FS_NP";} + virtual const QString getType() const override {return "FSNP";} virtual const QString getAbbreviation() const override {return "FSNP";} virtual const QString getReportLine() const override; diff --git a/src/OpticalOverrides/phscatclaudiomodel.h b/src/OpticalOverrides/phscatclaudiomodel.h index 37abae10..1a96a241 100644 --- a/src/OpticalOverrides/phscatclaudiomodel.h +++ b/src/OpticalOverrides/phscatclaudiomodel.h @@ -81,7 +81,7 @@ class PhScatClaudioModelV2d2 : public PhScatClaudioModelV2 PhScatClaudioModelV2d2(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : PhScatClaudioModelV2(MatCollection, MatFrom, MatTo) {} virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; - virtual const QString getType() const override {return "Claudio_Model_V2d2";} + virtual const QString getType() const override {return "ClaudioModel";} virtual const QString getReportLine() const override; }; diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.cpp b/src/OpticalOverrides/spectralbasicopticaloverride.cpp index 21d8fa13..e75bb872 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.cpp +++ b/src/OpticalOverrides/spectralbasicopticaloverride.cpp @@ -21,6 +21,8 @@ #include "amessage.h" #include "TGraph.h" #include "TMultiGraph.h" +#include "aglobalsettings.h" +#include #include #include #include @@ -167,8 +169,10 @@ const QString SpectralBasicOpticalOverride::loadData(const QString &fileName) #ifdef GUI void SpectralBasicOpticalOverride::loadSpectralData(QWidget* caller) { - QString fileName = QFileDialog::getOpenFileName(caller, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", "", "Data files (*.dat *.txt);;All files (*)"); + AGlobalSettings& GlobSet = AGlobalSettings::getInstance(); + QString fileName = QFileDialog::getOpenFileName(caller, "Load spectral data (Wavelength, Absorption, Reflection, Scattering)", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); if (fileName.isEmpty()) return; + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QVector< QVector* > vec; vec << &Wave << &ProbLoss << &ProbRef << &ProbDiff; diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.h b/src/OpticalOverrides/spectralbasicopticaloverride.h index 976a2b26..8e3b60b2 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.h +++ b/src/OpticalOverrides/spectralbasicopticaloverride.h @@ -21,7 +21,7 @@ class SpectralBasicOpticalOverride : public ABasicOpticalOverride virtual OpticalOverrideResultEnum calculate(ATracerStateful& Resources, APhoton* Photon, const double* NormalVector) override; //unitary vectors! iWave = -1 if not wavelength-resolved - virtual const QString getType() const override {return "SimplisticSpectral_model";} + virtual const QString getType() const override {return "SimplisticSpectral";} virtual const QString getAbbreviation() const override {return "SiSp";} virtual const QString getReportLine() const override; diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.ui b/src/gui/MainWindowTools/aopticaloverridedialog.ui index d93acbca..d26a961d 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.ui +++ b/src/gui/MainWindowTools/aopticaloverridedialog.ui @@ -148,7 +148,7 @@ - using Fresnel and Snell laws + using Fresnel equations and Snell's laws Qt::AlignCenter From 5d109a3d8ade339aa953b315f7b216a09f531b14 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 5 Oct 2018 20:49:50 +0100 Subject: [PATCH 046/140] fix override load sysyem - remove unnecessary tests, added useful --- .../abasicopticaloverride.cpp | 35 +++++++++--- src/OpticalOverrides/abasicopticaloverride.h | 1 + src/OpticalOverrides/aopticaloverride.cpp | 4 +- .../ascriptopticaloverride.cpp | 7 +-- src/OpticalOverrides/awaveshifteroverride.cpp | 20 +++---- src/OpticalOverrides/fsnpopticaloverride.cpp | 19 +++---- src/OpticalOverrides/fsnpopticaloverride.h | 1 + src/OpticalOverrides/phscatclaudiomodel.cpp | 55 ++++++++++++++----- src/OpticalOverrides/phscatclaudiomodel.h | 1 + src/OpticalOverrides/scatteronmetal.cpp | 20 ++++--- src/OpticalOverrides/scatteronmetal.h | 1 + .../spectralbasicopticaloverride.cpp | 10 ++-- src/common/ajsontools.cpp | 21 +++++-- src/common/ajsontools.h | 2 +- 14 files changed, 128 insertions(+), 69 deletions(-) diff --git a/src/OpticalOverrides/abasicopticaloverride.cpp b/src/OpticalOverrides/abasicopticaloverride.cpp index 6c2f6e50..5d0dc054 100644 --- a/src/OpticalOverrides/abasicopticaloverride.cpp +++ b/src/OpticalOverrides/abasicopticaloverride.cpp @@ -1,10 +1,10 @@ #include "abasicopticaloverride.h" - #include "aphoton.h" #include "amaterial.h" #include "amaterialparticlecolection.h" #include "atracerstateful.h" #include "asimulationstatistics.h" +#include "ajsontools.h" #include @@ -148,6 +148,26 @@ const QString ABasicOpticalOverride::getReportLine() const return s; } +const QString ABasicOpticalOverride::getLongReportLine() const +{ + QString s = "--> Simplistic <--\n"; + if (probLoss > 0) s += QString("Absorption: %1%\n").arg(100.0 * probLoss); + if (probRef > 0) s += QString("Specular reflection: %1%\n").arg(100.0 * probRef); + if (probDiff) + { + s += QString("Scattering: %1%").arg(100.0 * probDiff); + switch (scatterModel) + { + case 0: s += " (isotropic)\n"; break; + case 1: s += " (Lambertian, back)\n"; break; + case 2: s += " (Lambertian, forward)\n"; break; + } + } + double fres = 1.0 - probLoss - probRef - probDiff; + if (fres > 0) s += QString("Fresnel: %1%").arg(100.0 * fres); + return s; +} + void ABasicOpticalOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -160,14 +180,11 @@ void ABasicOpticalOverride::writeToJson(QJsonObject &json) const bool ABasicOpticalOverride::readFromJson(const QJsonObject &json) { - QString type = json["Model"].toString(); - if (type != getType()) return false; //file for wrong model! - - probLoss = json["Abs"].toDouble(); - probRef = json["Spec"].toDouble(); - probDiff = json["Scat"].toDouble(); - scatterModel = json["ScatMode"].toInt(); - return true; + if ( !parseJson(json, "Abs", probLoss) ) return false; + if ( !parseJson(json, "Spec", probRef) ) return false; + if ( !parseJson(json, "Scat", probDiff) ) return false; + if ( !parseJson(json, "ScatMode", scatterModel) ) return false; + return true; } #ifdef GUI diff --git a/src/OpticalOverrides/abasicopticaloverride.h b/src/OpticalOverrides/abasicopticaloverride.h index 5d65bdce..6e6e0f76 100644 --- a/src/OpticalOverrides/abasicopticaloverride.h +++ b/src/OpticalOverrides/abasicopticaloverride.h @@ -22,6 +22,7 @@ class ABasicOpticalOverride : public AOpticalOverride virtual const QString getType() const override {return "Simplistic";} virtual const QString getAbbreviation() const override {return "Simp";} virtual const QString getReportLine() const override; + virtual const QString getLongReportLine() const override; // save/load config is not used for this type! virtual void writeToJson(QJsonObject &json) const override; diff --git a/src/OpticalOverrides/aopticaloverride.cpp b/src/OpticalOverrides/aopticaloverride.cpp index 4dd9164e..109c7479 100644 --- a/src/OpticalOverrides/aopticaloverride.cpp +++ b/src/OpticalOverrides/aopticaloverride.cpp @@ -36,10 +36,8 @@ void AOpticalOverride::writeToJson(QJsonObject &json) const json["MatTo"] = MatTo; } -bool AOpticalOverride::readFromJson(const QJsonObject &json) +bool AOpticalOverride::readFromJson(const QJsonObject &) { - QString type = json["Model"].toString(); - if (type != getType()) return false; //file for wrong model! return true; } diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index ab3be188..8e40d0a1 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -3,6 +3,7 @@ #include "atracerstateful.h" #include "aopticaloverridescriptinterface.h" #include "amathscriptinterface.h" +#include "ajsontools.h" #ifdef GUI #include "ascriptwindow.h" @@ -52,11 +53,7 @@ void AScriptOpticalOverride::writeToJson(QJsonObject &json) const bool AScriptOpticalOverride::readFromJson(const QJsonObject &json) { - QString type = json["Model"].toString(); - if (type != getType()) return false; //file for wrong model! - - Script = json["Script"].toString(); - return true; + return parseJson(json, "Script", Script); } #ifdef GUI diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 1c5681ff..e6d0cf99 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -181,17 +181,17 @@ void AWaveshifterOverride::writeToJson(QJsonObject &json) const bool AWaveshifterOverride::readFromJson(const QJsonObject &json) { - //QString type = json["Model"].toString(); - //if (type != getType()) return false; //file for wrong model! - if (!AOpticalOverride::readFromJson(json)) return false; + if ( !parseJson(json, "ReemissionModel", ReemissionModel) ) return false; - QJsonArray arRP = json["ReemissionProbability"].toArray(); - readTwoQVectorsFromJArray(arRP, ReemissionProbability_lambda, ReemissionProbability); - QJsonArray arEm = json["EmissionSpectrum"].toArray(); - readTwoQVectorsFromJArray(arEm, EmissionSpectrum_lambda, EmissionSpectrum); - - ReemissionModel = 1; - parseJson(json, "ReemissionModel", ReemissionModel); + QJsonArray arRP; + if ( !parseJson(json, "ReemissionProbability", arRP) ) return false; + if (arRP.isEmpty()) return false; + if ( !readTwoQVectorsFromJArray(arRP, ReemissionProbability_lambda, ReemissionProbability) ) return false; + + QJsonArray arES; + if ( !parseJson(json, "EmissionSpectrum", arES) ) return false; + if (arES.isEmpty()) return false; + if ( !readTwoQVectorsFromJArray(arES, EmissionSpectrum_lambda, EmissionSpectrum) ) return false; return true; } diff --git a/src/OpticalOverrides/fsnpopticaloverride.cpp b/src/OpticalOverrides/fsnpopticaloverride.cpp index d81ecb99..7af649fd 100644 --- a/src/OpticalOverrides/fsnpopticaloverride.cpp +++ b/src/OpticalOverrides/fsnpopticaloverride.cpp @@ -4,6 +4,7 @@ #include "amaterialparticlecolection.h" #include "atracerstateful.h" #include "asimulationstatistics.h" +#include "ajsontools.h" #include @@ -97,6 +98,13 @@ const QString FSNPOpticalOverride::getReportLine() const return QString("Albedo %1").arg(Albedo); } +const QString FSNPOpticalOverride::getLongReportLine() const +{ + QString s = "--> FSNP <--\n"; + s += QString("Albedo: %1").arg(Albedo); + return s; +} + void FSNPOpticalOverride::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -106,16 +114,7 @@ void FSNPOpticalOverride::writeToJson(QJsonObject &json) const bool FSNPOpticalOverride::readFromJson(const QJsonObject &json) { - QString type = json["Model"].toString(); - if (type != getType()) return false; //file for wrong model! - - if (json.contains("Albedo")) - { - Albedo = json["Albedo"].toDouble(); - return true; - } - else - return false; + return parseJson(json, "Albedo", Albedo); } #ifdef GUI diff --git a/src/OpticalOverrides/fsnpopticaloverride.h b/src/OpticalOverrides/fsnpopticaloverride.h index a44e0fe2..57f044c5 100644 --- a/src/OpticalOverrides/fsnpopticaloverride.h +++ b/src/OpticalOverrides/fsnpopticaloverride.h @@ -23,6 +23,7 @@ class FSNPOpticalOverride : public AOpticalOverride virtual const QString getType() const override {return "FSNP";} virtual const QString getAbbreviation() const override {return "FSNP";} virtual const QString getReportLine() const override; + virtual const QString getLongReportLine() const override; // save/load config is not used for this type! virtual void writeToJson(QJsonObject &json) const override; diff --git a/src/OpticalOverrides/phscatclaudiomodel.cpp b/src/OpticalOverrides/phscatclaudiomodel.cpp index ff7d813a..05a03ba7 100644 --- a/src/OpticalOverrides/phscatclaudiomodel.cpp +++ b/src/OpticalOverrides/phscatclaudiomodel.cpp @@ -3,6 +3,7 @@ #include "aphoton.h" #include "asimulationstatistics.h" #include "atracerstateful.h" +#include "ajsontools.h" #include #include @@ -25,7 +26,34 @@ const QString PhScatClaudioModel::getReportLine() const { - return " v2"; + QString s; + s += QString("sA %1 / ").arg(sigma_alpha); + s += QString("sH %1 / ").arg(sigma_h); + s += QString("Alb %1 / ").arg(albedo); + s += "HD "; + switch (HeightDistribution) + { + case empirical : s += "em"; break; + case gaussian : s += "gau"; break; + case exponential : s += "exp"; break; + } + s += " / SD "; + switch (SlopeDistribution) + { + case trowbridgereitz : s += "tr"; break; + case cooktorrance : s += "cook"; break; + case bivariatecauchy : s += "biv"; break; + } + return s; +} + +const QString PhScatClaudioModel::getLongReportLine() const +{ + QString s = "--> Caludio's model v2.2 <--\n"; +// s += "Refractive index of metal:\n"; +// s += QString(" real: %1\n").arg(RealN); +// s += QString(" imaginary: %1").arg(ImaginaryN); + return s; } void PhScatClaudioModel::writeToJson(QJsonObject &json) const @@ -41,19 +69,20 @@ void PhScatClaudioModel::writeToJson(QJsonObject &json) const bool PhScatClaudioModel::readFromJson(const QJsonObject &json) { - QString type = json["Model"].toString(); - if (!type.startsWith("Claudio_Model")) - { - qCritical() << "Attempt to load json file for wrong override model!"; - return false; //file for wrong model! - } + if ( !parseJson(json, "SigmaAlpha", sigma_alpha)) return false; + if ( !parseJson(json, "SigmaH", sigma_h)) return false; + if ( !parseJson(json, "Albedo", albedo)) return false; + + int ival; + if ( !parseJson(json, "HDmodel", ival)) return false; + if (ival<0 || ival>2) return false; + HeightDistribution = static_cast(ival); + + if ( !parseJson(json, "SDmodel", ival)) return false; + if (ival<0 || ival>2) return false; + SlopeDistribution = static_cast(ival); - sigma_alpha = json["SigmaAlpha"].toDouble(); - sigma_h = json["SigmaH"].toDouble(); - albedo = json["Albedo"].toDouble(); - HeightDistribution = static_cast(json["HDmodel"].toInt()); - SlopeDistribution = static_cast(json["SDmodel"].toInt()); - return true; + return true; } #ifdef GUI diff --git a/src/OpticalOverrides/phscatclaudiomodel.h b/src/OpticalOverrides/phscatclaudiomodel.h index 1a96a241..54cbc33a 100644 --- a/src/OpticalOverrides/phscatclaudiomodel.h +++ b/src/OpticalOverrides/phscatclaudiomodel.h @@ -24,6 +24,7 @@ class PhScatClaudioModel : public AOpticalOverride //abstract class! //virtual const QString getType() const override = 0; virtual const QString getAbbreviation() const override {return "Clau";} virtual const QString getReportLine() const override; + virtual const QString getLongReportLine() const override; // save/load config virtual void writeToJson(QJsonObject &json) const override; diff --git a/src/OpticalOverrides/scatteronmetal.cpp b/src/OpticalOverrides/scatteronmetal.cpp index ebf7c0c4..13c8b32c 100644 --- a/src/OpticalOverrides/scatteronmetal.cpp +++ b/src/OpticalOverrides/scatteronmetal.cpp @@ -3,6 +3,7 @@ #include "aphoton.h" #include "asimulationstatistics.h" #include "atracerstateful.h" +#include "ajsontools.h" #include #include @@ -27,6 +28,15 @@ const QString ScatterOnMetal::getReportLine() const return s; } +const QString ScatterOnMetal::getLongReportLine() const +{ + QString s = "--> Dielectric to metal <--\n"; + s += "Refractive index of metal:\n"; + s += QString(" real: %1\n").arg(RealN); + s += QString(" imaginary: %1").arg(ImaginaryN); + return s; +} + void ScatterOnMetal::writeToJson(QJsonObject &json) const { AOpticalOverride::writeToJson(json); @@ -37,13 +47,9 @@ void ScatterOnMetal::writeToJson(QJsonObject &json) const bool ScatterOnMetal::readFromJson(const QJsonObject &json) { - QString type = json["Model"].toString(); - if (type != getType()) return false; //file for wrong model! - - RealN = json["RealN"].toDouble(); - ImaginaryN = json["ImaginaryN"].toDouble(); - - return true; + if ( !parseJson(json, "RealN", RealN) ) return false; + if ( !parseJson(json, "ImaginaryN", ImaginaryN) ) return false; + return true; } #ifdef GUI diff --git a/src/OpticalOverrides/scatteronmetal.h b/src/OpticalOverrides/scatteronmetal.h index a02bb31f..7ea8143d 100644 --- a/src/OpticalOverrides/scatteronmetal.h +++ b/src/OpticalOverrides/scatteronmetal.h @@ -21,6 +21,7 @@ class ScatterOnMetal : public AOpticalOverride virtual const QString getType() const override {return "DielectricToMetal";} virtual const QString getAbbreviation() const override {return "Met";} virtual const QString getReportLine() const override; + virtual const QString getLongReportLine() const override; // save/load config is not used for this type! virtual void writeToJson(QJsonObject &json) const override; diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.cpp b/src/OpticalOverrides/spectralbasicopticaloverride.cpp index e75bb872..28207fff 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.cpp +++ b/src/OpticalOverrides/spectralbasicopticaloverride.cpp @@ -83,10 +83,8 @@ void SpectralBasicOpticalOverride::writeToJson(QJsonObject &json) const bool SpectralBasicOpticalOverride::readFromJson(const QJsonObject &json) { - if (!AOpticalOverride::readFromJson(json)) return false; - - parseJson(json, "ScatMode", scatterModel); - parseJson(json, "EffWavelength", effectiveWavelength); + if ( !parseJson(json, "ScatMode", scatterModel) ) return false; + if ( !parseJson(json, "EffWavelength", effectiveWavelength) ) return false; //after constructor vectors are not empty! Wave.clear(); @@ -95,10 +93,12 @@ bool SpectralBasicOpticalOverride::readFromJson(const QJsonObject &json) ProbDiff.clear(); QJsonArray sp; - parseJson(json, "Data", sp); + if ( !parseJson(json, "Data", sp) ) return false; + if (sp.isEmpty()) return false; for (int i=0; i &x, const QVector &y return true; } -void readTwoQVectorsFromJArray(QJsonArray &ar, QVector &x, QVector &y) +bool readTwoQVectorsFromJArray(QJsonArray &ar, QVector &x, QVector &y) { - for (int i=0; i > &xy, QJsonArray &ar) diff --git a/src/common/ajsontools.h b/src/common/ajsontools.h index 04586853..9a3d7295 100644 --- a/src/common/ajsontools.h +++ b/src/common/ajsontools.h @@ -29,7 +29,7 @@ void JsonToLineEditText(QJsonObject& json, QString key, QLineEdit* le); void JsonToComboBox(QJsonObject& json, QString key, QComboBox* qb); bool writeTwoQVectorsToJArray(const QVector &x, const QVector &y, QJsonArray &ar); -void readTwoQVectorsFromJArray(QJsonArray &ar, QVector &x, QVector &y); +bool readTwoQVectorsFromJArray(QJsonArray &ar, QVector &x, QVector &y); bool write2DQVectorToJArray(const QVector > &xy, QJsonArray &ar); void read2DQVectorFromJArray(QJsonArray &ar, QVector > &xy); From f869ecc275b82416b6f79256bc42627dc570b27c Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 5 Oct 2018 21:15:57 +0100 Subject: [PATCH 047/140] all overrides: long and short reports finished --- .../ascriptopticaloverride.cpp | 8 +++- src/OpticalOverrides/awaveshifteroverride.cpp | 38 ++++++++++++++++++- src/OpticalOverrides/awaveshifteroverride.h | 1 + src/OpticalOverrides/phscatclaudiomodel.cpp | 35 +++++++++-------- src/OpticalOverrides/phscatclaudiomodel.h | 3 -- .../spectralbasicopticaloverride.cpp | 9 +++++ .../spectralbasicopticaloverride.h | 1 + 7 files changed, 71 insertions(+), 24 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index 8e40d0a1..a40e01e7 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -36,12 +36,16 @@ AOpticalOverride::OpticalOverrideResultEnum AScriptOpticalOverride::calculate(AT const QString AScriptOpticalOverride::getReportLine() const { - return QString(); + QString s = Script.simplified().left(40); + s += "..."; + return s; } const QString AScriptOpticalOverride::getLongReportLine() const { - return Script; + QString s = "--> Custom script <--\n"; + s += Script; + return s; } void AScriptOpticalOverride::writeToJson(QJsonObject &json) const diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index e6d0cf99..162133e1 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -163,7 +163,43 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra const QString AWaveshifterOverride::getReportLine() const { - return QString(); + QString s = QString("CProb %1 pts; Spectr %2 pts; Mod: ").arg(ReemissionProbability_lambda.size()).arg(EmissionSpectrum_lambda.size()); + switch( ReemissionModel ) + { + case 0: + s += "Iso"; + break; + case 1: + s += "Lamb_B"; + break; + case 2: + s += "Lamb_F"; + break; + } + return s; +} + +const QString AWaveshifterOverride::getLongReportLine() const +{ + QString s = "--> Wavelength shifter <--\n"; + s += QString("Reemission probaility from %1 to %2 nm\n").arg(ReemissionProbability_lambda.first()).arg(ReemissionProbability_lambda.last()); + s += QString("Number of points: %1\n").arg(ReemissionProbability_lambda.size()); + s += QString("Emission spectrum from %1 to %2 nm\n").arg(EmissionSpectrum_lambda.first()).arg(EmissionSpectrum_lambda.last()); + s += QString("Number of points: %1\n").arg(EmissionSpectrum_lambda.size()); + s += "Reemission model: "; + switch( ReemissionModel ) + { + case 0: + s += "isotropic"; + break; + case 1: + s += "Lambertian, back"; + break; + case 2: + s += "Lambertian, forward"; + break; + } + return s; } void AWaveshifterOverride::writeToJson(QJsonObject &json) const diff --git a/src/OpticalOverrides/awaveshifteroverride.h b/src/OpticalOverrides/awaveshifteroverride.h index 505350c6..ebd4151c 100644 --- a/src/OpticalOverrides/awaveshifteroverride.h +++ b/src/OpticalOverrides/awaveshifteroverride.h @@ -25,6 +25,7 @@ class AWaveshifterOverride : public AOpticalOverride virtual const QString getType() const override {return "SurfaceWLS";} virtual const QString getAbbreviation() const override {return "WLS";} virtual const QString getReportLine() const override; + virtual const QString getLongReportLine() const override; // save/load config is not used for this type! virtual void writeToJson(QJsonObject &json) const; diff --git a/src/OpticalOverrides/phscatclaudiomodel.cpp b/src/OpticalOverrides/phscatclaudiomodel.cpp index 05a03ba7..7d78ba65 100644 --- a/src/OpticalOverrides/phscatclaudiomodel.cpp +++ b/src/OpticalOverrides/phscatclaudiomodel.cpp @@ -50,9 +50,23 @@ const QString PhScatClaudioModel::getReportLine() const const QString PhScatClaudioModel::getLongReportLine() const { QString s = "--> Caludio's model v2.2 <--\n"; -// s += "Refractive index of metal:\n"; -// s += QString(" real: %1\n").arg(RealN); -// s += QString(" imaginary: %1").arg(ImaginaryN); + s += QString("Sigma alpha: %1\n").arg(sigma_alpha); + s += QString("Sigma height: %1\n").arg(sigma_h); + s += QString("Albedo: %1\n").arg(albedo); + s += "Height distribution: "; + switch (HeightDistribution) + { + case empirical : s += "emprirical"; break; + case gaussian : s += "gaussian"; break; + case exponential : s += "exponential"; break; + } + s += "\nSlope distribution: "; + switch (SlopeDistribution) + { + case trowbridgereitz : s += "trowbridgereitz"; break; + case cooktorrance : s += "cooktorrance"; break; + case bivariatecauchy : s += "bivariatecauchy"; break; + } return s; } @@ -374,11 +388,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(ATra return Back; } -const QString PhScatClaudioModelV2::getReportLine() const -{ - return " v2"; -} - AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { TVector3 K(Photon->v); // photon direction @@ -550,11 +559,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(AT return Back; } -const QString PhScatClaudioModelV2d2::getReportLine() const -{ - return " v2.2"; -} - AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(ATracerStateful &Resources, APhoton *Photon, const double *NormalVector) { TVector3 K(Photon->v); // photon direction @@ -725,8 +729,3 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(AT //qDebug() << "---"<<(int)Status< Date: Sat, 6 Oct 2018 00:45:43 +0100 Subject: [PATCH 048/140] overrides gui: update buttons; dialog: remember all tried ov until cancel/accept --- src/OpticalOverrides/awaveshifteroverride.cpp | 36 ++++++++++++------- src/OpticalOverrides/awaveshifteroverride.h | 3 ++ .../spectralbasicopticaloverride.cpp | 20 +++++++---- .../spectralbasicopticaloverride.h | 3 ++ .../aopticaloverridedialog.cpp | 29 +++++++++++++-- .../MainWindowTools/aopticaloverridedialog.h | 5 +++ 6 files changed, 75 insertions(+), 21 deletions(-) diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 162133e1..3919fe1a 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -266,25 +266,26 @@ QWidget *AWaveshifterOverride::getEditWidget(QWidget *caller, GraphWindowClass * vv->addWidget(pb); l->addLayout(vv); vv = new QVBoxLayout(); - pb = new QPushButton("Show"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showReemissionProbability(GraphWindow, caller);}); - vv->addWidget(pb); - pb = new QPushButton("Show"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showEmissionSpectrum(GraphWindow, caller);}); - vv->addWidget(pb); + pbShowRP = new QPushButton("Show"); + QObject::connect(pbShowRP, &QPushButton::clicked, [GraphWindow, caller, this] {showReemissionProbability(GraphWindow, caller);}); + vv->addWidget(pbShowRP); + pbShowES = new QPushButton("Show"); + QObject::connect(pbShowES, &QPushButton::clicked, [GraphWindow, caller, this] {showEmissionSpectrum(GraphWindow, caller);}); + vv->addWidget(pbShowES); l->addLayout(vv); vv = new QVBoxLayout(); - pb = new QPushButton("Binned"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedReemissionProbability(GraphWindow, caller);}); - vv->addWidget(pb); - pb = new QPushButton("Binned"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedEmissionSpectrum(GraphWindow, caller);}); - vv->addWidget(pb); + pbShowRPbinned = new QPushButton("Binned"); + QObject::connect(pbShowRPbinned, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedReemissionProbability(GraphWindow, caller);}); + vv->addWidget(pbShowRPbinned); + pbShowESbinned = new QPushButton("Binned"); + QObject::connect(pbShowESbinned, &QPushButton::clicked, [GraphWindow, caller, this] {showBinnedEmissionSpectrum(GraphWindow, caller);}); + vv->addWidget(pbShowESbinned); l->addLayout(vv); vl->addLayout(l); lab = new QLabel("If simulation is NOT wavelength-resolved, this override does nothing!"); lab->setAlignment(Qt::AlignCenter); vl->addWidget(lab); + updateButtons(); return f; } @@ -303,6 +304,7 @@ void AWaveshifterOverride::loadReemissionProbability(QWidget* caller) { ReemissionProbability_lambda = X; ReemissionProbability = Y; + updateButtons(); } } @@ -318,6 +320,7 @@ void AWaveshifterOverride::loadEmissionSpectrum(QWidget *caller) { EmissionSpectrum_lambda = X; EmissionSpectrum = Y; + updateButtons(); } } @@ -395,6 +398,15 @@ void AWaveshifterOverride::showBinnedEmissionSpectrum(GraphWindowClass *GraphWin SpectrumCopy->GetYaxis()->SetTitle("Relative intensity, a.u."); GraphWindow->Draw(SpectrumCopy, "hist"); //gets ownership of the copy } + +void AWaveshifterOverride::updateButtons() +{ + pbShowRP->setDisabled(ReemissionProbability_lambda.isEmpty()); + pbShowES->setDisabled(EmissionSpectrum_lambda.isEmpty()); + bool bWR = MatCollection->IsWaveResolved(); + pbShowRPbinned->setDisabled(!bWR || ReemissionProbability_lambda.isEmpty()); + pbShowESbinned->setDisabled(!bWR || EmissionSpectrum_lambda.isEmpty()); +} #endif const QString AWaveshifterOverride::checkOverrideData() diff --git a/src/OpticalOverrides/awaveshifteroverride.h b/src/OpticalOverrides/awaveshifteroverride.h index ebd4151c..0a119e66 100644 --- a/src/OpticalOverrides/awaveshifteroverride.h +++ b/src/OpticalOverrides/awaveshifteroverride.h @@ -12,6 +12,7 @@ class APhoton; class QJsonObject; class GraphWindowClass; class TH1D; +class QPushButton; class AWaveshifterOverride : public AOpticalOverride { @@ -53,12 +54,14 @@ class AWaveshifterOverride : public AOpticalOverride private: #ifdef GUI + QPushButton *pbShowRP, *pbShowRPbinned, *pbShowES, *pbShowESbinned; void loadReemissionProbability(QWidget *caller); void loadEmissionSpectrum(QWidget *caller); void showReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); void showEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); void showBinnedReemissionProbability(GraphWindowClass* GraphWindow, QWidget *caller); void showBinnedEmissionSpectrum(GraphWindowClass* GraphWindow, QWidget *caller); + void updateButtons(); #endif }; diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.cpp b/src/OpticalOverrides/spectralbasicopticaloverride.cpp index 46257cce..fb68408a 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.cpp +++ b/src/OpticalOverrides/spectralbasicopticaloverride.cpp @@ -257,6 +257,13 @@ void SpectralBasicOpticalOverride::showBinned(QWidget *widget, GraphWindowClass mg->GetYaxis()->SetTitle("Probability"); GraphWindow->AddLegend(0.7,0.8, 0.95,0.95, ""); } + +void SpectralBasicOpticalOverride::updateButtons() +{ + pbShow->setDisabled(Wave.isEmpty()); + bool bWR = MatCollection->IsWaveResolved(); + pbShowBinned->setDisabled(!bWR || Wave.isEmpty()); +} #endif #ifdef GUI @@ -273,12 +280,12 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller, GraphWindo pb->setToolTip("Every line of the file should contain 4 numbers:\nwavelength[nm] absorption_prob[0..1] reflection_prob[0..1] scattering_prob[0..1]"); QObject::connect(pb, &QPushButton::clicked, [caller, this] {loadSpectralData(caller);}); l->addWidget(pb); - pb = new QPushButton("Show"); - QObject::connect(pb, &QPushButton::clicked, [GraphWindow, this] {showLoaded(GraphWindow);}); - l->addWidget(pb); - pb = new QPushButton("Binned"); - QObject::connect(pb, &QPushButton::clicked, [caller, GraphWindow, this] {showBinned(caller, GraphWindow);}); - l->addWidget(pb); + pbShow = new QPushButton("Show"); + QObject::connect(pbShow, &QPushButton::clicked, [GraphWindow, this] {showLoaded(GraphWindow);}); + l->addWidget(pbShow); + pbShowBinned = new QPushButton("Binned"); + QObject::connect(pbShowBinned, &QPushButton::clicked, [caller, GraphWindow, this] {showBinned(caller, GraphWindow);}); + l->addWidget(pbShowBinned); vl->addLayout(l); l = new QHBoxLayout(); lab = new QLabel("Scattering model:"); @@ -303,6 +310,7 @@ QWidget *SpectralBasicOpticalOverride::getEditWidget(QWidget *caller, GraphWindo lab = new QLabel("nm"); l->addWidget(lab); vl->addLayout(l); + updateButtons(); return f; } diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.h b/src/OpticalOverrides/spectralbasicopticaloverride.h index b5df058d..6b8008cb 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.h +++ b/src/OpticalOverrides/spectralbasicopticaloverride.h @@ -12,6 +12,7 @@ class ATracerStateful; class APhoton; class QJsonObject; class GraphWindowClass; +class QPushButton; class SpectralBasicOpticalOverride : public ABasicOpticalOverride { @@ -53,9 +54,11 @@ class SpectralBasicOpticalOverride : public ABasicOpticalOverride private: #ifdef GUI + QPushButton *pbShow, *pbShowBinned; void loadSpectralData(QWidget *caller); void showLoaded(GraphWindowClass *GraphWindow); void showBinned(QWidget *widget, GraphWindowClass *GraphWindow); + void updateButtons(); #endif }; diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index b3347a85..3425609b 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -9,6 +9,7 @@ #include #include +#include AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, int matFrom, int matTo, GraphWindowClass * GraphWindow, GeometryWindowClass *GeometryWindow, QWidget * parent) : @@ -72,6 +73,20 @@ void AOpticalOverrideDialog::updateGui() } } +AOpticalOverride *AOpticalOverrideDialog::findInOpended(const QString &ovType) +{ + for (AOpticalOverride* ov : openedOVs) + if (ov->getType() == ovType) return ov; + return 0; +} + +void AOpticalOverrideDialog::clearOpenedExcept(AOpticalOverride *keepOV) +{ + for (AOpticalOverride* ov : openedOVs) + if (ov != keepOV) delete ov; + openedOVs.clear(); +} + void AOpticalOverrideDialog::on_pbAccept_clicked() { if (ovLocal) @@ -84,6 +99,8 @@ void AOpticalOverrideDialog::on_pbAccept_clicked() } } + clearOpenedExcept(ovLocal); + delete (*MatCollection)[matFrom]->OpticalOverrides[matTo]; (*MatCollection)[matFrom]->OpticalOverrides[matTo] = ovLocal; accept(); @@ -91,17 +108,23 @@ void AOpticalOverrideDialog::on_pbAccept_clicked() void AOpticalOverrideDialog::on_pbCancel_clicked() { + clearOpenedExcept(ovLocal); delete ovLocal; ovLocal = 0; reject(); } void AOpticalOverrideDialog::on_cobType_activated(int index) { - delete ovLocal; ovLocal = 0; + if (ovLocal) openedOVs << ovLocal; + ovLocal = 0; if (index != 0) - ovLocal = OpticalOverrideFactory(ui->cobType->currentText(), MatCollection, matFrom, matTo); - + { + QString selectedType = ui->cobType->currentText(); + ovLocal = findInOpended(selectedType); + if (!ovLocal) + ovLocal = OpticalOverrideFactory(ui->cobType->currentText(), MatCollection, matFrom, matTo); + } updateGui(); } diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.h b/src/gui/MainWindowTools/aopticaloverridedialog.h index 1ab7544a..7cdc523c 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.h +++ b/src/gui/MainWindowTools/aopticaloverridedialog.h @@ -3,6 +3,7 @@ #include #include +#include namespace Ui { class AOpticalOverrideDialog; @@ -44,7 +45,11 @@ private slots: int customWidgetPositionInLayout = 5; QWidget* customWidget = 0; + QSet openedOVs; + void updateGui(); + AOpticalOverride* findInOpended(const QString& ovType); + void clearOpenedExcept(AOpticalOverride* keepOV); }; #endif // AOPTICALOVERRIDEDIALOG_H From c0dd8f8070b0b686844e0024bcdcc8f9cc2dd867 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 6 Oct 2018 00:55:12 +0100 Subject: [PATCH 049/140] ++ --- src/OpticalOverrides/abasicopticaloverride.cpp | 2 ++ src/OpticalOverrides/awaveshifteroverride.cpp | 2 ++ src/OpticalOverrides/spectralbasicopticaloverride.cpp | 3 --- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OpticalOverrides/abasicopticaloverride.cpp b/src/OpticalOverrides/abasicopticaloverride.cpp index 5d0dc054..b79f51cc 100644 --- a/src/OpticalOverrides/abasicopticaloverride.cpp +++ b/src/OpticalOverrides/abasicopticaloverride.cpp @@ -239,6 +239,8 @@ QWidget *ABasicOpticalOverride::getEditWidget(QWidget*, GraphWindowClass *) const QString ABasicOpticalOverride::checkOverrideData() { + if (scatterModel<0 || scatterModel>2) return "Invalid scatter model"; + if (probLoss<0 || probLoss>1.0) return "Absorption probability should be within [0, 1.0]"; if (probRef <0 || probRef >1.0) return "Reflection probability should be within [0, 1.0]"; if (probDiff<0 || probDiff>1.0) return "Scattering probability should be within [0, 1.0]"; diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 3919fe1a..71e31b6e 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -411,6 +411,8 @@ void AWaveshifterOverride::updateButtons() const QString AWaveshifterOverride::checkOverrideData() { + if (ReemissionModel<0 || ReemissionModel>2) return "Invalid reemission model"; + if (ReemissionProbability_lambda.isEmpty()) return "Reemission probability not loaded"; if (ReemissionProbability_lambda.size() != ReemissionProbability.size()) diff --git a/src/OpticalOverrides/spectralbasicopticaloverride.cpp b/src/OpticalOverrides/spectralbasicopticaloverride.cpp index fb68408a..4f3aa982 100644 --- a/src/OpticalOverrides/spectralbasicopticaloverride.cpp +++ b/src/OpticalOverrides/spectralbasicopticaloverride.cpp @@ -332,8 +332,5 @@ const QString SpectralBasicOpticalOverride::checkOverrideData() } if (scatterModel < 0 || scatterModel > 2) return "unknown scattering model"; - //TODO check effective wavelength - //TODO check binned - return ""; } From 08afa1a5893fcb4561901546dff0f360143b47d2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 6 Oct 2018 12:29:49 +0100 Subject: [PATCH 050/140] sim abort updated; show true on sim finished; sim destructors updated --- src/common/atracerstateful.cpp | 6 ++ src/common/atracerstateful.h | 2 + src/gui/aremotewindow.cpp | 1 + src/gui/mainwindow.cpp | 35 +++---- src/gui/mainwindow.h | 2 + src/gui/mainwindow.ui | 12 ++- src/gui/reconstructionwindow.cpp | 27 +++--- src/gui/reconstructionwindow.h | 2 +- src/modules/aphotontracer.cpp | 10 +- src/modules/aphotontracer.h | 4 + src/modules/simulationmanager.cpp | 147 ++++++++++++++---------------- src/modules/simulationmanager.h | 33 +++---- 12 files changed, 142 insertions(+), 139 deletions(-) diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index 7f1b9584..28e4c2c3 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -54,3 +54,9 @@ void ATracerStateful::generateScriptInfrastructure(const AMaterialParticleCollec val = ScriptEngine->newQObject(mathInterface, QScriptEngine::QtOwnership); ScriptEngine->globalObject().setProperty(mathInterface->objectName(), val); } + +void ATracerStateful::abort() +{ + if (ScriptEngine) + ScriptEngine->abortEvaluation(); +} diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h index 107cf205..f07195e4 100644 --- a/src/common/atracerstateful.h +++ b/src/common/atracerstateful.h @@ -25,6 +25,8 @@ class ATracerStateful void generateScriptInfrastructure(const AMaterialParticleCollection *MPcollection); //can be use from outside to force generation (e.g. interface tester); RandGen should already be set! + void abort(); + TRandom2 * RandGen = 0; QScriptEngine * ScriptEngine = 0; AOpticalOverrideScriptInterface* overrideInterface = 0; diff --git a/src/gui/aremotewindow.cpp b/src/gui/aremotewindow.cpp index 1ca99b67..dd026df4 100644 --- a/src/gui/aremotewindow.cpp +++ b/src/gui/aremotewindow.cpp @@ -202,6 +202,7 @@ void ARemoteWindow::on_pbSimulate_clicked() MW->Owindow->RefreshData(); MW->Rwindow->OnEventsDataAdded(); + MW->Rwindow->ShowPositions(1, true); } void ARemoteWindow::on_pbReconstruct_clicked() diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 6752e89e..49b64f92 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -3782,6 +3782,7 @@ void MainWindow::simulationFinished() { //qDebug() << "---------Simulation finished. Events:"<Events.size(); ui->pbStopScan->setEnabled(false); + ui->pbStopScan->setText("stop"); if (!SimulationManager->fSuccess) { @@ -3789,37 +3790,20 @@ void MainWindow::simulationFinished() ui->leEventsPerSec->setText("n.a."); QString report = SimulationManager->Runner->getErrorMessages(); if (report != "Simulation stopped by user") message(report, this); - //ClearData(); - if (GeometryWindow->isVisible()) GeometryWindow->ShowGeometry(false); } bool showTracks = false; if (SimulationManager->LastSimType == 0) //PointSources sim { - //showTracks = ui->cbPointSourceBuildTracks->isChecked(); showTracks = SimulationManager->TrackBuildOptions.bBuildPhotonTracks; clearGeoMarkers(); - GeoMarkers = SimulationManager->GeoMarkers; - SimulationManager->GeoMarkers.clear(); //to avoid delete content - - if (ui->twSingleScan->currentIndex() == 0) - { - //info on last photon - APhoton& ph = SimulationManager->LastPhoton; - QString str; - QTextStream strBuilder(&str); - strBuilder<<" Position xyz[mm]: "<cbWaveResolved->isChecked()) strBuilder<<" Wavelength index = "<cbTimeResolved->isChecked()) strBuilder<<" Emission time: "<OutText("Last Photon info:\n"+str); + Rwindow->ShowPositions(1, true); + if (ui->twSingleScan->currentIndex() == 0 && SimulationManager->fSuccess) if (EventsDataHub->Events.size() == 1) Owindow->SiPMpixels = SimulationManager->SiPMpixels; - } } if (SimulationManager->LastSimType == 1) //ParticleSources sim { - //showTracks = ui->cbGunParticleTracks->isChecked() || ui->cbGunPhotonTracks->isChecked(); showTracks = SimulationManager->TrackBuildOptions.bBuildParticleTracks || SimulationManager->TrackBuildOptions.bBuildPhotonTracks; clearEnergyVector(); EnergyVector = SimulationManager->EnergyVector; @@ -3856,7 +3840,7 @@ void MainWindow::simulationFinished() if (GeometryWindow->isVisible()) { GeometryWindow->ShowGeometry(false); - if (showTracks) MainWindow::ShowTracks(); + if (showTracks) GeometryWindow->DrawTracks(); } //qDebug() << "==>After sim: OnEventsDataLoadOrClear"; Rwindow->OnEventsDataAdded(); @@ -4010,12 +3994,14 @@ void MainWindow::RefreshPhotSimOnTimer(int Progress, double msPerEv) ui->leEventsPerSec->setText( (msPerEv==0) ? "n.a." : QString::number(msPerEv, 'g', 4)); qApp->processEvents(); + /* if (ui->pbStopScan->isChecked()) { //emit StopRequested(); SimulationManager->StopSimulation(); return; } + */ } void MainWindow::on_pbGDML_clicked() @@ -4976,3 +4962,12 @@ void MainWindow::on_pbShowOverrideMap_clicked() OptOvDialogPosition = d->pos(); delete d; } + +void MainWindow::on_pbStopScan_clicked() +{ + //qDebug() << "Requesting sim stop..."; + ui->pbStopScan->setText("stopping..."); + qApp->processEvents(); + SimulationManager->StopSimulation(); + qApp->processEvents(); +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 1b576572..0be99768 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -606,6 +606,8 @@ private slots: void on_pbShowOverrideMap_clicked(); + void on_pbStopScan_clicked(); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index fda7bc0a..8a44be01 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -6771,7 +6771,7 @@ thermal neutrons: 4 13 - 341 + 307 16 @@ -6788,12 +6788,16 @@ thermal neutrons: - 350 - 11 - 51 + 316 + 10 + 81 21 + + First click attempts to stop simulation in soft mode: the already simulated events will be available for analysis. +Second click will trigger strong abort mode, which will result in loss of all simulated data. + Qt::LeftToRight diff --git a/src/gui/reconstructionwindow.cpp b/src/gui/reconstructionwindow.cpp index 7e4df834..da3431f6 100644 --- a/src/gui/reconstructionwindow.cpp +++ b/src/gui/reconstructionwindow.cpp @@ -329,21 +329,25 @@ void ReconstructionWindow::on_pbClearPositions_clicked() void ReconstructionWindow::on_pbShowReconstructionPositions_clicked() { - ShowPositions(0); + QString err = ShowPositions(0); + if (!err.isEmpty()) + message(err, this); } void ReconstructionWindow::on_pbShowTruePositions_clicked() { - ShowPositions(1); + QString err = ShowPositions(1); + if (!err.isEmpty()) + message(err, this); } -void ReconstructionWindow::ShowPositions(int Rec_True, bool fOnlyIfWindowVisible) +const QString ReconstructionWindow::ShowPositions(int Rec_True, bool fOnlyIfWindowVisible) { - if (fOnlyIfWindowVisible && !MW->GeometryWindow->isVisible()) return; + if (fOnlyIfWindowVisible && !MW->GeometryWindow->isVisible()) return ""; if (Rec_True<0 || Rec_True>1) { qWarning() << "Wrong index in ShowPositions"; - return; + return ""; } int CurrentGroup = PMgroups->getCurrentGroup(); @@ -354,21 +358,13 @@ void ReconstructionWindow::ShowPositions(int Rec_True, bool fOnlyIfWindowVisible if (Rec_True == 0) { int CurrentGroup = PMgroups->getCurrentGroup(); - if (!fRecReady) - { - message("Reconstruction not ready!", this); - return; - } + if (!fRecReady) return "Reconstruction not ready!"; numEvents = EventsDataHub->ReconstructionData[CurrentGroup].size(); marks = new GeoMarkerClass("Recon", 6, 2, kRed); } else if (Rec_True == 1) { - if (EventsDataHub->isScanEmpty()) - { - message("There are no true positions available!", this); - return; - } + if (EventsDataHub->isScanEmpty()) return "There are no data to show!"; numEvents = EventsDataHub->Scan.size(); marks = new GeoMarkerClass("Scan", 6, 2, kBlue); } @@ -435,6 +431,7 @@ void ReconstructionWindow::ShowPositions(int Rec_True, bool fOnlyIfWindowVisible MW->GeometryWindow->activateWindow(); MW->GeometryWindow->ShowGeometry(false); MW->ShowTracks(); + return ""; } /* diff --git a/src/gui/reconstructionwindow.h b/src/gui/reconstructionwindow.h index bb5b31b9..0c15e3db 100644 --- a/src/gui/reconstructionwindow.h +++ b/src/gui/reconstructionwindow.h @@ -627,7 +627,7 @@ public slots: void onKNNreadyXchanged(bool ready, int events); void onKNNreadyYchanged(bool ready, int events); - void ShowPositions(int Rec_True, bool fOnlyIfWindowVisible = false); + const QString ShowPositions(int Rec_True, bool fOnlyIfWindowVisible = false); signals: void cbReconstructEnergyChanged(bool changed); diff --git a/src/modules/aphotontracer.cpp b/src/modules/aphotontracer.cpp index 75d7322e..53ef62f5 100644 --- a/src/modules/aphotontracer.cpp +++ b/src/modules/aphotontracer.cpp @@ -55,7 +55,8 @@ void APhotonTracer::configure(const GeneralSimSettings *simSet, AOneEvent* oneEv } void APhotonTracer::TracePhoton(const APhoton* Photon) -{ +{ + if (bAbort) return; //qDebug() << "----accel is on?"<fQEaccelerator<< "Build tracks?"<fQEaccelerator) @@ -237,6 +238,7 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) const double* PhPos = navigator->GetCurrentPoint(); for (int i=0; i<3; i++) p->r[i] = PhPos[i]; AOpticalOverride::OpticalOverrideResultEnum result = ov->calculate(*ResourcesForOverrides, p, N); + if (bAbort) return; switch (result) { @@ -420,6 +422,12 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) //qDebug() << "Track size:" <size(); } +void APhotonTracer::hardAbort() +{ + bAbort = true; + ResourcesForOverrides->abort(); //if script engine is there will abort evaluation +} + void APhotonTracer::AppendHistoryRecord() { bool bVeto = false; diff --git a/src/modules/aphotontracer.h b/src/modules/aphotontracer.h index c2913c4a..908398dd 100644 --- a/src/modules/aphotontracer.h +++ b/src/modules/aphotontracer.h @@ -40,6 +40,8 @@ class APhotonTracer void setMaxTracks(int maxTracks) {MaxTracks = maxTracks;} + void hardAbort(); //before using it, give a chance to finish normally using abort at higher levels + private: TRandom2* RandGen; TGeoManager* GeoManager; @@ -79,6 +81,8 @@ class APhotonTracer QString nameFrom; QString nameTo; + bool bAbort = false; + enum AbsRayEnum {AbsRayNotTriggered=0, AbsTriggered, RayTriggered, WaveShifted}; inline AbsRayEnum AbsorptionAndRayleigh(); inline double CalculateReflectionCoefficient(); diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index aabea100..4d1ad752 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -241,6 +241,13 @@ bool ASimulatorRunner::wasSuccessful() const return fOK; } +bool ASimulatorRunner::wasHardAborted() const +{ + for(const Simulator * sim : workers) + if (sim->wasHardAborted()) return true; + return false; +} + QString ASimulatorRunner::getErrorMessages() const { QString msg; @@ -402,12 +409,13 @@ Simulator::~Simulator() { delete photonTracker; delete photonGenerator; - delete OneEvent; - dataHub->Events.resize(0); - dataHub->TimedEvents.resize(0); - dataHub->Scan.resize(0); delete dataHub; + delete OneEvent; delete RandGen; + + //if transferred, the container will be cleared, need cleaning only in case of abort + for (TrackHolderClass* t : tracks) delete t; + tracks.clear(); } void Simulator::updateGeoManager() @@ -432,7 +440,17 @@ void Simulator::setRngSeed(int seed) void Simulator::requestStop() { - fStopRequested = true; + if (fStopRequested) + { + //qDebug() << "Simulator recived repeated stop request, aborting in hard mode"; + hardAbort(); + fHardAbortWasTriggered = true; + } + else + { + //qDebug() << "First stop request was received by simulator"; + fStopRequested = true; + } } void Simulator::divideThreadWork(int threadId, int threadCount) @@ -462,7 +480,6 @@ void Simulator::divideThreadWork(int threadId, int threadCount) bool Simulator::setup(QJsonObject &json) { fUpdateGUI = json["DoGuiUpdate"].toBool(); - //fBuildPhotonTracks = fUpdateGUI && simSettings->fBuildPhotonTracks; fBuildPhotonTracks = fUpdateGUI && simSettings->TrackBuildOptions.bBuildPhotonTracks; //inits @@ -478,11 +495,17 @@ bool Simulator::setup(QJsonObject &json) void Simulator::appendToDataHub(EventsDataClass *dataHub) { - dataHub->Events << this->dataHub->Events; - dataHub->TimedEvents << this->dataHub->TimedEvents; - dataHub->Scan << this->dataHub->Scan; + dataHub->Events << this->dataHub->Events; //static + dataHub->TimedEvents << this->dataHub->TimedEvents; //static + dataHub->Scan << this->dataHub->Scan; //dynamic! + this->dataHub->Scan.clear(); + + dataHub->SimStat->AppendSimulationStatistics(this->dataHub->SimStat); //deep copy +} - dataHub->SimStat->AppendSimulationStatistics(this->dataHub->SimStat); +void Simulator::hardAbort() +{ + photonTracker->hardAbort(); } void Simulator::ReserveSpace(int expectedNumEvents) @@ -505,13 +528,11 @@ PointSourceSimulator::PointSourceSimulator(const DetectorClass *detector, int ID { CustomHist = 0; totalEventCount = 0; - DotsTGeo = new QVector(); } PointSourceSimulator::~PointSourceSimulator() { if (CustomHist) delete CustomHist; - delete DotsTGeo; } int PointSourceSimulator::getEventCount() const @@ -528,7 +549,6 @@ bool PointSourceSimulator::setup(QJsonObject &json) return false; } if(!Simulator::setup(json)) return false; - if (fUpdateGUI) DotsTGeo->clear(); QJsonObject js = json["PointSourcesConfig"].toObject(); //reading main control options @@ -705,6 +725,7 @@ void PointSourceSimulator::simulate() { ReserveSpace(getEventCount()); fStopRequested = false; + fHardAbortWasTriggered = false; switch (PointSimMode) { case 0: fSuccess = SimulateSingle(); break; @@ -713,6 +734,7 @@ void PointSourceSimulator::simulate() case 3: fSuccess = SimulateCustomNodes(); break; default: fSuccess = false; break; } + if (fHardAbortWasTriggered) fSuccess = false; } void PointSourceSimulator::appendToDataHub(EventsDataClass *dataHub) @@ -746,7 +768,6 @@ bool PointSourceSimulator::SimulateSingle() progress = irun * updateFactor; if(fStopRequested) return false; } - if (fUpdateGUI) addLastScanPointToMarkers(); return true; } @@ -833,7 +854,6 @@ bool PointSourceSimulator::SimulateRegularGrid() progress = eventCurrent * updateFactor; if(fStopRequested) return false; } - if (fUpdateGUI) addLastScanPointToMarkers(false); currentNode++; if(currentNode >= eventEnd) return true; } @@ -924,7 +944,6 @@ bool PointSourceSimulator::SimulateFlood() progress = eventCurrent * updateFactor; if(fStopRequested) return false; } - if (fUpdateGUI) addLastScanPointToMarkers(); } return true; } @@ -974,7 +993,6 @@ bool PointSourceSimulator::SimulateCustomNodes() progress = eventCurrent * updateFactor; if(fStopRequested) return false; } - if (fUpdateGUI) addLastScanPointToMarkers(); currentNode++; } return true; @@ -1320,8 +1338,6 @@ void PointSourceSimulator::doLRFsimulatedEvent(double *r) ss->Points[0].r[2] = r[2]; ss->Points[0].energy = numPhots; dataHub->Scan.append(ss); - - if (fUpdateGUI) DotsTGeo->append(DotsTGeoStruct(r)); } void PointSourceSimulator::GenerateFromSecond(AScanRecord *scs) @@ -1361,16 +1377,6 @@ void PointSourceSimulator::ReserveSpace(int expectedNumEvents) //if (fUpdateGUI) DotsTGeo->reserve(expectedNumEvents); //no need anymore, they are limited in size now to 1000 entries } -void PointSourceSimulator::addLastScanPointToMarkers(bool fLimitNumber) //we do not want to limit for scan, can confuse the user -{ - if (dataHub->Scan.isEmpty()) return; - if (fLimitNumber && DotsTGeo->size()>1000) return; /// *** absolute number! - - AScanRecord* sc = dataHub->Scan.last(); - for (int i=0; iPoints.size(); i++) - DotsTGeo->append(DotsTGeoStruct(sc->Points[i].r)); -} - /******************************************************************************\ * Particle Source Simulator | \******************************************************************************/ @@ -1404,11 +1410,9 @@ ParticleSourceSimulator::~ParticleSourceSimulator() delete ParticleTracker; delete ParticleSources; clearParticleStack(); - if (EnergyVector.size() > 0) - { - for (int i = 0; i < EnergyVector.size(); i++) delete EnergyVector[i]; - EnergyVector.resize(0); - } + + for (int i = 0; i < EnergyVector.size(); i++) delete EnergyVector[i]; + EnergyVector.clear(); } bool ParticleSourceSimulator::setup(QJsonObject &json) @@ -1497,6 +1501,7 @@ void ParticleSourceSimulator::simulate() ReserveSpace(getEventCount()); fStopRequested = false; + fHardAbortWasTriggered = false; //Simulation double updateFactor = 100.0 / ( eventEnd - eventBegin ); @@ -1591,7 +1596,7 @@ void ParticleSourceSimulator::simulate() progress = (eventCurrent - eventBegin + 1) * updateFactor; } //all events finished - fSuccess = true; + fSuccess = !fHardAbortWasTriggered; } void ParticleSourceSimulator::appendToDataHub(EventsDataClass *dataHub) @@ -1815,18 +1820,11 @@ void ASimulationManager::onSimFailedToStart() void ASimulationManager::Clear() { - clearGeoMarkers(); clearEnergyVector(); clearTracks(); SiPMpixels.clear(); } -void ASimulationManager::clearGeoMarkers() -{ - for (int i=0; iwasSuccessful(); + fHardAborted = Runner->wasHardAborted(); - //in Raimundo's code on simulation fail workers were not cleared! - ASimulationManager::Clear(); + ASimulationManager::Clear(); //data clear containers if (Runner->modeSetup == "PointSim") LastSimType = 0; //was Point sources sim else if (Runner->modeSetup == "SourceSim") LastSimType = 1; //was Particle sources sim else LastSimType = -1; QVector simulators = Runner->getWorkers(); - if (!simulators.isEmpty()) - { + if (!simulators.isEmpty() && !fHardAborted) + { if (LastSimType == 0) - { + { PointSourceSimulator *lastPointSrcSimulator = static_cast< PointSourceSimulator *>(simulators.last()); EventsDataHub->ScanNumberOfRuns = lastPointSrcSimulator->getNumRuns(); - LastPhoton = *lastPointSrcSimulator->getLastPhotonOnStart(); - if (fStartedFromGui) - { - for (int i = 0; i < simulators.count(); i++) - { - const PointSourceSimulator *simulator = static_cast(simulators[i]); - const QVector* dots = simulator->getDotsTGeo(); - GeoMarkerClass* marks = new GeoMarkerClass("Nodes", 6, 2, kBlack); - for (int i=0; isize(); i++) - marks->SetNextPoint(dots->at(i).r[0], dots->at(i).r[1], dots->at(i).r[2]); - GeoMarkers.append(marks); - } - SiPMpixels = lastPointSrcSimulator->getLastEvent()->SiPMpixels; //only makes sense if there was only 1 event - } - } - if (LastSimType == 1) - { - ParticleSourceSimulator *lastPartSrcSimulator = static_cast< ParticleSourceSimulator *>(simulators.last()); - EnergyVector = lastPartSrcSimulator->getEnergyVector(); - lastPartSrcSimulator->ClearEnergyVectorButKeepObjects(); // to avoid clearing the energy vector cells - } + if (fStartedFromGui) SiPMpixels = lastPointSrcSimulator->getLastEvent()->SiPMpixels; //only makes sense if there was only 1 event + } + else if (LastSimType == 1) + { + ParticleSourceSimulator *lastPartSrcSimulator = static_cast< ParticleSourceSimulator *>(simulators.last()); + EnergyVector = lastPartSrcSimulator->getEnergyVector(); + lastPartSrcSimulator->ClearEnergyVectorButKeepObjects(); // to avoid clearing the energy vector cells + } - for(int iSim = 0; iSimtracks; - simulators[iSim]->tracks.clear(); - } - } + for (Simulator * sim : simulators) + { + Tracks += sim->tracks; + sim->tracks.clear(); //to avoid delete objects on simulator delete + } + } //Raimundo's comment: This is part of a hack. Check this function declaration in .h for more details. Runner->clearWorkers(); - //before was limited to the mode whenlocations are limited to a certain object in the detector geometry - //scan and custom nodes might have nodes outside of the limiting object - they are still present but marked with 1e10 X and Y true coordinates - EventsDataHub->purge1e10events(); //purging events with "true" positions x==1e10 && y==1e10 + if (fHardAborted) + EventsDataHub->clear(); //data are not valid! + else + { + //before was limited to the mode whenlocations are limited to a certain object in the detector geometry + //scan and custom nodes might have nodes outside of the limiting object - they are still present but marked with 1e10 X and Y true coordinates + EventsDataHub->purge1e10events(); //purging events with "true" positions x==1e10 && y==1e10 + } Detector->BuildDetector(); - //Detector->Config->UpdateSimSettingsOfDetector(); //inside the rebuild now - emit SimulationFinished(); - ASimulationManager::Clear(); //clear tmp data - if needed, main window has copied all needed in the slot on SimulationFinished() //qDebug() << "SimManager: Sim finished"; } diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 01b0996e..78404c74 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -59,6 +59,7 @@ class ASimulationManager : public QObject bool fFinished; bool fSuccess; + bool fHardAborted; bool fStartedFromGui; int LastSimType; // -1 - undefined, 0 - PointSources, 1 - ParticleSources @@ -66,9 +67,7 @@ class ASimulationManager : public QObject int MaxThreads = -1; //info to report back - APhoton LastPhoton; QVector< QBitArray > SiPMpixels; - QVector GeoMarkers; QVector EnergyVector; QVector Tracks; @@ -82,7 +81,6 @@ class ASimulationManager : public QObject EventsDataClass* EventsDataHub; //alias DetectorClass* Detector; //alias - void clearGeoMarkers(); void clearEnergyVector(); void clearTracks(); @@ -118,6 +116,7 @@ class ASimulatorRunner : public QObject double getProgress() const { return progress; } //double getmsPerEvent() const { return usPerEvent; } bool wasSuccessful() const; + bool wasHardAborted() const; bool isFinished() const {return simState == SFinished;} void setFinished() {simState = SFinished;} QString getErrorMessages() const; @@ -194,7 +193,8 @@ class Simulator virtual int getTotalEventCount() const = 0; const AOneEvent *getLastEvent() const { return OneEvent; } - bool wasSuccessful() const { return fSuccess; } + bool wasSuccessful() const { return (fSuccess && !fHardAbortWasTriggered); } + bool wasHardAborted() const { return fHardAbortWasTriggered; } virtual void updateGeoManager(); void setSimSettings(const GeneralSimSettings *settings); void initSimStat(); @@ -206,21 +206,24 @@ class Simulator virtual void simulate() = 0; virtual void appendToDataHub(EventsDataClass *dataHub); + virtual void hardAbort(); + protected: virtual void ReserveSpace(int expectedNumEvents); int evenDivisionOfLabor(int totalEventCount); virtual void updateMaxTracks(int maxPhotonTracks, int maxParticleTracks); - const DetectorClass *detector; - TRandom2 *RandGen; - AOneEvent* OneEvent; //PM hit data for one event is stored here - EventsDataClass *dataHub; - Photon_Generator *photonGenerator; + const DetectorClass *detector; // external + const GeneralSimSettings *simSettings; // external + TRandom2 *RandGen; // local + AOneEvent* OneEvent; // local //PM hit data for one event is stored here + EventsDataClass *dataHub; // local + Photon_Generator *photonGenerator; // local + APhotonTracer* photonTracker; // local + QString ErrorString; //last error int ID; - APhotonTracer* photonTracker; - //state control int eventBegin; int eventCurrent; //to be updated by implementor, or override getEventsDone() @@ -231,9 +234,7 @@ class Simulator bool fBuildPhotonTracks; bool fStopRequested; //Implementors must check whenever possible (without impacting performance) to stop simulation() bool fSuccess; //Implementors should set this flag at end of simulation() - - //general simulation options - const GeneralSimSettings *simSettings; + bool fHardAbortWasTriggered; private: }; @@ -251,8 +252,6 @@ class PointSourceSimulator : public Simulator virtual void simulate(); virtual void appendToDataHub(EventsDataClass *dataHub); - const QVector *getDotsTGeo() const { return DotsTGeo; } - const APhoton *getLastPhotonOnStart() const { return &PhotonOnStart; } int getNumRuns() const {return NumRuns;} private: @@ -271,11 +270,9 @@ class PointSourceSimulator : public Simulator void GenerateFromSecond(AScanRecord *scs); bool isInsideLimitingObject(double *r); virtual void ReserveSpace(int expectedNumEvents); - void addLastScanPointToMarkers(bool fLimitNumber = true); QJsonObject simOptions; TH1I *CustomHist; //custom photon generation distribution - QVector *DotsTGeo; APhoton PhotonOnStart; //properties of the photon which are used to initiate Photon_Tracker From 07fc79bbe50d04a3f2b90c0786d415f40db6b4c8 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 6 Oct 2018 17:13:25 +0100 Subject: [PATCH 051/140] ++ --- src/common/atracerstateful.cpp | 7 ++---- src/common/atracerstateful.h | 8 +++---- .../aopticaloverridedialog.cpp | 1 + src/gui/mainwindow.cpp | 23 +++++++++++-------- src/gui/mainwindow.h | 4 ++-- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/common/atracerstateful.cpp b/src/common/atracerstateful.cpp index 28e4c2c3..f00db907 100644 --- a/src/common/atracerstateful.cpp +++ b/src/common/atracerstateful.cpp @@ -14,11 +14,8 @@ ATracerStateful::ATracerStateful(TRandom2 *RandGen) : RandGen(RandGen) {} ATracerStateful::~ATracerStateful() { delete ScriptEngine; ScriptEngine = 0; - if (overrideInterface) - { - qDebug() << "Deleting ov script interface"; - delete overrideInterface; - } + delete overrideInterface; overrideInterface = 0; + delete mathInterface; mathInterface = 0; } void ATracerStateful::evaluateScript(const QString &Script) diff --git a/src/common/atracerstateful.h b/src/common/atracerstateful.h index f07195e4..6e8220ec 100644 --- a/src/common/atracerstateful.h +++ b/src/common/atracerstateful.h @@ -27,10 +27,10 @@ class ATracerStateful void abort(); - TRandom2 * RandGen = 0; - QScriptEngine * ScriptEngine = 0; - AOpticalOverrideScriptInterface* overrideInterface = 0; - AMathScriptInterface* mathInterface = 0; + TRandom2 * RandGen = 0; //external + QScriptEngine * ScriptEngine = 0; //local + AOpticalOverrideScriptInterface* overrideInterface = 0; //local + AMathScriptInterface* mathInterface = 0; //local }; #endif // ATRACERSTATEFUL_H diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 3425609b..4749e38d 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -41,6 +41,7 @@ AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * Mat AOpticalOverrideDialog::~AOpticalOverrideDialog() { + delete TesterWindow; delete ui; } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 49b64f92..3807e0c4 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -726,17 +726,20 @@ void MainWindow::on_pbEditOverride_clicked() int From = ui->cobMaterialForOverrides->currentIndex(); int To = ui->cobMaterialTo->currentIndex(); - AOpticalOverrideDialog d(MpCollection, From, To, GraphWindow, GeometryWindow, this); - int res = d.exec(); - if (res == 1) - { - ReconstructDetector(true); + AOpticalOverrideDialog* d = new AOpticalOverrideDialog(MpCollection, From, To, GraphWindow, GeometryWindow, this); + d->setAttribute(Qt::WA_DeleteOnClose); + d->setWindowModality(Qt::WindowModal); + QObject::connect(d, &AOpticalOverrideDialog::accepted, this, &MainWindow::onOpticalOverrideDialogAccepted); + d->show(); +} - on_pbRefreshOverrides_clicked(); - int i = ui->lwMaterials->currentRow(); - UpdateMaterialListEdit(); //to update (*) status - ui->lwMaterials->setCurrentRow(i); - } +void MainWindow::onOpticalOverrideDialogAccepted() +{ + ReconstructDetector(true); + on_pbRefreshOverrides_clicked(); + int i = ui->lwMaterials->currentRow(); + UpdateMaterialListEdit(); //to update (*) status + ui->lwMaterials->setCurrentRow(i); } void MainWindow::on_pbRefreshOverrides_clicked() diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 0be99768..a6338c83 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -639,8 +639,8 @@ public slots: void OnWarningMessage(QString text); void OnDetectorColorSchemeChanged(int scheme, int matId); void OnSlabDoubleClicked(QString SlabName); - void onNewConfigLoaded(); - + void onNewConfigLoaded(); + void onOpticalOverrideDialogAccepted(); signals: void RequestStopLoad(); }; From 877ea5e37bd2e8dfb7488e6e4c6f5b0fbc1b8f85 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 6 Oct 2018 21:45:07 +0100 Subject: [PATCH 052/140] ++ --- src/gui/MainWindowTools/MainWindowMenu.cpp | 7 +++ .../aopticaloverridedialog.cpp | 43 ++++++++++++------- .../MainWindowTools/aopticaloverridedialog.h | 16 +++---- .../aopticaloverridetester.cpp | 30 ++++++++++--- .../MainWindowTools/aopticaloverridetester.h | 25 +++++------ src/gui/mainwindow.cpp | 7 +-- src/gui/mainwindow.h | 3 ++ src/gui/windownavigatorclass.cpp | 2 + 8 files changed, 86 insertions(+), 47 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowMenu.cpp b/src/gui/MainWindowTools/MainWindowMenu.cpp index d5c89708..20e82dee 100644 --- a/src/gui/MainWindowTools/MainWindowMenu.cpp +++ b/src/gui/MainWindowTools/MainWindowMenu.cpp @@ -131,6 +131,9 @@ void MainWindow::on_actionReset_position_of_windows_triggered() } bOptOvDialogPositioned = false; + + OvTesterSettings["PositionX"] = -1; + OvTesterSettings["PositionY"] = -1; } void addWindow(QString name, QMainWindow* w, QJsonObject &json) @@ -194,6 +197,8 @@ void MainWindow::on_actionSave_position_and_stratus_of_all_windows_triggered() jsOD["h"] = OptOvDialogSize.height(); json["OptOvDialog"] = jsOD; + json["OptOvTester"] = OvTesterSettings; + //QString configDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)+"/ants2"; //if (!QDir(configDir).exists()) QDir().mkdir(configDir); QString fileName = GlobSet.ConfigDir + "/WindowConfig.ini"; @@ -276,6 +281,8 @@ void MainWindow::on_actionLoad_positions_and_status_of_all_windows_triggered() OptOvDialogSize = QSize(w, h); bOptOvDialogPositioned = true; } + + parseJson(json, "OptOvTester", OvTesterSettings); } } diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 4749e38d..aa52a567 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -1,6 +1,7 @@ #include "aopticaloverridedialog.h" #include "ui_aopticaloverridedialog.h" #include "aopticaloverride.h" +#include "mainwindow.h" #include "amaterialparticlecolection.h" #include "amessage.h" #include "aopticaloverridetester.h" @@ -11,37 +12,38 @@ #include #include -AOpticalOverrideDialog::AOpticalOverrideDialog(AMaterialParticleCollection * MatCollection, int matFrom, int matTo, - GraphWindowClass * GraphWindow, GeometryWindowClass *GeometryWindow, QWidget * parent) : - QDialog(parent), ui(new Ui::AOpticalOverrideDialog), GraphWindow(GraphWindow), GeometryWindow(GeometryWindow), - MatCollection(MatCollection), matFrom(matFrom), matTo(matTo), matNames(MatCollection->getListOfMaterialNames()) +AOpticalOverrideDialog::AOpticalOverrideDialog(MainWindow *MW, int matFrom, int matTo) : + QDialog(MW), ui(new Ui::AOpticalOverrideDialog), MW(MW), + matFrom(matFrom), matTo(matTo) { ui->setupUi(this); ui->pbInterceptorForEnter->setVisible(false); ui->pbInterceptorForEnter->setDefault(true); setWindowTitle("Photon tracing rules for material interface"); + QStringList matNames = MW->MpCollection->getListOfMaterialNames(); ui->leMatFrom->setText(matNames.at(matFrom)); ui->leMatTo->setText(matNames.at(matTo)); ui->cobType->addItem("No special rule"); QStringList avOv = ListOvAllOpticalOverrideTypes(); ui->cobType->addItems(avOv); - AOpticalOverride* ov = (*MatCollection)[matFrom]->OpticalOverrides[matTo]; + AOpticalOverride* ov = (*MW->MpCollection)[matFrom]->OpticalOverrides[matTo]; if (ov) { - ovLocal = OpticalOverrideFactory( ov->getType(), MatCollection, matFrom, matTo); + ovLocal = OpticalOverrideFactory( ov->getType(), MW->MpCollection, matFrom, matTo ); QJsonObject json; ov->writeToJson(json); ovLocal->readFromJson(json); } updateGui(); - TesterWindow = new AOpticalOverrideTester(&ovLocal, GraphWindow, GeometryWindow, MatCollection, matFrom, matTo, this); + TesterWindow = new AOpticalOverrideTester(&ovLocal, MW, matFrom, matTo, this); + TesterWindow->readFromJson(MW->OvTesterSettings); } AOpticalOverrideDialog::~AOpticalOverrideDialog() { - delete TesterWindow; + //TesterWindow is saved and deleted on CloseEvent delete ui; } @@ -64,7 +66,7 @@ void AOpticalOverrideDialog::updateGui() ui->cobType->setCurrentIndex(index+1); QVBoxLayout* l = static_cast(layout()); - customWidget = ovLocal->getEditWidget(this, GraphWindow); + customWidget = ovLocal->getEditWidget(this, MW->GraphWindow); l->insertWidget(customWidgetPositionInLayout, customWidget); } else @@ -102,16 +104,27 @@ void AOpticalOverrideDialog::on_pbAccept_clicked() clearOpenedExcept(ovLocal); - delete (*MatCollection)[matFrom]->OpticalOverrides[matTo]; - (*MatCollection)[matFrom]->OpticalOverrides[matTo] = ovLocal; - accept(); + delete (*MW->MpCollection)[matFrom]->OpticalOverrides[matTo]; + (*MW->MpCollection)[matFrom]->OpticalOverrides[matTo] = ovLocal; + ovLocal = 0; + close(); } void AOpticalOverrideDialog::on_pbCancel_clicked() { - clearOpenedExcept(ovLocal); + close(); +} + +void AOpticalOverrideDialog::closeEvent(QCloseEvent *e) +{ + clearOpenedExcept(ovLocal); //to avoid double-delete delete ovLocal; ovLocal = 0; - reject(); + + TesterWindow->writeToJson(MW->OvTesterSettings); + TesterWindow->hide(); + delete TesterWindow; TesterWindow = 0; + + QDialog::closeEvent(e); } void AOpticalOverrideDialog::on_cobType_activated(int index) @@ -124,7 +137,7 @@ void AOpticalOverrideDialog::on_cobType_activated(int index) QString selectedType = ui->cobType->currentText(); ovLocal = findInOpended(selectedType); if (!ovLocal) - ovLocal = OpticalOverrideFactory(ui->cobType->currentText(), MatCollection, matFrom, matTo); + ovLocal = OpticalOverrideFactory(ui->cobType->currentText(), MW->MpCollection, matFrom, matTo); } updateGui(); } diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.h b/src/gui/MainWindowTools/aopticaloverridedialog.h index 7cdc523c..1b63cbf8 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.h +++ b/src/gui/MainWindowTools/aopticaloverridedialog.h @@ -10,9 +10,7 @@ class AOpticalOverrideDialog; } class AOpticalOverride; -class AMaterialParticleCollection; -class GraphWindowClass; -class GeometryWindowClass; +class MainWindow; class AOpticalOverrideTester; class AOpticalOverrideDialog : public QDialog @@ -20,8 +18,7 @@ class AOpticalOverrideDialog : public QDialog Q_OBJECT public: - explicit AOpticalOverrideDialog(AMaterialParticleCollection* MatCollection, int matFrom, int matTo, - GraphWindowClass* GraphWindow, GeometryWindowClass* GeometryWindow, QWidget* parent); + explicit AOpticalOverrideDialog(MainWindow* MW, int matFrom, int matTo); ~AOpticalOverrideDialog(); private slots: @@ -30,16 +27,15 @@ private slots: void on_cobType_activated(int index); void on_pbTestOverride_clicked(); +protected: + void closeEvent(QCloseEvent* e); + private: Ui::AOpticalOverrideDialog * ui; - GraphWindowClass * GraphWindow; - GeometryWindowClass* GeometryWindow; - AOpticalOverride ** pOV; + MainWindow* MW; AOpticalOverride * ovLocal = 0; - AMaterialParticleCollection* MatCollection; int matFrom; int matTo; - QStringList matNames; //need? AOpticalOverrideTester* TesterWindow; int customWidgetPositionInLayout = 5; diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 40080c7f..cd54bdac 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -1,5 +1,6 @@ #include "aopticaloverridetester.h" #include "ui_aopticaloverridetester.h" +#include "mainwindow.h" #include "amessage.h" #include "amaterialparticlecolection.h" #include "aopticaloverride.h" @@ -10,6 +11,7 @@ #include "geometrywindowclass.h" #include "asimulationstatistics.h" #include "atrackrecords.h" +#include "ajsontools.h" #include #include @@ -28,15 +30,13 @@ static QVector tracks; static TVector3 NormViz; -AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, - GraphWindowClass* GraphWindow, GeometryWindowClass* GeometryWindow, - AMaterialParticleCollection* MPcollection, int matFrom, int matTo, QWidget *parent) : +AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, MainWindow *MW, int matFrom, int matTo, QWidget *parent) : QMainWindow(parent), ui(new Ui::AOpticalOverrideTester), - MPcollection(MPcollection), MatFrom(matFrom), MatTo(matTo), - pOV(ovLocal), - GraphWindow(GraphWindow), GeometryWindow(GeometryWindow) + pOV(ovLocal), MatFrom(matFrom), MatTo(matTo), MW(MW), + MPcollection(MW->MpCollection), GraphWindow(MW->GraphWindow), GeometryWindow(MW->GeometryWindow) { ui->setupUi(this); + setWindowTitle("Override tester"); QDoubleValidator* dv = new QDoubleValidator(this); dv->setNotation(QDoubleValidator::ScientificNotation); @@ -45,7 +45,7 @@ AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, RandGen = new TRandom2(); Resources = new ATracerStateful(RandGen); - Resources->generateScriptInfrastructure(MPcollection); + Resources->generateScriptInfrastructure(MW->MpCollection); } AOpticalOverrideTester::~AOpticalOverrideTester() @@ -55,6 +55,22 @@ AOpticalOverrideTester::~AOpticalOverrideTester() delete ui; } +void AOpticalOverrideTester::writeToJson(QJsonObject &json) const +{ + json["PositionX"] = x(); + json["PositionY"] = y(); +} + +void AOpticalOverrideTester::readFromJson(const QJsonObject &json) +{ + if (json.isEmpty()) return; + + int x, y; + parseJson(json, "PositionX", x); + parseJson(json, "PositionY", y); + if (x>0 && y>0) move(x, y); +} + void AOpticalOverrideTester::on_pbDirectionHelp_clicked() { QString s = "Vectors are not necessary normalized to unity (automatic when used)\n\n" diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 3da1de37..284dad8f 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -11,41 +11,42 @@ class AOpticalOverrideTester; class AMaterialParticleCollection; class AOpticalOverride; +class MainWindow; class GraphWindowClass; class GeometryWindowClass; class TRandom2; +class QJsonObject; class AOpticalOverrideTester : public QMainWindow { Q_OBJECT public: - explicit AOpticalOverrideTester(AOpticalOverride ** ovLocal, GraphWindowClass *GraphWindow, GeometryWindowClass* GeometryWindow, AMaterialParticleCollection *MPcollection, int matFrom, int matTo, QWidget *parent = 0); + explicit AOpticalOverrideTester(AOpticalOverride ** ovLocal, MainWindow* MW, int matFrom, int matTo, QWidget *parent = 0); ~AOpticalOverrideTester(); + void writeToJson(QJsonObject& json) const; + void readFromJson(const QJsonObject& json); + private slots: void on_pbDirectionHelp_clicked(); - void on_pbST_RvsAngle_clicked(); - void on_pbCSMtestmany_clicked(); - void on_pbST_showTracks_clicked(); - void on_pbST_uniform_clicked(); - void on_pbST_AngleCos_clicked(); private: Ui::AOpticalOverrideTester *ui; - AMaterialParticleCollection* MPcollection; + AOpticalOverride ** pOV; //external int MatFrom; int MatTo; - AOpticalOverride ** pOV; - GraphWindowClass* GraphWindow; - GeometryWindowClass* GeometryWindow; - TRandom2* RandGen; - ATracerStateful* Resources; + MainWindow* MW; //external + AMaterialParticleCollection* MPcollection; //external + GraphWindowClass* GraphWindow; //external + GeometryWindowClass* GeometryWindow; //external + TRandom2* RandGen; //local + ATracerStateful* Resources; //loacl bool testOverride(); }; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 3807e0c4..07fc1379 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -201,12 +201,12 @@ void MainWindow::clearEnergyVector() EnergyVector.clear(); } -void MainWindow::closeEvent(QCloseEvent *event) +void MainWindow::closeEvent(QCloseEvent *) { qDebug() << "\nisBusy() || !SimulationManager->fFinished) if (timesTriedToExit < 6) { @@ -220,6 +220,7 @@ void MainWindow::closeEvent(QCloseEvent *event) event->ignore(); return; } + */ ui->pbAddparticleToActive->setFocus(); //to finish editing whatever QLineEdit the user can be in - they call on_editing_finish @@ -726,7 +727,7 @@ void MainWindow::on_pbEditOverride_clicked() int From = ui->cobMaterialForOverrides->currentIndex(); int To = ui->cobMaterialTo->currentIndex(); - AOpticalOverrideDialog* d = new AOpticalOverrideDialog(MpCollection, From, To, GraphWindow, GeometryWindow, this); + AOpticalOverrideDialog* d = new AOpticalOverrideDialog(this, From, To); d->setAttribute(Qt::WA_DeleteOnClose); d->setWindowModality(Qt::WindowModal); QObject::connect(d, &AOpticalOverrideDialog::accepted, this, &MainWindow::onOpticalOverrideDialogAccepted); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index a6338c83..1c5b1af3 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -7,6 +7,7 @@ #include #include #include +#include // forward declarations class AConfiguration; @@ -392,6 +393,8 @@ private slots: bool fSimDataNotSaved = false; + QJsonObject OvTesterSettings; + void createScriptWindow(); void SimGeneralConfigToJson(QJsonObject &jsonMaster); //Save to JSON general options of simulation diff --git a/src/gui/windownavigatorclass.cpp b/src/gui/windownavigatorclass.cpp index 4b49d70d..412724c1 100644 --- a/src/gui/windownavigatorclass.cpp +++ b/src/gui/windownavigatorclass.cpp @@ -277,6 +277,8 @@ void WindowNavigatorClass::BusyOn() emit BusyStatusChanged(true); time->restart(); + + qApp->processEvents(); } void WindowNavigatorClass::BusyOff(bool fShowTime) From bc8d326ffe6552f6235a4e7df85ed5a63f4a4f51 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 6 Oct 2018 22:08:23 +0100 Subject: [PATCH 053/140] ++ --- .../aopticaloverridedialog.cpp | 4 +- .../aopticaloverridetester.cpp | 17 ++- .../MainWindowTools/aopticaloverridetester.h | 3 + .../MainWindowTools/aopticaloverridetester.ui | 108 +++++++++++------- 4 files changed, 84 insertions(+), 48 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index aa52a567..e736ed0c 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -107,12 +107,12 @@ void AOpticalOverrideDialog::on_pbAccept_clicked() delete (*MW->MpCollection)[matFrom]->OpticalOverrides[matTo]; (*MW->MpCollection)[matFrom]->OpticalOverrides[matTo] = ovLocal; ovLocal = 0; - close(); + accept(); } void AOpticalOverrideDialog::on_pbCancel_clicked() { - close(); + reject(); } void AOpticalOverrideDialog::closeEvent(QCloseEvent *e) diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index cd54bdac..00347994 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -46,6 +46,8 @@ AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, Main RandGen = new TRandom2(); Resources = new ATracerStateful(RandGen); Resources->generateScriptInfrastructure(MW->MpCollection); + + updateWavelengthIndication(); } AOpticalOverrideTester::~AOpticalOverrideTester() @@ -261,7 +263,7 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() QString::number(1.0*lobe/sum, 'g', 3) + "/" + QString::number(1.0*lamb/sum, 'g', 3) + ")"; } - ui->leST_out->setText(str); + //ui->leST_out->setText(str); delete ph.SimStat; } @@ -343,6 +345,17 @@ bool AOpticalOverrideTester::testOverride() return true; } +void AOpticalOverrideTester::updateWavelengthIndication() +{ + if ( !MPcollection->IsWaveResolved() ) + { + ui->cbWavelength->setEnabled(false); + ui->cbWavelength->setChecked(false); + } + else + ui->cbWavelength->setEnabled(true); +} + void AOpticalOverrideTester::on_pbST_uniform_clicked() { if ( !testOverride() ) return; @@ -425,7 +438,7 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() QString::number(1.0*lobe/sum, 'g', 3) + "/" + QString::number(1.0*lamb/sum, 'g', 3) + ")"; } - ui->leST_out->setText(str); + //ui->leST_out->setText(str); delete ph.SimStat; } diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 284dad8f..0a049e9a 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -49,6 +49,9 @@ private slots: ATracerStateful* Resources; //loacl bool testOverride(); + +private slots: + void updateWavelengthIndication(); }; #endif // AOPTICALOVERRIDETESTER_H diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index 9cb2c16f..f73f4fcc 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -6,8 +6,8 @@ 0 0 - 401 - 369 + 424 + 466 @@ -280,17 +280,30 @@ - - - Photon wavelength: + + + Qt::Horizontal - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 40 + 20 + + + + + + + + Photon wavelength: + + false + 75 @@ -309,19 +322,6 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -329,7 +329,7 @@ - Refractive index + Refractive index: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -337,7 +337,7 @@ - + from: @@ -347,7 +347,7 @@ - 75 + 50 16777215 @@ -357,7 +357,7 @@ - + to: @@ -370,7 +370,7 @@ - 75 + 50 16777215 @@ -379,6 +379,13 @@ + + + + (a -> b) + + + @@ -410,25 +417,18 @@ - Reflection vs angle of incidence + Processes vs angle of incidence - + 75 true - - Trace photons - - - - - Lambertian distribution for incoming photons! @@ -438,18 +438,21 @@ - - - Absorption/Spike/Lobe/Lambert: counts and fractions + + + + + + + 75 + true + - - Qt::AlignCenter + + Trace photons - - - @@ -507,12 +510,29 @@ 0 0 - 401 + 424 21 - + + + cbWavelength + toggled(bool) + ledST_wave + setEnabled(bool) + + + 268 + 132 + + + 369 + 129 + + + + From 33bc07542dc6bd4dbe93d7cb5ca8cf1a82d2f43b Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 6 Oct 2018 22:45:15 +0100 Subject: [PATCH 054/140] ++ --- .../aopticaloverridedialog.cpp | 4 ++ .../aopticaloverridetester.cpp | 45 ++++++++++++++----- .../MainWindowTools/aopticaloverridetester.h | 9 +++- .../MainWindowTools/aopticaloverridetester.ui | 17 ++++++- src/modules/amaterialparticlecolection.cpp | 12 ++++- src/modules/amaterialparticlecolection.h | 3 +- 6 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index e736ed0c..5c5958ce 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -28,6 +28,9 @@ AOpticalOverrideDialog::AOpticalOverrideDialog(MainWindow *MW, int matFrom, int QStringList avOv = ListOvAllOpticalOverrideTypes(); ui->cobType->addItems(avOv); + MW->MpCollection->UpdateWaveResolvedProperties(matFrom); + MW->MpCollection->UpdateWaveResolvedProperties(matTo); + AOpticalOverride* ov = (*MW->MpCollection)[matFrom]->OpticalOverrides[matTo]; if (ov) { @@ -145,4 +148,5 @@ void AOpticalOverrideDialog::on_cobType_activated(int index) void AOpticalOverrideDialog::on_pbTestOverride_clicked() { TesterWindow->show(); + TesterWindow->updateIndication(); } diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 00347994..3b83b378 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -47,7 +47,29 @@ AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, Main Resources = new ATracerStateful(RandGen); Resources->generateScriptInfrastructure(MW->MpCollection); - updateWavelengthIndication(); + QStringList matNames = MW->MpCollection->getListOfMaterialNames(); + ui->labMaterials->setText( QString("(%1 -> %2)").arg(matNames.at(matFrom)).arg(matNames.at(matTo)) ); + + updateIndication(); +} + +void AOpticalOverrideTester::updateIndication() +{ + bool bWR = MPcollection->IsWaveResolved(); + if (!bWR) + { + ui->cbWavelength->setEnabled(false); + ui->cbWavelength->setChecked(false); + } + else + ui->cbWavelength->setEnabled(true); + + int waveIndex = -1; + if (ui->cbWavelength->isChecked()) + waveIndex = MPcollection->WaveToIndex( ui->ledST_wave->text().toDouble() ); // always in [0, WaveNodes-1] + + ui->ledST_Ref1->setText( QString::number( (*MPcollection)[MatFrom]->getRefractiveIndex(waveIndex) ) ); + ui->ledST_Ref2->setText( QString::number( (*MPcollection)[MatTo] ->getRefractiveIndex(waveIndex) ) ); } AOpticalOverrideTester::~AOpticalOverrideTester() @@ -345,17 +367,6 @@ bool AOpticalOverrideTester::testOverride() return true; } -void AOpticalOverrideTester::updateWavelengthIndication() -{ - if ( !MPcollection->IsWaveResolved() ) - { - ui->cbWavelength->setEnabled(false); - ui->cbWavelength->setChecked(false); - } - else - ui->cbWavelength->setEnabled(true); -} - void AOpticalOverrideTester::on_pbST_uniform_clicked() { if ( !testOverride() ) return; @@ -457,3 +468,13 @@ void AOpticalOverrideTester::on_pbST_AngleCos_clicked() ui->pbST_AngleCos->setText("Theta="+QString::number(ang, 'g', 3)+" cos="+QString::number(cos, 'g', 3)); } + +void AOpticalOverrideTester::on_cbWavelength_toggled(bool) +{ + updateIndication(); +} + +void AOpticalOverrideTester::on_ledST_wave_editingFinished() +{ + updateIndication(); +} diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 0a049e9a..43f81b13 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -28,6 +28,9 @@ class AOpticalOverrideTester : public QMainWindow void writeToJson(QJsonObject& json) const; void readFromJson(const QJsonObject& json); +public slots: + void updateIndication(); + private slots: void on_pbDirectionHelp_clicked(); void on_pbST_RvsAngle_clicked(); @@ -36,6 +39,10 @@ private slots: void on_pbST_uniform_clicked(); void on_pbST_AngleCos_clicked(); + void on_cbWavelength_toggled(bool checked); + + void on_ledST_wave_editingFinished(); + private: Ui::AOpticalOverrideTester *ui; AOpticalOverride ** pOV; //external @@ -50,8 +57,6 @@ private slots: bool testOverride(); -private slots: - void updateWavelengthIndication(); }; #endif // AOPTICALOVERRIDETESTER_H diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index f73f4fcc..ffce490e 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -75,6 +75,9 @@ + + false + 0 @@ -120,6 +123,9 @@ + + false + 0 @@ -165,6 +171,9 @@ + + false + 1 @@ -311,7 +320,7 @@ - 176 + 450 @@ -354,6 +363,9 @@ 1.69 + + true + @@ -377,6 +389,9 @@ 1.66 + + true + diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index b77a3d38..eaf79f0a 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -896,7 +896,7 @@ void AMaterialParticleCollection::OnRequestListOfParticles(QStringList &definedP definedParticles << ParticleCollection.at(i)->ParticleName; } -void AMaterialParticleCollection::IsParticleInUse(int particleId, bool &bInUse, QString& MaterialNames) +void AMaterialParticleCollection::IsParticleInUse(int particleId, bool &bInUse, QString& MaterialNames) const { bInUse = false; MaterialNames.clear(); @@ -946,3 +946,13 @@ void AMaterialParticleCollection::RemoveParticle(int particleId) delete ParticleCollection[particleId]; ParticleCollection.remove(particleId); } + +int AMaterialParticleCollection::WaveToIndex(double wavelength) const +{ + if (!WavelengthResolved) return -1; + + int iwave = round( (wavelength - WaveFrom) / WaveStep ); + if (iwave >= WaveNodes) iwave = WaveNodes-1; + if (iwave < 0) iwave = 0; + return iwave; +} diff --git a/src/modules/amaterialparticlecolection.h b/src/modules/amaterialparticlecolection.h index 6bd6436d..a83fbf5f 100644 --- a/src/modules/amaterialparticlecolection.h +++ b/src/modules/amaterialparticlecolection.h @@ -107,8 +107,9 @@ class AMaterialParticleCollection : public QObject //if not in range, the first material index with such a problem is returned. // -1 is returned if there are no errors - void IsParticleInUse(int particleId, bool& bInUse, QString &MaterialNames); + void IsParticleInUse(int particleId, bool& bInUse, QString &MaterialNames) const; void RemoveParticle(int particleId); // should NOT be used directly - use RemoveParticle method of AConfiguration + int WaveToIndex(double wavelength) const; private: int ConflictingMaterialIndex; //used by CheckMaterial function From ed578b283d3b77757a1eefb8f36523a2642299c2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 7 Oct 2018 11:29:46 +0100 Subject: [PATCH 055/140] ++ --- .../aopticaloverridedialog.cpp | 2 +- .../aopticaloverridetester.cpp | 156 +++++-- .../MainWindowTools/aopticaloverridetester.h | 14 +- .../MainWindowTools/aopticaloverridetester.ui | 398 +++++++++--------- src/gui/graphwindowclass.cpp | 37 +- src/gui/graphwindowclass.h | 5 +- src/modules/aphotontracer.cpp | 6 +- 7 files changed, 339 insertions(+), 279 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 5c5958ce..899b2328 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -148,5 +148,5 @@ void AOpticalOverrideDialog::on_cobType_activated(int index) void AOpticalOverrideDialog::on_pbTestOverride_clicked() { TesterWindow->show(); - TesterWindow->updateIndication(); + TesterWindow->updateGUI(); } diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 3b83b378..2423c9b7 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -28,7 +28,6 @@ #include "TVirtualGeoTrack.h" static QVector tracks; -static TVector3 NormViz; AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, MainWindow *MW, int matFrom, int matTo, QWidget *parent) : QMainWindow(parent), ui(new Ui::AOpticalOverrideTester), @@ -50,10 +49,12 @@ AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, Main QStringList matNames = MW->MpCollection->getListOfMaterialNames(); ui->labMaterials->setText( QString("(%1 -> %2)").arg(matNames.at(matFrom)).arg(matNames.at(matTo)) ); - updateIndication(); + updateGUI(); + + showGeometry(); } -void AOpticalOverrideTester::updateIndication() +void AOpticalOverrideTester::updateGUI() { bool bWR = MPcollection->IsWaveResolved(); if (!bWR) @@ -70,6 +71,15 @@ void AOpticalOverrideTester::updateIndication() ui->ledST_Ref1->setText( QString::number( (*MPcollection)[MatFrom]->getRefractiveIndex(waveIndex) ) ); ui->ledST_Ref2->setText( QString::number( (*MPcollection)[MatTo] ->getRefractiveIndex(waveIndex) ) ); + + TVector3 photon(ui->ledST_i->text().toDouble(), ui->ledST_j->text().toDouble(), ui->ledST_k->text().toDouble()); + photon = photon.Unit(); + //vector surface normal + TVector3 normal(ui->ledST_si->text().toDouble(), ui->ledST_sj->text().toDouble(), ui->ledST_sk->text().toDouble()); + normal = normal.Unit(); + double cos = photon * normal; + double ang = 180.0 / TMath::Pi() * acos(cos); + ui->ledAngle->setText( QString::number(ang, 'g', 4) ); } AOpticalOverrideTester::~AOpticalOverrideTester() @@ -98,9 +108,10 @@ void AOpticalOverrideTester::readFromJson(const QJsonObject &json) void AOpticalOverrideTester::on_pbDirectionHelp_clicked() { QString s = "Vectors are not necessary normalized to unity (automatic when used)\n\n" - "Note that in overrides caluclations" - "normal of the surface is always oriented" - "in the direction away from the incoming photon"; + "Note that in override caluclations\n" + "normal of the surface is always oriented\n" + "in the same direction as the one of the incoming photon!\n"; + message(s, this); } void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() @@ -189,8 +200,6 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() ui->ledST_sj->text().toDouble(), ui->ledST_sk->text().toDouble()); SurfNorm = SurfNorm.Unit(); - NormViz = SurfNorm; //visualization of tracks - SurfNorm = - SurfNorm; //In ANTS2 navigator provides normal in the opposite direction double N[3]; N[0] = SurfNorm.X(); N[1] = SurfNorm.Y(); @@ -202,9 +211,8 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() tracks.clear(); double d = 0.5; //offset - for drawing only - tracks.append(TrackHolderClass(10, kRed)); //incoming photon track - tracks.last().Nodes.append(TrackNodeStruct(d, d ,d, 0)); - tracks.last().Nodes.append(TrackNodeStruct(d-PhotDir.X(), d-PhotDir.Y(), d-PhotDir.Z(), 0)); + + //preparing and running cycle with photons int abs, spike, lobe, lamb; @@ -262,12 +270,10 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() double costr = -SurfNorm[0]*ph.v[0] -SurfNorm[1]*ph.v[1] -SurfNorm[2]*ph.v[2]; - if (fDegrees) hist1->Fill(180.0/3.1415926535*acos(costr)); + if (fDegrees) hist1->Fill(180.0 / TMath::Pi() * acos(costr)); else hist1->Fill(costr); } - qDebug() << "Here!"; - //show cos angle hist GraphWindow->Draw(hist1); //show tracks @@ -289,39 +295,64 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() delete ph.SimStat; } -void AOpticalOverrideTester::on_pbST_showTracks_clicked() +void AOpticalOverrideTester::showGeometry() { - if (tracks.isEmpty()) return; - int selector = ui->cobST_trackType->currentIndex() - 1; - if (selector == 3) return; //do not show any tracks - gGeoManager->ClearTracks(); GeometryWindow->ClearRootCanvas(); - //showing surface - Int_t track_index = gGeoManager->AddTrack(1,22); - TVirtualGeoTrack* track = gGeoManager->GetTrack(track_index); + double d = 0.5; double f = 0.5; //surface normal + TVector3 SurfNorm(ui->ledST_si->text().toDouble(), + ui->ledST_sj->text().toDouble(), + ui->ledST_sk->text().toDouble()); + SurfNorm = SurfNorm.Unit(); + int track_index = gGeoManager->AddTrack(1,22); + TVirtualGeoTrack* track = gGeoManager->GetTrack(track_index); track->AddPoint(d, d, d, 0); - track->AddPoint(d+NormViz.X(), d+NormViz.Y(), d+NormViz.Z(), 0); + track->AddPoint(d + SurfNorm.X(), d + SurfNorm.Y(), d + SurfNorm.Z(), 0); track->SetLineWidth(3); + track->SetLineStyle(2); track->SetLineColor(1); - //surf - track_index = gGeoManager->AddTrack(1,22); + + //surface + track_index = gGeoManager->AddTrack(1, 22); track = gGeoManager->GetTrack(track_index); - TVector3 perp = NormViz.Orthogonal(); - perp.Rotate(0.25*3.1415926535, NormViz); + TVector3 perp = SurfNorm.Orthogonal(); + perp.Rotate(0.25 * TMath::Pi(), SurfNorm); for (int i=0; i<5; i++) { - track->AddPoint(d+f*perp.X(), d+f*perp.Y(), d+f*perp.Z(), 0); - perp.Rotate(0.5*3.1415926535, NormViz); + track->AddPoint(d + f * perp.X(), d + f * perp.Y(), d + f * perp.Z(), 0); + perp.Rotate(0.5 * TMath::Pi(), SurfNorm); } - track->SetLineWidth(2); + track->SetLineWidth(3); track->SetLineColor(1); - //photon tracks + //intitial photon track + track_index = gGeoManager->AddTrack(1, 10); + track = gGeoManager->GetTrack(track_index); + track->AddPoint(d, d, d, 0); + TVector3 PhotDir(ui->ledST_i->text().toDouble(), + ui->ledST_j->text().toDouble(), + ui->ledST_k->text().toDouble()); + PhotDir = PhotDir.Unit(); + track->AddPoint(d-PhotDir.X(), d-PhotDir.Y(), d-PhotDir.Z(), 0); + track->SetLineColor(kRed); + track->SetLineWidth(3); + + GeometryWindow->show(); + GeometryWindow->DrawTracks(); +} + +void AOpticalOverrideTester::on_pbST_showTracks_clicked() +{ + showGeometry(); + + if (tracks.isEmpty()) return; + int selector = ui->cobST_trackType->currentIndex() - 1; + if (selector == 3) return; //do not show any tracks + int numTracks = 0; for(int i = 1; i-1) //-1 - show all if (selector != th->UserIndex) continue; - track_index = gGeoManager->AddTrack(1,22); - track = gGeoManager->GetTrack(track_index); + int track_index = gGeoManager->AddTrack(1,22); + TVirtualGeoTrack* track = gGeoManager->GetTrack(track_index); track->SetLineColor(th->Color); track->SetLineWidth(1); for (int iNode=0; iNodeNodes.size(); iNode++) track->AddPoint(th->Nodes[iNode].R[0], th->Nodes[iNode].R[1], th->Nodes[iNode].R[2], th->Nodes[iNode].Time); } - //intitial photon track - track_index = gGeoManager->AddTrack(1,22); - track = gGeoManager->GetTrack(track_index); - TrackHolderClass* th = &tracks.first(); - track->SetLineColor(kRed); - track->SetLineWidth(2); - for (int iNode=0; iNodeNodes.size(); iNode++) - track->AddPoint(th->Nodes[iNode].R[0], th->Nodes[iNode].R[1], th->Nodes[iNode].R[2], th->Nodes[iNode].Time); GeometryWindow->show(); GeometryWindow->DrawTracks(); @@ -375,7 +398,6 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() ui->ledST_sj->text().toDouble(), ui->ledST_sk->text().toDouble()); SurfNorm = SurfNorm.Unit(); - SurfNorm = - SurfNorm; //In ANTS2 navigator provides normal in the opposite direction double N[3]; N[0] = SurfNorm.X(); N[1] = SurfNorm.Y(); @@ -453,6 +475,7 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() delete ph.SimStat; } +/* void AOpticalOverrideTester::on_pbST_AngleCos_clicked() { //vector photon dir @@ -468,13 +491,58 @@ void AOpticalOverrideTester::on_pbST_AngleCos_clicked() ui->pbST_AngleCos->setText("Theta="+QString::number(ang, 'g', 3)+" cos="+QString::number(cos, 'g', 3)); } +*/ void AOpticalOverrideTester::on_cbWavelength_toggled(bool) { - updateIndication(); + updateGUI(); } void AOpticalOverrideTester::on_ledST_wave_editingFinished() { - updateIndication(); + updateGUI(); +} + +void AOpticalOverrideTester::on_ledST_i_editingFinished() +{ + updateGUI(); + showGeometry(); +} + +void AOpticalOverrideTester::on_ledST_j_editingFinished() +{ + updateGUI(); + showGeometry(); +} + +void AOpticalOverrideTester::on_ledST_k_editingFinished() +{ + if (ui->ledST_k->text().toDouble() >= 0) + { + ui->ledST_k->setText("-1"); + message("The photon direction vector along Z axis should be neagtive!", this); + } + updateGUI(); + showGeometry(); +} + +void AOpticalOverrideTester::on_ledAngle_editingFinished() +{ + double angle = ui->ledAngle->text().toDouble(); + if (angle <= -90.0 || angle >= 90.0 ) + { + ui->ledAngle->setText("45"); + message("Angle should be within (-90, 90) degrees!", this); + angle = 45.0; + } + + TVector3 photon(0, 0, -1.0); + TVector3 perp(0, 1.0, 0); + angle *= -TMath::Pi() / 180.0; + photon.Rotate(angle, perp); + ui->ledST_i->setText( QString::number( photon.x(), 'g', 6) ); + ui->ledST_j->setText( QString::number( photon.y(), 'g', 6) ); + ui->ledST_k->setText( QString::number( photon.z(), 'g', 6) ); + + showGeometry(); } diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 43f81b13..3140a5a1 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -29,20 +29,30 @@ class AOpticalOverrideTester : public QMainWindow void readFromJson(const QJsonObject& json); public slots: - void updateIndication(); + void updateGUI(); private slots: + void showGeometry(); + void on_pbDirectionHelp_clicked(); void on_pbST_RvsAngle_clicked(); void on_pbCSMtestmany_clicked(); void on_pbST_showTracks_clicked(); void on_pbST_uniform_clicked(); - void on_pbST_AngleCos_clicked(); + //void on_pbST_AngleCos_clicked(); void on_cbWavelength_toggled(bool checked); void on_ledST_wave_editingFinished(); + void on_ledST_i_editingFinished(); + + void on_ledST_j_editingFinished(); + + void on_ledST_k_editingFinished(); + + void on_ledAngle_editingFinished(); + private: Ui::AOpticalOverrideTester *ui; AOpticalOverride ** pOV; //external diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index ffce490e..41c08deb 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -15,6 +15,199 @@ + + + + + + Number of photons: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 1000000 + + + 1000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Photon wavelength: + + + + + + + false + + + + 75 + 16777215 + + + + 450 + + + + + + + nm + + + + + + + + + + + Refractive index: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + from: + + + + + + + + 50 + 16777215 + + + + 1.69 + + + true + + + + + + + to: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + 16777215 + + + + 1.66 + + + true + + + + + + + (a -> b) + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + 75 + true + + + + Processes vs angle of incidence + + + + + + + + 75 + true + + + + Lambertian distribution for incoming photons! + + + Diffuse irradiation test + + + + + + + Qt::Horizontal + + + @@ -175,7 +368,7 @@ false - 1 + -1 false @@ -225,9 +418,9 @@ - + - Set angle to + Angle of incidence: @@ -266,195 +459,6 @@ - - - - - - Number of photons: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 1000000 - - - 1000 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Photon wavelength: - - - - - - - false - - - - 75 - 16777215 - - - - 450 - - - - - - - nm - - - - - - - - - - - Refractive index: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - from: - - - - - - - - 50 - 16777215 - - - - 1.69 - - - true - - - - - - - to: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 50 - 16777215 - - - - 1.66 - - - true - - - - - - - (a -> b) - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - - - - - - 75 - true - - - - Processes vs angle of incidence - - - - - - - - 75 - true - - - - Lambertian distribution for incoming photons! - - - Diffuse irradiation test - - - - - - @@ -518,6 +522,16 @@ + + + + Qt::Horizontal + + + + + + diff --git a/src/gui/graphwindowclass.cpp b/src/gui/graphwindowclass.cpp index 8f0cf609..e24e3bb4 100644 --- a/src/gui/graphwindowclass.cpp +++ b/src/gui/graphwindowclass.cpp @@ -684,28 +684,6 @@ void GraphWindowClass::switchOffBasket() ui->cbShowBasket->setChecked(false); } -void GraphWindowClass::resizeEvent(QResizeEvent *) -{ - //tool bar box height and basket fit the window - //ui->fUIbox->resize(ui->fUIbox->width(), this->height() - 24 - 3); - //ui->fBasket->resize(ui->fBasket->width(), this->height()); - //ui->lwBasket->resize(ui->lwBasket->width(), this->height()-ui->lwBasket->y()-3); - - //int deltaBasket = 0; - //if (ui->cbShowBasket->isChecked()) deltaBasket = ui->fBasket->width(); - - //int width = this->width() - (3 + ui->fUIbox->width()) - deltaBasket; - //int height = this->height() - (3 + 3); -// qDebug()<menuBar) mh = ui->menuBar->height(); - //if (RasterWindow) RasterWindow->setGeometry(ui->fUIbox->x() + ui->fUIbox->width()+3, mh, width, height); - //if (RasterWindow) RasterWindow->ForceResize(); - - //if (ui->cbShowBasket->isChecked()) ui->fBasket->move(this->width()-3-ui->fBasket->width(), 0); -} - void GraphWindowClass::mouseMoveEvent(QMouseEvent *event) { if(RasterWindow->isVisible()) @@ -3495,19 +3473,9 @@ void GraphWindowClass::on_pbAttributes_clicked() RasterWindow->fCanvas->SetLineAttributes(); } -void GraphWindowClass::on_actionToggle_toolbar_toggled(bool arg1) +void GraphWindowClass::on_actionToggle_toolbar_triggered(bool checked) { - if (arg1) - { - BarShown = false; - ui->fUIbox->resize(150,500); - } - else - { - BarShown = true; - ui->fUIbox->resize(0,500); - } - GraphWindowClass::resizeEvent(0); + ui->fUIbox->setVisible(checked); } void GraphWindowClass::on_actionEqualize_scale_XY_triggered() @@ -3809,3 +3777,4 @@ void GraphWindowClass::on_ledAngle_customContextMenuRequested(const QPoint &pos) selBoxControlsUpdated(); } } + diff --git a/src/gui/graphwindowclass.h b/src/gui/graphwindowclass.h index 951b8f89..f2c6965d 100644 --- a/src/gui/graphwindowclass.h +++ b/src/gui/graphwindowclass.h @@ -158,7 +158,6 @@ class GraphWindowClass : public QMainWindow void SetStatPanelVisible(bool flag); protected: - void resizeEvent(QResizeEvent *event); void mouseMoveEvent(QMouseEvent *event); bool event(QEvent *event); void closeEvent(QCloseEvent *event); @@ -243,7 +242,6 @@ private slots: void on_actionSide_triggered(); void on_actionFront_triggered(); void on_pbAttributes_clicked(); - void on_actionToggle_toolbar_toggled(bool arg1); void on_pbDensityDistribution_clicked(); void on_actionEqualize_scale_XY_triggered(); void on_ledRulerDX_editingFinished(); @@ -258,6 +256,8 @@ private slots: void on_ledAngle_customContextMenuRequested(const QPoint &pos); + void on_actionToggle_toolbar_triggered(bool checked); + private: Ui::GraphWindowClass *ui; MainWindow *MW; @@ -284,7 +284,6 @@ private slots: //flags bool TMPignore = false; //temporarily forbid updates - need for bulk update to avoid cross-modification - bool BarShown; bool ColdStart = true; bool fFirstTime = false; //signals that "UnZoom" range values (xmin0, etc...) have to be stored diff --git a/src/modules/aphotontracer.cpp b/src/modules/aphotontracer.cpp index 53ef62f5..2f88ca98 100644 --- a/src/modules/aphotontracer.cpp +++ b/src/modules/aphotontracer.cpp @@ -246,7 +246,7 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) //qDebug() << "-Override: absorption triggered"; navigator->PopDummy(); //clean up the stack if (SimSet->bDoPhotonHistoryLog) - PhLog.append( APhotonHistoryLog(navigator->GetCurrentPoint(), nameFrom, p->time, p->waveIndex, APhotonHistoryLog::Override_Loss, MatIndexFrom, MatIndexTo) ); + PhLog.append( APhotonHistoryLog(PhPos, nameFrom, p->time, p->waveIndex, APhotonHistoryLog::Override_Loss, MatIndexFrom, MatIndexTo) ); OneEvent->SimStat->OverrideLoss++; goto force_stop_tracing; //finished with this photon case AOpticalOverride::Back: @@ -254,14 +254,14 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) navigator->PopPoint(); //remaining in the original volume navigator->SetCurrentDirection(p->v); //updating direction if (SimSet->bDoPhotonHistoryLog) - PhLog.append( APhotonHistoryLog(navigator->GetCurrentPoint(), nameFrom, p->time, p->waveIndex, APhotonHistoryLog::Override_Back, MatIndexFrom, MatIndexTo) ); + PhLog.append( APhotonHistoryLog(PhPos, nameFrom, p->time, p->waveIndex, APhotonHistoryLog::Override_Back, MatIndexFrom, MatIndexTo) ); OneEvent->SimStat->OverrideBack++; continue; //send to the next iteration case AOpticalOverride::Forward: navigator->SetCurrentDirection(p->v); //updating direction fDoFresnel = false; //stack cleaned afterwards if (SimSet->bDoPhotonHistoryLog) - PhLog.append( APhotonHistoryLog(navigator->GetCurrentPoint(), nameTo, p->time, p->waveIndex, APhotonHistoryLog::Override_Forward, MatIndexFrom, MatIndexTo) ); + PhLog.append( APhotonHistoryLog(PhPos, nameTo, p->time, p->waveIndex, APhotonHistoryLog::Override_Forward, MatIndexFrom, MatIndexTo) ); OneEvent->SimStat->OverrideForward++; break; //switch break case AOpticalOverride::NotTriggered: From cce99951d4782fc540147592b7ca6b66035524f5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 7 Oct 2018 11:30:21 +0100 Subject: [PATCH 056/140] ++ --- .../aopticaloverridetester.cpp | 26 +++---------------- .../MainWindowTools/aopticaloverridetester.h | 1 - .../MainWindowTools/aopticaloverridetester.ui | 11 +++++++- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 2423c9b7..91ece79d 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -107,10 +107,10 @@ void AOpticalOverrideTester::readFromJson(const QJsonObject &json) void AOpticalOverrideTester::on_pbDirectionHelp_clicked() { - QString s = "Vectors are not necessary normalized to unity (automatic when used)\n\n" - "Note that in override caluclations\n" - "normal of the surface is always oriented\n" - "in the same direction as the one of the incoming photon!\n"; + QString s = "Vectors are not necessary normalized to unity (automatically scaled)\n\n" + "Note that in override caluclations the normal vector of the surface\n" + "is provided in such a way that the dot product of the normal and\n" + "the incoming photon direction is positive."; message(s, this); } @@ -475,24 +475,6 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() delete ph.SimStat; } -/* -void AOpticalOverrideTester::on_pbST_AngleCos_clicked() -{ - //vector photon dir - TVector3 ph(ui->ledST_i->text().toDouble(), ui->ledST_j->text().toDouble(), ui->ledST_k->text().toDouble()); - ph = ph.Unit(); - - //vector surface normal - TVector3 surf(-ui->ledST_si->text().toDouble(), -ui->ledST_sj->text().toDouble(), -ui->ledST_sk->text().toDouble()); - surf = surf.Unit(); - - double cos = ph*surf; - double ang = 180.0/3.1415926*acos(cos); - - ui->pbST_AngleCos->setText("Theta="+QString::number(ang, 'g', 3)+" cos="+QString::number(cos, 'g', 3)); -} -*/ - void AOpticalOverrideTester::on_cbWavelength_toggled(bool) { updateGUI(); diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 3140a5a1..81d6f596 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -39,7 +39,6 @@ private slots: void on_pbCSMtestmany_clicked(); void on_pbST_showTracks_clicked(); void on_pbST_uniform_clicked(); - //void on_pbST_AngleCos_clicked(); void on_cbWavelength_toggled(bool checked); diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index 41c08deb..6a751db3 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -215,7 +215,7 @@ - Can be any values: Unitary vector is calculated automatically + The dot product of the normal and the incoming photon direction is positive defined! Surface normal: @@ -271,6 +271,9 @@ false + + The dot product of the normal and the incoming photon direction is positive defined! + 0 @@ -319,6 +322,9 @@ false + + The dot product of the normal and the incoming photon direction is positive defined! + 0 @@ -367,6 +373,9 @@ false + + The dot product of the normal and the incoming photon direction is positive defined! + -1 From 5e28695524c60a290bb083c13eb42afd6b662ff3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 7 Oct 2018 19:23:42 +0100 Subject: [PATCH 057/140] ++ --- .../aopticaloverridedialog.cpp | 1 + .../aopticaloverridetester.cpp | 239 ++++++++++-------- .../MainWindowTools/aopticaloverridetester.h | 4 +- .../MainWindowTools/aopticaloverridetester.ui | 80 ++++-- 4 files changed, 201 insertions(+), 123 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridedialog.cpp b/src/gui/MainWindowTools/aopticaloverridedialog.cpp index 899b2328..27601964 100644 --- a/src/gui/MainWindowTools/aopticaloverridedialog.cpp +++ b/src/gui/MainWindowTools/aopticaloverridedialog.cpp @@ -149,4 +149,5 @@ void AOpticalOverrideDialog::on_pbTestOverride_clicked() { TesterWindow->show(); TesterWindow->updateGUI(); + TesterWindow->showGeometry(); } diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 91ece79d..91986bcf 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -50,8 +50,6 @@ AOpticalOverrideTester::AOpticalOverrideTester(AOpticalOverride ** ovLocal, Main ui->labMaterials->setText( QString("(%1 -> %2)").arg(matNames.at(matFrom)).arg(matNames.at(matTo)) ); updateGUI(); - - showGeometry(); } void AOpticalOverrideTester::updateGUI() @@ -65,10 +63,7 @@ void AOpticalOverrideTester::updateGUI() else ui->cbWavelength->setEnabled(true); - int waveIndex = -1; - if (ui->cbWavelength->isChecked()) - waveIndex = MPcollection->WaveToIndex( ui->ledST_wave->text().toDouble() ); // always in [0, WaveNodes-1] - + int waveIndex = getWaveIndex(); ui->ledST_Ref1->setText( QString::number( (*MPcollection)[MatFrom]->getRefractiveIndex(waveIndex) ) ); ui->ledST_Ref2->setText( QString::number( (*MPcollection)[MatTo] ->getRefractiveIndex(waveIndex) ) ); @@ -118,8 +113,12 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() { if ( !testOverride() ) return; + //TODO wavelength shifted + int numPhotons = ui->sbST_number->value(); - QVector Spike(91, 0), Lobe(91, 0), Diffuse(91, 0), Total(91, 0), Angle; + QVector Back(91, 0), Forward(91, 0), Absorb(91, 0), NotTrigger(91, 0); + QVector Spike(91, 0), BackLobe(91, 0), BackLambert(91, 0), WaveShifted(91, 0); + QVector Angle; double N[3], K[3]; N[0] = 0; N[1] = 0; @@ -128,15 +127,16 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); - for (int iA=0; iA<91; iA++) //cycle by angle of incidence - { - double angle = iA; - if (angle == 90) angle = 89.9; + for (int iAngle = 0; iAngle < 91; iAngle++) //cycle by angle of incidence + { + double angle = iAngle; + if (angle == 90) angle = 89.99; Angle.append(angle); + //angle->photon direction double cosA = cos(TMath::Pi() * angle / 180.0); double sinA = sin(TMath::Pi() * angle / 180.0); - for (int i=0; icalculate(*Resources, &ph, N); + ph.waveIndex = getWaveIndex(); + AOpticalOverride::OpticalOverrideResultEnum result = (*pOV)->calculate(*Resources, &ph, N); + + switch (result) + { + case AOpticalOverride::NotTriggered: NotTrigger[iAngle]++; break; + case AOpticalOverride::Absorbed: Absorb[iAngle]++; break; + case AOpticalOverride::Forward: Forward[iAngle]++; break; + case AOpticalOverride::Back: Back[iAngle]++; break; + default:; + } switch ((*pOV)->Status) { - case AOpticalOverride::Absorption: continue; break; - case AOpticalOverride::SpikeReflection: Spike[iA]++; break; - case AOpticalOverride::LobeReflection: Lobe[iA]++; break; - case AOpticalOverride::LambertianReflection: Diffuse[iA]++; break; //TODO what about scrip override? + case AOpticalOverride::SpikeReflection: Spike[iAngle]++; break; + case AOpticalOverride::LobeReflection: BackLobe[iAngle]++; break; + case AOpticalOverride::LambertianReflection: BackLambert[iAngle]++; break; default: ; } } - Spike[iA] /= numPhotons; - Lobe[iA] /= numPhotons; - Diffuse[iA] /= numPhotons; - Total[iA] = Spike[iA]+Lobe[iA]+Diffuse[iA]; - } + NotTrigger[iAngle] /= numPhotons; + Absorb[iAngle] /= numPhotons; + Forward[iAngle] /= numPhotons; + Back[iAngle] /= numPhotons; + + Spike[iAngle] /= numPhotons; + BackLobe[iAngle] /= numPhotons; + BackLambert[iAngle] /= numPhotons; + } - TGraph *gS, *gL, *gD, *gT; - gT = GraphWindow->MakeGraph(&Angle, &Total, 2, "Angle", "", 0, 1, 1, 2, "", true); - gT->SetMinimum(0); - gT->SetTitle("Total"); - gS = GraphWindow->MakeGraph(&Angle, &Spike, 1, "Angle", "", 0, 1, 1, 1, "", true); - gS->SetTitle("Spike"); - gL = GraphWindow->MakeGraph(&Angle, &Lobe, 3, "Angle", "", 0, 1, 1, 1, "", true); - gL->SetTitle("Lobe"); - gD = GraphWindow->MakeGraph(&Angle, &Diffuse, 4, "Angle", "", 0, 1, 1, 1, "", true); - gD->SetTitle("Diffuse"); - - GraphWindow->Draw(gT, "AL"); - GraphWindow->Draw(gS, "Lsame"); - GraphWindow->Draw(gL, "Lsame"); - GraphWindow->Draw(gD, "Lsame"); - - TLegend *leg = new TLegend(0.1, 0.7, 0.3, 0.9); - leg->SetFillColor(0); - leg->AddEntry(gT, "Total", "lp"); - leg->AddEntry(gS, "Spike", "lp"); - leg->AddEntry(gL, "Lobe", "lp"); - leg->AddEntry(gD, "Diffuse", "lp"); - GraphWindow->Draw(leg, "same"); + if ( ui->cobPrVsAngle_WhatToCollect->currentIndex() == 1 ) + { + TGraph *gS, *gL, *gD, *gT; + gT = GraphWindow->MakeGraph(&Angle, &Back, 2, "Angle", "", 0, 1, 1, 2, "", true); + gT->SetMinimum(0); + gT->SetTitle("All reflections"); + gS = GraphWindow->MakeGraph(&Angle, &Spike, 1, "Angle", "", 0, 1, 1, 2, "", true); + gS->SetTitle("Spike"); + gL = GraphWindow->MakeGraph(&Angle, &BackLobe, 3, "Angle", "", 0, 1, 1, 2, "", true); + gL->SetTitle("Lobe"); + gD = GraphWindow->MakeGraph(&Angle, &BackLambert, 4, "Angle", "", 0, 1, 1, 2, "", true); + gD->SetTitle("Diffuse"); + + GraphWindow->Draw(gT, "AL"); + GraphWindow->Draw(gS, "Lsame"); + GraphWindow->Draw(gL, "Lsame"); + GraphWindow->Draw(gD, "Lsame"); + + GraphWindow->on_pbAddLegend_clicked(); + } + else + { + TGraph *gN, *gA, *gB, *gF; + gN = GraphWindow->MakeGraph(&Angle, &NotTrigger, 2, "Angle", "", 0, 1, 1, 2, "", true); + gN->SetMinimum(0); + gN->SetTitle("Not triggered"); + gA = GraphWindow->MakeGraph(&Angle, &Absorb, 1, "Angle", "", 0, 1, 1, 2, "", true); + gA->SetTitle("Absorption"); + gB = GraphWindow->MakeGraph(&Angle, &Back, 3, "Angle", "", 0, 1, 1, 2, "", true); + gB->SetTitle("Back"); + gF = GraphWindow->MakeGraph(&Angle, &Forward, 4, "Angle", "", 0, 1, 1, 2, "", true); + gF->SetTitle("Forward"); + + GraphWindow->Draw(gN, "AL"); + GraphWindow->Draw(gA, "Lsame"); + GraphWindow->Draw(gB, "Lsame"); + GraphWindow->Draw(gF, "Lsame"); + + GraphWindow->on_pbAddLegend_clicked(); + } delete ph.SimStat; } @@ -200,10 +229,12 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() ui->ledST_sj->text().toDouble(), ui->ledST_sk->text().toDouble()); SurfNorm = SurfNorm.Unit(); - double N[3]; + + double N[3]; //needs to calculate override N[0] = SurfNorm.X(); N[1] = SurfNorm.Y(); N[2] = SurfNorm.Z(); + TVector3 PhotDir(ui->ledST_i->text().toDouble(), ui->ledST_j->text().toDouble(), ui->ledST_k->text().toDouble()); @@ -212,86 +243,91 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() tracks.clear(); double d = 0.5; //offset - for drawing only - - //preparing and running cycle with photons - int abs, spike, lobe, lamb; - abs = spike = lobe = lamb = 0; - TH1D* hist1; - bool fDegrees = ui->cbST_cosToDegrees->isChecked(); - if (fDegrees) hist1 = new TH1D("statScatter", "Angle_scattered", 100, 0, 0); - else hist1 = new TH1D("statScatter", "Cos_scattered", 100, 0, 0); + double abs, back, forw, notTrigger, spike, lobe, lamb; + abs = back = forw = notTrigger = spike = lobe = lamb = 0; + TH1D* hist1 = new TH1D("", "", 100, 0, 0); + hist1->GetXaxis()->SetTitle("Backscattering angle, degrees"); APhoton ph; ph.SimStat = new ASimulationStatistics(); - for (int i=0; isbST_number->value(); i++) - { + const int numPhot = ui->sbST_number->value(); + for (int i = 0; i < numPhot; i++) + { ph.v[0] = PhotDir.X(); //old has output direction after full cycle! ph.v[1] = PhotDir.Y(); ph.v[2] = PhotDir.Z(); - ph.waveIndex = -1; - (*pOV)->calculate(*Resources, &ph, N); + ph.waveIndex = getWaveIndex(); + AOpticalOverride::OpticalOverrideResultEnum result = (*pOV)->calculate(*Resources, &ph, N); + + switch (result) + { + case AOpticalOverride::NotTriggered: notTrigger++; break; + case AOpticalOverride::Absorbed: abs++; break; + case AOpticalOverride::Forward: forw++; break; + case AOpticalOverride::Back: back++; break; + default:; + } Color_t col; Int_t type; - if ((*pOV)->Status == AOpticalOverride::Absorption) - { - abs++; - continue; - } - else if ((*pOV)->Status == AOpticalOverride::SpikeReflection) - { + if ((*pOV)->Status == AOpticalOverride::SpikeReflection) + { spike++; type = 0; col = 6; //0,magenta for Spike - } + } else if ((*pOV)->Status == AOpticalOverride::LobeReflection) - { + { lobe++; type = 1; col = 7; //1,teal for Lobe - } + } else if ((*pOV)->Status == AOpticalOverride::LambertianReflection) - { + { lamb++; type = 2; col = 3; //2,grean for lambert - } + } else - { + { type = 666; col = kBlue; //blue for error - } + } + + //TODO if Fresnel, change direction! tracks.append(TrackHolderClass(type, col)); - tracks.last().Nodes.append(TrackNodeStruct(d,d,d, 0)); - tracks.last().Nodes.append(TrackNodeStruct(d+ph.v[0], d+ph.v[1], d+ph.v[2], 0)); + tracks.last().Nodes.append(TrackNodeStruct(d, d, d, 0)); + tracks.last().Nodes.append(TrackNodeStruct(d + ph.v[0], d + ph.v[1], d + ph.v[2], 0)); - double costr = -SurfNorm[0]*ph.v[0] -SurfNorm[1]*ph.v[1] -SurfNorm[2]*ph.v[2]; + double costr = - SurfNorm[0] * ph.v[0] - SurfNorm[1] * ph.v[1] - SurfNorm[2] * ph.v[2]; - if (fDegrees) hist1->Fill(180.0 / TMath::Pi() * acos(costr)); - else hist1->Fill(costr); - } + hist1->Fill(180.0 / TMath::Pi() * acos(costr)); + } - //show cos angle hist GraphWindow->Draw(hist1); - //show tracks on_pbST_showTracks_clicked(); + + ui->pte->clear(); + QString t = "Process fractions:\n"; + t += QString(" Absorption: %1\n").arg(abs/numPhot); + t += QString(" Back: %1\n").arg(back/numPhot); + t += QString(" Forward: %1\n").arg(forw/numPhot); + t += QString(" Not triggered: %1\n").arg(notTrigger/numPhot); + t += "\n"; + //show stat of processes - int sum = abs + spike + lobe + lamb; - QString str = QString::number(abs) + "/" + - QString::number(spike) + "/" + - QString::number(lobe) + "/" + - QString::number(lamb); - if (sum>0) - { - str += " (" + QString::number(1.0*abs/sum, 'g', 3) + "/" + - QString::number(1.0*spike/sum, 'g', 3) + "/" + - QString::number(1.0*lobe/sum, 'g', 3) + "/" + - QString::number(1.0*lamb/sum, 'g', 3) + ")"; - } - //ui->leST_out->setText(str); + t += "Backscattering info:\n"; + t += QString(" Specular spike: %1\n").arg(spike/numPhot); + t += QString(" Diffuse lobe: %1\n").arg(lobe/numPhot); + t += QString(" Lambertian: %1\n").arg(lamb/numPhot); + + ui->pte->appendPlainText(t); + ui->pte->moveCursor(QTextCursor::Start); + ui->pte->ensureCursorVisible(); + delete ph.SimStat; } @@ -390,6 +426,13 @@ bool AOpticalOverrideTester::testOverride() return true; } +int AOpticalOverrideTester::getWaveIndex() +{ + if (ui->cbWavelength->isChecked()) + return MPcollection->WaveToIndex( ui->ledST_wave->text().toDouble() ); // always in [0, WaveNodes-1] + else return -1; +} + void AOpticalOverrideTester::on_pbST_uniform_clicked() { if ( !testOverride() ) return; @@ -408,9 +451,8 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() int abs, spike, lobe, lamb; abs = spike = lobe = lamb = 0; TH1D* hist1; - bool fDegrees = ui->cbST_cosToDegrees->isChecked(); - if (fDegrees) hist1 = new TH1D("statScatter", "Angle_scattered", 100, 0, 0); - else hist1 = new TH1D("statScatter", "Cos_scattered", 100, 0, 0); + hist1 = new TH1D("", "", 100, 0, 0); + hist1->GetXaxis()->SetTitle("Backscattering angle, degrees"); int num = ui->sbST_number->value(); @@ -450,8 +492,7 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() } double costr = -N[0]*K[0] -N[1]*K[1] -N[2]*K[2]; // after scatter, K will be in positive Z direction - if (fDegrees) hist1->Fill(180.0/3.1415926535*acos(costr)); - else hist1->Fill(costr); + hist1->Fill(180.0 / TMath::Pi() * acos(costr)); } //show cos angle hist diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 81d6f596..c9217d4f 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -30,10 +30,9 @@ class AOpticalOverrideTester : public QMainWindow public slots: void updateGUI(); - -private slots: void showGeometry(); +private slots: void on_pbDirectionHelp_clicked(); void on_pbST_RvsAngle_clicked(); void on_pbCSMtestmany_clicked(); @@ -65,6 +64,7 @@ private slots: ATracerStateful* Resources; //loacl bool testOverride(); + int getWaveIndex(); }; diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index 6a751db3..aaa7eae6 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -6,7 +6,7 @@ 0 0 - 424 + 443 466 @@ -173,17 +173,63 @@ - - - - 75 - true - - - - Processes vs angle of incidence + + + 10 - + + + + + 0 + 0 + + + + + 250 + 0 + + + + + 75 + true + + + + Processes vs angle of incidence + + + + + + + Collect: + + + + + + + + 0 + 0 + + + + + Basic info + + + + + Backscattering + + + + + @@ -519,16 +565,6 @@ - - - - Histogram: cos to degrees - - - true - - - @@ -548,7 +584,7 @@ 0 0 - 424 + 443 21 From 6012e791116b10830187e145a73a18aa431c7f8c Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 8 Oct 2018 16:59:21 +0100 Subject: [PATCH 058/140] ++ --- .../aopticaloverridetester.cpp | 46 +++++++++++-------- .../MainWindowTools/aopticaloverridetester.h | 4 +- .../MainWindowTools/aopticaloverridetester.ui | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 91986bcf..d4e182c5 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -12,6 +12,7 @@ #include "asimulationstatistics.h" #include "atrackrecords.h" #include "ajsontools.h" +#include "aglobalsettings.h" #include #include @@ -251,20 +252,23 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() APhoton ph; ph.SimStat = new ASimulationStatistics(); - - const int numPhot = ui->sbST_number->value(); + const int waveIndex = getWaveIndex(); + const int numPhot = ui->sbST_number->value(); for (int i = 0; i < numPhot; i++) { ph.v[0] = PhotDir.X(); //old has output direction after full cycle! ph.v[1] = PhotDir.Y(); ph.v[2] = PhotDir.Z(); - ph.waveIndex = getWaveIndex(); + ph.time = 0; + ph.waveIndex = waveIndex; AOpticalOverride::OpticalOverrideResultEnum result = (*pOV)->calculate(*Resources, &ph, N); + //in case of absorption or not triggered override, do not build tracks! switch (result) { - case AOpticalOverride::NotTriggered: notTrigger++; break; - case AOpticalOverride::Absorbed: abs++; break; + case AOpticalOverride::Absorbed: abs++; continue; // ! -> + case AOpticalOverride::NotTriggered: notTrigger++; continue; // ! -> + case AOpticalOverride::Forward: forw++; break; case AOpticalOverride::Back: back++; break; default:; @@ -296,8 +300,6 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() col = kBlue; //blue for error } - //TODO if Fresnel, change direction! - tracks.append(TrackHolderClass(type, col)); tracks.last().Nodes.append(TrackNodeStruct(d, d, d, 0)); tracks.last().Nodes.append(TrackNodeStruct(d + ph.v[0], d + ph.v[1], d + ph.v[2], 0)); @@ -311,18 +313,22 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() on_pbST_showTracks_clicked(); ui->pte->clear(); - QString t = "Process fractions:\n"; - t += QString(" Absorption: %1\n").arg(abs/numPhot); - t += QString(" Back: %1\n").arg(back/numPhot); - t += QString(" Forward: %1\n").arg(forw/numPhot); - t += QString(" Not triggered: %1\n").arg(notTrigger/numPhot); + QString t = "Processes:\n"; + if (abs > 0) t += QString(" Absorption: %1% (%2)\n").arg(abs/numPhot*100.0).arg(abs); + if (back > 0) t += QString(" Back: %1% (%2)\n").arg(back/numPhot*100.0).arg(back); + if (forw) t += QString(" Forward: %1% (%2)\n").arg(forw/numPhot*100.0).arg(forw); + if (notTrigger) t += QString(" Not triggered: %1% (%2)\n").arg(notTrigger/numPhot*100.0).arg(notTrigger); t += "\n"; - //show stat of processes - t += "Backscattering info:\n"; - t += QString(" Specular spike: %1\n").arg(spike/numPhot); - t += QString(" Diffuse lobe: %1\n").arg(lobe/numPhot); - t += QString(" Lambertian: %1\n").arg(lamb/numPhot); + if (back > 0) + { + //show stat of processes + t += "Backscattering composition:\n"; + if (spike > 0) t += QString(" Specular spike: %1% (%2)\n").arg(spike/back*100.0).arg(spike); + if (lobe > 0) t += QString(" Diffuse lobe: %1% (%2)\n").arg(lobe/back*100.0).arg(lobe); + if (lamb > 0) t += QString(" Lambertian: %1% (%2)\n").arg(lamb/back*100.0).arg(lamb); + } + ui->pte->appendPlainText(t); ui->pte->moveCursor(QTextCursor::Start); @@ -390,8 +396,8 @@ void AOpticalOverrideTester::on_pbST_showTracks_clicked() if (selector == 3) return; //do not show any tracks int numTracks = 0; - for(int i = 1; i-1) //-1 - show all @@ -403,7 +409,7 @@ void AOpticalOverrideTester::on_pbST_showTracks_clicked() track->SetLineWidth(1); for (int iNode=0; iNodeNodes.size(); iNode++) track->AddPoint(th->Nodes[iNode].R[0], th->Nodes[iNode].R[1], th->Nodes[iNode].R[2], th->Nodes[iNode].Time); - } + } GeometryWindow->show(); GeometryWindow->DrawTracks(); diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index c9217d4f..05b5103c 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -61,7 +61,9 @@ private slots: GraphWindowClass* GraphWindow; //external GeometryWindowClass* GeometryWindow; //external TRandom2* RandGen; //local - ATracerStateful* Resources; //loacl + ATracerStateful* Resources; //local + + const int maxNumTracks = 1000; bool testOverride(); int getWaveIndex(); diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index aaa7eae6..37198163 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -175,7 +175,7 @@ - 10 + 0 From d79eb7c3b425390dce30d6274a49929cf714df74 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 9 Oct 2018 12:48:16 +0100 Subject: [PATCH 059/140] remove specific statistic by override types --- .../abasicopticaloverride.cpp | 3 -- src/OpticalOverrides/awaveshifteroverride.cpp | 4 --- src/OpticalOverrides/fsnpopticaloverride.cpp | 3 -- src/OpticalOverrides/phscatclaudiomodel.cpp | 9 ----- src/OpticalOverrides/scatteronmetal.cpp | 2 -- src/common/asimulationstatistics.cpp | 23 ------------- src/common/asimulationstatistics.h | 8 +---- src/gui/outputwindow.cpp | 33 ------------------- 8 files changed, 1 insertion(+), 84 deletions(-) diff --git a/src/OpticalOverrides/abasicopticaloverride.cpp b/src/OpticalOverrides/abasicopticaloverride.cpp index b79f51cc..99c29d7b 100644 --- a/src/OpticalOverrides/abasicopticaloverride.cpp +++ b/src/OpticalOverrides/abasicopticaloverride.cpp @@ -32,7 +32,6 @@ AOpticalOverride::OpticalOverrideResultEnum ABasicOpticalOverride::calculate(ATr if (rnd<0) { // qDebug()<<"Override: surface loss!"; - Photon->SimStat->OverrideSimplisticAbsorption++; Status = Absorption; return Absorbed; } @@ -46,7 +45,6 @@ AOpticalOverride::OpticalOverrideResultEnum ABasicOpticalOverride::calculate(ATr double NK = NormalVector[0]*Photon->v[0]; NK += NormalVector[1]*Photon->v[1]; NK += NormalVector[2]*Photon->v[2]; Photon->v[0] -= 2.0*NK*NormalVector[0]; Photon->v[1] -= 2.0*NK*NormalVector[1]; Photon->v[2] -= 2.0*NK*NormalVector[2]; - Photon->SimStat->OverrideSimplisticReflection++; Status = SpikeReflection; return Back; } @@ -56,7 +54,6 @@ AOpticalOverride::OpticalOverrideResultEnum ABasicOpticalOverride::calculate(ATr if (rnd<0) { // qDebug()<<"scattering triggered"; - Photon->SimStat->OverrideSimplisticScatter++; switch (scatterModel) { diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 71e31b6e..6e123dd4 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -75,7 +75,6 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra ReemissionProbabilityBinned.isEmpty() ) //or probability not defined { Status = Absorption; - Photon->SimStat->OverrideWLSabs++; return Absorbed; } @@ -94,7 +93,6 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra if (attempts > 9) { Status = Absorption; - Photon->SimStat->OverrideWLSabs++; return Absorbed; } wavelength = Spectrum->GetRandom(); @@ -103,7 +101,6 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra while (waveIndex < Photon->waveIndex); //conserving energy Photon->waveIndex = waveIndex; - Photon->SimStat->OverrideWLSshift++; if (ReemissionModel == 0) { @@ -157,7 +154,6 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra // else absorption Status = Absorption; - Photon->SimStat->OverrideWLSabs++; return Absorbed; } diff --git a/src/OpticalOverrides/fsnpopticaloverride.cpp b/src/OpticalOverrides/fsnpopticaloverride.cpp index 7af649fd..72cb721a 100644 --- a/src/OpticalOverrides/fsnpopticaloverride.cpp +++ b/src/OpticalOverrides/fsnpopticaloverride.cpp @@ -64,7 +64,6 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATrac //rotating the vector: K = K - 2*(NK)*N Photon->v[0] -= 2.0*cos1*NormalVector[0]; Photon->v[1] -= 2.0*cos1*NormalVector[1]; Photon->v[2] -= 2.0*cos1*NormalVector[2]; Status = SpikeReflection; - Photon->SimStat->OverrideFSNPspecular++; return Back; } @@ -73,7 +72,6 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATrac { //qDebug()<<"Override: absorption"; Status = Absorption; - Photon->SimStat->OverrideFSNPabs++; return Absorbed; } @@ -89,7 +87,6 @@ AOpticalOverride::OpticalOverrideResultEnum FSNPOpticalOverride::calculate(ATrac double normInverted = 1.0/TMath::Sqrt(norm2); Photon->v[0] *= normInverted; Photon->v[1] *= normInverted; Photon->v[2] *= normInverted; Status = LambertianReflection; - Photon->SimStat->OverrideFSNlambert++; return Back; } diff --git a/src/OpticalOverrides/phscatclaudiomodel.cpp b/src/OpticalOverrides/phscatclaudiomodel.cpp index 7d78ba65..c8f50389 100644 --- a/src/OpticalOverrides/phscatclaudiomodel.cpp +++ b/src/OpticalOverrides/phscatclaudiomodel.cpp @@ -331,7 +331,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(ATra //G4double C_perp = std::sqrt(Amp_perp/Amp_tot); //G4double C_parl = std::sqrt(Amp_parl/Amp_tot); //NewPolarization = C_parl*A_paral + C_perp*A_trans; - Photon->SimStat->OverrideClaudioSpec++; } else { @@ -342,7 +341,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(ATra if ( Resources.RandGen->Rndm() > albedo) { Status = Absorption; - Photon->SimStat->OverrideClaudioAbs++; return Absorbed; } @@ -379,7 +377,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2::calculate(ATra // A_paral = A_paral.unit(); // G4double ThetaPolar = twopi*G4UniformRand(); // NewPolarization = cos(ThetaPolar)*A_paral + sin(ThetaPolar)*A_trans; - Photon->SimStat->OverrideClaudioLamb++; } Photon->v[0] = K.X(); @@ -500,7 +497,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(AT //G4double C_perp = std::sqrt(Amp_perp/Amp_tot); //G4double C_parl = std::sqrt(Amp_parl/Amp_tot); //NewPolarization = C_parl*A_paral + C_perp*A_trans; - Photon->SimStat->OverrideClaudioSpec++; } else { @@ -511,7 +507,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(AT if ( Resources.RandGen->Rndm() > albedo) { Status = Absorption; - Photon->SimStat->OverrideClaudioAbs++; return Absorbed; } @@ -549,7 +544,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d2::calculate(AT // A_paral = A_paral.unit(); // G4double ThetaPolar = twopi*G4UniformRand(); // NewPolarization = cos(ThetaPolar)*A_paral + sin(ThetaPolar)*A_trans; - Photon->SimStat->OverrideClaudioLamb++; } Photon->v[0] = K.X(); @@ -671,7 +665,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(AT //G4double C_perp = std::sqrt(Amp_perp/Amp_tot); //G4double C_parl = std::sqrt(Amp_parl/Amp_tot); //NewPolarization = C_parl*A_paral + C_perp*A_trans; - Photon->SimStat->OverrideClaudioSpec++; } else { @@ -682,7 +675,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(AT if ( Resources.RandGen->Rndm() > albedo) { Status = Absorption; - Photon->SimStat->OverrideClaudioAbs++; return Absorbed; } @@ -720,7 +712,6 @@ AOpticalOverride::OpticalOverrideResultEnum PhScatClaudioModelV2d1::calculate(AT // A_paral = A_paral.unit(); // G4double ThetaPolar = twopi*G4UniformRand(); // NewPolarization = cos(ThetaPolar)*A_paral + sin(ThetaPolar)*A_trans; - Photon->SimStat->OverrideClaudioLamb++; } Photon->v[0] = K.X(); diff --git a/src/OpticalOverrides/scatteronmetal.cpp b/src/OpticalOverrides/scatteronmetal.cpp index 13c8b32c..b5d70e0a 100644 --- a/src/OpticalOverrides/scatteronmetal.cpp +++ b/src/OpticalOverrides/scatteronmetal.cpp @@ -116,7 +116,6 @@ AOpticalOverride::OpticalOverrideResultEnum ScatterOnMetal::calculate(ATracerSta //Absorption //qDebug() << "Override: Loss on metal"; Status = Absorption; - Photon->SimStat->OverrideMetalAbs++; return Absorbed; } @@ -126,7 +125,6 @@ AOpticalOverride::OpticalOverrideResultEnum ScatterOnMetal::calculate(ATracerSta double NK = NormalVector[0]*Photon->v[0]; NK += NormalVector[1]*Photon->v[1]; NK += NormalVector[2]*Photon->v[2]; Photon->v[0] -= 2.0*NK*NormalVector[0]; Photon->v[1] -= 2.0*NK*NormalVector[1]; Photon->v[2] -= 2.0*NK*NormalVector[2]; Status = SpikeReflection; - Photon->SimStat->OverrideMetalReflection++; return Back; } diff --git a/src/common/asimulationstatistics.cpp b/src/common/asimulationstatistics.cpp index f19a7dff..d629fcb1 100644 --- a/src/common/asimulationstatistics.cpp +++ b/src/common/asimulationstatistics.cpp @@ -59,11 +59,6 @@ void ASimulationStatistics::initialize(QVector monitorRecords FresnelTransmitted = FresnelReflected = BulkAbsorption = Rayleigh = Reemission = 0; OverrideForward = OverrideBack = 0; - OverrideSimplisticAbsorption = OverrideSimplisticReflection = OverrideSimplisticScatter = 0; - OverrideFSNPabs = OverrideFSNlambert = OverrideFSNPspecular = 0; - OverrideMetalAbs = OverrideMetalReflection = 0; - OverrideClaudioAbs = OverrideClaudioSpec = OverrideClaudioLamb = 0; - OverrideWLSabs = OverrideWLSshift = 0; PhotonHistoryLog.clear(); PhotonHistoryLog.squeeze(); @@ -136,24 +131,6 @@ void ASimulationStatistics::AppendSimulationStatistics(ASimulationStatistics* fr OverrideBack += from->OverrideBack; OverrideForward += from->OverrideForward; - OverrideSimplisticAbsorption += from->OverrideSimplisticAbsorption; - OverrideSimplisticReflection += from->OverrideSimplisticReflection; - OverrideSimplisticScatter += from->OverrideSimplisticScatter; - - OverrideFSNPabs += from->OverrideFSNPabs; - OverrideFSNlambert += from->OverrideFSNlambert; - OverrideFSNPspecular += from->OverrideFSNPspecular; - - OverrideMetalAbs += from->OverrideMetalAbs; - OverrideMetalReflection += from->OverrideMetalReflection; - - OverrideClaudioAbs += from->OverrideClaudioAbs; - OverrideClaudioSpec += from->OverrideClaudioSpec; - OverrideClaudioLamb += from->OverrideClaudioLamb; - - OverrideWLSabs += from->OverrideWLSabs; - OverrideWLSshift += from->OverrideWLSshift; - if (Monitors.size() != from->Monitors.size()) { qWarning() << "Cannot append monitor data - size mismatch:\n" << diff --git a/src/common/asimulationstatistics.h b/src/common/asimulationstatistics.h index e9ed7893..76b2564f 100644 --- a/src/common/asimulationstatistics.h +++ b/src/common/asimulationstatistics.h @@ -44,13 +44,7 @@ class ASimulationStatistics //statistics for optical processes long FresnelTransmitted, FresnelReflected, BulkAbsorption, Rayleigh, Reemission; //general bulk - long OverrideBack, OverrideForward; //general override - //specific overrides - long OverrideSimplisticAbsorption, OverrideSimplisticReflection, OverrideSimplisticScatter; //simplistic - long OverrideFSNPabs, OverrideFSNlambert, OverrideFSNPspecular; //FSNP - long OverrideMetalAbs, OverrideMetalReflection; //on metal - long OverrideClaudioAbs, OverrideClaudioSpec, OverrideClaudioLamb; //Claudio's - long OverrideWLSabs, OverrideWLSshift; + long OverrideBack, OverrideForward; //general override. Note that OverrideLoss is already defined //only affects script unit "photon" tracing! QVector< QVector > PhotonHistoryLog; diff --git a/src/gui/outputwindow.cpp b/src/gui/outputwindow.cpp index deccbd30..6332d6af 100644 --- a/src/gui/outputwindow.cpp +++ b/src/gui/outputwindow.cpp @@ -1187,39 +1187,6 @@ void OutputWindow::ShowPhotonProcessesLog() s += "Overrides, loss: " + QString::number(d->OverrideLoss) + "\n"; s += "Overrides, back: " + QString::number(d->OverrideBack) + "\n"; s += "Overrides, forward: " + QString::number(d->OverrideForward) + "\n"; - if (d->OverrideSimplisticAbsorption>0 || d->OverrideSimplisticReflection>0 || d->OverrideSimplisticScatter>0) - { - s += "----\n"; - s += "Override simplistic, absorption: " + QString::number(d->OverrideSimplisticAbsorption) + "\n"; - s += "Override simplistic, specular: " + QString::number(d->OverrideSimplisticReflection) + "\n"; - s += "Override simplistic, lambertian: " + QString::number(d->OverrideSimplisticScatter) + "\n"; - } - if (d->OverrideFSNPabs>0 || d->OverrideFSNlambert>0 || d->OverrideFSNPspecular>0) - { - s += "----\n"; - s += "Override FSNP, absorption: " + QString::number(d->OverrideFSNPabs) + "\n"; - s += "Override FSNP, specular: " + QString::number(d->OverrideFSNPspecular) + "\n"; - s += "Override FSNP, lambertian: " + QString::number(d->OverrideFSNlambert) + "\n"; - } - if (d->OverrideMetalAbs>0 || d->OverrideMetalReflection>0) - { - s += "----\n"; - s += "Override OnMetal, absorption: " + QString::number(d->OverrideMetalAbs) + "\n"; - s += "Override OnMetal, specular: " + QString::number(d->OverrideMetalReflection) + "\n"; - } - if (d->OverrideClaudioAbs>0 || d->OverrideClaudioLamb>0 || d->OverrideClaudioSpec>0) - { - s += "----\n"; - s += "Override Clauido's model', absorption: " + QString::number(d->OverrideClaudioAbs) + "\n"; - s += "Override Claudio's model', specular: " + QString::number(d->OverrideClaudioSpec) + "\n"; - s += "Override Claudio's model', lambertian: " + QString::number(d->OverrideClaudioLamb) + "\n"; - } - if (d->OverrideWLSabs>0 || d->OverrideWLSshift>0) - { - s += "----\n"; - s += "Override WLS, absorption: " + QString::number(d->OverrideWLSabs) + "\n"; - s += "Override WLS, reemission: " + QString::number(d->OverrideWLSshift) + "\n"; - } s += "====================="; //OutText(s); //SetTab(0); From da822217dceb91ec915500041d8e34e1039c390d Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 9 Oct 2018 16:25:17 +0100 Subject: [PATCH 060/140] ++ --- .../aopticaloverridetester.cpp | 95 +---- .../MainWindowTools/aopticaloverridetester.h | 10 +- .../MainWindowTools/aopticaloverridetester.ui | 373 +++++------------- 3 files changed, 112 insertions(+), 366 deletions(-) diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index d4e182c5..47de0ed4 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -67,15 +67,6 @@ void AOpticalOverrideTester::updateGUI() int waveIndex = getWaveIndex(); ui->ledST_Ref1->setText( QString::number( (*MPcollection)[MatFrom]->getRefractiveIndex(waveIndex) ) ); ui->ledST_Ref2->setText( QString::number( (*MPcollection)[MatTo] ->getRefractiveIndex(waveIndex) ) ); - - TVector3 photon(ui->ledST_i->text().toDouble(), ui->ledST_j->text().toDouble(), ui->ledST_k->text().toDouble()); - photon = photon.Unit(); - //vector surface normal - TVector3 normal(ui->ledST_si->text().toDouble(), ui->ledST_sj->text().toDouble(), ui->ledST_sk->text().toDouble()); - normal = normal.Unit(); - double cos = photon * normal; - double ang = 180.0 / TMath::Pi() * acos(cos); - ui->ledAngle->setText( QString::number(ang, 'g', 4) ); } AOpticalOverrideTester::~AOpticalOverrideTester() @@ -101,15 +92,6 @@ void AOpticalOverrideTester::readFromJson(const QJsonObject &json) if (x>0 && y>0) move(x, y); } -void AOpticalOverrideTester::on_pbDirectionHelp_clicked() -{ - QString s = "Vectors are not necessary normalized to unity (automatically scaled)\n\n" - "Note that in override caluclations the normal vector of the surface\n" - "is provided in such a way that the dot product of the normal and\n" - "the incoming photon direction is positive."; - message(s, this); -} - void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() { if ( !testOverride() ) return; @@ -226,20 +208,12 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() if ( !testOverride() ) return; //surface normal and photon direction - TVector3 SurfNorm(ui->ledST_si->text().toDouble(), - ui->ledST_sj->text().toDouble(), - ui->ledST_sk->text().toDouble()); - SurfNorm = SurfNorm.Unit(); - + TVector3 SurfNorm(0, 0, -1.0); double N[3]; //needs to calculate override N[0] = SurfNorm.X(); N[1] = SurfNorm.Y(); N[2] = SurfNorm.Z(); - - TVector3 PhotDir(ui->ledST_i->text().toDouble(), - ui->ledST_j->text().toDouble(), - ui->ledST_k->text().toDouble()); - PhotDir = PhotDir.Unit(); + TVector3 PhotDir = getPhotonVector(); tracks.clear(); double d = 0.5; //offset - for drawing only @@ -346,10 +320,7 @@ void AOpticalOverrideTester::showGeometry() double f = 0.5; //surface normal - TVector3 SurfNorm(ui->ledST_si->text().toDouble(), - ui->ledST_sj->text().toDouble(), - ui->ledST_sk->text().toDouble()); - SurfNorm = SurfNorm.Unit(); + TVector3 SurfNorm(0, 0, -1.0); int track_index = gGeoManager->AddTrack(1,22); TVirtualGeoTrack* track = gGeoManager->GetTrack(track_index); track->AddPoint(d, d, d, 0); @@ -375,11 +346,9 @@ void AOpticalOverrideTester::showGeometry() track_index = gGeoManager->AddTrack(1, 10); track = gGeoManager->GetTrack(track_index); track->AddPoint(d, d, d, 0); - TVector3 PhotDir(ui->ledST_i->text().toDouble(), - ui->ledST_j->text().toDouble(), - ui->ledST_k->text().toDouble()); - PhotDir = PhotDir.Unit(); - track->AddPoint(d-PhotDir.X(), d-PhotDir.Y(), d-PhotDir.Z(), 0); + + TVector3 PhotDir = getPhotonVector(); + track->AddPoint(d - PhotDir.X(), d - PhotDir.Y(), d - PhotDir.Z(), 0); track->SetLineColor(kRed); track->SetLineWidth(3); @@ -439,14 +408,21 @@ int AOpticalOverrideTester::getWaveIndex() else return -1; } +const TVector3 AOpticalOverrideTester::getPhotonVector() +{ + TVector3 PhotDir(0, 0, -1.0); + TVector3 perp(0, 1.0, 0); + double angle = ui->ledAngle->text().toDouble(); + angle *= -TMath::Pi() / 180.0; + PhotDir.Rotate(angle, perp); + return PhotDir; +} + void AOpticalOverrideTester::on_pbST_uniform_clicked() { if ( !testOverride() ) return; - TVector3 SurfNorm(ui->ledST_si->text().toDouble(), - ui->ledST_sj->text().toDouble(), - ui->ledST_sk->text().toDouble()); - SurfNorm = SurfNorm.Unit(); + TVector3 SurfNorm(0, 0, -1.0); double N[3]; N[0] = SurfNorm.X(); N[1] = SurfNorm.Y(); @@ -497,7 +473,7 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() exit(666); } - double costr = -N[0]*K[0] -N[1]*K[1] -N[2]*K[2]; // after scatter, K will be in positive Z direction + double costr = N[0]*K[0] + N[1]*K[1] + N[2]*K[2]; hist1->Fill(180.0 / TMath::Pi() * acos(costr)); } @@ -532,46 +508,15 @@ void AOpticalOverrideTester::on_ledST_wave_editingFinished() updateGUI(); } -void AOpticalOverrideTester::on_ledST_i_editingFinished() -{ - updateGUI(); - showGeometry(); -} - -void AOpticalOverrideTester::on_ledST_j_editingFinished() -{ - updateGUI(); - showGeometry(); -} - -void AOpticalOverrideTester::on_ledST_k_editingFinished() -{ - if (ui->ledST_k->text().toDouble() >= 0) - { - ui->ledST_k->setText("-1"); - message("The photon direction vector along Z axis should be neagtive!", this); - } - updateGUI(); - showGeometry(); -} - void AOpticalOverrideTester::on_ledAngle_editingFinished() { double angle = ui->ledAngle->text().toDouble(); - if (angle <= -90.0 || angle >= 90.0 ) + if (angle < 0 || angle >= 90.0 ) { ui->ledAngle->setText("45"); - message("Angle should be within (-90, 90) degrees!", this); + message("Angle should be within [0, 90) degrees!", this); angle = 45.0; } - TVector3 photon(0, 0, -1.0); - TVector3 perp(0, 1.0, 0); - angle *= -TMath::Pi() / 180.0; - photon.Rotate(angle, perp); - ui->ledST_i->setText( QString::number( photon.x(), 'g', 6) ); - ui->ledST_j->setText( QString::number( photon.y(), 'g', 6) ); - ui->ledST_k->setText( QString::number( photon.z(), 'g', 6) ); - showGeometry(); } diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index 05b5103c..c2276361 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -5,6 +5,8 @@ #include +#include "TVector3.h" + namespace Ui { class AOpticalOverrideTester; } @@ -33,7 +35,6 @@ public slots: void showGeometry(); private slots: - void on_pbDirectionHelp_clicked(); void on_pbST_RvsAngle_clicked(); void on_pbCSMtestmany_clicked(); void on_pbST_showTracks_clicked(); @@ -43,12 +44,6 @@ private slots: void on_ledST_wave_editingFinished(); - void on_ledST_i_editingFinished(); - - void on_ledST_j_editingFinished(); - - void on_ledST_k_editingFinished(); - void on_ledAngle_editingFinished(); private: @@ -67,6 +62,7 @@ private slots: bool testOverride(); int getWaveIndex(); + const TVector3 getPhotonVector(); }; diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index 37198163..5bcf0ac6 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -7,7 +7,7 @@ 0 0 443 - 466 + 424 @@ -172,288 +172,6 @@ - - - - 0 - - - - - - 0 - 0 - - - - - 250 - 0 - - - - - 75 - true - - - - Processes vs angle of incidence - - - - - - - Collect: - - - - - - - - 0 - 0 - - - - - Basic info - - - - - Backscattering - - - - - - - - - - - 75 - true - - - - Lambertian distribution for incoming photons! - - - Diffuse irradiation test - - - - - - - Qt::Horizontal - - - - - - - - - - - The dot product of the normal and the incoming photon direction is positive defined! - - - Surface normal: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Can be any values: Unitary vector is calculated automatically - - - Photon direction: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - i: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - i: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - false - - - The dot product of the normal and the incoming photon direction is positive defined! - - - 0 - - - false - - - - - - - 1 - - - - - - - - - - - j: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - j: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - false - - - The dot product of the normal and the incoming photon direction is positive defined! - - - 0 - - - false - - - - - - - 0 - - - - - - - - - - - k: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - k: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - - false - - - The dot product of the normal and the incoming photon direction is positive defined! - - - -1 - - - false - - - - - - - -1 - - - - - - - - - - 25 - 16777215 - - - - ? - - - - - @@ -522,6 +240,11 @@ true + + Note that in override caluclations the normal vector of the surface +is provided in such a way that the dot product of the normal and +the incoming photon direction is positive. + Trace photons @@ -568,7 +291,89 @@ - + + + Qt::Horizontal + + + + + + + 0 + + + + + + 0 + 0 + + + + + 250 + 0 + + + + + 75 + true + + + + Processes vs angle of incidence + + + + + + + Collect: + + + + + + + + 0 + 0 + + + + + Basic info + + + + + Backscattering + + + + + + + + + + + 75 + true + + + + Lambertian distribution for incoming photons! + + + Diffuse irradiation test + + + + + Qt::Horizontal From afd08f6812a2d418ea412e0a4df7e68235972387 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 9 Oct 2018 18:15:49 +0100 Subject: [PATCH 061/140] ++ --- src/ants2.pro | 6 +- src/common/ahistoryrecords.h | 5 +- src/gui/MainWindowTools/globalscript.cpp | 4 + src/modules/primaryparticletracker.cpp | 2 +- src/scriptmode/ainterfacetodeposcript.h | 2 +- .../aparticletrackinghistoryinterface.cpp | 107 ++++++++++++++++++ .../aparticletrackinghistoryinterface.h | 45 ++++++++ 7 files changed, 165 insertions(+), 6 deletions(-) create mode 100644 src/scriptmode/aparticletrackinghistoryinterface.cpp create mode 100644 src/scriptmode/aparticletrackinghistoryinterface.h diff --git a/src/ants2.pro b/src/ants2.pro index f8d40e76..d33c39ad 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -367,7 +367,8 @@ SOURCES += main.cpp \ common/agammarandomgenerator.cpp \ Net/agridrunner.cpp \ Net/aremoteserverrecord.cpp \ - common/atrackbuildoptions.cpp + common/atrackbuildoptions.cpp \ + scriptmode/aparticletrackinghistoryinterface.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -491,7 +492,8 @@ HEADERS += common/CorrelationFilters.h \ scriptmode/awebserverinterface.h \ Net/agridrunner.h \ Net/aremoteserverrecord.h \ - common/atrackbuildoptions.h + common/atrackbuildoptions.h \ + scriptmode/aparticletrackinghistoryinterface.h # --- SIM --- ants2_SIM { diff --git a/src/common/ahistoryrecords.h b/src/common/ahistoryrecords.h index 1e835e84..9caa97cb 100644 --- a/src/common/ahistoryrecords.h +++ b/src/common/ahistoryrecords.h @@ -32,10 +32,11 @@ struct EventHistoryStructure int index; // this is particle index! - "serial number" of the particle int SecondaryOf; float dx, dy, dz; //direction + float initialEnergy; TerminationTypes Termination; - EventHistoryStructure(int ParticleId, int index, int SecondaryOf, double* v) - : ParticleId(ParticleId), index(index), SecondaryOf(SecondaryOf), dx(v[0]), dy(v[1]), dz(v[2]) { } + EventHistoryStructure(int ParticleId, int index, int SecondaryOf, double* v, double energy) + : ParticleId(ParticleId), index(index), SecondaryOf(SecondaryOf), dx(v[0]), dy(v[1]), dz(v[2]), initialEnergy(energy) { } EventHistoryStructure(){} bool isSecondary() const {return SecondaryOf > -1;} diff --git a/src/gui/MainWindowTools/globalscript.cpp b/src/gui/MainWindowTools/globalscript.cpp index f9b7f3c8..12882b30 100644 --- a/src/gui/MainWindowTools/globalscript.cpp +++ b/src/gui/MainWindowTools/globalscript.cpp @@ -18,6 +18,7 @@ #include "ainterfacetomultithread.h" #include "ainterfacetoguiscript.h" #include "ainterfacetottree.h" +#include "aparticletrackinghistoryinterface.h" #include "mainwindow.h" #include "graphwindowclass.h" @@ -117,6 +118,9 @@ void MainWindow::createScriptWindow() AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(Detector, GlobSet, EventsDataHub); ScriptWindow->SetInterfaceObject(depo, "depo"); + AParticleTrackingHistoryInterface* pth = new AParticleTrackingHistoryInterface(EventsDataHub->EventHistory); + ScriptWindow->SetInterfaceObject(pth, "pth"); + #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager->KNNmodule); ScriptWindow->SetInterfaceObject(knn, "knn"); diff --git a/src/modules/primaryparticletracker.cpp b/src/modules/primaryparticletracker.cpp index 005eab60..07255084 100644 --- a/src/modules/primaryparticletracker.cpp +++ b/src/modules/primaryparticletracker.cpp @@ -65,7 +65,7 @@ bool PrimaryParticleTracker::TrackParticlesOnStack(int eventId) if (SimSet->fLogsStat) { //initializing history record - at the end it will be appended to EventHistory QVector - History = new EventHistoryStructure(ParticleId, counter, ParticleStack->at(0)->secondaryOf, ParticleStack->at(0)->v) ; + History = new EventHistoryStructure(ParticleId, counter, ParticleStack->at(0)->secondaryOf, ParticleStack->at(0)->v, ParticleStack->at(0)->energy); } //setting current position, direction vector, energy and time double r[3]; //position diff --git a/src/scriptmode/ainterfacetodeposcript.h b/src/scriptmode/ainterfacetodeposcript.h index e3afe902..dabebeb8 100644 --- a/src/scriptmode/ainterfacetodeposcript.h +++ b/src/scriptmode/ainterfacetodeposcript.h @@ -1,7 +1,7 @@ #ifndef AINTERFACETODEPOSCRIPT_H #define AINTERFACETODEPOSCRIPT_H -#include "localscriptinterfaces.h" +#include "ascriptinterface.h" #include "ahistoryrecords.h" #include "detectorclass.h" diff --git a/src/scriptmode/aparticletrackinghistoryinterface.cpp b/src/scriptmode/aparticletrackinghistoryinterface.cpp new file mode 100644 index 00000000..141acb8d --- /dev/null +++ b/src/scriptmode/aparticletrackinghistoryinterface.cpp @@ -0,0 +1,107 @@ +#include "aparticletrackinghistoryinterface.h" +#include "ahistoryrecords.h" + +AParticleTrackingHistoryInterface::AParticleTrackingHistoryInterface(QVector &EventHistory) : + EventHistory(EventHistory) {} + +QVariantList AParticleTrackingHistoryInterface::getAllDefinedTerminatorTypes() +{ + const QStringList defined = EventHistoryStructure::getAllDefinedTerminationTypes(); + QVariantList l; + for (int i=0; i= EventHistory.size()) + { + abort("Attempt to address non-existent particle number in history"); + return false; + } + if (m<0 || m >= EventHistory.at(i)->Deposition.size()) + { + abort("Attempt to address non-existent material record in history"); + return false; + } + return true; +} diff --git a/src/scriptmode/aparticletrackinghistoryinterface.h b/src/scriptmode/aparticletrackinghistoryinterface.h new file mode 100644 index 00000000..6459fcba --- /dev/null +++ b/src/scriptmode/aparticletrackinghistoryinterface.h @@ -0,0 +1,45 @@ +#ifndef APARTICLETRACKINGHISTORYINTERFACE_H +#define APARTICLETRACKINGHISTORYINTERFACE_H + +#include "ascriptinterface.h" + +#include +#include +#include + +class EventsDataClass; +struct EventHistoryStructure; + +class AParticleTrackingHistoryInterface : public AScriptInterface +{ + Q_OBJECT +public: + AParticleTrackingHistoryInterface(QVector& EventHistory); + +private: + QVector& EventHistory; + +public slots: + int countParticles() {return EventHistory.size();} + + int getParticleId(int iParticle); + bool isSecondary(int iParticle); + int getParent(int iParticle); + double getInitialEnergy(int iParticle); + int getTermination(int iParticle); + + QVariantList getAllDefinedTerminatorTypes(); + //QVariantList getDirection(int i); + //int sernum(int i); + + int countRecords(int iParticle); + int getRecordMaterial(int iParticle, int iRecord); + double getRecordDepositedEnergy(int iParticle, int iRecord); + double getRecordDistance(int iParticle, int iRecord); + +private: + bool checkParticle(int i); + bool checkParticleAndMaterial(int i, int m); +}; + +#endif // APARTICLETRACKINGHISTORYINTERFACE_H From 6fd79b6b7354f11efe38c90a62f166bbcd0308ac Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 9 Oct 2018 18:50:33 +0100 Subject: [PATCH 062/140] ++ --- .../aparticletrackinghistoryinterface.cpp | 34 +++++++++++++++++++ .../aparticletrackinghistoryinterface.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/src/scriptmode/aparticletrackinghistoryinterface.cpp b/src/scriptmode/aparticletrackinghistoryinterface.cpp index 141acb8d..960fea5d 100644 --- a/src/scriptmode/aparticletrackinghistoryinterface.cpp +++ b/src/scriptmode/aparticletrackinghistoryinterface.cpp @@ -105,3 +105,37 @@ bool AParticleTrackingHistoryInterface::checkParticleAndMaterial(int i, int m) } return true; } + +/* +#include "TTree.h" +#include "TFile.h" +bool AParticleTrackingHistoryInterface::saveHistoryToTTree(QString fileName) +{ + TFile* f = new TFile(fileName,"RECREATE"); + + TTree *t = new TTree("","Particle tracking history"); + + std::vector x; //Can be multiple point reconstruction! + double chi2; + double ssum; + int ievent; //event number + int good, recOK; + + t->Branch("i",&ievent, "i/I"); + t->Branch("ssum",&ssum, "ssum/D"); + t->Branch("x", &x); + + int ParticleId; + int index; + int SecondaryOf; + float dx, dy, dz; + float initialEnergy; + int Termination; + + < + int MaterialId; + double DepositedEnergy; + double Distance; + > +} +*/ diff --git a/src/scriptmode/aparticletrackinghistoryinterface.h b/src/scriptmode/aparticletrackinghistoryinterface.h index 6459fcba..06ab8894 100644 --- a/src/scriptmode/aparticletrackinghistoryinterface.h +++ b/src/scriptmode/aparticletrackinghistoryinterface.h @@ -37,6 +37,8 @@ public slots: double getRecordDepositedEnergy(int iParticle, int iRecord); double getRecordDistance(int iParticle, int iRecord); + //bool saveHistoryToTTree(QString fileName); + private: bool checkParticle(int i); bool checkParticleAndMaterial(int i, int m); From 8784afe27839f1a78220b48d599a87796a084c12 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 10 Oct 2018 13:42:11 +0100 Subject: [PATCH 063/140] ++ --- src/common/ahistoryrecords.h | 2 +- .../aparticletrackinghistoryinterface.cpp | 71 ++++++++++++------- .../aparticletrackinghistoryinterface.h | 2 +- 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/src/common/ahistoryrecords.h b/src/common/ahistoryrecords.h index 9caa97cb..e1f77a0c 100644 --- a/src/common/ahistoryrecords.h +++ b/src/common/ahistoryrecords.h @@ -52,7 +52,7 @@ struct EventHistoryStructure struct GeneratedPhotonsHistoryStructure { int event; - int index; //# t distinguish between particles with the same ParticleId (e.g. during the same event) + int index; // to distinguish between particles with the same ParticleId (e.g. during the same event) int ParticleId; int MaterialId; double Energy; diff --git a/src/scriptmode/aparticletrackinghistoryinterface.cpp b/src/scriptmode/aparticletrackinghistoryinterface.cpp index 960fea5d..632a697a 100644 --- a/src/scriptmode/aparticletrackinghistoryinterface.cpp +++ b/src/scriptmode/aparticletrackinghistoryinterface.cpp @@ -106,36 +106,55 @@ bool AParticleTrackingHistoryInterface::checkParticleAndMaterial(int i, int m) return true; } -/* + #include "TTree.h" #include "TFile.h" -bool AParticleTrackingHistoryInterface::saveHistoryToTTree(QString fileName) +#include +bool AParticleTrackingHistoryInterface::saveHistoryToTree(QString fileName) { - TFile* f = new TFile(fileName,"RECREATE"); + TFile f(fileName.toLatin1().data(),"RECREATE"); TTree *t = new TTree("","Particle tracking history"); - std::vector x; //Can be multiple point reconstruction! - double chi2; - double ssum; - int ievent; //event number - int good, recOK; - - t->Branch("i",&ievent, "i/I"); - t->Branch("ssum",&ssum, "ssum/D"); - t->Branch("x", &x); - - int ParticleId; - int index; - int SecondaryOf; - float dx, dy, dz; - float initialEnergy; - int Termination; - - < - int MaterialId; - double DepositedEnergy; - double Distance; - > + int index; + int particleId; + int secondaryOf; + std::vector dirVector; dirVector.resize(3); + float initialEnergy; + int termination; + + std::vector Vol_MaterialId; + std::vector Vol_DepositedEnergy; + std::vector Vol_TravelledDistance; + + t->Branch("index", &index, "index/I"); + t->Branch("partId", &particleId, "partId/I"); + t->Branch("secondaryOf", &secondaryOf, "secondaryOf/I"); + t->Branch("dirVector", &dirVector); + t->Branch("energyOnEntrance", &initialEnergy, "energyOnEntrance/F"); + t->Branch("termination", &termination, "termination/I"); + t->Branch("vol_materialId", &Vol_MaterialId); + t->Branch("vol_depositedEnergy", &Vol_DepositedEnergy); + t->Branch("vol_distance", &Vol_TravelledDistance); + + for (const EventHistoryStructure* h : EventHistory) + { + index = h->index; + particleId = h->ParticleId; + secondaryOf = h->SecondaryOf; + dirVector[0] = h->dx; dirVector[1] = h->dy; dirVector[2] = h->dz; + initialEnergy = h->initialEnergy; + termination = h->Termination; + + Vol_MaterialId.clear(); Vol_DepositedEnergy.clear(); Vol_TravelledDistance.clear(); + for (const MaterialHistoryStructure& d : h->Deposition) + { + Vol_MaterialId.push_back(d.MaterialId); + Vol_DepositedEnergy.push_back(d.DepositedEnergy); + Vol_TravelledDistance.push_back(d.Distance); + } + t->Fill(); + } + f.Close(); } -*/ + diff --git a/src/scriptmode/aparticletrackinghistoryinterface.h b/src/scriptmode/aparticletrackinghistoryinterface.h index 06ab8894..1072bb10 100644 --- a/src/scriptmode/aparticletrackinghistoryinterface.h +++ b/src/scriptmode/aparticletrackinghistoryinterface.h @@ -37,7 +37,7 @@ public slots: double getRecordDepositedEnergy(int iParticle, int iRecord); double getRecordDistance(int iParticle, int iRecord); - //bool saveHistoryToTTree(QString fileName); + bool saveHistoryToTree(QString fileName); private: bool checkParticle(int i); From 7a6cf7075497b04a5eba840b82eb55465e6bcf72 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 11 Oct 2018 12:51:20 +0100 Subject: [PATCH 064/140] add button to outputWindow to save tracking history to TTree --- src/common/ahistoryrecords.h | 29 +++++-- src/gui/MainWindowTools/globalscript.cpp | 4 +- src/gui/MainWindowTools/pythonscript.cpp | 4 + src/gui/outputwindow.cpp | 42 ++++++++++ src/gui/outputwindow.h | 4 + src/gui/outputwindow.ui | 27 ++++++ src/main.cpp | 3 + src/modules/eventsdataclass.cpp | 54 +++++++++++- src/modules/eventsdataclass.h | 1 + src/modules/primaryparticletracker.cpp | 7 +- .../aparticletrackinghistoryinterface.cpp | 84 +++++-------------- .../aparticletrackinghistoryinterface.h | 14 ++-- 12 files changed, 192 insertions(+), 81 deletions(-) diff --git a/src/common/ahistoryrecords.h b/src/common/ahistoryrecords.h index e1f77a0c..fb09aff9 100644 --- a/src/common/ahistoryrecords.h +++ b/src/common/ahistoryrecords.h @@ -1,6 +1,9 @@ #ifndef AHISTORYRECORDS #define AHISTORYRECORDS +#include "aparticleonstack.h" + +#include #include struct MaterialHistoryStructure @@ -8,8 +11,8 @@ struct MaterialHistoryStructure MaterialHistoryStructure(int mat, double en, double dis) {MaterialId = mat; DepositedEnergy = en; Distance = dis;} MaterialHistoryStructure(){} int MaterialId; - double DepositedEnergy; - double Distance; + float DepositedEnergy; + float Distance; }; struct EventHistoryStructure @@ -31,19 +34,29 @@ struct EventHistoryStructure int ParticleId; int index; // this is particle index! - "serial number" of the particle int SecondaryOf; + float x, y, z; //creation position float dx, dy, dz; //direction - float initialEnergy; + float initialEnergy; //energy when created TerminationTypes Termination; + QVector Deposition; + + EventHistoryStructure(int ParticleId, int index, int SecondaryOf, double* r, double* v, double energy) : + ParticleId(ParticleId), index(index), SecondaryOf(SecondaryOf), + x(r[0]), y(r[1]), z(r[2]), + dx(v[0]), dy(v[1]), dz(v[2]), initialEnergy(energy) {} + + EventHistoryStructure(const AParticleOnStack* p, int index) : + ParticleId(p->Id), index(index), SecondaryOf(p->secondaryOf), + x(p->r[0]), y(p->r[1]), z(p->r[2]), + dx(p->v[0]), dy(p->v[1]), dz(p->v[2]), + initialEnergy(p->energy) {} - EventHistoryStructure(int ParticleId, int index, int SecondaryOf, double* v, double energy) - : ParticleId(ParticleId), index(index), SecondaryOf(SecondaryOf), dx(v[0]), dy(v[1]), dz(v[2]), initialEnergy(energy) { } EventHistoryStructure(){} - bool isSecondary() const {return SecondaryOf > -1;} - QList Deposition; + bool isSecondary() const {return SecondaryOf > -1;} //utilities - static QStringList getAllDefinedTerminationTypes() {return QStringList({"NotFinished", "Escaped", "AllEnergyDisspated", "Photoelectric", + static QStringList getAllDefinedTerminationTypes() {return QStringList({"NotFinished", "Escaped", "AllEnergyDissipated", "Photoelectric", "ComptonScattering", "NeutronAbsorption", "ErrorDuringTracking", "CreatedOutside", "FoundUntrackableMaterial", "PairProduction", "ElasticScattering", "StoppedOnMonitor"});} diff --git a/src/gui/MainWindowTools/globalscript.cpp b/src/gui/MainWindowTools/globalscript.cpp index 12882b30..393eb5aa 100644 --- a/src/gui/MainWindowTools/globalscript.cpp +++ b/src/gui/MainWindowTools/globalscript.cpp @@ -118,8 +118,8 @@ void MainWindow::createScriptWindow() AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(Detector, GlobSet, EventsDataHub); ScriptWindow->SetInterfaceObject(depo, "depo"); - AParticleTrackingHistoryInterface* pth = new AParticleTrackingHistoryInterface(EventsDataHub->EventHistory); - ScriptWindow->SetInterfaceObject(pth, "pth"); + AParticleTrackingHistoryInterface* pth = new AParticleTrackingHistoryInterface(*EventsDataHub); + ScriptWindow->SetInterfaceObject(pth, "tracklog"); #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager->KNNmodule); diff --git a/src/gui/MainWindowTools/pythonscript.cpp b/src/gui/MainWindowTools/pythonscript.cpp index 6de8f151..6e5a5957 100644 --- a/src/gui/MainWindowTools/pythonscript.cpp +++ b/src/gui/MainWindowTools/pythonscript.cpp @@ -25,6 +25,7 @@ #include "ainterfacetophotonscript.h" #include "ainterfacetomultithread.h" #include "ainterfacetottree.h" +#include "aparticletrackinghistoryinterface.h" #ifdef ANTS_FLANN #include "ainterfacetoknnscript.h" @@ -101,6 +102,9 @@ void MainWindow::createPythonScriptWindow() AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(Detector, GlobSet, EventsDataHub); PythonScriptWindow->SetInterfaceObject(depo, "depo"); + AParticleTrackingHistoryInterface* pth = new AParticleTrackingHistoryInterface(*EventsDataHub); + ScriptWindow->SetInterfaceObject(pth, "tracklog"); + #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager->KNNmodule); PythonScriptWindow->SetInterfaceObject(knn, "knn"); diff --git a/src/gui/outputwindow.cpp b/src/gui/outputwindow.cpp index 797cb7a8..b653d8cf 100644 --- a/src/gui/outputwindow.cpp +++ b/src/gui/outputwindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include OutputWindow::OutputWindow(QWidget *parent, MainWindow *mw, EventsDataClass *eventsDataHub) : QMainWindow(parent), @@ -1640,3 +1641,44 @@ void OutputWindow::on_pbShowAverageOverAll_clicked() addTextitems(&sums, MaxSignal, 0); //add icons with signal text to the scene updateSignalScale(); } + +void OutputWindow::on_pbSaveLog_clicked() +{ + if (EventsDataHub->EventHistory.isEmpty()) + { + message("Log is empty! Make sure to acivate 'Do logs and statistics'\nin MainWindow->Simulation->Accelerators before running a simulation!", this); + return; + } + + QString fileName = QFileDialog::getSaveFileName(this, "Save particle tracking log to ROOT tree", MW->GlobSet->LastOpenDir, "TTree files (*.root)"); + if (fileName.isEmpty()) return; + MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + QFileInfo file(fileName); + if (file.suffix().isEmpty()) fileName += ".root"; + EventsDataHub->saveEventHistoryToTree(fileName); +} + +void OutputWindow::on_pbHelpWithSaveToTree_clicked() +{ + QStringList sl = EventHistoryStructure::getAllDefinedTerminationTypes(); + + QString s = ""; + + s += "index -> particle#\n"; + s += "partId -> index (type) of the particle\n"; + s += "secondaryOf -> -1 if primary, otherwise particle# of the parent\n"; + s += "initialPosition -> vector with the generation position\n"; + s += "direction -> direction of the particle (unit vector)\n"; + s += "initialEnergy -> energy on start\n"; + s += "termination -> how the particle tracking has ended\n"; + for (int i=0; ipteOut->appendPlainText(s); +} diff --git a/src/gui/outputwindow.h b/src/gui/outputwindow.h index 005abbfa..d9b14b56 100644 --- a/src/gui/outputwindow.h +++ b/src/gui/outputwindow.h @@ -95,6 +95,10 @@ private slots: void on_pbShowWavelength_clicked(); + void on_pbSaveLog_clicked(); + + void on_pbHelpWithSaveToTree_clicked(); + protected: bool event(QEvent *event); diff --git a/src/gui/outputwindow.ui b/src/gui/outputwindow.ui index da0d1772..ada090a8 100644 --- a/src/gui/outputwindow.ui +++ b/src/gui/outputwindow.ui @@ -872,6 +872,33 @@ over all events + + + + Qt::Vertical + + + + + + + Save log to TTree + + + + + + + + 20 + 16777215 + + + + ? + + + diff --git a/src/main.cpp b/src/main.cpp index e2c815a0..04126689 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -24,6 +24,7 @@ #include "ainterfacetomultithread.h" #include "ainterfacetowebsocket.h" #include "awebserverinterface.h" +#include "aparticletrackinghistoryinterface.h" #ifdef ANTS_FLANN #include "ainterfacetoknnscript.h" @@ -270,6 +271,8 @@ int main(int argc, char *argv[]) SM.SetInterfaceObject(depo, "depo"); AInterfaceToMultiThread* threads = new AInterfaceToMultiThread(&SM); SM.SetInterfaceObject(threads, "threads"); + AParticleTrackingHistoryInterface* pth = new AParticleTrackingHistoryInterface(EventsDataHub); + SM.SetInterfaceObject(pth, "tracklog"); AInterfaceToWebSocket* web = new AInterfaceToWebSocket(&EventsDataHub); SM.SetInterfaceObject(web, "web"); AWebServerInterface* server = new AWebServerInterface(*Network.WebSocketServer, &EventsDataHub); diff --git a/src/modules/eventsdataclass.cpp b/src/modules/eventsdataclass.cpp index a2bc9345..3ec54a0b 100644 --- a/src/modules/eventsdataclass.cpp +++ b/src/modules/eventsdataclass.cpp @@ -445,7 +445,59 @@ const QVector *EventsDataClass::getEvent(int iev) const const QVector > *EventsDataClass::getTimedEvent(int iev) { - return &TimedEvents.at(iev); + return &TimedEvents.at(iev); +} + +void EventsDataClass::saveEventHistoryToTree(const QString &fileName) const +{ + TFile f(fileName.toLatin1().data(),"RECREATE"); + + TTree t("Log","Particle tracking log"); + + int index; + int particleId; + int secondaryOf; + std::vector pos; pos.resize(3); + std::vector dir; dir.resize(3); + float initialEnergy; + int termination; + + std::vector Vol_MaterialId; + std::vector Vol_DepositedEnergy; + std::vector Vol_TravelledDistance; + + t.Branch("index", &index, "index/I"); + t.Branch("partId", &particleId, "partId/I"); + t.Branch("secondaryOf", &secondaryOf, "secondaryOf/I"); + t.Branch("initialPosition", &pos); + t.Branch("direction", &dir); + t.Branch("initialEnergy", &initialEnergy, "initialEnergy/F"); + t.Branch("termination", &termination, "termination/I"); + t.Branch("vol_materialId", &Vol_MaterialId); + t.Branch("vol_depositedEnergy", &Vol_DepositedEnergy); + t.Branch("vol_distance", &Vol_TravelledDistance); + + for (const EventHistoryStructure* h : EventHistory) + { + index = h->index; + particleId = h->ParticleId; + secondaryOf = h->SecondaryOf; + pos[0] = h->x; pos[1] = h->y; pos[2] = h->z; + dir[0] = h->dx; dir[1] = h->dy; dir[2] = h->dz; + initialEnergy = h->initialEnergy; + termination = h->Termination; + + Vol_MaterialId.clear(); Vol_DepositedEnergy.clear(); Vol_TravelledDistance.clear(); + for (const MaterialHistoryStructure& d : h->Deposition) + { + Vol_MaterialId.push_back(d.MaterialId); + Vol_DepositedEnergy.push_back(d.DepositedEnergy); + Vol_TravelledDistance.push_back(d.Distance); + } + t.Fill(); + } + t.Write(); + f.Close(); } int EventsDataClass::countGoodEvents(int igroup) //counts events passing all filters diff --git a/src/modules/eventsdataclass.h b/src/modules/eventsdataclass.h index 2cc09935..f75ad360 100644 --- a/src/modules/eventsdataclass.h +++ b/src/modules/eventsdataclass.h @@ -49,6 +49,7 @@ class EventsDataClass : public QObject #ifdef SIM // Logs QVector EventHistory; + void saveEventHistoryToTree(const QString& fileName) const; QVector GeneratedPhotonsHistory; //Detection statistics diff --git a/src/modules/primaryparticletracker.cpp b/src/modules/primaryparticletracker.cpp index 07255084..d713f30f 100644 --- a/src/modules/primaryparticletracker.cpp +++ b/src/modules/primaryparticletracker.cpp @@ -63,10 +63,11 @@ bool PrimaryParticleTracker::TrackParticlesOnStack(int eventId) EventHistoryStructure* History; if (SimSet->fLogsStat) - { + { //initializing history record - at the end it will be appended to EventHistory QVector - History = new EventHistoryStructure(ParticleId, counter, ParticleStack->at(0)->secondaryOf, ParticleStack->at(0)->v, ParticleStack->at(0)->energy); - } + //History = new EventHistoryStructure(ParticleId, counter, ParticleStack->at(0)->secondaryOf, ParticleStack->at(0)->v, ParticleStack->at(0)->energy); + History = new EventHistoryStructure(ParticleStack->at(0), counter); + } //setting current position, direction vector, energy and time double r[3]; //position double v[3]; //direction vector diff --git a/src/scriptmode/aparticletrackinghistoryinterface.cpp b/src/scriptmode/aparticletrackinghistoryinterface.cpp index 632a697a..b651cf90 100644 --- a/src/scriptmode/aparticletrackinghistoryinterface.cpp +++ b/src/scriptmode/aparticletrackinghistoryinterface.cpp @@ -1,8 +1,9 @@ #include "aparticletrackinghistoryinterface.h" +#include "eventsdataclass.h" #include "ahistoryrecords.h" -AParticleTrackingHistoryInterface::AParticleTrackingHistoryInterface(QVector &EventHistory) : - EventHistory(EventHistory) {} +AParticleTrackingHistoryInterface::AParticleTrackingHistoryInterface(EventsDataClass &EventsDataHub) : + EventsDataHub(EventsDataHub), EventHistory(EventsDataHub.EventHistory) {} QVariantList AParticleTrackingHistoryInterface::getAllDefinedTerminatorTypes() { @@ -19,13 +20,21 @@ int AParticleTrackingHistoryInterface::getTermination(int iParticle) return EventHistory.at(iParticle)->Termination; } -//QVariantList AParticleTrackingHistoryInterface::getDirection(int i) -//{ -// QVariantList vl; -// if (checkParticle(i)) -// vl << EventHistory.at(i)->dx << EventHistory.at(i)->dy << EventHistory.at(i)->dz; -// return vl; -//} +QVariantList AParticleTrackingHistoryInterface::getDirection(int iParticle) +{ + QVariantList vl; + if (checkParticle(iParticle)) + vl << EventHistory.at(iParticle)->dx << EventHistory.at(iParticle)->dy << EventHistory.at(iParticle)->dz; + return vl; +} + +QVariantList AParticleTrackingHistoryInterface::getInitialPosition(int iParticle) +{ + QVariantList vl; + if (checkParticle(iParticle)) + vl << EventHistory.at(iParticle)->x << EventHistory.at(iParticle)->y << EventHistory.at(iParticle)->z; + return vl; +} int AParticleTrackingHistoryInterface::getParticleId(int iParticle) { @@ -35,8 +44,8 @@ int AParticleTrackingHistoryInterface::getParticleId(int iParticle) //int AParticleTrackingHistoryInterface::sernum(int i) //{ -// if (!checkParticle(i)) return -1; -// return EventHistory.at(i)->index; +// if (!checkParticle(i)) return -1; +// return EventHistory.at(i)->index; //} bool AParticleTrackingHistoryInterface::isSecondary(int iParticle) @@ -45,7 +54,7 @@ bool AParticleTrackingHistoryInterface::isSecondary(int iParticle) return EventHistory.at(iParticle)->isSecondary(); } -int AParticleTrackingHistoryInterface::getParent(int iParticle) +int AParticleTrackingHistoryInterface::getParentIndex(int iParticle) { if (!checkParticle(iParticle)) return -1; return EventHistory.at(iParticle)->SecondaryOf; @@ -106,55 +115,8 @@ bool AParticleTrackingHistoryInterface::checkParticleAndMaterial(int i, int m) return true; } - -#include "TTree.h" -#include "TFile.h" -#include -bool AParticleTrackingHistoryInterface::saveHistoryToTree(QString fileName) +void AParticleTrackingHistoryInterface::saveHistoryToTree(QString fileName) { - TFile f(fileName.toLatin1().data(),"RECREATE"); - - TTree *t = new TTree("","Particle tracking history"); - - int index; - int particleId; - int secondaryOf; - std::vector dirVector; dirVector.resize(3); - float initialEnergy; - int termination; - - std::vector Vol_MaterialId; - std::vector Vol_DepositedEnergy; - std::vector Vol_TravelledDistance; - - t->Branch("index", &index, "index/I"); - t->Branch("partId", &particleId, "partId/I"); - t->Branch("secondaryOf", &secondaryOf, "secondaryOf/I"); - t->Branch("dirVector", &dirVector); - t->Branch("energyOnEntrance", &initialEnergy, "energyOnEntrance/F"); - t->Branch("termination", &termination, "termination/I"); - t->Branch("vol_materialId", &Vol_MaterialId); - t->Branch("vol_depositedEnergy", &Vol_DepositedEnergy); - t->Branch("vol_distance", &Vol_TravelledDistance); - - for (const EventHistoryStructure* h : EventHistory) - { - index = h->index; - particleId = h->ParticleId; - secondaryOf = h->SecondaryOf; - dirVector[0] = h->dx; dirVector[1] = h->dy; dirVector[2] = h->dz; - initialEnergy = h->initialEnergy; - termination = h->Termination; - - Vol_MaterialId.clear(); Vol_DepositedEnergy.clear(); Vol_TravelledDistance.clear(); - for (const MaterialHistoryStructure& d : h->Deposition) - { - Vol_MaterialId.push_back(d.MaterialId); - Vol_DepositedEnergy.push_back(d.DepositedEnergy); - Vol_TravelledDistance.push_back(d.Distance); - } - t->Fill(); - } - f.Close(); + EventsDataHub.saveEventHistoryToTree(fileName.toLatin1().data()); } diff --git a/src/scriptmode/aparticletrackinghistoryinterface.h b/src/scriptmode/aparticletrackinghistoryinterface.h index 1072bb10..304f22e5 100644 --- a/src/scriptmode/aparticletrackinghistoryinterface.h +++ b/src/scriptmode/aparticletrackinghistoryinterface.h @@ -14,30 +14,32 @@ class AParticleTrackingHistoryInterface : public AScriptInterface { Q_OBJECT public: - AParticleTrackingHistoryInterface(QVector& EventHistory); + AParticleTrackingHistoryInterface(EventsDataClass& EventsDataHub); private: - QVector& EventHistory; + EventsDataClass& EventsDataHub; + const QVector& EventHistory; public slots: int countParticles() {return EventHistory.size();} int getParticleId(int iParticle); bool isSecondary(int iParticle); - int getParent(int iParticle); + int getParentIndex(int iParticle); double getInitialEnergy(int iParticle); + QVariantList getInitialPosition(int iParticle); + QVariantList getDirection(int iParticle); int getTermination(int iParticle); + //int sernum(int i); QVariantList getAllDefinedTerminatorTypes(); - //QVariantList getDirection(int i); - //int sernum(int i); int countRecords(int iParticle); int getRecordMaterial(int iParticle, int iRecord); double getRecordDepositedEnergy(int iParticle, int iRecord); double getRecordDistance(int iParticle, int iRecord); - bool saveHistoryToTree(QString fileName); + void saveHistoryToTree(QString fileName); private: bool checkParticle(int i); From 60a9d9f19122ed5b1dce6985f943ba76a1f9121e Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 11 Oct 2018 18:49:51 +0100 Subject: [PATCH 065/140] add help for methods in interface to tracklog script --- .../aparticletrackinghistoryinterface.cpp | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/scriptmode/aparticletrackinghistoryinterface.cpp b/src/scriptmode/aparticletrackinghistoryinterface.cpp index b651cf90..15170302 100644 --- a/src/scriptmode/aparticletrackinghistoryinterface.cpp +++ b/src/scriptmode/aparticletrackinghistoryinterface.cpp @@ -3,7 +3,28 @@ #include "ahistoryrecords.h" AParticleTrackingHistoryInterface::AParticleTrackingHistoryInterface(EventsDataClass &EventsDataHub) : - EventsDataHub(EventsDataHub), EventHistory(EventsDataHub.EventHistory) {} + EventsDataHub(EventsDataHub), EventHistory(EventsDataHub.EventHistory) +{ + H["countParticles"] = "Number of entries in the log"; + + H["getParticleId"] = "Particle id of this particle"; + H["isSecondary"] = "Returns true if this is the primary particle."; + H["getParentIndex"] = "If it is primary particle, returns -1. Otherwise returns index (entry number) of the parent"; + H["getInitialEnergy"] = "Returns energy which the particle had when created."; + H["getInitialPosition"] = "Returns array of XYZ of the position where the particle was created"; + H["getDirection"] = "Return unit vector (XYZ components) of the particle's direction"; + H["getTermination"] = "Returns int number corresponding to how the tracking of the particle has ended.\n" + "Use getAllDefinedTerminatorTypes() method to get the list of all possible terminator values"; + + H["getAllDefinedTerminatorTypes"] = "Get the list of all possible values of the termination"; + + H["countRecords"] = "Returns the number of volumes the particle passed during tracking"; + H["getRecordMaterial"] = "Returns the list of material indexes of the crossed volumes"; + H["getRecordDepositedEnergy"] = "Returns energies depositied in all crossed volumes"; + H["getRecordDistance"] = "Returns distances travelled by the particle in each volume"; + + H["saveHistoryToTree"] = "Save particle tracking log to a CERN root tree"; +} QVariantList AParticleTrackingHistoryInterface::getAllDefinedTerminatorTypes() { From d9362d0d03941a2aa7a111cafa671cfaf1340630 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 12 Oct 2018 11:13:12 +0100 Subject: [PATCH 066/140] add in GUI help on PM thickness --- src/gui/mainwindow.cpp | 16 ++++++++++++++++ src/gui/mainwindow.h | 2 ++ src/gui/mainwindow.ui | 15 ++++++++++++++- src/gui/materialinspectorwindow.cpp | 2 +- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 07fc1379..43d1872d 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4975,3 +4975,19 @@ void MainWindow::on_pbStopScan_clicked() SimulationManager->StopSimulation(); qApp->processEvents(); } + +void MainWindow::on_pbPMtypeHelp_clicked() +{ + QString s = "Note that photon detection test is triggered\n" + " as soon as a photon eneters the PM volume!\n\n" + "That means that the material of the PM is important\n" + " only for the material interface\n" + " (Fresnel/Snell's + optical overrides)\n\n" + "The PM thickness matters only for positioning\n" + " of the volume in the detector geometry.\n\n" + "For simulation of, e.g., PMT structure (window +\n" + " photocathode) one has to add the window\n" + " volume to the geometry and the PM object should\n" + " represent the photocathode."; + message(s, this); +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 1c5b1af3..94196b24 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -611,6 +611,8 @@ private slots: void on_pbStopScan_clicked(); + void on_pbPMtypeHelp_clicked(); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 8a44be01..7b03d52f 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -920,7 +920,7 @@ Data: matrix NumPixelsInX by NumPixelsInY of values 0..1 - 420 + 460 30 51 22 @@ -1185,6 +1185,19 @@ Data: matrix NumPixelsInX by NumPixelsInY of values 0..1 + + + + 410 + 34 + 29 + 23 + + + + ? + + diff --git a/src/gui/materialinspectorwindow.cpp b/src/gui/materialinspectorwindow.cpp index 296d1d58..9a35faca 100644 --- a/src/gui/materialinspectorwindow.cpp +++ b/src/gui/materialinspectorwindow.cpp @@ -1614,7 +1614,7 @@ void MaterialInspectorWindow::on_pbRename_clicked() { if (!ui->labMatWasModified->text().simplified().isEmpty()) { - message("Material properties were modified!\nUpdate, add as new or cancel changes before renaming"); + message("Material properties were modified!\nUpdate, add as new or cancel changes before renaming", this); return; } From b55ad52a7b9edba681ef11e4f1de633282e113ac Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 12 Oct 2018 13:24:23 +0100 Subject: [PATCH 067/140] crestored compatibility with old config containing WLS optical override --- src/OpticalOverrides/awaveshifteroverride.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 6e123dd4..84536c19 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -8,6 +8,7 @@ #include "ajsontools.h" #include +#include #include "TMath.h" #include "TRandom2.h" @@ -213,7 +214,11 @@ void AWaveshifterOverride::writeToJson(QJsonObject &json) const bool AWaveshifterOverride::readFromJson(const QJsonObject &json) { - if ( !parseJson(json, "ReemissionModel", ReemissionModel) ) return false; + if ( !parseJson(json, "ReemissionModel", ReemissionModel) ) + { + ReemissionModel = 1; + qWarning() << "Load WLS optical override: ReemissionModel not given, assuming Lambert back"; + } QJsonArray arRP; if ( !parseJson(json, "ReemissionProbability", arRP) ) return false; From bda01b627fd95d2477b4863bdbedc967a47b6baa Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 12 Oct 2018 13:32:59 +0100 Subject: [PATCH 068/140] if override returns error, doing fresnel --- src/modules/aphotontracer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/aphotontracer.cpp b/src/modules/aphotontracer.cpp index 2f88ca98..c36ce041 100644 --- a/src/modules/aphotontracer.cpp +++ b/src/modules/aphotontracer.cpp @@ -268,7 +268,8 @@ void APhotonTracer::TracePhoton(const APhoton* Photon) fDoFresnel = true; break; //switch break default: - qCritical() << "override reported an error!"; + qCritical() << "override error - doing fresnel instead!"; + fDoFresnel = true; } } else fDoFresnel = true; From 10a23865d75ab23a8358fe56592f9448cd9be42a Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 12 Oct 2018 16:00:34 +0100 Subject: [PATCH 069/140] ++ --- src/OpticalOverrides/aopticaloverride.h | 9 +- .../aopticaloverridescriptinterface.cpp | 4 + src/OpticalOverrides/awaveshifteroverride.cpp | 1 + src/common/asimulationstatistics.h | 4 + .../aopticaloverridetester.cpp | 231 ++++++++++-------- .../MainWindowTools/aopticaloverridetester.h | 16 ++ .../MainWindowTools/aopticaloverridetester.ui | 5 + 7 files changed, 163 insertions(+), 107 deletions(-) diff --git a/src/OpticalOverrides/aopticaloverride.h b/src/OpticalOverrides/aopticaloverride.h index 5624be4f..6a4fae5d 100644 --- a/src/OpticalOverrides/aopticaloverride.h +++ b/src/OpticalOverrides/aopticaloverride.h @@ -21,8 +21,13 @@ class AOpticalOverride { public: enum OpticalOverrideResultEnum {NotTriggered, Absorbed, Forward, Back, _Error_}; //return status for photon tracing: - enum ScatterStatusEnum {SpikeReflection, LobeReflection, LambertianReflection, - Absorption, Transmission, Error, UnclassifiedReflection, Empty, Fresnel}; //detailed status for statistics only - used by override tester only + enum ScatterStatusEnum { + Absorption, + SpikeReflection, LobeReflection, LambertianReflection, + UnclassifiedReflection, + Transmission, + Empty, Fresnel, Error + }; //detailed status for statistics only - used by override tester only AOpticalOverride(AMaterialParticleCollection* MatCollection, int MatFrom, int MatTo) : MatCollection(MatCollection), MatFrom(MatFrom), MatTo(MatTo) {} diff --git a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp index 9aedcfd6..a0828f25 100644 --- a/src/OpticalOverrides/aopticaloverridescriptinterface.cpp +++ b/src/OpticalOverrides/aopticaloverridescriptinterface.cpp @@ -1,6 +1,7 @@ #include "aopticaloverridescriptinterface.h" #include "aphoton.h" #include "amaterialparticlecolection.h" +#include "asimulationstatistics.h" #include #include @@ -187,11 +188,13 @@ void AOpticalOverrideScriptInterface::SetDirection(double vx, double vy, double void AOpticalOverrideScriptInterface::SetTime(double time) { Photon->time = time; + Photon->SimStat->timeChanged++; } void AOpticalOverrideScriptInterface::AddTime(double dt) { Photon->time += dt; + Photon->SimStat->timeChanged++; } double AOpticalOverrideScriptInterface::getWaveIndex() @@ -202,6 +205,7 @@ double AOpticalOverrideScriptInterface::getWaveIndex() void AOpticalOverrideScriptInterface::setWaveIndex(int waveIndex) { Photon->waveIndex = waveIndex; + Photon->SimStat->wavelengthChanged++; } double AOpticalOverrideScriptInterface::getRefractiveIndexFrom() diff --git a/src/OpticalOverrides/awaveshifteroverride.cpp b/src/OpticalOverrides/awaveshifteroverride.cpp index 84536c19..ba7c4e99 100644 --- a/src/OpticalOverrides/awaveshifteroverride.cpp +++ b/src/OpticalOverrides/awaveshifteroverride.cpp @@ -101,6 +101,7 @@ AOpticalOverride::OpticalOverrideResultEnum AWaveshifterOverride::calculate(ATra } while (waveIndex < Photon->waveIndex); //conserving energy + Photon->SimStat->wavelengthChanged++; Photon->waveIndex = waveIndex; if (ReemissionModel == 0) diff --git a/src/common/asimulationstatistics.h b/src/common/asimulationstatistics.h index 76b2564f..33c44086 100644 --- a/src/common/asimulationstatistics.h +++ b/src/common/asimulationstatistics.h @@ -53,6 +53,10 @@ class ASimulationStatistics QSet MustNotInclude_Volumes; //fast QVector MustInclude_Volumes; //v.slow + //only for optical override tester! + long wavelengthChanged = 0; + long timeChanged = 0; + QVector Monitors; private: diff --git a/src/gui/MainWindowTools/aopticaloverridetester.cpp b/src/gui/MainWindowTools/aopticaloverridetester.cpp index 47de0ed4..5a47e9d2 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.cpp +++ b/src/gui/MainWindowTools/aopticaloverridetester.cpp @@ -96,8 +96,6 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() { if ( !testOverride() ) return; - //TODO wavelength shifted - int numPhotons = ui->sbST_number->value(); QVector Back(91, 0), Forward(91, 0), Absorb(91, 0), NotTrigger(91, 0); QVector Spike(91, 0), BackLobe(91, 0), BackLambert(91, 0), WaveShifted(91, 0); @@ -157,13 +155,42 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() Spike[iAngle] /= numPhotons; BackLobe[iAngle] /= numPhotons; BackLambert[iAngle] /= numPhotons; + + WaveShifted[iAngle] = ph.SimStat->wavelengthChanged / numPhotons; + ph.SimStat->wavelengthChanged = 0; } - if ( ui->cobPrVsAngle_WhatToCollect->currentIndex() == 1 ) + int what = ui->cobPrVsAngle_WhatToCollect->currentIndex(); + switch (what) { + case 0: + { + TGraph *gN, *gA, *gB, *gF = 0; + gN = GraphWindow->MakeGraph(&Angle, &NotTrigger, 2, "Angle, deg", "Fraction", 0, 1, 1, 2, "", true); + gN->SetMinimum(0); + gN->SetMaximum(1.05); + gN->SetTitle("Not triggered"); + gA = GraphWindow->MakeGraph(&Angle, &Absorb, 1, "Angle", "", 0, 1, 1, 2, "", true); + gA->SetTitle("Absorption"); + gB = GraphWindow->MakeGraph(&Angle, &Back, 3, "Angle", "", 0, 1, 1, 2, "", true); + gB->SetTitle("Back"); + gF = GraphWindow->MakeGraph(&Angle, &Forward, 4, "Angle", "", 0, 1, 1, 2, "", true); + gF->SetTitle("Forward"); + + GraphWindow->Draw(gN, "AL"); + GraphWindow->Draw(gA, "Lsame"); + GraphWindow->Draw(gB, "Lsame"); + GraphWindow->Draw(gF, "Lsame"); + + GraphWindow->on_pbAddLegend_clicked(); + break; + } + case 1: + { TGraph *gS, *gL, *gD, *gT; - gT = GraphWindow->MakeGraph(&Angle, &Back, 2, "Angle", "", 0, 1, 1, 2, "", true); + gT = GraphWindow->MakeGraph(&Angle, &Back, 2, "Angle, deg", "Fraction", 0, 1, 1, 2, "", true); gT->SetMinimum(0); + gT->SetMaximum(1.05); gT->SetTitle("All reflections"); gS = GraphWindow->MakeGraph(&Angle, &Spike, 1, "Angle", "", 0, 1, 1, 2, "", true); gS->SetTitle("Spike"); @@ -178,26 +205,17 @@ void AOpticalOverrideTester::on_pbST_RvsAngle_clicked() GraphWindow->Draw(gD, "Lsame"); GraphWindow->on_pbAddLegend_clicked(); - } - else - { - TGraph *gN, *gA, *gB, *gF; - gN = GraphWindow->MakeGraph(&Angle, &NotTrigger, 2, "Angle", "", 0, 1, 1, 2, "", true); - gN->SetMinimum(0); - gN->SetTitle("Not triggered"); - gA = GraphWindow->MakeGraph(&Angle, &Absorb, 1, "Angle", "", 0, 1, 1, 2, "", true); - gA->SetTitle("Absorption"); - gB = GraphWindow->MakeGraph(&Angle, &Back, 3, "Angle", "", 0, 1, 1, 2, "", true); - gB->SetTitle("Back"); - gF = GraphWindow->MakeGraph(&Angle, &Forward, 4, "Angle", "", 0, 1, 1, 2, "", true); - gF->SetTitle("Forward"); - - GraphWindow->Draw(gN, "AL"); - GraphWindow->Draw(gA, "Lsame"); - GraphWindow->Draw(gB, "Lsame"); - GraphWindow->Draw(gF, "Lsame"); - + break; + } + case 2: + { + TGraph *gW = GraphWindow->ConstructTGraph(Angle, WaveShifted, "Wavelength shifted", "Angle, deg", "Fraction", 4, 0, 1, 4, 1, 2); + gW->SetMaximum(1.05); + gW->SetMinimum(0); + GraphWindow->Draw(gW, "AL"); GraphWindow->on_pbAddLegend_clicked(); + break; + } } delete ph.SimStat; @@ -219,13 +237,14 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() double d = 0.5; //offset - for drawing only //preparing and running cycle with photons - double abs, back, forw, notTrigger, spike, lobe, lamb; - abs = back = forw = notTrigger = spike = lobe = lamb = 0; + TH1D* hist1 = new TH1D("", "", 100, 0, 0); hist1->GetXaxis()->SetTitle("Backscattering angle, degrees"); APhoton ph; ph.SimStat = new ASimulationStatistics(); + AReportForOverride rep; + const int waveIndex = getWaveIndex(); const int numPhot = ui->sbST_number->value(); for (int i = 0; i < numPhot; i++) @@ -240,31 +259,30 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() //in case of absorption or not triggered override, do not build tracks! switch (result) { - case AOpticalOverride::Absorbed: abs++; continue; // ! -> - case AOpticalOverride::NotTriggered: notTrigger++; continue; // ! -> - - case AOpticalOverride::Forward: forw++; break; - case AOpticalOverride::Back: back++; break; - default:; + case AOpticalOverride::Absorbed: rep.abs++; continue; // ! -> + case AOpticalOverride::NotTriggered: rep.notTrigger++; continue; // ! -> + case AOpticalOverride::Forward: rep.forw++; break; + case AOpticalOverride::Back: rep.back++; break; + default: rep.error++; continue; // ! -> } Color_t col; Int_t type; if ((*pOV)->Status == AOpticalOverride::SpikeReflection) { - spike++; + rep.Bspike++; type = 0; col = 6; //0,magenta for Spike } else if ((*pOV)->Status == AOpticalOverride::LobeReflection) { - lobe++; + rep.Blobe++; type = 1; col = 7; //1,teal for Lobe } else if ((*pOV)->Status == AOpticalOverride::LambertianReflection) { - lamb++; + rep.Blamb++; type = 2; col = 3; //2,grean for lambert } @@ -286,27 +304,9 @@ void AOpticalOverrideTester::on_pbCSMtestmany_clicked() GraphWindow->Draw(hist1); on_pbST_showTracks_clicked(); - ui->pte->clear(); - QString t = "Processes:\n"; - if (abs > 0) t += QString(" Absorption: %1% (%2)\n").arg(abs/numPhot*100.0).arg(abs); - if (back > 0) t += QString(" Back: %1% (%2)\n").arg(back/numPhot*100.0).arg(back); - if (forw) t += QString(" Forward: %1% (%2)\n").arg(forw/numPhot*100.0).arg(forw); - if (notTrigger) t += QString(" Not triggered: %1% (%2)\n").arg(notTrigger/numPhot*100.0).arg(notTrigger); - t += "\n"; - - if (back > 0) - { - //show stat of processes - t += "Backscattering composition:\n"; - if (spike > 0) t += QString(" Specular spike: %1% (%2)\n").arg(spike/back*100.0).arg(spike); - if (lobe > 0) t += QString(" Diffuse lobe: %1% (%2)\n").arg(lobe/back*100.0).arg(lobe); - if (lamb > 0) t += QString(" Lambertian: %1% (%2)\n").arg(lamb/back*100.0).arg(lamb); - } - - - ui->pte->appendPlainText(t); - ui->pte->moveCursor(QTextCursor::Start); - ui->pte->ensureCursorVisible(); + rep.waveChanged = ph.SimStat->wavelengthChanged; + rep.timeChanged = ph.SimStat->timeChanged; + reportStatistics(rep, numPhot); delete ph.SimStat; } @@ -358,6 +358,7 @@ void AOpticalOverrideTester::showGeometry() void AOpticalOverrideTester::on_pbST_showTracks_clicked() { + GeometryWindow->ShowAndFocus(); showGeometry(); if (tracks.isEmpty()) return; @@ -422,79 +423,64 @@ void AOpticalOverrideTester::on_pbST_uniform_clicked() { if ( !testOverride() ) return; - TVector3 SurfNorm(0, 0, -1.0); - double N[3]; - N[0] = SurfNorm.X(); - N[1] = SurfNorm.Y(); - N[2] = SurfNorm.Z(); + double N[3]; //normal + N[0] = 0; + N[1] = 0; + N[2] = -1.0; - double K[3]; + double K[3]; //photon direction - new for every photon! - int abs, spike, lobe, lamb; - abs = spike = lobe = lamb = 0; - TH1D* hist1; - hist1 = new TH1D("", "", 100, 0, 0); + TH1D* hist1 = new TH1D("", "", 100, 0, 0); hist1->GetXaxis()->SetTitle("Backscattering angle, degrees"); - int num = ui->sbST_number->value(); + const int waveIndex = getWaveIndex(); + const int numPhot = ui->sbST_number->value(); APhoton ph; ph.SimStat = new ASimulationStatistics(); + AReportForOverride rep; - for (int i=0; iRndm(); double angle = asin(sqrt(sin2angle)); double yOff = cos(angle), zOff = -sin(angle); - N[0] = 0; N[1] = 0; N[2] = -1; // convention of photon tracer - normal is med1->med2 K[0] = 0; K[1] = yOff; K[2] = zOff; // -z direction on xy plane (incidence angle from 90 to 0) ph.v[0] = K[0]; ph.v[1] = K[1]; ph.v[2] = K[2]; - ph.waveIndex = -1; - (*pOV)->calculate(*Resources, &ph, N); - - if ((*pOV)->Status == AOpticalOverride::Absorption) - { - abs++; - continue; - } - else if ((*pOV)->Status == AOpticalOverride::SpikeReflection) - spike++; - else if ((*pOV)->Status == AOpticalOverride::LobeReflection) - lobe++; - else if ((*pOV)->Status == AOpticalOverride::LambertianReflection) - lamb++; - else - { - qCritical()<<"Unknown process!"; - exit(666); - } + ph.time = 0; + ph.waveIndex = waveIndex; + + AOpticalOverride::OpticalOverrideResultEnum result = (*pOV)->calculate(*Resources, &ph, N); + + switch (result) + { + case AOpticalOverride::Absorbed: rep.abs++; break; + case AOpticalOverride::NotTriggered: rep.notTrigger++; break; + case AOpticalOverride::Forward: rep.forw++; break; + case AOpticalOverride::Back: rep.back++; break; + default: rep.error++; + } + + if ((*pOV)->Status == AOpticalOverride::SpikeReflection) rep.Bspike++; + else if ((*pOV)->Status == AOpticalOverride::LobeReflection) rep.Blobe++; + else if ((*pOV)->Status == AOpticalOverride::LambertianReflection) rep.Blamb++; double costr = N[0]*K[0] + N[1]*K[1] + N[2]*K[2]; hist1->Fill(180.0 / TMath::Pi() * acos(costr)); - } + } - //show cos angle hist GraphWindow->Draw(hist1); - //show stat of processes - int sum = abs + spike + lobe + lamb; - QString str = "Scat probability: "+QString::number(1.0*(sum-abs)/num, 'g', 4) + " Processes:"+ - QString::number(abs) + "/" + - QString::number(spike) + "/" + - QString::number(lobe) + "/" + - QString::number(lamb); - if (sum>0) - { - str += " (" + QString::number(1.0*abs/sum, 'g', 3) + "/" + - QString::number(1.0*spike/sum, 'g', 3) + "/" + - QString::number(1.0*lobe/sum, 'g', 3) + "/" + - QString::number(1.0*lamb/sum, 'g', 3) + ")"; - } - //ui->leST_out->setText(str); + rep.waveChanged = ph.SimStat->wavelengthChanged; + rep.timeChanged = ph.SimStat->timeChanged; + reportStatistics(rep, numPhot); + + showGeometry(); //to clear track vis + delete ph.SimStat; } @@ -520,3 +506,38 @@ void AOpticalOverrideTester::on_ledAngle_editingFinished() showGeometry(); } + +void AOpticalOverrideTester::reportStatistics(const AReportForOverride &rep, int numPhot) +{ + ui->pte->clear(); + + QString t; + if (rep.error > 0) t += QString("Error detected: %1\n\n").arg(rep.error); + + t += "Processes:\n"; + if (rep.abs > 0) t += QString(" Absorption: %1% (%2)\n").arg(rep.abs/numPhot*100.0).arg(rep.abs); + if (rep.back > 0) t += QString(" Back: %1% (%2)\n").arg(rep.back/numPhot*100.0).arg(rep.back); + if (rep.forw) t += QString(" Forward: %1% (%2)\n").arg(rep.forw/numPhot*100.0).arg(rep.forw); + if (rep.notTrigger) t += QString(" Not triggered: %1% (%2)\n").arg(rep.notTrigger/numPhot*100.0).arg(rep.notTrigger); + t += "\n"; + + if (rep.back > 0) + { + //show stat of processes + t += "Backscattering composition:\n"; + if (rep.Bspike > 0) t += QString(" Specular spike: %1% (%2)\n").arg(rep.Bspike/rep.back*100.0).arg(rep.Bspike); + if (rep.Blobe > 0) t += QString(" Diffuse lobe: %1% (%2)\n").arg(rep.Blobe/rep.back*100.0).arg(rep.Blobe); + if (rep.Blamb > 0) t += QString(" Lambertian: %1% (%2)\n").arg(rep.Blamb/rep.back*100.0).arg(rep.Blamb); + } + + if (rep.waveChanged > 0) + t += QString("\nWavelength changed: %1 (%2)\n").arg(rep.waveChanged/numPhot*100.0).arg(rep.waveChanged); + + if (rep.timeChanged > 0) + t += QString("\nTime changed: %1 (%2)\n").arg(rep.timeChanged/numPhot*100.0).arg(rep.timeChanged); + + + ui->pte->appendPlainText(t); + ui->pte->moveCursor(QTextCursor::Start); + ui->pte->ensureCursorVisible(); +} diff --git a/src/gui/MainWindowTools/aopticaloverridetester.h b/src/gui/MainWindowTools/aopticaloverridetester.h index c2276361..1d344548 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.h +++ b/src/gui/MainWindowTools/aopticaloverridetester.h @@ -11,6 +11,21 @@ namespace Ui { class AOpticalOverrideTester; } +struct AReportForOverride +{ + double abs = 0; + double back = 0; + double forw = 0; + double notTrigger = 0; + double error = 0; + + double Bspike = 0; + double Blobe = 0; + double Blamb = 0; + + double waveChanged = 0; + double timeChanged = 0; +}; class AMaterialParticleCollection; class AOpticalOverride; class MainWindow; @@ -63,6 +78,7 @@ private slots: bool testOverride(); int getWaveIndex(); const TVector3 getPhotonVector(); + void reportStatistics(const AReportForOverride& rep, int numPhot); }; diff --git a/src/gui/MainWindowTools/aopticaloverridetester.ui b/src/gui/MainWindowTools/aopticaloverridetester.ui index 5bcf0ac6..a1467ea0 100644 --- a/src/gui/MainWindowTools/aopticaloverridetester.ui +++ b/src/gui/MainWindowTools/aopticaloverridetester.ui @@ -352,6 +352,11 @@ the incoming photon direction is positive. Backscattering + + + Wavelength shift + + From 29bbd890b29a7631226d815cde520716e3f30a47 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 12 Oct 2018 17:32:19 +0100 Subject: [PATCH 070/140] ++ --- src/gui/ascriptwindow.h | 2 +- src/scriptmode/coreinterfaces.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/ascriptwindow.h b/src/gui/ascriptwindow.h index 1431c481..d469a227 100644 --- a/src/gui/ascriptwindow.h +++ b/src/gui/ascriptwindow.h @@ -36,7 +36,7 @@ class AScriptWindow : public QMainWindow explicit AScriptWindow(AScriptManager *ScriptManager, bool LightMode, QWidget *parent); ~AScriptWindow(); - void SetInterfaceObject(QObject *interfaceObject, QString name = ""); + void SetInterfaceObject(QObject *interfaceObject, QString name = ""); // if not lightMode, do not forget to call UpdateAllTabs() after all units were registered! void UpdateAllTabs(); //highlighter, helper etc void SetShowEvaluationResult(bool flag) {ShowEvalResult = flag;} //if false, window only reports "success", ptherwise eval result is shown diff --git a/src/scriptmode/coreinterfaces.cpp b/src/scriptmode/coreinterfaces.cpp index 774e9c6d..3775bb21 100644 --- a/src/scriptmode/coreinterfaces.cpp +++ b/src/scriptmode/coreinterfaces.cpp @@ -52,6 +52,7 @@ AInterfaceToCore::AInterfaceToCore(AScriptManager* ScriptManager) : H["getFittedArr"] = "Used with setCurveFitter. Extracts the fitted values of y for an array of x"; //DepRem["isFileExists"] = "Deprecated. Use file.isFileExists method"; + DepRem["str"] = "Deprecated. Use .toFixed(n) javaScript method. E.g.: 'var i=123.456; i.toFixed(2)'"; } AInterfaceToCore::AInterfaceToCore(const AInterfaceToCore &other) : From c3f4db13dad61b38b1c4bf19ad69899a675a6c84 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 14 Oct 2018 13:35:47 +0100 Subject: [PATCH 071/140] updated and cleaned up registration of script unit interfaces --- .../ascriptopticaloverride.cpp | 4 +- src/common/aglobalsettings.cpp | 2 +- .../MainWindowDetectorConstructor.cpp | 4 +- src/gui/MainWindowTools/globalscript.cpp | 55 ++++++----- src/gui/MainWindowTools/pythonscript.cpp | 46 +++++----- src/gui/ascriptwindow.cpp | 92 ++++++++++++++----- src/gui/ascriptwindow.h | 18 ++-- src/gui/detectoraddonswindow.cpp | 4 +- src/gui/globalsettingswindowclass.cpp | 8 +- src/gui/mainwindow.cpp | 4 +- src/main.cpp | 40 ++++---- src/scriptmode/ajavascriptmanager.cpp | 61 ++++++++++-- src/scriptmode/ajavascriptmanager.h | 7 +- src/scriptmode/apythonscriptmanager.cpp | 30 ++++++ src/scriptmode/apythonscriptmanager.h | 5 +- src/scriptmode/ascriptinterfacefactory.h | 2 +- src/scriptmode/ascriptmanager.cpp | 3 + src/scriptmode/ascriptmanager.h | 7 +- 18 files changed, 264 insertions(+), 128 deletions(-) diff --git a/src/OpticalOverrides/ascriptopticaloverride.cpp b/src/OpticalOverrides/ascriptopticaloverride.cpp index a40e01e7..bb80fb52 100644 --- a/src/OpticalOverrides/ascriptopticaloverride.cpp +++ b/src/OpticalOverrides/ascriptopticaloverride.cpp @@ -128,10 +128,10 @@ void AScriptOpticalOverride::openScriptWindow(QWidget *caller) AOpticalOverrideScriptInterface* interfaceObject = new AOpticalOverrideScriptInterface(MatCollection, RandGen); interfaceObject->configure(&phot, normal, MatFrom, MatTo); interfaceObject->setObjectName("photon"); - sw->SetInterfaceObject(interfaceObject, "photon"); //takes ownership + sw->RegisterInterface(interfaceObject, "photon"); //takes ownership AMathScriptInterface* math = new AMathScriptInterface(RandGen); math->setObjectName("math"); - sw->SetInterfaceObject(math, "math"); //takes ownership + sw->RegisterInterface(math, "math"); //takes ownership sw->ConfigureForLightMode(&Script, "Optical override: custom script", example); sw->setWindowModality(Qt::ApplicationModal); diff --git a/src/common/aglobalsettings.cpp b/src/common/aglobalsettings.cpp index 1fba3fd1..87b68aa5 100644 --- a/src/common/aglobalsettings.cpp +++ b/src/common/aglobalsettings.cpp @@ -88,7 +88,7 @@ AGlobalSettings::AGlobalSettings() //running root TStyle script AJavaScriptManager* SM = new AJavaScriptManager(0); AInterfaceToGStyleScript* GStyleInterface = new AInterfaceToGStyleScript(); //deleted by the SM - SM->SetInterfaceObject(GStyleInterface); + SM->RegisterInterfaceAsGlobal(GStyleInterface); SM->Evaluate(RootStyleScript); SM->deleteLater(); } diff --git a/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp b/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp index e451a408..b3d49a81 100644 --- a/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp +++ b/src/gui/MainWindowTools/MainWindowDetectorConstructor.cpp @@ -263,10 +263,12 @@ void MainWindow::on_pbPositionScript_clicked() GenScriptWindow->ConfigureForLightMode(&Detector->PMarrays[ul].PositioningScript, title, example); PMscriptInterface = new InterfaceToPMscript(); - GenScriptWindow->SetInterfaceObject(PMscriptInterface); + GenScriptWindow->RegisterInterfaceAsGlobal(PMscriptInterface); + GenScriptWindow->RegisterCoreInterfaces(); connect(GenScriptWindow, &AScriptWindow::success, this, &MainWindow::PMscriptSuccess); // ***!!! uses ScriptWindow directly! recallGeometryOfLocalScriptWindow(); + GenScriptWindow->UpdateGui(); GenScriptWindow->show(); } diff --git a/src/gui/MainWindowTools/globalscript.cpp b/src/gui/MainWindowTools/globalscript.cpp index 556259a0..0071fa2f 100644 --- a/src/gui/MainWindowTools/globalscript.cpp +++ b/src/gui/MainWindowTools/globalscript.cpp @@ -53,105 +53,102 @@ void MainWindow::createScriptWindow() // interface objects are owned after this by the ScriptManager! - ScriptWindow->SetInterfaceObject(0); //initialization + ScriptWindow->RegisterCoreInterfaces(); AInterfaceToMultiThread* threads = new AInterfaceToMultiThread(SM); - ScriptWindow->SetInterfaceObject(threads, "threads"); + ScriptWindow->RegisterInterface(threads, "threads"); AInterfaceToConfig* conf = new AInterfaceToConfig(Config); QObject::connect(conf, SIGNAL(requestReadRasterGeometry()), GeometryWindow, SLOT(readRasterWindowProperties())); - ScriptWindow->SetInterfaceObject(conf, "config"); + ScriptWindow->RegisterInterface(conf, "config"); AInterfaceToAddObjScript* geo = new AInterfaceToAddObjScript(Detector); connect(geo, SIGNAL(requestShowCheckUpWindow()), CheckUpWindow, SLOT(showNormal())); - ScriptWindow->SetInterfaceObject(geo, "geo"); + ScriptWindow->RegisterInterface(geo, "geo"); AInterfaceToMinimizerJavaScript* mini = new AInterfaceToMinimizerJavaScript(SM); - ScriptWindow->SetInterfaceObject(mini, "mini"); //mini should be before sim to handle abort correctly + ScriptWindow->RegisterInterface(mini, "mini"); //mini should be before sim to handle abort correctly AInterfaceToData* dat = new AInterfaceToData(Config, EventsDataHub); QObject::connect(dat, SIGNAL(RequestEventsGuiUpdate()), Rwindow, SLOT(onRequestEventsGuiUpdate())); - ScriptWindow->SetInterfaceObject(dat, "events"); + ScriptWindow->RegisterInterface(dat, "events"); InterfaceToSim* sim = new InterfaceToSim(SimulationManager, EventsDataHub, Config, GlobSet.RecNumTreads); QObject::connect(sim, SIGNAL(requestStopSimulation()), SimulationManager, SLOT(StopSimulation())); - ScriptWindow->SetInterfaceObject(sim, "sim"); + ScriptWindow->RegisterInterface(sim, "sim"); InterfaceToReconstructor* rec = new InterfaceToReconstructor(ReconstructionManager, Config, EventsDataHub, TmpHub, GlobSet.RecNumTreads); QObject::connect(rec, SIGNAL(RequestStopReconstruction()), ReconstructionManager, SLOT(requestStop())); QObject::connect(rec, SIGNAL(RequestUpdateGuiForManifest()), Rwindow, SLOT(onManifestItemsGuiUpdate())); - ScriptWindow->SetInterfaceObject(rec, "rec"); + ScriptWindow->RegisterInterface(rec, "rec"); AInterfaceToLRF* lrf = new AInterfaceToLRF(Config, EventsDataHub); - ScriptWindow->SetInterfaceObject(lrf, "lrf"); + ScriptWindow->RegisterInterface(lrf, "lrf"); ALrfScriptInterface* newLrf = new ALrfScriptInterface(Detector, EventsDataHub); - ScriptWindow->SetInterfaceObject(newLrf, "newLrf"); + ScriptWindow->RegisterInterface(newLrf, "newLrf"); AInterfaceToPMs* pmS = new AInterfaceToPMs(Config); - ScriptWindow->SetInterfaceObject(pmS, "pms"); + ScriptWindow->RegisterInterface(pmS, "pms"); AInterfaceToGraph* graph = new AInterfaceToGraph(TmpHub); - ScriptWindow->SetInterfaceObject(graph, "graph"); + ScriptWindow->RegisterInterface(graph, "graph"); AInterfaceToHist* hist = new AInterfaceToHist(TmpHub); - ScriptWindow->SetInterfaceObject(hist, "hist"); + ScriptWindow->RegisterInterface(hist, "hist"); AInterfaceToTTree* tree = new AInterfaceToTTree(TmpHub); - ScriptWindow->SetInterfaceObject(tree, "tree"); + ScriptWindow->RegisterInterface(tree, "tree"); connect(tree, &AInterfaceToTTree::RequestTreeDraw, GraphWindow, &GraphWindowClass::DrawTree); AInterfaceToMessageWindow* txt = new AInterfaceToMessageWindow(SM, ScriptWindow); - ScriptWindow->SetInterfaceObject(txt, "msg"); + ScriptWindow->RegisterInterface(txt, "msg"); AInterfaceToWebSocket* web = new AInterfaceToWebSocket(EventsDataHub); QObject::connect(web, &AInterfaceToWebSocket::showTextOnMessageWindow, txt, &AInterfaceToMessageWindow::Append); // make sure this line is after AInterfaceToMessageWindow init QObject::connect(web, &AInterfaceToWebSocket::clearTextOnMessageWindow, txt, &AInterfaceToMessageWindow::Clear); // make sure this line is after AInterfaceToMessageWindow init - ScriptWindow->SetInterfaceObject(web, "web"); + ScriptWindow->RegisterInterface(web, "web"); AWebServerInterface* server = new AWebServerInterface(*NetModule->WebSocketServer, EventsDataHub); - ScriptWindow->SetInterfaceObject(server, "server"); + ScriptWindow->RegisterInterface(server, "server"); AInterfaceToPhotonScript* photon = new AInterfaceToPhotonScript(Config, EventsDataHub); - ScriptWindow->SetInterfaceObject(photon, "photon"); + ScriptWindow->RegisterInterface(photon, "photon"); AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(Detector, EventsDataHub); - ScriptWindow->SetInterfaceObject(depo, "depo"); + ScriptWindow->RegisterInterface(depo, "depo"); #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager->KNNmodule); - ScriptWindow->SetInterfaceObject(knn, "knn"); + ScriptWindow->RegisterInterface(knn, "knn"); #endif #ifdef ANTS_FANN //AInterfaceToANNScript* ann = new AInterfaceToANNScript(); - //ScriptWindow->SetInterfaceObject(ann, "ann"); + //ScriptWindow->RegisterInterface(ann, "ann"); #endif // Interfaces which rely on MainWindow InterfaceToGeoWin* geowin = new InterfaceToGeoWin(this, TmpHub); - ScriptWindow->SetInterfaceObject(geowin, "geowin"); + ScriptWindow->RegisterInterface(geowin, "geowin"); InterfaceToGraphWin* grwin = new InterfaceToGraphWin(this); - ScriptWindow->SetInterfaceObject(grwin, "grwin"); + ScriptWindow->RegisterInterface(grwin, "grwin"); AInterfaceToGuiScript* gui = new AInterfaceToGuiScript(SM); - ScriptWindow->SetInterfaceObject(gui, "gui"); + ScriptWindow->RegisterInterface(gui, "gui"); AInterfaceToOutputWin* out = new AInterfaceToOutputWin(this); - ScriptWindow->SetInterfaceObject(out, "outwin"); - + ScriptWindow->RegisterInterface(out, "outwin"); // window inits - - ScriptWindow->UpdateAllTabs(); //highlighers etc ScriptWindow->SetShowEvaluationResult(true); QObject::connect(ScriptWindow, SIGNAL(onStart()), this, SLOT(onGlobalScriptStarted())); QObject::connect(ScriptWindow, SIGNAL(success(QString)), this, SLOT(onGlobalScriptFinished())); QObject::connect(ScriptWindow, SIGNAL(RequestDraw(TObject*,QString,bool)), GraphWindow, SLOT(DrawStrOpt(TObject*,QString,bool))); - ScriptWindow->UpdateHighlight(); + ScriptWindow->UpdateGui(); } void MainWindow::onGlobalScriptStarted() diff --git a/src/gui/MainWindowTools/pythonscript.cpp b/src/gui/MainWindowTools/pythonscript.cpp index ee283f29..b9a43f4e 100644 --- a/src/gui/MainWindowTools/pythonscript.cpp +++ b/src/gui/MainWindowTools/pythonscript.cpp @@ -44,83 +44,83 @@ void MainWindow::createPythonScriptWindow() connect(PythonScriptWindow, SIGNAL(WindowHidden(QString)), WindowNavigator, SLOT(HideWindowTriggered(QString))); // interface objects are owned after this by the ScriptManager! - PythonScriptWindow->SetInterfaceObject(0); //initialization + PythonScriptWindow->RegisterCoreInterfaces(); AInterfaceToConfig* conf = new AInterfaceToConfig(Config); QObject::connect(conf, SIGNAL(requestReadRasterGeometry()), GeometryWindow, SLOT(readRasterWindowProperties())); - PythonScriptWindow->SetInterfaceObject(conf, "config"); + PythonScriptWindow->RegisterInterface(conf, "config"); AInterfaceToAddObjScript* geo = new AInterfaceToAddObjScript(Detector); connect(geo, SIGNAL(requestShowCheckUpWindow()), CheckUpWindow, SLOT(showNormal())); - PythonScriptWindow->SetInterfaceObject(geo, "geo"); + PythonScriptWindow->RegisterInterface(geo, "geo"); AInterfaceToMinimizerPythonScript* mini = new AInterfaceToMinimizerPythonScript(PSM); - PythonScriptWindow->SetInterfaceObject(mini, "mini"); //mini should be before sim to handle abort correctly + PythonScriptWindow->RegisterInterface(mini, "mini"); //mini should be before sim to handle abort correctly AInterfaceToData* dat = new AInterfaceToData(Config, EventsDataHub); QObject::connect(dat, SIGNAL(RequestEventsGuiUpdate()), Rwindow, SLOT(onRequestEventsGuiUpdate())); - PythonScriptWindow->SetInterfaceObject(dat, "events"); + PythonScriptWindow->RegisterInterface(dat, "events"); InterfaceToSim* sim = new InterfaceToSim(SimulationManager, EventsDataHub, Config, GlobSet.RecNumTreads); QObject::connect(sim, SIGNAL(requestStopSimulation()), SimulationManager, SLOT(StopSimulation())); - PythonScriptWindow->SetInterfaceObject(sim, "sim"); + PythonScriptWindow->RegisterInterface(sim, "sim"); InterfaceToReconstructor* rec = new InterfaceToReconstructor(ReconstructionManager, Config, EventsDataHub, TmpHub, GlobSet.RecNumTreads); QObject::connect(rec, SIGNAL(RequestStopReconstruction()), ReconstructionManager, SLOT(requestStop())); QObject::connect(rec, SIGNAL(RequestUpdateGuiForManifest()), Rwindow, SLOT(onManifestItemsGuiUpdate())); - PythonScriptWindow->SetInterfaceObject(rec, "rec"); + PythonScriptWindow->RegisterInterface(rec, "rec"); AInterfaceToLRF* lrf = new AInterfaceToLRF(Config, EventsDataHub); - PythonScriptWindow->SetInterfaceObject(lrf, "lrf"); + PythonScriptWindow->RegisterInterface(lrf, "lrf"); ALrfScriptInterface* newLrf = new ALrfScriptInterface(Detector, EventsDataHub); - PythonScriptWindow->SetInterfaceObject(newLrf, "newLrf"); + PythonScriptWindow->RegisterInterface(newLrf, "newLrf"); AInterfaceToPMs* pmS = new AInterfaceToPMs(Config); - PythonScriptWindow->SetInterfaceObject(pmS, "pms"); + PythonScriptWindow->RegisterInterface(pmS, "pms"); AInterfaceToGraph* graph = new AInterfaceToGraph(TmpHub); - PythonScriptWindow->SetInterfaceObject(graph, "graph"); + PythonScriptWindow->RegisterInterface(graph, "graph"); AInterfaceToHist* hist = new AInterfaceToHist(TmpHub); - PythonScriptWindow->SetInterfaceObject(hist, "hist"); + PythonScriptWindow->RegisterInterface(hist, "hist"); AInterfaceToTTree* tree = new AInterfaceToTTree(TmpHub); - PythonScriptWindow->SetInterfaceObject(tree, "tree"); + PythonScriptWindow->RegisterInterface(tree, "tree"); AInterfaceToMessageWindow* txt = new AInterfaceToMessageWindow(PSM, PythonScriptWindow); - PythonScriptWindow->SetInterfaceObject(txt, "msg"); + PythonScriptWindow->RegisterInterface(txt, "msg"); AInterfaceToWebSocket* web = new AInterfaceToWebSocket(EventsDataHub); QObject::connect(web, &AInterfaceToWebSocket::showTextOnMessageWindow, txt, &AInterfaceToMessageWindow::Append); // make sure this line is after AInterfaceToMessageWindow init QObject::connect(web, &AInterfaceToWebSocket::clearTextOnMessageWindow, txt, &AInterfaceToMessageWindow::Clear); // make sure this line is after AInterfaceToMessageWindow init - PythonScriptWindow->SetInterfaceObject(web, "web"); + PythonScriptWindow->RegisterInterface(web, "web"); AInterfaceToPhotonScript* photon = new AInterfaceToPhotonScript(Config, EventsDataHub); - PythonScriptWindow->SetInterfaceObject(photon, "photon"); + PythonScriptWindow->RegisterInterface(photon, "photon"); AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(Detector, GlobSet, EventsDataHub); - PythonScriptWindow->SetInterfaceObject(depo, "depo"); + PythonScriptWindow->RegisterInterface(depo, "depo"); #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager->KNNmodule); - PythonScriptWindow->SetInterfaceObject(knn, "knn"); + PythonScriptWindow->RegisterInterface(knn, "knn"); #endif #ifdef ANTS_FANN //AInterfaceToANNScript* ann = new AInterfaceToANNScript(); - //PythonScriptWindow->SetInterfaceObject(ann, "ann"); + //PythonScriptWindow->RegisterInterface(ann, "ann"); #endif // Interfaces which rely on MainWindow InterfaceToGeoWin* geowin = new InterfaceToGeoWin(this, TmpHub); - PythonScriptWindow->SetInterfaceObject(geowin, "geowin"); + PythonScriptWindow->RegisterInterface(geowin, "geowin"); InterfaceToGraphWin* grwin = new InterfaceToGraphWin(this); - PythonScriptWindow->SetInterfaceObject(grwin, "grwin"); + PythonScriptWindow->RegisterInterface(grwin, "grwin"); AInterfaceToOutputWin* out = new AInterfaceToOutputWin(this); - PythonScriptWindow->SetInterfaceObject(out, "outwin"); + PythonScriptWindow->RegisterInterface(out, "outwin"); PythonScriptWindow->SetShowEvaluationResult(true); @@ -128,5 +128,5 @@ void MainWindow::createPythonScriptWindow() QObject::connect(PythonScriptWindow, SIGNAL(success(QString)), this, SLOT(onGlobalScriptFinished())); QObject::connect(PythonScriptWindow, SIGNAL(RequestDraw(TObject*,QString,bool)), GraphWindow, SLOT(DrawStrOpt(TObject*,QString,bool))); - PythonScriptWindow->UpdateHighlight(); + PythonScriptWindow->UpdateGui(); } diff --git a/src/gui/ascriptwindow.cpp b/src/gui/ascriptwindow.cpp index 86497d0a..f1a329f5 100644 --- a/src/gui/ascriptwindow.cpp +++ b/src/gui/ascriptwindow.cpp @@ -2,6 +2,7 @@ #include "ui_ascriptwindow.h" #include "ahighlighters.h" #include "atextedit.h" +#include "ascriptinterface.h" #include "localscriptinterfaces.h" #include "coreinterfaces.h" #include "amathscriptinterface.h" @@ -277,11 +278,9 @@ AScriptWindow::~AScriptWindow() delete ui; delete RedIcon; delete ScriptManager; - //qDebug() << "Script manager deleted"; - //delete completitionModel; - //qDebug() << "Completition model deleted"; } +/* void AScriptWindow::SetInterfaceObject(QObject *interfaceObject, QString name) { ScriptManager->SetInterfaceObject(interfaceObject, name); @@ -292,7 +291,6 @@ void AScriptWindow::SetInterfaceObject(QObject *interfaceObject, QString name) if(name.isEmpty()) { // empty name means the main module // populating help for main, math and core units - trwHelp->clear(); if (bLightMode && interfaceObject) fillHelper(interfaceObject, ""); AInterfaceToCore core(0); //dummy to extract methods @@ -305,7 +303,6 @@ void AScriptWindow::SetInterfaceObject(QObject *interfaceObject, QString name) fillHelper(&math, mathName); newFunctions << getListOfMethods(&math, mathName, false); appendDeprecatedOrRemovedMethods(&math, mathName); - trwHelp->expandItem(trwHelp->itemAt(0,0)); } else { @@ -321,7 +318,7 @@ void AScriptWindow::SetInterfaceObject(QObject *interfaceObject, QString name) //completitionModel->setStringList(functions); //if standalone script, update the highlighter and tooltip - if (bLightMode) UpdateAllTabs(); + if (bLightMode) UpdateGui(); //special "needs" of particular interface objects if ( dynamic_cast(interfaceObject) || dynamic_cast(interfaceObject)) //"graph" or "hist" @@ -330,11 +327,64 @@ void AScriptWindow::SetInterfaceObject(QObject *interfaceObject, QString name) if (bLightMode && interfaceObject && trwHelp->topLevelItemCount() > 0) trwHelp->expandItem(trwHelp->itemAt(0,0)); else trwHelp->collapseAll(); } +*/ + +void AScriptWindow::RegisterInterfaceAsGlobal(AScriptInterface *interface) +{ + ScriptManager->RegisterInterfaceAsGlobal(interface); + + doRegister(interface, ""); +} + +void AScriptWindow::RegisterCoreInterfaces(bool bCore, bool bMath) +{ + ScriptManager->RegisterCoreInterfaces(bCore, bMath); + + if (bCore) + { + AInterfaceToCore core(0); //dummy to extract method names + doRegister(&core, "core"); + } + if (bMath) + { + AMathScriptInterface math(0); //dummy to extract method names + QString mathName = (ScriptLanguage == _JavaScript_ ? "math" : "MATH"); + doRegister(&math, mathName); + } +} + +void AScriptWindow::RegisterInterface(AScriptInterface *interface, const QString &name) +{ + ScriptManager->RegisterInterface(interface, name); + + doRegister(interface, name); + + //special "needs" of particular interface objects + if ( dynamic_cast(interface) || dynamic_cast(interface)) //"graph" or "hist" + QObject::connect(interface, SIGNAL(RequestDraw(TObject*,QString,bool)), this, SLOT(onRequestDraw(TObject*,QString,bool))); +} -void AScriptWindow::UpdateAllTabs() +void AScriptWindow::doRegister(AScriptInterface *interface, const QString &name) +{ + // populating help + fillHelper(interface, name); + QStringList newFunctions; + newFunctions << getListOfMethods(interface, name, false); + appendDeprecatedOrRemovedMethods(interface, name); + + //filling autocompleter + for (int i=0; itopLevelItemCount() > 0) + trwHelp->expandItem(trwHelp->itemAt(0,0)); + else trwHelp->collapseAll(); } void AScriptWindow::ReportError(QString error, int line) @@ -462,12 +512,6 @@ void AScriptWindow::ReadFromJson(QJsonObject& json) } } -void AScriptWindow::UpdateHighlight() -{ - for (int i=0; iUpdateHighlight(); -} - void AScriptWindow::SetMainSplitterSizes(QList values) { splMain->setSizes(values); @@ -1192,23 +1236,20 @@ QStringList AScriptWindow::getListOfMethods(QObject *obj, QString ObjName, bool return commands; } -void AScriptWindow::appendDeprecatedOrRemovedMethods(const QObject *obj, const QString &name) +void AScriptWindow::appendDeprecatedOrRemovedMethods(const AScriptInterface *obj, const QString &name) { - const AScriptInterface* unit = dynamic_cast(obj); + if (!obj) return; - if (unit) + QHashIterator iter(obj->getDeprecatedOrRemovedMethods()); + while (iter.hasNext()) { - QHashIterator iter(unit->getDeprecatedOrRemovedMethods()); - while (iter.hasNext()) - { - iter.next(); + iter.next(); - QString key = iter.key(); - if (!name.isEmpty()) key = name + "." + key; + QString key = iter.key(); + if (!name.isEmpty()) key = name + "." + key; - DeprecatedOrRemovedMethods[key] = iter.value(); - ListOfDeprecatedOrRemovedMethods << key; - } + DeprecatedOrRemovedMethods[key] = iter.value(); + ListOfDeprecatedOrRemovedMethods << key; } } @@ -1394,6 +1435,7 @@ void AScriptWindow::onScriptTabMoved(int from, int to) void AScriptWindow::UpdateTab(AScriptWindowTabItem* tab) { tab->highlighter->setHighlighterRules(functions, ListOfDeprecatedOrRemovedMethods, ListOfConstants); + tab->UpdateHighlight(); tab->TextEdit->functionList = functionList; tab->TextEdit->DeprecatedOrRemovedMethods = &DeprecatedOrRemovedMethods; } diff --git a/src/gui/ascriptwindow.h b/src/gui/ascriptwindow.h index d469a227..d5281407 100644 --- a/src/gui/ascriptwindow.h +++ b/src/gui/ascriptwindow.h @@ -6,8 +6,8 @@ #include #include +class AScriptInterface; class AHighlighterScriptWindow; -class QAbstractItemModel; class QCompleter; class QStringListModel; class ATextEdit; @@ -18,10 +18,8 @@ class QSplitter; class QFrame; class QLineEdit; class TObject; -class QThread; class AScriptManager; class AScriptWindowTabItem; -class QTextCursor; class AGlobalSettings; namespace Ui { @@ -36,8 +34,11 @@ class AScriptWindow : public QMainWindow explicit AScriptWindow(AScriptManager *ScriptManager, bool LightMode, QWidget *parent); ~AScriptWindow(); - void SetInterfaceObject(QObject *interfaceObject, QString name = ""); // if not lightMode, do not forget to call UpdateAllTabs() after all units were registered! - void UpdateAllTabs(); //highlighter, helper etc + //void SetInterfaceObject(QObject *interfaceObject, QString name = ""); // if not lightMode, do not forget to call UpdateAllTabs() after all units were registered! + void RegisterInterfaceAsGlobal(AScriptInterface* interface); + void RegisterCoreInterfaces(bool bCore = true, bool bMath = true); + void RegisterInterface(AScriptInterface* interface, const QString& name); + void UpdateGui(); //highlighter, helper etc - call it to take into account all changes introduced by introduction of new interface units! void SetShowEvaluationResult(bool flag) {ShowEvalResult = flag;} //if false, window only reports "success", ptherwise eval result is shown @@ -48,8 +49,6 @@ class AScriptWindow : public QMainWindow void WriteToJson(); void ReadFromJson(); - void UpdateHighlight(); - void SetMainSplitterSizes(QList values); void onBusyOn(); @@ -60,6 +59,9 @@ class AScriptWindow : public QMainWindow AScriptManager* ScriptManager; QStringList functions; +private: + void doRegister(AScriptInterface *interface, const QString& name); + public slots: void updateJsonTree(); @@ -164,7 +166,7 @@ private slots: QString getKeyPath(QTreeWidgetItem *item); void showContextMenuForJsonTree(QTreeWidgetItem *item, QPoint pos); QStringList getListOfMethods(QObject *obj, QString ObjName, bool fWithArguments = false); - void appendDeprecatedOrRemovedMethods(const QObject *obj, const QString& name); + void appendDeprecatedOrRemovedMethods(const AScriptInterface *obj, const QString& name); void ReadFromJson(QJsonObject &json); void WriteToJson(QJsonObject &json); diff --git a/src/gui/detectoraddonswindow.cpp b/src/gui/detectoraddonswindow.cpp index b518fa4e..e98caa87 100644 --- a/src/gui/detectoraddonswindow.cpp +++ b/src/gui/detectoraddonswindow.cpp @@ -538,13 +538,15 @@ void DetectorAddOnsWindow::on_pbUseScriptToAddObj_clicked() MW->GenScriptWindow->ConfigureForLightMode(&Detector->AddObjPositioningScript, title, example); AddObjScriptInterface = new AInterfaceToAddObjScript(Detector); - MW->GenScriptWindow->SetInterfaceObject(AddObjScriptInterface); + MW->GenScriptWindow->RegisterInterfaceAsGlobal(AddObjScriptInterface); + MW->GenScriptWindow->RegisterCoreInterfaces(); connect(AddObjScriptInterface, &AInterfaceToAddObjScript::AbortScriptEvaluation, this, &DetectorAddOnsWindow::ReportScriptError); connect(AddObjScriptInterface, &AInterfaceToAddObjScript::requestShowCheckUpWindow, MW->CheckUpWindow, &CheckUpWindowClass::showNormal); connect(MW->GenScriptWindow, &AScriptWindow::success, this, &DetectorAddOnsWindow::AddObjScriptSuccess); MW->recallGeometryOfLocalScriptWindow(); + MW->GenScriptWindow->UpdateGui(); MW->GenScriptWindow->show(); // MW->extractGeometryOfLocalScriptWindow(); diff --git a/src/gui/globalsettingswindowclass.cpp b/src/gui/globalsettingswindowclass.cpp index 226a6e2d..b5edf099 100644 --- a/src/gui/globalsettingswindowclass.cpp +++ b/src/gui/globalsettingswindowclass.cpp @@ -137,13 +137,17 @@ void GlobalSettingsWindowClass::on_pbgStyleScript_clicked() AJavaScriptManager* jsm = new AJavaScriptManager(MW->Detector->RandGen); MW->GenScriptWindow = new AScriptWindow(jsm, true, this); - QString example = QString(""); + QString example = QString("//see https://root.cern.ch/doc/master/classTStyle.html\n" + "\n" + "//try, e.g.:\n" + "//SetOptStat(\"ei\") //\"nemr\" is redault"); MW->GenScriptWindow->ConfigureForLightMode(&MW->GlobSet.RootStyleScript, "Script to set ROOT's gStyle", example); GStyleInterface = new AInterfaceToGStyleScript(); - MW->GenScriptWindow->SetInterfaceObject(GStyleInterface); + MW->GenScriptWindow->RegisterInterfaceAsGlobal(GStyleInterface); + MW->GenScriptWindow->UpdateGui(); MW->recallGeometryOfLocalScriptWindow(); MW->GenScriptWindow->show(); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 43d1872d..e29642d2 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4121,10 +4121,12 @@ void MainWindow::on_pbRunNodeScript_clicked() GenScriptWindow->ConfigureForLightMode(&NodesScript, "Custom nodes", "clear();\nfor (var i=0; i<5; i++)\n node(i*10, (i-2)*20, 0)\n\nnode(40, -20, 0)"); NodesScriptInterface = new InterfaceToNodesScript(CustomScanNodes); - GenScriptWindow->SetInterfaceObject(NodesScriptInterface); + GenScriptWindow->RegisterInterfaceAsGlobal(NodesScriptInterface); + GenScriptWindow->RegisterCoreInterfaces(); connect(GenScriptWindow, &AScriptWindow::success, this, &MainWindow::NodesScriptSuccess); recallGeometryOfLocalScriptWindow(); + GenScriptWindow->UpdateGui(); GenScriptWindow->show(); } diff --git a/src/main.cpp b/src/main.cpp index 6c0596bb..e4506e9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -236,52 +236,52 @@ int main(int argc, char *argv[]) AJavaScriptManager SM(Detector.RandGen); Network.SetScriptManager(&SM); - SM.SetInterfaceObject(0); //no replacement for the global object in "gloal script" mode + SM.RegisterCoreInterfaces(); AInterfaceToConfig* conf = new AInterfaceToConfig(&Config); - SM.SetInterfaceObject(conf, "config"); + SM.RegisterInterface(conf, "config"); AInterfaceToAddObjScript* geo = new AInterfaceToAddObjScript(&Detector); - SM.SetInterfaceObject(geo, "geo"); + SM.RegisterInterface(geo, "geo"); AInterfaceToMinimizerJavaScript* mini = new AInterfaceToMinimizerJavaScript(&SM); - SM.SetInterfaceObject(mini, "mini"); //mini should be before sim to handle abort correctly + SM.RegisterInterface(mini, "mini"); //mini should be before sim to handle abort correctly AInterfaceToData* dat = new AInterfaceToData(&Config, &EventsDataHub); - SM.SetInterfaceObject(dat, "events"); + SM.RegisterInterface(dat, "events"); #ifdef SIM InterfaceToSim* sim = new InterfaceToSim(&SimulationManager, &EventsDataHub, &Config, GlobSet.RecNumTreads, false); QObject::connect(sim, SIGNAL(requestStopSimulation()), &SimulationManager, SLOT(StopSimulation())); - SM.SetInterfaceObject(sim, "sim"); + SM.RegisterInterface(sim, "sim"); #endif InterfaceToReconstructor* rec = new InterfaceToReconstructor(&ReconstructionManager, &Config, &EventsDataHub, &TmpHub, GlobSet.RecNumTreads); QObject::connect(rec, SIGNAL(RequestStopReconstruction()), &ReconstructionManager, SLOT(requestStop())); - SM.SetInterfaceObject(rec, "rec"); + SM.RegisterInterface(rec, "rec"); AInterfaceToLRF* lrf = new AInterfaceToLRF(&Config, &EventsDataHub); - SM.SetInterfaceObject(lrf, "lrf"); + SM.RegisterInterface(lrf, "lrf"); ALrfScriptInterface* newLrf = new ALrfScriptInterface(&Detector, &EventsDataHub); - SM.SetInterfaceObject(newLrf, "newLrf"); + SM.RegisterInterface(newLrf, "newLrf"); AInterfaceToPMs* pmS = new AInterfaceToPMs(&Config); - SM.SetInterfaceObject(pmS, "pms"); + SM.RegisterInterface(pmS, "pms"); AInterfaceToGraph* graph = new AInterfaceToGraph(&TmpHub); - SM.SetInterfaceObject(graph, "graph"); + SM.RegisterInterface(graph, "graph"); AInterfaceToHist* hist = new AInterfaceToHist(&TmpHub); - SM.SetInterfaceObject(hist, "hist"); + SM.RegisterInterface(hist, "hist"); AInterfaceToTTree* tree = new AInterfaceToTTree(&TmpHub); - SM.SetInterfaceObject(tree, "tree"); + SM.RegisterInterface(tree, "tree"); AInterfaceToPhotonScript* photon = new AInterfaceToPhotonScript(&Config, &EventsDataHub); - SM.SetInterfaceObject(photon, "photon"); + SM.RegisterInterface(photon, "photon"); AInterfaceToDepoScript* depo = new AInterfaceToDepoScript(&Detector, &EventsDataHub); - SM.SetInterfaceObject(depo, "depo"); + SM.RegisterInterface(depo, "depo"); AInterfaceToMultiThread* threads = new AInterfaceToMultiThread(&SM); - SM.SetInterfaceObject(threads, "threads"); + SM.RegisterInterface(threads, "threads"); AInterfaceToWebSocket* web = new AInterfaceToWebSocket(&EventsDataHub); - SM.SetInterfaceObject(web, "web"); + SM.RegisterInterface(web, "web"); AWebServerInterface* server = new AWebServerInterface(*Network.WebSocketServer, &EventsDataHub); - SM.SetInterfaceObject(server, "server"); + SM.RegisterInterface(server, "server"); #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager.KNNmodule); - SM.SetInterfaceObject(knn, "knn"); + SM.RegisterInterface(knn, "knn"); #endif #ifdef ANTS_FANN //AInterfaceToANNScript* ann = new AInterfaceToANNScript(); - //SM.SetInterfaceObject(ann, "ann"); + //SM.RegisterInterface(ann, "ann"); #endif if ( parser.isSet(scriptOption) ) diff --git a/src/scriptmode/ajavascriptmanager.cpp b/src/scriptmode/ajavascriptmanager.cpp index b87ee8d3..ab414982 100644 --- a/src/scriptmode/ajavascriptmanager.cpp +++ b/src/scriptmode/ajavascriptmanager.cpp @@ -1,7 +1,10 @@ #include "ajavascriptmanager.h" + #ifdef GUI #include "ainterfacetomessagewindow.h" #endif + +#include "ascriptinterface.h" #include "coreinterfaces.h" #include "amathscriptinterface.h" #include "ascriptinterfacefactory.h" @@ -10,7 +13,6 @@ #include #include #include -//#include #include AJavaScriptManager::AJavaScriptManager(TRandom2* RandGen) : @@ -166,6 +168,7 @@ void AJavaScriptManager::restoreMsgDialogs() } #endif +/* void AJavaScriptManager::SetInterfaceObject(QObject *interfaceObject, QString name) { //qDebug() << "Registering:" << interfaceObject << name; @@ -188,7 +191,7 @@ void AJavaScriptManager::SetInterfaceObject(QObject *interfaceObject, QString na QString mathName = "math"; mathObj->setObjectName(mathName); engine->globalObject().setProperty(mathName, mathVal); - interfaces.append(mathObj); //SERVICE OBJECT IS FIRST in interfaces! + interfaces.append(mathObj); } else { // name is not empty - this is one of the secondary modules @@ -204,7 +207,48 @@ void AJavaScriptManager::SetInterfaceObject(QObject *interfaceObject, QString na int index = interfaceObject->metaObject()->indexOfSignal("AbortScriptEvaluation(QString)"); if (index != -1) QObject::connect(interfaceObject, "2AbortScriptEvaluation(QString)", this, SLOT(AbortEvaluation(QString))); //1-slot, 2-signal - } + } +} +*/ + +void AJavaScriptManager::RegisterInterfaceAsGlobal(AScriptInterface *interface) +{ + QScriptValue obj = engine->newQObject(interface, QScriptEngine::QtOwnership); + engine->setGlobalObject(obj); + doRegister(interface, ""); +} + +void AJavaScriptManager::RegisterCoreInterfaces(bool bCore, bool bMath) +{ + if (bCore) + { + coreObj = new AInterfaceToCore(this); + QScriptValue coreVal = engine->newQObject(coreObj, QScriptEngine::QtOwnership); + engine->globalObject().setProperty("core", coreVal); + doRegister(coreObj, "core"); + } + + if (bMath) + { + AMathScriptInterface* mathObj = new AMathScriptInterface(RandGen); + QScriptValue mathVal = engine->newQObject(mathObj, QScriptEngine::QtOwnership); + engine->globalObject().setProperty("math", mathVal); + doRegister(mathObj, "math"); + } +} + +void AJavaScriptManager::RegisterInterface(AScriptInterface *interface, const QString &name) +{ + QScriptValue obj = engine->newQObject(interface, QScriptEngine::QtOwnership); + engine->globalObject().setProperty(name, obj); + doRegister(interface, name); +} + +void AJavaScriptManager::doRegister(AScriptInterface *interface, const QString &name) +{ + interface->setObjectName(name); + interfaces.append(interface); + QObject::connect(interface, &AScriptInterface::AbortScriptEvaluation, this, &AJavaScriptManager::AbortEvaluation); } int AJavaScriptManager::FindSyntaxError(const QString& script) @@ -417,14 +461,11 @@ AJavaScriptManager *AJavaScriptManager::createNewScriptManager(int threadNumber, sm->bOwnRandomGen = true; sm->bShowAbortMessageInOutput = bAbortIsGlobal; - for (QObject* io : interfaces) + for (AScriptInterface* si : interfaces) { - AScriptInterface* si = dynamic_cast(io); - if (!si) continue; - if (!si->IsMultithreadCapable()) continue; - QObject* copy = AScriptInterfaceFactory::makeCopy(io); //cloning script interfaces + AScriptInterface* copy = AScriptInterfaceFactory::makeCopy(si); //cloning script interfaces if (copy) { // qDebug() << "Making available for multi-thread use: "<objectName(); @@ -476,11 +517,11 @@ AJavaScriptManager *AJavaScriptManager::createNewScriptManager(int threadNumber, if (base) connect(base, &AScriptInterface::AbortScriptEvaluation, coreObj, &AInterfaceToCore::abort); } - sm->SetInterfaceObject(copy, io->objectName()); + sm->RegisterInterface(copy, si->objectName()); } else { - qDebug() << "Unknown interface object type for unit" << io->objectName(); + qDebug() << "Unknown interface object type for unit" << si->objectName(); } } diff --git a/src/scriptmode/ajavascriptmanager.h b/src/scriptmode/ajavascriptmanager.h index 53d21462..5e24da77 100644 --- a/src/scriptmode/ajavascriptmanager.h +++ b/src/scriptmode/ajavascriptmanager.h @@ -26,7 +26,10 @@ class AJavaScriptManager : public AScriptManager ~AJavaScriptManager(); //configuration - virtual void SetInterfaceObject(QObject* interfaceObject, QString name = "") override; + //virtual void SetInterfaceObject(QObject* interfaceObject, QString name = "") override; + virtual void RegisterInterfaceAsGlobal(AScriptInterface* interface) override; + virtual void RegisterCoreInterfaces(bool bCore = true, bool bMath = true) override; + virtual void RegisterInterface(AScriptInterface* interface, const QString& name) override; //run virtual int FindSyntaxError(const QString &script) override; //returns line number of the first syntax error; -1 if no errors found @@ -65,6 +68,8 @@ public slots: QVector ThreadMessangerDialogs; #endif +private: + void doRegister(AScriptInterface *interface, const QString &name); }; #endif // AJAVASCRIPTMANAGER_H diff --git a/src/scriptmode/apythonscriptmanager.cpp b/src/scriptmode/apythonscriptmanager.cpp index 74a2e83e..1a30509c 100644 --- a/src/scriptmode/apythonscriptmanager.cpp +++ b/src/scriptmode/apythonscriptmanager.cpp @@ -2,6 +2,7 @@ //#include "PythonQt_QtAll.h" #include "apythonscriptmanager.h" +#include "ascriptinterface.h" #include "coreinterfaces.h" APythonScriptManager::APythonScriptManager(TRandom2 *RandGen) : @@ -14,6 +15,7 @@ APythonScriptManager::APythonScriptManager(TRandom2 *RandGen) : connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), this, SLOT(stdErr(const QString&))); } +/* void APythonScriptManager::SetInterfaceObject(QObject *interfaceObject, QString name) { //qDebug() << "Registering:" << interfaceObject << name; @@ -45,7 +47,35 @@ void APythonScriptManager::SetInterfaceObject(QObject *interfaceObject, QString if (index != -1) QObject::connect(interfaceObject, "2AbortScriptEvaluation(QString)", this, SLOT(AbortEvaluation(QString))); //1-slot, 2-signal } +} +*/ + +void APythonScriptManager::RegisterInterfaceAsGlobal(AScriptInterface *) +{ + qDebug() << "Registering as global is not implemented for python scripting!"; +} +void APythonScriptManager::RegisterCoreInterfaces(bool bCore, bool bMath) +{ + if (bCore) + { + AInterfaceToCore* coreObj = new AInterfaceToCore(this); + RegisterInterface(coreObj, "core"); + } + + if (bMath) + { + QObject* mathObj = new AInterfaceToMath(RandGen); + RegisterInterface(mathObj, "MATH"); + } +} + +void APythonScriptManager::RegisterInterface(AScriptInterface *interface, const QString &name) +{ + PythonQt::self()->addObject(PythonQt::self()->getMainModule(), name, interface); + interface->setObjectName(name); + interfaces.append(interface); + QObject::connect(interface, &AScriptInterface::AbortScriptEvaluation, this, &APythonScriptManager::AbortEvaluation); } QString APythonScriptManager::Evaluate(const QString &Script) diff --git a/src/scriptmode/apythonscriptmanager.h b/src/scriptmode/apythonscriptmanager.h index e3a355b7..2ebd2780 100644 --- a/src/scriptmode/apythonscriptmanager.h +++ b/src/scriptmode/apythonscriptmanager.h @@ -21,7 +21,10 @@ class APythonScriptManager : public AScriptManager ~APythonScriptManager() {} //configuration - virtual void SetInterfaceObject(QObject* interfaceObject, QString name) override; + //virtual void SetInterfaceObject(QObject* interfaceObject, QString name) override; + virtual void RegisterInterfaceAsGlobal(AScriptInterface* interface) override; + virtual void RegisterCoreInterfaces(bool bCore = true, bool bMath = true) override; + virtual void RegisterInterface(AScriptInterface* interface, const QString& name) override; //run virtual QString Evaluate(const QString &Script) override; diff --git a/src/scriptmode/ascriptinterfacefactory.h b/src/scriptmode/ascriptinterfacefactory.h index a0b85677..7d10207e 100644 --- a/src/scriptmode/ascriptinterfacefactory.h +++ b/src/scriptmode/ascriptinterfacefactory.h @@ -17,7 +17,7 @@ class AScriptInterfaceFactory { public: - static QObject* makeCopy(const QObject* other) + static AScriptInterface* makeCopy(const AScriptInterface* other) { const AInterfaceToCore* core = dynamic_cast(other); if (core) return new AInterfaceToCore(*core); diff --git a/src/scriptmode/ascriptmanager.cpp b/src/scriptmode/ascriptmanager.cpp index 4d1df89c..9130686a 100644 --- a/src/scriptmode/ascriptmanager.cpp +++ b/src/scriptmode/ascriptmanager.cpp @@ -1,8 +1,11 @@ #include "ascriptmanager.h" #include "ascriptinterface.h" +#include "ascriptinterface.h" + #ifdef GUI #include "ainterfacetomessagewindow.h" #endif + #include #include #include diff --git a/src/scriptmode/ascriptmanager.h b/src/scriptmode/ascriptmanager.h index f4c078e6..12ad9b88 100644 --- a/src/scriptmode/ascriptmanager.h +++ b/src/scriptmode/ascriptmanager.h @@ -6,6 +6,7 @@ #include #include +class AScriptInterface; class TRandom2; class AInterfaceToCore; class QElapsedTimer; @@ -19,7 +20,9 @@ class AScriptManager : public QObject virtual ~AScriptManager(); //configuration - virtual void SetInterfaceObject(QObject* interfaceObject, QString name = "") = 0; + virtual void RegisterInterfaceAsGlobal(AScriptInterface* interface) = 0; + virtual void RegisterCoreInterfaces(bool bCore = true, bool bMath = true) = 0; + virtual void RegisterInterface(AScriptInterface* interface, const QString& name) = 0; //run virtual int FindSyntaxError(const QString & /*script*/ ) {return -1;} //returns line number of the first syntax error; -1 if no errors found @@ -53,7 +56,7 @@ public slots: virtual void AbortEvaluation(QString message = "Aborted!"); public: - QVector interfaces; //registered interfaces (units) + QVector interfaces; //registered interfaces (units) TRandom2* RandGen; //math module uses it //pointers to starter dirs From 3a7442e4f47cc06f3930307bde53b8a8cc5982c4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 15 Oct 2018 14:28:23 +0100 Subject: [PATCH 072/140] ++ --- src/ants2.pro | 9 +- src/aparticlesourcedialog.cpp | 77 + src/aparticlesourcedialog.h | 37 + src/aparticlesourcedialog.ui | 1470 +++++++++++++++++ .../MainWindowParticleSimulation.cpp | 38 +- src/gui/checkupwindowclass.cpp | 2 +- src/gui/mainwindow.h | 4 +- src/gui/mainwindow.ui | 4 +- src/modules/particlesourcesclass.cpp | 63 +- src/modules/particlesourcesclass.h | 83 +- 10 files changed, 1691 insertions(+), 96 deletions(-) create mode 100644 src/aparticlesourcedialog.cpp create mode 100644 src/aparticlesourcedialog.h create mode 100644 src/aparticlesourcedialog.ui diff --git a/src/ants2.pro b/src/ants2.pro index ca8bcde5..ca83e581 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -356,7 +356,8 @@ SOURCES += main.cpp \ OpticalOverrides/awaveshifteroverride.cpp \ OpticalOverrides/spectralbasicopticaloverride.cpp \ OpticalOverrides/abasicopticaloverride.cpp \ - common/aglobalsettings.cpp + common/aglobalsettings.cpp \ + aparticlesourcedialog.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -488,7 +489,8 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/awaveshifteroverride.h \ OpticalOverrides/spectralbasicopticaloverride.h \ OpticalOverrides/abasicopticaloverride.h \ - common/aglobalsettings.h + common/aglobalsettings.h \ + aparticlesourcedialog.h # --- SIM --- ants2_SIM { @@ -814,3 +816,6 @@ unix { } #------------ +FORMS += \ + aparticlesourcedialog.ui + diff --git a/src/aparticlesourcedialog.cpp b/src/aparticlesourcedialog.cpp new file mode 100644 index 00000000..1996fd1d --- /dev/null +++ b/src/aparticlesourcedialog.cpp @@ -0,0 +1,77 @@ +#include "aparticlesourcedialog.h" +#include "ui_aparticlesourcedialog.h" +#include "mainwindow.h" + +#include + +AParticleSourceDialog::AParticleSourceDialog(MainWindow &MW, const AParticleSourceRecord &Rec) : + QDialog(*MW), ui(new Ui::AParticleSourceDialog), + MW(MW), Rec(Rec.clone()) +{ + ui->setupUi(this); +} + +AParticleSourceDialog::~AParticleSourceDialog() +{ + delete ui; + delete Rec; +} + +void AParticleSourceDialog::on_pbAccept_clicked() +{ + accept(); +} + +void AParticleSourceDialog::on_pbReject_clicked() +{ + reject(); +} + +void AParticleSourceDialog::on_pbGunTest_clicked() +{ + +} + +void AParticleSourceDialog::on_cobGunSourceType_currentIndexChanged(int index) +{ + QVector s; + switch (index) + { + default: + case 0: s <<""<<""<<""; + break; + case 1: s <<"Length:"<<""<<""; + break; + case 2: s <<"Size X:"<<"Size Y:"<<""; + break; + case 3: s <<"Diameter:"<<""<<""; + break; + case 4: s <<"Size X:"<<"Size Y:"<<"Size Z:"; + break; + case 5: s <<"Diameter:"<<""<<"Height:"; + break; + default: + qWarning() << "Unknown source type!"; + } + ui->lGun1DSize->setText(s[0]); + ui->lGun2DSize->setText(s[1]); + ui->lGun3DSize->setText(s[2]); + ui->fGun1D->setVisible(!s[0].isEmpty()); + ui->fGun2D->setVisible(!s[1].isEmpty()); + ui->fGun3D->setVisible(!s[2].isEmpty()); + + ui->fGunPhi->setEnabled(index != 0); + ui->fGunTheta->setEnabled(index != 0); + ui->fGunPsi->setEnabled(index > 1); + + if (index == 1) + { + ui->labGunPhi->setText("Phi"); + ui->labGunTheta->setText("Theta"); + } + else + { + ui->labGunPhi->setText("around X"); + ui->labGunTheta->setText("around Y"); + } +} diff --git a/src/aparticlesourcedialog.h b/src/aparticlesourcedialog.h new file mode 100644 index 00000000..78db0575 --- /dev/null +++ b/src/aparticlesourcedialog.h @@ -0,0 +1,37 @@ +#ifndef APARTICLESOURCEDIALOG_H +#define APARTICLESOURCEDIALOG_H + +#include "particlesourcesclass.h" + +#include + +namespace Ui { +class AParticleSourceDialog; +} + +class MainWindow; + +class AParticleSourceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AParticleSourceDialog(MainWindow& MW, const AParticleSourceRecord& Rec); + ~AParticleSourceDialog(); + + const AParticleSourceRecord& getResultToClone() const {return Rec;} //clone the result! + +private slots: + void on_pbAccept_clicked(); + void on_pbReject_clicked(); + void on_pbGunTest_clicked(); + + void on_cobGunSourceType_currentIndexChanged(int index); + +private: + Ui::AParticleSourceDialog *ui; + MainWindow& MW; + AParticleSourceRecord Rec; +}; + +#endif // APARTICLESOURCEDIALOG_H diff --git a/src/aparticlesourcedialog.ui b/src/aparticlesourcedialog.ui new file mode 100644 index 00000000..516526ea --- /dev/null +++ b/src/aparticlesourcedialog.ui @@ -0,0 +1,1470 @@ + + + AParticleSourceDialog + + + + 0 + 0 + 600 + 627 + + + + Dialog + + + + + + 0 + + + + + + 75 + true + + + + Source name: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 75 + true + + + + Geometry: + + + Qt::AlignCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 50 + false + + + + + Point + + + + + Linear + + + + + Surface: square + + + + + Surface: round + + + + + Volume: box + + + + + Volume: cylinder + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Size1: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 10 + + + + + + + + 0 + 0 + + + + mm + + + + + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Size2: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 10 + + + + + + + + 0 + 0 + + + + mm + + + + + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Size3: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 10 + + + + + + + + 0 + 0 + + + + mm + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 75 + true + + + + Position of the source center: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + X: + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + mm Y: + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + mm Z: + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + mm + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 75 + true + + + + Source orientation: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Phi: + + + Qt::AlignCenter + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + deg + + + + + + + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Theta: + + + Qt::AlignCenter + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + deg + + + + + + + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + around Z: + + + Qt::AlignCenter + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + deg + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 75 + true + + + + Collimation direction: + + + + + + + + + Phi: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + deg + + + + + + + Theta: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + deg + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 75 + true + + + + Collimation cone (angle from collimation direction): + + + + + + + + + + 75 + 16777215 + + + + 45 + + + + + + + deg + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + 75 + true + + + + Particle composition: + + + + + + + QAbstractItemView::SelectRows + + + QListView::ListMode + + + + + + + + + + 75 + true + + + + Add new particle + + + + + + + Remove particle + + + + + + + + + + + + 0 + 0 + + + + + 275 + 16777215 + + + + QFrame::Box + + + QFrame::Raised + + + + 2 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + 0 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Stat weight: + + + + + + + + 50 + 16777215 + + + + 1 + + + + + + + + + + + Fixed energy: + + + + + + + + 75 + 16777215 + + + + 1000 + + + + + + + + MeV + + + + + keV + + + + + eV + + + + + meV + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Energy spectrum: + + + + + + + false + + + + 50 + 0 + + + + Show + + + + + + + + 50 + 0 + + + + Format: two columns, first is the energy in keV, second is the probability + + + Load + + + + + + + + + Linked particle: + + + true + + + + + + + + 0 + 0 + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + Linked to particle #: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + 16777215 + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + with probability: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 50 + 16777215 + + + + 1 + + + + + + + Opposite + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + label_152 + label_153 + ledLinkingProbability + leiParticleLinkedTo + cbLinkingOpposite + horizontalSpacer_12 + horizontalSpacer_13 + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + pbGunDeleteSpectrum + pbGunLoadSpectrum + cbIndividualParticle + fLinkedParticle + pbGunShowSpectrum + radioButton + ledGunEnergy + comboBox + radioButton_2 + verticalSpacer + horizontalLayoutWidget_2 + frSecondary + + + + + + + + + + Limit particle generation to the material: + + + + + + + true + + + Particle will be generated only if the point sampled inside the source is located within an object with the indicated material. +If material with this name does not exist, this limitation is not applied. + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 200 + 0 + + + + Test generator + + + + + + + 1 + + + 1000000 + + + 100 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 150 + 35 + + + + + 75 + true + + + + Accept changes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 150 + 35 + + + + + 75 + true + + + + Cancel changes + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + cbIndividualParticle + toggled(bool) + frSecondary + setEnabled(bool) + + + 373 + 406 + + + 531 + 421 + + + + + diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index f03126ba..f1808899 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -53,7 +53,7 @@ void MainWindow::SimParticleSourcesConfigToJson(QJsonObject &json) void MainWindow::ShowSource(int isource, bool clear) { - ParticleSourceStructure* p = ParticleSources->getSource(isource); + const AParticleSourceRecord* p = ParticleSources->getSource(isource); int index = p->index; double X0 = p->X0; @@ -295,7 +295,7 @@ void MainWindow::on_pbGunRefreshparticles_clicked() int isource = ui->cobParticleSource->currentIndex(); if (isource > ParticleSources->size()-1) return; //protection - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); //Populating ListView int DefinedSourceParticles = ps->GunParticles.size(); @@ -349,7 +349,7 @@ void MainWindow::SourceUpdateThisParticleIndication() if (isource<0 || isource>=ParticleSources->size()) return; int row = ui->lwGunParticles->currentRow(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + const AParticleSourceRecord* ps = ParticleSources->getSource(isource); int DefinedSourceParticles = ps->GunParticles.size(); if (DefinedSourceParticles > 0 && row>-1) @@ -409,7 +409,7 @@ void MainWindow::on_pbGunAddNew_clicked() void MainWindow::on_pbGunRemove_clicked() { int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); if (ps->GunParticles.size() < 2) { message("Source should contain at least one particle!"); @@ -482,7 +482,7 @@ void MainWindow::on_cobGunParticle_activated(int index) int isource = ui->cobParticleSource->currentIndex(); if (isource > ParticleSources->size() - 1) return; - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); if (ps->GunParticles.isEmpty()) return; int particle = ui->lwGunParticles->currentRow(); @@ -498,7 +498,7 @@ void MainWindow::on_ledGunEnergy_editingFinished() { //if (BulkUpdate) return; int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; @@ -513,7 +513,7 @@ void MainWindow::on_ledGunParticleWeight_editingFinished() { //if (BulkUpdate) return; int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; ps->GunParticles[particle]->StatWeight = ui->ledGunParticleWeight->text().toDouble(); @@ -527,7 +527,7 @@ void MainWindow::on_cbIndividualParticle_clicked(bool checked) { //if (BulkUpdate) return; int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; @@ -549,7 +549,7 @@ void MainWindow::on_leiParticleLinkedTo_editingFinished() { //if (BulkUpdate) return; int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; int iLinkedTo = ui->leiParticleLinkedTo->text().toInt(); @@ -589,7 +589,7 @@ void MainWindow::on_ledLinkingProbability_editingFinished() } int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; ps->GunParticles[particle]->LinkingProbability = val; @@ -602,7 +602,7 @@ void MainWindow::on_ledLinkingProbability_editingFinished() void MainWindow::on_cbLinkingOpposite_clicked(bool checked) { int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; int linkedTo = ui->leiParticleLinkedTo->text().toInt(); @@ -629,7 +629,7 @@ void MainWindow::on_pbGunLoadSpectrum_clicked() GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; ParticleSources->LoadGunEnergySpectrum(isource, particle, fileName); @@ -643,7 +643,7 @@ void MainWindow::on_pbGunLoadSpectrum_clicked() void MainWindow::on_pbGunShowSpectrum_clicked() { int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; ps->GunParticles[particle]->spectrum->GetXaxis()->SetTitle("Energy, keV"); @@ -653,7 +653,7 @@ void MainWindow::on_pbGunShowSpectrum_clicked() void MainWindow::on_pbGunDeleteSpectrum_clicked() { int isource = ui->cobParticleSource->currentIndex(); - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); int particle = ui->lwGunParticles->currentRow(); if (particle<0 || particle > ps->GunParticles.size()-1) return; if (ps->GunParticles[particle]->spectrum) @@ -712,7 +712,7 @@ void MainWindow::on_pbRemoveSource_clicked() void MainWindow::on_pbAddSource_clicked() { - ParticleSourceStructure* s = new ParticleSourceStructure(); + AParticleSourceRecord* s = new AParticleSourceRecord(); ParticleSources->append(s); ui->cobParticleSource->addItem(ParticleSources->getLastSource()->name); ui->cobParticleSource->setCurrentIndex(ParticleSources->size()-1); @@ -750,7 +750,7 @@ void MainWindow::on_pbUpdateSources_clicked() return; } - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); ps->Activity = ui->ledSourceActivity->text().toDouble(); ps->index = ui->cobGunSourceType->currentIndex(); @@ -842,7 +842,7 @@ void MainWindow::updateActivityIndication() ui->labOfTotal->setText(QString::number(fraction, 'g', 3)+"%"); } -void MainWindow::updateOneParticleSourcesIndication(ParticleSourceStructure* ps) +void MainWindow::updateOneParticleSourcesIndication(AParticleSourceRecord* ps) { bool BulkUpdateCopy = BulkUpdate; //it could be set outside to true already, do not want to reselt to false on exit BulkUpdate = true; @@ -870,7 +870,7 @@ void MainWindow::updateOneParticleSourcesIndication(ParticleSourceStructure* ps) void MainWindow::clearParticleSourcesIndication() { - ParticleSourceStructure ps; + AParticleSourceRecord ps; updateOneParticleSourcesIndication(&ps); ui->cobParticleSource->clear(); ui->cobParticleSource->setCurrentIndex(-1); @@ -997,7 +997,7 @@ void MainWindow::on_pbRenameSource_clicked() //qDebug() << "current source:"<ParticleSources->size()-1) return; - ParticleSourceStructure* ps = ParticleSources->getSource(isource); + AParticleSourceRecord* ps = ParticleSources->getSource(isource); bool ok; QString text = QInputDialog::getText(this, "Rename particle source", "New name:", QLineEdit::Normal, diff --git a/src/gui/checkupwindowclass.cpp b/src/gui/checkupwindowclass.cpp index 706030e7..8be9e57f 100644 --- a/src/gui/checkupwindowclass.cpp +++ b/src/gui/checkupwindowclass.cpp @@ -242,7 +242,7 @@ TriState CheckUpWindowClass::CheckInteractions() //Check all particle sources: if links are valid, if interaction data for a given energy is available for(int i = 0; i < MW->ParticleSources->size(); i++) { - ParticleSourceStructure* source = MW->ParticleSources->getSource(i); + AParticleSourceRecord* source = MW->ParticleSources->getSource(i); int sourceParticleCount = source->GunParticles.size(); //Loop over all GunParticles diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 94196b24..380e4656 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -55,7 +55,7 @@ class ASimulationManager; class AScriptWindow; class ALrfWindow; class ANetworkModule; -struct ParticleSourceStructure; +struct AParticleSourceRecord; class ARemoteWindow; class AWebSocketServerDialog; @@ -630,7 +630,7 @@ public slots: void SourceUpdateThisParticleIndication(); void onGuiEnableStatus(bool fLocked); void clearParticleSourcesIndication(); - void updateOneParticleSourcesIndication(ParticleSourceStructure *ps); + void updateOneParticleSourcesIndication(AParticleSourceRecord *ps); void ShowParticleSource_noFocus(); void updateActivityIndication(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 7b03d52f..a3b00514 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 0 + 1 @@ -6893,7 +6893,7 @@ Second click will trigger strong abort mode, which will result in loss of all si QTabWidget::Rounded - 0 + 1 false diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index c827199e..5be01cb0 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -420,7 +420,7 @@ void ParticleSourcesClass::IsParticleInUse(int particleId, bool &bInUse, QString for (int isource=0; isourceGunParticles.size(); ip++) { if ( particleId == ps->GunParticles[ip]->ParticleId ) @@ -437,7 +437,7 @@ void ParticleSourcesClass::RemoveParticle(int particleId) { for (int isource=0; isourceGunParticles.size(); ip++) if ( ps->GunParticles[ip]->ParticleId > particleId) ps->GunParticles[ip]->ParticleId--; @@ -461,7 +461,7 @@ bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) { if (iSource<0 || iSource>ParticleSourcesData.size()-1) return false; - ParticleSourceStructure* s = ParticleSourcesData[iSource]; + AParticleSourceRecord* s = ParticleSourcesData[iSource]; //general json["Name"] = s->name; @@ -552,13 +552,13 @@ bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) if (iSource == -1) { //append new! - ParticleSourceStructure* ns = new ParticleSourceStructure(); + AParticleSourceRecord* ns = new AParticleSourceRecord(); ParticleSourcesData.append(ns); iSource = ParticleSourcesData.size()-1; } delete ParticleSourcesData[iSource]; //have to delete here, or histograms might have not unique names - ParticleSourceStructure* s = new ParticleSourceStructure(); + AParticleSourceRecord* s = new AParticleSourceRecord(); ParticleSourcesData[iSource] = s; //reading general info parseJson(json, "Name", s->name); @@ -614,7 +614,7 @@ bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) AParticle::ParticleType Type = static_cast(type); int ParticleId = MpCollection->FindCreateParticle(name, Type, charge, mass); - s->GunParticles.append(new GunParticleStruct()); + s->GunParticles << new GunParticleStruct(); s->GunParticles[ip]->ParticleId = ParticleId; //qDebug()<<"Added gun particle with particle Id"<at(ParticleId)->ParticleName; @@ -652,7 +652,7 @@ bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) return true; } -void ParticleSourcesClass::checkLimitedToMaterial(ParticleSourceStructure* s) +void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) { bool fFound = false; int iMat; @@ -744,7 +744,7 @@ int ParticleSourcesClass::CheckSource(int isource) if (MpCollection == 0) return 3; // 3 - material collection not connected if (getTotalActivity() == 0) return 4; // 4 - total activity = 0 - ParticleSourceStructure* ps = ParticleSourcesData[isource]; + AParticleSourceRecord* ps = ParticleSourcesData[isource]; if (ps->index <0 || ps->index>5) return 10; //10 - unknown source shape int numParts = ps->GunParticles.size(); //11 - no particles defined @@ -801,7 +801,7 @@ QString ParticleSourcesClass::getErrorString(int error) return "undefined error"; } -void ParticleSourcesClass::append(ParticleSourceStructure *gunParticle) +void ParticleSourcesClass::append(AParticleSourceRecord *gunParticle) { ParticleSourcesData.append(gunParticle); CalculateTotalActivity(); @@ -817,28 +817,43 @@ void ParticleSourcesClass::remove(int iSource) CalculateTotalActivity(); } +GunParticleStruct * GunParticleStruct::clone() const +{ + //shallow copy + GunParticleStruct* gp = new GunParticleStruct(*this); + + //clear dynamic + gp->spectrum = 0; + + //deep copy for dynamic properties + if (spectrum) + gp->spectrum = new TH1D(*spectrum); + + return gp; +} + GunParticleStruct::~GunParticleStruct() { if (spectrum) delete spectrum; } - -ParticleSourceStructure::ParticleSourceStructure() +AParticleSourceRecord::~AParticleSourceRecord() { - name = "Underfined_name"; - Activity = 1; - index = 0; - X0 = 0; Y0 = 0; Z0 = 0; - size1 = 10; size2 = 10; size3 = 10; - Phi = 0; Theta = 0; Psi = 0; - CollPhi = 0; CollTheta = 0; - Spread = 45; - DoMaterialLimited = fLimit = false; - - GunParticles.resize(0); + for (GunParticleStruct* g : GunParticles) delete g; + GunParticles.clear(); } -ParticleSourceStructure::~ParticleSourceStructure() +AParticleSourceRecord * AParticleSourceRecord::clone() const { - for (int i=0; iGunParticles.clear(); + + //deep copy of dynamic resources + for (GunParticleStruct* g : GunParticles) + newRec->GunParticles << g->clone(); + + return newRec; } diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 33346c9e..9db01f62 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -15,70 +15,61 @@ class DetectorClass; struct GunParticleStruct { - int ParticleId; - double StatWeight; - double energy; - TH1D* spectrum; //energy spectrum - bool Individual; // true = individual particle; false = linked - int LinkedTo; // index of the "parent" particle this one is following - double LinkingProbability; //probability to be emitted after the parent particle - bool LinkingOppositeDir; // false = random direction; otherwise particle is emitted in the opposite direction in respect to the LinkedTo particle - - GunParticleStruct() - { - spectrum = 0; - Individual = true; - LinkedTo = 0;//-1; - LinkingProbability = 0; - LinkingOppositeDir = false; - } + int ParticleId = 0; + double StatWeight = 1.0; + double energy = 100.0; //in keV + bool Individual = true; // true = individual particle; false = linked + int LinkedTo = 0; // index of the "parent" particle this one is following + double LinkingProbability = 0; //probability to be emitted after the parent particle + bool LinkingOppositeDir = false; // false = random direction; otherwise particle is emitted in the opposite direction in respect to the LinkedTo particle + + TH1D* spectrum = 0; //energy spectrum + + GunParticleStruct * clone() const; ~GunParticleStruct(); }; -struct ParticleSourceStructure +struct AParticleSourceRecord { //name - QString name; + QString name = "Underfined"; //source type (geometry) - int index; //shape + int index = 0; //shape //position - double X0; - double Y0; - double Z0; + double X0 = 0; + double Y0 = 0; + double Z0 = 0; //orientation - double Phi; - double Theta; - double Psi; + double Phi = 0; + double Theta = 0; + double Psi = 0; //size - double size1; - double size2; - double size3; + double size1 = 10.0; + double size2 = 10.0; + double size3 = 10.0; //collimation - double CollPhi; - double CollTheta; - double Spread; + double CollPhi = 0; + double CollTheta = 0; + double Spread = 45.0; //limit to material - bool DoMaterialLimited; + bool DoMaterialLimited = false; QString LimtedToMatName; - //Activity - double Activity; + //Relative activity + double Activity = 1.0; //particles QVector GunParticles; - //constructor - creates a default source with _no_ particles! - ParticleSourceStructure(); - - //destructor - takes care of dynamic GunParticles - ~ParticleSourceStructure(); + ~AParticleSourceRecord(); //deletes records in dynamic GunParticles + AParticleSourceRecord * clone() const; //local variables, used in tracking, calculated autonatically, not to be loaded/saved! int LimitedToMat; //automatically calculated if LimtedToMatName matches a material - bool fLimit; + bool fLimit = false; }; class GeneratedParticleStructure @@ -114,13 +105,13 @@ class ParticleSourcesClass : public QObject //requests int size() {return ParticleSourcesData.size();} double getTotalActivity(); - ParticleSourceStructure* getSource(int iSource) {return ParticleSourcesData[iSource];} + AParticleSourceRecord* getSource(int iSource) {return ParticleSourcesData[iSource];} //ParticleSourceStructure &operator[] (int iSource) {return *ParticleSourcesData[iSource];} - ParticleSourceStructure* getLastSource() {return ParticleSourcesData.last();} + AParticleSourceRecord* getLastSource() {return ParticleSourcesData.last();} //ParticleSourceStructure &last() {return *ParticleSourcesData.last();} //Source handling - after handling is finished, requires Init() !!! - void append(ParticleSourceStructure* gunParticle); + void append(AParticleSourceRecord* gunParticle); void remove(int iSource); void clear(); @@ -137,7 +128,7 @@ class ParticleSourcesClass : public QObject bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); TVector3 GenerateRandomDirection(); - void checkLimitedToMaterial(ParticleSourceStructure *s); + void checkLimitedToMaterial(AParticleSourceRecord *s); //for remove particle from configuration void RemoveParticle(int particleId); //should NOT be used to remove one of particles in use! use onIspareticleInUse first @@ -151,7 +142,7 @@ class ParticleSourcesClass : public QObject TString NameID; //use to make unique hist name in multithread environment /// - actually not needed anymore! - QVector ParticleSourcesData; + QVector ParticleSourcesData; QVector TotalParticleWeight; double TotalActivity; QVector< QVector< QVector > > LinkedPartiles; //[isource] [iparticle] [] (includes the record of the particle iteslf!!!) From 19db2204e3f0072f966b1ec5f7ecfd1109e523b5 Mon Sep 17 00:00:00 2001 From: vovasolo Date: Mon, 15 Oct 2018 14:31:31 +0100 Subject: [PATCH 073/140] Added NCrystal to docker image in ants2.pro --- src/ants2.pro | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ants2.pro b/src/ants2.pro index d33c39ad..375de42d 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -16,7 +16,8 @@ ants2_docker { CONFIG += ants2_flann #enable FLANN (fast neighbour search) library: see https://github.com/mariusmuja/flann CONFIG += ants2_fann #enables FANN (fast neural network) library: see https://github.com/libfann/fann CONFIG += ants2_RootServer #enable cern CERN ROOT html server - CONFIG += ants2_Python #enable Python scripting + CONFIG += ants2_Python #enable Python scripting + CONFIG += ants2_NCrystal #enable NCrystal library (neutron scattering) } DEBUG_VERBOSITY = 1 # 0 - debug messages suppressed, 1 - normal, 2 - normal + file/line information @@ -233,10 +234,16 @@ ants2_NCrystal{ LIBS += -LC:/NCrystal/lib -lNCrystal } linux-g++ || unix { - INCLUDEPATH += /home/andr/Work/NCrystal/include + ants2_docker { + INCLUDEPATH += /usr/local/include/NCrystal/ + LIBS += -L/usr/local/lib/ + LIBS += -lNCrystal - LIBS += -L/home/andr/Work/NCrystal/lib/ - LIBS += -lNCrystal + } else { + INCLUDEPATH += /home/andr/Work/NCrystal/include + LIBS += -L/home/andr/Work/NCrystal/lib/ + LIBS += -lNCrystal + } } SOURCES += common/arandomgenncrystal.cpp From ba19b662fb89624192f371ecc14c05d9fb8ca38e Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 15 Oct 2018 17:32:47 +0100 Subject: [PATCH 074/140] ++ --- src/ants2.pro | 18 +- src/aparticlesourcedialog.cpp | 77 -- src/aparticlesourcedialog.h | 37 - .../MainWindowParticleSimulation.cpp | 6 +- .../MainWindowTools/aparticlesourcedialog.cpp | 337 +++++ .../MainWindowTools/aparticlesourcedialog.h | 57 + .../MainWindowTools}/aparticlesourcedialog.ui | 1181 ++++++++++------- src/gui/gainevaluatorwindowclass.cpp | 7 - src/gui/gainevaluatorwindowclass.h | 1 - src/gui/mainwindow.cpp | 8 + src/gui/mainwindow.h | 5 +- src/gui/mainwindow.ui | 243 ++-- src/gui/reconstructionwindow.cpp | 4 +- src/modules/amaterialparticlecolection.cpp | 10 +- src/modules/amaterialparticlecolection.h | 1 + src/modules/particlesourcesclass.cpp | 3 + src/modules/particlesourcesclass.h | 15 +- 17 files changed, 1250 insertions(+), 760 deletions(-) delete mode 100644 src/aparticlesourcedialog.cpp delete mode 100644 src/aparticlesourcedialog.h create mode 100644 src/gui/MainWindowTools/aparticlesourcedialog.cpp create mode 100644 src/gui/MainWindowTools/aparticlesourcedialog.h rename src/{ => gui/MainWindowTools}/aparticlesourcedialog.ui (63%) diff --git a/src/ants2.pro b/src/ants2.pro index ca83e581..84db9093 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -356,8 +356,7 @@ SOURCES += main.cpp \ OpticalOverrides/awaveshifteroverride.cpp \ OpticalOverrides/spectralbasicopticaloverride.cpp \ OpticalOverrides/abasicopticaloverride.cpp \ - common/aglobalsettings.cpp \ - aparticlesourcedialog.cpp + common/aglobalsettings.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -489,8 +488,7 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/awaveshifteroverride.h \ OpticalOverrides/spectralbasicopticaloverride.h \ OpticalOverrides/abasicopticaloverride.h \ - common/aglobalsettings.h \ - aparticlesourcedialog.h + common/aglobalsettings.h # --- SIM --- ants2_SIM { @@ -607,7 +605,8 @@ ants2_GUI { gui/MainWindowTools/atrackdrawdialog.cpp \ gui/aserverdelegate.cpp \ gui/MainWindowTools/aopticaloverridedialog.cpp \ - gui/MainWindowTools/aopticaloverridetester.cpp + gui/MainWindowTools/aopticaloverridetester.cpp \ + gui/MainWindowTools/aparticlesourcedialog.cpp HEADERS += gui/mainwindow.h \ gui/materialinspectorwindow.h \ @@ -666,7 +665,8 @@ HEADERS += gui/mainwindow.h \ gui/MainWindowTools/atrackdrawdialog.h \ gui/aserverdelegate.h \ gui/MainWindowTools/aopticaloverridedialog.h \ - gui/MainWindowTools/aopticaloverridetester.h + gui/MainWindowTools/aopticaloverridetester.h \ + gui/MainWindowTools/aparticlesourcedialog.h FORMS += gui/mainwindow.ui \ gui/materialinspectorwindow.ui \ @@ -698,7 +698,8 @@ FORMS += gui/mainwindow.ui \ gui/aremotewindow.ui \ gui/MainWindowTools/atrackdrawdialog.ui \ gui/MainWindowTools/aopticaloverridedialog.ui \ - gui/MainWindowTools/aopticaloverridetester.ui + gui/MainWindowTools/aopticaloverridetester.ui \ + gui/MainWindowTools/aparticlesourcedialog.ui INCLUDEPATH += gui INCLUDEPATH += gui/RasterWindow @@ -816,6 +817,3 @@ unix { } #------------ -FORMS += \ - aparticlesourcedialog.ui - diff --git a/src/aparticlesourcedialog.cpp b/src/aparticlesourcedialog.cpp deleted file mode 100644 index 1996fd1d..00000000 --- a/src/aparticlesourcedialog.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "aparticlesourcedialog.h" -#include "ui_aparticlesourcedialog.h" -#include "mainwindow.h" - -#include - -AParticleSourceDialog::AParticleSourceDialog(MainWindow &MW, const AParticleSourceRecord &Rec) : - QDialog(*MW), ui(new Ui::AParticleSourceDialog), - MW(MW), Rec(Rec.clone()) -{ - ui->setupUi(this); -} - -AParticleSourceDialog::~AParticleSourceDialog() -{ - delete ui; - delete Rec; -} - -void AParticleSourceDialog::on_pbAccept_clicked() -{ - accept(); -} - -void AParticleSourceDialog::on_pbReject_clicked() -{ - reject(); -} - -void AParticleSourceDialog::on_pbGunTest_clicked() -{ - -} - -void AParticleSourceDialog::on_cobGunSourceType_currentIndexChanged(int index) -{ - QVector s; - switch (index) - { - default: - case 0: s <<""<<""<<""; - break; - case 1: s <<"Length:"<<""<<""; - break; - case 2: s <<"Size X:"<<"Size Y:"<<""; - break; - case 3: s <<"Diameter:"<<""<<""; - break; - case 4: s <<"Size X:"<<"Size Y:"<<"Size Z:"; - break; - case 5: s <<"Diameter:"<<""<<"Height:"; - break; - default: - qWarning() << "Unknown source type!"; - } - ui->lGun1DSize->setText(s[0]); - ui->lGun2DSize->setText(s[1]); - ui->lGun3DSize->setText(s[2]); - ui->fGun1D->setVisible(!s[0].isEmpty()); - ui->fGun2D->setVisible(!s[1].isEmpty()); - ui->fGun3D->setVisible(!s[2].isEmpty()); - - ui->fGunPhi->setEnabled(index != 0); - ui->fGunTheta->setEnabled(index != 0); - ui->fGunPsi->setEnabled(index > 1); - - if (index == 1) - { - ui->labGunPhi->setText("Phi"); - ui->labGunTheta->setText("Theta"); - } - else - { - ui->labGunPhi->setText("around X"); - ui->labGunTheta->setText("around Y"); - } -} diff --git a/src/aparticlesourcedialog.h b/src/aparticlesourcedialog.h deleted file mode 100644 index 78db0575..00000000 --- a/src/aparticlesourcedialog.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef APARTICLESOURCEDIALOG_H -#define APARTICLESOURCEDIALOG_H - -#include "particlesourcesclass.h" - -#include - -namespace Ui { -class AParticleSourceDialog; -} - -class MainWindow; - -class AParticleSourceDialog : public QDialog -{ - Q_OBJECT - -public: - explicit AParticleSourceDialog(MainWindow& MW, const AParticleSourceRecord& Rec); - ~AParticleSourceDialog(); - - const AParticleSourceRecord& getResultToClone() const {return Rec;} //clone the result! - -private slots: - void on_pbAccept_clicked(); - void on_pbReject_clicked(); - void on_pbGunTest_clicked(); - - void on_cobGunSourceType_currentIndexChanged(int index); - -private: - Ui::AParticleSourceDialog *ui; - MainWindow& MW; - AParticleSourceRecord Rec; -}; - -#endif // APARTICLESOURCEDIALOG_H diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index f1808899..cc99941b 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -51,10 +51,8 @@ void MainWindow::SimParticleSourcesConfigToJson(QJsonObject &json) json["ParticleSourcesConfig"] = masterjs; } -void MainWindow::ShowSource(int isource, bool clear) +void MainWindow::ShowSource(const AParticleSourceRecord* p, bool clear) { - const AParticleSourceRecord* p = ParticleSources->getSource(isource); - int index = p->index; double X0 = p->X0; double Y0 = p->Y0; @@ -901,7 +899,7 @@ void MainWindow::ShowParticleSource_noFocus() message("Source number is out of bounds!",this); return; } - ShowSource(isource, true); + ShowSource(ParticleSources->getSource(isource), true); } void MainWindow::on_lwGunParticles_currentRowChanged(int /*currentRow*/) diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.cpp b/src/gui/MainWindowTools/aparticlesourcedialog.cpp new file mode 100644 index 00000000..fe5d128c --- /dev/null +++ b/src/gui/MainWindowTools/aparticlesourcedialog.cpp @@ -0,0 +1,337 @@ +#include "aparticlesourcedialog.h" +#include "ui_aparticlesourcedialog.h" +#include "mainwindow.h" +#include "amaterialparticlecolection.h" +#include "amessage.h" + +#include + +AParticleSourceDialog::AParticleSourceDialog(MainWindow & MW, const AParticleSourceRecord * Rec) : + QDialog(&MW), + MW(MW), Rec(Rec->clone()), + ui(new Ui::AParticleSourceDialog) +{ + ui->setupUi(this); + + ui->pbUpdateRecord->setDefault(true); + ui->pbUpdateRecord->setVisible(false); + + ui->cobGunParticle->addItems(MW.MpCollection->getListOfParticleNames()); + + ui->leSourceName->setText(Rec->name); + ui->cobGunSourceType->setCurrentIndex(Rec->index); + + ui->ledGun1DSize->setText(QString::number(2.0 * Rec->size1)); + ui->ledGun2DSize->setText(QString::number(2.0 * Rec->size2)); + ui->ledGun3DSize->setText(QString::number(2.0 * Rec->size3)); + + ui->ledGunOriginX->setText(QString::number(Rec->X0)); + ui->ledGunOriginY->setText(QString::number(Rec->Y0)); + ui->ledGunOriginZ->setText(QString::number(Rec->Z0)); + + ui->ledGunPhi->setText(QString::number(Rec->Phi)); + ui->ledGunTheta->setText(QString::number(Rec->Theta)); + ui->ledGunPsi->setText(QString::number(Rec->Psi)); + + ui->ledGunCollPhi->setText(QString::number(Rec->CollPhi)); + ui->ledGunCollTheta->setText(QString::number(Rec->CollTheta)); + ui->ledGunSpread->setText(QString::number(Rec->Spread)); + + ui->cbSourceLimitmat->setChecked(Rec->DoMaterialLimited); + ui->leSourceLimitMaterial->setText(Rec->LimtedToMatName); + + ui->frSecondary->setVisible(false); + UpdateListWidget(); + if ( !Rec->GunParticles.isEmpty() ) + { + ui->lwGunParticles->setCurrentRow(0); + UpdateParticleInfo(); + } +} + +AParticleSourceDialog::~AParticleSourceDialog() +{ + delete ui; + delete Rec; +} + +AParticleSourceRecord *AParticleSourceDialog::getResult() +{ + AParticleSourceRecord* tmp = Rec; + Rec = 0; + return tmp; +} + +void AParticleSourceDialog::on_pbAccept_clicked() +{ + accept(); +} + +void AParticleSourceDialog::on_pbReject_clicked() +{ + reject(); +} + +void AParticleSourceDialog::on_pbGunTest_clicked() +{ + +} + +void AParticleSourceDialog::on_cobGunSourceType_currentIndexChanged(int index) +{ + QVector s; + switch (index) + { + case 0: s <<""<<""<<""; + break; + case 1: s <<"Length:"<<""<<""; + break; + case 2: s <<"Size X:"<<"Size Y:"<<""; + break; + case 3: s <<"Diameter:"<<""<<""; + break; + case 4: s <<"Size X:"<<"Size Y:"<<"Size Z:"; + break; + case 5: s <<"Diameter:"<<""<<"Height:"; + break; + default: + qWarning() << "Unknown source type!"; + s <<""<<""<<""; + } + ui->lGun1DSize->setText(s[0]); + ui->lGun2DSize->setText(s[1]); + ui->lGun3DSize->setText(s[2]); + + bool b1 = !s[0].isEmpty(); + ui->lGun1DSize->setVisible(b1); + ui->ledGun1DSize->setVisible(b1); + ui->lGun1DSize_mm->setVisible(b1); + + bool b2 = !s[1].isEmpty(); + ui->lGun2DSize->setVisible(b2); + ui->ledGun2DSize->setVisible(b2); + ui->lGun2DSize_mm->setVisible(b2); + + bool b3 = !s[2].isEmpty(); + ui->lGun3DSize->setVisible(b3); + ui->ledGun3DSize->setVisible(b3); + ui->lGun3DSize_mm->setVisible(b3); + + ui->ledGunPhi->setEnabled(index != 0); + ui->ledGunTheta->setEnabled(index != 0); + ui->ledGunPsi->setEnabled(index > 1); + + if (index == 1) + { + ui->labGunPhi->setText("Phi"); + ui->labGunTheta->setText("Theta"); + } + else + { + ui->labGunPhi->setText("around X"); + ui->labGunTheta->setText("around Y"); + } +} + +void AParticleSourceDialog::on_pbGunAddNew_clicked() +{ + GunParticleStruct* tmp = new GunParticleStruct(); + tmp->ParticleId = ui->cobGunParticle->currentIndex(); + tmp->StatWeight = ui->ledGunParticleWeight->text().toDouble(); + tmp->energy = ui->ledGunEnergy->text().toDouble(); + tmp->spectrum = 0; + Rec->GunParticles << tmp; + + UpdateListWidget(); + ui->lwGunParticles->setCurrentRow( Rec->GunParticles.size()-1 ); + UpdateParticleInfo(); +} + +void AParticleSourceDialog::on_pbGunRemove_clicked() +{ + if (Rec->GunParticles.size() < 2) + { + message("There should be at least one particle!", this); + return; + } + + int iparticle = ui->lwGunParticles->currentRow(); + if (iparticle == -1) + { + message("Select a particle to remove!", this); + return; + } + + delete Rec->GunParticles[iparticle]; + Rec->GunParticles.remove(iparticle); + + UpdateListWidget(); + ui->lwGunParticles->setCurrentRow( Rec->GunParticles.size()-1 ); + UpdateParticleInfo(); +} + +void AParticleSourceDialog::UpdateListWidget() +{ + ui->lwGunParticles->clear(); + int counter = 0; + for (const GunParticleStruct* gps : Rec->GunParticles) + { + bool Individual = gps->Individual; + + QString str, str1; + if (Individual) str = ""; + else str = ">"; + str1.setNum(counter++); + str += str1 + "> "; + str += MW.MpCollection->getParticleName(gps->ParticleId); + if (gps->spectrum) str += " E=spec"; + else + { + str1.setNum(gps->energy); + str += " E=" + str1; + } + + if (Individual) + { + str += " W="; + str1.setNum(gps->StatWeight); + str += str1; + } + else + { + str += " Link:"; + str += QString::number(gps->LinkedTo); + str += " P="; + str += QString::number(gps->LinkingProbability); + if (gps->LinkingOppositeDir) + str += " Opposite"; + } + ui->lwGunParticles->addItem(str); + } +} + +void AParticleSourceDialog::UpdateParticleInfo() +{ + int row = ui->lwGunParticles->currentRow(); + + int DefinedSourceParticles = Rec->GunParticles.size(); + if (DefinedSourceParticles > 0 && row>-1) + { + ui->fGunParticle->setEnabled(true); + int part = Rec->GunParticles.at(row)->ParticleId; + ui->cobGunParticle->setCurrentIndex(part); + + const GunParticleStruct* gRec = Rec->GunParticles.at(row); + + QString str; + str.setNum(gRec->StatWeight); + ui->ledGunParticleWeight->setText(str); + + int iPrefUnits = ui->cobUnits->findText(gRec->PreferredUnits); + double energy = gRec->energy; + if (iPrefUnits > -1) + { + ui->cobUnits->setCurrentIndex(iPrefUnits); + if (gRec->PreferredUnits == "MeV") energy *= 1.0e-3; + else if (gRec->PreferredUnits == "keV") ; + else if (gRec->PreferredUnits == "eV") energy *= 1.0e3; + else if (gRec->PreferredUnits == "meV") energy *= 1.0e6; + } + else ui->cobUnits->setCurrentText("keV"); + ui->ledGunEnergy->setText( QString::number(energy) ); + + ui->cbLinkedParticle->setChecked(!gRec->Individual); + ui->frSecondary->setVisible(!gRec->Individual); + ui->leiParticleLinkedTo->setText( QString::number(gRec->LinkedTo) ); + str.setNum(gRec->LinkingProbability); + ui->ledLinkingProbability->setText(str); + ui->cbLinkingOpposite->setChecked(gRec->LinkingOppositeDir); + if (gRec->spectrum == 0) + { + ui->pbGunShowSpectrum->setEnabled(false); + ui->ledGunEnergy->setEnabled(true); + ui->rbFixed->setChecked(true); + } + else + { + ui->pbGunShowSpectrum->setEnabled(true); + ui->ledGunEnergy->setEnabled(false); + ui->rbSpectrum->setChecked(false); + } + } + else ui->fGunParticle->setEnabled(false); +} + +void AParticleSourceDialog::on_lwGunParticles_currentRowChanged(int) +{ + UpdateParticleInfo(); +} + +void AParticleSourceDialog::on_cobUnits_activated(int) +{ + int iPart = ui->lwGunParticles->currentRow(); + if (iPart == -1) return; + Rec->GunParticles[iPart]->PreferredUnits = ui->cobUnits->currentText(); + UpdateParticleInfo(); +} + +#include "geometrywindowclass.h" +#include "TGeoManager.h" +void AParticleSourceDialog::on_pbShowSource_toggled(bool checked) +{ + if (checked) + { + MW.GeometryWindow->ShowAndFocus(); + MW.ShowSource(Rec, true); + } + else + { + gGeoManager->ClearTracks(); + MW.GeometryWindow->ShowGeometry(); + } +} + +void AParticleSourceDialog::on_cbLinkedParticle_toggled(bool checked) +{ + ui->fLinkedParticle->setVisible(checked); +} + +void AParticleSourceDialog::on_pbUpdateRecord_clicked() +{ + Rec->index = ui->cobGunSourceType->currentIndex(); + + Rec->size1 = 0.5 * ui->ledGun1DSize->text().toDouble(); + Rec->size2 = 0.5 * ui->ledGun2DSize->text().toDouble(); + Rec->size3 = 0.5 * ui->ledGun3DSize->text().toDouble(); + + Rec->DoMaterialLimited = ui->cbSourceLimitmat->isChecked(); + Rec->LimtedToMatName = ui->leSourceLimitMaterial->text(); + //ParticleSources->checkLimitedToMaterial(Rec); + + Rec->X0 = ui->ledGunOriginX->text().toDouble(); + Rec->Y0 = ui->ledGunOriginY->text().toDouble(); + Rec->Z0 = ui->ledGunOriginZ->text().toDouble(); + + Rec->Phi = ui->ledGunPhi->text().toDouble(); + Rec->Theta = ui->ledGunTheta->text().toDouble(); + Rec->Psi = ui->ledGunPsi->text().toDouble(); + + Rec->CollPhi = ui->ledGunCollPhi->text().toDouble(); + Rec->CollTheta = ui->ledGunCollTheta->text().toDouble(); + Rec->Spread = ui->ledGunSpread->text().toDouble(); + + int iPart = ui->lwGunParticles->currentRow(); + if (iPart >= 0) + { + GunParticleStruct* p = Rec->GunParticles[iPart]; + + p->ParticleId = ui->cobGunParticle->currentIndex(); + p->StatWeight = ui->ledGunParticleWeight->text().toDouble(); + p->energy = ui->ledGunEnergy->text().toDouble(); + p->Individual = !ui->cbLinkedParticle->isChecked(); + p->LinkingProbability = ui->ledLinkingProbability->text().toDouble(); + p->LinkingOppositeDir = ui->cbLinkingOpposite->isChecked(); + } + + UpdateParticleInfo(); +} diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.h b/src/gui/MainWindowTools/aparticlesourcedialog.h new file mode 100644 index 00000000..35f8a13c --- /dev/null +++ b/src/gui/MainWindowTools/aparticlesourcedialog.h @@ -0,0 +1,57 @@ +#ifndef APARTICLESOURCEDIALOG_H +#define APARTICLESOURCEDIALOG_H + +#include "particlesourcesclass.h" + +#include + +namespace Ui { +class AParticleSourceDialog; +} + +class MainWindow; + +class AParticleSourceDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AParticleSourceDialog(MainWindow & MW, const AParticleSourceRecord * Rec); + ~AParticleSourceDialog(); + + AParticleSourceRecord* getResult(); //transfers ownership + +private slots: + void on_pbAccept_clicked(); + void on_pbReject_clicked(); + void on_pbGunTest_clicked(); + + void on_cobGunSourceType_currentIndexChanged(int index); + + void on_pbGunAddNew_clicked(); + + void on_pbGunRemove_clicked(); + + void on_lwGunParticles_currentRowChanged(int currentRow); + + void on_cobUnits_activated(int index); + + void on_pbShowSource_toggled(bool checked); + + void on_cbLinkedParticle_toggled(bool checked); + + void on_pbUpdateRecord_clicked(); + +private: + MainWindow& MW; + + AParticleSourceRecord* Rec; + + Ui::AParticleSourceDialog *ui; + +private: + void UpdateListWidget(); + void UpdateParticleInfo(); +}; + +#endif // APARTICLESOURCEDIALOG_H diff --git a/src/aparticlesourcedialog.ui b/src/gui/MainWindowTools/aparticlesourcedialog.ui similarity index 63% rename from src/aparticlesourcedialog.ui rename to src/gui/MainWindowTools/aparticlesourcedialog.ui index 516526ea..83eb63b1 100644 --- a/src/aparticlesourcedialog.ui +++ b/src/gui/MainWindowTools/aparticlesourcedialog.ui @@ -6,14 +6,29 @@ 0 0 - 600 - 627 + 502 + 538 Dialog - + + + 5 + + + 6 + + + 6 + + + 6 + + + 6 + @@ -28,7 +43,7 @@ - Source name: + Source name: @@ -61,7 +76,7 @@ - Geometry: + Geometry: Qt::AlignCenter @@ -114,22 +129,22 @@ - Surface: square + Surface - square - Surface: round + Surface - round - Volume: box + Volume - box - Volume: cylinder + Volume - cylinder @@ -151,211 +166,122 @@ + + 0 + + + + + + + + - + + + Size1: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 75 + 16777215 + + + + 10 + + + + + - + 0 0 - - QFrame::Box + + mm - - QFrame::Raised + + + + + + Size2: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 3 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Size1: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 75 - 16777215 - - - - 10 - - - - - - - - 0 - 0 - - - - mm - - - - - + + + + 75 + 16777215 + + + + 10 + + + + + - + 0 0 - - QFrame::Box + + mm - - QFrame::Raised + + + + + + Size3: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 3 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Size2: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 75 - 16777215 - - - - 10 - - - - - - - - 0 - 0 - - - - mm - - - - - + + + + 75 + 16777215 + + + + 10 + + + + + - + 0 0 - - QFrame::Box - - - QFrame::Raised + + mm - - - 3 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Size3: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 75 - 16777215 - - - - 10 - - - - - - - - 0 - 0 - - - - mm - - - - @@ -373,6 +299,55 @@ + + + + + + + + + + + + + Limit particle generation to the material: + + + + + + + true + + + Particle will be generated only if the point sampled inside the source is located within an object with the indicated material. +If material with this name does not exist, this limitation is not applied. + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ...UpdateRecord + + + + + @@ -382,7 +357,7 @@ - Position of the source center: + Position of the source center: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -391,6 +366,13 @@ + + + + + + + @@ -482,7 +464,7 @@ - Source orientation: + Source orientation: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -492,174 +474,100 @@ - - - QFrame::Box + + + - - QFrame::Raised + + + + + + Phi: + + + Qt::AlignCenter - - - 3 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Phi: - - - Qt::AlignCenter - - - - - - - - 75 - 16777215 - - - - 0 - - - - - - - deg - - - - - - - QFrame::Box + + + + 75 + 16777215 + - - QFrame::Raised + + 0 - - - 3 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Theta: - - - Qt::AlignCenter - - - - - - - - 75 - 16777215 - - - - 0 - - - - - - - deg - - - - - - - QFrame::Box + + + deg - - QFrame::Raised + + + + + + Theta: + + + Qt::AlignCenter + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + deg + + + + + + + around Z: + + + Qt::AlignCenter + + + + + + + + 75 + 16777215 + + + + 0 + + + + + + + deg - - - 3 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - around Z: - - - Qt::AlignCenter - - - - - - - - 75 - 16777215 - - - - 0 - - - - - - - deg - - - - @@ -686,12 +594,19 @@ - Collimation direction: + Collimation direction: + + + + + + + @@ -753,35 +668,12 @@ - - - Qt::Horizontal - - - - 40 - 20 - + + + Collimation cone: - + - - - - - - - 75 - true - - - - Collimation cone (angle from collimation direction): - - - - - @@ -790,6 +682,9 @@ 16777215 + + Angle from the collimation direction + 45 @@ -803,7 +698,7 @@ - + Qt::Horizontal @@ -818,22 +713,28 @@ - - - - - - - - 75 - true - - - - Particle composition: - - - + + + + 75 + true + + + + Particle composition: + + + + + + + 1 + + + + + 0 + @@ -880,7 +781,7 @@ - 275 + 250 16777215 @@ -892,19 +793,19 @@ - 2 + 1 3 - 3 + 1 - 3 + 1 - 3 + 1 @@ -914,7 +815,7 @@ - + 0 0 @@ -925,6 +826,12 @@ 0 + + + 120 + 16777215 + + @@ -938,6 +845,9 @@ Stat weight: + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -958,9 +868,12 @@ - + - Fixed energy: + Fixed energy + + + true @@ -973,12 +886,12 @@ - 1000 + 100 - + MeV @@ -1019,9 +932,9 @@ - + - Energy spectrum: + Energy spectrum @@ -1032,7 +945,7 @@ - 50 + 45 0 @@ -1045,7 +958,7 @@ - 50 + 45 0 @@ -1060,12 +973,12 @@ - + - Linked particle: + Linked particle - true + false @@ -1078,7 +991,7 @@ - QFrame::Box + QFrame::NoFrame QFrame::Raised @@ -1214,13 +1127,6 @@ 0 - label_152 - label_153 - ledLinkingProbability - leiParticleLinkedTo - cbLinkingOpposite - horizontalSpacer_12 - horizontalSpacer_13 @@ -1237,64 +1143,14 @@ - pbGunDeleteSpectrum - pbGunLoadSpectrum - cbIndividualParticle + cbLinkedParticle fLinkedParticle - pbGunShowSpectrum - radioButton - ledGunEnergy - comboBox - radioButton_2 verticalSpacer - horizontalLayoutWidget_2 frSecondary - - - - - - Limit particle generation to the material: - - - - - - - true - - - Particle will be generated only if the point sampled inside the source is located within an object with the indicated material. -If material with this name does not exist, this limitation is not applied. - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - ... - - - - - @@ -1305,17 +1161,27 @@ If material with this name does not exist, this limitation is not applied. - - - Qt::Horizontal - - + + - 40 - 20 + 200 + 0 - + + Show source + + + true + + + + + + + Qt::Vertical + + @@ -1343,19 +1209,6 @@ If material with this name does not exist, this limitation is not applied. - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -1385,7 +1238,7 @@ If material with this name does not exist, this limitation is not applied. 150 - 35 + 31 @@ -1417,7 +1270,7 @@ If material with this name does not exist, this limitation is not applied. 150 - 35 + 31 @@ -1451,18 +1304,354 @@ If material with this name does not exist, this limitation is not applied. - cbIndividualParticle - toggled(bool) - frSecondary - setEnabled(bool) + leSourceName + editingFinished() + pbUpdateRecord + click() + + + 274 + 15 + + + 478 + 126 + + + + + cobGunSourceType + activated(int) + pbUpdateRecord + click() + + + 228 + 72 + + + 455 + 125 + + + + + ledGun1DSize + editingFinished() + pbUpdateRecord + click() + + + 124 + 94 + + + 432 + 122 + + + + + ledGun2DSize + editingFinished() + pbUpdateRecord + click() + + + 262 + 97 + + + 417 + 130 + + + + + ledGun3DSize + editingFinished() + pbUpdateRecord + click() + + + 388 + 93 + + + 426 + 128 + + + + + cbSourceLimitmat + clicked() + pbUpdateRecord + click() + + + 99 + 126 + + + 440 + 124 + + + + + leSourceLimitMaterial + editingFinished() + pbUpdateRecord + click() + + + 355 + 127 + + + 440 + 127 + + + + + ledGunOriginX + editingFinished() + pbUpdateRecord + click() + + + 84 + 170 + + + 433 + 120 + + + + + ledGunOriginY + editingFinished() + pbUpdateRecord + click() + + + 212 + 176 + + + 439 + 125 + + + + + ledGunOriginZ + editingFinished() + pbUpdateRecord + click() + + + 322 + 171 + + + 491 + 131 + + + + + ledGunPhi + editingFinished() + pbUpdateRecord + click() + + + 103 + 213 + + + 434 + 127 + + + + + ledGunTheta + editingFinished() + pbUpdateRecord + click() + + + 242 + 215 + + + 421 + 124 + + + + + ledGunPsi + editingFinished() + pbUpdateRecord + click() + + + 412 + 211 + + + 421 + 125 + + + + + ledGunCollPhi + editingFinished() + pbUpdateRecord + click() + + + 64 + 261 + + + 418 + 123 + + + + + ledGunCollTheta + editingFinished() + pbUpdateRecord + click() + + + 190 + 265 + + + 429 + 131 + + + + + ledGunSpread + editingFinished() + pbUpdateRecord + click() + + + 402 + 258 + + + 416 + 128 + + + + + ledGunParticleWeight + editingFinished() + pbUpdateRecord + click() + + + 470 + 304 + + + 465 + 124 + + + + + cobGunParticle + activated(int) + pbUpdateRecord + click() + + + 342 + 305 + + + 443 + 129 + + + + + ledGunEnergy + editingFinished() + pbUpdateRecord + click() + + + 386 + 328 + + + 454 + 123 + + + + + cbLinkedParticle + clicked() + pbUpdateRecord + click() + + + 310 + 381 + + + 445 + 122 + + + + + ledLinkingProbability + editingFinished() + pbUpdateRecord + click() 373 - 406 + 427 + + + 441 + 128 + + + + + cbLinkingOpposite + clicked() + pbUpdateRecord + click() + + + 441 + 426 - 531 - 421 + 466 + 121 diff --git a/src/gui/gainevaluatorwindowclass.cpp b/src/gui/gainevaluatorwindowclass.cpp index 13e9885e..5b2d5290 100644 --- a/src/gui/gainevaluatorwindowclass.cpp +++ b/src/gui/gainevaluatorwindowclass.cpp @@ -2592,13 +2592,6 @@ void GainEvaluatorWindowClass::UpdateTriads() Triads.SetEvents(list, &EventsDataHub->Events); } -void GainEvaluatorWindowClass::SetWindowFont(int ptsize) -{ - QFont font = this->font(); - font.setPointSize(ptsize); - this->setFont(font); -} - void GainEvaluatorWindowClass::on_pbShowNonLinkedSet_clicked() { flagShowNonLinkedSet = true; diff --git a/src/gui/gainevaluatorwindowclass.h b/src/gui/gainevaluatorwindowclass.h index 3e492f6d..ad163c40 100644 --- a/src/gui/gainevaluatorwindowclass.h +++ b/src/gui/gainevaluatorwindowclass.h @@ -75,7 +75,6 @@ class GainEvaluatorWindowClass : public QMainWindow double CalculateAreaFraction(int ipm1, int ipm2); //return area(pm1)/area(pm2) double getPolygonArea(QPolygonF &qpolygonf); //for non-self intersecting polygons! - void SetWindowFont(int ptsize); public slots: void UpdateGraphics(); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index e29642d2..45b854d3 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4993,3 +4993,11 @@ void MainWindow::on_pbPMtypeHelp_clicked() " represent the photocathode."; message(s, this); } + +#include "aparticlesourcedialog.h" +void MainWindow::on_pushButton_2_clicked() +{ + int isource = ui->cobParticleSource->currentIndex(); + AParticleSourceDialog d(*this, ParticleSources->getSource(isource)); + d.exec(); +} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 380e4656..bf0c193b 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -414,6 +414,7 @@ private slots: void UpdateCustomScanNodesIndication(); void CalculateIndividualQEPDE(); //Public for use in scripting void clearEnergyVector(); + void ShowSource(const AParticleSourceRecord *p, bool clear = true); private: bool startupDetector(); //on ANTS start load/create detector void PointSource_UpdateTabWidget(); @@ -434,8 +435,6 @@ private slots: int LoadSPePHSfile(QString fileName, QVector* SPePHS_x, QVector* SPePHS); ///see MainWindowDiskIO.cpp QStringList LoadedEventFiles, LoadedTreeFiles; - void ShowSource(int isource, bool clear = true); - QString CheckerScript; QVector ScanFloodNoise; @@ -613,6 +612,8 @@ private slots: void on_pbPMtypeHelp_clicked(); + void on_pushButton_2_clicked(); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index a3b00514..68d5327f 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9669,7 +9669,7 @@ double events: - 1 + 3 @@ -11018,6 +11018,19 @@ If material with this name does not exist, this limitation is not applied.-- + + + + 330 + 10 + 75 + 23 + + + + PushButton + + @@ -14542,8 +14555,8 @@ on stack setCurrentIndex(int) - 370 - 433 + 368 + 411 519 @@ -14574,8 +14587,8 @@ on stack setCurrentIndex(int) - 309 - 406 + 313 + 384 257 @@ -14606,8 +14619,8 @@ on stack click() - 201 - 360 + 203 + 382 449 @@ -14622,8 +14635,8 @@ on stack click() - 281 - 360 + 283 + 382 449 @@ -14638,8 +14651,8 @@ on stack click() - 361 - 360 + 363 + 382 449 @@ -14654,8 +14667,8 @@ on stack click() - 417 - 363 + 419 + 385 449 @@ -14670,8 +14683,8 @@ on stack click() - 417 - 394 + 419 + 416 449 @@ -14686,8 +14699,8 @@ on stack click() - 417 - 424 + 419 + 446 449 @@ -14702,8 +14715,8 @@ on stack click() - 201 - 427 + 203 + 449 449 @@ -14718,8 +14731,8 @@ on stack click() - 282 - 427 + 284 + 449 449 @@ -14734,8 +14747,8 @@ on stack click() - 362 - 427 + 364 + 449 449 @@ -14750,8 +14763,8 @@ on stack click() - 175 - 374 + 177 + 396 449 @@ -14766,8 +14779,8 @@ on stack click() - 285 - 374 + 287 + 396 449 @@ -14782,8 +14795,8 @@ on stack click() - 227 - 430 + 229 + 452 449 @@ -14814,8 +14827,8 @@ on stack setHidden(bool) - 358 - 406 + 360 + 428 513 @@ -14878,8 +14891,8 @@ on stack setVisible(bool) - 358 - 406 + 360 + 428 504 @@ -16206,8 +16219,8 @@ on stack click() - 227 - 419 + 225 + 397 46 @@ -16222,8 +16235,8 @@ on stack click() - 317 - 419 + 315 + 397 92 @@ -16238,8 +16251,8 @@ on stack click() - 407 - 419 + 405 + 397 112 @@ -16254,8 +16267,8 @@ on stack click() - 178 - 398 + 182 + 376 40 @@ -16270,8 +16283,8 @@ on stack click() - 250 - 398 + 254 + 376 61 @@ -16286,8 +16299,8 @@ on stack click() - 321 - 398 + 325 + 376 88 @@ -16302,8 +16315,8 @@ on stack click() - 172 - 440 + 176 + 418 31 @@ -16318,8 +16331,8 @@ on stack click() - 214 - 440 + 218 + 418 48 @@ -16334,8 +16347,8 @@ on stack click() - 256 - 440 + 260 + 418 47 @@ -16350,8 +16363,8 @@ on stack click() - 323 - 441 + 327 + 419 83 @@ -16366,8 +16379,8 @@ on stack click() - 422 - 440 + 426 + 418 101 @@ -16382,8 +16395,8 @@ on stack click() - 106 - 459 + 110 + 437 43 @@ -16398,8 +16411,8 @@ on stack click() - 172 - 461 + 176 + 439 14 @@ -16414,8 +16427,8 @@ on stack click() - 214 - 461 + 218 + 439 28 @@ -16430,8 +16443,8 @@ on stack click() - 256 - 461 + 260 + 439 50 @@ -16446,8 +16459,8 @@ on stack click() - 325 - 462 + 329 + 440 77 @@ -16462,8 +16475,8 @@ on stack click() - 389 - 461 + 393 + 439 122 @@ -16478,8 +16491,8 @@ on stack click() - 125 - 480 + 129 + 458 44 @@ -16494,8 +16507,8 @@ on stack click() - 172 - 482 + 176 + 460 52 @@ -16510,8 +16523,8 @@ on stack click() - 214 - 482 + 218 + 460 36 @@ -16526,8 +16539,8 @@ on stack click() - 256 - 482 + 260 + 460 50 @@ -16542,8 +16555,8 @@ on stack click() - 322 - 483 + 326 + 461 75 @@ -16558,8 +16571,8 @@ on stack click() - 428 - 482 + 432 + 460 111 @@ -16574,8 +16587,8 @@ on stack click() - 158 - 406 + 162 + 384 36 @@ -16590,8 +16603,8 @@ on stack click() - 309 - 406 + 313 + 384 51 @@ -16606,8 +16619,8 @@ on stack click() - 129 - 436 + 127 + 414 40 @@ -16622,8 +16635,8 @@ on stack click() - 129 - 458 + 127 + 436 57 @@ -16638,8 +16651,8 @@ on stack click() - 225 - 436 + 223 + 414 58 @@ -16654,8 +16667,8 @@ on stack click() - 225 - 458 + 223 + 436 37 @@ -16670,8 +16683,8 @@ on stack click() - 370 - 433 + 368 + 411 97 @@ -16686,8 +16699,8 @@ on stack click() - 369 - 456 + 367 + 434 110 @@ -16702,8 +16715,8 @@ on stack click() - 159 - 438 + 157 + 416 31 @@ -16718,8 +16731,8 @@ on stack click() - 159 - 459 + 157 + 437 33 @@ -16734,8 +16747,8 @@ on stack click() - 239 - 438 + 237 + 416 68 @@ -16750,8 +16763,8 @@ on stack click() - 239 - 459 + 237 + 437 58 @@ -16766,8 +16779,8 @@ on stack click() - 370 - 456 + 368 + 434 119 @@ -16782,8 +16795,8 @@ on stack click() - 466 - 456 + 464 + 434 122 @@ -17198,8 +17211,8 @@ on stack click() - 208 - 406 + 214 + 428 495 @@ -17214,12 +17227,12 @@ on stack setVisible(bool) - 186 - 406 + 192 + 428 - 179 - 432 + 185 + 454 @@ -17230,8 +17243,8 @@ on stack click() - 237 - 432 + 239 + 454 480 diff --git a/src/gui/reconstructionwindow.cpp b/src/gui/reconstructionwindow.cpp index da3431f6..f0d6d069 100644 --- a/src/gui/reconstructionwindow.cpp +++ b/src/gui/reconstructionwindow.cpp @@ -3606,13 +3606,11 @@ void ReconstructionWindow::ShowGainWindow() //qDebug()<<"-->Creating GainWindow"; QWidget* w = new QWidget(); MW->GainWindow = new GainEvaluatorWindowClass(w, MW, EventsDataHub); - //MW->GainWindow = new GainEvaluatorWindowClass(this, MW, EventsDataHub); // fix font size on Linux #ifdef Q_OS_WIN//Q_OS_LINUX #else - SetWindowFont(MW->GainWindow, 8); - // GainWindow->SetWindowFont(8); + GuiUtils::SetWindowFont(MW->GainWindow, 8); #endif MW->GainWindow->show(); MW->GainWindow->resize(MW->GainWindow->width()+1, MW->GainWindow->height()); diff --git a/src/modules/amaterialparticlecolection.cpp b/src/modules/amaterialparticlecolection.cpp index eaf79f0a..1fe8f6ee 100644 --- a/src/modules/amaterialparticlecolection.cpp +++ b/src/modules/amaterialparticlecolection.cpp @@ -151,7 +151,15 @@ double AMaterialParticleCollection::getParticleMass(int particleIndex) const const AParticle *AMaterialParticleCollection::getParticle(int particleIndex) const { - return ParticleCollection.at(particleIndex); + return ParticleCollection.at(particleIndex); +} + +const QStringList AMaterialParticleCollection::getListOfParticleNames() const +{ + QStringList l; + for (AParticle* p : ParticleCollection) + l << p->ParticleName; + return l; } void AMaterialParticleCollection::clearMaterialCollection() diff --git a/src/modules/amaterialparticlecolection.h b/src/modules/amaterialparticlecolection.h index a83fbf5f..6f4dfd11 100644 --- a/src/modules/amaterialparticlecolection.h +++ b/src/modules/amaterialparticlecolection.h @@ -60,6 +60,7 @@ class AMaterialParticleCollection : public QObject int getParticleCharge(int particleIndex) const; double getParticleMass(int particleIndex) const; const AParticle* getParticle(int particleIndex) const; + const QStringList getListOfParticleNames() const; //Material handling void AddNewMaterial(bool fSuppressChangedSignal = false); diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 5be01cb0..edec04db 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -520,6 +520,7 @@ bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) writeTH1DtoJsonArr(s->GunParticles[ip]->spectrum, ja); jGunParticle["EnergySpectrum"] = ja; } + jGunParticle["PreferredUnits"] = s->GunParticles[ip]->PreferredUnits; jParticleEntries.append(jGunParticle); } json["GunParticles"] = jParticleEntries; @@ -626,6 +627,8 @@ bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) parseJson(jThisGunPart, "LinkingOppositeDir", s->GunParticles[ip]->LinkingOppositeDir ); parseJson(jThisGunPart, "Energy", s->GunParticles[ip]->energy ); + parseJson(jThisGunPart, "PreferredUnits", s->GunParticles[ip]->PreferredUnits ); + QJsonArray ar = jThisGunPart["EnergySpectrum"].toArray(); if (!ar.isEmpty()) { diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 9db01f62..8abdedab 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -15,13 +15,14 @@ class DetectorClass; struct GunParticleStruct { - int ParticleId = 0; - double StatWeight = 1.0; - double energy = 100.0; //in keV - bool Individual = true; // true = individual particle; false = linked - int LinkedTo = 0; // index of the "parent" particle this one is following - double LinkingProbability = 0; //probability to be emitted after the parent particle - bool LinkingOppositeDir = false; // false = random direction; otherwise particle is emitted in the opposite direction in respect to the LinkedTo particle + int ParticleId = 0; + double StatWeight = 1.0; + double energy = 100.0; //in keV + QString PreferredUnits = "keV"; + bool Individual = true; // true = individual particle; false = linked + int LinkedTo = 0; // index of the "parent" particle this one is following + double LinkingProbability = 0; //probability to be emitted after the parent particle + bool LinkingOppositeDir = false; // false = random direction; otherwise particle is emitted in the opposite direction in respect to the LinkedTo particle TH1D* spectrum = 0; //energy spectrum From 177026fb7cb41427ca0189e491c605622f4ab356 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 15 Oct 2018 23:48:17 +0100 Subject: [PATCH 075/140] ++ --- .../MainWindowTools/aparticlesourcedialog.cpp | 164 +++- .../MainWindowTools/aparticlesourcedialog.h | 19 +- .../MainWindowTools/aparticlesourcedialog.ui | 819 ++++++++---------- src/gui/mainwindow.ui | 2 +- src/modules/particlesourcesclass.cpp | 54 +- src/modules/particlesourcesclass.h | 6 +- 6 files changed, 563 insertions(+), 501 deletions(-) diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.cpp b/src/gui/MainWindowTools/aparticlesourcedialog.cpp index fe5d128c..6d84a3cc 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.cpp +++ b/src/gui/MainWindowTools/aparticlesourcedialog.cpp @@ -3,8 +3,16 @@ #include "mainwindow.h" #include "amaterialparticlecolection.h" #include "amessage.h" +#include "geometrywindowclass.h" +#include "graphwindowclass.h" +#include "aglobalsettings.h" #include +#include +#include + +#include "TGeoManager.h" +#include "TH1D.h" AParticleSourceDialog::AParticleSourceDialog(MainWindow & MW, const AParticleSourceRecord * Rec) : QDialog(&MW), @@ -13,6 +21,14 @@ AParticleSourceDialog::AParticleSourceDialog(MainWindow & MW, const AParticleSou { ui->setupUi(this); + setWindowModality(Qt::WindowModal); + setWindowTitle("Particle source configurator"); + + QDoubleValidator* dv = new QDoubleValidator(this); + dv->setNotation(QDoubleValidator::ScientificNotation); + QList list = this->findChildren(); + foreach(QLineEdit *w, list) if (w->objectName().startsWith("led")) w->setValidator(dv); + ui->pbUpdateRecord->setDefault(true); ui->pbUpdateRecord->setVisible(false); @@ -86,11 +102,11 @@ void AParticleSourceDialog::on_cobGunSourceType_currentIndexChanged(int index) break; case 1: s <<"Length:"<<""<<""; break; - case 2: s <<"Size X:"<<"Size Y:"<<""; + case 2: s <<"X:"<<"Y:"<<""; break; case 3: s <<"Diameter:"<<""<<""; break; - case 4: s <<"Size X:"<<"Size Y:"<<"Size Z:"; + case 4: s <<"X:"<<"Y:"<<"Z:"; break; case 5: s <<"Diameter:"<<""<<"Height:"; break; @@ -105,17 +121,14 @@ void AParticleSourceDialog::on_cobGunSourceType_currentIndexChanged(int index) bool b1 = !s[0].isEmpty(); ui->lGun1DSize->setVisible(b1); ui->ledGun1DSize->setVisible(b1); - ui->lGun1DSize_mm->setVisible(b1); bool b2 = !s[1].isEmpty(); ui->lGun2DSize->setVisible(b2); ui->ledGun2DSize->setVisible(b2); - ui->lGun2DSize_mm->setVisible(b2); bool b3 = !s[2].isEmpty(); ui->lGun3DSize->setVisible(b3); ui->ledGun3DSize->setVisible(b3); - ui->lGun3DSize_mm->setVisible(b3); ui->ledGunPhi->setEnabled(index != 0); ui->ledGunTheta->setEnabled(index != 0); @@ -123,13 +136,13 @@ void AParticleSourceDialog::on_cobGunSourceType_currentIndexChanged(int index) if (index == 1) { - ui->labGunPhi->setText("Phi"); - ui->labGunTheta->setText("Theta"); + ui->labGunPhi->setText("Phi:"); + ui->labGunTheta->setText("Theta:"); } else { - ui->labGunPhi->setText("around X"); - ui->labGunTheta->setText("around Y"); + ui->labGunPhi->setText("Around X:"); + ui->labGunTheta->setText("Around Y:"); } } @@ -139,7 +152,6 @@ void AParticleSourceDialog::on_pbGunAddNew_clicked() tmp->ParticleId = ui->cobGunParticle->currentIndex(); tmp->StatWeight = ui->ledGunParticleWeight->text().toDouble(); tmp->energy = ui->ledGunEnergy->text().toDouble(); - tmp->spectrum = 0; Rec->GunParticles << tmp; UpdateListWidget(); @@ -172,6 +184,8 @@ void AParticleSourceDialog::on_pbGunRemove_clicked() void AParticleSourceDialog::UpdateListWidget() { + bUpdateInProgress = true; // >>>--- + ui->lwGunParticles->clear(); int counter = 0; for (const GunParticleStruct* gps : Rec->GunParticles) @@ -184,12 +198,9 @@ void AParticleSourceDialog::UpdateListWidget() str1.setNum(counter++); str += str1 + "> "; str += MW.MpCollection->getParticleName(gps->ParticleId); - if (gps->spectrum) str += " E=spec"; - else - { - str1.setNum(gps->energy); - str += " E=" + str1; - } + if (gps->bUseFixedEnergy) + str += QString(" E=%1").arg(gps->energy); + else str += " E=spec"; if (Individual) { @@ -208,6 +219,8 @@ void AParticleSourceDialog::UpdateListWidget() } ui->lwGunParticles->addItem(str); } + + bUpdateInProgress = false; // <<<--- } void AParticleSourceDialog::UpdateParticleInfo() @@ -242,28 +255,27 @@ void AParticleSourceDialog::UpdateParticleInfo() ui->cbLinkedParticle->setChecked(!gRec->Individual); ui->frSecondary->setVisible(!gRec->Individual); - ui->leiParticleLinkedTo->setText( QString::number(gRec->LinkedTo) ); + ui->sbLinkedTo->setValue(gRec->LinkedTo); str.setNum(gRec->LinkingProbability); ui->ledLinkingProbability->setText(str); ui->cbLinkingOpposite->setChecked(gRec->LinkingOppositeDir); - if (gRec->spectrum == 0) - { - ui->pbGunShowSpectrum->setEnabled(false); - ui->ledGunEnergy->setEnabled(true); - ui->rbFixed->setChecked(true); - } - else - { - ui->pbGunShowSpectrum->setEnabled(true); - ui->ledGunEnergy->setEnabled(false); - ui->rbSpectrum->setChecked(false); - } + + ui->pbGunShowSpectrum->setEnabled(gRec->spectrum); + bool bFix = gRec->bUseFixedEnergy; + ui->cobEnergy->setCurrentIndex( bFix ? 0 : 1 ); + ui->pbGunShowSpectrum->setVisible(!bFix); + ui->pbGunLoadSpectrum->setVisible(!bFix); + ui->pbDeleteSpectrum->setVisible(!bFix); + ui->ledGunEnergy->setVisible(bFix); + ui->cobUnits->setVisible(bFix); } else ui->fGunParticle->setEnabled(false); } void AParticleSourceDialog::on_lwGunParticles_currentRowChanged(int) { + if (bUpdateInProgress) return; + UpdateParticleInfo(); } @@ -275,20 +287,18 @@ void AParticleSourceDialog::on_cobUnits_activated(int) UpdateParticleInfo(); } -#include "geometrywindowclass.h" -#include "TGeoManager.h" void AParticleSourceDialog::on_pbShowSource_toggled(bool checked) { if (checked) - { + { MW.GeometryWindow->ShowAndFocus(); MW.ShowSource(Rec, true); - } + } else - { + { gGeoManager->ClearTracks(); MW.GeometryWindow->ShowGeometry(); - } + } } void AParticleSourceDialog::on_cbLinkedParticle_toggled(bool checked) @@ -327,11 +337,93 @@ void AParticleSourceDialog::on_pbUpdateRecord_clicked() p->ParticleId = ui->cobGunParticle->currentIndex(); p->StatWeight = ui->ledGunParticleWeight->text().toDouble(); - p->energy = ui->ledGunEnergy->text().toDouble(); + p->bUseFixedEnergy = ( ui->cobEnergy->currentIndex() == 0); + p->PreferredUnits = ui->cobUnits->currentText(); + double energy = ui->ledGunEnergy->text().toDouble(); + if (p->PreferredUnits == "MeV") energy *= 1.0e3; + else if (p->PreferredUnits == "keV") ; + else if (p->PreferredUnits == "eV") energy *= 1.0e-3; + else if (p->PreferredUnits == "meV") energy *= 1.0e-6; + p->energy = energy; p->Individual = !ui->cbLinkedParticle->isChecked(); + p->LinkedTo = ui->sbLinkedTo->value(); p->LinkingProbability = ui->ledLinkingProbability->text().toDouble(); p->LinkingOppositeDir = ui->cbLinkingOpposite->isChecked(); } + int curRow = ui->lwGunParticles->currentRow(); + UpdateListWidget(); + if ( curRow < 0 && curRow >= ui->lwGunParticles->count() ) + curRow = 0; + ui->lwGunParticles->setCurrentRow(curRow); + UpdateParticleInfo(); + if (ui->pbShowSource->isChecked()) MW.ShowSource(Rec, true); +} + +void AParticleSourceDialog::on_cbLinkedParticle_clicked(bool checked) +{ + if (checked) + { + if (ui->lwGunParticles->currentRow() == 0) + { + ui->cbLinkedParticle->setChecked(false); + message("First particle cannot be linked", this); + return; + } + } + on_pbUpdateRecord_clicked(); +} + +void AParticleSourceDialog::on_sbLinkedTo_editingFinished() +{ + int index = ui->sbLinkedTo->value(); + if (index >= ui->lwGunParticles->currentRow()) + { + ui->sbLinkedTo->setValue(0); + message("Bad index of the particle linked to! Setting to 0", this); + } + on_pbUpdateRecord_clicked(); +} + +void AParticleSourceDialog::on_ledLinkingProbability_editingFinished() +{ + double val = ui->ledLinkingProbability->text().toDouble(); + if (val < 0 || val > 1.0) + { + ui->ledLinkingProbability->setText(0); + message("Linking probability has to be within [0, 1] range. Setting to 0", this); + } + on_pbUpdateRecord_clicked(); +} + +void AParticleSourceDialog::on_pbGunShowSpectrum_clicked() +{ + int particle = ui->lwGunParticles->currentRow(); + TH1D* h = new TH1D(*Rec->GunParticles[particle]->spectrum); + + h->GetXaxis()->SetTitle("Energy, keV"); + MW.GraphWindow->Draw(h); //registering! + MW.GraphWindow->ShowAndFocus(); +} + +void AParticleSourceDialog::on_pbGunLoadSpectrum_clicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, "Load energy spectrum", MW.GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + MW.GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); + + int iPart = ui->lwGunParticles->currentRow(); + bool bOK = Rec->GunParticles[iPart]->loadSpectrum(fileName); + + //if (!bOK) message("Load file failed!", this); + + UpdateParticleInfo(); +} + +void AParticleSourceDialog::on_pbDeleteSpectrum_clicked() +{ + int iPart = ui->lwGunParticles->currentRow(); + delete Rec->GunParticles[iPart]->spectrum; Rec->GunParticles[iPart]->spectrum = 0; + UpdateParticleInfo(); } diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.h b/src/gui/MainWindowTools/aparticlesourcedialog.h index 35f8a13c..d8a7d761 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.h +++ b/src/gui/MainWindowTools/aparticlesourcedialog.h @@ -25,22 +25,23 @@ private slots: void on_pbAccept_clicked(); void on_pbReject_clicked(); void on_pbGunTest_clicked(); - void on_cobGunSourceType_currentIndexChanged(int index); - void on_pbGunAddNew_clicked(); - void on_pbGunRemove_clicked(); - void on_lwGunParticles_currentRowChanged(int currentRow); - void on_cobUnits_activated(int index); - void on_pbShowSource_toggled(bool checked); - void on_cbLinkedParticle_toggled(bool checked); - void on_pbUpdateRecord_clicked(); + void on_cbLinkedParticle_clicked(bool checked); + void on_sbLinkedTo_editingFinished(); + void on_ledLinkingProbability_editingFinished(); + + void on_pbGunShowSpectrum_clicked(); + + void on_pbGunLoadSpectrum_clicked(); + + void on_pbDeleteSpectrum_clicked(); private: MainWindow& MW; @@ -49,6 +50,8 @@ private slots: Ui::AParticleSourceDialog *ui; + bool bUpdateInProgress = false; + private: void UpdateListWidget(); void UpdateParticleInfo(); diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.ui b/src/gui/MainWindowTools/aparticlesourcedialog.ui index 83eb63b1..a8d27421 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.ui +++ b/src/gui/MainWindowTools/aparticlesourcedialog.ui @@ -7,9 +7,15 @@ 0 0 502 - 538 + 599 + + + 16777215 + 16777215 + + Dialog @@ -35,135 +41,145 @@ 0 - - - - 75 - true - - - - Source name: - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 75 - true - - - - Geometry: - - - Qt::AlignCenter - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - 0 - - - - - - 0 - 0 - - - - - 50 - false - + + + 0 - - Point - + + + + 75 + true + + + + Source name: + + - - Linear - + + + + 75 + true + + + + Geometry: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 5 + + + 0 + - - Surface - square - + - - Surface - round - + + + + 0 + 0 + + + + + 50 + false + + + + + Point + + + + + Linear + + + + + Surface - square + + + + + Surface - round + + + + + Volume - box + + + + + Volume - cylinder + + + + + + + + + 0 + - - Volume - box - + + + + 200 + 0 + + + + Show source + + + true + + - - Volume - cylinder - + + + + + - - - - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + + 75 + true + + + + Dimensions, mm: + + + @@ -172,7 +188,7 @@ - + @@ -199,19 +215,6 @@ - - - - - 0 - 0 - - - - mm - - - @@ -235,19 +238,6 @@ - - - - - 0 - 0 - - - - mm - - - @@ -271,19 +261,6 @@ - - - - - 0 - 0 - - - - mm - - - @@ -304,7 +281,7 @@ - + @@ -327,7 +304,7 @@ If material with this name does not exist, this limitation is not applied. - + Qt::Horizontal @@ -357,7 +334,7 @@ If material with this name does not exist, this limitation is not applied. - Position of the source center: + Position of the source center, mm: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -369,7 +346,7 @@ If material with this name does not exist, this limitation is not applied. - + @@ -396,7 +373,7 @@ If material with this name does not exist, this limitation is not applied. - mm Y: + Y: @@ -416,7 +393,7 @@ If material with this name does not exist, this limitation is not applied. - mm Z: + Z: @@ -433,13 +410,6 @@ If material with this name does not exist, this limitation is not applied. - - - - mm - - - @@ -464,7 +434,7 @@ If material with this name does not exist, this limitation is not applied. - Source orientation: + Source orientation, degrees: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -476,7 +446,7 @@ If material with this name does not exist, this limitation is not applied. - + @@ -503,13 +473,6 @@ If material with this name does not exist, this limitation is not applied. - - - - deg - - - @@ -533,17 +496,10 @@ If material with this name does not exist, this limitation is not applied. - - - - deg - - - - around Z: + Around Z: Qt::AlignCenter @@ -563,13 +519,6 @@ If material with this name does not exist, this limitation is not applied. - - - - deg - - - @@ -594,7 +543,7 @@ If material with this name does not exist, this limitation is not applied. - Collimation direction: + Collimation direction and cone, degrees: @@ -603,7 +552,7 @@ If material with this name does not exist, this limitation is not applied. - + @@ -630,13 +579,6 @@ If material with this name does not exist, this limitation is not applied. - - - - deg - - - @@ -660,17 +602,10 @@ If material with this name does not exist, this limitation is not applied. - - - - deg - - - - Collimation cone: + Cone: @@ -690,13 +625,6 @@ If material with this name does not exist, this limitation is not applied. - - - - deg - - - @@ -721,7 +649,7 @@ If material with this name does not exist, this limitation is not applied. - Particle composition: + Particle composition: @@ -781,7 +709,7 @@ If material with this name does not exist, this limitation is not applied. - 250 + 200 16777215 @@ -793,7 +721,7 @@ If material with this name does not exist, this limitation is not applied. - 1 + 3 3 @@ -812,10 +740,17 @@ If material with this name does not exist, this limitation is not applied. 0 + + + + Particle: + + + - + 0 0 @@ -828,12 +763,19 @@ If material with this name does not exist, this limitation is not applied. - 120 + 16777215 16777215 + + + + + + 0 + @@ -843,7 +785,7 @@ If material with this name does not exist, this limitation is not applied. - Stat weight: + Statistical weight: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -854,7 +796,7 @@ If material with this name does not exist, this limitation is not applied. - 50 + 16777215 16777215 @@ -866,109 +808,145 @@ If material with this name does not exist, this limitation is not applied. - - - - - Fixed energy - - - true - - - + + + Energy: + + + + + + + 3 + + + 0 + - - - - 75 - 16777215 - - - - 100 + + + + 0 + 0 + - - - - - - - MeV - - - - - keV - - - eV + Fixed - meV + Distribution - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - Energy spectrum - - - - - - - false - - - - 45 - 0 - - - - Show - - - - - - - - 45 - 0 - + + + 0 - - Format: two columns, first is the energy in keV, second is the probability + + 0 - - Load - - + + + + 1 + + + + + + 75 + 16777215 + + + + 100 + + + + + + + + MeV + + + + + keV + + + + + eV + + + + + meV + + + + + + + + + + 1 + + + + + false + + + + 35 + 0 + + + + Show + + + + + + + + 35 + 0 + + + + Format: two columns, first is the energy in keV, second is the probability + + + Load + + + + + + + + 18 + 16777215 + + + + X + + + + + + @@ -1017,7 +995,7 @@ If material with this name does not exist, this limitation is not applied. - Linked to particle #: + Linked to particle # Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -1025,30 +1003,7 @@ If material with this name does not exist, this limitation is not applied. - - - - 50 - 16777215 - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - + @@ -1057,7 +1012,7 @@ If material with this name does not exist, this limitation is not applied. - with probability: + With probability: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -1068,7 +1023,7 @@ If material with this name does not exist, this limitation is not applied. - 50 + 16777215 16777215 @@ -1077,28 +1032,15 @@ If material with this name does not exist, this limitation is not applied. - - - - Opposite - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - + + + + Generated in opposite direction + + + @@ -1147,6 +1089,9 @@ If material with this name does not exist, this limitation is not applied.fLinkedParticle verticalSpacer frSecondary + horizontalLayoutWidget + label_11 + horizontalLayoutWidget_2 @@ -1161,33 +1106,30 @@ If material with this name does not exist, this limitation is not applied. - - - - 200 - 0 - - - - Show source - - - true + + + Qt::Vertical - + - Qt::Vertical + Qt::Horizontal - + + + 40 + 20 + + + - 200 + 150 0 @@ -1209,6 +1151,19 @@ If material with this name does not exist, this limitation is not applied. + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -1326,8 +1281,8 @@ If material with this name does not exist, this limitation is not applied.click() - 228 - 72 + 285 + 52 455 @@ -1358,12 +1313,12 @@ If material with this name does not exist, this limitation is not applied.click() - 262 - 97 + 243 + 98 - 417 - 130 + 494 + 128 @@ -1374,8 +1329,8 @@ If material with this name does not exist, this limitation is not applied.click() - 388 - 93 + 359 + 98 426 @@ -1390,8 +1345,8 @@ If material with this name does not exist, this limitation is not applied.click() - 99 - 126 + 117 + 125 440 @@ -1406,8 +1361,8 @@ If material with this name does not exist, this limitation is not applied.click() - 355 - 127 + 361 + 126 440 @@ -1438,8 +1393,8 @@ If material with this name does not exist, this limitation is not applied.click() - 212 - 176 + 205 + 173 439 @@ -1454,12 +1409,12 @@ If material with this name does not exist, this limitation is not applied.click() - 322 - 171 + 302 + 173 - 491 - 131 + 494 + 128 @@ -1486,8 +1441,8 @@ If material with this name does not exist, this limitation is not applied.click() - 242 - 215 + 235 + 218 421 @@ -1502,8 +1457,8 @@ If material with this name does not exist, this limitation is not applied.click() - 412 - 211 + 370 + 218 421 @@ -1534,12 +1489,12 @@ If material with this name does not exist, this limitation is not applied.click() - 190 - 265 + 235 + 263 - 429 - 131 + 494 + 128 @@ -1550,8 +1505,8 @@ If material with this name does not exist, this limitation is not applied.click() - 402 - 258 + 351 + 263 416 @@ -1559,22 +1514,6 @@ If material with this name does not exist, this limitation is not applied. - - ledGunParticleWeight - editingFinished() - pbUpdateRecord - click() - - - 470 - 304 - - - 465 - 124 - - - cobGunParticle activated(int) @@ -1582,12 +1521,12 @@ If material with this name does not exist, this limitation is not applied.click() - 342 - 305 + 490 + 312 - 443 - 129 + 494 + 128 @@ -1598,8 +1537,8 @@ If material with this name does not exist, this limitation is not applied.click() - 386 - 328 + 438 + 380 454 @@ -1608,50 +1547,50 @@ If material with this name does not exist, this limitation is not applied. - cbLinkedParticle + cbLinkingOpposite clicked() pbUpdateRecord click() - 310 - 381 + 491 + 504 - 445 - 122 + 466 + 121 - ledLinkingProbability - editingFinished() + cobEnergy + activated(int) pbUpdateRecord click() - 373 - 427 + 326 + 379 - 441 - 128 + 426 + 116 - cbLinkingOpposite - clicked() + ledGunParticleWeight + editingFinished() pbUpdateRecord click() - 441 - 426 + 490 + 337 - 466 - 121 + 465 + 124 diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 68d5327f..275821a2 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9669,7 +9669,7 @@ double events: - 3 + 0 diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index edec04db..63483031 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -228,9 +228,10 @@ QVector* ParticleSourcesClass::GenerateEvent() GeneratedParticleStructure ps; ps.ParticleId = ParticleSourcesData[isource]->GunParticles[thisParticle]->ParticleId; - if (ParticleSourcesData[isource]->GunParticles[thisParticle]->spectrum == 0) - ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->energy; - else ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->spectrum->GetRandom(); + //if (ParticleSourcesData[isource]->GunParticles[thisParticle]->spectrum == 0) + // ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->energy; + //else ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->spectrum->GetRandom(); + ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->generateEnergy(); ps.Direction[0] = -GeneratedParticles->at(index).Direction[0]; ps.Direction[1] = -GeneratedParticles->at(index).Direction[1]; ps.Direction[2] = -GeneratedParticles->at(index).Direction[2]; @@ -379,9 +380,10 @@ void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector ps.ParticleId = ParticleSourcesData[isource]->GunParticles[iparticle]->ParticleId; //energy - if (ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum == 0) - ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->energy; - else ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum->GetRandom(); + //if (ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum == 0) + // ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->energy; + //else ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum->GetRandom(); + ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->generateEnergy(); //generating random direction inside the collimation cone double spread = ParticleSourcesData[isource]->Spread*3.1415926535/180.0; //max angle away from generation diretion double cosTheta = cos(spread); @@ -505,21 +507,18 @@ bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) jGunParticle["StatWeight"] = s->GunParticles[ip]->StatWeight; bool individual = s->GunParticles[ip]->Individual; jGunParticle["Individual"] = individual; - //if (!individual) - // { jGunParticle["LinkedTo"] = s->GunParticles[ip]->LinkedTo; jGunParticle["LinkingProbability"] = s->GunParticles[ip]->LinkingProbability; jGunParticle["LinkingOppositeDir"] = s->GunParticles[ip]->LinkingOppositeDir; - // } - if ( s->GunParticles[ip]->spectrum == 0 ) - jGunParticle["Energy"] = s->GunParticles[ip]->energy; - else - { + jGunParticle["Energy"] = s->GunParticles[ip]->energy; + jGunParticle["UseFixedEnergy"] = s->GunParticles[ip]->bUseFixedEnergy; + if ( s->GunParticles[ip]->spectrum ) + { //saving spectrum QJsonArray ja; writeTH1DtoJsonArr(s->GunParticles[ip]->spectrum, ja); jGunParticle["EnergySpectrum"] = ja; - } + } jGunParticle["PreferredUnits"] = s->GunParticles[ip]->PreferredUnits; jParticleEntries.append(jGunParticle); } @@ -628,6 +627,7 @@ bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) parseJson(jThisGunPart, "Energy", s->GunParticles[ip]->energy ); parseJson(jThisGunPart, "PreferredUnits", s->GunParticles[ip]->PreferredUnits ); + parseJson(jThisGunPart, "UseFixedEnergy", s->GunParticles[ip]->bUseFixedEnergy ); QJsonArray ar = jThisGunPart["EnergySpectrum"].toArray(); if (!ar.isEmpty()) @@ -724,7 +724,8 @@ bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QSt int error = LoadDoubleVectorsFromFile(fileName, &x, &y); if (error>0) return false; - if (ParticleSourcesData[iSource]->GunParticles[iParticle]->spectrum) delete ParticleSourcesData[iSource]->GunParticles[iParticle]->spectrum; + if (ParticleSourcesData[iSource]->GunParticles[iParticle]->spectrum) + delete ParticleSourcesData[iSource]->GunParticles[iParticle]->spectrum; int size = x.size(); double* xx = new double [size]; for (int i = 0; iGetRandom(); +} + +bool GunParticleStruct::loadSpectrum(const QString &fileName) +{ + QVector x, y; + int error = LoadDoubleVectorsFromFile(fileName, &x, &y); + if (error > 0) return false; + + delete spectrum; spectrum = 0; + int size = x.size(); + //double* xx = new double[size]; + //for (int i = 0; iSetBinContent(j, y[j-1]); + return true; +} + GunParticleStruct::~GunParticleStruct() { if (spectrum) delete spectrum; diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 8abdedab..82a0b5ed 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -17,6 +17,7 @@ struct GunParticleStruct { int ParticleId = 0; double StatWeight = 1.0; + bool bUseFixedEnergy = true; double energy = 100.0; //in keV QString PreferredUnits = "keV"; bool Individual = true; // true = individual particle; false = linked @@ -24,10 +25,13 @@ struct GunParticleStruct double LinkingProbability = 0; //probability to be emitted after the parent particle bool LinkingOppositeDir = false; // false = random direction; otherwise particle is emitted in the opposite direction in respect to the LinkedTo particle - TH1D* spectrum = 0; //energy spectrum + TH1D* spectrum = 0; //energy spectrum GunParticleStruct * clone() const; + double generateEnergy() const; + bool loadSpectrum(const QString& fileName); + ~GunParticleStruct(); }; From 3617a47e6f705041ede438307c8b2e5e54e7711e Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 00:41:54 +0100 Subject: [PATCH 076/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 8 +- .../MainWindowParticleSimulation.cpp | 590 +----- .../MainWindowTools/MainWindowParticles.cpp | 2 +- .../MainWindowTools/aparticlesourcedialog.cpp | 20 + .../MainWindowTools/aparticlesourcedialog.h | 3 + src/gui/MainWindowTools/mainwindowjson.cpp | 6 - src/gui/mainwindow.cpp | 26 - src/gui/mainwindow.h | 23 +- src/gui/mainwindow.ui | 1644 +---------------- src/modules/particlesourcesclass.cpp | 9 + src/modules/particlesourcesclass.h | 1 + 11 files changed, 148 insertions(+), 2184 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 02c31656..949c07fc 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -241,16 +241,16 @@ MainWindow::MainWindow(DetectorClass *Detector, invis << ui->pbRefreshParticles << ui->pbRefreshOverrides << ui->pbUpdatePreprocessingSettings << ui->pbRefreshStack << ui->pbShowPMsArrayRegularData << ui->pbRefreshPMArrayData << ui->pbUpdateElectronics << ui->pbRefreshPMproperties << ui->pbUpdatePMproperties << ui->pbRefreshMaterials << ui->pbStopLoad - << ui->pbGunRefreshparticles << ui->pbIndPMshowInfo << ui->pbUpdateToFixedZ << ui->pbUpdateSimConfig + << ui->pbIndPMshowInfo << ui->pbUpdateToFixedZ << ui->pbUpdateSimConfig << ui->pbUpdateToFullCustom << ui->pbElUpdateIndication << ui->pbUnlockGui << ui->pbInitializeScanFloodNoise << ui->pbUpdateScanFloodTabWidget << ui->fScanFloodTotProb - << ui->fSecondaryScintLoadProfile << ui->pbUpdateSources << ui->pbUpdateSourcesIndication - << ui->fLinkedParticle << ui->sbPMtype << ui->fUpperLowerArrays << ui->sbPMtypeForGroup + << ui->fSecondaryScintLoadProfile << ui->pbUpdateSourcesIndication + << ui->sbPMtype << ui->fUpperLowerArrays << ui->sbPMtypeForGroup << ui->pbRebuildDetector << ui->fReloadRequired << ui->pbYellow << ui->pbGDML << ui->fGunMultipleEvents; for (int i=0;isetVisible(false); ui->frLimitNodesTo->setVisible( ui->twSingleScan->currentIndex()!=0 ); QList disables; - disables << ui->fGunParticle << ui->fFixedDir << ui->fFixedWorldSize; + disables << ui->fFixedDir << ui->fFixedWorldSize; for (int i=0;isetEnabled(false); ui->fWaveOptions->setEnabled(ui->cbWaveResolved->isChecked()); ui->fWaveTests->setEnabled(ui->cbWaveResolved->isChecked()); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index cc99941b..bc978ae2 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -18,6 +18,7 @@ #include "amessage.h" #include "acommonfunctions.h" #include "guiutils.h" +#include "aparticlesourcedialog.h" //Qt #include @@ -251,9 +252,10 @@ void MainWindow::on_pbGunTest_clicked() { if (iRun>2) { - if (ui->cbSourceLimitmat->isChecked()) message("Did several attempts but no particles were generated!\n" - "Possible reason: generation is limited to a wrong material", this); - else message("Did several attempts but no particles were generated!", this); +// if (ui->cbSourceLimitmat->isChecked()) message("Did several attempts but no particles were generated!\n" +// "Possible reason: generation is limited to a wrong material", this); +// else + message("Did several attempts but no particles were generated!", this); return; } } @@ -285,388 +287,6 @@ void MainWindow::on_pbGunTest_clicked() ParticleSources->getSource(i)->Activity = activities.at(i); } -void MainWindow::on_pbGunRefreshparticles_clicked() -{ - ui->lwGunParticles->clear(); //Cleaning ListView - - if (ParticleSources->size() == 0) return; - int isource = ui->cobParticleSource->currentIndex(); - if (isource > ParticleSources->size()-1) return; //protection - - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - - //Populating ListView - int DefinedSourceParticles = ps->GunParticles.size(); - //qDebug() << "Defined particles for this source:"<< DefinedSourceParticles; - - for (int i=0; iGunParticles[i]; - - bool Individual = gps->Individual; - - QString str, str1; - if (Individual) str = ""; - else str = ">"; - str1.setNum(i); - str += str1 + "> "; - //str += Detector->ParticleCollection[gps->ParticleId]->ParticleName; - str += Detector->MpCollection->getParticleName(gps->ParticleId); - if (gps->spectrum) str += " E=spec"; - else - { - str1.setNum(gps->energy); - str += " E=" + str1; - } - - if (Individual) - { - str += " W="; - str1.setNum(gps->StatWeight); - str += str1; - } - else - { - str += " Link:"; - str += QString::number(gps->LinkedTo); - str += " P="; - str += QString::number(gps->LinkingProbability); - if (gps->LinkingOppositeDir) - str += " Opposite"; - } - ui->lwGunParticles->addItem(str); - //qDebug() << str; - } - MainWindow::SourceUpdateThisParticleIndication(); -} - -void MainWindow::SourceUpdateThisParticleIndication() -{ - //showing selected row and updating data indication - int isource = ui->cobParticleSource->currentIndex(); - if (isource<0 || isource>=ParticleSources->size()) return; - int row = ui->lwGunParticles->currentRow(); - - const AParticleSourceRecord* ps = ParticleSources->getSource(isource); - - int DefinedSourceParticles = ps->GunParticles.size(); - if (DefinedSourceParticles > 0 && row>-1) - { - ui->fGunParticle->setEnabled(true); - int part = ps->GunParticles[row]->ParticleId; - ui->cobGunParticle->setCurrentIndex(part); - - GunParticleStruct* gps = ps->GunParticles[row]; - - QString str; - str.setNum(gps->StatWeight); - ui->ledGunParticleWeight->setText(str); - str.setNum(gps->energy); - ui->ledGunEnergy->setText(str); - ui->cbIndividualParticle->setChecked(gps->Individual); - ui->leiParticleLinkedTo->setText( QString::number(gps->LinkedTo) ); - str.setNum(gps->LinkingProbability); - ui->ledLinkingProbability->setText(str); - ui->cbLinkingOpposite->setChecked(gps->LinkingOppositeDir); - //Depending on the presence of spectrum data, modifing visiblility and enable/disable - if (gps->spectrum == 0) - { - ui->pbGunShowSpectrum->setEnabled(false); - ui->pbGunDeleteSpectrum->setEnabled(false); - ui->ledGunEnergy->setEnabled(true); - ui->fPartEnergy->setVisible(true); - } - else - { - ui->pbGunShowSpectrum->setEnabled(true); - ui->pbGunDeleteSpectrum->setEnabled(true); - ui->ledGunEnergy->setEnabled(false); - ui->fPartEnergy->setVisible(false); - } - } - else ui->fGunParticle->setEnabled(false); -} - -void MainWindow::on_pbGunAddNew_clicked() -{ - int isource = ui->cobParticleSource->currentIndex(); - - GunParticleStruct* tmp = new GunParticleStruct(); - tmp->ParticleId = ui->cobGunParticle->currentIndex(); - tmp->StatWeight = ui->ledGunParticleWeight->text().toDouble(); - tmp->energy = ui->ledGunEnergy->text().toDouble(); - tmp->spectrum = 0; - ParticleSources->getSource(isource)->GunParticles.append(tmp); - - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow( ParticleSources->getSource(isource)->GunParticles.size()-1 ); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_pbGunRemove_clicked() -{ - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - if (ps->GunParticles.size() < 2) - { - message("Source should contain at least one particle!"); - return; - } - - int iparticle = ui->lwGunParticles->currentRow(); - if (iparticle == -1) - { - message("Select a particle to remove!", this); - return; - } - delete ps->GunParticles[iparticle]; - ps->GunParticles.remove(iparticle); - MainWindow::on_pbGunRefreshparticles_clicked(); - int errCode = ParticleSources->CheckSource(isource); - if (errCode>0) - { - QString err = ParticleSources->getErrorString(errCode); - message("Source checker reports an error: "+err, this); - } - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_cobGunSourceType_currentIndexChanged(int index) -{ - QList s; - switch (index) - { - default: - case 0: s <<""<<""<<""; - break; - case 1: s <<"Length:"<<""<<""; - break; - case 2: s <<"Size X:"<<"Size Y:"<<""; - break; - case 3: s <<"Diameter:"<<""<<""; - break; - case 4: s <<"Size X:"<<"Size Y:"<<"Size Z:"; - break; - case 5: s <<"Diameter:"<<""<<"Height:"; - } - ui->lGun1DSize->setText(s[0]); - ui->lGun2DSize->setText(s[1]); - ui->lGun3DSize->setText(s[2]); - ui->fGun1D->setDisabled(s[0].isEmpty()); - ui->fGun2D->setDisabled(s[1].isEmpty()); - ui->fGun3D->setDisabled(s[2].isEmpty()); - - ui->fGunPhi->setEnabled(index != 0); - ui->fGunTheta->setEnabled(index != 0); - ui->fGunPsi->setEnabled(index > 1); - - if (index == 1) - { - ui->labGunPhi->setText("Phi"); - ui->labGunTheta->setText("Theta"); - } - else - { - ui->labGunPhi->setText("around X"); - ui->labGunTheta->setText("around Y"); - } -} - -void MainWindow::on_cobGunParticle_activated(int index) -{ - //next 4 obsolete? - if (ParticleSources->size() == 0) return; - int isource = ui->cobParticleSource->currentIndex(); - if (isource > ParticleSources->size() - 1) return; - - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - if (ps->GunParticles.isEmpty()) return; - - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - ps->GunParticles[particle]->ParticleId = index; - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_ledGunEnergy_editingFinished() -{ - //if (BulkUpdate) return; - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - - ps->GunParticles[particle]->energy = ui->ledGunEnergy->text().toDouble(); - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_ledGunParticleWeight_editingFinished() -{ - //if (BulkUpdate) return; - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - ps->GunParticles[particle]->StatWeight = ui->ledGunParticleWeight->text().toDouble(); - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_cbIndividualParticle_clicked(bool checked) -{ - //if (BulkUpdate) return; - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - - if (particle == 0 && !checked) - { - ui->cbIndividualParticle->setChecked(true); - message("First particle should be 'Individual'", this); - return;//update on_toggle - } - ps->GunParticles[particle]->Individual = checked; - if (!checked) ps->GunParticles[particle]->LinkedTo = ui->leiParticleLinkedTo->text().toInt(); - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_leiParticleLinkedTo_editingFinished() -{ - //if (BulkUpdate) return; - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - int iLinkedTo = ui->leiParticleLinkedTo->text().toInt(); - if (iLinkedTo == particle) - { - ui->leiParticleLinkedTo->setText("0"); - message("Particle cannot be linked to itself!", this); - MainWindow::on_leiParticleLinkedTo_editingFinished(); - return; - } - - int TotParticles = ps->GunParticles.size(); - if (iLinkedTo>TotParticles-1 || iLinkedTo<0) - { - if (iLinkedTo == 0) return; //protection - no particles are defined - ui->leiParticleLinkedTo->setText("0"); - message("Particle index is out of range: "+QString::number(TotParticles)+" particle are defined", this); - MainWindow::on_leiParticleLinkedTo_editingFinished(); - return; - } - - ps->GunParticles[particle]->LinkedTo = iLinkedTo; - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_ledLinkingProbability_editingFinished() -{ - double val = ui->ledLinkingProbability->text().toDouble(); - if (val<0 || val>1) - { - ui->ledLinkingProbability->setText("0"); - message("Error in probability value: should be between 0 and 1",this); - val = 0; - } - - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - ps->GunParticles[particle]->LinkingProbability = val; - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_cbLinkingOpposite_clicked(bool checked) -{ - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - int linkedTo = ui->leiParticleLinkedTo->text().toInt(); - if (linkedTo<0 || linkedTo > ps->GunParticles.size()-1) return; - if (linkedTo == particle) - { - ps->GunParticles[particle]->LinkingOppositeDir = false; - message("Cannot link particle to itself", this); - } - - ps->GunParticles[particle]->LinkingOppositeDir = checked; - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -void MainWindow::on_pbGunLoadSpectrum_clicked() -{ - QString fileName; - fileName = QFileDialog::getOpenFileName(this, "Load energy spectrum", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); - qDebug()<cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - ParticleSources->LoadGunEnergySpectrum(isource, particle, fileName); - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - -#include "TH1.h" -void MainWindow::on_pbGunShowSpectrum_clicked() -{ - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - ps->GunParticles[particle]->spectrum->GetXaxis()->SetTitle("Energy, keV"); - GraphWindow->Draw(ps->GunParticles[particle]->spectrum, "", true, false); -} - -void MainWindow::on_pbGunDeleteSpectrum_clicked() -{ - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - int particle = ui->lwGunParticles->currentRow(); - if (particle<0 || particle > ps->GunParticles.size()-1) return; - if (ps->GunParticles[particle]->spectrum) - { - delete ps->GunParticles[particle]->spectrum; - ps->GunParticles[particle]->spectrum = 0; - } - ui->pbGunShowSpectrum->setEnabled(false); - ui->pbGunDeleteSpectrum->setEnabled(false); - MainWindow::on_pbGunRefreshparticles_clicked(); - ui->lwGunParticles->setCurrentRow(particle); - - MainWindow::on_pbUpdateSources_clicked(); -} - void MainWindow::on_ledGunAverageNumPartperEvent_editingFinished() { double val = ui->ledGunAverageNumPartperEvent->text().toDouble(); @@ -691,7 +311,6 @@ void MainWindow::on_pbRemoveSource_clicked() ParticleSources->remove(isource); ui->cobParticleSource->removeItem(isource); ui->cobParticleSource->setCurrentIndex(isource-1); - if (ParticleSources->size() == 0) clearParticleSourcesIndication(); on_pbUpdateSimConfig_clicked(); @@ -711,95 +330,12 @@ void MainWindow::on_pbRemoveSource_clicked() void MainWindow::on_pbAddSource_clicked() { AParticleSourceRecord* s = new AParticleSourceRecord(); + s->GunParticles << new GunParticleStruct(); ParticleSources->append(s); ui->cobParticleSource->addItem(ParticleSources->getLastSource()->name); ui->cobParticleSource->setCurrentIndex(ParticleSources->size()-1); - ui->ledGunParticleWeight->setText("1"); - ui->cbIndividualParticle->setChecked(true); - on_pbGunAddNew_clicked(); //to add new particle and register the changes in config - on_pbUpdateSourcesIndication_clicked(); - if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); -} - -void MainWindow::on_pbUpdateSources_clicked() -{ - int isource = ui->cobParticleSource->currentIndex(); - if (isource<0) - { - //qWarning() << "Attempt to update source with number <0"; - return; - } - - if (BulkUpdate) return; - if (DoNotUpdateGeometry) return; - if (ShutDown) return; - if (ParticleSources->size() == 0) - { - qWarning()<<"Attempt to update particle source while there are no defined ones!"; - return; - } - - //qDebug()<<"Update source#"<size(); - - if (isource >= ParticleSources->size()) - { - message("Error: Attempting to update particle source parameters, but source number is out of bounds!",this); - return; - } - - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - - ps->Activity = ui->ledSourceActivity->text().toDouble(); - ps->index = ui->cobGunSourceType->currentIndex(); - ps->X0 = ui->ledGunOriginX->text().toDouble(); - ps->Y0 = ui->ledGunOriginY->text().toDouble(); - ps->Z0 = ui->ledGunOriginZ->text().toDouble(); - ps->Phi = ui->ledGunPhi->text().toDouble(); - ps->Theta = ui->ledGunTheta->text().toDouble(); - ps->Psi = ui->ledGunPsi->text().toDouble(); - ps->size1 = 0.5 * ui->ledGun1DSize->text().toDouble(); - ps->size2 = 0.5 * ui->ledGun2DSize->text().toDouble(); - ps->size3 = 0.5 * ui->ledGun3DSize->text().toDouble(); - ps->CollPhi = ui->ledGunCollPhi->text().toDouble(); - ps->CollTheta = ui->ledGunCollTheta->text().toDouble(); - ps->Spread = ui->ledGunSpread->text().toDouble(); - ps->DoMaterialLimited = ui->cbSourceLimitmat->isChecked(); - ps->LimtedToMatName = ui->leSourceLimitMaterial->text(); - ParticleSources->checkLimitedToMaterial(ps); - - if (Detector->isGDMLempty()) - { //check world size - double XYm = 0; - double Zm = 0; - for (int isource = 0; isource < ParticleSources->size(); isource++) - { - double msize = ps->size1; - UpdateMax(msize, ps->size2); - UpdateMax(msize, ps->size3); - - UpdateMax(XYm, fabs(ps->X0)+msize); - UpdateMax(XYm, fabs(ps->Y0)+msize); - UpdateMax(Zm, fabs(ps->Z0)+msize); - } - - double currXYm = Detector->WorldSizeXY; - double currZm = Detector->WorldSizeZ; - if (XYm>currXYm || Zm>currZm) - { - //need to override - Detector->fWorldSizeFixed = true; - Detector->WorldSizeXY = std::max(XYm,currXYm); - Detector->WorldSizeZ = std::max(Zm,currZm); - MainWindow::ReconstructDetector(); - } - } - - on_pbUpdateSimConfig_clicked(); - - updateActivityIndication(); //update marker! - if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); - //qDebug() << "...update sources done"; + on_pbEditParticleSource_clicked(); } void MainWindow::on_pbUpdateSourcesIndication_clicked() @@ -809,7 +345,6 @@ void MainWindow::on_pbUpdateSourcesIndication_clicked() int numSources = ParticleSources->size(); ui->labPartSourcesDefined->setText(QString::number(numSources)); - clearParticleSourcesIndication(); if (numSources == 0) return; ui->fParticleSources->setEnabled(true); ui->frSelectSource->setEnabled(true); @@ -820,9 +355,6 @@ void MainWindow::on_pbUpdateSourcesIndication_clicked() if (isource == -1) isource = 0; ui->cobParticleSource->setCurrentIndex(isource); - updateOneParticleSourcesIndication(ParticleSources->getSource(isource)); - on_pbGunRefreshparticles_clicked(); - on_leSourceLimitMaterial_textChanged(""); //update color only! updateActivityIndication(); } @@ -840,42 +372,6 @@ void MainWindow::updateActivityIndication() ui->labOfTotal->setText(QString::number(fraction, 'g', 3)+"%"); } -void MainWindow::updateOneParticleSourcesIndication(AParticleSourceRecord* ps) -{ - bool BulkUpdateCopy = BulkUpdate; //it could be set outside to true already, do not want to reselt to false on exit - BulkUpdate = true; - - ui->ledSourceActivity->setText(QString::number(ps->Activity)); - ui->cobGunSourceType->setCurrentIndex(ps->index); - ui->ledGunOriginX->setText(QString::number(ps->X0)); - ui->ledGunOriginY->setText(QString::number(ps->Y0)); - ui->ledGunOriginZ->setText(QString::number(ps->Z0)); - ui->ledGunPhi->setText(QString::number(ps->Phi)); - ui->ledGunTheta->setText(QString::number(ps->Theta)); - ui->ledGunPsi->setText(QString::number(ps->Psi)); - ui->ledGun1DSize->setText(QString::number(2.0 * ps->size1)); - ui->ledGun2DSize->setText(QString::number(2.0 * ps->size2)); - ui->ledGun3DSize->setText(QString::number(2.0 * ps->size3)); - ui->ledGunCollPhi->setText(QString::number(ps->CollPhi)); - ui->ledGunCollTheta->setText(QString::number(ps->CollTheta)); - ui->ledGunSpread->setText(QString::number(ps->Spread)); - - ui->cbSourceLimitmat->setChecked(ps->DoMaterialLimited); - ui->leSourceLimitMaterial->setText(ps->LimtedToMatName); - - BulkUpdate = BulkUpdateCopy; -} - -void MainWindow::clearParticleSourcesIndication() -{ - AParticleSourceRecord ps; - updateOneParticleSourcesIndication(&ps); - ui->cobParticleSource->clear(); - ui->cobParticleSource->setCurrentIndex(-1); - ui->fParticleSources->setEnabled(false); - ui->frSelectSource->setEnabled(false); -} - void MainWindow::on_pbGunShowSource_toggled(bool checked) { if (checked) @@ -902,11 +398,6 @@ void MainWindow::ShowParticleSource_noFocus() ShowSource(ParticleSources->getSource(isource), true); } -void MainWindow::on_lwGunParticles_currentRowChanged(int /*currentRow*/) -{ - MainWindow::SourceUpdateThisParticleIndication(); -} - void MainWindow::on_pbSaveParticleSource_clicked() { QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; @@ -989,25 +480,6 @@ void MainWindow::on_pbSingleSourceShow_clicked() GeometryWindow->ShowGeometry(false); } -void MainWindow::on_pbRenameSource_clicked() -{ - int isource = ui->cobParticleSource->currentIndex(); - //qDebug() << "current source:"<ParticleSources->size()-1) return; - - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - bool ok; - QString text = QInputDialog::getText(this, "Rename particle source", - "New name:", QLineEdit::Normal, - ps->name, &ok); - if (ok && !text.isEmpty()) - { - ps->name = text; - ui->cobParticleSource->setItemText(isource, text); - MainWindow::on_pbUpdateSources_clicked(); - } -} - void MainWindow::on_pbAddParticleToStack_clicked() { //check is this particle's energy in the defined range? @@ -1156,3 +628,51 @@ void MainWindow::on_pbClearAllStack_clicked() ParticleStack.clear(); MainWindow::on_pbRefreshStack_clicked(); } + +void MainWindow::on_pbEditParticleSource_clicked() +{ + int isource = ui->cobParticleSource->currentIndex(); + AParticleSourceDialog d(*this, ParticleSources->getSource(isource)); + int res = d.exec(); + + if (res == QDialog::Rejected) return; + ParticleSources->replace(isource, d.getResult()); + + AParticleSourceRecord* ps = ParticleSources->getSource(isource); + + ps->Activity = ui->ledSourceActivity->text().toDouble(); + ParticleSources->checkLimitedToMaterial(ps); + + if (Detector->isGDMLempty()) + { //check world size + double XYm = 0; + double Zm = 0; + for (int isource = 0; isource < ParticleSources->size(); isource++) + { + double msize = ps->size1; + UpdateMax(msize, ps->size2); + UpdateMax(msize, ps->size3); + + UpdateMax(XYm, fabs(ps->X0)+msize); + UpdateMax(XYm, fabs(ps->Y0)+msize); + UpdateMax(Zm, fabs(ps->Z0)+msize); + } + + double currXYm = Detector->WorldSizeXY; + double currZm = Detector->WorldSizeZ; + if (XYm>currXYm || Zm>currZm) + { + //need to override + Detector->fWorldSizeFixed = true; + Detector->WorldSizeXY = std::max(XYm,currXYm); + Detector->WorldSizeZ = std::max(Zm,currZm); + MainWindow::ReconstructDetector(); + } + } + + on_pbUpdateSimConfig_clicked(); + + updateActivityIndication(); //update marker! + if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); + //qDebug() << "...update sources done"; +} diff --git a/src/gui/MainWindowTools/MainWindowParticles.cpp b/src/gui/MainWindowTools/MainWindowParticles.cpp index 70eafdda..0a262606 100644 --- a/src/gui/MainWindowTools/MainWindowParticles.cpp +++ b/src/gui/MainWindowTools/MainWindowParticles.cpp @@ -79,7 +79,7 @@ void updateParticleCOB(QComboBox* cob, DetectorClass* Detector) void MainWindow::on_pbRefreshParticles_clicked() { QList< QComboBox* > cobs; - cobs << ui->cobParticleToInspect << ui->cobParticleToStack << ui->cobGunParticle; + cobs << ui->cobParticleToInspect << ui->cobParticleToStack; foreach (QComboBox* cob, cobs) updateParticleCOB(cob, Detector); diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.cpp b/src/gui/MainWindowTools/aparticlesourcedialog.cpp index 6d84a3cc..894e953f 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.cpp +++ b/src/gui/MainWindowTools/aparticlesourcedialog.cpp @@ -58,6 +58,7 @@ AParticleSourceDialog::AParticleSourceDialog(MainWindow & MW, const AParticleSou ui->frSecondary->setVisible(false); UpdateListWidget(); + updateColorLimitingMat(); if ( !Rec->GunParticles.isEmpty() ) { ui->lwGunParticles->setCurrentRow(0); @@ -357,6 +358,7 @@ void AParticleSourceDialog::on_pbUpdateRecord_clicked() curRow = 0; ui->lwGunParticles->setCurrentRow(curRow); UpdateParticleInfo(); + updateColorLimitingMat(); if (ui->pbShowSource->isChecked()) MW.ShowSource(Rec, true); } @@ -427,3 +429,21 @@ void AParticleSourceDialog::on_pbDeleteSpectrum_clicked() UpdateParticleInfo(); } + +void AParticleSourceDialog::updateColorLimitingMat() +{ + if (!ui->cbSourceLimitmat->isChecked()) return; + + const QString name = ui->leSourceLimitMaterial->text(); + bool fFound = false; + for (int iMat=0; iMat < MW.MpCollection->countMaterials(); iMat++) + if (name == (*MW.MpCollection)[iMat]->name) + { + fFound = true; + break; + } + + QPalette palette = ui->leSourceLimitMaterial->palette(); + palette.setColor(QPalette::Text, (fFound ? Qt::black : Qt::red) ); + ui->leSourceLimitMaterial->setPalette(palette); +} diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.h b/src/gui/MainWindowTools/aparticlesourcedialog.h index d8a7d761..4506cfea 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.h +++ b/src/gui/MainWindowTools/aparticlesourcedialog.h @@ -43,6 +43,8 @@ private slots: void on_pbDeleteSpectrum_clicked(); + + private: MainWindow& MW; @@ -55,6 +57,7 @@ private slots: private: void UpdateListWidget(); void UpdateParticleInfo(); + void updateColorLimitingMat(); }; #endif // APARTICLESOURCEDIALOG_H diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 243157b2..49c8fe09 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -581,15 +581,9 @@ if (scj.contains("CustomDistrib")) JsonToCheckbox(csjs, "IgnoreNoDepoEvents", ui->cbIgnoreEventsWithNoEnergyDepo); //particle sources - int SelectedSource = ui->cobParticleSource->currentIndex(); ParticleSources->clear(); ParticleSources->readFromJson(psjs); on_pbUpdateSourcesIndication_clicked(); - if (SelectedSource>-1 && SelectedSourcesize()) - { - ui->cobParticleSource->setCurrentIndex(SelectedSource); - updateOneParticleSourcesIndication(ParticleSources->getSource(SelectedSource)); - } //Window CONTROL if (js.contains("Mode")) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 45b854d3..2daa11ff 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4605,24 +4605,6 @@ void MainWindow::on_tabMCcrosstalk_cellChanged(int row, int column) on_pbUpdateElectronics_clicked(); } -void MainWindow::on_leSourceLimitMaterial_textChanged(const QString &/*arg1*/) -{ - if (!ui->cbSourceLimitmat->isChecked()) return; - - const QString name = ui->leSourceLimitMaterial->text(); - bool fFound = false; - for (int iMat=0; iMatcountMaterials(); iMat++) - if (name == (*MpCollection)[iMat]->name) - { - fFound = true; - break; - } - - QPalette palette = ui->leSourceLimitMaterial->palette(); - palette.setColor(QPalette::Text, (fFound ? Qt::black : Qt::red) ); - ui->leSourceLimitMaterial->setPalette(palette); -} - void MainWindow::on_leLimitNodesObject_textChanged(const QString &/*arg1*/) { bool fFound = (ui->cbLimitNodesOutsideObject->isChecked()) ? @@ -4993,11 +4975,3 @@ void MainWindow::on_pbPMtypeHelp_clicked() " represent the photocathode."; message(s, this); } - -#include "aparticlesourcedialog.h" -void MainWindow::on_pushButton_2_clicked() -{ - int isource = ui->cobParticleSource->currentIndex(); - AParticleSourceDialog d(*this, ParticleSources->getSource(isource)); - d.exec(); -} diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index bf0c193b..01cdb7b1 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -282,17 +282,7 @@ private slots: void on_pbPMtypeShowAngular_clicked(); void on_pbPMtypeDeleteAngular_clicked(); void on_pbPMtypeShowEffectiveAngular_clicked(); - void on_cobGunSourceType_currentIndexChanged(int index); void on_pbGunTest_clicked(); - void on_pbGunRefreshparticles_clicked(); - void on_pbGunAddNew_clicked(); - void on_pbGunRemove_clicked(); - void on_cobGunParticle_activated(int index); - void on_ledGunEnergy_editingFinished(); - void on_ledGunParticleWeight_editingFinished(); - void on_pbGunLoadSpectrum_clicked(); - void on_pbGunShowSpectrum_clicked(); - void on_pbGunDeleteSpectrum_clicked(); void on_ledGunAverageNumPartperEvent_editingFinished(); void on_ledMediumRefrIndex_editingFinished(); void on_pbPMtypeLoadArea_clicked(); @@ -369,7 +359,6 @@ private slots: void LoadSimTreeRequested(); void on_pbRemoveSource_clicked(); void on_pbAddSource_clicked(); - void on_pbUpdateSources_clicked(); void on_pbUpdateSourcesIndication_clicked(); void on_pbGunShowSource_toggled(bool checked); @@ -462,8 +451,6 @@ private slots: private slots: void timerTimeout(); //timer-based update of Root events - void on_cbIndividualParticle_clicked(bool checked); - void on_ledLinkingProbability_editingFinished(); void on_pbShowCheckUpWindow_clicked(); void on_lePreprocessingMultiply_editingFinished(); void on_extractPedestals_clicked(); @@ -485,7 +472,6 @@ private slots: void on_actionSave_configuration_triggered(); void on_actionLoad_configuration_triggered(); void on_pbRemoveParticle_clicked(); - void on_lwGunParticles_currentRowChanged(int currentRow); void on_pbSaveParticleSource_clicked(); void on_pbLoadParticleSource_clicked(); void on_pbSaveResults_clicked(); @@ -493,7 +479,6 @@ private slots: void on_lwLoadedEventsFiles_itemChanged(QListWidgetItem *item); void on_pobTest_clicked(); void on_actionGain_evaluation_triggered(); - void on_leiParticleLinkedTo_editingFinished(); void on_cbLRFs_toggled(bool checked); void on_pbClearAdd_clicked(); void on_pbClearMulti_clicked(); @@ -507,11 +492,9 @@ private slots: void on_cobTOP_activated(int index); void on_actionNew_detector_triggered(); void on_pbReloadTreeData_clicked(); - void on_pbRenameSource_clicked(); void on_pbStopLoad_clicked(); void on_pbConfigureNumberOfThreads_clicked(); void on_cobFixedDirOrCone_currentIndexChanged(int index); - void on_cbLinkingOpposite_clicked(bool checked); void on_pbShowComptonAngles_clicked(); void on_pbShowComptonEnergies_clicked(); void on_pbCheckRandomGen_clicked(); @@ -562,7 +545,6 @@ private slots: void on_cbEnableMCcrosstalk_toggled(bool checked); void on_pbRemoveCellMCcrosstalk_clicked(); void on_pbMCnormalize_clicked(); - void on_leSourceLimitMaterial_textChanged(const QString &arg1); void on_leLimitNodesObject_textChanged(const QString &arg1); void on_cbLimitNodesOutsideObject_toggled(bool checked); void on_bpResults_clicked(); @@ -612,7 +594,7 @@ private slots: void on_pbPMtypeHelp_clicked(); - void on_pushButton_2_clicked(); + void on_pbEditParticleSource_clicked(); public slots: void on_pbRebuildDetector_clicked(); @@ -628,10 +610,7 @@ public slots: private: void initDetectorSandwich(); - void SourceUpdateThisParticleIndication(); void onGuiEnableStatus(bool fLocked); - void clearParticleSourcesIndication(); - void updateOneParticleSourcesIndication(AParticleSourceRecord *ps); void ShowParticleSource_noFocus(); void updateActivityIndication(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 275821a2..f2b1b529 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9638,1248 +9638,23 @@ double events: - 5 - 68 - 523 - 201 - - - - QFrame::Box - - - QFrame::Plain - - - - true - - - - 10 - 37 - 507 - 162 - - - - - 50 - false - - - - 0 - - - - Particles - - - - - 10 - 2 - 101 - 16 - - - - Particle composition: - - - - - - 143 - 108 - 101 - 23 - - - - Remove particle - - - - - - 4 - 108 - 131 - 23 - - - - - 75 - true - - - - Add new particle - - - - - - 20 - 30 - 151 - 21 - - - - ...refresh GunPart indication - - - - - - 3 - 20 - 241 - 85 - - - - QAbstractItemView::SelectRows - - - QListView::ListMode - - - - - - 247 - 3 - 252 - 130 - - - - QFrame::Box - - - QFrame::Raised - - - - false - - - - 221 - 53 - 21 - 23 - - - - X - - - - - - 9 - 6 - 121 - 22 - - - - - - - 165 - 53 - 51 - 23 - - - - Format: two columns, first is the energy in keV, second is the probability - - - Load - - - - - false - - - - 109 - 53 - 51 - 23 - - - - Show - - - - - - 10 - 84 - 81 - 16 - - - - Individual - - - true - - - - - - 20 - 81 - 231 - 48 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 13 - 23 - 83 - 20 - - - - with probability: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 100 - 24 - 50 - 20 - - - - 1 - - - - - - 74 - 3 - 96 - 17 - - - - Linked to particle: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 173 - 2 - 50 - 20 - - - - 0 - - - - - - 158 - 26 - 70 - 17 - - - - Opposite - - - label_152 - label_153 - ledLinkingProbability - leiParticleLinkedTo - cbLinkingOpposite - - - - - 131 - 5 - 119 - 25 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 72 - 2 - 41 - 20 - - - - 1 - - - - - - 5 - 3 - 64 - 16 - - - - Stat weight: - - - - - - - 15 - 56 - 91 - 16 - - - - Energy spectrum: - - - - - - 5 - 30 - 221 - 23 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 174 - 2 - 31 - 16 - - - - - 75 - true - - - - - or - - - - - - - 1 - 4 - 46 - 13 - - - - Energy: - - - - - - 47 - 1 - 80 - 20 - - - - 1000 - - - - - - 131 - 0 - 31 - 21 - - - - keV - - - - pbGunDeleteSpectrum - pbGunLoadSpectrum - cbIndividualParticle - fLinkedParticle - pbGunShowSpectrum - fStatWeight - cobGunParticle - label_205 - fPartEnergy - - lwGunParticles - label_161 - pbGunRemove - pbGunAddNew - pbGunRefreshparticles - fGunParticle - - - - Shape and size - - - - - 60 - 40 - 123 - 23 - - - - - 75 - true - - - - - Point - - - - - Linear - - - - - Surface: square - - - - - Surface: round - - - - - Volume: box - - - - - Volume: cylinder - - - - - - - 43 - 11 - 151 - 20 - - - - - 75 - true - - - - Geometry: - - - Qt::AlignCenter - - - - - - 325 - 10 - 101 - 16 - - - - - 75 - true - - - - Size: - - - Qt::AlignCenter - - - - - - 267 - 65 - 164 - 31 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 134 - 9 - 26 - 13 - - - - mm - - - - - - 89 - 6 - 41 - 20 - - - - 10 - - - - - - 6 - 9 - 77 - 13 - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 267 - 35 - 164 - 31 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 134 - 9 - 26 - 13 - - - - mm - - - - - - 89 - 5 - 41 - 20 - - - - 10 - - - - - - 6 - 8 - 77 - 13 - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 267 - 95 - 164 - 31 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 134 - 9 - 26 - 13 - - - - mm - - - - - - 89 - 6 - 41 - 20 - - - - 10 - - - - - - 6 - 10 - 77 - 13 - - - - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - 30 - 86 - 230 - 17 - - - - Limit generation to specific material - - - - - true - - - - 26 - 109 - 191 - 20 - - - - Particle will be generated only if the point sampled inside the source is located within an object with the indicated material. -If material with this name does not exist, this limitation is not applied. - - - - - - Position and orientation - - - - - 123 - 8 - 250 - 20 - - - - - 75 - true - - - - Position of the source center, mm: - - - Qt::AlignCenter - - - - - - 300 - 37 - 41 - 20 - - - - 0 - - - - - - 220 - 37 - 41 - 20 - - - - 0 - - - - - - 140 - 37 - 41 - 20 - - - - 0 - - - - - - 120 - 37 - 16 - 16 - - - - X: - - - - - - 200 - 37 - 16 - 16 - - - - Y: - - - - - - 280 - 37 - 16 - 16 - - - - Z: - - - - - - 123 - 66 - 250 - 20 - - - - - 75 - true - - - - Source orientation, degrees: - - - Qt::AlignCenter - - - - - - 215 - 88 - 61 - 41 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 50 - 10 - 16 - 16 - - - - o - - - - - - 1 - 0 - 51 - 16 - - - - Theta: - - - Qt::AlignCenter - - - - - - 6 - 16 - 41 - 20 - - - - 0 - - - - - - - 130 - 88 - 61 - 40 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 53 - 9 - 16 - 16 - - - - o - - - - - - 10 - 16 - 41 - 20 - - - - 0 - - - - - - 6 - 0 - 51 - 16 - - - - Phi: - - - Qt::AlignCenter - - - - - - - 295 - 88 - 61 - 41 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 50 - 10 - 16 - 16 - - - - o - - - - - - 6 - 16 - 41 - 20 - - - - 0 - - - - - - -6 - -2 - 71 - 20 - - - - around Z: - - - Qt::AlignCenter - - - - - - - Collimation - - - - - 140 - 20 - 170 - 16 - - - - - 75 - true - - - - Collimation direction: - - - - - - 210 - 100 - 16 - 16 - - - - o - - - - - - 114 - 51 - 41 - 20 - - - - 0 - - - - - - 267 - 44 - 16 - 16 - - - - o - - - - - - 132 - 86 - 170 - 16 - - - - - 75 - true - - - - Collimation cone (+-): - - - - - - 72 - 53 - 38 - 16 - - - - Phi: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 158 - 44 - 16 - 16 - - - - o - - - - - - 166 - 107 - 41 - 20 - - - - 45 - - - - - - 178 - 52 - 42 - 16 - - - - Theta: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 224 - 51 - 41 - 20 - - - - 0 - - - - - - 390 - 80 - 81 - 20 - - - - 1 - - - 1000000 - - - 100 - - - - - - 380 - 50 - 101 - 24 - - - - Test generator - - - - - - 350 - 20 - 16 - 111 - - - - Qt::Vertical - - - - + 27 + 68 + 441 + 101 + + + + QFrame::Box + + + QFrame::Plain + - 398 - 6 + 60 + 70 61 23 @@ -10897,8 +9672,8 @@ If material with this name does not exist, this limitation is not applied. - 457 - 6 + 130 + 70 61 23 @@ -10986,49 +9761,62 @@ If material with this name does not exist, this limitation is not applied.of total activity - + - 420 - 31 - 101 - 23 + 15 + 8 + 21 + 16 - - - 50 - false - - - ...update Sources + -- - + - 15 - 8 - 21 - 16 + 70 + 40 + 131 + 23 + + + + Edit source + + + + + + 350 + 50 + 81 + 20 - - -- + + 1 + + + 1000000 + + + 100 - + - 330 - 10 - 75 - 23 + 250 + 50 + 101 + 24 - PushButton + Test generator @@ -11269,25 +10057,6 @@ If material with this name does not exist, this limitation is not applied.false - - - - 212 - 7 - 71 - 23 - - - - - 50 - false - - - - Rename - - @@ -11351,7 +10120,6 @@ If material with this name does not exist, this limitation is not applied.line_2 pbRemoveSource cobParticleSource - pbRenameSource pbGunShowSource label_150 @@ -14612,230 +13380,6 @@ on stack - - ledGunOriginX - editingFinished() - pbUpdateSources - click() - - - 203 - 382 - - - 449 - 298 - - - - - ledGunOriginY - editingFinished() - pbUpdateSources - click() - - - 283 - 382 - - - 449 - 298 - - - - - ledGunOriginZ - editingFinished() - pbUpdateSources - click() - - - 363 - 382 - - - 449 - 298 - - - - - ledGun1DSize - editingFinished() - pbUpdateSources - click() - - - 419 - 385 - - - 449 - 298 - - - - - ledGun2DSize - editingFinished() - pbUpdateSources - click() - - - 419 - 416 - - - 449 - 298 - - - - - ledGun3DSize - editingFinished() - pbUpdateSources - click() - - - 419 - 446 - - - 449 - 298 - - - - - ledGunPhi - editingFinished() - pbUpdateSources - click() - - - 203 - 449 - - - 449 - 298 - - - - - ledGunTheta - editingFinished() - pbUpdateSources - click() - - - 284 - 449 - - - 449 - 298 - - - - - ledGunPsi - editingFinished() - pbUpdateSources - click() - - - 364 - 449 - - - 449 - 298 - - - - - ledGunCollPhi - editingFinished() - pbUpdateSources - click() - - - 177 - 396 - - - 449 - 298 - - - - - ledGunCollTheta - editingFinished() - pbUpdateSources - click() - - - 287 - 396 - - - 449 - 298 - - - - - ledGunSpread - editingFinished() - pbUpdateSources - click() - - - 229 - 452 - - - 449 - 298 - - - - - ledSourceActivity - editingFinished() - pbUpdateSources - click() - - - 210 - 293 - - - 449 - 298 - - - - - cbIndividualParticle - toggled(bool) - fLinkedParticle - setHidden(bool) - - - 360 - 428 - - - 513 - 413 - - - cbLoadedDataHasEnergy toggled(bool) @@ -14884,22 +13428,6 @@ on stack - - cbIndividualParticle - toggled(bool) - fStatWeight - setVisible(bool) - - - 360 - 428 - - - 504 - 336 - - - cbIgnoreEvent toggled(bool) @@ -15124,22 +13652,6 @@ on stack - - cobGunSourceType - activated(int) - pbUpdateSources - click() - - - 203 - 366 - - - 442 - 298 - - - sbPMrings editingFinished() @@ -17204,54 +15716,6 @@ on stack - - cbSourceLimitmat - clicked() - pbUpdateSources - click() - - - 214 - 428 - - - 495 - 298 - - - - - cbSourceLimitmat - toggled(bool) - leSourceLimitMaterial - setVisible(bool) - - - 192 - 428 - - - 185 - 454 - - - - - leSourceLimitMaterial - editingFinished() - pbUpdateSources - click() - - - 239 - 454 - - - 480 - 298 - - - ledNumElPerUnitaryLRF editingFinished() diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 63483031..1b587ef6 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -811,6 +811,15 @@ void ParticleSourcesClass::append(AParticleSourceRecord *gunParticle) CalculateTotalActivity(); } +bool ParticleSourcesClass::replace(int iSource, AParticleSourceRecord *gunParticle) +{ + if (iSource < 0 || iSource >= ParticleSourcesData.size()) return false; + + delete ParticleSourcesData[iSource]; + ParticleSourcesData[iSource] = gunParticle; + return true; +} + void ParticleSourcesClass::remove(int iSource) { if (ParticleSourcesData.isEmpty()) return; diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 82a0b5ed..6d512de0 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -117,6 +117,7 @@ class ParticleSourcesClass : public QObject //Source handling - after handling is finished, requires Init() !!! void append(AParticleSourceRecord* gunParticle); + bool replace(int iSource, AParticleSourceRecord* gunParticle); void remove(int iSource); void clear(); From 420427480bf44cef67e84b51637173b13ae28c8c Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 00:46:53 +0100 Subject: [PATCH 077/140] ++ --- src/gui/MainWindowTools/MainWindowParticleSimulation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index bc978ae2..415fcd80 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -340,9 +340,11 @@ void MainWindow::on_pbAddSource_clicked() void MainWindow::on_pbUpdateSourcesIndication_clicked() { - //qDebug() << "Update sources inidcation. Defined sources:"<size(); + qDebug() << "Update sources indication. Defined sources:"<size(); int isource = ui->cobParticleSource->currentIndex(); + ui->cobParticleSource->clear(); + int numSources = ParticleSources->size(); ui->labPartSourcesDefined->setText(QString::number(numSources)); if (numSources == 0) return; From b5c9b989844d02d264b664511e7669e022381c38 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 10:51:54 +0100 Subject: [PATCH 078/140] aparticlesourcerecord in separate file, moved there json operations --- src/ants2.pro | 6 +- src/common/aparticlesourcerecord.cpp | 249 ++++++++++++++++++ src/common/aparticlesourcerecord.h | 85 ++++++ .../MainWindowParticleSimulation.cpp | 3 +- .../MainWindowTools/aparticlesourcedialog.cpp | 11 + .../MainWindowTools/aparticlesourcedialog.h | 5 - src/gui/MainWindowTools/mainwindowjson.cpp | 1 + src/gui/checkupwindowclass.cpp | 1 + src/gui/mainwindow.cpp | 1 + src/modules/particlesourcesclass.cpp | 222 +--------------- src/modules/particlesourcesclass.h | 67 +---- 11 files changed, 358 insertions(+), 293 deletions(-) create mode 100644 src/common/aparticlesourcerecord.cpp create mode 100644 src/common/aparticlesourcerecord.h diff --git a/src/ants2.pro b/src/ants2.pro index 84db9093..70d2bdf1 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -356,7 +356,8 @@ SOURCES += main.cpp \ OpticalOverrides/awaveshifteroverride.cpp \ OpticalOverrides/spectralbasicopticaloverride.cpp \ OpticalOverrides/abasicopticaloverride.cpp \ - common/aglobalsettings.cpp + common/aglobalsettings.cpp \ + common/aparticlesourcerecord.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -488,7 +489,8 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/awaveshifteroverride.h \ OpticalOverrides/spectralbasicopticaloverride.h \ OpticalOverrides/abasicopticaloverride.h \ - common/aglobalsettings.h + common/aglobalsettings.h \ + common/aparticlesourcerecord.h # --- SIM --- ants2_SIM { diff --git a/src/common/aparticlesourcerecord.cpp b/src/common/aparticlesourcerecord.cpp new file mode 100644 index 00000000..40bef8fe --- /dev/null +++ b/src/common/aparticlesourcerecord.cpp @@ -0,0 +1,249 @@ +#include "aparticlesourcerecord.h" +#include "amaterialparticlecolection.h" +#include "afiletools.h" +#include "ajsontools.h" +#include "aparticle.h" //--- + +#include +#include +#include + +#include "TH1D.h" + +GunParticleStruct * GunParticleStruct::clone() const +{ + //shallow copy + GunParticleStruct* gp = new GunParticleStruct(*this); + + //clear dynamic + gp->spectrum = 0; + + //deep copy for dynamic properties + if (spectrum) + gp->spectrum = new TH1D(*spectrum); + + return gp; +} + +double GunParticleStruct::generateEnergy() const +{ + if (bUseFixedEnergy || !spectrum) + return energy; + return spectrum->GetRandom(); +} + +bool GunParticleStruct::loadSpectrum(const QString &fileName) +{ + QVector x, y; + int error = LoadDoubleVectorsFromFile(fileName, &x, &y); + if (error > 0) return false; + + delete spectrum; spectrum = 0; + int size = x.size(); + //double* xx = new double[size]; + //for (int i = 0; iSetBinContent(j, y[j-1]); + return true; +} + +void GunParticleStruct::writeToJson(QJsonObject &json, const AMaterialParticleCollection &MpCollection) const +{ + const AParticle* p = MpCollection.getParticle(ParticleId); // TODO matColl -> partToJson + QJsonObject jparticle; + jparticle["name"] = p->ParticleName; + jparticle["type"] = p->type; + jparticle["charge"] = p->charge; + jparticle["mass"] = p->mass; + json["Particle"] = jparticle; + + json["StatWeight"] = StatWeight; + json["Individual"] = Individual; + json["LinkedTo"] = LinkedTo; + json["LinkingProbability"] = LinkingProbability; + json["LinkingOppositeDir"] = LinkingOppositeDir; + json["Energy"] = energy; + json["UseFixedEnergy"] = bUseFixedEnergy; + if ( spectrum ) + { + QJsonArray ja; + writeTH1DtoJsonArr(spectrum, ja); + json["EnergySpectrum"] = ja; + } + json["PreferredUnits"] = PreferredUnits; +} + +bool GunParticleStruct::readFromJson(const QJsonObject &json, AMaterialParticleCollection & MpCollection) +{ + QJsonObject jparticle = json["Particle"].toObject(); + if (jparticle.isEmpty()) + { + qWarning()<<"Particle data not given in the particle source file"; + return false; + } + QString name = jparticle["name"].toString(); + int type = jparticle["type"].toInt(); + int charge = jparticle["charge"].toInt(); + double mass = jparticle["mass"].toDouble(); + //looking for this particle in the collection and create if necessary + AParticle::ParticleType Type = static_cast(type); + ParticleId = MpCollection.FindCreateParticle(name, Type, charge, mass); + //qDebug()<<"Added gun particle with particle Id"<at(ParticleId)->ParticleName; + + parseJson(json, "StatWeight", StatWeight ); + parseJson(json, "Individual", Individual ); + parseJson(json, "LinkedTo", LinkedTo ); //linked always to previously already defined particles! + parseJson(json, "LinkingProbability", LinkingProbability ); + parseJson(json, "LinkingOppositeDir", LinkingOppositeDir ); + + parseJson(json, "Energy", energy ); + parseJson(json, "PreferredUnits", PreferredUnits ); + parseJson(json, "UseFixedEnergy", bUseFixedEnergy ); + + QJsonArray ar = json["EnergySpectrum"].toArray(); + if (!ar.isEmpty()) + { + int size = ar.size(); + double* xx = new double [size]; + double* yy = new double [size]; + for (int i=0; iSetBinContent(j, yy[j-1]); + delete[] xx; + delete[] yy; + } + return true; +} + +GunParticleStruct::~GunParticleStruct() +{ + if (spectrum) delete spectrum; +} + +// ---------------------- AParticleSourceRecord ---------------------- + +AParticleSourceRecord::~AParticleSourceRecord() +{ + clearGunParticles(); +} + +void AParticleSourceRecord::clearGunParticles() +{ + for (GunParticleStruct* g : GunParticles) delete g; + GunParticles.clear(); +} + +AParticleSourceRecord * AParticleSourceRecord::clone() const +{ + //shallow copy + AParticleSourceRecord * newRec = new AParticleSourceRecord(*this); + + //clear dynamic + newRec->GunParticles.clear(); + + //deep copy of dynamic resources + for (GunParticleStruct* g : GunParticles) + newRec->GunParticles << g->clone(); + + return newRec; +} + +void AParticleSourceRecord::writeToJson(QJsonObject & json, const AMaterialParticleCollection & MpCollection) const +{ + json["Name"] = name; + json["Type"] = index; + json["Activity"] = Activity; + json["X"] = X0; + json["Y"] = Y0; + json["Z"] = Z0; + json["Size1"] = size1; + json["Size2"] = size2; + json["Size3"] = size3; + json["Phi"] = Phi; + json["Theta"] = Theta; + json["Psi"] = Psi; + json["CollPhi"] = CollPhi; + json["CollTheta"] = CollTheta; + json["Spread"] = Spread; + + json["DoMaterialLimited"] = DoMaterialLimited; + json["LimitedToMaterial"] = LimtedToMatName; + + //particles + int GunParticleSize = GunParticles.size(); + json["Particles"] = GunParticleSize; + QJsonArray jParticleEntries; + for (const GunParticleStruct* gp : GunParticles) + { + QJsonObject js; + gp->writeToJson(js, MpCollection); + jParticleEntries.append(js); + } + json["GunParticles"] = jParticleEntries; +} + +bool AParticleSourceRecord::readFromJson(const QJsonObject &json, AMaterialParticleCollection &MpCollection) +{ + parseJson(json, "Name", name); + parseJson(json, "Type", index); + parseJson(json, "Activity", Activity); + parseJson(json, "X", X0); + parseJson(json, "Y", Y0); + parseJson(json, "Z", Z0); + parseJson(json, "Size1", size1); + parseJson(json, "Size2", size2); + parseJson(json, "Size3", size3); + parseJson(json, "Phi", Phi); + parseJson(json, "Theta", Theta); + parseJson(json, "Psi", Psi); + parseJson(json, "CollPhi", CollPhi); + parseJson(json, "CollTheta", CollTheta); + parseJson(json, "Spread", Spread); + + DoMaterialLimited = fLimit = false; + LimtedToMatName = ""; + if (json.contains("DoMaterialLimited")) + { + parseJson(json, "DoMaterialLimited", DoMaterialLimited); + parseJson(json, "LimitedToMaterial", LimtedToMatName); + + if (DoMaterialLimited) + { + bool fFound = false; + int iMat; + for (iMat = 0; iMat < MpCollection.countMaterials(); iMat++) //TODO make a method in MpCol + if (LimtedToMatName == MpCollection[iMat]->name) + { + fFound = true; + break; + } + + if (fFound) //only in this case limit to material will be used! + { + fLimit = true; + LimitedToMat = iMat; + } + } + } + + //GunParticles + clearGunParticles(); + QJsonArray jGunPartArr = json["GunParticles"].toArray(); + int numGP = jGunPartArr.size(); + //qDebug()<<"Entries in gunparticles:"<readFromJson(jThisGunPart, MpCollection); + if (!bOK) return false; + GunParticles << gp; + } + return true; +} diff --git a/src/common/aparticlesourcerecord.h b/src/common/aparticlesourcerecord.h new file mode 100644 index 00000000..358be67c --- /dev/null +++ b/src/common/aparticlesourcerecord.h @@ -0,0 +1,85 @@ +#ifndef APARTICLESOURCERECORD_H +#define APARTICLESOURCERECORD_H + +#include +#include + +class TH1D; +class QJsonObject; +class AMaterialParticleCollection; + +struct GunParticleStruct +{ + ~GunParticleStruct(); //deletes spectrum + + int ParticleId = 0; + double StatWeight = 1.0; + bool bUseFixedEnergy = true; + double energy = 100.0; //in keV + QString PreferredUnits = "keV"; + bool Individual = true; // true = individual particle; false = linked + int LinkedTo = 0; // index of the "parent" particle this one is following + double LinkingProbability = 0; //probability to be emitted after the parent particle + bool LinkingOppositeDir = false; // false = random direction; otherwise particle is emitted in the opposite direction in respect to the LinkedTo particle + + TH1D* spectrum = 0; //energy spectrum + + GunParticleStruct * clone() const; + + double generateEnergy() const; + bool loadSpectrum(const QString& fileName); + + void writeToJson(QJsonObject & json, const AMaterialParticleCollection & MpCollection) const; + bool readFromJson(const QJsonObject & json, AMaterialParticleCollection & MpCollection); + +}; + +struct AParticleSourceRecord +{ + ~AParticleSourceRecord(); //deletes records in dynamic GunParticles + + QString name = "Underfined"; + //source type (geometry) + int index = 0; //shape + //position + double X0 = 0; + double Y0 = 0; + double Z0 = 0; + //orientation + double Phi = 0; + double Theta = 0; + double Psi = 0; + //size + double size1 = 10.0; + double size2 = 10.0; + double size3 = 10.0; + //collimation + double CollPhi = 0; + double CollTheta = 0; + double Spread = 45.0; + + //limit to material + bool DoMaterialLimited = false; + QString LimtedToMatName; + + //Relative activity + double Activity = 1.0; + + //particles + QVector GunParticles; + + AParticleSourceRecord * clone() const; + + void writeToJson(QJsonObject & json, const AMaterialParticleCollection & MpCollection) const; + bool readFromJson(const QJsonObject & json, AMaterialParticleCollection & MpCollection); + + //local variables, used in tracking, calculated autonatically, not to be loaded/saved! + int LimitedToMat; //automatically calculated if LimtedToMatName matches a material + bool fLimit = false; + +private: + void clearGunParticles(); +}; + + +#endif // APARTICLESOURCERECORD_H diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 415fcd80..d409c62b 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -1,6 +1,7 @@ //ANTS2 #include "mainwindow.h" #include "ui_mainwindow.h" +#include "aparticlesourcerecord.h" #include "outputwindow.h" #include "apmhub.h" #include "eventsdataclass.h" @@ -440,7 +441,6 @@ void MainWindow::on_pbLoadParticleSource_clicked() message("Json file format error", this); return; } - //int oldPartCollSize = Detector->ParticleCollection.size(); int oldPartCollSize = Detector->MpCollection->countParticles(); js = json["ParticleSource"].toObject(); ParticleSources->readSourceFromJson(iSource, js); @@ -457,7 +457,6 @@ void MainWindow::on_pbLoadParticleSource_clicked() else str += " was"; str += " added:\n"; for (int i=oldPartCollSize; iParticleCollection[i]->ParticleName + "\n"; str += Detector->MpCollection->getParticleName(i) + "\n"; str += "\nSet the interaction data for the detector materials!"; message(str,this); diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.cpp b/src/gui/MainWindowTools/aparticlesourcedialog.cpp index 894e953f..862aa173 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.cpp +++ b/src/gui/MainWindowTools/aparticlesourcedialog.cpp @@ -1,15 +1,20 @@ #include "aparticlesourcedialog.h" #include "ui_aparticlesourcedialog.h" #include "mainwindow.h" +#include "aparticlesourcerecord.h" #include "amaterialparticlecolection.h" #include "amessage.h" #include "geometrywindowclass.h" #include "graphwindowclass.h" #include "aglobalsettings.h" +#include "ajsontools.h" #include #include #include +//#include +//#include +//#include #include "TGeoManager.h" #include "TH1D.h" @@ -64,6 +69,12 @@ AParticleSourceDialog::AParticleSourceDialog(MainWindow & MW, const AParticleSou ui->lwGunParticles->setCurrentRow(0); UpdateParticleInfo(); } + +// QMenuBar* mb = new QMenuBar(this); +// QMenu* fileMenu = mb->addMenu("&File"); +// fileMenu->addAction("Load source", this, &AParticleSourceDialog::loadSource); +// fileMenu->addAction("Save source", this, &AParticleSourceDialog::saveSource); +// layout()->setMenuBar(mb); } AParticleSourceDialog::~AParticleSourceDialog() diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.h b/src/gui/MainWindowTools/aparticlesourcedialog.h index 4506cfea..b291d5c0 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.h +++ b/src/gui/MainWindowTools/aparticlesourcedialog.h @@ -36,15 +36,10 @@ private slots: void on_cbLinkedParticle_clicked(bool checked); void on_sbLinkedTo_editingFinished(); void on_ledLinkingProbability_editingFinished(); - void on_pbGunShowSpectrum_clicked(); - void on_pbGunLoadSpectrum_clicked(); - void on_pbDeleteSpectrum_clicked(); - - private: MainWindow& MW; diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 49c8fe09..b1eef914 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -1,4 +1,5 @@ #include "mainwindow.h" +#include "aparticlesourcerecord.h" #include "aglobalsettings.h" #include "ui_mainwindow.h" #include "detectorclass.h" diff --git a/src/gui/checkupwindowclass.cpp b/src/gui/checkupwindowclass.cpp index 8be9e57f..05dd5c78 100644 --- a/src/gui/checkupwindowclass.cpp +++ b/src/gui/checkupwindowclass.cpp @@ -9,6 +9,7 @@ #include "generalsimsettings.h" #include "particlesourcesclass.h" #include "aglobalsettings.h" +#include "aparticlesourcerecord.h" #include #include diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 2daa11ff..2cbf71f5 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -54,6 +54,7 @@ #include "ascriptwindow.h" #include "aremotewindow.h" #include "aopticaloverridedialog.h" +#include "aparticlesourcerecord.h" //--- //Qt #include diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 1b587ef6..4f4e1ea2 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -1,4 +1,5 @@ #include "particlesourcesclass.h" +#include "aparticlesourcerecord.h" #include "detectorclass.h" #include "jsonparser.h" #include "amaterialparticlecolection.h" @@ -18,8 +19,6 @@ #include "TRandom2.h" #include "TGeoManager.h" - - ParticleSourcesClass::ParticleSourcesClass(const DetectorClass *Detector, TRandom2 *RandGen, TString nameID) : Detector(Detector), MpCollection(Detector->MpCollection), RandGen(RandGen), NameID(nameID), TotalActivity(0) {} @@ -464,65 +463,7 @@ bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) if (iSource<0 || iSource>ParticleSourcesData.size()-1) return false; AParticleSourceRecord* s = ParticleSourcesData[iSource]; - - //general - json["Name"] = s->name; - json["Type"] = s->index; - json["Activity"] = s->Activity; - json["X"] = s->X0; - json["Y"] = s->Y0; - json["Z"] = s->Z0; - json["Size1"] = s->size1; - json["Size2"] = s->size2; - json["Size3"] = s->size3; - json["Phi"] = s->Phi; - json["Theta"] = s->Theta; - json["Psi"] = s->Psi; - json["CollPhi"] = s->CollPhi; - json["CollTheta"] = s->CollTheta; - json["Spread"] = s->Spread; - - json["DoMaterialLimited"] = s->DoMaterialLimited; - json["LimitedToMaterial"] = s->LimtedToMatName; - - //particles - int GunParticleSize = s->GunParticles.size(); - json["Particles"] = GunParticleSize; - - QJsonArray jParticleEntries; - for (int ip=0; ipGunParticles[ip]->ParticleId; - const AParticle* p = MpCollection->getParticle(ParticleId); - jparticle["name"] = p->ParticleName; - jparticle["type"] = p->type; - jparticle["charge"] = p->charge; - jparticle["mass"] = p->mass; - //adding to top level - jGunParticle["Particle"] = jparticle; - - jGunParticle["StatWeight"] = s->GunParticles[ip]->StatWeight; - bool individual = s->GunParticles[ip]->Individual; - jGunParticle["Individual"] = individual; - jGunParticle["LinkedTo"] = s->GunParticles[ip]->LinkedTo; - jGunParticle["LinkingProbability"] = s->GunParticles[ip]->LinkingProbability; - jGunParticle["LinkingOppositeDir"] = s->GunParticles[ip]->LinkingOppositeDir; - jGunParticle["Energy"] = s->GunParticles[ip]->energy; - jGunParticle["UseFixedEnergy"] = s->GunParticles[ip]->bUseFixedEnergy; - if ( s->GunParticles[ip]->spectrum ) - { - //saving spectrum - QJsonArray ja; - writeTH1DtoJsonArr(s->GunParticles[ip]->spectrum, ja); - jGunParticle["EnergySpectrum"] = ja; - } - jGunParticle["PreferredUnits"] = s->GunParticles[ip]->PreferredUnits; - jParticleEntries.append(jGunParticle); - } - json["GunParticles"] = jParticleEntries; + s->writeToJson(json, *MpCollection); return true; } @@ -557,102 +498,11 @@ bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) iSource = ParticleSourcesData.size()-1; } - delete ParticleSourcesData[iSource]; //have to delete here, or histograms might have not unique names + delete ParticleSourcesData[iSource]; AParticleSourceRecord* s = new AParticleSourceRecord(); ParticleSourcesData[iSource] = s; - //reading general info - parseJson(json, "Name", s->name); - //qDebug() << s->name; - parseJson(json, "Type", s->index); - parseJson(json, "Activity", s->Activity); - parseJson(json, "X", s->X0); - parseJson(json, "Y", s->Y0); - parseJson(json, "Z", s->Z0); - parseJson(json, "Size1", s->size1); - parseJson(json, "Size2", s->size2); - parseJson(json, "Size3", s->size3); - parseJson(json, "Phi", s->Phi); - parseJson(json, "Theta", s->Theta); - parseJson(json, "Psi", s->Psi); - parseJson(json, "CollPhi", s->CollPhi); - parseJson(json, "CollTheta", s->CollTheta); - parseJson(json, "Spread", s->Spread); - - s->DoMaterialLimited = s->fLimit = false; - s->LimtedToMatName = ""; - if (json.contains("DoMaterialLimited")) - { - parseJson(json, "DoMaterialLimited", s->DoMaterialLimited); - parseJson(json, "LimitedToMaterial", s->LimtedToMatName); - - if (s->DoMaterialLimited) checkLimitedToMaterial(s); - } - - //GunParticles - //int declPart; //declared number of particles - //parseJson(json, "Particles", declPart); //obsolete - QJsonArray jGunPartArr = json["GunParticles"].toArray(); - int numGP = jGunPartArr.size(); - //qDebug()<<"Entries in gunparticles:"<(type); - int ParticleId = MpCollection->FindCreateParticle(name, Type, charge, mass); - - s->GunParticles << new GunParticleStruct(); - s->GunParticles[ip]->ParticleId = ParticleId; - //qDebug()<<"Added gun particle with particle Id"<at(ParticleId)->ParticleName; - - //going through gunparticle general properties - parseJson(jThisGunPart, "StatWeight", s->GunParticles[ip]->StatWeight ); - parseJson(jThisGunPart, "Individual", s->GunParticles[ip]->Individual ); - parseJson(jThisGunPart, "LinkedTo", s->GunParticles[ip]->LinkedTo ); //linked always to previously already defined particles! - parseJson(jThisGunPart, "LinkingProbability", s->GunParticles[ip]->LinkingProbability ); - parseJson(jThisGunPart, "LinkingOppositeDir", s->GunParticles[ip]->LinkingOppositeDir ); - - parseJson(jThisGunPart, "Energy", s->GunParticles[ip]->energy ); - parseJson(jThisGunPart, "PreferredUnits", s->GunParticles[ip]->PreferredUnits ); - parseJson(jThisGunPart, "UseFixedEnergy", s->GunParticles[ip]->bUseFixedEnergy ); - - QJsonArray ar = jThisGunPart["EnergySpectrum"].toArray(); - if (!ar.isEmpty()) - { - int size = ar.size(); - double* xx = new double [size]; - double* yy = new double [size]; - for (int i=0; iGunParticles[ip]->spectrum = new TH1D(c_str,"Energy spectrum", size-1, xx); - for (int j = 1; jGunParticles[ip]->spectrum->SetBinContent(j, yy[j-1]); - delete[] xx; - delete[] yy; - } - // TO DO !!! *** add error if no energy or spectrum - } - return true; + return s->readFromJson(json, *MpCollection); } void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) @@ -829,67 +679,3 @@ void ParticleSourcesClass::remove(int iSource) ParticleSourcesData.remove(iSource); CalculateTotalActivity(); } - -GunParticleStruct * GunParticleStruct::clone() const -{ - //shallow copy - GunParticleStruct* gp = new GunParticleStruct(*this); - - //clear dynamic - gp->spectrum = 0; - - //deep copy for dynamic properties - if (spectrum) - gp->spectrum = new TH1D(*spectrum); - - return gp; -} - -double GunParticleStruct::generateEnergy() const -{ - if (bUseFixedEnergy || !spectrum) - return energy; - return spectrum->GetRandom(); -} - -bool GunParticleStruct::loadSpectrum(const QString &fileName) -{ - QVector x, y; - int error = LoadDoubleVectorsFromFile(fileName, &x, &y); - if (error > 0) return false; - - delete spectrum; spectrum = 0; - int size = x.size(); - //double* xx = new double[size]; - //for (int i = 0; iSetBinContent(j, y[j-1]); - return true; -} - -GunParticleStruct::~GunParticleStruct() -{ - if (spectrum) delete spectrum; -} - -AParticleSourceRecord::~AParticleSourceRecord() -{ - for (GunParticleStruct* g : GunParticles) delete g; - GunParticles.clear(); -} - -AParticleSourceRecord * AParticleSourceRecord::clone() const -{ - //shallow copy - AParticleSourceRecord * newRec = new AParticleSourceRecord(*this); - - //clear dynamic - newRec->GunParticles.clear(); - - //deep copy of dynamic resources - for (GunParticleStruct* g : GunParticles) - newRec->GunParticles << g->clone(); - - return newRec; -} diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 6d512de0..df39983d 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -6,76 +6,11 @@ #include #include "TVector3.h" -class AParticle; class AMaterialParticleCollection; class QJsonObject; -class TH1D; class TRandom2; class DetectorClass; - -struct GunParticleStruct -{ - int ParticleId = 0; - double StatWeight = 1.0; - bool bUseFixedEnergy = true; - double energy = 100.0; //in keV - QString PreferredUnits = "keV"; - bool Individual = true; // true = individual particle; false = linked - int LinkedTo = 0; // index of the "parent" particle this one is following - double LinkingProbability = 0; //probability to be emitted after the parent particle - bool LinkingOppositeDir = false; // false = random direction; otherwise particle is emitted in the opposite direction in respect to the LinkedTo particle - - TH1D* spectrum = 0; //energy spectrum - - GunParticleStruct * clone() const; - - double generateEnergy() const; - bool loadSpectrum(const QString& fileName); - - ~GunParticleStruct(); -}; - -struct AParticleSourceRecord -{ - //name - QString name = "Underfined"; - //source type (geometry) - int index = 0; //shape - //position - double X0 = 0; - double Y0 = 0; - double Z0 = 0; - //orientation - double Phi = 0; - double Theta = 0; - double Psi = 0; - //size - double size1 = 10.0; - double size2 = 10.0; - double size3 = 10.0; - //collimation - double CollPhi = 0; - double CollTheta = 0; - double Spread = 45.0; - - //limit to material - bool DoMaterialLimited = false; - QString LimtedToMatName; - - //Relative activity - double Activity = 1.0; - - //particles - QVector GunParticles; - - ~AParticleSourceRecord(); //deletes records in dynamic GunParticles - - AParticleSourceRecord * clone() const; - - //local variables, used in tracking, calculated autonatically, not to be loaded/saved! - int LimitedToMat; //automatically calculated if LimtedToMatName matches a material - bool fLimit = false; -}; +struct AParticleSourceRecord; class GeneratedParticleStructure { From 1b4e8a3a5bbbd02c00c406ced0005d7cdabb67c4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 11:54:24 +0100 Subject: [PATCH 079/140] ++ --- .../MainWindowParticleSimulation.cpp | 82 +++++++++---------- .../MainWindowTools/aparticlesourcedialog.cpp | 9 ++ src/gui/mainwindow.h | 2 + src/modules/particlesourcesclass.cpp | 36 ++++---- src/modules/particlesourcesclass.h | 29 ++++--- src/modules/simulationmanager.cpp | 4 +- 6 files changed, 88 insertions(+), 74 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index d409c62b..9c028da9 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -226,7 +226,6 @@ void MainWindow::ShowSource(const AParticleSourceRecord* p, bool clear) void MainWindow::on_pbGunTest_clicked() { - //MainWindow::on_pbGunShowSource_clicked(); MainWindow::on_pbGunShowSource_toggled(true); QVector activities; @@ -238,56 +237,51 @@ void MainWindow::on_pbGunTest_clicked() if (i==isource) ParticleSources->getSource(i)->Activity = 1.0; else ParticleSources->getSource(i)->Activity = 0; } - ParticleSources->Init(); - - double Length = std::max(Detector->WorldSizeXY, Detector->WorldSizeZ)*0.4; - double R[3], K[3]; - int numParticles = ui->sbGunTestEvents->value(); - bool bHaveSome = false; - for (int iRun=0; iRun* GP = ParticleSources->GenerateEvent(); - if (GP->size()>0) - bHaveSome = true; - else - { - if (iRun>2) - { -// if (ui->cbSourceLimitmat->isChecked()) message("Did several attempts but no particles were generated!\n" -// "Possible reason: generation is limited to a wrong material", this); -// else - message("Did several attempts but no particles were generated!", this); - return; - } - } - for (int iP = 0; iPsize(); iP++) - { - R[0] = (*GP)[iP].Position[0]; - R[1] = (*GP)[iP].Position[1]; - R[2] = (*GP)[iP].Position[2]; - K[0] = (*GP)[iP].Direction[0]; - K[1] = (*GP)[iP].Direction[1]; - K[2] = (*GP)[iP].Direction[2]; - - Int_t track_index = Detector->GeoManager->AddTrack(1,22); - TVirtualGeoTrack *track = Detector->GeoManager->GetTrack(track_index); - track->AddPoint(R[0], R[1], R[2], 0); - track->AddPoint(R[0]+K[0]*Length, R[1]+K[1]*Length, R[2]+K[2]*Length, 0); - track->SetLineWidth(1); - track->SetLineColor(1+(*GP)[iP].ParticleId); - } - //clear and delete QVector with generated event - GP->clear(); - delete GP; - } - MainWindow::ShowTracks(); + TestParticleGun(ParticleSources, ui->sbGunTestEvents->value()); //restore activities of the sources for (int i=0; isize(); i++) ParticleSources->getSource(i)->Activity = activities.at(i); } +void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numParticles) +{ + ParticleSources->Init(); + + double Length = std::max(Detector->WorldSizeXY, Detector->WorldSizeZ)*0.4; + double R[3], K[3]; + for (int iRun=0; iRun* GP = ParticleSources->GenerateEvent(); + if (GP->isEmpty() && iRun > 2) + { + message("Did several attempts but no particles were generated!", this); + return; + } + for (GeneratedParticleStructure& p : *GP) + { + R[0] = p.Position[0]; + R[1] = p.Position[1]; + R[2] = p.Position[2]; + + K[0] = p.Direction[0]; + K[1] = p.Direction[1]; + K[2] = p.Direction[2]; + + Int_t track_index = Detector->GeoManager->AddTrack(1,22); + TVirtualGeoTrack *track = Detector->GeoManager->GetTrack(track_index); + track->AddPoint(R[0], R[1], R[2], 0); + track->AddPoint(R[0] + K[0]*Length, R[1] + K[1]*Length, R[2] + K[2]*Length, 0); + track->SetLineWidth(1); //TODO respect all attributes! + track->SetLineColor(1 + p.ParticleId); //TODO respect particle track colors! + } + GP->clear(); + delete GP; + } + ShowTracks(); +} + void MainWindow::on_ledGunAverageNumPartperEvent_editingFinished() { double val = ui->ledGunAverageNumPartperEvent->text().toDouble(); diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.cpp b/src/gui/MainWindowTools/aparticlesourcedialog.cpp index 862aa173..e7bef2c5 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.cpp +++ b/src/gui/MainWindowTools/aparticlesourcedialog.cpp @@ -8,6 +8,8 @@ #include "graphwindowclass.h" #include "aglobalsettings.h" #include "ajsontools.h" +#include "particlesourcesclass.h" +#include "detectorclass.h" #include #include @@ -102,7 +104,14 @@ void AParticleSourceDialog::on_pbReject_clicked() void AParticleSourceDialog::on_pbGunTest_clicked() { + ParticleSourcesClass ps(MW.Detector, MW.Detector->RandGen); + ps.append(Rec); + MW.GeometryWindow->ShowAndFocus(); + MW.ShowSource(Rec, true); + MW.TestParticleGun(&ps, ui->sbGunTestEvents->value()); + + ps.forget(Rec); //so Rec is not deleted } void AParticleSourceDialog::on_cobGunSourceType_currentIndexChanged(int index) diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 01cdb7b1..75adc9e0 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -404,6 +404,8 @@ private slots: void CalculateIndividualQEPDE(); //Public for use in scripting void clearEnergyVector(); void ShowSource(const AParticleSourceRecord *p, bool clear = true); + void TestParticleGun(ParticleSourcesClass *ParticleSources, int numParticles); + private: bool startupDetector(); //on ANTS start load/create detector void PointSource_UpdateTabWidget(); diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 4f4e1ea2..0fc2215d 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -19,12 +19,12 @@ #include "TRandom2.h" #include "TGeoManager.h" -ParticleSourcesClass::ParticleSourcesClass(const DetectorClass *Detector, TRandom2 *RandGen, TString nameID) - : Detector(Detector), MpCollection(Detector->MpCollection), RandGen(RandGen), NameID(nameID), TotalActivity(0) {} +ParticleSourcesClass::ParticleSourcesClass(const DetectorClass *Detector, TRandom2 *RandGen) + : Detector(Detector), MpCollection(Detector->MpCollection), RandGen(RandGen), TotalActivity(0) {} ParticleSourcesClass::~ParticleSourcesClass() { - ParticleSourcesClass::clear(); + clear(); } void ParticleSourcesClass::clear() @@ -249,18 +249,18 @@ QVector* ParticleSourcesClass::GenerateEvent() return GeneratedParticles; } -void ParticleSourcesClass::GeneratePosition(int isource, double *R) +void ParticleSourcesClass::GeneratePosition(int isource, double *R) const { - int index = ParticleSourcesData[isource]->index; - double X0 = ParticleSourcesData[isource]->X0; - double Y0 = ParticleSourcesData[isource]->Y0; - double Z0 = ParticleSourcesData[isource]->Z0; - double Phi = ParticleSourcesData[isource]->Phi*3.1415926535/180.0; - double Theta = ParticleSourcesData[isource]->Theta*3.1415926535/180.0; - double Psi = ParticleSourcesData[isource]->Psi*3.1415926535/180.0; - double size1 = ParticleSourcesData[isource]->size1; - double size2 = ParticleSourcesData[isource]->size2; - double size3 = ParticleSourcesData[isource]->size3; + const int& index = ParticleSourcesData[isource]->index; + const double& X0 = ParticleSourcesData[isource]->X0; + const double& Y0 = ParticleSourcesData[isource]->Y0; + const double& Z0 = ParticleSourcesData[isource]->Z0; + const double& Phi = ParticleSourcesData[isource]->Phi*3.1415926535/180.0; + const double& Theta = ParticleSourcesData[isource]->Theta*3.1415926535/180.0; + const double& Psi = ParticleSourcesData[isource]->Psi*3.1415926535/180.0; + const double& size1 = ParticleSourcesData[isource]->size1; + const double& size2 = ParticleSourcesData[isource]->size2; + const double& size3 = ParticleSourcesData[isource]->size3; switch (index) //source geometry type { @@ -372,7 +372,7 @@ void ParticleSourcesClass::GeneratePosition(int isource, double *R) return; } -void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) +void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const { GeneratedParticleStructure ps; @@ -661,6 +661,12 @@ void ParticleSourcesClass::append(AParticleSourceRecord *gunParticle) CalculateTotalActivity(); } +void ParticleSourcesClass::forget(AParticleSourceRecord *gunParticle) +{ + ParticleSourcesData.removeAll(gunParticle); + CalculateTotalActivity(); +} + bool ParticleSourcesClass::replace(int iSource, AParticleSourceRecord *gunParticle) { if (iSource < 0 || iSource >= ParticleSourcesData.size()) return false; diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index df39983d..bfc035e9 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -3,7 +3,6 @@ #include #include -#include #include "TVector3.h" class AMaterialParticleCollection; @@ -31,27 +30,35 @@ class LinkedParticleStructure LinkedParticleStructure(int iparticle, int linkedto = -1) {iParticle = iparticle; LinkedTo = linkedto;} }; -class ParticleSourcesClass : public QObject +/* +class AParticleGun +{ + virtual ~AParticleGenerator(){} + + virtual void Init() = 0; + virtual QVector* GenerateEvent() const = 0; +}; +*/ + +class ParticleSourcesClass { - Q_OBJECT public: - ParticleSourcesClass(const DetectorClass* Detector, TRandom2* RandGen, TString nameID = ""); + ParticleSourcesClass(const DetectorClass* Detector, TRandom2* RandGen); ~ParticleSourcesClass(); //MAIN usage - void Init(); // !!! has to be called before the first use of "GenerateEvent" NOT thread safe! + void Init(); // !!! has to be called before the first use of "GenerateEvent"! QVector* GenerateEvent(); //see Init!!! //requests int size() {return ParticleSourcesData.size();} double getTotalActivity(); AParticleSourceRecord* getSource(int iSource) {return ParticleSourcesData[iSource];} - //ParticleSourceStructure &operator[] (int iSource) {return *ParticleSourcesData[iSource];} AParticleSourceRecord* getLastSource() {return ParticleSourcesData.last();} - //ParticleSourceStructure &last() {return *ParticleSourcesData.last();} //Source handling - after handling is finished, requires Init() !!! void append(AParticleSourceRecord* gunParticle); + void forget(AParticleSourceRecord* gunParticle); bool replace(int iSource, AParticleSourceRecord* gunParticle); void remove(int iSource); void clear(); @@ -72,7 +79,7 @@ class ParticleSourcesClass : public QObject void checkLimitedToMaterial(AParticleSourceRecord *s); //for remove particle from configuration - void RemoveParticle(int particleId); //should NOT be used to remove one of particles in use! use onIspareticleInUse first + void RemoveParticle(int particleId); //should NOT be used to remove one of particles in use! use onIsPareticleInUse first void IsParticleInUse(int particleId, bool& bInUse, QString& SourceNames); private: @@ -81,8 +88,6 @@ class ParticleSourcesClass : public QObject AMaterialParticleCollection* MpCollection; TRandom2 *RandGen; - TString NameID; //use to make unique hist name in multithread environment /// - actually not needed anymore! - QVector ParticleSourcesData; QVector TotalParticleWeight; double TotalActivity; @@ -95,8 +100,8 @@ class ParticleSourcesClass : public QObject //utilities void CalculateTotalActivity(); - void GeneratePosition(int isource, double *R); - void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles); //QVector - only pointer is transferred! + void GeneratePosition(int isource, double *R) const; + void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! }; #endif // PARTICLESOURCESCLASS_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 4d1ad752..5e08d588 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1398,9 +1398,7 @@ ParticleSourceSimulator::ParticleSourceSimulator(const DetectorClass *detector, S1generator = new S1_Generator(photonGenerator, photonTracker, detector->MpCollection, &EnergyVector, &dataHub->GeneratedPhotonsHistory, RandGen); S2generator = new S2_Generator(photonGenerator, photonTracker, &EnergyVector, RandGen, detector->GeoManager, detector->MpCollection, &dataHub->GeneratedPhotonsHistory); - TString SName = "PartSource"; - SName += ID; - ParticleSources = new ParticleSourcesClass(detector, RandGen, SName); + ParticleSources = new ParticleSourcesClass(detector, RandGen); } ParticleSourceSimulator::~ParticleSourceSimulator() From 89fc33815e5a56c8b2608fc9c156c4c21ce04b00 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 13:21:11 +0100 Subject: [PATCH 080/140] ++ --- src/common/aparticlesourcerecord.cpp | 15 + src/common/aparticlesourcerecord.h | 2 + .../MainWindowParticleSimulation.cpp | 119 ++- src/gui/MainWindowTools/mainwindowjson.cpp | 13 +- src/gui/mainwindow.cpp | 5 - src/gui/mainwindow.h | 3 +- src/gui/mainwindow.ui | 999 ++++++++---------- 7 files changed, 533 insertions(+), 623 deletions(-) diff --git a/src/common/aparticlesourcerecord.cpp b/src/common/aparticlesourcerecord.cpp index 40bef8fe..7529377d 100644 --- a/src/common/aparticlesourcerecord.cpp +++ b/src/common/aparticlesourcerecord.cpp @@ -247,3 +247,18 @@ bool AParticleSourceRecord::readFromJson(const QJsonObject &json, AMaterialParti } return true; } + +const QString AParticleSourceRecord::getShapeString() const +{ + switch (index) + { + case 0: return "Point"; + case 1: return "Linear"; + case 2: return "Square"; + case 3: return "Round"; + case 4: return "Box"; + case 5: return "Cylinder"; + default: ; + } + return "-error-"; +} diff --git a/src/common/aparticlesourcerecord.h b/src/common/aparticlesourcerecord.h index 358be67c..68d795dd 100644 --- a/src/common/aparticlesourcerecord.h +++ b/src/common/aparticlesourcerecord.h @@ -73,6 +73,8 @@ struct AParticleSourceRecord void writeToJson(QJsonObject & json, const AMaterialParticleCollection & MpCollection) const; bool readFromJson(const QJsonObject & json, AMaterialParticleCollection & MpCollection); + const QString getShapeString() const; + //local variables, used in tracking, calculated autonatically, not to be loaded/saved! int LimitedToMat; //automatically calculated if LimtedToMatName matches a material bool fLimit = false; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 9c028da9..c78e3df6 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -227,22 +227,7 @@ void MainWindow::ShowSource(const AParticleSourceRecord* p, bool clear) void MainWindow::on_pbGunTest_clicked() { MainWindow::on_pbGunShowSource_toggled(true); - - QVector activities; - //forcing to 100% activity the currently selected source - int isource = ui->cobParticleSource->currentIndex(); - for (int i=0; isize(); i++) - { - activities << ParticleSources->getSource(i)->Activity; //remember old - if (i==isource) ParticleSources->getSource(i)->Activity = 1.0; - else ParticleSources->getSource(i)->Activity = 0; - } - TestParticleGun(ParticleSources, ui->sbGunTestEvents->value()); - - //restore activities of the sources - for (int i=0; isize(); i++) - ParticleSources->getSource(i)->Activity = activities.at(i); } void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numParticles) @@ -295,7 +280,7 @@ void MainWindow::on_ledGunAverageNumPartperEvent_editingFinished() void MainWindow::on_pbRemoveSource_clicked() { if (ParticleSources->size() == 0) return; - int isource = ui->cobParticleSource->currentIndex(); + int isource = ui->lwDefinedParticleSources->currentRow(); int ret = QMessageBox::question(this, "Remove particle source", "Are you sure - this will remove source " + ParticleSources->getSource(isource)->name, @@ -304,11 +289,8 @@ void MainWindow::on_pbRemoveSource_clicked() if (ret != QMessageBox::Yes) return; ParticleSources->remove(isource); - ui->cobParticleSource->removeItem(isource); - ui->cobParticleSource->setCurrentIndex(isource-1); on_pbUpdateSimConfig_clicked(); - on_pbUpdateSourcesIndication_clicked(); if (ui->pbGunShowSource->isChecked()) { @@ -327,46 +309,72 @@ void MainWindow::on_pbAddSource_clicked() AParticleSourceRecord* s = new AParticleSourceRecord(); s->GunParticles << new GunParticleStruct(); ParticleSources->append(s); - ui->cobParticleSource->addItem(ParticleSources->getLastSource()->name); - ui->cobParticleSource->setCurrentIndex(ParticleSources->size()-1); + on_pbUpdateSourcesIndication_clicked(); + ui->lwDefinedParticleSources->setCurrentRow( ParticleSources->size()-1 ); on_pbEditParticleSource_clicked(); } +#include void MainWindow::on_pbUpdateSourcesIndication_clicked() { qDebug() << "Update sources indication. Defined sources:"<size(); - int isource = ui->cobParticleSource->currentIndex(); - - ui->cobParticleSource->clear(); int numSources = ParticleSources->size(); ui->labPartSourcesDefined->setText(QString::number(numSources)); - if (numSources == 0) return; - ui->fParticleSources->setEnabled(true); - ui->frSelectSource->setEnabled(true); + + int curRow = ui->lwDefinedParticleSources->currentRow(); + ui->lwDefinedParticleSources->clear(); for (int i=0; icobParticleSource->addItem(ParticleSources->getSource(i)->name); - if (isource >= numSources) isource = 0; - if (isource == -1) isource = 0; + { + AParticleSourceRecord* pr = ParticleSources->getSource(i); + QListWidgetItem* item = new QListWidgetItem(); + ui->lwDefinedParticleSources->addItem(item); + + QFrame* fr = new QFrame(); + fr->setFrameShape(QFrame::Box); + QHBoxLayout* l = new QHBoxLayout(); + l->setContentsMargins(3, 2, 3, 2); + l->addWidget(new QLabel(pr->name + ',')); + l->addWidget(new QLabel(pr->getShapeString() + ',')); + l->addWidget(new QLabel( QString("%1 particle(s)").arg(pr->GunParticles.size()))); + l->addStretch(); + l->addWidget(new QLabel("Activity:")); + QLineEdit* e = new QLineEdit(QString::number(pr->Activity)); + e->setMaximumWidth(75); + QDoubleValidator* val = new QDoubleValidator(this); + val->setBottom(0); + e->setValidator(val); + QObject::connect(e, &QLineEdit::editingFinished, [pr, e, this] + { + double newVal = e->text().toDouble(); + if (pr->Activity == newVal) return; + pr->Activity = newVal; + this->onTotalActivityChanged(); + }); + l->addWidget(e); + double totAct = ParticleSources->getTotalActivity(); + double per = ( totAct == 0 ? 0 : 100.0 * pr->Activity / totAct ); + QString t = QString("(%1%)").arg(per, 3, 'g', 3); + l->addWidget(new QLabel(t)); + + fr->setLayout(l); + item->setSizeHint(fr->sizeHint()); + + ui->lwDefinedParticleSources->setItemWidget(item, fr); - ui->cobParticleSource->setCurrentIndex(isource); - updateActivityIndication(); + } + + if (curRow < 0 || curRow >= ui->lwDefinedParticleSources->count()) + curRow = 0; + ui->lwDefinedParticleSources->setCurrentRow(curRow); } -void MainWindow::updateActivityIndication() +void MainWindow::onTotalActivityChanged() { - double activity = ui->ledSourceActivity->text().toDouble(); - QSize size(ui->lSourceActive->height(), ui->lSourceActive->height()); - QIcon wIcon = GuiUtils::createColorCircleIcon(size, Qt::yellow); - if (activity == 0) ui->lSourceActive->setPixmap(wIcon.pixmap(16,16)); - else ui->lSourceActive->setPixmap(QIcon().pixmap(16,16)); - - double fraction = 0; - double TotalActivity = ParticleSources->getTotalActivity(); - if (TotalActivity != 0) fraction = activity / TotalActivity * 100.0; - ui->labOfTotal->setText(QString::number(fraction, 'g', 3)+"%"); + //on_pbUpdateSourcesIndication_clicked(); + on_pbUpdateSimConfig_clicked(); } void MainWindow::on_pbGunShowSource_toggled(bool checked) @@ -385,7 +393,7 @@ void MainWindow::on_pbGunShowSource_toggled(bool checked) void MainWindow::ShowParticleSource_noFocus() { - int isource = ui->cobParticleSource->currentIndex(); + int isource = ui->lwDefinedParticleSources->currentRow(); if (isource < 0) return; if (isource >= ParticleSources->size()) { @@ -403,7 +411,7 @@ void MainWindow::on_pbSaveParticleSource_clicked() QFileInfo file(fileName); if (file.suffix().isEmpty()) fileName += ".json"; QJsonObject json, js; - ParticleSources->writeSourceToJson(ui->cobParticleSource->currentIndex(), json); + ParticleSources->writeSourceToJson(ui->lwDefinedParticleSources->currentRow(), json); js["ParticleSource"] = json; bool bOK = SaveJsonToFile(js, fileName); if (!bOK) message("Failed to save json to file: "+fileName, this); @@ -422,7 +430,7 @@ void MainWindow::on_pbLoadParticleSource_clicked() QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; QString fileName = QFileDialog::getOpenFileName(this, "Import particle source", starter, "json files (*.json)"); if (fileName.isEmpty()) return; - int iSource = ui->cobParticleSource->currentIndex(); + int iSource = ui->lwDefinedParticleSources->currentRow(); QJsonObject json, js; bool ok = LoadJsonFromFile(json, fileName); if (!ok) @@ -438,7 +446,6 @@ void MainWindow::on_pbLoadParticleSource_clicked() int oldPartCollSize = Detector->MpCollection->countParticles(); js = json["ParticleSource"].toObject(); ParticleSources->readSourceFromJson(iSource, js); - ui->cobParticleSource->setItemText(iSource, ParticleSources->getSource(iSource)->name); onRequestDetectorGuiUpdate(); @@ -626,16 +633,25 @@ void MainWindow::on_pbClearAllStack_clicked() void MainWindow::on_pbEditParticleSource_clicked() { - int isource = ui->cobParticleSource->currentIndex(); + int isource = ui->lwDefinedParticleSources->currentRow(); + if (isource == -1) + { + message("Select a source to edit", this); + return; + } + if (isource >= ParticleSources->size()) + { + message("Error - bad source index!", this); + return; + } + AParticleSourceDialog d(*this, ParticleSources->getSource(isource)); int res = d.exec(); - if (res == QDialog::Rejected) return; + ParticleSources->replace(isource, d.getResult()); AParticleSourceRecord* ps = ParticleSources->getSource(isource); - - ps->Activity = ui->ledSourceActivity->text().toDouble(); ParticleSources->checkLimitedToMaterial(ps); if (Detector->isGDMLempty()) @@ -667,7 +683,6 @@ void MainWindow::on_pbEditParticleSource_clicked() on_pbUpdateSimConfig_clicked(); - updateActivityIndication(); //update marker! if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); //qDebug() << "...update sources done"; } diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index b1eef914..3bb2f5b1 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -633,13 +633,14 @@ if (scj.contains("CustomDistrib")) void MainWindow::selectFirstActiveParticleSource() { if (ParticleSources->getTotalActivity() > 0) - { //show the first source with non-zero activity - int i=0; + { + //show the first source with non-zero activity + int i = 0; for (; isize(); i++) if (ParticleSources->getSource(i)->Activity > 0) break; - ui->cobParticleSource->setCurrentIndex(i); - } - else if (ParticleSources->size()>0) ui->cobParticleSource->setCurrentIndex(0); - else ui->cobParticleSource->setCurrentIndex(-1); + + if (i < ui->lwDefinedParticleSources->count()) + ui->lwDefinedParticleSources->setCurrentRow(i); + } on_pbUpdateSourcesIndication_clicked(); } diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 2cbf71f5..18d7603e 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4642,11 +4642,6 @@ void MainWindow::on_bpResults_2_clicked() Owindow->SetTab(3); } -void MainWindow::on_cobParticleSource_activated(int /*index*/) -{ - if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); -} - void MainWindow::on_cobPartPerEvent_currentIndexChanged(int index) { QString s; diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 75adc9e0..fc801d5c 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -553,7 +553,6 @@ private slots: void on_pobTest_2_clicked(); void on_bpResults_2_clicked(); void on_actionScript_window_triggered(); - void on_cobParticleSource_activated(int index); void on_actionQuick_save_1_triggered(); void on_actionQuick_save_2_triggered(); void on_actionQuick_save_3_triggered(); @@ -614,7 +613,6 @@ public slots: void initDetectorSandwich(); void onGuiEnableStatus(bool fLocked); void ShowParticleSource_noFocus(); - void updateActivityIndication(); #ifdef __USE_ANTS_PYTHON__ void createPythonScriptWindow(); @@ -628,6 +626,7 @@ public slots: void OnSlabDoubleClicked(QString SlabName); void onNewConfigLoaded(); void onOpticalOverrideDialogAccepted(); + void onTotalActivityChanged(); signals: void RequestStopLoad(); }; diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index f2b1b529..d72f282e 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9489,378 +9489,6 @@ double events: Particle sources - - - - 210 - 299 - 320 - 21 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 114 - 0 - 141 - 20 - - - - - 50 - false - - - - # of particles per event: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 260 - 0 - 54 - 20 - - - - - 50 - false - - - - 2 - - - - - - 30 - 0 - 80 - 19 - - - - - 50 - false - - - - - Constant - - - - - Poisson - - - - - - - - 7 - 9 - 149 - 16 - - - - - 50 - false - - - - Particles sources defined: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 38 - 300 - 200 - 17 - - - - - 50 - false - - - - Multiple particles per event - - - - - - 380 - 0 - 142 - 23 - - - - - 50 - false - - - - ...update source indication - - - - - true - - - - 27 - 68 - 441 - 101 - - - - QFrame::Box - - - QFrame::Plain - - - - - 60 - 70 - 61 - 23 - - - - - 50 - false - - - - Export - - - - - - 130 - 70 - 61 - 23 - - - - - 50 - false - - - - Import - - - - - - 135 - 7 - 67 - 20 - - - - - 50 - false - - - - 1 - - - - - - 36 - 8 - 95 - 16 - - - - - 50 - false - - - - Relative activity: - - - - - - 213 - 11 - 46 - 13 - - - - 100% - - - Qt::AlignCenter - - - - - - 261 - 9 - 121 - 16 - - - - - 50 - false - - - - of total activity - - - - - - 15 - 8 - 21 - 16 - - - - -- - - - - - - 70 - 40 - 131 - 23 - - - - Edit source - - - - - - 350 - 50 - 81 - 20 - - - - 1 - - - 1000000 - - - 100 - - - - - - 250 - 50 - 101 - 24 - - - - Test generator - - - - - - - 162 - 11 - 40 - 13 - - - - - 75 - true - - - - 0 - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - 218 - 7 - 197 - 23 - - - - - 75 - true - - - - Define new source - - @@ -9954,7 +9582,7 @@ double events: 38 - 280 + 304 210 17 @@ -9969,16 +9597,438 @@ double events: Ignore events with no PM hits - - - true - + + + true + + + + 240 + 304 + 271 + 17 + + + + + 50 + false + + + + Ignore events with no energy deposition + + + false + + + + + + 10 + 340 + 90 + 22 + + + + 1 + + + 2147483647 + + + 10 + + + + + + 424 + 340 + 101 + 21 + + + + + 50 + false + + + + tracks options + + + + + + 8 + 11 + 514 + 261 + + + + + 50 + false + + + + 0 + + + + Direct + + + + + 70 + 0 + 171 + 36 + + + + QFrame::Box + + + QFrame::Raised + + + + + 30 + 10 + 120 + 23 + + + + + 50 + false + + + + Show geometry + + + true + + + + + + + 360 + 0 + 142 + 23 + + + + + 50 + false + + + + ...update source indication + + + + + + 430 + 90 + 60 + 23 + + + + + 75 + true + + + + New + + + + + + 13 + 40 + 149 + 16 + + + + + 50 + false + + + + Defined sources: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + 260 + 10 + 40 + 13 + + + + + 75 + true + + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + 180 + 212 + 320 + 21 + + + + QFrame::NoFrame + + + QFrame::Raised + + + + + 114 + 0 + 141 + 20 + + + + + 50 + false + + + + # of particles per event: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 260 + 0 + 54 + 20 + + + + + 50 + false + + + + 2 + + + + + + 30 + 0 + 80 + 19 + + + + + 50 + false + + + + + Constant + + + + + Poisson + + + + + + + + 10 + 211 + 198 + 18 + + + + + 50 + false + + + + Multiple particles per event + + + + + + 10 + 60 + 411 + 131 + + + + + + + 430 + 120 + 60 + 23 + + + + + 50 + false + + + + Remove + + + + + + 430 + 160 + 60 + 23 + + + + + 50 + false + + + + Export + + + + + + 430 + 180 + 60 + 23 + + + + + 50 + false + + + + Import + + + + + + 430 + 60 + 60 + 23 + + + + Edit + + + + + + 320 + 10 + 21 + 16 + + + + -- + + + cbGunAllowMultipleEvents + frSelectSource + pbUpdateSourcesIndication + pbAddSource + label_76 + labPartSourcesDefined + fGunMultipleEvents + lwDefinedParticleSources + pbRemoveSource + pbSaveParticleSource + pbLoadParticleSource + pbEditParticleSource + lSourceActive + + + + From script + + + + + From file + + + + - 240 - 280 - 271 - 17 + 271 + 276 + 81 + 20 @@ -9987,168 +10037,23 @@ double events: false - - Ignore events with no energy deposition - - - false - - - - - - 131 - 50 - 4 - 19 - - - - QFrame::Plain - - - Qt::Vertical - - - - - - 6 - 28 - 524 - 36 - - - - QFrame::NoFrame - - - QFrame::Raised - - - - - 444 - 7 - 71 - 23 - - - - - 50 - false - - - - Remove - - - - - - 58 - 8 - 150 - 22 - - - - false - - - - - - 163 - 17 - 308 - 3 - - - - QFrame::Plain - - - Qt::Horizontal - - - - - - 289 - 7 - 120 - 23 - - - - - 50 - false - - - - Show geometry - - - true - - - - - - -5 - 12 - 60 - 13 - - - - - 50 - false - - - - Source: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - line_2 - pbRemoveSource - cobParticleSource - pbGunShowSource - label_150 - - - - - 10 - 340 - 90 - 22 - - 1 - 2147483647 + 1000000 - 10 + 100 - + - 424 - 340 + 164 + 275 101 - 21 + 24 @@ -10158,19 +10063,10 @@ double events: - tracks options + Test generator - line_16 - frSelectSource line_21 - fGunMultipleEvents - label_76 - cbGunAllowMultipleEvents - pbUpdateSourcesIndication - fParticleSources - labPartSourcesDefined - pbAddSource cbGunDoS1 cbGunDoS2 label_253 @@ -10179,6 +10075,9 @@ double events: cbIgnoreEventsWithNoEnergyDepo sbGunEvents pbTrackOptionsGun + tabWidget_3 + sbGunTestEvents + pbGunTest @@ -15636,22 +15535,6 @@ on stack - - cobParticleSource - activated(int) - pbUpdateSourcesIndication - click() - - - 187 - 256 - - - 408 - 199 - - - cbEnableMCcrosstalk clicked() From 2257e1260784f7baf9603a323254079c106d6cbc Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 13:27:10 +0100 Subject: [PATCH 081/140] ++ --- src/common/aparticlesourcerecord.cpp | 6 +- src/common/aparticlesourcerecord.h | 5 +- .../MainWindowParticleSimulation.cpp | 2 +- .../MainWindowTools/aparticlesourcedialog.cpp | 5 +- src/gui/mainwindow.ui | 175 +++++++++--------- src/modules/particlesourcesclass.cpp | 4 +- 6 files changed, 100 insertions(+), 97 deletions(-) diff --git a/src/common/aparticlesourcerecord.cpp b/src/common/aparticlesourcerecord.cpp index 7529377d..d02e7496 100644 --- a/src/common/aparticlesourcerecord.cpp +++ b/src/common/aparticlesourcerecord.cpp @@ -156,7 +156,7 @@ AParticleSourceRecord * AParticleSourceRecord::clone() const void AParticleSourceRecord::writeToJson(QJsonObject & json, const AMaterialParticleCollection & MpCollection) const { json["Name"] = name; - json["Type"] = index; + json["Type"] = shape; json["Activity"] = Activity; json["X"] = X0; json["Y"] = Y0; @@ -190,7 +190,7 @@ void AParticleSourceRecord::writeToJson(QJsonObject & json, const AMaterialParti bool AParticleSourceRecord::readFromJson(const QJsonObject &json, AMaterialParticleCollection &MpCollection) { parseJson(json, "Name", name); - parseJson(json, "Type", index); + parseJson(json, "Type", shape); parseJson(json, "Activity", Activity); parseJson(json, "X", X0); parseJson(json, "Y", Y0); @@ -250,7 +250,7 @@ bool AParticleSourceRecord::readFromJson(const QJsonObject &json, AMaterialParti const QString AParticleSourceRecord::getShapeString() const { - switch (index) + switch (shape) { case 0: return "Point"; case 1: return "Linear"; diff --git a/src/common/aparticlesourcerecord.h b/src/common/aparticlesourcerecord.h index 68d795dd..2044a892 100644 --- a/src/common/aparticlesourcerecord.h +++ b/src/common/aparticlesourcerecord.h @@ -38,9 +38,8 @@ struct AParticleSourceRecord { ~AParticleSourceRecord(); //deletes records in dynamic GunParticles - QString name = "Underfined"; - //source type (geometry) - int index = 0; //shape + QString name = "No_name"; + int shape = 0; //position double X0 = 0; double Y0 = 0; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index c78e3df6..53bf33d1 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -55,7 +55,7 @@ void MainWindow::SimParticleSourcesConfigToJson(QJsonObject &json) void MainWindow::ShowSource(const AParticleSourceRecord* p, bool clear) { - int index = p->index; + int index = p->shape; double X0 = p->X0; double Y0 = p->Y0; double Z0 = p->Z0; diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.cpp b/src/gui/MainWindowTools/aparticlesourcedialog.cpp index e7bef2c5..825f6fce 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.cpp +++ b/src/gui/MainWindowTools/aparticlesourcedialog.cpp @@ -42,7 +42,7 @@ AParticleSourceDialog::AParticleSourceDialog(MainWindow & MW, const AParticleSou ui->cobGunParticle->addItems(MW.MpCollection->getListOfParticleNames()); ui->leSourceName->setText(Rec->name); - ui->cobGunSourceType->setCurrentIndex(Rec->index); + ui->cobGunSourceType->setCurrentIndex(Rec->shape); ui->ledGun1DSize->setText(QString::number(2.0 * Rec->size1)); ui->ledGun2DSize->setText(QString::number(2.0 * Rec->size2)); @@ -329,7 +329,8 @@ void AParticleSourceDialog::on_cbLinkedParticle_toggled(bool checked) void AParticleSourceDialog::on_pbUpdateRecord_clicked() { - Rec->index = ui->cobGunSourceType->currentIndex(); + Rec->name = ui->leSourceName->text(); + Rec->shape = ui->cobGunSourceType->currentIndex(); Rec->size1 = 0.5 * ui->ledGun1DSize->text().toDouble(); Rec->size2 = 0.5 * ui->ledGun2DSize->text().toDouble(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index d72f282e..93480789 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9913,6 +9913,9 @@ double events: 131 + + 1 + @@ -13222,8 +13225,8 @@ on stack setCurrentIndex(int) - 368 - 411 + 370 + 433 519 @@ -13254,8 +13257,8 @@ on stack setCurrentIndex(int) - 313 - 384 + 319 + 406 257 @@ -14630,8 +14633,8 @@ on stack click() - 225 - 397 + 227 + 419 46 @@ -14646,8 +14649,8 @@ on stack click() - 315 - 397 + 317 + 419 92 @@ -14662,8 +14665,8 @@ on stack click() - 405 - 397 + 407 + 419 112 @@ -14678,8 +14681,8 @@ on stack click() - 182 - 376 + 188 + 398 40 @@ -14694,8 +14697,8 @@ on stack click() - 254 - 376 + 260 + 398 61 @@ -14710,8 +14713,8 @@ on stack click() - 325 - 376 + 331 + 398 88 @@ -14726,8 +14729,8 @@ on stack click() - 176 - 418 + 182 + 440 31 @@ -14742,8 +14745,8 @@ on stack click() - 218 - 418 + 224 + 440 48 @@ -14758,8 +14761,8 @@ on stack click() - 260 - 418 + 266 + 440 47 @@ -14774,8 +14777,8 @@ on stack click() - 327 - 419 + 333 + 441 83 @@ -14790,8 +14793,8 @@ on stack click() - 426 - 418 + 432 + 440 101 @@ -14806,8 +14809,8 @@ on stack click() - 110 - 437 + 116 + 459 43 @@ -14822,8 +14825,8 @@ on stack click() - 176 - 439 + 182 + 461 14 @@ -14838,8 +14841,8 @@ on stack click() - 218 - 439 + 224 + 461 28 @@ -14854,8 +14857,8 @@ on stack click() - 260 - 439 + 266 + 461 50 @@ -14870,8 +14873,8 @@ on stack click() - 329 - 440 + 335 + 462 77 @@ -14886,8 +14889,8 @@ on stack click() - 393 - 439 + 399 + 461 122 @@ -14902,8 +14905,8 @@ on stack click() - 129 - 458 + 135 + 480 44 @@ -14918,8 +14921,8 @@ on stack click() - 176 - 460 + 182 + 482 52 @@ -14934,8 +14937,8 @@ on stack click() - 218 - 460 + 224 + 482 36 @@ -14950,8 +14953,8 @@ on stack click() - 260 - 460 + 266 + 482 50 @@ -14966,8 +14969,8 @@ on stack click() - 326 - 461 + 332 + 483 75 @@ -14982,8 +14985,8 @@ on stack click() - 432 - 460 + 438 + 482 111 @@ -14998,8 +15001,8 @@ on stack click() - 162 - 384 + 168 + 406 36 @@ -15014,8 +15017,8 @@ on stack click() - 313 - 384 + 319 + 406 51 @@ -15030,8 +15033,8 @@ on stack click() - 127 - 414 + 129 + 436 40 @@ -15046,8 +15049,8 @@ on stack click() - 127 - 436 + 129 + 458 57 @@ -15062,8 +15065,8 @@ on stack click() - 223 - 414 + 225 + 436 58 @@ -15078,8 +15081,8 @@ on stack click() - 223 - 436 + 225 + 458 37 @@ -15094,8 +15097,8 @@ on stack click() - 368 - 411 + 370 + 433 97 @@ -15110,8 +15113,8 @@ on stack click() - 367 - 434 + 369 + 456 110 @@ -15126,8 +15129,8 @@ on stack click() - 157 - 416 + 159 + 438 31 @@ -15142,8 +15145,8 @@ on stack click() - 157 - 437 + 159 + 459 33 @@ -15158,8 +15161,8 @@ on stack click() - 237 - 416 + 239 + 438 68 @@ -15174,8 +15177,8 @@ on stack click() - 237 - 437 + 239 + 459 58 @@ -15190,8 +15193,8 @@ on stack click() - 368 - 434 + 370 + 456 119 @@ -15206,8 +15209,8 @@ on stack click() - 464 - 434 + 466 + 456 122 @@ -15382,8 +15385,8 @@ on stack click() - 142 - 495 + 146 + 519 19 @@ -15398,8 +15401,8 @@ on stack click() - 190 - 515 + 176 + 460 46 @@ -15414,8 +15417,8 @@ on stack click() - 488 - 517 + 472 + 463 113 @@ -15670,8 +15673,8 @@ on stack click() - 285 - 516 + 269 + 462 83 diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 0fc2215d..a6514c27 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -251,7 +251,7 @@ QVector* ParticleSourcesClass::GenerateEvent() void ParticleSourcesClass::GeneratePosition(int isource, double *R) const { - const int& index = ParticleSourcesData[isource]->index; + const int& index = ParticleSourcesData[isource]->shape; const double& X0 = ParticleSourcesData[isource]->X0; const double& Y0 = ParticleSourcesData[isource]->Y0; const double& Z0 = ParticleSourcesData[isource]->Z0; @@ -599,7 +599,7 @@ int ParticleSourcesClass::CheckSource(int isource) if (getTotalActivity() == 0) return 4; // 4 - total activity = 0 AParticleSourceRecord* ps = ParticleSourcesData[isource]; - if (ps->index <0 || ps->index>5) return 10; //10 - unknown source shape + if (ps->shape <0 || ps->shape>5) return 10; //10 - unknown source shape int numParts = ps->GunParticles.size(); //11 - no particles defined if (numParts == 0) return 11; From 2883d84d61e7e57a098a3713004e810d471b1765 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 17:55:13 +0100 Subject: [PATCH 082/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 2 + .../MainWindowParticleSimulation.cpp | 111 ++++++------- src/gui/mainwindow.h | 2 +- src/gui/mainwindow.ui | 147 +++++++----------- 4 files changed, 115 insertions(+), 147 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 949c07fc..e111b202 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -187,6 +187,8 @@ MainWindow::MainWindow(DetectorClass *Detector, QObject::connect(SimulationManager->Runner, SIGNAL(updateReady(int, double)), this, SLOT(RefreshPhotSimOnTimer(int, double))); //Simulation interface refresh/update stuff QObject::connect(SimulationManager, SIGNAL(SimulationFinished()), this, SLOT(simulationFinished())); //Simulation finished + QObject::connect(this, &MainWindow::RequestUpdateSimConfig, this, &MainWindow::on_pbUpdateSimConfig_clicked, Qt::QueuedConnection); + DoNotUpdateGeometry = false; //control qDebug()<<">Loading default detector..."; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 53bf33d1..416f35bd 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -318,63 +318,68 @@ void MainWindow::on_pbAddSource_clicked() #include void MainWindow::on_pbUpdateSourcesIndication_clicked() { - qDebug() << "Update sources indication. Defined sources:"<size(); + qDebug() << "Update sources indication. Defined sources:"<size(); - int numSources = ParticleSources->size(); - ui->labPartSourcesDefined->setText(QString::number(numSources)); + int numSources = ParticleSources->size(); - int curRow = ui->lwDefinedParticleSources->currentRow(); - ui->lwDefinedParticleSources->clear(); + int curRow = ui->lwDefinedParticleSources->currentRow(); + ui->lwDefinedParticleSources->clear(); - for (int i=0; igetSource(i); - QListWidgetItem* item = new QListWidgetItem(); - ui->lwDefinedParticleSources->addItem(item); - - QFrame* fr = new QFrame(); - fr->setFrameShape(QFrame::Box); - QHBoxLayout* l = new QHBoxLayout(); - l->setContentsMargins(3, 2, 3, 2); - l->addWidget(new QLabel(pr->name + ',')); - l->addWidget(new QLabel(pr->getShapeString() + ',')); - l->addWidget(new QLabel( QString("%1 particle(s)").arg(pr->GunParticles.size()))); - l->addStretch(); - l->addWidget(new QLabel("Activity:")); - QLineEdit* e = new QLineEdit(QString::number(pr->Activity)); - e->setMaximumWidth(75); - QDoubleValidator* val = new QDoubleValidator(this); - val->setBottom(0); - e->setValidator(val); - QObject::connect(e, &QLineEdit::editingFinished, [pr, e, this] - { - double newVal = e->text().toDouble(); - if (pr->Activity == newVal) return; - pr->Activity = newVal; - this->onTotalActivityChanged(); - }); - l->addWidget(e); - double totAct = ParticleSources->getTotalActivity(); - double per = ( totAct == 0 ? 0 : 100.0 * pr->Activity / totAct ); - QString t = QString("(%1%)").arg(per, 3, 'g', 3); - l->addWidget(new QLabel(t)); - - fr->setLayout(l); - item->setSizeHint(fr->sizeHint()); - - ui->lwDefinedParticleSources->setItemWidget(item, fr); - - } - - if (curRow < 0 || curRow >= ui->lwDefinedParticleSources->count()) - curRow = 0; - ui->lwDefinedParticleSources->setCurrentRow(curRow); -} + for (int i=0; igetSource(i); + QListWidgetItem* item = new QListWidgetItem(); + ui->lwDefinedParticleSources->addItem(item); + + QFrame* fr = new QFrame(); + fr->setFrameShape(QFrame::Box); + QHBoxLayout* l = new QHBoxLayout(); + l->setContentsMargins(3, 2, 3, 2); + QLabel* lab = new QLabel(pr->name); + lab->setMinimumWidth(110); + QFont f = lab->font(); + f.setBold(true); + lab->setFont(f); + l->addWidget(lab); + l->addWidget(new QLabel(pr->getShapeString() + ',')); + l->addWidget(new QLabel( QString("%1 particle%2").arg(pr->GunParticles.size()).arg( pr->GunParticles.size()>1 ? "s" : "" ) ) ); + l->addStretch(); + + l->addWidget(new QLabel("Fraction:")); + QLineEdit* e = new QLineEdit(QString::number(pr->Activity)); + e->setMaximumWidth(50); + e->setMinimumWidth(50); + QDoubleValidator* val = new QDoubleValidator(this); + val->setBottom(0); + e->setValidator(val); + QObject::connect(e, &QLineEdit::editingFinished, [pr, e, this]() + { + double newVal = e->text().toDouble(); + if (pr->Activity == newVal) return; + pr->Activity = newVal; + e->clearFocus(); + emit this->RequestUpdateSimConfig(); + }); + e->setVisible(numSources > 1); + l->addWidget(e); + + double totAct = ParticleSources->getTotalActivity(); + double per = ( totAct == 0 ? 0 : 100.0 * pr->Activity / totAct ); + QString t = QString("%1%").arg(per, 3, 'g', 3); + lab = new QLabel(t); + lab->setMinimumWidth(45); + l->addWidget(lab); + + + fr->setLayout(l); + item->setSizeHint(fr->sizeHint()); + ui->lwDefinedParticleSources->setItemWidget(item, fr); + item->setSizeHint(fr->sizeHint()); + } -void MainWindow::onTotalActivityChanged() -{ - //on_pbUpdateSourcesIndication_clicked(); - on_pbUpdateSimConfig_clicked(); + if (curRow < 0 || curRow >= ui->lwDefinedParticleSources->count()) + curRow = 0; + ui->lwDefinedParticleSources->setCurrentRow(curRow); } void MainWindow::on_pbGunShowSource_toggled(bool checked) diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index fc801d5c..9e02315b 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -626,9 +626,9 @@ public slots: void OnSlabDoubleClicked(QString SlabName); void onNewConfigLoaded(); void onOpticalOverrideDialogAccepted(); - void onTotalActivityChanged(); signals: void RequestStopLoad(); + void RequestUpdateSimConfig(); //used to delay execution (quesued connection have to be used). Used in Lambda expression! }; #endif // MAINWINDOW_H diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 93480789..d6dd9cbb 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9666,7 +9666,7 @@ double events: 8 11 514 - 261 + 251 @@ -9682,44 +9682,6 @@ double events: Direct - - - - 70 - 0 - 171 - 36 - - - - QFrame::Box - - - QFrame::Raised - - - - - 30 - 10 - 120 - 23 - - - - - 50 - false - - - - Show geometry - - - true - - - @@ -9743,15 +9705,15 @@ double events: 430 - 90 + 53 60 23 - 75 - true + 50 + false @@ -9761,8 +9723,8 @@ double events: - 13 - 40 + 10 + 2 149 16 @@ -9780,33 +9742,11 @@ double events: Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - 260 - 10 - 40 - 13 - - - - - 75 - true - - - - 0 - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - 180 - 212 + 194 320 21 @@ -9889,7 +9829,7 @@ double events: 10 - 211 + 193 198 18 @@ -9907,10 +9847,10 @@ double events: - 10 - 60 + 7 + 22 411 - 131 + 161 @@ -9921,7 +9861,7 @@ double events: 430 - 120 + 83 60 23 @@ -9940,7 +9880,7 @@ double events: 430 - 160 + 110 60 23 @@ -9959,7 +9899,7 @@ double events: 430 - 180 + 130 60 23 @@ -9978,7 +9918,7 @@ double events: 430 - 60 + 23 60 23 @@ -9987,32 +9927,16 @@ double events: Edit - - - - 320 - 10 - 21 - 16 - - - - -- - - cbGunAllowMultipleEvents - frSelectSource pbUpdateSourcesIndication pbAddSource label_76 - labPartSourcesDefined fGunMultipleEvents lwDefinedParticleSources pbRemoveSource pbSaveParticleSource pbLoadParticleSource pbEditParticleSource - lSourceActive @@ -10029,7 +9953,7 @@ double events: 271 - 276 + 269 81 20 @@ -10054,7 +9978,7 @@ double events: 164 - 275 + 268 101 24 @@ -10069,6 +9993,41 @@ double events: Test generator + + + + 32 + 268 + 120 + 23 + + + + + 50 + false + + + + Show geometry + + + true + + + + + + 370 + 273 + 21 + 16 + + + + -- + + line_21 cbGunDoS1 cbGunDoS2 @@ -10081,6 +10040,8 @@ double events: tabWidget_3 sbGunTestEvents pbGunTest + pbGunShowSource + lSourceActive From d69d7605f7f87e31fc0a39b7b3a811c6df0f32a3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 18:33:25 +0100 Subject: [PATCH 083/140] ++ --- .../MainWindowParticleSimulation.cpp | 193 ++++++++++-------- src/gui/mainwindow.h | 4 + src/gui/mainwindow.ui | 84 ++++---- 3 files changed, 156 insertions(+), 125 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 416f35bd..b86f06ff 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -26,6 +26,7 @@ #include #include #include +#include //Root #include "TVirtualGeoTrack.h" @@ -269,57 +270,63 @@ void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numP void MainWindow::on_ledGunAverageNumPartperEvent_editingFinished() { - double val = ui->ledGunAverageNumPartperEvent->text().toDouble(); - if (val<0) - { - message("Average number of particles per event should be more than 0", this); - ui->ledGunAverageNumPartperEvent->setText("1"); - } + double val = ui->ledGunAverageNumPartperEvent->text().toDouble(); + if (val<0) + { + message("Average number of particles per event should be more than 0", this); + ui->ledGunAverageNumPartperEvent->setText("1"); + } } void MainWindow::on_pbRemoveSource_clicked() { - if (ParticleSources->size() == 0) return; - int isource = ui->lwDefinedParticleSources->currentRow(); + int isource = ui->lwDefinedParticleSources->currentRow(); + if (isource == -1) + { + message("Select a source to remove", this); + return; + } + if (isource >= ParticleSources->size()) + { + message("Error - bad source index!", this); + return; + } - int ret = QMessageBox::question(this, "Remove particle source", - "Are you sure - this will remove source " + ParticleSources->getSource(isource)->name, - QMessageBox::Yes | QMessageBox::Cancel, - QMessageBox::Cancel); - if (ret != QMessageBox::Yes) return; + int ret = QMessageBox::question(this, "Remove particle source", + "Are you sure you want to remove source " + ParticleSources->getSource(isource)->name, + QMessageBox::Yes | QMessageBox::Cancel, + QMessageBox::Cancel); + if (ret != QMessageBox::Yes) return; - ParticleSources->remove(isource); + ParticleSources->remove(isource); - on_pbUpdateSimConfig_clicked(); - on_pbUpdateSourcesIndication_clicked(); - if (ui->pbGunShowSource->isChecked()) + on_pbUpdateSimConfig_clicked(); + on_pbUpdateSourcesIndication_clicked(); + if (ui->pbGunShowSource->isChecked()) { - if (ParticleSources->size() == 0) + if (ParticleSources->size() == 0) { - Detector->GeoManager->ClearTracks(); - GeometryWindow->ShowGeometry(false); + Detector->GeoManager->ClearTracks(); + GeometryWindow->ShowGeometry(false); } else - ShowParticleSource_noFocus(); + ShowParticleSource_noFocus(); } } void MainWindow::on_pbAddSource_clicked() { - AParticleSourceRecord* s = new AParticleSourceRecord(); - s->GunParticles << new GunParticleStruct(); - ParticleSources->append(s); + AParticleSourceRecord* s = new AParticleSourceRecord(); + s->GunParticles << new GunParticleStruct(); + ParticleSources->append(s); - on_pbUpdateSourcesIndication_clicked(); - ui->lwDefinedParticleSources->setCurrentRow( ParticleSources->size()-1 ); - on_pbEditParticleSource_clicked(); + on_pbUpdateSourcesIndication_clicked(); + ui->lwDefinedParticleSources->setCurrentRow( ParticleSources->size()-1 ); + on_pbEditParticleSource_clicked(); } -#include void MainWindow::on_pbUpdateSourcesIndication_clicked() { - qDebug() << "Update sources indication. Defined sources:"<size(); - int numSources = ParticleSources->size(); int curRow = ui->lwDefinedParticleSources->currentRow(); @@ -385,15 +392,25 @@ void MainWindow::on_pbUpdateSourcesIndication_clicked() void MainWindow::on_pbGunShowSource_toggled(bool checked) { if (checked) - { + { GeometryWindow->ShowAndFocus(); ShowParticleSource_noFocus(); - } + } else - { + { Detector->GeoManager->ClearTracks(); GeometryWindow->ShowGeometry(); - } + } +} + +void MainWindow::on_lwDefinedParticleSources_itemDoubleClicked(QListWidgetItem *) +{ + on_pbEditParticleSource_clicked(); +} + +void MainWindow::on_lwDefinedParticleSources_itemClicked(QListWidgetItem *) +{ + if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); } void MainWindow::ShowParticleSource_noFocus() @@ -410,63 +427,75 @@ void MainWindow::ShowParticleSource_noFocus() void MainWindow::on_pbSaveParticleSource_clicked() { - QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; - QString fileName = QFileDialog::getSaveFileName(this, "Export particle source", starter, "Json files (*.json)"); - if (fileName.isEmpty()) return; - QFileInfo file(fileName); - if (file.suffix().isEmpty()) fileName += ".json"; - QJsonObject json, js; - ParticleSources->writeSourceToJson(ui->lwDefinedParticleSources->currentRow(), json); - js["ParticleSource"] = json; - bool bOK = SaveJsonToFile(js, fileName); - if (!bOK) message("Failed to save json to file: "+fileName, this); + int isource = ui->lwDefinedParticleSources->currentRow(); + if (isource == -1) + { + message("Select a source to remove", this); + return; + } + if (isource >= ParticleSources->size()) + { + message("Error - bad source index!", this); + return; + } + + QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; + QString fileName = QFileDialog::getSaveFileName(this, "Save particle source", starter, "Json files (*.json)"); + if (fileName.isEmpty()) return; + QFileInfo file(fileName); + if (file.suffix().isEmpty()) fileName += ".json"; + + QJsonObject json, js; + ParticleSources->writeSourceToJson(isource, json); + js["ParticleSource"] = json; + bool bOK = SaveJsonToFile(js, fileName); + if (!bOK) message("Failed to save json to file: "+fileName, this); } void MainWindow::on_pbLoadParticleSource_clicked() { - QMessageBox msgBox(this); - msgBox.setText("You are about to replace this source with a source from a file."); - msgBox.setInformativeText("Proceed?"); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - int ret = msgBox.exec(); - if (ret == QMessageBox::Cancel) return; - - QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; - QString fileName = QFileDialog::getOpenFileName(this, "Import particle source", starter, "json files (*.json)"); - if (fileName.isEmpty()) return; - int iSource = ui->lwDefinedParticleSources->currentRow(); - QJsonObject json, js; - bool ok = LoadJsonFromFile(json, fileName); - if (!ok) - { - message("Cannot open file: "+fileName, this); - return; - } - if (!json.contains("ParticleSource")) + QString starter = (GlobSet.LibParticleSources.isEmpty()) ? GlobSet.LastOpenDir : GlobSet.LibParticleSources; + QString fileName = QFileDialog::getOpenFileName(this, "Import particle source", starter, "json files (*.json)"); + if (fileName.isEmpty()) return; + + QJsonObject json, js; + bool ok = LoadJsonFromFile(json, fileName); + if (!ok) { - message("Json file format error", this); - return; + message("Cannot open file: "+fileName, this); + return; + } + if (!json.contains("ParticleSource")) + { + message("Json file format error", this); + return; } - int oldPartCollSize = Detector->MpCollection->countParticles(); - js = json["ParticleSource"].toObject(); - ParticleSources->readSourceFromJson(iSource, js); - onRequestDetectorGuiUpdate(); + int oldPartCollSize = Detector->MpCollection->countParticles(); + js = json["ParticleSource"].toObject(); - int newPartCollSize = Detector->MpCollection->countParticles(); - if (oldPartCollSize != newPartCollSize) + ParticleSources->append(new AParticleSourceRecord()); + ParticleSources->readSourceFromJson(ParticleSources->size()-1, js); + + onRequestDetectorGuiUpdate(); + on_pbUpdateSimConfig_clicked(); + + int newPartCollSize = Detector->MpCollection->countParticles(); + if (oldPartCollSize != newPartCollSize) { - //qDebug() << oldPartCollSize <<"->"<1) str += "s were"; - else str += " was"; - str += " added:\n"; - for (int i=oldPartCollSize; iMpCollection->getParticleName(i) + "\n"; - str += "\nSet the interaction data for the detector materials!"; - message(str,this); + //qDebug() << oldPartCollSize <<"->"<1) str += "s were"; + else str += " was"; + str += " added:\n"; + for (int i=oldPartCollSize; iMpCollection->getParticleName(i) + "\n"; + str += "\nSet the interaction data for the detector materials!"; + message(str,this); } + + ui->lwDefinedParticleSources->setCurrentRow(ui->lwDefinedParticleSources->count()-1); + if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); } void MainWindow::on_pbSingleSourceShow_clicked() @@ -687,7 +716,5 @@ void MainWindow::on_pbEditParticleSource_clicked() } on_pbUpdateSimConfig_clicked(); - if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); - //qDebug() << "...update sources done"; } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 9e02315b..029a8ec9 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -597,6 +597,10 @@ private slots: void on_pbEditParticleSource_clicked(); + void on_lwDefinedParticleSources_itemDoubleClicked(QListWidgetItem *item); + + void on_lwDefinedParticleSources_itemClicked(QListWidgetItem *item); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index d6dd9cbb..3d4a06b6 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 1 + 0 @@ -5049,7 +5049,7 @@ of the refracted beam: - 1 + 0 @@ -9705,8 +9705,8 @@ double events: 430 - 53 - 60 + 50 + 70 23 @@ -9760,8 +9760,8 @@ double events: - 114 - 0 + 130 + -1 141 20 @@ -9782,9 +9782,9 @@ double events: - 260 + 276 0 - 54 + 41 20 @@ -9801,7 +9801,7 @@ double events: - 30 + 24 0 80 19 @@ -9828,8 +9828,8 @@ double events: - 10 - 193 + 7 + 194 198 18 @@ -9849,7 +9849,7 @@ double events: 7 22 - 411 + 417 161 @@ -9861,8 +9861,8 @@ double events: 430 - 83 - 60 + 77 + 70 23 @@ -9880,8 +9880,8 @@ double events: 430 - 110 - 60 + 108 + 70 23 @@ -9892,7 +9892,7 @@ double events: - Export + Save @@ -9900,7 +9900,7 @@ double events: 430 130 - 60 + 70 23 @@ -9919,7 +9919,7 @@ double events: 430 23 - 60 + 70 23 @@ -9927,6 +9927,28 @@ double events: Edit + + + + 430 + 160 + 70 + 23 + + + + + 50 + false + + + + Show + + + true + + cbGunAllowMultipleEvents pbUpdateSourcesIndication pbAddSource @@ -9937,6 +9959,7 @@ double events: pbSaveParticleSource pbLoadParticleSource pbEditParticleSource + pbGunShowSource @@ -9993,28 +10016,6 @@ double events: Test generator - - - - 32 - 268 - 120 - 23 - - - - - 50 - false - - - - Show geometry - - - true - - @@ -10040,7 +10041,6 @@ double events: tabWidget_3 sbGunTestEvents pbGunTest - pbGunShowSource lSourceActive From 5f2e5b0902337f7baaaf6e3c9d33b19bef412e26 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 16 Oct 2018 19:00:12 +0100 Subject: [PATCH 084/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 4 + .../MainWindowParticleSimulation.cpp | 18 +- src/gui/MainWindowTools/mainwindowjson.cpp | 2 +- src/gui/mainwindow.ui | 174 +++++++++++------- 4 files changed, 129 insertions(+), 69 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index e111b202..b2b7b69a 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -232,6 +232,10 @@ MainWindow::MainWindow(DetectorClass *Detector, ui->labReloadRequired->setPixmap(Rwindow->RedIcon.pixmap(16,16)); ui->labAdvancedOn->setPixmap(Rwindow->YellowIcon.pixmap(16,16)); ui->labAdvancedOn->setVisible(false); + ui->labIgnoreNoHitEvents->setPixmap(Rwindow->YellowIcon.pixmap(16,16)); + ui->labIgnoreNoHitEvents->setVisible(false); + ui->labIgnoreNoDepoEvents->setPixmap(Rwindow->YellowIcon.pixmap(16,16)); + ui->labIgnoreNoDepoEvents->setVisible(false); //misc gui inits ui->swPMTvsSiPM->setCurrentIndex(ui->cobPMdeviceType->currentIndex()); MainWindow::on_pbRefreshPMproperties_clicked(); //indication of PM properties diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index b86f06ff..1f684c18 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -227,14 +227,24 @@ void MainWindow::ShowSource(const AParticleSourceRecord* p, bool clear) void MainWindow::on_pbGunTest_clicked() { - MainWindow::on_pbGunShowSource_toggled(true); - TestParticleGun(ParticleSources, ui->sbGunTestEvents->value()); + GeometryWindow->ShowAndFocus(); + gGeoManager->ClearTracks(); + + if (ui->pbGunShowSource->isChecked()) + { + for (int i=0; isize(); i++) + ShowSource(ParticleSources->getSource(i), false); + } + + TestParticleGun(ParticleSources, ui->sbGunTestEvents->value()); } void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numParticles) { ParticleSources->Init(); + + double Length = std::max(Detector->WorldSizeXY, Detector->WorldSizeZ)*0.4; double R[3], K[3]; for (int iRun=0; iRun* GP = ParticleSources->GenerateEvent(); if (GP->isEmpty() && iRun > 2) { - message("Did several attempts but no particles were generated!", this); - return; + message("Did several attempts but no particles were generated!", this); + return; } for (GeneratedParticleStructure& p : *GP) { diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 3bb2f5b1..20b8816a 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -578,7 +578,7 @@ if (scj.contains("CustomDistrib")) //JsonToCheckbox(csjs, "PhotonTracks", ui->cbBuilPhotonTrackstester); ui->cbIgnoreEventsWithNoHits->setChecked(false);//compatibility JsonToCheckbox(csjs, "IgnoreNoHitsEvents", ui->cbIgnoreEventsWithNoHits); - ui->cbIgnoreEventsWithNoEnergyDepo->setChecked(true);//compatibility + ui->cbIgnoreEventsWithNoEnergyDepo->setChecked(false); JsonToCheckbox(csjs, "IgnoreNoDepoEvents", ui->cbIgnoreEventsWithNoEnergyDepo); //particle sources diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 3d4a06b6..329e83ff 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 0 + 1 @@ -5049,7 +5049,7 @@ of the refracted beam: - 0 + 1 @@ -9581,9 +9581,9 @@ double events: - 38 + 33 304 - 210 + 191 17 @@ -9603,7 +9603,7 @@ double events: - 240 + 266 304 271 17 @@ -9961,21 +9961,21 @@ double events: pbEditParticleSource pbGunShowSource - + - From script + From file - + - From file + From script - 271 + 280 269 81 20 @@ -10000,9 +10000,9 @@ double events: - 164 - 268 - 101 + 143 + 267 + 131 24 @@ -10016,11 +10016,24 @@ double events: Test generator - + - 370 - 273 + 16 + 304 + 21 + 16 + + + + -- + + + + + + 250 + 304 21 16 @@ -10034,14 +10047,15 @@ double events: cbGunDoS2 label_253 pbParticleSourcesSimulate - cbIgnoreEventsWithNoHits - cbIgnoreEventsWithNoEnergyDepo sbGunEvents pbTrackOptionsGun tabWidget_3 sbGunTestEvents pbGunTest - lSourceActive + labIgnoreNoHitEvents + labIgnoreNoDepoEvents + cbIgnoreEventsWithNoEnergyDepo + cbIgnoreEventsWithNoHits @@ -13026,8 +13040,8 @@ on stack click() - 224 - 518 + 226 + 540 280 @@ -13682,8 +13696,8 @@ on stack click() - 293 - 360 + 295 + 382 467 @@ -13698,8 +13712,8 @@ on stack click() - 179 - 452 + 181 + 474 460 @@ -13714,8 +13728,8 @@ on stack click() - 441 - 421 + 443 + 443 447 @@ -13730,8 +13744,8 @@ on stack click() - 441 - 450 + 443 + 472 500 @@ -13746,8 +13760,8 @@ on stack click() - 441 - 450 + 443 + 472 502 @@ -13762,8 +13776,8 @@ on stack click() - 293 - 360 + 295 + 382 464 @@ -13778,8 +13792,8 @@ on stack click() - 163 - 360 + 165 + 382 464 @@ -13794,8 +13808,8 @@ on stack click() - 317 - 420 + 319 + 442 510 @@ -15362,8 +15376,8 @@ on stack click() - 176 - 460 + 179 + 443 46 @@ -15378,8 +15392,8 @@ on stack click() - 472 - 463 + 494 + 445 113 @@ -15426,8 +15440,8 @@ on stack setCurrentIndex(int) - 179 - 452 + 181 + 474 310 @@ -15458,8 +15472,8 @@ on stack click() - 249 - 450 + 251 + 472 498 @@ -15474,8 +15488,8 @@ on stack click() - 233 - 436 + 235 + 458 485 @@ -15490,8 +15504,8 @@ on stack click() - 233 - 474 + 235 + 496 499 @@ -15506,8 +15520,8 @@ on stack click() - 174 - 360 + 180 + 382 424 @@ -15522,8 +15536,8 @@ on stack setCurrentIndex(int) - 237 - 420 + 241 + 442 427 @@ -15538,8 +15552,8 @@ on stack click() - 390 - 457 + 392 + 479 486 @@ -15554,8 +15568,8 @@ on stack click() - 239 - 420 + 241 + 442 443 @@ -15635,7 +15649,7 @@ on stack 269 - 462 + 444 83 @@ -15746,8 +15760,8 @@ on stack click() - 249 - 473 + 251 + 495 412 @@ -15762,8 +15776,8 @@ on stack click() - 130 - 360 + 136 + 382 399 @@ -15778,8 +15792,8 @@ on stack click() - 292 - 452 + 298 + 474 434 @@ -15835,5 +15849,37 @@ on stack + + cbIgnoreEventsWithNoHits + toggled(bool) + labIgnoreNoHitEvents + setVisible(bool) + + + 115 + 505 + + + 29 + 509 + + + + + cbIgnoreEventsWithNoEnergyDepo + toggled(bool) + labIgnoreNoDepoEvents + setVisible(bool) + + + 295 + 505 + + + 266 + 510 + + + From 92d9002b64d465a62beb945284ad0bc285d8e5f3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Oct 2018 09:35:20 +0100 Subject: [PATCH 085/140] ++ --- src/ants2.pro | 3 +- src/common/aconfiguration.cpp | 4 +- src/common/aparticlegun.h | 30 ++++++++++++++ .../MainWindowParticleSimulation.cpp | 4 +- src/modules/particlesourcesclass.cpp | 41 +++++++++++-------- src/modules/particlesourcesclass.h | 40 +++++------------- src/modules/simulationmanager.cpp | 4 +- 7 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 src/common/aparticlegun.h diff --git a/src/ants2.pro b/src/ants2.pro index 70d2bdf1..ec1d6be0 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -490,7 +490,8 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/spectralbasicopticaloverride.h \ OpticalOverrides/abasicopticaloverride.h \ common/aglobalsettings.h \ - common/aparticlesourcerecord.h + common/aparticlesourcerecord.h \ + common/aparticlegun.h # --- SIM --- ants2_SIM { diff --git a/src/common/aconfiguration.cpp b/src/common/aconfiguration.cpp index 77c9c50d..956f3df7 100644 --- a/src/common/aconfiguration.cpp +++ b/src/common/aconfiguration.cpp @@ -370,8 +370,8 @@ const QString AConfiguration::RemoveParticle(int particleId) Detector->MpCollection->IsParticleInUse(particleId, bInUse, s); if (bInUse) return "This particle is a secondary particle defined in neutron capture.\nIt appears in the following material(s):\n"+s; - ParticleSources->IsParticleInUse(particleId, bInUse, s); - if (bInUse) return "This particle is in use by the particle source(s):\n" + s; + if ( ParticleSources->IsParticleInUse(particleId, s) ) + return "This particle is in use by the particle source(s):\n" + s; Detector->Sandwich->IsParticleInUse(particleId, bInUse, s); if (bInUse) return "This particle is currently in use by the monitor(s):\n" + s; diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h new file mode 100644 index 00000000..21bdd518 --- /dev/null +++ b/src/common/aparticlegun.h @@ -0,0 +1,30 @@ +#ifndef APARTICLEGUN_H +#define APARTICLEGUN_H + +#include + +class AGeneratedParticle +{ +public: + int ParticleId; + double Energy; + double Position[3]; + double Direction[3]; +}; + +class AParticleGun +{ +public: + virtual ~AParticleGun(){} + + virtual void Init() {} //called before first use + virtual void ReleaseResources() {} //called after end of operation + virtual QVector* GenerateEvent() = 0; + + virtual bool CheckConfiguration() {return true;} //check consistency of the configuration + + virtual void RemoveParticle(int particleId) = 0; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first + virtual bool IsParticleInUse(int particleId, QString& SourceNames) const = 0; +}; + +#endif // APARTICLEGUN_H diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 1f684c18..caa74956 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -249,13 +249,13 @@ void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numP double R[3], K[3]; for (int iRun=0; iRun* GP = ParticleSources->GenerateEvent(); + QVector* GP = ParticleSources->GenerateEvent(); if (GP->isEmpty() && iRun > 2) { message("Did several attempts but no particles were generated!", this); return; } - for (GeneratedParticleStructure& p : *GP) + for (AGeneratedParticle& p : *GP) { R[0] = p.Position[0]; R[1] = p.Position[1]; diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index a6514c27..50ac990f 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -109,11 +109,11 @@ void ParticleSourcesClass::Init() } } -QVector* ParticleSourcesClass::GenerateEvent() +QVector* ParticleSourcesClass::GenerateEvent() { //after any operation with sources (add, remove), init should be called before first use! - QVector* GeneratedParticles = new QVector; + QVector* GeneratedParticles = new QVector; //selecting the source int isource = 0; @@ -225,7 +225,7 @@ QVector* ParticleSourcesClass::GenerateEvent() for (int i=0; iGunParticles[thisParticle]->ParticleId; //if (ParticleSourcesData[isource]->GunParticles[thisParticle]->spectrum == 0) // ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->energy; @@ -372,9 +372,9 @@ void ParticleSourcesClass::GeneratePosition(int isource, double *R) const return; } -void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const +void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const { - GeneratedParticleStructure ps; + AGeneratedParticle ps; ps.ParticleId = ParticleSourcesData[isource]->GunParticles[iparticle]->ParticleId; @@ -414,23 +414,30 @@ TVector3 ParticleSourcesClass::GenerateRandomDirection() return TVector3(a*scale, b*scale, -1.0 + 8.0 * r2 ); } -void ParticleSourcesClass::IsParticleInUse(int particleId, bool &bInUse, QString &SourceNames) +#include +bool ParticleSourcesClass::IsParticleInUse(int particleId, QString &SourceNames) const { - bInUse = false; - SourceNames.clear(); + SourceNames.clear(); + QSet sources; - for (int isource=0; isourceGunParticles.size(); ip++) + for (int ip = 0; ip < ps->GunParticles.size(); ip++) { - if ( particleId == ps->GunParticles[ip]->ParticleId ) - { - bInUse = true; - if (!SourceNames.isEmpty()) SourceNames += ", "; - SourceNames += ps->name; - } + if ( particleId == ps->GunParticles[ip]->ParticleId ) + sources << ps->name; + } + } + + if (sources.isEmpty()) return false; + else + { + for (const QString& s : sources) + { + if (!SourceNames.isEmpty()) SourceNames += ", "; + SourceNames += s; } + return true; } } diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index bfc035e9..837dcebf 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -1,6 +1,8 @@ #ifndef PARTICLESOURCESCLASS_H #define PARTICLESOURCESCLASS_H +#include "aparticlegun.h" + #include #include #include "TVector3.h" @@ -11,15 +13,6 @@ class TRandom2; class DetectorClass; struct AParticleSourceRecord; -class GeneratedParticleStructure -{ -public: - int ParticleId; - double Energy; - double Position[3]; - double Direction[3]; -}; - class LinkedParticleStructure { public: @@ -30,25 +23,18 @@ class LinkedParticleStructure LinkedParticleStructure(int iparticle, int linkedto = -1) {iParticle = iparticle; LinkedTo = linkedto;} }; -/* -class AParticleGun -{ - virtual ~AParticleGenerator(){} - - virtual void Init() = 0; - virtual QVector* GenerateEvent() const = 0; -}; -*/ - -class ParticleSourcesClass +class ParticleSourcesClass : public AParticleGun { public: ParticleSourcesClass(const DetectorClass* Detector, TRandom2* RandGen); - ~ParticleSourcesClass(); + ~ParticleSourcesClass(); - //MAIN usage - void Init(); // !!! has to be called before the first use of "GenerateEvent"! - QVector* GenerateEvent(); //see Init!!! + virtual void Init() override; // !!! has to be called before the first use of "GenerateEvent"! + virtual QVector* GenerateEvent() override; //see Init!!! + + //for remove particle from configuration + virtual void RemoveParticle(int particleId) override; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first + virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; //requests int size() {return ParticleSourcesData.size();} @@ -78,10 +64,6 @@ class ParticleSourcesClass TVector3 GenerateRandomDirection(); void checkLimitedToMaterial(AParticleSourceRecord *s); - //for remove particle from configuration - void RemoveParticle(int particleId); //should NOT be used to remove one of particles in use! use onIsPareticleInUse first - void IsParticleInUse(int particleId, bool& bInUse, QString& SourceNames); - private: //external resources - pointers const DetectorClass* Detector; @@ -101,7 +83,7 @@ class ParticleSourcesClass //utilities void CalculateTotalActivity(); void GeneratePosition(int isource, double *R) const; - void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! + void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! }; #endif // PARTICLESOURCESCLASS_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 5e08d588..a2d7e0bc 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1532,14 +1532,14 @@ void ParticleSourceSimulator::simulate() for(int iRun = 0; iRun < ParticleRunsThisEvent; iRun++) { //generating one event - QVector* GP = ParticleSources->GenerateEvent(); + QVector* GP = ParticleSources->GenerateEvent(); //adding particles to the stack for (int iPart = 0; iPart < GP->size(); iPart++ ) { if(iRun > 0 && timeRange != 0) time = timeFrom + timeRange*RandGen->Rndm(); //added TimeFrom 05/02/2015 - const GeneratedParticleStructure &part = GP->at(iPart); + const AGeneratedParticle &part = GP->at(iPart); ParticleStack.append(new AParticleOnStack(part.ParticleId, part.Position[0], part.Position[1], part.Position[2], part.Direction[0], part.Direction[1], part.Direction[2], From e9ac283c0985b61597196cab23c5746f6d890955 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Oct 2018 10:03:24 +0100 Subject: [PATCH 086/140] ++ --- src/ants2.pro | 8 ++- src/common/aparticlegun.h | 2 +- src/modules/afileparticlegenerator.cpp | 64 ++++++++++++++++++++++++ src/modules/afileparticlegenerator.h | 36 +++++++++++++ src/modules/ascriptparticlegenerator.cpp | 28 +++++++++++ src/modules/ascriptparticlegenerator.h | 22 ++++++++ src/modules/particlesourcesclass.cpp | 3 +- src/modules/particlesourcesclass.h | 2 +- 8 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 src/modules/afileparticlegenerator.cpp create mode 100644 src/modules/afileparticlegenerator.h create mode 100644 src/modules/ascriptparticlegenerator.cpp create mode 100644 src/modules/ascriptparticlegenerator.h diff --git a/src/ants2.pro b/src/ants2.pro index ec1d6be0..d4cc3133 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -357,7 +357,9 @@ SOURCES += main.cpp \ OpticalOverrides/spectralbasicopticaloverride.cpp \ OpticalOverrides/abasicopticaloverride.cpp \ common/aglobalsettings.cpp \ - common/aparticlesourcerecord.cpp + common/aparticlesourcerecord.cpp \ + modules/ascriptparticlegenerator.cpp \ + modules/afileparticlegenerator.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -491,7 +493,9 @@ HEADERS += common/CorrelationFilters.h \ OpticalOverrides/abasicopticaloverride.h \ common/aglobalsettings.h \ common/aparticlesourcerecord.h \ - common/aparticlegun.h + common/aparticlegun.h \ + modules/ascriptparticlegenerator.h \ + modules/afileparticlegenerator.h # --- SIM --- ants2_SIM { diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 21bdd518..44092a33 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -17,7 +17,7 @@ class AParticleGun public: virtual ~AParticleGun(){} - virtual void Init() {} //called before first use + virtual bool Init() = 0; //called before first use virtual void ReleaseResources() {} //called after end of operation virtual QVector* GenerateEvent() = 0; diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp new file mode 100644 index 00000000..c38c1c4b --- /dev/null +++ b/src/modules/afileparticlegenerator.cpp @@ -0,0 +1,64 @@ +#include "afileparticlegenerator.h" + +#include +#include +#include + +AFileParticleGenerator::AFileParticleGenerator(const QString &FileName) : + FileName(FileName) {} + +void AFileParticleGenerator::Init() +{ + File.setFileName(FileName); + if(!File.open(QIODevice::ReadOnly | QFile::Text)) + { + qWarning() << "Could not open: " << FileName; + return false; + } + + Stream = new QTextStream(&file); + return true; +} + +void AFileParticleGenerator::ReleaseResources() +{ + delete Stream; Stream = 0; + File.close(); +} + +QVector * AFileParticleGenerator::GenerateEvent() +{ + QVector* GeneratedParticles = new QVector; + + QRegExp rx("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' + + /* + x->resize(0); + + while(!in.atEnd()) + { + QString line = in.readLine(); + QStringList fields = line.split(rx, QString::SkipEmptyParts); + + bool ok1= false; + double xx; + if (fields.size()>0) xx = fields[0].toDouble(&ok1); //*** potential problem with decimal separator! + + if (ok1) + { + x->append(xx); + } + } + */ + return GeneratedParticles; +} + +bool AFileParticleGenerator::CheckConfiguration() +{ + return true; //TODO +} + +bool AFileParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const +{ + return false; //TODO +} diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h new file mode 100644 index 00000000..07d956e6 --- /dev/null +++ b/src/modules/afileparticlegenerator.h @@ -0,0 +1,36 @@ +#ifndef AFILEPARTICLEGENERATOR_H +#define AFILEPARTICLEGENERATOR_H + +#include "aparticlegun.h" + +#include +#include + +class QTextStream; + +class AFileParticleGenerator : public AParticleGun +{ +public: + AFileParticleGenerator(const QString& FileName); + virtual ~AFileParticleGenerator(){} + + virtual void Init() override; //called before first use + virtual void ReleaseResources() override; //called after end of operation + virtual QVector* GenerateEvent(); + + virtual bool CheckConfiguration() override; //check consistency of the configuration + + virtual void RemoveParticle(int particleId) override {} //cannot be used for this class + virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; + +private: + const QString FileName; + QFile File; + + QTextStream* Stream = 0; + +private: + //bool readLine(); +}; + +#endif // AFILEPARTICLEGENERATOR_H diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp new file mode 100644 index 00000000..73b864b0 --- /dev/null +++ b/src/modules/ascriptparticlegenerator.cpp @@ -0,0 +1,28 @@ +#include "ascriptparticlegenerator.h" + +AScriptParticleGenerator::AScriptParticleGenerator() +{ + +} + +bool AScriptParticleGenerator::Init() +{ + return true; +} + +QVector *AScriptParticleGenerator::GenerateEvent() +{ + QVector* GeneratedParticles = new QVector; + + return GeneratedParticles; +} + +void AScriptParticleGenerator::RemoveParticle(int particleId) +{ + //TODO +} + +bool AScriptParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const +{ + return false; //TODO +} diff --git a/src/modules/ascriptparticlegenerator.h b/src/modules/ascriptparticlegenerator.h new file mode 100644 index 00000000..92460ad0 --- /dev/null +++ b/src/modules/ascriptparticlegenerator.h @@ -0,0 +1,22 @@ +#ifndef ASCRIPTPARTICLEGENERATOR_H +#define ASCRIPTPARTICLEGENERATOR_H + +#include "aparticlegun.h" + +class AScriptParticleGenerator : public AParticleGun +{ +public: + AScriptParticleGenerator(); + virtual ~AScriptParticleGenerator(){} + + virtual bool Init() override; //called before first use + //virtual void ReleaseResources() override {} //called after end of operation + virtual QVector* GenerateEvent(); + + // virtual bool CheckConfiguration() override {return true;} //check consistency of the configuration + + virtual void RemoveParticle(int particleId) override; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first + virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; +}; + +#endif // ASCRIPTPARTICLEGENERATOR_H diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 50ac990f..0cf7cb25 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -34,7 +34,7 @@ void ParticleSourcesClass::clear() TotalActivity = 0; } -void ParticleSourcesClass::Init() +bool ParticleSourcesClass::Init() { int NumSources = ParticleSourcesData.size(); CalculateTotalActivity(); @@ -107,6 +107,7 @@ void ParticleSourcesClass::Init() CollimationProbability[isource] = 0.5 * (1.0 - cos(Spread)); //CollimationSpreadProduct[isource] = cos(Spread); //scalar product of coll direction and max spread unit vectors } + return true; //TODO check for fails } QVector* ParticleSourcesClass::GenerateEvent() diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 837dcebf..6c21ba86 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -29,7 +29,7 @@ class ParticleSourcesClass : public AParticleGun ParticleSourcesClass(const DetectorClass* Detector, TRandom2* RandGen); ~ParticleSourcesClass(); - virtual void Init() override; // !!! has to be called before the first use of "GenerateEvent"! + virtual bool Init() override; // !!! has to be called before the first use of "GenerateEvent"! virtual QVector* GenerateEvent() override; //see Init!!! //for remove particle from configuration From 3caed935b60e9cee8c0e290748eb9b54023cc7c7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Oct 2018 11:56:23 +0100 Subject: [PATCH 087/140] ++ --- src/common/aparticlegun.h | 12 +++ .../MainWindowParticleSimulation.cpp | 22 +++++ src/gui/mainwindow.cpp | 1 + src/gui/mainwindow.h | 8 ++ src/gui/mainwindow.ui | 90 ++++++++++++++++++- src/modules/afileparticlegenerator.cpp | 40 +++++---- src/modules/afileparticlegenerator.h | 4 +- 7 files changed, 157 insertions(+), 20 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 44092a33..3fbd61fa 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -6,6 +6,18 @@ class AGeneratedParticle { public: + AGeneratedParticle(int pId, double energy, double x, double y, double z, double vx, double vy, double vz) : + ParticleId(pId), Energy(energy) + { + Position[0] = x; + Position[1] = y; + Position[2] = z; + Direction[0] = vx; + Direction[1] = vy; + Direction[2] = vz; + } + AGeneratedParticle(){} + int ParticleId; double Energy; double Position[3]; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index caa74956..9f4411f8 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -728,3 +728,25 @@ void MainWindow::on_pbEditParticleSource_clicked() on_pbUpdateSimConfig_clicked(); if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); } + +// ---- from file ---- + +void MainWindow::on_pbGenerateFromFile_Help_clicked() +{ + +} + +void MainWindow::on_pbGenerateFromFile_Change_clicked() +{ + +} + +void MainWindow::on_leGenerateFromFile_FileName_editingFinished() +{ + +} + +void MainWindow::on_pbGenerateFromFile_Check_clicked() +{ + +} diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 18d7603e..297237cc 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4971,3 +4971,4 @@ void MainWindow::on_pbPMtypeHelp_clicked() " represent the photocathode."; message(s, this); } + diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 029a8ec9..92a10164 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -601,6 +601,14 @@ private slots: void on_lwDefinedParticleSources_itemClicked(QListWidgetItem *item); + void on_pbGenerateFromFile_Help_clicked(); + + void on_pbGenerateFromFile_Change_clicked(); + + void on_leGenerateFromFile_FileName_editingFinished(); + + void on_pbGenerateFromFile_Check_clicked(); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 329e83ff..fb405020 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9676,7 +9676,7 @@ double events: - 0 + 1 @@ -9965,6 +9965,94 @@ double events: From file + + + + 20 + 20 + 281 + 16 + + + + Generate event from file: + + + + + + 10 + 40 + 421 + 20 + + + + + + + 431 + 38 + 71 + 23 + + + + Change + + + + + + 431 + 0 + 75 + 23 + + + + ? + + + + + + 10 + 70 + 101 + 23 + + + + Check file + + + + + + 60 + 100 + 47 + 13 + + + + File info: + + + + + + 60 + 120 + 47 + 13 + + + + ... + + diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index c38c1c4b..157e3504 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -3,11 +3,12 @@ #include #include #include +#include AFileParticleGenerator::AFileParticleGenerator(const QString &FileName) : FileName(FileName) {} -void AFileParticleGenerator::Init() +bool AFileParticleGenerator::Init() { File.setFileName(FileName); if(!File.open(QIODevice::ReadOnly | QFile::Text)) @@ -16,7 +17,7 @@ void AFileParticleGenerator::Init() return false; } - Stream = new QTextStream(&file); + Stream = new QTextStream(&File); return true; } @@ -30,26 +31,29 @@ QVector * AFileParticleGenerator::GenerateEvent() { QVector* GeneratedParticles = new QVector; - QRegExp rx("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' + while(!Stream->atEnd()) + { + const QString line = Stream->readLine(); + QStringList f = line.split(rx, QString::SkipEmptyParts); + //format: ParticleId Energy X Y Z VX VY VZ * //'*' is optional - indicates event not finished yet + + if (f.size() < 8) continue; - /* - x->resize(0); + int pId = f.at(0).toInt(); //TODO index check + double energy = f.at(1).toDouble(); + double x = f.at(2).toDouble(); + double y = f.at(3).toDouble(); + double z = f.at(4).toDouble(); + double vx = f.at(5).toDouble(); + double vy = f.at(6).toDouble(); + double vz = f.at(7).toDouble(); - while(!in.atEnd()) - { - QString line = in.readLine(); - QStringList fields = line.split(rx, QString::SkipEmptyParts); + (*GeneratedParticles) << AGeneratedParticle(pId, energy, x, y, z, vx, vy, vz); - bool ok1= false; - double xx; - if (fields.size()>0) xx = fields[0].toDouble(&ok1); //*** potential problem with decimal separator! + if (f.size() > 8 && f.at(8) == '*') continue; + break; + } - if (ok1) - { - x->append(xx); - } - } - */ return GeneratedParticles; } diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 07d956e6..abea97b6 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -5,6 +5,7 @@ #include #include +#include class QTextStream; @@ -14,7 +15,7 @@ class AFileParticleGenerator : public AParticleGun AFileParticleGenerator(const QString& FileName); virtual ~AFileParticleGenerator(){} - virtual void Init() override; //called before first use + virtual bool Init() override; //called before first use virtual void ReleaseResources() override; //called after end of operation virtual QVector* GenerateEvent(); @@ -26,6 +27,7 @@ class AFileParticleGenerator : public AParticleGun private: const QString FileName; QFile File; + QRegularExpression rx = QRegularExpression("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' QTextStream* Stream = 0; From 253d1dd4a4697dc9a84b29ef2bcde39c8a67e3f8 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 17 Oct 2018 13:41:07 +0100 Subject: [PATCH 088/140] ++ --- .../MainWindowParticleSimulation.cpp | 20 +++++++ src/gui/mainwindow.ui | 6 +-- src/modules/afileparticlegenerator.cpp | 54 +++++++++++++++++++ src/modules/afileparticlegenerator.h | 15 +++++- 4 files changed, 91 insertions(+), 4 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 9f4411f8..d5de1132 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -746,7 +746,27 @@ void MainWindow::on_leGenerateFromFile_FileName_editingFinished() } +#include "afileparticlegenerator.h" void MainWindow::on_pbGenerateFromFile_Check_clicked() { + ui->labGenerateFromFile_info->setText(""); + int numParticles = MpCollection->countParticles(); + AParticleFileStat stat = AFileParticleGenerator::InspectFile(ui->leGenerateFromFile_FileName->text(), numParticles); + if (!stat.ErrorString.isEmpty()) + { + message(stat.ErrorString, this); + return; + } + + QString s; + s += QString("Events: %1\n").arg(stat.numEvents); + if (stat.numMultipleEvents > 0) s += QString("Multiple events: %1\n").arg(stat.numMultipleEvents); + s += "Particle distribution:\n"; + for (int ip = 0; ip < numParticles; ip++) + { + if (stat.ParticleStat.at(ip) > 0) + s += QString(" %1 - %2\n").arg(MpCollection->getParticleName(ip)).arg(stat.ParticleStat.at(ip)); + } + ui->labGenerateFromFile_info->setText(s); } diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index fb405020..66717a37 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -10045,12 +10045,12 @@ double events: 60 120 - 47 - 13 + 421 + 91 - ... + diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 157e3504..7c6be6c0 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -66,3 +66,57 @@ bool AFileParticleGenerator::IsParticleInUse(int particleId, QString &SourceName { return false; //TODO } + +const AParticleFileStat AFileParticleGenerator::InspectFile(const QString &fname, int ParticleCount) +{ + AParticleFileStat stat; + stat.ParticleStat = QVector(ParticleCount, 0); + + QFile file(fname); + if(!file.open(QIODevice::ReadOnly | QFile::Text)) + { + stat.ErrorString = QString("Cannot open file %1").arg(fname); + return stat; + } + + QRegularExpression rx("(\\ |\\,|\\:|\\t)"); //Not synchronized with the class! + QTextStream in(&file); + bool bContinueEvent = false; + while(!in.atEnd()) + { + const QString line = in.readLine(); + QStringList f = line.split(rx, QString::SkipEmptyParts); + + if (f.size() < 8) continue; + + int pId = f.at(0).toInt(); + if (pId < 0 || pId >= ParticleCount) + { + stat.ErrorString = QString("Invalid particle index %1 in file %2").arg(pId).arg(fname); + return stat; + } + stat.ParticleStat[pId]++; + + /* + double energy = f.at(1).toDouble(); + double x = f.at(2).toDouble(); + double y = f.at(3).toDouble(); + double z = f.at(4).toDouble(); + double vx = f.at(5).toDouble(); + double vy = f.at(6).toDouble(); + double vz = f.at(7).toDouble(); + */ + + if (!bContinueEvent) stat.numEvents++; + + if (f.size() > 8 && f.at(8) == '*') + { + if (!bContinueEvent) stat.numMultipleEvents++; + bContinueEvent = true; + } + else bContinueEvent = false; + } + + file.close(); + return stat; +} diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index abea97b6..9fda6694 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -6,9 +6,19 @@ #include #include #include +#include class QTextStream; +class AParticleFileStat +{ +public: + int numEvents = 0; + int numMultipleEvents = 0; + QVector ParticleStat; + QString ErrorString; +}; + class AFileParticleGenerator : public AParticleGun { public: @@ -27,12 +37,15 @@ class AFileParticleGenerator : public AParticleGun private: const QString FileName; QFile File; - QRegularExpression rx = QRegularExpression("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' + const QRegularExpression rx = QRegularExpression("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' QTextStream* Stream = 0; private: //bool readLine(); + +public: + static const AParticleFileStat InspectFile(const QString& fname, int ParticleCount); //TODO remove static }; #endif // AFILEPARTICLEGENERATOR_H From 63831459927ec5b1cf93f5e9f1845fd0ff896567 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 10:05:18 +0100 Subject: [PATCH 089/140] remove alias for particlesources in main window --- src/EXAMPLES/ExampleParticlesFromFile.dat | 9 +++ src/gui/MainWindowTools/MainWindowInits.cpp | 8 +- .../MainWindowParticleSimulation.cpp | 78 +++++++++++++------ src/gui/MainWindowTools/mainwindowjson.cpp | 9 +-- src/gui/checkupwindowclass.cpp | 5 +- src/gui/mainwindow.cpp | 25 ------ src/gui/mainwindow.h | 1 - src/gui/mainwindow.ui | 21 +---- src/modules/afileparticlegenerator.cpp | 4 +- src/modules/simulationmanager.h | 2 +- 10 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 src/EXAMPLES/ExampleParticlesFromFile.dat diff --git a/src/EXAMPLES/ExampleParticlesFromFile.dat b/src/EXAMPLES/ExampleParticlesFromFile.dat new file mode 100644 index 00000000..46c80df8 --- /dev/null +++ b/src/EXAMPLES/ExampleParticlesFromFile.dat @@ -0,0 +1,9 @@ +format: particleId energy x y z vx vy vz if line ends with *, the next particle is added to the same event +separators can be any number of spaces or tabs +comments are ignored + +0 120 0 0 -10 0 0 1 +2 250 0 0 -10 1 0 1 +1 115 0 0 -10 0 1 1 +0 511 0 0 0 0 0 1 * +0 511 0 0 0 0 0 -1 \ No newline at end of file diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index b2b7b69a..025d6f28 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -20,7 +20,7 @@ #include "detectorclass.h" #include "simulationmanager.h" #include "areconstructionmanager.h" -#include "particlesourcesclass.h" +//#include "particlesourcesclass.h" #include "aglobalsettings.h" #include "globalsettingswindowclass.h" #include "aconfiguration.h" @@ -74,14 +74,14 @@ MainWindow::MainWindow(DetectorClass *Detector, QString mav = QString::number(majVer); setWindowTitle("ANTS2_v"+mav+"."+miv); + QString epff = GlobSet.ExamplesDir + "/ExampleParticlesFromFile.dat"; + ui->leGenerateFromFile_FileName->setText(epff); + //adding Context menus ui->lwLoadedEventsFiles->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(ui->lwLoadedEventsFiles, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(LoadEventsListContextMenu(const QPoint&))); - //setting up alias for particle sources container class - just for GUI - ParticleSources = SimulationManager->ParticleSources; - //interface windows qDebug()<<">Creating Examples Window"; QWidget* w = new QWidget(); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index d5de1132..9467bd54 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -20,6 +20,9 @@ #include "acommonfunctions.h" #include "guiutils.h" #include "aparticlesourcedialog.h" +#include "simulationmanager.h" +#include "exampleswindow.h" +#include "aconfiguration.h" //Qt #include @@ -49,7 +52,7 @@ void MainWindow::SimParticleSourcesConfigToJson(QJsonObject &json) cjs["IgnoreNoDepoEvents"] = ui->cbIgnoreEventsWithNoEnergyDepo->isChecked(); masterjs["SourceControlOptions"] = cjs; //particle sources - ParticleSources->writeToJson(masterjs); + SimulationManager->ParticleSources->writeToJson(masterjs); json["ParticleSourcesConfig"] = masterjs; } @@ -232,11 +235,11 @@ void MainWindow::on_pbGunTest_clicked() if (ui->pbGunShowSource->isChecked()) { - for (int i=0; isize(); i++) - ShowSource(ParticleSources->getSource(i), false); + for (int i=0; iParticleSources->size(); i++) + ShowSource(SimulationManager->ParticleSources->getSource(i), false); } - TestParticleGun(ParticleSources, ui->sbGunTestEvents->value()); + TestParticleGun(SimulationManager->ParticleSources, ui->sbGunTestEvents->value()); } void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numParticles) @@ -296,25 +299,25 @@ void MainWindow::on_pbRemoveSource_clicked() message("Select a source to remove", this); return; } - if (isource >= ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->size()) { message("Error - bad source index!", this); return; } int ret = QMessageBox::question(this, "Remove particle source", - "Are you sure you want to remove source " + ParticleSources->getSource(isource)->name, + "Are you sure you want to remove source " + SimulationManager->ParticleSources->getSource(isource)->name, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); if (ret != QMessageBox::Yes) return; - ParticleSources->remove(isource); + SimulationManager->ParticleSources->remove(isource); on_pbUpdateSimConfig_clicked(); on_pbUpdateSourcesIndication_clicked(); if (ui->pbGunShowSource->isChecked()) { - if (ParticleSources->size() == 0) + if (SimulationManager->ParticleSources->size() == 0) { Detector->GeoManager->ClearTracks(); GeometryWindow->ShowGeometry(false); @@ -328,23 +331,23 @@ void MainWindow::on_pbAddSource_clicked() { AParticleSourceRecord* s = new AParticleSourceRecord(); s->GunParticles << new GunParticleStruct(); - ParticleSources->append(s); + SimulationManager->ParticleSources->append(s); on_pbUpdateSourcesIndication_clicked(); - ui->lwDefinedParticleSources->setCurrentRow( ParticleSources->size()-1 ); + ui->lwDefinedParticleSources->setCurrentRow( SimulationManager->ParticleSources->size()-1 ); on_pbEditParticleSource_clicked(); } void MainWindow::on_pbUpdateSourcesIndication_clicked() { - int numSources = ParticleSources->size(); + int numSources = SimulationManager->ParticleSources->size(); int curRow = ui->lwDefinedParticleSources->currentRow(); ui->lwDefinedParticleSources->clear(); for (int i=0; igetSource(i); + AParticleSourceRecord* pr = SimulationManager->ParticleSources->getSource(i); QListWidgetItem* item = new QListWidgetItem(); ui->lwDefinedParticleSources->addItem(item); @@ -380,7 +383,7 @@ void MainWindow::on_pbUpdateSourcesIndication_clicked() e->setVisible(numSources > 1); l->addWidget(e); - double totAct = ParticleSources->getTotalActivity(); + double totAct = SimulationManager->ParticleSources->getTotalActivity(); double per = ( totAct == 0 ? 0 : 100.0 * pr->Activity / totAct ); QString t = QString("%1%").arg(per, 3, 'g', 3); lab = new QLabel(t); @@ -427,12 +430,12 @@ void MainWindow::ShowParticleSource_noFocus() { int isource = ui->lwDefinedParticleSources->currentRow(); if (isource < 0) return; - if (isource >= ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->size()) { message("Source number is out of bounds!",this); return; } - ShowSource(ParticleSources->getSource(isource), true); + ShowSource(SimulationManager->ParticleSources->getSource(isource), true); } void MainWindow::on_pbSaveParticleSource_clicked() @@ -443,7 +446,7 @@ void MainWindow::on_pbSaveParticleSource_clicked() message("Select a source to remove", this); return; } - if (isource >= ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->size()) { message("Error - bad source index!", this); return; @@ -456,7 +459,7 @@ void MainWindow::on_pbSaveParticleSource_clicked() if (file.suffix().isEmpty()) fileName += ".json"; QJsonObject json, js; - ParticleSources->writeSourceToJson(isource, json); + SimulationManager->ParticleSources->writeSourceToJson(isource, json); js["ParticleSource"] = json; bool bOK = SaveJsonToFile(js, fileName); if (!bOK) message("Failed to save json to file: "+fileName, this); @@ -484,8 +487,8 @@ void MainWindow::on_pbLoadParticleSource_clicked() int oldPartCollSize = Detector->MpCollection->countParticles(); js = json["ParticleSource"].toObject(); - ParticleSources->append(new AParticleSourceRecord()); - ParticleSources->readSourceFromJson(ParticleSources->size()-1, js); + SimulationManager->ParticleSources->append(new AParticleSourceRecord()); + SimulationManager->ParticleSources->readSourceFromJson( SimulationManager->ParticleSources->size()-1, js ); onRequestDetectorGuiUpdate(); on_pbUpdateSimConfig_clicked(); @@ -683,26 +686,26 @@ void MainWindow::on_pbEditParticleSource_clicked() message("Select a source to edit", this); return; } - if (isource >= ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->size()) { message("Error - bad source index!", this); return; } - AParticleSourceDialog d(*this, ParticleSources->getSource(isource)); + AParticleSourceDialog d(*this, SimulationManager->ParticleSources->getSource(isource)); int res = d.exec(); if (res == QDialog::Rejected) return; - ParticleSources->replace(isource, d.getResult()); + SimulationManager->ParticleSources->replace(isource, d.getResult()); - AParticleSourceRecord* ps = ParticleSources->getSource(isource); - ParticleSources->checkLimitedToMaterial(ps); + AParticleSourceRecord* ps = SimulationManager->ParticleSources->getSource(isource); + SimulationManager->ParticleSources->checkLimitedToMaterial(ps); if (Detector->isGDMLempty()) { //check world size double XYm = 0; double Zm = 0; - for (int isource = 0; isource < ParticleSources->size(); isource++) + for (int isource = 0; isource < SimulationManager->ParticleSources->size(); isource++) { double msize = ps->size1; UpdateMax(msize, ps->size2); @@ -729,6 +732,31 @@ void MainWindow::on_pbEditParticleSource_clicked() if (ui->pbGunShowSource->isChecked()) ShowParticleSource_noFocus(); } +void MainWindow::on_pbParticleSourcesSimulate_clicked() +{ + ELwindow->QuickSave(0); + fStartedFromGUI = true; + fSimDataNotSaved = false; // to disable the warning + //watchdog on particle sources, can be transferred later to check-upwindow + if (SimulationManager->ParticleSources->size() == 0) + { + message("No particle sources defined!", this); + return; + } + + for (int i = 0; iParticleSources->size(); i++) + { + int error = SimulationManager->ParticleSources->CheckSource(i); + if (error == 0) continue; + + message("Error in source " + SimulationManager->ParticleSources->getSource(i)->name +":\n\n" + SimulationManager->ParticleSources->getErrorString(error), this); + return; + } + + MainWindow::writeSimSettingsToJson(Config->JSON); + startSimulation(Config->JSON); +} + // ---- from file ---- void MainWindow::on_pbGenerateFromFile_Help_clicked() diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 20b8816a..93bbf345 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -582,8 +582,7 @@ if (scj.contains("CustomDistrib")) JsonToCheckbox(csjs, "IgnoreNoDepoEvents", ui->cbIgnoreEventsWithNoEnergyDepo); //particle sources - ParticleSources->clear(); - ParticleSources->readFromJson(psjs); + SimulationManager->ParticleSources->readFromJson(psjs); on_pbUpdateSourcesIndication_clicked(); //Window CONTROL @@ -632,12 +631,12 @@ if (scj.contains("CustomDistrib")) void MainWindow::selectFirstActiveParticleSource() { - if (ParticleSources->getTotalActivity() > 0) + if (SimulationManager->ParticleSources->getTotalActivity() > 0) { //show the first source with non-zero activity int i = 0; - for (; isize(); i++) - if (ParticleSources->getSource(i)->Activity > 0) break; + for (; iParticleSources->size(); i++) + if (SimulationManager->ParticleSources->getSource(i)->Activity > 0) break; if (i < ui->lwDefinedParticleSources->count()) ui->lwDefinedParticleSources->setCurrentRow(i); diff --git a/src/gui/checkupwindowclass.cpp b/src/gui/checkupwindowclass.cpp index 05dd5c78..6806c494 100644 --- a/src/gui/checkupwindowclass.cpp +++ b/src/gui/checkupwindowclass.cpp @@ -10,6 +10,7 @@ #include "particlesourcesclass.h" #include "aglobalsettings.h" #include "aparticlesourcerecord.h" +#include "simulationmanager.h" #include #include @@ -241,9 +242,9 @@ TriState CheckUpWindowClass::CheckInteractions() int listIndex = ui->listInteraction->count(); //Check all particle sources: if links are valid, if interaction data for a given energy is available - for(int i = 0; i < MW->ParticleSources->size(); i++) + for(int i = 0; i < MW->SimulationManager->ParticleSources->size(); i++) { - AParticleSourceRecord* source = MW->ParticleSources->getSource(i); + AParticleSourceRecord* source = MW->SimulationManager->ParticleSources->getSource(i); int sourceParticleCount = source->GunParticles.size(); //Loop over all GunParticles diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 297237cc..893df0b9 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -3751,31 +3751,6 @@ void MainWindow::on_pbSimulate_clicked() startSimulation(Config->JSON); } -void MainWindow::on_pbParticleSourcesSimulate_clicked() -{ - ELwindow->QuickSave(0); - fStartedFromGUI = true; - fSimDataNotSaved = false; // to disable the warning - //watchdog on particle sources, can be transferred later to check-upwindow - if (ParticleSources->size() == 0) - { - message("No particle sources defined!", this); - return; - } - - for (int i = 0; isize(); i++) - { - int error = ParticleSources->CheckSource(i); - if (error == 0) continue; - - message("Error in source "+ParticleSources->getSource(i)->name +":\n\n"+ParticleSources->getErrorString(error), this); - return; - } - - MainWindow::writeSimSettingsToJson(Config->JSON); - startSimulation(Config->JSON); -} - void MainWindow::startSimulation(QJsonObject &json) { WindowNavigator->BusyOn(); //go busy mode, most of gui controls disabled diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 92a10164..6007cc53 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -90,7 +90,6 @@ class MainWindow : public QMainWindow EventsDataClass *EventsDataHub = 0; TApplication *RootApp = 0; ASimulationManager* SimulationManager = 0; - ParticleSourcesClass* ParticleSources = 0; AReconstructionManager *ReconstructionManager = 0; ANetworkModule* NetModule = 0; TmpObjHubClass *TmpHub = 0; diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 66717a37..f0f71363 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -10027,26 +10027,13 @@ double events: Check file - - - - 60 - 100 - 47 - 13 - - - - File info: - - - 60 - 120 - 421 - 91 + 10 + 100 + 491 + 111 diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 7c6be6c0..605e3bc2 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -89,7 +89,9 @@ const AParticleFileStat AFileParticleGenerator::InspectFile(const QString &fname if (f.size() < 8) continue; - int pId = f.at(0).toInt(); + bool bOK; + int pId = f.at(0).toInt(&bOK); + if (!bOK) continue; //assuming this is a comment line if (pId < 0 || pId >= ParticleCount) { stat.ErrorString = QString("Invalid particle index %1 in file %2").arg(pId).arg(fname); diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 78404c74..5c15debb 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -74,7 +74,7 @@ class ASimulationManager : public QObject void StartSimulation(QJsonObject &json, int threads, bool fStartedFromGui); void Clear(); - ParticleSourcesClass* ParticleSources; //used to update JSON on config chamges and in GUI to configure; Simulateors use their local copies build from JSON + ParticleSourcesClass* ParticleSources; //used to update JSON on config changes and in GUI to configure; Simulateors use their local copies build from JSON ATrackBuildOptions TrackBuildOptions; private: From 4e33eb2b77be4d8c3a766a6837c9add9816df8ba Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 11:19:29 +0100 Subject: [PATCH 090/140] ++ --- src/EXAMPLES/ExampleParticlesFromFile.dat | 12 +-- src/common/aparticlegun.h | 5 + .../MainWindowParticleSimulation.cpp | 96 ++++++++++++------- .../MainWindowPhotonSource.cpp | 3 +- src/gui/MainWindowTools/mainwindowjson.cpp | 60 +++++++----- src/gui/exampleswindow.cpp | 2 +- src/gui/mainwindow.h | 8 +- src/gui/mainwindow.ui | 7 +- src/modules/afileparticlegenerator.cpp | 23 +++-- src/modules/afileparticlegenerator.h | 10 +- src/modules/simulationmanager.cpp | 3 + src/modules/simulationmanager.h | 6 +- 12 files changed, 155 insertions(+), 80 deletions(-) diff --git a/src/EXAMPLES/ExampleParticlesFromFile.dat b/src/EXAMPLES/ExampleParticlesFromFile.dat index 46c80df8..3697a77f 100644 --- a/src/EXAMPLES/ExampleParticlesFromFile.dat +++ b/src/EXAMPLES/ExampleParticlesFromFile.dat @@ -1,9 +1,9 @@ format: particleId energy x y z vx vy vz if line ends with *, the next particle is added to the same event separators can be any number of spaces or tabs comments are ignored - -0 120 0 0 -10 0 0 1 -2 250 0 0 -10 1 0 1 -1 115 0 0 -10 0 1 1 -0 511 0 0 0 0 0 1 * -0 511 0 0 0 0 0 -1 \ No newline at end of file + +0 120 0 0 -10 0 0 1 +2 250 0 0 -10 1 0 1 +1 115 0 0 -10 0 1 1 +0 511 10 10 0 1 0.25 1 * +0 511 10 10 0 -1 -0.25 -1 \ No newline at end of file diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 3fbd61fa..35db2dd7 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -37,6 +37,11 @@ class AParticleGun virtual void RemoveParticle(int particleId) = 0; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first virtual bool IsParticleInUse(int particleId, QString& SourceNames) const = 0; + + const QString& GetErrorString() const {return ErrorString;} + +protected: + QString ErrorString; }; #endif // APARTICLEGUN_H diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 9467bd54..2f4cff7e 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -37,24 +37,37 @@ #include "TH1D.h" void MainWindow::SimParticleSourcesConfigToJson(QJsonObject &json) -{ - QJsonObject masterjs; - // control options - QJsonObject cjs; - cjs["EventsToDo"] = ui->sbGunEvents->text().toDouble(); - cjs["AllowMultipleParticles"] = ui->cbGunAllowMultipleEvents->isChecked(); - cjs["AverageParticlesPerEvent"] = ui->ledGunAverageNumPartperEvent->text().toDouble(); - cjs["TypeParticlesPerEvent"] = ui->cobPartPerEvent->currentIndex(); - cjs["DoS1"] = ui->cbGunDoS1->isChecked(); - cjs["DoS2"] = ui->cbGunDoS2->isChecked(); - //cjs["ParticleTracks"] = ui->cbGunParticleTracks->isChecked(); - cjs["IgnoreNoHitsEvents"] = ui->cbIgnoreEventsWithNoHits->isChecked(); - cjs["IgnoreNoDepoEvents"] = ui->cbIgnoreEventsWithNoEnergyDepo->isChecked(); - masterjs["SourceControlOptions"] = cjs; +{ + QString str; + switch (ui->twParticleGenerationMode->currentIndex()) + { + case 0 : str = "Sources"; break; + case 1 : str = "File"; break; + case 2 : str = "Script"; break; + default: qWarning() << "Save sim config: unknown particle generation mode"; + } + json["ParticleGenerationMode"] = str; + + //from file + QJsonObject fjs; + SimulationManager->FileParticleGenerator->writeToJson(fjs); + json["GenerationFromFile"] = fjs; + + //Particle sources + QJsonObject psjs; + QJsonObject cjs; // control options + cjs["EventsToDo"] = ui->sbGunEvents->text().toDouble(); + cjs["AllowMultipleParticles"] = ui->cbGunAllowMultipleEvents->isChecked(); + cjs["AverageParticlesPerEvent"] = ui->ledGunAverageNumPartperEvent->text().toDouble(); + cjs["TypeParticlesPerEvent"] = ui->cobPartPerEvent->currentIndex(); + cjs["DoS1"] = ui->cbGunDoS1->isChecked(); + cjs["DoS2"] = ui->cbGunDoS2->isChecked(); + cjs["IgnoreNoHitsEvents"] = ui->cbIgnoreEventsWithNoHits->isChecked(); + cjs["IgnoreNoDepoEvents"] = ui->cbIgnoreEventsWithNoEnergyDepo->isChecked(); + psjs["SourceControlOptions"] = cjs; //particle sources - SimulationManager->ParticleSources->writeToJson(masterjs); - - json["ParticleSourcesConfig"] = masterjs; + SimulationManager->ParticleSources->writeToJson(psjs); + json["ParticleSourcesConfig"] = psjs; } void MainWindow::ShowSource(const AParticleSourceRecord* p, bool clear) @@ -233,31 +246,48 @@ void MainWindow::on_pbGunTest_clicked() GeometryWindow->ShowAndFocus(); gGeoManager->ClearTracks(); - if (ui->pbGunShowSource->isChecked()) + if (ui->twParticleGenerationMode->currentIndex() == 0) { - for (int i=0; iParticleSources->size(); i++) - ShowSource(SimulationManager->ParticleSources->getSource(i), false); + if (ui->pbGunShowSource->isChecked()) + { + for (int i=0; iParticleSources->size(); i++) + ShowSource(SimulationManager->ParticleSources->getSource(i), false); + } } + else GeometryWindow->ShowGeometry(); - TestParticleGun(SimulationManager->ParticleSources, ui->sbGunTestEvents->value()); + AParticleGun* pg; + switch (ui->twParticleGenerationMode->currentIndex()) + { + case 0: pg = SimulationManager->ParticleSources; break; + case 1: pg = SimulationManager->FileParticleGenerator; break; + case 2: + default: + message("This generation mode is not implemented!", this); + return; + } + TestParticleGun(pg, ui->sbGunTestEvents->value()); } -void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numParticles) +void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) { - ParticleSources->Init(); - - + bool bOK = Gun->Init(); + if (!bOK) + { + message("failed to initialize particle gun", this); //TODO ErrorStrig + return; + } double Length = std::max(Detector->WorldSizeXY, Detector->WorldSizeZ)*0.4; double R[3], K[3]; for (int iRun=0; iRun* GP = ParticleSources->GenerateEvent(); - if (GP->isEmpty() && iRun > 2) - { - message("Did several attempts but no particles were generated!", this); - return; - } + { + QVector* GP = Gun->GenerateEvent(); +// if (GP->isEmpty() && iRun > 2) +// { +// message("Did several attempts but no particles were generated!", this); +// break; +// } for (AGeneratedParticle& p : *GP) { R[0] = p.Position[0]; @@ -277,7 +307,7 @@ void MainWindow::TestParticleGun(ParticleSourcesClass* ParticleSources, int numP } GP->clear(); delete GP; - } + } ShowTracks(); } diff --git a/src/gui/MainWindowTools/MainWindowPhotonSource.cpp b/src/gui/MainWindowTools/MainWindowPhotonSource.cpp index 35955728..3ef4e3b2 100644 --- a/src/gui/MainWindowTools/MainWindowPhotonSource.cpp +++ b/src/gui/MainWindowTools/MainWindowPhotonSource.cpp @@ -108,8 +108,9 @@ struct SAxis SAxis(double DX, double DY, double DZ, int Nodes, int Option){dX=DX; dY=DY; dZ=DZ; nodes=Nodes; option=Option;} }; -void MainWindow::SimPointSourcesConfigToJson(QJsonObject &jsonMaster, bool fVerbose) +void MainWindow::SimPointSourcesConfigToJson(QJsonObject &jsonMaster) { + bool fVerbose = true; QJsonObject json; //main control options diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 93bbf345..8e6c7b39 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -244,32 +244,25 @@ void MainWindow::writeLoadExpDataConfigToJson(QJsonObject &json) } // SIMULATION GUI -void MainWindow::writeSimSettingsToJson(QJsonObject &json, bool fVerbose) +void MainWindow::writeSimSettingsToJson(QJsonObject &json) { //qDebug() << "GUI->Sim Json"; - fVerbose = true; //Now always!!! - - QJsonObject js; - SimGeneralConfigToJson(js); //general sim settings - if (ui->twSourcePhotonsParticles->currentIndex() == 0) - { //point source sim - js["Mode"] = "PointSim"; - SimPointSourcesConfigToJson(js, fVerbose); - if (fVerbose) SimParticleSourcesConfigToJson(js); - } - else - { //particle source sim - js["Mode"] = "SourceSim"; - SimParticleSourcesConfigToJson(js); - if (fVerbose) SimPointSourcesConfigToJson(js, fVerbose); - } - js["DoGuiUpdate"] = true; //batcher have to set it to false! - - json["SimulationConfig"] = js; - - //QJsonObject js1; - //js1["SimulationConfig"] = js; - //SaveJsonToFile(js1, "SimConfig.json"); + QJsonObject js; + SimGeneralConfigToJson(js); //general sim settings + if (ui->twSourcePhotonsParticles->currentIndex() == 0) + js["Mode"] = "PointSim"; //point source sim + else + js["Mode"] = "SourceSim"; //particle source sim + SimPointSourcesConfigToJson(js); + SimParticleSourcesConfigToJson(js); + + js["DoGuiUpdate"] = true; //batcher have to set it to false! + + json["SimulationConfig"] = js; + + //QJsonObject js1; + //js1["SimulationConfig"] = js; + //SaveJsonToFile(js1, "SimConfig.json"); } void MainWindow::onRequestSimulationGuiUpdate() @@ -559,6 +552,25 @@ if (scj.contains("CustomDistrib")) } ui->lScriptNodes->setText( QString::number(CustomScanNodes.size()) ); + //Particle generation mode + QString PartGenMode = "Sources"; //compatibility + parseJson(js, "ParticleGenerationMode", PartGenMode); + int PGMindex = 0; + if (PartGenMode == "Sources") PGMindex = 0; + else if (PartGenMode == "File") PGMindex = 1; + else if (PartGenMode == "Script") PGMindex = 2; + else qWarning() << "Load sim settings: Unknown particle generation mode!"; + ui->twParticleGenerationMode->setCurrentIndex(PGMindex); + + //From file + QJsonObject fjs; + parseJson(js, "GenerationFromFile", fjs); + if (!fjs.isEmpty()) + { + SimulationManager->FileParticleGenerator->readFromJson(fjs); + ui->leGenerateFromFile_FileName->setText(SimulationManager->FileParticleGenerator->GetFileName()); + } + //PARTICLE SOURCES QJsonObject psjs = js["ParticleSourcesConfig"].toObject(); //full sources mode diff --git a/src/gui/exampleswindow.cpp b/src/gui/exampleswindow.cpp index e163eea8..c114051c 100644 --- a/src/gui/exampleswindow.cpp +++ b/src/gui/exampleswindow.cpp @@ -65,7 +65,7 @@ void ExamplesWindow::SaveConfig(QString fileName, bool DetConstructor, bool SimS { MW->writeDetectorToJson(MW->Config->JSON); MW->writeExtraGuiToJson(MW->Config->JSON); - MW->writeSimSettingsToJson(MW->Config->JSON, true); + MW->writeSimSettingsToJson(MW->Config->JSON); MW->Rwindow->writeToJson(MW->Config->JSON); MW->Config->UpdateLRFmakeJson(); MW->Config->UpdateLRFv3makeJson(); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 6007cc53..878555e4 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -34,7 +34,6 @@ class OutputWindow; class QComboBox; class TH1D; class TH1I; -class ParticleSourcesClass; class WindowNavigatorClass; class GeometryWindowAddOn; class GlobalSettingsWindowClass; @@ -58,6 +57,7 @@ class ANetworkModule; struct AParticleSourceRecord; class ARemoteWindow; class AWebSocketServerDialog; +class AParticleGun; #ifdef ANTS_FANN class NeuralNetworksWindow; @@ -160,7 +160,7 @@ class MainWindow : public QMainWindow void writeDetectorToJson(QJsonObject &json); //GDML is NOT here bool readDetectorFromJson(QJsonObject &json); - void writeSimSettingsToJson(QJsonObject &json, bool fVerbose = false); //true - save point and source settings + void writeSimSettingsToJson(QJsonObject &json); bool readSimSettingsFromJson(QJsonObject &json); //save data to file - public due to batch mode usage @@ -386,7 +386,7 @@ private slots: void createScriptWindow(); void SimGeneralConfigToJson(QJsonObject &jsonMaster); //Save to JSON general options of simulation - void SimPointSourcesConfigToJson(QJsonObject &jsonMaster, bool fVerbose = false); //Save to JSON config for PointSources simulation + void SimPointSourcesConfigToJson(QJsonObject &jsonMaster); //Save to JSON config for PointSources simulation void SimParticleSourcesConfigToJson(QJsonObject &json); //Save to JSON config for ParticleSources simulation void updatePMArrayDataIndication(); void writeLoadExpDataConfigToJson(QJsonObject &json); @@ -403,7 +403,7 @@ private slots: void CalculateIndividualQEPDE(); //Public for use in scripting void clearEnergyVector(); void ShowSource(const AParticleSourceRecord *p, bool clear = true); - void TestParticleGun(ParticleSourcesClass *ParticleSources, int numParticles); + void TestParticleGun(AParticleGun *ParticleSources, int numParticles); private: bool startupDetector(); //on ANTS start load/create detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index f0f71363..592fd04c 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9660,7 +9660,7 @@ double events: tracks options - + 8 @@ -10087,6 +10087,9 @@ double events: false + + Particle are generated and their directions are shown. No interaction is simulated! + Test generator @@ -10124,7 +10127,7 @@ double events: pbParticleSourcesSimulate sbGunEvents pbTrackOptionsGun - tabWidget_3 + twParticleGenerationMode sbGunTestEvents pbGunTest labIgnoreNoHitEvents diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 605e3bc2..48449b59 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -1,22 +1,24 @@ #include "afileparticlegenerator.h" +#include "ajsontools.h" #include #include #include #include -AFileParticleGenerator::AFileParticleGenerator(const QString &FileName) : - FileName(FileName) {} - bool AFileParticleGenerator::Init() { + if (File.isOpen()) File.close(); File.setFileName(FileName); + if(!File.open(QIODevice::ReadOnly | QFile::Text)) { - qWarning() << "Could not open: " << FileName; + ErrorString = QString("Failed to open file: %1").arg(FileName); + qWarning() << ErrorString; return false; } + if (Stream) delete Stream; Stream = 0; Stream = new QTextStream(&File); return true; } @@ -39,7 +41,7 @@ QVector * AFileParticleGenerator::GenerateEvent() if (f.size() < 8) continue; - int pId = f.at(0).toInt(); //TODO index check + int pId = f.at(0).toInt(); //TODO index check double energy = f.at(1).toDouble(); double x = f.at(2).toDouble(); double y = f.at(3).toDouble(); @@ -53,7 +55,6 @@ QVector * AFileParticleGenerator::GenerateEvent() if (f.size() > 8 && f.at(8) == '*') continue; break; } - return GeneratedParticles; } @@ -67,6 +68,16 @@ bool AFileParticleGenerator::IsParticleInUse(int particleId, QString &SourceName return false; //TODO } +void AFileParticleGenerator::writeToJson(QJsonObject &json) const +{ + json["FileName"] = FileName; +} + +void AFileParticleGenerator::readFromJson(const QJsonObject &json) +{ + parseJson(json, "FileName", FileName); +} + const AParticleFileStat AFileParticleGenerator::InspectFile(const QString &fname, int ParticleCount) { AParticleFileStat stat; diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 9fda6694..638d2365 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -7,6 +7,7 @@ #include #include #include +#include class QTextStream; @@ -22,9 +23,11 @@ class AParticleFileStat class AFileParticleGenerator : public AParticleGun { public: - AFileParticleGenerator(const QString& FileName); virtual ~AFileParticleGenerator(){} + void SetFileName(const QString &fileName) {FileName = fileName;} + const QString GetFileName() const {return FileName;} + virtual bool Init() override; //called before first use virtual void ReleaseResources() override; //called after end of operation virtual QVector* GenerateEvent(); @@ -34,8 +37,11 @@ class AFileParticleGenerator : public AParticleGun virtual void RemoveParticle(int particleId) override {} //cannot be used for this class virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; + void writeToJson(QJsonObject& json) const; + void readFromJson(const QJsonObject& json); + private: - const QString FileName; + QString FileName; QFile File; const QRegularExpression rx = QRegularExpression("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index a2d7e0bc..f13a29c7 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1756,6 +1756,8 @@ ASimulationManager::ASimulationManager(EventsDataClass* EventsDataHub, DetectorC ParticleSources = new ParticleSourcesClass(Detector, Detector->RandGen); //qDebug() << "->Container for particle sources created and configured"; + FileParticleGenerator = new AFileParticleGenerator(); + Runner = new ASimulatorRunner(Detector, EventsDataHub); QObject::connect(Runner, SIGNAL(simulationFinished()), this, SLOT(onSimulationFinished())); @@ -1775,6 +1777,7 @@ ASimulationManager::~ASimulationManager() delete Runner; ASimulationManager::Clear(); + delete FileParticleGenerator; delete ParticleSources; } diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 5c15debb..0306701c 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -6,6 +6,7 @@ #include "aphoton.h" #include "dotstgeostruct.h" #include "atrackbuildoptions.h" +#include "afileparticlegenerator.h" #include #include @@ -74,7 +75,10 @@ class ASimulationManager : public QObject void StartSimulation(QJsonObject &json, int threads, bool fStartedFromGui); void Clear(); - ParticleSourcesClass* ParticleSources; //used to update JSON on config changes and in GUI to configure; Simulateors use their local copies build from JSON + // Next two: Simulators use their own local copies constructed using configuration in JSON + ParticleSourcesClass* ParticleSources = 0; //used to update JSON on config changes and in GUI to configure + AFileParticleGenerator* FileParticleGenerator = 0; //only for gui, simulation threads use their own + ATrackBuildOptions TrackBuildOptions; private: From 0a3774bfa607a38b771f6e4ec2216052efa7d431 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 11:51:46 +0100 Subject: [PATCH 091/140] ++ --- src/EXAMPLES/ExampleParticlesFromFile.dat | 6 +++--- src/gui/MainWindowTools/MainWindowInits.cpp | 1 + .../MainWindowTools/MainWindowParticleSimulation.cpp | 11 +++++++++-- src/gui/mainwindow.cpp | 3 ++- src/modules/afileparticlegenerator.cpp | 6 +++++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/EXAMPLES/ExampleParticlesFromFile.dat b/src/EXAMPLES/ExampleParticlesFromFile.dat index 3697a77f..cfd2afca 100644 --- a/src/EXAMPLES/ExampleParticlesFromFile.dat +++ b/src/EXAMPLES/ExampleParticlesFromFile.dat @@ -2,8 +2,8 @@ format: particleId energy x y z vx vy vz if line ends with *, the next part separators can be any number of spaces or tabs comments are ignored -0 120 0 0 -10 0 0 1 -2 250 0 0 -10 1 0 1 -1 115 0 0 -10 0 1 1 +0 120 5 0 -10 0 0 1 +2 250 5 0 -10 1 0 1 +1 115 5 0 -10 0 1 1 0 511 10 10 0 1 0.25 1 * 0 511 10 10 0 -1 -0.25 -1 \ No newline at end of file diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 025d6f28..e4422d85 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -76,6 +76,7 @@ MainWindow::MainWindow(DetectorClass *Detector, QString epff = GlobSet.ExamplesDir + "/ExampleParticlesFromFile.dat"; ui->leGenerateFromFile_FileName->setText(epff); + SimulationManager->FileParticleGenerator->SetFileName(epff); //adding Context menus ui->lwLoadedEventsFiles->setContextMenuPolicy(Qt::CustomContextMenu); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 2f4cff7e..8af453d5 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -271,10 +271,12 @@ void MainWindow::on_pbGunTest_clicked() void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) { + clearGeoMarkers(); + bool bOK = Gun->Init(); if (!bOK) { - message("failed to initialize particle gun", this); //TODO ErrorStrig + message("Failed to initialize particle gun!\n" + Gun->GetErrorString(), this); //TODO ErrorStrig return; } @@ -296,7 +298,7 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) K[0] = p.Direction[0]; K[1] = p.Direction[1]; - K[2] = p.Direction[2]; + K[2] = p.Direction[2]; Int_t track_index = Detector->GeoManager->AddTrack(1,22); TVirtualGeoTrack *track = Detector->GeoManager->GetTrack(track_index); @@ -304,11 +306,16 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) track->AddPoint(R[0] + K[0]*Length, R[1] + K[1]*Length, R[2] + K[2]*Length, 0); track->SetLineWidth(1); //TODO respect all attributes! track->SetLineColor(1 + p.ParticleId); //TODO respect particle track colors! + + GeoMarkerClass* marks = new GeoMarkerClass("t", 7, 1, kBlack); + marks->SetNextPoint(R[0], R[1], R[2]); + GeoMarkers.append(marks); } GP->clear(); delete GP; } ShowTracks(); + ShowGeoMarkers(); } void MainWindow::on_ledGunAverageNumPartperEvent_editingFinished() diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 893df0b9..9a473e2a 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -444,9 +444,10 @@ void MainWindow::clearGeoMarkers(int All_Rec_True) case 0: default: delete GeoMarkers[i]; - GeoMarkers.remove(i); } } + + if (All_Rec_True == 0) GeoMarkers.clear(); } void MainWindow::clearCustomScanNodes() diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 48449b59..465d6e63 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -41,7 +41,11 @@ QVector * AFileParticleGenerator::GenerateEvent() if (f.size() < 8) continue; - int pId = f.at(0).toInt(); //TODO index check + bool bOK; + int pId = f.at(0).toInt(&bOK); + if (!bOK) continue; + //TODO protection of wrong index, either test on start + double energy = f.at(1).toDouble(); double x = f.at(2).toDouble(); double y = f.at(3).toDouble(); From 2f9ad30f15425901d6a6887075ca9f1c8a4827a2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 12:05:31 +0100 Subject: [PATCH 092/140] ++ --- src/common/atrackbuildoptions.cpp | 33 +++++++++++++++++++ src/common/atrackbuildoptions.h | 4 +++ .../MainWindowParticleSimulation.cpp | 9 ++--- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/common/atrackbuildoptions.cpp b/src/common/atrackbuildoptions.cpp index dd79e629..4e26ff66 100644 --- a/src/common/atrackbuildoptions.cpp +++ b/src/common/atrackbuildoptions.cpp @@ -2,6 +2,8 @@ #include "ajsontools.h" #include "atrackrecords.h" +#include "TVirtualGeoTrack.h" + void ATrackAttributes::writeToJson(QJsonObject &json) const { json["color"] = color; @@ -30,6 +32,13 @@ void ATrackAttributes::setTrackAttributes(TrackHolderClass *track) const track->Style = style; } +void ATrackAttributes::setTrackAttributes(TVirtualGeoTrack *track) const +{ + track->SetLineColor(color); + track->SetLineWidth(width); + track->SetLineStyle(style); +} + void ATrackAttributes::reset() { color = 7; @@ -154,6 +163,30 @@ void ATrackBuildOptions::applyToParticleTrack(TrackHolderClass *track, int Parti track->Color = DefaultParticle_Colors.at(ParticleId); } +void ATrackBuildOptions::applyToParticleTrack(TVirtualGeoTrack *track, int ParticleId) const +{ + if ( ParticleId < CustomParticle_Attributes.size() && CustomParticle_Attributes.at(ParticleId) ) + { + //custom properties defined for this particle + CustomParticle_Attributes.at(ParticleId)->setTrackAttributes(track); + return; + } + + TA_DefaultParticle.setTrackAttributes(track); + + if ( ParticleId < DefaultParticle_Colors.size()) + track->SetLineColor( DefaultParticle_Colors.at(ParticleId) ); +} + +int ATrackBuildOptions::getParticleColor(int ParticleId) const +{ + if ( ParticleId < CustomParticle_Attributes.size() && CustomParticle_Attributes.at(ParticleId) ) + return CustomParticle_Attributes.at(ParticleId)->color; //custom properties defined for this particle + + if ( ParticleId < DefaultParticle_Colors.size()) return DefaultParticle_Colors.at(ParticleId); + else return TA_DefaultParticle.color; +} + void ATrackBuildOptions::clear() { bBuildPhotonTracks = false; diff --git a/src/common/atrackbuildoptions.h b/src/common/atrackbuildoptions.h index 1853fbca..de1be3af 100644 --- a/src/common/atrackbuildoptions.h +++ b/src/common/atrackbuildoptions.h @@ -5,6 +5,7 @@ class QJsonObject; class TrackHolderClass; +class TVirtualGeoTrack; class ATrackAttributes { @@ -18,6 +19,7 @@ class ATrackAttributes void readFromJson(const QJsonObject& json); void setTrackAttributes(TrackHolderClass* track) const; + void setTrackAttributes(TVirtualGeoTrack* track) const; void reset(); }; @@ -58,6 +60,8 @@ class ATrackBuildOptions void readFromJson(const QJsonObject& json); void applyToParticleTrack(TrackHolderClass* track, int ParticleId) const; + void applyToParticleTrack(TVirtualGeoTrack *track, int ParticleId) const; + int getParticleColor(int ParticleId) const; private: void clear(); //clear and reset to default values diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 8af453d5..9a6060b6 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -290,7 +290,7 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) // message("Did several attempts but no particles were generated!", this); // break; // } - for (AGeneratedParticle& p : *GP) + for (const AGeneratedParticle& p : *GP) { R[0] = p.Position[0]; R[1] = p.Position[1]; @@ -304,10 +304,11 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) TVirtualGeoTrack *track = Detector->GeoManager->GetTrack(track_index); track->AddPoint(R[0], R[1], R[2], 0); track->AddPoint(R[0] + K[0]*Length, R[1] + K[1]*Length, R[2] + K[2]*Length, 0); - track->SetLineWidth(1); //TODO respect all attributes! - track->SetLineColor(1 + p.ParticleId); //TODO respect particle track colors! + SimulationManager->TrackBuildOptions.applyToParticleTrack(track, p.ParticleId); + //track->SetLineWidth(1); //TODO respect all attributes! + //track->SetLineColor(1 + p.ParticleId); //TODO respect particle track colors! - GeoMarkerClass* marks = new GeoMarkerClass("t", 7, 1, kBlack); + GeoMarkerClass* marks = new GeoMarkerClass("t", 7, 1, SimulationManager->TrackBuildOptions.getParticleColor(p.ParticleId)); marks->SetNextPoint(R[0], R[1], R[2]); GeoMarkers.append(marks); } From 79bd95136b62a8d2bc85bf00930e14ebf0fd1c7d Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 12:19:52 +0100 Subject: [PATCH 093/140] ++ --- src/gui/mainwindow.cpp | 16 +++ src/gui/mainwindow.h | 4 + src/gui/mainwindow.ui | 249 +++++++++++++++++++++-------------------- 3 files changed, 150 insertions(+), 119 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 9a473e2a..23a8f02d 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4807,6 +4807,22 @@ void MainWindow::on_pbTrackOptionsGun_clicked() on_pbOpenTrackProperties_Phot_clicked(); } +void MainWindow::on_pbTrackOptionsGun_customContextMenuRequested(const QPoint &) +{ // in particle source + SimulationManager->TrackBuildOptions.bBuildPhotonTracks = false; + + SimulationManager->TrackBuildOptions.bBuildParticleTracks = !SimulationManager->TrackBuildOptions.bBuildParticleTracks; + on_pbUpdateSimConfig_clicked(); +} + +void MainWindow::on_pbOpenTrackProperties_Phot_customContextMenuRequested(const QPoint &) +{ //in photon sources + SimulationManager->TrackBuildOptions.bBuildParticleTracks = false; + + SimulationManager->TrackBuildOptions.bBuildPhotonTracks = !SimulationManager->TrackBuildOptions.bBuildPhotonTracks; + on_pbUpdateSimConfig_clicked(); +} + void MainWindow::on_pbTrackOptionsStack_clicked() { on_pbOpenTrackProperties_Phot_clicked(); diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 878555e4..a74c25a8 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -608,6 +608,10 @@ private slots: void on_pbGenerateFromFile_Check_clicked(); + void on_pbTrackOptionsGun_customContextMenuRequested(const QPoint &pos); + + void on_pbOpenTrackProperties_Phot_customContextMenuRequested(const QPoint &pos); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 592fd04c..85a72235 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -8676,8 +8676,12 @@ Second click will trigger strong abort mode, which will result in loss of all si false + + Qt::CustomContextMenu + - Track build options + Click: Show / edit all track options +Right click: toggle build photon tracks. Also switches of building particle tracks tracks options @@ -9656,6 +9660,13 @@ double events: false + + Qt::CustomContextMenu + + + Click: Show / edit all track options +Right click: toggle build particle tracks. Also switch off building photon tracks + tracks options @@ -13118,8 +13129,8 @@ on stack click() - 226 - 540 + 224 + 518 280 @@ -13278,8 +13289,8 @@ on stack setCurrentIndex(int) - 370 - 433 + 368 + 411 519 @@ -13310,8 +13321,8 @@ on stack setCurrentIndex(int) - 319 - 406 + 317 + 384 257 @@ -13774,8 +13785,8 @@ on stack click() - 295 - 382 + 293 + 360 467 @@ -13790,8 +13801,8 @@ on stack click() - 181 - 474 + 179 + 452 460 @@ -13806,8 +13817,8 @@ on stack click() - 443 - 443 + 441 + 421 447 @@ -13822,8 +13833,8 @@ on stack click() - 443 - 472 + 441 + 450 500 @@ -13838,8 +13849,8 @@ on stack click() - 443 - 472 + 441 + 450 502 @@ -13854,8 +13865,8 @@ on stack click() - 295 - 382 + 293 + 360 464 @@ -13870,8 +13881,8 @@ on stack click() - 165 - 382 + 163 + 360 464 @@ -13886,8 +13897,8 @@ on stack click() - 319 - 442 + 317 + 420 510 @@ -14686,8 +14697,8 @@ on stack click() - 227 - 419 + 225 + 397 46 @@ -14702,8 +14713,8 @@ on stack click() - 317 - 419 + 315 + 397 92 @@ -14718,8 +14729,8 @@ on stack click() - 407 - 419 + 405 + 397 112 @@ -14734,8 +14745,8 @@ on stack click() - 188 - 398 + 190 + 376 40 @@ -14750,8 +14761,8 @@ on stack click() - 260 - 398 + 262 + 376 61 @@ -14766,8 +14777,8 @@ on stack click() - 331 - 398 + 333 + 376 88 @@ -14782,8 +14793,8 @@ on stack click() - 182 - 440 + 186 + 418 31 @@ -14798,8 +14809,8 @@ on stack click() - 224 - 440 + 228 + 418 48 @@ -14814,8 +14825,8 @@ on stack click() - 266 - 440 + 270 + 418 47 @@ -14830,8 +14841,8 @@ on stack click() - 333 - 441 + 337 + 419 83 @@ -14846,8 +14857,8 @@ on stack click() - 432 - 440 + 436 + 418 101 @@ -14862,8 +14873,8 @@ on stack click() - 116 - 459 + 120 + 437 43 @@ -14878,8 +14889,8 @@ on stack click() - 182 - 461 + 186 + 439 14 @@ -14894,8 +14905,8 @@ on stack click() - 224 - 461 + 228 + 439 28 @@ -14910,8 +14921,8 @@ on stack click() - 266 - 461 + 270 + 439 50 @@ -14926,8 +14937,8 @@ on stack click() - 335 - 462 + 339 + 440 77 @@ -14942,8 +14953,8 @@ on stack click() - 399 - 461 + 403 + 439 122 @@ -14958,8 +14969,8 @@ on stack click() - 135 - 480 + 134 + 458 44 @@ -14974,8 +14985,8 @@ on stack click() - 182 - 482 + 186 + 460 52 @@ -14990,8 +15001,8 @@ on stack click() - 224 - 482 + 228 + 460 36 @@ -15006,8 +15017,8 @@ on stack click() - 266 - 482 + 270 + 460 50 @@ -15022,8 +15033,8 @@ on stack click() - 332 - 483 + 336 + 461 75 @@ -15038,8 +15049,8 @@ on stack click() - 438 - 482 + 442 + 460 111 @@ -15054,8 +15065,8 @@ on stack click() - 168 - 406 + 166 + 384 36 @@ -15070,8 +15081,8 @@ on stack click() - 319 - 406 + 317 + 384 51 @@ -15086,8 +15097,8 @@ on stack click() - 129 - 436 + 127 + 414 40 @@ -15102,8 +15113,8 @@ on stack click() - 129 - 458 + 127 + 436 57 @@ -15118,8 +15129,8 @@ on stack click() - 225 - 436 + 223 + 414 58 @@ -15134,8 +15145,8 @@ on stack click() - 225 - 458 + 223 + 436 37 @@ -15150,8 +15161,8 @@ on stack click() - 370 - 433 + 368 + 411 97 @@ -15166,8 +15177,8 @@ on stack click() - 369 - 456 + 367 + 434 110 @@ -15182,8 +15193,8 @@ on stack click() - 159 - 438 + 157 + 416 31 @@ -15198,8 +15209,8 @@ on stack click() - 159 - 459 + 157 + 437 33 @@ -15214,8 +15225,8 @@ on stack click() - 239 - 438 + 237 + 416 68 @@ -15230,8 +15241,8 @@ on stack click() - 239 - 459 + 237 + 437 58 @@ -15246,8 +15257,8 @@ on stack click() - 370 - 456 + 368 + 434 119 @@ -15262,8 +15273,8 @@ on stack click() - 466 - 456 + 464 + 434 122 @@ -15518,8 +15529,8 @@ on stack setCurrentIndex(int) - 181 - 474 + 179 + 452 310 @@ -15550,8 +15561,8 @@ on stack click() - 251 - 472 + 249 + 450 498 @@ -15566,8 +15577,8 @@ on stack click() - 235 - 458 + 233 + 436 485 @@ -15582,8 +15593,8 @@ on stack click() - 235 - 496 + 233 + 474 499 @@ -15598,8 +15609,8 @@ on stack click() - 180 - 382 + 184 + 360 424 @@ -15614,8 +15625,8 @@ on stack setCurrentIndex(int) - 241 - 442 + 239 + 420 427 @@ -15630,8 +15641,8 @@ on stack click() - 392 - 479 + 390 + 457 486 @@ -15646,8 +15657,8 @@ on stack click() - 241 - 442 + 239 + 420 443 @@ -15838,8 +15849,8 @@ on stack click() - 251 - 495 + 249 + 473 412 @@ -15854,8 +15865,8 @@ on stack click() - 136 - 382 + 140 + 360 399 @@ -15870,8 +15881,8 @@ on stack click() - 298 - 474 + 302 + 452 434 From 74ffc99b359933165e7d6caa1dbfc8769c49d00c Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 13:41:50 +0100 Subject: [PATCH 094/140] ++ --- src/common/aparticlegun.h | 5 +++++ .../MainWindowParticleSimulation.cpp | 15 +++++++++++++-- src/gui/mainwindow.h | 2 ++ src/gui/mainwindow.ui | 8 ++++---- src/modules/afileparticlegenerator.cpp | 4 ++-- src/modules/afileparticlegenerator.h | 4 ++-- src/modules/particlesourcesclass.cpp | 10 ++++------ src/modules/particlesourcesclass.h | 9 ++++----- 8 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 35db2dd7..701220bb 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -3,6 +3,8 @@ #include +class QJsonObject; + class AGeneratedParticle { public: @@ -38,6 +40,9 @@ class AParticleGun virtual void RemoveParticle(int particleId) = 0; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first virtual bool IsParticleInUse(int particleId, QString& SourceNames) const = 0; + virtual void writeToJson(QJsonObject &json) const = 0; + virtual bool readFromJson(const QJsonObject &json) = 0; + const QString& GetErrorString() const {return ErrorString;} protected: diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 9a6060b6..c6d36194 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -795,6 +795,13 @@ void MainWindow::on_pbParticleSourcesSimulate_clicked() startSimulation(Config->JSON); } +void MainWindow::on_twParticleGenerationMode_currentChanged(int index) +{ + ui->sbGunEvents->setVisible(index != 1); + ui->labEventsPS->setVisible(index != 1); + ui->linePS->setVisible(index != 1); +} + // ---- from file ---- void MainWindow::on_pbGenerateFromFile_Help_clicked() @@ -804,12 +811,16 @@ void MainWindow::on_pbGenerateFromFile_Help_clicked() void MainWindow::on_pbGenerateFromFile_Change_clicked() { - + QString fileName = QFileDialog::getOpenFileName(this, "Select a file with particle generation data", GlobSet.LastOpenDir, "Data files (*.dat *.txt);;All files (*)"); + if (fileName.isEmpty()) return; + GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); + on_leGenerateFromFile_FileName_editingFinished(); } void MainWindow::on_leGenerateFromFile_FileName_editingFinished() { - + SimulationManager->FileParticleGenerator->SetFileName(ui->leGenerateFromFile_FileName->text()); + on_pbUpdateSimConfig_clicked(); } #include "afileparticlegenerator.h" diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index a74c25a8..3d5ebcec 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -612,6 +612,8 @@ private slots: void on_pbOpenTrackProperties_Phot_customContextMenuRequested(const QPoint &pos); + void on_twParticleGenerationMode_currentChanged(int index); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 85a72235..c876688c 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9537,7 +9537,7 @@ double events: Secondary scintillation - + 49 @@ -9550,7 +9550,7 @@ double events: Qt::Horizontal - + 29 @@ -10131,10 +10131,10 @@ Right click: toggle build particle tracks. Also switch off building photon track -- - line_21 + linePS cbGunDoS1 cbGunDoS2 - label_253 + labEventsPS pbParticleSourcesSimulate sbGunEvents pbTrackOptionsGun diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 465d6e63..fbf7f3c5 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -77,9 +77,9 @@ void AFileParticleGenerator::writeToJson(QJsonObject &json) const json["FileName"] = FileName; } -void AFileParticleGenerator::readFromJson(const QJsonObject &json) +bool AFileParticleGenerator::readFromJson(const QJsonObject &json) { - parseJson(json, "FileName", FileName); + return parseJson(json, "FileName", FileName); } const AParticleFileStat AFileParticleGenerator::InspectFile(const QString &fname, int ParticleCount) diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 638d2365..feb84f33 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -37,8 +37,8 @@ class AFileParticleGenerator : public AParticleGun virtual void RemoveParticle(int particleId) override {} //cannot be used for this class virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; - void writeToJson(QJsonObject& json) const; - void readFromJson(const QJsonObject& json); + virtual void writeToJson(QJsonObject& json) const override; + virtual bool readFromJson(const QJsonObject& json) override; private: QString FileName; diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 0cf7cb25..bed3a29a 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -466,7 +466,7 @@ void ParticleSourcesClass::CalculateTotalActivity() TotalActivity += ParticleSourcesData[i]->Activity; } -bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) +bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) const { if (iSource<0 || iSource>ParticleSourcesData.size()-1) return false; @@ -475,18 +475,16 @@ bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) return true; } -bool ParticleSourcesClass::writeToJson(QJsonObject &json) +void ParticleSourcesClass::writeToJson(QJsonObject &json) const { QJsonArray ja; for (int iSource=0; iSourcefLimit = false; } -bool ParticleSourcesClass::readFromJson(QJsonObject &json) +bool ParticleSourcesClass::readFromJson(const QJsonObject &json) { if (!json.contains("ParticleSources")) { diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 6c21ba86..20b5cf39 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -53,12 +53,11 @@ class ParticleSourcesClass : public AParticleGun int CheckSource(int isource); // 0 - no errors QString getErrorString(int error); - // save - bool writeSourceToJson(int iSource, QJsonObject &json); //only one source - bool writeToJson(QJsonObject &json); //all config - // load + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; + + bool writeSourceToJson(int iSource, QJsonObject &json) const; //only one source bool readSourceFromJson(int iSource, QJsonObject &json); - bool readFromJson(QJsonObject &json); // all config bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); TVector3 GenerateRandomDirection(); From 8e95f5042817003c2b9b1ad36ff837dc842a7ce3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 19:14:56 +0100 Subject: [PATCH 095/140] ++ --- .../MainWindowParticleSimulation.cpp | 81 +++++++++--------- src/gui/MainWindowTools/mainwindowjson.cpp | 83 +++++++++---------- src/gui/checkupwindowclass.cpp | 2 +- src/modules/particlesourcesclass.cpp | 2 +- src/modules/particlesourcesclass.h | 42 +++++----- src/modules/simulationmanager.cpp | 56 ++++++------- 6 files changed, 132 insertions(+), 134 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index c6d36194..647af075 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -38,35 +38,36 @@ void MainWindow::SimParticleSourcesConfigToJson(QJsonObject &json) { - QString str; - switch (ui->twParticleGenerationMode->currentIndex()) - { - case 0 : str = "Sources"; break; - case 1 : str = "File"; break; - case 2 : str = "Script"; break; - default: qWarning() << "Save sim config: unknown particle generation mode"; - } - json["ParticleGenerationMode"] = str; - - //from file - QJsonObject fjs; - SimulationManager->FileParticleGenerator->writeToJson(fjs); - json["GenerationFromFile"] = fjs; - - //Particle sources QJsonObject psjs; - QJsonObject cjs; // control options - cjs["EventsToDo"] = ui->sbGunEvents->text().toDouble(); - cjs["AllowMultipleParticles"] = ui->cbGunAllowMultipleEvents->isChecked(); - cjs["AverageParticlesPerEvent"] = ui->ledGunAverageNumPartperEvent->text().toDouble(); - cjs["TypeParticlesPerEvent"] = ui->cobPartPerEvent->currentIndex(); - cjs["DoS1"] = ui->cbGunDoS1->isChecked(); - cjs["DoS2"] = ui->cbGunDoS2->isChecked(); - cjs["IgnoreNoHitsEvents"] = ui->cbIgnoreEventsWithNoHits->isChecked(); - cjs["IgnoreNoDepoEvents"] = ui->cbIgnoreEventsWithNoEnergyDepo->isChecked(); - psjs["SourceControlOptions"] = cjs; - //particle sources - SimulationManager->ParticleSources->writeToJson(psjs); + //control options + QJsonObject cjs; + QString str; + switch (ui->twParticleGenerationMode->currentIndex()) + { + default: qWarning() << "Save sim config: unknown particle generation mode"; + case 0 : str = "Sources"; break; + case 1 : str = "File"; break; + case 2 : str = "Script"; break; + } + cjs["ParticleGenerationMode"] = str; + cjs["EventsToDo"] = ui->sbGunEvents->text().toDouble(); + cjs["AllowMultipleParticles"] = ui->cbGunAllowMultipleEvents->isChecked(); //--->ps + cjs["AverageParticlesPerEvent"] = ui->ledGunAverageNumPartperEvent->text().toDouble(); //--->ps + cjs["TypeParticlesPerEvent"] = ui->cobPartPerEvent->currentIndex(); //--->ps + cjs["DoS1"] = ui->cbGunDoS1->isChecked(); + cjs["DoS2"] = ui->cbGunDoS2->isChecked(); + cjs["IgnoreNoHitsEvents"] = ui->cbIgnoreEventsWithNoHits->isChecked(); + cjs["IgnoreNoDepoEvents"] = ui->cbIgnoreEventsWithNoEnergyDepo->isChecked(); + psjs["SourceControlOptions"] = cjs; + + //particle sources + SimulationManager->ParticleSources->writeToJson(psjs); + + //from file + QJsonObject fjs; + SimulationManager->FileParticleGenerator->writeToJson(fjs); + psjs["GenerationFromFile"] = fjs; + json["ParticleSourcesConfig"] = psjs; } @@ -250,7 +251,7 @@ void MainWindow::on_pbGunTest_clicked() { if (ui->pbGunShowSource->isChecked()) { - for (int i=0; iParticleSources->size(); i++) + for (int i=0; iParticleSources->countSources(); i++) ShowSource(SimulationManager->ParticleSources->getSource(i), false); } } @@ -337,7 +338,7 @@ void MainWindow::on_pbRemoveSource_clicked() message("Select a source to remove", this); return; } - if (isource >= SimulationManager->ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->countSources()) { message("Error - bad source index!", this); return; @@ -355,7 +356,7 @@ void MainWindow::on_pbRemoveSource_clicked() on_pbUpdateSourcesIndication_clicked(); if (ui->pbGunShowSource->isChecked()) { - if (SimulationManager->ParticleSources->size() == 0) + if (SimulationManager->ParticleSources->countSources() == 0) { Detector->GeoManager->ClearTracks(); GeometryWindow->ShowGeometry(false); @@ -372,13 +373,13 @@ void MainWindow::on_pbAddSource_clicked() SimulationManager->ParticleSources->append(s); on_pbUpdateSourcesIndication_clicked(); - ui->lwDefinedParticleSources->setCurrentRow( SimulationManager->ParticleSources->size()-1 ); + ui->lwDefinedParticleSources->setCurrentRow( SimulationManager->ParticleSources->countSources()-1 ); on_pbEditParticleSource_clicked(); } void MainWindow::on_pbUpdateSourcesIndication_clicked() { - int numSources = SimulationManager->ParticleSources->size(); + int numSources = SimulationManager->ParticleSources->countSources(); int curRow = ui->lwDefinedParticleSources->currentRow(); ui->lwDefinedParticleSources->clear(); @@ -468,7 +469,7 @@ void MainWindow::ShowParticleSource_noFocus() { int isource = ui->lwDefinedParticleSources->currentRow(); if (isource < 0) return; - if (isource >= SimulationManager->ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->countSources()) { message("Source number is out of bounds!",this); return; @@ -484,7 +485,7 @@ void MainWindow::on_pbSaveParticleSource_clicked() message("Select a source to remove", this); return; } - if (isource >= SimulationManager->ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->countSources()) { message("Error - bad source index!", this); return; @@ -526,7 +527,7 @@ void MainWindow::on_pbLoadParticleSource_clicked() js = json["ParticleSource"].toObject(); SimulationManager->ParticleSources->append(new AParticleSourceRecord()); - SimulationManager->ParticleSources->readSourceFromJson( SimulationManager->ParticleSources->size()-1, js ); + SimulationManager->ParticleSources->readSourceFromJson( SimulationManager->ParticleSources->countSources()-1, js ); onRequestDetectorGuiUpdate(); on_pbUpdateSimConfig_clicked(); @@ -724,7 +725,7 @@ void MainWindow::on_pbEditParticleSource_clicked() message("Select a source to edit", this); return; } - if (isource >= SimulationManager->ParticleSources->size()) + if (isource >= SimulationManager->ParticleSources->countSources()) { message("Error - bad source index!", this); return; @@ -743,7 +744,7 @@ void MainWindow::on_pbEditParticleSource_clicked() { //check world size double XYm = 0; double Zm = 0; - for (int isource = 0; isource < SimulationManager->ParticleSources->size(); isource++) + for (int isource = 0; isource < SimulationManager->ParticleSources->countSources(); isource++) { double msize = ps->size1; UpdateMax(msize, ps->size2); @@ -776,13 +777,13 @@ void MainWindow::on_pbParticleSourcesSimulate_clicked() fStartedFromGUI = true; fSimDataNotSaved = false; // to disable the warning //watchdog on particle sources, can be transferred later to check-upwindow - if (SimulationManager->ParticleSources->size() == 0) + if (SimulationManager->ParticleSources->countSources() == 0) { message("No particle sources defined!", this); return; } - for (int i = 0; iParticleSources->size(); i++) + for (int i = 0; iParticleSources->countSources(); i++) { int error = SimulationManager->ParticleSources->CheckSource(i); if (error == 0) continue; diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 8e6c7b39..27fbf9e1 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -552,50 +552,45 @@ if (scj.contains("CustomDistrib")) } ui->lScriptNodes->setText( QString::number(CustomScanNodes.size()) ); - //Particle generation mode - QString PartGenMode = "Sources"; //compatibility - parseJson(js, "ParticleGenerationMode", PartGenMode); - int PGMindex = 0; - if (PartGenMode == "Sources") PGMindex = 0; - else if (PartGenMode == "File") PGMindex = 1; - else if (PartGenMode == "Script") PGMindex = 2; - else qWarning() << "Load sim settings: Unknown particle generation mode!"; - ui->twParticleGenerationMode->setCurrentIndex(PGMindex); - - //From file - QJsonObject fjs; - parseJson(js, "GenerationFromFile", fjs); - if (!fjs.isEmpty()) - { - SimulationManager->FileParticleGenerator->readFromJson(fjs); - ui->leGenerateFromFile_FileName->setText(SimulationManager->FileParticleGenerator->GetFileName()); - } + //PARTICLE SOURCES + QJsonObject psjs = js["ParticleSourcesConfig"].toObject(); + QJsonObject csjs = psjs["SourceControlOptions"].toObject(); + //Particle generation mode + QString PartGenMode = "Sources"; //compatibility + parseJson(csjs, "ParticleGenerationMode", PartGenMode); + int PGMindex = 0; + if (PartGenMode == "Sources") PGMindex = 0; + else if (PartGenMode == "File") PGMindex = 1; + else if (PartGenMode == "Script") PGMindex = 2; + else qWarning() << "Load sim settings: Unknown particle generation mode!"; + ui->twParticleGenerationMode->setCurrentIndex(PGMindex); + JsonToSpinBox (csjs, "EventsToDo", ui->sbGunEvents); + JsonToCheckbox(csjs, "AllowMultipleParticles", ui->cbGunAllowMultipleEvents); + JsonToLineEditDouble(csjs, "AverageParticlesPerEvent", ui->ledGunAverageNumPartperEvent); + ui->cobPartPerEvent->setCurrentIndex(0); + JsonToComboBox(csjs, "TypeParticlesPerEvent", ui->cobPartPerEvent); + JsonToCheckbox(csjs, "DoS1", ui->cbGunDoS1); + JsonToCheckbox(csjs, "DoS1", ui->cbDoS1tester); + JsonToCheckbox(csjs, "DoS2", ui->cbGunDoS2); + JsonToCheckbox(csjs, "DoS2", ui->cbDoS2tester); + ui->cbIgnoreEventsWithNoHits->setChecked(false);//compatibility + JsonToCheckbox(csjs, "IgnoreNoHitsEvents", ui->cbIgnoreEventsWithNoHits); + ui->cbIgnoreEventsWithNoEnergyDepo->setChecked(false); + JsonToCheckbox(csjs, "IgnoreNoDepoEvents", ui->cbIgnoreEventsWithNoEnergyDepo); + + //particle sources + SimulationManager->ParticleSources->readFromJson(psjs); + + //generation from file + QJsonObject fjs; + parseJson(js, "GenerationFromFile", fjs); + if (!fjs.isEmpty()) + { + SimulationManager->FileParticleGenerator->readFromJson(fjs); + ui->leGenerateFromFile_FileName->setText(SimulationManager->FileParticleGenerator->GetFileName()); + } - //PARTICLE SOURCES - QJsonObject psjs = js["ParticleSourcesConfig"].toObject(); - //full sources mode - QJsonObject csjs = psjs["SourceControlOptions"].toObject(); - JsonToSpinBox (csjs, "EventsToDo", ui->sbGunEvents); - JsonToCheckbox(csjs, "AllowMultipleParticles", ui->cbGunAllowMultipleEvents); - JsonToLineEditDouble(csjs, "AverageParticlesPerEvent", ui->ledGunAverageNumPartperEvent); - ui->cobPartPerEvent->setCurrentIndex(0); - JsonToComboBox(csjs, "TypeParticlesPerEvent", ui->cobPartPerEvent); - JsonToCheckbox(csjs, "DoS1", ui->cbGunDoS1); - JsonToCheckbox(csjs, "DoS1", ui->cbDoS1tester); - JsonToCheckbox(csjs, "DoS2", ui->cbGunDoS2); - JsonToCheckbox(csjs, "DoS2", ui->cbDoS2tester); - //JsonToCheckbox(csjs, "ParticleTracks", ui->cbGunParticleTracks); - //JsonToCheckbox(csjs, "ParticleTracks", ui->cbBuildParticleTrackstester); - //JsonToCheckbox(csjs, "PhotonTracks", ui->cbGunPhotonTracks); - //JsonToCheckbox(csjs, "PhotonTracks", ui->cbBuilPhotonTrackstester); - ui->cbIgnoreEventsWithNoHits->setChecked(false);//compatibility - JsonToCheckbox(csjs, "IgnoreNoHitsEvents", ui->cbIgnoreEventsWithNoHits); - ui->cbIgnoreEventsWithNoEnergyDepo->setChecked(false); - JsonToCheckbox(csjs, "IgnoreNoDepoEvents", ui->cbIgnoreEventsWithNoEnergyDepo); - - //particle sources - SimulationManager->ParticleSources->readFromJson(psjs); - on_pbUpdateSourcesIndication_clicked(); + on_pbUpdateSourcesIndication_clicked(); //Window CONTROL if (js.contains("Mode")) @@ -647,7 +642,7 @@ void MainWindow::selectFirstActiveParticleSource() { //show the first source with non-zero activity int i = 0; - for (; iParticleSources->size(); i++) + for (; iParticleSources->countSources(); i++) if (SimulationManager->ParticleSources->getSource(i)->Activity > 0) break; if (i < ui->lwDefinedParticleSources->count()) diff --git a/src/gui/checkupwindowclass.cpp b/src/gui/checkupwindowclass.cpp index 6806c494..c20c0dbb 100644 --- a/src/gui/checkupwindowclass.cpp +++ b/src/gui/checkupwindowclass.cpp @@ -242,7 +242,7 @@ TriState CheckUpWindowClass::CheckInteractions() int listIndex = ui->listInteraction->count(); //Check all particle sources: if links are valid, if interaction data for a given energy is available - for(int i = 0; i < MW->SimulationManager->ParticleSources->size(); i++) + for(int i = 0; i < MW->SimulationManager->ParticleSources->countSources(); i++) { AParticleSourceRecord* source = MW->SimulationManager->ParticleSources->getSource(i); int sourceParticleCount = source->GunParticles.size(); diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index bed3a29a..1ff451b5 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -598,7 +598,7 @@ bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QSt int ParticleSourcesClass::CheckSource(int isource) { - if (isource<0 || isource>size()-1) return 1; // 1 - wrong isource + if (isource<0 || isource>countSources()-1) return 1; // 1 - wrong isource // obsolete: 2 - particle collection not connected if (MpCollection == 0) return 3; // 3 - material collection not connected diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 20b5cf39..23941d7a 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -26,35 +26,37 @@ class LinkedParticleStructure class ParticleSourcesClass : public AParticleGun { public: - ParticleSourcesClass(const DetectorClass* Detector, TRandom2* RandGen); - ~ParticleSourcesClass(); + ParticleSourcesClass(const DetectorClass* Detector, TRandom2* RandGen); + ~ParticleSourcesClass(); - virtual bool Init() override; // !!! has to be called before the first use of "GenerateEvent"! - virtual QVector* GenerateEvent() override; //see Init!!! + virtual bool Init() override; // !!! has to be called before the first use of "GenerateEvent"! + virtual QVector* GenerateEvent() override; //see Init!!! - //for remove particle from configuration - virtual void RemoveParticle(int particleId) override; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first - virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; + //triggered when remove particle from configuration is attempted + virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; + virtual void RemoveParticle(int particleId) override; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first - //requests - int size() {return ParticleSourcesData.size();} - double getTotalActivity(); - AParticleSourceRecord* getSource(int iSource) {return ParticleSourcesData[iSource];} - AParticleSourceRecord* getLastSource() {return ParticleSourcesData.last();} + virtual void writeToJson(QJsonObject &json) const override; + virtual bool readFromJson(const QJsonObject &json) override; - //Source handling - after handling is finished, requires Init() !!! - void append(AParticleSourceRecord* gunParticle); - void forget(AParticleSourceRecord* gunParticle); - bool replace(int iSource, AParticleSourceRecord* gunParticle); - void remove(int iSource); - void clear(); + //requests + int countSources() const {return ParticleSourcesData.size();} + double getTotalActivity(); + AParticleSourceRecord* getSource(int iSource) {return ParticleSourcesData[iSource];} + AParticleSourceRecord* getLastSource() {return ParticleSourcesData.last();} + + //Source handling - after handling is finished, requires Init() !!! + void append(AParticleSourceRecord* gunParticle); + void forget(AParticleSourceRecord* gunParticle); + bool replace(int iSource, AParticleSourceRecord* gunParticle); + void remove(int iSource); + void clear(); //check consistency of data int CheckSource(int isource); // 0 - no errors QString getErrorString(int error); - virtual void writeToJson(QJsonObject &json) const override; - virtual bool readFromJson(const QJsonObject &json) override; + bool writeSourceToJson(int iSource, QJsonObject &json) const; //only one source bool readSourceFromJson(int iSource, QJsonObject &json); diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index f13a29c7..1ecb3dd5 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1430,34 +1430,34 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) } QJsonObject js = json["ParticleSourcesConfig"].toObject(); + //control options + QJsonObject cjs = js["SourceControlOptions"].toObject(); + if (cjs.isEmpty()) + { + ErrorString = "Json sent to simulator does not contain proper sim config data!"; + return false; + } - //control options - //QJsonObject cjs = js[controlOptions].toObject(); - QJsonObject cjs = js["SourceControlOptions"].toObject(); - if (cjs.isEmpty()) - { - ErrorString = "Json sent to simulator does not contain proper sim config data!"; - return false; - } - totalEventCount = cjs["EventsToDo"].toInt(); - fAllowMultiple = cjs["AllowMultipleParticles"].toBool(); - AverageNumParticlesPerEvent = cjs["AverageParticlesPerEvent"].toDouble(); - TypeParticlesPerEvent = cjs["TypeParticlesPerEvent"].toInt(); - fDoS1 = cjs["DoS1"].toBool(); - fDoS2 = cjs["DoS2"].toBool(); - //fBuildParticleTracks = cjs["ParticleTracks"].toBool(); - fBuildParticleTracks = simSettings->TrackBuildOptions.bBuildParticleTracks; - fIgnoreNoHitsEvents = false; //compatibility - parseJson(cjs, "IgnoreNoHitsEvents", fIgnoreNoHitsEvents); - fIgnoreNoDepoEvents = true; //compatibility - parseJson(cjs, "IgnoreNoDepoEvents", fIgnoreNoDepoEvents); - - //particle sources - if (js.contains("ParticleSources")) - { - ParticleSources->readFromJson(js); - ParticleSources->Init(); - } + // select ParticleGun type and load the appropriate options + + totalEventCount = cjs["EventsToDo"].toInt(); + fAllowMultiple = cjs["AllowMultipleParticles"].toBool(); + AverageNumParticlesPerEvent = cjs["AverageParticlesPerEvent"].toDouble(); + TypeParticlesPerEvent = cjs["TypeParticlesPerEvent"].toInt(); + fDoS1 = cjs["DoS1"].toBool(); + fDoS2 = cjs["DoS2"].toBool(); + fBuildParticleTracks = simSettings->TrackBuildOptions.bBuildParticleTracks; + fIgnoreNoHitsEvents = false; //compatibility + parseJson(cjs, "IgnoreNoHitsEvents", fIgnoreNoHitsEvents); + fIgnoreNoDepoEvents = true; //compatibility + parseJson(cjs, "IgnoreNoDepoEvents", fIgnoreNoDepoEvents); + + //particle sources + if (js.contains("ParticleSources")) + { + ParticleSources->readFromJson(js); + ParticleSources->Init(); + } //inits ParticleTracker->configure(simSettings, fBuildParticleTracks, &tracks, fIgnoreNoDepoEvents); @@ -1478,7 +1478,7 @@ void ParticleSourceSimulator::updateGeoManager() void ParticleSourceSimulator::simulate() { //watchdogs - int NumSources = ParticleSources->size(); + int NumSources = ParticleSources->countSources(); if (NumSources == 0) { ErrorString = "Particle sources are not defined!"; From a6a49aec22d8e50c08a4166d5f65953bcd37907d Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 23:14:30 +0100 Subject: [PATCH 096/140] ++ --- src/common/aparticlegun.h | 3 +- src/common/aparticlesourcerecord.cpp | 42 ++++++++++ src/common/aparticlesourcerecord.h | 2 + .../MainWindowParticleSimulation.cpp | 27 +++---- src/modules/afileparticlegenerator.cpp | 4 +- src/modules/afileparticlegenerator.h | 2 +- src/modules/particlesourcesclass.cpp | 78 ++++--------------- src/modules/particlesourcesclass.h | 8 +- 8 files changed, 74 insertions(+), 92 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 701220bb..3fb0d453 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -2,6 +2,7 @@ #define APARTICLEGUN_H #include +#include class QJsonObject; @@ -35,7 +36,7 @@ class AParticleGun virtual void ReleaseResources() {} //called after end of operation virtual QVector* GenerateEvent() = 0; - virtual bool CheckConfiguration() {return true;} //check consistency of the configuration + virtual const QString CheckConfiguration() const = 0; //check consistency of the configuration virtual void RemoveParticle(int particleId) = 0; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first virtual bool IsParticleInUse(int particleId, QString& SourceNames) const = 0; diff --git a/src/common/aparticlesourcerecord.cpp b/src/common/aparticlesourcerecord.cpp index d02e7496..0bb1ee27 100644 --- a/src/common/aparticlesourcerecord.cpp +++ b/src/common/aparticlesourcerecord.cpp @@ -262,3 +262,45 @@ const QString AParticleSourceRecord::getShapeString() const } return "-error-"; } + +const QString AParticleSourceRecord::CheckSource(const AMaterialParticleCollection & MpCollection) const +{ + if (shape < 0 || shape > 5) return "unknown source shape"; + + int numParts = GunParticles.size(); //11 - no particles defined + if (numParts == 0) return "no particles defined"; + + if (Spread < 0) return "negative spread angle"; + if (Activity < 0) return "negative activity"; + + //checking all particles + int numIndParts = 0; + double TotPartWeight = 0; + for (int ip = 0; ipParticleId; + if (pid < 0 || pid >= MpCollection.countParticles()) return QString("uses not valid particle index %1").arg(pid); + + if (gp->Individual) + { + //individual + numIndParts++; + if (GunParticles.at(ip)->StatWeight < 0) return QString("negative statistical weight for particle #%1").arg(ip); + TotPartWeight += GunParticles.at(ip)->StatWeight; + } + else + { + //linked + if (ip == gp->LinkedTo) return QString("particle #%1 is linked to itself").arg(ip); + if (ip < gp->LinkedTo) return QString("invalid linking for particle #%1").arg(ip); + } + + if (gp->energy <= 0) return QString("invalid energy of %1 for particle #%2").arg(gp->energy).arg(ip); + } + + if (numIndParts == 0) return "no individual particles defined"; + if (TotPartWeight == 0) return "total statistical weight of individual particles is zero"; + + return ""; +} diff --git a/src/common/aparticlesourcerecord.h b/src/common/aparticlesourcerecord.h index 2044a892..e92ada0a 100644 --- a/src/common/aparticlesourcerecord.h +++ b/src/common/aparticlesourcerecord.h @@ -74,6 +74,8 @@ struct AParticleSourceRecord const QString getShapeString() const; + const QString CheckSource(const AMaterialParticleCollection & MpCollection) const; //return error description if error found + //local variables, used in tracking, calculated autonatically, not to be loaded/saved! int LimitedToMat; //automatically calculated if LimtedToMatName matches a material bool fLimit = false; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 647af075..87ea72ab 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -773,27 +773,20 @@ void MainWindow::on_pbEditParticleSource_clicked() void MainWindow::on_pbParticleSourcesSimulate_clicked() { - ELwindow->QuickSave(0); - fStartedFromGUI = true; - fSimDataNotSaved = false; // to disable the warning - //watchdog on particle sources, can be transferred later to check-upwindow - if (SimulationManager->ParticleSources->countSources() == 0) - { - message("No particle sources defined!", this); - return; - } + ELwindow->QuickSave(0); + fStartedFromGUI = true; + fSimDataNotSaved = false; // to disable the warning + //watchdog on particle sources, can be transferred later to check-upwindow - for (int i = 0; iParticleSources->countSources(); i++) + QString err = SimulationManager->ParticleSources->CheckConfiguration(); + if (!err.isEmpty()) { - int error = SimulationManager->ParticleSources->CheckSource(i); - if (error == 0) continue; - - message("Error in source " + SimulationManager->ParticleSources->getSource(i)->name +":\n\n" + SimulationManager->ParticleSources->getErrorString(error), this); - return; + message(err); + return; } - MainWindow::writeSimSettingsToJson(Config->JSON); - startSimulation(Config->JSON); + MainWindow::writeSimSettingsToJson(Config->JSON); + startSimulation(Config->JSON); } void MainWindow::on_twParticleGenerationMode_currentChanged(int index) diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index fbf7f3c5..7abdb8be 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -62,9 +62,9 @@ QVector * AFileParticleGenerator::GenerateEvent() return GeneratedParticles; } -bool AFileParticleGenerator::CheckConfiguration() +const QString AFileParticleGenerator::CheckConfiguration() const { - return true; //TODO + return ""; //TODO } bool AFileParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index feb84f33..63b3cdbc 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -32,7 +32,7 @@ class AFileParticleGenerator : public AParticleGun virtual void ReleaseResources() override; //called after end of operation virtual QVector* GenerateEvent(); - virtual bool CheckConfiguration() override; //check consistency of the configuration + virtual const QString CheckConfiguration() const override; //check consistency of the configuration virtual void RemoveParticle(int particleId) override {} //cannot be used for this class virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 1ff451b5..e75d2a96 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -450,7 +450,20 @@ void ParticleSourcesClass::RemoveParticle(int particleId) for (int ip = 0; ipGunParticles.size(); ip++) if ( ps->GunParticles[ip]->ParticleId > particleId) ps->GunParticles[ip]->ParticleId--; + } +} + +const QString ParticleSourcesClass::CheckConfiguration() const +{ + if (ParticleSourcesData.isEmpty()) return "No sources are defined"; + for (AParticleSourceRecord* ps : ParticleSourcesData) + { + QString err = ps->CheckSource(*MpCollection); + if (!err.isEmpty()) return QString("Error in source %1:\n%2").arg(ps->name).arg(err); } + if (TotalActivity == 0) return "Total activity is zero"; + + return ""; } double ParticleSourcesClass::getTotalActivity() @@ -596,71 +609,6 @@ bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QSt return true; } -int ParticleSourcesClass::CheckSource(int isource) -{ - if (isource<0 || isource>countSources()-1) return 1; // 1 - wrong isource - - // obsolete: 2 - particle collection not connected - if (MpCollection == 0) return 3; // 3 - material collection not connected - if (getTotalActivity() == 0) return 4; // 4 - total activity = 0 - - AParticleSourceRecord* ps = ParticleSourcesData[isource]; - if (ps->shape <0 || ps->shape>5) return 10; //10 - unknown source shape - - int numParts = ps->GunParticles.size(); //11 - no particles defined - if (numParts == 0) return 11; - - //checking all particles - int numIndParts = 0; - double TotPartWeight = 0; - for (int ip = 0; ipGunParticles[ip]; - - int id = gp->ParticleId; - //if (id<0 || id>ParticleCollection->size()-1) return 12; // 12 - use of non-defined particle - if (id<0 || id>MpCollection->countParticles()-1) return 12; // 12 - use of non-defined particle - - if (gp->Individual) - { - //individual - numIndParts++; - - TotPartWeight += ParticleSourcesData[isource]->GunParticles[ip]->StatWeight; - } - else - { - //linked - if (ip == gp->LinkedTo) return 13; // 13 - particle is linked to itself - } - } - - if (numIndParts == 0) return 21; //21 - no individual particles defined - if (TotPartWeight == 0) return 22; //total weight of individual particles = 0 - - return 0; //all is OK -} - -QString ParticleSourcesClass::getErrorString(int error) -{ - switch (error) - { - case 0: return "No errors"; - case 1: return "Wrong source number"; - case 2: return "Particle collection not connected"; - case 3: return "Materia collection not connected"; - case 4: return "Total activity of all sources = 0"; - case 10: return "Unknown source shape"; - case 11: return "No particles defined"; - case 12: return "Use of non-defined particle"; - case 13: return "Particle is linked to itself"; - case 21: return "No individual particles defined"; - case 22: return "Notal probability to emit a particle = 0"; - } - - return "undefined error"; -} - void ParticleSourcesClass::append(AParticleSourceRecord *gunParticle) { ParticleSourcesData.append(gunParticle); diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 23941d7a..ef474d0e 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -36,6 +36,8 @@ class ParticleSourcesClass : public AParticleGun virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; virtual void RemoveParticle(int particleId) override; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first + virtual const QString CheckConfiguration() const; + virtual void writeToJson(QJsonObject &json) const override; virtual bool readFromJson(const QJsonObject &json) override; @@ -52,12 +54,6 @@ class ParticleSourcesClass : public AParticleGun void remove(int iSource); void clear(); - //check consistency of data - int CheckSource(int isource); // 0 - no errors - QString getErrorString(int error); - - - bool writeSourceToJson(int iSource, QJsonObject &json) const; //only one source bool readSourceFromJson(int iSource, QJsonObject &json); bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); From a4a845bee9bdb591d56d0154ebb15c0baeeb2b6c Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 18 Oct 2018 23:24:44 +0100 Subject: [PATCH 097/140] ++ --- .../MainWindowParticleSimulation.cpp | 2 +- src/modules/particlesourcesclass.cpp | 21 ++++++------------- src/modules/particlesourcesclass.h | 1 - 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 87ea72ab..facbe6e8 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -498,7 +498,7 @@ void MainWindow::on_pbSaveParticleSource_clicked() if (file.suffix().isEmpty()) fileName += ".json"; QJsonObject json, js; - SimulationManager->ParticleSources->writeSourceToJson(isource, json); + SimulationManager->ParticleSources->getSource(isource)->writeToJson(json, *MpCollection); js["ParticleSource"] = json; bool bOK = SaveJsonToFile(js, fileName); if (!bOK) message("Failed to save json to file: "+fileName, this); diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index e75d2a96..ac9553ad 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -479,25 +479,16 @@ void ParticleSourcesClass::CalculateTotalActivity() TotalActivity += ParticleSourcesData[i]->Activity; } -bool ParticleSourcesClass::writeSourceToJson(int iSource, QJsonObject &json) const -{ - if (iSource<0 || iSource>ParticleSourcesData.size()-1) return false; - - AParticleSourceRecord* s = ParticleSourcesData[iSource]; - s->writeToJson(json, *MpCollection); - return true; -} - void ParticleSourcesClass::writeToJson(QJsonObject &json) const { - QJsonArray ja; - for (int iSource=0; iSourcewriteToJson(js, *MpCollection); + ja.append(js); } - json["ParticleSources"] = ja; + json["ParticleSources"] = ja; } bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index ef474d0e..2e9ccd85 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -54,7 +54,6 @@ class ParticleSourcesClass : public AParticleGun void remove(int iSource); void clear(); - bool writeSourceToJson(int iSource, QJsonObject &json) const; //only one source bool readSourceFromJson(int iSource, QJsonObject &json); bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); From 944c9c7a6e810be25355a3c558a11ec2bb897478 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 19 Oct 2018 00:48:26 +0100 Subject: [PATCH 098/140] ++ --- .../MainWindowParticleSimulation.cpp | 6 +- src/modules/particlesourcesclass.cpp | 68 ++++++------------- src/modules/particlesourcesclass.h | 37 +++++----- 3 files changed, 41 insertions(+), 70 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index facbe6e8..473bca96 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -526,8 +526,10 @@ void MainWindow::on_pbLoadParticleSource_clicked() int oldPartCollSize = Detector->MpCollection->countParticles(); js = json["ParticleSource"].toObject(); - SimulationManager->ParticleSources->append(new AParticleSourceRecord()); - SimulationManager->ParticleSources->readSourceFromJson( SimulationManager->ParticleSources->countSources()-1, js ); + AParticleSourceRecord* ps = new AParticleSourceRecord(); + ps->readFromJson(js, *MpCollection); + SimulationManager->ParticleSources->append(ps); + //SimulationManager->ParticleSources->readSourceFromJson( SimulationManager->ParticleSources->countSources()-1, js ); onRequestDetectorGuiUpdate(); on_pbUpdateSimConfig_clicked(); diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index ac9553ad..ab44b25e 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -468,15 +468,15 @@ const QString ParticleSourcesClass::CheckConfiguration() const double ParticleSourcesClass::getTotalActivity() { - CalculateTotalActivity(); - return TotalActivity; + CalculateTotalActivity(); + return TotalActivity; } void ParticleSourcesClass::CalculateTotalActivity() { - TotalActivity = 0; - for (int i=0; iActivity; + TotalActivity = 0; + for (int i=0; iActivity; } void ParticleSourcesClass::writeToJson(QJsonObject &json) const @@ -491,30 +491,6 @@ void ParticleSourcesClass::writeToJson(QJsonObject &json) const json["ParticleSources"] = ja; } -bool ParticleSourcesClass::readSourceFromJson(int iSource, QJsonObject &json) -{ - //qDebug() << "Read!"; - if (iSource<-1 || iSource>ParticleSourcesData.size()-1) - { - qWarning("Particle source was NOT loaded - wrong source index"); - return false; - } - - if (iSource == -1) - { - //append new! - AParticleSourceRecord* ns = new AParticleSourceRecord(); - ParticleSourcesData.append(ns); - iSource = ParticleSourcesData.size()-1; - } - - delete ParticleSourcesData[iSource]; - AParticleSourceRecord* s = new AParticleSourceRecord(); - ParticleSourcesData[iSource] = s; - - return s->readFromJson(json, *MpCollection); -} - void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) { bool fFound = false; @@ -536,35 +512,31 @@ void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) bool ParticleSourcesClass::readFromJson(const QJsonObject &json) { - if (!json.contains("ParticleSources")) - { - qWarning() << "--- Json does not contain config for particle sources!"; - return false; - } + clear(); - QJsonArray ar = json["ParticleSources"].toArray(); - if (ar.isEmpty()) + if (!json.contains("ParticleSources")) { - //qDebug() << "No sources defined in the json object!"; - return false; + qWarning() << "--- Json does not contain config for particle sources!"; + return false; } - // qDebug() << " Sources in json:"<< ar.size(); - ParticleSourcesClass::clear(); + QJsonArray ar = json["ParticleSources"].toArray(); + if (ar.isEmpty()) return true; - for (int iSource =0; iSourcereadFromJson(json, *MpCollection); + if (!bOK) { - qWarning() << "||| Load particles from json failed!"; - ParticleSourcesClass::clear(); - return false; + qWarning() << "||| Load particle source #" << iSource << "from json failed!"; + delete ps; } + else ParticleSourcesData << ps; } - return true; + return true; } bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName) diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 2e9ccd85..40585c0b 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -54,32 +54,29 @@ class ParticleSourcesClass : public AParticleGun void remove(int iSource); void clear(); - bool readSourceFromJson(int iSource, QJsonObject &json); - bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); + bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); - TVector3 GenerateRandomDirection(); - void checkLimitedToMaterial(AParticleSourceRecord *s); + TVector3 GenerateRandomDirection(); + void checkLimitedToMaterial(AParticleSourceRecord *s); private: - //external resources - pointers - const DetectorClass* Detector; - AMaterialParticleCollection* MpCollection; - TRandom2 *RandGen; - - QVector ParticleSourcesData; - QVector TotalParticleWeight; - double TotalActivity; - QVector< QVector< QVector > > LinkedPartiles; //[isource] [iparticle] [] (includes the record of the particle iteslf!!!) + const DetectorClass* Detector; //external + AMaterialParticleCollection* MpCollection; //external + TRandom2 *RandGen; //external + + QVector ParticleSourcesData; + QVector TotalParticleWeight; + double TotalActivity; + QVector< QVector< QVector > > LinkedPartiles; //[isource] [iparticle] [] (includes the record of the particle iteslf!!!) //full recipe of emission builder (containes particles linked to particles etc up to the top level individual particle) - QVector CollimationDirection; //[isource] collimation direction - QVector CollimationProbability; //[isource] collimation probability: solid angle inside cone / 4Pi - //QVector CollimationSpreadProduct; //[isource] vector product of collimation and normal (used to check is the new vector inisde collimation cone) + QVector CollimationDirection; //[isource] collimation direction + QVector CollimationProbability; //[isource] collimation probability: solid angle inside cone / 4Pi - //utilities - void CalculateTotalActivity(); - void GeneratePosition(int isource, double *R) const; - void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! + //utilities + void CalculateTotalActivity(); + void GeneratePosition(int isource, double *R) const; + void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! }; #endif // PARTICLESOURCESCLASS_H From dba9957aaded0565801e564ca41c185fee654935 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 19 Oct 2018 09:44:06 +0100 Subject: [PATCH 099/140] ++ --- src/modules/particlesourcesclass.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 40585c0b..11907265 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -42,19 +42,16 @@ class ParticleSourcesClass : public AParticleGun virtual bool readFromJson(const QJsonObject &json) override; //requests - int countSources() const {return ParticleSourcesData.size();} + int countSources() const {return ParticleSourcesData.size();} double getTotalActivity(); AParticleSourceRecord* getSource(int iSource) {return ParticleSourcesData[iSource];} - AParticleSourceRecord* getLastSource() {return ParticleSourcesData.last();} + void append(AParticleSourceRecord* gunParticle); + void forget(AParticleSourceRecord* gunParticle); + bool replace(int iSource, AParticleSourceRecord* gunParticle); + void remove(int iSource); + void clear(); - //Source handling - after handling is finished, requires Init() !!! - void append(AParticleSourceRecord* gunParticle); - void forget(AParticleSourceRecord* gunParticle); - bool replace(int iSource, AParticleSourceRecord* gunParticle); - void remove(int iSource); - void clear(); - - bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); + bool LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName); //TODO uses load function with message TVector3 GenerateRandomDirection(); void checkLimitedToMaterial(AParticleSourceRecord *s); @@ -66,7 +63,7 @@ class ParticleSourcesClass : public AParticleGun QVector ParticleSourcesData; QVector TotalParticleWeight; - double TotalActivity; + double TotalActivity = 0; QVector< QVector< QVector > > LinkedPartiles; //[isource] [iparticle] [] (includes the record of the particle iteslf!!!) //full recipe of emission builder (containes particles linked to particles etc up to the top level individual particle) From 7efb037fd826c57adcd965f6278588ac0a9ba1e4 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 19 Oct 2018 09:44:15 +0100 Subject: [PATCH 100/140] ++ --- src/modules/particlesourcesclass.cpp | 107 ++++++++++++++------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index ab44b25e..290b5ece 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -20,7 +20,7 @@ #include "TGeoManager.h" ParticleSourcesClass::ParticleSourcesClass(const DetectorClass *Detector, TRandom2 *RandGen) - : Detector(Detector), MpCollection(Detector->MpCollection), RandGen(RandGen), TotalActivity(0) {} + : Detector(Detector), MpCollection(Detector->MpCollection), RandGen(RandGen) {} ParticleSourcesClass::~ParticleSourcesClass() { @@ -112,38 +112,39 @@ bool ParticleSourcesClass::Init() QVector* ParticleSourcesClass::GenerateEvent() { - //after any operation with sources (add, remove), init should be called before first use! + //after any operation with sources (add, remove), init should be called before first use! - QVector* GeneratedParticles = new QVector; + QVector* GeneratedParticles = new QVector; - //selecting the source - int isource = 0; - int NumSources = ParticleSourcesData.size(); - if (NumSources>1) + //selecting the source + int isource = 0; + int NumSources = ParticleSourcesData.size(); + if (NumSources>1) { - double rnd = RandGen->Rndm()*TotalActivity; - for (; isourceRndm()*TotalActivity; + for (; isourceActivity >= rnd) break; //this source selected - rnd -= ParticleSourcesData[isource]->Activity; + if (ParticleSourcesData[isource]->Activity >= rnd) break; //this source selected + rnd -= ParticleSourcesData[isource]->Activity; } } - //position - double R[3]; - if (ParticleSourcesData[isource]->fLimit) - { - QElapsedTimer timer; - timer.start(); - do - { - if (timer.elapsed()>500) return GeneratedParticles; + //position + double R[3]; + if (ParticleSourcesData[isource]->fLimit) + { + QElapsedTimer timer; //TODO make dynamic member + timer.start(); + do + { + if (timer.elapsed()>500) return GeneratedParticles; //qDebug() << "Time passed" << timer.elapsed() << "milliseconds"; - GeneratePosition(isource, R); - } - while ( Detector->GeoManager->FindNode(R[0], R[1], R[2])->GetVolume()->GetMaterial()->GetIndex() != ParticleSourcesData[isource]->LimitedToMat ); - } - else GeneratePosition(isource, R); + GeneratePosition(isource, R); + } + //TODO - not safe in multithread!!! + while ( Detector->GeoManager->FindNode(R[0], R[1], R[2])->GetVolume()->GetMaterial()->GetIndex() != ParticleSourcesData[isource]->LimitedToMat ); + } + else GeneratePosition(isource, R); //selecting the particle double rnd = RandGen->Rndm()*TotalParticleWeight[isource]; @@ -491,25 +492,6 @@ void ParticleSourcesClass::writeToJson(QJsonObject &json) const json["ParticleSources"] = ja; } -void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) -{ - bool fFound = false; - int iMat; - for (iMat=0; iMatcountMaterials(); iMat++) - if (s->LimtedToMatName == (*MpCollection)[iMat]->name) - { - fFound = true; - break; - } - - if (fFound) - { //only in this case limit to material will be used! - s->fLimit = true; - s->LimitedToMat = iMat; - } - else s->fLimit = false; -} - bool ParticleSourcesClass::readFromJson(const QJsonObject &json) { clear(); @@ -539,14 +521,33 @@ bool ParticleSourcesClass::readFromJson(const QJsonObject &json) return true; } +void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) +{ + bool fFound = false; + int iMat; + for (iMat=0; iMatcountMaterials(); iMat++) + if (s->LimtedToMatName == (*MpCollection)[iMat]->name) + { + fFound = true; + break; + } + + if (fFound) + { //only in this case limit to material will be used! + s->fLimit = true; + s->LimitedToMat = iMat; + } + else s->fLimit = false; +} + bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName) { - if (iSource<0 || iSource>ParticleSourcesData.size()-1) + if (iSource < 0 || iSource >= ParticleSourcesData.size()) { qWarning("Energy spectrum was NOT loaded - wrong source index"); return false; } - if (iParticle<0 || iParticle>ParticleSourcesData[iSource]->GunParticles.size()-1) + if (iParticle < 0 || iParticle >= ParticleSourcesData[iSource]->GunParticles.size()) { qWarning("Energy spectrum was NOT loaded - wrong particle index"); return false; @@ -574,8 +575,8 @@ bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QSt void ParticleSourcesClass::append(AParticleSourceRecord *gunParticle) { - ParticleSourcesData.append(gunParticle); - CalculateTotalActivity(); + ParticleSourcesData.append(gunParticle); + CalculateTotalActivity(); } void ParticleSourcesClass::forget(AParticleSourceRecord *gunParticle) @@ -595,10 +596,10 @@ bool ParticleSourcesClass::replace(int iSource, AParticleSourceRecord *gunPartic void ParticleSourcesClass::remove(int iSource) { - if (ParticleSourcesData.isEmpty()) return; - if (iSource >= ParticleSourcesData.size()) return; + if (ParticleSourcesData.isEmpty()) return; + if (iSource < 0 || iSource >= ParticleSourcesData.size()) return; - delete ParticleSourcesData[iSource]; - ParticleSourcesData.remove(iSource); - CalculateTotalActivity(); + delete ParticleSourcesData[iSource]; + ParticleSourcesData.remove(iSource); + CalculateTotalActivity(); } From 9a1ff428d193cbdb2c7c15678f56acccf790ee18 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 19 Oct 2018 17:53:10 +0100 Subject: [PATCH 101/140] ++ --- src/modules/particlesourcesclass.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 290b5ece..c217b68a 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -141,24 +141,23 @@ QVector* ParticleSourcesClass::GenerateEvent() //qDebug() << "Time passed" << timer.elapsed() << "milliseconds"; GeneratePosition(isource, R); } - //TODO - not safe in multithread!!! - while ( Detector->GeoManager->FindNode(R[0], R[1], R[2])->GetVolume()->GetMaterial()->GetIndex() != ParticleSourcesData[isource]->LimitedToMat ); + while ( Detector->GeoManager->FindNode(R[0], R[1], R[2])->GetVolume()->GetMaterial()->GetIndex() != ParticleSourcesData[isource]->LimitedToMat ); //gGeoManager is Thread-aware } else GeneratePosition(isource, R); - //selecting the particle - double rnd = RandGen->Rndm()*TotalParticleWeight[isource]; - int iparticle; - for (iparticle = 0; iparticleGunParticles.size()-1; iparticle++) + //selecting the particle + double rnd = RandGen->Rndm() * TotalParticleWeight.at(isource); + int iparticle; + for (iparticle = 0; iparticleGunParticles.size()-1; iparticle++) { - if (ParticleSourcesData[isource]->GunParticles[iparticle]->Individual) + if (ParticleSourcesData[isource]->GunParticles[iparticle]->Individual) { - if (ParticleSourcesData[isource]->GunParticles[iparticle]->StatWeight >= rnd) break; //this one - rnd -= ParticleSourcesData[isource]->GunParticles[iparticle]->StatWeight; + if (ParticleSourcesData[isource]->GunParticles[iparticle]->StatWeight >= rnd) break; //this one + rnd -= ParticleSourcesData[isource]->GunParticles[iparticle]->StatWeight; } } - //iparticle is the particle number in the list - //qDebug()<<"----Particle"< Date: Fri, 19 Oct 2018 23:04:35 +0100 Subject: [PATCH 102/140] ++ --- src/gui/MainWindowTools/MainWindowParticleSimulation.cpp | 4 ++-- src/gui/mainwindow.ui | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 473bca96..b5eb0726 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -419,7 +419,6 @@ void MainWindow::on_pbUpdateSourcesIndication_clicked() e->clearFocus(); emit this->RequestUpdateSimConfig(); }); - e->setVisible(numSources > 1); l->addWidget(e); double totAct = SimulationManager->ParticleSources->getTotalActivity(); @@ -429,11 +428,12 @@ void MainWindow::on_pbUpdateSourcesIndication_clicked() lab->setMinimumWidth(45); l->addWidget(lab); - fr->setLayout(l); item->setSizeHint(fr->sizeHint()); ui->lwDefinedParticleSources->setItemWidget(item, fr); item->setSizeHint(fr->sizeHint()); + + e->setVisible(numSources > 1); } if (curRow < 0 || curRow >= ui->lwDefinedParticleSources->count()) diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index c876688c..d724061c 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9687,7 +9687,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - 1 + 0 From 789cfee6ffb785c2a9d777578be8e6f918fbbed9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 20 Oct 2018 00:33:01 +0100 Subject: [PATCH 103/140] ++ --- src/modules/simulationmanager.cpp | 73 ++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 1ecb3dd5..b599f25a 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -134,20 +134,27 @@ bool ASimulatorRunner::setup(QJsonObject &json, int threadCount) ErrorString = detector->MpCollection->CheckOverrides(); if (!ErrorString.isEmpty()) return false; - clearWorkers(); //just rebuild them all everytime, it's easier + clearWorkers(); - for(int i = 0; i < threadCount; i++) + for (int i = 0; i < threadCount; i++) { Simulator *worker; if (modeSetup == "PointSim") //Photon simulator - worker = new PointSourceSimulator(detector, i); + worker = new PointSourceSimulator(detector, i); else //Particle simulator - worker = new ParticleSourceSimulator(detector, i); + worker = new ParticleSourceSimulator(detector, i); worker->setSimSettings(&simSettings); - int seed = detector->RandGen->Rndm()*100000; + int seed = detector->RandGen->Rndm() * 100000; worker->setRngSeed(seed); - worker->setup(jsSimSet); + bool bOK = worker->setup(jsSimSet); + if (!bOK) + { + ErrorString = worker->getErrorString(); + delete worker; + clearWorkers(); + return false; + } worker->initSimStat(); worker->divideThreadWork(i, threadCount); @@ -1415,8 +1422,7 @@ ParticleSourceSimulator::~ParticleSourceSimulator() bool ParticleSourceSimulator::setup(QJsonObject &json) { - if(!Simulator::setup(json)) - return false; + if(!Simulator::setup(json)) return false; //prepare this module timeFrom = simSettings->TimeFrom; @@ -1437,9 +1443,6 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) ErrorString = "Json sent to simulator does not contain proper sim config data!"; return false; } - - // select ParticleGun type and load the appropriate options - totalEventCount = cjs["EventsToDo"].toInt(); fAllowMultiple = cjs["AllowMultipleParticles"].toBool(); AverageNumParticlesPerEvent = cjs["AverageParticlesPerEvent"].toDouble(); @@ -1452,11 +1455,51 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) fIgnoreNoDepoEvents = true; //compatibility parseJson(cjs, "IgnoreNoDepoEvents", fIgnoreNoDepoEvents); - //particle sources - if (js.contains("ParticleSources")) + // particle generation mode + QString PartGenMode = "Sources"; //compatibility + parseJson(cjs, "ParticleGenerationMode", PartGenMode); + + if (PartGenMode == "Sources") + { + // particle sources + if (js.contains("ParticleSources")) + { + ParticleSources->readFromJson(js); + ParticleSources->Init(); + } + else + { + ErrorString = "Simulation settings do not contain particle source configuration"; + return false; + } + } + else if (PartGenMode == "File") + { + // generation from file + QJsonObject fjs; + parseJson(js, "GenerationFromFile", fjs); + if (fjs.isEmpty()) + { + ErrorString = "Simulation settings do not contain 'from file' generator configuration"; + return false; + } + else + { + ErrorString = "'From file' mode is not yet implemented"; + return false; + //FileParticleGenerator->readFromJson(fjs); + } + } + else if (PartGenMode == "Script") { - ParticleSources->readFromJson(js); - ParticleSources->Init(); + // script based generator + ErrorString = "Script particle generator is not yet implemented"; + return false; + } + else + { + ErrorString = "Load sim settings: Unknown particle generation mode!"; + return false; } //inits From b21a9e23c1c0db3415200aaa0b185affb82a9ec1 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 20 Oct 2018 01:37:37 +0100 Subject: [PATCH 104/140] ++ --- src/common/aparticlegun.h | 2 + .../MainWindowParticleSimulation.cpp | 2 + src/modules/afileparticlegenerator.cpp | 33 ++++++++++++- src/modules/afileparticlegenerator.h | 2 + src/modules/simulationmanager.cpp | 49 ++++++++++++------- src/modules/simulationmanager.h | 11 +++-- 6 files changed, 75 insertions(+), 24 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 3fb0d453..4f18ba4f 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -44,6 +44,8 @@ class AParticleGun virtual void writeToJson(QJsonObject &json) const = 0; virtual bool readFromJson(const QJsonObject &json) = 0; + virtual void SetStartEvent(int) {} // for 'from file' generator + const QString& GetErrorString() const {return ErrorString;} protected: diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index b5eb0726..4a0e75e1 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -793,9 +793,11 @@ void MainWindow::on_pbParticleSourcesSimulate_clicked() void MainWindow::on_twParticleGenerationMode_currentChanged(int index) { + /* ui->sbGunEvents->setVisible(index != 1); ui->labEventsPS->setVisible(index != 1); ui->linePS->setVisible(index != 1); + */ } // ---- from file ---- diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 7abdb8be..4d9d036f 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -33,7 +33,7 @@ QVector * AFileParticleGenerator::GenerateEvent() { QVector* GeneratedParticles = new QVector; - while(!Stream->atEnd()) + while (!Stream->atEnd()) { const QString line = Stream->readLine(); QStringList f = line.split(rx, QString::SkipEmptyParts); @@ -82,6 +82,37 @@ bool AFileParticleGenerator::readFromJson(const QJsonObject &json) return parseJson(json, "FileName", FileName); } +void AFileParticleGenerator::SetStartEvent(int startEvent) +{ + if (Stream) + { + Stream->seek(0); + if (startEvent == 0) return; + + int event = -1; + bool bContinueEvent = false; + while (!Stream->atEnd()) + { + const QString line = Stream->readLine(); + QStringList f = line.split(rx, QString::SkipEmptyParts); + if (f.size() < 8) continue; + bool bOK; + int pId = f.at(0).toInt(&bOK); + if (!bOK) continue; //assuming this is a comment line + + if (!bContinueEvent) event++; + + if (f.size() > 8 && f.at(8) == '*') + bContinueEvent = true; + else + { + bContinueEvent = false; + if (event == startEvent-1) return; + } + } + } +} + const AParticleFileStat AFileParticleGenerator::InspectFile(const QString &fname, int ParticleCount) { AParticleFileStat stat; diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 63b3cdbc..2e3d4b19 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -40,6 +40,8 @@ class AFileParticleGenerator : public AParticleGun virtual void writeToJson(QJsonObject& json) const override; virtual bool readFromJson(const QJsonObject& json) override; + virtual void SetStartEvent(int startEvent) override; + private: QString FileName; QFile File; diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index b599f25a..16fe25c9 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -160,12 +160,12 @@ bool ASimulatorRunner::setup(QJsonObject &json, int threadCount) worker->divideThreadWork(i, threadCount); int workerEventCount = worker->getEventCount(); //Let's not create more than the necessary number of workers, but require at least 1 - if(workerEventCount == 0 && i != 0) - { + if (workerEventCount == 0 && i != 0) + { //qDebug()<<"Worker ("<<(i+1)<<") discarded, no job assigned"; delete worker; break; - } + } totalEventCount += worker->getEventCount(); workers.append(worker); } @@ -1405,7 +1405,7 @@ ParticleSourceSimulator::ParticleSourceSimulator(const DetectorClass *detector, S1generator = new S1_Generator(photonGenerator, photonTracker, detector->MpCollection, &EnergyVector, &dataHub->GeneratedPhotonsHistory, RandGen); S2generator = new S2_Generator(photonGenerator, photonTracker, &EnergyVector, RandGen, detector->GeoManager, detector->MpCollection, &dataHub->GeneratedPhotonsHistory); - ParticleSources = new ParticleSourcesClass(detector, RandGen); + //ParticleSources = new ParticleSourcesClass(detector, RandGen); /too early - do not know yet the particle generator mode } ParticleSourceSimulator::~ParticleSourceSimulator() @@ -1413,7 +1413,7 @@ ParticleSourceSimulator::~ParticleSourceSimulator() delete S2generator; delete S1generator; delete ParticleTracker; - delete ParticleSources; + delete ParticleGun; clearParticleStack(); for (int i = 0; i < EnergyVector.size(); i++) delete EnergyVector[i]; @@ -1422,7 +1422,7 @@ ParticleSourceSimulator::~ParticleSourceSimulator() bool ParticleSourceSimulator::setup(QJsonObject &json) { - if(!Simulator::setup(json)) return false; + if ( !Simulator::setup(json) ) return false; //prepare this module timeFrom = simSettings->TimeFrom; @@ -1464,8 +1464,8 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) // particle sources if (js.contains("ParticleSources")) { - ParticleSources->readFromJson(js); - ParticleSources->Init(); + ParticleGun = new ParticleSourcesClass(detector, RandGen); + ParticleGun->readFromJson(js); } else { @@ -1485,9 +1485,9 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) } else { - ErrorString = "'From file' mode is not yet implemented"; - return false; - //FileParticleGenerator->readFromJson(fjs); + ParticleGun = new AFileParticleGenerator(); + ParticleGun->readFromJson(fjs); + } } else if (PartGenMode == "Script") @@ -1502,6 +1502,13 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) return false; } + // trying initialize the gun + if ( !ParticleGun->Init() ) + { + ErrorString = ParticleGun->GetErrorString(); + return false; + } + //inits ParticleTracker->configure(simSettings, fBuildParticleTracks, &tracks, fIgnoreNoDepoEvents); ParticleTracker->resetCounter(); @@ -1520,27 +1527,32 @@ void ParticleSourceSimulator::updateGeoManager() void ParticleSourceSimulator::simulate() { - //watchdogs - int NumSources = ParticleSources->countSources(); + //watchdogs TODO + /* + int NumSources = ParticleGun->countSources(); if (NumSources == 0) { ErrorString = "Particle sources are not defined!"; fSuccess = false; return; } - if (ParticleSources->getTotalActivity() == 0) + if (ParticleGun->getTotalActivity() == 0) { ErrorString = "Total activity of sources is zero!"; fSuccess = false; return; } - if (ParticleStack.size()>0) // *** to be moved to "ClearData"? + */ + + if ( !ParticleStack.isEmpty() ) // *** to be moved to "ClearData"? { for (int i=0; iSetStartEvent(eventBegin); + //qDebug() << "---Thread"<* GP = ParticleSources->GenerateEvent(); + QVector* GP = ParticleGun->GenerateEvent(); + //qDebug() << "Thread"<size(); //adding particles to the stack for (int iPart = 0; iPart < GP->size(); iPart++ ) { diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 0306701c..38ea9723 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -39,6 +39,7 @@ class AParticleOnStack; struct AEnergyDepositionCell; class ASimulatorRunner; class GeoMarkerClass; +class AParticleGun; #if ROOT_VERSION_CODE < ROOT_VERSION(6,11,1) class TThread; @@ -332,7 +333,7 @@ class ParticleSourceSimulator : public Simulator virtual int getTotalEventCount() const { return totalEventCount; } virtual bool setup(QJsonObject &json); virtual void updateGeoManager(); - virtual void simulate(); + virtual void simulate(); // TODO watchdogs? virtual void appendToDataHub(EventsDataClass *dataHub); //test purposes - direct tracking with provided stack or photon generation from provided energy deposition @@ -348,10 +349,10 @@ class ParticleSourceSimulator : public Simulator void clearParticleStack(); //local objects - PrimaryParticleTracker* ParticleTracker; - S1_Generator* S1generator; - S2_Generator* S2generator; - ParticleSourcesClass *ParticleSources; + PrimaryParticleTracker* ParticleTracker = 0; + S1_Generator* S1generator = 0; + S2_Generator* S2generator = 0; + AParticleGun* ParticleGun = 0; QVector EnergyVector; QVector ParticleStack; From d49715eb6e7973b66c8b44019d616c7dfb85974c Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 20 Oct 2018 10:59:15 +0100 Subject: [PATCH 105/140] ++ --- .../MainWindowParticleSimulation.cpp | 23 ++-- src/gui/mainwindow.ui | 2 +- src/modules/afileparticlegenerator.cpp | 126 +++++++++++------- src/modules/afileparticlegenerator.h | 30 +++-- src/modules/simulationmanager.cpp | 4 +- 5 files changed, 108 insertions(+), 77 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 4a0e75e1..a74fc63b 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -23,6 +23,7 @@ #include "simulationmanager.h" #include "exampleswindow.h" #include "aconfiguration.h" +#include "afileparticlegenerator.h" //Qt #include @@ -817,31 +818,35 @@ void MainWindow::on_pbGenerateFromFile_Change_clicked() void MainWindow::on_leGenerateFromFile_FileName_editingFinished() { - SimulationManager->FileParticleGenerator->SetFileName(ui->leGenerateFromFile_FileName->text()); + QString newName = ui->leGenerateFromFile_FileName->text(); + if (newName == SimulationManager->FileParticleGenerator->GetFileName()) return; + + SimulationManager->FileParticleGenerator->SetFileName(newName); on_pbUpdateSimConfig_clicked(); } -#include "afileparticlegenerator.h" void MainWindow::on_pbGenerateFromFile_Check_clicked() { + AFileParticleGenerator* pg = SimulationManager->FileParticleGenerator; ui->labGenerateFromFile_info->setText(""); int numParticles = MpCollection->countParticles(); - AParticleFileStat stat = AFileParticleGenerator::InspectFile(ui->leGenerateFromFile_FileName->text(), numParticles); - if (!stat.ErrorString.isEmpty()) + pg->InvalidateFile(); + + if (!pg->Init()) { - message(stat.ErrorString, this); + message(pg->GetErrorString(), this); return; } QString s; - s += QString("Events: %1\n").arg(stat.numEvents); - if (stat.numMultipleEvents > 0) s += QString("Multiple events: %1\n").arg(stat.numMultipleEvents); + s += QString("Events: %1\n").arg(pg->statNumEvents); + if (pg->statNumMultipleEvents > 0) s += QString("Multiple events: %1\n").arg(pg->statNumMultipleEvents); s += "Particle distribution:\n"; for (int ip = 0; ip < numParticles; ip++) { - if (stat.ParticleStat.at(ip) > 0) - s += QString(" %1 - %2\n").arg(MpCollection->getParticleName(ip)).arg(stat.ParticleStat.at(ip)); + if (pg->statParticleQuantity.at(ip) > 0) + s += QString(" %1 - %2\n").arg(MpCollection->getParticleName(ip)).arg(pg->statParticleQuantity.at(ip)); } ui->labGenerateFromFile_info->setText(s); } diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index d724061c..c876688c 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9687,7 +9687,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - 0 + 1 diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 4d9d036f..b6be99ad 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -1,10 +1,23 @@ #include "afileparticlegenerator.h" +#include "amaterialparticlecolection.h" #include "ajsontools.h" #include #include #include #include +#include + +AFileParticleGenerator::AFileParticleGenerator(const AMaterialParticleCollection & MpCollection) : + MpCollection(MpCollection) {} + +void AFileParticleGenerator::SetFileName(const QString &fileName) +{ + if (FileName == fileName) return; + + FileName = fileName; + clearFileStat(); +} bool AFileParticleGenerator::Init() { @@ -20,6 +33,54 @@ bool AFileParticleGenerator::Init() if (Stream) delete Stream; Stream = 0; Stream = new QTextStream(&File); + + QFileInfo fi(File); + if (FileLastModified != fi.lastModified() || RegisteredParticleCount != MpCollection.countParticles()) //requires inspection + { + qDebug() << "Inspecting file:" << FileName; + RegisteredParticleCount = MpCollection.countParticles(); + clearFileStat(); // resizes statParticleQuantity container according to RegisteredParticleCount + + FileLastModified = fi.lastModified(); + + bool bContinueEvent = false; + while (!Stream->atEnd()) + { + const QString line = Stream->readLine(); + QStringList f = line.split(rx, QString::SkipEmptyParts); + + if (f.size() < 8) continue; + + bool bOK; + int pId = f.at(0).toInt(&bOK); + if (!bOK) continue; //assuming this is a comment line + if (pId < 0 || pId >= RegisteredParticleCount) + { + ErrorString = QString("Invalid particle index %1 in file %2").arg(pId).arg(FileName); + return false; + } + statParticleQuantity[pId]++; + + /* + double energy = f.at(1).toDouble(); + double x = f.at(2).toDouble(); + double y = f.at(3).toDouble(); + double z = f.at(4).toDouble(); + double vx = f.at(5).toDouble(); + double vy = f.at(6).toDouble(); + double vz = f.at(7).toDouble(); + */ + + if (!bContinueEvent) statNumEvents++; + + if (f.size() > 8 && f.at(8) == '*') + { + if (!bContinueEvent) statNumMultipleEvents++; + bContinueEvent = true; + } + else bContinueEvent = false; + } + } return true; } @@ -67,6 +128,11 @@ const QString AFileParticleGenerator::CheckConfiguration() const return ""; //TODO } +void AFileParticleGenerator::RemoveParticle(int) +{ + qWarning() << "Remove particle has no effect for AFileParticleGenerator"; +} + bool AFileParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const { return false; //TODO @@ -113,58 +179,16 @@ void AFileParticleGenerator::SetStartEvent(int startEvent) } } -const AParticleFileStat AFileParticleGenerator::InspectFile(const QString &fname, int ParticleCount) +void AFileParticleGenerator::InvalidateFile() { - AParticleFileStat stat; - stat.ParticleStat = QVector(ParticleCount, 0); - - QFile file(fname); - if(!file.open(QIODevice::ReadOnly | QFile::Text)) - { - stat.ErrorString = QString("Cannot open file %1").arg(fname); - return stat; - } - - QRegularExpression rx("(\\ |\\,|\\:|\\t)"); //Not synchronized with the class! - QTextStream in(&file); - bool bContinueEvent = false; - while(!in.atEnd()) - { - const QString line = in.readLine(); - QStringList f = line.split(rx, QString::SkipEmptyParts); - - if (f.size() < 8) continue; - - bool bOK; - int pId = f.at(0).toInt(&bOK); - if (!bOK) continue; //assuming this is a comment line - if (pId < 0 || pId >= ParticleCount) - { - stat.ErrorString = QString("Invalid particle index %1 in file %2").arg(pId).arg(fname); - return stat; - } - stat.ParticleStat[pId]++; - - /* - double energy = f.at(1).toDouble(); - double x = f.at(2).toDouble(); - double y = f.at(3).toDouble(); - double z = f.at(4).toDouble(); - double vx = f.at(5).toDouble(); - double vy = f.at(6).toDouble(); - double vz = f.at(7).toDouble(); - */ - - if (!bContinueEvent) stat.numEvents++; + clearFileStat(); +} - if (f.size() > 8 && f.at(8) == '*') - { - if (!bContinueEvent) stat.numMultipleEvents++; - bContinueEvent = true; - } - else bContinueEvent = false; - } +void AFileParticleGenerator::clearFileStat() +{ + FileLastModified = QDateTime(); //will force to inspect file on next use - file.close(); - return stat; + statNumEvents = 0; + statNumMultipleEvents = 0; + statParticleQuantity = QVector(RegisteredParticleCount, 0); } diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 2e3d4b19..1430f039 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -8,24 +8,18 @@ #include #include #include +#include +class AMaterialParticleCollection; class QTextStream; -class AParticleFileStat -{ -public: - int numEvents = 0; - int numMultipleEvents = 0; - QVector ParticleStat; - QString ErrorString; -}; - class AFileParticleGenerator : public AParticleGun { public: + AFileParticleGenerator(const AMaterialParticleCollection& MpCollection); virtual ~AFileParticleGenerator(){} - void SetFileName(const QString &fileName) {FileName = fileName;} + void SetFileName(const QString &fileName); const QString GetFileName() const {return FileName;} virtual bool Init() override; //called before first use @@ -34,7 +28,7 @@ class AFileParticleGenerator : public AParticleGun virtual const QString CheckConfiguration() const override; //check consistency of the configuration - virtual void RemoveParticle(int particleId) override {} //cannot be used for this class + virtual void RemoveParticle(int particleId) override; //cannot be used for this class virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; virtual void writeToJson(QJsonObject& json) const override; @@ -42,18 +36,26 @@ class AFileParticleGenerator : public AParticleGun virtual void SetStartEvent(int startEvent) override; + void InvalidateFile(); //signals that the file has to be inspected again + + //public file inspect results + int statNumEvents = 0; + int statNumMultipleEvents = 0; + QVector statParticleQuantity; + private: + const AMaterialParticleCollection & MpCollection; QString FileName; QFile File; const QRegularExpression rx = QRegularExpression("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' + int RegisteredParticleCount = -1; QTextStream* Stream = 0; + QDateTime FileLastModified; private: - //bool readLine(); + void clearFileStat(); -public: - static const AParticleFileStat InspectFile(const QString& fname, int ParticleCount); //TODO remove static }; #endif // AFILEPARTICLEGENERATOR_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 16fe25c9..eb3b6280 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1485,7 +1485,7 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) } else { - ParticleGun = new AFileParticleGenerator(); + ParticleGun = new AFileParticleGenerator(*detector->MpCollection); ParticleGun->readFromJson(fjs); } @@ -1812,7 +1812,7 @@ ASimulationManager::ASimulationManager(EventsDataClass* EventsDataHub, DetectorC ParticleSources = new ParticleSourcesClass(Detector, Detector->RandGen); //qDebug() << "->Container for particle sources created and configured"; - FileParticleGenerator = new AFileParticleGenerator(); + FileParticleGenerator = new AFileParticleGenerator(*Detector->MpCollection); Runner = new ASimulatorRunner(Detector, EventsDataHub); From d2c231edcc60098d57b664c4ce91ece96a37609f Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 20 Oct 2018 11:18:04 +0100 Subject: [PATCH 106/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 1 + .../MainWindowParticleSimulation.cpp | 36 +++++++++++++------ src/gui/mainwindow.h | 2 ++ src/gui/mainwindow.ui | 6 ++-- src/modules/afileparticlegenerator.cpp | 6 ++++ src/modules/afileparticlegenerator.h | 1 + 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index e4422d85..ba988bac 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -162,6 +162,7 @@ MainWindow::MainWindow(DetectorClass *Detector, QObject::connect(Config, SIGNAL(requestLRFGuiUpdate()), lrfwindow, SLOT(onRequestGuiUpdate())); QObject::connect(Config, SIGNAL(NewConfigLoaded()), this, SLOT(onNewConfigLoaded())); QObject::connect(Config, &AConfiguration::requestGuiBusyStatusChange, WindowNavigator, &WindowNavigatorClass::ChangeGuiBusyStatus); + QObject::connect(MpCollection, &AMaterialParticleCollection::ParticleCollectionChanged, this, &MainWindow::updateFileParticleGeneratorGui); QObject::connect(EventsDataHub, SIGNAL(loaded(int, int)), this, SLOT(updateLoaded(int, int))); QObject::connect(this, SIGNAL(RequestStopLoad()), EventsDataHub, SLOT(onRequestStopLoad())); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index a74fc63b..be079d25 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -828,25 +828,39 @@ void MainWindow::on_leGenerateFromFile_FileName_editingFinished() void MainWindow::on_pbGenerateFromFile_Check_clicked() { AFileParticleGenerator* pg = SimulationManager->FileParticleGenerator; - ui->labGenerateFromFile_info->setText(""); - int numParticles = MpCollection->countParticles(); - pg->InvalidateFile(); - if (!pg->Init()) - { message(pg->GetErrorString(), this); + + updateFileParticleGeneratorGui(); +} + +void MainWindow::updateFileParticleGeneratorGui() +{ + AFileParticleGenerator* pg = SimulationManager->FileParticleGenerator; + + QFileInfo fi(pg->GetFileName()); + if (!fi.exists()) + { + ui->labGenerateFromFile_info->setText("File not found"); return; } QString s; - s += QString("Events: %1\n").arg(pg->statNumEvents); - if (pg->statNumMultipleEvents > 0) s += QString("Multiple events: %1\n").arg(pg->statNumMultipleEvents); - s += "Particle distribution:\n"; - for (int ip = 0; ip < numParticles; ip++) + if (pg->IsValidated()) { - if (pg->statParticleQuantity.at(ip) > 0) - s += QString(" %1 - %2\n").arg(MpCollection->getParticleName(ip)).arg(pg->statParticleQuantity.at(ip)); + s += QString("Events: %1\n").arg(pg->statNumEvents); + if (pg->statNumMultipleEvents > 0) s += QString("Multiple events: %1\n").arg(pg->statNumMultipleEvents); + + int numParticles = MpCollection->countParticles(); + s += "Particle distribution:\n"; + for (int ip = 0; ip < numParticles; ip++) + { + if (pg->statParticleQuantity.at(ip) > 0) + s += QString(" %1 - %2\n").arg(MpCollection->getParticleName(ip)).arg(pg->statParticleQuantity.at(ip)); + } } + else s = "Click 'Analyse file' to see statistics"; + ui->labGenerateFromFile_info->setText(s); } diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 3d5ebcec..891c1556 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -227,6 +227,8 @@ public slots: void ShowGeometrySlot(); private slots: + void updateFileParticleGeneratorGui(); + void on_pbAddParticleToStack_clicked(); void on_pbRemoveFromStack_clicked(); void on_pbRefreshMaterials_clicked(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index c876688c..7232081e 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -10035,15 +10035,15 @@ Right click: toggle build particle tracks. Also switch off building photon track - Check file + Analyse file - 10 + 50 100 - 491 + 451 111 diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index b6be99ad..fccd3514 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -184,6 +184,12 @@ void AFileParticleGenerator::InvalidateFile() clearFileStat(); } +bool AFileParticleGenerator::IsValidated() const +{ + QFileInfo fi(File); + return (fi.exists() && FileLastModified == fi.lastModified() && RegisteredParticleCount == MpCollection.countParticles()); +} + void AFileParticleGenerator::clearFileStat() { FileLastModified = QDateTime(); //will force to inspect file on next use diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 1430f039..e97300e3 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -37,6 +37,7 @@ class AFileParticleGenerator : public AParticleGun virtual void SetStartEvent(int startEvent) override; void InvalidateFile(); //signals that the file has to be inspected again + bool IsValidated() const; //public file inspect results int statNumEvents = 0; From 7002816c37d282dcd99f5530e8c55376bbeff8ba Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 20 Oct 2018 18:19:50 +0100 Subject: [PATCH 107/140] ++ --- src/common/ajsontools.cpp | 13 ++++++++++++- src/common/ajsontools.h | 1 + .../MainWindowParticleSimulation.cpp | 15 +++++++++++---- src/gui/MainWindowTools/mainwindowjson.cpp | 3 ++- src/modules/afileparticlegenerator.cpp | 16 +++++++++++++--- src/modules/afileparticlegenerator.h | 12 +++++++----- 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/common/ajsontools.cpp b/src/common/ajsontools.cpp index 57ebfb0d..2615fc10 100644 --- a/src/common/ajsontools.cpp +++ b/src/common/ajsontools.cpp @@ -34,6 +34,18 @@ bool parseJson(const QJsonObject &json, const QString &key, int &var) } else return false; } + +bool parseJson(const QJsonObject &json, const QString &key, qint64 &var) +{ + if (json.contains(key)) + { + double val = json[key].toDouble(); + var = val; + return true; + } + else return false; +} + bool parseJson(const QJsonObject &json, const QString &key, double &var) { if (json.contains(key)) @@ -277,4 +289,3 @@ const QString jsonToString(const QJsonObject &json) QString s( doc.toJson(QJsonDocument::Compact) ); return s; } - diff --git a/src/common/ajsontools.h b/src/common/ajsontools.h index 9a3d7295..ad2cd070 100644 --- a/src/common/ajsontools.h +++ b/src/common/ajsontools.h @@ -15,6 +15,7 @@ class TH1D; bool parseJson(const QJsonObject &json, const QString &key, bool &var); bool parseJson(const QJsonObject &json, const QString &key, int &var); //can convert double content of the key to int - uses std::round +bool parseJson(const QJsonObject &json, const QString &key, qint64 &var); //can convert double content of the key to int - uses std::round bool parseJson(const QJsonObject &json, const QString &key, double &var); bool parseJson(const QJsonObject &json, const QString &key, float &var); bool parseJson(const QJsonObject &json, const QString &key, QString &var); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index be079d25..0db3f54d 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -849,16 +849,23 @@ void MainWindow::updateFileParticleGeneratorGui() QString s; if (pg->IsValidated()) { - s += QString("Events: %1\n").arg(pg->statNumEvents); - if (pg->statNumMultipleEvents > 0) s += QString("Multiple events: %1\n").arg(pg->statNumMultipleEvents); + s += QString("%1 events in the file").arg(pg->NumEventsInFile); + if (pg->statNumMultipleEvents > 0) s += QString(", including %1 multiple events").arg(pg->statNumMultipleEvents); + s += "\n\n"; + + QString pd; + bool bFound = false; int numParticles = MpCollection->countParticles(); - s += "Particle distribution:\n"; for (int ip = 0; ip < numParticles; ip++) { if (pg->statParticleQuantity.at(ip) > 0) - s += QString(" %1 - %2\n").arg(MpCollection->getParticleName(ip)).arg(pg->statParticleQuantity.at(ip)); + { + pd += QString(" %2 %1\n").arg(MpCollection->getParticleName(ip)).arg(pg->statParticleQuantity.at(ip)); + bFound = true; + } } + if (bFound) s += "Particle distribution:\n" + pd; } else s = "Click 'Analyse file' to see statistics"; diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 27fbf9e1..d305b5cb 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -583,12 +583,13 @@ if (scj.contains("CustomDistrib")) //generation from file QJsonObject fjs; - parseJson(js, "GenerationFromFile", fjs); + parseJson(psjs, "GenerationFromFile", fjs); if (!fjs.isEmpty()) { SimulationManager->FileParticleGenerator->readFromJson(fjs); ui->leGenerateFromFile_FileName->setText(SimulationManager->FileParticleGenerator->GetFileName()); } + updateFileParticleGeneratorGui(); on_pbUpdateSourcesIndication_clicked(); diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index fccd3514..071c99ec 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -71,7 +71,7 @@ bool AFileParticleGenerator::Init() double vz = f.at(7).toDouble(); */ - if (!bContinueEvent) statNumEvents++; + if (!bContinueEvent) NumEventsInFile++; if (f.size() > 8 && f.at(8) == '*') { @@ -141,10 +141,20 @@ bool AFileParticleGenerator::IsParticleInUse(int particleId, QString &SourceName void AFileParticleGenerator::writeToJson(QJsonObject &json) const { json["FileName"] = FileName; + + json["NumEventsInFile"] = NumEventsInFile; + json["RegisteredParticleCount"] = RegisteredParticleCount; + json["FileLastModified"] = FileLastModified.toMSecsSinceEpoch(); } bool AFileParticleGenerator::readFromJson(const QJsonObject &json) { + parseJson(json, "NumEventsInFile", NumEventsInFile); + parseJson(json, "RegisteredParticleCount", RegisteredParticleCount); + qint64 lastMod; + parseJson(json, "FileLastModified", lastMod); + FileLastModified = QDateTime::fromMSecsSinceEpoch(lastMod); + return parseJson(json, "FileName", FileName); } @@ -186,7 +196,7 @@ void AFileParticleGenerator::InvalidateFile() bool AFileParticleGenerator::IsValidated() const { - QFileInfo fi(File); + QFileInfo fi(FileName); return (fi.exists() && FileLastModified == fi.lastModified() && RegisteredParticleCount == MpCollection.countParticles()); } @@ -194,7 +204,7 @@ void AFileParticleGenerator::clearFileStat() { FileLastModified = QDateTime(); //will force to inspect file on next use - statNumEvents = 0; + NumEventsInFile = 0; statNumMultipleEvents = 0; statParticleQuantity = QVector(RegisteredParticleCount, 0); } diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index e97300e3..b6c53c68 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -36,11 +36,11 @@ class AFileParticleGenerator : public AParticleGun virtual void SetStartEvent(int startEvent) override; - void InvalidateFile(); //signals that the file has to be inspected again + void InvalidateFile(); //signals that the file has to be inspected again by running Init() bool IsValidated() const; //public file inspect results - int statNumEvents = 0; + int NumEventsInFile = 0; //saved int statNumMultipleEvents = 0; QVector statParticleQuantity; @@ -48,11 +48,13 @@ class AFileParticleGenerator : public AParticleGun const AMaterialParticleCollection & MpCollection; QString FileName; QFile File; + QTextStream* Stream = 0; + const QRegularExpression rx = QRegularExpression("(\\ |\\,|\\:|\\t)"); //separators: ' ' or ',' or ':' or '\t' - int RegisteredParticleCount = -1; - QTextStream* Stream = 0; - QDateTime FileLastModified; + int RegisteredParticleCount = -1; //saved - used in validity check + QDateTime FileLastModified; //saved - used in validity check + private: void clearFileStat(); From cad905ff7ed540204395d45c4c44bd400e07fcbe Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 20 Oct 2018 18:35:45 +0100 Subject: [PATCH 108/140] ++ --- src/modules/simulationmanager.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index eb3b6280..bc6ba327 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1444,9 +1444,7 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) return false; } totalEventCount = cjs["EventsToDo"].toInt(); - fAllowMultiple = cjs["AllowMultipleParticles"].toBool(); - AverageNumParticlesPerEvent = cjs["AverageParticlesPerEvent"].toDouble(); - TypeParticlesPerEvent = cjs["TypeParticlesPerEvent"].toInt(); + fAllowMultiple = false; //only applies to 'Sources' mode fDoS1 = cjs["DoS1"].toBool(); fDoS2 = cjs["DoS2"].toBool(); fBuildParticleTracks = simSettings->TrackBuildOptions.bBuildParticleTracks; @@ -1466,6 +1464,10 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) { ParticleGun = new ParticleSourcesClass(detector, RandGen); ParticleGun->readFromJson(js); + + fAllowMultiple = cjs["AllowMultipleParticles"].toBool(); + AverageNumParticlesPerEvent = cjs["AverageParticlesPerEvent"].toDouble(); + TypeParticlesPerEvent = cjs["TypeParticlesPerEvent"].toInt(); } else { @@ -1509,6 +1511,8 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) return false; } + //update config according to the selected generation mode + if (PartGenMode == "File") totalEventCount = static_cast(ParticleGun)->NumEventsInFile; //inits ParticleTracker->configure(simSettings, fBuildParticleTracks, &tracks, fIgnoreNoDepoEvents); ParticleTracker->resetCounter(); From 43797a74f3e3498dada77c74812e157002bf91cc Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 27 Oct 2018 10:46:44 +0100 Subject: [PATCH 109/140] started merging particleonstack and generatedparticle --- src/ants2.pro | 9 ++- src/common/aparticleonstack.h | 33 ---------- src/common/aparticlerecord.cpp | 63 +++++++++++++++++++ src/common/aparticlerecord.h | 27 ++++++++ src/common/aphoton.cpp | 8 ++- src/gui/MainWindowTools/MainWindowDiskIO.cpp | 1 - .../MainWindowParticleSimulation.cpp | 4 +- .../MainWindowTools/MainWindowParticles.cpp | 1 - src/gui/MainWindowTools/mainwindowjson.cpp | 1 - src/gui/mainwindow.h | 4 +- src/modules/primaryparticletracker.cpp | 14 ++--- src/modules/primaryparticletracker.h | 6 +- src/modules/simulationmanager.cpp | 6 +- src/modules/simulationmanager.h | 6 +- src/scriptmode/ainterfacetodeposcript.cpp | 12 +--- src/scriptmode/ainterfacetodeposcript.h | 4 +- .../aparticlegeneratorinterface.cpp | 44 +++++++++++++ src/scriptmode/aparticlegeneratorinterface.h | 32 ++++++++++ 18 files changed, 201 insertions(+), 74 deletions(-) delete mode 100644 src/common/aparticleonstack.h create mode 100644 src/common/aparticlerecord.cpp create mode 100644 src/common/aparticlerecord.h create mode 100644 src/scriptmode/aparticlegeneratorinterface.cpp create mode 100644 src/scriptmode/aparticlegeneratorinterface.h diff --git a/src/ants2.pro b/src/ants2.pro index d4cc3133..d53f718f 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -359,7 +359,9 @@ SOURCES += main.cpp \ common/aglobalsettings.cpp \ common/aparticlesourcerecord.cpp \ modules/ascriptparticlegenerator.cpp \ - modules/afileparticlegenerator.cpp + modules/afileparticlegenerator.cpp \ + scriptmode/aparticlegeneratorinterface.cpp \ + common/aparticlerecord.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -495,7 +497,9 @@ HEADERS += common/CorrelationFilters.h \ common/aparticlesourcerecord.h \ common/aparticlegun.h \ modules/ascriptparticlegenerator.h \ - modules/afileparticlegenerator.h + modules/afileparticlegenerator.h \ + scriptmode/aparticlegeneratorinterface.h \ + common/aparticlerecord.h # --- SIM --- ants2_SIM { @@ -520,7 +524,6 @@ ants2_SIM { common/atrackrecords.h \ common/dotstgeostruct.h \ common/aenergydepositioncell.h \ - common/aparticleonstack.h \ common/ahistoryrecords.h \ common/asimulationstatistics.h \ modules/primaryparticletracker.h \ diff --git a/src/common/aparticleonstack.h b/src/common/aparticleonstack.h deleted file mode 100644 index 3a85ac24..00000000 --- a/src/common/aparticleonstack.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef APARTICLEONSTACK -#define APARTICLEONSTACK - -class AParticleOnStack //element of the particle stack -{ - public: - AParticleOnStack(int Id, - double x, double y, double z, - double vx, double vy, double vz, - double time, double energy, - int secondaryOf = -1) : - Id(Id), time(time), energy(energy), secondaryOf(secondaryOf) - { - r[0]=x; r[1]=y; r[2]=z; - v[0]=vx; v[1]=vy; v[2]=vz; - } - AParticleOnStack(){} - - int Id; - double r[3]; //starting point - double v[3]; //starting vector - double time; //time on start - double energy; //staring energy - int secondaryOf; //use in primary tracker to designate secondary particles and link to their primary - - AParticleOnStack* clone() - { - return new AParticleOnStack(Id, r[0], r[1], r[2], v[0], v[1], v[2], time, energy, secondaryOf); - } -}; - -#endif // APARTICLEONSTACK - diff --git a/src/common/aparticlerecord.cpp b/src/common/aparticlerecord.cpp new file mode 100644 index 00000000..7b7dc739 --- /dev/null +++ b/src/common/aparticlerecord.cpp @@ -0,0 +1,63 @@ +#include "aparticlerecord.h" + +#include "TMath.h" +#include "TRandom2.h" + +AParticleRecord::AParticleRecord(int Id, + double x, double y, double z, + double vx, double vy, double vz, + double time, double energy, + int secondaryOf) : + Id(Id), time(time), energy(energy), secondaryOf(secondaryOf) +{ + r[0] = x; + r[1] = y; + r[2] = z; + + v[0] = vx; + v[1] = vy; + v[2] = vz; +} + +AParticleRecord *AParticleRecord::clone() +{ + return new AParticleRecord(Id, r[0], r[1], r[2], v[0], v[1], v[2], time, energy, secondaryOf); +} + +void AParticleRecord::ensureUnitaryLength() +{ + double mod = 0; + for (int i=0; i<3; i++) + mod += ( v[i] * v[i] ); + + if (mod == 1.0) return; + mod = TMath::Sqrt(mod); + + if (mod != 0) + { + for (int i=0; i<3; i++) + v[i] /= mod; + } + else + { + v[0] = 0; + v[1] = 0; + v[2] = 1.0; + } +} + +void AParticleRecord::randomDir(TRandom2 *RandGen) +{ + //Sphere function of Root: + double a = 0, b = 0, r2 = 1.0; + while (r2 > 0.25) + { + a = RandGen->Rndm() - 0.5; + b = RandGen->Rndm() - 0.5; + r2 = a*a + b*b; + } + v[2] = ( -1.0 + 8.0 * r2 ); + double scale = 8.0 * TMath::Sqrt(0.25 - r2); + v[0] = a*scale; + v[1] = b*scale; +} diff --git a/src/common/aparticlerecord.h b/src/common/aparticlerecord.h new file mode 100644 index 00000000..665b1838 --- /dev/null +++ b/src/common/aparticlerecord.h @@ -0,0 +1,27 @@ +#ifndef APARTICLERECORD_H +#define APARTICLERECORD_H + +class TRandom2; + +class AParticleRecord +{ +public: + AParticleRecord(int Id, + double x, double y, double z, + double vx, double vy, double vz, + double time, double energy, + int secondaryOf = -1); + + int Id; //type of particle in MatPart collection + double r[3]; //starting point + double v[3]; //starting vector + double time; //time on start + double energy; //staring energy + int secondaryOf; //use in primary tracker to designate secondary particles and link to their primary + + AParticleRecord * clone(); // TODO no need? + void ensureUnitaryLength(); + void randomDir(TRandom2 * RandGen); +}; + +#endif // APARTICLERECORD_H diff --git a/src/common/aphoton.cpp b/src/common/aphoton.cpp index ae6054a1..c99ea42f 100644 --- a/src/common/aphoton.cpp +++ b/src/common/aphoton.cpp @@ -8,8 +8,8 @@ APhoton::APhoton() {} APhoton::APhoton(double *xyz, double *Vxyz, int waveIndex, double time) : time(time), waveIndex(waveIndex), scint_type(0) { - r[0]=xyz[0]; r[1]=xyz[1]; r[2]=xyz[2]; - v[0]=Vxyz[0]; v[1]=Vxyz[1]; v[2]=Vxyz[2]; + r[0] = xyz[0]; r[1] = xyz[1]; r[2] = xyz[2]; + v[0] = Vxyz[0]; v[1] = Vxyz[1]; v[2] = Vxyz[2]; } void APhoton::CopyFrom(const APhoton *CopyFrom) @@ -32,9 +32,11 @@ void APhoton::CopyFrom(const APhoton *CopyFrom) void APhoton::EnsureUnitaryLength() { - double mod; + double mod = 0; for (int i=0; i<3; i++) mod += ( v[i] * v[i] ); + + if (mod == 1.0) return; mod = TMath::Sqrt(mod); if (mod != 0) diff --git a/src/gui/MainWindowTools/MainWindowDiskIO.cpp b/src/gui/MainWindowTools/MainWindowDiskIO.cpp index e4ce9a5d..e8b4eb85 100644 --- a/src/gui/MainWindowTools/MainWindowDiskIO.cpp +++ b/src/gui/MainWindowTools/MainWindowDiskIO.cpp @@ -17,7 +17,6 @@ #include "aenergydepositioncell.h" #include "afiletools.h" #include "amessage.h" -#include "aparticleonstack.h" #include "aconfiguration.h" #include "tmpobjhubclass.h" #include "apmgroupsmanager.h" diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 0db3f54d..fa46a09f 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -15,7 +15,7 @@ #include "amaterialparticlecolection.h" #include "ageomarkerclass.h" #include "ajsontools.h" -#include "aparticleonstack.h" +#include "aparticlerecord.h" #include "amessage.h" #include "acommonfunctions.h" #include "guiutils.h" @@ -630,7 +630,7 @@ void MainWindow::on_pbAddParticleToStack_clicked() ParticleStack.reserve(ParticleStack.size() + numCopies); for (int i=0; icobParticleToStack->currentIndex(), + AParticleRecord *tmp = new AParticleRecord(ui->cobParticleToStack->currentIndex(), ui->ledParticleStackX->text().toDouble(), ui->ledParticleStackY->text().toDouble(), ui->ledParticleStackZ->text().toDouble(), ui->ledParticleStackVx->text().toDouble(), ui->ledParticleStackVy->text().toDouble(), ui->ledParticleStackVz->text().toDouble(), ui->ledParticleStackTime->text().toDouble(), ui->ledParticleStackEnergy->text().toDouble()); diff --git a/src/gui/MainWindowTools/MainWindowParticles.cpp b/src/gui/MainWindowTools/MainWindowParticles.cpp index 0a262606..75e9e442 100644 --- a/src/gui/MainWindowTools/MainWindowParticles.cpp +++ b/src/gui/MainWindowTools/MainWindowParticles.cpp @@ -5,7 +5,6 @@ #include "materialinspectorwindow.h" #include "outputwindow.h" #include "detectorclass.h" -#include "aparticleonstack.h" #include "particlesourcesclass.h" #include "amessage.h" #include "aconfiguration.h" diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index d305b5cb..b0f43fd8 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -11,7 +11,6 @@ #include "aconfiguration.h" #include "ajsontools.h" #include "particlesourcesclass.h" -#include "aparticleonstack.h" #include "apmhub.h" #include "eventsdataclass.h" #include "tmpobjhubclass.h" diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 891c1556..a37ad60c 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -14,7 +14,7 @@ class AConfiguration; class AGlobalSettings; struct AEnergyDepositionCell; class GeoMarkerClass; -class AParticleOnStack; +class AParticleRecord; class AMaterialParticleCollection; class EventsDataClass; class GeneralSimSettings; @@ -125,7 +125,7 @@ class MainWindow : public QMainWindow //local data, just for GUI QVector EnergyVector; QVector GeoMarkers; - QVector ParticleStack; + QVector ParticleStack; InterfaceToPMscript* PMscriptInterface = 0; // if created -> managed by the script manager diff --git a/src/modules/primaryparticletracker.cpp b/src/modules/primaryparticletracker.cpp index 005eab60..993bda43 100644 --- a/src/modules/primaryparticletracker.cpp +++ b/src/modules/primaryparticletracker.cpp @@ -4,7 +4,7 @@ #include "acompton.h" #include "atrackrecords.h" #include "aenergydepositioncell.h" -#include "aparticleonstack.h" +#include "aparticlerecord.h" #include "ahistoryrecords.h" #include "acommonfunctions.h" #include "asimulationstatistics.h" @@ -22,7 +22,7 @@ PrimaryParticleTracker::PrimaryParticleTracker(TGeoManager *geoManager, TRandom2 *RandomGenerator, AMaterialParticleCollection* MpCollection, - QVector* particleStack, + QVector* particleStack, QVector* energyVector, QVector* eventHistory, ASimulationStatistics *simStat, int threadIndex, @@ -384,7 +384,7 @@ bool PrimaryParticleTracker::TrackParticlesOnStack(int eventId) EnergyVector->append(tc); //creating gamma and putting it on stack - AParticleOnStack *tmp = new AParticleOnStack(ParticleId, r[0],r[1],r[2], G1.direction[0], G1.direction[1], G1.direction[2], time, G1.energy, counter); + AParticleRecord *tmp = new AParticleRecord(ParticleId, r[0],r[1],r[2], G1.direction[0], G1.direction[1], G1.direction[2], time, G1.energy, counter); ParticleStack->append(tmp); //creating electron //int IdElectron = @@ -497,7 +497,7 @@ bool PrimaryParticleTracker::TrackParticlesOnStack(int eventId) GenerateRandomDirection(vv); // qDebug() << " in random direction"; } - AParticleOnStack* pp = new AParticleOnStack(ParticleId, r[0], r[1], r[2], vv[0], vv[1], vv[2], time, energy, counter); + AParticleRecord* pp = new AParticleRecord(ParticleId, r[0], r[1], r[2], vv[0], vv[1], vv[2], time, energy, counter); ParticleStack->append(pp); } } @@ -523,9 +523,9 @@ bool PrimaryParticleTracker::TrackParticlesOnStack(int eventId) //creating two gammas from positron anihilation and putting it on stack double vv[3]; GenerateRandomDirection(vv); - AParticleOnStack* tmp = new AParticleOnStack(ParticleId, r[0],r[1],r[2], vv[0], vv[1], vv[2], time, 511, counter); + AParticleRecord* tmp = new AParticleRecord(ParticleId, r[0],r[1],r[2], vv[0], vv[1], vv[2], time, 511, counter); ParticleStack->append(tmp); - tmp = new AParticleOnStack(ParticleId, r[0],r[1],r[2], -vv[0], -vv[1], -vv[2], time, 511, counter); + tmp = new AParticleRecord(ParticleId, r[0],r[1],r[2], -vv[0], -vv[1], -vv[2], time, 511, counter); ParticleStack->append(tmp); terminationStatus = EventHistoryStructure::PairProduction;//9 @@ -650,7 +650,7 @@ bool PrimaryParticleTracker::TrackParticlesOnStack(int eventId) if (newEnergy > SimSet->MinEnergyNeutrons * 1.0e-6) // meV -> keV to compare { - AParticleOnStack *tmp = new AParticleOnStack(ParticleId, r[0],r[1], r[2], vnew[0]/vnewMod, vnew[1]/vnewMod, vnew[2]/vnewMod, time, newEnergy, counter); + AParticleRecord *tmp = new AParticleRecord(ParticleId, r[0],r[1], r[2], vnew[0]/vnewMod, vnew[1]/vnewMod, vnew[2]/vnewMod, time, newEnergy, counter); ParticleStack->append(tmp); energyHistory = energy - newEnergy; } diff --git a/src/modules/primaryparticletracker.h b/src/modules/primaryparticletracker.h index d26cce33..b4d4c92b 100644 --- a/src/modules/primaryparticletracker.h +++ b/src/modules/primaryparticletracker.h @@ -8,7 +8,7 @@ class TGeoManager; class TRandom2; class AParticle; class AMaterial; -class AParticleOnStack; +class AParticleRecord; struct AEnergyDepositionCell; struct EventHistoryStructure; class AMaterialParticleCollection; @@ -24,7 +24,7 @@ class PrimaryParticleTracker : public QObject explicit PrimaryParticleTracker(TGeoManager* geoManager, TRandom2* RandomGenerator, AMaterialParticleCollection* MpCollection, - QVector* particleStack, + QVector* particleStack, QVector* energyVector, QVector* eventHistory, ASimulationStatistics* simStat, @@ -55,7 +55,7 @@ public slots: TGeoManager* GeoManager; TRandom2* RandGen; AMaterialParticleCollection* MpCollection; - QVector* ParticleStack; + QVector* ParticleStack; QVector* EnergyVector; QVector* EventHistory; ASimulationStatistics* SimStat; diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index bc6ba327..73a22c32 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -15,7 +15,7 @@ #include "aphotontracer.h" #include "apositionenergyrecords.h" #include "aenergydepositioncell.h" -#include "aparticleonstack.h" +#include "aparticlerecord.h" #include "amessage.h" #include "acommonfunctions.h" #include "ageomarkerclass.h" @@ -1600,7 +1600,7 @@ void ParticleSourceSimulator::simulate() time = timeFrom + timeRange*RandGen->Rndm(); //added TimeFrom 05/02/2015 const AGeneratedParticle &part = GP->at(iPart); - ParticleStack.append(new AParticleOnStack(part.ParticleId, + ParticleStack.append(new AParticleRecord(part.ParticleId, part.Position[0], part.Position[1], part.Position[2], part.Direction[0], part.Direction[1], part.Direction[2], time, part.Energy)); @@ -1674,7 +1674,7 @@ void ParticleSourceSimulator::appendToDataHub(EventsDataClass *dataHub) dataHub->ScanNumberOfRuns = 1; } -bool ParticleSourceSimulator::standaloneTrackStack(QVector *particleStack) +bool ParticleSourceSimulator::standaloneTrackStack(QVector *particleStack) { if (particleStack->isEmpty()) { diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 38ea9723..5cb9f626 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -35,7 +35,7 @@ class TGeoManager; class APhotonTracer; class TrackHolderClass; struct AScanRecord; -class AParticleOnStack; +class AParticleRecord; struct AEnergyDepositionCell; class ASimulatorRunner; class GeoMarkerClass; @@ -337,7 +337,7 @@ class ParticleSourceSimulator : public Simulator virtual void appendToDataHub(EventsDataClass *dataHub); //test purposes - direct tracking with provided stack or photon generation from provided energy deposition - bool standaloneTrackStack(QVector* particleStack); + bool standaloneTrackStack(QVector* particleStack); bool standaloneGenerateLight(QVector* energyVector); protected: @@ -354,7 +354,7 @@ class ParticleSourceSimulator : public Simulator S2_Generator* S2generator = 0; AParticleGun* ParticleGun = 0; QVector EnergyVector; - QVector ParticleStack; + QVector ParticleStack; int totalEventCount; double timeFrom, timeRange; diff --git a/src/scriptmode/ainterfacetodeposcript.cpp b/src/scriptmode/ainterfacetodeposcript.cpp index b80b77dc..c2930b3d 100644 --- a/src/scriptmode/ainterfacetodeposcript.cpp +++ b/src/scriptmode/ainterfacetodeposcript.cpp @@ -1,7 +1,7 @@ #include "ainterfacetodeposcript.h" #include "eventsdataclass.h" #include "aenergydepositioncell.h" -#include "aparticleonstack.h" +#include "aparticlerecord.h" #include "simulationmanager.h" #include "asandwich.h" #include "atrackrecords.h" @@ -81,18 +81,10 @@ void AInterfaceToDepoScript::AddParticleToStack(int particleID, double X, double double Time, double Energy, int numCopies) { -// MW->ParticleStack.reserve(MW->ParticleStack.size() + numCopies); -// for (int i=0; iParticleStack.append(tmp); -// } -// MW->on_pbRefreshStack_clicked(); - ParticleStack.reserve( ParticleStack.size() + numCopies ); for (int i=0; i ParticleStack; + QVector ParticleStack; QVector EnergyVector; QVector PR; diff --git a/src/scriptmode/aparticlegeneratorinterface.cpp b/src/scriptmode/aparticlegeneratorinterface.cpp new file mode 100644 index 00000000..6bfc8f8f --- /dev/null +++ b/src/scriptmode/aparticlegeneratorinterface.cpp @@ -0,0 +1,44 @@ +#include "aparticlegeneratorinterface.h" +#include "amaterialparticlecolection.h" +#include "aparticlerecord.h" + +#include "TMath.h" +#include "TRandom2.h" + +AParticleGeneratorInterface::AParticleGeneratorInterface(const AMaterialParticleCollection *MpCollection, TRandom2 *RandGen) : + MpCollection(MpCollection), RandGen(RandGen) {} + +void AParticleGeneratorInterface::configure(QVector * GeneratedParticles) +{ + GP = GeneratedParticles; +} + +void AParticleGeneratorInterface::AddParticle(int type, double energy, double x, double y, double z, double i, double k, double j, double time) +{ + if (type < 0 || type >= MpCollection->countParticles()) + abort("Invalid particle Id"); + else + { + AParticleRecord * p = new AParticleRecord(type, + x, y, z, + i, k, j, + time, energy); + p->ensureUnitaryLength(); + GP->append(p); + } +} + +void AParticleGeneratorInterface::AddParticleIsotropic(int type, double energy, double x, double y, double z, double time) +{ + if (type < 0 || type >= MpCollection->countParticles()) + abort("Invalid particle Id"); + else + { + AParticleRecord * p = new AParticleRecord(type, + x, y, z, + 0, 0, 1.0, + time, energy); + p->randomDir(RandGen); //will generate unitary length + GP->append(p); + } +} diff --git a/src/scriptmode/aparticlegeneratorinterface.h b/src/scriptmode/aparticlegeneratorinterface.h new file mode 100644 index 00000000..41e5ae18 --- /dev/null +++ b/src/scriptmode/aparticlegeneratorinterface.h @@ -0,0 +1,32 @@ +#ifndef APARTICLEGENERATORINTERFACE_H +#define APARTICLEGENERATORINTERFACE_H + +#include "ascriptinterface.h" + +#include + +class AParticleRecord; +class AMaterialParticleCollection; +class TRandom2; + +class AParticleGeneratorInterface : public AScriptInterface +{ + Q_OBJECT + +public: + AParticleGeneratorInterface(const AMaterialParticleCollection * MpCollection, TRandom2 * RandGen); + + void configure(QVector * GeneratedParticles); + +public slots: + void AddParticle(int type, double energy, double x, double y, double z, double i, double k, double j, double time = 0); + void AddParticleIsotropic(int type, double energy, double x, double y, double z, double time = 0); + +private: + const AMaterialParticleCollection * MpCollection = 0; //external + TRandom2 * RandGen = 0; //external + QVector * GP = 0; //external + +}; + +#endif // APARTICLEGENERATORINTERFACE_H From a348acf13d9a3c2319e584602b290960e647d700 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 27 Oct 2018 11:05:17 +0100 Subject: [PATCH 110/140] ++ --- src/common/aparticlegun.h | 25 ++--------- src/common/aparticlerecord.h | 5 ++- .../MainWindowParticleSimulation.cpp | 22 +++++---- src/modules/afileparticlegenerator.cpp | 11 +++-- src/modules/afileparticlegenerator.h | 2 +- src/modules/ascriptparticlegenerator.cpp | 4 +- src/modules/ascriptparticlegenerator.h | 2 +- src/modules/particlesourcesclass.cpp | 45 +++++++++---------- src/modules/particlesourcesclass.h | 4 +- src/modules/simulationmanager.cpp | 12 ++--- 10 files changed, 57 insertions(+), 75 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 4f18ba4f..f5e15cb7 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -5,27 +5,8 @@ #include class QJsonObject; - -class AGeneratedParticle -{ -public: - AGeneratedParticle(int pId, double energy, double x, double y, double z, double vx, double vy, double vz) : - ParticleId(pId), Energy(energy) - { - Position[0] = x; - Position[1] = y; - Position[2] = z; - Direction[0] = vx; - Direction[1] = vy; - Direction[2] = vz; - } - AGeneratedParticle(){} - - int ParticleId; - double Energy; - double Position[3]; - double Direction[3]; -}; +//class AParticleRecord; +#include "aparticlerecord.h" class AParticleGun { @@ -34,7 +15,7 @@ class AParticleGun virtual bool Init() = 0; //called before first use virtual void ReleaseResources() {} //called after end of operation - virtual QVector* GenerateEvent() = 0; + virtual QVector * GenerateEvent() = 0; virtual const QString CheckConfiguration() const = 0; //check consistency of the configuration diff --git a/src/common/aparticlerecord.h b/src/common/aparticlerecord.h index 665b1838..0ad1b862 100644 --- a/src/common/aparticlerecord.h +++ b/src/common/aparticlerecord.h @@ -11,13 +11,14 @@ class AParticleRecord double vx, double vy, double vz, double time, double energy, int secondaryOf = -1); + AParticleRecord(){} int Id; //type of particle in MatPart collection double r[3]; //starting point double v[3]; //starting vector - double time; //time on start + double time = 0; //time on start double energy; //staring energy - int secondaryOf; //use in primary tracker to designate secondary particles and link to their primary + int secondaryOf = -1; //use in primary tracker to designate secondary particles and link to their primary AParticleRecord * clone(); // TODO no need? void ensureUnitaryLength(); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index fa46a09f..112dc732 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -286,31 +286,29 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) double R[3], K[3]; for (int iRun=0; iRun* GP = Gun->GenerateEvent(); + QVector* GP = Gun->GenerateEvent(); // if (GP->isEmpty() && iRun > 2) // { // message("Did several attempts but no particles were generated!", this); // break; // } - for (const AGeneratedParticle& p : *GP) + for (const AParticleRecord& p : *GP) { - R[0] = p.Position[0]; - R[1] = p.Position[1]; - R[2] = p.Position[2]; + R[0] = p.r[0]; + R[1] = p.r[1]; + R[2] = p.r[2]; - K[0] = p.Direction[0]; - K[1] = p.Direction[1]; - K[2] = p.Direction[2]; + K[0] = p.v[0]; + K[1] = p.v[1]; + K[2] = p.v[2]; Int_t track_index = Detector->GeoManager->AddTrack(1,22); TVirtualGeoTrack *track = Detector->GeoManager->GetTrack(track_index); track->AddPoint(R[0], R[1], R[2], 0); track->AddPoint(R[0] + K[0]*Length, R[1] + K[1]*Length, R[2] + K[2]*Length, 0); - SimulationManager->TrackBuildOptions.applyToParticleTrack(track, p.ParticleId); - //track->SetLineWidth(1); //TODO respect all attributes! - //track->SetLineColor(1 + p.ParticleId); //TODO respect particle track colors! + SimulationManager->TrackBuildOptions.applyToParticleTrack(track, p.Id); - GeoMarkerClass* marks = new GeoMarkerClass("t", 7, 1, SimulationManager->TrackBuildOptions.getParticleColor(p.ParticleId)); + GeoMarkerClass* marks = new GeoMarkerClass("t", 7, 1, SimulationManager->TrackBuildOptions.getParticleColor(p.Id)); marks->SetNextPoint(R[0], R[1], R[2]); GeoMarkers.append(marks); } diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 071c99ec..b1dd2a35 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -90,9 +90,9 @@ void AFileParticleGenerator::ReleaseResources() File.close(); } -QVector * AFileParticleGenerator::GenerateEvent() +QVector *AFileParticleGenerator::GenerateEvent() { - QVector* GeneratedParticles = new QVector; + QVector* GeneratedParticles = new QVector; while (!Stream->atEnd()) { @@ -115,7 +115,12 @@ QVector * AFileParticleGenerator::GenerateEvent() double vy = f.at(6).toDouble(); double vz = f.at(7).toDouble(); - (*GeneratedParticles) << AGeneratedParticle(pId, energy, x, y, z, vx, vy, vz); + //(*GeneratedParticles) << AGeneratedParticle(pId, energy, x, y, z, vx, vy, vz); + (*GeneratedParticles) << AParticleRecord(pId, + x, y, z, + vx, vy, vz, + 0, energy); + //TODO ensure unitary? if (f.size() > 8 && f.at(8) == '*') continue; break; diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index b6c53c68..4e984fc9 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -24,7 +24,7 @@ class AFileParticleGenerator : public AParticleGun virtual bool Init() override; //called before first use virtual void ReleaseResources() override; //called after end of operation - virtual QVector* GenerateEvent(); + virtual QVector* GenerateEvent(); virtual const QString CheckConfiguration() const override; //check consistency of the configuration diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index 73b864b0..dd58bd83 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -10,9 +10,9 @@ bool AScriptParticleGenerator::Init() return true; } -QVector *AScriptParticleGenerator::GenerateEvent() +QVector *AScriptParticleGenerator::GenerateEvent() { - QVector* GeneratedParticles = new QVector; + QVector* GeneratedParticles = new QVector; return GeneratedParticles; } diff --git a/src/modules/ascriptparticlegenerator.h b/src/modules/ascriptparticlegenerator.h index 92460ad0..a6e9dad9 100644 --- a/src/modules/ascriptparticlegenerator.h +++ b/src/modules/ascriptparticlegenerator.h @@ -11,7 +11,7 @@ class AScriptParticleGenerator : public AParticleGun virtual bool Init() override; //called before first use //virtual void ReleaseResources() override {} //called after end of operation - virtual QVector* GenerateEvent(); + virtual QVector* GenerateEvent(); // virtual bool CheckConfiguration() override {return true;} //check consistency of the configuration diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index c217b68a..6ab32dc5 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -110,11 +110,11 @@ bool ParticleSourcesClass::Init() return true; //TODO check for fails } -QVector* ParticleSourcesClass::GenerateEvent() +QVector *ParticleSourcesClass::GenerateEvent() { //after any operation with sources (add, remove), init should be called before first use! - QVector* GeneratedParticles = new QVector; + QVector* GeneratedParticles = new QVector; //selecting the source int isource = 0; @@ -165,9 +165,9 @@ QVector* ParticleSourcesClass::GenerateEvent() //there are no linked particles //qDebug()<<"Generating individual particle"<last().Position[0] = R[0]; - GeneratedParticles->last().Position[1] = R[1]; - GeneratedParticles->last().Position[2] = R[2]; + GeneratedParticles->last().r[0] = R[0]; + GeneratedParticles->last().r[1] = R[1]; + GeneratedParticles->last().r[2] = R[2]; } else { @@ -226,21 +226,18 @@ QVector* ParticleSourcesClass::GenerateEvent() for (int i=0; iGunParticles[thisParticle]->ParticleId; - //if (ParticleSourcesData[isource]->GunParticles[thisParticle]->spectrum == 0) - // ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->energy; - //else ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->spectrum->GetRandom(); - ps.Energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->generateEnergy(); - ps.Direction[0] = -GeneratedParticles->at(index).Direction[0]; - ps.Direction[1] = -GeneratedParticles->at(index).Direction[1]; - ps.Direction[2] = -GeneratedParticles->at(index).Direction[2]; + AParticleRecord ps; + ps.Id = ParticleSourcesData[isource]->GunParticles[thisParticle]->ParticleId; + ps.energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->generateEnergy(); + ps.v[0] = -GeneratedParticles->at(index).v[0]; + ps.v[1] = -GeneratedParticles->at(index).v[1]; + ps.v[2] = -GeneratedParticles->at(index).v[2]; GeneratedParticles->append(ps); } - GeneratedParticles->last().Position[0] = R[0]; - GeneratedParticles->last().Position[1] = R[1]; - GeneratedParticles->last().Position[2] = R[2]; + GeneratedParticles->last().r[0] = R[0]; + GeneratedParticles->last().r[1] = R[1]; + GeneratedParticles->last().r[2] = R[2]; } //qDebug()<<"---No Event:"< *GeneratedParticles) const +void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const { - AGeneratedParticle ps; + AParticleRecord ps; - ps.ParticleId = ParticleSourcesData[isource]->GunParticles[iparticle]->ParticleId; + ps.Id = ParticleSourcesData[isource]->GunParticles[iparticle]->ParticleId; //energy //if (ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum == 0) // ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->energy; //else ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum->GetRandom(); - ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->generateEnergy(); + ps.energy = ParticleSourcesData[isource]->GunParticles[iparticle]->generateEnergy(); //generating random direction inside the collimation cone double spread = ParticleSourcesData[isource]->Spread*3.1415926535/180.0; //max angle away from generation diretion double cosTheta = cos(spread); @@ -393,9 +390,9 @@ void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector TVector3 K1(tmp*cos(phi), tmp*sin(phi), z); TVector3 Coll(CollimationDirection[isource]); K1.RotateUz(Coll); - ps.Direction[0] = K1[0]; - ps.Direction[1] = K1[1]; - ps.Direction[2] = K1[2]; + ps.v[0] = K1[0]; + ps.v[1] = K1[1]; + ps.v[2] = K1[2]; GeneratedParticles->append(ps); } diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 11907265..f6457a8b 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -30,7 +30,7 @@ class ParticleSourcesClass : public AParticleGun ~ParticleSourcesClass(); virtual bool Init() override; // !!! has to be called before the first use of "GenerateEvent"! - virtual QVector* GenerateEvent() override; //see Init!!! + virtual QVector* GenerateEvent() override; //see Init!!! //triggered when remove particle from configuration is attempted virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; @@ -73,7 +73,7 @@ class ParticleSourcesClass : public AParticleGun //utilities void CalculateTotalActivity(); void GeneratePosition(int isource, double *R) const; - void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! + void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! }; #endif // PARTICLESOURCESCLASS_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 73a22c32..f1f279c3 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1591,7 +1591,7 @@ void ParticleSourceSimulator::simulate() for (int iRun = 0; iRun < ParticleRunsThisEvent; iRun++) { //generating one event - QVector* GP = ParticleGun->GenerateEvent(); + QVector* GP = ParticleGun->GenerateEvent(); //qDebug() << "Thread"<size(); //adding particles to the stack for (int iPart = 0; iPart < GP->size(); iPart++ ) @@ -1599,11 +1599,11 @@ void ParticleSourceSimulator::simulate() if(iRun > 0 && timeRange != 0) time = timeFrom + timeRange*RandGen->Rndm(); //added TimeFrom 05/02/2015 - const AGeneratedParticle &part = GP->at(iPart); - ParticleStack.append(new AParticleRecord(part.ParticleId, - part.Position[0], part.Position[1], part.Position[2], - part.Direction[0], part.Direction[1], part.Direction[2], - time, part.Energy)); + const AParticleRecord &part = GP->at(iPart); + ParticleStack.append(new AParticleRecord(part.Id, + part.r[0], part.r[1], part.r[2], + part.v[0], part.v[1], part.v[2], + time, part.energy)); } //clear and delete QVector with generated event GP->clear(); From d3b2fd4df17dd0e3fa2c9528db37d00998690e03 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 27 Oct 2018 11:37:28 +0100 Subject: [PATCH 111/140] ++ --- src/ants2.pro | 2 +- src/common/aparticlegun.h | 5 +- .../MainWindowParticleSimulation.cpp | 38 +++++----- src/modules/afileparticlegenerator.cpp | 12 ++- src/modules/afileparticlegenerator.h | 2 +- src/modules/ascriptparticlegenerator.cpp | 5 +- src/modules/ascriptparticlegenerator.h | 2 +- src/modules/particlesourcesclass.cpp | 74 +++++++++---------- src/modules/particlesourcesclass.h | 4 +- src/modules/simulationmanager.cpp | 28 +++---- src/modules/simulationmanager.h | 5 ++ 11 files changed, 87 insertions(+), 90 deletions(-) diff --git a/src/ants2.pro b/src/ants2.pro index d53f718f..36e8f64c 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -1,6 +1,6 @@ #--------------ANTS2-------------- ANTS2_MAJOR = 4 -ANTS2_MINOR = 13 +ANTS2_MINOR = 14 #Optional libraries #CONFIG += ants2_cuda #enable CUDA support - need NVIDIA GPU and drivers (CUDA toolkit) installed! diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index f5e15cb7..1d19d068 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -5,8 +5,7 @@ #include class QJsonObject; -//class AParticleRecord; -#include "aparticlerecord.h" +class AParticleRecord; class AParticleGun { @@ -15,7 +14,7 @@ class AParticleGun virtual bool Init() = 0; //called before first use virtual void ReleaseResources() {} //called after end of operation - virtual QVector * GenerateEvent() = 0; + virtual void GenerateEvent(QVector & GeneratedParticles) = 0; virtual const QString CheckConfiguration() const = 0; //check consistency of the configuration diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 112dc732..3e884275 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -284,36 +284,38 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) double Length = std::max(Detector->WorldSizeXY, Detector->WorldSizeZ)*0.4; double R[3], K[3]; + QVector GP; for (int iRun=0; iRun* GP = Gun->GenerateEvent(); -// if (GP->isEmpty() && iRun > 2) -// { -// message("Did several attempts but no particles were generated!", this); -// break; -// } - for (const AParticleRecord& p : *GP) + Gun->GenerateEvent(GP); + if (GP.isEmpty() && iRun > 2) { - R[0] = p.r[0]; - R[1] = p.r[1]; - R[2] = p.r[2]; + message("Did several attempts but no particles were generated!", this); + break; + } + for (const AParticleRecord * p : GP) + { + R[0] = p->r[0]; + R[1] = p->r[1]; + R[2] = p->r[2]; - K[0] = p.v[0]; - K[1] = p.v[1]; - K[2] = p.v[2]; + K[0] = p->v[0]; + K[1] = p->v[1]; + K[2] = p->v[2]; - Int_t track_index = Detector->GeoManager->AddTrack(1,22); + int track_index = Detector->GeoManager->AddTrack(1, 22); TVirtualGeoTrack *track = Detector->GeoManager->GetTrack(track_index); track->AddPoint(R[0], R[1], R[2], 0); track->AddPoint(R[0] + K[0]*Length, R[1] + K[1]*Length, R[2] + K[2]*Length, 0); - SimulationManager->TrackBuildOptions.applyToParticleTrack(track, p.Id); + SimulationManager->TrackBuildOptions.applyToParticleTrack(track, p->Id); - GeoMarkerClass* marks = new GeoMarkerClass("t", 7, 1, SimulationManager->TrackBuildOptions.getParticleColor(p.Id)); + GeoMarkerClass* marks = new GeoMarkerClass("t", 7, 1, SimulationManager->TrackBuildOptions.getParticleColor(p->Id)); marks->SetNextPoint(R[0], R[1], R[2]); GeoMarkers.append(marks); + + delete p; } - GP->clear(); - delete GP; + GP.clear(); } ShowTracks(); ShowGeoMarkers(); diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index b1dd2a35..be7981b6 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -1,5 +1,6 @@ #include "afileparticlegenerator.h" #include "amaterialparticlecolection.h" +#include "aparticlerecord.h" #include "ajsontools.h" #include @@ -90,10 +91,8 @@ void AFileParticleGenerator::ReleaseResources() File.close(); } -QVector *AFileParticleGenerator::GenerateEvent() +void AFileParticleGenerator::GenerateEvent(QVector & GeneratedParticles) { - QVector* GeneratedParticles = new QVector; - while (!Stream->atEnd()) { const QString line = Stream->readLine(); @@ -115,17 +114,16 @@ QVector *AFileParticleGenerator::GenerateEvent() double vy = f.at(6).toDouble(); double vz = f.at(7).toDouble(); - //(*GeneratedParticles) << AGeneratedParticle(pId, energy, x, y, z, vx, vy, vz); - (*GeneratedParticles) << AParticleRecord(pId, + AParticleRecord* p = new AParticleRecord(pId, x, y, z, vx, vy, vz, 0, energy); - //TODO ensure unitary? + p->ensureUnitaryLength(); + GeneratedParticles << p; if (f.size() > 8 && f.at(8) == '*') continue; break; } - return GeneratedParticles; } const QString AFileParticleGenerator::CheckConfiguration() const diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 4e984fc9..7cebb360 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -24,7 +24,7 @@ class AFileParticleGenerator : public AParticleGun virtual bool Init() override; //called before first use virtual void ReleaseResources() override; //called after end of operation - virtual QVector* GenerateEvent(); + virtual void GenerateEvent(QVector & GeneratedParticles) override; virtual const QString CheckConfiguration() const override; //check consistency of the configuration diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index dd58bd83..6656fe7f 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -1,4 +1,5 @@ #include "ascriptparticlegenerator.h" +#include "aparticlerecord.h" AScriptParticleGenerator::AScriptParticleGenerator() { @@ -10,11 +11,9 @@ bool AScriptParticleGenerator::Init() return true; } -QVector *AScriptParticleGenerator::GenerateEvent() +void AScriptParticleGenerator::GenerateEvent(QVector & GeneratedParticles) { - QVector* GeneratedParticles = new QVector; - return GeneratedParticles; } void AScriptParticleGenerator::RemoveParticle(int particleId) diff --git a/src/modules/ascriptparticlegenerator.h b/src/modules/ascriptparticlegenerator.h index a6e9dad9..055f6e9a 100644 --- a/src/modules/ascriptparticlegenerator.h +++ b/src/modules/ascriptparticlegenerator.h @@ -11,7 +11,7 @@ class AScriptParticleGenerator : public AParticleGun virtual bool Init() override; //called before first use //virtual void ReleaseResources() override {} //called after end of operation - virtual QVector* GenerateEvent(); + virtual void GenerateEvent(QVector & GeneratedParticles) override; // virtual bool CheckConfiguration() override {return true;} //check consistency of the configuration diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 6ab32dc5..a7e84e36 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -1,4 +1,5 @@ #include "particlesourcesclass.h" +#include "aparticlerecord.h" #include "aparticlesourcerecord.h" #include "detectorclass.h" #include "jsonparser.h" @@ -110,12 +111,10 @@ bool ParticleSourcesClass::Init() return true; //TODO check for fails } -QVector *ParticleSourcesClass::GenerateEvent() +void ParticleSourcesClass::GenerateEvent(QVector & GeneratedParticles) { //after any operation with sources (add, remove), init should be called before first use! - QVector* GeneratedParticles = new QVector; - //selecting the source int isource = 0; int NumSources = ParticleSourcesData.size(); @@ -137,7 +136,7 @@ QVector *ParticleSourcesClass::GenerateEvent() timer.start(); do { - if (timer.elapsed()>500) return GeneratedParticles; + if (timer.elapsed() > 500) return; //qDebug() << "Time passed" << timer.elapsed() << "milliseconds"; GeneratePosition(isource, R); } @@ -165,9 +164,9 @@ QVector *ParticleSourcesClass::GenerateEvent() //there are no linked particles //qDebug()<<"Generating individual particle"<last().r[0] = R[0]; - GeneratedParticles->last().r[1] = R[1]; - GeneratedParticles->last().r[2] = R[2]; + GeneratedParticles.last()->r[0] = R[0]; + GeneratedParticles.last()->r[1] = R[1]; + GeneratedParticles.last()->r[2] = R[2]; } else { @@ -226,25 +225,23 @@ QVector *ParticleSourcesClass::GenerateEvent() for (int i=0; iGunParticles[thisParticle]->ParticleId; - ps.energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->generateEnergy(); - ps.v[0] = -GeneratedParticles->at(index).v[0]; - ps.v[1] = -GeneratedParticles->at(index).v[1]; - ps.v[2] = -GeneratedParticles->at(index).v[2]; - GeneratedParticles->append(ps); + AParticleRecord* ps = new AParticleRecord(); + ps->Id = ParticleSourcesData[isource]->GunParticles[thisParticle]->ParticleId; + ps->energy = ParticleSourcesData[isource]->GunParticles[thisParticle]->generateEnergy(); + ps->v[0] = -GeneratedParticles.at(index)->v[0]; + ps->v[1] = -GeneratedParticles.at(index)->v[1]; + ps->v[2] = -GeneratedParticles.at(index)->v[2]; + GeneratedParticles << ps; } - GeneratedParticles->last().r[0] = R[0]; - GeneratedParticles->last().r[1] = R[1]; - GeneratedParticles->last().r[2] = R[2]; + GeneratedParticles.last()->r[0] = R[0]; + GeneratedParticles.last()->r[1] = R[1]; + GeneratedParticles.last()->r[2] = R[2]; } //qDebug()<<"---No Event:"< *GeneratedParticles) const +void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector & GeneratedParticles) const { - AParticleRecord ps; - - ps.Id = ParticleSourcesData[isource]->GunParticles[iparticle]->ParticleId; + AParticleRecord* ps = new AParticleRecord(); - //energy - //if (ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum == 0) - // ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->energy; - //else ps.Energy = ParticleSourcesData[isource]->GunParticles[iparticle]->spectrum->GetRandom(); - ps.energy = ParticleSourcesData[isource]->GunParticles[iparticle]->generateEnergy(); + ps->Id = ParticleSourcesData[isource]->GunParticles[iparticle]->ParticleId; + ps->energy = ParticleSourcesData[isource]->GunParticles[iparticle]->generateEnergy(); //generating random direction inside the collimation cone - double spread = ParticleSourcesData[isource]->Spread*3.1415926535/180.0; //max angle away from generation diretion - double cosTheta = cos(spread); - double z = cosTheta + RandGen->Rndm() * (1.0 - cosTheta); - double tmp = TMath::Sqrt(1.0 - z*z); - double phi = RandGen->Rndm()*3.1415926535*2.0; - TVector3 K1(tmp*cos(phi), tmp*sin(phi), z); - TVector3 Coll(CollimationDirection[isource]); - K1.RotateUz(Coll); - ps.v[0] = K1[0]; - ps.v[1] = K1[1]; - ps.v[2] = K1[2]; - - GeneratedParticles->append(ps); + double spread = ParticleSourcesData[isource]->Spread*3.1415926535/180.0; //max angle away from generation diretion + double cosTheta = cos(spread); + double z = cosTheta + RandGen->Rndm() * (1.0 - cosTheta); + double tmp = TMath::Sqrt(1.0 - z*z); + double phi = RandGen->Rndm()*3.1415926535*2.0; + TVector3 K1(tmp*cos(phi), tmp*sin(phi), z); + TVector3 Coll(CollimationDirection[isource]); + K1.RotateUz(Coll); + ps->v[0] = K1[0]; + ps->v[1] = K1[1]; + ps->v[2] = K1[2]; + + GeneratedParticles << ps; } TVector3 ParticleSourcesClass::GenerateRandomDirection() diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index f6457a8b..efc43588 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -30,7 +30,7 @@ class ParticleSourcesClass : public AParticleGun ~ParticleSourcesClass(); virtual bool Init() override; // !!! has to be called before the first use of "GenerateEvent"! - virtual QVector* GenerateEvent() override; //see Init!!! + virtual void GenerateEvent(QVector & GeneratedParticles) override; //see Init!!! //triggered when remove particle from configuration is attempted virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; @@ -73,7 +73,7 @@ class ParticleSourcesClass : public AParticleGun //utilities void CalculateTotalActivity(); void GeneratePosition(int isource, double *R) const; - void AddParticleInCone(int isource, int iparticle, QVector *GeneratedParticles) const; //QVector - only pointer is transferred! + void AddParticleInCone(int isource, int iparticle, QVector & GeneratedParticles) const; //QVector - only pointer is transferred! }; #endif // PARTICLESOURCESCLASS_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index f1f279c3..73f392cc 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1415,6 +1415,7 @@ ParticleSourceSimulator::~ParticleSourceSimulator() delete ParticleTracker; delete ParticleGun; clearParticleStack(); + clearGeneratedParticles(); //if something was not transferred for (int i = 0; i < EnergyVector.size(); i++) delete EnergyVector[i]; EnergyVector.clear(); @@ -1591,23 +1592,18 @@ void ParticleSourceSimulator::simulate() for (int iRun = 0; iRun < ParticleRunsThisEvent; iRun++) { //generating one event - QVector* GP = ParticleGun->GenerateEvent(); - //qDebug() << "Thread"<size(); + ParticleGun->GenerateEvent(GeneratedParticles); + //adding particles to the stack - for (int iPart = 0; iPart < GP->size(); iPart++ ) + for (AParticleRecord * p : GeneratedParticles) { - if(iRun > 0 && timeRange != 0) - time = timeFrom + timeRange*RandGen->Rndm(); //added TimeFrom 05/02/2015 - - const AParticleRecord &part = GP->at(iPart); - ParticleStack.append(new AParticleRecord(part.Id, - part.r[0], part.r[1], part.r[2], - part.v[0], part.v[1], part.v[2], - time, part.energy)); + if (iRun > 0 && timeRange != 0) + p->time = timeFrom + timeRange*RandGen->Rndm(); + + ParticleStack << p; } //clear and delete QVector with generated event - GP->clear(); - delete GP; + GeneratedParticles.clear(); //do not delete particles - they were transferred to the ParticleStack! } //event prepared // qDebug()<<"event! Particle stack length:"<EventsDataHub = EventsDataHub; diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 5cb9f626..80ef8a25 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -356,6 +356,9 @@ class ParticleSourceSimulator : public Simulator QVector EnergyVector; QVector ParticleStack; + //local use - container which particle generator fills for each event; the particles are deleted by the tracker + QVector GeneratedParticles; + int totalEventCount; double timeFrom, timeRange; @@ -368,6 +371,8 @@ class ParticleSourceSimulator : public Simulator int TypeParticlesPerEvent; //0 - constant, 1 - Poisson bool fIgnoreNoHitsEvents; bool fIgnoreNoDepoEvents; + + void clearGeneratedParticles(); }; #endif // SIMULATION_MANAGER_H From 2734c573762096853680a5f535a33037c4ee60f6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 27 Oct 2018 11:40:47 +0100 Subject: [PATCH 112/140] ++ --- .../MainWindowTools/MainWindowParticleSimulation.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 3e884275..81e37376 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -288,11 +288,11 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) for (int iRun=0; iRunGenerateEvent(GP); - if (GP.isEmpty() && iRun > 2) - { - message("Did several attempts but no particles were generated!", this); - break; - } +// if (GP.isEmpty() && iRun > 2) +// { +// message("Did several attempts but no particles were generated!", this); +// break; +// } for (const AParticleRecord * p : GP) { R[0] = p->r[0]; From 9642862e1e3e0f8c461684336758b8ec87ca6412 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 27 Oct 2018 13:44:55 +0100 Subject: [PATCH 113/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 8 ++++ .../MainWindowParticleSimulation.cpp | 25 +++++++++-- src/gui/MainWindowTools/mainwindowjson.cpp | 13 +++++- src/gui/mainwindow.cpp | 1 - src/gui/mainwindow.h | 4 ++ src/gui/mainwindow.ui | 44 ++++++++++++++++++- src/modules/ascriptparticlegenerator.cpp | 20 +++++---- src/modules/ascriptparticlegenerator.h | 21 +++++++-- src/modules/simulationmanager.cpp | 6 ++- src/modules/simulationmanager.h | 10 +++-- 10 files changed, 128 insertions(+), 24 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index ba988bac..d723b28a 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -21,6 +21,8 @@ #include "simulationmanager.h" #include "areconstructionmanager.h" //#include "particlesourcesclass.h" +#include "afileparticlegenerator.h" +#include "ascriptparticlegenerator.h" #include "aglobalsettings.h" #include "globalsettingswindowclass.h" #include "aconfiguration.h" @@ -78,6 +80,12 @@ MainWindow::MainWindow(DetectorClass *Detector, ui->leGenerateFromFile_FileName->setText(epff); SimulationManager->FileParticleGenerator->SetFileName(epff); + QString SPGtext = "AddParticle(0, 100+math.Random(), 10*math.Random(), 10*math.Random(), 0, 0, 0, 1)\n" + "AddParticleIsotropic(0, 111, 0, 0, -5)"; + ui->pteParticleGenerationScript->clear(); + ui->pteParticleGenerationScript->appendPlainText(SPGtext); + SimulationManager->ScriptParticleGenerator->SetScript(SPGtext); + //adding Context menus ui->lwLoadedEventsFiles->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(ui->lwLoadedEventsFiles, SIGNAL(customContextMenuRequested(const QPoint&)), diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 81e37376..4cd4feea 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -8,6 +8,8 @@ #include "windownavigatorclass.h" #include "geometrywindowclass.h" #include "particlesourcesclass.h" +#include "afileparticlegenerator.h" +#include "ascriptparticlegenerator.h" #include "graphwindowclass.h" #include "detectorclass.h" #include "checkupwindowclass.h" @@ -23,7 +25,6 @@ #include "simulationmanager.h" #include "exampleswindow.h" #include "aconfiguration.h" -#include "afileparticlegenerator.h" //Qt #include @@ -61,13 +62,17 @@ void MainWindow::SimParticleSourcesConfigToJson(QJsonObject &json) cjs["IgnoreNoDepoEvents"] = ui->cbIgnoreEventsWithNoEnergyDepo->isChecked(); psjs["SourceControlOptions"] = cjs; - //particle sources + //Particle generation + //--particle sources SimulationManager->ParticleSources->writeToJson(psjs); - - //from file + //--from file QJsonObject fjs; SimulationManager->FileParticleGenerator->writeToJson(fjs); psjs["GenerationFromFile"] = fjs; + //--from script + QJsonObject sjs; + SimulationManager->ScriptParticleGenerator->writeToJson(sjs); + psjs["GenerationFromScript"] = sjs; json["ParticleSourcesConfig"] = psjs; } @@ -871,3 +876,15 @@ void MainWindow::updateFileParticleGeneratorGui() ui->labGenerateFromFile_info->setText(s); } + +// --- by script + +void MainWindow::on_pbParticleGenerationScript_clicked() +{ + +} + +void MainWindow::on_pteParticleGenerationScript_customContextMenuRequested(const QPoint &) +{ + on_pbParticleGenerationScript_clicked(); +} diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index b0f43fd8..a2409d81 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -11,6 +11,8 @@ #include "aconfiguration.h" #include "ajsontools.h" #include "particlesourcesclass.h" +#include "afileparticlegenerator.h" +#include "ascriptparticlegenerator.h" #include "apmhub.h" #include "eventsdataclass.h" #include "tmpobjhubclass.h" @@ -579,6 +581,7 @@ if (scj.contains("CustomDistrib")) //particle sources SimulationManager->ParticleSources->readFromJson(psjs); + on_pbUpdateSourcesIndication_clicked(); //generation from file QJsonObject fjs; @@ -590,7 +593,15 @@ if (scj.contains("CustomDistrib")) } updateFileParticleGeneratorGui(); - on_pbUpdateSourcesIndication_clicked(); + QJsonObject sjs; + parseJson(psjs, "GenerationFromScript", sjs); + if (!sjs.isEmpty()) + { + SimulationManager->FileParticleGenerator->readFromJson(sjs); + ui->pteParticleGenerationScript->clear(); + ui->pteParticleGenerationScript->appendPlainText(SimulationManager->ScriptParticleGenerator->GetScript()); + } + //Window CONTROL if (js.contains("Mode")) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 23a8f02d..a55f1840 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -4963,4 +4963,3 @@ void MainWindow::on_pbPMtypeHelp_clicked() " represent the photocathode."; message(s, this); } - diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index a37ad60c..e464b67e 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -616,6 +616,10 @@ private slots: void on_twParticleGenerationMode_currentChanged(int index); + void on_pbParticleGenerationScript_clicked(); + + void on_pteParticleGenerationScript_customContextMenuRequested(const QPoint &pos); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 7232081e..1f7c869e 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9687,7 +9687,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - 1 + 2 @@ -10056,6 +10056,48 @@ Right click: toggle build particle tracks. Also switch off building photon track From script + + + + 178 + 197 + 160 + 23 + + + + Edit script + + + + + + 10 + 30 + 491 + 161 + + + + Qt::CustomContextMenu + + + true + + + + + + 20 + 10 + 471 + 16 + + + + Particle generation script: + + diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index 6656fe7f..d2ada67d 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -1,10 +1,9 @@ #include "ascriptparticlegenerator.h" #include "aparticlerecord.h" +#include "ajsontools.h" -AScriptParticleGenerator::AScriptParticleGenerator() -{ - -} +AScriptParticleGenerator::AScriptParticleGenerator(const AMaterialParticleCollection &MpCollection) : + MpCollection(MpCollection) {} bool AScriptParticleGenerator::Init() { @@ -16,12 +15,17 @@ void AScriptParticleGenerator::GenerateEvent(QVector & Generat } -void AScriptParticleGenerator::RemoveParticle(int particleId) +bool AScriptParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const +{ + return false; //TODO +} + +void AScriptParticleGenerator::writeToJson(QJsonObject &json) const { - //TODO + json["Script"] = Script; } -bool AScriptParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const +bool AScriptParticleGenerator::readFromJson(const QJsonObject &json) { - return false; //TODO + return parseJson(json, "Script", Script); } diff --git a/src/modules/ascriptparticlegenerator.h b/src/modules/ascriptparticlegenerator.h index 055f6e9a..25439277 100644 --- a/src/modules/ascriptparticlegenerator.h +++ b/src/modules/ascriptparticlegenerator.h @@ -3,20 +3,35 @@ #include "aparticlegun.h" +#include + +class AMaterialParticleCollection; + class AScriptParticleGenerator : public AParticleGun { public: - AScriptParticleGenerator(); + AScriptParticleGenerator(const AMaterialParticleCollection& MpCollection); virtual ~AScriptParticleGenerator(){} + void SetScript(const QString& script) {Script = script;} + const QString& GetScript() const {return Script;} + virtual bool Init() override; //called before first use //virtual void ReleaseResources() override {} //called after end of operation virtual void GenerateEvent(QVector & GeneratedParticles) override; - // virtual bool CheckConfiguration() override {return true;} //check consistency of the configuration + virtual const QString CheckConfiguration() const override {return "";} //check consistency of the configuration - virtual void RemoveParticle(int particleId) override; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first + virtual void RemoveParticle(int) override {} //should NOT be used to remove one of particles in use! use onIsPareticleInUse first virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; + + virtual void writeToJson(QJsonObject& json) const override; + virtual bool readFromJson(const QJsonObject& json) override; + +private: + const AMaterialParticleCollection& MpCollection; + + QString Script; }; #endif // ASCRIPTPARTICLEGENERATOR_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 73f392cc..29167659 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -9,6 +9,8 @@ #include "s1_generator.h" #include "s2_generator.h" #include "particlesourcesclass.h" +#include "afileparticlegenerator.h" +#include "ascriptparticlegenerator.h" #include "amaterialparticlecolection.h" #include "asandwich.h" #include "ageoobject.h" @@ -1816,9 +1818,8 @@ ASimulationManager::ASimulationManager(EventsDataClass* EventsDataHub, DetectorC this->Detector = Detector; ParticleSources = new ParticleSourcesClass(Detector, Detector->RandGen); - //qDebug() << "->Container for particle sources created and configured"; - FileParticleGenerator = new AFileParticleGenerator(*Detector->MpCollection); + ScriptParticleGenerator = new AScriptParticleGenerator(*Detector->MpCollection); Runner = new ASimulatorRunner(Detector, EventsDataHub); @@ -1839,6 +1840,7 @@ ASimulationManager::~ASimulationManager() delete Runner; ASimulationManager::Clear(); + delete ScriptParticleGenerator; delete FileParticleGenerator; delete ParticleSources; } diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 80ef8a25..2c154d90 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -6,7 +6,6 @@ #include "aphoton.h" #include "dotstgeostruct.h" #include "atrackbuildoptions.h" -#include "afileparticlegenerator.h" #include #include @@ -27,6 +26,8 @@ class PrimaryParticleTracker; class S1_Generator; class S2_Generator; class ParticleSourcesClass; +class AFileParticleGenerator; +class AScriptParticleGenerator; class Simulator; class TRandom2; class TString; @@ -76,9 +77,10 @@ class ASimulationManager : public QObject void StartSimulation(QJsonObject &json, int threads, bool fStartedFromGui); void Clear(); - // Next two: Simulators use their own local copies constructed using configuration in JSON - ParticleSourcesClass* ParticleSources = 0; //used to update JSON on config changes and in GUI to configure - AFileParticleGenerator* FileParticleGenerator = 0; //only for gui, simulation threads use their own + // Next three: Simulators use their own local copies constructed using configuration in JSON + ParticleSourcesClass* ParticleSources = 0; //used to update JSON on config changes and in GUI to configure + AFileParticleGenerator* FileParticleGenerator = 0; //only for gui, simulation threads use their own + AScriptParticleGenerator* ScriptParticleGenerator = 0; //only for gui, simulation threads use their own ATrackBuildOptions TrackBuildOptions; From fa07882a5134cebe9d898074420016f7e7403658 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 27 Oct 2018 21:18:41 +0100 Subject: [PATCH 114/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 4 +- .../MainWindowParticleSimulation.cpp | 2 +- src/modules/ascriptparticlegenerator.cpp | 41 +++++++++++++++++-- src/modules/ascriptparticlegenerator.h | 15 +++++-- src/modules/simulationmanager.cpp | 19 +++++++-- .../aparticlegeneratorinterface.cpp | 6 +-- src/scriptmode/aparticlegeneratorinterface.h | 4 +- 7 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index d723b28a..849c55aa 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -80,8 +80,8 @@ MainWindow::MainWindow(DetectorClass *Detector, ui->leGenerateFromFile_FileName->setText(epff); SimulationManager->FileParticleGenerator->SetFileName(epff); - QString SPGtext = "AddParticle(0, 100+math.Random(), 10*math.Random(), 10*math.Random(), 0, 0, 0, 1)\n" - "AddParticleIsotropic(0, 111, 0, 0, -5)"; + QString SPGtext = "gen.AddParticle(0, 100+math.random(), 10*math.random(), 10*math.random(), 0, 0, 0, 1)\n" + "gen.AddParticleIsotropic(0, 111, 0, 0, -5)"; ui->pteParticleGenerationScript->clear(); ui->pteParticleGenerationScript->appendPlainText(SPGtext); SimulationManager->ScriptParticleGenerator->SetScript(SPGtext); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 4cd4feea..9f526bed 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -268,7 +268,7 @@ void MainWindow::on_pbGunTest_clicked() { case 0: pg = SimulationManager->ParticleSources; break; case 1: pg = SimulationManager->FileParticleGenerator; break; - case 2: + case 2: pg = SimulationManager->ScriptParticleGenerator; break; default: message("This generation mode is not implemented!", this); return; diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index d2ada67d..4defe331 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -1,18 +1,53 @@ #include "ascriptparticlegenerator.h" #include "aparticlerecord.h" #include "ajsontools.h" +#include "aparticlegeneratorinterface.h" +#include "amathscriptinterface.h" -AScriptParticleGenerator::AScriptParticleGenerator(const AMaterialParticleCollection &MpCollection) : - MpCollection(MpCollection) {} +#include +#include + +AScriptParticleGenerator::AScriptParticleGenerator(const AMaterialParticleCollection &MpCollection, TRandom2 * RandGen) : + MpCollection(MpCollection), RandGen(RandGen) {} + +AScriptParticleGenerator::~AScriptParticleGenerator() +{ + delete ScriptInterface; + delete ScriptEngine; +} bool AScriptParticleGenerator::Init() { + qDebug() << "Init script particle ghenerator"; + + if (!ScriptEngine) + { + qDebug() << "Creating script infrastructure"; + ScriptEngine = new QScriptEngine(); + ScriptInterface = new AParticleGeneratorInterface(MpCollection, RandGen); + + ScriptInterface->setObjectName("gen"); + QScriptValue val = ScriptEngine->newQObject(ScriptInterface, QScriptEngine::QtOwnership); + ScriptEngine->globalObject().setProperty(ScriptInterface->objectName(), val); + + //QObject::connect(ScriptInterface, &AParticleGeneratorInterface::requestAbort, ScriptEngine, &QScriptEngine::abortEvaluation, Qt::DirectConnection); + + mathInterface = new AMathScriptInterface(RandGen); + mathInterface->setObjectName("math"); + val = ScriptEngine->newQObject(mathInterface, QScriptEngine::QtOwnership); + ScriptEngine->globalObject().setProperty(mathInterface->objectName(), val); + } + return true; } void AScriptParticleGenerator::GenerateEvent(QVector & GeneratedParticles) { - + qDebug() << "Generating event!"; + ScriptInterface->configure(&GeneratedParticles); + qDebug() << ScriptEngine->evaluate(Script).toString(); + qDebug() << "Script>:"< class AMaterialParticleCollection; +class TRandom2; +class QScriptEngine; +class AParticleGeneratorInterface; +class AMathScriptInterface; class AScriptParticleGenerator : public AParticleGun { public: - AScriptParticleGenerator(const AMaterialParticleCollection& MpCollection); - virtual ~AScriptParticleGenerator(){} + AScriptParticleGenerator(const AMaterialParticleCollection& MpCollection, TRandom2 *RandGen); + virtual ~AScriptParticleGenerator(); void SetScript(const QString& script) {Script = script;} const QString& GetScript() const {return Script;} @@ -29,9 +33,14 @@ class AScriptParticleGenerator : public AParticleGun virtual bool readFromJson(const QJsonObject& json) override; private: - const AMaterialParticleCollection& MpCollection; + const AMaterialParticleCollection & MpCollection; + TRandom2 * RandGen; QString Script; + QScriptEngine * ScriptEngine = 0; // creates only on Init - only if from script mode was selected! + //TODO make external (e.g. Simulator class can host it for sim) + AParticleGeneratorInterface * ScriptInterface = 0; // creates only on Init - only if from script mode was selected! + AMathScriptInterface * mathInterface = 0; // creates only on Init - only if from script mode was selected! }; #endif // ASCRIPTPARTICLEGENERATOR_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 29167659..6e5e3425 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1492,14 +1492,25 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) { ParticleGun = new AFileParticleGenerator(*detector->MpCollection); ParticleGun->readFromJson(fjs); - } } else if (PartGenMode == "Script") { // script based generator - ErrorString = "Script particle generator is not yet implemented"; - return false; + //ErrorString = "Script particle generator is not yet implemented"; + //return false; + QJsonObject sjs; + parseJson(js, "GenerationFromScript", sjs); + if (sjs.isEmpty()) + { + ErrorString = "Simulation settings do not contain 'from script' generator configuration"; + return false; + } + else + { + ParticleGun = new AScriptParticleGenerator(*detector->MpCollection, RandGen); + ParticleGun->readFromJson(sjs); + } } else { @@ -1819,7 +1830,7 @@ ASimulationManager::ASimulationManager(EventsDataClass* EventsDataHub, DetectorC ParticleSources = new ParticleSourcesClass(Detector, Detector->RandGen); FileParticleGenerator = new AFileParticleGenerator(*Detector->MpCollection); - ScriptParticleGenerator = new AScriptParticleGenerator(*Detector->MpCollection); + ScriptParticleGenerator = new AScriptParticleGenerator(*Detector->MpCollection, Detector->RandGen); Runner = new ASimulatorRunner(Detector, EventsDataHub); diff --git a/src/scriptmode/aparticlegeneratorinterface.cpp b/src/scriptmode/aparticlegeneratorinterface.cpp index 6bfc8f8f..c07a34ac 100644 --- a/src/scriptmode/aparticlegeneratorinterface.cpp +++ b/src/scriptmode/aparticlegeneratorinterface.cpp @@ -5,7 +5,7 @@ #include "TMath.h" #include "TRandom2.h" -AParticleGeneratorInterface::AParticleGeneratorInterface(const AMaterialParticleCollection *MpCollection, TRandom2 *RandGen) : +AParticleGeneratorInterface::AParticleGeneratorInterface(const AMaterialParticleCollection & MpCollection, TRandom2 *RandGen) : MpCollection(MpCollection), RandGen(RandGen) {} void AParticleGeneratorInterface::configure(QVector * GeneratedParticles) @@ -15,7 +15,7 @@ void AParticleGeneratorInterface::configure(QVector * Generate void AParticleGeneratorInterface::AddParticle(int type, double energy, double x, double y, double z, double i, double k, double j, double time) { - if (type < 0 || type >= MpCollection->countParticles()) + if (type < 0 || type >= MpCollection.countParticles()) abort("Invalid particle Id"); else { @@ -30,7 +30,7 @@ void AParticleGeneratorInterface::AddParticle(int type, double energy, double x, void AParticleGeneratorInterface::AddParticleIsotropic(int type, double energy, double x, double y, double z, double time) { - if (type < 0 || type >= MpCollection->countParticles()) + if (type < 0 || type >= MpCollection.countParticles()) abort("Invalid particle Id"); else { diff --git a/src/scriptmode/aparticlegeneratorinterface.h b/src/scriptmode/aparticlegeneratorinterface.h index 41e5ae18..878397c9 100644 --- a/src/scriptmode/aparticlegeneratorinterface.h +++ b/src/scriptmode/aparticlegeneratorinterface.h @@ -14,7 +14,7 @@ class AParticleGeneratorInterface : public AScriptInterface Q_OBJECT public: - AParticleGeneratorInterface(const AMaterialParticleCollection * MpCollection, TRandom2 * RandGen); + AParticleGeneratorInterface(const AMaterialParticleCollection & MpCollection, TRandom2 * RandGen); void configure(QVector * GeneratedParticles); @@ -23,7 +23,7 @@ public slots: void AddParticleIsotropic(int type, double energy, double x, double y, double z, double time = 0); private: - const AMaterialParticleCollection * MpCollection = 0; //external + const AMaterialParticleCollection & MpCollection; TRandom2 * RandGen = 0; //external QVector * GP = 0; //external From 4be664313cc8d638ef368e55ab10be8adf0024ef Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 28 Oct 2018 11:23:34 +0000 Subject: [PATCH 115/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 6 +-- .../MainWindowParticleSimulation.cpp | 49 +++++++++++++++++ src/gui/MainWindowTools/mainwindowjson.cpp | 18 +++---- src/gui/mainwindow.h | 1 + src/gui/mainwindow.ui | 54 +++++++++++++------ src/modules/ascriptparticlegenerator.cpp | 5 +- 6 files changed, 97 insertions(+), 36 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 849c55aa..631b4ae8 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -20,7 +20,6 @@ #include "detectorclass.h" #include "simulationmanager.h" #include "areconstructionmanager.h" -//#include "particlesourcesclass.h" #include "afileparticlegenerator.h" #include "ascriptparticlegenerator.h" #include "aglobalsettings.h" @@ -77,14 +76,13 @@ MainWindow::MainWindow(DetectorClass *Detector, setWindowTitle("ANTS2_v"+mav+"."+miv); QString epff = GlobSet.ExamplesDir + "/ExampleParticlesFromFile.dat"; - ui->leGenerateFromFile_FileName->setText(epff); SimulationManager->FileParticleGenerator->SetFileName(epff); + updateFileParticleGeneratorGui(); QString SPGtext = "gen.AddParticle(0, 100+math.random(), 10*math.random(), 10*math.random(), 0, 0, 0, 1)\n" "gen.AddParticleIsotropic(0, 111, 0, 0, -5)"; - ui->pteParticleGenerationScript->clear(); - ui->pteParticleGenerationScript->appendPlainText(SPGtext); SimulationManager->ScriptParticleGenerator->SetScript(SPGtext); + updateScriptParticleGeneratorGui(); //adding Context menus ui->lwLoadedEventsFiles->setContextMenuPolicy(Qt::CustomContextMenu); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 9f526bed..8cd73062 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -844,6 +844,8 @@ void MainWindow::updateFileParticleGeneratorGui() { AFileParticleGenerator* pg = SimulationManager->FileParticleGenerator; + ui->leGenerateFromFile_FileName->setText(pg->GetFileName()); + QFileInfo fi(pg->GetFileName()); if (!fi.exists()) { @@ -879,9 +881,56 @@ void MainWindow::updateFileParticleGeneratorGui() // --- by script +#include "ajavascriptmanager.h" +#include "ascriptwindow.h" +#include "aparticlegeneratorinterface.h" +#include "amathscriptinterface.h" + +void MainWindow::updateScriptParticleGeneratorGui() +{ + ui->pteParticleGenerationScript->clear(); + ui->pteParticleGenerationScript->appendPlainText(SimulationManager->ScriptParticleGenerator->GetScript()); +} + void MainWindow::on_pbParticleGenerationScript_clicked() { + AJavaScriptManager* sm = new AJavaScriptManager(Detector->RandGen); + AScriptWindow* sw = new AScriptWindow(sm, true, this); + + AParticleGeneratorInterface* gen = new AParticleGeneratorInterface(*Detector->MpCollection, Detector->RandGen); + QVector GeneratedParticles; + gen->configure(&GeneratedParticles); + gen->setObjectName("gen"); + sw->RegisterInterface(gen, "gen"); //takes ownership + AMathScriptInterface* math = new AMathScriptInterface(Detector->RandGen); + math->setObjectName("math"); + sw->RegisterInterface(math, "math"); //takes ownership + + sw->UpdateGui(); + + QObject::connect(sw, &AScriptWindow::onStart, [&GeneratedParticles](){for (AParticleRecord* p : GeneratedParticles) delete p; GeneratedParticles.clear();}); + + QString Script = SimulationManager->ScriptParticleGenerator->GetScript(); + QString Example = "gen.AddParticle(0, 100+math.random(), 10*math.random(), 10*math.random(), 0, 0, 0, 1)\n" + "gen.AddParticleIsotropic(0, 111, 0, 0, -5)"; + sw->ConfigureForLightMode(&Script, "Optical override: custom script", Example); + sw->setWindowModality(Qt::ApplicationModal); + sw->show(); + GuiUtils::AssureWidgetIsWithinVisibleArea(sw); + + while (sw->isVisible()) + { + QCoreApplication::processEvents(); + QThread::usleep(200); + } + + for (AParticleRecord* p : GeneratedParticles) delete p; + GeneratedParticles.clear(); + delete sw; //also deletes script manager + + SimulationManager->ScriptParticleGenerator->SetScript(Script); + on_pbUpdateSimConfig_clicked(); } void MainWindow::on_pteParticleGenerationScript_customContextMenuRequested(const QPoint &) diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index a2409d81..153ec4f7 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -18,6 +18,7 @@ #include "tmpobjhubclass.h" #include "reconstructionwindow.h" #include "simulationmanager.h" +#include "aparticlerecord.h" #include #include @@ -290,10 +291,11 @@ bool MainWindow::readSimSettingsFromJson(QJsonObject &json) ui->pbScanDistrDelete->setEnabled(false); populateTable = true; if (ParticleStack.size()>0) - { - for (int i=0; iFileParticleGenerator->readFromJson(fjs); - ui->leGenerateFromFile_FileName->setText(SimulationManager->FileParticleGenerator->GetFileName()); - } updateFileParticleGeneratorGui(); QJsonObject sjs; parseJson(psjs, "GenerationFromScript", sjs); if (!sjs.isEmpty()) - { - SimulationManager->FileParticleGenerator->readFromJson(sjs); - ui->pteParticleGenerationScript->clear(); - ui->pteParticleGenerationScript->appendPlainText(SimulationManager->ScriptParticleGenerator->GetScript()); - } + SimulationManager->ScriptParticleGenerator->readFromJson(sjs); + updateScriptParticleGeneratorGui(); //Window CONTROL diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index e464b67e..19f64ecd 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -228,6 +228,7 @@ public slots: private slots: void updateFileParticleGeneratorGui(); + void updateScriptParticleGeneratorGui(); void on_pbAddParticleToStack_clicked(); void on_pbRemoveFromStack_clicked(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 1f7c869e..ed69fde9 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 1 + 0 @@ -6906,7 +6906,7 @@ Second click will trigger strong abort mode, which will result in loss of all si - Photon sources + Only photons @@ -9491,7 +9491,7 @@ double events: - Particle sources + Particles + photons @@ -9675,9 +9675,9 @@ Right click: toggle build particle tracks. Also switch off building photon track 8 - 11 + 21 514 - 251 + 241 @@ -9687,7 +9687,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - 2 + 0 @@ -9716,7 +9716,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 430 - 50 + 49 70 23 @@ -9757,7 +9757,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 180 - 194 + 187 320 21 @@ -9840,7 +9840,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 7 - 194 + 187 198 18 @@ -9861,7 +9861,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 7 22 417 - 161 + 155 @@ -9872,7 +9872,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 430 - 77 + 75 70 23 @@ -9891,7 +9891,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 430 - 108 + 104 70 23 @@ -9910,7 +9910,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 430 - 130 + 126 70 23 @@ -9942,7 +9942,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 430 - 160 + 154 70 23 @@ -10044,7 +10044,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 50 100 451 - 111 + 108 @@ -10060,7 +10060,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 178 - 197 + 186 160 23 @@ -10075,7 +10075,7 @@ Right click: toggle build particle tracks. Also switch off building photon track 10 30 491 - 161 + 150 @@ -10173,6 +10173,25 @@ Right click: toggle build particle tracks. Also switch off building photon track -- + + + + 22 + 2 + 501 + 16 + + + + + 50 + false + + + + Particle generation mode: + + linePS cbGunDoS1 cbGunDoS2 @@ -10187,6 +10206,7 @@ Right click: toggle build particle tracks. Also switch off building photon track labIgnoreNoDepoEvents cbIgnoreEventsWithNoEnergyDepo cbIgnoreEventsWithNoHits + label_45 diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index 4defe331..6f33cccd 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -43,11 +43,8 @@ bool AScriptParticleGenerator::Init() void AScriptParticleGenerator::GenerateEvent(QVector & GeneratedParticles) { - qDebug() << "Generating event!"; ScriptInterface->configure(&GeneratedParticles); - qDebug() << ScriptEngine->evaluate(Script).toString(); - qDebug() << "Script>:"<evaluate(Script).toString(); } bool AScriptParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const From e2a768e125b6520fcec70322d098103815186faa Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Oct 2018 09:30:52 +0000 Subject: [PATCH 116/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 3 +-- src/gui/mainwindow.ui | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 631b4ae8..9893ef1e 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -79,8 +79,7 @@ MainWindow::MainWindow(DetectorClass *Detector, SimulationManager->FileParticleGenerator->SetFileName(epff); updateFileParticleGeneratorGui(); - QString SPGtext = "gen.AddParticle(0, 100+math.random(), 10*math.random(), 10*math.random(), 0, 0, 0, 1)\n" - "gen.AddParticleIsotropic(0, 111, 0, 0, -5)"; + QString SPGtext = "gen.AddParticleIsotropic(0, math.gauss(150, 25), 10, 12, -5)"; SimulationManager->ScriptParticleGenerator->SetScript(SPGtext); updateScriptParticleGeneratorGui(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index ed69fde9..babe1e3e 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -9986,7 +9986,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - Generate event from file: + Generate events from file: @@ -10095,7 +10095,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - Particle generation script: + Particle generation script (called for each event): From 7b08470797d977d3b53c63e4773d7ab8d5c9c914 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 29 Oct 2018 09:55:06 +0000 Subject: [PATCH 117/140] ++ --- src/common/aparticlegun.h | 2 +- src/gui/MainWindowTools/MainWindowParticleSimulation.cpp | 2 +- src/modules/ascriptparticlegenerator.cpp | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 1d19d068..a34c5b1a 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -16,7 +16,7 @@ class AParticleGun virtual void ReleaseResources() {} //called after end of operation virtual void GenerateEvent(QVector & GeneratedParticles) = 0; - virtual const QString CheckConfiguration() const = 0; //check consistency of the configuration + virtual const QString CheckConfiguration() const = 0; //check consistency of the configuration - TODO: merge with Init() virtual void RemoveParticle(int particleId) = 0; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first virtual bool IsParticleInUse(int particleId, QString& SourceNames) const = 0; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 8cd73062..ccb8a82e 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -283,7 +283,7 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) bool bOK = Gun->Init(); if (!bOK) { - message("Failed to initialize particle gun!\n" + Gun->GetErrorString(), this); //TODO ErrorStrig + message("Failed to initialize particle gun!\n" + Gun->GetErrorString(), this); return; } diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index 6f33cccd..8707c4a6 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -18,11 +18,11 @@ AScriptParticleGenerator::~AScriptParticleGenerator() bool AScriptParticleGenerator::Init() { - qDebug() << "Init script particle ghenerator"; + //qDebug() << "Init script particle ghenerator"; if (!ScriptEngine) { - qDebug() << "Creating script infrastructure"; + //qDebug() << "Creating script infrastructure"; ScriptEngine = new QScriptEngine(); ScriptInterface = new AParticleGeneratorInterface(MpCollection, RandGen); @@ -38,6 +38,9 @@ bool AScriptParticleGenerator::Init() ScriptEngine->globalObject().setProperty(mathInterface->objectName(), val); } + //TODO: check script syntax + //TODO: check particles + return true; } From 29f560bfcc53d3b4a58a870fad29f63b4132dd19 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 30 Oct 2018 09:54:11 +0000 Subject: [PATCH 118/140] add possibility to stop infi-cycle script particle generator --- src/common/aparticlegun.h | 11 +++++++++-- src/gui/MainWindowTools/MainWindowInits.cpp | 1 + .../MainWindowParticleSimulation.cpp | 18 ++++++++++++++++-- src/gui/mainwindow.ui | 4 ++-- src/modules/afileparticlegenerator.cpp | 8 +++++--- src/modules/afileparticlegenerator.h | 2 +- src/modules/ascriptparticlegenerator.cpp | 11 ++++++++++- src/modules/ascriptparticlegenerator.h | 9 ++++++++- src/modules/particlesourcesclass.cpp | 8 ++++++-- src/modules/particlesourcesclass.h | 2 +- src/modules/simulationmanager.cpp | 10 +++++++--- src/modules/simulationmanager.h | 2 ++ 12 files changed, 68 insertions(+), 18 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index a34c5b1a..06314e6f 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -1,20 +1,23 @@ #ifndef APARTICLEGUN_H #define APARTICLEGUN_H +#include #include #include class QJsonObject; class AParticleRecord; -class AParticleGun +class AParticleGun : public QObject { + Q_OBJECT + public: virtual ~AParticleGun(){} virtual bool Init() = 0; //called before first use virtual void ReleaseResources() {} //called after end of operation - virtual void GenerateEvent(QVector & GeneratedParticles) = 0; + virtual bool GenerateEvent(QVector & GeneratedParticles) = 0; virtual const QString CheckConfiguration() const = 0; //check consistency of the configuration - TODO: merge with Init() @@ -28,8 +31,12 @@ class AParticleGun const QString& GetErrorString() const {return ErrorString;} +public slots: + virtual void abort() {bAbortRequested = true;} + protected: QString ErrorString; + bool bAbortRequested = false; }; #endif // APARTICLEGUN_H diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 9893ef1e..2a991564 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -81,6 +81,7 @@ MainWindow::MainWindow(DetectorClass *Detector, QString SPGtext = "gen.AddParticleIsotropic(0, math.gauss(150, 25), 10, 12, -5)"; SimulationManager->ScriptParticleGenerator->SetScript(SPGtext); + QObject::connect(ui->pbStopScan, &QPushButton::clicked, SimulationManager->ScriptParticleGenerator, &AScriptParticleGenerator::abort);//[pg](){pg->abort();}); updateScriptParticleGeneratorGui(); //adding Context menus diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index ccb8a82e..e982b5a2 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -273,7 +273,20 @@ void MainWindow::on_pbGunTest_clicked() message("This generation mode is not implemented!", this); return; } - TestParticleGun(pg, ui->sbGunTestEvents->value()); + + ui->pbStopScan->setEnabled(true); + QFont font = ui->pbStopScan->font(); + font.setBold(true); + ui->pbStopScan->setFont(font); + WindowNavigator->BusyOn(); + + TestParticleGun(pg, ui->sbGunTestEvents->value()); //script generator is aborted on click of the stop button! + + ui->pbStopScan->setEnabled(false); + ui->pbStopScan->setText("stop"); + font.setBold(false); + ui->pbStopScan->setFont(font); + WindowNavigator->BusyOff(); } void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) @@ -292,7 +305,8 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) QVector GP; for (int iRun=0; iRunGenerateEvent(GP); + bool bOK = Gun->GenerateEvent(GP); + if (!bOK) return; // if (GP.isEmpty() && iRun > 2) // { // message("Did several attempts but no particles were generated!", this); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index babe1e3e..97930738 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -6893,7 +6893,7 @@ Second click will trigger strong abort mode, which will result in loss of all si QTabWidget::Rounded - 1 + 0 false @@ -9691,7 +9691,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - Direct + Sources diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index be7981b6..ec699fff 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -91,7 +91,7 @@ void AFileParticleGenerator::ReleaseResources() File.close(); } -void AFileParticleGenerator::GenerateEvent(QVector & GeneratedParticles) +bool AFileParticleGenerator::GenerateEvent(QVector & GeneratedParticles) { while (!Stream->atEnd()) { @@ -121,9 +121,11 @@ void AFileParticleGenerator::GenerateEvent(QVector & Generated p->ensureUnitaryLength(); GeneratedParticles << p; - if (f.size() > 8 && f.at(8) == '*') continue; - break; + if (f.size() > 8 && f.at(8) == '*') continue; //this is multiple event! + return true; //normal termination } + + return false; //could not read particle record in file! } const QString AFileParticleGenerator::CheckConfiguration() const diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 7cebb360..29a0cebe 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -24,7 +24,7 @@ class AFileParticleGenerator : public AParticleGun virtual bool Init() override; //called before first use virtual void ReleaseResources() override; //called after end of operation - virtual void GenerateEvent(QVector & GeneratedParticles) override; + virtual bool GenerateEvent(QVector & GeneratedParticles) override; virtual const QString CheckConfiguration() const override; //check consistency of the configuration diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index 8707c4a6..73e74e2a 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -24,6 +24,7 @@ bool AScriptParticleGenerator::Init() { //qDebug() << "Creating script infrastructure"; ScriptEngine = new QScriptEngine(); + ScriptEngine->setProcessEventsInterval(processInterval); ScriptInterface = new AParticleGeneratorInterface(MpCollection, RandGen); ScriptInterface->setObjectName("gen"); @@ -44,10 +45,12 @@ bool AScriptParticleGenerator::Init() return true; } -void AScriptParticleGenerator::GenerateEvent(QVector & GeneratedParticles) +bool AScriptParticleGenerator::GenerateEvent(QVector & GeneratedParticles) { + bAbortRequested = false; ScriptInterface->configure(&GeneratedParticles); ScriptEngine->evaluate(Script).toString(); + return !bAbortRequested; } bool AScriptParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const @@ -64,3 +67,9 @@ bool AScriptParticleGenerator::readFromJson(const QJsonObject &json) { return parseJson(json, "Script", Script); } + +void AScriptParticleGenerator::abort() +{ + bAbortRequested = true; + ScriptEngine->abortEvaluation(); +} diff --git a/src/modules/ascriptparticlegenerator.h b/src/modules/ascriptparticlegenerator.h index 7b450234..933e5444 100644 --- a/src/modules/ascriptparticlegenerator.h +++ b/src/modules/ascriptparticlegenerator.h @@ -22,7 +22,7 @@ class AScriptParticleGenerator : public AParticleGun virtual bool Init() override; //called before first use //virtual void ReleaseResources() override {} //called after end of operation - virtual void GenerateEvent(QVector & GeneratedParticles) override; + virtual bool GenerateEvent(QVector & GeneratedParticles) override; virtual const QString CheckConfiguration() const override {return "";} //check consistency of the configuration @@ -32,6 +32,11 @@ class AScriptParticleGenerator : public AParticleGun virtual void writeToJson(QJsonObject& json) const override; virtual bool readFromJson(const QJsonObject& json) override; + void SetProcessInterval(int msOrMinus1) {processInterval = msOrMinus1;} + +public slots: + virtual void abort() override; + private: const AMaterialParticleCollection & MpCollection; TRandom2 * RandGen; @@ -41,6 +46,8 @@ class AScriptParticleGenerator : public AParticleGun //TODO make external (e.g. Simulator class can host it for sim) AParticleGeneratorInterface * ScriptInterface = 0; // creates only on Init - only if from script mode was selected! AMathScriptInterface * mathInterface = 0; // creates only on Init - only if from script mode was selected! + + int processInterval = -1; //ms; if -1 processing of events during evaluation is disabled }; #endif // ASCRIPTPARTICLEGENERATOR_H diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index a7e84e36..90118262 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -111,8 +111,9 @@ bool ParticleSourcesClass::Init() return true; //TODO check for fails } -void ParticleSourcesClass::GenerateEvent(QVector & GeneratedParticles) +bool ParticleSourcesClass::GenerateEvent(QVector & GeneratedParticles) { + bAbortRequested = false; //after any operation with sources (add, remove), init should be called before first use! //selecting the source @@ -136,7 +137,8 @@ void ParticleSourcesClass::GenerateEvent(QVector & GeneratedPa timer.start(); do { - if (timer.elapsed() > 500) return; + if (bAbortRequested) return false; + if (timer.elapsed() > 500) return false; //qDebug() << "Time passed" << timer.elapsed() << "milliseconds"; GeneratePosition(isource, R); } @@ -242,6 +244,8 @@ void ParticleSourcesClass::GenerateEvent(QVector & GeneratedPa } while (NoEvent); } + + return true; } void ParticleSourcesClass::GeneratePosition(int isource, double *R) const diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index efc43588..82e6416a 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -30,7 +30,7 @@ class ParticleSourcesClass : public AParticleGun ~ParticleSourcesClass(); virtual bool Init() override; // !!! has to be called before the first use of "GenerateEvent"! - virtual void GenerateEvent(QVector & GeneratedParticles) override; //see Init!!! + virtual bool GenerateEvent(QVector & GeneratedParticles) override; //see Init!!! //triggered when remove particle from configuration is attempted virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 6e5e3425..8b92c388 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1587,9 +1587,6 @@ void ParticleSourceSimulator::simulate() EnergyVector.resize(0); } - //adding particles to stack - double time = 0; - //how many particles to run this event? int ParticleRunsThisEvent = 1; if (fAllowMultiple) @@ -1735,6 +1732,12 @@ bool ParticleSourceSimulator::standaloneGenerateLight(QVectorabort(); +} + void ParticleSourceSimulator::updateMaxTracks(int maxPhotonTracks, int maxParticleTracks) { ParticleTracker->setMaxTracks(maxParticleTracks); @@ -1831,6 +1834,7 @@ ASimulationManager::ASimulationManager(EventsDataClass* EventsDataHub, DetectorC ParticleSources = new ParticleSourcesClass(Detector, Detector->RandGen); FileParticleGenerator = new AFileParticleGenerator(*Detector->MpCollection); ScriptParticleGenerator = new AScriptParticleGenerator(*Detector->MpCollection, Detector->RandGen); + ScriptParticleGenerator->SetProcessInterval(200); Runner = new ASimulatorRunner(Detector, EventsDataHub); diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 2c154d90..1dd1b176 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -342,6 +342,8 @@ class ParticleSourceSimulator : public Simulator bool standaloneTrackStack(QVector* particleStack); bool standaloneGenerateLight(QVector* energyVector); + virtual void hardAbort() override; + protected: virtual void updateMaxTracks(int maxPhotonTracks, int maxParticleTracks); From 103f67559f75c776a1080cae3210793a9447384b Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 30 Oct 2018 09:59:45 +0000 Subject: [PATCH 119/140] ++ --- src/gui/MainWindowTools/MainWindowParticleSimulation.cpp | 2 +- src/gui/amatparticleconfigurator.cpp | 2 +- src/modules/afileparticlegenerator.cpp | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index e982b5a2..a68f91a6 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -811,7 +811,7 @@ void MainWindow::on_pbParticleSourcesSimulate_clicked() startSimulation(Config->JSON); } -void MainWindow::on_twParticleGenerationMode_currentChanged(int index) +void MainWindow::on_twParticleGenerationMode_currentChanged(int) { /* ui->sbGunEvents->setVisible(index != 1); diff --git a/src/gui/amatparticleconfigurator.cpp b/src/gui/amatparticleconfigurator.cpp index 1e9bbd3e..1dacebae 100644 --- a/src/gui/amatparticleconfigurator.cpp +++ b/src/gui/amatparticleconfigurator.cpp @@ -202,7 +202,7 @@ void AMatParticleConfigurator::on_pbShowSystemDir_clicked() QDesktopServices::openUrl(QUrl("file:///"+CrossSectionSystemDir, QUrl::TolerantMode)); } -void AMatParticleConfigurator::on_pbChangeDir_customContextMenuRequested(const QPoint &pos) +void AMatParticleConfigurator::on_pbChangeDir_customContextMenuRequested(const QPoint &) { QString st = ui->leCustomDataDir->text(); if (!st.isEmpty()) diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index ec699fff..3b1097ac 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -180,6 +180,7 @@ void AFileParticleGenerator::SetStartEvent(int startEvent) bool bOK; int pId = f.at(0).toInt(&bOK); if (!bOK) continue; //assuming this is a comment line + //TODO protection of wrong index, either test on start // synchronize! if (!bContinueEvent) event++; From d78f51328ff47cdcfb96dcb97adbd1c0d1ee5a68 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 30 Oct 2018 18:33:38 +0000 Subject: [PATCH 120/140] particle generator: merged check into Init() --- src/common/aparticlegun.h | 4 +- .../MainWindowParticleSimulation.cpp | 8 -- src/modules/afileparticlegenerator.cpp | 5 - src/modules/afileparticlegenerator.h | 2 - src/modules/ascriptparticlegenerator.h | 2 - src/modules/particlesourcesclass.cpp | 126 ++++++++++-------- src/modules/particlesourcesclass.h | 2 - src/modules/simulationmanager.cpp | 2 +- 8 files changed, 69 insertions(+), 82 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 06314e6f..741029b0 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -16,11 +16,9 @@ class AParticleGun : public QObject virtual ~AParticleGun(){} virtual bool Init() = 0; //called before first use - virtual void ReleaseResources() {} //called after end of operation + virtual void ReleaseResources() {} //called after end of operation TODO use virtual bool GenerateEvent(QVector & GeneratedParticles) = 0; - virtual const QString CheckConfiguration() const = 0; //check consistency of the configuration - TODO: merge with Init() - virtual void RemoveParticle(int particleId) = 0; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first virtual bool IsParticleInUse(int particleId, QString& SourceNames) const = 0; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index a68f91a6..a30cf572 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -798,14 +798,6 @@ void MainWindow::on_pbParticleSourcesSimulate_clicked() ELwindow->QuickSave(0); fStartedFromGUI = true; fSimDataNotSaved = false; // to disable the warning - //watchdog on particle sources, can be transferred later to check-upwindow - - QString err = SimulationManager->ParticleSources->CheckConfiguration(); - if (!err.isEmpty()) - { - message(err); - return; - } MainWindow::writeSimSettingsToJson(Config->JSON); startSimulation(Config->JSON); diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 3b1097ac..d39f3c21 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -128,11 +128,6 @@ bool AFileParticleGenerator::GenerateEvent(QVector & Generated return false; //could not read particle record in file! } -const QString AFileParticleGenerator::CheckConfiguration() const -{ - return ""; //TODO -} - void AFileParticleGenerator::RemoveParticle(int) { qWarning() << "Remove particle has no effect for AFileParticleGenerator"; diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 29a0cebe..31da1eb3 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -26,8 +26,6 @@ class AFileParticleGenerator : public AParticleGun virtual void ReleaseResources() override; //called after end of operation virtual bool GenerateEvent(QVector & GeneratedParticles) override; - virtual const QString CheckConfiguration() const override; //check consistency of the configuration - virtual void RemoveParticle(int particleId) override; //cannot be used for this class virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; diff --git a/src/modules/ascriptparticlegenerator.h b/src/modules/ascriptparticlegenerator.h index 933e5444..5ee97719 100644 --- a/src/modules/ascriptparticlegenerator.h +++ b/src/modules/ascriptparticlegenerator.h @@ -24,8 +24,6 @@ class AScriptParticleGenerator : public AParticleGun //virtual void ReleaseResources() override {} //called after end of operation virtual bool GenerateEvent(QVector & GeneratedParticles) override; - virtual const QString CheckConfiguration() const override {return "";} //check consistency of the configuration - virtual void RemoveParticle(int) override {} //should NOT be used to remove one of particles in use! use onIsPareticleInUse first virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/particlesourcesclass.cpp index 90118262..f297d7b7 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/particlesourcesclass.cpp @@ -38,50 +38,71 @@ void ParticleSourcesClass::clear() bool ParticleSourcesClass::Init() { int NumSources = ParticleSourcesData.size(); + if (NumSources == 0) + { + ErrorString = "No sources are defined"; + return false; + } + CalculateTotalActivity(); //qDebug()<<"Tot activity:"<GunParticles.size(); i++) - if (ParticleSourcesData[isource]->GunParticles[i]->Individual) - TotalParticleWeight[isource] += ParticleSourcesData[isource]->GunParticles[i]->StatWeight; + for (AParticleSourceRecord* ps : ParticleSourcesData) + { + QString err = ps->CheckSource(*MpCollection); + if (!err.isEmpty()) + { + ErrorString = QString("Error in source %1:\n%2").arg(ps->name).arg(err); + return false; + } } - //creating lists of linked particles - LinkedPartiles.resize(NumSources); - for (int isource=0; isourceGunParticles.size(); - LinkedPartiles[isource].resize(numParts); - for (int iparticle=0; iparticleGunParticles[iparticle]->Individual) continue; //nothing to do for non-individual particles - - //every individual particles defines an "event generation chain" containing the particle iteslf and all linked (and linked to linked to linked etc) particles - LinkedPartiles[isource][iparticle].append(LinkedParticleStructure(iparticle)); //list always contains the particle itself - simplifies the generation algorithm - //only particles with larger indexes can be linked to this particle - for (int ip=iparticle+1; ipGunParticles[ip]->Individual) //only looking for non-individuals - { - //for iparticle, checking if it is linked to any particle in the list of the LinkedParticles - for (int idef=0; idefGunParticles[ip]->LinkedTo; - if ( linkedTo == compareWith) - { - LinkedPartiles[isource][iparticle].append(LinkedParticleStructure(ip, linkedTo)); - break; - } - } - } + for (int i=0; iGunParticles.size(); i++) + if (ParticleSourcesData[isource]->GunParticles[i]->Individual) + TotalParticleWeight[isource] += ParticleSourcesData[isource]->GunParticles[i]->StatWeight; + } + + //creating lists of linked particles + LinkedPartiles.resize(NumSources); + for (int isource=0; isourceGunParticles.size(); + LinkedPartiles[isource].resize(numParts); + for (int iparticle=0; iparticleGunParticles[iparticle]->Individual) continue; //nothing to do for non-individual particles + + //every individual particles defines an "event generation chain" containing the particle iteslf and all linked (and linked to linked to linked etc) particles + LinkedPartiles[isource][iparticle].append(LinkedParticleStructure(iparticle)); //list always contains the particle itself - simplifies the generation algorithm + //only particles with larger indexes can be linked to this particle + for (int ip=iparticle+1; ipGunParticles[ip]->Individual) //only looking for non-individuals + { + //for iparticle, checking if it is linked to any particle in the list of the LinkedParticles + for (int idef=0; idefGunParticles[ip]->LinkedTo; + if ( linkedTo == compareWith) + { + LinkedPartiles[isource][iparticle].append(LinkedParticleStructure(ip, linkedTo)); + break; + } + } + } } } - /* + /* //debug for (int isource=0; isourceGunParticles.size(); iparticle++) @@ -95,20 +116,20 @@ bool ParticleSourcesClass::Init() //vectors related to collmation direction - CollimationDirection.resize(NumSources); - CollimationProbability.resize(NumSources); - //CollimationSpreadProduct.resize(NumSources); - for (int isource=0; isourceCollPhi*3.1415926535/180.0; - double CollTheta = ParticleSourcesData[isource]->CollTheta*3.1415926535/180.0; - double Spread = ParticleSourcesData[isource]->Spread*3.1415926535/180.0; + double CollPhi = ParticleSourcesData[isource]->CollPhi*3.1415926535/180.0; + double CollTheta = ParticleSourcesData[isource]->CollTheta*3.1415926535/180.0; + double Spread = ParticleSourcesData[isource]->Spread*3.1415926535/180.0; - CollimationDirection[isource] = TVector3(sin(CollTheta)*sin(CollPhi), sin(CollTheta)*cos(CollPhi), cos(CollTheta)); - CollimationProbability[isource] = 0.5 * (1.0 - cos(Spread)); - //CollimationSpreadProduct[isource] = cos(Spread); //scalar product of coll direction and max spread unit vectors + CollimationDirection[isource] = TVector3(sin(CollTheta)*sin(CollPhi), sin(CollTheta)*cos(CollPhi), cos(CollTheta)); + CollimationProbability[isource] = 0.5 * (1.0 - cos(Spread)); + //CollimationSpreadProduct[isource] = cos(Spread); //scalar product of coll direction and max spread unit vectors } - return true; //TODO check for fails + return true; //TODO check for fails } bool ParticleSourcesClass::GenerateEvent(QVector & GeneratedParticles) @@ -446,19 +467,6 @@ void ParticleSourcesClass::RemoveParticle(int particleId) } } -const QString ParticleSourcesClass::CheckConfiguration() const -{ - if (ParticleSourcesData.isEmpty()) return "No sources are defined"; - for (AParticleSourceRecord* ps : ParticleSourcesData) - { - QString err = ps->CheckSource(*MpCollection); - if (!err.isEmpty()) return QString("Error in source %1:\n%2").arg(ps->name).arg(err); - } - if (TotalActivity == 0) return "Total activity is zero"; - - return ""; -} - double ParticleSourcesClass::getTotalActivity() { CalculateTotalActivity(); diff --git a/src/modules/particlesourcesclass.h b/src/modules/particlesourcesclass.h index 82e6416a..d077f1c5 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/particlesourcesclass.h @@ -36,8 +36,6 @@ class ParticleSourcesClass : public AParticleGun virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; virtual void RemoveParticle(int particleId) override; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first - virtual const QString CheckConfiguration() const; - virtual void writeToJson(QJsonObject &json) const override; virtual bool readFromJson(const QJsonObject &json) override; diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 8b92c388..a5e91492 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1518,7 +1518,7 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) return false; } - // trying initialize the gun + // trying to initialize the gun if ( !ParticleGun->Init() ) { ErrorString = ParticleGun->GetErrorString(); From 25dbca94bce914822f1c1aa52f31326b0b29daa9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 30 Oct 2018 18:51:58 +0000 Subject: [PATCH 121/140] ++ --- src/common/aparticlegun.h | 2 +- src/modules/afileparticlegenerator.cpp | 17 +++++++++++++---- src/modules/afileparticlegenerator.h | 2 +- src/modules/simulationmanager.cpp | 18 +----------------- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/common/aparticlegun.h b/src/common/aparticlegun.h index 741029b0..4f81e67c 100644 --- a/src/common/aparticlegun.h +++ b/src/common/aparticlegun.h @@ -16,7 +16,7 @@ class AParticleGun : public QObject virtual ~AParticleGun(){} virtual bool Init() = 0; //called before first use - virtual void ReleaseResources() {} //called after end of operation TODO use + virtual void ReleaseResources() {} //called after end of operation virtual bool GenerateEvent(QVector & GeneratedParticles) = 0; virtual void RemoveParticle(int particleId) = 0; //should NOT be used to remove one of particles in use! use onIsPareticleInUse first diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index d39f3c21..a763aa37 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -12,6 +12,11 @@ AFileParticleGenerator::AFileParticleGenerator(const AMaterialParticleCollection & MpCollection) : MpCollection(MpCollection) {} +AFileParticleGenerator::~AFileParticleGenerator() +{ + ReleaseResources(); +} + void AFileParticleGenerator::SetFileName(const QString &fileName) { if (FileName == fileName) return; @@ -22,9 +27,14 @@ void AFileParticleGenerator::SetFileName(const QString &fileName) bool AFileParticleGenerator::Init() { - if (File.isOpen()) File.close(); - File.setFileName(FileName); + ReleaseResources(); + if (FileName.isEmpty()) + { + ErrorString = "File name is not defined"; + return false; + } + File.setFileName(FileName); if(!File.open(QIODevice::ReadOnly | QFile::Text)) { ErrorString = QString("Failed to open file: %1").arg(FileName); @@ -32,7 +42,6 @@ bool AFileParticleGenerator::Init() return false; } - if (Stream) delete Stream; Stream = 0; Stream = new QTextStream(&File); QFileInfo fi(File); @@ -88,7 +97,7 @@ bool AFileParticleGenerator::Init() void AFileParticleGenerator::ReleaseResources() { delete Stream; Stream = 0; - File.close(); + if (File.isOpen()) File.close(); } bool AFileParticleGenerator::GenerateEvent(QVector & GeneratedParticles) diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index 31da1eb3..f6ca4d37 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -17,7 +17,7 @@ class AFileParticleGenerator : public AParticleGun { public: AFileParticleGenerator(const AMaterialParticleCollection& MpCollection); - virtual ~AFileParticleGenerator(){} + virtual ~AFileParticleGenerator(); void SetFileName(const QString &fileName); const QString GetFileName() const {return FileName;} diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index a5e91492..944a9d8b 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1545,23 +1545,6 @@ void ParticleSourceSimulator::updateGeoManager() void ParticleSourceSimulator::simulate() { - //watchdogs TODO - /* - int NumSources = ParticleGun->countSources(); - if (NumSources == 0) - { - ErrorString = "Particle sources are not defined!"; - fSuccess = false; - return; - } - if (ParticleGun->getTotalActivity() == 0) - { - ErrorString = "Total activity of sources is zero!"; - fSuccess = false; - return; - } - */ - if ( !ParticleStack.isEmpty() ) // *** to be moved to "ClearData"? { for (int i=0; iReleaseResources(); } void ParticleSourceSimulator::appendToDataHub(EventsDataClass *dataHub) From 040d58871840a4c7b86cf5cfc0d67ab4d99dc463 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 31 Oct 2018 10:19:09 +0000 Subject: [PATCH 122/140] ++ --- src/gui/MainWindowTools/MainWindowInits.cpp | 4 +++- src/gui/MainWindowTools/MainWindowParticleSimulation.cpp | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index 2a991564..d305d906 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -79,7 +79,9 @@ MainWindow::MainWindow(DetectorClass *Detector, SimulationManager->FileParticleGenerator->SetFileName(epff); updateFileParticleGeneratorGui(); - QString SPGtext = "gen.AddParticleIsotropic(0, math.gauss(150, 25), 10, 12, -5)"; + QString SPGtext = "gen.AddParticle(0, 120, math.gauss(0, 25), math.gauss(0, 25), -20, 0,0,1)\n" + "if (math.random() < 0.1)\n" + " gen.AddParticle(0, 120, math.gauss(0, 25), math.gauss(0, 25), -20, 0,0,1)"; SimulationManager->ScriptParticleGenerator->SetScript(SPGtext); QObject::connect(ui->pbStopScan, &QPushButton::clicked, SimulationManager->ScriptParticleGenerator, &AScriptParticleGenerator::abort);//[pg](){pg->abort();}); updateScriptParticleGeneratorGui(); diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index a30cf572..98ef811a 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -306,7 +306,7 @@ void MainWindow::TestParticleGun(AParticleGun* Gun, int numParticles) for (int iRun=0; iRunGenerateEvent(GP); - if (!bOK) return; + if (!bOK) break; // if (GP.isEmpty() && iRun > 2) // { // message("Did several attempts but no particles were generated!", this); From a5a35eb88f9ffd68eacd8722b569fa2db24d23d6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 31 Oct 2018 10:28:49 +0000 Subject: [PATCH 123/140] coreinterface -> acorescriptinterface --- src/ants2.pro | 8 +-- src/gui/ascriptwindow.cpp | 4 +- ...nterfaces.cpp => acorescriptinterface.cpp} | 72 +++++++++---------- ...oreinterfaces.h => acorescriptinterface.h} | 12 ++-- src/scriptmode/ajavascriptmanager.cpp | 8 +-- src/scriptmode/ajavascriptmanager.h | 2 +- src/scriptmode/apythonscriptmanager.cpp | 4 +- src/scriptmode/ascriptinterfacefactory.h | 6 +- src/scriptmode/ascriptmanager.h | 2 +- 9 files changed, 59 insertions(+), 59 deletions(-) rename src/scriptmode/{coreinterfaces.cpp => acorescriptinterface.cpp} (86%) rename src/scriptmode/{coreinterfaces.h => acorescriptinterface.h} (88%) diff --git a/src/ants2.pro b/src/ants2.pro index 36e8f64c..f88d8043 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -319,7 +319,6 @@ SOURCES += main.cpp \ common/amaterialcomposition.cpp \ common/aneutroninteractionelement.cpp \ scriptmode/ainterfacetodeposcript.cpp \ - scriptmode/coreinterfaces.cpp \ scriptmode/localscriptinterfaces.cpp \ scriptmode/histgraphinterfaces.cpp \ scriptmode/ainterfacetomultithread.cpp \ @@ -361,7 +360,8 @@ SOURCES += main.cpp \ modules/ascriptparticlegenerator.cpp \ modules/afileparticlegenerator.cpp \ scriptmode/aparticlegeneratorinterface.cpp \ - common/aparticlerecord.cpp + common/aparticlerecord.cpp \ + scriptmode/acorescriptinterface.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -456,7 +456,6 @@ HEADERS += common/CorrelationFilters.h \ common/amaterialcomposition.h \ common/aneutroninteractionelement.h \ scriptmode/ainterfacetodeposcript.h \ - scriptmode/coreinterfaces.h \ scriptmode/localscriptinterfaces.h \ scriptmode/histgraphinterfaces.h \ common/amessageoutput.h \ @@ -499,7 +498,8 @@ HEADERS += common/CorrelationFilters.h \ modules/ascriptparticlegenerator.h \ modules/afileparticlegenerator.h \ scriptmode/aparticlegeneratorinterface.h \ - common/aparticlerecord.h + common/aparticlerecord.h \ + scriptmode/acorescriptinterface.h # --- SIM --- ants2_SIM { diff --git a/src/gui/ascriptwindow.cpp b/src/gui/ascriptwindow.cpp index f1a329f5..ecc88dd2 100644 --- a/src/gui/ascriptwindow.cpp +++ b/src/gui/ascriptwindow.cpp @@ -4,7 +4,7 @@ #include "atextedit.h" #include "ascriptinterface.h" #include "localscriptinterfaces.h" -#include "coreinterfaces.h" +#include "acorescriptinterface.h" #include "amathscriptinterface.h" #include "histgraphinterfaces.h" #include "interfacetoglobscript.h" @@ -342,7 +342,7 @@ void AScriptWindow::RegisterCoreInterfaces(bool bCore, bool bMath) if (bCore) { - AInterfaceToCore core(0); //dummy to extract method names + ACoreScriptInterface core(0); //dummy to extract method names doRegister(&core, "core"); } if (bMath) diff --git a/src/scriptmode/coreinterfaces.cpp b/src/scriptmode/acorescriptinterface.cpp similarity index 86% rename from src/scriptmode/coreinterfaces.cpp rename to src/scriptmode/acorescriptinterface.cpp index 3775bb21..2b73e8ed 100644 --- a/src/scriptmode/coreinterfaces.cpp +++ b/src/scriptmode/acorescriptinterface.cpp @@ -1,4 +1,4 @@ -#include "coreinterfaces.h" +#include "acorescriptinterface.h" #include "ascriptmanager.h" #include "afiletools.h" @@ -19,7 +19,7 @@ #include #include -AInterfaceToCore::AInterfaceToCore(AScriptManager* ScriptManager) : +ACoreScriptInterface::ACoreScriptInterface(AScriptManager* ScriptManager) : ScriptManager(ScriptManager) { Description = "General-purpose opeartions: abort script, basic text output and file save/load"; @@ -55,24 +55,24 @@ AInterfaceToCore::AInterfaceToCore(AScriptManager* ScriptManager) : DepRem["str"] = "Deprecated. Use .toFixed(n) javaScript method. E.g.: 'var i=123.456; i.toFixed(2)'"; } -AInterfaceToCore::AInterfaceToCore(const AInterfaceToCore &other) : +ACoreScriptInterface::ACoreScriptInterface(const ACoreScriptInterface &other) : AScriptInterface(other) { ScriptManager = 0; //to be set after copy!!! } -void AInterfaceToCore::abort(QString message) +void ACoreScriptInterface::abort(QString message) { qDebug() << ">Core module: abort triggered!"; ScriptManager->AbortEvaluation(message); } -QVariant AInterfaceToCore::evaluate(QString script) +QVariant ACoreScriptInterface::evaluate(QString script) { return ScriptManager->EvaluateScriptInScript(script); } -void AInterfaceToCore::sleep(int ms) +void ACoreScriptInterface::sleep(int ms) { if (ms == 0) return; QTime t; @@ -86,37 +86,37 @@ void AInterfaceToCore::sleep(int ms) while (t.elapsed()getElapsedTime(); } -void AInterfaceToCore::print(QString text) +void ACoreScriptInterface::print(QString text) { emit ScriptManager->showMessage(text); } -void AInterfaceToCore::clearText() +void ACoreScriptInterface::clearText() { emit ScriptManager->clearText(); } -QString AInterfaceToCore::str(double value, int precision) +QString ACoreScriptInterface::str(double value, int precision) { return QString::number(value, 'g', precision); } -QString AInterfaceToCore::GetTimeStamp() +QString ACoreScriptInterface::GetTimeStamp() { return QDateTime::currentDateTime().toString("H:m:s"); } -QString AInterfaceToCore::GetDateTimeStamp() +QString ACoreScriptInterface::GetDateTimeStamp() { return QDateTime::currentDateTime().toString("d/M/yyyy H:m:s"); } -bool AInterfaceToCore::save(QString fileName, QString str) +bool ACoreScriptInterface::save(QString fileName, QString str) { if (!QFileInfo(fileName).exists()) { @@ -140,7 +140,7 @@ bool AInterfaceToCore::save(QString fileName, QString str) return true; } -bool AInterfaceToCore::saveArray(QString fileName, QVariant array) +bool ACoreScriptInterface::saveArray(QString fileName, QVariant array) { QString type = array.typeName(); if (type != "QVariantList") @@ -191,7 +191,7 @@ bool AInterfaceToCore::saveArray(QString fileName, QVariant array) return true; } -bool AInterfaceToCore::saveObject(QString FileName, QVariant Object, bool CanOverride) +bool ACoreScriptInterface::saveObject(QString FileName, QVariant Object, bool CanOverride) { QString type = Object.typeName(); if (type != "QVariantMap") @@ -225,7 +225,7 @@ bool AInterfaceToCore::saveObject(QString FileName, QVariant Object, bool CanOve return true; } -QVariant AInterfaceToCore::loadColumn(QString fileName, int column) +QVariant ACoreScriptInterface::loadColumn(QString fileName, int column) { QVector< QVector* > vec; for (int i=0; iLastOpenDir) return QString(); else return *ScriptManager->LastOpenDir; } -QString AInterfaceToCore::GetScriptDir() +QString ACoreScriptInterface::GetScriptDir() { if (!ScriptManager->LibScripts) return QString(); else return *ScriptManager->LibScripts; } -QString AInterfaceToCore::GetExamplesDir() +QString ACoreScriptInterface::GetExamplesDir() { if (!ScriptManager->ExamplesDir) return QString(); else return *ScriptManager->ExamplesDir; } -QVariant AInterfaceToCore::SetNewFileFinder(const QString dir, const QString fileNamePattern) +QVariant ACoreScriptInterface::SetNewFileFinder(const QString dir, const QString fileNamePattern) { Finder_Dir = dir; Finder_NamePattern = fileNamePattern; @@ -475,7 +475,7 @@ QVariant AInterfaceToCore::SetNewFileFinder(const QString dir, const QString fil return res; } -QVariant AInterfaceToCore::GetNewFiles() +QVariant ACoreScriptInterface::GetNewFiles() { QVariantList newFiles; QDir d(Finder_Dir); @@ -489,18 +489,18 @@ QVariant AInterfaceToCore::GetNewFiles() return newFiles; } -void AInterfaceToCore::processEvents() +void ACoreScriptInterface::processEvents() { qApp->processEvents(); } -void AInterfaceToCore::reportProgress(int percents) +void ACoreScriptInterface::reportProgress(int percents) { emit ScriptManager->reportProgress(percents); qApp->processEvents(); } -void AInterfaceToCore::setCurveFitter(double min, double max, int nInt, QVariant x, QVariant y) +void ACoreScriptInterface::setCurveFitter(double min, double max, int nInt, QVariant x, QVariant y) { #ifdef USE_EIGEN QVariantList vlX = x.toList(); @@ -519,7 +519,7 @@ void AInterfaceToCore::setCurveFitter(double min, double max, int nInt, QVariant #endif } -double AInterfaceToCore::getFitted(double x) +double ACoreScriptInterface::getFitted(double x) { #ifdef USE_EIGEN if (!CurF) return 0; @@ -531,7 +531,7 @@ double AInterfaceToCore::getFitted(double x) #endif } -const QVariant AInterfaceToCore::getFittedArr(const QVariant array) +const QVariant ACoreScriptInterface::getFittedArr(const QVariant array) { #ifdef USE_EIGEN if (!CurF) return 0; @@ -548,7 +548,7 @@ const QVariant AInterfaceToCore::getFittedArr(const QVariant array) #endif } -bool AInterfaceToCore::createFile(QString fileName, bool AbortIfExists) +bool ACoreScriptInterface::createFile(QString fileName, bool AbortIfExists) { if (QFileInfo(fileName).exists()) { @@ -571,17 +571,17 @@ bool AInterfaceToCore::createFile(QString fileName, bool AbortIfExists) return true; } -bool AInterfaceToCore::isFileExists(QString fileName) +bool ACoreScriptInterface::isFileExists(QString fileName) { return QFileInfo(fileName).exists(); } -bool AInterfaceToCore::deleteFile(QString fileName) +bool ACoreScriptInterface::deleteFile(QString fileName) { return QFile(fileName).remove(); } -bool AInterfaceToCore::createDir(QString path) +bool ACoreScriptInterface::createDir(QString path) { //QDir dir(path); //return dir.mkdir("."); @@ -589,12 +589,12 @@ bool AInterfaceToCore::createDir(QString path) return dir.mkpath(path); } -QString AInterfaceToCore::getCurrentDir() +QString ACoreScriptInterface::getCurrentDir() { return QDir::currentPath(); } -bool AInterfaceToCore::setCirrentDir(QString path) +bool ACoreScriptInterface::setCirrentDir(QString path) { return QDir::setCurrent(path); } diff --git a/src/scriptmode/coreinterfaces.h b/src/scriptmode/acorescriptinterface.h similarity index 88% rename from src/scriptmode/coreinterfaces.h rename to src/scriptmode/acorescriptinterface.h index 1308807b..8b059adf 100644 --- a/src/scriptmode/coreinterfaces.h +++ b/src/scriptmode/acorescriptinterface.h @@ -1,5 +1,5 @@ -#ifndef COREINTERFACES_H -#define COREINTERFACES_H +#ifndef ACORESCRIPTINTERFACE_H +#define ACORESCRIPTINTERFACE_H #include "ascriptinterface.h" @@ -10,13 +10,13 @@ class AScriptManager; class CurveFit; -class AInterfaceToCore : public AScriptInterface +class ACoreScriptInterface : public AScriptInterface { Q_OBJECT public: - explicit AInterfaceToCore(AScriptManager *ScriptManager); - explicit AInterfaceToCore(const AInterfaceToCore& other); + explicit ACoreScriptInterface(AScriptManager *ScriptManager); + explicit ACoreScriptInterface(const ACoreScriptInterface& other); virtual bool IsMultithreadCapable() const override {return true;} @@ -88,4 +88,4 @@ public slots: }; -#endif // COREINTERFACES_H +#endif // ACORESCRIPTINTERFACE_H diff --git a/src/scriptmode/ajavascriptmanager.cpp b/src/scriptmode/ajavascriptmanager.cpp index ab414982..6d10f27e 100644 --- a/src/scriptmode/ajavascriptmanager.cpp +++ b/src/scriptmode/ajavascriptmanager.cpp @@ -5,7 +5,7 @@ #endif #include "ascriptinterface.h" -#include "coreinterfaces.h" +#include "acorescriptinterface.h" #include "amathscriptinterface.h" #include "ascriptinterfacefactory.h" #include "ainterfacetomultithread.h" @@ -222,7 +222,7 @@ void AJavaScriptManager::RegisterCoreInterfaces(bool bCore, bool bMath) { if (bCore) { - coreObj = new AInterfaceToCore(this); + coreObj = new ACoreScriptInterface(this); QScriptValue coreVal = engine->newQObject(coreObj, QScriptEngine::QtOwnership); engine->globalObject().setProperty("core", coreVal); doRegister(coreObj, "core"); @@ -471,7 +471,7 @@ AJavaScriptManager *AJavaScriptManager::createNewScriptManager(int threadNumber, // qDebug() << "Making available for multi-thread use: "<objectName(); //special for core unit - AInterfaceToCore* core = dynamic_cast(copy); + ACoreScriptInterface* core = dynamic_cast(copy); if (core) { //qDebug() << "--this is core"; @@ -514,7 +514,7 @@ AJavaScriptManager *AJavaScriptManager::createNewScriptManager(int threadNumber, if (bAbortIsGlobal) { AScriptInterface* base = dynamic_cast(copy); - if (base) connect(base, &AScriptInterface::AbortScriptEvaluation, coreObj, &AInterfaceToCore::abort); + if (base) connect(base, &AScriptInterface::AbortScriptEvaluation, coreObj, &ACoreScriptInterface::abort); } sm->RegisterInterface(copy, si->objectName()); diff --git a/src/scriptmode/ajavascriptmanager.h b/src/scriptmode/ajavascriptmanager.h index 5e24da77..4c6c17f2 100644 --- a/src/scriptmode/ajavascriptmanager.h +++ b/src/scriptmode/ajavascriptmanager.h @@ -53,7 +53,7 @@ class AJavaScriptManager : public AScriptManager QScriptValue getProperty(const QString& properyName) const; QScriptValue registerNewVariant(const QVariant &Variant); QScriptValue EvaluationResult; - AInterfaceToCore* coreObj = 0; //core interface - to forward evaluate-script-in-script + ACoreScriptInterface* coreObj = 0; //core interface - to forward evaluate-script-in-script public slots: #ifdef GUI diff --git a/src/scriptmode/apythonscriptmanager.cpp b/src/scriptmode/apythonscriptmanager.cpp index 1a30509c..da946b22 100644 --- a/src/scriptmode/apythonscriptmanager.cpp +++ b/src/scriptmode/apythonscriptmanager.cpp @@ -3,7 +3,7 @@ #include "apythonscriptmanager.h" #include "ascriptinterface.h" -#include "coreinterfaces.h" +#include "acorescriptinterface.h" APythonScriptManager::APythonScriptManager(TRandom2 *RandGen) : AScriptManager(RandGen) @@ -59,7 +59,7 @@ void APythonScriptManager::RegisterCoreInterfaces(bool bCore, bool bMath) { if (bCore) { - AInterfaceToCore* coreObj = new AInterfaceToCore(this); + ACoreScriptInterface* coreObj = new ACoreScriptInterface(this); RegisterInterface(coreObj, "core"); } diff --git a/src/scriptmode/ascriptinterfacefactory.h b/src/scriptmode/ascriptinterfacefactory.h index 7d10207e..b543659b 100644 --- a/src/scriptmode/ascriptinterfacefactory.h +++ b/src/scriptmode/ascriptinterfacefactory.h @@ -2,7 +2,7 @@ #define ASCRIPTINTERFACEFACTORY_H #include "ascriptinterface.h" -#include "coreinterfaces.h" +#include "acorescriptinterface.h" #include "amathscriptinterface.h" #include "interfacetoglobscript.h" #include "scriptminimizer.h" @@ -19,8 +19,8 @@ class AScriptInterfaceFactory public: static AScriptInterface* makeCopy(const AScriptInterface* other) { - const AInterfaceToCore* core = dynamic_cast(other); - if (core) return new AInterfaceToCore(*core); + const ACoreScriptInterface* core = dynamic_cast(other); + if (core) return new ACoreScriptInterface(*core); const AMathScriptInterface* math = dynamic_cast(other); if (math) return new AMathScriptInterface(*math); diff --git a/src/scriptmode/ascriptmanager.h b/src/scriptmode/ascriptmanager.h index 12ad9b88..09b604f7 100644 --- a/src/scriptmode/ascriptmanager.h +++ b/src/scriptmode/ascriptmanager.h @@ -8,7 +8,7 @@ class AScriptInterface; class TRandom2; -class AInterfaceToCore; +class ACoreScriptInterface; class QElapsedTimer; class AScriptManager : public QObject From 310e709914aa27ee36bd4a6034148f6b8d57a6e2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 31 Oct 2018 10:35:21 +0000 Subject: [PATCH 124/140] particlesourcesclass ->asourceparticlegenerator --- src/ants2.pro | 8 +-- src/common/aconfiguration.cpp | 2 +- src/common/aconfiguration.h | 6 +-- .../MainWindowParticleSimulation.cpp | 2 +- .../MainWindowTools/MainWindowParticles.cpp | 2 +- .../MainWindowTools/aparticlesourcedialog.cpp | 4 +- .../MainWindowTools/aparticlesourcedialog.h | 2 +- src/gui/MainWindowTools/mainwindowjson.cpp | 2 +- src/gui/checkupwindowclass.cpp | 2 +- src/gui/mainwindow.cpp | 2 +- src/main.cpp | 2 +- ...class.cpp => asourceparticlegenerator.cpp} | 50 +++++++++---------- ...rcesclass.h => asourceparticlegenerator.h} | 24 ++++----- src/modules/simulationmanager.cpp | 6 +-- src/modules/simulationmanager.h | 4 +- 15 files changed, 59 insertions(+), 59 deletions(-) rename src/modules/{particlesourcesclass.cpp => asourceparticlegenerator.cpp} (90%) rename src/modules/{particlesourcesclass.h => asourceparticlegenerator.h} (78%) diff --git a/src/ants2.pro b/src/ants2.pro index f88d8043..f49d7cab 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -261,7 +261,6 @@ SOURCES += main.cpp \ modules/eventsdataclass.cpp \ modules/dynamicpassiveshandler.cpp \ modules/processorclass.cpp \ - modules/particlesourcesclass.cpp \ modules/flatfield.cpp \ modules/sensorlrfs.cpp \ modules/manifesthandling.cpp \ @@ -361,7 +360,8 @@ SOURCES += main.cpp \ modules/afileparticlegenerator.cpp \ scriptmode/aparticlegeneratorinterface.cpp \ common/aparticlerecord.cpp \ - scriptmode/acorescriptinterface.cpp + scriptmode/acorescriptinterface.cpp \ + modules/asourceparticlegenerator.cpp HEADERS += common/CorrelationFilters.h \ common/jsonparser.h \ @@ -383,7 +383,6 @@ HEADERS += common/CorrelationFilters.h \ common/ageoobject.h \ OpticalOverrides/aopticaloverride.h \ modules/detectorclass.h \ - modules/particlesourcesclass.h \ modules/flatfield.h \ modules/sensorlrfs.h \ modules/eventsdataclass.h \ @@ -499,7 +498,8 @@ HEADERS += common/CorrelationFilters.h \ modules/afileparticlegenerator.h \ scriptmode/aparticlegeneratorinterface.h \ common/aparticlerecord.h \ - scriptmode/acorescriptinterface.h + scriptmode/acorescriptinterface.h \ + modules/asourceparticlegenerator.h # --- SIM --- ants2_SIM { diff --git a/src/common/aconfiguration.cpp b/src/common/aconfiguration.cpp index 956f3df7..4b48a56b 100644 --- a/src/common/aconfiguration.cpp +++ b/src/common/aconfiguration.cpp @@ -4,7 +4,7 @@ #include "alrfmoduleselector.h" #include "apmgroupsmanager.h" #include "amaterialparticlecolection.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "asandwich.h" #include "generalsimsettings.h" #include "apmhub.h" diff --git a/src/common/aconfiguration.h b/src/common/aconfiguration.h index ac66039a..57f186de 100644 --- a/src/common/aconfiguration.h +++ b/src/common/aconfiguration.h @@ -6,7 +6,7 @@ #include class DetectorClass; -class ParticleSourcesClass; +class ASourceParticleGenerator; class AConfiguration : public QObject { @@ -19,7 +19,7 @@ class AConfiguration : public QObject QString ErrorString; // Last detected error (load config) void SetDetector(DetectorClass* detector) {Detector = detector;} - void SetParticleSources(ParticleSourcesClass* particleSources) {ParticleSources = particleSources;} + void SetParticleSources(ASourceParticleGenerator* particleSources) {ParticleSources = particleSources;} DetectorClass* GetDetector() {return Detector;} // save/load to json @@ -78,7 +78,7 @@ public slots: private: DetectorClass* Detector; // Link to the Detector object - ParticleSourcesClass* ParticleSources; // Link to the ParticleSources object of SimulationManager + ASourceParticleGenerator* ParticleSources; // Link to the ParticleSources object of SimulationManager }; diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index 98ef811a..ee57f98a 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -7,7 +7,7 @@ #include "eventsdataclass.h" #include "windownavigatorclass.h" #include "geometrywindowclass.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "afileparticlegenerator.h" #include "ascriptparticlegenerator.h" #include "graphwindowclass.h" diff --git a/src/gui/MainWindowTools/MainWindowParticles.cpp b/src/gui/MainWindowTools/MainWindowParticles.cpp index 75e9e442..bf5435d3 100644 --- a/src/gui/MainWindowTools/MainWindowParticles.cpp +++ b/src/gui/MainWindowTools/MainWindowParticles.cpp @@ -5,7 +5,7 @@ #include "materialinspectorwindow.h" #include "outputwindow.h" #include "detectorclass.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "amessage.h" #include "aconfiguration.h" #include "atrackrecords.h" diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.cpp b/src/gui/MainWindowTools/aparticlesourcedialog.cpp index 825f6fce..f3929577 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.cpp +++ b/src/gui/MainWindowTools/aparticlesourcedialog.cpp @@ -8,7 +8,7 @@ #include "graphwindowclass.h" #include "aglobalsettings.h" #include "ajsontools.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "detectorclass.h" #include @@ -104,7 +104,7 @@ void AParticleSourceDialog::on_pbReject_clicked() void AParticleSourceDialog::on_pbGunTest_clicked() { - ParticleSourcesClass ps(MW.Detector, MW.Detector->RandGen); + ASourceParticleGenerator ps(MW.Detector, MW.Detector->RandGen); ps.append(Rec); MW.GeometryWindow->ShowAndFocus(); diff --git a/src/gui/MainWindowTools/aparticlesourcedialog.h b/src/gui/MainWindowTools/aparticlesourcedialog.h index b291d5c0..85f505b6 100644 --- a/src/gui/MainWindowTools/aparticlesourcedialog.h +++ b/src/gui/MainWindowTools/aparticlesourcedialog.h @@ -1,7 +1,7 @@ #ifndef APARTICLESOURCEDIALOG_H #define APARTICLESOURCEDIALOG_H -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 153ec4f7..5275be0b 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -10,7 +10,7 @@ #include "geometrywindowclass.h" #include "aconfiguration.h" #include "ajsontools.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "afileparticlegenerator.h" #include "ascriptparticlegenerator.h" #include "apmhub.h" diff --git a/src/gui/checkupwindowclass.cpp b/src/gui/checkupwindowclass.cpp index c20c0dbb..1cc167d8 100644 --- a/src/gui/checkupwindowclass.cpp +++ b/src/gui/checkupwindowclass.cpp @@ -7,7 +7,7 @@ #include "apmtype.h" #include "materialinspectorwindow.h" #include "generalsimsettings.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "aglobalsettings.h" #include "aparticlesourcerecord.h" #include "simulationmanager.h" diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index a55f1840..e613d7a4 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -49,7 +49,7 @@ #include "ascriptwindow.h" #include "gui/alrfwindow.h" #include "acustomrandomsampling.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "ajavascriptmanager.h" #include "ascriptwindow.h" #include "aremotewindow.h" diff --git a/src/main.cpp b/src/main.cpp index e4506e9e..8048c00f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,7 +14,7 @@ #include "aglobalsettings.h" #include "afiletools.h" #include "aqtmessageredirector.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "anetworkmodule.h" #include "asandwich.h" #include "amessageoutput.h" diff --git a/src/modules/particlesourcesclass.cpp b/src/modules/asourceparticlegenerator.cpp similarity index 90% rename from src/modules/particlesourcesclass.cpp rename to src/modules/asourceparticlegenerator.cpp index f297d7b7..aabb5dcb 100644 --- a/src/modules/particlesourcesclass.cpp +++ b/src/modules/asourceparticlegenerator.cpp @@ -1,4 +1,4 @@ -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "aparticlerecord.h" #include "aparticlesourcerecord.h" #include "detectorclass.h" @@ -20,22 +20,22 @@ #include "TRandom2.h" #include "TGeoManager.h" -ParticleSourcesClass::ParticleSourcesClass(const DetectorClass *Detector, TRandom2 *RandGen) +ASourceParticleGenerator::ASourceParticleGenerator(const DetectorClass *Detector, TRandom2 *RandGen) : Detector(Detector), MpCollection(Detector->MpCollection), RandGen(RandGen) {} -ParticleSourcesClass::~ParticleSourcesClass() +ASourceParticleGenerator::~ASourceParticleGenerator() { clear(); } -void ParticleSourcesClass::clear() +void ASourceParticleGenerator::clear() { for (int i=0; iGunParticles[iparticle]->Individual) continue; //nothing to do for non-individual particles //every individual particles defines an "event generation chain" containing the particle iteslf and all linked (and linked to linked to linked etc) particles - LinkedPartiles[isource][iparticle].append(LinkedParticleStructure(iparticle)); //list always contains the particle itself - simplifies the generation algorithm + LinkedPartiles[isource][iparticle].append(ALinkedParticle(iparticle)); //list always contains the particle itself - simplifies the generation algorithm //only particles with larger indexes can be linked to this particle for (int ip=iparticle+1; ipGunParticles[ip]->Individual) //only looking for non-individuals @@ -94,7 +94,7 @@ bool ParticleSourcesClass::Init() int linkedTo = ParticleSourcesData[isource]->GunParticles[ip]->LinkedTo; if ( linkedTo == compareWith) { - LinkedPartiles[isource][iparticle].append(LinkedParticleStructure(ip, linkedTo)); + LinkedPartiles[isource][iparticle].append(ALinkedParticle(ip, linkedTo)); break; } } @@ -132,7 +132,7 @@ bool ParticleSourcesClass::Init() return true; //TODO check for fails } -bool ParticleSourcesClass::GenerateEvent(QVector & GeneratedParticles) +bool ASourceParticleGenerator::GenerateEvent(QVector & GeneratedParticles) { bAbortRequested = false; //after any operation with sources (add, remove), init should be called before first use! @@ -186,7 +186,7 @@ bool ParticleSourcesClass::GenerateEvent(QVector & GeneratedPa { //there are no linked particles //qDebug()<<"Generating individual particle"<r[0] = R[0]; GeneratedParticles.last()->r[1] = R[1]; GeneratedParticles.last()->r[2] = R[2]; @@ -240,7 +240,7 @@ bool ParticleSourcesClass::GenerateEvent(QVector & GeneratedPa WasGenerated[ip] = true; if (!fOpposite) - ParticleSourcesClass::AddParticleInCone(isource, thisParticle, GeneratedParticles); + ASourceParticleGenerator::AddParticleInCone(isource, thisParticle, GeneratedParticles); else { //find index in the GeneratedParticles @@ -269,7 +269,7 @@ bool ParticleSourcesClass::GenerateEvent(QVector & GeneratedPa return true; } -void ParticleSourcesClass::GeneratePosition(int isource, double *R) const +void ASourceParticleGenerator::GeneratePosition(int isource, double *R) const { const int& index = ParticleSourcesData[isource]->shape; const double& X0 = ParticleSourcesData[isource]->X0; @@ -392,7 +392,7 @@ void ParticleSourcesClass::GeneratePosition(int isource, double *R) const return; } -void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector & GeneratedParticles) const +void ASourceParticleGenerator::AddParticleInCone(int isource, int iparticle, QVector & GeneratedParticles) const { AParticleRecord* ps = new AParticleRecord(); @@ -414,7 +414,7 @@ void ParticleSourcesClass::AddParticleInCone(int isource, int iparticle, QVector GeneratedParticles << ps; } -TVector3 ParticleSourcesClass::GenerateRandomDirection() +TVector3 ASourceParticleGenerator::GenerateRandomDirection() { //Sphere function of Root: double a=0,b=0,r2=1; @@ -430,7 +430,7 @@ TVector3 ParticleSourcesClass::GenerateRandomDirection() } #include -bool ParticleSourcesClass::IsParticleInUse(int particleId, QString &SourceNames) const +bool ASourceParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const { SourceNames.clear(); QSet sources; @@ -456,7 +456,7 @@ bool ParticleSourcesClass::IsParticleInUse(int particleId, QString &SourceNames) } } -void ParticleSourcesClass::RemoveParticle(int particleId) +void ASourceParticleGenerator::RemoveParticle(int particleId) { for (int isource=0; isourceActivity; } -void ParticleSourcesClass::writeToJson(QJsonObject &json) const +void ASourceParticleGenerator::writeToJson(QJsonObject &json) const { QJsonArray ja; for (const AParticleSourceRecord* ps : ParticleSourcesData) @@ -492,7 +492,7 @@ void ParticleSourcesClass::writeToJson(QJsonObject &json) const json["ParticleSources"] = ja; } -bool ParticleSourcesClass::readFromJson(const QJsonObject &json) +bool ASourceParticleGenerator::readFromJson(const QJsonObject &json) { clear(); @@ -521,7 +521,7 @@ bool ParticleSourcesClass::readFromJson(const QJsonObject &json) return true; } -void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) +void ASourceParticleGenerator::checkLimitedToMaterial(AParticleSourceRecord* s) { bool fFound = false; int iMat; @@ -540,7 +540,7 @@ void ParticleSourcesClass::checkLimitedToMaterial(AParticleSourceRecord* s) else s->fLimit = false; } -bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName) +bool ASourceParticleGenerator::LoadGunEnergySpectrum(int iSource, int iParticle, QString fileName) { if (iSource < 0 || iSource >= ParticleSourcesData.size()) { @@ -573,19 +573,19 @@ bool ParticleSourcesClass::LoadGunEnergySpectrum(int iSource, int iParticle, QSt return true; } -void ParticleSourcesClass::append(AParticleSourceRecord *gunParticle) +void ASourceParticleGenerator::append(AParticleSourceRecord *gunParticle) { ParticleSourcesData.append(gunParticle); CalculateTotalActivity(); } -void ParticleSourcesClass::forget(AParticleSourceRecord *gunParticle) +void ASourceParticleGenerator::forget(AParticleSourceRecord *gunParticle) { ParticleSourcesData.removeAll(gunParticle); CalculateTotalActivity(); } -bool ParticleSourcesClass::replace(int iSource, AParticleSourceRecord *gunParticle) +bool ASourceParticleGenerator::replace(int iSource, AParticleSourceRecord *gunParticle) { if (iSource < 0 || iSource >= ParticleSourcesData.size()) return false; @@ -594,7 +594,7 @@ bool ParticleSourcesClass::replace(int iSource, AParticleSourceRecord *gunPartic return true; } -void ParticleSourcesClass::remove(int iSource) +void ASourceParticleGenerator::remove(int iSource) { if (ParticleSourcesData.isEmpty()) return; if (iSource < 0 || iSource >= ParticleSourcesData.size()) return; diff --git a/src/modules/particlesourcesclass.h b/src/modules/asourceparticlegenerator.h similarity index 78% rename from src/modules/particlesourcesclass.h rename to src/modules/asourceparticlegenerator.h index d077f1c5..bab7390f 100644 --- a/src/modules/particlesourcesclass.h +++ b/src/modules/asourceparticlegenerator.h @@ -1,5 +1,5 @@ -#ifndef PARTICLESOURCESCLASS_H -#define PARTICLESOURCESCLASS_H +#ifndef ASOURCEPARTICLEGENERATOR_H +#define ASOURCEPARTICLEGENERATOR_H #include "aparticlegun.h" @@ -13,21 +13,21 @@ class TRandom2; class DetectorClass; struct AParticleSourceRecord; -class LinkedParticleStructure +class ALinkedParticle { public: - int iParticle; //indexed according to GunParticles index - int LinkedTo; //index of particle it is linked to + int iParticle; //indexed according to GunParticles index + int LinkedTo; //index of particle it is linked to - LinkedParticleStructure() {} - LinkedParticleStructure(int iparticle, int linkedto = -1) {iParticle = iparticle; LinkedTo = linkedto;} + ALinkedParticle() {} + ALinkedParticle(int iparticle, int linkedto = -1) {iParticle = iparticle; LinkedTo = linkedto;} }; -class ParticleSourcesClass : public AParticleGun +class ASourceParticleGenerator : public AParticleGun { public: - ParticleSourcesClass(const DetectorClass* Detector, TRandom2* RandGen); - ~ParticleSourcesClass(); + ASourceParticleGenerator(const DetectorClass* Detector, TRandom2* RandGen); + ~ASourceParticleGenerator(); virtual bool Init() override; // !!! has to be called before the first use of "GenerateEvent"! virtual bool GenerateEvent(QVector & GeneratedParticles) override; //see Init!!! @@ -62,7 +62,7 @@ class ParticleSourcesClass : public AParticleGun QVector ParticleSourcesData; QVector TotalParticleWeight; double TotalActivity = 0; - QVector< QVector< QVector > > LinkedPartiles; //[isource] [iparticle] [] (includes the record of the particle iteslf!!!) + QVector< QVector< QVector > > LinkedPartiles; //[isource] [iparticle] [] (includes the record of the particle iteslf!!!) //full recipe of emission builder (containes particles linked to particles etc up to the top level individual particle) QVector CollimationDirection; //[isource] collimation direction @@ -74,4 +74,4 @@ class ParticleSourcesClass : public AParticleGun void AddParticleInCone(int isource, int iparticle, QVector & GeneratedParticles) const; //QVector - only pointer is transferred! }; -#endif // PARTICLESOURCESCLASS_H +#endif // ASOURCEPARTICLEGENERATOR_H diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 944a9d8b..abc9ee08 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -8,7 +8,7 @@ #include "primaryparticletracker.h" #include "s1_generator.h" #include "s2_generator.h" -#include "particlesourcesclass.h" +#include "asourceparticlegenerator.h" #include "afileparticlegenerator.h" #include "ascriptparticlegenerator.h" #include "amaterialparticlecolection.h" @@ -1465,7 +1465,7 @@ bool ParticleSourceSimulator::setup(QJsonObject &json) // particle sources if (js.contains("ParticleSources")) { - ParticleGun = new ParticleSourcesClass(detector, RandGen); + ParticleGun = new ASourceParticleGenerator(detector, RandGen); ParticleGun->readFromJson(js); fAllowMultiple = cjs["AllowMultipleParticles"].toBool(); @@ -1815,7 +1815,7 @@ ASimulationManager::ASimulationManager(EventsDataClass* EventsDataHub, DetectorC this->EventsDataHub = EventsDataHub; this->Detector = Detector; - ParticleSources = new ParticleSourcesClass(Detector, Detector->RandGen); + ParticleSources = new ASourceParticleGenerator(Detector, Detector->RandGen); FileParticleGenerator = new AFileParticleGenerator(*Detector->MpCollection); ScriptParticleGenerator = new AScriptParticleGenerator(*Detector->MpCollection, Detector->RandGen); ScriptParticleGenerator->SetProcessInterval(200); diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 1dd1b176..8e6f8116 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -25,7 +25,7 @@ class Photon_Generator; class PrimaryParticleTracker; class S1_Generator; class S2_Generator; -class ParticleSourcesClass; +class ASourceParticleGenerator; class AFileParticleGenerator; class AScriptParticleGenerator; class Simulator; @@ -78,7 +78,7 @@ class ASimulationManager : public QObject void Clear(); // Next three: Simulators use their own local copies constructed using configuration in JSON - ParticleSourcesClass* ParticleSources = 0; //used to update JSON on config changes and in GUI to configure + ASourceParticleGenerator* ParticleSources = 0; //used to update JSON on config changes and in GUI to configure AFileParticleGenerator* FileParticleGenerator = 0; //only for gui, simulation threads use their own AScriptParticleGenerator* ScriptParticleGenerator = 0; //only for gui, simulation threads use their own From 64c8bb7f0cea8d1cb908754d034886d7ad47c987 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 31 Oct 2018 11:07:18 +0000 Subject: [PATCH 125/140] ++ --- src/modules/afileparticlegenerator.cpp | 1 + src/modules/simulationmanager.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index a763aa37..5f6b34d6 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -104,6 +104,7 @@ bool AFileParticleGenerator::GenerateEvent(QVector & Generated { while (!Stream->atEnd()) { + if (bAbortRequested) return false; const QString line = Stream->readLine(); QStringList f = line.split(rx, QString::SkipEmptyParts); //format: ParticleId Energy X Y Z VX VY VZ * //'*' is optional - indicates event not finished yet diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index abc9ee08..51a5b4dc 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -1582,10 +1582,13 @@ void ParticleSourceSimulator::simulate() //qDebug()<<"----particle runs this event: "<GenerateEvent(GeneratedParticles); + bGenerationSuccessful = ParticleGun->GenerateEvent(GeneratedParticles); + //qDebug() << "thr--->"< " << bGenerationSuccessful << GeneratedParticles.size(); + if (!bGenerationSuccessful) break; //adding particles to the stack for (AParticleRecord * p : GeneratedParticles) @@ -1599,6 +1602,7 @@ void ParticleSourceSimulator::simulate() GeneratedParticles.clear(); //do not delete particles - they were transferred to the ParticleStack! } //event prepared // qDebug()<<"event! Particle stack length:"< end of file reached ParticleTracker->TrackParticlesOnStack(eventCurrent); //energy vector is ready @@ -1644,7 +1648,9 @@ void ParticleSourceSimulator::simulate() } //all events finished fSuccess = !fHardAbortWasTriggered; + //qDebug() << "----Releasing resources"; if (ParticleGun) ParticleGun->ReleaseResources(); + //qDebug() << "done!"< Date: Wed, 31 Oct 2018 13:15:11 +0000 Subject: [PATCH 126/140] ++ --- src/modules/ascriptparticlegenerator.cpp | 2 +- src/modules/simulationmanager.cpp | 53 ++++++++++++++---------- src/modules/simulationmanager.h | 6 +-- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/modules/ascriptparticlegenerator.cpp b/src/modules/ascriptparticlegenerator.cpp index 73e74e2a..6fb7a6cf 100644 --- a/src/modules/ascriptparticlegenerator.cpp +++ b/src/modules/ascriptparticlegenerator.cpp @@ -71,5 +71,5 @@ bool AScriptParticleGenerator::readFromJson(const QJsonObject &json) void AScriptParticleGenerator::abort() { bAbortRequested = true; - ScriptEngine->abortEvaluation(); + if (ScriptEngine) ScriptEngine->abortEvaluation(); } diff --git a/src/modules/simulationmanager.cpp b/src/modules/simulationmanager.cpp index 51a5b4dc..73a666c4 100644 --- a/src/modules/simulationmanager.cpp +++ b/src/modules/simulationmanager.cpp @@ -323,18 +323,18 @@ void ASimulatorRunner::simulate() #else //std::thread -> start on construction for (int i=0; i < workers.count(); i++) - { - // qDebug() << "Asking thread"<<(i+1)<<" to join..."; + { + //qDebug() << "Asking thread"<<(i+1)<<" to join..."; threads[i]->join(); - // qDebug() <<"Thread"<<(i+1)<<"joined"; - } + //qDebug() <<" Thread"<<(i+1)<<"joined"; + } #endif + //qDebug() << "SimRunner: all threads joined"; for (int i=0; ifSimulatedData = true; dataHub->LastSimSet = simSettings; - ErrorString.clear(); + //qDebug() << "SimRunner: Collecting data from workers"; for(int i = 0; i < workers.count(); i++) { workers[i]->appendToDataHub(dataHub); @@ -352,7 +352,7 @@ void ASimulatorRunner::simulate() ErrorString += QString("Thread %1 reported error: %2\n").arg(i).arg(err); } - //qDebug()<<"Simulation finished!"; + //qDebug()<<"Sim runner reports simulation finished!"; // qDebug() << "\n Pointer of the List of navigators: "<< detector->GeoManager->GetListOfNavigators(); // if (detector->GeoManager->IsMultiThread()) @@ -451,13 +451,13 @@ void Simulator::requestStop() { if (fStopRequested) { - //qDebug() << "Simulator recived repeated stop request, aborting in hard mode"; + // qDebug() << "Simulator #" << ID << "recived repeated stop request, aborting in hard mode"; hardAbort(); fHardAbortWasTriggered = true; } else { - //qDebug() << "First stop request was received by simulator"; + // qDebug() << "First stop request was received by simulator #"< appending data"; Simulator::appendToDataHub(dataHub); dataHub->ScanNumberOfRuns = this->NumRuns; } @@ -1545,7 +1547,7 @@ void ParticleSourceSimulator::updateGeoManager() void ParticleSourceSimulator::simulate() { - if ( !ParticleStack.isEmpty() ) // *** to be moved to "ClearData"? + if ( !ParticleStack.isEmpty() ) // TODO --> to be moved to "ClearData"? { for (int i=0; iGenerateEvent(GeneratedParticles); - //qDebug() << "thr--->"< " << bGenerationSuccessful << GeneratedParticles.size(); + // qDebug() << "thr--->"< " << bGenerationSuccessful << GeneratedParticles.size(); if (!bGenerationSuccessful) break; //adding particles to the stack @@ -1648,13 +1650,14 @@ void ParticleSourceSimulator::simulate() } //all events finished fSuccess = !fHardAbortWasTriggered; - //qDebug() << "----Releasing resources"; + // qDebug() << "----Releasing resources"; if (ParticleGun) ParticleGun->ReleaseResources(); - //qDebug() << "done!"<countEvents(); } void ParticleSourceSimulator::appendToDataHub(EventsDataClass *dataHub) { + //qDebug() << "Thread #"< appending data"; Simulator::appendToDataHub(dataHub); int oldSize = dataHub->EventHistory.count(); dataHub->EventHistory.reserve(oldSize + this->dataHub->EventHistory.count()); @@ -1828,15 +1831,19 @@ ASimulationManager::ASimulationManager(EventsDataClass* EventsDataHub, DetectorC Runner = new ASimulatorRunner(Detector, EventsDataHub); - QObject::connect(Runner, SIGNAL(simulationFinished()), this, SLOT(onSimulationFinished())); - QObject::connect(this, SIGNAL(RequestStopSimulation()), Runner, SLOT(requestStop()), Qt::DirectConnection); + //QObject::connect(Runner, SIGNAL(simulationFinished()), this, SLOT(onSimulationFinished())); + QObject::connect(Runner, &ASimulatorRunner::simulationFinished, this, &ASimulationManager::onSimulationFinished); + //QObject::connect(this, SIGNAL(RequestStopSimulation()), Runner, SLOT(requestStop()), Qt::DirectConnection); + QObject::connect(this, &ASimulationManager::RequestStopSimulation, Runner, &ASimulatorRunner::requestStop, Qt::DirectConnection); - Runner->moveToThread(&simThread); //Move to background thread, as it always runs synchronously even in MT - QObject::connect(&simThread, SIGNAL(started()), Runner, SLOT(simulate())); //Connect thread to simulation start + Runner->moveToThread(&simRunnerThread); //Move to background thread, as it always runs synchronously even in MT + //QObject::connect(&simRunnerThread, SIGNAL(started()), Runner, SLOT(simulate())); //Connect thread to simulation start + QObject::connect(&simRunnerThread, &QThread::started, Runner, &ASimulatorRunner::simulate); //Connect thread to simulation start + //GUI update simTimerGuiUpdate.setInterval(1000); - QObject::connect(&simTimerGuiUpdate, SIGNAL(timeout()), Runner, SLOT(updateGui()), Qt::DirectConnection); - + //QObject::connect(&simTimerGuiUpdate, SIGNAL(timeout()), Runner, SLOT(updateGui()), Qt::DirectConnection); + QObject::connect(&simTimerGuiUpdate, &QTimer::timeout, Runner, &ASimulatorRunner::updateGui, Qt::DirectConnection); QObject::connect(Runner, &ASimulatorRunner::updateReady, this, &ASimulationManager::ProgressReport); } @@ -1869,7 +1876,7 @@ void ASimulationManager::StartSimulation(QJsonObject& json, int threads, bool fF } else { - simThread.start(); + simRunnerThread.start(); simTimerGuiUpdate.start(); } } @@ -1909,10 +1916,12 @@ void ASimulationManager::clearTracks() void ASimulationManager::onSimulationFinished() { + // qDebug() << "Simulation manager: Simulation finished"; + //qDebug() << "after finish, manager has monitors:"<< EventsDataHub->SimStat->Monitors.size(); simTimerGuiUpdate.stop(); QThread::usleep(5000); // to make sure update cycle is finished - simThread.quit(); + simRunnerThread.quit(); fFinished = true; fSuccess = Runner->wasSuccessful(); diff --git a/src/modules/simulationmanager.h b/src/modules/simulationmanager.h index 8e6f8116..8375cbfe 100644 --- a/src/modules/simulationmanager.h +++ b/src/modules/simulationmanager.h @@ -57,7 +57,7 @@ class ASimulationManager : public QObject ~ASimulationManager(); ASimulatorRunner* Runner; - QThread simThread; + QThread simRunnerThread; QTimer simTimerGuiUpdate; bool fFinished; @@ -189,7 +189,7 @@ class Simulator virtual ~Simulator(); const DetectorClass *getDetector() { return detector; } - QString getErrorString() const { return ErrorString; } + const QString getErrorString() const { return ErrorString; } virtual int getEventsDone() const = 0; char progress; @@ -335,7 +335,7 @@ class ParticleSourceSimulator : public Simulator virtual int getTotalEventCount() const { return totalEventCount; } virtual bool setup(QJsonObject &json); virtual void updateGeoManager(); - virtual void simulate(); // TODO watchdogs? + virtual void simulate(); virtual void appendToDataHub(EventsDataClass *dataHub); //test purposes - direct tracking with provided stack or photon generation from provided energy deposition From 089433841e6f2df3bf0a623bc9b0d41d2434e5f2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 1 Nov 2018 09:58:51 +0000 Subject: [PATCH 127/140] ++ --- .../MainWindowParticleSimulation.cpp | 21 +++++-- src/gui/ascriptwindow.cpp | 32 +++++++++- src/gui/ascriptwindow.h | 8 ++- src/gui/ascriptwindow.ui | 62 +++++++++++++++++++ 4 files changed, 113 insertions(+), 10 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index ee57f98a..efe91182 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -902,10 +902,11 @@ void MainWindow::on_pbParticleGenerationScript_clicked() { AJavaScriptManager* sm = new AJavaScriptManager(Detector->RandGen); AScriptWindow* sw = new AScriptWindow(sm, true, this); + sw->EnableAcceptReject(); AParticleGeneratorInterface* gen = new AParticleGeneratorInterface(*Detector->MpCollection, Detector->RandGen); - QVector GeneratedParticles; - gen->configure(&GeneratedParticles); + QVector GP; + gen->configure(&GP); gen->setObjectName("gen"); sw->RegisterInterface(gen, "gen"); //takes ownership AMathScriptInterface* math = new AMathScriptInterface(Detector->RandGen); @@ -914,7 +915,14 @@ void MainWindow::on_pbParticleGenerationScript_clicked() sw->UpdateGui(); - QObject::connect(sw, &AScriptWindow::onStart, [&GeneratedParticles](){for (AParticleRecord* p : GeneratedParticles) delete p; GeneratedParticles.clear();}); + QObject::connect(sw, &AScriptWindow::onFinish, + [&GP, this](bool bError) + { + if (!bError) message(QString("Script generated %1 particle%2").arg(GP.size()).arg(GP.size()==1?"":"s"), this); + for (AParticleRecord* p : GP) delete p; + GP.clear(); + } + ); QString Script = SimulationManager->ScriptParticleGenerator->GetScript(); @@ -931,11 +939,12 @@ void MainWindow::on_pbParticleGenerationScript_clicked() QThread::usleep(200); } - for (AParticleRecord* p : GeneratedParticles) delete p; - GeneratedParticles.clear(); + bool bWasAccepted = sw->isAccepted(); + for (AParticleRecord* p : GP) delete p; + GP.clear(); delete sw; //also deletes script manager - SimulationManager->ScriptParticleGenerator->SetScript(Script); + if (bWasAccepted) SimulationManager->ScriptParticleGenerator->SetScript(Script); on_pbUpdateSimConfig_clicked(); } diff --git a/src/gui/ascriptwindow.cpp b/src/gui/ascriptwindow.cpp index ecc88dd2..cf404f7a 100644 --- a/src/gui/ascriptwindow.cpp +++ b/src/gui/ascriptwindow.cpp @@ -231,6 +231,9 @@ AScriptWindow::AScriptWindow(AScriptManager* ScriptManager, bool LightMode, QWid ui->centralwidget->layout()->addWidget(splMain); ui->centralwidget->layout()->addItem(ui->horizontalLayout); + ui->centralwidget->layout()->removeWidget(ui->frAccept); + ui->centralwidget->layout()->addWidget(ui->frAccept); + trwJson->header()->resizeSection(0, 200); sizes.clear(); @@ -259,9 +262,7 @@ AScriptWindow::AScriptWindow(AScriptManager* ScriptManager, bool LightMode, QWid //QShortcut* DoPaste = new QShortcut(QKeySequence("Ctrl+V"), this); //connect(DoPaste, &QShortcut::activated, [&](){ScriptTabs[CurrentTab]->TextEdit->paste();}); - if (!bLightMode) - ReadFromJson(); - else + if (bLightMode) { ui->pbConfig->setEnabled(false); twScriptTabs->setStyleSheet("QTabWidget::tab-bar { width: 0; height: 0; margin: 0; padding: 0; border: none; }"); @@ -269,7 +270,9 @@ AScriptWindow::AScriptWindow(AScriptManager* ScriptManager, bool LightMode, QWid ui->menuTabs->setEnabled(false); ui->menuView->setEnabled(false); } + else ReadFromJson(); + ui->frAccept->setVisible(false); } AScriptWindow::~AScriptWindow() @@ -540,6 +543,16 @@ void AScriptWindow::ConfigureForLightMode(QString *ScriptPtr, const QString& Win } } +void AScriptWindow::EnableAcceptReject() +{ + ui->frAccept->setVisible(true); + + ui->pbRunScript->setText("Test script"); + QFont f = ui->pbRunScript->font(); + f.setBold(false); + ui->pbRunScript->setFont(f); +} + void AScriptWindow::ShowText(QString text) { pteOut->appendHtml(text); @@ -1172,6 +1185,7 @@ void AScriptWindow::receivedOnSuccess(QString eval) ui->prbProgress->setValue(0); ui->prbProgress->setVisible(false); emit success(eval); + emit onFinish(ScriptManager->isUncaughtException()); } void AScriptWindow::onDefaulFontSizeChanged(int size) @@ -2119,3 +2133,15 @@ void AScriptWindowTabItem::onTextChanged() Variables.append(functions); completitionModel->setStringList(Variables); } + +void AScriptWindow::on_pbAccept_clicked() +{ + bAccepted = true; + close(); +} + +void AScriptWindow::on_pbCancel_clicked() +{ + bAccepted = false; + close(); +} diff --git a/src/gui/ascriptwindow.h b/src/gui/ascriptwindow.h index d5281407..daea9fc1 100644 --- a/src/gui/ascriptwindow.h +++ b/src/gui/ascriptwindow.h @@ -55,6 +55,8 @@ class AScriptWindow : public QMainWindow void onBusyOff(); void ConfigureForLightMode(QString* ScriptPtr, const QString &WindowTitle, const QString& Example); + void EnableAcceptReject(); + bool isAccepted() const {return bAccepted;} AScriptManager* ScriptManager; QStringList functions; @@ -135,7 +137,8 @@ private slots: QList ScriptTabs; QTabWidget* twScriptTabs; - bool bLightMode = false; // true -> to imitate former genericscriptwindow. Used for small local scripts + bool bLightMode = false; // true -> to imitate former genericscriptwindow. Used for local scripts + bool bAccepted = false; QString* LightModeScript = 0; QString LightModeExample; @@ -192,6 +195,7 @@ private slots: //just retranslators: void onStart(); void onAbort(); + void onFinish(bool bError); void success(QString eval); public slots: @@ -209,6 +213,8 @@ private slots: virtual void onFindVariable(); void onBack(); void onForward(); + void on_pbAccept_clicked(); + void on_pbCancel_clicked(); }; class AScriptWindowTabItem : public QObject diff --git a/src/gui/ascriptwindow.ui b/src/gui/ascriptwindow.ui index 09317f14..40466eeb 100644 --- a/src/gui/ascriptwindow.ui +++ b/src/gui/ascriptwindow.ui @@ -204,6 +204,68 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 150 + 0 + + + + + 75 + true + + + + Accept changes + + + + + + + + 150 + 0 + + + + + 50 + false + + + + Cancel + + + + + + From 2478d2f294050f94df60d6eeab2adb11ad930964 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 1 Nov 2018 10:01:28 +0000 Subject: [PATCH 128/140] ++ --- src/gui/MainWindowTools/MainWindowParticleSimulation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index efe91182..fd077625 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -916,9 +916,9 @@ void MainWindow::on_pbParticleGenerationScript_clicked() sw->UpdateGui(); QObject::connect(sw, &AScriptWindow::onFinish, - [&GP, this](bool bError) + [&GP, sw](bool bError) { - if (!bError) message(QString("Script generated %1 particle%2").arg(GP.size()).arg(GP.size()==1?"":"s"), this); + if (!bError) message(QString("Script generated %1 particle%2").arg(GP.size()).arg(GP.size()==1?"":"s"), sw); for (AParticleRecord* p : GP) delete p; GP.clear(); } From 357cd3a0af7d5a6ade89c949fdb123ad727a4fe9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 1 Nov 2018 12:19:25 +0000 Subject: [PATCH 129/140] GUI: add tracks on indication --- src/gui/MainWindowTools/MainWindowInits.cpp | 6 +++ src/gui/MainWindowTools/mainwindowjson.cpp | 4 ++ src/gui/mainwindow.ui | 46 +++++++++++++++++---- src/modules/afileparticlegenerator.cpp | 40 ++++++++++++++---- src/modules/afileparticlegenerator.h | 10 +++-- 5 files changed, 86 insertions(+), 20 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowInits.cpp b/src/gui/MainWindowTools/MainWindowInits.cpp index d305d906..ffc92026 100644 --- a/src/gui/MainWindowTools/MainWindowInits.cpp +++ b/src/gui/MainWindowTools/MainWindowInits.cpp @@ -246,6 +246,12 @@ MainWindow::MainWindow(DetectorClass *Detector, ui->labIgnoreNoHitEvents->setVisible(false); ui->labIgnoreNoDepoEvents->setPixmap(Rwindow->YellowIcon.pixmap(16,16)); ui->labIgnoreNoDepoEvents->setVisible(false); + ui->labPhTracksOn->setPixmap(Rwindow->YellowIcon.pixmap(8,8)); + ui->labPhTracksOn->setVisible(false); + ui->labPhTracksOn_1->setPixmap(Rwindow->YellowIcon.pixmap(8,8)); + ui->labPhTracksOn_1->setVisible(false); + ui->labPartTracksOn->setPixmap(Rwindow->YellowIcon.pixmap(8,8)); + ui->labPartTracksOn->setVisible(false); //misc gui inits ui->swPMTvsSiPM->setCurrentIndex(ui->cobPMdeviceType->currentIndex()); MainWindow::on_pbRefreshPMproperties_clicked(); //indication of PM properties diff --git a/src/gui/MainWindowTools/mainwindowjson.cpp b/src/gui/MainWindowTools/mainwindowjson.cpp index 5275be0b..97e1f1ce 100644 --- a/src/gui/MainWindowTools/mainwindowjson.cpp +++ b/src/gui/MainWindowTools/mainwindowjson.cpp @@ -554,6 +554,7 @@ if (scj.contains("CustomDistrib")) CustomScanNodes.append( new QVector3D(el[0].toDouble(), el[1].toDouble(), el[2].toDouble())); } ui->lScriptNodes->setText( QString::number(CustomScanNodes.size()) ); + ui->labPhTracksOn->setVisible(SimulationManager->TrackBuildOptions.bBuildPhotonTracks); //PARTICLE SOURCES QJsonObject psjs = js["ParticleSourcesConfig"].toObject(); @@ -598,6 +599,9 @@ if (scj.contains("CustomDistrib")) SimulationManager->ScriptParticleGenerator->readFromJson(sjs); updateScriptParticleGeneratorGui(); + ui->labPhTracksOn_1->setVisible(SimulationManager->TrackBuildOptions.bBuildPhotonTracks); + ui->labPartTracksOn->setVisible(SimulationManager->TrackBuildOptions.bBuildParticleTracks); + //Window CONTROL if (js.contains("Mode")) diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 97930738..8511938e 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -8664,7 +8664,7 @@ Second click will trigger strong abort mode, which will result in loss of all si - 350 + 370 208 111 21 @@ -8687,23 +8687,23 @@ Right click: toggle build photon tracks. Also switches of building particle trac tracks options - + - 270 - 218 - 118 - 3 + 359 + 210 + 21 + 16 - - Qt::Horizontal + + -- - line_11 twSingleScan pbSimulate frLimitNodesTo + labPhTracksOn pbOpenTrackProperties_Phot @@ -10192,6 +10192,32 @@ Right click: toggle build particle tracks. Also switch off building photon track Particle generation mode: + + + + 413 + 338 + 21 + 16 + + + + -- + + + + + + 413 + 347 + 21 + 16 + + + + -- + + linePS cbGunDoS1 cbGunDoS2 @@ -10207,6 +10233,8 @@ Right click: toggle build particle tracks. Also switch off building photon track cbIgnoreEventsWithNoEnergyDepo cbIgnoreEventsWithNoHits label_45 + labPhTracksOn_1 + labPartTracksOn diff --git a/src/modules/afileparticlegenerator.cpp b/src/modules/afileparticlegenerator.cpp index 5f6b34d6..f7f9882c 100644 --- a/src/modules/afileparticlegenerator.cpp +++ b/src/modules/afileparticlegenerator.cpp @@ -138,11 +138,6 @@ bool AFileParticleGenerator::GenerateEvent(QVector & Generated return false; //could not read particle record in file! } -void AFileParticleGenerator::RemoveParticle(int) -{ - qWarning() << "Remove particle has no effect for AFileParticleGenerator"; -} - bool AFileParticleGenerator::IsParticleInUse(int particleId, QString &SourceNames) const { return false; //TODO @@ -183,9 +178,8 @@ void AFileParticleGenerator::SetStartEvent(int startEvent) QStringList f = line.split(rx, QString::SkipEmptyParts); if (f.size() < 8) continue; bool bOK; - int pId = f.at(0).toInt(&bOK); + f.at(0).toInt(&bOK); if (!bOK) continue; //assuming this is a comment line - //TODO protection of wrong index, either test on start // synchronize! if (!bContinueEvent) event++; @@ -211,6 +205,38 @@ bool AFileParticleGenerator::IsValidated() const return (fi.exists() && FileLastModified == fi.lastModified() && RegisteredParticleCount == MpCollection.countParticles()); } +const QString AFileParticleGenerator::GetEventRecords(int fromEvent, int toEvent) const +{ + QString s; + if (Stream) + { + Stream->seek(0); + + int event = -1; + bool bContinueEvent = false; + while (!Stream->atEnd()) + { + const QString line = Stream->readLine(); + QStringList f = line.split(rx, QString::SkipEmptyParts); + if (f.size() < 8) continue; + bool bOK; + f.at(0).toInt(&bOK); + if (!bOK) continue; //assuming this is a comment line + + if (!bContinueEvent) event++; + + if (event >= fromEvent && event < toEvent) s += line; + + if (f.size() > 8 && f.at(8) == '*') + bContinueEvent = true; + else + bContinueEvent = false; + } + + } + return s; +} + void AFileParticleGenerator::clearFileStat() { FileLastModified = QDateTime(); //will force to inspect file on next use diff --git a/src/modules/afileparticlegenerator.h b/src/modules/afileparticlegenerator.h index f6ca4d37..a9a717e9 100644 --- a/src/modules/afileparticlegenerator.h +++ b/src/modules/afileparticlegenerator.h @@ -22,11 +22,11 @@ class AFileParticleGenerator : public AParticleGun void SetFileName(const QString &fileName); const QString GetFileName() const {return FileName;} - virtual bool Init() override; //called before first use - virtual void ReleaseResources() override; //called after end of operation + virtual bool Init() override; //has to be called before first use of GenerateEvent() + virtual void ReleaseResources() override; virtual bool GenerateEvent(QVector & GeneratedParticles) override; - virtual void RemoveParticle(int particleId) override; //cannot be used for this class + virtual void RemoveParticle(int) override {} //cannot be used for this class virtual bool IsParticleInUse(int particleId, QString& SourceNames) const override; virtual void writeToJson(QJsonObject& json) const override; @@ -34,9 +34,11 @@ class AFileParticleGenerator : public AParticleGun virtual void SetStartEvent(int startEvent) override; - void InvalidateFile(); //signals that the file has to be inspected again by running Init() + void InvalidateFile(); //forces the file to be inspected again during next call of Init() bool IsValidated() const; + const QString GetEventRecords(int fromEvent, int toEvent) const; + //public file inspect results int NumEventsInFile = 0; //saved int statNumMultipleEvents = 0; From 56aa11b613859314b19baad9876f8a823d4d1edf Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 3 Nov 2018 10:12:15 +0000 Subject: [PATCH 130/140] ++ --- src/gui/MainWindowTools/MainWindowParticleSimulation.cpp | 8 +++++++- src/gui/mainwindow.ui | 6 +++--- src/scriptmode/aparticlegeneratorinterface.cpp | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp index fd077625..ea8109a9 100644 --- a/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp +++ b/src/gui/MainWindowTools/MainWindowParticleSimulation.cpp @@ -816,7 +816,13 @@ void MainWindow::on_twParticleGenerationMode_currentChanged(int) void MainWindow::on_pbGenerateFromFile_Help_clicked() { - + QString s = "File should contain particle records, one line per particle.\n\n" + "Record format:\n" + "ParticleId Energy StartX StartY StartZ DirX DirY DirZ *\n\n" + "where optional '*' indicates that the event is not finished:\n" + "the next particle will be generated within the same event.\n\n" + "If a line does not start with an integer, it is ignored."; + message(s, this); } void MainWindow::on_pbGenerateFromFile_Change_clicked() diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 8511938e..c9c04bb8 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 0 + 1 @@ -6893,7 +6893,7 @@ Second click will trigger strong abort mode, which will result in loss of all si QTabWidget::Rounded - 0 + 1 false @@ -9687,7 +9687,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - 0 + 1 diff --git a/src/scriptmode/aparticlegeneratorinterface.cpp b/src/scriptmode/aparticlegeneratorinterface.cpp index c07a34ac..da2829fe 100644 --- a/src/scriptmode/aparticlegeneratorinterface.cpp +++ b/src/scriptmode/aparticlegeneratorinterface.cpp @@ -6,7 +6,11 @@ #include "TRandom2.h" AParticleGeneratorInterface::AParticleGeneratorInterface(const AMaterialParticleCollection & MpCollection, TRandom2 *RandGen) : - MpCollection(MpCollection), RandGen(RandGen) {} + MpCollection(MpCollection), RandGen(RandGen) +{ + H["AddParticle"] = "Adds particle to track to this event"; + H["AddParticleIsotropic"] = "Adds particle to track to this event. The particle's direction is randomly generated (isotropic)"; +} void AParticleGeneratorInterface::configure(QVector * GeneratedParticles) { From 147668f216f734e474d268b172294d9b84ce3385 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 3 Nov 2018 11:02:19 +0000 Subject: [PATCH 131/140] added LUX and RED100 examples, tweaked default and simplst configs --- src/EXAMPLES/ExamplesTree.txt | 7 +- src/EXAMPLES/LUX.json | 9726 +++++++++++++++++++++++++++++ src/EXAMPLES/RED100.json | 3880 ++++++++++++ src/EXAMPLES/Simplest.json | 104 +- src/EXAMPLES/StartupDetector.json | 214 +- src/gui/exampleswindow.ui | 36 +- src/gui/mainwindow.ui | 8 +- 7 files changed, 13875 insertions(+), 100 deletions(-) create mode 100644 src/EXAMPLES/LUX.json create mode 100644 src/EXAMPLES/RED100.json diff --git a/src/EXAMPLES/ExamplesTree.txt b/src/EXAMPLES/ExamplesTree.txt index a0acc1e8..2e412c38 100644 --- a/src/EXAMPLES/ExamplesTree.txt +++ b/src/EXAMPLES/ExamplesTree.txt @@ -1,6 +1,7 @@ define:Gamma cameras define:Neutrons define:Dark matter +define:Neutrinos define:ANTS2 tests define: Startup @@ -12,9 +13,10 @@ define:Gamma cameras:PMT-based define:Neutrons:Gas define:Neutrons:Converter -define:Dark matter:RED define:Dark matter:LUX +define:Neutrinos:RED + define:ANTS2 tests:Fresnel test define:ANTS2 tests:Scatter model define:ANTS2 tests:Optical grids @@ -43,5 +45,8 @@ add:Gamma cameras:PMT-based:Med37.json:Medical gamma camera GE MaxiCamera 400T; add:Neutrons:Gas:AngerGSPC19.json:GSPC19 detector add:Neutrons:Converter:B4C_multigap.json:Multigap RPC neutron detector +add:Dark matter:LUX:LUX.json:A model of LUX - a dual-phase detector for dark matter search +add:Neutrinos:RED:RED100.json:A model of RED100 - a dual-phase neutrino detector + add:Startup:Startup:StartupDetector.json:Detector loaded on start of ANTS2 add:Startup:Startup:Simplest.json:Nearly empty detector diff --git a/src/EXAMPLES/LUX.json b/src/EXAMPLES/LUX.json new file mode 100644 index 00000000..d0564405 --- /dev/null +++ b/src/EXAMPLES/LUX.json @@ -0,0 +1,9726 @@ +{ + "DetectorConfig": { + "DummyPMs": [ + ], + "Electronics": { + "ADC": { + "ADCbits": [ + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16 + ], + "ADCmax": [ + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535 + ], + "Active": false + }, + "DarkCounts": { + "Active": false, + "Data": [ + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + } + ] + }, + "MCcrosstalk": { + "Active": false, + "Model": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "ProbDistr": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "TrigProb": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + }, + "Noise": { + "Active": false, + "NoiseSigma": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "NoiseSigmaStat": [ + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ] + ] + }, + "PHS": { + "Active": false, + "Data": [ + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + } + ] + } + }, + "FixedWorldSizes": { + "WorldSizeFixed": false, + "XY": 757.1865167895415, + "Z": 757.1865167895415 + }, + "IndividualPMoverrides": { + "Angular": { + "AngularResponse": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "RefrIndex": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ] + }, + "Area": { + "AreaResponse": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "Step": [ + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ] + ] + }, + "PDEeffective": [ + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + ], + "PDEwave": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "RelQEandElStr": [ + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ] + ] + }, + "LoadExpDataConfig": { + "AddMulti": [ + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ] + ], + "IgnoreThresholds": { + "Activated": false, + "Max": 10000000000, + "Min": 1 + }, + "LoadFirst": -1, + "LoadedEnergy": { + "Activated": false, + "Add": 0, + "Channel": 0, + "Multi": 1 + }, + "LoadedPosition": { + "Activated": false, + "Channel": 0 + }, + "LoadedZPosition": { + "Activated": false, + "Channel": 0 + }, + "ManifestFile": "", + "Preprocessing": false + }, + "MaterialCollection": { + "LogLog": false, + "Materials": [ + { + "*MaterialName": "LiqiudXe", + "BulkAbsorption": 3.3e-05, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 1.2906182123022553e-306 + }, + "Comments": "", + "Density": 3, + "ElDriftVelo": 0, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + } + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Decay": [ + [ + 1, + 5 + ] + ], + "PrimScint_Model": 0, + "PrimScint_Raise": 0, + "RayleighMFP": 300, + "RayleighWave": 175, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1.69, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 0, + "SecScint_Tau": 0, + "W": 0 + }, + { + "*MaterialName": "GasXe", + "BulkAbsorption": 0, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 4.6273797e-316 + }, + "Comments": "", + "Density": 0.005, + "ElDriftVelo": 1, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + } + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Decay": [ + [ + 1, + 5 + ] + ], + "PrimScint_Model": 0, + "PrimScint_Raise": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 2, + "SecScint_Tau": 5, + "W": 25 + }, + { + "*MaterialName": "PTFE", + "BulkAbsorption": 3, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 4.450334455169617e-308 + }, + "Comments": "", + "Density": 2, + "ElDriftVelo": 0, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + } + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Decay": [ + [ + 1, + 5 + ] + ], + "PrimScint_Model": 0, + "PrimScint_Raise": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1.6, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 0, + "SecScint_Tau": 0, + "W": 0 + }, + { + "*MaterialName": "FusedSilica", + "BulkAbsorption": 0.1, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 5.020642041424e-311 + }, + "Comments": "", + "Density": 3, + "ElDriftVelo": 0, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + } + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Decay": [ + [ + 1, + 5 + ] + ], + "PrimScint_Model": 0, + "PrimScint_Raise": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1.6, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 0, + "SecScint_Tau": 0, + "W": 0 + }, + { + "*MaterialName": "StainlessSteel", + "BulkAbsorption": 10000, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 1.2906182123022553e-306 + }, + "Comments": "", + "Density": 8, + "ElDriftVelo": 0, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": false, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": false + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "EllasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "ReactionType": 2 + }, + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "ReactionType": 4 + } + ], + "TotalInteraction": [ + ], + "TrackingAllowed": false + } + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Decay": [ + [ + 1, + 5 + ] + ], + "PrimScint_Model": 0, + "PrimScint_Raise": 0, + "RayleighMFP": 0, + "RayleighWave": 175, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 0, + "SecScint_Tau": 0, + "W": 0 + } + ], + "Overrides": [ + { + "Abs": 0.03, + "MatFrom": 0, + "MatTo": 2, + "Model": "Simplistic_model", + "Scat": 0.97, + "ScatMode": 1, + "Spec": 0 + }, + { + "Abs": 0.8, + "MatFrom": 0, + "MatTo": 4, + "Model": "Simplistic_model", + "Scat": 0, + "ScatMode": 1, + "Spec": 0.2 + }, + { + "Abs": 0.2, + "MatFrom": 1, + "MatTo": 2, + "Model": "Simplistic_model", + "Scat": 0.8, + "ScatMode": 1, + "Spec": 0 + }, + { + "Abs": 0.8, + "MatFrom": 1, + "MatTo": 4, + "Model": "Simplistic_model", + "Scat": 0, + "ScatMode": 1, + "Spec": 0.2 + } + ] + }, + "PMarrays": [ + { + "PMarrayData": { + "Activated": true, + "PMtype": 0, + "PositioningScript": "var Pi = 3.1415926;\nvar d = 30.;\n\nvar basex = [-3., -4., -5., -6.,\n -2., -3., -4.,\n -1., -2.,\n 0.];\nvar basey = [3., 2., 1., 0., \t\n 2., 1., 0.,\n 1., 0.,\n 0.];\n\nPM(0., 0., 0, 0); \nfor (var i=0; i<6; i++) {\n // rotation matrix\n var R11 = Math.cos(i*Pi/3.);\n var R12 = -Math.sin(i*Pi/3.);\n var R21 = Math.sin(i*Pi/3.);\n var R22 = Math.cos(i*Pi/3.);\n\n for (var j=0; j<10; j++) { \n var x = basex[j] - 1.;\n var y = Math.sqrt(3.) * (basey[j] + 1.);\n\n var xx = R11*x + R12*y;\n var yy = R21*x + R22*y;\n PM(xx*d, yy*d, 0, 0);\n }\n}", + "PositionsTypes": [ + [ + 0, + 0, + 0, + 0 + ], + [ + 0, + -120, + 207.84609690826525, + 0 + ], + [ + 0, + -150, + 155.88457268119896, + 0 + ], + [ + 0, + -180, + 103.92304845413263, + 0 + ], + [ + 0, + -210, + 51.96152422706631, + 0 + ], + [ + 0, + -90, + 155.88457268119896, + 0 + ], + [ + 0, + -120, + 103.92304845413263, + 0 + ], + [ + 0, + -150, + 51.96152422706631, + 0 + ], + [ + 0, + -60, + 103.92304845413263, + 0 + ], + [ + 0, + -90, + 51.96152422706631, + 0 + ], + [ + 0, + -30, + 51.96152422706631, + 0 + ], + [ + 0, + -239.99999999999994, + 4.287183421602947e-06, + 0 + ], + [ + 0, + -210.00000092820238, + -51.96152047578082, + 0 + ], + [ + 0, + -180.00000185640485, + -103.92304523874505, + 0 + ], + [ + 0, + -150.0000027846073, + -155.8845700017093, + 0 + ], + [ + 0, + -179.99999999999997, + 3.2153875695328793e-06, + 0 + ], + [ + 0, + -150.0000009282024, + -51.96152154757667, + 0 + ], + [ + 0, + -120.00000185640485, + -103.92304631054091, + 0 + ], + [ + 0, + -119.99999999999997, + 2.1435917108014735e-06, + 0 + ], + [ + 0, + -90.00000092820243, + -51.96152261937252, + 0 + ], + [ + 0, + -59.999999999999986, + 1.0717958554007367e-06, + 0 + ], + [ + 0, + -120.00000742561949, + -207.8460926210817, + 0 + ], + [ + 0, + -60.00000742561949, + -207.84609476467347, + 0 + ], + [ + 0, + -7.425619545919915e-06, + -207.84609690826517, + 0 + ], + [ + 0, + 59.99999257438042, + -207.8460990518569, + 0 + ], + [ + 0, + -90.0000055692146, + -155.88456946581127, + 0 + ], + [ + 0, + -30.000005569214636, + -155.884571609403, + 0 + ], + [ + 0, + 29.999994430785332, + -155.88457375299473, + 0 + ], + [ + 0, + -60.00000371280974, + -103.92304631054085, + 0 + ], + [ + 0, + -3.7128097729599574e-06, + -103.92304845413258, + 0 + ], + [ + 0, + -30.00000185640487, + -51.96152315527043, + 0 + ], + [ + 0, + 119.99998886157059, + -207.8461033390401, + 0 + ], + [ + 0, + 149.99999164617785, + -155.88458071966764, + 0 + ], + [ + 0, + 179.9999944307851, + -103.92305810029518, + 0 + ], + [ + 0, + 209.9999972153924, + -51.96153548092271, + 0 + ], + [ + 0, + 89.99999164617793, + -155.8845775042801, + 0 + ], + [ + 0, + 119.99999443078521, + -103.92305488490761, + 0 + ], + [ + 0, + 149.99999721539245, + -51.961532265535155, + 0 + ], + [ + 0, + 59.99999443078529, + -103.92305166952005, + 0 + ], + [ + 0, + 89.99999721539255, + -51.96152905014759, + 0 + ], + [ + 0, + 29.999997215392646, + -51.961525834760025, + 0 + ], + [ + 0, + 239.99999999999937, + -1.7148733726379817e-05, + 0 + ], + [ + 0, + 210.00000371280922, + 51.961509221924175, + 0 + ], + [ + 0, + 180.00000742561906, + 103.92303559258207, + 0 + ], + [ + 0, + 150.0000111384289, + 155.88456196323995, + 0 + ], + [ + 0, + 179.99999999999952, + -1.286155030477687e-05, + 0 + ], + [ + 0, + 150.00000371280936, + 51.961513509107604, + 0 + ], + [ + 0, + 120.00000742561922, + 103.92303987976551, + 0 + ], + [ + 0, + 119.99999999999969, + -8.574366863189908e-06, + 0 + ], + [ + 0, + 90.00000371280953, + 51.961517796291034, + 0 + ], + [ + 0, + 59.999999999999844, + -4.287183431594954e-06, + 0 + ], + [ + 0, + 120.00001856404849, + 207.84608619030578, + 0 + ], + [ + 0, + 60.00001856404875, + 207.84609154928512, + 0 + ], + [ + 0, + 1.856404896471986e-05, + 207.84609690826443, + 0 + ], + [ + 0, + -59.9999814359508, + 207.84610226724377, + 0 + ], + [ + 0, + 90.00001392303638, + 155.88456464272934, + 0 + ], + [ + 0, + 30.000013923036605, + 155.88457000170868, + 0 + ], + [ + 0, + -29.99998607696315, + 155.884575360688, + 0 + ], + [ + 0, + 60.000009282024244, + 103.92304309515289, + 0 + ], + [ + 0, + 9.28202448235993e-06, + 103.92304845413221, + 0 + ], + [ + 0, + 30.000004641012122, + 51.961521547576446, + 0 + ] + ], + "Regularity": 1 + } + }, + { + "PMarrayData": { + "Activated": true, + "PMtype": 0, + "PositioningScript": "var Pi = 3.1415926;\nvar d = 30.;\n\nvar basex = [-3., -4., -5., -6.,\n -2., -3., -4.,\n -1., -2.,\n 0.];\nvar basey = [3., 2., 1., 0., \t\n 2., 1., 0.,\n 1., 0.,\n 0.];\n \nfor (var i=0; i<6; i++) {\n // rotation matrix\n var R11 = Math.cos(i*Pi/3.);\n var R12 = -Math.sin(i*Pi/3.);\n var R21 = Math.sin(i*Pi/3.);\n var R22 = Math.cos(i*Pi/3.);\n\n for (var j=0; j<10; j++) { \n var x = basex[j] - 1.;\n var y = Math.sqrt(3.) * (basey[j] + 1.);\n\n var xx = R11*x + R12*y;\n var yy = R21*x + R22*y;\n PM(xx*d, yy*d, 0, 0);\n }\n}\nPM(0., 0., 0, 0); ", + "PositionsTypes": [ + [ + 0, + -120, + 207.84609690826525, + 0 + ], + [ + 0, + -150, + 155.88457268119896, + 0 + ], + [ + 0, + -180, + 103.92304845413263, + 0 + ], + [ + 0, + -210, + 51.96152422706631, + 0 + ], + [ + 0, + -90, + 155.88457268119896, + 0 + ], + [ + 0, + -120, + 103.92304845413263, + 0 + ], + [ + 0, + -150, + 51.96152422706631, + 0 + ], + [ + 0, + -60, + 103.92304845413263, + 0 + ], + [ + 0, + -90, + 51.96152422706631, + 0 + ], + [ + 0, + -30, + 51.96152422706631, + 0 + ], + [ + 0, + -239.99999999999994, + 4.287183421602947e-06, + 0 + ], + [ + 0, + -210.00000092820238, + -51.96152047578082, + 0 + ], + [ + 0, + -180.00000185640485, + -103.92304523874505, + 0 + ], + [ + 0, + -150.0000027846073, + -155.8845700017093, + 0 + ], + [ + 0, + -179.99999999999997, + 3.2153875695328793e-06, + 0 + ], + [ + 0, + -150.0000009282024, + -51.96152154757667, + 0 + ], + [ + 0, + -120.00000185640485, + -103.92304631054091, + 0 + ], + [ + 0, + -119.99999999999997, + 2.1435917108014735e-06, + 0 + ], + [ + 0, + -90.00000092820243, + -51.96152261937252, + 0 + ], + [ + 0, + -59.999999999999986, + 1.0717958554007367e-06, + 0 + ], + [ + 0, + -120.00000742561949, + -207.8460926210817, + 0 + ], + [ + 0, + -60.00000742561949, + -207.84609476467347, + 0 + ], + [ + 0, + -7.425619545919915e-06, + -207.84609690826517, + 0 + ], + [ + 0, + 59.99999257438042, + -207.8460990518569, + 0 + ], + [ + 0, + -90.0000055692146, + -155.88456946581127, + 0 + ], + [ + 0, + -30.000005569214636, + -155.884571609403, + 0 + ], + [ + 0, + 29.999994430785332, + -155.88457375299473, + 0 + ], + [ + 0, + -60.00000371280974, + -103.92304631054085, + 0 + ], + [ + 0, + -3.7128097729599574e-06, + -103.92304845413258, + 0 + ], + [ + 0, + -30.00000185640487, + -51.96152315527043, + 0 + ], + [ + 0, + 119.99998886157059, + -207.8461033390401, + 0 + ], + [ + 0, + 149.99999164617785, + -155.88458071966764, + 0 + ], + [ + 0, + 179.9999944307851, + -103.92305810029518, + 0 + ], + [ + 0, + 209.9999972153924, + -51.96153548092271, + 0 + ], + [ + 0, + 89.99999164617793, + -155.8845775042801, + 0 + ], + [ + 0, + 119.99999443078521, + -103.92305488490761, + 0 + ], + [ + 0, + 149.99999721539245, + -51.961532265535155, + 0 + ], + [ + 0, + 59.99999443078529, + -103.92305166952005, + 0 + ], + [ + 0, + 89.99999721539255, + -51.96152905014759, + 0 + ], + [ + 0, + 29.999997215392646, + -51.961525834760025, + 0 + ], + [ + 0, + 239.99999999999937, + -1.7148733726379817e-05, + 0 + ], + [ + 0, + 210.00000371280922, + 51.961509221924175, + 0 + ], + [ + 0, + 180.00000742561906, + 103.92303559258207, + 0 + ], + [ + 0, + 150.0000111384289, + 155.88456196323995, + 0 + ], + [ + 0, + 179.99999999999952, + -1.286155030477687e-05, + 0 + ], + [ + 0, + 150.00000371280936, + 51.961513509107604, + 0 + ], + [ + 0, + 120.00000742561922, + 103.92303987976551, + 0 + ], + [ + 0, + 119.99999999999969, + -8.574366863189908e-06, + 0 + ], + [ + 0, + 90.00000371280953, + 51.961517796291034, + 0 + ], + [ + 0, + 59.999999999999844, + -4.287183431594954e-06, + 0 + ], + [ + 0, + 120.00001856404849, + 207.84608619030578, + 0 + ], + [ + 0, + 60.00001856404875, + 207.84609154928512, + 0 + ], + [ + 0, + 1.856404896471986e-05, + 207.84609690826443, + 0 + ], + [ + 0, + -59.9999814359508, + 207.84610226724377, + 0 + ], + [ + 0, + 90.00001392303638, + 155.88456464272934, + 0 + ], + [ + 0, + 30.000013923036605, + 155.88457000170868, + 0 + ], + [ + 0, + -29.99998607696315, + 155.884575360688, + 0 + ], + [ + 0, + 60.000009282024244, + 103.92304309515289, + 0 + ], + [ + 0, + 9.28202448235993e-06, + 103.92304845413221, + 0 + ], + [ + 0, + 30.000004641012122, + 51.961521547576446, + 0 + ], + [ + 0, + 0, + 0, + 0 + ] + ], + "Regularity": 1 + } + } + ], + "PMtypes": [ + { + "AngularResponse": { + "RefrIndexMeasure": 1, + "ResponseVsAngle": [ + ] + }, + "AreaResponse": { + "AreaStepX": 1, + "AreaStepY": 1, + "ResponseVsXY": [ + ] + }, + "General": { + "MaterialIndex": 3, + "Name": "Type0", + "Shape": 1, + "SiPM": false, + "SizeX": 57, + "SizeY": 25, + "SizeZ": 0.01 + }, + "PDEproperties": { + "PDE": 0.3, + "PDEwave": [ + ] + }, + "SiPMproperties": { + "DarkCountRate": 300000, + "PixelsX": 50, + "PixelsY": 50, + "RecoveryTime": 50 + } + }, + { + "AngularResponse": { + "RefrIndexMeasure": 1, + "ResponseVsAngle": [ + ] + }, + "AreaResponse": { + "AreaStepX": 1, + "AreaStepY": 1, + "ResponseVsXY": [ + ] + }, + "General": { + "MaterialIndex": 3, + "Name": "Type_1", + "Shape": 1, + "SiPM": false, + "SizeX": 1456, + "SizeY": 25, + "SizeZ": 0.01 + }, + "PDEproperties": { + "PDE": 0.3, + "PDEwave": [ + ] + }, + "SiPMproperties": { + "DarkCountRate": 300000, + "PixelsX": 50, + "PixelsY": 50, + "RecoveryTime": 50 + } + } + ], + "ParticleCollection": [ + { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + } + ], + "Sandwich": { + "DefaultXY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 473, + "size2": 60 + }, + "Slabs": [ + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 473, + "size2": 60 + }, + "color": 7, + "fActive": true, + "fCenter": false, + "height": 1, + "material": 2, + "name": "TopLightGuide", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 473, + "size2": 60 + }, + "color": 28, + "fActive": true, + "fCenter": false, + "height": 60, + "material": 1, + "name": "TopSpace", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 473, + "size2": 60 + }, + "color": 6, + "fActive": true, + "fCenter": false, + "height": 5, + "material": 1, + "name": "SecScint", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 473, + "size2": 60 + }, + "color": 2, + "fActive": true, + "fCenter": true, + "height": 492, + "material": 0, + "name": "PrScint", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 473, + "size2": 60 + }, + "color": 4, + "fActive": true, + "fCenter": false, + "height": 60, + "material": 0, + "name": "BottomSpace", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 473, + "size2": 60 + }, + "color": 29, + "fActive": true, + "fCenter": false, + "height": 1, + "material": 2, + "name": "BottomLightGuide", + "style": 1, + "width": 1 + } + ], + "State": "CommonShapeSize", + "WorldMaterial": 2, + "WorldTree": [ + { + "Container": "", + "Locked": false, + "Name": "World", + "ObjectType": { + "Type": "World" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "World", + "Locked": false, + "Name": "TopLightGuide", + "ObjectType": { + "Type": "Lightguide", + "UpperLower": "Upper" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "TopLightGuide", + "Locked": false, + "Material": 1, + "Name": "Guide_L2", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoCone", + "ShapeSpecific": { + "dz": 0.5, + "rmaxL": 22.5, + "rmaxU": 22.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 15, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "World", + "Locked": false, + "Name": "TopSpace", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "TopSpace", + "Locked": false, + "Material": 0, + "Name": "TopGrid", + "ObjectType": { + "Type": "Grid" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoPolygon", + "ShapeSpecific": { + "dphi": 360, + "dz": 0.026, + "nedges": 12, + "rmaxL": 236.5, + "rmaxU": 236.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 10, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "TopGrid", + "Locked": false, + "Material": 0, + "Name": "GridElement_TopGrid", + "ObjectType": { + "Type": "GridElement", + "dz": 0.026000000000000002, + "shape": 0, + "size1": 5, + "size2": 250 + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoBBox", + "ShapeSpecific": { + "dx": 5, + "dy": 250, + "dz": 0.026000000000000002 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_TopGrid", + "Locked": false, + "Material": 4, + "Name": "New_XR5", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": -90, + "phi2": 90, + "rmax": 0.025, + "rmin": 0 + }, + "Theta": 90, + "X": -5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_TopGrid", + "Locked": false, + "Material": 4, + "Name": "New_WT5", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": 90, + "phi2": 270, + "rmax": 0.025, + "rmin": 0 + }, + "Theta": 90, + "X": 5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "TopSpace", + "Locked": false, + "Material": 0, + "Name": "AnodeMesh", + "ObjectType": { + "Type": "Grid" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoPolygon", + "ShapeSpecific": { + "dphi": 360, + "dz": 0.016, + "nedges": 12, + "rmaxL": 236.5, + "rmaxU": 236.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": -29, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "AnodeMesh", + "Locked": false, + "Material": 0, + "Name": "GridElement_AnodeMesh", + "ObjectType": { + "Type": "GridElement", + "dz": 0.016, + "shape": 1, + "size1": 0.25, + "size2": 0.25 + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoBBox", + "ShapeSpecific": { + "dx": 0.25, + "dy": 0.25, + "dz": 0.016 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_AnodeMesh", + "Locked": false, + "Material": 4, + "Name": "Composite_MP7", + "ObjectType": { + "Type": "Composite" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoCompositeShape", + "ShapeSpecific": { + "GenerationString": "TGeoCompositeShape( New_LZ1 + New_IH8 + New_RV3 + New_JG5 )" + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "Composite_MP7", + "Locked": false, + "Name": "CompositeSet_Composite_MP7", + "ObjectType": { + "Type": "CompositeContainer" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "CompositeSet_Composite_MP7", + "Locked": false, + "Material": 0, + "Name": "New_LZ1", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 0.25, + "phi1": -90, + "phi2": 90, + "rmax": 0.015, + "rmin": 0 + }, + "Theta": 90, + "X": -0.25, + "Y": 0, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_MP7", + "Locked": false, + "Material": 0, + "Name": "New_IH8", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 0.25, + "phi1": 90, + "phi2": 270, + "rmax": 0.015, + "rmin": 0 + }, + "Theta": 90, + "X": 0.25, + "Y": 0, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_MP7", + "Locked": false, + "Material": 0, + "Name": "New_RV3", + "ObjectType": { + "Type": "Single" + }, + "Phi": 90, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 0.25, + "phi1": 90, + "phi2": 270, + "rmax": 0.015, + "rmin": 0 + }, + "Theta": 90, + "X": 0, + "Y": 0.25, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_MP7", + "Locked": false, + "Material": 0, + "Name": "New_JG5", + "ObjectType": { + "Type": "Single" + }, + "Phi": 90, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 0.25, + "phi1": -90, + "phi2": 90, + "rmax": 0.015, + "rmin": 0 + }, + "Theta": 90, + "X": 0, + "Y": -0.25, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "World", + "Locked": false, + "Name": "SecScint", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "World", + "Locked": false, + "Name": "PrScint", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "PrScint", + "Locked": false, + "Material": 0, + "Name": "GateGrid", + "ObjectType": { + "Type": "Grid" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoPolygon", + "ShapeSpecific": { + "dphi": 360, + "dz": 0.026, + "nedges": 12, + "rmaxL": 236.5, + "rmaxU": 236.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 241, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GateGrid", + "Locked": false, + "Material": 0, + "Name": "GridElement_GateGrid", + "ObjectType": { + "Type": "GridElement", + "dz": 0.026000000000000002, + "shape": 0, + "size1": 2.5, + "size2": 250 + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoBBox", + "ShapeSpecific": { + "dx": 2.5, + "dy": 250, + "dz": 0.026000000000000002 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_GateGrid", + "Locked": false, + "Material": 4, + "Name": "New_JA4", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": -90, + "phi2": 90, + "rmax": 0.025, + "rmin": 0 + }, + "Theta": 90, + "X": -2.5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_GateGrid", + "Locked": false, + "Material": 4, + "Name": "New_JG9", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": 90, + "phi2": 270, + "rmax": 0.025, + "rmin": 0 + }, + "Theta": 90, + "X": 2.5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "World", + "Locked": false, + "Name": "BottomSpace", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "BottomSpace", + "Locked": false, + "Material": 0, + "Name": "CathodeGrid", + "ObjectType": { + "Type": "Grid" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoPolygon", + "ShapeSpecific": { + "dphi": 360, + "dz": 0.101, + "nedges": 12, + "rmaxL": 236.5, + "rmaxU": 236.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 29.9, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CathodeGrid", + "Locked": false, + "Material": 0, + "Name": "GridElement_CathodeGrid", + "ObjectType": { + "Type": "GridElement", + "dz": 0.101, + "shape": 0, + "size1": 2.5, + "size2": 250 + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoBBox", + "ShapeSpecific": { + "dx": 2.5, + "dy": 250, + "dz": 0.101 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_CathodeGrid", + "Locked": false, + "Material": 4, + "Name": "New_KW5", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": -90, + "phi2": 90, + "rmax": 0.1, + "rmin": 0 + }, + "Theta": 90, + "X": -2.5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_CathodeGrid", + "Locked": false, + "Material": 4, + "Name": "New_YA2", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": 90, + "phi2": 270, + "rmax": 0.1, + "rmin": 0 + }, + "Theta": 90, + "X": 2.5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "BottomSpace", + "Locked": false, + "Material": 0, + "Name": "BottomGrid", + "ObjectType": { + "Type": "Grid" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoPolygon", + "ShapeSpecific": { + "dphi": 360, + "dz": 0.101, + "nedges": 12, + "rmaxL": 236.5, + "rmaxU": 236.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": -10, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "BottomGrid", + "Locked": false, + "Material": 0, + "Name": "GridElement_BottomGrid", + "ObjectType": { + "Type": "GridElement", + "dz": 0.101, + "shape": 0, + "size1": 5, + "size2": 250 + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoBBox", + "ShapeSpecific": { + "dx": 5, + "dy": 250, + "dz": 0.101 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_BottomGrid", + "Locked": false, + "Material": 4, + "Name": "New_IN3", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": -90, + "phi2": 90, + "rmax": 0.1, + "rmin": 0 + }, + "Theta": 90, + "X": -5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_BottomGrid", + "Locked": false, + "Material": 4, + "Name": "New_HJ9", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTubeSeg", + "ShapeSpecific": { + "dz": 250, + "phi1": 90, + "phi2": 270, + "rmax": 0.1, + "rmin": 0 + }, + "Theta": 90, + "X": 5, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "World", + "Locked": false, + "Name": "BottomLightGuide", + "ObjectType": { + "Type": "Lightguide", + "UpperLower": "Lower" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "BottomLightGuide", + "Locked": false, + "Material": 0, + "Name": "Guide_N8", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoCone", + "ShapeSpecific": { + "dz": 0.5, + "rmaxL": 22.5, + "rmaxU": 22.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 15, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + } + ], + "ZeroZ": "Center" + } + }, + "GUI": { + "GeometryWindow": { + "ZoomLevel": 2 + }, + "MW": { + "ConfigGuiLocked": false + }, + "PartcleStackChecker": { + "Copies": 1, + "Energy": 200, + "Particle": 0, + "ScriptEV": "", + "Time": 0, + "X": 0, + "Y": 0, + "Z": 0, + "dX": 1, + "dY": 0, + "dZ": 0 + }, + "ReconstructionWindow": { + "Blur": { + "BlurSigma": 1, + "BlurSigmaZ": 1, + "BlurType": 0, + "BlurWidth": 1, + "BlurWidthZ": 1 + }, + "ChPerPhePeaks": { + "Bins": 300, + "From": -50, + "MaxPeaks": 30, + "Sigma": 8, + "Threshold": 0.02, + "To": 250 + }, + "ChPerPheStat": { + "Bins": 100, + "ENF": 1, + "Lower": 3, + "MaxRange": 1000, + "MinRange": 0, + "Upper": 500 + }, + "PlotXYsettings": { + "PlotXYbinsX": 50, + "PlotXYbinsY": 50, + "PlotXYfromX": -180, + "PlotXYfromY": -180, + "PlotXYfromZ": -5, + "PlotXYoptionZ": 0, + "PlotXYtoX": 180, + "PlotXYtoY": 180, + "PlotXYtoZ": 5 + } + } + }, + "ReconstructionConfig": { + "FilterOptions": [ + { + "Chi2": { + "Active": false, + "Max": 10000000000, + "Min": 0 + }, + "Correlation": { + "Active": false, + "Set": [ + { + "Active": true, + "AutoSize": true, + "BinX": 100, + "BinY": 100, + "Cut": { + "CutOption": 0, + "Data": [ + 0, + 1, + 300 + ], + "Type": "line" + }, + "XY": [ + { + "Array": [ + 0 + ], + "Type": "SingleChannel" + }, + { + "Array": [ + 0 + ], + "Type": "SingleChannel" + } + ], + "maxX": 20, + "maxY": 20, + "minX": -20, + "minY": -20 + } + ] + }, + "EventNumber": { + "Active": false, + "Max": 0, + "Min": 0 + }, + "IndividualPMSignal": { + "Active": false, + "UsePassives": true + }, + "LoadedEnergy": { + "Active": false, + "Max": 10000000000, + "Min": 0 + }, + "MultipleScanEvents": false, + "ReconstructedEnergy": { + "Active": false, + "Max": 10000000000, + "Min": 0 + }, + "SpatialCustom": { + "Active": false, + "AllZ": true, + "Angle": 0, + "CutOutsideInside": 0, + "Diameter": 30, + "Polygon": [ + ], + "RecOrScan": 0, + "Shape": 0, + "Side": 15, + "SizeX": 30, + "SizeY": 30, + "X0": 0, + "Y0": 0, + "Zfrom": -5, + "Zto": 5 + }, + "SpatialToObject": { + "Active": false, + "LimitObject": "PrScint", + "RecOrScan": 0 + }, + "SumSignal": { + "Active": false, + "Max": 10000000000, + "Min": 0, + "UseGains": false, + "UsePassives": true + }, + "kNN": { + "Active": false, + "AverageOver": 10, + "Max": 10000000000, + "Min": 0 + } + } + ], + "LRFmakeJson": { + "AdjustGains": true, + "Compression_k": 5, + "Compression_lam": 50, + "Compression_r0": 150, + "DataSelector": 0, + "EnergyNormalization": 1, + "FitOnlyLast": false, + "ForceInZ": 0, + "ForceNonIncreasingInR": false, + "ForceNonNegative": false, + "ForceZeroDeriv": true, + "GroupToMake": 0, + "GroupingOption": "Individual", + "GrouppingType": 0, + "LRF_3D": false, + "LRF_compress": true, + "LRF_type": 0, + "LimitGroup": false, + "Nodes_x": 10, + "Nodes_y": 10, + "StoreError": false, + "UseEnergy": true, + "UseGrid": true, + "UseGroupping": false + }, + "LRFmoduleSelected": 0, + "LRFv3makeJson": { + }, + "ReconstructionOptions": [ + { + "AlgorithmOptions": { + "Algorithm": 0, + "CGonCUDAsettings": { + "Buffer": 500, + "Iterations": 3, + "OptimizeMLChi2": 0, + "ScaleReduction": 8, + "StartOption": 0, + "StartStep": 10, + "StartX": 0, + "StartY": 0, + "StarterZ": 0, + "ThreadBlockXY": 8 + }, + "CPUgridsOptions": { + "InitialStep": 10, + "Iterations": 3, + "NodesXY": 8, + "OptimizeWhat": 0, + "Reduction": 8, + "StartOption": 0, + "StartX": 0, + "StartY": 0 + }, + "CoGoptions": { + "DoStretch": false, + "ForceFixedZ": true, + "IgnoreBySignal": true, + "IgnoreDistance": 100, + "IgnoreFar": false, + "IgnoreThresholdHigh": 10000000000, + "IgnoreThresholdLow": 5, + "StretchX": 1, + "StretchY": 1, + "StretchZ": 1 + }, + "RootMinimizerOptions": { + "LSorLikelihood": 0, + "LSsuppressConsole": true, + "MaxCalls": 500, + "Minuit2Option": 0, + "StartOption": 0, + "StartStepEnergy": 0.1, + "StartStepX": 1, + "StartStepY": 1, + "StartStepZ": 1 + } + }, + "DynamicPassives": { + "DistanceLimit": 120, + "IgnoreByDistance": true, + "IgnoreBySignal": false, + "SignalLimitHigh": 10000000000, + "SignalLimitLow": -10000000000 + }, + "General": { + "IncludePassives": false, + "InitialEnergy": 1, + "InitialZ": 0, + "LimitSearchGauss": false, + "LimitSearchIfTrueIsSet": false, + "RangeForLimitSearchIfTrueSet": 1, + "ReconstructEnergy": true, + "ReconstructZ": false, + "WeightedChi2": true, + "Zstrategy": 0 + }, + "MultipleEvents": { + "Option": 0 + } + } + ], + "SensorGroups": [ + { + "CutOffs": [ + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ] + ], + "Gains": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ], + "Name": "DefaultGroup", + "PmIndexes": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39, + 40, + 41, + 42, + 43, + 44, + 45, + 46, + 47, + 48, + 49, + 50, + 51, + 52, + 53, + 54, + 55, + 56, + 57, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 95, + 96, + 97, + 98, + 99, + 100, + 101, + 102, + 103, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 120, + 121 + ] + } + ], + "StaticPassives": [ + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ] + }, + "SimulationConfig": { + "DoGuiUpdate": true, + "GeneralSimConfig": { + "AcceleratorConfig": { + "CheckBeforeTrack": true, + "LogsStatistics": false, + "MaxNumTransitions": 25, + "OnlyTracksOnPMs": false + }, + "AngleConfig": { + "AngResolved": false, + "NumBins": 1000 + }, + "AreaConfig": { + "AreaResolved": false + }, + "BuildPhotonTracks": false, + "DetStatNumBins": 300, + "LrfBasedSim": { + "NumPhotElLRFunity": 1, + "NumPhotsLRFunity": 20000, + "UseLRFs": false + }, + "MaxNumberOfTracks": 1000, + "SecScintConfig": { + "Type": 0 + }, + "TimeConfig": { + "TimeBins": 5, + "TimeFrom": 0, + "TimeResolved": false, + "TimeTo": 1000 + }, + "TrackingConfig": { + "MaxStep": 0.1, + "MinEnergy": 0.01, + "MinEnergyNeutrons": 0.01, + "MinStep": 5e-05, + "Safety": 1e-10, + "TrackColorAdd": 0, + "dE": 0.05 + }, + "WaveConfig": { + "WaveFrom": 200, + "WaveNodes": 121, + "WaveResolved": false, + "WaveStep": 5, + "WaveTo": 800 + } + }, + "Mode": "PointSim", + "ParticleSourcesConfig": { + "ParticleSources": [ + { + "Activity": 1, + "CollPhi": 0, + "CollTheta": 0, + "DoMaterialLimited": false, + "GunParticles": [ + { + "Energy": 122, + "Individual": true, + "LinkedTo": 0, + "LinkingOppositeDir": false, + "LinkingProbability": 0, + "Particle": { + "charge": 0, + "mass": 0, + "name": "gamma", + "type": 0 + }, + "StatWeight": 0.856 + }, + { + "Energy": 136, + "Individual": true, + "LinkedTo": 0, + "LinkingOppositeDir": false, + "LinkingProbability": 0, + "Particle": { + "charge": 0, + "mass": 0, + "name": "gamma", + "type": 0 + }, + "StatWeight": 0.1068 + } + ], + "LimitedToMaterial": "", + "Name": "Co_57", + "Particles": 2, + "Phi": 0, + "Psi": 0, + "Size1": 150, + "Size2": 50, + "Size3": 10, + "Spread": 5, + "Theta": 0, + "Type": 3, + "X": 0, + "Y": 0, + "Z": -25 + } + ], + "SourceControlOptions": { + "AllowMultipleParticles": false, + "AverageParticlesPerEvent": 0.1, + "DoS1": true, + "DoS2": false, + "EventsToDo": 10, + "IgnoreNoDepoEvents": true, + "IgnoreNoHitsEvents": false, + "ParticleTracks": true, + "TypeParticlesPerEvent": 0 + } + }, + "PointSourcesConfig": { + "BadEventOptions": { + "BadEvents": false, + "NoiseArray": [ + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in one PM", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in one PM\n(over a normal event)", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in all PMs", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in all PMs\n(over a normal event)", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 0, + "Description": "Double event\n(two independent)", + "Probability": 0.01, + "Spread": 0 + }, + { + "Active": false, + "AverageValue": 0.5, + "Description": "Double event\n(# of photons is shared)", + "Probability": 0.01, + "Spread": 0.25 + } + ], + "Probability": 0, + "SigmaDouble": 10 + }, + "ControlOptions": { + "LimitNodes": true, + "LimitNodesTo": "PrScint", + "MultipleRuns": false, + "MultipleRunsNumber": 100, + "Primary_Secondary": 1, + "Single_Scan_Flood": 2 + }, + "CustomNodesOptions": { + "Nodes": [ + [ + 0, + 0, + 0 + ], + [ + 8.960000038146973, + 0, + 0 + ], + [ + 8.960000038146973, + 8.960000038146973, + 0 + ], + [ + 17.920000076293945, + 0, + 0 + ], + [ + 17.920000076293945, + 8.960000038146973, + 0 + ], + [ + 17.920000076293945, + 17.920000076293945, + 0 + ], + [ + 17.920000076293945, + 26.8799991607666, + 0 + ], + [ + 26.8799991607666, + 0, + 0 + ], + [ + 26.8799991607666, + 8.960000038146973, + 0 + ], + [ + 26.8799991607666, + 17.920000076293945, + 0 + ], + [ + 26.8799991607666, + 26.8799991607666, + 0 + ], + [ + 26.8799991607666, + 35.84000015258789, + 0 + ], + [ + 26.8799991607666, + 44.79999923706055, + 0 + ], + [ + 35.84000015258789, + 0, + 0 + ], + [ + 35.84000015258789, + 8.960000038146973, + 0 + ], + [ + 35.84000015258789, + 17.920000076293945, + 0 + ], + [ + 35.84000015258789, + 26.8799991607666, + 0 + ], + [ + 35.84000015258789, + 35.84000015258789, + 0 + ], + [ + 35.84000015258789, + 44.79999923706055, + 0 + ], + [ + 35.84000015258789, + 53.7599983215332, + 0 + ], + [ + 44.79999923706055, + 0, + 0 + ], + [ + 44.79999923706055, + 8.960000038146973, + 0 + ], + [ + 44.79999923706055, + 17.920000076293945, + 0 + ], + [ + 44.79999923706055, + 26.8799991607666, + 0 + ], + [ + 44.79999923706055, + 35.84000015258789, + 0 + ], + [ + 44.79999923706055, + 44.79999923706055, + 0 + ], + [ + 44.79999923706055, + 53.7599983215332, + 0 + ], + [ + 44.79999923706055, + 62.720001220703125, + 0 + ], + [ + 44.79999923706055, + 71.68000030517578, + 0 + ], + [ + 53.7599983215332, + 0, + 0 + ], + [ + 53.7599983215332, + 8.960000038146973, + 0 + ], + [ + 53.7599983215332, + 17.920000076293945, + 0 + ], + [ + 53.7599983215332, + 26.8799991607666, + 0 + ], + [ + 53.7599983215332, + 35.84000015258789, + 0 + ], + [ + 53.7599983215332, + 44.79999923706055, + 0 + ], + [ + 53.7599983215332, + 53.7599983215332, + 0 + ], + [ + 53.7599983215332, + 62.720001220703125, + 0 + ], + [ + 53.7599983215332, + 71.68000030517578, + 0 + ], + [ + 53.7599983215332, + 80.63999938964844, + 0 + ], + [ + 53.7599983215332, + 89.5999984741211, + 0 + ], + [ + 62.720001220703125, + 0, + 0 + ], + [ + 62.720001220703125, + 8.960000038146973, + 0 + ], + [ + 62.720001220703125, + 17.920000076293945, + 0 + ], + [ + 62.720001220703125, + 26.8799991607666, + 0 + ], + [ + 62.720001220703125, + 35.84000015258789, + 0 + ], + [ + 62.720001220703125, + 44.79999923706055, + 0 + ], + [ + 62.720001220703125, + 53.7599983215332, + 0 + ], + [ + 62.720001220703125, + 62.720001220703125, + 0 + ], + [ + 62.720001220703125, + 71.68000030517578, + 0 + ], + [ + 62.720001220703125, + 80.63999938964844, + 0 + ], + [ + 62.720001220703125, + 89.5999984741211, + 0 + ], + [ + 62.720001220703125, + 98.55999755859375, + 0 + ], + [ + 62.720001220703125, + 107.5199966430664, + 0 + ], + [ + 71.68000030517578, + 0, + 0 + ], + [ + 71.68000030517578, + 8.960000038146973, + 0 + ], + [ + 71.68000030517578, + 17.920000076293945, + 0 + ], + [ + 71.68000030517578, + 26.8799991607666, + 0 + ], + [ + 71.68000030517578, + 35.84000015258789, + 0 + ], + [ + 71.68000030517578, + 44.79999923706055, + 0 + ], + [ + 71.68000030517578, + 53.7599983215332, + 0 + ], + [ + 71.68000030517578, + 62.720001220703125, + 0 + ], + [ + 71.68000030517578, + 71.68000030517578, + 0 + ], + [ + 71.68000030517578, + 80.63999938964844, + 0 + ], + [ + 71.68000030517578, + 89.5999984741211, + 0 + ], + [ + 71.68000030517578, + 98.55999755859375, + 0 + ], + [ + 71.68000030517578, + 107.5199966430664, + 0 + ], + [ + 71.68000030517578, + 116.4800033569336, + 0 + ], + [ + 80.63999938964844, + 0, + 0 + ], + [ + 80.63999938964844, + 8.960000038146973, + 0 + ], + [ + 80.63999938964844, + 17.920000076293945, + 0 + ], + [ + 80.63999938964844, + 26.8799991607666, + 0 + ], + [ + 80.63999938964844, + 35.84000015258789, + 0 + ], + [ + 80.63999938964844, + 44.79999923706055, + 0 + ], + [ + 80.63999938964844, + 53.7599983215332, + 0 + ], + [ + 80.63999938964844, + 62.720001220703125, + 0 + ], + [ + 80.63999938964844, + 71.68000030517578, + 0 + ], + [ + 80.63999938964844, + 80.63999938964844, + 0 + ], + [ + 80.63999938964844, + 89.5999984741211, + 0 + ], + [ + 80.63999938964844, + 98.55999755859375, + 0 + ], + [ + 80.63999938964844, + 107.5199966430664, + 0 + ], + [ + 80.63999938964844, + 116.4800033569336, + 0 + ], + [ + 80.63999938964844, + 125.44000244140625, + 0 + ], + [ + 80.63999938964844, + 134.39999389648438, + 0 + ], + [ + 89.5999984741211, + 0, + 0 + ], + [ + 89.5999984741211, + 8.960000038146973, + 0 + ], + [ + 89.5999984741211, + 17.920000076293945, + 0 + ], + [ + 89.5999984741211, + 26.8799991607666, + 0 + ], + [ + 89.5999984741211, + 35.84000015258789, + 0 + ], + [ + 89.5999984741211, + 44.79999923706055, + 0 + ], + [ + 89.5999984741211, + 53.7599983215332, + 0 + ], + [ + 89.5999984741211, + 62.720001220703125, + 0 + ], + [ + 89.5999984741211, + 71.68000030517578, + 0 + ], + [ + 89.5999984741211, + 80.63999938964844, + 0 + ], + [ + 89.5999984741211, + 89.5999984741211, + 0 + ], + [ + 89.5999984741211, + 98.55999755859375, + 0 + ], + [ + 89.5999984741211, + 107.5199966430664, + 0 + ], + [ + 89.5999984741211, + 116.4800033569336, + 0 + ], + [ + 89.5999984741211, + 125.44000244140625, + 0 + ], + [ + 89.5999984741211, + 134.39999389648438, + 0 + ], + [ + 98.55999755859375, + 0, + 0 + ], + [ + 98.55999755859375, + 8.960000038146973, + 0 + ], + [ + 98.55999755859375, + 17.920000076293945, + 0 + ], + [ + 98.55999755859375, + 26.8799991607666, + 0 + ], + [ + 98.55999755859375, + 35.84000015258789, + 0 + ], + [ + 98.55999755859375, + 44.79999923706055, + 0 + ], + [ + 98.55999755859375, + 53.7599983215332, + 0 + ], + [ + 98.55999755859375, + 62.720001220703125, + 0 + ], + [ + 98.55999755859375, + 71.68000030517578, + 0 + ], + [ + 98.55999755859375, + 80.63999938964844, + 0 + ], + [ + 98.55999755859375, + 89.5999984741211, + 0 + ], + [ + 98.55999755859375, + 98.55999755859375, + 0 + ], + [ + 98.55999755859375, + 107.5199966430664, + 0 + ], + [ + 98.55999755859375, + 116.4800033569336, + 0 + ], + [ + 98.55999755859375, + 125.44000244140625, + 0 + ], + [ + 107.5199966430664, + 0, + 0 + ], + [ + 107.5199966430664, + 8.960000038146973, + 0 + ], + [ + 107.5199966430664, + 17.920000076293945, + 0 + ], + [ + 107.5199966430664, + 26.8799991607666, + 0 + ], + [ + 107.5199966430664, + 35.84000015258789, + 0 + ], + [ + 107.5199966430664, + 44.79999923706055, + 0 + ], + [ + 107.5199966430664, + 53.7599983215332, + 0 + ], + [ + 107.5199966430664, + 62.720001220703125, + 0 + ], + [ + 107.5199966430664, + 71.68000030517578, + 0 + ], + [ + 107.5199966430664, + 80.63999938964844, + 0 + ], + [ + 107.5199966430664, + 89.5999984741211, + 0 + ], + [ + 107.5199966430664, + 98.55999755859375, + 0 + ], + [ + 107.5199966430664, + 107.5199966430664, + 0 + ], + [ + 107.5199966430664, + 116.4800033569336, + 0 + ], + [ + 116.4800033569336, + 0, + 0 + ], + [ + 116.4800033569336, + 8.960000038146973, + 0 + ], + [ + 116.4800033569336, + 17.920000076293945, + 0 + ], + [ + 116.4800033569336, + 26.8799991607666, + 0 + ], + [ + 116.4800033569336, + 35.84000015258789, + 0 + ], + [ + 116.4800033569336, + 44.79999923706055, + 0 + ], + [ + 116.4800033569336, + 53.7599983215332, + 0 + ], + [ + 116.4800033569336, + 62.720001220703125, + 0 + ], + [ + 116.4800033569336, + 71.68000030517578, + 0 + ], + [ + 116.4800033569336, + 80.63999938964844, + 0 + ], + [ + 116.4800033569336, + 89.5999984741211, + 0 + ], + [ + 116.4800033569336, + 98.55999755859375, + 0 + ], + [ + 116.4800033569336, + 107.5199966430664, + 0 + ], + [ + 116.4800033569336, + 116.4800033569336, + 0 + ], + [ + 125.44000244140625, + 0, + 0 + ], + [ + 125.44000244140625, + 8.960000038146973, + 0 + ], + [ + 125.44000244140625, + 17.920000076293945, + 0 + ], + [ + 125.44000244140625, + 26.8799991607666, + 0 + ], + [ + 125.44000244140625, + 35.84000015258789, + 0 + ], + [ + 125.44000244140625, + 44.79999923706055, + 0 + ], + [ + 125.44000244140625, + 53.7599983215332, + 0 + ], + [ + 125.44000244140625, + 62.720001220703125, + 0 + ], + [ + 125.44000244140625, + 71.68000030517578, + 0 + ], + [ + 125.44000244140625, + 80.63999938964844, + 0 + ], + [ + 125.44000244140625, + 89.5999984741211, + 0 + ], + [ + 125.44000244140625, + 98.55999755859375, + 0 + ], + [ + 134.39999389648438, + 0, + 0 + ], + [ + 134.39999389648438, + 8.960000038146973, + 0 + ], + [ + 134.39999389648438, + 17.920000076293945, + 0 + ], + [ + 134.39999389648438, + 26.8799991607666, + 0 + ], + [ + 134.39999389648438, + 35.84000015258789, + 0 + ], + [ + 134.39999389648438, + 44.79999923706055, + 0 + ], + [ + 134.39999389648438, + 53.7599983215332, + 0 + ], + [ + 134.39999389648438, + 62.720001220703125, + 0 + ], + [ + 134.39999389648438, + 71.68000030517578, + 0 + ], + [ + 134.39999389648438, + 80.63999938964844, + 0 + ], + [ + 134.39999389648438, + 89.5999984741211, + 0 + ], + [ + 143.36000061035156, + 0, + 0 + ], + [ + 143.36000061035156, + 8.960000038146973, + 0 + ], + [ + 143.36000061035156, + 17.920000076293945, + 0 + ], + [ + 143.36000061035156, + 26.8799991607666, + 0 + ], + [ + 143.36000061035156, + 35.84000015258789, + 0 + ], + [ + 143.36000061035156, + 44.79999923706055, + 0 + ], + [ + 143.36000061035156, + 53.7599983215332, + 0 + ], + [ + 143.36000061035156, + 62.720001220703125, + 0 + ], + [ + 143.36000061035156, + 71.68000030517578, + 0 + ], + [ + 143.36000061035156, + 80.63999938964844, + 0 + ], + [ + 152.32000732421875, + 0, + 0 + ], + [ + 152.32000732421875, + 8.960000038146973, + 0 + ], + [ + 152.32000732421875, + 17.920000076293945, + 0 + ], + [ + 152.32000732421875, + 26.8799991607666, + 0 + ], + [ + 152.32000732421875, + 35.84000015258789, + 0 + ], + [ + 152.32000732421875, + 44.79999923706055, + 0 + ], + [ + 152.32000732421875, + 53.7599983215332, + 0 + ], + [ + 152.32000732421875, + 62.720001220703125, + 0 + ], + [ + 161.27999877929688, + 0, + 0 + ], + [ + 161.27999877929688, + 8.960000038146973, + 0 + ], + [ + 161.27999877929688, + 17.920000076293945, + 0 + ], + [ + 161.27999877929688, + 26.8799991607666, + 0 + ] + ], + "Script": "node(0, 0, 0)\nfor (var i=1; i<19; i++)\n for (var j=0; j<17; j++)\n { \n var x = i * 17.92 * 0.5\n var y = j * 17.92 * 0.5\n var angle = Math.atan(y/x)\n if (angle>1.0472) continue \n if ( x*x + y*y > 165*165) continue\n node(x, y, 0)\n }\n" + }, + "FloodOptions": { + "CenterX": 0, + "CenterY": 0, + "DiameterIn": 0, + "DiameterOut": 473, + "Nodes": 5000, + "Shape": 1, + "Xfrom": -15, + "Xto": 15, + "Yfrom": -15, + "Yto": 15, + "Zfixed": 0, + "Zfrom": -2.49, + "Zoption": 0, + "Zto": 2.49 + }, + "PhotPerNodeOptions": { + "PhotPerNodeConstant": 100, + "PhotPerNodeCustom": [ + ], + "PhotPerNodeGaussMean": 10, + "PhotPerNodeGaussSigma": 2.5, + "PhotPerNodeMode": 0, + "PhotPerNodeUniMax": 12, + "PhotPerNodeUniMin": 10 + }, + "PhotonDirectionOptions": { + "Cone": 45, + "FixedX": 0, + "FixedY": 0, + "FixedZ": 1, + "Fixed_or_Cone": 0, + "Random": true + }, + "RegularScanOptions": { + "AxesData": [ + { + "Nodes": 21, + "Option": 1, + "dX": 10, + "dY": 0, + "dZ": 0 + }, + { + "Nodes": 11, + "Option": 1, + "dX": 10, + "dY": 17.321, + "dZ": 0 + } + ], + "ScanX0": 0, + "ScanY0": 0, + "ScanZ0": 0 + }, + "SinglePositionOptions": { + "SingleX": 0, + "SingleY": 0, + "SingleZ": 0 + }, + "WaveTimeOptions": { + "UseFixedWavelength": false, + "WaveIndex": 0 + } + } + } +} diff --git a/src/EXAMPLES/RED100.json b/src/EXAMPLES/RED100.json new file mode 100644 index 00000000..3997d733 --- /dev/null +++ b/src/EXAMPLES/RED100.json @@ -0,0 +1,3880 @@ +{ + "DetectorConfig": { + "DummyPMs": [ + ], + "Electronics": { + "ADC": { + "ADCbits": [ + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16, + 16 + ], + "ADCmax": [ + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535, + 65535 + ], + "Active": false + }, + "DarkCounts": { + "Active": false, + "Data": [ + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + }, + { + "DarkCounts_distribution": [ + ], + "DarkCounts_model": 0, + "DarkCounts_time": 150 + } + ] + }, + "MCcrosstalk": { + "Active": false, + "Model": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "ProbDistr": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "TrigProb": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + }, + "Noise": { + "Active": false, + "NoiseSigma": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "NoiseSigmaStat": [ + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ] + ] + }, + "PHS": { + "Active": false, + "Data": [ + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + }, + { + "Average": 1, + "Mode": 0 + } + ] + } + }, + "FixedWorldSizes": { + "WorldSizeFixed": false, + "XY": 932.41333698683025, + "Z": 932.41333698683025 + }, + "IndividualPMoverrides": { + "Angular": { + "AngularResponse": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "RefrIndex": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ] + }, + "Area": { + "AreaResponse": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "Step": [ + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ], + [ + 777, + 777 + ] + ] + }, + "PDEeffective": [ + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + -1 + ], + "PDEwave": [ + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ], + [ + ] + ], + "RelQEandElStr": [ + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ], + [ + 1, + 1 + ] + ] + }, + "LoadExpDataConfig": { + "AddMulti": [ + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ], + [ + 0, + 1 + ] + ], + "IgnoreThresholds": { + "Activated": false, + "Max": 10000000000, + "Min": 1 + }, + "LoadFirst": -1, + "LoadedEnergy": { + "Activated": false, + "Add": 0, + "Channel": 38, + "Multi": 1 + }, + "LoadedPosition": { + "Activated": false, + "Channel": 0 + }, + "LoadedZPosition": { + "Activated": false, + "Channel": 0 + }, + "ManifestFile": "", + "Preprocessing": false + }, + "MaterialCollection": { + "LogLog": false, + "Materials": [ + { + "*MaterialName": "Air", + "BulkAbsorption": 0, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 0 + }, + "Comments": "", + "Density": 0.0012041, + "ElDriftVelo": 1, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "ElasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true, + "UseNCrystal": false + } + ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Model": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 2, + "SecScint_Tau": 5, + "Temperature": 298, + "W": 100 + }, + { + "*MaterialName": "LXenon", + "BulkAbsorption": 0.00054000000000000001, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 0 + }, + "Comments": "", + "Density": 0.0012041, + "ElDriftVelo": 1, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "ElasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "ReactionType": 2 + }, + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "NCrystal_Ncmat": "", + "NCystal_CutOff": 0, + "NCystal_Packing": 1, + "ReactionType": 4 + } + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true, + "UseNCrystal": false + } + ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Model": 0, + "RayleighMFP": 300, + "RayleighWave": 175, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1.6899999999999999, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 2, + "SecScint_Tau": 5, + "Temperature": 298, + "W": 100 + }, + { + "*MaterialName": "GXenon", + "BulkAbsorption": 0, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 0 + }, + "Comments": "", + "Density": 0.0012041, + "ElDriftVelo": 1, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "ElasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "ReactionType": 2 + }, + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "NCrystal_Ncmat": "", + "NCystal_CutOff": 0, + "NCystal_Packing": 1, + "ReactionType": 4 + } + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true, + "UseNCrystal": false + } + ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Model": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 100, + "SecScint_Tau": 5, + "Temperature": 298, + "W": 0.029999999999999999 + }, + { + "*MaterialName": "Cu", + "BulkAbsorption": 10000, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 0 + }, + "Comments": "", + "Density": 0.0012041, + "ElDriftVelo": 1, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "ElasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "ReactionType": 2 + }, + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "NCrystal_Ncmat": "", + "NCystal_CutOff": 0, + "NCystal_Packing": 1, + "ReactionType": 4 + } + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true, + "UseNCrystal": false + } + ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Model": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 2, + "SecScint_Tau": 5, + "Temperature": 298, + "W": 100 + }, + { + "*MaterialName": "Teflon", + "BulkAbsorption": 10000, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 0 + }, + "Comments": "", + "Density": 0.0012041, + "ElDriftVelo": 0, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "ElasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true, + "UseNCrystal": false + } + ], + "PrimScintDecay": [ + [ + 0, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Model": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1.3500000000000001, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 0, + "SecScint_Tau": 0, + "Temperature": 298, + "W": 100 + }, + { + "*MaterialName": "Glass", + "BulkAbsorption": 0.0030000000000000001, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 0 + }, + "Comments": "", + "Density": 0.0012041, + "ElDriftVelo": 1, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "ElasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "ReactionType": 2 + }, + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "NCrystal_Ncmat": "", + "NCystal_CutOff": 0, + "NCystal_Packing": 1, + "ReactionType": 4 + } + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true, + "UseNCrystal": false + } + ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Model": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1.55, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 2, + "SecScint_Tau": 5, + "Temperature": 298, + "W": 100 + }, + { + "*MaterialName": "DarkTeflon", + "BulkAbsorption": 100000, + "BulkAbsorptionWave": [ + ], + "ChemicalComposition": { + "ElementComposition": [ + ], + "ElementCompositionString": "", + "MeanAtomMass": 0 + }, + "Comments": "", + "Density": 0.0012041, + "ElDriftVelo": 1, + "MatParticles": [ + { + "*Particle": { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + "DataSource": "", + "DataString": "", + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "TotalInteraction": [ + ], + "TrackingAllowed": true + }, + { + "*Particle": { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + }, + "AllowAbsentCsData": false, + "CaptureEnabled": true, + "DataSource": "", + "DataString": "", + "ElasticEnabled": false, + "IntrEnergyRes": 0, + "MatIsTransparent": true, + "PrimScintPhYield": 0, + "Terminators": [ + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "ReactionType": 2 + }, + { + "InteractionData": [ + ], + "IsotopeRecords": [ + ], + "NCrystal_Ncmat": "", + "NCystal_CutOff": 0, + "NCystal_Packing": 1, + "ReactionType": 4 + } + ], + "TotalInteraction": [ + ], + "TrackingAllowed": true, + "UseNCrystal": false + } + ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], + "PrimScintSpectrum": [ + ], + "PrimScint_Model": 0, + "RayleighMFP": 0, + "RayleighWave": 500, + "ReemissionProb": 0, + "ReemissionProbabilityWave": [ + ], + "RefractiveIndex": 1.3500000000000001, + "RefractiveIndexWave": [ + ], + "SecScintSpectrum": [ + ], + "SecScint_PhYield": 2, + "SecScint_Tau": 5, + "Temperature": 298, + "W": 100 + } + ], + "Overrides": [ + { + "Abs": 0.050000000000000003, + "MatFrom": 1, + "MatTo": 4, + "Model": "Simplistic_model", + "Scat": 0.94999999999999996, + "ScatMode": 1, + "Spec": 0 + }, + { + "Abs": 1, + "MatFrom": 1, + "MatTo": 6, + "Model": "Simplistic_model", + "Scat": 0, + "ScatMode": 1, + "Spec": 0 + }, + { + "Abs": 1, + "MatFrom": 2, + "MatTo": 3, + "Model": "Simplistic_model", + "Scat": 0, + "ScatMode": 1, + "Spec": 0 + }, + { + "Abs": 0.10000000000000001, + "MatFrom": 2, + "MatTo": 4, + "Model": "Simplistic_model", + "Scat": 0.90000000000000002, + "ScatMode": 1, + "Spec": 0 + }, + { + "Abs": 1, + "MatFrom": 2, + "MatTo": 6, + "Model": "Simplistic_model", + "Scat": 0, + "ScatMode": 1, + "Spec": 0 + } + ] + }, + "PMarrays": [ + { + "PMarrayData": { + "Activated": true, + "CenterToCenter": 79, + "NumRings": 2, + "PMtype": 0, + "Packing": 1, + "PositioningScript": "PM( 0, 0, 0, Type1 )", + "Regularity": 0, + "UseRings": true + } + }, + { + "PMarrayData": { + "Activated": true, + "CenterToCenter": 79, + "NumRings": 2, + "PMtype": 0, + "Packing": 1, + "Regularity": 0, + "UseRings": true + } + } + ], + "PMtypes": [ + { + "AngularResponse": { + "RefrIndexMeasure": 1, + "ResponseVsAngle": [ + ] + }, + "AreaResponse": { + "AreaStepX": 1, + "AreaStepY": 1, + "ResponseVsXY": [ + ] + }, + "General": { + "AngleSphere": 35, + "MaterialIndex": 5, + "Name": "Type1", + "Shape": 1, + "SiPM": false, + "SizeX": 76, + "SizeY": 100, + "SizeZ": 0.01 + }, + "PDEproperties": { + "PDE": 0.29999999999999999, + "PDEwave": [ + ] + }, + "SiPMproperties": { + "DarkCountRate": 10000000, + "PixelsX": 50, + "PixelsY": 50, + "RecoveryTime": 50 + } + } + ], + "ParticleCollection": [ + { + "Charge": 0, + "Mass": 0, + "Name": "gamma", + "Type": 0 + }, + { + "Charge": 2, + "Mass": 4, + "Name": "alpha", + "Type": 1 + }, + { + "Charge": 0, + "Mass": 1, + "Name": "neutron", + "Type": 2 + } + ], + "Sandwich": { + "DefaultXY": { + "angle": 0, + "shape": 1, + "sides": 6, + "size1": 400, + "size2": 100 + }, + "Slabs": [ + { + "XY": { + "angle": 0, + "shape": 1, + "sides": 12, + "size1": 450, + "size2": 100 + }, + "color": 7, + "fActive": true, + "fCenter": false, + "height": 50, + "material": 2, + "name": "New_B7", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 400, + "size2": 100 + }, + "color": 2, + "fActive": true, + "fCenter": true, + "height": 26, + "material": 2, + "name": "SecScint", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 2, + "sides": 12, + "size1": 400, + "size2": 100 + }, + "color": 4, + "fActive": true, + "fCenter": false, + "height": 430, + "material": 1, + "name": "Scint", + "style": 1, + "width": 1 + }, + { + "XY": { + "angle": 0, + "shape": 1, + "sides": 12, + "size1": 450, + "size2": 100 + }, + "color": 28, + "fActive": true, + "fCenter": false, + "height": 50, + "material": 1, + "name": "New_B9", + "style": 1, + "width": 1 + } + ], + "State": "Individual", + "WorldMaterial": 4, + "WorldTree": [ + { + "Container": "", + "Locked": false, + "Name": "World", + "ObjectType": { + "Type": "World" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "World", + "Locked": false, + "Material": 6, + "Name": "DarkCorp1", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTube", + "ShapeSpecific": { + "dz": 25, + "rmax": 250, + "rmin": 225 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 51, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "World", + "Locked": false, + "Material": 6, + "Name": "DarkCorp2", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTube", + "ShapeSpecific": { + "dz": 25, + "rmax": 250, + "rmin": 225 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": -455, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "World", + "Locked": false, + "Name": "New_B7", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "World", + "Locked": false, + "Name": "SecScint", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "SecScint", + "Locked": false, + "Material": 2, + "Name": "Grid_O7", + "ObjectType": { + "Type": "Grid" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTube", + "ShapeSpecific": { + "dz": 0.251, + "rmax": 200, + "rmin": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": false, + "style": 1, + "width": 1 + }, + { + "Container": "Grid_O7", + "Locked": false, + "Material": 2, + "Name": "GridElement_Grid_O7", + "ObjectType": { + "Type": "GridElement", + "dz": 0.251, + "shape": 2, + "size1": 3.5, + "size2": 3 + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoPolygon", + "ShapeSpecific": { + "dphi": 360, + "dz": 0.251, + "nedges": 6, + "rmaxL": 3.5, + "rmaxU": 3.5, + "rminL": 0, + "rminU": 0 + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": 1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "GridElement_Grid_O7", + "Locked": false, + "Material": 3, + "Name": "Composite_XJ7", + "ObjectType": { + "Type": "Composite" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoCompositeShape", + "ShapeSpecific": { + "GenerationString": "TGeoCompositeShape( New_NG6 + New_IP2 + New_OY3 + New_AA7 + New_VK9 + New_UX7 )" + }, + "Theta": 0, + "X": 0, + "Y": 0, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": false, + "style": 1, + "width": 1 + }, + { + "Container": "Composite_XJ7", + "Locked": false, + "Name": "CompositeSet_Composite_XJ7", + "ObjectType": { + "Type": "CompositeContainer" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "CompositeSet_Composite_XJ7", + "Locked": false, + "Material": 2, + "Name": "New_UX7", + "ObjectType": { + "Type": "Single" + }, + "Phi": -120, + "Psi": 0, + "Shape": "TGeoTrd1", + "ShapeSpecific": { + "dx1": 2.0207152177176311, + "dx2": 2.3093902177176311, + "dy": 0.25, + "dz": 0.25 + }, + "Theta": 90, + "X": 2.8145812500000003, + "Y": -1.625, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_XJ7", + "Locked": false, + "Material": 2, + "Name": "New_VK9", + "ObjectType": { + "Type": "Single" + }, + "Phi": 120, + "Psi": 0, + "Shape": "TGeoTrd1", + "ShapeSpecific": { + "dx1": 2.0207152177176311, + "dx2": 2.3093902177176311, + "dy": 0.25, + "dz": 0.25 + }, + "Theta": 90, + "X": -2.8145812500000003, + "Y": -1.625, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_XJ7", + "Locked": false, + "Material": 2, + "Name": "New_AA7", + "ObjectType": { + "Type": "Single" + }, + "Phi": -60, + "Psi": 0, + "Shape": "TGeoTrd1", + "ShapeSpecific": { + "dx1": 2.0207152177176311, + "dx2": 2.3093902177176311, + "dy": 0.25, + "dz": 0.25 + }, + "Theta": 90, + "X": 2.8145812500000003, + "Y": 1.625, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_XJ7", + "Locked": false, + "Material": 2, + "Name": "New_OY3", + "ObjectType": { + "Type": "Single" + }, + "Phi": 60, + "Psi": 0, + "Shape": "TGeoTrd1", + "ShapeSpecific": { + "dx1": 2.0207152177176311, + "dx2": 2.3093902177176311, + "dy": 0.25, + "dz": 0.25 + }, + "Theta": 90, + "X": -2.8145812500000003, + "Y": 1.625, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_XJ7", + "Locked": false, + "Material": 2, + "Name": "New_IP2", + "ObjectType": { + "Type": "Single" + }, + "Phi": 180, + "Psi": 0, + "Shape": "TGeoTrd1", + "ShapeSpecific": { + "dx1": 2.0207152177176311, + "dx2": 2.3093902177176311, + "dy": 0.25, + "dz": 0.25 + }, + "Theta": 90, + "X": 0, + "Y": -3.25, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "CompositeSet_Composite_XJ7", + "Locked": false, + "Material": 2, + "Name": "New_NG6", + "ObjectType": { + "Type": "Single" + }, + "Phi": 0, + "Psi": 0, + "Shape": "TGeoTrd1", + "ShapeSpecific": { + "dx1": 2.0207152177176311, + "dx2": 2.3093902177176311, + "dy": 0.25, + "dz": 0.25 + }, + "Theta": 90, + "X": 0, + "Y": 3.25, + "Z": 0, + "color": -1, + "fActive": true, + "fExpanded": true, + "style": 1, + "width": 1 + }, + { + "Container": "World", + "Locked": false, + "Name": "Scint", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + }, + { + "Container": "World", + "Locked": false, + "Name": "New_B9", + "ObjectType": { + "Type": "Slab" + }, + "fActive": true, + "fExpanded": true + } + ], + "ZeroZ": "Bottom" + } + }, + "GUI": { + "GeometryWindow": { + "ZoomLevel": 2 + }, + "MW": { + "ConfigGuiLocked": false + }, + "PartcleStackChecker": { + "Copies": 1, + "Energy": 200, + "Particle": 0, + "ScriptEV": "", + "Time": 0, + "X": 0, + "Y": 0, + "Z": 0, + "dX": 1, + "dY": 0, + "dZ": 0 + }, + "ReconstructionWindow": { + "Blur": { + "BlurSigma": 10, + "BlurSigmaZ": 1, + "BlurType": 1, + "BlurWidth": 10, + "BlurWidthZ": 1 + }, + "ChPerPhePeaks": { + "Bins": 300, + "From": -50, + "MaxPeaks": 30, + "Sigma": 8, + "Threshold": 0.02, + "To": 250 + }, + "ChPerPheStat": { + "Bins": 100, + "ENF": 1, + "Lower": 3, + "MaxRange": 1000, + "MinRange": 0, + "Upper": 500 + }, + "PlotXYsettings": { + "PlotXYbinsX": 50, + "PlotXYbinsY": 50, + "PlotXYfromX": -180, + "PlotXYfromY": -180, + "PlotXYfromZ": -5, + "PlotXYoptionZ": 0, + "PlotXYtoX": 180, + "PlotXYtoY": 180, + "PlotXYtoZ": 5 + } + } + }, + "ReconstructionConfig": { + "ANTS2build": 2197, + "FilterOptions": [ + { + "Chi2": { + "Active": false, + "Max": 2, + "Min": 0 + }, + "Correlation": { + "Active": false, + "Set": [ + { + "Active": true, + "AutoSize": true, + "BinX": 100, + "BinY": 100, + "Cut": { + "CutOption": 0, + "Data": [ + 0, + 1, + 300 + ], + "Type": "line" + }, + "XY": [ + { + "Array": [ + 0 + ], + "Type": "SingleChannel" + }, + { + "Array": [ + 0 + ], + "Type": "SingleChannel" + } + ], + "maxX": 20, + "maxY": 20, + "minX": -20, + "minY": -20 + } + ] + }, + "EventNumber": { + "Active": false, + "Max": 0, + "Min": 0 + }, + "IndividualPMSignal": { + "Active": false, + "UsePassives": true + }, + "LoadedEnergy": { + "Active": false, + "Max": 10000000000, + "Min": 0 + }, + "MultipleScanEvents": false, + "ReconstructedEnergy": { + "Active": false, + "Max": 10000000000, + "Min": 0 + }, + "SpatialCustom": { + "Active": false, + "AllZ": true, + "Angle": 0, + "CutOutsideInside": 0, + "Diameter": 400, + "Polygon": [ + ], + "RecOrScan": 0, + "Shape": 1, + "Side": 15, + "SizeX": 30, + "SizeY": 30, + "X0": 0, + "Y0": 0, + "Zfrom": -5, + "Zto": 5 + }, + "SpatialToObject": { + "Active": false, + "LimitObject": "PrScint", + "RecOrScan": 0 + }, + "SumSignal": { + "Active": false, + "Max": 10000000000, + "Min": 0, + "UseGains": false, + "UsePassives": true + }, + "kNN": { + "Active": false, + "AverageOver": 10, + "Max": 10000000000, + "Min": 0 + } + } + ], + "LRFmakeJson": { + "AdjustGains": true, + "Compression_k": 5, + "Compression_lam": 50, + "Compression_r0": 150, + "DataSelector": 0, + "EnergyNormalization": 1, + "FitOnlyLast": false, + "ForceInZ": 0, + "ForceNonIncreasingInR": false, + "ForceNonNegative": false, + "ForceZeroDeriv": true, + "GroupToMake": 0, + "GroupingOption": "Individual", + "GrouppingType": 0, + "LRF_3D": false, + "LRF_compress": true, + "LRF_type": 0, + "LimitGroup": false, + "Nodes_x": 10, + "Nodes_y": 10, + "StoreError": false, + "UseEnergy": true, + "UseGrid": true, + "UseGroupping": false + }, + "LRFmoduleSelected": 0, + "LRFv3makeJson": { + "fit error": true, + "instruction list vpos": 0, + "instructions": [ + { + "current instruction": 0, + "expanded": true, + "instructions": [ + { + "EffectOnPrevious": 0, + "Groupping": { + "AdjustGains": true, + "Enabled": true, + "Type": 0 + }, + "Lrf": { + "Category": "Script", + "Settings": { + "script": "//Variables to be fitted and their initial values:\nvar A = 150; var m = 0\nvar b = 2; var g = 1\n\nfunction eval(r)\n{\n // var dr = r[0]-mu\n return m*r[0]+b+A/Math.pow(1+g*g*r[0]*r[0], 1.5)\n}\n", + "text height": 130 + }, + "Type": "Script Polar" + }, + "SensorComposition": 0, + "SensorGroup": 0, + "SensorList": "0, 2-5" + }, + { + "recipe": 9, + "sensors": "", + "version": -1 + } + ], + "name": "Name" + }, + { + "current instruction": 0, + "expanded": true, + "instructions": [ + { + "EffectOnPrevious": 0, + "Groupping": { + "AdjustGains": true, + "Enabled": true, + "Type": 1 + }, + "Lrf": { + "Category": "Bspline", + "Settings": { + "nintx": 2, + "ninty": 2 + }, + "Type": "XY" + }, + "SensorComposition": 0, + "SensorGroup": 0, + "SensorList": "7-18" + }, + { + "recipe": 9, + "sensors": "", + "version": -1 + } + ], + "name": "Name" + } + ], + "name": "Recipe's name", + "scale by energy": true, + "use true data": true + }, + "ReconstructionOptions": [ + { + "AlgorithmOptions": { + "Algorithm": 1, + "CGonCUDAsettings": { + "Buffer": 500, + "Iterations": 3, + "OptimizeMLChi2": 0, + "ScaleReduction": 8, + "StartOption": 0, + "StartStep": 10, + "StartX": 0, + "StartY": 0, + "StarterZ": 0, + "ThreadBlockXY": 8 + }, + "CPUgridsOptions": { + "InitialStep": 10, + "Iterations": 3, + "NodesXY": 15, + "OptimizeWhat": 0, + "Reduction": 8, + "StartOption": 1, + "StartX": 0, + "StartY": 0 + }, + "CoGoptions": { + "DoStretch": true, + "ForceFixedZ": true, + "IgnoreBySignal": false, + "IgnoreDistance": 100, + "IgnoreFar": false, + "IgnoreThresholdHigh": 10000000000, + "IgnoreThresholdLow": 200, + "StretchX": 2.2000000000000002, + "StretchY": 2.2000000000000002, + "StretchZ": 1 + }, + "RootMinimizerOptions": { + "LSorLikelihood": 1, + "LSsuppressConsole": true, + "MaxCalls": 500, + "Minuit2Option": 1, + "StartOption": 1, + "StartStepEnergy": 0.10000000000000001, + "StartStepX": 1, + "StartStepY": 1, + "StartStepZ": 1 + } + }, + "DynamicPassives": { + "DistanceLimit": 200, + "IgnoreByDistance": false, + "IgnoreBySignal": true, + "SignalLimitHigh": 10000000000, + "SignalLimitLow": 0 + }, + "General": { + "IncludePassives": false, + "InitialEnergy": 1, + "InitialZ": 0, + "LimitSearchGauss": false, + "LimitSearchIfTrueIsSet": false, + "RangeForLimitSearchIfTrueSet": 1, + "ReconstructEnergy": true, + "ReconstructZ": false, + "WeightedChi2": true, + "Zstrategy": 0 + }, + "MultipleEvents": { + "Option": 0 + } + } + ], + "SensorGroups": [ + { + "CutOffs": [ + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ], + [ + -10000000000, + 10000000000 + ] + ], + "Gains": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ], + "Name": "Default group", + "PmIndexes": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37 + ] + } + ], + "StaticPassives": [ + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false, + false + ] + }, + "SimulationConfig": { + "DoGuiUpdate": true, + "GeneralSimConfig": { + "AcceleratorConfig": { + "CheckBeforeTrack": false, + "LogsStatistics": true, + "MaxNumTransitions": 10 + }, + "AngleConfig": { + "AngResolved": false, + "NumBins": 1000 + }, + "AreaConfig": { + "AreaResolved": false + }, + "DetStatNumBins": 100, + "LrfBasedSim": { + "NumPhotElLRFunity": 1, + "NumPhotsLRFunity": 20000, + "UseLRFs": false + }, + "SecScintConfig": { + "Type": 0 + }, + "TimeConfig": { + "TimeBins": 5, + "TimeFrom": 0, + "TimeResolved": false, + "TimeTo": 1000 + }, + "TrackBuildingOptions": { + "BuildParticleTracks": false, + "BuildPhotonTracks": false, + "GeneralPhoton_Attributes": { + "color": 7, + "style": 1, + "width": 1 + }, + "MaxParticleTracks": 1000, + "MaxPhotonTracks": 1000, + "Particle_CustomAttribtes": [ + ], + "Particle_DefaultAttributes": { + "color": 15, + "style": 1, + "width": 2 + }, + "Particle_DefaultColors": [ + 1, + 2, + 3, + 4, + 6, + 7, + 8, + 9, + 28, + 30, + 36, + 38, + 39, + 40, + 46, + 49 + ], + "PhotonHittingPM_Attributes": { + "color": 2, + "style": 1, + "width": 1 + }, + "PhotonSecScint_Attributes": { + "color": 6, + "style": 1, + "width": 1 + }, + "PhotonSpecialRule_HittingPMs": true, + "PhotonSpecialRule_SecScint": true, + "SkipParticles_Primary": false, + "SkipParticles_PrimaryNoInteraction": false, + "SkipParticles_Secondary": false, + "SkipPhotonsMissingPMs": false + }, + "TrackingConfig": { + "MaxStep": 0.10000000000000001, + "MinEnergy": 0.01, + "MinEnergyNeutrons": 0.01, + "MinStep": 5.0000000000000002e-05, + "Safety": 1e-10, + "dE": 0.050000000000000003 + }, + "WaveConfig": { + "WaveFrom": 200, + "WaveNodes": 121, + "WaveResolved": false, + "WaveStep": 5, + "WaveTo": 800 + } + }, + "Mode": "PointSim", + "ParticleSourcesConfig": { + "ParticleSources": [ + ], + "SourceControlOptions": { + "AllowMultipleParticles": false, + "AverageParticlesPerEvent": 0.10000000000000001, + "DoS1": true, + "DoS2": false, + "EventsToDo": 10, + "IgnoreNoDepoEvents": true, + "IgnoreNoHitsEvents": false, + "TypeParticlesPerEvent": 0 + } + }, + "PointSourcesConfig": { + "BadEventOptions": { + "BadEvents": false, + "NoiseArray": [ + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in one PM", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in one PM\n(over a normal event)", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in all PMs", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 100, + "Description": "Noise signal in all PMs\n(over a normal event)", + "Probability": 0.01, + "Spread": 40 + }, + { + "Active": false, + "AverageValue": 0, + "Description": "Double event\n(two independent)", + "Probability": 0.01, + "Spread": 0 + }, + { + "Active": false, + "AverageValue": 0.5, + "Description": "Double event\n(# of photons is shared)", + "Probability": 0.01, + "Spread": 0.25 + } + ], + "Probability": 0, + "SigmaDouble": 10 + }, + "ControlOptions": { + "LimitNodes": false, + "LimitNodesTo": "PrScint", + "MultipleRuns": false, + "MultipleRunsNumber": 100, + "Primary_Secondary": 1, + "Single_Scan_Flood": 2 + }, + "CustomNodesOptions": { + "Nodes": [ + ], + "Script": "" + }, + "FloodOptions": { + "CenterX": 0, + "CenterY": 0, + "DiameterIn": 0, + "DiameterOut": 400, + "Nodes": 10000, + "Shape": 1, + "Xfrom": -50, + "Xto": 50, + "Yfrom": -50, + "Yto": 50, + "Zfixed": -50, + "Zfrom": -2.4900000000000002, + "Zoption": 0, + "Zto": 2.4900000000000002 + }, + "PhotPerNodeOptions": { + "PhotPerNodeConstant": 1000, + "PhotPerNodeCustom": [ + ], + "PhotPerNodeGaussMean": 10000, + "PhotPerNodeGaussSigma": 250, + "PhotPerNodeMode": 0, + "PhotPerNodeUniMax": 12, + "PhotPerNodeUniMin": 10 + }, + "PhotonDirectionOptions": { + "Cone": 45, + "FixedX": 0, + "FixedY": 0, + "FixedZ": 1, + "Fixed_or_Cone": 0, + "Random": true + }, + "RegularScanOptions": { + "AxesData": [ + { + "Nodes": 5, + "Option": 0, + "dX": 10, + "dY": 0, + "dZ": 0 + }, + { + "Nodes": 5, + "Option": 0, + "dX": 0, + "dY": 10, + "dZ": 0 + } + ], + "ScanX0": 0, + "ScanY0": 0, + "ScanZ0": 0 + }, + "SinglePositionOptions": { + "SingleX": 50, + "SingleY": 0, + "SingleZ": 0 + }, + "WaveTimeOptions": { + "UseFixedWavelength": false, + "WaveIndex": 0 + } + } + } +} diff --git a/src/EXAMPLES/Simplest.json b/src/EXAMPLES/Simplest.json index 914054a1..37514d36 100644 --- a/src/EXAMPLES/Simplest.json +++ b/src/EXAMPLES/Simplest.json @@ -154,11 +154,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -175,11 +172,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -198,7 +192,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -206,12 +200,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": true + "TrackingAllowed": true, + "UseNCrystal": false } ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], "PrimScintSpectrum": [ ], - "PrimScint_Tau": 5, + "PrimScint_Model": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -224,6 +231,7 @@ ], "SecScint_PhYield": 2, "SecScint_Tau": 5, + "Temperature": 298, "W": 100 } ] @@ -267,6 +275,7 @@ ] }, "General": { + "AngleSphere": 35, "MaterialIndex": 0, "Name": "Type1", "Shape": 0, @@ -654,8 +663,7 @@ "AcceleratorConfig": { "CheckBeforeTrack": false, "LogsStatistics": false, - "MaxNumTransitions": 500, - "OnlyTracksOnPMs": false + "MaxNumTransitions": 500 }, "AngleConfig": { "AngResolved": false, @@ -664,14 +672,12 @@ "AreaConfig": { "AreaResolved": false }, - "BuildPhotonTracks": false, "DetStatNumBins": 100, "LrfBasedSim": { "NumPhotElLRFunity": 1, "NumPhotsLRFunity": 20000, "UseLRFs": false }, - "MaxNumberOfTracks": 5000, "SecScintConfig": { "Type": 0 }, @@ -681,13 +687,64 @@ "TimeResolved": false, "TimeTo": 1000 }, + "TrackBuildingOptions": { + "BuildParticleTracks": false, + "BuildPhotonTracks": false, + "GeneralPhoton_Attributes": { + "color": 7, + "style": 1, + "width": 1 + }, + "MaxParticleTracks": 1000, + "MaxPhotonTracks": 1000, + "Particle_CustomAttribtes": [ + ], + "Particle_DefaultAttributes": { + "color": 15, + "style": 1, + "width": 2 + }, + "Particle_DefaultColors": [ + 1, + 2, + 3, + 4, + 6, + 7, + 8, + 9, + 28, + 30, + 36, + 38, + 39, + 40, + 46, + 49 + ], + "PhotonHittingPM_Attributes": { + "color": 2, + "style": 1, + "width": 1 + }, + "PhotonSecScint_Attributes": { + "color": 6, + "style": 1, + "width": 1 + }, + "PhotonSpecialRule_HittingPMs": true, + "PhotonSpecialRule_SecScint": true, + "SkipParticles_Primary": false, + "SkipParticles_PrimaryNoInteraction": false, + "SkipParticles_Secondary": false, + "SkipPhotonsMissingPMs": false + }, "TrackingConfig": { "MaxStep": 0.1, "MinEnergy": 0.01, "MinEnergyNeutrons": 0.01, "MinStep": 5e-05, "Safety": 1e-10, - "TrackColorAdd": 0, "dE": 0.05 }, "WaveConfig": { @@ -700,6 +757,15 @@ }, "Mode": "PointSim", "ParticleSourcesConfig": { + "GenerationFromFile": { + "FileLastModified": 0, + "FileName": "", + "NumEventsInFile": 0, + "RegisteredParticleCount": -1 + }, + "GenerationFromScript": { + "Script": "" + }, "ParticleSources": [ ], "SourceControlOptions": { @@ -708,9 +774,9 @@ "DoS1": true, "DoS2": false, "EventsToDo": 10, - "IgnoreNoDepoEvents": true, + "IgnoreNoDepoEvents": false, "IgnoreNoHitsEvents": false, - "ParticleTracks": true, + "ParticleGenerationMode": "Sources", "TypeParticlesPerEvent": 0 } }, @@ -794,7 +860,7 @@ "Zto": 2.49 }, "PhotPerNodeOptions": { - "PhotPerNodeConstant": 4000, + "PhotPerNodeConstant": 100, "PhotPerNodeCustom": [ ], "PhotPerNodeGaussMean": 10, @@ -838,9 +904,7 @@ "SingleZ": 0 }, "WaveTimeOptions": { - "DecayTime": 0, - "Direct_Material": 2, - "Material": 0, + "UseFixedWavelength": false, "WaveIndex": 0 } } diff --git a/src/EXAMPLES/StartupDetector.json b/src/EXAMPLES/StartupDetector.json index 77135783..2e4e7274 100644 --- a/src/EXAMPLES/StartupDetector.json +++ b/src/EXAMPLES/StartupDetector.json @@ -892,11 +892,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -913,11 +910,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -936,7 +930,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -944,12 +938,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": true + "TrackingAllowed": true, + "UseNCrystal": false } ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], "PrimScintSpectrum": [ ], - "PrimScint_Tau": 5, + "PrimScint_Model": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -962,6 +969,7 @@ ], "SecScint_PhYield": 2, "SecScint_Tau": 5, + "Temperature": 298, "W": 100 }, { @@ -986,11 +994,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -1007,11 +1012,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -1030,7 +1032,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -1038,12 +1040,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": true + "TrackingAllowed": true, + "UseNCrystal": false } ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], "PrimScintSpectrum": [ ], - "PrimScint_Tau": 5, + "PrimScint_Model": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -1056,6 +1071,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 }, { @@ -1080,11 +1096,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": false, "PrimScintPhYield": 38, @@ -2243,11 +2256,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -2266,7 +2276,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -2274,9 +2284,22 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": true + "TrackingAllowed": true, + "UseNCrystal": false } ], + "PrimScintDecay": [ + [ + 250, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], "PrimScintSpectrum": [ [ 300, @@ -2339,7 +2362,7 @@ 0 ] ], - "PrimScint_Tau": 250, + "PrimScint_Model": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -2380,6 +2403,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 }, { @@ -2404,11 +2428,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -2425,11 +2446,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -2448,7 +2466,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -2456,12 +2474,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": true + "TrackingAllowed": true, + "UseNCrystal": false } ], + "PrimScintDecay": [ + [ + 5, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], "PrimScintSpectrum": [ ], - "PrimScint_Tau": 5, + "PrimScint_Model": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -2474,6 +2505,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 }, { @@ -2498,11 +2530,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": false, "PrimScintPhYield": 0, @@ -3805,11 +3834,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": true, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -3828,7 +3854,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -3836,12 +3862,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": true + "TrackingAllowed": true, + "UseNCrystal": false } ], + "PrimScintDecay": [ + [ + 0, + 1 + ] + ], + "PrimScintRaise": [ + [ + 0, + 1 + ] + ], "PrimScintSpectrum": [ ], - "PrimScint_Tau": 0, + "PrimScint_Model": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -3854,6 +3893,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 } ] @@ -3897,6 +3937,7 @@ ] }, "General": { + "AngleSphere": 35, "MaterialIndex": 1, "Name": "Hex", "Shape": 1, @@ -5420,8 +5461,7 @@ "AcceleratorConfig": { "CheckBeforeTrack": true, "LogsStatistics": false, - "MaxNumTransitions": 500, - "OnlyTracksOnPMs": false + "MaxNumTransitions": 500 }, "AngleConfig": { "AngResolved": false, @@ -5430,14 +5470,12 @@ "AreaConfig": { "AreaResolved": false }, - "BuildPhotonTracks": false, "DetStatNumBins": 100, "LrfBasedSim": { "NumPhotElLRFunity": 1, "NumPhotsLRFunity": 20000, "UseLRFs": false }, - "MaxNumberOfTracks": 5000, "SecScintConfig": { "Type": 0 }, @@ -5447,13 +5485,64 @@ "TimeResolved": false, "TimeTo": 1000 }, + "TrackBuildingOptions": { + "BuildParticleTracks": false, + "BuildPhotonTracks": true, + "GeneralPhoton_Attributes": { + "color": 7, + "style": 1, + "width": 1 + }, + "MaxParticleTracks": 1000, + "MaxPhotonTracks": 1000, + "Particle_CustomAttribtes": [ + ], + "Particle_DefaultAttributes": { + "color": 15, + "style": 1, + "width": 2 + }, + "Particle_DefaultColors": [ + 1, + 2, + 3, + 4, + 6, + 7, + 8, + 9, + 28, + 30, + 36, + 38, + 39, + 40, + 46, + 49 + ], + "PhotonHittingPM_Attributes": { + "color": 2, + "style": 1, + "width": 1 + }, + "PhotonSecScint_Attributes": { + "color": 6, + "style": 1, + "width": 1 + }, + "PhotonSpecialRule_HittingPMs": true, + "PhotonSpecialRule_SecScint": true, + "SkipParticles_Primary": false, + "SkipParticles_PrimaryNoInteraction": false, + "SkipParticles_Secondary": false, + "SkipPhotonsMissingPMs": false + }, "TrackingConfig": { "MaxStep": 0.1, "MinEnergy": 0.01, "MinEnergyNeutrons": 0.01, "MinStep": 5e-05, "Safety": 1e-10, - "TrackColorAdd": 0, "dE": 0.05 }, "WaveConfig": { @@ -5466,6 +5555,15 @@ }, "Mode": "PointSim", "ParticleSourcesConfig": { + "GenerationFromFile": { + "FileLastModified": 0, + "FileName": "D:/QtProjects/ANTS2git/ANTS2/build-ants2-Desktop_Qt_5_8_0_MSVC2013_32bit-Release/EXAMPLES/ExampleParticlesFromFile.dat", + "NumEventsInFile": 0, + "RegisteredParticleCount": -1 + }, + "GenerationFromScript": { + "Script": "gen.AddParticle(0, 120, math.gauss(0, 25), math.gauss(0, 25), -20, 0,0,1)\nif (math.random() < 0.1)\n gen.AddParticle(0, 120, math.gauss(0, 25), math.gauss(0, 25), -20, 0,0,1)" + }, "ParticleSources": [ { "Activity": 1, @@ -5485,7 +5583,9 @@ "name": "gamma", "type": 0 }, - "StatWeight": 0.856 + "PreferredUnits": "keV", + "StatWeight": 0.856, + "UseFixedEnergy": true }, { "Energy": 136, @@ -5499,7 +5599,9 @@ "name": "gamma", "type": 0 }, - "StatWeight": 0.1068 + "PreferredUnits": "keV", + "StatWeight": 0.1068, + "UseFixedEnergy": true } ], "LimitedToMaterial": "", @@ -5524,9 +5626,9 @@ "DoS1": true, "DoS2": false, "EventsToDo": 10, - "IgnoreNoDepoEvents": true, + "IgnoreNoDepoEvents": false, "IgnoreNoHitsEvents": false, - "ParticleTracks": true, + "ParticleGenerationMode": "Sources", "TypeParticlesPerEvent": 0 } }, @@ -6582,9 +6684,7 @@ "SingleZ": 0 }, "WaveTimeOptions": { - "DecayTime": 0, - "Direct_Material": 2, - "Material": 0, + "UseFixedWavelength": false, "WaveIndex": 0 } } diff --git a/src/gui/exampleswindow.ui b/src/gui/exampleswindow.ui index b66492b5..e53d98d0 100644 --- a/src/gui/exampleswindow.ui +++ b/src/gui/exampleswindow.ui @@ -7,7 +7,7 @@ 0 0 458 - 455 + 492 @@ -18,7 +18,7 @@ 123 - 410 + 444 231 17 @@ -31,7 +31,7 @@ 1 - 271 + 306 457 20 @@ -55,7 +55,7 @@ 4 30 451 - 233 + 271 @@ -68,7 +68,7 @@ 12 - 114 + 150 151 16 @@ -87,7 +87,7 @@ 129 - 204 + 241 191 24 @@ -105,7 +105,7 @@ - 8 + 20 4 107 13 @@ -123,8 +123,8 @@ 6 20 - 111 - 91 + 129 + 127 @@ -138,7 +138,7 @@ 6 - 131 + 167 441 70 @@ -147,17 +147,17 @@ - 126 + 140 20 131 - 91 + 127 - 268 + 270 4 178 13 @@ -173,7 +173,7 @@ - 128 + 142 4 130 13 @@ -189,10 +189,10 @@ - 266 + 276 20 - 181 - 91 + 171 + 127 @@ -223,7 +223,7 @@ 4 - 292 + 327 451 111 diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index c9c04bb8..cd779282 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -6893,7 +6893,7 @@ Second click will trigger strong abort mode, which will result in loss of all si QTabWidget::Rounded - 1 + 0 false @@ -8684,7 +8684,7 @@ Second click will trigger strong abort mode, which will result in loss of all si Right click: toggle build photon tracks. Also switches of building particle tracks - tracks options + track options @@ -9668,7 +9668,7 @@ double events: Right click: toggle build particle tracks. Also switch off building photon tracks - tracks options + track options @@ -9687,7 +9687,7 @@ Right click: toggle build particle tracks. Also switch off building photon track - 1 + 0 From aacb5d03412e590930bdccacecda2fec17f40b87 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 4 Nov 2018 20:15:50 +0000 Subject: [PATCH 132/140] fix for the merge from Andr-dev --- src/common/ahistoryrecords.h | 4 ++-- src/gui/MainWindowTools/globalscript.cpp | 2 +- src/gui/MainWindowTools/pythonscript.cpp | 2 +- src/gui/outputwindow.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/ahistoryrecords.h b/src/common/ahistoryrecords.h index fb09aff9..2de2445f 100644 --- a/src/common/ahistoryrecords.h +++ b/src/common/ahistoryrecords.h @@ -1,7 +1,7 @@ #ifndef AHISTORYRECORDS #define AHISTORYRECORDS -#include "aparticleonstack.h" +#include "aparticlerecord.h" #include #include @@ -45,7 +45,7 @@ struct EventHistoryStructure x(r[0]), y(r[1]), z(r[2]), dx(v[0]), dy(v[1]), dz(v[2]), initialEnergy(energy) {} - EventHistoryStructure(const AParticleOnStack* p, int index) : + EventHistoryStructure(const AParticleRecord* p, int index) : ParticleId(p->Id), index(index), SecondaryOf(p->secondaryOf), x(p->r[0]), y(p->r[1]), z(p->r[2]), dx(p->v[0]), dy(p->v[1]), dz(p->v[2]), diff --git a/src/gui/MainWindowTools/globalscript.cpp b/src/gui/MainWindowTools/globalscript.cpp index 4808cdf9..332bb8c4 100644 --- a/src/gui/MainWindowTools/globalscript.cpp +++ b/src/gui/MainWindowTools/globalscript.cpp @@ -119,7 +119,7 @@ void MainWindow::createScriptWindow() ScriptWindow->RegisterInterface(depo, "depo"); AParticleTrackingHistoryInterface* pth = new AParticleTrackingHistoryInterface(*EventsDataHub); - ScriptWindow->SetInterfaceObject(pth, "tracklog"); + ScriptWindow->RegisterInterface(pth, "tracklog"); #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager->KNNmodule); diff --git a/src/gui/MainWindowTools/pythonscript.cpp b/src/gui/MainWindowTools/pythonscript.cpp index 03d8831f..79832ded 100644 --- a/src/gui/MainWindowTools/pythonscript.cpp +++ b/src/gui/MainWindowTools/pythonscript.cpp @@ -103,7 +103,7 @@ void MainWindow::createPythonScriptWindow() PythonScriptWindow->RegisterInterface(depo, "depo"); AParticleTrackingHistoryInterface* pth = new AParticleTrackingHistoryInterface(*EventsDataHub); - ScriptWindow->SetInterfaceObject(pth, "tracklog"); + ScriptWindow->RegisterInterface(pth, "tracklog"); #ifdef ANTS_FLANN AInterfaceToKnnScript* knn = new AInterfaceToKnnScript(ReconstructionManager->KNNmodule); diff --git a/src/gui/outputwindow.cpp b/src/gui/outputwindow.cpp index 7b704aba..28b50ecc 100644 --- a/src/gui/outputwindow.cpp +++ b/src/gui/outputwindow.cpp @@ -1617,9 +1617,9 @@ void OutputWindow::on_pbSaveLog_clicked() return; } - QString fileName = QFileDialog::getSaveFileName(this, "Save particle tracking log to ROOT tree", MW->GlobSet->LastOpenDir, "TTree files (*.root)"); + QString fileName = QFileDialog::getSaveFileName(this, "Save particle tracking log to ROOT tree", MW->GlobSet.LastOpenDir, "TTree files (*.root)"); if (fileName.isEmpty()) return; - MW->GlobSet->LastOpenDir = QFileInfo(fileName).absolutePath(); + MW->GlobSet.LastOpenDir = QFileInfo(fileName).absolutePath(); QFileInfo file(fileName); if (file.suffix().isEmpty()) fileName += ".root"; EventsDataHub->saveEventHistoryToTree(fileName); From 91c73d887fe9ece132d3a43104089a2c41dfc41d Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 7 Nov 2018 16:30:57 +0000 Subject: [PATCH 133/140] ++ --- src/EXAMPLES/LUX.json | 233 +++++++++++++++++++++++++++--------------- 1 file changed, 152 insertions(+), 81 deletions(-) diff --git a/src/EXAMPLES/LUX.json b/src/EXAMPLES/LUX.json index d0564405..fcc86895 100644 --- a/src/EXAMPLES/LUX.json +++ b/src/EXAMPLES/LUX.json @@ -5115,11 +5115,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5136,11 +5133,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5159,7 +5153,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5167,19 +5161,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": false + "TrackingAllowed": false, + "UseNCrystal": false } ], - "PrimScintSpectrum": [ + "PrimScintDecay": [ + [ + 5, + 1 + ] ], - "PrimScint_Decay": [ + "PrimScintRaise": [ [ - 1, - 5 + 0, + 1 ] ], + "PrimScintSpectrum": [ + ], "PrimScint_Model": 0, - "PrimScint_Raise": 0, "RayleighMFP": 300, "RayleighWave": 175, "ReemissionProb": 0, @@ -5192,6 +5192,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 }, { @@ -5216,11 +5217,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5237,11 +5235,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5260,7 +5255,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5268,19 +5263,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": false + "TrackingAllowed": false, + "UseNCrystal": false } ], - "PrimScintSpectrum": [ + "PrimScintDecay": [ + [ + 5, + 1 + ] ], - "PrimScint_Decay": [ + "PrimScintRaise": [ [ - 1, - 5 + 0, + 1 ] ], + "PrimScintSpectrum": [ + ], "PrimScint_Model": 0, - "PrimScint_Raise": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -5293,6 +5294,7 @@ ], "SecScint_PhYield": 2, "SecScint_Tau": 5, + "Temperature": 298, "W": 25 }, { @@ -5317,11 +5319,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5338,11 +5337,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5361,7 +5357,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5369,19 +5365,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": false + "TrackingAllowed": false, + "UseNCrystal": false } ], - "PrimScintSpectrum": [ + "PrimScintDecay": [ + [ + 5, + 1 + ] ], - "PrimScint_Decay": [ + "PrimScintRaise": [ [ - 1, - 5 + 0, + 1 ] ], + "PrimScintSpectrum": [ + ], "PrimScint_Model": 0, - "PrimScint_Raise": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -5394,6 +5396,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 }, { @@ -5418,11 +5421,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5439,11 +5439,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5462,7 +5459,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5470,19 +5467,25 @@ ], "TotalInteraction": [ ], - "TrackingAllowed": false + "TrackingAllowed": false, + "UseNCrystal": false } ], - "PrimScintSpectrum": [ + "PrimScintDecay": [ + [ + 5, + 1 + ] ], - "PrimScint_Decay": [ + "PrimScintRaise": [ [ - 1, - 5 + 0, + 1 ] ], + "PrimScintSpectrum": [ + ], "PrimScint_Model": 0, - "PrimScint_Raise": 0, "RayleighMFP": 0, "RayleighWave": 500, "ReemissionProb": 0, @@ -5495,6 +5498,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 }, { @@ -5519,11 +5523,8 @@ "Name": "gamma", "Type": 0 }, - "AllowAbsentCsData": false, - "CaptureEnabled": false, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5540,11 +5541,8 @@ "Name": "alpha", "Type": 1 }, - "AllowAbsentCsData": false, - "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5563,7 +5561,7 @@ "CaptureEnabled": true, "DataSource": "", "DataString": "", - "EllasticEnabled": false, + "ElasticEnabled": false, "IntrEnergyRes": 0, "MatIsTransparent": true, "PrimScintPhYield": 0, @@ -5580,24 +5578,33 @@ ], "IsotopeRecords": [ ], + "NCrystal_Ncmat": "", + "NCystal_CutOff": 0, + "NCystal_Packing": 1, "ReactionType": 4 } ], "TotalInteraction": [ ], - "TrackingAllowed": false + "TrackingAllowed": false, + "UseNCrystal": false } ], - "PrimScintSpectrum": [ + "PrimScintDecay": [ + [ + 5, + 1 + ] ], - "PrimScint_Decay": [ + "PrimScintRaise": [ [ - 1, - 5 + 0, + 1 ] ], + "PrimScintSpectrum": [ + ], "PrimScint_Model": 0, - "PrimScint_Raise": 0, "RayleighMFP": 0, "RayleighWave": 175, "ReemissionProb": 0, @@ -5610,6 +5617,7 @@ ], "SecScint_PhYield": 0, "SecScint_Tau": 0, + "Temperature": 298, "W": 0 } ], @@ -5618,7 +5626,7 @@ "Abs": 0.03, "MatFrom": 0, "MatTo": 2, - "Model": "Simplistic_model", + "Model": "Simplistic", "Scat": 0.97, "ScatMode": 1, "Spec": 0 @@ -5627,7 +5635,7 @@ "Abs": 0.8, "MatFrom": 0, "MatTo": 4, - "Model": "Simplistic_model", + "Model": "Simplistic", "Scat": 0, "ScatMode": 1, "Spec": 0.2 @@ -5636,7 +5644,7 @@ "Abs": 0.2, "MatFrom": 1, "MatTo": 2, - "Model": "Simplistic_model", + "Model": "Simplistic", "Scat": 0.8, "ScatMode": 1, "Spec": 0 @@ -5645,7 +5653,7 @@ "Abs": 0.8, "MatFrom": 1, "MatTo": 4, - "Model": "Simplistic_model", + "Model": "Simplistic", "Scat": 0, "ScatMode": 1, "Spec": 0.2 @@ -6420,6 +6428,7 @@ ] }, "General": { + "AngleSphere": 35, "MaterialIndex": 3, "Name": "Type0", "Shape": 1, @@ -6453,6 +6462,7 @@ ] }, "General": { + "AngleSphere": 35, "MaterialIndex": 3, "Name": "Type_1", "Shape": 1, @@ -8549,8 +8559,7 @@ "AcceleratorConfig": { "CheckBeforeTrack": true, "LogsStatistics": false, - "MaxNumTransitions": 25, - "OnlyTracksOnPMs": false + "MaxNumTransitions": 25 }, "AngleConfig": { "AngResolved": false, @@ -8559,14 +8568,12 @@ "AreaConfig": { "AreaResolved": false }, - "BuildPhotonTracks": false, - "DetStatNumBins": 300, + "DetStatNumBins": 100, "LrfBasedSim": { "NumPhotElLRFunity": 1, "NumPhotsLRFunity": 20000, "UseLRFs": false }, - "MaxNumberOfTracks": 1000, "SecScintConfig": { "Type": 0 }, @@ -8576,13 +8583,64 @@ "TimeResolved": false, "TimeTo": 1000 }, + "TrackBuildingOptions": { + "BuildParticleTracks": false, + "BuildPhotonTracks": false, + "GeneralPhoton_Attributes": { + "color": 7, + "style": 1, + "width": 1 + }, + "MaxParticleTracks": 1000, + "MaxPhotonTracks": 1000, + "Particle_CustomAttribtes": [ + ], + "Particle_DefaultAttributes": { + "color": 15, + "style": 1, + "width": 2 + }, + "Particle_DefaultColors": [ + 1, + 2, + 3, + 4, + 6, + 7, + 8, + 9, + 28, + 30, + 36, + 38, + 39, + 40, + 46, + 49 + ], + "PhotonHittingPM_Attributes": { + "color": 2, + "style": 1, + "width": 1 + }, + "PhotonSecScint_Attributes": { + "color": 6, + "style": 1, + "width": 1 + }, + "PhotonSpecialRule_HittingPMs": true, + "PhotonSpecialRule_SecScint": true, + "SkipParticles_Primary": false, + "SkipParticles_PrimaryNoInteraction": false, + "SkipParticles_Secondary": false, + "SkipPhotonsMissingPMs": false + }, "TrackingConfig": { "MaxStep": 0.1, "MinEnergy": 0.01, "MinEnergyNeutrons": 0.01, "MinStep": 5e-05, "Safety": 1e-10, - "TrackColorAdd": 0, "dE": 0.05 }, "WaveConfig": { @@ -8595,6 +8653,15 @@ }, "Mode": "PointSim", "ParticleSourcesConfig": { + "GenerationFromFile": { + "FileLastModified": 0, + "FileName": "D:/QtProjects/ANTS2git/ANTS2/build-ants2-Desktop_Qt_5_8_0_MSVC2013_32bit-Release/EXAMPLES/ExampleParticlesFromFile.dat", + "NumEventsInFile": 0, + "RegisteredParticleCount": -1 + }, + "GenerationFromScript": { + "Script": "gen.AddParticle(0, 120, math.gauss(0, 25), math.gauss(0, 25), -20, 0,0,1)\nif (math.random() < 0.1)\n gen.AddParticle(0, 120, math.gauss(0, 25), math.gauss(0, 25), -20, 0,0,1)" + }, "ParticleSources": [ { "Activity": 1, @@ -8614,7 +8681,9 @@ "name": "gamma", "type": 0 }, - "StatWeight": 0.856 + "PreferredUnits": "keV", + "StatWeight": 0.856, + "UseFixedEnergy": true }, { "Energy": 136, @@ -8628,7 +8697,9 @@ "name": "gamma", "type": 0 }, - "StatWeight": 0.1068 + "PreferredUnits": "keV", + "StatWeight": 0.1068, + "UseFixedEnergy": true } ], "LimitedToMaterial": "", @@ -8655,7 +8726,7 @@ "EventsToDo": 10, "IgnoreNoDepoEvents": true, "IgnoreNoHitsEvents": false, - "ParticleTracks": true, + "ParticleGenerationMode": "Sources", "TypeParticlesPerEvent": 0 } }, @@ -8715,7 +8786,7 @@ "MultipleRuns": false, "MultipleRunsNumber": 100, "Primary_Secondary": 1, - "Single_Scan_Flood": 2 + "Single_Scan_Flood": 0 }, "CustomNodesOptions": { "Nodes": [ @@ -9674,7 +9745,7 @@ "Zto": 2.49 }, "PhotPerNodeOptions": { - "PhotPerNodeConstant": 100, + "PhotPerNodeConstant": 50000, "PhotPerNodeCustom": [ ], "PhotPerNodeGaussMean": 10, @@ -9713,7 +9784,7 @@ "ScanZ0": 0 }, "SinglePositionOptions": { - "SingleX": 0, + "SingleX": 50, "SingleY": 0, "SingleZ": 0 }, From 385d33336b828398dfb9f7c9cd8ba3159ec194b1 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 26 Nov 2018 14:06:17 +0000 Subject: [PATCH 134/140] add loadArrayFromWeb --- src/scriptmode/acorescriptinterface.cpp | 43 +++++++++++++++++++++++++ src/scriptmode/acorescriptinterface.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/src/scriptmode/acorescriptinterface.cpp b/src/scriptmode/acorescriptinterface.cpp index 2b73e8ed..97e972cc 100644 --- a/src/scriptmode/acorescriptinterface.cpp +++ b/src/scriptmode/acorescriptinterface.cpp @@ -439,6 +439,49 @@ QVariant ACoreScriptInterface::loadObject(QString fileName) return v; } +#include "ainternetbrowser.h" +QVariant ACoreScriptInterface::loadArrayFromWeb(QString url, int msTimeout) +{ + AInternetBrowser b(msTimeout); + QString Reply; + bool fOK = b.Post(url, "", Reply); + // qDebug() << "Post result:"<LastOpenDir) return QString(); diff --git a/src/scriptmode/acorescriptinterface.h b/src/scriptmode/acorescriptinterface.h index 8b059adf..e1f8c4fe 100644 --- a/src/scriptmode/acorescriptinterface.h +++ b/src/scriptmode/acorescriptinterface.h @@ -59,6 +59,8 @@ public slots: QString loadText(QString fileName); QVariant loadObject(QString fileName); + QVariant loadArrayFromWeb(QString url, int msTimeout = 3000); + //dirs QString GetWorkDir(); QString GetScriptDir(); From 4636371a4930682275adc40fb4cf1d42c71d97f5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 5 Dec 2018 12:56:05 +0000 Subject: [PATCH 135/140] fix crash in gainevaluator; fix gainevaluator gui in sum tab --- src/gui/gainevaluatorwindowclass.cpp | 132 +++++++++++---------------- src/gui/gainevaluatorwindowclass.h | 24 ++--- src/modules/apmgroupsmanager.cpp | 8 +- 3 files changed, 71 insertions(+), 93 deletions(-) diff --git a/src/gui/gainevaluatorwindowclass.cpp b/src/gui/gainevaluatorwindowclass.cpp index 5b2d5290..ed710ad7 100644 --- a/src/gui/gainevaluatorwindowclass.cpp +++ b/src/gui/gainevaluatorwindowclass.cpp @@ -74,17 +74,8 @@ GainEvaluatorWindowClass::GainEvaluatorWindowClass(QWidget *parent, MainWindow * move(50,50); - Equations = 0; - Variables = 0; - tmpHistForLogR = 0; - TMPignore = false; - flagShowNeighbourGroups = false; - flagShowNonLinkedSet = false; - flagAllPMsCovered = false; - flagShowingLinked = false; CenterTopFraction = 0.01 * ui->ledCenterTopFraction->text().toDouble(); CutOffFraction = 0.01 * ui->ledCutOffFraction->text().toDouble(); - CenterGroups.clear(); CenterGroups << CenterGroupClass(30.0, 0.5); ui->pbUpdateLogR->setVisible(false); @@ -96,7 +87,6 @@ GainEvaluatorWindowClass::GainEvaluatorWindowClass(QWidget *parent, MainWindow * QList list = this->findChildren(); foreach(QLineEdit *w, list) if (w->objectName().startsWith("led")) w->setValidator(dv); - iSets4PMs.clear(); ui->tabwid4sets->resizeColumnsToContents(); //icons @@ -105,9 +95,8 @@ GainEvaluatorWindowClass::GainEvaluatorWindowClass(QWidget *parent, MainWindow * ui->labIconWarningCutOffs->setPixmap(RedIcon.pixmap(16,16)); //Graphics view - GVscale = 10.0; scene = new QGraphicsScene(this); - connect(scene, SIGNAL(selectionChanged()), this, SLOT(sceneSelectionChanged())); + connect(scene, &QGraphicsScene::selectionChanged, this, &GainEvaluatorWindowClass::sceneSelectionChanged); gvGains = new myQGraphicsView(this); int gvY = ui->fGV->y() + ui->fGV->height() + 3; gvGains->setGeometry(ui->fGV->x(), gvY, 256, 192); @@ -198,9 +187,8 @@ void GainEvaluatorWindowClass::UpdateEvaluator() iPMs.clear(); for (int i=0; iPMs->count(); i++) if (!MW->Detector->PMgroups->isStaticPassive(i)) - //if (MW->PMs->at(i).group == igroup) - if (MW->Detector->PMgroups->isPmBelongsToGroup(i, CurrentGroup)) - iPMs.append(i); + if (MW->Detector->PMgroups->isPmBelongsToGroup(i, CurrentGroup)) + iPMs.append(i); Variables = iPMs.size(); //all methods - Equations + collecting statistics on PMs and store in dedicated sets Equations = 1; //the only one equation with nonzero "y" value of SVD @@ -1041,7 +1029,7 @@ void GainEvaluatorWindowClass::on_pbEvaluateGains_clicked() //============================== Log ================================= if (ui->cbActivateLogR->isChecked()) { - qDebug()<<"----------!!!--------------"; + //qDebug()<<"----------!!!--------------"; if (ui->cobLogMethodSelection->currentIndex() == 0) { //Log pairs @@ -1054,7 +1042,7 @@ void GainEvaluatorWindowClass::on_pbEvaluateGains_clicked() for (int i2=i1+1; i2 relative gains:"< relative gains:"<( Triads.getTriads()->size() ); for (int iTriad=0; iTriadDetector->PMgroups->setGain(iPMs[i], CurrentGroup, c_svd(i)/max); //reporting gains: - qDebug()<<"-------------------"; - for (int i=0; icbCentersActivate->isChecked(); ui->labPMsCenters->setText(QString::number(iCentersPMs.size())); @@ -1629,7 +1616,7 @@ void GainEvaluatorWindowClass::on_ledCenterTopFraction_editingFinished() void GainEvaluatorWindowClass::on_sbCentersGroupNumber_valueChanged(int arg1) { - if ( arg1>CenterGroups.size() ) + if ( arg1 >= CenterGroups.size() ) { ui->sbCentersGroupNumber->setValue(0); return; //update on_change @@ -1678,7 +1665,7 @@ void GainEvaluatorWindowClass::on_ledCutOffFraction_editingFinished() void GainEvaluatorWindowClass::on_pbUpdate4_clicked() { - qDebug()<<"4Sets: "<cb4Activate->isChecked(); ui->f4->setEnabled( enabled ); @@ -1857,11 +1844,7 @@ void GainEvaluatorWindowClass::UpdateGraphics() //============================ drawing PMs =================================== for (int ipm=0; ipmPMs->count(); ipm++) { - - const APm &PM = MW->PMs->at(ipm); - //if (PM.isStaticPassive()) continue; - //if (igroup != -1) if ( PM.group != igroup ) continue; //wrong group //PM object pen QPen pen(Qt::black); @@ -1872,7 +1855,6 @@ void GainEvaluatorWindowClass::UpdateGraphics() QBrush brush(Qt::white); //default color bool fVisible; - //if (PM.isStaticPassive() || (igroup != -1) && ( PM.group != igroup ) ) if (MW->Detector->PMgroups->isStaticPassive(ipm) || !MW->Detector->PMgroups->isPmBelongsToGroup(ipm, CurrentGroup) ) { fVisible = false; @@ -1961,7 +1943,6 @@ void GainEvaluatorWindowClass::UpdateGraphics() tmp->setRotation(-PM.psi); tmp->setTransform(QTransform().translate(PM.x*GVscale, -PM.y*GVscale)); //minus!!!! - //if (PM.isStaticPassive() || (igroup != -1) && ( PM.group != igroup ) ) ;//unclickable! if (MW->Detector->PMgroups->isStaticPassive(ipm) || !MW->Detector->PMgroups->isPmBelongsToGroup(ipm, CurrentGroup) ) ;//unclickable! else tmp->setFlag(QGraphicsItem::ItemIsSelectable); @@ -2033,7 +2014,6 @@ void GainEvaluatorWindowClass::UpdateGraphics() for (int ipm=0; ipmPMs->count(); ipm++) { if (MW->Detector->PMgroups->isStaticPassive(ipm)) continue; //no static passives! - //if ( MW->PMs->at(ipm).group != igroup ) continue; //wrong group if ( !MW->Detector->PMgroups->isPmBelongsToGroup(ipm, CurrentGroup) ) continue; //wrong group QGraphicsTextItem * io = new QGraphicsTextItem(); @@ -2137,7 +2117,7 @@ void GainEvaluatorWindowClass::sceneSelectionChanged() ipm = PMicons.indexOf(pointer); if (ipm == -1) { - qDebug()<<" --ipm not found!"; + qWarning() << " --ipm not found!"; return; } //qDebug()<<" -- ipm = "<MW->PMs->count()-1) return; if (isPMDistanceCheckFail(ipm1, ipm2)) - { - qDebug()<<"warning: distance check fail!"; - } + qWarning() << "warning: distance check fail!"; GainEvaluatorWindowClass::AdjustGainPair(ipm1, ipm2); } @@ -2372,8 +2350,8 @@ double GainEvaluatorWindowClass::AdjustGainPair(int ipm1, int ipm2) //----automa } double ratio; if (larger2>0) ratio = 1.0*larger1/larger2; else ratio = 1.0; -/// qDebug()<<"-------"; -/// qDebug()<<"larger1, larger2:"<AddPolygonfToGeometry(circ1, 3, 2); -/// MW->AddPolygonfToGeometry(circ2, 4, 2); +// qDebug()<<"\n\nCircles around ipm1 and ipm2:"<AddPolygonfToGeometry(circ1, 3, 2); +// MW->AddPolygonfToGeometry(circ2, 4, 2); //creating polygons for illuminated area split by the middle line QPolygonF illum1, illum2; //on start dont know which one belongs to which pm! @@ -2450,9 +2428,9 @@ double GainEvaluatorWindowClass::CalculateAreaFraction(int ipm1, int ipm2) //ret QLineF radius2(QPointF(0,0), SecondPointOnCircle); double endAngle = radius2.angle(); //in degrees! if (endAngleAddLineToGeometry(QPointF(0,0), FirstPointOnCircle); -/// MW->AddLineToGeometry(QPointF(0,0), SecondPointOnCircle); +// qDebug()<<"\n\nStart and end angles:"<AddLineToGeometry(QPointF(0,0), FirstPointOnCircle); +// MW->AddLineToGeometry(QPointF(0,0), SecondPointOnCircle); //filling polygons //finding angular step per sector startAngle *= 3.1415926/180.0; @@ -2473,33 +2451,33 @@ double GainEvaluatorWindowClass::CalculateAreaFraction(int ipm1, int ipm2) //ret if (illum2.containsPoint( QPointF(MW->PMs->X(ipm1), MW->PMs->Y(ipm1) ), Qt::OddEvenFill)) { //have to swap! -/// qDebug()<<"swapping illum1 and illum2!"; +// qDebug()<<"swapping illum1 and illum2!"; illum1.swap(illum2); } -/// qDebug()<<"\n\nIllum1 and illum2:"<AddPolygonfToGeometry(illum1, 3, 2); -/// MW->AddPolygonfToGeometry(illum2, 4, 2); +// qDebug()<<"\n\nIllum1 and illum2:"<AddPolygonfToGeometry(illum1, 3, 2); +// MW->AddPolygonfToGeometry(illum2, 4, 2); //overlaping polygons circ1 = circ1.intersected(illum1); circ2 = circ2.intersected(illum2); -/// qDebug()<<"\n\nIntersected results for ipm1 and ipm2:"<ShowGeometry(); -/// MW->GeoManager->DrawTracks(); -/// MW->GeometryWindow->UpdateRootCanvas(); -/// MW->GeometryWindow->raise(); +// MW->ShowGeometry(); +// MW->GeoManager->DrawTracks(); +// MW->GeometryWindow->UpdateRootCanvas(); +// MW->GeometryWindow->raise(); return area1/area2; } @@ -2531,7 +2509,7 @@ double GainEvaluatorWindowClass::AdjustGainPairLogR(int ipm1, int ipm2) } double av = tmpHistForLogR->GetMean(); - qDebug()<<"av:"< iPMs; //indeces of all PMs to be used in gain reconstruction QList iCutOffPMs; //indeces of PMs to be used in CutOffs gain eval procedure QList iCentersPMs; //indeces of PMs to be used in CutOffs gain eval procedure @@ -201,24 +201,24 @@ private slots: QString Overlap4PMs; double Tolerance4PMs; - QGraphicsScene *scene; - myQGraphicsView *gvGains; - double GVscale; + QGraphicsScene *scene = 0; + myQGraphicsView *gvGains = 0; + double GVscale = 10.0; QVector PMicons; QList SelectedPMsFor4Set; //tmp set used to draw new 4pm set QVector< QSet > SetNeighbour; //all neigbours by group QVector< QSet > AllLinks; //link between all PMs - used in check of all PM coverage; - bool flagShowNeighbourGroups; - bool flagAllPMsCovered; + bool flagShowNeighbourGroups = false; + bool flagAllPMsCovered = false; QSet firstUncoveredSet; - bool flagShowingLinked; - bool flagShowNonLinkedSet; + bool flagShowingLinked = false; + bool flagShowNonLinkedSet = false; QIcon RedIcon, GreenIcon; - TH1D *tmpHistForLogR; + TH1D *tmpHistForLogR = 0; FlatField Triads; diff --git a/src/modules/apmgroupsmanager.cpp b/src/modules/apmgroupsmanager.cpp index 7a3ff023..fc2e2974 100644 --- a/src/modules/apmgroupsmanager.cpp +++ b/src/modules/apmgroupsmanager.cpp @@ -21,14 +21,14 @@ APmGroupsManager::~APmGroupsManager() void APmGroupsManager::setCurrentGroup(int iGroup) { - if (iGroup<0 || iGroup>Groups.size()-1) return; + if (iGroup < 0 || iGroup >= Groups.size()) return; CurrentGroup = iGroup; emit CurrentSensorGroupChanged(); //Gain evaluator gui is listening } const QString APmGroupsManager::getGroupName(int iGroup) const { - if (iGroup > Groups.size()-1) return ""; + if (iGroup < 0 || iGroup >= Groups.size()) return ""; return Groups.at(iGroup)->Name; } @@ -244,8 +244,8 @@ bool APmGroupsManager::removeGroup(int igroup) bool APmGroupsManager::isPmBelongsToGroup(int ipm, int igroup) const { - if (igroup>Groups.size()-1) return false; - if (ipm>PMs->count()-1) return false; + if (igroup < 0 || igroup >= Groups.size()) return false; + if (ipm < 0 || ipm >= PMs->count()) return false; if (Groups.at(igroup)->PMS.isEmpty()) return false; return Groups.at(igroup)->PMS.at(ipm).member; From 604237fe50bde2fdbf02ea638e7cbb409e24fa9e Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 12 Dec 2018 13:44:40 +0000 Subject: [PATCH 136/140] add functionality to control relative QE factors in GUI --- src/gui/mainwindow.cpp | 72 +++++++++--- src/gui/mainwindow.h | 6 + src/gui/mainwindow.ui | 255 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 301 insertions(+), 32 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index e613d7a4..551d6aca 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -2012,11 +2012,8 @@ void MainWindow::on_ledIndEffectiveDE_editingFinished() void MainWindow::on_pbIndRestoreEffectiveDE_clicked() { const int ipm = ui->sbIndPMnumber->value(); - PMs->at(ipm).effectivePDE = -1.0; - ReconstructDetector(true); - //MainWindow::on_pbIndPMshowInfo_clicked(); } void MainWindow::on_pbIndShowDE_clicked() @@ -2040,7 +2037,6 @@ void MainWindow::on_pbIndRestoreDE_clicked() PMs->at(ipm).PDEbinned.clear(); ReconstructDetector(true); - //MainWindow::on_pbIndPMshowInfo_clicked(); } void MainWindow::on_pbIndLoadDE_clicked() @@ -3223,11 +3219,6 @@ void MainWindow::ViewChangeRelFactors(QString options) tw->setItemDelegate(new TableDoubleDelegateClass(tw)); //accept only doubles - //tw->resizeColumnsToContents(); - //tw->resizeRowsToContents(); - //tw->setColumnWidth(0, 56); - //tw->setColumnWidth(1, 56); - QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(tw); mainLayout->addLayout(buttonsLayout); @@ -3238,7 +3229,7 @@ void MainWindow::ViewChangeRelFactors(QString options) if (result == 1) { - Detector->PMs->setDoPHS( true ); + Detector->PMs->setDoPHS( true ); // *** should be in "EL" ? if (options == "QE") { //updating data @@ -3309,6 +3300,19 @@ void MainWindow::on_pbLoadRelQEfactors_clicked() ReconstructDetector(true); } +void MainWindow::on_pbClearRelQEfactors_clicked() +{ + for (int ipm = 0; ipm < PMs->count(); ipm++) + { + PMs->at(ipm).effectivePDE = -1.0; + + PMs->at(ipm).PDE.clear(); + PMs->at(ipm).PDE_lambda.clear(); + PMs->at(ipm).PDEbinned.clear(); + } + ReconstructDetector(true); +} + void MainWindow::on_pbLoadRelELfactors_clicked() { QString fileName = QFileDialog::getOpenFileName(this, "Load relative strength of electronic channels", GlobSet.LastOpenDir, "Data files (*.dat);;Text files (*.txt);;All files (*)"); @@ -3365,16 +3369,52 @@ void MainWindow::on_pbRandomScaleELaverages_clicked() ReconstructDetector(true); } +void MainWindow::on_pbRelQERandomScaleELaverages_clicked() +{ + bool bUniform = ( ui->cobRelQEScaleGainsUniNorm->currentIndex() == 0 ); + double min = ui->ledRelQEELavScaleMin->text().toDouble(); + double max = ui->ledRelQEELavScaleMax->text().toDouble(); + if (bUniform && min >= max) return; + double mean = ui->ledRelQEELavScaleMean->text().toDouble(); + double sigma = ui->ledRelQEELavScaleSigma->text().toDouble(); + + for (int ipm = 0; ipm < PMs->count(); ipm++) + { + double factor; + if (bUniform) + { + factor = Detector->RandGen->Rndm(); + factor = min + (max-min)*factor; + } + else + factor = Detector->RandGen->Gaus(mean, sigma); + + PMs->at(ipm).relQE_PDE = factor; + } + + CalculateIndividualQEPDE(); + ReconstructDetector(true); +} + +void MainWindow::on_pbRelQESetELaveragesToUnity_clicked() +{ + double val = ui->ledRelQEvalue->text().toDouble(); + for (int ipm = 0; ipm < PMs->count(); ipm++) + PMs->at(ipm).relQE_PDE = val; + + CalculateIndividualQEPDE(); + ReconstructDetector(true); +} + void MainWindow::on_pbSetELaveragesToUnity_clicked() { - //ui->cbEnableSPePHS->setChecked(true); - Detector->PMs->setDoPHS( true ); + Detector->PMs->setDoPHS( true ); - for (int ipm = 0; ipmcount(); ipm++) - PMs->at(ipm).scaleSPePHS(1.0); + double val = ui->ledELEvalue->text().toDouble(); + for (int ipm = 0; ipmcount(); ipm++) + PMs->at(ipm).scaleSPePHS(val); - ReconstructDetector(true); - //MainWindow::on_pbElUpdateIndication_clicked(); + ReconstructDetector(true); } void MainWindow::on_pbShowRelGains_clicked() diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 19f64ecd..6343bfd6 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -621,6 +621,12 @@ private slots: void on_pteParticleGenerationScript_customContextMenuRequested(const QPoint &pos); + void on_pbClearRelQEfactors_clicked(); + + void on_pbRelQERandomScaleELaverages_clicked(); + + void on_pbRelQESetELaveragesToUnity_clicked(); + public slots: void on_pbRebuildDetector_clicked(); void onRequestDetectorGuiUpdate(); // called to update GUI related to Detector diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index cd779282..7de29e34 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 1 + 0 @@ -4680,22 +4680,22 @@ of the refracted beam: - 61 + 120 64 - 121 + 120 23 - Load relative factors + Load factors - 41 + 10 33 - 171 + 230 23 @@ -4703,6 +4703,215 @@ of the refracted beam: View / change relative factors + + + + 10 + 64 + 100 + 23 + + + + Use base properties of the type for all PMs + + + Use PM type + + + + + + 20 + 87 + 211 + 16 + + + + Qt::Horizontal + + + + + + 10 + 179 + 170 + 23 + + + + Set all gains to: + + + + + + 10 + 100 + 81 + 31 + + + + Randomize + + + + + + 100 + 103 + 130 + 22 + + + + + Uniform + + + + + Normal + + + + + + + 103 + 130 + 130 + 48 + + + + 1 + + + + + + 50 + 24 + 50 + 20 + + + + 2 + + + + + + 50 + 2 + 50 + 20 + + + + 0.5 + + + + + + 10 + 6 + 35 + 13 + + + + min: + + + + + + 10 + 25 + 35 + 13 + + + + max: + + + + + + + + 50 + 2 + 50 + 20 + + + + 1 + + + + + + 50 + 24 + 50 + 20 + + + + 0.2 + + + + + + 0 + 6 + 48 + 13 + + + + mean: + + + + + + 0 + 25 + 48 + 13 + + + + sigma: + + + + + + + + 190 + 180 + 50 + 20 + + + + 1.0 + + @@ -4741,9 +4950,9 @@ of the refracted beam: - 40 + 9 33 - 171 + 230 23 @@ -4754,14 +4963,14 @@ of the refracted beam: - 65 + 70 64 - 121 + 120 23 - Load relative factors + Load factors @@ -4795,19 +5004,19 @@ of the refracted beam: 10 179 - 232 + 170 23 - Set all gains to 1 + Set all gains to: 100 - 101 + 103 130 22 @@ -4827,13 +5036,13 @@ of the refracted beam: 103 - 126 + 130 130 48 - 0 + 1 @@ -4944,6 +5153,19 @@ of the refracted beam: + + + + 190 + 180 + 50 + 20 + + + + 1.0 + + label_35 pbViewChangeRelELfactors pbLoadRelELfactors @@ -4952,6 +5174,7 @@ of the refracted beam: pbRandomScaleELaverages cobScaleGainsUniNorm swGainUniNorm + ledELEvalue From 5de62c40be485328ce20fbf57f9dc7762d249512 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 12 Dec 2018 13:46:58 +0000 Subject: [PATCH 137/140] ++ --- src/gui/mainwindow.ui | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 7de29e34..84d2c967 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -4788,7 +4788,7 @@ of the refracted beam: - 1 + 0 @@ -5042,7 +5042,7 @@ of the refracted beam: - 1 + 0 From 27ac0d009c0146fb4e8e9ec1284e579eeaa58f75 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 20 Jan 2019 13:19:48 +0000 Subject: [PATCH 138/140] gui script: add setMax and Min size and tooltip --- src/scriptmode/ainterfacetoguiscript.cpp | 49 ++++++++++++++++++++++++ src/scriptmode/ainterfacetoguiscript.h | 8 ++++ 2 files changed, 57 insertions(+) diff --git a/src/scriptmode/ainterfacetoguiscript.cpp b/src/scriptmode/ainterfacetoguiscript.cpp index 599b39b3..926a11d1 100644 --- a/src/scriptmode/ainterfacetoguiscript.cpp +++ b/src/scriptmode/ainterfacetoguiscript.cpp @@ -554,6 +554,41 @@ void AInterfaceToGuiScript::checkboxOnClick(const QString name, const QVariant s [=]() { ScriptManager->getProperty(functionName).call(); ScriptManager->ifError_AbortAndReport(); } ); } +void AInterfaceToGuiScript::setMinimumWidth(const QString name, int min) +{ + QWidget* w = Widgets.value(name, 0); + if (!w) abort("Widget " + name + " does not exist"); + else w->setMinimumWidth(min); +} + +void AInterfaceToGuiScript::setMinimumHeight(const QString name, int min) +{ + QWidget* w = Widgets.value(name, 0); + if (!w) abort("Widget " + name + " does not exist"); + else w->setMinimumHeight(min); +} + +void AInterfaceToGuiScript::setMaximumWidth(const QString name, int max) +{ + QWidget* w = Widgets.value(name, 0); + if (!w) abort("Widget " + name + " does not exist"); + else w->setMaximumWidth(max); +} + +void AInterfaceToGuiScript::setMaximumHeight(const QString name, int max) +{ + QWidget* w = Widgets.value(name, 0); + if (!w) abort("Widget " + name + " does not exist"); + else w->setMaximumHeight(max); +} + +void AInterfaceToGuiScript::setToolTip(const QString name, const QString text) +{ + QWidget* w = Widgets.value(name, 0); + if (!w) abort("Widget " + name + " does not exist"); + else w->setToolTip(text); +} + void AInterfaceToGuiScript::addStretch(const QString addTo) { QLayout* lay = Layouts.value(addTo, 0); @@ -585,6 +620,20 @@ void AInterfaceToGuiScript::addHoizontalLine(const QString addTo) lay->addWidget(e); } +void AInterfaceToGuiScript::addVerticalLine(const QString addTo) +{ + QLayout* lay = Layouts.value(addTo, 0); + if (!lay) + { + abort("Layout " + addTo + " does not exist"); + return; + } + QFrame* e = new QFrame; + e->setFrameShape(QFrame::VLine); + e->setFrameShadow(QFrame::Raised); + lay->addWidget(e); +} + void AInterfaceToGuiScript::verticalLayout(const QString name, const QString addTo) { if (Layouts.contains(name)) diff --git a/src/scriptmode/ainterfacetoguiscript.h b/src/scriptmode/ainterfacetoguiscript.h index 9576bf22..676fc11c 100644 --- a/src/scriptmode/ainterfacetoguiscript.h +++ b/src/scriptmode/ainterfacetoguiscript.h @@ -56,8 +56,16 @@ public slots: bool checkboxIsChecked(const QString name); void checkboxOnClick(const QString name, const QVariant scriptFunction); + void setMinimumWidth(const QString name, int min); + void setMinimumHeight(const QString name, int min); + void setMaximumWidth(const QString name, int max); + void setMaximumHeight(const QString name, int max); + + void setToolTip(const QString name, const QString text); + void addStretch(const QString addTo); void addHoizontalLine(const QString addTo); + void addVerticalLine(const QString addTo); void verticalLayout(const QString name, const QString addTo); void horizontalLayout(const QString& name, const QString& addTo); From 169740ddf3a412246e9acbfcbcf0832d0e9969ef Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 20 Jan 2019 13:49:11 +0000 Subject: [PATCH 139/140] add possibility to launch external process from core script unit (requires enable in ants2.pro) --- src/ants2.pro | 3 ++ src/scriptmode/acorescriptinterface.cpp | 51 +++++++++++++++++++++++++ src/scriptmode/acorescriptinterface.h | 2 + 3 files changed, 56 insertions(+) diff --git a/src/ants2.pro b/src/ants2.pro index d6f1a57d..b24b4ba1 100644 --- a/src/ants2.pro +++ b/src/ants2.pro @@ -779,6 +779,9 @@ TEMPLATE = app RC_FILE = myapp.rc #------------ +# The next define allows the core script interface to launch external processes. Enable only if you know what are you doing +#DEFINES += _ALLOW_LAUNCH_EXTERNAL_PROCESS_ + #---Optimization of compilation--- win32 { #when the next two lines are NOT commented, optimization during compilation is disabled. It will drastically shorten compilation time on MSVC2013, but there are performance loss, especially strong for LRF computation diff --git a/src/scriptmode/acorescriptinterface.cpp b/src/scriptmode/acorescriptinterface.cpp index 97e972cc..ca68470a 100644 --- a/src/scriptmode/acorescriptinterface.cpp +++ b/src/scriptmode/acorescriptinterface.cpp @@ -6,6 +6,10 @@ #include "curvefit.h" #endif +#ifdef _ALLOW_LAUNCH_EXTERNAL_PROCESS_ +#include +#endif + #include #include #include @@ -641,3 +645,50 @@ bool ACoreScriptInterface::setCirrentDir(QString path) { return QDir::setCurrent(path); } + +const QString ACoreScriptInterface::StartExternalProcess(QString command, QVariant argumentArray, bool waitToFinish, int milliseconds) +{ +#ifndef _ALLOW_LAUNCH_EXTERNAL_PROCESS_ + abort("Launch of external process is not allowed.\nEnable \"_ALLOW_LAUNCH_EXTERNAL_PROCESS_\" in ants2.pro"); + return ""; +#else + QStringList arg; + QString type = argumentArray.typeName(); + if (type == "QString") arg << argumentArray.toString(); + else if (type == "int") arg << QString::number(argumentArray.toInt()); + else if (type == "double") arg << QString::number(argumentArray.toDouble()); + else if (type == "QVariantList") + { + QVariantList vl = argumentArray.toList(); + QJsonArray ar = QJsonArray::fromVariantList(vl); + for (int i=0; istart(command, arg); + process->waitForFinished(milliseconds); + errorString = process->errorString(); + delete process; + } + else + { + QObject::connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater())); + process->start(command, arg); + } + + return errorString; +#endif // ANTS2_ALLOW_EXTERNAL_PROCESS +} diff --git a/src/scriptmode/acorescriptinterface.h b/src/scriptmode/acorescriptinterface.h index e1f8c4fe..96cd3f80 100644 --- a/src/scriptmode/acorescriptinterface.h +++ b/src/scriptmode/acorescriptinterface.h @@ -78,6 +78,8 @@ public slots: double getFitted(double x); const QVariant getFittedArr(const QVariant array); + const QString StartExternalProcess(QString command, QVariant arguments, bool waitToFinish, int milliseconds); + private: AScriptManager* ScriptManager; From e76fb6318033c6ec32a2569210116832c597cfb9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Sun, 3 Feb 2019 16:07:41 +0000 Subject: [PATCH 140/140] fix basket save for vsXY with PMs + tweak to ui for gauss fit --- src/gui/graphwindowclass.cpp | 14 +++++++++----- src/gui/graphwindowclass.ui | 21 +++++++++++++++++++-- src/gui/reconstructionwindow.cpp | 15 +++++++++------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/gui/graphwindowclass.cpp b/src/gui/graphwindowclass.cpp index e24e3bb4..8cca6f6e 100644 --- a/src/gui/graphwindowclass.cpp +++ b/src/gui/graphwindowclass.cpp @@ -3207,7 +3207,8 @@ void GraphWindowClass::SaveBasket() TString name = ""; name += index; index++; - ((TNamed*)Basket[ib].DrawObjects[i].getPointer())->SetName(name); + TNamed* no = dynamic_cast(Basket[ib].DrawObjects[i].getPointer()); + if (no) no->SetName(name); Basket[ib].DrawObjects[i].getPointer()->Write(); str += "|"+Basket[ib].DrawObjects[i].getOptions(); } @@ -3741,10 +3742,13 @@ void GraphWindowClass::on_pbFWHM_clicked() Draw(f, "same"); //draw base line - TF1 *fl = new TF1("line", "pol2", startX, stopX); - fl->SetLineStyle(2); - fl->SetParameters(c/b, -a/b); - Draw(fl, "same"); + if (ui->cbShowBaseLine->isChecked()) + { + TF1 *fl = new TF1("line", "pol2", startX, stopX); + fl->SetLineStyle(2); + fl->SetParameters(c/b, -a/b); + Draw(fl, "same"); + } //draw panel with results ShowTextPanel("fwhm = " + QString::number(FWHM) + "\nmean = " + QString::number(mid) + "\nfwhm/mean = "+QString::number(rel)); diff --git a/src/gui/graphwindowclass.ui b/src/gui/graphwindowclass.ui index 283b0b08..163abcd7 100644 --- a/src/gui/graphwindowclass.ui +++ b/src/gui/graphwindowclass.ui @@ -707,7 +707,7 @@ 10 - 421 + 434 131 23 @@ -726,7 +726,7 @@ -2 - 414 + 429 150 3 @@ -752,6 +752,22 @@ Click-drag-release selects the base line and the range of the fit. Extract fwhm/mean + + + + 23 + 410 + 111 + 17 + + + + Show base line + + + true + + line line_2 fLog @@ -777,6 +793,7 @@ Click-drag-release selects the base line and the range of the fit. pbAddToBasket line_15 pbFWHM + cbShowBaseLine diff --git a/src/gui/reconstructionwindow.cpp b/src/gui/reconstructionwindow.cpp index f0d6d069..f24ba754 100644 --- a/src/gui/reconstructionwindow.cpp +++ b/src/gui/reconstructionwindow.cpp @@ -726,7 +726,7 @@ void ReconstructionWindow::on_pbShowSumSignal_clicked() hist1D->SetXTitle("Sum signal"); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) - hist1D->SetBit(TH1::kCanRebin); + if (!ui->cbFilterSumSignal->isChecked()) hist1D->SetBit(TH1::kCanRebin); #endif int counter = 0; @@ -813,7 +813,7 @@ void ReconstructionWindow::ShowIndividualSpectrum(bool focus) hist1D->SetXTitle("Signal"); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) - hist1D->SetBit(TH1::kCanRebin); + if (!ui->cbFilterIndividualSignals->isChecked()) hist1D->SetBit(TH1::kCanRebin); #endif int counter = 0; @@ -1198,7 +1198,7 @@ void ReconstructionWindow::ShowEnergySpectrum() auto hist1D = new TH1D("hist1ShEnSp","Energy spectrum", MW->GlobSet.BinsX, 0, 0); #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) - hist1D->SetBit(TH1::kCanRebin); + if (!ui->cbActivateEnergyFilter->isChecked()) hist1D->SetBit(TH1::kCanRebin); #endif for (int i=0; iReconstructionData[CurrentGroup].size(); i++) @@ -1251,10 +1251,11 @@ void ReconstructionWindow::ShowChi2Spectrum() return; } - auto hist1D = new TH1D("hist1Chi2Dis","Chi2 distribution", MW->GlobSet.BinsX, 0, 0); + auto hist1D = new TH1D("hist1Chi2Dis","Chi2 distribution", MW->GlobSet.BinsX, 0, 0); hist1D->SetXTitle("Chi2"); + #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) - hist1D->SetBit(TH1::kCanRebin); + if (!ui->cbActivateChi2Filter->isChecked()) hist1D->SetBit(TH1::kCanRebin); #endif for (int i=0; iReconstructionData[CurrentGroup].size(); i++) @@ -3376,9 +3377,11 @@ void ReconstructionWindow::on_pbLoadEnergySpectrum_clicked() auto hist1D = new TH1D("hist1ShLoEnSp","True/loaded energy", MW->GlobSet.BinsX, 0, 0); hist1D->SetXTitle("True or loaded energy"); + #if ROOT_VERSION_CODE < ROOT_VERSION(6,0,0) - hist1D->SetBit(TH1::kCanRebin); + if (!ui->cbActivateLoadedEnergyFilter->isChecked()) hist1D->SetBit(TH1::kCanRebin); #endif + //check filter status only of reconstruction has been done bool DoFiltering = false; if (!EventsDataHub->isReconstructionDataEmpty()) DoFiltering = true;