CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEgamma/EgammaPhotonAlgos/src/ConversionTrackEcalImpactPoint.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vector>
00003 #include <memory>
00004 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionTrackEcalImpactPoint.h"
00005 // Framework
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 //
00010 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00011 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00012 #include "TrackingTools/TransientTrack/interface/TrackTransientTrack.h"
00013 
00014 
00015 //
00016 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00017 #include <TMath.h>
00018 #include <vector>
00019 #include <map>
00020 
00021 ReferenceCountingPointer<BoundCylinder>  ConversionTrackEcalImpactPoint::theBarrel_ = 0;
00022 ReferenceCountingPointer<BoundDisk>      ConversionTrackEcalImpactPoint::theNegativeEtaEndcap_ = 0;
00023 ReferenceCountingPointer<BoundDisk>      ConversionTrackEcalImpactPoint::thePositiveEtaEndcap_ = 0;
00024 bool                                     ConversionTrackEcalImpactPoint::theInit_ = false;
00025 
00026 
00027 ConversionTrackEcalImpactPoint::ConversionTrackEcalImpactPoint(const MagneticField* field ): 
00028 
00029 theMF_(field)
00030 { 
00031 
00032     forwardPropagator_ = new PropagatorWithMaterial ( dir_ = alongMomentum, 0.000511, theMF_ );
00033 
00034 }
00035 
00036 ConversionTrackEcalImpactPoint::~ConversionTrackEcalImpactPoint() {
00037 
00038     delete    forwardPropagator_ ; 
00039     
00040 }
00041 
00042 std::vector<math::XYZPointF> ConversionTrackEcalImpactPoint::find( const std::vector<reco::TransientTrack>&  tracks,  const edm::Handle<edm::View<reco::CaloCluster> >&  bcHandle )   {
00043 
00044   
00045   std::vector<math::XYZPointF> result;
00046   // 
00047   matchingBC_.clear();   
00048 
00049   std::vector<reco::CaloClusterPtr> matchingBC(2);
00050 
00051 
00052   // 
00053 
00054 
00055 
00056   int iTrk=0;
00057   for (    std::vector<reco::TransientTrack>::const_iterator iTk=tracks.begin(); iTk!=tracks.end(); ++iTk) {
00058 
00059     math::XYZPointF ecalImpactPosition(0.,0.,0.);
00060     const TrajectoryStateOnSurface myTSOS=(*iTk).innermostMeasurementState();
00061     if ( !( myTSOS.isValid() ) ) continue; 
00062 
00063     stateAtECAL_= forwardPropagator_->propagate( myTSOS, barrel() );
00064     
00065 
00066     if (!stateAtECAL_.isValid() || ( stateAtECAL_.isValid() && fabs(stateAtECAL_.globalPosition().eta() ) >1.479 )  ) {
00067     
00068          
00069       if ( (*iTk).innermostMeasurementState().globalPosition().eta() > 0.) {
00070         stateAtECAL_= forwardPropagator_->propagate( myTSOS, positiveEtaEndcap());
00071 
00072       } else {
00073 
00074         stateAtECAL_= forwardPropagator_->propagate( myTSOS, negativeEtaEndcap());
00075 
00076       }
00077     }
00078 
00079 
00080     if ( stateAtECAL_.isValid() ) ecalImpactPosition = stateAtECAL_.globalPosition();
00081 
00082 
00083     result.push_back(ecalImpactPosition  );
00084 
00085 
00086     if ( stateAtECAL_.isValid() ) { 
00087       int goodBC=0;
00088       float bcDistanceToTrack=9999;
00089       reco::CaloClusterPtr matchedBCItr;
00090       int ibc=0;
00091       goodBC=0;
00092 
00093       for (unsigned i = 0; i < bcHandle->size(); ++i ) {
00094         float dEta= bcHandle->ptrAt(i)->position().eta() - ecalImpactPosition.eta()  ;
00095         float dPhi= bcHandle->ptrAt(i)->position().phi() - ecalImpactPosition.phi()  ;
00096         if ( sqrt(dEta*dEta + dPhi*dPhi)  <  bcDistanceToTrack ) {
00097           goodBC=ibc;
00098           bcDistanceToTrack=sqrt(dEta*dEta + dPhi*dPhi);
00099         } 
00100         ibc++;  
00101 
00102       }
00103 
00104       matchingBC[iTrk]=bcHandle->ptrAt(goodBC);
00105     }
00106        
00107      
00108     iTrk++;
00109   }
00110 
00111   matchingBC_=matchingBC;
00112 
00113   return result;
00114 
00115 }
00116 
00117 
00118 
00119 
00120 void ConversionTrackEcalImpactPoint::initialize() {
00121 
00122   const float epsilon = 0.001;
00123   Surface::RotationType rot; // unit rotation matrix
00124 
00125 
00126   theBarrel_ = new BoundCylinder( Surface::PositionType(0,0,0), rot, 
00127                                  SimpleCylinderBounds( barrelRadius()-epsilon, 
00128                                                        barrelRadius()+epsilon, 
00129                                                        -barrelHalfLength(), 
00130                                                        barrelHalfLength()));
00131   theNegativeEtaEndcap_ = 
00132     new BoundDisk( Surface::PositionType( 0, 0, -endcapZ()), rot, 
00133                    SimpleDiskBounds( 0, endcapRadius(), -epsilon, epsilon));
00134   
00135   thePositiveEtaEndcap_ = 
00136     new BoundDisk( Surface::PositionType( 0, 0, endcapZ()), rot, 
00137                    SimpleDiskBounds( 0, endcapRadius(), -epsilon, epsilon));
00138   
00139   theInit_ = true;
00140 
00141 
00142 }