CMS 3D CMS Logo

PiZeroTask.cc
Go to the documentation of this file.
2 
3 namespace ecaldqm {
5  : DQWorkerTask(),
6  seleXtalMinEnergy_(0.f),
7  clusSeedThr_(0.f),
8  clusEtaSize_(0),
9  clusPhiSize_(0),
10  selePtGammaOne_(0.f),
11  selePtGammaTwo_(0.f),
12  seleS4S9GammaOne_(0.f),
13  seleS4S9GammaTwo_(0.f),
14  selePtPi0_(0.f),
15  selePi0Iso_(0.f),
16  selePi0BeltDR_(0.f),
17  selePi0BeltDeta_(0.f),
18  seleMinvMaxPi0_(0.f),
19  seleMinvMinPi0_(0.f),
20  posCalcParameters_(edm::ParameterSet()) {}
21 
23  // Parameters needed for pi0 finding
24  seleXtalMinEnergy_ = params.getParameter<double>("seleXtalMinEnergy");
25 
26  clusSeedThr_ = params.getParameter<double>("clusSeedThr");
27  clusEtaSize_ = params.getParameter<int>("clusEtaSize");
28  clusPhiSize_ = params.getParameter<int>("clusPhiSize");
29 
30  selePtGammaOne_ = params.getParameter<double>("selePtGammaOne");
31  selePtGammaTwo_ = params.getParameter<double>("selePtGammaTwo");
32  seleS4S9GammaOne_ = params.getParameter<double>("seleS4S9GammaOne");
33  seleS4S9GammaTwo_ = params.getParameter<double>("seleS4S9GammaTwo");
34  selePtPi0_ = params.getParameter<double>("selePtPi0");
35  selePi0Iso_ = params.getParameter<double>("selePi0Iso");
36  selePi0BeltDR_ = params.getParameter<double>("selePi0BeltDR");
37  selePi0BeltDeta_ = params.getParameter<double>("selePi0BeltDeta");
38  seleMinvMaxPi0_ = params.getParameter<double>("seleMinvMaxPi0");
39  seleMinvMinPi0_ = params.getParameter<double>("seleMinvMinPi0");
40 
41  posCalcParameters_ = params.getParameter<edm::ParameterSet>("posCalcParameters");
42  }
43 
44  bool PiZeroTask::filterRunType(short const* runType) {
45  for (unsigned iFED(0); iFED != ecaldqm::nDCC; iFED++) {
49  return true;
50  }
51 
52  return false;
53  }
54 
56  MESet& mePi0MinvEB(MEs_.at("Pi0MinvEB"));
57  MESet& mePi0Pt1EB(MEs_.at("Pi0Pt1EB"));
58  MESet& mePi0Pt2EB(MEs_.at("Pi0Pt2EB"));
59  MESet& mePi0PtEB(MEs_.at("Pi0PtEB"));
60  MESet& mePi0IsoEB(MEs_.at("Pi0IsoEB"));
61 
62  const CaloSubdetectorTopology* topology_p;
65 
66  // Parameters for the position calculation:
68 
69  std::map<DetId, EcalRecHit> recHitsEB_map;
70 
71  std::vector<EcalRecHit> seeds;
72  std::vector<EBDetId> usedXtals;
73  seeds.clear();
74  usedXtals.clear();
75 
76  int nClus = 0;
77  std::vector<float> eClus;
78  std::vector<float> etClus;
79  std::vector<float> etaClus;
80  std::vector<float> phiClus;
81  std::vector<EBDetId> max_hit;
82  std::vector<std::vector<EcalRecHit> > RecHitsCluster;
83  std::vector<float> s4s9Clus;
84 
85  // Find cluster seeds in EB
86  for (auto const& hit : hits) {
87  EBDetId id(hit.id());
88  double energy = hit.energy();
89  if (energy > seleXtalMinEnergy_) {
90  std::pair<DetId, EcalRecHit> map_entry(hit.id(), hit);
91  recHitsEB_map.insert(map_entry);
92  }
93  if (energy > clusSeedThr_)
94  seeds.push_back(hit);
95  } // EB rechits
96 
97  sort(seeds.begin(), seeds.end(), [](auto& x, auto& y) { return (x.energy() > y.energy()); });
98  for (auto const& seed : seeds) {
99  EBDetId seed_id = seed.id();
100 
101  bool seedAlreadyUsed = false;
102  for (auto const& usedIds : usedXtals) {
103  if (usedIds == seed_id) {
104  seedAlreadyUsed = true;
105  break;
106  }
107  }
108  if (seedAlreadyUsed)
109  continue;
111  std::vector<DetId> clus_v = topology_p->getWindow(seed_id, clusEtaSize_, clusPhiSize_);
112  std::vector<std::pair<DetId, float> > clus_used;
113 
114  std::vector<EcalRecHit> RecHitsInWindow;
115 
116  double simple_energy = 0;
117 
118  for (auto const& det : clus_v) {
119  bool HitAlreadyUsed = false;
120  for (auto const& usedIds : usedXtals) {
121  if (usedIds == det) {
122  HitAlreadyUsed = true;
123  break;
124  }
125  }
126  if (HitAlreadyUsed)
127  continue;
128  if (recHitsEB_map.find(det) != recHitsEB_map.end()) {
129  std::map<DetId, EcalRecHit>::iterator aHit;
130  aHit = recHitsEB_map.find(det);
131  usedXtals.push_back(det);
132  RecHitsInWindow.push_back(aHit->second);
133  clus_used.push_back(std::pair<DetId, float>(det, 1.));
134  simple_energy = simple_energy + aHit->second.energy();
135  }
136  }
137 
138  math::XYZPoint clus_pos = posCalculator_.Calculate_Location(clus_used, &hits, geometry_p, geometryES_p);
139  float theta_s = 2. * atan(exp(-clus_pos.eta()));
140  float p0x_s = simple_energy * sin(theta_s) * cos(clus_pos.phi());
141  float p0y_s = simple_energy * sin(theta_s) * sin(clus_pos.phi());
142  float et_s = sqrt(p0x_s * p0x_s + p0y_s * p0y_s);
143 
144  eClus.push_back(simple_energy);
145  etClus.push_back(et_s);
146  etaClus.push_back(clus_pos.eta());
147  phiClus.push_back(clus_pos.phi());
148  max_hit.push_back(seed_id);
149  RecHitsCluster.push_back(RecHitsInWindow);
150 
151  // Compute S4/S9 variable
152  // We are not sure to have 9 RecHits so need to check eta and phi:
153  float s4s9_[4];
154  for (int i = 0; i < 4; i++)
155  s4s9_[i] = seed.energy();
156  for (unsigned int j = 0; j < RecHitsInWindow.size(); j++) {
157  if ((((EBDetId)RecHitsInWindow[j].id()).ieta() == seed_id.ieta() - 1 && seed_id.ieta() != 1) ||
158  (seed_id.ieta() == 1 && (((EBDetId)RecHitsInWindow[j].id()).ieta() == seed_id.ieta() - 2))) {
159  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi() - 1 ||
160  ((EBDetId)RecHitsInWindow[j].id()).iphi() - 360 == seed_id.iphi() - 1) {
161  s4s9_[0] += RecHitsInWindow[j].energy();
162  } else {
163  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()) {
164  s4s9_[0] += RecHitsInWindow[j].energy();
165  s4s9_[1] += RecHitsInWindow[j].energy();
166  } else {
167  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi() + 1 ||
168  ((EBDetId)RecHitsInWindow[j].id()).iphi() - 360 == seed_id.iphi() + 1) {
169  s4s9_[1] += RecHitsInWindow[j].energy();
170  }
171  }
172  }
173  } else {
174  if (((EBDetId)RecHitsInWindow[j].id()).ieta() == seed_id.ieta()) {
175  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi() - 1 ||
176  ((EBDetId)RecHitsInWindow[j].id()).iphi() - 360 == seed_id.iphi() - 1) {
177  s4s9_[0] += RecHitsInWindow[j].energy();
178  s4s9_[3] += RecHitsInWindow[j].energy();
179  } else {
180  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi() + 1 ||
181  ((EBDetId)RecHitsInWindow[j].id()).iphi() - 360 == seed_id.iphi() + 1) {
182  s4s9_[1] += RecHitsInWindow[j].energy();
183  s4s9_[2] += RecHitsInWindow[j].energy();
184  }
185  }
186  } else {
187  if ((((EBDetId)RecHitsInWindow[j].id()).ieta() == seed_id.ieta() + 1 && seed_id.ieta() != -1) ||
188  (seed_id.ieta() == -1 && (((EBDetId)RecHitsInWindow[j].id()).ieta() == seed_id.ieta() + 2))) {
189  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi() - 1 ||
190  ((EBDetId)RecHitsInWindow[j].id()).iphi() - 360 == seed_id.iphi() - 1) {
191  s4s9_[3] += RecHitsInWindow[j].energy();
192  } else {
193  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi()) {
194  s4s9_[2] += RecHitsInWindow[j].energy();
195  s4s9_[3] += RecHitsInWindow[j].energy();
196  } else {
197  if (((EBDetId)RecHitsInWindow[j].id()).iphi() == seed_id.iphi() + 1 ||
198  ((EBDetId)RecHitsInWindow[j].id()).iphi() - 360 == seed_id.iphi() + 1) {
199  s4s9_[2] += RecHitsInWindow[j].energy();
200  }
201  }
202  }
203  } else {
204  edm::LogWarning("EcalDQM") << " (EBDetId)RecHitsInWindow[j].id()).ieta() "
205  << ((EBDetId)RecHitsInWindow[j].id()).ieta() << " seed_id.ieta() "
206  << seed_id.ieta() << "\n"
207  << " Problem with S4 calculation\n";
208  return;
209  }
210  }
211  }
212  }
213  s4s9Clus.push_back(*std::max_element(s4s9_, s4s9_ + 4) / simple_energy);
214  nClus++;
215  if (nClus == MAXCLUS)
216  return;
217  } // End loop over seed clusters
218 
219  // Selection, based on simple clustering
220  // pi0 candidates
221  int npi0_s = 0;
222 
223  std::vector<EBDetId> scXtals;
224  scXtals.clear();
225 
226  if (nClus <= 1)
227  return;
228  for (Int_t i = 0; i < nClus; i++) {
229  for (Int_t j = i + 1; j < nClus; j++) {
230  if (etClus[i] > selePtGammaOne_ && etClus[j] > selePtGammaTwo_ && s4s9Clus[i] > seleS4S9GammaOne_ &&
231  s4s9Clus[j] > seleS4S9GammaTwo_) {
232  float theta_0 = 2. * atan(exp(-etaClus[i]));
233  float theta_1 = 2. * atan(exp(-etaClus[j]));
234 
235  float p0x = eClus[i] * sin(theta_0) * cos(phiClus[i]);
236  float p1x = eClus[j] * sin(theta_1) * cos(phiClus[j]);
237  float p0y = eClus[i] * sin(theta_0) * sin(phiClus[i]);
238  float p1y = eClus[j] * sin(theta_1) * sin(phiClus[j]);
239  float p0z = eClus[i] * cos(theta_0);
240  float p1z = eClus[j] * cos(theta_1);
241 
242  float pt_pi0 = sqrt((p0x + p1x) * (p0x + p1x) + (p0y + p1y) * (p0y + p1y));
243  if (pt_pi0 < selePtPi0_)
244  continue;
245  float m_inv = sqrt((eClus[i] + eClus[j]) * (eClus[i] + eClus[j]) - (p0x + p1x) * (p0x + p1x) -
246  (p0y + p1y) * (p0y + p1y) - (p0z + p1z) * (p0z + p1z));
247  if ((m_inv < seleMinvMaxPi0_) && (m_inv > seleMinvMinPi0_)) {
248  // New Loop on cluster to measure isolation:
249  std::vector<int> IsoClus;
250  IsoClus.clear();
251  float Iso = 0;
252  TVector3 pi0vect = TVector3((p0x + p1x), (p0y + p1y), (p0z + p1z));
253  for (Int_t k = 0; k < nClus; k++) {
254  if (k == i || k == j)
255  continue;
256  TVector3 Clusvect = TVector3(eClus[k] * sin(2. * atan(exp(-etaClus[k]))) * cos(phiClus[k]),
257  eClus[k] * sin(2. * atan(exp(-etaClus[k]))) * sin(phiClus[k]),
258  eClus[k] * cos(2. * atan(exp(-etaClus[k]))));
259  float dretaclpi0 = fabs(etaClus[k] - pi0vect.Eta());
260  float drclpi0 = Clusvect.DeltaR(pi0vect);
261 
262  if ((drclpi0 < selePi0BeltDR_) && (dretaclpi0 < selePi0BeltDeta_)) {
263  Iso = Iso + etClus[k];
264  IsoClus.push_back(k);
265  }
266  }
267 
268  if (Iso / pt_pi0 < selePi0Iso_) {
269  mePi0MinvEB.fill(getEcalDQMSetupObjects(), m_inv);
270  mePi0Pt1EB.fill(getEcalDQMSetupObjects(), etClus[i]);
271  mePi0Pt2EB.fill(getEcalDQMSetupObjects(), etClus[j]);
272  mePi0PtEB.fill(getEcalDQMSetupObjects(), pt_pi0);
273  mePi0IsoEB.fill(getEcalDQMSetupObjects(), Iso / pt_pi0);
274 
275  npi0_s++;
276  }
277 
278  if (npi0_s == MAXPI0S)
279  return;
280  } // pi0 inv mass window
281  } // pt and S4S9 cut
282  } // cluster "j" index loop
283  } // cluster "i" index loop
284  } // runonEBRecHits()
285 
287 } // namespace ecaldqm
double selePtGammaOne_
Definition: PiZeroTask.h:39
double selePtGammaTwo_
Definition: PiZeroTask.h:40
#define DEFINE_ECALDQM_WORKER(TYPE)
Definition: DQWorker.h:168
bool filterRunType(short const *) override
Definition: PiZeroTask.cc:44
void setParams(edm::ParameterSet const &) override
Definition: PiZeroTask.cc:22
MESet & at(const std::string &key)
Definition: MESet.h:399
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
double selePi0BeltDeta_
Definition: PiZeroTask.h:46
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
edm::ParameterSet posCalcParameters_
Definition: PiZeroTask.h:50
CaloTopology const * GetTopology()
Definition: DQWorker.cc:165
CaloGeometry const * GetGeometry()
Definition: DQWorker.cc:160
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
void runOnEBRecHits(EcalRecHitCollection const &)
Definition: PiZeroTask.cc:55
static const int MAXPI0S
Definition: PiZeroTask.h:30
double seleS4S9GammaOne_
Definition: PiZeroTask.h:41
T sqrt(T t)
Definition: SSEVec.h:19
double seleXtalMinEnergy_
Definition: PiZeroTask.h:33
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
math::XYZPoint Calculate_Location(const HitsAndFractions &iDetIds, const edm::SortedCollection< HitType > *iRecHits, const CaloSubdetectorGeometry *iSubGeom, const CaloSubdetectorGeometry *iESGeom=nullptr)
Definition: PositionCalc.h:65
double f[11][100]
virtual std::vector< DetId > getWindow(const DetId &id, const int &northSouthSize, const int &eastWestSize) const
unsigned int id
EcalDQMSetupObjects const getEcalDQMSetupObjects()
Definition: DQWorker.cc:170
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:17
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
MESetCollection MEs_
Definition: DQWorker.h:131
static const int MAXCLUS
Definition: PiZeroTask.h:29
double seleMinvMinPi0_
Definition: PiZeroTask.h:48
HLT enums.
double seleMinvMaxPi0_
Definition: PiZeroTask.h:47
float x
Log< level::Warning, false > LogWarning
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
double seleS4S9GammaTwo_
Definition: PiZeroTask.h:42