CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SLHCUpgradeSimulations/L1TrackTrigger/interface/L1TkStubBuilder.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 #ifndef L1TK_STUB_BUILDER_H
00013 #define L1TK_STUB_BUILDER_H
00014 
00015 #include "FWCore/Framework/interface/Frameworkfwd.h"
00016 #include "FWCore/Framework/interface/EDProducer.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020 #include "FWCore/Framework/interface/MakerMacros.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 
00023 #include "SLHCUpgradeSimulations/L1TrackTrigger/interface/HitMatchingAlgorithm.h"
00024 #include "SLHCUpgradeSimulations/L1TrackTrigger/interface/HitMatchingAlgorithmRecord.h"
00025 #include "classNameFinder.h"
00026 
00027 #include <memory>
00028 #include <map>
00029 #include <vector>
00030 
00037 template<  typename T  >
00038 class L1TkStubBuilder : public edm::EDProducer
00039 {
00040   public:
00041     typedef std::pair< StackedTrackerDetId, unsigned int >                      ClusterKey;     
00042     typedef std::map< ClusterKey, std::vector< edm::Ptr< L1TkCluster< T > > > > L1TkClusterMap; 
00043 
00045     explicit L1TkStubBuilder( const edm::ParameterSet& iConfig );
00046 
00048     ~L1TkStubBuilder();
00049 
00050   private:
00052     const StackedTrackerGeometry               *theStackedTracker;
00053     edm::ESHandle< HitMatchingAlgorithm< T > > MatchingAlgoHandle;
00054     edm::InputTag                                           L1TkClustersInputTag;
00055 
00057     virtual void beginRun( edm::Run& run, const edm::EventSetup& iSetup );
00058     virtual void endRun( edm::Run& run, const edm::EventSetup& iSetup );
00059     virtual void produce( edm::Event& iEvent, const edm::EventSetup& iSetup );
00060 
00061 }; 
00062 
00069 
00070 template< typename T >
00071 L1TkStubBuilder< T >::L1TkStubBuilder( const edm::ParameterSet& iConfig )
00072 {
00073   produces< std::vector< L1TkStub< T > > >( "StubsPass" );
00074   produces< std::vector< L1TkStub< T > > >( "StubsFail" );
00075   L1TkClustersInputTag = iConfig.getParameter< edm::InputTag >("L1TkClusters");
00076 }
00077 
00079 template< typename T >
00080 L1TkStubBuilder< T >::~L1TkStubBuilder(){}
00081 
00083 template< typename T >
00084 void L1TkStubBuilder< T >::beginRun( edm::Run& run, const edm::EventSetup& iSetup )
00085 {
00087   edm::ESHandle< StackedTrackerGeometry > StackedTrackerGeomHandle;
00088   iSetup.get< StackedTrackerGeometryRecord >().get( StackedTrackerGeomHandle );
00089   theStackedTracker = StackedTrackerGeomHandle.product();
00090 
00092   iSetup.get< HitMatchingAlgorithmRecord >().get( MatchingAlgoHandle );
00093 
00095   std::cout << std::endl;
00096   std::cout << "L1TkStubBuilder<" << templateNameFinder<T>() << "> loaded modules:"
00097             << "\n\tHitMatchingAlgorithm:\t" << MatchingAlgoHandle->AlgorithmName()
00098             << std::endl;
00099   std::cout << std::endl;
00100   std::cout << "W A R N I N G! this producer produces two categories of stubs: accepted and rejected!" << std::endl;
00101   std::cout << "               ONLY the accepted ones are correctly filled with MC truth etc" << std::endl;
00102   std::cout << "               the rejected ones have only the clusters correctly filled in data members!" << std::endl;
00103   std::cout << std::endl;
00104 
00105 }
00106 
00108 template< typename T >
00109 void L1TkStubBuilder< T >::endRun( edm::Run& run, const edm::EventSetup& iSetup ){}
00110 
00112 template< typename T >
00113 void L1TkStubBuilder< T >::produce( edm::Event& iEvent, const edm::EventSetup& iSetup )
00114 {  
00116   std::auto_ptr< std::vector< L1TkStub< T > > > L1TkStubsForOutputAccepted( new std::vector< L1TkStub< T > > );
00117   std::auto_ptr< std::vector< L1TkStub< T > > > L1TkStubsForOutputRejected( new std::vector< L1TkStub< T > > );
00118 
00120   edm::Handle< std::vector< L1TkCluster< T > > > L1TkClusterHandle;
00121   iEvent.getByLabel( L1TkClustersInputTag, L1TkClusterHandle);   
00122 
00124   L1TkClusterMap clusterMap;
00125   clusterMap.clear();
00126   typename std::vector< L1TkCluster< T > >::const_iterator inputIter;
00127   unsigned int j = 0; 
00128 
00129   for ( inputIter = L1TkClusterHandle->begin();
00130         inputIter != L1TkClusterHandle->end();
00131         ++inputIter )
00132   {
00135     edm::Ptr< L1TkCluster< T > > tempCluPtr( L1TkClusterHandle, j++ );
00137     ClusterKey mapkey = std::make_pair( StackedTrackerDetId( inputIter->getDetId() ), inputIter->getStackMember() );
00138 
00141     if ( clusterMap.find( mapkey ) == clusterMap.end() )
00142     {
00144       std::vector< edm::Ptr< L1TkCluster< T > > > tempCluVec;
00145       tempCluVec.clear();
00146       tempCluVec.push_back( tempCluPtr );
00147       clusterMap.insert( std::pair< ClusterKey, std::vector< edm::Ptr< L1TkCluster< T > > > > ( mapkey, tempCluVec ) );
00148     }
00149     else
00150     {
00152       clusterMap[mapkey].push_back( tempCluPtr );   
00153     }
00154   }
00155 
00157   StackedTrackerGeometry::StackContainerIterator StackedTrackerIterator;
00158   for ( StackedTrackerIterator = theStackedTracker->stacks().begin();
00159         StackedTrackerIterator != theStackedTracker->stacks().end();
00160         ++StackedTrackerIterator )
00161   {
00162     StackedTrackerDetUnit* Unit = *StackedTrackerIterator;
00163     StackedTrackerDetId Id = Unit->Id();
00164     assert(Unit == theStackedTracker->idToStack(Id));
00165     
00167     ClusterKey inmapkey  = std::make_pair(Id, 0);
00168     ClusterKey outmapkey = std::make_pair(Id, 1);
00169 
00172     typename L1TkClusterMap::const_iterator innerIter = clusterMap.find(inmapkey);
00173     typename L1TkClusterMap::const_iterator outerIter = clusterMap.find(outmapkey);
00174 
00175     if ( innerIter == clusterMap.end() || outerIter == clusterMap.end() ) continue;
00176 
00177     std::vector< edm::Ptr< L1TkCluster< T > > > innerClusters = innerIter->second;
00178     std::vector< edm::Ptr< L1TkCluster< T > > > outerClusters = outerIter->second;
00179 
00180     typename std::vector< edm::Ptr< L1TkCluster< T > > >::iterator innerClusterIter, outerClusterIter;
00181 
00184     if ( innerClusters.size() && outerClusters.size() )
00185     {
00187       for ( innerClusterIter = innerClusters.begin();
00188             innerClusterIter != innerClusters.end();
00189             ++innerClusterIter )
00190       {
00191         for ( outerClusterIter = outerClusters.begin();
00192               outerClusterIter != outerClusters.end();
00193               ++outerClusterIter )
00194         {
00196           L1TkStub< T > tempL1TkStub( Id );
00197           tempL1TkStub.addClusterPtr( *innerClusterIter ); 
00198           tempL1TkStub.addClusterPtr( *outerClusterIter );
00199 
00201           bool thisConfirmation = false;
00202           int thisDisplacement = 999999;
00203           int thisOffset = 0; 
00204 
00205           MatchingAlgoHandle->CheckTwoMemberHitsForCompatibility( thisConfirmation, thisDisplacement, thisOffset, tempL1TkStub );
00206 
00208           if ( thisConfirmation )
00209           {
00210             if ( iEvent.isRealData() == false )
00211               tempL1TkStub.checkSimTrack();
00212 
00213             tempL1TkStub.setTriggerDisplacement( thisDisplacement );
00214             tempL1TkStub.setTriggerOffset( thisOffset );
00215 
00217             L1TkStubsForOutputAccepted->push_back( tempL1TkStub );
00218 
00219           } 
00220           else
00221             L1TkStubsForOutputRejected->push_back( tempL1TkStub );
00222 
00223         } 
00224       } 
00225     } 
00226   } 
00227 
00229   iEvent.put( L1TkStubsForOutputAccepted, "StubsPass" );
00230   iEvent.put( L1TkStubsForOutputRejected, "StubsFail" );
00231 }
00232 
00233 #endif
00234