FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_main/mainuti.cpp

Go to the documentation of this file.
00001 /*******   main utility routines *********/
00002 
00003 #define   MAINFLYO
00004 #include "flyoh.h"
00019 using namespace std;
00020 
00021 Particella *Pr_avo,*pr,*pb,*pc;
00022 //=======================================
00023 
00024 
00031 void flyoinit()
00032 {
00033 
00034     //-------------------------------------------------------------
00035     cout<<"\n <><><><><><><><><><><><><><><><><><><><><><><><><>"<<endl;
00036     cout<<"\n  Flyo starts  running "<< ctime ( &clockstart );
00037     clockstart=clocklast = time ( &tck );
00038     Gout<<"\n  Flyo starts  running "<< ctime ( &clockstart );
00039     Gout<<"\n <><><><><><><><><><><><><><><><><><><><><><><><><>"<<endl;
00040     //------------------------------------------------------------------
00041 
00042 
00043 
00044     // Inizializzazione....
00045     TBurst=new Tempo();
00046 
00047 // crea il data base delle particelle .
00048 //Se manacano particelle aggiungere in:   Crea_part_db();
00049     Crea_part_db();
00050 // crea il data base dei materiali
00051 //Se manacano materiali aggiungere in:   Crea_materiali_db();
00052     Crea_materiali_db();
00053 
00054 // si legge le file .epc e .app
00055     File_Manager();
00056     Sommario_Input_Data();
00057 
00058 
00059 // first call... initialization
00060 
00061     if ( Reaction==0 )
00062     {
00063         Gout<<"\n Reactions not defined.. exit!!";
00064         exit ( 0 );
00065     }
00066     Reaction->MaxSpettro();
00067     Reaction->Norma_Rate(); // rate normalization
00068     Reaction->Simple_List();
00069     Gout<<"\n\n"<<endl ;
00070 
00071     // get dev pointers. Attention...adjust with dev name changes...
00072     Apparato->Get_Pointers();
00073 
00074     if ( Trigger_low_on==1 ) Trigger=new TriggerBox();
00075    
00076 
00077     if ( Wtrk==1 )
00078     {
00079         // do tracks or trigger... at least four chamber...
00080         // for the kpivv experiment we need six chamber. of four planes each.....
00081 
00082         // NA48 experiment    4 chambers
00083         if ( Cam1!=0&&Cam2!=0&&Cam3!=0&&Cam4!=0&&Mag48!=0 )
00084         {
00085             // Na48/1, NA48/2   apparatus
00086 
00087             // in principio si possono trovare piu' tracce ma
00088             // ne ricostruiamo solo per 6 ....
00089             Le_Tracce=new Flyline();
00090             Tracc[0]=new Flytrk();
00091             Tracc[1]=new Flytrk();
00092             Tracc[2]=new Flytrk();
00093             Tracc[3]=new Flytrk();
00094             Tracc[4]=new Flytrk();
00095             Tracc[5]=new Flytrk();
00096             Gout<<"\n Dev NA48  track  done \n";
00097         }
00098         // Kpvv   experimento... nuovo apparato per il calcolo della fascio dal gigatrack...
00099         if ( giga1!=0&&giga2!=0&&giga3 )
00100         {
00101             // NA62: Kpivv new apparatus with double spectrometer
00102 //            Trkgiga=new TrackGiga();  // to test
00103 //            Gout<<"\n Dev Trkgiga    done \n";
00104         }
00105     }
00106 // here devstraw create...TriggerBox
00107 
00108 
00109     if ( FirstStraw!=0 )
00110     {
00111 // gmpKill
00112 
00113         DevStraw * poistraw=FirstStraw;
00114 
00115         ChambClus[0]=new ClusterStraw ( poistraw );
00116         poistraw=poistraw->nextstraw->nextstraw->nextstraw->nextstraw;
00117         ChambClus[1]=new ClusterStraw ( poistraw );
00118         poistraw=poistraw->nextstraw->nextstraw->nextstraw->nextstraw;
00119         ChambClus[2]=new ClusterStraw ( poistraw );
00120         poistraw=poistraw->nextstraw->nextstraw->nextstraw->nextstraw;
00121         ChambClus[3]=new ClusterStraw ( poistraw );
00122 // generate the track straw pointer.
00123         if ( Wtrk==1 )Trkstraw = new TrgmpStraw();
00124         Gout<<"\n Dev NA62  track (gmp)  done \n";
00125 
00126 
00127         // generate the track straw pointer.
00128         //        if( Wtrk==1 )Trkstraw = new TrackStraw();
00129         //        Gout<<"\n Dev NA62  track  done \n";
00130 
00131         //        ChambClus[0]=new ClusterStraw ( FirstStraw);//  attenzione per test gmp
00132     }
00133 
00134     Gout<<endl;
00135 
00136 
00137     // general random initialitiation:
00138     //     Correla =0 Inizializzazione fissa
00139     //     Correla =1 Inizializzazione dipendente dal run
00140     //     Correla =2 Inizializzazione dipendente dal run ed evento
00141 
00142     if ( Correla==0 ) Pran();
00143     else Set_Pran();
00144 
00145 
00146     Mostra=evento_.Mxev/10;
00147     if ( Mostra< 10000 ) Mostra=10000;
00148     if ( Mostra>200000 ) Mostra=200000;
00149 
00150 
00151     clockstart = time ( &tck );
00152     Gout<<"\n\n Starting time: "<< tck<<" ===> "<<ctime ( &clockstart );
00153     cout<<"\n\n Starting time: "<< tck<<" ===> "<<ctime ( &clockstart ) <<endl;
00154 }
00155 
00156 //================== F l y o e v e n t  =============================
00157 //============>>   M a i n    e v e n t  generator....     <<===========
00158 
00163 int flyoevento()
00164 {
00165 
00166 
00167 
00168     //   int colpo=0, visto = 0,debaggati=0;
00169     colpo=0;
00170 
00171 //  se Correla=2 inizializzazione di random secondo l'evento e run
00172     if ( Correla==2 ) Set_PranEv();
00173 
00174     Debugon=1;
00175     if ( Eventi_Fatti < evento_.Debg_first ) Debugon=0;
00176     if ( Eventi_Fatti > evento_.Debg_last ) Debugon=0;
00177 
00178     if ( Eventi_Fatti % Mostra == 0 )
00179     {
00180         clockend = time ( &tck );
00181         double Elapsed=clockend-clockstart;
00182         double FromLast=clockend-clocklast;
00183         double pevsec=-1.,evsec =-1.;
00184 
00185 
00186 
00187 
00188         if ( Elapsed>0.0 ) evsec=Eventi_Fatti/Elapsed;
00189         if ( FromLast>0.0 ) pevsec= ( Eventi_Fatti-evento_.Evenlast ) /FromLast;
00190 
00191         std::ostringstream strs;
00192         strs << pevsec;
00193         std::string str = strs.str();
00194         if (pevsec<0.) str="inf";
00195 
00196         cout<<"\n Run "<<evento_.Gen.Run
00197             <<"  Ev. "<<setw ( 8 ) <<Eventi_Fatti
00198             <<"  Ev/s "<<setw ( 8 ) << str.c_str()
00199             <<"  Ev/s medio "<<setw ( 8 ) <<evsec
00200             <<"  elapsed  "<<Elapsed
00201             <<" At "<<ctime ( &clockend );
00202 
00203         cout<<endl;
00204 
00205         Gout<<setprecision ( 1 );
00206         Gout<<"\n Run "<<evento_.Gen.Run
00207         <<"  Ev. "<<setw ( 8 ) <<Eventi_Fatti
00208         <<"  Ev/s "<<setw ( 8 ) << str.c_str()
00209         <<"  Ev/s medio "<<setw ( 8 ) <<evsec
00210         <<"  elapsed  "<<Elapsed
00211         <<" At "<<ctime ( &clockend );
00212 
00213         clocklast=clockend;
00214         evento_.Evenlast=Eventi_Fatti;
00215 
00216     }
00217 // reset the old reaction....
00218 
00219 //   if(SelRea!=0) SelRea->Reset_Rea();
00220 
00221     // get the reaction pointer according to the rate...
00222     if ( ( SelRea = Reaction->Select_reation () ) == 0 )
00223     {
00224         Gout<<"\n Reaction not found... exit"<<endl;
00225         exit ( 0 );
00226     }
00227     SelRea->AddGen();
00228 
00229     if ( Debugon==1 )
00230     {
00231         debaggati++;
00232         Gout<<"\n\nRun "
00233         <<setprecision ( 0 ) <<fixed
00234         <<setw ( 6 ) <<evento_.Gen.Run<<"  E v e n t o "
00235         <<setw ( 6 ) <<Eventi_Fatti<<"  Dbg="
00236         <<setw ( 6 ) <<debaggati<<" "
00237         <<setw ( 25 ) <<SelRea->Get_Titolo() <<endl;
00238     }
00239     // =================== reset param...=====================================
00240     Pr_avo = SelRea->avo;
00241 //-------------------
00242 
00243 // get the beam  (for the moment Get_Beam returns allways 1! but just in the case...
00244     if ( SelRea->Get_Beam () ==0 )  return ( -2 );
00245 
00246 //--------------------------------------------
00247 
00248     visto=0;
00249 
00250 //   trasport the first particle della reazione...
00251     colpo = Pr_avo->Trasport();
00252 //   Pr_avo->Stampa_questa_particella();
00253     visto+= colpo;
00254 // if the beam do not decay or has not gas intaractions...get out
00255 
00256     if ( Pr_avo->dw!=0 || Pr_avo->cls!=0 );
00257     else if ( SelRea->rea_type==-1 )
00258     {
00259         visto=1;
00260         return ( 1 );
00261     }
00262 
00263     if ( colpo<0 )
00264     {
00265         return ( colpo );
00266     }
00267 
00268 //================================ l o o p  for the other particles =========//
00269 //  decay loop ....dei decadimenti .
00270 // main loop: iterative procedura to follow the reaction tree...
00271 
00272 
00273 
00274 
00275 
00276     if ( Pr_avo->dw!=0 || Pr_avo->cls!=0 ) //non un urto: decay oppure gas
00277     { // la particella padre decade comunque....
00278         // se è un proiettile che ha interagito non decade vedi PartBullet::Get_Bersaglio()
00279         Pr_avo->Set_Pbar();
00280         Pr_avo->Main_Loop();  //vedi qui sotto il sorgente
00281 //        cout<<"\n DGEv dopo main  "<<Eventi_Fatti<<" colpo "<<colpo<<" visto "<<visto;
00282     }
00283 
00284 
00285     if ( Pr_avo->Get_Type() ==Bullet )
00286     { // la particella padre è il proiettile
00287         // il bersaglio è alla sua destra.....
00288         // ccms è il sistema virtuale (proiettile -bersaglio)
00289         // i cui parametri sono definiti in PartBullet::Get_Bersaglio()
00290 //     Gout<<"\n "<<Eventi_Fatti<<" è una Bullet....";
00291         Particella * ccms=Pr_avo->rg->dw;
00292         ccms->Set_Pbar();
00293         ccms->Main_Loop();
00294     }
00295 
00296 
00297 
00298 // qui solo per debug
00299 //  if(Eventi_Fatti==151) SelRea->Simple_List();
00300 
00301     if ( Debugon==1 )
00302     {
00303         Pr_avo->Stampa_particle ( SelRea );
00304         Gout<<endl;
00305     }
00306 
00307 
00308 //============================  main l o o p   end===================//
00309 
00310     //------------update special counters ---
00311     SelRea->Totpair+=   SelRea->Pair_done;
00312     SelRea->Totbrem+=  SelRea->Brem_done;
00313     SelRea->Totdltz+=   SelRea->Dalitz_done;
00314     evento_.Gen.Ipair=SelRea->Pair_done;
00315     evento_.Gen.Ibrem=SelRea->Brem_done;
00316     evento_.Gen.Idlz =SelRea->Dalitz_done;
00317 
00318     if ( Debugon==1 ) SelRea->avo->Debug_out ();
00319 
00320 //  cout<<"\n Run-spia "<<evento_.Gen.Run  <<"  Ev. "<<setw ( 8 ) <<Eventi_Fatti<<endl;
00321 
00322     return ( visto );
00323 }
00324 
00325 
00326 
00327 
00328 
00333 void flyosimuladev()
00334 {
00335     Device *pv;
00336     pv=Apparato;
00337     while ( pv!=0 )
00338     {
00339         if ( pv->escludi==0)
00340         {
00341             pv->Reset_RootData();
00342 
00343 //            if ( pv->nhit>-1 )
00344 //            {
00345 // si simula in dettaglio il dev e poi si introducono gli errori 
00346 // aggionamento con inversione (DataSmear<-> simulaDev) dal 5/3/2011
00347                 if ( Errori==1 )  pv->SimulaDev();
00348                 if ( Errori==1 )  pv->DataSmear(); 
00349              
00350  //           }
00351         }
00352         pv=pv->next;
00353     }
00354 
00355 
00356 //========================================================
00357     // ricostruisco le tracce per NA48.....
00358 
00359     if ( Le_Tracce!=0 )
00360     {
00361         Le_Tracce->Reset();
00362         Le_Tracce->Get_Hits_from_Dev();
00363         Le_Tracce->Find_Tracce();  // creo le tracce:  max six ma si puo' aumentare
00364         if ( Debugon==1 )
00365         {
00366             if ( Tracc[0]!=0 ) Tracc[0]->Spia_Trk();
00367         }
00368     }
00369 
00370 //========================================================
00371 
00372 //  straw chamber track                                 GmpKill
00373 
00374     if ( Trkstraw !=0 )   {
00375         ChambClus[0]->Get_Cluster();
00376         ChambClus[1]->Get_Cluster();
00377         ChambClus[2]->Get_Cluster();
00378         ChambClus[3]->Get_Cluster();
00379 
00380 
00381         Trkstraw->Make_Trk();
00382 
00383 
00384     }
00385 
00386 
00387 
00388 
00389 
00390 
00391     // it is called at the  tracing end
00392     //------------update special counters ---
00393 
00394     SelRea->Tailsrt+=   SelRea->Tailsrt_done;
00395     SelRea->Tailong+=   SelRea->Tailong_done;
00396     evento_.Gen.Itsrt=SelRea->Tailsrt_done;
00397     evento_.Gen.Itlg= SelRea->Tailong_done;
00398 
00399 
00400 
00401 
00402 }
00403 
00404 
00405 //=================================================
00413 void flyoend()
00414 {
00415     Gout<<"\n------------ Device hit summary   ----------";
00416     Apparato->Dev_summary();
00417     Gout<<"\n------------         E n d        ----------";
00418     Gout<<"\n---                                     ----\n";
00419     if ( Le_Tracce!=0 )
00420         Gout<<"\n Charged tracks info.. "<<Tracc[0]->tottrk<<" "<<Tracc[1]->tottrk<<" "<<Tracc[2]->tottrk<<endl;
00421     Reaction->Fine_run ();
00422 
00423     clockend = time ( &tck );
00424     double dft=clockend-clockstart;
00425     double evsec =Eventi_Fatti/dft;
00426 
00427     Gout<<"\n T start "<<clockstart<<"  e stop "<<clockend<<"  e diff  "<<dft<<" Sec."<<endl;
00428     Gout<<"\n Epsi Event/sec = "<<setw ( 10 ) <<evsec<<endl;
00429 
00430     Gout<<"\n Epsi main loop start at "<<setw ( 25 ) <<ctime ( &clockstart ) <<endl;
00431     Gout<<"\n Epsi main loop end   at "<<setw ( 25 ) <<ctime ( &clockend ) <<endl;
00432 
00433 
00434 }
00435 
00436 //========================================================================
00437 
00438 int Particella::Main_Loop()
00439 {
00440     Particella  *pb=0, *pc=0;
00441 
00442 // decay and particle transport....
00443 // iterative procedure to follow the reaction tree...
00444     /*
00445         Gout<<"\n Vold1_Ev "<<Eventi_Fatti<<" "<<setw(6)<<ido
00446           <<" "<<setw(6)<<id
00447           <<" "<<setw(6) <<nome<<flush;*/
00448 
00449 //--------- decay
00450     if ( colpo<0 ) return 0; // close any tracing if "colpo" has been set to negative, ( as by veto system?)
00451     if ( dw != 0 )
00452     {
00453         pb = dw;
00454         if ( pb->rg!=0 ) pc = pb->rg;
00455         else if ( pb->lf!=0 ) pc = pb->lf;
00456         if ( pc==0 )
00457         {
00458             Gout<<"\n Voldec Chaining error!! Ev "<<evento_.Gen.Event;
00459             exit ( 0 );
00460         }
00461 
00462 
00463         if ( Voldec ( pb, pc ) >0 )  //trasport only if return > 0! Check the program wy!
00464         {
00465 
00466 //      trasport  per la prima particella
00467 //        Gout<<"\n traccio  "  <<pb->nome; //pb->Gp.print(pb->nome);
00468             if ( ( colpo = pb->Trasport() ) <0 ) return 0;
00469             visto+= colpo;
00470 
00471 //      seconda particella
00472 //        Gout<<"\n traccio  "  <<pc->nome; //pc->Gp.print(pc->nome);
00473             if ( ( colpo = pc->Trasport () ) <0 ) return 0;
00474             visto+= colpo;
00475 
00476 //         pb->Stampa_questa_particella();
00477 //         pc->Stampa_questa_particella();
00478 
00479 //                 Gout<<" =dw=> "<<setw(6)<<pb->id<<" "<<setw(6) <<pb->nome;
00480 //                 if(pb->dw!=0) Gout << " =dw=> "<<pb->dw->nome; else Gout << "    -- ";
00481 //                 Gout<<" =rg=> "<<setw(6)<<pc->id<<" "<<setw(6)<<pc->nome;
00482 //                 if(pc->dw!=0) Gout << " =dw=> "<<pc->dw->nome; else Gout << "    -- ";
00483 
00484 
00485             if ( pb->dw!=0||pb->cls!=0 ) pb->Main_Loop();  //itera....
00486             if ( pc->dw!=0||pc->cls!=0 ) pc->Main_Loop();  //itera....
00487         }
00488     }
00489 
00490 
00491 //---------------only tracing (particles from cluster)
00492     if ( cls != 0 )
00493     {
00494         if ( ( colpo = cls->Trasport () ) <0 )  return 0; //just in the case of veto
00495         visto+= colpo;
00496         /*
00497            Gout<<" =cls=>  "<<setw(6)<<cls->id<<" "<<setw(6)<<cls->nome;
00498            if(cls->dw!=0) Gout << " =dw=> "<<cls->dw->nome; else Gout << "    -- ";*/
00499 
00500         if ( cls->dw!=0||cls->cls!=0 ) cls->Main_Loop();
00501     }
00502 
00503     return 0;
00504 
00505 }
00506 
00507 
 All Classes Namespaces Files Functions Variables