PREAN/TFndPrean.h

00001 // @(#)fROOT/PREAN:$Name:  $:$Id: TFndPrean.h,v 1.59 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 
00004 #ifndef FROOT_TFndPrean
00005 #define FROOT_TFndPrean
00006 
00007 #include <Riostream.h>
00008 #include <TObject.h>
00009 #include <TString.h>
00010 #include "TDatime.h"
00011 #include "TTree.h"
00012 #include "TFile.h"
00013 #include <TThread.h>
00014 
00015 #include "TClonesArray.h"
00016 
00017 #include "TFndTrack.h" // this includes FROOT.h and FIN_PHYS.h
00018 #include "TFndProcessRec.h" // this includes FROOT.h
00019 
00020 //#define FndPrean_CheckForDaqRunning
00021 
00022 using namespace FROOT;
00023 using namespace FIN_PHYS;
00024 
00025 class TFndPrean: public TObject
00026 {
00027 
00028  public:
00029   
00030   enum E_Scaler_Inhibit_Status {
00031     E_Scal_Inhib_No  = 0,
00032     E_Scal_Inhib_Inj = 1,
00033     E_Scal_Inhib_All = 2,
00034     E_Scal_Inhib_End = 3 // used for arrays (forced while creating branches)
00035   };
00036   
00037   TString GetScalInhibitStatusName(Int_t which,Bool_t isname)
00038     {
00039       E_Scaler_Inhibit_Status wh = (E_Scaler_Inhibit_Status) which;
00040       switch(wh){
00041       case E_Scal_Inhib_No:  return (isname)? "no_inhib"  : "no inhib.";
00042       case E_Scal_Inhib_Inj: return (isname)? "inj_inhib" : "inj inhib.";
00043       case E_Scal_Inhib_All: return (isname)? "all_inhib" : "all inhib.";
00044       default:  
00045         Warning("GetScalInhibitStatusName","Status not available ()",which);
00046         return "";
00047       }
00048     }
00049   
00050   enum E_Kaon_StopCode {
00051     E_Kaon_Stop_Target = 0,
00052     E_Kaon_Stop_Isim = 1,
00053     E_Kaon_Stop_Glass = 2,
00054     E_Kaon_Stop_Upilex = 3,
00055     E_Kaon_Stop_Osim = 4,
00056     E_Kaon_Stop_Other = 5,
00057   };
00058   
00059   enum E_Count_id{ // id used by counters (#trig / #analyzed / #patt.rec / #rec /#cut)
00060     E_count_trigger = 0,
00061     E_count_analyze = 1,
00062     E_count_pat_rec = 2,
00063     E_count_reconst = 3,    
00064     E_count_rec_sel = 4, // in case of new entries remember to correct data-members
00065   };
00066 
00067 protected:
00068 
00069 
00070   // --- folowing enums could be moved into FROOT.h
00071   enum E_Fnd_Scal_01_Descr{ // index of the "single-scaler" array (mod 0-1)
00072     E_FndScal_01_Desc_M27_HYP      = 0,
00073     E_FndScal_01_Desc_M27_BHA      = 1,
00074     E_FndScal_01_Desc_BTB_11       = 2,
00075     E_FndScal_01_Desc_BTB_EL       = 3,
00076     E_FndScal_01_Desc_PC           = 4, // prompt-coincidence
00077     E_FndScal_01_Desc_Presc_BTB_MB = 5,
00078     E_FndScal_01_Desc_OR_MB        = 6,
00079     E_FndScal_01_Desc_OR_EL        = 7,
00080     E_FndScal_01_Desc_HYP          = 8,
00081     E_FndScal_01_Desc_BHA          = 9,
00082     E_FndScal_01_Desc_Presc_BHA    = 10,
00083     E_FndScal_01_Desc_Presc_BTB_EL = 11,
00084     E_FndScal_01_Desc_OR_TOFO      = 12,
00085     E_FndScal_01_Desc_Presc_OR_MB  = 13,
00086     E_FndScal_01_Desc_TotTrig      = 14,
00087     E_FndScal_01_Desc_Time         = 15, // (100 Hz)   
00088     E_FndScal_01_Desc_End          = 16
00089   };
00090   
00091   enum E_Fnd_Scal_23_Descr{ // index of the "single-scaler" array (mod 2-3)
00092     E_FndScal_23_Desc_HYP          = 0,
00093     E_FndScal_23_Desc_BHA          = 1,
00094     E_FndScal_23_Desc_Presc_OR_EL  = 2,
00095     E_FndScal_23_Desc_BTB_EL       = 3,
00096     E_FndScal_23_Desc_OR_TOFO      = 4,
00097     E_FndScal_23_Desc_LASER        = 5,
00098     E_FndScal_23_Desc_OR_TOFI      = 6,
00099     E_FndScal_23_Desc_SC           = 7, // slow coincidence
00100     E_FndScal_23_Desc_BTB_MB       = 8,
00101     E_FndScal_23_Desc_ORtofiORtofo = 9, 
00102     E_FndScal_23_Desc_ORelORtofo   = 10,
00103     E_FndScal_23_Desc_void1        = 11,// slow coincidence
00104     E_FndScal_23_Desc_void2        = 12,// slow coincidence
00105     E_FndScal_23_Desc_RF           = 13, // RF over 4
00106     E_FndScal_23_Desc_Trig_Busy    = 14,
00107     E_FndScal_23_Desc_Time         = 15, // (100 Hz)  
00108     E_FndScal_23_Desc_End          = 16,
00109   };
00110 
00111   enum E_Fnd_Scal_4_Descr{ // index of the "single-scaler" array (mod 4)
00112     E_FndScal_4_Desc_TOFI_01       = 0,
00113     E_FndScal_4_Desc_TOFI_02       = 1,
00114     E_FndScal_4_Desc_TOFI_03       = 2,
00115     E_FndScal_4_Desc_TOFI_04       = 3,
00116     E_FndScal_4_Desc_TOFI_05       = 4,
00117     E_FndScal_4_Desc_TOFI_06       = 5,
00118     E_FndScal_4_Desc_TOFI_07       = 6,
00119     E_FndScal_4_Desc_TOFI_08       = 7,
00120     E_FndScal_4_Desc_TOFI_09       = 8,
00121     E_FndScal_4_Desc_TOFI_10       = 9,
00122     E_FndScal_4_Desc_TOFI_11       = 10,
00123     E_FndScal_4_Desc_TOFI_12       = 11,
00124     E_FndScal_4_Desc_End           = 12,
00125   };
00126   
00127   TString GetScal_01_DescName(Int_t bit)
00128     {
00129       // bit: 0,...,15
00130       E_Fnd_Scal_01_Descr desc = (E_Fnd_Scal_01_Descr)(bit);
00131       switch(desc){
00132       case E_FndScal_01_Desc_M27_HYP:      return "Mul 2-7 (HYP).";
00133       case E_FndScal_01_Desc_M27_BHA:      return "Mul 2-7 (BHA).";
00134       case E_FndScal_01_Desc_BTB_11:       return "BTB 1-1.......";
00135       case E_FndScal_01_Desc_BTB_EL:       return "BTB EL........";
00136       case E_FndScal_01_Desc_PC:           return "Prompt Coinc. ";
00137       case E_FndScal_01_Desc_Presc_BTB_MB: return "Presc. BTB MB.";
00138       case E_FndScal_01_Desc_OR_MB:        return "OR TOFINO (MB)";
00139       case E_FndScal_01_Desc_OR_EL:        return "OR TOFINO (EL)";
00140       case E_FndScal_01_Desc_HYP:          return "HYP...........";
00141       case E_FndScal_01_Desc_BHA:          return "BHA...........";
00142       case E_FndScal_01_Desc_Presc_BHA:    return "Presc BHA.....";
00143       case E_FndScal_01_Desc_Presc_BTB_EL: return "Presc BTB EL..";
00144       case E_FndScal_01_Desc_OR_TOFO:      return "OR TOFONE.....";
00145       case E_FndScal_01_Desc_Presc_OR_MB:  return "Presc OR MB...";
00146       case E_FndScal_01_Desc_TotTrig:      return "Total Triggers";
00147       case E_FndScal_01_Desc_Time:         return "Time..........";
00148       default :
00149         Error("GetScal_01_DescName","Scalers bit %d not available",bit);
00150         return "";
00151       }
00152     }
00153 
00154   TString GetScal_23_DescName(Int_t bit)
00155     {
00156       // bit: 0,...,15
00157       E_Fnd_Scal_23_Descr desc = (E_Fnd_Scal_23_Descr)(bit);
00158       switch(desc){
00159       case E_FndScal_23_Desc_HYP:          return "HYP..............";
00160       case E_FndScal_23_Desc_BHA:          return "BHA..............";
00161       case E_FndScal_23_Desc_Presc_OR_EL:  return "Presc OR-EL......";
00162       case E_FndScal_23_Desc_BTB_EL:       return "BTB-EL...........";
00163       case E_FndScal_23_Desc_OR_TOFO:      return "OR-TOFONE........";
00164       case E_FndScal_23_Desc_LASER:        return "LASER............";
00165       case E_FndScal_23_Desc_OR_TOFI:      return "OR-TOFINO.(MB)..."; // low-threshold
00166       case E_FndScal_23_Desc_SC:           return "Slow Coinc. .....";
00167       case E_FndScal_23_Desc_BTB_MB:       return "BTB-MB...........";
00168       case E_FndScal_23_Desc_ORtofiORtofo: return "ORtofino*ORtofone";
00169       case E_FndScal_23_Desc_ORelORtofo:   return "OR-EL*ORtofone...";
00170       case E_FndScal_23_Desc_void1:        return "(void)...........";
00171       case E_FndScal_23_Desc_void2:        return "(void)...........";
00172       case E_FndScal_23_Desc_RF:           return "RF/4.............";
00173       case E_FndScal_23_Desc_Trig_Busy:    return "Trig*busy........";
00174       case E_FndScal_23_Desc_Time:         return "Time.............";
00175       default :
00176         Error("GetScal_23_DescName","Scalers bit %d not available",bit);
00177         return "";
00178       }
00179     }
00180 
00181   TString GetScal_4_DescName(Int_t bit)
00182     {
00183       // bit: 0,...,11
00184       E_Fnd_Scal_4_Descr desc = (E_Fnd_Scal_4_Descr)(bit);
00185       switch(desc){
00186       case E_FndScal_4_Desc_TOFI_01:  return "TOFINO-01";
00187       case E_FndScal_4_Desc_TOFI_02:  return "TOFINO-02";
00188       case E_FndScal_4_Desc_TOFI_03:  return "TOFINO-03";
00189       case E_FndScal_4_Desc_TOFI_04:  return "TOFINO-04";
00190       case E_FndScal_4_Desc_TOFI_05:  return "TOFINO-05";
00191       case E_FndScal_4_Desc_TOFI_06:  return "TOFINO-06";
00192       case E_FndScal_4_Desc_TOFI_07:  return "TOFINO-07";
00193       case E_FndScal_4_Desc_TOFI_08:  return "TOFINO-08";
00194       case E_FndScal_4_Desc_TOFI_09:  return "TOFINO-09";
00195       case E_FndScal_4_Desc_TOFI_10:  return "TOFINO-10";
00196       case E_FndScal_4_Desc_TOFI_11:  return "TOFINO-11";
00197       case E_FndScal_4_Desc_TOFI_12:  return "TOFINO-12";
00198       default :
00199         Error("GetScal_4_DescName","Scalers bit %d not available",bit);
00200         return "";
00201       }
00202     }
00203   // ---
00204   
00205   Int_t  fDebugLev;  // can be 0-1-2 (default is 'zero')
00206   Bool_t fIsOnline;  // True in online mode
00207 
00208   ofstream *fCurLogFile; 
00209 
00210   Int_t fTrkStream; // store streamer version for loaded TFndTrack
00211 
00212   // -----
00213   TTree *fScalTree;  // tree filled with the content of scalers (raw-data)
00214   TTree *fGesTree;   // tree filled from the content of JFGES zebra bank (before event-reconstruction)
00215   TTree *fBabaTree;  // tree filled by baba reconstruction process (single helix reconstruction)
00216   TTree *fBhabhaTree; // tree filled by bhabha reconstruction process (double helix reconstruction)
00217   TTree *fHypeTree;   // tree filled by hype reconstruction process (full reconstruction)
00218 
00219   // ----- scalers reading (used to evaluate rates) -----
00220   //  temporary buffers (containing the whole information)
00221   UInt_t fScal0[E_FndScal_01_Desc_End]; // scaler number 0 (injection inhibit)
00222   UInt_t fScal1[E_FndScal_01_Desc_End]; // scaler number 1 (inhibit)
00223   UInt_t fScal2[E_FndScal_23_Desc_End]; // scaler number 2 (no inhibit)
00224   UInt_t fScal3[E_FndScal_23_Desc_End]; // scaler number 3 (inhibit)
00225   UInt_t fScal4[E_FndScal_4_Desc_End];  // scaler number 4 (TOFINO rates)
00226 
00227   // data-members for scaler tree
00228   Int_t fScalEvNum; // event number used by the scaler tree
00229   Int_t fScal_Time[E_Scal_Inhib_End]; // real-time (must be used for rates evaluation)
00230   Int_t fScal_HYP[E_Scal_Inhib_End];  // number of HYPE triggers
00231   Int_t fScal_BHA[E_Scal_Inhib_End];  // number of BHABHA triggers
00232   Int_t fScal_ORtofino_MB[E_Scal_Inhib_End]; // number of low-th OR-tofino triggers
00233   Int_t fScal_ORtofone[E_Scal_Inhib_End]; // number of OR-tofone triggers
00234 
00235   // --- GES content
00236   Int_t fGesEvNum;     // data-part [2]
00237   Int_t fGesTrigType;  // data-part [3]
00238   UInt_t fGesEvTime; // Unix time of the run [4] + Time of the event from the run start (s) [5]
00239   Int_t fGesNentryBhabha; // current number of entry in Bhabha tree
00240   Int_t fGesNentryHype; // current number of entry in Hype tree
00241 
00242   // --- Reconstructed information handling
00243   Int_t fForeseenSign[2]; // foreseen sign for reconstructed tracks
00244 
00245   // Bhabha tree variables (see the "EEVERT1" routine for variables meaning)
00246   Int_t   fBhaEvNum; // software number of event
00247   Bool_t  fBhaVertImpossible; // true if one track only is present (vertex determination impossible)
00248   Bool_t  fBhaVertDoubtful; // true if the distance between e-,e+ tracks is too large (vertex doubtful)
00249   Float_t fBhaVertPos[3]; // bhabha vertex position (x,y,z) 
00250   Float_t fBhaMom[2];     // see FIN_PHYS::E_FinPhys_BhabhaPart_ID
00251   Float_t fBhaPipe_X[2];  // X position at outer beam-pipe  (after backtracking)
00252   Float_t fBhaPipe_Y[2];  // Y position at outer beam-pipe  (after backtracking)
00253   Float_t fBhaPipe_Z[2];  // Z position at outer beam-pipe  (after backtracking)
00254   Float_t fBhaDirCos_X[2];     // X director cosines (after backtracking)
00255   Float_t fBhaDirCos_Y[2];     // X director cosines (after backtracking)
00256   Float_t fBhaDirCos_Z[2];     // X director cosines (after backtracking)
00257   Bool_t  fBhaIsLong[2];   // false/true : short-track/long-track
00258   Float_t fBhaPipeAngle[2];   // angle between the track and the normal to the pipe (deg)
00259   Float_t fBhaTofiTime[2]; // Calibrated time at TOFINO (added after version 9.00/01)
00260   Float_t fBhaTofoTime[2]; // Calibrated time at TOFONE (added after version 9.00/01)
00261   Float_t fBhaTrackLength[2]; // track length is needed for displaying purposes
00262   // --- both tracks will be required for filling following variables:
00263   Float_t fBhaInvMass_EpluEmin; // invariant mass (hypothesys: bhabha e+e- pair)
00264   Float_t fBhaInvMass_PIpluPImin; // invariant mass (hypothesys: K_short decay)
00265   Float_t fBhaTotalMomentum; // scalar product of e+e- tracks
00266   Float_t fBhaAngle; // angle between the two tracks (deg)
00267 
00268   // --- work in progress: adding geometric info for displaying purposes
00269   Float_t fBhaGeoPRradius[2];    // radius (1/curvature) from P.R. zebra: 4
00270   Float_t fBhaGeoFitPoint_X[2];    // zebra: 13
00271   Float_t fBhaGeoFitPoint_Y[2];    // zebra: 14
00272   Float_t fBhaGeoFitPoint_Z[2];    // zebra: 15
00273   Float_t fBhaGeoFitDirCos_X[2];   // zebra: 16
00274   Float_t fBhaGeoFitDirCos_Y[2];   // zebra: 17
00275   Float_t fBhaGeoFitDirCos_Z[2];   // zebra: 18
00276 
00277   // Hype tree variables
00278   Int_t   fHypEvNum; // software number of event
00279   Int_t fHyp_PattRec_Err;      // K+/K- pattern recognition error-code (see zebra doc [blankdek])
00280   Float_t fHyp_PhiDecayPos[3]; // x,y,z position of the PHI dacay position (MRS)
00281 
00282   Int_t fHypStopID[2]; // encoded identification of K-/K+ stopping volume
00283   Int_t fHypStopTgtNum[2];  // number of the target the kaon stopped into (-1 if out of targets)
00284   Int_t fHypStopVolNum[2];  // number of the volume the kaon stopped into (-1 if inside targets)
00285 
00286   Float_t fHyp_K_StopPoint_X[2]; // x position of the kaon stopping point (MRS)
00287   Float_t fHyp_K_StopPoint_Y[2]; // y position of the kaon stopping point (MRS)
00288   Float_t fHyp_K_StopPoint_Z[2]; // z position of the kaon stopping point (MRS)
00289 
00290   Float_t fHyp_K_DeDx_Isi[2]; // dE/dX in ISIM
00291 
00292   // --- work in progress: adding geometric info for displaying purposes
00293   //       Check if using double-helix method
00294   Float_t fHyp_K_Vert_Center_X[2]; //zebra: GRAV+1  
00295   Float_t fHyp_K_Vert_Center_Y[2]; //zebra: GRAV+2
00296   Float_t fHyp_K_Vert_Radius[2];   //zebra: GRAV+3
00297 
00298   // --- support for reconstructed tracks
00299   //  tracks are used for physics analysis
00300   //  bhabha tracks are handled apart (single data-members),
00301   //  since the reconstructed bhabha structure is fixed:
00302   //  handling every kind of track inside the spectrometer
00303   //  is more complex, then a dedicated class is used
00304   TClonesArray *fTracks_Kmin; // tracks starting from the K- vertex
00305   TClonesArray *fTracks_Kplu; // tracks starting from the K+ vertex
00306   TClonesArray *fVertices; // Vertices different from K+/K- stop
00307 
00308   TFndTrack *fCurTrack; // used while filling tracks from zebra
00309   TFndVertex *fCurVertex; // used while filling vertices from zebra
00310 
00311  protected:
00312   TFile *fCurPreanFile; // current root-file (contains pre-analysis trees)
00313   void AddTrack(Int_t part_id);  // will change fCurTrack
00314   void AddVertex();  // will change fCurVertex
00315 
00316  private:
00317   void InitTrees();
00318 
00319  public:
00320   explicit TFndPrean(Int_t debug_lev = 0);
00321   ~TFndPrean();
00322   
00323   void SetDeamonBehaviour(); // Set class attributes for using it as a deamon
00324   void Init(Bool_t is_online);
00325   void Finish();
00326   Int_t SaveTrees(TFile *file); // save all trees to the given root-file
00327   
00328   void ResetDataVariables(); // reset all variables used by trees
00329   void Reset(); // empty all trees, reset rates evaluation variables
00330   
00331   
00332   // --- General preanalysis methods
00333   Int_t GoToEvent(const Int_t &ev_num,Int_t &mode); // find event "ev_num" (numbering starts from 1) in every tree
00334 
00335   void ReadScalers(UInt_t *RawEvent);
00336   void InspectGES(TFndProcessRec *prec);
00337   void AnalyzeBhabha(TFndProcessRec *prec);
00338   void AnalyzeHype(TFndProcessRec *prec);
00339   void UpdateGESTree(); // some information are referred to other trees
00340 
00341   TTree *GetScalTree()   { return fScalTree; }
00342   TTree *GetGesTree()    { return fGesTree; }
00343   TTree *GetBabaTree()   { return fBabaTree; }
00344   TTree *GetBhabhaTree() { return fBhabhaTree; }
00345   TTree *GetHypeTree()   { return fHypeTree; }
00346 
00347   void PrintScaler(Int_t scal_id); // scal_id = 0,1,2,3,4
00348 
00349   // --- support for reading saved preanalysis-trees
00350   Int_t LoadTrees(const TString &fNam);
00351   Int_t CloseCurrentSourceFile();
00352 
00353   void SetLogFile(ofstream *logfile) 
00354     { //  logfile must be deleted out of here.
00355       fCurLogFile = logfile;
00356     }
00357 
00358   static TClonesArray *fgKminTracks;
00359   static TClonesArray *fgKpluTracks;
00360   static TClonesArray *fgVertices;
00361 
00362   //--- check methods ---
00363   Int_t CheckTofinoCFDs(TFndProcessRec *prec); // find CFD glitches
00364 
00365   friend class TFndEvd;
00366 
00367   ClassDef(TFndPrean,0) // Pre-analysis class: heart of the preanalysis program
00368 };
00369 
00370 #endif  // FROOT_TFndPrean

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