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