1from __future__
import print_function
4import multiprocessing
as mp
5from rootpyPickler
import Unpickler
6ROOT.gInterpreter.ProcessLine(
'typedef double Double32_t')
8if not os.uname()[1].lower().find(
'ubuntu')< 0: local =
True
311xx = os.path.abspath(
'.').lower()
312if not xx.find(
'neutrino')<0: pref=
'neutrino'
313if not xx.find(
'vdis')<0: pref=
'disV'
314elif not xx.find(
'clby')<0: pref=
'disCLBY'
315elif not xx.find(
'dis')<0: pref=
'dis'
317if len(os.sys.argv)>1 :
318 for i
in range(1,len(os.sys.argv)):
319 for prefix
in os.sys.argv[i].split(
','):
320 if prefix.find(pref)<0:prefix=pref+prefix
321 prefixes.append(prefix)
329if prefixes[0]!=
'': testdir = path+prefixes[0]+
'1'
331for f
in os.listdir(testdir):
332 if not f.find(
"geofile_full")<0:
333 fgeo = ROOT.TFile(testdir+
'/'+f)
335 inputFile = f.replace(
"geofile_full",
"ship")
338tmp = inputFile.split(
'.')
340 dy = float( tmp[1]+
'.'+tmp[2] )
344if not inputFile.find(
'_D.')<0:
345 inputFile1 = inputFile.replace(
'_D.',
'.')
346 inputFile2 = inputFile
348 inputFile1 = inputFile
349 inputFile2 = inputFile.replace(
'.root',
'_D.root')
351import rootUtils
as ut
353PDG = ROOT.TDatabasePDG.Instance()
354from ShipGeoConfig
import ConfigRegistry
356if not fgeo.FindKey(
'ShipGeo'):
358 if sGeo.GetVolume(
'EcalModule3') : ecalGeoFile =
"ecal_ellipse6x12m2.geo"
359 else: ecalGeoFile =
"ecal_ellipse5x10m2.geo"
360 print(
'found ecal geo for ',ecalGeoFile)
362 ShipGeo = ConfigRegistry.loadpy(
"$FAIRSHIP/geometry/geometry_config.py", Yheight = dy, EcalGeoFile = ecalGeoFile )
366 ShipGeo = upkl.load(
'ShipGeo')
367 ecalGeoFile = ShipGeo.ecal.File
371run = ROOT.FairRunSim()
374ecal = modules[
'Ecal']
378 at = sTree.MCTrack[it]
379 im = at.GetMotherId()
386 rz_inter = ROOT.TMath.Sqrt(at.GetStartX()**2+at.GetStartY()**2),at.GetStartZ()
392top = sGeo.GetTopVolume()
393muon = top.GetNode(
"MuonDetector_1")
394mvol = muon.GetVolume()
395zmuon = muon.GetMatrix().GetTranslation()[2]
396totl = (zmuon + mvol.GetShape().GetDZ() ) / u.m
403if path !=
'': testdir = path
405 for prefix
in prefixes:
406 for i
in range(1,10):
407 if not prefix+str(i)
in os.listdir(testdir):
continue
408 q1 = inputFile1
in os.listdir(path+prefix+str(i))
409 q2 = inputFile2
in os.listdir(path+prefix+str(i))
410 recFile1 = inputFile1.replace(
'.root',
'_rec.root')
411 recFile2 = inputFile2.replace(
'.root',
'_rec.root')
412 r1 = recFile1
in os.listdir(path+prefix+str(i))
413 r2 = recFile2
in os.listdir(path+prefix+str(i))
414 if q1
or r1 : inputFile = inputFile1
415 elif q2
or r2: inputFile = inputFile2
417 fname = path+prefix+str(i)+
'/'+inputFile
418 recFile = inputFile.replace(
'.root',
'_rec.root')
419 if not recFile
in os.listdir(path+prefix+str(i)):
422 fname = path+prefix+str(i)+
'/'+recFile
423 fchainRec.append(fname)
426 fchain.append(inputFile)
433 cmd =
"python $FAIRSHIP/macro/run_simScript.py --MuonBack -f $SHIPSOFT/data/pythia8_Geant4_onlyMuons.root "
436 for i
in range(1,ncpu+1):
438 if d
not in os.listdir(
'.'): os.system(
'mkdir '+d)
439 os.chdir(
'./'+prefix+
'1')
440 for i
in range(1,ncpu+1):
441 if i==ncpu: n3 = ntot - i*n3
442 os.system(
'cp $FAIRSHIP/macro/run_simScript.py .')
443 os.system(cmd+
" -n "+str(n3)+
" -i "+str(ns) +
" > log &")
447 os.chdir(
'../'+prefix+str(i+1))
458 modules[
'Strawtubes'].StrawDecode(detid,statnb,vnb,pnb,lnb,snb)
459 return [statnb,vnb,pnb,lnb,snb]
462 sGeo = ROOT.gGeoManager
464 for v
in sGeo.GetListOfVolumes():
466 i = sGeo.FindVolumeFast(nm).GetNumber()
472 myGauss = h[x].GetListOfFunctions().FindObject(name)
474 if not ba : ba = h[x].GetBinCenter(1)
475 if not be : be = h[x].GetBinCenter(h[x].GetNbinsX())
476 bw = h[x].GetBinWidth(1)
477 mean = h[x].GetMean()
478 sigma = h[x].GetRMS()
479 norm = h[x].GetEntries()*0.3
480 myGauss = TF1(name,
'[0]*'+str(bw)+
'/([2]*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+[3]',4)
481 myGauss.SetParameter(0,norm)
482 myGauss.SetParameter(1,mean)
483 myGauss.SetParameter(2,sigma)
484 myGauss.SetParameter(3,1.)
485 myGauss.SetParName(0,
'Signal')
486 myGauss.SetParName(1,
'Mean')
487 myGauss.SetParName(2,
'Sigma')
488 h[x].Fit(myGauss,
'',
'',ba,be)
498 for mu
in [
'',
'_mu',
'_muV0']:
500 if detName.find(
'LS')<0:
501 ut.bookHist(h,tag,
'x/y '+detName,100,-3.,3.,100,-6.,6.)
503 ut.bookHist(h,tag,
'z phi '+detName,100,-50.,50.,100,-1.,1.)
504 ut.bookHist(h,tag+
'_E',
'deposited energy MeV '+detName,100,0.,2.)
505 ut.bookHist(h,tag+
'_P',
'particle mom GeV '+detName,500,0.,50.)
506 ut.bookHist(h,tag+
'_LP',
'particle mom GeV '+detName,100,0.,1.)
507 ut.bookHist(h,tag+
'_OP',
'original particle mom GeV '+detName,400,0.,400.)
508 ut.bookHist(h,tag+
'_id',
'particle id '+detName,5001,-2499.5,2499.5)
509 ut.bookHist(h,tag+
'_mul',
'multiplicity of hits/tracks '+detName,100,-0.5,99.5)
510 ut.bookHist(h,tag+
'_evmul',
'multiplicity of hits/event '+detName,100,-0.5,9999.5)
511 ut.bookHist(h,tag+
'_origin',
'r vs z',100, ztarget,totl,100,0.,12.)
512 ut.bookHist(h,tag+
'_originmu',
'r vs z',100,ztarget,totl,100,0.,12.)
514ut.bookHist(h,
'origin',
'r vs z',100,ztarget,totl,100,0.,15.)
515ut.bookHist(h,
'borigin',
'r vs z',100,ztarget,totl,500,0.,30.)
516ut.bookHist(h,
'porigin',
'r vs z secondary',100,ztarget,totl,500,0.,30.)
517ut.bookHist(h,
'mu-inter',
'r vs z',100,ztarget,totl,50,0.,3.)
518ut.bookHist(h,
'muonP',
'muon momentum',100,0.,400.)
519ut.bookHist(h,
'weight',
'muon weight',1000,1.E3,1.E6)
520ut.bookHist(h,
'delx13',
'x diff first and last point, mu-',100,-10.,10.)
521ut.bookHist(h,
'delx-13',
'x diff first and last point, mu+',100,-10.,10.)
522ut.bookHist(h,
'deltaElec',
'energy of delta electrons',100,0.,10.)
523ut.bookHist(h,
'secondaries',
'energy of delta electrons',100,0.,10.)
524ut.bookHist(h,
'prop_deltaElec',
'energy of delta elec / muon energy',100,0.,1.)
525ut.bookHist(h,
'dummy',
'',10,0.,1.)
526ut.bookHist(h,
'dE',
'',100,0.,10.,100,0.,10.)
527h[
'dummy'].SetMaximum(10.)
529histlistAll = {1:
'strawstation_5',2:
'strawstation_1',3:
'strawstation_4',4:
'Ecal',5:
'muondet',
530 6:
'VetoTimeDet',7:
'T1LiSc',8:
'T2LiSc',9:
'T3LiSc',10:
'T5LiSc',
531 11:
'ShipRpc',12:
'volHPT',13:
'Target',14:
'TimeDet',15:
'Det2'}
533for i
in range(1,7): hLiSc[1][i] =
"T1LiSc_"+str(i)
535for i
in range(1,48): hLiSc[2][i] =
"T2LiSc_"+str(i)
537for i
in range(1,3): hLiSc[3][i] =
"T3LiSc_"+str(i)
539for i
in range(1,3): hLiSc[5][i] =
"T5LiSc_"+str(i)
541for i
in range(0,4): hMuon[i] =
"muondet"+str(i)
551 if os.path.islink(fn):
552 rfn = os.path.realpath(fn).split(
'eos')[1]
553 fn = ROOT.gSystem.Getenv(
"EOSSHIP")+
'/eos/'+rfn
554 elif not os.path.isfile(fn):
555 print(
"Don't know what to do with",fn)
559 processes.append(mp.Process(target=executeOneFile, args=(fn,output,pid) ) )
572 for p
in processes: p.join()
574 for x
in h: h[x].Reset()
575 print(
"now, collect the output")
578 ut.readHists(h,
'tmpHists_'+str(pid)+
'.root')
581 for mu
in [
'',
'_mu',
'_muV0']:
582 for x
in [
'',
'_E',
'_P',
'_LP',
'_OP',
'_id',
'_mul',
'_evmul',
'_origin',
'_originmu']:
588 newh = detName[0:2]+
'LiSc'+mu+x
589 if tag
not in h:
continue
591 h[newh] = h[tag].Clone(newh)
592 h[newh].SetTitle( h[tag].GetTitle().split(
'_')[0])
594 else: rc = h[newh].Add(h[tag])
596 for mu
in [
'',
'_mu',
'_muV0']:
597 for x
in [
'',
'_E',
'_P',
'_LP',
'_OP',
'_id',
'_mul',
'_evmul',
'_origin',
'_originmu']:
602 newh =
'muondet'+mu+x
604 h[newh] = h[tag].Clone(newh)
605 h[newh].SetTitle( h[tag].GetTitle().split(
' ')[0]+
' '+newh)
607 else: rc = h[newh].Add(h[tag])
611 for x
in histlistAll:
612 if histlistAll[x]
in h:
613 histlist[k]=histlistAll[x]
615 for c
in [
'',
'_E',
'_P',
'_LP',
'_OP',
'_id',
'_mul',
'_evmul',
'_origin',
'_originmu']:
616 h[histlist[k]+
'_mu'+c].Add( h[histlist[k]+
'_muV0'+c] )
617 h[histlist[k]+c].Add( h[histlist[k]+
'_mu'+c] )
618 h[histlist[k]+c].SetMinimum(0.)
619 h[histlist[k]+
'_mu'+c].SetMinimum(0.)
620 h[histlist[k]+
'_muV0'+c] .SetMinimum(0.)
622 nstations = len(histlist)
626 f = ROOT.TFile.Open(fn)
628 nEvents = sTree.GetEntries()
629 if sTree.GetBranch(
"GeoTracks"): sTree.SetBranchStatus(
"GeoTracks",0)
631 hitContainers = [sTree.vetoPoint,sTree.muonPoint,sTree.EcalPointLite,sTree.strawtubesPoint,sTree.ShipRpcPoint,sTree.TargetPoint]
633 for n
in range(nEvents):
634 rc = sTree.GetEntry(n)
635 theMuon = sTree.MCTrack[0]
636 if sTree.MCTrack.GetEntries() > 1:
637 w = sTree.MCTrack[1].GetWeight()
639 print(
'should not happen with new files',n,fn)
640 w = sTree.MCTrack[0].GetWeight()
642 rc = h[
'weight'].Fill(w)
643 rc = h[
'muonP'].Fill(theMuon.GetP()/u.GeV,w)
645 if ntot%10000 == 0 : print(
'read event',f.GetName(),n)
648 for mcp
in sTree.MCTrack:
649 if mcp.GetMotherId() == 0:
651 if mcp.GetPdgCode() == 11:
652 rc = h[
'deltaElec'].Fill(E,w)
654 rc = h[
'secondaries'].Fill(E,w)
655 rc = h[
'prop_deltaElec'].Fill(esum/sTree.MCTrack[0].GetP(),w)
656 for c
in hitContainers:
658 if not ahit.GetEnergyLoss()>0:
continue
659 detID = ahit.GetDetectorID()
660 if ahit.GetName() ==
'strawtubesPoint':
663 detName =
"strawstation_"+str(tmp[0])
666 E = ahit.GetEnergyLoss()
667 elif ahit.GetName() ==
'ecalPoint':
673 E = ahit.GetEnergyLoss()
675 if detID
not in logVols:
676 detName = c.GetName().replace(
'Points',
'')
677 if not detName
in histlistAll.values(): print(detID,detName,c.GetName())
678 else: detName = logVols[detID]
682 E = ahit.GetEnergyLoss()
683 if detName
not in h:
bookHist(detName)
686 if 'PdgCode' in dir(ahit): pdgID = ahit.PdgCode()
687 trackID = ahit.GetTrackID()
689 mom = ROOT.TVector3()
691 aTrack = sTree.MCTrack[trackID]
692 pdgID = aTrack.GetPdgCode()
693 aTrack.GetMomentum(mom)
694 phit = mom.Mag()/u.GeV
695 if abs(pdgID)==13: mu=
'_mu'
696 if ahit.GetName().find(
'ecal')<0:
697 rc = ahit.Momentum(mom)
698 phit = mom.Mag()/u.GeV
700 for ahit
in sTree.EcalPoint:
701 if ahit.GetTrackID() == trackID:
702 rc = ahit.Momentum(mom)
703 phit = mom.Mag()/u.GeV
704 if phit>3
and abs(pdgID)==13: mu=
'_muV0'
705 detName = detName + mu
706 if detName.find(
'LS')<0: rc = h[detName].Fill(x/u.m,y/u.m,w)
707 else: rc = h[detName].Fill(ahit.GetZ()/u.m,ROOT.TMath.ATan2(y,x)/ROOT.TMath.Pi(),w)
708 rc = h[detName+
'_E'].Fill(E/u.MeV,w)
709 if detName
not in hitmult: hitmult[detName] = {-1:0}
710 if trackID
not in hitmult[detName]: hitmult[detName][trackID] = 0
711 hitmult[detName][trackID] +=1
712 hitmult[detName][-1] +=1
713 rc = h[detName+
'_id'].Fill(pdgID,w)
714 rc = h[detName+
'_P'].Fill(phit,w)
715 rc = h[detName+
'_LP'].Fill(phit,w)
717 r = ROOT.TMath.Sqrt(aTrack.GetStartX()**2+aTrack.GetStartY()**2)/u.m
718 rc = h[
'origin'].Fill(aTrack.GetStartZ()/u.m,r,w)
719 rc = h[detName+
'_origin'].Fill(aTrack.GetStartZ()/u.m,r,w)
720 if abs(pdgID)== 13: rc = h[detName+
'_originmu'].Fill(aTrack.GetStartZ()/u.m,r,w)
721 rc = h[
'borigin'].Fill(aTrack.GetStartZ()/u.m,r,w)
722 rc = aTrack.GetMomentum(mom)
723 rc = h[detName+
'_OP'].Fill(mom.Mag()/u.GeV,w)
726 rc = h[
'porigin'].Fill(aTrack.GetStartZ()/u.m,ROOT.TMath.Sqrt(aTrack.GetStartX()**2+aTrack.GetStartY()**2)/u.m,w)
727 rc = h[
'mu-inter'].Fill(rz_inter[1]/u.m,rz_inter[0]/u.m,w)
728 for detName
in hitmult:
729 rc = h[detName+
'_evmul'].Fill(hitmult[detName][-1],w)
730 for tr
in hitmult[detName]:
731 rc = h[detName+
'_mul'].Fill(hitmult[detName][tr],w)
733 ut.writeHists(h,
'tmpHists_'+str(pid)+
'.root')
738 cxcy = {1:[2,1],2:[3,1],3:[2,2],4:[3,2],5:[3,2],6:[3,2],7:[3,3],8:[3,3],9:[3,3],10:[4,3],11:[4,3],12:[4,3],13:[5,3],14:[5,3],15:[5,3]}
739 ut.bookCanvas(h,key=
'ResultsI',title=
'hit occupancies', nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
740 ut.bookCanvas(h,key=
'ResultsImu',title=
'hit occupancies',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
741 ut.bookCanvas(h,key=
'ResultsImuV0',title=
'hit occupancies',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
742 ut.bookCanvas(h,key=
'ResultsII', title=
'deposited energies',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
743 ut.bookCanvas(h,key=
'ResultsIII',title=
'track info',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
744 ut.bookCanvas(h,key=
'ResultsIV',title=
'track info',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
745 ut.bookCanvas(h,key=
'ResultsV',title=
'origin info',nx=600,ny=400,cx=1,cy=1)
746 txt[0] =
'occupancy 1sec 5E13pot '
748 nSpills = len(prefixes)
750 tc = h[
'ResultsI'].cd(i)
752 if hn
not in h:
continue
755 txt[i] =
'%5.2G'%(h[hn].GetSumOfWeights()/nSpills)
756 l[i] = ROOT.TLatex().DrawLatexNDC(0.15,0.85,txt[i])
758 hn = histlist[i]+
'_mu'
759 tc = h[
'ResultsImu'].cd(i)
762 txt[i+100] =
'%5.2G'%(h[hn].GetSumOfWeights()/nSpills)
763 l[i+100] = ROOT.TLatex().DrawLatexNDC(0.15,0.85,txt[i+100])
765 hn = histlist[i]+
'_muV0'
766 tc = h[
'ResultsImuV0'].cd(i)
769 txt[i+200] =
'%5.2G'%(h[hn].GetSumOfWeights()/nSpills)
770 l[i+200] = ROOT.TLatex().DrawLatexNDC(0.15,0.85,txt[i+200])
773 tc = h[
'ResultsII'].cd(i)
774 h[histlist[i]+
'_E'].Draw(
'colz')
777 tc = h[
'ResultsIII'].cd(i)
782 print(
'particle statistics for '+histlist[i])
783 for k
in range(hid.GetNbinsX()):
784 ncont = hid.GetBinContent(k+1)
785 pid = hid.GetBinCenter(k+1)
787 temp = int(abs(pid)+0.5)*int(pid/abs(pid))
788 nm = PDG.GetParticle(temp).GetName()
789 print(
'%s :%5.2g'%(nm,ncont))
790 hid = h[histlist[i]+
'_mu_id']
791 for k
in range(hid.GetNbinsX()):
792 ncont = hid.GetBinContent(k+1)
793 pid = hid.GetBinCenter(k+1)
795 temp = int(abs(pid)+0.5)*int(pid/abs(pid))
796 nm = PDG.GetParticle(temp).GetName()
797 print(
'%s :%5.2g'%(nm,ncont))
799 tc = h[
'ResultsV'].cd(1)
800 h[
'origin'].SetStats(0)
801 h[
'origin'].Draw(
'colz')
804 tc = h[
'ResultsIV'].cd(i)
812 fout = open(
'rareEvents.txt',
'w')
815 if not f.FindObjectAny(
'cbmsim'):
816 print(
'skip file ',f.GetName())
820 if sTree.GetBranch(
"GeoTracks"): sTree.SetBranchStatus(
"GeoTracks",0)
821 nEvents = sTree.GetEntries()
822 for n
in range(nEvents):
824 if n==0 : print(
'now at event ',n,f.GetName())
825 if sTree.MCTrack.GetEntries() > 1:
826 wg = sTree.MCTrack[1].GetWeight()
828 wg = sTree.MCTrack[0].GetWeight()
830 for atrack
in sTree.FitTracks:
832 fitStatus = atrack.getFitStatus()
833 if not fitStatus.isFitConverged() :
continue
834 nmeas = atrack.getNumPoints()
835 chi2 = fitStatus.getChi2()/nmeas
836 fittedState = atrack.getFittedState()
837 P = fittedState.getMomMag()
838 fout.write(
'rare event with track %i, %s, %8.2F \n'%(n,f.GetName(),wg) )
840 fout.write(
'reco %i,%5.3F,%8.2F \n'%(nmeas,chi2,P) )
841 mcPartKey = sTree.fitTrack2MC[i]
842 mcPart = sTree.MCTrack[mcPartKey]
843 for ahit
in sTree.strawtubesPoint:
844 if ahit.GetTrackID() == mcPartKey:
845 fout.write(
'P when making hit %i, %8.2F \n'%(ahit.PdgCode(),ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2+ahit.GetPz()**2)/u.GeV) )
847 if not mcPart :
continue
848 Ptruth = mcPart.GetP()
849 fout.write(
'Ptruth %i %8.2F \n'%(mcPart.GetPdgCode(),Ptruth/u.GeV) )
853 fout = ROOT.TFile(
'muDISVetoCounter.root',
'recreate')
854 h[
'ntuple'] = ROOT.TNtuple(
"muons",
"muon flux VetoCounter",
"id:px:py:pz:x:y:z:w")
857 nEvents = sTree.GetEntries()
858 for n
in range(nEvents):
860 if sTree.MCTrack.GetEntries() > 1:
861 wg = sTree.MCTrack[1].GetWeight()
863 wg = sTree.MCTrack[0].GetWeight()
864 for ahit
in sTree.vetoPoint:
865 detID = ahit.GetDetectorID()
866 if logVols[detID] !=
'VetoTimeDet':
continue
868 if abs(pid) != 13:
continue
869 P = ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2+ahit.GetPz()**2)
871 h[
'ntuple'].Fill(float(pid), float(ahit.GetPx()/u.GeV),float(ahit.GetPy()/u.GeV),float(ahit.GetPz()/u.GeV),\
872 float(ahit.GetX()/u.m),float(ahit.GetY()/u.m),float(ahit.GetZ()/u.m),float(wg) )
876 h[
'fout'] = ROOT.TFile(
'muConcrete.root',
'recreate')
877 h[
'ntuple'] = ROOT.TNtuple(
"muons",
"muon flux concrete",
"id:px:py:pz:x:y:z:w")
878 for m
in [
'',
'mu',
'V0']:
879 ut.bookHist(h,
'conc_hitz'+m,
'concrete hit z '+m,100,-100.,100.)
880 ut.bookHist(h,
'conc_hitzP'+m,
'concrete hit z vs P'+m,100,-100.,100.,100,0.,25.)
881 ut.bookHist(h,
'conc_hity'+m,
'concrete hit y '+m,100,-15.,15.)
882 ut.bookHist(h,
'conc_p'+m,
'concrete hit p '+m,1000,0.,400.)
883 ut.bookHist(h,
'conc_pt'+m,
'concrete hit pt '+m,100,0.,20.)
884 ut.bookHist(h,
'conc_hitzy'+m,
'concrete hit zy '+m,100,-100.,100.,100,-15.,15.)
885 top = sGeo.GetTopVolume()
886 magn = top.GetNode(
"magyoke_1")
887 z0 = magn.GetMatrix().GetTranslation()[2]/u.m
890 if not f.FindObjectAny(
'cbmsim'):
891 print(
'skip file ',f.GetName())
894 nEvents = sTree.GetEntries()
896 for n
in range(nEvents):
898 if sTree.MCTrack.GetEntries() > 1:
899 wg = sTree.MCTrack[1].GetWeight()
901 wg = sTree.MCTrack[0].GetWeight()
902 for ahit
in sTree.vetoPoint:
903 detID = ahit.GetDetectorID()
904 if logVols[detID] !=
'rockD':
continue
907 if abs(pid) == 13: m=
'mu'
908 P = ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2+ahit.GetPz()**2)
909 if abs(pid) == 13
and P>3/u.GeV:
911 h[
'ntuple'].Fill(float(pid), float(ahit.GetPx()/u.GeV),float(ahit.GetPy()/u.GeV),float(ahit.GetPz()/u.GeV),\
912 float(ahit.GetX()/u.m),float(ahit.GetY()/u.m),float(ahit.GetZ()/u.m),float(wg) )
913 h[
'conc_hitz'+m].Fill(ahit.GetZ()/u.m-z0,wg)
914 h[
'conc_hity'+m].Fill(ahit.GetY()/u.m,wg)
915 h[
'conc_p'+m].Fill(P/u.GeV,wg)
916 h[
'conc_hitzP'+m].Fill(ahit.GetZ()/u.m,P/u.GeV,wg)
917 Pt = ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2)
918 h[
'conc_pt'+m].Fill(Pt/u.GeV,wg)
919 h[
'conc_hitzy'+m].Fill(ahit.GetZ()/u.m-z0,ahit.GetY()/u.m,wg)
925 ut.bookCanvas(h,key=
'ResultsV0',title=
'muons hitting concrete, p>3GeV',nx=1000,ny=600,cx=2,cy=2)
926 ut.bookCanvas(h,key=
'Resultsmu',title=
'muons hitting concrete',nx=1000,ny=600,cx=2,cy=2)
927 ut.bookCanvas(h,key=
'Results',title=
'hitting concrete',nx=1000,ny=600,cx=2,cy=2)
928 for m
in [
'',
'mu',
'V0']:
929 tc = h[
'Results'+m].cd(1)
930 h[
'conc_hity'+m].Draw()
931 tc = h[
'Results'+m].cd(2)
932 h[
'conc_hitz'+m].Draw()
933 tc = h[
'Results'+m].cd(3)
935 h[
'conc_pt'+m].Draw()
936 tc = h[
'Results'+m].cd(4)
944 fout = open(fname,
'w')
947 if not f.FindObjectAny(
'cbmsim'):
948 print(
'skip file ',f.GetName())
952 if sTree.GetBranch(
"GeoTracks"): sTree.SetBranchStatus(
"GeoTracks",0)
953 nEvents = sTree.GetEntries()
954 for n
in range(nEvents):
956 if n==0 : print(
'now at event ',n,f.GetName())
957 for ahit
in sTree.vetoPoint:
958 detID = ahit.GetDetectorID()
959 if logVols[detID] !=
'Emulsion':
continue
963 if sTree.MCTrack.GetEntries() > 1:
964 wg = sTree.MCTrack[1].GetWeight()
966 wg = sTree.MCTrack[0].GetWeight()
967 fout.write(
'rare emulsion hit %i, %s, %8.3F, %i \n'%(n,f.GetName(),wg,ahit.PdgCode() ))
968 if ahit.GetPz()/u.GeV > 1. :
969 fout.write(
'V,P when making hit %8.3F,%8.3F,%8.3F %8.3F,%8.3F,%8.3F (GeV) \n'%(\
970 ahit.GetX()/u.m,ahit.GetY()/u.m,ahit.GetZ()/u.m, \
971 ahit.GetPx()/u.GeV,ahit.GetPy()/u.GeV,ahit.GetPz()/u.GeV ) )
973 fout.write(
'V,P when making hit %8.3F,%8.3F,%8.3F %8.3F,%8.3F,%8.3F (MeV)\n'%(\
974 ahit.GetX()/u.m,ahit.GetY()/u.m,ahit.GetZ()/u.m, \
975 ahit.GetPx()/u.MeV,ahit.GetPy()/u.MeV,ahit.GetPz()/u.MeV ) )
981 if fn.find(str(single)) < 0 :
continue
983 if not f.FindObjectAny(
'cbmsim'):
984 print(
'skip file ',f.GetName())
987 nEvents = sTree.GetEntries()
988 raref = ROOT.TFile(fn.replace(
".root",
"_rare.root"),
"recreate")
989 newTree = sTree.CloneTree(0)
990 for n
in range(nEvents):
992 if n==0 : print(
'now at event ',n,f.GetName())
995 for fT
in sTree.FitTracks:
996 fst = fT.getFitStatus()
997 if not fst.isFitConverged():
continue
998 if fst.getNdf() < 20:
continue
1002 print(
'filled newTree',rc)
1005 print(
' --> events saved:',newTree.GetEntries())
1010 mom = ROOT.TVector3()
1011 pos = ROOT.TVector3()
1012 golmx = top.GetNode(
"volGoliath_1").GetMatrix()
1013 zGol = golmx.GetTranslation()[2]
1014 for fn
in fchainRec:
1016 if fn.find(str(single)) < 0 :
continue
1018 if not f.FindObjectAny(
'cbmsim'):
1019 print(
'skip file ',f.GetName())
1022 nEvents = sTree.GetEntries()
1023 raref = ROOT.TFile(fn.replace(
".root",
"_clby.root"),
"recreate")
1024 newTree = sTree.CloneTree(0)
1025 for n
in range(nEvents):
1027 if n==0 : print(
'now at event ',n,f.GetName())
1030 for c
in [sTree.vetoPoint,sTree.strawtubesPoint,sTree.ShipRpcPoint]:
1032 if abs(ahit.PdgCode())!=13:
continue
1034 if mom.Mag()<3. :
continue
1036 if pos.z()<zGol :
continue
1043 print(
' --> events saved:',newTree.GetEntries())
1049 cmd =
'$ROOTSYS/bin/hadd rareEvents_'+prefix+
'.root -f '
1050 for fn
in fchainRec:
1051 if fn.find(
'muon'+prefix)<0 :
continue
1052 fr = fn.replace(
".root",
"_rare.root")
1059 ut.writeHists(h,prefix+
".root",plusCanvas=
True)
1062 if fn.find(
'root')<0: fn=fn+
'.root'
1063 if 'tc' not in h: h[
'tc'] = ROOT.TFile(fn)
1064 for x
in [
'ResultsI',
'ResultsII',
'ResultsImu',
'ResultsImuV0',
'ResultsIII',
'ResultsIV',
'ResultsV']:
1065 h[x]=h[
'tc'].FindObjectAny(x)
1068 if not prefix: prefix = (h[
'tc'].GetName()).replace(
'.root',
'')
1069 for x
in [
'ResultsI',
'ResultsII',
'ResultsImu',
'ResultsImuV0',
'ResultsIII',
'ResultsIV',
'ResultsV']:
1071 if not prefix
in os.listdir(
'.'): os.mkdir(prefix)
1073 h[
'ResultsI'].Print(prefix+
'Back_occ.png')
1074 h[
'ResultsII'].Print(prefix+
'Back_depE.png')
1075 h[
'ResultsImu'].Print(prefix+
'muBack_occ.png')
1076 h[
'ResultsImuV0'].Print(prefix+
'muV0Back_occ.png')
1077 h[
'ResultsIII'].Print(prefix+
'Back_P.png')
1078 h[
'ResultsIV'].Print(prefix+
'Back_OP.png')
1079 h[
'ResultsV'].Print(prefix+
'origin.png')
1084 n1 = h[hn+
'_mu'+tag].GetMaximum()
1085 n2 = h[hn+tag].GetMaximum()
1086 if n1>n2: h[hn+tag].SetMaximum(n1)
1087 h[hn+
'_mu'+tag].SetLineColor(4)
1088 h[hn+tag].SetLineColor(3)
1089 h[hn+
'_mu'+tag].Draw()
1090 h[hn+tag].Draw(
'same')
1094 for i
in range(sTree.GetEntries()):
1097 for gt
in sTree.GeoTracks:
1098 print(i,n,gt.GetFirstPoint()[2],gt.GetLastPoint()[2],gt.GetParticle().GetPdgCode(),gt.GetParticle().P())
1101 sTree = fchain[i].cbmsim
1102 mom = ROOT.TVector3()
1103 for i
in range(sTree.GetEntries()):
1105 nS = sTree.strawtubesPoint.GetEntries()
1107 mu = sTree.MCTrack[0]
1111 sp = sTree.strawtubesPoint[(max(0,nS-3))]
1114 print(
'-----------------------')
1116 sTree = fchain[i].cbmsim
1117 mom = ROOT.TVector3()
1118 for i
in range(sTree.GetEntries()):
1121 for vp
in sTree.vetoPoint:
1122 detName = logVols[vp. GetDetectorID()]
1123 if detName==
"VetoTimeDet": np+=0
1125 print(i,detName,vp.PdgCode())
1127 print(
'-----------------------')
1129 for n
in range(sTree.GetEntries()):
1130 rc = sTree.GetEntry(n)
1131 for ahit
in sTree.strawtubesPoint:
1132 dE = ahit.GetEnergyLoss()/u.keV
1133 rc = ahit.Momentum(mom)
1134 pa = PDG.GetParticle(ahit.PdgCode())
1136 E = ROOT.TMath.Sqrt(mom.Mag2()+mpa**2)
1138 rc = h[
'dE'].Fill(dE,ekin/u.MeV)
1139 h[
'dE'].SetXTitle(
'keV')
1140 h[
'dE'].SetYTitle(
'MeV')
1146 ni = int(fn[x-1:x])-1
1147 if nEvents < 100000:
1148 fm =
"$SHIPSOFT/data/pythia8_Geant4_onlyMuons.root"
1150 fm =
"$SHIPSOFT/data/pythia8_Geant4_Yandex_onlyMuons.root"
1151 fmuon = ROOT.TFile(fm)
1152 ntupl = fmuon.Get(
"pythia8-Geant4")
1153 ntot = ntupl.GetEntries()
1157 P = ROOT.TMath.Sqrt(ntupl.pz*ntupl.pz+ntupl.py*ntupl.py+ntupl.px*ntupl.px)
1158 fout.write(
'original muon %i, %i, %8.2F \n'%(ntupl.parentid,ntupl.pythiaid,P) )
1167 xdisk =
'/media/Work/HNL/'
1169 if type(h[x])==type(ROOT.TCanvas()):
1171 tn = h[x].GetName()+
'.png'
1173 rpath = os.path.abspath(
'.').split(
'/HNL/')[1]
1174 lp = rpath.split(
'/')
1176 for i
in range(len(lp)):
1177 if not lp[i]
in os.listdir(prefix): os.system(
'mkdir '+prefix+
'/'+lp[i])
1178 prefix = prefix+
'/'+lp[i]
1179 os.system(
'cp '+tn+
' '+xdisk+rpath)
1181from operator
import itemgetter
1188 if fn==
"rareEvents_81-102.txt" : cor = 30.
1189 for lx
in f.readlines():
1190 l = lx.replace(
'\n',
'')
1191 if not l.find(
'rare event')<0:
1192 if recTrack: result.append(recTrack)
1194 w = tmp[2].replace(
' ',
'')
1195 ff = tmp[1].split(
'/')[0].replace(
' ',
'')
1196 recTrack = {
'w':w,
'file':ff}
1197 elif not l.find(
'original')<0:
1199 recTrack[
'origin'] = tmp[0].split(
' ')[2]
1200 recTrack[
'pytiaid'] = tmp[1].replace(
' ',
'')
1201 recTrack[
'o-mom'] = tmp[2].replace(
' ',
'')
1202 elif not l.find(
'reco ')<0:
1204 recTrack[
'nmeas'] = tmp[0].split(
' ')[1]
1205 recTrack[
'chi2'] = tmp[1]
1206 recTrack[
'p_rec'] = tmp[2].replace(
' ',
'')
1207 elif not l.find(
'making')<0:
1209 recTrack[
'p_hit'] = tmp[1].replace(
' ',
'')
1210 recTrack[
'fp_hit'] = float(tmp[1].replace(
' ',
''))
1211 elif not l.find(
'Ptruth')<0:
1213 recTrack[
'id_hit'] = tmp[1].replace(
' ',
'')
1215 print(
'%4s %8s %8s %4s %8s %8s %8s %8s %8s %8s '%(
'nr',
'origin',
'pythiaID',
'ID',
'p_orig',
'p_hit',
'chi2',
'weight',
'file',
'cor w'))
1217 tmp = sorted(result, key=itemgetter(
'fp_hit'))
1221 for i
in range(len(tmp)):
1223 corw = float(tr[
'w'])/cor
1224 if float(tr[
'p_hit'])>1:muonrate1+=corw
1225 if float(tr[
'p_hit'])>2:muonrate2+=corw
1226 if float(tr[
'p_hit'])>3:muonrate3+=corw
1227 print(
'%4i %8s %8s %4s %8s %8s %8s %8s %8s %8s '%( i,tr[
'origin'],tr[
'pytiaid'],tr[
'id_hit'],tr[
'o-mom'],tr[
'p_hit'],tr[
'chi2'],tr[
'w'],tr[
'file'],corw))
1228 print(
"guestimate for muonrate above 1GeV = ",muonrate1)
1229 print(
"guestimate for muonrate above 2GeV = ",muonrate2)
1230 print(
"guestimate for muonrate above 3GeV = ",muonrate3)
1239 if p.find(
'.root')<0: x=p+
'.root'
1243 for x
in histlistAll:
1244 if histlistAll[x]
in h:
1245 histlist[k]=histlistAll[x]
1247 nstations = len(histlist)
1248 print(
"make plots for ",nstations)
static Bool_t GetCellCoordForPy(Int_t fVolID, TVector3 &all)
originOfMuon(fout, n, fn, nEvents)
executeOneFile(fn, output=None, pid=None)
extractMuCloseByEvents(single=None)
readAndMergeHistos(prods)
rareEventEmulsion(fname='rareEmulsion.txt')
extractRareEvents(single=None)
makeNicePrintout(x=['rareEvents_61-62.txt', 'rareEvents_71-72.txt'])
printAndCopy(prefix=None)
MergeRareEvents(runs=['61', '62'])
fitSingleGauss(x, ba=None, be=None)