21 mHPileup[0] =
new TH1D(
"zFirst +",
"zFirst +",200,1,200);
22 mHPileup[1] =
new TH1D(
"zFirst -",
"zFirst -",200,-200,-1);
23 mHPileup[2] =
new TH1D(
"zLast +",
"zLast +",200,1,200);
24 mHPileup[3] =
new TH1D(
"zLast -",
"zLast -",200,-200,-1);
25 mHPileup[4] =
new TH1D(
"V_z +",
"V_z +",500,-250,250);
26 mHPileup[5] =
new TH1D(
"V_z -",
"V_z -",500,-250,250);
28 mHQA2D[0] =
new TH2D(
"zFirst vs. zLast",
"zFirst vs. zLast",100,-200,200, 100,-200,200);
29 mHQA2D[1] =
new TH2D(
"zFirst vs. zLast scaled",
"zFirst vs. zLast scaled",100,-200,200, 100,-250,250);
30 mHQA2D[2] =
new TH2D(
"V_z vs. zLast",
"V_z vs. zLast",100,-200,200, 100,-250,250);
32 mHQA2D[0]->SetMarkerStyle(20);
33 mHQA2D[0]->SetMarkerSize(0.5);
34 TAxis *x = mHQA2D[0]->GetXaxis();
35 TAxis *y = mHQA2D[0]->GetYaxis();
36 x->SetTitle(
"Z_{first}");
37 y->SetTitle(
"Z_{last}");
38 mHQA2D[1]->SetMarkerStyle(20);
39 mHQA2D[1]->SetMarkerSize(0.5);
40 x = mHQA2D[1]->GetXaxis();
41 y = mHQA2D[1]->GetYaxis();
42 x->SetTitle(
"Z_{first} at 65cm");
43 y->SetTitle(
"Z_{last} at 190cm");
44 mHQA2D[2]->SetMarkerStyle(20);
45 mHQA2D[2]->SetMarkerSize(0.5);
46 x = mHQA2D[2]->GetXaxis();
47 y = mHQA2D[2]->GetYaxis();
49 y->SetTitle(
"Z_{last} at 190cm");
51 mHQA1D[0] =
new TH1D(
"QA zLast -",
"zLast -",400,-200,200);
52 mHQA1D[1] =
new TH1D(
"QA V_z +",
"V_z +",500,-250,250);
53 mHQA1D[2] =
new TH1D(
"QA V_z -",
"V_z -",500,-250,250);
64 mZStartStopMatchMin = -10;
65 mZStartStopMatchMax = +10;
80 cout <<
"Deleting a pileup object. " << endl;
81 for (
int ih=0;ih<6;ih++) {
84 for (
int ih=0;ih<3;ih++) {
91 int Pileup::verbose() {
94 void Pileup::verbose(
int val) {
100 double Pileup::zEndplate() {
103 void Pileup::zEndplate(
double val) {
109 double Pileup::zStartStopMatchMin() {
110 return mZStartStopMatchMin;
112 void Pileup::zStartStopMatchMin(
double val) {
113 mZStartStopMatchMin = val;
117 double Pileup::zPileMatchMin() {
118 return mZPileMatchMin;
120 void Pileup::zPileMatchMin(
double val) {
121 mZPileMatchMin = val;
125 double Pileup::zPeakMatchMin() {
126 return mZPeakMatchMin;
128 void Pileup::zPeakMatchMin(
double val) {
129 mZPeakMatchMin = val;
133 double Pileup::zStartStopMatchMax() {
134 return mZStartStopMatchMax;
136 void Pileup::zStartStopMatchMax(
double val) {
137 mZStartStopMatchMax = val;
141 double Pileup::zPileMatchMax() {
142 return mZPileMatchMax;
144 void Pileup::zPileMatchMax(
double val) {
145 mZPileMatchMax = val;
149 double Pileup::zPeakMatchMax() {
150 return mZPeakMatchMax;
152 void Pileup::zPeakMatchMax(
double val) {
153 mZPeakMatchMax = val;
157 double Pileup::dead(
int ih) {
158 if (0 <= ih && ih < 7) {
164 void Pileup::dead(
int ih,
double dead) {
169 if (0 <= ih && ih < 7) {
177 double Pileup::z(
int iv,
int which) {
178 if (iv < 0 || mNVerts < iv) {
181 if (1 == mFlag[iv] || 2 == mFlag[iv] || 3 == mFlag[iv]) {
183 return 0.5*(mVerts[iv][0] + mVerts[iv][2]);
184 }
else if (2 == which) {
185 return mVerts[iv][0];
186 }
else if (3 == which) {
187 return mVerts[iv][2];
188 }
else if (4 == which) {
189 return mVerts[iv][4];
193 }
else if (4 == mFlag[iv] || 5 == mFlag[iv]) {
195 return mVerts[iv][0];
196 }
else if (2 == which) {
197 return mVerts[iv][2];
198 }
else if (3 == which) {
199 return mVerts[iv][4];
200 }
else if (4 == which) {
201 return mVerts[iv][5];
205 }
else if (6 == mFlag[iv]) {
207 return 0.5*(mVerts[iv][0] + mVerts[iv][2]);
208 }
else if (2 == which) {
209 return mVerts[iv][0];
210 }
else if (3 == which) {
211 return mVerts[iv][2];
215 }
else if (7 == mFlag[iv]) {
217 return mVerts[iv][0];
225 int Pileup::n(
int iv,
int which) {
226 if (iv < 0 || mNVerts < iv) {
230 if (1 == mFlag[iv] || 2 == mFlag[iv] || 3 == mFlag[iv]) {
232 num = mVerts[iv][1] + mVerts[iv][3];
233 }
else if (2 == which) {
235 }
else if (3 == which) {
240 }
else if (4 == mFlag[iv] || 5 == mFlag[iv]) {
243 }
else if (2 == which) {
248 }
else if (6 == mFlag[iv]) {
250 num = mVerts[iv][1] + mVerts[iv][3];
251 }
else if (2 == which) {
253 }
else if (3 == which) {
258 }
else if (7 == mFlag[iv]) {
269 int Pileup::flag(
int iv) {
270 if (iv < 0 || mNVerts < iv) {
277 int Pileup::nearest(
StMuDst *muDst,
double z,
double *dist,
int *mult) {
286 double minDist = 9999.0;
288 for (
int ip=0;ip<mNPiles;ip++) {
289 for (
int ip4=0;ip4<mNPeaks[4];ip4++) {
290 for (
int ip5=0;ip5<mNPeaks[5];ip5++) {
292 if (2 == mPileFlag[ip]) {
293 dist = mPos[4][ip4]-mPos[5][ip5] - mPileDist[ip];
294 }
else if (3 == mPileFlag[ip]) {
295 dist = mPos[5][ip5]-mPos[4][ip4] - mPileDist[ip];
297 if ( mZPileMatchMin < dist && dist < mZPileMatchMax ) {
299 if (fabs(mPos[4][ip4]-z) < fabs(minDist)) {
300 minDist = mPos[4][ip4] - z;
301 minNum = int(mArea[4][ip4]);
303 if (fabs(mPos[5][ip5]-z) < fabs(minDist)) {
304 minDist = mPos[5][ip5] - z;
305 minNum = int(mArea[5][ip5]);
317 int Pileup::find(
StMuDst *muDst) {
343 for (
int i=0;i<5;i++) {
350 for (
int ip4=0;ip4<mNPeaks[4];ip4++) {
351 for (
int ip5=0;ip5<mNPeaks[5];ip5++) {
352 if ( mZPeakMatchMin < mPos[4][ip4]-mPos[5][ip5] &&
353 mPos[4][ip4]-mPos[5][ip5] < mZPeakMatchMax) {
355 mVerts[nVerts][0] = mPos[4][ip4];
356 mVerts[nVerts][1] = mArea[4][ip4];
357 mVerts[nVerts][2] = mPos[5][ip5];
358 mVerts[nVerts][3] = mArea[5][ip5];
359 mVerts[nVerts][4] = mPos[4][ip4]-mPos[5][ip5];
363 mMatchP[ip4] = nVerts;
364 mMatchM[ip5] = nVerts;
365 mUsedP[ip4] = nVerts;
366 mUsedM[ip5] = nVerts;
368 cout <<
"Good vertex. pos4 = " << mPos[4][ip4] <<
", pos5 = " << mPos[5][ip5] << endl;
374 for (
int ip=0;ip<mNPiles;ip++) {
375 for (
int ip4=0;ip4<mNPeaks[4];ip4++) {
376 for (
int ip5=0;ip5<mNPeaks[5];ip5++) {
378 if (2 == mPileFlag[ip]) {
379 dist = mPos[4][ip4]-mPos[5][ip5] - mPileDist[ip];
380 }
else if (3 == mPileFlag[ip]) {
381 dist = mPos[5][ip5]-mPos[4][ip4] - mPileDist[ip];
383 if ( mZPileMatchMin < dist &&
384 dist < mZPileMatchMax ) {
385 if (!mMatchP[ip4] && !mMatchM[ip5]) {
387 mVerts[nVerts][0] = mPos[4][ip4];
388 mVerts[nVerts][1] = mArea[4][ip4];
389 mVerts[nVerts][2] = mPos[5][ip5];
390 mVerts[nVerts][3] = mArea[5][ip5];
391 mVerts[nVerts][4] = dist;
392 mFlag[nVerts] = mPileFlag[ip];
395 mUsedP[ip4] = nVerts;
396 mUsedM[ip5] = nVerts;
398 cout <<
"Matched pileup at " << mPos[4][ip4] <<
" to " << mPos[5][ip5] <<
". Expected distance of " << mPileDist[ip] << endl;
400 }
else if (mMatchP[ip4]) {
402 mVerts[nVerts][0] = mPos[4][ip4];
403 mVerts[nVerts][1] = mArea[4][ip4];
404 mVerts[nVerts][2] = mPos[5][ip5];
405 mVerts[nVerts][3] = mArea[5][ip5];
407 mVerts[nVerts][4] = dist;
409 if (2 == mPileFlag[ip]) {
410 mVerts[nVerts][5] = mPos[5][ip5] + mPileDist[ip];
411 }
else if (3 == mPileFlag[ip]) {
412 mVerts[nVerts][5] = mPos[5][ip5] - mPileDist[ip];
414 mFlag[nVerts] = mPileFlag[ip] + 2;
417 mUsedM[ip5] = nVerts;
419 cout <<
"!!!!!Matched pileup with good vertex? 4 ->" << mPos[4][ip4] <<
" 5 -> " << mPos[5][ip5] <<
". Expected distance of " << mPileDist[ip] << endl;
421 }
else if (mMatchM[ip5]) {
423 mVerts[nVerts][0] = mPos[5][ip5];
424 mVerts[nVerts][1] = mArea[5][ip5];
425 mVerts[nVerts][2] = mPos[4][ip4];
426 mVerts[nVerts][3] = mArea[4][ip4];
428 mVerts[nVerts][4] = dist;
430 if (2 == mPileFlag[ip]) {
431 mVerts[nVerts][5] = mPos[4][ip4] - mPileDist[ip];
432 }
else if (3 == mPileFlag[ip]) {
433 mVerts[nVerts][5] = mPos[4][ip4] + mPileDist[ip];
435 mFlag[nVerts] = mPileFlag[ip] + 2;
438 mUsedP[ip4] = nVerts;
440 cout <<
"!!!!!Matched pileup with good vertex? 5 ->" << mPos[4][ip4] <<
" 5 -> " << mPos[5][ip5] <<
". Expected distance of " << mPileDist[ip] << endl;
448 int iPlus[5], nPlus = 0;
449 for (
int ip4=0;ip4<mNPeaks[4];ip4++) {
455 int iMinus[5], nMinus = 0;
456 for (
int ip5=0;ip5<mNPeaks[5];ip5++) {
458 iMinus[nMinus] = ip5;
462 if ( nPlus==1 && nMinus==1) {
464 mVerts[nVerts][0] = mPos[4][iPlus[0]];
465 mVerts[nVerts][1] = mArea[4][iPlus[0]];
466 mVerts[nVerts][2] = mPos[5][iMinus[0]];
467 mVerts[nVerts][3] = mArea[5][iMinus[0]];
468 mVerts[nVerts][4] = mPos[4][iPlus[0]]-mPos[5][iMinus[0]];
473 for (
int ip=0;ip<nPlus;ip++) {
475 mVerts[nVerts][0] = mPos[4][iPlus[ip]];
476 mVerts[nVerts][1] = mArea[4][iPlus[ip]];
481 for (
int im=0;im<nMinus;im++) {
483 mVerts[nVerts][0] = mPos[5][iMinus[im]];
484 mVerts[nVerts][1] = mArea[5][iMinus[im]];
491 cout <<
"Found too many vertices; nVerts = " << nVerts << endl;
498 int Pileup::fillQAHistos(
StMuDst *muDst) {
499 float x1, y1, z1, x2, y2, z2;
502 double phi1, phi2, pt;
506 for (
int i=0;i<3;i++) {
512 for (
int it=0;it<muDst->
globalTracks()->GetEntries();it++) {
514 flag = track->
flag();
515 if (flag < 0 || 700 <= flag) {
530 phi1 = fabs(atan2(y1,x1)*360/(2*3.1415926));
531 isec1 = int((phi1+15.0)/30.0);
532 phi1 = fabs(phi1-30*isec1);
533 phi2 = fabs(atan2(y2,x2)*360/(2*3.1415926));
534 isec2 = int((phi2+15.0)/30.0);
535 phi2 = fabs(phi2-30*isec2);
536 r1 = sqrt( x1*x1 + y1*y1 );
537 r2 = sqrt( x2*x2 + y2*y2 );
538 if (r1 > 50 && fabs(z1) < 190.0 && fabs(z2) < 190.0 && phi1 < 12.0 && phi2 < 12.0) {
542 mHQA2D[0]->Fill(z1,z2);
543 zS1 = z1 + (z2-z1)*(65.0-r1)/(r2-r1);
544 zS2 = z2 + (z1-z2)*(190.0-r2)/(r1-r2);
545 mHQA2D[1]->Fill(zS1,zS2);
546 mHQA2D[2]->Fill((65.0*zS2-190.0*zS1)/(65.0-190.0),zS2);
547 mHQA1D[2]->Fill( (65.0*zS2-190.0*zS1) / (65.0-190.0) );
554 int Pileup::fillHistos(
StMuDst *muDst) {
556 float x1, y1, z1, x2, y2, z2;
558 double phi1, phi2, pt;
562 for (
int i=0;i<6;i++) {
563 mHPileup[i]->Reset();
567 for (
int it=0;it<muDst->
globalTracks()->GetEntries();it++) {
569 flag = track->
flag();
570 if (flag < 0 || 700 <= flag) {
585 r1 = sqrt( x1*x1 + y1*y1 );
586 r2 = sqrt( x2*x2 + y2*y2 );
587 Vz = (r1*z2-r2*z1)/(r1-r2);
593 mHPileup[4]->Fill(Vz);
594 }
else if (z2 < -mDead[6]) {
595 mHPileup[5]->Fill(Vz);
603 phi1 = fabs(atan2(y1,x1)*360/(2*3.1415926));
604 isec1 = int((phi1+15.0)/30.0);
605 phi1 = fabs(phi1-30*isec1);
607 if (0 < z2 && z2 < 190) {
608 mHPileup[0]->Fill(z1);
609 }
else if (-190 < z2 && z2 < 0) {
610 mHPileup[1]->Fill(z1);
616 phi2 = fabs(atan2(y2,x2)*360/(2*3.1415926));
617 isec2 = int((phi2+15.0)/30.0);
618 phi2 = fabs(phi2-30*isec2);
619 if (phi2 < 12 && fabs(z2) < 190) {
621 mHPileup[2]->Fill(z2);
623 mHPileup[3]->Fill(z2);
633 int Pileup::findPeaks(
int ih) {
634 int nBins = mHPileup[ih]->GetNbinsX();
635 double binStart = mHPileup[ih]->GetBinLowEdge(1);
636 double binWidth = mHPileup[ih]->GetBinWidth(1);
637 double avg = mHPileup[ih]->Integral() / 400.0;
638 double min = 2.5+mHPileup[ih]->Integral()*7/1000.0;
642 for (
int i=2;i<nBins-1;i++) {
643 if (mHPileup[ih]->GetBinContent(i) > min) {
646 sum = mHPileup[ih]->GetBinContent(i);
648 mean = i*mHPileup[ih]->GetBinContent(i);
650 while (mHPileup[ih]->GetBinContent(j) > 2*avg+1) {
651 sum += mHPileup[ih]->GetBinContent(j);
653 mean += j*mHPileup[ih]->GetBinContent(j);
662 while (mHPileup[ih]->GetBinContent(j) > 2*avg+1 || mHPileup[ih]->GetBinContent(j+1) > 2*avg+1) {
663 sum += mHPileup[ih]->GetBinContent(j);
665 mean += j*mHPileup[ih]->GetBinContent(j);
676 if (sum-w*avg > 5*sqrt(w*avg)) {
682 for (
int ib=0;ib<5;ib++) {
683 back += mHPileup[ih]->GetBinContent(ib+k);
686 if (imax < nBins-6) {
688 for (
int ib=0;ib<5;ib++) {
689 back += mHPileup[ih]->GetBinContent(ib+k);
692 if (imin <= 5 || imax > nBins-5) {
696 mean = mean*binWidth + binStart;
697 if (fabs(mean) > mDead[ih]) {
698 if (sum-back > 5*sqrt(back)) {
700 mPos[ih][nPeaks] = mean;
701 mArea[ih][nPeaks] = sum;
702 mWidth[ih][nPeaks] = w;
706 printf(
"ih = %i: Width of peak = %f, area = %f, position = %f, background = %f\n",ih,w,sum,mean,back);
711 printf(
"Found a peak but it is in dead region. ");
712 printf(
"ih = %i:Width of peak = %f, area = %f, position = %f, background = %f\n",ih,w,sum,mean,back);
722 int Pileup::testFindPeaks(TH1D *h,
int ih) {
723 TH1D *lp = lowPass(h,1);
725 int nBins = lp->GetNbinsX();
726 double binStart = lp->GetBinLowEdge(1);
727 double binWidth = lp->GetBinWidth(1);
728 double avg = lp->Integral() / nBins;
729 double min = 5*sqrt(avg);
733 for (
int i=2;i<nBins-1;i++) {
734 if (lp->GetBinContent(i) > min) {
737 sum = lp->GetBinContent(i);
739 mean = i*lp->GetBinContent(i);
742 while (lp->GetBinContent(j) > 2*sqrt(avg)) {
743 sum += lp->GetBinContent(j);
745 mean += j*lp->GetBinContent(j);
752 while (lp->GetBinContent(j) > 2*sqrt(avg)) {
753 sum += lp->GetBinContent(j);
755 mean += j*lp->GetBinContent(j);
763 if (sum-w*avg > 5*sqrt(w*avg)) {
764 mean = mean*binWidth + binStart;
765 if (fabs(mean) > mDead[ih]) {
767 mPos[ih][nPeaks] = mean;
768 mArea[ih][nPeaks] = sum;
769 mWidth[ih][nPeaks] = w;
773 printf(
"ih = %i: Width of peak = %f, area = %f, position = %f\n",ih,w,sum,mean);
777 printf(
"Found a peak but it is in dead region. ");
778 printf(
"ih = %i:Width of peak = %f, area = %f, position = %f\n",ih,w,sum,mean);
789 TH1D* Pileup::lowPass(TH1D *h,
int width) {
790 TH1D *lp = (TH1D *) h->Clone();
792 int upper = h->GetNbinsX();
794 int nSum, jMin, jMax;
796 for (
int i=1;i<upper;i++) {
797 jMin = i-width < 1 ? 1 : i-width;
798 jMax = i+width >upper ? upper : i+width;
801 for (
int j=jMin;j<jMax;j++) {
802 sum += h->GetBinContent(j);
805 lp->SetBinContent(i,sum/nSum);
810 int Pileup::findPiles() {
812 for (
int ih=0;ih<6;ih++) {
813 mNPeaks[ih] = findPeaks(ih);
814 if (mNPeaks[ih] > 5) {
815 cout <<
"Vertex " << ih <<
" had " << mNPeaks[ih] <<
" peaks found which is too big for my arrays." << endl;
823 for (
int ip0=0;ip0<mNPeaks[0];ip0++) {
824 for (
int ip3=0;ip3<mNPeaks[3];ip3++) {
825 if ( mZStartStopMatchMin < mPos[0][ip0]+mPos[3][ip3] &&
826 mPos[0][ip0]+mPos[3][ip3] < mZStartStopMatchMax) {
828 cout <<
"Possible match for pre + -. pos0 = " << mPos[0][ip0] <<
", pos3 = " << mPos[3][ip3] << endl;
833 mPileDist[mNPiles] = mPos[0][ip0] - mPos[3][ip3];
834 mPileFlag[mNPiles] = 2;
840 for (
int ip2=0;ip2<mNPeaks[2];ip2++) {
841 for (
int ip1=0;ip1<mNPeaks[1];ip1++) {
842 if ( mZStartStopMatchMin < mPos[2][ip2]+mPos[1][ip1] &&
843 mPos[2][ip2]+mPos[1][ip1] < mZStartStopMatchMax) {
845 cout <<
"Possible match for pre - +. pos2 = " << mPos[2][ip2] <<
", pos1 = " << mPos[1][ip1] << endl;
848 mPileDist[mNPiles] = mPos[2][ip2] - mPos[1][ip1];
849 mPileFlag[mNPiles] = 2;
856 for (
int ip2=0;ip2<mNPeaks[2];ip2++) {
857 for (
int ip3=0;ip3<mNPeaks[3];ip3++) {
858 if ( mZStartStopMatchMin < mPos[2][ip2]+mPos[3][ip3] &&
859 mPos[2][ip2]+mPos[3][ip3] < mZStartStopMatchMax) {
861 cout <<
"Possible match for post. pos2 = " << mPos[2][ip2] <<
", pos3 = " << mPos[3][ip3] << endl;
865 mPileDist[mNPiles] = mZEndplate-mPos[2][ip2] + mZEndplate+mPos[3][ip3];
866 mPileFlag[mNPiles] = 3;
873 cout <<
"Found too many piles; nPiles = " << mNPiles << endl;
879 TH1D *Pileup::hist(
int ih) {
892 if (ih < 0 || 5 < ih) {
898 TH1D *Pileup::histQA1D(
int ih) {
903 if (ih < 0 || 2 < ih) {
909 TH2D *Pileup::histQA2D(
int ih) {
914 if (ih < 0 || 2 < ih) {
static TObjArray * globalTracks()
returns pointer to the global tracks list
Double_t pt() const
Returns pT at point of dca to primary vertex.
short flag() const
Returns flag, (see StEvent manual for type information)
const StThreeVectorF & firstPoint() const
Returns positions of first measured point.
const StThreeVectorF & lastPoint() const
Returns positions of last measured point.