Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APRIL and SDHCALContent integration #29

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a907286
made the changes to allow the inclusion of SDHCALContent and APRILCon…
tanguypasquier Feb 27, 2024
47cb514
Update README.md
tanguypasquier Mar 4, 2024
ebd193d
Update compilation instruction
ggrenier Mar 8, 2024
08d484e
First attempt to really include APRILContent : 1 over 4 APRIL registr…
ggrenier Mar 8, 2024
0a2868f
Cleaned APRIL and solved the problem for the RegisterAlgorithms. 2 ov…
tanguypasquier Mar 11, 2024
c070114
Added a parameter that allows to choose between Pandora and APRIL dir…
tanguypasquier May 22, 2024
d6fc74c
Modified README and cleaned some comments
tanguypasquier May 22, 2024
df38b05
Fixed the CaloHitFactory problem. Not fully optimized but works
tanguypasquier May 23, 2024
751ee26
Created a new method that calls the right method to create the caloHi…
tanguypasquier May 30, 2024
ea7a897
Cleaned some comments
tanguypasquier May 30, 2024
55dd1a8
Fixed an issue with the Non-APRIL mode. Now works in all cases
tanguypasquier May 31, 2024
cdcf8f3
Deleted useless include
tanguypasquier May 31, 2024
4557661
Included the choice of the factory instead of the last option
tanguypasquier Jun 7, 2024
76d15af
Created a function allowing the registration of energy corrections an…
tanguypasquier Jun 13, 2024
fc937a7
Removed unused include
tanguypasquier Jun 13, 2024
bdc6e79
Added some comments and modified README
tanguypasquier Jul 10, 2024
d1531bc
Update README.md
tanguypasquier Jul 10, 2024
4e33c8c
Update README.md
tanguypasquier Jul 10, 2024
d49c7a0
CMakeLists updates
tanguypasquier Sep 20, 2024
d8f1d2c
Fixed Findmlpack.cmake
tanguypasquier Sep 20, 2024
d793e70
Fixed the factory issue
tanguypasquier Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
lib/
25 changes: 24 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,38 @@ FIND_PACKAGE( DD4hep REQUIRED )
FIND_PACKAGE( ROOT REQUIRED )
FIND_PACKAGE( MarlinTrk REQUIRED )

OPTION( USE_SDHCALCONTENT "Use SDHCALContent" OFF )
OPTION( USE_APRILCONTENT "Use APRILContent" OFF )

FOREACH( pkg PandoraSDK Marlin MarlinUtil LCContent DD4hep ROOT MarlinTrk )
FOREACH( pkg PandoraSDK Marlin MarlinUtil LCContent DD4hep ROOT MarlinTrk )
IF( ${pkg}_FOUND )
INCLUDE_DIRECTORIES( SYSTEM ${${pkg}_INCLUDE_DIRS} )
LINK_LIBRARIES( ${${pkg}_LIBRARIES} )
ADD_DEFINITIONS ( ${${pkg}_DEFINITIONS} )
ENDIF()
ENDFOREACH()

IF( USE_SDHCALCONTENT )
FIND_PACKAGE( SDHCALContent REQUIRED )
INCLUDE_DIRECTORIES( SYSTEM ${SDHCALContent_INCLUDE_DIRS} )
LINK_LIBRARIES( ${SDHCALContent_LIBRARIES} )
ADD_DEFINITIONS ( ${SDHCALContent_DEFINITIONS} )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDHCALContent doesn't seem to export any definitions(?): https://github.com/tanguypasquier/SDHCALContent/blob/main/cmake/SDHCALContentConfig.cmake.in

Suggested change
ADD_DEFINITIONS ( ${SDHCALContent_DEFINITIONS} )

ADD_DEFINITIONS( "-DSDHCALCONTENT" )
ENDIF()

