Home | News | Documentation | Download

Using Scan in macro


#1

Hello,

Normally using TTree::Scan, if there are arrays as branches, then if one performs a cut on a non-array variable, Scan will output a separate row for each Instance, up to the maximum size of any shown array.

Example from the root prompt (the tree in the root file is named ‘t’):

[code]
phoenix% root -l …/CreeperR4/TestRun.root
root [0]
Attaching file …/CreeperR4/TestRun.root as _file0…
[root [1] t->Scan(“fEventNum:fSTACId”,“fEventNum==314379”)


  • Row * Instance * fEventNum * fSTACId *

  • 314379 * 0 * 314379 * 13 *
  • 314379 * 1 * 314379 * 0 *
  • 314379 * 2 * 314379 * 2 *
  • 314379 * 3 * 314379 * 7 *
  • 314379 * 4 * 314379 * 5 *
  • 314379 * 5 * 314379 * 2 *
  • 314379 * 6 * 314379 * 7 *
  • 314379 * 7 * 314379 * 7 *
  • 314379 * 8 * 314379 * 11 *
  • 314379 * 9 * 314379 * 6 *
  • 314379 * 10 * 314379 * 13 *
  • 314379 * 11 * 314379 * 3 *
  • 314379 * 12 * 314379 * 14 *
  • 314379 * 13 * 314379 * 4 *
  • 314379 * 14 * 314379 * 14 *
  • 314379 * 15 * 314379 * 7 *
  • 314379 * 16 * 314379 * 15 *
  • 314379 * 17 * 314379 * 4 *
  • 314379 * 18 * 314379 * 1 *
  • 314379 * 19 * 314379 * 2 *
  • 314379 * 20 * 314379 * 1 *
  • 314379 * 21 * 314379 * 1 *
  • 314379 * 22 * 314379 * 2 *
  • 314379 * 23 * 314379 * 4 *
  • 314379 * 24 * 314379 * 5 *
    Type to continue or q to quit ==> [/code]

Now suppose I have used t->MakeClass() to create a tree reader skeleton, and defined a function within that class. Here the tree pointer is now called ‘fChain.’

void makeclassobject::RootScan() { fChain->Scan("fEventNum:fSTACId","fEventNum==314379"); }

Then suppose I create an un-named Macro.C which instantiates the makeclassobject and calls the makeclassobject::RootScan() function. When I run that macro, the output is then:

[code]***********************************************

  • Row * Instance * fEventNum * fSTACId *

  • 314379 * 0 * 314379 * 13 *

==> 1 selected entry[/code]

If I want the scan to appear to the user just as if he/she had entered the Scan command from the root prompt, what parameters to I need to pass to Scan in order to make it appear as normal?

Thanks,

Joe


#2

[quote]When I run that macro, the output is then … :[/quote]A priori the result should have been the same in both case. Can you send a complete running example showing the problem?

Philippe.


#3

Yes I can. I attach some files:

Root version: 5.29/01
treeshort.root - truncated version of my root file, containing tree 't’
ScanIssue.C/.h: result of t->MakeClass(“ScanIssue”) with one function added, ScanIssue::UserScan()
StartScanIssue.C: un-named macro code.

Usage: do root StartScanIssue.C
My results (pasted below): I get ‘1 selected entry’ when executing the UserScan function from a root prompt, and the regular, functioning Scan when doing 't->Scan("…","…") from the root prompt. Let me know if you need anything else.

Thanks!

Joe

[code]battlezone% root -l StartScanIssue.C
root [0]
Processing StartScanIssue.C…
Executing script in 'StartScanIssue.C’
Warning in TClass::TClass: no dictionary for class UC_FreezeCycle is available

Constructed si with tree from file located at ./treeshort.root.
(entries = 1000)
root [1] si.UserScan()


  • Row * Instance * fEventNum * fSTACId *

  •  358 *        0 *       358 *         8 *
    

==> 1 selected entry
root [2] .q
battlezone% root -l treeshort.root
root [0]
Attaching file treeshort.root as _file0…
Warning in TClass::TClass: no dictionary for class UC_FreezeCycle is available
root [1] t->Scan(“fEventNum:fSTACId”,“fEventNum==358”)


  • Row * Instance * fEventNum * fSTACId *

  •  358 *        0 *       358 *         8 *
    
  •  358 *        1 *       358 *         8 *
    
  •  358 *        2 *       358 *         8 *
    
  •  358 *        3 *       358 *         8 *
    
  •  358 *        4 *       358 *         8 *
    
  •  358 *        5 *       358 *         8 *
    
  •  358 *        6 *       358 *         8 *
    
  •  358 *        7 *       358 *         8 *
    
  •  358 *        8 *       358 *         8 *
    
  •  358 *        9 *       358 *         8 *
    
  •  358 *       10 *       358 *         8 *
    
  •  358 *       11 *       358 *         8 *
    
  •  358 *       12 *       358 *         8 *
    
  •  358 *       13 *       358 *         8 *
    
  •  358 *       14 *       358 *         8 *
    
  •  358 *       15 *       358 *         8 *
    
  •  358 *       16 *       358 *         8 *
    
  •  358 *       17 *       358 *         8 *
    
  •  358 *       18 *       358 *         8 *
    
  •  358 *       19 *       358 *         8 *
    
  •  358 *       20 *       358 *         8 *
    
  •  358 *       21 *       358 *         8 *
    
  •  358 *       22 *       358 *         8 *
    
  •  358 *       23 *       358 *         8 *
    
  •  358 *       24 *       358 *         8 *
    

Type to continue or q to quit ==> [/code]
ScanIssue.zip (115 KB)


#4

Hi,

Thanks for reporting this issue, it is fixed in revision 38262 and up of the trunk.

Cheers,
Philippe.