ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/Plotting/Modules/AachenCompatibility.C
Revision: 1.4
Committed: Wed Jan 9 09:27:49 2013 UTC (12 years, 3 months ago) by buchmann
Content type: text/plain
Branch: MAIN
Changes since 1.3: +23 -18 lines
Log Message:
Quick commit of WZ for Aachen - original version will be restored in a minute

File Contents

# User Rev Content
1 buchmann 1.3 TTree* SkimTreeAndAachifyIt(TCut eventselection, string treename, string jzbexpression, TFile *sfile) {
2 buchmann 1.2 TTree* newTree = new TTree(treename.c_str(),treename.c_str());
3 buchmann 1.1 float AachenWeight,AachenchargeProduct,Aachenpt1,Aachenpt2;
4    
5     newTree->Branch("weight",&AachenWeight,"weight/F");
6     newTree->Branch("chargeProduct",&AachenchargeProduct,"chargeProduct/F");
7     newTree->Branch("pt1",&Aachenpt1,"pt1/F");
8     newTree->Branch("pt2",&Aachenpt2,"pt2/F");
9 buchmann 1.2 float ETHweight,ETHpt1,ETHpt2;
10 buchmann 1.4 float ETHid1,ETHid2,ETHch1,ETHch2;
11 buchmann 1.3
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 buchmann 1.4 origtree->SetBranchAddress("tri_id2",&ETHid1);
20     origtree->SetBranchAddress("tri_id3",&ETHid2);
21 buchmann 1.3 origtree->SetBranchAddress("weight",&ETHweight);
22 buchmann 1.4 origtree->SetBranchAddress("tri_pt2",&ETHpt1);
23     origtree->SetBranchAddress("tri_pt3",&ETHpt2);
24 buchmann 1.3 origtree->SetBranchAddress("ch1",&ETHch1);
25     origtree->SetBranchAddress("ch2",&ETHch2);
26 buchmann 1.1
27    
28     float Aacheneta1,Aacheneta2,Aachenid1,Aachenid2,Aachenjzb,Aachenht,Aachenmet;
29     newTree->Branch("eta1",&Aacheneta1,"eta1/F");
30     newTree->Branch("eta2",&Aacheneta2,"eta2/F");
31     newTree->Branch("id1",&Aachenid1,"id1/F");
32     newTree->Branch("id2",&Aachenid2,"id2/F");
33     newTree->Branch("jzb",&Aachenjzb,"jzb/F");
34     newTree->Branch("ht",&Aachenht,"ht/F");
35     newTree->Branch("met",&Aachenmet,"met/F");
36    
37     float ETHeta1,ETHeta2,ETHiso1,ETHiso2,ETHht;
38     float ETHjzb[30];
39     float ETHmet[30];
40 buchmann 1.4 origtree->SetBranchAddress("tri_eta2",&ETHeta1);
41     origtree->SetBranchAddress("tri_eta3",&ETHeta2);
42     origtree->SetBranchAddress("tri_iso2",&ETHiso1);
43     origtree->SetBranchAddress("tri_iso3",&ETHiso2);
44     origtree->SetBranchAddress("pfTightHT",&ETHht);
45 buchmann 1.3 origtree->SetBranchAddress("met",&ETHmet);
46 buchmann 1.1
47    
48    
49     float AachenpZeta,AachenpZetaVis,AachennJets,AachennBJets,AachennVertices,Aachenjet1pt,Aachenjet2pt,Aachenjet3pt,Aachenjet4pt;
50     newTree->Branch("pZeta",&AachenpZeta,"pZeta/F");
51     newTree->Branch("pZetaVis",&AachenpZetaVis,"pZetaVis/F");
52     newTree->Branch("nJets",&AachennJets,"nJets/F");
53     newTree->Branch("nBJets",&AachennBJets,"nBJets/F");
54     newTree->Branch("nVertices",&AachennVertices,"nVertices/F");
55     newTree->Branch("jet1pt",&Aachenjet1pt,"jet1pt/F");
56     newTree->Branch("jet2pt",&Aachenjet2pt,"jet2pt/F");
57     newTree->Branch("jet3pt",&Aachenjet3pt,"jet3pt/F");
58     newTree->Branch("jet4pt",&Aachenjet4pt,"jet4pt/F");
59    
60 buchmann 1.2 float ETHeta;
61     int ETHnjets,ETHnBJets,ETHnVertices;
62 buchmann 1.1 float ETHjetPt[30];
63 buchmann 1.3 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 buchmann 1.1
69    
70    
71     float Aachenbjet1pt;
72     int AachenrunNr,AachenlumiSec,AachenpdgId1,AachenpdgId2,AacheneventNr;
73     newTree->Branch("bjet1pt",&Aachenbjet1pt,"bjet1pt/F");
74     newTree->Branch("runNr",&AachenrunNr,"runNr/I");
75     newTree->Branch("lumiSec",&AachenlumiSec,"lumiSec/I");
76     newTree->Branch("eventNr",&AacheneventNr,"eventNr/I");
77     newTree->Branch("pdgId1",&AachenpdgId1,"pdgId1/I");
78     newTree->Branch("pdgId2",&AachenpdgId2,"pdgId2/I");
79    
80 buchmann 1.2 float ETHBJetPt[30];
81     int ETHlumi,ETHrunNum,ETHgenId1,ETHgenId2;
82     ULong64_t ETHevent;
83 buchmann 1.3 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 buchmann 1.1
89    
90     float ETHmll;
91 buchmann 1.4 origtree->SetBranchAddress("tri_submll",&ETHmll);
92 buchmann 1.2
93     float Aachenmll;
94     newTree->Branch("inv",&Aachenmll,"inv/F");
95    
96 buchmann 1.3 TTreeFormula *JZBExpression = new TTreeFormula("jzbexpression",jzbexpression.c_str(),origtree);
97 buchmann 1.4 TTreeFormula *select = new TTreeFormula("select", eventselection, origtree);
98 buchmann 1.3 for (Int_t entry = 0 ; entry < origtree->GetEntries() ; entry++) {
99     origtree->LoadTree(entry);
100 buchmann 1.2 if (select->EvalInstance()) {
101 buchmann 1.3 origtree->GetEntry(entry);
102 buchmann 1.2 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 buchmann 1.1
114 buchmann 1.2 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 buchmann 1.1
130 buchmann 1.2
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 buchmann 1.4 // Aachenjzb=JZBExpression->EvalInstance();
147     // if(Aachenjzb<0 && ETHid1!=ETHid2) AachenWeight=-1 * AachenWeight;
148 buchmann 1.2 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 buchmann 1.1 newTree->Fill();
166     }
167     }
168    
169 buchmann 1.2 dout << " Reduced tree (" << newTree->GetName() << ") contains " << newTree->GetEntries() << " entries " << endl;
170 buchmann 1.1 return newTree;
171     }
172    
173 buchmann 1.3 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     }
181    
182     dout << "Going to process file " << filename << " with JZB expression " << jzbexpression << endl;
183 buchmann 1.1
184 buchmann 1.2 stringstream jzbcut;
185     jzbcut << "abs(" << jzbexpression << ")>100";
186 buchmann 1.4 // TCut basecut(("pfJetGoodNum40>=3&&"+jzbcut.str()).c_str());
187 buchmann 1.2
188 buchmann 1.4 TCut BasicCut("leptonNum>2&&tri_pt1>30&&tri_pt2>20&&tri_pt3>20");
189     TCut Selection("abs(tri_mlll-91)>30 && tri_mT>40 && met[4] > 30 && abs(tri_mll-91)<10 && tri_submll > 10");
190     TCut basecut(BasicCut&&Selection);
191    
192    
193     TTree *eetree = SkimTreeAndAachifyIt(basecut&&"tri_id2==tri_id3&&tri_id2==0","EEDileptonTree", jzbexpression,sfile);
194     TTree *mmtree = SkimTreeAndAachifyIt(basecut&&"tri_id2==tri_id3&&tri_id2==1" ,"MuMuDileptonTree",jzbexpression,sfile);
195     TTree *emtree = SkimTreeAndAachifyIt(basecut&&"tri_id2!=tri_id3" ,"EMuDileptonTree", jzbexpression,sfile);
196 buchmann 1.3
197 buchmann 1.2 TFile *f = new TFile("Aachen_Sample.root","RECREATE");
198     f->mkdir("ETH2AachenNtuples");
199     f->cd("ETH2AachenNtuples");
200     eetree->Write();
201     mmtree->Write();
202     emtree->Write();
203 buchmann 1.1 f->Close();
204     }