Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-15 08:47:29

0001 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0002 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0003 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0004 #include "DataFormats/EgammaReco/interface/BasicClusterFwd.h"
0005 
0006 using namespace reco;
0007 
0008 GsfElectronCoreRef GsfElectron::core() const { return core_; }
0009 
0010 void GsfElectron::init() {
0011   passCutBasedPreselection_ = false;
0012   passPflowPreselection_ = false;
0013   passMvaPreslection_ = false;
0014   ambiguous_ = true;
0015   class_ = UNKNOWN;
0016 }
0017 
0018 GsfElectron::GsfElectron() { init(); }
0019 
0020 GsfElectron::GsfElectron(const GsfElectronCoreRef& core) : core_(core) { init(); }
0021 
0022 GsfElectron::GsfElectron(int charge,
0023                          const ChargeInfo& chargeInfo,
0024                          const GsfElectronCoreRef& core,
0025                          const TrackClusterMatching& tcm,
0026                          const TrackExtrapolations& te,
0027                          const ClosestCtfTrack& ctfInfo,
0028                          const FiducialFlags& ff,
0029                          const ShowerShape& ss,
0030                          const ConversionRejection& crv)
0031     : chargeInfo_(chargeInfo),
0032       core_(core),
0033       trackClusterMatching_(tcm),
0034       trackExtrapolations_(te),
0035       //closestCtfTrack_(ctfInfo),
0036       fiducialFlags_(ff),
0037       showerShape_(ss),
0038       conversionRejection_(crv) {
0039   init();
0040   setCharge(charge);
0041   setVertex(math::XYZPoint(te.positionAtVtx.x(), te.positionAtVtx.y(), te.positionAtVtx.z()));
0042   setPdgId(-11 * charge);
0043   /*if (ecalDrivenSeed())*/ corrections_.correctedEcalEnergy = superCluster()->energy();
0044   //  assert(ctfInfo.ctfTrack==(GsfElectron::core()->ctfTrack())) ;
0045   //  assert(ctfInfo.shFracInnerHits==(GsfElectron::core()->ctfGsfOverlap())) ;
0046 }
0047 
0048 GsfElectron::GsfElectron(int charge,
0049                          const ChargeInfo& chargeInfo,
0050                          const GsfElectronCoreRef& core,
0051                          const TrackClusterMatching& tcm,
0052                          const TrackExtrapolations& te,
0053                          const ClosestCtfTrack& ctfInfo,
0054                          const FiducialFlags& ff,
0055                          const ShowerShape& ss,
0056                          const ShowerShape& full5x5_ss,
0057                          const ConversionRejection& crv,
0058                          const SaturationInfo& si)
0059     : chargeInfo_(chargeInfo),
0060       core_(core),
0061       trackClusterMatching_(tcm),
0062       trackExtrapolations_(te),
0063       fiducialFlags_(ff),
0064       showerShape_(ss),
0065       full5x5_showerShape_(full5x5_ss),
0066       saturationInfo_(si),
0067       conversionRejection_(crv) {
0068   init();
0069   setCharge(charge);
0070   setVertex(math::XYZPoint(te.positionAtVtx.x(), te.positionAtVtx.y(), te.positionAtVtx.z()));
0071   setPdgId(-11 * charge);
0072   corrections_.correctedEcalEnergy = superCluster()->energy();
0073 }
0074 
0075 GsfElectron::GsfElectron(const GsfElectron& electron, const GsfElectronCoreRef& core)
0076     : RecoCandidate(electron),
0077       chargeInfo_(electron.chargeInfo_),
0078       core_(core),
0079       trackClusterMatching_(electron.trackClusterMatching_),
0080       trackExtrapolations_(electron.trackExtrapolations_),
0081       //closestCtfTrack_(electron.closestCtfTrack_),
0082       fiducialFlags_(electron.fiducialFlags_),
0083       showerShape_(electron.showerShape_),
0084       full5x5_showerShape_(electron.full5x5_showerShape_),
0085       saturationInfo_(electron.saturationInfo_),
0086       dr03_(electron.dr03_),
0087       dr04_(electron.dr04_),
0088       conversionRejection_(electron.conversionRejection_),
0089       pfIso_(electron.pfIso_),
0090       mvaInput_(electron.mvaInput_),
0091       mvaOutput_(electron.mvaOutput_),
0092       passCutBasedPreselection_(electron.passCutBasedPreselection_),
0093       passPflowPreselection_(electron.passPflowPreselection_),
0094       passMvaPreslection_(electron.passMvaPreslection_),
0095       ambiguous_(electron.ambiguous_),
0096       ambiguousGsfTracks_(electron.ambiguousGsfTracks_),
0097       classVariables_(electron.classVariables_),
0098       class_(electron.class_),
0099       corrections_(electron.corrections_),
0100       pixelMatchVariables_(electron.pixelMatchVariables_) {
0101   //assert(electron.core()->ctfTrack()==core->ctfTrack()) ;
0102   //assert(electron.core()->ctfGsfOverlap()==core->ctfGsfOverlap()) ;
0103 }
0104 
0105 GsfElectron::GsfElectron(const GsfElectron& electron,
0106                          const GsfElectronCoreRef& core,
0107                          const CaloClusterPtr& electronCluster,
0108                          const TrackRef& closestCtfTrack,
0109                          const TrackBaseRef& conversionPartner,
0110                          const GsfTrackRefVector& ambiguousTracks)
0111     : RecoCandidate(electron),
0112       chargeInfo_(electron.chargeInfo_),
0113       core_(core),
0114       trackClusterMatching_(electron.trackClusterMatching_),
0115       trackExtrapolations_(electron.trackExtrapolations_),
0116       //closestCtfTrack_(electron.closestCtfTrack_),
0117       fiducialFlags_(electron.fiducialFlags_),
0118       showerShape_(electron.showerShape_),
0119       full5x5_showerShape_(electron.full5x5_showerShape_),
0120       saturationInfo_(electron.saturationInfo_),
0121       dr03_(electron.dr03_),
0122       dr04_(electron.dr04_),
0123       conversionRejection_(electron.conversionRejection_),
0124       pfIso_(electron.pfIso_),
0125       mvaInput_(electron.mvaInput_),
0126       mvaOutput_(electron.mvaOutput_),
0127       passCutBasedPreselection_(electron.passCutBasedPreselection_),
0128       passPflowPreselection_(electron.passPflowPreselection_),
0129       passMvaPreslection_(electron.passMvaPreslection_),
0130       ambiguous_(electron.ambiguous_),
0131       ambiguousGsfTracks_(ambiguousTracks),
0132       //mva_(electron.mva_),
0133       classVariables_(electron.classVariables_),
0134       class_(electron.class_),
0135       corrections_(electron.corrections_),
0136       pixelMatchVariables_(electron.pixelMatchVariables_) {
0137   trackClusterMatching_.electronCluster = electronCluster;
0138   //closestCtfTrack_.ctfTrack = closestCtfTrack ;
0139   conversionRejection_.partner = conversionPartner;
0140   //assert(closestCtfTrack==core->ctfTrack()) ;
0141   //assert(electron.core()->ctfGsfOverlap()==core->ctfGsfOverlap()) ;
0142   // TO BE DONE
0143   // Check that the new edm references are really
0144   // the clones of the former references, and therefore other attributes
0145   // stay valid :
0146   // * electron.core_ ~ core ?
0147   // * electron.trackClusterMatching_.electronCluster ~ electronCluster ?
0148   // * electron.closestCtfTrack_.ctfTrack ~ closestCtfTrack ?
0149   // * electron.ambiguousGsfTracks_ ~ ambiguousTracks ?
0150 }
0151 
0152 bool GsfElectron::overlap(const Candidate& c) const {
0153   const RecoCandidate* o = dynamic_cast<const RecoCandidate*>(&c);
0154   return (o != nullptr && (checkOverlap(gsfTrack(), o->gsfTrack()) || checkOverlap(superCluster(), o->superCluster())));
0155   //?? return false;
0156 }
0157 
0158 GsfElectron* GsfElectron::clone() const { return new GsfElectron(*this); }
0159 
0160 GsfElectron* GsfElectron::clone(const GsfElectronCoreRef& core,
0161                                 const CaloClusterPtr& electronCluster,
0162                                 const TrackRef& closestCtfTrack,
0163                                 const TrackBaseRef& conversionPartner,
0164                                 const GsfTrackRefVector& ambiguousTracks) const {
0165   return new GsfElectron(*this, core, electronCluster, closestCtfTrack, conversionPartner, ambiguousTracks);
0166 }
0167 
0168 bool GsfElectron::ecalDriven() const { return (ecalDrivenSeed() && passingCutBasedPreselection()); }
0169 
0170 void GsfElectron::setCorrectedEcalEnergyError(float energyError) {
0171   corrections_.correctedEcalEnergyError = energyError;
0172 }
0173 
0174 void GsfElectron::setCorrectedEcalEnergy(float newEnergy) { setCorrectedEcalEnergy(newEnergy, true); }
0175 
0176 void GsfElectron::setCorrectedEcalEnergy(float newEnergy, bool rescaleDependentValues) {
0177   math::XYZTLorentzVectorD momentum = p4();
0178   momentum *= newEnergy / momentum.e();
0179   setP4(momentum);
0180   if (corrections_.correctedEcalEnergy > 0. && rescaleDependentValues) {
0181     for (size_t id = 0; id < showerShape_.hcalOverEcal.size(); ++id) {
0182       showerShape_.hcalOverEcal[id] *= corrections_.correctedEcalEnergy / newEnergy;
0183       showerShape_.hcalOverEcalBc[id] *= corrections_.correctedEcalEnergy / newEnergy;
0184     }
0185     trackClusterMatching_.eSuperClusterOverP *= newEnergy / corrections_.correctedEcalEnergy;
0186     corrections_.correctedEcalEnergyError *= newEnergy / corrections_.correctedEcalEnergy;
0187   }
0188   corrections_.correctedEcalEnergy = newEnergy;
0189   corrections_.isEcalEnergyCorrected = true;
0190 }
0191 
0192 void GsfElectron::setTrackMomentumError(float trackErr) { corrections_.trackMomentumError = trackErr; }
0193 
0194 void GsfElectron::setP4(P4Kind kind, const reco::Candidate::LorentzVector& p4, float error, bool setCandidate) {
0195   switch (kind) {
0196     case P4_FROM_SUPER_CLUSTER:
0197       corrections_.fromSuperClusterP4 = p4;
0198       corrections_.fromSuperClusterP4Error = error;
0199       break;
0200     case P4_COMBINATION:
0201       corrections_.combinedP4 = p4;
0202       corrections_.combinedP4Error = error;
0203       break;
0204     case P4_PFLOW_COMBINATION:
0205       corrections_.pflowP4 = p4;
0206       corrections_.pflowP4Error = error;
0207       break;
0208     default:
0209       throw cms::Exception("GsfElectron") << "unexpected p4 kind: " << kind;
0210   }
0211   if (setCandidate) {
0212     setP4(p4);
0213     corrections_.candidateP4Kind = kind;
0214   }
0215 }
0216 
0217 const Candidate::LorentzVector& GsfElectron::p4(P4Kind kind) const {
0218   switch (kind) {
0219     case P4_FROM_SUPER_CLUSTER:
0220       return corrections_.fromSuperClusterP4;
0221     case P4_COMBINATION:
0222       return corrections_.combinedP4;
0223     case P4_PFLOW_COMBINATION:
0224       return corrections_.pflowP4;
0225     default:
0226       throw cms::Exception("GsfElectron") << "unexpected p4 kind: " << kind;
0227   }
0228 }
0229 
0230 float GsfElectron::p4Error(P4Kind kind) const {
0231   switch (kind) {
0232     case P4_FROM_SUPER_CLUSTER:
0233       return corrections_.fromSuperClusterP4Error;
0234     case P4_COMBINATION:
0235       return corrections_.combinedP4Error;
0236     case P4_PFLOW_COMBINATION:
0237       return corrections_.pflowP4Error;
0238     default:
0239       throw cms::Exception("GsfElectron") << "unexpected p4 kind: " << kind;
0240   }
0241 }
0242 
0243 void GsfElectron::hcalToRun2EffDepth() {
0244   auto& ss1 = showerShape_;
0245   auto& ss2 = full5x5_showerShape_;
0246   auto& iv1 = dr03_;
0247   auto& iv2 = dr04_;
0248 
0249   for (uint id = 2u; id < ss1.hcalOverEcal.size(); ++id) {
0250     ss1.hcalOverEcal[1] += ss1.hcalOverEcal[id];
0251     ss1.hcalOverEcalBc[1] += ss1.hcalOverEcalBc[id];
0252 
0253     ss1.hcalOverEcal[id] = 0.f;
0254     ss1.hcalOverEcalBc[id] = 0.f;
0255 
0256     ss2.hcalOverEcal[1] += ss2.hcalOverEcal[id];
0257     ss2.hcalOverEcalBc[1] += ss2.hcalOverEcalBc[id];
0258 
0259     ss2.hcalOverEcal[id] = 0.f;
0260     ss2.hcalOverEcalBc[id] = 0.f;
0261 
0262     iv1.hcalRecHitSumEt[1] += iv1.hcalRecHitSumEt[id];
0263     iv1.hcalRecHitSumEtBc[1] += iv1.hcalRecHitSumEtBc[id];
0264 
0265     iv1.hcalRecHitSumEt[id] = 0.f;
0266     iv1.hcalRecHitSumEtBc[id] = 0.f;
0267 
0268     iv2.hcalRecHitSumEt[1] += iv2.hcalRecHitSumEt[id];
0269     iv2.hcalRecHitSumEtBc[1] += iv2.hcalRecHitSumEtBc[id];
0270 
0271     iv2.hcalRecHitSumEt[id] = 0.f;
0272     iv2.hcalRecHitSumEtBc[id] = 0.f;
0273   }
0274 }