IF( USE_APRILCONTENT )
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
FIND_PACKAGE( APRILContent REQUIRED )
FIND_PACKAGE( mlpack REQUIRED )
INCLUDE_DIRECTORIES( SYSTEM ${APRILContent_INCLUDE_DIRS} )
LINK_LIBRARIES( ${APRILContent_LIBRARIES} )
ADD_DEFINITIONS ( ${APRILContent_DEFINITIONS} )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ADD_DEFINITIONS ( ${APRILContent_DEFINITIONS} )

APRILContent doesn't seem to export any definitions(?): https://github.com/SDHCAL/APRILContent/blob/current/cmake/APRILContentConfig.cmake.in

ADD_DEFINITIONS( "-DAPRILCONTENT" )
INCLUDE_DIRECTORIES( SYSTEM ${mlpack_INCLUDE_DIRS} )
LINK_LIBRARIES( ${mlpack_LIBRARIES} )
ADD_DEFINITIONS ( ${mlpack_DEFINITIONS} )
ENDIF()

IF( PANDORA_MONITORING )
FIND_PACKAGE( PandoraMonitoring 03.00.00 REQUIRED )
IF( PandoraMonitoring_FOUND )
Expand Down
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,48 @@ DDMarlinPandora is free software: you can redistribute it and/or modify it under
This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License long with this program. If not, see <http://www.gnu.org/licenses/>.

**The following options need to be taken into consideration only if you want to use APRIL or SDHCAL plugins. If you use DDMarlinPandora in the default configuration, you can install it the usual way.**

## Options to add SDHCALContent or APRILContent

Added the compilation options to choose to include SDHCALContent or APRILContent in DDMarlinPandora.

Note, you should have sourced the init_ilcsoft.sh script

**To compile with SDHCALContent :**

1. `mkdir build`
2. `cd build`
3. `cmake -C ${ILCSOFT}/ILCSoft.cmake -DPANDORA_MONITORING=ON -DUSE_SDHCALCONTENT=ON -DSDHCALContent_DIR=/absolute/path/to/SDHCALContent ..`
4. `make install`

**To compile with APRILContent :**

mlpack should be installed. You should use the same mlpack installation as the one used to compile APRILContent


1. `mkdir build`
2. `cd build`
3. `cmake -C ${ILCSOFT}/ILCSoft.cmake -DPANDORA_MONITORING=ON -DUSE_APRILCONTENT=ON -DAPRILContent_DIR=/absolute/path/to/APRILContent -Dmlpack_DIR=/absolute/path/to/mlpack/INSTALL ..`
4. `make install`

**To compile with both SDHCALContent and APRILContent :**

Combine the two cmake options above.

## To run Marlin with this DDMarlinPandora :

1. `echo $MARLIN_DLL`
2. Copy the entire output of the previous command and find the part with the location of `libDDMarlinPandora.so`
3. Replace it with the location of the DDMarlinPandora libraries you just installed and keep the rest of the output as it is
4. `export MARLIN_DLL=/modified/output/of/echo/command`

**To choose between APRIL and Pandora when calling Marlin :**

1. Go to your ILDConfig folder in `ILDConfig/StandardConfig/production/ParticleFlow`
2. Open the xml file you are using for the PFA
3. In the section for the DDMarlinProcessor add : `<parameter name="UseAPRIL" type="bool">false</parameter>`
4. In `ILDConfig/StandardConfig/production/PandoraSettings`, put an APRILPFA settings file
5. To run Marlin with APRIL in `ILDConfig/StandardConfig/production`, add the following option when calling it : `--MyDDMarlinPandora.UseAPRIL="true" --constant.PandoraSettingsFile=PandoraSettings/YourAPRILSettingsFile.xml`

15 changes: 15 additions & 0 deletions cmake/Findmlpack.cmake
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mlpack should come with a cmake config file, so this findmlpack should not be needed
https://github.com/mlpack/mlpack/blob/master/CMake/mlpack-config.cmake.in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tanguypasquier did you check, whether you can simply remove this file and things keep working?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I indeed tried to simply remove the file but it generates some errors during the compilation. I get :

