Fork me on GitHub

source: git/examples/Example1.C@ 01f457a

ImprovedOutputFile Timing dual_readout llp
Last change on this file since 01f457a was fc4e460, checked in by Michele <michele.selvaggi@…>, 10 years ago

removed muon check in jet constituent loop. Added comments to example macros

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