def DrawCol():
   u.bookCanvas(h,key='colorTable',title='colors',nx=100,ny=600,cx=1,cy=1)
   gPad = h['colorTable'].cd(1)
   gPad.SetFillColor(0)
   gPad.Clear()
   text = ROOT.TText(0,0,"")
   text.SetTextFont(61)
   text.SetTextSize(0.07)
   text.SetTextAlign(22)
   box =  ROOT.TBox()
   # Draw color table boxes.
   hs   = 1./float(8)
   xlow = 0.1
   xup  = 0.9
   j = 0
   for E in range(50,450,50):
      ylow =  hs*(j+0.1)
      yup  =  hs*(j+0.9)
      color = ncol[E]
      box.SetFillStyle(1001)
      box.SetFillColor(color)
      box.DrawBox(xlow, ylow, xup, yup)
      box.SetFillStyle(0)
      box.SetLineColor(1)
      box.DrawBox(xlow, ylow, xup, yup)
      if color == 1: text.SetTextColor(0)
      else         : text.SetTextColor(1)
      text.DrawText(0.5*(xlow+xup), 0.5*(ylow+yup), str(E)+' GeV/c')
      j+=1
示例#2
0
def eventTime(Nev=-1):
 Tprev = -1
 if Nev < 0 : Nev = eventTree.GetEntries()
 ut.bookHist(h,'Etime','delta event time; dt [s]',100,0.0,1.)
 ut.bookHist(h,'EtimeZ','delta event time; dt [ns]',1000,0.0,10000.)
 ut.bookCanvas(h,'T',' ',1024,2*768,1,2)
 eventTree.GetEvent(0)
 t0 =  eventTree.EventHeader.GetEventTime()/160.E6
 eventTree.GetEvent(Nev-1)
 tmax = eventTree.EventHeader.GetEventTime()/160.E6
 ut.bookHist(h,'time','elapsed time; t [s]',1000,0,tmax-t0)

 N=-1
 for event in eventTree:
    N+=1
    if N>Nev: break
    T = event.EventHeader.GetEventTime()
    dT = 0
    if Tprev >0: dT = T-Tprev
    Tprev = T
    rc = h['Etime'].Fill(dT/freq)
    rc = h['EtimeZ'].Fill(dT*1E9/160.E6)
    rc = h['time'].Fill( (T/freq-t0))
 tc = h['T'].cd(1)
 tc.SetLogy(1)
 h['EtimeZ'].Draw()
 tc.Update()
 tc = h['T'].cd(2)
 h['time'].Draw()
 h['T'].Update()
 h['T'].Print('time-run'+str(options.runNumber)+'.png')
示例#3
0
def plotHitMaps():
 for event in sTree:
  for hit in event.Digi_MufluxSpectrometerHits:
   s,v,p,l,view = stationInfo(hit)
   rc = xLayers[s][p][l][view].Fill(hit.GetDetectorID()%1000)
   rc = h['TDC'+xLayers[s][p][l][view].GetName()].Fill(hit.GetDigi())
  if not h.has_key('hitMapsX'): ut.bookCanvas(h,key='hitMapsX',title='Hit Maps All Layers',nx=1600,ny=1200,cx=4,cy=6)
  if not h.has_key('TDCMapsX'): ut.bookCanvas(h,key='TDCMapsX',title='TDC Maps All Layers',nx=1600,ny=1200,cx=4,cy=6)
 j=0
 for s in range(1,5):
  for view in ['_x','_u','_v']:
   for p in range(2):
    for l in range(2):
     if not xLayers[s][p][l].has_key(view):continue
     if s>2 and view != '_x': continue
     if s==1 and view == '_v': continue
     if s==2 and view == '_u': continue
     j+=1
     rc = h['hitMapsX'].cd(j)
     xLayers[s][p][l][view].Draw()
     rc = h['TDCMapsX'].cd(j)
     h['TDC'+xLayers[s][p][l][view].GetName()].Draw()
     mean = xLayers[s][p][l][view].GetEntries()/channels[s][p][l][view]
     for i in range(int(xLayers[s][p][l][view].GetEntries())):
      if xLayers[s][p][l][view].GetBinContent(i) > noiseThreshold * mean:
          n = xLayers[s][p][l][view].GetName().split('_')[0]
          noisyChannels.append(int(n)*100+i)
 print "list of noisy channels"
 for n in noisyChannels: print n
示例#4
0
def runStability(C=None):
    if not C: C = getCalibrationParameters(options.runNumbers)
    runEvol = {1:{},2:{}}
    badChannels = {1:{},2:{}}
    for r in C:
       for s in C[r]:
          for l in C[r][s]:
            for i in C[r][s][l]['mean']:
               value = C[r][s][l]['mean'][i]
               key = l+'_'+str(i)
               rError = value[1] / value[0]
               if rError > 0.05: continue # remove distributions with low statistics
               if not key in runEvol[s]: runEvol[s][key] = ROOT.TGraph()
               n = runEvol[s][key].GetN()
               runEvol[s][key].SetPoint(n,value[0],1.)
          ut.bookHist(h,'rms'+sdict[s],'rms',1000,-1.,1.)
          ut.bookCanvas(h,sdict[s],'',900,600,1,1)
          h[sdict[s]].cd()
          for key in runEvol[s]:
            x = runEvol[s][key].GetRMS()/runEvol[s][key].GetMean()
            rc = h['rms'+sdict[s]].Fill(x)
            if abs(x)>0.2: badChannels[key]=x
            print("%s : %5.2F  %5.2F  %5.2F"%(key,x,runEvol[s][key].GetRMS(),runEvol[s][key].GetMean()))
          h['rms'+sdict[s]+'100']=h['rms'+sdict[s]].Rebin(10,'rms'+sdict[s]+'100')
          h['rms'+sdict[s]+'100'].Draw()
    return runEvol,badChannels
示例#5
0
def makePlots():
   ut.bookCanvas(h,key='fitresults',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   cv = h['fitresults'].cd(1)
   h['delPOverP'].Draw('box')
   cv = h['fitresults'].cd(2)
   cv.SetLogy(1)
   h['chi2'].Draw()
   cv = h['fitresults'].cd(3)
   h['delPOverP_proj'] = h['delPOverP'].ProjectionY()
   ROOT.gStyle.SetOptFit(11111)
   h['delPOverP_proj'].Draw()
   h['delPOverP_proj'].Fit('gaus')
   cv = h['fitresults'].cd(4)
   h['delPOverP2_proj'] = h['delPOverP2'].ProjectionY()
   h['delPOverP2_proj'].Draw()
   h['delPOverP2_proj'].Fit('gaus')  
   h['fitresults'].Print('fitresults.gif')
   ut.bookCanvas(h,key='fitresults2',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   cv = h['fitresults2'].cd(1)
   h['Doca'].Draw()
   cv = h['fitresults2'].cd(2)
   h['IP0'].Draw()
   cv = h['fitresults2'].cd(3)
   h['HNL'].Draw()
   h['HNL'].Fit('gaus') 
   cv = h['fitresults2'].cd(4)
   h['IP0/mass'].Draw('box')
   h['fitresults2'].Print('fitresults2.gif')
def DrawCol():
   if h.has_key('colorTable') : return
   u.bookCanvas(h,key='colorTable',title='colors',nx=100,ny=600,cx=1,cy=1)
   gPad = h['colorTable'].cd(1)
   gPad.SetFillColor(0)
   gPad.Clear()
   text = ROOT.TText(0,0,"")
   text.SetTextFont(61)
   text.SetTextSize(0.07)
   text.SetTextAlign(22)
   box =  ROOT.TBox()
   # Draw color table boxes.
   hs   = 1./float(8)
   xlow = 0.1
   xup  = 0.9
   for j in h['Erange']:
      E  = h['Erange'][j]
      ylow =  hs*(j-1+0.1)
      yup  =  hs*(j-1+0.9)
      color = ncol[int(E)]
      box.SetFillStyle(1001)
      box.SetFillColor(color)
      box.DrawBox(xlow, ylow, xup, yup)
      box.SetFillStyle(0)
      box.SetLineColor(1)
      box.DrawBox(xlow, ylow, xup, yup)
      if color == 1: text.SetTextColor(0)
      else         : text.SetTextColor(1)
      text.DrawText(0.5*(xlow+xup), 0.5*(ylow+yup), E+' GeV/c')
def makePlots():
    ut.bookCanvas(h,
                  key='Test_Mass',
                  title='Fit Results',
                  nx=1000,
                  ny=1000,
                  cx=2,
                  cy=2)
    cv = h['Test_Mass'].cd(1)
    h['HNL_true'].SetXTitle('Invariant mass [GeV/c2]')
    h['HNL_true'].SetYTitle('No. of Particles')
    h['HNL_true'].Draw()

    cv = h['Test_Mass'].cd(2)
    h['HNL_reco'].SetXTitle('Invariant mass [GeV/c2]')
    h['HNL_reco'].SetYTitle('No. of Particles')
    h['HNL_reco'].Draw()
    fitSingleGauss('HNL_reco', 0.9, 1.1)

    cv = h['Test_Mass'].cd(3)
    h['HNL_mom'].SetXTitle('Momentum [GeV/c]')
    h['HNL_mom'].SetYTitle('No. of Particles')
    h['HNL_mom'].SetLineColor(2)
    h['HNL_mom'].Draw()
    h['HNL_mom_reco'].Draw("same")

    cv = h['Test_Mass'].cd(4)
    h['HNL_mom_diff'].SetXTitle('Momentum Difference [GeV/c]')
    h['HNL_mom_diff'].SetYTitle('Frequency')
    h['HNL_mom_diff'].Draw()
    h['Test_Mass'].Print('HNLgraphs.png')
    #======================================================================================================================
    ut.bookCanvas(h,
                  key='Time_Res',
                  title='Fit Results 2',
                  nx=1000,
                  ny=1000,
                  cx=2,
                  cy=2)
    cv = h['Time_Res'].cd(1)
    h['Time'].SetXTitle('Time [ns]')
    h['Time'].SetYTitle('Frequency')
    h['Time'].Draw()

    cv = h['Time_Res'].cd(2)
    h['Time2'].SetXTitle('Time [ns]')
    h['Time2'].SetYTitle('Frequency')
    h['Time2'].Draw()

    cv = h['Time_Res'].cd(3)
    h['Time3'].SetXTitle('Time [ns]')
    h['Time3'].SetYTitle('Frequency')
    h['Time3'].Draw()

    cv = h['Time_Res'].cd(4)
    h['Time4'].SetXTitle('Time [ns]')
    h['Time4'].SetYTitle('Frequency')
    h['Time4'].Draw()
    h['Time_Res'].Print('TimeRes1.png')
示例#8
0
def makePlots():
    ut.bookCanvas(h,key='DPanalysis',title='Mass',nx=800,ny=600,cx=2,cy=1)
    cv = h['DPanalysis'].cd(1)
    h['DPgenM'].Draw()
    cv = h['DPanalysis'].cd(2)
    h['DPselMw'].Draw()
    h['DPanalysis'].Print("./DPmass.pdf")
    h['DPanalysis'].Print("./DPmass.png")
    print 'finished making plots'
示例#9
0
def plotEvent(n):
   rc = sTree.GetEvent(n)
   for c in hitCollection: rc=hitCollection[c][1].Set(0)
   global stereoHits
   stereoHits = []
   ut.bookHist(h,'xz','x (y) vs z',500,0.,1200.,100,-150.,150.)
   if not h.has_key('simpleDisplay'): ut.bookCanvas(h,key='simpleDisplay',title='simple event display',nx=1600,ny=1200,cx=1,cy=0)
   rc = h[ 'simpleDisplay'].cd(1)
   h['xz'].SetMarkerStyle(30)
   h['xz'].SetStats(0)
   h['xz'].Draw('b')
   for hit in sTree.Digi_MufluxSpectrometerHits:
    statnb,vnb,pnb,lnb,view = stationInfo(hit)
    # print statnb,vnb,pnb,lnb,view,hit.GetDetectorID()
    rc = hit.MufluxSpectrometerEndPoints(vbot,vtop)
    if view != '_x':
      stereoHit = ROOT.TGraph()
      stereoHit.SetPoint(0,vbot[2],vbot[0])
      stereoHit.SetPoint(1,vtop[2],vtop[0])
      stereoHits.append(stereoHit)
      continue
    if statnb<3:  
     c = hitCollection['upstream'] 
     rc = c[1].SetPoint(c[0],vbot[2],vbot[0])
     c[0]+=1 
    else:
     c = hitCollection['downstream'] 
     rc = c[1].SetPoint(c[0],vbot[2],vbot[0])
     c[0]+=1
   c = hitCollection['muonTagger'] 
   for hit in sTree.Digi_MuonTaggerHits:
    channelID = hit.GetDetectorID()
    statnb = channelID/10000
    view   = (channelID-10000*statnb)/1000
    channel = channelID%1000
    if view == 1:
    #poor man geometry , probably completly wrong
     x = +rpc[statnb][0] - 2*rpc[statnb][0]/rpcchannels*channel
     rc = c[1].SetPoint(c[0],rpc[statnb][2],x)
     c[0]+=1
   hitCollection['downstream'][1].SetMarkerColor(ROOT.kRed)
   hitCollection['upstream'][1].SetMarkerColor(ROOT.kBlue)
   hitCollection['muonTagger'][1].SetMarkerColor(ROOT.kGreen)
   for c in hitCollection: rc=hitCollection[c][1].SetMarkerStyle(30)
   for c in hitCollection:
     if hitCollection[c][1].GetN()<1: continue
     rc=hitCollection[c][1].Draw('sameP')
     h['display:'+c]=hitCollection[c][1]
   for g in stereoHits:
     g.SetLineWidth(2)
     g.Draw('same')
   h[ 'simpleDisplay'].Update()
示例#10
0
def analyzeConcrete():
 for m in ['','mu']:
  ut.bookHist(h,'conc_hitz'+m,'concrete hit z '+m,100,-100.,100.)
  ut.bookHist(h,'conc_hity'+m,'concrete hit y '+m,100,-15.,15.)
  ut.bookHist(h,'conc_p'+m,'concrete hit p '+m,100,0.,300.)
  ut.bookHist(h,'conc_pt'+m,'concrete hit pt '+m,100,0.,10.)
  ut.bookHist(h,'conc_hitzy'+m,'concrete hit zy '+m,100,-100.,100.,100,-15.,15.)
 top = fGeo.GetTopVolume()
 magn = top.GetNode("magyoke_1")
 z0 = magn.GetMatrix().GetTranslation()[2]/u.m
 for fn in fchain:
  f = ROOT.TFile(fn)
  if not f.FindObjectAny('cbmsim'): 
   print 'skip file ',f.GetName() 
   continue
  sTree = f.cbmsim
  nEvents = sTree.GetEntries()
  for n in range(nEvents):
   sTree.GetEntry(n)
   wg = sTree.MCTrack[0].GetWeight()   
   for ahit in sTree.vetoPoint:
     detID = ahit.GetDetectorID()
     if logVols[detID] != 'rockD': continue  
     m=''       
     if abs(ahit.PdgCode()) == 13: m='mu'
     h['conc_hitz'+m].Fill(ahit.GetZ()/u.m-z0,wg)
     h['conc_hity'+m].Fill(ahit.GetY()/u.m,wg)
     P = ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2+ahit.GetPz()**2)
     h['conc_p'+m].Fill(P/u.GeV,wg)
     Pt = ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2)
     h['conc_pt'+m].Fill(Pt/u.GeV,wg)
     h['conc_hitzy'+m].Fill(ahit.GetZ()/u.m-z0,ahit.GetY()/u.m,wg)
 #
     start = [ahit.GetX()/u.m,ahit.GetY()/u.m,ahit.GetZ()/u.m]
     direc = [-ahit.GetPx()/P,-ahit.GetPy()/P,-ahit.GetPz()/P]
     t = - start[0]/direc[0]
     
 ut.bookCanvas(h,key='Resultsmu',title='muons hitting concrete',nx=1000,ny=600,cx=2,cy=2)  
 ut.bookCanvas(h,key='Results',title='hitting concrete',nx=1000,ny=600,cx=2,cy=2)  
 for m in ['','mu']:
  tc = h['Results'+m].cd(1)
  h['conc_hity'+m].Draw()
  tc = h['Results'+m].cd(2)
  h['conc_hitz'+m].Draw()
  tc = h['Results'+m].cd(3)
  tc.SetLogy(1)
  h['conc_pt'+m].Draw()
  tc = h['Results'+m].cd(4)
  tc.SetLogy(1)
  h['conc_p'+m].Draw()
示例#11
0
def makeTPplots():
 h['decayVolumeRho'] = ROOT.TLine(0,5.,(ShipGeo['TrackStation1'].z-z_zero)/u.m,5.)
 h['decayVolumeRho'].SetLineColor(3)
 h['decayVolumeRho'].SetLineWidth(3)
 h['decayVolumeRho2'] = ROOT.TLine(0,2.5,(ShipGeo['TrackStation1'].z-z_zero)/u.m,2.5)
 h['decayVolumeRho2'].SetLineColor(3)
 h['decayVolumeRho2'].SetLineWidth(3)
 h['decayVolumeRho2'].SetLineStyle(4)
 h['decayVolumeZ'] = ROOT.TLine((ShipGeo['TrackStation1'].z-z_zero)/u.m,0.,(ShipGeo['TrackStation1'].z-z_zero)/u.m,5.)
 h['decayVolumeZ'].SetLineColor(3)
 h['decayVolumeZ'].SetLineWidth(3)
 h['txtDV1'] = ROOT.TLatex(5.,1.0,"Decay volume")
 h['txtDV2a'] = ROOT.TLatex(5.,1.5,"Decay")
 h['txtDV2b'] = ROOT.TLatex(5.,0.5,"volume")
# 
 ROOT.gStyle.SetOptStat(0)
 h['rhozmu'] = h['130rhozmu'].Clone('rhozmu') 
 h['rhozmu'].Add(h['310rhozmu'])
 h['rhozmu'].Add(h['3122rhozmu'])
 ut.bookCanvas(h,key='tp1',title='rho z muons',nx=900,ny=600,cx=1,cy=1) 
 tc = h['tp1'].cd(1)
 h['rhozmu'].SetYTitle('distance from beam axis [m]')  
 h['rhozmu'].SetXTitle('distance to start of decay volume [m]') 
 h['rhozmu'].SetZTitle('Number of muons') 
 h['rhozmu'].Draw('colz')
 h['decayVolumeRho'].Draw()
 h['decayVolumeRho2'].Draw()
 h['decayVolumeZ'].Draw()
 h['txtDV1'].Draw() 
 h['tp1'].Print('muonConcreterhoZ.pdf')
#
 i = 1
 for x in hdict: 
  h['resultsrhoZ'].cd(i) 
  hn = str(x)+'rhoz'
  if i==1: h[hn].SetYTitle('distance from beam axis [m]')  
  else: h[hn].SetYTitle('')
  if i==2: h[hn].SetXTitle('distance to start of decay vol. [m]')
  else: h[hn].SetXTitle('')
  h['txtV0'+str(x)] = ROOT.TLatex(10.,6.,hdict[x])
  h[hn].Draw('colz')
  h['txtV0'+str(x)].Draw()
  h['decayVolumeRho'].Draw()
  h['decayVolumeRho2'].Draw()
  h['decayVolumeZ'].Draw()
  h['txtDV2a'].Draw() 
  h['txtDV2b'].Draw() 
  i+=1
 h['resultsrhoZ'].Print('V0Decay_point.pdf')
def addAllHistograms():
 h={}
 ecut = '10.0'
 Nmax=45000
 path = os.environ['EOSSHIP']+"/eos/experiment/ship/data/Mbias/background-prod-2018/"
 ut.bookCanvas(h,key='canvas',title='debug',nx=1600,ny=1200,cx=1,cy=1)
 h['canvas'].SetLogy(1)
 for i in range(0,Nmax,1000):
  fname = "pythia8_Geant4_"+ecut+"_c"+str(i)+".root"
  ut.readHists(h,path+fname)
  if i==0:
    h[1012].Draw()
 for x in h.keys():
   if h[x].GetName().find('proj')>0: rc = h.pop(x)
 ut.writeHists(h,"pythia8_Geant4_"+ecut+"_c"+str(Nmax)+"-histos.root")
示例#13
0
def absorptionLengthOLD():
    Lfun = ROOT.TF1('Lfun', '[0]*(10**x)**[1]', -9, -6)
    Lfun.SetParameter(0, 6.4)
    Lfun.SetParameter(1, 0.98)
    hFiles = {
        "thermNeutron_BoronCarbide_X.XX_-E_-E_0.root": [0.08, 0.3],
        "thermNeutron_Boratedpolyethylene_X.XX_0.root": [1.0, 100.]
    }
    # thermNeutron_BoronCarbide_4.0_-8_-7_0.root

    Ls = {
        0.01: ROOT.kRed,
        0.1: ROOT.kOrange,
        0.04: ROOT.kCyan,
        0.4: ROOT.kBlue,
        4.0: ROOT.kMagenta
    }

    for hFile in hFiles:
        material = hFile.split('_')[1]
        ut.bookCanvas(h, 'absorb' + material, '', 1200, 800, 1, 1)
        h['absorb' + material].cd()
        for L in Ls:
            l = str(L)
            if L < 3: tmp = hFile.replace("X.XX", l).replace(" _-E_-E", "")
            else: tmp = hFile.replace("X.XX", l).replace(" _-E_-E", "_-8_-7")
            count(tmp)
            h['Eff_' + l] = h['Eff'].Clone('Eff_' + l)
            h['L_' + l] = ROOT.TGraph()
            h['L_' + l].SetLineColor(Ls[L])
            h['Eff'].Draw()
            g = h['Eff'].GetPaintedGraph()
            for n in range(g.GetN()):
                logE, p = g.GetPointX(n), g.GetPointY(n)
                if p > 0:
                    absL = -L / ROOT.TMath.Log(p)
                else:
                    absL = 0
                h['L_' + l].SetPoint(n, logE, absL)
        ut.bookHist(h, 'L', ';logE; L [cm]', 100, -9., -6.)
        h['L'].SetMaximum(hFiles[hFile][0])
        h['L'].SetStats(0)
        h['L'].Draw()
        for L in Ls:
            if L > hFiles[hFile][1]: continue
            h['L_' + str(L)].Draw('same')
            h['L_' + str(0.1)].Fit(Lfun)
        myPrint(h['absorb' + material], 'absorbLength' + material)
def addAllHistograms():
 h={}
 ecut = '10.0'
 Nmax=45000
 path = os.environ['EOSSHIP']+"/eos/experiment/ship/data/Mbias/background-prod-2018/"
 ut.bookCanvas(h,key='canvas',title='debug',nx=1600,ny=1200,cx=1,cy=1)
 h['canvas'].SetLogy(1)
 for i in range(0,Nmax,1000):
  fname = "pythia8_Geant4_"+ecut+"_c"+str(i)+".root"
  ut.readHists(h,path+fname)
  if i==0:
    h[1012].Draw()
 tmp = h.keys()
 for x in tmp:
   if h[x].GetName().find('proj')>0: rc = h.pop(x)
 ut.writeHists(h,"pythia8_Geant4_"+ecut+"_c"+str(Nmax)+"-histos.root")
