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