Re: reconstructed variables

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 22 Sep 2010 15:49:34 -0500


  Hi Michelle,

There are 3 major problems. You have:

{

    Float_t px2,py2,pz2,p2,p,E;
    Float_t phi,theta,zen,azi,varzen,varazi,priphi,pritheta;
    Float_t varzenm,varazim,varp,vart;

    oldtree->Branch("px2",&px2,"px2/F");     ...
}

...
  TTree *newtree = oldtree->CloneTree();

The extra '{' and '}' means that variable 'px2','py2' all go out of scope then reaching the '}' which is before you need to use them (during the cloning). This is likely the cause of:

   "because it doesn't recognize the variables"

Using SetAlias is not doing what you want in you case. Literaly SetAlias records that when ever TTree::Draw see the target string (for example 'px2') it should replace it with the alias (for example "particle..Px*particle..Px") and thus TTree::Draw will indeed get the right value for px2 .... but only by reading particle..Px and multiplying it. BUT whenever you access the variable directly, you would get zeros since you never assigned any value to them (well actually because of the variable going out of scope you actually assign random value).

Calling: TTree *newtree = oldtree->CloneTree(); makes an exact copy of the original TTree (well plus branches with zeros/random value in them) and does not give you a chance to update add the values.

Instead you the code below ... plus setting the addresses on the oldtree of the data you need to load it (you probably will need particle object and a shower object).

Cheers,
Philippe.

void ct() {

    TFile *oldfile = new TFile("/home/michelle/Desktop/corsika-6900/run/DAT000265.root");     TTree*oldtree = (TTree*)oldfile->Get("sim");

    oldtree->SetBranchStatus("*",0);
    oldtree->SetBranchStatus("particle..Px",1);
    oldtree->SetBranchStatus("particle..Py",1);
    oldtree->SetBranchStatus("particle..Pz",1);
    oldtree->SetBranchStatus("shower.nMuons",1);
    oldtree->SetBranchStatus("shower.Theta",1);
    oldtree->SetBranchStatus("shower.Phi",1);

    //Create a new file + a clone of old tree in new file     TFile *newfile = new TFile("small.root","recreate");     TTree *newtree = oldtree->CloneTree(0); // Only copy the structure for now.

    Float_t px2,py2,pz2,p2,p,E;
    Float_t phi,theta,zen,azi,varzen,varazi,priphi,pritheta;
    Float_t varzenm,varazim,varp,vart;

    newtree->Branch("px2",&px2,"px2/F");
    newtree->Branch("py2",&py2,"px2/F");
    newtree->Branch("pz2",&pz2,"px2/F");
    newtree->Branch("p2",&p2,"p2/F");
    newtree->Branch("p",&p,"p/F");
    newtree->Branch("E",&E,"E/F");
    newtree->Branch("phi",&phi,"phi/F");
    newtree->Branch("theta",&theta,"theta/F");
    newtree->Branch("vart",&vart,"vart/F");
    newtree->Branch("varp",&varp,"varp/F");
    newtree->Branch("zen",&zen,"zen/F");
    newtree->Branch("azi",&azi,"azi/F");
    newtree->Branch("pritheta",&pritheta,"pritheta/F");
    newtree->Branch("priphi",&priphi,"priphi/F");
    newtree->Branch("varzen",&varzen,"varzen/F");
    newtree->Branch("varazi",&varazi,"varazi/F");
    newtree->Branch("varzenm",&varzenm,"varzenm/F");     newtree->Branch("varazim",&varazim,"varazim/F");

    Long64_t nentries = oldtree->GetEntries();     for (Int_t i=0;i<nentries; i++) {

       oldtree->GetEntry(i);
       ... here set of the value correctly ....
       px2 =
       newtree->Fill();

    }

    newtree->Print();
    newfile->Write();
    delete oldfile;
    delete newfile;
}

On 9/22/10 3:30 PM, Michelle Mesquita Medeiros wrote:

> Hello ROOTers,
>
> I am trying to create a new file containing  variables from a file I already have. I'm putting in this new file only the variables 
> I need and I'm trying to put some reconstructed variables too. My script (attached) executes and the original variables are OK, 
> but when I look into those reconstructed variables, they aren't filled, that means it returns zero for all of them, although they 
> have 1000 entries. I think that the expressions for those variables aren't being read. Anybody know what am I doing wrong?
>
> I also tried
> "for (Int_t i = 0; i<nentries; i++) {
>    T.GetEntry(i);"
>
> instead of using SetAlias. But when I do this, the scripts does not execute completely because it doesn't recognize the variables 
> I already have in the expression of the reconstructed variables. For example "particle..Px".
>
> Thank you,
>
> Michelle.
>
>
Received on Wed Sep 22 2010 - 22:49:40 CEST

This archive was generated by hypermail 2.2.0 : Thu Sep 23 2010 - 05:50:01 CEST