CbmTofFindTracks.cxx 91.8 KB
Newer Older
1
2
3
4
5
6
7
// -------------------------------------------------------------------------
// -----                  CbmTofFindTracks source file                -----
// -----                  Created 25/04/15  by N. Herrmann             -----
// -----                  initially following  CbmTrdFindTracks        -----
// -------------------------------------------------------------------------

#include "CbmTofFindTracks.h"
Administrator's avatar
Administrator committed
8
#include "CbmTofAddress.h"  // in cbmdata/tof
9

Administrator's avatar
Administrator committed
10
11
12
13
14
15
16
#include "CbmEvent.h"
#include "CbmMatch.h"
#include "CbmTofCalibrator.h"
#include "CbmTofCell.h"             // in tof/TofData
#include "CbmTofCreateDigiPar.h"    // in tof/TofTools
#include "CbmTofDetectorId_v12b.h"  // in cbmdata/tof
#include "CbmTofDetectorId_v14a.h"  // in cbmdata/tof
Norbert Herrmann's avatar
Norbert Herrmann committed
17
#include "CbmTofDetectorId_v21a.h"  // in cbmdata/tof
Administrator's avatar
Administrator committed
18
19
20
21
#include "CbmTofDigiBdfPar.h"       // in tof/TofParam
#include "CbmTofDigiPar.h"          // in tof/TofParam
#include "CbmTofGeoHandler.h"       // in tof/TofTools
#include "CbmTofHit.h"
22
23
24
#include "CbmTofTrackFinder.h"
#include "CbmTofTrackFinderNN.h"
#include "CbmTofTrackFitter.h"
Administrator's avatar
Administrator committed
25
#include "CbmTofTracklet.h"
26
27
28
#include "CbmTofTrackletTools.h"
#include "CbmVertex.h"

Administrator's avatar
Administrator committed
29
#include "FairLogger.h"
30
31
32
33
34
#include "FairRootManager.h"
#include "FairRunAna.h"
#include "FairRuntimeDb.h"

#include "TClonesArray.h"
Administrator's avatar
Administrator committed
35
#include "TDirectory.h"
36
#include "TF1.h"
Administrator's avatar
Administrator committed
37
38
39
#include "TFile.h"
#include "TFitResult.h"
#include "TGeoManager.h"
40
41
42
43
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TMath.h"
Administrator's avatar
Administrator committed
44
#include "TProfile.h"
45
#include "TROOT.h"
Administrator's avatar
Administrator committed
46
#include "TRandom.h"
47
#include "TSpectrum.h"
Administrator's avatar
Administrator committed
48
#include "TString.h"
49
50

#include <iostream>
Administrator's avatar
Administrator committed
51
#include <vector>
52
53
54
55
56

using std::cout;
using std::endl;
using std::vector;

57
58
//const Int_t DetMask = 0x3FFFFF;  // check for consistency with v14a geometry
const Int_t DetMask = 0x1FFFFF;  // check for consistency with v21a geometry
59
60
61

ClassImp(CbmTofFindTracks);

Administrator's avatar
Administrator committed
62
CbmTofFindTracks* CbmTofFindTracks::fInstance = 0;
63
64

// -----   Default constructor   -------------------------------------------
Administrator's avatar
Administrator committed
65
66
67
CbmTofFindTracks::CbmTofFindTracks()
  : CbmTofFindTracks::CbmTofFindTracks("TofFindTracks", "Main", NULL) {
  if (!fInstance) fInstance = this;
68
69
70
71
72
73
}
// -------------------------------------------------------------------------


// -----   Standard constructor   ------------------------------------------
CbmTofFindTracks::CbmTofFindTracks(const char* name,
Administrator's avatar
Administrator committed
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
                                   const char* /*title*/,
                                   CbmTofTrackFinder* finder)
  : FairTask(name)
  , fFinder(finder)
  , fFitter(NULL)
  , fTrackletTools(NULL)
  , fTofCalibrator(NULL)
  , fEventsColl(NULL)
  , fTofHitArrayIn(NULL)
  , fTofMatchArrayIn(NULL)
  , fTofHitArray(NULL)
  , fTrackArray(NULL)
  , fTrackArrayOut(nullptr)
  , fTofUHitArray(NULL)
  , fMinNofHits(-1)
  , fNofTracks(-1)
  , fNTofStations(-1)
  , fNReqStations(-1)
  , fInspectEvent(kTRUE)
  , fStationType()
  , fStationHMul()
  , fRpcAddr()
  , fMapStationRpcId()
  , fMapRpcIdParInd()
  , fhTrklMul(NULL)
  , fhTrklChi2(NULL)
  , fhAllHitsStation(NULL)
  , fhAllHitsSmTypes(NULL)
  , fhUsedHitsStation(NULL)
  , fhTrackingTimeNhits(NULL)
  , fhTrklMulNhits(NULL)
  , fhTrklMulMaxMM(NULL)
  , fhTrklMul3D(NULL)
  , fhTrklHMul(NULL)
  , fhTrklZ0xHMul(NULL)
  , fhTrklZ0yHMul(NULL)
  , fhTrklTxHMul(NULL)
  , fhTrklTyHMul(NULL)
  , fhTrklTtHMul(NULL)
  , fhTrklVelHMul(NULL)
  , fhTrklT0HMul(NULL)
  , fhTrklT0Mul(NULL)
  , fhTrklDT0SmMis(NULL)
  , fhTrklDT0StMis2(NULL)
  , fhTrklXY0_0(NULL)
  , fhTrklXY0_1(NULL)
  , fhTrklXY0_2(NULL)
  , vhPullX()
  , vhPullY()
  , vhPullZ()
  , vhPullT()
  , vhPullTB()
  , vhResidualTBWalk()
  , vhResidualYWalk()
  , vhXY_AllTracks()
  , vhXY_AllStations()
  , vhXY_MissedStation()
  , vhXY_DX()
  , vhXY_DY()
  , vhXY_DT()
  , vhXY_TOT()
  , vhXY_CSZ()
  , vhUDXDY_DT()
  , vhUCDXDY_DT()
  , fhVTXNorm(NULL)
  , fhVTX_XY0(NULL)
  , fhVTX_DT0_Norm(NULL)
  , fOutHstFileName("")
  , fCalParFileName("")
  , fCalOutFileName("./tofFindTracks.hst.root")
  , fCalParFile(NULL)
  , fhPullT_Smt(NULL)
  , fhPullT_Smt_Off(NULL)
  , fhPullX_Smt(NULL)
  , fhPullX_Smt_Off(NULL)
  , fhPullY_Smt(NULL)
  , fhPullY_Smt_Off(NULL)
  , fhPullZ_Smt(NULL)
  , fhPullZ_Smt_Off(NULL)
  , fhPullT_Smt_Width(NULL)
  , fhPullX_Smt_Width(NULL)
  , fhPullY_Smt_Width(NULL)
  , fhPullZ_Smt_Width(NULL)
  , fhTOff_Smt(NULL)
  , fhTOff_Smt_Off(NULL)
  , fhDeltaTt_Smt(NULL)
  , fhTOff_HMul2(NULL)
  , fiCorMode(0)
  , fiBeamCounter(-1)
  , fiStationMaxHMul(1000)
  , fTtTarg(30.)
  , fVTXNorm(0.)
  , fVTX_T(0.)
  , fVTX_X(0.)
  , fVTX_Y(0.)
  , fVTX_Z(0.)
  , fT0MAX(0.5)
  , fiEvent(0)
  , fGeoHandler(new CbmTofGeoHandler())
  , fTofId(NULL)
  , fDigiPar(NULL)
  , fDigiBdfPar(NULL)
  , fSIGT(0.1)
  , fSIGX(1.)
  , fSIGY(1.)
  , fSIGZ(1.)
  , fbUseSigCalib(kTRUE)
  , fdRefVelMean(0.)
  , fdRefDVel(1.E7)
