CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/RecoHI/HiEgammaAlgos/src/TxCalculator.cc

Go to the documentation of this file.
00001 // ROOT includes
00002 #include <Math/VectorUtil.h>
00003 
00004 #include "RecoHI/HiEgammaAlgos/interface/TxCalculator.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00008 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00009 
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00012 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00013 #include "DataFormats/PatCandidates/interface/Photon.h"
00014 #include "DataFormats/Math/interface/Vector3D.h"
00015 
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00018 
00019 using namespace edm;
00020 using namespace reco;
00021 using namespace std;
00022 using namespace ROOT::Math::VectorUtil; 
00023 
00024 
00025 TxCalculator::TxCalculator (const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::InputTag trackLabel)
00026 {
00027    iEvent.getByLabel(trackLabel, recCollection); 
00028    edm::Service<edm::RandomNumberGenerator> rng;
00029    if ( ! rng.isAvailable()) {
00030       throw cms::Exception("Configuration")
00031          << "XXXXXXX requires the RandomNumberGeneratorService\n"
00032          "which is not present in the configuration file.  You must add the service\n"
00033          "in the configuration file or remove the modules that require it.";
00034    }
00035    CLHEP::HepRandomEngine& engine = rng->getEngine();
00036    theDice = new CLHEP::RandFlat(engine, 0, 1);
00037    
00038 } 
00039 
00040 
00041 double TxCalculator::getJurassicArea( double r1, double r2, double width) {
00042    
00043    float theta1 = asin( width / r1);
00044    float theta2 = asin( width / r2);
00045    float theA   = sqrt ( r1*r1 + r2*r2 - 2 * r1 * r2 * cos ( theta1 - theta2) );
00046    float area1 =  0.5 * r1*r1 * ( 3.141592 - 2 * theta1 )   ;
00047    float area2 =  0.5 * r2*r2 * ( 3.141592 - 2 * theta2 )   ;
00048    float area3 =  width * theA;
00049    float finalArea = 2 * ( area1 - area2 - area3);
00050    return finalArea;
00051 }
00052 
00053 
00054 double TxCalculator::getMPT( double ptCut     ,   double etaCut  )
00055 {
00056    using namespace edm;
00057    using namespace reco;
00058    
00059    double sumpx(0), sumpy(0);
00060    
00061    for(reco::TrackCollection::const_iterator
00062           recTrack = recCollection->begin(); recTrack!= recCollection->end(); recTrack++)
00063       {
00064          double pt = recTrack->pt();
00065          double eta = recTrack->eta();
00066          
00067          if(pt < ptCut ) 
00068             continue;
00069          if ( fabs( eta) > etaCut ) 
00070             continue;
00071          
00072          double pxTemp = recTrack->px();
00073          double pyTemp = recTrack->py();
00074          
00075          sumpx = sumpx + pxTemp;
00076          sumpy = sumpy + pyTemp;
00077          //      cout << " pt  = " << recTrack->pt() <<  "    and px = " << pxTemp << " and  py = " << pyTemp << endl;
00078       }
00079    //   cout << " square = " << sumpx*sumpx + sumpy*sumpy << endl;
00080    double theMPT = sqrt(sumpx*sumpx + sumpy*sumpy) ;
00081    //  cout << " mpt    = "<< theMPT << endl;
00082    
00083    return theMPT;
00084 }
00085 
00086 
00087 double TxCalculator::getTx(const reco::Photon cluster, double x, double threshold, double innerDR, double effRatio)
00088 {
00089 
00090    using namespace edm;
00091    using namespace reco;
00092 
00093    
00094    
00095    double SClusterEta = cluster.eta();
00096    double SClusterPhi = cluster.phi();
00097    double TotalPt = 0;
00098    
00099    for(reco::TrackCollection::const_iterator
00100           recTrack = recCollection->begin(); recTrack!= recCollection->end(); recTrack++)
00101       {
00102          double diceNum = theDice->fire();
00103          if ( (effRatio < 1 ) &&  ( diceNum > effRatio))
00104             continue;
00105          
00106          double pt = recTrack->pt();
00107          double eta2 = recTrack->eta();
00108          double phi2 = recTrack->phi();
00109          
00110          if(dRDistance(SClusterEta,SClusterPhi,eta2,phi2) >= 0.1 * x)
00111             continue;
00112          if(dRDistance(SClusterEta,SClusterPhi,eta2,phi2) < innerDR)
00113             continue;
00114          if(pt > threshold)
00115             TotalPt = TotalPt + pt;
00116       }
00117    
00118    return TotalPt;
00119 }
00120 
00121 
00122 
00123 
00124 
00125 double TxCalculator::getCTx(const reco::Photon cluster, double x, double threshold, double innerDR,double effRatio)
00126 {
00127    using namespace edm;
00128    using namespace reco;
00129 
00130    double SClusterEta = cluster.eta();
00131    double SClusterPhi = cluster.phi();
00132    double TotalPt = 0;
00133 
00134    TotalPt = 0;
00135 
00136    for(reco::TrackCollection::const_iterator
00137           recTrack = recCollection->begin(); recTrack!= recCollection->end(); recTrack++)
00138       {
00139          double diceNum = theDice->fire();
00140          if ( (effRatio < 1 ) &&  ( diceNum > effRatio))
00141             continue;
00142          
00143          
00144          double pt = recTrack->pt();
00145          double eta2 = recTrack->eta();
00146          double phi2 = recTrack->phi();
00147          double dEta = fabs(eta2-SClusterEta);
00148          
00149       if(dEta >= 0.1 * x)
00150          continue;
00151       if(dRDistance(SClusterEta,SClusterPhi,eta2,phi2) < innerDR)
00152          continue;
00153       
00154       if(pt > threshold)
00155          TotalPt = TotalPt + pt;
00156    }
00157    
00158    double Tx = getTx(cluster,x,threshold,innerDR,effRatio);
00159    double CTx = Tx - TotalPt / 40.0 * x;
00160 
00161    return CTx;
00162 }
00163 
00164 
00165 
00166 double TxCalculator::getJt(const reco::Photon cluster, double r1, double r2, double jWidth, double threshold)
00167 {
00168 
00169    using namespace edm;
00170    using namespace reco;
00171 
00172 
00173    double SClusterEta = cluster.eta();
00174    double SClusterPhi = cluster.phi();
00175    double TotalPt = 0;
00176 
00177    for(reco::TrackCollection::const_iterator
00178           recTrack = recCollection->begin(); recTrack!= recCollection->end(); recTrack++)
00179       {
00180          double pt = recTrack->pt();
00181          double eta = recTrack->eta();
00182          double phi = recTrack->phi();
00183          double dEta = fabs(eta-SClusterEta);
00184          double dPhi = phi-SClusterPhi;
00185          if ( dPhi < -PI )    dPhi = dPhi + 2*PI ;
00186          if ( dPhi >  PI )    dPhi = dPhi - 2*PI ;
00187          if ( fabs(dPhi) >PI )   cout << " error!!! dphi > 2pi   : " << dPhi << endl;
00188          double dR = sqrt(dEta*dEta+dPhi*dPhi);
00189          // Jurassic Cone /////                                                                                                     
00190          if ( dR > r1 ) continue;
00191          if ( dR < r2 ) continue;
00192          if ( fabs(dEta) <  jWidth)  continue;
00193          // stupid bug if ( fabs(dPhi) >  jWidth)  continue;
00195          
00196          if(pt > threshold)
00197             TotalPt = TotalPt + pt;
00198       }
00199 
00200    return TotalPt;
00201 }
00202 
00203 
00204 double TxCalculator::getJct(const reco::Photon cluster, double r1, double r2, double jWidth, double threshold)
00205 {
00206 
00207    using namespace edm;
00208    using namespace reco;
00209 
00210 
00211    double SClusterEta = cluster.eta();
00212    double SClusterPhi = cluster.phi();
00213    double TotalPt = 0;
00214 
00215    for(reco::TrackCollection::const_iterator
00216           recTrack = recCollection->begin(); recTrack!= recCollection->end(); recTrack++)
00217       {
00218          double pt = recTrack->pt();
00219          double eta = recTrack->eta();
00220          double phi = recTrack->phi();
00221          double dEta = fabs(eta-SClusterEta);
00222          double dPhi = phi-SClusterPhi;
00223          if ( dPhi < -PI )    dPhi = dPhi + 2*PI ;
00224          if ( dPhi >  PI )    dPhi = dPhi - 2*PI ;
00225          if ( fabs(dPhi) >PI )   cout << " error!!! dphi > 2pi   : " << dPhi << endl;
00226          //         double dR = sqrt(dEta*dEta+dPhi*dPhi);
00227          
00228 
00230          if ( fabs(dEta) > r1 ) continue;
00231          if ( fabs(dPhi) <r1 ) continue;
00233          
00234          if(pt > threshold)
00235             TotalPt = TotalPt + pt;
00236       }
00237    
00238    double areaStrip = 4*PI*r1 -  4*r1*r1;
00239    double areaJura  = getJurassicArea(r1,r2, jWidth) ;
00240    double theCJ     = getJt(cluster,r1,  r2, jWidth, threshold);
00241 
00242    double theCCJ   = theCJ - TotalPt * areaJura / areaStrip ;
00243    return theCCJ;
00244 
00245 }
00246