Skip to content

Commit

Permalink
Merge pull request KFTrack#199 from Jasonguo9019/jason
Browse files Browse the repository at this point in the history
MatEnv Change
  • Loading branch information
brownd1978 authored Jan 23, 2025
2 parents 157924f + 2b5c12c commit 2bd57ef
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Examples/StrawMaterial.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace KinKal {
public:
// explicit constructor from geometry and materials
StrawMaterial(double srad, double thick, double sradsig, double wrad,
const MatEnv::DetMaterial *wallmat, const MatEnv::DetMaterial *gasmat, const MatEnv::DetMaterial *wiremat) :
const std::shared_ptr<MatEnv::DetMaterial> wallmat, const std::shared_ptr<MatEnv::DetMaterial> gasmat, const std::shared_ptr<MatEnv::DetMaterial> wiremat) :
srad_(srad), thick_(thick), sradsig_(sradsig), wrad_(wrad), wallmat_(wallmat), gasmat_(gasmat), wiremat_(wiremat) {
srad2_ = srad_*srad_;
grad_ = srad_-sradsig_; // count the gas volume inside 1 sigma. This smooths discontinuities at the edge
Expand Down Expand Up @@ -47,9 +47,9 @@ namespace KinKal {
double grad_; // effective gas volume radius
double grad2_; // effective gas volume radius squared
double wrad_; // transverse radius of the wire
const MatEnv::DetMaterial* wallmat_; // material of the straw wall
const MatEnv::DetMaterial* gasmat_; // material of the straw gas
const MatEnv::DetMaterial* wiremat_; // material of the wire
const std::shared_ptr<MatEnv::DetMaterial> wallmat_; // material of the straw wall
const std::shared_ptr<MatEnv::DetMaterial> gasmat_; // material of the straw gas
const std::shared_ptr<MatEnv::DetMaterial> wiremat_; // material of the wire
// utility to calculate material factor given the cosine of the angle of the particle WRT the straw
double angleFactor(double dirdot) const;
// maximum DOCA given straw irregularities
Expand Down
1 change: 1 addition & 0 deletions MatEnv/DetMaterial.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <vector>
#include <math.h>
#include <algorithm>
#include <memory>

namespace MatEnv {
class DetMaterial{
Expand Down
17 changes: 8 additions & 9 deletions MatEnv/MatDBInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ namespace MatEnv {

MatDBInfo::~MatDBInfo() {
// delete the materials
std::map< std::string*, DetMaterial*, PtrLess >::iterator
std::map< std::string*, std::shared_ptr<DetMaterial>, PtrLess >::iterator
iter = _matList.begin();
for (; iter != _matList.end(); ++iter) {
delete iter->first;
delete iter->second;
}
_matList.clear();
}
Expand All @@ -44,10 +43,10 @@ namespace MatEnv {
return;
}

const DetMaterial* MatDBInfo::findDetMaterial( const std::string& matName ) const
const std::shared_ptr<DetMaterial> MatDBInfo::findDetMaterial( const std::string& matName ) const
{
DetMaterial* theMat;
std::map< std::string*, DetMaterial*, PtrLess >::const_iterator pos;
std::shared_ptr<DetMaterial> theMat;
std::map< std::string*, std::shared_ptr<DetMaterial>, PtrLess >::const_iterator pos;
if ((pos = _matList.find((std::string*)&matName)) != _matList.end()) {
theMat = pos->second;
} else {
Expand All @@ -71,20 +70,20 @@ namespace MatEnv {
return theMat;
}

DetMaterial* MatDBInfo::createDetMaterial( const std::string& db_name,
std::shared_ptr<DetMaterial> MatDBInfo::createDetMaterial( const std::string& db_name,
const std::string& detMatName ) const
{
MtrPropObj* genMtrProp;
DetMaterial* theMat;
std::shared_ptr<DetMaterial> theMat;

genMtrProp = _genMatFactory->GetMtrProperties(db_name);
if(genMtrProp != 0){
theMat = new DetMaterial( detMatName.c_str(), genMtrProp ) ;
theMat = std::make_shared<DetMaterial> ( detMatName.c_str(), genMtrProp ) ;
theMat->setEnergyLossMode(_elossmode);
that()->_matList[new std::string( detMatName )] = theMat;
return theMat;
} else {
return 0;
return nullptr;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions MatEnv/MatDBInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "KinKal/MatEnv/FileFinderInterface.hh"
#include <string>
#include <map>
#include <memory>

namespace MatEnv {

Expand All @@ -39,17 +40,17 @@ namespace MatEnv {
MatDBInfo(FileFinderInterface const& interface, DetMaterial::energylossmode elossmode);
virtual ~MatDBInfo();
// Find the material, given the name
const DetMaterial* findDetMaterial( const std::string& matName ) const override;
const std::shared_ptr<DetMaterial> findDetMaterial( const std::string& matName ) const override;
// utility functions
private:
DetMaterial* createDetMaterial( const std::string& dbName,
std::shared_ptr<DetMaterial> createDetMaterial( const std::string& dbName,
const std::string& detMatName ) const;
void declareMaterial( const std::string& dbName,
const std::string& detMatName );
// Cache of RecoMatFactory pointer
RecoMatFactory* _genMatFactory;
// Cache of list of materials for DetectorModel
std::map< std::string*, DetMaterial*, PtrLess > _matList;
std::map< std::string*, std::shared_ptr<DetMaterial>, PtrLess > _matList;
// Map for reco- and DB material names
std::map< std::string, std::string > _matNameMap;
// function to cast-off const
Expand Down
3 changes: 2 additions & 1 deletion MatEnv/MaterialInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <string>
#include <vector>
#include <memory>
namespace MatEnv {
class DetMaterial;

Expand All @@ -29,7 +30,7 @@ namespace MatEnv {
MaterialInfo(){;}
virtual ~MaterialInfo(){;}
// Find the material, given the name
virtual const DetMaterial* findDetMaterial( const std::string& matName ) const = 0;
virtual const std::shared_ptr<DetMaterial> findDetMaterial( const std::string& matName ) const = 0;
const std::vector< std::string >& materialNames() const {
return _matNameList; }
std::vector< std::string >& materialNames() {
Expand Down
3 changes: 2 additions & 1 deletion Tests/MatEnv_unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstdio>
#include <iostream>
#include <getopt.h>
#include <memory>

#include "TH1F.h"
#include "TSystem.h"
Expand Down Expand Up @@ -85,7 +86,7 @@ int main(int argc, char **argv) {
cout << "Searching for material " << matname << endl;
MatEnv::SimpleFileFinder sfinder;
MatDBInfo matdbinfo(sfinder,MatEnv::DetMaterial::moyalmean);
const DetMaterial* dmat = matdbinfo.findDetMaterial(matname);
const std::shared_ptr<DetMaterial> dmat = matdbinfo.findDetMaterial(matname);
if(dmat != 0){
cout << "Found DetMaterial " << dmat->name() << endl;
unsigned nstep(100);
Expand Down
2 changes: 1 addition & 1 deletion Tests/ToyMC.hh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace KKTest {
StrawMaterial smat_; // straw material
Cylinder ipacyl_;
double ipathick_;
const MatEnv::DetMaterial* ipamat_;
const std::shared_ptr<MatEnv::DetMaterial> ipamat_;
MetaIterConfig miconfig_; // configuration used when calculating initial effect
};

Expand Down

0 comments on commit 2bd57ef

Please sign in to comment.