35 #include "Math/VectorUtil.h"
36 #include "TMVA/MethodBDT.h"
48 LogInfo(
"GoodSeedProducer")<<
"Electron PreIdentification started ";
51 std::vector<edm::InputTag>
tags = iConfig.
getParameter< vector < InputTag > >(
"TkColList");
52 for(
unsigned int i=0;
i<tags.size();++
i) {
103 LogDebug(
"GoodSeedProducer")<<
"Seeds for GSF will be produced ";
106 produces<ElectronSeedCollection>(
preidgsf_);
109 LogDebug(
"GoodSeedProducer")<<
"Seeds for CKF will be produced ";
110 produces<TrajectorySeedCollection>(
preidckf_);
114 LogDebug(
"GoodSeedProducer")<<
"PreId debugging information will be produced ";
143 <<
" in run "<<iEvent.
id().
run();
176 vector<PFCluster const *> basClus;
177 for (
auto const & klus : *theECPfClustCollection.
product() ) {
178 if(klus.correctedEnergy()>
clusThreshold_) basClus.push_back(&klus);
200 auto const & Tj=*(tjCollection.
product());
202 LogDebug(
"GoodSeedProducer")<<
"Number of tracks in collection "
207 for(
unsigned int i=0;
i<Tk.size();++
i){
212 bool GoodPreId=
false;
217 auto tketa= tkmom.eta();
219 auto const & Seed=(*trackRef->seedRef());
225 float oPTOB=1.f/Tj[
i].lastMeasurement().updatedState().globalMomentum().mag();
227 float nchi=Tk[
i].normalizedChi2();
229 int nhitpi=Tj[
i].foundHits();
237 auto pfoutenergy=
sqrt((pfmass*pfmass)+Tk[
i].outerMomentum().Mag2());
240 Tk[
i].outerMomentum().
y(),
241 Tk[
i].outerMomentum().
z(),
244 Tk[
i].outerPosition().
y(),
245 Tk[
i].outerPosition().
z(),
252 theOutParticle.propagateToEcalEntrance(
false);
265 if(theOutParticle.getSuccess()!=0){
266 ElecTrkEcalPos=
GlobalPoint(theOutParticle.vertex().x(),
267 theOutParticle.vertex().y(),
268 theOutParticle.vertex().z()
272 bool isBelowPS= (ElecTrkEcalPos.
z()*ElecTrkEcalPos.
z()) > (psLim*psLim)*ElecTrkEcalPos.
perp2();
275 unsigned clusCounter=0;
277 for(
auto aClus : basClus) {
279 float tmp_ep=float(aClus->correctedEnergy())*oPTOB;
280 if ((tmp_ep<
minEp_)|(tmp_ep>
maxEp_)) { ++clusCounter;
continue;}
282 double ecalShowerDepth
283 = PFCluster::getDepthCorrection(aClus->correctedEnergy(),
286 auto mom = theOutParticle.momentum().Vect();
287 auto meanShower = ElecTrkEcalPos +
290 float etarec=meanShower.eta();
291 float phirec=meanShower.phi();
294 float tmp_phi=
std::abs(aClus->positionREP().phi()-phirec);
298 std::pow(aClus->positionREP().eta()-etarec,2.f));
303 if(aClus->correctedEnergy() > max_ee){
305 toteta=aClus->positionREP().eta()-etarec;
308 EE=aClus->correctedEnergy();
309 feta= aClus->positionREP().eta();
310 clusterRef =
PFClusterRef(theECPfClustCollection,clusCounter);
311 meanShowerSaved = meanShower;
319 float trk_ecalDeta_ = fabs(toteta);
320 float trk_ecalDphi_ = fabs(totphi);
329 float chieta=(toteta!=1000.f)? toteta/ecaletares : toteta;
330 float chiphi=(totphi!=1000.f)? totphi/ecalphires : totphi;
331 float chichi=
sqrt(chieta*chieta + chiphi*chiphi);
334 float eta_cut =
thr[ibin+0];
335 float phi_cut =
thr[ibin+1];
336 float ep_cutmin=
thr[ibin+2];
337 bool GoodMatching= ((trk_ecalDeta_<eta_cut) && (trk_ecalDphi_<phi_cut) && (EP>ep_cutmin) && (nhitpi>10));
339 bool EcalMatching=GoodMatching;
341 if (tkpt>
maxPt_) GoodMatching=
true;
342 if (tkpt<
minPt_) GoodMatching=
false;
346 math::XYZPoint myPoint(ElecTrkEcalPos.
x(),ElecTrkEcalPos.
y(),ElecTrkEcalPos.
z());
355 int hit1max=int(
thr[ibin+3]);
356 float chiredmin=
thr[ibin+4];
357 bool GoodKFFiltering =
358 ((nchi>chiredmin) | (nhitpi<hit1max));
363 bool GoodTkId=
false;
365 if((!GoodMatching) &&(GoodKFFiltering) &&(GoodRange)){
376 for (
int ih=hits.size()-1; ih>=0; ih--) tmp.push_back(hits[ih]);
377 Trajectory && FitTjs=
fitter_->fitOne(Seed,tmp,Tj[
i].lastMeasurement().updatedState());
386 updatedState().globalMomentum().perp();
388 updatedState().globalMomentum().perp();
389 dpt=(pt_in>0) ? fabs(pt_out-pt_in)/pt_in : 0.;
406 float Ytmva = globalCache()->gbr[ipteta]->GetClassifier( vars );
408 float BDTcut=
thr[ibin+5];
409 if ( Ytmva>BDTcut) GoodTkId=
true;
410 myPreId.
setMVA(GoodTkId,Ytmva);
414 float chiratiocut=
thr[ibin+6];
415 float gschicut=
thr[ibin+7];
416 float gsptmin=
thr[ibin+8];
423 GoodPreId= GoodTkId | GoodMatching;
428 LogDebug(
"GoodSeedProducer")<<
"Track (pt= "<<Tk[
i].pt()<<
429 "GeV/c, eta= "<<Tk[
i].eta() <<
430 ") preidentified for agreement between track and ECAL cluster";
431 if(GoodPreId &&(!GoodMatching))
432 LogDebug(
"GoodSeedProducer")<<
"Track (pt= "<<Tk[
i].pt()<<
433 "GeV/c, eta= "<<Tk[
i].eta() <<
434 ") preidentified only for track properties";
442 output_preid->push_back(NewSeed);
445 output_nopre->push_back(Seed);
451 refMap_[trackRef] = output_preidinfo->size();
452 output_preidinfo->push_back(myPreId);
479 namespace goodseedhelpers {
496 for(UInt_t
j = 0;
j <
gbr.size(); ++
j){
497 TMVA::Reader
reader(
"!Color:Silent");
499 reader.AddVariable(
"NHits", &
nhit);
500 reader.AddVariable(
"NormChi", &
chikfred);
501 reader.AddVariable(
"dPtGSF", &
dpt);
502 reader.AddVariable(
"EoP", &
eP);
503 reader.AddVariable(
"ChiRatio", &
chiRatio);
504 reader.AddVariable(
"RedChi", &
chired);
507 reader.AddVariable(
"pt", &
pt);
508 reader.AddVariable(
"eta", &
eta);
510 std::unique_ptr<TMVA::IMethod>
temp( reader.BookMVA(method_, weights[
j].fullPath().c_str()) );
512 gbr[
j].reset(
new GBRForest( dynamic_cast<TMVA::MethodBDT*>( reader.FindMVA(method_) ) ) );
539 ifstream ifs(parFile.
fullPath().c_str());
540 for (
int iy=0;iy<81;++iy) ifs >>
thr[iy];
547 if (fabs(eta)<0.8) ie=0;
548 else{
if (fabs(eta)<1.479) ie=1;
552 else {
if (pt<12) ip=1;
556 LogDebug(
"GoodSeedProducer")<<
"Track pt ="<<pt<<
" eta="<<eta<<
" bin="<<iep;
564 std::vector<reco::PreIdRef>
values;
566 unsigned ntracks=tracks->size();
567 for(
unsigned itrack=0;itrack<ntracks;++itrack)
570 std::map<reco::TrackRef,unsigned>::const_iterator itcheck=
refMap_.find(theTrackRef);
579 values.push_back(preIdRef);
583 filler.
insert(tracks,values.begin(),values.end());
int nHitsInSeed_
Number of hits in the seed;.
void setCharge(float q)
set the MEASURED charge
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
void setECALMatchingProperties(PFClusterRef clusterRef, const math::XYZPoint &ecalpos, const math::XYZPoint &meanShower, float deta, float dphi, float chieta, float chiphi, float chi2, float eop)
std::vector< reco::PreId > PreIdCollection
std::string preidckf_
Name of the Seed(Ckf) Collection.
edm::EDGetTokenT< reco::PFClusterCollection > pfCLusTagPSLabel_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
float eP
VARIABLES NEEDED FOR TMVA.
std::unique_ptr< TrajectorySmoother > smoother_
Smoother.
void insert(const H &h, I begin, I end)
Global3DPoint GlobalPoint
std::unique_ptr< PFResolutionMap > resMapEtaECAL_
std::vector< Track > TrackCollection
collection of Tracks
double EcalStripSumE_minClusEnergy_
float thr[150]
vector of thresholds for different bins of eta and pt
GoodSeedProducer(const edm::ParameterSet &, const goodseedhelpers::HeavyObjectCache *)
void setCtfTrack(const CtfTrackRef &)
Set additional info.
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setTrack(reco::TrackRef trackref)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
int getBin(float, float)
Find the bin in pt and eta.
std::unique_ptr< TrajectoryFitter > fitter_
Fitter.
void setMVA(bool accepted, float mva, unsigned n=0)
HeavyObjectCache(const edm::ParameterSet &conf)
double EcalStripSumE_deltaEta_
double EcalStripSumE_deltaPhiOverQ_minValue_
std::vector< TrajectorySeed > TrajectorySeedCollection
double EcalStripSumE_deltaPhiOverQ_maxValue_
void setTrackFiltering(bool accepted, unsigned n=0)
virtual void produce(edm::Event &, const edm::EventSetup &) override
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
edm::Ref< PFClusterCollection > PFClusterRef
persistent reference to PFCluster objects
math::XYZVector B_
B field.
std::string preidname_
Name of the preid Collection (FB)
TrajectoryMeasurement const & lastMeasurement() const
std::array< std::unique_ptr< const GBRForest >, kMaxWeights > gbr
TypeLabelItem const & produces()
declare what type of product will make and with which optional label
Abs< T >::type abs(const T &t)
bool useQuality_
TRACK QUALITY.
void fillPreIdRefValueMap(edm::Handle< reco::TrackCollection > tkhandle, const edm::OrphanHandle< reco::PreIdCollection > &, edm::ValueMap< reco::PreIdRef >::Filler &filler)
double minPt_
Minimum transverse momentum and maximum pseudorapidity.
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
bool disablePreId_
switch to disable the pre-id
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
virtual void beginRun(const edm::Run &run, const edm::EventSetup &) override
reco::TrackBase::TrackQuality trackQuality_
double clusThreshold_
Cut on the energy of the clusters.
bool produceCkfseed_
Produce the Seed for Ckf tracks?
TrajectoryMeasurement const & firstMeasurement() const
T const * product() const
bool useTmva_
USE OF TMVA.
std::unique_ptr< PFResolutionMap > resMapPhiECAL_
XYZPointD XYZPoint
point in space with cartesian internal representation
T const * product() const
TrackingRecHit::ConstRecHitContainer ConstRecHitContainer
std::vector< edm::EDGetTokenT< reco::TrackCollection > > tracksContainers_
std::vector< std::vector< double > > tmp
void setTrackProperties(float newchi2, float chi2ratio, float dpt)
void setECALMatching(bool accepted, unsigned n=0)
std::map< reco::TrackRef, unsigned > refMap_
Map used to create the TrackRef, PreIdRef value map.
bool producePreId_
Produce the pre-id debugging collection.
std::unique_ptr< PFTrackTransformer > pfTransformer_
PFTrackTransformer.
std::string trackerRecHitBuilderName_
std::string smootherName_
edm::EDGetTokenT< reco::PFClusterCollection > pfCLusTagHCLabel_
std::string fullPath() const
Resolution Map (resolution as a function of eta and E)
std::string preidgsf_
Name of the Seed(Gsf) Collection.
edm::EDGetTokenT< reco::PFClusterCollection > pfCLusTagECLabel_
double minEp_
Min and MAx allowed values forEoverP.
Power< A, B >::type pow(const A &a, const B &b)
std::vector< edm::EDGetTokenT< std::vector< Trajectory > > > trajContainers_
double PtThresholdSavePredId_
Threshold to save Pre Idinfo.
Global3DVector GlobalVector
void setFinalDecision(bool accepted, unsigned n=0)
math::XYZTLorentzVector XYZTLorentzVector