Apply weight to each events

i went through Event-by-event weighting and saving as a branch at TTree - #3 by saurm but it doesnt seem like a good example

Long64_t nentries = tree1->GetEntries(); //get total number of enteries
 for(Long64_t i=0; i< nentries; i++){ // loop over all of them
	 tree1->GetEntry(i); // Load the data for TTree entry number "i" from branch
	 D_ETA_w = D_ETA * weight;
	 newb->Fill();

i dont understand how

tree1->GetEntry(i);

correlates with

D_ETA_w = D_ETA * weight;

also in this case it draws the tree, but n my case i want to weight each event, so im not sure what variable is should fill in,
h->Fill(variable, weight)
and stack the histograms,

do you have any suggestion how i may fix this?
thankyou!