`By not providing "Findmlpack.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "mlpack", but
CMake did not find one.

Could not find a package configuration file provided by "mlpack" with any
of the following names:

mlpackConfig.cmake
mlpack-config.cmake

Add the installation prefix of "mlpack" to CMAKE_PREFIX_PATH or set
"mlpack_DIR" to a directory containing one of the above files. If "mlpack"
provides a separate development package or SDK, be sure it has been installed.`

I checked in the mlpack files for the ones mentioned in the CMake error but couldn't find any of them.

I had already encountered this error during the APRIL installation and I then came across this issue (mlpack/mlpack#444) which seemed to indicate that the best option was to have the Findmlpack.cmake file.
As it solved the problem, I didn't really tried other ways of doing it since then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you getting your mlpack from? It looks like it should be shipping a cmake configuration since v3.2.2 in principle. It might just be a question of pointing cmake into the right direction.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
IF(NOT DEFINED mlpack_DIR)
MESSAGE(STATUS "Warning: it is mandorary to define mlpack_DIR.")
ENDIF()

IF (NOT DEFINED mlpack_INCLUDE_DIRS)
SET(mlpack_INCLUDE_DIRS ${mlpack_DIR}/include)
ENDIF()

# Check mlpack core header file
FIND_PATH(mlpack_CORE_HPP_DIR NAMES core.hpp HINTS ${mlpack_INCLUDE_DIRS}/mlpack)

# Check mlpack library
#FIND_LIBRARY(mlpack_LIBRARIES NAMES mlpack HINTS ${mlpack_DIR}/*)
tmadlener marked this conversation as resolved.
Show resolved Hide resolved
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(mlpack DEFAULT_MSG mlpack_CORE_HPP_DIR)
22 changes: 22 additions & 0 deletions include/DDCaloHitCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
#include <DD4hep/Detector.h>
#include <DD4hep/DetElement.h>

#include <Pandora/PandoraObjectFactories.h>

#include <memory>


typedef std::vector<EVENT::CalorimeterHit *> CalorimeterHitVector;

#ifdef APRILCONTENT
namespace april_content { class CaloHitFactory; }
#endif


/**
* @brief DDCaloHitCreator class
*/
Expand Down Expand Up @@ -111,6 +119,8 @@ class DDCaloHitCreator
float m_hCalBarrelOuterPhi0; ///< HCal barrel outer phi0 coordinate
unsigned int m_hCalBarrelOuterSymmetry; ///< HCal barrel outer symmetry order

bool m_useAPRIL = false; ///< Choose if we want to use APRIL instead of Pandora for the reconstruction

public:
FloatVector m_eCalBarrelNormalVector;
FloatVector m_hCalBarrelNormalVector;
Expand Down Expand Up @@ -241,6 +251,12 @@ class DDCaloHitCreator
*/
float GetMaximumRadius(const EVENT::CalorimeterHit *const pCaloHit, const unsigned int symmetryOrder, const float phi0) const;

/**
* @brief Initialize the factory for calo hit creation
*
*/
void ChooseFactory();

const Settings m_settings; ///< The calo hit creator settings

const pandora::Pandora & m_pandora; ///< Reference to the pandora object to create calo hits
Expand All @@ -252,6 +268,12 @@ class DDCaloHitCreator

dd4hep::VolumeManager m_volumeManager; ///< DD4hep volume manager

//Added by T.Pasquier
std::unique_ptr<pandora::ObjectFactory<object_creation::CaloHit::Parameters, object_creation::CaloHit::Object>> m_caloHitFactory{nullptr}; //General factory to initialize

/* DDCaloHitCreator& operator=(const DDCaloHitCreator&) = delete; // Disallow copying
DDCaloHitCreator(const DDCaloHitCreator&) = delete; */
Comment on lines +274 to +275
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* DDCaloHitCreator& operator=(const DDCaloHitCreator&) = delete; // Disallow copying
DDCaloHitCreator(const DDCaloHitCreator&) = delete; */
public:
DDCaloHitCreator& operator=(const DDCaloHitCreator&) = delete;
DDCaloHitCreator(const DDCaloHitCreator&) = delete;

Since you know have a unique_ptr member copying won't work in any case. Marking these as = delete will improve the compiler error message. (I would move them to the rest of the constructors a bit further above).


};

