CMS 3D CMS Logo

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