CMS 3D CMS Logo

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