//------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions include/DDPandoraPFANewProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class DDPandoraPFANewProcessor : public marlin::Processor
FloatVector m_ecalInputEnergyCorrectionPoints{}; ///< The input energy points for non-linearity energy correction in the ECAL
FloatVector m_ecalOutputEnergyCorrectionPoints{}; ///< The input energy points for non-linearity energy correction in the ECAL


bool m_useAPRIL = false; ///< Choose if we want to use APRIL instead of Pandora for the reconstruction

// Software compensation parameters
FloatVector m_softCompParameters{};
FloatVector m_softCompEnergyDensityBins{};
Expand Down Expand Up @@ -156,6 +159,7 @@ class DDPandoraPFANewProcessor : public marlin::Processor
*/
void Reset();


pandora::Pandora *m_pPandora = NULL; ///< Address of the pandora instance
DDCaloHitCreator *m_pCaloHitCreator = NULL; ///< The calo hit creator
DDGeometryCreator *m_pGeometryCreator = NULL; ///< The geometry creator
Expand All @@ -181,4 +185,11 @@ inline marlin::Processor *DDPandoraPFANewProcessor::newProcessor()
return new DDPandoraPFANewProcessor;
}

//------------------------------------------------------------------------------------------------------------------------------------------
//Added by T.Pasquier
/**
* @brief Register the LCContent plugins outside their original function. Temporary fix. Would be better to change the plugins registration directly in LCContent
*/
pandora::StatusCode APRILLCContentPluginRegistration(const pandora::Pandora &pandora);

#endif // #ifndef DDPANDORAPFANEWPROCESSOR_H
41 changes: 34 additions & 7 deletions src/DDCaloHitCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#include "UTIL/CellIDDecoder.h"

#ifdef APRILCONTENT
#include "APRILApi/ObjectFactories.h"
#endif

#include <DD4hep/DD4hepUnits.h>
#include <DD4hep/DetType.h>
Expand All @@ -37,7 +40,8 @@ DDCaloHitCreator::DDCaloHitCreator(const Settings &settings, const pandora::Pand
m_hCalBarrelLayerThickness(0.f),
m_hCalEndCapLayerThickness(0.f),
m_calorimeterHitVector(0),
m_volumeManager()
m_volumeManager(),
m_caloHitFactory()
{

const std::vector<dd4hep::rec::LayeredCalorimeterStruct::Layer>& barrelLayers= getExtension(( dd4hep::DetType::CALORIMETER | dd4hep::DetType::HADRONIC | dd4hep::DetType::BARREL), ( dd4hep::DetType::AUXILIARY | dd4hep::DetType::FORWARD ))->layers;
Expand All @@ -58,6 +62,8 @@ DDCaloHitCreator::DDCaloHitCreator(const Settings &settings, const pandora::Pand
m_volumeManager = theDetector.volumeManager();
}

ChooseFactory();

}

//------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -94,7 +100,7 @@ pandora::StatusCode DDCaloHitCreator::CreateECalCaloHits(const EVENT::LCEvent *c
if (0 == nElements)
continue;

streamlog_out( DEBUG1 ) << "Creating " << *iter << " hits" << std::endl;
streamlog_out( DEBUG1 ) << "Creating " << *iter << " hits" << std::endl;

const std::vector<dd4hep::rec::LayeredCalorimeterStruct::Layer>& barrelLayers= getExtension( ( dd4hep::DetType::CALORIMETER | dd4hep::DetType::ELECTROMAGNETIC | dd4hep::DetType::BARREL), ( dd4hep::DetType::AUXILIARY | dd4hep::DetType::FORWARD ) )->layers;
const std::vector<dd4hep::rec::LayeredCalorimeterStruct::Layer>& endcapLayers= getExtension( ( dd4hep::DetType::CALORIMETER | dd4hep::DetType::ELECTROMAGNETIC | dd4hep::DetType::ENDCAP), ( dd4hep::DetType::AUXILIARY | dd4hep::DetType::FORWARD ) )->layers;
Expand Down Expand Up @@ -195,7 +201,8 @@ pandora::StatusCode DDCaloHitCreator::CreateECalCaloHits(const EVENT::LCEvent *c
caloHitParameters.m_cellSize1 = splitCellSize;
}

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters));
PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters, *m_caloHitFactory));

