Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:04:47

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