test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicMuonGenerator.cc
Go to the documentation of this file.
1 // modified by P. Biallass 29.03.2006 to implement new cosmic generator (CMSCGEN.cc) and new normalization of flux (CMSCGENnorm.cc)
4 // 04.12.2008 sonne: replaced Min/MaxE by Min/MaxP to get cos_sf/ug scripts working again
5 // 20.04.2009 sonne: Implemented mechanism to read in multi muon events and propagate each muon
6 #define sim_cxx
7 
8 
10 
11 
13  initialize();
14  for (unsigned int iGen=0; iGen<NumberOfEvents; ++iGen){ nextEvent(); }
15  terminate();
16 }
17 
18 void CosmicMuonGenerator::setRandomEngine(CLHEP::HepRandomEngine* v) {
19  if (delRanGen)
20  delete RanGen;
21  RanGen = v;
22  delRanGen = false;
24 }
25 
26 void CosmicMuonGenerator::initialize(CLHEP::HepRandomEngine *rng){
27  if (delRanGen)
28  delete RanGen;
29  if (!rng) {
30  RanGen = new CLHEP::HepJamesRandom;
31  RanGen->setSeed(RanSeed, 0); //set seed for Random Generator (seed can be controled by config-file)
32  delRanGen = true;
33  } else {
34  RanGen = rng;
35  delRanGen = false;
36  }
37  checkIn();
38  if (NumberOfEvents > 0){
39  // set up "surface geometry" dimensions
40  double RadiusTargetEff = RadiusOfTarget; //get this from cfg-file
41  double Z_DistTargetEff = ZDistOfTarget; //get this from cfg-file
42  //double Z_CentrTargetEff = ZCentrOfTarget; //get this from cfg-file
43  if(TrackerOnly==true){
44  RadiusTargetEff = RadiusTracker;
45  Z_DistTargetEff = Z_DistTracker;
46  }
47  Target3dRadius = sqrt(RadiusTargetEff*RadiusTargetEff + Z_DistTargetEff*Z_DistTargetEff) + MinStepSize;
48  if (Debug) std::cout << " radius of sphere around target = " << Target3dRadius << " mm" << std::endl;
49 
50  if (MinTheta > 90.*Deg2Rad) //upgoing muons from neutrinos
52  else
54  if (Debug) std::cout << " starting point radius at Surface + PlugWidth = " << SurfaceRadius << " mm" << std::endl;
55 
63  //set energy and angle limits for CMSCGEN, give same seed as above
64  if (MinTheta >= 90.*Deg2Rad) //upgoing muons from neutrinos
67  else
69 
70 #if ROOT_INTERACTIVE
71  // book histos
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.);
76 #endif
77  if (EventDisplay) initEvDis();
78  std::cout << std::endl;
79 
80  if (MultiMuon) {
81  MultiIn = 0;
82 
83  std::cout << "MultiMuonFileName.c_str()=" << MultiMuonFileName.c_str() << std::endl;
84  MultiIn = new TFile( MultiMuonFileName.c_str() );
85 
86  if (!MultiIn) std::cout << "MultiMuon=True: MultiMuonFileName='"
87  << MultiMuonFileName.c_str() << "' does not exist" << std::endl;
88  else std::cout << "MultiMuonFile: " << MultiMuonFileName.c_str() << " opened!" << std::endl;
89  //MultiTree = (TTree*) gDirectory->Get("sim");
90  MultiTree = (TTree*) MultiIn->Get("sim");
91  SimTree = new sim(MultiTree);
93  SimTreeEntries = SimTree->fChain->GetEntriesFast();
94  std::cout << "SimTreeEntries=" << SimTreeEntries << std::endl;
95 
96  if (MultiMuonFileFirstEvent <= 0)
97  SimTree_jentry = 0;
98  else
99  SimTree_jentry = MultiMuonFileFirstEvent - 1; //1=1st evt (SimTree_jentry=0)
100 
103  }
104 
105  if (!MultiMuon || (MultiMuon && MultiIn)) NotInitialized = false;
106 
107  }
108 }
109 
111 
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;
114  // generate cosmic (E,theta,phi)
115  bool notSelected = true;
116  while (notSelected){
117  bool badMomentumGenerated = true;
118  while (badMomentumGenerated){
119 
120  if (MinTheta > 90.*Deg2Rad) //upgoing muons from neutrinos
122  else
123  Cosmics->generate(); //dice one event now
124 
126  Theta = TMath::ACos( Cosmics->cos_theta() ) ; //angle has to be in RAD here
127  Ngen+=1.; //count number of initial cosmic events (in surface area), vertices will be added later
128  badMomentumGenerated = false;
129  Phi = RanGen->flat()*(MaxPhi-MinPhi) + MinPhi;
130  }
131  Norm->events_n100cos(E, Theta); //test if this muon is in normalization range
132  Ndiced += 1; //one more cosmic is diced
133 
134  // generate vertex
135  double Nver = 0.;
136  bool badVertexGenerated = true;
137  while (badVertexGenerated){
138  RxzV = sqrt(RanGen->flat())*SurfaceRadius;
139  PhiV = RanGen->flat()*TwoPi;
140  // check phi range (for a sphere with Target3dRadius around the target)
141  double dPhi = Pi; if (RxzV > Target3dRadius) dPhi = asin(Target3dRadius/RxzV);
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;
145  Nver+=1.;
146  }
147  Ngen += (Nver-1.); //add number of generated vertices to initial cosmic events
148 
149  // complete event at surface
150  int id = 13; // mu-
151  if (Cosmics->momentum_times_charge() >0.) id = -13; // mu+
152  double absMom = sqrt(E*E - MuonMass*MuonMass);
153  double verMom = absMom*cos(Theta);
154  double horMom = absMom*sin(Theta);
155  double Px = horMom*sin(Phi); // [GeV/c]
156  double Py = -verMom; // [GeV/c]
157  double Pz = horMom*cos(Phi); // [GeV/c]
158  double Vx = RxzV*sin(PhiV); // [mm]
159 
160  double Vy;
161  if (MinTheta > 90.*Deg2Rad) //upgoing muons from neutrinos
162  Vy = -RadiusCMS;
163  else
164  Vy = SurfaceOfEarth + PlugWidth; // [mm]
165 
166  double Vz = RxzV*cos(PhiV); // [mm]
167  double T0 = (RanGen->flat()*(MaxT0-MinT0) + MinT0)*SpeedOfLight; // [mm/c];
168 
169  Id_at = id;
170  Px_at = Px; Py_at = Py; Pz_at = Pz; E_at = E; //M_at = MuonMass;
171  Vx_at = Vx; Vy_at = Vy; Vz_at = Vz; T0_at = T0;
172 
173  OneMuoEvt.create(id, Px, Py, Pz, E, MuonMass, Vx, Vy, Vz, T0);
174  // if angles are ok, propagate to target
175  if (goodOrientation()) {
176  if (MinTheta > 90.*Deg2Rad) //upgoing muons from neutrinos
178  else
180  }
181 
182  if ( (OneMuoEvt.hitTarget() && sqrt(OneMuoEvt.e()*OneMuoEvt.e() - MuonMass*MuonMass) > MinP_CMS)
183  || AcptAllMu==true){
184  Nsel+=1.; //count number of generated and accepted events
185  notSelected = false;
186  }
187  }
188 
189  EventWeight = 1.;
190 
191  //just one outgoing particle at SurFace
192  Id_sf.resize(1);
193  Px_sf.resize(1);
194  Py_sf.resize(1);
195  Pz_sf.resize(1);
196  E_sf.resize(1);
197  //M_sf.resize(1);
198  Vx_sf.resize(1);
199  Vy_sf.resize(1);
200  Vz_sf.resize(1);
201  T0_sf.resize(1);
202 
203  Id_sf[0] = Id_at;
204  Px_sf[0] = Px_at; Py_sf[0] = Py_at; Pz_sf[0] = Pz_at; E_sf[0] = E_at; //M_fs[0] = MuonMass;
205  Vx_sf[0] = Vx_at; Vy_sf[0] = Vy_at; Vz_sf[0] = Vz_at; T0_sf[0] = T0_at;
206 
207 
208  //just one particle at UnderGround
209  Id_ug.resize(1);
210  Px_ug.resize(1);
211  Py_ug.resize(1);
212  Pz_ug.resize(1);
213  E_ug.resize(1);
214  //M_ug.resize(1);
215  Vx_ug.resize(1);
216  Vy_ug.resize(1);
217  Vz_ug.resize(1);
218  T0_ug.resize(1);
219 
220  Id_ug[0] = OneMuoEvt.id();
221  Px_ug[0] = OneMuoEvt.px();
222  Py_ug[0] = OneMuoEvt.py();
223  Pz_ug[0] = OneMuoEvt.pz();
224  E_ug[0] = OneMuoEvt.e();
225  //M_ug[0] = OneMuoEvt.m();
226  Vx_ug[0] = OneMuoEvt.vx();
227  Vy_ug[0] = OneMuoEvt.vy();
228  Vz_ug[0] = OneMuoEvt.vz();
229  T0_ug[0] = OneMuoEvt.t0();
230 
231  // plot variables of selected events
232 #if ROOT_INTERACTIVE
233  ene->Fill(OneMuoEvt.e());
234  the->Fill((OneMuoEvt.theta()*Rad2Deg));
235  phi->Fill((OneMuoEvt.phi()*Rad2Deg));
236  ver->Fill((OneMuoEvt.vz()/1000.),(OneMuoEvt.vx()/1000.),(OneMuoEvt.vy()/1000.));
237 #endif
238  if (Debug){
239  std::cout << "new event" << std::endl;
240  std::cout << " Px,Py,Pz,E,m = " << OneMuoEvt.px() << ", " << OneMuoEvt.py() << ", "
241  << OneMuoEvt.pz() << ", " << OneMuoEvt.e() << ", " << OneMuoEvt.m() << " GeV" << std::endl;
242  std::cout << " Vx,Vy,Vz,t0 = " << OneMuoEvt.vx() << ", " << OneMuoEvt.vy() << ", "
243  << OneMuoEvt.vz() << ", " << OneMuoEvt.t0() << " mm" << std::endl;
244  }
245  if (EventDisplay) displayEv();
246 
247 }
248 
249 
250 
252 
253  if (Debug) std::cout << "\nEntered CosmicMuonGenerator::nextMultiEvent()" << std::endl;
254  bool EvtRejected = true;
255  bool MuInMaxDist = false;
256  double MinDist; //[mm]
257 
258  while (EvtRejected) {
259 
260  //read in event from SimTree
261  //ULong64_t ientry = SimTree->LoadTree(SimTree_jentry);
262  Long64_t ientry = SimTree->GetEntry(SimTree_jentry);
263  std::cout << "CosmicMuonGenerator::nextMultiEvent(): SimTree_jentry=" << SimTree_jentry
264  //<< " ientry=" << ientry
265  << " SimTreeEntries=" << SimTreeEntries << std::endl;
266  if (ientry < 0) return false; //stop run
268  SimTree_jentry++;
269  }
270  else {
271  std::cout << "CosmicMuonGenerator.cc::nextMultiEvent: No more events in file!" << std::endl;
272  return false; //stop run
273  }
274 
275 
276 
277  int nmuons = SimTree->shower_nParticlesWritten;
278  if (nmuons<MultiMuonNmin) {
279  std::cout << "CosmicMuonGenerator.cc: Warning! Less than " << MultiMuonNmin <<
280  " muons in event!" << std::endl;
281  std::cout << "trying next event from file" << std::endl;
283  continue; //EvtRejected while loop: get next event from file
284  }
285 
286 
287 
288  Px_mu.resize(nmuons); Py_mu.resize(nmuons); Pz_mu.resize(nmuons);
289  P_mu.resize(nmuons);
290 
291  MinDist = 99999.e9; //[mm]
292  double MuMuDist;
293  MuInMaxDist = false;
294  //check if at least one muon pair closer than 30m at surface
295  int NmuPmin = 0;
296  for (int imu=0; imu<nmuons; ++imu) {
297 
302  Py_mu[imu] = -SimTree->particle__Pz[imu]; //Corsika down going particles defined in -z direction!
303  P_mu[imu] = sqrt(Px_mu[imu]*Px_mu[imu] + Py_mu[imu]*Py_mu[imu] + Pz_mu[imu]*Pz_mu[imu]);
304 
305  if (P_mu[imu] < MinP_CMS && AcptAllMu==false) continue;
306  else if (SimTree->particle__ParticleID[imu] != 5 &&
307  SimTree->particle__ParticleID[imu] != 6) continue;
308  else NmuPmin++;
309 
310  for (int jmu=0; jmu<imu; ++jmu) {
311  if (P_mu[jmu] < MinP_CMS && AcptAllMu==false) continue;
312  if (SimTree->particle__ParticleID[imu] != 5 &&
313  SimTree->particle__ParticleID[imu] != 6) continue;
314  MuMuDist = sqrt( (SimTree->particle__x[imu]-SimTree->particle__x[jmu])*
315  (SimTree->particle__x[imu]-SimTree->particle__x[jmu])
316  +(SimTree->particle__y[imu]-SimTree->particle__y[jmu])*
317  (SimTree->particle__y[imu]-SimTree->particle__y[jmu])
318  )*10.; //CORSIKA [cm] to CMSCGEN [mm]
319  if (MuMuDist < MinDist) MinDist = MuMuDist;
320  if (MuMuDist < 2.*Target3dRadius) MuInMaxDist = true;
321  }
322  }
323  if (MultiMuonNmin>=2) {
324  if (MuInMaxDist) {
326  }
327  else {
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: "
331  << 1 - double(NcloseMultiMuonEvents)/SimTree_jentry << std::endl;
332  std::cout << "NcloseMultiMuonEvents=" << NcloseMultiMuonEvents << std::endl;
333  std::cout << "trying next event from file" << std::endl;
335  continue; //EvtRejected while loop: get next event from file
336  }
337  }
338 
339  if (NmuPmin < MultiMuonNmin && AcptAllMu==false) { //take single muon events consistently into account
341  continue; //EvtRejected while loop: get next event from file
342  }
343 
344  if (Debug)
345  if (MultiMuonNmin>=2)
346  std::cout << "start trial do loop: MuMuDist=" << MinDist/1000. << "[m] Nmuons="
347  << nmuons << " NcloseMultiMuonEvents=" << NcloseMultiMuonEvents
348  << " NskippedMultiMuonEvents=" << NskippedMultiMuonEvents << std::endl;
349 
350 
351  //int primary_id = SimTree->run_ParticleID;
353 
354  double M_at = 0.;
355  //if (Id_at == 13) {
356  Id_at = 2212; //convert from Corsika to HepPDT
357  M_at = 938.272e-3; //[GeV] mass
358  //}
359 
362  double phi_at = SimTree->shower_Phi - NorthCMSzDeltaPhi; //rotate by almost 90 degrees
363  if (phi_at < -Pi) phi_at +=TwoPi; //bring into interval (-Pi,Pi]
364  else if (phi_at > Pi) phi_at -= TwoPi;
365  double P_at = sqrt(E_at*E_at - M_at*M_at);
366  //need to rotate about 90degrees around x->N axis => y<=>z,
367  //then rotate new x-z-plane from x->North to x->LHC centre
368  Px_at = P_at*sin(Theta_at)*sin(phi_at);
369  Py_at = -P_at*cos(Theta_at);
370  Pz_at = P_at*sin(Theta_at)*cos(phi_at);
371 
372  //compute maximal theta of secondary muons
373  double theta_mu_max = Theta_at;
374  double theta_mu_min = Theta_at;
375 
376  double phi_rel_min = 0.; //phi_mu_min - phi_at
377  double phi_rel_max = 0.; //phi_mu_max - phi_at
378 
379  //std::cout << "SimTree->shower_Energy=" << SimTree->shower_Energy <<std::endl;
380 
381  Theta_mu.resize(nmuons);
382  for (int imu=0; imu<nmuons; ++imu) {
383  Theta_mu[imu] = acos(-Py_mu[imu]/P_mu[imu]);
384  if (Theta_mu[imu]>theta_mu_max) theta_mu_max = Theta_mu[imu];
385  if (Theta_mu[imu]<theta_mu_min) theta_mu_min = Theta_mu[imu];
386 
387  double phi_mu = atan2(Px_mu[imu],Pz_mu[imu]); // in (-Pi,Pi]
388  double phi_rel = phi_mu - phi_at;
389  if (phi_rel < -Pi) phi_rel += TwoPi; //bring into interval (-Pi,Pi]
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;
393 
394 
395  }
396 
397 
398  double h_sf = SurfaceOfEarth + PlugWidth; //[mm]
399 
400  double R_at = h_sf*tan(Theta_at);
401 
402  double JdRxzV_dR_trans = 1.;
403  double JdPhiV_dPhi_trans = 1.;
404  double JdR_trans_sqrt = 1.;
405 
406  //chose random vertex Phi and Rxz weighted to speed up and smoothen
407  double R_mu_max = (h_sf+Target3dRadius)*tan(theta_mu_max);
408  double R_max = std::min(SurfaceRadius, R_mu_max);
409  double R_mu_min = (h_sf-Target3dRadius)*tan(theta_mu_min);
410  double R_min = std::max(0., R_mu_min);
411 
412  if (R_at>SurfaceRadius) {
413  std::cout << "CosmicMuonGenerator.cc: Warning! R_at=" << R_at
414  << " > SurfaceRadius=" << SurfaceRadius <<std::endl;
415  }
416 
417  //do phase space transformation for horizontal radius R
418 
419  //determine first phase space limits
420 
421  double psR1min = R_min + 0.25*(R_max-R_min);
422  double psR1max = std::min(SurfaceRadius,R_max-0.25*(R_max-R_min)); //no R's beyond R_max
423  double psR1 = psR1max - psR1min;
424 
425  double psR2min = R_min;
426  double psR2max = R_max;
427  double psR2 = psR2max - psR2min;
428 
429  double psR3min = 0.;
430  double psR3max = SurfaceRadius;
431  double psR3 = psR3max - psR3min;
432 
433  //double psall = psR1+psR2+psR3;
434  double psRall = psR3;
435 
436  double fR1=psR1/psRall, fR2=psR2/psRall, fR3=psR3/psRall; //f1+f2+f3=130%
437  double pR1=0.25, pR2=0.7, pR3=0.05;
438 
439 
440  //do phase space transformation for azimuthal angle phi
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;
445 
446  double fPh1=psPh1/psPhall, fPh2=psPh2/psPhall, fPh3=psPh3/psPhall; //(f1+f2+f3=TwoPi+f1+f2)/(TwoPi+f1+f2)
447 
448  double pPh1=0.25, pPh2=0.7, pPh3=0.05;
449 
450  Trials = 0; //global int trials
451  double trials = 0.; //local weighted trials
452  Vx_mu.resize(nmuons); Vy_mu.resize(nmuons); Vz_mu.resize(nmuons);
453  int NmuHitTarget = 0;
454  while (NmuHitTarget < MultiMuonNmin) {
455 
456  NmuHitTarget = 0; //re-initialize every loop iteration
457  double Nver = 0.;
458 
459 
460  //chose phase space class
461  double RxzV;
462  double which_R_class = RanGen->flat();
463  if (which_R_class < pR1) { //pR1% in psR1
464  RxzV = psR1min + psR1 * RanGen->flat();
465  JdRxzV_dR_trans = fR1/pR1 * SurfaceRadius/psR1;
466  }
467  else if (which_R_class < pR1+pR2) { //further pR2% in psR2
468  RxzV = psR2min + psR2 * RanGen->flat();
469  JdRxzV_dR_trans = fR2/pR2 * SurfaceRadius/psR2;
470  }
471  else { //remaining pR3% in psR3=[0., R_max]
472  RxzV = psR3min + psR3 * RanGen->flat();
473  JdRxzV_dR_trans = fR3/pR3 * SurfaceRadius/psR3;
474  }
475 
476  JdR_trans_sqrt = 2.*RxzV/SurfaceRadius; //flat in sqrt(r) space
477 
478  //chose phase space class
479  double PhiV;
480  double which_phi_class = RanGen->flat();
481  if (which_phi_class < pPh1) { //pPh1% in psPh1
482  PhiV = phi_at + phi_rel_min + psPh1 * RanGen->flat();
483  JdPhiV_dPhi_trans = fPh1/pPh1 * TwoPi/psPh1;
484  }
485  else if (which_phi_class < pPh1+pPh2) { //further pPh2% in psPh2
486  PhiV = phi_at + phi_rel_min + psPh2 * RanGen->flat();
487  JdPhiV_dPhi_trans = fPh2/pPh2 * TwoPi/psPh2;
488  }
489  else { //remaining pPh3% in psPh3=[-Pi,Pi]
490  PhiV = phi_at + phi_rel_min + psPh3 * RanGen->flat();
491  JdPhiV_dPhi_trans = fPh3/pPh3 * TwoPi/psPh3;
492  }
493 
494  //shuffle PhiV into [-Pi,+Pi] interval
495  if (PhiV < -Pi) PhiV+=TwoPi;
496  else if (PhiV > Pi) PhiV-=TwoPi;
497 
498 
499  Nver++;
500  trials += JdR_trans_sqrt * JdRxzV_dR_trans * JdPhiV_dPhi_trans;
501  Trials++;
502  if (trials > max_Trials) break; //while (Id_sf.size() < 2) loop
503  Ngen += (Nver-1.); //add number of generated vertices to initial cosmic events
504 
505 
506  Vx_at = RxzV*sin(PhiV); // [mm]
507 
508  Vy_at = h_sf; // [mm] (SurfaceOfEarth + PlugWidth; Determine primary particle height below)
509  //Vy_at = SimTree->shower_StartingAltitude*10. + h_sf; // [mm]
510  //std::cout << "SimTree->shower_StartingAltitude*10=" << SimTree->shower_StartingAltitude*10 <<std::endl;
511  Vz_at = RxzV*cos(PhiV); // [mm]
512 
513  int NmuHitTargetSphere = 0;
514  for (int imu=0; imu<nmuons; ++imu) {
515 
517  +SimTree->particle__y[imu]*cos(NorthCMSzDeltaPhi) )*10; //[mm] (Corsika cm to CMSCGEN mm)
518  Vy_mu[imu] = h_sf; //[mm] fixed at surface + PlugWidth
520  +SimTree->particle__y[imu]*sin(NorthCMSzDeltaPhi) )*10; //[mm] (Corsika cm to CMSCGEN mm)
521 
522 
523  //add atmospheric height to primary particle (default SimTree->shower_StartingAltitude = 0.)
524  double pt_sec = sqrt(Px_mu[imu]*Px_mu[imu]+Pz_mu[imu]*Pz_mu[imu]);
525  double theta_sec = atan2(std::fabs(Py_mu[imu]),pt_sec);
526  double r_sec = sqrt((Vx_mu[imu]-Vx_at)*(Vx_mu[imu]-Vx_at)
527  +(Vz_mu[imu]-Vz_at)*(Vz_mu[imu]-Vz_at));
528  double h_prod = r_sec * tan(theta_sec);
529  if (h_prod + h_sf > Vy_at) Vy_at = h_prod + h_sf;
530 
531  //only muons
532  if (SimTree->particle__ParticleID[imu] != 5 &&
533  SimTree->particle__ParticleID[imu] != 6) continue;
534 
535  if (P_mu[imu] < MinP_CMS && AcptAllMu==false) continue;
536 
537  //check here if at least 2 muons make it to the target sphere
538  double Vxz_mu = sqrt(Vx_mu[imu]*Vx_mu[imu] + Vz_mu[imu]*Vz_mu[imu]);
539  theta_mu_max = atan((Vxz_mu+Target3dRadius)/(h_sf-Target3dRadius));
540  theta_mu_min = atan((Vxz_mu-Target3dRadius)/(h_sf+Target3dRadius));
541  if (Theta_mu[imu] > theta_mu_min && Theta_mu[imu] < theta_mu_max) {
542 
543  // check phi range (for a sphere with Target3dRadius around the target)
544  double dPhi = Pi; if (Vxz_mu > Target3dRadius) dPhi = asin(Target3dRadius/Vxz_mu);
545  double PhiPmu = atan2(Px_mu[imu],Pz_mu[imu]); //muon phi
546  double PhiVmu = atan2(Vx_mu[imu],Vz_mu[imu]); //muon phi
547  double rotPhi = PhiVmu + Pi; if (rotPhi > Pi) rotPhi -= TwoPi;
548  double disPhi = std::fabs(rotPhi - PhiPmu); if (disPhi > Pi) disPhi = TwoPi - disPhi;
549  if (disPhi < dPhi) {
550  NmuHitTargetSphere++;
551  }
552 
553  }
554 
555  } //end imu for loop
556 
557 
558 
559 
560  if (NmuHitTargetSphere < MultiMuonNmin) continue; //while (Id_sf.size() < 2) loop
561 
562  //nmuons outgoing particle at SurFace
563  Id_sf.clear();
564  Px_sf.clear();
565  Py_sf.clear();
566  Pz_sf.clear();
567  E_sf.clear();
568  //M_sf_out.clear();
569  Vx_sf.clear();
570  Vy_sf.clear();
571  Vz_sf.clear();
572  T0_sf.clear();
573 
574  //nmuons particles at UnderGround
575  Id_ug.clear();
576  Px_ug.clear();
577  Py_ug.clear();
578  Pz_ug.clear();
579  E_ug.clear();
580  //M_ug.clear();
581  Vx_ug.clear();
582  Vy_ug.clear();
583  Vz_ug.clear();
584  T0_ug.clear();
585 
586  int Id_sf_this =0;
587  double Px_sf_this =0., Py_sf_this=0., Pz_sf_this=0.;
588  double E_sf_this=0.;
589  //double M_sf_this=0.;
590  double Vx_sf_this=0., Vy_sf_this=0., Vz_sf_this=0.;
591  double T0_sf_this=0.;
592 
593  T0_at = SimTree->shower_GH_t0 * SpeedOfLight; // [mm]
594 
595  for (int imu=0; imu<nmuons; ++imu) {
596 
597  if (P_mu[imu] < MinP_CMS && AcptAllMu==false) continue;
598  //for the time being only muons
599  if (SimTree->particle__ParticleID[imu] != 5 &&
600  SimTree->particle__ParticleID[imu] != 6) continue;
601 
602  Id_sf_this = SimTree->particle__ParticleID[imu];
603  if (Id_sf_this == 5) Id_sf_this = -13; //mu+
604  else if (Id_sf_this == 6) Id_sf_this = 13; //mu-
605 
606  else if (Id_sf_this == 1) Id_sf_this = 22; //gamma
607  else if (Id_sf_this == 2) Id_sf_this = -11; //e+
608  else if (Id_sf_this == 3) Id_sf_this = 11; //e-
609  else if (Id_sf_this == 7) Id_sf_this = 111; //pi0
610  else if (Id_sf_this == 8) Id_sf_this = 211; //pi+
611  else if (Id_sf_this == 9) Id_sf_this = -211; //pi-
612  else if (Id_sf_this == 10) Id_sf_this = 130; //KL0
613  else if (Id_sf_this == 11) Id_sf_this = 321; //K+
614  else if (Id_sf_this == 12) Id_sf_this = -321; //K-
615  else if (Id_sf_this == 13) Id_sf_this = 2112; //n
616  else if (Id_sf_this == 14) Id_sf_this = 2212; //p
617  else if (Id_sf_this == 15) Id_sf_this = -2212; //pbar
618  else if (Id_sf_this == 16) Id_sf_this = 310; //Ks0
619  else if (Id_sf_this == 17) Id_sf_this = 221; //eta
620  else if (Id_sf_this == 18) Id_sf_this = 3122; //Lambda
621 
622  else {
623  std::cout << "CosmicMuonGenerator.cc: Warning! Muon Id=" << Id_sf_this
624  << " from file read in" <<std::endl;
625  Id_sf_this = 99999; //trouble
626  }
627 
628  T0_sf_this = SimTree->particle__Time[imu] * SpeedOfLight; //in [mm]
629 
630  Px_sf_this = Px_mu[imu];
631  Py_sf_this = Py_mu[imu]; //Corsika down going particles defined in -z direction!
632  Pz_sf_this = Pz_mu[imu];
633  E_sf_this = sqrt(P_mu[imu]*P_mu[imu] + MuonMass*MuonMass);
634  Vx_sf_this = Vx_mu[imu];
635  Vy_sf_this = Vy_mu[imu]; //[mm] fixed at surface + PlugWidth
636  Vz_sf_this = Vz_mu[imu];
637 
638 
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);
640  // if angles are ok, propagate to target
641  if (goodOrientation()) {
643  }
644 
645  if ( (OneMuoEvt.hitTarget()
646  && sqrt(OneMuoEvt.e()*OneMuoEvt.e() - MuonMass*MuonMass) > MinP_CMS)
647  || AcptAllMu==true ) {
648 
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);
654  //M_sf.push_back(M_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);
659  //T0_sf.push_back(0.); //synchronised arrival for 100% efficient full simulation tests
660 
661  Id_ug.push_back(OneMuoEvt.id());
662  Px_ug.push_back(OneMuoEvt.px());
663  Py_ug.push_back(OneMuoEvt.py());
664  Pz_ug.push_back(OneMuoEvt.pz());
665  E_ug.push_back(OneMuoEvt.e());
666  //M_sf.push_back(OneMuoEvt.m());
667  Vx_ug.push_back(OneMuoEvt.vx());
668  Vy_ug.push_back(OneMuoEvt.vy());
669  Vz_ug.push_back(OneMuoEvt.vz());
670  T0_ug.push_back(OneMuoEvt.t0());
671 
672  NmuHitTarget++;
673  }
674  }
675 
676 
677  } // while (Id_sf.size() < 2); //end of do loop
678 
679 
680  if (trials > max_Trials) {
681  std::cout << "CosmicMuonGenerator.cc: Warning! trials reach max_trials=" << max_Trials
682  << " without accepting event!" << std::endl;
683  if (Debug) {
684  std::cout << " N(mu)=" << Id_ug.size();
685  if (Id_ug.size()>=1)
686  std::cout << " E[0]=" << E_ug[0] << " theta="
687  << acos(-Py_ug[0]/sqrt(Px_ug[0]*Px_ug[0]+Py_ug[0]*Py_ug[0]+Pz_ug[0]*Pz_ug[0]))
688  << " R_xz=" << sqrt(Vx_sf[0]*Vx_sf[0]+Vy_sf[0]*Vy_sf[0]);
689  std::cout << " Theta_at=" << Theta_at << std::endl;
690  }
691  std::cout << "Unweighted int num of Trials = " << Trials << std::endl;
692  std::cout << "trying next event (" << SimTree_jentry << ") from file" << std::endl;
694  continue; //EvtRejected while loop: get next event from file
695  }
696  else {
697  if (NmuHitTarget < MultiMuonNmin) {
698  std::cout << "CosmicMuonGenerator.cc: Warning! less than " << MultiMuonNmin <<
699  " muons hit target: N(mu=)" << NmuHitTarget << std::endl;
700  std::cout << "trying next event (" << SimTree_jentry << ") from file" << std::endl;
702  continue; //EvtRejected while loop: get next event from file
703  }
704  else { //if (MuInMaxDist) {
705 
706  //re-adjust T0's of surviving muons shifted to trigger time box
707  //(possible T0 increase due to propagation (loss of energy/speed + travelled distance))
708  double T0_ug_min, T0_ug_max;
709  T0_ug_min = T0_ug_max = T0_ug[0];
710  double Tbox = (MaxT0 - MinT0) * SpeedOfLight; // [mm]
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;
716  if (Debug) std::cout << "imu=" << imu << " T0_this=" << T0_this
717  << " P=" << sqrt(pow(Px_ug[imu],2) + pow(Py_ug[imu],2) + pow(Pz_ug[imu],2))
718  << std::endl;
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]);
721  }
722  }
723 
724  if (int(Id_ug.size()) >= MultiMuonNmin && MultiMuonNmin>=2 && minDeltaT0 > Tbox)
725  continue; //EvtRejected while loop: get next event from file
726 
727  double T0_min = T0_ug_min +MinT0*SpeedOfLight; //-12.5ns * c [mm]
728  double T0_max = T0_ug_max +MaxT0*SpeedOfLight; //+12.5ns * c [mm]
729 
730  //ckeck if >= NmuMin in time box, else throw new random number + augment evt weight
731  int TboxTrials = 0;
732  int NmuInTbox;
733  double T0_offset, T0diff;
734  for (int tboxtrial=0; tboxtrial<1000; ++tboxtrial) { //max 1000 trials
735  T0_offset = RanGen->flat()*(T0_max -T0_min); // [mm]
736  TboxTrials++;
737  T0diff = T0_offset - T0_max; // [mm]
738  NmuInTbox = 0;
739  for (unsigned int imu=0; imu<Id_ug.size(); ++imu) {
740  if (T0_ug[imu]+T0diff > MinT0*SpeedOfLight && T0_ug[imu]+T0diff < MaxT0*SpeedOfLight)
741  NmuInTbox++;
742  }
743  if (NmuInTbox >= MultiMuonNmin) break;
744 
745  }
746  if (NmuInTbox < MultiMuonNmin) continue; //EvtRejected while loop: get next event from file
747 
748 
749  if (Debug) std::cout << "initial T0_at=" << T0_at << " T0_min=" << T0_min << " T0_max=" << T0_max
750  << " T0_offset=" << T0_offset;
751  T0_at += T0diff; //[mm]
752  if (Debug) std::cout << " T0diff=" << T0diff << std::endl;
753  for (unsigned int imu=0; imu<Id_ug.size(); ++imu) { //adjust @ surface + underground
754  if (Debug) std::cout << "before: T0_sf[" << imu << "]=" << T0_sf[imu] << " T0_ug=" << T0_ug[imu];
755  T0_sf[imu] += T0diff;
756  T0_ug[imu] += T0diff;
757  if (Debug)
758  std::cout << " after: T0_sf[" << imu << "]=" << T0_sf[imu] << " T0_ug=" << T0_ug[imu] << std::endl;
759  }
760  if (Debug) std::cout << "T0diff=" << T0diff << " T0_at=" << T0_at << std::endl;
761 
762 
763 
764  Nsel += 1;
765  EventWeight = JdR_trans_sqrt * JdRxzV_dR_trans * JdPhiV_dPhi_trans
766  / (trials * TboxTrials);
767  EvtRejected = false;
768  if (Debug) std::cout << "CosmicMuonGenerator.cc: Theta_at=" << Theta_at << " phi_at=" << phi_at
769  << " Px_at=" << Px_at << " Py_at=" << Py_at << " Pz_at=" << Pz_at
770  << " T0_at=" << T0_at
771  << " Vx_at=" << Vx_at << " Vy_at=" << Vy_at << " Vz_at=" << Vz_at
772  << " EventWeight=" << EventWeight << " Nmuons=" << Id_sf.size() << std::endl;
773  }
774  }
775 
776 
777  } //while loop EvtRejected
778 
779 
780  return true; //write event to HepMC;
781 
782 }
783 
784 
785 
787  if (NumberOfEvents > 0){
788  std::cout << std::endl;
789  std::cout << "*********************************************************" << std::endl;
790  std::cout << "*********************************************************" << std::endl;
791  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;
793  std::cout << "*** ***" << std::endl;
794  std::cout << "*********************************************************" << std::endl;
795  std::cout << "*********************************************************" << std::endl;
796  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;
800  double selEff = Nsel/Ngen; // selection efficiency
801  std::cout << " event selection efficiency: " << selEff*100. << "%" << std::endl;
802  int n100cos = Norm->events_n100cos(0., 0.); //get final amount of cosmics in defined range for normalisation of flux
803  std::cout << " events with ~100 GeV and 1 - cos(theta) < 1/2pi: " << n100cos << std::endl;
804  std::cout << std::endl;
805  std::cout << " momentum range: " << MinP << " ... " << MaxP << " GeV" << std::endl;
806  std::cout << " theta range: " << MinTheta*Rad2Deg << " ... " << MaxTheta*Rad2Deg << " deg" << std::endl;
807  std::cout << " phi range: " << MinPhi*Rad2Deg << " ... " << MaxPhi*Rad2Deg << " deg" << std::endl;
808  std::cout << " time range: " << MinT0 << " ... " << MaxT0 << " ns" << std::endl;
809  std::cout << " energy loss: " << ElossScaleFactor*100. << "%" << std::endl;
810  std::cout << std::endl;
811  double area = 1.e-6*Pi*SurfaceRadius*SurfaceRadius; // area on surface [m^2]
812  if (MinTheta > 90.*Deg2Rad) //upgoing muons from neutrinos)
813  std::cout << " area of initial cosmics at CMS detector bottom surface: " << area << " m^2" << std::endl;
814  else
815  std::cout << " area of initial cosmics on Surface + PlugWidth: " << area << " m^2" << std::endl;
816  std::cout << " depth of CMS detector (from Surface): " << SurfaceOfEarth/1000 << " m" << std::endl;
817 
818  //at least 100 evts., and
819  //downgoing inside theta parametersisation range
820  //or upgoing neutrino muons
821  if( (n100cos>0 && MaxTheta<84.26*Deg2Rad)
822  || MinTheta>90.*Deg2Rad) {
823  // rate: corrected for area and selection-Eff. and normalized to known flux, integration over solid angle (dOmega) is implicit
824  // flux is normalised with respect to known flux of vertical 100GeV muons in area at suface level
825  // rate seen by detector is lower than rate at surface area, so has to be corrected for selection-Eff.
826  // normalisation factor has unit [1/s/m^2]
827  // rate = N/time --> normalization factor gives 1/runtime/area
828  // normalization with respect to number of actually diced events (Ndiced)
829 
830  if (MinTheta > 90.*Deg2Rad) {//upgoing muons from neutrinos)
831  double Omega = (cos(MinTheta)-cos(MaxTheta)) * (MaxPhi-MinPhi);
832  //EventRate = (Ndiced * 3.e-13) * Omega * area*1.e4 * selEff;//area in cm, flux=3.e-13cm^-2s^-1sr^-1
833  EventRate = (Ndiced * 3.e-13) * Omega * 4.*RadiusOfTarget*ZDistOfTarget*1.e-2 * selEff;//area in cm, flux=3.e-13cm^-2s^-1sr^-1
834  rateErr_stat = EventRate/sqrt( (double) Ndiced); // stat. rate error
835  rateErr_syst = EventRate/3.e-13 * 1.0e-13; // syst. rate error, from error of known flux
836  }
837  else {
838  EventRate= (Ndiced * Norm->norm(n100cos)) * area * selEff;
839  rateErr_stat = EventRate/sqrt( (double) n100cos); // stat. rate error
840  rateErr_syst = EventRate/2.63e-3 * 0.06e-3; // syst. rate error, from error of known flux
841  }
842 
843  // normalisation in region 1.-cos(theta) < 1./(2.*Pi), if MaxTheta even lower correct for this
844  if(MaxTheta<0.572){
845  double spacean = 2.*Pi*(1.-cos(MaxTheta));
846  EventRate= (Ndiced * Norm->norm(n100cos)) * area * selEff * spacean;
847  rateErr_stat = EventRate/sqrt( (double) n100cos); // rate error
848  rateErr_syst = EventRate/2.63e-3 * 0.06e-3; // syst. rate error, from error of known flux
849  }
850 
851  }else{
852  EventRate=Nsel; //no info as no muons at 100 GeV
855  std::cout << std::endl;
856  if (MinP > 100.)
857  std::cout << " !!! MinP > 100 GeV. Cannot apply normalisation!" << std::endl;
858  else if (MaxTheta > 84.26*Deg2Rad)
859  std::cout << " !!! Note: generated cosmics exceed parameterisation. No flux calculated!" << std::endl;
860 
861  else
862  std::cout << " !!! Not enough statistics to apply normalisation (rate=1 +- 1) !!!" << std::endl;
863  }
864 
865  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
866  std::cout << " rate is " << EventRate << " +-" << rateErr_stat <<" (stat) " << "+-" <<
867  rateErr_syst << " (syst) " <<" muons per second" << std::endl;
868  if(EventRate!=0) std::cout << " number of events corresponds to " << Nsel/EventRate << " s" << std::endl; //runtime at CMS = Nsel/rate
869  std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
870  std::cout << std::endl;
871  std::cout << "*********************************************************" << std::endl;
872  std::cout << "*********************************************************" << std::endl;
873  }
874 }
875 
877  if (MinP < 0.){ NumberOfEvents = 0;
878  std::cout << " CMG-ERR: min.energy is out of range (0 GeV ... inf]" << std::endl << std::endl; }
879  if (MaxP < 0.){ NumberOfEvents = 0;
880  std::cout << " CMG-ERR: max.energy is out of range (0 GeV ... inf]" << std::endl << std::endl; }
881  if (MaxP <= MinP){ NumberOfEvents = 0;
882  std::cout << " CMG-ERR: max.energy is not greater than min.energy" << std::endl << std::endl; }
883  if (MinTheta < 0.){ NumberOfEvents = 0;
884  std::cout << " CMG-ERR: min.theta is out of range [0 deg ... 90 deg)" << std::endl << std::endl; }
885  if (MaxTheta < 0.){ NumberOfEvents = 0;
886  std::cout << " CMG-ERR: max.theta is out of range [0 deg ... 90 deg)" << std::endl << std::endl; }
887  if (MaxTheta <= MinTheta){ NumberOfEvents = 0;
888  std::cout << " CMG-ERR: max.theta is not greater than min.theta" << std::endl << std::endl; }
889  if (MinPhi < 0.){ NumberOfEvents = 0;
890  std::cout << " CMG-ERR: min.phi is out of range [0 deg ... 360 deg]" << std::endl << std::endl; }
891  if (MaxPhi < 0.){ NumberOfEvents = 0;
892  std::cout << " CMG-ERR: max.phi is out of range [0 deg ... 360 deg]" << std::endl << std::endl; }
893  if (MaxPhi <= MinPhi){ NumberOfEvents = 0;
894  std::cout << " CMG-ERR: max.phi is not greater than min.phi" << std::endl << std::endl; }
895  if (MaxT0 <= MinT0){ NumberOfEvents = 0;
896  std::cout << " CMG-ERR: max.t0 is not greater than min.t0" << std::endl << std::endl; }
897  if (ElossScaleFactor < 0.){ NumberOfEvents = 0;
898  std::cout << " CMG-ERR: E-loss scale factor is out of range [0 ... inf)" << std::endl << std::endl; }
899  if (MinEnu < 0.){ NumberOfEvents = 0;
900  std::cout << " CMG-ERR: min.Enu is out of range [0 GeV ... inf]" << std::endl << std::endl; }
901  if (MaxEnu < 0.){ NumberOfEvents = 0;
902  std::cout << " CMG-ERR: max.Enu is out of range [0 GeV ... inf]" << std::endl << std::endl; }
903  if (MaxEnu <= MinEnu){ NumberOfEvents = 0;
904  std::cout << " CMG-ERR: max.Enu is not greater than min.Enu" << std::endl << std::endl; }
905 
906 }
907 
909  // check angular range (for a sphere with Target3dRadius around the target)
910  bool goodAngles = false;
911  bool phiaccepted = false;
912  bool thetaaccepted = false;
913  double RxzV = sqrt(OneMuoEvt.vx()*OneMuoEvt.vx() + OneMuoEvt.vz()*OneMuoEvt.vz());
914 
915  double rVY;
916  if (MinTheta > 90.*Deg2Rad) //upgoing muons from neutrinos
917  rVY = -sqrt(RxzV*RxzV + RadiusCMS*RadiusCMS);
918  else
919  rVY = sqrt(RxzV*RxzV + (SurfaceOfEarth+PlugWidth)*(SurfaceOfEarth+PlugWidth));
920 
921  double Phi = OneMuoEvt.phi();
922  double PhiV = atan2(OneMuoEvt.vx(),OneMuoEvt.vz()) + Pi; if (PhiV > TwoPi) PhiV -= TwoPi;
923  double disPhi = std::fabs(PhiV - Phi); if (disPhi > Pi) disPhi = TwoPi - disPhi;
924  double dPhi = Pi; if (RxzV > Target3dRadius) dPhi = asin(Target3dRadius/RxzV);
925  if (disPhi < dPhi) phiaccepted = true;
926  double Theta = OneMuoEvt.theta();
927  double ThetaV = asin(RxzV/rVY);
928  double dTheta = Pi; if (std::fabs(rVY) > Target3dRadius) dTheta = asin(Target3dRadius/std::fabs(rVY));
929  //std::cout << " dPhi = " << dPhi << " (" << Phi << " <p|V> " << PhiV << ")" << std::endl;
930  //std::cout << " dTheta = " << dTheta << " (" << Theta << " <p|V> " << ThetaV << ")" << std::endl;
931 
932  if (!phiaccepted && RxzV < Target3dRadius)
933  //if (RxzV < Target3dRadius)
934  std::cout << "Rejected phi=" << Phi << " PhiV=" << PhiV
935  << " dPhi=" << dPhi << " disPhi=" << disPhi
936  << " RxzV=" << RxzV << " Target3dRadius=" << Target3dRadius
937  << " Theta=" << Theta << std::endl;
938 
939  if (std::fabs(Theta-ThetaV) < dTheta) thetaaccepted = true;
940  if (phiaccepted && thetaaccepted) goodAngles = true;
941  return goodAngles;
942 }
943 
945 #if ROOT_INTERACTIVE
946  float rCMS = RadiusCMS/1000.;
947  float zCMS = Z_DistCMS/1000.;
948  if(TrackerOnly==true){
949  rCMS = RadiusTracker/1000.;
950  zCMS = Z_DistTracker/1000.;
951 }
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);
958  disC->Divide(2,1);
959  disC->cd(1);
960  gPad->SetTicks(1,1);
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]");
971  disC->cd(2);
972  gPad->SetGrid(1,1);
973  gPad->SetTicks(1,1);
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]");
984 #endif
985 }
986 
988 #if ROOT_INTERACTIVE
989  double RadiusDet=RadiusCMS;
990  double Z_DistDet=Z_DistCMS;
991  if(TrackerOnly==true){
992  RadiusDet = RadiusTracker;
993  Z_DistDet = Z_DistTracker;
994  }
995  disXY->Reset();
996  disZY->Reset();
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);
1000  float energy = float(OneMuoEvt.e());
1001  float verX = float(OneMuoEvt.vx()/1000.); // [m]
1002  float verY = float(OneMuoEvt.vy()/1000.); // [m]
1003  float verZ = float(OneMuoEvt.vz()/1000.); // [m]
1004  float dirX = float(OneMuoEvt.px())/std::fabs(OneMuoEvt.py());
1005  float dirY = float(OneMuoEvt.py())/std::fabs(OneMuoEvt.py());
1006  float dirZ = float(OneMuoEvt.pz())/std::fabs(OneMuoEvt.py());
1007  float yStep = disXY->GetYaxis()->GetBinWidth(1);
1008  int NbinY = disXY->GetYaxis()->GetNbins();
1009  for (int iy=0; iy<NbinY; ++iy){
1010  verX += dirX*yStep;
1011  verY += dirY*yStep;
1012  verZ += dirZ*yStep;
1013  float rXY = sqrt(verX*verX + verY*verY)*1000.; // [mm]
1014  float absZ = std::fabs(verZ)*1000.; // [mm]
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");
1021  gPad->Update();
1022  }
1023  }
1024 #endif
1025 }
1026 
1028 
1030 
1032 
1034 
1036 
1038 
1040 
1042 
1044 
1046 
1048 
1049 void CosmicMuonGenerator::setElossScaleFactor(double ElossScaleFact){ if (NotInitialized) ElossScaleFactor = ElossScaleFact; }
1050 
1052 
1054 
1056 
1058 
1059 void CosmicMuonGenerator::setMultiMuon(bool MultiMu){ if (NotInitialized) MultiMuon = MultiMu; }
1061 void CosmicMuonGenerator::setMultiMuonFileFirstEvent(int MultiMuFile1stEvt){ if (NotInitialized) MultiMuonFileFirstEvent = MultiMuFile1stEvt; }
1062 void CosmicMuonGenerator::setMultiMuonNmin(int MultiMuNmin){ if (NotInitialized) MultiMuonNmin = MultiMuNmin; }
1063 
1065 
1068 
1069 void CosmicMuonGenerator::setPlugVx(double PlugVtx){ if (NotInitialized) PlugVx = PlugVtx; }
1070 void CosmicMuonGenerator::setPlugVz(double PlugVtz){ if (NotInitialized) PlugVz = PlugVtz; }
1071 void CosmicMuonGenerator::setRhoAir(double VarRhoAir){ if (NotInitialized) RhoAir = VarRhoAir; }
1072 void CosmicMuonGenerator::setRhoWall(double VarRhoWall){ if (NotInitialized) RhoWall = VarRhoWall; }
1073 void CosmicMuonGenerator::setRhoRock(double VarRhoRock){ if (NotInitialized) RhoRock = VarRhoRock; }
1074 void CosmicMuonGenerator::setRhoClay(double VarRhoClay){ if (NotInitialized) RhoClay = VarRhoClay; }
1075 void CosmicMuonGenerator::setRhoPlug(double VarRhoPlug){ if (NotInitialized) RhoPlug = VarRhoPlug; }
1076 void CosmicMuonGenerator::setClayWidth(double ClayLayerWidth){ if (NotInitialized) ClayWidth = ClayLayerWidth; }
1077 
1078 void CosmicMuonGenerator::setMinEnu(double MinEn){ if (NotInitialized) MinEnu = MinEn; }
1079 void CosmicMuonGenerator::setMaxEnu(double MaxEn){ if (NotInitialized) MaxEnu = MaxEn; }
1080 void CosmicMuonGenerator::setNuProdAlt(double NuPrdAlt){ if (NotInitialized) NuProdAlt = NuPrdAlt; }
1081 
1083 
const double Z[kNumberCalorimeter]
Int_t shower_nParticlesWritten
Definition: sim.h:41
void setZDistOfTarget(double Z)
const double TwoPi
const double Pi
void propagate(double ElossScaleFac, double RadiusTarget, double Z_DistTarget, double Z_CentrTarget, bool TrackerOnly, bool MTCCHalf)
void initialize(CLHEP::HepRandomEngine *rng=0)
float norm(int n100cos)
Definition: CMSCGENnorm.cc:31
std::vector< double > Theta_mu
int events_n100cos(double energy, double theta)
Definition: CMSCGENnorm.cc:15
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_]
Definition: sim.h:62
std::vector< double > Py_mu
void setRhoAir(double VarRhoAir)
const double Z_DistTracker
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< int > Id_ug
TTree * fChain
Definition: sim.h:21
int initialize(double, double, double, double, CLHEP::HepRandomEngine *, bool, bool)
Definition: CMSCGEN.cc:30
void setRandomEngine(CLHEP::HepRandomEngine *v)
Definition: CMSCGEN.cc:23
void setRadiusOfTarget(double R)
Double_t particle__Time[kMaxparticle_]
Definition: sim.h:66
void setNumberOfEvents(unsigned int N)
#define P
std::vector< double > Py_sf
virtual void Init(TTree *tree)
std::vector< double > E_sf
Double_t particle__Px[kMaxparticle_]
Definition: sim.h:61
Int_t shower_EventID
Definition: sim.h:28
std::vector< double > Pz_mu
const double SpeedOfLight
Double_t particle__Pz[kMaxparticle_]
Definition: sim.h:63
Definition: sim.h:19
std::vector< double > E_ug
void setMultiMuonFileFirstEvent(int MultiMuFile1stEvt)
const double NorthCMSzDeltaPhi
virtual Int_t GetEntry(Long64_t entry)
void setRhoPlug(double VarRhoPlug)
double cos_theta()
Definition: CMSCGEN.cc:469
const double PlugWidth
Float_t shower_Energy
Definition: sim.h:29
std::vector< double > Vz_ug
int generate()
Definition: CMSCGEN.cc:263
void setMinPhi(double Phi)
const double RadiusCMS
const double SurfaceOfEarth
void setMaxPhi(double Phi)
void setRandomEngine(CLHEP::HepRandomEngine *v)
std::vector< double > Vz_sf
std::vector< double > Vz_mu
const double Deg2Rad
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< double > Vx_sf
const double Z_DistCMS
void setMultiMuonNmin(int MultiMuNmin)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Float_t shower_Phi
Definition: sim.h:34
std::vector< double > Vy_sf
void setMinTheta(double Theta)
CLHEP::HepRandomEngine * RanGen
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< double > Vx_mu
void setMaxEnu(double MaxEn)
T min(T a, T b)
Definition: MathUtil.h:58
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
#define N
Definition: blowfish.cc:9
std::vector< double > Px_sf
std::vector< double > Vy_ug
void setAcptAllMu(bool AllMu)
Int_t particle__ParticleID[kMaxparticle_]
Definition: sim.h:58
double momentum_times_charge()
Definition: CMSCGEN.cc:454
void setPlugVz(double PlugVtz)
void setTIFOnly_linear(bool TIF)
std::vector< double > Pz_ug
const double MinStepSize
Double_t particle__x[kMaxparticle_]
Definition: sim.h:64
void create(int id, double px, double py, double pz, double e, double m, double vx, double vy, double vz, double t0)
const bool EventDisplay
const int max_Trials
const double MuonMass
void setMultiMuonFileName(std::string MultiMuonFileName)
const double RadiusTracker
void setElossScaleFactor(double ElossScaleFact)
void setMaxTheta(double Theta)
tuple cout
Definition: gather_cfg.py:145
void setRhoWall(double VarRhoSWall)
const double Rad2Deg
void setPlugVx(double PlugVtx)
Float_t shower_GH_t0
Definition: sim.h:47
void setRhoRock(double VarRhoRock)
int initializeNuMu(double, double, double, double, double, double, double, double, double, CLHEP::HepRandomEngine *)
Definition: CMSCGEN.cc:502
std::vector< double > Vx_ug
int generateNuMu()
Definition: CMSCGEN.cc:595
std::vector< double > P_mu
std::vector< double > Py_ug
const bool Debug
Float_t shower_Theta
Definition: sim.h:33
std::vector< double > T0_ug
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::vector< int > Id_sf
void setRhoClay(double VarRhoClay)
std::vector< double > Pz_sf
Double_t particle__y[kMaxparticle_]
Definition: sim.h:65
void setTrackerOnly(bool Tracker)