23 #include "G4SDManager.hh" 27 #include "G4PrimaryVertex.hh" 28 #include "G4VProcess.hh" 29 #include "G4HCofThisEvent.hh" 30 #include "G4UserEventAction.hh" 32 #include <CLHEP/Units/GlobalSystemOfUnits.h> 33 #include <CLHEP/Units/GlobalPhysicalConstants.h> 34 #include <CLHEP/Random/Randomize.h> 42 #include "TLorentzVector.h" 43 #include "TUnixSystem.h" 61 public Observer<const BeginOfEvent*>,
148 edm::LogVerbatim(
"ZdcAnalysis") <<
"\n============================================================================";
149 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTestAnalysis:: Initialized as observer";
158 edm::LogVerbatim(
"ZdcAnalysis") <<
"============================================================================" 163 new TNtuple(
"NTzdcstep",
165 "evt:trackid:charge:pdgcode:x:y:z:stepl:stepe:eta:phi:vpx:vpy:vpz:idx:idl:pvtype:ncherphot");
169 new TNtuple(
"NTzdcevent",
171 "evt:ihit:fiberid:zside:subdet:layer:fiber:channel:enem:enhad:hitenergy:x:y:z:time:etot");
192 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZDCTestAnalysis: output step file created";
198 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZDCTestAnalysis: output event file created";
218 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
220 G4double stepL = aStep->GetStepLength();
221 G4double stepE = aStep->GetTotalEnergyDeposit();
226 G4Track* theTrack = aStep->GetTrack();
227 G4int theTrackID = theTrack->GetTrackID();
228 G4double
theCharge = theTrack->GetDynamicParticle()->GetCharge();
229 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
230 G4int pdgcode = theTrack->GetDefinition()->GetPDGEncoding();
232 const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
233 G4double vpx = vert_mom.x();
234 G4double vpy = vert_mom.y();
235 G4double vpz = vert_mom.z();
236 double eta = 0.5 *
log((1. + vpz) / (1. - vpz));
237 double phi = atan2(vpy, vpx);
239 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
240 G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
242 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
243 int idx = touch->GetReplicaNumber(0);
251 std::vector<G4VPhysicalVolume*> thePhysicalVolumes(
historyDepth);
253 std::vector<G4LogicalVolume*> theLogicalVolumes(
historyDepth);
259 theReplicaNumbers[
jj] = touch->GetReplicaNumber(
jj);
260 thePhysicalVolumes[
jj] = touch->GetVolume(
jj);
261 thePVnames[
jj] = thePhysicalVolumes[
jj]->GetName();
262 theLogicalVolumes[
jj] = thePhysicalVolumes[
jj]->GetLogicalVolume();
263 theLVnames[
jj] = theLogicalVolumes[
jj]->GetName();
264 theMaterials[
jj] = theLogicalVolumes[
jj]->GetMaterial();
265 theMaterialNames[
jj] = theMaterials[
jj]->GetName();
267 edm::LogVerbatim(
"ZdcAnalysis") <<
" GHD " <<
jj <<
": " << theReplicaNumbers[
jj] <<
"," << thePVnames[
jj]
268 <<
"," << theLVnames[
jj] <<
"," << theMaterialNames[
jj];
271 idLayer = theReplicaNumbers[1];
272 if (thePVnames[0] ==
"ZDC_EMLayer")
274 else if (thePVnames[0] ==
"ZDC_EMAbsorber")
276 else if (thePVnames[0] ==
"ZDC_EMFiber")
278 else if (thePVnames[0] ==
"ZDC_HadLayer")
280 else if (thePVnames[0] ==
"ZDC_HadAbsorber")
282 else if (thePVnames[0] ==
"ZDC_HadFiber")
284 else if (thePVnames[0] ==
"ZDC_PhobosLayer")
286 else if (thePVnames[0] ==
"ZDC_PhobosAbsorber")
288 else if (thePVnames[0] ==
"ZDC_PhobosFiber")
294 << thePVnames[0] <<
"," << theLVnames[0] <<
"," << theMaterialNames[0];
297 int theReplicaNumber = touch->GetReplicaNumber(0);
298 G4VPhysicalVolume* thePhysicalVolume = touch->GetVolume(0);
299 const G4String& thePVname = thePhysicalVolume->GetName();
300 G4LogicalVolume* theLogicalVolume = thePhysicalVolume->GetLogicalVolume();
301 const G4String& theLVname = theLogicalVolume->GetName();
302 G4Material* theMaterial = theLogicalVolume->GetMaterial();
303 const G4String& theMaterialName = theMaterial->GetName();
305 edm::LogVerbatim(
"ZdcAnalysis") <<
" hd=0 " << theReplicaNumber <<
"," << thePVname <<
"," << theLVname <<
"," 311 double NCherPhot = -1;
338 edm::LogVerbatim(
"ZdcAnalysis") <<
"\nZdcTest::upDate(const EndOfEvent * evt) - event #" << (*evt)()->GetEventID()
339 <<
"\n # of aSteps followed in event = " <<
stepIndex;
342 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
345 int theZDCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"ZDCHITS");
354 unsigned int unsignedfiberID = 0;
355 std::map<int, float, std::less<int> > energyInFibers;
356 std::map<int, float, std::less<int> > primaries;
357 float totalEnergy = 0;
358 int nentries = theZDCHC->entries();
359 edm::LogVerbatim(
"ZdcAnalysis") <<
" theZDCHC has " << nentries <<
" entries";
363 for (
int ihit = 0; ihit < nentries; ihit++) {
368 for (
int ihit = 0; ihit < nentries; ihit++) {
372 double enEm = aHit->
getEM();
373 double enHad = aHit->
getHadr();
378 <<
" entry #" << ihit <<
": fiberID=0x" << std::hex << fiberID <<
std::dec <<
"; enEm=" << enEm
379 <<
"; enHad=" << enHad <<
"; hitEnergy=" << hitEnergy <<
"z=" << hitPoint.z();
380 energyInFibers[fiberID] += enEm + enHad;
381 primaries[aHit->
getTrackID()] += enEm + enHad;
386 int thesubdet, thelayer, thefiber, thechannel, thez;
388 int unsignedsubdet, unsignedlayer, unsignedfiber, unsignedchannel, unsignedz;
390 unsignedfiberID, unsignedsubdet, unsignedlayer, unsignedfiber, unsignedchannel, unsignedz);
425 G4PrimaryParticle* thePrim =
nullptr;
426 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
431 for (
int i = 0;
i < nvertex;
i++) {
432 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
433 if (avertex ==
nullptr) {
434 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTest End Of Event ERR: pointer to vertex = 0";
437 int npart = avertex->GetNumberOfParticle();
440 if (thePrim ==
nullptr)
441 thePrim = avertex->GetPrimary(trackID);
445 double px = 0.,
py = 0., pz = 0.;
448 if (thePrim !=
nullptr) {
449 px = thePrim->GetPx();
450 py = thePrim->GetPy();
451 pz = thePrim->GetPz();
454 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTest End Of Event ERR: primary has p=0 ";
457 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTest End Of Event ERR: could not find primary ";
464 int iEvt = (*evt)()->GetEventID();
467 else if ((iEvt < 100) && (iEvt % 10 == 0))
469 else if ((iEvt < 1000) && (iEvt % 100 == 0))
471 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
Log< level::Info, true > LogVerbatim
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
Float_t zdceventarray[16]
TFile * zdcOutputEventFile
std::string stepNtFileName
TFile * zdcOutputStepFile
~ZdcTestAnalysis() override
math::XYZPoint getPosition() const
int getTimeSliceID() const
ZdcTestAnalysis(const edm::ParameterSet &p)
XYZPointD XYZPoint
point in space with cartesian internal representation
static void unpackZdcIndex(const unsigned int &idx, int &subDet, int &layer, int &fiber, int &channel, int &z)
double getEnergyDeposit() const
uint32_t getUnitID() const
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
std::string eventNtFileName
Power< A, B >::type pow(const A &a, const B &b)