~maus-release/maus/release

« back to all changes in this revision

Viewing changes to src/utilities/event-viewer/mainwindow.cpp

  • Committer: Paolo Franchini
  • Date: 2018-06-24 14:27:26 UTC
  • mfrom: (659.2.80 release-candidate)
  • Revision ID: p.franchini@warwick.ac.uk-20180624142726-nbxxyjyer146dr1t
Tags: MAUS-v3.2.0
MAUS-v3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "mainwindow.h"
2
2
#include "ui_mainwindow.h"
3
 
//#include "HepRepXMLWriter.h"
4
3
 
5
4
#include "JsonCppStreamer/IRStream.hh"
6
5
 
22
21
    dummyValue = 5673390;
23
22
 
24
23
    initFile = QApplication::applicationDirPath() + "/ev.ini";
25
 
    std::cout << initFile.toStdString() << std::endl;
26
24
    LoadInitValues();
27
25
}
28
26
 
69
67
    connect(ui->btn_JavaDir, SIGNAL(clicked()), SLOT(choose_java_dir()));
70
68
    connect(ui->btn_HeprappDir, SIGNAL(clicked()), SLOT(choose_heprapp_dir()));
71
69
 
 
70
    connect(ui->btn_DetectorGeometryPath, SIGNAL(clicked()), SLOT(choose_detgeom_path()));
 
71
 
 
72
    // ToDo: replace "choose" in all slot names with "select" - just cosmetics
 
73
 
72
74
 
73
75
    settings_window = new Settings();
74
76
    read_settings();
84
86
    outputDirName = settings.value("outputDirName", "").toString();
85
87
    javaDirName = settings.value("javaDirName", "").toString();
86
88
    heprappDirName = settings.value("heprappDirName", "").toString();
 
89
    detGeomFilesPath = settings.value("detGeomFilesPath", "").toString();
87
90
 
88
91
}
89
92
 
102
105
    settings.setValue("outputDirName", outputDirName);
103
106
    settings.setValue("javaDirName", javaDirName);
104
107
    settings.setValue("heprappDirName", heprappDirName);
 
108
    settings.setValue("detGeomFilesPath", detGeomFilesPath);
105
109
}
106
110
 
107
111
void MainWindow::open_settings(){
234
238
    setenv("EV_HEPRAPP_DIR", heprappDirName.toStdString().c_str(), 1);
235
239
}
236
240
 
 
241
void MainWindow::choose_detgeom_path()
 
242
{
 
243
    QStringList filenames;
 
244
    QFileDialog dialog(this);
 
245
    dialog.setDirectory(detGeomFilesPath);
 
246
    dialog.setFileMode(QFileDialog::Directory);
 
247
    dialog.setViewMode(QFileDialog::Detail);
 
248
    if(dialog.exec()){
 
249
        filenames = dialog.selectedFiles();
 
250
        if(!filenames.empty()) {
 
251
            detGeomFilesPath = filenames.first();
 
252
            ui->line_DetectorGeometryPath->setText(detGeomFilesPath);
 
253
        }
 
254
    }
 
255
 
 
256
    setenv("EV_GEOM_HOME", detGeomFilesPath.toStdString().c_str(), 1);
 
257
}
 
258
 
