Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:30:54

0001 // ----------------------------------------------------------------------------
0002 // 'CheckClustParEPProcessor.h'
0003 // Derek Anderson
0004 // 05.07.2024
0005 //
0006 // A JANA plugin to check the E/p of calorimeter
0007 // clusters and their associated MCParticles
0008 // ----------------------------------------------------------------------------
0009 
0010 #define CHECKCLUSTPAREPPROCESSOR_CC
0011 
0012 // plugin definition
0013 #include "CheckClustParEPProcessor.h"
0014 
0015 // The following just makes this a JANA plugin
0016 extern "C" {
0017   void InitPlugin(JApplication *app) {
0018     InitJANAPlugin(app);
0019     app -> Add(new CheckClustParEPProcessor);
0020   }
0021 }
0022 
0023 
0024 
0025 // public methods -------------------------------------------------------------
0026 
0027 void CheckClustParEPProcessor::InitWithGlobalRootLock() {
0028 
0029   // create output directory
0030   auto rootfile_svc = GetApplication() -> GetService<RootFile_service>();
0031   auto rootfile     = rootfile_svc -> GetHistFile();
0032   rootfile -> mkdir(m_config.sPlugin.data()) -> cd();
0033 
0034   // hist binning
0035   const tuple<size_t, float, float> epBins = make_tuple(1000, 0., 10.);
0036 
0037   // hist names
0038   const vector<string> vecHistNames = {
0039     "hNHCalEP",
0040     "hNECalEP",
0041     "hBHCalEP",
0042     "hBECalEP",
0043     "hPHCalEP",
0044     "hPECalEP"
0045   };
0046 
0047   // turn on errors
0048   TH1::SetDefaultSumw2(true);
0049 
0050   // create hists
0051   for (const string& name : vecHistNames) {
0052     m_vecHistEP.push_back(
0053       new TH1D(name.data(), "", get<0>(epBins), get<1>(epBins), get<2>(epBins))
0054     );
0055   }
0056   return;
0057 
0058 }  // end 'InitWithGlobalRootLock()'
0059 
0060 
0061 
0062 void CheckClustParEPProcessor::ProcessSequential(const std::shared_ptr<const JEvent>& event) {
0063 
0064   // grab mc particles
0065   const auto& particles = *(event -> GetCollection<edm4hep::MCParticle>(m_config.sMCPars.data()));
0066 
0067   // loop over calorimeters
0068   for (size_t iCalo = 0; iCalo < m_config.sClustAndAssocs.size(); iCalo++) {
0069 
0070     // grab collections
0071     const auto& clusters = *(event -> GetCollection<edm4eic::Cluster>(m_config.sClustAndAssocs.at(iCalo).first.data()));
0072     const auto& assocs   = *(event -> GetCollection<edm4eic::MCRecoClusterParticleAssociation>(m_config.sClustAndAssocs.at(iCalo).second.data()));
0073 
0074     // loop over clusters and associations
0075     for (auto cluster : clusters) {
0076       for (auto assoc : assocs) {
0077 
0078         // consider only current cluster
0079         const bool isSameClust = (assoc.getRecID() == cluster.getObjectID().index);
0080         if (!isSameClust) continue;
0081 
0082         // grab associated particle
0083         auto mcPar = assoc.getSim();
0084 
0085         // calculate e/p and fill hist
0086         const double ep = cluster.getEnergy() / edm4hep::utils::magnitude(mcPar.getMomentum());
0087         m_vecHistEP.at(iCalo) -> Fill(ep);
0088 
0089       } // end assoc loop
0090     }  // end cluster loop
0091   }  // end calo loop
0092   return;
0093 
0094 }  // end 'ProcessSequential(std::shared_ptr<const JEvent>&)'
0095 
0096 
0097 
0098 void CheckClustParEPProcessor::FinishWithGlobalRootLock() {
0099 
0100   /* nothing to do */
0101 
0102 }  // end 'FinishWithGlobalRootLock()'
0103 
0104 // end ------------------------------------------------------------------------