CMS 3D CMS Logo

HGCalShowerSeparation.cc
Go to the documentation of this file.
1 // user include files
2 
6 
10 
12 
14 
19 
26 
31 
37 
39 
40 #include <map>
41 #include <array>
42 #include <string>
43 #include <numeric>
44 
46  public:
48  ~HGCalShowerSeparation() override;
49 
50  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
51 
52  private:
54  edm::EventSetup const&) override;
55  void analyze(const edm::Event&, const edm::EventSetup&) override;
56 
57  void fillWithRecHits(std::map<DetId, const HGCRecHit*>&, DetId, unsigned int,
58  float, int&, float&);
59 
64 
65  int debug_;
68 
80  std::vector<MonitorElement*> profileOnLayer_;
81  std::vector<MonitorElement*> globalProfileOnLayer_;
82  std::vector<MonitorElement*> distanceOnLayer_;
83  std::vector<MonitorElement*> idealDistanceOnLayer_;
84  std::vector<MonitorElement*> idealDeltaXY_;
85  std::vector<MonitorElement*> centers_;
86 
87  static const int layers_ = 52;
88 };
89 
91  : debug_(iConfig.getParameter<int>("debug")),
92  filterOnEnergyAndCaloP_(iConfig.getParameter<bool>("filterOnEnergyAndCaloP")){
93  auto recHitsEE = iConfig.getParameter<edm::InputTag>("recHitsEE");
94  auto recHitsFH = iConfig.getParameter<edm::InputTag>("recHitsFH");
95  auto recHitsBH = iConfig.getParameter<edm::InputTag>("recHitsBH");
96  auto caloParticles = iConfig.getParameter<edm::InputTag>("caloParticles");
97  recHitsEE_ = consumes<HGCRecHitCollection>(recHitsEE);
98  recHitsFH_ = consumes<HGCRecHitCollection>(recHitsFH);
99  recHitsBH_ = consumes<HGCRecHitCollection>(recHitsBH);
100  caloParticles_ = consumes<std::vector<CaloParticle> >(caloParticles);
101 }
102 
104  // do anything here that needs to be done at desctruction time
105  // (e.g. close files, deallocate resources etc.)
106 }
107 
109  edm::Run const& iRun,
110  edm::EventSetup const& /* iSetup */) {
111  ibooker.cd();
112  ibooker.setCurrentFolder("HGCalShowerSeparation");
113  scEnergy_ = ibooker.book1D("SCEnergy", "SCEnergy", 240, 0., 120.);
114  eta1_ = ibooker.book1D("eta1", "eta1", 80, 0., 4.);
115  eta2_ = ibooker.book1D("eta2", "eta2", 80, 0., 4.);
116  energy1_ = ibooker.book1D("energy1", "energy1", 240, 0., 120.);
117  energy2_ = ibooker.book1D("energy2", "energy2", 240, 0., 120.);
118  energytot_ = ibooker.book1D("energytot", "energytot", 200, 100., 200.);
119  showerProfile_ = ibooker.book2D("ShowerProfile", "ShowerProfile",
120  800, -400., 400.,
121  layers_, 0., (float)layers_);
122  layerEnergy_ = ibooker.book2D("LayerEnergy", "LayerEnergy",
123  60, 0., 60.,
124  50, 0., 0.1);
125  layerDistance_ = ibooker.book2D("LayerDistance", "LayerDistance",
126  60, 0., 60.,
127  400, -400., 400.);
128  etaPhi_ = ibooker.book2D("EtaPhi", "EtaPhi",
129  800, -4., 4.,
130  800, -4., 4.);
131  deltaEtaPhi_ = ibooker.book2D("DeltaEtaPhi", "DeltaEtaPhi",
132  100, -0.5, 0.5,
133  100, -0.5, 0.5);
134  for (int i = 0; i < layers_; ++i) {
135  profileOnLayer_.push_back(ibooker.book2D(std::string("ProfileOnLayer_") + std::to_string(i),
136  std::string("ProfileOnLayer_") + std::to_string(i),
137  120, -600., 600.,
138  120, -600., 600.)
139  );
140  globalProfileOnLayer_.push_back(ibooker.book2D(std::string("GlobalProfileOnLayer_") + std::to_string(i),
141  std::string("GlobalProfileOnLayer_") + std::to_string(i),
142  320, -160., 160.,
143  320, -160., 160.)
144  );
145  distanceOnLayer_.push_back(ibooker.book1D(std::string("DistanceOnLayer_") + std::to_string(i),
146  std::string("DistanceOnLayer_") + std::to_string(i),
147  120, -600., 600.)
148  );
149  idealDistanceOnLayer_.push_back(ibooker.book1D(std::string("IdealDistanceOnLayer_") + std::to_string(i),
150  std::string("IdealDistanceOnLayer_") + std::to_string(i),
151  120, -600., 600.)
152  );
153  idealDeltaXY_.push_back(ibooker.book2D(std::string("IdealDeltaXY_") + std::to_string(i),
154  std::string("IdealDeltaXY_") + std::to_string(i),
155  800, -400., 400.,
156  800, -400., 400.)
157  );
158  centers_.push_back(ibooker.book2D(std::string("Centers_") + std::to_string(i),
159  std::string("Centers_") + std::to_string(i),
160  320, -1600., 1600.,
161  320, -1600., 1600.)
162  );
163  }
164 }
165 
167  const edm::EventSetup& iSetup) {
168  using namespace edm;
169 
170  recHitTools_.getEventSetup(iSetup);
171 
172  Handle<HGCRecHitCollection> recHitHandleEE;
173  Handle<HGCRecHitCollection> recHitHandleFH;
174  Handle<HGCRecHitCollection> recHitHandleBH;
175 
176  Handle<std::vector<CaloParticle> > caloParticleHandle;
177  iEvent.getByToken(caloParticles_, caloParticleHandle);
178  const std::vector<CaloParticle>& caloParticles = *caloParticleHandle;
179 
180 
181  iEvent.getByToken(recHitsEE_, recHitHandleEE);
182  iEvent.getByToken(recHitsFH_, recHitHandleFH);
183  iEvent.getByToken(recHitsBH_, recHitHandleBH);
184  const auto& rechitsEE = *recHitHandleEE;
185  const auto& rechitsFH = *recHitHandleFH;
186  const auto& rechitsBH = *recHitHandleBH;
187 
188  std::map<DetId, const HGCRecHit*> hitmap;
189  for (unsigned int i = 0; i < rechitsEE.size(); ++i) {
190  hitmap[rechitsEE[i].detid()] = &rechitsEE[i];
191  }
192  for (unsigned int i = 0; i < rechitsFH.size(); ++i) {
193  hitmap[rechitsFH[i].detid()] = &rechitsFH[i];
194  }
195  for (unsigned int i = 0; i < rechitsBH.size(); ++i) {
196  hitmap[rechitsBH[i].detid()] = &rechitsBH[i];
197  }
198 
199  // loop over caloParticles
200  IfLogTrace(debug_ > 0, "HGCalShowerSeparation")
201  << "Number of caloParticles: " << caloParticles.size() << std::endl;
202  if (caloParticles.size() == 2) {
203  auto eta1 = caloParticles[0].eta();
204  auto phi1 = caloParticles[0].phi();
205  auto theta1 = 2.*atan(exp(-eta1));
206  auto eta2 = caloParticles[1].eta();
207  auto phi2 = caloParticles[1].phi();
208  auto theta2 = 2.*atan(exp(-eta2));
209  eta1_->Fill(eta1);
210  eta2_->Fill(eta2);
211 
212 
213  // Select event only if the sum of the energy of its recHits
214  // is close enough to the gen energy
215  int count = 0;
216  int size = 0;
217  float energy = 0.;
218  float energy_tmp = 0.;
219  for (const auto& it_caloPart : caloParticles) {
220  count++;
221  const SimClusterRefVector& simClusterRefVector = it_caloPart.simClusters();
222  size += simClusterRefVector.size();
223  for (const auto& it_sc : simClusterRefVector) {
224  const SimCluster& simCluster = (*(it_sc));
225  const std::vector<std::pair<uint32_t, float> >& hits_and_fractions =
226  simCluster.hits_and_fractions();
227  for (const auto& it_haf : hits_and_fractions) {
228  if (hitmap.count(it_haf.first))
229  energy += hitmap[it_haf.first]->energy()*it_haf.second;
230  } //hits and fractions
231  } // simcluster
232  if (count == 1) {
233  energy1_->Fill(energy);
234  energy_tmp = energy;
235  } else {
236  energy2_->Fill(energy-energy_tmp);
237  }
238  } // caloParticle
239  energytot_->Fill(energy);
240  if (filterOnEnergyAndCaloP_ && (energy < 2.*0.8*80 or size !=2))
241  return;
242 
243  deltaEtaPhi_->Fill(eta1-eta2, phi1-phi2);
244 
245  for (const auto& it_caloPart : caloParticles) {
246  const SimClusterRefVector& simClusterRefVector = it_caloPart.simClusters();
247  IfLogTrace(debug_ > 0, "HGCalShowerSeparation")
248  << ">>> " << simClusterRefVector.size() << std::endl;
249  for (const auto& it_sc : simClusterRefVector) {
250  const SimCluster& simCluster = (*(it_sc));
251  if (simCluster.energy() < 80*0.8)
252  continue;
253  scEnergy_->Fill(simCluster.energy());
254  IfLogTrace(debug_ > 1, "HGCalShowerSeparation")
255  << ">>> SC.energy(): " << simCluster.energy()
256  << " SC.simEnergy(): " << simCluster.simEnergy()
257  << std::endl;
258  const std::vector<std::pair<uint32_t, float> >& hits_and_fractions =
259  simCluster.hits_and_fractions();
260 
261  for (const auto& it_haf : hits_and_fractions) {
262  if (!hitmap.count(it_haf.first))
263  continue;
264  unsigned int hitlayer = recHitTools_.getLayerWithOffset(it_haf.first);
265  auto global = recHitTools_.getPosition(it_haf.first);
266  float globalx = global.x();
267  float globaly = global.y();
268  float globalz = global.z();
269  if (globalz == 0)
270  continue;
271  auto rho1 = globalz*tan(theta1);
272  auto rho2 = globalz*tan(theta2);
273  auto x1 = rho1*cos(phi1);
274  auto y1 = rho1*sin(phi1);
275  auto x2 = rho2*cos(phi2);
276  auto y2 = rho2*sin(phi2);
277  auto half_point_x = (x1+x2)/2.;
278  auto half_point_y = (y1+y2)/2.;
279  auto half_point = sqrt((x1-half_point_x)*(x1-half_point_x)+(y1-half_point_y)*(y1-half_point_y));
280  auto d_len = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
281  auto dn_x = (x2-x1)/d_len;
282  auto dn_y = (y2-y1)/d_len;
283  auto distance = (globalx-x1)*dn_x + (globaly - y1)*dn_y;
284  distance -= half_point;
285  auto idealDistance = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
286  if (hitmap.count(it_haf.first)) {
287  profileOnLayer_[hitlayer]->Fill(10.*(globalx-half_point_x),
288  10.*(globaly-half_point_y),
289  hitmap[it_haf.first]->energy()*it_haf.second);
290  profileOnLayer_[55]->Fill(10.*(globalx-half_point_x),
291  10.*(globaly-half_point_y),
292  hitmap[it_haf.first]->energy()*it_haf.second);
293  globalProfileOnLayer_[hitlayer]->Fill(globalx,
294  globaly,
295  hitmap[it_haf.first]->energy()*it_haf.second);
296  globalProfileOnLayer_[55]->Fill(globalx,
297  globaly,
298  hitmap[it_haf.first]->energy()*it_haf.second);
299  layerEnergy_->Fill(hitlayer, hitmap[it_haf.first]->energy());
300  layerDistance_->Fill(hitlayer, std::abs(10.*distance), hitmap[it_haf.first]->energy()*it_haf.second);
301  etaPhi_->Fill(global.eta(), global.phi());
302  distanceOnLayer_[hitlayer]->Fill(10.*distance);//,
303  idealDistanceOnLayer_[hitlayer]->Fill(10.*idealDistance);//,
304  idealDeltaXY_[hitlayer]->Fill(10.*(x1-x2), 10.*(y1-y2));//,
305  centers_[hitlayer]->Fill(10.*half_point_x, 10.*half_point_y);//,
306  IfLogTrace(debug_ > 0, "HGCalShowerSeparation")
307  << ">>> " << distance
308  << " " << hitlayer
309  << " " << hitmap[it_haf.first]->energy()*it_haf.second
310  << std::endl;
312  hitlayer,
313  hitmap[it_haf.first]->energy()*it_haf.second);
314  }
315  } // end simHit
316  } // end simCluster
317  } // end caloparticle
318  }
319 }
320 
321 // ------------ method fills 'descriptions' with the allowed parameters for the
322 // module ------------
324  edm::ConfigurationDescriptions& descriptions) {
326  desc.add<int>("debug", 1);
327  desc.add<bool>("filterOnEnergyAndCaloP", false);
328  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
329  desc.add<edm::InputTag>("recHitsEE", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
330  desc.add<edm::InputTag>("recHitsFH", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
331  desc.add<edm::InputTag>("recHitsBH", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
332  descriptions.add("hgcalShowerSeparation", desc);
333 }
334 
335 // define this as a plug-in
size
Write out results.
edm::EDGetTokenT< HGCRecHitCollection > recHitsEE_
T getParameter(std::string const &) const
edm::EDGetTokenT< HGCRecHitCollection > recHitsFH_
std::vector< std::pair< uint32_t, float > > hits_and_fractions() const
Returns list of rechit IDs and fractions for this SimCluster.
Definition: SimCluster.h:210
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
void cd(void)
Definition: DQMStore.cc:269
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< MonitorElement * > globalProfileOnLayer_
#define IfLogTrace(cond, cat)
std::vector< MonitorElement * > idealDeltaXY_
std::vector< MonitorElement * > profileOnLayer_
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:61
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< HGCRecHitCollection > recHitsBH_
Monte Carlo truth information used for tracking validation.
Definition: SimCluster.h:28
T sqrt(T t)
Definition: SSEVec.h:18
edm::EDGetTokenT< std::vector< CaloParticle > > caloParticles_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< MonitorElement * > distanceOnLayer_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float energy() const
Energy. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:111
ParameterDescriptionBase * add(U const &iLabel, T const &value)
float simEnergy() const
returns the accumulated sim energy in the cluster
Definition: SimCluster.h:225
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: DetId.h:18
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
hgcal::RecHitTools recHitTools_
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:176
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
void fillWithRecHits(std::map< DetId, const HGCRecHit * > &, DetId, unsigned int, float, int &, float &)
MonitorElement * layerDistance_
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:77
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void analyze(const edm::Event &, const edm::EventSetup &) override
HLT enums.
std::vector< MonitorElement * > centers_
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
std::vector< MonitorElement * > idealDistanceOnLayer_
T x() const
Definition: PV3DBase.h:62
MonitorElement * showerProfile_
Definition: Run.h:42
HGCalShowerSeparation(const edm::ParameterSet &)