FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_dev/device.cpp

00001 /***************************************************************************
00002                           device.cpp  -  description
00003                              -------------------
00004     begin                : Sat May 26 2001
00005     copyright            : (C) 2001 by Giuseppe Pierazzini
00006     email                : peppe@unipi.it
00007   ***************************************************************************
00008   *                                                                         *
00009   *   NA48  simulation program.                                             *
00010   *                                                                         *
00011   ***************************************************************************/
00012 
00013 
00014 #define CEPSI 1.0e-6
00015 #include "flyoh.h"
00016 
00017 //        Tirrenia   GmP 4.09.
00018 #include <ctype.h>
00019 
00020 #define ESTERNO  1
00021 #define INTERNO  0
00022 #define INBUCO   -1
00023 #define EPSR     1.0E-200
00024 
00025 using namespace GmpConst;
00026 using namespace std;
00027 static Device *last_device = 0;
00028 static int tot_device = 0;
00029 double sinPhi=0.0, cosPhi=1.0;
00030 void Scrivi_Dati ( int );
00034 // classe Base
00035 Device::Device()
00036 {
00037     working_buffer=MemoryBuffer;
00038     Make_working_buffer ( working_buffer );
00039     Make_measur_buffer ( working_buffer );
00040     // create e new device
00041     tot_device++;
00042     idev = tot_device;
00043     devtype=TypDevice;  //=0
00044     if ( last_device== 0 ) Apparato=this;
00045     else             last_device->next = this;   // linking
00046     up=last_device;
00047     last_device = this;
00048     this->next = 0;   // end linking
00049 
00050     // default orientation and zero setting
00051     Nx.setvn ( 1.,0.,0. );
00052     Ny.setvn ( 0.,1.,0. );
00053     Nz.setvn ( 0.,0.,1. );
00054     Tot_seen=0;
00055     for ( int i=0;i<40;i++ ) Part_hit[i]=0;
00056     nhit =ghcir= gnhit=nvede = -1;
00057     ghit_last=mhit=0;
00058 
00059     nowpos=prevpos=6;
00060     wrout=accedi=escludi=rivela=Zint=Zbuc=0;
00061     registra=1;
00062     campo=-1;
00063     reckik=-1. ; // reconstruction Kik non defined
00064     mattint="";
00065     mattbuc="";
00066     maxBrems=maxPair=0;    //if >1 enable bremsstrhalung  and pair production
00067     Brem_done=Pair_done=0;
00068     eDev=t_dead_mem =time_now=Ro =Dedx =0.0;
00069     Roint=Robuc=Dedxint=Dedxbuc=0.0;
00070     Aint=Abuc=lradi = lradb=lrad= 0.0;
00071     fun=Nodef;       // set default function at None...
00072 
00073 // legge i dati di definizione del dev
00074     Leggi_schede_dev();
00075 }
00076 
00077 void Device::Leggi_schede_dev()
00078 {
00079     // legge  le schede di definizione...
00080     string stringline,label,label2;
00081     char line[128];
00082     double ax,ay,az;
00083     int centro_dato= 0;
00084 
00085     Cardcur->getline ( line, 128 );
00086     while ( !Cardcur->eof() )
00087     {
00088 
00089         stringline=line;
00090         stringstream scheda;
00091         scheda<<line;
00092         scheda>>label;
00093 
00094         if ( Dbginput==1 )
00095         {
00096             Gout<<"\n Device label: "<<label<<"  Linea:"<<line;
00097         }
00098 
00099         if ( stringline.size()      <1  ||
00100                 label.find ( "**" )  ==0  ||
00101                 label.find ( "\\\\" ) ==0  ||
00102                 label.find ( "//" )  ==0 )
00103         {
00104             Cardcur->getline ( line, 128 );
00105             continue;
00106         } //line empty or comment ...read next line
00107 
00108 
00109         if ( label.find ( "device" ) == 0 )
00110         {
00111             Gout<<"\n Device card out of sequence !!!\n "<<endl;
00112             cout<<"\n Device card out of sequence !!!\n "<<endl;
00113             exit ( 0 );
00114         }
00115         else if ( label.find ( "nome" ) == 0 )
00116         {
00117             scheda>>nome>>nickname;
00118         }
00119 
00120         else if ( label.find ( "flags" ) == 0 ||
00121                   label.find ( "fun" ) == 0 )
00122         {
00123             label="";
00124             scheda>>label;
00125             if ( label.find ( None ) == 0 )  fun = None;
00126             else if ( label.find ( Trig ) == 0 )   fun = Trig;
00127             else if ( label.find ( Veto ) == 0 )  fun = Veto;
00128             else if ( label.find ( Magn ) == 0 )  fun = Magn;
00129             else if ( label.find ( Trigh ) == 0 )  fun = Trigh;
00130             else if ( label.find ( Dead ) == 0 )   fun = Dead;
00131             else if ( label.find ( Dump ) == 0 )  fun = Dump;
00132             else if ( label.find ( Gasint ) == 0 ) fun =  Gasint;
00133             else if ( label.find ( Bersaglio ) == 0 ) fun =  Bersaglio;
00134             else
00135             {
00136                 Gout<<"\n Device "<<nome<< "... flags error:  "<<label;
00137                 exit ( 0 );
00138             }
00139         }
00140         else if ( label.find ( "detect" ) == 0 )
00141         {
00142             if ( nvede< 20 )
00143             {
00144                 label="";
00145                 scheda>>label;
00146                 nvede++;
00147                 const char *ptm;
00148                 if ( ( ptm = Matter->Ptbsdat ( label.c_str() ) ) != 0 )
00149                 {
00150                     vede[nvede] = ptm;
00151                 }
00152                 else if ( label.find ( All ) == 0 )  vede[nvede] = All;
00153                 else if ( label.find ( Char ) == 0 ) vede[nvede] = Char;
00154                 else if ( label.find ( Neut ) == 0 ) vede[nvede] = Neut;
00155                 else
00156                 {
00157                     Gout<<"\n Device parameter error ==> "<< label<<endl;
00158                     cout<<"\n Device parameter error ==> "<< label<<endl;
00159                     exit ( 0 );
00160                 }
00161                 assorb[nvede]=0;
00162                 label="";
00163                 scheda>>label;
00164                 if ( label.size() !=0 )
00165                 {
00166                     if ( label.find ( "enevd" ) ==0 ) assorb[nvede]=1;
00167                     else if ( label.find ( "dump" ) ==0 ) assorb[nvede]=2; // dump ma registra
00168                     else if ( label.find ( "noreg" ) ==0 ) assorb[nvede]=3; // non registra
00169                     else if ( label.find ( "cdump" ) ==0 ) assorb[nvede]=4; // dump ma non registra
00170                 }
00171             }
00172         }
00173         else if ( label.find ( "esclu" ) == 0 )
00174         {
00175             escludi=1;
00176             accedi=100;
00177         }
00178         else if ( label.find ( "writeout" ) == 0 ) wrout=1;
00179 
00180         else if ( label.find ( "buffer" ) == 0 ) // working buffer: standard 30
00181         {
00182             scheda>>working_buffer;
00183 
00184         }
00185 
00186 
00187 
00188         else if ( label.find ( "centro" ) == 0 )
00189         {
00190             if ( centro_dato!=0 )
00191             {
00192                 Gout<<"\n  Error: centro duplicato! in dev "<< idev<<endl;
00193                 exit ( 1 );
00194             }
00195             centro_dato=1;
00196             scheda>>ax>>ay>>az;
00197             Centro.setvn ( ax,ay,az );
00198             Centro=Centro-Lab_Zero;
00199             Centro.Norma();
00200         }
00201         else if ( label.find ( "cface" ) == 0 ) // coord.centro superficie di ingresso
00202         {
00203             if ( centro_dato!=0 )
00204             {
00205                 Gout<<"\n  Error: centro duplicato! in dev "<< idev<<endl;
00206                 exit ( 1 );
00207             }
00208             centro_dato=2;
00209             scheda>>ax>>ay>>az;
00210             Cface.setvn ( ax,ay,az );
00211 
00212         }
00213         else if ( label.find ( "centrin" ) == 0 )   // centro del buco...coordinate interne
00214         {
00215             scheda>>ax>>ay>>az;
00216             Centrin.setvn ( ax,ay,az );
00217         }
00218         else if ( label.find ( "versx" ) == 0 )
00219         {
00220             scheda>>ax>>ay>>az;
00221             Nx.setvn ( ax,ay,az );
00222         }
00223         else if ( label.find ( "versy" ) == 0 )
00224         {
00225             scheda>>ax>>ay>>az;
00226             Ny.setvn ( ax,ay,az );
00227         }
00228         else if ( label.find ( "versz" ) == 0 )
00229         {
00230             scheda>>ax>>ay>>az;
00231             Nz.setvn ( ax,ay,az );
00232         }
00233         else if ( label.find ( "rotap" ) == 0 )  // START RUGGIERO
00234         {
00235             double Phi;
00236             scheda>>Phi;
00237             Phi*=PiGreco/180.;
00238             sinPhi = sin ( Phi );
00239             cosPhi = cos ( Phi );
00240 // la rotazione è attorno all'asse zeta del laboratorio...
00241 // ridefinisco i versori del device rispetto al sistema del lab.
00242             Nx.setvn ( cosPhi, sinPhi,0.0 );
00243             Ny.setvn ( -sinPhi, cosPhi,0.0 );
00244             Nz.setvn ( 0.0,    0.0,   1.0 );
00245         }                                          // END RUGGIERO
00246 
00247         else if ( label.find ( "sizein" ) == 0 ||
00248                   label.find ( "rin" ) == 0 )
00249         {
00250             scheda>>ax>>ay>>az;
00251             Lin.setvn ( ax,ay,az );
00252         }
00253 
00254         else if ( label.find ( "totin" ) == 0 ||
00255                   label.find ( "dtin" ) == 0 )
00256         {
00257             scheda>>ax>>ay>>az;
00258             Lin.setvn ( ax*.5, ay*.5, az*.5 );
00259         }
00260 
00261         else if ( label.find ( "sizeout" ) == 0 ||
00262                   label.find ( "rout" ) == 0 )
00263         {
00264             scheda>>ax>>ay>>az;
00265             Lout.setvn ( ax,ay,az );
00266             Rqsize=Lout.normaq*1.1;
00267         }
00268         else if ( label.find ( "totout" ) == 0 ||
00269                   label.find ( "dtout" ) == 0 )
00270         {
00271             scheda>>ax>>ay>>az;
00272             Lout.setvn ( ax*.5,ay*.5,az*.5 );
00273             Rqsize=Lout.normaq*1.1;
00274         }
00275         else if ( label.find ( "opens" ) == 0 )
00276         {
00277             scheda>> OpenSector;
00278             OpenSector*= 0.017453293;
00279         }
00280         else if ( label.find ( "fortax" ) == 0 )
00281             // per definire dimensioni semiapertura del foro finale  interno dei tax
00282         {
00283             scheda>>ax>>ay>>az;
00284             Fortax.setvn ( ax,ay,az );
00285         }
00286 
00287         else if ( label.find ( "field" ) == 0 )
00288         {
00289             scheda>>ax>>ay>>az;
00290             Field.setvn ( ax,ay,az );
00291             Bref=ax;
00292             Field_sav=Field;
00293         }
00294         else if ( label.find ( "vfiel" ) == 0 )
00295         {
00296             //      Bref e posizione valore di riferimento del campo
00297             //      per il focussing quadrupoli.....
00298             scheda>>Bref ;
00299             scheda>>Dbref;
00300             Field.setvn ( Bref,0.0,0.0 );
00301             Field_sav=Field;
00302         }
00303         else if ( label.find ( "magki" ) == 0 )
00304             scheda>>reckik;
00305         else if ( label.find ( "mem" ) == 0 )
00306         {
00307             scheda>> t_dead_mem ;
00308             if ( Tpipe<t_dead_mem ) Tpipe=t_dead_mem;
00309         }
00310 
00311         else if ( label.find ( "registra" ) == 0 )
00312         {
00313             scheda>> label;
00314             if ( label=="no" ) registra=0;  //default=1;
00315         }
00316 
00317         else if ( label.find ( "materiali" ) == 0 )
00318         {
00319 
00320             scheda>>mattint>>mattbuc;
00321             Get_Materiali();
00322         }
00323         else if ( label.find ( "brems" ) == 0 ) scheda>>maxBrems;
00324         else if ( label.find ( "pair" ) == 0 ) scheda>>maxPair;
00325 
00326         //--------------------------------------------------
00327         //  the  following procedure is obsolate
00328         else if ( label.find ( "radi" ) == 0 )
00329         {
00330             Gout<<"\n In dev "<<nome
00331             <<"  \"radi\" too old ... to be subtituted by \"materiali\" card ...thanks " ;
00332         }
00333         else if ( label.find ( "dens" ) == 0 )
00334         {
00335             Gout<<"\n In dev "<<nome
00336             <<"  \"dens\" too old ... to be subtituted by \"materiali\" card ...thanks ";
00337         }
00338         //----------------------------------------------------
00339 
00340 
00341         //exit dev generation
00342         else if ( label.find ( "end" ) == 0 ||
00343                   label.find ( "done" ) == 0 )
00344         {
00345             if ( centro_dato==2 ) // calcolo il vero centro del dev
00346             {
00347                 Centro=Cface-Lab_Zero;
00348                 Centro[2]+=Lout[2];
00349                 Centro.Norma();
00350             }
00351             else if ( centro_dato==1 )
00352             {
00353                 Cface=Centro;
00354                 Cface[2]-=Lout[2];
00355                 Cface.Norma();
00356             }
00357             else
00358             {
00359                 Gout<<"\n Error: Missing centro in dev "<<idev<<endl;
00360                 exit ( 1 );
00361             }
00362 
00363             if ( escludi==1 ) wrout=0;
00364 
00365 // attenzione  aggiustamento memoria di lavoro se richieste dimensioni maggiori di 30 !!!!!!!
00366 // device buffers: local, circular, after dev simulation and measured buffer for root using.
00367 // standard dim=30
00368 
00369             Make_working_buffer ( working_buffer );
00370             Make_measur_buffer ( working_buffer );
00371 
00372 
00373             return;
00374         }
00375         //  next for debug.....
00376         else if ( label.find ( "stopr" ) == 0 )
00377         {
00378             Gout<<"\n Stop run by operator. "<<endl;
00379             cout<<"\n Stop run by operator. "<<endl;
00380             exit ( 0 );
00381         }
00382         Cardcur->getline ( line, 120 );
00383     }
00384 
00385 
00386 
00387 
00388 }
00389 //---------------------------------
00390 Device::~Device()
00391 {}
00392 //--------------------------------------------
00393 // making buffer procedures
00394 void  Device::Make_working_buffer ( int dim )
00395 {
00396     if ( dim>MemoryBuffer )
00397     {
00398         delete[] Hits;
00399         delete[] G_Hits;
00400         delete[] M_Hits;
00401         Gout<<"\n In device ** "<<nome <<" **  working_buffer adjusted to ==> "<<dim;
00402     }
00403 
00404     circular_buffer=dim;
00405     if ( Pipeline>0 )  circular_buffer=4*dim;
00406     Hits  = new Bufdev[dim];
00407     G_Hits= new Bufdev[circular_buffer];
00408     M_Hits= new Bufdev[dim];
00409 
00410 }
00411 void  Device::Make_measur_buffer ( int dim )
00412 {
00413 
00414 
00415 
00416     if ( dim>MemoryBuffer )
00417     {
00418 // nel primo dev non di delete.....
00419 //if(idev==2) Gout<<"\n old pointer  "<< index<<" "<< fdx[0]<<" "<<&index<<" "<< &fdx;
00420 
00421 
00422         delete[] index;
00423         delete[] mid;
00424         delete[] mdead;
00425         delete[] devstory;
00426         delete[] mxd;
00427         delete[] myd;
00428         delete[] mzd;
00429         delete[] mdd;
00430         delete[] me;
00431         delete[] mxl;
00432         delete[] myl;
00433         delete[] mzl;
00434         delete[] gpx;
00435         delete[] gpy;
00436         delete[] gpz;
00437         delete[] ge;
00438         delete[] dtemp;
00439         delete[] structinfo;
00440 
00441         Gout<<"\n In device ** "<<nome <<" **  measur_buffer adjusted to ==> "<<dim;
00442 
00443     }
00444 
00445     index=new int[dim];
00446     mid =new int[dim];
00447     mdead=new int[dim];
00448     devstory= new unsigned long long[dim];
00449     mxd=new float[dim];
00450     myd=new float[dim];
00451     mzd=new float[dim];
00452     mdd=new float[dim];
00453     me=new float[dim];
00454     mxl=new float[dim];
00455     myl=new float[dim];
00456     mzl=new float[dim];
00457     gpx=new float[dim];
00458     gpy=new float[dim];
00459     gpz=new float[dim];
00460     ge=new float[dim];
00461     dtemp=new double[dim];
00462     structinfo=new int[dim];
00463 
00464 
00465 }
00466 
00468 void Device::Reset_Pos()
00469 {
00470     // start from the tree top
00471     Device *pdev=Apparato;
00472     while ( pdev!=0 )
00473     {
00474         nowpos=prevpos=6;
00475         pdev=pdev->next;
00476     }
00477 }
00478 
00479 //***********************  R E S E T ****************************
00480 
00482 void Reset_Devices()
00483 {
00484 // attenzione dove si mette questo reset... per la relazine tempoarle
00485     // start from the tree top...
00486     Device *pdev=Apparato;
00487     while ( pdev!=0 )
00488     {
00489         pdev->Reset_Dev();
00490         pdev=pdev->next;
00491     }
00492 }
00494 void Device::Reset_Dev()
00495 {
00496 // attenzione dove si mette questo reset... si suppone all'inizio evento
00497 // quando si conosce il tempo di generazione del nouvo evento ....
00498 
00499     nowpos=prevpos=6;  //posizione non definita
00500     accedi=0;
00501     rivela=0;
00502     eDev=0.0;
00503     Brem_done=Pair_done=0;
00504     nhit=-1;
00505     mhit = 0;
00506 
00507     if ( Pipeline==0 )
00508     {
00509         gnhit = -1;  // hits generati
00510     }
00511 }
00512 
00513 //====================   s c r i v i   c o l p i  ================
00521 void  Device::ScrvColpi ( Particella *pr )
00522 {
00536 //  cout<<"\n Ev Scrv "<<Eventi_Fatti<< " dev "<<nome<< " pr "<<pr->nome<<" colpo "<<colpo<<" visto "<<visto;
00537 
00538     if ( nhit> ( working_buffer-2 ) ) //verifica la size del buffer!
00539     {
00540         Gout<<"\n Ev "<< Eventi_Fatti<<"  In dev "<<nome<<" too many particles "<< nhit<< "  get out! "<<endl;
00541         Scrivi_Dati ( 2 );
00542         flyoend();
00543         exit ( 0 );
00544     }
00545 
00546 
00547 // aggiorna il contatore di dev per le particelle che lo attraversano
00548     Part_hit[Idsee]++;
00549     Tot_seen++;
00550 
00551     pr->devhit=idev;  //memorizzo l'ultimo indice del dev colpito.
00552 
00553     // salva in formato codificato i devices colpiti dalla particell
00554     // il bit acceso corrisponde al device colpito
00555     // attenzione memorizza solo i primi 64 device.
00556     pr->Update_Devstory ( idev );
00557 
00558 
00559     if ( rivela>2 ) return;   // non registered
00560 // attenzione si evita anche  di registrare  gli hits per i dev che non sono esplicitamente
00561 // usati nella analisi successiva. registra=(0,1)==(no,si)
00562     if ( registra==0 ) return;
00563 
00564     nhit++;       // remember nhit starts from -1 that corrisponds to no  hits...
00565 
00566     Bufdev  *bf = &Hits[nhit];
00567     bf->Pr=             pr;
00568     bf->tempo=          evento_.Gen.tempo;
00569     bf->idead=          pr->Ifato;
00570     bf->devstory=       pr->devstory;
00571     bf->last_path=      pr->last_path;
00572     bf->pnome =         pr->nome;
00573     bf->id=             pr->id;
00574     bf->idm=            pr->idm;
00575     bf->Vers=           pr->Vers;
00576     bf->Xlab=           pr->X;
00577     bf->Xdev=           Lab2cDev ( pr->X );
00578     bf->Pdev=           pr->P;
00579     bf->structinfo= Get_Structinfo();
00580 
00581 //  ----------------------
00582     if ( rivela>0 ) bf->e_rivela=pr->P.e;
00583     else bf->e_rivela=0.0;   //it is done anyway if multiplescattering if required...
00584 
00585 //  ------------- pipeline test -------
00586     if ( Pipeline==0 ) return;
00587 
00588 // pipeline is on! copies the hits in the circular buffer
00589 
00590     gnhit++;       // hits index up to now...
00591     ghcir=gnhit%circular_buffer;  //attention... Circular buffer
00592     G_Hits[ghcir]=bf[0];
00593     G_Hits[ ( ghcir+1 ) %circular_buffer].tempo=-10;  //set to -10 next hit not yet arrived....
00594 
00595 //    Gout<<"\n Eve_gen "<<evento_.Gen.Event<<" dev "<<nome<< " hit "<<gnhit<<" "<<ghcir<<" tempo "<< G_Hits[ghcir].tempo
00596 //     <<" " << G_Hits[(ghcir+1)%circular_buffer].tempo;
00597     ;
00598 
00599 };
00600 
00601 
00602 
00607 void  Device::GetWindowHits ( double trigger_time )
00608 {
00609 
00610 
00611 
00612     double dtm, adtm;
00613     int pipe=0;
00614     nhit=-1;
00615     mhit=0;
00616 
00617 
00618     if ( gnhit<0 ) return;  // gnhit: total hit seen up to now memorized in the circular buffer
00619 
00620     double tmorto=t_dead_mem;  // get dead time of the device
00621     if ( tmorto>0.0 ) tmorto=t_dead_mem +0.001;
00622     else tmorto=0.001;   //if zero set to 0.001 ns
00623 
00624     int ghit=ghit_last; // get the last hit
00625     ghit_last=0;
00626 
00627 // Gout<<"\n In Dev " <<nome << " for  trig_time  " <<trigger_time;
00628 // cout<<"\n In Dev " <<nome << " for  trig_time  " <<trigger_time;
00629 
00630     int ih=0;
00631     while ( ih<circular_buffer )
00632     {
00633         ghit=ghit%circular_buffer;
00634         if ( G_Hits[ghit].tempo<-9. ) break; // test on last hit to break the loop...
00635         dtm = trigger_time -G_Hits[ghit].tempo;  // difference between trigger_time and hit_time...
00636         adtm=fabs ( dtm );
00637 
00638         if ( adtm<=tmorto )  //Test if the hit is inside the dead_time....
00639         {
00640             pipe=0;
00641             nhit++;
00642             if ( adtm>0.001 )
00643             {
00644                 pipe=1;
00645                 evento_.Gen.Pipev=1;
00646             }
00647             M_Hits[nhit]=G_Hits[ghit];   //copy from circular buffer into M_Hits...
00648             M_Hits[nhit].Pileup=pipe;
00649             if ( ghit_last==0 ) ghit_last=ghit;
00650 
00651         }
00652         else if ( dtm>0.0 ) ghit_last=ghit;
00653         else if ( dtm<0.0 ) break;
00654 
00655 //      Gout<<" Lasthit "<<setw(5)<<ghit_last<<"  pipe "<<pipe ;
00656 
00657         if ( nhit> ( working_buffer-2 ) )
00658         {
00659             Gout<<"\n Ev "<< evento_.Gen.Event<<"  Too many hits in dev " << nome<< "  see GetWindowHits()... exit" <<endl;
00660             exit ( 0 );
00661         }
00662         ghit++;
00663         ih++;
00664     }
00665     mhit=nhit+1;
00666     //   if(mhit>0)Gout<<"\n Ev "<< Eventi_Fatti<<"  In dev "<<nome<<"  Collected hits "<<mhit;
00667 }
00668 
00669 
00670 //***************************************************
00671 //======== fill default dev coordinate type(2) with type(1).====
00674 int Device::Fill_Default()
00675 {
00676     mhit=nhit+1;
00677 //  Gout<<"\n Default copy Ev "<< evento_.Gen.Event<<" dev "<<nome<< " hits "<< mhit;
00678 
00679     for ( int i=0;i<mhit;i++ )
00680     {
00681         M_Hits[i] =Hits[i];
00682     }
00683     return mhit;
00684 }
00685 
00686 //===============================================================
00687 int Device::Get_DatiOut()
00688 {
00702     hit_recorded=mhit;
00703 
00704     emDev=0.;
00705     if ( mhit>0 )
00706     {
00707 // test on the total hits
00708         if ( mhit>working_buffer )
00709         {
00710             Gout<<"\n Ev "<< Eventi_Fatti<<" <Measur_buffer> too low  in "<<nome<< " Detected hits: "<<mhit
00711             << " cut to  "<<working_buffer;
00712             mhit=working_buffer;
00713         }
00714 
00715         hit_recorded=mhit;
00716         for ( int hts=0;hts<hit_recorded;hts++ )
00717         {
00718             index[hts]=M_Hits[hts].id;
00719             mid[hts]=M_Hits[hts].idm;
00720             mdead[hts]=M_Hits[hts].idead;
00721             structinfo[hts]=M_Hits[hts].structinfo;
00722             devstory[hts]=M_Hits[hts].devstory;
00723             M_Hits[hts].Xdev.putv ( mxd[hts],myd[hts],mzd[hts] );
00724             mdd[hts]= M_Hits[hts].Xdev.XYNorma();
00725             me[hts]=M_Hits[hts].e_rivela;
00726             M_Hits[hts].Xlab.putv ( mxl[hts],myl[hts],mzl[hts] );
00727             M_Hits[hts].Pdev.putq ( gpx[hts],gpy[hts],gpz[hts],ge[hts] );
00728             dtemp[hts]=M_Hits[hts].tempo-evento_.Gen.tempo;
00729             emDev+=me[hts];
00730 
00731         }
00732     }
00733 
00734     return hit_recorded;
00735 }
00736 
00737 //*********************************************************
00738 
00739 //------------------------------------------
00740 void  Device::Get_Materiali()
00741 {
00742     MattPar *Elem;
00743     // nel interno del dev
00744     //   Gout<<"\n Elemeto interno "<< mattint;
00745     if ( mattint.size() !=0 )
00746     {
00747         Elem= Elemento->PntElem ( mattint );
00748         Zint   =Elem->Get_Z();   // carica atomica
00749         Aint   =Elem->Get_A();   // numero atomico
00750         liint  =Elem->Get_Intl();// lungh. interazione cm
00751         Roint  =Elem->Get_Ro();  // densita' g/cm3
00752         Dedxint=Elem->Get_Dedxl();// perdita energia Gev/cm
00753         lradi  =Elem->Get_Radl();//  rad in cm
00754     }
00755 
00756     if ( mattbuc.size() !=0 )
00757     {
00758         Elem= Elemento->PntElem ( mattbuc );
00759         Zbuc   =Elem->Get_Z();   // carica atomica
00760         Abuc   =Elem->Get_A();   // numero atomico
00761         libuc  =Elem->Get_Intl();// lungh. interazione cm
00762         Robuc  =Elem->Get_Ro();  // densita' g/cm3
00763         Dedxbuc=Elem->Get_Dedxl();// perdita energia Gev/cm
00764         lradb  =Elem->Get_Radl();//  rad in cm
00765     }
00766 }
00775 //------------------------------------------
00776 void  Device::Get_Pointers()
00777 {
00778 
00779 
00780     // to be updated according to the device names....
00781     // get dev pointers
00782     Gout<<"\n Device::Get_pointers() : get the device pointers to speed up the simulation..."
00783     <<"\n The user must adjust the device labels occording to names as defined in  .app file \n";
00784 
00785 
00786     collo=   Apparato->Get_Pointer ( "Collo" );
00787     xch02=   Apparato->Get_Pointer ( "XCH02" );
00788     spione0 = Apparato->Get_Pointer ( "spione0" );
00789     spione1 = Apparato->Get_Pointer ( "spione1" );
00790     vtappo = Apparato->Get_Pointer ( "Vtappo" );
00791 
00792     dectubo= Apparato->Get_Pointer ( "dectubo" );
00793     kabs1= (Devkabes*)  Apparato->Get_Pointer ( "Spibes1" );
00794     kabs2= (Devkabes*)  Apparato->Get_Pointer ( "Spibes2" );
00795     kabs3= (Devkabes*)  Apparato->Get_Pointer ( "Spibes3" );
00796 
00797     giga1=  (DevGtk*) Apparato->Get_Pointer ( "Gtk1" );
00798     giga2=  (DevGtk*) Apparato->Get_Pointer ( "Gtk2" );
00799     giga3=  (DevGtk*) Apparato->Get_Pointer ( "Gtk3" );
00800          cedar=  (DevCedar*) Apparato->Get_Pointer ( "cedar" );
00801     mgb1 =   Apparato->Get_Pointer ( "MCB80" );   // magnet pointers of acromat 2
00802     mgb2 =   Apparato->Get_Pointer ( "MCB84" );
00803     mgb3 =   Apparato->Get_Pointer ( "MCB95" );
00804     mgb4 =   Apparato->Get_Pointer ( "MCB97" );
00805     mgb5 =   Apparato->Get_Pointer ( "MDX99" );
00806 
00807     Chanti =   (DevChanti*) Apparato->Get_Pointer ( "chanti" );
00808 
00809     // get anticounter pointers...
00810 
00811     anti[0]=  (DevLav*) Apparato->Get_Pointer ( "Ant1" );
00812     anti[1]=  (DevLav*) Apparato->Get_Pointer ( "Ant2" );
00813     anti[2]=  (DevLav*) Apparato->Get_Pointer ( "Ant3" );
00814     anti[3]=  (DevLav*) Apparato->Get_Pointer ( "Ant4" );
00815     anti[4]=  (DevLav*) Apparato->Get_Pointer ( "Ant5" );
00816     anti[5]=  (DevLav*) Apparato->Get_Pointer ( "Ant6" );
00817     anti[6]=  (DevLav*) Apparato->Get_Pointer ( "Ant7" );
00818     anti[7]=  (DevLav*) Apparato->Get_Pointer ( "Ant8" );
00819     anti[8]=  (DevLav*) Apparato->Get_Pointer ( "Ant9" );
00820     anti[9]=  (DevLav*) Apparato->Get_Pointer ( "Ant10" );
00821     anti[10]= (DevLav*) Apparato->Get_Pointer ( "Ant11" );
00822     anti[11]= (DevLav*) Apparato->Get_Pointer ( "Ant12" );
00823 
00824 
00825     Cam1= (DevMwc*)  Apparato->Get_Pointer ( "Cam1" );
00826     Cam2= (DevMwc*)  Apparato->Get_Pointer ( "Cam2" );
00827     Cam3= (DevMwc*)  Apparato->Get_Pointer ( "Cam3" );
00828     Cam4= (DevMwc*)  Apparato->Get_Pointer ( "Cam4" );
00829 
00830     Rich= (DevRich*)   Apparato->Get_Pointer ( "Rich" );
00831 
00832     St1x= (DevStraw*)  Apparato->Get_Pointer ( "St1x" );  // la coordinata è parallela ai fili attenzione
00833     St1y= (DevStraw*)  Apparato->Get_Pointer ( "St1y" );
00834     St1u= (DevStraw*)  Apparato->Get_Pointer ( "St1u" );
00835     St1v= (DevStraw*)  Apparato->Get_Pointer ( "St1v" );
00836     St2x= (DevStraw*)  Apparato->Get_Pointer ( "St2x" );
00837     St2y= (DevStraw*)  Apparato->Get_Pointer ( "St2y" );
00838     St2u= (DevStraw*)  Apparato->Get_Pointer ( "St2u" );
00839     St2v= (DevStraw*)  Apparato->Get_Pointer ( "St2v" );
00840     St3x= (DevStraw*)  Apparato->Get_Pointer ( "St3x" );
00841     St3y= (DevStraw*)  Apparato->Get_Pointer ( "St3y" );
00842     St3u= (DevStraw*)  Apparato->Get_Pointer ( "St3u" );
00843     St3v= (DevStraw*)  Apparato->Get_Pointer ( "St3v" );
00844     St4x= (DevStraw*)  Apparato->Get_Pointer ( "St4x" );
00845     St4y= (DevStraw*)  Apparato->Get_Pointer ( "St4y" );
00846     St4u= (DevStraw*)  Apparato->Get_Pointer ( "St4u" );
00847     St4v= (DevStraw*)  Apparato->Get_Pointer ( "St4v" );
00848 
00849     mnp1 = (DevMagn*) Apparato->Get_Pointer ( "Mnp1" );
00850     mnp2 = (DevMagn*)  Apparato->Get_Pointer ( "Mnp2" );
00851     Mag48= (DevMagn*)  Apparato->Get_Pointer ( "Magn" );
00852     Mnp33= (DevMagn*)  Apparato->Get_Pointer ( "Mnp33" );
00853     hodo =  (DevChod*) Apparato->Get_Pointer ( "Hodo" );
00854     hodox = (DevChod*) Apparato->Get_Pointer ( "Hodx" );
00855     hodoy = (DevChod*) Apparato->Get_Pointer ( "Hody" );
00856 
00857     hadc =  (DevHac*)  Apparato->Get_Pointer ( "HACM" );
00858     iron  =  Apparato->Get_Pointer ( "Ironwall" );
00859     muvet1= (DevMuv*) Apparato->Get_Pointer ( "MUVET1" );
00860     muvet2= (DevMuv*) Apparato->Get_Pointer ( "MUVET2" );
00861     muvet3= (DevMuv*) Apparato->Get_Pointer ( "MUVET3" );
00862     monit = Apparato->Get_Pointer ( "Moni" );
00863     mamud=   Apparato->Get_Pointer ( "Mamu" );
00864 
00865     sacdev= (DevSac*)Apparato->Get_Pointer ( "Sac" );
00866     ircdev=(DevIrc*)Apparato->Get_Pointer ( "IRC" );
00867     lkry=   (DevLkr*) Apparato->Get_Pointer ( "Lkry" );
00868     if ( lkry==0 ) lkry= (DevLkr*)Apparato->Get_Pointer ( "Lkr" );
00869 
00870 
00871 }
00872 //------static Device *Walls,*lkry;
00873 //  static Device *Coll, *Updet,*Veto,*Buco,*Walls,*lkry;
00874 
00881 Device * Device::Get_Pointer ( const  char *word )
00882 {
00883     Device *dv,*dvok=0;
00884     dv=Apparato;
00885     while ( dv!=0 )
00886     {
00887         if ( dv->escludi==0 &&
00888                 strcmp ( dv->nome,word ) ==0 ) dvok= dv;
00889         dv=dv->next;
00890     }
00891     Gout<<"\n Device "<< setw ( 9 ) <<word<<" pointer "<< ( dvok?" found":" === not ===  found or excluded" );
00892     return dvok;
00893 }
00894 
00895 
00896 
00897 //------------------------------------------
00898 //  accedi=escludi=0;     trasformazioni lab -> dev -> lab
00899 //--------------------------------------------
00900 gvet& Device::Lab2Dev ( gvet &Vlab )
00901 {
00902     // trasformazioni di vettori direzione lab-> dev.
00903     static gvet _Vdev;
00904     _Vdev.setvn ( Vlab%Nx,Vlab%Ny,Vlab%Nz );
00905     return _Vdev;
00906 }
00907 //--------------------------------------------
00908 gvet& Device::Lab2cDev ( gvet &Xin )
00909 {
00910     // trasformazione di vettori al dev con traslazione...
00911 
00912     static gvet _Xdc,_Xdev;
00913     _Xdc=Xin-Centro;
00914     _Xdev.setvn ( _Xdc%Nx,_Xdc%Ny,_Xdc%Nz );
00915     return _Xdev;
00916 }
00917 
00918 //--------------------------------------------
00919 gvet& Device::Dev2Lab ( gvet &Vdev )
00920 {
00921     // trasformazioni di vettori direzione dev->lab.
00922     // calcola la norma.
00923     static gvet _Vlab;
00924     _Vlab=Nx*Vdev[0] + Ny*Vdev[1] + Nz*Vdev[2];
00925     _Vlab.normaq= _Vlab[0]*_Vlab[0]+ _Vlab[1]*_Vlab[1]+_Vlab[2]*_Vlab[2];
00926     _Vlab.norma= sqrt ( _Vlab.normaq );
00927     return _Vlab;
00928 }
00929 //--------------------------------------------
00930 gvet& Device::Devc2Lab ( gvet &Xdev )
00931 {
00932     // trasformazione di vettori dal Dev al lab con traslazione...
00933     // non calcola la norma...
00934     static gvet _Xlab;
00935     _Xlab=Nx*Xdev[0] + Ny*Xdev[1] + Nz*Xdev[2];
00936     _Xlab=_Xlab+Centro;
00937     return  _Xlab;
00938 }
00939 
00940 //================   T R A C C I A ====================================
00942 //================   T R A C C I A ====================================
00943 
00950 int Device::Traccia ( Particella *pr )
00951 {
00952     int iter=0;
00953     // impulso ==0 no tracing ... return;
00954     if ( pr->P.norma == 0.0 ) return 1;
00955 
00956     lint=nowpos?libuc:liint; //get the interaction length
00957 
00958 
00959     if ( fun==Bersaglio&& pr->rg!=0&&lint>0.0&&nowpos<1 )
00960     {   // se qui è un caso particolare... particelle si distrugge  nel dev 
00961         // Il dev fa da bersaglio 
00962         // ed è interna o nel buco ( è qui c'è di default)
00963         // e la lunghezza di interazione è definita non nulla!
00964         // si ridefisce il cammino se interagisce nel bersaglio
00965         pr->Get_Bersaglio ( this,lint );
00966         if ( pr->Ifato==-3 )
00967         { // la particella è stata distrutta!!!
00968             pr->Move ( pr->pathok );  // nuovo path (ma vedere meglio)
00969             pr->last_path=pr->pathok;
00970             pr->rg->dw->X=pr->rg->X=pr->X;    // definisco la posizione del C.M.
00971             pr->rg->dw->Gx=pr->rg->Gx=pr->X;
00972             return -3;   // la bullet muore nel dev
00973         }
00974     }
00975 
00976     double tratok=pr->pathok;
00977     lrad=nowpos?lradb:lradi; //get the radiation  length
00978     if ( lrad==0. )     // no radiation...
00979     {
00980         // free flight
00981         pr->Move ( tratok );
00982         pr->last_path=tratok;
00983         return 0;
00984     }
00985 
00986 // qui lrad != 0
00987 
00988     if ( pr->charg ==0.0 )
00989     {
00990 
00991 // se è un gamma fa Pair_Production
00992         if ( pr->Pair_Production>0&& Pair_done<maxPair ) //        Pair production activated?
00993         {
00994             if ( pr->P.e<0.002 ) // Energy cutoff .... fare meglio
00995             {
00996                 Hits[nhit].e_rivela+=pr->P.e;  // aggiorno l'energia persa...
00997                 Hits[nhit].idead=-18;
00998                 pr->Ifato=-18;
00999                 pr->P.setqn ( 0.,0.,0.,0. );
01000                 pr->pathok=0.0;
01001                 return -18;
01002             }
01003             pr->Get_Pair ( this,tratok,lrad );
01004             Hits[nhit].idead=pr->Ifato;
01005             pr->pathok=tratok; //redefine (if nedeed) free path before pair prod..
01006         }
01007         pr->Move ( tratok );
01008         pr->last_path=tratok;
01009         return 0;
01010     }
01011 //  qui lrad != 0   ed è carica 
01012     int crepa;
01013     double passdone=0.0;
01014     double passo= lrad;
01015 
01016 // fa bremsstrahlung
01017 
01018     while ( passdone<tratok )
01019     {
01020         double diff=tratok-passdone;
01021         if ( diff <passo ) passo =diff+0.001;
01022 
01023         if ( pr->Brems_Production>0 && Brem_done<maxBrems )
01024         {
01025             if ( pr->Get_Brems ( this,passo,lrad ) !=0 )
01026             {
01027                 pr->Move ( passo );  // divido per 2  ??? media
01028                 Mscatter ( pr,passo );
01029                 pr->last_path=passdone+passo;
01030                 Hits[nhit].idead=pr->Ifato;
01031                 return 0;
01032             }
01033         }
01034         // qui se non c'è stato brems...
01035         pr->Move ( passo );   //forse passo/2  ???!|!!
01036         if ( ( crepa=Mscatter ( pr,passo ) ) !=0 )
01037         {
01038             pr->last_path=passdone+passo;
01039 
01040             Hits[nhit].idead=crepa;
01041             return crepa;
01042         }
01043         passdone+=passo;
01044         iter++;
01045     }
01046     Hits[nhit].idead=pr->Ifato;
01047     Hits[nhit].last_path =pr->last_path=tratok;
01048     return 0;
01049 
01050 }
01051 
01052 //***************************************************
01053 //           Set_Rivela
01054 //--------------------------------------------
01055 void Set_Rivela_in_Dev ( Particella *pr )
01056 {
01057     // start from the tree top...
01058     Device *pdev=Apparato;
01059     while ( pdev!=0 )
01060     {
01061         pdev->Set_Rivela ( pr );
01062         pdev=pdev->next;
01063     }
01064 }
01065 
01066 //--------------------------------------------
01067 void Device::Set_Rivela ( Particella *pr )
01068 {
01082     int isee;
01083     const char *label;
01084 
01085 
01086 
01087     if ( escludi!=1 )
01088     {
01089         // dev visibile
01090         accedi=0;
01091         rivela=-1;
01092         // test if the dev sees the particle ...first by name
01093         isee = nvede;
01094         while ( isee >= 0 )
01095         {
01096             label = vede[isee];
01097             if ( label == pr->nome )
01098             {
01099                 rivela=assorb[isee];
01100                 Idsee=isee;
01101                 break;
01102             }
01103             isee--;
01104         }
01105         // ... and now  by type
01106         if ( rivela==-1 )
01107 
01108         {
01109             isee = nvede;
01110             while ( isee >= 0 )
01111             {
01112                 label = vede[isee];
01113                 if ( label == All ||label == pr->type ||
01114                         ( label == Char && pr->charg!=0. ) )
01115                 {
01116                     rivela=assorb[isee];
01117                     Idsee=isee;
01118                     break;
01119                 }
01120                 isee--;
01121             }
01122         }
01123     }
01124 
01125 // if(idev>1&&idev<4)
01126 // Gout<<"\n Riv "<< nome <<" "<<pr->nome<<" " <<accedi << " " <<rivela;
01127 
01128 
01129 }
01130 
01131 //--------------------------------------------
01132 void Device::Dev_summary()
01133 {
01134     if ( Tot_seen!=0 && escludi!=1 )
01135     {
01136         int ns;
01137         for ( int i=0;i<40;i++ ) if ( ( ns=Part_hit[i] ) !=0 )
01138             {
01139                 Gout.setf ( ios::fixed, ios::floatfield );
01140                 Gout<<"\n Dev "
01141                 <<setw ( 10 ) <<nome
01142                 <<" "<<setw ( 3 ) <<idev
01143                 <<" sees "<<setw ( 9 ) <<ns
01144                 <<"  "<<setw ( 6 ) <<vede[i]
01145                 <<"   Tot: "<<setw ( 9 ) <<Tot_seen<<setprecision ( 2 )
01146                 <<"  Z_lim.["<<setw ( 8 ) <<Centro.z-Lout.z
01147                 <<" <---> "<<setw ( 8 ) <<Centro.z+Lout.z<<"]"<<flush;
01148             }
01149     }
01150     if ( next!=0 ) next->Dev_summary(); //iterate !
01151 
01152 }
01153 
01154 //-------------------------------------------
01155 
01156 void Device::PrgeomId()
01157 {
01158 
01159     if ( this==Apparato )
01160     {
01161         Gout<<"\n\n==================  Detectors block =====================\n";
01162         Gout<<"\n    Id     nome   niknome  vs.    Z_in        Z_out      Wrk_buff          type \n";
01163     }
01164     Gout.setf ( ios::fixed, ios::floatfield );
01165     Gout<<setprecision ( 2 ) <<"\n "<<setw ( 3 ) <<idev
01166     <<setw ( 10 ) <<nome<<"   ["<<setw ( 6 ) <<nickname<<"] "
01167     <<" "<<escludi
01168     << "    "<<setw ( 8 ) << Cface.z
01169     << "    "<<setw ( 8 ) << Cface.z+2.*Lout.z
01170     << "    Wrb "<<setw ( 4 ) <<working_buffer
01171     << "   "<<setw ( 4 ) <<devtype<<" <=> "<<devclass;
01172     if ( next!=0 ) next->PrgeomId();
01173     else Gout<<"\n===========  End apparatus list   ============\n \n \n";
01174 }
01175 
01176 
01177 void Device::Prgeom()
01178 {
01179 
01180 
01181     Gout<<"\n Dev   Id ="<<setw ( 4 ) <<idev
01182     <<"\n Dev Type ="<<setw ( 4 ) <<devtype
01183     <<"\n Nome = "<<nome<< "    Code: "<<nickname;
01184     if ( escludi==1 ) Gout<<"\n\n Rivelatore  E S C L U S O  dall'utente";
01185 
01186     Gout<<endl;
01187     if ( Cface.norma>0. ) Cface.print ( "S.Lab" );
01188     Centro.print ( "C_lab" );
01189     gvet Cfine=Cface;
01190     Cfine[2]+=Lout[2]*2.;
01191     Cfine.print ( "E.Lab" );
01192     Lout.print ( "Lout" );
01193     if ( Lin.norma>0. )
01194     {
01195         if ( Centrin.norma>0. ) Centrin.print ( "C_in" );
01196         Lin.print ( "Lin" );
01197     }
01198     if ( Fortax.norma>0. )
01199     {
01200         Fortax.print ( "Linend" );
01201     }
01202     Gout<<endl;
01203     Nx.print ( "Nx" );
01204     Ny.print ( "Ny" );
01205     Nz.print ( "Nz" );
01206     //campo.....
01207 
01208     if ( campo==0 ) Field.print ( "Field" );
01209     if ( campo==1 ) Gout<<"\n Quad Bref                "<<setprecision ( 3 ) <<fixed<<setw ( 11 ) <<Bref;
01210     if ( campo==2 ) Gout<<"\n Campo magnetico variabile!";
01211     if ( campo==0 ) Gout<<"\n Reconstruction magic kik "<< setw ( 7 ) <<reckik;
01212     Gout<<"\n Memoria in ns             "<<setw ( 6 ) <<t_dead_mem;
01213     Gout<<"\n Working buffers           "<<setw ( 6 ) <<working_buffer;
01214     if ( wrout==1 ) Gout<<"\n Writeout ok";
01215     else Gout<<"\n Writeout off...";
01216 
01217     Gout<<endl;
01218     Gout.setf ( ios::floatfield );
01219     if ( lradi != 0.0 || lradb != 0.0 )
01220     {
01221         Gout.setf ( ios::right,ios::adjustfield );
01222         Gout<<setfill ( ' ' ) <<setprecision ( 5 )
01223         <<"\n Dev  stuff:           "<<setw ( 10 ) <<mattint<<"  in hole: "<<setw ( 10 ) <<mattbuc<<"  "
01224         <<"\n DensInt, DensBuco     "<<setw ( 10 ) <<Roint<<"  "<<setw ( 10 ) <<Robuc<<"  g/cm3"
01225         <<"\n Zint, Zbuc            "<<setw ( 10 ) <<Zint <<"  "<<setw ( 10 ) <<Zbuc<<"  Atom. charges"
01226         <<"\n Aint, Abuc            "<<setw ( 10 ) <<Aint <<"  "<<setw ( 10 ) <<Abuc<<"  Atom. Numbers"
01227         <<"\n Radin,Radb            "<<setw ( 10 ) <<lradi<<"  "<<setw ( 10 ) <<lradb<<"  "
01228         << ( Scatter==0?"M.S. off":"M.S. on " )
01229         <<"\n InterInt,InterBuco    "<<setw ( 10 ) <<liint<<"  "<<setw ( 10 ) <<libuc
01230         <<"\n Dedxint,Dedxbuc       "<<setw ( 10 ) <<Dedxint<<"  "<<setw ( 10 ) <<Dedxbuc<<"  Gev/cm  "
01231         << ( Perdita==0?"Loss off":"Loss on" )
01232         <<"\n MaxBrems, MaxPair     "<<setw ( 10 ) << maxBrems<<"  "<<setw ( 10 ) <<maxPair;
01233 
01234 
01235 
01236 
01237     }
01238     Gout.setf ( ios::floatfield );
01239 
01240     Gout<<"\n";
01241     int vst;
01242     int idt=0;;
01243     if ( nvede>-1 ) Gout<<"\n Lista delle particelle rivelate.\n";
01244     while ( idt<=nvede )
01245     {
01246         vst=assorb[idt];
01247         Gout<<"\n"<<idt<<" ->   Detect: < "<<setw ( 7 ) <<vede[idt]<<" >  "<<setw ( 7 ) <<
01248         ( vst==0?"Seen": vst==1?"Dump":vst==2?"Seen but not reg.":"Dump but not reg." );
01249         idt++;
01250     }
01251     Gout<<"\n---------------\n";
01252 }
01253 
01254 
01255 //==================Get_camm ==================
01256 
01282 Device *Device::Get_camm ( Particella *pr )
01283 {
01284     //  double tratto,path;  ...in device.h
01285     //  int posok,pos;
01286     //  double Last_distq=1.e+12;
01287     Device *Dvk,*Dev;
01288     //
01289     path=1.e+10;
01290     Dvk=0;
01291     Dev=this;    // device di partenza per la loop
01292     posok=3;
01293 
01294 
01295     while ( Dev!=0 )
01296     {
01297 
01298 
01299         if ( Dev->accedi>0|| Dev->escludi>0||
01300                 Dev->rivela<0 )      // dev non visibile o non vede
01301         {
01302 
01303             if ( Dev == Devloop ) Devloop = Devloop->next; //  aggiorno Devloop
01304             Dev=Dev->next;
01305             continue;
01306         }
01307 
01308 
01309 
01310         //--------------------=================----------------
01311         Dev->pr_dev=pr;
01312         Dev->X_dev=Dev->Lab2cDev ( pr->X ); // trasla al centro dev e ruota
01313         Dev->V_dev=Dev->Lab2Dev ( pr->Vers ); // routa il versore.... att. aggiornato!
01314 
01315         Dev->X_dev.Norma();
01316         if ( Dev->X_dev.normaq>Dev->Rqsize )  // test grossolano ma veloce  per dev esterno
01317         {
01318             dcs=Dev->X_dev%Dev->V_dev;   // dist. dal centro dev proiet. sul cammino
01319             if ( dcs>=0.0 )  // dev superato
01320             {
01321                 if ( Dev == Devloop ) Devloop = Devloop->next; //  aggiorno Devloop
01322                 Dev->accedi=13;
01323 
01324                 Dev=Dev->next;
01325                 continue;
01326             }
01327             else if ( Dev->X_dev.normaq-dcs*dcs>Dev->Rqsize )
01328             {
01329                 //  Dev->accedi=12;   //no! se lo scattering o un campo cambia la direzione di volo!
01330 
01331                 Dev=Dev->next;
01332                 continue;
01333             }
01334         }
01335         // check position carefullly.....
01336 
01337 
01338         pos = Dev->Posizione();
01339 
01340 //    if ( pr->idm==14 ) Dev->SpiaPr ( " Posiz ", 49,49 ,-99.);
01341 
01342 
01343 
01344 
01345 
01346         if ( pos==1 )              //Esterno
01347         {
01348             // calcolo il cammino per colpire il dev.....
01349             Dev->tratto=Dev->CamEster();
01350             //    if ( pr->idm==14 ) Dev->SpiaPr ( " Esterno ", 49,49 , Dev->tratto);
01351 
01352 
01353 
01354             if ( Dev->tratto>Dev->X_dev.norma ) Dev->tratto=Dev->X_dev.norma;
01355 //      if ( pr->idm==14 ) Dev->SpiaPr ( " Ester ", 48,48 );
01356 
01357             if ( Dev->tratto<0.0001 )          // Dev not accessible or just crossed
01358             {
01359                 Dev->accedi = 14;
01360                 if ( Dev == Devloop ) Devloop = Devloop->next; //  aggiorno Devloop
01361                 Dev=Dev->next;
01362                 continue;
01363             }
01364             else if ( Dev->tratto<path )    // viaggia verso il dev...
01365             {
01366                 path=Dev->tratto+0.01;
01367                 if ( posok>0 )
01368                 {
01369                     Dvk=Dev;
01370                     posok=pos;
01371                 }
01372             }
01373         }
01374 
01375         else if ( pos==0 )               //Interno ..
01376         {
01377             // calcolo la dist dalle parete di uscita. o da un dev  interno
01378             Dev->tratto=Dev->CamInter();
01379             if ( Dev->tratto<path ) path=Dev->tratto+0.01;  // corretto
01380             Dvk=Dev;
01381             posok=pos;
01382 //      if ( pr->idm==14 ) Dev->SpiaPr ( " Inter ", 48,48 );
01383 
01384             //qui cambiato??????????????????????????????????????
01385             //       break;  se non ci sono device interni si potrebbe uscire subito
01386 
01387         }
01388         else if ( pos==-1 )   //nel buco...  anxhe qui attenzione ai dev interni ......
01389         {
01390             Dev->tratto=Dev->CamBuco();
01391             if ( Dev->nowpos>-1 )
01392             {
01393                 Dvk=Dev;
01394                 posok=pos;
01395             }
01396             if ( Dev->tratto<path )  // corretto
01397             {
01398                 path=Dev->tratto+0.01;
01399                 if ( posok>-1 )
01400                 {
01401                     Dvk=Dev;
01402                     posok=pos;
01403                 }
01404             }
01405 
01406         }
01407 
01408 
01409         Dev=Dev->next;
01410     }       // end loop
01411 
01412     if ( Dvk!=0 )
01413     {
01414 
01415 
01416         Dvk->pr_dev=pr;   // ricordo l'indirizzo della particella in tracing..
01417         Dvk->camm= path+CEPSI;
01418         Dvk->prevpos=Dvk->nowpos;
01419         Dvk->nowpos=posok;
01420 //  Dvk->SpiaPr ( " Scelt ", 2,4, Dvk->camm );
01421     }
01422     return Dvk;
01423 }
01424 
01425 void Device::SpiaPr ( char *Tit, int start,int stop, double corri )
01426 {
01427     if ( idev<start|| idev>stop ) return;
01428     Gout.setf ( ios::fixed,ios::floatfield );
01429     Gout<<setprecision ( 2 );
01430     Gout<<"\n  Ev "<<setw ( 8 ) <<evento_.Gen.Event<<setw ( 10 ) <<Tit
01431     <<" " <<setw ( 10 ) << nome
01432     <<" at z "<<setw ( 10 ) <<Cface.z
01433     <<" pr "<<setw ( 6 ) <<pr_dev->nome
01434     <<"   at_Z "<<setw ( 10 ) <<X_dev.z
01435     <<" acc "<<setw ( 4 ) <<accedi
01436     <<" es "<<setw ( 4 ) <<escludi
01437     <<" Rv "<<setw ( 4 ) <<rivela
01438     <<" prev "<<setw ( 4 ) <<prevpos
01439     <<" pos "<<setw ( 4 ) <<nowpos
01440     <<" tratto "<<setw ( 10 ) <<corri;
01441 
01442 }
01443 
 All Classes Namespaces Files Functions Variables