589 """History of variable what vs LB or time."""
590 ROOT.gStyle.SetOptStat(0)
591 if options.ave:
592 calc = BeamSpotAverage([what],weightedAverage=not options.simpleaverage)
593 grDict = {}
594
595 arescale = varDef(what,'arescale',1.0)
596 for b in nt:
597 if b.sigmaX < 0.01 or b.sigmaY < 0.01:
598 print ("OUTLIER ", b.run, b.lbStart, b.lbEnd, b.sigmaX, b.sigmaY)
599 if not b.bcid in grDict:
600 grDict[b.bcid] = BeamSpotGraph(timeAxis=options.timeaxis, separationAxis=options.separation)
601
602
603 grDict[b.bcid].
add(b,what,arescale)
604 if options.ave:
605 calc.add(b)
606
607 print ('Plotting data from %i BCID ...\n' % len(grDict))
608
609
610 xmin = 1E10
611 xmax = -1E10
612 ymin = 1E10
613 ymax = -1E10
614 for gr in [grDict.get(bcid) for bcid in grDict]:
615 xmin =
min(xmin,gr.xmin)
616 xmax =
max(xmax,gr.xmax)
617 ymin =
min(ymin,gr.ymin)
618 ymax =
max(ymax,gr.ymax)
619
620
621 if xmin>xmax:
622 xmin,xmax=0,1
623 if ymin>ymax:
624 ymin,ymax=0,1
625
626 h = (xmax-xmin)
627 xmax += .05*h if len(grDict)==1 else 0.3*h
628 xmin -= .05*h
629 h = (ymax-ymin)/2*options.yscale
630 ymax += 1.3*h
631 ymin -= 0.5*h
632 if options.xmin!=None:
633 xmin = time.mktime(time.strptime(options.xmin,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmin)
634 if options.xmax!=None:
635 xmax = time.mktime(time.strptime(options.xmax,'%b %d %H:%M:%S %Y')) if options.timeaxis else float(options.xmax)
636 if options.ydef:
637 ymin = varDef(what,'min',-100)
638 ymax = varDef(what,'max',+100)
639 if options.ymin!=None:
640 ymin = options.ymin
641 if options.ymax!=None:
642 ymax = options.ymax
643
644
645 if options.timeaxis:
646 atit = ';%s;%s' % (timeLabel,varDef(what,'atit',what))
647 elif options.separation:
648 atit = ';%s;%s' % ('Nominal Separation [mm]',varDef(what,'atit',what))
649 else:
650 atit = ';%s;%s' % ('Luminosity block number',varDef(what,'atit',what))
652 if options.logy:
653 ROOT.gPad.SetLogy(options.logy)
654 if options.timeaxis:
655 xAxis = frame.GetXaxis()
656 yAxis = frame.GetYaxis()
657 xAxis.SetTimeDisplay(1)
658
659
660
661
662 xAxis.SetTimeOffset(0)
663
664 if (xmax-xmin)/86400 < 1:
665 xAxis.SetTimeFormat('%H:%M')
666 else:
667
668
669
670
671 if options.public:
672 xAxis.SetTimeFormat('%b %d')
673 else:
674 xAxis.SetTimeFormat('#splitline{%b %d}{%H:%M}')
675 xAxis.SetLabelOffset(0.02)
676 xAxis.SetTitleOffset(1.6)
677 if options.lsize:
678 xAxis.SetLabelSize(options.lsize)
679 xAxis.SetTitleSize(options.lsize)
680 yAxis.SetLabelSize(options.lsize)
681 yAxis.SetTitleSize(options.lsize)
682 else:
683 xAxis.SetLabelSize(0.044)
684 if options.adatefmt:
685 xAxis.SetTimeFormat(options.adatefmt)
686 if options.ndivs:
687 xAxis.SetNdivisions(options.ndivs,0)
688 frame.LabelsOption('d','X')
689
690 if options.xtitoffset:
691 xAxis.SetTitleOffset(options.xtitoffset)
692 if options.ytitoffset:
693 yAxis.SetTitleOffset(options.ytitoffset)
694
695 legendList = []
696
697
698 if options.ave:
699 calc.average()
700 dx = (xmax-xmin)/30
701 mean = calc.ave[0]
702 if options.rms:
703 error = calc.rms[0]
704 else:
705 error = calc.err[0]
707 legendList.append([b,options.alegend,'FL'])
708 legendList.append([None,'%s %s #pm %s %s' % (fmtVal(what,mean,True),varDef(what,'units'),
709 fmtVal(what,error,True),varDef(what,'units')),''])
710
711
713 for bcid in sorted(grDict.keys()):
714 gr = grDict[bcid]
715
716
717 name = what if bcid==0 else '%s-bcid%04i' % (what,bcid)
718 tgraph = self.protect( gr.getTGraph(name) )
719 if not tgraph:
720 continue
721 if options.tgraphfile:
722 print ('Saving TGraphErrors',tgraph.GetName(),'to file',options.tgraphfile)
723 tgraphfile = ROOT.TFile(options.tgraphfile,'UPDATE')
724 tgraph.Write()
725 tgraphfile.Close()
726
727
728 if len(grDict)==1:
729 tgraph.SetMarkerSize(options.msize if options.msize else 0.8)
730 if options.plegend:
731 legendList.append([tgraph,options.plegend,'PLE'])
732 else:
733 tgraph.SetMarkerColor(styleFactory.nextColorStyle())
734 tgraph.SetMarkerStyle(styleFactory.nextMarkerStyle())
735 tgraph.SetMarkerSize(options.msize if options.msize else 1.2)
736 if len(legendList)<options.maxlegends:
737 text = 'All' if bcid==0 else 'BCID %i' % bcid
738 legendList.append([tgraph,text,'PLE'])
739 tgraph.Draw('P')
740
741
742 if len(grDict)>options.maxlegends:
743 legendList.append([None,'...',''])
744
745
746 if options.fit and len(grDict)==1:
747 ROOT.gStyle.SetOptFit(1111)
748 legendList = []
749 tgraph.Fit(options.fit,'','SAME', gr.xmin,gr.xmax)
750
751
752 legendX = 0.6 if len(grDict)==1 else 0.8
753 self.writeText(what,legendList if not options.public else [],not options.public,legendX=legendX)
754