52 for(
unsigned int i=0;
i<PGParticleIDs.size();
i++) {
53 switch (
int(fabs(PGParticleIDs.at(
i)))) {
67 std::cout <<
"============================================================================"<<std::endl;
68 std::cout <<
"CastorShowerLibraryMaker:: Initialized as observer" << std::endl;
69 std::cout <<
" Event Ntuple will be created" << std::endl;
70 std::cout <<
" Event Ntuple file: " << eventNtFileName << std::endl;
77 std::cout <<
"============================================================================"<<std::endl;
86 int nBinsE,nBinsEta,nBinsPhi,nEvtPerBinPhi;
110 showerholder.
SLCollection.assign(nBinsE,std::vector<std::vector<std::vector<CastorShowerEvent> > >());
112 showerholder.
nEvtInBinEta.assign(nBinsE,std::vector<int>(0));
113 showerholder.
nEvtInBinPhi.assign(nBinsE,std::vector<std::vector<int> >());
114 for(
int i=0;
i<nBinsE;
i++) {
115 showerholder.
SLCollection.at(
i).assign(nBinsEta,std::vector<std::vector<CastorShowerEvent> >());
117 showerholder.
nEvtInBinPhi.at(
i).assign(nBinsEta,std::vector<int>(0));
118 for(
int j=0;
j<nBinsEta;
j++) {
119 showerholder.
SLCollection.at(
i).at(
j).assign(nBinsPhi,std::vector<CastorShowerEvent>());
121 for(
int k=0;
k<nBinsPhi;
k++)
133 std::cout <<
"CastorShowerLibraryMaker: End of process" << std::endl;
140 std::cout <<
" CastorShowerLibraryMaker::Starting new job " << std::endl;
146 std::cout << std::endl <<
"CastorShowerLibraryMaker: Starting Run"<< std::endl;
148 std::cout <<
"CastorShowerLibraryMaker: output event root file created" << std::endl;
151 theFile =
new TFile(eventfilename,
"RECREATE");
152 theTree =
new TTree(
"CastorCherenkovPhotons",
"Cherenkov Photons");
161 theTree->Branch(
"emShowerLibInfo.",
"CastorShowerLibraryInfo", &
emInfo, bsize, split);
162 theTree->Branch(
"emParticles.",
"CastorShowerEvent", &
emShower, bsize, split);
163 theTree->Branch(
"hadShowerLibInfo.",
"CastorShowerLibraryInfo", &
hadInfo, bsize, split);
164 theTree->Branch(
"hadParticles.",
"CastorShowerEvent", &
hadShower, bsize, split);
226 std::cout <<
"CastorShowerLibraryMaker: Processing Event Number: " <<
eventIndex << std::endl;
231 static int CurrentPrimary = 0;
232 G4Track *trk = aStep->GetTrack();
233 if (trk->GetCurrentStepNumber()==1) {
234 if (trk->GetParentID()==0) CurrentPrimary = trk->GetDynamicParticle()->GetPDGcode();
235 if (CurrentPrimary==0)
236 SimG4Exception(
"CastorShowerLibraryMaker::update(G4Step) -> Primary particle undefined");
257 std::vector<G4PrimaryParticle*> thePrims =
GetPrimary(evt);
258 if (thePrims.size() == 0) {
259 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"No valid primary particle found. Skipping event" << std::endl;
264 for(
unsigned int i=0;
i<thePrims.size();
i++) {
265 G4PrimaryParticle* thePrim = thePrims.at(
i);
267 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"NULL Pointer to the primary" << std::endl;
271 int particleType = thePrim->GetPDGcode();
274 std::string SLType(
"");
275 if (particleType==11) {
277 SLType =
"Electromagnetic";
285 double px=0., py=0., pz=0., pInit = 0.,
eta = 0.,
phi = 0.;
288 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n Primary (thePrim) trackID is " << thePrim->GetTrackID() <<
"\n" ;
298 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"Event not accepted for ebin="
299 << ebin<<
",etabin="<<etabin<<
",phibin="<<phibin<<std::endl;
307 <<
"\n CastorShowerLibraryMaker::update(EndOfEvent * evt) - event #"
308 << (*evt)()->GetEventID() ;
311 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
317 edm::LogInfo(
"CastorShowerLibraryMaker") <<
" update(*evt) --> accessed all HC ";
353 unsigned int ibine,ibineta,ibinphi,ievt;
354 unsigned int jbine,jbineta,jbinphi,jevt;
356 ibine=ibineta=ibinphi=ievt=jbine=jbineta=jbinphi=jevt=0;
365 while(nEvtInTree<maxEvtInTree) {
387 theTree->SetBranchStatus(
"emShowerLibInfo.",0);
388 theTree->SetBranchStatus(
"hadShowerLibInfo.",0);
392 if (run==
NULL)
throw SimG4Exception(
"\n\nNumber of needed trigger events reached in CastorShowerLibraryMaker\n\n");
401 theTree->Write(
"",TObject::kOverwrite);
402 std::cout <<
"CastorShowerLibraryMaker: Ntuple event written" << std::endl;
404 std::cout <<
"CastorShowerLibraryMaker: Event file closed" << std::endl;
418 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nFindEnergyBin can be called only after BeginOfEvent\n\n";
419 throw SimG4Exception(
"\n\nNULL Pointer to the shower library.\n\n");
422 if (energy >= SLenergies.back())
return SLenergies.size()-1;
425 for(;i<SLenergies.size()-1;i++)
426 if (energy >= SLenergies.at(i) && energy < SLenergies.at(i+1))
return (
int)
i;
429 if (energy>=SLenergies.at(i))
return (
int)
i;
439 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nFindEtaBin can be called only after BeginOfEvent\n\n";
440 throw SimG4Exception(
"\n\nNULL Pointer to the shower library.\n\n");
443 if (eta>=SLetas.back())
return SLetas.size()-1;
445 for(;i<SLetas.size()-1;i++)
446 if (eta >= SLetas.at(i) && eta < SLetas.at(i+1))
return (
int)
i;
448 if (eta>=SLetas.at(i))
return (
int)
i;
460 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nFindPhiBin can be called only after BeginOfEvent\n\n";
461 throw SimG4Exception(
"\n\nNULL Pointer to the shower library.\n\n");
464 if (phi>=SLphis.back())
return SLphis.size()-1;
466 for(;i<SLphis.size()-1;i++)
467 if (phi >= SLphis.at(i) && phi < SLphis.at(i+1))
return (
int)
i;
469 if (phi>=SLphis.at(i))
return (
int)
i;
477 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nIsSLReady must be called when a new event starts.\n\n";
478 throw SimG4Exception(
"\n\nNOT NULL Pointer to the shower library.\n\n");
504 px=py=pz=phi=eta=0.0;
505 if (thePrim==0)
return;
506 px = thePrim->GetPx()/GeV;
507 py = thePrim->GetPy()/GeV;
508 pz = thePrim->GetPz()/GeV;
511 std::cout <<
"CastorShowerLibraryMaker::GetKinematics: ERROR: primary has p=0 " << std::endl;
514 double costheta = pz/pInit;
516 eta = -
log(
tan(theta/2.0));
517 phi = (px==0 && py==0) ? 0 : atan2(py,px);
524 std::vector<G4PrimaryParticle*> thePrims;
525 G4PrimaryParticle* thePrim = 0;
526 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
527 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"Event has " << nvertex <<
" vertex";
529 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"CastorShowerLibraryMaker::GetPrimary ERROR: no vertex";
533 for (
int i = 0 ;
i<nvertex;
i++) {
534 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
537 <<
"CastorShowerLibraryMaker::GetPrimary ERROR: pointer to vertex = 0";
540 unsigned int npart = avertex->GetNumberOfParticle();
542 for (
unsigned int j=0;
j<
npart;
j++) {
546 thePrim=avertex->GetPrimary(trackID);
549 thePrims.push_back(thePrim);
560 for(
int n=0;
n<11+(nBinsEta*nBinsPhi);
n++)
std::cout <<
"=";
562 for(
int i=0;
i<nBinsE;
i++) {
563 std::cout <<
"E bin " << SLenergies.at(
i) <<
" : ";
564 for(
int j=0;
j<nBinsEta;
j++) {
565 for(
int k=0;
k<nBinsPhi;
k++) {
572 if (ebin!=
i)
continue;
574 for(
int j=0;
j<nBinsEta;
j++) {
575 for(
int k=0;
k<nBinsPhi;
k++) {
582 for(
int n=0;
n<11+(nBinsEta*nBinsPhi);
n++)
std::cout <<
"=";
587 if (ebin<0)
return false;
590 if (etabin<0)
return false;
593 if (phibin<0)
return false;
600 int CAFIid = G4SDManager::GetSDMpointer()->GetCollectionID(
"CastorFI");
606 unsigned int volumeID=0;
607 double en_in_fi = 0.;
610 int nentries = theCAFI->entries();
611 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"Found "<<nentries <<
" hits in G4HitCollection";
613 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n Empty G4HitCollection";
625 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"Error. NULL pointer to CastorShowerEvent";
634 for (
int ihit = 0; ihit < nentries; ihit++) {
638 if (
verbosity)
edm::LogInfo(
"CastorShowerLibraryMaker") <<
"Skipping hit from trackID " << hit_particleID;
645 int zside, sector, zmodule;
646 theCastorNumScheme->
unpackIndex(volumeID, zside, sector,zmodule);
650 <<
"\n side , sector , module = " << zside <<
" , "
651 << sector <<
" , " << zmodule
652 <<
"\n nphotons = " << hitEnergy ;
656 << theCastorNumScheme->
packIndex(zside, sector,zmodule);
660 <<
"\n nentries = " << nentries
661 <<
"\n time[" << ihit <<
"] = " << time
662 <<
"\n trackID[" << ihit <<
"] = " << aHit->
getTrackID()
663 <<
"\n volumeID[" << ihit <<
"] = " << volumeID
664 <<
"\n nphotons[" << ihit <<
"] = " << hitEnergy
665 <<
"\n side, sector, module = " << zside <<
", " << sector<<
", " << zmodule
666 <<
"\n packIndex " << theCastorNumScheme->
packIndex(zside,sector,zmodule)
667 <<
"\n X,Y,Z = " << entry.x() <<
","<< entry.y() <<
"," << entry.z();
696 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"No hits found for this track (trackID=" << ipart <<
")." << std::endl;
701 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"Filling the SL vector with new element ("<<nHits<<
" hits)";
708 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nSLnEvtInBinE can be called only after BeginOfEvent\n\n";
717 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nSLnEvtInBinEta can be called only after BeginOfEvent\n\n";
726 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nSLnEvtInBinPhi can be called only after BeginOfEvent\n\n";
734 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nSLisEBinFilled can be called only after BeginOfEvent\n\n";
743 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nSLisEtaBinFilled can be called only after BeginOfEvent\n\n";
752 edm::LogInfo(
"CastorShowerLibraryMaker") <<
"\n\nSLisPhiBinFilled can be called only after BeginOfEvent\n\n";
std::string eventNtFileName
std::vector< double > SLEtaBins
T getParameter(std::string const &) const
void setNBins(unsigned int n)
math::XYZPoint getPosition() const
void setPrimEta(float eta)
int & SLnEvtInBinE(int ebin)
void setDetID(unsigned int id)
CastorShowerEvent * hadShower
std::vector< double > SLPhiBins
int & SLnEvtInBinEta(int ebin, int etabin)
void setPrimPhi(float phi)
CastorShowerLibraryInfo SLInfo
virtual ~CastorShowerLibraryMaker()
Geom::Theta< T > theta() const
double getIncidentEnergy() const
void InitSLHolder(ShowerLib &)
void printSLstatus(int, int, int)
bool SLacceptEvent(int, int, int)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
bool SLisEtaBinFilled(int ebin, int etabin)
static void unpackIndex(const uint32_t &idx, int &z, int §or, int &zmodule)
static int position[TOTALCHAMBERS][3]
void setNEvtPerBin(unsigned int n)
bool SLisEBinFilled(int ebin)
CastorShowerLibraryInfo * hadInfo
std::vector< int > nEvtInBinE
const T & max(const T &a, const T &b)
int FindEnergyBin(double e)
std::pair< std::string, MonitorElement * > entry
Tan< T >::type tan(const T &t)
std::vector< std::vector< std::vector< int > > > nEvtInBinPhi
unsigned int nEvtPerBinPhi
std::map< int, std::set< int > > MapOfSecondaries
CastorShowerLibraryInfo * emInfo
CastorShowerLibraryMaker(const edm::ParameterSet &p)
void GetKinematics(G4PrimaryParticle *, double &px, double &py, double &pz, double &pInit, double &eta, double &phi)
Log< T >::type log(const T &t)
int & SLnEvtInBinPhi(int ebin, int etabin, int phibin)
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< std::vector< int > > nEvtInBinEta
void setHitPosition(Point p)
int FindPhiBin(double phi)
std::vector< G4PrimaryParticle * > GetPrimary(const EndOfEvent *)
void setNEvts(unsigned int n)
void update(const BeginOfJob *run)
This routine will be called when the appropriate signal arrives.
unsigned int nEvtPerBinEta
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
bool SLisPhiBinFilled(int ebin, int etabin, int phibin)
bool FillShowerEvent(G4HCofThisEvent *, CastorShowerEvent *, int)
double getTimeSlice() const
std::vector< double > SLEnergyBins
int FindEtaBin(double eta)
math::XYZPoint getEntry() const
std::vector< int > PGParticleIDs
uint32_t getUnitID() const
static uint32_t packIndex(int z, int sector, int zmodule)
void setNphotons(float np)
CastorShowerEvent * emShower
void setNhit(unsigned int i)
Power< A, B >::type pow(const A &a, const B &b)
double getEnergyDeposit() const