Commit d4aced04 authored by Tobias Rump's avatar Tobias Rump
Browse files

[ADD #53] multiselector from PDG-Encoding shows particlenames and pdg

parent bdff4b80
......@@ -24,6 +24,8 @@
#include <string>
#include <vector>
#include <iostream>
#include <regex>
#include "WMFilterPropertyHandler.h"
......@@ -62,10 +64,10 @@ void WMFilterPropertyHandler::createMultiSelectionForPDG()
searchPDGTypes();
for( auto pdgType : m_pdgTypes )
{
m_possibleSelection->addItem( std::to_string( pdgType ) );
m_possibleSelection->addItem( getParticleNameFromPdg(pdgType) + "( " + std::to_string(pdgType) +" )" );
}
m_selectedPDGTypes.push_back( std::to_string( m_pdgTypes[0] ) );
m_selectedPDGTypes.push_back( m_pdgTypes[0] );
m_multiSelection = m_filteringGroup->addProperty( "PDGEncoding", "Choose particle type(s) you want show",
m_possibleSelection->getSelectorFirst(), pdgEncodingnotifier );
......@@ -108,7 +110,7 @@ void WMFilterPropertyHandler::updateSelectedPDGTypes( WPropertyBase::SPtr proper
for( int i = 0; i < selectedItems.size(); ++i )
{
m_selectedPDGTypes.push_back( selectedItems.at( i )->getName() );
m_selectedPDGTypes.push_back(getPdgFromName(selectedItems.at( i )->getName()));
}
}
......@@ -119,7 +121,7 @@ bool WMFilterPropertyHandler::isPDGTypeSelected( int pdgType )
{
for( auto idx = 0; idx < m_selectedPDGTypes.size(); idx++ )
{
if(pdgType == std::stoi( m_selectedPDGTypes[idx] ) )
if(pdgType == m_selectedPDGTypes[idx] )
{
return true;
}
......@@ -146,3 +148,65 @@ void WMFilterPropertyHandler::updateCheckboxProperty( WPropertyBase::SPtr proper
}
}
}
void WMFilterPropertyHandler::createPDGMap(std::string path)
{
std::fstream pdgSignFile;
std::string dataRow;
bool firstLine = true;
std::string particleName;
int pdg;
pdgSignFile.open( path );
if( !pdgSignFile.is_open() )
{
throw WException( "File could not be opened!" );
}
while( std::getline( pdgSignFile, dataRow ) )
{
if(firstLine)
{
firstLine = false;
continue;
}
std::istringstream iss( dataRow );
iss >> particleName >> pdg;
m_PdgNamesByID.insert( PdgElement( particleName, pdg ) );
}
pdgSignFile.close();
}
std::string WMFilterPropertyHandler::getParticleNameFromPdg(int pdg)
{
BM_PDG::right_const_iterator pdg_iter = m_PdgNamesByID.right.find(pdg);
if(pdg_iter != m_PdgNamesByID.right.end())
{
return pdg_iter->second;
}
else
{
return "unknown";
}
}
int WMFilterPropertyHandler::getPdgFromName(std::string particleName)
{
BM_PDG::left_const_iterator pdg_iter = m_PdgNamesByID.left.find(particleName.substr(0, particleName.find("(")));
if(pdg_iter != m_PdgNamesByID.left.end())
{
return pdg_iter->second;
}
else
{
std::regex regexp("[-+0-9]+");
std::smatch m;
std::regex_search(particleName, m, regexp);
return std::stoi(m[0]);
}
}
......@@ -27,6 +27,7 @@
#include <string>
#include <vector>
#include <boost/bimap.hpp>
#include "../WMProtonData.h"
......@@ -46,6 +47,16 @@ public:
*/
typedef boost::function< void( ) > CallbackPtr;
/**
* bimap to save the pdg to a particlename
*/
typedef boost::bimap< std::string, int > BM_PDG;
/**
* represent an Element of a pdg and a particlename for the map
*/
typedef BM_PDG::value_type PdgElement;
/**
* constructor
*
......@@ -84,7 +95,16 @@ public:
*/
bool isPDGTypeSelected( int pdgType );
/**
* creates a bimap out of the names and ids of PDG txt
*
* \param path fielpath of the pdg particlename file
* \throws WException
*/
void createPDGMap(std:: string path);
private:
/**
* Pointer to the content and header of the CSV
*/
......@@ -127,6 +147,27 @@ private:
*/
void updateCheckboxProperty( WPropertyBase::SPtr property );
/**
* Seatch the ParticleName in the map with a given pdg
*
* \param pdg pdg number of a particlename
* \return the particle name
*/
std::string getParticleNameFromPdg(int pdg);
/**
* Search the pdg in the map with a given particlename
*
* \param particleName particlename of a pdg number
* \return pdg number
*/
int getPdgFromName(std::string particleName);
/**
* A Map of the PDG and their names
*/
BM_PDG m_PdgNamesByID;
/**
* Stores every unique particle id.
*/
......@@ -160,7 +201,7 @@ private:
/**
* vector of the options of PDG
*/
std::vector < std::string > m_selectedPDGTypes;
std::vector < int > m_selectedPDGTypes;
};
#endif // WMFILTERPROPERTYHANDLER_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2013 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
// Provide additional material and descriptions for your module. You can
// provide this for multiple modules if you like.
// NOTE: everything but the module name is optional, even if this makes no
// sense at all.
"FilterProtonData"
{
icon="proton_module_icon2.png";
};
"common"
{
pdgnames = "PDFEncodingNameMap.txt"; // in german
};
Particlename PDG
electron 11
positron -11
muon+ -13
moun- 13
tauon+ -15
tauon- 15
electron_neutrino 12
electron_(anti)neutrino -12
muon_neutrino 14
muon_antineutrino -14
tau_neutrino 16
tau_antineutrino -16
photon 22
proton 2212
antiproton -2212
neutron 2112
antineutron -2112
lambda 3122
antilambda 3122
pion- -211
pion+ 211
pion0 111
kaon-, 321
kaon+ 321
kaon0 311
kaon0L 130
kaon0S 310
alpha 1000020040
antialpha -1000020040
deuteron 1000010020
antideuteron -1000010020
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