CMS 3D CMS Logo

PreshowerClusterProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <vector>
3 #include <memory>
4 
5 // user include files
8 
16 
17 // Reconstruction Classes
41 #include <fstream>
42 
44 
45 using namespace edm;
46 using namespace std;
47 
49 
50  // use configuration file to setup input/output collection names
51  preshHitsToken_ =
52  consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("preshRecHitProducer"));
53 
54  // Name of a SuperClusterCollection to make associations:
55  endcapSClusterToken_ =
56  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSClusterProducer"));
57 
58  // Output collections:
59  preshClusterCollectionX_ = ps.getParameter<std::string>("preshClusterCollectionX");
60  preshClusterCollectionY_ = ps.getParameter<std::string>("preshClusterCollectionY");
61  preshNclust_ = ps.getParameter<int>("preshNclust");
62 
63  etThresh_ = ps.getParameter<double>("etThresh");
64 
65  assocSClusterCollection_ = ps.getParameter<std::string>("assocSClusterCollection");
66 
67  produces< reco::PreshowerClusterCollection >(preshClusterCollectionX_);
68  produces< reco::PreshowerClusterCollection >(preshClusterCollectionY_);
69  produces< reco::SuperClusterCollection >(assocSClusterCollection_);
70 
71  float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
72  int preshSeededNst = ps.getParameter<int>("preshSeededNstrip");
73  preshClustECut = ps.getParameter<double>("preshClusterEnergyCut");
74 
75  presh_algo = new PreshowerClusterAlgo(preshStripECut,preshClustECut,preshSeededNst);
76 
77  nEvt_ = 0;
78 }
79 
80 
82  delete presh_algo;
83 }
84 
86 
89 
90  // get the ECAL geometry:
92  es.get<CaloGeometryRecord>().get(geoHandle);
93 
94  // retrieve ES-EE intercalibration constants and channel status
95  set(es);
96  const ESChannelStatus *channelStatus = esChannelStatus_.product();
97 
99 
100  // create unique_ptr to a PreshowerClusterCollection
101  auto clusters_p1 = std::make_unique<reco::PreshowerClusterCollection>();
102  auto clusters_p2 = std::make_unique<reco::PreshowerClusterCollection>();
103  // create new collection of corrected super clusters
104  auto superclusters_p = std::make_unique<reco::SuperClusterCollection>();
105 
106  CaloSubdetectorTopology * topology_p=nullptr;
107  if (geometry_p)
108  topology_p = new EcalPreshowerTopology(geoHandle);
109 
110  // fetch the product (pSuperClusters)
111  evt.getByToken(endcapSClusterToken_, pSuperClusters);
112  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
113 
114  // fetch the product (RecHits)
115  evt.getByToken( preshHitsToken_, pRecHits);
116  // pointer to the object in the product
117  const EcalRecHitCollection* rechits = pRecHits.product(); // EcalRecHitCollection hit_collection = *rhcHandle;
118 
119  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### Total # of preshower RecHits: "<< rechits->size();
120 
121  // make the map of rechits:
122  std::map<DetId, EcalRecHit> rechits_map;
124  for (it = rechits->begin(); it != rechits->end(); it++) {
125  // remove bad ES rechits
126  if (it->recoFlag()==1 || it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
127  //Make the map of DetID, EcalRecHit pairs
128  rechits_map.insert(std::make_pair(it->id(), *it));
129  }
130  // The set of used DetID's for a given event:
131  std::set<DetId> used_strips;
132  used_strips.clear();
133  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### rechits_map of size " << rechits_map.size() <<" was created!";
134 
135 
136  reco::PreshowerClusterCollection clusters1, clusters2; // output collection of corrected PCs
137  reco::SuperClusterCollection new_SC; // output collection of corrected SCs
138 
139  //make cycle over super clusters
140  reco::SuperClusterCollection::const_iterator it_super;
141  int isc = 0;
142  for (it_super=SClusts->begin(); it_super!=SClusts->end(); ++it_super) {
143 
144  float e1 = 0;
145  float e2 = 0;
146  float deltaE = 0;
147 
149  ++isc;
150  LogTrace("EcalClusters")<< " superE = " << it_super->energy() << " superETA = " << it_super->eta() << " superPHI = " << it_super->phi() ;
151 
152  int nBC = 0;
153  int condP1 = 1; // 0: dead channel; 1: active channel
154  int condP2 = 1;
155  reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
156  for ( ; bc_iter !=it_super->clustersEnd(); ++bc_iter ) {
157  if (geometry_p) {
158 
159  // Get strip position at intersection point of the line EE - Vertex:
160  double X = (*bc_iter)->x();
161  double Y = (*bc_iter)->y();
162  double Z = (*bc_iter)->z();
163  const GlobalPoint point(X,Y,Z);
164 
165  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
166  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
167  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
168  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
169 
170  if (nBC == 0) {
171  if (strip1 != ESDetId(0) && strip2 != ESDetId(0)) {
172  ESChannelStatusMap::const_iterator status_p1 = channelStatus->getMap().find(strip1);
173  ESChannelStatusMap::const_iterator status_p2 = channelStatus->getMap().find(strip2);
174  if (status_p1->getStatusCode() == 1) condP1 = 0;
175  if (status_p2->getStatusCode() == 1) condP2 = 0;
176  } else if (strip1 == ESDetId(0))
177  condP1 = 0;
178  else if (strip2 == ESDetId(0))
179  condP2 = 0;
180  }
181 
182  // Get a vector of ES clusters (found by the PreshSeeded algorithm) associated with a given EE basic cluster.
183  for (int i=0; i<preshNclust_; i++) {
184  reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&rechits_map,geometry_p,topology_p);
185  cl1.setBCRef(*bc_iter);
186  if (cl1.energy() > preshClustECut) {
187  clusters1.push_back(cl1);
188  e1 += cl1.energy();
189  }
190  reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&rechits_map,geometry_p,topology_p);
191  cl2.setBCRef(*bc_iter);
192 
193  if ( cl2.energy() > preshClustECut) {
194  clusters2.push_back(cl2);
195  e2 += cl2.energy();
196  }
197  } // end of cycle over ES clusters
198  }
199 
200  new_BC.push_back(*bc_iter);
201  nBC++;
202  } // end of cycle over BCs
203 
204  LogTrace("EcalClusters") << " For SC #" << isc-1 << ", containing "
205  << it_super->clustersSize()
206  << " basic clusters, PreshowerClusterAlgo made "
207  << clusters1.size() << " in X plane and "
208  << clusters2.size()
209  << " in Y plane " << " preshower clusters " ;
210 
211  // update energy of the SuperCluster
212  if(e1+e2 > 1.0e-10) {
213 
214  e1 = e1 / mip_; // GeV to #MIPs
215  e2 = e2 / mip_;
216 
217  if (condP1 == 1 && condP2 == 1) {
218  deltaE = gamma0_*(e1 + alpha0_*e2);
219  } else if (condP1 == 1 && condP2 == 0) {
220  deltaE = gamma1_*(e1 + alpha1_*e2);
221  } else if (condP1 == 0 && condP2 == 1) {
222  deltaE = gamma2_*(e1 + alpha2_*e2);
223  } else if (condP1 == 0 && condP2 == 0) {
224  deltaE = gamma3_*(e1 + alpha3_*e2);
225  }
226  }
227 
228  //corrected Energy
229  float E = it_super->energy() + deltaE;
230 
231  LogTrace("EcalClusters") << " Creating corrected SC ";
232 
233  reco::SuperCluster sc(E, it_super->position(), it_super->seed(), new_BC, deltaE);
234  if (condP1 == 1 && condP2 == 1) sc.setPreshowerPlanesStatus(0);
235  else if (condP1 == 1 && condP2 == 0) sc.setPreshowerPlanesStatus(1);
236  else if (condP1 == 0 && condP2 == 1) sc.setPreshowerPlanesStatus(2);
237  else if (condP1 == 0 && condP2 == 0) sc.setPreshowerPlanesStatus(3);
238 
239  if (sc.energy()*sin(sc.position().theta())>etThresh_)
240  new_SC.push_back(sc);
241  LogTrace("EcalClusters") << " SuperClusters energies: new E = " << sc.energy() << " vs. old E =" << it_super->energy();
242 
243  } // end of cycle over SCs
244 
245  // copy the preshower clusters into collections and put in the Event:
246  clusters_p1->assign(clusters1.begin(), clusters1.end());
247  clusters_p2->assign(clusters2.begin(), clusters2.end());
248  // put collection of preshower clusters to the event
249  evt.put(std::move(clusters_p1), preshClusterCollectionX_);
250  evt.put(std::move(clusters_p2), preshClusterCollectionY_);
251  LogTrace("EcalClusters") << "Preshower clusters added to the event" ;
252 
253  // put collection of corrected super clusters to the event
254  superclusters_p->assign(new_SC.begin(), new_SC.end());
255  evt.put(std::move(superclusters_p), assocSClusterCollection_);
256  LogTrace("EcalClusters") << "Corrected SClusters added to the event" ;
257 
258  if (topology_p)
259  delete topology_p;
260 
261  nEvt_++;
262 
263 }
264 
266 
267  es.get<ESGainRcd>().get(esgain_);
268  const ESGain *gain = esgain_.product();
269 
270  double ESGain = gain->getESGain();
271 
272  es.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
273  const ESMIPToGeVConstant *mipToGeV = esMIPToGeV_.product();
274 
275  mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
276 
277  es.get<ESChannelStatusRcd>().get(esChannelStatus_);
278 
279  es.get<ESEEIntercalibConstantsRcd>().get(esEEInterCalib_);
280  const ESEEIntercalibConstants *esEEInterCalib = esEEInterCalib_.product();
281 
282  // both planes work
283  gamma0_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh0();
284  alpha0_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
285 
286  // only first plane works
287  gamma1_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow1()) : esEEInterCalib->getGammaHigh1();
288  alpha1_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow1() : esEEInterCalib->getAlphaHigh1();
289 
290  // only second plane works
291  gamma2_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow2()) : esEEInterCalib->getGammaHigh2();
292  alpha2_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow2() : esEEInterCalib->getAlphaHigh2();
293 
294  // both planes do not work
295  gamma3_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh3();
296  alpha3_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow3() : esEEInterCalib->getAlphaHigh3();
297 
298  es.get<ESMissingEnergyCalibrationRcd>().get(esMissingECalib_);
299  const ESMissingEnergyCalibration * esMissingECalib = esMissingECalib_.product();
300 
301  // |eta| < 1.9
302  aEta_[0] = esMissingECalib->getConstAEta0();
303  bEta_[0] = esMissingECalib->getConstBEta0();
304 
305  // 1.9 < |eta| < 2.1
306  aEta_[1] = esMissingECalib->getConstAEta1();
307  bEta_[1] = esMissingECalib->getConstBEta1();
308 
309  // 2.1 < |eta| < 2.3
310  aEta_[2] = esMissingECalib->getConstAEta2();
311  bEta_[2] = esMissingECalib->getConstBEta2();
312 
313  // 2.3 < |eta| < 2.5
314  aEta_[3] = esMissingECalib->getConstAEta3();
315  bEta_[3] = esMissingECalib->getConstBEta3();
316 
317 }
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:49
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
Definition: ESGain.h:7
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
const self & getMap() const
float getESValueLow() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< EcalRecHit >::const_iterator const_iterator
#define X(str)
Definition: MuonsGrabber.cc:48
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
void setBCRef(const CaloClusterPtr &r)
DetIds of component RecHits – now inherited from CaloCluster.
const_iterator find(uint32_t rawId) const
float energy() const
Energy. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:111
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
double energy() const
cluster energy
Definition: CaloCluster.h:126
#define LogTrace(id)
float theta() const
Momentum polar angle. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:166
const_iterator end() const
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
float getESGain() const
Definition: ESGain.h:13
PreshowerClusterProducer(const edm::ParameterSet &ps)
void set(const edm::EventSetup &es)
std::vector< Item >::const_iterator const_iterator
HLT enums.
size_type size() const
T get() const
Definition: EventSetup.h:63
void produce(edm::Event &evt, const edm::EventSetup &es) override
float getESValueHigh() const
def move(src, dest)
Definition: eostools.py:510
*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