Using more than one ROOT TBranch to store undistorted sim particles


{
    
    PUtils::SetSeed(123); 
    PReaction my_reaction("_T1 = 2.2", "p", "p", "p p w [e+ e-]", "w_multiple_branches");
    //for syntax see parse_eta.C

    //save particles on a new branch, called "particles_stage1":
    my_reaction.Do("foreach(*); [*]->Push(Branch(particles_stage1))");

    //apply a filter (keeping the w out):
    my_reaction.Do("loop: theta_ep = ([*]->Theta() * 180.)/TMath::Pi()");
    my_reaction.Do("theta_em = ([*]->Theta() * 180.)/TMath::Pi()");
    my_reaction.Do("if ((theta_ep<18 || theta_ep>85 || theta_em<18 || theta_em>85) && ![*]->HasID(w.pid)); [*]->SetInActive(); ");
    my_reaction.Do("formore(*); goto loop;");

    //reconstruct w, which "survived" the filter
    my_reaction.Do("[w]->SetM(([e+]+[e-])->M()); else; [w]->SetInActive();");

    //save particles on a new branch, called "particles_stage2", before doing the smearing:
    my_reaction.Do("foreach(*); [*]->Push(Branch(particles_stage2))");

    //10% momentum resolution:
    my_reaction.Do("foreach(*); mom = [*]->P(); newmom = sampleGaus(mom,0.1*mom);[*]->SetMom(newmom);");

    //reconstruct w, after smearing:
    my_reaction.Do("[w]->SetM( ([e+]+[e-])->M() );");

    my_reaction.Print();   //The "Print()" statement is optional
    my_reaction.Loop(1000);

#if 0
    //root -l w_multiple_branches.root
    data->Draw("particles_stage1.M() >> htemp1","particles_stage1.ID() == 52");
    htemp1->SetLineColor(1);
    data->Draw("particles_stage2.M() >> htemp2","particles_stage2.ID() == 52","same");
    htemp2->SetLineColor(2);
    data->Draw("Particles.M() >> htemp3","Particles.ID() == 52","same");
#endif

}
 multiple_branches.C:1
 multiple_branches.C:2
 multiple_branches.C:3
 multiple_branches.C:4
 multiple_branches.C:5
 multiple_branches.C:6
 multiple_branches.C:7
 multiple_branches.C:8
 multiple_branches.C:9
 multiple_branches.C:10
 multiple_branches.C:11
 multiple_branches.C:12
 multiple_branches.C:13
 multiple_branches.C:14
 multiple_branches.C:15
 multiple_branches.C:16
 multiple_branches.C:17
 multiple_branches.C:18
 multiple_branches.C:19
 multiple_branches.C:20
 multiple_branches.C:21
 multiple_branches.C:22
 multiple_branches.C:23
 multiple_branches.C:24
 multiple_branches.C:25
 multiple_branches.C:26
 multiple_branches.C:27
 multiple_branches.C:28
 multiple_branches.C:29
 multiple_branches.C:30
 multiple_branches.C:31
 multiple_branches.C:32
 multiple_branches.C:33
 multiple_branches.C:34
 multiple_branches.C:35
 multiple_branches.C:36
 multiple_branches.C:37
 multiple_branches.C:38
 multiple_branches.C:39
 multiple_branches.C:40
 multiple_branches.C:41
 multiple_branches.C:42