32 #include "CLHEP/Random/RandGaussQ.h" 34 #include "G4SDManager.hh" 35 #include "G4VProcess.hh" 36 #include "G4HCofThisEvent.hh" 37 #include "CLHEP/Units/GlobalSystemOfUnits.h" 38 #include "CLHEP/Units/GlobalPhysicalConstants.h" 39 #include "Randomize.hh" 42 class HepRandomEngine;
55 produces<HcalTB02HistoClass>();
57 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis:: Initialised as observer of " 58 <<
"BeginOfJob/BeginOfEvent/EndOfEvent with " 59 <<
"Parameter values:\n \thcalOnly = " << hcalOnly;
83 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = " 84 << (*evt) ()->GetEventID();
90 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
91 CLHEP::RandGaussQ randGauss(*engine);
94 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event " 95 << (*evt)()->GetEventID();
98 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
103 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
105 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd
106 <<
" of ID " << HCHCid <<
" is obtained at " <<theHCHC;
109 nentries = theHCHC->entries();
110 if (nentries==0)
return;
119 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
121 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd
122 <<
" of ID " << XTALSid <<
" is obtained at " 124 xentries = theXTHC->entries();
125 if (xentries==0)
return;
128 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries
129 <<
" HCal hits, and" << xentries <<
" xtal hits";
131 float ETot=0., xETot=0.;
132 int scintID=0, xtalID=0;
137 if (HCHCid >= 0 && theHCHC > 0) {
138 for ( ihit = 0; ihit < nentries; ihit++) {
143 float enEm = aHit->
getEM();
151 energyInScints[scintID]+= enEm + enhad;
155 histo->fillAllTime(time);
163 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
164 for (
int iphi=0 ; iphi<8; iphi++) {
166 TowerEne[iphi][
jeta]=0.;
167 TowerEneCF[iphi][
jeta]=0.;
171 for (
int ilayer=0; ilayer<19; ilayer++) LayerEne[ilayer]=0.;
172 for (
int iring=0; iring<100; iring++) EnRing[iring]=0.;
174 for (std::map<int,float>::iterator is = energyInScints.begin();
175 is!= energyInScints.end(); is++) {
181 if ( (layer!=17) && (layer!=18) ) {
187 TowerEne[(
int)phi][(
int)
eta] += ETot;
189 TowerEneCF[(
int)phi][(
int)
eta] += ETot*(1.+ 0.1*randGauss.fire() );
190 double dR=0.08727*
std::sqrt( (eta-8.)*(eta-8.) + (phi-3.)*(phi-3.) );
191 EnRing[(
int)(dR/0.01)] += ETot;
194 LayerEne[layer] += ETot;
198 for (
int ilayer=0 ; ilayer<19 ; ilayer++) {
199 histo->fillProfile(ilayer,LayerEne[ilayer]/
GeV);
202 for (
int iring=0; iring<100; iring++)
203 histo->fillTransProf(0.01*iring+0.005,EnRing[iring]/
GeV);
205 for (
int iphi=0 ; iphi<8; iphi++) {
208 SEnergyN += TowerEneCF[iphi][
jeta] + 3.*randGauss.fire();
210 double Rand = 3.*randGauss.fire();
212 if ( (iphi>=0) && (iphi<7) ) {
215 E7x7Matrix += TowerEne[iphi][
jeta];
216 E7x7MatrixN += TowerEneCF[iphi][
jeta] + Rand;
218 if ( (iphi>=1) && (iphi<6) ) {
221 E5x5Matrix += TowerEne[iphi][
jeta];
222 E5x5MatrixN += TowerEneCF[iphi][
jeta] + Rand;
237 G4PrimaryParticle* thePrim=0;
238 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
239 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex
243 <<
"ERROR: no vertex";
245 for (
int i = 0 ;
i<nvertex;
i++) {
247 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
250 <<
"ERROR: pointer to vertex = 0";
252 int npart = avertex->GetNumberOfParticle();
253 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i 254 <<
" with " << npart <<
" particles";
255 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
259 double px=0.,py=0.,pz=0.;
262 px = thePrim->GetPx();
263 py = thePrim->GetPy();
264 pz = thePrim->GetPz();
268 <<
" ERROR: primary has p=0 ";
270 float costheta = pz/pInit;
273 if (px != 0)
phi = atan(py/px);
277 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could" 278 <<
" not find primary ";
290 if (XTALSid >= 0 && theXTHC > 0) {
291 for (
int xihit = 0; xihit < xentries; xihit++) {
295 float xenEm = xaHit->
getEM();
296 float xenhad = xaHit->
getHadr();
299 energyInCrystals[xtalID]+= xenEm + xenhad;
302 float xCrysEne[7][7];
303 for (
int irow=0 ; irow<7; irow++) {
304 for (
int jcol=0 ; jcol<7; jcol++) {
305 xCrysEne[irow][jcol]=0.;
309 for (std::map<int,float>::iterator is = energyInCrystals.begin();
310 is!= energyInCrystals.end(); is++) {
311 int xtalID = (*is).first;
312 xETot = (*is).second;
314 int irow = (
int)(xtalID/100.);
315 int jcol = (
int)(xtalID-100.*irow);
318 xCrysEne[irow][jcol] = xETot;
320 float dR=
std::sqrt( 0.01619*0.01619*(jcol-3)*(jcol-3) +
321 0.01606*0.01606*(irow-3)*(irow-3) );
322 histo->fillTransProf(dR,xETot*1.05);
324 if ( (irow>0) && (irow<6) ) {
325 if ( (jcol>0) && (jcol<6) ) {
327 xE5x5Matrix += xCrysEne[irow][jcol];
328 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5*randGauss.fire();
330 if ( (irow>1) && (irow<5) ) {
331 if ( (jcol>1) && (jcol<5) ) {
332 xE3x3Matrix += xCrysEne[irow][jcol];
333 xE3x3MatrixN += xCrysEne[irow][jcol] +108.5*randGauss.fire();
343 if ( theXTHC != 0 ) {
353 int iEvt = (*evt)()->GetEventID();
355 std::cout <<
" Event " << iEvt << std::endl;
356 else if ((iEvt < 100) && (iEvt%10 == 0))
357 std::cout <<
" Event " << iEvt << std::endl;
358 else if ((iEvt < 1000) && (iEvt%100 == 0))
359 std::cout <<
" Event " << iEvt << std::endl;
360 else if ((iEvt < 10000) && (iEvt%1000 == 0))
361 std::cout <<
" Event " << iEvt << std::endl;
369 product.
set_Nprim(
float(primaries.size()));
383 product.
set_NUnit(
float(energyInScints.size()));
388 product.
set_xNUnit(
float(energyInCrystals.size()));
401 pInit =
eta =
phi = incidentEnergy = 0;
403 SEnergy = E7x7Matrix = E5x5Matrix = SEnergyN = 0;
404 E7x7MatrixN = E5x5MatrixN = 0;
405 energyInScints.clear();
409 energyInCrystals.clear();
410 xSEnergy = xSEnergyN = xE5x5Matrix = xE3x3Matrix = 0;
411 xE5x5MatrixN = xE3x3MatrixN = 0;
T getParameter(std::string const &) const
void set_Ntimesli(float v)
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_SIMWATCHER(type)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void set_xEentry(float v)
static const HistoName names[]
def fillEvent(tree, event)
Geom::Theta< T > theta() const
int getphiID(int sID) const
double getIncidentEnergy() const
void fillEvent(HcalTB02HistoClass &)
virtual ~HcalTB02Analysis()
HcalTB02Analysis(const edm::ParameterSet &p)
int getlayerID(int sID) const
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Tan< T >::type tan(const T &t)
void update(const BeginOfEvent *evt)
This routine will be called when the appropriate signal arrives.
virtual void produce(edm::Event &, const edm::EventSetup &)
void set_partType(float v)
int getTimeSliceID() const
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
int getetaID(int sID) const
uint32_t getUnitID() const
Power< A, B >::type pow(const A &a, const B &b)