CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/Calibration/IsolatedParticles/src/ChargeIsolationExtra.cc

Go to the documentation of this file.
00001 #include "Calibration/IsolatedParticles/interface/ChargeIsolationExtra.h"
00002 #include "Calibration/IsolatedParticles/interface/ChargeIsolation.h"
00003 #include "Calibration/IsolatedParticles/interface/CaloPropagateTrack.h"
00004 #include "Calibration/IsolatedParticles/interface/FindDistCone.h"
00005 #include "Calibration/IsolatedParticles/interface/MatrixECALDetIds.h"
00006 #include "Calibration/IsolatedParticles/interface/MatrixHCALDetIds.h"
00007 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00008 
00009 #include<iostream>
00010 
00011 namespace spr{
00012 
00013   double chargeIsolation(const edm::Event& iEvent, const edm::EventSetup& iSetup, CaloNavigator<DetId>& theNavigator, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const CaloSubdetectorGeometry* gEB, const CaloSubdetectorGeometry* gEE, TrackDetectorAssociator& associator, TrackAssociatorParameters& parameters_, int ieta, int iphi, std::string theTrackQuality, bool debug) {
00014   
00015     double maxNearP = -1.0;
00016     reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
00017 
00018     // const DetId anyCell,
00019     reco::TrackCollection::const_iterator trkItr2;
00020     for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
00021 
00022       const reco::Track* pTrack2 = &(*trkItr2);
00023 
00024       bool   trkQuality  = pTrack2->quality(trackQuality_);
00025       if ( (trkItr2 != trkItr) && trkQuality )  {
00026       
00027         const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
00028         TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
00029         const GlobalPoint point2(info2.trkGlobPosAtEcal.x(),info2.trkGlobPosAtEcal.y(),info2.trkGlobPosAtEcal.z());
00030 
00031         if (info2.isGoodEcal ) {
00032           if (std::abs(point2.eta())<1.479) {
00033             const DetId anyCell = gEB->getClosestCell(point2);
00034             if (!spr::chargeIsolation(anyCell,theNavigator,ieta, iphi)) {
00035               if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
00036             }
00037           } else {
00038             const DetId anyCell = gEE->getClosestCell(point2);
00039             if(!spr::chargeIsolation(anyCell,theNavigator,ieta, iphi)) {
00040               if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
00041             }
00042           }
00043         } //info2.isGoodEcal
00044       }
00045     }
00046     return maxNearP;
00047   }
00048 
00049   //===========================================================================================================
00050 
00051   bool chargeIsolation(const DetId anyCell,CaloNavigator<DetId>& navigator,int ieta,int iphi) {
00052 
00053     bool isIsolated = false;
00054 
00055     DetId thisDet;
00056 
00057     for (int dx = -ieta; dx < ieta+1; ++dx) {
00058       for (int dy = -iphi; dy < iphi+1; ++dy) {
00059 
00060         thisDet = navigator.offsetBy(dx, dy);
00061         navigator.home();
00062       
00063         if (thisDet != DetId(0)) {
00064           if (thisDet == anyCell) {
00065             isIsolated = false;
00066             return isIsolated;
00067           }
00068         }
00069       }
00070     }
00071     return isIsolated;
00072   }
00073 
00074   //===========================================================================================================
00075 
00076   double chargeIsolationEcal(const edm::Event& iEvent, const edm::EventSetup& iSetup, const DetId& coreDet, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const CaloGeometry* geo, const CaloTopology* caloTopology, TrackDetectorAssociator& associator, TrackAssociatorParameters& parameters_, int ieta, int iphi, std::string& theTrackQuality, bool debug) {
00077   
00078     const EcalBarrelGeometry *barrelGeom = (dynamic_cast< const EcalBarrelGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalBarrel)));
00079     const EcalEndcapGeometry *endcapGeom = (dynamic_cast< const EcalEndcapGeometry *> (geo->getSubdetectorGeometry(DetId::Ecal,EcalEndcap)));
00080 
00081     std::vector<DetId> vdets = spr::matrixECALIds(coreDet, ieta, iphi, geo, caloTopology, debug);
00082     if (debug) std::cout << "chargeIsolation:: eta/phi/dets " << ieta << " " << iphi << " " << vdets.size() << std::endl;
00083 
00084     double maxNearP = -1.0;
00085     reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
00086 
00087     // const DetId anyCell,
00088     reco::TrackCollection::const_iterator trkItr2;
00089     for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
00090 
00091       const reco::Track* pTrack2 = &(*trkItr2);
00092 
00093       bool   trkQuality  = pTrack2->quality(trackQuality_);
00094       if ( (trkItr2 != trkItr) && trkQuality )  {
00095       
00096         const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
00097         TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
00098         const GlobalPoint point2(info2.trkGlobPosAtEcal.x(),info2.trkGlobPosAtEcal.y(),info2.trkGlobPosAtEcal.z());
00099 
00100         if (info2.isGoodEcal ) {
00101           if (std::abs(point2.eta())<1.479) {
00102             const DetId anyCell = barrelGeom->getClosestCell(point2);
00103             if (!spr::chargeIsolation(anyCell,vdets)) {
00104               if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
00105             }
00106           } else {
00107             const DetId anyCell = endcapGeom->getClosestCell(point2);
00108             if (!spr::chargeIsolation(anyCell,vdets)) {
00109               if (maxNearP<pTrack2->p()) maxNearP=pTrack2->p();
00110             }
00111           }
00112         } //info2.isGoodEcal
00113       }
00114     }
00115     return maxNearP;
00116   }
00117 
00118   //===========================================================================================================
00119 
00120   double chargeIsolationHcal(const edm::Event& iEvent, const edm::EventSetup& iSetup, reco::TrackCollection::const_iterator trkItr, edm::Handle<reco::TrackCollection> trkCollection, const DetId ClosestCell, const HcalTopology* topology, const CaloSubdetectorGeometry* gHB, TrackDetectorAssociator& associator, TrackAssociatorParameters& parameters_, int ieta, int iphi, std::string& theTrackQuality, bool debug) {
00121 
00122     std::vector<DetId> dets(1,ClosestCell);
00123 
00124     if (debug) std::cout << (HcalDetId) ClosestCell << std::endl;
00125 
00126     std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, false, debug);
00127     std::vector<DetId>::iterator it;  
00128   
00129     if (debug) {
00130       for (unsigned int i=0; i<vdets.size(); i++) {
00131         std::cout << "HcalDetId in " <<2*ieta+1 << "x" << 2*iphi+1 << " " << (HcalDetId) vdets[i] << std::endl;
00132       }
00133     }
00134 
00135     double maxNearP = -1.0;
00136     reco::TrackBase::TrackQuality trackQuality_=reco::TrackBase::qualityByName(theTrackQuality);
00137   
00138     reco::TrackCollection::const_iterator trkItr2;
00139     for (trkItr2 = trkCollection->begin(); trkItr2 != trkCollection->end(); ++trkItr2) {
00140     
00141       const reco::Track* pTrack2 = &(*trkItr2);
00142     
00143       bool   trkQuality  = pTrack2->quality(trackQuality_);
00144       if ( (trkItr2 != trkItr) && trkQuality )  {
00145         const FreeTrajectoryState fts2 = associator.getFreeTrajectoryState(iSetup, *pTrack2);
00146         TrackDetMatchInfo info2 = associator.associate(iEvent, iSetup, fts2, parameters_);
00147         const GlobalPoint point2(info2.trkGlobPosAtHcal.x(),info2.trkGlobPosAtHcal.y(),info2.trkGlobPosAtHcal.z());
00148 
00149         if (debug) {
00150           std::cout << "Track2 (p,eta,phi) " << pTrack2->p() << " " << pTrack2->eta() << " " << pTrack2->phi() << std::endl;
00151         }
00152 
00153         if (info2.isGoodHcal ) {
00154           const DetId anyCell = gHB->getClosestCell(point2);
00155           if (!spr::chargeIsolation(anyCell,vdets)) {   
00156             if(maxNearP<pTrack2->p())  maxNearP=pTrack2->p();
00157           }
00158           if (debug){
00159             std::cout << "maxNearP " << maxNearP << " thisCell " 
00160                       << (HcalDetId)anyCell << " (" 
00161                       << info2.trkGlobPosAtHcal.x() << ","
00162                       << info2.trkGlobPosAtHcal.y() <<","
00163                       << info2.trkGlobPosAtHcal.z() <<")" << std::endl;
00164           }
00165         }
00166       }
00167     }
00168     return maxNearP;
00169   }
00170 
00171 }