Norbert Herrmann's avatar
Norbert Herrmann committed
183
  , fdR0Lim(0.)
Administrator's avatar
Administrator committed
184
185
186
187
188
189
190
191
  , fStart()
  , fStop()
  , fdTrackingTime(0.)
  , fdBeamMomentumLab(0.)
  , fbRemoveSignalPropagationTime(kFALSE)
  , fiBeamMaxHMul(1000)
  , fiCalOpt(0) {
  if (!fInstance) fInstance = this;
192
193
194
195
196
}
// -------------------------------------------------------------------------


// -----   Destructor   ----------------------------------------------------
Administrator's avatar
Administrator committed
197
198
CbmTofFindTracks::~CbmTofFindTracks() {
  if (fInstance == this) fInstance = 0;
199
200
201
202
203
204
  fTrackArray->Delete();
}
// -------------------------------------------------------------------------


// -----   Public method Init (abstract in base class)  --------------------
Administrator's avatar
Administrator committed
205
206
InitStatus CbmTofFindTracks::Init() {

207
  // Check for Track finder
Administrator's avatar
Administrator committed
208
  if (!fFinder) {
209
210
211
212
213
    cout << "-W- CbmTofFindTracks::Init: No track finder selected!" << endl;
    return kERROR;
  }

  // Check for Track fitter
Administrator's avatar
Administrator committed
214
  if (!fFitter) {
215
216
217
    cout << "-W- CbmTofFindTracks::Init: No track fitter selected!" << endl;
    return kERROR;
  }
Administrator's avatar
Administrator committed
218
219
220
221
  cout << Form("-D- CbmTofFindTracks::Init: track fitter at 0x%p", fFitter)
       << endl;

  fTrackletTools = new CbmTofTrackletTools();  // initialize tools
222
223
224

  // Get and check FairRootManager
  FairRootManager* ioman = FairRootManager::Instance();
Administrator's avatar
Administrator committed
225
  if (!ioman) {
226
    cout << "-E- CbmTofFindTracks::Init: "
Administrator's avatar
Administrator committed
227
         << "RootManager not instantiated!" << endl;
228
229
230
    return kFATAL;
  }

Administrator's avatar
Administrator committed
231
  ioman->InitSink();
232
233

  fEventsColl = dynamic_cast<TClonesArray*>(ioman->GetObject("Event"));
Administrator's avatar
Administrator committed
234
  if (!fEventsColl)
235
    fEventsColl = dynamic_cast<TClonesArray*>(ioman->GetObject("CbmEvent"));
Administrator's avatar
Administrator committed
236
237
238
239
  if (!fEventsColl) {
    LOG(info) << "CbmEvent not found in input file, assume eventwise input";
  } else {
    fTofHitArray = new TClonesArray("CbmTofHit");
240
241
242
243
  }

  // Get TOF hit Array
  fTofHitArrayIn = (TClonesArray*) ioman->GetObject("TofHit");
Administrator's avatar
Administrator committed
244
  if (!fTofHitArrayIn) {
245
246
247
248
    LOG(fatal) << "-W- CbmTofFindTracks::Init: No TofHit array!";
    return kERROR;
  }

Administrator's avatar
Administrator committed
249
  // Get TOF hit Array
250
  fTofMatchArrayIn = (TClonesArray*) ioman->GetObject("TofCalDigiMatch");
Administrator's avatar
Administrator committed
251
  if (!fTofMatchArrayIn) {
252
253
254
255
256
    LOG(fatal) << "CbmTofFindTracks::Init: No TofDigiMatch array!";
    return kERROR;
  }

  // Create and register output TofTrack array
Administrator's avatar
Administrator committed
257
258
259
260
261
262
263
264
265
266
267
268
  fTrackArray   = new TClonesArray("CbmTofTracklet", 100);
  fTofUHitArray = new TClonesArray("CbmTofHit", 100);
  //fTrackArray->BypassStreamer(kTRUE);  //needed?
  //ioman->Register("TofTracks", "TOF", fTrackArray, kFALSE); //FIXME
  if (fEventsColl) {
    fTrackArrayOut = new TClonesArray("CbmTofTracklet", 100);
    ioman->Register(
      "TofTracks", "TOF", fTrackArrayOut, kTRUE);  //FIXME, does not work !
  } else {
    ioman->Register(
      "TofTracks", "TOF", fTrackArray, kTRUE);  //FIXME, does not work !
    cout << "-I- CbmTofFindTracks::Init:TofTrack array registered" << endl;
269
270

    // Create and register TofUHit array for unused Hits
Administrator's avatar
Administrator committed
271
    ioman->Register("TofUHit", "TOF", fTofUHitArray, kFALSE);
272
273
274
275
  }
  // Call the Init method of the track finder
  fFinder->Init();

Administrator's avatar
Administrator committed
276
277
278
  if (fOutHstFileName == "") { fOutHstFileName = "./FindTofTracks.hst.root"; }
  LOG(info) << "CbmTofFindTracks::Init: Hst Output filename = "
            << fOutHstFileName;
279

Administrator's avatar
Administrator committed
280
  if (kFALSE == InitParameters()) return kFATAL;
281
282
283
284

  // default parameters
  // if (fMinNofHits < 1) fMinNofHits=1;

Administrator's avatar
Administrator committed
285
286
287
  //fill RpcId - map
  Bool_t bBeamCounter = kFALSE;
  Int_t iRpc          = 0;
Norbert Herrmann's avatar
Norbert Herrmann committed
288
  fRpcAddr.resize(0);
Administrator's avatar
Administrator committed
289
290
291
  for (Int_t iCell = 0; iCell < fDigiPar->GetNrOfModules(); iCell++) {
    Int_t iCellId = fDigiPar->GetCellId(iCell);
    Int_t iCh     = fTofId->GetCell(iCellId);
Norbert Herrmann's avatar
Norbert Herrmann committed
292
293
294
295
296
297
298
299
300
    if (0 == iCh) {
      LOG(info) << Form("Init found RpcInd %d, %lu at Addr 0x%08x, ModType %d, "
                        "ModId %d, RpcId %d ",
                        iRpc,
                        fRpcAddr.size(),
                        iCellId,
                        fTofId->GetSMType(iCellId),
                        fTofId->GetSModule(iCellId),
                        fTofId->GetCounter(iCellId));
Norbert Herrmann's avatar
Norbert Herrmann committed
301
      if (fTofId->GetSMType(iCellId) == 5) {
Administrator's avatar
Administrator committed
302
        bBeamCounter = kTRUE;
Norbert Herrmann's avatar
Norbert Herrmann committed
303
        LOG(info) << "Found beam counter in setup! at RpcInd " << iRpc
Norbert Herrmann's avatar
Norbert Herrmann committed
304
                  << ", Addr.size " << fRpcAddr.size();
Norbert Herrmann's avatar
Norbert Herrmann committed
305
      }
Administrator's avatar
Administrator committed
306
307
308
      fMapRpcIdParInd[iCellId] = iRpc;
      fRpcAddr.push_back(iCellId);
      iRpc++;
309
    }
Administrator's avatar
Administrator committed
310
311
  }
  fStationHMul.resize(fNTofStations + 1);
312
313
314
315
316
317


  LoadCalParameter();

  CreateHistograms();

Administrator's avatar
Administrator committed
318
319
320
321
  if (fiCalOpt > 0) {
    fTofCalibrator = new CbmTofCalibrator();
    if (fTofCalibrator->Init() != kSUCCESS) return kFATAL;
    if (bBeamCounter) {
Norbert Herrmann's avatar
Norbert Herrmann committed
322
      fTofCalibrator->SetBeam(bBeamCounter);
323
      fTofCalibrator->SetR0Lim(fdR0Lim);
Administrator's avatar
Administrator committed
324
      LOG(info) << "Set CbmTofCalibrator::R0Lim to " << fdR0Lim;
Administrator's avatar
Administrator committed
325
    }
326
327
  }

Administrator's avatar
Administrator committed
328
329
330
331
  LOG(info) << Form("BeamCounter to be used in tracking: 0x%08x",
                    fiBeamCounter);

  return kSUCCESS;
332
333
334
}
// -------------------------------------------------------------------------
/************************************************************************************/
Administrator's avatar
Administrator committed
335
336
Bool_t CbmTofFindTracks::LoadCalParameter() {
  if (fCalParFileName.IsNull()) return kTRUE;
337

Administrator's avatar
Administrator committed
338
339
340
341
342
343
  fCalParFile = new TFile(fCalParFileName, "");
  if (NULL == fCalParFile) {
    LOG(error) << "CbmTofFindTracks::LoadCalParameter: "
               << "file " << fCalParFileName << " does not exist!";
    return kTRUE;
  }
344

Administrator's avatar
Administrator committed
345
346
  LOG(info) << "CbmTofFindTracks::LoadCalParameter: "
            << " read from file " << fCalParFileName;
347

Administrator's avatar
Administrator committed
348
349
350
351
352
353
354
355
  TH1D* fhtmp   = (TH1D*) gDirectory->FindObjectAny(Form("hPullT_Smt_Off"));
  TH1D* fhtmpX  = (TH1D*) gDirectory->FindObjectAny(Form("hPullX_Smt_Off"));
  TH1D* fhtmpY  = (TH1D*) gDirectory->FindObjectAny(Form("hPullY_Smt_Off"));
  TH1D* fhtmpZ  = (TH1D*) gDirectory->FindObjectAny(Form("hPullZ_Smt_Off"));
  TH1D* fhtmpW  = (TH1D*) gDirectory->FindObjectAny(Form("hPullT_Smt_Width"));
  TH1D* fhtmpWX = (TH1D*) gDirectory->FindObjectAny(Form("hPullX_Smt_Width"));
  TH1D* fhtmpWY = (TH1D*) gDirectory->FindObjectAny(Form("hPullY_Smt_Width"));
  TH1D* fhtmpWZ = (TH1D*) gDirectory->FindObjectAny(Form("hPullZ_Smt_Width"));
356
357


Administrator's avatar
Administrator committed
358
359
360
361
362
363
364
  gROOT->cd();
  if (NULL == fhtmp) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullT_Smt_Off")
              << " not found. ";
  } else {
    fhPullT_Smt_Off = (TH1D*) fhtmp->Clone();
  }
