bshi
                
              
                
              
                  
                  
              1
              
             
            
              Dear experts,
I am trying to perform a fit to a sWeighted data while the information of fit variable and sWeight factor are stored in different root files.
Here is what I did.
 TFile *input_root_1 = new TFile(filename);
 TTree *tree1 = (TTree*)input_root_1->Get("DecayTree");
 
 TFile *input_root_2 = new TFile(sweight_file);
 TTree *tree2 = (TTree*)input_root_2->Get("DecayTree");
  tree1->AddFriend(tree2); 
  ....
  RooDataSet data_sw("data_sw", "ipchi", tree1, RooArgSet(ipchi),0, "sig_sw");
where “ipchi” is the fit variable and “sig_sw” is the weight factor I want to input.
But there is an warning shows “designated weight variable sig_sw not found in set of variables, no weighting will be assigned”
How can I fix it?
Thanks.
Boan
             
            
              
              
              
            
            
           
          
            
              
                Axel
                
              
              
                  
                  
              2
              
             
            
              @jonas could you have a look here?
             
            
              
              
              
            
            
           
          
            
              
                jonas
                
              
              
                  
                  
              3
              
             
            
              Hi @bshi, welcome to the ROOT forum!
You need to create a dummy weight variable explicitly that you are passing to the set of variables in the RooDataSet constructor:
  RooRealVar sig_sw{"sig_sw", "", 1.0};
  RooDataSet data_sw("data_sw", "ipchi", tree1, RooArgSet(ipchi, sig_sw),0, "sig_sw");
However, what you did would work in ROOT 6.28.00 onward, where the weight variable is created implicitly once you pass a weight name 
Hope this helps!
Cheers,
Jonas
             
            
              
              
              
            
            
           
          
            
              
                bshi
                
              
              
                  
                  
              4
              
             
            
              Thank you, Jonas.
Sorry for missing two points.
First, my ROOT is 6.18.
Second, I have created a weight variable explicitly.
Here is my more complete code.
’
TFile *input_root_1 = new TFile(filename);
TTree tree1 = (TTree)input_root_1->Get(“DecayTree”);
TFile *input_root_2 = new TFile(sweight_file);
TTree tree2 = (TTree)input_root_2->Get(“DecayTree”);
Double_t xmin=-6, xmax=9;
RooRealVar ipchi(“TMath::log(D_IPCHI2_OWNPV)”, “ipchi”, xmin, xmax);
RooRealVar* mass_weight = new RooRealVar(“sig_sw”, “sig_sw”, -5, 5);
RooDataSet data_sw(“data_sw”, “ipchi”, tree1, RooArgSet(ipchi),0, “sig_sw”);
…
’
With best respect,
Boan
             
            
              
              
              
            
            
           
          
            
              
                jonas
                
              
              
                  
                  
              5
              
             
            
              Please use newer ROOT versions, there are many bugfixes and improvements 
And, as I said, you have to pass your weight variable also to the RooDataSet constructor:
 RooDataSet data_sw(“data_sw”, “ipchi”, tree1, RooArgSet(ipchi, *mass_weight),0, “sig_sw”);
             
            
              
              
              
            
            
           
          
            
              
                bshi
                
              
              
                  
                  
              6
              
             
            
              OK. Thanks for your answer. 
             
            
              
              
              
            
            
           
          
            
              
                system
                
                  Closed 
              
              
                  
                  
              7
              
             
            
              This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.