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  const CaloSubdetectorGeometry *& geometry_p = geometry;
100 
101  // create unique_ptr to a PreshowerClusterCollection
102  auto clusters_p1 = std::make_unique<reco::PreshowerClusterCollection>();
103  auto clusters_p2 = std::make_unique<reco::PreshowerClusterCollection>();
104  // create new collection of corrected super clusters
105  auto superclusters_p = std::make_unique<reco::SuperClusterCollection>();
106 
107  CaloSubdetectorTopology * topology_p=0;
108  if (geometry)
109  topology_p = new EcalPreshowerTopology(geoHandle);
110 
111  // fetch the product (pSuperClusters)
112  evt.getByToken(endcapSClusterToken_, pSuperClusters);
113  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
114 
115  // fetch the product (RecHits)
116  evt.getByToken( preshHitsToken_, pRecHits);
117  // pointer to the object in the product
118  const EcalRecHitCollection* rechits = pRecHits.product(); // EcalRecHitCollection hit_collection = *rhcHandle;
119 
120  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### Total # of preshower RecHits: "<< rechits->size();
121 
122  // make the map of rechits:
123  std::map<DetId, EcalRecHit> rechits_map;
125  for (it = rechits->begin(); it != rechits->end(); it++) {
126  // remove bad ES rechits
127  if (it->recoFlag()==1 || it->recoFlag()==14 || (it->recoFlag()<=10 && it->recoFlag()>=5)) continue;
128  //Make the map of DetID, EcalRecHit pairs
129  rechits_map.insert(std::make_pair(it->id(), *it));
130  }
131  // The set of used DetID's for a given event:
132  std::set<DetId> used_strips;
133  used_strips.clear();
134  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### rechits_map of size " << rechits_map.size() <<" was created!";
135 
136 
137  reco::PreshowerClusterCollection clusters1, clusters2; // output collection of corrected PCs
138  reco::SuperClusterCollection new_SC; // output collection of corrected SCs
139 
140  //make cycle over super clusters
141  reco::SuperClusterCollection::const_iterator it_super;
142  int isc = 0;
143  for (it_super=SClusts->begin(); it_super!=SClusts->end(); ++it_super) {
144 
145  float e1 = 0;
146  float e2 = 0;
147  float deltaE = 0;
148 
150  ++isc;
151  LogTrace("EcalClusters")<< " superE = " << it_super->energy() << " superETA = " << it_super->eta() << " superPHI = " << it_super->phi() ;
152 
153  int nBC = 0;
154  int condP1 = 1; // 0: dead channel; 1: active channel
155  int condP2 = 1;
156  reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
157  for ( ; bc_iter !=it_super->clustersEnd(); ++bc_iter ) {
158  if (geometry) {
159 
160  // Get strip position at intersection point of the line EE - Vertex:
161  double X = (*bc_iter)->x();
162  double Y = (*bc_iter)->y();
163  double Z = (*bc_iter)->z();
164  const GlobalPoint point(X,Y,Z);
165 
166  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
167  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
168  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
169  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
170 
171  if (nBC == 0) {
172  if (strip1 != ESDetId(0) && strip2 != ESDetId(0)) {
173  ESChannelStatusMap::const_iterator status_p1 = channelStatus->getMap().find(strip1);
174  ESChannelStatusMap::const_iterator status_p2 = channelStatus->getMap().find(strip2);
175  if (status_p1->getStatusCode() == 1) condP1 = 0;
176  if (status_p2->getStatusCode() == 1) condP2 = 0;
177  } else if (strip1 == ESDetId(0))
178  condP1 = 0;
179  else if (strip2 == ESDetId(0))
180  condP2 = 0;
181  }
182 
183  // Get a vector of ES clusters (found by the PreshSeeded algorithm) associated with a given EE basic cluster.
184  for (int i=0; i<preshNclust_; i++) {
185  reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&rechits_map,geometry_p,topology_p);
186  cl1.setBCRef(*bc_iter);
187  if (cl1.energy() > preshClustECut) {
188  clusters1.push_back(cl1);
189  e1 += cl1.energy();
190  }
191  reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&rechits_map,geometry_p,topology_p);
192  cl2.setBCRef(*bc_iter);
193 
194  if ( cl2.energy() > preshClustECut) {
195  clusters2.push_back(cl2);
196  e2 += cl2.energy();
197  }
198  } // end of cycle over ES clusters
199  }
200 
201  new_BC.push_back(*bc_iter);
202  nBC++;
203  } // end of cycle over BCs
204 
205  LogTrace("EcalClusters") << " For SC #" << isc-1 << ", containing "
206  << it_super->clustersSize()
207  << " basic clusters, PreshowerClusterAlgo made "
208  << clusters1.size() << " in X plane and "
209  << clusters2.size()
210  << " in Y plane " << " preshower clusters " ;
211 
212  // update energy of the SuperCluster
213  if(e1+e2 > 1.0e-10) {
214 
215  e1 = e1 / mip_; // GeV to #MIPs
216  e2 = e2 / mip_;
217 
218  if (condP1 == 1 && condP2 == 1) {
219  deltaE = gamma0_*(e1 + alpha0_*e2);
220  } else if (condP1 == 1 && condP2 == 0) {
221  deltaE = gamma1_*(e1 + alpha1_*e2);
222  } else if (condP1 == 0 && condP2 == 1) {
223  deltaE = gamma2_*(e1 + alpha2_*e2);
224  } else if (condP1 == 0 && condP2 == 0) {
225  deltaE = gamma3_*(e1 + alpha3_*e2);
226  }
227  }
228 
229  //corrected Energy
230  float E = it_super->energy() + deltaE;
231 
232  LogTrace("EcalClusters") << " Creating corrected SC ";
233 
234  reco::SuperCluster sc(E, it_super->position(), it_super->seed(), new_BC, deltaE);
235  if (condP1 == 1 && condP2 == 1) sc.setPreshowerPlanesStatus(0);
236  else if (condP1 == 1 && condP2 == 0) sc.setPreshowerPlanesStatus(1);
237  else if (condP1 == 0 && condP2 == 1) sc.setPreshowerPlanesStatus(2);
238  else if (condP1 == 0 && condP2 == 0) sc.setPreshowerPlanesStatus(3);
239 
240  if (sc.energy()*sin(sc.position().theta())>etThresh_)
241  new_SC.push_back(sc);
242  LogTrace("EcalClusters") << " SuperClusters energies: new E = " << sc.energy() << " vs. old E =" << it_super->energy();
243 
244  } // end of cycle over SCs
245 
246  // copy the preshower clusters into collections and put in the Event:
247  clusters_p1->assign(clusters1.begin(), clusters1.end());
248  clusters_p2->assign(clusters2.begin(), clusters2.end());
249  // put collection of preshower clusters to the event
250  evt.put(std::move(clusters_p1), preshClusterCollectionX_);
251  evt.put(std::move(clusters_p2), preshClusterCollectionY_);
252  LogTrace("EcalClusters") << "Preshower clusters added to the event" ;
253 
254  // put collection of corrected super clusters to the event
255  superclusters_p->assign(new_SC.begin(), new_SC.end());
256  evt.put(std::move(superclusters_p), assocSClusterCollection_);
257  LogTrace("EcalClusters") << "Corrected SClusters added to the event" ;
258 
259  if (topology_p)
260  delete topology_p;
261 
262  nEvt_++;
263 
264 }
265 
267 
268  es.get<ESGainRcd>().get(esgain_);
269  const ESGain *gain = esgain_.product();
270 
271  double ESGain = gain->getESGain();
272 
273  es.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
274  const ESMIPToGeVConstant *mipToGeV = esMIPToGeV_.product();
275 
276  mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
277 
278  es.get<ESChannelStatusRcd>().get(esChannelStatus_);
279 
280  es.get<ESEEIntercalibConstantsRcd>().get(esEEInterCalib_);
281  const ESEEIntercalibConstants *esEEInterCalib = esEEInterCalib_.product();
282 
283  // both planes work
284  gamma0_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh0();
285  alpha0_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
286 
287  // only first plane works
288  gamma1_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow1()) : esEEInterCalib->getGammaHigh1();
289  alpha1_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow1() : esEEInterCalib->getAlphaHigh1();
290 
291  // only second plane works
292  gamma2_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow2()) : esEEInterCalib->getGammaHigh2();
293  alpha2_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow2() : esEEInterCalib->getAlphaHigh2();
294 
295  // both planes do not work
296  gamma3_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh3();
297  alpha3_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow3() : esEEInterCalib->getAlphaHigh3();
298 
299  es.get<ESMissingEnergyCalibrationRcd>().get(esMissingECalib_);
300  const ESMissingEnergyCalibration * esMissingECalib = esMissingECalib_.product();
301 
302  // |eta| < 1.9
303  aEta_[0] = esMissingECalib->getConstAEta0();
304  bEta_[0] = esMissingECalib->getConstBEta0();
305 
306  // 1.9 < |eta| < 2.1
307  aEta_[1] = esMissingECalib->getConstAEta1();
308  bEta_[1] = esMissingECalib->getConstBEta1();
309 
310  // 2.1 < |eta| < 2.3
311  aEta_[2] = esMissingECalib->getConstAEta2();
312  bEta_[2] = esMissingECalib->getConstBEta2();
313 
314  // 2.3 < |eta| < 2.5
315  aEta_[3] = esMissingECalib->getConstAEta3();
316  bEta_[3] = esMissingECalib->getConstBEta3();
317 
318 }
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
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
Definition: ESGain.h:7
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:141
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:124
#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
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
Float e1
Definition: deltaR.h:20
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
float getESGain() const
Definition: ESGain.h:13
const T & get() const
Definition: EventSetup.h:56
PreshowerClusterProducer(const edm::ParameterSet &ps)
void set(const edm::EventSetup &es)
std::vector< Item >::const_iterator const_iterator
Float e2
Definition: deltaR.h:21
ESHandle< TrackerGeometry > geometry
HLT enums.
size_type size() const
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