STEER/TFndRdt.cxx

00001 // @(#)fROOT/STEER:$Name:  $:$Id: TFndRdt.cxx,v 1.65 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Revision Author: Diego Faso <mailto:faso@to.infn.it>, 2005/06/24
00003 // Original Author: P. Cerello <mailto:cerello@to.infn.it>, 2000
00004 
00006 //                                                                      //
00007 //                               TFndRdt                                //
00008 //                                                                      //
00009 // This class gives the Description of the Raw Data Tape event.         //
00010 // The private part includes some data members                          //
00011 // (event length, pointers to the whole buffer and the subdetector      //
00012 // buffers) and a set of member functions retrieving some information   //
00013 // needed to build the Hit Data Tape.                                   //
00014 // The public part allows to dump the event and invoke the member       //
00015 // functions which transform the RDT sub-events into HDT sub-events.    //
00016 //                                                                      //
00018 
00019 #include "TApplication.h"
00020 
00021 #include "TObjectTable.h"
00022 #include "TBranch.h"
00023 #include "TVector.h"
00024 #include "TFndFeeMap.h"
00025 #include "TFndRun.h"
00026 #include "TFndRdt.h"
00027 #include "TFndHdt.h"
00028 #include "TFndTrig.h"
00029 #include "TFndHTof.h"
00030 #include "TFndHLmd.h"
00031 #include "TFndRunConfiguration.h"
00032 
00033 #include "TThread.h"
00034 
00035 #include "TFndGeometry.h"
00036 
00037 ClassImp(TFndRdt)
00038 
00039 //____________________________________
00040 TFndRdt::TFndRdt():
00041   fCurRunType(),fFndFeeMap(),
00042   fMustEvalCommonMode(),fMustFindSilClusters()
00043 {
00044   // Debug levels are obtained according to the detectors "enum EFndMonDetectors" (see FROOT.h)
00045   
00046   Reload();
00047 }
00048 
00049 //____________________________________
00050 TFndRdt::~TFndRdt() {  
00051 
00052   Reset();
00053   
00054 }
00055 
00056 //_____________________________________________
00057 UInt_t *TFndRdt::GetDetector(E_FIN_RDT_DetID det_id){
00058   // offset (7) taken into account
00059   UInt_t *det = (fRawEvent[7 + det_id])?  fRawEvent+fRawEvent[7 + det_id] : NULL;
00060   return det;
00061   
00062 }
00063 
00064 //_____________________________________________
00065 UInt_t *TFndRdt::GetEquipment(E_FIN_RDT_DetID det_id,Int_t eqp_num){
00066   // offset (6) taken into account
00067   
00068   //  UInt_t *det = (fRawEvent[7 + det_id])?  fRawEvent+fRawEvent[7 + det_id] : NULL;
00069   UInt_t *det = GetDetector(det_id);
00070   UInt_t *equ = (det && det[6 + eqp_num])?  det+det[6 + eqp_num] : NULL;
00071   return equ;
00072   
00073 }
00074 
00075 //_____________________________________________
00076 void TFndRdt::PrintEquipment(Int_t eqp_id, Int_t neqp) {
00077   // to be implemented (if really needed)
00078 
00079   if(eqp_id == 2 || eqp_id == 3){
00080     Warning("PrintEquipment","No equipment loaded for SIL");
00081     return;
00082   }
00083   
00084 }
00085 
00086 //____________________________________
00087 void TFndRdt::Reload(){
00088   
00089   Reset();
00090   fDebugLev = fndrun->GetDebugRawEv();
00091   fndrun->GetRunType(fCurRunType);
00092   if(!fndrun) TerminateFroot(0,"TFndRdt::TFndRdt() ---> pointer to TfndRun not available!");
00093   fFndFeeMap = fndrun->GetFeeMap();
00094   if(!fFndFeeMap) TerminateFroot(0,"TFndRdt::TFndRdt() ---> fFndFeeMap not ready!");
00095 }
00096 
00097 //____________________________________
00098 void TFndRdt::Reset(){
00099   // Come back to the just created object
00100   
00101   //  delete fCurHdtEv;
00102   //  fCurHdtEv = 0;
00103   fRawEvent = 0;
00104   fSilHits.clear();
00105   fMustEvalCommonMode = kFALSE;
00106   fMustFindSilClusters = kFALSE;
00107 }
00108 
00109 //____________________________________
00110 void TFndRdt::RdtToHdt(UInt_t *raw,TFndHdt* fndhdt) {
00111   //  ------------------------------
00112   // | Build the HDT complete event |
00113   //  ------------------------------
00114   
00115   if(!fFndFeeMap->IsThere()){
00116     Error("RdtToHdt","fFndFeeMap not available");
00117     gApplication->Terminate();
00118   }
00119 
00120   //fCurHdtEv = fndrun->GetCurrentHdt();
00121   //  fCurHdtEv = fndhdt;
00122   //  Printf("fCurHdtEv in TFndRdt: 0x%x",fCurHdtEv);
00123   if(!TFndRun::fgFinHdt){
00124     Error("RdtToHdt","TFndRun::fgFinHdt not defined!");
00125     gApplication->Terminate();
00126   }
00127   fRawEvent = raw;
00128 
00129   if(fDebugLev) Printf("TFndRdt::RdtToHdt ---> HEADER");
00130 
00131   if(fDebugLev) Printf("TFndRdt::RdtToHdt ---> Detector Trees");
00132 #ifdef _FND_ENABLE_RAW_GTS
00133   if ( FillGtsHit() == -4 || FillGtsHit() == -3 || FillGtsHit() == -1 ) return; // -2 accepted for PEDE runs
00134 #endif
00135 #ifdef _FND_ENABLE_RAW_TOF
00136   FillTofHits();
00137 #endif
00138 #ifdef _FND_ENABLE_RAW_ISIM
00139   FillSilHits((Int_t) E_FIN_INNER_LAYER); // ISIM
00140 #endif
00141 #ifdef _FND_ENABLE_RAW_OSIM
00142   FillSilHits((Int_t) E_FIN_OUTER_LAYER); // OSIM
00143 #endif
00144   //#if defined _FND_ENABLE_RAW_ISIM && defined  _FND_ENABLE_RAW_OSIM
00145   if(fMustEvalCommonMode) EvalCommonModeNoise();
00146   if(fMustFindSilClusters) FindSilClusters();
00147   //#endif
00148 #ifdef _FND_ENABLE_RAW_LMD
00149   FillLmdHits();
00150 #endif
00151 #ifdef _FND_ENABLE_RAW_STB
00152   FillStbHits();
00153 #endif
00154 
00155   if(fDebugLev) Printf("TFndRdt::RdtToHdt ---> Exiting method");
00156 }
00157 
00158 //____________________________________
00159 Int_t TFndRdt::FillGtsHit() {
00160   // return value:
00161   //               0 : normal buffer
00162   //              -1 : wrong buffer (detector not in the run) (or wrong eqp length)
00163   //              -2 : wrong buffer (PU eqp not found)
00164   //              -3 : wrong buffer (PU pointer not found)
00165   //              -4 : wrong buffer (wrong PU length)
00166   //              -5 : (MALU eqp not found)
00167   //              -6 : (MALU pointer not found)
00168   //              -7 : (wrong MALU length)
00169   //              -8 : (TRIG-SEL eqp not found)
00170   //              -9 : (TRIG-SEL pointer not found)
00171   //              -10: (wrong TRIG-SEL length)
00172 
00173   UInt_t deb_gts = (fDebugLev >> ((Int_t)(D_GTS)*4)) & 0xF; // get gts digit
00174 
00175   UInt_t *det = GetDetector(FIN_RDT_Eqp_Gts);  
00176   if (det==NULL){
00177     if(fDebugLev > 0) Warning("FillGtsHit","detector not in the run (null pointer)");
00178     return -1; //
00179   }
00180   // GTS equipment
00181   
00182   // --- Pattern Unit
00183   UInt_t *eqp = GetEquipment( FIN_RDT_Eqp_Gts, FIN_EQ_CAEN_V529 );
00184   if(!eqp){
00185     if( fCurRunType != (Int_t)(RT_PEDE) )
00186       Warning("FillGtsHit","Pointer to PU equipment is NULL");
00187     return -2;
00188   }
00189   UInt_t *pu_ptr=eqp+1;
00190   if(!pu_ptr){
00191     Error("FillGtsHit","Pointer to the PU structure is NULL");    
00192     return -3;
00193   }
00194   
00195   if(eqp[0] <= 0 || eqp[0] > K_MAX_EQP_LEN) {
00196     Error("FillGtsHit","Wrong length found in GTS equipment");
00197     return -1;
00198   }
00199   
00200   UInt_t pu_len=eqp[0]-1;
00201   if(deb_gts>0) Printf("TFndRdt::FillGtsHit -----> Reading Pattern Units");
00202   if(pu_len <= 1 || pu_len > K_N_GTS_P_UNITS * 2) {
00203     Error("FillGtsHit","PU length not accepted: value= %u",pu_len);
00204     return -4;
00205   } 
00206   for(UInt_t i=0;i<pu_len;i++) {
00207     UInt_t cont = 0;
00208     UInt_t mult = 0;
00209     if(i%2 == 0){
00210       cont = *(pu_ptr + i) & 0xFFFF;
00211       TFndRun::fgFinHdt->GetGts()->SetPU_cont(cont,i/2);
00212     }    
00213     else{
00214       mult = *(pu_ptr + i) & 0xFFFF;
00215       TFndRun::fgFinHdt->GetGts()->SetPU_mult(mult,(i/2)+1);
00216     }    
00217   }
00218   if(deb_gts>1){
00219     for(UInt_t i=0;i<K_N_GTS_P_UNITS;i++) 
00220       Printf("TFndRdt::FillGtsHit -----> PU(id:%u): content: 0x%x; mult:0x%x",
00221                       i,
00222                       TFndRun::fgFinHdt->GetGts()->GetPU_cont(i),
00223                       TFndRun::fgFinHdt->GetGts()->GetPU_mult(i));
00224   }
00225 
00226   // --- MALU
00227   eqp = GetEquipment( FIN_RDT_Eqp_Gts, FIN_EQ_LECROY_4532);
00228   if(!eqp){
00229     if(deb_gts>0) Error("FillGtsHit","Pointer to MALU equipment is NULL");
00230     return -5;
00231   }
00232   UInt_t *mu_ptr=eqp+1;
00233   if(!mu_ptr){
00234     Error("FillGtsHit","Pointer to the MALU structure is NULL");    
00235     return -6;
00236   }
00237   UInt_t mu_len=eqp[0]-1;
00238   if(deb_gts>0) Printf("TFndRdt::FillGtsHit -----> Reading MALU(s)");
00239   if(mu_len <= 1 || mu_len > K_N_GTS_MALU * 2) {
00240     Error("FillGtsHit","MALU length not accepted: value= %u",mu_len);
00241     return -7;
00242   } 
00243   UInt_t pat1 = 0;
00244   UInt_t pat2 = 0;
00245   if(deb_gts>0) Printf("TFndRdt::FillGtsHit -----> MALU length: %u",mu_len);
00246   for(UInt_t i=0;i<mu_len;i++) {
00247     if(i%2 == 0) pat1 = *(mu_ptr + i) & 0xFFFF;    
00248     else{
00249       pat2 = *(mu_ptr + i) & 0xFFFF;
00250       TFndRun::fgFinHdt->GetGts()->SetMalu_cont(pat1,pat2,(i/2));
00251       pat1 = 0; pat2 = 0;
00252     }
00253   }    
00254   
00255   if(deb_gts>1){
00256     for(UInt_t i=0;i<K_N_GTS_MALU;i++) 
00257       Printf("TFndRdt::FillGtsHit -----> MALU(id:%u): content: 0x%x;",
00258                       i,
00259                       TFndRun::fgFinHdt->GetGts()->GetMalu_cont(i));
00260   }
00261   // --- TRIGGER SELECTOR
00262   eqp = GetEquipment( FIN_RDT_Eqp_Gts, FIN_EQ_TRIG_SEL);
00263   if(!eqp){
00264     Error("FillGtsHit","Pointer to TRIGGER SELECTOR equipment is NULL");
00265     return -8;
00266   }
00267   UInt_t *ts_ptr=eqp+1;
00268   if(!ts_ptr){
00269     Error("FillGtsHit","Pointer to the TRIGGER SELECTOR structure is NULL");    
00270     return -9;
00271   }
00272   UInt_t ts_len=eqp[0]-1;
00273   if(deb_gts>0) Printf("TFndRdt::FillGtsHit -----> Reading TRIGGER SELECTOR");
00274   if(ts_len <= 1 || ts_len > K_N_GTS_SELECTORS) {
00275     Error("FillGtsHit","TRIGGER SELECTOR length not accepted: value= %u",ts_len);
00276     return -10;
00277   }
00278   if(deb_gts>0) Printf("TFndRdt::FillGtsHit -----> Trigger Selector length: %u",ts_len);
00279   for(UInt_t i=0;i<ts_len;i++) {
00280     TFndRun::fgFinHdt->GetGts()->SetTriggerSelector(*(ts_ptr+i),i);
00281   }    
00282   
00283   if(deb_gts>1){
00284     for(UInt_t i=0;i<K_N_GTS_SELECTORS;i++) 
00285       Printf("TFndRdt::FillGtsHit -----> TrigSel(id:%u): content: 0x%x;",
00286                       i,
00287                       TFndRun::fgFinHdt->GetGts()->GetTriggerSelector(i));
00288   }
00289 
00290   return 0;
00291 }
00292 
00293 //____________________________________
00294 void TFndRdt::FillSilHits(Int_t io) {
00295   // Rewritten (September 2006)
00296   // hit = new TFndHSil(nmodule,nside,nadc,nstrip,noise,spych,adc);
00297   
00298   UInt_t *det = (io == 1 ) ? GetDetector(FIN_RDT_Eqp_Isi) : GetDetector(FIN_RDT_Eqp_Osi);  
00299   if (det==NULL){
00300     if(fDebugLev > 0) Warning("FillSilHits","detector not in the run (null pointer) (io = %d)",io);
00301     return;
00302   }
00303 
00304   UInt_t deb_sil = (fDebugLev >> ((Int_t)(D_SIL)*4)) & 0xF; // get sil digit
00305 
00306   // 2006 hardware has different base address for CRAMS
00307   Int_t b_addr = K_Sil_Crams_BaseAddress_03;
00308   if(fndrun->GetRunTime() > Fee_2006_NewSilDB_StartTime) b_addr = K_Sil_Crams_BaseAddress_06;
00309 
00310   if(deb_sil) Printf( "TFndRdt::FillSilHits ---> using base address 0x%x",b_addr);
00311   int cram;
00312   int sez;
00313   for (int k=3,h=0; k<det[0]; k++,h--) {
00314     static int PhBuf[0x2000],ZaBuf[0x1000],ZbBuf[0x1000],*Buf;
00315     static int ll;
00316     static int j,jza,jzb;
00317     //       static SILDBADC *db;
00318     
00319     //---------------------
00320     
00321     if (h==0) {
00322       cram = ((det[k++]>>16) & 0xFFFF) - b_addr;
00323       if (cram >= 0x60 || cram < 0) break;
00324       
00325       sez  = det[k++];
00326       if (sez != 0 && sez != 1) break;
00327       
00328       h = det[k];
00329       if (h) k++;
00330       j=0;
00331     }
00332       
00333     //---------------------
00334     int is_spy    = (det[k]>>31) & 1;        // spy channal flag
00335     int noise     = (det[k]>>23) & 0xFF;     // noise value
00336     int n_adc_cha = (det[k]>>12) & 0x3FF;    // cram channel number
00337     int adc_val   = det[k]       & 0x3FF;    // adc value
00338     
00339     // typedef struct {
00340     //   Char_t  Module;               // Module number
00341     //   Char_t  P_Z;                  // 0=Phi 1=Za  2=Zb
00342     //   char  Spy[K_N_Sil_AdcCha];   // 1=Spy
00343     //   char  Noise[K_N_Sil_AdcCha]; // Noise level: 0=OK ... 6=dead
00344     //   short Strip[K_N_Sil_AdcCha]; // Strip number
00345     //   short Chip[K_N_Sil_AdcCha];  // Chip (VA1) number
00346     //   float Amp[K_N_Sil_AdcCha];   // Strip amplification
00347     // } SILDBADC;
00348     
00349     if(deb_sil>1) Printf("TFndRdt::FillSilHits -----> is_spy %d; noise %d; n_adc_cha %d; adc_val %d.", is_spy, noise, n_adc_cha, adc_val);
00350     //    
00351     Short_t nmodule = fFndFeeMap->GetSilModule(io,cram,sez);
00352     Short_t nside = fFndFeeMap->GetSilSide(io,cram,sez);
00353     //      Short_t nadc = cha; // unique variable will be used
00354     Short_t nstrip = fFndFeeMap->GetSilStrip(io,cram,sez,n_adc_cha);
00355     //      Short_t noise = noi; // check
00356     //      Short_t spych = spy;
00357     //      Float_t adc = val;
00358     
00359     // histos:
00360     // - per ogni module/side ===> noise vs n_adc_cha (TH1) // resetteto evento per evento
00361     // - valutare common-mode e varianza
00362     // - valutazione del cluster
00363     //      |
00364     //      + -> per ogni module/side ==> cluster charge
00365     
00366     if(deb_sil>1) Printf("TFndRdt::FillSilHits -----> layer %d; nmodule %d; nside %d; nstrip %d.", io, nmodule, nside, nstrip);
00367     
00368     SILADCHIT s_hit;
00369     s_hit.Layer  = (Int_t) io;
00370     s_hit.Module = (Int_t) nmodule;
00371     s_hit.Side   = (Int_t) nside;
00372     s_hit.Strip  = (Int_t) nstrip;
00373     s_hit.Spy    = (Int_t) is_spy;
00374     s_hit.Noise  = (Int_t) noise;
00375     s_hit.AdcCh  = (Int_t) n_adc_cha;
00376     s_hit.AdcVal = (Int_t) adc_val - (Int_t) K_N_Sil_FixPede;
00377     fSilHits.push_back(s_hit);
00378     
00380     //       TFndHSil *hit; // the TFndHSil class will be removed
00381     //       //      if(noise > 5) {
00382     //       hit = new TFndHSil(nmodule,nside,nadc,nstrip,noise,spych,adc);
00383     //       //    if(fDebugLev) hit->Print();
00384     //       if(nmodule < 10) 
00385     //          fCurHdtEv->AddIsmHit(hit); 
00386     //       else 
00387     //          fCurHdtEv->AddOsmHit(hit); 
00388     //}
00390   }
00391 
00392   fMustEvalCommonMode = kTRUE;
00393   fMustFindSilClusters = kTRUE;
00394   if(deb_sil) Printf("TFndRdt::FillSilHits ---> exiting method");
00395 }
00396     
00397 //____________________________________
00398 void TFndRdt::EvalCommonModeNoise() {
00399   // Check the list of hits on SIL first
00400   if(fSilHits.empty()){
00401     Warning("EvalCommonModeNoise","List of SIL hits empty");
00402     return;
00403   }
00404   Bool_t vfound = kFALSE;
00405   // Check if you need to set at zero all vectors!
00406   // Clear Common Mode mean max count vectors on hdt.  
00407   // Printf("EvalCommonMode: Clear Common Mode Vectors");
00408 
00409   //  TFndRun::fgFinHdt->SetSilComMod_meanmaxcount_zero(); 
00410 
00411   // get an iterator to the starting point of the vector
00412   // Printf("EvalCommonMode: First Loop on Hits");
00413   for(std::vector<SILADCHIT>::iterator itNum = fSilHits.begin(); itNum < fSilHits.end(); itNum++){ // loop on all hits
00414     // maximum number of hits: 55296
00415     //
00416     // Set SIL-noise
00417     TFndRun::fgFinHdt->SetSilNoise(itNum->AdcCh,itNum->Side, itNum->Module, itNum->Layer, itNum->Noise) ;
00418     // Fill the CM mean value
00419     if (itNum->Spy == 1) TFndRun::fgFinHdt->FillSilComMod_mean((itNum->AdcCh)/(Int_t)K_N_Sil_ChaOnChip,itNum->Side, itNum->Module, itNum->Layer, (Double_t) itNum->AdcVal) ;
00420     //
00421     //
00422   } // first loop on all hits completed  
00423   // Calculate the Common Mode
00424   //  Printf("EvalCommonMode: Calculate Common Mode");
00425   TFndRun::fgFinHdt->CalculateSilComMod_mean_all();
00426   // Subtract the Common Mode to the spy channels 
00427   // Printf("EvalCommonMode: Second Loop on Hits");
00428   for(std::vector<SILADCHIT>::iterator itNum = fSilHits.begin(); itNum < fSilHits.end(); itNum++){ // loop on all hits
00429     if (itNum->Spy == 1) itNum->AdcVal -=  TFndRun::fgFinHdt->GetIntSilComMod_mean((itNum->AdcCh)/(Int_t)K_N_Sil_ChaOnChip,itNum->Side, itNum->Module, itNum->Layer);
00430   } // second loop on all hits completed  
00431 }
00432 
00433 //____________________________________
00434 void TFndRdt::FindSilClusters(){
00435   //
00436   // the raw-datum reading is completed: now create or update hits      
00437   // Printf("Finding Sil Cluster...");
00438   //
00439   SetAdc_Val_Noi_Zero();
00440   //
00441   std::vector<SILCLRAW> PhiSilCluster;
00442   std::vector<SILCLRAW> ZetaSilCluster;
00443   //
00444   Double_t PhiKaonThreshold[8] = 
00445     { 
00446       200.,
00447       200.,
00448       170.,
00449       170.,
00450       150.,
00451       160.,
00452       180.,
00453       200.
00454     };
00455   
00456   //
00457   SILCLRAW SilCluster;
00458   //
00459   for(std::vector<SILADCHIT>::iterator itNum = fSilHits.begin(); itNum < fSilHits.end(); itNum++){ // loop on all hits
00460     SetSilAdcVal(itNum->Layer,itNum->Module,(itNum->Side < 1 ? 0 : 1),itNum->Strip,itNum->AdcVal);
00461     SetSilAdcNoi(itNum->Layer,itNum->Module,(itNum->Side < 1 ? 0 : 1),itNum->Strip,itNum->Noise);
00462     SetSilAdcCh(itNum->Layer,itNum->Module,(itNum->Side < 1 ? 0 : 1),itNum->Strip, (itNum->Side < 2 ? itNum->AdcCh : itNum->AdcCh + (Int_t) K_N_Sil_AdcCha ));
00463     //
00464   }
00465   //
00466   for(Int_t nlay = 1; nlay < (Int_t) E_FIN_OUTER_LAYER+1; nlay++){
00467     for(Int_t nmod = 1; nmod < (Int_t) K_N_Sil_Modules+1; nmod++) {
00468       PhiSilCluster.clear();
00469       ZetaSilCluster.clear();
00470       Double_t dedx_phi_cosalpha = 0.;
00471       Double_t dedx_zeta_cosalpha = 0.;
00472       for(Int_t nside = 0; nside < (Int_t) K_N_Sil_Sides - 1; nside++) {
00473         //
00474         Int_t nstrip = 1;
00475         Int_t nclustr = 0;
00476         Int_t nminstr = 0;
00477         Int_t nmaxstr = 0;
00478         Int_t nadcchcl = 0;
00479         Double_t strcomcl = 0.;
00480         Double_t noisecl = 0.;
00481         Double_t adcvalcl = 0.;
00482         Double_t bar_pre = 0.;
00483         Double_t sum_pre = 0.;
00484         Double_t noi_pre = 0.;
00485         Int_t nst_pre = 0;
00486         //
00487         Int_t MaxStrSide = ( nside < 1 ? (Int_t) K_N_Sil_Phi_Strips : (Int_t) K_N_Sil_Z_Strips );
00488         //
00489         // simple cluster finding algorithm
00490         //
00491         //
00492         while (nstrip <= MaxStrSide) {
00493           //
00494           if (((GetSilAdcVal(nlay,nmod,nside,nstrip)*(Int_t)K_N_Sil_MulNoise) > (GetSilAdcNoi(nlay,nmod,nside,nstrip)*(Int_t)K_N_Sil_Sigma_Pre)) && (GetSilAdcNoi(nlay,nmod,nside,nstrip) > (Int_t)K_N_Sil_Noise_Cut)) {
00495             //
00496             nclustr = nstrip; 
00497             while((nclustr >= 1) && ((GetSilAdcVal(nlay,nmod,nside,nclustr)*(Int_t)K_N_Sil_MulNoise) > (GetSilAdcNoi(nlay,nmod,nside,nclustr)*(Int_t)K_N_Sil_Sigma_Cut))) nclustr--;
00498             nminstr = nclustr+1;
00499             // 
00500             nclustr = nstrip; 
00501             while((nclustr <= MaxStrSide) && ((GetSilAdcVal(nlay,nmod,nside,nclustr)*(Int_t)K_N_Sil_MulNoise) > (GetSilAdcNoi(nlay,nmod,nside,nclustr)*(Int_t)K_N_Sil_Sigma_Cut))) nclustr++;
00502             nmaxstr = nclustr-1;
00503             // prepare for next cluster
00504             nstrip = nclustr;
00505             // calculation of cluster parameter
00506             bar_pre = 0.;
00507             sum_pre = 0.;
00508             noi_pre = 0.;
00509             nst_pre = 0;
00510             //
00511             for (Int_t nstr = nminstr; nstr <= nmaxstr; nstr++) {
00512               bar_pre += (((Double_t)GetSilAdcVal(nlay,nmod,nside,nstr))*((Double_t)nstr));   
00513               sum_pre += ((Double_t)GetSilAdcVal(nlay,nmod,nside,nstr));
00514               noi_pre += (((Double_t)GetSilAdcNoi(nlay,nmod,nside,nstr))*((Double_t)GetSilAdcNoi(nlay,nmod,nside,nstr)));
00515               nst_pre++; 
00516             }
00517             strcomcl = (sum_pre != 0. ? bar_pre/sum_pre : -1.);
00518             noisecl = (noi_pre > 0 ? sqrt(noi_pre) : -1.);
00519             adcvalcl = sum_pre;
00520             nadcchcl = GetSilAdcCh(nlay,nmod,nside,lrint(strcomcl));
00521             // here store the value of Phi and Z cluster
00522             SilCluster.NumStripCl = nst_pre; // Min Strip Number of Cluster
00523             SilCluster.AdcChCl = nadcchcl;   // Center of Mass of Cluster (adc channel) 
00524             SilCluster.StripChCl = strcomcl; // Center of Mass of Cluster
00525             SilCluster.NoiseCl = noisecl;    // Noise level of Cluster
00526             SilCluster.AdcValCl = adcvalcl;  // Sum Adc Values of Cluster
00527             //
00528             //      Printf("TFndRdt::FindSilCluster -----> Cluster: min_str %d; max_str %d; num_str %d; num_int %d; bar_cha %f; n_adc_bar_cha %f; charge %f; noise %f. ", nminstr,nmaxstr,nst_pre,lrint(strcomcl),(Float_t) strcomcl,(Float_t) nadcchcl,(Float_t) adcvalcl,(Float_t) noisecl);      
00529             //
00530             if (nside == 0) { 
00531               PhiSilCluster.push_back(SilCluster);
00532             } else {
00533               ZetaSilCluster.push_back(SilCluster);
00534             }
00535             // ...
00536           } else {
00537             nstrip++; 
00538           } // end of high threshold if
00539         } // end of while (nstrip ...)
00540       } // end of side loop
00541       // Sort the cluster vectors
00542       std::sort(PhiSilCluster.begin(), PhiSilCluster.end(), SDescendingAdcValClSort());
00543       std::sort(ZetaSilCluster.begin(), ZetaSilCluster.end(), SDescendingAdcValClSort());
00544       // here insert the Phi and Z Cluster association
00545       // diff_adc_val = 0.;
00546       //
00547       Double_t diff_adc_val = -1.;
00548       std::vector<SILCLRAW>::iterator itStopPhi = PhiSilCluster.begin();
00549       std::vector<SILCLRAW>::iterator itStopZeta = ZetaSilCluster.begin();
00550       // loop on all phi cluster
00551       if ( (!PhiSilCluster.empty()) && (!ZetaSilCluster.empty()) ) {
00552         for(std::vector<SILCLRAW>::iterator itPhi = PhiSilCluster.begin(); itPhi < PhiSilCluster.end(); itPhi++){ 
00553           //
00554           diff_adc_val = -1.;
00555           // loop on all zeta cluster
00556           for(std::vector<SILCLRAW>::iterator itZeta = ZetaSilCluster.begin(); itZeta < ZetaSilCluster.end(); itZeta++){ 
00557             //
00558             if(diff_adc_val==-1.) {
00559               diff_adc_val = TMath::Abs(itPhi->AdcValCl - itZeta->AdcValCl);
00560               itStopPhi = itPhi; 
00561               itStopZeta = itZeta;
00562             }
00563             //
00564             if(diff_adc_val > TMath::Abs(itPhi->AdcValCl - itZeta->AdcValCl)) {
00565               diff_adc_val = TMath::Abs(itPhi->AdcValCl - itZeta->AdcValCl) ;
00566               itStopPhi = itPhi; 
00567               itStopZeta = itZeta;
00568             }     
00569           } //end loop on zeta cluster
00570           //
00571           // Printf("Found Sil Cluster");
00572           //
00573           // fill the hit cluster vector
00574           //
00575           TFndHSilCluster * hsilcl = TFndRun::fgFinHdt->Add_SilCluster(nlay);
00576           if ( diff_adc_val >= 0. ) {
00577             hsilcl->SetModNum(nmod);
00578             hsilcl->SetGoodCl(1);
00579             hsilcl->SetIDCl(0);
00580             hsilcl->SetClusterPhiAdcCh((Float_t) itStopPhi->AdcChCl);
00581             hsilcl->SetClusterZetaAdcCh((Float_t) itStopZeta->AdcChCl);
00582             hsilcl->SetLocalPosition(0.0,TFndGeometry::SilPositionStrip(0,itStopPhi->StripChCl),TFndGeometry::SilPositionStrip(1,itStopZeta->StripChCl));
00583             hsilcl->SetPhiClusterSignal((Float_t) itStopPhi->AdcValCl );
00584             hsilcl->SetPhiClusterNoise((Float_t) itStopPhi->NoiseCl);
00585             hsilcl->SetZetaClusterSignal((Float_t) itStopZeta->AdcValCl );
00586             hsilcl->SetZetaClusterNoise((Float_t) itStopPhi->NoiseCl); 
00587             dedx_phi_cosalpha = (itStopPhi->AdcValCl / TMath::Sqrt(1.+((Double_t)(itStopPhi->NumStripCl*itStopPhi->NumStripCl))/36.+ ((Double_t)(itStopZeta->NumStripCl*itStopZeta->NumStripCl)/9.)));
00588             dedx_zeta_cosalpha = (itStopZeta->AdcValCl / TMath::Sqrt(1.+((Double_t)(itStopPhi->NumStripCl*itStopPhi->NumStripCl))/36.+ ((Double_t)(itStopZeta->NumStripCl*itStopZeta->NumStripCl)/9.)));
00589             hsilcl->SetDEDxPhi((Float_t) dedx_phi_cosalpha);
00590             hsilcl->SetDEDxZeta((Float_t) dedx_zeta_cosalpha);
00591             if (nlay == 1 && dedx_phi_cosalpha > PhiKaonThreshold[nmod-1]) hsilcl->SetIDCl(1);
00592             // erase zeta cluster
00593             ZetaSilCluster.erase(itStopZeta);
00594           } else { 
00595             hsilcl->SetModNum(nmod);
00596             hsilcl->SetGoodCl(0);
00597             hsilcl->SetIDCl(0);
00598             hsilcl->SetClusterPhiAdcCh(itPhi->AdcChCl);
00599             hsilcl->SetClusterZetaAdcCh(-1.);
00600             hsilcl->SetLocalPosition(0.0,TFndGeometry::SilPositionStrip(0,itPhi->StripChCl),0.0);
00601             hsilcl->SetPhiClusterSignal((Float_t) itPhi->AdcValCl );
00602             hsilcl->SetPhiClusterNoise((Float_t) itPhi->NoiseCl);
00603             hsilcl->SetZetaClusterSignal(-1.);
00604             hsilcl->SetZetaClusterNoise(-1.); 
00605             hsilcl->SetDEDxPhi(-1.);
00606             hsilcl->SetDEDxZeta(-1.);
00607           }
00608         } //end loop on phi cluster
00609         // reloop on remaining zeta clusters
00610         if (!ZetaSilCluster.empty()) {
00611           for(std::vector<SILCLRAW>::iterator itZeta = ZetaSilCluster.begin(); itZeta < ZetaSilCluster.end(); itZeta++){
00612             TFndHSilCluster * hsilcl = TFndRun::fgFinHdt->Add_SilCluster(nlay);
00613             //
00614             hsilcl->SetModNum(nmod);
00615             hsilcl->SetGoodCl(0);
00616             hsilcl->SetIDCl(0);
00617             hsilcl->SetClusterPhiAdcCh(-1.);
00618             hsilcl->SetClusterZetaAdcCh((Float_t) itZeta->AdcChCl);
00619             hsilcl->SetLocalPosition(0.0,0.0,TFndGeometry::SilPositionStrip(1,itZeta->StripChCl));
00620             hsilcl->SetPhiClusterSignal(-1.);
00621             hsilcl->SetPhiClusterNoise(-1.);
00622             hsilcl->SetZetaClusterSignal((Float_t) itZeta->AdcValCl);
00623             hsilcl->SetZetaClusterNoise((Float_t) itZeta->NoiseCl); 
00624             hsilcl->SetDEDxPhi(-1.);
00625             hsilcl->SetDEDxZeta(-1.);
00626           }
00627         }
00628       } else if (!PhiSilCluster.empty()) {
00629         for(std::vector<SILCLRAW>::iterator itPhi = PhiSilCluster.begin(); itPhi < PhiSilCluster.end(); itPhi++){ 
00630           TFndHSilCluster * hsilcl = TFndRun::fgFinHdt->Add_SilCluster(nlay);
00631           //
00632           hsilcl->SetModNum(nmod);
00633           hsilcl->SetGoodCl(0);
00634           hsilcl->SetIDCl(0);
00635           hsilcl->SetClusterPhiAdcCh((Float_t) itPhi->AdcChCl);
00636           hsilcl->SetClusterZetaAdcCh(-1.);
00637           hsilcl->SetLocalPosition(0.0,TFndGeometry::SilPositionStrip(0,itPhi->StripChCl),0.0);
00638           hsilcl->SetPhiClusterSignal((Float_t) itPhi->AdcValCl );
00639           hsilcl->SetPhiClusterNoise((Float_t) itPhi->NoiseCl);
00640           hsilcl->SetZetaClusterSignal(-1.);
00641           hsilcl->SetZetaClusterNoise(-1.); 
00642           hsilcl->SetDEDxPhi(-1.);
00643           hsilcl->SetDEDxZeta(-1.);
00644         }
00645       } else if (!ZetaSilCluster.empty()) {
00646         for(std::vector<SILCLRAW>::iterator itZeta = ZetaSilCluster.begin(); itZeta < ZetaSilCluster.end(); itZeta++){
00647           TFndHSilCluster * hsilcl = TFndRun::fgFinHdt->Add_SilCluster(nlay);
00648           //
00649           hsilcl->SetModNum(nmod);
00650           hsilcl->SetGoodCl(0);
00651           hsilcl->SetIDCl(0);
00652           hsilcl->SetClusterPhiAdcCh(-1.);
00653           hsilcl->SetClusterZetaAdcCh((Float_t) itZeta->AdcChCl);
00654           hsilcl->SetLocalPosition(0.0,0.0,TFndGeometry::SilPositionStrip(1,itZeta->StripChCl));
00655           hsilcl->SetPhiClusterSignal(-1.);
00656           hsilcl->SetPhiClusterNoise(-1.);
00657           hsilcl->SetZetaClusterSignal((Float_t) itZeta->AdcValCl);
00658           hsilcl->SetZetaClusterNoise((Float_t) itZeta->NoiseCl); 
00659           hsilcl->SetDEDxPhi(-1.);
00660           hsilcl->SetDEDxZeta(-1.);
00661         }
00662       } // end if cluster empty
00663     } // end of module loop
00664   } // end of layer loop
00665   //
00666   //
00667   // TFndHSilCluster * hsilcl = TFndRun::fgFinHdt->Add_SilCluster(layer);
00668   // hsilcl->SetModNum(Int_t mod_num);
00669   //
00670   // hit creation (or update) completed
00671   //
00672 }
00673 
00674 
00675 //____________________________________
00676 void TFndRdt::FillTofHits() {
00677   
00678   UInt_t *det = GetDetector(FIN_RDT_Eqp_Tof);  
00679   if (det==NULL){
00680     if(fDebugLev > 0) Warning("FillTofHits","detector not in the run (null pointer)");
00681     return;
00682   }
00683   
00684   FillTofAdcHits(det);
00685   FillTofTdcHits(det);
00686 }
00687 
00688 //____________________________________
00689 void TFndRdt::FillTofAdcHits(UInt_t *det) {
00690 
00691   UInt_t deb_tof = (fDebugLev >> ((Int_t)(D_TOF)*4)) & 0xF; // get tof digit
00692 
00693   // ADC equipment
00694   if(deb_tof) Printf("TFndRdt::FillTofAdcHits ---> ADC equipment");
00695   UInt_t *eqp = GetEquipment( FIN_RDT_Eqp_Tof, FIN_EQ_CAEN_VN1485 );
00696   if(!eqp){
00697     Error("FillTofAdcHits","Pointer to the required equipment is NULL");
00698     return;
00699   }
00700   UInt_t *ladcptr=eqp+1;
00701   if(!ladcptr){
00702     Error("FillTofAdcHits","Pointer to the adc structure is NULL");    
00703     return;
00704   }
00705 
00706   if(eqp[0] <= 0 || eqp[0] > K_MAX_EQP_LEN) {
00707     Error("FillTofAdcHits","adc length not accepted: value= %u",eqp[0]);
00708     return;
00709   }
00710   UInt_t ladclen=eqp[0]-1;
00711   if(deb_tof) Printf("TFndRdt::FillTofAdcHits ---> ADC length: %u",ladclen);  
00712   if(ladclen == 0 ) return;
00713 
00714   Int_t tof_adc_cnt = 0;
00715   Int_t tof_adc_chn = 0;
00716   Int_t tof_adc_brd = 0;
00717 
00718   Int_t n_conv = 0;  
00719 
00720   Int_t tof_bit = 0; // check if the current value is valid
00721   Int_t cur_slab = 0;
00722   Int_t is_side_p = -1; // 0:e-side ; 1: p-side
00723 
00724   //  Bool_t is_new_hit = kFALSE;
00725   
00726   Int_t i=0;
00727   while(i < (Int_t) ladclen-1) {
00728     if(i>0) { ladcptr++; i++; }
00729     n_conv = *ladcptr;
00730     if(deb_tof) Printf( "TFndRdt::FillTofAdcHits ---> %d conversions",n_conv);
00731     for(Int_t k=0;k<n_conv;k++) {
00732       i++;
00733       ladcptr++;
00734       tof_bit = (Int_t) ((*ladcptr)>>0xD)&0x1;
00735       if(tof_bit != 0) { continue; }
00736       tof_adc_cnt = (Int_t) (*ladcptr)&0xFFF;
00737       tof_adc_chn = (Int_t) ((*ladcptr)>>0x10)&0x3F;
00738       tof_adc_brd = (Int_t) ((*ladcptr)>>0x17)&0x1F;
00739       if(deb_tof > 1) {
00740         Printf("TFndRdt::FillTofAdcHits ---> conv: %d ; EvtBuf Ch-data = 0x%x",k,(Int_t) (*ladcptr));
00741         Printf("TFndRdt::FillTofAdcHits -----> conv: %d ; tof_adc_cnt = %d",k,tof_adc_cnt);
00742         Printf("TFndRdt::FillTofAdcHits -----> conv: %d ; tof_adc_chn = %d",k,tof_adc_chn);
00743         Printf("TFndRdt::FillTofAdcHits -----> conv: %d ; tof_adc_brd = %d",k,tof_adc_brd);
00744       }
00745       //      cur_slab = fFndFeeMap->GetTofAdcSlb(tof_adc_brd-1,tof_adc_chn);
00746       cur_slab = fFndFeeMap->GetTofAdcSlb(tof_adc_brd,tof_adc_chn);
00747       //      is_side_p = fFndFeeMap->GetTofAdcSide(tof_adc_brd-1,tof_adc_chn);
00748       is_side_p = fFndFeeMap->GetTofAdcSide(tof_adc_brd,tof_adc_chn);
00749       if(deb_tof > 2) {
00750         Printf("TFndRdt::FillTofAdcHits --------> conv: %d ; cur_slab = %d",k,cur_slab);
00751         Printf("TFndRdt::FillTofAdcHits --------> conv: %d ; is_side_p = %d",k,is_side_p);
00752       }
00753       if(cur_slab <= 0 || cur_slab > 172){
00754         if(deb_tof > 2 && fCurRunType != RT_PEDE) Warning("FillTofAdcHits","Event %d: Adc board: %d, ch: %d not mapped inside DB",fRawEvent[2],tof_adc_brd,tof_adc_chn);
00755         continue;
00756       }
00757       if(cur_slab>300){
00758         Error("FillTofAdcHits","cur_slab (%d) should never occur with ADC",cur_slab);
00759         TerminateFroot();
00760       }
00761       // the raw-datum reading is completed: now create or update hits  
00762       TFndRun::fgFinHdt->Find_Add_TofHit(cur_slab,kTRUE)->SetAdc(tof_adc_cnt,(E_Fnd_Side)is_side_p);
00763       // hit creation (or update) completed
00764     }
00765     i++;
00766     ladcptr++;
00767   }
00768   if(deb_tof) Printf("TFndRdt::FillTofAdcHits ---> exiting method");
00769 }
00770  
00771 //____________________________________
00772 void TFndRdt::FillTofTdcHits(UInt_t *det) {
00773   //  Bool_t fCheckHit_Tofino[K_N_SLABS_TOFINO];
00774   //  Bool_t fCheckHit_Tofone[K_N_SLABS_TOFONE];
00775     
00776   UInt_t deb_tof = (fDebugLev >> ((Int_t)(D_TOF)*4)) & 0xF; // get tof digit
00777 
00778   // TDC equipment
00779   if(deb_tof) Printf("TFndRdt::FillTofTdcHits ---> TDC equipment");
00780   UInt_t *eqp = GetEquipment( FIN_RDT_Eqp_Tof, FIN_EQ_CAEN_VN1488 );  
00781   if(!eqp){
00782     Error("FillTofTdcHits","Pointer to the required equipment is NULL");
00783     return;
00784   }
00785   UInt_t *ltdcptr = eqp+1;
00786   if(!ltdcptr){
00787     Error("FillTofTdcHits","Pointer to the tdc structure is NULL");    
00788     return;
00789   }
00790 
00791   if(eqp[0] <= 0 || eqp[0] > K_MAX_EQP_LEN) {
00792     Error("FillTofTdcHits","tdc length not accepted: value= %u",eqp[0]);
00793     return;
00794   }
00795   UInt_t ltdclen = eqp[0]-1;  
00796   if(deb_tof) Printf("TFndRdt::FillTofTdcHits ---> TDC length: %u",ltdclen);
00797   if(ltdclen == 0 ) return;
00798 
00799   Int_t tof_tdc_cnt = 0;
00800   Int_t tof_tdc_chn = 0; 
00801   Int_t tof_tdc_brd = 0;
00802   
00803   Int_t n_conv = 0;  // number of conversions
00804   Int_t tof_bit = 0; // check if the current value is valid
00805   
00806   Int_t tdcslb1 = 0; // SLAB number for CFD TDC (1-12: low-threshold; 300-312: high-threshold)
00807   Short_t is_side_p  = -1; // 0:e-side ; 1: p-side
00808   Int_t tdcmt1 = 0; // SLAB number for mean-timer TDC (1-12: low-threshold; 300-312: high-threshold)
00809   
00810   UShort_t WhichMod = 0;
00811   //  Bool_t is_new_hit = kFALSE;
00813   // --- available module types are:                                                //
00814   //       - CFD (Constant-Fraction-Discriminator) [low-threshold / high-threshold] //
00815   //       - MT  (Mean-Timer) [low-threshold / high-threshold]                      //
00816   //   They are identified by a 2-bit mask:                                         //
00817   //               - bit 0: threshold   (0: Low ; 1: High)                          //
00818   //               - bit 1: module type (0: CFD ; 1: MT)                            //
00819   //                                                                                //
00820   //                                                                                //
00821   //       UShort_t w = 0;                                                          //
00822   //       w = (w & (0x1));  // select cfd                                          //
00823   //       w = (w | (1<<1)); // select mt                                           //
00824   //       w = (w | (0x1));  // select high thr                                     //
00825   //       w = (w & (0x2));  // select low thr                                      //
00826   //                                                                                //
00827   //   The result is:                                                               //
00828   //     switch(w){                                                                 //
00829   //       case 0: [... CFD-LOW ...]                                                //
00830   //       case 1: [... CFD-HIGH ...]                                               //
00831   //       case 2: [... MT-LOW ...]                                                 //
00832   //       case 3: [... MT-HIGH ...]                                                //
00833   //     }                                                                          //
00834   //                                                                                //
00836 
00837   Int_t i=0;
00838   while(i < (Int_t) ltdclen-1) { // check "-1"
00839     if(i>0) { ltdcptr++; i++; }
00840     n_conv = *ltdcptr;
00841     if(deb_tof) Printf( "TFndRdt::FillTofTdcHits ---> %d conversions",n_conv);
00842     for(Int_t k=0;k<n_conv;k++) {
00843       i++;
00844       ltdcptr++;
00845       tof_bit = (Int_t) ((*ltdcptr)>>0xD)&0x1;
00846       if(tof_bit != 0) { continue; }
00847       tof_tdc_cnt = (Int_t) (*ltdcptr)&0xFFF;
00848       tof_tdc_chn = (Int_t) ((*ltdcptr)>>0x10)&0x3F;
00849       tof_tdc_brd = (Int_t) ((*ltdcptr)>>0x17)&0x1F;
00850       if(((Int_t) ((*ltdcptr)>>0xD)&0x2) != 0 && fCurRunType != RT_PEDE){
00851         cout << "TFndRdt::FillTofTdcHits Warning---> Tdc NO_HIT bit detected: event " << fRawEvent[2] << "; board: " << tof_tdc_brd << "; ch: " << tof_tdc_chn << endl;
00852         //Printf("TFndRdt::FillTofTdcHits Warning---> Tdc NO_HIT bit detected: event %d; board: %d, ch: %d",fRawEvent[2],tof_tdc_brd,tof_tdc_chn);
00853         continue;
00854       }
00855       if(deb_tof > 1) {
00856         Printf("TFndRdt::FillTofTdcHits ---> conv: %d ; EvtBuf Ch-data = 0x%x",k,(Int_t) (*ltdcptr));
00857         Printf("TFndRdt::FillTofTdcHits -----> conv: %d ; tof_tdc_cnt = %d",k,tof_tdc_cnt);
00858         Printf("TFndRdt::FillTofTdcHits -----> conv: %d ; tof_tdc_chn = %d",k,tof_tdc_chn);
00859         Printf("TFndRdt::FillTofTdcHits -----> conv: %d ; tof_tdc_brd = %d",k,tof_tdc_brd);
00860       }
00861       tdcmt1 = fFndFeeMap->GetTofMTSlb(tof_tdc_brd,tof_tdc_chn);
00862       tdcslb1 = fFndFeeMap->GetTofTdcSlb(tof_tdc_brd,tof_tdc_chn);
00863       is_side_p = (Short_t) fFndFeeMap->GetTofTdcSide(tof_tdc_brd,tof_tdc_chn); 
00864       if(deb_tof > 2) {
00865         Printf("TFndRdt::FillTofTdcHits --------> conv: %d ; tdcslb1 = %d",k,tdcslb1);
00866         Printf("TFndRdt::FillTofTdcHits --------> conv: %d ; tdcmt1 = %d",k,tdcmt1);
00867         Printf("TFndRdt::FillTofTdcHits --------> conv: %d ; is_side_p = %d",k,is_side_p);
00868       }
00869       if(tdcslb1 == 0 && tdcmt1 == 0){
00870         if(deb_tof && fCurRunType != RT_PEDE) Warning("FillTofTdcHits","Event %d: Tdc board: %d, ch: %d not mapped inside DB",fRawEvent[2],tof_tdc_brd,tof_tdc_chn);
00871         continue;
00872       }
00873       // the raw-datum reading is completed: now building (or updating) the hit
00874       WhichMod = 0;
00875       //is_new_hit = kFALSE;
00876       if     (tdcslb1 != 0 && tdcmt1 == 0) WhichMod = (WhichMod & (0x1));
00877       else if(tdcslb1 == 0 && tdcmt1 != 0) WhichMod = (WhichMod | (1<<1));
00878       else{
00879         Error("FillTofTdcHits","Ambiguous module selection");
00880         //gApplication->Terminate(); // this line has been commented on June 12, 2007
00881         continue; // this line has been added on June 12, 2007
00882       }
00883       
00884       if     (tdcslb1 > 300) { WhichMod = (WhichMod | (0x1)); tdcslb1 -= 300; }
00885       else if( tdcmt1 > 300) { WhichMod = (WhichMod | (0x1)); tdcmt1 -= 300; }
00886       //        else WhichMod = (WhichMod & (0x2));
00887 
00888       TFndHTof *htof;
00889       if((WhichMod & (0x2)) == 0) htof = TFndRun::fgFinHdt->Find_Add_TofHit(tdcslb1,kTRUE);
00890       else htof = TFndRun::fgFinHdt->Find_Add_TofHit(tdcmt1,kTRUE);
00891 
00892       switch(WhichMod){
00893       case 0: htof->SetLowTdc(tof_tdc_cnt,(E_Fnd_Side)is_side_p);     break;
00894       case 1: htof->SetHighTdc(tof_tdc_cnt,(E_Fnd_Side)is_side_p); break;
00895       case 2: htof->SetLowMeanTimer(tof_tdc_cnt);         break;
00896       case 3: htof->SetHighMeanTimer(tof_tdc_cnt);     break;
00897       default: 
00898         Error("FillTofTdcHits","Don't know what to do :(");
00899         gApplication->Terminate();
00900       }
00901 
00902     }
00903   }
00904 
00905   if(deb_tof) Printf("TFndRdt::FillTofTdcHits ---> exiting method");
00906 } 
00907 
00908 //____________________________________
00909 void TFndRdt::FillLmdHits() {
00910 
00911   UInt_t *det = GetDetector(FIN_RDT_Eqp_Lmd);  
00912   if (det==NULL){
00913     if(fDebugLev > 0) Warning("FillLmdHits","detector not in the run (null pointer)");
00914     return;
00915   }
00916   
00917   FillLmdAdcHits();
00918   FillLmdTdcHits();
00919 }
00920 
00921 //____________________________________
00922 void TFndRdt::FillLmdAdcHits() {
00923   // Rewritten (September 2006)
00924   
00925   UInt_t deb_lmd = (fDebugLev >> ((Int_t)(D_LMD)*4)) & 0xF; // get sil digit
00926 
00927   if(deb_lmd) Printf("TFndRdt::FillLmdAdcHits ---> ADC equipment");
00928   UInt_t *equ = GetEquipment( FIN_RDT_Eqp_Lmd, FIN_EQ_CAEN_VN1485 );
00929   if(!equ){
00930     Error("FillLmdAdcHits","Pointer to the required equipment is NULL");
00931     return;
00932   }
00933   UInt_t *ladcptr=equ+1;
00934   if(!ladcptr){
00935     Error("FillLmdAdcHits","Pointer to the adc structure is NULL");    
00936     return;
00937   }
00938   
00939   if(equ[0] <= 0 || equ[0] > K_MAX_EQP_LEN) {
00940     Error("FillLmdAdcHits","adc length not accepted: value= %u",equ[0]);
00941     return;
00942   }
00943   Int_t ladclen=(Int_t)(equ[0]-1);
00944   if(deb_lmd) Printf("TFndRdt::FillLmdAdcHits ---> ADC length: %u",ladclen);
00945   if(ladclen == 0) return;
00946   // if you are here ladclen is a valid number  
00947 
00948   //  equ = find_equ(ev,LMD,EQ06);
00949   Int_t conv_counter = 0;
00950   if (equ) for (int k=1,h=0; k<equ[0]; k++,h--) {
00951     if (h==0) {
00952       h = (equ[k]&0x7FF) + 1;  k++;
00953       if(deb_lmd) Printf( "TFndRdt::FillLmdAdcHits ---> %d conversions",h-1);
00954       conv_counter=0;
00955     }
00956     if (h==1) continue;
00957     
00958     int mod = ((equ[k]>>23) & 0x1F); //lmd_adc_brd
00959     int cha = (equ[k]>>16) & 0x3F; // lmd_adc_chn
00960     float val = (float)(equ[k] & 0xFFF); // lmd_adc_cnt
00961 
00962     Int_t lmd_adc_cnt = (Int_t)val;
00963     Int_t lmd_adc_chn = cha;
00964     Int_t lmd_adc_brd = mod;
00965     if(deb_lmd > 1) {
00966       Printf("TFndRdt::FillLmdAdcHits ---> conv: %d ; EvtBuf Ch-data = 0x%x",conv_counter,(Int_t)equ[k]);
00967       Printf("TFndRdt::FillLmdAdcHits -----> conv: %d ; lmd_adc_cnt = %d",conv_counter,lmd_adc_cnt);
00968       Printf("TFndRdt::FillLmdAdcHits -----> conv: %d ; lmd_adc_chn = %d",conv_counter,lmd_adc_chn);
00969       Printf("TFndRdt::FillLmdAdcHits -----> conv: %d ; lmd_adc_brd = %d",conv_counter,lmd_adc_brd);
00970     }
00971     
00972     Int_t adcdch1 = 0;
00973     Int_t adcwir1 = 0;
00974     Short_t is_side_p = -1;
00975     if(!fFndFeeMap->IsThere()) continue;
00976     //    if(fFndFeeMap->IsThere()){
00977     adcdch1 = fFndFeeMap->GetLmdAdcDch(lmd_adc_brd,lmd_adc_chn);
00978     if(adcdch1<=0) continue;
00979     adcwir1 = fFndFeeMap->GetLmdAdcWire(lmd_adc_brd,lmd_adc_chn);
00980     is_side_p = (Short_t) fFndFeeMap->GetLmdAdcSide(lmd_adc_brd,lmd_adc_chn);
00981     if(deb_lmd > 2) {
00982       Printf("TFndRdt::FillLmdAdcHits --------> conv: %d ; adcdch1 = %d",conv_counter,adcdch1);
00983       Printf("TFndRdt::FillLmdAdcHits --------> conv: %d ; adcwir1 = %d",conv_counter,adcwir1);
00984       Printf("TFndRdt::FillLmdAdcHits --------> conv: %d ; is_side_p = %d",conv_counter,is_side_p);
00985     }
00986     conv_counter++;
00987     
00988     TFndHLmd *check_hit; // can be used for debuggin purposes
00989     check_hit = TFndRun::fgFinHdt->Find_Add_LmdHit(TFndDB::Lmd_ChannelToDBNumbering(adcdch1,adcwir1),kTRUE);
00990     check_hit->SetAdc(lmd_adc_cnt,(E_Fnd_Side)is_side_p);
00991     
00992     if(deb_lmd > 3) check_hit->PrintHit(1);
00993     
00994   }
00995   
00996   if(deb_lmd) Printf("TFndRdt::FillLmdAdcHits ---> exiting method");
00997 }
00998 
00999 //____________________________________
01000 void TFndRdt::FillLmdTdcHits() {
01001   // Rewritten (September 2006)
01002   
01003   UInt_t deb_lmd = (fDebugLev >> ((Int_t)(D_LMD)*4)) & 0xF; // get sil digit
01004   Int_t run_time = fndrun->GetRunTime();
01005   
01006   //  TDC equipment
01007   E_FIN_RDT_EqpID tdceqpnum = FIN_EQ_LECROY_1277;
01008   if(run_time > Fee_Lmd_NewTdcsTime) tdceqpnum = FIN_EQ_CAEN_673A;
01009   if(deb_lmd) Printf("TFndRdt::FillLmdTdcHits ---> TDC equipment");
01010   
01011   UInt_t *equ = GetEquipment( FIN_RDT_Eqp_Lmd, tdceqpnum );
01012   if(!equ){
01013     if( fCurRunType != (Int_t)(RT_PEDE) )
01014       Error("FillLmdTdcHits","Pointer to the required equipment is NULL");
01015     return;
01016   }
01017 
01019   UInt_t *ltdcptr=equ+1;
01020   if(!ltdcptr){
01021     Error("FillLmdTdcHits","Pointer to the tdc structure is NULL");    
01022     return;
01023   }
01024 
01025   if(equ[0] <= 0 || equ[0] > K_MAX_EQP_LEN) {
01026     Error("FillLmdTdcHits","tdc length not accepted: value= %u",equ[0]);
01027     return;
01028   }
01029   UInt_t ltdclen=equ[0]-1;
01030   if(deb_lmd) Printf("TFndRdt::FillLmdTdcHits ---> TDC length: %u",ltdclen);
01031   if(ltdclen == 0) return;
01033   // if you are here ltdclen is a valid number  
01034   
01035   //-------------------------------------------------------------
01036   //-----------> (LMD, eqp 10) vme tdc 6U CAEN VN673A  <----------
01037   //-------------------------------------------------------------
01038   //  equ = find_equ(ev,LMD,EQ10);
01039   Int_t iboard_offset = 0;
01040   int h=0;
01041   int k=1;
01042   if (equ) while ( k<equ[0]-1) {
01043     h = (equ[k]&0xFFFF); // number of conversions
01044     if(deb_lmd) Printf( "TFndRdt::FillLmdTdcHits ---> %d conversions",h);
01045     int lmd_tdc_brd = ((equ[k]>>26) & 0xF); //lmd_tdc_brd
01046     k++;
01047     for(int i=0;i<h;i++,k++){
01048       int isval = (equ[k]>>31)&0x1; // isvalid
01049       if(isval==0){
01050         int lmd_tdc_chn = (equ[k]>>18) & 0x3F; // lmd_tdc_chn
01051         Int_t lmd_tdc_cnt = (equ[k] & 0xFFFF); // (don't know)
01052         //      float lmd_tdc_cnt = (float)(equ[k] & 0xFFFF); // (don't know)
01053         lmd_tdc_brd = ((equ[k]>>26) & 0xF); // lmd_tdc_brd
01054 
01055         // --- comparison with read_lib variables
01056         //      Int_t lmd_tdc_cnt = (Int_t)val;
01057         //      Int_t lmd_tdc_chn = cha; 
01058         //      Int_t lmd_tdc_brd = mod;
01059         if(deb_lmd > 1) {
01060           Printf("TFndRdt::FillLmdTdcHits ---> conv: %d ; EvtBuf Ch-data = 0x%x",k,(Int_t)equ[k]);
01061           Printf("TFndRdt::FillLmdTdcHits -----> conv: %d ; lmd_tdc_cnt = %d",k,lmd_tdc_cnt);
01062           Printf("TFndRdt::FillLmdTdcHits -----> conv: %d ; lmd_tdc_chn = %d",k,lmd_tdc_chn);
01063           Printf("TFndRdt::FillLmdTdcHits -----> conv: %d ; lmd_tdc_brd = %d",k,lmd_tdc_brd);
01064         }       
01065         Int_t tdcdch1 = 0;
01066         Int_t tdcwir1 = 0;
01067         Int_t is_side_p  = -1;
01068         if(!fFndFeeMap->IsThere() || isval != 0) continue;
01069           tdcdch1 = fFndFeeMap->GetLmdTdcDch(lmd_tdc_brd-iboard_offset,lmd_tdc_chn);
01070           if(tdcdch1<=0) continue;
01071           tdcwir1 = fFndFeeMap->GetLmdTdcWire(lmd_tdc_brd-iboard_offset,lmd_tdc_chn);
01072           is_side_p = fFndFeeMap->GetLmdTdcSide(lmd_tdc_brd-iboard_offset,lmd_tdc_chn); 
01073 
01074           if(deb_lmd > 2) {
01075             Printf("TFndRdt::FillLmdTdcHits --------> conv: %d ; tdcdch1 = %d",k,tdcdch1);
01076             Printf("TFndRdt::FillLmdTdcHits --------> conv: %d ; tdcwir1 = %d",k,tdcwir1);
01077             Printf("TFndRdt::FillLmdTdcHits --------> conv: %d ; is_side_p = %d",k,is_side_p);
01078           }
01079           
01080           TFndHLmd *check_hit; // can be used for debuggin purposes
01081           check_hit = TFndRun::fgFinHdt->Find_Add_LmdHit(TFndDB::Lmd_ChannelToDBNumbering(tdcdch1,tdcwir1),kTRUE);
01082           check_hit->SetTdc(lmd_tdc_cnt,(E_Fnd_Side)is_side_p);
01083 
01084           if(deb_lmd > 3) check_hit->PrintHit(1);
01085 
01086       }
01087     }
01088   }
01089   
01090   if(deb_lmd) Printf("TFndRdt::FillLmdTdcHits ---> exiting method");
01091 } 
01092 
01093 //____________________________________
01094 void TFndRdt::FillStbHits() {
01095   
01096   UInt_t *det = GetDetector(FIN_RDT_Eqp_Stb);  
01097   if (det==NULL){
01098     if(fDebugLev > 0) Warning("FillStbHits","detector not in the run (null pointer)");
01099     return;
01100   }
01101 
01102   UInt_t deb_stb = (fDebugLev >> ((Int_t)(D_STB)*4)) & 0xF; // get tof digit
01103   if(deb_stb) Printf("TFndRdt::FillStbHits ---> TDC equipment");
01104   
01105   UInt_t *equ = GetEquipment( FIN_RDT_Eqp_Stb, FIN_EQ_LECROY_1277 );
01106   if(!equ){
01107     Error("FillStbHits","Pointer to the required equipment is NULL");
01108     return;
01109   }
01110   UInt_t *ltdcptr = equ+1;
01111   if(!ltdcptr){
01112     Error("FillStbHits","Pointer to the tdc structure is NULL");    
01113     return;
01114   }
01115 
01116   if(equ[0] <= 0 || equ[0] > K_MAX_EQP_LEN) {
01117     if(deb_stb) Printf("TFndRdt::FillStbTdcHits ---> exiting method (tdc length = %u)",equ[0]);
01118     return;
01119   }
01120   UInt_t ltdclen = equ[0]-1;
01121   if(deb_stb) Printf("TFndRdt::FillStbHits ---> TDC length: %u",ltdclen);
01122   if(ltdclen == 0) return;
01123   // if you are here ltdclen is a valid number  
01124  
01125   
01126 
01127   
01128   
01130   
01131   Int_t stb_tdc_cnt;
01132   Int_t stb_tdc_chn; 
01133   Int_t stb_tdc_brd;
01134   Int_t i=0;
01135 
01136   // UInt_t *end = ltdcptr + (*ltdcptr); TEST
01137   // while(ltdcptr < end) { // TEST
01138   while(i < (Int_t) ltdclen-1) { 
01139     //            if(i>0) { ltdcptr++; i++; } // BUG (infinite loop!)
01140     Int_t n_conv = (*ltdcptr)&0xFFFFFF;
01141     Int_t n_cage = ((*ltdcptr)>>0x18)&0xF;
01142     ltdcptr++; i++; // Diego and Giuseppe bugfix (moved to this line by D. Faso)
01143     if(deb_stb) Printf( "TFndRdt::FillStbTdcHits ---> %d conversions",n_conv);
01144     for(Int_t k=0;k<n_conv;k++) {
01145       stb_tdc_cnt = (Int_t) (*ltdcptr)&0xFFFF;
01146       stb_tdc_chn = (Int_t) ((*ltdcptr)>>0x11)&0x7F;
01147       stb_tdc_brd = (Int_t) ((*ltdcptr)>>0x1B)&0x1F;
01148       i++;
01149       ltdcptr++;
01150       if(stb_tdc_brd < 6 || stb_tdc_brd > 19){
01151         Warning("FillStbHits","board %d ",stb_tdc_brd); 
01152         continue;
01153       }      
01154       if(stb_tdc_chn < 0 || stb_tdc_chn > 95){
01155         Warning("FillStbHits","channel %d",stb_tdc_chn);
01156         continue;        
01157       } 
01158       if(deb_stb > 1) {
01159         Printf("TFndRdt::FillStbHits ---> conv: %d ; EvtBuf Ch-data = 0x%x",k,(UInt_t) (*ltdcptr));
01160         Printf("TFndRdt::FillStbHits -----> conv: %d ; stb_tdc_cnt = %d",k,stb_tdc_cnt);
01161         Printf("TFndRdt::FillStbHits -----> conv: %d ; stb_tdc_chn = %d",k,stb_tdc_chn);
01162         Printf("TFndRdt::FillStbHits -----> conv: %d ; stb_tdc_brd = %d",k,stb_tdc_brd);
01163       }
01164       // map stb tdc channel to stb wire
01165         
01166       Int_t crown = 0;
01167       Int_t tube  = 0;
01168       Int_t ppanel = 0;
01169       if(fFndFeeMap->IsThere()) {
01170         crown  = fFndFeeMap->GetStbCrown(n_cage,stb_tdc_brd,stb_tdc_chn);
01171         tube   = fFndFeeMap->GetStbWire(n_cage,stb_tdc_brd,stb_tdc_chn);
01172         ppanel = fFndFeeMap->GetStbPatchPanel(n_cage,stb_tdc_brd,stb_tdc_chn);
01173       }
01174       if(deb_stb > 2) {
01175         Printf("TFndRdt::FillStbHits --------> conv: %d ; crown   = %d",k,crown);
01176         Printf("TFndRdt::FillStbHits --------> conv: %d ; tube    = %d",k,tube);
01177         Printf("TFndRdt::FillStbHits --------> conv: %d ; p-panel = %d",k,ppanel);
01178       }
01179         
01180       if(crown < 1 || crown > 6){
01181         // Printf("TFndRdt::FillStbHits WARNING: crown %d ( skipping hit )",crown);
01182         continue;
01183       }
01184       if(tube < 1 || tube > 404){
01185         Printf("TFndRdt::FillStbHits WARNING: tube %d ( skipping hit )",tube);
01186         continue;
01187       }
01188         
01189       TFndHStb *hs = TFndRun::fgFinHdt->Find_Add_StbHit(TFndDB::Stb_ChannelToDBNumbering(crown,tube),kTRUE);
01190       hs->SetTdc(stb_tdc_cnt);
01191       hs->SetPatchPanel(ppanel);
01192       //        Printf("crown %d - tube %d - channel %d ===> tdc value: %d ; PPan: %d",crown, tube, TFndDB::Stb_ChannelToDBNumbering(crown,tube),stb_tdc_chn,ppanel);
01193       //        fCurHdtEv->AddStbHit(crown,tube,ppanel,stb_tdc_cnt);
01194       //        n_stb_hit++;
01195     }
01196   }
01197 
01198   if(deb_stb) Printf("TFndRdt::FillStbHits ---> exiting method");
01199 }

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