Commit 57ae333d authored by Adrien Matta's avatar Adrien Matta
Browse files

* Adding Samurai field map class

parent 91c19982
Pipeline #121030 passed with stages
in 6 minutes and 5 seconds
add_custom_command(OUTPUT TSamuraiHodoscopeDataDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TSamuraiHodoscopeData.h TSamuraiHodoscopeDataDict.cxx TSamuraiHodoscopeData.rootmap libNPSamurai.dylib DEPENDS TSamuraiHodoscopeData.h)
add_custom_command(OUTPUT SamuraiFieldMapDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh SamuraiFieldMap.h SamuraiFieldMapDict.cxx SamuraiFieldMap.rootmap libNPSamurai.dylib DEPENDS SamuraiFieldMap.h)
add_custom_command(OUTPUT TSamuraiHodoscopePhysicsDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TSamuraiHodoscopePhysics.h TSamuraiHodoscopePhysicsDict.cxx TSamuraiHodoscopePhysics.rootmap libNPSamurai.dylib DEPENDS TSamuraiHodoscopePhysics.h)
add_custom_command(OUTPUT TSamuraiBDCDataDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TSamuraiBDCData.h TSamuraiBDCDataDict.cxx TSamuraiBDCData.rootmap libNPSamurai.dylib DEPENDS TSamuraiBDCData.h)
......@@ -14,8 +17,8 @@ add_custom_command(OUTPUT TSamuraiFDC0DataDict.cxx COMMAND ${CMAKE_BINARY_DIR}/s
add_custom_command(OUTPUT TSamuraiFDC0PhysicsDict.cxx COMMAND ${CMAKE_BINARY_DIR}/scripts/build_dict.sh TSamuraiFDC0Physics.h TSamuraiFDC0PhysicsDict.cxx TSamuraiFDC0Physics.rootmap libNPSamurai.dylib DEPENDS TSamuraiFDC0Physics.h)
add_library(NPSamurai SHARED TSamuraiHodoscopeData.cxx TSamuraiBDCData.cxx TSamuraiBDCPhysics.cxx TSamuraiBDCDataDict.cxx TSamuraiBDCPhysicsDict.cxx TSamuraiFDC2Data.cxx TSamuraiFDC2DataDict.cxx TSamuraiHodoscopePhysics.cxx TSamuraiHodoscopePhysicsDict.cxx TSamuraiFDC2Physics.cxx TSamuraiHodoscopeDataDict.cxx TSamuraiFDC2PhysicsDict.cxx TSamuraiFDC0Data.cxx TSamuraiFDC0DataDict.cxx TSamuraiFDC0Physics.cxx TSamuraiFDC0PhysicsDict.cxx)
add_library(NPSamurai SHARED SamuraiFieldMapDict.cxx SamuraiFieldMap.cxx TSamuraiHodoscopeData.cxx TSamuraiBDCData.cxx TSamuraiBDCPhysics.cxx TSamuraiBDCDataDict.cxx TSamuraiBDCPhysicsDict.cxx TSamuraiFDC2Data.cxx TSamuraiFDC2DataDict.cxx TSamuraiHodoscopePhysics.cxx TSamuraiHodoscopePhysicsDict.cxx TSamuraiFDC2Physics.cxx TSamuraiHodoscopeDataDict.cxx TSamuraiFDC2PhysicsDict.cxx TSamuraiFDC0Data.cxx TSamuraiFDC0DataDict.cxx TSamuraiFDC0Physics.cxx TSamuraiFDC0PhysicsDict.cxx)
target_link_libraries(NPSamurai ${ROOT_LIBRARIES} NPCore NPTrackReconstruction)
install(FILES TSamuraiBDCData.h TSamuraiBDCPhysics.h TSamuraiHodoscopeData.h TSamuraiHodoscopePhysics.h TSamuraiFDC2Data.h TSamuraiFDC2Physics.h TSamuraiFDC0Data.h TSamuraiFDC0Physics.h SamuraiDCIndex.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
install(FILES SamuraiFieldMap.h TSamuraiBDCData.h TSamuraiBDCPhysics.h TSamuraiHodoscopeData.h TSamuraiHodoscopePhysics.h TSamuraiFDC2Data.h TSamuraiFDC2Physics.h TSamuraiFDC0Data.h TSamuraiFDC0Physics.h SamuraiDCIndex.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
/*****************************************************************************
* Copyright (C) 2009-2021 this file is part of the NPTool Project *
* *
* For the licensing terms see $NPTOOL/Licence/NPTool_Licence *
* For the list of contributors see $NPTOOL/Licence/Contributors *
*****************************************************************************/
/*****************************************************************************
* Original Author: Adrien Matta contact address: matta@lpccaen.in2p3.fr *
* *
* Creation Date : May 2021 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Samurai field map data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include "SamuraiFieldMap.h"
#include <fstream>
#include <iostream>
using namespace std;
ClassImp(SamuraiFieldMap);
////////////////////////////////////////////////////////////////////////////////
SamuraiFieldMap::SamuraiFieldMap(std::string file){
LoadMap(file);
}
////////////////////////////////////////////////////////////////////////////////
void SamuraiFieldMap::LoadMap(std::string file){
if(file.find(".bin")!=std::string::npos)
LoadBinary(file);
else
LoadAscii(file);
}
////////////////////////////////////////////////////////////////////////////////
std::vector<float>& SamuraiFieldMap::GetB(std::vector<float>& pos){
static vector<float> nullv ={0,0,0};
auto it=m_field.find(pos);
if(it!=m_field.end()){
return it->second;
}
else
return nullv;
}
////////////////////////////////////////////////////////////////////////////////
void SamuraiFieldMap::LoadAscii(std::string file){
ifstream in(file.c_str());
if(!in.is_open()){
cout << "Error: failed to load samurai field map " << file << endl;
exit(1);
}
cout << "//////// Loading Ascii Samurai field map " << file << endl;
float x,y,z,Bx,By,Bz;
m_x_max=m_y_max=m_z_max=-1e32;
m_x_min=m_y_min=m_z_min=1e32;
unsigned int count =0 ;
// ignore 8 first line
string buffer;
for(unsigned int i = 0 ; i < 8 ; i++){
getline(in,buffer);
}
while(in >> x >> y >> z >> Bx >> By >> Bz){
if(++count%50000==0)
cout << "\r - Loading " << count << " values " << flush;
vector<float> p = {x,y,z};
vector<float> B = {Bx,By,Bz};
m_field[p]=B;
if(x<m_x_min)
m_x_min=x;
if(x>m_x_max)
m_x_max=x;
if(y<m_y_min)
m_y_min=y;
if(y>m_y_max)
m_y_max=y;
if(z<m_z_min)
m_z_min=z;
if(z>m_z_max)
m_z_max=z;
}
cout << "\r - " << count << " values loaded" << endl;
in.close();
}
////////////////////////////////////////////////////////////////////////////////
void SamuraiFieldMap::LoadBinary(std::string file){
ifstream in(file.c_str(),std::ifstream::binary);
if(!in.is_open()){
cout << "Error: failed to load samurai field map " << file << endl;
exit(1);
}
cout << "//////// Loading Binary Samurai field map " << file << endl;
float x,y,z,Bx,By,Bz;
m_x_max=m_y_max=m_z_max=-1e32;
m_x_min=m_y_min=m_z_min=1e32;
unsigned int count =0 ;
while(!in.eof()){
if(++count%50000==0)
cout << "\r - Loading " << count << " values " << flush;
in.read((char*)&x,sizeof(x));
in.read((char*)&y,sizeof(y));
in.read((char*)&z,sizeof(z));
in.read((char*)&Bx,sizeof(Bx));
in.read((char*)&By,sizeof(By));
in.read((char*)&Bz,sizeof(Bz));
vector<float> p = {x,y,z};
vector<float> B = {Bx,By,Bz};
m_field[p]=B;
if(x<m_x_min)
m_x_min=x;
if(x>m_x_max)
m_x_max=x;
if(y<m_y_min)
m_y_min=y;
if(y>m_y_max)
m_y_max=y;
if(z<m_z_min)
m_z_min=z;
if(z>m_z_max)
m_z_max=z;
}
cout << "\r - " << count << " values loaded" << endl;
cout << " - min(" << m_x_min <<";"<< m_y_min <<";" << m_z_min<< ") max(" << m_x_max <<";"<< m_y_max <<";" << m_z_max<< ")" << endl;
in.close();
}
#ifndef SamuraiFieldMap_h
#define SamuraiFieldMap_h
/*****************************************************************************
* Copyright (C) 2009-2021 this file is part of the NPTool Project *
* *
* For the licensing terms see $NPTOOL/Licence/NPTool_Licence *
* For the list of contributors see $NPTOOL/Licence/Contributors *
*****************************************************************************/
/*****************************************************************************
* Original Author: Adrien Matta contact address: matta@lpccaen.in2p3.fr *
* *
* Creation Date : May 2021 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class hold Samurai field map data *
* *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include"TObject.h"
#include<string>
#include<vector>
#include<map>
class SamuraiFieldMap{
public:
SamuraiFieldMap(){};
SamuraiFieldMap(std::string file);
~SamuraiFieldMap(){};
public: // Map reading
void LoadMap(std::string file);
void LoadAscii(std::string file);
void LoadBinary(std::string file);
private:
// map[Pos]=B;
std::map<std::vector<float>,std::vector<float>> m_field;
float m_x_max,m_y_max,m_z_max,m_x_min,m_y_min,m_z_min;
public:
std::vector<float>& GetB(std::vector<float>& pos);
inline std::vector<float>& GetB(float x,float y ,float z){
std::vector<float> pos = {x,y,z};
return GetB(pos);
};
ClassDef(SamuraiFieldMap,1);
};
#endif
#ifndef TSamuraiHodoscopePHYSICS_H
#define TSamuraiHodoscopePHYSICS_H
/*****************************************************************************
* Copyright (C) 2009-2019 this file is part of the NPTool Project *
* Copyright (C) 2009-2021 this file is part of the NPTool Project *
* *
* For the licensing terms see $NPTOOL/Licence/NPTool_Licence *
* For the list of contributors see $NPTOOL/Licence/Contributors *
......
......@@ -43,6 +43,7 @@ void Analysis::Init(){
FDC0 = (TSamuraiFDC0Physics*) m_DetectorManager->GetDetector("SAMURAIFDC0");
FDC2 = (TSamuraiFDC2Physics*) m_DetectorManager->GetDetector("SAMURAIFDC2");
Hodo = (TSamuraiHodoscopePhysics*) m_DetectorManager->GetDetector("SAMURAIHOD");
m_field.LoadMap("field_map/180702-2,40T-3000.table.bin");
InitOutputBranch();
InitInputBranch();
......
......@@ -28,6 +28,7 @@
#include"TSamuraiFDC0Physics.h"
#include"TSamuraiFDC2Physics.h"
#include"TSamuraiHodoscopePhysics.h"
#include"SamuraiFieldMap.h"
class Analysis: public NPL::VAnalysis{
public:
......@@ -48,7 +49,7 @@ class Analysis: public NPL::VAnalysis{
TSamuraiFDC0Physics* FDC0;
TSamuraiFDC2Physics* FDC2;
TSamuraiHodoscopePhysics* Hodo;
SamuraiFieldMap m_field ;
private: // output variable
double Brho;
double Beta_f;
......
void ascii2bin(){
std::string file ="180702-2,40T-3000.table";
ifstream in(file.c_str());
if(!in.is_open()){
cout << "Error: failed to load samurai field map " << file << endl;
exit(1);
}
cout << "//////// Loading Samurai Field Map " << file << endl;
float x,y,z,Bx,By,Bz;
std::string name = file+".bin";
ofstream out(name.c_str(),std::ofstream::binary);
unsigned int count =0 ;
// ignore 8 first line
string buffer;
for(unsigned int i = 0 ; i < 8 ; i++){
getline(in,buffer);
}
while(in >> x >> y >> z >> Bx >> By >> Bz){
if(++count%10000==0)
cout << "\r - Loading " << count << " values " << flush;
out.write((char*)&x,sizeof(x));
out.write((char*)&y,sizeof(y));
out.write((char*)&z,sizeof(z));
out.write((char*)&Bx,sizeof(Bx));
out.write((char*)&By,sizeof(By));
out.write((char*)&Bz,sizeof(Bz));
//out << x << y << z << Bx << By << Bz;
}
cout << "\r - " << count << " values loaded" << endl;
out.close();
in.close();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment