Fork me on GitHub

source: git/examples/Example1.C@ d2ac201

ImprovedOutputFile Timing dual_readout llp
Last change on this file since d2ac201 was 21f3c04, checked in by Pavel Demin <demin@…>, 10 years ago

replace \(\"...\"\) with '("...")' in ROOT command line examples

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2root -l examples/Example1.C'("delphes_output.root")'
3*/
4
5//------------------------------------------------------------------------------
6
7void Example1(const char *inputFile)
8{
9 gSystem->Load("libDelphes");
10
11 // Create chain of root trees
12 TChain chain("Delphes");
13 chain.Add(inputFile);
14
15 // Create object of class ExRootTreeReader
16 ExRootTreeReader *treeReader = new ExRootTreeReader(&chain);
17 Long64_t numberOfEntries = treeReader->GetEntries();
18
19 // Get pointers to branches used in this analysis
20 TClonesArray *branchJet = treeReader->UseBranch("Jet");
21 TClonesArray *branchElectron = treeReader->UseBranch("Electron");
22
23 // Book histograms
24 TH1 *histJetPT = new TH1F("jet_pt", "jet P_{T}", 100, 0.0, 100.0);
25 TH1 *histMass = new TH1F("mass", "M_{inv}(e_{1}, e_{2})", 100, 40.0, 140.0);
26
27 // Loop over all events
28 for(Int_t entry = 0; entry < numberOfEntries; ++entry)
29 {
30 // Load selected branches with data from specified event
31 treeReader->ReadEntry(entry);
32
33 // If event contains at least 1 jet
34 if(branchJet->GetEntries() > 0)
35 {
36 // Take first jet
37 Jet *jet = (Jet*) branchJet->At(0);
38
39 // Plot jet transverse momentum
40 histJetPT->Fill(jet->PT);
41
42 // Print jet transverse momentum
43 cout << jet->PT << endl;
44 }
45
46 Electron *elec1, *elec2;
47
48 // If event contains at least 2 electrons
49 if(branchElectron->GetEntries() > 1)
50 {
51 // Take first two electrons
52 elec1 = (Electron *) branchElectron->At(0);
53 elec2 = (Electron *) branchElectron->At(1);
54
55 // Plot their invariant mass
56 histMass->Fill(((elec1->P4()) + (elec2->P4())).M());
57 }
58 }
59
60 // Show resulting histograms
61 histJetPT->Draw();
62 histMass->Draw();
63}
Note: See TracBrowser for help on using the repository browser.