CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/SimGeneral/TrackingAnalysis/src/PSimHitSelector.cc

Go to the documentation of this file.
00001 
00002 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00003 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00004 
00005 #include "SimGeneral/TrackingAnalysis/interface/PSimHitSelector.h"
00006 
00007 PSimHitSelector::PSimHitSelector(edm::ParameterSet const & config)
00008 {
00009     // Initilize psimhit collection discriminated by sub systems
00010     edm::ParameterSet pSimHitCollections = config.getParameter<edm::ParameterSet>("simHitCollections");
00011 
00012     std::vector<std::string> subdetectors( pSimHitCollections.getParameterNames() );
00013 
00014     mixLabel_ = config.getParameter<std::string>("mixLabel");
00015 
00016     for (size_t i = 0; i < subdetectors.size(); ++i)
00017     {
00018         pSimHitCollectionMap_.insert(
00019             std::pair<std::string, std::vector<std::string> >(
00020                 subdetectors[i],
00021                 pSimHitCollections.getParameter<std::vector<std::string> >(subdetectors[i])
00022             )
00023         );
00024     }
00025 }
00026 
00027 
00028 void PSimHitSelector::select(PSimHitCollection & selection, edm::Event const & event, edm::EventSetup const & setup) const
00029 {
00030     // Look for all psimhit collections
00031     PSimHitCollectionMap::const_iterator pSimHitCollections = pSimHitCollectionMap_.begin();
00032 
00033     std::vector<const CrossingFrame<PSimHit> *> cfPSimHitProductPointers;
00034 
00035     for (; pSimHitCollections != pSimHitCollectionMap_.end(); ++pSimHitCollections)
00036     {
00037         // Grab all the PSimHit from the different sencitive volumes
00038         edm::Handle<CrossingFrame<PSimHit> > cfPSimHits;
00039 
00040         // Collect the product pointers to the different psimhit collection
00041         for (std::size_t i = 0; i < pSimHitCollections->second.size(); ++i)
00042         {
00043             event.getByLabel(mixLabel_, pSimHitCollections->second[i], cfPSimHits);
00044             cfPSimHitProductPointers.push_back(cfPSimHits.product());
00045         }
00046     }
00047 
00048     if (cfPSimHitProductPointers.empty()) return;
00049 
00050     // Create a mix collection from the different psimhit collections
00051     std::auto_ptr<MixCollection<PSimHit> > pSimHits(new MixCollection<PSimHit>(cfPSimHitProductPointers));
00052 
00053     // Select all psimhits
00054     for (MixCollection<PSimHit>::MixItr pSimHit = pSimHits->begin(); pSimHit != pSimHits->end(); ++pSimHit)
00055         selection.push_back(*pSimHit);
00056 }