Skip to content
Snippets Groups Projects
Commit 70367235 authored by Will Buttinger's avatar Will Buttinger Committed by Graeme Stewart
Browse files

' Made error messages just warnings when metadata is missing, and ensured will...

' Made error messages just warnings when metadata is missing, and ensured will only display once per file' (EvgenProdTools-00-02-21)

	* Made error messages just warnings when metadata is missing, and ensured will only display once per file
	* tagging EvgenProdTools-00-02-21

2015-06-25 Will Buttinger <will@cern.ch>
         * Made safe for AthAnalysisBase usage ... had to do if HepMCWeightSvc will live in this package
         * tagging EvgenProdTools-00-02-20

2015-06-23 Ewelina Maria Lobodzinska <ewelina@mail.desy.de>
        *  event print-out (for corrupted events) only when testSeq.TestHepMC.DumpEvent=1 specified in JOs
        *  tagging EvgenProdTools-00-02-19

2015-06-11 Will Buttinger <will@cern.ch>
        * committed first attempt at HepMCWeightSvc, which will be used by the McEventCollection TPConvertor to read and write weight names from and to metadata
        * this is more efficient than storing the same weight names over and over in the file
        * Holding off tagging until this is tested
parent 1c723fbf
No related branches found
No related tags found
No related merge requests found
Showing
with 339 additions and 14 deletions
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#ifndef EVGENPRODTOOLS_COPYEVENTWEIGHT_H
#define EVGENPRODTOOLS_COPYEVENTWEIGHT_H
......@@ -38,3 +40,5 @@ private:
#endif
#endif
\ No newline at end of file
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#ifndef EVGENPRODTOOLS_COUNTHEPMC_H
#define EVGENPRODTOOLS_COUNTHEPMC_H
......@@ -37,3 +39,5 @@ private:
#endif
#endif
\ No newline at end of file
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#ifndef EVGENPRODTOOLS_EVGENOTFTOPUPSVC_H
#define EVGENPRODTOOLS_EVGENOTFTOPUPSVC_H
......@@ -59,3 +61,5 @@ private:
};
#endif
#endif
\ No newline at end of file
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#ifndef FIX_HEPMC
#define FIX_HEPMC
......@@ -58,4 +60,6 @@ private:
};
#endif
#endif
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef EVGENPRODTOOLS_IHEPMCWEIGHTSVC_H
#define EVGENPRODTOOLS_IHEPMCWEIGHTSVC_H
#include "GaudiKernel/IInterface.h"
#include <string>
/// @brief IService to read/write HepMC's WeightContainer key names from/to IOVMetaDataContainers
/// author: will buttinger , NLAA
///
///
static const InterfaceID IID_IHepMCWeightSvc("IHepMCWeightSvc", 1 , 0);
class IHepMCWeightSvc : virtual public IInterface {
public:
///checks for any changes to weightnames ... none are allowed. Then records to metadata
virtual StatusCode setWeightNames(const std::map<std::string, std::size_t>& weightNames)= 0;
///returns the current weight names ... will only change at file boudaries, it is assumed all events in a given file will have same weights in SAME ORDER
virtual const std::map<std::string, std::size_t>& weightNames() = 0;
static const InterfaceID& interfaceID() { return IID_IHepMCWeightSvc; }
};
#endif
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#ifndef EVGENPRODTOOLS_TESTHEPMC_H
#define EVGENPRODTOOLS_TESTHEPMC_H
......@@ -121,3 +123,5 @@ public:
#endif
#endif
\ No newline at end of file
......@@ -2,6 +2,7 @@ package EvgenProdTools
author Andy Buckley <andy.buckley@cern.ch>
author Zach Marshall <zach.marshall@cern.ch>
author Will Buttinger <will@cern.ch>
use AtlasPolicy AtlasPolicy-*
use AtlasHepMC AtlasHepMC-* External
......@@ -15,6 +16,10 @@ use AthenaKernel AthenaKernel-* Control
use TruthUtils TruthUtils-* Generators
use GaudiInterface GaudiInterface-* External
use EventInfo EventInfo-* Event
use IOVDbMetaDataTools IOVDbMetaDataTools-* Database
use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL
use IOVDbDataModel IOVDbDataModel-* Database
end_private
#use AtlasHepMC AtlasHepMC-* External
......
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#include "EvgenProdTools/CopyEventWeight.h"
#include "EventInfo/EventInfo.h"
#include "EventInfo/EventType.h"
......@@ -47,3 +49,5 @@ StatusCode CopyEventWeight::execute() {
return StatusCode::SUCCESS;
}
#endif
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#include "EvgenProdTools/CountHepMC.h"
#include "GaudiKernel/IEventProcessor.h"
#include "GaudiKernel/IAlgManager.h"
......@@ -104,3 +106,5 @@ StatusCode CountHepMC::finalize() {
ATH_MSG_INFO("Events passing all checks and written = " << m_nPass);
return StatusCode::SUCCESS;
}
#endif
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#include "EvgenProdTools/EvgenOTFTopUpSvc.h"
EvgenOTFTopUpSvc::EvgenOTFTopUpSvc(const std::string& name, ISvcLocator* pSvcLocator)
......@@ -34,3 +36,4 @@ StatusCode EvgenOTFTopUpSvc::queryInterface(const InterfaceID& riid, void** ppvI
return StatusCode::SUCCESS;
}
#endif
\ No newline at end of file
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#include "EvgenProdTools/FixHepMC.h"
#include "TruthUtils/HepMCUtils.h"
using namespace std;
......@@ -156,3 +158,5 @@ bool FixHepMC::isLoop(const HepMC::GenParticle* p) {
}
//@}
#endif
\ No newline at end of file
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "HepMCWeightSvc.h"
#include "AthenaPoolUtilities/CondAttrListCollection.h"
#include "EventInfo/EventInfo.h"
#include "EventInfo/EventType.h"
#include "EventInfo/EventID.h"
#include "EventInfo/EventStreamInfo.h"
#include "IOVDbDataModel/IOVMetaDataContainer.h"
HepMCWeightSvc::HepMCWeightSvc(const std::string& name, ISvcLocator* pSvcLocator)
: AthService(name, pSvcLocator),
m_metaDataTool("IOVDbMetaDataTool")
{
}
bool HepMCWeightSvc::weightNamesChanged(const std::map<std::string, std::size_t>& weightNames) {
//check all weights are the same
if(m_currentWeightNames.size() != weightNames.size()) {
return true;
}
auto itr1 = m_currentWeightNames.begin();
auto itr2 = weightNames.begin();
for(;itr1!=m_currentWeightNames.end();++itr1,++itr2) {
if( itr1->first != itr2->first ) return true;
if( itr1->second != itr2->second ) return true;
}
return false;
}
StatusCode HepMCWeightSvc::initialize() {
ServiceHandle<IIncidentSvc> incsvc("IncidentSvc",name());
int priority = 100;
incsvc->addListener( this, IncidentType::BeginInputFile, priority);
return StatusCode::SUCCESS;
}
void HepMCWeightSvc::handle(const Incident& inc) {
if(inc.type()==IncidentType::BeginInputFile) { //resets the weight names
m_weightNamesLoaded = false;
m_currentWeightNames.clear();
}
}
StatusCode HepMCWeightSvc::loadWeights() {
//clear the currentWeightNames
m_currentWeightNames.clear();
m_weightNamesLoaded = true; //regardless of success or failure, we will say the weights are loaded!
//read the weight map from the metadata, it will be std::map<std::string,int> so we need to convert to our internal type
ServiceHandle<StoreGateSvc> inputMetaStore("StoreGateSvc/InputMetaDataStore",name());
CHECK( inputMetaStore.retrieve() );
const IOVMetaDataContainer* cont = 0;
if(inputMetaStore->retrieve(cont,"/Generation/Parameters").isFailure()) {
//exit quietly... will print the warning in the calling method
return StatusCode::FAILURE;
}
//payload is a collection of condattrlistcollections
//only look a the first one, assuming it exists, and within that only look at the first channel;
if(! (cont->payloadContainer()->size()>0 && cont->payloadContainer()->at(0)->size()>0) ) return StatusCode::FAILURE;
//need to retrieve the EventStreamInfo to get at the channel number
const EventStreamInfo* esi = 0;
CHECK( inputMetaStore->retrieve(esi) );
if(esi->getEventTypes().size() == 0) return StatusCode::FAILURE;
int chanNum = esi->getEventTypes().begin()->mc_channel_number();
if(chanNum==0) {
//perhaps channel number not set yet, use the first run number instead
if(esi->getRunNumbers().size()==0) return StatusCode::FAILURE;
chanNum = *esi->getRunNumbers().begin();
}
const coral::Attribute& attr = cont->payloadContainer()->at(0)->attributeList(chanNum)["HepMCWeightNames"];
std::map<std::string, int> in;
CHECK( Gaudi::Parsers::parse(in,attr.data<std::string>()) );
ATH_MSG_DEBUG("Loaded weightnames: " << attr.data<std::string>());
for(auto& i : in) m_currentWeightNames[i.first] = i.second;
return StatusCode::SUCCESS;
}
StatusCode HepMCWeightSvc::setWeightNames(const std::map<std::string, std::size_t>& weightNames) {
if(m_weightNamesLoaded) return StatusCode::SUCCESS; //we only allow setting of weightNames ONCE!
//check that the weight names correspond to what we have currently.
if( weightNamesChanged(weightNames) ) {
m_currentWeightNames = weightNames;
//create and register the metadata containter with these weight names
//use the MetaDataTool to do this
CHECK( m_metaDataTool->registerFolder("/Generation/Parameters","Metadata created during Event Generation") );
//create a new attributelist collection for it ...
CondAttrListCollection* cont = new CondAttrListCollection(true /* use regular timestamps, not run-lumiblock timestamps */);
//create a single attribute list
CondAttrListCollection::AttributeList myAttributes;
//store as strings ... when read back in we use a gaudi parser to parse the list
myAttributes.extend("HepMCWeightNames","string");
std::string stringToStore = "{";
for(auto& name : weightNames) {
if(stringToStore != "{") stringToStore += ", ";
std::stringstream ss;
ss << "'" << name.first << "':" << name.second; stringToStore += ss.str();
}
stringToStore += "}";
myAttributes["HepMCWeightNames"].data<std::string>() = stringToStore;
//use the run-number as the 'channel' ... all weightnames should be the same for the same channel
//set the start time ... do we set the stop time?
const EventInfo* evt = 0;
ServiceHandle<StoreGateSvc> evtStore("StoreGateSvc/StoreGateSvc",name());
CHECK( evtStore->retrieve(evt) );
//IOVTime evtTime;
//evtTime.setRunEvent(evt->event_ID()->run_number(), evt->event_ID()->lumi_block());
//uint64_t nsTime=evt->event_ID()->time_stamp()*1000000000LL;
//nsTime += evt->event_ID()->time_stamp_ns_offset();
//evtTime.setTimestamp(nsTime);
//cont->addNewStart(evtTime);
cont->add(evt->event_ID()->run_number(),myAttributes);
ATH_MSG_DEBUG("Storing /Generation/Parameters :: WeightNames = " << stringToStore);
//and assign it to 'channel 0' .. consistent with other metadata
CHECK( m_metaDataTool->addPayload("/Generation/Parameters",cont) );
m_weightNamesLoaded=true;
}
return StatusCode::SUCCESS;
}
const std::map<std::string,std::size_t>& HepMCWeightSvc::weightNames() {
if(!m_weightNamesLoaded) {
if(loadWeights().isFailure()) { ATH_MSG_WARNING("Unable to load weightnames from metadata ... do not trust the weightnames!"); }
}
return m_currentWeightNames;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef EVGENPRODTOOLS_HEPMCWEIGHTSVC_H
#define EVGENPRODTOOLS_HEPMCWEIGHTSVC_H
#include "AthenaBaseComps/AthService.h"
#include "EvgenProdTools/IHepMCWeightSvc.h"
#include <string>
#include "IOVDbMetaDataTools/IIOVDbMetaDataTool.h"
#include "GaudiKernel/IIncidentListener.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/ToolHandle.h"
/// @brief Service to read/write HepMC's WeightContainer key names from/to IOVMetaDataContainers
/// author: will buttinger , NLAA
///
///
class HepMCWeightSvc : public AthService , public IHepMCWeightSvc, virtual public IIncidentListener {
public:
// Constructor and destructor
HepMCWeightSvc(const std::string& name, ISvcLocator* pSvcLocator);
~HepMCWeightSvc() {;}
///checks for any changes to weightnames ... none are allowed. Then records to metadata
virtual StatusCode setWeightNames(const std::map<std::string, std::size_t>& weightNames);
///returns the current weight names ... will only change at file boudaries, it is assumed all events in a given file will have same weights in SAME ORDER
virtual const std::map<std::string, std::size_t>& weightNames();
virtual StatusCode initialize();
virtual void handle(const Incident& inc); //listen for beginInputFile and load the weights at that point
StatusCode queryInterface(const InterfaceID& riid, void** ppvInterface) {
if(IID_IHepMCWeightSvc == riid) {
*ppvInterface = dynamic_cast<IHepMCWeightSvc*>(this);
return StatusCode::SUCCESS;
}
return AthService::queryInterface(riid,ppvInterface);
}
private:
bool weightNamesChanged(const std::map<std::string, std::size_t>& weightNames);
StatusCode loadWeights(); //reads from the IOVMetaData
std::map<std::string, std::size_t> m_currentWeightNames;
ToolHandle<IIOVDbMetaDataTool> m_metaDataTool;
bool m_weightNamesLoaded;
};
#endif
......@@ -2,6 +2,8 @@
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef XAOD_ANALYSIS
#include "EvgenProdTools/TestHepMC.h"
#include "GaudiKernel/DataSvc.h"
......@@ -289,16 +291,23 @@ StatusCode TestHepMC::execute() {
HepMC::GenVertex::particle_iterator par = (*vitr)->particles_begin(HepMC::parents);
for (; par != (*vitr)->particles_end(HepMC::parents); ++par) {
std::cout << "Outgoing particle : " << std::endl;
(*par)->print();
std::cout << "production vertex = " << (*par)->production_vertex()->point3d().x() << ", " << (*par)->production_vertex()->point3d().y() << ", " << (*par)->production_vertex()->point3d().z() << endl;
std::cout << "end vertex = " << (*par)->end_vertex()->point3d().x() << ", " << (*par)->end_vertex()->point3d().y() << ", " << (*par)->end_vertex()->point3d().z() << endl;
std::cout << "parents info: " << std::endl;
// std::cout << "Outgoing particle : " << std::endl;
// (*par)->print();
ATH_MSG_WARNING("Outgoing particle : ");
if (m_dumpEvent) (*par)->print();
ATH_MSG_WARNING("production vertex = " << (*par)->production_vertex()->point3d().x() << ", " << (*par)->production_vertex()->point3d().y() << ", " << (*par)->production_vertex()->point3d().z());
ATH_MSG_WARNING("end vertex = " << (*par)->end_vertex()->point3d().x() << ", " << (*par)->end_vertex()->point3d().y() << ", " << (*par)->end_vertex()->point3d().z());
ATH_MSG_WARNING("parents info: ");
// std::cout << "production vertex = " << (*par)->production_vertex()->point3d().x() << ", " << (*par)->production_vertex()->point3d().y() << ", " << (*par)->production_vertex()->point3d().z() << endl;
// std::cout << "end vertex = " << (*par)->end_vertex()->point3d().x() << ", " << (*par)->end_vertex()->point3d().y() << ", " << (*par)->end_vertex()->point3d().z() << endl;
// std::cout << << std::endl;
if ((*par)->production_vertex()) {
HepMC::GenVertex::particle_iterator p_parents = (*par)->production_vertex()->particles_begin(HepMC::parents);
for(; p_parents != (*par)->production_vertex()->particles_end(HepMC::parents); ++p_parents) {
cout << "\t";
(*p_parents)->print();
// cout << "\t";
if (m_dumpEvent) (*p_parents)->print();
ATH_MSG_WARNING("\t");
}
}
......@@ -356,7 +365,7 @@ StatusCode TestHepMC::execute() {
ATH_MSG_WARNING("NaN (Not A Number) or inf found in the event record momenta");
++m_partMomentumNANandINFCheckRate;
++m_nFail;
if (m_dumpEvent) (*itr)->print();
if (m_dumpEvent) (*pitr)->print();
setFilterPassed(false);
return StatusCode::SUCCESS;
}
......@@ -376,7 +385,8 @@ StatusCode TestHepMC::execute() {
double plifetime = pd->lifetime()*1e+12; // why lifetime doesn't come in common units???
if (plifetime != 0 && plifetime < m_min_tau) { // particles with infinite lifetime get a 0 in the PDT
ATH_MSG_WARNING("Stable particle found with lifetime = " << plifetime << "~ns!!");
(*pitr)->print();
if (m_dumpEvent) (*pitr)->print();
++m_Status1ShortLifetime;
++m_nFail;
setFilterPassed(false);
......@@ -396,7 +406,8 @@ StatusCode TestHepMC::execute() {
}
if (susyPart==0){
ATH_MSG_WARNING("Stable particle not found in PDT, no lifetime check done");
(*pitr)->print();
if (m_dumpEvent) (*pitr)->print();
}
}
}
......@@ -528,10 +539,10 @@ StatusCode TestHepMC::execute() {
double lostE = fabs(totalE - cmenergy);
if (lostE > m_energy_diff) {
ATH_MSG_WARNING("ENERGY BALANCE FAILED : E-difference = " << lostE << " MeV");
if (m_dumpEvent || lostE > m_energy_diff) {
(*itr)->print();
std::cout << "balance " << totalPx << " " << totalPy << " " << totalPz << " " << totalE << std::endl;
}
// std::cout << "balance " << totalPx << " " << totalPy << " " << totalPz << " " << totalE << std::endl;
ATH_MSG_WARNING("balance " << totalPx << " " << totalPy << " " << totalPz << " " << totalE);
if (m_doHist){
m_h_energyImbalance->Fill(lostE*1.E-03);
// std::cout << "hidt filled " << std::endl;
......@@ -687,3 +698,6 @@ StatusCode TestHepMC::finalize() {
return StatusCode::SUCCESS;
}
#endif
\ No newline at end of file
#include "GaudiKernel/DeclareFactoryEntries.h"
#ifndef XAOD_ANALYSIS
#include "EvgenProdTools/CopyEventWeight.h"
#include "EvgenProdTools/CountHepMC.h"
#include "EvgenProdTools/FixHepMC.h"
......@@ -11,12 +12,19 @@ DECLARE_ALGORITHM_FACTORY(CountHepMC)
DECLARE_ALGORITHM_FACTORY(FixHepMC)
DECLARE_ALGORITHM_FACTORY(TestHepMC)
DECLARE_SERVICE_FACTORY(EvgenOTFTopUpSvc)
#endif
#include "../HepMCWeightSvc.h"
DECLARE_SERVICE_FACTORY(HepMCWeightSvc)
DECLARE_FACTORY_ENTRIES( EvgenProdTools ) {
#ifndef XAOD_ANALYSIS
DECLARE_ALGORITHM( ExpressionGenFilter )
DECLARE_ALGORITHM(CopyEventWeight)
DECLARE_ALGORITHM(CountHepMC)
DECLARE_ALGORITHM(FixHepMC)
DECLARE_ALGORITHM(TestHepMC)
DECLARE_SERVICE(EvgenOTFTopUpSvc)
#endif
DECLARE_SERVICE(HepMCWeightSvc)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment