-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
PATElectronProducer.cc
1444 lines (1267 loc) · 67.3 KB
/
PATElectronProducer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
\class pat::PATElectronProducer PATElectronProducer.h "PhysicsTools/PatAlgos/interface/PATElectronProducer.h"
\brief Produces pat::Electron's
The PATElectronProducer produces analysis-level pat::Electron's starting from
a collection of objects of reco::GsfElectron.
\author Steven Lowette, James Lamb\
\version $Id: PATElectronProducer.h,v 1.31 2013/02/27 23:26:56 wmtan Exp $
*/
#include "CommonTools/Egamma/interface/ConversionTools.h"
#include "CommonTools/Utils/interface/PtComparator.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/Candidate/interface/CandAssociation.h"
#include "DataFormats/Common/interface/Association.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
#include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
#include "DataFormats/PatCandidates/interface/PFIsolation.h"
#include "DataFormats/PatCandidates/interface/UserData.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/EmptyGroupDescription.h"
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/isFinite.h"
#include "FWCore/Utilities/interface/transform.h"
#include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
#include "Geometry/CaloTopology/interface/CaloTopology.h"
#include "Geometry/Records/interface/CaloGeometryRecord.h"
#include "Geometry/Records/interface/CaloTopologyRecord.h"
#include "PhysicsTools/PatAlgos/interface/EfficiencyLoader.h"
#include "PhysicsTools/PatAlgos/interface/KinResolutionsLoader.h"
#include "PhysicsTools/PatAlgos/interface/MultiIsolator.h"
#include "PhysicsTools/PatAlgos/interface/PATUserDataHelper.h"
#include "PhysicsTools/PatUtils/interface/CaloIsolationEnergy.h"
#include "PhysicsTools/PatUtils/interface/MiniIsolation.h"
#include "PhysicsTools/PatUtils/interface/TrackerIsolationPt.h"
#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h"
#include "TrackingTools/IPTools/interface/IPTools.h"
#include "TrackingTools/Records/interface/TransientTrackRecord.h"
#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
#include <memory>
#include <string>
#include <vector>
namespace pat {
class TrackerIsolationPt;
class CaloIsolationEnergy;
class LeptonLRCalc;
class PATElectronProducer : public edm::stream::EDProducer<> {
public:
explicit PATElectronProducer(const edm::ParameterSet& iConfig);
~PATElectronProducer() override;
void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
// configurables
const edm::EDGetTokenT<edm::View<reco::GsfElectron>> electronToken_;
const edm::EDGetTokenT<reco::ConversionCollection> hConversionsToken_;
const bool embedGsfElectronCore_;
const bool embedGsfTrack_;
const bool embedSuperCluster_;
const bool embedPflowSuperCluster_;
const bool embedSeedCluster_;
const bool embedBasicClusters_;
const bool embedPreshowerClusters_;
const bool embedPflowBasicClusters_;
const bool embedPflowPreshowerClusters_;
const bool embedTrack_;
bool addGenMatch_;
bool embedGenMatch_;
const bool embedRecHits_;
// for mini-iso calculation
edm::EDGetTokenT<pat::PackedCandidateCollection> pcToken_;
bool computeMiniIso_;
std::vector<double> miniIsoParamsE_;
std::vector<double> miniIsoParamsB_;
typedef std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> GenAssociations;
std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection>>> genMatchTokens_;
/// pflow specific
const bool useParticleFlow_;
const bool usePfCandidateMultiMap_;
const edm::EDGetTokenT<reco::PFCandidateCollection> pfElecToken_;
const edm::EDGetTokenT<edm::ValueMap<reco::PFCandidatePtr>> pfCandidateMapToken_;
const edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef>>> pfCandidateMultiMapToken_;
const bool embedPFCandidate_;
/// mva input variables
const bool addMVAVariables_;
const edm::InputTag reducedBarrelRecHitCollection_;
const edm::EDGetTokenT<EcalRecHitCollection> reducedBarrelRecHitCollectionToken_;
const edm::InputTag reducedEndcapRecHitCollection_;
const edm::EDGetTokenT<EcalRecHitCollection> reducedEndcapRecHitCollectionToken_;
const EcalClusterLazyTools::ESGetTokens ecalClusterToolsESGetTokens_;
const bool addPFClusterIso_;
const bool addPuppiIsolation_;
const edm::EDGetTokenT<edm::ValueMap<float>> ecalPFClusterIsoT_;
const edm::EDGetTokenT<edm::ValueMap<float>> hcalPFClusterIsoT_;
/// embed high level selection variables?
const bool embedHighLevelSelection_;
const edm::EDGetTokenT<reco::BeamSpot> beamLineToken_;
const edm::EDGetTokenT<std::vector<reco::Vertex>> pvToken_;
typedef edm::RefToBase<reco::GsfElectron> ElectronBaseRef;
typedef std::vector<edm::Handle<edm::ValueMap<IsoDeposit>>> IsoDepositMaps;
typedef std::vector<edm::Handle<edm::ValueMap<double>>> IsolationValueMaps;
/// common electron filling, for both the standard and PF2PAT case
void fillElectron(Electron& aElectron,
const ElectronBaseRef& electronRef,
const reco::CandidateBaseRef& baseRef,
const GenAssociations& genMatches,
const IsoDepositMaps& deposits,
const bool pfId,
const IsolationValueMaps& isolationValues,
const IsolationValueMaps& isolationValuesNoPFId) const;
void fillElectron2(Electron& anElectron,
const reco::CandidatePtr& candPtrForIsolation,
const reco::CandidatePtr& candPtrForGenMatch,
const reco::CandidatePtr& candPtrForLoader,
const GenAssociations& genMatches,
const IsoDepositMaps& deposits,
const IsolationValueMaps& isolationValues) const;
// set the mini-isolation variables
void setElectronMiniIso(pat::Electron& anElectron, const pat::PackedCandidateCollection* pc);
// embed various impact parameters with errors
// embed high level selection
void embedHighLevel(pat::Electron& anElectron,
reco::GsfTrackRef track,
reco::TransientTrack& tt,
reco::Vertex& primaryVertex,
bool primaryVertexIsValid,
reco::BeamSpot& beamspot,
bool beamspotIsValid);
typedef std::pair<pat::IsolationKeys, edm::InputTag> IsolationLabel;
typedef std::vector<IsolationLabel> IsolationLabels;
/// fill the labels vector from the contents of the parameter set,
/// for the isodeposit or isolation values embedding
template <typename T>
void readIsolationLabels(const edm::ParameterSet& iConfig,
const char* psetName,
IsolationLabels& labels,
std::vector<edm::EDGetTokenT<edm::ValueMap<T>>>& tokens);
const bool addElecID_;
typedef std::pair<std::string, edm::InputTag> NameTag;
std::vector<NameTag> elecIDSrcs_;
std::vector<edm::EDGetTokenT<edm::ValueMap<float>>> elecIDTokens_;
// tools
const GreaterByPt<Electron> pTComparator_;
pat::helper::MultiIsolator isolator_;
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_; // better here than recreate at each event
IsolationLabels isoDepositLabels_;
std::vector<edm::EDGetTokenT<edm::ValueMap<IsoDeposit>>> isoDepositTokens_;
IsolationLabels isolationValueLabels_;
std::vector<edm::EDGetTokenT<edm::ValueMap<double>>> isolationValueTokens_;
IsolationLabels isolationValueLabelsNoPFId_;
std::vector<edm::EDGetTokenT<edm::ValueMap<double>>> isolationValueNoPFIdTokens_;
const bool addEfficiencies_;
pat::helper::EfficiencyLoader efficiencyLoader_;
const bool addResolutions_;
pat::helper::KinResolutionsLoader resolutionLoader_;
const bool useUserData_;
//PUPPI isolation tokens
edm::EDGetTokenT<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons_;
edm::EDGetTokenT<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons_;
edm::EDGetTokenT<edm::ValueMap<float>> PUPPIIsolation_photons_;
//PUPPINoLeptons isolation tokens
edm::EDGetTokenT<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons_;
edm::EDGetTokenT<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons_;
edm::EDGetTokenT<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons_;
pat::PATUserDataHelper<pat::Electron> userDataHelper_;
const edm::ESGetToken<CaloTopology, CaloTopologyRecord> ecalTopologyToken_;
const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> trackBuilderToken_;
const CaloTopology* ecalTopology_;
};
} // namespace pat
template <typename T>
void pat::PATElectronProducer::readIsolationLabels(const edm::ParameterSet& iConfig,
const char* psetName,
pat::PATElectronProducer::IsolationLabels& labels,
std::vector<edm::EDGetTokenT<edm::ValueMap<T>>>& tokens) {
labels.clear();
if (iConfig.exists(psetName)) {
edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>(psetName);
if (depconf.exists("tracker"))
labels.push_back(std::make_pair(pat::TrackIso, depconf.getParameter<edm::InputTag>("tracker")));
if (depconf.exists("ecal"))
labels.push_back(std::make_pair(pat::EcalIso, depconf.getParameter<edm::InputTag>("ecal")));
if (depconf.exists("hcal"))
labels.push_back(std::make_pair(pat::HcalIso, depconf.getParameter<edm::InputTag>("hcal")));
if (depconf.exists("pfAllParticles")) {
labels.push_back(std::make_pair(pat::PfAllParticleIso, depconf.getParameter<edm::InputTag>("pfAllParticles")));
}
if (depconf.exists("pfChargedHadrons")) {
labels.push_back(
std::make_pair(pat::PfChargedHadronIso, depconf.getParameter<edm::InputTag>("pfChargedHadrons")));
}
if (depconf.exists("pfChargedAll")) {
labels.push_back(std::make_pair(pat::PfChargedAllIso, depconf.getParameter<edm::InputTag>("pfChargedAll")));
}
if (depconf.exists("pfPUChargedHadrons")) {
labels.push_back(
std::make_pair(pat::PfPUChargedHadronIso, depconf.getParameter<edm::InputTag>("pfPUChargedHadrons")));
}
if (depconf.exists("pfNeutralHadrons")) {
labels.push_back(
std::make_pair(pat::PfNeutralHadronIso, depconf.getParameter<edm::InputTag>("pfNeutralHadrons")));
}
if (depconf.exists("pfPhotons")) {
labels.push_back(std::make_pair(pat::PfGammaIso, depconf.getParameter<edm::InputTag>("pfPhotons")));
}
if (depconf.exists("user")) {
std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag>>("user");
std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
int key = pat::IsolationKeys::UserBaseIso;
for (; it != ed; ++it, ++key) {
labels.push_back(std::make_pair(pat::IsolationKeys(key), *it));
}
}
}
tokens = edm::vector_transform(
labels, [this](IsolationLabel const& label) { return consumes<edm::ValueMap<T>>(label.second); });
}
using namespace pat;
using namespace std;
PATElectronProducer::PATElectronProducer(const edm::ParameterSet& iConfig)
: // general configurables
electronToken_(consumes<edm::View<reco::GsfElectron>>(iConfig.getParameter<edm::InputTag>("electronSource"))),
hConversionsToken_(consumes<reco::ConversionCollection>(edm::InputTag("allConversions"))),
embedGsfElectronCore_(iConfig.getParameter<bool>("embedGsfElectronCore")),
embedGsfTrack_(iConfig.getParameter<bool>("embedGsfTrack")),
embedSuperCluster_(iConfig.getParameter<bool>("embedSuperCluster")),
embedPflowSuperCluster_(iConfig.getParameter<bool>("embedPflowSuperCluster")),
embedSeedCluster_(iConfig.getParameter<bool>("embedSeedCluster")),
embedBasicClusters_(iConfig.getParameter<bool>("embedBasicClusters")),
embedPreshowerClusters_(iConfig.getParameter<bool>("embedPreshowerClusters")),
embedPflowBasicClusters_(iConfig.getParameter<bool>("embedPflowBasicClusters")),
embedPflowPreshowerClusters_(iConfig.getParameter<bool>("embedPflowPreshowerClusters")),
embedTrack_(iConfig.getParameter<bool>("embedTrack")),
addGenMatch_(iConfig.getParameter<bool>("addGenMatch")),
embedGenMatch_(addGenMatch_ ? iConfig.getParameter<bool>("embedGenMatch") : false),
embedRecHits_(iConfig.getParameter<bool>("embedRecHits")),
// pflow configurables
useParticleFlow_(iConfig.getParameter<bool>("useParticleFlow")),
usePfCandidateMultiMap_(iConfig.getParameter<bool>("usePfCandidateMultiMap")),
pfElecToken_(!usePfCandidateMultiMap_
? consumes<reco::PFCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfElectronSource"))
: edm::EDGetTokenT<reco::PFCandidateCollection>()),
pfCandidateMapToken_(!usePfCandidateMultiMap_ ? mayConsume<edm::ValueMap<reco::PFCandidatePtr>>(
iConfig.getParameter<edm::InputTag>("pfCandidateMap"))
: edm::EDGetTokenT<edm::ValueMap<reco::PFCandidatePtr>>()),
pfCandidateMultiMapToken_(usePfCandidateMultiMap_
? consumes<edm::ValueMap<std::vector<reco::PFCandidateRef>>>(
iConfig.getParameter<edm::InputTag>("pfCandidateMultiMap"))
: edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef>>>()),
embedPFCandidate_(iConfig.getParameter<bool>("embedPFCandidate")),
// mva input variables
addMVAVariables_(iConfig.getParameter<bool>("addMVAVariables")),
reducedBarrelRecHitCollection_(iConfig.getParameter<edm::InputTag>("reducedBarrelRecHitCollection")),
reducedBarrelRecHitCollectionToken_(mayConsume<EcalRecHitCollection>(reducedBarrelRecHitCollection_)),
reducedEndcapRecHitCollection_(iConfig.getParameter<edm::InputTag>("reducedEndcapRecHitCollection")),
reducedEndcapRecHitCollectionToken_(mayConsume<EcalRecHitCollection>(reducedEndcapRecHitCollection_)),
ecalClusterToolsESGetTokens_{consumesCollector()},
// PFCluster Isolation maps
addPFClusterIso_(iConfig.getParameter<bool>("addPFClusterIso")),
addPuppiIsolation_(iConfig.getParameter<bool>("addPuppiIsolation")),
ecalPFClusterIsoT_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("ecalPFClusterIsoMap"))),
hcalPFClusterIsoT_(consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("hcalPFClusterIsoMap"))),
// embed high level selection variables?
embedHighLevelSelection_(iConfig.getParameter<bool>("embedHighLevelSelection")),
beamLineToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamLineSrc"))),
pvToken_(mayConsume<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("pvSrc"))),
addElecID_(iConfig.getParameter<bool>("addElectronID")),
pTComparator_(),
isolator_(iConfig.getParameter<edm::ParameterSet>("userIsolation"), consumesCollector(), false),
addEfficiencies_(iConfig.getParameter<bool>("addEfficiencies")),
addResolutions_(iConfig.getParameter<bool>("addResolutions")),
useUserData_(iConfig.exists("userData")),
ecalTopologyToken_{esConsumes()},
trackBuilderToken_{esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))} {
// MC matching configurables (scheduled mode)
if (addGenMatch_) {
genMatchTokens_.push_back(consumes<edm::Association<reco::GenParticleCollection>>(
iConfig.getParameter<edm::InputTag>("genParticleMatch")));
}
// resolution configurables
if (addResolutions_) {
resolutionLoader_ =
pat::helper::KinResolutionsLoader(iConfig.getParameter<edm::ParameterSet>("resolutions"), consumesCollector());
}
if (addPuppiIsolation_) {
//puppi
PUPPIIsolation_charged_hadrons_ =
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationChargedHadrons"));
PUPPIIsolation_neutral_hadrons_ =
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationNeutralHadrons"));
PUPPIIsolation_photons_ =
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiIsolationPhotons"));
//puppiNoLeptons
PUPPINoLeptonsIsolation_charged_hadrons_ =
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationChargedHadrons"));
PUPPINoLeptonsIsolation_neutral_hadrons_ =
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationNeutralHadrons"));
PUPPINoLeptonsIsolation_photons_ =
consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("puppiNoLeptonsIsolationPhotons"));
}
// electron ID configurables
if (addElecID_) {
// it might be a single electron ID
if (iConfig.existsAs<edm::InputTag>("electronIDSource")) {
elecIDSrcs_.push_back(NameTag("", iConfig.getParameter<edm::InputTag>("electronIDSource")));
}
// or there might be many of them
if (iConfig.existsAs<edm::ParameterSet>("electronIDSources")) {
// please don't configure me twice
if (!elecIDSrcs_.empty()) {
throw cms::Exception("Configuration")
<< "PATElectronProducer: you can't specify both 'electronIDSource' and 'electronIDSources'\n";
}
// read the different electron ID names
edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("electronIDSources");
std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
elecIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
}
}
// but in any case at least once
if (elecIDSrcs_.empty()) {
throw cms::Exception("Configuration")
<< "PATElectronProducer: id addElectronID is true, you must specify either:\n"
<< "\tInputTag electronIDSource = <someTag>\n"
<< "or\n"
<< "\tPSet electronIDSources = { \n"
<< "\t\tInputTag <someName> = <someTag> // as many as you want \n "
<< "\t}\n";
}
}
elecIDTokens_ = edm::vector_transform(
elecIDSrcs_, [this](NameTag const& tag) { return mayConsume<edm::ValueMap<float>>(tag.second); });
// construct resolution calculator
// // IsoDeposit configurables
// if (iConfig.exists("isoDeposits")) {
// edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
// if (depconf.exists("tracker")) isoDepositLabels_.push_back(std::make_pair(TrackerIso, depconf.getParameter<edm::InputTag>("tracker")));
// if (depconf.exists("ecal")) isoDepositLabels_.push_back(std::make_pair(ECalIso, depconf.getParameter<edm::InputTag>("ecal")));
// if (depconf.exists("hcal")) isoDepositLabels_.push_back(std::make_pair(HCalIso, depconf.getParameter<edm::InputTag>("hcal")));
// if (depconf.exists("user")) {
// std::vector<edm::InputTag> userdeps = depconf.getParameter<std::vector<edm::InputTag> >("user");
// std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
// int key = UserBaseIso;
// for ( ; it != ed; ++it, ++key) {
// isoDepositLabels_.push_back(std::make_pair(IsolationKeys(key), *it));
// }
// }
// }
// isoDepositTokens_ = edm::vector_transform(isoDepositLabels_, [this](std::pair<IsolationKeys,edm::InputTag> const & label){return consumes<edm::ValueMap<IsoDeposit> >(label.second);});
// for mini-iso
computeMiniIso_ = iConfig.getParameter<bool>("computeMiniIso");
miniIsoParamsE_ = iConfig.getParameter<std::vector<double>>("miniIsoParamsE");
miniIsoParamsB_ = iConfig.getParameter<std::vector<double>>("miniIsoParamsB");
if (computeMiniIso_ && (miniIsoParamsE_.size() != 9 || miniIsoParamsB_.size() != 9)) {
throw cms::Exception("ParameterError") << "miniIsoParams must have exactly 9 elements.\n";
}
if (computeMiniIso_)
pcToken_ = consumes<pat::PackedCandidateCollection>(iConfig.getParameter<edm::InputTag>("pfCandsForMiniIso"));
// read isoDeposit labels, for direct embedding
readIsolationLabels(iConfig, "isoDeposits", isoDepositLabels_, isoDepositTokens_);
// read isolation value labels, for direct embedding
readIsolationLabels(iConfig, "isolationValues", isolationValueLabels_, isolationValueTokens_);
// read isolation value labels for non PF identified electron, for direct embedding
readIsolationLabels(iConfig, "isolationValuesNoPFId", isolationValueLabelsNoPFId_, isolationValueNoPFIdTokens_);
// Efficiency configurables
if (addEfficiencies_) {
efficiencyLoader_ =
pat::helper::EfficiencyLoader(iConfig.getParameter<edm::ParameterSet>("efficiencies"), consumesCollector());
}
// Check to see if the user wants to add user data
if (useUserData_) {
userDataHelper_ =
PATUserDataHelper<Electron>(iConfig.getParameter<edm::ParameterSet>("userData"), consumesCollector());
}
// consistency check
if (useParticleFlow_ && usePfCandidateMultiMap_)
throw cms::Exception("Configuration", "usePfCandidateMultiMap not supported when useParticleFlow is set to true");
// produces vector of muons
produces<std::vector<Electron>>();
}
PATElectronProducer::~PATElectronProducer() {}
void PATElectronProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
// switch off embedding (in unschedules mode)
if (iEvent.isRealData()) {
addGenMatch_ = false;
embedGenMatch_ = false;
}
ecalTopology_ = &iSetup.getData(ecalTopologyToken_);
// Get the collection of electrons from the event
edm::Handle<edm::View<reco::GsfElectron>> electrons;
iEvent.getByToken(electronToken_, electrons);
edm::Handle<PackedCandidateCollection> pc;
if (computeMiniIso_)
iEvent.getByToken(pcToken_, pc);
// for additional mva variables
edm::InputTag reducedEBRecHitCollection(string("reducedEcalRecHitsEB"));
edm::InputTag reducedEERecHitCollection(string("reducedEcalRecHitsEE"));
//EcalClusterLazyTools lazyTools(iEvent, iSetup, reducedEBRecHitCollection, reducedEERecHitCollection);
EcalClusterLazyTools lazyTools(iEvent,
ecalClusterToolsESGetTokens_.get(iSetup),
reducedBarrelRecHitCollectionToken_,
reducedEndcapRecHitCollectionToken_);
// for conversion veto selection
edm::Handle<reco::ConversionCollection> hConversions;
iEvent.getByToken(hConversionsToken_, hConversions);
// Get the ESHandle for the transient track builder, if needed for
// high level selection embedding
edm::ESHandle<TransientTrackBuilder> trackBuilder;
if (isolator_.enabled())
isolator_.beginEvent(iEvent, iSetup);
if (efficiencyLoader_.enabled())
efficiencyLoader_.newEvent(iEvent);
if (resolutionLoader_.enabled())
resolutionLoader_.newEvent(iEvent, iSetup);
IsoDepositMaps deposits(isoDepositTokens_.size());
for (size_t j = 0, nd = isoDepositTokens_.size(); j < nd; ++j) {
iEvent.getByToken(isoDepositTokens_[j], deposits[j]);
}
IsolationValueMaps isolationValues(isolationValueTokens_.size());
for (size_t j = 0; j < isolationValueTokens_.size(); ++j) {
iEvent.getByToken(isolationValueTokens_[j], isolationValues[j]);
}
IsolationValueMaps isolationValuesNoPFId(isolationValueNoPFIdTokens_.size());
for (size_t j = 0; j < isolationValueNoPFIdTokens_.size(); ++j) {
iEvent.getByToken(isolationValueNoPFIdTokens_[j], isolationValuesNoPFId[j]);
}
// prepare the MC matching
GenAssociations genMatches(genMatchTokens_.size());
if (addGenMatch_) {
for (size_t j = 0, nd = genMatchTokens_.size(); j < nd; ++j) {
iEvent.getByToken(genMatchTokens_[j], genMatches[j]);
}
}
// prepare ID extraction
std::vector<edm::Handle<edm::ValueMap<float>>> idhandles;
std::vector<pat::Electron::IdPair> ids;
if (addElecID_) {
idhandles.resize(elecIDSrcs_.size());
ids.resize(elecIDSrcs_.size());
for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
iEvent.getByToken(elecIDTokens_[i], idhandles[i]);
ids[i].first = elecIDSrcs_[i].first;
}
}
// prepare the high level selection:
// needs beamline
reco::TrackBase::Point beamPoint(0, 0, 0);
reco::Vertex primaryVertex;
reco::BeamSpot beamSpot;
bool beamSpotIsValid = false;
bool primaryVertexIsValid = false;
// Get the beamspot
edm::Handle<reco::BeamSpot> beamSpotHandle;
iEvent.getByToken(beamLineToken_, beamSpotHandle);
if (embedHighLevelSelection_) {
// Get the primary vertex
edm::Handle<std::vector<reco::Vertex>> pvHandle;
iEvent.getByToken(pvToken_, pvHandle);
// This is needed by the IPTools methods from the tracking group
trackBuilder = iSetup.getHandle(trackBuilderToken_);
if (pvHandle.isValid() && !pvHandle->empty()) {
primaryVertex = pvHandle->at(0);
primaryVertexIsValid = true;
} else {
edm::LogError("DataNotAvailable")
<< "No primary vertex available from EventSetup, not adding high level selection \n";
}
}
//value maps for puppi isolation
edm::Handle<edm::ValueMap<float>> PUPPIIsolation_charged_hadrons;
edm::Handle<edm::ValueMap<float>> PUPPIIsolation_neutral_hadrons;
edm::Handle<edm::ValueMap<float>> PUPPIIsolation_photons;
//value maps for puppiNoLeptons isolation
edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_charged_hadrons;
edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_neutral_hadrons;
edm::Handle<edm::ValueMap<float>> PUPPINoLeptonsIsolation_photons;
if (addPuppiIsolation_) {
//puppi
iEvent.getByToken(PUPPIIsolation_charged_hadrons_, PUPPIIsolation_charged_hadrons);
iEvent.getByToken(PUPPIIsolation_neutral_hadrons_, PUPPIIsolation_neutral_hadrons);
iEvent.getByToken(PUPPIIsolation_photons_, PUPPIIsolation_photons);
//puppiNoLeptons
iEvent.getByToken(PUPPINoLeptonsIsolation_charged_hadrons_, PUPPINoLeptonsIsolation_charged_hadrons);
iEvent.getByToken(PUPPINoLeptonsIsolation_neutral_hadrons_, PUPPINoLeptonsIsolation_neutral_hadrons);
iEvent.getByToken(PUPPINoLeptonsIsolation_photons_, PUPPINoLeptonsIsolation_photons);
}
std::vector<Electron>* patElectrons = new std::vector<Electron>();
if (useParticleFlow_) {
edm::Handle<reco::PFCandidateCollection> pfElectrons;
iEvent.getByToken(pfElecToken_, pfElectrons);
unsigned index = 0;
for (reco::PFCandidateConstIterator i = pfElectrons->begin(); i != pfElectrons->end(); ++i, ++index) {
reco::PFCandidateRef pfRef(pfElectrons, index);
reco::PFCandidatePtr ptrToPFElectron(pfElectrons, index);
// reco::CandidateBaseRef pfBaseRef( pfRef );
reco::GsfTrackRef PfTk = i->gsfTrackRef();
bool Matched = false;
bool MatchedToAmbiguousGsfTrack = false;
for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end();
++itElectron) {
unsigned int idx = itElectron - electrons->begin();
auto elePtr = electrons->ptrAt(idx);
if (Matched || MatchedToAmbiguousGsfTrack)
continue;
reco::GsfTrackRef EgTk = itElectron->gsfTrack();
if (itElectron->gsfTrack() == i->gsfTrackRef()) {
Matched = true;
} else {
for (auto const& it : itElectron->ambiguousGsfTracks()) {
MatchedToAmbiguousGsfTrack |= (bool)(i->gsfTrackRef() == it);
}
}
if (Matched || MatchedToAmbiguousGsfTrack) {
// ptr needed for finding the matched gen particle
reco::CandidatePtr ptrToGsfElectron(electrons, idx);
// ref to base needed for the construction of the pat object
const edm::RefToBase<reco::GsfElectron>& elecsRef = electrons->refAt(idx);
Electron anElectron(elecsRef);
anElectron.setPFCandidateRef(pfRef);
if (addPuppiIsolation_) {
anElectron.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[elePtr],
(*PUPPIIsolation_neutral_hadrons)[elePtr],
(*PUPPIIsolation_photons)[elePtr]);
anElectron.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[elePtr],
(*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
(*PUPPINoLeptonsIsolation_photons)[elePtr]);
} else {
anElectron.setIsolationPUPPI(-999., -999., -999.);
anElectron.setIsolationPUPPINoLeptons(-999., -999., -999.);
}
//it should be always true when particleFlow electrons are used.
anElectron.setIsPF(true);
if (embedPFCandidate_)
anElectron.embedPFCandidate();
if (useUserData_) {
userDataHelper_.add(anElectron, iEvent, iSetup);
}
double ip3d = -999; // for mva variable
// embed high level selection
if (embedHighLevelSelection_) {
// get the global track
const reco::GsfTrackRef& track = PfTk;
// Make sure the collection it points to is there
if (track.isNonnull() && track.isAvailable()) {
reco::TransientTrack tt = trackBuilder->build(track);
embedHighLevel(anElectron, track, tt, primaryVertex, primaryVertexIsValid, beamSpot, beamSpotIsValid);
std::pair<bool, Measurement1D> ip3dpv = IPTools::absoluteImpactParameter3D(tt, primaryVertex);
ip3d = ip3dpv.second.value(); // for mva variable
}
}
//Electron Id
if (addElecID_) {
//STANDARD EL ID
for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
ids[i].second = (*idhandles[i])[elecsRef];
}
//SPECIFIC PF ID
ids.push_back(std::make_pair("pf_evspi", pfRef->mva_e_pi()));
ids.push_back(std::make_pair("pf_evsmu", pfRef->mva_e_mu()));
anElectron.setElectronIDs(ids);
}
if (addMVAVariables_) {
// add missing mva variables
const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
anElectron.setMvaVariables(vCov[1], ip3d);
}
// PFClusterIso
if (addPFClusterIso_) {
// Get PFCluster Isolation
edm::Handle<edm::ValueMap<float>> ecalPFClusterIsoMapH;
iEvent.getByToken(ecalPFClusterIsoT_, ecalPFClusterIsoMapH);
edm::Handle<edm::ValueMap<float>> hcalPFClusterIsoMapH;
iEvent.getByToken(hcalPFClusterIsoT_, hcalPFClusterIsoMapH);
reco::GsfElectron::PflowIsolationVariables newPFIsol = anElectron.pfIsolationVariables();
newPFIsol.sumEcalClusterEt = (*ecalPFClusterIsoMapH)[elecsRef];
newPFIsol.sumHcalClusterEt = (*hcalPFClusterIsoMapH)[elecsRef];
anElectron.setPfIsolationVariables(newPFIsol);
}
std::vector<DetId> selectedCells;
bool barrel = itElectron->isEB();
//loop over sub clusters
if (embedBasicClusters_) {
for (reco::CaloCluster_iterator clusIt = itElectron->superCluster()->clustersBegin();
clusIt != itElectron->superCluster()->clustersEnd();
++clusIt) {
//get seed (max energy xtal)
DetId seed = lazyTools.getMaximum(**clusIt).first;
//get all xtals in 5x5 window around the seed
std::vector<DetId> dets5x5 =
(barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalBarrel)->getWindow(seed, 5, 5)
: ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalEndcap)->getWindow(seed, 5, 5);
selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
//get all xtals belonging to cluster
for (const std::pair<DetId, float>& hit : (*clusIt)->hitsAndFractions()) {
selectedCells.push_back(hit.first);
}
}
}
if (embedPflowBasicClusters_ && itElectron->parentSuperCluster().isNonnull()) {
for (reco::CaloCluster_iterator clusIt = itElectron->parentSuperCluster()->clustersBegin();
clusIt != itElectron->parentSuperCluster()->clustersEnd();
++clusIt) {
//get seed (max energy xtal)
DetId seed = lazyTools.getMaximum(**clusIt).first;
//get all xtals in 5x5 window around the seed
std::vector<DetId> dets5x5 =
(barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalBarrel)->getWindow(seed, 5, 5)
: ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalEndcap)->getWindow(seed, 5, 5);
selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
//get all xtals belonging to cluster
for (const std::pair<DetId, float>& hit : (*clusIt)->hitsAndFractions()) {
selectedCells.push_back(hit.first);
}
}
}
//remove duplicates
std::sort(selectedCells.begin(), selectedCells.end());
std::unique(selectedCells.begin(), selectedCells.end());
// Retrieve the corresponding RecHits
edm::Handle<EcalRecHitCollection> rechitsH;
if (barrel)
iEvent.getByToken(reducedBarrelRecHitCollectionToken_, rechitsH);
else
iEvent.getByToken(reducedEndcapRecHitCollectionToken_, rechitsH);
EcalRecHitCollection selectedRecHits;
const EcalRecHitCollection* recHits = rechitsH.product();
unsigned nSelectedCells = selectedCells.size();
for (unsigned icell = 0; icell < nSelectedCells; ++icell) {
EcalRecHitCollection::const_iterator it = recHits->find(selectedCells[icell]);
if (it != recHits->end()) {
selectedRecHits.push_back(*it);
}
}
selectedRecHits.sort();
if (embedRecHits_)
anElectron.embedRecHits(&selectedRecHits);
// set conversion veto selection
bool passconversionveto = false;
if (hConversions.isValid()) {
// this is recommended method
passconversionveto =
!ConversionTools::hasMatchedConversion(*itElectron, *hConversions, beamSpotHandle->position());
} else {
// use missing hits without vertex fit method
passconversionveto =
itElectron->gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) < 1;
}
anElectron.setPassConversionVeto(passconversionveto);
// fillElectron(anElectron,elecsRef,pfBaseRef,
// genMatches, deposits, isolationValues);
//COLIN small warning !
// we are currently choosing to take the 4-momentum of the PFCandidate;
// the momentum of the GsfElectron is saved though
// we must therefore match the GsfElectron.
// because of this, we should not change the source of the electron matcher
// to the collection of PFElectrons in the python configuration
// I don't know what to do with the efficiencyLoader, since I don't know
// what this class is for.
fillElectron2(
anElectron, ptrToPFElectron, ptrToGsfElectron, ptrToGsfElectron, genMatches, deposits, isolationValues);
//COLIN need to use fillElectron2 in the non-pflow case as well, and to test it.
if (computeMiniIso_)
setElectronMiniIso(anElectron, pc.product());
patElectrons->push_back(anElectron);
}
}
//if( !Matched && !MatchedToAmbiguousGsfTrack) std::cout << "!!!!A pf electron could not be matched to a gsf!!!!" << std::endl;
}
}
else {
edm::Handle<reco::PFCandidateCollection> pfElectrons;
edm::Handle<edm::ValueMap<reco::PFCandidatePtr>> ValMapH;
edm::Handle<edm::ValueMap<std::vector<reco::PFCandidateRef>>> ValMultiMapH;
bool pfCandsPresent = false, valMapPresent = false;
if (usePfCandidateMultiMap_) {
iEvent.getByToken(pfCandidateMultiMapToken_, ValMultiMapH);
} else {
pfCandsPresent = iEvent.getByToken(pfElecToken_, pfElectrons);
valMapPresent = iEvent.getByToken(pfCandidateMapToken_, ValMapH);
}
for (edm::View<reco::GsfElectron>::const_iterator itElectron = electrons->begin(); itElectron != electrons->end();
++itElectron) {
// construct the Electron from the ref -> save ref to original object
//FIXME: looks like a lot of instances could be turned into const refs
unsigned int idx = itElectron - electrons->begin();
edm::RefToBase<reco::GsfElectron> elecsRef = electrons->refAt(idx);
reco::CandidateBaseRef elecBaseRef(elecsRef);
Electron anElectron(elecsRef);
auto elePtr = electrons->ptrAt(idx);
// Is this GsfElectron also identified as an e- in the particle flow?
bool pfId = false;
if (usePfCandidateMultiMap_) {
for (const reco::PFCandidateRef& pf : (*ValMultiMapH)[elePtr]) {
if (pf->particleId() == reco::PFCandidate::e) {
pfId = true;
anElectron.setPFCandidateRef(pf);
break;
}
}
} else if (pfCandsPresent) {
// PF electron collection not available.
const reco::GsfTrackRef& trkRef = itElectron->gsfTrack();
int index = 0;
for (reco::PFCandidateConstIterator ie = pfElectrons->begin(); ie != pfElectrons->end(); ++ie, ++index) {
if (ie->particleId() != reco::PFCandidate::e)
continue;
const reco::GsfTrackRef& pfTrkRef = ie->gsfTrackRef();
if (trkRef == pfTrkRef) {
pfId = true;
reco::PFCandidateRef pfRef(pfElectrons, index);
anElectron.setPFCandidateRef(pfRef);
break;
}
}
} else if (valMapPresent) {
// use value map if PF collection not available
const edm::ValueMap<reco::PFCandidatePtr>& myValMap(*ValMapH);
// Get the PFCandidate
const reco::PFCandidatePtr& pfElePtr(myValMap[elecsRef]);
pfId = pfElePtr.isNonnull();
}
// set PFId function
anElectron.setIsPF(pfId);
// add resolution info
// Isolation
if (isolator_.enabled()) {
isolator_.fill(*electrons, idx, isolatorTmpStorage_);
typedef pat::helper::MultiIsolator::IsolationValuePairs IsolationValuePairs;
// better to loop backwards, so the vector is resized less times
for (IsolationValuePairs::const_reverse_iterator it = isolatorTmpStorage_.rbegin(),
ed = isolatorTmpStorage_.rend();
it != ed;
++it) {
anElectron.setIsolation(it->first, it->second);
}
}
for (size_t j = 0, nd = deposits.size(); j < nd; ++j) {
anElectron.setIsoDeposit(isoDepositLabels_[j].first, (*deposits[j])[elecsRef]);
}
// add electron ID info
if (addElecID_) {
for (size_t i = 0; i < elecIDSrcs_.size(); ++i) {
ids[i].second = (*idhandles[i])[elecsRef];
}
anElectron.setElectronIDs(ids);
}
if (useUserData_) {
userDataHelper_.add(anElectron, iEvent, iSetup);
}
double ip3d = -999; //for mva variable
// embed high level selection
if (embedHighLevelSelection_) {
// get the global track
reco::GsfTrackRef track = itElectron->gsfTrack();
// Make sure the collection it points to is there
if (track.isNonnull() && track.isAvailable()) {
reco::TransientTrack tt = trackBuilder->build(track);
embedHighLevel(anElectron, track, tt, primaryVertex, primaryVertexIsValid, beamSpot, beamSpotIsValid);
std::pair<bool, Measurement1D> ip3dpv = IPTools::absoluteImpactParameter3D(tt, primaryVertex);
ip3d = ip3dpv.second.value(); // for mva variable
}
}
if (addMVAVariables_) {
// add mva variables
const auto& vCov = lazyTools.localCovariances(*(itElectron->superCluster()->seed()));
anElectron.setMvaVariables(vCov[1], ip3d);
}
// PFCluster Isolation
if (addPFClusterIso_) {
// Get PFCluster Isolation
edm::Handle<edm::ValueMap<float>> ecalPFClusterIsoMapH;
iEvent.getByToken(ecalPFClusterIsoT_, ecalPFClusterIsoMapH);
edm::Handle<edm::ValueMap<float>> hcalPFClusterIsoMapH;
iEvent.getByToken(hcalPFClusterIsoT_, hcalPFClusterIsoMapH);
reco::GsfElectron::PflowIsolationVariables newPFIsol = anElectron.pfIsolationVariables();
newPFIsol.sumEcalClusterEt = (*ecalPFClusterIsoMapH)[elecsRef];
newPFIsol.sumHcalClusterEt = (*hcalPFClusterIsoMapH)[elecsRef];
anElectron.setPfIsolationVariables(newPFIsol);
}
if (addPuppiIsolation_) {
anElectron.setIsolationPUPPI((*PUPPIIsolation_charged_hadrons)[elePtr],
(*PUPPIIsolation_neutral_hadrons)[elePtr],
(*PUPPIIsolation_photons)[elePtr]);
anElectron.setIsolationPUPPINoLeptons((*PUPPINoLeptonsIsolation_charged_hadrons)[elePtr],
(*PUPPINoLeptonsIsolation_neutral_hadrons)[elePtr],
(*PUPPINoLeptonsIsolation_photons)[elePtr]);
} else {
anElectron.setIsolationPUPPI(-999., -999., -999.);
anElectron.setIsolationPUPPINoLeptons(-999., -999., -999.);
}
std::vector<DetId> selectedCells;
bool barrel = itElectron->isEB();
//loop over sub clusters
if (embedBasicClusters_) {
for (reco::CaloCluster_iterator clusIt = itElectron->superCluster()->clustersBegin();
clusIt != itElectron->superCluster()->clustersEnd();
++clusIt) {
//get seed (max energy xtal)
DetId seed = lazyTools.getMaximum(**clusIt).first;
//get all xtals in 5x5 window around the seed
std::vector<DetId> dets5x5 =
(barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalBarrel)->getWindow(seed, 5, 5)
: ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalEndcap)->getWindow(seed, 5, 5);
selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
//get all xtals belonging to cluster
for (const std::pair<DetId, float>& hit : (*clusIt)->hitsAndFractions()) {
selectedCells.push_back(hit.first);
}
}
}
if (embedPflowBasicClusters_ && itElectron->parentSuperCluster().isNonnull()) {
for (reco::CaloCluster_iterator clusIt = itElectron->parentSuperCluster()->clustersBegin();
clusIt != itElectron->parentSuperCluster()->clustersEnd();
++clusIt) {
//get seed (max energy xtal)
DetId seed = lazyTools.getMaximum(**clusIt).first;
//get all xtals in 5x5 window around the seed
std::vector<DetId> dets5x5 =
(barrel) ? ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalBarrel)->getWindow(seed, 5, 5)
: ecalTopology_->getSubdetectorTopology(DetId::Ecal, EcalEndcap)->getWindow(seed, 5, 5);
selectedCells.insert(selectedCells.end(), dets5x5.begin(), dets5x5.end());
//get all xtals belonging to cluster
for (const std::pair<DetId, float>& hit : (*clusIt)->hitsAndFractions()) {
selectedCells.push_back(hit.first);
}
}
}
//remove duplicates
std::sort(selectedCells.begin(), selectedCells.end());
std::unique(selectedCells.begin(), selectedCells.end());
// Retrieve the corresponding RecHits
edm::Handle<EcalRecHitCollection> rechitsH;
if (barrel)
iEvent.getByToken(reducedBarrelRecHitCollectionToken_, rechitsH);
else
iEvent.getByToken(reducedEndcapRecHitCollectionToken_, rechitsH);
EcalRecHitCollection selectedRecHits;
const EcalRecHitCollection* recHits = rechitsH.product();
unsigned nSelectedCells = selectedCells.size();
for (unsigned icell = 0; icell < nSelectedCells; ++icell) {
EcalRecHitCollection::const_iterator it = recHits->find(selectedCells[icell]);
if (it != recHits->end()) {
selectedRecHits.push_back(*it);
}
}
selectedRecHits.sort();
if (embedRecHits_)
anElectron.embedRecHits(&selectedRecHits);
// set conversion veto selection
bool passconversionveto = false;
if (hConversions.isValid()) {
// this is recommended method
passconversionveto =
!ConversionTools::hasMatchedConversion(*itElectron, *hConversions, beamSpotHandle->position());
} else {
// use missing hits without vertex fit method
passconversionveto =
itElectron->gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) < 1;
}
anElectron.setPassConversionVeto(passconversionveto);