00001
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
00019
00020
00021
00022 UChar_t TGEMProc::fGEMRocIds[]={9,7};
00023 UChar_t TGEMProc::fGEMRocStripStation=7;
00024 UChar_t TGEMProc::fGEMROCStripNx=0;
00025
00026
00027
00028
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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
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
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
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
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
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
00176
00177
00178
00179
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
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
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
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
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
00223
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
00228
00229
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
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
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
00296
00297
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
00316
00317
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;
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
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
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
00422
00423
00424
00425
00426
00427
00428 if (msg.GetMessageType() != roc::MSG_HIT)
00429 continue;
00430 Int_t nxId = msg.GetNxNumber();
00431 Int_t nxChannel = msg.GetNxChNum();
00432 Int_t ADC = msg.GetNxADC();
00433 Float_t timedist = msg.GetTriggerDeltaT();
00434 uint64_t fulltime = msg.GetFullTime();
00435 Bool_t iscorrectedpedestal = kTRUE;
00436 Double_t nxadc_corr = msg.GetCorrectedNxADC();
00437
00438
00439 if (nxadc_corr < 10 )
00440 iscorrectedpedestal = kFALSE;
00441 if (IsGEM(msg)) {
00442
00443 int z = 10;
00444
00445 if (rocId == 9 && nxId == 0) {
00446 z = 2;
00447 } else if (rocId == 9 && nxId == 2) {
00448 z = 3;
00449 } else if (rocId == 7 && nxId == 0) {
00450 z = 0;
00451 } else if (rocId == 7 && nxId == 2) {
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
00475
00476
00477
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
00492
00493 if (fPar->useOwnPedestal) {
00494 if (gemid == fPar->pedestalGemid) {
00495
00496 nxch_adc_tot[rocId][nxChannel] += ADC;
00497 nxch_tot[rocId][nxChannel]++;
00498
00499
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
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 }
00521
00522 if (iscorrectedpedestal) {
00523
00524
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
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
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 }
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 }
00573 }
00574 }
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
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
00619
00620 if(rocid==fGEMRocStripStation && nxid==fGEMROCStripNx)
00621 {
00622 gemno=1;
00623 xpos=0;
00624 ypos=nxCh;
00625 return kTRUE;
00626 }
00627 else
00628 {
00629 gemno=0;
00630
00631 }
00632
00633
00634
00635
00636
00637
00638
00640 int nxix=0;
00641 if(nxid==0) nxix=0;
00642 if(nxid==2) nxix=1;
00643 if(rocid==fGEMRocStripStation) nxix=0;
00644 if(rocix>1) rocix-=2;
00645 xpos=fGEM_X[rocix][nxix][nxCh];
00646 ypos=fGEM_Y[rocix][nxix][nxCh];
00647
00648
00649
00650
00651
00652 return kTRUE;
00653
00654
00655
00656 }
00657
00658
00659
00660 void TGEMProc::Init_GEM_Map()
00661 {
00662
00663
00664 int ydimension=22;
00665
00666 int nx=0;
00667
00668
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
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
00690 fGEM_Y[roc][nx][ch-nx*128]=y;
00691 fGEM_X[roc][nx][ch-nx*128]=x;
00692
00693 }
00694
00695 roc=1;
00696
00697 int xstart=11;
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
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
00719 fGEM_X[roc][nx][ch-nx*128]=xstart + x;
00720
00721 }
00722
00723 printf("GEM Mapping initialized. \n");
00724
00725 #ifdef _GEM_MAP_DEBUG_
00726
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
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