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

beamtime/cosy-dec10/go4/TCosyDec10Proc.cxx (r4864/r3193)

Go to the documentation of this file.
00001 #include "TCosyDec10Proc.h"
00002 
00003 
00004 #include "TGo4Version.h"
00005 #if __GO4BUILDVERSION__ > 40502
00006 #include "go4iostream.h"
00007 #else
00008 #include "Riostream.h"
00009 #endif
00010 #include "TH1.h"
00011 #include "TSystem.h"
00012 #include "TH2.h"
00013 #include <stdlib.h>
00014 
00015 #include "TCosyDec10Param.h"
00016 #include "TGo4WinCond.h"
00017 #include "TGo4PolyCond.h"
00018 #include "TGo4Picture.h"
00019 #include "TGo4Analysis.h"
00020 #include "TGo4MbsEvent.h"
00021 #include "TRocParam.h"
00022 #include "TGo4Log.h"
00023 
00024 #include "TPedestalExtractor.h"
00025 
00026 #include "roc/Board.h"
00027 #include "roc/Message.h"
00028 #include "roc/Iterator.h"
00029 
00030 extern "C"
00031 {
00032     INTS4 f_ut_utime(INTS4 l_sec, INTS4 l_msec, CHARS *pc_time);
00033 }
00034 
00035 #include "f_ut_utime.h"
00036 
00037 #define L1182_DEBUG 0
00038 
00039 UChar_t       TCosyDec10Proc::fStsRocIds[]={0,1,2,3};
00040 
00041 UChar_t       TCosyDec10Proc::fGEMRocIds[]={7,4,5,6};
00042 
00043 
00044 // these arrays define GEM geometry mapping:
00045 
00046 // left part (for roc 0)
00047 
00048 // channel numbers at the end of each y row 
00049 Int_t  TCosyDec10Proc::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};
00050 
00051 // number of channels for each row
00052 Int_t  TCosyDec10Proc::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};
00053 
00054 // shift of each row with respect to left gem edge
00055 Int_t  TCosyDec10Proc::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 };
00056 
00057 // left part (for roc 1)
00058 // channel numbers at the end of each y row 
00059 Int_t  TCosyDec10Proc::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};
00060 
00061 // number of channels for each row
00062 Int_t  TCosyDec10Proc::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};
00063 
00064 //shift of each row with respect to gem vertical middle line x=11
00065 Int_t  TCosyDec10Proc::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 };
00066 
00067             
00068   
00069 
00070               
00071           
00072            
00073            
00074             
00075              
00076             
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085        
00086 
00087 
00088 
00089 //***********************************************************
00090 // this one is used in standard factory
00091 TCosyDec10Proc::TCosyDec10Proc(const char* name) : TRocProc(name)
00092 {
00093    cout << "**** TCosyDec10Proc: Create instance" << name << endl;
00094    
00095    
00096   
00097    TString obname, obtitle;
00098    fParam->triggerSignal = 10;
00099    fLastMbsTimeSecs=0;
00100   fLastMbsTimeMicros= 0;
00101   fMbsDeltatime=0.;
00102 
00103    fCosyDec10Par = (TCosyDec10Param*) MakeParameter("CosyDec10Par", "TCosyDec10Param");
00104    
00105    if (IsObjMade()) {
00106       // redefine conditions ranges if we are starting without autosave
00107       for (unsigned n=0; n<4; n++) 
00108         ROC[n].fTriggerWind->SetValues(830., 940.);
00109       for (unsigned n=4; n<8; n++) 
00110         ROC[n].fTriggerWind->SetValues(850., 1100.);
00111    }
00112 
00113 
00114 
00115    fVulomSyncs = MakeTH1('I', "VULOM/Syncs", "Number of sync messages from VULOM", 65536, 0, 65536.);
00116    
00117    fSyncQuality = MakeTH1('I', "SyncQuality", "Differences between SYNC1 on different ROCs", 100, -100., 100., "ns");
00118 
00119    for (int n=0;n<NUM_SCALERS;n++)
00120    {
00121       fVulomScalers[n] = MakeTH1('I', Form("VULOM/Scaler%d", n), "Distribution of scaler signals", 16, 0, 16.);
00122        fVulomScalersRate[n] = MakeTH1('I', Form("VULOM/RateScaler%d", n), "Distribution of scaler rates", 16, 0, 16.);
00123    }
00124     fVulomScalerOverview=MakeTH2('I', Form("VULOM/ScalersOverview"), "Map of scalers", NUM_SCALERS,0,NUM_SCALERS,16, 0, 16.,"scaler id","channel");
00125     obname.Form("VulomScalers");
00126       if (GetPicture(obname.Data()) == 0) {
00127          obtitle.Form("Scalers overview");
00128          TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00129          pic->SetDivision(1, 1);
00130          pic->Pic(0, 0)->AddObject(fVulomScalerOverview);
00131          pic->Pic(0, 0)->SetDrawOption("TEXT BOX");
00132         AddPicture(pic,"Vulom");
00133    }
00134       
00135    //fScintVertical=MakeTH2('I', Form("Scintillators/ScintVertical"), "Vertical scintillators (Counts/s)", 1,0,1,4, 0, 4,"","y pos");
00136    //fScintHorizontal=MakeTH2('I', Form("Scintillators/ScintHorizontal"), "Horizotal scintillators (Counts/s)", 4,0,4,1, 0, 1,"x pos","");;
00137    fScintVerticalQDC = MakeTH2('I', "Scintillators/QDC_ScintVertical", "Vertical scintillators (Counts)", 1, 0.,1., 4, 0., 4.,"","y pos");
00138    fScintHorizontalQDC = MakeTH2('I', "Scintillators/QDC_ScintHorizontal", "Horizotal scintillators (Counts)", 4, 0.,4., 1, 0., 1.,"x pos","");;
00139  
00140    fScintAndQDC=MakeTH2('I', Form("Scintillators/QDC_ScintMap"), "Scintillators xy-AND (Counts/ev)", 4,0,4,4, 0, 4,"x pos","y pos");;
00141    fScintRolu=MakeTH2('I', Form("Scintillators/ROLU"), "Right upper left lower (Counts/ev)", 3,0,3,3, 0, 3,"x","y");
00142    fScintExtra=MakeTH2('I', Form("Scintillators/Extra"), "Extra scints (Counts/ev)" , 4,0,4,1, 0, 1);
00143    if (IsObjMade()) {
00144             fScintExtra->GetXaxis()->SetBinLabel(1 , "S1");
00145             fScintExtra->GetXaxis()->SetBinLabel(2 , "S2");
00146             fScintExtra->GetXaxis()->SetBinLabel(3 , "S3");
00147             fScintExtra->GetXaxis()->SetBinLabel(4 , "S4");
00148    }
00149 
00150    obname.Form("BeamCheckScalers");
00151       if (GetPicture(obname.Data()) == 0) {
00152          obtitle.Form("Beam scalers");
00153          TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00154          pic->SetDivision(2, 2);
00155          pic->Pic(0, 0)->AddObject(fScintVerticalQDC);
00156          pic->Pic(0, 0)->SetDrawOption("Lego2 Z");
00157           pic->Pic(0, 1)->AddObject(fScintHorizontalQDC);
00158          pic->Pic(0, 1)->SetDrawOption("Lego2 Z");
00159           pic->Pic(1, 0)->AddObject(fScintRolu);
00160          pic->Pic(1, 0)->SetDrawOption("Lego2 Z");
00161           pic->Pic(1, 1)->AddObject(fScintExtra);
00162          pic->Pic(1, 1)->SetDrawOption("Lego2 Z");
00163         AddPicture(pic,"Scintillators");
00164    }   
00165    
00166    
00167 
00168    
00169       
00170    for (int n=0;n<NUM_STS_STATIONS;n++) {
00171       fSTStm[n] = MakeTH1('I', Form("STS/STS%dtm", n), Form("Time correlation on STS%d to SYNC0 signal", n), 500, -1000., 4000.);
00172       lastSync[n] = 0;
00173       for (int j=0;j<NX_HISTORY;j++) lastNx[n][j] = 0;
00174 
00175       //fSTStmGate[n]= MakeWinCond(Form("STS/STS%dtm_Gate", n), -20, 2000, fSTStm[n]->GetName());;
00176 
00177       fSTSNeg[n]= MakeTH1('D', Form("STS/STS%d_Neg", n), Form("STS Station %d Negative side", n), NUM_STS_STRIPS, 0, NUM_STS_STRIPS);
00178       fSTSPos[n]= MakeTH1('D', Form("STS/STS%d_Pos", n), Form("STS Station %d Positive side", n), NUM_STS_STRIPS, 0, NUM_STS_STRIPS);
00179       fSTSNegTimegated[n]= MakeTH1('D', Form("STS/STS%d_Neg_Gated", n), Form("STS Station %d Negative side under time gate", n), NUM_STS_STRIPS, 0, NUM_STS_STRIPS);
00180       fSTSPosTimegated[n]= MakeTH1('D', Form("STS/STS%d_Pos_Gated", n), Form("STS Station %d Positive side under time gate", n), NUM_STS_STRIPS, 0, NUM_STS_STRIPS);
00181 
00182    }
00183 
00184    obname.Form("STS_Strips_Overview");
00185    if (GetPicture(obname.Data()) == 0) {
00186             obtitle.Form("STS strip overview");
00187             TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00188             pic->SetDivision(NUM_STS_STATIONS, 2);
00189             for (int n=0;n<NUM_STS_STATIONS;n++) {
00190             pic->Pic(n, 0)->AddObject(fSTSNeg[n]);
00191             pic->Pic(n, 0)->SetFillAtt(5, 3001);
00192             pic->Pic(n, 1)->AddObject(fSTSPos[n]);
00193             pic->Pic(n, 1)->SetFillAtt(3, 3001);
00194             }
00195             AddPicture(pic,"STS");
00196       }
00197       
00198     obname.Form("STS_Strips_Overview_Gated");
00199    if (GetPicture(obname.Data()) == 0) {
00200             obtitle.Form("STS strip overview under time condition");
00201             TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00202             pic->SetDivision(NUM_STS_STATIONS, 2);
00203             for (int n=0;n<NUM_STS_STATIONS;n++) {
00204             pic->Pic(n, 0)->AddObject(fSTSNegTimegated[n]);
00205             pic->Pic(n, 0)->SetFillAtt(5, 3001);
00206             pic->Pic(n, 1)->AddObject(fSTSPosTimegated[n]);
00207             pic->Pic(n, 1)->SetFillAtt(3, 3001);
00208             }
00209             AddPicture(pic,"STS");
00210       }   
00211 
00213  for (int n=0;n<NUM_GEM_STATIONS;n++) {
00214       fGEMtm[n] = MakeTH1('I', Form("GEM/GEM%dtm", n), Form("Time correlation on GEM %d to SYNC0 signal", n), 500, -1000., 4000.);
00215 
00216        //fGEMtmGate[n]= MakeWinCond(Form("GEM/GEM%dtm_Gate", n), -20, 2000, fGEMtm[n]->GetName());;
00217 
00218       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");
00219       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");
00220   
00221       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");
00222       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");
00223    
00224  }
00225   
00226 
00227    // 1182 histo
00228    for (int n=0;n<NUM_1182;n++) {
00229       obname.Form("1182/1182_channel%d", n);
00230       obtitle.Form("1182 Channel %d", n);
00231       f1182h[n] = MakeTH1('I', obname.Data(), obtitle.Data(), 1024, 0, 4096.);
00232       obname.Form("1182/Gate_1182_channel%d", n);
00233       obtitle.Form("1182 Channel %d", n);
00234       f1182Gate[n] = MakeWinCond(obname.Data(), 600, 3000, f1182h[n]->GetName()); // link condition to histogram
00235 
00236    }
00237    
00238     obname.Form("QDC_1182_Overview");
00239       if (GetPicture(obname.Data()) == 0) {
00240          obtitle.Form("QDC Spectra 1182");
00241          TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00242          pic->SetDivision(2, 4);
00243          for(int x=0;x<4;++x)
00244          {
00245            for(int y=0;y<2;++y)
00246            {
00247              pic->Pic(y, x)->AddObject(f1182h[x+4*y]);
00248              pic->Pic(y, x)->AddCondition(f1182Gate[x+4*y]);
00249            }
00250          }
00251         AddPicture(pic,"Scintillators");
00252    }   
00253    
00254    
00255    // 1183 histo
00256    for (int n=0;n<NUM_1183;n++) {
00257       obname.Form("1183/1183_channel%d", n);
00258       
00259       obtitle.Form("1183 Channel %d", n);
00260       f1183h[n] = MakeTH1('I', obname.Data(), obtitle.Data(), 1024, 0, 8192.);
00261 /*      obname.Form("1183/Gate_1182_channel%d", n);
00262       obtitle.Form("1183 Channel %d", n);
00263       f1183Gate[n] = MakeWinCond(obname.Data(), 0, 2000, f1183h[n]->GetName()); // link condition to histogram*/
00264       
00265    }
00266 //  obname.Form("QDC_1183_Overview");
00267 //       if (GetPicture(obname.Data()) == 0) {
00268 //          obtitle.Form("QDC Spectra 1183");
00269 //          TGo4Picture* pic = new TGo4Picture(obname.Data(), obtitle.Data());
00270 //          pic->SetDivision(2, 4);
00271 //       for(int x=0;x<4;++x)
00272 //       {
00273 //         for(int y=0;y<2;++y)
00274 //         {
00275 //           pic->Pic(y, x)->AddObject(f1183h[x+4*y]);
00276 //           pic->Pic(y, x)->AddCondition(f1183Gate[x+4*y]);
00277 //         }
00278 //       }
00279 //         AddPicture(pic,"Scintillators");
00280 //    }   
00281 
00282    fMotorPos=MakeTH2('I', Form("Epics/MotorPosition"), Form("GEM Motor"), 60,0,300,60,0,300,"X (mm)","Y (mm)");
00283    fRoluPos=MakeTH2('I', Form("Epics/ROLUPosition"), Form("Rolu positions"), 35,0,35,35,0,35,"X (mm)","Y (mm)");
00284    printf("Histograms created \n");
00285    
00286     Init_GEM_Map();
00287 }
00288 
00289 //***********************************************************
00290 TCosyDec10Proc::~TCosyDec10Proc()
00291 {
00292 }
00293 
00294 
00295 Bool_t TCosyDec10Proc::IsSTS(roc::Message* msg)
00296 {
00297  Int_t rocId=msg->getRocNumber();
00298  for(int ix=0;ix<NUM_STS_ROCS;++ix)
00299    {
00300            if(rocId==fStsRocIds[ix])
00301            {
00302                    return kTRUE;
00303            }
00304    }
00305  return kFALSE;  
00306   
00307 }
00308       
00309 Bool_t TCosyDec10Proc::IsGEM(roc::Message* msg)
00310 {
00311  Int_t rocId=msg->getRocNumber(); 
00312  for(int ix=0;ix<NUM_GEM_ROCS;++ix)
00313    {
00314            if(rocId==fGEMRocIds[ix])
00315            {
00316                    return kTRUE;
00317            }
00318    }
00319  return kFALSE; 
00320   
00321 }
00322 
00323 
00324 
00325 
00326 void TCosyDec10Proc::ProcessRocMsg(roc::Message* msg)
00327 {
00328    // this is a place for nx-specific code.
00329    // Here coming hits which are not involved in any kind of calibration procedure
00330 
00331 
00334    if (IsSTS(msg)) {
00335          // add sts mapping by I.Sorokin:
00336 
00337          Int_t rocId = msg->getRocNumber();
00338 
00339          Int_t stsid(0);
00340 
00341          if ((rocId == 0) || (rocId == 1)) stsid = 0; else
00342          if ((rocId == 2) || (rocId == 3)) stsid = 1;
00343 
00344          uint64_t fulltm = msg->getMsgFullTime(ROC[msg->getRocNumber()].fCurrEpoch);
00345 
00346             if (msg->isSyncMsg()) {
00347 
00348       //         printf("SYNC %10lu  diff %lu\n", fulltm, fulltm - lastNx);
00349                lastSync[stsid] = fulltm;
00350                for (int j=0;j<NX_HISTORY;j++) {
00351                   if (lastNx[stsid][j]>fulltm)
00352                      fSTStm[stsid]->Fill(roc::Message::CalcDistance(fulltm, lastNx[stsid][j]));
00353                   else
00354                      fSTStm[stsid]->Fill(-1.*roc::Message::CalcDistance(lastNx[stsid][j], fulltm));
00355                }
00356             } else
00357             if (msg->isHitMsg()) {
00358                for (int j=0;j<NX_HISTORY-1;j++)
00359                   lastNx[stsid][j] = lastNx[stsid][j+1];
00360                lastNx[stsid][NX_HISTORY-1] = fulltm;
00361       //         printf("NX %10lu  diff %lu\n", fulltm, fulltm - lastSync);
00362                uint64_t dist = roc::Message::CalcDistance(lastSync[stsid], fulltm);
00363                fSTStm[stsid]->Fill(1*dist);
00364 
00365 // this part is done in ProcessNxHit now
00366                // here comes detector mapping:
00367 //                Int_t nxChannel=msg->getNxChNum();
00368 //                Int_t StsStrip=STS_GetStrip(side,odd,nxChannel)+1;// strip numbering begins with 1
00369 //                if(side)
00370 //                                 {
00371 //                                         fCosyDec10Event->fStsNeg[stsid][StsStrip]=msg->getNxAdcValue();
00372 //                                         fSTSNeg[stsid]->Fill(StsStrip,msg->getNxAdcValue());
00373 //                                 }
00374 //                         else
00375 //                 {
00376 //                                         fCosyDec10Event->fStsPos[stsid][StsStrip]=msg->getNxAdcValue();
00377 //                                         fSTSPos[stsid]->Fill(StsStrip,msg->getNxAdcValue());
00378 //                 }
00379 
00380                 }
00381                 else 
00382             if(msg->isSysMsg())
00383             {
00384               if(msg->getSysMesType()==roc::SYSMSG_NX_PARITY)
00385               {
00386                 TString str;
00387                 str.Form("**** TCosyDec10Proc: STS Found roc parity error for roc %d = sts:%d \n",rocId,stsid);
00388                 GO4MESSAGE((2, str.Data()));
00389               }
00390             }
00391 
00392 
00393    }
00396    if (IsGEM(msg)) {
00397 
00398       if(msg->isSysMsg() && (msg->getSysMesType()==roc::SYSMSG_NX_PARITY)) {
00399          TString str;
00400          str.Form("**** TCosyDec10Proc: GEM Found roc parity error for roc %d  \n",msg->getRocNumber());
00401          GO4MESSAGE((2, str.Data()));
00402       }
00403    }
00404 }
00405 
00406 
00407 
00408 void TCosyDec10Proc::ProcessNxHit(roc::Message* msg, Double_t nxadc_corr)
00409 {
00410    Int_t rocId=msg->getRocNumber();
00411    Int_t nxId=msg->getNxNumber();
00412    Int_t nxChannel=msg->getNxChNum();
00413    uint64_t fulltm = msg->getMsgFullTime(ROC[rocId].fCurrEpoch);
00414    int32_t timedist = CalcDistanceToTrigger(rocId, fulltm);
00415    Bool_t iscorrectedpedestal=kTRUE;
00416    if( ROC[rocId].fPedestals->GetPedestal(rocId, nxId, nxChannel) < 900 )
00417            iscorrectedpedestal=kFALSE;
00418    
00421    if (IsSTS(msg)) {
00422          // add sts mapping by I.Sorokin:
00423          Int_t stsid;
00424          Int_t side;     // "p"   ->  0    "n"    ->  1
00425          Int_t odd;      // "Odd" ->  1    "Even" ->  0
00426 
00427          // Actual rocId, nxId must be set.
00428          if ( rocId == 0 && nxId == 0 ) { stsid = 0; side = 0; odd = 0; }
00429          if ( rocId == 0 && nxId == 2 ) { stsid = 0; side = 0; odd = 1; }
00430          if ( rocId == 1 && nxId == 0 ) { stsid = 0; side = 1; odd = 0; }
00431          if ( rocId == 1 && nxId == 2 ) { stsid = 0; side = 1; odd = 1; }
00432          if ( rocId == 2 && nxId == 0 ) { stsid = 1; side = 0; odd = 0; }
00433          if ( rocId == 2 && nxId == 2 ) { stsid = 1; side = 0; odd = 1; }
00434          if ( rocId == 3 && nxId == 0 ) { stsid = 1; side = 1; odd = 0; }
00435          if ( rocId == 3 && nxId == 2 ) { stsid = 1; side = 1; odd = 1; }
00436 
00437           // here comes detector mapping:
00438           Int_t StsStrip=STS_GetStrip(side,odd,nxChannel)+1;// strip numbering begins with 1
00439           if(iscorrectedpedestal)
00440         {
00441           if(side)
00442                   {
00443                           //fCosyDec10Event->fStsNeg[stsid][StsStrip]=msg->getNxAdcValue();
00444                           
00445                           fCosyDec10Event->fStsNeg[stsid][StsStrip]=nxadc_corr;
00446                           fSTSNeg[stsid]->Fill(StsStrip,nxadc_corr);
00447                           if (ROC[rocId].fTriggerWind->Test(timedist))
00448                             {
00449                               fSTSNegTimegated[stsid]->Fill(StsStrip,nxadc_corr);
00450                             }
00451                           
00452                           
00453                   }
00454           else
00455                   {
00456                     
00457                         fCosyDec10Event->fStsPos[stsid][StsStrip]=  nxadc_corr;
00458                         fSTSPos[stsid]->Fill(StsStrip,nxadc_corr);
00459                         if (ROC[rocId].fTriggerWind->Test(timedist))
00460                           {
00461                              fSTSPosTimegated[stsid]->Fill(StsStrip,nxadc_corr);
00462                           }               
00463                                           
00464                   }
00465           }// else ifcorrectedpedestal
00466 
00467 
00468     
00469    } else
00470    if (IsGEM(msg)) {
00471       Int_t gemx(0), gemy(0), gemid(0);
00472       if(!GEM_Map(rocId, nxId, nxChannel, gemid, gemx, gemy)) {
00473          TString msg;
00474          msg.Form("**** TCosyDec10Proc: GEM illegal mapping for roc %d nx:%d ch:%d  - ignored\n",rocId,nxId,nxChannel);
00475          GO4MESSAGE((2, msg.Data()));
00476          return;
00477       }
00478 
00479       fGEMtm[gemid]->Fill(timedist);
00480 
00481       if(iscorrectedpedestal){
00482          if(gemid==0){
00483             fCosyDec10Event->fGemOne[gemx][gemy]=nxadc_corr;
00484          }
00485          else if(gemid==1){
00486             fCosyDec10Event->fGemTwo[gemx][gemy]=nxadc_corr;
00487          }
00488          else
00489          {
00490             TString msg;
00491             msg.Form("**** TCosyDec10Proc: GEM invalid station id %d  - ignored\n",gemid);
00492             GO4MESSAGE((2, msg.Data()));
00493             return;
00494 
00495          }
00496       }
00497       fGEM_Map[gemid]->Fill(gemx,gemy);
00498       if(iscorrectedpedestal)
00499          fGEM_Map_Adc[gemid]->Fill(gemx,gemy,nxadc_corr);
00500 
00501 
00502 
00503       if (ROC[rocId].fTriggerWind->Test(timedist))
00504       {
00505          fGEM_Map_Time[gemid]->Fill(gemx,gemy);
00506          if(iscorrectedpedestal)
00507             fGEM_Map_Adc_Time[gemid]->Fill(gemx,gemy,nxadc_corr);
00508       }
00509    }
00510 }
00511 
00512 
00513 
00514 void TCosyDec10Proc::ExtractTriggerTimes(TGo4MbsEvent* evt)
00515 {
00516   fTriggers.clear();
00517   
00518   if (evt==0) return;
00519   TGo4MbsSubEvent* psubevt = 0;
00520   
00521   uint32_t fCurrEpoch = 0;
00522   uint64_t fulltm = 0;
00523 
00524   evt->ResetIterator();
00525   while((psubevt = evt->NextSubEvent()) != 0) { // loop over subevents
00526       if (psubevt->GetProcid() != roc::proc_RocEvent) continue;
00527 
00528       // all relevant triggers are on the roc number 1
00529       if (psubevt->GetSubcrate() != fCosyDec10Par->triggerRoc) continue;
00530 
00531       roc::Iterator iter(psubevt->GetControl());
00532 
00533       iter.setRocNumber(psubevt->GetSubcrate());
00534       
00535       int datasize = (psubevt->GetDlen() - 2) * 2;
00536 
00537       if (!iter.assign(psubevt->GetDataField(), datasize)) continue;
00538 
00539       roc::Message* data = & iter.msg();
00540 
00541       while (iter.next()) {
00542 
00543         int rocid = data->getRocNumber();
00544         if (rocid!=fCosyDec10Par->triggerRoc) {
00545            printf ("ROCID != %d  \n", fCosyDec10Par->triggerRoc);
00546            continue;
00547         }
00548         
00549         if (data->isEpochMsg()) fCurrEpoch = data->getEpochNumber();
00550         
00551         if (data->isAuxMsg() && (data->getAuxChNum() == fCosyDec10Par->triggerAux) && (data->getAuxFalling() == fCosyDec10Par->triggerFalling)) {
00552            fulltm = data->getMsgFullTime(fCurrEpoch);
00553            fTriggers.push_back(fulltm);
00554         }
00555       }
00556   }  
00557 }
00558 
00559 
00560 int32_t TCosyDec10Proc::CalcDistanceToTrigger(int rocid, uint64_t fulltm)
00561 {
00562    if (fTriggers.size() == 0) return -100000000;
00563    
00564    int32_t diff = -100000000;
00565    
00566    int32_t goal = 750;
00567    
00568    int32_t curr = 0;
00569   
00570    for (unsigned n=0; n < fTriggers.size(); n++) {
00571       uint64_t trigger = fTriggers[n];
00572       if (trigger < fulltm) {
00573          curr = fulltm - trigger;
00574       } else {
00575         curr = -1 * (trigger - fulltm);
00576         if (curr < -1000) curr = - 1000000000;
00577       }
00578       if (abs(curr-goal) < abs(diff-goal)) diff = curr;
00579 
00580    }
00581    
00582    return diff;
00583 }
00584 
00585 
00586 
00587 
00588 //-----------------------------------------------------------
00589 // event function
00590 Bool_t TCosyDec10Proc::BuildEvent(TGo4EventElement* outevnt)
00591 {
00592    fCosyDec10Event= dynamic_cast<TCosyDec10Event*>(outevnt);
00593    if(fCosyDec10Event==0) {
00594       GO4_STOP_ANALYSIS_MESSAGE("**** TCosyDec10Proc: Fatal error: output event is not a TCosyDec10Event!!! STOP GO4");
00595    }
00596 
00597 
00598    for (unsigned n=0; n<fNumRocs; n++)
00599      ROC[n].fLastSyncTm[1] = 0;
00600   
00601    ExtractTriggerTimes(dynamic_cast<TGo4MbsEvent*> (GetInputEvent()));
00602   
00603    Bool_t res = TRocProc::BuildEvent(outevnt);
00604    
00605    if (ROC[1].fLastSyncTm[1] != 0) {
00606       if (ROC[2].fLastSyncTm[1]) fSyncQuality->Fill(ROC[2].fLastSyncTm[1] - ROC[1].fLastSyncTm[1]);
00607       if (ROC[4].fLastSyncTm[1]) fSyncQuality->Fill(ROC[4].fLastSyncTm[1] - ROC[1].fLastSyncTm[1]);
00608       if (ROC[5].fLastSyncTm[1]) fSyncQuality->Fill(ROC[5].fLastSyncTm[1] - ROC[1].fLastSyncTm[1]);
00609    }
00610    
00611    return res;
00612 }
00613 
00614 void TCosyDec10Proc::ProcessSubevent(TGo4MbsSubEvent* subevt)
00615 {
00616    if (subevt->GetProcid() == roc::proc_Triglog) {
00617            uint32_t *pudata = (uint32_t*) (subevt->GetDataField());
00618       //Int_t sync_num = subevt->Data(0);
00619            UInt_t sync_num = *pudata++;
00620            fCosyDec10Event->fVulomSyncNumber=sync_num;
00621 
00622       // just to see that sync number is changing
00623       fVulomSyncs->Fill(sync_num % 65536);
00624 
00625       //int ind = 1;
00626 
00627       pudata++; // skip trigger pattern here!
00628 
00629       // now we have time expression
00630       UInt_t timeseconds=*pudata++;
00631       UInt_t timemicros=*pudata++;
00632       fCosyDec10Event->fMbsTimeSecs=timeseconds;
00633       fCosyDec10Event->fMbsTimeMicros=timemicros;
00634       char sbuf[1000]; f_ut_utime(timeseconds, timemicros, sbuf);
00635       fVulomSyncs->SetTitle(Form("Mbs Time:%s", sbuf));
00636       //cout <<"found timestring: " << sbuf <<endl;
00637 
00638       // calculate time difference to last mbs event time: 
00639        UInt_t deltatseconds=0;
00640        UInt_t deltatmicros=0;
00641        fMbsDeltatime=0;
00642        if(fLastMbsTimeSecs)
00643        {
00644           deltatseconds=fCosyDec10Event->fMbsTimeSecs-fLastMbsTimeSecs;
00645           deltatmicros=fCosyDec10Event->fMbsTimeMicros - fLastMbsTimeMicros;
00646           fMbsDeltatime= 1.0*deltatseconds + 1.0e-3 * deltatmicros; //NOTE: micros are milliseconds
00647           //cout <<"mbs deltatime: " << fMbsDeltatime <<" s." <<endl;
00648           
00649        }
00650       fLastMbsTimeSecs=fCosyDec10Event->fMbsTimeSecs;
00651       fLastMbsTimeMicros= fCosyDec10Event->fMbsTimeMicros;
00652 
00653 
00654             UInt_t val=0;
00655             //fScintVertical->Reset("");
00656             //fScintHorizontal->Reset("");
00657             fScintRolu->Reset("");
00658             fScintExtra->Reset("");
00659             
00660                              
00661            for (int nscaler = 0; nscaler < NUM_SCALERS; nscaler++) {
00662 
00663                  fVulomScalers[nscaler]->Reset("");
00664                  fVulomScalersRate[nscaler]->Reset("");
00665                  
00666                         for (int n = 0; n < 16; n++) {
00667 
00668                                 val= (UInt_t) ((*pudata++) & 0x7FFFFFFF); // mask upper bits?
00669                                 if(val){
00670                                         fCosyDec10Event->fVulomScaler[nscaler][n]=val;
00671                                         fVulomScalers[nscaler]->Fill(n,val); // get histo statistics calculated right
00672                                         //fVulomScalers[nscaler]->SetBinContent(n+1,val); // maybe faster...?
00673                                         fVulomScalerOverview->Fill(nscaler,n,val);
00674                                 
00675                                 
00676                                         Double_t rate=0;
00677                                         if(fMbsDeltatime)
00678                                          rate=(val-fVulomOldVals[n]) / fMbsDeltatime;
00679                                          //rate=(val-fVulomOldVals[n]);
00680                                         
00681                                         fVulomScalersRate[nscaler]->Fill(n,rate);    
00682                                             
00683                                         if(n>=0 && n<4)
00684                                         {
00685                                           fScintExtra->Fill(n, (Double_t) 0,rate);
00686                                         }
00687                                         else if(n>=4 && n<8)
00688                                         
00689                                         {
00690                                             if(n==4)
00691                                               fScintRolu->Fill(2,1,rate);
00692                                             else if (n==5)
00693                                               fScintRolu->Fill((Double_t)0,1,rate);
00694                                             else if (n==6)
00695                                               fScintRolu->Fill(1,2,rate);
00696                                             else if (n==7)
00697                                               fScintRolu->Fill(1,(Double_t)0,rate);
00698                                         }
00699                                         else 
00700                                         {
00701                                           //NOP
00702                                         }
00703                         } // if val 
00704                              fVulomOldVals[n]=val;   
00705                         }
00706                 }
00707 
00708 
00709 
00710 
00711       return;
00712    }
00713 
00714    // SL - for cosy beamtime same procid was used as for previous cern beamtime
00715    if (subevt->GetProcid() == roc::proc_TRD_MADC) {
00716       // TRD MADC data + silicon strips + cherenkov
00717            ProcessMADCSub(subevt);
00718            return;
00719    }
00720    
00721    
00722    // SL - at this beamtime epics was produced with procid=8
00723    if (subevt->GetProcid() == 8) {
00724       ProcessEpicsSub(subevt);
00725       return;
00726    }//
00727 }
00728 
00729 
00730 
00731 void  TCosyDec10Proc::ProcessMADCSub(TGo4MbsSubEvent* subevt)
00732 {
00733         Int_t *pdata = subevt->GetDataField();
00734         UInt_t lwords = subevt->GetIntLen();
00735         
00736 //      printf("TOTALLEN = %u\n", lwords);
00737         
00738         const int numtags = 7;
00739         
00740         const uint64_t tags[numtags] = { 0x3035357676353530ULL,  // v550
00741                                         0x3238313131313832ULL,  // 1182
00742                                         0x3338313131313833ULL,  // 1183
00743                                         0x3637313131313736ULL,  // 1176
00744                                         0x3164616d6d616431ULL,  // mad1
00745                                         0x3264616d6d616432ULL,  // mad2
00746                                         0x3364616d6d616433ULL   // mad3
00747                                       };
00748         Int_t* tagpos[numtags];
00749         Int_t taglen[numtags];
00750         
00751         for (int n=0;n<numtags;n++) {
00752            tagpos[n] = 0;
00753            taglen[n] = 0;
00754         }
00755         
00756         int lasttag = -1;
00757         
00758 //      Int_t* p0 = pdata;
00759         
00760         for (UInt_t cur = 0; cur < lwords; ++cur) {
00761            uint64_t* ptag = (uint64_t*) pdata;
00762            
00763 //         printf("DATA 0x%x\n", *pdata);
00764            
00765            bool find = false;
00766            
00767            for (int ntag=0;ntag<numtags;ntag++)
00768               if (*ptag == tags[ntag]) {
00769                  if (lasttag>=0) {
00770                     taglen[lasttag] = pdata - tagpos[lasttag];
00771                     lasttag = -1;
00772                  }
00773                  
00774                  if (tagpos[ntag]==0) {
00775 //                  printf("TAG %d  pos %u\n", ntag, pdata - p0);
00776                  
00777                     pdata+=2; cur+=1;
00778                     tagpos[ntag] = pdata;
00779                     lasttag = ntag;
00780                  } else {
00781                     printf("FORMAT ERROR found tag %lld twice\n", tags[ntag]);
00782                     pdata+=2; cur+=1;
00783                  }
00784 
00785                  find = true;
00786                  break;
00787 
00788               }
00789             
00790             if (!find) pdata++;
00791         }
00792 
00793         if (lasttag>=0) 
00794            taglen[lasttag] = pdata - tagpos[lasttag];
00795 /*      
00796         for (int ntag=0;ntag<numtags;ntag++)
00797            if (tagpos[ntag])
00798               printf("TAG %d POS %lu LEN %d\n", ntag, tagpos[ntag] - p0, taglen[ntag]);
00799         
00800         exit(1);
00801 */
00802 
00803         // actually process data in subroutines:
00804         
00805 
00806         
00807 
00808 //      if (tagpos[0] && taglen[0]) ProcessSi(tagpos[0], taglen[0]); // v550
00809         if (tagpos[1] && taglen[1]) Process1182(tagpos[1], taglen[1]); // 1182
00810    if (tagpos[2] && taglen[2]) Process1183(tagpos[2], taglen[2]); // 1183
00811 //      if (tagpos[3] && taglen[3]) ProcessTDC(tagpos[3], taglen[3]);  // 1176
00812 //      if (tagpos[4] && taglen[4]) ProcessMADC(0, tagpos[4], taglen[4]);  // mad1
00813 //      if (tagpos[5] && taglen[5]) ProcessMADC(1, tagpos[5], taglen[5]);  // mad2
00814 //      if (tagpos[6] && taglen[6]) ProcessMADC(2, tagpos[6], taglen[6]);  // mad3
00815 }
00816 
00817 
00818 void TCosyDec10Proc::Process1182(int* pdata, int len) 
00819 {
00820 
00821    if (len < 2 + 8) {
00822       cout <<"TCosyDec10Proc:Process1182 data length"<< len << "not sufficient!" <<endl;
00823       return;
00824    }
00825    
00826    // skip event header:
00827    int header = *pdata++;
00828    if (L1182_DEBUG)  printf("1182 header:0x%0x \n",header);
00829 
00830    // skip status
00831    int status = *pdata++;
00832    if (L1182_DEBUG)
00833       printf("1182 status:0x%0x :  \n"
00834             "        conversion complete    (bit0): 0x%x\n"
00835             "        conversion in progress (bit1): 0x%x\n"
00836             "        front(1)/rear(0) panel (bit2): 0x%x\n"
00837             "        Event buffer not full  (bit3): 0x%x\n"
00838             "        Event count       (bits 4..7): 0x%x\n"
00839             "        should be 0            (bit8): 0x%x\n"
00840             "        should be 0            (bit9): 0x%x\n",
00841             status, status & 1, (status >> 1) & 1 , (status >> 2) & 1, (status >> 3) & 1,
00842             (status >> 4) & 0xf,  (status >> 8) & 1, (status >> 9) & 1);
00843   
00844             
00845         //fScintVerticalQDC->Reset("");
00846         // fScintHorizontalQDC->Reset("");
00847       for(int ch=0;ch<NUM_1182;++ch) {
00848       int val = *pdata++;
00849       fCosyDec10Event->fData1182[ch]=val;
00850       f1182h[ch]->Fill(val);
00851       Double_t content=0;
00852       if(f1182Gate[ch]->Test(val))
00853       {
00854         Double_t rate=1;
00855 //      if(fMbsDeltatime)
00856 //      {
00857 //        rate=1/fMbsDeltatime;
00858 //      }
00859         
00860         if(ch>=0 && ch<4) 
00861            fScintVerticalQDC->Fill(0., ch + 0., rate);
00862         if(ch>=4 && ch<8) 
00863             fScintHorizontalQDC->Fill(ch-4., 0.,rate);
00864 
00865         
00866       }
00867       
00868       f1182OldVals[ch]=content;
00869       
00870       
00871    }
00872 
00873 // AND mapping of scints:
00874   Bool_t x[4]={kFALSE,kFALSE,kFALSE,kFALSE};
00875    Bool_t y[4]={kFALSE,kFALSE,kFALSE,kFALSE};
00876   if(f1182Gate[0]->Test(fCosyDec10Event->fData1182[0]))
00877          y[0]=kTRUE;
00878   if(f1182Gate[1]->Test(fCosyDec10Event->fData1182[1]))
00879          y[1]=kTRUE;
00880    if(f1182Gate[2]->Test(fCosyDec10Event->fData1182[2]))
00881          y[2]=kTRUE;
00882   if(f1182Gate[3]->Test(fCosyDec10Event->fData1182[3]))
00883          y[3]=kTRUE;
00884   if(f1182Gate[4]->Test(fCosyDec10Event->fData1182[4]))
00885          x[0]=kTRUE;
00886   if(f1182Gate[5]->Test(fCosyDec10Event->fData1182[5]))
00887          x[1]=kTRUE;
00888    if(f1182Gate[6]->Test(fCosyDec10Event->fData1182[6]))
00889          x[2]=kTRUE;
00890   if(f1182Gate[7]->Test(fCosyDec10Event->fData1182[7]))
00891          x[3]=kTRUE;
00892   
00893                       
00894 for(int i=0;i<4;++i)
00895 {
00896   for(int j=0;j<4;++j)
00897   {
00898         if(x[i] && y[j])
00899               fScintAndQDC->Fill(i,j);  
00900   }
00901 }
00902 }
00903 
00904 
00905 void TCosyDec10Proc::Process1183(int* pdata, int len) 
00906 {
00907 
00908    if (len < 2 + 8) {
00909       cout <<"TCosyDec10Proc::Process1183 data length"<< len << "not sufficient!" <<endl;
00910       return;
00911    }
00912 
00913    // skip event header:
00914    int header = *pdata++;
00915    if (L1182_DEBUG) printf("1183 header:0x%0x \n",header);
00916 
00917    // skip status:
00918    int status = *pdata++;
00919    if (L1182_DEBUG)
00920       printf("1183 status:0x%0x :  \n"
00921             "        conversion complete    (bit0): 0x%x\n"
00922             "        conversion in progress (bit1): 0x%x\n"
00923             "        front(1)/rear(0) panel (bit2): 0x%x\n"
00924             "        Event buffer not full  (bit3): 0x%x\n"
00925             "        Event count       (bits 4..7): 0x%x\n"
00926             "        should be 0            (bit8): 0x%x\n"
00927             "        should be 0            (bit9): 0x%x\n",
00928             status, status & 1, (status >> 1) &1 , (status >> 2) &1, (status >> 3) &1,
00929             (status >> 4) & 0xf,  (status >> 8) &1, (status >> 9) &1);
00930 
00931    for(int ch=0;ch<8;++ch) {
00932       int val = *pdata++;
00933       fCosyDec10Event->fData1183[ch]=val;
00934       f1183h[ch]->Fill(val);
00935    }
00936 }
00937 
00938 
00939 
00940 void TCosyDec10Proc::ProcessEpicsSub(TGo4MbsSubEvent* psubevt)
00941 {
00942 
00943    int* pdata= psubevt->GetDataField();
00944    //first payload: event id number
00945    pdata++;
00946    //cout <<"Found event id -"<<evid<< endl;
00947    // secondly get dabc record time expressiong
00948    UInt_t timeseconds=*pdata++;
00949    UInt_t timemicros=0;
00950    char sbuf[1000]; f_ut_utime(timeseconds, timemicros, sbuf);
00951    fMotorPos->SetTitle(Form("Motor position, EPICS Time:%s -", sbuf));
00952    fRoluPos->SetTitle(Form("ROLU positions, EPICS Time:%s -", sbuf));
00953    //cout <<"Found EPICS timestring: " << sbuf <<endl;
00954 
00955 
00956    // first payload: header with number of long records
00957    int numlong=*pdata++;
00958    for(int i=0; i<numlong;++i)
00959    {
00960       long val=*pdata++;
00961       if(_VARPRINT_)
00962       {
00963          cout <<"Long "<<i<<"="<< val<< endl;
00964       }
00965       //                    if(i>=_NUM_LONG_RECS_) continue;
00966       //                    fLongRecords[i]->Fill(val);
00967    }
00968    int numdub=*pdata++;
00969    int motorx=0;
00970    int motory=0;
00971    int rolu_left=0;
00972    int rolu_right=0;
00973    int rolu_up=0;
00974    int rolu_down=0;
00975    for(int i=0; i<numdub;++i)
00976    {
00977       int valint= *pdata++;
00978       double val=  (double) (valint) / 1000.;
00979       if(_VARPRINT_)
00980       {
00981          printf("Double %d: valint:%d, float:%f\n",i,valint, val);
00982          //cout <<"Double "<<i<<"="<< val<< endl;
00983       }
00984       //                    if(i>=_NUM_DOUBLE_RECS_) continue;
00985       //                    fDoubleRecords[i]->Fill(val);
00986 
00987       switch(i){
00988 
00989          case CBM_LAUDA0_Read_Bath :
00990             //cout <<"Read lauda temp:" << val<< endl;
00991             break;
00992          case CBM_MOTOR_GETPOSX:
00993             motorx=val;
00994             break;
00995          case CBM_MOTOR_GETPOSY:
00996             motory=val;
00997             break;
00998          case CBM_rolu_step_to_mm_L:
00999             rolu_left=val;
01000             break;
01001          case CBM_rolu_step_to_mm_R:
01002             rolu_right=val;
01003             break;
01004          case CBM_rolu_step_to_mm_O:
01005             rolu_up=val;
01006             break;
01007          case CBM_rolu_step_to_mm_U:
01008             rolu_down=val;
01009             break;
01010          default:
01011             break;
01012 
01013 
01014       };
01015 
01016    }
01017    fMotorPos->Fill(motorx,motory);
01018 
01019    Int_t roludim=35;
01020    Int_t middle=roludim/2;
01021    Int_t displaywidth=6;
01022    for(int i=0; i<2*displaywidth;++i)
01023    {
01024       fRoluPos->Fill(middle-rolu_left,middle-displaywidth+i);
01025       fRoluPos->Fill(middle+rolu_right,middle-displaywidth+i);
01026       fRoluPos->Fill(middle-displaywidth+i,middle-rolu_down);
01027       fRoluPos->Fill(middle-displaywidth+i,rolu_up + middle);
01028 
01029    }
01030 }
01031 
01032 
01033 
01034 
01035 Int_t TCosyDec10Proc::STS_GetStrip(Int_t side, Int_t odd, Int_t nxCh)
01036 {
01037    if( nxCh < 0 || nxCh > 255 ) return 1001;
01038 
01039    // p-E
01040    if( side == 0 && odd == 0 ) {
01041       if( nxCh < 64 ) return 2 * ( nxCh + 2 - 2 * ( nxCh % 2 ) );
01042       return 2 * ( nxCh + 1 );
01043    }
01044 
01045    // p-O
01046    if( side == 0 && odd == 1 ) {
01047       if( nxCh < 64 ) return 256 - 2 * ( nxCh + 2 - 2 * ( nxCh % 2 ) ) + 1;
01048       return 256 - 2 * nxCh - 1;
01049    }
01050 
01051    // n-E
01052    if( side == 1 && odd == 0 ) {
01053       if( nxCh < 64 ) return 256 - 2 * ( nxCh + 1 - 2 * ( nxCh % 2 ) );
01054       return 256 - 2 * nxCh;
01055    }
01056 
01057    // n-O
01058    if( side == 1 && odd == 1 ) {
01059       if( nxCh < 64 ) return 2 * ( nxCh + 1 - 2 * ( nxCh % 2 ) ) + 1;
01060       return 2 * nxCh + 1;
01061    }
01062 
01063    return 1002;
01064 }
01065 
01066 
01067 Bool_t TCosyDec10Proc::GEM_Map(Int_t rocid, Int_t nxid, Int_t nxCh, Int_t &gemno, Int_t &xpos, Int_t &ypos)
01068 {
01069    if( nxCh < 0 || nxCh > 127 ) return kFALSE;
01070    
01071    //return kTRUE;
01072    int rocix=0;
01073    bool found=false;
01074    for(rocix=0;rocix<4;++rocix)
01075    {
01076            if(rocid==fGEMRocIds[rocix])
01077            {
01078                    found=kTRUE; break;
01079            }
01080    }
01081    if(!found) return kFALSE;
01082    //cout <<"GEM Map found rocix "<<rocix<<" for rocid "<<rocid << endl;
01083    
01084    if(rocix<2) 
01085      gemno=0;
01086    else
01087      gemno=1;
01088    
01090    int nxix=0;
01091    if(nxid==0) nxix=0;
01092    if(nxid==2) nxix=1;
01093    if(rocix>1) rocix-=2;
01094    xpos=fGEM_X[rocix][nxix][nxCh]; 
01095    ypos=fGEM_Y[rocix][nxix][nxCh];
01096    
01097    //cout <<"           xpos:"<<xpos<<", ypos:"<<ypos<<" rocid"<<rocid<<",nxid:"<<nxid<<" , ch:"<<nxCh << endl;
01098    if(gemno==1)
01099      xpos=22-xpos; // second GEM is flipped around in x
01100    
01101    return kTRUE;
01102    
01103    
01104   
01105   
01106 }
01107 
01108  void TCosyDec10Proc::Init_GEM_Map()
01109  {
01110 
01111 //   int xdimension=22;
01112    int ydimension=22;
01113    
01114    int nx=0;
01115    
01116 // left part:
01117 int roc=0;
01118    for(int ch=0; ch<2*NUM_GEM_CH; ch++)
01119           {
01120              if(ch>127) 
01121               nx=1;
01122             else
01123               nx=0;
01124             
01125             int row=0;
01126             // find out current row number:
01127             int channelsum=0;
01128             for(row=0; row<NUM_GEM_Y; ++row)
01129               {     
01130                 if(ch< fGEM_Y_BoundariesLeft[row]) break;
01131                 channelsum+=fGEM_Y_PeriodLeft[row];
01132               }
01133               
01134               int y=row; 
01135               int x= ch - channelsum + fGEM_Y_ShiftLeft[row];
01136               
01137                 fGEM_Y[roc][nx][ch-nx*128]=ydimension-y; // flip origin of left side down
01138                 fGEM_X[roc][nx][ch-nx*128]=x; 
01139             
01140           }// for
01141 // right part:
01142 roc=1;
01143 
01144 int xstart=11; // vertical middle line of detector is reference for right side x shift
01145 
01146    for(int ch=0; ch<2*NUM_GEM_CH; ch++)
01147           {
01148              if(ch>127) 
01149               nx=1;
01150             else
01151               nx=0;
01152             
01153           int row=0;
01154          // find out current row number:
01155          int channelsum=0;
01156          for(row=0; row<NUM_GEM_Y; ++row)
01157           {         
01158             if(ch< fGEM_Y_BoundariesRight[row]) break;
01159             channelsum+=fGEM_Y_PeriodRight[row];
01160           }
01161             int y=row; 
01162             int x= ch - channelsum + fGEM_Y_ShiftRight[row];
01163            
01164             fGEM_Y[roc][nx][ch-nx*128]=y; 
01165             fGEM_X[roc][nx][ch-nx*128]=xstart + x; 
01166             
01167           } // for
01168 
01169  printf("GEM Mapping initialized. \n");
01170 
01171  #ifdef _GEM_MAP_DEBUG_ 
01172 // fill histograms for debugging:
01173 for(int roc=0; roc<2;++roc)
01174 {
01175     for(int nx=0;nx<2;++nx)
01176     {
01177       for(int c=0; c<128;++c)
01178       {
01179           int mx=fGEM_X[roc][nx][c];
01180           int my=fGEM_Y[roc][nx][c];
01181           printf("roc %d nx %d c:%d - \tx=%d \ty=%d \n",roc,nx,c,mx,my);
01182           fGEM_Map[0]->Fill(mx,my);
01183     
01184       }
01185       }
01186   
01187 }
01188 
01189 #endif
01190           
01191   
01192  }

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