CMS 3D CMS Logo

HITrackVertexMaker.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    TestMuL1L2
00004 // Class:      TestMuL1L2
00005 //
00006 // \class TestMuL1L2 TestMuL1L2.cc TestMuonL1L2/TestMuL1L2/src/TestMuL1L2.cc
00007 //
00008 // Original Author:  Dong Ho Moon
00009 //         Created:  Wed May  9 06:22:36 CEST 2007
00010 // $Id: HITrackVertexMaker.cc,v 1.9 2009/02/20 08:48:19 kodolova Exp $
00011 //
00012 //
00013  
00014 #include "RecoHIMuon/HiMuTracking/interface/HITrackVertexMaker.h" 
00015 
00016 // C++ Headers
00017 
00018 #include <memory>
00019 #include<iostream>
00020 #include<iomanip>
00021 #include<vector>
00022 #include<cmath>
00023 
00024 // ES include files 
00025 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00026 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00027 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
00028 
00029 // Muon trigger includes 
00030 #include "L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h"
00031 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
00032 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
00033 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuRegionalCand.h"
00034 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00035 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00036 
00037 // Tracking includes
00038 #include "DataFormats/TrackReco/interface/Track.h"
00039 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00040 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00041 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00042 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00043 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
00044 #include "TrackingTools/GeomPropagators/interface/StateOnTrackerBound.h"
00045 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00046 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00047 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00048 #include "TrackingTools/TrajectoryFiltering/interface/RegionalTrajectoryFilter.h"
00049 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00050 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00051 #include "RecoTracker/TkNavigation/interface/NavigationSchoolFactory.h"
00052 #include "DataFormats/TrackReco/interface/TrackBase.h"
00053 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
00054 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00055 #include "DataFormats/VertexReco/interface/Vertex.h"
00056 #include "RecoVertex/KalmanVertexFit/interface/KalmanVertexFitter.h"
00057 #include "TrackingTools/PatternTools/interface/TrajectoryStateClosestToBeamLineBuilder.h"
00058 #include "RecoTracker/TkNavigation/interface/SimpleNavigationSchool.h"
00059 #include "TrackingTools/DetLayers/interface/NavigationSetter.h"
00060 #include "TrackingTools/DetLayers/interface/NavigationSchool.h"
00061 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00062 #include "DataFormats/TrackReco/interface/TrackBase.h"
00063 #include "TrackingTools/PatternTools/interface/TrajectorySmoother.h"
00064 #include "TrackingTools/PatternTools/interface/TrajectoryFitter.h"
00065 // Geometry includes
00066 
00067 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00068 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00069 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00070 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00071 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00072 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00073 #include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
00074 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00075 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00076 
00077 // RecoHIMuon includes
00078 
00079 #include "RecoHIMuon/HiMuSeed/interface/HICFTSfromL1orL2.h"
00080 #include "RecoHIMuon/HiMuSeed/interface/HICConst.h"
00081 #include "RecoHIMuon/HiMuPropagator/interface/FastMuPropagator.h"
00082 #include "RecoHIMuon/HiMuPropagator/interface/FmpConst.h"
00083 #include "RecoHIMuon/HiMuPropagator/interface/HICTkOuterStartingLayerFinder.h"
00084 #include "RecoHIMuon/HiMuSeed/interface/DiMuonSeedGeneratorHIC.h"
00085 #include "RecoHIMuon/HiMuTracking/interface/HICTrajectoryBuilder.h"
00086 #include "RecoHIMuon/HiMuTracking/interface/HICSimpleNavigationSchool.h"
00087 #include "RecoHIMuon/HiMuTracking/interface/HICMuonUpdator.h"
00088 #include "RecoHIMuon/HiMuSeed/interface/HICConst.h"
00089 
00090 // Global  points
00091 
00092 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00093 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00094 
00095 
00096 //Constructor
00097 
00098 using namespace reco;
00099 using namespace std;
00100 
00101 //#define DEBUG
00102 
00103 namespace cms{
00104 HITrackVertexMaker::HITrackVertexMaker(const edm::ParameterSet& ps1, const edm::EventSetup& es1)
00105 {
00106 
00107    L2candTag_          = ps1.getParameter< edm::InputTag > ("L2CandTag");
00108    rphirecHitsTag      = ps1.getParameter< edm::InputTag > ("rphiRecHits");
00109    builderName         = ps1.getParameter< std::string > ("TTRHBuilder");
00110    primaryVertexTag    = ps1.getParameter< edm::InputTag > ("PrimaryVertexTag");
00111 
00112 #ifdef DEBUG
00113    std::cout<<" Start HI TrackVertexMaker constructor "<<std::endl;
00114 #endif
00115    pset_ = ps1;
00116 
00117 //
00118 // Initializetion from Records
00119     es1.get<TrackerRecoGeometryRecord>().get( tracker );
00120     es1.get<IdealMagneticFieldRecord>().get(magfield);
00121     es1.get<CkfComponentsRecord>().get("",measurementTrackerHandle);
00122     es1.get<TransientRecHitRecord>().get(builderName,recHitBuilderHandle); 
00123        
00124     double theChiSquareCut = 500.;
00125     double nsig = 3.;
00126     int theLowMult = 1;
00127     theEstimator = new HICMeasurementEstimator(&(*tracker), &(*magfield), theChiSquareCut, nsig);
00128     std::string updatorName = "KFUpdator";
00129     std::string propagatorAlongName    = "PropagatorWithMaterial";
00130     std::string propagatorOppositeName = "PropagatorWithMaterialOpposite";
00131     es1.get<TrackingComponentsRecord>().get(propagatorAlongName,propagatorAlongHandle);
00132     es1.get<TrackingComponentsRecord>().get(propagatorOppositeName,propagatorOppositeHandle);
00133     es1.get<TrackingComponentsRecord>().get(updatorName,updatorHandle);
00134     double ptmin=1.;
00135     theMinPtFilter = new MinPtTrajectoryFilter(ptmin); 
00136     theTrajectoryBuilder = new HICTrajectoryBuilder(        pset_, es1,
00137                                                      updatorHandle.product(),
00138                                                      propagatorAlongHandle.product(),
00139                                                      propagatorOppositeHandle.product(),
00140                                                      theEstimator,
00141                                                      recHitBuilderHandle.product(),
00142                                                      measurementTrackerHandle.product(),
00143                                                      theMinPtFilter);
00144 #ifdef DEBUG
00145     std::cout<<" HICTrajectoryBuilder constructed "<<std::endl;
00146 #endif
00147 }
00148 
00149 
00150 
00151 //Destructor
00152 
00153 HITrackVertexMaker::~HITrackVertexMaker()
00154 {
00155 } 
00156 
00157 bool HITrackVertexMaker::produceTracks(const edm::Event& e1, const edm::EventSetup& es1, HICConst* theHICConst, FmpConst* theFmpConst)
00158 {
00159     
00160    bool dimuon = false;
00161    edm::Handle<reco::VertexCollection> vertexcands;
00162    e1.getByLabel (primaryVertexTag,vertexcands);
00163    int iv = 0;
00164 
00165 //   cout<<" Number of vertices primary  "<<vertexcands->size()<<endl;
00166 
00167    if(vertexcands->size()<1) return dimuon;
00168 
00169    for (reco::VertexCollection::const_iterator ipvertex=vertexcands->begin();ipvertex!=vertexcands->end();ipvertex++)
00170    {
00171 //     cout<<" Vertex position from pixels "<<(*ipvertex).position().z()<<endl;
00172      if (iv == 0) {theHICConst->setVertex((*ipvertex).position().z()); theFmpConst->setVertex((*ipvertex).position().z());} 
00173      iv++;
00174    } 
00175 
00176 //   cout << " Vertex is set to "<<theHICConst->zvert<<endl;
00177  
00178 //
00179 // Get recHit builder
00180 //
00181 
00182   es1.get<TransientRecHitRecord>().get(builderName,recHitBuilderHandle);
00183 
00184 //
00185 // Get measurement tracker
00186 //
00187 //  
00188  
00189   es1.get<CkfComponentsRecord>().get("",measurementTrackerHandle);
00190     
00191 #ifdef DEBUG  
00192   std::cout<<" Before first tracker update "<<std::endl;
00193 #endif
00194 
00195   measurementTrackerHandle->update(e1);
00196   
00197 #ifdef DEBUG
00198   std::cout<<" After first tracker update "<<std::endl;
00199 #endif
00200 //
00201 // Get L1 muon info
00202 //
00203 
00204   vector<L1MuGMTExtendedCand> excall;
00205 
00206 /*  
00207 try{  
00208 edm::Handle<L1MuGMTReadoutCollection> gmtrc1_handle;
00209 e1.getByLabel("gmtDigis",gmtrc1_handle);
00210 
00211 L1MuGMTReadoutCollection const* gmtrc1 = gmtrc1_handle.product();
00212 
00213 
00214 vector<L1MuGMTReadoutRecord> gmtrecords = gmtrc1->getRecords();
00215 vector<L1MuGMTReadoutRecord>::const_iterator igmtrr1;
00216 std::cout<<" Number of :L1 "<<gmtrecords.size()<<std::endl;
00217 
00218 
00219 for(igmtrr1=gmtrecords.begin(); igmtrr1!=gmtrecords.end(); igmtrr1++)
00220 {
00221 
00222 vector<L1MuRegionalCand>::const_iterator iter11;
00223 vector<L1MuRegionalCand> rmc1;
00224 
00225 vector<L1MuGMTExtendedCand>::const_iterator gmt_iter1; 
00226 vector<L1MuGMTExtendedCand> exc1 = igmtrr1->getGMTCands();
00227 
00228 std::cout<<" Number of :L1MuGMTExtendedCand "<<exc1.size()<<std::endl;
00229 int igmt1 = 0;
00230 for(gmt_iter1 = exc1.begin(); gmt_iter1!=exc1.end(); gmt_iter1++)
00231         {
00232         double etal1=(*gmt_iter1).etaValue();
00233         double phil1=(*gmt_iter1).phiValue();
00234         int chargel1=(*gmt_iter1).charge();
00235         double ptl1=(*gmt_iter1).ptValue();
00236         cout<<"etal1= "<<etal1<<"phil1= "<<phil1<<"ptl1= "<<ptl1<<"chargel1= "<<chargel1<<endl;
00237         igmt1++;
00238         excall.push_back(*gmt_iter1);
00239 
00240         } 
00241 }
00242 
00243 } 
00244         catch (cms::Exception& e) { // can't find it!
00245               throw e;
00246        }
00247 
00248 */
00249 
00250    edm::Handle<RecoChargedCandidateCollection> L2mucands;
00251    //edm::Handle<TrackCollection> L2mucands;
00252    e1.getByLabel (L2candTag_,L2mucands);
00253    RecoChargedCandidateCollection::const_iterator L2cand1;
00254    RecoChargedCandidateCollection::const_iterator L2cand2;
00255       
00256 #ifdef DEBUG
00257    cout<<" Number of muon candidates "<<L2mucands->size()<<endl;
00258 #endif
00259 
00260    if( L2mucands->size() < 2 ) return dimuon;
00261    
00262 // For trajectory builder   
00263    int  theLowMult = 1;
00264    theEstimator->setHICConst(theHICConst);
00265    theEstimator->setMult(theLowMult);
00266    theNavigationSchool = new HICSimpleNavigationSchool(&(*tracker), &(*magfield));
00267    theTrajectoryBuilder->settracker(measurementTrackerHandle.product());
00268 //============================   
00269     FastMuPropagator* theFmp = new FastMuPropagator(&(*magfield),theFmpConst); 
00270     StateOnTrackerBound state(theFmp); 
00271     TrajectoryStateOnSurface tsos;
00272     
00273 #ifdef DEBUG   
00274 //   for (cand1=L2mucands->begin(); cand1!=L2mucands->end(); cand1++) {
00275 //     reco::TrackRef mytr = (*cand1).track(); 
00276 //      std::cout<<" Inner position "<<(*mytr).innerPosition().x()<<" "<<(*mytr).innerPosition().y()<<" "<<(*mytr).innerPosition().z()<<std::endl;
00277 //
00278 //   } 
00279 #endif 
00280   
00281     HICFTSfromL1orL2 vFts(&(*magfield));
00282     
00283     
00284     int NumOfSigma=4;
00285     HICTkOuterStartingLayerFinder TkOSLF(NumOfSigma, &(*magfield), &(*tracker), theHICConst);
00286    
00287     int mult = 1;
00288     DiMuonSeedGeneratorHIC Seed(rphirecHitsTag,&(*magfield),&(*tracker), theHICConst, builderName, mult);
00289 
00290 //    vector<FreeTrajectoryState> theFts = vFts.createFTSfromStandAlone((*mucands));
00291 
00292    vector<FreeTrajectoryState> theFts = vFts.createFTSfromL2((*L2mucands)); 
00293 
00294 #ifdef DEBUG
00295     cout<<" Size of the freeTS "<<theFts.size()<<endl;
00296 #endif 
00297    
00298    
00299     
00300    DiMuonSeedGeneratorHIC::SeedContainer myseeds;  
00301    map<DetLayer*, DiMuonSeedGeneratorHIC::SeedContainer> seedmap;
00302    vector<Trajectory> allTraj;
00303    
00304    int numofseeds = 0; 
00305    for(vector<FreeTrajectoryState>::iterator ifts=theFts.begin(); ifts!=theFts.end(); ifts++)
00306    {
00307 #ifdef DEBUG
00308      cout<<" cycle on Muon Trajectory State " <<(*ifts).parameters().position().perp()<<
00309                                           " " <<(*ifts).parameters().position().z()   <<endl;
00310 #endif
00311      tsos=state((*ifts));
00312      
00313      int iseedn = 0; 
00314      
00315      if(tsos.isValid())
00316      {
00317      
00318 #ifdef DEBUG
00319         cout<<" Position "<<tsos.globalPosition().perp()<<" "<<tsos.globalPosition().phi()<<
00320         " "<<tsos.globalPosition().z()<<" "<<tsos.globalMomentum().perp()<<endl;
00321 #endif
00322 
00323 // Start to find starting layers
00324         FreeTrajectoryState* ftsnew=tsos.freeTrajectoryState();
00325         
00326         vector<DetLayer*> seedlayers = TkOSLF.startingLayers((*ftsnew));
00327 
00328 #ifdef DEBUG
00329         std::cout<<" The size of the starting layers "<<seedlayers.size()<<std::endl;
00330 #endif
00331 
00332         if( seedlayers.size() == 0 ) continue;
00333 
00334         map<DetLayer*, DiMuonSeedGeneratorHIC::SeedContainer> seedmap = Seed.produce(e1 ,es1, (*ftsnew), tsos, (*ifts), 
00335                                                recHitBuilderHandle.product(), measurementTrackerHandle.product(), &seedlayers);
00336         
00337         int ilnum = 0;
00338           for( vector<DetLayer*>::iterator it = seedlayers.begin(); it != seedlayers.end(); it++)
00339           {
00340             ilnum++;
00341             vector<Trajectory> theTmpTrajectories0;
00342             DiMuonSeedGeneratorHIC::SeedContainer seeds = (*seedmap.find(*it)).second;
00343     // set the correct navigation
00344             NavigationSetter setter( *theNavigationSchool);
00345 #ifdef DEBUG
00346        std::cout<<" Layer "<<ilnum<<" Number of seeds in layer "<<seeds.size()<<std::endl;          
00347 #endif      
00348             if(seeds.size() > 0) {
00349        for(DiMuonSeedGeneratorHIC::SeedContainer::iterator iseed=seeds.begin();iseed!=seeds.end();iseed++)
00350        {
00351          std::vector<TrajectoryMeasurement> theV = (*iseed).measurements();
00352 #ifdef DEBUG
00353          std::cout<< "Layer " <<ilnum<<" Seed number "<<iseedn<<"position r "<<theV[0].recHit()->globalPosition().perp()<<" phi "<<theV[0].recHit()->globalPosition().phi()<<" z "<<
00354          theV[0].recHit()->globalPosition().z()<<" momentum "<<theV[0].updatedState().freeTrajectoryState()->parameters().momentum().perp()<<" "<<
00355          theV[0].updatedState().freeTrajectoryState()->parameters().momentum().z()<<std::endl;
00356 #endif
00357          vector<Trajectory> theTmpTrajectories = theTrajectoryBuilder->trajectories(*iseed);   
00358 #ifdef DEBUG
00359         cout<<" Number of found trajectories "<<theTmpTrajectories.size()<<endl;         
00360 #endif
00361         if(theTmpTrajectories.size()>0) {
00362                                             allTraj.insert(allTraj.end(),theTmpTrajectories.begin(),theTmpTrajectories.end());
00363                                             theTmpTrajectories0.insert(theTmpTrajectories0.end(),theTmpTrajectories.begin(),theTmpTrajectories.end());
00364                                         }
00365         if(theTmpTrajectories0.size() > 0) { 
00366 #ifdef DEBUG
00367           std::cout<<"We found trajectories for at least one seed "<<std::endl; 
00368 #endif
00369           break;
00370         }
00371                                         
00372         iseedn++;
00373             
00374        } // seeds           
00375             } // there are seeds/layer
00376             
00377 //          std::cout<<" Size of seed container "<<seeds.size()<<" size of trajectories "<<theTmpTrajectories0.size()<<std::endl;  
00378             
00379             if( theTmpTrajectories0.size() > 0 ) break;
00380             
00381           } // Detlayer cycle  
00382         
00383      } // tsos. isvalid
00384      if(iseedn > 0) numofseeds++;
00385    } // Muon Free trajectory state
00386 
00387 #ifdef DEBUG
00388    cout<<" Number of muons trajectories in MUON "<<theFts.size()<<" Number of seeds "<<numofseeds+1<<endl;
00389 #endif
00390         
00391 //
00392 // start fitting procedure
00393 //
00394 #ifdef DEBUG
00395     if(allTraj.size()>0 ) {std::cout<<" Event reconstruction finished with "<<allTraj.size()<<std::endl;} else {std::cout<<" Event reconstruction::no tracks found"<<std::endl;}
00396 #endif
00397     if(allTraj.size()<2)  return dimuon;
00398 
00399     edm::ESHandle<GlobalTrackingGeometry> globTkGeomHandle;
00400     es1.get<GlobalTrackingGeometryRecord>().get(globTkGeomHandle);
00401 
00402     vector<reco::Track> thePositiveTracks;
00403     vector<reco::Track> theNegativeTracks; 
00404     vector<reco::TrackRef> thePositiveTrackRefs;
00405     vector<reco::TrackRef> theNegativeTrackRefs;
00406     vector<reco::TransientTrack> thePositiveTransTracks;
00407     vector<reco::TransientTrack> theNegativeTransTracks;
00408 
00409     reco::BeamSpot::CovarianceMatrix matrix;
00410     matrix(2,2) = 0.001;
00411     matrix(3,3) = 0.001;
00412 
00413     reco::BeamSpot bs( reco::BeamSpot::Point(0., 0., theHICConst->zvert),
00414                                                      0.1,
00415                                                      0.,
00416                                                      0.,
00417                                                      0.,
00418                                                     matrix
00419                      );
00420 
00421 
00422     reco::TrackBase::TrackAlgorithm Algo = reco::TrackBase::undefAlgorithm;
00423 
00424     edm::ESHandle<TrajectoryFitter> theFitterTrack;
00425     edm::ESHandle<TrajectorySmoother> theSmootherTrack;
00426     edm::ESHandle<Propagator> thePropagatorTrack;
00427     es1.get<TrackingComponentsRecord>().get("KFFitterForRefitInsideOut",theFitterTrack);
00428     es1.get<TrackingComponentsRecord>().get("KFSmootherForRefitInsideOut",theSmootherTrack);
00429     es1.get<TrackingComponentsRecord>().get("SmartPropagatorAny",thePropagatorTrack);
00430     enum RefitDirection{insideOut,outsideIn,undetermined};
00431 
00432 
00433     for(vector<Trajectory>::iterator it = allTraj.begin(); it!= allTraj.end(); it++)
00434     {
00435 //
00436 // Refit the trajectory
00437 //
00438 // Refit the trajectory before putting into the last result
00439 
00440   Trajectory::ConstRecHitContainer recHitsForReFit = (*it).recHits();
00441   
00442   PTrajectoryStateOnDet garbage1;
00443   edm::OwnVector<TrackingRecHit> garbage2;
00444   TrajectoryStateOnSurface firstTSOS = (*it).firstMeasurement().updatedState();
00445 
00446 //   cout<<" firstTSOS "<<firstTSOS.freeTrajectoryState()->position().perp()<<" "<<firstTSOS.freeTrajectoryState()->position().z()<<endl;
00447 //  PropagationDirection propDir =
00448 //    (firstTSOS.globalPosition().basicVector().dot(firstTSOS.globalMomentum().basicVector())>0) ? alongMomentum : oppositeToMomentum;
00449 
00450   PropagationDirection propDir = oppositeToMomentum;
00451   
00452 //  RefitDirection theRefitDirection = insideOut;
00453 //  propDir = alongMomentum;
00454 //  RefitDirection theRefitDirection = outsideIn;
00455 
00456 //  if(propDir == alongMomentum && theRefitDirection == outsideIn)  {cout<<" oppositeToMomentum "<<endl; propDir=oppositeToMomentum;}
00457 //  if(propDir == oppositeToMomentum && theRefitDirection == insideOut) {cout<<" alongMomentum "<<endl; propDir=alongMomentum;}
00458 
00459   TrajectorySeed seed(garbage1,garbage2,propDir);
00460   vector<Trajectory> trajectories = theFitterTrack->fit(seed,recHitsForReFit,firstTSOS);
00461 
00462 //  vector<Trajectory> trajectories = theFitterTrack->fit(*it);
00463 
00464 //  if(trajectories.empty()) {cout<<" No refit is done "<<endl;};
00465   
00466 //  Trajectory trajectoryBW = trajectories.front();
00467 //  vector<Trajectory> trajectoriesSM = theSmoother->trajectories(trajectoryBW);
00468 //  if(trajectoriesSM.size()<1) continue;
00469 
00470     TrajectoryStateOnSurface innertsos;
00471     if (it->direction() == alongMomentum) {
00472    //    cout<<" Direction is along momentum "<<endl;
00473       innertsos = it->firstMeasurement().updatedState();
00474     } else {
00475       innertsos = it->lastMeasurement().updatedState();
00476    //   cout<<" Direction is opposite to momentum "<<endl;
00477       
00478     }
00479    //  cout<<" Position of the innermost point "<<innertsos.freeTrajectoryState()->position().perp()<<" "<<innertsos.freeTrajectoryState()->position().z()<<endl;
00480     TrajectoryStateClosestToBeamLineBuilder tscblBuilder;
00481     TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(innertsos.freeState()),bs);
00482 
00483     if (tscbl.isValid()==false) {
00484     //cout<<" false track "<<endl; 
00485     continue;}
00486 
00487     GlobalPoint v = tscbl.trackStateAtPCA().position();
00488     math::XYZPoint  pos( v.x(), v.y(), v.z() );
00489     
00490 //    cout<<" Position of track close to vertex "<<v.perp()<<" "<<v.z()<<" Primary vertex "<<theHICConst->zvert<<
00491 //                                     " charge "<<tscbl.trackStateAtPCA().charge()<<endl;
00492    
00493     if(v.perp() > 0.1 ) continue;
00494     if(fabs(v.z() - theHICConst->zvert ) > 0.4 ) continue;
00495 
00496     GlobalVector p = tscbl.trackStateAtPCA().momentum();
00497     math::XYZVector mom( p.x(), p.y(), p.z() );
00498 
00499     Track theTrack(it->chiSquared(),
00500                    it->ndof(), 
00501                    pos, mom, tscbl.trackStateAtPCA().charge(), tscbl.trackStateAtPCA().curvilinearError(),Algo);
00502     TransientTrack tmpTk( theTrack, &(*magfield), globTkGeomHandle );
00503     if( tscbl.trackStateAtPCA().charge() > 0)
00504     {
00505       thePositiveTracks.push_back( theTrack );
00506       thePositiveTransTracks.push_back( tmpTk );
00507     }
00508       else
00509       {
00510         theNegativeTracks.push_back( theTrack );
00511         theNegativeTransTracks.push_back( tmpTk );
00512       }
00513     } // Traj
00514 
00515    if( thePositiveTracks.size() < 1 || theNegativeTracks.size() < 1 ){ 
00516 #ifdef DEBUG
00517      cout<<" No enough tracks to get vertex "<<endl; 
00518 #endif
00519      return dimuon; 
00520    }
00521 
00522    bool useRefTrax=true;
00523    KalmanVertexFitter theFitter(useRefTrax);
00524    TransientVertex theRecoVertex;
00525 //
00526 // Create possible two particles vertices
00527 //
00528    vector<reco::TransientTrack> theTwoTransTracks;
00529    vector<TransientVertex> theVertexContainer;
00530    for(vector<reco::TransientTrack>::iterator iplus = thePositiveTransTracks.begin(); iplus != thePositiveTransTracks.end(); iplus++)
00531    {
00532      theTwoTransTracks.clear();
00533      theTwoTransTracks.push_back(*iplus);
00534      for(vector<reco::TransientTrack>::iterator iminus = theNegativeTransTracks.begin(); iminus != theNegativeTransTracks.end(); iminus++)
00535      {
00536        theTwoTransTracks.push_back(*iminus);
00537        theRecoVertex = theFitter.vertex(theTwoTransTracks);
00538       if( !theRecoVertex.isValid() ) {
00539         continue;
00540       } 
00541       
00542 //        cout<<" Vertex is found "<<endl;
00543 //        cout<<" Chi2 = "<<theRecoVertex.totalChiSquared()<<
00544 //                " r= "<<theRecoVertex.position().perp()<<
00545 //                " z= "<<theRecoVertex.position().z()<<endl;
00546 
00547 // Additional cuts       
00548      if ( theRecoVertex.totalChiSquared() > 0.0002 ) {
00549 //        cout<<" Vertex is failed with Chi2 : "<<theRecoVertex.totalChiSquared()<<endl; 
00550      continue;
00551      }
00552      if ( theRecoVertex.position().perp() > 0.08 ) {
00553 //        cout<<" Vertex is failed with r position : "<<theRecoVertex.position().perp()<<endl; 
00554         continue;
00555       }    
00556      if ( fabs(theRecoVertex.position().z()-theHICConst->zvert) > 0.06 ) {
00557 //         cout<<" Vertex is failed with z position : "<<theRecoVertex.position().z()<<endl; 
00558          continue;
00559      }
00560      double quality = theRecoVertex.normalisedChiSquared();
00561      std::vector<reco::TransientTrack> tracks = theRecoVertex.originalTracks();
00562      vector<TransientTrack> refittedTrax;
00563      if( theRecoVertex.hasRefittedTracks() ) {
00564           refittedTrax = theRecoVertex.refittedTracks();
00565      }
00566 
00567      for (std::vector<reco::TransientTrack>::iterator ivb = tracks.begin(); ivb != tracks.end(); ivb++)
00568      {
00569       quality = quality * (*ivb).chi2() /(*ivb).ndof();
00570      }
00571       if( quality > 70. ) {
00572             //    cout<<" Vertex failed quality cut "<<quality<<endl; 
00573                 continue;
00574       }
00575       theVertexContainer.push_back(theRecoVertex);
00576      } // iminus
00577   } // iplus
00578   
00579        if( theVertexContainer.size() < 1 ) { 
00580 #ifdef DEBUG
00581         std::cout<<" No vertex found in event "<<std::endl; 
00582 #endif
00583        return dimuon; 
00584        } else {
00585           // cout<<" Event vertex is selected "<<endl;
00586        }
00587 
00588 
00589     dimuon = true;
00590     return dimuon;
00591 } 
00592 }
00593 
00594 

Generated on Tue Jun 9 17:43:38 2009 for CMSSW by  doxygen 1.5.4