CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/SLHCUpgradeSimulations/L1TrackTrigger/plugins/L1TrackProducer.cc

Go to the documentation of this file.
00001 
00002 //  Producer by Anders  //
00003 //     and Emmanuele    //
00004 //    july 2012 @ CU    //
00006 
00007 
00008 #ifndef L1TTRACK_PRDC_H
00009 #define L1TTRACK_PRDC_H
00010 
00012 // FRAMEWORK HEADERS
00013 #include "FWCore/PluginManager/interface/ModuleDef.h"
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 //
00016 // #include "FWCore/Framework/interface/EDAnalyzer.h"
00017 #include "FWCore/Framework/interface/EDProducer.h"
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020 #include "FWCore/Framework/interface/EventSetup.h"
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 //
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025 #include "FWCore/ServiceRegistry/interface/Service.h"
00026 
00028 // DATA FORMATS HEADERS
00029 #include "DataFormats/Common/interface/Handle.h"
00030 #include "DataFormats/Common/interface/EDProduct.h"
00031 #include "DataFormats/Common/interface/Ref.h"
00032 //
00033 #include "DataFormats/DetId/interface/DetId.h"
00034 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h" 
00035 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h" 
00036 #include "DataFormats/Common/interface/DetSetVector.h"
00037 //
00038 #include "SimDataFormats/SLHC/interface/StackedTrackerTypes.h"
00039 #include "SimDataFormats/SLHC/interface/slhcevent.hh"
00040 //#include "SimDataFormats/SLHC/interface/L1TRod.hh"
00041 //#include "SimDataFormats/SLHC/interface/L1TSector.hh"
00042 #include "SimDataFormats/SLHC/interface/L1TBarrel.hh"
00043 #include "SimDataFormats/SLHC/interface/L1TDisk.hh"
00044 #include "SimDataFormats/SLHC/interface/L1TStub.hh"
00045 //#include "SimDataFormats/SLHC/interface/L1TWord.hh"
00046 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00047 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00048 #include "SimDataFormats/Track/interface/SimTrack.h"
00049 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00050 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00051 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00052 //
00053 #include "DataFormats/Math/interface/LorentzVector.h"
00054 #include "DataFormats/Math/interface/Vector3D.h"
00055 //
00056 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00057 #include "DataFormats/Candidate/interface/Candidate.h"
00058 //
00059 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
00060 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00061 #include "DataFormats/SiPixelDetId/interface/PixelChannelIdentifier.h"
00062 #include "TrackingTools/GeomPropagators/interface/HelixArbitraryPlaneCrossing.h"
00064 // FAST SIMULATION STUFF
00065 #include "FastSimulation/Particle/interface/RawParticle.h"
00066 #include "FastSimulation/BaseParticlePropagator/interface/BaseParticlePropagator.h"
00067 
00069 // DETECTOR GEOMETRY HEADERS
00070 #include "MagneticField/Engine/interface/MagneticField.h"
00071 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00072 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00073 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00074 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetType.h"
00075 #include "Geometry/TrackerGeometryBuilder/interface/PixelTopologyBuilder.h"
00076 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00077 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
00078 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00079 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00080 //
00081 #include "Geometry/Records/interface/StackedTrackerGeometryRecord.h"
00082 #include "Geometry/TrackerGeometryBuilder/interface/StackedTrackerGeometry.h"
00083 #include "Geometry/TrackerGeometryBuilder/interface/StackedTrackerDetUnit.h"
00084 #include "DataFormats/SiPixelDetId/interface/StackedTrackerDetId.h"
00085 //#include "SLHCUpgradeSimulations/Utilities/interface/classInfo.h" REMOVE
00086 
00088 // PHYSICS TOOLS
00089 #include "RecoTracker/TkSeedGenerator/interface/FastHelix.h"
00090 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00091 //
00092 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h"
00093 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
00094 //#include "SLHCUpgradeSimulations/Utilities/interface/constants.h" REMOVE
00095 
00097 // STD HEADERS
00098 #include <memory>
00099 #include <string>
00100 #include <iostream>
00101 #include <fstream>
00102 
00104 // NAMESPACES
00105 // using namespace std;
00106 // using namespace reco;
00107 using namespace edm;
00108 //using namespace cmsUpgrades;
00109 
00110 
00112 //                          //
00113 //     CLASS DEFINITION     //
00114 //                          //
00116 
00118 // this class is needed to make a map
00119 // between different types of stubs
00120 class L1TStubCompare 
00121 {
00122 public:
00123   bool operator()(const L1TStub& x, const L1TStub& y) {
00124     if (x.layer() != y.layer()) return (y.layer()-x.layer())>0;
00125     else {
00126       if (x.ladder() != y.ladder()) return (y.ladder()-x.ladder())>0;
00127       else {
00128         if (x.module() != y.module()) return (y.module()-x.module())>0;
00129         else {
00130           if (x.iz() != y.iz()) return (y.iz()-x.iz())>0;
00131           else return (x.iphi()-y.iphi())>0;
00132         }
00133       }
00134     }
00135   }
00136 };
00137 
00138 
00139 class L1TrackProducer : public edm::EDProducer
00140 {
00141 public:
00142 
00143   typedef L1TkStub_PixelDigi_                           L1TkStubType;
00144   typedef std::vector< L1TkStubType >                                L1TkStubCollectionType;
00145   typedef edm::Ptr< L1TkStubType >                                   L1TkStubPtrType;
00146   typedef std::vector< L1TkStubPtrType >                             L1TkStubPtrCollection;
00147   typedef std::vector< L1TkStubPtrCollection >                       L1TkStubPtrCollVectorType;
00148 
00149   //typedef L1TkTracklet_PixelDigi_                       L1TkTrackletType;
00150   //typedef std::vector< L1TkTrackletType >                            L1TkTrackletCollectionType;
00151   //typedef edm::Ptr< L1TkTrackletType >                               L1TkTrackletPtrType;
00152 
00153   typedef L1TkTrack_PixelDigi_                          L1TkTrackType;
00154   typedef std::vector< L1TkTrackType >                               L1TkTrackCollectionType;
00155   typedef std::vector< L1TTrack >                                    L1TrackCollectionType;
00156 
00158   explicit L1TrackProducer(const edm::ParameterSet& iConfig);
00159   virtual ~L1TrackProducer();
00160 
00161 protected:
00162                      
00163 private:
00164   GeometryMap geom;
00165   int eventnum;
00166 
00168   edm::ParameterSet config;
00169 
00170   string geometry_;
00171 
00174   virtual void beginRun( edm::Run& run, const edm::EventSetup& iSetup );
00175   virtual void endRun( edm::Run& run, const edm::EventSetup& iSetup );
00176   virtual void produce( edm::Event& iEvent, const edm::EventSetup& iSetup );
00177 };
00178 
00179 
00181 // CONSTRUCTOR
00182 L1TrackProducer::L1TrackProducer(edm::ParameterSet const& iConfig) // :   config(iConfig)
00183 {
00184   //produces<L1TrackCollectionType>( "Level1Tracks" ).setBranchAlias("Level1Tracks");
00185   produces< L1TkStubPtrCollVectorType >( "L1TkStubs" ).setBranchAlias("L1TkStubs");
00186   produces< L1TkTrackCollectionType >( "Level1TkTracks" ).setBranchAlias("Level1TkTracks");
00187   // produces<L1TkStubMapType>( "L1TkStubMap" ).setBranchAlias("L1TkStubMap");
00188   // produces< L1TkTrackletCollectionType >( "L1TkTracklets" ).setBranchAlias("L1TkTracklets");
00189 
00190   geometry_ = iConfig.getUntrackedParameter<string>("geometry","");
00191 }
00192 
00194 // DESTRUCTOR
00195 L1TrackProducer::~L1TrackProducer()
00196 {
00199 }  
00200 
00202 // END JOB
00203 void L1TrackProducer::endRun(edm::Run& run, const edm::EventSetup& iSetup)
00204 {
00206 
00207 }
00208 
00210 // BEGIN JOB
00211 void L1TrackProducer::beginRun(edm::Run& run, const edm::EventSetup& iSetup )
00212 {
00213   eventnum=0;
00214   std::cout << "L1TrackProducer" << std::endl;
00215 }
00216 
00218 // PRODUCE
00219 void L1TrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00220 {
00221 
00222   typedef std::map< L1TStub, L1TkStubPtrType, L1TStubCompare > stubMapType;
00223 
00225   //std::auto_ptr< L1TrackCollectionType > L1TracksForOutput( new L1TrackCollectionType );
00226   std::auto_ptr< L1TkStubPtrCollVectorType > L1TkStubsForOutput( new L1TkStubPtrCollVectorType );
00227   //std::auto_ptr< L1TkTrackletCollectionType > L1TkTrackletsForOutput( new L1TkTrackletCollectionType );
00228   std::auto_ptr< L1TkTrackCollectionType > L1TkTracksForOutput( new L1TkTrackCollectionType );
00229 
00231   edm::ESHandle<TrackerGeometry>                               geometryHandle;
00232   const TrackerGeometry*                                       theGeometry;
00233   edm::ESHandle<StackedTrackerGeometry>           stackedGeometryHandle;
00234   const StackedTrackerGeometry*                   theStackedGeometry;
00235   StackedTrackerGeometry::StackContainerIterator  StackedTrackerIterator;
00236 
00239   iSetup.get<TrackerDigiGeometryRecord>().get(geometryHandle);
00240   theGeometry = &(*geometryHandle);
00242   iSetup.get<StackedTrackerGeometryRecord>().get(stackedGeometryHandle);
00243   theStackedGeometry = stackedGeometryHandle.product(); 
00244 
00245 
00246   // GET MAGNETIC FIELD //
00247   edm::ESHandle<MagneticField> magneticFieldHandle;
00248   iSetup.get<IdealMagneticFieldRecord>().get(magneticFieldHandle);
00249   const MagneticField* theMagneticField = magneticFieldHandle.product();
00250   double mMagneticFieldStrength = theMagneticField->inTesla(GlobalPoint(0,0,0)).z();
00251 
00253   // GET BS //
00255   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00256   iEvent.getByLabel("BeamSpotFromSim","BeamSpot",recoBeamSpotHandle);
00257   math::XYZPoint bsPosition=recoBeamSpotHandle->position();
00258 
00259   cout << "L1TrackProducer: B="<<mMagneticFieldStrength
00260        <<" vx reco="<<bsPosition.x()
00261        <<" vy reco="<<bsPosition.y()
00262        <<" vz reco="<<bsPosition.z()
00263        <<endl;
00264 
00265   SLHCEvent ev;
00266   ev.setIPx(bsPosition.x());
00267   ev.setIPy(bsPosition.y());
00268   eventnum++;
00269 
00270   cout << "Get simtracks"<<endl;
00271 
00273   // GET SIMTRACKS //
00274   edm::Handle<edm::SimTrackContainer>   simTrackHandle;
00275   edm::Handle<edm::SimVertexContainer>  simVtxHandle;
00276   //iEvent.getByLabel( "famosSimHits", simTrackHandle );
00277   //iEvent.getByLabel( "famosSimHits", simVtxHandle );
00278   iEvent.getByLabel( "g4SimHits", simTrackHandle );
00279   iEvent.getByLabel( "g4SimHits", simVtxHandle );
00280 
00282   // GET MC PARTICLES //
00283   edm::Handle<reco::GenParticleCollection> genpHandle;
00284   iEvent.getByLabel( "genParticles", genpHandle );
00285 
00286   cout << "Get pixel digis"<<endl;
00287 
00289   // GET PIXEL DIGIS //
00290   edm::Handle<edm::DetSetVector<PixelDigi> >         pixelDigiHandle;
00291   edm::Handle<edm::DetSetVector<PixelDigiSimLink> >  pixelDigiSimLinkHandle;
00292   iEvent.getByLabel("simSiPixelDigis", pixelDigiHandle);
00293   iEvent.getByLabel("simSiPixelDigis", pixelDigiSimLinkHandle);
00294 
00295   cout << "Get stubs and clusters"<<endl;
00296 
00298   // GET THE PRIMITIVES //
00299   edm::Handle<L1TkCluster_PixelDigi_Collection>  pixelDigiL1TkClusterHandle;
00300   edm::Handle<L1TkStub_PixelDigi_Collection>     pixelDigiL1TkStubHandle;
00301   iEvent.getByLabel("L1TkClustersFromPixelDigis", pixelDigiL1TkClusterHandle);
00302   iEvent.getByLabel("L1TkStubsFromPixelDigis", "StubsPass", pixelDigiL1TkStubHandle);
00303 
00304   cout << "Will loop over simtracks" <<endl;
00305 
00308   SimTrackContainer::const_iterator iterSimTracks;
00309   for ( iterSimTracks = simTrackHandle->begin();
00310         iterSimTracks != simTrackHandle->end();
00311         ++iterSimTracks ) {
00312 
00314     int vertexIndex = iterSimTracks->vertIndex();
00315     const SimVertex& theSimVertex = (*simVtxHandle)[vertexIndex];
00316     math::XYZTLorentzVectorD trkVtxPos = theSimVertex.position();
00317     GlobalPoint trkVtxCorr = GlobalPoint( trkVtxPos.x() - bsPosition.x(), 
00318                                           trkVtxPos.y() - bsPosition.y(), 
00319                                           trkVtxPos.z() - bsPosition.z() );
00320     
00321     double pt=iterSimTracks->momentum().pt();
00322     if (pt!=pt) pt=9999.999;
00323     ev.addL1SimTrack(iterSimTracks->trackId(),iterSimTracks->type(),pt,
00324                      iterSimTracks->momentum().eta(), 
00325                      iterSimTracks->momentum().phi(), 
00326                      trkVtxCorr.x(),
00327                      trkVtxCorr.y(),
00328                      trkVtxCorr.z());
00329    
00330     
00331   } 
00332 
00333 
00334   std::cout << "Will loop over digis:"<<std::endl;
00335 
00336   DetSetVector<PixelDigi>::const_iterator iterDet;
00337   for ( iterDet = pixelDigiHandle->begin();
00338         iterDet != pixelDigiHandle->end();
00339         iterDet++ ) {
00340 
00342     DetId tkId( iterDet->id );
00343     StackedTrackerDetId stdetid(tkId);
00345     if ( tkId.subdetId() == 2 ) {
00346 
00347       PXFDetId pxfId(tkId);
00348       DetSetVector<PixelDigiSimLink>::const_iterator itDigiSimLink1=pixelDigiSimLinkHandle->find(pxfId.rawId());
00349       if (itDigiSimLink1!=pixelDigiSimLinkHandle->end()){
00350         DetSet<PixelDigiSimLink> digiSimLink = *itDigiSimLink1;
00351         //DetSet<PixelDigiSimLink> digiSimLink = (*pixelDigiSimLinkHandle)[ pxfId.rawId() ];
00352         DetSet<PixelDigiSimLink>::const_iterator iterSimLink;
00354 
00355         int disk = pxfId.disk();
00356         
00357         if (disk<4) {
00358           continue;
00359         }
00360 
00361         disk-=3;
00362         
00363         // Layer 0-20
00364         //DetId digiDetId = iterDet->id;
00365         //int sensorLayer = 0.5*(2*PXFDetId(digiDetId).layer() + (PXFDetId(digiDetId).ladder() + 1)%2 - 8);
00366         
00368         DetSet<PixelDigi>::const_iterator iterDigi;
00369         for ( iterDigi = iterDet->data.begin();
00370               iterDigi != iterDet->data.end();
00371               iterDigi++ ) {
00372       
00374           if ( iterDigi->adc() <= 30 ) continue;
00375             
00377           const GeomDetUnit* gDetUnit = theGeometry->idToDetUnit( tkId );
00378           MeasurementPoint mp( iterDigi->row() + 0.5, iterDigi->column() + 0.5 );
00379           GlobalPoint pdPos = gDetUnit->surface().toGlobal( gDetUnit->topology().localPosition( mp ) ) ;
00380             
00381           int offset=1000;
00382 
00383           if (pxfId.side()==1) {
00384             offset=2000;
00385           }
00386 
00387           assert(pxfId.panel()==1);
00388 
00389           vector<int> simtrackids;
00392           for ( iterSimLink = digiSimLink.data.begin();
00393                 iterSimLink != digiSimLink.data.end();
00394                 iterSimLink++) {
00395                 
00397             if ( (int)iterSimLink->channel() == iterDigi->channel() ) {
00398                     
00400               unsigned int simTrackId = iterSimLink->SimTrackId();
00401               simtrackids.push_back(simTrackId); 
00402             }
00403           }
00404         ev.addDigi(offset+disk,iterDigi->row(),iterDigi->column(),
00405                    pxfId.blade(),pxfId.panel(),pxfId.module(),
00406                    pdPos.x(),pdPos.y(),pdPos.z(),simtrackids);
00407         }
00408       }
00409     }
00410 
00411     if ( tkId.subdetId() == 1 ) {
00413       PXBDetId pxbId(tkId);
00414       DetSetVector<PixelDigiSimLink>::const_iterator itDigiSimLink=pixelDigiSimLinkHandle->find(pxbId.rawId());
00415       if (itDigiSimLink==pixelDigiSimLinkHandle->end()){
00416         continue;
00417       }
00418       DetSet<PixelDigiSimLink> digiSimLink = *itDigiSimLink;
00419       //DetSet<PixelDigiSimLink> digiSimLink = (*pixelDigiSimLinkHandle)[ pxbId.rawId() ];
00420       DetSet<PixelDigiSimLink>::const_iterator iterSimLink;
00422       if ( pxbId.layer() < 5 ) {
00423         continue;
00424         
00425       }
00426 
00427       // Layer 0-20
00428       DetId digiDetId = iterDet->id;
00429       int sensorLayer = 0.5*(2*PXBDetId(digiDetId).layer() + (PXBDetId(digiDetId).ladder() + 1)%2 - 8);
00430       
00432       DetSet<PixelDigi>::const_iterator iterDigi;
00433       for ( iterDigi = iterDet->data.begin();
00434             iterDigi != iterDet->data.end();
00435             iterDigi++ ) {
00436         
00438         if ( iterDigi->adc() <= 30 ) continue;
00439         
00441         const GeomDetUnit* gDetUnit = theGeometry->idToDetUnit( tkId );
00442         MeasurementPoint mp( iterDigi->row() + 0.5, iterDigi->column() + 0.5 );
00443         GlobalPoint pdPos = gDetUnit->surface().toGlobal( gDetUnit->topology().localPosition( mp ) ) ;
00444         
00447         vector<int > simtrackids;
00448         for ( iterSimLink = digiSimLink.data.begin();
00449               iterSimLink != digiSimLink.data.end();
00450               iterSimLink++) {
00451             
00453           if ( (int)iterSimLink->channel() == iterDigi->channel() ) {
00454                 
00456             unsigned int simTrackId = iterSimLink->SimTrackId();
00457             simtrackids.push_back(simTrackId);
00458           }
00459         }
00460         ev.addDigi(sensorLayer,iterDigi->row(),iterDigi->column(),
00461                    pxbId.layer(),pxbId.ladder(),pxbId.module(),
00462                    pdPos.x(),pdPos.y(),pdPos.z(),simtrackids);
00463       }
00464     }
00465   }    
00466 
00467 
00468   cout << "Will loop over stubs" << endl;
00469 
00471   L1TkStub_PixelDigi_Collection::const_iterator iterL1TkStub;
00472   for ( iterL1TkStub = pixelDigiL1TkStubHandle->begin();
00473         iterL1TkStub != pixelDigiL1TkStubHandle->end();
00474         ++iterL1TkStub ) {
00475 
00476     double stubPt = theStackedGeometry->findRoughPt(mMagneticFieldStrength,&(*iterL1TkStub));
00477         
00478     if (stubPt>10000.0) stubPt=9999.99;
00479     GlobalPoint stubPosition = theStackedGeometry->findGlobalPosition(&(*iterL1TkStub));
00480 
00481     StackedTrackerDetId stubDetId = iterL1TkStub->getDetId();
00482     unsigned int iStack = stubDetId.iLayer();
00483     unsigned int iRing = stubDetId.iRing();
00484     unsigned int iPhi = stubDetId.iPhi();
00485     unsigned int iZ = stubDetId.iZ();
00486 
00487     std::vector<bool> innerStack;
00488     std::vector<int> irphi;
00489     std::vector<int> iz;
00490     std::vector<int> iladder;
00491     std::vector<int> imodule;
00492 
00493 
00494     if (iStack==999999) {
00495       iStack=1000+iRing;
00496     }
00497 
00498 
00500     edm::Ptr<L1TkCluster_PixelDigi_> innerCluster = iterL1TkStub->getClusterPtr(0);
00501 
00502     const DetId innerDetId = theStackedGeometry->idToDet( innerCluster->getDetId(), 0 )->geographicalId();
00503 
00504     for (unsigned int ihit=0;ihit<innerCluster->getHits().size();ihit++){
00505 
00506       std::pair<int,int> rowcol=PixelChannelIdentifier::channelToPixel(innerCluster->getHits().at(ihit)->channel());
00507     
00508       if (iStack<1000) {
00509         innerStack.push_back(true);
00510         irphi.push_back(rowcol.first);
00511         iz.push_back(rowcol.second);
00512         iladder.push_back(PXBDetId(innerDetId).ladder());
00513         imodule.push_back(PXBDetId(innerDetId).module());
00514       }
00515       else {
00516         innerStack.push_back(true);
00517         irphi.push_back(rowcol.first);
00518         iz.push_back(rowcol.second);
00519         iladder.push_back(PXFDetId(innerDetId).disk());
00520         imodule.push_back(PXFDetId(innerDetId).module());
00521       }    
00522     }
00523 
00524 
00525     edm::Ptr<L1TkCluster_PixelDigi_> outerCluster = iterL1TkStub->getClusterPtr(1);
00526       
00527     const DetId outerDetId = theStackedGeometry->idToDet( outerCluster->getDetId(), 1 )->geographicalId();
00528 
00529     for (unsigned int ihit=0;ihit<outerCluster->getHits().size();ihit++){
00530 
00531       std::pair<int,int> rowcol=PixelChannelIdentifier::channelToPixel(outerCluster->getHits().at(ihit)->channel());
00532     
00533       if (iStack<1000) {
00534         innerStack.push_back(false);
00535         irphi.push_back(rowcol.first);
00536         iz.push_back(rowcol.second);
00537         iladder.push_back(PXBDetId(outerDetId).ladder());
00538         imodule.push_back(PXBDetId(outerDetId).module());
00539       }
00540       else {
00541         innerStack.push_back(false);
00542         irphi.push_back(rowcol.first);
00543         iz.push_back(rowcol.second);
00544         iladder.push_back(PXFDetId(outerDetId).disk());
00545         imodule.push_back(PXFDetId(outerDetId).module());
00546       }    
00547     }    
00548 
00549     ev.addStub(iStack-1,iPhi,iZ,stubPt,
00550                stubPosition.x(),stubPosition.y(),stubPosition.z(),
00551                innerStack,irphi,iz,iladder,imodule);
00552         
00553   }
00554 
00555 
00556   std::cout << "Will actually do L1 tracking:"<<std::endl;
00557 
00558 
00560   // NOW RUN THE L1 tracking
00561 
00562 
00563   int mode = 0;
00564 
00565   // mode means:
00566   // 1 LB_6PS
00567   // 2 LB_4PS_2SS
00568   // 3 EB
00569 
00570   //cout << "geometry:"<<geometry_<<endl;
00571 
00572   if (geometry_=="LB_6PS") mode=1;
00573   if (geometry_=="LB_4PS_2SS") mode=2;
00574   if (geometry_=="BE") mode=3;
00575 
00576 
00577 
00578   assert(mode==1||mode==2||mode==3);
00579 
00580 #include "L1Tracking.icc"  
00581 
00582 
00583   
00584   for (unsigned itrack=0; itrack<purgedTracks.size(); itrack++) {
00585     L1TTrack track=purgedTracks.get(itrack);
00586 
00587     //L1TkTrackType TkTrack(TkStubs, aSeedTracklet);
00588     L1TkTrackType TkTrack;
00589     //double frac;
00590     //TkTrack.setSimTrackId(track.simtrackid(frac));  FIXME
00591     //TkTrack.setRadius(1./track.rinv());  FIXME
00592     //GlobalPoint bsPosition(recoBeamSpotHandle->position().x(),
00593     //                     recoBeamSpotHandle->position().y(),
00594     //                     track.z0()
00595     //                     ); //store the L1 track vertex position 
00596     GlobalPoint bsPosition(0.0,
00597                            0.0,
00598                            track.z0()
00599                            ); //store the L1 track vertex position 
00600     //TkTrack.setVertex(bsPosition);  FIXME
00601     //TkTrack.setChi2RPhi(track.chisq1()); FIXME
00602     //TkTrack.setChi2ZPhi(track.chisq2()); FIXME
00603     //cout << "L1TrackProducer Track with pt="<<track.pt(mMagneticFieldStrength)<<endl;
00604     TkTrack.setMomentum( GlobalVector ( GlobalVector::Cylindrical(fabs(track.pt(mMagneticFieldStrength)), 
00605                                                                   track.phi0(), 
00606                                                                   fabs(track.pt(mMagneticFieldStrength))*sinh(track.eta())) ) );
00607 
00608     L1TkTracksForOutput->push_back(TkTrack);
00609 
00610     vector<L1TkStubPtrType> TkStubs;
00611     L1TTracklet tracklet = track.getSeed();
00612     vector<L1TStub> stubComponents;// = tracklet.getStubComponents();
00613     vector<L1TStub> stubs = track.getStubs();
00614     //L1TkTrackletType TkTracklet;
00615 
00616     stubMapType::iterator it;
00617     //for (it = stubMap.begin(); it != stubMap.end(); it++) {
00618       //if (it->first == stubComponents[0] || it->first == stubComponents[1]) {
00619       //L1TkStubPtrType TkStub = it->second;
00620         //if (TkStub->getStack()%2 == 0)
00621         //  TkTracklet.addStub(0, TkStub);
00622         //else
00623         //  TkTracklet.addStub(1, TkStub);
00624       //}
00625       
00626       //for (int j=0; j<(int)stubs.size(); j++) {
00627     //  if (it->first == stubs[j])
00628     //  TkStubs.push_back(it->second);
00629     //}
00630     //}
00631 
00632     L1TkStubsForOutput->push_back( TkStubs );
00633     //TkTracklet.checkSimTrack();
00634     //TkTracklet.fitTracklet(mMagneticFieldStrength, GlobalPoint(bsPosition.x(), bsPosition.y(), 0.0), true);
00635     //L1TkTrackletsForOutput->push_back( TkTracklet );
00636   }
00637 
00638 
00639 
00640   // }
00641 
00642   iEvent.put( L1TkStubsForOutput, "L1TkStubs");
00643   //iEvent.put( L1TkTrackletsForOutput, "L1TkTracklets" );
00644   iEvent.put( L1TkTracksForOutput, "Level1TkTracks");
00645 
00646 } 
00647 
00648 
00649 // ///////////////////////////
00650 // // DEFINE THIS AS A PLUG-IN
00651 DEFINE_FWK_MODULE(L1TrackProducer);
00652 
00653 #endif