00001
00002
00003 #include <assert.h>
00004 #include <stdlib.h>
00005
00006
00007 #include <TClonesArray.h>
00008 #include <TVector3.h>
00009 #include <TObjArray.h>
00010 #include <TH1.h>
00011 #include <TH2.h>
00012
00013 #include "EEsoloPi0.h"
00014
00015 #include "StEEmcUtil/EEfeeRaw/EEfeeRawEvent.h"
00016 #include "StEEmcUtil/EEfeeRaw/EEstarTrig.h"
00017 #include "StEEmcUtil/EEfeeRaw/EEmcEventHeader.h"
00018
00019 #include "StEEmcUtil/EEfeeRaw/EEfeeDataBlock.h"
00020 #include "StEEmcUtil/EEfeeRaw/EEname2Index.h"
00021
00022 #include "StEEmcUtil/database/EEmcDbItem.h"
00023
00024
00025 #ifdef StRootFREE
00026 #include "EEmcDb/EEmcDb.h"
00027 #else
00028 #include "StEEmcUtil/database/StEEmcDb.h"
00029 #endif
00030
00031
00032 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
00033
00034 ClassImp(EEsoloPi0)
00035
00036
00037 EEsoloPi0::EEsoloPi0(){
00038
00039 nInpEve=0;
00040 HList=0;
00041 eeDb=0;
00042 dbMapped=-1;
00043
00044 geom= new EEmcGeomSimple();
00045 set(0,0,0);
00046 printf("EEsoloPi0() constructed\n");
00047 nClust=0;
00048
00049 float XscaleFactor=1;
00050 float XseedEnergy=0.8;
00051 float XshapeLimit=.7;
00052 float XmassLo=0.07, XmassHi=0.22;
00053 set(XscaleFactor, XseedEnergy,XshapeLimit,XmassLo,XmassHi);
00054 memset(hA,0, sizeof(hA));
00055 memset(hR,0, sizeof(hR));
00056 memset(hM,0, sizeof(hM));
00057
00058 }
00059
00060
00061
00062 EEsoloPi0::~EEsoloPi0() {}
00063
00064
00065
00066 void EEsoloPi0::initRun(int runID){
00067 printf(" EEsoloPi0::initRun(%d)\n",runID);
00068
00069 assert(dbMapped<0);
00070 dbMapped=runID;
00071 }
00072
00073
00074
00075
00076 void EEsoloPi0::init(){
00077 int i;
00078 float Emax=20;
00079 TString C="";
00080
00081 hA[0]=new TH1F ("tE","Eneregy (GeV) from any tower",100,0.,Emax);
00082 hA[1]=new TH1F ("sE","Total Eneregy in event (GeV) (sum from all tower)",100,0.,Emax*24);
00083
00084 hA[2]=new TH1F ("cE","cluster Eneregy (GeV) ",200,0.,1.5*Emax);
00085
00086 hA[3]=new TH1F ("cSh","Shape: energy ratio highT/cluster",55,0.,1.1);
00087 hA[4]=new TH1F ("cN","No. of clusters per event",30,-0.5,29.5);
00088 hA[5]=new TH1F ("tT","Transverse Eneregy (GeV) from any tower",100,0.,Emax);
00089 hA[6]=0;
00090 hA[7]=new TH1F ("ctbSum","CTB ADC sum", 240,0,12000);
00091
00092 if(HList) {
00093 for(i=0;i<=14;i++) {
00094 if(hA[i]==0) continue;
00095 HList->Add(hA[i]);
00096 }
00097 }
00098
00099
00100 hR[0]=0;
00101
00102 hR[1]=new TH1F ("invm","Invariant mass of 2 gammas (GeV)",80,0.,1.2);
00103
00104 hR[2]=(TH1F*)new TH2F ("d-E","Distance (cm) vs. 2clust energy (GeV)",50,0,1.5*Emax,100,0.,100);
00105 hR[3]=(TH1F*)new TH2F ("eta12","eta1 vs. eta2 (bins)",12,0.5,12.5,12,0.5,12.5);
00106
00107 hR[4]=(TH1F*)new TH2F ("xyL","Y vs. X (cm) of LOW energy cluster",200,-250.,250,200,-250,250);
00108 hR[5]=(TH1F*)new TH2F ("xyH","Y vs. X (cm) of HIGH energy cluster",200,-250.,250,200,-250,250);
00109 hR[6]=new TH1F ("oAng","Opening angle/rad of any pair",30,0.,.3);
00110
00111
00112 char ttt[100];
00113 sprintf(ttt,"cut invM=[%.2f,%.2f]",mLo,mHi);
00114 hR[7]=new TH1F ("0ener","Energy (GeV), "+C+ttt,50,0.,Emax/2.);
00115 hR[8]=new TH1F ("0eta","Pseudorapidity, "+C+ttt,25,0.,2.5);
00116 hR[9]=new TH1F ("0phi","phi/rad, "+C+ttt,30,-3.14,3.14);
00117 hR[10]=new TH1F ("0pt","pT (GeV/c), "+C+ttt,50,0.,Emax/4.);
00118 hR[11]=(TH1F*)new TH2F ("0xyL","Y vs. X (cm) of LOW energy, "+C+ttt,200,-250.,250,200,-250,250);
00119 hR[12]=(TH1F*)new TH2F ("0xyH","Y vs. X (cm) of HIGH energy, "+C+ttt,200,-250.,250,200,-250,250);
00120
00121 hR[13]=new TH1F ("ytw","Yield of clusters ;X= iphi+(Eta-1)*60, spiral",721,-.5,720.5);
00122
00123 hR[14]=new TH1F ("0ytw","Yield of clusters, "+C+ttt+";X= iphi+(Eta-1)*60, spiral",721,-.5,720.5);
00124
00125 hR[15]=(TH1F*)new TH2F ("0d-E","Distance (cm) vs. 2clust energy (GeV), "+C+ttt,50,0,Emax,100,0.,100);
00126
00127
00128 hR[24]=new TH1F ("0Ang","Opening angle/rad of pairs "+C+ttt,50,0.,.7);
00129 hR[25]=(TH1F*)new TH2F ("invH","Time (minutes) vs. Invariant mass of 2 gammas (GeV)",75,0.,1.5,50,0,100);
00130 hR[26]=new TH1F ("0Z","Z=|E1-E2|/sum ,"+C+ttt,25,0.,1.0);
00131
00132
00133 for(i=0;i<12;i++) {
00134 char t1[100],t2[100];
00135 sprintf(t1,"invm%02d",i+1);
00136 sprintf(t2,"Invariant mass(GeV), ETA=%d",i+1);
00137 hR[27+i]=new TH1F (t1,t2,80,0.,1.2);
00138 }
00139
00140 for(i=0;i<=38;i++) {
00141 TH1F *h1=hR[i];
00142 if(h1==0) continue;
00143 TH1F *h2=(TH1F *)h1->Clone();
00144 TString tt=h2->GetTitle();
00145 h2->SetTitle( "MIX: "+tt);
00146 tt=h2->GetName();
00147 h2->SetName( "X"+tt);
00148 h2->SetLineColor(kGreen);
00149 hM[i]=h2;
00150 if(HList) {
00151 HList->Add(h1);
00152 HList->Add(h2);
00153 }
00154 }
00155
00156
00157 printf("\nEEsoloPi0::init(), cuts: scaleFactor=%f ch/GeV, seedEnergy=%f GeV ,shapeLimit=%f, mLo=%.2f GeV, mHi=%.2f GeV\n\n",scaleFactor, seedEnergy,shapeLimit,mLo, mHi);
00158
00159
00160
00161
00162 oldClust.eH=0.5;
00163 oldClust.eC=0.6;
00164 oldClust.k1=1;
00165 oldClust.fphi=1.;
00166 oldClust.feta=1.;
00167
00168
00169 clear();
00170 TotN2g=totPi0=totXPi0=0;
00171
00172 }
00173
00174
00175
00176 void EEsoloPi0::clear(){
00177 if( nClust>1) {
00178 int j=rand()%nClust;
00179 oldClust=clust[j];
00180 }
00181 memset(soloMip,0,sizeof(soloMip));
00182 memset(clust,0,sizeof(clust));
00183 nClust=0;
00184
00185 }
00186
00187
00188
00189
00190 void EEsoloPi0::finish(){
00191 float s1=totPi0;
00192 float s2=totXPi0;
00193 if(s1==0) s1=-1;
00194 if(s2==0) s2=-1;
00195 float x=s1-s2;
00196 float ex=sqrt(s1+s2);
00197 printf("s1=%f s2=%f\n",s1,s2);
00198 float s2b=x/s2;
00199
00200 float es2b=s2b*sqrt(1/s1+1/s2);
00201
00202 printf("\n EEsoloPi0::finish() TotN2g=%d, totPi0=%d totXPi0=%d \n",TotN2g,totPi0,totXPi0);
00203 printf(" Npi0=%.0f + / - %.0f , s2b=%.2f + / - %.3f for invm=[%.2f, %.2f]\n\n", x,ex,s2b,es2b,mLo,mHi);
00204
00205
00206 }
00207
00208
00209
00210
00211 void EEsoloPi0::print(){
00212 printf("\n EEsoloPi0::print()\n soloMip dump:\n");
00213 int k0;
00214 for(k0=0;k0<MxTw;k0++) {
00215 if(soloMip[k0].e<=0) continue;
00216
00217 int ieta=k0%12;
00218 int iphi=k0/12;
00219 printf("ieta=%d iphi=%d key=%d e=%f id=%d\n",ieta,iphi,soloMip[k0].key,soloMip[k0].e,soloMip[k0].id);
00220 }
00221
00222 printf("Clusters found:\nid k1 feta fphi eneTot\n");
00223 int ic;
00224 for(ic=0;ic<nClust;ic++) {
00225 printf("%d %d %.2f %.2f %5g\n",ic+1, clust[ic].k1,clust[ic].feta,clust[ic].fphi,clust[ic].eC);
00226 }
00227 }
00228
00229
00230
00231 int EEsoloPi0:: findTowerClust() {
00232 assert(seedEnergy>0);
00233
00234 int k;
00235 float totEner=0;
00236 for(k=0;k<MxTw;k++) {
00237 float ene=soloMip[k].e;
00238 if(ene<=0) continue;
00239
00240 hA[0]->Fill(ene);
00241 totEner+=ene;
00242 }
00243 hA[1]->Fill(totEner);
00244
00245
00246 while(1) {
00247 float maxE=seedEnergy;
00248 int k0,k1=-1;
00249 for(k0=0;k0<MxTw;k0++) {
00250 if(soloMip[k0].e<maxE) continue;
00251 if(soloMip[k0].key>0) continue;
00252 k1=k0;
00253 maxE=soloMip[k0].e;
00254 }
00255 if(k1<0) break;
00256
00257 clust[nClust].k1=k1;
00258 clust[nClust].eH=soloMip[k1].e;
00259 nClust++;
00260 soloMip[k1].id=nClust;
00261 tagCluster(k1);
00262 }
00263
00264
00265
00266
00267 Cluster clustG[MxTw];
00268 int nClustG=0;
00269 int ic;
00270 for(ic=0;ic<nClust;ic++) {
00271 sumTwClusterEnergy(ic);
00272 float rat=clust[ic].eH/clust[ic].eC;
00273
00274 if(rat<shapeLimit) continue;
00275 hA[2]->Fill(clust[ic].eC);
00276 hA[3]->Fill(rat);
00277 clustG[nClustG++]=clust[ic];
00278 }
00279
00280
00281
00282
00283 for(ic=0;ic<nClustG;ic++) {
00284
00285 clust[ic]=clustG[ic];
00286 }
00287 nClust=nClustG;
00288
00289 hA[4]->Fill(nClust);
00290
00291 return nClust;
00292 }
00293
00294
00295
00296
00297
00298 void EEsoloPi0::findTowerPi0() {
00299 if(nClust<2) return ;
00300
00301
00302 int i,j;
00303 for(i=0;i<nClust;i++)
00304 for(j=i+1;j<nClust;j++) {
00305
00306 Cluster *cl1=&clust[i];
00307 Cluster *cl2=&clust[j];
00308
00309 totPi0+=findInvM(cl1,cl2,hR);
00310
00311
00312
00313 if(rand()%2)
00314 cl1=&oldClust;
00315 else
00316 cl2=&oldClust;
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326 float a=cl1->feta - cl2->feta;
00327 float b=cl1->fphi - cl2->fphi;
00328
00329
00330
00331 if(b<0) b+=MxTwPhi;
00332 if(b>MxTwPhi/2.) b=MxTwPhi-b;
00333 if(sqrt(a*a+b*b) <sqrt(2.) )continue;
00334
00335 totXPi0+=findInvM(cl1,cl2,hM);
00336
00337 }
00338
00339
00340 }
00341
00342
00343
00344
00345
00346 void EEsoloPi0:: tagCluster(int k0,int d){
00347
00348 int ieta=k0%12;
00349 int iphi=k0/12;
00350
00351 int i,j;
00352 float ener=soloMip[ ieta + MxTwEta*iphi ].e;
00353 for(i=ieta-d; i<=ieta+d;i++){
00354
00355 if( i>=MxTwEta || i<0) continue;
00356 for(j=iphi-d;j<=iphi+d;j++){
00357 int jj=j;
00358 if( jj<0 ) jj+=MxTwPhi;
00359 if( jj>=MxTwPhi ) jj-=MxTwPhi;
00360 assert( jj>=0 && jj<MxTwPhi );
00361 soloMip[ i + MxTwEta*jj ].key+=(int)(1000*ener);
00362
00363 }
00364 }
00365 }
00366
00367
00368
00369 void EEsoloPi0:: sumTwClusterEnergy(int ic,int d){
00370
00371 int k0=clust[ic].k1;
00372 int ieta=k0%12;
00373 int iphi=k0/12;
00374
00375 int i,j;
00376 float w0=soloMip[ieta + MxTwEta*iphi].key;
00377 double sum=0, sumi=0, sumj=0;
00378 for(i=ieta-d; i<=ieta+d;i++){
00379 if( i>=MxTwEta || i<0) continue;
00380 for(j=iphi-d;j<=iphi+d;j++){
00381 int jj=j;
00382 if( jj<0 ) jj+=MxTwPhi;
00383 if( jj>=MxTwPhi ) jj-=MxTwPhi;
00384 assert( jj>=0 && jj<MxTwPhi );
00385 int k1=i + MxTwEta*jj;
00386 if(soloMip[k1].e<=0) continue;
00387
00388 float w=w0/soloMip[ k1 ].key;
00389
00390
00391 float e=w*soloMip[k1 ].e;
00392
00393 sum+=e;
00394 sumi+=e*i;
00395 sumj+=e*j;
00396 }
00397 }
00398 assert(sum>0);
00399
00400 clust[ic].eC=sum;
00401 clust[ic].feta=sumi/sum;
00402 clust[ic].fphi=sumj/sum;
00403
00404
00405 }
00406
00407
00408
00409 float EEsoloPi0::sumPatchEnergy(int k0,int d,EEsoloMipA *soloMipX, float *maxVal){
00410
00411 int ieta=k0%12;
00412 int iphi=k0/12;
00413
00414 int i,j;
00415 double sum=0;
00416 double max=0;
00417 for(i=ieta-d; i<=ieta+d;i++){
00418 if( i>=MxTwEta || i<0) continue;
00419 for(j=iphi-d;j<=iphi+d;j++){
00420 int jj=j;
00421 if( jj<0 ) jj+=MxTwPhi;
00422 if( jj>=MxTwPhi ) jj-=MxTwPhi;
00423 assert( jj>=0 && jj<MxTwPhi );
00424 int k1=i + MxTwEta*jj;
00425 if(soloMipX[k1].e<=0) continue;
00426 sum+=soloMipX[k1 ].e;
00427 if(max<soloMipX[k1 ].e) max=soloMipX[k1 ].e;
00428 }
00429 }
00430
00431 if(maxVal) *maxVal=max;
00432
00433 printf("sumPatchEnergy(k0=%d, d=%d)=%f ,max=%f\n",k0, d,sum,max);
00434 return sum;
00435 }
00436
00437
00438
00439
00440
00441 int EEsoloPi0::findInvM(Cluster *c1, Cluster *c2, TH1F **h){
00442 int isPi0=0;
00443 float e1=c1->eC;
00444 float e2=c2->eC;
00445
00446
00447 TVector3 r1=geom-> getDirection( c1->feta, c1->fphi);
00448 TVector3 r2=geom-> getDirection( c2->feta, c2->fphi);
00449
00450 TVector3 p1=e1* r1.Unit();
00451 TVector3 p2=e2* r2.Unit();
00452
00453 float opAngle=p1.Angle(p2);
00454
00455
00456 h[6]->Fill(opAngle);
00457
00458 TVector3 p12=p1+p2;
00459 float e12=e1+e2;
00460 float invm2= e12*e12-p12*p12;
00461 float invm=sqrt(invm2);
00462 TVector3 r12=r1-r2;
00463 float d12=sqrt(r12*r12);
00464
00465 #if 0
00466 if(invm>0.1 & invm<0.20)
00467 {
00468 printf("\ninvM=%.3f e1=%.2f e2=%.2f ", invm,e1,e2);
00469
00470 #if 0
00471
00472 float mm2=2.0*e1*e2*(1.0-cos(p1.Angle(p2)));
00473 printf("\ninvM=%f e1=%f e2=%f feta1=%f fphi1=%f feta2=%f fphi2=%f\n d12/cm=%f ang01=%f ang02=%f ang12=%f etot=%f m=%f\n",
00474 invm,e1,e2,c1->feta, c1->fphi,c2->feta, c2->fphi,d12,p12.Angle(p1),p12.Angle(p2),p1.Angle(p2),e12, sqrt(mm2));
00475
00476 printf(" x1,y1,z1=%f %f %f\n",r1.x(),r1.y(),r1.z());
00477 printf(" x2,y2,z2=%f %f %f\n",r2.x(),r2.y(),r2.z());
00478 printf(" p1,p1,p1=%f %f %f\n",p1.x(),p1.y(),p1.z());
00479 printf(" p2,p2,p2=%f %f %f\n",p2.x(),p2.y(),p2.z());
00480 #endif
00481 }
00482
00483 #endif
00484
00485 h[1]->Fill(invm);
00486 h[25]->Fill(invm,timeSec/60.);
00487
00488 h[(int) (27+c1->feta)] ->Fill(invm);
00489 h[(int) (27+c2->feta)] ->Fill(invm);
00490
00491 if(c1->eC < c2->eC) {
00492 ((TH2F*) h[4])->Fill(r1.x(),r1.y());
00493 ((TH2F*) h[5])->Fill(r2.x(),r2.y());
00494 } else {
00495 ((TH2F*) h[5])->Fill(r1.x(),r1.y());
00496 ((TH2F*) h[4])->Fill(r2.x(),r2.y());
00497 }
00498
00499 int bin1=1+c1->k1%12;
00500 int bin2=1+c2->k1%12;
00501 if (bin2>bin1) { int kk=bin1; bin1=bin2; bin2=kk;}
00502
00503 ((TH2F*) h[3])->Fill(bin1, bin2);
00504
00505 ((TH2F*) h[2])->Fill(e12,d12);
00506
00507
00508 int kk1=(c1->k1%12)*60+ (c1->k1/12);
00509 int kk2=(c2->k1%12)*60+ (c2->k1/12);
00510 h[13]->Fill(kk1);
00511 h[13]->Fill(kk2);
00512
00513 if(mLo<invm && invm<mHi){
00514 isPi0=1;
00515 h[7]->Fill(e12);
00516 h[8]->Fill(p12.Eta());
00517 h[9]->Fill(p12.Phi());
00518 h[10]->Fill(p12.Pt());
00519 h[14]->Fill(kk1);
00520 h[14]->Fill(kk2);
00521 ((TH2F*) h[15])->Fill(e12,d12);
00522 h[24]->Fill(opAngle);
00523
00524 float zE=fabs(c1->eC - c2->eC)/(c1->eC + c2->eC);
00525 h[26]->Fill(zE);
00526
00527 if(c1->eC < c2->eC) {
00528 ((TH2F*) h[11])->Fill(r1.x(),r1.y());
00529 ((TH2F*) h[12])->Fill(r2.x(),r2.y());
00530 } else {
00531 ((TH2F*) h[12])->Fill(r1.x(),r1.y());
00532 ((TH2F*) h[11])->Fill(r2.x(),r2.y());
00533 }
00534 }
00535 return isPi0;
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565 #if 0
00566 float adc2gev[MaxEtaBins]={
00567 18.938, 20.769, 22.650, 24.575,
00568 26.539, 28.514, 30.493, 32.473,
00569 34.438, 36.387, 38.28, 40.146 };
00570
00571 if(strstr(x->name,"01TA05")) continue;
00572 if(strstr(x->name,"11TD09")) continue;
00573 if(strstr(x->name,"09TB06")) continue;
00574
00575
00576 #endif
00577