CbmRoot
Loading...
Searching...
No Matches
CbmTofTestBeamClusterizer.cxx
Go to the documentation of this file.
1/* Copyright (C) 2013-2021 PI-UHd, GSI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann [committer], Pierre-Alain Loizeau */
4
14
15// TOF Classes and includes
16#include "CbmMatch.h"
17#include "CbmTofAddress.h" // in cbmdata/tof
18#include "CbmTofCell.h" // in tof/TofData
19#include "CbmTofDetectorId_v12b.h" // in cbmdata/tof
20#include "CbmTofDetectorId_v14a.h" // in cbmdata/tof
21#include "CbmTofDigi.h" // in cbmdata/tof
22#include "CbmTofDigiBdfPar.h" // in tof/TofParam
23#include "CbmTofDigiPar.h" // in tof/TofParam
24#include "CbmTofGeoHandler.h" // in tof/TofTools
25#include "CbmTofHit.h" // in cbmdata/tof
26#include "CbmTofPoint.h" // in cbmdata/tof
27#include "TTrbHeader.h"
28
29// CBMroot classes and includes
30#include "CbmMCTrack.h"
31
32// FAIR classes and includes
33#include "FairRootManager.h"
34#include "FairRunAna.h"
35#include "FairRuntimeDb.h"
36
37#include <Logger.h>
38
39// ROOT Classes and includes
40#include "TClonesArray.h"
41#include "TDirectory.h"
42#include "TF1.h"
43#include "TF2.h"
44#include "TGeoManager.h"
45#include "TH1.h"
46#include "TH2.h"
47#include "TLine.h"
48#include "TMath.h"
49#include "TMinuit.h"
50#include "TProfile.h"
51#include "TROOT.h"
52#include "TRandom3.h"
53#include "TVector3.h"
54
55#include <TFile.h>
56
57// Constants definitions
59
60// C++ Classes and includes
61// Globals
62#include <vector>
63
64static Int_t iIndexDut = 0;
65static Double_t StartAnalysisTime = 0.;
66//const Double_t cLight=29.9792; // in cm/ns (VF) not used
67
68std::vector<CbmTofPoint*> vPtsRef;
69std::vector<Int_t> vDigiIndRef;
70
72
73/************************************************************************************/
78
79CbmTofTestBeamClusterizer::CbmTofTestBeamClusterizer(const char* name, Int_t verbose, Bool_t writeDataInOut)
80 : FairTask(TString(name), verbose)
81 , fGeoHandler(new CbmTofGeoHandler())
82 , fTofId(NULL)
83 , fDigiPar(NULL)
84 , fChannelInfo(NULL)
85 , fDigiBdfPar(NULL)
86 , fTrbHeader(NULL)
87 , fTofPointsColl(NULL)
88 , fMcTracksColl(NULL)
89 , fTofDigisColl(NULL)
90 , fbWriteHitsInOut(writeDataInOut)
91 , fbWriteDigisInOut(writeDataInOut)
92 , fTofCalDigisColl(NULL)
93 , fTofHitsColl(NULL)
94 , fTofDigiMatchColl(NULL)
95 , fiNbHits(0)
96 , fVerbose(verbose)
97 , fStorDigiExp()
98 , fStorDigiInd()
99 , fviClusterMul()
100 , fviClusterSize()
101 , fviTrkMul()
102 , fvdX()
103 , fvdY()
104 , fvdDifX()
105 , fvdDifY()
106 , fvdDifCh()
107 , fhClustBuildTime(NULL)
108 , fhHitsPerTracks(NULL)
109 , fhPtsPerHit(NULL)
110 , fhTimeResSingHits(NULL)
111 , fhTimeResSingHitsB(NULL)
112 , fhTimePtVsHits(NULL)
113 , fhClusterSize(NULL)
114 , fhClusterSizeType(NULL)
115 , fhTrackMul(NULL)
116 , fhClusterSizeMulti(NULL)
117 , fhTrk1MulPos(NULL)
118 , fhHiTrkMulPos(NULL)
119 , fhAllTrkMulPos(NULL)
120 , fhMultiTrkProbPos(NULL)
121 , fhDigSpacDifClust(NULL)
122 , fhDigTimeDifClust(NULL)
123 , fhDigDistClust(NULL)
124 , fhClustSizeDifX(NULL)
125 , fhClustSizeDifY(NULL)
126 , fhChDifDifX(NULL)
127 , fhChDifDifY(NULL)
128 , fhCluMulCorDutSel(NULL)
129 , fhRpcDigiCor()
130 , fhRpcCluMul()
131 , fhRpcCluRate()
132 , fhRpcCluPosition()
133 , fhRpcCluDelPos()
134 , fhRpcCluDelMatPos()
135 , fhRpcCluTOff()
136 , fhRpcCluDelTOff()
137 , fhRpcCluDelMatTOff()
138 , fhRpcCluTrms()
139 , fhRpcCluTot()
140 , fhRpcCluSize()
141 , fhRpcCluAvWalk()
142 , fhRpcCluAvLnWalk()
143 , fhRpcCluWalk()
144 , fhSmCluPosition()
145 , fhSmCluTOff()
146 , fhSmCluSvel()
147 , fhSmCluFpar()
148 , fhRpcDTLastHits()
149 , fhRpcDTLastHits_Tot()
150 , fhRpcDTLastHits_CluSize()
151 , fhTRpcCluMul()
152 , fhTRpcCluPosition()
153 , fhTRpcCluTOff()
154 , fhTRpcCluTot()
155 , fhTRpcCluSize()
156 , fhTRpcCluAvWalk()
157 , fhTRpcCluDelTof()
158 , fhTRpcCludXdY()
159 , fhTRpcCluWalk()
160 , fhTSmCluPosition()
161 , fhTSmCluTOff()
162 , fhTSmCluTRun()
163 , fhTRpcCluTOffDTLastHits()
164 , fhTRpcCluTotDTLastHits()
165 , fhTRpcCluSizeDTLastHits()
166 , fhTRpcCluMemMulDTLastHits()
167 , fhSeldT()
168 , fvCPDelTof()
169 , fvCPTOff()
170 , fvCPTotGain()
171 , fvCPTotOff()
172 , fvCPWalk()
173 , fvLastHits()
174 , fiNbSameSide(0)
175 , fhNbSameSide(NULL)
176 , fhNbDigiPerChan(NULL)
177 , fStart()
178 , fStop()
179 , dTRef(0.)
180 , fdTRefMax(0.)
181 , fCalMode(0)
182 , fCalSel(0)
183 , fCalSmAddr(0)
184 , fdCaldXdYMax(0.)
185 , fiCluMulMax(0)
186 , fTRefMode(0)
187 , fTRefHits(0)
188 , fDutId(0)
189 , fDutSm(0)
190 , fDutRpc(0)
191 , fDutAddr(0)
192 , fSelId(0)
193 , fSelSm(0)
194 , fSelRpc(0)
195 , fSelAddr(0)
196 , fiBeamRefType(0)
197 , fiBeamRefSm(0)
198 , fiBeamRefDet(0)
199 , fiBeamRefAddr(0)
200 , fiBeamRefMulMax(1)
201 , fiBeamAddRefMul(0)
202 , fSel2Id(0)
203 , fSel2Sm(0)
204 , fSel2Rpc(0)
205 , fSel2Addr(0)
206 , fDetIdIndexMap()
207 , fviDetId()
208 , fPosYMaxScal(0.)
209 , fTRefDifMax(0.)
210 , fTotMax(0.)
211 , fTotMin(0.)
212 , fTotOff(0.)
213 , fTotMean(0.)
214 , fdDelTofMax(60.)
215 , fTotPreRange(0.)
216 , fMaxTimeDist(0.)
217 , fdChannelDeadtime(0.)
218 , fdMemoryTime(0.)
219 , fdYFitMin(1.E6)
220 , fEnableMatchPosScaling(kTRUE)
221 , fEnableAvWalk(kFALSE)
222 , fbPs2Ns(kFALSE)
223 , fCalParFileName("")
224 , fOutHstFileName("")
225 , fCalParFile(NULL)
226 , fiNevtBuild(0)
227 , fiMsgCnt(100)
228 , fdTOTMax(50.)
229 , fdTOTMin(0.)
230 , fdTTotMean(2.)
231 , fdMaxTimeDist(0.)
232 , fdMaxSpaceDist(0.)
233 , fdEvent(0)
234 , fbSwapChannelSides(kFALSE)
235 , fiOutputTreeEntry(0)
236 , fiFileIndex(0)
237 , fbAlternativeBranchNames(kFALSE)
238{
239 if (!fInstance) fInstance = this;
240}
241
243{
244 if (fGeoHandler) delete fGeoHandler;
245 if (fInstance == this) fInstance = 0;
246 // DeleteHistos(); // <-- if needed ?
247}
248
249/************************************************************************************/
250// FairTasks inherited functions
252{
253 LOG(info) << "CbmTofTestBeamClusterizer initializing... expect Digis in ns units! ";
254
255 if (kFALSE == RegisterInputs()) return kFATAL;
256
257 if (kFALSE == RegisterOutputs()) return kFATAL;
258
259 if (kFALSE == InitParameters()) return kFATAL;
260
261 if (kFALSE == LoadGeometry()) return kFATAL;
262
263 if (kFALSE == InitCalibParameter()) return kFATAL;
264
265 if (kFALSE == CreateHistos()) return kFATAL;
266
272
273 return kSUCCESS;
274}
275
276
278{
279 LOG(info) << "=> Get the digi parameters for tof";
280 LOG(warning) << "Return without action";
281 return;
282 // Get Base Container
283 FairRunAna* ana = FairRunAna::Instance();
284 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
285
286 fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
287
288 LOG(info) << "found " << fDigiPar->GetNrOfModules() << " cells ";
289 fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
290}
291
292
293void CbmTofTestBeamClusterizer::Exec(Option_t* /*option*/)
294{
295 // N.B. FIXME
296 // Neither the 'CbmDigi' nor the 'CbmHit' inheritance chains reimplement
297 // 'TObject::Clear' which would allow the pointer member variables
298 // 'CbmDigi::fMatch' and 'CbmHit::fMatch', respectively, to be properly
299 // deleted by calling 'TClonesArray::Clear("C")'.
300 // As in the case of 'CbmTofHit' a separate matching branch exists,
301 // its member variable 'fMatch' never points to a valid 'CbmMatch' object.
302 // For this reason, NOT calling the 'CbmHit' destructor (wherein a valid
303 // 'fMatch' would be deleted) through 'TClonesArray::Delete' does NOT cause
304 // a memory leak upon constructing new 'CbmTofHit' objects in the output
305 // array performing a placement new operation on the 'TClonesArray'.
306 // On the contrary, digi-to-point links are (currently) not stored in a
307 // separate matching branch but streamed with the 'CbmDigi' object.
308 // If the digis which are read from the input 'TTree' do contain valid
309 // 'fMatch' pointers, copy-constructing them in the "TofCalDigi" output
310 // array will be accompanied with memory allocation. Without calling the
311 // destructors of objects in "TofCalDigi" through 'TClonesArray::Delete'
312 // (see below) the allocated memory is not freed and accumulates the more
313 // digis are being processed. In consequence, a memory leak appears.
314
315 // Clear output arrays
316 fTofCalDigisColl->Delete();
317 fTofHitsColl->Clear("C");
318 //fTofHitsColl->Delete(); // Computationally costly!, but hopefully safe
319 //for (Int_t i=0; i<fTofDigiMatchColl->GetEntriesFast(); i++) ((CbmMatch *)(fTofDigiMatchColl->At(i)))->ClearLinks(); // FIXME, try to tamper memory leak (did not help)
320 //fTofDigiMatchColl->Clear("C+L"); // leads to memory leak
321 fTofDigiMatchColl->Delete();
322
323 fiOutputTreeEntry = FairRootManager::Instance()->GetOutTree()->GetEntries();
324
325 fiNbHits = 0;
326
327 LOG(debug) << "CbmTofTestBeamClusterizer::Exec => New event";
328 fStart.Set();
329
331
333
334 fStop.Set();
335
336 fdEvent++;
337 FillHistos();
338
339 // fTofDigisColl->RemoveAll();
340}
341
342/************************************************************************************/
344{
345 WriteHistos();
346 // Prevent them from being sucked in by the CbmHadronAnalysis WriteHistograms method
347 // DeleteHistos();
348 if (fdMemoryTime > 0.) CleanLHMemory();
349}
350
352{
353 SetCalMode(calMode);
354 WriteHistos();
355}
356
357/************************************************************************************/
358// Functions common for all clusters approximations
360{
361 FairRootManager* fManager = FairRootManager::Instance();
362
363 if (NULL == fManager) {
364 LOG(error) << "CbmTofTestBeamClusterizer::RegisterInputs => Could not find "
365 "FairRootManager!!!";
366 return kFALSE;
367 } // if( NULL == fTofDigisColl)
368
369 /*
370 fTofPointsColl = (TClonesArray *) fManager->GetObject("TofPoint");
371 if( NULL == fTofPointsColl)
372 {
373 LOG(error)<<"CbmTofTestBeamClusterizer::RegisterInputs => Could not get the TofPoint TClonesArray!!!";
374 return kFALSE;
375 } // if( NULL == fTofPointsColl)
376
377 fMcTracksColl = (TClonesArray *) fManager->GetObject("MCTrack");
378 if( NULL == fMcTracksColl)
379 {
380 LOG(error)<<"CbmTofTestBeamClusterizer::RegisterInputs => Could not get the MCTrack TClonesArray!!!";
381 return kFALSE;
382 } // if( NULL == fMcTracksColl)
383 */
384
385 fTofDigisColl = (TClonesArray*) fManager->GetObject("CbmTofDigi");
386
387 if (NULL == fTofDigisColl) fTofDigisColl = (TClonesArray*) fManager->GetObject("CbmTofDigi");
388
389 if (NULL == fTofDigisColl) fTofDigisColl = (TClonesArray*) fManager->GetObject("TofDigiExp");
390
391 if (NULL == fTofDigisColl) fTofDigisColl = (TClonesArray*) fManager->GetObject("TofDigi");
392
393 if (NULL == fTofDigisColl) {
394 LOG(error) << "CbmTofTestBeamClusterizer::RegisterInputs => Could not get "
395 "the CbmTofDigi TClonesArray!!!";
396 return kFALSE;
397 } // if( NULL == fTofDigisColl)
398
399
400 fTrbHeader = (TTrbHeader*) fManager->GetObject("TofTrbHeader.");
401 if (NULL == fTrbHeader) {
402 LOG(info) << "CbmTofTestBeamClusterizer::RegisterInputs => Could not get "
403 "the TofTrbHeader Object";
404 }
405
406 return kTRUE;
407}
409{
410 FairRootManager* rootMgr = FairRootManager::Instance();
411
412 fTofCalDigisColl = new TClonesArray("CbmTofDigi");
413
414 // Flag check to control whether digis are written in output root file
415 rootMgr->Register("TofCalDigi", "Tof", fTofCalDigisColl, fbWriteDigisInOut && IsOutputBranchPersistent("TofCalDigi"));
416
417
418 fTofHitsColl = new TClonesArray("CbmTofHit");
419
420 TString tHitBranchName;
421 TString tHitDigiMatchBranchName;
422
424 tHitBranchName = "ATofHit";
425 tHitDigiMatchBranchName = "ATofDigiMatch";
426 }
427 else {
428 tHitBranchName = "TofHit";
429 tHitDigiMatchBranchName = "TofDigiMatch";
430 }
431
432 // Flag check to control whether digis are written in output root file
433 rootMgr->Register(tHitBranchName, "Tof", fTofHitsColl, fbWriteHitsInOut && IsOutputBranchPersistent(tHitBranchName));
434
435 fTofDigiMatchColl = new TClonesArray("CbmMatch", 100);
436 rootMgr->Register(tHitDigiMatchBranchName, "Tof", fTofDigiMatchColl,
437 fbWriteHitsInOut && IsOutputBranchPersistent(tHitDigiMatchBranchName));
438
439 return kTRUE;
440}
442{
443
444 // Initialize the TOF GeoHandler
445 Bool_t isSimulation = kFALSE;
446 LOG(info) << "CbmTofTestBeamClusterizer::InitParameters - Geometry, Mapping, ... ??";
447
448 // Get Base Container
449 FairRun* ana = FairRun::Instance();
450 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
451
452 Int_t iGeoVersion = fGeoHandler->Init(isSimulation);
453 if (k14a > iGeoVersion) {
454 LOG(error) << "CbmTofTestBeamClusterizer::InitParameters => Only "
455 "compatible with geometries after v14a !!!";
456 return kFALSE;
457 }
459
460 fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
461 if (0 == fDigiPar) {
462 LOG(error) << "CbmTofTestBeamClusterizer::InitParameters => Could not "
463 "obtain the CbmTofDigiPar ";
464 return kFALSE;
465 }
466
467 fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
468 if (0 == fDigiBdfPar) {
469 LOG(error) << "CbmTofTestBeamClusterizer::InitParameters => Could not "
470 "obtain the CbmTofDigiBdfPar ";
471 return kFALSE;
472 }
473
474 rtdb->initContainers(ana->GetRunId());
475
476 LOG(info) << "CbmTofTestBeamClusterizer::InitParameter: currently " << fDigiPar->GetNrOfModules() << " digi cells ";
477
478
481
483 fdMaxTimeDist = fMaxTimeDist; // modify default
485 * 0.5; // cut consistently on positions (with default signal velocity)
486 }
487
488 LOG(info) << " BuildCluster with MaxTimeDist " << fdMaxTimeDist << ", MaxSpaceDist " << fdMaxSpaceDist;
489
490 if (fiCluMulMax == 0) fiCluMulMax = 100;
491 if (fOutHstFileName == "") {
492 fOutHstFileName = "./tofTestBeamClust.hst.root";
493 }
494
495 LOG(info) << " Hst Output filename = " << fOutHstFileName;
496 /*
497 if(fiBeamRefAddr == 0) { // initialize defaults of sep14
498 fiBeamRefType = 5;
499 fiBeamRefSm = 1;
500 fiBeamRefDet = 0;
501 fiBeamAddRefMul= 0;
502 }
503 if(fSelId == 0) { // initialize defaults of sep14
504 fSelId=4;
505 }
506 */
507
508 LOG(info) << "<I> BeamRefType = " << fiBeamRefType << ", Sm " << fiBeamRefSm << ", Det " << fiBeamRefDet
509 << ", MulMax " << fiBeamRefMulMax;
510
511 return kTRUE;
512}
513/************************************************************************************/
515{
516 // dimension and initialize calib parameter
517 //Int_t iNbDet = fDigiBdfPar->GetNbDet(); (VF) not used
518 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
519
520 if (fTotMean != 0.) fdTTotMean = fTotMean; // adjust target mean for TTT
521
522 fvCPTOff.resize(iNbSmTypes);
523 fvCPTotGain.resize(iNbSmTypes);
524 fvCPTotOff.resize(iNbSmTypes);
525 fvCPWalk.resize(iNbSmTypes);
526 fvCPDelTof.resize(iNbSmTypes);
527 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
528 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
529 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
530 fvCPTOff[iSmType].resize(iNbSm * iNbRpc);
531 fvCPTotGain[iSmType].resize(iNbSm * iNbRpc);
532 fvCPTotOff[iSmType].resize(iNbSm * iNbRpc);
533 fvCPWalk[iSmType].resize(iNbSm * iNbRpc);
534 fvCPDelTof[iSmType].resize(iNbSm * iNbRpc);
535 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
536 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
537 // LOG(info)<<Form(" fvCPDelTof resize for SmT %d, R %d, B %d ",iSmType,iNbSm*iNbRpc,nbClDelTofBinX)
538 // ;
539 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc].resize(nbClDelTofBinX);
540 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
541 // LOG(info)<<Form(" fvCPDelTof for SmT %d, R %d, B %d",iSmType,iSm*iNbRpc+iRpc,iBx);
542 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx].resize(iNSel);
543 for (Int_t iSel = 0; iSel < iNSel; iSel++)
544 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] = 0.; // initialize
545 }
546
547 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc);
548 fvCPTOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
549 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
550 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
551 fvCPWalk[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
552 Int_t nbSide = 2 - fDigiBdfPar->GetChanType(iSmType, iRpc);
553 for (Int_t iCh = 0; iCh < iNbChan; iCh++) {
554 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
555 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
556 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
557 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
558 for (Int_t iSide = 0; iSide < nbSide; iSide++) {
559 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.; //initialize
560 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 1.; //initialize
561 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.; //initialize
562 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide].resize(nbClWalkBinX);
563 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
564 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide][iWx] = 0.;
565 }
566 }
567 }
568 }
569 }
570 }
571
572 LOG(info) << "CbmTofTestBeamClusterizer::InitCalibParameter: defaults set";
573
575 // <= To prevent histos from being sucked in by the param file of the TRootManager!
576 TFile* oldFile = gFile;
577 TDirectory* oldDir = gDirectory;
578
579 if (0 < fCalMode) {
580 LOG(info) << "CbmTofTestBeamClusterizer::InitCalibParameter: read histos from "
581 << "file " << fCalParFileName;
582
583 // read parameter from histos
584 if (fCalParFileName.IsNull()) return kTRUE;
585
586 fCalParFile = new TFile(fCalParFileName, "");
587 if (NULL == fCalParFile) {
588 LOG(fatal) << "CbmTofTestBeamClusterizer::InitCalibParameter: "
589 << "file " << fCalParFileName << " does not exist!";
590 return kTRUE;
591 }
592 /*
593 gDirectory->Print();
594 fCalParFile->cd();
595 fCalParFile->ls();
596 */
597 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
598 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
599 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
600 TProfile* hSvel = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Svel", iSmType));
601
602 // copy Histo to memory
603 TDirectory* curdir = gDirectory;
604 if (NULL != hSvel) {
605 gDirectory->cd(oldDir->GetPath());
606 // TProfile *hSvelmem = (TProfile *)hSvel->Clone(); (VF) not used
607 gDirectory->cd(curdir->GetPath());
608 }
609 else {
610 LOG(info) << "Svel histogram not found for module type " << iSmType;
611 }
612
613 for (Int_t iPar = 0; iPar < 4; iPar++) {
614 TProfile* hFparcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Fpar%1d", iSmType, iPar));
615 if (NULL != hFparcur) {
616 gDirectory->cd(oldDir->GetPath());
617 // TProfile *hFparmem = (TProfile *)hFparcur->Clone(); (VF) not used
618 gDirectory->cd(curdir->GetPath());
619 }
620 }
621
622 for (Int_t iSm = 0; iSm < iNbSm; iSm++)
623 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
624 // update default parameter
625 if (NULL != hSvel) {
626 Double_t Vscal = 1.; //hSvel->GetBinContent(iSm*iNbRpc+iRpc+1);
627 if (Vscal == 0.) Vscal = 1.;
628 fDigiBdfPar->SetSigVel(iSmType, iSm, iRpc, fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * Vscal);
629 LOG(info) << "Modify " << iSmType << iSm << iRpc << " Svel by " << Vscal << " to "
630 << fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
631 }
632 TH2F* htempPos_pfx =
633 (TH2F*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx", iSmType, iSm, iRpc));
634 TH2F* htempTOff_pfx =
635 (TH2F*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx", iSmType, iSm, iRpc));
636 TH1D* htempTot_Mean =
637 (TH1D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Mean", iSmType, iSm, iRpc));
638 TH1D* htempTot_Off =
639 (TH1D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Off", iSmType, iSm, iRpc));
640 if (NULL != htempPos_pfx && NULL != htempTOff_pfx && NULL != htempTot_Mean && NULL != htempTot_Off) {
641 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
642 Int_t iNbinTot = htempTot_Mean->GetNbinsX();
643 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
644 Double_t YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1); //nh +1 empirical(?)
645 Double_t TMean = ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1);
646 //Double_t dTYOff=YMean/fDigiBdfPar->GetSignalSpeed() ;
647 Double_t dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
648 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
649 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
650
651 for (Int_t iSide = 0; iSide < 2; iSide++) {
652 Double_t TotMean = htempTot_Mean->GetBinContent(iCh * 2 + 1 + iSide); //nh +1 empirical(?)
653 if (0.001 < TotMean) {
654 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] *= fdTTotMean / TotMean;
655 }
656 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = htempTot_Off->GetBinContent(iCh * 2 + 1 + iSide);
657 }
658
659 if (5 == iSmType || 8 == iSmType) {
660 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
661 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0];
662 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
663 }
664
665 LOG(debug) << "CbmTofTestBeamClusterizer::InitCalibParameter:"
666 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh
667 << Form(": YMean %f, TMean %f", YMean, TMean) << " -> "
668 << Form(" %f, %f, %f, %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
669 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
670 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
671 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1])
672 << ", NbinTot " << iNbinTot;
673
674 TH1D* htempWalk0 = (TH1D*) gDirectory->FindObjectAny(
675 Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
676 TH1D* htempWalk1 = (TH1D*) gDirectory->FindObjectAny(
677 Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
678 if (NULL != htempWalk0 && NULL != htempWalk1) { // reinitialize Walk array
679 LOG(debug) << "Initialize Walk correction for "
680 << Form(" SmT%01d_sm%03d_rpc%03d_Ch%03d", iSmType, iSm, iRpc, iCh);
681 if (htempWalk0->GetNbinsX() != nbClWalkBinX)
682 LOG(error) << "CbmTofTestBeamClusterizer::InitCalibParameter:"
683 " Inconsistent Walk histograms";
684 for (Int_t iBin = 0; iBin < nbClWalkBinX; iBin++) {
685 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin] = htempWalk0->GetBinContent(iBin + 1);
686 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin] = htempWalk1->GetBinContent(iBin + 1);
687 LOG(debug1) << Form(" SmT%01d_sm%03d_rpc%03d_Ch%03d bin %d walk %f ", iSmType, iSm, iRpc, iCh, iBin,
688 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin]);
689 if (5 == iSmType || 8 == iSmType) { // Pad structure
690 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin] =
691 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin];
692 }
693 }
694 }
695 }
696 }
697 else {
698 LOG(warning) << " Calibration histos " << Form("cl_SmT%01d_sm%03d_rpc%03d_XXX", iSmType, iSm, iRpc)
699 << " not found. ";
700 }
701 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
702 TH1D* htmpDelTof = (TH1D*) gDirectory->FindObjectAny(
703 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
704 if (NULL == htmpDelTof) {
705 LOG(debug) << " Histos " << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel)
706 << " not found. ";
707 continue;
708 }
709 LOG(debug) << " Load DelTof from histos "
710 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel) << ".";
711 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
712 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] += htmpDelTof->GetBinContent(iBx + 1);
713 }
714
715 // copy Histo to memory
716 // TDirectory * curdir = gDirectory;
717 gDirectory->cd(oldDir->GetPath());
718 TH1D* h1DelTof =
719 (TH1D*) htmpDelTof->Clone(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
720
721 LOG(debug) << " copy histo " << h1DelTof->GetName() << " to directory " << oldDir->GetName();
722
723 gDirectory->cd(curdir->GetPath());
724 }
725 }
726 }
727 }
728 // fCalParFile->Delete();
730 // <= To prevent histos from being sucked in by the param file of the TRootManager!
731 gFile = oldFile;
732 gDirectory = oldDir;
733 LOG(info) << "CbmTofTestBeamClusterizer::InitCalibParameter: initialization done";
734 return kTRUE;
735}
736/************************************************************************************/
738{
739 LOG(info) << "CbmTofTestBeamClusterizer::LoadGeometry starting for " << fDigiBdfPar->GetNbDet()
740 << " described detectors, " << fDigiPar->GetNrOfModules() << " geometrically known modules ";
741
742 //fTRefMode=0x00002016; // use plastic 1 as time reference
743
744 Int_t iNrOfCells = fDigiPar->GetNrOfModules();
745 LOG(info) << "Digi Parameter container contains " << iNrOfCells << " cells.";
746 for (Int_t icell = 0; icell < iNrOfCells; ++icell) {
747
748 Int_t cellId = fDigiPar->GetCellId(icell); // cellId is assigned in CbmTofCreateDigiPar
749 fChannelInfo = fDigiPar->GetCell(cellId);
750
751 Int_t smtype = fGeoHandler->GetSMType(cellId);
752 Int_t smodule = fGeoHandler->GetSModule(cellId);
753 Int_t module = fGeoHandler->GetCounter(cellId);
754 Int_t cell = fGeoHandler->GetCell(cellId);
755
756 Double_t x = fChannelInfo->GetX();
757 Double_t y = fChannelInfo->GetY();
758 Double_t z = fChannelInfo->GetZ();
759 Double_t dx = fChannelInfo->GetSizex();
760 Double_t dy = fChannelInfo->GetSizey();
761 LOG(debug) << "-I- InitPar " << icell << " Id: " << Form("0x%08x", cellId) << " " << cell << " tmcs: " << smtype
762 << " " << smodule << " " << module << " " << cell << " x=" << Form("%6.2f", x)
763 << " y=" << Form("%6.2f", y) << " z=" << Form("%6.2f", z) << " dx=" << dx << " dy=" << dy;
764
765 TGeoNode* fNode = // prepare local->global trafo
766 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
767 LOG(debug2) << Form(" Node at (%6.1f,%6.1f,%6.1f) : 0x%p", fChannelInfo->GetX(), fChannelInfo->GetY(),
768 fChannelInfo->GetZ(), fNode);
769 // fNode->Print();
770 }
771
772 Int_t iNbDet = fDigiBdfPar->GetNbDet();
773 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
774 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
775 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
776 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
777 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
778 LOG(info) << " DetIndx " << iDetIndx << "(" << iNbDet << "), SmType " << iSmType << ", SmId " << iSmId << ", RpcId "
779 << iRpcId << " => UniqueId " << Form("0x%08x ", iUniqueId)
780 << Form(" Svel %6.6f ", fDigiBdfPar->GetSigVel(iSmType, iSmId, iRpcId));
781 Int_t iCell = -1;
782 while (kTRUE) {
783 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, ++iCell, 0, iSmType);
784 fChannelInfo = fDigiPar->GetCell(iUCellId);
785 if (NULL == fChannelInfo) break;
786 LOG(debug3) << " Cell " << iCell << Form(" 0x%08x ", iUCellId) << Form(", fCh 0x%p ", fChannelInfo)
787 << ", x: " << fChannelInfo->GetX() << ", y: " << fChannelInfo->GetY()
788 << ", z: " << fChannelInfo->GetZ();
789 }
790 }
791
792 // return kTRUE;
793
794 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
795
796 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
797 fStorDigiExp.resize(iNbSmTypes);
798 fStorDigiInd.resize(iNbSmTypes);
799 fviClusterSize.resize(iNbSmTypes);
800 fviTrkMul.resize(iNbSmTypes);
801 fvdX.resize(iNbSmTypes);
802 fvdY.resize(iNbSmTypes);
803 fvdDifX.resize(iNbSmTypes);
804 fvdDifY.resize(iNbSmTypes);
805 fvdDifCh.resize(iNbSmTypes);
806 fviClusterMul.resize(iNbSmTypes);
807 fvLastHits.resize(iNbSmTypes);
808
809 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
810 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
811 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
812 fStorDigiExp[iSmType].resize(iNbSm * iNbRpc);
813 fStorDigiInd[iSmType].resize(iNbSm * iNbRpc);
814 fviClusterSize[iSmType].resize(iNbRpc);
815 fviTrkMul[iSmType].resize(iNbRpc);
816 fvdX[iSmType].resize(iNbRpc);
817 fvdY[iSmType].resize(iNbRpc);
818 fvdDifX[iSmType].resize(iNbRpc);
819 fvdDifY[iSmType].resize(iNbRpc);
820 fvdDifCh[iSmType].resize(iNbRpc);
821 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
822 fviClusterMul[iSmType].resize(iNbSm);
823 fvLastHits[iSmType].resize(iNbSm);
824 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
825 fviClusterMul[iSmType][iSm].resize(iNbRpc);
826 fvLastHits[iSmType][iSm].resize(iNbRpc);
827 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc);
828 if (iNbChan == 0) {
829 LOG(warning) << "CbmTofTestBeamClusterizer::LoadGeometry: "
830 "StoreDigi without channels "
831 << Form("SmTy %3d, Sm %3d, NbRpc %3d, Rpc, %3d ", iSmType, iSm, iNbRpc, iRpc);
832 }
833 LOG(debug1) << "CbmTofTestBeamClusterizer::LoadGeometry: StoreDigi with "
834 << Form(" %3d %3d %3d %3d %5d ", iSmType, iSm, iNbRpc, iRpc, iNbChan);
835 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
836 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
837 fvLastHits[iSmType][iSm][iRpc].resize(iNbChan);
838 } // for( Int_t iRpc = 0; iRpc < iNbRpc; iRpc++ )
839 } // for( Int_t iSm = 0; iSm < iNbSm; iSm++ )
840 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
841 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
842 return kTRUE;
843}
845{
846 LOG(info) << "CbmTofTestBeamClusterizer::DeleteGeometry starting";
847 return kTRUE;
848 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
849 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
850 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
851 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
852 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
853 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
854 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
855 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc].clear();
856 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc].clear();
857 }
858 } // for( Int_t iSm = 0; iSm < iNbSm; iSm++ )
859 fStorDigiExp[iSmType].clear();
860 fStorDigiInd[iSmType].clear();
861 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
862 fStorDigiExp.clear();
863 fStorDigiInd.clear();
864 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
865 return kTRUE;
866}
867/************************************************************************************/
868// Histogramming functions
870{
871 TDirectory* oldir = gDirectory; // <= To prevent histos from being sucked in by the param file of the TRootManager!
872 gROOT->cd(); // <= To prevent histos from being sucked in by the param file of the TRootManager !
874 new TH1I("TofTestBeamClus_ClustBuildTime", "Time needed to build clusters in each event; Time [s]", 4000, 0.0, 4.0);
875
876 /* TH2* hTemp = 0;*/
877
878 // Sm related distributions
886
887 for (Int_t iS = 0; iS < fDigiBdfPar->GetNbSmTypes(); iS++) {
888 Double_t YSCAL = 50.;
889 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
890
891 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(0, 0, 0, 0, iS);
892 fChannelInfo = fDigiPar->GetCell(iUCellId);
893
894 // Cover the case that the geometry file does not contain the module
895 // indexed with 0 of a certain module type BUT modules with higher indices.
896 for (Int_t iSM = 0; iSM < fDigiBdfPar->GetNbSm(iS); iSM++) {
897 iUCellId = CbmTofAddress::GetUniqueAddress(iSM, 0, 0, 0, iS);
898 fChannelInfo = fDigiPar->GetCell(iUCellId);
899
900 // Retrieve geometry information from the first module of a certain
901 // module type that is found in the geometry file.
902 if (NULL != fChannelInfo) {
903 LOG(info) << Form("Channel info for module type %d obtained from counter: %d-%d-%d", iS, iS, iSM, 0);
904 break;
905 }
906 }
907
908 if (NULL == fChannelInfo) {
909 LOG(warning) << "No DigiPar for SmType " << Form("%d, 0x%08x", iS, iUCellId);
910 continue;
911 }
912 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
913
914 fhSmCluPosition[iS] =
915 new TH2F(Form("cl_SmT%01d_Pos", iS), Form("Clu position of SmType %d; Sm+Rpc# []; ypos [cm]", iS),
917 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -YDMAX, YDMAX);
918
919 Double_t TSumMax = 1.E3;
920 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
921 fhSmCluTOff[iS] =
922 new TH2F(Form("cl_SmT%01d_TOff", iS), Form("Clu TimeZero in SmType %d; Sm+Rpc# []; TOff [ns]", iS),
924 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -TSumMax, TSumMax);
925
926 TProfile* hSvelcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Svel", iS));
927 if (NULL == hSvelcur) {
928 fhSmCluSvel[iS] =
929 new TProfile(Form("cl_SmT%01d_Svel", iS), Form("Clu Svel in SmType %d; Sm+Rpc# []; v/v_{nominal} ", iS),
931 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0.8, 1.2);
932 fhSmCluSvel[iS]->Sumw2();
933 }
934 else
935 fhSmCluSvel[iS] = (TProfile*) hSvelcur->Clone();
936
937 fhSmCluFpar[iS].resize(4);
938 for (Int_t iPar = 0; iPar < 4; iPar++) {
939 TProfile* hFparcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Fpar%1d", iS, iPar));
940 if (NULL == hFparcur) {
941 LOG(info) << "Histo " << Form("cl_SmT%01d_Fpar%1d", iS, iPar) << " not found, recreate ...";
942 fhSmCluFpar[iS][iPar] = new TProfile(Form("cl_SmT%01d_Fpar%1d", iS, iPar),
943 Form("Clu Fpar %d in SmType %d; Sm+Rpc# []; value ", iPar, iS),
945 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), -100., 100.);
946 }
947 else
948 fhSmCluFpar[iS][iPar] = (TProfile*) hFparcur->Clone();
949 }
950
951 fhTSmCluPosition[iS].resize(iNSel);
952 fhTSmCluTOff[iS].resize(iNSel);
953 fhTSmCluTRun[iS].resize(iNSel);
954 for (Int_t iSel = 0; iSel < iNSel; iSel++) { // Loop over selectors
955 fhTSmCluPosition[iS][iSel] = new TH2F(Form("cl_TSmT%01d_Sel%02d_Pos", iS, iSel),
956 Form("Clu position of SmType %d under Selector %02d; Sm+Rpc# "
957 "[]; ypos [cm]",
958 iS, iSel),
960 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -YDMAX, YDMAX);
961 fhTSmCluTOff[iS][iSel] = new TH2F(Form("cl_TSmT%01d_Sel%02d_TOff", iS, iSel),
962 Form("Clu TimeZero in SmType %d under Selector %02d; Sm+Rpc# "
963 "[]; TOff [ns]",
964 iS, iSel),
966 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -TSumMax, TSumMax);
967 fhTSmCluTRun[iS][iSel] = new TH2F(Form("cl_TSmT%01d_Sel%02d_TRun", iS, iSel),
968 Form("Clu TimeZero in SmType %d under Selector %02d; Event# "
969 "[]; TMean [ns]",
970 iS, iSel),
971 100, 0, MaxNbEvent, 99, -TSumMax, TSumMax);
972 }
973 }
974
975 // RPC related distributions
976 Int_t iNbDet = fDigiBdfPar->GetNbDet();
977 LOG(info) << " Define Clusterizer histos for " << iNbDet << " detectors ";
978
979 fhRpcDigiCor.resize(iNbDet);
980 fhRpcCluMul.resize(iNbDet);
981 fhRpcCluRate.resize(iNbDet);
982 fhRpcCluPosition.resize(iNbDet);
983 fhRpcCluDelPos.resize(iNbDet);
984 fhRpcCluDelMatPos.resize(iNbDet);
985 fhRpcCluTOff.resize(iNbDet);
986 fhRpcCluDelTOff.resize(iNbDet);
987 fhRpcCluDelMatTOff.resize(iNbDet);
988 fhRpcCluTrms.resize(iNbDet);
989 fhRpcCluTot.resize(iNbDet);
990 fhRpcCluSize.resize(iNbDet);
991 fhRpcCluAvWalk.resize(iNbDet);
992 fhRpcCluAvLnWalk.resize(iNbDet);
993 fhRpcCluWalk.resize(iNbDet);
994 fhRpcDTLastHits.resize(iNbDet);
995 fhRpcDTLastHits_Tot.resize(iNbDet);
996 fhRpcDTLastHits_CluSize.resize(iNbDet);
997 fviDetId.resize(iNbDet);
998
999 fDetIdIndexMap.clear();
1000
1001 if (fTotMax != 0.) fdTOTMax = fTotMax;
1002 if (fTotMin != 0.) fdTOTMin = fTotMin;
1003
1004 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1005 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1006 fDetIdIndexMap[iUniqueId] = iDetIndx;
1007 fviDetId[iDetIndx] = iUniqueId;
1008
1009 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1010 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1011 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1012 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, 0, 0, iSmType);
1013 fChannelInfo = fDigiPar->GetCell(iUCellId);
1014 if (NULL == fChannelInfo) {
1015 LOG(warning) << "No DigiPar for Det " << Form("0x%08x", iUCellId);
1016 continue;
1017 }
1018 LOG(info) << "DetIndx " << iDetIndx << ", SmType " << iSmType << ", SmId " << iSmId << ", RpcId " << iRpcId
1019 << " => UniqueId " << Form("(0x%08x, 0x%08x)", iUniqueId, iUCellId) << ", dx " << fChannelInfo->GetSizex()
1020 << ", dy " << fChannelInfo->GetSizey() << Form(" ChPoi: %p ", fChannelInfo) << ", nbCh "
1021 << fDigiBdfPar->GetNbChan(iSmType, 0);
1022
1023 // check access to all channel infos
1024 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1025 Int_t iCCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, iCh, 0, iSmType);
1026 fChannelInfo = fDigiPar->GetCell(iCCellId);
1027 if (NULL == fChannelInfo) LOG(warning) << Form("missing ChannelInfo for ch %d addr 0x%08x", iCh, iCCellId);
1028 }
1029
1030 fChannelInfo = fDigiPar->GetCell(iUCellId);
1031 fhRpcDigiCor[iDetIndx] =
1032 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiCor", iSmType, iSmId, iRpcId),
1033 Form("Digi Correlation of Rpc #%03d in Sm %03d of type %d; digi 0; digi 1", iRpcId, iSmId, iSmType),
1034 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId),
1035 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1036
1037 fhRpcCluMul[iDetIndx] =
1038 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_Mul", iSmType, iSmId, iRpcId),
1039 Form("Clu multiplicity of Rpc #%03d in Sm %03d of type %d; M []; Cnts", iRpcId, iSmId, iSmType),
1040 2. + 2. * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, 2. + 2. * fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1041
1042 fhRpcCluRate[iDetIndx] =
1043 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_rate", iSmType, iSmId, iRpcId),
1044 Form("Clu rate of Rpc #%03d in Sm %03d of type %d; Time (s); Rate (Hz)", iRpcId, iSmId, iSmType), 3600.,
1045 0., 3600.);
1046
1047 fhRpcDTLastHits[iDetIndx] = new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_DTLastHits", iSmType, iSmId, iRpcId),
1048 Form("Clu #DeltaT to last hits of Rpc #%03d in Sm %03d of type %d; log( "
1049 "#DeltaT (ns)); counts",
1050 iRpcId, iSmId, iSmType),
1051 100., 0., 10.);
1052
1053 fhRpcDTLastHits_Tot[iDetIndx] = new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot_DTLH", iSmType, iSmId, iRpcId),
1054 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d; log(#DeltaT (ns)); TOT "
1055 "[ns]",
1056 iRpcId, iSmId, iSmType),
1057 100, 0., 10., 100, fdTOTMin, 4. * fdTOTMax);
1058
1059 fhRpcDTLastHits_CluSize[iDetIndx] = new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_CluSize_DTLH", iSmType, iSmId, iRpcId),
1060 Form("Clu Size of Rpc #%03d in Sm %03d of type %d; log(#DeltaT (ns)); "
1061 "CluSize []",
1062 iRpcId, iSmId, iSmType),
1063 100, 0., 10., 16, 0.5, 16.5);
1064
1065 Double_t YSCAL = 50.;
1066 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1067 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1068 fhRpcCluPosition[iDetIndx] =
1069 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Pos", iSmType, iSmId, iRpcId),
1070 Form("Clu position of Rpc #%03d in Sm %03d of type %d; Strip []; ypos [cm]", iRpcId, iSmId, iSmType),
1071 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -YDMAX, YDMAX);
1072
1073 fhRpcCluDelPos[iDetIndx] =
1074 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelPos", iSmType, iSmId, iRpcId),
1075 Form("Clu position difference of Rpc #%03d in Sm %03d of type "
1076 "%d; Strip []; #Deltaypos(clu) [cm]",
1077 iRpcId, iSmId, iSmType),
1078 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -10., 10.);
1079
1080 fhRpcCluDelMatPos[iDetIndx] =
1081 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelMatPos", iSmType, iSmId, iRpcId),
1082 Form("Matched Clu position difference of Rpc #%03d in Sm %03d of type "
1083 "%d; Strip []; #Deltaypos(mat) [cm]",
1084 iRpcId, iSmId, iSmType),
1085 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -5., 5.);
1086
1087 Double_t TSumMax = 1.E3;
1088 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1089 fhRpcCluTOff[iDetIndx] = new TH2F(
1090 Form("cl_SmT%01d_sm%03d_rpc%03d_TOff", iSmType, iSmId, iRpcId),
1091 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d; Strip []; TOff [ns]", iRpcId, iSmId, iSmType),
1092 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -TSumMax, TSumMax);
1093
1094 fhRpcCluDelTOff[iDetIndx] =
1095 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelTOff", iSmType, iSmId, iRpcId),
1096 Form("Clu TimeZero Difference of Rpc #%03d in Sm %03d of type %d; Strip "
1097 "[]; #DeltaTOff(clu) [ns]",
1098 iRpcId, iSmId, iSmType),
1099 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -0.6, 0.6);
1100
1101 fhRpcCluDelMatTOff[iDetIndx] =
1102 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelMatTOff", iSmType, iSmId, iRpcId),
1103 Form("Clu TimeZero Difference of Rpc #%03d in Sm %03d of type %d; Strip "
1104 "[]; #DeltaTOff(mat) [ns]",
1105 iRpcId, iSmId, iSmType),
1106 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -0.6, 0.6);
1107
1108 fhRpcCluTrms[iDetIndx] =
1109 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Trms", iSmType, iSmId, iRpcId),
1110 Form("Clu Time RMS of Rpc #%03d in Sm %03d of type %d; Strip []; Trms [ns]", iRpcId, iSmId, iSmType),
1111 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, 0., 0.5);
1112
1113 fhRpcCluTot[iDetIndx] =
1114 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot", iSmType, iSmId, iRpcId),
1115 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d; StripSide []; TOT [ns]", iRpcId, iSmId, iSmType),
1116 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 100,
1118
1119 fhRpcCluSize[iDetIndx] =
1120 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Size", iSmType, iSmId, iRpcId),
1121 Form("Clu size of Rpc #%03d in Sm %03d of type %d; Strip []; size [strips]", iRpcId, iSmId, iSmType),
1122 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 16, 0.5, 16.5);
1123
1124 // Walk histos
1125 fhRpcCluAvWalk[iDetIndx] = new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_AvWalk", iSmType, iSmId, iRpcId),
1126 Form("Walk in SmT%01d_sm%03d_rpc%03d_AvWalk", iSmType, iSmId, iRpcId),
1127 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1128
1129 fhRpcCluAvLnWalk[iDetIndx] =
1130 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_AvLnWalk", iSmType, iSmId, iRpcId),
1131 Form("Walk in SmT%01d_sm%03d_rpc%03d_AvLnWalk", iSmType, iSmId, iRpcId), nbClWalkBinX,
1132 TMath::Log10(fdTOTMax / 50.), TMath::Log10(fdTOTMax), nbClWalkBinY, -TSumMax, TSumMax);
1133
1134 fhRpcCluWalk[iDetIndx].resize(fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1135 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1136 fhRpcCluWalk[iDetIndx][iCh].resize(2);
1137 for (Int_t iSide = 0; iSide < 2; iSide++) {
1138 fhRpcCluWalk[iDetIndx][iCh][iSide] =
1139 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk", iSmType, iSmId, iRpcId, iCh, iSide),
1140 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk", iSmType, iSmId, iRpcId, iCh, iSide),
1141 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1142 }
1143 /*
1144 (fhRpcCluWalk[iDetIndx]).push_back( hTemp );
1145 */
1146 }
1147 }
1148
1149 // Clusterizing monitoring
1150
1151 LOG(info) << " Define Clusterizer monitoring histos ";
1152
1153 fhCluMulCorDutSel = new TH2F(Form("hCluMulCorDutSel"),
1154 Form("Cluster Multiplicity Correlation of Dut %d%d%d with Sel "
1155 "%d%d%d; Mul(Sel); Mul(Dut)",
1157 32, 0, 32, 32, 0, 32);
1158
1159 fhDigSpacDifClust = new TH1I("Clus_DigSpacDifClust",
1160 "Space difference along channel direction between Digi pairs on "
1161 "adjacent channels; PosCh i - Pos Ch i+1 [cm]",
1162 5000, -10.0, 10.0);
1163 fhDigTimeDifClust = new TH1I("Clus_DigTimeDifClust",
1164 "Time difference between Digi pairs on adjacent channels; "
1165 "0.5*(tDigiA + tDigiA)chi - 0.5*(tDigiA + tDigiA)chi+1 [ns]",
1166 5000, -5.0, 5.0);
1167 fhDigDistClust = new TH2I("Clus_DigDistClust",
1168 "Distance between Digi pairs on adjacent channels; PosCh i - Pos Ch i+1 "
1169 "[cm along ch]; 0.5*(tDigiA + tDigiA)chi - 0.5*(tDigiA + tDigiA)chi+1 [ns]",
1170 5000, -10.0, 10.0, 2000, -5.0, 5.0);
1171 fhClustSizeDifX = new TH2I("Clus_ClustSizeDifX",
1172 "Position difference between Point and Hit as function of Cluster "
1173 "Size; Cluster Size [Strips]; dX [cm]",
1174 100, 0.5, 100.5, 500, -50, 50);
1175 fhClustSizeDifY = new TH2I("Clus_ClustSizeDifY",
1176 "Position difference between Point and Hit as function of Cluster "
1177 "Size; Cluster Size [Strips]; dY [cm]",
1178 100, 0.5, 100.5, 500, -50, 50);
1179 fhChDifDifX = new TH2I("Clus_ChDifDifX",
1180 "Position difference between Point and Hit as "
1181 "function of Channel dif; Ch Dif [Strips]; dX [cm]",
1182 101, -50.5, 50.5, 500, -50, 50);
1183 fhChDifDifY = new TH2I("Clus_ChDifDifY",
1184 "Position difference between Point and Hit as "
1185 "function of Channel Dif; Ch Dif [Strips]; dY [cm]",
1186 101, -50.5, 50.5, 500, -50, 50);
1187 fhNbSameSide = new TH1I("Clus_NbSameSide",
1188 "How many time per event the 2 digis on a channel "
1189 "were of the same side ; Counts/Event []",
1190 500, 0.0, 500.0);
1191 fhNbDigiPerChan = new TH1I("Clus_NbDigiPerChan", "Nb of Digis per channel; Nb Digis []", 100, 0.0, 100.0);
1192
1193 // Trigger selected histograms
1194 if (0 < iNSel) {
1195
1196 fhSeldT.resize(iNSel);
1197 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1198 fhSeldT[iSel] = new TH2F(Form("cl_dt_Sel%02d", iSel), Form("Selector time %02d; dT [ns]", iSel), 99,
1199 -fdDelTofMax * 10., fdDelTofMax * 10., 16, -0.5, 15.5);
1200 }
1201
1202 fhTRpcCluMul.resize(iNbDet);
1203 fhTRpcCluPosition.resize(iNbDet);
1204 fhTRpcCluTOff.resize(iNbDet);
1205 fhTRpcCluTot.resize(iNbDet);
1206 fhTRpcCluSize.resize(iNbDet);
1207 fhTRpcCluAvWalk.resize(iNbDet);
1208 fhTRpcCluDelTof.resize(iNbDet);
1209 fhTRpcCludXdY.resize(iNbDet);
1210 fhTRpcCluWalk.resize(iNbDet);
1211 fhTRpcCluTOffDTLastHits.resize(iNbDet);
1212 fhTRpcCluTotDTLastHits.resize(iNbDet);
1213 fhTRpcCluSizeDTLastHits.resize(iNbDet);
1214 fhTRpcCluMemMulDTLastHits.resize(iNbDet);
1215
1216 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1217 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1218 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1219 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1220 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1221 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, 0, 0, iSmType);
1222 fChannelInfo = fDigiPar->GetCell(iUCellId);
1223 if (NULL == fChannelInfo) {
1224 LOG(warning) << "No DigiPar for Det " << Form("0x%08x", iUCellId);
1225 continue;
1226 }
1227 LOG(debug1) << "DetIndx " << iDetIndx << ", SmType " << iSmType << ", SmId " << iSmId << ", RpcId " << iRpcId
1228 << " => UniqueId " << Form("(0x%08x, 0x%08x)", iUniqueId, iUCellId) << ", dx "
1229 << fChannelInfo->GetSizex() << ", dy " << fChannelInfo->GetSizey()
1230 << Form(" poi: 0x%p ", fChannelInfo) << ", nbCh " << fDigiBdfPar->GetNbChan(iSmType, iRpcId);
1231
1232 fhTRpcCluMul[iDetIndx].resize(iNSel);
1233 fhTRpcCluPosition[iDetIndx].resize(iNSel);
1234 fhTRpcCluTOff[iDetIndx].resize(iNSel);
1235 fhTRpcCluTot[iDetIndx].resize(iNSel);
1236 fhTRpcCluSize[iDetIndx].resize(iNSel);
1237 fhTRpcCluAvWalk[iDetIndx].resize(iNSel);
1238 fhTRpcCluDelTof[iDetIndx].resize(iNSel);
1239 fhTRpcCludXdY[iDetIndx].resize(iNSel);
1240 fhTRpcCluWalk[iDetIndx].resize(iNSel);
1241 fhTRpcCluTOffDTLastHits[iDetIndx].resize(iNSel);
1242 fhTRpcCluTotDTLastHits[iDetIndx].resize(iNSel);
1243 fhTRpcCluSizeDTLastHits[iDetIndx].resize(iNSel);
1244 fhTRpcCluMemMulDTLastHits[iDetIndx].resize(iNSel);
1245
1246 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1247 fhTRpcCluMul[iDetIndx][iSel] =
1248 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Mul", iSmType, iSmId, iRpcId, iSel),
1249 Form("Clu multiplicity of Rpc #%03d in Sm %03d of type %d "
1250 "under Selector %02d; M []; cnts",
1251 iRpcId, iSmId, iSmType, iSel),
1252 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0., fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1253
1254 if (NULL == fhTRpcCluMul[iDetIndx][iSel]) LOG(fatal) << " Histo not generated !";
1255
1256 Double_t YSCAL = 50.;
1257 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1258 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1259 fhTRpcCluPosition[iDetIndx][iSel] = new TH2F(
1260 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Pos", iSmType, iSmId, iRpcId, iSel),
1261 Form("Clu position of Rpc #%03d in Sm %03d of type %d under "
1262 "Selector %02d; Strip []; ypos [cm]",
1263 iRpcId, iSmId, iSmType, iSel),
1264 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 100, -YDMAX, YDMAX);
1265
1266 Double_t TSumMax = 1.E4;
1267 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1268 fhTRpcCluTOff[iDetIndx][iSel] = new TH2F(
1269 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_TOff", iSmType, iSmId, iRpcId, iSel),
1270 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d under "
1271 "Selector %02d; Strip []; TOff [ns]",
1272 iRpcId, iSmId, iSmType, iSel),
1273 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -TSumMax, TSumMax);
1274
1275 if (fTotMax != 0.) fdTOTMax = fTotMax;
1276 fhTRpcCluTot[iDetIndx][iSel] =
1277 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Tot", iSmType, iSmId, iRpcId, iSel),
1278 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d under "
1279 "Selector %02d; StripSide []; TOT [ns]",
1280 iRpcId, iSmId, iSmType, iSel),
1281 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 100,
1283
1284 fhTRpcCluSize[iDetIndx][iSel] =
1285 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Size", iSmType, iSmId, iRpcId, iSel),
1286 Form("Clu size of Rpc #%03d in Sm %03d of type %d under "
1287 "Selector %02d; Strip []; size [strips]",
1288 iRpcId, iSmId, iSmType, iSel),
1289 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 16, 0.5, 16.5);
1290
1291 // Walk histos
1292 fhTRpcCluAvWalk[iDetIndx][iSel] =
1293 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_AvWalk", iSmType, iSmId, iRpcId, iSel),
1294 Form("Walk in SmT%01d_sm%03d_rpc%03d_Sel%02d_AvWalk; TOT; T-TSel", iSmType, iSmId, iRpcId, iSel),
1295 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1296
1297 // Tof Histos
1298 fhTRpcCluDelTof[iDetIndx][iSel] =
1299 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSmId, iRpcId, iSel),
1300 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof; TRef-TSel; T-TSel", iSmType, iSmId, iRpcId, iSel),
1301 nbClDelTofBinX, -fdDelTofMax, fdDelTofMax, nbClDelTofBinY, -TSumMax, TSumMax);
1302
1303 // Position deviation histos
1304 fhTRpcCludXdY[iDetIndx][iSel] =
1305 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_dXdY", iSmType, iSmId, iRpcId, iSel),
1306 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_dXdY; #Delta x [cm]; "
1307 "#Delta y [cm];",
1308 iSmType, iSmId, iRpcId, iSel),
1310
1311 fhTRpcCluWalk[iDetIndx][iSel].resize(fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1312 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1313 fhTRpcCluWalk[iDetIndx][iSel][iCh].resize(2);
1314 for (Int_t iSide = 0; iSide < 2; iSide++) {
1315 fhTRpcCluWalk[iDetIndx][iSel][iCh][iSide] = new TH2D(
1316 Form("cl_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Sel%02d_Walk", iSmType, iSmId, iRpcId, iCh, iSide, iSel),
1317 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Sel%02d_Walk", iSmType, iSmId, iRpcId, iCh, iSide,
1318 iSel),
1319 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1320 }
1321 }
1322
1323 fhTRpcCluTOffDTLastHits[iDetIndx][iSel] =
1324 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_TOff_DTLH", iSmType, iSmId, iRpcId, iSel),
1325 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d under "
1326 "Selector %02d; log(#DeltaT (ns)); TOff [ns]",
1327 iRpcId, iSmId, iSmType, iSel),
1328 100, 0., 10., 99, -TSumMax, TSumMax);
1329
1330 fhTRpcCluTotDTLastHits[iDetIndx][iSel] =
1331 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Tot_DTLH", iSmType, iSmId, iRpcId, iSel),
1332 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d under "
1333 "Selector %02d; log(#DeltaT (ns)); TOT [ns]",
1334 iRpcId, iSmId, iSmType, iSel),
1335 100, 0., 10., 100, fdTOTMin, fdTOTMax);
1336
1337 fhTRpcCluSizeDTLastHits[iDetIndx][iSel] =
1338 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Size_DTLH", iSmType, iSmId, iRpcId, iSel),
1339 Form("Clu size of Rpc #%03d in Sm %03d of type %d under "
1340 "Selector %02d; log(#DeltaT (ns)); size [strips]",
1341 iRpcId, iSmId, iSmType, iSel),
1342 100, 0., 10., 10, 0.5, 10.5);
1343
1344 fhTRpcCluMemMulDTLastHits[iDetIndx][iSel] =
1345 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_MemMul_DTLH", iSmType, iSmId, iRpcId, iSel),
1346 Form("Clu Memorized Multiplicity of Rpc #%03d in Sm %03d of type %d "
1347 "under Selector %02d; log(#DeltaT (ns)); TOff [ns]",
1348 iRpcId, iSmId, iSmType, iSel),
1349 100, 0., 10., 10, 0, 10);
1350 }
1351 }
1352 }
1353 // MC reference
1355 new TH1I("Clus_TofHitPerTrk", "Mean Number of TofHit per Mc Track; Nb TofHits/Nb MC Tracks []", 2000, 0.0, 20.0);
1356 if (kFALSE == fDigiBdfPar->ClustUseTrackId())
1357 fhPtsPerHit = new TH1I("Clus_TofPtsPerHit",
1358 "Distribution of the Number of MCPoints associated "
1359 "to each TofHit; Nb MCPoint []",
1360 20, 0.0, 20.0);
1361 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
1362 fhTimeResSingHits = new TH1I("Clus_TofTimeResClust",
1363 "Time resolution for TofHits containing Digis from a single MC "
1364 "Track; t(1st Mc Point) -tTofHit [ns]",
1365 10000, -25.0, 25.0);
1366 fhTimeResSingHitsB = new TH2I("Clus_TofTimeResClustB",
1367 "Time resolution for TofHits containing Digis from a single MC "
1368 "Track; (1st Mc Point) -tTofHit [ns]",
1369 5000, -25.0, 25.0, 6, 0, 6);
1370 fhTimePtVsHits = new TH2I("Clus_TofTimePtVsHit",
1371 "Time resolution for TofHits containing Digis from a single MC "
1372 "Track; t(1st Mc Point) -tTofHit [ns]",
1373 2000, 0.0, 50.0, 2000, 0.0, 50.0);
1374 }
1375 else {
1376 fhTimeResSingHits = new TH1I("Clus_TofTimeResClust",
1377 "Time resolution for TofHits containing Digis from a single "
1378 "TofPoint; tMcPoint -tTofHit [ns]",
1379 10000, -25.0, 25.0);
1380 fhTimeResSingHitsB = new TH2I("Clus_TofTimeResClustB",
1381 "Time resolution for TofHits containing Digis from a single "
1382 "TofPoint; tMcPoint -tTofHit [ns]",
1383 5000, -25.0, 25.0, 6, 0, 6);
1384 fhTimePtVsHits = new TH2I("Clus_TofTimePtVsHit",
1385 "Time resolution for TofHits containing Digis "
1386 "from a single TofPoint; tMcPoint -tTofHit [ps]",
1387 2000, 0.0, 50.0, 2000, 0.0, 50.0);
1388 } // else of if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
1389 fhClusterSize = new TH1I("Clus_ClusterSize", "Cluster Size distribution; Cluster Size [Strips]", 100, 0.5, 100.5);
1391 new TH2I("Clus_ClusterSizeType",
1392 "Cluster Size distribution in each (SM type, Rpc) pair; Cluster "
1393 "Size [Strips]; 10*SM Type + Rpc Index []",
1394 100, 0.5, 100.5, 40 * fDigiBdfPar->GetNbSmTypes(), 0.0, 40 * fDigiBdfPar->GetNbSmTypes());
1395 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
1396 fhTrackMul = new TH1I("Clus_TrackMul", "Number of MC tracks generating the cluster; MC Tracks multiplicity []", 100,
1397 0.5, 100.5);
1398 fhClusterSizeMulti = new TH2I("Clus_ClusterSizeMulti",
1399 "Cluster Size distribution as function of Number of MC tracks generating "
1400 "the cluster; Cluster Size [Strips]; MC tracks mul. []",
1401 100, 0.5, 100.5, 100, 0.5, 100.5);
1402 fhTrk1MulPos = new TH2D("Clus_Trk1MulPos",
1403 "Position of Clusters with only 1 MC tracks "
1404 "generating the cluster; X [cm]; Y [cm]",
1405 1500, -750, 750, 1000, -500, 500);
1406 fhHiTrkMulPos = new TH2D("Clus_HiTrkMulPos",
1407 "Position of Clusters with >1 MC tracks "
1408 "generating the cluster; X [cm]; Y [cm]",
1409 1500, -750, 750, 1000, -500, 500);
1410 fhAllTrkMulPos = new TH2D("Clus_AllTrkMulPos", "Position of all clusters generating the cluster; X [cm]; Y [cm]",
1411 1500, -750, 750, 1000, -500, 500);
1412 fhMultiTrkProbPos = new TH2D("Clus_MultiTrkProbPos",
1413 "Probability of having a cluster with multiple tracks as "
1414 "function of position; X [cm]; Y [cm]; Prob. [%]",
1415 1500, -750, 750, 1000, -500, 500);
1416 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
1417
1418 gDirectory->cd(oldir->GetPath()); // <= To prevent histos from being sucked in by the param file of the TRootManager!
1419
1420 return kTRUE;
1421}
1422
1424{
1425 fhClustBuildTime->Fill(fStop.GetSec() - fStart.GetSec() + (fStop.GetNanoSec() - fStart.GetNanoSec()) / 1e9);
1426 Int_t iNbTofHits = fTofHitsColl->GetEntriesFast();
1427 CbmTofHit* pHit;
1428 //gGeoManager->SetTopVolume( gGeoManager->FindVolumeFast("tof_v14a") );
1429 gGeoManager->CdTop();
1430
1431 if (0 < iNbTofHits) {
1432 /* Double_t dCluMul=0.;*/
1433 Bool_t BSel[iNSel];
1434 Double_t dTTrig[iNSel];
1435 CbmTofHit* pTrig[iNSel];
1436 Double_t ddXdZ[iNSel];
1437 Double_t ddYdZ[iNSel];
1438 Double_t dSel2dXdYMin[iNSel];
1439
1440 Int_t iBeamRefMul = 0;
1441 Int_t iBeamAddRefMul = 0;
1442
1443 if (0 < iNSel) { // check software triggers
1444
1445 LOG(debug) << "CbmTofTestBeamClusterizer::FillHistos() for " << iNSel << " triggers"
1446 << ", Dut " << fDutId << ", " << fDutSm << ", " << fDutRpc << Form(", 0x%08x", fDutAddr) << ", Sel "
1447 << fSelId << ", " << fSelSm << ", " << fSelRpc << Form(", 0x%08x", fSelAddr) << ", Sel2 " << fSel2Id
1448 << ", " << fSel2Sm << ", " << fSel2Rpc << Form(", 0x%08x", fSel2Addr);
1449 LOG(debug) << "CbmTofTestBeamClusterizer::FillHistos: Muls: " << fviClusterMul[fDutId][fDutSm][fDutRpc] << ", "
1451 // monitor multiplicities
1452 Int_t iNbDet = fDigiBdfPar->GetNbDet();
1453 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1454 Int_t iDetId = fviDetId[iDetIndx];
1455 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
1456 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
1457 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
1458 //LOG(info) << Form(" indx %d, Id 0x%08x, TSR %d %d %d", iDetIndx, iDetId, iSmType, iSm, iRpc)
1459 // ;
1460 if (NULL != fhRpcCluMul[iDetIndx]) fhRpcCluMul[iDetIndx]->Fill(fviClusterMul[iSmType][iSm][iRpc]); //
1461 }
1462
1464
1465 // do input distributions first
1466 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
1467 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
1468 if (NULL == pHit) continue;
1469 if (StartAnalysisTime == 0.) {
1470 StartAnalysisTime = pHit->GetTime();
1471 LOG(info) << "StartAnalysisTime set to " << StartAnalysisTime << " ns. ";
1472 }
1473 Int_t iDetId = (pHit->GetAddress() & DetMask);
1474
1475 std::map<UInt_t, UInt_t>::iterator it = fDetIdIndexMap.find(iDetId);
1476 if (it == fDetIdIndexMap.end()) continue; // continue for invalid detector index
1477 Int_t iDetIndx = it->second; //fDetIdIndexMap[iDetId];
1478
1479 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
1480 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
1481 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
1482 Int_t iCh = CbmTofAddress::GetChannelId(pHit->GetAddress());
1483
1484 Double_t dTimeAna = (pHit->GetTime() - StartAnalysisTime) / 1.E9;
1485 LOG(debug) << "TimeAna " << StartAnalysisTime << ", " << pHit->GetTime() << ", " << dTimeAna;
1486 fhRpcCluRate[iDetIndx]->Fill(dTimeAna);
1487
1488 if (fdMemoryTime > 0. && fvLastHits[iSmType][iSm][iRpc][iCh].size() == 0)
1489 LOG(fatal) << Form(" <E> hit not stored in memory for TSRC %d%d%d%d", iSmType, iSm, iRpc, iCh);
1490
1491 //CheckLHMemory();
1492
1493 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for outdated hits
1494 //std::list<CbmTofHit *>::iterator it0=fvLastHits[iSmType][iSm][iRpc][iCh].begin();
1495 //std::list<CbmTofHit *>::iterator itL=fvLastHits[iSmType][iSm][iRpc][iCh].end();
1496 //CbmTofHit* pH0 = *it0;
1497 //CbmTofHit* pHL = *(--itL);
1498 CbmTofHit* pH0 = fvLastHits[iSmType][iSm][iRpc][iCh].front();
1499 CbmTofHit* pHL = fvLastHits[iSmType][iSm][iRpc][iCh].back();
1500 if (pH0->GetTime() > pHL->GetTime())
1501 LOG(warning) << Form("Invalid time ordering in ev %8.0f in list of "
1502 "size %lu for TSRC %d%d%d%d: Delta t %f ",
1503 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
1504 pHL->GetTime() - pH0->GetTime());
1505
1506 // while( (*((std::list<CbmTofHit *>::iterator) fvLastHits[iSmType][iSm][iRpc][iCh].begin()))->GetTime()+fdMemoryTime < pHit->GetTime()
1507 while (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 2.
1508 || fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime() + fdMemoryTime < pHit->GetTime())
1509
1510 {
1511 LOG(debug) << " pop from list size " << fvLastHits[iSmType][iSm][iRpc][iCh].size()
1512 << Form(" outdated hits for ev %8.0f in TSRC %d%d%d%d", fdEvent, iSmType, iSm, iRpc, iCh)
1513 << Form(" with tHit - tLast %f ",
1514 pHit->GetTime() - fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime())
1515 //(*((std::list<CbmTofHit *>::iterator) fvLastHits[iSmType][iSm][iRpc][iCh].begin()))->GetTime())
1516 ;
1517 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != pHit->GetAddress())
1518 LOG(fatal) << Form("Inconsistent address in list of size %lu for TSRC %d%d%d%d: "
1519 "0x%08x, time %f",
1520 fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
1521 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
1522 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
1523 fvLastHits[iSmType][iSm][iRpc][iCh].front()->Delete();
1524 fvLastHits[iSmType][iSm][iRpc][iCh].pop_front();
1525 }
1526 } //fvLastHits[iSmType][iSm][iRpc][iCh].size()>1)
1527
1528 // plot remaining time difference to previous hits
1529 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
1530 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
1531 Double_t dTotSum = 0.;
1532 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
1533 CbmLink L0 = digiMatch->GetLink(iLink);
1534 Int_t iDigInd0 = L0.GetIndex();
1535 Int_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex();
1536 CbmTofDigi* pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
1537 CbmTofDigi* pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
1538 dTotSum += pDig0->GetTot() + pDig1->GetTot();
1539 }
1540
1541 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
1542 itL--;
1543 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
1544 itL--;
1545 fhRpcDTLastHits[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()));
1546 fhRpcDTLastHits_CluSize[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
1547 digiMatch->GetNofLinks() / 2.);
1548 fhRpcDTLastHits_Tot[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()), dTotSum);
1549 }
1550 }
1551 } // iHitInd loop end
1552
1553 // do reference first
1554 dTRef = dDoubleMax;
1555 fTRefHits = 0;
1556
1557 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
1558 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
1559 if (NULL == pHit) continue;
1560 Int_t iDetId = (pHit->GetAddress() & DetMask);
1561
1562 if (fiBeamRefAddr == iDetId) {
1564 // Check Tot
1565 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
1566 Double_t TotSum = 0.;
1567 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
1568 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
1569 Int_t iDigInd0 = L0.GetIndex();
1570 if (iDigInd0 < fTofCalDigisColl->GetEntriesFast()) {
1571 CbmTofDigi* pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
1572 TotSum += pDig0->GetTot();
1573 }
1574 }
1575 TotSum /= (0.5 * digiMatch->GetNofLinks());
1576 if (TotSum > fhRpcCluTot[iIndexDut]->GetYaxis()->GetXmax()) continue; // ignore too large clusters
1577
1578 fTRefHits = 1;
1579 if (pHit->GetTime() < dTRef) {
1580 dTRef = pHit->GetTime();
1581 }
1582 iBeamRefMul++;
1583 }
1584 else { //additional reference type multiplicity
1585 if (fiBeamRefType == CbmTofAddress::GetSmType(iDetId)) iBeamAddRefMul++;
1586 }
1587 }
1588 LOG(debug) << "CbmTofTestBeamClusterizer::FillHistos: BRefMul: " << iBeamRefMul << ", " << iBeamAddRefMul;
1589
1590 if (iBeamRefMul == 0) return kFALSE; // don't fill histos without reference time
1591 if (iBeamAddRefMul < fiBeamAddRefMul) return kFALSE; // ask for confirmation by other beam counters
1592
1593 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1594 BSel[iSel] = kFALSE;
1595 pTrig[iSel] = NULL;
1596 Int_t iDutMul = 0;
1597 Int_t iRefMul = 0;
1598 Int_t iR0 = 0;
1599 Int_t iRl = 0;
1600 ddXdZ[iSel] = 0.;
1601 ddYdZ[iSel] = 0.;
1602 dSel2dXdYMin[iSel] = 1.E300;
1603
1604 switch (iSel) {
1605 case 0: // Detector under Test (Dut) && Diamonds,BeamRef
1606 iRl = fviClusterMul[fDutId][fDutSm].size();
1607 if (fDutRpc > -1) {
1608 iR0 = fDutRpc;
1609 }
1610 for (Int_t iRpc = iR0; iRpc < iRl; iRpc++)
1611 iDutMul += fviClusterMul[fDutId][fDutSm][iRpc];
1612 LOG(debug) << "CbmTofTestBeamClusterizer::FillHistos(): selector 0: DutMul "
1613 << fviClusterMul[fDutId][fDutSm][fDutRpc] << ", " << iDutMul << ", BRefMul " << iBeamRefMul
1614 << " TRef: " << dTRef << ", BeamAddRefMul " << iBeamAddRefMul << ", " << fiBeamAddRefMul;
1615 if (iDutMul > 0 && iDutMul < fiCluMulMax) {
1616 LOG(debug1) << "CbmTofTestBeamClusterizer::FillHistos(): Found selector 0";
1617 dTTrig[iSel] = dDoubleMax;
1618 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
1619 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
1620 if (NULL == pHit) continue;
1621
1622 Int_t iDetId = (pHit->GetAddress() & DetMask);
1623 //if( fDutId == CbmTofAddress::GetSmType( iDetId ))
1624 if (fDutAddr == iDetId) {
1625 if (pHit->GetTime() < dTTrig[iSel]) {
1626 dTTrig[iSel] = pHit->GetTime();
1627 pTrig[iSel] = pHit;
1628 BSel[iSel] = kTRUE;
1629 }
1630 }
1631 }
1632 LOG(debug) << Form("Found selector 0 with mul %d from 0x%08x at %f ", iDutMul, pTrig[iSel]->GetAddress(),
1633 dTTrig[iSel]);
1634 }
1635 break;
1636
1637 case 1: // MRef & BRef
1638 iRl = fviClusterMul[fSelId][fSelSm].size();
1639 if (fSelRpc > -1) {
1640 iR0 = fSelRpc;
1641 }
1642 for (Int_t iRpc = iR0; iRpc < iRl; iRpc++)
1643 iRefMul += fviClusterMul[fSelId][fSelSm][iRpc];
1644 LOG(debug) << "CbmTofTestBeamClusterizer::FillHistos(): selector 1: RefMul "
1645 << fviClusterMul[fSelId][fSelSm][fSelRpc] << ", " << iRefMul << ", BRefMul " << iBeamRefMul;
1646 if (iRefMul > 0 && iRefMul < fiCluMulMax) {
1647 LOG(debug1) << "CbmTofTestBeamClusterizer::FillHistos(): Found selector 1";
1648 dTTrig[iSel] = dDoubleMax;
1649 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
1650 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
1651 if (NULL == pHit) continue;
1652
1653 Int_t iDetId = (pHit->GetAddress() & DetMask);
1654 if (fSelAddr == iDetId) {
1655 if (pHit->GetTime() < dTTrig[iSel]) {
1656 dTTrig[iSel] = pHit->GetTime();
1657 pTrig[iSel] = pHit;
1658 BSel[iSel] = kTRUE;
1659 }
1660 }
1661 }
1662 LOG(debug) << Form("Found selector 1 with mul %d from 0x%08x at %f ", iRefMul, pTrig[iSel]->GetAddress(),
1663 dTTrig[iSel]);
1664 }
1665 break;
1666
1667 default:
1668 LOG(info) << "CbmTofTestBeamClusterizer::FillHistos: selection not "
1669 "implemented "
1670 << iSel;
1671 ;
1672 } // switch end
1673 if (fTRefMode > 10) {
1674 dTTrig[iSel] = dTRef;
1675 }
1676 } // iSel - loop end
1677
1678 if (fSel2Id > 0) { // confirm selector by independent match
1679 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1680 if (BSel[iSel]) {
1681 BSel[iSel] = kFALSE;
1684 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
1685 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
1686 if (NULL == pHit) continue;
1687 Int_t iDetId = (pHit->GetAddress() & DetMask);
1688 if (fSel2Addr == iDetId) {
1689 Double_t dzscal = 1.;
1690 if (fEnableMatchPosScaling) dzscal = pHit->GetZ() / pTrig[iSel]->GetZ();
1691 Double_t dSEl2dXdz = (pHit->GetX() - pTrig[iSel]->GetX()) / (pHit->GetZ() - pTrig[iSel]->GetZ());
1692 Double_t dSEl2dYdz = (pHit->GetY() - pTrig[iSel]->GetY()) / (pHit->GetZ() - pTrig[iSel]->GetZ());
1693
1694 if (TMath::Sqrt(TMath::Power(pHit->GetX() - dzscal * pTrig[iSel]->GetX(), 2.)
1695 + TMath::Power(pHit->GetY() - dzscal * pTrig[iSel]->GetY(), 2.))
1696 < fdCaldXdYMax) {
1697 BSel[iSel] = kTRUE;
1698 Double_t dX2Y2 = TMath::Sqrt(dSEl2dXdz * dSEl2dXdz + dSEl2dYdz * dSEl2dYdz);
1699 if (dX2Y2 < dSel2dXdYMin[iSel]) {
1700 ddXdZ[iSel] = dSEl2dXdz;
1701 ddYdZ[iSel] = dSEl2dYdz;
1702 dSel2dXdYMin[iSel] = dX2Y2;
1703 }
1704 break;
1705 }
1706 }
1707 }
1708 } // BSel condition end
1709 } // iSel lopp end
1710 } // Sel2Id condition end
1711
1712 /*
1713 // find the best dTRef
1714 fTRefHits=0;
1715 dTRef=0.; // invalidate old value
1716 Double_t dRefChi2=dDoubleMax;
1717 for( Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++)
1718 {
1719 pHit = (CbmTofHit*) fTofHitsColl->At( iHitInd );
1720 if (NULL==pHit) continue;
1721 Int_t iDetId = (pHit->GetAddress() & DetMask);
1722
1723 if( fiBeamRefType == CbmTofAddress::GetSmType( iDetId )){
1724 if(fiBeamRefSm == CbmTofAddress::GetSmId( iDetId ))
1725 {
1726 Double_t dDT2=0.;
1727 Double_t dNT=0.;
1728 for (Int_t iSel=0; iSel<iNSel; iSel++){
1729 if(BSel[iSel]){
1730 dDT2 += TMath::Power(pHit->GetTime()-dTTrig[iSel],2);
1731 dNT++;
1732 }
1733 }
1734 if( dNT > 0)
1735 if( dDT2/dNT < dRefChi2 )
1736 {
1737 fTRefHits=1;
1738 dTRef = pHit->GetTime();
1739 dRefChi2 = dDT2/dNT;
1740 }
1741 }
1742 }
1743 }
1744*/
1745
1746 UInt_t uTriggerPattern = 1;
1747 if (NULL != fTrbHeader)
1748 uTriggerPattern = fTrbHeader->GetTriggerPattern();
1749 else {
1750 for (Int_t iSel = 0; iSel < iNSel; iSel++)
1751 if (BSel[iSel]) {
1752 uTriggerPattern |= (0x1 << (iSel * 3 + CbmTofAddress::GetRpcId(pTrig[iSel]->GetAddress() & DetMask)));
1753 }
1754 }
1755 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1756 if (BSel[iSel]) {
1757 if (dTRef != 0. && fTRefHits > 0) {
1758 for (UInt_t uChannel = 0; uChannel < 16; uChannel++) {
1759 if (uTriggerPattern & (0x1 << uChannel)) {
1760 fhSeldT[iSel]->Fill(dTTrig[iSel] - dTRef, uChannel);
1761 }
1762 }
1763 }
1764 }
1765 }
1766 } // 0<iNSel software triffer check end
1767
1768 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
1769 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
1770 if (NULL == pHit) continue;
1771
1772 Int_t iDetId = (pHit->GetAddress() & DetMask);
1773 std::map<UInt_t, UInt_t>::iterator it = fDetIdIndexMap.find(iDetId);
1774 if (it == fDetIdIndexMap.end()) continue; // continue for invalid detector index
1775 Int_t iDetIndx = it->second; //fDetIdIndexMap[iDetId];
1776
1777 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
1778 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
1779 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
1780 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
1781 if (-1 < fviClusterMul[iSmType][iSm][iRpc]) {
1782 for (Int_t iSel = 0; iSel < iNSel; iSel++)
1783 if (BSel[iSel]) {
1784 Double_t w = fviClusterMul[iSmType][iSm][iRpc];
1785 if (w == 0.)
1786 w = 1.;
1787 else
1788 w = 1. / w;
1789 fhTRpcCluMul[iDetIndx][iSel]->Fill(fviClusterMul[iSmType][iSm][iRpc], w);
1790 }
1791 }
1792
1793 if (fviClusterMul[iSmType][iSm][iRpc] > fiCluMulMax) continue; // skip this event
1794 if (iBeamRefMul == 0) break;
1795
1796 Int_t iChId = pHit->GetAddress();
1797 fChannelInfo = fDigiPar->GetCell(iChId);
1798 Int_t iCh = CbmTofAddress::GetChannelId(iChId);
1799 if (NULL == fChannelInfo) {
1800 LOG(error) << "Invalid Channel Pointer for ChId " << Form(" 0x%08x ", iChId) << ", Ch " << iCh;
1801 continue;
1802 }
1803 /*TGeoNode *fNode=*/ // prepare global->local trafo
1804 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
1805
1806 LOG(debug1) << "Hit info: "
1807 << Form(" 0x%08x %d %f %f %f %f %f %d", iChId, iCh, pHit->GetX(), pHit->GetY(), pHit->GetTime(),
1808 fChannelInfo->GetX(), fChannelInfo->GetY(), iHitInd);
1809
1810 Double_t hitpos[3];
1811 hitpos[0] = pHit->GetX();
1812 hitpos[1] = pHit->GetY();
1813 hitpos[2] = pHit->GetZ();
1814 Double_t hitpos_local[3];
1815 TGeoNode* cNode = gGeoManager->GetCurrentNode();
1816 gGeoManager->MasterToLocal(hitpos, hitpos_local);
1817 LOG(debug1) << Form(" MasterToLocal for node %p: (%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)", cNode, hitpos[0],
1818 hitpos[1], hitpos[2], hitpos_local[0], hitpos_local[1], hitpos_local[2]);
1819
1820 fhRpcCluPosition[iDetIndx]->Fill((Double_t) iCh, hitpos_local[1]); //pHit->GetY()-fChannelInfo->GetY());
1821 fhSmCluPosition[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), hitpos_local[1]);
1822
1823 for (Int_t iSel = 0; iSel < iNSel; iSel++)
1824 if (BSel[iSel]) {
1825 fhTRpcCluPosition[iDetIndx][iSel]->Fill((Double_t) iCh,
1826 hitpos_local[1]); //pHit->GetY()-fChannelInfo->GetY());
1827 fhTSmCluPosition[iSmType][iSel]->Fill((Double_t)(iSm * iNbRpc + iRpc), hitpos_local[1]);
1828 }
1829
1830 if (TMath::Abs(hitpos_local[1]) > fChannelInfo->GetSizey() * fPosYMaxScal) continue;
1831 LOG(debug1) << " TofDigiMatchColl entries:" << fTofDigiMatchColl->GetEntriesFast();
1832
1833 if (iHitInd > fTofDigiMatchColl->GetEntriesFast()) {
1834 LOG(error) << " Inconsistent DigiMatches for Hitind " << iHitInd
1835 << ", TClonesArraySize: " << fTofDigiMatchColl->GetEntriesFast();
1836 }
1837
1838 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
1839 LOG(debug1) << " got " << digiMatch->GetNofLinks() << " matches for iCh " << iCh << " at iHitInd " << iHitInd;
1840
1841 fhRpcCluSize[iDetIndx]->Fill((Double_t) iCh, digiMatch->GetNofLinks() / 2.);
1842
1843 for (Int_t iSel = 0; iSel < iNSel; iSel++)
1844 if (BSel[iSel]) {
1845 fhTRpcCluSize[iDetIndx][iSel]->Fill((Double_t) iCh, digiMatch->GetNofLinks() / 2.);
1846 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
1847 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
1848 itL--;
1849 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
1850 itL--;
1851 fhTRpcCluSizeDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
1852 digiMatch->GetNofLinks() / 2.);
1853 }
1854 }
1855 }
1856
1857 Double_t TotSum = 0.;
1858 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink++) { // loop over digis
1859 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
1860 Int_t iDigInd0 = L0.GetIndex();
1861 if (iDigInd0 < fTofCalDigisColl->GetEntriesFast()) {
1862 CbmTofDigi* pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
1863 TotSum += pDig0->GetTot();
1864 }
1865 }
1866 Double_t dMeanTimeSquared = 0.;
1867 Double_t dNstrips = 0.;
1868
1869 Double_t dDelTof = 0.;
1870 Double_t dTcor[iNSel];
1871 Double_t dTTcor[iNSel];
1872 Double_t dZsign[iNSel];
1873 Double_t dzscal = 1.;
1874 //Double_t dDist=0.;
1875
1876 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
1877 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
1878 Int_t iDigInd0 = L0.GetIndex();
1879 Int_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex(); //vDigish.at(ivDigInd+1);
1880 //LOG(debug1)<<" " << iDigInd0<<", "<<iDigInd1;
1881
1882 if (iDigInd0 < fTofCalDigisColl->GetEntriesFast() && iDigInd1 < fTofCalDigisColl->GetEntriesFast()) {
1883 CbmTofDigi* pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
1884 CbmTofDigi* pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
1885 if ((Int_t) pDig0->GetType() != iSmType) {
1886 LOG(error) << Form(" Wrong Digi SmType for Tofhit %d in iDetIndx "
1887 "%d, Ch %d with %3.0f strips at Indx %d, %d",
1888 iHitInd, iDetIndx, iCh, dNstrips, iDigInd0, iDigInd1);
1889 }
1890 LOG(debug1) << " fhRpcCluTot: Digi 0 " << iDigInd0 << ": Ch " << pDig0->GetChannel() << ", Side "
1891 << pDig0->GetSide() << ", StripSide " << (Double_t) iCh * 2. + pDig0->GetSide() << " Digi 1 "
1892 << iDigInd1 << ": Ch " << pDig1->GetChannel() << ", Side " << pDig1->GetSide() << ", StripSide "
1893 << (Double_t) iCh * 2. + pDig1->GetSide() << ", Tot0 " << pDig0->GetTot() << ", Tot1 "
1894 << pDig1->GetTot();
1895
1896 fhRpcCluTot[iDetIndx]->Fill(pDig0->GetChannel() * 2. + pDig0->GetSide(), pDig0->GetTot());
1897 fhRpcCluTot[iDetIndx]->Fill(pDig1->GetChannel() * 2. + pDig1->GetSide(), pDig1->GetTot());
1898
1899 Int_t iCh0 = pDig0->GetChannel();
1900 Int_t iCh1 = pDig1->GetChannel();
1901 Int_t iS0 = pDig0->GetSide();
1902 Int_t iS1 = pDig1->GetSide();
1903 if (iCh0 != iCh1 || iS0 == iS1) {
1904 LOG(fatal) << Form(" MT2 for Tofhit %d in iDetIndx %d, Ch %d from %3.0f strips: ", iHitInd, iDetIndx, iCh,
1905 dNstrips)
1906 << Form(" Dig0: Ind %d, Ch %d, Side %d, T: %6.1f ", iDigInd0, iCh0, iS0, pDig0->GetTime())
1907 << Form(" Dig1: Ind %d, Ch %d, Side %d, T: %6.1f ", iDigInd1, iCh1, iS1, pDig1->GetTime());
1908 continue;
1909 }
1910
1911 if (0 > iCh0 || fDigiBdfPar->GetNbChan(iSmType, iRpc) <= iCh0) {
1912 LOG(error) << Form(" Wrong Digi for Tofhit %d in iDetIndx %d, Ch %d at Indx %d, %d "
1913 "from %3.0f strips: %d, %d, %d, %d",
1914 iHitInd, iDetIndx, iCh, iDigInd0, iDigInd1, dNstrips, iCh0, iCh1, iS0, iS1);
1915 continue;
1916 }
1917
1918 if (digiMatch->GetNofLinks() > 2) //&& digiMatch->GetNofLinks()<8 ) // FIXME: hardcoded limits on CluSize
1919 {
1920 dNstrips += 1.;
1921 dMeanTimeSquared += TMath::Power(0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime(), 2);
1922 // fhRpcCluAvWalk[iDetIndx]->Fill(0.5*(pDig0->GetTot()+pDig1->GetTot()),
1923 // 0.5*(pDig0->GetTime()+pDig1->GetTime())-pHit->GetTime());
1924
1925 fhRpcCluAvLnWalk[iDetIndx]->Fill(TMath::Log10(0.5 * (pDig0->GetTot() + pDig1->GetTot())),
1926 0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime());
1927
1928 Double_t dTotWeigth = (pDig0->GetTot() + pDig1->GetTot()) / TotSum;
1929 Double_t dCorWeigth = 1. - dTotWeigth;
1930
1931 fhRpcCluDelTOff[iDetIndx]->Fill(
1932 pDig0->GetChannel(), dCorWeigth * (0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime()));
1933
1934 Double_t dDelPos = 0.5 * (pDig0->GetTime() - pDig1->GetTime()) * fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
1935 if (0 == pDig0->GetSide()) dDelPos *= -1.;
1936 fhRpcCluDelPos[iDetIndx]->Fill(pDig0->GetChannel(), dCorWeigth * (dDelPos - hitpos_local[1]));
1937
1938 fhRpcCluWalk[iDetIndx][iCh0][iS0]->Fill(
1939 pDig0->GetTot(),
1940 pDig0->GetTime()
1941 - (pHit->GetTime()
1942 - (1. - 2. * pDig0->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
1943
1944 fhRpcCluWalk[iDetIndx][iCh1][iS1]->Fill(
1945 pDig1->GetTot(),
1946 pDig1->GetTime()
1947 - (pHit->GetTime()
1948 - (1. - 2. * pDig1->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
1949
1950 fhRpcCluAvWalk[iDetIndx]->Fill(pDig0->GetTot(), pDig0->GetTime()
1951 - (pHit->GetTime()
1952 - (1. - 2. * pDig0->GetSide()) * hitpos_local[1]
1953 / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
1954 fhRpcCluAvWalk[iDetIndx]->Fill(pDig1->GetTot(), pDig1->GetTime()
1955 - (pHit->GetTime()
1956 - (1. - 2. * pDig1->GetSide()) * hitpos_local[1]
1957 / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
1958 } // end of Clustersize > 1 condition
1959
1960 LOG(debug1) << " fhTRpcCluTot: Digi 0 " << iDigInd0 << ": Ch " << pDig0->GetChannel() << ", Side "
1961 << pDig0->GetSide() << ", StripSide " << (Double_t) iCh * 2. + pDig0->GetSide() << " Digi 1 "
1962 << iDigInd1 << ": Ch " << pDig1->GetChannel() << ", Side " << pDig1->GetSide() << ", StripSide "
1963 << (Double_t) iCh * 2. + pDig1->GetSide();
1964
1965 for (Int_t iSel = 0; iSel < iNSel; iSel++)
1966 if (BSel[iSel]) {
1967 if (NULL == pHit || NULL == pTrig[iSel]) {
1968 LOG(info) << " invalid pHit, iSel " << iSel << ", iDetIndx " << iDetIndx;
1969 break;
1970 }
1971 if (pHit->GetAddress() == pTrig[iSel]->GetAddress()) continue;
1972
1973 fhTRpcCluTot[iDetIndx][iSel]->Fill(pDig0->GetChannel() * 2. + pDig0->GetSide(), pDig0->GetTot());
1974 fhTRpcCluTot[iDetIndx][iSel]->Fill(pDig1->GetChannel() * 2. + pDig1->GetSide(), pDig1->GetTot());
1975 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
1976 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
1977 itL--;
1978 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
1979 itL--;
1980 fhTRpcCluTotDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
1981 pDig0->GetTot());
1982 fhTRpcCluTotDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
1983 pDig1->GetTot());
1984 }
1985 }
1986 if (iLink == 0) { // Fill histo only once (for 1. digi entry)
1987 if (fEnableMatchPosScaling) dzscal = pHit->GetZ() / pTrig[iSel]->GetZ();
1988 fhTRpcCludXdY[iDetIndx][iSel]->Fill(pHit->GetX() - dzscal * pTrig[iSel]->GetX(),
1989 pHit->GetY() - dzscal * pTrig[iSel]->GetY());
1990 dZsign[iSel] = 1.;
1991 if (pHit->GetZ() < pTrig[iSel]->GetZ()) dZsign[iSel] = -1.;
1992 }
1994 //if( iSmType==fiBeamRefType // to get entries in diamond/BeamRef histos
1995 if (iSmType == 5 // FIXME, to get entries in diamond histos
1996 || TMath::Sqrt(TMath::Power(pHit->GetX() - dzscal * pTrig[iSel]->GetX(), 2.)
1997 + TMath::Power(pHit->GetY() - dzscal * pTrig[iSel]->GetY(), 2.))
1998 < fdCaldXdYMax) {
1999 if (!fEnableMatchPosScaling && dSel2dXdYMin[iSel] < 1.E300)
2000 if (TMath::Sqrt(
2001 TMath::Power(pHit->GetX()
2002 - (pTrig[iSel]->GetX() + ddXdZ[iSel] * (pHit->GetZ() - (pTrig[iSel]->GetZ()))),
2003 2.)
2004 + TMath::Power(pHit->GetY()
2005 - (pTrig[iSel]->GetY() + ddYdZ[iSel] * (pHit->GetZ() - (pTrig[iSel]->GetZ()))),
2006 2.))
2007 > 0.5 * fdCaldXdYMax)
2008 continue; // refine position selection cut in cosmic measurement
2009 dTcor[iSel] = 0.; // precaution
2010 if (dTRef != 0.
2011 && TMath::Abs(dTRef - dTTrig[iSel]) < fdDelTofMax) { // correct times for DelTof - velocity spread
2012 if (iLink == 0) { // do calculations only once (at 1. digi entry) // interpolate!
2013 // calculate spatial distance to trigger hit
2014 /*
2015 dDist=TMath::Sqrt(TMath::Power(pHit->GetX()-pTrig[iSel]->GetX(),2.)
2016 +TMath::Power(pHit->GetY()-pTrig[iSel]->GetY(),2.)
2017 +TMath::Power(pHit->GetZ()-pTrig[iSel]->GetZ(),2.));
2018 */
2019 // determine correction value
2020 //if(fiBeamRefAddr != iDetId) // do not do this for reference counter itself
2021 if (fTRefMode < 11) // do not do this for trigger counter itself
2022 {
2023 Double_t dTentry = dTRef - dTTrig[iSel] + fdDelTofMax;
2024 Int_t iBx = dTentry / 2. / fdDelTofMax * nbClDelTofBinX;
2025 if (iBx < 0) iBx = 0;
2026 if (iBx > nbClDelTofBinX - 1) iBx = nbClDelTofBinX - 1;
2027 Double_t dBinWidth = 2. * fdDelTofMax / nbClDelTofBinX;
2028 Double_t dDTentry = dTentry - ((Double_t) iBx) * dBinWidth;
2029 Int_t iBx1 = 0;
2030 dDTentry < 0 ? iBx1 = iBx - 1 : iBx1 = iBx + 1;
2031 Double_t w0 = 1. - TMath::Abs(dDTentry) / dBinWidth;
2032 Double_t w1 = 1. - w0;
2033 if (iBx1 < 0) iBx1 = 0;
2034 if (iBx1 > nbClDelTofBinX - 1) iBx1 = nbClDelTofBinX - 1;
2035 dDelTof = fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] * w0
2036 + fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx1][iSel] * w1;
2037 //dDelTof *= dDist; // has to be consistent with fhTRpcCluDelTof filling
2038 LOG(debug1) << Form(" DelTof for SmT %d, Sm %d, R %d, T %d, dTRef "
2039 "%6.1f, Bx %d, Bx1 %d, DTe %6.1f -> DelT %6.1f",
2040 iSmType, iSm, iRpc, iSel, dTRef - dTTrig[iSel], iBx, iBx1, dDTentry, dDelTof);
2041 }
2042 dTTcor[iSel] = dDelTof * dZsign[iSel];
2043 dTcor[iSel] = pHit->GetTime() - dDelTof - dTTrig[iSel];
2044 // Double_t dAvTot=0.5*(pDig0->GetTot()+pDig1->GetTot()); (VF) not used
2045 } // if(iLink==0)
2046
2047 LOG(debug) << Form(" TRpcCluWalk for Ev %d, Link %d(%d), Sel %d, TSR %d%d%d, "
2048 "Ch %d,%d, S %d,%d T %f, DelTof %6.1f, W-ent: %6.0f,%6.0f",
2049 fiNevtBuild, iLink, (Int_t) digiMatch->GetNofLinks(), iSel, iSmType, iSm, iRpc,
2050 iCh0, iCh1, iS0, iS1, dTTrig[iSel], dDelTof,
2051 fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->GetEntries(),
2052 fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->GetEntries());
2053
2054 if (fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->GetEntries()
2055 != fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->GetEntries())
2056 LOG(error) << Form(" Inconsistent walk histograms -> debugging "
2057 "necessary ... for %d, %d, %d, %d, %d, %d, %d ",
2058 fiNevtBuild, iDetIndx, iSel, iCh0, iCh1, iS0, iS1);
2059
2060 LOG(debug1) << Form(
2061 " TRpcCluWalk values side %d: %f, %f, side %d: %f, %f ", iS0, pDig0->GetTot(),
2062 pDig0->GetTime()
2063 + ((1. - 2. * pDig0->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc))
2064 - dTTcor[iSel] - dTTrig[iSel],
2065 iS1, pDig1->GetTot(),
2066 pDig1->GetTime()
2067 + ((1. - 2. * pDig1->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc))
2068 - dTTcor[iSel] - dTTrig[iSel]);
2069
2070 fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->Fill(
2071 pDig0->GetTot(),
2072 //(pDig0->GetTime()+((1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2073 // dTcor[iSel]+(1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2074 dTcor[iSel]);
2075 fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->Fill(
2076 pDig1->GetTot(),
2077 //(pDig1->GetTime()+((1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2078 //dTcor[iSel]+(1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2079 dTcor[iSel]);
2080
2081 fhTRpcCluAvWalk[iDetIndx][iSel]->Fill(
2082 pDig0->GetTot(),
2083 //(pDig0->GetTime()+((1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2084 //dTcor[iSel]+(1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2085 dTcor[iSel]);
2086 fhTRpcCluAvWalk[iDetIndx][iSel]->Fill(
2087 pDig1->GetTot(),
2088 //(pDig1->GetTime()+((1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2089 //dTcor[iSel]+(1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2090 dTcor[iSel]);
2091
2092 if (iLink == 0) { // Fill histo only once (for 1. digi entry)
2093 //fhTRpcCluDelTof[iDetIndx][iSel]->Fill(dTRef-dTTrig[iSel],dTcor[iSel]/dDist);
2094 fhTRpcCluDelTof[iDetIndx][iSel]->Fill(dTRef - dTTrig[iSel], dTcor[iSel]);
2095 fhTSmCluTOff[iSmType][iSel]->Fill((Double_t)(iSm * iNbRpc + iRpc), dTcor[iSel]);
2096 fhTSmCluTRun[iSmType][iSel]->Fill(fdEvent, dTcor[iSel]);
2097 if (iDetId
2098 != (pTrig[iSel]->GetAddress()
2099 & DetMask)) { // transform matched hit-pair back into detector frame
2100 hitpos[0] = pHit->GetX() - dzscal * pTrig[iSel]->GetX() + fChannelInfo->GetX();
2101 hitpos[1] = pHit->GetY() - dzscal * pTrig[iSel]->GetY() + fChannelInfo->GetY();
2102 hitpos[2] = pHit->GetZ();
2103 gGeoManager->MasterToLocal(hitpos, hitpos_local); // transform into local frame
2104 fhRpcCluDelMatPos[iDetIndx]->Fill((Double_t) iCh, hitpos_local[1]);
2105 fhRpcCluDelMatTOff[iDetIndx]->Fill((Double_t) iCh,
2106 (pHit->GetTime() - dTTrig[iSel]) - dTTcor[iSel]);
2107 }
2108 } // iLink==0 condition end
2109 } // position condition end
2110 } // Match condition end
2111 } // closing of selector loop
2112 }
2113 else {
2114 LOG(error) << "CbmTofTestBeamClusterizer::FillHistos: invalid digi index " << iDetIndx << " digi0,1"
2115 << iDigInd0 << ", " << iDigInd1 << " - max:" << fTofCalDigisColl->GetEntriesFast()
2116 // << " in event " << XXX
2117 ;
2118 }
2119 } // iLink digi loop end;
2120
2121 if (1 < dNstrips) {
2122 // Double_t dVar=dMeanTimeSquared/dNstrips - TMath::Power(pHit->GetTime(),2);
2123 Double_t dVar = dMeanTimeSquared / (dNstrips - 1);
2124 //if(dVar<0.) dVar=0.;
2125 Double_t dTrms = TMath::Sqrt(dVar);
2126 LOG(debug) << Form(" Trms for Tofhit %d in iDetIndx %d, Ch %d from "
2127 "%3.0f strips: %6.3f ns",
2128 iHitInd, iDetIndx, iCh, dNstrips, dTrms);
2129 fhRpcCluTrms[iDetIndx]->Fill((Double_t) iCh, dTrms);
2130 pHit->SetTimeError(dTrms);
2131 }
2132
2133 LOG(debug1) << " Fill Time of iDetIndx " << iDetIndx << ", hitAddr "
2134 << Form(" %08x, y = %5.2f", pHit->GetAddress(), hitpos_local[1]) << " for |y| <"
2135 << fhRpcCluPosition[iDetIndx]->GetYaxis()->GetXmax();
2136 if (TMath::Abs(hitpos_local[1]) < (fhRpcCluPosition[iDetIndx]->GetYaxis()->GetXmax())) {
2137 if (dTRef != 0. && fTRefHits == 1) {
2138 fhRpcCluTOff[iDetIndx]->Fill((Double_t) iCh, pHit->GetTime() - dTRef);
2139 fhSmCluTOff[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), pHit->GetTime() - dTRef);
2140
2141 for (Int_t iSel = 0; iSel < iNSel; iSel++)
2142 if (BSel[iSel]) {
2143 LOG(debug1) << " TRpcCluTOff " << iDetIndx << ", Sel " << iSel
2144 << Form(", Dt %7.3f, LHsize %lu ", pHit->GetTime() - dTTrig[iSel],
2145 fvLastHits[iSmType][iSm][iRpc][iCh].size());
2146 if (pHit->GetAddress() == pTrig[iSel]->GetAddress()) continue;
2147
2148 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
2149 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
2150 itL--;
2151 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
2152 itL--;
2153 LOG(debug1) << Form(" %f,", pHit->GetTime() - (*itL)->GetTime());
2154 }
2155 }
2156 LOG(debug1);
2157 // fill Time Offset histograms without velocity spread (DelTof) correction
2158 fhTRpcCluTOff[iDetIndx][iSel]->Fill((Double_t) iCh,
2159 pHit->GetTime()
2160 - dTTrig[iSel]); // -dTTcor[iSel] only valid for matches
2161 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
2162 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
2163 itL--;
2164 for (Int_t iH = 0; iH < 1; iH++) { // use only last hit
2165 // for(Int_t iH=0; iH<fvLastHits[iSmType][iSm][iRpc][iCh].size()-1; iH++){//fill for all memorized hits
2166 itL--;
2167 Double_t dTsinceLast = pHit->GetTime() - (*itL)->GetTime();
2168 if (dTsinceLast > fdMemoryTime)
2169 LOG(fatal) << Form("Invalid Time since last hit on channel "
2170 "TSRC %d%d%d%d: %f > %f",
2171 iSmType, iSm, iRpc, iCh, dTsinceLast, fdMemoryTime);
2172
2173 fhTRpcCluTOffDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(dTsinceLast),
2174 pHit->GetTime() - dTTrig[iSel]);
2175 fhTRpcCluMemMulDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(dTsinceLast),
2176 fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1);
2177 }
2178 }
2179 }
2180 }
2181 }
2182 }
2183
2184 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
2185 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
2186 LOG(debug1) << "CbmTofTestBeamClusterizer::FillHistos: "
2187 << Form(" %3d %3d %3lu ", iSmType, iRpc, fviClusterSize[iSmType][iRpc].size());
2188
2189 for (UInt_t uCluster = 0; uCluster < fviClusterSize[iSmType][iRpc].size(); uCluster++) {
2190 LOG(debug2) << "CbmTofTestBeamClusterizer::FillHistos: " << Form(" %3d %3d %3d ", iSmType, iRpc, uCluster);
2191
2192 fhClusterSize->Fill(fviClusterSize[iSmType][iRpc][uCluster]);
2193 fhClusterSizeType->Fill(fviClusterSize[iSmType][iRpc][uCluster],
2194 40 * iSmType + iRpc); //FIXME - hardwired constant
2195 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
2196 fhTrackMul->Fill(fviTrkMul[iSmType][iRpc][uCluster]);
2197 fhClusterSizeMulti->Fill(fviClusterSize[iSmType][iRpc][uCluster], fviTrkMul[iSmType][iRpc][uCluster]);
2198 if (1 == fviTrkMul[iSmType][iRpc][uCluster])
2199 fhTrk1MulPos->Fill(fvdX[iSmType][iRpc][uCluster], fvdY[iSmType][iRpc][uCluster]);
2200 if (1 < fviTrkMul[iSmType][iRpc][uCluster])
2201 fhHiTrkMulPos->Fill(fvdX[iSmType][iRpc][uCluster], fvdY[iSmType][iRpc][uCluster]);
2202 fhAllTrkMulPos->Fill(fvdX[iSmType][iRpc][uCluster], fvdY[iSmType][iRpc][uCluster]);
2203 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
2204 if (kFALSE) // 1 == fviTrkMul[iSmType][iRpc][uCluster] )
2205 {
2206 fhClustSizeDifX->Fill(fviClusterSize[iSmType][iRpc][uCluster], fvdDifX[iSmType][iRpc][uCluster]);
2207 fhClustSizeDifY->Fill(fviClusterSize[iSmType][iRpc][uCluster], fvdDifY[iSmType][iRpc][uCluster]);
2208 if (1 == fviClusterSize[iSmType][iRpc][uCluster]) {
2209 fhChDifDifX->Fill(fvdDifCh[iSmType][iRpc][uCluster], fvdDifX[iSmType][iRpc][uCluster]);
2210 fhChDifDifY->Fill(fvdDifCh[iSmType][iRpc][uCluster], fvdDifY[iSmType][iRpc][uCluster]);
2211 }
2212 }
2213 } // for( UInt_t uCluster = 0; uCluster < fviClusterSize[iSmType][iRpc].size(); uCluster++ )
2214 fviClusterSize[iSmType][iRpc].clear();
2215 fviTrkMul[iSmType][iRpc].clear();
2216 fvdX[iSmType][iRpc].clear();
2217 fvdY[iSmType][iRpc].clear();
2218 fvdDifX[iSmType][iRpc].clear();
2219 fvdDifY[iSmType][iRpc].clear();
2220 fvdDifCh[iSmType][iRpc].clear();
2221 } // for( Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc( iSmType); iRpc++ )
2222 }
2224 }
2225
2226 return kTRUE;
2227}
2228
2230{
2232 TFile* oldFile = gFile;
2233 TDirectory* oldDir = gDirectory;
2234 TFile* fHist;
2235 fHist = new TFile(fOutHstFileName, "RECREATE");
2236 fHist->cd();
2237 // fhClustBuildTime->Write();
2238
2239 for (Int_t iDetIndx = 0; iDetIndx < fDigiBdfPar->GetNbDet(); iDetIndx++) {
2240 if (NULL == fhRpcCluMul[iDetIndx]) continue;
2241 // fhRpcCluMul[iDetIndx]->Write();
2242 // fhRpcCluRate[iDetIndx]->Write();
2243 // fhRpcCluPosition[iDetIndx]->Write();
2244 // fhRpcCluDelPos[iDetIndx]->Write();
2245 // fhRpcCluTOff[iDetIndx]->Write();
2246 // fhRpcCluDelTOff[iDetIndx]->Write();
2247 // fhRpcCluTrms[iDetIndx]->Write();
2248 // fhRpcCluTot[iDetIndx]->Write();
2249 // fhRpcCluAvWalk[iDetIndx]->Write();
2250 // fhRpcCluAvLnWalk[iDetIndx]->Write();
2251 // fhRpcDTLastHits[iDetIndx]->Write();
2252 // fhRpcDTLastHits_Tot[iDetIndx]->Write();
2253 // fhRpcDTLastHits_CluSize[iDetIndx]->Write();
2254
2255 LOG(debug) << "Write triggered Histos for Det Ind " << iDetIndx
2256 << Form(", UID 0x%08x", fDigiBdfPar->GetDetUId(iDetIndx));
2257 for (Int_t iSel = 0; iSel < iNSel; iSel++) { // Save trigger selected histos
2258 if (NULL == fhTRpcCluMul[iDetIndx][iSel]) continue;
2259 // fhTRpcCluMul[iDetIndx][iSel]->Write();
2260 // fhTRpcCluPosition[iDetIndx][iSel]->Write();
2261 // fhTRpcCluTOff[iDetIndx][iSel]->Write();
2262 // fhTRpcCluTot[iDetIndx][iSel]->Write();
2263 // fhTRpcCluAvWalk[iDetIndx][iSel]->Write();
2264 }
2265
2266 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
2267 Int_t iSmAddr = iUniqueId & DetMask;
2268 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
2269 Int_t iSm = CbmTofAddress::GetSmId(iUniqueId);
2270 Int_t iRpc = CbmTofAddress::GetRpcId(iUniqueId);
2271
2272 Int_t iNent = 0;
2273 if (fCalSel > -1) {
2274 if (NULL == fhTRpcCluAvWalk[iDetIndx][fCalSel]) continue;
2275 iNent = (Int_t) fhTRpcCluAvWalk[iDetIndx][fCalSel]->GetEntries();
2276 }
2277 else {
2278 if (NULL == fhRpcCluAvWalk[iDetIndx]) continue;
2279 iNent = (Int_t) fhRpcCluAvWalk[iDetIndx]->GetEntries();
2280 }
2281 if (0 == iNent) {
2282 LOG(info) << "WriteHistos: No entries in Walk histos for "
2283 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc;
2284 // continue;
2285 }
2286
2287 // if(-1<fCalSmAddr && fcalType != iSmAddr) continue;
2288 TH2* htempPos = NULL;
2289 TProfile* htempPos_pfx = NULL;
2290 TH1* htempPos_py = NULL;
2291 TProfile* htempTOff_pfx = NULL;
2292 TH1* htempTOff_px = NULL;
2293 TProfile* hAvPos_pfx = NULL;
2294 TProfile* hAvTOff_pfx = NULL;
2295 TH2* htempTOff = NULL; // -> Comment to remove warning because set but never used
2296 TH2* htempTot = NULL;
2297 TProfile* htempTot_pfx = NULL;
2298 TH1* htempTot_Mean = NULL;
2299 TH1* htempTot_Off = NULL;
2300
2301 if (-1 < fCalSel) {
2302 htempPos = fhRpcCluPosition[iDetIndx]; // use untriggered distributions for position
2303 htempPos_pfx = fhRpcCluPosition[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluPosition[iDetIndx]->GetNbinsY());
2304 //htempPos = fhTRpcCluPosition[iDetIndx][fCalSel];
2305 //htempPos_pfx = fhTRpcCluPosition[iDetIndx][fCalSel]->ProfileX("_pfx",1,fhTRpcCluPosition[iDetIndx][fCalSel]->GetNbinsY());
2306 htempTOff = fhTRpcCluTOff[iDetIndx][fCalSel]; // -> Comment to remove warning because set but never used
2307 htempTOff_pfx = htempTOff->ProfileX("_pfx", 1, fhTRpcCluTOff[iDetIndx][fCalSel]->GetNbinsY());
2308 htempTOff_px = htempTOff->ProjectionX("_px", 1, fhTRpcCluTOff[iDetIndx][fCalSel]->GetNbinsY());
2309 htempTot = fhTRpcCluTot[iDetIndx][fCalSel];
2310 htempTot_pfx = fhTRpcCluTot[iDetIndx][fCalSel]->ProfileX("_pfx", 1, fhTRpcCluTot[iDetIndx][fCalSel]->GetNbinsY());
2311 hAvPos_pfx =
2312 fhTSmCluPosition[iSmType][fCalSel]->ProfileX("_pfx", 1, fhTSmCluPosition[iSmType][fCalSel]->GetNbinsY());
2313 hAvTOff_pfx =
2314 fhTSmCluTOff[iSmType][fCalSel]->ProfileX("_pfx", 1, fhTSmCluTOff[iSmType][fCalSel]->GetNbinsY(), "s");
2315 }
2316 else // all triggers
2317 {
2318 htempPos = fhRpcCluPosition[iDetIndx];
2319 htempTot = fhRpcCluTot[iDetIndx];
2320 htempTot_pfx = fhRpcCluTot[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluTot[iDetIndx]->GetNbinsY());
2321 hAvPos_pfx = fhSmCluPosition[iSmType]->ProfileX("_pfx", 1, fhSmCluPosition[iSmType]->GetNbinsY());
2322 hAvTOff_pfx = fhSmCluTOff[iSmType]->ProfileX("_pfx", 1, fhSmCluTOff[iSmType]->GetNbinsY());
2323 if (-1 == fCalSel) { // take corrections from untriggered distributions
2324 htempPos_pfx = fhRpcCluPosition[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluPosition[iDetIndx]->GetNbinsY());
2325 // htempTOff = fhRpcCluTOff[iDetIndx]; // -> Comment to remove warning because set but never used
2326 htempTOff_pfx = fhRpcCluTOff[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluTOff[iDetIndx]->GetNbinsY(), "s");
2327 htempTOff_px = fhRpcCluTOff[iDetIndx]->ProjectionX("_px", 1, fhRpcCluTOff[iDetIndx]->GetNbinsY());
2328 }
2329 else {
2330 if (-2 == fCalSel) { //take corrections from Cluster deviations
2331 htempPos_pfx = fhRpcCluDelPos[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelPos[iDetIndx]->GetNbinsY());
2332 // htempTOff = fhRpcCluDelTOff[iDetIndx]; // -> Comment to remove warning because set but never used
2333 htempTOff_pfx = fhRpcCluDelTOff[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelTOff[iDetIndx]->GetNbinsY());
2334 htempTOff_px = fhRpcCluDelTOff[iDetIndx]->ProjectionX("_px", 1, fhRpcCluDelTOff[iDetIndx]->GetNbinsY());
2335 }
2336 else {
2337 if (-3 == fCalSel) { // take corrections from deviations to matched trigger hit
2338 htempPos_pfx = fhRpcCluDelMatPos[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelMatPos[iDetIndx]->GetNbinsY());
2339 // htempTOff = fhRpcCluDelMatTOff[iDetIndx]; // -> Comment to remove warning because set but never used
2340 htempTOff_pfx =
2341 fhRpcCluDelMatTOff[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelMatTOff[iDetIndx]->GetNbinsY());
2342 htempTOff_px =
2343 fhRpcCluDelMatTOff[iDetIndx]->ProjectionX("_px", 1, fhRpcCluDelMatTOff[iDetIndx]->GetNbinsY());
2344 }
2345 }
2346 }
2347 }
2348
2349 if (NULL == htempPos_pfx) {
2350 LOG(info) << "WriteHistos: Projections not available, continue ";
2351 continue;
2352 }
2353
2354 htempTot_Mean = htempTot_pfx->ProjectionX("_Mean");
2355 htempTot_Off = htempTot_pfx->ProjectionX("_Off");
2356
2357 htempPos_pfx->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx", iSmType, iSm, iRpc));
2358 htempTOff_pfx->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx", iSmType, iSm, iRpc));
2359 htempTot_pfx->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_pfx", iSmType, iSm, iRpc));
2360 htempTot_Mean->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Mean", iSmType, iSm, iRpc));
2361 htempTot_Off->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Off", iSmType, iSm, iRpc));
2362 hAvPos_pfx->SetName(Form("cl_CorSmT%01d_Pos_pfx", iSmType));
2363 hAvTOff_pfx->SetName(Form("cl_CorSmT%01d_TOff_pfx", iSmType));
2364
2365 switch (fCalMode % 10) {
2366 case 0: { // Initialize
2367 htempTot_Off->Reset(); // prepare TotOffset histo
2368 TH1* hbins[200];
2369 Int_t nbins = htempTot->GetNbinsX();
2370 for (int i = 0; i < nbins; i++) {
2371 hbins[i] = htempTot->ProjectionY(Form("bin%d", i + 1), i + 1, i + 1);
2372 /* Double_t Ymax=hbins[i]->GetMaximum();*/
2373 Int_t iBmax = hbins[i]->GetMaximumBin();
2374 TAxis* xaxis = hbins[i]->GetXaxis();
2375 Double_t Xmax = xaxis->GetBinCenter(iBmax);
2376 Double_t XOff = Xmax - fTotPreRange;
2377 XOff = (Double_t)(Int_t) XOff;
2378 if (XOff < 0) XOff = 0;
2379 htempTot_Off->SetBinContent(i + 1, XOff);
2380 Double_t Xmean = htempTot_Mean->GetBinContent(i + 1);
2381 if (Xmean < XOff) {
2382 LOG(warning) << "Inconsistent Tot numbers for "
2383 << Form("SmT%01d_sm%03d_rpc%03d bin%d: mean %f, Off %f", iSmType, iSm, iRpc, i, Xmean, XOff);
2384 }
2385 htempTot_Mean->SetBinContent(i + 1, (Xmean - XOff));
2386 if (htempTot_Mean->GetBinContent(i + 1) != (Xmean - XOff))
2387 LOG(warning) << "Tot numbers not stored properly for "
2388 << Form("SmT%01d_sm%03d_rpc%03d bin%d: mean %f, target %f", iSmType, iSm, iRpc, i,
2389 htempTot_Mean->GetBinContent(i + 1), Xmean - XOff);
2390 }
2391 htempPos_pfx->Write();
2392 htempTOff_pfx->Write();
2393 // htempTot_pfx->Write();
2394 htempTot_Mean->Write();
2395 htempTot_Off->Write();
2396 } break;
2397 case 1: //save offsets, update walks
2398 {
2399 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
2400 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
2401 LOG(debug) << "WriteHistos: restore Offsets and Gains and save Walk for "
2402 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc
2403 << " and calSmAddr = " << Form(" 0x%08x ", TMath::Abs(fCalSmAddr));
2404 htempPos_pfx->Reset(); //reset to restore means of original histos
2405 htempTOff_pfx->Reset();
2406 htempTot_Mean->Reset();
2407 htempTot_Off->Reset();
2408 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
2409 Double_t YMean =
2410 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
2411 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
2412 Double_t TMean =
2413 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
2414 htempPos_pfx->Fill(iCh, YMean);
2415 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
2416 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got " << htempPos_pfx->GetBinContent(iCh)
2417 << "," << htempPos_pfx->GetBinContent(iCh + 1) << "," << htempPos_pfx->GetBinContent(iCh + 2)
2418 << ", expected " << YMean;
2419 }
2420 htempTOff_pfx->Fill(iCh, TMean);
2421
2422 for (Int_t iSide = 0; iSide < 2; iSide++) {
2423 htempTot_Mean->SetBinContent(
2424 iCh * 2 + 1 + iSide,
2425 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]); //nh +1 empirical(?)
2426 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
2427 }
2428 }
2429
2430 LOG(debug1) << " Offset, gain restoring done ... ";
2431 htempPos_pfx->Write();
2432 htempTOff_pfx->Write();
2433 // htempTot_pfx->Write();
2434 htempTot_Mean->Write();
2435 htempTot_Off->Write();
2436
2437 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
2438 // Store DelTof corrections
2439 TDirectory* curdir = gDirectory;
2440 gROOT->cd(); //
2441 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
2442 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
2443 gDirectory->cd(curdir->GetPath());
2444 if (NULL != hCorDelTof) {
2445 TH1D* hCorDelTofout =
2446 (TH1D*) hCorDelTof->Clone(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
2447 hCorDelTofout->Write();
2448 }
2449 else {
2450 LOG(debug) << " No CorDelTof histo "
2451 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
2452 }
2453 }
2454
2455 if ((fCalSmAddr < 0 && TMath::Abs(fCalSmAddr) != iSmAddr)
2456 || fCalSmAddr == iSmAddr) // select detectors for determination of walk correction
2457 {
2458
2459 LOG(debug) << "WriteHistos: restore Offsets and Gains and update Walk for "
2460 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc << " with "
2461 << fDigiBdfPar->GetNbChan(iSmType, iRpc) << " channels";
2462 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++) {
2463 TH2* h2tmp0;
2464 TH2* h2tmp1;
2465 if (!fEnableAvWalk) {
2466 if (-1 < fCalSel) {
2467 h2tmp0 = fhTRpcCluWalk[iDetIndx][fCalSel][iCh][0];
2468 h2tmp1 = fhTRpcCluWalk[iDetIndx][fCalSel][iCh][1];
2469 }
2470 else { // take correction from deviation within clusters
2471 h2tmp0 = fhRpcCluWalk[iDetIndx][iCh][0];
2472 h2tmp1 = fhRpcCluWalk[iDetIndx][iCh][1];
2473 }
2474 }
2475 else { // go for averages (low statistics)
2476 if (-1 < fCalSel) {
2477 h2tmp0 = fhTRpcCluAvWalk[iDetIndx][fCalSel];
2478 h2tmp1 = fhTRpcCluAvWalk[iDetIndx][fCalSel];
2479 }
2480 else { // take correction from deviation within clusters
2481 h2tmp0 = fhRpcCluAvWalk[iDetIndx];
2482 h2tmp1 = fhRpcCluAvWalk[iDetIndx];
2483 }
2484 }
2485 if (NULL == h2tmp0) {
2486 LOG(debug) << Form("WriteHistos: Walk histo not available for "
2487 "SmT %d, Sm %d, Rpc %d, Ch %d",
2488 iSmType, iSm, iRpc, iCh);
2489 continue;
2490 }
2491 Int_t iNEntries = h2tmp0->GetEntries();
2492 if (iCh == 0) // condition to print message only once
2493 LOG(debug) << Form(" Update Walk correction for SmT %d, Sm %d, "
2494 "Rpc %d, Ch %d, Sel%d: Entries %d",
2495 iSmType, iSm, iRpc, iCh, fCalSel, iNEntries);
2496
2497 // h2tmp0->Write();
2498 // h2tmp1->Write();
2499 if (-1 < iNEntries) { // always done
2500 TProfile* htmp0 = h2tmp0->ProfileX("_pfx", 1, h2tmp0->GetNbinsY());
2501 TProfile* htmp1 = h2tmp1->ProfileX("_pfx", 1, h2tmp1->GetNbinsY());
2502 TH1D* h1tmp0 = h2tmp0->ProjectionX("_px", 1, h2tmp0->GetNbinsY());
2503 TH1D* h1tmp1 = h2tmp1->ProjectionX("_px", 1, h2tmp1->GetNbinsY());
2504 TH1D* h1ytmp0 = h2tmp0->ProjectionY("_py", 1, nbClWalkBinX); // preserve means
2505 TH1D* h1ytmp1 = h2tmp1->ProjectionY("_py", 1, nbClWalkBinX);
2506 Double_t dWMean0 = h1ytmp0->GetMean();
2507 Double_t dWMean1 = h1ytmp1->GetMean();
2508 Double_t dWMean = 0.5 * (dWMean0 + dWMean1);
2509 Int_t iWalkUpd = 2; // Walk update mode flag
2510 //if(5==iSmType || 8==iSmType || 2==iSmType) iWalkUpd=0; // keep both sides consistent for diamonds and pads
2511 if (5 == iSmType || 8 == iSmType)
2512 iWalkUpd = 0; // keep both sides consistent for diamonds and pads (Cern2016)
2513 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
2514 switch (iWalkUpd) {
2515 case 0:
2516 if (h1tmp0->GetBinContent(iWx + 1) > WalkNHmin && h1tmp1->GetBinContent(iWx + 1) > WalkNHmin) {
2517 // preserve y - position (difference) on average
2518 Double_t dWcor =
2519 (((TProfile*) htmp0)->GetBinContent(iWx + 1) + ((TProfile*) htmp1)->GetBinContent(iWx + 1))
2520 * 0.5;
2521 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] += dWcor - dWMean;
2522 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx] += dWcor - dWMean;
2523 }
2524 break;
2525 case 1:
2526 if (h1tmp0->GetBinContent(iWx + 1) > WalkNHmin && h1tmp1->GetBinContent(iWx + 1) > WalkNHmin) {
2527 Double_t dWcor0 = ((TProfile*) htmp0)->GetBinContent(iWx + 1) - dWMean0;
2528 Double_t dWcor1 = ((TProfile*) htmp1)->GetBinContent(iWx + 1) - dWMean1;
2529 Double_t dWcor = 0.5 * (dWcor0 + dWcor1);
2530 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] += dWcor; //-dWMean0;
2531 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx] += dWcor; //-dWMean1;
2532
2533 if (iCh == 10 && iSmType == 9 && iSm == 1 && h1tmp0->GetBinContent(iWx + 1) > WalkNHmin)
2534 LOG(debug) << "Update Walk Sm = " << iSm << "(" << iNbRpc << "), Rpc " << iRpc << ", Bin "
2535 << iWx << ", " << h1tmp0->GetBinContent(iWx + 1)
2536 << " cts: " << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] << " + "
2537 << ((TProfile*) htmp0)->GetBinContent(iWx + 1) << " - " << dWMean0 << " -> "
2538 << dWcor - dWMean0 << ", S1: " << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]
2539 << " + " << ((TProfile*) htmp1)->GetBinContent(iWx + 1) << " - " << dWMean1 << " -> "
2540 << dWcor - dWMean1;
2541 }
2542 break;
2543 case 2:
2544 if (h1tmp0->GetBinContent(iWx + 1) > WalkNHmin && h1tmp1->GetBinContent(iWx + 1) > WalkNHmin) {
2545 Double_t dWcor0 = ((TProfile*) htmp0)->GetBinContent(iWx + 1) - dWMean0;
2546 Double_t dWcor1 = ((TProfile*) htmp1)->GetBinContent(iWx + 1) - dWMean1;
2547 //Double_t dWcor = 0.5*(dWcor0 + dWcor1);
2548 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] += dWcor0;
2549 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx] += dWcor1;
2550 }
2551 break;
2552
2553 default:;
2554 }
2555 }
2556 h1tmp0->Reset();
2557 h1tmp1->Reset();
2558 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
2559 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
2560 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
2561 Int_t iTry = 3;
2562 while (iTry-- > 0
2563 && h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
2564 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
2565 }
2566 if (iTry == 0)
2567 LOG(error) << "writing not successful for " << h1tmp0->GetName() << ", attempts left: " << iTry
2568 << ", iWx " << iWx << ", got " << h1tmp0->GetBinContent(iWx + 1) << ", expected "
2569 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
2570 iTry = 3;
2571 while (iTry-- > 0
2572 && h1tmp1->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]) {
2573 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
2574 }
2575 if (iTry == 0)
2576 LOG(error) << "writing not successful for " << h1tmp1->GetName() << ", attempts left: " << iTry
2577 << ", iWx " << iWx << ", got " << h1tmp1->GetBinContent(iWx + 1) << ", expected "
2578 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx];
2579 }
2580
2581 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
2582 h1tmp0->Smooth(iNWalkSmooth);
2583 h1tmp0->Write();
2584 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
2585 h1tmp1->Smooth(iNWalkSmooth);
2586 h1tmp1->Write();
2587 }
2588 }
2589 }
2590 else { // preserve whatever is there for fCalSmAddr !
2591 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++) // restore old values
2592 {
2593 //TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
2594 //TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
2595 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
2596 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
2597 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
2598 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
2599 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
2600 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
2601 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
2602 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
2603 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
2604 }
2605 }
2606 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
2607 // htmp0->Write();
2608 h1tmp0->Write();
2609 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
2610 // htmp1->Write();
2611 h1tmp1->Write();
2612 }
2613 }
2614 } break;
2615
2616 case 2: //update time offsets from positions and times with Sm averages, save walks and DELTOF
2617 {
2618 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
2619 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
2620
2621 if ((fCalSmAddr < 0) || (fCalSmAddr != iSmAddr)) { // select detectors for updating offsets
2622 LOG(debug) << "WriteHistos: (case 2) update Offsets and keep Gains, "
2623 "Walk and DELTOF for "
2624 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc;
2625 Int_t iB = iSm * iNbRpc + iRpc;
2626 Double_t dVscal = 1.;
2627 if (NULL != fhSmCluSvel[iSmType]) dVscal = fhSmCluSvel[iSmType]->GetBinContent(iSm * iNbRpc + iRpc + 1);
2628 if (dVscal == 0.) dVscal = 1.;
2629
2630 Double_t YMean = ((TProfile*) hAvPos_pfx)->GetBinContent(iB + 1); //nh +1 empirical(?)
2631 htempPos_py = htempPos->ProjectionY(Form("%s_py", htempPos->GetName()), 1, iNbCh);
2632 if (htempPos_py->GetEntries() > fdYFitMin && fPosYMaxScal < 1.1) {
2633 LOG(debug1) << Form("Determine YMean in %s by fit to %d entries", htempPos->GetName(),
2634 (Int_t) htempPos_py->GetEntries());
2635 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, 0);
2636 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
2637 fChannelInfo = fDigiPar->GetCell(iChId);
2638 if (NULL == fChannelInfo) {
2639 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
2640 continue;
2641 }
2642 fit_ybox(htempPos_py, 0.5 * fChannelInfo->GetSizey());
2643 TF1* ff = htempPos_py->GetFunction("YBox");
2644 if (NULL != ff) {
2645 LOG(info) << "FRes YBox " << htempPos_py->GetEntries() << " entries in TSR " << iSmType << iSm << iRpc
2646 << ", chi2 " << ff->GetChisquare() / ff->GetNDF()
2647 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos "
2648 "res %5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
2649 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1), 2. * ff->GetParError(1),
2650 ff->GetParameter(2), ff->GetParError(2), ff->GetParameter(3), ff->GetParError(3));
2651
2652 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey() < 0.2
2653 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.2)
2654 // && ff->GetChisquare() < 500.) //FIXME - constants!
2655 {
2656 if (TMath::Abs(ff->GetParameter(3) - YMean) < 0.5 * fChannelInfo->GetSizey()) {
2657 YMean = ff->GetParameter(3);
2658 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
2659 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV);
2660 }
2661 }
2662 }
2663 }
2664
2665 Double_t TMean = ((TProfile*) hAvTOff_pfx)->GetBinContent(iB + 1);
2666 Double_t TWidth = ((TProfile*) hAvTOff_pfx)->GetBinError(iB + 1);
2667 Double_t dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
2668
2669
2670 if (fiBeamRefType == iSmType && fiBeamRefSm == iSm && fiBeamRefDet == iRpc)
2671 TMean = 0.; // don't shift reference counter
2672
2673 LOG(debug) << Form("<ICor> Correct %d %d %d by TMean=%8.2f, "
2674 "TYOff=%8.2f, TWidth=%8.2f, ",
2675 iSmType, iSm, iRpc, TMean, dTYOff, TWidth);
2676
2677
2678 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // update Offset and Gain
2679 {
2680 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
2681 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
2682
2683 LOG(debug) << "FillCalHist:"
2684 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh << ": YMean " << YMean
2685 << ", TMean " << TMean << " -> "
2686 << Form(" %f, %f, %f, %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
2687 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
2688 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
2689 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
2690 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
2691 }
2692 htempPos_pfx->Reset(); //reset to store new values
2693 htempTOff_pfx->Reset();
2694 htempTot_Mean->Reset();
2695 htempTot_Off->Reset();
2696 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
2697 {
2698 Double_t YMean =
2699 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
2700 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
2701 Double_t TMean =
2702 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
2703 htempPos_pfx->Fill(iCh, YMean);
2704 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
2705 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got " << htempPos_pfx->GetBinContent(iCh)
2706 << "," << htempPos_pfx->GetBinContent(iCh + 1) << "," << htempPos_pfx->GetBinContent(iCh + 2)
2707 << ", expected " << YMean;
2708 }
2709 htempTOff_pfx->Fill(iCh, TMean);
2710
2711 for (Int_t iSide = 0; iSide < 2; iSide++) {
2712 htempTot_Mean->SetBinContent(
2713 iCh * 2 + 1 + iSide,
2714 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]); //nh +1 empirical(?)
2715 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
2716 }
2717 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
2718
2719 LOG(debug1) << " Updating done ... write to file ";
2720 htempPos_pfx->Write();
2721 htempTOff_pfx->Write();
2722 // htempTot_pfx->Write();
2723 htempTot_Mean->Write();
2724 htempTot_Off->Write();
2725
2726 // store old DELTOF histos
2727 LOG(debug) << " Copy old DelTof histos from " << gDirectory->GetName() << " to file ";
2728
2729 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
2730 // Store DelTof corrections
2731 TDirectory* curdir = gDirectory;
2732 gROOT->cd(); //
2733 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
2734 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
2735 gDirectory->cd(curdir->GetPath());
2736 if (NULL != hCorDelTof) {
2737 TH1D* hCorDelTofout =
2738 (TH1D*) hCorDelTof->Clone(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
2739 hCorDelTofout->Write();
2740 }
2741 else {
2742 LOG(debug) << " No CorDelTof histo "
2743 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
2744 }
2745 }
2746
2747 // store walk histos
2748 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
2749 {
2750 //TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
2751 //TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
2752 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
2753 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
2754 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
2755 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
2756 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
2757 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
2758 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
2759 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
2760 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
2761 }
2762 }
2763 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
2764 // htmp0->Write();
2765 h1tmp0->Write();
2766 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
2767 // htmp1->Write();
2768 h1tmp1->Write();
2769 }
2770 } break;
2771
2772 case 3: //update offsets, gains, save walks and DELTOF
2773 {
2774 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
2775 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
2776 if ((fCalSmAddr < 0) || (fCalSmAddr != iSmAddr)) { // select detectors for updating offsets
2777 LOG(info) << "WriteHistos (calMode==3): update Offsets and Gains, "
2778 "keep Walk and DelTof for "
2779 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc << " with " << iNbCh << " channels "
2780 << " using selector " << fCalSel;
2781 /*
2782 Double_t dTRefMean=0.;
2783 if (5 == iSmType && fTRefMode%10 == iSm){ // reference counter
2784 dTRefMean=htempTOff->GetMean(2);
2785 }
2786 */
2787 Double_t dVscal = 1.;
2788 Double_t dVW = 1.;
2789 if (0) // NULL != fhSmCluSvel[iSmType])
2790 {
2791 dVscal = fhSmCluSvel[iSmType]->GetBinContent(iSm * iNbRpc + iRpc + 1);
2792 if (dVscal == 0.) dVscal = 1.;
2793 dVW = fhSmCluSvel[iSmType]->GetBinEffectiveEntries(iSm * iNbRpc + iRpc + 1);
2794 dVW *= 50.; //(Double_t)iNbCh;
2795 if (dVW < 0.1) dVW = 0.1;
2796 }
2797
2798 // determine average values
2799 htempPos_py = htempPos->ProjectionY(Form("%s_py", htempPos->GetName()), 1, iNbCh);
2800 Double_t dYMeanAv = 0.;
2801 Double_t dYMeanFit = 0.;
2802 if (htempPos_py->GetEntries() > fdYFitMin && fPosYMaxScal < 1.1) {
2803 dYMeanAv = htempPos_py->GetMean();
2804 LOG(debug1) << Form("Determine YMeanAv in %s by fit to %d entries", htempPos->GetName(),
2805 (Int_t) htempPos_py->GetEntries());
2806 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, 0);
2807 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
2808 fChannelInfo = fDigiPar->GetCell(iChId);
2809 if (NULL == fChannelInfo) {
2810 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
2811 continue;
2812 }
2813 fit_ybox(htempPos_py, 0.5 * fChannelInfo->GetSizey());
2814 TF1* ff = htempPos_py->GetFunction("YBox");
2815 if (NULL != ff) {
2816 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey() < 0.2
2817 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.2) {
2818 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
2819 LOG(info) << "FAvRes YBox " << htempPos_py->GetEntries() << " entries in TSR " << iSmType << iSm << iRpc
2820 << ", stat: " << gMinuit->fCstatu << ", chi2 " << ff->GetChisquare() / ff->GetNDF()
2821 << Form(", striplen (%5.2f): %7.2f+/-%5.2f, pos res "
2822 "%5.2f+/-%5.2f at y_cen = %5.2f+/-%5.2f",
2823 fChannelInfo->GetSizey(), 2. * ff->GetParameter(1), 2. * ff->GetParError(1),
2824 ff->GetParameter(2), ff->GetParError(2), ff->GetParameter(3), ff->GetParError(3));
2825 if (TMath::Abs(ff->GetParameter(3) - dYMeanAv) < 0.5 * fChannelInfo->GetSizey()) {
2826 dYMeanFit = ff->GetParameter(3);
2827 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV, dVW);
2828 for (Int_t iPar = 0; iPar < 4; iPar++)
2829 fhSmCluFpar[iSmType][iPar]->Fill((Double_t)(iSm * iNbRpc + iRpc), ff->GetParameter(2 + iPar));
2830 }
2831 }
2832 else {
2833 LOG(info) << "FAvBad YBox " << htempPos_py->GetEntries() << " entries in " << iSmType << iSm << iRpc
2834 << ", chi2 " << ff->GetChisquare()
2835
2836 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos res "
2837 "%5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
2838 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1), 2. * ff->GetParError(1),
2839 ff->GetParameter(2), ff->GetParError(2), ff->GetParameter(3), ff->GetParError(3));
2840 }
2841 }
2842 else {
2843 LOG(info) << "FAvFailed for TSR " << iSmType << iSm << iRpc;
2844 }
2845 }
2846 Double_t dYShift = dYMeanFit - dYMeanAv;
2847
2848 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // update Offset and Gain
2849 {
2850 Double_t YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1); //set default
2851 YMean += dYShift;
2852
2853 htempPos_py = htempPos->ProjectionY(Form("%s_py%02d", htempPos->GetName(), iCh), iCh + 1, iCh + 1);
2854 if (htempPos_py->GetEntries() > fdYFitMin && fPosYMaxScal < -1.1) { //disabled
2855 LOG(debug1) << Form("Determine YMean in %s of channel %d by fit to %d entries", htempPos->GetName(), iCh,
2856 (Int_t) htempPos_py->GetEntries());
2857 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
2858 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
2859 fChannelInfo = fDigiPar->GetCell(iChId);
2860 if (NULL == fChannelInfo) {
2861 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
2862 continue;
2863 }
2864 Double_t fp[4] = {1., 3 * 0.}; // initialize fit parameter
2865 for (Int_t iPar = 2; iPar < 4; iPar++)
2866 if (NULL != fhSmCluFpar[iSmType][iPar])
2867 fp[iPar] = fhSmCluFpar[iSmType][iPar]->GetBinContent(iSm * iNbRpc + iRpc + 1);
2868 //LOG(info) << Form("Call yFit with %6.3f, %6.3f, %6.3f, %6.3f",fp[0],fp[1],fp[2],fp[3])
2869 // ;
2870 Double_t* fpp = &fp[0];
2871 fit_ybox(htempPos_py, 0.5 * fChannelInfo->GetSizey(), fpp);
2872 TF1* ff = htempPos_py->GetFunction("YBox");
2873 if (NULL != ff) {
2874 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey() < 0.1
2875 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.05)
2876 //&& ff->GetChisquare() < 200.) //FIXME - constants!
2877 {
2878 if (TMath::Abs(ff->GetParameter(3) - YMean) < 0.5 * fChannelInfo->GetSizey()) {
2879 YMean = ff->GetParameter(3);
2880 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
2881 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV, dVW);
2882 LOG(info) << "FRes YBox " << htempPos_py->GetEntries() << " entries in " << iSmType << iSm << iRpc
2883 << iCh << ", chi2 " << ff->GetChisquare()
2884 << Form(", striplen (%5.2f), %4.2f -> %4.2f, "
2885 "%4.1f: %7.2f+/-%5.2f, pos res "
2886 "%5.2f+/-%5.2f at y_cen = %5.2f+/-%5.2f",
2887 fChannelInfo->GetSizey(), dVscal, dV, dVW, 2. * ff->GetParameter(1),
2888 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2),
2889 ff->GetParameter(3), ff->GetParError(3));
2890 for (Int_t iPar = 0; iPar < 4; iPar++)
2891 fhSmCluFpar[iSmType][iPar]->Fill((Double_t)(iSm * iNbRpc + iRpc), ff->GetParameter(2 + iPar));
2892 }
2893 }
2894 else {
2895 //YMean=0.; // no new info available - did not help!
2896 LOG(info) << "FBad YBox " << htempPos_py->GetEntries() << " entries in " << iSmType << iSm << iRpc
2897 << iCh << ", chi2 " << ff->GetChisquare()
2898 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos "
2899 "res %5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
2900 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1), 2. * ff->GetParError(1),
2901 ff->GetParameter(2), ff->GetParError(2), ff->GetParameter(3), ff->GetParError(3));
2902 }
2903 }
2904 }
2905
2906 Double_t TMean = ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1);
2907 Double_t dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
2908
2909 if (fiBeamRefType == iSmType && fiBeamRefSm == iSm && fiBeamRefDet == iRpc) {
2910 // don't shift reference counter on average
2911 TMean -= ((TProfile*) hAvTOff_pfx)->GetBinContent(iSm * iNbRpc + iRpc + 1);
2912 }
2913
2914 if (htempTOff_px->GetBinContent(iCh + 1) > WalkNHmin) {
2915 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
2916 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
2917 LOG(debug) << Form("Calib: TSRC %d%d%d%d, hits %6.0f, dTY %8.3f, TM %8.3f -> new "
2918 "Off %8.3f,%8.3f ",
2919 iSmType, iSm, iRpc, iCh, htempTOff_px->GetBinContent(iCh + 1), dTYOff, TMean,
2920 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
2921 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
2922 }
2923 /*
2924 Double_t TotMean=((TProfile *)htempTot_pfx)->GetBinContent(iCh+1); //nh +1 empirical(!)
2925 if(0.001 < TotMean){
2926 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][0] *= fdTTotMean / TotMean;
2927 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1] *= fdTTotMean / TotMean;
2928 }
2929 */
2930 for (Int_t iSide = 0; iSide < 2; iSide++) {
2931 Int_t ib = iCh * 2 + 1 + iSide;
2932 TH1* hbin = htempTot->ProjectionY(Form("bin%d", ib), ib, ib);
2933 if (100 > hbin->GetEntries()) continue; //request min number of entries
2934 /* Double_t Ymax=hbin->GetMaximum();*/
2935 Int_t iBmax = hbin->GetMaximumBin();
2936 TAxis* xaxis = hbin->GetXaxis();
2937 Double_t Xmax = xaxis->GetBinCenter(iBmax) / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide];
2938 Double_t XOff = Xmax - fTotPreRange;
2939 if (0) { //TMath::Abs(XOff - fvCPTotOff[iSmType][iSm*iNbRpc+iRpc][iCh][iSide])>100){
2940 LOG(warning) << "XOff changed for "
2941 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: XOff %f, old %f", iSmType, iSm, iRpc, iSide, XOff,
2942 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
2943 }
2944 // Double_t TotMean=htempTot_Mean->GetBinContent(ib);
2945 Double_t TotMean = hbin->GetMean();
2946 if (15 == iSmType) {
2947 LOG(warning) << "Gain for "
2948 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: TotMean %f, prof %f, "
2949 "gain %f, modg %f ",
2950 iSmType, iSm, iRpc, iSide, TotMean, htempTot_Mean->GetBinContent(ib),
2951 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide], fdTTotMean / TotMean);
2952 }
2953 if (0.001 < TotMean) {
2954 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] *= fdTTotMean / TotMean;
2955 }
2956 }
2957 if (5 == iSmType
2958 && fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]
2959 != fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]) { // diamond
2960 LOG(warning) << "CbmTofTestBeamClusterizer::FillCalHist:"
2961 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh << ": YMean "
2962 << YMean << ", TMean " << TMean << " -> "
2963 << Form(" %f %f %f %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
2964 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
2965 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
2966 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
2967 Double_t dTOff =
2968 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
2969 Double_t dGain = 0.5
2970 * (fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0]
2971 + fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
2972 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dTOff;
2973 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dTOff;
2974 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dGain;
2975 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dGain;
2976 } // diamond warning end
2977 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
2978 } // iSmType selection condition
2979
2980 htempPos_pfx->Reset(); //reset to store new values
2981 htempTOff_pfx->Reset();
2982 htempTot_Mean->Reset();
2983 htempTot_Off->Reset();
2984 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
2985 {
2986 Double_t YMean =
2987 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
2988 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
2989 Double_t TMean =
2990 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
2991 htempPos_pfx->Fill(iCh, YMean);
2992 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
2993 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got " << htempPos_pfx->GetBinContent(iCh)
2994 << "," << htempPos_pfx->GetBinContent(iCh + 1) << "," << htempPos_pfx->GetBinContent(iCh + 2)
2995 << ", expected " << YMean;
2996 }
2997 htempTOff_pfx->Fill(iCh, TMean);
2998
2999 for (Int_t iSide = 0; iSide < 2; iSide++) {
3000 htempTot_Mean->SetBinContent(iCh * 2 + 1 + iSide,
3001 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3002 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3003 }
3004 // htempTot_pfx->Fill(iCh,fdTTotMean/fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1]);
3005 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
3006
3007
3008 LOG(debug1) << " Updating done ... write to file ";
3009 htempPos_pfx->Write();
3010 htempTOff_pfx->Write();
3011 // htempTot_pfx->Write();
3012 htempTot_Mean->Write();
3013 htempTot_Off->Write();
3014
3015 // store old DELTOF histos
3016 LOG(debug) << " Copy old DelTof histos from " << gDirectory->GetName() << " to file ";
3017
3018 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3019 // Store DelTof corrections
3020 TDirectory* curdir = gDirectory;
3021 gROOT->cd(); //
3022 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
3023 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3024 gDirectory->cd(curdir->GetPath());
3025 if (NULL != hCorDelTof) {
3026 TH1D* hCorDelTofout =
3027 (TH1D*) hCorDelTof->Clone(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3028 hCorDelTofout->Write();
3029 }
3030 else {
3031 LOG(debug) << " No CorDelTof histo "
3032 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
3033 }
3034 }
3035
3036 LOG(debug) << " Store old walk histos to file ";
3037 // store walk histos
3038 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // restore old values
3039 {
3040 if (NULL == fhRpcCluWalk[iDetIndx][iCh][0]) break;
3041 //TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3042 //TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3043 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
3044 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
3045 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
3046 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3047 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
3048 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
3049 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
3050 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
3051 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
3052 }
3053 }
3054 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
3055 // htmp0->Write();
3056 h1tmp0->Write();
3057 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
3058 // htmp1->Write();
3059 h1tmp1->Write();
3060 }
3061 } break;
3062 case 4: //update DelTof, save offsets, gains and walks
3063 {
3064 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3065 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
3066 LOG(debug) << "WriteHistos: restore Offsets, Gains and Walk, save DelTof for "
3067 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc;
3068 htempPos_pfx->Reset(); //reset to restore mean of original histos
3069 htempTOff_pfx->Reset();
3070 htempTot_Mean->Reset();
3071 htempTot_Off->Reset();
3072 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
3073 Double_t YMean =
3074 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
3075 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3076 Double_t TMean =
3077 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3078 htempPos_pfx->Fill(iCh, YMean);
3079 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
3080 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got " << htempPos_pfx->GetBinContent(iCh)
3081 << "," << htempPos_pfx->GetBinContent(iCh + 1) << "," << htempPos_pfx->GetBinContent(iCh + 2)
3082 << ", expected " << YMean;
3083 }
3084 htempTOff_pfx->Fill(iCh, TMean);
3085
3086 for (Int_t iSide = 0; iSide < 2; iSide++) {
3087 htempTot_Mean->SetBinContent(
3088 iCh * 2 + 1 + iSide,
3089 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]); //nh +1 empirical(?)
3090 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3091 }
3092 }
3093
3094 LOG(debug1) << " Restoring of Offsets and Gains done ... ";
3095 htempPos_pfx->Write();
3096 htempTOff_pfx->Write();
3097 // htempTot_pfx->Write();
3098 htempTot_Mean->Write();
3099 htempTot_Off->Write();
3100
3101 // restore walk histos
3102 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // restore old values
3103 {
3104 if (NULL == fhRpcCluWalk[iDetIndx][iCh][0]) break;
3105 //TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3106 //TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3107 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
3108 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
3109 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
3110 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3111 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
3112 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
3113 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
3114 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
3115 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
3116 }
3117 }
3118 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
3119 // htmp0->Write();
3120 h1tmp0->Write();
3121 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
3122 // htmp1->Write();
3123 h1tmp1->Write();
3124 }
3125
3126 // generate/update DelTof corrections
3127 if ((fCalSmAddr < 0 && -fCalSmAddr != iSmAddr)
3128 || (fCalSmAddr == iSmAddr)) // select detectors for determination of DelTof correction
3129 {
3130 // if( fiBeamRefType == iSmType ) continue; // no DelTof correction for Diamonds
3131
3132 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3133 TH2* h2tmp = fhTRpcCluDelTof[iDetIndx][iSel];
3134 if (NULL == h2tmp) {
3135 LOG(debug) << Form("WriteHistos: histo not available for SmT %d, Sm %d, Rpc %d", iSmType, iSm, iRpc);
3136 break;
3137 }
3138 Int_t iNEntries = h2tmp->GetEntries();
3139
3140 // h2tmp->Write();
3141 TProfile* htmp = h2tmp->ProfileX("_pfx", 1, h2tmp->GetNbinsY());
3142 TH1D* h1tmp = h2tmp->ProjectionX("_px", 1, h2tmp->GetNbinsY());
3143 /* TH1D *h1ytmp = h2tmp->ProjectionY("_py",1,h2tmp->GetNbinsX());*/
3144 Double_t dDelMean =
3145 0.; //h1ytmp->GetMean();// inspect normalization, interferes with mode 3 for diamonds, nh, 10.01.2015 (?)
3146 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
3147 Double_t dNEntries = h1tmp->GetBinContent(iBx + 1);
3148 if (dNEntries > WalkNHmin) // modify, request sufficient # of entries
3149 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] += ((TProfile*) htmp)->GetBinContent(iBx + 1);
3150 dDelMean += fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel];
3151 }
3152 dDelMean /= (Double_t) nbClDelTofBinX;
3153
3154 LOG(debug) << Form(" Update DelTof correction for SmT %d, Sm %d, "
3155 "Rpc %d, Sel%d: Entries %d, Mean shift %6.1f",
3156 iSmType, iSm, iRpc, iSel, iNEntries, dDelMean);
3157
3158 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
3159 //h1tmp->SetBinContent(iBx+1,fvCPDelTof[iSmType][iSm*iNbRpc+iRpc][iBx][iSel]-dDelMean);
3160 h1tmp->SetBinContent(iBx + 1, fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel]);
3161 }
3162 h1tmp->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3163 h1tmp->Write();
3164 }
3165 }
3166 else { // copy existing histograms
3167 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3168 // Store DelTof corrections
3169 TDirectory* curdir = gDirectory;
3170 gROOT->cd(); //
3171 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
3172 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3173 gDirectory->cd(curdir->GetPath());
3174 if (NULL != hCorDelTof) {
3175 TH1D* hCorDelTofout = (TH1D*) hCorDelTof->Clone(
3176 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3177 LOG(debug) << " Save existing CorDelTof histo "
3178 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
3179 hCorDelTofout->Write();
3180 }
3181 else {
3182 LOG(debug) << " No CorDelTof histo "
3183 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
3184 }
3185 }
3186 }
3187 } break;
3188 case 5: //update offsets (from positions only), gains, save walks and DELTOF
3189 {
3190 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3191 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
3192 if ((fCalSmAddr < 0) || (fCalSmAddr != iSmAddr)) { // select detectors for updating offsets
3193 LOG(info) << "WriteHistos (calMode==3): update Offsets and Gains, "
3194 "keep Walk and DelTof for "
3195 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc << " with " << iNbCh << " channels "
3196 << " using selector " << fCalSel;
3197
3198 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // update Offset and Gain
3199 {
3200 Double_t YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1); //nh +1 empirical(?)
3201 Double_t TMean = 0.;
3202 Double_t dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
3203
3204
3205 if (htempTOff_px->GetBinContent(iCh + 1) > WalkNHmin) {
3206 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
3207 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
3208 }
3209 LOG(debug3) << Form("Calib: TSRC %d%d%d%d, hits %6.0f, new Off %8.0f,%8.0f ", iSmType, iSm, iRpc, iCh,
3210 htempTOff_px->GetBinContent(iCh + 1), fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
3211 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
3212
3213 /*
3214 Double_t TotMean=((TProfile *)htempTot_pfx)->GetBinContent(iCh+1); //nh +1 empirical(!)
3215 if(0.001 < TotMean){
3216 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][0] *= fdTTotMean / TotMean;
3217 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1] *= fdTTotMean / TotMean;
3218 }
3219 */
3220 for (Int_t iSide = 0; iSide < 2; iSide++) {
3221 Int_t ib = iCh * 2 + 1 + iSide;
3222 TH1* hbin = htempTot->ProjectionY(Form("bin%d", ib), ib, ib);
3223 if (100 > hbin->GetEntries()) continue; //request min number of entries
3224 /* Double_t Ymax=hbin->GetMaximum();*/
3225 Int_t iBmax = hbin->GetMaximumBin();
3226 TAxis* xaxis = hbin->GetXaxis();
3227 Double_t Xmax = xaxis->GetBinCenter(iBmax) / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide];
3228 Double_t XOff = Xmax - fTotPreRange;
3229 if (0) { //TMath::Abs(XOff - fvCPTotOff[iSmType][iSm*iNbRpc+iRpc][iCh][iSide])>100){
3230 LOG(warning) << "XOff changed for "
3231 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: XOff %f, old %f", iSmType, iSm, iRpc, iSide, XOff,
3232 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3233 }
3234 // Double_t TotMean=htempTot_Mean->GetBinContent(ib);
3235 Double_t TotMean = hbin->GetMean();
3236 if (15 == iSmType) {
3237 LOG(warning) << "Gain for "
3238 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: TotMean %f, prof %f, "
3239 "gain %f, modg %f ",
3240 iSmType, iSm, iRpc, iSide, TotMean, htempTot_Mean->GetBinContent(ib),
3241 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide], fdTTotMean / TotMean);
3242 }
3243 if (0.001 < TotMean) {
3244 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] *= fdTTotMean / TotMean;
3245 }
3246 }
3247 if (5 == iSmType
3248 && fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]
3249 != fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]) { // diamond
3250 LOG(warning) << "CbmTofTestBeamClusterizer::FillCalHist:"
3251 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh << ": YMean "
3252 << YMean << ", TMean " << TMean << " -> "
3253 << Form(" %f %f %f %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
3254 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
3255 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
3256 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
3257 Double_t dTOff =
3258 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
3259 Double_t dGain = 0.5
3260 * (fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0]
3261 + fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
3262 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dTOff;
3263 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dTOff;
3264 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dGain;
3265 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dGain;
3266 } // diamond warning end
3267 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
3268 } // iSmType selection condition
3269
3270 htempPos_pfx->Reset(); //reset to store new values
3271 htempTOff_pfx->Reset();
3272 htempTot_Mean->Reset();
3273 htempTot_Off->Reset();
3274 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
3275 {
3276 Double_t YMean =
3277 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
3278 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3279 Double_t TMean =
3280 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3281 htempPos_pfx->Fill(iCh, YMean);
3282 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
3283 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got " << htempPos_pfx->GetBinContent(iCh)
3284 << "," << htempPos_pfx->GetBinContent(iCh + 1) << "," << htempPos_pfx->GetBinContent(iCh + 2)
3285 << ", expected " << YMean;
3286 }
3287 htempTOff_pfx->Fill(iCh, TMean);
3288
3289 for (Int_t iSide = 0; iSide < 2; iSide++) {
3290 htempTot_Mean->SetBinContent(iCh * 2 + 1 + iSide,
3291 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3292 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3293 }
3294 // htempTot_pfx->Fill(iCh,fdTTotMean/fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1]);
3295 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
3296
3297
3298 LOG(debug1) << " Updating done ... write to file ";
3299 htempPos_pfx->Write();
3300 htempTOff_pfx->Write();
3301 // htempTot_pfx->Write();
3302 htempTot_Mean->Write();
3303 htempTot_Off->Write();
3304
3305 // store old DELTOF histos
3306 LOG(debug) << " Copy old DelTof histos from " << gDirectory->GetName() << " to file ";
3307
3308 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3309 // Store DelTof corrections
3310 TDirectory* curdir = gDirectory;
3311 gROOT->cd(); //
3312 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
3313 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3314 gDirectory->cd(curdir->GetPath());
3315 if (NULL != hCorDelTof) {
3316 TH1D* hCorDelTofout =
3317 (TH1D*) hCorDelTof->Clone(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3318 hCorDelTofout->Write();
3319 }
3320 else {
3321 LOG(debug) << " No CorDelTof histo "
3322 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
3323 }
3324 }
3325
3326 LOG(debug) << " Store old walk histos to file ";
3327 // store walk histos
3328 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // restore old values
3329 {
3330 if (NULL == fhRpcCluWalk[iDetIndx][iCh][0]) break;
3331 //TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3332 //TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3333 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
3334 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
3335 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
3336 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3337 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
3338 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
3339 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
3340 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
3341 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
3342 }
3343 }
3344 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
3345 // htmp0->Write();
3346 h1tmp0->Write();
3347 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
3348 // htmp1->Write();
3349 h1tmp1->Write();
3350 }
3351 } break;
3352
3353
3354 default: LOG(debug) << "WriteHistos: update mode " << fCalMode << " not yet implemented";
3355 }
3356 }
3357
3358 // fhCluMulCorDutSel->Write();
3359
3360 // fhDigSpacDifClust->Write();
3361 // fhDigTimeDifClust->Write();
3362 // fhDigDistClust->Write();
3363
3364 // fhClustSizeDifX->Write();
3365 // fhClustSizeDifY->Write();
3366
3367 // fhChDifDifX->Write();
3368 // fhChDifDifY->Write();
3369
3370 // fhNbSameSide->Write();
3371 // fhNbDigiPerChan->Write();
3372
3373
3374 // fhHitsPerTracks->Write();
3375 if (kFALSE == fDigiBdfPar->ClustUseTrackId())
3376 // fhPtsPerHit->Write();
3377 // fhTimeResSingHits->Write();
3378 // fhTimeResSingHitsB->Write();
3379 // fhTimePtVsHits->Write();
3380 // fhClusterSize->Write();
3381 // fhClusterSizeType->Write();
3382 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
3383 // fhTrackMul->Write();
3384 // fhClusterSizeMulti->Write();
3385 // fhTrk1MulPos->Write();
3386 // fhHiTrkMulPos->Write();
3387 // fhAllTrkMulPos->Write();
3388 // fhMultiTrkProbPos->Divide( fhHiTrkMulPos, fhAllTrkMulPos);
3389 // fhMultiTrkProbPos->Scale( 100.0 );
3390 // fhMultiTrkProbPos->Write();
3391 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
3392
3393 for (Int_t iS = 0; iS < fDigiBdfPar->GetNbSmTypes(); iS++) {
3394 if (NULL == fhSmCluPosition[iS]) continue;
3395 // fhSmCluPosition[iS]->Write();
3396 // fhSmCluTOff[iS]->Write();
3397 fhSmCluSvel[iS]->Write();
3398 for (Int_t iPar = 0; iPar < 4; iPar++)
3399 fhSmCluFpar[iS][iPar]->Write();
3400
3401 for (Int_t iSel = 0; iSel < iNSel; iSel++) { // Loop over selectors
3402 // fhTSmCluPosition[iS][iSel]->Write();
3403 // fhTSmCluTOff[iS][iSel]->Write();
3404 // fhTSmCluTRun[iS][iSel]->Write();
3405 }
3406 }
3407
3409 gFile = oldFile;
3410 gDirectory = oldDir;
3411
3412 fHist->Close();
3413
3414 return kTRUE;
3415}
3417{
3418 delete fhClustBuildTime;
3419 delete fhHitsPerTracks;
3420 delete fhPtsPerHit;
3421 delete fhTimeResSingHits;
3422 delete fhTimeResSingHitsB;
3423 delete fhTimePtVsHits;
3424 delete fhClusterSize;
3425 delete fhClusterSizeType;
3426
3427 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
3428 delete fhTrackMul;
3429 delete fhClusterSizeMulti;
3430 delete fhTrk1MulPos;
3431 delete fhHiTrkMulPos;
3432 delete fhAllTrkMulPos;
3433 delete fhMultiTrkProbPos;
3434 }
3435 delete fhDigSpacDifClust;
3436 delete fhDigTimeDifClust;
3437 delete fhDigDistClust;
3438
3439 delete fhClustSizeDifX;
3440 delete fhClustSizeDifY;
3441
3442 delete fhChDifDifX;
3443 delete fhChDifDifY;
3444
3445 delete fhNbSameSide;
3446 delete fhNbDigiPerChan;
3447
3448 return kTRUE;
3449}
3450/************************************************************************************/
3452{
3453 /*
3454 * FIXME: maybe use the 2D distance (X/Y) as criteria instead of the distance long channel
3455 * direction
3456 */
3457 Int_t iMess = 0;
3458 //gGeoManager->SetTopVolume( gGeoManager->FindVolumeFast("tof_v14a") );
3459 gGeoManager->CdTop();
3460
3461 if (NULL == fTofDigisColl) {
3462 LOG(info) << " No CalDigis defined ! Check! ";
3463 return kFALSE;
3464 }
3465 fiNevtBuild++;
3466 LOG(debug) << "CbmTofTestBeamClusterizer::BuildClusters from " << fTofDigisColl->GetEntriesFast()
3467 << " digis in event " << fiNevtBuild;
3468
3469 fTRefHits = 0.;
3470
3471 Int_t iNbTofDigi = fTofDigisColl->GetEntriesFast();
3472 if (kTRUE) {
3473 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
3474 CbmTofDigi* pDigi = (CbmTofDigi*) fTofDigisColl->At(iDigInd);
3475 LOG(debug1) << iDigInd << " " << pDigi << Form(" Address : 0x%08x ", pDigi->GetAddress()) << " SmT "
3476 << pDigi->GetType() << " Sm " << pDigi->GetSm() << " Rpc " << pDigi->GetRpc() << " Ch "
3477 << pDigi->GetChannel() << " S " << pDigi->GetSide() << " : " << pDigi->ToString()
3478 // <<" Time "<<pDigi->GetTime()
3479 // <<" Tot " <<pDigi->GetTot()
3480 ;
3481
3482 Int_t iDetIndx = fDigiBdfPar->GetDetInd(pDigi->GetAddress());
3483
3484 if (fDigiBdfPar->GetNbDet() - 1 < iDetIndx || iDetIndx < 0) {
3485 LOG(debug) << Form(" Wrong DetIndx %d >< %d,0 ", iDetIndx, fDigiBdfPar->GetNbDet());
3486 break;
3487 }
3488
3489 if (NULL == fhRpcDigiCor[iDetIndx]) {
3490 if (100 < iMess++)
3491 LOG(warning) << Form(" DigiCor Histo for DetIndx %d derived from 0x%08x not found", iDetIndx,
3492 pDigi->GetAddress());
3493 continue;
3494 }
3495
3496 Double_t dTDifMin = dDoubleMax;
3497 CbmTofDigi* pDigi2Min = NULL;
3498 // for (Int_t iDigI2 =iDigInd+1; iDigI2<iNbTofDigi;iDigI2++){
3499 for (Int_t iDigI2 = 0; iDigI2 < iNbTofDigi; iDigI2++) {
3500 CbmTofDigi* pDigi2 = (CbmTofDigi*) fTofDigisColl->At(iDigI2);
3501 if (iDetIndx == fDigiBdfPar->GetDetInd(pDigi2->GetAddress())) {
3502 if (0. == pDigi->GetSide() && 1. == pDigi2->GetSide()) {
3503 fhRpcDigiCor[iDetIndx]->Fill(pDigi->GetChannel(), pDigi2->GetChannel());
3504 }
3505 else {
3506 if (1. == pDigi->GetSide() && 0. == pDigi2->GetSide()) {
3507 fhRpcDigiCor[iDetIndx]->Fill(pDigi2->GetChannel(), pDigi->GetChannel());
3508 }
3509 }
3510 if (pDigi->GetSide() != pDigi2->GetSide()) {
3511 if (pDigi->GetChannel() == pDigi2->GetChannel()) {
3512 Double_t dTDif = TMath::Abs(pDigi->GetTime() - pDigi2->GetTime());
3513 if (dTDif < dTDifMin) {
3514 dTDifMin = dTDif;
3515 pDigi2Min = pDigi2;
3516 }
3517 }
3518 else if (TMath::Abs(pDigi->GetChannel() - pDigi2->GetChannel())
3519 == 1) { // opposite side missing, neighbouring channel has hit on opposite side // FIXME
3520 // check that same side digi of neighbouring channel is absent
3521 Int_t iDigI3 = 0;
3522 for (; iDigI3 < iNbTofDigi; iDigI3++) {
3523 CbmTofDigi* pDigi3 = (CbmTofDigi*) fTofDigisColl->At(iDigI3);
3524 if (pDigi3->GetSide() == pDigi->GetSide() && pDigi2->GetChannel() == pDigi3->GetChannel()) break;
3525 }
3526 if (iDigI3 == iNbTofDigi) // same side neighbour did not fire
3527 {
3528 Int_t iCorMode = 2; // Missing hit correction mode
3529 switch (iCorMode) {
3530 case 0: // no action
3531 break;
3532 case 1: // shift found hit
3533 LOG(debug2) << Form("shift channel %d%d%d%d%d and ", (Int_t) pDigi->GetType(),
3534 (Int_t) pDigi->GetSm(), (Int_t) pDigi->GetRpc(), (Int_t) pDigi->GetChannel(),
3535 (Int_t) pDigi->GetSide())
3536 << Form(" %d%d%d%d%d ", (Int_t) pDigi2->GetType(), (Int_t) pDigi2->GetSm(),
3537 (Int_t) pDigi2->GetRpc(), (Int_t) pDigi2->GetChannel(),
3538 (Int_t) pDigi2->GetSide());
3539 //if(pDigi->GetTime() < pDigi2->GetTime())
3540 if (pDigi->GetSide() == 0)
3541 pDigi2->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi->GetChannel(), 1 - pDigi->GetSide(),
3542 pDigi->GetType());
3543 else
3544 pDigi->SetAddress(pDigi2->GetSm(), pDigi2->GetRpc(), pDigi2->GetChannel(), 1 - pDigi2->GetSide(),
3545 pDigi2->GetType());
3546
3547 LOG(debug2) << Form("resultchannel %d%d%d%d%d and ", (Int_t) pDigi->GetType(),
3548 (Int_t) pDigi->GetSm(), (Int_t) pDigi->GetRpc(), (Int_t) pDigi->GetChannel(),
3549 (Int_t) pDigi->GetSide())
3550 << Form(" %d%d%d%d%d ", (Int_t) pDigi2->GetType(), (Int_t) pDigi2->GetSm(),
3551 (Int_t) pDigi2->GetRpc(), (Int_t) pDigi2->GetChannel(),
3552 (Int_t) pDigi2->GetSide());
3553 break;
3554 case 2: // insert missing hits
3555 CbmTofDigi* pDigiN = new ((*fTofDigisColl)[iNbTofDigi++]) CbmTofDigi(*pDigi);
3556 pDigiN->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi2->GetChannel(), pDigi->GetSide(),
3557 pDigi->GetType());
3558 pDigiN->SetTot(pDigi2->GetTot());
3559
3560 CbmTofDigi* pDigiN2 = new ((*fTofDigisColl)[iNbTofDigi++]) CbmTofDigi(*pDigi2);
3561 pDigiN2->SetAddress(pDigi2->GetSm(), pDigi2->GetRpc(), pDigi->GetChannel(), pDigi2->GetSide(),
3562 pDigi2->GetType());
3563 pDigiN2->SetTot(pDigi->GetTot());
3564
3565 break;
3566 }
3567 }
3568 }
3569 }
3570 }
3571 }
3572
3573 if (pDigi2Min != NULL) {
3574 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, pDigi->GetType(), pDigi->GetSm(), pDigi->GetRpc(), 0,
3575 pDigi->GetChannel());
3576 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
3577 fChannelInfo = fDigiPar->GetCell(iChId);
3578 if (NULL == fChannelInfo) {
3579 LOG(warning) << Form("BuildClusters: invalid ChannelInfo for 0x%08x", iChId);
3580 continue;
3581 }
3582 if (fDigiBdfPar->GetSigVel(pDigi->GetType(), pDigi->GetSm(), pDigi->GetRpc()) * dTDifMin * 0.5
3584 //check consistency
3585 if (8 == pDigi->GetType() || 5 == pDigi->GetType()) {
3586 if (pDigi->GetTime() != pDigi2Min->GetTime()) {
3587 if (fiMsgCnt-- > 0) {
3588 LOG(warning) << " BuildClusters: Inconsistent duplicated digis in event " << fiNevtBuild
3589 << ", Ind: " << iDigInd;
3590 LOG(warning) << " " << pDigi->ToString();
3591 LOG(warning) << " " << pDigi2Min->ToString();
3592 }
3593 pDigi2Min->SetTot(pDigi->GetTot());
3594 pDigi2Min->SetTime(pDigi->GetTime());
3595 }
3596 }
3597
3598 // average ToTs! temporary fix, FIXME
3599 /*
3600 Double_t dAvTot=0.5*(pDigi->GetTot()+pDigi2Min->GetTot());
3601 pDigi->SetTot(dAvTot);
3602 pDigi2Min->SetTot(dAvTot);
3603 LOG(debug)<<" BuildClusters: TDif "<<dTDifMin<<", Average Tot "<<dAvTot;
3604 LOG(debug)<<" "<<pDigi->ToString();
3605 LOG(debug)<<" "<<pDigi2Min->ToString();
3606 */
3607 }
3608 }
3609 }
3610 }
3611
3612 // First Time order the Digis array
3613 // fTofDigisColl->Sort();
3614
3615 // Then loop over the digis array and store the Digis in separate vectors for
3616 // each RPC modules
3617
3618 // Calibrate RawDigis
3619 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
3620 CbmTofDigi* pDigi;
3621 CbmTofDigi* pCalDigi = NULL;
3622 Int_t iDigIndCal = -1;
3623 // channel deadtime map
3624 std::map<Int_t, Double_t> mChannelDeadTime;
3625
3626 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
3627 pDigi = (CbmTofDigi*) fTofDigisColl->At(iDigInd);
3628
3629 if (fbSwapChannelSides && 5 != pDigi->GetType() && 8 != pDigi->GetType()) {
3630 pDigi->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi->GetChannel(), (0 == pDigi->GetSide()) ? 1 : 0,
3631 pDigi->GetType());
3632 }
3633
3634 Int_t iAddr = pDigi->GetAddress();
3635
3636 LOG(debug1) << "BC " // Before Calibration
3637 << Form("0x%08x", pDigi->GetAddress()) << " TSRC " << pDigi->GetType() << pDigi->GetSm()
3638 << pDigi->GetRpc() << Form("%2d", (Int_t) pDigi->GetChannel()) << " " << pDigi->GetSide() << " "
3639 << Form("%f", pDigi->GetTime()) << " " << pDigi->GetTot();
3640
3641 if (pDigi->GetType() == 5 || pDigi->GetType() == 8) // for Pad counters generate fake digi to mockup a strip
3642 if (pDigi->GetSide() == 1) continue; // skip one side to avoid double entries
3643
3644 Bool_t bValid = kTRUE;
3645 std::map<Int_t, Double_t>::iterator it;
3646 it = mChannelDeadTime.find(iAddr);
3647 if (it != mChannelDeadTime.end()) {
3648 LOG(debug1) << "CCT found valid ChannelDeadtime entry " << mChannelDeadTime[iAddr] << ", DeltaT "
3649 << pDigi->GetTime() - mChannelDeadTime[iAddr];
3650 if ((bValid = (pDigi->GetTime() > mChannelDeadTime[iAddr] + fdChannelDeadtime)))
3651 pCalDigi = new ((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi(*pDigi);
3652 }
3653 else {
3654 pCalDigi = new ((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi(*pDigi);
3655 }
3656 mChannelDeadTime[iAddr] = pDigi->GetTime();
3657 if (!bValid) continue;
3658
3659 LOG(debug1) << "DC " // After deadtime check. before Calibration
3660 << Form("0x%08x", pDigi->GetAddress()) << " TSRC " << pDigi->GetType() << pDigi->GetSm()
3661 << pDigi->GetRpc() << Form("%2d", (Int_t) pDigi->GetChannel()) << " " << pDigi->GetSide() << " "
3662 << Form("%f", pDigi->GetTime()) << " " << pDigi->GetTot();
3663
3664 if (fbPs2Ns) {
3665 pCalDigi->SetTime(pCalDigi->GetTime() / 1000.); // for backward compatibility
3666 pCalDigi->SetTot(pCalDigi->GetTot() / 1000.); // for backward compatibility
3667 }
3668
3669 if (fDigiBdfPar->GetNbSmTypes() > pDigi->GetType() // prevent crash due to misconfiguration
3670 && fDigiBdfPar->GetNbSm(pDigi->GetType()) > pDigi->GetSm()
3671 && fDigiBdfPar->GetNbRpc(pDigi->GetType()) > pDigi->GetRpc()
3672 && fDigiBdfPar->GetNbChan(pDigi->GetType(), pDigi->GetRpc()) > pDigi->GetChannel()) {
3673
3674 LOG(debug2) << " CluCal-Init: " << pDigi->ToString();
3675 // apply calibration vectors
3676 pCalDigi->SetTime(pCalDigi->GetTime() - // calibrate Digi Time
3677 fvCPTOff[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
3678 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()]);
3679 LOG(debug2) << " CluCal-TOff: " << pCalDigi->ToString();
3680
3681 Double_t dTot = pCalDigi->GetTot() - // subtract Offset
3682 fvCPTotOff[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
3683 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()];
3684 if (dTot < 0.001) dTot = 0.001;
3685 pCalDigi->SetTot(dTot * // calibrate Digi ToT
3686 fvCPTotGain[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
3687 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()]);
3688
3689 // walk correction
3690 Double_t dTotBinSize = (fdTOTMax - fdTOTMin) / nbClWalkBinX;
3691 Int_t iWx = (Int_t)((pCalDigi->GetTot() - fdTOTMin) / dTotBinSize);
3692 if (0 > iWx) iWx = 0;
3693 if (iWx >= nbClWalkBinX) iWx = nbClWalkBinX - 1;
3694 Double_t dDTot = (pCalDigi->GetTot() - fdTOTMin) / dTotBinSize - (Double_t) iWx - 0.5;
3695 Double_t dWT =
3696 fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
3697 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx];
3698 if (dDTot > 0) { // linear interpolation to next bin
3699 if (iWx < nbClWalkBinX - 1) { // linear interpolation to next bin
3700
3701 dWT += dDTot
3702 * (fvCPWalk[pCalDigi->GetType()]
3703 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
3704 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx + 1]
3705 - fvCPWalk[pCalDigi->GetType()]
3706 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
3707 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]); //memory leak???
3708 }
3709 }
3710 else // dDTot < 0, linear interpolation to next bin
3711 {
3712 if (0 < iWx) { // linear interpolation to next bin
3713 dWT -= dDTot
3714 * (fvCPWalk[pCalDigi->GetType()]
3715 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
3716 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx - 1]
3717 - fvCPWalk[pCalDigi->GetType()]
3718 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
3719 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]); //memory leak???
3720 }
3721 }
3722
3723 pCalDigi->SetTime(pCalDigi->GetTime() - dWT); // calibrate Digi Time
3724 LOG(debug2) << " CluCal-Walk: " << pCalDigi->ToString();
3725
3726 if (0) { //pDigi->GetType()==7 && pDigi->GetSm()==0){
3727 LOG(info)
3728 << "CbmTofTestBeamClusterizer::BuildClusters: CalDigi " << iDigIndCal << ", T " << pCalDigi->GetType()
3729 << ", Sm " << pCalDigi->GetSm() << ", R " << pCalDigi->GetRpc() << ", Ch " << pCalDigi->GetChannel()
3730 << ", S " << pCalDigi->GetSide() << ", T " << pCalDigi->GetTime() << ", Tot " << pCalDigi->GetTot()
3731 << ", TotGain "
3732 << fvCPTotGain[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
3733 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()]
3734 << ", TotOff "
3735 << fvCPTotOff[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
3736 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()]
3737 << ", Walk " << iWx << ": "
3738 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
3739 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx];
3740
3741 LOG(info)
3742 << " dDTot " << dDTot << " BinSize: " << dTotBinSize << ", CPWalk "
3743 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
3744 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx - 1]
3745 << ", "
3746 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
3747 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]
3748 << ", "
3749 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
3750 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx + 1]
3751 << " -> dWT = " << dWT;
3752 }
3753 }
3754 else {
3755 LOG(info) << "Skip1 Digi "
3756 << " Type " << pDigi->GetType() << " " << fDigiBdfPar->GetNbSmTypes() << " Sm " << pDigi->GetSm()
3757 << " " << fDigiBdfPar->GetNbSm(pDigi->GetType()) << " Rpc " << pDigi->GetRpc() << " "
3758 << fDigiBdfPar->GetNbRpc(pDigi->GetType()) << " Ch " << pDigi->GetChannel() << " "
3759 << fDigiBdfPar->GetNbChan(pDigi->GetType(), 0);
3760 }
3761 if (pCalDigi->GetType() == 5
3762 || pCalDigi->GetType() == 8) { // for Pad counters generate fake digi to mockup a strip
3763 CbmTofDigi* pCalDigi2 = new ((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi(*pCalDigi);
3764 if (pCalDigi->GetSide() == 0)
3765 pCalDigi2->SetAddress(pCalDigi->GetSm(), pCalDigi->GetRpc(), pCalDigi->GetChannel(), 1, pCalDigi->GetType());
3766 else
3767 pCalDigi2->SetAddress(pCalDigi->GetSm(), pCalDigi->GetRpc(), pCalDigi->GetChannel(), 0, pCalDigi->GetType());
3768 ;
3769 }
3770 } // for( Int_t iDigInd = 0; iDigInd < nTofDigi; iDigInd++ )
3771
3772 iNbTofDigi = fTofCalDigisColl->GetEntriesFast(); // update because of added duplicted digis
3773 if (fTofCalDigisColl->IsSortable())
3774 LOG(debug) << "CbmTofTestBeamClusterizer::BuildClusters: Sort " << fTofCalDigisColl->GetEntriesFast()
3775 << " calibrated digis ";
3776 if (iNbTofDigi > 1) {
3777 fTofCalDigisColl->Sort(iNbTofDigi); // Time order again, in case modified by the calibration
3778 if (!fTofCalDigisColl->IsSorted()) {
3779 LOG(warning) << "CbmTofTestBeamClusterizer::BuildClusters: Sorting not "
3780 "successful ";
3781 }
3782 }
3783
3784 // Store CalDigis in vectors
3785 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
3786 pDigi = (CbmTofDigi*) fTofCalDigisColl->At(iDigInd);
3787 LOG(debug1) << "AC " // After Calibration
3788 << Form("0x%08x", pDigi->GetAddress()) << " TSRC " << pDigi->GetType() << pDigi->GetSm()
3789 << pDigi->GetRpc() << Form("%2d", (Int_t) pDigi->GetChannel()) << " " << pDigi->GetSide() << " "
3790 << Form("%f", pDigi->GetTime()) << " " << pDigi->GetTot();
3791
3792 if (fDigiBdfPar->GetNbSmTypes() > pDigi->GetType() // prevent crash due to misconfiguration
3793 && fDigiBdfPar->GetNbSm(pDigi->GetType()) > pDigi->GetSm()
3794 && fDigiBdfPar->GetNbRpc(pDigi->GetType()) > pDigi->GetRpc()
3795 && fDigiBdfPar->GetNbChan(pDigi->GetType(), pDigi->GetRpc()) > pDigi->GetChannel()) {
3796 fStorDigiExp[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType()) + pDigi->GetRpc()]
3797 [pDigi->GetChannel()]
3798 .push_back(pDigi);
3799 fStorDigiInd[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType()) + pDigi->GetRpc()]
3800 [pDigi->GetChannel()]
3801 .push_back(iDigInd);
3802 }
3803 else {
3804 LOG(info) << "Skip2 Digi "
3805 << " Type " << pDigi->GetType() << " " << fDigiBdfPar->GetNbSmTypes() << " Sm " << pDigi->GetSm()
3806 << " " << fDigiBdfPar->GetNbSm(pDigi->GetType()) << " Rpc " << pDigi->GetRpc() << " "
3807 << fDigiBdfPar->GetNbRpc(pDigi->GetType()) << " Ch " << pDigi->GetChannel() << " "
3808 << fDigiBdfPar->GetNbChan(pDigi->GetType(), 0);
3809 }
3810 } // for( Int_t iDigInd = 0; iDigInd < nTofDigi; iDigInd++ )
3811
3812 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
3813 else {
3814 return kFALSE; // not implemented properly yet
3815 /*
3816 CbmTofDigi *pDigi;
3817 for( Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++ )
3818 {
3819 pDigi = (CbmTofDigi*) fTofDigisColl->At( iDigInd );
3820 fStorDigi[pDigi->GetType()]
3821 [pDigi->GetSm()*fDigiBdfPar->GetNbRpc( pDigi->GetType()) + pDigi->GetRpc()]
3822 [pDigi->GetChannel()].push_back(pDigi);
3823 fStorDigiInd[pDigi->GetType()]
3824 [pDigi->GetSm()*fDigiBdfPar->GetNbRpc( pDigi->GetType()) + pDigi->GetRpc()]
3825 [pDigi->GetChannel()].push_back(iDigInd);
3826 } // for( Int_t iDigInd = 0; iDigInd < nTofDigi; iDigInd++ )
3827 */
3828 } // else of if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
3829
3830
3831 // Then build clusters inside each RPC module
3832 // Assume only 0 or 1 Digi per channel/side in each event
3833 // Use simplest method possible, scan direction independent:
3834 // a) Loop over channels in the RPC starting from 0
3835 // * If strips
3836 // i) Loop over Digis to check if both ends of the channel have a Digi
3837 // ii) Reconstruct a mean channel time and a mean position
3838 // + If a Hit is currently filled & the mean position (space, time) is less than XXX from last channel position
3839 // iii) Add the mean channel time and the mean position to the ones of the hit
3840 // + else
3841 // iii) Use nb of strips in cluster to cal. the hit mean time and pos (charge/tot weighting)
3842 // iv) Save the hit
3843 // v) Start a new hit with current channel
3844 // * else (pads)
3845 // i) Loop over Digis to find if this channel fired
3846 // ii) FIXME: either scan all other channels to check for matching Digis or have more than 1 hit open
3847 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
3848 // Hit variables
3849 Double_t dWeightedTime = 0.0;
3850 Double_t dWeightedPosX = 0.0;
3851 Double_t dWeightedPosY = 0.0;
3852 Double_t dWeightedPosZ = 0.0;
3853 Double_t dWeightsSum = 0.0;
3854 vPtsRef.clear();
3855 vDigiIndRef.clear();
3856 //CbmTofCell *fTrafoCell=NULL; (VF) not used
3857 //Int_t iTrafoCell=-1; (VF) not used
3858 Int_t iNbChanInHit = 0;
3859 // Last Channel Temp variables
3860 Int_t iLastChan = -1;
3861 Double_t dLastPosX = 0.0; // -> Comment to remove warning because set but never used
3862 Double_t dLastPosY = 0.0;
3863 Double_t dLastTime = 0.0;
3864 // Channel Temp variables
3865 Double_t dPosX = 0.0;
3866 Double_t dPosY = 0.0;
3867 Double_t dPosZ = 0.0;
3868 Double_t dTime = 0.0;
3869 Double_t dTimeDif = 0.0;
3870 Double_t dTotS = 0.0;
3871 fiNbSameSide = 0;
3872 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
3873 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
3874 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
3875 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3876 for (Int_t iSm = 0; iSm < iNbSm; iSm++)
3877 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
3878 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
3879 Int_t iChType = fDigiBdfPar->GetChanType(iSmType, iRpc);
3880 LOG(debug2) << "RPC - Loop " << Form(" %3d %3d %3d %3d ", iSmType, iSm, iRpc, iChType);
3881 fviClusterMul[iSmType][iSm][iRpc] = 0;
3882 Int_t iChId = 0;
3883 if (0 == iChType) {
3884 // Don't spread clusters over RPCs!!!
3885 dWeightedTime = 0.0;
3886 dWeightedPosX = 0.0;
3887 dWeightedPosY = 0.0;
3888 dWeightedPosZ = 0.0;
3889 dWeightsSum = 0.0;
3890 iNbChanInHit = 0;
3891 vPtsRef.clear();
3892 // For safety reinitialize everything
3893 iLastChan = -1;
3894 // dLastPosX = 0.0; // -> Comment to remove warning because set but never used
3895 dLastPosY = 0.0;
3896 dLastTime = 0.0;
3897 LOG(debug2) << "ChanOrient "
3898 << Form(" %3d %3d %3d %3d %3d ", iSmType, iSm, iRpc, fDigiBdfPar->GetChanOrient(iSmType, iRpc),
3899 iNbCh);
3900
3901 if (1 == fDigiBdfPar->GetChanOrient(iSmType, iRpc)) {
3902 // Horizontal strips => X comes from left right time difference
3903 } // if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
3904 else {
3905 // Vertical strips => Y comes from bottom top time difference
3906 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
3907 LOG(debug3) << "VDigisize "
3908 << Form(" T %3d Sm %3d R %3d Ch %3d Size %3lu ", iSmType, iSm, iRpc, iCh,
3909 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size());
3910 if (0 == fStorDigiExp[iSmType][iSm * iNbRpc + iRpc].size()) continue;
3911 if (0 < fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size())
3912 fhNbDigiPerChan->Fill(fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size());
3913
3914 while (1 < fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
3915
3916 while ((fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetSide()
3917 == (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetSide()) {
3918 // Not one Digi of each end!
3919 fiNbSameSide++;
3920 if (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size() > 2) {
3921 LOG(debug) << "SameSide Digis! on TSRC " << iSmType << iSm << iRpc << iCh << ", Times: "
3922 << Form("%f", (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()) << ", "
3923 << Form("%f", (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime())
3924 << ", DeltaT "
3925 << (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
3926 - (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
3927 << ", array size: " << fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size();
3928 if (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetSide()
3929 == fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetSide()) {
3930 LOG(debug) << "3 consecutive SameSide Digis! on TSRC " << iSmType << iSm << iRpc << iCh
3931 << ", Times: " << (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
3932 << ", " << (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
3933 << ", DeltaT "
3934 << (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
3935 - (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
3936 << ", array size: " << fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size();
3937 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3938 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
3939 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3940 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
3941 }
3942 else {
3943 if (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetTime()
3944 - fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetTime()
3945 > fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetTime()
3946 - fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][1]->GetTime()) {
3947 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3948 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
3949 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3950 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
3951 }
3952 else {
3953 LOG(debug) << Form("Ev %8.0f, digis not properly time ordered, TSRCS "
3954 "%d%d%d%d%d ",
3955 fdEvent, iSmType, iSm, iRpc, iCh,
3956 (Int_t) fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetSide());
3957 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3958 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1);
3959 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3960 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1);
3961 }
3962 }
3963 }
3964 else {
3965 LOG(debug2) << "SameSide Erase fStor entries(d) " << iSmType << ", SR " << iSm * iNbRpc + iRpc
3966 << ", Ch" << iCh;
3967 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3968 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
3969 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
3970 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
3971 }
3972 if (2 > fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size()) break;
3973 continue;
3974 } // same condition side end
3975
3976 LOG(debug2) << "digis processing for "
3977 << Form(" SmT %3d Sm %3d Rpc %3d Ch %3d # %3lu ", iSmType, iSm, iRpc, iCh,
3978 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size());
3979 if (2 > fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
3980 LOG(debug) << Form("Leaving digi processing for TSRC %d%d%d%d, size %3lu", iSmType, iSm, iRpc, iCh,
3981 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size());
3982 break;
3983 }
3984 /* Int_t iLastChId = iChId; // Save Last hit channel*/
3985
3986 // 2 Digis = both sides present
3987 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
3988 iChId = fTofId->SetDetectorInfo(xDetInfo);
3989 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType);
3990 LOG(debug1) << Form(" TSRC %d%d%d%d size %3lu ", iSmType, iSm, iRpc, iCh,
3991 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size())
3992 << Form(" ChId: 0x%08x 0x%08x ", iChId, iUCellId);
3993 fChannelInfo = fDigiPar->GetCell(iChId);
3994
3995 if (NULL == fChannelInfo) {
3996 LOG(error) << "CbmTofTestBeamClusterizer::BuildClusters: "
3997 "no geometry info! "
3998 << Form(" %3d %3d %3d %3d 0x%08x 0x%08x ", iSmType, iSm, iRpc, iCh, iChId, iUCellId);
3999 break;
4000 }
4001
4002 TGeoNode* fNode = // prepare local->global trafo
4003 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
4004 LOG(debug2) << Form(" Node at (%6.1f,%6.1f,%6.1f) : %p", fChannelInfo->GetX(), fChannelInfo->GetY(),
4005 fChannelInfo->GetZ(), fNode);
4006 // fNode->Print();
4007
4008 CbmTofDigi* xDigiA = fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][0];
4009 CbmTofDigi* xDigiB = fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][1];
4010
4011 LOG(debug2) << " " << xDigiA->ToString();
4012 LOG(debug2) << " " << xDigiB->ToString();
4013
4014 dTimeDif = (xDigiA->GetTime() - xDigiB->GetTime());
4015 if (5 == iSmType && dTimeDif != 0.) {
4016 // FIXME -> Overflow treatment in calib/tdc/TMbsCalibTdcTof.cxx
4017 LOG(debug) << "CbmTofTestBeamClusterizer::BuildClusters: "
4018 "Diamond hit in "
4019 << iSm << " with inconsistent digits " << xDigiA->GetTime() << ", " << xDigiB->GetTime()
4020 << " -> " << dTimeDif;
4021 LOG(debug) << " " << xDigiA->ToString();
4022 LOG(debug) << " " << xDigiB->ToString();
4023 }
4024 if (1 == xDigiA->GetSide())
4025 // 0 is the top side, 1 is the bottom side
4026 dPosY = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
4027 else
4028 // 0 is the bottom side, 1 is the top side
4029 dPosY = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
4030
4031 if (TMath::Abs(dPosY) > fChannelInfo->GetSizey()
4032 && fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size() > 2) {
4033 LOG(debug) << "Hit candidate outside correlation window, check for "
4034 "better possible digis, "
4035 << " mul " << fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size();
4036
4037 CbmTofDigi* xDigiC = fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][2];
4038 Double_t dPosYN = 0.;
4039 Double_t dTimeDifN = 0;
4040 if (xDigiC->GetSide() == xDigiA->GetSide())
4041 dTimeDifN = xDigiC->GetTime() - xDigiB->GetTime();
4042 else
4043 dTimeDifN = xDigiA->GetTime() - xDigiC->GetTime();
4044
4045 if (1 == xDigiA->GetSide())
4046 dPosYN = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDifN * 0.5;
4047 else
4048 dPosYN = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDifN * 0.5;
4049
4050 if (TMath::Abs(dPosYN) < TMath::Abs(dPosY)) {
4051 LOG(debug) << "Replace digi on side " << xDigiC->GetSide() << ", yPosNext " << dPosYN
4052 << " old: " << dPosY;
4053 dTimeDif = dTimeDifN;
4054 dPosY = dPosYN;
4055 if (xDigiC->GetSide() == xDigiA->GetSide()) {
4056 xDigiA = xDigiC;
4057 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4058 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4059 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4060 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4061 }
4062 else {
4063 xDigiB = xDigiC;
4064 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4065 ++(fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1));
4066 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4067 ++(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1));
4068 }
4069 }
4070 }
4071
4072 if (xDigiA->GetSide() == xDigiB->GetSide()) {
4073 LOG(fatal) << "Wrong combinations of digis " << fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]
4074 << "," << fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1];
4075 }
4076 // The "Strip" time is the mean time between each end
4077 dTime = 0.5 * (xDigiA->GetTime() + xDigiB->GetTime());
4078
4079 // Weight is the total charge => sum of both ends ToT
4080 dTotS = xDigiA->GetTot() + xDigiB->GetTot();
4081
4082
4083 // use local coordinates, (0,0,0) is in the center of counter ?
4084 dPosX = ((Double_t)(-iNbCh / 2 + iCh) + 0.5) * fChannelInfo->GetSizex();
4085 dPosZ = 0.;
4086
4087 LOG(debug1) << "NbChanInHit "
4088 << Form(" %3d %3d %3d %3d %3d 0x%p %1.0f Time %f PosX %f "
4089 "PosY %f Svel %f ",
4090 iNbChanInHit, iSmType, iRpc, iCh, iLastChan, xDigiA, xDigiA->GetSide(), dTime,
4091 dPosX, dPosY, fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc))
4092 // << Form( ", Offs %f, %f ",fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][0],
4093 // fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][1])
4094 ;
4095
4096 // Now check if a hit/cluster is already started
4097 if (0 < iNbChanInHit) {
4098 if (iLastChan == iCh - 1) {
4099 fhDigTimeDifClust->Fill(dTime - dLastTime);
4100 fhDigSpacDifClust->Fill(dPosY - dLastPosY);
4101 fhDigDistClust->Fill(dPosY - dLastPosY, dTime - dLastTime);
4102 }
4103 // if( iLastChan == iCh - 1 )
4104 // a cluster is already started => check distance in space/time
4105 // For simplicity, just check along strip direction for now
4106 // and break cluster when a not fired strip is found
4107 if (TMath::Abs(dTime - dLastTime) < fdMaxTimeDist && iLastChan == iCh - 1
4108 && TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist) {
4109 // Add to cluster/hit
4110 dWeightedTime += dTime * dTotS;
4111 dWeightedPosX += dPosX * dTotS;
4112 dWeightedPosY += dPosY * dTotS;
4113 dWeightedPosZ += dPosZ * dTotS;
4114 dWeightsSum += dTotS;
4115 iNbChanInHit += 1;
4116
4117 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
4118 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
4119
4120 LOG(debug1) << " Add Digi and erase fStor entries(a): NbChanInHit " << iNbChanInHit << ", "
4121 << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch" << iCh;
4122
4123 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4124 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4125 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4126 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4127 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4128 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4129 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4130 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4131
4132 } // if current Digis compatible with last fired chan
4133 else {
4134 // Save Hit
4135 dWeightedTime /= dWeightsSum;
4136 dWeightedPosX /= dWeightsSum;
4137 dWeightedPosY /= dWeightsSum;
4138 dWeightedPosZ /= dWeightsSum;
4139 // TVector3 hitPosLocal(dWeightedPosX, dWeightedPosY, dWeightedPosZ);
4140 //TVector3 hitPos;
4141 Double_t hitpos_local[3];
4142 hitpos_local[0] = dWeightedPosX;
4143 hitpos_local[1] = dWeightedPosY;
4144 hitpos_local[2] = dWeightedPosZ;
4145
4146 Double_t hitpos[3];
4147 TGeoNode* cNode = gGeoManager->GetCurrentNode();
4148 /*TGeoHMatrix* cMatrix =*/gGeoManager->GetCurrentMatrix();
4149 //cNode->Print();
4150 //cMatrix->Print();
4151
4152 gGeoManager->LocalToMaster(hitpos_local, hitpos);
4153 LOG(debug1) << Form(" LocalToMaster for node %p: "
4154 "(%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)",
4155 cNode, hitpos_local[0], hitpos_local[1], hitpos_local[2], hitpos[0],
4156 hitpos[1], hitpos[2]);
4157
4158 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
4159
4160 // Simple errors, not properly done at all for now
4161 // Right way of doing it should take into account the weight distribution
4162 // and real system time resolution
4163 TVector3 hitPosErr(0.5, 0.5, 0.5); // including positioning uncertainty
4164 /*
4165 TVector3 hitPosErr( fChannelInfo->GetSizex()/TMath::Sqrt(12.0), // Single strips approximation
4166 0.5, // Use generic value
4167 1.);
4168
4169 */ // fDigiBdfPar->GetFeeTimeRes() * fDigiBdfPar->GetSigVel(iSmType,iRpc), // Use the electronics resolution
4170 //fDigiBdfPar->GetNbGaps( iSmType, iRpc)*
4171 //fDigiBdfPar->GetGapSize( iSmType, iRpc)/ //10.0 / // Change gap size in cm
4172 //TMath::Sqrt(12.0) ); // Use full RPC thickness as "Channel" Z size
4173
4174 // Int_t iDetId = vPtsRef[0]->GetDetectorID();// detID = pt->GetDetectorID() <= from TofPoint
4175 // calc mean ch from dPosX=((Double_t)(-iNbCh/2 + iCh)+0.5)*fChannelInfo->GetSizex();
4176
4177 Int_t iChm = floor(dWeightedPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
4178 if (iChm < 0) iChm = 0;
4179 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
4180 Int_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
4181 Int_t iRefId = 0; // Index of the correspondng TofPoint
4182 if (NULL != fTofPointsColl) {
4183 iRefId = fTofPointsColl->IndexOf(vPtsRef[0]);
4184 }
4185 LOG(debug) << "Save Hit "
4186 << Form(" %3d %3d 0x%08x %3d %3d %3d %f %f", fiNbHits, iNbChanInHit, iDetId, iChm,
4187 iLastChan, iRefId, dWeightedTime, dWeightedPosY)
4188 << ", DigiSize: " << vDigiIndRef.size() << ", DigiInds: ";
4189
4190 fviClusterMul[iSmType][iSm][iRpc]++;
4191
4192 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
4193 LOG(debug) << " " << vDigiIndRef.at(i) << "(M" << fviClusterMul[iSmType][iSm][iRpc] << ")";
4194 }
4195 LOG(debug);
4196
4197 if (vDigiIndRef.size() < 2) {
4198 LOG(warning) << "Digi refs for Hit " << fiNbHits << ": vDigiIndRef.size()";
4199 }
4200 if (fiNbHits > 0) {
4201 CbmTofHit* pHitL = (CbmTofHit*) fTofHitsColl->At(fiNbHits - 1);
4202 if (iDetId == pHitL->GetAddress() && dWeightedTime == pHitL->GetTime()) {
4203 LOG(debug) << "Store Hit twice? "
4204 << " fiNbHits " << fiNbHits << ", " << Form("0x%08x", iDetId);
4205
4206 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
4207 CbmTofDigi* pDigiC = (CbmTofDigi*) fTofCalDigisColl->At(vDigiIndRef.at(i));
4208 LOG(debug) << " Digi " << pDigiC->ToString();
4209 }
4210 CbmMatch* digiMatchL = (CbmMatch*) fTofDigiMatchColl->At(fiNbHits - 1);
4211 for (Int_t i = 0; i < digiMatchL->GetNofLinks(); i++) {
4212 CbmLink L0 = digiMatchL->GetLink(i);
4213 Int_t iDigIndL = L0.GetIndex();
4214 CbmTofDigi* pDigiC = (CbmTofDigi*) fTofCalDigisColl->At(iDigIndL);
4215 LOG(debug) << " DigiL " << pDigiC->ToString();
4216 }
4217 }
4218 }
4219 CbmTofHit* pHit =
4220 new CbmTofHit(iDetId, hitPos,
4221 hitPosErr, //local detector coordinates
4222 fiNbHits, // this number is used as reference!!
4223 dWeightedTime,
4224 vDigiIndRef.size(), // number of linked digis = 2*CluSize
4225 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
4226 Int_t(dWeightsSum * 10.)); //channel -> Tot
4227 //0) ; //channel
4228 // output hit
4229 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
4230 // memorize hit
4231 if (fdMemoryTime > 0.) {
4232 LH_store(iSmType, iSm, iRpc, iChm, pHit);
4233 }
4234 else {
4235 pHit->Delete();
4236 }
4237 /*
4238 new((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
4239 CbmMatch* digiMatch = (CbmMatch *)fTofDigiMatchColl->At(fiNbHits);
4240 */
4241 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
4242 for (size_t i = 0; i < vDigiIndRef.size(); i++) {
4243 Double_t dTot = ((CbmTofDigi*) (fTofCalDigisColl->At(vDigiIndRef.at(i))))->GetTot();
4244 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
4245 }
4246
4247 fiNbHits++;
4248 // For Histogramming
4249 fviClusterSize[iSmType][iRpc].push_back(iNbChanInHit);
4250 fviTrkMul[iSmType][iRpc].push_back(vPtsRef.size());
4251 fvdX[iSmType][iRpc].push_back(dWeightedPosX);
4252 fvdY[iSmType][iRpc].push_back(dWeightedPosY);
4253 /* no TofPoint available for data!
4254 fvdDifX[iSmType][iRpc].push_back( vPtsRef[0]->GetX() - dWeightedPosX);
4255 fvdDifY[iSmType][iRpc].push_back( vPtsRef[0]->GetY() - dWeightedPosY);
4256 fvdDifCh[iSmType][iRpc].push_back( fGeoHandler->GetCell( vPtsRef[0]->GetDetectorID() ) -1 -iLastChan );
4257 */
4258 vPtsRef.clear();
4259 vDigiIndRef.clear();
4260
4261 // Start a new hit
4262 dWeightedTime = dTime * dTotS;
4263 dWeightedPosX = dPosX * dTotS;
4264 dWeightedPosY = dPosY * dTotS;
4265 dWeightedPosZ = dPosZ * dTotS;
4266 dWeightsSum = dTotS;
4267 iNbChanInHit = 1;
4268 // Save pointer on CbmTofPoint
4269 // vPtsRef.push_back( (CbmTofPoint*)(xDigiA->GetLinks()) );
4270 // Save next digi address
4271 LOG(debug2) << " Next fStor Digi " << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch" << iCh
4272 << ", Dig0 " << (fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]) << ", Dig1 "
4273 << (fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4274
4275 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
4276 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
4277 LOG(debug2) << " Erase fStor entries(b) " << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch"
4278 << iCh;
4279 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4280 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4281 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4282 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4283 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4284 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4285 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4286 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4287
4288 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
4289 // if( ((CbmTofPoint*)(xDigiA->GetLinks()))->GetTrackID() !=
4290 // ((CbmTofPoint*)(xDigiB->GetLinks()))->GetTrackID() )
4291 // if other side come from a different Track,
4292 // also save the pointer on CbmTofPoint
4293 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
4294 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
4295 //else if( xDigiA->GetLinks() != xDigiB->GetLinks() )
4296 // if other side come from a different TofPoint,
4297 // also save the pointer on CbmTofPoint
4298 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
4299 } // else of if current Digis compatible with last fired chan
4300 } // if( 0 < iNbChanInHit)
4301 else {
4302 LOG(debug) << Form("1.Hit on channel %d, time: %f, PosY %f", iCh, dTime, dPosY);
4303
4304 // first fired strip in this RPC
4305 dWeightedTime = dTime * dTotS;
4306 dWeightedPosX = dPosX * dTotS;
4307 dWeightedPosY = dPosY * dTotS;
4308 dWeightedPosZ = dPosZ * dTotS;
4309 dWeightsSum = dTotS;
4310 iNbChanInHit = 1;
4311 // Save pointer on CbmTofPoint
4312 //if(NULL != fTofPointsColl)
4313 // vPtsRef.push_back( (CbmTofPoint*)(xDigiA->GetLinks()) );
4314 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
4315 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
4316
4317 LOG(debug2) << " Erase fStor entries(c) " << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch"
4318 << iCh;
4319 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4320 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4321 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4322 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4323 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4324 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4325 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4326 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
4327
4328 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
4329 // if( ((CbmTofPoint*)(xDigiA->GetLinks()))->GetTrackID() !=
4330 // ((CbmTofPoint*)(xDigiB->GetLinks()))->GetTrackID() )
4331 // if other side come from a different Track,
4332 // also save the pointer on CbmTofPoint
4333 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
4334 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
4335 // else if( xDigiA->GetLinks() != xDigiB->GetLinks() )
4336 // if other side come from a different TofPoint,
4337 // also save the pointer on CbmTofPoint
4338 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
4339 } // else of if( 0 < iNbChanInHit)
4340 iLastChan = iCh;
4341 dLastPosX = dPosX;
4342 dLastPosY = dPosY;
4343 dLastTime = dTime;
4344 if (AddNextChan(iSmType, iSm, iRpc, iLastChan, dLastPosX, dLastPosY, dLastTime, dWeightsSum)) {
4345 iNbChanInHit = 0; // cluster already stored
4346 }
4347 } // while( 1 < fStorDigiExp[iSmType][iSm*iNbRpc+iRpc][iCh].size() )
4348 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].clear();
4349 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].clear();
4350 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
4351 LOG(debug2) << "finished V-RPC"
4352 << Form(" %3d %3d %3d %d %f %fx", iSmType, iSm, iRpc, fTofHitsColl->GetEntriesFast(),
4353 dLastPosX, dLastPosY);
4354 } // else of if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
4355 } // if( 0 == iChType)
4356 else {
4357 LOG(error) << "=> Cluster building "
4358 << "from digis to hits not implemented for pads, Sm type " << iSmType << " Rpc " << iRpc;
4359 return kFALSE;
4360 } // else of if( 0 == iChType)
4361
4362 // Now check if another hit/cluster is started
4363 // and save it if it's the case
4364 if (0 < iNbChanInHit) {
4365 LOG(debug1) << "Process cluster " << iNbChanInHit;
4366
4367 // Check orientation to properly assign errors
4368 if (1 == fDigiBdfPar->GetChanOrient(iSmType, iRpc)) {
4369 LOG(debug1) << "H-Hit ";
4370 } // if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
4371 else {
4372 LOG(debug2) << "V-Hit ";
4373 // Save Hit
4374 dWeightedTime /= dWeightsSum;
4375 dWeightedPosX /= dWeightsSum;
4376 dWeightedPosY /= dWeightsSum;
4377 dWeightedPosZ /= dWeightsSum;
4378 //TVector3 hitPos(dWeightedPosX, dWeightedPosY, dWeightedPosZ);
4379
4380 Double_t hitpos_local[3] = {3 * 0.};
4381 hitpos_local[0] = dWeightedPosX;
4382 hitpos_local[1] = dWeightedPosY;
4383 hitpos_local[2] = dWeightedPosZ;
4384
4385 Double_t hitpos[3];
4386 TGeoNode* cNode = gGeoManager->GetCurrentNode();
4387 /*TGeoHMatrix* cMatrix =*/gGeoManager->GetCurrentMatrix();
4388 //cNode->Print();
4389 //cMatrix->Print();
4390
4391 gGeoManager->LocalToMaster(hitpos_local, hitpos);
4392 LOG(debug1) << Form(" LocalToMaster for V-node %p: "
4393 "(%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)",
4394 cNode, hitpos_local[0], hitpos_local[1], hitpos_local[2], hitpos[0], hitpos[1],
4395 hitpos[2]);
4396
4397 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
4398 // TestBeam errors, not properly done at all for now
4399 // Right way of doing it should take into account the weight distribution
4400 // and real system time resolution
4401 TVector3 hitPosErr(0.5, 0.5, 0.5); // including positioning uncertainty
4402 /*
4403 TVector3 hitPosErr( fChannelInfo->GetSizex()/TMath::Sqrt(12.0), // Single strips approximation
4404 0.5, // Use generic value
4405 1.);
4406 */
4407 // fDigiBdfPar->GetFeeTimeRes() * fDigiBdfPar->GetSigVel(iSmType,iRpc), // Use the electronics resolution
4408 // fDigiBdfPar->GetNbGaps( iSmType, iRpc)*
4409 // fDigiBdfPar->GetGapSize( iSmType, iRpc)/10.0 / // Change gap size in cm
4410 // TMath::Sqrt(12.0) ); // Use full RPC thickness as "Channel" Z size
4411 // cout<<"a "<<vPtsRef.size()<<endl;
4412 // cout<<"b "<<vPtsRef[0]<<endl;
4413 // cout<<"c "<<vPtsRef[0]->GetDetectorID()<<endl;
4414 // Int_t iDetId = vPtsRef[0]->GetDetectorID();// detID = pt->GetDetectorID() <= from TofPoint
4415 // Int_t iDetId = iChId;
4416 Int_t iChm = floor(dWeightedPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
4417 if (iChm < 0) iChm = 0;
4418 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
4419 Int_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
4420 Int_t iRefId = 0; // Index of the correspondng TofPoint
4421 if (NULL != fTofPointsColl) iRefId = fTofPointsColl->IndexOf(vPtsRef[0]);
4422 LOG(debug) << "Save V-Hit "
4423 << Form(" %3d %3d 0x%08x %3d 0x%08x", // %3d %3d
4424 fiNbHits, iNbChanInHit, iDetId, iLastChan,
4425 iRefId) //vPtsRef.size(),vPtsRef[0])
4426 // dWeightedTime,dWeightedPosY)
4427 << ", DigiSize: " << vDigiIndRef.size();
4428 LOG(debug) << ", DigiInds: ";
4429
4430 fviClusterMul[iSmType][iSm][iRpc]++;
4431
4432 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
4433 LOG(debug) << " " << vDigiIndRef.at(i) << "(M" << fviClusterMul[iSmType][iSm][iRpc] << ")";
4434 }
4435 LOG(debug);
4436
4437 if (vDigiIndRef.size() < 2) {
4438 LOG(warning) << "Digi refs for Hit " << fiNbHits << ": vDigiIndRef.size()";
4439 }
4440 if (fiNbHits > 0) {
4441 CbmTofHit* pHitL = (CbmTofHit*) fTofHitsColl->At(fiNbHits - 1);
4442 if (iDetId == pHitL->GetAddress() && dWeightedTime == pHitL->GetTime())
4443 LOG(debug) << "Store Hit twice? "
4444 << " fiNbHits " << fiNbHits << ", " << Form("0x%08x", iDetId);
4445 }
4446
4447 CbmTofHit* pHit = new CbmTofHit(iDetId, hitPos,
4448 hitPosErr, //local detector coordinates
4449 fiNbHits, // this number is used as reference!!
4450 dWeightedTime,
4451 vDigiIndRef.size(), // number of linked digis = 2*CluSize
4452 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
4453 Int_t(dWeightsSum * 10.)); //channel -> Tot
4454 // 0) ; //channel
4455 // vDigiIndRef);
4456 // output hit
4457 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
4458 // memorize hit
4459 if (fdMemoryTime > 0.) {
4460 LH_store(iSmType, iSm, iRpc, iChm, pHit);
4461 }
4462 else {
4463 pHit->Delete();
4464 }
4465 /*
4466 new((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
4467 CbmMatch* digiMatch = (CbmMatch *)fTofDigiMatchColl->At(fiNbHits);
4468 */
4469 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
4470
4471 for (size_t i = 0; i < vDigiIndRef.size(); i++) {
4472 Double_t dTot = ((CbmTofDigi*) (fTofCalDigisColl->At(vDigiIndRef.at(i))))->GetTot();
4473 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
4474 }
4475
4476 fiNbHits++;
4477 // For Histogramming
4478 fviClusterSize[iSmType][iRpc].push_back(iNbChanInHit);
4479 fviTrkMul[iSmType][iRpc].push_back(vPtsRef.size());
4480 fvdX[iSmType][iRpc].push_back(dWeightedPosX);
4481 fvdY[iSmType][iRpc].push_back(dWeightedPosY);
4482 /*
4483 fvdDifX[iSmType][iRpc].push_back( vPtsRef[0]->GetX() - dWeightedPosX);
4484 fvdDifY[iSmType][iRpc].push_back( vPtsRef[0]->GetY() - dWeightedPosY);
4485 fvdDifCh[iSmType][iRpc].push_back( fGeoHandler->GetCell( vPtsRef[0]->GetDetectorID() ) -1 -iLastChan );
4486 */
4487 vPtsRef.clear();
4488 vDigiIndRef.clear();
4489 } // else of if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
4490 } // if( 0 < iNbChanInHit)
4491 LOG(debug2) << " Fini-A " << Form(" %3d %3d %3d M%3d", iSmType, iSm, iRpc, fviClusterMul[iSmType][iSm][iRpc]);
4492 } // for each sm/rpc pair
4493 LOG(debug2) << " Fini-B " << Form(" %3d ", iSmType);
4494 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
4495 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
4496 else {
4497 LOG(error) << " Compressed Digis not implemented ... ";
4498 }
4499 return kTRUE;
4500}
4501
4503{
4504 // Merge clusters from neigbouring Rpc within a (Super)Module
4505 if (NULL == fTofHitsColl) {
4506 LOG(info) << " No Hits defined ! Check! ";
4507 return kFALSE;
4508 }
4509 // inspect hits
4510 for (Int_t iHitInd = 0; iHitInd < fTofHitsColl->GetEntriesFast(); iHitInd++) {
4511 CbmTofHit* pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
4512 if (NULL == pHit) continue;
4513
4514 Int_t iDetId = (pHit->GetAddress() & DetMask);
4515 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
4516 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
4517 if (iSmType != 5 && iSmType != 8) continue; // only merge diamonds and Pad
4518 LOG(debug) << "MergeClusters: in SmT " << iSmType << " for " << iNbRpc << " Rpcs";
4519
4520 if (iNbRpc > 1) { // check for possible mergers
4521 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
4522 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
4523 Int_t iChId = pHit->GetAddress();
4524 fChannelInfo = fDigiPar->GetCell(iChId);
4525 Int_t iCh = CbmTofAddress::GetChannelId(iChId);
4526 LOG(debug) << "MergeClusters: Check for mergers in "
4527 << Form(" SmT %d, Sm %d, Rpc %d, Ch %d - hit %d", iSmType, iSm, iRpc, iCh, iHitInd);
4528 for (Int_t iHitInd2 = iHitInd + 1; iHitInd2 < fTofHitsColl->GetEntriesFast(); iHitInd2++) {
4529 CbmTofHit* pHit2 = (CbmTofHit*) fTofHitsColl->At(iHitInd2);
4530 if (NULL == pHit2) continue;
4531 Int_t iDetId2 = (pHit2->GetAddress() & DetMask);
4532 Int_t iSmType2 = CbmTofAddress::GetSmType(iDetId2);
4533 if (iSmType2 == iSmType) {
4534 Int_t iSm2 = CbmTofAddress::GetSmId(iDetId2);
4535 if (iSm2 == iSm || iSmType == 5) {
4536 Int_t iRpc2 = CbmTofAddress::GetRpcId(iDetId2);
4537 if (TMath::Abs(iRpc - iRpc2) == 1 || iSm2 != iSm) { // Found neighbour
4538 Int_t iChId2 = pHit2->GetAddress();
4539 // CbmTofCell *fChannelInfo2 = fDigiPar->GetCell( iChId2 ); (VF) not used
4540 Int_t iCh2 = CbmTofAddress::GetChannelId(iChId2);
4541 Double_t xPos = pHit->GetX();
4542 Double_t yPos = pHit->GetY();
4543 Double_t tof = pHit->GetTime();
4544 Double_t xPos2 = pHit2->GetX();
4545 Double_t yPos2 = pHit2->GetY();
4546 Double_t tof2 = pHit2->GetTime();
4547 LOG(debug) << "MergeClusters: Found hit in neighbour "
4548 << Form(" SmT %d, Sm %d, Rpc %d, Ch %d - hit %d", iSmType2, iSm2, iRpc2, iCh2, iHitInd2)
4549 << Form(" DX %6.1f, DY %6.1f, DT %6.1f", xPos - xPos2, yPos - yPos2, tof - tof2);
4550
4551
4552 if (TMath::Abs(xPos - xPos2) < fdCaldXdYMax * 2. && TMath::Abs(yPos - yPos2) < fdCaldXdYMax * 2.
4553 && TMath::Abs(tof - tof2) < fMaxTimeDist) {
4554
4555 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
4556 Double_t dTot = 0;
4557 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
4558 CbmLink L0 = digiMatch->GetLink(iLink);
4559 Int_t iDigInd0 = L0.GetIndex();
4560 Int_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex();
4561 if (iDigInd0 < fTofCalDigisColl->GetEntriesFast() && iDigInd1 < fTofCalDigisColl->GetEntriesFast()) {
4562 CbmTofDigi* pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
4563 CbmTofDigi* pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
4564 dTot += pDig0->GetTot();
4565 dTot += pDig1->GetTot();
4566 }
4567 }
4568
4569 CbmMatch* digiMatch2 = (CbmMatch*) fTofDigiMatchColl->At(iHitInd2);
4570 Double_t dTot2 = 0;
4571 for (Int_t iLink = 0; iLink < digiMatch2->GetNofLinks(); iLink += 2) { // loop over digis
4572 CbmLink L0 = digiMatch2->GetLink(iLink);
4573 Int_t iDigInd0 = L0.GetIndex();
4574 Int_t iDigInd1 = (digiMatch2->GetLink(iLink + 1)).GetIndex();
4575 if (iDigInd0 < fTofCalDigisColl->GetEntriesFast() && iDigInd1 < fTofCalDigisColl->GetEntriesFast()) {
4576 CbmTofDigi* pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
4577 CbmTofDigi* pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
4578 dTot2 += pDig0->GetTot();
4579 dTot2 += pDig1->GetTot();
4580 digiMatch->AddLink(CbmLink(pDig0->GetTot(), iDigInd0, fiOutputTreeEntry, fiFileIndex));
4581 digiMatch->AddLink(CbmLink(pDig1->GetTot(), iDigInd1, fiOutputTreeEntry, fiFileIndex));
4582 }
4583 }
4584 LOG(debug) << "MergeClusters: Found merger in neighbour "
4585 << Form(" SmT %d, Sm %d, Rpc %d, Ch %d - hit %d(%d)", iSmType2, iSm2, iRpc2, iCh2, iHitInd2,
4586 fTofHitsColl->GetEntriesFast())
4587 << Form(" DX %6.1f, DY %6.1f, DT %6.1f", xPos - xPos2, yPos - yPos2, tof - tof2)
4588 << Form(" Tots %6.1f - %6.1f", dTot, dTot2);
4589 Double_t dTotSum = dTot + dTot2;
4590 Double_t dxPosM = (xPos * dTot + xPos2 * dTot2) / dTotSum;
4591 Double_t dyPosM = (yPos * dTot + yPos2 * dTot2) / dTotSum;
4592 Double_t dtofM = (tof * dTot + tof2 * dTot2) / dTotSum;
4593 pHit->SetX(dxPosM);
4594 pHit->SetY(dyPosM);
4595 pHit->SetTime(dtofM);
4596
4597 // remove merged hit at iHitInd2 and update digiMatch
4598
4599 fTofHitsColl->RemoveAt(iHitInd2);
4600 fTofDigiMatchColl->RemoveAt(iHitInd2);
4601 fTofDigiMatchColl->Compress();
4602 fTofHitsColl->Compress();
4603 LOG(debug) << "MergeClusters: Compress TClonesArrays to " << fTofHitsColl->GetEntriesFast() << ", "
4604 << fTofDigiMatchColl->GetEntriesFast();
4605 /*
4606 for(Int_t i=iHitInd2; i<fTofHitsColl->GetEntriesFast(); i++){ // update RefLinks
4607 CbmTofHit *pHiti = (CbmTofHit*) fTofHitsColl->At( i );
4608 pHiti->SetRefId(i);
4609 }
4610 */
4611 //check merged hit (cluster)
4612 //pHit->Print();
4613 }
4614 }
4615 }
4616 }
4617 }
4618 }
4619 }
4620 return kTRUE;
4621}
4622
4623static Double_t f1_xboxe(double* x, double* par)
4624{
4625 double xx = x[0];
4626 double wx = 1. - par[4] * TMath::Power(xx + par[5], 2);
4627 double xboxe = par[0] * 0.25 * (1. + TMath::Erf((xx + par[1] - par[3]) / par[2]))
4628 * (1. + TMath::Erf((-xx + par[1] + par[3]) / par[2]));
4629 return xboxe * wx;
4630}
4631
4633{
4634 TH1* h1;
4635 h1 = (TH1*) gROOT->FindObjectAny(hname);
4636 if (NULL != h1) {
4637 fit_ybox(h1, 0.);
4638 }
4639}
4640
4641void CbmTofTestBeamClusterizer::fit_ybox(TH1* h1, Double_t ysize)
4642{
4643 Double_t* fpar = NULL;
4644 fit_ybox(h1, ysize, fpar);
4645}
4646
4647void CbmTofTestBeamClusterizer::fit_ybox(TH1* h1, Double_t ysize, Double_t* fpar = NULL)
4648{
4649 TAxis* xaxis = h1->GetXaxis();
4650 Double_t Ymin = xaxis->GetXmin();
4651 Double_t Ymax = xaxis->GetXmax();
4652 TF1* f1 = new TF1("YBox", f1_xboxe, Ymin, Ymax, 6);
4653 Double_t yini = (h1->GetMaximum() + h1->GetMinimum()) * 0.5;
4654 if (ysize == 0.) ysize = Ymax * 0.8;
4655 f1->SetParameters(yini, ysize * 0.5, 1., 0., 0., 0.);
4656 // f1->SetParLimits(1,ysize*0.8,ysize*1.2);
4657 f1->SetParLimits(2, 0.2, 3.);
4658 f1->SetParLimits(3, -4., 4.);
4659 if (fpar != NULL) {
4660 Double_t fp[4];
4661 for (Int_t i = 0; i < 4; i++)
4662 fp[i] = *fpar++;
4663 for (Int_t i = 0; i < 4; i++)
4664 f1->SetParameter(2 + i, fp[i]);
4665 LOG(debug) << "Ini Fpar for " << h1->GetName() << " with "
4666 << Form(" %6.3f %6.3f %6.3f %6.3f ", fp[0], fp[1], fp[2], fp[3]);
4667 }
4668
4669 h1->Fit("YBox", "Q");
4670
4671 double res[10];
4672 double err[10];
4673 res[9] = f1->GetChisquare();
4674
4675 for (int i = 0; i < 6; i++) {
4676 res[i] = f1->GetParameter(i);
4677 err[i] = f1->GetParError(i);
4678 //cout << " FPar "<< i << ": " << res[i] << ", " << err[i] << endl;
4679 }
4680 LOG(debug) << "YBox Fit of " << h1->GetName() << " ended with chi2 = " << res[9]
4681 << Form(", strip length %7.2f +/- %5.2f, position resolution "
4682 "%7.2f +/- %5.2f at y_cen = %7.2f +/- %5.2f",
4683 2. * res[1], 2. * err[1], res[2], err[2], res[3], err[3]);
4684}
4685
4687{
4688 if (fvLastHits.size() != static_cast<size_t>(fDigiBdfPar->GetNbSmTypes()))
4689 LOG(fatal) << Form("Inconsistent LH Smtype size %lu, %d ", fvLastHits.size(), fDigiBdfPar->GetNbSmTypes());
4690
4691 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
4692 if (fvLastHits[iSmType].size() != static_cast<size_t>(fDigiBdfPar->GetNbSm(iSmType)))
4693 LOG(fatal) << Form("Inconsistent LH Sm size %lu, %d T %d", fvLastHits[iSmType].size(),
4694 fDigiBdfPar->GetNbSm(iSmType), iSmType);
4695 for (Int_t iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); iSm++) {
4696 if (fvLastHits[iSmType][iSm].size() != static_cast<size_t>(fDigiBdfPar->GetNbRpc(iSmType)))
4697 LOG(fatal) << Form("Inconsistent LH Rpc size %lu, %d TS %d%d ", fvLastHits[iSmType][iSm].size(),
4698 fDigiBdfPar->GetNbRpc(iSmType), iSmType, iSm);
4699 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
4700 if (fvLastHits[iSmType][iSm][iRpc].size() != static_cast<size_t>(fDigiBdfPar->GetNbChan(iSmType, iRpc)))
4701 LOG(fatal) << Form("Inconsistent LH RpcChannel size %lu, %d TSR %d%d%d ",
4702 fvLastHits[iSmType][iSm][iRpc].size(), fDigiBdfPar->GetNbChan(iSmType, iRpc), iSmType, iSm,
4703 iRpc);
4704 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++)
4705 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 0) {
4706 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
4707 Int_t iAddr = fTofId->SetDetectorInfo(xDetInfo);
4708 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != iAddr)
4709 LOG(fatal) << Form("Inconsistent address for Ev %8.0f in list of size %lu for "
4710 "TSRC %d%d%d%d: 0x%08x, time %f",
4711 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
4712 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
4713 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
4714 }
4715 }
4716 }
4717 }
4718 LOG(debug) << Form("LH check passed for event %8.0f", fdEvent);
4719}
4720
4722{
4723 if (fvLastHits.size() != static_cast<size_t>(fDigiBdfPar->GetNbSmTypes()))
4724 LOG(fatal) << Form("Inconsistent LH Smtype size %lu, %d ", fvLastHits.size(), fDigiBdfPar->GetNbSmTypes());
4725 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
4726 if (fvLastHits[iSmType].size() != static_cast<size_t>(fDigiBdfPar->GetNbSm(iSmType)))
4727 LOG(fatal) << Form("Inconsistent LH Sm size %lu, %d T %d", fvLastHits[iSmType].size(),
4728 fDigiBdfPar->GetNbSm(iSmType), iSmType);
4729 for (Int_t iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); iSm++) {
4730 if (fvLastHits[iSmType][iSm].size() != static_cast<size_t>(fDigiBdfPar->GetNbRpc(iSmType)))
4731 LOG(fatal) << Form("Inconsistent LH Rpc size %lu, %d TS %d%d ", fvLastHits[iSmType][iSm].size(),
4732 fDigiBdfPar->GetNbRpc(iSmType), iSmType, iSm);
4733 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
4734 if (fvLastHits[iSmType][iSm][iRpc].size() != static_cast<size_t>(fDigiBdfPar->GetNbChan(iSmType, iRpc)))
4735 LOG(fatal) << Form("Inconsistent LH RpcChannel size %lu, %d TSR %d%d%d ",
4736 fvLastHits[iSmType][iSm][iRpc].size(), fDigiBdfPar->GetNbChan(iSmType, iRpc), iSmType, iSm,
4737 iRpc);
4738 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++)
4739 while (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 0) {
4740 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
4741 Int_t iAddr = fTofId->SetDetectorInfo(xDetInfo);
4742 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != iAddr)
4743 LOG(fatal) << Form("Inconsistent address for Ev %8.0f in list of size %lu for "
4744 "TSRC %d%d%d%d: 0x%08x, time %f",
4745 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
4746 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
4747 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
4748 fvLastHits[iSmType][iSm][iRpc][iCh].front()->Delete();
4749 fvLastHits[iSmType][iSm][iRpc][iCh].pop_front();
4750 }
4751 }
4752 }
4753 }
4754 LOG(info) << Form("LH cleaning done after %8.0f events", fdEvent);
4755}
4756
4757Bool_t CbmTofTestBeamClusterizer::AddNextChan(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iLastChan, Double_t dLastPosX,
4758 Double_t dLastPosY, Double_t dLastTime, Double_t dLastTotS)
4759{
4760 //Int_t iNbSm = fDigiBdfPar->GetNbSm( iSmType); (VF) not used
4761 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
4762 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
4763 //Int_t iChType = fDigiBdfPar->GetChanType( iSmType, iRpc ); (VF) not used
4764
4765 Int_t iCh = iLastChan + 1;
4766 LOG(debug) << Form("Inspect channel TSRC %d%d%d%d at time %f, pos %f, size ", iSmType, iSm, iRpc, iCh, dLastTime,
4767 dLastPosY)
4768 << fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size();
4769 if (iCh == iNbCh) return kFALSE;
4770 if (0 == fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size()) return kFALSE;
4771 if (0 < fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size())
4772 fhNbDigiPerChan->Fill(fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size());
4773 if (1 < fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
4774 Bool_t AddedHit = kFALSE;
4775 for (size_t i1 = 0; i1 < fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size() - 1; i1++) {
4776 if (AddedHit) break;
4777 size_t i2 = i1 + 1;
4778 while (!AddedHit && i2 < fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
4779 LOG(debug) << "check digi pair " << i1 << "," << i2 << " with size "
4780 << fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].size();
4781
4782 if ((fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][i1])->GetSide()
4783 == (fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][i2])->GetSide()) {
4784 i2++;
4785 continue;
4786 } // endif same side
4787 // 2 Digis, both sides present
4788 CbmTofDigi* xDigiA = fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][i1];
4789 CbmTofDigi* xDigiB = fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh][i2];
4790 Double_t dTime = 0.5 * (xDigiA->GetTime() + xDigiB->GetTime());
4791 if (TMath::Abs(dTime - dLastTime) < fdMaxTimeDist) {
4792 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
4793 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
4794 fChannelInfo = fDigiPar->GetCell(iChId);
4795 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
4796
4797 Double_t dTimeDif = xDigiA->GetTime() - xDigiB->GetTime();
4798 Double_t dPosY = 0.;
4799 if (1 == xDigiA->GetSide())
4800 dPosY = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
4801 else
4802 dPosY = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
4803
4804 if (TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist) { // append digi pair to current cluster
4805
4806 Double_t dNClHits = (Double_t)(vDigiIndRef.size() / 2);
4807 Double_t dPosX = ((Double_t)(-iNbCh / 2 + iCh) + 0.5) * fChannelInfo->GetSizex();
4808 Double_t dTotS = xDigiA->GetTot() + xDigiB->GetTot();
4809 Double_t dNewTotS = (dLastTotS + dTotS);
4810 dLastPosX = (dLastPosX * dLastTotS + dPosX * dTotS) / dNewTotS;
4811 dLastPosY = (dLastPosY * dLastTotS + dPosY * dTotS) / dNewTotS;
4812 dLastTime = (dLastTime * dLastTotS + dTime * dTotS) / dNewTotS;
4813 dLastTotS = dNewTotS;
4814 // attach selected digis from pool
4815 Int_t Ind1 = fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][i1];
4816 Int_t Ind2 = fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][i2];
4817 vDigiIndRef.push_back(Ind1);
4818 vDigiIndRef.push_back(Ind2);
4819 // remove selected digis from pool
4820 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4821 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + i1);
4822 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4823 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + i1);
4824
4825 std::vector<int>::iterator it;
4826 it = find(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin(),
4827 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].end(), Ind2);
4828 if (it != fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].end()) {
4829 auto ipos = it - fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin();
4830 LOG(debug) << "Found i2 " << i2 << " with Ind2 " << Ind2 << " at position " << ipos;
4831 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4832 fStorDigiExp[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + ipos);
4833 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
4834 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + ipos);
4835 }
4836 else {
4837 LOG(fatal) << " Did not find i2 " << i2 << " with Ind2 " << Ind2;
4838 }
4839
4840 //if(iCh == iNbCh-1) break; //Last strip reached
4841 if (iCh != (iNbCh - 1)
4842 && AddNextChan(iSmType, iSm, iRpc, iCh, dLastPosX, dLastPosY, dLastTime, dLastTotS)) {
4843 LOG(debug) << "Added Strip " << iCh << " to cluster of size " << dNClHits;
4844 return kTRUE; // signal hit was already added
4845 }
4846 AddedHit = kTRUE;
4847 } //TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist
4848 } //TMath::Abs(dTime-dLastTime)<fdMaxTimeDist)
4849 i2++;
4850 } // while(i2 < fStorDigiExp[iSmType][iSm*iNbRpc+iRpc][iCh].size()-1 )
4851 } // end for i1
4852 } // end if size
4853 Double_t hitpos_local[3] = {3 * 0.};
4854 hitpos_local[0] = dLastPosX;
4855 hitpos_local[1] = dLastPosY;
4856 hitpos_local[2] = 0.;
4857 Double_t hitpos[3];
4858 /*TGeoNode* cNode = */ gGeoManager->GetCurrentNode();
4859 /*TGeoHMatrix* cMatrix = */ gGeoManager->GetCurrentMatrix();
4860 gGeoManager->LocalToMaster(hitpos_local, hitpos);
4861 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
4862 TVector3 hitPosErr(0.5, 0.5, 0.5); // FIXME including positioning uncertainty
4863 Int_t iChm = floor(dLastPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
4864 if (iChm < 0) iChm = 0;
4865 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
4866 Int_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
4867
4868 Int_t iNbChanInHit = vDigiIndRef.size() / 2;
4869 fviClusterMul[iSmType][iSm][iRpc]++;
4870
4871 LOG(debug) << "Save A-Hit "
4872 << Form("%2d %2d 0x%08x %3d t %f, y %f ", fiNbHits, iNbChanInHit, iDetId, iLastChan, dLastTime, dLastPosY)
4873 << ", DigiSize: " << vDigiIndRef.size();
4874 LOG(debug) << ", DigiInds: ";
4875 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
4876 LOG(debug) << " " << vDigiIndRef.at(i) << "(M" << fviClusterMul[iSmType][iSm][iRpc] << ")";
4877 }
4878 LOG(debug);
4879
4880 CbmTofHit* pHit = new CbmTofHit(iDetId, hitPos,
4881 hitPosErr, //local detector coordinates
4882 fiNbHits, // this number is used as reference!!
4883 dLastTime,
4884 vDigiIndRef.size(), // number of linked digis = 2*CluSize
4885 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
4886 Int_t(dLastTotS * 10.)); //channel -> Tot
4887 // output hit
4888 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
4889 if (fdMemoryTime > 0.) { // memorize hit
4890 LH_store(iSmType, iSm, iRpc, iChm, pHit);
4891 }
4892 else {
4893 pHit->Delete();
4894 }
4895 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
4896 for (size_t i = 0; i < vDigiIndRef.size(); i++) {
4897 Double_t dTot = ((CbmTofDigi*) (fTofCalDigisColl->At(vDigiIndRef.at(i))))->GetTot();
4898 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
4899 }
4900 fiNbHits++;
4901 vDigiIndRef.clear();
4902
4903 return kTRUE;
4904}
4905
4906void CbmTofTestBeamClusterizer::LH_store(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iChm, CbmTofHit* pHit)
4907{
4908
4909 if (fvLastHits[iSmType][iSm][iRpc][iChm].size() == 0)
4910 fvLastHits[iSmType][iSm][iRpc][iChm].push_back(pHit);
4911 else {
4912 Double_t dLastTime = pHit->GetTime();
4913 if (dLastTime >= fvLastHits[iSmType][iSm][iRpc][iChm].back()->GetTime()) {
4914 fvLastHits[iSmType][iSm][iRpc][iChm].push_back(pHit);
4915 LOG(debug) << Form(" Store LH from Ev %8.0f for TSRC %d%d%d%d, size %lu, addr 0x%08x, "
4916 "time %f, dt %f",
4917 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
4918 pHit->GetAddress(), dLastTime,
4919 dLastTime - fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime());
4920 }
4921 else {
4922 if (dLastTime
4923 >= fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime()) { // hit has to be inserted in the proper place
4924 std::list<CbmTofHit*>::iterator it;
4925 for (it = fvLastHits[iSmType][iSm][iRpc][iChm].begin(); it != fvLastHits[iSmType][iSm][iRpc][iChm].end(); ++it)
4926 if ((*it)->GetTime() > dLastTime) break;
4927 fvLastHits[iSmType][iSm][iRpc][iChm].insert(--it, pHit);
4928 Double_t deltaTime = dLastTime - (*it)->GetTime();
4929 LOG(debug) << Form("Hit inserted into LH from Ev %8.0f for TSRC "
4930 "%d%d%d%d, size %lu, addr 0x%08x, delta time %f ",
4931 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
4932 pHit->GetAddress(), deltaTime);
4933 }
4934 else { // this hit is first
4935 Double_t deltaTime = dLastTime - fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime();
4936 LOG(debug) << Form("first LH from Ev %8.0f for TSRC %d%d%d%d, size "
4937 "%lu, addr 0x%08x, delta time %f ",
4938 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
4939 pHit->GetAddress(), deltaTime);
4940 if (deltaTime == 0.) {
4941 // remove hit, otherwise double entry?
4942 pHit->Delete();
4943 }
4944 else {
4945 fvLastHits[iSmType][iSm][iRpc][iChm].push_front(pHit);
4946 }
4947 }
4948 }
4949 }
4950}
@ kTof
Time-of-flight Detector.
static Int_t iIndexDut
static FairRootManager * rootMgr
static Int_t iMess
static TFile * fHist
TClonesArray * fTofHitsColl
static Double_t StartAnalysisTime
const Int_t DetMask
static Double_t fdMemoryTime
std::vector< TH1 * > hSvel
const Int_t iNWalkSmooth
const Double_t WalkNHmin
const Int_t iNSel
const Int_t nbCldXdYBinX
const Int_t nbClDelTofBinY
const Int_t nbClWalkBinX
const Int_t nbClDelTofBinX
const Double_t dDoubleMax
const Double_t dXdYMax
const Int_t nbClWalkBinY
const Double_t MaxNbEvent
const Int_t nbCldXdYBinY
@ k14a
static Double_t StartAnalysisTime
static Double_t f1_xboxe(double *x, double *par)
static Int_t iIndexDut
std::vector< Int_t > vDigiIndRef
std::vector< CbmTofPoint * > vPtsRef
static constexpr size_t size()
Definition KfSimdPseudo.h:2
void SetTimeError(double error)
Definition CbmHit.h:91
double GetTime() const
Definition CbmHit.h:76
int32_t GetAddress() const
Definition CbmHit.h:74
double GetZ() const
Definition CbmHit.h:71
void SetTime(double time)
Definition CbmHit.h:85
const CbmLink & GetLink(int32_t i) const
Definition CbmMatch.h:39
int32_t GetNofLinks() const
Definition CbmMatch.h:42
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
void SetX(double x)
Definition CbmPixelHit.h:92
double GetY() const
Definition CbmPixelHit.h:74
void SetY(double y)
Definition CbmPixelHit.h:93
double GetX() const
Definition CbmPixelHit.h:73
static uint32_t GetUniqueAddress(uint32_t Sm, uint32_t Rpc, uint32_t Channel, uint32_t Side=0, uint32_t SmType=0, uint32_t RpcType=0)
static int32_t GetSmId(uint32_t address)
static int32_t GetRpcId(uint32_t address)
static int32_t GetSmType(uint32_t address)
static int32_t GetChannelId(uint32_t address)
Double_t GetSizey() const
Definition CbmTofCell.h:40
Double_t GetY() const
Definition CbmTofCell.h:36
Double_t GetSizex() const
Definition CbmTofCell.h:39
Double_t GetX() const
Definition CbmTofCell.h:35
Double_t GetZ() const
Definition CbmTofCell.h:37
virtual int32_t SetDetectorInfo(const CbmTofDetectorInfo detectorInfo)=0
Parameters class for the CBM ToF digitizer using beam data distributions.
Int_t GetNbSmTypes() const
void SetSigVel(Int_t iSmType, Int_t iSm, Int_t iRpc, Double_t dvel)
Int_t GetNbSm(Int_t iSmType) const
Double_t GetMaxDistAlongCh() const
Int_t GetNbChan(Int_t iSmType, Int_t iRpc) const
Int_t GetDetInd(Int_t iAddr)
Bool_t ClustUseTrackId() const
Int_t GetChanType(Int_t iSmType, Int_t iRpc) const
Int_t GetNbRpc(Int_t iSmType) const
Bool_t UseExpandedDigi() const
Double_t GetMaxTimeDist() const
Int_t GetChanOrient(Int_t iSmType, Int_t iRpc) const
Int_t GetDetUId(Int_t iDet)
Double_t GetSignalSpeed() const
Double_t GetSigVel(Int_t iSmType, Int_t iSm, Int_t iRpc) const
CbmTofCell * GetCell(Int_t i)
Int_t GetNrOfModules()
Int_t GetCellId(Int_t i)
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
double GetSide() const
Channel Side.
Definition CbmTofDigi.h:160
std::string ToString() const
void SetTot(double tot)
Definition CbmTofDigi.h:166
double GetChannel() const
Channel .
Definition CbmTofDigi.h:156
int32_t GetAddress() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:112
double GetSm() const
Sm.
Definition CbmTofDigi.h:144
double GetTime() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:131
double GetType() const
Sm Type .
Definition CbmTofDigi.h:148
double GetRpc() const
Detector aka Module aka RPC .
Definition CbmTofDigi.h:152
double GetTot() const
Alias for GetCharge.
Definition CbmTofDigi.h:140
void SetAddress(int32_t address)
Definition CbmTofDigi.h:163
void SetTime(double time)
Definition CbmTofDigi.h:165
Int_t GetCell(Int_t uniqueId)
Int_t Init(Bool_t isSimulation=kFALSE)
Int_t GetSModule(Int_t uniqueId)
Int_t GetCounter(Int_t uniqueId)
Int_t GetSMType(Int_t uniqueId)
std::vector< std::vector< std::vector< std::vector< std::vector< Double_t > > > > > fvCPWalk
std::vector< std::vector< std::vector< Int_t > > > fviClusterMul
Bool_t LoadGeometry()
Load the geometry: for now just resizing the Digis temporary vectors.
std::vector< std::vector< TH2 * > > fhTRpcCluTOffDTLastHits
std::vector< std::vector< TH2 * > > fhTRpcCluTOff
std::vector< std::vector< TProfile * > > fhSmCluFpar
std::vector< std::vector< TH2 * > > fhTRpcCluAvWalk
std::vector< TProfile * > fhSmCluSvel
std::vector< std::vector< std::vector< Double_t > > > fvdDifCh
std::vector< std::vector< std::vector< std::vector< CbmTofDigi * > > > > fStorDigiExp
virtual void fit_ybox(const char *hname)
virtual void LH_store(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iChm, CbmTofHit *pHit)
Bool_t BuildClusters()
Build clusters out of ToF Digis and store the resulting info in a TofHit.
std::vector< std::vector< TH2 * > > fhTRpcCluDelTof
std::vector< TH1 * > fhRpcDTLastHits_CluSize
std::vector< std::vector< TH2 * > > fhTRpcCluSize
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTOff
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTotOff
virtual void Finish()
Inherited from FairTask.
static CbmTofTestBeamClusterizer * fInstance
virtual ~CbmTofTestBeamClusterizer()
Destructor.
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTotGain
Bool_t DeleteGeometry()
Delete the geometry related arrays: for now just clearing the Digis temporary vectors.
std::vector< std::vector< TH1 * > > fhTRpcCluMul
std::vector< std::vector< TH2 * > > fhTRpcCluMemMulDTLastHits
std::vector< std::vector< std::vector< Int_t > > > fviTrkMul
Bool_t InitCalibParameter()
Initialize other parameters not included in parameter classes.
std::vector< std::vector< TH2 * > > fhTRpcCludXdY
std::vector< std::vector< std::vector< std::vector< TH2 * > > > > fhTRpcCluWalk
std::vector< std::vector< TH2 * > > fhTRpcCluTotDTLastHits
std::map< UInt_t, UInt_t > fDetIdIndexMap
Bool_t InitParameters()
Initialize other parameters not included in parameter classes.
std::vector< std::vector< std::vector< Double_t > > > fvdDifX
std::vector< std::vector< TH2 * > > fhTRpcCluPosition
Bool_t RegisterOutputs()
Create and register output TClonesArray of Tof Hits.
virtual InitStatus Init()
Inherited from FairTask.
virtual Bool_t AddNextChan(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iLastChan, Double_t dLastPosX, Double_t dLastPosY, Double_t dLastTime, Double_t dLastTot)
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPDelTof
std::vector< std::vector< std::vector< Double_t > > > fvdX
virtual void SetParContainers()
Inherited from FairTask.
std::vector< std::vector< TH2 * > > fhTSmCluPosition
std::vector< std::vector< TH2 * > > fhTRpcCluSizeDTLastHits
Bool_t RegisterInputs()
Recover pointer on input TClonesArray: TofPoints, TofDigis...
std::vector< std::vector< TH2 * > > fhTSmCluTRun
std::vector< std::vector< std::vector< TH2 * > > > fhRpcCluWalk
std::vector< std::vector< std::vector< Double_t > > > fvdY
std::vector< std::vector< std::vector< std::vector< Int_t > > > > fStorDigiInd
std::vector< std::vector< TH2 * > > fhTRpcCluTot
std::vector< std::vector< TH2 * > > fhTSmCluTOff
std::vector< std::vector< std::vector< Double_t > > > fvdDifY
std::vector< std::vector< std::vector< std::vector< std::list< CbmTofHit * > > > > > fvLastHits
std::vector< std::vector< std::vector< Int_t > > > fviClusterSize
virtual void Exec(Option_t *option)
Inherited from FairTask.
UInt_t GetTriggerPattern() const
Definition TTrbHeader.h:34
Double_t f1_xboxe(double *x, double *par)
Definition fit_ybox.h:6