29 #include "G4SDManager.hh" 33 #include "G4PrimaryVertex.hh" 34 #include "G4VProcess.hh" 35 #include "G4HCofThisEvent.hh" 36 #include "G4UserEventAction.hh" 38 #include <CLHEP/Units/GlobalSystemOfUnits.h> 39 #include <CLHEP/Units/GlobalPhysicalConstants.h> 40 #include <CLHEP/Random/Randomize.h> 49 #include "TLorentzVector.h" 50 #include "TUnixSystem.h" 69 public Observer<const BeginOfEvent *>,
152 edm::LogVerbatim(
"ForwardSim") <<
"============================================================================";
153 edm::LogVerbatim(
"ForwardSim") <<
"CastorTestAnalysis:: Initialized as observer";
162 edm::LogVerbatim(
"ForwardSim") <<
"============================================================================";
167 new TNtuple(
"NTcastorstep",
"NTcastorstep",
"evt:trackid:charge:pdgcode:x:y:z:stepl:stepe:eta:phi:vpx:vpy:vpz");
171 "NTcastorevent",
"NTcastorevent",
"evt:ihit:detector:sector:module:enem:totalenergy:hitenergy:x:y:z");
190 edm::LogVerbatim(
"ForwardSim") << std::endl <<
"CastorTestAnalysis: Starting Run";
192 edm::LogVerbatim(
"ForwardSim") <<
"CastorTestAnalysis: output step root file created";
198 edm::LogVerbatim(
"ForwardSim") <<
"CastorTestAnalysis: output event root file created";
216 G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
218 G4double stepL = aStep->GetStepLength();
219 G4double stepE = aStep->GetTotalEnergyDeposit();
224 G4Track *theTrack = aStep->GetTrack();
225 G4int theTrackID = theTrack->GetTrackID();
226 G4double
theCharge = theTrack->GetDynamicParticle()->GetCharge();
228 G4int pdgcode = theTrack->GetDefinition()->GetPDGEncoding();
230 const G4ThreeVector &vert_mom = theTrack->GetVertexMomentumDirection();
231 G4double vpx = vert_mom.x();
232 G4double vpy = vert_mom.y();
233 G4double vpz = vert_mom.z();
234 double eta = 0.5 *
log((1. + vpz) / (1. - vpz));
235 double phi = atan2(vpy, vpx);
237 const G4ThreeVector &hitPoint = preStepPoint->GetPosition();
282 if (theTrack->GetNextVolume() != 0)
283 edm::LogVerbatim(
"ForwardSim") <<
" NextVolume: " << theTrack->GetNextVolume()->GetName();
297 <<
"CastorTest::update(EndOfEvent * evt) - event #" << (*evt)()->GetEventID();
300 G4HCofThisEvent *allHC = (*evt)()->GetHCofThisEvent();
303 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"CastorFI");
327 if (theCAFI->entries() > 0)
335 G4PrimaryParticle *thePrim =
nullptr;
336 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
339 edm::LogVerbatim(
"ForwardSim") <<
"CASTORTest End Of Event ERROR: no vertex";
341 for (
int i = 0;
i < nvertex;
i++) {
342 G4PrimaryVertex *avertex = (*evt)()->GetPrimaryVertex(
i);
343 if (avertex ==
nullptr) {
344 edm::LogVerbatim(
"ForwardSim") <<
"CASTORTest End Of Event ERR: pointer to vertex = 0";
348 int npart = avertex->GetNumberOfParticle();
350 edm::LogVerbatim(
"ForwardSim") <<
"CASTORTest End Of Event ERR: no primary!";
351 if (thePrim ==
nullptr)
352 thePrim = avertex->GetPrimary(trackID);
355 double px = 0.,
py = 0., pz = 0., pInit = 0;
357 double eta = 0.,
phi = 0.;
359 if (thePrim !=
nullptr) {
360 px = thePrim->GetPx();
361 py = thePrim->GetPy();
362 pz = thePrim->GetPz();
365 edm::LogVerbatim(
"ForwardSim") <<
"CASTORTest End Of Event ERR: primary has p=0 ";
368 float costheta = pz / pInit;
380 edm::LogVerbatim(
"ForwardSim") <<
"CASTORTest End Of Event ERR: could not find primary ";
384 <<
", " <<
eta <<
", " <<
phi;
388 int iEvt = (*evt)()->GetEventID();
391 else if ((iEvt < 100) && (iEvt % 10 == 0))
393 else if ((iEvt < 1000) && (iEvt % 100 == 0))
395 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
398 edm::LogVerbatim(
"ForwardSim") << std::endl <<
"===>>> Done writing user histograms ";
405 int nentries = hc->entries();
408 unsigned int volumeID = 0;
410 std::map<int, float, std::less<int> > themap;
411 double totalEnergy = 0;
412 double hitEnergy = 0;
413 double en_in_sd = 0.;
415 for (
int ihit = 0; ihit < nentries; ihit++) {
420 for (
int ihit = 0; ihit < nentries; ihit++) {
463 edm::LogVerbatim(
"ForwardSim") <<
"CastorTestAnalysis: Ntuple step written";
471 edm::LogVerbatim(
"ForwardSim") <<
"CastorTestAnalysis: Ntuple event written";
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
~CastorTestAnalysis() override
Float_t castoreventarray[11]
TNtuple * castoreventntuple
TNtuple * castorstepntuple
static void unpackIndex(const uint32_t &idx, int &z, int §or, int &zmodule)
CastorNumberingScheme * theCastorNumScheme
math::XYZPoint getPosition() const
Tan< T >::type tan(const T &t)
Float_t castorsteparray[14]
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
double getEnergyDeposit() const
uint32_t getUnitID() const
CastorTestAnalysis(const edm::ParameterSet &p)
std::string stepNtFileName
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
TFile * castorOutputStepFile
Geom::Theta< T > theta() const
TFile * castorOutputEventFile
Power< A, B >::type pow(const A &a, const B &b)
void getCastorBranchData(const CaloG4HitCollection *hc)
std::string eventNtFileName