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 "CLHEP/Random/Random.h"
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;
72 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis is deleting";
88 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = "
89 << (*evt) ()->GetEventID();
95 CLHEP::HepRandomEngine* engine = CLHEP::HepRandom::getTheEngine();
96 CLHEP::RandGaussQ randGauss(*engine);
99 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event "
100 << (*evt)()->GetEventID();
103 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
108 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
111 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd
112 <<
" of ID " << HCHCid <<
" is obtained at " <<theHCHC;
115 nentries = theHCHC->entries();
116 if (nentries==0)
return;
125 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
130 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd
131 <<
" of ID " << XTALSid <<
" is obtained at "
133 xentries = theXTHC->entries();
134 if (xentries==0)
return;
137 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries
138 <<
" HCal hits, and" << xentries <<
" xtal hits";
140 float ETot=0., xETot=0.;
143 int scintID=0, xtalID=0;
147 if (HCHCid >= 0 && theHCHC > 0) {
148 for ( ihit = 0; ihit < nentries; ihit++) {
153 float enEm = aHit->
getEM();
173 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
174 for (
int iphi=0 ; iphi<8; iphi++) {
175 for (
int jeta=0 ; jeta<18; jeta++) {
176 TowerEne[iphi][jeta]=0.;
177 TowerEneCF[iphi][jeta]=0.;
181 for (
int ilayer=0; ilayer<19; ilayer++) LayerEne[ilayer]=0.;
182 for (
int iring=0; iring<100; iring++) EnRing[iring]=0.;
191 if ( (layer!=17) && (layer!=18) ) {
197 TowerEne[(int)phi][(
int)
eta] += ETot;
199 TowerEneCF[(int)phi][(
int)
eta] += ETot*(1.+ 0.1*randGauss.fire() );
200 double dR=0.08727*
std::sqrt( (eta-8.)*(eta-8.) + (phi-3.)*(phi-3.) );
201 EnRing[(int)(dR/0.01)] += ETot;
204 LayerEne[layer] += ETot;
208 for (
int ilayer=0 ; ilayer<19 ; ilayer++) {
212 for (
int iring=0; iring<100; iring++)
215 for (
int iphi=0 ; iphi<8; iphi++) {
216 for (
int jeta=0 ; jeta<18; jeta++) {
219 SEnergyN += TowerEneCF[iphi][jeta] + 3.*randGauss.fire();
227 double Rand = 3.*randGauss.fire();
229 if ( (iphi>=0) && (iphi<7) ) {
230 if ( (jeta>=5) && (jeta<12) ) {
235 if ( (iphi>=1) && (iphi<6) ) {
236 if ( (jeta>=6) && (jeta<11) ) {
254 G4PrimaryParticle* thePrim=0;
255 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
256 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex
260 <<
"ERROR: no vertex";
262 for (
int i = 0 ;
i<nvertex;
i++) {
264 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
267 <<
"ERROR: pointer to vertex = 0";
269 int npart = avertex->GetNumberOfParticle();
270 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i
271 <<
" with " << npart <<
" particles";
272 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
276 double px=0.,py=0.,pz=0.;
279 px = thePrim->GetPx();
280 py = thePrim->GetPy();
281 pz = thePrim->GetPz();
285 <<
" ERROR: primary has p=0 ";
287 float costheta = pz/
pInit;
290 if (px != 0)
phi = atan(py/px);
294 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could"
295 <<
" not find primary ";
307 if (XTALSid >= 0 && theXTHC > 0) {
308 for (
int xihit = 0; xihit < xentries; xihit++) {
312 float xenEm = xaHit->
getEM();
313 float xenhad = xaHit->
getHadr();
319 float xCrysEne[7][7];
320 for (
int irow=0 ; irow<7; irow++) {
321 for (
int jcol=0 ; jcol<7; jcol++) {
322 xCrysEne[irow][jcol]=0.;
328 int xtalID = (*is).first;
329 xETot = (*is).second;
331 int irow = (int)(xtalID/100.);
332 int jcol = (int)(xtalID-100.*irow);
335 xCrysEne[irow][jcol] = xETot;
337 float dR=
std::sqrt( 0.01619*0.01619*(jcol-3)*(jcol-3) +
338 0.01606*0.01606*(irow-3)*(irow-3) );
341 if ( (irow>0) && (irow<6) ) {
342 if ( (jcol>0) && (jcol<6) ) {
345 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5*randGauss.fire();
347 if ( (irow>1) && (irow<5) ) {
348 if ( (jcol>1) && (jcol<5) ) {
350 xE3x3MatrixN += xCrysEne[irow][jcol] +108.5*randGauss.fire();
360 if ( theXTHC != 0 ) {
370 int iEvt = (*evt)()->GetEventID();
372 std::cout <<
" Event " << iEvt << std::endl;
373 else if ((iEvt < 100) && (iEvt%10 == 0))
374 std::cout <<
" Event " << iEvt << std::endl;
375 else if ((iEvt < 1000) && (iEvt%100 == 0))
376 std::cout <<
" Event " << iEvt << std::endl;
377 else if ((iEvt < 10000) && (iEvt%1000 == 0))
378 std::cout <<
" Event " << iEvt << std::endl;
T getParameter(std::string const &) const
void set_Ntimesli(float v)
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_SIMWATCHER(type)
void set_xEentry(float v)
void fillTransProf(float u, float v)
Geom::Theta< T > theta() const
int getphiID(int sID) const
double getIncidentEnergy() const
void fillEvent(HcalTB02HistoClass &)
virtual ~HcalTB02Analysis()
std::map< int, float > energyInCrystals
HcalTB02Analysis(const edm::ParameterSet &p)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
int getlayerID(int sID) const
void fillAllTime(float v)
Tan< T >::type tan(const T &t)
std::map< int, float > primaries
std::map< int, float > energyInScints
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
std::vector< std::string > names
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
void fillProfile(int ilayer, float value)
int getetaID(int sID) const
uint32_t getUnitID() const
Power< A, B >::type pow(const A &a, const B &b)