1 |
fgolf |
1.1 |
/* Usage:
|
2 |
|
|
root [0] .L ScanChain.C++
|
3 |
|
|
root [1] TFile *_file0 = TFile::Open("merged_ntuple.root")
|
4 |
|
|
root [2] TChain *chain = new TChain("Events")
|
5 |
|
|
root [3] chain->Add("merged_ntuple.root")
|
6 |
|
|
|
7 |
|
|
There are several places where one may create CMS2 cms2
|
8 |
|
|
It can be done here (in a doAll.C script), i.e.:
|
9 |
|
|
|
10 |
|
|
root [4] CMS2 cms2
|
11 |
|
|
|
12 |
|
|
It can be done in the source as is done below, or it can be
|
13 |
|
|
ascertained by including CORE/CMS2.cc as is commented out
|
14 |
|
|
below. They are all the same, and everything will work so
|
15 |
|
|
long as it is created somewhere globally.
|
16 |
|
|
|
17 |
|
|
root [5] ScanChain(chain)
|
18 |
|
|
*/
|
19 |
|
|
#include <iostream>
|
20 |
|
|
#include <vector>
|
21 |
|
|
|
22 |
|
|
#include "TChain.h"
|
23 |
|
|
#include "TFile.h"
|
24 |
|
|
#include "TDirectory.h"
|
25 |
|
|
#include "TROOT.h"
|
26 |
|
|
|
27 |
|
|
#include "CMS2.h"
|
28 |
|
|
CMS2 cms2;
|
29 |
|
|
/*
|
30 |
|
|
#include "CORE/CMS2.cc"
|
31 |
|
|
#include "CORE/selections.cc"
|
32 |
|
|
#include "CORE/utilities.cc"
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
|
|
using namespace tas;
|
36 |
|
|
|
37 |
|
|
int ScanChain( TChain* chain, int nEvents = -1, std::string skimFilePrefix="") {
|
38 |
|
|
|
39 |
|
|
TObjArray *listOfFiles = chain->GetListOfFiles();
|
40 |
|
|
|
41 |
|
|
unsigned int nEventsChain=0;
|
42 |
|
|
if(nEvents==-1)
|
43 |
|
|
nEvents = chain->GetEntries();
|
44 |
|
|
nEventsChain = nEvents;
|
45 |
|
|
unsigned int nEventsTotal = 0;
|
46 |
|
|
TDirectory *rootdir = gDirectory->GetDirectory("Rint:");
|
47 |
|
|
|
48 |
|
|
TH1F *samplehisto = new TH1F("samplehisto", "Example histogram", 200,0,200);
|
49 |
|
|
samplehisto->SetDirectory(rootdir);
|
50 |
|
|
// file loop
|
51 |
|
|
TIter fileIter(listOfFiles);
|
52 |
|
|
TFile *currentFile = 0;
|
53 |
|
|
while ( currentFile = (TFile*)fileIter.Next() ) {
|
54 |
|
|
TFile f(currentFile->GetTitle());
|
55 |
|
|
TTree *tree = (TTree*)f.Get("Events");
|
56 |
|
|
cms2.Init(tree);
|
57 |
|
|
|
58 |
|
|
//Event Loop
|
59 |
|
|
unsigned int nEvents = tree->GetEntries();
|
60 |
|
|
for( unsigned int event = 0; event < nEvents; ++event) {
|
61 |
|
|
cms2.GetEntry(event);
|
62 |
|
|
++nEventsTotal;
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
if ( nEventsChain != nEventsTotal ) {
|
67 |
|
|
std::cout << "ERROR: number of events from files is not equal to total number of events" << std::endl;
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
samplehisto->Draw();
|
71 |
|
|
return 0;
|
72 |
|
|
}
|