365

Administrator's avatar
Administrator committed
366
367
368
369
370
371
  if (NULL == fhtmpX) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullX_Smt_Off")
              << " not found. ";
  } else {
    fhPullX_Smt_Off = (TH1D*) fhtmpX->Clone();
  }
372

Administrator's avatar
Administrator committed
373
374
375
376
377
378
  if (NULL == fhtmpY) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullY_Smt_Off")
              << " not found. ";
  } else {
    fhPullY_Smt_Off = (TH1D*) fhtmpY->Clone();
  }
379

Administrator's avatar
Administrator committed
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
  if (NULL == fhtmpZ) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullZ_Smt_Off")
              << " not found. ";
  } else {
    fhPullZ_Smt_Off = (TH1D*) fhtmpZ->Clone();
  }

  if (NULL == fhtmpW) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullT_Smt_Width")
              << " not found. ";
  } else {
    if (fbUseSigCalib) fhPullT_Smt_Width = (TH1D*) fhtmpW->Clone();
  }

  if (NULL == fhtmpWX) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullX_Smt_Width")
              << " not found. ";
  } else {
    if (fbUseSigCalib) fhPullX_Smt_Width = (TH1D*) fhtmpWX->Clone();
  }

  if (NULL == fhtmpWY) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullY_Smt_Width")
              << " not found. ";
  } else {
    if (fbUseSigCalib) fhPullY_Smt_Width = (TH1D*) fhtmpWY->Clone();
  }

  if (NULL == fhtmpWZ) {
    LOG(info) << Form("CbmTofFindTracks::LoadCalParameter: hPullZ_Smt_Width")
              << " not found. ";
  } else {
    if (fbUseSigCalib) fhPullZ_Smt_Width = (TH1D*) fhtmpWZ->Clone();
  }

  fCalParFile->Close();

  Double_t nSmt = fMapRpcIdParInd.size();

  if (NULL == fhPullT_Smt_Off) {  // provide default TOffset histogram
    fhPullT_Smt_Off =
      new TH1F(Form("hPullT_Smt_Off"),
               Form("Tracklet PullT vs RpcInd ; RpcInd ; #DeltaT (ns)"),
               nSmt,
               0,
               nSmt);

    // Initialize Parameter
    if (fiCorMode == 3)  // hidden option, FIXME
      for (Int_t iDet = 0; iDet < nSmt; iDet++) {
        std::map<Int_t, Int_t>::iterator it;
        //it = fMapRpcIdParInd.find(iDet);
        for (it = fMapRpcIdParInd.begin(); it != fMapRpcIdParInd.end(); it++) {
          if (it->second == iDet) break;
        }
        LOG(debug1) << Form(" iDet %d -> iUniqueId ?  0x%08x, 0x%08x ",
                            iDet,
                            it->first,
                            it->second);
        Int_t iUniqueId          = it->first;
        CbmTofCell* fChannelInfo = fDigiPar->GetCell(iUniqueId);
        if (NULL != fChannelInfo) {
Administrator's avatar
Administrator committed
442
443
          Double_t dVal =
            0.;  // FIXME numeric constant in code, default for cosmic
Administrator's avatar
Administrator committed
444
          if (fiBeamCounter != iUniqueId)
Administrator's avatar
Administrator committed
445
446
            dVal =
              fChannelInfo->GetZ() * fTtTarg;  //  use calibration target value
Administrator's avatar
Administrator committed
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
          fhPullT_Smt_Off->SetBinContent(iDet + 1, dVal);
          LOG(info) << Form("Initialize det 0x%08x at %d, z=%f with TOff %6.2f",
                            iUniqueId,
                            iDet + 1,
                            fChannelInfo->GetZ(),
                            dVal);
        }
      }
  }

  if (NULL == fhPullT_Smt_Width) {  // provide default TWidth histogram
    fhPullT_Smt_Width =
      new TH1F(Form("hPullT_Smt_Width"),
               Form("Tracklet ResiT Width vs RpcInd ; RpcInd ; RMS(T) (ns)"),
               nSmt,
               0,
               nSmt);

    // Initialize Parameter
    for (Int_t iDet = 0; iDet < nSmt; iDet++) {
      fhPullT_Smt_Width->SetBinContent(iDet + 1, fSIGT);
468
    }
Administrator's avatar
Administrator committed
469
  }
