Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #33 from alicerobson/lxplus
Browse files Browse the repository at this point in the history
Thank you for your answers!
  • Loading branch information
cbernet authored Jun 12, 2017
2 parents 586c877 + 3bc30e5 commit e6324c7
Show file tree
Hide file tree
Showing 52 changed files with 420 additions and 329 deletions.
9 changes: 0 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ include_directories(
"${FCCEDM_INCLUDE_DIRS}"
)


add_definitions(-Wno-unused-variable -Wno-unused-parameter -pthread)
#--temporary fix of inconsistency in ROOT CMake macros
#set(ROOT_genreflex_cmd ${ROOT_genreflex_CMD})


#--- enable unit testing capabilities ------------------------------------------
include(CTest)
Expand All @@ -67,8 +63,6 @@ include(CTest)
include(cmake/papasDoxygen.cmake)
#endif()



#--- add version files ---------------------------------------------------------
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/papasVersion.h
${CMAKE_CURRENT_BINARY_DIR}/papasVersion.h )
Expand All @@ -78,14 +72,11 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/papasVersion.h
#--- add CMake infrastructure --------------------------------------------------
include(cmake/papasCreateConfig.cmake)


#--- add license files ---------------------------------------------------------
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE
${CMAKE_CURRENT_SOURCE_DIR}/NOTICE
DESTINATION ${CMAKE_INSTALL_PREFIX})


