FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_ana/anak4g.cpp

00001 /***************************************************************************
00002                           anak4g.cpp  -  description
00003                              -------------------
00004     begin                : Sat Jan 18 2003
00005     copyright            : (C) 2003 by Giuseppe Pierazzini
00006     email                : peppe@unipi.it
00007   ***************************************************************************
00008   *                                                                         *
00009   *   NA48  simulation program.                                             *
00010   *                                                                         *
00011   ***************************************************************************/
00012 #define EPSR     1.0E-200
00013 
00014 #include "flyoh.h"
00015 #include "anak4g.h"
00016 
00017 using namespace std;
00018 
00029 AnaK4g::AnaK4g()
00030 {
00031   tipo=1;nfit=4;titol="K--> 2 pi0 -> 4 gam" ;nome="K4gam";
00032   nd=0;
00033   pi0mass=ptr_Pi0->Get_Massa();
00034   twopi0mass=2.*pi0mass,pi0massq=pi0mass*pi0mass;
00035   Utot=msqAvo+3.*pi0massq;
00036   Gout<<"\n Definito il fit "<<titol<<" con K="<<msAvo<<" piomas="<<pi0mass;
00037 }
00038 
00039 //============
00040 int AnaK4g::kappa(int i,int j)
00041 //---------------nota on index ...
00042 //define k from 0 to 5 (01,02,03,12,13,23)
00043 //   k= i*3+j    with i<j    no i==j!!!
00044 //   if(i>0)k++;
00045 //   if(i=4)k=15;
00046 //--------------------------------
00047 
00048 { if(i>j)   //swap
00049   { int jj=j; j=i; i=jj;}
00050   int k=i*2+j-1;
00051   if(i==2)k=5;
00052   //   Gout<<"\n i j k %2d %2d %2d",i,j,k);
00053   return k;
00054 }
00055 
00056 
00057 
00058 //=========  N e u t r a l    n pi0   F i t =====
00059 
00060 //------------------------------------
00061 double  AnaK4g::Distvtx()
00062 {
00063   //  Decay  K -> pi0 pi0
00064   // procedure for the  calculation of distance
00065   // of decay vertice from calorimetr + 
00066   // the gg masses
00067   double qij,xi,xj,yi,yj,dx,dy,ei,ej,cxij,cyij;
00068   double dq=0.0;
00069   int i=0,j,k=-1;
00070   Kmax=((nfit-1)*nfit)/2;
00071   // number indipendente pairings
00072   
00073   while(i<nfit)
00074   {
00075     ei=egood[i];
00076     xi=xgood[i];
00077     yi=ygood[i];
00078 
00079 //    Gout<<"\n Dstvtx"<< nfit<<"   "<<idpr[i]<<"  "<<lkry->Pdev[i].e<<" "<<ei<<" "<<xi<<" "<<yi;
00080 
00081 
00082     j=i+1;
00083     while(j<nfit)
00084     {
00085       ej=egood[j];
00086       xj=xgood[j];
00087       yj=ygood[j];
00088 
00089       //  k index to speed up pairing ..
00090       //  Kmax= (mishit**2-mishit)/2= elementi off diagonal/2.
00091       //  for 4 gamma:
00092       //  define k from 0 to 5 (01,02,03,12,13,23)
00093       //  for 6 gamma:
00094       //  define k from 0 to 15 (01,02,03,04,05,12,13,14,15,23,24,25,34,35,45)
00095       k++;
00096 
00097       dxij[k]=dx=xi-xj;
00098       dyij[k]=dy=yi-yj;
00099 
00100       if ((dx*dx+dy*dy) < 100.) return -2.;   // attenzione???????? distanza cluster
00101 
00102       qij=ei*ej;
00103       cxij=exij[k]=qij*dx*dx;
00104       cyij=eyij[k]=qij*dy*dy;
00105       dq+=cxij+cyij;
00106       j++;
00107     }
00108     i++;
00109   }
00110   distq=dq/msqAvo;
00111   dist=sqrt(distq);
00112 
00113   Particella *pr;
00114   pr=SelRea->avo; 
00115 
00116    
00117   // define the massees
00118   for(k=0;k<Kmax;k++)
00119   {
00120     egij[k]=exij[k]+eyij[k];
00121     mij[k]=sqrt(egij[k]/distq);
00122 
00123     if(Debugon==1)
00124     {
00125       Gout<<"\nEv "<<evento_.Gen.Event<<" Distpiu Masse k "<<k<<" ms="<<mij[k]<<std::endl;
00126     }
00127   }
00128   return dist;
00129 }
00130 
00131 //------------------------------------
00132 
00133 double AnaK4g::Degij(int k,int i)
00134 {
00135   // calcola la derivata della prodotto  egij(k)=el*ej*dqlj rispetto
00136   //alle variabili v(i)= x1,..x4,y1,..y4,e1,..e4
00137   // matrice per la definizione della metrica...
00138   static double cij[4][6] =    {{2., 2., 2., 0., 0., 0.},
00139                                 {-2., 0., 0., 2., 2., 0.},
00140                                 { 0.,-2., 0.,-2., 0., 2.},
00141                                 { 0., 0.,-2., 0.,-2.,-2.}} ;
00142 
00143   int ii=i%4;
00144   double derv= cij[ii][k];
00145   if(derv==0.0) return 0.0;
00146   // x1..x4  y1...y4   e1...e4
00147 
00148   if(i<4)      derv*=    exij[k]/dxij[k];
00149   else if(i<8) derv*=    eyij[k]/dyij[k];
00150   else if(i>7) derv =    egij[k]/egood[ii];
00151   return derv;
00152 }
00153 //--------------------------------------------------
00154 
00155 void AnaK4g::Ddistq()
00156 {
00157 
00158   // errors   on the (x1,..x4(x6),y1,..y4(y6), e1,..e4(e6))
00159   int mis2=2*nfit;
00160   for(int i=0;i<nfit;i++)
00161   {
00162     double ep=egood[i];
00163     //    se= sqrt(0.01 + (0.001024+2.5e-5*ep)*ep);       // 1998
00164     sv[i+mis2]=sqrt(0.0081 + (0.001024+1.764e-5*ep)*ep);  // 1999
00165     //    sv[i] =sv[i+nfit] =sqrt(3.6e-3 + 0.001764/ep);
00166     sv[i] =sv[i+nfit] =sqrt(3.6e-3 + 0.1764/ep);      // correzione 2001
00167 
00168   }
00169 
00170   // derivate di distq rispetto alle variabili
00171   // nvar allready defined nvar=3*nfit
00172   //var(i)i (x1...y1...e1...e6) in ddistq(nvar)
00173   double der=0.0;
00174   int i=0,k;
00175   while(i<nvar)
00176   {
00177     der=0.0;
00178     k=0;
00179     while(k<Kmax)
00180     {
00181       der+=Degij(k,i);
00182       k++;
00183     }
00184     dersq[i]=der/msqAvo;   // attenzione per il pionio....
00185 
00186     i++;
00187   }
00188 }
00189 
00190 //----------------------------------------------
00191 
00192 void AnaK4g::Simq(int k1, int k2)
00193 {
00194   // calcolo sigma sulle variabili del chiq
00195   // v_i (x1...y1...e1...e4) in ddistq(12)
00196   double de1,de2,des, def;
00197   int i=0;                        //??????
00198   double m1=mij[k1], m2=mij[k2];
00199   dsumq=0.;
00200   diffq=0.;
00201   while(i<12)
00202   {
00203 
00204     de1 =0.9*sv[i]*(Degij(k1,i)- m1*m1*dersq[i])/(2.*distq*m1);
00205     de2 =0.9*sv[i]*(Degij(k2,i)- m2*m2*dersq[i])/(2.*distq*m2);
00206 
00207     des=de1+de2;
00208     def=de1-de2;
00209 
00210     dsumq+=des*des;
00211     diffq+=def*def;
00212 
00213     //     if(Debugon==1)
00214     //     Gout<<"\n err %3ld %1d %1d %11.7lf %11.7lf %11.7lf  %11.7lf %11.7lf  %11.7lf",
00215     //     Event,k1,k2,m1,m2,de1,de2,dv1,dv2);
00216 
00217     i++;
00218   }
00219 
00220   if(Debugon==1)
00221     Gout<<"\n S m: "<<m1<<" dsmq="<< dsumq<<" ddfq= "<< diffq<<diffq/dsumq;
00222 
00223 }
00224 
00225 //----------------------------------------------------
00226 void AnaK4g::print_scale()
00227 {
00228 
00229   Gout<<"\n -----> "<<titol<<" Analysis Summary <-------\n";
00230 
00231   Gout<<"\n Fit entries          "<<count_call;
00232   Gout<<"\n Too few gams         "<<getta_gg;
00233   Gout<<"\n Too few charge       "<<getta_ch;
00234   Gout<<"\n Killed by energy     "<<getta_en;
00235   Gout<<"\n Killed by cog        "<<getta_cog;
00236   Gout<<"\n Vertex               "<<getta_gf;
00237   Gout<<"\n Tau cut              "<<getta_tau;
00238   Gout<<"\n No good fit          "<<getta_fit;
00239   Gout<<"\n Good events          "<<count_wnt;
00240   Gout<<"\n\n ======>           d o n e     <============ "<<std::endl;
00241 }
00242 //-------------------------------------------
00243 void AnaK4g::Reset_parm()
00244 {
00245   nd=0;
00246   mgg[0]=mgg[1]=mgg[2]=-1.;
00247   egamtot=cog=cvita=peso=0.0; chisq=3000.;
00248   zeta=-12020.;
00249   nextra=0;
00250   for(int i=0;i<8;i++){e[i]=egood[i]=0.0;}
00251   nvar=3*nfit;
00252 }
00253 //=========================
00254 
00255 int AnaK4g::Fisica()
00256 {
00257   // neutral procedure  for gammas in lkr calorimeter
00258   // cuts: acceptance, distance between ganmmas,
00259   //       energy,
00260   // calculate ekappa,egamtot,cog, cvita,masse,chisq
00261   // make cuts and evaluate the best chisq fit
00262   //----------------------------------------------------
00263   //----------------- reset----------------------------
00264   double egx;
00265   count_call++;
00266   if(Debugon==1)Write_titol();
00267   Reset_parm();
00268 
00269    if(tipo==2&&lkry->mhit!=6){getta_gg++;return -2;}
00270    else if(tipo==1&& lkry->mhit!=4){getta_gg++;return -2;}
00271 //  altri test per altre reazioni
00272 
00273   mishit=lkry->mhit;
00274 
00275   // get coordinates  and xcog
00276   double xi,yi,xcog=0.0,  ycog=0.0;
00277 
00278   int ngood=-1;
00279   for(int i=0;i<mishit;i++)
00280   {
00281     egx=lkry->M_Hits[i].e_rivela;
00282     if (egx<=1.5)  nextra++;       // fiorini dixit
00283 
00284 
00285     if(egx<3.||egx>100.)   continue;  // giudici 2007 energia test
00286     xi=lkry->M_Hits[i].Xdev.x;
00287     yi=lkry->M_Hits[i].Xdev.y;
00288 
00289 
00290 //      if (xi*xi+yi*yi<225.)           continue     // old ottagono cut
00291     if ((xi*xi+yi*yi)<215.)               continue;    // ottagono cut
00292     if (fabs(xi)>116. || fabs(yi)>116.) continue; 
00293     if (fabs(xi)+fabs(yi) > 164.)       continue; 
00294     if (fabs(xi)>63.2 && fabs(yi)>84.7) continue; 
00295     if (fabs(xi)>52.2 && fabs(yi)>84.7) continue; 
00296 
00297 
00298     ngood++;
00299     egood[ngood]=egx;
00300     xgood[ngood]=xi;
00301     ygood[ngood]=yi;
00302     xcog+=egx*xi;
00303     ycog+=egx*yi;
00304     egamtot+=egx;
00305     idpr[ngood]=lkry->M_Hits[i].idm%100;
00306 
00307   }
00308   // cut on gammas on the base of fit type...
00309   if( ngood!=nfit-1)      {getta_gg++;return -2;}
00310   // energy cut
00311   if(egamtot< 60.||egamtot>180.){getta_en++; return -5;}  // giudici cut 2007
00312 
00313   xcog/=egamtot; ycog/=egamtot;
00314   cog=sqrt(xcog*xcog+ycog*ycog);
00315 // cog=(fabs(xcog)+fabs(ycog))/2.;
00316   // cut on cog...for all tipo.
00317   if(tipo>5 && tipo!=21)
00318   {if(cog > 100.){ getta_cog++; return -7;}}
00319   else   if(cog > 10.0 ){ getta_cog++; return -6;}
00320 
00321 
00322 
00323   //Vertex.  Distance from the calorimeter and dij,mij
00324   if((dist=Distvtx())<0.0) {getta_gf++;return -3;}
00325 
00326   zeta=lkry->Get_Cface().z-dist;
00327   if(Debugon==1)
00328   {
00329     Gout<<"\n Ana_1: Ev "<<evento_.Gen.Event<<" mis="<<mishit<<" Ek="
00330     <<egamtot<<" cog="<<cog<<" zv="<<zeta<<std::endl;
00331   }
00332 
00333   //  time life cut from aks for Kl
00334   if(tipo==1||tipo==2 )
00335   {
00336     static double aks=607.4; // posizione della coincidenza
00337     double volo=zeta-aks;
00338    
00339     
00340    
00341     double eta =sqrt(egamtot*egamtot-msqAvo)/msAvo;
00342     cvita=volo/(eta*2.676); // in ks time_life
00343     //attenzione taglio sbagliato   Corretto 4.5
00344     if(cvita<-2.|| cvita>10.) {getta_tau++;return -7;}
00345     if(cvita>(0.8+0.06*egamtot) ){getta_tau++;return -7;}
00346 
00347     peso= exp( -cvita +volo/(eta*1551.0));
00348   }
00349 
00350 
00351 
00352   Ddistq();  // define errors and all the derivatives
00353 
00354 
00355   pair[0]= pair[1]= pair[2]=0;
00356 
00357   // choice of the best mass fit
00358   int stato=MassFit();
00359 
00360   if(stato==1) count_wnt++;
00361 
00362   else getta_fit++;
00363 
00364   return stato;
00365 }
00366 //----------------------------------------------------------
00367 int AnaK4g::MassFit()
00368 {
00369   int  err=-10;  //set fit error level to -10...
00370 //  chisq=200.01;         // nota ?????????
00371   chisq=100.01;         // nota ?????????
00372   //    if(mishit!=4) return err;
00373   g0=0;g1=1;g2=2;g3=3;
00374   if(MassChiq()==1) err=1;
00375   g0=0;g1=2;g2=1;g3=3;
00376   if(MassChiq()==1) err=1;
00377   g0=0;g1=3;g2=1;g3=2;
00378   if(MassChiq()==1) err=1;
00379   return err;
00380 }
00381 
00382 
00383 //------------------------------------------------
00384 int AnaK4g::MassChiq()
00385 {
00386   int err=-1;
00387   //---------------------------------------
00388   // masses and chisq  for each permutation...
00389   //---------------nota on index ...
00390   //   see procedure  kappa()
00391   //--------------------------------
00392 
00393 
00394   //  masse g0,g1 - g2,g3 - g4,g5
00395 
00396 
00397   double ma,mb,chiq;
00398   double dm,sm;
00399   int k01,k23;
00400   k01=kappa(g0,g1);
00401   k23=kappa(g2,g3);
00402   ma=mij[k01]; mb=mij[k23];
00403   Simq(k01,k23);
00404   dm=(ma-mb); sm=(ma+mb-twopi0mass);
00405 
00406   chiq=(dm*dm)/diffq + (sm*sm)/dsumq;
00407 
00408   // unal chiq
00409 
00410   // Gout<<"\n Ev %10ld Chi %10.3lf pair %4d %4d  %10.3lf %10.3lf ";
00411   //  if(Debugon==1)Gout<<"\n Ev %10ld Chi %10.3lf pair %4d %4d  %10.3lf %10.3lf ",
00412   //  Event,chiq,idpr[g0]+100*idpr[g1],idpr[g2]+100*idpr[g3],
00413   //           ma,mb);
00414 
00415   if(chiq<chisq)
00416   {
00417     mgg[0]=ma; mgg[1]=mb;chisq=chiq;
00418     pair[0]=idpr[g0]+100*idpr[g1];
00419     pair[1]=idpr[g2]+100*idpr[g3];
00420     dif1=dm/sqrt(diffq); dif2=sm/sqrt(dsumq);
00421     if(Debugon==1&&fabs(ma-pi0mass)<0.05)
00422       Gout<<"\nEV "<<evento_.Gen.Event<<" m:"<< sm<<" "<< dm<<" df1="
00423       << dif1<<" df2="<< dif2<<" df1/df2"<<dif1/dif2;
00424     nd=2;
00425     err=1;
00426   }
00427   return err;
00428 }
 All Classes Namespaces Files Functions Variables