• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

beamtime/cosy-jan12/go4/GEM/TGEMProc.cxx (r4864/r3159)

Go to the documentation of this file.
00001 /* Generated by Together */
00002 
00003 #include "TGEMProc.h"
00004 #include "TCBMBeamtimeEvent.h"
00005 #include "TGo4Version.h"
00006 #if __GO4BUILDVERSION__ > 40502
00007 #include "go4iostream.h"
00008 #else
00009 #include "Riostream.h"
00010 #endif
00011 #include "TGo4UserException.h"
00012 #include "TGo4MbsEvent.h"
00013 #include "roc/Message.h"
00014 #include "roc/Board.h"
00015 #include "TGo4Log.h"
00016 
00017 
00018 // dec10 test beam
00019 //UChar_t       TGEMProc::fGEMRocIds[]={7,4,5,6};
00020 
00021 // Oct11 cern test beam
00022  UChar_t       TGEMProc::fGEMRocIds[]={9,7};
00023  UChar_t           TGEMProc::fGEMRocStripStation=7;
00024  UChar_t           TGEMProc::fGEMROCStripNx=0;
00025 
00026 
00027 
00028 // cern test mapp array, obtained from Saini
00029 
00030 Int_t nxch_adc_tot[2][128];
00031 Int_t nxch_tot[2][128];
00032 Int_t nxch_baseline[2][128];
00033 
00034 
00035 /*
00036 Int_t X[4][128]={     {2,3,4,5,6,7,8,9,10,11,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,
00037                         10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,
00038                         5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,
00039                         0,1,2,3,4},
00040                         {5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,
00041                         0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,
00042                         8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,11,2,3,4,5,6,7,8,9,10,2,3,4,5,6,7,
00043                         8,9,10,11},
00044 
00045                         {12,13,14,15,16,17,18,19,20,11,12,13,14,15,16,17,18,19,20,12,13,14,15,16,17,18,19,20,21,
00046                         22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,
00047                         16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,
00048                         12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,
00049                         19,20,21,22,11,12,13,14,15,16},
00050                         {17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,
00051                         12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,
00052                         18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,
00053                         13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,
00054                         20,12,13,14,15,16,17,18,19,20} };
00055 
00056 Int_t Y[4][128]={ {22,22,22,22,22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,20,20,20,20,20,20,20,20,20,20,
00057                         20,20,19,19,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,
00058                         17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,14,
00059                         14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,
00060                         12,12,12,12,11,11,11,11,11},
00061                         {11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,
00062                         8,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,
00063                         4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
00064                         0,0,0},
00065                         {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,
00066                         4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,8,8,
00067                         8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11},
00068                         {11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,14,
00069                         14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,
00070                         16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,
00071                         19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,22,
00072                         22,22,22,22,22,22,22,22} };
00073                                                                        
00074 */
00075 //
00076 
00077  Int_t X[4][128]={     {2,3,4,5,6,7,8,9,10,11,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,
00078                         10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,
00079                         5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,
00080                         0,1,2,3,4},
00081                         {5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,
00082                         0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,
00083                         8,9,10,11,0,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,11,2,3,4,5,6,7,8,9,10,2,3,4,5,6,7,
00084                         8,9,10,11},
00085                         {12,13,14,15,16,17,18,19,20,11,12,13,14,15,16,17,18,19,20,12,13,14,15,16,17,18,19,20,21,
00086                         22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,
00087                         16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,
00088                         12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,
00089                         19,20,21,22,11,12,13,14,15,16},
00090                         {17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,
00091                         12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,
00092                         18,19,20,21,22,11,12,13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,
00093                         13,14,15,16,17,18,19,20,21,22,12,13,14,15,16,17,18,19,20,21,22,11,12,13,14,15,16,17,18,19,
00094                         20,12,13,14,15,16,17,18,19,20} },
00095 
00096   Y[4][128]={ {22,22,22,22,22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,20,20,20,20,20,20,20,20,20,20,
00097                         20,20,19,19,19,19,19,19,19,19,19,19,19,18,18,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,
00098                         17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,14,
00099                         14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,12,
00100                         12,12,12,12,11,11,11,11,11},
00101                         {11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,
00102                         8,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,4,4,4,4,4,
00103                         4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,
00104                         0,0,0}, 
00105                         {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,
00106                         4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,8,8,
00107                         8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11},
00108                         {11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,14,
00109                         14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,
00110                         16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,
00111                         19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,22,
00112                         22,22,22,22,22,22,22,22} };
00113 //
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 //uint64_t oldtm=0;
00124 // float count_gem=0;
00125 // float count_trigger=0;
00126 // int aux_opt=2;
00127 // uint64_t first_trig_time=0;
00128 // uint64_t first_hit_time=0;
00129 // Bool_t firsttrig=kTRUE;
00130 // Bool_t firsthit=kTRUE;
00131 //  int status[1000];
00132 //  int status1[1000];
00133 //  int got=0;
00134 //  float total_got=0;
00135 //  float total_trigger=0;
00136 //uint64_t timeold;
00137 //int cellno=0;
00138 //int nevt=0;
00139 //float countsts=0;
00140 //float countstsgem=0;
00141 //float stsgem=0;
00142 //float stsgem0=0;
00143 //float stsgem1=0;
00144 //float close_ev=0;
00145 //float close_ev0=0;
00146 //float close_ev1=0;
00147 //
00148 //float X1[1000],Y1[1000];
00149 //int hittime0[1000],hittime1[1000];
00150 //int nhit1=0, nhit0=0;
00151 //float X0[1000],Y0[1000];
00152 //int ADC_C_0[1000];
00153 //int ADC_C_1[1000];
00154 //int tot_tr_ADC_0[1000];
00155 //int tot_tr_ADC_1[1000];
00156 //int tot_tr_X_0[1000];
00157 //int tot_tr_X_1[1000];
00158 //int tot_tr_Y_0[1000];
00159 //int tot_tr_Y_1[1000];
00160 //int TrN0[1000],TrN1[1000];
00161 //int32_t timediff0[1000];
00162 //int32_t timediff1[1000];
00163 //int32_t timests[1000];
00164 
00165 
00166 // channel numbers at the end of each y row
00167 Int_t  TGEMProc::fGEM_Y_BoundariesLeft[]        ={10,19,31,42,54,65,77,88,100,111,123,134,146,157,169,180,192,203,215,226,237,246,256};
00168 
00169 
00170 // number of channels for each row
00171 Int_t  TGEMProc::fGEM_Y_PeriodLeft[]    ={10,9,12,11,12,11,12,11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 11, 9, 10};
00172 
00173 // shift of each row with respect to left gem edge
00174 Int_t  TGEMProc::fGEM_Y_ShiftLeft[]     ={ 2, 2, 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2 };
00175 //Int_t  TGEMProc::fGEM_Y_ShiftLeft[] ={ 2, 2, 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2 };
00176 
00177 
00178 // left part (for roc 1)
00179 // channel numbers at the end of each y row
00180 Int_t  TGEMProc::fGEM_Y_BoundariesRight[]       ={ 9,19,30,42,53,65,76,88,99,111,122,134,145,157,168,180,191,203,214,226,237,247,256};
00181 
00182 // number of channels for each row
00183 Int_t  TGEMProc::fGEM_Y_PeriodRight[]   ={ 9,10,11,12,11,12,11,12,11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 10, 9};
00184 
00185 //shift of each row with respect to gem vertical middle line x=11
00186 Int_t  TGEMProc::fGEM_Y_ShiftRight[]    ={ 1, 0, 1, 0, 1, 0, 1, 0, 1 , 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ,0,1,0,1 };
00187 //Int_t  TGEMProc::fGEM_Y_ShiftRight[]   ={ 1, 0, 0, 0, 1, 0, 1, 0, 1 , 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 ,0,1,0,1 };
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 TGEMProc::TGEMProc(const char* name) :
00196 TCBMBeamtimeProc(name), 
00197 fRocInputEvent(0), 
00198 fOutputEvent(0), 
00199 fBeamEvent(0),
00200 fFiberHodEvent1(0),
00201 fFiberHodEvent2(0)
00202 {
00203    cout << "**** TGEMProc: Create instance " << name << endl;
00204    
00205     fPar = (TGEMParam*) MakeParameter("GEMPar", "TGEMParam");
00206 
00207     // do we need this? JAM
00208     for(int ir=0;ir<2;ir++){
00209         for(int ich=0;ich<128;ich++){
00210            nxch_adc_tot[ir][ich]=0;
00211            nxch_tot[ir][ich]=0;
00212            nxch_baseline[ir][ich]=0;
00213          }
00214       }
00215 
00216 
00217     for (int n=0;n<NUM_GEM_STATIONS;n++) {
00218           fGEMtm[n] = MakeTH1('I', Form("GEM/GEM%dtm", n), Form("Time correlation on GEM %d to trigger signal", n), 500, -1000., 4000.);
00219 
00220           fGEMtmGate[n]= MakeWinCond(Form("GEM/GEM%dtm_Gate", n), -20, 2000, fGEMtm[n]->GetName());;
00221 
00222             //lastGEMSync[n] = 0;
00223             //ft_GEMaux[n] = MakeTH1('I', Form("GEM/GEM%dtaux", n), Form("Time diff from GEM %d to AUX1 signal", n), 1000, 0., 4000.);
00224             fGEM_adc_corrected[n] = MakeTH1('I', Form("GEM/GEM%dadc_corr_time", n), Form("Corrected adc for GEM (time window) %d ", n), 1000, 0., 2500.);
00225             fGEM_adc[n] = MakeTH1('I', Form("GEM/GEM%dadc_raw", n), Form("UnCorrected adc for GEM %d ", n), 1000, 0., 2500.);
00226 
00227             //fGEM_timediff[n] = MakeTH1('I', Form("GEM/GEM%dtimediff", n), Form("time difference bet GEM %d hits", n), 1000, -50.,450.);
00228             //fGEM_cellcounts[n] = MakeTH1('I', Form("GEM/GEM%dcellcounts", n), Form("Cell counts for GEM %d ", n), 100, 0.,25.);
00229             //fGEM_ratio[n] = MakeTH1('I', Form("GEM/GEM%dratio", n), Form("ratio of counts bet AUX and GEM %d ", n), 1000, 0., 20.);
00230 
00231 
00232 
00233 
00234            fMappingSource[n]=MakeTH2('I', Form("GEM/GEM%d_Map_saini", n), Form("Hits of GEM 9saini map) %d ", n), NUM_GEM_X,0,NUM_GEM_X,NUM_GEM_Y,0,NUM_GEM_Y,"X","Y");
00235 
00236 
00237           fGEM_Map[n]=MakeTH2('I', Form("GEM/GEM%d_Map", n), Form("Hits of GEM %d ", n), NUM_GEM_X,0,NUM_GEM_X,NUM_GEM_Y,0,NUM_GEM_Y,"X","Y");
00238           fGEM_Map_Time[n]=MakeTH2('I', Form("GEM/GEM%d_Map_Timegated", n), Form("Hits of GEM %d under time gate", n), NUM_GEM_X,0,NUM_GEM_X,NUM_GEM_Y,0,NUM_GEM_Y,"X","Y");
00239 
00240           fGEM_Map_Adc[n]=MakeTH2('D', Form("GEM/GEM%d_Map_ADC", n), Form("ADC (corrected) of GEM %d ", n), NUM_GEM_X,0,NUM_GEM_X,NUM_GEM_Y,0,NUM_GEM_Y,"X","Y");
00241           fGEM_Map_Adc_Time[n]=MakeTH2('D', Form("GEM/GEM%d_Map_ADC_Timegated", n), Form("ADC (corrected) of GEM %d under time gate", n), NUM_GEM_X,0,NUM_GEM_X,NUM_GEM_Y,0,NUM_GEM_Y,"X","Y");
00242 
00243           fGEM_Strip[n]=MakeTH1('I', Form("GEM/GEM%d_Strip", n), Form("Hits of GEM %d ", n), NUM_STRIPS_Y,0,NUM_STRIPS_Y,"Y");
00244           fGEM_Strip_Time[n]=MakeTH1('I', Form("GEM/GEM%d_Strip_Timegated", n), Form("Hits of GEM %d under time gate", n), NUM_STRIPS_Y,0,NUM_STRIPS_Y,"Y");
00245           fGEM_Strip_Adc[n]=MakeTH1('I', Form("GEM/GEM%d_Strip_ADC", n), Form("ADC (corrected) of GEM %d", n), NUM_STRIPS_Y,0,NUM_STRIPS_Y,"Y");
00246           fGEM_Strip_Adc_Time[n]=MakeTH1('I', Form("GEM/GEM%d_Strip_ADC_Timegated", n), Form("ADC (corrected) of GEM %d under time gate", n), NUM_STRIPS_Y,0,NUM_STRIPS_Y,"Y");
00247 
00248 
00249 
00250 
00251 
00252      }
00253 
00254 
00255    //fnxCh_roc0 = MakeTH1('I', Form("GEM/nxch_roc0"), Form("Roc0 channel no "), 128, -0.5,127.5);
00256    //fnxCh_roc1 = MakeTH1('I', Form("GEM/nxch_roc1"), Form("Roc1 channel no "), 128, -0.5,127.5);
00257   //f_CloseTrg = MakeTH1('I', Form("GEM/GEM_clostrg"), Form("Close trigger to hit "), 1000, 0., 100.);
00258   //fGEM0_sts_timecorr=MakeTH2('I', Form("GEM/GEM0_sts_timecorr"), Form("gem0_sts_timediff"), 500,0,5000,500,0,5000,"sts","gem1");
00259   //fGEM1_sts_timecorr=MakeTH2('I', Form("GEM/GEM1_sts_timecorr"), Form("gem1_sts_timediff"), 500,0,5000,500,0,5000,"sts","gem1");
00260   //fGEM0_roc=MakeTH1('I', Form("GEM/GEM0_roc"), Form("gem_0_rocNo"), 10,-0.5,9.5);
00261   //fGEM_time0=MakeTH1('I', Form("GEM/GEM_time0"), Form("gem_timediff_0"), 500,0,5000);
00262   //fGEM_time1=MakeTH1('I', Form("GEM/GEM_time1"), Form("gem_timediff_1"), 500,0,5000);
00263   //fSTS_tme=MakeTH1('I', Form("GEM/sts_tme"), Form("sts_timediff"), 1000,-5000,5000);
00264   //ftrig_evt=MakeTH1('I', Form("GEM/trig_evt"), Form("trigger_evt"), 1000,0,500);
00265   //fTrigDiff=MakeTH1('I', Form("GEM/trig_diff"), Form("trig_diff"), 10000,0,50000);
00266 
00267   //fGEM_sts_ratio = MakeTH1('I', Form("GEM/GEM1_sts_ratio"), Form("ratio of counts bet sts and GEM"), 1000, 0., 20.);
00268   //fhit_ratio0=MakeTH2('I', Form("GEM/hit_ratio0"), Form("hit_rati0"), 200,0,200,100,0,2.);
00269   //fhit_ratio1=MakeTH2('I', Form("GEM/hit_ratio1"), Form("hit_ratio1"), 200,0,200,100,0.,2.);
00270   //fMotorPos=MakeTH2('I', Form("Epics/MotorPosition"), Form("GEM Motor"), 60,0,300,60,0,300,"X (mm)","Y (mm)");
00271   //fRoluPos=MakeTH2('I', Form("Epics/ROLUPosition"), Form("Rolu positions"), 35,0,35,35,0,35,"X (mm)","Y (mm)");
00272 //     fGEM_X_0 = MakeTH1('I', Form("GEM/GEM%dX0"), Form("Weighted X for GEM0 %d "), 1000, 0., 100.);
00273 //     fGEM_Y_0 = MakeTH1('I', Form("GEM/GEM%dY0"), Form("Weighted Y for GEM0 %d "), 1000, 0., 100.);
00274 //     fGEM_X_1 = MakeTH1('I', Form("GEM/GEM%dX1"), Form("Weighted X for GEM1 %d "), 1000, 0., 100.);
00275 //     fGEM_Y_1 = MakeTH1('I', Form("GEM/GEM%dY1"), Form("Weighted Y for GEM1 %d "), 1000, 0., 100.);
00276 //
00277 //for (int ir=0;ir<2;ir++) {
00278 //  fGEM_baseline[ir] = MakeTH1('I', Form("GEM/GEM%d_baseline", ir), Form("Baseline for ROC_ %d ", ir), 128, -0.5, 127.5);
00279 //}
00280   fratio0_evt=MakeTH1('I', Form("GEM/eff"), Form("evt by evt eff"), 100,0,10);
00281   fcellMult_evt=MakeTH1('I', Form("GEM/cellMult"), Form("evt by evt cell mult"), 100,0,10);
00282 
00283    printf("GEM Histograms created \n");
00284    fflush ( stdout);
00285 
00286  Init_GEM_Map();
00287 }
00288 
00289 TGEMProc::~TGEMProc()
00290 {
00291 }
00292 
00293 void TGEMProc::InitEvent(TGo4EventElement* outevnt)
00294 {
00295 // first assign input event:
00296 // since input event object is never discarded within processor lifetime,
00297 // we just search for subevent by name once to speed up processing  
00298 if(fRocInputEvent==0)
00299 {
00300         TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(GetInputEvent());
00301         if(btevent)
00302                 {
00303                         fRocInputEvent=dynamic_cast<TRocEvent*>(btevent->GetSubEvent("ROC"));
00304                 }       
00305         else
00306                 {
00307                         fRocInputEvent=dynamic_cast<TRocEvent*>(GetInputEvent());
00308                         
00309                 }
00310         if(fRocInputEvent==0) {
00311                 GO4_STOP_ANALYSIS_MESSAGE("**** TGEMProc: Fatal error: input event is not a TRocEvent!!! STOP GO4");
00312                 }   
00313 }
00314 
00315 // then assign output event
00316 // since output event object is never discarded within processor lifetime,
00317 // we just search for subevent by name once to speed up processing  
00318 if(fOutputEvent==0)
00319 {
00320    TCBMBeamtimeEvent* btevent=dynamic_cast<TCBMBeamtimeEvent*>(outevnt);
00321    if(btevent)
00322         {
00323                 fOutputEvent=dynamic_cast<TGEMEvent*>(btevent->GetSubEvent("GEM"));
00324                 fBeamEvent=dynamic_cast<TBeamMonitorEvent*>(btevent->GetSubEvent("BEAM"));
00325                 fFiberHodEvent1=dynamic_cast<TFiberHodEvent*>(btevent->GetSubEvent("Hodo1"));
00326                 fFiberHodEvent2=dynamic_cast<TFiberHodEvent*>(btevent->GetSubEvent("Hodo2"));
00327         }       
00328    else
00329         {
00330 
00331                 fOutputEvent= dynamic_cast<TGEMEvent*>(outevnt);
00332         }
00333    if(fOutputEvent==0) {
00334         GO4_STOP_ANALYSIS_MESSAGE("**** TGEMProc: Fatal error: output event is not a TGEMEvent!!! STOP GO4");
00335         }
00336 
00337 }
00338 
00339 }
00340 
00341 
00342 void TGEMProc::FinalizeEvent()
00343 {
00344    if (!fRocInputEvent->IsValid())
00345       return; // skip incomplete roc events from first step t
00346 
00347 //   printf("Event time in GEM %14.9f\n", fRocInputEvent->GetEventTime());
00348 
00349 
00350 //   for (int it = 0; it < 1000; it++) {
00351 //      status[it] = 0;
00352 //   }
00353 //   for (int it = 0; it < 1000; it++) {
00354 //      status1[it] = 0;
00355 //   }
00356 //   for (int it = 0; it < 1000; it++) {
00357 //      timediff0[it] = 10000;
00358 //      timediff1[it] = 10000;
00359 //      timests[it] = 10000;
00360 //      tot_tr_ADC_0[it] = 0;
00361 //      tot_tr_ADC_1[it] = 0;
00362 //      tot_tr_X_0[it] = 0;
00363 //      tot_tr_X_1[it] = 0;
00364 //      tot_tr_Y_0[it] = 0;
00365 //      tot_tr_Y_1[it] = 0;
00366 //   }
00367 //
00368 //   for (int ic = 0; ic < 1000; ic++) {
00369 //      X1[ic] = 0;
00370 //      Y1[ic] = 0;
00371 //      hittime0[ic] = 0;
00372 //      hittime1[ic] = 0;
00373 //      X0[ic] = 0;
00374 //      Y0[ic] = 0;
00375 //      ADC_C_1[ic] = 0;
00376 //      ADC_C_0[ic] = 0;
00377 //      TrN0[ic] = 0;
00378 //      TrN1[ic] = 0;
00379 //   }
00380 //   nhit0 = 0;
00381 //   nhit1 = 0;
00382 
00383    int trig_count=0;
00384    int finger=0;
00385    int trig_found=0;
00386    //
00387 
00388  for (int rix = 0; rix < NUM_GEM_ROCS; ++rix) {
00389       Int_t rocId = fGEMRocIds[rix];
00390 
00391       //cout<<"rix, rocid   "<<rix<<" "<<rocId<<endl;
00392 
00393       TRocData* theRoc =
00394             dynamic_cast<TRocData*>(fRocInputEvent->getEventElement(rocId));
00395       if (theRoc == 0)
00396          continue;
00397 
00398       for (unsigned i = 0; i < theRoc->fExtMessages.size(); i++) {
00399          TRocMessageExtended msg = theRoc->fExtMessages.at(i);
00400          
00401          if (msg.GetMessageType() == roc::MSG_AUX) {
00402              if (msg.GetRocMessage().getAuxChNum()==1 && rocId==7) {
00403                finger=1;
00404              }
00405              }
00406              }
00407              }       
00408  if(finger==1)trig_count++;
00409 
00410  //
00411    for (int rix = 0; rix < NUM_GEM_ROCS; ++rix) {
00412       Int_t rocId = fGEMRocIds[rix];
00413       TRocData* theRoc =
00414             dynamic_cast<TRocData*>(fRocInputEvent->getEventElement(rocId));
00415       if (theRoc == 0)
00416          continue;
00417 
00418       for (unsigned i = 0; i < theRoc->fExtMessages.size(); i++) {
00419          TRocMessageExtended msg = theRoc->fExtMessages.at(i);
00420          
00421          //      if (msg.GetMessageType() == roc::MSG_AUX) {
00422          //          if (msg.GetRocMessage().getAuxChNum()==1 && rocId==7) {
00423          //            finger=1;
00424          //          }
00425          //      }
00426         // if(finger==1)cout<<"finger ==1 "<<endl;
00427          
00428          if (msg.GetMessageType() != roc::MSG_HIT)
00429             continue; // note that input vector contains _all_ message types now!
00430          Int_t nxId = msg.GetNxNumber();
00431          Int_t nxChannel = msg.GetNxChNum();
00432          Int_t ADC = msg.GetNxADC();
00433          Float_t timedist = msg.GetTriggerDeltaT(); // corrected trigger diff is already in input message!
00434          uint64_t fulltime = msg.GetFullTime();
00435          Bool_t iscorrectedpedestal = kTRUE;
00436          Double_t nxadc_corr = msg.GetCorrectedNxADC();
00437          //              if(finger==0)continue;
00438          
00439          if (nxadc_corr < 10 )
00440             iscorrectedpedestal = kFALSE;
00441          if (IsGEM(msg)) {
00442 //            int CloseTrig = -999;
00443             int z = 10;
00444             // for mapping as obtained from Saini
00445             if (rocId == 9 && nxId == 0) {  //earlier it was rocId==0
00446               z = 2;
00447             } else if (rocId == 9 && nxId == 2) {  //earlier it was rocId==0
00448                z = 3;
00449             } else if (rocId == 7   && nxId == 0) {  //earlier rocid==1
00450               z =  0;
00451             } else if (rocId == 7 && nxId == 2) { //earlier rocId==1
00452                z = 1;
00453             }
00454             Bool_t isGemStripStation=kFALSE;
00455             Int_t gemx(0), gemy(0), gemid(0);
00456             if (!GEM_Map(rocId, nxId, nxChannel, gemid, gemx, gemy)) {
00457                TString mess;
00458                mess.Form(
00459                      "**** TGEMProc: GEM illegal mapping for roc %d nx:%d ch:%d  - ignored\n",
00460                      rocId, nxId, nxChannel);
00461                GO4MESSAGE((2, mess.Data()));
00462                return;
00463             }
00464 
00465             if (gemid != 0 && gemid != 1) {
00466                TString mess;
00467                mess.Form(
00468                      "**** TGEMProc: GEM invalid station id %d  - ignored\n",
00469                      gemid);
00470                GO4MESSAGE((2, mess.Data()));
00471                return;
00472             }
00473                        if(gemid==1) isGemStripStation=kTRUE;
00474             // if(rocId==7 && nxId==0 ) isGemStripStation=kTRUE;
00475 
00476 
00477             // cout<<"gemid, rocId "<<gemid<<" "<<rocId<<" nxid  "<<nxId<<endl;
00478 
00479             fGEMtm[gemid]->Fill(timedist);
00480             if(isGemStripStation)
00481             {
00482                 fGEM_Strip[gemid]->Fill(gemy);
00483 
00484             }
00485             else
00486             { 
00487                 fGEM_Map[gemid]->Fill(gemx, gemy);
00488             }
00489             fGEM_adc[gemid]->Fill(ADC);
00490 
00491             //if(gemid==0)cout<<"rocid,nxch, nxid "<<rocId<<" "<<nxChannel<<" "<<nxId<<" "<<z<<" "<<"X, Y"<<X[z][nxChannel]<<" "<<Y[z][nxChannel]<<endl;
00492         
00493             if (fPar->useOwnPedestal) {
00494                if (gemid == fPar->pedestalGemid) {
00495                   //accumulate pedestals from one station
00496                   nxch_adc_tot[rocId][nxChannel] += ADC;
00497                   nxch_tot[rocId][nxChannel]++;
00498                   //
00499                   //cout<<"ratio, adc, total, rocid, channel "<<nxch_baseline[rocId][nxChannel]<<" "<<nxch_adc_tot[rocId][nxChannel]<<" "<<nxch_tot[rocId][nxChannel]<<" "<<rocId<<" "<<nxChannel<<endl;
00500                }
00501                //
00502                float adc_subtracted = 0;
00503                if (nxch_tot[rocId][nxChannel] > 10) {
00504                   if ((nxChannel) > 0)
00505                      nxch_baseline[rocId][nxChannel] = float(
00506                            nxch_adc_tot[rocId][nxChannel])
00507                            / nxch_tot[rocId][nxChannel];
00508 
00509                   if (nxch_baseline[rocId][nxChannel - 6] > 0)
00510                      adc_subtracted = nxch_baseline[rocId][nxChannel - 6] - ADC;
00511                   //hittime0[CloseTrig] = timedist;
00512                   if (adc_subtracted > 0) {
00513                      fGEM_adc_corrected[gemid]->Fill(adc_subtracted);
00514                      iscorrectedpedestal = kTRUE;
00515                      nxadc_corr = adc_subtracted;
00516                   } else {
00517                      iscorrectedpedestal = kFALSE;
00518                   }
00519                }
00520             } //  if(fPar->useOwnPedestal)
00521 
00522             if (iscorrectedpedestal) {
00523 
00524                //TODO: calculate hit coordinates in mm
00525                 Double_t mmx=0, mmy=0;
00526                 if(isGemStripStation)
00527                 {
00528                         Double_t stripsize=0.7;
00529                         mmy=stripsize*(mmy - 64);
00530                         mmx=-99999;
00531                 }
00532                 else
00533                 {
00534                         // assume 3x3 mm size of station
00535                         Double_t x_pixsize=3.2;
00536                         Double_t y_pixsize=3.2;
00537                         mmx=(gemx-((double) NUM_GEM_X/2.0))*x_pixsize;
00538                         mmy=(gemy-((double) NUM_GEM_Y/2.0))*y_pixsize;
00539                 }
00540 
00541                 //fOutputEvent->AddHit(gemid,gemx,gemy,timedist,nxadc_corr);
00542                 fOutputEvent->AddHit(gemid,mmx,mmy,timedist,nxadc_corr, fulltime);
00543                if(isGemStripStation)
00544                       {
00545                                    fGEM_Strip_Adc[gemid]->Fill(gemy); }
00546                else{
00547                    fGEM_Map_Adc[gemid]->Fill(gemx, gemy, nxadc_corr);
00548                }
00549             }
00550             //
00551 
00552             if (fGEMtmGate[gemid]->Test(timedist)) {
00553                fGEM_adc_corrected[gemid]->Fill(nxadc_corr);
00554             if(z==2|| z==3 || z==1){
00555  fMappingSource[gemid]->Fill(X[z][nxChannel], Y[z][nxChannel]);   
00556             } //cout<<"zvalues "<<z<<endl;
00557                 if(isGemStripStation)
00558                 {
00559                         fGEM_Strip_Time[gemid]->Fill(gemy);
00560                 }
00561                 else
00562                 {
00563                   trig_found++;
00564                   fGEM_Map_Time[gemid]->Fill(gemx, gemy);
00565                   //                    }
00566                 if (iscorrectedpedestal){
00567                fGEM_Map_Adc_Time[gemid]->Fill(gemx, gemy, nxadc_corr);  
00568                 }
00569                 }
00570 
00571             }
00572          } // if (IsGEM(msg))
00573       } // for (unsigned i=0; i<theRoc->fExtMessages.size(); i++)
00574    } // for rix 
00575    int got_trig=0;
00576    if(trig_found>0)got_trig=1;
00577    if(trig_count==1)fratio0_evt->Fill(float(got_trig)/float(trig_count));
00578    if(trig_found>0)fcellMult_evt->Fill(float(trig_found));
00579    //
00580 }
00581 
00582 
00583 
00584 
00585 
00586 
00587 
00588 Bool_t TGEMProc::IsGEM(TRocMessageExtended& msg)
00589 {
00590  Int_t rocId=msg.GetRocNumber();
00591  for(int ix=0;ix<NUM_GEM_ROCS;++ix)
00592    {
00593            if(rocId==fGEMRocIds[ix])
00594            {
00595                    return kTRUE;
00596            }
00597    }
00598  return kFALSE;
00599 
00600 }
00601 
00602 
00603 Bool_t TGEMProc::GEM_Map(Int_t rocid, Int_t nxid, Int_t nxCh, Int_t &gemno, Int_t &xpos, Int_t &ypos)
00604 {
00605    if( nxCh < 0 || nxCh > 127 ) return kFALSE;
00606 
00607    //return kTRUE;
00608    int rocix=0;
00609    bool found=false;
00610    for(rocix=0;rocix<NUM_GEM_ROCS;++rocix)
00611    {
00612       if(rocid==fGEMRocIds[rocix])
00613       {
00614          found=kTRUE; break;
00615       }
00616    }
00617    if(!found) return kFALSE;
00618    //cout <<"GEM Map found rocix "<<rocix<<" for rocid "<<rocid << endl;
00619 
00620    if(rocid==fGEMRocStripStation && nxid==fGEMROCStripNx)
00621            {
00622                    gemno=1;
00623                    xpos=0; // no columns
00624                    ypos=nxCh;
00625                    return kTRUE; // do not use sophisticated mapping
00626            }
00627    else
00628            {
00629                    gemno=0;
00630 
00631            }
00632 
00633 
00634 //   if(rocix<2)
00635 //     gemno=0;
00636 //   else
00637 //     gemno=1;
00638 
00640    int nxix=0;
00641    if(nxid==0) nxix=0;
00642    if(nxid==2) nxix=1;
00643    if(rocid==fGEMRocStripStation) nxix=0; // swap for strip roc
00644    if(rocix>1) rocix-=2;
00645    xpos=fGEM_X[rocix][nxix][nxCh];
00646    ypos=fGEM_Y[rocix][nxix][nxCh];
00647 
00648    //cout <<"           xpos:"<<xpos<<", ypos:"<<ypos<<" rocid"<<rocid<<",nxid:"<<nxid<<" , ch:"<<nxCh << endl;
00649 //   if(rocid==fGEMRocStripStation)
00650 //     xpos=22-xpos; // second ha is flipped around in x
00651 
00652    return kTRUE;
00653 
00654 
00655 
00656 }
00657 
00658 
00659 
00660 void TGEMProc::Init_GEM_Map()
00661 {
00662 
00663 //   int xdimension=22;
00664   int ydimension=22;
00665 
00666   int nx=0;
00667 
00668 // left part:
00669 int roc=0;
00670   for(int ch=0; ch<2*NUM_GEM_CH; ch++)
00671           {
00672              if(ch>127)
00673               nx=1;
00674             else
00675               nx=0;
00676 
00677             int row=0;
00678             // find out current row number:
00679             int channelsum=0;
00680             for(row=0; row<NUM_GEM_Y; ++row)
00681               {
00682                 if(ch< fGEM_Y_BoundariesLeft[row]) break;
00683                 channelsum+=fGEM_Y_PeriodLeft[row];
00684               }
00685 
00686               int y=row;
00687               int x= ch - channelsum + fGEM_Y_ShiftLeft[row];
00688 
00689                 //fGEM_Y[roc][nx][ch-nx*128]=ydimension-y; // flip origin of left side down
00690               fGEM_Y[roc][nx][ch-nx*128]=y;
00691               fGEM_X[roc][nx][ch-nx*128]=x;
00692 
00693           }// for
00694 // right part:
00695 roc=1;
00696 
00697 int xstart=11; // vertical middle line of detector is reference for right side x shift
00698 
00699   for(int ch=0; ch<2*NUM_GEM_CH; ch++)
00700           {
00701              if(ch>127)
00702               nx=1;
00703             else
00704               nx=0;
00705 
00706           int row=0;
00707          // find out current row number:
00708          int channelsum=0;
00709          for(row=0; row<NUM_GEM_Y; ++row)
00710           {
00711             if(ch< fGEM_Y_BoundariesRight[row]) break;
00712             channelsum+=fGEM_Y_PeriodRight[row];
00713           }
00714             int y=row;
00715             int x= ch - channelsum + fGEM_Y_ShiftRight[row];
00716 
00717             fGEM_Y[roc][nx][ch-nx*128]=y;
00718             //fGEM_Y[roc][nx][ch-nx*128]=ydimension-y; //correct for cosyjan12 cabling?
00719             fGEM_X[roc][nx][ch-nx*128]=xstart + x;
00720 
00721           } // for
00722 
00723 printf("GEM Mapping initialized. \n");
00724 
00725 #ifdef _GEM_MAP_DEBUG_
00726 // fill histograms for debugging:
00727 for(int roc=0; roc<2;++roc)
00728 {
00729    for(int nx=0;nx<2;++nx)
00730    {
00731      for(int c=0; c<128;++c)
00732      {
00733           int mx=fGEM_X[roc][nx][c];
00734           int my=fGEM_Y[roc][nx][c];
00735           printf("roc %d nx %d \tc:%d - \tx=%d \ty=%d \n",roc,nx,c,mx,my);
00736           // check against sainis coordinates JAM
00737           int ix=nx + roc*2;
00738           int sx=X[ix][c];
00739           int sy=Y[ix][c];
00740           printf("index %d \tc:%d - \tsx=%d \tsy=%d \n",ix,c,sx,sy);
00741           if(sx!=mx)
00742                   printf ("!!!! X MISMATCH at channel %d : mx=%d, sx=%d\n ",c,mx,sx);
00743           if(sy!=my)
00744                           printf ("!!!! Y MISMATCH at channel %d : my=%d, sy=%d\n ",c,my,sy);
00745           fGEM_Map[0]->Fill(mx,my);
00746 
00747      }
00748      }
00749 
00750 }
00751 
00752 #endif
00753 
00754 
00755 }
00756 
00757 
00758 
00759 

Generated on Tue Dec 10 2013 04:52:18 for ROCsoft by  doxygen 1.7.1