StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St2011W_Ealgo.cxx
1 // $Id: St2011W_Ealgo.cxx,v 1.23 2013/09/13 19:33:13 stevens4 Exp $
2 //
3 //*-- Author : Jan Balewski, MIT
4 //*-- Author for Endcap: Justin Stevens, IUCF
5 
6 #include "TF1.h"
7 
8 #include "StEmcUtil/geometry/StEmcGeom.h"
9 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
10 #include "StEEmcUtil/StEEmcSmd/EEmcSmdGeom.h"
11 #include "WeventDisplay.h"
12 #include "StSpinPool/StJets/StJet.h"
13 #include "StSpinPool/StJets/TowerToJetIndex.h"
14 
15 #include "St2011WMaker.h"
16 
17 //________________________________________________
18 //________________________________________________
19 void
20 St2011WMaker::findEndcap_W_boson(){
21 
22  if(!wEve->l2EbitET) return;
23 
24  //printf("========= findEndcap_W_boson() \n");
25  int nNoNear=0,nSmdRatio=0,nNoAway=0,nGoldW=0,nGoldWp=0,nGoldWn=0;
26  //remove events tagged as Zs
27  if(wEve->zTag) return;
28 
29  // search for Ws ............
30  for(unsigned int iv=0;iv<wEve->vertex.size();iv++) {
31  WeveVertex &V=wEve->vertex[iv];
32  for(unsigned int it=0;it<V.eleTrack.size();it++) {
33  WeveEleTrack &T=V.eleTrack[it];
34  if(T.pointTower.id>=0) continue; //skip barrel towers
35  if(T.isMatch2Cl==false) continue;
36  assert(T.cluster.nTower>0); // internal logical error
37  assert(T.nearTotET>0); // internal logical error
38 
39  //signal plots w/o EEMC in awayside veto
40  if(T.cluster.ET/T.nearTotET_noEEMC>parE_nearTotEtFrac){
41  if(T.sPtBalance_noEEMC>parE_ptBalance ) {//only signed ptBalance cut
42  hE[140]->Fill(T.cluster.ET);
43  if (T.prMuTrack->charge() < 0) {
44  hE[184+3]->Fill(T.cluster.ET);
45  } else if (T.prMuTrack->charge() > 0) {
46  hE[184+4]->Fill(T.cluster.ET);
47  }
48  }
49  }
50 
51  // track matched to cluster plots
52  StThreeVectorF ri=T.glMuTrack->firstPoint();
53  StThreeVectorF ro=T.glMuTrack->lastPoint();
54  int sec = WtpcFilter::getTpcSec(ro.phi(),ro.pseudoRapidity());
55  if((sec < 5 || sec > 7) && sec!=21) { //skip sectors with dead padrows for this
56  hE[63]->Fill(T.glMuTrack->nHitsFit());
57  hE[64]->Fill(1.*T.glMuTrack->nHitsFit()/T.glMuTrack->nHitsPoss());
58  hE[65]->Fill(ri.perp());
59  hE[65]->Fill(ro.perp());
60  }
61 
62  if(T.cluster.ET /T.nearTotET< parE_nearTotEtFrac) continue; // too large nearET
63 
64  hE[20]->Fill("noNear",1.);
65  nNoNear++;
66  hE[112]->Fill( T.cluster.ET); // for Joe
67  hE[50]->Fill(T.awayTpcPT);
68  hE[51]->Fill(T.awayBtowET);
69  hE[54]->Fill(T.awayTotET);
70  hE[52]->Fill(T.cluster.ET,T.awayTotET);
71  hE[53]->Fill(T.cluster.ET,T.awayEmcET);
72  hE[55]->Fill(T.awayEtowET);
73  hE[60]->Fill(T.cluster.ET,T.awayTpcPT);
74 
75  hE[132]->Fill(T.cluster.ET,T.ptBalance.Perp());
76  hE[133]->Fill(T.awayTotET,T.ptBalance.Perp());
77  hE[134]->Fill(T.cluster.ET,T.sPtBalance);
78  hE[135]->Fill(T.awayTotET,T.sPtBalance);
79  if(T.cluster.ET > parE_highET) hE[239]->Fill(T.awayTotET,T.sPtBalance);
80 
81  //alternate sPtBalance
82  hE[141]->Fill(T.sPtBalance,T.sPtBalance-T.sPtBalance2);
83 
84  //plots for backg sub yield
85  if(T.sPtBalance>parE_ptBalance ) {
86  hE[136]->Fill(T.cluster.ET);//signal
87  hE[62]->Fill(T.pointTower.iEta ,T.cluster.energy);
88  if (T.prMuTrack->charge() < 0) {
89  hE[184+1]->Fill(T.cluster.ET);
90  } else if (T.prMuTrack->charge() > 0) {
91  hE[184+2]->Fill(T.cluster.ET);
92  }
93  } else {
94  hE[137]->Fill(T.cluster.ET);//background
95  if (T.prMuTrack->charge() < 0) {
96  hE[184+5]->Fill(T.cluster.ET);
97  } else if (T.prMuTrack->charge() > 0) {
98  hE[184+6]->Fill(T.cluster.ET);
99  }
100  }
101 
102  //some ESMD QA plots
103  if(T.sPtBalance2>parE_ptBalance){
104  hE[214]->Fill(T.cluster.ET,T.esmdE[0]+T.esmdE[1]);
105  hE[215]->Fill(T.cluster.ET,T.esmdNhit[0]+T.esmdNhit[1]);
106  hE[220]->Fill(T.cluster.ET,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
107  hE[223]->Fill(T.cluster.ET,T.enePre1+T.enePre2);
108  hE[224]->Fill(T.cluster.ET,T.enePost);
109  hE[227]->Fill(T.cluster.ET,T.esmdPeakSumE[0]+T.esmdPeakSumE[1]);
110  hE[228]->Fill(T.cluster.ET,T.esmdMaxADC);
111 
112  if(T.cluster.ET>parE_highET) { //most W like
113  hE[211]->Fill(T.esmdNhit[0],T.esmdNhit[1]);
114  hE[212]->Fill(T.esmdE[0],T.esmdE[1]);
115  hE[213]->Fill(T.esmdNhit[0]+T.esmdNhit[1],T.esmdE[0]+T.esmdE[1]);
116  hE[217]->Fill(T.pointTower.R.X()-T.esmdXPcentroid.X(),T.pointTower.R.Y()-T.esmdXPcentroid.Y());
117  hE[218]->Fill(T.pointTower.R.Eta()-T.esmdXPcentroid.Eta(),T.pointTower.R.Phi()-T.esmdXPcentroid.Phi());
118  hE[219]->Fill(T.esmdPeakSumE[0]/T.esmdE[0],T.esmdPeakSumE[1]/T.esmdE[1]);
119 
120  hE[221]->Fill(T.enePre1,T.enePre2);
121  hE[222]->Fill(T.enePre1+T.enePre2,T.enePost);
122  hE[225]->Fill(T.enePre1+T.enePre2,T.esmdE[0]+T.esmdE[1]);
123  hE[226]->Fill(T.enePost,T.esmdE[0]+T.esmdE[1]);
124  hE[256]->Fill(T.pointTower.R.Phi(), T.esmdPeakOffset[0]);
125  hE[257]->Fill(T.pointTower.R.Phi(), T.esmdPeakOffset[1]);
126  }
127  }
128  else { //mostly QCD
129  if(T.cluster.ET>parE_highET) hE[235]->Fill(T.esmdPeakSumE[0]/T.esmdE[0],T.esmdPeakSumE[1]/T.esmdE[1]);
130  hE[236]->Fill(T.cluster.ET,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
131  }
132 
133  //define charge separation
134  float q2pt_g = T.glMuTrack->charge()/T.glMuTrack->pt();
135  float q2pt_p = T.prMuTrack->charge()/T.prMuTrack->pt();
136  float hypCorr_g = q2pt_g*(T.cluster.ET);
137  float hypCorr_p = q2pt_p*(T.cluster.ET);
138 
139  //correlate ratio with sPtBal for goldWs (used for background)
140  if( fabs(hypCorr_p) > parE_QET2PTlow && fabs(hypCorr_p) < parE_QET2PThigh) { //remove ambiguous charges BG treatment
141  if(T.cluster.ET > parE_highET && T.cluster.ET < 50.){
142  hE[237]->Fill(T.sPtBalance,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
143  hE[238]->Fill(T.sPtBalance2,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
144  if(T.prMuTrack->charge()>0)
145  hE[250]->Fill(T.sPtBalance2,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
146  else
147  hE[251]->Fill(T.sPtBalance2,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
148  }
149  // try lower threshold to find background
150  if(T.cluster.ET > 20.&& T.cluster.ET < 50.){
151  hE[252]->Fill(T.sPtBalance,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
152  hE[253]->Fill(T.sPtBalance2,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
153  if(T.prMuTrack->charge()>0)
154  hE[254]->Fill(T.sPtBalance2,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
155  else
156  hE[255]->Fill(T.sPtBalance2,(T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]));
157  }
158  }
159 
160  //fail ratio cut at 0.5 (mostly BG)
161  if((T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]) < 0.5){
162  hE[232]->Fill(T.cluster.ET,T.sPtBalance);
163  hE[233]->Fill(T.cluster.ET,T.sPtBalance2);
164  }
165 
166  //event display
167  if(T.sPtBalance2>parE_ptBalance && (T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]) > parE_smdRatio){/***************************/
168  printf("\n WWWWWWWWWWWWWWWWWWWWW Endcap \n");
169  wDisaply->exportEvent( "WE", V, T, iv);
170  wEve->print();
171  // assert(1==2);
172  }/***************************/
173 
174  //cut on ESMD ratio
175  if((T.esmdPeakSumE[0]+T.esmdPeakSumE[1])/(T.esmdE[0]+T.esmdE[1]) < parE_smdRatio)
176  continue;
177 
178  hE[20]->Fill("smdRatio",1.0);
179  nSmdRatio++;
180 
181  hE[113]->Fill( T.cluster.ET);//for Joe
182  hE[230]->Fill(T.cluster.ET,T.sPtBalance);
183  hE[231]->Fill(T.cluster.ET,T.sPtBalance2);
184 
185  //put final W cut here
186  if(T.sPtBalance2<parE_ptBalance) continue;
187  //::::::::::::::::::::::::::::::::::::::::::::::::
188  //:::::accepted W events for x-section :::::::::::
189  //::::::::::::::::::::::::::::::::::::::::::::::::
190 
191  hE[20]->Fill("noAway",1.0);
192  nNoAway++;
193  hE[114]->Fill( T.cluster.ET);//for Joe
194 
195  hE[90]->Fill( T.cluster.ET);
196  hE[92]->Fill( T.cluster.ET,T.glMuTrack->dEdx()*1e6);
197  //hE[93]->Fill( T.cluster.ET,T.glMuTrack->dca().mag());
198  int k=0; if(T.prMuTrack->charge()<0) k=1;
199  hE[94+k]->Fill( T.cluster.ET,T.glMuTrack->dcaD());
200  // h95 used above
201 
202  // do charge sign plot
203  float ET=T.cluster.ET;
204  const StMuTrack *glTr=T.glMuTrack; assert(glTr);
205  const StMuTrack *prTr=T.prMuTrack; assert(prTr);
206  float g_chrg=glTr->charge();
207  float p_chrg=prTr->charge();
208  hE[200]->Fill(ET,g_chrg/glTr->pt());
209  hE[201]->Fill(ET,p_chrg/prTr->pt());
210  hE[202]->Fill(T.cluster.ET,hypCorr_g);
211  hE[203]->Fill(T.cluster.ET,hypCorr_p);
212 
213  //charge sign flip with vertex refit
214  int g_ipn=0, p_ipn=0; // plus
215  if( g_chrg<0 ) g_ipn=1;// minus
216  if( p_chrg<0 ) p_ipn=1;// minus
217  hE[240+g_ipn]->Fill(ET);
218  hE[242+p_ipn]->Fill(ET);
219  if(g_chrg* p_chrg <-0.5) hE[244+p_ipn]->Fill(ET); // charge flip
220 
221  if(T.cluster.ET<parE_highET) continue; // very likely Ws
222  hE[91]->Fill(T.cluster.position.PseudoRapidity(),T.cluster.position.Phi());
223  hE[96]->Fill(V.id);
224  hE[97]->Fill(V.funnyRank);
225  hE[98]->Fill(V.z);
226  hE[99]->Fill( T.prMuTrack->eta());
227  hE[100]->Fill(T.pointTower.R.X(),T.pointTower.R.Y());
228  hE[190+k]->Fill(T.prMuTrack->eta(),T.cluster.ET);
229  hE[101]->Fill(T.cluster.ET/T.cl4x4.ET,T.sPtBalance);
230  hE[102]->Fill(T.cluster.ET/T.nearTotET,T.sPtBalance);
231  hE[103]->Fill(T.cluster.ET/T.nearEmcET,T.sPtBalance);
232  hE[104]->Fill(T.cluster.ET/T.nearEtowET,T.sPtBalance);
233  hE[105]->Fill(T.glMuTrack->dEdx()*1e6,T.sPtBalance);
234 
235  // plots to study charge separation
236  hE[106]->Fill(T.prMuTrack->chi2(),hypCorr_p);
237  hE[107]->Fill(T.glMuTrack->chi2(),hypCorr_p);
238  hE[108]->Fill(1.*T.glMuTrack->nHitsFit()/T.glMuTrack->nHitsPoss(),hypCorr_p);
239  hE[109]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
240 
241  hE[120]->Fill(T.prMuTrack->chi2()-T.glMuTrack->chi2(),hypCorr_p);
242  hE[121]->Fill(T.glMuTrack->dcaD(),hypCorr_p);
243  hE[122]->Fill(T.esmdPeakOffset[0],hypCorr_p);
244  hE[123]->Fill(T.esmdPeakOffset[1],hypCorr_p);
245  hE[124]->Fill(T.esmdPeakOffset[1],T.esmdPeakOffset[0]);
246  hE[125]->Fill(ri.perp(),hypCorr_p);
247  hE[126]->Fill(ro.perp(),hypCorr_p);
248  hE[127]->Fill(T.glMuTrack->dEdx()*1e6,hypCorr_p);
249  hE[128]->Fill(T.glMuTrack->lengthMeasured(),hypCorr_p);
250  hE[129]->Fill(ro.perp()-ri.perp(),hypCorr_p);
251  float phiScale = 180./TMath::Pi();
252  float deltaPhiESMD = (T.pointTower.R.Phi()-T.esmdXPcentroid.Phi())*phiScale;
253  float deltaPhiTrack = (T.pointTower.R.Phi()-T.pointTower.Rglob.Phi())*phiScale;
254  float deltaR = ro.perp()-ri.perp();
255  float chi2 = T.prMuTrack->chi2();
256  hE[130]->Fill(deltaPhiESMD,hypCorr_p);
257  hE[131]->Fill(deltaPhiTrack,hypCorr_p);
258 
259  if(hypCorr_p > parE_QET2PTlow && hypCorr_p < parE_QET2PThigh) {
260  hE[150]->Fill(T.glMuTrack->dcaD(),ro.perp());
261  hE[152]->Fill(deltaPhiESMD,ro.perp());
262  hE[154]->Fill(deltaPhiESMD,ro.perp()-ri.perp());
263  hE[156]->Fill(deltaPhiTrack,ro.perp()-ri.perp());
264  hE[158]->Fill(deltaPhiTrack,T.prMuTrack->chi2());
265  hE[160]->Fill(deltaPhiESMD,T.prMuTrack->chi2());
266  hE[162]->Fill(ro.perp()-ri.perp(),T.prMuTrack->chi2());
267  }
268  else if(hypCorr_p < -1.*parE_QET2PTlow && hypCorr_p > -1.*parE_QET2PThigh) {
269  hE[151]->Fill(T.glMuTrack->dcaD(),ro.perp());
270  hE[153]->Fill(deltaPhiESMD,ro.perp());
271  hE[155]->Fill(deltaPhiESMD,ro.perp()-ri.perp());
272  hE[157]->Fill(deltaPhiTrack,ro.perp()-ri.perp());
273  hE[159]->Fill(deltaPhiTrack,T.prMuTrack->chi2());
274  hE[161]->Fill(deltaPhiESMD,T.prMuTrack->chi2());
275  hE[163]->Fill(ro.perp()-ri.perp(),T.prMuTrack->chi2());
276  }
277 
278  // harder "or" cuts
279  float delRcut = 45.; //50
280  float RoutCut = 110.; //115
281  float delPhiCut = 0.25; //0.2
282  float chi2cut = 3.0; //2.5
283  if( (chi2 < chi2cut && fabs(deltaPhiTrack) < delPhiCut) || (chi2 < chi2cut && deltaR > delRcut) || (fabs(deltaPhiTrack) < delPhiCut && deltaR > delRcut) )
284  hE[170]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
285  if( (chi2 < chi2cut && fabs(deltaPhiTrack) < delPhiCut) || (chi2 < chi2cut && ro.perp() > RoutCut) || (fabs(deltaPhiTrack) < delPhiCut && ro.perp() > RoutCut) )
286  hE[171]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
287 
288  // softer "and" cuts
289  if(chi2 < 4.0 && fabs(deltaPhiTrack) < 0.4 && ro.perp() > 90.) //3.5 0.35 90 (old cuts)
290  hE[172]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
291  if(chi2 < 3.5 && fabs(deltaPhiTrack) < 0.4 && ro.perp() > 90.)
292  hE[173]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
293  if(chi2 < 4.0 && fabs(deltaPhiTrack) < 0.4)
294  hE[174]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
295  if(chi2 < 4.0 && fabs(deltaPhiTrack) < 0.35)
296  hE[175]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
297  if(chi2 < 3.5 && fabs(deltaPhiTrack) < 0.4)
298  hE[176]->Fill(T.glMuTrack->nHitsFit(),hypCorr_p);
299 
300  hE[20]->Fill("goldW",1.);
301  nGoldW++;
302  if(T.prMuTrack->charge()>0) nGoldWp++;
303  else if(T.prMuTrack->charge()<0) nGoldWn++;
304 
305  }// loop over tracks
306  }// loop over vertices
307  if(nNoNear>0) hE[0]->Fill("noNear",1.);
308  if(nSmdRatio>0) hE[0]->Fill("smdRatio",1.);
309  if(nNoAway>0) hE[0]->Fill("noAway",1.);
310  if(nGoldW>0) hE[0]->Fill("goldW",1.);
311  if(nGoldWp>0) hE[0]->Fill("goldW+",1.);
312  if(nGoldWn>0) hE[0]->Fill("goldW-",1.);
313 
314 }
315 
316 //________________________________________________
317 //________________________________________________
318 void
319 St2011WMaker::analyzeESMD(){
320  if(!wEve->l2EbitET) return;
321 
322  //printf("========= analyzeESMD \n");
323  for(unsigned int iv=0;iv<wEve->vertex.size();iv++) {
324  WeveVertex &V=wEve->vertex[iv];
325  for(unsigned int it=0;it<V.eleTrack.size();it++) {
326  WeveEleTrack &T=V.eleTrack[it];
327  if(T.pointTower.id>=0) continue; //skip barrel towers
328  if(T.isMatch2Cl==false) continue;
329  assert(T.cluster.nTower>0); // internal logical error
330 
331  //id of strips pointed by prim and glob tracks in each plane
332  int hitStrip[2]={-1,-1}; int hitStripGlob[2]={-1,-1};
333 
334  int isec=T.pointTower.iPhi/mxEtowSub;
335  int layer[2]={((isec+2)%3) +1, (isec%3) +1};
336 
337  for(int iuv=0; iuv<2; iuv++){ //loop over planes
338 
339  //.... extrapolate track to the disk perpendicular to the z-axis
340  const StPhysicalHelixD trkHlx=T.prMuTrack->outerHelix();
341  // to account for the z-depth of each plane, sector dependent, (cm), Z=smd depth
342  StThreeVectorD diskPosition=StThreeVectorD(0,0,geomE->getZSMD() + (layer[iuv]-2)* 1.25);
343  StThreeVectorD diskNormal=StThreeVectorD(0,0,1);
344  printf(" ESMD sec=%d iuv=%d layer=%d, smdZ=%.1f\n", isec+1, iuv,layer[iuv],diskPosition.z() );
345  //path length at intersection with plane
346  double path = trkHlx.pathLength(diskPosition,diskNormal);
347  StThreeVectorD r = trkHlx.at(path);
348  TVector3 rCross(r.x(),r.y(),r.z());
349 
350  Float_t dca; //primary extrapolation to smd plane
351  const StructEEmcStrip *stripPtr = geoSmd->getDca2Strip(iuv,rCross,&dca); // find pointed strip
352  if(!stripPtr) {cout<<"No Strip found"<<endl; continue;}
353  if(fabs(dca)>0.51 /*cm*/) {cout<<"Esmd DCA to big ="<<dca<<endl; continue;}
354 
355  Float_t dcaGlob; //global extrapolation to smd plane
356  const StPhysicalHelixD trkHlxGlob=T.glMuTrack->outerHelix();
357  double pathGlob = trkHlxGlob.pathLength(diskPosition,diskNormal);
358  StThreeVectorD rGlob = trkHlxGlob.at(pathGlob);
359  TVector3 rCrossGlob(rGlob.x(),rGlob.y(),rGlob.z());
360  const StructEEmcStrip *stripPtrGlob = geoSmd->getDca2Strip(iuv,rCrossGlob,&dcaGlob); // find pointed strip
361 
362  int stripId=stripPtr->stripStructId.stripId;
363  int sectorId=stripPtr->stripStructId.sectorId;
364  T.hitSector=sectorId;
365  T.esmdGlobStrip[iuv]=stripPtrGlob->stripStructId.stripId-stripId;
366  T.esmdDca[iuv]=dca; T.esmdDcaGlob[iuv]=dcaGlob;
367  hitStrip[iuv]=stripId; hitStripGlob[iuv]=stripPtrGlob->stripStructId.stripId;
368 
369  // set integration range for smd energy
370  int str1=stripId - parE_nSmdStrip; if(str1<1) str1=1;
371  int str2=stripId + parE_nSmdStrip; if(str2>288) str2=288;
372  for(int istrip=str1; istrip<=str2; istrip++){
373  float ene = wEve->esmd.ene[sectorId-1][iuv][istrip-1]*1e3; // in MeV now
374  int adc = wEve->esmd.adc[sectorId-1][iuv][istrip-1];
375  T.esmdShower[iuv][istrip-stripId+parE_nSmdStrip]=ene;
376  if(adc > T.esmdMaxADC){ T.esmdMaxADC=adc; }
377  if(ene > 0){
378  T.esmdE[iuv]+=ene; //total energy
379  T.esmdNhit[iuv]++;
380  if(abs(istrip-stripId)<4){ //7 central sum
381  //cout<<istrip<<" "<<stripId<<" "<<ene<<endl;
382  T.esmdEsum7[iuv]+=ene;
383  }
384  }
385  }// end loop over strips
386 
387  // finding smd-peak center correction
388  float bestSum=-1;
389  int bestOff=9999;
390  int delOff=parE_esmdWL -parE_esmdGL;
391  for(int off1=-delOff; off1<=delOff; off1++) {
392  float sum=0;
393  for(int off2=-parE_esmdGL; off2<=parE_esmdGL; off2++)
394  sum+=T.esmdShower[iuv][parE_nSmdStrip+off1+off2];
395  //printf("off1=%d sum=%.1f bestSum=%.1f bestOff=%d\n",off1,sum,bestSum,bestOff);
396  if(bestSum>sum) continue;
397  bestSum=sum;
398  bestOff=off1;
399  }
400  printf("do slide iuv=%d sum7=%.1f bestSum=%.1f bestOff=%d\n",iuv, T.esmdEsum7[iuv], bestSum,bestOff);
401  T.esmdPeakSumE[iuv]=bestSum;
402  T.esmdPeakOffset[iuv]=bestOff;
403 
404  } //end plane loop
405 
406  //get shower x-point from hitStrip + centroid of fit
407  T.esmdXPcentroid = geoSmd->getIntersection(T.hitSector-1,hitStrip[0]-1+T.esmdPeakOffset[0],hitStrip[1]-1+T.esmdPeakOffset[1]);//janCheck
408 
409  } //end track loop
410  } //end vertex loop
411 }
412 
413 
414 //________________________________________________
415 //________________________________________________
416 void
417 St2011WMaker::analyzeEPRS(){
418  if(!wEve->l2EbitET) return;
419 
420  //printf("========= analyzeEPRS \n");
421  for(unsigned int iv=0;iv<wEve->vertex.size();iv++) {
422  WeveVertex &V=wEve->vertex[iv];
423  for(unsigned int it=0;it<V.eleTrack.size();it++) {
424  WeveEleTrack &T=V.eleTrack[it];
425  if(T.pointTower.id>=0) continue; //skip barrel towers
426  if(T.isMatch2Cl==false) continue;
427  assert(T.cluster.nTower>0); // internal logical error
428 
429  //do some clustering of EPRS deposits and plot histos
430  T.enePre1 = wEve->eprs.ene[T.cluster.iPhi][T.cluster.iEta][0];
431  T.enePre2 = wEve->eprs.ene[T.cluster.iPhi][T.cluster.iEta][1];
432  T.enePost = wEve->eprs.ene[T.cluster.iPhi][T.cluster.iEta][2];
433 
434  }
435  }
436 
437 }
438 
439 
440 //________________________________________________
441 //________________________________________________
442 float
443 St2011WMaker::sumEtowCone(float zVert, TVector3 refAxis, int flag){
444  /* flag=1 : only delta phi cut; flag=2 use 2D cut */
445  assert(flag==1 || flag==2);
446  float ptsum=0;
447 
448  //....loop over all phi bins
449  for(int iphi=0; iphi<mxEtowPhiBin; iphi++){
450  for(int ieta=0; ieta<mxEtowEta; ieta++){//sum all eta rings
451  float ene=wEve->etow.ene[iphi][ieta];
452  if(ene<=0) continue; //skip towers with no energy
453  TVector3 primP=positionEtow[iphi][ieta]-TVector3(0,0,zVert);
454  primP.SetMag(ene); // it is 3D momentum in the event ref frame
455  if(flag==1) {
456  float deltaPhi=refAxis.DeltaPhi(primP);
457  if(fabs(deltaPhi)> par_awayDeltaPhi) continue;
458  }
459  if(flag==2) {
460  float deltaR=refAxis.DeltaR(primP);
461  if(deltaR> par_nearDeltaR) continue;
462  }
463  ptsum+=primP.Perp();
464  }
465  }
466 
467  return ptsum;
468 }
469 
470 
471 // ************* Endcap Code ************ //
472 // ************************************** //
473 
474 //________________________________________________
475 //________________________________________________
476 int
477 St2011WMaker::extendTrack2Endcap(){// return # of extended tracks
478  //printf("******* extendTracksEndcap() nVert=%d\n",wEve.vertex.size());
479  if(!wEve->l2EbitET) return 0; //fire endcap trigger
480 
481  double parE_zSMD=geomE->getZSMD(); // (cm), smd depth
482  int nTrE=0;
483  for(unsigned int iv=0;iv<wEve->vertex.size();iv++) {
484  WeveVertex &V=wEve->vertex[iv];
485  for(unsigned int it=0;it<V.eleTrack.size();it++) {
486  WeveEleTrack &T=V.eleTrack[it];
487  if(T.prMuTrack->eta()<parE_trackEtaMin)
488  continue; // to avoid extrapolation nonsense
489 
490  //do eta sorting at track level (tree analysis)
491  if(T.primP.Eta() < parE_leptonEtaLow || T.primP.Eta() > parE_leptonEtaHigh) continue;
492 
493  //.... extrapolate track to the disk perpendicular to the z-axis
494  const StPhysicalHelixD trkHlx=T.prMuTrack->outerHelix();
495  StThreeVectorD diskPosition=StThreeVectorD(0,0,parE_zSMD);
496  StThreeVectorD diskNormal=StThreeVectorD(0,0,1);
497 
498  //path length at intersection with plane
499  double path = trkHlx.pathLength(diskPosition,diskNormal);
500 
501  StThreeVectorD r = trkHlx.at(path);
502  float periodL=trkHlx.period();
503 
504  if(periodL<2*path) {
505  printf(" Warn, long path fac=%.1f ",path/periodL);
506  printf(" punchEEMC1 x,y,z=%.1f, %.1f, %.1f path=%.1f period=%.1f\n",r.x(),r.y(),r.z(),path,periodL);
507  }
508 
509  //printf("hitR xyz=%f %f %f, detEta=%f\n",r.x(),r.y(),r.z(),eta);
510  hE[69]->Fill(r.x(), r.y());
511 
512  int isec,isubSec,ietaBin;
513  Float_t epsPhi, epsEta;
514  TVector3 rCross(r.x(),r.y(),r.z());
515  bool inEtow=geomE->getTower(rCross,isec,isubSec,ietaBin,epsPhi,epsEta);
516  if(!inEtow) continue;
517  hE[20]->Fill("@E",1.);
518  //printf("trk points EEMC tower isec=%d isub=%d ieta=%d epsPhi=%f epsEta=%f trkPT=%f\n", isec,isubSec,ietaBin,epsPhi,epsEta,T.prMuTrack->pt());
519 
520  nTrE++;
521  T.pointTower.id=-999; //set negative for endcap towers
522  T.pointTower.R=rCross;
523  T.pointTower.iEta=ietaBin;
524  T.pointTower.iPhi=isec*mxEtowSub+isubSec;
525 
526  //find global track extrapolation (for ESMD analysis)
527  const StPhysicalHelixD trkHlxGlob=T.glMuTrack->outerHelix();
528  double pathGlob = trkHlxGlob.pathLength(diskPosition,diskNormal);
529 
530  StThreeVectorD rGlob = trkHlxGlob.at(pathGlob);
531  float periodLGlob=trkHlxGlob.period();
532 
533  if(periodLGlob<2*pathGlob) {
534  printf(" Warn, long path Global fac=%.1f ",pathGlob/periodLGlob);
535  printf(" punchEEMC1 x,y,z=%.1f, %.1f, %.1f path=%.1f period=%.1f\n",r.x(),r.y(),r.z(),pathGlob,periodLGlob);
536  }
537  TVector3 rCrossGlob(rGlob.x(),rGlob.y(),rGlob.z());
538  T.pointTower.Rglob=rCrossGlob;
539 
540  }
541  }// end of loop over vertices
542 
543  if(nTrE<=0) return -1;
544  hE[0]->Fill("TrE",1.0);
545  return 0;
546 
547 }
548 
549 
550 //________________________________________________
551 //________________________________________________
552 int
553 St2011WMaker::matchTrack2EtowCluster(){
554  //printf("******* matchEtowCluster() nVert=%d\n",wEve.vertex.size());
555 
556  if(!wEve->l2EbitET) return 0;
557 
558  int nTr=0;
559  for(unsigned int iv=0;iv<wEve->vertex.size();iv++) {
560  WeveVertex &V=wEve->vertex[iv];
561  float zVert=V.z;
562  for(unsigned int it=0;it<V.eleTrack.size();it++) {
563  WeveEleTrack &T=V.eleTrack[it];
564  if(T.pointTower.id>=0) continue; //skip barrel towers
565 
566  float trackPT=T.prMuTrack->momentum().perp();
567  T.cluster=maxEtow2x2(T.pointTower.iEta,T.pointTower.iPhi,zVert);
568  hE[110]->Fill( T.cluster.ET);
569  hE[33]->Fill(T.cluster.ET);
570  hE[34]->Fill(T.cluster.adcSum,trackPT);
571 
572  // ........compute surrounding cluster energy
573  int iEta=T.cluster.iEta;
574  int iPhi=T.cluster.iPhi;
575  T.cl4x4=sumEtowPatch(iEta-1,iPhi-1,4,4,zVert);
576 
577  if (T.cluster.ET<parE_clustET) continue; // too low energy
578  hE[20]->Fill("CL",1.);
579  hE[37]->Fill(T.cl4x4.ET);
580  hE[38]->Fill(T.cluster.energy, T.cl4x4.energy-T.cluster.energy);
581 
582  float frac24=T.cluster.ET/(T.cl4x4.ET);
583  hE[39]->Fill(frac24);
584  if(frac24<parE_clustFrac24) continue;
585  hE[20]->Fill("fr24",1.);
586 
587  //set logE weighted cluster position vector at SMD z depth
588  float newMag=geomE->getZSMD()/TMath::Cos(T.cluster.position.Theta());
589  T.cluster.position.SetMag(newMag);
590 
591  //.. spacial separation (track - cluster) only use 2D X-Y distance for endcap (ie. D.Perp())
592  TVector3 D=T.pointTower.R-T.cluster.position;
593  hE[43]->Fill(T.cluster.energy,D.Perp());
594  float delPhi=T.pointTower.R.DeltaPhi(T.cluster.position);
595  float Rxy=T.cluster.position.Perp();
596 
597  hE[44]->Fill( T.cluster.position.Phi(),Rxy*delPhi);
598  hE[45]->Fill( T.cluster.energy,Rxy*delPhi);// wrong?
599  hE[46]->Fill( D.Perp());
600 
601  if(D.Perp()>par_delR3D) continue;
602  T.isMatch2Cl=true; // cluster is matched to TPC track
603  hE[20]->Fill("#Delta R",1.);
604  hE[111]->Fill( T.cluster.ET);
605 
606  nTr++;
607  }// end of one vertex
608  }// end of vertex loop
609 
610  if(nTr<=0) return -1;
611  hE[0]->Fill("Tr2Cl",1.0);
612  return 0;
613 
614 }
615 
616 
617 //________________________________________________
618 //________________________________________________
620 St2011WMaker::maxEtow2x1(int iEta, int iPhi, float zVert){
621  //printf(" maxEtow2x1 seed iEta=%d iPhi=%d \n",iEta, iPhi);
622 
623  WeveCluster maxCL;
624  // just 4 cases of 2x1 clusters
625  float maxET=0;
626  int I0=iEta-1;
627  int J0=iPhi-1;
628  for(int I=I0;I<=I0+1;I++){ // try along eta dir
629  WeveCluster CL=sumEtowPatch(I,iPhi,2,1,zVert);
630  if(maxET>CL.ET) continue;
631  maxET=CL.ET;
632  maxCL=CL;
633  //printf(" maxEtow2x1 A newMaxETSum=%.1f iEta=%d iPhi=%d \n",maxET, I,iPhi);
634  }
635 
636  for(int J=J0;J<=J0+1;J++) { // try along phi dir
637  WeveCluster CL=sumEtowPatch(iEta,J,1,2,zVert);
638  if(maxET>CL.ET) continue;
639  maxET=CL.ET;
640  maxCL=CL;
641  //printf(" maxEtow2x1 B newMaxETSum=%.1f iEta=%d iPhi=%d \n",maxET,iEta,J);
642  }
643  //printf(" final inpEve=%d SumET2x2=%.1f \n",nInpEve,maxET);
644  return maxCL;
645 }
646 
647 
648 //________________________________________________
649 //________________________________________________
651 St2011WMaker::maxEtow2x2(int iEta, int iPhi, float zVert){
652  //printf(" maxEtow2x1 seed iEta=%d iPhi=%d \n",iEta, iPhi);
653  const int L=2; // size of the summed square
654 
655  WeveCluster maxCL;
656  // just 4 cases of 2x1 clusters
657  float maxET=0;
658  int I0=iEta-1;
659  int J0=iPhi-1;
660  for(int I=I0;I<=I0+1;I++){
661  for(int J=J0;J<=J0+1;J++) {
662  WeveCluster CL=sumEtowPatch(I,J,L,L,zVert);
663  if(maxET>CL.ET) continue;
664  maxET=CL.ET;
665  maxCL=CL;
666  //printf(" maxEtow2x2 A newMaxETSum=%.1f iEta=%d iPhi=%d \n",maxET, I,iPhi);
667  }
668  }// 4 combinations done
669 
670  //printf(" final inpEve=%d SumET2x2=%.1f \n",nInpEve,maxET);
671  return maxCL;
672 }
673 
674 
675 //________________________________________________
676 //________________________________________________
678 St2011WMaker::sumEtowPatch(int iEta, int iPhi, int Leta,int Lphi, float zVert){
679  //printf(" eveID=%d etowPatch seed iEta=%d[+%d] iPhi=%d[+%d] zVert=%.0f \n",wEve.id,iEta,Leta, iPhi,Lphi,zVert);
680  WeveCluster CL; // object is small, not to much overhead in creating it
681  CL.iEta=iEta;
682  CL.iPhi=iPhi;
683  TVector3 R;
684  double sumW=0;
685 
686  for(int i=iEta; i<iEta+Leta;i++){// trim in eta-direction
687  if(i<0) continue;
688  if(i>=mxEtowEta) continue;
689  for(int j=iPhi;j<iPhi+Lphi;j++) {// wrap up in the phi-direction
690  int jj=(j+mxEtowPhiBin)%mxEtowPhiBin;// keep it always positive
691  //if(L<5) printf("n=%2d i=%d jj=%d\n",CL.nTower,i,jj);
692 
693  float ene= wEve->etow.ene[jj][i];
694  if(ene<=0) continue; // skip towers w/o energy
695  float adc= wEve->etow.adc[jj][i];
696  float delZ=positionEtow[jj][i].z()-zVert;
697  float Rxy=positionEtow[jj][i].Perp();
698  float e2et=Rxy/sqrt(Rxy*Rxy+delZ*delZ);
699  float ET=ene*e2et;
700  float logET=log10(ET+0.5);
701  CL.nTower++;
702  CL.energy+=ene;
703  CL.ET+=ET;
704  CL.adcSum+=adc;
705  if(logET>0) {
706  R+=logET*positionEtow[jj][i];
707  sumW+=logET;
708  }
709  }
710  //printf(" in etowPatch: iEta=%d nTw=%d, ET=%.1f adcSum=%.1f\n",i,CL.nTower,CL.ET,CL.adcSum);
711  if(sumW>0) {
712  CL.position=1./sumW*R; // weighted cluster position
713  } else {
714  CL.position=TVector3(0,0,999);
715  }
716  }
717  return CL;
718 }
719 
720 // $Log: St2011W_Ealgo.cxx,v $
721 // Revision 1.23 2013/09/13 19:33:13 stevens4
722 // Updates to code for combined 2011+2012 result presented to spin PWG 9.12.13
723 //
724 // Revision 1.22 2012/10/01 19:48:20 stevens4
725 // add plots for Z result and move esmd cross point calculation outside plane loop
726 //
727 // Revision 1.21 2012/09/28 16:00:41 stevens4
728 // add Q*ET/PT requirement to WB histos used for background estimation to be consistent with spin sorting
729 //
730 // Revision 1.20 2012/09/26 14:20:59 stevens4
731 // use PtBal cos(phi) for WB and WE algos and use Q*ET/PT for barrel charge sign
732 //
733 // Revision 1.19 2012/09/26 01:10:51 stevens4
734 // apply R_ESMD cut using maximum of sliding window
735 //
736 // Revision 1.18 2012/09/21 21:14:04 balewski
737 // plane/sectord dependent Z-location for ESMD implemented in matching of TPC track to ESMD shower.
738 // I'm done
739 //
740 // Revision 1.17 2012/09/21 16:59:10 balewski
741 // added ESMD peak adjustement - partialy finished
742 //
743 // Revision 1.16 2012/09/18 22:30:18 stevens4
744 // change to new jet tree format with access to all rank>0 vertices
745 //
746 // Revision 1.15 2012/09/18 21:10:06 stevens4
747 // Include all rank>0 vertex again (new jet format coming next), and remove rank<0 endcap vertices.
748 //
749 // Revision 1.14 2012/09/17 22:05:50 stevens4
750 // exclude not-highest rank vertex until jet issue is resolved
751 //
752 // Revision 1.13 2012/09/17 03:29:29 stevens4
753 // Updates to Endcap algo and Q*ET/PT charge separation
754 //
755 // Revision 1.12 2012/08/31 20:10:51 stevens4
756 // switch to second EEMC background using both isolation and sPt-Bal (for mirror symmetry (also adjust eta binning)
757 //
758 // Revision 1.11 2012/08/28 14:28:27 stevens4
759 // add histos for barrel and endcap algos
760 //
761 // Revision 1.10 2012/08/21 21:28:22 stevens4
762 // Add spin sorting for endcap Ws
763 //
764 // Revision 1.9 2012/08/21 18:29:16 stevens4
765 // Updates to endcap W selection using ESMD strip ratio
766 //
767 // Revision 1.8 2012/08/07 21:06:38 stevens4
768 // update to tree analysis to produce independent histos in a TDirectory for each eta-bin
769 //
770 // Revision 1.7 2012/07/06 17:47:02 stevens4
771 // Updates for tree reader
772 //
773 // Revision 1.6 2012/06/25 20:53:19 stevens4
774 // algo and histo cleanup
775 //
776 // Revision 1.5 2012/06/18 18:28:00 stevens4
777 // Updates for Run 9+11+12 AL analysis
778 //
779 // Revision 1.4 2011/02/25 06:03:39 stevens4
780 // addes some histos and enabled running on MC
781 //
782 // Revision 1.3 2011/02/17 04:16:18 stevens4
783 // move sector dependent track QA cuts before track pt>10 cut and lower par_clustET and par_ptBalance thresholds to 14 GeV
784 //
785 // Revision 1.2 2011/02/14 01:36:17 stevens4
786 // *** empty log message ***
787 //
788 // Revision 1.1 2011/02/10 20:33:22 balewski
789 // start
790 //
Double_t lengthMeasured() const
Returns length of track (cm) from first to last measured point.
Definition: StMuTrack.cxx:418
Double_t pt() const
Returns pT at point of dca to primary vertex.
Definition: StMuTrack.h:256
Double_t chi2() const
Returns chi2 of fit.
Definition: StMuTrack.h:251
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351
UShort_t nHitsFit() const
Return total number of hits used in fit.
Definition: StMuTrack.h:239
Short_t charge() const
Returns charge.
Definition: StMuTrack.h:255
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
Definition: StMuTrack.h:257
const StThreeVectorF & firstPoint() const
Returns positions of first measured point.
Definition: StMuTrack.h:261
Float_t getZSMD() const
gets z-depth of the SMD layer in EEMC
UShort_t nHitsPoss() const
Return number of possible hits on track.
Definition: StMuTrack.cxx:242
const StThreeVectorF & momentum() const
Returns 3-momentum at dca to primary vertex.
Definition: StMuTrack.h:260
const StThreeVectorF & lastPoint() const
Returns positions of last measured point.
Definition: StMuTrack.h:262
Double_t dEdx() const
Returns measured dE/dx value.
Definition: StMuTrack.h:248
TVector3 getIntersection(Int_t iSec, Int_t iUStrip, Int_t iVStrip, const TVector3 &vertex) const
bool getTower(const TVector3 &r, int &sec, int &sub, int &etabin, Float_t &dphi, Float_t &deta) const
Float_t dcaD(Int_t vtx_id=-1) const
Signed radial component of global DCA (projected)
Definition: StMuTrack.cxx:332
double period() const
returns period length of helix
Definition: StHelix.cc:339
StPhysicalHelixD outerHelix() const
Returns outer helix (last measured point)
Definition: StMuTrack.cxx:412
const StructEEmcStrip * getDca2Strip(const Int_t iUV, const TVector3 &point, Float_t *dca) const