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 #37 from alicerobson/attempt2
Browse files Browse the repository at this point in the history
Attempt2
  • Loading branch information
cbernet authored Sep 4, 2017
2 parents 087f8d4 + f3688cb commit fee61f5
Show file tree
Hide file tree
Showing 27 changed files with 25,929 additions and 140 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ You need to install:
Before installing and everytime you want to use this software on lxplus, set up your environment:

```bash
source /cvmfs/fcc.cern.ch/sw/0.8/init_fcc_stack.sh
source init.sh
```

Expand Down
11 changes: 8 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ install(TARGETS example_simple DESTINATION bin)
install(TARGETS example_loop DESTINATION bin)
install(TARGETS example_pdebug DESTINATION bin)
install(TARGETS example_plot DESTINATION bin)
#install(TARGETS example_root DESTINATION bin)

FILE(GLOB files "${CMAKE_SOURCE_DIR}/examples/data/*")
INSTALL(FILES ${files} DESTINATION data/)

# --- adding tests for examples ------------------------------
add_test(NAME fcc-generate COMMAND $ENV{FCCPHYSICS}/bin/fcc-pythia8-generate $ENV{FCCPHYSICS}/share/ee_ZH_Zmumu_Hbb.txt WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
add_test(NAME example_loop COMMAND $ENV{FCCPAPASCPP}/bin/example_loop ee_ZH_Zmumu_Hbb.root WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )

#set_property(TEST example_loop PROPERTY DEPENDS fcc-generate)
set_property(TEST example_loop PROPERTY DEPENDS fcc-generate)
add_test(NAME test_debug_cms COMMAND /bin/bash $ENV{FCCPAPASCPP}/data/pdebug_CMS.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
set_tests_properties(test_debug_cms PROPERTIES PASS_REGULAR_EXPRESSION "compare.out matches")
add_test(NAME test_debug_clic COMMAND /bin/bash $ENV{FCCPAPASCPP}/data/pdebug_CLIC.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
set_tests_properties(test_debug_clic PROPERTIES PASS_REGULAR_EXPRESSION "compare.out matches")
152 changes: 93 additions & 59 deletions examples/PythiaConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "papas/detectors/Field.h"
#include "papas/display/PFApp.h"
#include "papas/simulation/Simulator.h"
#include "papas/utility/Log.h"
#include "papas/utility/Logger.h"
#include "papas/utility/PDebug.h"

#include <exception>
Expand All @@ -43,7 +43,7 @@ PythiaConnector::PythiaConnector(const char* fname) : m_store(podio::EventStore(
if (access(fname, F_OK) != -1) {
m_reader.openFile(fname);
} else {
throw "File not found";
PAPASLOG_ERROR("File not found");
}
m_store.setReader(&m_reader);
}
Expand Down Expand Up @@ -119,7 +119,41 @@ void PythiaConnector::processEvent(unsigned int eventNo, papas::PapasManager& pa
papasManager.simplifyBlocks('r');
papasManager.reconstruct('s');
} catch (std::string message) {
papas::Log::error("An error occurred and event was discarsed. Event no: {} : {}", eventNo, message);
std::string outstring =
string_format("An error occurred and event was discarded. Event no: %d : %s", eventNo, message.c_str());
PAPASLOG_ERROR(outstring);
} catch (...) {
PAPASLOG_ERROR("unknown error occured");
}
m_store.clear();
}
m_reader.endOfEvent();
}

void PythiaConnector::processEvent(unsigned int eventNo, std::shared_ptr<papas::PapasManager> papasManager) {
// make a papas particle collection from the next event
// then run simulate and reconstruct
m_reader.goToEvent(eventNo);
papasManager->setEventNo(eventNo);
const fcc::MCParticleCollection* ptcs;
if (m_store.get("GenParticle", ptcs)) {
try {
papasManager->clear();
papas::Particles& genParticles = papasManager->createParticles();
makePapasParticlesFromGeneratedParticles(ptcs, genParticles, papasManager->detector());
papasManager->addParticles(genParticles);
papasManager->simulate('s');
papasManager->mergeClusters("es");
papasManager->mergeClusters("hs");
papasManager->buildBlocks('m', 'm', 's');
papasManager->simplifyBlocks('r');
papasManager->reconstruct('s');
} catch (std::string message) {
std::string outstring =
string_format("An error occurred and event was discarded. Event no: %i : %s", eventNo, message.c_str());
PAPASLOG_ERROR(outstring);
} catch (...) {
PAPASLOG_ERROR("unknown error occured");
}
m_store.clear();
}
Expand Down Expand Up @@ -166,69 +200,69 @@ void PythiaConnector::writeParticlesROOT(const char* fname, const papas::Particl
}

/*
void PythiaConnector::writeClustersROOT(const char* fname, const papas::Clusters& clusters) {
void PythiaConnector::writeClustersROOT(const char* fname, const papas::Clusters& clusters) {
podio::ROOTWriter writer(fname, &m_store);
unsigned int nevents = 1;
unsigned int eventno = 0;
auto& evinfocoll = m_store.create<fcc::EventInfoCollection>("evtinfo");
auto& ccoll = m_store.create<fcc::CaloClusterCollection>("Cluster");
podio::ROOTWriter writer(fname, &m_store);
unsigned int nevents = 1;
unsigned int eventno = 0;
auto& evinfocoll = m_store.create<fcc::EventInfoCollection>("evtinfo");
auto& ccoll = m_store.create<fcc::CaloClusterCollection>("Cluster");
writer.registerForWrite("evtinfo");
writer.registerForWrite("Cluster");
writer.registerForWrite("evtinfo");
writer.registerForWrite("Cluster");
auto evinfo = fcc::EventInfo(); // evinfocoll.create();
evinfo.number(eventno);
evinfocoll.push_back(evinfo);
AddClustersToEDM(clusters, ccoll);
auto evinfo = fcc::EventInfo(); // evinfocoll.create();
evinfo.number(eventno);
evinfocoll.push_back(evinfo);
AddClustersToEDM(clusters, ccoll);
auto checkClusters = ConvertClustersToPapas(ccoll,
0, // size or 0 for merged
papas::IdCoder::ItemType::kEcalCluster,
's');
auto checkClusters = ConvertClustersToPapas(ccoll,
0, // size or 0 for merged
papas::IdCoder::ItemType::kEcalCluster,
's');
writer.writeEvent();
m_store.clearCollections();
writer.finish();
}
writer.writeEvent();
m_store.clearCollections();
writer.finish();
}
papas::Clusters PythiaConnector::ConvertClustersToPapas(const fcc::CaloClusterCollection& fccClusters,
float size,
papas::IdCoder::ItemType itemtype,
char subtype) const {
papas::Clusters clusters;
for (const auto& c : fccClusters) {
const auto position = c.core().position;
const auto energy = c.core().energy;
papas::Cluster cluster(energy, TVector3(position.x, position.y, position.z), size, clusters.size(), itemtype,
subtype);
clusters.emplace(cluster.id(), std::move(cluster));
}
return clusters;
}
papas::Clusters PythiaConnector::ConvertClustersToPapas(const fcc::CaloClusterCollection& fccClusters,
float size,
papas::IdCoder::ItemType itemtype,
char subtype) const {
papas::Clusters clusters;
for (const auto& c : fccClusters) {
const auto position = c.core().position;
const auto energy = c.core().energy;
papas::Cluster cluster(energy, TVector3(position.x, position.y, position.z), size, clusters.size(), itemtype,
subtype);
clusters.emplace(cluster.id(), std::move(cluster));
}
return clusters;
}
void PythiaConnector::AddClustersToEDM(const papas::Clusters& papasClusters, fcc::CaloClusterCollection& fccClusters) {
for (const auto& c : papasClusters) {
auto clust = fccClusters.create();
clust.core().energy = c.second.energy();
auto& p3 = clust.core().position;
p3.x = c.second.position().X();
p3.y = c.second.position().Y();
p3.z = c.second.position().Z();
}
}
*/
void PythiaConnector::AddClustersToEDM(const papas::Clusters& papasClusters, fcc::CaloClusterCollection& fccClusters) {
for (const auto& c : papasClusters) {
auto clust = fccClusters.create();
clust.core().energy = c.second.energy();
auto& p3 = clust.core().position;
p3.x = c.second.position().X();
p3.y = c.second.position().Y();
p3.z = c.second.position().Z();
}
}
*/
/*void PythiaConnector::readClustersROOT(unsigned int eventNo, papas::PapasManager& papasManager) {
const fcc::ParticleCollection* ptcs(nullptr);
if (m_store.get("GenParticle", ptcs)) {
papas::Particles papasparticles = makePapasClustersFromCaloClusts(ptcs);
papasManager.storeParticles(std::move(papasparticles));
papasManager.simulateEvent();
papasManager.mergeClusters();
papasManager.reconstructEvent();
m_store.clear();
}
const fcc::ParticleCollection* ptcs(nullptr);
if (m_store.get("GenParticle", ptcs)) {
papas::Particles papasparticles = makePapasClustersFromCaloClusts(ptcs);
papasManager.storeParticles(std::move(papasparticles));
papasManager.simulateEvent();
papasManager.mergeClusters();
papasManager.reconstructEvent();
m_store.clear();
}
m_reader.endOfEvent();
}*/
m_reader.endOfEvent();
}*/
2 changes: 2 additions & 0 deletions examples/PythiaConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class PythiaConnector {
// todo find new home;
void displayEvent(const papas::PapasManager& papasManager);
void processEvent(unsigned int eventNo, papas::PapasManager& papasManager); ///<reads and processes a Pythia event
void processEvent(unsigned int eventNo,
std::shared_ptr<papas::PapasManager> papasManager); ///<reads and processes a Pythia event

///< Takes pythia particles and creates Papas type particles adding them into
/// an empty Particles collection
Expand Down
Binary file added examples/data/ee_ZH_Zmumu_Hbb.root
Binary file not shown.
Binary file added examples/data/ee_Z_ddbar.root
Binary file not shown.
38 changes: 38 additions & 0 deletions examples/data/pdebug_CLIC.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#This file runs a Clic example to produce a physics debug output file
#The physics output is then compared against the required physics file
#The required file will need to be updated when the physics changes
FILE="compare.out"
PHYSICS="physicsdd.txt"
MATCHPHYSICS=$FCCPAPASCPP/data/required_clic_physics_dd.txt
ROOTFILE=$FCCPAPASCPP/data/ee_Z_ddbar.root
if [ -f $FILE ]
then
rm $FILE
fi
if [ -f $PHYSICS ]
then
rm $PHYSICS
fi
$FCCPAPASCPP/bin/example_pdebug $ROOTFILE CLIC $PHYSICS
if ([ -f $PHYSICS ] && [ -f $MATCHPHYSICS ])
then
#echo "difference files"
diff $MATCHPHYSICS $PHYSICS > $FILE

if [ -f $FILE ]
then
if [[ -s $FILE ]];
then
echo "$FILE is different"
else
echo "$FILE matches"
rm $FILE
rm $PHYSICS
fi
else
echo "$FILE not found."
fi
else
echo "$PHYSICS not found."
fi
38 changes: 38 additions & 0 deletions examples/data/pdebug_CMS.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
#This file runs a CMS example to produce a physics debug output file
#The physics output is then compared against the required physics file
#The required file will need to be updated when the physics changes
FILE="compare.out"
PHYSICS="physics.txt"
MATCHPHYSICS=$FCCPAPASCPP/data/required_cms_physics.txt
ROOTFILE=$FCCPAPASCPP/data/ee_ZH_Zmumu_Hbb.root
if [ -f $FILE ]
then
rm $FILE
fi
if [ -f $PHYSICS ]
then
rm $PHYSICS
fi
$FCCPAPASCPP/bin/example_pdebug $ROOTFILE CMS $PHYSICS
if ([ -f $PHYSICS ] && [ -f $MATCHPHYSICS ])
then
#echo "difference files"
diff $MATCHPHYSICS $PHYSICS > $FILE

if [ -f $FILE ]
then
if [[ -s $FILE ]];
then
echo "$FILE is different"
else
echo "$FILE matches"
rm $FILE
rm $PHYSICS
fi
else
echo "$FILE not found."
fi
else
echo "$PHYSICS not found."
fi
Loading

0 comments on commit fee61f5

Please sign in to comment.