470

Administrator's avatar
Administrator committed
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
  LOG(info) << "CbmTofFindTracks::LoadCalParameter: fhPullT_Smt_Off at "
            << fhPullT_Smt_Off;

  if (NULL == fhPullX_Smt_Off)  // provide default XOffset histogram
    fhPullX_Smt_Off =
      new TH1F(Form("hPullX_Smt_Off"),
               Form("Tracklet ResiX vs RpcInd ; RpcInd ; #DeltaX (cm)"),
               nSmt,
               0,
               nSmt);
  if (NULL == fhPullX_Smt_Width) {
    fhPullX_Smt_Width =
      new TH1F(Form("hPullX_Smt_Width"),
               Form("Tracklet ResiX Width vs RpcInd ; RpcInd ; RMS(X) (cm)"),
               nSmt,
               0,
               nSmt);
    // Initialize Parameter
    for (Int_t iDet = 0; iDet < nSmt; iDet++) {
      fhPullX_Smt_Width->SetBinContent(iDet + 1, fSIGX);
491
    }
Administrator's avatar
Administrator committed
492
  }
493

Administrator's avatar
Administrator committed
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
  if (NULL == fhPullY_Smt_Off)  // provide default YOffset histogram
    fhPullY_Smt_Off =
      new TH1F(Form("hPullY_Smt_Off"),
               Form("Tracklet ResiY vs RpcInd ; RpcInd ; #DeltaY (cm)"),
               nSmt,
               0,
               nSmt);
  if (NULL == fhPullY_Smt_Width) {
    fhPullY_Smt_Width =
      new TH1F(Form("hPullY_Smt_Width"),
               Form("Tracklet ResiY Width vs RpcInd ; RpcInd ; RMS(Y) (cm)"),
               nSmt,
               0,
               nSmt);
    // Initialize Parameter
    for (Int_t iDet = 0; iDet < nSmt; iDet++) {
      fhPullY_Smt_Width->SetBinContent(iDet + 1, fSIGY);
511
    }
Administrator's avatar
Administrator committed
512
  }
513

Administrator's avatar
Administrator committed
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
  if (NULL == fhPullZ_Smt_Off)  // provide default TOffset histogram
    fhPullZ_Smt_Off =
      new TH1F(Form("hPullZ_Smt_Off"),
               Form("Tracklet ResiZ vs RpcInd ; RpcInd ; #DeltaZ (cm)"),
               nSmt,
               0,
               nSmt);
  if (NULL == fhPullZ_Smt_Width) {
    fhPullZ_Smt_Width =
      new TH1F(Form("hPullZ_Smt_Width"),
               Form("Tracklet ResiZ Width vs RpcInd ; RpcInd ; RMS(Z) (cm)"),
               nSmt,
               0,
               nSmt);
    // Initialize Parameter
    for (Int_t iDet = 0; iDet < nSmt; iDet++) {
      fhPullZ_Smt_Width->SetBinContent(iDet + 1, fSIGZ);
531
    }
Administrator's avatar
Administrator committed
532
  }
533

Administrator's avatar
Administrator committed
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
  return kTRUE;
}
//-------------------------------------------------------------------------------------------------
Bool_t CbmTofFindTracks::InitParameters() {
  // Initialize the TOF GeoHandler
  Bool_t isSimulation = kFALSE;
  Int_t iGeoVersion   = fGeoHandler->Init(isSimulation);
  if (k12b > iGeoVersion) {
    LOG(error) << "CbmTofFindTracks::InitParameters => Only compatible with "
                  "geometries after v12b !!!";
    return kFALSE;
  }

  LOG(info) << "CbmTofFindTracks::InitParameters: GeoVersion " << iGeoVersion;

  switch (iGeoVersion) {
    case k12b: fTofId = new CbmTofDetectorId_v12b(); break;
    case k14a: fTofId = new CbmTofDetectorId_v14a(); break;
Norbert Herrmann's avatar
Norbert Herrmann committed
552
    case k21a: fTofId = new CbmTofDetectorId_v21a(); break;
Administrator's avatar
Administrator committed
553
    default:
Norbert Herrmann's avatar
Norbert Herrmann committed
554
      LOG(fatal) << "CbmTofFindTracks::InitParameters: Invalid Detector ID "
Administrator's avatar
Administrator committed
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
                 << iGeoVersion;
  }

  // create digitization parameters from geometry file
  CbmTofCreateDigiPar* tofDigiPar =
    new CbmTofCreateDigiPar("TOF Digi Producer", "TOF task");
  LOG(info) << "Create DigiPar ";
  tofDigiPar->Init();

  return kTRUE;
}
// -----  SetParContainers -------------------------------------------------
void CbmTofFindTracks::SetParContainers() {
  FairRunAna* ana     = FairRunAna::Instance();
  FairRuntimeDb* rtdb = ana->GetRuntimeDb();
  //  rtdb->getContainer("CbmGeoPassivePar");
  //   rtdb->getContainer("CbmGeoStsPar");
  //   rtdb->getContainer("CbmGeoTofPar");
  rtdb->getContainer("FairBaseParSet");
  //    rtdb->getContainer("CbmGeoPassivePar");
  // rtdb->getContainer("CbmGeoStsPar");
  // rtdb->getContainer("CbmGeoRichPar");
  rtdb->getContainer("CbmGeoTofPar");
  // rtdb->getContainer("CbmFieldPar");
  fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));

  LOG(info) << "  CbmTofFindTracks::SetParContainers found "
            << fDigiPar->GetNrOfModules() << " cells ";

  fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
}
// -------------------------------------------------------------------------

Bool_t CbmTofFindTracks::WriteHistos() {
  if (fiCorMode < 0) return kTRUE;

  LOG(info) << Form("CbmTofFindTracks::WriteHistos: %s, mode = %d",
                    fCalOutFileName.Data(),
                    fiCorMode);

  // Write histogramms to the file
  TDirectory* oldir = gDirectory;
  TFile* fHist      = new TFile(fCalOutFileName, "RECREATE");
  fHist->cd();
  const Double_t RMSmin = 0.03;  // in ns

  switch (fiCorMode) {
    case 0: {
      TProfile* htmp  = fhPullT_Smt->ProfileX();
      TH1D* htmp1D    = htmp->ProjectionX();
      TProfile* hTOff = fhTOff_HMul2->ProfileX();
      TH1D* hTOff1D   = hTOff->ProjectionX();

      Double_t nx = htmp1D->GetNbinsX();
      for (Int_t ix = 1; ix < nx; ix++) {
        Double_t dVal = 0;
        if (fhPullT_Smt_Off != NULL) {
          dVal = fhPullT_Smt_Off->GetBinContent(ix + 1);
        } else {
          fhPullT_Smt_Off = htmp1D;
        }
        TH1D* hTOff1DY =
          fhTOff_HMul2->ProjectionY(Form("_py%d", ix), ix + 1, ix + 1, "");
        Double_t dFMean = 0.;
        if (hTOff1DY->GetEntries() > 100) {
          //Double_t dMean=hTOff1DY->GetMean();
          Int_t iBmax  = hTOff1DY->GetMaximumBin();
          TAxis* xaxis = hTOff1DY->GetXaxis();
          Double_t dMean =
            xaxis->GetBinCenter(iBmax);  //X-value of bin with maximal content
          Double_t dLim = 1000.;         //1.5*hTOff1DY->GetRMS();
          TFitResultPtr fRes =
            hTOff1DY->Fit("gaus", "S", "", dMean - dLim, dMean + dLim);
          dFMean = fRes->Parameter(1);
        }
        dVal -= dFMean;
        LOG(info) << "Init  TOff " << ix << ": Old "
                  << fhPullT_Smt_Off->GetBinContent(ix + 1) << ", Cnts "
                  << hTOff1D->GetBinContent(ix + 1) << ", FitMean " << dFMean
                  << " -> " << dVal;
        fhPullT_Smt_Off->SetBinContent(ix + 1, dVal);
636
637
638
      }
    }

Administrator's avatar
Administrator committed
639
    break;
640

Administrator's avatar
Administrator committed
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
    case 1:  // correct mean deviation from fit (Pull)
    {
      TProfile* htmp  = fhPullT_Smt->ProfileX();
      TH1D* htmp1D    = htmp->ProjectionX();
      TProfile* hTOff = fhTOff_Smt->ProfileX();
      TH1D* hTOff1D   = hTOff->ProjectionX();

      if (fhPullT_Smt_Off != NULL) {
        Double_t nx = htmp1D->GetNbinsX();
        for (Int_t ix = 0; ix < nx; ix++) {
          Double_t dVal = fhPullT_Smt_Off->GetBinContent(ix + 1);
          dVal -= htmp1D->GetBinContent(ix + 1);

          LOG(debug1) << "Update hPullT_Smt_Off " << ix << ": "
                      << fhPullT_Smt_Off->GetBinContent(ix + 1) << " + "
                      << htmp1D->GetBinContent(ix + 1) << " + "
                      << hTOff1D->GetBinContent(ix + 1) << " -> " << dVal;
          fhPullT_Smt_Off->SetBinContent(ix + 1, dVal);
        }
      } else {
        LOG(warning)
          << "CbmTofFindTracks::WriteHistos: fhPullT_Smt_Off not found ";
663
664
665
      }
    }

Administrator's avatar
Administrator committed
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
    break;

    case 2:  // correct deviation from DeltaTt=0 expectation
    {
      TProfile* htmp  = fhPullT_Smt->ProfileX();
      TH1D* htmp1D    = htmp->ProjectionX();
      TProfile* hTOff = fhTOff_Smt->ProfileX();
      TH1D* hTOff1D   = hTOff->ProjectionX();

      if (fhPullT_Smt_Off != NULL) {
        Double_t nx = htmp1D->GetNbinsX();
        for (Int_t ix = 0; ix < nx; ix++) {
          Double_t dVal = fhPullT_Smt_Off->GetBinContent(ix + 1);
          dVal -= hTOff1D->GetBinContent(ix + 1);
          TH1D* hTOff1DY =
            fhTOff_Smt->ProjectionY(Form("_py%d", ix), ix + 1, ix + 1, "");
          Double_t dFMean = 0.;
          if (hTOff1DY->GetEntries() > 100) {
            //Double_t dMean=hTOff1DY->GetMean();
            Int_t iBmax  = hTOff1DY->GetMaximumBin();
            TAxis* xaxis = hTOff1DY->GetXaxis();
            Double_t dMean =
              xaxis->GetBinCenter(iBmax);  //X-value of bin with maximal content
            Double_t dLim = 1.5 * hTOff1DY->GetRMS();
            TFitResultPtr fRes =
              hTOff1DY->Fit("gaus", "S", "", dMean - dLim, dMean + dLim);
            Int_t iFitStatus = fRes;
            if (iFitStatus == 0) {  // check validity of fit
              dFMean = fRes->Parameter(1);
              dVal +=
                hTOff1D->GetBinContent(ix + 1);  //revert default correction
              dVal -= dFMean;
            }
            LOG(info) << "Update hPullT_Smt_Off Ind " << ix << ": Old "
                      << fhPullT_Smt_Off->GetBinContent(ix + 1) << ", Pull "
                      << htmp1D->GetBinContent(ix + 1) << ", Dev@Peak "
                      << hTOff1D->GetBinContent(ix + 1) << ", FitMean "
                      << dFMean << " -> " << dVal;
          } else {
            LOG(debug1) << "Update hPullT_Smt_Off " << ix
                        << ": insufficient counts: " << hTOff1DY->GetEntries();
          }
          fhPullT_Smt_Off->SetBinContent(ix + 1, dVal);
        }
      } else {
        LOG(warning)
          << "CbmTofFindTracks::WriteHistos: fhPullT_Smt_Off not found ";
713
      }
Administrator's avatar
Administrator committed
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
    } break;

    case 3:  // correct Time Offset from PullT, extract width
    {
      TProfile* htmp = fhPullT_Smt->ProfileX();
      TH1D* htmp1D   = htmp->ProjectionX();

      if (fhPullT_Smt_Off != NULL) {
        Double_t nx = htmp1D->GetNbinsX();
        for (Int_t ix = 0; ix < nx; ix++) {
          TH1D* hpy = fhPullT_Smt->ProjectionY("_py", ix + 1, ix + 1);
          if (hpy->GetEntries() > 100.) {
            Int_t iBmax  = hpy->GetMaximumBin();
            TAxis* xaxis = hpy->GetXaxis();
            Double_t dMean =
              xaxis->GetBinCenter(iBmax);  //X-value of bin with maximal content
            Double_t dRMS = TMath::Abs(hpy->GetRMS());
            Double_t dLim = 1.5 * dRMS;
            TFitResultPtr fRes =
              hpy->Fit("gaus", "S", "", dMean - dLim, dMean + dLim);
            Double_t dFMean = fRes->Parameter(1);

            Double_t dVal = fhPullT_Smt_Off->GetBinContent(ix + 1);
            dVal -= dFMean;
            TF1* fg              = hpy->GetFunction("gaus");
            Double_t dFMeanError = fg->GetParError(1);
Norbert Herrmann's avatar
Norbert Herrmann committed
740
            LOG(info) << "Update hPullT_Smt_Off3 Ind " << ix
Norbert Herrmann's avatar
Norbert Herrmann committed
741
                      << Form(", 0x%08x: ", fRpcAddr[ix])
Administrator's avatar
Administrator committed
742
743
744
745
746
747
748
                      << fhPullT_Smt_Off->GetBinContent(ix + 1) << " + "
                      << dFMean << ", Err " << dFMeanError << " -> " << dVal
                      << ", Width " << dRMS << ", Chi2 " << fg->GetChisquare();
            if (dFMeanError < 0.05) {  // FIXME: hardwired constant
              if (dRMS < RMSmin) dRMS = RMSmin;
              if (dRMS > fSIGT * 3.0) dRMS = fSIGT * 3.;
              if (fRpcAddr[ix]
Norbert Herrmann's avatar
Norbert Herrmann committed
749
                  != fiBeamCounter)  // don't correct beam counter time
Administrator's avatar
Administrator committed
750
                fhPullT_Smt_Off->SetBinContent(ix + 1, dVal);
Norbert Herrmann's avatar
Norbert Herrmann committed
751
              else
Norbert Herrmann's avatar
Norbert Herrmann committed
752
753
                LOG(info) << "No Off3 correction for beam counter at index "
                          << ix;
Administrator's avatar
Administrator committed
754
755
756
757
758
759
760
761
762
763
              fhPullT_Smt_Width->SetBinContent(ix + 1, dRMS);
            }
          } else {
            LOG(debug1) << "Update hPullT_Smt_Off " << ix
                        << ": insufficient counts: " << hpy->GetEntries();
          }
        }
      } else {
        LOG(warning)
          << "CbmTofFindTracks::WriteHistos: fhPullT_Smt_Off not found ";
764
765
      }
    }
Administrator's avatar
Administrator committed
766
767
768
769
770
771
772
773
774
775
776

    break;

    case 4:  // correct mean deviation from fit (Pull), extract width for x direction
    {
      TProfile* htmp = fhPullX_Smt->ProfileX();
      TH1D* htmp1D   = htmp->ProjectionX();

      if (fhPullX_Smt_Off != NULL) {
        Double_t nx = htmp1D->GetNbinsX();
        for (Int_t ix = 0; ix < nx; ix++) {
Administrator's avatar
Administrator committed
777
          TH1D* hpy     = fhPullX_Smt->ProjectionY("_py", ix + 1, ix + 1);
778
779
          Double_t dVal = fhPullX_Smt_Off->GetBinContent(ix + 1);
          //dVal -= htmp1D->GetBinContent(ix + 1);
Administrator's avatar
Administrator committed
780
781
          if (hpy->GetEntries() > 100.) {
            Double_t dRMS = TMath::Abs(hpy->GetRMS());
782
783
784
785
786
787
            /* not found by linker
            Int_t maxPeaks=1;
            auto *s=new TSpectrum(maxPeaks);
            Int_t nPeaks=s->Search(hpy,dRMS,"new");
            if (nPeaks==1) {
            */
Administrator's avatar
Administrator committed
788
            if (kTRUE) {
789
790
791
792
              //Double_t *xPeaks=s->GetPositionX();
              //LOG(info) << "Found peak at" << xPeaks[0];
              // Fit gaussian
              //Double_t dFMean = xPeaks[0];
Administrator's avatar
Administrator committed
793
794
              Double_t dFMean   = hpy->GetBinCenter(hpy->GetMaximumBin());
              Double_t dFLim    = 0.5;  // CAUTION, fixed numeric value
795
              Double_t dBinSize = hpy->GetBinWidth(1);
Administrator's avatar
Administrator committed
796
              dFLim             = TMath::Max(dFLim, 5. * dBinSize);
797
798
799
              TFitResultPtr fRes =
                hpy->Fit("gaus", "S", "", dFMean - dFLim, dFMean + dFLim);
              dVal -= fRes->Parameter(1);
Administrator's avatar
Administrator committed
800
801
802
803
              dRMS = fRes->Parameter(2);
              LOG(info) << "PeakFit at " << dFMean << ", lim " << dFLim
                        << " : mean " << fRes->Parameter(1) << ", width "
                        << dRMS;
804
805
            }

Administrator's avatar
Administrator committed
806
807
808
            if (dRMS < fSIGX * 0.5) dRMS = fSIGX * 0.5;
            if (dRMS > fSIGX * 3.0) dRMS = fSIGX * 3.;

809
810
            // limit maximal shift in X, for larger values, change geometry file
            if (dVal < -3.) dVal = -3.;
Administrator's avatar
Administrator committed
811
            if (dVal > 3.) dVal = 3.;
Administrator's avatar
Administrator committed
812
813
814
815
            LOG(info) << "Update hPullX_Smt_Off " << ix << ": "
                      << fhPullX_Smt_Off->GetBinContent(ix + 1) << " + "
                      << htmp1D->GetBinContent(ix + 1) << " -> " << dVal
                      << ", Width " << dRMS;
Norbert Herrmann's avatar
Norbert Herrmann committed
816
817
            if (fRpcAddr[ix]
                != fiBeamCounter)  // don't correct beam counter position
Norbert Herrmann's avatar
Norbert Herrmann committed
818
              fhPullX_Smt_Off->SetBinContent(ix + 1, dVal);
819
            fhPullX_Smt_Width->SetBinContent(ix + 1, dRMS);
Administrator's avatar
Administrator committed
820
821
822
823
824
          }
        }
      } else {
        LOG(warning)
          << "CbmTofFindTracks::WriteHistos: fhPullX_Smt_Off not found ";
825
826
827
      }
    }

Administrator's avatar
Administrator committed
828
    break;
829

Administrator's avatar
Administrator committed
830
    case 5:  // correct mean deviation from fit (Pull), extract width for Y direction
831
    {
Administrator's avatar
Administrator committed
832
833
834
835
836
837
838
839
      TProfile* htmp = fhPullY_Smt->ProfileX();
      TH1D* htmp1D   = htmp->ProjectionX();

      if (fhPullY_Smt_Off != NULL) {
        Double_t nx = htmp1D->GetNbinsX();
        for (Int_t ix = 0; ix < nx; ix++) {
          Double_t dVal = fhPullY_Smt_Off->GetBinContent(ix + 1);
          dVal -= htmp1D->GetBinContent(ix + 1);
Norbert Herrmann's avatar
Norbert Herrmann committed
840
841
          if (fRpcAddr[ix]
              != fiBeamCounter)  // don't correct beam counter position
Norbert Herrmann's avatar
Norbert Herrmann committed
842
            fhPullY_Smt_Off->SetBinContent(ix + 1, dVal);
Administrator's avatar
Administrator committed
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866

          TH1D* hpy = fhPullY_Smt->ProjectionY("_py", ix + 1, ix + 1);
          if (hpy->GetEntries() > 100.) {
            Double_t dRMS = TMath::Abs(hpy->GetRMS());
            if (dRMS < fSIGY * 0.5) dRMS = 0.5 * fSIGY;
            if (dRMS > fSIGY * 3.0) dRMS = fSIGY * 3.;
            fhPullY_Smt_Width->SetBinContent(ix + 1, dRMS);

            LOG(debug1) << "Update hPullY_Smt_Off " << ix << ": "
                        << fhPullY_Smt_Off->GetBinContent(ix + 1) << " + "
                        << htmp1D->GetBinContent(ix + 1) << " -> " << dVal
                        << ", Width " << dRMS;
          }
        }
      } else {
        LOG(warning)
          << "CbmTofFindTracks::WriteHistos: fhPullY_Smt_Off not found ";
      }

    }

    break;

    case 6:  // correct mean deviation from fit (Pull), extract width
867
    {
Administrator's avatar
Administrator committed
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
      TProfile* htmp = fhPullZ_Smt->ProfileX();
      TH1D* htmp1D   = htmp->ProjectionX();

      if (fhPullZ_Smt_Off != NULL) {
        Double_t nx = htmp1D->GetNbinsX();
        for (Int_t ix = 0; ix < nx; ix++) {
          Double_t dVal = fhPullZ_Smt_Off->GetBinContent(ix + 1);
          dVal -= htmp1D->GetBinContent(ix + 1);
          fhPullZ_Smt_Off->SetBinContent(ix + 1, dVal);

          TH1D* hpy = fhPullZ_Smt->ProjectionY("_py", ix + 1, ix + 1);
          if (hpy->GetEntries() > 100.) {
            Double_t dRMS = TMath::Abs(hpy->GetRMS());

            LOG(debug1) << "Update hPullZ_Smt_Off " << ix << ": "
                        << fhPullZ_Smt_Off->GetBinContent(ix + 1) << " + "
                        << htmp1D->GetBinContent(ix + 1) << " -> " << dVal
                        << ", Width " << dRMS;
            if (dRMS < 1.5) dRMS = 1.5;
            fhPullZ_Smt_Width->SetBinContent(ix + 1, dRMS);
          }
        }
      } else {
        LOG(warning)
          << "CbmTofFindTracks::WriteHistos: fhPullZ_Smt_Off not found ";
      }

    } break;

    case 7:  // extract residual widthes in T, X, Y, Z
898
    {
Administrator's avatar
Administrator committed
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
      for (Int_t iStation = 0;
           iStation < static_cast<Int_t>(fMapRpcIdParInd.size());
           iStation++) {
        TH1D* hResidualT =
          fhPullT_Smt->ProjectionY("_py", iStation + 1, iStation + 1);
        TH1D* hResidualX =
          fhPullX_Smt->ProjectionY("_py", iStation + 1, iStation + 1);
        TH1D* hResidualY =
          fhPullY_Smt->ProjectionY("_py", iStation + 1, iStation + 1);
        TH1D* hResidualZ =
          fhPullZ_Smt->ProjectionY("_py", iStation + 1, iStation + 1);

        if (hResidualT->GetEntries() > 100.) {
          Double_t dRMS = TMath::Abs(hResidualT->GetRMS());

          if (dRMS < RMSmin) dRMS = RMSmin;
          if (dRMS > 3. * fSIGT) dRMS = 3. * fSIGT;

          fhPullT_Smt_Width->SetBinContent(iStation + 1, dRMS);
        }

        if (hResidualX->GetEntries() > 100.) {
          Double_t dRMS = TMath::Abs(hResidualX->GetRMS());

          if (dRMS < 0.5 * fSIGX) dRMS = 0.5 * fSIGX;
          if (dRMS > 3. * fSIGX) dRMS = 3. * fSIGX;

          fhPullX_Smt_Width->SetBinContent(iStation + 1, dRMS);
        }

        if (hResidualY->GetEntries() > 100.) {
          Double_t dRMS = TMath::Abs(hResidualY->GetRMS());

          if (dRMS < 0.5 * fSIGY) dRMS = 0.5 * fSIGY;
          if (dRMS > 3. * fSIGY) dRMS = 3. * fSIGY;

          fhPullY_Smt_Width->SetBinContent(iStation + 1, dRMS);
        }

        if (hResidualZ->GetEntries() > 100.) {
          Double_t dRMS = TMath::Abs(hResidualZ->GetRMS());

          if (dRMS < 1.5) dRMS = 1.5;

          fhPullZ_Smt_Width->SetBinContent(iStation + 1, dRMS);
        }
      }
    } break;

    case 10:  //correct mean deviation from TB - histo of station 0
    case 11:
    case 12:
    case 13:
    case 14:
    case 15:
    case 16:
    case 17:
    case 18:
    case 19: {
      Int_t iSt     = fiCorMode % 10;
      TString hname = Form("hPull%s_Station_%d", "TB", iSt);
      TH1* h1       = (TH1*) gROOT->FindObjectAny(hname);
      if (h1->GetEntries() > 100) {
        Double_t dFMean = h1->GetMean();
        Double_t dFLim  = 2.5 * h1->GetRMS();
        TFitResultPtr fRes =
          h1->Fit("gaus", "S", "", dFMean - dFLim, dFMean + dFLim);
        Double_t dDOff = fRes->Parameter(1);
        Double_t dSig  = fRes->Parameter(2);
        Int_t iRpcInd  = fMapRpcIdParInd[fMapStationRpcId[iSt]];
        Double_t dVal  = fhPullT_Smt_Off->GetBinContent(iRpcInd + 1);
        dVal -= dDOff;
        LOG(info) << "Update hPullT_Smt_OffP Ind " << iSt << ", Ind " << iRpcInd
                  << ": " << fhPullT_Smt_Off->GetBinContent(iRpcInd + 1)
                  << " - " << dDOff << " -> " << dVal << ", Width " << dSig;
        fhPullT_Smt_Off->SetBinContent(iRpcInd + 1, dVal);
        if (dSig < fSIGT * 0.5) dSig = 0.5 * fSIGT;
        if (dSig > fSIGT * 3.0) dSig = fSIGT * 3.;
        fhPullT_Smt_Width->SetBinContent(iRpcInd + 1, dSig);
      } else {
        LOG(info) << "CbmTofFindTracks::WriteHistos: Too few entries in histo "
                  << hname;
      }
    } break;

    default:;
  }

  if (NULL != fhPullT_Smt_Off) {
    // always extract residual widthes in T, X, Y, Z
    for (Int_t iStation = 0;
         iStation < static_cast<Int_t>(fMapRpcIdParInd.size());
         iStation++) {
      TH1D* hResidualT =
        fhPullT_Smt->ProjectionY("_py", iStation + 1, iStation + 1);
      TH1D* hResidualX =
        fhPullX_Smt->ProjectionY("_py", iStation + 1, iStation + 1);
      TH1D* hResidualY =
        fhPullY_Smt->ProjectionY("_py", iStation + 1, iStation + 1);
      TH1D* hResidualZ =
        fhPullZ_Smt->ProjectionY("_py", iStation + 1, iStation + 1);
      if (hResidualT->GetEntries() > 100.) {