CMS 3D CMS Logo

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