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();
145 auto output_preid = std::make_unique<ElectronSeedCollection>();
146 auto output_nopre = std::make_unique<TrajectorySeedCollection>();
147 auto output_preidinfo = std::make_unique<PreIdCollection>();
148 auto preIdMap_p = std::make_unique<edm::ValueMap<reco::PreIdRef>>();
180 vector<PFCluster const *> basClus;
181 for (
auto const & klus : *theECPfClustCollection.
product() ) {
182 if(klus.correctedEnergy()>
clusThreshold_) basClus.push_back(&klus);
201 LogDebug(
"GoodSeedProducer")<<
"Number of tracks in collection " 202 <<
"tracksContainers_[" << istr <<
"] to be analyzed " 206 for(
unsigned int i=0;
i<Tk.size();++
i){
211 bool GoodPreId=
false;
215 auto tketa= tkmom.eta();
217 auto const & Seed=(*trackRef->seedRef());
225 float nchi=Tk[
i].normalizedChi2();
227 int nhitpi=Tk[
i].found();
235 auto pfoutenergy=
sqrt((pfmass*pfmass)+Tk[
i].outerMomentum().Mag2());
238 Tk[
i].outerMomentum().
y(),
239 Tk[
i].outerMomentum().
z(),
242 Tk[
i].outerPosition().
y(),
243 Tk[
i].outerPosition().
z(),
250 theOutParticle.propagateToEcalEntrance(
false);
263 if(theOutParticle.getSuccess()!=0){
264 ElecTrkEcalPos=
GlobalPoint(theOutParticle.vertex().x(),
265 theOutParticle.vertex().y(),
266 theOutParticle.vertex().z()
270 bool isBelowPS= (ElecTrkEcalPos.
z()*ElecTrkEcalPos.
z()) > (psLim*psLim)*ElecTrkEcalPos.
perp2();
273 unsigned clusCounter=0;
275 for(
auto aClus : basClus) {
277 float tmp_ep=
float(aClus->correctedEnergy())*oPTOB;
278 if ((tmp_ep<
minEp_)|(tmp_ep>
maxEp_)) { ++clusCounter;
continue;}
280 double ecalShowerDepth
281 = PFCluster::getDepthCorrection(aClus->correctedEnergy(),
284 auto mom = theOutParticle.momentum().Vect();
285 auto meanShower = ElecTrkEcalPos +
288 float etarec=meanShower.eta();
289 float phirec=meanShower.phi();
292 float tmp_phi=
std::abs(aClus->positionREP().phi()-phirec);
296 std::pow(aClus->positionREP().eta()-etarec,2.f));
301 if(aClus->correctedEnergy() > max_ee){
303 toteta=aClus->positionREP().eta()-etarec;
306 EE=aClus->correctedEnergy();
307 feta= aClus->positionREP().eta();
308 clusterRef =
PFClusterRef(theECPfClustCollection,clusCounter);
309 meanShowerSaved = meanShower;
317 float trk_ecalDeta_ = fabs(toteta);
318 float trk_ecalDphi_ = fabs(totphi);
327 float chieta=(toteta!=1000.f)? toteta/ecaletares : toteta;
328 float chiphi=(totphi!=1000.f)? totphi/ecalphires : totphi;
329 float chichi=
sqrt(chieta*chieta + chiphi*chiphi);
332 float eta_cut =
thr[ibin+0];
333 float phi_cut =
thr[ibin+1];
334 float ep_cutmin=
thr[ibin+2];
335 bool GoodMatching= ((trk_ecalDeta_<eta_cut) && (trk_ecalDphi_<phi_cut) && (EP>ep_cutmin) && (nhitpi>10));
337 bool EcalMatching=GoodMatching;
339 if (tkpt>
maxPt_) GoodMatching=
true;
340 if (tkpt<
minPt_) GoodMatching=
false;
344 math::XYZPoint myPoint(ElecTrkEcalPos.
x(),ElecTrkEcalPos.
y(),ElecTrkEcalPos.
z());
353 int hit1max=
int(
thr[ibin+3]);
354 float chiredmin=
thr[ibin+4];
355 bool GoodKFFiltering =
356 ((nchi>chiredmin) | (nhitpi<hit1max));
361 bool GoodTkId=
false;
363 if((!GoodMatching) &&(GoodKFFiltering) &&(GoodRange)){
373 auto hb = Tk[
i].recHitsBegin();
374 for(
unsigned int h=0;
h<Tk[
i].recHitsSize();
h++){
377 auto const & theTrack = Tk[
i];
378 GlobalVector gv(theTrack.innerMomentum().x(),theTrack.innerMomentum().y(),theTrack.innerMomentum().z());
379 GlobalPoint gp(theTrack.innerPosition().x(),theTrack.innerPosition().y(),theTrack.innerPosition().z());
384 if(FitTjs.isValid()){
394 dpt=(pt_in>0) ? fabs(pt_out-pt_in)/pt_in : 0.;
411 float Ytmva = globalCache()->gbr[ipteta]->GetClassifier( vars );
413 float BDTcut=
thr[ibin+5];
414 if ( Ytmva>BDTcut) GoodTkId=
true;
415 myPreId.
setMVA(GoodTkId,Ytmva);
419 float chiratiocut=
thr[ibin+6];
420 float gschicut=
thr[ibin+7];
421 float gsptmin=
thr[ibin+8];
428 GoodPreId= GoodTkId | GoodMatching;
434 LogDebug(
"GoodSeedProducer")<<
"Track (pt= "<<Tk[
i].pt()<<
435 "GeV/c, eta= "<<Tk[
i].eta() <<
436 ") preidentified for agreement between track and ECAL cluster";
437 if(GoodPreId &&(!GoodMatching))
438 LogDebug(
"GoodSeedProducer")<<
"Track (pt= "<<Tk[
i].pt()<<
439 "GeV/c, eta= "<<Tk[
i].eta() <<
440 ") preidentified only for track properties";
450 output_preid->push_back(NewSeed);
453 output_nopre->push_back(Seed);
459 refMap_[trackRef] = output_preidinfo->size();
460 output_preidinfo->push_back(myPreId);
504 for(UInt_t j = 0; j < gbr.size(); ++j){
505 TMVA::Reader
reader(
"!Color:Silent");
507 reader.AddVariable(
"NHits", &
nhit);
508 reader.AddVariable(
"NormChi", &
chikfred);
509 reader.AddVariable(
"dPtGSF", &
dpt);
510 reader.AddVariable(
"EoP", &
eP);
511 reader.AddVariable(
"ChiRatio", &
chiRatio);
512 reader.AddVariable(
"RedChi", &
chired);
515 reader.AddVariable(
"pt", &
pt);
516 reader.AddVariable(
"eta", &
eta);
518 reader.BookMVA(method_, weights[j].fullPath().c_str());
520 gbr[j].reset(
new GBRForest( dynamic_cast<TMVA::MethodBDT*>( reader.FindMVA(method_) ) ) );
547 ifstream ifs(parFile.
fullPath().c_str());
548 for (
int iy=0;iy<81;++iy) ifs >>
thr[iy];
555 if (fabs(eta)<0.8) ie=0;
556 else{
if (fabs(eta)<1.479) ie=1;
560 else {
if (pt<12) ip=1;
564 LogDebug(
"GoodSeedProducer")<<
"Track pt ="<<pt<<
" eta="<<eta<<
" bin="<<iep;
572 std::vector<reco::PreIdRef>
values;
574 unsigned ntracks=tracks->size();
575 for(
unsigned itrack=0;itrack<ntracks;++itrack)
578 std::map<reco::TrackRef,unsigned>::const_iterator itcheck=
refMap_.find(theTrackRef);
587 values.push_back(preIdRef);
591 filler.
insert(tracks,values.begin(),values.end());
int nHitsInSeed_
Number of hits in the seed;.
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void setECALMatchingProperties(PFClusterRef clusterRef, const math::XYZPoint &ecalpos, const math::XYZPoint &meanShower, float deta, float dphi, float chieta, float chiphi, float chi2, float eop)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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)
virtual TrajectorySmoother * clone() const =0
void setTrack(reco::TrackRef trackref)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
virtual std::unique_ptr< TrajectoryFitter > clone() const =0
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)
std::string method_
TMVA method.
double EcalStripSumE_deltaEta_
double EcalStripSumE_deltaPhiOverQ_minValue_
double EcalStripSumE_deltaPhiOverQ_maxValue_
void setTrackFiltering(bool accepted, unsigned n=0)
void produce(edm::Event &, const edm::EventSetup &) override
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
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
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.
bool disablePreId_
switch to disable the pre-id
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< float > > XYZVectorF
spatial vector with cartesian internal representation
void beginRun(const edm::Run &run, const edm::EventSetup &) override
reco::TrackBase::TrackQuality trackQuality_
double clusThreshold_
Cut on the energy of the clusters.
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
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
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 fullPath() const
std::string trackerRecHitBuilderName_
std::string smootherName_
edm::EDGetTokenT< reco::PFClusterCollection > pfCLusTagHCLabel_
Resolution Map (resolution as a function of eta and E)
std::string preidgsf_
Name of the Seed(Gsf) Collection.
T const * product() const
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