示例#15
0
def printScalers():
   ut.bookHist(h,'rate','rate',100,-0.5,99.5)
   if not h.has_key('rates'): ut.bookCanvas(h,key='rates',title='Rates',nx=600,ny=400,cx=1,cy=1)
   rc = h['rates'].cd(1)
   scalers = f.scalers
   if not scalers:
     print "no scalers in this file"
     return
   scalers.GetEntry(0)
   for x in scalers.GetListOfBranches():
    name = x.GetName()
    s = eval('scalers.'+name)
    if name!='slices': print "%20s :%8i"%(name,s)
    else:
      for n in range(s.size()):
        rc=h['rate'].Fill(n,s[n])
示例#16
0
def someDrawings(F, channel):
    AF = ROOT.TVector3()
    BF = ROOT.TVector3()
    ut.bookCanvas(h, 'c1', ' ;x;y', 800, 800, 1, 1)
    s = int(channel / 1000000)
    o = int((channel - 1000000 * s) / 100000)
    locChannel = channel % 100000
    fibreVol = sGeo.FindVolumeFast('FiberVolume')
    R = fibreVol.GetShape().GetDX()
    sipmVol = sGeo.FindVolumeFast("ChannelVol")
    DY = sipmVol.GetShape().GetDY()
    DZ = sipmVol.GetShape().GetDZ()
    n = 0
    xmin = 999.
    xmax = -999.
    ymin = 999.
    ymax = -999.
    for fibre in F[locChannel]:
        globFibre = int(s * 1000000 + o * 100000 + fibre)
        scifi.GetPosition(globFibre, AF, BF)
        loc = scifi.GetLocalPos(globFibre, AF)
        h['ellipse' + str(n)] = ROOT.TEllipse(loc[0], loc[2], R, 0)
        n += 1
        if xmin > loc[0]: xmin = loc[0]
        if ymin > loc[2]: ymin = loc[2]
        if xmax < loc[0]: xmax = loc[0]
        if ymax < loc[2]: ymax = loc[2]
    print(xmin, xmax, ymin, ymax)
    D = ymax - ymin + 3 * R
    x0 = (xmax + xmin) / 2.
    ut.bookHist(h, 'x', '', 100, x0 - D / 2, x0 + D / 2, 100, ymin - 1.5 * R,
                ymax + 1.5 * R)
    h['x'].SetStats(0)
    h['x'].Draw()
    for i in range(n):
        print(fibre, globFibre, loc[0], loc[1], loc[2])
        el = h['ellipse' + str(i)]
        el.SetFillColor(6)
        el.Draw('same')
    scifi.GetSiPMPosition(channel, AF, BF)
    loc = scifi.GetLocalPos(globFibre, AF)
    h['rectang'] = ROOT.TBox(loc[0] - DY, loc[2] - DZ, loc[0] + DY,
                             loc[2] + DZ)
    h['rectang'].SetFillColor(4)
    h['rectang'].SetFillStyle(3001)
    h['rectang'].Draw('same')
def makeTrajPlot():
 gStyle.SetCanvasPreferGL(kTRUE)
 u.bookCanvas(h,key='trajectories',title='trajectories of surviving muons',nx=1600,ny=800,cx=2,cy=1)
 gROOT.cd()
 if not h.has_key('world'): 
   h['world']   = TH3F('world','world',100,-5.,5.,100,-5.,5.,100,-50.,51.)
   h['world2d'] = TH2F('world2d','world2d',100,-5.,5.,100,-50.,51.)
 h['world'].GetXaxis().SetTitle('x-axis')
 h['world'].GetYaxis().SetTitle('y-axis')
 h['world'].GetZaxis().SetTitle('beam')
 h['world'].SetStats(0)
 h['trajectories'].cd(1)
 h['world'].Draw('gl')
 h['trajectories'].cd(2)
 h['world2d'].Draw()
 h['world_leg'] = TLegend(0.38,0.62,0.62,0.89)
 for E in range(25,425,50):
  makeEntryLists(E-25,E+25,3)
 h['trajectories'].cd(2)
 h['world_leg'].Draw()
示例#18
0
def plotRPCHitmap():
 ut.bookHist(h,'rpcHitmap','rpc Hitmaps',60,-0.5,59.5)
 for n in range(1,6):
  for l in range(2):
    ut.bookHist(h,'rpcHitmap'+str(n)+str(l),'rpc Hitmaps station '+str(n)+'layer '+str(l),200,-0.5,199.5)
 for event in sTree:
    for m in event.Digi_MuonTaggerHits:
      layer = m.GetDetectorID()/1000
      rc = h['rpcHitmap'].Fill(layer)
      channel = m.GetDetectorID()%1000
      rc = h['rpcHitmap'+str(layer)].Fill(channel)
 if not h.has_key('rpcPlot'): ut.bookCanvas(h,key='rpcPlot',title='RPC Hitmaps',nx=1200,ny=600,cx=4,cy=3)
 j=0
 for n in range(1,6):
  for l in range(2):
    j+=1
    rc = h['rpcPlot'].cd(j)
    h['rpcHitmap'+str(n)+str(l)].Draw()
 j+=1
 rc = h['rpcPlot'].cd(j)
 h['rpcHitmap'].Draw()
示例#19
0
def makePlots():
   ut.bookCanvas(h,key='Mass_Comparison',title='Fit Results',nx=1000,ny=1000,cx=2,cy=2)
   cv = h['Mass_Comparison'].cd(1)
   h['HNL_true'].SetXTitle('Invariant Mass [GeV/c2]')
   h['HNL_true'].SetYTitle('No. of Particles')
   h['HNL_true'].Draw()
   #fitSingleGauss('HNL_true',0.9,1.1)
   cv = h['Mass_Comparison'].cd(2)
   h['HNL_reco'].SetXTitle('Invariant Mass [GeV/c2]')
   h['HNL_reco'].SetYTitle('No. of Particles')
   h['HNL_reco'].Draw()
   fitSingleGauss('HNL_reco',0.9,1.1)
   #--------------------------------------------------------------------------------------------------------------
   cv = h['Mass_Comparison'].cd(3)
   h['HNL'].SetXTitle('Invariant Mass [GeV/c2]')
   h['HNL'].SetYTitle('No. of Particles')
   h['HNL'].Draw()
   fitSingleGauss('HNL',0.9,1.1)
   #--------------------------------------------------------------------------------------------------------------
   h['Mass_Comparison'].Print('Mass_Comparison.png')
   print('finished making plots')
示例#20
0
def makePlots():
   ut.bookCanvas(h,key='ecalanalysis',title='cluster map',nx=800,ny=600,cx=1,cy=1)
   cv = h['ecalanalysis'].cd(1)
   h['ecalClusters'].Draw('colz')
   ut.bookCanvas(h,key='strawanalysis',title='Distance to wire and mean nr of hits',nx=1200,ny=600,cx=3,cy=1)
   cv = h['strawanalysis'].cd(1)
   h['disty'].Draw()
   h['distu'].Draw('same')
   h['distv'].Draw('same')
   cv = h['strawanalysis'].cd(2)
   h['meanhits'].Draw()
   cv = h['strawanalysis'].cd(3)
   h['meas2'].Draw()
   ut.bookCanvas(h,key='fitresults',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   cv = h['fitresults'].cd(1)
   h['delPOverPz'].Draw('box')
   cv = h['fitresults'].cd(2)
   cv.SetLogy(1)
   h['prob'].Draw()
   cv = h['fitresults'].cd(3)
   h['delPOverPz_proj'] = h['delPOverPz'].ProjectionY()
   ROOT.gStyle.SetOptFit(11111)
   h['delPOverPz_proj'].Draw()
   h['delPOverPz_proj'].Fit('gaus')
   cv = h['fitresults'].cd(4)
   h['delPOverP2z_proj'] = h['delPOverP2z'].ProjectionY()
   h['delPOverP2z_proj'].Draw()
   fitSingleGauss('delPOverP2z_proj')
   h['fitresults'].Print('fitresults.gif')
   ut.bookCanvas(h,key='fitresults2',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   print 'finished with first canvas'
   cv = h['fitresults2'].cd(1)
   h['Doca'].SetXTitle('closest distance between 2 tracks   [cm]')
   h['Doca'].SetYTitle('N/1mm')
   h['Doca'].Draw()
   cv = h['fitresults2'].cd(2)
   h['IP0'].SetXTitle('impact parameter to p-target   [cm]')
   h['IP0'].SetYTitle('N/1cm')
   h['IP0'].Draw()
   cv = h['fitresults2'].cd(3)
   h['HNL'].SetXTitle('inv. mass  [GeV/c2]')
   h['HNL'].SetYTitle('N/4MeV/c2')
   h['HNL'].Draw()
   fitSingleGauss('HNL',0.9,1.1)
   cv = h['fitresults2'].cd(4)
   h['IP0/mass'].SetXTitle('inv. mass  [GeV/c2]')
   h['IP0/mass'].SetYTitle('IP [cm]')
   h['IP0/mass'].Draw('colz')
   h['fitresults2'].Print('fitresults2.gif')
   print 'finished making plots'
示例#21
0
def makePlots():
   ut.bookCanvas(h,key='fitresults2',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   print 'finished with first canvas'
   cv = h['fitresults2'].cd(1)
   h['Doca'].Draw()
   cv = h['fitresults2'].cd(2)
   h['IP0'].Draw()
   cv = h['fitresults2'].cd(3)
   h['HNL'].Draw()
   fitSingleGauss('HNL',0.9,1.1)
   cv = h['fitresults2'].cd(4)
   h['IP0/mass'].Draw('box')
   h['fitresults2'].Print('fitresults2.gif')
   ut.bookCanvas(h,key='otherResults',title='other results',nx=1600,ny=1200,cx=2,cy=2)
   cv = h['otherResults'].cd(1)
   h['Ntracks'].SetXTitle('number of tracks / event')
   h['Ntracks'].Draw()
   cv = h['otherResults'].cd(2)
   h['P'].SetXTitle('momentum of tracks  [GeV/c]')
   h['P'].Draw()
   cv = h['otherResults'].cd(3)
   h['recoVXrhoz'].Draw()
   cv = h['otherResults'].cd(4)
   h['HNLOtherTracks'].Draw()
   ut.bookCanvas(h,key='Vx',title='vertex position',nx=800,ny=600,cx=1,cy=1)
   cv = h['Vx'].cd(1)
   h['VxZ'].Draw('colz')
示例#22
0
def plotFromJpsi():
    inputFiles()
    muonSpect()
    for p in ["P", "Pt"]:
        ut.bookCanvas(h, key=p, title=" ", nx=1000, ny=600)
        h["lg" + p] = ROOT.TLegend(0.4, 0.7, 0.85, 0.85)
        h["fCERN" + p].SetLineColor(ROOT.kRed)
        mx = h["fCERN" + p].SetMaximum(
            max(h["fCERN" + p].GetMaximum(), h["fYAND" + p].GetMaximum(), h["fJPSI" + p].GetMaximum())
        )
        h["fCERN" + p].Draw()
        h["fYAND" + p].SetLineColor(ROOT.kBlue)
        h["fYAND" + p].Draw("same")
        h["fJPSI" + p].SetLineColor(ROOT.kGreen)
        h["fJPSI" + p].Draw("same")
        h["fMO" + p].SetLineColor(ROOT.kMagenta)
        h["fMO" + p].Draw("same")
        h["lg" + p].AddEntry(h["fCERN" + p], "CERN/Cracow production", "PL")
        h["lg" + p].AddEntry(h["fYAND" + p], "Yandex production", "PL")
        h["lg" + p].AddEntry(h["fJPSI" + p], "Jpsi-only production", "PL")
        h["lg" + p].AddEntry(h["fMO" + p], "molybdenum", "PL")
        h["lg" + p].Draw()
示例#23
0
def makePlots():
    ut.bookCanvas(h, key="fitresults", title="Fit Results", nx=1600, ny=1200, cx=2, cy=2)
    cv = h["fitresults"].cd(1)
    h["delPOverP"].Draw("box")
    cv = h["fitresults"].cd(2)
    cv.SetLogy(1)
    h["chi2"].Draw()
    cv = h["fitresults"].cd(3)
    h["delPOverP_proj"] = h["delPOverP"].ProjectionY()
    ROOT.gStyle.SetOptFit(11111)
    h["delPOverP_proj"].Draw()
    h["delPOverP_proj"].Fit("gaus")
    cv = h["fitresults"].cd(4)
    h["delPOverP2_proj"] = h["delPOverP2"].ProjectionY()
    h["delPOverP2_proj"].Draw()
    h["delPOverP2_proj"].Fit("gaus")
    h["fitresults"].Print("fitresults.gif")
    ut.bookCanvas(h, key="fitresults2", title="Fit Results", nx=1600, ny=1200, cx=2, cy=2)
    cv = h["fitresults2"].cd(1)
    h["IP"].Draw()
    cv = h["fitresults2"].cd(2)
    h["HNL"].Draw()
    h["HNL"].Fit("gaus")
    h["fitresults2"].Print("fitresults2.gif")
示例#24
0
def eventTime():
    Tprev = -1
    freq = 160.E6
    ut.bookHist(h, 'Etime', 'delta event time; dt [s]', 100, 0.0, 1.)
    ut.bookCanvas(h, 'E', ' ', 1024, 2 * 768, 1, 2)
    eventTree.GetEvent(0)
    t0 = eventTree.EventHeader.GetEventTime() / 160.E6
    eventTree.GetEvent(eventTree.GetEntries() - 1)
    tmax = eventTree.EventHeader.GetEventTime() / 160.E6
    ut.bookHist(h, 'time', 'elapsed time; t [s]', 1000, t0, tmax)
    for event in eventTree:
        T = event.EventHeader.GetEventTime()
        dT = 0
        if Tprev > 0: dT = T - Tprev
        Tprev = T
        rc = h['Etime'].Fill(dT / freq)
        rc = h['time'].Fill((T / freq - t0))
    tc = h['E'].cd(1)
    rc = h['Etime'].Fit('expo')
    tc.Update()
    stats = h['Etime'].FindObject("stats")
    stats.SetOptFit(111)
    tc = h['E'].cd(2)
    h['time'].Draw()
示例#25
0
def hitMaps(Nev=-1):
    for mat in range(30):
        ut.bookHist(h, 'mat_' + str(mat), 'hit map / mat', 512, -0.5, 511.5)
        ut.bookHist(h, 'sig_' + str(mat), 'signal / mat', 150, 0.0, 150.)
    N = -1
    if Nev < 0: Nev = eventTree.GetEntries()
    for event in eventTree:
        N += 1
        if N > Nev: break
        for aHit in event.Digi_ScifiHits:
            if not aHit.isValid(): continue
            X = xPos(aHit.GetDetectorID())
            rc = h['mat_' + str(X[0] * 3 + X[1])].Fill(X[2])
            rc = h['sig_' + str(X[0] * 3 + X[1])].Fill(aHit.GetSignal(0))
    ut.bookCanvas(h, 'hitmaps', ' ', 1024, 768, 6, 5)
    ut.bookCanvas(h, 'signal', ' ', 1024, 768, 6, 5)
    for mat in range(30):
        tc = h['hitmaps'].cd(mat + 1)
        A = h['mat_' + str(mat)].GetSumOfWeights() / 512.
        if h['mat_' + str(mat)].GetMaximum() > 10 * A:
            h['mat_' + str(mat)].SetMaximum(10 * A)
        h['mat_' + str(mat)].Draw()
        tc = h['signal'].cd(mat + 1)
        h['sig_' + str(mat)].Draw()
示例#26
0
def makePlots():
    ut.bookCanvas(h,
                  key='strawanalysis',
                  title='Distance to wire and mean nr of hits',
                  nx=1200,
                  ny=600,
                  cx=2,
                  cy=1)
    cv = h['strawanalysis'].cd(1)
    h['disty'].Draw()
    h['distu'].Draw('same')
    h['distv'].Draw('same')
    cv = h['strawanalysis'].cd(2)
    h['meanhits'].Draw()
    ut.bookCanvas(h,
                  key='fitresults',
                  title='Fit Results',
                  nx=1600,
                  ny=1200,
                  cx=2,
                  cy=2)
    cv = h['fitresults'].cd(1)
    h['delPOverPz'].Draw('box')
    cv = h['fitresults'].cd(2)
    cv.SetLogy(1)
    h['chi2'].Draw()
    cv = h['fitresults'].cd(3)
    h['delPOverPz_proj'] = h['delPOverPz'].ProjectionY()
    ROOT.gStyle.SetOptFit(11111)
    h['delPOverPz_proj'].Draw()
    h['delPOverPz_proj'].Fit('gaus')
    cv = h['fitresults'].cd(4)
    h['delPOverP2z_proj'] = h['delPOverP2z'].ProjectionY()
    h['delPOverP2z_proj'].Draw()
    fitSingleGauss('delPOverP2z_proj')
    h['fitresults'].Print('fitresults.gif')
    ut.bookCanvas(h,
                  key='fitresults2',
                  title='Fit Results',
                  nx=1600,
                  ny=1200,
                  cx=2,
                  cy=2)
    print 'finished with first canvas'
    cv = h['fitresults2'].cd(1)
    h['Doca'].Draw()
    cv = h['fitresults2'].cd(2)
    h['IP0'].Draw()
    cv = h['fitresults2'].cd(3)
    h['HNL'].Draw()
    fitSingleGauss('HNL')
    cv = h['fitresults2'].cd(4)
    h['IP0/mass'].Draw('box')
    h['fitresults2'].Print('fitresults2.gif')
    print 'finished making plots'
示例#27
0
def mergeHistosMakePlots(p):
 if not type(p)==type([]): pl=[p]
 else: pl = p
 hlist = ''
 for p in pl:
   prefix = str(p) 
   for x in os.listdir('.'):
    if not x.find(prefix)<0: 
       if os.path.isdir(x) : 
         hlist += x+'/ShipAna.root '
 print "-->",hlist
 os.system('hadd -f ShipAna.root '+hlist)
 ut.readHists(h,"ShipAna.root")
 print h['meanhits'].GetEntries()
 if 1>0: 
   ut.bookCanvas(h,key='strawanalysis',title='Distance to wire and mean nr of hits',nx=1200,ny=600,cx=2,cy=1)
#
   cv = h['strawanalysis'].cd(1)
   h['disty'].DrawCopy()
   h['distu'].DrawCopy('same')
   h['distv'].DrawCopy('same')
   cv = h['strawanalysis'].cd(2)
   h['meanhits'].DrawCopy()
   print h['meanhits'].GetEntries()

   ut.bookCanvas(h,key='fitresults',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   cv = h['fitresults'].cd(1)
   h['delPOverP'].Draw('box')
   cv = h['fitresults'].cd(2)
   cv.SetLogy(1)
   h['chi2'].Draw()
   cv = h['fitresults'].cd(3)
   h['delPOverP_proj'] = h['delPOverP'].ProjectionY()
   ROOT.gStyle.SetOptFit(11111)
   h['delPOverP_proj'].Draw()
   h['delPOverP_proj'].Fit('gaus')
   cv = h['fitresults'].cd(4)
   h['delPOverP2_proj'] = h['delPOverP2'].ProjectionY()
   h['delPOverP2_proj'].Draw()
   fitSingleGauss('delPOverP2_proj')
   h['fitresults'].Print('fitresults.gif')
   ut.bookCanvas(h,key='fitresults2',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   print 'finished with first canvas'
   cv = h['fitresults2'].cd(1)
   h['Doca'].Draw()
   cv = h['fitresults2'].cd(2)
   h['IP0'].Draw()
   cv = h['fitresults2'].cd(3)
   h['HNL'].Draw()
   fitSingleGauss('HNL',0.,2.)
   cv = h['fitresults2'].cd(4)
   h['IP0/mass'].Draw('box')
   h['fitresults2'].Print('fitresults2.gif')
   h['strawanalysis'].Print('strawanalysis.gif')
   print 'finished making plots'
示例#28
0
def makePlots():
    ut.bookCanvas(h, key="strawanalysis", title="Distance to wire and mean nr of hits", nx=1200, ny=600, cx=2, cy=1)
    cv = h["strawanalysis"].cd(1)
    h["disty"].Draw()
    h["distu"].Draw("same")
    h["distv"].Draw("same")
    cv = h["strawanalysis"].cd(2)
    h["meanhits"].Draw()
    ut.bookCanvas(h, key="fitresults", title="Fit Results", nx=1600, ny=1200, cx=2, cy=2)
    cv = h["fitresults"].cd(1)
    h["delPOverP"].Draw("box")
    cv = h["fitresults"].cd(2)
    cv.SetLogy(1)
    h["chi2"].Draw()
    cv = h["fitresults"].cd(3)
    h["delPOverP_proj"] = h["delPOverP"].ProjectionY()
    ROOT.gStyle.SetOptFit(11111)
    h["delPOverP_proj"].Draw()
    h["delPOverP_proj"].Fit("gaus")
    cv = h["fitresults"].cd(4)
    h["delPOverP2_proj"] = h["delPOverP2"].ProjectionY()
    h["delPOverP2_proj"].Draw()
    fitSingleGauss("delPOverP2_proj")
    h["fitresults"].Print("fitresults.gif")
    ut.bookCanvas(h, key="fitresults2", title="Fit Results", nx=1600, ny=1200, cx=2, cy=2)
    print "finished with first canvas"
    cv = h["fitresults2"].cd(1)
    h["Doca"].Draw()
    cv = h["fitresults2"].cd(2)
    h["IP0"].Draw()
    cv = h["fitresults2"].cd(3)
    h["HNL"].Draw()
    fitSingleGauss("HNL")
    cv = h["fitresults2"].cd(4)
    h["IP0/mass"].Draw("box")
    h["fitresults2"].Print("fitresults2.gif")
    print "finished making plots"
示例#29
0
def makePlots():
   ut.bookCanvas(h,key='strawanalysis',title='Distance to wire and mean nr of hits',nx=1200,ny=600,cx=2,cy=1)
   cv = h['strawanalysis'].cd(1)
   h['disty'].Draw()
   h['distu'].Draw('same')
   h['distv'].Draw('same')
   cv = h['strawanalysis'].cd(2)
   h['meanhits'].Draw()
   ut.bookCanvas(h,key='fitresults',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   cv = h['fitresults'].cd(1)
   h['delPOverP'].Draw('box')
   cv = h['fitresults'].cd(2)
   cv.SetLogy(1)
   h['chi2'].Draw()
   cv = h['fitresults'].cd(3)
   h['delPOverP_proj'] = h['delPOverP'].ProjectionY()
   ROOT.gStyle.SetOptFit(11111)
   h['delPOverP_proj'].Draw()
   h['delPOverP_proj'].Fit('gaus')
   cv = h['fitresults'].cd(4)
   h['delPOverP2_proj'] = h['delPOverP2'].ProjectionY()
   h['delPOverP2_proj'].Draw()
   fitSingleGauss('delPOverP2_proj')
   h['fitresults'].Print('fitresults.gif')
   ut.bookCanvas(h,key='fitresults2',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   print 'finished with first canvas'
   cv = h['fitresults2'].cd(1)
   h['Doca'].Draw()
   cv = h['fitresults2'].cd(2)
   h['IP0'].Draw()
   cv = h['fitresults2'].cd(3)
   h['HNL'].Draw()
   fitSingleGauss('HNL')
   cv = h['fitresults2'].cd(4)
   h['IP0/mass'].Draw('box')
   h['fitresults2'].Print('fitresults2.gif')
   print 'finished making plots'
 if not l.find('muMinusCaptureAtRest:')<0: 
   x  = (l.replace('\n','')).replace('{','')
   xx = (x.replace('}','')).replace("'",'')
   for k in xx.split(','):
       i = k.split(':')
       ProcDict[i[0]]=int(i[1]) 
       dictProc[int(i[1])]  = i[0]
#   
model = "QGSP_BERT_EMX"
withField    = False
shieldLength = 30.5  #    80m  50 + 30
zdet         = 40    # at 90m  50 + 40
Rdet = str(2.5/100.*90.)

h={}
u.bookCanvas(h,key='ResultsI',title='results',nx=1600,ny=1200,cx=4,cy=2)
if not withField:
 u.bookCanvas(h,key='ResultsII',title='results only muons reaching detector for shielding '+str(shieldLength+50-0.5),nx=1600,ny=1200,cx=4,cy=2)
else:
 u.bookCanvas(h,key='ResultsII',title='results only muons reaching detector',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsIII',title='results final momentum ',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsIV',title='results X Y',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsV',title='results X Y',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsVI',title='results tX tY',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsVII',title='results X Y z=60m for emulsion',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='Momsurv',title='mom spectrum of surviving muons',nx=800,ny=600,cx=1,cy=1)

u.bookHist(h,'mom','mom',400,0.,400.)

def extrap(zscor,pyl):
# extrapolate to detector
示例#31
0
f=ROOT.TFile('TLV.root')
pdg = ROOT.TDatabasePDG.Instance()
h={}
sTree = f.cbmsim
ut.bookHist(h,'Ekin','Ekin of particles in sens plane',400000,0.,400)
ut.bookHist(h,'EkinLow','Ekin of particles in sens plane',1000,0.,0.001)
for n in range(sTree.GetEntries()):
 rc = sTree.GetEvent(n)
 for aHit in sTree.vetoPoint:
   oTrack = sTree.MCTrack[aHit.GetTrackID()]
   M = pdg.GetParticle(oTrack.GetPdgCode()).Mass()
   Ekin = ROOT.TMath.Sqrt( aHit.GetPx()**2+aHit.GetPy()**2+aHit.GetPz()**2 + M**2) - M
   rc = h['Ekin'].Fill(Ekin)
   rc = h['EkinLow'].Fill(Ekin)
ut.bookCanvas(h,key=s,title=s,nx=900,ny=600,cx=1,cy=1)
tc = h[s].cd(1)
tc.SetLogy(1)
h['Ekin'].Draw()

# tungsten dedex mev cm**2/g 1.145 * rho g/cm-3 19.3 * 0.1
#          interactionLength 191.9 / 19.3 = 9.94cm, 0.1/9.94 = 1%

# -----Finish-------------------------------------------------------
timer.Stop()
rtime = timer.RealTime()
ctime = timer.CpuTime()
print ' ' 
print "Macro finished succesfully." 
print "Output file is ",  outFile 
print "Real time ",rtime, " s, CPU time ",ctime,"s"
示例#32
0
f = ROOT.TFile('TLV.root')
pdg = ROOT.TDatabasePDG.Instance()
h = {}
sTree = f.cbmsim
ut.bookHist(h, 'Ekin', 'Ekin of particles in sens plane', 400000, 0., 400)
ut.bookHist(h, 'EkinLow', 'Ekin of particles in sens plane', 1000, 0., 0.001)
for n in range(sTree.GetEntries()):
    rc = sTree.GetEvent(n)
    for aHit in sTree.vetoPoint:
        oTrack = sTree.MCTrack[aHit.GetTrackID()]
        M = pdg.GetParticle(oTrack.GetPdgCode()).Mass()
        Ekin = ROOT.TMath.Sqrt(aHit.GetPx()**2 + aHit.GetPy()**2 +
                               aHit.GetPz()**2 + M**2) - M
        rc = h['Ekin'].Fill(Ekin)
        rc = h['EkinLow'].Fill(Ekin)
ut.bookCanvas(h, key=s, title=s, nx=900, ny=600, cx=1, cy=1)
tc = h[s].cd(1)
tc.SetLogy(1)
h['Ekin'].Draw()

# tungsten dedex mev cm**2/g 1.145 * rho g/cm-3 19.3 * 0.1
#          interactionLength 191.9 / 19.3 = 9.94cm, 0.1/9.94 = 1%

# -----Finish-------------------------------------------------------
timer.Stop()
rtime = timer.RealTime()
ctime = timer.CpuTime()
print ' '
print "Macro finished succesfully."
print "Output file is ", outFile
print "Real time ", rtime, " s, CPU time ", ctime, "s"
# create volDict from log file:
dictVol = {-1:'detPlane'}
log = file('log_g4opt','r')
for l in log.readlines():
 if not l.find('volume dictionary:')<0: 
   x = (l.replace('\n','')).split(' ')
   dictVol[int(x[4])]=x[3]   
 if not l.find('muMinusCaptureAtRest:')<0: 
   x  = (l.replace('\n','')).replace('{','')
   xx = (x.replace('}','')).replace("'",'')
   for k in xx.split(','):
       i = k.split(':')
       ProcDict[i[0]]=int(i[1]) 
       dictProc[int(i[1])]  = i[0]

u.bookCanvas(h,key='materialMap',title='Material Map',nx=1200,ny=800,cx=1,cy=1)
u.bookCanvas(h,key='ResultsI',title='results',nx=1600,ny=1200,cx=4,cy=2)
if not withField:
 u.bookCanvas(h,key='ResultsII',title='results only muons reaching detector',nx=1600,ny=1200,cx=4,cy=2)
else:
 u.bookCanvas(h,key='ResultsII',title='results only muons reaching detector',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsIII',title='results final momentum ',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsIV', title='results X Y',                    nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsIVC',title='results X Y with Energy cutoff',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsV',  title='results X Y',                    nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsVC', title='results X Y with Energy cutoff',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsVI',title='results tX tY',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='ResultsVII',title='results X Y z=0m for emulsion',nx=1600,ny=1200,cx=4,cy=2)
u.bookCanvas(h,key='Momsurv',title='mom spectrum of surviving muons',nx=800,ny=600,cx=1,cy=1)
u.bookCanvas(h,key='trajectories',title='trajectories of surviving muons',nx=1600,ny=800,cx=2,cy=1)
u.bookCanvas(h,key='test',title='general purpose',nx=800,ny=600,cx=1,cy=1)
示例#34
0
def v0Spec():
# start event loop
 nTot = sTree.GetEntries()
 for n in range(500000): 
  rc = sTree.GetEntry(n)
  key = -1
  for apart in sTree.MCTrack:
    key+=1
    apid =  abs(apart.GetPdgCode())
    if apid in hdict:
       w = sTree.MCTrack[1].GetWeight()  # 0 = original muon, 1 = geant4 followed muon
       h[str(apid)].Fill(apart.GetP(),w)
    mo = apart.GetMotherId()
    if mo < 0 : continue
    mopart = sTree.MCTrack[mo] 
    mpid =  abs(mopart.GetPdgCode())
    if mpid in hdict:
       w = sTree.MCTrack[1].GetWeight()
       z,x,y = (apart.GetStartZ()-z_zero)/u.m,apart.GetStartX()/u.m,apart.GetStartY()/u.m
       h[str(mpid)+'xyz'].Fill(z,x,y,w)
       h[str(mpid)+'rhoz'].Fill(z,ROOT.TMath.Sqrt(x**2+y**2),w)
       z0,x0,y0 = (mopart.GetStartZ()-z_zero)/u.m,mopart.GetStartX()/u.m,mopart.GetStartY()/u.m
       h[str(mpid)+'xyzmu'].Fill(z0,x0,y0,w)
       h[str(mpid)+'rhozmu'].Fill(z0,ROOT.TMath.Sqrt(x0**2+y0**2),w)
       L=ROOT.TMath.Sqrt( (x-x0)**2+(y-y0)**2+(z-z0)**2)
       h[str(mpid)+'L'].Fill(L,w)
       if findDaughters(mo): h[str(mpid)+'Ldecay'].Fill(L,w)
       break
 ut.bookCanvas(h,key='results',title='V0',nx=1200,ny=600,cx=3,cy=1)
 ut.bookCanvas(h,key='resultsXYZ',title='V0 XYZ',nx=1200,ny=600,cx=3,cy=1)
 ut.bookCanvas(h,key='resultsrhoZ',title='V0 rhoZ',nx=1200,ny=600,cx=3,cy=1)
 ut.bookCanvas(h,key='resultsrhoZmu',title='mu rhoZ',nx=1200,ny=600,cx=3,cy=1)
 ut.bookCanvas(h,key='resultsL',title='V0 L',nx=1200,ny=600,cx=3,cy=1)
 ut.bookCanvas(h,key='resultsLd',title='V0 Ldecay',nx=1200,ny=600,cx=3,cy=1)
 ROOT.gStyle.SetOptStat(1111111)
 i = 1
 for x in hdict: 
  h['results'].cd(i) 
  h[str(x)].Draw()
  h['resultsXYZ'].cd(i) 
  h[str(x)+'xyz'].Draw()
  h['resultsrhoZ'].cd(i) 
  h[str(x)+'rhoz'].Draw()
  h['resultsrhoZmu'].cd(i) 
  h[str(x)+'rhozmu'].Draw()
  h['resultsL'].cd(i) 
  h[str(x)+'L'].Draw()
  h['resultsLd'].cd(i) 
  h[str(x)+'Ldecay'].Draw()
  i+=1
 h['results'].Print('V0Spectrum_MuDIS.gif')
 h['resultsXYZ'].Print('V0XYZ_MuDIS.gif')
 h['resultsrhoZ'].Print('V0RHOZ_MuDIS.pdf')
 h['resultsL'].Print('V0L_MuDIS.pdf')
 h['resultsLd'].Print('V0Ldecay_MuDIS.pdf')
示例#35
0
       if trackID > 0: 
         origin(trackID)
         rc = h['porigin'].Fill(aTrack.GetStartZ()/u.m,ROOT.TMath.Sqrt(aTrack.GetStartX()**2+aTrack.GetStartY()**2)/u.m,w)
       rc = h['mu-inter'].Fill(rz_inter[1]/u.m,rz_inter[0]/u.m,w) 
  for hit in sTree.EcalPoint:
    rc = h['Ecal'].Fill(hit.GetX()/u.m,hit.GetY()/u.m,w)
    rc = h['Ecal_E'].Fill(hit.GetEnergyLoss()/u.MeV,w)
  for hit in sTree.muonPoint:
    rc = h['muon'].Fill(hit.GetX()/u.m,hit.GetY()/u.m,w)
    rc = h['muon_E'].Fill(hit.GetEnergyLoss()/u.MeV,w)
  for detID in hitmult:
    rc = h[vetoDet[detID]+'_evmul'].Fill(hitmult[detID][-1],w) 
    for tr in hitmult[detID]:
      rc = h[vetoDet[detID]+'_mul'].Fill(hitmult[detID][tr],w) 

ut.bookCanvas(h,key='ResultsI',title='hit occupancies',nx=1600,ny=1200,cx=3,cy=2)
ut.bookCanvas(h,key='ResultsImu',title='hit occupancies',nx=1600,ny=1200,cx=3,cy=2)
if 'Sveto_0' in h : 
 histlist = {1:'Sveto_0',2:'STr1_1',3:'STr4_1',4:'Ecal',5:'muon'}
 nstations = 3+1
else:               
 histlist = {1:'STr1_1',2:'STr4_1',3:'Ecal',4:'muon'}
 nstations = 2+1
txt = {}
txt[0] ='occupancy 1sec 5E13pot '
txt[10] ='occupancy 1sec 5E13pot '

for i in histlist:
 tc = h['ResultsI'].cd(i)
 h[histlist[i]].SetStats(0)
 h[histlist[i]].Draw('colz')
示例#36
0
def makePlots(nstations):
    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]
    }
    ut.bookCanvas(h,
                  key='ResultsI',
                  title='hit occupancies',
                  nx=1100,
                  ny=600 * cxcy[nstations][1],
                  cx=cxcy[nstations][0],
                  cy=cxcy[nstations][1])
    ut.bookCanvas(h,
                  key='ResultsImu',
                  title='hit occupancies',
                  nx=1100,
                  ny=600 * cxcy[nstations][1],
                  cx=cxcy[nstations][0],
                  cy=cxcy[nstations][1])
    ut.bookCanvas(h,
                  key='ResultsImuV0',
                  title='hit occupancies',
                  nx=1100,
                  ny=600 * cxcy[nstations][1],
                  cx=cxcy[nstations][0],
                  cy=cxcy[nstations][1])
    ut.bookCanvas(h,
                  key='ResultsII',
                  title='deposited energies',
                  nx=1100,
                  ny=600 * cxcy[nstations][1],
                  cx=cxcy[nstations][0],
                  cy=cxcy[nstations][1])
    ut.bookCanvas(h,
                  key='ResultsIII',
                  title='track info',
                  nx=1100,
                  ny=600 * cxcy[nstations][1],
                  cx=cxcy[nstations][0],
                  cy=cxcy[nstations][1])
    ut.bookCanvas(h,
                  key='ResultsIV',
                  title='track info',
                  nx=1100,
                  ny=600 * cxcy[nstations][1],
                  cx=cxcy[nstations][0],
                  cy=cxcy[nstations][1])
    ut.bookCanvas(h,
                  key='ResultsV',
                  title='origin info',
                  nx=600,
                  ny=400,
                  cx=1,
                  cy=1)
    txt[0] = 'occupancy 1sec 5E13pot '
    h['dummy'].Fill(-1)
    nSpills = len(prefixes)
    for i in histlist:
        tc = h['ResultsI'].cd(i)
        hn = histlist[i]
        if not h.has_key(hn): continue
        h[hn].SetStats(0)
        h[hn].Draw('colz')
        txt[i] = '%5.2G' % (h[hn].GetSumOfWeights() / nSpills)
        l[i] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i])
        #
        hn = histlist[i] + '_mu'
        tc = h['ResultsImu'].cd(i)
        h[hn].SetStats(0)
        h[hn].Draw('colz')
        txt[i + 100] = '%5.2G' % (h[hn].GetSumOfWeights() / nSpills)
        l[i + 100] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i + 100])
        #
        hn = histlist[i] + '_muV0'
        tc = h['ResultsImuV0'].cd(i)
        h[hn].SetStats(0)
        h[hn].Draw('colz')
        txt[i + 200] = '%5.2G' % (h[hn].GetSumOfWeights() / nSpills)
        l[i + 200] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i + 200])
