def harvesttree(textfile=''): filename, description = treedescription() tree = TTree('tree', 'data from ascii file') if len(textfile) > 0: nlines = tree.ReadFile(textfile, description) elif len(filename) > 0: nlines = tree.ReadFile(filename, description) else: print 'WARNING: file name is empty. No tree is read.' tree.SetMarkerStyle(8) tree.SetMarkerSize(0.5) return tree
def saveConstants(detector, file): from ROOT import TFile from ROOT import TTree from ROOT import gROOT from ROOT import AddressOf f = TFile(file, 'RECREATE') t = TTree('Corrections', 'Corrections') gROOT.ProcessLine(\ "struct MyStruct{\ Int_t index;\ Int_t type;\ Int_t bec;\ Int_t layer;\ Int_t sector;\ Int_t ring;\ Int_t hits;\ Double_t tx;\ Double_t ty;\ Double_t tz;\ Double_t rx;\ Double_t ry;\ Double_t rz;\ Double_t etx;\ Double_t ety;\ Double_t etz;\ Double_t erx;\ Double_t ery;\ Double_t erz;\ };" ) from ROOT import MyStruct # Create branches in the tree s = MyStruct() t.Branch('index', AddressOf(s, 'index'), 'index/I') t.Branch('type', AddressOf(s, 'type'), 'type/I') t.Branch('bec', AddressOf(s, 'bec'), 'bec/I') t.Branch('layer', AddressOf(s, 'layer'), 'layer/I') t.Branch('sector', AddressOf(s, 'sector'), 'sector/I') t.Branch('ring', AddressOf(s, 'ring'), 'ring/I') t.Branch('hits', AddressOf(s, 'hits'), 'hits/I') t.Branch('tx', AddressOf(s, 'tx'), 'tx/D') t.Branch('ty', AddressOf(s, 'ty'), 'ty/D') t.Branch('tz', AddressOf(s, 'tz'), 'tz/D') t.Branch('rx', AddressOf(s, 'rx'), 'rx/D') t.Branch('ry', AddressOf(s, 'ry'), 'ry/D') t.Branch('rz', AddressOf(s, 'rz'), 'rz/D') t.Branch('etx', AddressOf(s, 'etx'), 'etx/D') t.Branch('ety', AddressOf(s, 'ety'), 'ety/D') t.Branch('etz', AddressOf(s, 'etz'), 'etz/D') t.Branch('erx', AddressOf(s, 'erx'), 'erx/D') t.Branch('ery', AddressOf(s, 'ery'), 'ery/D') t.Branch('erz', AddressOf(s, 'erz'), 'erz/D') t.SetMarkerStyle(20) #print detector for i in range(detector.nModules()): detector.GetModule(i) s.index = i if "Pixel" in detector.GetModule(i).Det: det = 1 elif "SCT" in detector.GetModule(i).Det: det = 2 elif "TRT" in detector.GetModule(i).Det: det = 3 else: det = 0 s.type = det if "Barrel" in detector.GetModule(i).BarrelEC: bec = 0 elif "EndCapA" in detector.GetModule( i).BarrelEC or "EndcapA" in detector.GetModule(i).BarrelEC: bec = -1 elif "EndCapC" in detector.GetModule( i).BarrelEC or "EndcapC" in detector.GetModule(i).BarrelEC: bec = 1 else: bec = 999 s.bec = bec s.layer = int(detector.GetModule(i).Layer) s.sector = int(detector.GetModule(i).PhiModule) s.ring = int(detector.GetModule(i).EtaModule) s.hits = int(detector.GetModule(i).Hits) s.tx = detector.GetModule(i).Tx s.ty = detector.GetModule(i).Ty s.tz = detector.GetModule(i).Tz s.rx = detector.GetModule(i).Rx s.ry = detector.GetModule(i).Ry s.rz = detector.GetModule(i).Rz s.bx = detector.GetModule(i).Bx s.etx = detector.GetModule(i).ETx s.ety = detector.GetModule(i).ETy s.etz = detector.GetModule(i).ETz s.erx = detector.GetModule(i).ERx s.ery = detector.GetModule(i).ERy s.erz = detector.GetModule(i).ERz s.ebx = detector.GetModule(i).EBx t.Fill() f.Write() f.Close()