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*>,
150 edm::LogVerbatim(
"ZdcAnalysis") <<
"\n============================================================================";
151 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTestAnalysis:: Initialized as observer";
160 edm::LogVerbatim(
"ZdcAnalysis") <<
"============================================================================" 165 new TNtuple(
"NTzdcstep",
167 "evt:trackid:charge:pdgcode:x:y:z:stepl:stepe:eta:phi:vpx:vpy:vpz:idx:idl:pvtype:ncherphot");
171 new TNtuple(
"NTzdcevent",
173 "evt:ihit:fiberid:zside:subdet:layer:fiber:channel:enem:enhad:hitenergy:x:y:z:time:etot");
196 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZDCTestAnalysis: output step file created";
202 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZDCTestAnalysis: output event file created";
222 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
224 G4double stepL = aStep->GetStepLength();
225 G4double stepE = aStep->GetTotalEnergyDeposit();
230 G4Track* theTrack = aStep->GetTrack();
231 G4int theTrackID = theTrack->GetTrackID();
232 G4double
theCharge = theTrack->GetDynamicParticle()->GetCharge();
233 G4String
particleType = theTrack->GetDefinition()->GetParticleName();
234 G4int pdgcode = theTrack->GetDefinition()->GetPDGEncoding();
236 const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
237 G4double vpx = vert_mom.x();
238 G4double vpy = vert_mom.y();
239 G4double vpz = vert_mom.z();
240 double eta = 0.5 *
log((1. + vpz) / (1. - vpz));
241 double phi = atan2(vpy, vpx);
243 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
244 G4ThreeVector localPoint = theTrack->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
246 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
247 int idx = touch->GetReplicaNumber(0);
255 std::vector<G4VPhysicalVolume*> thePhysicalVolumes(
historyDepth);
257 std::vector<G4LogicalVolume*> theLogicalVolumes(
historyDepth);
263 theReplicaNumbers[
jj] = touch->GetReplicaNumber(
jj);
264 thePhysicalVolumes[
jj] = touch->GetVolume(
jj);
265 thePVnames[
jj] = thePhysicalVolumes[
jj]->GetName();
266 theLogicalVolumes[
jj] = thePhysicalVolumes[
jj]->GetLogicalVolume();
267 theLVnames[
jj] = theLogicalVolumes[
jj]->GetName();
268 theMaterials[
jj] = theLogicalVolumes[
jj]->GetMaterial();
269 theMaterialNames[
jj] = theMaterials[
jj]->GetName();
271 edm::LogVerbatim(
"ZdcAnalysis") <<
" GHD " <<
jj <<
": " << theReplicaNumbers[
jj] <<
"," << thePVnames[
jj]
272 <<
"," << theLVnames[
jj] <<
"," << theMaterialNames[
jj];
275 idLayer = theReplicaNumbers[1];
276 if (thePVnames[0] ==
"ZDC_EMLayer")
278 else if (thePVnames[0] ==
"ZDC_EMAbsorber")
280 else if (thePVnames[0] ==
"ZDC_EMFiber")
282 else if (thePVnames[0] ==
"ZDC_HadLayer")
284 else if (thePVnames[0] ==
"ZDC_HadAbsorber")
286 else if (thePVnames[0] ==
"ZDC_HadFiber")
288 else if (thePVnames[0] ==
"ZDC_PhobosLayer")
290 else if (thePVnames[0] ==
"ZDC_PhobosAbsorber")
292 else if (thePVnames[0] ==
"ZDC_PhobosFiber")
298 << thePVnames[0] <<
"," << theLVnames[0] <<
"," << theMaterialNames[0];
301 int theReplicaNumber = touch->GetReplicaNumber(0);
302 G4VPhysicalVolume* thePhysicalVolume = touch->GetVolume(0);
303 const G4String& thePVname = thePhysicalVolume->GetName();
304 G4LogicalVolume* theLogicalVolume = thePhysicalVolume->GetLogicalVolume();
305 const G4String& theLVname = theLogicalVolume->GetName();
306 G4Material* theMaterial = theLogicalVolume->GetMaterial();
307 const G4String& theMaterialName = theMaterial->GetName();
309 edm::LogVerbatim(
"ZdcAnalysis") <<
" hd=0 " << theReplicaNumber <<
"," << thePVname <<
"," << theLVname <<
"," 315 double NCherPhot = -1;
342 edm::LogVerbatim(
"ZdcAnalysis") <<
"\nZdcTest::upDate(const EndOfEvent * evt) - event #" << (*evt)()->GetEventID()
343 <<
"\n # of aSteps followed in event = " <<
stepIndex;
346 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
349 int theZDCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"ZDCHITS");
359 float ETot = 0., SEnergy = 0.;
362 unsigned int unsignedfiberID = 0;
363 std::map<int, float, std::less<int> > energyInFibers;
364 std::map<int, float, std::less<int> > primaries;
365 float totalEnergy = 0;
366 int nentries = theZDCHC->entries();
367 edm::LogVerbatim(
"ZdcAnalysis") <<
" theZDCHC has " << nentries <<
" entries";
371 for (
int ihit = 0; ihit < nentries; ihit++) {
376 for (
int ihit = 0; ihit < nentries; ihit++) {
380 double enEm = aHit->
getEM();
381 double enHad = aHit->
getHadr();
386 <<
" entry #" << ihit <<
": fiberID=0x" << std::hex << fiberID <<
std::dec <<
"; enEm=" << enEm
387 <<
"; enHad=" << enHad <<
"; hitEnergy=" << hitEnergy <<
"z=" << hitPoint.z();
388 energyInFibers[fiberID] += enEm + enHad;
389 primaries[aHit->
getTrackID()] += enEm + enHad;
394 int thesubdet, thelayer, thefiber, thechannel, thez;
396 int unsignedsubdet, unsignedlayer, unsignedfiber, unsignedchannel, unsignedz;
398 unsignedfiberID, unsignedsubdet, unsignedlayer, unsignedfiber, unsignedchannel, unsignedz);
424 for (
std::map<
int,
float, std::less<int> >::iterator is = energyInFibers.begin(); is != energyInFibers.end();
432 G4PrimaryParticle* thePrim =
nullptr;
433 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
438 for (
int i = 0;
i < nvertex;
i++) {
439 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
440 if (avertex ==
nullptr) {
441 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTest End Of Event ERR: pointer to vertex = 0";
444 int npart = avertex->GetNumberOfParticle();
447 if (thePrim ==
nullptr)
448 thePrim = avertex->GetPrimary(trackID);
452 double px = 0.,
py = 0., pz = 0.;
455 if (thePrim !=
nullptr) {
456 px = thePrim->GetPx();
457 py = thePrim->GetPy();
458 pz = thePrim->GetPz();
461 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTest End Of Event ERR: primary has p=0 ";
464 edm::LogVerbatim(
"ZdcAnalysis") <<
"ZdcTest End Of Event ERR: could not find primary ";
471 int iEvt = (*evt)()->GetEventID();
474 else if ((iEvt < 100) && (iEvt % 10 == 0))
476 else if ((iEvt < 1000) && (iEvt % 100 == 0))
478 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
ZdcNumberingScheme * theZdcNumScheme
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)