Set energy 0 in a sum

Dear all,
I’ve built an energy sum plot having some conditions in this way:

TString heneossstring = TString::Format("Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] >> htemp(16000., 0., 16000.)", b,c,c2,d,e,f,g);

t->Draw(heneossstring, cut && cut3sub && cut3sub2 && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub);

now I need that Root doens’t delete the events not fullfilling the criteria && cut3sub && cut3sub2 but just set Energy =0 for these events in my sum.

how should I do?


ROOT Version: 5,34/38
Platform: Windows
Compiler: Not Provided


Multiplying the quantity you are plotting by

( (cut3sub && cut3sub2) ? 1 : 0 )

should work.

Hi @pcanal thank you, unfortunately t I wrote:

TString heneoss3leadstring = TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] )* ( (cut3sub && cut3sub2) ? 1 : 0 )>> htemp(16000., 0., 16000.)", b,c,c2,d,e,f,g);
			t->Draw(heneoss3leadstring, cut && cut3sub && cut3sub2 && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub);

but I get error

does @pcanal or someoneelse know how to fix it please?

Can you provide a small macro reproducing the problem ?

Hi @couet, in attachment the root file and the macro

si-500596.root (1.4 MB)
caloeff.cpp (180.3 KB)

can you fix these errors please:

Processing caloeff.cpp...
In file included from input_line_9:1:
/Users/couet/Downloads/caloeff.cpp:2364:10: error: redefinition of 'c16'
TCanvas *c16 = new TCanvas("c16",canvtitle,1280,1024);
         ^
/Users/couet/Downloads/caloeff.cpp:636:10: note: previous definition is here
TCanvas *c16 = new TCanvas("c16",canvtitle,1280,1024);
         ^
/Users/couet/Downloads/caloeff.cpp:2450:10: error: redefinition of 'c17'
TCanvas *c17 = new TCanvas("c17",canvtitle,1280,1024);
         ^
/Users/couet/Downloads/caloeff.cpp:722:10: note: previous definition is here
TCanvas *c17 = new TCanvas("c17",canvtitle,1280,1024);
         ^
/Users/couet/Downloads/caloeff.cpp:2536:13: error: redefinition of 'c18'
   TCanvas *c18 = new TCanvas("c18",canvtitle,1280,1024);
            ^
/Users/couet/Downloads/caloeff.cpp:808:13: note: previous definition is here
   TCanvas *c18 = new TCanvas("c18",canvtitle,1280,1024);
            ^
/Users/couet/Downloads/caloeff.cpp:2715:16: error: redefinition of 'c19'
      TCanvas *c19 = new TCanvas("c19",canvtitle,1280,1024);
               ^
/Users/couet/Downloads/caloeff.cpp:917:16: note: previous definition is here
      TCanvas *c19 = new TCanvas("c19",canvtitle,1280,1024);

Hi @couet, I didnt’ get these errors by using windows root, then I forgot to change the canvas name name after the copy/past of the code.

Anyway I’ve just renamed the 3 canvas.caloeff.cpp (180.3 KB)

You should use Aclic:

.x caloeff.cpp++

An other error:

In file included from input_line_9:1:
/Users/couet/Downloads/caloeff.cpp:342:76: warning: more '%' conversions than data arguments [-Wformat]
                TString myplottimeout7sub = TString::Format("%ssi-%d_time%d-%d-%d-%d-%d-%d.pdf",outfolder7sub.Data(),ifile,a,b,d,e,f); // TO USE FOR FILES WITH TARGET
                                                                                        ~^

Done
caloeff.cpp (180.3 KB)

another one:

Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
In file included from input_line_9:1:
/Users/couet/Downloads/caloeff.cpp:3523:4: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
                        heneoss3lead->GetXaxis()->SetTitle(cdeneXnameab);
                        ^~~~~~~~~~~~

caloeff.cpp (180.0 KB)

Hi @couet, I runned your macro…but I still get the error due to this line

	TString heneoss3leadstring = TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] ) * ( (cut3sub && cut3sub2) ? 1 : 0 )>> htemp(3000., 0., 3000.)", b,c,c2,d,e,f,g);

You cannot put:

( (cut3sub && cut3sub2) ? 1 : 0 )

in heneoss3leadstring

That’s the variable you will plot. not the selection.

do:

TString heneoss3leadstring =
TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] ) >> htemp(3000., 0., 3000.)", b,c,c2,d,e,f,g);

Hi @couet, I know it works without the

( (cut3sub && cut3sub2) ? 1 : 0 )

but I explain what I should to do.

I’ve built an energy sum plot having some conditions in this way:

TString heneossstring = TString::Format("Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] >> htemp(16000., 0., 16000.)", b,c,c2,d,e,f,g);

t->Draw(heneossstring, cut && cut3sub && cut3sub2 && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub);

now I need that Root doens’t delete the events not fullfilling the criteria && cut3sub && cut3sub2 but just set Energy =0 for these events in my sum.

@pcanal replied me (look on the top ) to multply by

( (cut3sub && cut3sub2) ? 1 : 0 )

but in this way I get the error.

Yes but why don’t you apply this on the selection parameter instead of applying it on the variables to plot ?

I’m not sure to understand what you mean…
I wrote:

	TString heneoss3leadstring = TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] ) >> htemp(3000., 0., 3000.)", b,c,c2,d,e,f,g);
			t->Draw(heneoss3leadstring , (cut && cut3sub && cut3sub2 && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub) * ( (cut3sub && cut3sub2) ? 1 : 0 ));

but I get this error

TString heneoss3leadstring = TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] ) >> htemp(3000., 0., 3000.)", b,c,c2,d,e,f,g);
TCut cut999 = Form("((%s && %s) ? 1 : 0 )",cut3sub.GetTitle(),cut3sub2.GetTitle());
t->Draw(heneoss3leadstring , cut && cut3sub && cut3sub2 && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub * cut999);

Hi @couet, by using your code I don’t get error, but I’m not sure to get what I need.

I tried first to run the macro without the

&& cut3sub &&cut3sub2

conditions, i.e. by writing

TString heneoss3leadstring = TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] ) >> htemp(3000., 0., 3000.)", b,c,c2,d,e,f,g);
t->Draw(heneoss3leadstring , (cut && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub));

in this way, in the plot si-500596_eneoss_Sum-0-2-1-12-13-14-15.pdf I get 1899 events.

Later I used your code

String heneoss3leadstring = TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] ) >> htemp(3000., 0., 3000.)", b,c,c2,d,e,f,g);
TCut cut999 = Form("((%s && %s) ? 1 : 0 )",cut3sub.GetTitle(),cut3sub2.GetTitle());
t->Draw(heneoss3leadstring , cut && cut3sub && cut3sub2 && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub * cut999);

but I got just 12 events, then it means that ROOT deletes the events not fullfilling the

&& cut3sub &&cut3sub2 

conditions (instead I want to keep the events not fullfilling these conditions, but to set in the sum energy_i =0 for the i-events not fullfilling these conditions. To check it, I also wrote:

	TString heneoss3leadstring = TString::Format("(Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d]  + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] + Calo_EnDep[%d] ) >> htemp(3000., 0., 3000.)", b,c,c2,d,e,f,g);
t->Draw(heneoss3leadstring , (cut && cut3sub && cut3sub2 && cuteneb && cut4sub && cut5sub && cut6sub && cut7sub));

getting 12 events too.