CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/SimDataFormats/CaloTest/src/HcalTestHistoClass.cc

Go to the documentation of this file.
00001 
00002 // File: HcalTestHistoClass.cc
00003 // Description: Histogram handling class in HcalTestAnalysis (HcalTest)
00005 
00006 #include "SimDataFormats/CaloTest/interface/HcalTestHistoClass.h"
00007 #include "SimDataFormats/CaloTest/interface/HcalTestNumbering.h"
00008 
00009 #include <algorithm>
00010 #include <iostream>
00011 #include <cmath>
00012 
00013 void HcalTestHistoClass::setCounters(){
00014   nLayers   = 0;
00015   nHits     = 0;
00016   nQIE      = 0;
00017   nTowerQIE = 0;
00018   nGroupQIE = 0;
00019 }
00020 
00021 void HcalTestHistoClass::fillLayers(double* edepl, double edepHO,
00022                                     double edepHBHE, double* muxy) {
00023 
00024   nLayers = 0;
00025   layers.resize(nLayersMAX);
00026   for (int i = 0; i < 20; i++) {
00027     double ed  = 0.001*edepl[i];
00028     LogDebug("HcalSim") << "HcalTestHistoClass:: fillLayer: nLayers, ed " << i 
00029                         << " "  << ed;
00030     if (nLayers < nLayersMAX) {
00031       layers[i].e = ed;
00032       layers[i].muDist = muxy[i];
00033       nLayers++;
00034     }
00035   }
00036 
00037   eHO   = edepHO;
00038   eHBHE = edepHBHE;
00039 }
00040 
00041 void HcalTestHistoClass::fillHits(std::vector<CaloHit> hitcache) {
00042 
00043   int nHit = hitcache.size();
00044   int hit  = 0;
00045   int i;
00046   std::vector<CaloHit>::iterator itr;
00047   std::vector<CaloHit*> lhits(nHit);
00048   for (i = 0, itr = hitcache.begin(); itr != hitcache.end(); i++, itr++) {
00049     uint32_t unitID=itr->id();
00050     int   subdet, zside, group, ieta, iphi, lay;
00051     HcalTestNumbering::unpackHcalIndex(unitID, subdet, zside, group,
00052                                        ieta, iphi, lay);
00053     subdet = itr->det();
00054     lay    = itr->layer();
00055     group  = (subdet&15)<<20;
00056     group += ((lay-1)&31)<<15;
00057     group += (zside&1)<<14;
00058     group += (ieta&127)<<7;
00059     group += (iphi&127);
00060     itr->setId(group);
00061     lhits[i] = &hitcache[i];
00062     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Original " << i 
00063                         << " " << hitcache[i];
00064     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Copied   " << i 
00065                         << " " << *lhits[i];
00066   }
00067   sort(lhits.begin(),lhits.end(),CaloHitIdMore());
00068   std::vector<CaloHit*>::iterator k1, k2;
00069   for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++)
00070     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Sorted " << i << " " 
00071                         << **k1;
00072 
00073   hits.resize(lhits.size());
00074   for (i = 0, k1 = lhits.begin(); k1 != lhits.end(); i++, k1++) {
00075     double       ehit  = (**k1).e();
00076     double       jitter= (**k1).t();
00077     unsigned int unitID= (**k1).id();
00078     int          jump  = 0;
00079     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Start " << i 
00080                         << " U/T/E 0x" << std::hex << unitID << std::dec << " "
00081                         << jitter << " "  << ehit;
00082     for (k2 = k1+1; k2 != lhits.end() && (jitter-(**k2).t())<1. &&
00083            (jitter-(**k2).t())>-1. && unitID==(**k2).id(); k2++) {
00084       ehit += (**k2).e();
00085       LogDebug("HcalSim") << " + " << (**k2).e();
00086       jump++;
00087     }
00088     LogDebug("HcalSim") << " = " << ehit << " in " << jump;
00089 
00090     float eta   = itr->eta();
00091     float phi   = itr->phi();
00092     float t     = itr->t();
00093     int lay     = ((unitID>>15)&31)+1;
00094 
00095     hits[nHits].layer = lay;
00096     hits[nHits].id = unitID;
00097     hits[nHits].eta = eta;
00098     hits[nHits].phi = phi;
00099     hits[nHits].e = ehit;
00100     hits[nHits].t = t;
00101     hits[nHits].jitter = jitter;
00102     nHits++;
00103     hit++;
00104 
00105     int subdet = (unitID>>20)&15;
00106     int zside  = (unitID>>14)&1;
00107     int ieta   = (unitID>>7)&127;
00108     int iphi   = (unitID)&127;
00109     LogDebug("HcalSim") << "HcalTestHistoClass::fillHits:Hit " << hit << " " 
00110                         << i << " ID 0x" << std::hex << unitID << std::dec 
00111                         << " " << subdet << " " << lay << " " << zside << " " 
00112                         << ieta << " " << iphi << " Time " << jitter << " E " 
00113                         << ehit;
00114 
00115     i  += jump;
00116     k1 += jump;
00117   }
00118 
00119   LogDebug("HcalSim") << "HcalTestHistoClass::fillHits called with " << nHit 
00120                       << " hits" << " and writes out " << nHits << '(' << hit 
00121                       << ") hits";
00122 
00123 }
00124 
00125 void HcalTestHistoClass::fillQie (int id, double esimtot, double eqietot, 
00126                                   int nGroup, std::vector<double> longs,
00127                                   std::vector<double> longq, int nTower,
00128                                   std::vector<double> latphi, 
00129                                   std::vector<double> latfs, 
00130                                   std::vector<double> latfq) {
00131 
00132   nGroupQIE = 0;
00133   nTowerQIE = 0;
00134   
00135   if (id>=0 && id<4) {
00136     unsigned int qiesiz = (unsigned int)(id+1);
00137     if (qie.size()<qiesiz) {
00138       qie.resize(qiesiz);     
00139     }
00140 
00141     qie[id].sim=esimtot;
00142     qie[id].qie=eqietot;
00143     qie[id].id = id;
00144     nQIE++;
00145     
00146     LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, esimtot, eqietot"
00147                         << " = " << id << " " << esimtot << " " << eqietot;
00148     
00149     for (int i=0; i<nGroup; i++) {
00150       LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, nGroupQIE, "
00151                           << "longs, longq = " << id << " " << nGroupQIE 
00152                           << " " << longs[i] << " " << longq[i];
00153       qie[id].lngs.push_back(longs[i]);
00154       qie[id].lngq.push_back(longq[i]);
00155       nGroupQIE++;
00156     }
00157 
00158     for (int i=0; i<nTower; i++) {
00159       int tow = (int)latphi[i];
00160       LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: id, nTowerQIE, "
00161                           << "tower, latfs, latfq = " << id << " " << nTowerQIE
00162                           << " "  << tow << " " << latfs[i] << " " << latfq[i];
00163       qie[id].lats.push_back(latfs[i]);
00164       qie[id].latq.push_back(latfq[i]);
00165       qie[id].tow.push_back(tow);
00166       nTowerQIE++;
00167     }
00168   }
00169   LogDebug("HcalSim") << "HcalTestHistoClass::fillQie: Called with ID " << id
00170                       << " nQIE " << nQIE << " nGroup " << nGroupQIE 
00171                       << " nTower " << nTowerQIE;
00172 }
00173