PREAN/TFndProcessRec.cxx

00001 // @(#)fROOT/PREAN:$Name:  $:$Id: TFndProcessRec.cxx,v 1.18 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Final Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2006/10/30
00003 // First Revision Author: B. Dalena, D. Di Santo, D. Faso, G. Simonetti
00004 // Original Author: Valerio Filippini, Alberto Panzarasa (2000)
00005 
00007 //                                                                                        //
00008 //    TFndProcessRec:                                                                     // 
00009 //      root interface to fortran FINUDA reconstruction program (fidarc)                  //
00010 //                                                                                        //
00011 //    06.12.2003: Class updated and modified in turin for fROOT by:                       //
00012 //                Barbara Dalena, Daniela Di Santo, Diego Faso, Giuseppe Simonetti        //
00013 //                                                                                        //
00014 // Every change in the reconstruction proceduremust be applied here if some of the        //
00015 // following routines are changed:                                                        //
00016 //  - main.f -----> check "InitRun()"                                                     //
00017 //  - uginit.f ---> just check fortran (if something new has been added)                  //
00018 //  - gutrev.f ---> check "FillJFGES()" up to "IF (HYPE) THEN" [in gutrev.f]              //
00019 //             ---> check "Reconstruct()" from "IF (HYPE) THEN" [in gutrev.f]             //
00020 //                  for kaons: remember to update both cases: "HYPE" and "HYPE && BHABHA" //
00021 //                                                                                        //
00022 // zebra access example methods                                                           //
00023 // // --- you can test the class like this:                                               //
00024 //                                                                                        //
00025 //    TFndProcessRec *proc =new TFndProcessRec("FINU",536,kTRUE);                         //
00026 //    proc->SetMaxEv(100);                                                                //
00027 //    proc->AutoProcessRun();                                                             //
00028 //                                                                                        //
00029 // Automatic file 'Autoprocess_histos.root' is created                                    //
00030 // BHABHA bank not decoded in this example!!!                                             //
00032 
00033 #include <dlfcn.h>
00034 #include <Riostream.h>
00035 #include <TROOT.h>
00036 #include <TSystem.h>
00037 #include <TMath.h>
00038 
00039 #include "TFndProcessRec.h"
00040 
00041 // --- Used for examples
00042 #include "TCanvas.h"
00043 #include "TFile.h"
00044 // ---
00045 const Int_t Ng=1500000; // good
00046 const Int_t Nh=500000; // good
00047 // from main.f
00048 //  (NG = 5000024, NH = 1000000) // before fida-version 603
00049 //  (NG = 5000024, NH = 5000024) // from fida-version 603
00050 
00051 struct FidaIntPawc   { int H[Nh]; } pawc_;
00052 struct FidaIntGcBank { int Q[Ng]; } gcbank_;
00053 
00054 ClassImp(TFndProcessRec)
00055 
00056 //_______________________________________________________________
00057 TFndProcessRec::TFndProcessRec()
00058 :TNamed("dummyinterface","dummy interface"),
00059  fProcDirBaseName(),fCurProcNum(),fTyp(),fNum(),fRawFileName(),fMsqlDbHostStr(),
00060  fZebini(),fGcflag(),fRuninf(),flib_handle(),
00061  fJINFO(),fJFGES(),fJFDST(),fLQ(),fIQ(),fQ(),fdebug(),fRawFileExists()
00062 {
00063   //
00064   CommInit();
00065 }
00066 
00067 //_______________________________________________________________
00068 TFndProcessRec::TFndProcessRec(Int_t num, Bool_t debug)
00069 :TNamed("froot<->fidarc_interface","FINUDA froot<->mc_interface"),
00070  fProcDirBaseName(),fCurProcNum(),fTyp(),fNum(),fRawFileName(),fMsqlDbHostStr(),
00071  fZebini(),fGcflag(),fRuninf(),flib_handle(),
00072  fJINFO(),fJFGES(),fJFDST(),fLQ(),fIQ(),fQ(),fdebug(),fRawFileExists()
00073 {
00074   // method to be debugged and completed!
00075   CommInit();
00076 
00077   fdebug = debug;
00078   // Monte Carlo
00079   if(fdebug) cout << " --->debug TFndProcessRec::TFndProcessRec: "<< this->GetName() << " constructor called for MonteCarlo data" << endl;
00080   fTyp = new TString("MCAR");
00081   fNum = num;
00082   Char_t opt[10];
00083   sprintf(opt,"%d",num);
00084   SetFidaRC("NRUN",opt);
00085   if(fdebug) cout << " ---> ...opening library libFIDARC.so..." << endl; 
00086   flib_handle=dlopen("libFIDAMC.so",RTLD_LAZY);
00087   if(fdebug) cout << " --->done! Calling InitRun() " << endl; 
00088   
00089   InitRun(); 
00090   SetZebini();
00091   SetGcflag();
00092 }
00093 
00094 //_______________________________________________________________
00095 TFndProcessRec::TFndProcessRec(const Char_t *typ, Int_t num, const Char_t *data_path, const Char_t *msql_db_host, Bool_t debug)
00096 :TNamed("froot<->fidarc_interface","FINUDA froot<->rec_interface"),
00097  fProcDirBaseName(),fCurProcNum(),fTyp(),fNum(),fRawFileName(),fMsqlDbHostStr(),
00098  fZebini(),fGcflag(),fRuninf(),flib_handle(),
00099  fJINFO(),fJFGES(),fJFDST(),fLQ(),fIQ(),fQ(),fdebug(debug),fRawFileExists()
00100 { 
00101 
00102   CommInit();
00103   
00104   //--- Setting of $MSQL_DB_HOST
00105   if (msql_db_host && *msql_db_host == '$')
00106     msql_db_host = gSystem->Getenv(msql_db_host + 1);
00107   
00108   gSystem->Setenv("MSQL_DB_HOST",msql_db_host);
00109   if(fdebug) cout << "Starting \"FINUDA froot<->rec_interface\": msql host is: " << gSystem->Getenv("MSQL_DB_HOST") << endl;
00110   
00111   //--- Setting of $RDT
00112   if (data_path && *data_path == '$')
00113     data_path = gSystem->Getenv(data_path + 1);
00114   
00115   gSystem->Setenv("RDT",data_path);
00116   if(fdebug) cout << "Starting \"FINUDA froot<->rec_interface\": raw data path is: " << gSystem->Getenv("RDT") << endl;
00117   
00118   //--- Setting of temporary $INP (needed for running in multi-process mode)
00119   CreateProcInpFiles();
00120   
00121   // Real data
00122   //  fdebug = debug;
00123   fTyp = new TString(typ);
00124   fNum = num;
00125   fMsqlDbHostStr = new TString(msql_db_host);
00126   
00127   if(fdebug) cout << " --->debug TFndProcessRec::TFndProcessRec: "<< this->GetName() << " constructor called for Real data" << endl;
00128   CheckRawFile(); 
00129   
00130   TString type_pass;
00131   type_pass.Form("'%s'",fTyp->Data());
00132   
00133   if(fdebug) cout << " --->debug TFndProcessRec::TFndProcessRec: passing string " << type_pass << " to 'SetFidaRC' method" << endl;
00134   
00135   SetFidaRC("TRUN",(Char_t *)type_pass.Data());  
00136   
00137   Char_t opt[10];
00138   sprintf(opt,"%d",num);
00139   SetFidaRC("NRUN",opt);  
00140   
00141   // --- now chose the correct geometry according to the RUN-type/number
00142   //  ( really dangerous, but fortran needs it...the run-time from raw event should be used! )
00143   Bool_t IsNewDataTaking = kFALSE;
00144   Int_t RunNumThresholds[FROOT::RT_ONLM]; // last number of 2003 d-tak depending on the run type
00145   RunNumThresholds[FROOT::RT_FINU] = 2583;
00146   RunNumThresholds[FROOT::RT_COSM] = 4200; //check
00147   RunNumThresholds[FROOT::RT_PULS] = 1000;
00148   RunNumThresholds[FROOT::RT_PEDE] = 1000;
00149   RunNumThresholds[FROOT::RT_CALI] = 1000;
00150   RunNumThresholds[FROOT::RT_PLAT] = 1000;
00151 
00152   Int_t i_check;
00153   for(i_check=FROOT::RT_FINU; i_check<= FROOT::RT_ONLM; i_check++){
00154     //    Printf(" ---------------> \"%s\" <-> \"%s\"",fTyp->Data(),FROOT::RunType_Name(i_check).Data());
00155     if( !fTyp->CompareTo(FROOT::RunType_Name(i_check).Data()) ) break;
00156   }
00157   
00158   if(i_check!=FROOT::RT_ONLM){
00159     IsNewDataTaking = ( num <=  RunNumThresholds[i_check] ) ? kFALSE : kTRUE;
00160     Info("TFndProcessRec","Setting \"GEOC\" in \"fidarc.dat\" according to %d",IsNewDataTaking);
00161     (IsNewDataTaking) ? SetFidaRC("GEOC","1       1") : SetFidaRC("GEOC","0       1");
00162   }
00163   else{ // support for new data-taking only available in online mode
00164     Info("TFndProcessRec","run type is \"%s\": Setting \"GEOC\" in \"fidarc.dat\" to \"1\"");
00165     SetFidaRC("GEOC","1       1");
00166   }
00167   // ---
00168   SelectBhabhaInFidaRC(E_DOUBLE_HELIX); // by default use double-helix procedure for bhabha events
00169 
00170   // --- fidarc.dat card has been set
00171 
00172   flib_handle=dlopen("libFIDARC.so",RTLD_LAZY);
00173 
00174   if(fdebug) cout << "Initialyzing new run..." << endl;
00175   InitRun();
00176   if(fdebug) cout << "...done: now setting zebini..." << endl;
00177   SetZebini();
00178   if(fdebug) cout << "...done: now setting gcflag..." << endl;
00179   SetGcflag();
00180   if(fdebug) cout << "Constructor completed" << endl;
00181 }
00182 
00183 //_______________________________________________________________
00184 TFndProcessRec::~TFndProcessRec()
00185 {
00186   if(fdebug) cout << "TFndProcessRec debug: Destructor called." << endl; 
00187   
00188   // remove temporary (*.dat) directory
00189   //  gROOT->Info("~TFndProcessRec","DEBUG");
00190   CleanCurrentProcess();
00191   //  uglast_();
00192   //  gROOT->Info("~TFndProcessRec","DEBUG");
00193   delete fTyp;
00194   delete fMsqlDbHostStr;
00195   delete fRawFileName;
00196   //  gROOT->Info("~TFndProcessRec","DEBUG");
00197   fZebini = 0;
00198   fGcflag = 0;
00199   fRuninf = 0;
00200   flib_handle = 0;
00201   fIQ=0;
00202   fQ  =0;
00203   fLQ =0; 
00204   //  gROOT->Info("~TFndProcessRec","DEBUG");
00205 
00206   if(fdebug) cout << "TFndProcessRec debug: Destructor completed." << endl; 
00207 }
00208 
00209 //_______________________________________________________________
00210 void TFndProcessRec::CommInit(){
00211   // Initialization needed by all ctors
00212   fProcDirBaseName = "fida_proc_";
00213 }
00214 
00215 //_______________________________________________________________
00216 void TFndProcessRec::CreateProcInpFiles(){
00217   // make a directory for current process fida*.dat
00218   TString Ori_Inp = gSystem->Getenv("INP");
00219   // ---
00220   // Create a new subdirectory for current process setup files
00221   TString Proc_Inp = gSystem->Getenv("PWD");
00222   TString pth = Proc_Inp;
00223 
00224   Int_t i = 0;
00225   for(i=1; i <= K_NMAX_PROCESSES; i++){
00226     Proc_Inp.Form("%s/%s%d",pth.Data(),fProcDirBaseName.Data(),i);
00227     if(fdebug) Printf("looking for directory \"%s\"",Proc_Inp.Data());
00228     if( !gSystem->AccessPathName(Proc_Inp.Data()) ){
00229       Printf("Directory for process number \"%d\" already exists: trying next...",i);
00230       continue;
00231     }
00232     TString MkCmd = "mkdir ";
00233     MkCmd+=Proc_Inp;
00234     Printf("Sending command: \"%s\"",MkCmd.Data());
00235     gSystem->Exec(MkCmd.Data());
00236     break;
00237   }
00238   if(i>=K_NMAX_PROCESSES){
00239     Printf("Can not start process number \"%d\" (max # of processes reached)",i);
00240     FROOT::TerminateFroot(0,"TFndProcessRec -> Maximum number of processes reached");
00241   }
00242   fCurProcNum = i;
00243   
00244   // ---
00245   // copy every needed file in new directory
00246   TString copy_cmd;
00247   copy_cmd.Form("cp %s/*.dat %s/.",Ori_Inp.Data(),Proc_Inp.Data());
00248   Printf("Sending command: \"%s\"",copy_cmd.Data());
00249   gSystem->Exec(copy_cmd.Data());
00250   
00251   // --- 
00252   // change $INP for current session
00253   Printf("changing INP variable to directory \"%s\"",Proc_Inp.Data());
00254   gSystem->Setenv("INP",Proc_Inp.Data());
00255 }
00256 
00257 //_______________________________________________________________
00258 void TFndProcessRec::CleanCurrentProcess(){
00259   // remove directory with current process fida*.dat
00260 
00261   TString Proc_Inp;
00262   TString Cdir = gSystem->Getenv("PWD");
00263   Proc_Inp.Form("%s/%s%d",Cdir.Data(),fProcDirBaseName.Data(),fCurProcNum);
00264   
00265   TString clean_cmd;
00266   clean_cmd.Form("rm -rf %s",Proc_Inp.Data());
00267   if(gSystem->AccessPathName(Proc_Inp.Data())){
00268     Warning("CleanCurrentProcess","Directory fpr current process does not exist (%s)",Proc_Inp.Data());
00269     return;
00270   }
00271   
00272   Printf( "Sending command: \"%s\"",clean_cmd.Data() );
00273   
00274   TString InpChk = gSystem->Getenv("INP");
00275   InpChk.Prepend("rm -rf ");
00276   Int_t CmpRes = InpChk.CompareTo(clean_cmd);
00277   if(fdebug) Printf("Comparing \"%s\" to \"%s\": result: %d",InpChk.Data(),clean_cmd.Data(),CmpRes);
00278   if(CmpRes != 0){
00279     Error("CleanCurrentProcess","$INP sems to be wrong!");
00280     FROOT::TerminateFroot();
00281   }
00282   gSystem->Exec(clean_cmd.Data());
00283 }
00284 
00285 //___________________________________
00286 void TFndProcessRec::CheckRawFile()
00287 {
00288   // while using TFndPreanMan this method should be
00289   // useless (raw-file check is performed previousely)
00290 
00291   if(fdebug) cout << "TFndProcessRec::CheckRawFile ---> fNum = " << fNum << endl;
00292   if(fNum==-1){// fNum==-1 means online (no raw file needed)
00293     fRawFileExists = kTRUE; // for any eventual check
00294     return;
00295   }
00296 
00297   fRawFileExists = kFALSE;
00298   // --- converting to 'run_num' to 'TString*'
00299   TString RunNumStr = "";
00300   RunNumStr.Form("%d",fNum);
00301   while(1){
00302     Int_t size = RunNumStr.Sizeof()-1;
00303     if(size>=5)break;
00304     RunNumStr.Prepend("0");
00305   }
00306   // --- filename and control strings
00307   delete fRawFileName;
00308   fRawFileName = new TString(fTyp->Data());
00309   *fRawFileName+=RunNumStr;
00310   if(fdebug) cout << endl << "Checking existence of run " << fRawFileName->Data();
00311   *fRawFileName+=".raw";
00312   // --- file must be in $RDT
00313   TString *PathName = new TString(gSystem->Getenv("RDT"));
00314   //cout << " in directory: " << PathName->Data() << endl;
00315 
00316   *PathName+="/";
00317   *PathName+=fRawFileName->Data();
00318 
00319   if(fdebug) cout << " --->debug TFndProcessRec::CheckRawFile(): file:" << PathName->Data() << endl; 
00320   // --- check raw file
00321   if(gSystem->AccessPathName(PathName->Data())==0){
00322    fRawFileExists = kTRUE;
00323    if(fdebug) cout << " ...raw file found"<< endl;
00324   }
00325   else{ // --- check zip-file
00326     *PathName+=".gz";
00327     if(gSystem->AccessPathName(PathName->Data())==0){
00328       fRawFileExists = kTRUE;
00329       if(fdebug) cout << " ...raw zip-file found"<< endl;
00330     }
00331   }
00332   // --- result
00333   if(!fRawFileExists) {
00334     cout << " *** file " << PathName->Data() << " not found!" << endl;
00335     cout << " Exiting program!" << endl << endl;
00336     gROOT->ProcessLine(".q");
00337   }
00338   delete PathName;
00339 }
00340 
00341 //_______________________________________________________________
00342 void TFndProcessRec::InitRun() {
00343   // Method used to initialize fortran
00344   // see fidarc->main.f
00345 
00346   fMaxEv=100000000;
00347 
00348   Int_t a =  Ng;
00349   Int_t b = -Nh;  
00350   if(fdebug) cout << " --->debug TFndProcessRec::InitRun(): entering method." << endl; 
00351 
00352   gzcali_(&a);
00353   hlimit_(&b);
00354   uginit_();
00355     
00356   if(fdebug) cout << " --->debug TFndProcessRec::InitRun(): 'gzcali_', 'hlimit_' and 'uginit_' called succesfully." << endl; 
00357 }  
00358 
00359 //_________________________________________________________
00360 void TFndProcessRec::SetZebini(){
00361   fZebini = (Zerbini_t *)dlsym(flib_handle,"zebini_");
00362   fLQ = &(fZebini->jinfo)-1;
00363   fIQ=fLQ+8;            // to get integer data
00364   fQ=(Float_t *)fIQ;    // to get integer data
00365   if(fdebug) cout << " ===>debug SetZebini(): fZebini address:" << fZebini << endl; 
00366 
00367 }
00368 //_________________________________________________________
00369 void TFndProcessRec::SetGcflag(){
00370   fGcflag = (Gcflag_t *)dlsym(flib_handle,"gcflag_");
00371 }
00372 
00373 
00374 //_________________________________________________________
00375 void TFndProcessRec::SetRuninf(){
00376   fRuninf = (Runinf_t *)dlsym(flib_handle,"runinf_");
00377 }
00378 
00379 //_______________________________________________________________
00380 void TFndProcessRec::SelectBhabhaInFidaRC(E_prec_Bhabha_Mode mode){
00381   // uncomment or comment the BABA line according to the requested mode
00382   // mode: TFndProcessRec::E_prec_Bhabha_Mode { E_SINGLE_HELIX=0, E_DOUBLE_HELIX=1 };
00383   
00384 
00385   if(mode < E_SINGLE_HELIX || mode > E_DOUBLE_HELIX ){
00386     FROOT::TerminateFroot(0,"Mode not accepted in TFndProcessRec::SelectBhabhaInFidaRC");
00387   }
00388   fCurBhabhaRecMode = mode;
00389 
00390   if(fdebug) {
00391     cout << " --->debug TFndProcessRec::SelectBhabhaInFidaRC(): entering method" << endl;
00392     cout << "     mode  = " << mode << endl;
00393   }  
00394   TString fnam = FROOT::ExpandPathName("$INP"); 
00395   fnam+="/fidarc.dat";
00396 
00397   if(fdebug) cout << " --->debug TFndProcessRec::SetFidaRC(): reading file: " << fnam << endl;
00398   Char_t file[200][200];
00399   
00400   FILE *f = fopen(fnam.Data(),"r");
00401   int l=0;
00402 
00403 
00404   Int_t IsCardFormatOk = kFALSE;
00405 
00406   while (fgets(file[l],200,f)) {    Char_t *line=file[l++];
00407     line[strlen(line)-1]='\0';
00408     if(fdebug) cout << "=======> original line: \"" << line << "\"" << endl;
00409    
00410     if(strncmp("C BABA",line,6)==0){
00411       cout << "Current mode is \"double-helix\"" << endl;
00412       if(mode == E_SINGLE_HELIX){
00413         //      line[0]='\0';
00414         //      strcat(line,"BABA");
00415         strcpy(line,"BABA");
00416         cout << "fidarc card switched to single-helix mode" << endl;
00417       }
00418       IsCardFormatOk = kTRUE;
00419     }
00420     else if(strncmp("BABA",line,4)==0){
00421       cout << "Current mode is \"single-helix\"" << endl;
00422       if(mode == E_DOUBLE_HELIX){
00423         //      line[0]='\0';
00424         //      strcat(line,"C BABA");
00425         strcpy(line,"C BABA");
00426         cout << "fidarc card switched to double-helix mode" << endl;
00427       }
00428       IsCardFormatOk = kTRUE;
00429     }
00430     
00431     if(fdebug) cout << "=======> line after check: \"" << line << "\"" << endl;
00432   }
00433   fclose(f);
00434   
00435   if(IsCardFormatOk == kFALSE){
00436     Error("SelectBhabhaInFidaRC","(\"BABA\" or \"C BABA\" is expected somewhere) check spaces and endline!");
00437     FROOT::TerminateFroot(0,"Card format not recognized in TFndProcessRec::SelectBhabhaInFidaRC" );
00438   }
00439   // --- up to here file has not been modified yet  
00440 
00441   if(fdebug) cout << " --->debug TFndProcessRec::SetFidaRC(): modifying file: " << fnam << endl; 
00442   f = fopen(fnam.Data(),"w");
00443   for (int n=0;n<l;n++) fprintf(f,"%s\n",file[n]);
00444   fclose(f); 
00445   if(fdebug) cout << " --->debug TFndProcessRec::SetFidaRC(): done!" << endl; 
00446   
00447 }
00448 
00449 //________________________________________________________
00450 void TFndProcessRec::SetFidaRC(Char_t *card, Char_t *option) {
00451   if(fdebug) {
00452     cout << " --->debug TFndProcessRec::SetFidaRC(): entering method" << endl;
00453     cout << "     card   = " << card << endl;
00454     cout << "     option = " << option << endl;
00455   }  
00456   Char_t fnam[200];
00457   strcpy(fnam,gSystem->Getenv("INP"));
00458   strcat(fnam,"/fidarc.dat");
00459   if(fdebug) cout << " --->debug TFndProcessRec::SetFidaRC(): reading file: " << fnam << endl;
00460   Char_t file[200][200];
00461   
00462   FILE *f = fopen(fnam,"r");
00463   int l=0;
00464   while (fgets(file[l],200,f)) {    Char_t *line=file[l++];
00465     line[strlen(line)-1]='\0';
00466     if (line[0]=='C') continue;
00467     
00468     int k=0;
00469     while (line[k]!=' ' && line[k]!='\0') k++;
00470     line[k]='\0';
00471     
00472     if (strcmp(card,line)==0) {
00473       strcat(line,"   ");
00474       strcat(line,option);
00475     }
00476     else line[k]=' ';
00477   }
00478   fclose(f);
00479 
00480   if(fdebug) cout << " --->debug TFndProcessRec::SetFidaRC(): modifying file: " << fnam << endl; 
00481   f = fopen(fnam,"w");
00482   for (int n=0;n<l;n++) fprintf(f,"%s\n",file[n]);
00483   fclose(f); 
00484   if(fdebug) cout << " --->debug TFndProcessRec::SetFidaRC(): done!" << endl; 
00485 
00486 }
00487 
00488 //_______________________________________________________________
00489 void TFndProcessRec::InitNewRun(const Char_t *typ, Int_t num, const Char_t *data_path, const Char_t *msql_db_host, Bool_t debug){
00490   // start new run processing (recycling the used zebra structure)
00491   // (read_lib method called to open new raw file)
00492 
00493   //--- Setting of $MSQL_DB_HOST
00494   if(fdebug) cout << " --->debug TFndProcessRec::InitNewRun(): entering method." << endl; 
00495 
00496   if (msql_db_host && *msql_db_host == '$')
00497     msql_db_host = gSystem->Getenv(msql_db_host + 1);
00498   
00499   gSystem->Setenv("MSQL_DB_HOST",msql_db_host);
00500   if(fdebug) cout << "Starting \"FINUDA froot<->rec_interface\": msql host is: " << gSystem->Getenv("MSQL_DB_HOST") << endl;
00501   
00502   //--- Setting of $RDT
00503   if (data_path && *data_path == '$')
00504     data_path = gSystem->Getenv(data_path + 1);
00505   
00506   gSystem->Setenv("RDT",data_path);
00507   if(fdebug) cout << "Starting \"FINUDA froot<->rec_interface\": raw data path is: " << gSystem->Getenv("RDT") << endl;
00508   
00509   // Real data
00510   fdebug = debug;
00511   fTyp = new TString(typ);
00512   fNum = num;
00513   fMsqlDbHostStr = new TString(msql_db_host);
00514   
00515   if(fdebug) cout << " --->debug TFndProcessRec::TFndProcessRec: "<< this->GetName() << " constructor called for Real data" << endl;
00516   CheckRawFile(); 
00517   
00518   TString *type_pass = new TString(fTyp->Data());
00519   type_pass->Prepend("'");
00520   type_pass->Append("'");
00521   
00522   if(fdebug) cout << " --->debug TFndProcessRec::TFndProcessRec: passing string " << (Char_t *)type_pass->Data() << " to 'SetFidaRC' method" << endl;
00523   
00524   SetFidaRC("TRUN",(Char_t *)type_pass->Data());  
00525   delete type_pass;
00526   Char_t opt[10];
00527   sprintf(opt,"%d",num);
00528   SetFidaRC("NRUN",opt);  
00529   
00530   // ---
00531   fMaxEv=100000000;
00532 
00533   Int_t ierr = 0;
00534   Int_t IOUT[9];
00535   if(fNum!=-1){
00536     //cout << "===============> " << fRawFileName << endl;
00537     fRawFileName->Resize(9);
00538     //  TString finopen_str = TString(fRawFileName->Data());
00539     TString finopen_str = FROOT::ExpandPathName("$RDT");
00540     finopen_str+= "/";
00541     finopen_str+= fRawFileName->Data();
00542     //  cout << "DEBUG: Initializing new run with: passing string \"" << finopen_str.Data() << "\"" << endl;
00543     fin_open_((char *)finopen_str.Data(), IOUT, &ierr);
00544     //    fin_open03_((char *)finopen_str.Data(), IOUT, &ierr);
00545   }
00546   else fin_open_("online", IOUT, &ierr);
00547   
00548   if(!fRuninf) SetRuninf(); // check it out
00549   for(Int_t i=0;i<9;i++) fRuninf->iout[i] = IOUT[i];
00550 
00551 }
00552 
00553 //_______________________________________________________________
00554 Int_t TFndProcessRec::UgEvent(){ 
00555   // Complete offline event processing (FORTRAN code called)
00556   // this method returns:
00557   //                     0 -> good event
00558   //                     1 -> run finished
00559 
00560   if(fdebug) cout << " --->debug TFndProcessRec::UgEvent(): entering method" << endl; 
00561   Int_t a=fZebini->ixdiv2;
00562   if(fdebug) cout << "----->UgEvent DEBUG1" << endl;  
00563   mzwipe_(&a);
00564   if(fdebug) cout << "----->UgEvent DEBUG2" << endl;  
00565   gtrigc_();
00566   if(fdebug) cout << "----->UgEvent DEBUG3" << endl;  
00567   gtrigi_();
00568   if(fdebug) cout << "----->UgEvent DEBUG4" << endl;  
00569   gutrev_();
00570   if(fdebug) cout << "----->UgEvent DEBUG5" << endl;
00571   
00572   if(fdebug) cout << " --->debug TFndProcessRec::UgEvent(): fortran called succesfully!" << endl;
00573   // zebra dst address assignment
00574   fJFDST=fZebini->jfdst;
00575   if(fdebug) cout << " ===>debug TFndProcessRec::fJFDST address: " << fJFDST << endl;
00576   
00577   
00578   if(fJFDST==0) {  // if 'fJFDST==0' run is finished or something is wrong
00579     if(fdebug)  cout << " ---> debug TFndProcessRec::UgEvent(): Run completed!" << endl << endl;
00580     return 1; // exit if run is finished
00581   }
00582   if(fdebug) cout << " --->debug TFndProcessRec::UgEvent(): event " <<  fIQ[fJFDST+2] << " procesed." << endl; 
00583   return 0;   
00584 }
00585 
00586 //_______________________________________________________________
00587 UInt_t *TFndProcessRec::GetRawEvPointer(){
00588   return (UInt_t *) ( get_current_raw_event_() );
00589 }
00590 
00591 //_______________________________________________________________
00592 /*
00593 Int_t TFndProcessRec::UgEvent(){
00594   // this method returns:
00595   //                     0 -> good event
00596   //                     1 -> run completed
00597 
00598   if(FillJFGES()) return 1; // exit if run completed
00599   if(Reconstruct()) return 1;
00600 
00601   return 0;
00602 }
00603 */
00604 
00605 //_______________________________________________________________
00606 Int_t TFndProcessRec::FillJFGES(){
00607   // Fill JFGES and evaluate detectors coordinates
00608   // without reconstructing the event
00609   // the event number (in fortran)
00610   // is automatically incremented by this method
00611   // this method returns:
00612   //                     0 -> good event
00613   //                     1 -> run completed
00614   //
00615   // see fidarc->gutrev
00616 
00617   if(fdebug) cout << " --->debug TFndProcessRec::FillJFGES(): entering method" << endl;
00618   //  cout << "DEBUG_FILLGES 1: Runinf address: " << fRuninf << endl;
00619 
00620   Int_t a=fZebini->ixdiv2;
00621   //  cout << "DEBUG_FILLGES 2: a = " << a << " --- fZebini = " << fZebini << endl;
00622   mzwipe_(&a);
00623   gtrigc_();
00624   gtrigi_();
00625 
00626   // --- GUTREV first part
00627   Int_t ierr = 0;
00628   rdtupk_(&ierr); // fill zebra GES
00629   if(ierr < 0) return 1; // run completed
00630 
00631   checktrig_(); // added into this code from fidarc-version 601 on
00632 
00633   //  consinit_(); // (from v521 on) initialize constant in fidarc
00634   //    consinit has been included into uginit from fidarc-version 601 on
00635 
00636   vrecon_();  // reconstruct vertex
00637   films_();   // needed by microstrips
00638   patstrw_(); // evaluate straw-tube triplets
00639   //  provatof_(); // (used by TOF group for dedicated analysis) 
00640   // ---
00641 
00642   fJINFO=fZebini->jinfo; // zebra info addresses assignment (event-zero information)
00643   fJFGES=fZebini->jfges; // zebra ges addresses assignment
00644   
00645   return 0;
00646   //return fGcflag->ieorun;
00647 } 
00648 
00649 //_______________________________________________________________
00650 Int_t TFndProcessRec::Reconstruct(){
00651   // reconstruct current event (FORTRAN code)
00652   // This method corresponds to the second part of GUTREV (fidarc fortran code)
00653   // NOTE: This method must be called only if FillJFGES()
00654   // was called previousely
00655   // this method returns:
00656   //                     0 -> good event
00657   //                     1 -> run completed
00658   //                    -1 -> problems
00659   //  
00660   //  COSM NOT IMPLEMENTED
00661   //  see fidarc->gutrev_() from "IF (HYPE) THEN" on [without rdtupk]
00662 
00663   fJFDST = 0;
00664   if(!fJFGES){
00665     Warning("Reconstruct","fJFGES not assigned.");
00666     return -1;
00667   }
00668   
00669   Int_t trig_type = fIQ[fJFGES+3];
00670   if(fdebug) cout << "trigger type: " << trig_type << endl;
00671 
00672   // the following code is the "translation" of the GUTREV fortran routine
00673   switch(trig_type){
00674   case 1: // HYPE
00675     genrec_();
00676     trkfit_();
00677 #ifdef FIDA_USE_SHORT
00678     ktrkvert_(); // from fida-version 603 on
00679     vertfit_();
00680 #endif
00681 #ifdef FIDA_USE_KALMAN
00682     kalmanfit_();
00683 #endif
00684     neutfind_();
00685     break;
00686   case 2: // BHABHA
00687     if(fCurBhabhaRecMode == E_DOUBLE_HELIX){
00688       bhabharc_();
00689       bhatrkfit_();
00690     }
00691     else if(fCurBhabhaRecMode == E_SINGLE_HELIX){
00692       babarc_();
00693       babafit_();
00694     }
00695     break;
00696   case 3: // COSM
00697     Warning("Reconstruct()","COSM reconstruction not implemented");
00698     return 0;
00699   case 11: // HYPE && BHABHA
00700     genrec_();
00701     trkfit_();
00702 #ifdef FIDA_USE_SHORT
00703     ktrkvert_(); // from fida-version 603 on
00704     vertfit_();
00705 #endif
00706 #ifdef FIDA_USE_KALMAN
00707     kalmanfit_();
00708 #endif
00709     neutfind_();
00710     break;
00711   case 21:
00712     Warning("Reconstruct()","MONTECARLO reconstruction not implemented");
00713     return 0;
00714   default: return 0;
00715 
00716   }
00717 
00718   fJFDST=fZebini->jfdst;  // zebra dst addresses assignment
00719 
00720   if(fdebug) cout << " ===>debug TFndProcessRec::fJFDST address: " << fJFDST << endl;
00721   if(fJFDST==0) {  // if 'fJFDST==0' run is finished or something is wrong
00722     if(fdebug)  cout << " ---> debug TFndProcessRec::Reconstruct(): Run completed!" << endl << endl;
00723     return 1; // exit if run is finished
00724   }
00725   if(fdebug) cout << " --->debug TFndProcessRec::Reconstruct(): event " <<  fIQ[fJFDST+2] << " procesed." << endl; 
00726   return 0;   
00727 
00728 } 
00729 
00730 //_______________________________________________________________
00731 void TFndProcessRec::CloseRun(Bool_t last) {
00732   // Close raw file (read_lib method called)
00733   // Perform FORTRAN close operation (uglast/zebra reset) if last is true
00734   // Should be called with "last=true" before calling CloseInterface()
00735 
00736   if(fdebug) cout << "TFndProcessRec::CloseRun(); Closing raw file..." << endl;
00737   if(!last){
00738     if(fdebug) cout << "--> TFndProcessRec::CloseRun() DEBUG 1" << endl;
00739     Int_t r_tim = fIQ[fJFGES+4];
00740     if(!r_tim) r_tim = fIQ[fJFDST+4];
00741     if(fdebug) cout << "Run-time is: " << r_tim <<  endl;
00742     if(!r_tim) return;
00743     if(r_tim <= FROOT::DTak_2006_SftwStartTime) fin_close03_(); 
00744     else fin_close_();
00745 
00746     if(fdebug) cout << "TFndProcessRec::CloseRun(); raw file closed: Runinf address: " << fRuninf << endl;
00747   }
00748   else{
00749     if(fdebug) cout << "--> TFndProcessRec::CloseRun() DEBUG 2" << endl;
00750     uglast_();
00751     if(fdebug) cout << "--> TFndProcessRec::CloseRun() DEBUG 3" << endl;
00752     Int_t a;
00753     a = fZebini->ixdiv1;   mzwipe_(&a);
00754     if(fdebug) cout << "--> TFndProcessRec::CloseRun() DEBUG 4" << endl;
00755     a = fZebini->ixdiv2;   mzwipe_(&a);
00756     if(fdebug) cout << "--> TFndProcessRec::CloseRun() DEBUG 5" << endl;
00757     a = fZebini->ixdiv3;   mzwipe_(&a);
00758     if(fdebug) cout << "--> TFndProcessRec::CloseRun() DEBUG 6" << endl;
00759   }
00760   CleanRecOutputs(kTRUE,kTRUE,kTRUE);
00761 }
00762 
00763 //___________________________________
00764 Int_t TFndProcessRec::CloseInterface(){
00765   // close fida*.so
00766   // Should be called before calling dtor
00767   // return value: exit code of the "dlclose" function
00768 
00769 
00770   Int_t dlclose_err = dlclose(flib_handle);
00771   if(fdebug) cout << "dlclose output: " << dlclose_err << endl;
00772   return dlclose_err;
00773 }
00774 
00775 //_________________________________________________________
00776 Bool_t TFndProcessRec::GetStatusBit(Int_t l, Int_t k) {
00777   // this function returns the value of the bit 'k' of the bank 'l'
00778   // (grab bit number "k" from the status word of bank "l")
00779   // range for "k": 1-2-3-4-5-...
00780 
00781   if(k<=0){
00782     Error("GetStatusBit","bit number must be >0 (%d received)",k);
00783     FROOT::TerminateFroot();
00784     return 0;
00785   }
00786 
00787   if (fJFDST==0) return 0;
00788   else return (Bool_t)(fIQ[l]&((Int_t)TMath::Power(2,k-1)));
00789 }
00790 
00791 //___________________________________________________________
00792 void TFndProcessRec::PrintZebiniContent(){
00793   if(fZebini){
00794     cout << "fZebini->ixdst: " << fZebini->ixdst << "   at address: " << &(fZebini->ixdst) << endl;
00795     cout << "fZebini->ixdiv1: " << fZebini->ixdiv1 << "   at address: " << &(fZebini->ixdiv1) << endl;
00796     cout << "fZebini->ixdiv2: " << fZebini->ixdiv2 << "   at address: " << &(fZebini->ixdiv2) << endl;
00797     cout << "fZebini->ixdiv3: " << fZebini->ixdiv3 << "   at address: " << &(fZebini->ixdiv3) << endl;
00798     for(Int_t i=0;i<16;i++)
00799       cout << "fZebini->fence[" <<i << "]: " << fZebini->fence[i] << "   at address: " << &(fZebini->fence[i]) << endl;
00800     cout << "fZebini->jinfo: " << fZebini->jinfo << "   at address: " << &(fZebini->jinfo) << endl;
00801     cout << "fZebini->jfges: " << fZebini->jfges << "   at address: " << &(fZebini->jfges) << endl;
00802     cout << "fZebini->jmstr: " << fZebini->jmstr << "   at address: " << &(fZebini->jmstr) << endl;
00803     cout << "fZebini->jstrw: " << fZebini->jstrw << "   at address: " << &(fZebini->jstrw) << endl;
00804     cout << "fZebini->jfdst: " << fZebini->jfdst << "   at address: " << &(fZebini->jfdst) << endl;
00805   }
00806   else cout << "No zebini defined!!!" << endl;
00807 }
00808 
00809 //___________________________________________________________
00810 void TFndProcessRec::PrintGcflagContent(){
00811   if(fGcflag){
00812     cout << "fGcflag->idebug ===> " << fGcflag->idebug << "   at address: " << &(fGcflag->idebug) << endl;
00813     cout << "fGcflag->idemin ===> " << fGcflag->idemin << "   at address: " << &(fGcflag->idemin) << endl;
00814     cout << "fGcflag->idemax ===> " << fGcflag->idemax << "   at address: " << &(fGcflag->idemax) << endl;
00815     cout << "fGcflag->itest ====> " << fGcflag->itest << "   at address: " << &(fGcflag->itest) << endl;
00816     cout << "fGcflag->idrun ====> " << fGcflag->idrun << "   at address: " << &(fGcflag->idrun) << endl;
00817     cout << "fGcflag->idevt ====> " << fGcflag->idevt << "   at address: " << &(fGcflag->idevt) << endl;
00818     cout << "fGcflag->ieorun ===> " << fGcflag->ieorun << "   at address: " << &(fGcflag->ieorun) << endl;
00819     cout << "fGcflag->ieotri ===> " << fGcflag->ieotri << "   at address: " << &(fGcflag->ieotri) << endl;
00820     cout << "fGcflag->ievent ===> " << fGcflag->ievent << "   at address: " << &(fGcflag->ievent) << endl;
00821     for(Int_t i=0;i<10;i++)
00822       cout << "fGcflag->iswit " << i << " ==> " << fGcflag->iswit[i] << "   at address: " << &(fGcflag->iswit[i]) << endl;
00823     for(Int_t i=0;i<20;i++)
00824       cout << "fGcflag->ifinit " << i << " => " << fGcflag->ifinit[i] << "   at address: " << &(fGcflag->ifinit[i]) << endl;
00825     cout << "fGcflag->nevent ===> " << fGcflag->nevent << "   at address: " << &(fGcflag->nevent) << endl;
00826     for(Int_t i=0;i<2;i++)
00827       cout << "fGcflag->nrndm " << i << " ==> " << fGcflag->nrndm[i] << "   at address: " << &(fGcflag->nrndm[i]) << endl;
00828   }
00829   else cout << "No gcflag defined!!!" << endl;
00830 }
00831 
00832 //___________________________________________________________
00833 void TFndProcessRec::CleanRecOutputs(Bool_t out,Bool_t his,Bool_t dst){
00834 
00835   Printf("TFndProcessRec::CleanRecOutputs ---> Cleaning reconstruction outputs.");
00836   TString dest_cmd_out;
00837   TString dest_cmd_his;
00838   TString dest_cmd_dst;
00839   
00840   dest_cmd_out.Form("rm -f %s/*.lis", FROOT::ExpandPathName("$REC_OUTPUTS/out").Data() );
00841   dest_cmd_his.Form("rm -f %s/*.rzf", FROOT::ExpandPathName("$REC_OUTPUTS/histos").Data() );
00842   dest_cmd_dst.Form("rm -f %s/*.dat", FROOT::ExpandPathName("$REC_OUTPUTS/dstapes").Data() );
00843 
00844   if(out){
00845     Printf(" ---> Sending command \"%s\"",dest_cmd_out.Data());
00846     gSystem->Exec(dest_cmd_out.Data());
00847   }
00848   if(his){
00849     Printf(" ---> Sending command \"%s\"",dest_cmd_his.Data());
00850     gSystem->Exec(dest_cmd_his.Data());
00851   }
00852   if(dst){
00853     Printf(" ---> Sending command \"%s\"",dest_cmd_dst.Data());
00854     gSystem->Exec(dest_cmd_dst.Data());
00855   }
00856 
00857 
00858   Printf("TFndProcessRec::CleanRecOutputs ---> Reconstruction outputs cleaned.");
00859 }
00860 
00861 // ---------- EXAMPLE methods -----------
00862 //___________________________________________________________
00863 void TFndProcessRec::AutoProcessRun() {
00864   // This method must not be used in froot: is just an example
00865   fBhaFlag  = kFALSE;
00866   fHypeFlag = kFALSE;
00867   fCosmFlag = kFALSE;
00868 
00869   Int_t nev=0;
00870   if(fdebug) cout << " --->debug ProcessRun(): beginning events loop." << endl; 
00871   
00872   Int_t end_of_run=0;
00873   while(end_of_run==0 && nev<fMaxEv){
00874     if(nev==fMaxEv) cout << "Max number of events reached:" << endl;
00875     nev++;
00876     cout << "Start processing event " << nev << endl;
00877     Int_t a=fZebini->ixdiv2;
00878     mzwipe_(&a);
00879     gtrigc_();
00880     gtrigi_();
00881     gutrev_();
00882     //---------------------------
00883     fJFDST=fZebini->jfdst;
00884  
00885     if(fdebug) cout << " ===>debug ProcessRun():fJFDST = " << fJFDST << endl;
00886     if (fJFDST==0) {
00887       cout << "fJFDST not assigned to anything!!! exiting from loop" << endl;
00888       end_of_run = 1;
00889     }
00890     // here I begin to read zebra dst-bank:
00891     // reading run number and event number (using fJFDST)
00892     cout << "run number: " << fIQ[fJFDST+1]<< endl;
00893     cout << "ev. number: " << fIQ[fJFDST+2]<< endl;
00894     Int_t trig_type = fIQ[fJFDST+3];
00895     cout << "trigger type: " << trig_type << endl;
00896     /*
00897       Values of trigger bit:
00898        1 ---> Hypernuclear trigger
00899        2 ---> Bhabha Trigger
00900        3 ---> Cosmic ray trigger
00901       11 ---> Both HYP and BHA bits on (priority to HYP trigger)
00902       21 ---> Single track (only MC)
00903     */
00904     switch (trig_type) {
00905     case 1:
00906       cout << " -> trigger: HYP" << endl;
00907       end_of_run = GetHypeDst();
00908       break;
00909     case 2:
00910       cout << " -> trigger: BHA" << endl;
00911       end_of_run = GetBabaDst();
00912       //end_of_run = GetBhabhaDst();
00913       break;
00914     case 3:
00915       cout << " -> trigger: COSM" << endl;
00916       end_of_run = GetCosmDst();
00917       break;
00918     case 11:
00919       cout << " -> double trigger: HYP & BHA (reading HYPE bank)" << endl;
00920       end_of_run = GetHypeDst();
00921       break;
00922     case 21:
00923       cout << " -> Single track (Montecarlo only)" << endl;
00924       end_of_run = 1;
00925       break;
00926     default: 
00927       cout << "unknown trigger bit value!!!" << endl;
00928     }
00929 
00930     if(end_of_run) cout << " This event doesn't exist: run is finished." << endl;
00931   }
00932   if(fdebug) cout << " --->debug ProcessRun(): events loop completed" << endl; 
00933   cout << "Processing completed." << endl; 
00934 
00935   // Drawing histos...
00936   TFile *OutRootFile = new TFile("Autoprocess_histos.root","RECREATE");
00937   //--
00938   if(fHypeFlag){
00939     TCanvas *hype_canv = new TCanvas("hype_canv","hype canvas",20,20,800,800);
00940     hype_canv->Divide(2,2);
00941     hype_canv->cd(1);
00942     fHyp_K_min_xy_vert_histo->Draw();
00943     fHyp_K_min_xy_vert_histo->Write();
00944     hype_canv->cd(2);
00945     fHyp_K_min_z_vert_histo->Draw();
00946     fHyp_K_min_z_vert_histo->Write();
00947     hype_canv->cd(3);
00948     fHyp_K_min_mom_neg_trk->Draw();
00949     fHyp_K_min_mom_neg_trk->Write();
00950     hype_canv->cd(4);
00951     fHyp_K_min_mom_pos_trk->Draw();
00952     fHyp_K_min_mom_pos_trk->Write();
00953 
00954     cout << fcount_k_min << " Hypernuclear events ; " << fcount_k_min_inside << " stopped in target (" << 100 * ((Float_t)fcount_k_min_inside / (Float_t)fcount_k_min) << "%)" << endl;
00955   }
00956   //--
00957   if(fBhaFlag){
00958     TCanvas *bhabha_canv = new TCanvas("bhabha_canv","bhabha canvas",40,40,1000,500);
00959     bhabha_canv->Divide(2,1);
00960     bhabha_canv->cd(1);
00961     fBABA_mom_patt_histo->Draw();
00962     bhabha_canv->cd(2);
00963     fBABA_mom_fit_histo->Draw();
00964     cout << fcount_BABA << " Bhabha events ; " << fcount_BABA_OK << " fitted events (" << 100 * ((Float_t)fcount_BABA_OK / (Float_t)fcount_BABA) << "%)" << endl;
00965   }
00966   //--
00967   if(fCosmFlag){
00968     TCanvas *cosm_canv = new TCanvas("cosm_canv","cosm canvas",60,60,900,300);
00969     cosm_canv->Divide(3,1);
00970     cosm_canv->cd(1);
00971     fCOSM_mom_patt_histo->Draw();
00972     cosm_canv->cd(2);
00973     fCOSM_mom_fit_histo->Draw();
00974     cosm_canv->cd(3);
00975     fCosm_SignOfCharge_histo->Draw();
00976    
00977     cout << fcount_COSM << " Cosmic events ; " << fcount_COSM_OK << " fitted events (" << 100 * ((Float_t)fcount_COSM_OK / (Float_t)fcount_COSM) << "%)" << endl;
00978   }
00979   //--
00980   OutRootFile->Close();
00981 }
00982 
00983 //_____________________________
00984 Int_t TFndProcessRec::GetHypeDst() {
00985   // This method must not be used in froot: is just an example
00986   // ---> k- bank access
00987   if(fJFDST==0) { cout << "no fJFDST!!!" << endl; return 1; }
00988   
00989   if(fHypeFlag==kFALSE){ // Declare histos only the first time
00990     fHyp_K_min_xy_vert_histo = new TH2F("K_min_xy_vert_histo","K- vertex: x-y coordinates",200,-10,10,200,-10,10);
00991     fHyp_K_min_z_vert_histo = new TH1F("K_min_z_vert_histo","K- vertex: z coordinate",200,-10,10);
00992     fHyp_K_min_mom_neg_trk = new TH1F("fHyp_K_min_mom_neg_trk","K- negative trk: momentum at vertex",1400,0,0.7);
00993     fHyp_K_min_mom_pos_trk = new TH1F("fHyp_K_min_mom_pos_trk","K- positive trk: momentum at vertex",1000,0,2);
00994     fcount_k_min = 0;
00995     fcount_k_min_inside = 0;
00996     fHypeFlag=kTRUE;
00997   }
00998   fcount_k_min++;
00999   Int_t LKMIN = fLQ[fJFDST-1];
01000   Int_t Interact_inside = GetStatusBit(LKMIN,1); // 1==>Interaction inside the target
01001   if (LKMIN)  {         
01002     //cout << "LKMIN offset= " << LKMIN << endl;
01003     cout << "vertex ======> " << fQ[LKMIN+5] << " - " << fQ[LKMIN+6] << " - "<< fQ[LKMIN+7] << endl;
01004     fHyp_K_min_xy_vert_histo->Fill(fQ[LKMIN+5],fQ[LKMIN+6]);  
01005     fHyp_K_min_z_vert_histo->Fill(fQ[LKMIN+7]); 
01006     // K- negative track bank access:
01007     Int_t LKMIN_NEGT = fLQ[LKMIN-3];
01008     if(LKMIN_NEGT){
01009       Int_t fit_err_code = fIQ[LKMIN_NEGT+7];
01010       if(fit_err_code==0 && Interact_inside==1){
01011         fHyp_K_min_mom_neg_trk->Fill(fQ[LKMIN_NEGT+8]);
01012         fcount_k_min_inside++;
01013       }
01014     }
01015     // K- positive track bank access:
01016     Int_t LKMIN_POST = fLQ[LKMIN-4];
01017     if(LKMIN_POST){
01018       Int_t fit_err_code = fIQ[LKMIN_POST+7];
01019       if(fit_err_code==0 && Interact_inside==1)
01020         fHyp_K_min_mom_pos_trk->Fill(fQ[LKMIN_POST+8]);  
01021     }
01022   }
01023   cout << " - - - - - - - " << endl << endl;
01024   return 0; // return '0' if event is exists
01025 }
01026 
01027 //_____________________________
01028 Int_t TFndProcessRec::GetBabaDst() {
01029   // This method must not be used in froot: is just an example
01030   // baba bank access
01031   // Shows reconstructed momentum for Bhabha events (simplified routine)
01032   
01033   if(fJFDST==0) { cout << "no fJFDST!!!" << endl; return 1; }
01034   
01035   if(fBhaFlag==kFALSE){ // Declare histos only the first time
01036     fBABA_mom_patt_histo = new TH1F("fBABA_mom_patt_histo","BABA bank: momentum from pattern recognition",1000,0,1);
01037     fBABA_mom_fit_histo = new TH1F("fBABA_mom_fit_histo","BABA bank: momentum from fit",1000,0,1);
01038     fcount_BABA=0;
01039     fcount_BABA_OK=0;
01040     fBhaFlag=kTRUE;
01041   }
01042   fcount_BABA++;
01043   Int_t Fbaba = fLQ[fJFDST-1];
01044   if(Fbaba){
01045     Int_t FitOk = GetStatusBit(Fbaba,1);
01046     if(FitOk){
01047       fBABA_mom_patt_histo->Fill(fQ[Fbaba+7]);
01048       fBABA_mom_fit_histo->Fill(fQ[Fbaba+10]);
01049       fcount_BABA_OK++;
01050     }    
01051   }   
01052   
01053   cout << " - - - - - - - " << endl << endl;
01054   return 0; // return '0' if event is exists
01055 }
01056 
01057 //_____________________________
01058 Int_t TFndProcessRec::GetBhabhaDst() {
01059   // This method must not be used in froot: is just an example
01060   // bhabha bank access
01061 
01062   if(fJFDST==0) { cout << "no fJFDST!!!" << endl; return 1; }
01063 
01064 
01065   cout << " - - - - - - - " << endl << endl;
01066   return 0; // return '0' if event is exists
01067 }
01068 
01069 //_____________________________
01070 Int_t TFndProcessRec::GetCosmDst() { // B>0
01071   // This method must not be used in froot: is just an example
01072   if(fJFDST==0)  { cout << "no fJFDST!!!" << endl; return 1; }
01073   
01074   if(fCosmFlag==kFALSE){ // Declare histos only the first time
01075     fCosm_SignOfCharge_histo = new TH1F("fCosm_SignOfCharge_histo","Cosmic DST: Sign of charge Histogram",3,-1,1);
01076     fCOSM_mom_patt_histo = new TH1F("fCOSM_mom_patt_histo","COSM bank: momentum from pattern recognition",100,0,6);
01077     fCOSM_mom_fit_histo = new TH1F("fCOSM_mom_fit_histo","COSM bank: momentum from fit",100,0,6);
01078     fcount_COSM=0;
01079     fcount_COSM_OK=0;
01080     fCosmFlag=kTRUE;
01081   }
01082   fcount_COSM++;
01083   Int_t Fcosm = fLQ[fJFDST-1];
01084   if(Fcosm){
01085     Int_t Fit_OK = GetStatusBit(Fcosm,1);
01086     if(Fit_OK==0){
01087       fCosm_SignOfCharge_histo->Fill(fIQ[Fcosm+1]);
01088       fCOSM_mom_patt_histo->Fill(fQ[Fcosm+10]);
01089       fCOSM_mom_fit_histo->Fill(fQ[Fcosm+11]);
01090       fcount_COSM_OK++;      
01091     }
01092   }
01093   cout << " - - - - - - - " << endl << endl;
01094   return 0; // return '0' if event is exists
01095 }

Generated on Tue Oct 16 15:40:47 2007 by  doxygen 1.5.2