1414#include " FWCore/MessageLogger/interface/MessageLogger.h"
1515#include " FWCore/ParameterSet/interface/ParameterSet.h"
1616#include " FWCore/Utilities/interface/ESGetToken.h"
17+ #include " FWCore/Utilities/interface/EDPutToken.h"
1718#include " FWCore/Utilities/interface/Exception.h"
1819#include " Geometry/CaloGeometry/interface/CaloCellGeometry.h"
1920#include " Geometry/CaloGeometry/interface/CaloGeometry.h"
2425#include " Geometry/Records/interface/CaloGeometryRecord.h"
2526#include " RecoEcal/EgammaClusterAlgos/interface/Multi5x5ClusterAlgo.h"
2627#include " RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
28+ #include " FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
2729
2830#include < ctime>
2931#include < iostream>
@@ -34,142 +36,113 @@ class Multi5x5ClusterProducer : public edm::stream::EDProducer<> {
3436public:
3537 Multi5x5ClusterProducer (const edm::ParameterSet& ps);
3638
37- ~Multi5x5ClusterProducer () override ;
39+ void produce (edm::Event&, const edm::EventSetup&) final ;
3840
39- void produce (edm::Event&, const edm::EventSetup&) override ;
41+ static void fillDescriptions (edm::ConfigurationDescriptions&) ;
4042
4143private:
42- int nMaxPrintout_; // max # of printouts
43- int nEvt_; // internal counter of events
44+ const edm::EDGetTokenT<EcalRecHitCollection> barrelHitToken_;
45+ const edm::EDGetTokenT<EcalRecHitCollection> endcapHitToken_;
46+ const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeometryToken_;
4447
45- // cluster which regions
46- bool doBarrel_;
47- bool doEndcap_;
48-
49- edm::EDGetTokenT<EcalRecHitCollection> barrelHitToken_;
50- edm::EDGetTokenT<EcalRecHitCollection> endcapHitToken_;
51- edm::ESGetToken<CaloGeometry, CaloGeometryRecord> caloGeometryToken_;
52-
53- std::string barrelClusterCollection_;
54- std::string endcapClusterCollection_;
55-
56- PositionCalc posCalculator_; // position calculation algorithm
57- Multi5x5ClusterAlgo* island_p;
48+ const edm::EDPutTokenT<reco::BasicClusterCollection> barrelToken_;
49+ const edm::EDPutTokenT<reco::BasicClusterCollection> endcapToken_;
5850
59- bool counterExceeded () const { return ((nEvt_ > nMaxPrintout_) || (nMaxPrintout_ < 0 )); }
51+ Multi5x5ClusterAlgo island_;
6052
61- const EcalRecHitCollection* getCollection (edm::Event& evt, const edm::EDGetTokenT<EcalRecHitCollection>& token);
62-
63- void clusterizeECALPart (edm::Event& evt,
64- const edm::EventSetup& es,
65- const edm::EDGetTokenT<EcalRecHitCollection>& token,
66- const std::string& clusterCollection,
67- const reco::CaloID::Detectors detector);
68-
69- void outputValidationInfo (reco::CaloClusterPtrVector& clusterPtrVector);
53+ // cluster which regions
54+ const bool doBarrel_;
55+ const bool doEndcap_;
56+
57+ reco::BasicClusterCollection clusterizeECALPart (const EcalRecHitCollection& hits,
58+ const edm::EventSetup& es,
59+ const reco::CaloID::Detectors detector);
60+
61+ reco::BasicClusterCollection makeClusters (const EcalRecHitCollection& hits,
62+ const CaloSubdetectorGeometry* geom,
63+ const CaloSubdetectorGeometry* preshower,
64+ const CaloSubdetectorTopology* topology,
65+ const reco::CaloID::Detectors detector);
7066};
7167
7268#include " FWCore/Framework/interface/MakerMacros.h"
7369DEFINE_FWK_MODULE (Multi5x5ClusterProducer);
7470
75- Multi5x5ClusterProducer::Multi5x5ClusterProducer (const edm::ParameterSet& ps) {
76- // Parameters to identify the hit collections
77- barrelHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter <edm::InputTag>(" barrelHitTag" ));
78-
79- endcapHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter <edm::InputTag>(" endcapHitTag" ));
80-
81- // EventSetup Token for CaloGeometry
82- caloGeometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
83-
84- // should cluster algo be run in barrel and endcap?
85- doEndcap_ = ps.getParameter <bool >(" doEndcap" );
86- doBarrel_ = ps.getParameter <bool >(" doBarrel" );
87-
88- // The names of the produced cluster collections
89- barrelClusterCollection_ = ps.getParameter <std::string>(" barrelClusterCollection" );
90- endcapClusterCollection_ = ps.getParameter <std::string>(" endcapClusterCollection" );
91-
92- // Island algorithm parameters
93- double barrelSeedThreshold = ps.getParameter <double >(" IslandBarrelSeedThr" );
94- double endcapSeedThreshold = ps.getParameter <double >(" IslandEndcapSeedThr" );
95-
96- const std::vector<std::string> flagnames = ps.getParameter <std::vector<std::string> >(" RecHitFlagToBeExcluded" );
97-
98- const std::vector<int > v_chstatus = StringToEnumValue<EcalRecHit::Flags>(flagnames);
99-
100- // Parameters for the position calculation:
101- edm::ParameterSet posCalcParameters = ps.getParameter <edm::ParameterSet>(" posCalcParameters" );
102- posCalculator_ = PositionCalc (posCalcParameters);
103-
104- // Produces a collection of barrel and a collection of endcap clusters
105- produces<reco::BasicClusterCollection>(endcapClusterCollection_);
106- produces<reco::BasicClusterCollection>(barrelClusterCollection_);
107-
108- bool reassignSeedCrysToClusterItSeeds = false ;
109- if (ps.exists (" reassignSeedCrysToClusterItSeeds" ))
110- reassignSeedCrysToClusterItSeeds = ps.getParameter <bool >(" reassignSeedCrysToClusterItSeeds" );
111-
112- island_p = new Multi5x5ClusterAlgo (
113- barrelSeedThreshold, endcapSeedThreshold, v_chstatus, posCalculator_, reassignSeedCrysToClusterItSeeds);
114-
115- nEvt_ = 0 ;
71+ Multi5x5ClusterProducer::Multi5x5ClusterProducer (const edm::ParameterSet& ps)
72+ : barrelHitToken_{consumes<EcalRecHitCollection>(ps.getParameter <edm::InputTag>(" barrelHitTag" ))},
73+ endcapHitToken_{consumes<EcalRecHitCollection>(ps.getParameter <edm::InputTag>(" endcapHitTag" ))},
74+ caloGeometryToken_{esConsumes<CaloGeometry, CaloGeometryRecord>()},
75+ barrelToken_{produces<reco::BasicClusterCollection>(ps.getParameter <std::string>(" barrelClusterCollection" ))},
76+ endcapToken_{produces<reco::BasicClusterCollection>(ps.getParameter <std::string>(" endcapClusterCollection" ))},
77+ island_{ps.getParameter <double >(" IslandBarrelSeedThr" ),
78+ ps.getParameter <double >(" IslandEndcapSeedThr" ),
79+ StringToEnumValue<EcalRecHit::Flags>(ps.getParameter <std::vector<std::string>>(" RecHitFlagToBeExcluded" )),
80+ PositionCalc (ps.getParameter <edm::ParameterSet>(" posCalcParameters" )),
81+ ps.getParameter <bool >(" reassignSeedCrysToClusterItSeeds" )},
82+ doBarrel_{ps.getParameter <bool >(" doBarrel" )},
83+ doEndcap_{ps.getParameter <bool >(" doEndcap" )} {}
84+
85+ void Multi5x5ClusterProducer::fillDescriptions (edm::ConfigurationDescriptions& iDesc) {
86+ edm::ParameterSetDescription ps;
87+ ps.add <edm::InputTag>(" barrelHitTag" );
88+ ps.add <edm::InputTag>(" endcapHitTag" );
89+ ps.add <bool >(" doEndcap" );
90+ ps.add <bool >(" doBarrel" );
91+ ps.add <std::string>(" barrelClusterCollection" );
92+ ps.add <std::string>(" endcapClusterCollection" );
93+ ps.add <double >(" IslandBarrelSeedThr" );
94+ ps.add <double >(" IslandEndcapSeedThr" );
95+ ps.add <std::vector<std::string>>(" RecHitFlagToBeExcluded" );
96+
97+ edm::ParameterSetDescription posCal;
98+ posCal.add <bool >(" LogWeighted" );
99+ posCal.add <double >(" T0_barl" );
100+ posCal.add <double >(" T0_endc" );
101+ posCal.add <double >(" T0_endcPresh" );
102+ posCal.add <double >(" W0" );
103+ posCal.add <double >(" X0" );
104+ ps.add <edm::ParameterSetDescription>(" posCalcParameters" , posCal);
105+
106+ ps.add <bool >(" reassignSeedCrysToClusterItSeeds" , false );
107+ iDesc.addDefault (ps);
116108}
117109
118- Multi5x5ClusterProducer::~Multi5x5ClusterProducer () { delete island_p; }
119-
120110void Multi5x5ClusterProducer::produce (edm::Event& evt, const edm::EventSetup& es) {
121111 if (doEndcap_) {
122- clusterizeECALPart (evt, es, endcapHitToken_, endcapClusterCollection_, reco::CaloID::DET_ECAL_ENDCAP);
112+ // get the hit collection from the event:
113+ const EcalRecHitCollection& hitCollection = evt.get (endcapHitToken_);
114+ evt.emplace (endcapToken_, clusterizeECALPart (hitCollection, es, reco::CaloID::DET_ECAL_ENDCAP));
123115 }
124116 if (doBarrel_) {
125- clusterizeECALPart (evt, es, barrelHitToken_, barrelClusterCollection_, reco::CaloID::DET_ECAL_BARREL);
117+ // get the hit collection from the event:
118+ const EcalRecHitCollection& hitCollection = evt.get (barrelHitToken_);
119+ evt.emplace (barrelToken_, clusterizeECALPart (hitCollection, es, reco::CaloID::DET_ECAL_BARREL));
126120 }
127-
128- nEvt_++;
129121}
130122
131- const EcalRecHitCollection* Multi5x5ClusterProducer::getCollection (
132- edm::Event& evt, const edm::EDGetTokenT<EcalRecHitCollection>& token) {
133- edm::Handle<EcalRecHitCollection> rhcHandle;
134- evt.getByToken (token, rhcHandle);
135- return rhcHandle.product ();
123+ reco::BasicClusterCollection Multi5x5ClusterProducer::makeClusters (const EcalRecHitCollection& hits,
124+ const CaloSubdetectorGeometry* geom,
125+ const CaloSubdetectorGeometry* preshower,
126+ const CaloSubdetectorTopology* topology,
127+ const reco::CaloID::Detectors detector) {
128+ // Run the clusterization algorithm:
129+ return island_.makeClusters (&hits, geom, topology, preshower, detector);
136130}
137131
138- void Multi5x5ClusterProducer::clusterizeECALPart (edm::Event& evt,
139- const edm::EventSetup& es,
140- const edm::EDGetTokenT<EcalRecHitCollection>& token,
141- const std::string& clusterCollection,
142- const reco::CaloID::Detectors detector) {
143- // get the hit collection from the event:
144- const EcalRecHitCollection* hitCollection_p = getCollection (evt, token);
145-
132+ reco::BasicClusterCollection Multi5x5ClusterProducer::clusterizeECALPart (const EcalRecHitCollection& hitCollection,
133+ const edm::EventSetup& es,
134+ const reco::CaloID::Detectors detector) {
146135 // get the geometry and topology from the event setup:
147- edm::ESHandle<CaloGeometry> geoHandle = es.getHandle (caloGeometryToken_);
148-
149- const CaloSubdetectorGeometry* geometry_p;
150- std::unique_ptr<CaloSubdetectorTopology> topology_p;
136+ CaloGeometry const & geo = es.getData (caloGeometryToken_);
151137
138+ const CaloSubdetectorGeometry* preshower_p = geo.getSubdetectorGeometry (DetId::Ecal, EcalPreshower);
152139 if (detector == reco::CaloID::DET_ECAL_BARREL) {
153- geometry_p = geoHandle->getSubdetectorGeometry (DetId::Ecal, EcalBarrel);
154- topology_p = std::make_unique<EcalBarrelTopology>(*geoHandle);
140+ auto geometry_p = geo.getSubdetectorGeometry (DetId::Ecal, EcalBarrel);
141+ EcalBarrelTopology topology{geo};
142+ return makeClusters (hitCollection, geometry_p, preshower_p, &topology, detector);
155143 } else {
156- geometry_p = geoHandle->getSubdetectorGeometry (DetId::Ecal, EcalEndcap);
157- topology_p = std::make_unique<EcalEndcapTopology>(*geoHandle);
144+ auto geometry_p = geo.getSubdetectorGeometry (DetId::Ecal, EcalEndcap);
145+ EcalEndcapTopology topology{geo};
146+ return makeClusters (hitCollection, geometry_p, preshower_p, &topology, detector);
158147 }
159-
160- const CaloSubdetectorGeometry* geometryES_p;
161- geometryES_p = geoHandle->getSubdetectorGeometry (DetId::Ecal, EcalPreshower);
162-
163- // Run the clusterization algorithm:
164- reco::BasicClusterCollection clusters;
165- clusters = island_p->makeClusters (hitCollection_p, geometry_p, topology_p.get (), geometryES_p, detector);
166-
167- // create a unique_ptr to a BasicClusterCollection, copy the barrel clusters into it and put in the Event:
168- auto clusters_p = std::make_unique<reco::BasicClusterCollection>();
169- clusters_p->assign (clusters.begin (), clusters.end ());
170- edm::OrphanHandle<reco::BasicClusterCollection> bccHandle;
171- if (detector == reco::CaloID::DET_ECAL_BARREL)
172- bccHandle = evt.put (std::move (clusters_p), barrelClusterCollection_);
173- else
174- bccHandle = evt.put (std::move (clusters_p), endcapClusterCollection_);
175148}
0 commit comments