#
    for i in histlist:
        tc = h['ResultsII'].cd(i)
        h[histlist[i] + '_E'].Draw('colz')
#
    for i in histlist:
        tc = h['ResultsIII'].cd(i)
        tc.SetLogy(1)
        hn = histlist[i]
        drawBoth('_P', hn)
        hid = h[hn + '_id']
        print 'particle statistics for ' + histlist[i]
        for k in range(hid.GetNbinsX()):
            ncont = hid.GetBinContent(k + 1)
            pid = hid.GetBinCenter(k + 1)
            if ncont > 0:
                temp = int(abs(pid) + 0.5) * int(pid / abs(pid))
                nm = PDG.GetParticle(temp).GetName()
                print '%s :%5.2g' % (nm, ncont)
        hid = h[histlist[i] + '_mu_id']
        for k in range(hid.GetNbinsX()):
            ncont = hid.GetBinContent(k + 1)
            pid = hid.GetBinCenter(k + 1)
            if ncont > 0:
                temp = int(abs(pid) + 0.5) * int(pid / abs(pid))
                nm = PDG.GetParticle(temp).GetName()
                print '%s :%5.2g' % (nm, ncont)
#
        tc = h['ResultsV'].cd(1)
        h['origin'].SetStats(0)
        h['origin'].Draw('colz')
#
    for i in histlist:
        tc = h['ResultsIV'].cd(i)
        tc.SetLogy(1)
        hn = histlist[i]
        drawBoth('_OP', hn)
    persistency()
示例#37
0
def makeCalibrationHistos(X=options.runNumbers,readHists=True,t0_channel=4):
 for r in X.split(','):
    if readHists:
       F = ROOT.TFile.Open(options.path+"MuFilterEff_run"+str(r)+".root")
    options.runNumber = r
    for s in [1,2]:
      if s==1 and int(r)<100: continue       # no Veto in H8
      h['tdcCalib'+sdict[s]] = {}
      for l in range(systemAndPlanes[s]):
        for bar in range(systemAndBars[s]):
           for side in ['L','R']:
              key = sdict[s]+str(s*10+l)+'_'+str(bar)
              for i in range(systemAndChannels[s][1]+systemAndChannels[s][0]):
                  if i==t0_channel: continue
                  j = side+'_'+key+'-c'+str(i)
                  x = 'TDCcalib'+j
                  # get TDC calibration constants:
                  h['tdcCalib'+sdict[s]][j] =[0,0,0,0]
                  h[x] = F.GetKey(x).ReadObj()
                  if h[x].GetEntries()>10: 
                       rc =  h[x].Fit('gaus','SNQ')
                       rc =  h[x].Fit('gaus','SNQ')
                       if rc:
                          res = rc.Get()
                          h['tdcCalib'+sdict[s]][j] =[res.Parameter(1),res.ParError(1),res.Parameter(2),res.ParError(2)]
#
      for l in range(systemAndPlanes[s]):
        tag = sdict[s]+str(l)
        ut.bookCanvas(h,'sigmaTDC_'+tag,'TDC RMS '+tag,2000,600,systemAndBars[s],2)
        ut.bookCanvas(h,  'TDCcalib_'+tag,'TDC TDCi-T0 '+tag,2000,600,systemAndBars[s],2)
        k=1
        for bar in range(systemAndBars[s]):
           for side in ['L','R']:
              key = sdict[s]+str(10*s+l)+'_'+str(bar)
              for i in range(systemAndChannels[s][1]+systemAndChannels[s][0]):
                  j = side+'_'+key+'-c'+str(i)
                  for x in ['sigmaTDC_'+tag,'TDCcalib_'+tag]:
                     if x.find('calib')>0 and (i==t0_channel):  continue
                     tc=h[x].cd(k)
                     opt='same'
                     if i==0 and x.find('calib')<0: opt=""
                     if i==1 and x.find('calib')>0: opt=""
                     aHist = x.split('_')[0]+j
                     h[aHist] = F.GetKey(aHist).ReadObj()
                     h[aHist].SetLineColor(barColor[i])
                     h[aHist].GetXaxis().SetRangeUser(-5,5)
                     h[aHist].Draw(opt)
                     h[aHist].Draw(opt+'HIST')
              k+=1
        myPrint(h['sigmaTDC_'+tag],'TDC/TDCrms_'+tag)
        myPrint(h['TDCcalib_'+tag],'TDC/TDCcalib_'+tag)
#
        ut.bookHist(h,'TDCcalibMean_'+tag,';SiPM channel ; [ns]',160,0.,160.)
        ut.bookHist(h,'TDCcalibSigma_'+tag,';SiPM channel ; [ns]',160,0.,160.)
        h['gTDCcalibMean_'+tag]=ROOT.TGraphErrors()
        h['gTDCcalibSigma_'+tag]=ROOT.TGraphErrors()
#
      for x in h['tdcCalib'+sdict[s]]:
               tmp =  h['tdcCalib'+sdict[s]][x]
               side = 0
               z = x.split('_')
               if z[0]=='R': side = 1
               l = z[1][len(z[1])-1]
               bar = z[2][0]
               c = z[2].split('c')[1]
               xbin = int(bar)*16+side*8+int(c)
               tag = sdict[s]+str(l)
               rc = h['TDCcalibMean_'+tag].SetBinContent(xbin+1,tmp[0])
               rc = h['TDCcalibMean_'+tag].SetBinError(xbin+1,tmp[1])
               rc = h['TDCcalibSigma_'+tag].SetBinContent(xbin+1,tmp[2])
               rc = h['TDCcalibSigma_'+tag].SetBinError(xbin+1,tmp[3])
               #print("%s %5.2F+/-%5.2F  %5.2F+/-%5.2F"%(x,tmp[0],tmp[1],tmp[2],tmp[3]))
      ut.bookCanvas(h,'tTDCcalib_'+sdict[s],'TDC calib '+sdict[s],2400,1800,2,systemAndPlanes[s])
      for l in range(systemAndPlanes[s]):
           tag = sdict[s]+str(l)
           aHistS  = h['TDCcalibSigma_'+tag]
           aHistM = h['TDCcalibMean_'+tag]
           k=0
           for i in range(1,aHistS.GetNbinsX()):
               if aHistS.GetBinContent(i)>0:
                 h['gTDCcalibSigma_'+tag].SetPoint(k,i-1,aHistS.GetBinContent(i))
                 h['gTDCcalibSigma_'+tag].SetPointError(k,0.5,aHistS.GetBinError(i))
                 h['gTDCcalibMean_'+tag].SetPoint(k,i-1,aHistM.GetBinContent(i))
                 h['gTDCcalibMean_'+tag].SetPointError(k,0.5,aHistM.GetBinError(i))
                 k+=1
#
      planeColor = {0:ROOT.kBlue,1:ROOT.kRed,2:ROOT.kGreen,3:ROOT.kCyan,4:ROOT.kMagenta}
      for l in range(systemAndPlanes[s]):
                tag = sdict[s]+str(l)
                tc = h['tTDCcalib_'+sdict[s]].cd(2*l+1)
                aHistS = h['TDCcalibSigma_'+tag]
                aHistS.Reset()
                aHistS.SetMaximum(2.0)
                aHistS.Draw()
                h['gTDCcalibSigma_'+tag].SetLineColor(planeColor[l])
                h['gTDCcalibSigma_'+tag].Draw('same')
#
      for l in range(systemAndPlanes[s]):
                tag = sdict[s]+str(l)
                tc = h['tTDCcalib_'+sdict[s]].cd(2*l+2)
                aHistM = h['TDCcalibMean_'+tag]
                aHistM.Reset()
                aHistM.SetMaximum(2.0)
                aHistM.SetMinimum(-2.0)
                aHistM.Draw()
                h['gTDCcalibMean_'+tag].SetLineColor(planeColor[l])
                h['gTDCcalibMean_'+tag].Draw('same')
      myPrint(h['tTDCcalib_'+sdict[s]],'TDC/TDCcalibration_'+sdict[s])
