30 RanGen =
new CLHEP::HepJamesRandom;
72 TH1D* ene =
new TH1D(
"ene",
"generated energy",210,0.,1050.);
73 TH1D* the =
new TH1D(
"the",
"generated theta",90,0.,90.);
74 TH1D*
phi =
new TH1D(
"phi",
"generated phi",120,0.,360.);
75 TH3F* ver =
new TH3F(
"ver",
"Z-X-Y coordinates",100,-25.,25.,20,-10.,10.,40,-10.,10.);
112 double E = 0.;
double Theta = 0.;
double Phi = 0.;
double RxzV = 0.;
double PhiV = 0.;
113 if (
int(
Nsel)%100 == 0)
std::cout <<
" generated " << int(
Nsel) <<
" events" << std::endl;
115 bool notSelected =
true;
117 bool badMomentumGenerated =
true;
118 while (badMomentumGenerated){
128 badMomentumGenerated =
false;
136 bool badVertexGenerated =
true;
137 while (badVertexGenerated){
142 double rotPhi = PhiV +
Pi;
if (rotPhi >
TwoPi) rotPhi -=
TwoPi;
143 double disPhi = std::fabs(rotPhi - Phi);
if (disPhi > Pi) disPhi =
TwoPi - disPhi;
144 if (disPhi < dPhi ||
AcptAllMu) badVertexGenerated =
false;
153 double verMom = absMom*
cos(Theta);
154 double horMom = absMom*
sin(Theta);
155 double Px = horMom*
sin(Phi);
157 double Pz = horMom*
cos(Phi);
158 double Vx = RxzV*
sin(PhiV);
166 double Vz = RxzV*
cos(PhiV);
253 if (
Debug)
std::cout <<
"\nEntered CosmicMuonGenerator::nextMultiEvent()" << std::endl;
254 bool EvtRejected =
true;
255 bool MuInMaxDist =
false;
258 while (EvtRejected) {
266 if (ientry < 0)
return false;
271 std::cout <<
"CosmicMuonGenerator.cc::nextMultiEvent: No more events in file!" << std::endl;
280 " muons in event!" << std::endl;
281 std::cout <<
"trying next event from file" << std::endl;
296 for (
int imu=0; imu<nmuons; ++imu) {
310 for (
int jmu=0; jmu<imu; ++jmu) {
319 if (MuMuDist < MinDist) MinDist = MuMuDist;
328 std::cout <<
"CosmicMuonGenerator.cc: Warning! No muon pair closer than "
329 << 2.*
Target3dRadius/1000. <<
"m MinDist=" << MinDist/1000. <<
"m at surface" << std::endl;
330 std::cout <<
"Fraction of too wide opening angle multi muon events: "
333 std::cout <<
"trying next event from file" << std::endl;
346 std::cout <<
"start trial do loop: MuMuDist=" << MinDist/1000. <<
"[m] Nmuons="
363 if (phi_at < -
Pi) phi_at +=
TwoPi;
364 else if (phi_at >
Pi) phi_at -=
TwoPi;
376 double phi_rel_min = 0.;
377 double phi_rel_max = 0.;
382 for (
int imu=0; imu<nmuons; ++imu) {
388 double phi_rel = phi_mu - phi_at;
389 if (phi_rel < -
Pi) phi_rel +=
TwoPi;
390 else if (phi_rel >
Pi) phi_rel -=
TwoPi;
391 if (phi_rel < phi_rel_min) phi_rel_min = phi_rel;
392 else if (phi_rel > phi_rel_max) phi_rel_max =phi_rel;
402 double JdRxzV_dR_trans = 1.;
403 double JdPhiV_dPhi_trans = 1.;
404 double JdR_trans_sqrt = 1.;
410 double R_min =
std::max(0., R_mu_min);
413 std::cout <<
"CosmicMuonGenerator.cc: Warning! R_at=" << R_at
421 double psR1min = R_min + 0.25*(R_max-R_min);
423 double psR1 = psR1max - psR1min;
425 double psR2min = R_min;
426 double psR2max = R_max;
427 double psR2 = psR2max - psR2min;
431 double psR3 = psR3max - psR3min;
434 double psRall = psR3;
436 double fR1=psR1/psRall, fR2=psR2/psRall, fR3=psR3/psRall;
437 double pR1=0.25, pR2=0.7, pR3=0.05;
441 double psPh1 = 0.5*(phi_rel_max - phi_rel_min);
442 double psPh2 = phi_rel_max - phi_rel_min;
443 double psPh3 =
TwoPi;
444 double psPhall = psPh3;
446 double fPh1=psPh1/psPhall, fPh2=psPh2/psPhall, fPh3=psPh3/psPhall;
448 double pPh1=0.25, pPh2=0.7, pPh3=0.05;
453 int NmuHitTarget = 0;
462 double which_R_class =
RanGen->flat();
463 if (which_R_class < pR1) {
464 RxzV = psR1min + psR1 *
RanGen->flat();
467 else if (which_R_class < pR1+pR2) {
468 RxzV = psR2min + psR2 *
RanGen->flat();
472 RxzV = psR3min + psR3 *
RanGen->flat();
480 double which_phi_class =
RanGen->flat();
481 if (which_phi_class < pPh1) {
482 PhiV = phi_at + phi_rel_min + psPh1 *
RanGen->flat();
483 JdPhiV_dPhi_trans = fPh1/pPh1 *
TwoPi/psPh1;
485 else if (which_phi_class < pPh1+pPh2) {
486 PhiV = phi_at + phi_rel_min + psPh2 *
RanGen->flat();
487 JdPhiV_dPhi_trans = fPh2/pPh2 *
TwoPi/psPh2;
490 PhiV = phi_at + phi_rel_min + psPh3 *
RanGen->flat();
491 JdPhiV_dPhi_trans = fPh3/pPh3 *
TwoPi/psPh3;
496 else if (PhiV >
Pi) PhiV-=
TwoPi;
500 trials += JdR_trans_sqrt * JdRxzV_dR_trans * JdPhiV_dPhi_trans;
513 int NmuHitTargetSphere = 0;
514 for (
int imu=0; imu<nmuons; ++imu) {
525 double theta_sec = atan2(std::fabs(
Py_mu[imu]),pt_sec);
528 double h_prod = r_sec *
tan(theta_sec);
529 if (h_prod + h_sf >
Vy_at)
Vy_at = h_prod + h_sf;
547 double rotPhi = PhiVmu +
Pi;
if (rotPhi > Pi) rotPhi -=
TwoPi;
548 double disPhi = std::fabs(rotPhi - PhiPmu);
if (disPhi > Pi) disPhi =
TwoPi - disPhi;
550 NmuHitTargetSphere++;
587 double Px_sf_this =0., Py_sf_this=0., Pz_sf_this=0.;
590 double Vx_sf_this=0., Vy_sf_this=0., Vz_sf_this=0.;
591 double T0_sf_this=0.;
595 for (
int imu=0; imu<nmuons; ++imu) {
603 if (Id_sf_this == 5) Id_sf_this = -13;
604 else if (Id_sf_this == 6) Id_sf_this = 13;
606 else if (Id_sf_this == 1) Id_sf_this = 22;
607 else if (Id_sf_this == 2) Id_sf_this = -11;
608 else if (Id_sf_this == 3) Id_sf_this = 11;
609 else if (Id_sf_this == 7) Id_sf_this = 111;
610 else if (Id_sf_this == 8) Id_sf_this = 211;
611 else if (Id_sf_this == 9) Id_sf_this = -211;
612 else if (Id_sf_this == 10) Id_sf_this = 130;
613 else if (Id_sf_this == 11) Id_sf_this = 321;
614 else if (Id_sf_this == 12) Id_sf_this = -321;
615 else if (Id_sf_this == 13) Id_sf_this = 2112;
616 else if (Id_sf_this == 14) Id_sf_this = 2212;
617 else if (Id_sf_this == 15) Id_sf_this = -2212;
618 else if (Id_sf_this == 16) Id_sf_this = 310;
619 else if (Id_sf_this == 17) Id_sf_this = 221;
620 else if (Id_sf_this == 18) Id_sf_this = 3122;
623 std::cout <<
"CosmicMuonGenerator.cc: Warning! Muon Id=" << Id_sf_this
624 <<
" from file read in" <<std::endl;
630 Px_sf_this =
Px_mu[imu];
631 Py_sf_this =
Py_mu[imu];
632 Pz_sf_this =
Pz_mu[imu];
634 Vx_sf_this =
Vx_mu[imu];
635 Vy_sf_this =
Vy_mu[imu];
636 Vz_sf_this =
Vz_mu[imu];
639 OneMuoEvt.
create(Id_sf_this, Px_sf_this, Py_sf_this, Pz_sf_this, E_sf_this, MuonMass, Vx_sf_this, Vy_sf_this, Vz_sf_this, T0_sf_this);
649 Id_sf.push_back(Id_sf_this);
650 Px_sf.push_back(Px_sf_this);
651 Py_sf.push_back(Py_sf_this);
652 Pz_sf.push_back(Pz_sf_this);
653 E_sf.push_back(E_sf_this);
655 Vx_sf.push_back(Vx_sf_this);
656 Vy_sf.push_back(Vy_sf_this);
657 Vz_sf.push_back(Vz_sf_this);
658 T0_sf.push_back(T0_sf_this);
682 <<
" without accepting event!" << std::endl;
699 " muons hit target: N(mu=)" << NmuHitTarget << std::endl;
708 double T0_ug_min, T0_ug_max;
709 T0_ug_min = T0_ug_max =
T0_ug[0];
711 double minDeltaT0 = 2*Tbox;
712 for (
unsigned int imu=0; imu<
Id_ug.size(); ++imu) {
713 double T0_this =
T0_ug[imu];
714 if (T0_this < T0_ug_min) T0_ug_min = T0_this;
715 if (T0_this > T0_ug_max) T0_ug_max = T0_this;
719 for (
unsigned int jmu=0; jmu<imu; ++jmu) {
720 if (std::fabs(
T0_ug[imu]-
T0_ug[jmu]) < minDeltaT0) minDeltaT0 = std::fabs(
T0_ug[imu]-
T0_ug[jmu]);
733 double T0_offset, T0diff;
734 for (
int tboxtrial=0; tboxtrial<1000; ++tboxtrial) {
735 T0_offset =
RanGen->flat()*(T0_max -T0_min);
737 T0diff = T0_offset - T0_max;
739 for (
unsigned int imu=0; imu<
Id_ug.size(); ++imu) {
749 if (
Debug)
std::cout <<
"initial T0_at=" <<
T0_at <<
" T0_min=" << T0_min <<
" T0_max=" << T0_max
750 <<
" T0_offset=" << T0_offset;
753 for (
unsigned int imu=0; imu<
Id_ug.size(); ++imu) {
755 T0_sf[imu] += T0diff;
756 T0_ug[imu] += T0diff;
758 std::cout <<
" after: T0_sf[" << imu <<
"]=" <<
T0_sf[imu] <<
" T0_ug=" << T0_ug[imu] << std::endl;
765 EventWeight = JdR_trans_sqrt * JdRxzV_dR_trans * JdPhiV_dPhi_trans
766 / (trials * TboxTrials);
770 <<
" T0_at=" <<
T0_at
772 <<
" EventWeight=" <<
EventWeight <<
" Nmuons=" <<
Id_sf.size() << std::endl;
789 std::cout <<
"*********************************************************" << std::endl;
790 std::cout <<
"*********************************************************" << std::endl;
792 std::cout <<
"*** C O S M I C M U O N S T A T I S T I C S ***" << std::endl;
794 std::cout <<
"*********************************************************" << std::endl;
795 std::cout <<
"*********************************************************" << std::endl;
797 std::cout <<
" number of initial cosmic events: " << int(
Ngen) << std::endl;
798 std::cout <<
" number of actually diced events: " << int(
Ndiced) << std::endl;
799 std::cout <<
" number of generated and accepted events: " << int(
Nsel) << std::endl;
801 std::cout <<
" event selection efficiency: " << selEff*100. <<
"%" << std::endl;
803 std::cout <<
" events with ~100 GeV and 1 - cos(theta) < 1/2pi: " << n100cos << std::endl;
805 std::cout <<
" momentum range: " <<
MinP <<
" ... " <<
MaxP <<
" GeV" << std::endl;
813 std::cout <<
" area of initial cosmics at CMS detector bottom surface: " << area <<
" m^2" << std::endl;
815 std::cout <<
" area of initial cosmics on Surface + PlugWidth: " << area <<
" m^2" << std::endl;
857 std::cout <<
" !!! MinP > 100 GeV. Cannot apply normalisation!" << std::endl;
859 std::cout <<
" !!! Note: generated cosmics exceed parameterisation. No flux calculated!" << std::endl;
862 std::cout <<
" !!! Not enough statistics to apply normalisation (rate=1 +- 1) !!!" << std::endl;
865 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
867 rateErr_syst <<
" (syst) " <<
" muons per second" << std::endl;
869 std::cout <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
871 std::cout <<
"*********************************************************" << std::endl;
872 std::cout <<
"*********************************************************" << std::endl;
878 std::cout <<
" CMG-ERR: min.energy is out of range (0 GeV ... inf]" << std::endl << std::endl; }
880 std::cout <<
" CMG-ERR: max.energy is out of range (0 GeV ... inf]" << std::endl << std::endl; }
882 std::cout <<
" CMG-ERR: max.energy is not greater than min.energy" << std::endl << std::endl; }
884 std::cout <<
" CMG-ERR: min.theta is out of range [0 deg ... 90 deg)" << std::endl << std::endl; }
886 std::cout <<
" CMG-ERR: max.theta is out of range [0 deg ... 90 deg)" << std::endl << std::endl; }
888 std::cout <<
" CMG-ERR: max.theta is not greater than min.theta" << std::endl << std::endl; }
890 std::cout <<
" CMG-ERR: min.phi is out of range [0 deg ... 360 deg]" << std::endl << std::endl; }
892 std::cout <<
" CMG-ERR: max.phi is out of range [0 deg ... 360 deg]" << std::endl << std::endl; }
894 std::cout <<
" CMG-ERR: max.phi is not greater than min.phi" << std::endl << std::endl; }
896 std::cout <<
" CMG-ERR: max.t0 is not greater than min.t0" << std::endl << std::endl; }
898 std::cout <<
" CMG-ERR: E-loss scale factor is out of range [0 ... inf)" << std::endl << std::endl; }
900 std::cout <<
" CMG-ERR: min.Enu is out of range [0 GeV ... inf]" << std::endl << std::endl; }
902 std::cout <<
" CMG-ERR: max.Enu is out of range [0 GeV ... inf]" << std::endl << std::endl; }
904 std::cout <<
" CMG-ERR: max.Enu is not greater than min.Enu" << std::endl << std::endl; }
910 bool goodAngles =
false;
911 bool phiaccepted =
false;
912 bool thetaaccepted =
false;
923 double disPhi = std::fabs(PhiV - Phi);
if (disPhi >
Pi) disPhi =
TwoPi - disPhi;
925 if (disPhi < dPhi) phiaccepted =
true;
927 double ThetaV = asin(RxzV/rVY);
934 std::cout <<
"Rejected phi=" << Phi <<
" PhiV=" << PhiV
935 <<
" dPhi=" << dPhi <<
" disPhi=" << disPhi
937 <<
" Theta=" << Theta << std::endl;
939 if (std::fabs(Theta-ThetaV) < dTheta) thetaaccepted =
true;
940 if (phiaccepted && thetaaccepted) goodAngles =
true;
952 TH2F* disXY =
new TH2F(
"disXY",
"X-Y view",160,-rCMS,rCMS,160,-rCMS,rCMS);
953 TH2F* disZY =
new TH2F(
"disZY",
"Z-Y view",150,-zCMS,zCMS,160,-rCMS,rCMS);
954 gStyle->SetPalette(1,0);
955 gStyle->SetMarkerColor(1);
956 gStyle->SetMarkerSize(1.5);
957 TCanvas *disC =
new TCanvas(
"disC",
"Cosmic Muon Event Display",0,0,800,410);
961 disXY->SetMinimum(log10(
MinP));
962 disXY->SetMaximum(log10(
MaxP));
963 disXY->GetXaxis()->SetLabelSize(0.05);
964 disXY->GetXaxis()->SetTitleSize(0.05);
965 disXY->GetXaxis()->SetTitleOffset(1.0);
966 disXY->GetXaxis()->SetTitle(
"X [m]");
967 disXY->GetYaxis()->SetLabelSize(0.05);
968 disXY->GetYaxis()->SetTitleSize(0.05);
969 disXY->GetYaxis()->SetTitleOffset(0.8);
970 disXY->GetYaxis()->SetTitle(
"Y [m]");
974 disZY->SetMinimum(log10(
MinP));
975 disZY->SetMaximum(log10(
MaxP));
976 disZY->GetXaxis()->SetLabelSize(0.05);
977 disZY->GetXaxis()->SetTitleSize(0.05);
978 disZY->GetXaxis()->SetTitleOffset(1.0);
979 disZY->GetXaxis()->SetTitle(
"Z [m]");
980 disZY->GetYaxis()->SetLabelSize(0.05);
981 disZY->GetYaxis()->SetTitleSize(0.05);
982 disZY->GetYaxis()->SetTitleOffset(0.8);
983 disZY->GetYaxis()->SetTitle(
"Y [m]");
997 TMarker* InteractionPoint =
new TMarker(0.,0.,2);
998 TArc* r8m =
new TArc(0.,0.,(RadiusDet/1000.));
999 TLatex* logEaxis =
new TLatex(); logEaxis->SetTextSize(0.05);
1007 float yStep = disXY->GetYaxis()->GetBinWidth(1);
1008 int NbinY = disXY->GetYaxis()->GetNbins();
1009 for (
int iy=0; iy<NbinY; ++iy){
1013 float rXY =
sqrt(verX*verX + verY*verY)*1000.;
1014 float absZ = std::fabs(verZ)*1000.;
1015 if (rXY < RadiusDet && absZ < Z_DistDet){
1016 disXY->Fill(verX,verY,log10(energy));
1017 disZY->Fill(verZ,verY,log10(energy));
1018 disC->cd(1); disXY->Draw(
"COLZ"); InteractionPoint->Draw(
"SAME"); r8m->Draw(
"SAME");
1019 logEaxis->DrawLatex((0.65*RadiusDet/1000.),(1.08*RadiusDet/1000.),
"log_{10}E(#mu^{#pm})");
1020 disC->cd(2); disZY->Draw(
"COL"); InteractionPoint->Draw(
"SAME");
const double Z[kNumberCalorimeter]
Int_t shower_nParticlesWritten
void setZDistOfTarget(double Z)
void propagate(double ElossScaleFac, double RadiusTarget, double Z_DistTarget, double Z_CentrTarget, bool TrackerOnly, bool MTCCHalf)
void initialize(CLHEP::HepRandomEngine *rng=0)
std::vector< double > Theta_mu
int events_n100cos(double energy, double theta)
void setMinEnu(double MinEn)
void setTIFOnly_constant(bool TIF)
std::vector< double > Px_ug
void setNuProdAlt(double NuPrdAlt)
void setZCentrOfTarget(double Z)
Double_t particle__Py[kMaxparticle_]
std::vector< double > Py_mu
void setRhoAir(double VarRhoAir)
const double Z_DistTracker
Sin< T >::type sin(const T &t)
int initialize(double, double, double, double, CLHEP::HepRandomEngine *, bool, bool)
void setRandomEngine(CLHEP::HepRandomEngine *v)
void setRadiusOfTarget(double R)
Double_t particle__Time[kMaxparticle_]
void setNumberOfEvents(unsigned int N)
std::vector< double > Py_sf
virtual void Init(TTree *tree)
std::vector< double > E_sf
Double_t particle__Px[kMaxparticle_]
std::vector< double > Pz_mu
const double SpeedOfLight
Double_t particle__Pz[kMaxparticle_]
std::vector< double > E_ug
std::string MultiMuonFileName
void setMultiMuonFileFirstEvent(int MultiMuFile1stEvt)
const double NorthCMSzDeltaPhi
virtual Int_t GetEntry(Long64_t entry)
void setRhoPlug(double VarRhoPlug)
std::vector< double > Vz_ug
void setMinPhi(double Phi)
const double SurfaceOfEarth
void setMaxPhi(double Phi)
void setRandomEngine(CLHEP::HepRandomEngine *v)
std::vector< double > Vz_sf
std::vector< double > Vz_mu
double dPhi(double phi1, double phi2)
std::vector< double > Vx_sf
void setMultiMuonNmin(int MultiMuNmin)
Cos< T >::type cos(const T &t)
int NcloseMultiMuonEvents
std::vector< double > Vy_sf
void setMinTheta(double Theta)
CLHEP::HepRandomEngine * RanGen
Tan< T >::type tan(const T &t)
std::vector< double > Vx_mu
void setMaxEnu(double MaxEn)
void setMultiMuon(bool MultiMu)
void setClayWidth(double ClayLaeyrWidth)
SingleParticleEvent OneMuoEvt
std::vector< double > Vy_mu
std::vector< double > T0_sf
std::vector< double > Px_mu
int MultiMuonFileFirstEvent
std::vector< double > Px_sf
std::vector< double > Vy_ug
void setAcptAllMu(bool AllMu)
Int_t particle__ParticleID[kMaxparticle_]
double momentum_times_charge()
void setPlugVz(double PlugVtz)
void setTIFOnly_linear(bool TIF)
std::vector< double > Pz_ug
Double_t particle__x[kMaxparticle_]
void create(int id, double px, double py, double pz, double e, double m, double vx, double vy, double vz, double t0)
void setMultiMuonFileName(std::string MultiMuonFileName)
void setMTCCHalf(bool MTCC)
const double RadiusTracker
int NskippedMultiMuonEvents
void setMinP_CMS(double P)
void setElossScaleFactor(double ElossScaleFact)
void setMaxTheta(double Theta)
unsigned int NumberOfEvents
void setRhoWall(double VarRhoSWall)
void setPlugVx(double PlugVtx)
void setRhoRock(double VarRhoRock)
int initializeNuMu(double, double, double, double, double, double, double, double, double, CLHEP::HepRandomEngine *)
std::vector< double > Vx_ug
std::vector< double > P_mu
std::vector< double > Py_ug
std::vector< double > T0_ug
Power< A, B >::type pow(const A &a, const B &b)
void setRhoClay(double VarRhoClay)
std::vector< double > Pz_sf
Double_t particle__y[kMaxparticle_]
void setTrackerOnly(bool Tracker)