CMS 3D CMS Logo

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