示例#38
0
          st = theTrack.getFittedState(j)
          pos,mom = st.getPos(), st.getMom()
          print "%i %5.2F %5.2F %5.2F %5.2F %5.2F  %5.2F %i %i "%(j,pos[0],pos[1],pos[2],mom[0],mom[1],mom[2],st.getPDG(),st.getCharge())

     h['dispTrack'].SetLineColor(ROOT.kMagenta)
     h['dispTrack'].SetLineWidth(2)
     h['dispTrackY'].SetLineColor(ROOT.kCyan)
     h['dispTrackY'].SetLineWidth(2)
     h['simpleDisplay'].cd(1)
     h['dispTrack'].Draw('same')
     h['dispTrackY'].Draw('same')
     h[ 'simpleDisplay'].Update()
     next = raw_input("Next (Ret/Quit): ")         
     if next<>'':  break
   nMax-=1
 ut.bookCanvas(h,key='mom',title='trackfit',nx=1200,ny=600,cx=2,cy=2)
 rc = h['mom'].cd(1)
 h['p/pt'].SetStats(0)
 rc = h['p/pt'].Draw('colz')
 rc = h['mom'].cd(2)
 h['p/pt_x']=h['p/pt'].ProjectionX()
 h['p/pt_x'].Draw()
 h['mom'].Update()
 stats = h['p/pt_x'].FindObject('stats')
 stats.SetOptStat(11111111)
 rc = h['mom'].cd(3)
 h['chi2'].Draw()
 rc = h['mom'].cd(4)
 h['Nmeasurements'].Draw()
 h['mom'].Update()
 
示例#39
0
def mergeHistosMakePlots(p):
    if not type(p) == type([]): pl = [p]
    else: pl = p
    hlist = ''
    for p in pl:
        prefix = str(p)
        for x in os.listdir('.'):
            if not x.find(prefix) < 0:
                if os.path.isdir(x):
                    hlist += x + '/ShipAna.root '
    print "-->", hlist
    os.system('hadd -f ShipAna.root ' + hlist)
    ut.readHists(h, "ShipAna.root")
    print h['meanhits'].GetEntries()
    if 1 > 0:
        ut.bookCanvas(h,
                      key='strawanalysis',
                      title='Distance to wire and mean nr of hits',
                      nx=1200,
                      ny=600,
                      cx=2,
                      cy=1)
        #
        cv = h['strawanalysis'].cd(1)
        h['disty'].DrawCopy()
        h['distu'].DrawCopy('same')
        h['distv'].DrawCopy('same')
        cv = h['strawanalysis'].cd(2)
        h['meanhits'].DrawCopy()
        print h['meanhits'].GetEntries()

        ut.bookCanvas(h,
                      key='fitresults',
                      title='Fit Results',
                      nx=1600,
                      ny=1200,
                      cx=2,
                      cy=2)
        cv = h['fitresults'].cd(1)
        h['delPOverP'].Draw('box')
        cv = h['fitresults'].cd(2)
        cv.SetLogy(1)
        h['chi2'].Draw()
        cv = h['fitresults'].cd(3)
        h['delPOverP_proj'] = h['delPOverP'].ProjectionY()
        ROOT.gStyle.SetOptFit(11111)
        h['delPOverP_proj'].Draw()
        h['delPOverP_proj'].Fit('gaus')
        cv = h['fitresults'].cd(4)
        h['delPOverP2_proj'] = h['delPOverP2'].ProjectionY()
        h['delPOverP2_proj'].Draw()
        fitSingleGauss('delPOverP2_proj')
        h['fitresults'].Print('fitresults.gif')
        ut.bookCanvas(h,
                      key='fitresults2',
                      title='Fit Results',
                      nx=1600,
                      ny=1200,
                      cx=2,
                      cy=2)
        print 'finished with first canvas'
        cv = h['fitresults2'].cd(1)
        h['Doca'].Draw()
        cv = h['fitresults2'].cd(2)
        h['IP0'].Draw()
        cv = h['fitresults2'].cd(3)
        h['HNL'].Draw()
        fitSingleGauss('HNL', 0., 2.)
        cv = h['fitresults2'].cd(4)
        h['IP0/mass'].Draw('box')
        h['fitresults2'].Print('fitresults2.gif')
        h['strawanalysis'].Print('strawanalysis.gif')
        print 'finished making plots'
示例#40
0
def coldBox(plotOnly=True, pas=''):

    if 1 > 0:
        tmp = options.inputFile.split('/')
        gFile = "geofile-" + (tmp[len(tmp) - 1].split('_coldbox')[0] +
                              '_coldbox.root').replace('histos-', '')
        g = ROOT.TFile(gFile)
        sGeo = g.FAIRGeom
        ROOT.gROOT.cd()
        vbox = sGeo.FindVolumeFast('vbox')
        sbox = sGeo.FindVolumeFast('sensBox')
        dX, dY, dZ = vbox.GetShape().GetDX(), vbox.GetShape().GetDY(
        ), vbox.GetShape().GetDZ()
        nav = sGeo.GetCurrentNavigator()
        boundaries = {}
        # find y boundaries
        start = array('d', [0, 200, 0])
        direction = array('d', [0, -1, 0])
        startnode = sGeo.InitTrack(start, direction)
        length = c_double(200.)
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['topIn'] = nav.GetCurrentPoint()[1]
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['topSens'] = nav.GetCurrentPoint()[1]
        start = array('d', [0, -200, 0])
        direction = array('d', [0, 1, 0])
        startnode = sGeo.InitTrack(start, direction)
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['botSens'] = nav.GetCurrentPoint()[1]
        # find x boundaries
        start = array('d', [-200, 0, 0])
        direction = array('d', [1, 0, 0])
        startnode = sGeo.InitTrack(start, direction)
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['leftIn'] = nav.GetCurrentPoint()[0]
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['leftSens'] = nav.GetCurrentPoint()[0]
        start = array('d', [200, 0, 0])
        direction = array('d', [-1, 0, 0])
        startnode = sGeo.InitTrack(start, direction)
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['rightIn'] = nav.GetCurrentPoint()[0]
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['rightSens'] = nav.GetCurrentPoint()[0]
        # find z boundaries
        start = array('d', [0, 0, -200])
        direction = array('d', [0, 0, 1])
        startnode = sGeo.InitTrack(start, direction)
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['backIn'] = nav.GetCurrentPoint()[2]
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['backSens'] = nav.GetCurrentPoint()[2]
        start = array('d', [0, 0, 200])
        direction = array('d', [0, 0, -1])
        startnode = sGeo.InitTrack(start, direction)
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['frontIn'] = nav.GetCurrentPoint()[2]
        node = sGeo.FindNextBoundaryAndStep(length, ROOT.kFALSE)
        boundaries['frontSens'] = nav.GetCurrentPoint()[2]
        Rin = {
            '': '',
            'topIn': 'Y',
            'leftIn': 'X',
            'rightIn': 'X',
            'frontIn': 'Z',
            'backIn': 'Z'
        }
        Rsens = {
            '': '',
            'topSens': 'Y',
            'botSens': 'Y',
            'leftSens': 'X',
            'rightSens': 'X',
            'frontSens': 'Z',
            'backSens': 'Z'
        }
        epsi = 0.1
#     side with holes is the front
#
    if not plotOnly:
        # example file "root://eospublic.cern.ch:1094//eos/experiment/sndlhc/MonteCarlo/ThermalNeutrons//thermNeutron_Borated30polyethylene_10.0_coldbox_0-20M.root"
        f = ROOT.TFile.Open(options.inputFile)
        ROOT.gROOT.cd()
        ut.bookHist(h, 'start', 'start neutron;x [cm] ;y [cm] ;z [cm]', 100,
                    -200, 200, 100, -200, 200, 100, -200, 200)
        ut.bookHist(h, 'startR', 'start neutron;R', 100, 0, 200)
        for o in ['_seco', '_prim']:
            for T in ['', 'cold', 'hot']:
                ut.bookHist(h, 'entry' + T + o,
                            'entry neutron;x [cm] ;y [cm] ;z [cm]', 100, -100,
                            100, 100, -100, 100, 100, -100, 100)
                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)
                ut.bookHist(h, 'exit' + T + o,
                            'enter coldbox neutron;x [cm] ;y [cm] ;z [cm]',
                            100, -100, 100, 100, -100, 100, 100, -100, 100)
            for r in Rin:
                ut.bookHist(h, 'EkinE' + r + o, 'log10(Ekin)', 100, -13., 0,
                            100, -200., 200.)
                ut.bookHist(h, 'Ekin' + r + o, 'log10(Ekin)', 100, -13., 0,
                            100, -200., 200.)
            for r in Rsens:
                ut.bookHist(h, 'DF' + r + o, 'travel  distance', 100, 0., 200.)
                ut.bookHist(h, 'EkinF' + r + o, 'log10(Ekin) vs distance', 100,
                            -13., 0, 100, -200., 200.)
                ut.bookHist(h, 'EkinF-original' + r + o,
                            'log10(Ekin) vs distance', 100, -13., 0, 100,
                            -200., 200.)
                ut.bookHist(h, 'checkBox' + r + o,
                            'enter coldbox neutron;x [cm] ;y [cm] ;z [cm]',
                            100, -100, 100, 100, -100, 100, 100, -100, 100)
        ut.bookHist(h, 'EkinG', 'log10(Ekin)', 100, -13., 0.)
        ut.bookHist(h, 'EkinW', 'log10(Ekin)', 100, -13., 0.)
        ut.bookHist(h, 'EkinWlin', 'Ekin', 100, 1E-9, 100 * 1E-9)
        ut.bookHist(h, 'multS', 'mult veto points shielding', 100, -0.5, 99.5)
        ut.bookHist(h, 'multC', 'mult veto points inside', 100, -0.5, 99.5)
        ut.bookHist(h, 'multN', 'mult neutrons', 100, -0.5, 99.5)

        flukaRateIntegrated()
        Nsim = f.cbmsim.GetEntries()
        for sTree in f.cbmsim:
            rc = h['multN'].Fill(sTree.MCTrack.GetEntries())
            neutron = sTree.MCTrack[0]
            start = ROOT.TVector3(neutron.GetStartX(), neutron.GetStartY(),
                                  neutron.GetStartZ())
            if start.y() < boundaries['botSens']: continue

            P = ROOT.TVector3(neutron.GetPx(), neutron.GetPy(),
                              neutron.GetPz())
            Ekin = ROOT.TMath.Sqrt(P.Mag2() + neutronMass**2) - neutronMass
            W = h['Fig12'].Eval(ROOT.TMath.Log10(Ekin * 1000)) / Nsim
            rc = h['start'].Fill(start.Z(), start.X(), start.Y(), W)
            rc = h['EkinW'].Fill(ROOT.TMath.Log10(Ekin), W)
            rc = h['EkinWlin'].Fill(Ekin, W)
            rc = h['EkinG'].Fill(ROOT.TMath.Log10(Ekin))
            rc = h['startR'].Fill(start.Mag(), W)
            nC, nS = 0, 0
            for p in sTree.vetoPoint:
                if p.PdgCode() != 2112: continue
                if p.GetDetectorID() == 13: nC += 1
                else: nS += 1
            rc = h['multC'].Fill(nC)
            rc = h['multS'].Fill(nS)
            trajectory = {}
            for p in sTree.vetoPoint:
                if p.PdgCode() != 2112: continue
                trackID = p.GetTrackID()
                if not trackID in trajectory: trajectory[trackID] = []
                trajectory[trackID].append(p)
            for trackID in trajectory:
                firstSens = True
                for p in trajectory[trackID]:
                    origin = '_seco'
                    if trackID == 0: origin = '_prim'
                    lastPoint = p.LastPoint()
                    mPoint = ROOT.TVector3(p.GetX(), p.GetY(), p.GetZ())
                    firstPoint = 2 * mPoint - lastPoint
                    D = lastPoint - firstPoint
                    TD = firstPoint - start
                    firstMom = ROOT.TVector3(p.GetPx(), p.GetPy(), p.GetPz())
                    Ekin_entry = ROOT.TMath.Sqrt(firstMom.Mag2() +
                                                 neutronMass**2) - neutronMass
                    if p.GetDetectorID(
                    ) == 13 and firstSens:  # first point inside coldbox
                        firstSens = False
                        rc = h['exit' + origin].Fill(firstPoint.X(),
                                                     firstPoint.Y(),
                                                     firstPoint.Z(), W)

                        if Ekin * 1E9 < 10:
                            rc = h['exitcold-original' + origin].Fill(
                                firstPoint.X(), firstPoint.Y(), firstPoint.Z(),
                                W)  # 10eV
                        else:
                            rc = h['exithot-original' + origin].Fill(
                                firstPoint.X(), firstPoint.Y(), firstPoint.Z(),
                                W)

                        if Ekin_entry * 1E9 < 10:
                            rc = h['exitcold' + origin].Fill(
                                firstPoint.X(), firstPoint.Y(), firstPoint.Z(),
                                W)  # 10eV
                        else:
                            rc = h['exithot' + origin].Fill(
                                firstPoint.X(), firstPoint.Y(), firstPoint.Z(),
                                W)
                        rc = h['DF' + origin].Fill(TD.Mag(), W)
                        rc = h['EkinF' + origin].Fill(
                            ROOT.TMath.Log10(Ekin_entry), D.Mag(), W)
                        rc = h['EkinF-original' + origin].Fill(
                            ROOT.TMath.Log10(Ekin), D.Mag(), W)
                        # find location     Rsens = ['','topSens','botSens','leftSens','rightSens','frontSens','backSens']
                        found = False
                        for r in Rsens:
                            if r == '': continue
                            X = eval('firstPoint.' + Rsens[r] + '()')
                            if abs(X - boundaries[r]) < epsi:
                                #           if r=='botSens' and p!=trajectory[trackID][0]: continue    # to enter from bottom is without crossing shield. It is more complicated!
                                found = True
                                break
                        if not found:
                            txt = ''
                            for r in Rsens:
                                if r == '': continue
                                X = eval('firstPoint.' + Rsens[r] + '()')
                                txt += " " + r + " " + str(X)
                                print("this should no happen", txt, boundaries)
                                for P in trajectory[trackID]:
                                    print(P.GetDetectorID(),
                                          P.LastPoint().X(),
                                          P.LastPoint().Y(),
                                          P.LastPoint().Z())
                        rc = h['DF' + r + origin].Fill(TD.Mag(), W)
                        rc = h['EkinF' + r + origin].Fill(
                            ROOT.TMath.Log10(Ekin_entry), D.Mag(), W)
                        rc = h['EkinF-original' + r + origin].Fill(
                            ROOT.TMath.Log10(Ekin), D.Mag(), W)
                        rc = h['checkBox' + r + origin].Fill(
                            firstPoint.X(), firstPoint.Y(), firstPoint.Z(), W)

                    if p.GetDetectorID() == 1:  # inside shielding
                        # check that first point is further out.
                        if firstPoint.Mag() < lastPoint.Mag(): continue
                        rc = h['Ekin' + origin].Fill(ROOT.TMath.Log10(Ekin),
                                                     D.Mag(), W)
                        rc = h['EkinE' + origin].Fill(
                            ROOT.TMath.Log10(Ekin_entry), D.Mag(), W)
                        rc = h['entry' + origin].Fill(firstPoint.X(),
                                                      firstPoint.Y(),
                                                      firstPoint.Z(), W)
                        if Ekin * 1E9 < 10:
                            rc = h['entrycold' + origin].Fill(
                                firstPoint.X(), firstPoint.Y(), firstPoint.Z(),
                                W)  # 10eV
                        else:
                            rc = h['entryhot' + origin].Fill(
                                firstPoint.X(), firstPoint.Y(), firstPoint.Z(),
                                W)
                        # find location
                        for r in Rin:
                            if r == '': continue
                            X = eval('firstPoint.' + Rin[r] + '()')
                            if abs(X - boundaries[r]) < epsi: break
                        rc = h['Ekin' + r + origin].Fill(
                            ROOT.TMath.Log10(Ekin), X, W)
                        rc = h['EkinE' + r + origin].Fill(
                            ROOT.TMath.Log10(Ekin_entry), X, W)

        tmp = options.inputFile.split('/')
        outFile = 'histos-' + tmp[len(tmp) - 1]
        # make sum of seco and prim
        hkeys = list(h.keys())
        for x in hkeys:
            if x.find('_seco') > 0:
                hname = x.replace('_seco', '')
                h[hname] = h[x].Clone(hname)
                h[hname].Add(h[x.replace('_seco', '_prim')])
#
        ut.writeHists(h, outFile)
        print('finished making histograms ',
              'histos-noConc-' + options.inputFile)

    else:
        ut.readHists(h, options.inputFile)
        if pas != '':
            ut.readHists(
                hnorm, 'histos-thermNeutron_vacuums_0.0001_coldbox_pass1.root')
        else:
            ut.readHists(hnorm, options.inputFile)
        tmp = options.inputFile.split('_')
        material = tmp[1] + "_coldbox/"
        thickness = "_" + tmp[2]

        binning = {}
        for c in ['entry', 'exit']:
            binning[c] = {}
            for p in ['x', 'y', 'z']:
                tmp = h[c].Project3D(p)
                for imin in range(1, tmp.GetNbinsX() + 1):
                    if tmp.GetBinContent(imin) > 0: break
                for imax in range(tmp.GetNbinsX(), 0, -1):
                    if tmp.GetBinContent(imax) > 0: break
                binning[c][p] = {'min': imin, 'max': imax}

#
        ytop = {
            'axis': 'Y',
            'proj': 'xz',
            'entry': binning['entry']['y']['max'],
            'exit': h['exit'].GetYaxis().FindBin(boundaries['topSens']),
            'xdist': dZ,
            'ydist': dX
        }
        ybot = {
            'axis': 'Y',
            'proj': 'xz',
            'entry': binning['entry']['y']['min'],
            'exit': h['exit'].GetYaxis().FindBin(boundaries['botSens']),
            'xdist': dZ,
            'ydist': dX
        }
        xLeft = {
            'axis': 'X',
            'proj': 'yz',
            'entry': binning['entry']['x']['min'],
            'exit': h['exit'].GetXaxis().FindBin(boundaries['leftSens']),
            'xdist': dZ,
            'ydist': dY
        }
        xRight = {
            'axis': 'X',
            'proj': 'yz',
            'entry': binning['entry']['x']['max'],
            'exit': h['exit'].GetXaxis().FindBin(boundaries['rightSens']),
            'xdist': dZ,
            'ydist': dY
        }
        zMin = {
            'axis': 'Z',
            'proj': 'yx',
            'entry': binning['entry']['z']['min'],
            'exit': h['exit'].GetZaxis().FindBin(boundaries['backSens']),
            'xdist': dX,
            'ydist': dY
        }
        zMax = {
            'axis': 'Z',
            'proj': 'yx',
            'entry': binning['entry']['z']['max'],
            'exit': h['exit'].GetXaxis().FindBin(boundaries['frontSens']),
            'xdist': dX,
            'ydist': dY
        }
        print('boundaries', boundaries)

        # make projections
        projections = {
            'Top': ytop,
            'Bot': ybot,
            'Right': xRight,
            'Left': xLeft,
            'Front': zMax,
            'Back': zMin
        }
        h['fluences'] = {}
        for o in ['', '_prim']:
            for T in ['', 'cold', 'hot']:
                for Z in ['entry', 'exit', 'exit-original']:
                    tmp = Z.split('-')
                    c = tmp[0]
                    x = ''
                    if len(tmp) > 1: x = '-' + tmp[1]
                    case = c + T + x + o
                    ut.bookCanvas(h, 't' + case, case, 1200, 1800, 2, 3)
                    k = 1
                    for p in projections:
                        h['t' + case].cd(k)
                        tmp = h[case]
                        axis = eval('tmp.Get' + projections[p]['axis'] +
                                    'axis()')
                        if Z == 'entry':
                            axis.SetRange(projections[p][c] - 1,
                                          projections[p][c] + 1)
                        else:
                            axis.SetRange(projections[p][c], projections[p][c])
                            if p == 'xBot':
                                xax = tmp.GetXaxis()
                                xax.SetRange(
                                    xax.FindBin(boundaries['leftSens']) + 1,
                                    xax.FindBin(boundaries['rightSens']) - 1)
                                zax = tmp.GetZaxis()
                                zax.SetRange(
                                    zax.FindBin(boundaries['backSens']) + 1,
                                    zax.FindBin(boundaries['frontSens']) - 1)
                        h[case + p] = tmp.Project3D(projections[p]['proj'])
                        h[case + p].SetName(case + p)
                        tmp.GetXaxis().SetRange(0, 0)
                        tmp.GetYaxis().SetRange(0, 0)
                        tmp.GetZaxis().SetRange(0, 0)
                        h[case + p].SetStats(0)
                        h[case + p].SetMinimum(0)
                        h[case + p].SetTitle(p)
                        h[case + p].Draw('colz')
                        # check uniformity:
                        h['X-' + case + p] = h[case + p].ProjectionX('X-' +
                                                                     case + p)
                        h['Y-' + case + p] = h[case + p].ProjectionY('Y-' +
                                                                     case + p)
                        k += 1
                        sqcm = projections[p]['xdist'] * projections[p]['ydist']
                        entries = h[case + p].GetSumOfWeights()
                        X = entries / sqcm
                        if X > 100: txt = "%5.1F/cm^{2}" % (X)
                        else: txt = "%5.2F/cm^{2}" % (X)
                        h['fluences'][case + p] = X
                        L = ROOT.TLatex()
                        rc = L.DrawLatexNDC(0.2, 0.85, txt)
                        h['X-' + case + p].Scale(1. / projections[p]['ydist'])
                        h['Y-' + case + p].Scale(1. / projections[p]['xdist'])
                    myPrint(h['t' + case], material + 't' + case + thickness)