#add_subdirectory(papascpp)
add_subdirectory(papaslib)
add_subdirectory(examples)
add_subdirectory(tests)
Expand Down
2 changes: 1 addition & 1 deletion cmake/papasConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ FIND_LIBRARY( papas_LIBRARIES NAMES papas PATHS
INCLUDE( FindPackageHandleStandardArgs )
FIND_PACKAGE_HANDLE_STANDARD_ARGS( papas DEFAULT_MSG papas_LIBRARY_DIR papas_INCLUDE_DIRS papas_LIBRARIES )

ADD_LIBRARY(papasexamplelibrary SHARED IMPORTED)
#ADD_LIBRARY(papasexamplelibrary SHARED IMPORTED)
39 changes: 26 additions & 13 deletions examples/PythiaConnector.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

//
// PythiaConnector.cpp
// papas
Expand All @@ -17,12 +16,15 @@
#include "datamodel/ParticleCollection.h"
#include "utilities/ParticleUtils.h"

#include "papas/datatypes/Helix.h"
#include "papas/datatypes/Particle.h"
#include "papas/simulation/Simulator.h"
#include "papas/utility/PDebug.h"

#include "papas/datatypes/Path.h"
#include "papas/detectors/Detector.h"
#include "papas/detectors/Field.h"
#include "papas/display/PFApp.h"
#include "papas/simulation/Simulator.h"
#include "papas/utility/Log.h"
#include "papas/utility/PDebug.h"

#include <exception>
#include <string>
Expand All @@ -47,7 +49,8 @@ PythiaConnector::PythiaConnector(const char* fname) : m_store(podio::EventStore(
}

void PythiaConnector::makePapasParticlesFromGeneratedParticles(const fcc::MCParticleCollection* ptcs,
papas::Particles& particles) {
papas::Particles& particles,
const papas::Detector& detector) {
// turns pythia particles into Papas particles and lodges them in the history
TLorentzVector tlv;
int countp = 0;
Expand Down Expand Up @@ -81,6 +84,15 @@ void PythiaConnector::makePapasParticlesFromGeneratedParticles(const fcc::MCPart
if (tlv.Pt() > 1e-5 && (abs(pdgid) != 12) && (abs(pdgid) != 14) && (abs(pdgid) != 16)) {
papas::Particle particle(pdgid, (double)ptc.core().charge, tlv, particles.size(), 's', startVertex,
ptc.core().status);
// set the particles papas path (allows particles to be const when passed to simulator)
std::shared_ptr<papas::Path> ppath;
if (fabs(particle.charge()) < 0.5) {
ppath = std::make_shared<papas::Path>(particle.p4(), particle.startVertex(), particle.charge());
} else {
ppath = std::make_shared<papas::Helix>(particle.p4(), particle.startVertex(), particle.charge(),
detector.field()->getMagnitude());
}
particle.setPath(ppath);
particles.emplace(particle.id(), particle);
papas::PDebug::write("Made {}", particle);
}
Expand All @@ -92,14 +104,15 @@ void PythiaConnector::processEvent(unsigned int eventNo, papas::PapasManager& pa
// make a papas particle collection from the next event
// then run simulate and reconstruct
m_reader.goToEvent(eventNo);
papasManager.clear();
papasManager.setEventNo(eventNo);
const fcc::MCParticleCollection* ptcs(nullptr);
const fcc::MCParticleCollection* ptcs;
if (m_store.get("GenParticle", ptcs)) {
try {
papasManager.clear();
papas::Particles& genParticles = papasManager.createParticles();
makePapasParticlesFromGeneratedParticles(ptcs, genParticles);
papasManager.simulate(genParticles);
makePapasParticlesFromGeneratedParticles(ptcs, genParticles, papasManager.detector());
papasManager.addParticles(genParticles);
papasManager.simulate('s');
papasManager.mergeClusters("es");
papasManager.mergeClusters("hs");
papasManager.buildBlocks('m', 'm', 's');
Expand Down Expand Up @@ -130,8 +143,8 @@ void PythiaConnector::writeParticlesROOT(const char* fname, const papas::Particl
auto& evinfocoll = m_store.create<fcc::EventInfoCollection>("evtinfo");
auto& pcoll = m_store.create<fcc::ParticleCollection>("GenParticle");

writer.registerForWrite<fcc::EventInfoCollection>("evtinfo");
writer.registerForWrite<fcc::ParticleCollection>("GenParticle");
writer.registerForWrite("evtinfo");
writer.registerForWrite("GenParticle");

auto evinfo = fcc::EventInfo(); // evinfocoll.create();
evinfo.number(eventno);
Expand Down Expand Up @@ -161,8 +174,8 @@ void PythiaConnector::writeClustersROOT(const char* fname, const papas::Clusters
auto& evinfocoll = m_store.create<fcc::EventInfoCollection>("evtinfo");
auto& ccoll = m_store.create<fcc::CaloClusterCollection>("Cluster");

writer.registerForWrite<fcc::EventInfoCollection>("evtinfo");
writer.registerForWrite<fcc::CaloClusterCollection>("Cluster");
writer.registerForWrite("evtinfo");
writer.registerForWrite("Cluster");

auto evinfo = fcc::EventInfo(); // evinfocoll.create();
evinfo.number(eventno);
Expand Down
3 changes: 2 additions & 1 deletion examples/PythiaConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class PythiaConnector {

///< Takes pythia particles and creates Papas type particles adding them into
/// an empty Particles collection
void makePapasParticlesFromGeneratedParticles(const fcc::MCParticleCollection* ptcs, papas::Particles& particles);
void makePapasParticlesFromGeneratedParticles(const fcc::MCParticleCollection* ptcs, papas::Particles& particles,
const papas::Detector& detector);
papas::Clusters ConvertClustersToPapas(const fcc::CaloClusterCollection& fccClusters, float size,
papas::IdCoder::ItemType itemtype, char subtype) const;
void AddClustersToEDM(const papas::Clusters& papasClusters, fcc::CaloClusterCollection& fccClusters);
Expand Down
6 changes: 3 additions & 3 deletions examples/example_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <iostream>

int main(int argc, char* argv[]) {

papas::PDebug::File("physics.txt");
// randomgen::setEngineSeed(0xdeadbeef); // make results reproduceable
rootrandom::Random::seed(0xdeadbeef);

if (argc != 2) {
Expand All @@ -41,14 +41,14 @@ int main(int argc, char* argv[]) {
papas::PapasManager papasManager(CMSDetector);

unsigned int eventNo = 0;
unsigned int nEvents = 10;
unsigned int nEvents = 10000;

auto start = std::chrono::steady_clock::now();

for (unsigned i = eventNo; i < eventNo + nEvents; ++i) {

papas::PDebug::write("Event: {}", i);
if (i % 10 == 0) {
if (i % 100 == 0) {
std::cout << "reading event " << i << std::endl;
}
if (i == eventNo)
Expand Down
13 changes: 11 additions & 2 deletions examples/example_plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@
#include "papas/detectors/CMS.h"
#include "papas/reconstruction/PapasManager.h"
#include "papas/utility/PDebug.h"
#include "papas/utility/TRandom.h"

#include <TApplication.h>

using namespace papas;

int main(int argc, char* argv[]) {

if (argc != 2) {
std::cerr << "Usage: ./mainexe filename" << std::endl;
rootrandom::Random::seed(0xdeadbeef);

if (argc < 2) {
std::cerr << "Usage: ./example_plot filename [logname]" << std::endl;
return 1;
}
if (argc == 3) {
const char* lname = argv[2];
PDebug::File(lname); // physics debug output
}

const char* fname = argv[1];
PythiaConnector pythiaConnector(fname);

Expand All @@ -35,5 +43,6 @@ int main(int argc, char* argv[]) {
pythiaConnector.processEvent(eventNo, papasManager);
TApplication tApp("theApp", &argc, argv);
pythiaConnector.displayEvent(papasManager);
papasManager.clear();
return EXIT_SUCCESS;
}
7 changes: 4 additions & 3 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ platform='unknown'
sw_afs=0
unamestr=`uname`

export LCGPATH=/afs/cern.ch/sw/lcg/views/LCG_83/x86_64-slc6-gcc49-opt
#if [ -z ${FCCPAPASCPP+x} ]; then
if [ -z ${FCCPAPASCPP+x} ]; then
unset $FCCPAPASCPP
echo "FCCPAPASCPP is unset, setting to $PWD/install";
export FCCPAPASCPP=$PWD/install
export PATH=$FCCPAPASCPP/bin:$PATH
#fi
fi

if [[ "$unamestr" == 'Linux' ]]; then
platform='Linux'
export LD_LIBRARY_PATH=$FCCPAPASCPP/lib:$LD_LIBRARY_PATH
source /cvmfs/fcc.cern.ch/sw/0.8.1/init_fcc_stack.sh $1
#export LCGPATH=/afs/cern.ch/sw/lcg/views/LCG_83/x86_64-slc6-gcc49-opt
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='Darwin'
export DYLD_LIBRARY_PATH=$FCCPAPASCPP/lib:$DYLD_LIBRARY_PATH
Expand Down
8 changes: 4 additions & 4 deletions papas/datatypes/Cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Cluster {
@param[in] id identifier type of cluster eg kEcalCluster or kHcalCluster
@param[in] subtype single char describing type of cluster eg s = smeared, t= true, m = merged
*/
Cluster(double energy, const TVector3& position, double size_m, unsigned int index, IdCoder::ItemType id,
Cluster(double energy, const TVector3& position, double size_m, uint32_t index, IdCoder::ItemType id,
char subtype = 't');

/** Constructor: makes new cluster with a new id based on a copy of an existing cluster. The new id must be provided.
Expand All @@ -37,7 +37,7 @@ class Cluster {
@param[in] val the value that will be used when creating the Cluster identifier and which is used for sorting.
When creating a merged cluster it should ideally be set to the total eneergy of the cluster
*/
Cluster(const Cluster& cluster, unsigned int index, IdCoder::ItemType type, char subtype = 'u', float val = 0.0);
Cluster(const Cluster& cluster, uint32_t index, IdCoder::ItemType type, char subtype = 'u', float val = 0.0);

/** Constructor: makes new merged cluster
@param[in] overlappingClusters list of clusters to be merged, they must have same type and subtype and must be
Expand All @@ -46,15 +46,15 @@ class Cluster {
@param[in] index of the collection into which the cluster is to be stored
@param[in] subtype subtype of cluster to be created eg 'm' for merged,
*/
Cluster(std::list<const Cluster*> overlappingClusters, unsigned int index, char subtype = 'm');
Cluster(std::list<const Cluster*> overlappingClusters, uint32_t index, char subtype = 'm');
Cluster() = default;
Cluster(Cluster&& c); // needed for unordered_map
Cluster(const Cluster& cluster) = default; // needed for unordered_map
Cluster& operator+=(const Cluster& rhs); ///< merges a cluster into an existing cluster
double angularSize() const; ///< The angle that the cluster boundary makes (not valid for merged clusters)
double size() const; ///< The radius of the cluster
double pt() const {
return m_energy * m_position.Perp();
return m_energy * m_position.Unit().Perp();
} ///< Transverse momentum (magnitude of p3 in transverse plane)
double energy() const { return m_energy; } ///< Energy
double eta() const { return m_position.Eta(); } ///< Pseudo-rapidity (-ln(tan self._tlv.Theta()/2))
Expand Down
4 changes: 2 additions & 2 deletions papas/datatypes/DefinitionsCollections.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Track;
class Edge;
class Particle;

typedef std::list<Particle> ListParticles; ///< list of Particles
typedef std::unordered_map<unsigned long long, Edge> Edges; ///< collection of Edge objects
typedef std::list<Particle> ListParticles; ///< list of Particles
typedef std::unordered_map<uint64_t, Edge> Edges; ///< collection of Edge objects
#if WITHSORT
typedef std::set<Identifier, std::greater<Identifier>> Ids; ///< set containing Identifiers
#else
Expand Down
31 changes: 14 additions & 17 deletions papas/datatypes/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <unordered_map>

namespace papas {
class Cluster;

class Cluster;

/**
* @brief The Event stores pointers to collections of Clusters, Tracks, Blocks, Particles in its
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace papas {
class Event {
public:
/// @brief Constructor
Event(std::shared_ptr<Nodes> hist = std::make_shared<Nodes>(Nodes()));
Event(Nodes& hist);

/**
* @brief adds a pointer to a Clusters collection (unordered map) into the Event
Expand Down Expand Up @@ -92,7 +92,7 @@ class Event {
* @brief makes history in Event point to an external history object
* @param[in] history unordered map of Nodes, *
*/
void setHistory(Nodes& history) { m_history = std::make_shared<Nodes>(history); }
void setHistory(Nodes& history) { m_history = history; }

/**
* @brief adds new history into existing papasevent history
Expand Down Expand Up @@ -212,7 +212,7 @@ class Event {
/**
* @brief returns the merged history
*/
std::shared_ptr<const Nodes> history() const { return m_history; }
const Nodes& history() const { return m_history; }

/**
* @brief resets everything, deletes all the clusters, tracks etc etc
Expand All @@ -233,7 +233,7 @@ class Event {
* @param[in] typeAndSubtype The type and subtype of a collection eg "em" for ecal merged
*/
Ids collectionIds(const std::string& typeAndSubtype) const;

std::string info() const; ///< text descriptor
private:
/**
* @brief templated class method used by the AddCollection methods to check that typeAndSubype match and that
Expand All @@ -255,25 +255,22 @@ class Event {
ParticlesFolder m_particlesFolder;
/// Unordered map of pointers to unordered map of (concrete) Blocks
BlocksFolder m_blocksFolder;
std::shared_ptr<Nodes> m_history; ///< points to the merged history (built from the sucessive histories)
Clusters m_emptyClusters; ///<Used to return an empty collection when no collection is found
Tracks m_emptyTracks; ///<Used to return an empty collection when no collection is found
Particles m_emptyParticles; ///<Used to return an empty collection when no collection is found
Blocks m_emptyBlocks; ///<Used to return an empty collection when no collection is found
unsigned int m_eventNo; ///<event number
Nodes& m_history; ///< points to the merged history (built from the sucessive histories)
Clusters m_emptyClusters; ///<Used to return an empty collection when no collection is found
Tracks m_emptyTracks; ///<Used to return an empty collection when no collection is found
Particles m_emptyParticles; ///<Used to return an empty collection when no collection is found
Blocks m_emptyBlocks; ///<Used to return an empty collection when no collection is found
unsigned int m_eventNo; ///<event number
};

template <class T>
void Event::addCollectionToFolderInternal(
const std::unordered_map<Identifier, T>& collection,
std::unordered_map<IdCoder::SubType, const std::unordered_map<Identifier, T>*>& folder) {
Identifier firstId = 0;
if (collection.size() == 0) return;
Identifier firstId = collection.begin()->first;
if (hasCollection(firstId)) throw "Collection already exists";
for (const auto& it : collection) {
if (!firstId) {
firstId = it.first;
if (hasCollection(firstId)) throw "Collection already exists";
}
if (IdCoder::typeAndSubtype(it.first) != IdCoder::typeAndSubtype(firstId)) {
std::cout << IdCoder::pretty(it.first) << " : " << IdCoder::pretty(firstId) << std::endl;
throw "more than one typeandSubtype found in collection";
Expand Down
16 changes: 8 additions & 8 deletions papas/datatypes/IdCoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class IdCoder {
@param[in] value: a float representing energy or momentum etc
@return identifier
*/
static Identifier makeId(unsigned int index, ItemType type, char subtype = 'u', float value = 0.0);
static Identifier makeId(uint32_t index, ItemType type, char subtype = 'u', float value = 0.0);

/** returns the item type of the identifier
This is one of: None = 0, kEcalCluster = 1, kHcalCluster, kTrack, kParticle, kBlock
Expand Down Expand Up @@ -90,12 +90,12 @@ class IdCoder {
@param[in] id: identifier
@return the index
*/
static unsigned int index(Identifier id); ///< Returns encoded index
static uint32_t index(Identifier id); ///< Returns encoded index

/** Takes an identifier and returns a unique id component of it (excludes value information)
@param[in] id: identifier
@return the index */
static unsigned int uniqueId(Identifier id); ///< Returns encoded unique id
static uint32_t uniqueId(Identifier id); ///< Returns encoded unique id

static char typeLetter(Identifier id); ///< One letter short code eg 'e' for ecal, 't' for track, 'x' for unknown
static std::string typeAndSubtype(Identifier id); ///< Two letter string of type and subtype eg "em"
Expand Down Expand Up @@ -147,12 +147,12 @@ class IdCoder {
static int bitshift() { return m_bitshift; }

private:
static const unsigned int m_bitshift1 = 61; ///< encoding parameter
static const unsigned int m_bitshift2 = 53; ///< encoding parameter
static const unsigned int m_bitshift = 21; ///< encoding parameter (max size of counter)
static const uint32_t m_bitshift1 = 61; ///< encoding parameter
static const uint32_t m_bitshift2 = 53; ///< encoding parameter
static const uint32_t m_bitshift = 21; ///< encoding parameter (max size of counter)
/// checks that the identifier can be correctly decoded
static bool checkValid(Identifier id, ItemType type, char subt, float val, unsigned int uid);
static bool checkUIDValid(Identifier id, unsigned int uniqueid);
static bool checkValid(Identifier id, ItemType type, char subt, float val, uint32_t uid);
static bool checkUIDValid(Identifier id, uint32_t uniqueid);
static uint64_t floatToBits(float value); /// convert float into binary
static float bitsToFloat(uint64_t bits); /// convert binary into float
};
Expand Down
Loading

0 comments on commit e6324c7

Please sign in to comment.