34 #include "CLHEP/Random/RandGaussQ.h"
37 #include "G4SDManager.hh"
38 #include "G4VProcess.hh"
39 #include "G4HCofThisEvent.hh"
40 #include "CLHEP/Units/GlobalSystemOfUnits.h"
41 #include "CLHEP/Units/GlobalPhysicalConstants.h"
53 produces<HcalTB02HistoClass>();
55 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis:: Initialised as observer of "
56 <<
"BeginOfJob/BeginOfEvent/EndOfEvent with "
57 <<
"Parameter values:\n \thcalOnly = " <<
hcalOnly;
70 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis is deleting";
86 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = "
87 << (*evt) ()->GetEventID();
96 <<
"HcalTB02Analysis requires the RandomNumberGeneratorService\n"
97 <<
"which is not present in the configuration file. "
98 <<
"You must add the service\n in the configuration file or "
99 <<
"remove the modules that require it.";
101 CLHEP::RandGaussQ randGauss(rng->
getEngine());
104 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event "
105 << (*evt)()->GetEventID();
108 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
113 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
116 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd
117 <<
" of ID " << HCHCid <<
" is obtained at " <<theHCHC;
120 nentries = theHCHC->entries();
121 if (nentries==0)
return;
130 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
135 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd
136 <<
" of ID " << XTALSid <<
" is obtained at "
138 xentries = theXTHC->entries();
139 if (xentries==0)
return;
142 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries
143 <<
" HCal hits, and" << xentries <<
" xtal hits";
145 float ETot=0., xETot=0.;
148 int scintID=0, xtalID=0;
152 if (HCHCid >= 0 && theHCHC > 0) {
153 for ( ihit = 0; ihit < nentries; ihit++) {
158 float enEm = aHit->
getEM();
178 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
179 for (
int iphi=0 ; iphi<8; iphi++) {
180 for (
int jeta=0 ; jeta<18; jeta++) {
181 TowerEne[iphi][jeta]=0.;
182 TowerEneCF[iphi][jeta]=0.;
186 for (
int ilayer=0; ilayer<19; ilayer++) LayerEne[ilayer]=0.;
187 for (
int iring=0; iring<100; iring++) EnRing[iring]=0.;
196 if ( (layer!=17) && (layer!=18) ) {
202 TowerEne[(int)phi][(
int)
eta] += ETot;
204 TowerEneCF[(int)phi][(
int)
eta] += ETot*(1.+ 0.1*randGauss.fire() );
205 double dR=0.08727*
std::sqrt( (eta-8.)*(eta-8.) + (phi-3.)*(phi-3.) );
206 EnRing[(int)(dR/0.01)] += ETot;
209 LayerEne[layer] += ETot;
213 for (
int ilayer=0 ; ilayer<19 ; ilayer++) {
217 for (
int iring=0; iring<100; iring++)
220 for (
int iphi=0 ; iphi<8; iphi++) {
221 for (
int jeta=0 ; jeta<18; jeta++) {
224 SEnergyN += TowerEneCF[iphi][jeta] + 3.*randGauss.fire();
232 double Rand = 3.*randGauss.fire();
234 if ( (iphi>=0) && (iphi<7) ) {
235 if ( (jeta>=5) && (jeta<12) ) {
240 if ( (iphi>=1) && (iphi<6) ) {
241 if ( (jeta>=6) && (jeta<11) ) {
259 G4PrimaryParticle* thePrim=0;
260 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
261 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex
265 <<
"ERROR: no vertex";
267 for (
int i = 0 ;
i<nvertex;
i++) {
269 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
272 <<
"ERROR: pointer to vertex = 0";
274 int npart = avertex->GetNumberOfParticle();
275 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i
276 <<
" with " << npart <<
" particles";
277 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
281 double px=0.,py=0.,pz=0.;
284 px = thePrim->GetPx();
285 py = thePrim->GetPy();
286 pz = thePrim->GetPz();
290 <<
" ERROR: primary has p=0 ";
292 float costheta = pz/
pInit;
295 if (px != 0)
phi = atan(py/px);
299 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could"
300 <<
" not find primary ";
312 if (XTALSid >= 0 && theXTHC > 0) {
313 for (
int xihit = 0; xihit < xentries; xihit++) {
317 float xenEm = xaHit->
getEM();
318 float xenhad = xaHit->
getHadr();
324 float xCrysEne[7][7];
325 for (
int irow=0 ; irow<7; irow++) {
326 for (
int jcol=0 ; jcol<7; jcol++) {
327 xCrysEne[irow][jcol]=0.;
333 int xtalID = (*is).first;
334 xETot = (*is).second;
336 int irow = (int)(xtalID/100.);
337 int jcol = (int)(xtalID-100.*irow);
340 xCrysEne[irow][jcol] = xETot;
342 float dR=
std::sqrt( 0.01619*0.01619*(jcol-3)*(jcol-3) +
343 0.01606*0.01606*(irow-3)*(irow-3) );
346 if ( (irow>0) && (irow<6) ) {
347 if ( (jcol>0) && (jcol<6) ) {
350 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5*randGauss.fire();
352 if ( (irow>1) && (irow<5) ) {
353 if ( (jcol>1) && (jcol<5) ) {
355 xE3x3MatrixN += xCrysEne[irow][jcol] +108.5*randGauss.fire();
365 if ( theXTHC != 0 ) {
375 int iEvt = (*evt)()->GetEventID();
377 std::cout <<
" Event " << iEvt << std::endl;
378 else if ((iEvt < 100) && (iEvt%10 == 0))
379 std::cout <<
" Event " << iEvt << std::endl;
380 else if ((iEvt < 1000) && (iEvt%100 == 0))
381 std::cout <<
" Event " << iEvt << std::endl;
382 else if ((iEvt < 10000) && (iEvt%1000 == 0))
383 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)
const T & max(const T &a, const T &b)
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
virtual CLHEP::HepRandomEngine & getEngine() const =0
Use this to get the random number engine, this is the only function most users should call...
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)