FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_uti62/clusgmp.cpp

00001 /***************************************************************************
00002  *   Questa File e di test
00003  ***************************************************************************/
00004 
00005 #include "parm.h"
00006 #include "apparato.h"
00007 #include "evento.h"
00008 #include "clusgmp.h"
00009 #include "gmatrix.h"
00010 
00011 
00012 using namespace GmpConst;
00013 using namespace std;
00014 
00016 // CONSTRUCTOR //
00018 
00019 ClusterStraw::ClusterStraw ( DevStraw *stwfirst )
00020 {
00021 
00022     Pij.Set_Size(3,3);
00023     Pjx.Set_Size(3,3);
00024     Pjy.Set_Size(3,3);
00025     Pju.Set_Size(3,3);
00026     Pjv.Set_Size(3,3);        ;
00027 
00028 
00029     // Reset some variables
00030     nclust=-1;
00031     nx=ny=nu=nv=0;
00032     ufl=vfl=xfl=yfl=0;
00033 
00034 // chicut:  test per la bontà del fit a quattro fili e a tre fili. ( a due chiq è nullo per definizione.)
00035 // la distanza media è d= sqrt (chicut/n) dove n= 3 o 4;
00036     chicut=0.8;
00037 
00038     // stwfirst is the first plan of the chamber.
00039     stwu =  stwfirst;
00040     stwv =  stwu->nextstraw;
00041     stwx =  stwv->nextstraw;
00042     stwy =  stwx->nextstraw;
00043     zy = stwy->Get_Cface().z;
00044     zx = stwx->Get_Cface().z;
00045     zv = stwv->Get_Cface().z;
00046     zu = stwu->Get_Cface().z;
00047 
00048 
00049     // Some output
00050 //   Gout<<"\n  ClusterStraw for "<<stwu->Get_Nome() <<" done. ";
00051 //   Gout<<"\n Piani z "<<  zu  <<" "<<  zv  <<" "<< zx  <<" "<<zy;
00052 
00053 // calcolo i proiettori verticali degli assi:  ( Pj= I -|u><u|)
00054 
00055 
00056 
00057     gmatrix Unita(3,1.);
00058     gvet verso_cw;
00059     verso_cw.setvn(0.,1.,0.);  //filo nel lab lungo y
00060     verso_cw>>Pjx;
00061     Pjx=Unita-Pjx;
00062     verso_cw.setvn(1.,0.,0.);  //filo nel lab lungo x
00063     verso_cw>>Pjy;
00064     Pjy=Unita-Pjy;
00065     verso_cw.setvn(SINCOS45,-SINCOS45, 0.);
00066     verso_cw>>Pju;
00067     Pju=Unita-Pju;
00068     verso_cw.setvn(SINCOS45,SINCOS45, 0.);
00069     verso_cw>>Pjv;
00070     Pjv=Unita-Pjv;
00071     /*
00072         Pjx.Print("Pijx");
00073         Pjy.Print("Pijy");
00074         Pju.Print("Piju");
00075         Pjv.Print("Pijv");*/
00076 
00077 }
00078 
00079 
00081 // CONSTRUCT CLUSTERS                                        //
00082 //                                                           //
00083 // The mskcode gives the multiplicity for each value of mask //
00084 // Mask values 0000,0001,0010,0011.... ( da 0 a 15)          //
00086 
00087 // Proiettori degli assi dei 4 piani.
00088 
00089 int ClusterStraw::Get_Cluster()
00090 {
00091     nclust=-1;
00092     single_plans=0;
00093     ncls=0;
00094     static int codemask[16]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
00095     static int coppmask[16]={0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0};
00096     static int LowPlan=0; // attenzione la loop sui piani parte da LowPlan+1 up to maxplan;
00097 
00098     int xflag[30],yflag[30],uflag[30],vflag[30];     // flags to kill the used wirecoord.
00099     for (int i=0;i<30;i++)xflag[i]=yflag[i]=uflag[i]=vflag[i]=1;// flags set to ok
00100 
00101     // Store number of hits per plane and the maximun active number of planes
00102     int maxplan=0;
00103     nx=ny=nu=nv=0;
00104 //    if ( (nx = stwx->mhit)>0) maxplan++;
00105 //    if ( (ny = stwy->mhit)>0) maxplan++;
00106 //    if ( (nu = stwu->mhit)>0) maxplan++;
00107 //    if ( (nv = stwv->mhit)>0) maxplan++;
00108 
00109 
00110     if ( (nx = stwx->nwire)>0) maxplan++;
00111     if ( (ny = stwy->nwire)>0) maxplan++;
00112     if ( (nu = stwu->nwire)>0) maxplan++;
00113     if ( (nv = stwv->nwire)>0) maxplan++;
00114 
00115 
00116 // main loop
00117 // prima si analizzano le associazioni a 4 viste, poi a tre ed infine a due
00118 
00119 
00120 
00121     if ( maxplan<1)  return 0;  // not enough views?  Un
00122 
00123     gvet Xcls;
00124     double chiq=0.;
00125     int Nplsvis=0;
00126     int ix,iy,iu,iv;
00127     int ixok,iyok,iuok,ivok;
00128     int id_x,id_y,id_u,id_v;
00129 
00130     id_x=id_y=id_u=id_v=0;
00131     ixok=iyok=iuok=ivok=0;
00132 
00133     for (int VisAcc=maxplan; VisAcc>LowPlan;VisAcc--)
00134     {
00135         int Istart=0;
00136         if (VisAcc<4)Istart=-1;
00137 
00138         for (iu= Istart;iu<nu;iu++)
00139         {
00140             iuok=0;
00141             id_u=0;
00142             if (iu>-1&&uflag[iu]>-1) {
00143                 uwc.setvt(stwu->Wirecoor[iu],0.,0.,stwu->Wiredtim[iu]); 
00144                 ufl=uwc.x;
00145                                                                 udt=uwc.t;
00146                 uwc=stwu->Devc2Lab(uwc);
00147                 iuok=1;// primo piano
00148                 id_u=stwu->M_Hits[iu].id;
00149             }
00150             else      uwc.Reset();
00151 
00152             for (iv=Istart;iv<nv;iv++)
00153             {
00154                 ivok=0;
00155                 id_v=0;
00156                 if (iv>-1 && vflag[iv]>-1) {
00157                     vwc.setvt(stwv->Wirecoor[iv],0.,0.,stwv->Wiredtim[iv]);     
00158                     vfl=vwc.x;
00159                                                                                 vdt=vwc.t;
00160                     vwc=stwv->Devc2Lab(vwc);
00161                     ivok=2;  // secondo piano
00162                     id_v=stwv->M_Hits[iv].id;
00163                 }
00164                 else      vwc.Reset();
00165 
00166                 for (ix= Istart;ix<nx;ix++)
00167                 {
00168                     ixok=0;
00169                     id_x=0;
00170                     if (ix>-1 && xflag[ix]>-1) {
00171                         xwc.setvt(stwx->Wirecoor[ix],0.,0.,stwx->Wiredtim[ix]); 
00172                         xfl=xwc.x;
00173                                                                                                 xdt = xwc.t;
00174                         xwc=stwx->Devc2Lab(xwc);
00175                         ixok=4; // terzo piano  ok
00176                         id_x=stwx->M_Hits[ix].id;
00177                     }
00178                     else      xwc.Reset();
00179                     for (iy= Istart;iy<ny;iy++)
00180                     {
00181                         iyok=0;
00182                         id_y=0;
00183                         if (iy>-1 && yflag[iy]>-1) {
00184                             ywc.setvt(stwy->Wirecoor[iy],0.,0.,stwy->Wiredtim[iy]);
00185                             yfl=ywc.x;
00186                                                                                                                 ydt=ywc.t;
00187                             ywc=stwy->Devc2Lab(ywc);
00188                             iyok=8;     // quarto piano ok
00189                             id_y=stwy->M_Hits[iy].id;
00190                         }
00191                         else      ywc.Reset();
00192 
00193 // end for ==============
00194 
00195                         mask=iuok+ivok+ixok+iyok;
00196                         Nplsvis=codemask[mask];      // numero di piani visti
00197                         if (Nplsvis!=VisAcc)  continue; // no  enough active planes
00198 
00199 // first special simple  test for cluster with only tho planes
00200 // we accept only the couple u-x, u-y, v-x, v-y or mask = (0101,1001,0110,1010)=(5,9,6,10)
00201 
00202                         if (Nplsvis==2) if (coppmask[mask]==0) continue;
00203 
00204 
00205 // reset variables
00206                         Xcls.Reset();
00207                         double Filo=0.;
00208 
00209 
00210                         if (VisAcc==1)  // only one plan is found active,
00211                         {
00212                             // special test for cluster with only one plan. It gives back the co0rdinate Xcls reported at Y=0,
00213                             if ( Filtro_1(Xcls,Filo)<0) continue; //skip if not ok;
00214                             chiq =-0.2;  // set to -0.2 to flag the cluster with only one plan
00215                             //                         Xcls.print("One_X");Gout<<" Ev "<< Eventi_Fatti;
00216                             single_plans++;
00217 
00218                         }
00219 
00220 //=================  Calcolo del Punto Cluster con 2,3,4 piani =================
00221                         else if (VisAcc>1)
00222                         {
00223                             chiq =0.0;
00224                             gvet Noto;
00225                             Pij.Reset();;
00226                             //                      Noto.Reset();;
00227 
00228 // calcolo della matrice dei coefficienti e il termine noto;
00229                             if (iyok>0) {
00230                                 Pij+=Pjy;
00231                                 Noto+=Pjy%ywc;
00232                             }
00233                             if (ixok>0) {
00234                                 Pij+=Pjx;
00235                                 Noto+=Pjx%xwc;
00236                             }
00237                             if (ivok>0) {
00238                                 Pij+=Pjv;
00239                                 Noto+=Pjv%vwc;
00240                             }
00241                             if (iuok>0) {
00242                                 Pij+=Pju;
00243                                 Noto+=Pju%uwc;
00244                             }
00245 
00246                             Pij.Det();
00247 
00248 
00249 //                     Noto.Print("Noto");
00250 //                     Pij.Print("Pij");
00251 
00252 // calcolo le coord. del cluster
00253                             Xcls=(!Pij)%Noto;
00254 
00255 // second  special test for cluster with only tho or three  planes
00256 // the cluster found has to be in the black central region of the other not hit  plans...
00257 // for two plans we accept only the couple u-x, u-y, v-x, v-y or mask = (0101,1001,0110,1010)=(5,9,6,10)
00258 
00259 
00260                             if (Nplsvis<4) if ( Filtro_23(Xcls)<0) continue; //skip if not ok;
00261 
00262 
00263 // calcolo del chiq ( somme quadrate delle distanze del punto trovato  dai fili sul piano xy)
00264                             //per due piani chiq=0.0 per definizione.
00265                             if (Nplsvis>2) {
00266                                 if (iuok>0)  chiq+=(Pju%(uwc-Xcls)).XYNorma();
00267                                 if (ivok>0)  chiq+=(Pjv%(vwc-Xcls)).XYNorma();
00268                                 if (ixok>0)  chiq+=(Pjx%(xwc-Xcls)).XYNorma();
00269                                 if (iyok>0)  chiq+=(Pjy%(ywc-Xcls)).XYNorma();
00270 
00271                             }
00272 
00273                         }
00274 //  attenzione end codice per 4-2 piani attivi
00275 //=============================================
00276                         if (Nplsvis==4) chiq/=2.;
00277 
00278 // memorizzo il cluster trovato se chiq/<cut;
00279                         if (chiq<chicut)
00280                         {
00281                             nclust++;
00282                             Clus[nclust].nome=stwu->Get_Nome();
00283                              Clus[nclust].Centro=stwu->Get_Centro();                          
00284                             Clus[nclust].id = nclust;
00285                             Clus[nclust].mask = mask;
00286                             Clus[nclust].hitx = id_x;
00287                             Clus[nclust].hity = id_y;
00288                             Clus[nclust].hitu = id_u;
00289                             Clus[nclust].hitv = id_v;
00290                             Clus[nclust].planes =Nplsvis;
00291                             if (ixok>0) {
00292                                 Clus[nclust].Xfil = xfl;
00293                                                                                                                                 Clus[nclust].Xdtim = xdt;
00294                                 xflag[ix]=-1;
00295                                 ixok=0;
00296                                 id_x=0;
00297                             }
00298                             else  Clus[nclust].Xfil = 0.;
00299                             if (iyok>0) {
00300                                 Clus[nclust].Yfil = yfl;
00301                                                                                                                          Clus[nclust].Ydtim = ydt;
00302                                 yflag[iy]=-1;
00303                                 iyok=0;
00304                                 id_y=0;
00305                             }
00306                             else  Clus[nclust].Yfil = 0.;
00307                             if (iuok>0) {
00308                                 Clus[nclust].Ufil = ufl;
00309                                                                                                                                 Clus[nclust].Udtim = udt;
00310                                 uflag[iu]=-1;
00311                                 iuok=0;
00312                                 id_u=0;
00313                             }
00314                             else  Clus[nclust].Ufil = 0.;
00315                             if (ivok>0) {
00316                                 Clus[nclust].Vfil = vfl;
00317                                                                                                                                 Clus[nclust].Vdtim = vdt;
00318                                 vflag[iv]=-1;
00319                                 ivok=0;
00320                                 id_v=0;
00321                             }
00322                             else  Clus[nclust].Vfil = 0.;
00323 
00324                             Clus[nclust].chiq = chiq;
00325                             Clus[nclust].Xcls=Xcls;
00326                             Clus[nclust].Filo=Filo; //for one plan
00327                              }
00328  
00329                     }
00330 
00331                 }
00332             }
00333         }
00334     }
00335 
00336 
00337     if (nclust>-1)Cluster2Root();
00338     
00339     
00340     
00341 //     if (nclust>-1)
00342 //     {
00343 //       if(Clus[0].mask==15)
00344 //       { gvet xpar,xxdv;
00345 //            Gout<<"\n Nome "<<stwu->Get_Nome()<<" Centro "<<stwu->Get_Centro().x;
00346 //            xxdv=Clus[0].Xcls;
00347 //            xxdv.print("Xcls");
00348 //            xpar=stwv->Lab2cDev(xxdv);
00349 //            xpar.print("xv");
00350 //             
00351 //              Gout<< " fili  " << Clus[0].Ufil<<" "<<Clus[0].Vfil<<" "<<Clus[0].Xfil<<" "<<Clus[0].Yfil;
00352 //           
00353 //           Gout<<"\n filo x " << Clus[0].Xfil+stwx->Get_Centro().x<<" "<<xxdv.x;
00354 //           Gout<<" filo y " << Clus[0].Yfil<<" "<<-xxdv.y;
00355 //   
00356 //           Gout<<" filo u " << Clus[0].Ufil+stwu->Get_Centro().x*SINCOS45<<" "<<xxdv.x*SINCOS45 +xxdv.y*SINCOS45;
00357 //           
00358 //           Gout<<" filo v " << Clus[0].Vfil+stwu->Get_Centro().x*SINCOS45<<" "<< xxdv.x*SINCOS45 -xxdv.y*SINCOS45 ;
00359 //     
00360 //         
00361 //       } }
00362 //       
00363 //       
00364 //     }
00365 //     if (zu>21000.)
00366 //     {
00367 //
00368 //       for (int i=0;i<nclust+1;i++)Clus[i].Cluster_Print ();
00369 //     }
00370 
00371     return  nclust;
00372 
00373 }
00374 //======  Cluster2Root()
00375 void ClusterStraw::Cluster2Root()
00376 {
00377 
00378     ncls=nclust+1;
00379     nwu=nu;
00380     nwv=nv;
00381     nwx=nx;
00382     nwy=ny;
00383 
00384     for (int in=0;in<nclust+1;in++)
00385     {
00386 
00387         hitu[in]=    Clus[in].hitu;
00388         hitv[in]=    Clus[in].hitv;
00389         hitx[in]=    Clus[in].hitx;
00390         hity[in]=    Clus[in].hity;
00391         maskera[in]= Clus[in].mask;
00392         planes[in]=  Clus[in].planes;
00393         Ufil[in]=  Clus[in].Ufil;
00394         Vfil[in]=  Clus[in].Vfil;
00395         Xfil[in]=  Clus[in].Xfil;
00396         Yfil[in]=  Clus[in].Yfil;
00397                         Udtim[in]=  Clus[in].Udtim;
00398         Vdtim[in]=  Clus[in].Vdtim;
00399         Xdtim[in]=  Clus[in].Xdtim;
00400         Ydtim[in]=  Clus[in].Ydtim;
00401         X[in]=  Clus[in].Xcls.x;
00402         Y[in]=  Clus[in].Xcls.y;
00403         Z[in]=  Clus[in].Xcls.z;
00404         chiq[in]=  Clus[in].chiq;
00405     }
00406 
00407 }
00408 
00409 //=======================================
00410 
00411 
00412 
00413 void HitClus::Cluster_Print()
00414 {
00415 
00416     Gout.setf ( ios::right,ios::adjustfield );
00417     Gout<<std::setfill ( ' ' );
00418     Gout<<std::setprecision ( 3 ) <<fixed;
00419     Gout<<"\n Ev-clus "<<setw ( 6 ) <<evento_.Gen.Event<<" "
00420     <<nome
00421     <<" Id "<<setw ( 2 ) <<id
00422     <<" Msk "<<setw ( 8 ) <<mask
00423     << " hts ["<<setw ( 6 ) <<hitu
00424     <<" "<<setw ( 6 ) <<hitv
00425     <<" "<<setw ( 6 ) <<hitx
00426     <<" "<<setw ( 6 ) <<hity
00427     <<"] W "<<setw ( 8 )<<Ufil
00428     <<" "<<setw ( 8 ) <<Vfil
00429     <<" "<<setw ( 8 ) <<Xfil
00430     <<" "<<setw ( 8 ) <<Yfil;
00431     Xcls.print("X");
00432     Gout<<" Chiq "<<setw ( 8 ) <<chiq;
00433 
00434     Gout.setf ( ios::floatfield );
00435 
00436 
00437 }
00438 //=======================================
00439 int  ClusterStraw::Filtro_23(gvet Xcls)
00440 {
00441     static int Central_Gap= 13.5/2.;  // attenzione questo parametro genera le righe nel plot dei xy dei cluster....(stringere un po')
00442     // attenzione vale solo per 2 o 3 camere attive
00443     static int short msk1=1, msk2=2, msk3=4, msk4=8;
00444     unsigned short maskera=mask;
00445 
00446     gvet Xcldv;
00447     if ((maskera&msk1)==0)   // camera u non c'è
00448     {
00449         Xcldv=stwu->Lab2cDev(Xcls);  // passo al rif interno al dev
00450         if ( abs(Xcldv.x)>Central_Gap) return -1; // se la x è fuori buco salto...
00451     }
00452     if ((maskera&msk2)==0)   // camera v non c'è
00453     {
00454         Xcldv=stwv->Lab2cDev(Xcls);
00455         if ( abs(Xcldv.x)>Central_Gap) return -1;
00456     }
00457     if ((maskera&msk3)==0)   // camera x non c'è
00458     {
00459         Xcldv=stwx->Lab2cDev(Xcls);
00460         if ( abs(Xcldv.x)>Central_Gap) return -1;
00461     }
00462     if ((maskera&msk4)==0)   // camera y non c'è
00463     {
00464         Xcldv=stwy->Lab2cDev(Xcls);
00465         if ( abs(Xcldv.x)>Central_Gap) return -1;
00466     }
00467     return 1;
00468 }
00469 
00470 int  ClusterStraw::Filtro_1(gvet &X,double &Filo)
00471 {// filtro to test the "one plan" case: cut on wire max address
00472 // filtro solo valido per il caso di un solo piano colpito
00473 //restituisce la coordinata del punto nel lab come se nel dev avesse
00474 // coordinate( x=filo,  y=0)
00475     static int Maxwire_addr= 9.018;
00476     unsigned short maskera=mask;
00477     static int short msk1=1, msk2=2, msk3=4, msk4=8;
00478     DevStraw *pstw=0;
00479 
00480     if ((maskera&msk1)>0) {
00481         pstw=stwu;
00482         Filo=ufl;
00483     }
00484     else if ((maskera&msk2)>0) {
00485         pstw=stwv;
00486         Filo=vfl;
00487     }
00488     else if ((maskera&msk3)>0) {
00489         pstw=stwx;
00490         Filo=xfl;
00491     }
00492     else if ((maskera&msk4)>0) {
00493         pstw=stwy;
00494         Filo=yfl;
00495     }
00496     else return -1; // se c'è un errore.....
00497 
00498     if (abs(Filo)>Maxwire_addr) return -1; // indirizzo fuori zona....
00499     X.setvn(Filo,0.,0.);
00500     X=pstw->Devc2Lab(X);
00501     X.z=pstw->Get_Centro().z;
00502 
00503     return 1;
00504 
00505 }
00506 
00507 
00508 
00509 
00510 
00511 
00512 //=======================================
00513 void  ClusterStraw::Ordina()
00514 {
00515     // ordina i cluster  in dist decrescente...
00516     double chiq,chiqb;
00517 
00518     if ( nclust>0 ) // ordina i cluster
00519     {
00520         for ( int i=0;i<nclust;i++ )
00521         {
00522             chiq=Clus[i].chiq;
00523             for ( int j=i+1;j<nclust;j++ )
00524             {
00525                 if ( ( chiqb=Clus[j].chiq ) <chiq )
00526                 {
00527                     ClusSave=Clus[i];
00528                     Clus[i]=Clus[j];
00529                     Clus[j]=ClusSave;
00530                     chiq=chiqb;
00531                 }
00532             }
00533         }
00534     }
00535 }
00536 
 All Classes Namespaces Files Functions Variables