Reading multiple files from the same directory

Hi,

I am using TSelector, derived from the MakeSelector.
It looks something like this:

void run_example() { TChain* fChain=new TChain("ExampleTree"); fChain->Add("/cms/data4/ttbar/ntuple/ttbar_ntuple_100.root"); fChain->Process("root_script/example.C++"); }

where the example.C is the file that contains the selection criteriea.

I have a lot of files in the same directory that contain the same tree.
Can anybody suggest a short code to process all the files in the directory without putting them in the code individually, like this …

fChain->Add("/cms/data4/ttbar/ntuple/ttbar_ntuple_100.root"); fChain->Add("/cms/data4/ttbar/ntuple/ttbar_ntuple_101.root"); fChain->Add("/cms/data4/ttbar/ntuple/ttbar_ntuple_102.root"); .... 70 lines

Also,

when I processing files from the different directory, i.e.

I want to use the same processing code, but different weight. Is there a way, I can tell to the process function which weight to use when the files from the certain directory are being processed?

thank you very much in advance,

Dmitry.

After little more searching I found that I can use wildcards for the first part of my question:

fChain->Add("/cms/data4/ttbar/ntuple/*.root");

But I still wondering if somebody can help me with the second part

[quote=“hits”]
when I processing files from the different directory, i.e.

I want to use the same processing code, but different weight. Is there a way, I can tell to the process function which weight to use when the files from the certain directory are being processed?

thank you very much in advance,

Dmitry.[/quote]

Hi,

In the Process (or probably better yet in the Notify function which is called once for each file), you can look up the name (and hence directory) of the file being processed. (Call fChain->GetTree()->GetDirectory()->GetFile()->GetName() for example).

Cheers,
Philippe