00001 #include "DataFormats/EgammaCandidates/interface/Conversion.h"
00002 #include "DataFormats/TrackReco/interface/Track.h"
00003 #include "DataFormats/CaloRecHit/interface/CaloCluster.h"
00004 #include "CLHEP/Units/GlobalPhysicalConstants.h"
00005
00006
00007
00008
00009
00010
00011
00012 #if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 4
00013 # pragma GCC diagnostic ignored "-Warray-bounds"
00014 #endif
00015
00016 using namespace reco;
00017
00018
00019 Conversion::Conversion( const reco::CaloClusterPtrVector sc,
00020 const std::vector<reco::TrackRef> tr,
00021 const std::vector<math::XYZPoint> trackPositionAtEcal,
00022 const reco::Vertex & convVtx,
00023 const std::vector<reco::CaloClusterPtr> & matchingBC,
00024 const float DCA,
00025 const std::vector<math::XYZPoint> & innPoint,
00026 const std::vector<math::XYZVector> & trackPin,
00027 const std::vector<math::XYZVector> & trackPout,
00028 const float mva,
00029 ConversionAlgorithm algo):
00030
00031
00032 caloCluster_(sc), tracks_(tr),
00033 thePositionAtEcal_(trackPositionAtEcal),
00034 theConversionVertex_(convVtx),
00035 theMatchingBCs_(matchingBC),
00036 theMinDistOfApproach_(DCA),
00037 theTrackInnerPosition_(innPoint),
00038 theTrackPin_(trackPin),
00039 theTrackPout_(trackPout),
00040 nSharedHits_(0),
00041 theMVAout_(mva),
00042 algorithm_(algo),
00043 qualityMask_(0)
00044 {
00045
00046 }
00047
00048
00049
00050
00051 Conversion::Conversion( const reco::CaloClusterPtrVector sc,
00052 const std::vector<edm::RefToBase<reco::Track> > tr,
00053 const std::vector<math::XYZPoint> trackPositionAtEcal,
00054 const reco::Vertex & convVtx,
00055 const std::vector<reco::CaloClusterPtr> & matchingBC,
00056 const float DCA,
00057 const std::vector<math::XYZPoint> & innPoint,
00058 const std::vector<math::XYZVector> & trackPin,
00059 const std::vector<math::XYZVector> & trackPout,
00060 const std::vector<uint8_t> nHitsBeforeVtx,
00061 const std::vector<Measurement1DFloat> & dlClosestHitToVtx,
00062 uint8_t nSharedHits,
00063 const float mva,
00064 ConversionAlgorithm algo):
00065
00066
00067 caloCluster_(sc), trackToBaseRefs_(tr),
00068 thePositionAtEcal_(trackPositionAtEcal),
00069 theConversionVertex_(convVtx),
00070 theMatchingBCs_(matchingBC),
00071 theMinDistOfApproach_(DCA),
00072 theTrackInnerPosition_(innPoint),
00073 theTrackPin_(trackPin),
00074 theTrackPout_(trackPout),
00075 nHitsBeforeVtx_(nHitsBeforeVtx),
00076 dlClosestHitToVtx_(dlClosestHitToVtx),
00077 nSharedHits_(nSharedHits),
00078 theMVAout_(mva),
00079 algorithm_(algo),
00080 qualityMask_(0)
00081 {
00082
00083 }
00084
00085
00086
00087
00088 Conversion::Conversion( const reco::CaloClusterPtrVector sc,
00089 const std::vector<reco::TrackRef> tr,
00090 const reco::Vertex & convVtx,
00091 ConversionAlgorithm algo):
00092 caloCluster_(sc), tracks_(tr),
00093 theConversionVertex_(convVtx),
00094 nSharedHits_(0),
00095 algorithm_(algo),
00096 qualityMask_(0)
00097 {
00098
00099
00100 theMinDistOfApproach_ = 9999.;
00101 theMVAout_ = 9999.;
00102 thePositionAtEcal_.push_back(math::XYZPoint(0.,0.,0.));
00103 thePositionAtEcal_.push_back(math::XYZPoint(0.,0.,0.));
00104 theTrackInnerPosition_.push_back(math::XYZPoint(0.,0.,0.));
00105 theTrackInnerPosition_.push_back(math::XYZPoint(0.,0.,0.));
00106 theTrackPin_.push_back(math::XYZVector(0.,0.,0.));
00107 theTrackPin_.push_back(math::XYZVector(0.,0.,0.));
00108 theTrackPout_.push_back(math::XYZVector(0.,0.,0.));
00109 theTrackPout_.push_back(math::XYZVector(0.,0.,0.));
00110
00111
00112 }
00113
00114
00115 Conversion::Conversion( const reco::CaloClusterPtrVector sc,
00116 const std::vector<edm::RefToBase<reco::Track> > tr,
00117 const reco::Vertex & convVtx,
00118 ConversionAlgorithm algo):
00119 caloCluster_(sc), trackToBaseRefs_(tr),
00120 theConversionVertex_(convVtx),
00121 nSharedHits_(0),
00122 algorithm_(algo),
00123 qualityMask_(0)
00124 {
00125
00126
00127 theMinDistOfApproach_ = 9999.;
00128 theMVAout_ = 9999.;
00129 thePositionAtEcal_.push_back(math::XYZPoint(0.,0.,0.));
00130 thePositionAtEcal_.push_back(math::XYZPoint(0.,0.,0.));
00131 theTrackInnerPosition_.push_back(math::XYZPoint(0.,0.,0.));
00132 theTrackInnerPosition_.push_back(math::XYZPoint(0.,0.,0.));
00133 theTrackPin_.push_back(math::XYZVector(0.,0.,0.));
00134 theTrackPin_.push_back(math::XYZVector(0.,0.,0.));
00135 theTrackPout_.push_back(math::XYZVector(0.,0.,0.));
00136 theTrackPout_.push_back(math::XYZVector(0.,0.,0.));
00137
00138
00139 }
00140
00141
00142
00143 Conversion::Conversion() {
00144
00145 algorithm_=0;
00146 qualityMask_=0;
00147 theMinDistOfApproach_ = 9999.;
00148 nSharedHits_ = 0;
00149 theMVAout_ = 9999.;
00150 thePositionAtEcal_.push_back(math::XYZPoint(0.,0.,0.));
00151 thePositionAtEcal_.push_back(math::XYZPoint(0.,0.,0.));
00152 theTrackInnerPosition_.push_back(math::XYZPoint(0.,0.,0.));
00153 theTrackInnerPosition_.push_back(math::XYZPoint(0.,0.,0.));
00154 theTrackPin_.push_back(math::XYZVector(0.,0.,0.));
00155 theTrackPin_.push_back(math::XYZVector(0.,0.,0.));
00156 theTrackPout_.push_back(math::XYZVector(0.,0.,0.));
00157 theTrackPout_.push_back(math::XYZVector(0.,0.,0.));
00158
00159 }
00160
00161
00162 Conversion::~Conversion() { }
00163
00164
00165 std::string const Conversion::algoNames[] = { "undefined","ecalSeeded","trackerOnly","mixed"};
00166
00167 Conversion::ConversionAlgorithm Conversion::algoByName(const std::string &name){
00168 ConversionAlgorithm size = algoSize;
00169 int index = std::find(algoNames, algoNames+size, name)-algoNames;
00170 if(index == size) return undefined;
00171
00172 return ConversionAlgorithm(index);
00173 }
00174
00175 Conversion * Conversion::clone() const {
00176 return new Conversion( * this );
00177 }
00178
00179
00180 std::vector<edm::RefToBase<reco::Track> > Conversion::tracks() const {
00181 if (trackToBaseRefs_.size() ==0 ) {
00182
00183 for (std::vector<reco::TrackRef>::const_iterator ref=tracks_.begin(); ref!=tracks_.end(); ref++ )
00184 {
00185 edm::RefToBase<reco::Track> tt(*ref);
00186 trackToBaseRefs_.push_back(tt);
00187
00188 }
00189 }
00190
00191 return trackToBaseRefs_;
00192 }
00193
00194
00195
00196 bool Conversion::isConverted() const {
00197
00198 if ( this->nTracks() == 2 )
00199 return true;
00200 else
00201 return false;
00202 }
00203
00204
00205 double Conversion::zOfPrimaryVertexFromTracks() const {
00206 double theZOfPrimaryVertexFromTracks=-9999.;
00207
00208 if ( this->conversionVertex().isValid() && sqrt(this->conversionVertex().position().perp2()) !=0 ) {
00209 float theta=this->pairMomentum().Theta();
00210 theZOfPrimaryVertexFromTracks = this->conversionVertex().position().z() - sqrt(this->conversionVertex().position().perp2())*(1./tan(theta));
00211
00212 }
00213
00214 return theZOfPrimaryVertexFromTracks;
00215
00216 }
00217
00218
00219 double Conversion::pairInvariantMass() const{
00220 double invMass=-99.;
00221 const float mElec= 0.000511;
00222 if ( nTracks()==2 ) {
00223 double px= tracksPin()[0].x() + tracksPin()[1].x();
00224 double py= tracksPin()[0].y() + tracksPin()[1].y();
00225 double pz= tracksPin()[0].z() + tracksPin()[1].z();
00226 double mom1= tracksPin()[0].Mag2();
00227 double mom2= tracksPin()[1].Mag2();
00228 double e = sqrt( mom1+ mElec*mElec ) + sqrt( mom2 + mElec*mElec );
00229 invMass= ( e*e - px*px -py*py - pz*pz);
00230 if ( invMass>0) invMass = sqrt(invMass);
00231 else
00232 invMass = -1;
00233 }
00234
00235 return invMass;
00236 }
00237
00238 double Conversion::pairCotThetaSeparation() const {
00239 double dCotTheta=-99.;
00240
00241 if ( nTracks()==2 ) {
00242 double theta1=this->tracksPin()[0].Theta();
00243 double theta2=this->tracksPin()[1].Theta();
00244 dCotTheta = 1./tan(theta1) - 1./tan(theta2) ;
00245 }
00246
00247 return dCotTheta;
00248
00249 }
00250
00251
00252 math::XYZVector Conversion::pairMomentum() const {
00253
00254 if ( nTracks()==2 ) {
00255 return this->tracksPin()[0] + this->tracksPin()[1];
00256 }
00257 return math::XYZVector(0.,0.,0.);
00258
00259
00260
00261 }
00262
00263
00264 math::XYZTLorentzVectorD Conversion::refittedPair4Momentum() const {
00265
00266 math::XYZTLorentzVectorD p4;
00267 if ( this->conversionVertex().isValid() )
00268 p4 = this->conversionVertex().p4( 0.000511, 0.5);
00269
00270 return p4;
00271
00272
00273 }
00274
00275
00276
00277 math::XYZVector Conversion::refittedPairMomentum() const {
00278
00279 if ( this->conversionVertex().isValid() ) {
00280 return this->refittedPair4Momentum().Vect();
00281 }
00282 return math::XYZVector(0.,0.,0.);
00283
00284 }
00285
00286
00287
00288 double Conversion::EoverP() const {
00289
00290
00291 double ep=-99.;
00292
00293 if ( nTracks() > 0 ) {
00294 unsigned int size= this->caloCluster().size();
00295 float etot=0.;
00296 for ( unsigned int i=0; i<size; i++) {
00297 etot+= caloCluster()[i]->energy();
00298 }
00299 if (this->pairMomentum().Mag2() !=0) ep= etot/sqrt(this->pairMomentum().Mag2());
00300 }
00301
00302
00303
00304 return ep;
00305
00306 }
00307
00308
00309
00310 double Conversion::EoverPrefittedTracks() const {
00311
00312
00313 double ep=-99.;
00314
00315 if ( nTracks() > 0 ) {
00316 unsigned int size= this->caloCluster().size();
00317 float etot=0.;
00318 for ( unsigned int i=0; i<size; i++) {
00319 etot+= caloCluster()[i]->energy();
00320 }
00321 if (this->refittedPairMomentum().Mag2() !=0) ep= etot/sqrt(this->refittedPairMomentum().Mag2());
00322 }
00323
00324
00325
00326 return ep;
00327
00328 }
00329
00330
00331
00332 std::vector<double> Conversion::tracksSigned_d0() const {
00333 std::vector<double> result;
00334
00335 for (unsigned int i=0; i< nTracks(); i++)
00336 result.push_back(tracks()[i]->d0()* tracks()[i]->charge()) ;
00337
00338 return result;
00339
00340
00341 }
00342
00343 double Conversion::dPhiTracksAtVtx() const {
00344 double result=-99;
00345 if ( nTracks()==2 ) {
00346 result = tracksPin()[0].phi() - tracksPin()[1].phi();
00347 if( result > pi) { result = result - twopi;}
00348 if( result < -pi) { result = result + twopi;}
00349 }
00350
00351 return result;
00352
00353
00354 }
00355
00356 double Conversion::dPhiTracksAtEcal() const {
00357 double result =-99.;
00358
00359 if ( nTracks()==2 && bcMatchingWithTracks()[0].isNonnull() && bcMatchingWithTracks()[1].isNonnull() ) {
00360
00361 float recoPhi1 = ecalImpactPosition()[0].phi();
00362 if( recoPhi1 > pi) { recoPhi1 = recoPhi1 - twopi;}
00363 if( recoPhi1 < -pi) { recoPhi1 = recoPhi1 + twopi;}
00364
00365 float recoPhi2 = ecalImpactPosition()[1].phi();
00366 if( recoPhi2 > pi) { recoPhi2 = recoPhi2 - twopi;}
00367 if( recoPhi2 < -pi) { recoPhi2 = recoPhi2 + twopi;}
00368
00369 result = recoPhi1 -recoPhi2;
00370
00371 if( result > pi) { result = result - twopi;}
00372 if( result < -pi) { result = result + twopi;}
00373
00374 }
00375
00376 return result;
00377
00378
00379 }
00380
00381 double Conversion::dEtaTracksAtEcal() const {
00382 double result=-99.;
00383
00384
00385 if ( nTracks()==2 && bcMatchingWithTracks()[0].isNonnull() && bcMatchingWithTracks()[1].isNonnull() ) {
00386
00387 result =ecalImpactPosition()[0].eta() - ecalImpactPosition()[1].eta();
00388
00389 }
00390
00391
00392
00393 return result;
00394
00395
00396 }
00397