37 #include "G4SDManager.hh"
38 #include "G4VProcess.hh"
39 #include "G4HCofThisEvent.hh"
40 #include "CLHEP/Units/GlobalSystemOfUnits.h"
41 #include "CLHEP/Units/GlobalPhysicalConstants.h"
56 double beamEta = (fMaxEta+fMinEta)/2.;
57 double beamPhi = (fMaxPhi+fMinPhi)/2.;
58 double beamThet= 2*atan(
exp(-beamEta));
59 if (beamPhi < 0) beamPhi += twopi;
60 iceta = (int)(beamEta/0.087) + 1;
61 icphi = (int)(fabs(beamPhi)/0.087) + 5;
64 produces<PHcalTB06Info>();
67 beamline_RM->rotateZ(-beamPhi);
68 beamline_RM->rotateY(-beamThet);
70 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06:: Initialised as observer of BeginOf"
71 <<
"Job/BeginOfRun/BeginOfEvent/G4Step/EndOfEvent"
72 <<
" with Parameter values:\n \tbeamOffset = "
73 << beamOffset <<
"\ticeta = " <<
iceta
74 <<
"\ticphi = " <<
icphi <<
"\n\tbeamline_RM = "
84 edm::LogInfo(
"HcalTBSim") <<
"\n --------> Total number of selected entries"
85 <<
" : " <<
count <<
"\nPointers:: Histo " <<
histo;
113 int irun = (*run)()->GetRunID();
114 edm::LogInfo(
"HcalTBSim") <<
" =====> Begin of Run = " << irun;
120 evNum = (*evt) ()->GetEventID ();
122 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06Analysis: =====> Begin of event = "
130 G4ThreeVector thePreStepPoint = aStep->GetPreStepPoint()->GetPosition();
131 G4ThreeVector thePostStepPoint;
134 G4Track* aTrack = aStep->GetTrack();
135 int trackID = aTrack->GetTrackID();
136 int parentID = aTrack->GetParentID();
137 G4ThreeVector
position = aTrack->GetPosition();
138 G4ThreeVector momentum = aTrack->GetMomentum();
139 G4String partType = aTrack->GetDefinition()->GetParticleType();
140 G4String partSubType = aTrack->GetDefinition()->GetParticleSubType();
141 int partPDGEncoding = aTrack->GetDefinition()->GetPDGEncoding();
143 bool isPDGStable = aTrack->GetDefinition()->GetPDGStable();
145 double pDGlifetime = aTrack->GetDefinition()->GetPDGLifeTime();
146 double gammaFactor = aStep->GetPreStepPoint()->GetGamma();
149 double stepDeltaEnergy = aStep->GetDeltaEnergy ();
150 double kinEnergy = aTrack->GetKineticEnergy ();
153 if (trackID == 1 && parentID == 0 &&
154 ((kinEnergy == 0.) || (fabs (stepDeltaEnergy / kinEnergy) > 0.1))) {
156 if (kinEnergy == 0.) {
159 if (fabs (stepDeltaEnergy / kinEnergy) > 0.1) pvType = 1;
168 G4String thePostPVname =
"NoName";
169 G4StepPoint * thePostPoint = aStep->GetPostStepPoint ();
171 thePostStepPoint = thePostPoint->GetPosition();
172 G4VPhysicalVolume * thePostPV = thePostPoint->GetPhysicalVolume ();
173 if (thePostPV) thePostPVname = thePostPV->GetName ();
176 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: V1 found at: "
177 << thePostStepPoint <<
" G4VPhysicalVolume: "
180 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis::fill_v1Pos: Primary Track "
186 if ((trackID != 1 && parentID == 1 &&
187 (aTrack->GetCurrentStepNumber () == 1) &&
189 (trackID == 1 && thePreStepPoint ==
pvPosition)) {
191 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis::A secondary... PDG:"
192 << partPDGEncoding <<
" TrackID:" << trackID
193 <<
" ParentID:" << parentID <<
" stable: "
194 << isPDGStable <<
" Tau: " << pDGlifetime
196 << c_light*pDGlifetime*gammaFactor*1000.
197 <<
"um" <<
" GammaFactor: " << gammaFactor;
202 secEkin.push_back(aTrack->GetKineticEnergy());
205 double ctaugamma_um = c_light * pDGlifetime * gammaFactor * 1000.;
206 if ((ctaugamma_um>0.) && (ctaugamma_um<100.)) {
214 if (aTrack->GetCurrentStepNumber() == 1) {
219 std::vector<int>::iterator
pos;
220 for (pos = pos1; pos != pos2; pos++) {
224 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: A tertiary... PDG:"
225 << partPDGEncoding <<
" TrackID:" <<trackID
226 <<
" ParentID:" << parentID <<
" stable: "
227 << isPDGStable <<
" Tau: " << pDGlifetime
229 << c_light*pDGlifetime*gammaFactor*1000.
230 <<
"um GammaFactor: " << gammaFactor;
245 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis::Fill event "
246 << (*evt)()->GetEventID();
250 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis::Final analysis";
253 int iEvt = (*evt)()->GetEventID();
255 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06Analysis:: Event " << iEvt;
256 else if ((iEvt < 100) && (iEvt%10 == 0))
257 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06Analysis:: Event " << iEvt;
258 else if ((iEvt < 1000) && (iEvt%100 == 0))
259 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06Analysis:: Event " << iEvt;
260 else if ((iEvt < 10000) && (iEvt%1000 == 0))
261 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06Analysis:: Event " << iEvt;
266 std::vector<CaloHit> hhits;
269 std::map<int,float,std::less<int> > primaries;
270 double etot1=0, etot2=0;
273 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
274 std::string sdName =
names[0];
275 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(sdName);
277 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Hit Collection for " << sdName
278 <<
" of ID " << idHC <<
" is obtained at " << theHC;
280 if (idHC >= 0 && theHC > 0) {
281 hhits.reserve(theHC->entries());
282 for (j = 0; j < theHC->entries(); j++) {
288 double theta = pos.theta();
290 double phi = pos.phi();
292 hhits.push_back(hit);
296 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Hcal Hit i/p " << j
297 <<
" ID 0x" << std::hex <<
id << std::dec
298 <<
" time " << std::setw(6) << time <<
" theta "
299 << std::setw(8) << theta <<
" eta " << std::setw(8)
300 << eta <<
" phi " << std::setw(8) << phi <<
" e "
301 << std::setw(8) << e;
307 std::vector<CaloHit>::iterator itr;
308 int nHit = hhits.size();
309 std::vector<CaloHit*> hits(nHit);
310 for (j = 0, itr = hhits.begin(); itr != hhits.end(); j++, itr++) {
314 std::vector<CaloHit*>::iterator k1, k2;
316 for (k1 = hits.begin(); k1 != hits.end(); k1++) {
317 int det = (**k1).det();
318 int layer = (**k1).layer();
319 double ehit = (**k1).e();
320 double eta = (**k1).eta();
321 double phi = (**k1).phi();
322 double jitter = (**k1).t();
323 uint32_t unitID = (**k1).id();
325 for (k2 = k1+1; k2 != hits.end() && fabs(jitter-(**k2).t())<1 &&
326 unitID==(**k2).id(); k2++) {
331 CaloHit hit(det, layer, ehit, eta, phi, jitter, unitID);
336 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Hcal Hit store " << nhit
337 <<
" ID 0x" << std::hex << unitID << std::dec
338 <<
" time " << std::setw(6) << jitter <<
" eta "
339 << std::setw(8) << eta <<
" phi " << std::setw(8)
340 << phi <<
" e " << std::setw(8) << ehit;
343 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Stores " << nhit <<
" HCal hits"
344 <<
" from " << nHit <<
" input hits E(Hcal) " << etot1
348 std::vector<CaloHit> ehits;
350 idHC = G4SDManager::GetSDMpointer()->GetCollectionID(sdName);
353 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Hit Collection for " << sdName
354 <<
" of ID " << idHC <<
" is obtained at " << theHC;
355 if (idHC >= 0 && theHC > 0) {
356 ehits.reserve(theHC->entries());
357 for (j = 0; j < theHC->entries(); j++) {
363 double theta = pos.theta();
365 double phi = pos.phi();
366 if (e < 0 || e > 100000.) e = 0;
368 ehits.push_back(hit);
372 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Ecal Hit i/p " << j
373 <<
" ID 0x" << std::hex <<
id << std::dec
374 <<
" time " << std::setw(6) << time <<
" theta "
375 << std::setw(8) << theta <<
" eta " <<std::setw(8)
376 << eta <<
" phi " << std::setw(8) << phi <<
" e "
377 << std::setw(8) << e;
384 std::vector<CaloHit*> hite(nHit);
385 for (j = 0, itr = ehits.begin(); itr != ehits.end(); j++, itr++) {
390 for (k1 = hite.begin(); k1 != hite.end(); k1++) {
391 int det = (**k1).det();
392 int layer = (**k1).layer();
393 double ehit = (**k1).e();
394 double eta = (**k1).eta();
395 double phi = (**k1).phi();
396 double jitter = (**k1).t();
397 uint32_t unitID = (**k1).id();
399 for (k2 = k1+1; k2 != hite.end() && fabs(jitter-(**k2).t())<1 &&
400 unitID==(**k2).id(); k2++) {
405 CaloHit hit(det, layer, ehit, eta, phi, jitter, unitID);
410 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Ecal Hit store " << nhit
411 <<
" ID 0x" << std::hex << unitID << std::dec
412 <<
" time " << std::setw(6) << jitter <<
" eta "
413 << std::setw(8) << eta <<
" phi " << std::setw(8)
414 << phi <<
" e " << std::setw(8) << ehit;
417 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Stores " << nhit <<
" ECal hits"
418 <<
" from " << nHit <<
" input hits E(Ecal) " << etot1
424 G4PrimaryParticle* thePrim=0;
425 int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
426 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Event has " << nvertex
429 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06Analysis::EndOfEvent ERROR: no "
430 <<
"vertex found for event " <<
evNum;
432 for (
int i = 0 ;
i<nvertex;
i++) {
433 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
435 edm::LogInfo(
"HcalTBSim") <<
"HcalTB06Analysis::EndOfEvent ERR: pointer "
436 <<
"to vertex = 0 for event " <<
evNum;
438 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis::Vertex number :" <<
i <<
" "
439 << avertex->GetPosition();
440 int npart = avertex->GetNumberOfParticle();
444 if (thePrim==0) thePrim=avertex->GetPrimary(trackID);
449 double px = thePrim->GetPx();
450 double py = thePrim->GetPy();
451 double pz = thePrim->GetPz();
456 <<
"primary has p=0 ";
458 double costheta = pz/
p;
461 if (px != 0 || py != 0)
phiInit = atan2(py,px);
465 edm::LogWarning(
"HcalTBSim") <<
"HcalTB06Analysis::EndOfEvent ERR: could "
466 <<
"not find primary";
484 LogDebug(
"HcalTBSim") <<
"HcalTB06Analysis:: Energy deposit at Sim Level "
525 pvUVW = G4ThreeVector();
T getParameter(std::string const &) const
void update(const BeginOfRun *run)
This routine will be called when the appropriate signal arrives.
std::vector< std::string > names
std::vector< CaloHit > ecalHitCache
void setEdep(double simtot, double sime, double simh)
void fillEdep(double etots, double eecals, double ehcals)
Geom::Theta< T > theta() const
Exp< T >::type exp(const T &t)
void setVtxPrim(int evNum, int type, double x, double y, double z, double u, double v, double w, double px, double py, double pz)
static int position[TOTALCHAMBERS][3]
virtual void produce(edm::Event &, const edm::EventSetup &)
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
void fillEvent(PHcalTB06Info &)
Tan< T >::type tan(const T &t)
void setVtxSec(int id, int pdg, double px, double py, double pz, double ek)
void saveHit(unsigned int det, double eta, double phi, double e, double t)
Log< T >::type log(const T &t)
std::vector< CaloHit > hcalHitCache
std::vector< G4ThreeVector > secMomentum
std::vector< int > shortLivedSecondaries
XYZPointD XYZPoint
point in space with cartesian internal representation
void setPrimary(int primary, int id, double energy, double eta, double phi)
void fillBuffer(const EndOfEvent *evt)
HcalTB06Analysis(const edm::ParameterSet &p)
std::vector< double > secEkin
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
double getTimeSlice() const
math::XYZPoint getEntry() const
std::vector< int > secPartID
uint32_t getUnitID() const
void fillPrimary(double energy, double eta, double phi)
virtual ~HcalTB06Analysis()
std::vector< int > secTrackID
G4RotationMatrix * beamline_RM
Power< A, B >::type pow(const A &a, const B &b)
double getEnergyDeposit() const