43 #include "G4HCofThisEvent.hh" 44 #include "G4SDManager.hh" 47 #include "G4ThreeVector.hh" 48 #include "G4VProcess.hh" 50 #include "CLHEP/Random/RandGaussQ.h" 51 #include "CLHEP/Units/GlobalSystemOfUnits.h" 52 #include "CLHEP/Units/GlobalPhysicalConstants.h" 53 #include "Randomize.hh" 56 class HepRandomEngine;
110 produces<HcalTB02HistoClass>();
112 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis:: Initialised as observer of " 113 <<
"BeginOfJob/BeginOfEvent/EndOfEvent with " 114 <<
"Parameter values:\n \thcalOnly = " << hcalOnly;
135 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = " << (*evt)()->GetEventID();
140 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
141 CLHEP::RandGaussQ randGauss(*engine);
144 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event " << (*evt)()->GetEventID();
147 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
152 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
154 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd <<
" of ID " << HCHCid <<
" is obtained at " 158 nentries = theHCHC->entries();
169 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
171 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd <<
" of ID " << XTALSid
172 <<
" is obtained at " << theXTHC;
173 xentries = theXTHC->entries();
178 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries <<
" HCal hits, and" << xentries
181 float ETot = 0., xETot = 0.;
182 int scintID = 0, xtalID = 0;
187 if (HCHCid >= 0 && theHCHC !=
nullptr) {
188 for (ihit = 0; ihit < nentries; ihit++) {
192 float enEm = aHit->
getEM();
200 energyInScints[scintID] += enEm + enhad;
201 primaries[aHit->
getTrackID()] += enEm + enhad;
205 histo->fillAllTime(time);
212 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
220 for (
int ilayer = 0; ilayer < 19; ilayer++)
221 LayerEne[ilayer] = 0.;
222 for (
int iring = 0; iring < 100; iring++)
225 for (std::map<int, float>::iterator is = energyInScints.begin(); is != energyInScints.end(); is++) {
230 if ((layer != 17) && (layer != 18)) {
232 float phi = org->
getphiID((*is).first);
235 TowerEne[(
int)phi][(
int)
eta] += ETot;
237 TowerEneCF[(
int)phi][(
int)
eta] += ETot * (1. + 0.1 * randGauss.fire());
238 double dR = 0.08727 *
std::sqrt((eta - 8.) * (eta - 8.) + (phi - 3.) * (phi - 3.));
239 EnRing[(
int)(dR / 0.01)] += ETot;
242 LayerEne[layer] += ETot;
245 for (
int ilayer = 0; ilayer < 19; ilayer++) {
246 histo->fillProfile(ilayer, LayerEne[ilayer] /
GeV);
249 for (
int iring = 0; iring < 100; iring++)
250 histo->fillTransProf(0.01 * iring + 0.005, EnRing[iring] /
GeV);
254 SEnergyN += TowerEneCF[
iphi][
jeta] + 3. * randGauss.fire();
256 double Rand = 3. * randGauss.fire();
261 E7x7MatrixN += TowerEneCF[
iphi][
jeta] + Rand;
266 E5x5MatrixN += TowerEneCF[
iphi][
jeta] + Rand;
278 G4PrimaryParticle* thePrim =
nullptr;
279 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
280 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex <<
" vertex";
283 <<
"ERROR: no vertex";
285 for (
int i = 0;
i < nvertex;
i++) {
286 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
287 if (avertex ==
nullptr) {
289 <<
"ERROR: pointer to vertex = 0";
291 int npart = avertex->GetNumberOfParticle();
292 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i <<
" with " << npart <<
" particles";
293 if (thePrim ==
nullptr)
294 thePrim = avertex->GetPrimary(trackID);
298 double px = 0.,
py = 0., pz = 0.;
300 if (thePrim !=
nullptr) {
301 px = thePrim->GetPx();
302 py = thePrim->GetPy();
303 pz = thePrim->GetPz();
307 <<
" ERROR: primary has p=0 ";
309 float costheta = pz / pInit;
317 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could" 318 <<
" not find primary ";
329 if (XTALSid >= 0 && theXTHC !=
nullptr) {
330 for (
int xihit = 0; xihit < xentries; xihit++) {
333 float xenEm = xaHit->
getEM();
334 float xenhad = xaHit->
getHadr();
337 energyInCrystals[xtalID] += xenEm + xenhad;
340 float xCrysEne[7][7];
341 for (
int irow = 0; irow < 7; irow++) {
342 for (
int jcol = 0; jcol < 7; jcol++) {
343 xCrysEne[irow][jcol] = 0.;
347 for (std::map<int, float>::iterator is = energyInCrystals.begin(); is != energyInCrystals.end(); is++) {
348 int xtalID = (*is).first;
349 xETot = (*is).second;
351 int irow = (
int)(xtalID / 100.);
352 int jcol = (
int)(xtalID - 100. * irow);
355 xCrysEne[irow][jcol] = xETot;
357 float dR =
std::sqrt(0.01619 * 0.01619 * (jcol - 3) * (jcol - 3) + 0.01606 * 0.01606 * (irow - 3) * (irow - 3));
358 histo->fillTransProf(dR, xETot * 1.05);
360 if ((irow > 0) && (irow < 6)) {
361 if ((jcol > 0) && (jcol < 6)) {
362 xE5x5Matrix += xCrysEne[irow][jcol];
363 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
365 if ((irow > 1) && (irow < 5)) {
366 if ((jcol > 1) && (jcol < 5)) {
367 xE3x3Matrix += xCrysEne[irow][jcol];
368 xE3x3MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
377 if (theXTHC !=
nullptr) {
386 int iEvt = (*evt)()->GetEventID();
388 std::cout <<
" Event " << iEvt << std::endl;
389 else if ((iEvt < 100) && (iEvt % 10 == 0))
390 std::cout <<
" Event " << iEvt << std::endl;
391 else if ((iEvt < 1000) && (iEvt % 100 == 0))
392 std::cout <<
" Event " << iEvt << std::endl;
393 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
394 std::cout <<
" Event " << iEvt << std::endl;
401 product.
set_Nprim(
float(primaries.size()));
415 product.
set_NUnit(
float(energyInScints.size()));
420 product.
set_xNUnit(
float(energyInCrystals.size()));
432 pInit =
eta = phi = incidentEnergy = 0;
434 SEnergy = E7x7Matrix = E5x5Matrix = SEnergyN = 0;
435 E7x7MatrixN = E5x5MatrixN = 0;
436 energyInScints.clear();
440 energyInCrystals.clear();
441 xSEnergy = xSEnergyN = xE5x5Matrix = xE3x3Matrix = 0;
442 xE5x5MatrixN = xE3x3MatrixN = 0;
std::string fileNameTuple
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.
std::map< int, float > energyInScints
void set_xEentry(float v)
~HcalTB02Analysis() override
def fillEvent(tree, event)
Geom::Theta< T > theta() const
int getphiID(int sID) const
double getIncidentEnergy() const
void produce(edm::Event &, const edm::EventSetup &) override
const std::string names[nVars_]
void fillEvent(HcalTB02HistoClass &)
HcalTB02Analysis(const edm::ParameterSet &p)
void update(const BeginOfEvent *evt) override
This routine will be called when the appropriate signal arrives.
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)
std::map< int, float > primaries
void set_partType(float v)
int getTimeSliceID() const
std::vector< std::string > names
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
int getetaID(int sID) const
uint32_t getUnitID() const
Power< A, B >::type pow(const A &a, const B &b)