CMS 3D CMS Logo

HGCalShowerSeparation.cc
Go to the documentation of this file.
1 // user include files
2 
6 
10 
12 
14 
17 
24 
29 
35 
37 
38 #include <map>
39 #include <array>
40 #include <string>
41 #include <numeric>
42 
44 public:
46  ~HGCalShowerSeparation() override;
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50 private:
51  void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
52  void analyze(const edm::Event&, const edm::EventSetup&) override;
53 
54  void fillWithRecHits(std::unordered_map<DetId, const HGCRecHit*>&, DetId, unsigned int, float, int&, float&);
55 
58 
59  int debug_;
62 
74  std::vector<MonitorElement*> profileOnLayer_;
75  std::vector<MonitorElement*> globalProfileOnLayer_;
76  std::vector<MonitorElement*> distanceOnLayer_;
77  std::vector<MonitorElement*> idealDistanceOnLayer_;
78  std::vector<MonitorElement*> idealDeltaXY_;
79  std::vector<MonitorElement*> centers_;
80 
81  static constexpr int layers_ = 52;
82 };
83 
85  : debug_(iConfig.getParameter<int>("debug")),
86  filterOnEnergyAndCaloP_(iConfig.getParameter<bool>("filterOnEnergyAndCaloP")) {
87  auto hitMapInputTag = iConfig.getParameter<edm::InputTag>("hitMapTag");
88  auto caloParticles = iConfig.getParameter<edm::InputTag>("caloParticles");
89  hitMap_ = consumes<std::unordered_map<DetId, const HGCRecHit*>>(hitMapInputTag);
90  caloParticles_ = consumes<std::vector<CaloParticle>>(caloParticles);
91 }
92 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 }
97 
99  edm::Run const& iRun,
100  edm::EventSetup const& /* iSetup */) {
101  ibooker.cd();
102  ibooker.setCurrentFolder("HGCalShowerSeparation");
103  scEnergy_ = ibooker.book1D("SCEnergy", "SCEnergy", 240, 0., 120.);
104  eta1_ = ibooker.book1D("eta1", "eta1", 80, 0., 4.);
105  eta2_ = ibooker.book1D("eta2", "eta2", 80, 0., 4.);
106  energy1_ = ibooker.book1D("energy1", "energy1", 240, 0., 120.);
107  energy2_ = ibooker.book1D("energy2", "energy2", 240, 0., 120.);
108  energytot_ = ibooker.book1D("energytot", "energytot", 200, 100., 200.);
109  showerProfile_ = ibooker.book2D("ShowerProfile", "ShowerProfile", 800, -400., 400., layers_, 0., (float)layers_);
110  layerEnergy_ = ibooker.book2D("LayerEnergy", "LayerEnergy", 60, 0., 60., 50, 0., 0.1);
111  layerDistance_ = ibooker.book2D("LayerDistance", "LayerDistance", 60, 0., 60., 400, -400., 400.);
112  etaPhi_ = ibooker.book2D("EtaPhi", "EtaPhi", 800, -4., 4., 800, -4., 4.);
113  deltaEtaPhi_ = ibooker.book2D("DeltaEtaPhi", "DeltaEtaPhi", 100, -0.5, 0.5, 100, -0.5, 0.5);
114  for (int i = 0; i < layers_; ++i) {
115  profileOnLayer_.push_back(ibooker.book2D(std::string("ProfileOnLayer_") + std::to_string(i),
116  std::string("ProfileOnLayer_") + std::to_string(i),
117  120,
118  -600.,
119  600.,
120  120,
121  -600.,
122  600.));
123  globalProfileOnLayer_.push_back(ibooker.book2D(std::string("GlobalProfileOnLayer_") + std::to_string(i),
124  std::string("GlobalProfileOnLayer_") + std::to_string(i),
125  320,
126  -160.,
127  160.,
128  320,
129  -160.,
130  160.));
131  distanceOnLayer_.push_back(ibooker.book1D(std::string("DistanceOnLayer_") + std::to_string(i),
132  std::string("DistanceOnLayer_") + std::to_string(i),
133  120,
134  -600.,
135  600.));
136  idealDistanceOnLayer_.push_back(ibooker.book1D(std::string("IdealDistanceOnLayer_") + std::to_string(i),
137  std::string("IdealDistanceOnLayer_") + std::to_string(i),
138  120,
139  -600.,
140  600.));
141  idealDeltaXY_.push_back(ibooker.book2D(std::string("IdealDeltaXY_") + std::to_string(i),
142  std::string("IdealDeltaXY_") + std::to_string(i),
143  800,
144  -400.,
145  400.,
146  800,
147  -400.,
148  400.));
149  centers_.push_back(ibooker.book2D(std::string("Centers_") + std::to_string(i),
150  std::string("Centers_") + std::to_string(i),
151  320,
152  -1600.,
153  1600.,
154  320,
155  -1600.,
156  1600.));
157  }
158 }
159 
161  using namespace edm;
162 
164  iSetup.get<CaloGeometryRecord>().get(geom);
166 
167  Handle<std::vector<CaloParticle>> caloParticleHandle;
168  iEvent.getByToken(caloParticles_, caloParticleHandle);
169  const std::vector<CaloParticle>& caloParticles = *caloParticleHandle;
170 
172  iEvent.getByToken(hitMap_, hitMapHandle);
173  const auto hitmap = *hitMapHandle;
174 
175  // loop over caloParticles
176  IfLogTrace(debug_ > 0, "HGCalShowerSeparation") << "Number of caloParticles: " << caloParticles.size() << std::endl;
177  if (caloParticles.size() == 2) {
178  auto eta1 = caloParticles[0].eta();
179  auto phi1 = caloParticles[0].phi();
180  auto theta1 = 2. * atan(exp(-eta1));
181  auto eta2 = caloParticles[1].eta();
182  auto phi2 = caloParticles[1].phi();
183  auto theta2 = 2. * atan(exp(-eta2));
184  eta1_->Fill(eta1);
185  eta2_->Fill(eta2);
186 
187  // Select event only if the sum of the energy of its recHits
188  // is close enough to the gen energy
189  int count = 0;
190  int size = 0;
191  float energy = 0.;
192  float energy_tmp = 0.;
193  for (const auto& it_caloPart : caloParticles) {
194  count++;
195  const SimClusterRefVector& simClusterRefVector = it_caloPart.simClusters();
196  size += simClusterRefVector.size();
197  for (const auto& it_sc : simClusterRefVector) {
198  const SimCluster& simCluster = (*(it_sc));
199  const std::vector<std::pair<uint32_t, float>>& hits_and_fractions = simCluster.hits_and_fractions();
200  for (const auto& it_haf : hits_and_fractions) {
201  if (hitmap.count(it_haf.first))
202  energy += hitmap.at(it_haf.first)->energy() * it_haf.second;
203  } //hits and fractions
204  } // simcluster
205  if (count == 1) {
206  energy1_->Fill(energy);
207  energy_tmp = energy;
208  } else {
209  energy2_->Fill(energy - energy_tmp);
210  }
211  } // caloParticle
213  if (filterOnEnergyAndCaloP_ && (energy < 2. * 0.8 * 80 or size != 2))
214  return;
215 
216  deltaEtaPhi_->Fill(eta1 - eta2, phi1 - phi2);
217 
218  for (const auto& it_caloPart : caloParticles) {
219  const SimClusterRefVector& simClusterRefVector = it_caloPart.simClusters();
220  IfLogTrace(debug_ > 0, "HGCalShowerSeparation") << ">>> " << simClusterRefVector.size() << std::endl;
221  for (const auto& it_sc : simClusterRefVector) {
222  const SimCluster& simCluster = (*(it_sc));
223  if (simCluster.energy() < 80 * 0.8)
224  continue;
225  scEnergy_->Fill(simCluster.energy());
226  IfLogTrace(debug_ > 1, "HGCalShowerSeparation")
227  << ">>> SC.energy(): " << simCluster.energy() << " SC.simEnergy(): " << simCluster.simEnergy() << std::endl;
228  const std::vector<std::pair<uint32_t, float>>& hits_and_fractions = simCluster.hits_and_fractions();
229 
230  for (const auto& it_haf : hits_and_fractions) {
231  if (!hitmap.count(it_haf.first))
232  continue;
233  unsigned int hitlayer = recHitTools_.getLayerWithOffset(it_haf.first);
234  auto global = recHitTools_.getPosition(it_haf.first);
235  float globalx = global.x();
236  float globaly = global.y();
237  float globalz = global.z();
238  if (globalz == 0)
239  continue;
240  auto rho1 = globalz * tan(theta1);
241  auto rho2 = globalz * tan(theta2);
242  auto x1 = rho1 * cos(phi1);
243  auto y1 = rho1 * sin(phi1);
244  auto x2 = rho2 * cos(phi2);
245  auto y2 = rho2 * sin(phi2);
246  auto half_point_x = (x1 + x2) / 2.;
247  auto half_point_y = (y1 + y2) / 2.;
248  auto half_point = sqrt((x1 - half_point_x) * (x1 - half_point_x) + (y1 - half_point_y) * (y1 - half_point_y));
249  auto d_len = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
250  auto dn_x = (x2 - x1) / d_len;
251  auto dn_y = (y2 - y1) / d_len;
252  auto distance = (globalx - x1) * dn_x + (globaly - y1) * dn_y;
253  distance -= half_point;
254  auto idealDistance = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
255  if (hitmap.count(it_haf.first)) {
256  profileOnLayer_[hitlayer]->Fill(10. * (globalx - half_point_x),
257  10. * (globaly - half_point_y),
258  hitmap.at(it_haf.first)->energy() * it_haf.second);
259  profileOnLayer_[55]->Fill(10. * (globalx - half_point_x),
260  10. * (globaly - half_point_y),
261  hitmap.at(it_haf.first)->energy() * it_haf.second);
262  globalProfileOnLayer_[hitlayer]->Fill(globalx, globaly, hitmap.at(it_haf.first)->energy() * it_haf.second);
263  globalProfileOnLayer_[55]->Fill(globalx, globaly, hitmap.at(it_haf.first)->energy() * it_haf.second);
264  layerEnergy_->Fill(hitlayer, hitmap.at(it_haf.first)->energy());
265  layerDistance_->Fill(hitlayer, std::abs(10. * distance), hitmap.at(it_haf.first)->energy() * it_haf.second);
266  etaPhi_->Fill(global.eta(), global.phi());
267  distanceOnLayer_[hitlayer]->Fill(10. * distance); //,
268  idealDistanceOnLayer_[hitlayer]->Fill(10. * idealDistance); //,
269  idealDeltaXY_[hitlayer]->Fill(10. * (x1 - x2), 10. * (y1 - y2)); //,
270  centers_[hitlayer]->Fill(10. * half_point_x, 10. * half_point_y); //,
271  IfLogTrace(debug_ > 0, "HGCalShowerSeparation")
272  << ">>> " << distance << " " << hitlayer << " " << hitmap.at(it_haf.first)->energy() * it_haf.second
273  << std::endl;
274  showerProfile_->Fill(10. * distance, hitlayer, hitmap.at(it_haf.first)->energy() * it_haf.second);
275  }
276  } // end simHit
277  } // end simCluster
278  } // end caloparticle
279  }
280 }
281 
282 // ------------ method fills 'descriptions' with the allowed parameters for the
283 // module ------------
286  desc.add<int>("debug", 1);
287  desc.add<bool>("filterOnEnergyAndCaloP", false);
288  desc.add<edm::InputTag>("caloParticles", edm::InputTag("mix", "MergedCaloTruth"));
289  desc.add<edm::InputTag>("hitMapTag", edm::InputTag("hgcalRecHitMapProducer"));
290  descriptions.add("hgcalShowerSeparationDefault", desc);
291 }
292 
293 // define this as a plug-in
HGCalShowerSeparation::energy1_
MonitorElement * energy1_
Definition: HGCalShowerSeparation.cc:65
dqm::impl::MonitorElement
Definition: MonitorElement.h:98
hgcal::RecHitTools
Definition: RecHitTools.h:23
electrons_cff.bool
bool
Definition: electrons_cff.py:366
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
ESHandle.h
HGCalShowerSeparation::showerProfile_
MonitorElement * showerProfile_
Definition: HGCalShowerSeparation.cc:69
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
CaloGeometryRecord
Definition: CaloGeometryRecord.h:30
HGCalShowerSeparation::idealDeltaXY_
std::vector< MonitorElement * > idealDeltaXY_
Definition: HGCalShowerSeparation.cc:78
edm
HLT enums.
Definition: AlignableModifier.h:19
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
RecHitTools.h
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
HGCalShowerSeparation::distanceOnLayer_
std::vector< MonitorElement * > distanceOnLayer_
Definition: HGCalShowerSeparation.cc:76
HGCalShowerSeparation::centers_
std::vector< MonitorElement * > centers_
Definition: HGCalShowerSeparation.cc:79
DQMStore.h
TrackingVertex.h
edm::RefVector< SimClusterCollection >
SimCluster::energy
float energy() const
Energy. Note this is taken from the first SimTrack only.
Definition: SimCluster.h:104
SimCluster
Monte Carlo truth information used for tracking validation.
Definition: SimCluster.h:29
HGCalShowerSeparation::hitMap_
edm::EDGetTokenT< std::unordered_map< DetId, const HGCRecHit * > > hitMap_
Definition: HGCalShowerSeparation.cc:56
edm::Handle
Definition: AssociativeIterator.h:50
HGCalShowerSeparation::filterOnEnergyAndCaloP_
bool filterOnEnergyAndCaloP_
Definition: HGCalShowerSeparation.cc:60
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DetId
Definition: DetId.h:17
MakerMacros.h
Photon.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
SimCluster.h
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HGCalShowerSeparation::caloParticles_
edm::EDGetTokenT< std::vector< CaloParticle > > caloParticles_
Definition: HGCalShowerSeparation.cc:57
TruncatedPyramid.h
caloTruthCellsProducer_cfi.caloParticles
caloParticles
Definition: caloTruthCellsProducer_cfi.py:6
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
HLT_FULL_cff.eta2
eta2
Definition: HLT_FULL_cff.py:9542
edm::ESHandle< CaloGeometry >
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
PFCluster.h
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
CaloClusterFwd.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
HGCalShowerSeparation::layerDistance_
MonitorElement * layerDistance_
Definition: HGCalShowerSeparation.cc:71
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
IfLogTrace
#define IfLogTrace(cond, cat)
Definition: MessageLogger.h:260
HGCalShowerSeparation::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HGCalShowerSeparation.cc:284
GsfElectron.h
HGCalShowerSeparation::layers_
static constexpr int layers_
Definition: HGCalShowerSeparation.cc:81
HGCalShowerSeparation
Definition: HGCalShowerSeparation.cc:43
HGCalShowerSeparation::energytot_
MonitorElement * energytot_
Definition: HGCalShowerSeparation.cc:67
DQMEDAnalyzer.h
CaloGeometryRecord.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.eta1
eta1
Definition: HLT_FULL_cff.py:9541
DQMEDAnalyzer
Definition: DQMEDAnalyzer.py:1
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
CaloSubdetectorGeometry.h
HGCRecHitCollections.h
HGCalGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
hgcal::RecHitTools::getLayerWithOffset
unsigned int getLayerWithOffset(const DetId &) const
Definition: RecHitTools.cc:352
HcalDetId.h
CaloParticle.h
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
HGCalShowerSeparation::recHitTools_
hgcal::RecHitTools recHitTools_
Definition: HGCalShowerSeparation.cc:61
HGCalShowerSeparation::~HGCalShowerSeparation
~HGCalShowerSeparation() override
Definition: HGCalShowerSeparation.cc:93
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
HGCalShowerSeparation::profileOnLayer_
std::vector< MonitorElement * > profileOnLayer_
Definition: HGCalShowerSeparation.cc:74
edm::EventSetup
Definition: EventSetup.h:58
HGCalShowerSeparation::deltaEtaPhi_
MonitorElement * deltaEtaPhi_
Definition: HGCalShowerSeparation.cc:73
HGCalShowerSeparation::layerEnergy_
MonitorElement * layerEnergy_
Definition: HGCalShowerSeparation.cc:70
get
#define get
HGCalShowerSeparation::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HGCalShowerSeparation.cc:160
HGCalShowerSeparation::eta2_
MonitorElement * eta2_
Definition: HGCalShowerSeparation.cc:64
TrackingParticle.h
CaloCellGeometry.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
HGCalDetId.h
HGCalShowerSeparation::scEnergy_
MonitorElement * scEnergy_
Definition: HGCalShowerSeparation.cc:68
SimCluster::simEnergy
float simEnergy() const
returns the accumulated sim energy in the cluster
Definition: SimCluster.h:213
Frameworkfwd.h
hgcal::RecHitTools::setGeometry
void setGeometry(CaloGeometry const &)
Definition: RecHitTools.cc:68
dqm::implementation::IBooker::book2D
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
HGCalShowerSeparation::etaPhi_
MonitorElement * etaPhi_
Definition: HGCalShowerSeparation.cc:72
CaloGeometry.h
or
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
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HGCalShowerSeparation::idealDistanceOnLayer_
std::vector< MonitorElement * > idealDistanceOnLayer_
Definition: HGCalShowerSeparation.cc:77
HGCalShowerSeparation::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: HGCalShowerSeparation.cc:98
dqm::implementation::IBooker
Definition: DQMStore.h:43
HGCalShowerSeparation::energy2_
MonitorElement * energy2_
Definition: HGCalShowerSeparation.cc:66
HGCalShowerSeparation::HGCalShowerSeparation
HGCalShowerSeparation(const edm::ParameterSet &)
Definition: HGCalShowerSeparation.cc:84
SimCluster::hits_and_fractions
std::vector< std::pair< uint32_t, float > > hits_and_fractions() const
Returns list of rechit IDs and fractions for this SimCluster.
Definition: SimCluster.h:184
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
HGCalShowerSeparation::eta1_
MonitorElement * eta1_
Definition: HGCalShowerSeparation.cc:63
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
edm::Event
Definition: Event.h:73
hgcal::RecHitTools::getPosition
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:126
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
edm::InputTag
Definition: InputTag.h:15
HGCalShowerSeparation::fillWithRecHits
void fillWithRecHits(std::unordered_map< DetId, const HGCRecHit * > &, DetId, unsigned int, float, int &, float &)
HGCalShowerSeparation::globalProfileOnLayer_
std::vector< MonitorElement * > globalProfileOnLayer_
Definition: HGCalShowerSeparation.cc:75
HGCalShowerSeparation::debug_
int debug_
Definition: HGCalShowerSeparation.cc:59
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443