Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:41

0001 
0002 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
0003 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
0004 
0005 #include "SimGeneral/TrackingAnalysis/interface/PSimHitSelector.h"
0006 
0007 PSimHitSelector::PSimHitSelector(edm::ParameterSet const &config, edm::ConsumesCollector &) {
0008   // Initilize psimhit collection discriminated by sub systems
0009   edm::ParameterSet pSimHitCollections = config.getParameter<edm::ParameterSet>("simHitCollections");
0010 
0011   std::vector<std::string> subdetectors(pSimHitCollections.getParameterNames());
0012 
0013   mixLabel_ = config.getParameter<std::string>("mixLabel");
0014 
0015   for (size_t i = 0; i < subdetectors.size(); ++i) {
0016     pSimHitCollectionMap_.insert(std::pair<std::string, std::vector<std::string>>(
0017         subdetectors[i], pSimHitCollections.getParameter<std::vector<std::string>>(subdetectors[i])));
0018   }
0019 }
0020 
0021 void PSimHitSelector::select(PSimHitCollection &selection,
0022                              edm::Event const &event,
0023                              edm::EventSetup const &setup) const {
0024   // Look for all psimhit collections
0025   PSimHitCollectionMap::const_iterator pSimHitCollections = pSimHitCollectionMap_.begin();
0026 
0027   std::vector<const CrossingFrame<PSimHit> *> cfPSimHitProductPointers;
0028 
0029   for (; pSimHitCollections != pSimHitCollectionMap_.end(); ++pSimHitCollections) {
0030     // Grab all the PSimHit from the different sencitive volumes
0031     edm::Handle<CrossingFrame<PSimHit>> cfPSimHits;
0032 
0033     // Collect the product pointers to the different psimhit collection
0034     for (std::size_t i = 0; i < pSimHitCollections->second.size(); ++i) {
0035       event.getByLabel(mixLabel_, pSimHitCollections->second[i], cfPSimHits);
0036       cfPSimHitProductPointers.push_back(cfPSimHits.product());
0037     }
0038   }
0039 
0040   if (cfPSimHitProductPointers.empty())
0041     return;
0042 
0043   // Create a mix collection from the different psimhit collections
0044   std::unique_ptr<MixCollection<PSimHit>> pSimHits(new MixCollection<PSimHit>(cfPSimHitProductPointers));
0045 
0046   // Select all psimhits
0047   for (MixCollection<PSimHit>::MixItr pSimHit = pSimHits->begin(); pSimHit != pSimHits->end(); ++pSimHit)
0048     selection.push_back(*pSimHit);
0049 }