237
259
void MainWindow::read_settings(){
238
260
    QVector<double> tof0_location = settings_window->GetTOF0Settings();
239
261
    QVector<double> tof1_location = settings_window->GetTOF1Settings();
958
980
    // plot straight tracks
959
981
    QCPItemLine* upstream_track_xz = static_cast<QCPItemLine*>(ui->plot_position_xz->item(0));
960
982
    upstream_track_xz->setPen(QPen(Qt::red));
961
 
    upstream_track_xz->start->setCoords(dummyValue, dummyValue);
962
 
    upstream_track_xz->end->setCoords(dummyValue, dummyValue);
963
983
    QCPItemLine* downstream_track_xz = static_cast<QCPItemLine*>(ui->plot_position_xz->item(1));
964
984
    downstream_track_xz->setPen(QPen(Qt::blue));
965
 
    downstream_track_xz->start->setCoords(dummyValue, dummyValue);
966
 
    downstream_track_xz->end->setCoords(dummyValue, dummyValue);
967
985
 
968
986
    upstream_track_xz->start->setCoords(evEvent.scifiUSTrackerStraightTrackPoints.at(0).z(), evEvent.scifiUSTrackerStraightTrackPoints.at(0).x());
969
987
    upstream_track_xz->end->setCoords(evEvent.scifiUSTrackerStraightTrackPoints.at(1).z(), evEvent.scifiUSTrackerStraightTrackPoints.at(1).x());
989
1007
    ui->plot_position_yz->replot();
990
1008
 
991
1009
 
 
1010
 
 
1011
 
 
1012
    // plot helical tracks
 
1013
 
 
1014
    // - load parent geometry mice module (needed for helical track transformations)
 
1015
    std::stringstream modulePath;
 
1016
    if (getenv("EV_GEOM_HOME"))
 
1017
        modulePath << getenv("EV_GEOM_HOME") << "/ParentGeometryFile.dat";
 
1018
    else
 
1019
        modulePath << getenv("MAUS_ROOT_DIR") << "/files/geometry/download/ParentGeometryFile.dat";
 
1020
 
 
1021
    // - Adam's fix (redirecting stdout/stderr)
 
1022
    std::ostream* stdout = new std::ofstream();
 
1023
    stdout->rdbuf(std::cout.rdbuf());
 
1024
    std::ostream* stderr = new std::ofstream();
 
1025
    stderr->rdbuf(std::cerr.rdbuf());
 
1026
 
 
1027
    try {
 
1028
        mm = new MiceModule(modulePath.str());
 
1029
        std::cout.rdbuf(stdout->rdbuf());
 
1030
        std::cerr.rdbuf(stderr->rdbuf());
 
1031
    } catch(MAUS::Exceptions::Exception e) {
 
1032
        std::cerr << "Caught exception while building MiceModules" << std::endl;
 
1033
        e.what();
 
1034
        e.Print();
 
1035
        modulePath.str("");
 
1036
        // this file should be included in the release so no try/catch neccessary
 
1037
        modulePath << getenv("MAUS_ROOT_DIR") << "/src/utilities/event-viewer/ParentGeometryFile.dat";
 
1038
        mm = new MiceModule(modulePath.str());
 
1039
        std::cout.rdbuf(stdout->rdbuf());
 
1040
        std::cerr.rdbuf(stderr->rdbuf());
 
1041
    }
 
1042
 
 
1043
    // --- fetch US tracker global geometry
 
1044
    mmTrackerUS = mm->findModulesByName ("ParentGeometryFile.dat/Tracker0.dat");
 
1045
 
 
1046
    // - get TrackerRef0 position
 
1047
    double trackerRef0posX = mmTrackerUS[0]->daughter(0)->globalPosition().x();
 
1048
    double trackerRef0posY = mmTrackerUS[0]->daughter(0)->globalPosition().y();
 
1049
    double trackerRef0posZ = mmTrackerUS[0]->daughter(0)->globalPosition().z();
 
1050
 
 
1051
    // - get rotation matrix
 
1052
    double xx = mmTrackerUS[0]->globalRotation().xx();
 
1053
    double xy = mmTrackerUS[0]->globalRotation().xy();
 
1054
    double xz = mmTrackerUS[0]->globalRotation().xz();
 
1055
    double yx = mmTrackerUS[0]->globalRotation().yx();
 
1056
    double yy = mmTrackerUS[0]->globalRotation().yy();
 
1057
    double yz = mmTrackerUS[0]->globalRotation().yz();
 
1058
    double zx = mmTrackerUS[0]->globalRotation().zx();
 
1059
    double zy = mmTrackerUS[0]->globalRotation().zy();
 
1060
    double zz = mmTrackerUS[0]->globalRotation().zz();
 
1061
 
 
1062
    // - fill matrix elements (for VectorTransform)
 
1063
    std::vector<double> matrixElements;
 
1064
    matrixElements.push_back(xx);
 
1065
    matrixElements.push_back(xy);
 
1066
    matrixElements.push_back(xz);
 
1067
    matrixElements.push_back(yx);
 
1068
    matrixElements.push_back(yy);
 
1069
    matrixElements.push_back(yz);
 
1070
    matrixElements.push_back(zx);
 
1071
    matrixElements.push_back(zy);
 
1072
    matrixElements.push_back(zz);
 
1073
 
 
1074
    // - dimensions (y coordinate is length)
 
1075
    Hep3Vector dimensions = mmTrackerUS[0]->dimensions();
 
1076
    double trackerLength = dimensions.y();
 
1077
 
 
1078
    // - plot upstream helical track
 
1079
    QCPCurve upstream_helix_xz_plane(ui->plot_position_xz->xAxis, ui->plot_position_xz->yAxis);
 
1080
    QCPCurve upstream_helix_yz_plane(ui->plot_position_yz->xAxis, ui->plot_position_yz->yAxis);
 
1081
    QVector<double> upstream_helix_x, upstream_helix_y, upstream_helix_z; // vectors to hold z coordinates array and coresponding values from projections to XZ and YZ planes
 
1082
    double circle_x0 = evEvent.scifiUSTrackerHelicalTrackParameters[0];
 
1083
    double circle_y0 = evEvent.scifiUSTrackerHelicalTrackParameters[1];
 
1084
    double radius = evEvent.scifiUSTrackerHelicalTrackParameters[2];
 
1085
    double dsdz = evEvent.scifiUSTrackerHelicalTrackParameters[3];
 
1086
    double line_dz_c = evEvent.scifiUSTrackerHelicalTrackParameters[4];
 
1087
    double posZ = evEvent.scifiUSTrackerHelicalTrackParameters[7];
 
1088
 
 
1089
    double zUSLocal = posZ;
 
1090
    int zStep = trackerLength/300;
 
1091
    while (zUSLocal < trackerLength) {
 
1092
        zUSLocal += zStep; // z value in tracker local reference system
 
1093
        double upstream_helix_x_value = circle_x0 + (radius*qCos((1/radius)*(dsdz*zUSLocal+line_dz_c))); // x value in tracker local reference system
 
1094
        double upstream_helix_y_value = circle_y0 + (radius*qSin((1/radius)*(dsdz*zUSLocal+line_dz_c))); // y value in tracker local reference system
 
1095
 
 
1096
        // - transformation to global coordinate system (not exactly correct but accurate enough (?!) for visual representation)
 
1097
        std::vector<double> vSpacePoint = {upstream_helix_x_value, upstream_helix_y_value, zUSLocal};
 
1098
        VectorTransform trans(vSpacePoint);
 
1099
        trans.Rotate(matrixElements, "reg");
 
1100
        trans.Translate(trackerRef0posX, trackerRef0posY, trackerRef0posZ, "reg");
 
1101
 
 
1102
        upstream_helix_x.push_back(trans.GetX());
 
1103
        upstream_helix_y.push_back(trans.GetY());
 
1104
        upstream_helix_z.push_back(trans.GetZ());
 
1105
    }
 
1106
 
 
1107
    upstream_helix_xz_plane.setData(upstream_helix_z, upstream_helix_x);
 
1108
    upstream_helix_yz_plane.setData(upstream_helix_z, upstream_helix_y);
 
1109
 
 
1110
 
 
1111
    // --- fetch DS tracker global geometry
 
1112
    mmTrackerDS = mm->findModulesByName ("ParentGeometryFile.dat/Tracker1.dat");
 
1113
 
 
1114
    // - get TrackerRef1 position
 
1115
    double trackerRef1posX = mmTrackerDS[0]->daughter(0)->globalPosition().x();
 
1116
    double trackerRef1posY = mmTrackerDS[0]->daughter(0)->globalPosition().y();
 
1117
    double trackerRef1posZ = mmTrackerDS[0]->daughter(0)->globalPosition().z();
 
1118
 
 
1119
    // - get rotation matrix
 
1120
    xx = mmTrackerDS[0]->globalRotation().xx();
 
1121
    xy = mmTrackerDS[0]->globalRotation().xy();
 
1122
    xz = mmTrackerDS[0]->globalRotation().xz();
 
1123
    yx = mmTrackerDS[0]->globalRotation().yx();
 
1124
    yy = mmTrackerDS[0]->globalRotation().yy();
 
1125
    yz = mmTrackerDS[0]->globalRotation().yz();
 
1126
    zx = mmTrackerDS[0]->globalRotation().zx();
 
1127
    zy = mmTrackerDS[0]->globalRotation().zy();
 
1128
    zz = mmTrackerDS[0]->globalRotation().zz();
 
1129
 
 
1130
    // - fill matrix elements (for VectorTransform)
 
1131
    matrixElements.clear();
 
1132
    matrixElements.push_back(xx);
 
1133
    matrixElements.push_back(xy);
 
1134
    matrixElements.push_back(xz);
 
1135
    matrixElements.push_back(yx);
 
1136
    matrixElements.push_back(yy);
 
1137
    matrixElements.push_back(yz);
 
1138
    matrixElements.push_back(zx);
 
1139
    matrixElements.push_back(zy);
 
1140
    matrixElements.push_back(zz);
 
1141
 
 
1142
    // - plot downstream helical track
 
1143
    QCPCurve downstream_helix_xz_plane(ui->plot_position_xz->xAxis, ui->plot_position_xz->yAxis);
 
1144
    QCPCurve downstream_helix_yz_plane(ui->plot_position_yz->xAxis, ui->plot_position_yz->yAxis);
 
1145
    QVector<double> downstream_helix_x, downstream_helix_y, downstream_helix_z; // vectors to hold z coordinates array and coresponding values from projections to XZ and YZ planes
 
1146
    circle_x0 = evEvent.scifiDSTrackerHelicalTrackParameters[0];
 
1147
    circle_y0 = evEvent.scifiDSTrackerHelicalTrackParameters[1];
 
1148
    radius = evEvent.scifiDSTrackerHelicalTrackParameters[2];
 
1149
    dsdz = evEvent.scifiDSTrackerHelicalTrackParameters[3];
 
1150
    line_dz_c = evEvent.scifiDSTrackerHelicalTrackParameters[4];
 
1151
    posZ = evEvent.scifiDSTrackerHelicalTrackParameters[7];
 
1152
 
 
1153
    zUSLocal = posZ;
 
1154
    while (zUSLocal < trackerLength) {
 
1155
        zUSLocal += zStep; // z value in tracker local reference system
 
1156
        double downstream_helix_x_value = circle_x0 + (radius*qCos((1/radius)*(dsdz*zUSLocal+line_dz_c))); // x value in tracker local reference system
 
1157
        double downstream_helix_y_value = circle_y0 + (radius*qSin((1/radius)*(dsdz*zUSLocal+line_dz_c))); // y value in tracker local reference system
 
1158
 
 
1159
        // - transformation to global coordinate system (not exactly correct but accurate enough for visual representation)
 
1160
        std::vector<double> vSpacePoint = {downstream_helix_x_value, downstream_helix_y_value, zUSLocal};
 
1161
        VectorTransform trans(vSpacePoint);
 
1162
        trans.Rotate(matrixElements, "reg");
 
1163
        trans.Translate(trackerRef1posX, trackerRef1posY, trackerRef1posZ, "reg");
 
1164
 
 
1165
        downstream_helix_x.push_back(trans.GetX());
 
1166
        downstream_helix_y.push_back(trans.GetY());
 
1167
        downstream_helix_z.push_back(trans.GetZ());
 
1168
    }
 
1169
 
 
1170
    downstream_helix_xz_plane.setData(downstream_helix_z, downstream_helix_x);
 
1171
    downstream_helix_yz_plane.setData(downstream_helix_z, downstream_helix_y);
 
1172
 
 
1173
 
992
1174
    // plot TOF2:
993
1175
    QVector<double> tof2_x, tof2_y, tof2_z;
994
1176
    MAUS::ThreeVector tof2 = evEvent.tofPoints[2];
1090
1272
            MAUS::Spill *spill = data.GetSpill();
1091
1273
            if(spill != NULL && spill->GetDaqEventType() == "physics_event") {
1092
1274
                if (spill->GetSpillNumber() == spillNumber) {
1093
 
                    //std::cout << std::endl << std::endl << "------->found spill: " << spill->GetSpillNumber() << " event: " << eventNumber << std::endl;//remove after checks
1094
1275
                    exp = new EventViewer::EVExporter(spill);
1095
1276
                    int detectorsHit = exp->ReadOneEvent(eventNumber, exportOpt.c_str(), eventSelection, displayOpt);
1096
 
                    //std::cout << "--->detectorsHit: " << detectorsHit << "  eventSelection: " << eventSelection << std::endl; //remove after checks
1097
1277
                    if (eventSelection == 0) { //if eventSelectio is 0 every event should be displayed
1098
1278
                        std::cout << std::endl << "...Processing spill: " << spill->GetSpillNumber() << "  event: " << eventNumber << std::endl; //remove or add verbosity option
1099
1279
                        evEvent = exp->evEvent;
1117
1297
        }
1118
1298
    }
1119
1299
 
1120
 
    //std::cout << "--->did not find spill: " << spillNumber << " event: " << eventNumber << std::endl;//remove after checks
1121
1300
    infile.close();
1122
1301
    return 0;
1123
1302
}