CMS 3D CMS Logo

PreshowerClusterProducer.cc
Go to the documentation of this file.
41 
42 #include <fstream>
43 #include <memory>
44 #include <vector>
45 
47 public:
49 
50  explicit PreshowerClusterProducer(const edm::ParameterSet& ps);
51 
52  ~PreshowerClusterProducer() override;
53 
54  void produce(edm::Event& evt, const edm::EventSetup& es) override;
55  void set(const edm::EventSetup& es);
56 
57 private:
58  int nEvt_; // internal counter of events
59 
60  //clustering parameters:
61  edm::EDGetTokenT<EcalRecHitCollection> preshHitsToken_; // name of module/plugin/producer producing hits
63 
64  // name out output collections
67 
70  double etThresh_;
71 
72  // association parameters:
73  std::string assocSClusterCollection_; // name of super cluster output collection
74 
86 
87  double mip_;
88  double gamma0_;
89  double gamma1_;
90  double gamma2_;
91  double gamma3_;
92  double alpha0_;
93  double alpha1_;
94  double alpha2_;
95  double alpha3_;
96  double aEta_[4];
97  double bEta_[4];
98 
99  PreshowerClusterAlgo* presh_algo; // algorithm doing the real work
100  // The set of used DetID's
101  //std::set<DetId> used_strips;
102 };
103 
106 
107 using namespace edm;
108 using namespace std;
109 
111  // use configuration file to setup input/output collection names
112  preshHitsToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("preshRecHitProducer"));
113 
114  // Name of a SuperClusterCollection to make associations:
115  endcapSClusterToken_ =
116  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSClusterProducer"));
117 
118  esGainToken_ = esConsumes<ESGain, ESGainRcd>();
119  esMIPToGeVToken_ = esConsumes<ESMIPToGeVConstant, ESMIPToGeVConstantRcd>();
120  esEEInterCalibToken_ = esConsumes<ESEEIntercalibConstants, ESEEIntercalibConstantsRcd>();
121  esMissingECalibToken_ = esConsumes<ESMissingEnergyCalibration, ESMissingEnergyCalibrationRcd>();
122  esChannelStatusToken_ = esConsumes<ESChannelStatus, ESChannelStatusRcd>();
123  caloGeometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
124 
125  // Output collections:
126  preshClusterCollectionX_ = ps.getParameter<std::string>("preshClusterCollectionX");
127  preshClusterCollectionY_ = ps.getParameter<std::string>("preshClusterCollectionY");
128  preshNclust_ = ps.getParameter<int>("preshNclust");
129 
130  etThresh_ = ps.getParameter<double>("etThresh");
131 
132  assocSClusterCollection_ = ps.getParameter<std::string>("assocSClusterCollection");
133 
134  produces<reco::PreshowerClusterCollection>(preshClusterCollectionX_);
135  produces<reco::PreshowerClusterCollection>(preshClusterCollectionY_);
136  produces<reco::SuperClusterCollection>(assocSClusterCollection_);
137 
138  float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
139  int preshSeededNst = ps.getParameter<int>("preshSeededNstrip");
140  preshClustECut = ps.getParameter<double>("preshClusterEnergyCut");
141 
142  presh_algo = new PreshowerClusterAlgo(preshStripECut, preshClustECut, preshSeededNst);
143 
144  nEvt_ = 0;
145 }
146 
148 
152 
153  // get the ECAL geometry:
154  edm::ESHandle<CaloGeometry> geoHandle = es.getHandle(caloGeometryToken_);
155 
156  // retrieve ES-EE intercalibration constants and channel status
157  set(es);
158  const ESChannelStatus* channelStatus = esChannelStatus_.product();
159 
161 
162  // create unique_ptr to a PreshowerClusterCollection
163  auto clusters_p1 = std::make_unique<reco::PreshowerClusterCollection>();
164  auto clusters_p2 = std::make_unique<reco::PreshowerClusterCollection>();
165  // create new collection of corrected super clusters
166  auto superclusters_p = std::make_unique<reco::SuperClusterCollection>();
167 
168  std::unique_ptr<CaloSubdetectorTopology> topology_p;
169  if (geometry_p)
170  topology_p = std::make_unique<EcalPreshowerTopology>();
171 
172  // fetch the product (pSuperClusters)
173  evt.getByToken(endcapSClusterToken_, pSuperClusters);
174  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
175 
176  // fetch the product (RecHits)
177  evt.getByToken(preshHitsToken_, pRecHits);
178  // pointer to the object in the product
179  const EcalRecHitCollection* rechits = pRecHits.product(); // EcalRecHitCollection hit_collection = *rhcHandle;
180 
181  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### Total # of preshower RecHits: " << rechits->size();
182 
183  // make the map of rechits:
184  std::map<DetId, EcalRecHit> rechits_map;
186  for (it = rechits->begin(); it != rechits->end(); it++) {
187  // remove bad ES rechits
188  if (it->recoFlag() == 1 || it->recoFlag() == 14 || (it->recoFlag() <= 10 && it->recoFlag() >= 5))
189  continue;
190  //Make the map of DetID, EcalRecHit pairs
191  rechits_map.insert(std::make_pair(it->id(), *it));
192  }
193  // The set of used DetID's for a given event:
194  std::set<DetId> used_strips;
195  used_strips.clear();
196  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### rechits_map of size " << rechits_map.size()
197  << " was created!";
198 
199  reco::PreshowerClusterCollection clusters1, clusters2; // output collection of corrected PCs
200  reco::SuperClusterCollection new_SC; // output collection of corrected SCs
201 
202  //make cycle over super clusters
203  reco::SuperClusterCollection::const_iterator it_super;
204  int isc = 0;
205  for (it_super = SClusts->begin(); it_super != SClusts->end(); ++it_super) {
206  float e1 = 0;
207  float e2 = 0;
208  float deltaE = 0;
209 
211  ++isc;
212  LogTrace("EcalClusters") << " superE = " << it_super->energy() << " superETA = " << it_super->eta()
213  << " superPHI = " << it_super->phi();
214 
215  int nBC = 0;
216  int condP1 = 1; // 0: dead channel; 1: active channel
217  int condP2 = 1;
218  reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
219  for (; bc_iter != it_super->clustersEnd(); ++bc_iter) {
220  if (geometry_p) {
221  // Get strip position at intersection point of the line EE - Vertex:
222  double X = (*bc_iter)->x();
223  double Y = (*bc_iter)->y();
224  double Z = (*bc_iter)->z();
225  const GlobalPoint point(X, Y, Z);
226 
227  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
228  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
229  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
230  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
231 
232  if (nBC == 0) {
233  if (strip1 != ESDetId(0) && strip2 != ESDetId(0)) {
234  ESChannelStatusMap::const_iterator status_p1 = channelStatus->getMap().find(strip1);
235  ESChannelStatusMap::const_iterator status_p2 = channelStatus->getMap().find(strip2);
236  if (status_p1->getStatusCode() == 1)
237  condP1 = 0;
238  if (status_p2->getStatusCode() == 1)
239  condP2 = 0;
240  } else if (strip1 == ESDetId(0))
241  condP1 = 0;
242  else if (strip2 == ESDetId(0))
243  condP2 = 0;
244  }
245 
246  // Get a vector of ES clusters (found by the PreshSeeded algorithm) associated with a given EE basic cluster.
247  for (int i = 0; i < preshNclust_; i++) {
249  presh_algo->makeOneCluster(strip1, &used_strips, &rechits_map, geometry_p, topology_p.get());
250  cl1.setBCRef(*bc_iter);
251  if (cl1.energy() > preshClustECut) {
252  clusters1.push_back(cl1);
253  e1 += cl1.energy();
254  }
256  presh_algo->makeOneCluster(strip2, &used_strips, &rechits_map, geometry_p, topology_p.get());
257  cl2.setBCRef(*bc_iter);
258 
259  if (cl2.energy() > preshClustECut) {
260  clusters2.push_back(cl2);
261  e2 += cl2.energy();
262  }
263  } // end of cycle over ES clusters
264  }
265 
266  new_BC.push_back(*bc_iter);
267  nBC++;
268  } // end of cycle over BCs
269 
270  LogTrace("EcalClusters") << " For SC #" << isc - 1 << ", containing " << it_super->clustersSize()
271  << " basic clusters, PreshowerClusterAlgo made " << clusters1.size() << " in X plane and "
272  << clusters2.size() << " in Y plane "
273  << " preshower clusters ";
274 
275  // update energy of the SuperCluster
276  if (e1 + e2 > 1.0e-10) {
277  e1 = e1 / mip_; // GeV to #MIPs
278  e2 = e2 / mip_;
279 
280  if (condP1 == 1 && condP2 == 1) {
281  deltaE = gamma0_ * (e1 + alpha0_ * e2);
282  } else if (condP1 == 1 && condP2 == 0) {
283  deltaE = gamma1_ * (e1 + alpha1_ * e2);
284  } else if (condP1 == 0 && condP2 == 1) {
285  deltaE = gamma2_ * (e1 + alpha2_ * e2);
286  } else if (condP1 == 0 && condP2 == 0) {
287  deltaE = gamma3_ * (e1 + alpha3_ * e2);
288  }
289  }
290 
291  //corrected Energy
292  float E = it_super->energy() + deltaE;
293 
294  LogTrace("EcalClusters") << " Creating corrected SC ";
295 
296  reco::SuperCluster sc(E, it_super->position(), it_super->seed(), new_BC, deltaE);
297  if (condP1 == 1 && condP2 == 1)
299  else if (condP1 == 1 && condP2 == 0)
300  sc.setPreshowerPlanesStatus(1);
301  else if (condP1 == 0 && condP2 == 1)
302  sc.setPreshowerPlanesStatus(2);
303  else if (condP1 == 0 && condP2 == 0)
304  sc.setPreshowerPlanesStatus(3);
305 
306  if (sc.energy() * sin(sc.position().theta()) > etThresh_)
307  new_SC.push_back(sc);
308  LogTrace("EcalClusters") << " SuperClusters energies: new E = " << sc.energy()
309  << " vs. old E =" << it_super->energy();
310 
311  } // end of cycle over SCs
312 
313  // copy the preshower clusters into collections and put in the Event:
314  clusters_p1->assign(clusters1.begin(), clusters1.end());
315  clusters_p2->assign(clusters2.begin(), clusters2.end());
316  // put collection of preshower clusters to the event
317  evt.put(std::move(clusters_p1), preshClusterCollectionX_);
318  evt.put(std::move(clusters_p2), preshClusterCollectionY_);
319  LogTrace("EcalClusters") << "Preshower clusters added to the event";
320 
321  // put collection of corrected super clusters to the event
322  superclusters_p->assign(new_SC.begin(), new_SC.end());
323  evt.put(std::move(superclusters_p), assocSClusterCollection_);
324  LogTrace("EcalClusters") << "Corrected SClusters added to the event";
325 
326  nEvt_++;
327 }
328 
330  esgain_ = es.getHandle(esGainToken_);
331  const ESGain* gain = esgain_.product();
332 
333  double ESGain = gain->getESGain();
334 
335  esMIPToGeV_ = es.getHandle(esMIPToGeVToken_);
336  const ESMIPToGeVConstant* mipToGeV = esMIPToGeV_.product();
337 
338  mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
339 
340  esChannelStatus_ = es.getHandle(esChannelStatusToken_);
341 
342  esEEInterCalib_ = es.getHandle(esEEInterCalibToken_);
343  const ESEEIntercalibConstants* esEEInterCalib = esEEInterCalib_.product();
344 
345  // both planes work
346  gamma0_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh0();
347  alpha0_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
348 
349  // only first plane works
350  gamma1_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow1()) : esEEInterCalib->getGammaHigh1();
351  alpha1_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow1() : esEEInterCalib->getAlphaHigh1();
352 
353  // only second plane works
354  gamma2_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow2()) : esEEInterCalib->getGammaHigh2();
355  alpha2_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow2() : esEEInterCalib->getAlphaHigh2();
356 
357  // both planes do not work
358  gamma3_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh3();
359  alpha3_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow3() : esEEInterCalib->getAlphaHigh3();
360 
361  esMissingECalib_ = es.getHandle(esMissingECalibToken_);
362  const ESMissingEnergyCalibration* esMissingECalib = esMissingECalib_.product();
363 
364  // |eta| < 1.9
365  aEta_[0] = esMissingECalib->getConstAEta0();
366  bEta_[0] = esMissingECalib->getConstBEta0();
367 
368  // 1.9 < |eta| < 2.1
369  aEta_[1] = esMissingECalib->getConstAEta1();
370  bEta_[1] = esMissingECalib->getConstBEta1();
371 
372  // 2.1 < |eta| < 2.3
373  aEta_[2] = esMissingECalib->getConstAEta2();
374  bEta_[2] = esMissingECalib->getConstBEta2();
375 
376  // 2.3 < |eta| < 2.5
377  aEta_[3] = esMissingECalib->getConstAEta3();
378  bEta_[3] = esMissingECalib->getConstBEta3();
379 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
float getESValueHigh() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::ESGetToken< ESEEIntercalibConstants, ESEEIntercalibConstantsRcd > esEEInterCalibToken_
edm::ESHandle< ESMissingEnergyCalibration > esMissingECalib_
Definition: ESGain.h:7
size_type size() const
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:152
edm::ESHandle< ESGain > esgain_
edm::ESGetToken< ESMIPToGeVConstant, ESMIPToGeVConstantRcd > esMIPToGeVToken_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T const * product() const
Definition: Handle.h:70
std::vector< EcalRecHit >::const_iterator const_iterator
#define X(str)
Definition: MuonsGrabber.cc:38
PreshowerClusterAlgo * presh_algo
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
const_iterator find(uint32_t rawId) const
#define LogTrace(id)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
edm::ESHandle< ESChannelStatus > esChannelStatus_
void setBCRef(const CaloClusterPtr &r)
DetIds of component RecHits – now inherited from CaloCluster.
float getESValueLow() const
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
edm::ESGetToken< ESGain, ESGainRcd > esGainToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
edm::ESGetToken< ESChannelStatus, ESChannelStatusRcd > esChannelStatusToken_
edm::ESHandle< ESMIPToGeVConstant > esMIPToGeV_
const_iterator end() const
edm::ESHandle< ESEEIntercalibConstants > esEEInterCalib_
double energy() const
cluster energy
Definition: CaloCluster.h:148
void setPreshowerPlanesStatus(const uint32_t &status)
Definition: SuperCluster.h:138
Definition: DetId.h:17
edm::EDGetTokenT< EcalRecHitCollection > preshHitsToken_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
PreshowerClusterProducer(const edm::ParameterSet &ps)
void set(const edm::EventSetup &es)
std::vector< Item >::const_iterator const_iterator
edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
HLT enums.
edm::ESGetToken< ESMissingEnergyCalibration, ESMissingEnergyCalibrationRcd > esMissingECalibToken_
const self & getMap() const
void produce(edm::Event &evt, const edm::EventSetup &es) override
edm::EDGetTokenT< reco::SuperClusterCollection > endcapSClusterToken_
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
def move(src, dest)
Definition: eostools.py:511
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5