CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoTracker/ConversionSeedGenerators/src/SeedForPhotonConversion1Leg.cc

Go to the documentation of this file.
00001 #include "RecoTracker/ConversionSeedGenerators/interface/SeedForPhotonConversion1Leg.h"
00002 
00003 #include "TrackingTools/KalmanUpdators/interface/KFUpdator.h"
00004 #include "RecoTracker/TkSeedGenerator/interface/FastHelix.h"
00005 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00006 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include "MagneticField/Engine/interface/MagneticField.h"
00009 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00010 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h" 
00011 #include "TrackingTools/Records/interface/TransientRecHitRecord.h" 
00012 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "TrackingTools/GeomPropagators/interface/PropagationExceptions.h"
00015 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00016 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00017 #include "RecoTracker/TransientTrackingRecHit/interface/TSiStripRecHit2DLocalPos.h"
00018 
00019 //#define mydebug_seed
00020 template <class T> T sqr( T t) {return t*t;}
00021 
00022 const TrajectorySeed * SeedForPhotonConversion1Leg::trajectorySeed(
00023     TrajectorySeedCollection & seedCollection,
00024     const SeedingHitSet & hits,
00025     const GlobalPoint & vertex,
00026     const GlobalVector & vertexBounds,
00027     float ptmin,
00028     const edm::EventSetup& es,
00029     float cotTheta, std::stringstream& ss)
00030 {
00031   pss = &ss;
00032   if ( hits.size() < 2) return 0;
00033 
00034   GlobalTrajectoryParameters kine = initialKinematic(hits, vertex, es, cotTheta);
00035   float sinTheta = sin(kine.momentum().theta());
00036 
00037   CurvilinearTrajectoryError error = initialError(vertexBounds, ptmin,  sinTheta);
00038   FreeTrajectoryState fts(kine, error);
00039 
00040   return buildSeed(seedCollection,hits,fts,es); 
00041 }
00042 
00043 
00044 GlobalTrajectoryParameters SeedForPhotonConversion1Leg::initialKinematic(
00045       const SeedingHitSet & hits, 
00046       const GlobalPoint & vertexPos, 
00047       const edm::EventSetup& es,
00048       const float cotTheta) const
00049 {
00050   GlobalTrajectoryParameters kine;
00051 
00052   TransientTrackingRecHit::ConstRecHitPointer tth1 = hits[0];
00053   TransientTrackingRecHit::ConstRecHitPointer tth2 = hits[1];
00054 
00055    // FIXME optimize: move outside loop
00056     edm::ESHandle<MagneticField> bfield;
00057     es.get<IdealMagneticFieldRecord>().get(bfield);
00058     float nomField = bfield->nominalValue();
00059 
00060   FastHelix helix(tth2->globalPosition(), tth1->globalPosition(), vertexPos, nomField, &*bfield, vertexPos);
00061   kine = helix.stateAtVertex();
00062 
00063   //force the pz/pt equal to the measured one
00064   if(fabs(cotTheta)<cotTheta_Max)
00065     kine = GlobalTrajectoryParameters(kine.position(),
00066                                       GlobalVector(kine.momentum().x(),kine.momentum().y(),kine.momentum().perp()*cotTheta),
00067                                       kine.charge(),
00068                                       & kine.magneticField()
00069                                       );
00070   else
00071     kine = GlobalTrajectoryParameters(kine.position(),
00072                                       GlobalVector(kine.momentum().x(),kine.momentum().y(),kine.momentum().perp()*cotTheta_Max),
00073                                       kine.charge(),
00074                                       & kine.magneticField()
00075                                       );
00076 
00077 #ifdef mydebug_seed
00078   uint32_t detid;
00079   (*pss) << "[SeedForPhotonConversion1Leg] initialKinematic tth1 " ;
00080   detid=tth1->geographicalId().rawId();
00081   po.print(*pss, detid );
00082   (*pss) << " \t " << detid << " " << tth1->localPosition()  << " " << tth1->globalPosition()    ;
00083   detid= tth2->geographicalId().rawId();
00084   (*pss) << " \n\t tth2 ";
00085   po.print(*pss, detid );
00086   (*pss) << " \t " << detid << " " << tth2->localPosition()  << " " << tth2->globalPosition()  
00087          << "\nhelix momentum " << kine.momentum() << " pt " << kine.momentum().perp() << " radius " << 1/kine.transverseCurvature(); 
00088 #endif
00089 
00090   bool isBOFF =(0==nomField);;
00091   if (isBOFF && (theBOFFMomentum > 0)) {
00092     kine = GlobalTrajectoryParameters(kine.position(),
00093                               kine.momentum().unit() * theBOFFMomentum,
00094                               kine.charge(),
00095                               &*bfield);
00096   }
00097   return kine;
00098 }
00099 
00100 
00101 
00102 CurvilinearTrajectoryError SeedForPhotonConversion1Leg::
00103 initialError( 
00104              const GlobalVector& vertexBounds, 
00105              float ptMin,  
00106              float sinTheta) const
00107 {
00108   // Set initial uncertainty on track parameters, using only P.V. constraint and no hit
00109   // information.
00110   GlobalError vertexErr( sqr(vertexBounds.x()), 0, 
00111                          sqr(vertexBounds.y()), 0, 0,
00112                          sqr(vertexBounds.z())
00113                          );
00114   
00115  
00116   AlgebraicSymMatrix55 C = ROOT::Math::SMatrixIdentity();
00117 
00118 // FIXME: minC00. Prevent apriori uncertainty in 1/P from being too small, 
00119 // to avoid instabilities.
00120 // N.B. This parameter needs optimising ...
00121   float sin2th = sqr(sinTheta);
00122   float minC00 = 1.0;
00123   C[0][0] = std::max(sin2th/sqr(ptMin), minC00);
00124   float zErr = vertexErr.czz();
00125   float transverseErr = vertexErr.cxx(); // assume equal cxx cyy
00126   C[3][3] = transverseErr;
00127   C[4][4] = zErr*sin2th + transverseErr*(1-sin2th);
00128 
00129   return CurvilinearTrajectoryError(C);
00130 }
00131 
00132 const TrajectorySeed * SeedForPhotonConversion1Leg::buildSeed(
00133     TrajectorySeedCollection & seedCollection,
00134     const SeedingHitSet & hits,
00135     const FreeTrajectoryState & fts,
00136     const edm::EventSetup& es) const
00137 {
00138   // get tracker
00139   edm::ESHandle<TrackerGeometry> tracker;
00140   es.get<TrackerDigiGeometryRecord>().get(tracker);
00141   
00142   // get propagator
00143   edm::ESHandle<Propagator>  propagatorHandle;
00144   es.get<TrackingComponentsRecord>().get(thePropagatorLabel, propagatorHandle);
00145   const Propagator*  propagator = &(*propagatorHandle);
00146   
00147   // get updator
00148   KFUpdator  updator;
00149   
00150   // Now update initial state track using information from seed hits.
00151   
00152   TrajectoryStateOnSurface updatedState;
00153   edm::OwnVector<TrackingRecHit> seedHits;
00154   
00155   const TrackingRecHit* hit = 0;
00156   for ( unsigned int iHit = 0; iHit < hits.size() && iHit<1; iHit++) {
00157     hit = hits[iHit]->hit();
00158     TrajectoryStateOnSurface state = (iHit==0) ? 
00159       propagator->propagate(fts,tracker->idToDet(hit->geographicalId())->surface())
00160       : propagator->propagate(updatedState, tracker->idToDet(hit->geographicalId())->surface());
00161     if (!state.isValid()) return 0;
00162     
00163     TransientTrackingRecHit::ConstRecHitPointer tth = hits[iHit]; 
00164     
00165     TransientTrackingRecHit::RecHitPointer newtth =  refitHit( tth, state);
00166 
00167     
00168     if (!checkHit(state,newtth,es)) return 0;
00169 
00170     updatedState =  updator.update(state, *newtth);
00171     if (!updatedState.isValid()) return 0;
00172     
00173     seedHits.push_back(newtth->hit()->clone());
00174 #ifdef mydebug_seed
00175     uint32_t detid = hit->geographicalId().rawId();
00176     (*pss) << "\n[SeedForPhotonConversion1Leg] hit " << iHit;
00177     po.print(*pss, detid);
00178     (*pss) << " "  << detid << "\t lp " << hit->localPosition()
00179            << " tth " << tth->localPosition() << " newtth " << newtth->localPosition() << " state " << state.globalMomentum().perp();
00180 #endif
00181   } 
00182   
00183   
00184   PTrajectoryStateOnDet const & PTraj =
00185       trajectoryStateTransform::persistentState(updatedState, hit->geographicalId().rawId());
00186   
00187   seedCollection.push_back( TrajectorySeed(PTraj,seedHits,alongMomentum));
00188   return &seedCollection.back();
00189 }
00190 
00191 TransientTrackingRecHit::RecHitPointer SeedForPhotonConversion1Leg::refitHit(
00192       const TransientTrackingRecHit::ConstRecHitPointer &hit, 
00193       const TrajectoryStateOnSurface &state) const
00194 {
00195   //const TransientTrackingRecHit* a= hit.get();
00196   //return const_cast<TransientTrackingRecHit*> (a);
00197   //This was modified otherwise the rechit will have just the local x component and local y=0
00198   // To understand how to modify for pixels
00199 
00200   //const TSiStripRecHit2DLocalPos* b = dynamic_cast<const TSiStripRecHit2DLocalPos*>(a);
00201   //return const_cast<TSiStripRecHit2DLocalPos*>(b);
00202   return hit->clone(state);
00203 }