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
34 #include <fstream>
35 
37 
38 using namespace edm;
39 using namespace std;
40 
42  // use configuration file to setup input/output collection names
43  preshHitsToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("preshRecHitProducer"));
44 
45  // Name of a SuperClusterCollection to make associations:
46  endcapSClusterToken_ =
47  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSClusterProducer"));
48 
49  esGainToken_ = esConsumes<ESGain, ESGainRcd>();
50  esMIPToGeVToken_ = esConsumes<ESMIPToGeVConstant, ESMIPToGeVConstantRcd>();
51  esEEInterCalibToken_ = esConsumes<ESEEIntercalibConstants, ESEEIntercalibConstantsRcd>();
52  esMissingECalibToken_ = esConsumes<ESMissingEnergyCalibration, ESMissingEnergyCalibrationRcd>();
53  esChannelStatusToken_ = esConsumes<ESChannelStatus, ESChannelStatusRcd>();
54  caloGeometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
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 
79 
83 
84  // get the ECAL geometry:
85  edm::ESHandle<CaloGeometry> geoHandle = es.getHandle(caloGeometryToken_);
86 
87  // retrieve ES-EE intercalibration constants and channel status
88  set(es);
89  const ESChannelStatus* channelStatus = esChannelStatus_.product();
90 
92 
93  // create unique_ptr to a PreshowerClusterCollection
94  auto clusters_p1 = std::make_unique<reco::PreshowerClusterCollection>();
95  auto clusters_p2 = std::make_unique<reco::PreshowerClusterCollection>();
96  // create new collection of corrected super clusters
97  auto superclusters_p = std::make_unique<reco::SuperClusterCollection>();
98 
99  std::unique_ptr<CaloSubdetectorTopology> topology_p;
100  if (geometry_p)
101  topology_p = std::make_unique<EcalPreshowerTopology>();
102 
103  // fetch the product (pSuperClusters)
104  evt.getByToken(endcapSClusterToken_, pSuperClusters);
105  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
106 
107  // fetch the product (RecHits)
108  evt.getByToken(preshHitsToken_, pRecHits);
109  // pointer to the object in the product
110  const EcalRecHitCollection* rechits = pRecHits.product(); // EcalRecHitCollection hit_collection = *rhcHandle;
111 
112  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### Total # of preshower RecHits: " << rechits->size();
113 
114  // make the map of rechits:
115  std::map<DetId, EcalRecHit> rechits_map;
117  for (it = rechits->begin(); it != rechits->end(); it++) {
118  // remove bad ES rechits
119  if (it->recoFlag() == 1 || it->recoFlag() == 14 || (it->recoFlag() <= 10 && it->recoFlag() >= 5))
120  continue;
121  //Make the map of DetID, EcalRecHit pairs
122  rechits_map.insert(std::make_pair(it->id(), *it));
123  }
124  // The set of used DetID's for a given event:
125  std::set<DetId> used_strips;
126  used_strips.clear();
127  LogTrace("EcalClusters") << "PreshowerClusterProducerInfo: ### rechits_map of size " << rechits_map.size()
128  << " was created!";
129 
130  reco::PreshowerClusterCollection clusters1, clusters2; // output collection of corrected PCs
131  reco::SuperClusterCollection new_SC; // output collection of corrected SCs
132 
133  //make cycle over super clusters
134  reco::SuperClusterCollection::const_iterator it_super;
135  int isc = 0;
136  for (it_super = SClusts->begin(); it_super != SClusts->end(); ++it_super) {
137  float e1 = 0;
138  float e2 = 0;
139  float deltaE = 0;
140 
142  ++isc;
143  LogTrace("EcalClusters") << " superE = " << it_super->energy() << " superETA = " << it_super->eta()
144  << " superPHI = " << it_super->phi();
145 
146  int nBC = 0;
147  int condP1 = 1; // 0: dead channel; 1: active channel
148  int condP2 = 1;
149  reco::CaloCluster_iterator bc_iter = it_super->clustersBegin();
150  for (; bc_iter != it_super->clustersEnd(); ++bc_iter) {
151  if (geometry_p) {
152  // Get strip position at intersection point of the line EE - Vertex:
153  double X = (*bc_iter)->x();
154  double Y = (*bc_iter)->y();
155  double Z = (*bc_iter)->z();
156  const GlobalPoint point(X, Y, Z);
157 
158  DetId tmp1 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 1);
159  DetId tmp2 = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(point, 2);
160  ESDetId strip1 = (tmp1 == DetId(0)) ? ESDetId(0) : ESDetId(tmp1);
161  ESDetId strip2 = (tmp2 == DetId(0)) ? ESDetId(0) : ESDetId(tmp2);
162 
163  if (nBC == 0) {
164  if (strip1 != ESDetId(0) && strip2 != ESDetId(0)) {
165  ESChannelStatusMap::const_iterator status_p1 = channelStatus->getMap().find(strip1);
166  ESChannelStatusMap::const_iterator status_p2 = channelStatus->getMap().find(strip2);
167  if (status_p1->getStatusCode() == 1)
168  condP1 = 0;
169  if (status_p2->getStatusCode() == 1)
170  condP2 = 0;
171  } else if (strip1 == ESDetId(0))
172  condP1 = 0;
173  else if (strip2 == ESDetId(0))
174  condP2 = 0;
175  }
176 
177  // Get a vector of ES clusters (found by the PreshSeeded algorithm) associated with a given EE basic cluster.
178  for (int i = 0; i < preshNclust_; i++) {
180  presh_algo->makeOneCluster(strip1, &used_strips, &rechits_map, geometry_p, topology_p.get());
181  cl1.setBCRef(*bc_iter);
182  if (cl1.energy() > preshClustECut) {
183  clusters1.push_back(cl1);
184  e1 += cl1.energy();
185  }
187  presh_algo->makeOneCluster(strip2, &used_strips, &rechits_map, geometry_p, topology_p.get());
188  cl2.setBCRef(*bc_iter);
189 
190  if (cl2.energy() > preshClustECut) {
191  clusters2.push_back(cl2);
192  e2 += cl2.energy();
193  }
194  } // end of cycle over ES clusters
195  }
196 
197  new_BC.push_back(*bc_iter);
198  nBC++;
199  } // end of cycle over BCs
200 
201  LogTrace("EcalClusters") << " For SC #" << isc - 1 << ", containing " << it_super->clustersSize()
202  << " basic clusters, PreshowerClusterAlgo made " << clusters1.size() << " in X plane and "
203  << clusters2.size() << " in Y plane "
204  << " preshower clusters ";
205 
206  // update energy of the SuperCluster
207  if (e1 + e2 > 1.0e-10) {
208  e1 = e1 / mip_; // GeV to #MIPs
209  e2 = e2 / mip_;
210 
211  if (condP1 == 1 && condP2 == 1) {
212  deltaE = gamma0_ * (e1 + alpha0_ * e2);
213  } else if (condP1 == 1 && condP2 == 0) {
214  deltaE = gamma1_ * (e1 + alpha1_ * e2);
215  } else if (condP1 == 0 && condP2 == 1) {
216  deltaE = gamma2_ * (e1 + alpha2_ * e2);
217  } else if (condP1 == 0 && condP2 == 0) {
218  deltaE = gamma3_ * (e1 + alpha3_ * e2);
219  }
220  }
221 
222  //corrected Energy
223  float E = it_super->energy() + deltaE;
224 
225  LogTrace("EcalClusters") << " Creating corrected SC ";
226 
227  reco::SuperCluster sc(E, it_super->position(), it_super->seed(), new_BC, deltaE);
228  if (condP1 == 1 && condP2 == 1)
230  else if (condP1 == 1 && condP2 == 0)
231  sc.setPreshowerPlanesStatus(1);
232  else if (condP1 == 0 && condP2 == 1)
233  sc.setPreshowerPlanesStatus(2);
234  else if (condP1 == 0 && condP2 == 0)
235  sc.setPreshowerPlanesStatus(3);
236 
237  if (sc.energy() * sin(sc.position().theta()) > etThresh_)
238  new_SC.push_back(sc);
239  LogTrace("EcalClusters") << " SuperClusters energies: new E = " << sc.energy()
240  << " 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(std::move(clusters_p1), preshClusterCollectionX_);
249  evt.put(std::move(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(std::move(superclusters_p), assocSClusterCollection_);
255  LogTrace("EcalClusters") << "Corrected SClusters added to the event";
256 
257  nEvt_++;
258 }
259 
261  esgain_ = es.getHandle(esGainToken_);
262  const ESGain* gain = esgain_.product();
263 
264  double ESGain = gain->getESGain();
265 
266  esMIPToGeV_ = es.getHandle(esMIPToGeVToken_);
267  const ESMIPToGeVConstant* mipToGeV = esMIPToGeV_.product();
268 
269  mip_ = (ESGain == 1) ? mipToGeV->getESValueLow() : mipToGeV->getESValueHigh();
270 
271  esChannelStatus_ = es.getHandle(esChannelStatusToken_);
272 
273  esEEInterCalib_ = es.getHandle(esEEInterCalibToken_);
274  const ESEEIntercalibConstants* esEEInterCalib = esEEInterCalib_.product();
275 
276  // both planes work
277  gamma0_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh0();
278  alpha0_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow0() : esEEInterCalib->getAlphaHigh0();
279 
280  // only first plane works
281  gamma1_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow1()) : esEEInterCalib->getGammaHigh1();
282  alpha1_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow1() : esEEInterCalib->getAlphaHigh1();
283 
284  // only second plane works
285  gamma2_ = (ESGain == 1) ? (0.02 * esEEInterCalib->getGammaLow2()) : esEEInterCalib->getGammaHigh2();
286  alpha2_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow2() : esEEInterCalib->getAlphaHigh2();
287 
288  // both planes do not work
289  gamma3_ = (ESGain == 1) ? 0.02 : esEEInterCalib->getGammaHigh3();
290  alpha3_ = (ESGain == 1) ? esEEInterCalib->getAlphaLow3() : esEEInterCalib->getAlphaHigh3();
291 
292  esMissingECalib_ = es.getHandle(esMissingECalibToken_);
293  const ESMissingEnergyCalibration* esMissingECalib = esMissingECalib_.product();
294 
295  // |eta| < 1.9
296  aEta_[0] = esMissingECalib->getConstAEta0();
297  bEta_[0] = esMissingECalib->getConstBEta0();
298 
299  // 1.9 < |eta| < 2.1
300  aEta_[1] = esMissingECalib->getConstAEta1();
301  bEta_[1] = esMissingECalib->getConstBEta1();
302 
303  // 2.1 < |eta| < 2.3
304  aEta_[2] = esMissingECalib->getConstAEta2();
305  bEta_[2] = esMissingECalib->getConstBEta2();
306 
307  // 2.3 < |eta| < 2.5
308  aEta_[3] = esMissingECalib->getConstAEta3();
309  bEta_[3] = esMissingECalib->getConstBEta3();
310 }
EcalPreshowerTopology.h
ESGain
Definition: ESGain.h:7
Handle.h
ESMissingEnergyCalibration
Definition: ESMissingEnergyCalibration.h:7
ESMissingEnergyCalibration::getConstBEta1
float getConstBEta1() const
Definition: ESMissingEnergyCalibration.h:28
mps_fire.i
i
Definition: mps_fire.py:428
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
ESEEIntercalibConstants::getGammaLow2
float getGammaLow2() const
Definition: ESEEIntercalibConstants.h:39
reco::SuperCluster
Definition: SuperCluster.h:18
X
#define X(str)
Definition: MuonsGrabber.cc:38
edm
HLT enums.
Definition: AlignableModifier.h:19
EBDetId.h
EEDetId.h
ESMissingEnergyCalibration::getConstBEta0
float getConstBEta0() const
Definition: ESMissingEnergyCalibration.h:23
ESCondObjectContainer::find
const_iterator find(uint32_t rawId) const
Definition: ESCondObjectContainer.h:33
reco::PreshowerCluster
Definition: PreshowerCluster.h:17
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
edm::PtrVectorItr
Definition: PtrVector.h:51
edm::SortedCollection< EcalRecHit >
reco::SuperCluster::setPreshowerPlanesStatus
void setPreshowerPlanesStatus(const uint32_t &status)
Definition: SuperCluster.h:136
PreshowerClusterProducer::~PreshowerClusterProducer
~PreshowerClusterProducer() override
Definition: PreshowerClusterProducer.cc:78
ESEEIntercalibConstants::getGammaHigh1
float getGammaHigh1() const
Definition: ESEEIntercalibConstants.h:54
GetRecoTauVFromDQM_MC_cff.cl2
cl2
Definition: GetRecoTauVFromDQM_MC_cff.py:44
EDAnalyzer.h
ESDetId
Definition: ESDetId.h:15
ESDetId.h
ESEEIntercalibConstants::getGammaLow1
float getGammaLow1() const
Definition: ESEEIntercalibConstants.h:34
ESMIPToGeVConstant::getESValueHigh
float getESValueHigh() const
Definition: ESMIPToGeVConstant.h:15
edm::Handle
Definition: AssociativeIterator.h:50
EcalRecHitCollections.h
PreshowerClusterProducer.h
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
reco::SuperClusterCollection
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
Definition: SuperClusterFwd.h:9
DetId
Definition: DetId.h:17
MakerMacros.h
ESMissingEnergyCalibration::getConstAEta2
float getConstAEta2() const
Definition: ESMissingEnergyCalibration.h:31
ESEEIntercalibConstants::getAlphaHigh3
float getAlphaHigh3() const
Definition: ESEEIntercalibConstants.h:66
ESEEIntercalibConstants::getAlphaHigh0
float getAlphaHigh0() const
Definition: ESEEIntercalibConstants.h:51
edm::PtrVector< CaloCluster >
PreshowerClusterProducer::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
Definition: PreshowerClusterProducer.cc:80
TruncatedPyramid.h
ESEEIntercalibConstants::getGammaHigh0
float getGammaHigh0() const
Definition: ESEEIntercalibConstants.h:49
edm::ESHandle< CaloGeometry >
ESCondObjectContainer::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: ESCondObjectContainer.h:17
ESEEIntercalibConstants::getAlphaHigh2
float getAlphaHigh2() const
Definition: ESEEIntercalibConstants.h:61
reco::PreshowerClusterCollection
std::vector< PreshowerCluster > PreshowerClusterCollection
collection of PreshowerCluster objects
Definition: PreshowerClusterFwd.h:12
HI_PhotonSkim_cff.rechits
rechits
Definition: HI_PhotonSkim_cff.py:76
EcalPreshowerGeometry.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
Point3DBase< float, GlobalTag >
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalSubdetector.h
edm::PtrVector::push_back
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
PreshowerClusterProducer::set
void set(const edm::EventSetup &es)
Definition: PreshowerClusterProducer.cc:260
CaloSubdetectorGeometry.h
ESEEIntercalibConstants::getGammaHigh2
float getGammaHigh2() const
Definition: ESEEIntercalibConstants.h:59
ESMissingEnergyCalibration::getConstAEta0
float getConstAEta0() const
Definition: ESMissingEnergyCalibration.h:21
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ESEEIntercalibConstants::getAlphaLow3
float getAlphaLow3() const
Definition: ESEEIntercalibConstants.h:46
HcalDetId.h
EgHLTOffHistBins_cfi.deltaE
deltaE
Definition: EgHLTOffHistBins_cfi.py:28
StorageManager_cfg.e1
e1
Definition: StorageManager_cfg.py:16
PreshowerClusterAlgo
Definition: PreshowerClusterAlgo.h:22
ESEEIntercalibConstants::getAlphaLow0
float getAlphaLow0() const
Definition: ESEEIntercalibConstants.h:31
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
ESEEIntercalibConstants::getAlphaLow2
float getAlphaLow2() const
Definition: ESEEIntercalibConstants.h:41
ESEEIntercalibConstants::getAlphaLow1
float getAlphaLow1() const
Definition: ESEEIntercalibConstants.h:36
ESMissingEnergyCalibration::getConstBEta2
float getConstBEta2() const
Definition: ESMissingEnergyCalibration.h:33
ESMIPToGeVConstant
Definition: ESMIPToGeVConstant.h:7
edm::EventSetup
Definition: EventSetup.h:57
ESMissingEnergyCalibration::getConstAEta1
float getConstAEta1() const
Definition: ESMissingEnergyCalibration.h:26
DetId::Ecal
Definition: DetId.h:27
ESMissingEnergyCalibration::getConstBEta3
float getConstBEta3() const
Definition: ESMissingEnergyCalibration.h:38
ESEEIntercalibConstants::getGammaHigh3
float getGammaHigh3() const
Definition: ESEEIntercalibConstants.h:64
ESCondObjectContainer
Definition: ESCondObjectContainer.h:11
EcalRecHit.h
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
EcalPreshower
Definition: EcalSubdetector.h:10
ESMIPToGeVConstant::getESValueLow
float getESValueLow() const
Definition: ESMIPToGeVConstant.h:13
CaloCellGeometry.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
ESCondObjectContainer::getMap
const self & getMap() const
Definition: ESCondObjectContainer.h:41
SuperClusterFwd.h
Frameworkfwd.h
SuperCluster.h
ESMissingEnergyCalibration::getConstAEta3
float getConstAEta3() const
Definition: ESMissingEnergyCalibration.h:36
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
BeamSpotPI::Y
Definition: BeamSpotPayloadInspectorHelper.h:31
ESEEIntercalibConstants::getAlphaHigh1
float getAlphaHigh1() const
Definition: ESEEIntercalibConstants.h:56
ESEEIntercalibConstants
Definition: ESEEIntercalibConstants.h:7
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
PreshowerClusterProducer::PreshowerClusterProducer
PreshowerClusterProducer(const edm::ParameterSet &ps)
Definition: PreshowerClusterProducer.cc:41
PreshowerClusterFwd.h
ParameterSet.h
BeamSpotPI::Z
Definition: BeamSpotPayloadInspectorHelper.h:32
point
*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
edm::Event
Definition: Event.h:73
reco::PreshowerCluster::setBCRef
void setBCRef(const CaloClusterPtr &r)
DetIds of component RecHits – now inherited from CaloCluster.
Definition: PreshowerCluster.h:53
reco::CaloCluster::energy
double energy() const
cluster energy
Definition: CaloCluster.h:149
edm::InputTag
Definition: InputTag.h:15
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37