Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:31:14

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: HcalTestHistoClass.cc
0003 // Description: Histogram handling class in HcalTestAnalysis (HcalTest)
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include "SimDataFormats/CaloTest/interface/HcalTestHistoClass.h"
0007 #include "DataFormats/HcalDetId/interface/HcalTestNumbering.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 #include <algorithm>
0011 #include <iostream>
0012 #include <cmath>
0013 
0014 void HcalTestHistoClass::setCounters() {
0015   nLayers = 0;
0016   nHits = 0;
0017   nQIE = 0;
0018   nTowerQIE = 0;
0019   nGroupQIE = 0;
0020 }
0021 
0022 void HcalTestHistoClass::fillLayers(double* edepl, double edepHO, double edepHBHE, double* muxy) {
0023   nLayers = 0;
0024   layers.resize(nLayersMAX);
0025   for (int i = 0; i < 20; i++) {
0026     double ed = 0.001 * edepl[i];
0027     LogDebug("HcalSim") << "HcalTestHistoClass:: fillLayer: nLayers, ed " << i << " " << ed;
0028     if (nLayers < nLayersMAX) {
0029       layers[i].e = ed;
0030       layers[i].muDist = muxy[i];
0031       nLayers++;
0032     }
0033   }
0034 
0035   eHO = edepHO;
0036   eHBHE = edepHBHE;
0037 }
0038 
0039 void HcalTestHistoClass::fillHits(std::vector<CaloHit>& hitcache) {
0040   int nHit = hitcache.size();
0041   int hit = 0;
0042   int i;
0043   std::vector<CaloHit>::iterator itr;
0044   std::vector<CaloHit*> lhits(nHit);
0045   for (i = 0, itr = hitcache.begin(); itr != hitcache.end(); i++, itr++) {
0046     uint32_t unitID = itr->id();
0047     int subdet, zside, group, ieta, iphi, lay;
0048     HcalTestNumbering::unpackHcalIndex(unitID, subdet, zside, group, ieta, iphi, lay);
0049     subdet = itr->det();
0050     lay = itr->layer();
0051     group = (subdet & 15) << 20;
0052     group += ((lay - 1) & 31) << 15;
0053     group += (zside & 1) << 14;
0054     group += (ieta & 127) << 7;
0055     group += (iphi & 127);
0056     itr->setId(group);
0057     lhits[i] = &hitcache[i];
0058     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Original " << i << " " << hitcache[i];
0059     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Copied   " << i << " " << *lhits[i];
0060   }
0061   sort(lhits.begin(), lhits.end(), CaloHitIdMore());
0062   std::vector<CaloHit*>::iterator k1, k2;
0063   for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
0064     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Sorted " << i << " " << **k1;
0065 
0066   hits.resize(lhits.size());
0067   for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
0068     double ehit = (**k1).e();
0069     double jitter = (**k1).t();
0070     unsigned int unitID = (**k1).id();
0071     int jump = 0;
0072     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Start " << i << " U/T/E 0x" << std::hex << unitID << std::dec
0073                         << " " << jitter << " " << ehit;
0074     for (k2 = k1 + 1;
0075          k2 != lhits.end() && (jitter - (**k2).t()) < 1. && (jitter - (**k2).t()) > -1. && unitID == (**k2).id();
0076          k2++) {
0077       ehit += (**k2).e();
0078       LogDebug("HcalSim") << " + " << (**k2).e();
0079       jump++;
0080     }
0081     LogDebug("HcalSim") << " = " << ehit << " in " << jump;
0082 
0083     float eta = itr->eta();
0084     float phi = itr->phi();
0085     float t = itr->t();
0086     int lay = ((unitID >> 15) & 31) + 1;
0087 
0088     hits[nHits].layer = lay;
0089     hits[nHits].id = unitID;
0090     hits[nHits].eta = eta;
0091     hits[nHits].phi = phi;
0092     hits[nHits].e = ehit;
0093     hits[nHits].t = t;
0094     hits[nHits].jitter = jitter;
0095     nHits++;
0096     hit++;
0097 
0098     int subdet = (unitID >> 20) & 15;
0099     int zside = (unitID >> 14) & 1;
0100     int ieta = (unitID >> 7) & 127;
0101     int iphi = (unitID)&127;
0102     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Hit " << hit << " " << i << " ID 0x" << std::hex << unitID
0103                         << std::dec << " " << subdet << " " << lay << " " << zside << " " << ieta << " " << iphi
0104                         << " Time " << jitter << " E " << ehit;
0105 
0106     i += jump;
0107     k1 += jump;
0108   }
0109 
0110   LogDebug("HcalSim") << "HcalTestHistoClass::fillHits called with " << nHit << " hits"
0111                       << " and writes out " << nHits << '(' << hit << ") hits";
0112 }
0113 
0114 void HcalTestHistoClass::fillQie(int id,
0115                                  double esimtot,
0116                                  double eqietot,
0117                                  int nGroup,
0118                                  const std::vector<double>& longs,
0119                                  const std::vector<double>& longq,
0120                                  int nTower,
0121                                  const std::vector<double>& latphi,
0122                                  const std::vector<double>& latfs,
0123                                  const std::vector<double>& latfq) {
0124   nGroupQIE = 0;
0125   nTowerQIE = 0;
0126 
0127   if (id >= 0 && id < 4) {
0128     unsigned int qiesiz = (unsigned int)(id + 1);
0129     if (qie.size() < qiesiz) {
0130       qie.resize(qiesiz);
0131     }
0132 
0133     qie[id].sim = esimtot;
0134     qie[id].qie = eqietot;
0135     qie[id].id = id;
0136     nQIE++;
0137 
0138     LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, esimtot, eqietot"
0139                         << " = " << id << " " << esimtot << " " << eqietot;
0140 
0141     for (int i = 0; i < nGroup; i++) {
0142       LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, nGroupQIE, "
0143                           << "longs, longq = " << id << " " << nGroupQIE << " " << longs[i] << " " << longq[i];
0144       qie[id].lngs.push_back(longs[i]);
0145       qie[id].lngq.push_back(longq[i]);
0146       nGroupQIE++;
0147     }
0148 
0149     for (int i = 0; i < nTower; i++) {
0150       int tow = (int)latphi[i];
0151       LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, nTowerQIE, "
0152                           << "tower, latfs, latfq = " << id << " " << nTowerQIE << " " << tow << " " << latfs[i] << " "
0153                           << latfq[i];
0154       qie[id].lats.push_back(latfs[i]);
0155       qie[id].latq.push_back(latfq[i]);
0156       qie[id].tow.push_back(tow);
0157       nTowerQIE++;
0158     }
0159   }
0160   LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: Called with ID " << id << " nQIE " << nQIE << " nGroup "
0161                       << nGroupQIE << " nTower " << nTowerQIE;
0162 }