StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMcJetCalibMaker.cxx
1 // $Id: StMcJetCalibMaker.cxx,v 1.1 2010/05/01 01:31:45 balewski Exp $
2 //
3 //*-- Author : Jan Balewski, MIT
4 //
5 #include <StMuDSTMaker/COMMON/StMuDstMaker.h>
6 #include <StMuDSTMaker/COMMON/StMuDst.h>
7 #include <StMuDSTMaker/COMMON/StMuEvent.h>
8 #include <StMuDSTMaker/COMMON/StMuPrimaryVertex.h>
9 
10 //need these to get MC record
11 #include "tables/St_g2t_tpc_hit_Table.h"
12 #include "StMcEventMaker/StMcEventMaker.h"
13 #include "StMcEvent/StMcEvent.hh"
14 #include "StMcEvent/StMcVertex.hh"
15 #include "StMcEvent/StMcTrack.hh"
16 
17 
18 #include "St2009WMaker.h"
19 #include "St2009WjjMaker.h" // for jetEcorr
20 #include "StMcJetCalibMaker.h"
21 #include <StSpinPool/StJets/StJet.h>
22 
23 ClassImp(StMcJetCalibMaker)
24 
25 //________________________________________________________
26 //
27 StMcJetCalibMaker::StMcJetCalibMaker(const char *name):StMaker(name){
28  wMK=0; wjjMK=0;HList=0;
29  core=name;
30  par_vertexZ=70;// cm
31  par_verZerr=1;//cm
32  par_delRmax=0.1;// match gen & reco jets
33  par_corLevel=0; // level of jet energy correction
34  par_jetEtaLow=-1.5; par_jetEtaHigh=2;
35  isMC=1;
36 }
37 
38 
39 //_____________________________________________________________________________
40 //
41 Int_t
42 StMcJetCalibMaker::Init(){
43  assert(wMK);
44  if( par_corLevel) assert(wjjMK);
45  assert(HList);
46  initHistos();
47 
48  return StMaker::Init();
49 }
50 
51 
52 //_____________________________________________________________________________
53 //
54 Int_t
55 StMcJetCalibMaker::FinishRun (int runNo){
56  return kStOK;
57 }
58 
59 //_____________________________________________________________________________
60 //
61 Int_t
62 StMcJetCalibMaker::InitRun (int runNo){
63 
64 
65  LOG_INFO<<GetName()<<Form("::InitRun(%d),calib params: |geant vertZ|<%.0f cm |zG-zR|<%.1f cm, jet: eta=[%.1f,%1f], delR(reco-gen)<%.2f \n JES corr level=%d",
66  runNo,par_vertexZ ,par_verZerr,par_jetEtaLow,par_jetEtaHigh,
67  par_delRmax,
68  par_corLevel
69  )<<endm;
70  assert(isMC);
71  return kStOK;
72 }
73 
74 //_____________________________________________________________________________
75 //
76 Int_t
78  calibrate();
79 
80  return kStOK;
81 }
82 
83 //_____________________________________________________________________________
84 //
85 void
86 StMcJetCalibMaker::calibrate(){
87  StMcEvent* mMcEvent = 0;
88  mMcEvent = (StMcEvent*) StMaker::GetChain()->GetDataSet("StMcEvent");
89  if(mMcEvent==0) return; // STARNGE - fix it
90  assert(mMcEvent);
91 
92 
93  //........ restrict M-C vertex .........
94 
95  StMcVertex *V=mMcEvent->primaryVertex();
96  TVector3 mcV=TVector3(V->position().x(),V->position().y(),V->position().z());
97  //printf("MC ver=%f %f %f\n", mcV.x(), mcV.y(), mcV.z());
98 
99  hA[0]->Fill("inp",1.);
100  hA[1]->Fill(mcV.z());
101  if(fabs(mcV.z()) > par_vertexZ) return;
102  hA[0]->Fill("verG",1.);
103 
104 #if 0
105  for(unsigned int i=0;i<mMcEvent->tracks().size();i++){//loop tracks
106  StMcTrack* mcTrack = mMcEvent->tracks()[i];
107  int pdgId=mcTrack->pdgId();
108  const StLorentzVectorF &p4=mcTrack-> fourMomentum();
109  printf("i=%d pdgId=%d p=%f %f %f m=%f\n",i,pdgId,p4.x(),p4.y(),p4.z(),p4.m());
110  if(i>15) break;
111  }
112 #endif
113 
114  //........ select Pythia particles .........
115  int type=0; // QCD process
116  int pdgId=mMcEvent->tracks()[6]->pdgId(); // boson?
117  if(pdgId==23) type=1; //Z
118  if( pdgId==-24 || pdgId==24 ) type=2;// W+, W-
119 
120  // A+B --> C+D or A+B-->W --> C+D
121 
122  if(mMcEvent->tracks().size()<10) return;
123  // access 2:2 kinematics for W, Z production or QCD scattering
124  // StMcTrack* mctA= mMcEvent->tracks()[4]; // q or qbar 1
125  // StMcTrack* mctB= mMcEvent->tracks()[5]; // q or qbar 2
126 
127  StMcTrack* mctW=0, *mctC=0, *mctD=0;
128  if(type) {// Z,W+, or W-
129  mctW=mMcEvent->tracks()[6]; // boson
130  mctC= mMcEvent->tracks()[7];// decay1 (lepton or q or qbar)
131  mctD= mMcEvent->tracks()[8];// decay 2 product
132  hA[0]->Fill("W,Z",1.);
133  } else { // QCD process
134  mctC= mMcEvent->tracks()[6];// paron1
135  mctD= mMcEvent->tracks()[7];// parton 2
136  }
137 
138  //... define matching array for gen vs. thrown jets
139  const int mxGJ=2, mxRJ=4;
140  int nGJ=0,nRJ=0 , mrJI[mxGJ];;
141  TLorentzVector gJA[mxGJ], rJA[mxRJ];
142 
143  float delRA[mxGJ][mxRJ],delRAc[mxGJ][mxRJ];
144  memset(mrJI,-1,sizeof(mrJI)); // clear all gen-jets as not-matched
145 
146  for(int k=0;k<2;k++) { // find parton in the barrel
147  const StLorentzVectorF &ttC=mctC-> fourMomentum();
148  const StLorentzVectorF &ttD=mctD-> fourMomentum();
149  TLorentzVector gJ;
150  if(k==0) gJ=TLorentzVector(ttC.px(),ttC.py(),ttC.pz(),ttC.e());
151  if(k==1) gJ=TLorentzVector(ttD.px(),ttD.py(),ttD.pz(),ttD.e());
152  hA[11]->Fill(gJ.Eta(),gJ.Phi());
153  if(gJ.Eta()<par_jetEtaLow ) continue;
154  if(gJ.Eta()>par_jetEtaHigh ) continue;
155  assert(nGJ<mxGJ);
156  gJA[nGJ++]=gJ;
157  hA[4]->Fill(gJ.Pt(),gJ.Eta());
158  }
159 
160  if(!nGJ) return;
161  hA[0]->Fill("etaG",1.);
162 
163  if(type) {
164  const StLorentzVectorF &pW=mctW-> fourMomentum();
165  hA[10]->Fill(pW.m());
166  }
167 
168 
169  //....... find reco 1st vertex .....
170 
171  int nInpPrimV=wMK->mMuDstMaker->muDst()->numberOfPrimaryVertices();
172  int nVer=0;
173  for(int iv=0;iv<nInpPrimV;iv++) {
174  if(nVer) break; // consider only 1st valid vertex
175  StMuPrimaryVertex* V= wMK->mMuDstMaker->muDst()->primaryVertex(iv);
176  assert(V);
177  wMK->mMuDstMaker->muDst()->setVertexIndex(iv);
178  float rank=V->ranking();
179  if (rank<=0) continue;
180  const StThreeVectorF &r=V->position();
181  hA[2]->Fill(r.z()-mcV.z());
182  if(fabs(r.z()-mcV.z()) > par_verZerr) continue;
183  nVer++; // count valid vertices
184  //printf(" reco ver=%f %f %f\n", r.x(), r.y(), r.z());
185  }
186 
187  if(nVer<=0) return;
188  hA[0]->Fill("verR",1.);
189 
190 
191  //....... select reco jets ........
192 
193  TClonesArray* jets = wMK->getJets("ConeJets12_100"); // select jet-tree type
194  int nJets= wMK->nJets;
195  //printf("nJets=%d n2J=%.0f\n",nJets, hA[0]->GetBinContent(1));
196 
197  if(nJets<1) return;
198  hA[0]->Fill("anyJ",1.);
199  if(nJets>=2) hA[0]->Fill("mulJ",1.);
200 
201  // ..... compute R-distance for all possible pairs (gen_i,reco_j) ...
202  float par_recJetPtMin=5.;
203 
204  for (int ir=0; ir< nJets; ir++){
205  StJet* jet = (StJet*)jets->At(ir);
206  TLorentzVector rJ = *jet;
207  if(par_corLevel) rJ=wjjMK->trueJet(rJ);// apply JES correction
208 
209  if(rJ.Pt()<par_recJetPtMin) continue;
210  if(nRJ>=mxRJ) continue; // skip
211  for(int ig=0;ig<nGJ;ig++) // compute R
212  delRA[ig][nRJ]=gJA[ig].DrEtaPhi(rJ);
213  rJA[nRJ++]=rJ; // store jet
214  }
215  // printf("aa nRJ=%d\n",nRJ);
216 
217 
218  memcpy(delRAc,delRA,sizeof(delRA));// just for QA & printouts
219 
220  //...... select best matching starting from lowest minimum in R
221  int nMJ=0;
222  while(nMJ<nRJ) {
223  float minR=1e37;
224  int irm=-1,igm=-1;
225  for (int ir=0; ir< nRJ; ir++)
226  for(int ig=0;ig<nGJ;ig++) {
227  if(delRA[ig][ir]>minR) continue;
228  minR= delRA[ig][ir];
229  igm=ig; irm=ir;
230  }
231  mrJI[igm]=irm;
232  nMJ++;
233  // disable this this pair
234  for (int ir=0; ir< nRJ; ir++) delRA[igm][ir]=99999;
235  for(int ig=0;ig<nGJ;ig++) delRA[ig][irm]=99999;
236 
237  }// end of while
238 
239  //.... work only with matched jets
240  for(int ig=0;ig<nGJ;ig++) {
241  if(mrJI[ig]<0) continue;
242  int ir=mrJI[ig];
243  float delR=delRAc[ig][ir];
244  TLorentzVector gJ=gJA[ig], rJ=rJA[ ir];
245 
246  hA[3]->Fill(delR);
247  if(delR>par_delRmax) continue;
248  hA[0]->Fill("delR",1.);
249 
250 
251 
252  hA[15]->Fill(gJ.Pt());
253  hA[12]->Fill(gJ.Pt(),gJ.Eta());
254  hA[21]->Fill(gJ.E(),rJ.E());
255  hA[22]->Fill(gJ.Pt(),rJ.Pt());
256 
257 
258  int iEta=(rJ.Eta()+1.2)/0.4;
259  if(iEta<0) iEta=0;
260  if(iEta>=mxEta) iEta=mxEta-1;
261  hA[40+iEta]->Fill(gJ.Pt(),rJ.Pt());
262 
263  float ratioPT=rJ.Pt()/gJ.Pt();
264  //float neutFrac=->neutralFraction();
265  //float chargFrac=jet->chargedFraction();
266  hA[16]->Fill(ratioPT);
267 
268  //... neutral....
269  //hA[26]->Fill(ratio*neutFrac);
270 
271  //.... charged....
272  //hA[36]->Fill(ratio*chargFrac);
273 
274  }
275 
276 #if 0 // pppppppppp test printing
277  TLorentzVector pG;
278  printf("gen type=%d pdgId=%d eveID=%d\n",type,pdgId,wMK->mMuDstMaker->muDst()->event()->eventId());
279  if(type && par_corLevel==0) {
280  const StLorentzVectorF &ttW=mctW-> fourMomentum();
281  pG=TLorentzVector(ttW.px(),ttW.py(),ttW.pz(),ttW.e());
282  printf("gen W, P=%.1f %.1f %.1f E=%.1f M=%.1f PT=%.1f eta=%.2f phi/deg=%.0f\n",pG.X(),pG.Y(),pG.Z(),pG.E(), pG.M(),pG.Pt(),pG.Eta(), pG.Phi()/3.14*180);
283  }
284  for(int k=0;k<2;k++) { // find parton in the barrel
285  const StLorentzVectorF &ttC=mctC-> fourMomentum();
286  const StLorentzVectorF &ttD=mctD-> fourMomentum();
287  if(k==0) pG=TLorentzVector(ttC.px(),ttC.py(),ttC.pz(),ttC.e());
288  if(k==1) pG=TLorentzVector(ttD.px(),ttD.py(),ttD.pz(),ttD.e());
289  printf("gen q=%c, P=%.1f %.1f %.1f E=%.1f M=%.1f PT=%.1f eta=%.2f phi/deg=%.0f\n",'C'+k,pG.X(),pG.Y(),pG.Z(),pG.E(), pG.M(),pG.Pt(),pG.Eta(), pG.Phi()/3.14*180);
290  }
291 
292 
293  printf("reco inp nJ=%d eveID=%d: selected nGJ=%d nRJ=%d\n",nJets,wMK->mMuDstMaker->muDst()->event()->eventId(),nGJ,nRJ);
294  for (int i_jet=0; i_jet< nJets; i_jet++){
295  StJet* jet = (StJet*)jets->At(i_jet);
296  TLorentzVector J = *jet;
297  float neutPt=jet->neutralFraction()*J.Pt();
298  if(J.Pt()<5) continue;
299  printf("recJ=%d, P=%.1f %.1f %.1f E=%.1f M=%.1f PT=%.1f neutPt=%.1f eta=%.2f phi/deg=%.0f\n",i_jet,J.X(),J.Y(),J.Z(),J.E(), J.M(),J.Pt(),neutPt,J.Eta(), J.Phi()/3.14*180);
300  }
301 
302  printf("matching gen-->reco :\n");
303  for(int ig=0;ig<nGJ;ig++) {
304  printf("gen J PT=%.1f : delR(ir)= ",gJA[ig].Pt());
305  for (int ir=0; ir< nRJ; ir++){
306  if( mrJI[ig]==ir) printf("*");
307  else printf(" ");
308  printf("%.2f, ", delRAc[ig][ir]);
309  }
310  if(mrJI[ig]<0) printf("no match");
311  else printf(" rec PT=%.1f", rJA[mrJI[ig]].Pt());
312  printf("\n");
313  }
314  printf("\n---------\n");
315 
316 #endif
317 
318 
319 
320 #if 0
321 
322 
323 
324 
325  //...... compute correction .......
326  TLorentzVector pJ=pJreco; //1:1
327  float cor1=1./St2009WjjMaker::jetEcorr(pJreco.E());
328 
329  // apply all corrections
330  if(par_corLevel) pJ=cor1*pJ;
331 
332  float neutFrac=jet->neutralFraction();
333  float chargFrac=jet->chargedFraction();
334 
335  float frac=pJ.E()/pG.E();
336  if(fabs(frac-1.)> par_ptMargin) continue;
337 
338  if(delR>par_delRmargin) continue;
339  hA[3]->Fill(delR);
340  if(delR>par_delRmax) continue;
341  hA[0]->Fill("delR",1.);
342  hA[12]->Fill(pG.Pt(),pG.Eta());
343 
344  //..... study energy resolution.....
345  //printf("%d %f %f %f \n",par_corLevel,frac,pJ.E(),pG.E());
346 
347  //...... full jet energy .....
348  hA[16]->Fill(frac);
349  hA[17]->Fill(frac,pG.Eta());
350  hA[18]->Fill(pG.Eta()-pJ.Eta(),pG.Eta());
351  hA[19]->Fill(pG.DeltaPhi(pJ)/3.1416*180 ,pG.Eta());
352  hA[21]->Fill(pG.E(),pJ.E());
353  hA[22]->Fill(pG.Pt(),pJ.Pt());
354 
355  int iEta=(pJ.Eta()+1.)/0.5;
356  if(iEta<0) iEta=0;
357  if(iEta>=mxEta) iEta=mxEta-1;
358  hA[40+iEta]->Fill(pG.Pt(),pJ.Pt());
359 
360  //... neutral....
361  hA[26]->Fill(frac*neutFrac);
362  hA[27]->Fill(pJ.Eta(),pJ.E()*neutFrac);
363 
364  //.... charged....
365  hA[36]->Fill(frac*chargFrac);
366  hA[37]->Fill(pJ.Eta(),pJ.E()*chargFrac);
367  break;
368  }
369 
370 #endif
371 
372  /* TLorentzVector (px,py,pz,E).
373  TLorentzVector v4(TVector3(1., 2., 3.),4.);
374  v.SetVect(TVector3(1,2,3));
375  v.SetXYZT(x,y,z,t);
376  v.SetPxPyPzE(px,py,pz,e);
377  v.SetXYZM(x,y,z,m); // -> v=(x,y,z,e=Sqrt(x*x+y*y+z*z+m*m))
378  */
379 
380 
381 
382  //::::::::::::::::::::::::::::::::::::::::::::::::
383  //:::::accepted W events for x-section :::::::::::
384  //::::::::::::::::::::::::::::::::::::::::::::::::
385 
386 }
387 
388 
389 // $Log: StMcJetCalibMaker.cxx,v $
390 // Revision 1.1 2010/05/01 01:31:45 balewski
391 // added W->JJ code & JES calibration
392 //
393 // Revision 1.1 2010/04/16 01:04:43 balewski
394 // start
395 //
396 
397 
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
StMuDst * muDst()
Definition: StMuDstMaker.h:425
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
Definition: StMcTrack.hh:144
virtual Int_t Make()
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:40
spin sorting of W&#39;s
static void setVertexIndex(Int_t vtx_id)
Set the index number of the current primary vertex (used by both primaryTracks() functions and for St...
Definition: StMuDst.cxx:273
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169
Definition: StJet.h:91