ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/AachenCompatibility.C
(Generate patch)

Comparing UserCode/cbrown/Development/Plotting/Modules/AachenCompatibility.C (file contents):
Revision 1.1 by buchmann, Wed Jul 4 14:35:57 2012 UTC vs.
Revision 1.3 by buchmann, Mon Jul 9 12:38:25 2012 UTC

# Line 1 | Line 1
1 < TTree* SkimTreeAndAachifyIt(int isample) {
2 <  TTree* newTree = new TTree("newTree","FullTree");
1 > TTree* SkimTreeAndAachifyIt(TCut eventselection, string treename, string jzbexpression, TFile *sfile) {
2 >  TTree* newTree = new TTree(treename.c_str(),treename.c_str());
3    float AachenWeight,AachenchargeProduct,Aachenpt1,Aachenpt2;
4    
5    newTree->Branch("weight",&AachenWeight,"weight/F");
6 //  initFloatBranch( "weight" );
6    newTree->Branch("chargeProduct",&AachenchargeProduct,"chargeProduct/F");
8 //   initFloatBranch( "chargeProduct" );  
7    newTree->Branch("pt1",&Aachenpt1,"pt1/F");
10 //   initFloatBranch( "pt1" );
8    newTree->Branch("pt2",&Aachenpt2,"pt2/F");
9 < //   initFloatBranch( "pt2" );
10 <  float ETHid1,ETHid2,ETHweight,ETHpt1,ETHpt2;
11 <  allsamples.collection[isample].events->SetBranchAddress("id1",&ETHid1);
12 <  allsamples.collection[isample].events->SetBranchAddress("id2",&ETHid2);
13 <  allsamples.collection[isample].events->SetBranchAddress("weight",&ETHweight);
14 <  allsamples.collection[isample].events->SetBranchAddress("pt1",&ETHpt1);
15 <  allsamples.collection[isample].events->SetBranchAddress("pt2",&ETHpt2);
9 >  float ETHweight,ETHpt1,ETHpt2;
10 >  int ETHid1,ETHid2,ETHch1,ETHch2;
11 >  
12 >  TTree *origtree = (TTree*)sfile->Get("events");
13 >  
14 >  if(!origtree) {
15 >    write_error(__FUNCTION__,"Problem while aachifying - there is no tree called \"events\" in this file! Aborting!");
16 >    assert(origtree);
17 >  }
18 >  
19 >  origtree->SetBranchAddress("id1",&ETHid1);
20 >  origtree->SetBranchAddress("id2",&ETHid2);
21 >  origtree->SetBranchAddress("weight",&ETHweight);
22 >  origtree->SetBranchAddress("pt1",&ETHpt1);
23 >  origtree->SetBranchAddress("pt2",&ETHpt2);
24 >  origtree->SetBranchAddress("ch1",&ETHch1);
25 >  origtree->SetBranchAddress("ch2",&ETHch2);
26    
27    
28    float Aacheneta1,Aacheneta2,Aachenid1,Aachenid2,Aachenjzb,Aachenht,Aachenmet;
29    newTree->Branch("eta1",&Aacheneta1,"eta1/F");
23 //   initFloatBranch( "eta1" );
30    newTree->Branch("eta2",&Aacheneta2,"eta2/F");
25 //   initFloatBranch( "eta2" );
31    newTree->Branch("id1",&Aachenid1,"id1/F");
27 //   initFloatBranch( "id1" ); // isolation
32    newTree->Branch("id2",&Aachenid2,"id2/F");
29 //   initFloatBranch( "id2" ); // isolation
33    newTree->Branch("jzb",&Aachenjzb,"jzb/F");
31 //   initFloatBranch( "jzb" );
34    newTree->Branch("ht",&Aachenht,"ht/F");
33 //   initFloatBranch( "ht" );
35    newTree->Branch("met",&Aachenmet,"met/F");
35 //   initFloatBranch( "met" );
36    
37    float ETHeta1,ETHeta2,ETHiso1,ETHiso2,ETHht;
38    float ETHjzb[30];
39    float ETHmet[30];
40 <  allsamples.collection[isample].events->SetBranchAddress("eta1",&ETHeta1);
41 <  allsamples.collection[isample].events->SetBranchAddress("eta2",&ETHeta2);
42 <  allsamples.collection[isample].events->SetBranchAddress("iso1",&ETHiso1);
43 <  allsamples.collection[isample].events->SetBranchAddress("iso2",&ETHiso2);
44 <  allsamples.collection[isample].events->SetBranchAddress("pfHT",&ETHht);
45 <  allsamples.collection[isample].events->SetBranchAddress("met",&ETHmet);
40 >  origtree->SetBranchAddress("eta1",&ETHeta1);
41 >  origtree->SetBranchAddress("eta2",&ETHeta2);
42 >  origtree->SetBranchAddress("iso1",&ETHiso1);
43 >  origtree->SetBranchAddress("iso2",&ETHiso2);
44 >  origtree->SetBranchAddress("pfHT",&ETHht);
45 >  origtree->SetBranchAddress("met",&ETHmet);
46    
47    
48    
49    float AachenpZeta,AachenpZetaVis,AachennJets,AachennBJets,AachennVertices,Aachenjet1pt,Aachenjet2pt,Aachenjet3pt,Aachenjet4pt;
50    newTree->Branch("pZeta",&AachenpZeta,"pZeta/F");
51 //   initFloatBranch( "pZeta" );
51    newTree->Branch("pZetaVis",&AachenpZetaVis,"pZetaVis/F");
53 //   initFloatBranch( "pZetaVis" );
52    newTree->Branch("nJets",&AachennJets,"nJets/F");
55 //   initIntBranch( "nJets" );
53    newTree->Branch("nBJets",&AachennBJets,"nBJets/F");
57 //   initIntBranch( "nBJets" );
54    newTree->Branch("nVertices",&AachennVertices,"nVertices/F");
59 //   initIntBranch( "nVertices" );
55    newTree->Branch("jet1pt",&Aachenjet1pt,"jet1pt/F");
61 //   initFloatBranch( "jet1pt" );
56    newTree->Branch("jet2pt",&Aachenjet2pt,"jet2pt/F");
63 //   initFloatBranch( "jet2pt" );
57    newTree->Branch("jet3pt",&Aachenjet3pt,"jet3pt/F");
65 //   initFloatBranch( "jet3pt" );
58    newTree->Branch("jet4pt",&Aachenjet4pt,"jet4pt/F");
67 //   initFloatBranch( "jet4pt" );
59    
60 <  float ETHeta,ETHnjets,ETHnBJets,ETHnVertices;
60 >  float ETHeta;
61 >  int ETHnjets,ETHnBJets,ETHnVertices;
62    float ETHjetPt[30];
63 <  allsamples.collection[isample].events->SetBranchAddress("eta",&ETHeta);
64 <  allsamples.collection[isample].events->SetBranchAddress("pfJetGoodNum",&ETHnjets);
65 <  allsamples.collection[isample].events->SetBranchAddress("pfJetGoodNumBtag",&ETHnBJets);
66 <  allsamples.collection[isample].events->SetBranchAddress("numVtx",&ETHnVertices);
67 <  allsamples.collection[isample].events->SetBranchAddress("pfJetGoodPt",&ETHjetPt);
63 >  origtree->SetBranchAddress("eta",&ETHeta);
64 >  origtree->SetBranchAddress("pfJetGoodNum40",&ETHnjets);
65 >  origtree->SetBranchAddress("pfJetGoodNumBtag",&ETHnBJets);
66 >  origtree->SetBranchAddress("numVtx",&ETHnVertices);
67 >  origtree->SetBranchAddress("pfJetGoodPt",&ETHjetPt);
68    
69    
70    
71    float Aachenbjet1pt;
72    int AachenrunNr,AachenlumiSec,AachenpdgId1,AachenpdgId2,AacheneventNr;
73    newTree->Branch("bjet1pt",&Aachenbjet1pt,"bjet1pt/F");
82 //   initFloatBranch( "bjet1pt" );
74    newTree->Branch("runNr",&AachenrunNr,"runNr/I");
84 //   initIntBranch( "runNr" );
75    newTree->Branch("lumiSec",&AachenlumiSec,"lumiSec/I");
86 //   initIntBranch( "lumiSec" );
76    newTree->Branch("eventNr",&AacheneventNr,"eventNr/I");
88 //   initIntBranch( "eventNr" );
77    newTree->Branch("pdgId1",&AachenpdgId1,"pdgId1/I");
90 //   initIntBranch( "pdgId1" );
78    newTree->Branch("pdgId2",&AachenpdgId2,"pdgId2/I");
92 //   initIntBranch( "pdgId2" );
79    
80 <  float ETHBJetPt;
81 <  int ETHrunNum,ETHlumi,ETHevent,ETHgenId1,ETHgenId2;
82 <  allsamples.collection[isample].events->SetBranchAddress("runNum",&ETHrunNum);
83 <  allsamples.collection[isample].events->SetBranchAddress("lumi",&ETHlumi);
84 <  allsamples.collection[isample].events->SetBranchAddress("eventNum",&ETHevent);
85 <  allsamples.collection[isample].events->SetBranchAddress("genId1",&ETHgenId1);
86 <  allsamples.collection[isample].events->SetBranchAddress("genId2",&ETHgenId2);
80 >  float ETHBJetPt[30];
81 >  int ETHlumi,ETHrunNum,ETHgenId1,ETHgenId2;
82 >  ULong64_t ETHevent;
83 >  origtree->SetBranchAddress("runNum",&ETHrunNum);
84 >  origtree->SetBranchAddress("lumi",&ETHlumi);
85 >  origtree->SetBranchAddress("eventNum",&ETHevent);
86 >  origtree->SetBranchAddress("genId1",&ETHgenId1);
87 >  origtree->SetBranchAddress("genId2",&ETHgenId2);
88    
89  
90    float ETHmll;
91 <  allsamples.collection[isample].events->SetBranchAddress("mll",&ETHmll);
105 <
106 < /*
107 < e ist pt1, mu ist pt2
108 < pt1 ist subleading lepton, pt2 leading
109 < fuege mll zu
110 < correctedJZB
111 < */
112 <
113 <  
114 <  
91 >  origtree->SetBranchAddress("mll",&ETHmll);
92    
93 < //  int id1,id2;
94 <  
95 <  TTreeFormula *select = new TTreeFormula("select", "pfJetGoodNum>4", allsamples.collection[isample].events);
96 <  for (Int_t entry = 0 ; entry < allsamples.collection[isample].events->GetEntries() ; entry++) {
97 <   allsamples.collection[isample].events->LoadTree(entry);
93 >  float Aachenmll;
94 >  newTree->Branch("inv",&Aachenmll,"inv/F");
95 >
96 >  TTreeFormula *JZBExpression = new TTreeFormula("jzbexpression",jzbexpression.c_str(),origtree);
97 >  TTreeFormula *select = new TTreeFormula("select", eventselection&&"(passed_triggers||!is_data)", origtree);
98 >  for (Int_t entry = 0 ; entry < origtree->GetEntries() ; entry++) {
99 >   origtree->LoadTree(entry);
100     if (select->EvalInstance()) {
101 <     allsamples.collection[isample].events->GetEntry(entry);
102 <     cout << ETHrunNum << endl;
101 >     origtree->GetEntry(entry);
102 >     AachenWeight=ETHweight;
103 >     AachenchargeProduct=ETHch1*ETHch2;
104 >     if(ETHid1==ETHid2) {
105 >       //ee or mm event: pt1 is the subleading, pt2 the leading one (Aachen convention)
106 >       Aachenpt1=ETHpt2;
107 >       Aachenpt2=ETHpt1;
108 >       Aacheneta1=ETHeta2;
109 >       Aacheneta2=ETHeta1;
110 >      
111 >       Aachenid1=ETHiso2;
112 >       Aachenid2=ETHeta1;
113 >
114 >       AachenpdgId1=ETHgenId2;
115 >       AachenpdgId2=ETHgenId1;
116 >     } else {
117 >       //emu event
118 >       if(ETHid1==0) {
119 >         Aachenpt1=ETHpt1; //electron
120 >         Aacheneta1=ETHeta1;
121 >         Aachenid1=ETHiso1;
122 >        
123 >         Aachenpt2=ETHpt2;//muon
124 >         Aacheneta2=ETHeta2;
125 >         Aachenid2=ETHiso2;
126 >        
127 >         AachenpdgId1=ETHgenId1;
128 >         AachenpdgId2=ETHgenId2;
129 >
130 >        
131 >       } else {
132 >         Aachenpt1=ETHpt2; //electron
133 >         Aacheneta1=ETHeta2;
134 >         Aachenid1=ETHiso2;
135 >        
136 >         Aachenpt2=ETHpt1;//muon
137 >         Aacheneta2=ETHeta1;
138 >         Aachenid2=ETHiso1;
139 >        
140 >         AachenpdgId1=ETHgenId1;
141 >         AachenpdgId2=ETHgenId2;
142 >       }
143 >     }
144 >     Aachenht=ETHht;
145 >     Aachenmet=ETHmet[2];
146 >     Aachenjzb=JZBExpression->EvalInstance();
147 >     if(Aachenjzb<0 && ETHid1!=ETHid2) AachenWeight=-1 * AachenWeight;
148 >     Aachenmll=ETHmll;
149 >    
150 >     AachenpZeta=ETHeta;
151 >     AachenpZetaVis=0.0;
152 >     AachennJets=ETHnjets;
153 >     AachennBJets=ETHnBJets;
154 >     AachennVertices=ETHnVertices;
155 >     Aachenjet1pt=ETHjetPt[0];
156 >     Aachenjet2pt=ETHjetPt[1];
157 >     Aachenjet3pt=ETHjetPt[2];
158 >     Aachenjet4pt=ETHjetPt[3];
159 >
160 >     Aachenbjet1pt=ETHBJetPt[0];
161 >     AachenrunNr=ETHrunNum;
162 >     AachenlumiSec=ETHlumi;
163 >     AacheneventNr=ETHevent;
164 >    
165       newTree->Fill();
166     }
167    }
168    
169 <  if(EdgeFitter::MarcoDebug) cout << "     Reduced tree contains " << newTree->GetEntries() << " entries " << endl;
169 >  dout << "     Reduced tree (" << newTree->GetName() << ") contains " << newTree->GetEntries() << " entries " << endl;
170    return newTree;
171   }
172  
173 < void CastETHtoAachenNtuple() {
174 <  TTree *completetree;
175 <  write_warning(__FUNCTION__,"Need to make this function ready for scans as well (use signal from scan samples)");
176 <  TList *treelist = new TList;
177 <  int is_data=1;
178 <  for(int isample=0;isample<(int)allsamples.collection.size();isample++) {
179 <    if(!allsamples.collection[isample].is_active) continue;
139 <    if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
140 <    if(is_data==1&&allsamples.collection[isample].is_data==false) continue;//kick all samples that aren't data if we're looking for data.
141 <    if(is_data!=1&&allsamples.collection[isample].is_data==true) continue;//kick all data samples when looking for MC
142 <    if(is_data!=2&&allsamples.collection[isample].is_signal==true) continue;//remove signal sample if we don't want it.
143 <    if(EdgeFitter::MarcoDebug) cout << "Considering : " << allsamples.collection[isample].samplename << endl;
144 <    treelist->Add(SkimTreeAndAachifyIt(isample));
173 > void CastETHtoAachenNtuple(string jzbexpression, string filename) {
174 >  
175 >  TFile *sfile = new TFile(filename.c_str(),"READ");
176 >  if(!sfile) {
177 >    write_error(__FUNCTION__,"The file you want to Aachify is invalid!");
178 >    dout << "Error while trying to Aachify " << filename << endl;
179 >    return;
180    }
146  completetree = TTree::MergeTrees(treelist);
147  if(EdgeFitter::MarcoDebug) cout << "Complete tree now contains " << completetree->GetEntries() << " entries " << endl;
181    
182 <  TFile *f = new TFile("AachenTree.root","RECREATE");
150 <  completetree->Write();
151 <  f->Close();
182 >  dout << "Going to process file " << filename << " with JZB expression " << jzbexpression << endl;
183    
184 +  stringstream jzbcut;
185 +  jzbcut << "abs(" << jzbexpression << ")>100";
186 +  TCut basecut(("pfJetGoodNum40>=3&&"+jzbcut.str()).c_str());
187 +  
188 +  TTree *eetree = SkimTreeAndAachifyIt(basecut&&"id1==id2&&id1==0","EEDileptonTree",  jzbexpression,sfile);
189 +  TTree *mmtree = SkimTreeAndAachifyIt(basecut&&"id1==id2&&id1==1"  ,"MuMuDileptonTree",jzbexpression,sfile);
190 +  TTree *emtree = SkimTreeAndAachifyIt(basecut&&"id1!=id2"          ,"EMuDileptonTree", jzbexpression,sfile);
191 +    
192 +  TFile *f = new TFile("Aachen_Sample.root","RECREATE");
193 +  f->mkdir("ETH2AachenNtuples");
194 +  f->cd("ETH2AachenNtuples");
195 +  eetree->Write();
196 +  mmtree->Write();
197 +  emtree->Write();
198 +  f->Close();
199   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines