CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Calibration/IsolatedParticles/src/FindDistCone.cc

Go to the documentation of this file.
00001 #include "Calibration/IsolatedParticles/interface/FindDistCone.h"
00002 
00003 #include <iostream>
00004 
00005 namespace spr {
00006 
00007   // Cone clustering core
00008   double getDistInPlaneTrackDir(const GlobalPoint&  caloPoint, const GlobalVector& caloVector, const GlobalPoint&  rechitPoint) {
00009   
00010     const GlobalVector caloIntersectVector(caloPoint.x(), 
00011                                            caloPoint.y(), 
00012                                            caloPoint.z()); //p
00013 
00014     const GlobalVector caloUnitVector = caloVector.unit();
00015     const GlobalVector rechitVector(rechitPoint.x(),
00016                                     rechitPoint.y(),
00017                                     rechitPoint.z());
00018     const GlobalVector rechitUnitVector = rechitVector.unit();
00019     double dotprod_denominator = caloUnitVector.dot(rechitUnitVector);
00020     double dotprod_numerator   = caloUnitVector.dot(caloIntersectVector);
00021     double rechitdist = dotprod_numerator/dotprod_denominator;
00022     const GlobalVector effectiveRechitVector = rechitdist*rechitUnitVector;
00023     const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
00024                                            effectiveRechitVector.y(),
00025                                            effectiveRechitVector.z());
00026     GlobalVector distance_vector = effectiveRechitPoint-caloPoint;
00027     if (dotprod_denominator > 0. && dotprod_numerator > 0.) {
00028       return distance_vector.mag();
00029     } else {
00030       return 999999.;
00031     }
00032   }
00033 
00034   // Not used, but here for reference
00035   double getDistInCMatEcal(double eta1, double phi1, double eta2, double phi2){
00036 
00037     double dR, Rec;
00038     if (fabs(eta1)<1.479) Rec=129;
00039     else Rec=317;
00040     double ce1=cosh(eta1);
00041     double ce2=cosh(eta2);
00042     double te1=tanh(eta1);
00043     double te2=tanh(eta2);
00044   
00045     double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
00046     if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
00047     else     dR=999999.;
00048     return dR;
00049   }
00050 
00051 
00052   // Not used, but here for reference
00053   double getDistInCMatHcal(double eta1, double phi1, double eta2, double phi2){
00054 
00055     // Radii and eta from Geometry/HcalCommonData/data/hcalendcapalgo.xml
00056     // and Geometry/HcalCommonData/data/hcalbarrelalgo.xml
00057 
00058     double dR, Rec;
00059     if (fabs(eta1)<1.392) Rec=177.5; 
00060     else Rec=391.95;
00061     double ce1=cosh(eta1);
00062     double ce2=cosh(eta2);
00063     double te1=tanh(eta1);
00064     double te2=tanh(eta2);
00065   
00066     double z=cos(phi1-phi2)/ce1/ce2+te1*te2;
00067     if(z!=0) dR=fabs(Rec*ce1*sqrt(1./z/z-1.));
00068     else     dR=999999.;
00069     return dR;
00070   }
00071 
00072   void getEtaPhi(HBHERecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene) {
00073 
00074     RH_ieta.push_back(hit->id().ieta());
00075     RH_iphi.push_back(hit->id().iphi());
00076     RH_ene.push_back(hit->energy());
00077   }
00078 
00079   void getEtaPhi(edm::PCaloHitContainer::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene)  {
00080     // SimHit function not yet implemented.
00081     RH_ieta.push_back(-9);
00082     RH_iphi.push_back(-9);
00083     RH_ene.push_back(-9.);
00084   }
00085 
00086   void getEtaPhi(EcalRecHitCollection::const_iterator hit, std::vector<int>& RH_ieta, std::vector<int>& RH_iphi, std::vector<double>& RH_ene) {
00087     // Ecal function not yet implemented.
00088     RH_ieta.push_back(-9);
00089     RH_iphi.push_back(-9);
00090     RH_ene.push_back(-9.);
00091   }
00092 
00093   void getEtaPhi(HBHERecHitCollection::const_iterator hit,int& ieta,int& iphi){
00094     ieta = hit->id().ieta();
00095     iphi = hit->id().iphi();
00096   }
00097 
00098   void getEtaPhi(edm::PCaloHitContainer::const_iterator hit,int& ieta,int& iphi){
00099     DetId id = DetId(hit->id());
00100     if (id.det() == DetId::Hcal) {
00101       ieta = ((HcalDetId)(hit->id())).ieta();
00102       iphi = ((HcalDetId)(hit->id())).iphi();
00103     } else if (id.det() == DetId::Ecal && id.subdetId() == EcalBarrel) {
00104       ieta = ((EBDetId)(id)).ieta();
00105       iphi = ((EBDetId)(id)).iphi();
00106 //    } else if (id.det() == DetId::Ecal && id.subdetId() == EcalEndcap) {
00107 //      ieta = ((EEDetId)(id)).ieta();
00108 //      iphi = ((EEDetId)(id)).iphi();
00109     } else {
00110       ieta = 999;
00111       iphi = 999;
00112     }
00113   }
00114 
00115   void getEtaPhi(EcalRecHitCollection::const_iterator hit,int& ieta,int& iphi){
00116     DetId id = hit->id();
00117     if (id.subdetId() == EcalBarrel) {
00118       ieta = ((EBDetId)(id)).ieta();
00119       iphi = ((EBDetId)(id)).iphi();
00120 //    } else if (id.subdetId() == EcalEndcap) {
00121 //      ieta = ((EEDetId)(id)).ieta();
00122 //      iphi = ((EEDetId)(id)).iphi();
00123     } else {
00124       ieta = 999;
00125       iphi = 999;
00126     }
00127   }
00128 
00129   double getEnergy(HBHERecHitCollection::const_iterator hit) {
00130     return hit->energy();
00131   }
00132 
00133   double getEnergy(EcalRecHitCollection::const_iterator hit) {
00134     return hit->energy();
00135   }
00136   
00137   double getEnergy(edm::PCaloHitContainer::const_iterator hit) {
00138     // This will not yet handle Ecal CaloHits!!
00139     double samplingWeight = 1.;
00140     // Hard coded sampling weights from JFH analysis of iso tracks
00141     // Sept 2009.
00142     HcalDetId detId(hit->id());
00143     if (detId.subdet() == HcalBarrel)
00144       samplingWeight = 114.1;
00145     else if (detId.subdet() == HcalEndcap) 
00146       samplingWeight = 167.3;
00147     else {
00148       // ONLY protection against summing HO, HF simhits
00149       return 0.;
00150     }
00151     
00152     return samplingWeight*hit->energy();
00153   }
00154 
00155   GlobalPoint getGpos(const CaloGeometry* geo,HBHERecHitCollection::const_iterator hit) {
00156     DetId detId(hit->id());
00157     return geo->getPosition(detId);
00158   }
00159 
00160   GlobalPoint getGpos(const CaloGeometry* geo,edm::PCaloHitContainer::const_iterator hit) {
00161     DetId detId(hit->id());
00162     return geo->getPosition(detId);
00163   }
00164 
00165   GlobalPoint getGpos(const CaloGeometry* geo, EcalRecHitCollection::const_iterator hit) {
00166     // Not tested for EcalRecHits!!
00167     if (hit->id().subdetId() == EcalEndcap) {
00168       EEDetId EEid = EEDetId(hit->id());
00169       return geo->getPosition(EEid);
00170     } else { // (hit->id().subdetId() == EcalBarrel)
00171       EBDetId EBid = EBDetId(hit->id());
00172       return geo->getPosition(EBid);
00173     }
00174   }
00175 }