ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/kiesel/TreeWriter/treeWriter.cc
(Generate patch)

Comparing UserCode/kiesel/TreeWriter/treeWriter.cc (file contents):
Revision 1.4 by kiesel, Mon Mar 25 12:00:06 2013 UTC vs.
Revision 1.6 by kiesel, Tue Apr 9 08:24:40 2013 UTC

# Line 1 | Line 1
1   #include<iostream>
2   #include<math.h>
3  
4 < #include "TFile.h"
5 < #include "TTree.h"
6 < #include "TString.h"
7 <
8 < #include "SusyEvent.h"
9 < #include "TreeObjects.h"
10 <
11 <
12 < class TreeWriter {
13 <        public :
14 <                TreeWriter(TString inputName, TString outputName );
15 <                virtual ~TreeWriter();
16 <                virtual void Loop();
17 <
18 <                void SetProcessNEvents(int nEvents) { processNEvents = nEvents; }
19 <                void SetReportEvents(int nEvents) { reportEvery = nEvents; }
20 <
21 <                TFile *inputFile;
22 <                TTree *inputTree;
23 <                susy::Event *event;
24 <
25 <                TFile *outFile;
26 <                TTree *tree;
27 <
28 <                float getPtFromMatchedJet( susy::Photon, susy::Event );
29 <                float deltaR( TLorentzVector, TLorentzVector );
30 <
31 <        private:
32 <                int processNEvents; // number of events to be processed
33 <                int reportEvery;
34 <                int loggingVerbosity;
35 <
36 <                // variables which will be stored in the tree
37 <                std::vector<tree::Photon> photon;
38 <                std::vector<tree::Jet> jet;
39 <                float met;
40 <                int nVertex;
41 <                int nElectron;
42 <                float weight;
43 < };
4 > #include "TSystem.h"
5  
6 < TreeWriter::TreeWriter(TString inputName, TString outputName) {
6 > #include "treeWriter.h"
7 >
8 > using namespace std;
9 >
10 > TreeWriter::TreeWriter(TString inputName, TString outputName, int loggingVerbosity_ ) {
11          // read the input file
12 <        inputFile = new TFile( inputName, "read" );
13 <        inputTree = (TTree*) inputFile->Get("susyTree");
12 >        inputTree = new TChain("susyTree");
13 >        if (loggingVerbosity_ > 0)
14 >                std::cout << "Add files to chain" << std::endl;
15 >        inputTree->Add( inputName );
16 >
17 >        if (loggingVerbosity_ > 0)
18 >                std::cout << "Set Branch Address of susy::Event" << std::endl;
19          event = new susy::Event;
20          inputTree->SetBranchAddress("susyEvent", &event);
21  
# Line 56 | Line 26 | TreeWriter::TreeWriter(TString inputName
26          // set default parameter
27          processNEvents = -1;
28          reportEvery = 1000;
29 <        loggingVerbosity = 0;
29 >        loggingVerbosity = loggingVerbosity_;
30 >        skim = true;
31  
32   }
33  
# Line 69 | Line 40 | float TreeWriter::deltaR( TLorentzVector
40          return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) );
41   }
42  
43 < float TreeWriter::getPtFromMatchedJet( susy::Photon photon, susy::Event event ) {
43 > float TreeWriter::getPtFromMatchedJet( susy::Photon myPhoton, susy::Event myEvent ) {
44          /**
45           * \brief Takes jet p_T as photon p_T
46           *
47           * At first all jets with DeltaR < 0.3 (isolation cone) are searched.
48           * If several jets are found, take the one with the minimal pt difference
49 <         * compared to the photon. If no such jets are found, return 0
49 >         * compared to the photon. If no such jets are found, keep the photon_pt
50           * TODO: remove photon matched jet from jet-selection?
51           */
52          std::vector<susy::PFJet> nearJets;
53          nearJets.clear();
54  
55 <        std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event.pfJets.find("ak5");
56 <        if(pfJets_it == event.pfJets.end()){
57 <                if(event.pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
55 >        std::map<TString,susy::PFJetCollection>::iterator pfJets_it = myEvent.pfJets.find("ak5");
56 >        if(pfJets_it == myEvent.pfJets.end()){
57 >                if(myEvent.pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
58          } else {
59                  susy::PFJetCollection& jetColl = pfJets_it->second;
60                  for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
# Line 95 | Line 66 | float TreeWriter::getPtFromMatchedJet( s
66                          }
67                          float scale = s_it->second;
68                          TLorentzVector corrP4 = scale * it->momentum;
69 <                        float deltaR_ = deltaR(photon.momentum, corrP4 );
69 >                        float deltaR_ = deltaR(myPhoton.momentum, corrP4 );
70                          if (deltaR_ > 0.3) continue;
71 +                        if( loggingVerbosity > 0 )
72 +                                std::cout << "gamma pt jet matching factor = " << it->momentum.Et() / myPhoton.momentum.Et() << std::endl;
73                          nearJets.push_back( *it );
74                  }// for jet
75          }// if, else
76  
77          if ( nearJets.size() == 0 ) {
78 <                std::cout << "No jet with ΔR < .3 found, set p_T to 0" << std::endl;
79 <                return 0;
78 >                //std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl;
79 >                return myPhoton.momentum.Et();
80          }
81  
82          float pt = 0;
83          float minPtDifferenz = 1E20; // should be very high
84          for( std::vector<susy::PFJet>::iterator it = nearJets.begin(), jetEnd = nearJets.end();
85                          it != jetEnd; it++ ) {
86 <                float ptDiff = fabs(photon.momentum.Et() - it->momentum.Et());
86 >                float ptDiff = fabs(myPhoton.momentum.Et() - it->momentum.Et());
87                  if (  ptDiff < minPtDifferenz ) {
88                          minPtDifferenz = ptDiff;
89                          pt = it->momentum.Et();
# Line 118 | Line 91 | float TreeWriter::getPtFromMatchedJet( s
91          }
92  
93          // testing
94 <        if( nearJets.size() > 1 )
94 >        if( nearJets.size() > 1 && loggingVerbosity > 0 )
95                  std::cout << "There are several jets matching to this photon. "
96 <                                        << "Please check if the upper assumtion is reasonable" << std::endl;
96 >                                        << "Please check if jet-matching is correct." << std::endl;
97          return pt;
98   }
99  
100  
101   void TreeWriter::Loop() {
129        // only for testing
130        bool skim = true;
102  
103          // here the event loop is implemented and the tree is filled
104          if (inputTree == 0) return;
# Line 146 | Line 117 | void TreeWriter::Loop() {
117          tree->Branch("photon", &photon);
118          tree->Branch("jet", &jet);
119          tree->Branch("met", &met, "met/F");
120 +        tree->Branch("ht", &ht, "ht/F");
121          tree->Branch("nVertex", &nVertex, "nVertex/I");
150        tree->Branch("weigth", &weight, "weight/F");
122          tree->Branch("nElectron", &nElectron, "nElectron/I");
123  
124  
# Line 158 | Line 129 | void TreeWriter::Loop() {
129  
130                  photon.clear();
131                  jet.clear();
132 +                ht = 0;
133  
134                  // photons
135 +                if( loggingVerbosity > 1 )
136 +                        std::cout << "Process photons" << std::endl;
137                  std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
138                  for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
139                                  it != phoMap->second.end() && phoMap != event->photons.end(); it++ ) {
# Line 180 | Line 154 | void TreeWriter::Loop() {
154                          thisphoton->hadTowOverEm = it->hadTowOverEm;
155                          thisphoton->pixelseed = it->nPixelSeeds;
156                          photon.push_back( *thisphoton );
157 +                        ht += thisphoton->pt;
158 +                        if( loggingVerbosity > 2 )
159 +                                std::cout << " p_T, gamma = " << thisphoton->pt << std::endl;
160                  }
161 +
162                  if( photon.size() == 0 && skim )
163                          continue;
164                  std::sort( photon.begin(), photon.end(), tree::EtGreater);
165 +                if( loggingVerbosity > 1 )
166 +                        std::cout << "Found " << photon.size() << " photons" << std::endl;
167  
168                  // jets
169                  std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event->pfJets.find("ak5");
# Line 208 | Line 188 | void TreeWriter::Loop() {
188                                  thisjet->eta = corrP4.Eta();
189                                  thisjet->phi = corrP4.Phi();
190                                  jet.push_back( *thisjet );
191 +                                ht += thisjet->pt;
192                          }// for jet
193                  }// if, else
194                  if( jet.size() < 2 && skim )
# Line 220 | Line 201 | void TreeWriter::Loop() {
201                  met = metobj->met();
202  
203                  // electrons
204 <                std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
205 <                nElectron = eVector.size();
204 >                //std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
205 >                //nElectron = eVector.size();
206  
207                  // vertices
208  
209                  nVertex = event->vertices.size();
229                weight = 1;
210  
211 <                // bjets
211 >                if( ht < 450 && skim)
212 >                        continue;
213  
214                  tree->Fill();
215          } // for jentry
# Line 241 | Line 222 | void TreeWriter::Loop() {
222          outFile->Close();
223   }
224  
244 int main(int argc, char** argv) {
245        TreeWriter *tw = new TreeWriter("../root-files/susyEvents_qcd_1000-inf_part.root", "myTree.root");
246        tw->SetProcessNEvents(-1);
247        tw->Loop();
248 }
249

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines