1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#include <iostream>
#include <math.h>
#include <vector>
#include <stdlib.h>
#include <iterator>
#include <bitset>

#include "TH1F.h"

#include "PhysicalConstants.h"
#include "StMessMgr.h"

#include "StEvent.h"
#include "StTriggerData.h"
#include "StTrack.h"
#include "StMtdCollection.h"
#include "StMtdHit.h"

#include "StMuDSTMaker/COMMON/StMuDstMaker.h"
#include "StMuDSTMaker/COMMON/StMuDst.h"
#include "StMuDSTMaker/COMMON/StMuEvent.h"
#include "StMuDSTMaker/COMMON/StMuMtdHit.h"

#include "tables/St_mtdModuleToQTmap_Table.h"
#include "tables/St_mtdQTSlewingCorr_Table.h"
#include "tables/St_trgOfflineFilter_Table.h"
#include "StMtdTrackingMaskMaker.h"

ClassImp(StMtdTrackingMaskMaker)

//_____________________________________________________________________________
StMtdTrackingMaskMaker::StMtdTrackingMaskMaker(const Char_t *name) : StMaker(name),
  mStEvent(NULL), mMuDst(NULL), mIsDiMuon(kFALSE), mTrigData(NULL),
  mTpcSectorsForTracking(0)
{
  // default constructor

  mSaveHistos               = false;
  mhEventStat               = NULL;
  mhNQTsignals              = NULL;
  mhNMIXsignals             = NULL;
  mhNMuons                  = NULL;
  mhNMtdHits                = NULL;  
  mhNTrigMtdHits            = NULL;
  mhNTpcSectorForTracking   = NULL;
}
 
//_____________________________________________________________________________
StMtdTrackingMaskMaker::~StMtdTrackingMaskMaker()
{
  // default destructor
}

//_____________________________________________________________________________
Int_t StMtdTrackingMaskMaker::Init()
{
  // book histograms
  bookHistos();

  return kStOK;
}

//_____________________________________________________________________________
Int_t StMtdTrackingMaskMaker::InitRun(const Int_t runNumber)
{
  // initialize trigger Ids for di-muon triggers
  LOG_INFO << "Retrieving trigger ID from database ..." << endm;
   St_trgOfflineFilter* flaggedTrgs =
     (St_trgOfflineFilter *) GetDataBase("Calibrations/trg/trgOfflineFilter");
   if (!flaggedTrgs) 
     {
       LOG_ERROR << "Could not find Calibrations/trg/trgOfflineFilter in database" << endm;
       return kStErr;
     }

   trgOfflineFilter_st* flaggedTrg = flaggedTrgs->GetTable();
   for (long j = 0;j < flaggedTrgs->GetNRows(); j++, flaggedTrg++) 
     {
       int trigid = flaggedTrg->trigid;
       if (0<trigid && trigid<1e9) mTriggerIDs.push_back(trigid);
     }

  // initialize maps
  memset(mModuleToQT,-1,sizeof(mModuleToQT));
  memset(mModuleToQTPos,-1,sizeof(mModuleToQTPos));
  memset(mQTtoModule,-1,sizeof(mQTtoModule));

  // obtain maps from DB
  LOG_INFO << "Retrieving mtdModuleToQTmap table from database ..." << endm;
  TDataSet *dataset = GetDataBase("Geometry/mtd/mtdModuleToQTmap");
  St_mtdModuleToQTmap *mtdModuleToQTmap = static_cast<St_mtdModuleToQTmap*>(dataset->Find("mtdModuleToQTmap"));
  if(!mtdModuleToQTmap)
    {
      LOG_ERROR << "No mtdModuleToQTmap table found in database" << endm;
      return kStErr;
    }
  mtdModuleToQTmap_st *mtdModuleToQTtable = static_cast<mtdModuleToQTmap_st*>(mtdModuleToQTmap->GetTable());

  for(int i=0; i<gMtdNBacklegs; i++)
    {
      for(int j=0; j<gMtdNModules; j++)
	{
	  int index = i*5 + j;
	  int qt = mtdModuleToQTtable->qtBoardId[index];
	  int channel = mtdModuleToQTtable->qtChannelId[index];
	  mModuleToQT[i][j]    = qt;
	  if(channel<0)
	    {
	      mModuleToQTPos[i][j] = channel;
	    }
	  else
	    {
	      if(channel%8==1) mModuleToQTPos[i][j] = 1 + channel/8 * 2;
	      else             mModuleToQTPos[i][j] = 2 + channel/8 * 2;
	    }

	  if(mModuleToQT[i][j]>0 && mModuleToQTPos[i][j]>0)
	    mQTtoModule[mModuleToQT[i][j]-1][mModuleToQTPos[i][j]-1] = j + 1;
	}
    }

  // online slewing correction for QT board
  memset(mQTSlewBinEdge,-1,sizeof(mQTSlewBinEdge));
  memset(mQTSlewCorr,-1,sizeof(mQTSlewCorr));
  LOG_INFO << "Retrieving mtdQTSlewingCorr table from database ..." << endm;
  dataset = GetDataBase("Calibrations/mtd/mtdQTSlewingCorr");
  St_mtdQTSlewingCorr *mtdQTSlewingCorr = static_cast<St_mtdQTSlewingCorr*>(dataset->Find("mtdQTSlewingCorr"));
  if(!mtdQTSlewingCorr)
    {
      LOG_ERROR << "No mtdQTSlewingCorr table found in database" << endm;
      return kStErr;
    }
  mtdQTSlewingCorr_st *mtdQTSlewingCorrtable = static_cast<mtdQTSlewingCorr_st*>(mtdQTSlewingCorr->GetTable());
  for(int j=0; j<4; j++)
    {
      for(int i=0; i<16; i++)
	{
	  for(Int_t k=0; k<8; k++)
	    {
	      Int_t index = j*16*8 + i*8 + k;
	      mQTSlewBinEdge[j][i][k] = (int) mtdQTSlewingCorrtable->slewingBinEdge[index];
	      mQTSlewCorr[j][i][k] = (int) mtdQTSlewingCorrtable->slewingCorr[index];
	    }
	}
    }

  return kStOK;
}

//_____________________________________________________________________________
void StMtdTrackingMaskMaker::Clear(Option_t *option)
{
  // initialize output bit to 0 for each event
  mTpcSectorsForTracking = 0; 
  mFiredSectors.clear();

  memset(mTrigQTpos,-1, sizeof(mTrigQTpos));
  mIsDiMuon = kFALSE;

  SetAttr("TpcSectorsByMtd",mTpcSectorsForTracking);
}

//_____________________________________________________________________________
Int_t StMtdTrackingMaskMaker::Make()
{

  // Check the availability of input data
  Int_t iret = -1;
  mStEvent = (StEvent*) GetInputDS("StEvent");
  if(mStEvent)
    {
      LOG_DEBUG << "Running on StEvent ..." << endm;
      iret = processStEvent();
    }
  else 
    {
      StMuDstMaker *muDstMaker = (StMuDstMaker*) GetMaker("MuDst");
      if(muDstMaker) 
	{
	  mMuDst = muDstMaker->muDst();
	  iret = processMuDst();
	}
      else
	{
	  LOG_ERROR << "No muDST is available ... "<< endm;
	  iret = kStErr;
	}
    }

  SetAttr("TpcSectorsByMtd",mTpcSectorsForTracking);


  if(mStEvent)
    {
      LOG_INFO << "Is di-muon event: " << mIsDiMuon << endm;
      LOG_INFO << "Tracking mask by MTD: " << (bitset<24>)mTpcSectorsForTracking << endm;  
    }

  return iret;
}

//_____________________________________________________________________________
Int_t StMtdTrackingMaskMaker::processStEvent()
{
  mhEventStat->Fill(0.5);

  // check trigger id
  for(unsigned int j=0; j<mTriggerIDs.size(); j++)
    {
      if(mStEvent->triggerIdCollection()->nominal()->isTrigger(mTriggerIDs[j]))
	{
	  mIsDiMuon = kTRUE;
	  break;
	}
    }
  if(!mIsDiMuon) return kStOK;
  mhEventStat->Fill(1.5);

  // trigger data
  mTrigData = (StTriggerData*)mStEvent->triggerData();
  if(!mTrigData) return kStWarn;
  processTriggerData();

  // MTD hits
  StMtdCollection *mtdCollection = mStEvent->mtdCollection();
  if(!mtdCollection) 
    {
      LOG_WARN << "No mtd collection available in StEvent ... " << endm;
      return kStWarn;
    }
  StSPtrVecMtdHit& mtdHits = mtdCollection->mtdHits();
  int nMtdHits = mtdHits.size();
  mhNMtdHits->Fill(nMtdHits);
  int nTrigMtdHits = 0;

  for(int i=0; i<nMtdHits; i++)
    {
      StMtdHit *hit = mtdHits[i];
      if(!hit) continue;
      if(!isMtdHitFiredTrigger(hit)) continue;
      nTrigMtdHits++;

      // depending on the hit position, find the two or four TPC
      // sectors that most likely hosts the corresponding tracks
      int backleg = hit->backleg();
      int module  = hit->module();
      int cell    = hit->cell();
      double hit_phi = getMtdHitGlobalPhi(backleg, module, cell);
      findTpcSectorsForTracking(hit_phi, module);
    }
  determineTpcTrackingMask();
  mhNTrigMtdHits->Fill(nTrigMtdHits);
  return kStOK;
}


//_____________________________________________________________________________
Int_t StMtdTrackingMaskMaker::processMuDst()
{
  mhEventStat->Fill(0.5);

  // check trigger id
  for(unsigned int j=0; j<mTriggerIDs.size(); j++)
    {
      if(mMuDst->event()->triggerIdCollection().nominal().isTrigger(mTriggerIDs[j]))
	{
	  mIsDiMuon = kTRUE;
	  break;
	}
    }
  if(!mIsDiMuon) return kStOK;
  mhEventStat->Fill(1.5);

  // trigger data
  mTrigData = const_cast<StTriggerData*>(mMuDst->event()->triggerData());
  if(!mTrigData) return kStWarn;
  processTriggerData();

  // MTD hits
  int nMtdHits = mMuDst->numberOfMTDHit();
  mhNMtdHits->Fill(nMtdHits);
  int nTrigMtdHits = 0;

  for(int i=0; i<nMtdHits; i++)
    {
      StMuMtdHit *hit = mMuDst->mtdHit(i);
      if(!hit) continue;
      if(!isMtdHitFiredTrigger(hit)) continue;
      nTrigMtdHits++;

      // depending on the hit position, find the two or four TPC
      // sectors that most likely hosts the corresponding tracks
      int backleg = hit->backleg();
      int module  = hit->module();
      int cell    = hit->cell();
      double hit_phi = getMtdHitGlobalPhi(backleg, module, cell);
      findTpcSectorsForTracking(hit_phi, module);
    }
  determineTpcTrackingMask();
  mhNTrigMtdHits->Fill(nTrigMtdHits);
  return kStOK;
}

//_____________________________________________________________________________
void StMtdTrackingMaskMaker::processTriggerData()
{
  ///
  /// De-code the trigger information to determine
  /// which MTD trigger hits/patches actually fire the trigger
  ///

  // TF201 decision
  unsigned short decision = mTrigData->dsmTF201Ch(0);

  // MT101 informaiton (QA purpose)
  int mix_tacsum[4][2];
  int mix_id[4][2];
  int nMixSignal = 0;
  for(int i = 0; i < 4; i++)
    {
      mix_tacsum[i][0] = (mTrigData->mtdDsmAtCh(3*i,0)) + ((mTrigData->mtdDsmAtCh(3*i+1,0)&0x3)<<8);
      mix_id[i][0]     = (mTrigData->mtdDsmAtCh(3*i+1,0)&0xc)>>2;
      mix_tacsum[i][1] = (mTrigData->mtdDsmAtCh(3*i+1,0)>>4) + ((mTrigData->mtdDsmAtCh(3*i+2,0)&0x3f)<<4);
      mix_id[i][1]     = (mTrigData->mtdDsmAtCh(3*i+2,0)&0xc0)>>6;

      for(int j=0; j<2; j++)
	{
	  if(mix_tacsum[i][j]>0) nMixSignal ++;
	}
    }
  mhNMIXsignals->Fill(nMixSignal);

  // QT
  int mxq_tacsum[4][2];
  int mxq_tacsum_pos[4][2];
  for(int i=0; i<4; i++)
    {
      for(int j=0; j<2; j++)
	{
	  mxq_tacsum[i][j] = 0;
	  mxq_tacsum_pos[i][j] = -1;
	}
    }

  // extract tac information for each QT board
  int mtdQTtac[4][16];
  int mtdQTadc[4][16];
  for(int i=0; i<32; i++)
    {
      int type = (i/4)%2;
      if(type==1)
	{
	  mtdQTtac[0][i-i/4*2-2] = mTrigData->mtdAtAddress(i,0);<--- Array index -2 is out of bounds.
	  mtdQTtac[1][i-i/4*2-2] = mTrigData->mtdgemAtAddress(i,0);<--- Array index -2 is out of bounds.
	  mtdQTtac[2][i-i/4*2-2] = mTrigData->mtd3AtAddress(i,0);<--- Array index -2 is out of bounds.
	  mtdQTtac[3][i-i/4*2-2] = mTrigData->mtd4AtAddress(i,0);<--- Array index -2 is out of bounds.
	}
      else
	{
	  mtdQTadc[0][i-i/4*2] = mTrigData->mtdAtAddress(i,0);
	  mtdQTadc[1][i-i/4*2] = mTrigData->mtdgemAtAddress(i,0);
	  mtdQTadc[2][i-i/4*2] = mTrigData->mtd3AtAddress(i,0);
	  mtdQTadc[3][i-i/4*2] = mTrigData->mtd4AtAddress(i,0);
	}
    }

  // In each QT board, find the two signals with
  // largest TacSum values
  int nQtSignal = 0;
  int j[2], a[2];
  for(int im=0; im<4; im++)
    {
      for(int i=0; i<8; i++)
	{
	  // slewing correction
	  for(int k=0; k<2; k++)
	    {
	      j[k] = mtdQTtac[im][i*2+k];
	      a[k] = mtdQTadc[im][i*2+k];

	      int slew_bin = -1;
	      if(a[k]>=0 && a[k]<=mQTSlewBinEdge[im][i*2+k][0]) slew_bin = 0;
	      else
		{
		  for(int l=1; l<8; l++)
		    {
		      if(a[k]>mQTSlewBinEdge[im][i*2+k][l-1] && a[k]<=mQTSlewBinEdge[im][i*2+k][l])
			{
			  slew_bin = l;
			  break;
			}
		    }
		}
	      if(slew_bin>=0)
		j[k] += mQTSlewCorr[im][i*2+k][slew_bin];
	    }

	  if(j[0]<100 || j[1]<100) continue;
	  if(abs(j[0]-j[1])>600) continue;
	  nQtSignal++;
	  
	  // position correction
	  int module = mQTtoModule[im][i];
	  int sumTac = int( j[0] + j[1] + abs(module-3)*1./8 * (j[0]-j[1]) );

	  if(mxq_tacsum[im][0] < sumTac)
	    {
	      mxq_tacsum[im][1] = mxq_tacsum[im][0];
	      mxq_tacsum[im][0] = sumTac;

	      mxq_tacsum_pos[im][1] = mxq_tacsum_pos[im][0];
	      mxq_tacsum_pos[im][0] = i+1;
	    }
	  else if (mxq_tacsum[im][1] < sumTac)
	    {
	      mxq_tacsum[im][1]  = sumTac;
	      mxq_tacsum_pos[im][1] = i+1;
	    }
	}
    }
  mhNQTsignals->Fill(nQtSignal);
  
  int nMuon = 0;
  for(int i = 0; i < 4; i++)
    {
      for(int j=0; j<2; j++)
	{
	  if((decision>>(i*2+j+4))&0x1)
	    {
	      nMuon ++;
	      mTrigQTpos[i][j] = mxq_tacsum_pos[i][j];
	    }
	}
    }
  mhNMuons->Fill(nMuon);

  LOG_DEBUG << "# of muon candidates = " << nMuon << endm;
}

//_____________________________________________________________________________
bool StMtdTrackingMaskMaker::isMtdHitFiredTrigger(const StMtdHit *hit)
{
  ///
  /// check if a MTD hit fired the trigger. This is done
  /// by looking at whether the corresponding QT board
  /// sends out the trigger signal
  ///

  return isQTFiredTrigger( mModuleToQT[hit->backleg()-1][hit->module()-1], mModuleToQTPos[hit->backleg()-1][hit->module()-1]);
}

//_____________________________________________________________________________
bool StMtdTrackingMaskMaker::isMtdHitFiredTrigger(const StMuMtdHit *hit)
{
  ///
  /// check if a MTD hit fired the trigger. This is done
  /// by looking at whether the corresponding QT board
  /// sends out the trigger signal
  ///

  return isQTFiredTrigger( mModuleToQT[hit->backleg()-1][hit->module()-1], mModuleToQTPos[hit->backleg()-1][hit->module()-1]);
}

//_____________________________________________________________________________
bool StMtdTrackingMaskMaker::isQTFiredTrigger(const int qt, const int pos)
{
  ///
  /// check if the QT board sends out the trigger signal
  ///

  return (pos==mTrigQTpos[qt-1][0] || pos==mTrigQTpos[qt-1][1]);
}

//_____________________________________________________________________________
void StMtdTrackingMaskMaker::determineTpcTrackingMask()
{
  // remove duplicated TPC sectors
  sort(mFiredSectors.begin(),mFiredSectors.end());
  mFiredSectors.erase(unique(mFiredSectors.begin(),mFiredSectors.end()),mFiredSectors.end());

  mhNTpcSectorForTracking->Fill(mFiredSectors.size());
  
  // 24-bit mask for TPC tracking
  for(unsigned int i=0; i<mFiredSectors.size(); i++)
    {
      int bit = mFiredSectors[i] - 1;
      mTpcSectorsForTracking |= (1U << bit);
    }
  LOG_DEBUG << "Output TPC mask = " << (bitset<24>) mTpcSectorsForTracking << endm;
}

//_____________________________________________________________________________
void StMtdTrackingMaskMaker::findTpcSectorsForTracking(const double hit_phi, const int hit_module)
{
  ///
  /// Find the corresponding TPC sector for a given MTD hit
  /// For hits in module 1, only tracking TPC sectors on east
  /// For hits in module 5, only tracking TPC sectors on west
  /// For hits in module 2-4, tracking TPC sectors both on east and west
  ///

  IntVec westTpc, eastTpc;
  westTpc.clear();
  eastTpc.clear();

  if(hit_module<5) eastTpc = findEastTpcSectors(hit_phi);
  if(hit_module>1) westTpc = findWestTpcSectors(hit_phi);

  for(unsigned int i=0; i<eastTpc.size(); i++)
    mFiredSectors.push_back(eastTpc[i]);

  for(unsigned int i=0; i<westTpc.size(); i++)
    mFiredSectors.push_back(westTpc[i]);
}

//_____________________________________________________________________________
vector<int> StMtdTrackingMaskMaker::findWestTpcSectors(const double hit_phi)
{
  ///
  /// Given the azimuthal angle of a MTD hit, find the two spatially closest TPC
  /// sectors on the west side of STAR
  ///
 
  IntVec sectors;
  sectors.clear();

  double tpc_sector_width = pi/6.;

  int tpc_sector_1 = 3 - int(floor(hit_phi/tpc_sector_width));
  if(tpc_sector_1<1) tpc_sector_1 += 12;

  int tpc_sector_2 = tpc_sector_1 - 1;
  if(tpc_sector_2<1) tpc_sector_2 += 12;
  
  sectors.push_back(tpc_sector_1);
  sectors.push_back(tpc_sector_2);

  LOG_DEBUG << "For hit at phi = " << hit_phi/pi*180 << ", west TPC sectors are " 
	    << tpc_sector_1 << " and " << tpc_sector_2 << endm;
  return sectors;
}

//_____________________________________________________________________________
vector<int> StMtdTrackingMaskMaker::findEastTpcSectors(const double hit_phi)
{
  ///
  /// Given the azimuthal angle of a MTD hit, find the two spatially closest TPC
  /// sectors on the east side of STAR
  ///

  IntVec sectors;
  sectors.clear();

  double tpc_sector_width = pi/6.;

  int tpc_sector_1 = int(floor(hit_phi/tpc_sector_width))+21;
  if(tpc_sector_1>24) tpc_sector_1 -= 12;

  int tpc_sector_2 = tpc_sector_1 + 1;
  if(tpc_sector_2>24) tpc_sector_2 -= 12;
  
  sectors.push_back(tpc_sector_1);
  sectors.push_back(tpc_sector_2);

  LOG_DEBUG << "For hit at phi = " << hit_phi/pi*180  << ", east TPC sectors are " 
	    << tpc_sector_1 << " and " << tpc_sector_2 << endm;

  return sectors;
}

//_____________________________________________________________________________
double StMtdTrackingMaskMaker::getMtdHitGlobalPhi(const int backleg, const int module, const int cell)
{
  ///
  /// Approximate phi center of a MTD hit
  ///

  double backlegPhiCen = gMtdFirstBacklegPhiCenter + (backleg-1) * (gMtdBacklegPhiWidth+gMtdBacklegPhiGap);
  if(backlegPhiCen>2*pi) backlegPhiCen -= 2*pi;
  double stripPhiCen = 0;
  if(module>0 && module<4)
    {
      stripPhiCen = backlegPhiCen - (gMtdNChannels/4.-0.5-cell)*(gMtdCellWidth+gMtdCellGap)/gMtdMinRadius;
    }
  else
    {
      stripPhiCen = backlegPhiCen + (gMtdNChannels/4.-0.5-cell)*(gMtdCellWidth+gMtdCellGap)/gMtdMinRadius;
    }
  return rotatePhi(stripPhiCen);
}

//_____________________________________________________________________________
double StMtdTrackingMaskMaker::rotatePhi(const double phi)
{
  double outPhi = phi;
  while(outPhi<0) outPhi += 2*pi;
  while(outPhi>2*pi) outPhi -= 2*pi;
  return outPhi;
}


//_____________________________________________________________________________
void StMtdTrackingMaskMaker::bookHistos()
{

  mhEventStat = new TH1F("hEventStat","Event statistics",5,0,5);
  mhEventStat->GetXaxis()->SetBinLabel(1,"All events");
  mhEventStat->GetXaxis()->SetBinLabel(2,"Good trigger");

  mhNQTsignals = new TH1F("hNQTsignals","Number of QT signals per event;N",10,0,10);

  mhNMIXsignals = new TH1F("hNMIXsignals","Number of MT101 signals per event;N",10,0,10);

  mhNMuons = new TH1F("hNMuons","Number of TF201 signals per event;N",10,0,10);

  mhNMtdHits = new TH1F("hNMtdHits","Number of MTD hits per event;N",50,0,50);

  mhNTrigMtdHits = new TH1F("hNTrigMtdHits","Number of triggering MTD hits per event;N",10,0,10);

  mhNTpcSectorForTracking = new TH1F("hNTpcSectorForTracking","Number of TPC sectors for tracking per event;N",20,0,20);

  if(mSaveHistos)
    {
      AddHist(mhEventStat);
      AddHist(mhNQTsignals); 
      AddHist(mhNMIXsignals); 
      AddHist(mhNMuons); 
      AddHist(mhNMtdHits); 
      AddHist(mhNTrigMtdHits); 
      AddHist(mhNTpcSectorForTracking); 
    }
}


// $Id: StMtdTrackingMaskMaker.cxx,v 1.4 2016/07/27 15:24:30 marr Exp $
// $Log: StMtdTrackingMaskMaker.cxx,v $
// Revision 1.4  2016/07/27 15:24:30  marr
// Fix coverity check: initialization of data members
//
// Revision 1.3  2015/05/01 21:37:20  marr
// Apply online slewing correction and position correction to QT data to make
// sure the correct trigger patches are found offline.
//
// Revision 1.2  2015/04/23 21:09:12  marr
// Add print-out in reconstruction
//
// Revision 1.1  2015/04/07 14:10:37  jeromel
// First version of StMtdEvtFilterMaker - R.Ma - review closed 2015/04/06
//
//