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  int ieta = 0; // eta bin
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  if (fabs(it_super->eta()) < 1.9) ieta = 0;
148  else if (fabs(it_super->eta()) >= 1.9 && fabs(it_super->eta()) < 2.1) ieta = 1;
149  else if (fabs(it_super->eta()) >= 2.1 && fabs(it_super->eta()) < 2.3) ieta = 2;
150  else if (fabs(it_super->eta()) >= 2.3) ieta = 3;
151 
153  ++isc;
154  LogTrace("EcalClusters")<< " superE = " << it_super->energy() << " superETA = " << it_super->eta() << " superPHI = " << it_super->phi() ;
155 
156  int nBC = 0;
157  int condP1 = 1; // 0: dead channel; 1: active channel
158  int condP2 = 1;
159  reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
160  for ( ; bc_iter !=it_super->clustersEnd(); ++bc_iter ) {
161  if (geometry) {
162 
163  // Get strip position at intersection point of the line EE - Vertex:
164  double X = (*bc_iter)->x();
165  double Y = (*bc_iter)->y();
166  double Z = (*bc_iter)->z();
167  const GlobalPoint point(X,Y,Z);
168 
169  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
170  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
171  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
172  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
173 
174  if (nBC == 0) {
175  if (strip1 != ESDetId(0) && strip2 != ESDetId(0)) {
176  ESChannelStatusMap::const_iterator status_p1 = channelStatus->getMap().find(strip1);
177  ESChannelStatusMap::const_iterator status_p2 = channelStatus->getMap().find(strip2);
178  if (status_p1->getStatusCode() == 1) condP1 = 0;
179  if (status_p2->getStatusCode() == 1) condP2 = 0;
180  } else if (strip1 == ESDetId(0))
181  condP1 = 0;
182  else if (strip2 == ESDetId(0))
183  condP2 = 0;
184  }
185 
186  // Get a vector of ES clusters (found by the PreshSeeded algorithm) associated with a given EE basic cluster.
187  for (int i=0; i<preshNclust_; i++) {
188  reco::PreshowerCluster cl1 = presh_algo->makeOneCluster(strip1,&used_strips,&rechits_map,geometry_p,topology_p);
189  cl1.setBCRef(*bc_iter);
190  if (cl1.energy() > preshClustECut) {
191  clusters1.push_back(cl1);
192  e1 += cl1.energy();
193  }
194  reco::PreshowerCluster cl2 = presh_algo->makeOneCluster(strip2,&used_strips,&rechits_map,geometry_p,topology_p);
195  cl2.setBCRef(*bc_iter);
196 
197  if ( cl2.energy() > preshClustECut) {
198  clusters2.push_back(cl2);
199  e2 += cl2.energy();
200  }
201  } // end of cycle over ES clusters
202  }
203 
204  new_BC.push_back(*bc_iter);
205  nBC++;
206  } // end of cycle over BCs
207 
208  LogTrace("EcalClusters") << " For SC #" << isc-1 << ", containing "
209  << it_super->clustersSize()
210  << " basic clusters, PreshowerClusterAlgo made "
211  << clusters1.size() << " in X plane and "
212  << clusters2.size()
213  << " in Y plane " << " preshower clusters " ;
214 
215  // update energy of the SuperCluster
216  if(e1+e2 > 1.0e-10) {
217  // GeV to #MIPs
218  e1 = e1 / mip_;
219  e2 = e2 / mip_;
220 
221  if (condP1 == 1 && condP2 == 1) {
222  deltaE = gamma0_*(e1 + alpha0_*e2);
223  } else if (condP1 == 1 && condP2 == 0) {
224  e2 = e1 * (aEta_[ieta] + bEta_[ieta] *it_super->energy());
225  deltaE = gamma1_*(e1 + alpha1_*e2);
226  } else if (condP1 == 0 && condP2 == 1) {
227  if (aEta_[ieta] != 0 || bEta_[ieta] != 0)
228  e1 = e2 / (aEta_[ieta] + bEta_[ieta] *it_super->energy());
229  deltaE = gamma2_*(e1 + alpha2_*e2);
230  } else if (condP1 == 0 && condP2 == 0) {
231  deltaE = gamma3_*(e1 + alpha3_*e2);
232  }
233  }
234 
235  //corrected Energy
236  float E = it_super->energy() + deltaE;
237 
238  LogTrace("EcalClusters") << " Creating corrected SC ";
239 
240  reco::SuperCluster sc(E, it_super->position(), it_super->seed(), new_BC, deltaE);
241  if (condP1 == 1 && condP2 == 1) sc.setPreshowerPlanesStatus(0);
242  else if (condP1 == 1 && condP2 == 0) sc.setPreshowerPlanesStatus(1);
243  else if (condP1 == 0 && condP2 == 1) sc.setPreshowerPlanesStatus(2);
244  else if (condP1 == 0 && condP2 == 0) sc.setPreshowerPlanesStatus(3);
245 
246  if (sc.energy()*sin(sc.position().theta())>etThresh_)
247  new_SC.push_back(sc);
248  LogTrace("EcalClusters") << " SuperClusters energies: new E = " << sc.energy() << " vs. old E =" << it_super->energy();
249 
250  } // end of cycle over SCs
251 
252  // copy the preshower clusters into collections and put in the Event:
253  clusters_p1->assign(clusters1.begin(), clusters1.end());
254  clusters_p2->assign(clusters2.begin(), clusters2.end());
255  // put collection of preshower clusters to the event
256  evt.put( clusters_p1, preshClusterCollectionX_ );
257  evt.put( clusters_p2, preshClusterCollectionY_ );
258  LogTrace("EcalClusters") << "Preshower clusters added to the event" ;
259 
260  // put collection of corrected super clusters to the event
261  superclusters_p->assign(new_SC.begin(), new_SC.end());
262  evt.put(superclusters_p, assocSClusterCollection_);
263  LogTrace("EcalClusters") << "Corrected SClusters added to the event" ;
264 
265  if (topology_p)
266  delete topology_p;
267 
268  nEvt_++;
269 
270 }
271 
273 
274  es.get<ESGainRcd>().get(esgain_);
275  const ESGain *gain = esgain_.product();
276 
277  double ESGain = gain->getESGain();
278 
279  es.get<ESMIPToGeVConstantRcd>().get(esMIPToGeV_);
280  const ESMIPToGeVConstant *mipToGeV = esMIPToGeV_.product();
281 
282  mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
283 
284  es.get<ESChannelStatusRcd>().get(esChannelStatus_);
285 
286  es.get<ESEEIntercalibConstantsRcd>().get(esEEInterCalib_);
287  const ESEEIntercalibConstants *esEEInterCalib = esEEInterCalib_.product();
288 
289  // both planes work
290  gamma0_ = (ESGain == 1) ? esEEInterCalib->getGammaLow0() : esEEInterCalib->getGammaHigh0();
291  alpha0_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
292 
293  // only first plane works
294  gamma1_ = (ESGain == 1) ? esEEInterCalib->getGammaLow1() : esEEInterCalib->getGammaHigh1();
295  alpha1_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow1() : esEEInterCalib->getAlphaHigh1();
296 
297  // only second plane works
298  gamma2_ = (ESGain == 1) ? esEEInterCalib->getGammaLow2() : esEEInterCalib->getGammaHigh2();
299  alpha2_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow2() : esEEInterCalib->getAlphaHigh2();
300 
301  // both planes do not work
302  gamma3_ = (ESGain == 1) ? esEEInterCalib->getGammaLow3() : esEEInterCalib->getGammaHigh3();
303  alpha3_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow3() : esEEInterCalib->getAlphaHigh3();
304 
305  es.get<ESMissingEnergyCalibrationRcd>().get(esMissingECalib_);
306  const ESMissingEnergyCalibration * esMissingECalib = esMissingECalib_.product();
307 
308  // |eta| < 1.9
309  aEta_[0] = esMissingECalib->getConstAEta0();
310  bEta_[0] = esMissingECalib->getConstBEta0();
311 
312  // 1.9 < |eta| < 2.1
313  aEta_[1] = esMissingECalib->getConstAEta1();
314  bEta_[1] = esMissingECalib->getConstBEta1();
315 
316  // 2.1 < |eta| < 2.3
317  aEta_[2] = esMissingECalib->getConstAEta2();
318  bEta_[2] = esMissingECalib->getConstBEta2();
319 
320  // 2.3 < |eta| < 2.5
321  aEta_[3] = esMissingECalib->getConstAEta3();
322  bEta_[3] = esMissingECalib->getConstBEta3();
323 
324 }
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:85
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:356
#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:100
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
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
void set(const std::string &name, int value)
set the flag, with a run-time name