Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-27 07:20:03

0001 #include <string>
0002 #include <vector>
0003 #include "GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h"
0004 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h"
0005 
0006 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0007 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0008 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0009 #include "DataFormats/Provenance/interface/BranchIDList.h"
0010 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
0011 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
0012 
0013 #include "FWCore/AbstractServices/interface/ResourceInformation.h"
0014 #include "FWCore/Utilities/interface/TypeID.h"
0015 #include "FWCore/Reflection/interface/TypeWithDict.h"
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 #include "FWCore/Version/interface/GetReleaseVersion.h"
0018 
0019 namespace edm {
0020   LHEProvenanceHelper::LHEProvenanceHelper(TypeID const& eventProductType,
0021                                            TypeID const& runProductType,
0022                                            ProductRegistry& productRegistry,
0023                                            BranchIDListHelper& branchIDListHelper)
0024       : eventProductProductDescription_(ProductDescription(InEvent,
0025                                                            "source",
0026                                                            "LHEFile"
0027                                                            // , "LHE"
0028                                                            ,
0029                                                            "LHEEventProduct",
0030                                                            "LHEEventProduct",
0031                                                            "",
0032                                                            TypeWithDict(eventProductType.typeInfo()),
0033                                                            false)),
0034         runProductProductDescription_(ProductDescription(InRun,
0035                                                          "source",
0036                                                          "LHEFile"
0037                                                          // , "LHE"
0038                                                          ,
0039                                                          "LHERunInfoProduct",
0040                                                          "LHERunInfoProduct",
0041                                                          "",
0042                                                          TypeWithDict(runProductType.typeInfo()),
0043                                                          false)),
0044         eventProductProvenance_(eventProductProductDescription_.branchID()),
0045         commonProcessParameterSet_(fillCommonProcessParameterSet()),
0046         processParameterSet_(),
0047         branchListIndexes_(1, 0) {
0048     // Add the products to the product registry
0049     auto ep = eventProductProductDescription_;
0050     ep.setIsProvenanceSetOnRead();
0051     productRegistry.copyProduct(ep);
0052     auto rp = runProductProductDescription_;
0053     rp.setIsProvenanceSetOnRead();
0054     productRegistry.copyProduct(rp);
0055     BranchIDList bli(1UL, ep.branchID().id());
0056     branchIDListHelper.updateFromInput({{bli}});
0057   }
0058 
0059   ParameterSet LHEProvenanceHelper::fillCommonProcessParameterSet() {
0060     // We create a process parameter set for the "LHC" process.
0061     // This function only fills parameters whose values are independent of the LHE input files.
0062     // We don't currently use the untracked parameters, However, we make them available, just in case.
0063     ParameterSet pset;
0064     std::string const& moduleLabel = eventProductProductDescription_.moduleLabel();
0065     std::string const& processName = eventProductProductDescription_.processName();
0066     std::string const moduleName = "LHESource";
0067     typedef std::vector<std::string> vstring;
0068     vstring empty;
0069 
0070     vstring modlbl;
0071     modlbl.reserve(1);
0072     modlbl.push_back(moduleLabel);
0073     pset.addParameter("@all_sources", modlbl);
0074 
0075     ParameterSet triggerPaths;
0076     triggerPaths.addParameter<vstring>("@trigger_paths", empty);
0077     pset.addParameter<ParameterSet>("@trigger_paths", triggerPaths);
0078 
0079     ParameterSet pseudoInput;
0080     pseudoInput.addParameter<std::string>("@module_edm_type", "Source");
0081     pseudoInput.addParameter<std::string>("@module_label", moduleLabel);
0082     pseudoInput.addParameter<std::string>("@module_type", moduleName);
0083     pset.addParameter<ParameterSet>(moduleLabel, pseudoInput);
0084 
0085     pset.addParameter<vstring>("@all_esmodules", empty);
0086     pset.addParameter<vstring>("@all_esprefers", empty);
0087     pset.addParameter<vstring>("@all_essources", empty);
0088     pset.addParameter<vstring>("@all_loopers", empty);
0089     pset.addParameter<vstring>("@all_modules", empty);
0090     pset.addParameter<vstring>("@end_paths", empty);
0091     pset.addParameter<vstring>("@paths", empty);
0092     pset.addParameter<std::string>("@process_name", processName);
0093     return pset;
0094   }
0095 
0096   void LHEProvenanceHelper::lheAugment(lhef::LHERunInfo const* runInfo) {
0097     processParameterSet_ = commonProcessParameterSet_;
0098     if (runInfo == nullptr)
0099       return;
0100     typedef std::vector<std::string> vstring;
0101     auto const& heprup = *runInfo->getHEPRUP();
0102     processParameterSet_.addParameter<int>("IDBMUP1", heprup.IDBMUP.first);
0103     processParameterSet_.addParameter<int>("IDBMUP2", heprup.IDBMUP.second);
0104     processParameterSet_.addParameter<int>("EBMUP1", heprup.EBMUP.first);
0105     processParameterSet_.addParameter<int>("EBMUP2", heprup.EBMUP.second);
0106     processParameterSet_.addParameter<int>("PDFGUP1", heprup.PDFGUP.first);
0107     processParameterSet_.addParameter<int>("PDFGUP2", heprup.PDFGUP.second);
0108     processParameterSet_.addParameter<int>("PDFSUP1", heprup.PDFSUP.first);
0109     processParameterSet_.addParameter<int>("PDFSUP2", heprup.PDFSUP.second);
0110     processParameterSet_.addParameter<int>("IDWTUP", heprup.IDWTUP);
0111     for (auto const& header : runInfo->getHeaders()) {
0112       if (!LHERunInfoProduct::isTagComparedInMerge(header.tag())) {
0113         continue;
0114       }
0115       processParameterSet_.addParameter<vstring>(header.tag(), header.lines());
0116     }
0117   }
0118 
0119   ProcessHistoryID LHEProvenanceHelper::lheInit(ProcessHistoryRegistry& processHistoryRegistry) {
0120     // Now we register the process parameter set.
0121     processParameterSet_.registerIt();
0122     //std::cerr << processParameterSet_.dump() << std::endl;
0123 
0124     // Insert an entry for this process in the process history registry
0125     ProcessHistory ph;
0126     edm::Service<edm::ResourceInformation> resourceInformationService;
0127     edm::HardwareResourcesDescription hwResources;
0128     if (resourceInformationService.isAvailable()) {
0129       hwResources = resourceInformationService->hardwareResourcesDescription();
0130     }
0131     ph.emplace_back(
0132         eventProductProductDescription_.processName(), processParameterSet_.id(), getReleaseVersion(), hwResources);
0133     processHistoryRegistry.registerProcessHistory(ph);
0134 
0135     // Save the process history ID for use every event.
0136     return ph.id();
0137   }
0138 
0139 }  // namespace edm