# make cross checks
        ut.bookCanvas(h, 'crosschecks', 'cross checks', 900, 600, 1, 1)
        tc = h['crosschecks'].cd()
        tc.SetLogy(1)
        tc.SetGridx()
        tc.SetGridy()
        h['EkinW'].SetStats(0)
        h['EkinW'].SetStats(0)
        h['EkinW'].SetLineWidth(3)
        h['EkinW'].SetTitle(';log(E) [GeV];dn/dlogE [cm^{-2}y^{-1}] ')
        h['EkinW'].SetMaximum(1E8)
        h['EkinW'].SetMinimum(1E2)
        h['EkinW'].Draw()
        myPrint(h['crosschecks'], material + 'kinEnergy' + thickness)
        tc.SetLogy(0)
        k = -10
        for p in projections:
            for l in ['X-', 'Y-']:
                case = l + 'entry' + p
                h[case].SetLineColor(ROOT.kRed + k)
                h[case].SetStats(0)
                if k < -9:
                    h[case].SetTitle('; x,y,z  [cm]; N/L [cm^{-1}]')
                    tpl = ut.findMaximumAndMinimum(h[case])
                    h[case].SetMaximum(tpl[1] * 1.5)
                    h[case].Draw()
                else:
                    h[case].Draw('same')
                k += 1
        myPrint(h['crosschecks'], material + 'irradiationXYZ' + thickness)
        #
        tc.SetLogy(1)
        #  Ekin     Rin      = {'':'','topIn':'Y','leftIn':'X','rightIn':'X','frontIn':'Z','backIn':'Z'}
        #  EkinF   Rsens = {'':'','topSens':'Y','botSens':'Y','leftSens':'X','rightSens':'X','frontSens':'Z','backSens':'Z'}
        ut.bookCanvas(h, 'trej', 'rejections', 1200, 1800, 2, 3)
        k = 0
        for r in ['', 'top', 'bot', 'right', 'left', 'front', 'back']:
            rej = 'rej' + r
            rejo = 'rejo' + r
            if r == '':
                norm = hnorm['Ekin'].ProjectionX('norm')
                h[rej] = h['EkinF'].ProjectionX(rej)
                h[rejo] = h['EkinF-original'].ProjectionX(rejo)
            else:
                k += 1
                if r == 'bot': norm = hnorm['EkintopIn'].ProjectionX('norm')
                else: norm = hnorm['Ekin' + r + 'In'].ProjectionX('norm')
                h[rej] = h['EkinF' + r + 'Sens'].ProjectionX(rej)
                h[rejo] = h['EkinF-original' + r + 'Sens'].ProjectionX(rejo)
            h[rej].Divide(norm)
            h[rejo].Divide(norm)
            h[rej].SetStats(0)
            h[rejo].SetStats(0)
            h[rej].SetTitle(';log10(Ekin) GeV; rejection')
            h[rej].SetLineColor(ROOT.kBlue)
            h[rej].SetLineWidth(2)
            h[rejo].SetLineWidth(2)
            h[rejo].SetLineColor(ROOT.kGreen)
            h[rej].GetXaxis().SetRangeUser(-13., -1.)
            h[rej].SetMaximum(1.2)
            h[rej].SetMinimum(1.E-4)
            if k == 0: tc = h['crosschecks'].cd()
            else:
                tc = h['trej'].cd(k)
                tc.SetGridx()
                tc.SetGridy()
                h[rej].SetMinimum(1.E-6)
                h[rej].SetTitle(r[0].upper() + r[1:])
            tc.SetLogy()
            h[rej].Draw('hist')
            h[rejo].Draw('histsame')
            h['legR' + r] = ROOT.TLegend(0.11, 0.74, 0.72, 0.82)
            rc = h['legR' + r].AddEntry(
                h[rejo],
                'reduction as function of original E_{kin} when entering shield',
                'PL')
            rc = h['legR' + r].AddEntry(
                h[rej], 'reduction as function of E_{kin} when leaving shield',
                'PL')
            h['legR' + r].Draw('same')
            if k == 0:
                myPrint(h['crosschecks'], material + 'rejections' + thickness)
        myPrint(h['trej'], material + 'Listrejections' + thickness + pas)
        #
        h['dangerZone'] = ROOT.TGraph()
        h['dangerZone'].SetPoint(0, -8.6, 0.)
        h['dangerZone'].SetPoint(1, -8.6, 1.)
        h['dangerZone'].SetPoint(2, -8.1, 1.)
        h['dangerZone'].SetPoint(3, -8.1, 0.)
        h['dangerZone'].SetFillStyle(1001)
        h['dangerZone'].SetFillColor(ROOT.kYellow)
        for r in ['rej', 'rejo']:
            ut.bookCanvas(h, r + 'ection2', 'rejectionRate', 900, 600, 1, 1)
            h[r + 'TopLeftRightBack'] = h[r + 'top'].Clone(r +
                                                           'TopLeftRightBack')
            h[r + 'TopLeftRightBack'].Add(h[r + 'left'])
            h[r + 'TopLeftRightBack'].Add(h[r + 'right'])
            h[r + 'TopLeftRightBack'].Add(h[r + 'back'])
            h[r + 'TopLeftRightBack'].Scale(1. / 4.)
            h[r + 'TopLeftRightBack'].SetTitle('')
            if r == 'rej':
                h[r + 'TopLeftRightBack'].GetXaxis().SetTitle(
                    'outgoing   ' +
                    h[r + 'TopLeftRightBack'].GetXaxis().GetTitle())
            if r == 'rejo':
                h[r + 'TopLeftRightBack'].GetXaxis().SetTitle(
                    'incoming   ' +
                    h[r + 'TopLeftRightBack'].GetXaxis().GetTitle())
            h[r + 'TopLeftRightBack'].SetLineColor(ROOT.kGreen)
            h[r + 'bot'].SetLineColor(ROOT.kGray)
            h[r + 'front'].SetLineColor(ROOT.kRed)
            h[r + 'TopLeftRightBack'].SetMaximum(1.2)
            h[r + 'TopLeftRightBack'].SetMinimum(1.E-6)
            tc = h[r + 'ection2'].cd()
            tc.SetGridx()
            tc.SetGridy()
            tc.SetLogy()
            h[r + 'TopLeftRightBack'].Draw()
            h['dangerZone'].Draw('sameF')
            h[r + 'TopLeftRightBack'].Draw('same')
            h[r + 'bot'].Draw('same')
            h[r + 'front'].Draw('same')
            h[r + 'legR2'] = ROOT.TLegend(0.55, 0.30, 0.86, 0.45)
            rc = h[r + 'legR2'].AddEntry(h[r + 'TopLeftRightBack'],
                                         'av. rejection top/left/right/back',
                                         'PL')
            rc = h[r + 'legR2'].AddEntry(h[r + 'bot'],
                                         'rejction bottom, only concrete',
                                         'PL')
            rc = h[r + 'legR2'].AddEntry(h[r + 'front'],
                                         'rejction front, with holes', 'PL')
            h[r + 'legR2'].Draw('same')
            myPrint(h[r + 'ection2'],
                    material + 'Sum ' + r + 'ections' + thickness + pas)

        if pas == '':
            ut.writeHists(h, options.inputFile.replace('.root', '_pass1.root'))

        # statistics:
        for o in ['', '-original']:
            for T in ['cold', 'hot']:
                norm = 0
                exit = 0
                concrete = 0
                holes = 0
                for p in projections:
                    if p != 'Bot' and norm != 'Front':
                        norm += h['fluences']['entry' + T + p]
                        exit += h['fluences']['exit' + T + o + p]
                    if p == 'Bot': concrete = h['fluences']['exit' + T + o + p]
                    elif p == 'Front':
                        holes = h['fluences']['exit' + T + o + p]
                norm = norm / float(4)
                exit = exit / float(4)
                #! do not need average, need total.
                # incoming = 6 * average !
                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))
示例#41
0
def makeV0Plots():
 ut.bookCanvas(h,key='results',title='V0',           nx=1400,ny=600,cx=4,cy=1)
 ut.bookCanvas(h,key='resultsXYZ',title='V0 XYZ',    nx=1400,ny=600,cx=4,cy=1)
 ut.bookCanvas(h,key='resultsrhoZ',title='V0 rhoZ',  nx=1400,ny=600,cx=4,cy=1)
 ut.bookCanvas(h,key='resultsrhoZmu',title='mu rhoZ',nx=1400,ny=600,cx=4,cy=1)
 ut.bookCanvas(h,key='resultsL',title='V0 L',        nx=1400,ny=600,cx=4,cy=1)
 ut.bookCanvas(h,key='resultsLd',title='V0 Ldecay',  nx=1400,ny=600,cx=4,cy=1)
 ROOT.gStyle.SetOptStat(1111111)
 i = 1
 for x in V0dict: 
  h['results'].cd(i) 
  h[x].Draw()
  h['resultsXYZ'].cd(i) 
  h[str(x)+'xyz'].Draw()
  h['resultsrhoZ'].cd(i) 
  h[str(x)+'rhoz'].Draw('colz')
  h['resultsrhoZmu'].cd(i) 
  h[str(x)+'rhozmu'].Draw('colz')
  h['resultsL'].cd(i) 
  h[str(x)+'L'].Draw()
  h['resultsLd'].cd(i) 
  h[str(x)+'Ldecay'].Draw()
  i+=1
