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.5 by kiesel, Tue Apr 9 07:28:02 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 > #include "treeWriter.h"
7 >
8 > using namespace std;
9  
10   TreeWriter::TreeWriter(TString inputName, TString outputName) {
11          // read the input file
12 <        inputFile = new TFile( inputName, "read" );
13 <        inputTree = (TTree*) inputFile->Get("susyTree");
12 >        //TFile *inputFile = TFile::Open( inputName, "read" );
13 >        inputTree = new TChain("susyTree");
14 >        inputTree->Add( inputName );
15 >
16          event = new susy::Event;
17          inputTree->SetBranchAddress("susyEvent", &event);
18  
# Line 57 | Line 24 | TreeWriter::TreeWriter(TString inputName
24          processNEvents = -1;
25          reportEvery = 1000;
26          loggingVerbosity = 0;
27 +        skim = true;
28  
29   }
30  
# Line 69 | Line 37 | float TreeWriter::deltaR( TLorentzVector
37          return sqrt(pow(v1.Eta() - v2.Eta(), 2) + pow(v1.Phi() - v2.Phi(), 2) );
38   }
39  
40 < float TreeWriter::getPtFromMatchedJet( susy::Photon photon, susy::Event event ) {
40 > float TreeWriter::getPtFromMatchedJet( susy::Photon myPhoton, susy::Event myEvent ) {
41          /**
42           * \brief Takes jet p_T as photon p_T
43           *
44           * At first all jets with DeltaR < 0.3 (isolation cone) are searched.
45           * If several jets are found, take the one with the minimal pt difference
46 <         * compared to the photon. If no such jets are found, return 0
46 >         * compared to the photon. If no such jets are found, keep the photon_pt
47           * TODO: remove photon matched jet from jet-selection?
48           */
49          std::vector<susy::PFJet> nearJets;
50          nearJets.clear();
51  
52 <        std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event.pfJets.find("ak5");
53 <        if(pfJets_it == event.pfJets.end()){
54 <                if(event.pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
52 >        std::map<TString,susy::PFJetCollection>::iterator pfJets_it = myEvent.pfJets.find("ak5");
53 >        if(pfJets_it == myEvent.pfJets.end()){
54 >                if(myEvent.pfJets.size() > 0) std::cout << "JetCollection is not available!!!" << std::endl;
55          } else {
56                  susy::PFJetCollection& jetColl = pfJets_it->second;
57                  for(std::vector<susy::PFJet>::iterator it = jetColl.begin();
# Line 95 | Line 63 | float TreeWriter::getPtFromMatchedJet( s
63                          }
64                          float scale = s_it->second;
65                          TLorentzVector corrP4 = scale * it->momentum;
66 <                        float deltaR_ = deltaR(photon.momentum, corrP4 );
66 >                        float deltaR_ = deltaR(myPhoton.momentum, corrP4 );
67                          if (deltaR_ > 0.3) continue;
68 +                        if( loggingVerbosity > 0 )
69 +                                std::cout << "gamma pt jet matching factor = " << it->momentum.Et() / myPhoton.momentum.Et() << std::endl;
70                          nearJets.push_back( *it );
71                  }// for jet
72          }// if, else
73  
74          if ( nearJets.size() == 0 ) {
75 <                std::cout << "No jet with ΔR < .3 found, set p_T to 0" << std::endl;
76 <                return 0;
75 >                //std::cout << "No jet with deltaR < .3 found, do not change photon_pt" << std::endl;
76 >                return myPhoton.momentum.Et();
77          }
78  
79          float pt = 0;
80          float minPtDifferenz = 1E20; // should be very high
81          for( std::vector<susy::PFJet>::iterator it = nearJets.begin(), jetEnd = nearJets.end();
82                          it != jetEnd; it++ ) {
83 <                float ptDiff = fabs(photon.momentum.Et() - it->momentum.Et());
83 >                float ptDiff = fabs(myPhoton.momentum.Et() - it->momentum.Et());
84                  if (  ptDiff < minPtDifferenz ) {
85                          minPtDifferenz = ptDiff;
86                          pt = it->momentum.Et();
# Line 126 | Line 96 | float TreeWriter::getPtFromMatchedJet( s
96  
97  
98   void TreeWriter::Loop() {
129        // only for testing
130        bool skim = true;
99  
100          // here the event loop is implemented and the tree is filled
101          if (inputTree == 0) return;
# Line 146 | Line 114 | void TreeWriter::Loop() {
114          tree->Branch("photon", &photon);
115          tree->Branch("jet", &jet);
116          tree->Branch("met", &met, "met/F");
117 +        tree->Branch("ht", &ht, "ht/F");
118          tree->Branch("nVertex", &nVertex, "nVertex/I");
150        tree->Branch("weigth", &weight, "weight/F");
119          tree->Branch("nElectron", &nElectron, "nElectron/I");
120  
121  
# Line 158 | Line 126 | void TreeWriter::Loop() {
126  
127                  photon.clear();
128                  jet.clear();
129 +                ht = 0;
130  
131                  // photons
132 +                if( loggingVerbosity > 1 )
133 +                        std::cout << std::endl << "Process photons" << std::endl;
134                  std::map<TString, std::vector<susy::Photon> >::iterator phoMap = event->photons.find("photons");
135                  for(std::vector<susy::Photon>::iterator it = phoMap->second.begin();
136                                  it != phoMap->second.end() && phoMap != event->photons.end(); it++ ) {
# Line 180 | Line 151 | void TreeWriter::Loop() {
151                          thisphoton->hadTowOverEm = it->hadTowOverEm;
152                          thisphoton->pixelseed = it->nPixelSeeds;
153                          photon.push_back( *thisphoton );
154 +                        ht += thisphoton->pt;
155 +                        if( loggingVerbosity > 2 )
156 +                                std::cout << " photonpt = " << thisphoton->pt << std::endl;
157                  }
158 +
159                  if( photon.size() == 0 && skim )
160                          continue;
161                  std::sort( photon.begin(), photon.end(), tree::EtGreater);
162 +                if( loggingVerbosity > 1 )
163 +                        std::cout << "Found " << photon.size() << " photons" << std::endl;
164  
165                  // jets
166                  std::map<TString,susy::PFJetCollection>::iterator pfJets_it = event->pfJets.find("ak5");
# Line 208 | Line 185 | void TreeWriter::Loop() {
185                                  thisjet->eta = corrP4.Eta();
186                                  thisjet->phi = corrP4.Phi();
187                                  jet.push_back( *thisjet );
188 +                                ht += thisjet->pt;
189                          }// for jet
190                  }// if, else
191                  if( jet.size() < 2 && skim )
# Line 220 | Line 198 | void TreeWriter::Loop() {
198                  met = metobj->met();
199  
200                  // electrons
201 <                std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
202 <                nElectron = eVector.size();
201 >                //std::vector<susy::Electron> eVector = event->electrons["gsfElectrons"];
202 >                //nElectron = eVector.size();
203  
204                  // vertices
205  
206                  nVertex = event->vertices.size();
229                weight = 1;
207  
208 <                // bjets
208 >                if( ht < 450 && skim)
209 >                        continue;
210  
211                  tree->Fill();
212          } // for jentry
# Line 241 | Line 219 | void TreeWriter::Loop() {
219          outFile->Close();
220   }
221  
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