StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St2009WjjMaker.cxx
1 // $Id: St2009WjjMaker.cxx,v 1.5 2010/06/25 15:42:09 balewski Exp $
2 //
3 //*-- Author : Jan Balewski, MIT
4 //
5 #include <math.h>
6 
7 #include <StMuDSTMaker/COMMON/StMuDstMaker.h>
8 #include <StMuDSTMaker/COMMON/StMuDst.h>
9 #include <StMuDSTMaker/COMMON/StMuEvent.h>
10 #include <StMuDSTMaker/COMMON/StMuTriggerIdCollection.h>
11 
12 #include <StSpinPool/StSpinDbMaker/StSpinDbMaker.h>
13 #include <StMuDSTMaker/COMMON/StMuPrimaryVertex.h>
14 
15 #include "St2009WMaker.h"
16 
17 #include "St2009WjjMaker.h"
18 #include <StSpinPool/StJets/StJet.h>
19 
20 ClassImp(St2009WjjMaker)
21 
22 //_____________________________________________________________________________
23 //
24 St2009WjjMaker::St2009WjjMaker(const char *name):StMaker(name){
25  wMK=0;HList=0;
26  core=name;
27 
28  par_jetPtLow=5.; par_jetPtHigh=60.;// GeV/c
29  par_jetEtaLow=1.0; par_jetEtaHigh=1.8;
30 
31  par_djPtLow=1.; par_djPtHigh=40;// GeV/c
32  par_djPzLow=3; par_djPzHigh=90; // GeV/c
33  par_djEtaMin=0.1;
34  par_etaSumLow=0.01; par_etaSumHigh=2.5;
35 
36  par_spinSort=false;
37  par_vertexZ=100;// cm
38  isMC=0;
39  spinDb=0;
40  par_corLevel=0; // default no corrections
41  mJEScorrFile="fixMe"; memset(mJEScorrH,0,sizeof(mJEScorrH));
42  }
43 
44 
45 //_____________________________________________________________________________
46 //
47 Int_t
48 St2009WjjMaker::Init(){
49  assert(wMK);
50  assert(HList);
51  initHistos();
52  nRun=0;
53 
54  LOG_INFO<<GetName()<<Form("::Init JES corr=%d, input=%s",par_corLevel,mJEScorrFile.Data())<<endl;;
55  if(par_corLevel) {
56  TFile *fd=new TFile(mJEScorrFile); assert(fd);
57  for(int i=0;i<mxJESeta;i++) {
58  TString tit= "jesCorr_iEta"; tit+=i;
59  mJEScorrH[i]=(TH1F*)fd->Get(tit); assert(mJEScorrH[i]);
60  mJEScorrH[i]->Print();
61 
62  // add derivate for interpolation
63  TH1F *h=mJEScorrH[i];
64  TAxis *ax=h->GetXaxis(); int nb=ax->GetNbins();
65  for(int k=1;k<=nb-1;k++) {
66  float x1=ax->GetBinCenter(k);
67  float x2=ax->GetBinCenter(k+1);
68  float y1=h->GetBinContent(k);
69  float y2=h->GetBinContent(k+1);
70  float tg=(y2-y1)/(x2-x1);
71  h->SetBinError(k,tg);
72  }
73  } // end of loop over eta bins
74  }// end of JES initialialization
75 
76  return StMaker::Init();
77 }
78 
79 //_____________________________________________________________________________
80 //
81 TLorentzVector
82 St2009WjjMaker::trueJet( TLorentzVector rJ) {
83  if (par_corLevel==0) return rJ;
84  int iEta=(rJ.Eta()+1.2)/0.4;
85  if(iEta<0) iEta=0;
86  if(iEta>=mxJESeta ) iEta=mxJESeta-1;
87  TH1F* h=mJEScorrH[iEta];
88  float rPt=rJ.Pt();
89  int bin=h->FindBin(rPt);
90  float x1=h->GetBinCenter(bin);
91 
92  if(x1>rPt && bin>1) { // use lower pT bin for interpolation
93  bin--;
94  x1=h->GetBinCenter(bin);
95  }
96  float y1=h->GetBinContent(bin);
97  float tg=h->GetBinError(bin);
98 
99  float truePt=y1+ tg*(rPt-x1);
100 
101  float fac=truePt/rJ.Pt();
102  //printf(" rPt=%.2f tPt=%.2f ratio=%.3f\n",rJ.Pt(),truePt ,fac);
103 
104 
105  return fac*rJ;
106 }
107 
108 
109 //_____________________________________________________________________________
110 //
111 Int_t
112 St2009WjjMaker::FinishRun (int runNo){
113  char txt[1000];
114 
115  if(par_spinSort) {
116  sprintf(txt,"events T= %d %d",Tfirst,Tlast);
117  printf("Finish run=%d , events time range %s\n",runNo,txt);
118  hbxIdeal->GetYaxis()->SetTitle(txt);
119  }
120  return kStOK;
121 }
122 
123 //_____________________________________________________________________________
124 //
125 Int_t
126 St2009WjjMaker::InitRun (int runNo){
127 
128  if(par_spinSort) {
129  assert(spinDb);
130  assert(runNo>= 10081007); // F10407, first pp500 long fill with defined pol pattern
131  assert(runNo<=10103046); // F10536, last pp500 fill in run9
132 
133  char txt[1000],txt0[100];
134  sprintf(txt0,"bxIdeal%d",nRun);
135  sprintf(txt,"intended fill pattern R%d-%d vs. bXing; %s", runNo,nRun,spinDb->getV124comment());
136  nRun++;
137  Tfirst=int(2e9); Tlast=-Tfirst;
138  hbxIdeal=new TH1F(core+txt0,txt,128,-0.5,127.5);
139  hbxIdeal->SetFillColor(kYellow);
140  HList->Add(hbxIdeal);
141 
142  spinDb->print(0); // 0=short, 1=huge
143  for(int bx=0;bx<120;bx++){
144  if(spinDb->isBXfilledUsingInternalBX(bx)) hbxIdeal->Fill(bx);
145  }
146 
147  sprintf(txt,"bXing= bx7+off=%d",spinDb->BX7offset());
148  hA[4]->GetXaxis()->SetTitle(txt);
149  } // end of spin sort
150 
151 
152  LOG_INFO<<GetName()<<Form("::InitRun(%d) done, W->jet+jet sorting params: doSpinSort=%d |vertZ|<%.0f cm,\n jetPt=[%.1f,%.1f] GeV/c, jetEta=[%.1f,%.1f]\n DJ: pT=[%.1f,%.1f] GeV/c, |Pz|=[%.1f,%.1f] GeV/c, eta1+2=[%.1f,%.1f]",
153  runNo,par_spinSort,par_vertexZ ,par_jetPtLow,par_jetPtHigh,par_jetEtaLow,par_jetEtaHigh,
154  par_djPtLow,par_djPtHigh,par_djPzLow,par_djPzHigh,par_etaSumLow, par_etaSumHigh
155  )<<endm;
156  return kStOK;
157 }
158 
159 //_____________________________________________________________________________
160 //
161 Int_t
163  int T=wMK->mMuDstMaker->muDst()->event()->eventInfo().time();
164  if(Tlast<T) Tlast=T;
165  if(Tfirst>T) Tfirst=T;
166 
167  bXingSort();
168  return kStOK;
169 }
170 
171 //_____________________________________________________________________________
172 //
173 void
174 St2009WjjMaker::bXingSort(){
175  //has access to whole W-algo-maker data via pointer 'wMK'
176 
177  hA[0]->Fill("inp",1.);
178 
179  //...... trigger .........
180 
181  if(!isMC ){ // fixed n the middle of processing
182  StMuEvent* muEve = wMK->mMuDstMaker->muDst()->event();
183  StMuTriggerIdCollection *tic=&(muEve->triggerIdCollection());
184  assert(tic);
185  const StTriggerId &l1=tic->l1();
186  vector<unsigned int> idL=l1.triggerIds();
187  // printf("nTrig=%d, trigID: ",idL.size());
188  int trgOK=0;
189  for(unsigned int i=0;i<idL.size(); i++){
190  if(idL[i]==230420) trgOK+=1; // AJP
191  if(idL[i]==230411) trgOK+=2; // JP2
192  }
193  if(trgOK) hA[0]->Fill("trig",1.);
194  // tmp, do not abort events here, now chain is trigger filtering
195  }
196 
197  //....... find vertex .....
198  int nInpPrimV=wMK->mMuDstMaker->muDst()->numberOfPrimaryVertices();
199  int nVer=0;
200  for(int iv=0;iv<nInpPrimV;iv++) {
201  if(nVer) break; // tmp - consider only 1st vertex, since jets are made only for the 1st vertex
202  StMuPrimaryVertex* V= wMK->mMuDstMaker->muDst()->primaryVertex(iv);
203  assert(V);
204  wMK->mMuDstMaker->muDst()->setVertexIndex(iv);
205  float rank=V->ranking();
206  if (rank<=0) continue;
207  const StThreeVectorF &r=V->position();
208  if(fabs(r.z()) > par_vertexZ) continue;
209  nVer++; // count valid vertices
210  }
211 
212  if(nVer<=0) return;
213  hA[0]->Fill("vert",1.);
214 
215  //......... require: vertex is reasonable .......
216 
217 
218  //****loop over jet branch with B+EEMC****
219  if(GetMaker("JetReader")==0) return; // most likely jet-maker was not in the chain
220  TClonesArray* jets = wMK->getJets("ConeJets12_100"); // select specific jet-tree type
221  if(jets==0) return; // most likely jet-maker was not in the chain
222  int nJets= wMK->nJets;
223  //printf("nJets=%d n2J=%.0f\n",nJets, hA[0]->GetBinContent(1));
224  if(nJets<1) return;
225  hA[0]->Fill("anyJ",1.);
226  if(nJets<2) return;
227  hA[0]->Fill("mulJ",1.);
228 
229  const int mxJ=2;
230  TLorentzVector jet[mxJ];
231  int nJ=0;
232  for (int i_jet=0; i_jet< nJets; i_jet++){// try to find 2 jets passing cuts
233  TLorentzVector Jreco = *((StJet*)jets->At(i_jet));
234 
235  //...... compute correction .......
236  TLorentzVector J=Jreco; //1:1
237  J=trueJet(J);
238 
239  if(J.Pt()<par_jetPtLow) continue;
240 
241  if(nJ>=mxJ) { // 3rd jet, kill for now
242  hA[0]->Fill("J3",1.);
243  hA[6]->Fill(fabs(jet[0].DeltaPhi(J)),fabs(jet[1].DeltaPhi(J)));
244  return;
245  }
246  jet[nJ++]=J;
247  if(nJ==1)hA[0]->Fill("J1",1.);
248  }
249 
250  if(nJ<mxJ) return;
251  hA[0]->Fill("J2",1.);
252 
253  // 2 jet-event, process it
254  assert(nJ<=mxJ);
255 
256  // decide which is jet #1
257  if( fabs(jet[0].Eta()) > fabs(jet[1].Eta()) ) {// swap
258  TLorentzVector J=jet[0];
259  jet[0]=jet[1]; jet[1]=J;
260  }
261 
262  // now jet1 has smaller |eta|
263  hA[10]->Fill(jet[0].Et(),jet[0].Eta());
264  hA[11]->Fill(jet[1].Et(),jet[1].Eta());
265  hA[17]->Fill(jet[0].E(),jet[1].E());
266  hA[18]->Fill(jet[0].Pt(),jet[1].Pt());
267  hA[19]->Fill(jet[0].Eta(),jet[1].Eta());
268  float phiCDdeg=jet[0].DeltaPhi(jet[1])/3.1416*180.;
269  if(phiCDdeg<-90) phiCDdeg+=360; // choose different phi range
270  hA[13]->Fill(phiCDdeg);
271 
272 
273  TLorentzVector diJet=jet[0]+jet[1];
274  float invM=sqrt(diJet*diJet);
275 
276  hA[14]->Fill(invM);
277  hA[16]->Fill(invM, diJet.Pt());
278  hA[15]->Fill( diJet.Z(),diJet.Pt());
279 
280 
281  // for Pavel N.
282  if(invM<60) {
283  hA[21]->Fill(diJet.Pt());
284  hA[22]->Fill(fabs(jet[0].DeltaPhi(jet[1])));
285  hA[23]->Fill(jet[0].Eta()-jet[1].Eta());
286  hA[24]->Fill(jet[0].Eta(),jet[1].Eta());
287  }
288 
289  if(par_spinSort) {//........ do spin sorting
290 
291  assert(spinDb->isValid()); // all 3 DB records exist
292  assert(spinDb->isPolDirLong()); // you do not want mix Long & Trans by accident
293  int bx48=wMK->wEve.bx48;
294  int bx7=wMK->wEve.bx7;
295  if(spinDb->offsetBX48minusBX7(bx48,bx7)) {
296  printf("BAD bx7=%d bx48=%d del=%d\n",bx7,bx48,spinDb->offsetBX48minusBX7(bx48,bx7));
297  hA[0]->Fill("badBx48",1.);
298  return; // both counters must be in sync
299  }
300  hA[2]->Fill(bx7);
301  int bxStar7=spinDb->BXstarUsingBX7(bx7);
302  hA[4]->Fill(bxStar7);
303 
304  int spin4=spinDb->spin4usingBX48(bx48);
305  hA[5]->Fill(bxStar7,spin4);
306 
307  hA[20]->Fill(invM,spin4);
308 
309  } // end of spin sorting
310 
311  /* TLorentzVector (px,py,pz,E).
312  TLorentzVector v4(TVector3(1., 2., 3.),4.);
313  v.SetVect(TVector3(1,2,3));
314  v.SetXYZT(x,y,z,t);
315  v.SetPxPyPzE(px,py,pz,e);
316  v.SetXYZM(x,y,z,m); // -> v=(x,y,z,e=Sqrt(x*x+y*y+z*z+m*m))
317  */
318 
319 
320 #if 0
321  for (int i_jet=1; i_jet< nJetsWE; i_jet++){//loop over jets
322  StJet* jet = wMK->getJet(i_jet);
323  TVector3 jetVec; //vector for jet momentum
324  //vary neutral and charged et in jets for systematic
325  float neutral=jet->neutralFraction()*jet->Pt();
326  float charged=jet->chargedFraction()*jet->Pt();
327  neutral=neutral*par_mcJetNeutScale;
328  charged=charged*par_mcJetChrgScale;
329  float sum=neutral+charged;
330  jetVec.SetPtEtaPhi(sum,jet->Eta(),jet->Phi());
331  if(jetVec.DeltaR(T.primP) > par_nearDeltaR)
332  T.ptBalance+=jetVec;
333  }
334  TVector3 clustPt(T.primP.X(),T.primP.Y(),0);
335  clustPt.SetMag(T.cluster.ET);
336  T.ptBalance+=clustPt;
337  T.sPtBalance = T.ptBalance.Perp();
338  if(T.ptBalance.Dot(clustPt)<0) T.sPtBalance *=-1.;
339 
340 
341 #endif
342 
343  if(par_spinSort) {
344  assert(spinDb->isValid()); // all 3 DB records exist
345  assert(spinDb->isPolDirLong()); // you do not want mix Long & Trans by accident
346  int bx48=wMK->wEve.bx48;
347  int bx7=wMK->wEve.bx7;
348  if(spinDb->offsetBX48minusBX7(bx48,bx7)) {
349  printf("BAD bx7=%d bx48=%d del=%d\n",bx7,bx48,spinDb->offsetBX48minusBX7(bx48,bx7));
350  hA[0]->Fill("badBx48",1.);
351  return;
352  }
353 
354  hA[2]->Fill(bx7);
355 
356  int bxStar7=spinDb->BXstarUsingBX7(bx7);
357 
358  hA[4]->Fill(bxStar7);
359 
360  int spin4=spinDb->spin4usingBX48(bx48);
361  hA[5]->Fill(bxStar7,spin4);
362  }// end of spin processing
363 
364 #if 0
365  StMuEvent* muEve = wMK->mMuDstMaker->muDst()->event();
366  int max=0;
367  for (int m=0;m<300;m++) { // access L0-HT data
368  int val=muEve->emcTriggerDetector().highTower(m);
369  if(max<val) max=val;
370  }
371 #endif
372 
373 
374  //::::::::::::::::::::::::::::::::::::::::::::::::
375  //:::::accepted W events for x-section :::::::::::
376  //::::::::::::::::::::::::::::::::::::::::::::::::
377 
378 }
379 
380 
381 // $Log: St2009WjjMaker.cxx,v $
382 // Revision 1.5 2010/06/25 15:42:09 balewski
383 // more plots for Pavel
384 //
385 // Revision 1.4 2010/05/04 12:14:35 balewski
386 // runs now w/o jet tree
387 //
388 // Revision 1.3 2010/05/03 17:24:37 balewski
389 // added spin sorting of di-jets
390 //
391 // Revision 1.2 2010/05/01 01:31:44 balewski
392 // added W->JJ code & JES calibration
393 //
394 // Revision 1.1 2010/04/16 01:04:43 balewski
395 // start
396 //
397 
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
bool isBXfilledUsingInternalBX(int bx)
defined only for 2005 run by CAD , based on first 4 filled bunches in both rings. Note...
bool isValid()
dump spinDb content for current time stamp
Definition: StSpinDbMaker.h:53
StMuDst * muDst()
Definition: StMuDstMaker.h:425
virtual Int_t Make()
int spin4usingBX48(int bx48)
8bit spin information
int BX7offset()
bXing at STAR IP, [0,119]
spin sorting of W&#39;s
void print(int level=0)
vs. STAR==yellow bXing
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
int BXstarUsingBX7(int bx7)
bXing at STAR IP, [0,119]
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
Collection of trigger ids as stored in MuDst.
Definition: StJet.h:91
bool isPolDirLong()
Returns true if beams are transversely polarized, false otherwise.
Definition: StSpinDbMaker.h:55