示例#42
0
def run():
 fGeo = ROOT.gGeoManager
 run = sys.modules['__main__'].run
 if hasattr(sys.modules['__main__'],'h'): h =  sys.modules['__main__'].h
 else: h={} 
 grid = 120,100,1500
 xmin,ymin,zmin = -4*u.m,-5*u.m,-100*u.m
 xmax,ymax,zmax = 4*u.m,5*u.m,50*u.m
 dx,dy,dz = (xmax-xmin)/grid[0],(ymax-ymin)/grid[1],(zmax-zmin)/grid[2]
 ut.bookHist(h,'Bx-','Bx- component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'By-','By- component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'Bz-','Bz- component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'Bx+','Bx+ component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'By+','By+ component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'Bz+','Bz+ component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 h['Bx-'].SetMarkerColor(ROOT.kGreen-3)
 h['Bx+'].SetMarkerColor(ROOT.kGreen+3)
 h['By-'].SetMarkerColor(ROOT.kBlue-3)
 h['By+'].SetMarkerColor(ROOT.kBlue+3)
 h['Bz-'].SetMarkerColor(ROOT.kCyan-2)
 h['Bz+'].SetMarkerColor(ROOT.kCyan+2)
 for ix in range(grid[0]):
  for iy in range(grid[1]):
   for iz in range(grid[2]):
    x,y,z = xmin + ix*dx,ymin + iy*dy,zmin + iz*dz
    n = fGeo.FindNode(x,y,z)
    f = n.GetVolume().GetField()
    if f: 
      if f.GetFieldValue()[0]<0:  rc=h['Bx-'].Fill(z,x,y,-f.GetFieldValue()[0]/u.tesla)     
      if f.GetFieldValue()[0]>0:  rc=h['Bx+'].Fill(z,x,y,f.GetFieldValue()[0]/u.tesla)     
      if f.GetFieldValue()[1]<0:  rc=h['By-'].Fill(z,x,y,-f.GetFieldValue()[1]/u.tesla)     
      if f.GetFieldValue()[1]>0:  rc=h['By+'].Fill(z,x,y,f.GetFieldValue()[1]/u.tesla)     
      if f.GetFieldValue()[2]<0:  rc=h['Bz-'].Fill(z,x,y,-f.GetFieldValue()[2]/u.tesla)   
      if f.GetFieldValue()[2]>0:  rc=h['Bz+'].Fill(z,x,y,f.GetFieldValue()[2]/u.tesla)   
    f = run.GetField()
    if f.GetBx(x,y,z)<0: rc=h['Bx-'].Fill(z,x,y,-f.GetBx(x,y,z)/u.tesla) 
    if f.GetBx(x,y,z)>0: rc=h['Bx+'].Fill(z,x,y,f.GetBx(x,y,z)/u.tesla) 
    if f.GetBy(x,y,z)<0: rc=h['By-'].Fill(z,x,y,-f.GetBy(x,y,z)/u.tesla)
    if f.GetBy(x,y,z)>0: rc=h['By+'].Fill(z,x,y,f.GetBy(x,y,z)/u.tesla) 
 hkeys = h.keys()
 for x in hkeys:
  hi = h[x]
  if hi.ClassName()=='TH3F':
   h[x+'_xz']=h[x].Project3D('xy')
   h[x+'_xz'].SetTitle(hi.GetTitle()+' top view')
   h[x+'_yz']=h[x].Project3D('xz')  
   h[x+'_yz'].SetTitle(hi.GetTitle()+' side view')
 for x in h: 
  h[x].SetStats(0)
  h[x].SetMarkerSize(3)
 txt = {'y':[' Up',' Down'],'x':[' Right',' Left']}
 for pol in ['y','x']:
  for p in ['_xz','_yz']:
   cn = 'c'+pol+p
   ut.bookCanvas(h,key=cn,title='field check',nx=1600,ny=1200,cx=1,cy=1)
   h[cn].cd(1)
   h['B'+pol+'+'+p].Draw()
   h['B'+pol+'-'+p].Draw('same')
   h['B'+pol+'L'+p] = ROOT.TLegend(0.79,0.72,0.91,0.87)
   h['B'+pol+'L'+p].AddEntry(h['B'+pol+'+'],'B'+pol+txt[pol][0],'PM')
   h['B'+pol+'L'+p].AddEntry(h['B'+pol+'-'],'B'+pol+txt[pol][1],'PM')
   h['B'+pol+'L'+p].Draw()
   h[cn].Update()
   h[cn].Print('FieldB'+pol+'Proj'+p+'.png')
    if not l.find("muMinusCaptureAtRest:") < 0:
        x = (l.replace("\n", "")).replace("{", "")
        xx = (x.replace("}", "")).replace("'", "")
        for k in xx.split(","):
            i = k.split(":")
            ProcDict[i[0]] = int(i[1])
            dictProc[int(i[1])] = i[0]
#
model = "QGSP_BERT_EMX"
withField = False
shieldLength = 30.5  #    80m  50 + 30
zdet = 40  # at 90m  50 + 40
Rdet = str(2.5 / 100.0 * 90.0)

h = {}
u.bookCanvas(h, key="ResultsI", title="results", nx=1600, ny=1200, cx=4, cy=2)
if not withField:
    u.bookCanvas(
        h,
        key="ResultsII",
        title="results only muons reaching detector for shielding " + str(shieldLength + 50 - 0.5),
        nx=1600,
        ny=1200,
        cx=4,
        cy=2,
    )
else:
    u.bookCanvas(h, key="ResultsII", title="results only muons reaching detector", nx=1600, ny=1200, cx=4, cy=2)
u.bookCanvas(h, key="ResultsIII", title="results final momentum ", nx=1600, ny=1200, cx=4, cy=2)
u.bookCanvas(h, key="ResultsIV", title="results X Y", nx=1600, ny=1200, cx=4, cy=2)
u.bookCanvas(h, key="ResultsV", title="results X Y", nx=1600, ny=1200, cx=4, cy=2)
示例#44
0
def makeSummaryPlot():
    # using data in /mnt/hgfs/microDisk/Data/eloss/eloss_sum.root
    # krypton total interaction length= 1.97246306079 total rad length= 26.5231000393
    pdg = {
        10.0: 1.914,
        14.0: 1.978,
        20.0: 2.055,
        30.0: 2.164,
        40.0: 2.263,
        80.0: 2.630,
        100.: 2.810,
        140.: 3.170,
        200.: 3.720,
        277.: 4.420,
        300.: 4.631,
        400.: 5.561
    }
    h['Gpdg'] = ROOT.TGraph(len(pdg))
    Gpdg = h['Gpdg']
    Gpdg.SetMarkerColor(ROOT.kRed)
    Gpdg.SetMarkerStyle(20)
    keys = sorted(pdg.keys())
    for n in range(len(keys)):
        Gpdg.SetPoint(n, keys[n], pdg[keys[n]])
    density = 2.413
    length = 125.0
    ut.readHists(h, "/mnt/hgfs/microDisk/Data/eloss/eloss_sum.root")
    ut.readHists(h, "/mnt/hgfs/microDisk/Data/eloss/eloss_withRaw.root")
    ut.bookCanvas(h, key='summary', title=" ", nx=1200, ny=600, cx=2, cy=1)
    tc = h['summary'].cd(1)
    h['0'] = h['eloss'].ProjectionX('0', 1, h['eloss'].GetNbinsY())
    h['0'].Sumw2()
    NA62()
    for t in [93, 95]:
        h[t] = h['eloss'].ProjectionX(str(t),
                                      int(h['eloss'].GetNbinsY() * t / 100.),
                                      h['eloss'].GetNbinsY())
        h[t].Sumw2()
        h[t].SetStats(0)
        h[t].SetMarkerStyle(24)
        rc = h[t].Divide(h['0'])
        h[t].Rebin(2)
        h[t].Scale(1. / 2.)
        if t != 93:
            h[t].SetMarkerColor(ROOT.kBlue)
            h[t].Draw('same')
        else:
            h[t].SetMaximum(1E-5)
            h[t].SetMarkerColor(ROOT.kMagenta)
            h[t].SetXTitle('incoming muon momentum [GeV/c]')
            h[t].SetYTitle('prob #DeltaE>X%')
            h[t].SetTitle('')
            h[t].Draw()
        h['NA62'].Draw('sameP')
    h['lg'] = ROOT.TLegend(0.53, 0.79, 0.98, 0.94)
    h['lg'].AddEntry(h['NA62'], 'NA62 measurement >95%', 'PL')
    h['lg'].AddEntry(h[95], 'FairShip >95%', 'PL')
    h['lg'].AddEntry(h[93], 'FairShip >93%', 'PL')
    h['lg'].Draw()
    tc = h['summary'].cd(2)
    h['meanEloss'] = h['elossRaw'].ProjectionX()
    for n in range(1, h['elossRaw'].GetNbinsX() + 1):
        tmp = h['elossRaw'].ProjectionY('tmp', n, n)
        eloss = tmp.GetMean()
        h['meanEloss'].SetBinContent(n, eloss / density / length * 1000)
        h['meanEloss'].SetBinError(n, 0)
    h['meanEloss'].SetTitle('mean energy loss MeV cm^{2}/g')
    h['meanEloss'].SetStats(0)
    h['meanEloss'].SetMaximum(7.)
    h['meanEloss'].SetXTitle('incoming muon momentum [GeV/c]')
    h['meanEloss'].SetYTitle('mean energy loss [MeV cm^[2]]/g')
    h['meanEloss'].SetTitle('')
    h['meanEloss'].Draw()
    Gpdg.Draw('sameP')
    h['lg2'] = ROOT.TLegend(0.53, 0.79, 0.98, 0.94)
    h['lg2'].AddEntry(h['Gpdg'], 'muon dE/dx, PDG ', 'PL')
    h['lg2'].AddEntry(h['meanEloss'], 'energy deposited in krypton, FairShip',
                      'PL')
    h['lg2'].Draw()
    h['summary'].Print('catastrophicEnergyLoss.png')
示例#45
0
def analyzeConcrete():
    for m in ['', 'mu']:
        ut.bookHist(h, 'conc_hitz' + m, 'concrete hit z ' + m, 100, -100.,
                    100.)
        ut.bookHist(h, 'conc_hity' + m, 'concrete hit y ' + m, 100, -15., 15.)
        ut.bookHist(h, 'conc_p' + m, 'concrete hit p ' + m, 100, 0., 300.)
        ut.bookHist(h, 'conc_pt' + m, 'concrete hit pt ' + m, 100, 0., 10.)
        ut.bookHist(h, 'conc_hitzy' + m, 'concrete hit zy ' + m, 100, -100.,
                    100., 100, -15., 15.)
    top = fGeo.GetTopVolume()
    magn = top.GetNode("magyoke_1")
    z0 = magn.GetMatrix().GetTranslation()[2] / u.m
    for fn in fchain:
        f = ROOT.TFile(fn)
        if not f.FindObjectAny('cbmsim'):
            print 'skip file ', f.GetName()
            continue
        sTree = f.cbmsim
        nEvents = sTree.GetEntries()
        for n in range(nEvents):
            sTree.GetEntry(n)
            wg = sTree.MCTrack[0].GetWeight()
            for ahit in sTree.vetoPoint:
                detID = ahit.GetDetectorID()
                if logVols[detID] != 'rockD': continue
                m = ''
                if abs(ahit.PdgCode()) == 13: m = 'mu'
                h['conc_hitz' + m].Fill(ahit.GetZ() / u.m - z0, wg)
                h['conc_hity' + m].Fill(ahit.GetY() / u.m, wg)
                P = ROOT.TMath.Sqrt(ahit.GetPx()**2 + ahit.GetPy()**2 +
                                    ahit.GetPz()**2)
                h['conc_p' + m].Fill(P / u.GeV, wg)
                Pt = ROOT.TMath.Sqrt(ahit.GetPx()**2 + ahit.GetPy()**2)
                h['conc_pt' + m].Fill(Pt / u.GeV, wg)
                h['conc_hitzy' + m].Fill(ahit.GetZ() / u.m - z0,
                                         ahit.GetY() / u.m, wg)
                #
                start = [
                    ahit.GetX() / u.m,
                    ahit.GetY() / u.m,
                    ahit.GetZ() / u.m
                ]
                direc = [
                    -ahit.GetPx() / P, -ahit.GetPy() / P, -ahit.GetPz() / P
                ]
                t = -start[0] / direc[0]

    ut.bookCanvas(h,
                  key='Resultsmu',
                  title='muons hitting concrete',
                  nx=1000,
                  ny=600,
                  cx=2,
                  cy=2)
    ut.bookCanvas(h,
                  key='Results',
                  title='hitting concrete',
                  nx=1000,
                  ny=600,
                  cx=2,
                  cy=2)
    for m in ['', 'mu']:
        tc = h['Results' + m].cd(1)
        h['conc_hity' + m].Draw()
        tc = h['Results' + m].cd(2)
        h['conc_hitz' + m].Draw()
        tc = h['Results' + m].cd(3)
        tc.SetLogy(1)
        h['conc_pt' + m].Draw()
        tc = h['Results' + m].cd(4)
        tc.SetLogy(1)
        h['conc_p' + m].Draw()
示例#46
0
def makePlots():
   ut.bookCanvas(h,key='ecalanalysis',title='cluster map',nx=800,ny=600,cx=1,cy=1)
   cv = h['ecalanalysis'].cd(1)
   h['ecalClusters'].Draw('colz')
   ut.bookCanvas(h,key='ecalCluster2Track',title='Ecal cluster distances to track impact',nx=1600,ny=800,cx=4,cy=2)
   if h.has_key("ecalReconstructed_dist_mu+"):
    cv = h['ecalCluster2Track'].cd(1)
    h['ecalReconstructed_distx_mu+'].Draw()
    cv = h['ecalCluster2Track'].cd(2)
    h['ecalReconstructed_disty_mu+'].Draw()
   if h.has_key("ecalReconstructed_dist_pi+"):
    cv = h['ecalCluster2Track'].cd(3)
    h['ecalReconstructed_distx_pi+'].Draw()
    cv = h['ecalCluster2Track'].cd(4)
    h['ecalReconstructed_disty_pi+'].Draw()
   if h.has_key("ecalReconstructed_dist_mu-"):
    cv = h['ecalCluster2Track'].cd(5)
    h['ecalReconstructed_distx_mu-'].Draw()
    cv = h['ecalCluster2Track'].cd(6)
    h['ecalReconstructed_disty_mu-'].Draw()
   if h.has_key("ecalReconstructed_dist_pi-"):
    cv = h['ecalCluster2Track'].cd(7)
    h['ecalReconstructed_distx_pi-'].Draw()
    cv = h['ecalCluster2Track'].cd(8)
    h['ecalReconstructed_disty_pi-'].Draw()

   ut.bookCanvas(h,key='strawanalysis',title='Distance to wire and mean nr of hits',nx=1200,ny=600,cx=3,cy=1)
   cv = h['strawanalysis'].cd(1)
   h['disty'].Draw()
   h['distu'].Draw('same')
   h['distv'].Draw('same')
   cv = h['strawanalysis'].cd(2)
   h['meanhits'].Draw()
   cv = h['strawanalysis'].cd(3)
   h['meas2'].Draw()
   ut.bookCanvas(h,key='fitresults',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   cv = h['fitresults'].cd(1)
   h['delPOverPz'].Draw('box')
   cv = h['fitresults'].cd(2)
   cv.SetLogy(1)
   h['prob'].Draw()
   cv = h['fitresults'].cd(3)
   h['delPOverPz_proj'] = h['delPOverPz'].ProjectionY()
   ROOT.gStyle.SetOptFit(11111)
   h['delPOverPz_proj'].Draw()
   h['delPOverPz_proj'].Fit('gaus')
   cv = h['fitresults'].cd(4)
   h['delPOverP2z_proj'] = h['delPOverP2z'].ProjectionY()
   h['delPOverP2z_proj'].Draw()
   fitSingleGauss('delPOverP2z_proj')
   h['fitresults'].Print('fitresults.gif')
   ut.bookCanvas(h,key='fitresults2',title='Fit Results',nx=1600,ny=1200,cx=2,cy=2)
   print 'finished with first canvas'
   cv = h['fitresults2'].cd(1)
   h['Doca'].SetXTitle('closest distance between 2 tracks   [cm]')
   h['Doca'].SetYTitle('N/1mm')
   h['Doca'].Draw()
   cv = h['fitresults2'].cd(2)
   h['IP0'].SetXTitle('impact parameter to p-target   [cm]')
   h['IP0'].SetYTitle('N/1cm')
   h['IP0'].Draw()
   cv = h['fitresults2'].cd(3)
   h['HNL'].SetXTitle('inv. mass  [GeV/c2]')
   h['HNL'].SetYTitle('N/4MeV/c2')
   h['HNL'].Draw()
   fitSingleGauss('HNL',0.9,1.1)
   cv = h['fitresults2'].cd(4)
   h['IP0/mass'].SetXTitle('inv. mass  [GeV/c2]')
   h['IP0/mass'].SetYTitle('IP [cm]')
   h['IP0/mass'].Draw('colz')
   h['fitresults2'].Print('fitresults2.gif')
   ut.bookCanvas(h,key='vxpulls',title='Vertex resol and pulls',nx=1600,ny=1200,cx=3,cy=2)
   cv = h['vxpulls'].cd(4)
   h['Vxpull'].Draw()
   cv = h['vxpulls'].cd(5)
   h['Vypull'].Draw()
   cv = h['vxpulls'].cd(6)
   h['Vzpull'].Draw()
   cv = h['vxpulls'].cd(1)
   h['Vxresol'].Draw()
   cv = h['vxpulls'].cd(2)
   h['Vyresol'].Draw()
   cv = h['vxpulls'].cd(3)
   h['Vzresol'].Draw()
   ut.bookCanvas(h,key='trpulls',title='momentum pulls',nx=1600,ny=600,cx=3,cy=1)
   cv = h['trpulls'].cd(1)
   h['pullPOverPx_proj']=h['pullPOverPx'].ProjectionY()
   h['pullPOverPx_proj'].Draw()
   cv = h['trpulls'].cd(2)
   h['pullPOverPy_proj']=h['pullPOverPy'].ProjectionY()
   h['pullPOverPy_proj'].Draw()
   cv = h['trpulls'].cd(3)
   h['pullPOverPz_proj']=h['pullPOverPz'].ProjectionY()
   h['pullPOverPz_proj'].Draw()
   ut.bookCanvas(h,key='vetodecisions',title='Veto Detectors',nx=1600,ny=600,cx=5,cy=1)
   cv = h['vetodecisions'].cd(1)
   cv.SetLogy(1)
   h['nrtracks'].Draw()
   cv = h['vetodecisions'].cd(2)
   cv.SetLogy(1)
   h['nrSVT'].Draw()
   cv = h['vetodecisions'].cd(3)
   cv.SetLogy(1)
   h['nrUVT'].Draw()
   cv = h['vetodecisions'].cd(4)
   cv.SetLogy(1)
   h['nrSBT'].Draw()
   cv = h['vetodecisions'].cd(5)
   cv.SetLogy(1)
   h['nrRPC'].Draw()
#
   print 'finished making plots'
示例#47
0
def zCentre():
 ut.bookHist(h,'xs','x vs z',500,0.,800.,100,-150.,150.)
 ut.bookHist(h,'xss','x vs station',4,0.5,4.5,100,-150.,150.)
 ut.bookHist(h,'wss','wire vs station',4,0.5,4.5,100, -0.5,99.5)
 ut.bookHist(h,'center','z crossing',500,0.,500.)
 ut.bookHist(h,'delx','delta x',200,-200.,200.)
 ut.bookHist(h,'delT3','extr to T3',100,-100.,100.)
 ut.bookHist(h,'delT2','extr to T2',100,-100.,100.)
 ut.bookHist(h,'delT1','extr to T1',100,-100.,100.)
 for event in sTree:
  spectrHitsSorted = sortHits(event)
  X = {1:0,2:0,3:0,4:0}
  Z = {1:0,2:0,3:0,4:0}
  nH  = {1:0,2:0,3:0,4:0}
  passed = True
  for s in range(1,5):
   for hit in spectrHitsSorted['_x'][s]:
     rc = hit.MufluxSpectrometerEndPoints(vbot,vtop)
     rc = h['xs'].Fill( (vbot[2]+vtop[2])/2.,(vbot[0]+vtop[2])/2.)
     rc = h['xss'].Fill( s,(vbot[0]+vtop[2])/2.)
     wire = hit.GetDetectorID()%1000
     rc = h['wss'].Fill(s,wire)
     statnb,vnb,pnb,lnb,view = stationInfo(hit)
     mychannel = (1000*statnb+100*pnb+10*lnb)*100+wire
     if mychannel in noisyChannels:
       continue  
     X[s]+=vbot[0]
     Z[s]+=vbot[2]
     nH[s]+=1
   if nH[s]<3 or nH[s]>6: passed = False
   if not passed: break
   Z[s]=Z[s]/float(nH[s])
   X[s]=X[s]/float(nH[s])
  if not passed: continue
  slopeA = (X[2]-X[1])/(Z[2]-Z[1])
  slopeB = (X[4]-X[3])/(Z[4]-Z[3])
  bA = X[1]-slopeA*Z[1]
  bB = X[3]-slopeB*Z[3]
  zC = (bB-bA)/(slopeA-slopeB+1E-10)
  rc = h['center'].Fill(zC)
  x1 = zgoliath*slopeA+bA
  x2 = zgoliath*slopeB+bB
  rc = h['delx'].Fill(x2-x1)
  rc = h['delT3'].Fill( slopeA*Z[3]+bA-X[3])
  delT1 = slopeB*Z[1]+bB-X[1]
  rc = h['delT1'].Fill( delT1 )
  if delT1 > -20 and delT1 < 10:
   delT2 = slopeB*Z[2]+bB-X[2]
   rc = h['delT2'].Fill( delT2 )
   #if delT2<-18 and delT2>-22 or delT2<38 and delT2> 30:
   #  txt = ''
   #  for hit in spectrHitsSorted['_x'][2]: txt+=str(hit.GetDetectorID())+" "
   #  print delT2,  txt
  
 if not h.has_key('magnetX'): ut.bookCanvas(h,key='magnetX',title='Tracks crossing at magnet',nx=1600,ny=600,cx=3,cy=2)
 h['magnetX'].cd(1)
 h['delx'].Draw()
 h['magnetX'].cd(2)
 h['center'].Draw()
 h['magnetX'].cd(4)
 h['delT3'].Draw()
 h['magnetX'].cd(5)
 h['delT1'].Draw()
 h['magnetX'].cd(6)
 h['delT2'].Draw()
示例#48
0
def makePlotsForTP():
   ut.bookCanvas(h,key='Cdoca',title='doca',nx=900,ny=600,cx=1,cy=1)
   ut.bookCanvas(h,key='SIP',title='IP signal',nx=900,ny=600,cx=1,cy=1)
   ut.bookCanvas(h,key='CIPvsMass',title='IPvsMass',nx=900,ny=600,cx=1,cy=1)
   cv = h['Cdoca'].cd(1)
   h['Doca'].SetXTitle('distance of closest approach  [cm]')
   h['Doca'].SetYTitle('N/1mm')
   h['Doca'].SetLineColor(ROOT.kBlue)
   h['Doca'].SetMarkerColor(ROOT.kBlue)
# DOCA background / signal
   h['Doca'].Draw()  
   f=ROOT.TFile(path+'signal/HNLY10/ship.10.0.Pythia8-TGeant4_50k_ana.root')
   ROOT.gROOT.cd()
   h['signalDoca'] = f.Doca.Clone('signalDoca')
   h['signalIP0'] = f.IP0.Clone('signalIP0')
   h['signaloa'] = f.oa.Clone('signaloa')
   f.Close()
   h['signalDoca'].SetStats(0)
   h['signalDoca'].SetLineColor(ROOT.kRed)
   norm = h['Doca'].GetMaximum() / h['signalDoca'].GetMaximum()
   h['signalDoca'].Scale(norm)
   h['signalDoca'].Draw('same') 
   h['Cdoca'].Print('muDIS_DOCAwithSignal.pdf')
#  
   cv = h['SIP'].cd(1)
   h['signalIP0'].SetStats(0)
   h['signalIP0'].SetXTitle('Impact parameter to primary target for signal  [cm]')
   h['signalIP0'].SetLineColor(ROOT.kRed)
   h['signalIP0'].Draw()
   h['SIP'].Print('muDIS_signalIP0.pdf')
#
   cv = h['CIPvsMass'].cd(1)
   h['IP0/mass'].SetXTitle('invariant mass  [GeV/c^{2}]')
   h['IP0/mass'].SetYTitle('IP to target  [cm]')
   h['IP0/mass'].Draw('box')
   h['CIPvsMass'].Print('CIPvsMass.pdf')
#
   h['rhozmu'] = h['130rhozmu'].Clone('rhozmu') 
   h['rhozmu'].Add(h['310rhozmu'])
   h['rhozmu'].Add(h['3122rhozmu'])
   ut.bookCanvas(h,key='tp1',title='rho z muons',nx=900,ny=600,cx=1,cy=1) 
   tc = h['tp1'].cd(1)
   h['rhozmu'].SetYTitle('distance from beam axis [m]')  
   h['rhozmu'].SetXTitle('distance to start of decay volume [m]') 
   h['rhozmu'].SetZTitle('Number of muons') 
   h['rhozmu'].RebinX(100)
   h['rhozmu'].GetYaxis().SetRange(1,40)
   h['rhozmu'].Draw('colz')
   h['tp1'].Print('muonDISrhoZ.pdf')
# veto counters
   ut.bookCanvas(h,key='veto',title='mass with veto',nx=900,ny=600,cx=1,cy=1) 
   tc = h['veto'].cd(1)
   k=1
   h['lgVeto'] = ROOT.TLegend(0.79,0.72,0.91,0.87)
   for c in vetoDets:      
      if c=="TRA": continue
      h['IP0/mass-'+c].SetXTitle('mass [GeV/c^{2}]')  
      h['IP0/mass-'+c].SetYTitle('IP [cm]')  
      h['IP0/mass-'+c].SetMarkerColor(vetoCl[c])
      h['IP0/mass-'+c].SetMarkerStyle(vetoMr[c])
      if k==1: h['IP0/mass-'+c].Draw('m')
      else: h['IP0/mass-'+c].Draw('msame')
      h['lgVeto'].AddEntry(h['IP0/mass-'+c],c,'PM')
      k+=1 
   h['lgVeto'].Draw()
   h['veto'].Print('muDISVeto.pdf')
#
   ut.bookCanvas(h,key='vetoDetectors',title='signal in Veto Detectors',nx=1200,ny=800,cx=3,cy=2) 
   k=0
   for x in ['nrtracks','nrSVT','nrUVT','nrSBT','nrRPC']:
    k+=1
    tc = h['vetoDetectors'].cd(k)
    bw = int(h[x].GetBinWidth(1))
    h[x].SetYTitle('#Events/'+str(bw))  
    h[x].SetXTitle(x.replace('nr','')+'     #Hits')  
    if x=='nrtracks': h[x].SetXTitle('#tracks') 
    h[x].Draw()
   h['vetoDetectors'].Print('muDISVetoResponse.pdf')
# opening angle 
   ut.bookCanvas(h,key='openingangle',title='cos opening angle',nx=900,ny=600,cx=1,cy=1) 
   tc = h['openingangle'].cd(1)
   h['oa'].SetYTitle('#Events')  
   h['oa'].SetXTitle('cosine of opening angle')  
   h['oa'].Draw()
   h['signaloa'].SetLineColor(ROOT.kRed)
   norm = h['oa'].GetMaximum() / h['signaloa'].GetMaximum()
   h['signaloa'].Scale(norm)
   h['signaloa'].Draw('same') 
   h['openingangle'].Print('muDIS_openingAngle.pdf')
# IP to mu inter
   ut.bookCanvas(h,key='IP2muinter',title='IP to mu inter',nx=900,ny=600,cx=1,cy=1) 
   tc = h['IP2muinter'].cd(1)
   h['IPmuCand'].SetYTitle('#Events')  
   h['IPmuCand'].SetXTitle('IP to muon interaction vertex [cm]')  
   h['IPmuCand'].Draw() 
   h['IP2muinter'].Print('muDIS_IP2MuInter.pdf')
# V0 
   ut.bookCanvas(h,key='V0massIP',title='mass for V0',nx=900,ny=600,cx=1,cy=1) 
   tc = h['V0massIP'].cd(1)
   k=1
   h['lgV0massIP'] = ROOT.TLegend(0.79,0.72,0.91,0.87)
   for c in V0dict:      
      h['IP0/mass-'+str(c)].SetXTitle('mass [GeV/c^{2}]')  
      h['IP0/mass-'+str(c)].SetYTitle('IP [cm]')  
      h['IP0/mass-'+str(c)].SetMarkerColor(v0Cl[c])
      h['IP0/mass-'+str(c)].SetMarkerStyle(v0Mr[c])
      if k==1: h['IP0/mass-'+str(c)].Draw('m')
      else: h['IP0/mass-'+str(c)].Draw('msame')
      h['lgV0massIP'].AddEntry(h['IP0/mass-'+str(c)],PDG.GetParticle(c).GetName(),'PM')
      k+=1 
   h['lgV0massIP'].Draw()
   h['V0massIP'].Print('muDISV0massIP.pdf')
#
   i = 1
   for x in V0dict: 
    h['resultsrhoZ'].cd(i) 
    hn = str(x)+'rhoz'
    if i==1: h[hn].SetYTitle('distance from beam axis [m]')  
    else: h[hn].SetYTitle('')
    if i==2: h[hn].SetXTitle('distance to start of decay vol. [m]')
    else: h[hn].SetXTitle('')
    h['txtV0'+str(x)] = ROOT.TLatex(55.,8.,V0dict[x])
    h[hn].Draw('colz')
    h['txtV0'+str(x)].Draw()
    i+=1
   h['resultsrhoZ'].Print('V0DISDecay_point.pdf')
 if x=='Yandex':
  # opts[x][0].AddFile('Yandex/result_100.root')
  opts[x][0].AddFile('Yandex/gather_result.root')
 else:
  for l in opts[x][1]:
   tl = str(l) 
   test = "/media/Data/HNL/test"
   path = opts[x][2]+'_g4Ex_gap_'+tl
   if path in  os.listdir(test) :
    fn = os.listdir(test+'/'+path)[0]
    opts[x][0].AddFile(test+'/'+path+'/'+fn)
   else: print 'file not found !',path

h={}

u.bookCanvas(h,key='Results',title='results',nx=1600,ny=1200,cx=1,cy=1)

def makeTable(pcut=0,rcut=1.E10):
 print '### for pcut > ',pcut,' and rcut < ',rcut
 pcutsq = str(pcut*pcut)
 rcutsq = str(rcut*rcut)
 for o in opts:
  ok = 'id'+o 
  u.bookHist(h,ok,'id '+o,5001,-2500.5,2499.5)
  opts[o][0].Draw('id>>'+ok,'px*px+py*py+pz*pz>'+pcutsq+'&&x*x+y*y<'+rcutsq)
    # count how many originate from Pythia
  u.bookHist(h,ok+'Py','id '+o+' from pythia',5001,-2500.5,2499.5)
  opts[o][0].Draw('id>>'+ok+'Py','pythiaid==id&&(px*px+py*py+pz*pz)>'+pcutsq+'&&(x*x+y*y)<'+rcutsq)   
  h[ok].SetLineColor(ocol[o])
 tc = h['Results'].cd(1)
 h[ok].Draw()
示例#50
0
def run():
 fGeo = ROOT.gGeoManager
 run = sys.modules['__main__'].run
 if hasattr(sys.modules['__main__'],'h'): h =  sys.modules['__main__'].h
 else: h={} 
 grid = 120,100,1500
 xmin,ymin,zmin = -4*u.m,-5*u.m,-100*u.m
 xmax,ymax,zmax = 4*u.m,5*u.m,50*u.m
 dx,dy,dz = (xmax-xmin)/grid[0],(ymax-ymin)/grid[1],(zmax-zmin)/grid[2]
 ut.bookHist(h,'Bx-','Bx- component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'By-','By- component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'Bz-','Bz- component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'Bx+','Bx+ component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'By+','By+ component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 ut.bookHist(h,'Bz+','Bz+ component ;z [cm];x [cm];y [cm]',grid[2],zmin,zmax,grid[0],xmin,xmax,grid[1],ymin,ymax)
 h['Bx-'].SetMarkerColor(ROOT.kGreen-3)
 h['Bx+'].SetMarkerColor(ROOT.kGreen+3)
 h['By-'].SetMarkerColor(ROOT.kBlue-3)
 h['By+'].SetMarkerColor(ROOT.kBlue+3)
 h['Bz-'].SetMarkerColor(ROOT.kCyan-2)
 h['Bz+'].SetMarkerColor(ROOT.kCyan+2)
 for ix in range(grid[0]):
  for iy in range(grid[1]):
   for iz in range(grid[2]):
    x,y,z = xmin + ix*dx,ymin + iy*dy,zmin + iz*dz
    n = fGeo.FindNode(x,y,z)
    f = n.GetVolume().GetField()
    if f: 
      if f.GetFieldValue()[0]<0:  rc=h['Bx-'].Fill(z,x,y,-f.GetFieldValue()[0]/u.tesla)     
      if f.GetFieldValue()[0]>0:  rc=h['Bx+'].Fill(z,x,y,f.GetFieldValue()[0]/u.tesla)     
      if f.GetFieldValue()[1]<0:  rc=h['By-'].Fill(z,x,y,-f.GetFieldValue()[1]/u.tesla)     
      if f.GetFieldValue()[1]>0:  rc=h['By+'].Fill(z,x,y,f.GetFieldValue()[1]/u.tesla)     
      if f.GetFieldValue()[2]<0:  rc=h['Bz-'].Fill(z,x,y,-f.GetFieldValue()[2]/u.tesla)   
      if f.GetFieldValue()[2]>0:  rc=h['Bz+'].Fill(z,x,y,f.GetFieldValue()[2]/u.tesla)   
    f = run.GetField()
    if f.GetBx(x,y,z)<0: rc=h['Bx-'].Fill(z,x,y,-f.GetBx(x,y,z)/u.tesla) 
    if f.GetBx(x,y,z)>0: rc=h['Bx+'].Fill(z,x,y,f.GetBx(x,y,z)/u.tesla) 
    if f.GetBy(x,y,z)<0: rc=h['By-'].Fill(z,x,y,-f.GetBy(x,y,z)/u.tesla)
    if f.GetBy(x,y,z)>0: rc=h['By+'].Fill(z,x,y,f.GetBy(x,y,z)/u.tesla) 
 for x in h.keys():
  hi = h[x]
  if hi.ClassName()=='TH3F':
   h[x+'_xz']=h[x].Project3D('xy')
   h[x+'_xz'].SetTitle(hi.GetTitle()+' top view')
   h[x+'_yz']=h[x].Project3D('xz')  
   h[x+'_yz'].SetTitle(hi.GetTitle()+' side view')
 for x in h: 
  h[x].SetStats(0)
  h[x].SetMarkerSize(3)
 txt = {'y':[' Up',' Down'],'x':[' Right',' Left']}
 for pol in ['y','x']:
  for p in ['_xz','_yz']:
   cn = 'c'+pol+p
   ut.bookCanvas(h,key=cn,title='field check',nx=1600,ny=1200,cx=1,cy=1)
   h[cn].cd(1)
   h['B'+pol+'+'+p].Draw()
   h['B'+pol+'-'+p].Draw('same')
   h['B'+pol+'L'+p] = ROOT.TLegend(0.79,0.72,0.91,0.87)
   h['B'+pol+'L'+p].AddEntry(h['B'+pol+'+'],'B'+pol+txt[pol][0],'PM')
   h['B'+pol+'L'+p].AddEntry(h['B'+pol+'-'],'B'+pol+txt[pol][1],'PM')
   h['B'+pol+'L'+p].Draw()
   h[cn].Update()
   h[cn].Print('FieldB'+pol+'Proj'+p+'.png')
示例#51
0
def TplotP(sTree):
    ut.bookCanvas(h, key='P', title='momentum', nx=1800, ny=1200, cx=3, cy=2)
    ut.bookCanvas(h, key='>P', title='N >P', nx=1800, ny=1200, cx=3, cy=2)
    ut.bookCanvas(h, key='PT', title='Pt', nx=1800, ny=1200, cx=3, cy=2)
    ut.bookCanvas(h, key='>PT', title='N >Pt', nx=1800, ny=1200, cx=3, cy=2)
    cuts = {
        'mu': 'abs(id)==13',
        'nu': 'abs(id)!=13',
        'mu-': 'id==13',
        'mu+': 'id==-13',
        'nutau': 'id==16',
        'nutaubar': 'id==-16',
        'numu': 'id==14',
        'numubar': 'id==-14',
        'nue': 'id==12',
        'nuebar': 'id==-12',
        'nuesum': 'abs(id)==12',
        'numusum': 'abs(id)==14',
        'nutausum': 'abs(id)==16'
    }
    OpenCharm = {
        '':
        '',
        'charm':
        "&(pythiaid==id & (abs(parentid) == 15 ||  abs(parentid) == 4112 || abs(parentid) == 4122  || abs(parentid) == 4132  \
                         ||  abs(parentid) == 431 || abs(parentid) == 421  || abs(parentid) == 411) )"
    }
    ROOT.gROOT.cd('')
    for x in ['', 'charm']:
        for q in cuts:
            p = q + x
            hn = 'Tp' + p
            hnt = 'Tpt' + p
            ut.bookHist(h, hn, p + ' ;p [GeV] ;N', 400, 0.0, 400.0)
            ut.bookHist(h, hnt, p + ' ;pt [GeV] ;N', 40, 0.0, 4.0)
            sTree.Draw('sqrt(px**2+py**2+pz**2)>>' + hn,
                       'w*(' + cuts[q] + OpenCharm[x] + ')', 'goff')
            sTree.Draw('sqrt(px**2+py**2)>>' + hnt,
                       'w*(' + cuts[q] + OpenCharm[x] + ')', 'goff')
            if q == 'mu+': h[hn].SetLineColor(3)
            if q == 'mu-': h[hn].SetLineColor(4)
# integrated rates
    for q in [
            'mu', 'mu-', 'mu+', 'nu', 'nue', 'nuesum', 'nuebar', 'numusum',
            'numu', 'numubar', 'nutau', 'nutaubar'
    ]:
        for x in ['', 'charm']:
            for z in ['p', 'pt']:
                p = z + q + x
                hi = 'T' + p + '_>E'
                h[hi] = h['T' + p].Clone(hi)
                h[hi].Reset()
                nsum = 0
                for i in range(h[hi].GetNbinsX() + 1, 0, -1):
                    nsum += h['T' + p].GetBinContent(i)
                    h[hi].SetBinContent(i, nsum)
    for z in ['p', 'pt']:
        k = 1
        for x in ['mu', 'nu']:
            t = z.upper()
            p = z + x
            cv = h[t].cd(k)
            cv.SetLogy(1)
            h['T' + p].Draw()
            if h['T' + p].GetEntries() < 1: continue
            if not p.find('mu') < 0:
                h['T' + p + '+'].Draw('same')
                h['T' + p + '-'].Draw('same')
            cv = h['>' + t].cd(k)
            cv.SetLogy(1)
            h[hi].Draw()
            k += 1
# plot different nu species:
        k = 3
        cv = h[t].cd(k)
        cv.SetLogy(1)
        first = True
        i = 2
        h['tlnu' + z + str(k)] = ROOT.TLegend(0.49, 0.13, 0.88, 0.36)
        for p in ['numu', 'numubar', 'nue', 'nuebar', 'nutau', 'nutaubar']:
            hn = 'T' + z + p
            h['tlnu' + z + str(k)].AddEntry(h[hn], z + ' ' + p, 'PL')
            h[hn].SetLineColor(i)
            h[hn + '8'] = h[hn].Clone()
            h[hn + '8'].SetName(hn + '8')
            h[hn + '8'].Rebin(8)
            i += 1
            if first:
                h[hn + '8'].Draw()
                first = False
            h[hn + '8'].Draw('same')
        h['tlnu' + z + str(k)].Draw()
        k += 1
示例#52
0
def makePlot(f, book=True):
    # print interaction and radiation length of target
    sGeo = ROOT.gGeoManager
    if sGeo:
        v = sGeo.FindVolumeFast('target')
        m = v.GetMaterial()
        length = v.GetShape().GetDZ() * 2
        print("Material:", m.GetName(), 'total interaction length=',
              length / m.GetIntLen(), 'total rad length=',
              length / m.GetRadLen())
    else:
        density = 2.413
        length = 125.0
        print("Use predefined values:", density, length)
    if book:
        ut.bookHist(h, 'theta',
                    'scattering angle ' + str(momentum) + 'GeV/c;{Theta}(rad)',
                    500, 0, maxTheta)
        ut.bookHist(h, 'eloss',
                    'rel energy loss as function of momentum GeV/c', 100, 0,
                    maxTheta, 10000, 0., 1.)
        ut.bookHist(h, 'elossRaw', 'energy loss as function of momentum GeV/c',
                    100, 0, maxTheta, 10000, 0., 100.)
    sTree = f.cbmsim
    for n in range(sTree.GetEntries()):
        rc = sTree.GetEvent(n)
        Ein = sTree.MCTrack[0].GetEnergy()
        M = sTree.MCTrack[0].GetMass()
        Eloss = 0
        for aHit in sTree.vetoPoint:
            Eloss += aHit.GetEnergyLoss()
            print(Ein, Eloss / Ein)
        rc = h['eloss'].Fill(Ein, Eloss / Ein)
        rc = h['elossRaw'].Fill(Ein, Eloss)
    ut.bookCanvas(h, key=s, title=s, nx=900, ny=600, cx=1, cy=1)
    tc = h[s].cd(1)
    if s == "NA62":
        h['eloss'].Draw()
        h['95'] = h['eloss'].ProjectionX('95', 96, 100)
        h['95'].Sumw2()
        h['0'] = h['eloss'].ProjectionX('0', 1, 100)
        h['0'].Sumw2()
        rc = h['95'].Divide(h['0'])
        h['95'].Draw()
        h['meanEloss'] = h['elossRaw'].ProjectionX()
        for n in range(1, h['elossRaw'].GetNbinsX() + 1):
            tmp = h['elossRaw'].ProjectionY('tmp', n, n)
            eloss = tmp.GetMean()
            h['meanEloss'].SetBinContent(n, eloss / density / length * 1000)
        h['meanEloss'].SetTitle('mean energy loss MeV cm2 / g')
        h['meanEloss'].Draw()
    elif s == "ATLAS":
        h['eloss'].Draw()
        h['>eloss'] = h['eloss'].ProjectionY().Clone('>eloss')
        cum = 0
        N = float(h['>eloss'].GetEntries())
        for n in range(h['>eloss'].GetNbinsX(), 0, -1):
            cum += h['>eloss'].GetBinContent(n)
            h['>eloss'].SetBinContent(n, cum / N)
        print("Ethreshold   event fraction in %")
        for E in [15., 20., 30., 50., 80.]:
            n = h['>eloss'].FindBin(E / 350.)
            print(" %5.0F   %5.2F " % (E, h['>eloss'].GetBinContent(n) * 100))
    else:
        tc.SetLogy(1)
        h['theta_100'] = h['theta'].Clone('theta_100')
        h['theta_100'] = h['theta'].Rebin(5)
        h['theta_100'].Scale(1. / h['theta_100'].GetMaximum())
        h['theta_100'].Draw()
        h[s].Print(s + '.png')
        h[s].Print(s + '.root')
        f.Write(h['theta'].GetName())
        f.Write(h['theta_100'].GetName())
示例#53
0
def compare():
    test(eospath + 'pythia8_Geant4_onlyMuons.root')
    for x in ['', '_>E']:
        for z in ['p', 'pt']:
            for ahist in [
                    'mu-', 'mu+', 'mu', 'mu-charm', 'mu+charm', 'mucharm'
            ]:
                h['TP' + z + ahist + x] = h['T' + z + ahist +
                                            x].Clone('CT' + ahist + x)
    test(eospath + 'pythia8_Geant4_Yandex_onlyNeutrinos.root')
    for x in ['', '_>E']:
        for z in ['p', 'pt']:
            for ahist in [
                    'numusum', 'nuesum', 'numusumcharm', 'nuesumcharm', 'numu',
                    'numubar', 'nue', 'nuebar', 'numucharm', 'numubarcharm',
                    'nuecharm', 'nuebarcharm'
            ]:
                h['TP' + z + ahist + x] = h['T' + z + ahist +
                                            x].Clone('CT' + ahist + x)
    test(eospath + 'Mbias/pythia8_Geant4-withCharm-ram.root')
    for x in ['', '_>E']:
        for z in ['p', 'pt']:
            t = z.upper()
            if x != '': t = '>' + t
            t1 = h[t].cd(1)
            p = z + 'mu'
            h['T' + p + x].SetTitle('musum')
            h['T' + p + x].Draw()
            h['T' + p + 'charm' + x].Draw('same')
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(6)
            h['TP' + p + 'charm' + x].Draw('same')
            h['TP' + p + 'charm' + x].SetLineColor(3)
            h['T' + p + 'charm' + x].SetLineColor(2)
            h['T' + p + x].SetLineColor(4)
            h['L' + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
            h['L' + p + x].AddEntry(h['T' + p + x],
                                    'muon new with charm, cascade, k-fac',
                                    'PL')
            h['L' + p + x].AddEntry(
                h['T' + p + 'charm' + x],
                'muon from charm new with charm, cascade, k-fac', 'PL')
            h['L' + p + x].AddEntry(h['TP' + p + x],
                                    'muon old CERN-Cracow prod', 'PL')
            h['L' + p + x].AddEntry(h['TP' + p + 'charm' + x],
                                    'muon from charm old CERN-Cracow prod',
                                    'PL')
            h['L' + p + x].Draw()
            h[t].cd(2)
            p = z + 'numusum'
            h['T' + p + x].Draw()
            h['T' + p + 'charm' + x].Draw('same')
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(6)
            h['TP' + p + 'charm' + x].Draw('same')
            h['TP' + p + 'charm' + x].SetLineColor(3)
            h['T' + p + 'charm' + x].SetLineColor(2)
            h['T' + p + x].SetLineColor(4)
            h['L' + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
            h['L' + p + x].AddEntry(h['T' + p + x],
                                    'nu_mu new with charm, cascade, k-fac',
                                    'PL')
            h['L' + p + x].AddEntry(
                h['T' + p + 'charm' + x],
                'nu_mu from charm new with charm, cascade, k-fac', 'PL')
            h['L' + p + x].AddEntry(h['TP' + p + x],
                                    'nu_mu old CERN-Cracow prod', 'PL')
            h['L' + p + x].AddEntry(h['TP' + p + 'charm' + x],
                                    'nu_mu from charm old CERN-Cracow prod',
                                    'PL')
            h['L' + p + x].Draw()
            t3 = h[t].cd(3)
            t3.SetLogy(1)
            p = z + 'nuesum'
            h['T' + p + x].Draw()
            h['T' + p + 'charm' + x].Draw('same')
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(6)
            h['TP' + p + 'charm' + x].Draw('same')
            h['TP' + p + 'charm' + x].SetLineColor(3)
            h['T' + p + 'charm' + x].SetLineColor(2)
            h['T' + p + x].SetLineColor(4)
            h['L' + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
            h['L' + p + x].AddEntry(h['T' + p + x],
                                    'nu_e new with charm, cascade, k-fac',
                                    'PL')
            h['L' + p + x].AddEntry(
                h['T' + p + 'charm' + x],
                'nu_e from charm new with charm, cascade, k-fac', 'PL')
            h['L' + p + x].AddEntry(h['TP' + p + x],
                                    'nu_e old CERN-Cracow prod', 'PL')
            h['L' + p + x].AddEntry(h['TP' + p + 'charm' + x],
                                    'nu_e from charm old CERN-Cracow prod',
                                    'PL')
            h['L' + p + x].Draw()
            #
            t4 = h[t].cd(4)
            t4.SetLogy(1)
            h['Lmuc' + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
            p = z + 'mu-'
            h['T' + p + x].SetTitle('mu-/mu+')
            h['T' + p + x].Draw()
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(6)
            h['T' + p + x].SetLineColor(4)
            h['Lmuc' + z + x].AddEntry(h['T' + p + x],
                                       'mu- new with charm, cascade, k-fac',
                                       'PL')
            h['Lmuc' + z + x].AddEntry(h['TP' + p + x], 'mu- old Yandex prod',
                                       'PL')
            p = z + 'mu+'
            h['T' + p + x].Draw('same')
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(3)
            h['T' + p + x].SetLineColor(2)
            h['Lmuc' + z + x].AddEntry(h['T' + p + x],
                                       'mu+ new with charm, cascade, k-fac',
                                       'PL')
            h['Lmuc' + z + x].AddEntry(h['TP' + p + x], 'mu+ old Yandex prod',
                                       'PL')
            h['Lmuc' + z + x].Draw()
            #
            t5 = h[t].cd(5)
            t5.SetLogy(1)
            h['Lnumu' + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
            p = z + 'numu'
            h['T' + p + x].SetTitle('numu/numubar')
            h['T' + p + x].Draw()
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(6)
            h['T' + p + x].SetLineColor(4)
            h['Lnumu' + z + x].AddEntry(
                h['T' + p + x], 'nu_mu new with charm, cascade, k-fac', 'PL')
            h['Lnumu' + z + x].AddEntry(h['TP' + p + x],
                                        'nu_mu old Yandex prod', 'PL')
            p = z + 'numubar'
            h['T' + p + x].Draw('same')
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(3)
            h['T' + p + x].SetLineColor(2)
            h['Lnumu' + z + x].AddEntry(
                h['T' + p + x], 'anti nu_mu new with charm, cascade, k-fac',
                'PL')
            h['Lnumu' + z + x].AddEntry(h['TP' + p + x],
                                        'anti nu_mu old Yandex prod', 'PL')
            h['Lnumu' + z + x].Draw()
            t6 = h[t].cd(6)
            t6.SetLogy(1)
            p = z + 'nue'
            h['Lnue' + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
            h['T' + p + x].SetTitle('nue/nuebar')
            h['T' + p + x].Draw()
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(6)
            h['T' + p + x].SetLineColor(4)
            h['Lnue' + z + x].AddEntry(h['T' + p + x],
                                       'nu_e new with charm, cascade, k-fac',
                                       'PL')
            h['Lnue' + z + x].AddEntry(h['TP' + p + x], 'nu_e old Yandex prod',
                                       'PL')
            p = z + 'nuebar'
            h['T' + p + x].Draw('same')
            h['TP' + p + x].Draw('same')
            h['TP' + p + x].SetLineColor(3)
            h['T' + p + x].SetLineColor(2)
            h['Lnue' + z + x].AddEntry(
                h['T' + p + x], 'anti nu_e new with charm, cascade, k-fac',
                'PL')
            h['Lnue' + z + x].AddEntry(h['TP' + p + x],
                                       'anti nu_e old Yandex prod', 'PL')
            h['Lnue' + z + x].Draw()
            #
            h[t].Print('comparison' + z + x.replace('_>', '') + '.png')
            h[t].Print('comparison' + z + x.replace('_>', '') + '.pdf')


# make ratio plots
    x = '_>E'
    for z in ['p', 'pt']:
        h[z + 'muRatio' + x] = h['T' + z + 'mu' + x].Clone(z + 'muRatio' + x)
        h[z + 'muRatio' + x].Divide(h['TP' + z + 'mu' + x])
        h[z + 'numuRatio' + x] = h['T' + z + 'numusum' +
                                   x].Clone(z + 'numuRatio' + x)
        h[z + 'numuRatio' + x].Divide(h['TP' + z + 'numusum' + x])
        h[z + 'nueRatio' + x] = h['T' + z + 'nuesum' + x].Clone(z +
                                                                'nueRatio' + x)
        h[z + 'nueRatio' + x].Divide(h['TP' + z + 'nuesum' + x])
    ut.bookCanvas(h, key='ratios', title='ratios', nx=1800, ny=600, cx=2, cy=1)
    n = 1
    for z in ['p', 'pt']:
        h['Lratio' + z + x] = ROOT.TLegend(0.21, 0.74, 0.71, 0.85)
        tc = h['ratios'].cd(n)
        n += 1
        h[z + 'muRatio' + x].SetLineColor(2)
        h[z + 'muRatio' + x].SetMaximum(
            max(h[z + 'muRatio' + x].GetMaximum(),
                h[z + 'numuRatio' + x].GetMaximum()))
        h[z + 'muRatio' + x].SetMinimum(0)
        h[z + 'muRatio' + x].SetStats(0)
        h[z + 'muRatio' + x].Draw()
        h[z + 'numuRatio' + x].SetLineColor(3)
        h[z + 'numuRatio' + x].SetStats(0)
        h[z + 'numuRatio' + x].Draw('same')
        #h[z+'nueRatio'+x].SetLineColor(4)
        #h[z+'nueRatio'+x].Draw('same')
        h['Lratio' + z + x].AddEntry(h[z + 'muRatio' + x],
                                     'muon flux new / old ', 'PL')
        h['Lratio' + z + x].AddEntry(h[z + 'numuRatio' + x],
                                     'nu_mu flux new / old ', 'PL')
        #h['Lratio'+z+x].AddEntry(h[z+'nueRatio'+x],'nu_e flux new / old ','PL')
        h['Lratio' + z + x].Draw()
    h['ratios'].Print('comparisonRatios.png')
    h['ratios'].Print('comparisonRatios.pdf')
示例#54
0
def analyzeConcrete():
 fout = ROOT.TFile('muConcrete.root','recreate')
 h['ntuple'] = ROOT.TNtuple("muons","muon flux concrete","id:px:py:pz:x:y:z:w")
 for m in ['','mu','V0']:
  ut.bookHist(h,'conc_hitz'+m,'concrete hit z '+m,100,-100.,100.)
  ut.bookHist(h,'conc_hitzP'+m,'concrete hit z vs P'+m,100,-100.,100.,100,0.,25.)
  ut.bookHist(h,'conc_hity'+m,'concrete hit y '+m,100,-15.,15.)
  ut.bookHist(h,'conc_p'+m,'concrete hit p '+m,100,0.,300.)
  ut.bookHist(h,'conc_pt'+m,'concrete hit pt '+m,100,0.,10.)
  ut.bookHist(h,'conc_hitzy'+m,'concrete hit zy '+m,100,-100.,100.,100,-15.,15.)
 top = fGeo.GetTopVolume()
 magn = top.GetNode("magyoke_1")
 z0 = magn.GetMatrix().GetTranslation()[2]/u.m
 for fn in fchain:
  f = ROOT.TFile(fn)
  if not f.FindObjectAny('cbmsim'): 
   print 'skip file ',f.GetName() 
   continue
  sTree = f.cbmsim
  nEvents = sTree.GetEntries()
  for n in range(nEvents):
   sTree.GetEntry(n)
   if sTree.MCTrack.GetEntries() > 1: 
      wg = sTree.MCTrack[1].GetWeight() 
   else: 
      wg = sTree.MCTrack[0].GetWeight() 
   for ahit in sTree.vetoPoint:
     detID = ahit.GetDetectorID()
     if logVols[detID] != 'rockD': continue  
     m=''    
     pid = ahit.PdgCode()    
     if abs(pid) == 13: m='mu'
     P = ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2+ahit.GetPz()**2)
     if abs(pid) == 13 and P>3/u.GeV: 
       m='V0'
       h['ntuple'].Fill(float(pid), float(ahit.GetPx()/u.GeV),float(ahit.GetPy()/u.GeV),float(ahit.GetPz()/u.GeV),\
                   float(ahit.GetX()/u.m),float(ahit.GetY()/u.m),float(ahit.GetZ()/u.m),float(wg) )
     h['conc_hitz'+m].Fill(ahit.GetZ()/u.m-z0,wg)
     h['conc_hity'+m].Fill(ahit.GetY()/u.m,wg)
     h['conc_p'+m].Fill(P/u.GeV,wg)
     h['conc_hitzP'+m].Fill(ahit.GetZ()/u.m,P/u.GeV,wg)
     Pt = ROOT.TMath.Sqrt(ahit.GetPx()**2+ahit.GetPy()**2)
     h['conc_pt'+m].Fill(Pt/u.GeV,wg)
     h['conc_hitzy'+m].Fill(ahit.GetZ()/u.m-z0,ahit.GetY()/u.m,wg)
 #
     #start = [ahit.GetX()/u.m,ahit.GetY()/u.m,ahit.GetZ()/u.m]
     #direc = [-ahit.GetPx()/P,-ahit.GetPy()/P,-ahit.GetPz()/P]
     #t = - start[0]/direc[0]
     
 ut.bookCanvas(h,key='Resultsmu',title='muons hitting concrete',nx=1000,ny=600,cx=2,cy=2)  
 ut.bookCanvas(h,key='Results',title='hitting concrete',nx=1000,ny=600,cx=2,cy=2)  
 for m in ['','mu']:
  tc = h['Results'+m].cd(1)
  h['conc_hity'+m].Draw()
  tc = h['Results'+m].cd(2)
  h['conc_hitz'+m].Draw()
  tc = h['Results'+m].cd(3)
  tc.SetLogy(1)
  h['conc_pt'+m].Draw()
  tc = h['Results'+m].cd(4)
  tc.SetLogy(1)
  h['conc_p'+m].Draw()
  fout.cd()
  h['ntuple'].Write()
示例#55
0
def compare():
 test(eospath+'pythia8_Geant4_onlyMuons.root')
 for x in ['','_>E']:
  for z in ['p','pt']:
   for ahist in ['mu-','mu+','mu','mu-charm','mu+charm','mucharm']:
    h['TP'+z+ahist+x]=h['T'+z+ahist+x].Clone('CT'+ahist+x)
 test(eospath+'pythia8_Geant4_Yandex_onlyNeutrinos.root')
 for x in ['','_>E']:
  for z in ['p','pt']:
   for ahist in ['numusum','nuesum','numusumcharm','nuesumcharm','numu','numubar','nue','nuebar','numucharm','numubarcharm','nuecharm','nuebarcharm']:
    h['TP'+z+ahist+x]=h['T'+z+ahist+x].Clone('CT'+ahist+x)
 test(eospath+'Mbias/pythia8_Geant4-withCharm-ram.root')
 for x in ['','_>E']:
  for z in ['p','pt']:
   t = z.upper()
   if x != '' : t='>'+t 
   t1=h[t].cd(1)
   p = z+'mu'
   h['T'+p+x].SetTitle('musum')
   h['T'+p+x].Draw()
   h['T'+p+'charm'+x].Draw('same')
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(6)
   h['TP'+p+'charm'+x].Draw('same')
   h['TP'+p+'charm'+x].SetLineColor(3)
   h['T'+p+'charm'+x].SetLineColor(2)
   h['T'+p+x].SetLineColor(4)
   h['L'+p+x] = ROOT.TLegend(0.33,0.69,0.99,0.94)
   h['L'+p+x].AddEntry(h['T'+p+x],'muon new with charm, cascade, k-fac','PL')
   h['L'+p+x].AddEntry(h['T'+p+'charm'+x],'muon from charm new with charm, cascade, k-fac','PL')
   h['L'+p+x].AddEntry(h['TP'+p+x],'muon old CERN-Cracow prod','PL')
   h['L'+p+x].AddEntry(h['TP'+p+'charm'+x],'muon from charm old CERN-Cracow prod','PL')
   h['L'+p+x].Draw()
   h[t].cd(2)
   p = z+'numusum'
   h['T'+p+x].Draw()
   h['T'+p+'charm'+x].Draw('same')
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(6)
   h['TP'+p+'charm'+x].Draw('same')
   h['TP'+p+'charm'+x].SetLineColor(3)
   h['T'+p+'charm'+x].SetLineColor(2)
   h['T'+p+x].SetLineColor(4)
   h['L'+p+x] = ROOT.TLegend(0.33,0.69,0.99,0.94)
   h['L'+p+x].AddEntry(h['T'+p+x],'nu_mu new with charm, cascade, k-fac','PL')
   h['L'+p+x].AddEntry(h['T'+p+'charm'+x],'nu_mu from charm new with charm, cascade, k-fac','PL')
   h['L'+p+x].AddEntry(h['TP'+p+x],'nu_mu old CERN-Cracow prod','PL')
   h['L'+p+x].AddEntry(h['TP'+p+'charm'+x],'nu_mu from charm old CERN-Cracow prod','PL')
   h['L'+p+x].Draw()
   t3=h[t].cd(3)
   t3.SetLogy(1)
   p = z+'nuesum'
   h['T'+p+x].Draw()
   h['T'+p+'charm'+x].Draw('same')
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(6)
   h['TP'+p+'charm'+x].Draw('same')
   h['TP'+p+'charm'+x].SetLineColor(3)
   h['T'+p+'charm'+x].SetLineColor(2)
   h['T'+p+x].SetLineColor(4)
   h['L'+p+x] = ROOT.TLegend(0.33,0.69,0.99,0.94)
   h['L'+p+x].AddEntry(h['T'+p+x],'nu_e new with charm, cascade, k-fac','PL')
   h['L'+p+x].AddEntry(h['T'+p+'charm'+x],'nu_e from charm new with charm, cascade, k-fac','PL')
   h['L'+p+x].AddEntry(h['TP'+p+x],'nu_e old CERN-Cracow prod','PL')
   h['L'+p+x].AddEntry(h['TP'+p+'charm'+x],'nu_e from charm old CERN-Cracow prod','PL')
   h['L'+p+x].Draw()
#
   t4 = h[t].cd(4)
   t4.SetLogy(1)
   h['Lmuc'+z+x] = ROOT.TLegend(0.33,0.73,0.99,0.94)
   p = z+'mu-'
   h['T'+p+x].SetTitle('mu-/mu+')
   h['T'+p+x].Draw()
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(6)
   h['T'+p+x].SetLineColor(4)
   h['Lmuc'+z+x].AddEntry(h['T'+p+x],'mu- new with charm, cascade, k-fac','PL')
   h['Lmuc'+z+x].AddEntry(h['TP'+p+x],'mu- old Yandex prod','PL')
   p = z+'mu+'
   h['T'+p+x].Draw('same')
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(3)
   h['T'+p+x].SetLineColor(2)
   h['Lmuc'+z+x].AddEntry(h['T'+p+x],'mu+ new with charm, cascade, k-fac','PL')
   h['Lmuc'+z+x].AddEntry(h['TP'+p+x],'mu+ old Yandex prod','PL')
   h['Lmuc'+z+x].Draw() 
#
   t5 = h[t].cd(5)
   t5.SetLogy(1)
   h['Lnumu'+z+x] = ROOT.TLegend(0.33,0.73,0.99,0.94)
   p = z+'numu'
   h['T'+p+x].SetTitle('numu/numubar')
   h['T'+p+x].Draw()
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(6)
   h['T'+p+x].SetLineColor(4)
   h['Lnumu'+z+x].AddEntry(h['T'+p+x],'nu_mu new with charm, cascade, k-fac','PL')
   h['Lnumu'+z+x].AddEntry(h['TP'+p+x],'nu_mu old Yandex prod','PL')
   p = z+'numubar'
   h['T'+p+x].Draw('same')
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(3)
   h['T'+p+x].SetLineColor(2)
   h['Lnumu'+z+x].AddEntry(h['T'+p+x],'anti nu_mu new with charm, cascade, k-fac','PL')
   h['Lnumu'+z+x].AddEntry(h['TP'+p+x],'anti nu_mu old Yandex prod','PL')
   h['Lnumu'+z+x].Draw() 
   t6 = h[t].cd(6)
   t6.SetLogy(1)
   p = z+'nue'
   h['Lnue'+z+x] = ROOT.TLegend(0.33,0.73,0.99,0.94)
   h['T'+p+x].SetTitle('nue/nuebar')
   h['T'+p+x].Draw()
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(6)
   h['T'+p+x].SetLineColor(4)
   h['Lnue'+z+x].AddEntry(h['T'+p+x],'nu_e new with charm, cascade, k-fac','PL')
   h['Lnue'+z+x].AddEntry(h['TP'+p+x],'nu_e old Yandex prod','PL')
   p = z+'nuebar'
   h['T'+p+x].Draw('same')
   h['TP'+p+x].Draw('same')
   h['TP'+p+x].SetLineColor(3)
   h['T'+p+x].SetLineColor(2)
   h['Lnue'+z+x].AddEntry(h['T'+p+x],'anti nu_e new with charm, cascade, k-fac','PL')
   h['Lnue'+z+x].AddEntry(h['TP'+p+x],'anti nu_e old Yandex prod','PL')
   h['Lnue'+z+x].Draw() 
#
   h[t].Print('comparison'+z+x.replace('_>','')+'.png')
   h[t].Print('comparison'+z+x.replace('_>','')+'.pdf')
# make ratio plots
 x = '_>E'
 for z in ['p','pt']:
   h[z+'muRatio'+x]=h['T'+z+'mu'+x].Clone(z+'muRatio'+x)
   h[z+'muRatio'+x].Divide(h['TP'+z+'mu'+x])
   h[z+'numuRatio'+x]=h['T'+z+'numusum'+x].Clone(z+'numuRatio'+x)
   h[z+'numuRatio'+x].Divide(h['TP'+z+'numusum'+x])
   h[z+'nueRatio'+x]=h['T'+z+'nuesum'+x].Clone(z+'nueRatio'+x)
   h[z+'nueRatio'+x].Divide(h['TP'+z+'nuesum'+x])
 ut.bookCanvas(h,key='ratios',title='ratios',nx=1800,ny=600,cx=2,cy=1)
 n = 1
 for z in ['p','pt']:
   h['Lratio'+z+x] = ROOT.TLegend(0.21,0.74,0.71,0.85)
   tc = h['ratios'].cd(n)
   n+=1
   h[z+'muRatio'+x].SetLineColor(2)
   h[z+'muRatio'+x].SetMaximum(max(h[z+'muRatio'+x].GetMaximum(),h[z+'numuRatio'+x].GetMaximum()))
   h[z+'muRatio'+x].SetMinimum(0)
   h[z+'muRatio'+x].SetStats(0)
   h[z+'muRatio'+x].Draw()
   h[z+'numuRatio'+x].SetLineColor(3)
   h[z+'numuRatio'+x].SetStats(0)
   h[z+'numuRatio'+x].Draw('same')
   #h[z+'nueRatio'+x].SetLineColor(4)
   #h[z+'nueRatio'+x].Draw('same')
   h['Lratio'+z+x].AddEntry(h[z+'muRatio'+x],'muon flux new / old ','PL')
   h['Lratio'+z+x].AddEntry(h[z+'numuRatio'+x],'nu_mu flux new / old ','PL')
   #h['Lratio'+z+x].AddEntry(h[z+'nueRatio'+x],'nu_e flux new / old ','PL')
   h['Lratio'+z+x].Draw()
 h['ratios'].Print('comparisonRatios.png')
 h['ratios'].Print('comparisonRatios.pdf')
示例#56
0
def makePlots(nstations):
 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],14:[5,3]}
 ut.bookCanvas(h,key='ResultsI',title='hit occupancies',  nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
 ut.bookCanvas(h,key='ResultsImu',title='hit occupancies',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
 ut.bookCanvas(h,key='ResultsImuV0',title='hit occupancies',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
 ut.bookCanvas(h,key='ResultsII', title='deposited energies',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
 ut.bookCanvas(h,key='ResultsIII',title='track info',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
 ut.bookCanvas(h,key='ResultsIV',title='track info',nx=1100,ny=600*cxcy[nstations][1],cx=cxcy[nstations][0],cy=cxcy[nstations][1])
 ut.bookCanvas(h,key='ResultsV',title='origin info',nx=600,ny=400,cx=1,cy=1)
 txt[0] ='occupancy 1sec 5E13pot '
 h['dummy'].Fill(-1)
 nSpills = len(prefixes)
 for i in histlist:
  tc = h['ResultsI'].cd(i)
  hn = histlist[i] 
  if not h.has_key(hn): continue 
  h[hn].SetStats(0)
  h[hn].Draw('colz')
  txt[i] = '%5.2G'%(h[hn].GetSumOfWeights()/nSpills)
  l[i] = ROOT.TLatex().DrawLatexNDC(0.15,0.85,txt[i])
#
  hn = histlist[i]+'_mu' 
  tc = h['ResultsImu'].cd(i)
  h[hn].SetStats(0)
  h[hn].Draw('colz')
  txt[i+100] = '%5.2G'%(h[hn].GetSumOfWeights()/nSpills)
  l[i+100] = ROOT.TLatex().DrawLatexNDC(0.15,0.85,txt[i+100])
#
  hn = histlist[i]+'_muV0' 
  tc = h['ResultsImuV0'].cd(i)
  h[hn].SetStats(0)
  h[hn].Draw('colz')
  txt[i+200] = '%5.2G'%(h[hn].GetSumOfWeights()/nSpills)
  l[i+200] = ROOT.TLatex().DrawLatexNDC(0.15,0.85,txt[i+200])
#
 for i in histlist:
  tc = h['ResultsII'].cd(i)
  h[histlist[i]+'_E'].Draw('colz')
#
 for i in histlist:
  tc = h['ResultsIII'].cd(i)
  tc.SetLogy(1)
  hn = histlist[i]
  drawBoth('_P',hn)
  hid = h[hn+'_id']
  print 'particle statistics for '+histlist[i]
  for k in range(hid.GetNbinsX()):
   ncont = hid.GetBinContent(k+1)
   pid   = hid.GetBinCenter(k+1) 
   if ncont > 0:
    temp = int(abs(pid)+0.5)*int(pid/abs(pid))
    nm = PDG.GetParticle(temp).GetName() 
    print '%s :%5.2g'%(nm,ncont)
  hid = h[histlist[i]+'_mu_id']
  for k in range(hid.GetNbinsX()):
   ncont = hid.GetBinContent(k+1)
   pid   = hid.GetBinCenter(k+1) 
   if ncont > 0:
    temp = int(abs(pid)+0.5)*int(pid/abs(pid))
    nm = PDG.GetParticle(temp).GetName() 
    print '%s :%5.2g'%(nm,ncont)
#
  tc = h['ResultsV'].cd(1)
  h['origin'].SetStats(0)
  h['origin'].Draw('colz')
#
 for i in histlist:
   tc = h['ResultsIV'].cd(i)
   tc.SetLogy(1)
   hn = histlist[i]
   drawBoth('_OP',hn)
 persistency()
示例#57
0
def TplotP(sTree):
  ut.bookCanvas(h,key='P',title='momentum',nx=1800,ny=1200,cx=3,cy=2)
  ut.bookCanvas(h,key='>P',title='N >P',   nx=1800,ny=1200,cx=3,cy=2)
  ut.bookCanvas(h,key='PT',title='Pt',nx=1800,ny=1200,cx=3,cy=2)
  ut.bookCanvas(h,key='>PT',title='N >Pt',   nx=1800,ny=1200,cx=3,cy=2)
  cuts = {'mu':'abs(id)==13','nu':'abs(id)!=13','mu-':'id==13','mu+':'id==-13',
          'nutau':'id==16','nutaubar':'id==-16','numu':'id==14','numubar':'id==-14',
          'nue':'id==12','nuebar':'id==-12','nuesum':'abs(id)==12','numusum':'abs(id)==14','nutausum':'abs(id)==16'}
  OpenCharm = {'':'','charm':"&(pythiaid==id & (abs(parentid) == 15 ||  abs(parentid) == 4112 || abs(parentid) == 4122  || abs(parentid) == 4132  \
                         ||  abs(parentid) == 431 || abs(parentid) == 421  || abs(parentid) == 411) )"}
  ROOT.gROOT.cd('')
  for x in ['','charm']:
   for q in cuts:
    p = q+x
    hn  = 'Tp'+p
    hnt = 'Tpt'+p
    ut.bookHist(h,hn,  p +' ;p [GeV] ;N',400,0.0,400.0)
    ut.bookHist(h,hnt, p +' ;pt [GeV] ;N',40,0.0,4.0)
    sTree.Draw('sqrt(px**2+py**2+pz**2)>>'+hn,'w*('+cuts[q]+OpenCharm[x]+')','goff')
    sTree.Draw('sqrt(px**2+py**2)>>'+hnt,'w*('+cuts[q]+OpenCharm[x]+')','goff')
    if q=='mu+': h[hn].SetLineColor(3) 
    if q=='mu-': h[hn].SetLineColor(4) 
# integrated rates
  for q in [ 'mu','mu-','mu+','nu','nue','nuesum','nuebar','numusum','numu','numubar','nutau','nutaubar']:
   for x in ['','charm']:
    for z in ['p','pt']:
     p = z+q+x
     hi =  'T'+p+'_>E'
     h[hi]=h['T'+p].Clone(hi)
     h[hi].Reset()
     nsum = 0 
     for i in range(h[hi].GetNbinsX()+1,0,-1):
      nsum+=h['T'+p].GetBinContent(i)
      h[hi].SetBinContent(i,nsum) 
  for z in ['p','pt']: 
   k = 1
   for x in [ 'mu','nu']:
    t=z.upper()
    p=z+x 
    cv = h[t].cd(k)
    cv.SetLogy(1)
    h['T'+p].Draw()
    if h['T'+p].GetEntries()<1: continue
    if not p.find('mu')<0: 
     h['T'+p+'+'].Draw('same')
     h['T'+p+'-'].Draw('same')
    cv = h['>'+t].cd(k)
    cv.SetLogy(1)
    h[hi].Draw()
    k+=1
# plot different nu species:
   k = 3
   cv = h[t].cd(k)
   cv.SetLogy(1)
   first = True
   i = 2
   h['tlnu'+z+str(k)] = ROOT.TLegend(0.49,0.13,0.88,0.36)
   for p in ['numu','numubar','nue','nuebar','nutau','nutaubar']:
    hn = 'T'+z+p 
    h['tlnu'+z+str(k)].AddEntry(h[hn],z+' '+p,'PL')
    h[hn].SetLineColor(i)
    h[hn+'8']=h[hn].Clone()
    h[hn+'8'].SetName(hn+'8')
    h[hn+'8'].Rebin(8)
    i+=1
    if first:
      h[hn+'8'].Draw() 
      first = False
    h[hn+'8'].Draw('same')  
   h['tlnu'+z+str(k)].Draw()
   k+=1
示例#58
0
def makePlots():
    ut.bookCanvas(h,
                  key='ecalanalysis',
                  title='cluster map',
                  nx=800,
                  ny=600,
                  cx=1,
                  cy=1)
    cv = h['ecalanalysis'].cd(1)
    h['ecalClusters'].Draw('colz')
    ut.bookCanvas(h,
                  key='ecalCluster2Track',
                  title='Ecal cluster distances to track impact',
                  nx=1600,
                  ny=800,
                  cx=4,
                  cy=2)
    if h.has_key("ecalReconstructed_dist_mu+"):
        cv = h['ecalCluster2Track'].cd(1)
        h['ecalReconstructed_distx_mu+'].Draw()
        cv = h['ecalCluster2Track'].cd(2)
        h['ecalReconstructed_disty_mu+'].Draw()
    if h.has_key("ecalReconstructed_dist_pi+"):
        cv = h['ecalCluster2Track'].cd(3)
        h['ecalReconstructed_distx_pi+'].Draw()
        cv = h['ecalCluster2Track'].cd(4)
        h['ecalReconstructed_disty_pi+'].Draw()
    if h.has_key("ecalReconstructed_dist_mu-"):
        cv = h['ecalCluster2Track'].cd(5)
        h['ecalReconstructed_distx_mu-'].Draw()
        cv = h['ecalCluster2Track'].cd(6)
        h['ecalReconstructed_disty_mu-'].Draw()
    if h.has_key("ecalReconstructed_dist_pi-"):
        cv = h['ecalCluster2Track'].cd(7)
        h['ecalReconstructed_distx_pi-'].Draw()
        cv = h['ecalCluster2Track'].cd(8)
        h['ecalReconstructed_disty_pi-'].Draw()

    ut.bookCanvas(h,
                  key='strawanalysis',
                  title='Distance to wire and mean nr of hits',
                  nx=1200,
                  ny=600,
                  cx=3,
                  cy=1)
    cv = h['strawanalysis'].cd(1)
    h['disty'].Draw()
    h['distu'].Draw('same')
    h['distv'].Draw('same')
    cv = h['strawanalysis'].cd(2)
    h['meanhits'].Draw()
    cv = h['strawanalysis'].cd(3)
    h['meas2'].Draw()
    ut.bookCanvas(h,
                  key='fitresults',
                  title='Fit Results',
                  nx=1600,
                  ny=1200,
                  cx=2,
                  cy=2)
    cv = h['fitresults'].cd(1)
    h['delPOverPz'].Draw('box')
    cv = h['fitresults'].cd(2)
    cv.SetLogy(1)
    h['prob'].Draw()
    cv = h['fitresults'].cd(3)
    h['delPOverPz_proj'] = h['delPOverPz'].ProjectionY()
    ROOT.gStyle.SetOptFit(11111)
    h['delPOverPz_proj'].Draw()
    h['delPOverPz_proj'].Fit('gaus')
    cv = h['fitresults'].cd(4)
    h['delPOverP2z_proj'] = h['delPOverP2z'].ProjectionY()
    h['delPOverP2z_proj'].Draw()
    fitSingleGauss('delPOverP2z_proj')
    h['fitresults'].Print('fitresults.gif')
    ut.bookCanvas(h,
                  key='fitresults2',
                  title='Fit Results',
                  nx=1600,
                  ny=1200,
                  cx=2,
                  cy=2)
    print('finished with first canvas')
    cv = h['fitresults2'].cd(1)
    h['Doca'].SetXTitle('closest distance between 2 tracks   [cm]')
    h['Doca'].SetYTitle('N/1mm')
    h['Doca'].Draw()
    cv = h['fitresults2'].cd(2)
    h['IP0'].SetXTitle('impact parameter to p-target   [cm]')
    h['IP0'].SetYTitle('N/1cm')
    h['IP0'].Draw()
    cv = h['fitresults2'].cd(3)
    h['HNL'].SetXTitle('inv. mass  [GeV/c2]')
    h['HNL'].SetYTitle('N/4MeV/c2')
    h['HNL'].Draw()
    fitSingleGauss('HNL', 0.9, 1.1)
    cv = h['fitresults2'].cd(4)
    h['IP0/mass'].SetXTitle('inv. mass  [GeV/c2]')
    h['IP0/mass'].SetYTitle('IP [cm]')
    h['IP0/mass'].Draw('colz')
    h['fitresults2'].Print('fitresults2.gif')
    ut.bookCanvas(h,
                  key='vxpulls',
                  title='Vertex resol and pulls',
                  nx=1600,
                  ny=1200,
                  cx=3,
                  cy=2)
    cv = h['vxpulls'].cd(4)
    h['Vxpull'].Draw()
    cv = h['vxpulls'].cd(5)
    h['Vypull'].Draw()
    cv = h['vxpulls'].cd(6)
    h['Vzpull'].Draw()
    cv = h['vxpulls'].cd(1)
    h['Vxresol'].Draw()
    cv = h['vxpulls'].cd(2)
    h['Vyresol'].Draw()
    cv = h['vxpulls'].cd(3)
    h['Vzresol'].Draw()
    ut.bookCanvas(h,
                  key='trpulls',
                  title='momentum pulls',
                  nx=1600,
                  ny=600,
                  cx=3,
                  cy=1)
    cv = h['trpulls'].cd(1)
    h['pullPOverPx_proj'] = h['pullPOverPx'].ProjectionY()
    h['pullPOverPx_proj'].Draw()
    cv = h['trpulls'].cd(2)
    h['pullPOverPy_proj'] = h['pullPOverPy'].ProjectionY()
    h['pullPOverPy_proj'].Draw()
    cv = h['trpulls'].cd(3)
    h['pullPOverPz_proj'] = h['pullPOverPz'].ProjectionY()
    h['pullPOverPz_proj'].Draw()
    ut.bookCanvas(h,
                  key='vetodecisions',
                  title='Veto Detectors',
                  nx=1600,
                  ny=600,
                  cx=5,
                  cy=1)
    cv = h['vetodecisions'].cd(1)
    cv.SetLogy(1)
    h['nrtracks'].Draw()
    cv = h['vetodecisions'].cd(2)
    cv.SetLogy(1)
    h['nrSVT'].Draw()
    cv = h['vetodecisions'].cd(3)
    cv.SetLogy(1)
    h['nrUVT'].Draw()
    cv = h['vetodecisions'].cd(4)
    cv.SetLogy(1)
    h['nrSBT'].Draw()
    cv = h['vetodecisions'].cd(5)
    cv.SetLogy(1)
    h['nrRPC'].Draw()
    #
    print('finished making plots')
示例#59
0
def TplotP(sTree):
    ut.bookCanvas(h, key="P", title="momentum", nx=700, ny=400, cx=2, cy=2)
    ut.bookCanvas(h, key=">P", title="N >P", nx=700, ny=400, cx=2, cy=2)
    cuts = {
        "mu": "abs(id)==13",
        "nu": "abs(id)!=13",
        "mu-": "id==13",
        "mu+": "id==-13",
        "nutau": "id==16",
        "nutaubar": "id==-16",
        "numu": "id==14",
        "numubar": "id==-14",
        "nue": "id==12",
        "nuebar": "id==-12",
    }
    ROOT.gROOT.cd("")
    for p in cuts:
        hn = "Tp" + p
        ut.bookHist(h, hn, p + " ;p [GeV] ;N", 400, 0.0, 400.0)
        h[hn].Sumw2()
        sTree.Draw("sqrt(px**2+py**2+pz**2)>>" + hn, "w*(" + cuts[p] + ")", "goff")
        if p == "mu+":
            h[hn].SetLineColor(3)
        if p == "mu-":
            h[hn].SetLineColor(4)
    # integrated rates
    for p in ["mu", "mu-", "mu+", "nu", "nue", "numu", "numubar", "nutau", "nutaubar"]:
        hi = "Tp" + p + "_>E"
        h[hi] = h["Tp" + p].Clone(hi)
        h[hi].Reset()
        nsum = 0
        for i in range(h[hi].GetNbinsX() + 1, 1, -1):
            nsum += h["Tp" + p].GetBinContent(i)
            h[hi].SetBinContent(i, nsum)
    k = 1
    for p in ["mu", "nu"]:
        cv = h["P"].cd(k)
        cv.SetLogy(1)
        h["Tp" + p].Draw()
        if h["Tp" + p].GetEntries() < 1:
            continue
        if p == "mu":
            h["Tpmu+"].Draw("same")
            h["Tpmu-"].Draw("same")
        cv = h[">P"].cd(k)
        cv.SetLogy(1)
        h[hi].Draw()
        k += 1
    # plot different nu species:
    k = 3
    cv = h["P"].cd(k)
    cv.SetLogy(1)
    first = True
    i = 2
    h["tlnu" + str(k)] = ROOT.TLegend(0.49, 0.13, 0.88, 0.36)
    for p in ["numu", "numubar", "nue", "nuebar", "nutau", "nutaubar"]:
        hn = "Tp" + p
        h["tlnu" + str(k)].AddEntry(h["Tp" + p], p, "PL")
        h[hn].SetLineColor(i)
        h[hn + "8"] = h[hn].Clone()
        h[hn + "8"].SetName(hn + "8")
        h[hn + "8"].Rebin(8)
        i += 1
        if first:
            h[hn + "8"].Draw()
            first = False
        h[hn + "8"].Draw("same")
    h["tlnu" + str(k)].Draw()
    k += 1