CMS 3D CMS Logo

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