CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalTestHistoClass.cc
Go to the documentation of this file.
1 // File: HcalTestHistoClass.cc
3 // Description: Histogram handling class in HcalTestAnalysis (HcalTest)
5 
9 
10 #include <algorithm>
11 #include <iostream>
12 #include <cmath>
13 
15  nLayers = 0;
16  nHits = 0;
17  nQIE = 0;
18  nTowerQIE = 0;
19  nGroupQIE = 0;
20 }
21 
22 void HcalTestHistoClass::fillLayers(double* edepl, double edepHO, double edepHBHE, double* muxy) {
23  nLayers = 0;
24  layers.resize(nLayersMAX);
25  for (int i = 0; i < 20; i++) {
26  double ed = 0.001 * edepl[i];
27  LogDebug("HcalSim") << "HcalTestHistoClass:: fillLayer: nLayers, ed " << i << " " << ed;
28  if (nLayers < nLayersMAX) {
29  layers[i].e = ed;
30  layers[i].muDist = muxy[i];
31  nLayers++;
32  }
33  }
34 
35  eHO = edepHO;
36  eHBHE = edepHBHE;
37 }
38 
39 void HcalTestHistoClass::fillHits(std::vector<CaloHit>& hitcache) {
40  int nHit = hitcache.size();
41  int hit = 0;
42  int i;
43  std::vector<CaloHit>::iterator itr;
44  std::vector<CaloHit*> lhits(nHit);
45  for (i = 0, itr = hitcache.begin(); itr != hitcache.end(); i++, itr++) {
46  uint32_t unitID = itr->id();
47  int subdet, zside, group, ieta, iphi, lay;
48  HcalTestNumbering::unpackHcalIndex(unitID, subdet, zside, group, ieta, iphi, lay);
49  subdet = itr->det();
50  lay = itr->layer();
51  group = (subdet & 15) << 20;
52  group += ((lay - 1) & 31) << 15;
53  group += (zside & 1) << 14;
54  group += (ieta & 127) << 7;
55  group += (iphi & 127);
56  itr->setId(group);
57  lhits[i] = &hitcache[i];
58  LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Original " << i << " " << hitcache[i];
59  LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Copied " << i << " " << *lhits[i];
60  }
61  sort(lhits.begin(), lhits.end(), CaloHitIdMore());
62  std::vector<CaloHit*>::iterator k1, k2;
63  for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
64  LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Sorted " << i << " " << **k1;
65 
66  hits.resize(lhits.size());
67  for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
68  double ehit = (**k1).e();
69  double jitter = (**k1).t();
70  unsigned int unitID = (**k1).id();
71  int jump = 0;
72  LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Start " << i << " U/T/E 0x" << std::hex << unitID << std::dec
73  << " " << jitter << " " << ehit;
74  for (k2 = k1 + 1;
75  k2 != lhits.end() && (jitter - (**k2).t()) < 1. && (jitter - (**k2).t()) > -1. && unitID == (**k2).id();
76  k2++) {
77  ehit += (**k2).e();
78  LogDebug("HcalSim") << " + " << (**k2).e();
79  jump++;
80  }
81  LogDebug("HcalSim") << " = " << ehit << " in " << jump;
82 
83  float eta = itr->eta();
84  float phi = itr->phi();
85  float t = itr->t();
86  int lay = ((unitID >> 15) & 31) + 1;
87 
88  hits[nHits].layer = lay;
89  hits[nHits].id = unitID;
90  hits[nHits].eta = eta;
91  hits[nHits].phi = phi;
92  hits[nHits].e = ehit;
93  hits[nHits].t = t;
94  hits[nHits].jitter = jitter;
95  nHits++;
96  hit++;
97 
98  int subdet = (unitID >> 20) & 15;
99  int zside = (unitID >> 14) & 1;
100  int ieta = (unitID >> 7) & 127;
101  int iphi = (unitID)&127;
102  LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Hit " << hit << " " << i << " ID 0x" << std::hex << unitID
103  << std::dec << " " << subdet << " " << lay << " " << zside << " " << ieta << " " << iphi
104  << " Time " << jitter << " E " << ehit;
105 
106  i += jump;
107  k1 += jump;
108  }
109 
110  LogDebug("HcalSim") << "HcalTestHistoClass::fillHits called with " << nHit << " hits"
111  << " and writes out " << nHits << '(' << hit << ") hits";
112 }
113 
115  double esimtot,
116  double eqietot,
117  int nGroup,
118  const std::vector<double>& longs,
119  const std::vector<double>& longq,
120  int nTower,
121  const std::vector<double>& latphi,
122  const std::vector<double>& latfs,
123  const std::vector<double>& latfq) {
124  nGroupQIE = 0;
125  nTowerQIE = 0;
126 
127  if (id >= 0 && id < 4) {
128  unsigned int qiesiz = (unsigned int)(id + 1);
129  if (qie.size() < qiesiz) {
130  qie.resize(qiesiz);
131  }
132 
133  qie[id].sim = esimtot;
134  qie[id].qie = eqietot;
135  qie[id].id = id;
136  nQIE++;
137 
138  LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, esimtot, eqietot"
139  << " = " << id << " " << esimtot << " " << eqietot;
140 
141  for (int i = 0; i < nGroup; i++) {
142  LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, nGroupQIE, "
143  << "longs, longq = " << id << " " << nGroupQIE << " " << longs[i] << " " << longq[i];
144  qie[id].lngs.push_back(longs[i]);
145  qie[id].lngq.push_back(longq[i]);
146  nGroupQIE++;
147  }
148 
149  for (int i = 0; i < nTower; i++) {
150  int tow = (int)latphi[i];
151  LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, nTowerQIE, "
152  << "tower, latfs, latfq = " << id << " " << nTowerQIE << " " << tow << " " << latfs[i] << " "
153  << latfq[i];
154  qie[id].lats.push_back(latfs[i]);
155  qie[id].latq.push_back(latfq[i]);
156  qie[id].tow.push_back(tow);
157  nTowerQIE++;
158  }
159  }
160  LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: Called with ID " << id << " nQIE " << nQIE << " nGroup "
161  << nGroupQIE << " nTower " << nTowerQIE;
162 }
void fillQie(int id, double esimtot, double eqietot, int nGroup, const std::vector< double > &longs, const std::vector< double > &longq, int nTower, const std::vector< double > &latphi, const std::vector< double > &latfs, const std::vector< double > &latfq)
uint16_t *__restrict__ id
void fillLayers(double el[], double ho, double hbhe, double muxy[])
void fillHits(std::vector< CaloHit > &)
int zside(DetId const &)
std::vector< Layer > layers
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
tuple group
Definition: watchdog.py:82
static const int nLayersMAX
std::vector< Hit > hits
std::vector< QIE > qie
#define LogDebug(id)