Commit 9e20a24a authored by Pierre Morfouace's avatar Pierre Morfouace
Browse files

Merge branch 'NPTool.2.dev' of https://gitlab.in2p3.fr/np/nptool into NPTool.2.dev

parents 8914836f a0d67fc6
Pipeline #127841 passed with stages
in 7 minutes and 41 seconds
......@@ -268,7 +268,7 @@ void NPL::DetectorManager::BuildPhysicalEvent(){
(it->second->*m_ClearEventPhysicsPtr)();
(it->second->*m_BuildPhysicalPtr)();
(it->second->*m_FillSpectra)();
if(m_CheckSpectra)
if(m_CheckSpectra) {
(it->second->*m_CheckSpectra)();
}
}
......
......@@ -57,18 +57,18 @@ class TComptonTelescopePhysics : public TObject, public NPL::VDetector
// DSSD
int EventMultiplicity;
vector<int> EventType;
//vector<int> TowerNumber;
vector<int> TowerNumber;//
vector<int> DetectorNumber;
vector<int> Strip_Front;
vector<int> Strip_Back;
//vector<double> Strip_E;
vector<double> Strip_E;//
vector<double> Strip_T;
vector<double> Front_Energy;
vector<double> Back_Energy;
//vector<double> Half_Energy;
vector<double> Half_Energy;//
vector<double> Front_Time;
vector<double> Back_Time;
//vector<bool> Same_FBTime;
vector<bool> Same_FBTime;//
// Calorimeter
vector<double> Calor_E;
vector<double> Calor_T;
......@@ -240,8 +240,8 @@ class TComptonTelescopePhysics : public TObject, public NPL::VDetector
Int_t m_CounterEvt[50]; //!
Int_t m_CounterHit[50]; //!
// physical events
vector<int> TowerNumber;
vector<double> Half_Energy;
//vector<int> TowerNumber;
//vector<double> Half_Energy;
//vector<bool> Same_FBTime;
};
......
// The MIT License (MIT)
//
// Copyright (c) 2011-2020 Christopher M. Poole <mail@christopherpoole.net>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// CADMESH - Load CAD files into Geant4 quickly and easily.
//
// Read all about it at: https://github.com/christopherpoole/CADMesh
//
// Basic usage:
//
// #include "CADMesh.hh" // This file.
// ...
// auto mesh = CADMesh::TessellatedMesh::FromSTL("mesh.stl");
// G4VSolid* solid = mesh->GetSolid();
// ...
//
// !! THIS FILE HAS BEEN AUTOMATICALLY GENERATED. DON'T EDIT IT DIRECTLY. !!
#pragma once
class BuiltInReader;
class CADMeshTemplate;
class Mesh;
class STLReader;
class ASSIMPReader;
class PLYReader;
class FileTypes;
class OBJReader;
class Exceptions;
class TetrahedralMesh;
class Reader;
class Lexer;
class LexerMacros;
class TessellatedMesh;
#include "G4String.hh"
#include <algorithm>
#include <map>
namespace CADMesh {
namespace File {
enum Type {
Unknown,
PLY,
STL,
DAE,
OBJ,
TET,
OFF,
};
static std::map<Type, G4String> Extension = {
{Unknown, "unknown"}, {PLY, "ply"}, {STL, "stl"}, {DAE, "dae"},
{OBJ, "obj"}, {TET, "tet"}, {OFF, "off"}};
static std::map<Type, G4String> TypeString = {
{Unknown, "UNKNOWN"}, {PLY, "PLY"}, {STL, "STL"}, {DAE, "DAE"},
{OBJ, "OBJ"}, {TET, "TET"}, {OFF, "OFF"}};
static std::map<Type, G4String> TypeName = {
{Unknown, "Unknown File Format"}, {PLY, "Stanford Triangle Format (PLY)"},
{STL, "Stereolithography (STL)"}, {DAE, "COLLADA (DAE)"},
{OBJ, "Wavefront (OBJ)"}, {TET, "TetGet (TET)"},
{OFF, "Object File Format (OFF)"}};
Type TypeFromExtension(G4String extension);
Type TypeFromName(G4String name);
}
}
#include "G4ThreeVector.hh"
#include "G4TriangularFacet.hh"
#include <memory>
#include <vector>
namespace CADMesh {
typedef std::vector<G4ThreeVector> Points;
typedef std::vector<G4TriangularFacet *> Triangles;
class Mesh {
public:
Mesh(Points points, Triangles triangles, G4String name = "");
static std::shared_ptr<Mesh> New(Points points, Triangles triangles,
G4String name = "");
static std::shared_ptr<Mesh> New(Triangles triangles, G4String name = "");
static std::shared_ptr<Mesh> New(std::shared_ptr<Mesh> mesh,
G4String name = "");
public:
G4String GetName();
Points GetPoints();
Triangles GetTriangles();
G4bool IsValidForNavigation();
private:
G4String name_ = "";
Points points_;
Triangles triangles_;
};
typedef std::vector<std::shared_ptr<Mesh>> Meshes;
}
namespace CADMesh {
namespace File {
class Reader {
public:
Reader(G4String reader_name);
~Reader();
virtual G4bool Read(G4String filepath) = 0;
virtual G4bool CanRead(Type file_type) = 0;
public:
G4String GetName();
std::shared_ptr<Mesh> GetMesh();
std::shared_ptr<Mesh> GetMesh(size_t index);
std::shared_ptr<Mesh> GetMesh(G4String name, G4bool exact = true);
size_t GetNumberOfMeshes();
Meshes GetMeshes();
protected:
size_t AddMesh(std::shared_ptr<Mesh> mesh);
void SetMeshes(Meshes meshs);
private:
Meshes meshes_;
G4String name_ = "";
};
}
}
#include <iostream>
#include <string>
namespace CADMesh {
namespace File {
struct Token {
std::string name;
bool operator==(Token other) { return name == other.name; };
bool operator!=(Token other) { return name != other.name; };
};
static Token ErrorToken{"ErrorToken"};
static Token EnfOfFileToken{"EndOfFileToken"};
static Token ParentToken{"Parent"};
static Token WordToken{"Word"};
static Token NumberToken{"Number"};
static Token ThreeVectorToken{"ThreeVector"};
static Token VertexToken{"Vertex"};
static Token VerticesToken{"Vertices"};
static Token FacetToken{"Facet"};
static Token LineToken{"Line"};
static Token NormalToken{"Normal"};
static Token TextureToken{"Texture"};
static Token SolidToken{"Solid"};
static Token ObjectToken{"Object"};
static Token CommentToken{"Comment"};
static Token BlankLineToken{"BlankLine"};
struct Item {
Token token;
size_t position;
size_t line;
std::string value;
std::string error;
Item *parent;
std::vector<Item> children;
};
typedef std::vector<Item> Items;
typedef Items::iterator ItemsIterator;
class Lexer;
struct State {
virtual State *operator()(Lexer *) const = 0;
};
struct __FinalState : public State {
State *operator()(Lexer *) const { return nullptr; }
};
class Lexer {
public:
Lexer(std::string filepath, State *initial_state = nullptr);
public:
std::string String();
void Run(State *initial_state, size_t lines = 0);
Items GetItems();
void Backup();
void BackupTo(int position);
std::string Next();
std::string Peek();
void Skip();
Item *ThisIsA(Token token, std::string error = "");
Item *StartOfA(Token token, std::string error = "");
Item *EndOfA(Token token, std::string error = "");
Item *MaybeEndOfA(Token token, std::string error = "");
bool OneOf(std::string possibles);
bool ManyOf(std::string possibles);
bool Until(std::string match);
bool MatchExactly(std::string match);
bool OneDigit();
bool ManyDigits();
bool OneLetter();
bool ManyLetters();
bool ManyCharacters();
bool Integer();
bool Float();
bool Number();
bool SkipWhiteSpace();
bool SkipLineBreak();
bool SkipLineBreaks();
bool SkipLine();
State *Error(std::string message);
State *LastError();
bool TestState(State *state);
bool IsDryRun();
void PrintMessage(std::string name, std::string message);
void PrintItem(Item item);
size_t LineNumber();
private:
State *state_;
Item *parent_item_ = nullptr;
Items items_;
std::string input_;
size_t position_ = 0;
size_t start_ = 0;
size_t width_ = 1;
size_t line_ = 1;
size_t end_line_ = 0;
bool dry_run_ = false;
int depth_ = 0;
std::string last_error_ = "";
};
}
}
#ifdef USE_CADMESH_ASSIMP_READER
#include "assimp/Importer.hpp"
#include "assimp/postprocess.h"
#include "assimp/scene.h"
namespace CADMesh {
namespace File {
class ASSIMPReader : public File::Reader {
public:
ASSIMPReader();
~ASSIMPReader();
public:
G4bool Read(G4String filepath);
G4bool CanRead(Type file_type);
private:
Assimp::Importer *importer_;
};
std::shared_ptr<ASSIMPReader> ASSIMP();
}
}
#endif
namespace CADMesh {
namespace File {
class BuiltInReader : public Reader {
public:
BuiltInReader() : Reader("BuiltInReader"){};
public:
G4bool Read(G4String filepath);
G4bool CanRead(File::Type file_type);
};
std::shared_ptr<BuiltInReader> BuiltIn();
}
}
#ifndef CADMESH_DEFAULT_READER
#define CADMESH_DEFAULT_READER BuiltIn
#endif
#include "G4AssemblyVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Material.hh"
#include "G4TessellatedSolid.hh"
#include "G4Tet.hh"
#include "G4UIcommand.hh"
namespace CADMesh {
template <typename T> class CADMeshTemplate {
public:
CADMeshTemplate();
CADMeshTemplate(G4String file_name);
CADMeshTemplate(G4String file_name, File::Type file_type);
CADMeshTemplate(std::shared_ptr<File::Reader> reader);
CADMeshTemplate(G4String file_name, std::shared_ptr<File::Reader> reader);
CADMeshTemplate(G4String file_name, File::Type file_type,
std::shared_ptr<File::Reader> reader);
static std::shared_ptr<T> From(G4String file_name);
static std::shared_ptr<T> From(G4String file_name,
std::shared_ptr<File::Reader> reader);
static std::shared_ptr<T> FromPLY(G4String file_name);
static std::shared_ptr<T> FromPLY(G4String file_name,
std::shared_ptr<File::Reader> reader);
static std::shared_ptr<T> FromSTL(G4String file_name);
static std::shared_ptr<T> FromSTL(G4String file_name,
std::shared_ptr<File::Reader> reader);
static std::shared_ptr<T> FromOBJ(G4String file_name);
static std::shared_ptr<T> FromOBJ(G4String file_name,
std::shared_ptr<File::Reader> reader);
~CADMeshTemplate();
public:
virtual G4VSolid *GetSolid() = 0;
virtual G4VSolid *GetSolid(G4int index) = 0;
virtual G4VSolid *GetSolid(G4String name, G4bool exact = true) = 0;
virtual std::vector<G4VSolid *> GetSolids() = 0;
virtual G4AssemblyVolume *GetAssembly() = 0;
bool IsValidForNavigation();
public:
G4String GetFileName();
File::Type GetFileType();
void SetVerbose(G4int verbose);
G4int GetVerbose();
void SetScale(G4double scale);
G4double GetScale();
void SetOffset(G4double x, G4double y, G4double z);
void SetOffset(G4ThreeVector offset);
G4ThreeVector GetOffset();
protected:
G4String file_name_;
File::Type file_type_;
G4int verbose_;
G4double scale_;
G4ThreeVector offset_;
G4AssemblyVolume *assembly_ = nullptr;
std::shared_ptr<File::Reader> reader_ = nullptr;
};
}
#include "globals.hh"
namespace CADMesh {
namespace Exceptions {
void FileNotFound(G4String origin, G4String filepath);
void LexerError(G4String origin, G4String message);
void ParserError(G4String origin, G4String message);
void ReaderCantReadError(G4String origin, File::Type file_type,
G4String filepath);
void MeshNotFound(G4String origin, size_t index);
void MeshNotFound(G4String origin, G4String name);
}
}
namespace CADMesh {
class TessellatedMesh : public CADMeshTemplate<TessellatedMesh> {
using CADMeshTemplate::CADMeshTemplate;
public:
G4VSolid *GetSolid();
G4VSolid *GetSolid(G4int index);
G4VSolid *GetSolid(G4String name, G4bool exact = true);
std::vector<G4VSolid *> GetSolids();
G4TessellatedSolid *GetTessellatedSolid();
G4TessellatedSolid *GetTessellatedSolid(G4int index);
G4TessellatedSolid *GetTessellatedSolid(G4String name, G4bool exact = true);
G4TessellatedSolid *GetTessellatedSolid(std::shared_ptr<Mesh> mesh);
G4AssemblyVolume *GetAssembly();
public:
void SetReverse(G4bool reverse) { this->reverse_ = reverse; };
G4bool GetReverse() { return this->reverse_; };
private:
G4bool reverse_;
};
}
#ifdef USE_CADMESH_TETGEN
#include "tetgen.h"
namespace CADMesh {
class TetrahedralMesh : public CADMeshTemplate<TetrahedralMesh> {
public:
using CADMeshTemplate::CADMeshTemplate;
TetrahedralMesh();
~TetrahedralMesh();
public:
G4VSolid *GetSolid();
G4VSolid *GetSolid(G4int index);
G4VSolid *GetSolid(G4String name, G4bool exact = true);
std::vector<G4VSolid *> GetSolids();
G4AssemblyVolume *GetAssembly();
public:
void SetMaterial(G4Material *material) { this->material_ = material; };
G4Material *GetMaterial() { return this->material_; };
void SetQuality(G4double quality) { this->quality_ = quality; };
G4double GetQuality() { return this->quality_; };
std::shared_ptr<tetgenio> GetTetgenInput() { return in_; };
std::shared_ptr<tetgenio> GetTetgenOutput() { return out_; };
private:
G4ThreeVector GetTetPoint(G4int index_offset);
private:
std::shared_ptr<tetgenio> in_ = nullptr;
std::shared_ptr<tetgenio> out_ = nullptr;
G4double quality_;
G4Material *material_;
};
}
#endif
namespace CADMesh {
namespace File {
inline Type TypeFromExtension(G4String extension) {
std::for_each(extension.begin(), extension.end(),
[](char &e) { e = ::tolower(e); });
for (auto e = Extension.begin(); e != Extension.end(); ++e) {
if (e->second == extension) {
return e->first;
}
}
return Unknown;
}
inline Type TypeFromName(G4String name) {
auto extension = name.substr(name.find_last_of(".") + 1);
return TypeFromExtension(extension);
}
}
}
namespace CADMesh {