429def coldBox(plotOnly=True,pas=''):
430
431 if 1>0:
432 tmp = options.inputFile.split('/')
433 gFile = "geofile-"+(tmp[len(tmp)-1].split('_coldbox')[0]+'_coldbox.root').replace('histos-','')
434 g = ROOT.TFile(gFile)
435 sGeo = g.FAIRGeom
436 ROOT.gROOT.cd()
437 vbox = sGeo.FindVolumeFast('vbox')
438 sbox = sGeo.FindVolumeFast('sensBox')
439 dX,dY,dZ = vbox.GetShape().GetDX(),vbox.GetShape().GetDY(),vbox.GetShape().GetDZ()
440 nav = sGeo.GetCurrentNavigator()
441 boundaries = {}
442
443 start = array('d',[0,200,0])
444 direction = array('d',[0,-1,0])
445 startnode = sGeo.InitTrack(start, direction)
446 length = c_double(200.)
447 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
448 boundaries['topIn'] = nav.GetCurrentPoint()[1]
449 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
450 boundaries['topSens'] = nav.GetCurrentPoint()[1]
451 start = array('d',[0,-200,0])
452 direction = array('d',[0,1,0])
453 startnode = sGeo.InitTrack(start, direction)
454 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
455 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
456 boundaries['botSens'] = nav.GetCurrentPoint()[1]
457
458 start = array('d',[-200,0,0])
459 direction = array('d',[1,0,0])
460 startnode = sGeo.InitTrack(start, direction)
461 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
462 boundaries['leftIn'] = nav.GetCurrentPoint()[0]
463 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
464 boundaries['leftSens'] = nav.GetCurrentPoint()[0]
465 start = array('d',[200,0,0])
466 direction = array('d',[-1,0,0])
467 startnode = sGeo.InitTrack(start, direction)
468 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
469 boundaries['rightIn'] = nav.GetCurrentPoint()[0]
470 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
471 boundaries['rightSens'] = nav.GetCurrentPoint()[0]
472
473 start = array('d',[0,0,-200])
474 direction = array('d',[0,0,1])
475 startnode = sGeo.InitTrack(start, direction)
476 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
477 boundaries['backIn'] = nav.GetCurrentPoint()[2]
478 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
479 boundaries['backSens'] = nav.GetCurrentPoint()[2]
480 start = array('d',[0,0,200])
481 direction = array('d',[0,0,-1])
482 startnode = sGeo.InitTrack(start, direction)
483 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
484 boundaries['frontIn'] = nav.GetCurrentPoint()[2]
485 node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
486 boundaries['frontSens'] = nav.GetCurrentPoint()[2]
487 Rin = {'':'','topIn':'Y','leftIn':'X','rightIn':'X','frontIn':'Z','backIn':'Z'}
488 Rsens = {'':'','topSens':'Y','botSens':'Y','leftSens':'X','rightSens':'X','frontSens':'Z','backSens':'Z'}
489 epsi = 0.1
490
491
492 if not plotOnly:
493
494 f = ROOT.TFile.Open(options.inputFile)
495 ROOT.gROOT.cd()
496 ut.bookHist(h,'start','start neutron;x [cm] ;y [cm] ;z [cm]',100,-200,200,100,-200,200,100,-200,200)
497 ut.bookHist(h,'startR','start neutron;R',100,0,200)
498 for o in ['_seco','_prim']:
499 for T in ['','cold','hot']:
500 ut.bookHist(h,'entry'+T+o,'entry neutron;x [cm] ;y [cm] ;z [cm]',100,-100,100,100,-100,100,100,-100,100)
501 ut.bookHist(h,'exit'+T+'-original'+o,'enter coldbox neutron;x [cm] ;y [cm] ;z [cm]',100,-100,100,100,-100,100,100,-100,100)
502 ut.bookHist(h,'exit'+T+o,'enter coldbox neutron;x [cm] ;y [cm] ;z [cm]',100,-100,100,100,-100,100,100,-100,100)
503 for r in Rin:
504 ut.bookHist(h,'EkinE'+r+o,'log10(Ekin)',100,-13.,0,100,-200.,200.)
505 ut.bookHist(h,'Ekin'+r+o,'log10(Ekin)',100,-13.,0,100,-200.,200.)
506 for r in Rsens:
507 ut.bookHist(h,'DF'+r+o,'travel distance',100,0.,200.)
508 ut.bookHist(h,'EkinF'+r+o,'log10(Ekin) vs distance',100,-13.,0,100,-200.,200.)
509 ut.bookHist(h,'EkinF-original'+r+o,'log10(Ekin) vs distance',100,-13.,0,100,-200.,200.)
510 ut.bookHist(h,'checkBox'+r+o,'enter coldbox neutron;x [cm] ;y [cm] ;z [cm]',100,-100,100,100,-100,100,100,-100,100)
511 ut.bookHist(h,'EkinG','log10(Ekin)',100,-13.,0.)
512 ut.bookHist(h,'EkinW','log10(Ekin)',100,-13.,0.)
513 ut.bookHist(h,'EkinWlin','Ekin',100,1E-9,100*1E-9)
514 ut.bookHist(h,'multS','mult veto points shielding',100,-0.5,99.5)
515 ut.bookHist(h,'multC','mult veto points inside',100,-0.5,99.5)
516 ut.bookHist(h,'multN','mult neutrons',100,-0.5,99.5)
517
518 flukaRateIntegrated()
519 Nsim = f.cbmsim.GetEntries()
520 for sTree in f.cbmsim:
521 rc=h['multN'].Fill(sTree.MCTrack.GetEntries())
522 neutron = sTree.MCTrack[0]
523 start = ROOT.TVector3(neutron.GetStartX(),neutron.GetStartY(),neutron.GetStartZ())
524 if start.y() < boundaries['botSens']: continue
525
526 P = ROOT.TVector3(neutron.GetPx(),neutron.GetPy(),neutron.GetPz())
527 Ekin = ROOT.TMath.Sqrt(P.Mag2()+neutronMass**2) - neutronMass
528 W = h['Fig12'].Eval(ROOT.TMath.Log10(Ekin*1000)) / Nsim
529 rc = h['start'].Fill(start.Z(),start.X(),start.Y(),W)
530 rc = h['EkinW'].Fill(ROOT.TMath.Log10(Ekin),W)
531 rc = h['EkinWlin'].Fill(Ekin,W)
532 rc = h['EkinG'].Fill(ROOT.TMath.Log10(Ekin))
533 rc = h['startR'].Fill(start.Mag(),W)
534 nC,nS=0,0
535 for p in sTree.vetoPoint:
536 if p.PdgCode()!=2112: continue
537 if p.GetDetectorID()==13: nC+=1
538 else: nS+=1
539 rc = h['multC'].Fill(nC)
540 rc = h['multS'].Fill(nS)
541 trajectory = {}
542 for p in sTree.vetoPoint:
543 if p.PdgCode()!=2112: continue
544 trackID = p.GetTrackID()
545 if not trackID in trajectory: trajectory[trackID]=[]
546 trajectory[trackID].append(p)
547 for trackID in trajectory:
548 firstSens = True
549 for p in trajectory[trackID]:
550 origin = '_seco'
551 if trackID==0: origin = '_prim'
552 lastPoint = p.LastPoint()
553 mPoint = ROOT.TVector3(p.GetX(),p.GetY(),p.GetZ())
554 firstPoint = 2*mPoint-lastPoint
555 D = lastPoint-firstPoint
556 TD = firstPoint - start
557 firstMom = ROOT.TVector3(p.GetPx(),p.GetPy(),p.GetPz())
558 Ekin_entry = ROOT.TMath.Sqrt(firstMom.Mag2()+neutronMass**2) - neutronMass
559 if p.GetDetectorID()==13 and firstSens:
560 firstSens = False
561 rc = h['exit'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
562
563 if Ekin*1E9< 10: rc = h['exitcold-original'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
564 else: rc = h['exithot-original'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
565
566 if Ekin_entry*1E9< 10: rc = h['exitcold'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
567 else: rc = h['exithot'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
568 rc = h['DF'+origin].Fill(TD.Mag(),W)
569 rc = h['EkinF'+origin].Fill(ROOT.TMath.Log10(Ekin_entry),D.Mag(),W)
570 rc = h['EkinF-original'+origin].Fill(ROOT.TMath.Log10(Ekin),D.Mag(),W)
571
572 found = False
573 for r in Rsens:
574 if r=='': continue
575 X = eval('firstPoint.'+Rsens[r]+'()')
576 if abs(X-boundaries[r]) < epsi:
577
578 found = True
579 break
580 if not found:
581 txt = ''
582 for r in Rsens:
583 if r=='': continue
584 X = eval('firstPoint.'+Rsens[r]+'()')
585 txt+= " "+r+" "+str(X)
586 print("this should no happen", txt, boundaries)
587 for P in trajectory[trackID]: print(P.GetDetectorID(),P.LastPoint().X(),P.LastPoint().Y(),P.LastPoint().Z())
588 rc = h['DF'+r+origin].Fill(TD.Mag(),W)
589 rc = h['EkinF'+r+origin].Fill(ROOT.TMath.Log10(Ekin_entry),D.Mag(),W)
590 rc = h['EkinF-original'+r+origin].Fill(ROOT.TMath.Log10(Ekin),D.Mag(),W)
591 rc = h['checkBox'+r+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
592
593 if p.GetDetectorID()==1:
594
595 if firstPoint.Mag()<lastPoint.Mag(): continue
596 rc = h['Ekin'+origin].Fill(ROOT.TMath.Log10(Ekin),D.Mag(),W)
597 rc = h['EkinE'+origin].Fill(ROOT.TMath.Log10(Ekin_entry),D.Mag(),W)
598 rc = h['entry'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
599 if Ekin*1E9< 10: rc = h['entrycold'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
600 else: rc = h['entryhot'+origin].Fill(firstPoint.X(),firstPoint.Y(),firstPoint.Z(),W)
601
602 for r in Rin:
603 if r=='': continue
604 X = eval('firstPoint.'+Rin[r]+'()')
605 if abs(X-boundaries[r]) < epsi: break
606 rc = h['Ekin'+r+origin].Fill(ROOT.TMath.Log10(Ekin),X,W)
607 rc = h['EkinE'+r+origin].Fill(ROOT.TMath.Log10(Ekin_entry),X,W)
608
609 tmp = options.inputFile.split('/')
610 outFile = 'histos-'+ tmp[len(tmp)-1]
611
612 hkeys = list(h.keys())
613 for x in hkeys:
614 if x.find( '_seco')>0:
615 hname = x.replace('_seco','')
616 h[hname]=h[x].Clone(hname)
617 h[hname].Add(h[x.replace('_seco','_prim')])
618
619 ut.writeHists(h,outFile)
620 print('finished making histograms ','histos-noConc-'+options.inputFile)
621
622 else:
623 ut.readHists(h,options.inputFile)
624 if pas!='': ut.readHists(hnorm,'histos-thermNeutron_vacuums_0.0001_coldbox_pass1.root')
625 else: ut.readHists(hnorm,options.inputFile)
626 tmp = options.inputFile.split('_')
627 material = tmp[1]+"_coldbox/"
628 thickness = "_"+tmp[2]
629
630 binning = {}
631 for c in ['entry','exit']:
632 binning[c]={}
633 for p in ['x','y','z']:
634 tmp = h[c].Project3D(p)
635 for imin in range(1,tmp.GetNbinsX()+1):
636 if tmp.GetBinContent(imin)>0: break
637 for imax in range(tmp.GetNbinsX(),0,-1):
638 if tmp.GetBinContent(imax)>0: break
639 binning[c][p]={'min':imin,'max':imax}
640
641
642 ytop = {'axis':'Y','proj':'xz','entry':binning['entry']['y']['max'],'exit':h['exit'].GetYaxis().FindBin(boundaries['topSens']),'xdist':dZ,'ydist':dX}
643 ybot = {'axis':'Y','proj':'xz','entry':binning['entry']['y']['min'],'exit':h['exit'].GetYaxis().FindBin(boundaries['botSens']),'xdist':dZ,'ydist':dX}
644 xLeft = {'axis':'X','proj':'yz','entry':binning['entry']['x']['min'],'exit':h['exit'].GetXaxis().FindBin(boundaries['leftSens']),'xdist':dZ,'ydist':dY}
645 xRight = {'axis':'X','proj':'yz','entry':binning['entry']['x']['max'],'exit':h['exit'].GetXaxis().FindBin(boundaries['rightSens']),'xdist':dZ,'ydist':dY}
646 zMin = {'axis':'Z','proj':'yx','entry':binning['entry']['z']['min'],'exit':h['exit'].GetZaxis().FindBin(boundaries['backSens']),'xdist':dX,'ydist':dY}
647 zMax = {'axis':'Z','proj':'yx','entry':binning['entry']['z']['max'],'exit':h['exit'].GetXaxis().FindBin(boundaries['frontSens']),'xdist':dX,'ydist':dY}
648 print('boundaries',boundaries)
649
650
651 projections = {'Top':ytop,'Bot':ybot,'Right':xRight,'Left':xLeft,'Front':zMax,'Back':zMin}
652 h['fluences'] = {}
653 for o in ['','_prim']:
654 for T in ['','cold','hot']:
655 for Z in ['entry','exit','exit-original']:
656 tmp = Z.split('-')
657 c = tmp[0]
658 x=''
659 if len(tmp)>1: x='-'+tmp[1]
660 case = c+T+x+o
661 ut.bookCanvas(h,'t'+case,case,1200,1800,2,3)
662 k=1
663 for p in projections:
664 h['t'+case].cd(k)
665 tmp = h[case]
666 axis = eval('tmp.Get'+projections[p]['axis']+'axis()')
667 if Z=='entry': axis.SetRange(projections[p][c]-1,projections[p][c]+1)
668 else:
669 axis.SetRange(projections[p][c],projections[p][c])
670 if p=='xBot':
671 xax = tmp.GetXaxis()
672 xax.SetRange(xax.FindBin(boundaries['leftSens'])+1,xax.FindBin(boundaries['rightSens'])-1)
673 zax = tmp.GetZaxis()
674 zax.SetRange(zax.FindBin(boundaries['backSens'])+1,zax.FindBin(boundaries['frontSens'])-1)
675 h[case+p] = tmp.Project3D(projections[p]['proj'])
676 h[case+p].SetName(case+p)
677 tmp.GetXaxis().SetRange(0,0)
678 tmp.GetYaxis().SetRange(0,0)
679 tmp.GetZaxis().SetRange(0,0)
680 h[case+p].SetStats(0)
681 h[case+p].SetMinimum(0)
682 h[case+p].SetTitle(p)
683 h[case+p].Draw('colz')
684
685 h['X-'+case+p]=h[case+p].ProjectionX('X-'+case+p)
686 h['Y-'+case+p]=h[case+p].ProjectionY('Y-'+case+p)
687 k+=1
688 sqcm = projections[p]['xdist']* projections[p]['ydist']
689 entries = h[case+p].GetSumOfWeights()
690 X = entries/sqcm
691 if X > 100: txt = "%5.1F/cm^{2}"%(X)
692 else: txt = "%5.2F/cm^{2}"%(X)
693 h['fluences'][case+p] =X
694 L = ROOT.TLatex()
695 rc = L.DrawLatexNDC(0.2,0.85,txt)
696 h['X-'+case+p].Scale(1./ projections[p]['ydist'])
697 h['Y-'+case+p].Scale(1./ projections[p]['xdist'])
698 myPrint(h['t'+case],material+'t'+case+thickness)
699
700
701 ut.bookCanvas(h,'crosschecks','cross checks',900,600,1,1)
702 tc = h['crosschecks'].cd()
703 tc.SetLogy(1)
704 tc.SetGridx()
705 tc.SetGridy()
706 h['EkinW'].SetStats(0)
707 h['EkinW'].SetStats(0)
708 h['EkinW'].SetLineWidth(3)
709 h['EkinW'].SetTitle(';log(E) [GeV];dn/dlogE [cm^{-2}y^{-1}] ')
710 h['EkinW'].SetMaximum(1E8)
711 h['EkinW'].SetMinimum(1E2)
712 h['EkinW'].Draw()
713 myPrint(h['crosschecks'],material+'kinEnergy'+thickness )
714 tc.SetLogy(0)
715 k=-10
716 for p in projections:
717 for l in ['X-','Y-']:
718 case = l+'entry'+p
719 h[case].SetLineColor(ROOT.kRed+k)
720 h[case].SetStats(0)
721 if k<-9:
722 h[case].SetTitle('; x,y,z [cm]; N/L [cm^{-1}]')
723 tpl = ut.findMaximumAndMinimum(h[case])
724 h[case].SetMaximum(tpl[1]*1.5)
725 h[case].Draw()
726 else: h[case].Draw('same')
727 k+=1
728 myPrint(h['crosschecks'],material+'irradiationXYZ'+thickness )
729
730 tc.SetLogy(1)
731
732
733 ut.bookCanvas(h,'trej','rejections',1200,1800,2,3)
734 k=0
735 for r in ['','top','bot','right','left','front','back']:
736 rej = 'rej'+r
737 rejo = 'rejo'+r
738 if r=='':
739 norm = hnorm['Ekin'].ProjectionX('norm')
740 h[rej] = h['EkinF'].ProjectionX(rej)
741 h[rejo] = h['EkinF-original'].ProjectionX(rejo)
742 else:
743 k+=1
744 if r=='bot': norm = hnorm['EkintopIn'].ProjectionX('norm')
745 else: norm = hnorm['Ekin'+r+'In'].ProjectionX('norm')
746 h[rej] = h['EkinF'+r+'Sens'].ProjectionX(rej)
747 h[rejo] = h['EkinF-original'+r+'Sens'].ProjectionX(rejo)
748 h[rej].Divide(norm)
749 h[rejo].Divide(norm)
750 h[rej].SetStats(0)
751 h[rejo].SetStats(0)
752 h[rej].SetTitle(';log10(Ekin) GeV; rejection')
753 h[rej].SetLineColor(ROOT.kBlue)
754 h[rej].SetLineWidth(2)
755 h[rejo].SetLineWidth(2)
756 h[rejo].SetLineColor(ROOT.kGreen)
757 h[rej].GetXaxis().SetRangeUser(-13.,-1.)
758 h[rej].SetMaximum(1.2)
759 h[rej].SetMinimum(1.E-4)
760 if k==0: tc = h['crosschecks'].cd()
761 else:
762 tc = h['trej'].cd(k)
763 tc.SetGridx()
764 tc.SetGridy()
765 h[rej].SetMinimum(1.E-6)
766 h[rej].SetTitle(r[0].upper()+r[1:])
767 tc.SetLogy()
768 h[rej].Draw('hist')
769 h[rejo].Draw('histsame')
770 h['legR'+r]=ROOT.TLegend(0.11,0.74,0.72,0.82)
771 rc = h['legR'+r].AddEntry(h[rejo],'reduction as function of original E_{kin} when entering shield','PL')
772 rc = h['legR'+r].AddEntry(h[rej],'reduction as function of E_{kin} when leaving shield','PL')
773 h['legR'+r].Draw('same')
774 if k==0: myPrint(h['crosschecks'],material+'rejections'+thickness)
775 myPrint(h['trej'],material+'Listrejections'+thickness+pas)
776
777 h['dangerZone']=ROOT.TGraph()
778 h['dangerZone'].SetPoint(0,-8.6,0.)
779 h['dangerZone'].SetPoint(1,-8.6,1.)
780 h['dangerZone'].SetPoint(2,-8.1,1.)
781 h['dangerZone'].SetPoint(3,-8.1,0.)
782 h['dangerZone'].SetFillStyle(1001)
783 h['dangerZone'].SetFillColor(ROOT.kYellow)
784 for r in ['rej','rejo']:
785 ut.bookCanvas(h,r+'ection2','rejectionRate',900,600,1,1)
786 h[r+'TopLeftRightBack'] = h[r+'top'].Clone(r+'TopLeftRightBack')
787 h[r+'TopLeftRightBack'].Add(h[r+'left'])
788 h[r+'TopLeftRightBack'].Add(h[r+'right'])
789 h[r+'TopLeftRightBack'].Add(h[r+'back'])
790 h[r+'TopLeftRightBack'].Scale(1./4.)
791 h[r+'TopLeftRightBack'].SetTitle('')
792 if r=='rej': h[r+'TopLeftRightBack'].GetXaxis().SetTitle('outgoing '+h[r+'TopLeftRightBack'].GetXaxis().GetTitle())
793 if r=='rejo': h[r+'TopLeftRightBack'].GetXaxis().SetTitle('incoming '+h[r+'TopLeftRightBack'].GetXaxis().GetTitle())
794 h[r+'TopLeftRightBack'].SetLineColor(ROOT.kGreen)
795 h[r+'bot'].SetLineColor(ROOT.kGray)
796 h[r+'front'].SetLineColor(ROOT.kRed)
797 h[r+'TopLeftRightBack'].SetMaximum(1.2)
798 h[r+'TopLeftRightBack'].SetMinimum(1.E-6)
799 tc = h[r+'ection2'].cd()
800 tc.SetGridx()
801 tc.SetGridy()
802 tc.SetLogy()
803 h[r+'TopLeftRightBack'].Draw()
804 h['dangerZone'].Draw('sameF')
805 h[r+'TopLeftRightBack'].Draw('same')
806 h[r+'bot'].Draw('same')
807 h[r+'front'].Draw('same')
808 h[r+'legR2']=ROOT.TLegend(0.55,0.30,0.86,0.45)
809 rc = h[r+'legR2'].AddEntry(h[r+'TopLeftRightBack'],'av. rejection top/left/right/back','PL')
810 rc = h[r+'legR2'].AddEntry(h[r+'bot'],'rejction bottom, only concrete','PL')
811 rc = h[r+'legR2'].AddEntry(h[r+'front'],'rejction front, with holes','PL')
812 h[r+'legR2'].Draw('same')
813 myPrint(h[r+'ection2'],material+'Sum '+r+'ections'+thickness+pas)
814
815 if pas=='': ut.writeHists(h,options.inputFile.replace('.root','_pass1.root'))
816
817
818 for o in ['','-original']:
819 for T in ['cold','hot']:
820 norm = 0
821 exit = 0
822 concrete = 0
823 holes = 0
824 for p in projections:
825 if p!='Bot' and norm!='Front':
826 norm+=h['fluences']['entry'+T+p]
827 exit+=h['fluences']['exit'+T+o+p]
828 if p=='Bot': concrete = h['fluences']['exit'+T+o+p]
829 elif p=='Front': holes = h['fluences']['exit'+T+o+p]
830 norm = norm/float(4)
831 exit = exit/float(4)
832
833
834 print('%s %s region: %5.2F concrete: %5.2F holes: %5.2F x permille total: %5.2F x permille'%(o,T,exit/norm*1000,concrete/norm*1000,holes/norm*1000,(4*exit+concrete+holes)/(6*norm)*1000))
835
836
837