diff --git a/elena_ShipAna.py b/elena_ShipAna.py index e0a2f7b..e147c97 100644 --- a/elena_ShipAna.py +++ b/elena_ShipAna.py @@ -109,6 +109,10 @@ leaves = sTree.GetListOfLeaves() names = ut.setAttributes(ev, leaves) +# Correct weights for neutrinos +weightHistFile = ROOT.TFile("../../FairShipTools/histoForWeights.root","read") +weightHist = weightHistFile.Get("h_Gio") + # Get geometry positions nodes = tools.searchForNodes2_xyz_dict(geofile) scintTankW = [nodes["lidT1lisci_1"]['z']['pos']-nodes["lidT1lisci_1"]['z']['dim'], nodes["lidT1lisci_1"]['z']['pos']+nodes["lidT1lisci_1"]['z']['dim']] @@ -124,6 +128,7 @@ print '\t stored some geometry nodes' #print 'ecal pos: ', ecalPos[0] + h = {} #ut.bookHist(h,'delPOverP','delP / P',100,0.,50.,100,-0.5,0.5) #ut.bookHist(h,'delPtOverP','delPt / P',100,0.,50.,100,-0.5,0.5) @@ -340,6 +345,11 @@ elenaTree, DaughtersPt = tools.AddVect(elenaTree, 'DaughtersPt', 'float') elenaTree, DaughtersChi2 = tools.AddVect(elenaTree, 'DaughtersChi2', 'float') elenaTree, DaughtersNPoints = tools.AddVect(elenaTree, 'DaughtersNPoints', 'int') +elenaTree, DaughtersTruthProdX = tools.AddVect(elenaTree, 'DaughtersTruthProdX', 'float') +elenaTree, DaughtersTruthProdY = tools.AddVect(elenaTree, 'DaughtersTruthProdY', 'float') +elenaTree, DaughtersTruthProdZ = tools.AddVect(elenaTree, 'DaughtersTruthProdZ', 'float') +elenaTree, DaughtersTruthPDG = tools.AddVect(elenaTree, 'DaughtersTruthPDG', 'int') +elenaTree, DaughtersTruthMotherPDG = tools.AddVect(elenaTree, 'DaughtersTruthMotherPDG', 'int') elenaTree, DaughtersFitConverged = tools.AddVect(elenaTree, 'DaughtersFitConverged', 'int') elenaTree, straw_x = tools.AddVect(elenaTree, 'straw_x', 'float') elenaTree, straw_y = tools.AddVect(elenaTree, 'straw_y', 'float') @@ -366,9 +376,12 @@ elenaTree, IP0 = tools.AddVar(elenaTree, 'IP0', 'float') elenaTree, Mass = tools.AddVar(elenaTree, 'Mass', 'float') elenaTree, Pt = tools.AddVar(elenaTree, 'Pt', 'float') +elenaTree, HNLw = tools.AddVar(elenaTree, 'HNLw', 'float') +elenaTree, NuWeight = tools.AddVar(elenaTree, 'NuWeight', 'float') def elenaEventLoop(N): - nEvents = min(sTree.GetEntries(),N) + entries = sTree.GetEntries() + nEvents = min(entries,N) for n in range(nEvents): rc = sTree.GetEntry(n) key = -1 @@ -380,6 +393,17 @@ # that the two tracks come from the same MCTrack ! GetDaughter allows to # get back to the underlying tracks, see ShipReco.py: # particle = ROOT.TParticle(9900015,0,-1,-1,t1,t2,HNL,vx) + nu = sTree.MCTrack[0] + if len(sTree.MCTrack) == 1 and len(sTree.Particles) > 0: + print "There is an error somewhere! Particles out of nothing..." + sys.exit() + if len(sTree.MCTrack) < 2: continue + nu_daughter = sTree.MCTrack[1] + if not isinstance(nu_daughter, ROOT.ShipMCTrack): continue + nu_x = nu_daughter.GetStartX(); nu_y = nu_daughter.GetStartY(); nu_z = nu_daughter.GetStartZ() + nu_energy = nu.GetEnergy() + nu_w = tools.calcWeight(nu_x,nu_y,nu_z, nu_energy, nodes, entries, weightHist, file_type) + tools.PutToZero(NuWeight); tools.Push(NuWeight, nu_w) for HNL in sTree.Particles: if signal_file and not (HNL.GetPdgCode() == theHNLcode): continue #if bg_file and (HNL.GetPdgCode() == theHNLcode): continue @@ -403,6 +427,10 @@ tools.PutToZero(DaughtersChi2) tools.PutToZero(DaughtersPt) tools.PutToZero(DaughtersNPoints) + w = sTree.MCTrack[1].GetWeight() + tools.PutToZero(HNLw); tools.Push(HNLw, w) + tools.PutToZero(DaughtersTruthPDG); tools.PutToZero(DaughtersTruthMotherPDG) + tools.PutToZero(DaughtersTruthProdX); tools.PutToZero(DaughtersTruthProdY); tools.PutToZero(DaughtersTruthProdZ); for tr in [t1,t2]: converged = 0 x = sTree.FitTracks[tr] @@ -416,6 +444,9 @@ h['CandidateDaughters-chi2'].Fill(x.getFitStatus().getChi2() / x.getNumPoints()) tools.Push(DaughtersChi2, x.getFitStatus().getChi2()) tools.Push(DaughtersNPoints, x.getNumPoints()) + pdg, mumPdg, truthX, truthY, truthZ = tools.retrieveMCParticleInfo(sTree, tr) + tools.Push(DaughtersTruthPDG, pdg); tools.Push(DaughtersTruthMotherPDG, mumPdg) + tools.Push(DaughtersTruthProdX, truthX); tools.Push(DaughtersTruthProdY, truthY); tools.Push(DaughtersTruthProdZ, truthZ); xv,yv,zv,doca = myVertex(t1,t2,PosDir) h['Candidate-DOCA'].Fill(doca) tools.PutToZero(DOCA); tools.Push(DOCA, doca) @@ -486,4 +517,5 @@ ofile = ROOT.TFile(outputFile, "update") elenaTree.Write() ofile.Close() -print "\tOutput saved to ", outputFile \ No newline at end of file +weightHistFile.Close() +print "\tOutput saved to ", outputFile