27 ntcastors_evt,
ntcastors_trackid,
ntcastors_charge,
ntcastors_pdgcode,
ntcastors_x,
ntcastors_y,
ntcastors_z,
ntcastors_stepl,
ntcastors_stepe,
ntcastors_eta,
ntcastors_phi,
ntcastors_vpx,
ntcastors_vpy,
ntcastors_vpz 31 ntcastore_evt,
ntcastore_ihit,
ntcastore_detector,
ntcastore_sector,
ntcastore_module,
ntcastore_enem,
ntcastore_enhad,
ntcastore_hitenergy,
ntcastore_x,
ntcastore_y,
ntcastore_z 45 std::cout<<
"============================================================================"<<std::endl;
46 std::cout <<
"CastorTestAnalysis:: Initialized as observer"<< std::endl;
47 if (doNTcastorstep > 0){
48 std::cout <<
" Step Ntuple will be created"<< std::endl;
49 std::cout <<
" Step Ntuple file: "<<stepNtFileName<<std::endl;
51 if (doNTcastorevent > 0){
52 std::cout <<
" Event Ntuple will be created"<< std::endl;
53 std::cout <<
" Step Ntuple file: "<<stepNtFileName<<std::endl;
55 std::cout<<
"============================================================================"<<std::endl;
58 if (doNTcastorstep > 0)
59 castorstepntuple =
new TNtuple(
"NTcastorstep",
"NTcastorstep",
"evt:trackid:charge:pdgcode:x:y:z:stepl:stepe:eta:phi:vpx:vpy:vpz");
61 if (doNTcastorevent > 0)
62 castoreventntuple =
new TNtuple(
"NTcastorevent",
"NTcastorevent",
"evt:ihit:detector:sector:module:enem:totalenergy:hitenergy:x:y:z");
70 std::cout << std::endl <<
"End of CastorTestAnalysis" 74 std::cout<<
"CastorTestAnalysis: End of process"<<std::endl;
81 std::cout <<
" Starting new job " << std::endl;
87 std::cout << std::endl <<
"CastorTestAnalysis: Starting Run"<< std::endl;
89 std::cout <<
"CastorTestAnalysis: output step root file created"<< std::endl;
96 std::cout <<
"CastorTestAnalysis: output event root file created"<< std::endl;
119 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
121 G4double stepL = aStep->GetStepLength();
122 G4double stepE = aStep->GetTotalEnergyDeposit();
125 std::cout <<
"Step " << stepL <<
", " << stepE << std::endl;
127 G4Track * theTrack = aStep->GetTrack();
128 G4int theTrackID = theTrack->GetTrackID();
129 G4double
theCharge = theTrack->GetDynamicParticle()->GetCharge();
131 G4int pdgcode = theTrack->GetDefinition()->GetPDGEncoding();
133 const G4ThreeVector& vert_mom = theTrack->GetVertexMomentumDirection();
134 G4double vpx = vert_mom.x();
135 G4double vpy = vert_mom.y();
136 G4double vpz = vert_mom.z();
137 double eta = 0.5 *
log( (1.+vpz) / (1.-vpz) );
138 double phi = atan2(vpy,vpx);
140 const G4ThreeVector& hitPoint = preStepPoint->GetPosition();
185 if ( theTrack->GetNextVolume() != 0 )
186 LogDebug(
"ForwardSim") <<
" NextVolume: " << theTrack->GetNextVolume()->GetName() ;
188 LogDebug(
"ForwardSim") <<
" NextVolume: OutOfWorld" ;
201 std::cout << std::endl <<
"CastorTest::update(EndOfEvent * evt) - event #" << (*evt)()->GetEventID() << std::endl;
204 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
205 std::cout <<
"update(*evt) --> accessed all HC";
207 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"CastorFI");
237 G4PrimaryParticle* thePrim=
nullptr;
238 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
239 std::cout <<
"Event has " << nvertex <<
" vertex" << std::endl;
240 if (nvertex==0)
std::cout <<
"CASTORTest End Of Event ERROR: no vertex" << std::endl;
242 for (
int i = 0 ;
i<nvertex;
i++) {
243 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
244 if (avertex ==
nullptr)
245 std::cout <<
"CASTORTest End Of Event ERR: pointer to vertex = 0" << std::endl;
246 std::cout <<
"Vertex number :" <<
i << std::endl;
247 int npart = avertex->GetNumberOfParticle();
249 std::cout <<
"CASTORTest End Of Event ERR: no primary!" << std::endl;
250 if (thePrim==
nullptr) thePrim=avertex->GetPrimary(trackID);
253 double px=0.,py=0.,pz=0., pInit=0;
254 double eta = 0.,
phi = 0.;
256 if (thePrim !=
nullptr) {
257 px = thePrim->GetPx();
258 py = thePrim->GetPy();
259 pz = thePrim->GetPz();
262 std::cout <<
"CASTORTest End Of Event ERR: primary has p=0 " << std::endl;
264 float costheta = pz/pInit;
268 if (px != 0)
phi = atan(py/px);
270 particleType = thePrim->GetPDGcode();
272 std::cout <<
"CASTORTest End Of Event ERR: could not find primary " 275 LogDebug(
"ForwardSim") <<
"CastorTestAnalysis: Particle Type " 276 << particleType <<
" p/eta/phi " << pInit <<
", " 277 << eta <<
", " <<
phi;
280 int iEvt = (*evt)()->GetEventID();
282 std::cout <<
" CastorTest Event " << iEvt << std::endl;
283 else if ((iEvt < 100) && (iEvt%10 == 0))
284 std::cout <<
" CastorTest Event " << iEvt << std::endl;
285 else if ((iEvt < 1000) && (iEvt%100 == 0))
286 std::cout <<
" CastorTest Event " << iEvt << std::endl;
287 else if ((iEvt < 10000) && (iEvt%1000 == 0))
288 std::cout <<
" CastorTest Event " << iEvt << std::endl;
290 std::cout << std::endl <<
"===>>> Done writing user histograms " << std::endl;
298 int nentries = hc->entries();
302 unsigned int volumeID=0;
303 int det=0,
zside, sector, zmodule;
304 std::map<int,float,std::less<int> > themap;
305 double totalEnergy = 0;
306 double hitEnergy = 0;
307 double en_in_sd = 0.;
309 for (
int ihit = 0; ihit < nentries; ihit++) {
314 for (
int ihit = 0; ihit < nentries; ihit++) {
357 std::cout <<
"CastorTestAnalysis: Ntuple step written" <<std::endl;
359 std::cout <<
"CastorTestAnalysis: Step file closed" << std::endl;
365 std::cout <<
"CastorTestAnalysis: Ntuple event written" << std::endl;
367 std::cout <<
"CastorTestAnalysis: Event file closed" << std::endl;
T getParameter(std::string const &) const
math::XYZPoint getPosition() const
~CastorTestAnalysis() override
Float_t castoreventarray[11]
TNtuple * castoreventntuple
TNtuple * castorstepntuple
Geom::Theta< T > theta() const
static void unpackIndex(const uint32_t &idx, int &z, int §or, int &zmodule)
CastorNumberingScheme * theCastorNumScheme
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.
CastorTestAnalysis(const edm::ParameterSet &p)
std::string stepNtFileName
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
TFile * castorOutputStepFile
uint32_t getUnitID() const
TFile * castorOutputEventFile
Power< A, B >::type pow(const A &a, const B &b)
void getCastorBranchData(const CaloG4HitCollection *hc)
std::string eventNtFileName
double getEnergyDeposit() const