CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HybridClusterProducer.cc
Go to the documentation of this file.
1 // C/C++ headers
2 #include <iostream>
3 #include <vector>
4 #include <memory>
5 
6 // Framework
13 
14 // Reconstruction Classes
20 
21 // Geometry
29 
32 
33 // Class header file
36 
37 
38 
40 {
41 
42 
43  basicclusterCollection_ = ps.getParameter<std::string>("basicclusterCollection");
44  superclusterCollection_ = ps.getParameter<std::string>("superclusterCollection");
45  hitsToken_ =
46  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("recHitsCollection"));
47 
48  //Setup for core tools objects.
50  ps.getParameter<edm::ParameterSet>("posCalcParameters");
51 
52  posCalculator_ = PositionCalc(posCalcParameters);
53 
54  const std::vector<std::string> flagnames =
55  ps.getParameter<std::vector<std::string> >("RecHitFlagToBeExcluded");
56 
57  const std::vector<int> flagsexcl=
58  StringToEnumValue<EcalRecHit::Flags>(flagnames);
59 
60  const std::vector<std::string> severitynames =
61  ps.getParameter<std::vector<std::string> >("RecHitSeverityToBeExcluded");
62 
63  const std::vector<int> severitiesexcl=
64  StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynames);
65 
66  hybrid_p = new HybridClusterAlgo(ps.getParameter<double>("HybridBarrelSeedThr"),
67  ps.getParameter<int>("step"),
68  ps.getParameter<double>("ethresh"),
69  ps.getParameter<double>("eseed"),
70  ps.getParameter<double>("xi"),
71  ps.getParameter<bool>("useEtForXi"),
72  ps.getParameter<double>("ewing"),
73  flagsexcl,
74  posCalculator_,
75  ps.getParameter<bool>("dynamicEThresh"),
76  ps.getParameter<double>("eThreshA"),
77  ps.getParameter<double>("eThreshB"),
78  severitiesexcl,
79  ps.getParameter<bool>("excludeFlagged")
80  );
81  //bremRecoveryPset,
82 
83  // get brem recovery parameters
84  bool dynamicPhiRoad = ps.getParameter<bool>("dynamicPhiRoad");
85  if (dynamicPhiRoad) {
86  edm::ParameterSet bremRecoveryPset = ps.getParameter<edm::ParameterSet>("bremRecoveryPset");
87  hybrid_p->setDynamicPhiRoad(bremRecoveryPset);
88  }
89 
90  produces< reco::BasicClusterCollection >(basicclusterCollection_);
92  nEvt_ = 0;
93 }
94 
95 
97 {
98  delete hybrid_p;
99 }
100 
101 
103 {
104  // get the hit collection from the event:
106 
107  evt.getByToken(hitsToken_, rhcHandle);
108  if (!(rhcHandle.isValid())){
109  edm::LogError("MissingProduct") << "could not get a handle on the EcalRecHitCollection!";
110  return;
111 
112  }
113  const EcalRecHitCollection *hit_collection = rhcHandle.product();
114 
115  // get the collection geometry:
116  edm::ESHandle<CaloGeometry> geoHandle;
117  es.get<CaloGeometryRecord>().get(geoHandle);
118  const CaloGeometry& geometry = *geoHandle;
119  const CaloSubdetectorGeometry *geometry_p;
120  std::unique_ptr<const CaloSubdetectorTopology> topology;
121 
123  es.get<EcalSeverityLevelAlgoRcd>().get(sevLv);
124 
125  geometry_p = geometry.getSubdetectorGeometry(DetId::Ecal, EcalBarrel);
126  topology = std::make_unique<EcalBarrelTopology>(geoHandle);
127 
128  // make the Basic clusters!
129  reco::BasicClusterCollection basicClusters;
130  hybrid_p->makeClusters(hit_collection, geometry_p, basicClusters, sevLv.product(),false,
131  std::vector<EcalEtaPhiRegion>());
132 
133  LogTrace("EcalClusters") << "Finished clustering - BasicClusterCollection returned to producer..." ;
134 
135  // create a unique_ptr to a BasicClusterCollection, copy the clusters into it and put in the Event:
136  auto basicclusters_p = std::make_unique<reco::BasicClusterCollection>();
137  basicclusters_p->assign(basicClusters.begin(), basicClusters.end());
139 
140  //Basic clusters now in the event.
141  LogTrace("EcalClusters") << "Basic Clusters now put into event." ;
142 
143 
144  //Weird though it is, get the BasicClusters back out of the event. We need the
145  //edm::Ref to these guys to make our superclusters for Hybrid.
146 
147  if (!(bccHandle.isValid())) {
148  edm::LogError("Missing Product") << "could not get a handle on the BasicClusterCollection!" ;
149  return;
150  }
151 
152  reco::BasicClusterCollection clusterCollection = *bccHandle;
153 
154  LogTrace("EcalClusters")<< "Got the BasicClusterCollection" << std::endl;
155 
156  reco::CaloClusterPtrVector clusterPtrVector;
157  for (unsigned int i = 0; i < clusterCollection.size(); i++){
158  clusterPtrVector.push_back(reco::CaloClusterPtr(bccHandle, i));
159  }
160 
161  reco::SuperClusterCollection superClusters = hybrid_p->makeSuperClusters(clusterPtrVector);
162  LogTrace("EcalClusters") << "Found: " << superClusters.size() << " superclusters." ;
163 
164  auto superclusters_p = std::make_unique<reco::SuperClusterCollection>();
165  superclusters_p->assign(superClusters.begin(), superClusters.end());
166 
167  evt.put(std::move(superclusters_p), superclusterCollection_);
168  LogTrace("EcalClusters") << "Hybrid Clusters (Basic/Super) added to the Event! :-)" ;
169 
170 
171  nEvt_++;
172 }
173 
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
int i
Definition: DBlmapReader.cc:9
HybridClusterProducer(const edm::ParameterSet &ps)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
virtual void produce(edm::Event &, const edm::EventSetup &)
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:141
edm::EDGetTokenT< EcalRecHitCollection > hitsToken_
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
reco::SuperClusterCollection makeSuperClusters(const reco::CaloClusterPtrVector &)
def move
Definition: eostools.py:510
tuple posCalcParameters
bool isValid() const
Definition: HandleBase.h:75
#define LogTrace(id)
produces< reco::SuperClusterCollection >("perfect")
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
std::vector< BasicCluster > BasicClusterCollection
collection of BasicCluster objects
ESHandle< TrackerGeometry > geometry
HybridClusterAlgo * hybrid_p
void makeClusters(const EcalRecHitCollection *, const CaloSubdetectorGeometry *geometry, reco::BasicClusterCollection &basicClusters, const EcalSeverityLevelAlgo *sevLv, bool regional=false, const std::vector< EcalEtaPhiRegion > &regions=std::vector< EcalEtaPhiRegion >())