CMS 3D CMS Logo

PreshowerClusterShapeProducer.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
20 
27 #include <fstream>
28 #include <sstream>
29 
31 
32 using namespace std;
33 using namespace reco;
34 using namespace edm;
36 
38  // use configuration file to setup input/output collection names
39  // Parameters to identify the hit collections
40  preshHitToken_ = consumes<EcalRecHitCollection>(ps.getParameter<edm::InputTag>("preshRecHitProducer"));
41  endcapSClusterToken_ =
42  consumes<reco::SuperClusterCollection>(ps.getParameter<edm::InputTag>("endcapSClusterProducer"));
43  caloGeometryToken_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
44 
45  PreshowerClusterShapeCollectionX_ = ps.getParameter<string>("PreshowerClusterShapeCollectionX");
46  PreshowerClusterShapeCollectionY_ = ps.getParameter<string>("PreshowerClusterShapeCollectionY");
47 
48  produces<reco::PreshowerClusterShapeCollection>(PreshowerClusterShapeCollectionX_);
49  produces<reco::PreshowerClusterShapeCollection>(PreshowerClusterShapeCollectionY_);
50 
51  float preshStripECut = ps.getParameter<double>("preshStripEnergyCut");
52  int preshNst = ps.getParameter<int>("preshPi0Nstrip");
53 
54  string debugString = ps.getParameter<string>("debugLevel");
55 
56  string tmpPath = ps.getUntrackedParameter<string>("pathToWeightFiles", "RecoEcal/EgammaClusterProducers/data/");
57 
58  presh_pi0_algo = new EndcapPiZeroDiscriminatorAlgo(preshStripECut, preshNst, tmpPath);
59 
60  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer:presh_pi0_algo class instantiated ";
61 
62  nEvt_ = 0;
63 }
64 
66 
68  ostringstream ostr; // use this stream for all messages in produce
69 
70  LogTrace("EcalClusters") << "\n ....... Event " << evt.id() << " with Number = " << nEvt_ + 1
71  << " is analyzing ....... ";
72 
74  Handle<SuperClusterCollection> pSuperClusters;
75 
76  // get the ECAL -> Preshower geometry and topology:
77  ESHandle<CaloGeometry> geoHandle = es.getHandle(caloGeometryToken_);
79  const CaloSubdetectorGeometry*& geometry_p = geometry;
80 
81  // create a unique_ptr to a PreshowerClusterShapeCollection
82  auto ps_cl_for_pi0_disc_x = std::make_unique<reco::PreshowerClusterShapeCollection>();
83  auto ps_cl_for_pi0_disc_y = std::make_unique<reco::PreshowerClusterShapeCollection>();
84 
85  std::unique_ptr<CaloSubdetectorTopology> topology_p;
86  if (geometry)
87  topology_p = std::make_unique<EcalPreshowerTopology>();
88 
89  // fetch the Preshower product (RecHits)
90  evt.getByToken(preshHitToken_, pRecHits);
91  // pointer to the object in the product
92  const EcalRecHitCollection* rechits = pRecHits.product();
93 
94  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Total # of preshower RecHits: " << rechits->size();
95 
96  // if ( rechits->size() <= 0 ) return;
97 
98  // make the map of Preshower rechits:
99  map<DetId, EcalRecHit> rechits_map;
101  for (it = rechits->begin(); it != rechits->end(); it++) {
102  rechits_map.insert(make_pair(it->id(), *it));
103  }
104 
105  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: ### Preshower RecHits_map of size " << rechits_map.size()
106  << " was created!";
107 
108  reco::PreshowerClusterShapeCollection ps_cl_x, ps_cl_y;
109 
110  //make cycle over Photon Collection
111  int SC_index = 0;
112  // Handle<PhotonCollection> correctedPhotonHandle;
113  // evt.getByLabel(photonCorrCollectionProducer_, correctedPhotonCollection_ , correctedPhotonHandle);
114  // const PhotonCollection corrPhoCollection = *(correctedPhotonHandle.product());
115  // cout << " Photon Collection size : " << corrPhoCollection.size() << endl;
116 
117  evt.getByToken(endcapSClusterToken_, pSuperClusters);
118  const reco::SuperClusterCollection* SClusts = pSuperClusters.product();
119  LogTrace("EcalClusters") << "### Total # Endcap Superclusters: " << SClusts->size();
120 
121  SuperClusterCollection::const_iterator it_s;
122  for (it_s = SClusts->begin(); it_s != SClusts->end(); it_s++) {
123  SuperClusterRef it_super(reco::SuperClusterRef(pSuperClusters, SC_index));
124 
125  float SC_eta = it_super->eta();
126 
127  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer: superCl_E = " << it_super->energy()
128  << " superCl_Et = " << it_super->energy() * sin(2 * atan(exp(-it_super->eta())))
129  << " superCl_Eta = " << SC_eta << " superCl_Phi = " << it_super->phi();
130 
131  if (fabs(SC_eta) >= 1.65 && fabs(SC_eta) <= 2.5) { // Use Preshower region only
132  if (geometry) {
133  const GlobalPoint pointSC(it_super->x(), it_super->y(), it_super->z()); // get the centroid of the SC
134  LogTrace("EcalClusters") << "SC centroind = " << pointSC;
135 
136  // Get the Preshower 2-planes RecHit vectors associated with the given SC
137 
138  DetId tmp_stripX = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 1);
139  DetId tmp_stripY = (dynamic_cast<const EcalPreshowerGeometry*>(geometry_p))->getClosestCellInPlane(pointSC, 2);
140  ESDetId stripX = (tmp_stripX == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripX);
141  ESDetId stripY = (tmp_stripY == DetId(0)) ? ESDetId(0) : ESDetId(tmp_stripY);
142 
143  vector<float> vout_stripE1 = presh_pi0_algo->findPreshVector(stripX, &rechits_map, topology_p.get());
144  vector<float> vout_stripE2 = presh_pi0_algo->findPreshVector(stripY, &rechits_map, topology_p.get());
145 
146  LogTrace("EcalClusters") << "PreshowerClusterShapeProducer : ES Energy vector associated to the given SC = ";
147  for (int k1 = 0; k1 < 11; k1++) {
148  LogTrace("EcalClusters") << vout_stripE1[k1] << " ";
149  }
150 
151  for (int k1 = 0; k1 < 11; k1++) {
152  LogTrace("EcalClusters") << vout_stripE2[k1] << " ";
153  }
154 
156  ps1.setSCRef(it_super);
157  ps_cl_x.push_back(ps1);
158 
160  ps2.setSCRef(it_super);
161  ps_cl_y.push_back(ps2);
162  }
163  SC_index++;
164  } // end of cycle over Endcap SC
165  }
166  // put collection of PreshowerClusterShape in the Event:
167  ps_cl_for_pi0_disc_x->assign(ps_cl_x.begin(), ps_cl_x.end());
168  ps_cl_for_pi0_disc_y->assign(ps_cl_y.begin(), ps_cl_y.end());
169 
170  evt.put(std::move(ps_cl_for_pi0_disc_x), PreshowerClusterShapeCollectionX_);
171  evt.put(std::move(ps_cl_for_pi0_disc_y), PreshowerClusterShapeCollectionY_);
172  LogTrace("EcalClusters") << "PreshowerClusterShapeCollection added to the event";
173 
174  nEvt_++;
175 
176  LogDebug("PiZeroDiscriminatorDebug") << ostr.str();
177 }
EcalPreshowerTopology.h
reco::PreshowerClusterShape
Definition: PreshowerClusterShape.h:14
geometry
ESHandle< TrackerGeometry > geometry
Definition: TkLasBeamFitter.cc:200
Handle.h
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
reco::PreshowerClusterShape::setSCRef
void setSCRef(const SuperClusterRef &r)
Definition: PreshowerClusterShape.h:36
edm
HLT enums.
Definition: AlignableModifier.h:19
geometry
Definition: geometry.py:1
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
edm::SortedCollection< EcalRecHit >
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EDAnalyzer.h
ESDetId
Definition: ESDetId.h:15
ESDetId.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
edm::Handle
Definition: AssociativeIterator.h:50
EndcapPiZeroDiscriminatorAlgo
Definition: EndcapPiZeroDiscriminatorAlgo.h:15
edm::Ref< SuperClusterCollection >
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
TruncatedPyramid.h
edm::ESHandle< CaloGeometry >
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 >
reco::PreshowerClusterShapeCollection
std::vector< PreshowerClusterShape > PreshowerClusterShapeCollection
collection of PreshowerClusterShape objects
Definition: PreshowerClusterShapeFwd.h:13
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PreshowerClusterShapeProducer::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
Definition: PreshowerClusterShapeProducer.cc:67
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
edm::EventSetup
Definition: EventSetup.h:57
DetId::Ecal
Definition: DetId.h:27
PreshowerClusterShapeProducer::~PreshowerClusterShapeProducer
~PreshowerClusterShapeProducer() override
Definition: PreshowerClusterShapeProducer.cc:65
EcalPreshower
Definition: EcalSubdetector.h:10
CaloCellGeometry.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
SuperClusterFwd.h
Frameworkfwd.h
SuperCluster.h
edm::EventBase::id
edm::EventID id() const
Definition: EventBase.h:59
EventSetup.h
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
ParameterSet.h
PreshowerClusterShapeProducer.h
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
edm::Event
Definition: Event.h:73
PreshowerClusterShapeProducer::PreshowerClusterShapeProducer
PreshowerClusterShapeProducer(const edm::ParameterSet &ps)
Definition: PreshowerClusterShapeProducer.cc:37
edm::InputTag
Definition: InputTag.h:15