Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:11

0001 #!/usr/bin/env python3
0002 
0003 import sys
0004 import os
0005 from ROOT import gROOT, TArrow, TCanvas, TGraph, TH2Poly, gPad, TLatex
0006 from copy import deepcopy
0007 from array import array
0008 
0009 gROOT.SetBatch() # don't pop up canvases
0010 
0011 maxPxBarrel = 4
0012 maxPxForward = 3
0013 barrelLadderShift = [0, 14, 44, 90]
0014 forwardDiskXShift = [25, 75, 125]
0015 forwardDiskYShift = 45; # to make +DISK on top in the 'strip-like' layout
0016 plotWidth, plotHeight = 3000, 2000
0017 listOfDetids=[]
0018 
0019 ##############################################
0020 #Find Data files
0021 def getFileInPath(rfile):
0022 ##############################################
0023    import os 
0024    for dir in os.environ['CMSSW_SEARCH_PATH'].split(":"):
0025      if os.path.exists(os.path.join(dir,rfile)): return os.path.join(dir,rfile)                                                                          
0026    return None
0027 
0028 ##############################################
0029 def __AddNamedBins(BaseTrackerMap, geoFile, tX, tY, sX, sY, applyModuleRotation = False):
0030 ##############################################
0031     for line in geoFile:
0032         lineSpl = line.strip().split("\"")
0033       
0034         detId = lineSpl[0].split(" ")[0]
0035       
0036         vertices = lineSpl[1]
0037         xy = vertices.split(" ")
0038         x, y = array('d'), array('d')
0039         verNum = 1
0040         for coord in xy:
0041             coordSpl = coord.split(",")
0042             if applyModuleRotation:
0043                 x.append(-(float(coordSpl[0]) * sX + tX))
0044                 y.append((float(coordSpl[1]) * sY + tY))
0045             else:
0046                 x.append(float(coordSpl[0]) * sX + tX)
0047                 y.append(float(coordSpl[1]) * sY + tY)
0048             verNum = verNum + 1
0049             #close polygon
0050         x.append(x[0])
0051         y.append(y[0])
0052       
0053         #print(detId, [p for p in x], [q for q in y])
0054         listOfDetids.append(detId)
0055         if applyModuleRotation:
0056             bin = TGraph(verNum, y, x)
0057         else:
0058             bin = TGraph(verNum, x, y)
0059             # bin = TGraph(verNum, y, x) # rotation by 90 deg (so that it had the same layout as for the strips)
0060         bin.SetName(detId)
0061         BaseTrackerMap.AddBin(bin)
0062 
0063 ##############################################
0064 def main():
0065 ##############################################
0066     geometryFilenames = []
0067     for i in range(maxPxBarrel):
0068         geometryFilenames.append(getFileInPath("DQM/SiStripMonitorClient/data/Geometry/vertices_barrel_" + str(i + 1))) 
0069 
0070     for i in range(-maxPxForward, maxPxForward + 1):
0071         if i == 0:
0072             continue #there is no 0 disk
0073         geometryFilenames.append(getFileInPath("DQM/SiStripMonitorClient/data/Geometry/vertices_forward_" + str(i)))
0074 
0075     BaseTrackerMap = TH2Poly("Summary", "", -10, 160, -70, 70)
0076     BaseTrackerMap.SetFloat(1)
0077     BaseTrackerMap.GetXaxis().SetTitle("")
0078     BaseTrackerMap.GetYaxis().SetTitle("")
0079     BaseTrackerMap.SetOption("COLZ L")
0080     BaseTrackerMap.SetStats(0)
0081   
0082     # BARREL FIRST
0083     for i in range(maxPxBarrel):
0084        with open(geometryFilenames[i], "r") as geoFile:
0085           currBarrelTranslateX = 0
0086           currBarrelTranslateY = barrelLadderShift[i]
0087           __AddNamedBins(BaseTrackerMap,geoFile, currBarrelTranslateX, currBarrelTranslateY, 1, 1, True)
0088 
0089     # MINUS FORWARD
0090     for i in range(-maxPxForward, 0):
0091         with open(geometryFilenames[maxPxBarrel + maxPxForward + i], "r") as geoFile:
0092             currForwardTranslateX = forwardDiskXShift[-i - 1]
0093             currForwardTranslateY = -forwardDiskYShift        
0094             __AddNamedBins(BaseTrackerMap,geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1)
0095         
0096     # PLUS FORWARD
0097     for i in range(maxPxForward):
0098         with open(geometryFilenames[maxPxBarrel + maxPxForward + i], "r") as geoFile:
0099             currForwardTranslateX = forwardDiskXShift[i]
0100             currForwardTranslateY = forwardDiskYShift
0101             __AddNamedBins(BaseTrackerMap,geoFile, currForwardTranslateX, currForwardTranslateY, 1, 1)
0102        
0103     print("Base Tracker Map: constructed")
0104 
0105     c1 = TCanvas("c1","c1", plotWidth , plotHeight)
0106     for detid in listOfDetids:
0107        BaseTrackerMap.Fill(str(detid),int(detid))
0108     BaseTrackerMap.Draw("AC COLZ L")        
0109               
0110     gPad.Update()
0111     palette = BaseTrackerMap.FindObject("palette");
0112     palette.SetX1NDC(0.89);
0113     palette.SetX2NDC(0.91);
0114     palette.SetLabelSize(0.05);
0115     gPad.Update()
0116 
0117     ### z arrow
0118     arrow = TArrow(0.05, 27.0, 0.05, -30.0, 0.02, "|>")
0119     arrow.SetLineWidth(4)
0120     arrow.Draw()
0121     ### phi arrow
0122     phiArrow = TArrow(0.0, 27.0, 30.0, 27.0, 0.02, "|>")
0123     phiArrow.SetLineWidth(4)
0124     phiArrow.Draw()
0125     ### x arrow
0126     xArrow = TArrow(25.0, 44.5, 50.0, 44.5, 0.02, "|>")
0127     xArrow.SetLineWidth(4)
0128     xArrow.Draw()
0129     ### y arrow
0130     yArrow = TArrow(25.0, 44.5, 25.0, 69.5, 0.02, "|>")
0131     yArrow.SetLineWidth(4)
0132     yArrow.Draw()
0133 
0134     ###################################################
0135     # add some captions
0136     txt = TLatex()
0137     txt.SetNDC()
0138     txt.SetTextFont(1)
0139     txt.SetTextColor(1)
0140     txt.SetTextAlign(22)
0141     txt.SetTextAngle(0)
0142 
0143     # draw new-style title
0144     txt.SetTextSize(0.05)
0145     txt.DrawLatex(0.5, 0.95, "Pixel Tracker Map")
0146     txt.SetTextSize(0.03)
0147     txt.DrawLatex(0.5, 0.125, "-DISK")
0148     txt.DrawLatex(0.5, 0.075, "NUMBER ->")
0149     txt.DrawLatex(0.5, 0.875, "+DISK")
0150     txt.DrawLatex(0.12, 0.35, "+z")
0151     txt.DrawLatexNDC(0.315, 0.665, "+phi") # WAY TO FORCE IT TO DRAW LATEX CORRECTLY NOT FOUND ('#' DOESN'T WORK)
0152     txt.DrawLatex(0.38, 0.73, "+x")
0153     txt.DrawLatex(0.235, 0.875, "+y")
0154     txt.SetTextAngle(90)
0155     txt.DrawLatex(0.125, 0.5, "BARREL")
0156 
0157     #save to the png
0158     c1.Print("test.png")
0159 
0160 ##################################################
0161 if __name__ == "__main__":        
0162     main()