m_calorimeterHitVector.push_back(pCaloHit);

}
Expand Down Expand Up @@ -283,7 +290,8 @@ pandora::StatusCode DDCaloHitCreator::CreateHCalCaloHits(const EVENT::LCEvent *c
caloHitParameters.m_hadronicEnergy = std::min(m_settings.m_hCalToHadGeV * pCaloHit->getEnergy(), m_settings.m_maxHCalHitHadronicEnergy);
caloHitParameters.m_electromagneticEnergy = m_settings.m_hCalToEMGeV * pCaloHit->getEnergy();

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters));
PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters, *m_caloHitFactory));

m_calorimeterHitVector.push_back(pCaloHit);
}
catch (pandora::StatusCodeException &statusCodeException)
Expand Down Expand Up @@ -385,7 +393,8 @@ pandora::StatusCode DDCaloHitCreator::CreateMuonCaloHits(const EVENT::LCEvent *c
caloHitParameters.m_mipEquivalentEnergy = pCaloHit->getEnergy() * m_settings.m_muonToMip;
}

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters));
PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters, *m_caloHitFactory));

m_calorimeterHitVector.push_back(pCaloHit);
}
catch (pandora::StatusCodeException &statusCodeException)
Expand Down Expand Up @@ -459,7 +468,8 @@ pandora::StatusCode DDCaloHitCreator::CreateLCalCaloHits(const EVENT::LCEvent *c
caloHitParameters.m_electromagneticEnergy = m_settings.m_eCalToEMGeV * pCaloHit->getEnergy();
caloHitParameters.m_hadronicEnergy = m_settings.m_eCalToHadGeVEndCap * pCaloHit->getEnergy();

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters));
PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters, *m_caloHitFactory));

m_calorimeterHitVector.push_back(pCaloHit);
}
catch (pandora::StatusCodeException &statusCodeException)
Expand Down Expand Up @@ -532,7 +542,8 @@ pandora::StatusCode DDCaloHitCreator::CreateLHCalCaloHits(const EVENT::LCEvent *
caloHitParameters.m_hadronicEnergy = std::min(m_settings.m_hCalToHadGeV * pCaloHit->getEnergy(), m_settings.m_maxHCalHitHadronicEnergy);
caloHitParameters.m_electromagneticEnergy = m_settings.m_hCalToEMGeV * pCaloHit->getEnergy();

PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters));
PANDORA_THROW_RESULT_IF(pandora::STATUS_CODE_SUCCESS, !=, PandoraApi::CaloHit::Create(m_pandora, caloHitParameters, *m_caloHitFactory));

m_calorimeterHitVector.push_back(pCaloHit);
}
catch (pandora::StatusCodeException &statusCodeException)
Expand Down Expand Up @@ -804,6 +815,22 @@ float DDCaloHitCreator::GetMaximumRadius(const EVENT::CalorimeterHit *const pCal
return maximumRadius;
}

//------------------------------------------------------------------------------------------------------------------------------------------
//Added by T. Pasquier
void DDCaloHitCreator::ChooseFactory()
{
#ifdef APRILCONTENT
if(m_settings.m_useAPRIL)
{
m_caloHitFactory = std::make_unique<april_content::CaloHitFactory>();
}
else
#endif
{
m_caloHitFactory = std::make_unique<pandora::PandoraObjectFactory<object_creation::CaloHit::Parameters, object_creation::CaloHit::Object>>();
}
}

//------------------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------------------------------------

Expand Down
Loading
Loading