CbmRoot
Loading...
Searching...
No Matches
CbmTofEventClusterizer.cxx
Go to the documentation of this file.
1/* Copyright (C) 2018-2021 PI-UHd/GSI, Heidelberg/Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann [committer] */
4
16
17// TOF Classes and includes
18#include "CbmBmonDigi.h" // in cbmdata/bmon
19#include "CbmDigiManager.h"
20#include "CbmEvent.h"
21#include "CbmMatch.h"
22#include "CbmTimeSlice.h"
23#include "CbmTofAddress.h" // in cbmdata/tof
24#include "CbmTofCalibrator.h"
25#include "CbmTofCell.h" // in tof/TofData
26#include "CbmTofCreateDigiPar.h" // in tof/TofTools
27#include "CbmTofDetectorId_v12b.h" // in cbmdata/tof
28#include "CbmTofDetectorId_v14a.h" // in cbmdata/tof
29#include "CbmTofDetectorId_v21a.h" // in cbmdata/tof
30#include "CbmTofDigi.h" // in cbmdata/tof
31#include "CbmTofDigiBdfPar.h" // in tof/TofParam
32#include "CbmTofDigiPar.h" // in tof/TofParam
33#include "CbmTofGeoHandler.h" // in tof/TofTools
34#include "CbmTofHit.h" // in cbmdata/tof
35#include "CbmTofPoint.h" // in cbmdata/tof
36#include "CbmTsEventHeader.h"
37#include "CbmVertex.h"
38#include "TTrbHeader.h"
39#include "TimesliceMetaData.h"
40
41// CBMroot classes and includes
42#include "CbmMCTrack.h"
43
44// FAIR classes and includes
45#include "FairEventHeader.h"
46#include "FairRootFileSink.h"
47#include "FairRootManager.h"
48#include "FairRunAna.h"
49#include "FairRuntimeDb.h"
50
51#include <Logger.h>
52
53// ROOT Classes and includes
54#include "TClonesArray.h"
55#include "TDirectory.h"
56#include "TF1.h"
57#include "TF2.h"
58#include "TFitResult.h"
59#include "TFitter.h"
60#include "TGeoManager.h"
61#include "TGeoPhysicalNode.h"
62#include "TH1.h"
63#include "TH2.h"
64#include "TH3.h"
65#include "TLine.h"
66#include "TMath.h"
67#include "TMinuit.h"
68#include "TProfile.h"
69#include "TROOT.h"
70#include "TRandom.h"
71#include "TRandom3.h"
72#include "TStopwatch.h"
73#include "TVector3.h"
74
75// Constants definitions
77
78// C++ Classes and includes
79#include <iomanip>
80#include <vector>
81
82// Globals
83static Int_t iIndexDut = 0;
84// const Double_t cLight=29.9792; // in cm/ns (VF) not used
86static Double_t fdStartAna10s = 0.;
87static Double_t dTLEvt = 0.;
88static Int_t iNSpill = 0;
89static Int_t iNbTs = 0;
90static int fiHitStart = 0;
91static double dTsStartTime = 0.;
92static double dTsStartTimeLast = -1.;
93const Double_t fdSpillDuration = 2.; // in seconds
94const Double_t fdSpillBreak = 0.9; // in seconds
95const Double_t dTimeRes = 0.08; // in ns
96
98static TRandom3* fRndm = new TRandom3();
99std::vector<CbmTofDigi>* fT0DigiVec;
100// std::vector< CbmTofPoint* > vPtsRef;
101
103
104/************************************************************************************/
106{
107 // if ( !fInstance ) fInstance = this;
108}
109
110CbmTofEventClusterizer::CbmTofEventClusterizer(const char* name, Int_t verbose, Bool_t writeDataInOut)
111 : FairTask(TString(name), verbose)
112 , fGeoHandler(new CbmTofGeoHandler())
113 , fTofId(NULL)
114 , fDigiPar(NULL)
115 , fChannelInfo(NULL)
116 , fDigiBdfPar(NULL)
117 , fTrbHeader(NULL)
118 , fEvtHeader(NULL)
119 , fTsHeader(NULL)
120 , fTimeSlice(NULL)
121 , fTofDigiPointMatches(NULL)
122 , fDigiMan(nullptr)
123 , fEventsColl(nullptr)
124 , fbWriteHitsInOut(writeDataInOut)
125 , fbWriteDigisInOut(writeDataInOut)
126 , fTofHitsColl(NULL)
127 , fTofDigiMatchColl(NULL)
128 , fTofHitsCollOut(NULL)
129 , fTofDigiMatchCollOut(NULL)
130 , fTofDigiPointMatchesOut(nullptr)
131 , fiNbHits(0)
132 , fVerbose(verbose)
133 , fStorDigi()
134 , fStorDigiInd()
135 , vDigiIndRef()
136 , fviClusterMul()
137 , fviClusterSize()
138 , fviTrkMul()
139 , fvdX()
140 , fvdY()
141 , fvdDifX()
142 , fvdDifY()
143 , fvdDifCh()
144 , fTofCalibrator(NULL)
145 , fhClustBuildTime(NULL)
146 , fhClustHitsDigi(NULL)
147 , fhHitsPerTracks(NULL)
148 , fhPtsPerHit(NULL)
149 , fhTimeResSingHits(NULL)
150 , fhTimeResSingHitsB(NULL)
151 , fhTimePtVsHits(NULL)
152 , fhClusterSize(NULL)
153 , fhClusterSizeType(NULL)
154 , fhTrackMul(NULL)
155 , fhClusterSizeMulti(NULL)
156 , fhTrk1MulPos(NULL)
157 , fhHiTrkMulPos(NULL)
158 , fhAllTrkMulPos(NULL)
159 , fhMultiTrkProbPos(NULL)
160 , fhDigSpacDifClust(NULL)
161 , fhDigTimeDifClust(NULL)
162 , fhDigDistClust(NULL)
163 , fhClustSizeDifX(NULL)
164 , fhClustSizeDifY(NULL)
165 , fhChDifDifX(NULL)
166 , fhChDifDifY(NULL)
167 , fhCluMulCorDutSel(NULL)
168 , fhEvCluMul(NULL)
169 , fhRpcDigiCor()
170 , fhRpcDigiMul()
171 , fhRpcDigiStatus()
172 , fhRpcDigiDTLD()
173 , fhRpcDigiDTFD()
174 , fhRpcDigiDTMul()
175 , fhRpcDigiRate()
176 , fhRpcDigiTotLeft()
177 , fhRpcDigiTotRight()
178 , fhRpcDigiTotDiff()
179 , fhRpcDigiTotMap()
180 , fhRpcCluMul()
181 , fhRpcCluRate()
182 , fhRpcCluRate10s()
183 , fhRpcCluPosition()
184 , fhRpcCluPos()
185 , fhRpcCluPositionEvol()
186 , fhRpcCluTimeEvol()
187 , fhRpcCluDelPos()
188 , fhRpcCluDelMatPos()
189 , fhRpcCluTOff()
190 , fhRpcCluDelTOff()
191 , fhRpcCluDelMatTOff()
192 , fhRpcCluTrms()
193 , fhRpcCluTot()
194 , fhRpcCluSize()
195 , fhRpcCluAvWalk()
196 , fhRpcCluAvLnWalk()
197 , fhRpcCluWalk()
198 , fhSmCluPosition()
199 , fhSmCluTOff()
200 , fhSmCluSvel()
201 , fhSmCluFpar()
202 , fhRpcDTLastHits()
203 , fhRpcDTLastHits_Tot()
204 , fhRpcDTLastHits_CluSize()
205 , fhTRpcCluMul()
206 , fhTRpcCluPosition()
207 , fhTRpcCluTOff()
208 , fhTRpcCluTofOff()
209 , fhTRpcCluTot()
210 , fhTRpcCluSize()
211 , fhTRpcCluAvWalk()
212 , fhTRpcCluDelTof()
213 , fhTRpcCludXdY()
214 , fhTRpcCluQASY()
215 , fhTRpcCluWalk()
216 , fhTRpcCluWalk2()
217 , fhTRpcCluQ2DT()
218 , fhTSmCluPosition()
219 , fhTSmCluTOff()
220 , fhTSmCluTRun()
221 , fhTRpcCluTOffDTLastHits()
222 , fhTRpcCluTotDTLastHits()
223 , fhTRpcCluSizeDTLastHits()
224 , fhTRpcCluMemMulDTLastHits()
225 , fhSeldT()
226 , fvCPDelTof()
227 , fvCPTOff()
228 , fvCPTotGain()
229 , fvCPTotOff()
230 , fvCPWalk()
231 , fvCPTOffY()
232 , fvCPTOffYBinWidth()
233 , fvCPTOffYRange()
234 , fvLastHits()
235 , fvDeadStrips()
236 , fvTimeLastDigi()
237 , fiNbSameSide(0)
238 , fhNbSameSide(NULL)
239 , fhNbDigiPerChan(NULL)
240 , fStart()
241 , fStop()
242 , dTRef(0.)
243 , fdTRefMax(0.)
244 , fCalMode(0)
245 , fCalSel(0)
246 , fCalSmAddr(0)
247 , fdCaldXdYMax(0.)
248 , fiCluMulMax(0)
249 , fTRefMode(0)
250 , fTRefHits(0)
251 , fIdMode(0)
252 , fDutId(-1)
253 , fDutSm(0)
254 , fDutRpc(0)
255 , fDutAddr(0)
256 , fSelId(0)
257 , fSelSm(0)
258 , fSelRpc(0)
259 , fSelAddr(0)
260 , fiBeamRefType(5)
261 , fiBeamRefSm(0)
262 , fiBeamRefDet(0)
263 , fiBeamRefAddr(-1)
264 , fiBeamRefMulMax(1)
265 , fiBeamAddRefMul(0)
266 , fSel2Id(-1)
267 , fSel2Sm(0)
268 , fSel2Rpc(0)
269 , fSel2Addr(0)
270 , fSel2MulMax(1)
271 , fiCluSizeMin(0)
272 , fNbCalHitMin(0)
273 , fDetIdIndexMap()
274 , fCellIdGeoMap()
275 , fviDetId()
276 , fPosYMaxScal(1.)
277 , fTRefDifMax(10.)
278 , fTotMax(100.)
279 , fTotMin(0.)
280 , fTotOff(0.)
281 , fTotMean(0.)
282 , fdDelTofMax(60.)
283 , fTotPreRange(0.)
284 , fMaxTimeDist(1.)
285 , fdChannelDeadtime(0.)
286 , fdMemoryTime(0.)
287 , fdYFitMin(1.E6)
288 , fdToDAv(0.033) // in ns/cm
289 , fEnableMatchPosScaling(kTRUE)
290 , fEnableAvWalk(kFALSE)
291 , fbPs2Ns(kFALSE)
292 , fCalParFileName("")
293 , fOutHstFileName("")
294 , fCalParFile(NULL)
295 , fiNevtBuild(0)
296 , fiMsgCnt(100)
297 , fdTOTMax(50.)
298 , fdTOTMin(0.)
299 , fdTTotMean(2.)
300 , fdMaxTimeDist(0.)
301 , fdMaxSpaceDist(0.)
302 , fdEdgeThr(0.1)
303 , fdEdgeLen(3.)
304 , fdEdgeTbias(-0.3)
305 , fdEdgeFrange(0.4)
306 , fdModifySigvel(0.)
307 , fdEvent(0)
308 , fdStartAnalysisTime(0.)
309 , fbSwapChannelSides(kFALSE)
310 , fiOutputTreeEntry(0)
311 , fiFileIndex(0)
312 , fbAlternativeBranchNames(kFALSE)
313{
314 if (!fInstance) fInstance = this;
315}
316
318{
319 if (fGeoHandler) delete fGeoHandler;
320 if (fInstance == this) fInstance = 0;
321 // DeleteHistos(); // <-- if needed ?
322}
323
324/************************************************************************************/
325// FairTasks inherited functions
327{
328 LOG(info) << "CbmTofEventClusterizer initializing... expect Digis in ns units!";
329
330 if (kFALSE == RegisterInputs()) return kFATAL;
331
332 if (kFALSE == RegisterOutputs()) return kFATAL;
333
334 if (kFALSE == InitParameters()) return kFATAL;
335
336 if (kFALSE == LoadGeometry()) return kFATAL;
337
338 if (kFALSE == InitCalibParameter()) return kFATAL;
339
340 if (kFALSE == CreateHistos()) return kFATAL;
341
342 if ((fCalMode > -1 && ((fCalMode % 10 > 7 && fDutId > -1))) || (fCalMode > 99 && fDutId < 0)) {
343 if (fiBeamRefType > -1)
345 LOG(info) << "Initialize Calibrator for Clusterizer ";
347 if (fTofCalibrator->Init() != kSUCCESS) return kFATAL;
348 return kSUCCESS;
349 }
350 switch (fIdMode) {
351 case 0:
355 if (fiBeamRefType > -1)
357 else
359 break;
360 case 1:
364 fiBeamRefDet = 0;
366 if (fiBeamRefType > -1)
368 else
370 break;
371 }
373 //TFitter::SetMaxIterations(10000); // for fit_ybox
374 TFitter::SetPrecision(0.01);
375 TFitter::SetDefaultFitter("Minuit");
376 //TVirtualFitter::SetDefaultFitter("Minuit2");
377
378
379 return kSUCCESS;
380}
381
383{
384 LOG(info) << "=> Get the digi parameters for tof";
385 //LOG(warning)<<"Return without action";
386 //return;
387 // Get Base Container
388 FairRunAna* ana = FairRunAna::Instance();
389 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
390
391 fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
392
393 LOG(info) << "found " << fDigiPar->GetNrOfModules() << " cells ";
394 fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
395}
396
397void CbmTofEventClusterizer::Exec(Option_t* option)
398{
400
402 if (fEventsColl) {
403 TStopwatch timerTs;
404 timerTs.Start();
405
406 fiNbSkip1 = 0;
407 fiNbSkip2 = 0;
408 iNbTs++;
409 fiHitStart = 0;
410 Int_t iNbHits = 0;
411 Int_t iNbCalDigis = 0;
412 fTofDigiMatchCollOut->Delete(); // costly, FIXME
413 //for(int i=0; i<fTofHitsCollOut->GetEntriesFast(); i++) delete fTofHitsCollOut->At(i);
414 fTofHitsCollOut->Delete(); // costly, FIXME
415 //fTofDigiMatchCollOut->Clear("C"); // not sufficient, memory leak
416 for (Int_t iEvent = 0; iEvent < fEventsColl->GetEntriesFast(); iEvent++) {
417 CbmEvent* tEvent = dynamic_cast<CbmEvent*>(fEventsColl->At(iEvent));
418 if (nullptr != fTsHeader && iEvent == 0) {
419 LOG(info) << "New Ts " << iNbTs << ", size " << fEventsColl->GetSize() << " at " << fTsHeader->GetTsStartTime()
420 << " with " << fEventsColl->GetEntriesFast() << " events, "
421 << " Ev0 " << (int32_t) tEvent->GetNumber() << ", " << fDigiMan->GetNofDigis(ECbmModuleId::kTof)
422 << " TOF digis + " << fDigiMan->GetNofDigis(ECbmModuleId::kBmon) << " Bmon digis ";
423 }
424 fTofDigiVec.clear();
425 //if (fTofDigisColl) fTofDigisColl->Clear("C");
426 //Int_t iNbDigis=0; (VF) not used
427 LOG(debug) << "TS event " << iEvent << " with " << tEvent->GetNofData(ECbmDataType::kBmonDigi) << " BMON and "
428 << tEvent->GetNofData(ECbmDataType::kTofDigi) << " Tof digis ";
429
430 for (auto iDigi = 0; iDigi < (int) tEvent->GetNofData(ECbmDataType::kBmonDigi); iDigi++) {
431 Int_t iDigiIndex = static_cast<Int_t>(tEvent->GetIndex(ECbmDataType::kBmonDigi, iDigi));
432 CbmTofDigi tDigi(fDigiMan->Get<CbmBmonDigi>(iDigiIndex));
433 if (tDigi.GetType() != 5) {
434 //LOG(fatal) << "Wrong T0 type " << tDigi.GetType() << ", Addr 0x" << std::hex << tDigi.GetAddress();
435 tDigi.SetAddress(0, 0, 0, 0, 5); // convert to Tof Address
436 }
437 if (tDigi.GetSide() == 1) { // HACK for May22 setup
438 tDigi.SetAddress(tDigi.GetSm(), tDigi.GetRpc(), tDigi.GetChannel() + 6, 0, tDigi.GetType());
439 }
440 fTofDigiVec.push_back(tDigi);
441 }
442 for (auto iDigi = 0; iDigi < (int) tEvent->GetNofData(ECbmDataType::kTofDigi); iDigi++) {
443 Int_t iDigiIndex = static_cast<Int_t>(tEvent->GetIndex(ECbmDataType::kTofDigi, iDigi));
444 const CbmTofDigi* tDigi = fDigiMan->Get<CbmTofDigi>(iDigiIndex);
445 fTofDigiVec.push_back(CbmTofDigi(*tDigi));
446 //new((*fTofDigisColl)[iNbDigis++]) CbmTofDigi(*tDigi);
447 }
448
449 ExecEvent(option, tEvent);
450
451 // --- In event-by-event mode: copy caldigis, hits and matches to output array and register them to event
452
453 uint uDigi0 = fTofCalDigiVecOut->size(); //starting index of current event
454 LOG(debug) << "Append " << fTofCalDigiVec->size() << " CalDigis to event " << tEvent->GetNumber();
455 for (UInt_t index = 0; index < fTofCalDigiVec->size(); index++) {
456 // for (Int_t index = 0; index < fTofCalDigisColl->GetEntriesFast(); index++){
457 CbmTofDigi* tDigi = &(fTofCalDigiVec->at(index));
458 //CbmTofDigi* tDigi = dynamic_cast<CbmTofDigi*>(fTofCalDigisColl->At(index));
459 tEvent->AddData(ECbmDataType::kTofCalDigi, iNbCalDigis);
460 fTofCalDigiVecOut->push_back(CbmTofDigi(*tDigi));
461 iNbCalDigis++;
462 //new((*fTofCalDigisCollOut)[iNbCalDigis++]) CbmTofDigi(*tDigi);
463 }
464
465 int iHit0 = iNbHits; //starting index of current event
466 LOG(debug) << "Assign " << fTofHitsColl->GetEntriesFast() << " hits to event " << tEvent->GetNumber();
467 for (Int_t index = 0; index < fTofHitsColl->GetEntriesFast(); index++) {
468 CbmTofHit* pHit = (CbmTofHit*) fTofHitsColl->At(index);
469 new ((*fTofHitsCollOut)[iNbHits]) CbmTofHit(*pHit);
470 tEvent->AddData(ECbmDataType::kTofHit, iNbHits);
471
472 CbmMatch* pDigiMatch = (CbmMatch*) fTofDigiMatchColl->At(index);
473
474 TString cstr = Form("Modify for hit %d, (%d", index, iNbHits);
475 cstr += Form(") %d links by uDigi0 %u: ", (Int_t) pDigiMatch->GetNofLinks(), uDigi0);
476
477 // update content of match object to TS array
478 CbmMatch* mDigiMatch = new CbmMatch();
479 for (Int_t iLink = 0; iLink < pDigiMatch->GetNofLinks(); iLink++) {
480 CbmLink Link = pDigiMatch->GetLink(iLink);
481 Link.SetIndex(Link.GetIndex() + uDigi0);
482 cstr += Form(" %d", (Int_t) Link.GetIndex());
483 mDigiMatch->AddLink(Link);
484 }
485 //delete pDigiMatch;
486
487 LOG(debug) << cstr;
488
489 new ((*fTofDigiMatchCollOut)[iNbHits]) CbmMatch(*mDigiMatch);
490 delete mDigiMatch;
491 //tEvent->SetMatch( (CbmMatch*)((*fTofDigiMatchCollOut)[iNbHits]) );
492 iNbHits++;
493 }
494
495 if ((fCalMode % 10 == 9 && fDutId > -1) || (fCalMode > 99 && fDutId < 0)) {
496 if (iNbHits - iHit0 > fNbCalHitMin) { // outsource all calibration actions
497 LOG(debug) << "Call Calibrator with fiHitStart = " << fiHitStart << ", entries "
498 << fTofHitsCollOut->GetEntriesFast();
499 CbmTofHit* pHit = (CbmTofHit*) fTofHitsCollOut->At(fiHitStart); // use most early hit as reference
501 fTofCalibrator->FillCalHist(pHit, fCalMode, tEvent);
502 else {
504 CbmTofHit* pRef = NULL;
506 }
507 }
508 }
509 }
510
511 fiHitStart += iNbHits - iHit0;
512 //fTofDigisColl->Delete();
513 fTofDigiVec.clear();
514 //fTofCalDigi->Delete();//Clear("C"); //otherwise memoryleak! FIXME
515 fTofCalDigiVec->clear();
516 fTofHitsColl->Delete(); //Clear("C");
517 fTofDigiMatchColl->Delete(); //Clear("C");
518 }
519 if (0 < fiNbSkip1) {
520 //
521 LOG(info) << "Total Skip1 Digi nb " << fiNbSkip1;
522 }
523 if (0 < fiNbSkip2) {
524 //
525 LOG(info) << "Total Skip2 Digi nb " << fiNbSkip2;
526 }
527
529 timerTs.Stop();
530 LOG(debug) << GetName() << "::Exec: real time=" << timerTs.RealTime() << " CPU time=" << timerTs.CpuTime();
531 fProcessTime += timerTs.RealTime();
535
536 std::stringstream logOut;
537 logOut << std::setw(20) << std::left << GetName() << " [";
538 logOut << std::fixed << std::setw(8) << std::setprecision(1) << std::right << timerTs.RealTime() * 1000. << " ms] ";
539 logOut << "TS " << iNbTs;
540 logOut << ", NofEvents " << fEventsColl->GetEntriesFast();
541 logOut << ", hits " << fiHitStart << ", time/1k-hit " << std::setprecision(4)
542 << timerTs.RealTime() * 1e6 / fiHitStart << " [ms]";
543 LOG(info) << logOut.str();
544 }
545 else {
546 // fTofDigisColl=fTofRawDigisColl;
547 // (VF) This does not work here. The digi manager does not foresee to add
548 // new data to the input array. So, I here copy the input digis into
549 // the array fTofDigisColl. Not very efficient, but temporary only, until
550 // also the internal data representations are changed to std::vectors.
551
552 fTofDigiVec.clear();
553 //if (fTofDigisColl) fTofDigisColl->Clear("C");
554 // Int_t iNbDigis=0; (VF) not used
555 if (NULL != fT0DigiVec) // 2022 data
556 for (Int_t iDigi = 0; iDigi < (int) (fT0DigiVec->size()); iDigi++) {
557 CbmTofDigi tDigi = fT0DigiVec->at(iDigi);
558 if (tDigi.GetType() != 5)
559 LOG(fatal) << "Wrong T0 type " << tDigi.GetType() << ", Addr 0x" << std::hex << tDigi.GetAddress();
560 if (tDigi.GetSide() == 1) { // HACK for May22 setup
561 tDigi.SetAddress(tDigi.GetSm(), tDigi.GetRpc(), tDigi.GetChannel() + 6, 0, tDigi.GetType());
562 }
563 fTofDigiVec.push_back(CbmTofDigi(tDigi));
564 }
565 else { // MC
566 /*
567 for (Int_t iDigi = 0; iDigi < fDigiMan->GetNofDigis(ECbmModuleId::kBmon); iDigi++) {
568 const CbmTofDigi* tDigi = fDigiMan->Get<CbmTofDigi>(iDigi);
569 }
570 */
571 }
572 for (Int_t iDigi = 0; iDigi < fDigiMan->GetNofDigis(ECbmModuleId::kTof); iDigi++) {
573 const CbmTofDigi* tDigi = fDigiMan->Get<CbmTofDigi>(iDigi);
574 fTofDigiVec.push_back(CbmTofDigi(*tDigi));
575 //new((*fTofDigisColl)[iNbDigis++]) CbmTofDigi(*tDigi);
576 }
577 ExecEvent(option);
578 }
579}
580
581void CbmTofEventClusterizer::ExecEvent(Option_t* /*option*/, CbmEvent* tEvent)
582{
583 // Clear output arrays
584 //fTofCalDigisColl->Delete(); //otherwise memoryleak if 'CbmDigi::fMatch' points to valid MC match objects (simulation)! FIXME
585 fTofCalDigiVec->clear();
586 //fTofHitsColl->Clear("C");
587 fTofHitsColl->Delete(); // Computationally costly!, but hopefully safe
588 //for (Int_t i=0; i<fTofDigiMatchColl->GetEntriesFast(); i++) ((CbmMatch *)(fTofDigiMatchColl->At(i)))->ClearLinks(); // FIXME, try to tamper memory leak (did not help)
589 //fTofDigiMatchColl->Clear("C+L"); // leads to memory leak
590 fTofDigiMatchColl->Delete();
591 FairRootFileSink* bla = (FairRootFileSink*) FairRootManager::Instance()->GetSink();
592 if (bla) fiOutputTreeEntry = ((FairRootFileSink*) FairRootManager::Instance()->GetSink())->GetOutTree()->GetEntries();
593
594 // Check for corruption
595 if (fTofDigiVec.size() > 20. * fDigiBdfPar->GetNbDet()) { // FIXME constant in code, skip this event
596 LOG(warn) << "Skip processing of Tof DigiEvent with " << fTofDigiVec.size() << " digis ";
597 return;
598 }
599 fiNbHits = 0;
600 if (fEvtHeader != NULL) {
601 dTsStartTime = fEvtHeader->GetEventTime();
602 if (fTsHeader != NULL) dTsStartTime = static_cast<double>(fTsHeader->GetTsStartTime());
604 LOG(debug) << Form("BuildClu for event %d at tTS = %f ", (int) fdEvent, dTsStartTime);
606 }
607 }
608 else
609 LOG(fatal) << "No EvtHeader found!";
610
611 fStart.Set();
612
614
615 //MergeClusters(); // needs update
616
617 fStop.Set();
618
619 fdEvent++;
620 FillHistos(tEvent);
621}
622
623/************************************************************************************/
625{
626 FairLogger::GetLogger()->SetLogScreenLevel("info");
627 LOG(info) << "Finish with " << fdEvent << " processed events";
628
630 LOG(info) << "=====================================";
631 LOG(info) << GetName() << ": Finish run";
632 LOG(info) << GetName() << ": Run summary ";
633 LOG(info) << GetName() << ": Processing time : " << std::fixed << std::setprecision(3) << fProcessTime;
634 LOG(info) << GetName() << ": Nr of events : " << fdEvent;
635 LOG(info) << GetName() << ": Nr of input digis : " << fuNbDigis;
636 LOG(info) << GetName() << ": Nr of produced hits : " << fuNbHits;
637 LOG(info) << GetName() << ": Nr of hits / event : " << std::fixed << std::setprecision(2)
638 << (fdEvent > 0 ? fuNbHits / fdEvent : 0);
639 LOG(info) << GetName() << ": Nr of hits / digis : " << std::fixed << std::setprecision(2)
640 << (fuNbDigis > 0 ? fuNbHits / (Double_t) fuNbDigis : 0);
641 LOG(info) << "=====================================";
642
643 if (fdEvent < 100) return; // don't save histos with insufficient statistics
644 if (fCalMode < 0) return;
645 if (fCalMode % 10 < 8 && fDutId > -1) {
646 WriteHistos();
647 }
648 else {
649 if ((fCalMode % 10 > 7 && fDutId > -1) || (fCalMode > 99 && fDutId < 0)) {
651 }
652 }
653
654 // Prevent them from being sucked in by the CbmHadronAnalysis WriteHistograms method
655 // DeleteHistos();
656 if (fdMemoryTime > 0.) CleanLHMemory();
657 //delete fDigiPar;
658}
659
660void CbmTofEventClusterizer::Finish(Double_t calMode)
661{
662 SetCalMode(calMode);
663 Finish();
664}
665
666/************************************************************************************/
667// Functions common for all clusters approximations
669{
670 FairRootManager* fManager = FairRootManager::Instance();
671
672 if (NULL == fManager) {
673 LOG(error) << "CbmTofEventClusterizer::RegisterInputs => Could not find "
674 "FairRootManager!!!";
675 return kFALSE;
676 } // if( NULL == fTofDigisColl)
677
678 fTofDigiPointMatches = fManager->InitObjectAs<std::vector<CbmMatch> const*>("TofDigiMatch");
679 if (NULL == fTofDigiPointMatches)
680 LOG(info) << "No tof digi to point matches in the input file";
681 else
682 LOG(info) << "Found tof digi to point matches in the input file";
683
684 fEventsColl = dynamic_cast<TClonesArray*>(fManager->GetObject("Event"));
685 if (NULL == fEventsColl) fEventsColl = dynamic_cast<TClonesArray*>(fManager->GetObject("CbmEvent"));
686
687 if (NULL == fEventsColl) LOG(info) << "CbmEvent not found in input file, assume eventwise input";
688
690 fDigiMan->Init();
692 LOG(error) << GetName() << ": No Tof digi input!";
693 return kFALSE;
694 }
696 LOG(info) << GetName() << ": separate BMON digi input!";
697 //fBmonDigiVec = fManager->InitObjectAs<std::vector<CbmTofDigi> const*>("TzdDigi");
698 }
699 else {
700 LOG(info) << "No separate BMON digi input found.";
701 } // if( ! fBmonDigiVec )
702
703 fTrbHeader = (TTrbHeader*) fManager->GetObject("TofTrbHeader.");
704 if (NULL == fTrbHeader) {
705 LOG(info) << "CbmTofEventClusterizer::RegisterInputs => Could not get "
706 "TofTrbHeader Object";
707 }
708
709 fEvtHeader = dynamic_cast<FairEventHeader*>(fManager->GetObject("EventHeader."));
710 if (NULL == fEvtHeader) {
711 LOG(fatal) << "CbmTofEventClusterizer::RegisterInputs => Could not get EvtHeader Object";
712 }
713 fTsHeader = fManager->InitObjectAs<CbmTsEventHeader const*>("EventHeader."); //for data
714 if (NULL == fTsHeader) {
715 LOG(info) << "CbmTofEventClusterizer::RegisterInputs => Could not get TsHeader Object";
716 fTimeSlice = fManager->InitObjectAs<CbmTimeSlice const*>("TimeSlice."); // MC
717 if (NULL == fTimeSlice) {
718 LOG(info) << "CbmTofEventClusterizer::RegisterInputs => Could not get TimeSlice Object";
719 }
720 }
721
722 if (NULL == fEventsColl) {
723 //fTofDigisColl = new TClonesArray("CbmTofDigi");
724 }
725 else {
726 // time based input
727 LOG(info) << "CbmEvent found in input file, assume time based input";
728 //fTofDigisColl = new TClonesArray("CbmTofDigi");
729 }
730
731 return kTRUE;
732}
734{
735 FairRootManager* rootMgr = FairRootManager::Instance();
736 // FairRunAna* ana = FairRunAna::Instance(); (VF) not used
737
738 rootMgr->InitSink();
739
740 //fTofCalDigisColl = new TClonesArray("CbmTofDigi");
741 fTofCalDigiVec = new std::vector<CbmTofDigi>();
742
743 fTofHitsColl = new TClonesArray("CbmTofHit", 100);
744
745 fTofDigiMatchColl = new TClonesArray("CbmMatch", 100);
746
747 TString tHitBranchName;
748 TString tHitDigiMatchBranchName;
749
751 tHitBranchName = "ATofHit";
752 tHitDigiMatchBranchName = "ATofDigiMatch";
753 }
754 else {
755 tHitBranchName = "TofHit";
756 tHitDigiMatchBranchName = "TofHitCalDigiMatch";
757 }
758
759 if (NULL == fEventsColl) {
760 // Flag check to control whether digis are written in output root file
761 //rootMgr->Register( "TofCalDigi","Tof", fTofCalDigisColl, fbWriteDigisInOut);
762 rootMgr->RegisterAny("TofCalDigi", fTofCalDigiVec, fbWriteDigisInOut);
763
764 // Flag check to control whether digis are written in output root file
765 rootMgr->Register(tHitBranchName, "Tof", fTofHitsColl, fbWriteHitsInOut);
767
768 rootMgr->Register(tHitDigiMatchBranchName, "Tof", fTofDigiMatchColl, fbWriteHitsInOut);
769 LOG(info) << Form("Register DigiMatch in TS mode at %p with %d", fTofDigiMatchColl, (int) fbWriteHitsInOut);
771
772 if (NULL != fTofDigiPointMatches) {
773 fTofDigiPointMatchesOut = new std::vector<CbmMatch>();
774 rootMgr->RegisterAny("TofCalDigiMatch", fTofDigiPointMatchesOut, fbWriteDigisInOut);
775 }
776 }
777 else { // CbmEvent - mode
778 //fTofCalDigisCollOut = new TClonesArray("CbmTofDigi");
779 fTofCalDigiVecOut = new std::vector<CbmTofDigi>();
780 fTofHitsCollOut = new TClonesArray("CbmTofHit", 10000);
781 fTofDigiMatchCollOut = new TClonesArray("CbmMatch", 10000);
782
783 //rootMgr->Register( "TofCalDigi","Tof", fTofCalDigisCollOut, fbWriteDigisInOut);
784 rootMgr->RegisterAny("TofCalDigi", fTofCalDigiVecOut, fbWriteDigisInOut);
785 rootMgr->Register(tHitBranchName, "Tof", fTofHitsCollOut, fbWriteHitsInOut);
786 rootMgr->Register(tHitDigiMatchBranchName, "Tof", fTofDigiMatchCollOut, fbWriteHitsInOut);
787 LOG(info) << Form("Register DigiMatch in event mode at %p with %d ", fTofDigiMatchCollOut, (int) fbWriteHitsInOut);
788
789 if (NULL != fTofDigiPointMatches) {
790 fTofDigiPointMatchesOut = new std::vector<CbmMatch>();
791 rootMgr->RegisterAny("TofCalDigiMatch", fTofDigiPointMatchesOut, fbWriteDigisInOut);
792 }
793 }
794 LOG(info) << "out branches: " << tHitBranchName << ", " << tHitDigiMatchBranchName;
795 return kTRUE;
796}
798{
799
800 // Initialize the TOF GeoHandler
801 Bool_t isSimulation = kFALSE;
802 LOG(info) << "CbmTofEventClusterizer::InitParameters - Geometry, Mapping, ... ??";
803
804 // Get Base Container
805 FairRun* ana = FairRun::Instance();
806 FairRuntimeDb* rtdb = ana->GetRuntimeDb();
807
808 Int_t iGeoVersion = fGeoHandler->Init(isSimulation);
809 if (k14a > iGeoVersion) {
810 LOG(error) << "CbmTofEventClusterizer::InitParameters => Only compatible "
811 "with geometries after v14a !!!";
812 return kFALSE;
813 }
814 if (iGeoVersion == k14a)
816 else
818
819 // create digitization parameters from geometry file
820 CbmTofCreateDigiPar* tofDigiPar = new CbmTofCreateDigiPar("TOF Digi Producer", "TOF task");
821 LOG(info) << "Create DigiPar ";
822 tofDigiPar->Init();
823
824 fDigiPar = (CbmTofDigiPar*) (rtdb->getContainer("CbmTofDigiPar"));
825 if (0 == fDigiPar) {
826 LOG(error) << "CbmTofEventClusterizer::InitParameters => Could not obtain "
827 "the CbmTofDigiPar ";
828 return kFALSE;
829 }
830
831 fDigiBdfPar = (CbmTofDigiBdfPar*) (rtdb->getContainer("CbmTofDigiBdfPar"));
832 if (0 == fDigiBdfPar) {
833 LOG(error) << "CbmTofEventClusterizer::InitParameters => Could not obtain "
834 "the CbmTofDigiBdfPar ";
835 return kFALSE;
836 }
837
838 rtdb->initContainers(ana->GetRunId());
839
840 LOG(info) << "CbmTofEventClusterizer::InitParameter: currently " << fDigiPar->GetNrOfModules() << " digi cells ";
841
844
846 fdMaxTimeDist = fMaxTimeDist; // modify default
848 * 0.5; // cut consistently on positions (with default signal velocity)
849 }
850
851 LOG(info) << " BuildCluster with MaxTimeDist " << fdMaxTimeDist << ", MaxSpaceDist " << fdMaxSpaceDist;
852
853 if (fiCluMulMax == 0) fiCluMulMax = 100;
854 if (fOutHstFileName == "") {
855 fOutHstFileName = "./tofEventClust.hst.root";
856 }
857
858 LOG(info) << " Hst Output filename = " << fOutHstFileName;
859
860 LOG(info) << "<I> BeamRefType = " << fiBeamRefType << ", Sm " << fiBeamRefSm << ", Det " << fiBeamRefDet
861 << ", MulMax " << fiBeamRefMulMax;
862
863 LOG(info) << "<I> EnableMatchPosScaling: " << fEnableMatchPosScaling;
864
865 return kTRUE;
866}
867/************************************************************************************/
869{
870 // dimension and initialize calib parameter
871 // Int_t iNbDet = fDigiBdfPar->GetNbDet(); (VF) not used
872 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
873
874 if (fTotMean != 0.) fdTTotMean = fTotMean; // adjust target mean for TOT
875
876 fvCPTOff.resize(iNbSmTypes);
877 fvCPTotGain.resize(iNbSmTypes);
878 fvCPTotOff.resize(iNbSmTypes);
879 fvCPWalk.resize(iNbSmTypes);
880 fvCPDelTof.resize(iNbSmTypes);
881 fvCPTOffY.resize(iNbSmTypes);
882 fvCPTOffYBinWidth.resize(iNbSmTypes);
883 fvCPTOffYRange.resize(iNbSmTypes);
884 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
885 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
886 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
887 fvCPTOff[iSmType].resize(iNbSm * iNbRpc);
888 fvCPTotGain[iSmType].resize(iNbSm * iNbRpc);
889 fvCPTotOff[iSmType].resize(iNbSm * iNbRpc);
890 fvCPWalk[iSmType].resize(iNbSm * iNbRpc);
891 fvCPTOffY[iSmType].resize(iNbSm * iNbRpc);
892 fvCPTOffYBinWidth[iSmType].resize(iNbSm * iNbRpc);
893 fvCPTOffYRange[iSmType].resize(iNbSm * iNbRpc);
894 fvCPDelTof[iSmType].resize(iNbSm * iNbRpc);
895 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
896 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
897 // LOG(info)<<Form(" fvCPDelTof resize for SmT %d, R %d, B %d ",iSmType,iNbSm*iNbRpc,nbClDelTofBinX)
898 // ;
899 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc].resize(nbClDelTofBinX);
900 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
901 // LOG(info)<<Form(" fvCPDelTof for SmT %d, R %d, B %d",iSmType,iSm*iNbRpc+iRpc,iBx);
902 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx].resize(iNSel);
903 for (Int_t iSel = 0; iSel < iNSel; iSel++)
904 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] = 0.; // initialize
905 }
906 fvCPTOffYBinWidth[iSmType][iSm * iNbRpc + iRpc] = 0.; // initialize
907 fvCPTOffYRange[iSmType][iSm * iNbRpc + iRpc] = 0.; // initialize
908
909 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc);
910 fvCPTOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
911 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
912 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
913 fvCPWalk[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
914 Int_t nbSide = 2 - fDigiBdfPar->GetChanType(iSmType, iRpc);
915 for (Int_t iCh = 0; iCh < iNbChan; iCh++) {
916 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
917 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
918 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
919 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
920 for (Int_t iSide = 0; iSide < nbSide; iSide++) {
921 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.; //initialize
922 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 1.; //initialize
923 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.; //initialize
924 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide].resize(nbClWalkBinX);
925 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
926 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide][iWx] = 0.;
927 }
928 }
929 }
930 }
931 }
932 }
933 LOG(info) << "CbmTofEventClusterizer::InitCalibParameter: defaults set";
934
936 // <= To prevent histos from being sucked in by the param file of the TRootManager!
937 TFile* oldFile = gFile;
938 TDirectory* oldDir = gDirectory;
939
940 if (kTRUE) {
941
942 LOG(info) << "CbmTofEventClusterizer::InitCalibParameter: read histos from "
943 << "file " << fCalParFileName;
944
945 // read parameter from histos
946 if (fCalParFileName.IsNull()) return kTRUE;
947
948 fCalParFile = new TFile(fCalParFileName, "READ");
949 if (NULL == fCalParFile) {
950 if (fCalMode % 10 == 9) { //modify reference file name
951 int iCalMode = fCalParFileName.Index("tofClust") - 3;
952 fCalParFileName(iCalMode) = '3';
953 LOG(info) << "Modified CalFileName = " << fCalParFileName;
954 fCalParFile = new TFile(fCalParFileName, "update");
955 if (NULL == fCalParFile)
956 LOG(fatal) << "CbmTofEventClusterizer::InitCalibParameter: "
957 << "file " << fCalParFileName << " does not exist!";
958
959 return kTRUE;
960 }
961 LOG(fatal) << "Calibration parameter file not existing!";
962 }
963 fhSmCluSvel.resize(iNbSmTypes);
964 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
965 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
966 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
967 if (iNbSm > 0 && NULL == fhSmCluSvel[iSmType]) {
968 TProfile* hSvel = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Svel", iSmType));
969 if (NULL == hSvel)
970 LOG(warn) << "hSvel not found in " << gDirectory->GetName();
971 else {
972 fhSmCluSvel[iSmType] = (TProfile*) hSvel->Clone();
973 LOG(info) << fhSmCluSvel[iSmType]->GetName() << " cloned from " << gDirectory->GetName();
974 }
975 }
976 TDirectory* curdir = gDirectory;
977 for (Int_t iSm = 0; iSm < iNbSm; iSm++)
978 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
979 // update default parameter
980 if (NULL != fhSmCluSvel[iSmType]) {
981 Double_t Vscal = fhSmCluSvel[iSmType]->GetBinContent(iSm * iNbRpc + iRpc + 1);
982 if (Vscal == 0.) Vscal = 1.;
983 if (Vscal < 0.8) {
984 LOG(warn) << "Fix parameter value of signal velocity TSR " << iSmType << iSm << iRpc << ": " << Vscal;
985 Vscal = 0.8;
986 }
987 if (Vscal > 1.2) {
988 LOG(warn) << "Fix parameter value of signal velocity TSR " << iSmType << iSm << iRpc << ": " << Vscal;
989 Vscal = 1.2;
990 }
991 //Vscal *= fdModifySigvel; //1.03; // testing the effect of wrong signal velocity, FIXME
992
993 int iUCellId = CbmTofAddress::GetUniqueAddress(iSm, 0, 0, 0, iSmType);
994 fChannelInfo = fDigiPar->GetCell(iUCellId);
996
997 fDigiBdfPar->SetSigVel(iSmType, iSm, iRpc, fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * Vscal);
998 LOG(debug) << "Modify " << iSmType << iSm << iRpc << " Svel by " << Vscal << " to "
999 << fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
1000 }
1001 else {
1002 LOG(warn) << "Svel modifier histo not found in " << curdir->GetName();
1003 }
1004 TH2D* htempPos_pfx =
1005 (TH2D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx", iSmType, iSm, iRpc));
1006 TH2D* htempTOff_pfx =
1007 (TH2D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx", iSmType, iSm, iRpc));
1008 TH1D* htempTot_Mean =
1009 (TH1D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Mean", iSmType, iSm, iRpc));
1010 TH1D* htempTot_Off =
1011 (TH1D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Off", iSmType, iSm, iRpc));
1012 if (NULL != htempPos_pfx && NULL != htempTOff_pfx && NULL != htempTot_Mean && NULL != htempTot_Off) {
1013 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
1014 //Int_t iNbinTot = htempTot_Mean->GetNbinsX();//not used any more
1015 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
1016 for (Int_t iSide = 0; iSide < 2; iSide++) {
1017 Double_t TotMean = htempTot_Mean->GetBinContent(iCh * 2 + 1 + iSide); //nh +1 empirical(?)
1018 if (0.001 < TotMean) {
1019 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] *= fdTTotMean / TotMean;
1020 }
1021 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = htempTot_Off->GetBinContent(iCh * 2 + 1 + iSide);
1022 }
1023 Double_t YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1); //nh +1 empirical(?)
1024 Double_t TMean = ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1);
1025 if (std::isnan(YMean) || std::isnan(TMean)) {
1026 LOG(warn) << "Invalid calibration for TSRC " << iSmType << iSm << iRpc << iCh << ", use default!";
1027 continue;
1028 }
1029 //Double_t dTYOff=YMean/fDigiBdfPar->GetSignalSpeed() ;
1030 Double_t dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
1031 if (5 == iSmType || 8 == iSmType) dTYOff = 0.; // no valid Y positon for pad counters
1032 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
1033 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
1034 /*
1035 if (iSmType==6 && iSm==0 && iRpc==1) {
1036 LOG(info) << "Skip loading other calib parameters for TSR "<<iSmType<<iSm<<iRpc
1037 ;
1038 continue; // skip for inspection
1039 }
1040 */
1041 if (5 == iSmType || 8 == iSmType) { // for PAD counters
1042 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
1043 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0];
1044 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
1045 }
1046 //if(iSmType==0 && iSm==4 && iRpc==2 && iCh==26)
1047 if (iSmType == 0 && iSm == 2 && iRpc == 0)
1048 //if (iSmType == 9 && iSm == 0 && iRpc == 0 && iCh == 10) // select specific channel
1049 LOG(debug) << "InitCalibParameter:"
1050 << " TSRC " << iSmType << iSm << iRpc << iCh
1051 << Form(": YMean %6.3f, TYOff %6.3f, TMean %6.3f", YMean, dTYOff, TMean) << " -> "
1052 << Form(" TOff %f, %f, TotG %f, %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
1053 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
1054 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
1055 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
1056 //<< ", NbinTot " << iNbinTot;
1057
1058 TH1D* htempWalk0 = (TH1D*) gDirectory->FindObjectAny(
1059 Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
1060 TH1D* htempWalk1 = (TH1D*) gDirectory->FindObjectAny(
1061 Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
1062 if (NULL == htempWalk0 && NULL == htempWalk1) { // regenerate Walk histos
1063 int iSide = 0;
1064 htempWalk0 =
1065 new TH1D(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh),
1066 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot [a.u.]; #DeltaT [ns]", iSmType,
1067 iSm, iRpc, iCh, iSide),
1069 iSide = 1;
1070 htempWalk1 =
1071 new TH1D(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh),
1072 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot [a.u.]; #DeltaT [ns]", iSmType,
1073 iSm, iRpc, iCh, iSide),
1075 }
1076 if (NULL != htempWalk0 && NULL != htempWalk1) { // reinitialize Walk array
1077 LOG(debug) << "Initialize Walk correction for "
1078 << Form(" SmT%01d_sm%03d_rpc%03d_Ch%03d", iSmType, iSm, iRpc, iCh);
1079 if (htempWalk0->GetNbinsX() != nbClWalkBinX)
1080 LOG(error) << "CbmTofEventClusterizer::InitCalibParameter: "
1081 "Inconsistent Walk histograms";
1082 for (Int_t iBin = 0; iBin < nbClWalkBinX; iBin++) {
1083 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin] = htempWalk0->GetBinContent(iBin + 1);
1084 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin] = htempWalk1->GetBinContent(iBin + 1);
1085 if (iSmType == 0 && iSm == 0 && iRpc == 2 && iCh == 15) // debugging
1086 LOG(debug) << Form("Read new SmT%01d_sm%03d_rpc%03d_Ch%03d bin %d cen %f walk %f %f", iSmType, iSm,
1087 iRpc, iCh, iBin, htempWalk0->GetBinCenter(iBin + 1),
1088 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin],
1089 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin]);
1090 if (5 == iSmType || 8 == iSmType) { // Pad structure, enforce consistency
1091 if (fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin]
1092 != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin]) {
1093 LOG(fatal) << "Inconsisten walk values for TSRC " << iSmType << iSm << iRpc << iCh << ", Bin "
1094 << iBin << ": " << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin] << ", "
1095 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin];
1096 }
1097 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin] =
1098 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin];
1099 htempWalk1->SetBinContent(iBin + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin]);
1100 }
1101 }
1102 }
1103 else {
1104 LOG(info) << "No Walk histograms for TSRC " << iSmType << iSm << iRpc << iCh;
1105 }
1106 }
1107 // look for TcorY corrections
1108 LOG(debug) << "Check for TCorY in " << gDirectory->GetName();
1109 TH1* hTCorY =
1110 (TH1*) gDirectory->FindObjectAny(Form("calXY_SmT%d_sm%03d_rpc%03d_TOff_z_all_TcorY", iSmType, iSm, iRpc));
1111 if (NULL != hTCorY) {
1112 fvCPTOffYBinWidth[iSmType][iSm * iNbRpc + iRpc] = hTCorY->GetBinWidth(0);
1113 fvCPTOffYRange[iSmType][iSm * iNbRpc + iRpc] = hTCorY->GetXaxis()->GetXmax();
1114 LOG(debug) << "Initialize TCorY: TSR " << iSmType << iSm << iRpc << ", Bwid "
1115 << fvCPTOffYBinWidth[iSmType][iSm * iNbRpc + iRpc] << ", Range "
1116 << fvCPTOffYRange[iSmType][iSm * iNbRpc + iRpc];
1117 fvCPTOffY[iSmType][iSm * iNbRpc + iRpc].resize(hTCorY->GetNbinsX());
1118 for (int iB = 0; iB < hTCorY->GetNbinsX(); iB++) {
1119 //LOG(info) << "iB " << iB <<": " << hTCorY->GetBinContent(iB+1);
1120 fvCPTOffY[iSmType][iSm * iNbRpc + iRpc][iB] = hTCorY->GetBinContent(iB + 1);
1121 }
1122 }
1123 }
1124 else {
1125 LOG(warning) << " Calibration histos " << Form("cl_SmT%01d_sm%03d_rpc%03d_XXX", iSmType, iSm, iRpc)
1126 << " not found. ";
1127 }
1128 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1129 TH1D* htmpDelTof = (TH1D*) gDirectory->FindObjectAny(
1130 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
1131 if (NULL == htmpDelTof) {
1132 LOG(debug) << " Histos " << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel)
1133 << " not found. ";
1134 continue;
1135 }
1136 LOG(debug) << " Load DelTof from histos "
1137 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel) << ".";
1138 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
1139 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] += htmpDelTof->GetBinContent(iBx + 1);
1140 }
1141
1142 // copy Histo to memory
1143 // TDirectory * curdir = gDirectory;
1144 gDirectory->cd(oldDir->GetPath());
1145 TH1D* h1DelTof =
1146 (TH1D*) htmpDelTof->Clone(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
1147
1148 LOG(debug) << " copy histo " << h1DelTof->GetName() << " to directory " << oldDir->GetName();
1149 gDirectory->cd(curdir->GetPath());
1150 }
1151 }
1152 }
1153 }
1154 // fCalParFile->Delete();
1156 // <= To prevent histos from being sucked in by the param file of the TRootManager!
1157 gFile = oldFile;
1158 gDirectory = oldDir;
1159 LOG(info) << "CbmTofEventClusterizer::InitCalibParameter: initialization done";
1160 return kTRUE;
1161}
1162/************************************************************************************/
1164{
1165 LOG(info) << "CbmTofEventClusterizer::LoadGeometry starting for " << fDigiBdfPar->GetNbDet()
1166 << " described detectors, " << fDigiPar->GetNrOfModules() << " geometrically known cells ";
1167 fCellIdGeoMap.clear();
1168 Int_t iNrOfCells = fDigiPar->GetNrOfModules();
1169 LOG(info) << "Digi Parameter container contains " << iNrOfCells << " cells.";
1170 for (Int_t icell = 0; icell < iNrOfCells; ++icell) {
1171
1172 Int_t cellId = fDigiPar->GetCellId(icell); // cellId is assigned in CbmTofCreateDigiPar
1173 fChannelInfo = fDigiPar->GetCell(cellId);
1174
1175 Int_t smtype = fGeoHandler->GetSMType(cellId);
1176 Int_t smodule = fGeoHandler->GetSModule(cellId);
1177 Int_t module = fGeoHandler->GetCounter(cellId);
1178 Int_t cell = fGeoHandler->GetCell(cellId);
1179
1180 Double_t x = fChannelInfo->GetX();
1181 Double_t y = fChannelInfo->GetY();
1182 Double_t z = fChannelInfo->GetZ();
1183 Double_t dx = fChannelInfo->GetSizex();
1184 Double_t dy = fChannelInfo->GetSizey();
1185 LOG(debug) << "-I- InitPar " << icell << " Id: " << Form("0x%08x", cellId) << " " << cell << " tmcs: " << smtype
1186 << " " << smodule << " " << module << " " << cell << " x=" << Form("%6.2f", x)
1187 << " y=" << Form("%6.2f", y) << " z=" << Form("%6.2f", z) << " dx=" << dx << " dy=" << dy;
1188
1189 TGeoNode* fNode = // prepare local->global trafo
1190 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
1191 LOG(debug2) << Form(" Node at (%6.1f,%6.1f,%6.1f) : 0x%p", fChannelInfo->GetX(), fChannelInfo->GetY(),
1192 fChannelInfo->GetZ(), fNode);
1193 fCellIdGeoMap[cellId] = gGeoManager->MakePhysicalNode();
1194
1195 if (icell == 0) {
1196 TGeoHMatrix* cMatrix = gGeoManager->GetCurrentMatrix();
1197 fNode->Print();
1198 fDigiPar->GetNode(cellId)->Print();
1199 cMatrix->Print();
1200 }
1201 }
1202
1203 Int_t iNbDet = fDigiBdfPar->GetNbDet();
1204 fvDeadStrips.resize(iNbDet);
1205 fvTimeLastDigi.resize(iNbDet);
1206 fvTimeFirstDigi.resize(iNbDet);
1207 fvMulDigi.resize(iNbDet);
1208
1209 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1210 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1211 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1212 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1213 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1214 LOG(debug) << " DetIndx " << iDetIndx << "(" << iNbDet << "), TSR " << iSmType << iSmId << iRpcId << " => UniqueId "
1215 << Form("0x%08x ", iUniqueId)
1216 << Form(" Svel %6.6f, DeadStrips 0x%08x ", fDigiBdfPar->GetSigVel(iSmType, iSmId, iRpcId),
1217 fvDeadStrips[iDetIndx]);
1218 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpcId);
1219 fvTimeLastDigi[iDetIndx].resize(iNbChan * 2);
1220 for (Int_t iCh = 0; iCh < iNbChan * 2; iCh++)
1221 fvTimeLastDigi[iDetIndx][iCh] = 0.;
1222 fvTimeFirstDigi[iDetIndx].resize(iNbChan * 2);
1223 fvMulDigi[iDetIndx].resize(iNbChan * 2);
1224 for (Int_t iCh = 0; iCh < iNbChan * 2; iCh++) {
1225 fvTimeFirstDigi[iDetIndx][iCh] = 0.;
1226 fvMulDigi[iDetIndx][iCh] = 0.;
1227 }
1228
1229 Int_t iCell = -1;
1230 while (kTRUE) {
1231 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, ++iCell, 0, iSmType);
1232 fChannelInfo = fDigiPar->GetCell(iUCellId);
1233 if (NULL == fChannelInfo) break;
1234 LOG(debug3) << " Cell " << iCell << Form(" 0x%08x ", iUCellId) << Form(", fCh %p ", fChannelInfo) << ", TSRC "
1235 << iSmType << iSmId << iRpcId << iCell << ", x: " << fChannelInfo->GetX()
1236 << ", y: " << fChannelInfo->GetY() << ", z: " << fChannelInfo->GetZ()
1237 << ", dy: " << fChannelInfo->GetSizey();
1238 if (iCell > 100) {
1239 LOG(fatal) << "Too many cells " << fDigiPar->GetNrOfModules();
1240 }
1241 }
1242 }
1243
1244 // return kTRUE;
1245
1246 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
1247
1248 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
1249 fStorDigi.resize(iNbSmTypes);
1250 fStorDigiInd.resize(iNbSmTypes);
1251 fviClusterSize.resize(iNbSmTypes);
1252 fviTrkMul.resize(iNbSmTypes);
1253 fvdX.resize(iNbSmTypes);
1254 fvdY.resize(iNbSmTypes);
1255 fvdDifX.resize(iNbSmTypes);
1256 fvdDifY.resize(iNbSmTypes);
1257 fvdDifCh.resize(iNbSmTypes);
1258 fviClusterMul.resize(iNbSmTypes);
1259 fvLastHits.resize(iNbSmTypes);
1260
1261 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
1262 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
1263 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
1264 fStorDigi[iSmType].resize(iNbSm * iNbRpc);
1265 fStorDigiInd[iSmType].resize(iNbSm * iNbRpc);
1266 fviClusterSize[iSmType].resize(iNbRpc);
1267 fviTrkMul[iSmType].resize(iNbRpc);
1268 fvdX[iSmType].resize(iNbRpc);
1269 fvdY[iSmType].resize(iNbRpc);
1270 fvdDifX[iSmType].resize(iNbRpc);
1271 fvdDifY[iSmType].resize(iNbRpc);
1272 fvdDifCh[iSmType].resize(iNbRpc);
1273 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
1274 fviClusterMul[iSmType].resize(iNbSm);
1275 fvLastHits[iSmType].resize(iNbSm);
1276 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
1277 fviClusterMul[iSmType][iSm].resize(iNbRpc);
1278 fvLastHits[iSmType][iSm].resize(iNbRpc);
1279 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc);
1280 if (iNbChan == 0) {
1281 LOG(warning) << "CbmTofEventClusterizer::LoadGeometry: StoreDigi "
1282 "without channels "
1283 << Form("SmTy %3d, Sm %3d, NbRpc %3d, Rpc, %3d ", iSmType, iSm, iNbRpc, iRpc);
1284 }
1285 LOG(debug1) << "CbmTofEventClusterizer::LoadGeometry: StoreDigi with "
1286 << Form(" %3d %3d %3d %3d %5d ", iSmType, iSm, iNbRpc, iRpc, iNbChan);
1287 fStorDigi[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
1288 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
1289 fvLastHits[iSmType][iSm][iRpc].resize(iNbChan);
1290 } // for( Int_t iRpc = 0; iRpc < iNbRpc; iRpc++ )
1291 } // for( Int_t iSm = 0; iSm < iNbSm; iSm++ )
1292 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
1293 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
1294
1295 return kTRUE;
1296}
1298{
1299 LOG(info) << "CbmTofEventClusterizer::DeleteGeometry starting";
1300 return kTRUE;
1301 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
1302 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
1303 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
1304 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
1305 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
1306 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
1307 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
1308 fStorDigi[iSmType][iSm * iNbRpc + iRpc].clear();
1309 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc].clear();
1310 }
1311 } // for( Int_t iSm = 0; iSm < iNbSm; iSm++ )
1312 fStorDigi[iSmType].clear();
1313 fStorDigiInd[iSmType].clear();
1314 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
1315 fStorDigi.clear();
1316 fStorDigiInd.clear();
1317 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
1318 return kTRUE;
1319}
1320/************************************************************************************/
1321// Histogramming functions
1323{
1324 TDirectory* oldir = gDirectory; // <= To prevent histos from being sucked in by the param file of the TRootManager!
1325 gROOT->cd(); // <= To prevent histos from being sucked in by the param file of the TRootManager !
1327 new TH1I("TofEventClus_ClustBuildTime", "Time needed to build clusters in each event; Time [s]", 4000, 0.0, 4.0);
1328
1330 new TH2D(Form("hClustHitsDigi"), Form("Hits vs. CalDigis; Mul_{Digi}; Mul_{Hits}"), 100, 0, 500, 100, 0, 200);
1331
1332 // RPC related distributions
1333 Int_t iNbDet = fDigiBdfPar->GetNbDet();
1334 fviDetId.resize(iNbDet);
1335
1336 fDetIdIndexMap.clear();
1337 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1338 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1339 fDetIdIndexMap[iUniqueId] = iDetIndx;
1340 fviDetId[iDetIndx] = iUniqueId;
1341 }
1342
1343 if (fTotMax != 0.) fdTOTMax = fTotMax;
1344 if (fTotMin != 0.) fdTOTMin = fTotMin;
1345 LOG(info) << "ToT init to Min " << fdTOTMin << " Max " << fdTOTMax;
1346
1347 if (fDutId < 0) {
1348 LOG(info) << GetName() << ": Skip booking of calibration histograms ";
1349 return kTRUE;
1350 }
1351
1352 // Sm related distributions
1360
1361 for (Int_t iS = 0; iS < fDigiBdfPar->GetNbSmTypes(); iS++) {
1362 Double_t YSCAL = 50.;
1363 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1364
1365 /*
1366 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(0,0,0,0,iS);
1367 fChannelInfo = fDigiPar->GetCell(iUCellId);
1368 */
1369
1370 Int_t iUCellId(0);
1371 fChannelInfo = NULL;
1372
1373 // Cover the case that the geometry file does not contain the module
1374 // indexed with 0 of a certain module type BUT modules with higher indices.
1375 for (Int_t iSM = 0; iSM < fDigiBdfPar->GetNbSm(iS); iSM++) {
1376 iUCellId = CbmTofAddress::GetUniqueAddress(iSM, 0, 0, 0, iS);
1377 fChannelInfo = fDigiPar->GetCell(iUCellId);
1378
1379 // Retrieve geometry information from the first module of a certain
1380 // module type that is found in the geometry file.
1381 if (NULL != fChannelInfo) {
1382 break;
1383 }
1384 }
1385
1386 if (NULL == fChannelInfo) {
1387 LOG(warning) << "No DigiPar for SmType " << Form("%d, 0x%08x", iS, iUCellId);
1388 continue;
1389 }
1390 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1391
1392 fhSmCluPosition[iS] =
1393 new TH2D(Form("cl_SmT%01d_Pos", iS), Form("Clu position of SmType %d; Sm+Rpc# []; ypos [cm]", iS),
1394 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1395 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -YDMAX, YDMAX);
1396
1397 Double_t TSumMax = 1.E3;
1398 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1399 fhSmCluTOff[iS] =
1400 new TH2D(Form("cl_SmT%01d_TOff", iS), Form("Clu TimeZero in SmType %d; Sm+Rpc# []; TOff [ns]", iS),
1401 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1402 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -TSumMax * 2., TSumMax * 2.);
1403
1404 if (NULL == fhSmCluSvel[iS]) {
1405 TProfile* hSvelcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Svel", iS));
1406 if (NULL == hSvelcur) {
1407 LOG(info) << "Histo " << Form("cl_SmT%01d_Svel", iS) << " not found, recreate ...";
1408 fhSmCluSvel[iS] =
1409 new TProfile(Form("cl_SmT%01d_Svel", iS), Form("Clu Svel in SmType %d; Sm+Rpc# []; v/v_{nominal} ", iS),
1410 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1411 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0.8, 1.2);
1412 fhSmCluSvel[iS]->Sumw2();
1413 }
1414 else {
1415 fhSmCluSvel[iS] = (TProfile*) hSvelcur->Clone();
1416 LOG(info) << fhSmCluSvel[iS]->GetName() << " cloned from " << gDirectory->GetName();
1417 }
1418 }
1419
1420 fhSmCluFpar[iS].resize(4);
1421 for (Int_t iPar = 0; iPar < 4; iPar++) {
1422 TProfile* hFparcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Fpar%1d", iS, iPar));
1423 if (NULL == hFparcur) {
1424 LOG(info) << "Histo " << Form("cl_SmT%01d_Fpar%1d", iS, iPar) << " not found, recreate ...";
1425 fhSmCluFpar[iS][iPar] = new TProfile(Form("cl_SmT%01d_Fpar%1d", iS, iPar),
1426 Form("Clu Fpar %d in SmType %d; Sm+Rpc# []; value ", iPar, iS),
1427 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1428 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), -100., 100.);
1429 }
1430 else
1431 fhSmCluFpar[iS][iPar] = (TProfile*) hFparcur->Clone();
1432 }
1433
1434 fhTSmCluPosition[iS].resize(iNSel);
1435 fhTSmCluTOff[iS].resize(iNSel);
1436 fhTSmCluTRun[iS].resize(iNSel);
1437 for (Int_t iSel = 0; iSel < iNSel; iSel++) { // Loop over selectors
1438 fhTSmCluPosition[iS][iSel] = new TH2D(Form("cl_TSmT%01d_Sel%02d_Pos", iS, iSel),
1439 Form("Clu position of SmType %d under Selector %02d; Sm+Rpc# "
1440 "[]; ypos [cm]",
1441 iS, iSel),
1442 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1443 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -YDMAX, YDMAX);
1444 fhTSmCluTOff[iS][iSel] = new TH2D(Form("cl_TSmT%01d_Sel%02d_TOff", iS, iSel),
1445 Form("Clu TimeZero in SmType %d under Selector %02d; Sm+Rpc# "
1446 "[]; TOff [ns]",
1447 iS, iSel),
1448 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1449 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -TSumMax, TSumMax);
1450 fhTSmCluTRun[iS][iSel] = new TH2D(Form("cl_TSmT%01d_Sel%02d_TRun", iS, iSel),
1451 Form("Clu TimeZero in SmType %d under Selector %02d; Event# "
1452 "[]; TMean [ns]",
1453 iS, iSel),
1454 100, 0, MaxNbEvent, 99, -TSumMax, TSumMax);
1455 }
1456 }
1457
1458 LOG(info) << " Define Clusterizer histos for " << iNbDet << " detectors ";
1459
1460 fhRpcDigiCor.resize(iNbDet);
1461 fhRpcDigiMul.resize(iNbDet);
1462 fhRpcDigiStatus.resize(iNbDet);
1463 fhRpcDigiDTLD.resize(iNbDet);
1464 fhRpcDigiDTFD.resize(iNbDet);
1465 fhRpcDigiDTMul.resize(iNbDet);
1466 fhRpcDigiRate.resize(iNbDet);
1467 fhRpcDigiTotLeft.resize(iNbDet);
1468 fhRpcDigiTotRight.resize(iNbDet);
1469 fhRpcDigiTotDiff.resize(iNbDet);
1470 fhRpcDigiTotMap.resize(iNbDet);
1471 fhRpcCluMul.resize(iNbDet);
1472 fhRpcCluRate.resize(iNbDet);
1473 fhRpcCluRate10s.resize(iNbDet);
1474 fhRpcCluPosition.resize(iNbDet);
1475 fhRpcCluPos.resize(iNbDet);
1476 fhRpcCluPositionEvol.resize(iNbDet);
1477 fhRpcCluTimeEvol.resize(iNbDet);
1478 fhRpcCluDelPos.resize(iNbDet);
1479 fhRpcCluDelMatPos.resize(iNbDet);
1480 fhRpcCluTOff.resize(iNbDet);
1481 fhRpcCluDelTOff.resize(iNbDet);
1482 fhRpcCluDelMatTOff.resize(iNbDet);
1483 fhRpcCluTrms.resize(iNbDet);
1484 fhRpcCluTot.resize(iNbDet);
1485 fhRpcCluSize.resize(iNbDet);
1486 fhRpcCluAvWalk.resize(iNbDet);
1487 fhRpcCluAvLnWalk.resize(iNbDet);
1488 fhRpcCluWalk.resize(iNbDet);
1489 fhRpcDTLastHits.resize(iNbDet);
1490 fhRpcDTLastHits_Tot.resize(iNbDet);
1491 fhRpcDTLastHits_CluSize.resize(iNbDet);
1492
1493 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1494 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1495
1496 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1497 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1498 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1499 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, 0, 0, iSmType);
1500 fChannelInfo = fDigiPar->GetCell(iUCellId);
1501 if (NULL == fChannelInfo) {
1502 LOG(warning) << "No DigiPar for Det " << Form("0x%08x", iUCellId);
1503 continue;
1504 }
1505 LOG(debug) << "DetIndx " << iDetIndx << ", SmType " << iSmType << ", SmId " << iSmId << ", RpcId " << iRpcId
1506 << " => UniqueId " << Form("(0x%08x, 0x%08x)", iUniqueId, iUCellId) << ", dx "
1507 << fChannelInfo->GetSizex() << ", dy " << fChannelInfo->GetSizey() << ", z " << fChannelInfo->GetZ()
1508 << Form(" ChPoi: %p ", fChannelInfo) << ", nbCh " << fDigiBdfPar->GetNbChan(iSmType, 0);
1509
1510 // check access to all channel infos
1511 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1512 Int_t iCCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, iCh, 0, iSmType);
1513 fChannelInfo = fDigiPar->GetCell(iCCellId);
1514 if (NULL == fChannelInfo) LOG(warning) << Form("missing ChannelInfo for ch %d addr 0x%08x", iCh, iCCellId);
1515 }
1516
1517 fChannelInfo = fDigiPar->GetCell(iUCellId);
1518 fhRpcDigiCor[iDetIndx] =
1519 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiCor", iSmType, iSmId, iRpcId),
1520 Form("Digi Correlation of Rpc #%03d in Sm %03d of type %d; digi 0; digi 1", iRpcId, iSmId, iSmType),
1521 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId),
1522 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1523
1524 fhRpcDigiMul[iDetIndx] =
1525 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiMul", iSmType, iSmId, iRpcId),
1526 Form("Digi Multiplicity of Rpc #%03d in Sm %03d of type %d; strip #; "
1527 "digi mul",
1528 iRpcId, iSmId, iSmType),
1529 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 20, 0, 20.);
1530
1531 fhRpcDigiStatus[iDetIndx] =
1532 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiStatus", iSmType, iSmId, iRpcId),
1533 Form("Digi Status of Rpc #%03d in Sm %03d of type %d; strip #; digi status", iRpcId, iSmId, iSmType),
1534 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 10, 0, 10.);
1535
1536 const Int_t NLogbin = 40;
1537 Double_t edge[NLogbin + 1];
1538 for (Int_t i = 0; i < NLogbin + 1; i++)
1539 edge[i] = TMath::Power(2, i);
1540 fhRpcDigiDTLD[iDetIndx] = new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiDTLD", iSmType, iSmId, iRpcId),
1541 Form("Time distance to last digi of Rpc #%03d in Sm %03d of type %d; "
1542 "channel; t_{digi} - t_{previous digi} (ns)",
1543 iRpcId, iSmId, iSmType),
1544 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 0,
1545 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, NLogbin, edge);
1546
1547 fhRpcDigiDTFD[iDetIndx] = new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiDTFD", iSmType, iSmId, iRpcId),
1548 Form("Time distance to first digi of Rpc #%03d in Sm %03d of type %d; "
1549 "channel; t_{digi} - t_{first digi} (ns)",
1550 iRpcId, iSmId, iSmType),
1551 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 0,
1552 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 500., 0., 55.8);
1553
1554 fhRpcDigiDTMul[iDetIndx] = new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiDTMul", iSmType, iSmId, iRpcId),
1555 Form("Multiplicity of digi of Rpc #%03d in Sm %03d of type %d; "
1556 "channel; Multiplicity",
1557 iRpcId, iSmId, iSmType),
1558 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 0,
1559 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 20., 0.5, 20.5);
1560 fhRpcDigiRate[iDetIndx] =
1561 new TH1D(Form("cl_SmT%01d_sm%03d_rpc%03d_digirate", iSmType, iSmId, iRpcId),
1562 Form("Digi rate of Rpc #%03d in Sm %03d of type %d; Time (s); Rate (Hz)", iRpcId, iSmId, iSmType),
1563 36000., 0., 3600.);
1564
1565 fhRpcCluMul[iDetIndx] =
1566 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_Mul", iSmType, iSmId, iRpcId),
1567 Form("Clu multiplicity of Rpc #%03d in Sm %03d of type %d; M []; Cnts", iRpcId, iSmId, iSmType),
1568 2. + 2. * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, 2. + 2. * fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1569
1570 fhRpcCluRate[iDetIndx] =
1571 new TH1D(Form("cl_SmT%01d_sm%03d_rpc%03d_rate", iSmType, iSmId, iRpcId),
1572 Form("Clu rate of Rpc #%03d in Sm %03d of type %d; Time (s); Rate (Hz)", iRpcId, iSmId, iSmType), 36000.,
1573 0., 3600.);
1574
1575 fhRpcCluRate10s[iDetIndx] = new TH1D(Form("cl_SmT%01d_sm%03d_rpc%03d_rate10s", iSmType, iSmId, iRpcId),
1576 Form(" Clu rate of Rpc #%03d in Sm %03d of type %d in last "
1577 "10s; Time (s); Counts per 100 #mus",
1578 iRpcId, iSmId, iSmType),
1579 100000, 0., 10.);
1580
1581 fhRpcDTLastHits[iDetIndx] = new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_DTLastHits", iSmType, iSmId, iRpcId),
1582 Form("Clu #DeltaT to last hits of Rpc #%03d in Sm %03d of type %d; log( "
1583 "#DeltaT (ns)); counts",
1584 iRpcId, iSmId, iSmType),
1585 100., 0., 10.);
1586
1587 fhRpcDTLastHits_Tot[iDetIndx] = new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot_DTLH", iSmType, iSmId, iRpcId),
1588 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d; log(#DeltaT (ns)); TOT "
1589 "[a.u.]",
1590 iRpcId, iSmId, iSmType),
1591 100, 0., 10., 100, fdTOTMin, 4. * fdTOTMax);
1592
1593 fhRpcDTLastHits_CluSize[iDetIndx] = new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_CluSize_DTLH", iSmType, iSmId, iRpcId),
1594 Form("Clu Size of Rpc #%03d in Sm %03d of type %d; log(#DeltaT (ns)); "
1595 "CluSize []",
1596 iRpcId, iSmId, iSmType),
1597 100, 0., 10., 16, 0.5, 16.5);
1598
1599 Double_t YSCAL = 50.;
1600 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1601 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1602 fhRpcCluPosition[iDetIndx] =
1603 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Pos", iSmType, iSmId, iRpcId),
1604 Form("Clu position of Rpc #%03d in Sm %03d of type %d; Strip []; ypos [cm]", iRpcId, iSmId, iSmType),
1605 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -YDMAX, YDMAX);
1606
1607 fhRpcCluPos[iDetIndx] = new TH2D(
1608 Form("cl_SmT%01d_sm%03d_rpc%03d_GloPos", iSmType, iSmId, iRpcId),
1609 Form("Clu global position of Rpc #%03d in Sm %03d of type %d; xpos [cm]; ypos [cm]", iRpcId, iSmId, iSmType), 200,
1610 -100, 100, 200, -100, 100);
1611 fhRpcDigiTotLeft[iDetIndx] =
1612 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot_Left", iSmType, iSmId, iRpcId),
1613 Form("Digi Tot of Rpc #%03d in Sm %03d of type %d; Tot; ypos [cm]", iRpcId, iSmId, iSmType), 100,
1614 fdTOTMin, fdTOTMax, 99, -YDMAX, YDMAX);
1615
1616 fhRpcDigiTotRight[iDetIndx] =
1617 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot_Right", iSmType, iSmId, iRpcId),
1618 Form("Digi Tot of Rpc #%03d in Sm %03d of type %d; Tot; ypos [cm]", iRpcId, iSmId, iSmType), 100,
1619 fdTOTMin, fdTOTMax, 99, -YDMAX, YDMAX);
1620
1621 fhRpcDigiTotDiff[iDetIndx] =
1622 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot_Diff", iSmType, iSmId, iRpcId),
1623 Form("Digi Tot of Rpc #%03d in Sm %03d of type %d; Tot; ypos [cm]", iRpcId, iSmId, iSmType), 200,
1624 fdTOTMax, fdTOTMax, 99, -YDMAX, YDMAX);
1625
1626 fhRpcDigiTotMap[iDetIndx] = new TH2D(
1627 Form("cl_SmT%01d_sm%03d_rpc%03d_Tot_Map", iSmType, iSmId, iRpcId),
1628 Form("Digi Tot left vs Tot right of Rpc #%03d in Sm %03d of type %d; Tot; ypos [cm]", iRpcId, iSmId, iSmType),
1629 100, 0, fdTOTMax, 100, 0, fdTOTMax);
1630
1631 fhRpcCluPositionEvol[iDetIndx] = new TProfile(Form("cl_SmT%01d_sm%03d_rpc%03d_PosEvol", iSmType, iSmId, iRpcId),
1632 Form("Clu position of Rpc #%03d in Sm %03d of type %d; Analysis Time "
1633 "[s]; ypos [cm]",
1634 iRpcId, iSmId, iSmType),
1635 1000, -1., 1.E4, -100., 100.);
1636
1637 fhRpcCluTimeEvol[iDetIndx] = new TProfile(Form("cl_SmT%01d_sm%03d_rpc%03d_TimeEvol", iSmType, iSmId, iRpcId),
1638 Form("Clu time of Rpc #%03d in Sm %03d of type %d; Analysis Time [s]; dT "
1639 "[ns]",
1640 iRpcId, iSmId, iSmType),
1641 1000, -1., 1.E4, -10., 10.);
1642
1643 fhRpcCluDelPos[iDetIndx] =
1644 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DelPos", iSmType, iSmId, iRpcId),
1645 Form("Clu position difference of Rpc #%03d in Sm %03d of type "
1646 "%d; Strip []; #Deltaypos(clu) [cm]",
1647 iRpcId, iSmId, iSmType),
1648 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -5., 5.);
1649
1650 fhRpcCluDelMatPos[iDetIndx] =
1651 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DelMatPos", iSmType, iSmId, iRpcId),
1652 Form("Matched Clu position difference of Rpc #%03d in Sm %03d of type "
1653 "%d; Strip []; #Deltaypos(mat) [cm]",
1654 iRpcId, iSmId, iSmType),
1655 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -5., 5.);
1656
1657 Double_t TSumMax = 1.E3;
1658 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1659 fhRpcCluTOff[iDetIndx] = new TH2D(
1660 Form("cl_SmT%01d_sm%03d_rpc%03d_TOff", iSmType, iSmId, iRpcId),
1661 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d; Strip []; TOff [ns]", iRpcId, iSmId, iSmType),
1662 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -TSumMax, TSumMax);
1663
1664 fhRpcCluDelTOff[iDetIndx] = new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DelTOff", iSmType, iSmId, iRpcId),
1665 Form("Clu TimeZero Difference of Rpc #%03d in Sm %03d of type %d; Strip "
1666 "[]; #DeltaTOff(clu) [ns]",
1667 iRpcId, iSmId, iSmType),
1668 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0,
1669 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -fdMaxTimeDist, fdMaxTimeDist);
1670
1671 fhRpcCluDelMatTOff[iDetIndx] =
1672 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_DelMatTOff", iSmType, iSmId, iRpcId),
1673 Form("Clu TimeZero Difference of Rpc #%03d in Sm %03d of type %d; Strip "
1674 "[]; #DeltaTOff(mat) [ns]",
1675 iRpcId, iSmId, iSmType),
1676 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -0.6, 0.6);
1677
1678 fhRpcCluTrms[iDetIndx] =
1679 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Trms", iSmType, iSmId, iRpcId),
1680 Form("Clu Time RMS of Rpc #%03d in Sm %03d of type %d; Strip []; Trms [ns]", iRpcId, iSmId, iSmType),
1681 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, 0., 0.5);
1682
1683 fhRpcCluTot[iDetIndx] =
1684 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot", iSmType, iSmId, iRpcId),
1685 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d; StripSide []; TOT [a.u.]", iRpcId, iSmId, iSmType),
1686 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 100,
1688
1689 fhRpcCluSize[iDetIndx] =
1690 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Size", iSmType, iSmId, iRpcId),
1691 Form("Clu size of Rpc #%03d in Sm %03d of type %d; Strip []; size [strips]", iRpcId, iSmId, iSmType),
1692 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 16, 0.5, 16.5);
1693
1694 // Walk histos
1695 fhRpcCluAvWalk[iDetIndx] =
1696 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_AvWalk", iSmType, iSmId, iRpcId),
1697 Form("Walk in SmT%01d_sm%03d_rpc%03d_AvWalk; Tot [a.u.]; #DeltaT [ns]", iSmType, iSmId, iRpcId),
1698 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1699
1700 fhRpcCluAvLnWalk[iDetIndx] = new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_AvLnWalk", iSmType, iSmId, iRpcId),
1701 Form("Walk in SmT%01d_sm%03d_rpc%03d_AvLnWalk; log_{10}Tot [a.u.]; "
1702 "#DeltaT [ns]",
1703 iSmType, iSmId, iRpcId),
1704 nbClWalkBinX, TMath::Log10(fdTOTMax / 50.), TMath::Log10(fdTOTMax),
1705 nbClWalkBinY, -TSumMax / 2, TSumMax / 2);
1706
1707 fhRpcCluWalk[iDetIndx].resize(fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1708 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1709 fhRpcCluWalk[iDetIndx][iCh].resize(2);
1710 for (Int_t iSide = 0; iSide < 2; iSide++) {
1711 fhRpcCluWalk[iDetIndx][iCh][iSide] =
1712 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk", iSmType, iSmId, iRpcId, iCh, iSide),
1713 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk; Tot "
1714 "[a.u.]; #DeltaT [ns]",
1715 iSmType, iSmId, iRpcId, iCh, iSide),
1716 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1717 }
1718 /*
1719 (fhRpcCluWalk[iDetIndx]).push_back( hTemp );
1720 */
1721 }
1722 }
1723
1724 // Clusterizing monitoring
1725
1726 LOG(info) << " Define Clusterizer monitoring histos ";
1727
1728 fhCluMulCorDutSel = new TH2D(Form("hCluMulCorDutSel"),
1729 Form("Cluster Multiplicity Correlation of Dut %d%d%d with Sel "
1730 "%d%d%d; Mul(Sel); Mul(Dut)",
1732 32, 0, 32, 32, 0, 32);
1733
1734 fhEvCluMul = new TH2D(Form("hEvCluMul"), Form("Time Evolution of Cluster Multiplicity in Event; Time (s); Mul"), 1800,
1735 0, 1800, 100, 0, 100);
1736
1737 fhDigSpacDifClust = new TH1I("Clus_DigSpacDifClust",
1738 "Space difference along channel direction between Digi pairs on "
1739 "adjacent channels; PosCh i - Pos Ch i+1 [cm]",
1740 5000, -10.0, 10.0);
1741 fhDigTimeDifClust = new TH1I("Clus_DigTimeDifClust",
1742 "Time difference between Digi pairs on adjacent channels; "
1743 "0.5*(tDigiA + tDigiA)chi - 0.5*(tDigiA + tDigiA)chi+1 [ns]",
1744 5000, -5.0, 5.0);
1745 fhDigDistClust = new TH2I("Clus_DigDistClust",
1746 "Distance between Digi pairs on adjacent channels; PosCh i - Pos Ch i+1 "
1747 "[cm along ch]; 0.5*(tDigiA + tDigiA)chi - 0.5*(tDigiA + tDigiA)chi+1 [ns]",
1748 5000, -10.0, 10.0, 2000, -5.0, 5.0);
1749 fhClustSizeDifX = new TH2I("Clus_ClustSizeDifX",
1750 "Position difference between Point and Hit as function of Cluster "
1751 "Size; Cluster Size [Strips]; dX [cm]",
1752 100, 0.5, 100.5, 500, -50, 50);
1753 fhClustSizeDifY = new TH2I("Clus_ClustSizeDifY",
1754 "Position difference between Point and Hit as function of Cluster "
1755 "Size; Cluster Size [Strips]; dY [cm]",
1756 100, 0.5, 100.5, 500, -50, 50);
1757 fhChDifDifX = new TH2I("Clus_ChDifDifX",
1758 "Position difference between Point and Hit as "
1759 "function of Channel dif; Ch Dif [Strips]; dX [cm]",
1760 101, -50.5, 50.5, 500, -50, 50);
1761 fhChDifDifY = new TH2I("Clus_ChDifDifY",
1762 "Position difference between Point and Hit as "
1763 "function of Channel Dif; Ch Dif [Strips]; dY [cm]",
1764 101, -50.5, 50.5, 500, -50, 50);
1765 fhNbSameSide = new TH1I("Clus_NbSameSide",
1766 "How many time per event the 2 digis on a channel "
1767 "were of the same side ; Counts/Event []",
1768 500, 0.0, 500.0);
1769 fhNbDigiPerChan = new TH1I("Clus_NbDigiPerChan", "Nb of Digis per channel; Nb Digis []", 100, 0.0, 100.0);
1770
1771 // Trigger selected histograms
1772 if (0 < iNSel) {
1773
1774 fhSeldT.resize(iNSel);
1775 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1776 fhSeldT[iSel] = new TH2D(Form("cl_dt_Sel%02d", iSel), Form("Selector time %02d; dT [ns]", iSel), 99,
1777 -fdDelTofMax * 10., fdDelTofMax * 10., 16, -0.5, 15.5);
1778 }
1779
1780 fhTRpcCluMul.resize(iNbDet);
1781 fhTRpcCluPosition.resize(iNbDet);
1782 fhTRpcCluTOff.resize(iNbDet);
1783 fhTRpcCluTofOff.resize(iNbDet);
1784 fhTRpcCluTot.resize(iNbDet);
1785 fhTRpcCluSize.resize(iNbDet);
1786 fhTRpcCluAvWalk.resize(iNbDet);
1787 fhTRpcCluDelTof.resize(iNbDet);
1788 fhTRpcCludXdY.resize(iNbDet);
1789 fhTRpcCluWalk.resize(iNbDet);
1790 fhTRpcCluQASY.resize(iNbDet);
1791 fhTRpcCluWalk2.resize(iNbDet);
1792 fhTRpcCluQ2DT.resize(iNbDet);
1793 fhTRpcCluTOffDTLastHits.resize(iNbDet);
1794 fhTRpcCluTotDTLastHits.resize(iNbDet);
1795 fhTRpcCluSizeDTLastHits.resize(iNbDet);
1796 fhTRpcCluMemMulDTLastHits.resize(iNbDet);
1797
1798 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1799 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1800 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1801 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1802 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1803 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, 0, 0, iSmType);
1804 fChannelInfo = fDigiPar->GetCell(iUCellId);
1805 if (NULL == fChannelInfo) {
1806 LOG(warning) << "No DigiPar for Det " << Form("0x%08x", iUCellId);
1807 continue;
1808 }
1809 LOG(debug1) << "DetIndx " << iDetIndx << ", SmType " << iSmType << ", SmId " << iSmId << ", RpcId " << iRpcId
1810 << " => UniqueId " << Form("(0x%08x, 0x%08x)", iUniqueId, iUCellId) << ", dx "
1811 << fChannelInfo->GetSizex() << ", dy " << fChannelInfo->GetSizey()
1812 << Form(" poi: 0x%p ", fChannelInfo) << ", nbCh " << fDigiBdfPar->GetNbChan(iSmType, iRpcId);
1813
1814 fhTRpcCluMul[iDetIndx].resize(iNSel);
1815 fhTRpcCluPosition[iDetIndx].resize(iNSel);
1816 fhTRpcCluTOff[iDetIndx].resize(iNSel);
1817 fhTRpcCluTofOff[iDetIndx].resize(iNSel);
1818 fhTRpcCluTot[iDetIndx].resize(iNSel);
1819 fhTRpcCluSize[iDetIndx].resize(iNSel);
1820 fhTRpcCluAvWalk[iDetIndx].resize(iNSel);
1821 fhTRpcCluDelTof[iDetIndx].resize(iNSel);
1822 fhTRpcCludXdY[iDetIndx].resize(iNSel);
1823 fhTRpcCluWalk[iDetIndx].resize(iNSel);
1824 fhTRpcCluQASY[iDetIndx].resize(iNSel);
1825 fhTRpcCluWalk2[iDetIndx].resize(iNSel);
1826 fhTRpcCluQ2DT[iDetIndx].resize(iNSel);
1827 fhTRpcCluTOffDTLastHits[iDetIndx].resize(iNSel);
1828 fhTRpcCluTotDTLastHits[iDetIndx].resize(iNSel);
1829 fhTRpcCluSizeDTLastHits[iDetIndx].resize(iNSel);
1830 fhTRpcCluMemMulDTLastHits[iDetIndx].resize(iNSel);
1831
1832 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1833 fhTRpcCluMul[iDetIndx][iSel] =
1834 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Mul", iSmType, iSmId, iRpcId, iSel),
1835 Form("Clu multiplicity of Rpc #%03d in Sm %03d of type %d "
1836 "under Selector %02d; M []; cnts",
1837 iRpcId, iSmId, iSmType, iSel),
1838 fDigiBdfPar->GetNbChan(iSmType, iRpcId) + 2, 0., fDigiBdfPar->GetNbChan(iSmType, iRpcId) + 2);
1839
1840 if (NULL == fhTRpcCluMul[iDetIndx][iSel]) LOG(fatal) << " Histo not generated !";
1841
1842 Double_t YSCAL = 50.;
1843 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1844 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1845 fhTRpcCluPosition[iDetIndx][iSel] = new TH2D(
1846 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Pos", iSmType, iSmId, iRpcId, iSel),
1847 Form("Clu position of Rpc #%03d in Sm %03d of type %d under "
1848 "Selector %02d; Strip []; ypos [cm]",
1849 iRpcId, iSmId, iSmType, iSel),
1850 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 100, -YDMAX, YDMAX);
1851
1852 Double_t TSumMax = 1.E4;
1853 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1854 if (iSmType == 5) TSumMax *= 2.;
1855 fhTRpcCluTOff[iDetIndx][iSel] = new TH2D(
1856 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_TOff", iSmType, iSmId, iRpcId, iSel),
1857 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d under "
1858 "Selector %02d; Strip []; TOff [ns]",
1859 iRpcId, iSmId, iSmType, iSel),
1860 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 999, -TSumMax, TSumMax);
1861
1862 fhTRpcCluTofOff[iDetIndx][iSel] =
1863 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_TofOff", iSmType, iSmId, iRpcId, iSel),
1864 Form("Clu TimeDeviation of Rpc #%03d in Sm %03d of type %d "
1865 "under Selector %02d; Strip []; TOff [ns]",
1866 iRpcId, iSmId, iSmType, iSel),
1867 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 999,
1868 -TSumMax * 4., TSumMax * 4.);
1869
1870 if (fTotMax != 0.) fdTOTMax = fTotMax;
1871 fhTRpcCluTot[iDetIndx][iSel] =
1872 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Tot", iSmType, iSmId, iRpcId, iSel),
1873 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d under "
1874 "Selector %02d; StripSide []; TOT [a.u.]",
1875 iRpcId, iSmId, iSmType, iSel),
1876 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 100,
1878
1879 fhTRpcCluSize[iDetIndx][iSel] =
1880 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Size", iSmType, iSmId, iRpcId, iSel),
1881 Form("Clu size of Rpc #%03d in Sm %03d of type %d under "
1882 "Selector %02d; Strip []; size [strips]",
1883 iRpcId, iSmId, iSmType, iSel),
1884 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 16, 0.5, 16.5);
1885
1886 // Walk histos
1887 fhTRpcCluAvWalk[iDetIndx][iSel] =
1888 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_AvWalk", iSmType, iSmId, iRpcId, iSel),
1889 Form("Walk in SmT%01d_sm%03d_rpc%03d_Sel%02d_AvWalk; TOT; T-TSel", iSmType, iSmId, iRpcId, iSel),
1890 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax / 2, TSumMax / 2);
1891
1892 // Tof Histos
1893 fhTRpcCluDelTof[iDetIndx][iSel] =
1894 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSmId, iRpcId, iSel),
1895 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof; TRef-TSel; T-TSel", iSmType, iSmId, iRpcId, iSel),
1896 nbClDelTofBinX, -fdDelTofMax, fdDelTofMax, nbClDelTofBinY, -TSumMax, TSumMax);
1897
1898 // Position deviation histos
1899 fhTRpcCludXdY[iDetIndx][iSel] =
1900 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_dXdY", iSmType, iSmId, iRpcId, iSel),
1901 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_dXdY; #Delta x [cm]; "
1902 "#Delta y [cm];",
1903 iSmType, iSmId, iRpcId, iSel),
1905
1906 // Position deviation histos
1907 fhTRpcCluQASY[iDetIndx][iSel] =
1908 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_QASY", iSmType, iSmId, iRpcId, iSel),
1909 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_QASY; Tot_{asy} []; Y [cm];", iSmType, iSmId, iRpcId, iSel), 50,
1910 -1, 1, 100, -YDMAX, YDMAX);
1911
1912 fhTRpcCluWalk2[iDetIndx][iSel] = new TH3F(
1913 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Walk2", iSmType, iSmId, iRpcId, iSel),
1914 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_Walk2; Tot_1; Tot_2; #Delta t[ns]", iSmType, iSmId, iRpcId, iSel),
1916
1917 fhTRpcCluQ2DT[iDetIndx][iSel] = new TH3F(
1918 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Q2DT", iSmType, iSmId, iRpcId, iSel),
1919 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_Q2DT; Tot_1; Tot_2; #Delta t[ns]", iSmType, iSmId, iRpcId, iSel),
1921
1922 fhTRpcCluWalk[iDetIndx][iSel].resize(fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1923
1924 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1925 fhTRpcCluWalk[iDetIndx][iSel][iCh].resize(2);
1926 for (Int_t iSide = 0; iSide < 2; iSide++) {
1927 fhTRpcCluWalk[iDetIndx][iSel][iCh][iSide] = new TH2D(
1928 Form("cl_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Sel%02d_Walk", iSmType, iSmId, iRpcId, iCh, iSide, iSel),
1929 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Sel%02d_Walk", iSmType, iSmId, iRpcId, iCh, iSide,
1930 iSel),
1931 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1932 }
1933 }
1934
1935 fhTRpcCluTOffDTLastHits[iDetIndx][iSel] =
1936 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_TOff_DTLH", iSmType, iSmId, iRpcId, iSel),
1937 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d under "
1938 "Selector %02d; log(#DeltaT (ns)); TOff [ns]",
1939 iRpcId, iSmId, iSmType, iSel),
1940 100, 0., 10., 99, -TSumMax, TSumMax);
1941
1942 fhTRpcCluTotDTLastHits[iDetIndx][iSel] =
1943 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Tot_DTLH", iSmType, iSmId, iRpcId, iSel),
1944 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d under "
1945 "Selector %02d; log(#DeltaT (ns)); TOT [a.u.]",
1946 iRpcId, iSmId, iSmType, iSel),
1947 100, 0., 10., 100, fdTOTMin, fdTOTMax);
1948
1949 fhTRpcCluSizeDTLastHits[iDetIndx][iSel] =
1950 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Size_DTLH", iSmType, iSmId, iRpcId, iSel),
1951 Form("Clu size of Rpc #%03d in Sm %03d of type %d under "
1952 "Selector %02d; log(#DeltaT (ns)); size [strips]",
1953 iRpcId, iSmId, iSmType, iSel),
1954 100, 0., 10., 10, 0.5, 10.5);
1955
1956 fhTRpcCluMemMulDTLastHits[iDetIndx][iSel] =
1957 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_MemMul_DTLH", iSmType, iSmId, iRpcId, iSel),
1958 Form("Clu Memorized Multiplicity of Rpc #%03d in Sm %03d of type %d "
1959 "under Selector %02d; log(#DeltaT (ns)); TOff [ns]",
1960 iRpcId, iSmId, iSmType, iSel),
1961 100, 0., 10., 10, 0, 10);
1962 }
1963 }
1964 }
1965 // MC reference
1967 new TH1I("Clus_TofHitPerTrk", "Mean Number of TofHit per Mc Track; Nb TofHits/Nb MC Tracks []", 2000, 0.0, 20.0);
1968 if (kFALSE == fDigiBdfPar->ClustUseTrackId())
1969 fhPtsPerHit = new TH1I("Clus_TofPtsPerHit",
1970 "Distribution of the Number of MCPoints associated "
1971 "to each TofHit; Nb MCPoint []",
1972 20, 0.0, 20.0);
1973 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
1974 fhTimeResSingHits = new TH1I("Clus_TofTimeResClust",
1975 "Time resolution for TofHits containing Digis from a single MC "
1976 "Track; t(1st Mc Point) -tTofHit [ns]",
1977 10000, -25.0, 25.0);
1978 fhTimeResSingHitsB = new TH2I("Clus_TofTimeResClustB",
1979 "Time resolution for TofHits containing Digis from a single MC "
1980 "Track; (1st Mc Point) -tTofHit [ns]",
1981 5000, -25.0, 25.0, 6, 0, 6);
1982 fhTimePtVsHits = new TH2I("Clus_TofTimePtVsHit",
1983 "Time resolution for TofHits containing Digis from a single MC "
1984 "Track; t(1st Mc Point) -tTofHit [ns]",
1985 2000, 0.0, 50.0, 2000, 0.0, 50.0);
1986 }
1987 else {
1988 fhTimeResSingHits = new TH1I("Clus_TofTimeResClust",
1989 "Time resolution for TofHits containing Digis from a single "
1990 "TofPoint; tMcPoint -tTofHit [ns]",
1991 10000, -25.0, 25.0);
1992 fhTimeResSingHitsB = new TH2I("Clus_TofTimeResClustB",
1993 "Time resolution for TofHits containing Digis from a single "
1994 "TofPoint; tMcPoint -tTofHit [ns]",
1995 5000, -25.0, 25.0, 6, 0, 6);
1996 fhTimePtVsHits = new TH2I("Clus_TofTimePtVsHit",
1997 "Time resolution for TofHits containing Digis "
1998 "from a single TofPoint; tMcPoint -tTofHit [ps]",
1999 2000, 0.0, 50.0, 2000, 0.0, 50.0);
2000 } // else of if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
2001 /*
2002 fhClusterSize = new TH1I("Clus_ClusterSize", "Cluster Size distribution; Cluster Size [Strips]", 100, 0.5, 100.5);
2003 fhClusterSizeType =
2004 new TH2I("Clus_ClusterSizeType",
2005 "Cluster Size distribution in each (SM type, Rpc) pair; Cluster "
2006 "Size [Strips]; 10*SM Type + Rpc Index []",
2007 100, 0.5, 100.5, 40 * fDigiBdfPar->GetNbSmTypes(), 0.0, 40 * fDigiBdfPar->GetNbSmTypes());
2008 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
2009 fhTrackMul = new TH1I("Clus_TrackMul", "Number of MC tracks generating the cluster; MC Tracks multiplicity []", 100,
2010 0.5, 100.5);
2011 fhClusterSizeMulti = new TH2I("Clus_ClusterSizeMulti",
2012 "Cluster Size distribution as function of Number of MC tracks generating "
2013 "the cluster; Cluster Size [Strips]; MC tracks mul. []",
2014 100, 0.5, 100.5, 100, 0.5, 100.5);
2015 fhTrk1MulPos = new TH2D("Clus_Trk1MulPos",
2016 "Position of Clusters with only 1 MC tracks "
2017 "generating the cluster; X [cm]; Y [cm]",
2018 1500, -750, 750, 1000, -500, 500);
2019 fhHiTrkMulPos = new TH2D("Clus_HiTrkMulPos",
2020 "Position of Clusters with >1 MC tracks "
2021 "generating the cluster; X [cm]; Y [cm]",
2022 1500, -750, 750, 1000, -500, 500);
2023 fhAllTrkMulPos = new TH2D("Clus_AllTrkMulPos", "Position of all clusters generating the cluster; X [cm]; Y [cm]",
2024 1500, -750, 750, 1000, -500, 500);
2025 fhMultiTrkProbPos = new TH2D("Clus_MultiTrkProbPos",
2026 "Probability of having a cluster with multiple tracks as "
2027 "function of position; X [cm]; Y [cm]; Prob. [%]",
2028 1500, -750, 750, 1000, -500, 500);
2029 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
2030 */
2031 gDirectory->cd(oldir->GetPath()); // <= To prevent histos from being sucked in by the param file of the TRootManager!
2032
2033 return kTRUE;
2034}
2035
2037{
2038 fhClustBuildTime->Fill(fStop.GetSec() - fStart.GetSec() + (fStop.GetNanoSec() - fStart.GetNanoSec()) / 1e9);
2039 fhClustHitsDigi->Fill(fTofCalDigiVec->size(), fTofHitsColl->GetEntriesFast());
2040
2041 if (fDutId < 0) return kTRUE;
2042
2043 Int_t iNbTofHits = fTofHitsColl->GetEntriesFast();
2044 CbmTofHit* pHit = NULL;
2045 if (NULL == tEvent) {
2046 if (fCalMode > -1 && fCalMode % 10 == 9) {
2047 if (iNbTofHits > 0) { // outsource all calibration actions
2048 //pHit = (CbmTofHit*) fTofHitsColl->At(0); // use most early hit as reference
2049 fTofCalibrator->FillCalHist(pHit, fCalMode, tEvent);
2050 }
2051 return kTRUE;
2052 }
2053 }
2054 else { // event array mode
2055 if (fCalMode % 10 == 9) return kTRUE; // call Calibrator after event is defined
2056 }
2057
2058 gGeoManager->CdTop();
2059
2060 if (0 < iNbTofHits) {
2061 Double_t dCluMul = 0.;
2062 Bool_t BSel[iNSel];
2063 Double_t dTTrig[iNSel];
2064 CbmTofHit* pTrig[iNSel];
2065 Double_t ddXdZ[iNSel];
2066 Double_t ddYdZ[iNSel];
2067 Double_t dSel2dXdYMin[iNSel];
2068
2069 Int_t iBeamRefMul = 0;
2070 Int_t iBeamAddRefMul = 0;
2071 CbmTofHit* pBeamRef = NULL;
2072
2073 if (0 < iNSel) { // check software triggers
2074
2075 LOG(debug) << "CbmTofEventClusterizer::FillHistos() for " << iNSel << " triggers"
2076 << ", Dut " << fDutId << ", " << fDutSm << ", " << fDutRpc << Form(", 0x%08x", fDutAddr) << ", Sel "
2077 << fSelId << ", " << fSelSm << ", " << fSelRpc << Form(", 0x%08x", fSelAddr) << ", Sel2 " << fSel2Id
2078 << ", " << fSel2Sm << ", " << fSel2Rpc << Form(", 0x%08x", fSel2Addr);
2079 LOG(debug) << "CbmTofEventClusterizer::FillHistos: Muls: " << fviClusterMul[fDutId][fDutSm][fDutRpc] << ", "
2081
2082 // monitor multiplicities
2083 Int_t iDetMul = 0;
2084 Int_t iNbDet = fDigiBdfPar->GetNbDet();
2085 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
2086 Int_t iDetId = fviDetId[iDetIndx];
2087 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
2088 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
2089 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
2090 //LOG(info) << Form(" indx %d, Id 0x%08x, TSR %d %d %d", iDetIndx, iDetId, iSmType, iSm, iRpc)
2091 // ;
2092 if (NULL != fhRpcCluMul[iDetIndx]) {
2093 if (fviClusterMul[iSmType][iSm][iRpc] > 0) iDetMul++;
2094 dCluMul += fviClusterMul[iSmType][iSm][iRpc]; // total hit multiplicity in event
2095 fhRpcCluMul[iDetIndx]->Fill(fviClusterMul[iSmType][iSm][iRpc]); //
2096 }
2097 }
2098 if (fSelId > (Int_t) fviClusterMul.size() || fDutId > (Int_t) fviClusterMul.size()) {
2099 LOG(fatal) << " Invalid Id: Sel " << fSelId << ", Dut " << fDutId << " in event " << fdEvent;
2100 return kFALSE;
2101 }
2102 else {
2103 if (fSelSm > (Int_t) fviClusterMul[fSelId].size()) {
2104 LOG(fatal) << " Invalid SelSm " << fSelSm << " in event " << fdEvent;
2105 return kFALSE;
2106 }
2107 else {
2109 LOG(fatal) << " Invalid SelRpc " << fSelRpc << " in event " << fdEvent;
2110 return kFALSE;
2111 }
2112 }
2113
2114 if (fDutSm > (Int_t) fviClusterMul[fDutId].size()) {
2115 LOG(fatal) << " Invalid DutSm " << fDutSm << " in event " << fdEvent;
2116 return kFALSE;
2117 }
2118 else {
2120 LOG(fatal) << " Invalid DutRpc " << fDutRpc << " in event " << fdEvent;
2121 return kFALSE;
2122 }
2123 }
2124 }
2125
2127
2128 // do input distributions first
2129 //LOG(debug)<<"Event " << fdEvent <<", StartTime "<<fdStartAnalysisTime;
2130 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
2131 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
2132 if (NULL == pHit) continue;
2133 if (fdStartAnalysisTime < 1.) {
2135 LOG(info) << "StartAnalysisTime set to " << fdStartAnalysisTime / 1.E9 << " s. ";
2137 }
2138 Int_t iDetId = (pHit->GetAddress() & DetMask);
2139
2140 std::map<UInt_t, UInt_t>::iterator it = fDetIdIndexMap.find(iDetId);
2141 if (it == fDetIdIndexMap.end()) continue; // continue for invalid detector index
2142 Int_t iDetIndx = it->second; //fDetIdIndexMap[iDetId];
2143
2144 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
2145 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
2146 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
2148
2149 Double_t dTimeAna = (pHit->GetTime() + dTsStartTime - fdStartAnalysisTime) / 1.E9;
2150 //LOG(debug)<<"TimeAna "<<StartAnalysisTime<<", "<< pHit->GetTime()<<", "<<dTimeAna;
2151 fhRpcCluRate[iDetIndx]->Fill(dTimeAna, 1. / fhRpcCluRate[iDetIndx]->GetBinWidth(1));
2152
2153 // deal with spill structures
2154
2155 Double_t dTimeAna10s = pHit->GetTime() + dTsStartTime - fdStartAna10s;
2156 if (iHitInd == 0) {
2157 fhEvCluMul->Fill(dTimeAna, dCluMul);
2158 if (iDetMul > 5
2159 && fviClusterMul[fiBeamRefType][fiBeamRefSm][fiBeamRefDet] > 0) { // FIXME: hardwired constants
2160 if (dTLEvt == 0) dTLEvt = pHit->GetTime();
2161 Double_t dDTLEvt = pHit->GetTime() - dTLEvt;
2162 dTLEvt = pHit->GetTime();
2163 if (dDTLEvt > fdSpillBreak * 1.E9 && dTimeAna10s > fdSpillDuration * 1.E9) {
2164 //if( dDTLEvt> 5.E8 && dTimeAna10s > 10.) {
2166 iNSpill++;
2167 LOG(debug) << "Resetting 10s rate histo for spill " << iNSpill << " at " << fdStartAna10s / 1.E9
2168 << "s after " << dDTLEvt / 1.E9 << " s without events";
2169 for (Int_t iDet = 0; iDet < fDigiBdfPar->GetNbDet(); iDet++) {
2170 if (NULL == fhRpcCluRate10s[iDet]) continue;
2171 fhRpcCluRate10s[iDet]->Reset("ICES");
2172 }
2173 dTimeAna10s = 0.;
2174 }
2175 }
2176 }
2177
2178 if (fdStartAna10s > 0.) fhRpcCluRate10s[iDetIndx]->Fill(dTimeAna10s / 1.E9, 1.);
2179 //fhRpcCluRate10s[iDetIndx]->Fill(dTimeAna10s/1.E9,1./fhRpcCluRate10s[iDetIndx]->GetBinWidth(1));
2180
2181 if (fdMemoryTime > 0. && fvLastHits[iSmType][iSm][iRpc][iCh].size() == 0)
2182 LOG(fatal) << Form(" <E> hit not stored in memory for TSRC %d%d%d%d", iSmType, iSm, iRpc, iCh);
2183
2184 //CheckLHMemory();
2185
2186 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for outdated hits
2187 //std::list<CbmTofHit *>::iterator it0=fvLastHits[iSmType][iSm][iRpc][iCh].begin();
2188 //std::list<CbmTofHit *>::iterator itL=fvLastHits[iSmType][iSm][iRpc][iCh].end();
2189 //CbmTofHit* pH0 = *it0;
2190 //CbmTofHit* pHL = *(--itL);
2191 CbmTofHit* pH0 = fvLastHits[iSmType][iSm][iRpc][iCh].front();
2192 CbmTofHit* pHL = fvLastHits[iSmType][iSm][iRpc][iCh].back();
2193 if (pH0->GetTime() > pHL->GetTime())
2194 LOG(warning) << Form("Invalid time ordering in ev %8.0f in list of "
2195 "size %lu for TSRC %d%d%d%d: Delta t %f ",
2196 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
2197 pHL->GetTime() - pH0->GetTime());
2198
2199 // while( (*((std::list<CbmTofHit *>::iterator) fvLastHits[iSmType][iSm][iRpc][iCh].begin()))->GetTime()+fdMemoryTime < pHit->GetTime()
2200 while (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 2.
2201 || fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime() + fdMemoryTime < pHit->GetTime())
2202
2203 {
2204 LOG(debug) << " pop from list size " << fvLastHits[iSmType][iSm][iRpc][iCh].size()
2205 << Form(" outdated hits for ev %8.0f in TSRC %d%d%d%d", fdEvent, iSmType, iSm, iRpc, iCh)
2206 << Form(" with tHit - tLast %f ",
2207 pHit->GetTime() - fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime())
2208 //(*((std::list<CbmTofHit *>::iterator) fvLastHits[iSmType][iSm][iRpc][iCh].begin()))->GetTime())
2209 ;
2210 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != pHit->GetAddress())
2211 LOG(fatal) << Form("Inconsistent address in list of size %lu for TSRC %d%d%d%d: "
2212 "0x%08x, time %f",
2213 fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
2214 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
2215 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
2216 fvLastHits[iSmType][iSm][iRpc][iCh].front()->Delete();
2217 fvLastHits[iSmType][iSm][iRpc][iCh].pop_front();
2218 }
2219 } //fvLastHits[iSmType][iSm][iRpc][iCh].size()>1)
2220
2221 // plot remaining time difference to previous hits
2222 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
2223 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
2224 Double_t dTotSum = 0.;
2225 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
2226 CbmLink L0 = digiMatch->GetLink(iLink);
2227 Int_t iDigInd0 = L0.GetIndex();
2228 Int_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex();
2229 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
2230 CbmTofDigi* pDig1 = &(fTofCalDigiVec->at(iDigInd1));
2231 //CbmTofDigi *pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
2232 //CbmTofDigi *pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
2233 dTotSum += pDig0->GetTot() + pDig1->GetTot();
2234 }
2235
2236 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
2237 itL--;
2238 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
2239 itL--;
2240 fhRpcDTLastHits[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()));
2241 fhRpcDTLastHits_CluSize[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
2242 digiMatch->GetNofLinks() / 2.);
2243 fhRpcDTLastHits_Tot[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()), dTotSum);
2244 }
2245 }
2246 } // iHitInd loop end
2247
2248 // do reference first
2249 dTRef = dDoubleMax;
2250 fTRefHits = 0;
2251 Double_t dTRefAv = 0.;
2252 std::vector<CbmTofHit*> pvBeamRef;
2253 Int_t iBRefMul = 0;
2254 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
2255 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
2256 if (NULL == pHit) continue;
2257 Int_t iDetId = (pHit->GetAddress() & SelMask);
2258 if (fDutAddr == fSelAddr) fiBeamRefAddr = iDetId; // dark rate inspection
2259 if (fiBeamRefAddr == iDetId) {
2260 if (fIdMode == 0) { //counterwise trigger
2262 }
2263 else { //modulewise reference
2264 if (iBRefMul == 0)
2265 for (UInt_t uDet = 0; uDet < fviClusterMul[fiBeamRefType][fiBeamRefSm].size(); uDet++)
2266 iBRefMul += fviClusterMul[fiBeamRefType][fiBeamRefSm][uDet];
2267 LOG(debug) << "Reference module multiplicity " << iBRefMul;
2268 if (iBRefMul > fiBeamRefMulMax) continue;
2269 }
2270 /* disabled by nh 23.05.2021
2271 // Check Tot
2272 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
2273 Double_t TotSum = 0.;
2274 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
2275 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
2276 UInt_t iDigInd0 = L0.GetIndex();
2277 // if (iDigInd0 < fTofCalDigisColl->GetEntriesFast()){
2278 if (iDigInd0 < fTofCalDigiVec->size()) {
2279 // CbmTofDigi *pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
2280 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
2281 TotSum += pDig0->GetTot();
2282 }
2283 }
2284 TotSum /= (0.5 * digiMatch->GetNofLinks());
2285 if (TotSum > fhRpcCluTot[iIndexDut]->GetYaxis()->GetXmax()) continue; // ignore too large clusters
2286 */
2287 fTRefHits = 1;
2288 pvBeamRef.push_back(pHit);
2289 if (pHit->GetTime() < dTRef) {
2290 dTRef = pHit->GetTime();
2291 pBeamRef = pHit;
2292 }
2293 dTRefAv = (dTRefAv * iBeamRefMul + pHit->GetTime()) / (iBeamRefMul + 1);
2294 iBeamRefMul++;
2295 }
2296 else { //additional reference type multiplicity
2297 if (fiBeamRefType == CbmTofAddress::GetSmType(iDetId)) iBeamAddRefMul++;
2298 }
2299 }
2300 if (iBeamRefMul > 2) {
2301 //LOG(info) << "BeamRefMul " << iBeamRefMul << ", pick hit with time closest to average " << dTRefAv << " from "
2302 // << pvBeamRef.size();
2303 Double_t dTDist = dDoubleMax;
2304 for (UInt_t i = 0; i < pvBeamRef.size(); i++) {
2305 //LOG(info) << "i " << i << " " << pvBeamRef[i]->GetTime();
2306 if (TMath::Abs(pvBeamRef[i]->GetTime() - dTRefAv) < dTDist) {
2307 pBeamRef = pvBeamRef[i];
2308 dTRef = pBeamRef->GetTime();
2309 dTDist = TMath::Abs(dTRef - dTRefAv);
2310 }
2311 }
2312 }
2313
2314 LOG(debug) << "CbmTofEventClusterizer::FillHistos: BRefMul: " << iBeamRefMul << ", " << iBeamAddRefMul;
2315
2316 if (iBeamRefMul == 0) return kFALSE; // don't fill histos without reference time
2317 if (iBeamAddRefMul < fiBeamAddRefMul) return kFALSE; // ask for confirmation by other beam counters
2318 if (NULL == pBeamRef) return kFALSE; // should never happen
2319
2320 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
2321 if (fDutAddr == fSelAddr)
2322 BSel[iSel] = kTRUE;
2323 else {
2324 BSel[iSel] = kFALSE;
2325 pTrig[iSel] = NULL;
2326 Int_t iDutMul = 0;
2327 Int_t iRefMul = 0;
2328 Int_t iR0 = 0;
2329 Int_t iRl = 0;
2330 ddXdZ[iSel] = 0.;
2331 ddYdZ[iSel] = 0.;
2332 dSel2dXdYMin[iSel] = 1.E300;
2333 dTTrig[iSel] = dDoubleMax;
2334
2335 switch (iSel) {
2336 case 0: // Detector under Test (Dut) && Diamonds,BeamRef
2337 iRl = fviClusterMul[fDutId][fDutSm].size();
2338 if (fIdMode == 0 && fDutRpc > -1) {
2339 iR0 = fDutRpc;
2340 iRl = fDutRpc + 1;
2341 }
2342 for (Int_t iRpc = iR0; iRpc < iRl; iRpc++)
2343 iDutMul += fviClusterMul[fDutId][fDutSm][iRpc];
2344 LOG(debug) << "Selector 0: DutMul " << fviClusterMul[fDutId][fDutSm][fDutRpc] << ", " << iDutMul
2345 << ", BRefMul " << iBeamRefMul << " TRef: " << dTRef << ", BeamAddRefMul " << iBeamAddRefMul
2346 << ", " << fiBeamAddRefMul;
2347
2348 if (iDutMul > 0 && iDutMul < fiCluMulMax) {
2349 LOG(debug1) << "Found selector 0, NbHits " << iNbTofHits;
2350 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
2351 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
2352 if (NULL == pHit) continue;
2353
2354 Int_t iDetId = (pHit->GetAddress() & SelMask);
2355 LOG(debug1) << Form(" Det 0x%08x, Dut 0x%08x, T %f, TTrig %f", iDetId, fDutAddr, pHit->GetTime(),
2356 dTTrig[iSel]);
2357 //if( fDutId == CbmTofAddress::GetSmType( iDetId ))
2358 if (fDutAddr == iDetId) {
2359 if (pHit->GetTime() < dTTrig[iSel]) {
2360 if (TMath::Abs(pBeamRef->GetTime() - pHit->GetTime()) < fdDelTofMax) {
2361 // < fhTRpcCluTOff[iIndexDut][iSel]->GetYaxis()->GetXmax()) {
2362 dTTrig[iSel] = pHit->GetTime();
2363 pTrig[iSel] = pHit;
2364 BSel[iSel] = kTRUE;
2365 }
2366 }
2367 }
2368 }
2369 if (BSel[iSel])
2370 LOG(debug) << Form("Found selector 0 with mul %d from 0x%08x at %f ", iDutMul,
2371 pTrig[iSel]->GetAddress(), dTTrig[iSel]);
2372 }
2373 break;
2374
2375 case 1: // MRef & BRef
2376 iRl = fviClusterMul[fSelId][fSelSm].size();
2377 if (fIdMode == 0 && fSelRpc > -1) {
2378 iR0 = fSelRpc;
2379 iRl = fSelRpc + 1;
2380 }
2381 for (Int_t iRpc = iR0; iRpc < iRl; iRpc++)
2382 iRefMul += fviClusterMul[fSelId][fSelSm][iRpc];
2383 LOG(debug) << "CbmTofEventClusterizer::FillHistos(): selector 1: RefMul "
2384 << fviClusterMul[fSelId][fSelSm][fSelRpc] << ", " << iRefMul << ", BRefMul " << iBeamRefMul;
2385 if (iRefMul > 0 && iRefMul < fiCluMulMax) {
2386 LOG(debug1) << "CbmTofEventClusterizer::FillHistos(): Found "
2387 "selector 1, BeamRef at"
2388 << pBeamRef;
2389 dTTrig[iSel] = dDoubleMax;
2390 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
2391 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
2392 if (NULL == pHit) continue;
2393
2394 Int_t iDetId = (pHit->GetAddress() & SelMask);
2395 if (fSelAddr == iDetId) {
2396 LOG(debug1) << "Check hit " << iHitInd << ", sel " << iSel << ", t: " << pHit->GetTime()
2397 << ", TT " << dTTrig[iSel];
2398
2399 if (pHit->GetTime() < dTTrig[iSel]) {
2400 if (TMath::Abs(pBeamRef->GetTime() - pHit->GetTime()) < fdDelTofMax) {
2401 // < fhTRpcCluTOff[iIndexDut][iSel]->GetYaxis()->GetXmax()) {
2402 dTTrig[iSel] = pHit->GetTime();
2403 pTrig[iSel] = pHit;
2404 BSel[iSel] = kTRUE;
2405 LOG(debug1) << "Accept hit " << iHitInd << ", sel " << iSel << ", t: " << pHit->GetTime()
2406 << ", TT " << dTTrig[iSel];
2407 }
2408 }
2409 }
2410 }
2411 if (BSel[iSel])
2412 LOG(debug) << Form("Found selector 1 with mul %d from 0x%08x at %f ", iRefMul,
2413 pTrig[iSel]->GetAddress(), dTTrig[iSel]);
2414 }
2415 break;
2416
2417 default:
2418 LOG(info) << "CbmTofEventClusterizer::FillHistos: selection not "
2419 "implemented "
2420 << iSel;
2421 ;
2422 } // switch end
2423 if (fTRefMode > 10) {
2424 dTTrig[iSel] = dTRef;
2425 Int_t iReqMul = (fTRefMode - fTRefMode % 10) / 10;
2426 if (iDetMul < iReqMul) BSel[iSel] = 0;
2427 }
2428 }
2429 } // iSel - loop end
2430
2431 LOG(debug1) << "selector loop passed, continue with Sel2Id " << fSel2Id
2432 << Form(", BSel %d %d ", (Int_t) BSel[0], (Int_t) BSel[1]);
2433
2434 if (fSel2Id > -1) { // confirm selector by independent match
2435 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
2436 if (BSel[iSel]) {
2437 BSel[iSel] = kFALSE;
2440 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
2441 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
2442 if (NULL == pHit) continue;
2443 Int_t iDetId = (pHit->GetAddress() & SelMask);
2444 if (fSel2Addr == (iDetId & SelMask)) {
2445 Double_t dzscal = 1.;
2446 if (fEnableMatchPosScaling) dzscal = pHit->GetZ() / pTrig[iSel]->GetZ();
2447 Double_t dSEl2dXdz = (pHit->GetX() - pTrig[iSel]->GetX()) / (pHit->GetZ() - pTrig[iSel]->GetZ());
2448 Double_t dSEl2dYdz = (pHit->GetY() - pTrig[iSel]->GetY()) / (pHit->GetZ() - pTrig[iSel]->GetZ());
2449
2450 if (iDetId == fiBeamRefAddr
2451 || (TMath::Sqrt(TMath::Power(pHit->GetX() - dzscal * pTrig[iSel]->GetX(), 2.)
2452 + TMath::Power(pHit->GetY() - dzscal * pTrig[iSel]->GetY(), 2.))
2453 < fdCaldXdYMax)) {
2454 BSel[iSel] = kTRUE;
2455 Double_t dX2Y2 = TMath::Sqrt(dSEl2dXdz * dSEl2dXdz + dSEl2dYdz * dSEl2dYdz);
2456 if (dX2Y2 < dSel2dXdYMin[iSel]) {
2457 ddXdZ[iSel] = dSEl2dXdz;
2458 ddYdZ[iSel] = dSEl2dYdz;
2459 dSel2dXdYMin[iSel] = dX2Y2;
2460 }
2461 break;
2462 }
2463 }
2464 }
2465 } // BSel condition end
2466 } // iSel lopp end
2467 } // Sel2Id condition end
2468
2469 /*
2470 // find the best dTRef
2471 fTRefHits=0;
2472 dTRef=0.; // invalidate old value
2473 Double_t dRefChi2=dDoubleMax;
2474 for( Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++)
2475 {
2476 pHit = (CbmTofHit*) fTofHitsColl->At( iHitInd );
2477 if (NULL==pHit) continue;
2478 Int_t iDetId = (pHit->GetAddress() & SelMask);
2479
2480 if( fiBeamRefType == CbmTofAddress::GetSmType( iDetId )){
2481 if(fiBeamRefSm == CbmTofAddress::GetSmId( iDetId ))
2482 {
2483 Double_t dDT2=0.;
2484 Double_t dNT=0.;
2485 for (Int_t iSel=0; iSel<iNSel; iSel++){
2486 if(BSel[iSel]){
2487 dDT2 += TMath::Power(pHit->GetTime()-dTTrig[iSel],2);
2488 dNT++;
2489 }
2490 }
2491 if( dNT > 0)
2492 if( dDT2/dNT < dRefChi2 )
2493 {
2494 fTRefHits=1;
2495 dTRef = pHit->GetTime();
2496 dRefChi2 = dDT2/dNT;
2497 }
2498 }
2499 }
2500 }
2501 */
2502
2503 LOG(debug1) << "Generate trigger pattern";
2504 UInt_t uTriggerPattern = 1;
2505 if (NULL != fTrbHeader)
2506 uTriggerPattern = fTrbHeader->GetTriggerPattern();
2507 else {
2508 for (Int_t iSel = 0; iSel < iNSel; iSel++)
2509 if (BSel[iSel]) {
2510 uTriggerPattern |= (0x1 << (iSel * 3 + CbmTofAddress::GetRpcId(pTrig[iSel]->GetAddress() & DetMask)));
2511 }
2512 }
2513 LOG(debug1) << "Inspect trigger pattern";
2514 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
2515 if (BSel[iSel]) {
2516 if (dTRef != 0. && fTRefHits > 0) {
2517 for (UInt_t uChannel = 0; uChannel < 16; uChannel++) {
2518 if (uTriggerPattern & (0x1 << uChannel)) {
2519 fhSeldT[iSel]->Fill(dTTrig[iSel] - dTRef, uChannel);
2520 }
2521 }
2522 }
2523 }
2524 }
2525 } // 0<iNSel software triffer check end
2526
2527 LOG(debug1) << "start filling histos ";
2528
2529 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
2530 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
2531 if (NULL == pHit) continue;
2532
2533 Int_t iDetId = (pHit->GetAddress() & DetMask);
2534 LOG(debug1) << "Process Hit " << iHitInd << ", DetId " << iDetId;
2535
2536 std::map<UInt_t, UInt_t>::iterator it = fDetIdIndexMap.find(iDetId);
2537 if (it == fDetIdIndexMap.end()) continue; // continue for invalid detector index
2538 Int_t iDetIndx = it->second; //fDetIdIndexMap[iDetId];
2539
2540 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
2541 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
2542 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
2543 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
2544 if (-1 < fviClusterMul[iSmType][iSm][iRpc]) {
2545 for (Int_t iSel = 0; iSel < iNSel; iSel++)
2546 if (BSel[iSel]) {
2547 Double_t w = fviClusterMul[iSmType][iSm][iRpc];
2548 if (w == 0.)
2549 w = 1.;
2550 else
2551 w = 1. / w;
2552 fhTRpcCluMul[iDetIndx][iSel]->Fill(fviClusterMul[iSmType][iSm][iRpc], w);
2553 }
2554 }
2555
2556 if (fviClusterMul[iSmType][iSm][iRpc] > fiCluMulMax) continue; // skip this event
2557 if (iBeamRefMul == 0) break;
2558
2559 Int_t iChId = pHit->GetAddress();
2560 fChannelInfo = fDigiPar->GetCell(iChId);
2562 if (NULL == fChannelInfo) {
2563 LOG(error) << "Invalid Channel Pointer for ChId " << Form(" 0x%08x ", iChId) << ", Ch " << iCh;
2564 continue;
2565 }
2566 /*TGeoNode *fNode=*/ // prepare global->local trafo
2567 //gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
2568
2569 LOG(debug1) << "Hit info: "
2570 << Form(" 0x%08x %d %f %f %f %f %f %d", iChId, iCh, pHit->GetX(), pHit->GetY(), pHit->GetTime(),
2571 fChannelInfo->GetX(), fChannelInfo->GetY(), iHitInd);
2572
2573 Double_t hitpos[3];
2574 hitpos[0] = pHit->GetX();
2575 hitpos[1] = pHit->GetY();
2576 hitpos[2] = pHit->GetZ();
2577 Double_t hitpos_local[3];
2578 //TGeoNode* cNode = gGeoManager->GetCurrentNode();
2579 fCellIdGeoMap[iChId]->GetMatrix()->MasterToLocal(hitpos, hitpos_local);
2580 /*
2581 LOG(debug1) << Form(" MasterToLocal for %d, %d%d%d, node %p: "
2582 "(%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)",
2583 iDetIndx, iSmType, iSm, iRpc, cNode, hitpos[0], hitpos[1], hitpos[2], hitpos_local[0],
2584 hitpos_local[1], hitpos_local[2]);
2585 */
2586 Bool_t bFillPos = kTRUE;
2587 //if( fCalMode/10 > 4 && pHit->GetClusterSize() < 3 ) bFillPos=kFALSE;
2588 if (bFillPos) {
2589 fhRpcCluPosition[iDetIndx]->Fill((Double_t) iCh,
2590 hitpos_local[1]); //pHit->GetY()-fChannelInfo->GetY());
2591 fhRpcCluPos[iDetIndx]->Fill(pHit->GetX(), pHit->GetY());
2592 fhSmCluPosition[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), hitpos_local[1]);
2593 }
2594 for (Int_t iSel = 0; iSel < iNSel; iSel++)
2595 if (BSel[iSel]) {
2596 fhTRpcCluPosition[iDetIndx][iSel]->Fill((Double_t) iCh,
2597 hitpos_local[1]); //pHit->GetY()-fChannelInfo->GetY());
2598 fhTSmCluPosition[iSmType][iSel]->Fill((Double_t)(iSm * iNbRpc + iRpc), hitpos_local[1]);
2599 }
2600
2601 if (TMath::Abs(hitpos_local[1]) > fChannelInfo->GetSizey() * fPosYMaxScal) continue;
2602
2603 Double_t dTimeAna = (pHit->GetTime() + dTsStartTime - fdStartAnalysisTime) / 1.E9;
2604 if (dTRef != 0.) fhRpcCluTimeEvol[iDetIndx]->Fill(dTimeAna, pHit->GetTime() - dTRef);
2605 fhRpcCluPositionEvol[iDetIndx]->Fill(dTimeAna, hitpos_local[1]);
2606 //LOG(info) << "Fill TEvol at " << dTimeAna ;
2607
2608 LOG(debug1) << " TofDigiMatchColl entries:" << fTofDigiMatchColl->GetEntriesFast();
2609
2610 if (iHitInd > fTofDigiMatchColl->GetEntriesFast()) {
2611 LOG(error) << " Inconsistent DigiMatches for Hitind " << iHitInd
2612 << ", TClonesArraySize: " << fTofDigiMatchColl->GetEntriesFast();
2613 }
2614
2615 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
2616 LOG(debug1) << " got " << digiMatch->GetNofLinks() << " matches for iCh " << iCh << " at iHitInd " << iHitInd;
2617
2618 fhRpcCluSize[iDetIndx]->Fill((Double_t) iCh, digiMatch->GetNofLinks() / 2.);
2619
2620 for (Int_t iSel = 0; iSel < iNSel; iSel++)
2621 if (BSel[iSel]) {
2622 fhTRpcCluSize[iDetIndx][iSel]->Fill((Double_t) iCh, digiMatch->GetNofLinks() / 2.);
2623 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
2624 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
2625 itL--;
2626 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
2627 itL--;
2628 fhTRpcCluSizeDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
2629 digiMatch->GetNofLinks() / 2.);
2630 }
2631 }
2632 }
2633
2634 /*
2635 Double_t TotSum = 0.;
2636 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink++) { // loop over digis
2637 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
2638 UInt_t iDigInd0 = L0.GetIndex();
2639 // if (iDigInd0 < fTofCalDigisColl->GetEntriesFast()){
2640 if (iDigInd0 < fTofCalDigiVec->size()) {
2641 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
2642 // CbmTofDigi *pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
2643 TotSum += pDig0->GetTot();
2644 }
2645 }
2646 */
2647 Double_t dMeanTimeSquared = 0.;
2648 Double_t dNstrips = 0.;
2649
2650 Double_t dDelTof = 0.;
2651 Double_t dTcor[iNSel];
2652 Double_t dTTcor[iNSel];
2653 Double_t dZsign[iNSel];
2654 Double_t dzscal = 1.;
2655 //Double_t dDist=0.;
2656
2657 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
2658 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
2659 UInt_t iDigInd0 = L0.GetIndex();
2660 UInt_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex(); //vDigish.at(ivDigInd+1);
2661 //LOG(debug1)<<" " << iDigInd0<<", "<<iDigInd1;
2662
2663 // if (iDigInd0 < fTofCalDigisColl->GetEntriesFast() && iDigInd1 < fTofCalDigisColl->GetEntriesFast()){
2664 if (iDigInd0 < fTofCalDigiVec->size() && iDigInd1 < fTofCalDigiVec->size()) {
2665 // CbmTofDigi *pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
2666 // CbmTofDigi *pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
2667 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
2668 CbmTofDigi* pDig1 = &(fTofCalDigiVec->at(iDigInd1));
2669 if ((Int_t) pDig0->GetType() != iSmType) {
2670 LOG(error) << Form(" Wrong Digi SmType for Tofhit %d in iDetIndx "
2671 "%d, Ch %d with %3.0f strips at Indx %d, %d",
2672 iHitInd, iDetIndx, iCh, dNstrips, iDigInd0, iDigInd1);
2673 }
2674 LOG(debug1) << " fhRpcCluTot: Digi 0 " << iDigInd0 << ": Ch " << pDig0->GetChannel() << ", Side "
2675 << pDig0->GetSide() << ", StripSide " << (Double_t) iCh * 2. + pDig0->GetSide() << " Digi 1 "
2676 << iDigInd1 << ": Ch " << pDig1->GetChannel() << ", Side " << pDig1->GetSide() << ", StripSide "
2677 << (Double_t) iCh * 2. + pDig1->GetSide() << ", Tot0 " << pDig0->GetTot() << ", Tot1 "
2678 << pDig1->GetTot();
2679
2680 fhRpcCluTot[iDetIndx]->Fill(pDig0->GetChannel() * 2. + pDig0->GetSide(), pDig0->GetTot());
2681 fhRpcCluTot[iDetIndx]->Fill(pDig1->GetChannel() * 2. + pDig1->GetSide(), pDig1->GetTot());
2682
2683 Int_t iCh0 = pDig0->GetChannel();
2684 Int_t iCh1 = pDig1->GetChannel();
2685 Int_t iS0 = pDig0->GetSide();
2686 Int_t iS1 = pDig1->GetSide();
2687
2688 CbmTofDigi* pDigS0 = pDig0;
2689 if (iS0 == 1) pDigS0 = pDig1;
2690 CbmTofDigi* pDigS1 = pDig1;
2691 if (iS1 == 0) pDigS1 = pDig0;
2692
2693 fhRpcDigiTotLeft[iDetIndx]->Fill(pDigS0->GetTot(), hitpos_local[1]);
2694 fhRpcDigiTotRight[iDetIndx]->Fill(pDigS1->GetTot(), hitpos_local[1]);
2695 fhRpcDigiTotDiff[iDetIndx]->Fill(pDigS0->GetTot() - pDigS1->GetTot(), hitpos_local[1]);
2696 fhRpcDigiTotMap[iDetIndx]->Fill(pDigS0->GetTot(), pDigS1->GetTot());
2697
2698 if (iCh0 != iCh1 || iS0 == iS1) {
2699 LOG(error) << Form(" MT2 for Tofhit %d in iDetIndx %d, Ch %d from "
2700 "in event %d, ",
2701 iHitInd, iDetIndx, iCh, (Int_t) fdEvent)
2702 << Form(" Dig0: Ind %d, Ch %d, Side %d, T: %6.1f ", iDigInd0, iCh0, iS0, pDig0->GetTime())
2703 << Form(" Dig1: Ind %d, Ch %d, Side %d, T: %6.1f ", iDigInd1, iCh1, iS1, pDig1->GetTime());
2704 continue;
2705 }
2706
2707 if (0 > iCh0 || fDigiBdfPar->GetNbChan(iSmType, iRpc) <= iCh0) {
2708 LOG(error) << Form(" Wrong Digi for Tofhit %d in iDetIndx %d, Ch %d at Indx %d, %d "
2709 "from %3.0f strips: %d, %d, %d, %d",
2710 iHitInd, iDetIndx, iCh, iDigInd0, iDigInd1, dNstrips, iCh0, iCh1, iS0, iS1);
2711 continue;
2712 }
2713
2714 if (digiMatch->GetNofLinks() > 2) //&& digiMatch->GetNofLinks()<8 ) // FIXME: hardcoded limits on CluSize
2715 {
2716 dNstrips += 1.;
2717 dMeanTimeSquared += TMath::Power(0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime(), 2);
2718 // fhRpcCluAvWalk[iDetIndx]->Fill(0.5*(pDig0->GetTot()+pDig1->GetTot()),
2719 // 0.5*(pDig0->GetTime()+pDig1->GetTime())-pHit->GetTime());
2720
2721 fhRpcCluAvLnWalk[iDetIndx]->Fill(TMath::Log10(0.5 * (pDig0->GetTot() + pDig1->GetTot())),
2722 0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime());
2723
2724 //Double_t dTotWeight = (pDig0->GetTot() + pDig1->GetTot()) / TotSum;
2725 Double_t dCorWeight = 1.; // - dTotWeight;
2726
2727 fhRpcCluDelTOff[iDetIndx]->Fill(pDig0->GetChannel(),
2728 0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime(), dCorWeight);
2729
2730 Double_t dDelPos = 0.5 * (pDig0->GetTime() - pDig1->GetTime()) * fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
2731 if (0 == pDig0->GetSide()) dDelPos *= -1.;
2732 fhRpcCluDelPos[iDetIndx]->Fill(pDig0->GetChannel(), dDelPos - hitpos_local[1], dCorWeight);
2733
2734 fhRpcCluWalk[iDetIndx][iCh0][iS0]->Fill(
2735 pDig0->GetTot(),
2736 pDig0->GetTime()
2737 - (pHit->GetTime()
2738 - (1. - 2. * pDig0->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
2739
2740 fhRpcCluWalk[iDetIndx][iCh1][iS1]->Fill(
2741 pDig1->GetTot(),
2742 pDig1->GetTime()
2743 - (pHit->GetTime()
2744 - (1. - 2. * pDig1->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
2745
2746 fhRpcCluAvWalk[iDetIndx]->Fill(pDig0->GetTot(), pDig0->GetTime()
2747 - (pHit->GetTime()
2748 - (1. - 2. * pDig0->GetSide()) * hitpos_local[1]
2749 / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
2750 fhRpcCluAvWalk[iDetIndx]->Fill(pDig1->GetTot(), pDig1->GetTime()
2751 - (pHit->GetTime()
2752 - (1. - 2. * pDig1->GetSide()) * hitpos_local[1]
2753 / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
2754 } // end of Clustersize > 1 condition
2755
2756 LOG(debug1) << " fhTRpcCluTot: Digi 0 " << iDigInd0 << ": Ch " << pDig0->GetChannel() << ", Side "
2757 << pDig0->GetSide() << ", StripSide " << (Double_t) iCh * 2. + pDig0->GetSide() << " Digi 1 "
2758 << iDigInd1 << ": Ch " << pDig1->GetChannel() << ", Side " << pDig1->GetSide() << ", StripSide "
2759 << (Double_t) iCh * 2. + pDig1->GetSide();
2760
2761 for (Int_t iSel = 0; iSel < iNSel; iSel++)
2762 if (BSel[iSel]) {
2763 if (NULL == pHit || NULL == pTrig[iSel]) {
2764 LOG(info) << " invalid pHit, iSel " << iSel << ", iDetIndx " << iDetIndx;
2765 break;
2766 }
2767 if (pHit->GetAddress() == pTrig[iSel]->GetAddress()) continue;
2768
2769 fhTRpcCluTot[iDetIndx][iSel]->Fill(pDig0->GetChannel() * 2. + pDig0->GetSide(), pDig0->GetTot());
2770 fhTRpcCluTot[iDetIndx][iSel]->Fill(pDig1->GetChannel() * 2. + pDig1->GetSide(), pDig1->GetTot());
2771 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
2772 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
2773 itL--;
2774 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
2775 itL--;
2776 fhTRpcCluTotDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
2777 pDig0->GetTot());
2778 fhTRpcCluTotDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
2779 pDig1->GetTot());
2780 }
2781 }
2782 fhTRpcCluQASY[iDetIndx][iSel]->Fill((1. - 2. * pDig0->GetSide()) * (pDig0->GetTot() - pDig1->GetTot())
2783 / (pDig0->GetTot() + pDig1->GetTot()),
2784 hitpos_local[1]);
2785
2786 if (iLink == 0) { // Fill histo only once (for 1. digi entry)
2787 if (fEnableMatchPosScaling) dzscal = pHit->GetZ() / pTrig[iSel]->GetZ();
2788 fhTRpcCludXdY[iDetIndx][iSel]->Fill(pHit->GetX() - dzscal * pTrig[iSel]->GetX(),
2789 pHit->GetY() - dzscal * pTrig[iSel]->GetY());
2790 /*
2791 if (iSmType == 0 && iSm==4 && iRpc==2
2792 && pHit->GetX() - dzscal * pTrig[iSel]->GetX()< -40
2793 && TMath::Abs(pHit->GetY() - dzscal * pTrig[iSel]->GetY())<10.) {
2794 LOG(fatal)<< Form("Ev %d, TSR %d%d%d, Addr 0x%08x - 0x%08x: x %4.1f, %4.1f, %4.1f, y %4.1f, %4.1f, %4.1f, z %5.1f, %5.1f, %5.1f, dzscal %4.2f",
2795 (int)fdEvent, iSmType, iSm, iRpc,
2796 pHit->GetAddress(), pTrig[iSel]->GetAddress(),
2797 pHit->GetX(),pTrig[iSel]->GetX(),pHit->GetX() - dzscal * pTrig[iSel]->GetX(),
2798 pHit->GetY(),pTrig[iSel]->GetY(),pHit->GetY() - dzscal * pTrig[iSel]->GetY(),
2799 pHit->GetZ(),pTrig[iSel]->GetZ(),pHit->GetZ() - dzscal * pTrig[iSel]->GetZ(), dzscal);
2800 }
2801*/
2802 dZsign[iSel] = 1.;
2803 if (pHit->GetZ() < pTrig[iSel]->GetZ()) dZsign[iSel] = -1.;
2804 }
2806 if (iSmType == fiBeamRefType // to get entries in diamond/BeamRef histos
2807 || TMath::Sqrt(TMath::Power(pHit->GetX() - dzscal * pTrig[iSel]->GetX(), 2.)
2808 + TMath::Power(pHit->GetY() - dzscal * pTrig[iSel]->GetY(), 2.))
2809 < fdCaldXdYMax) {
2810 if (!fEnableMatchPosScaling && dSel2dXdYMin[iSel] < 1.E300)
2811 if (TMath::Sqrt(
2812 TMath::Power(pHit->GetX()
2813 - (pTrig[iSel]->GetX() + ddXdZ[iSel] * (pHit->GetZ() - (pTrig[iSel]->GetZ()))),
2814 2.)
2815 + TMath::Power(pHit->GetY()
2816 - (pTrig[iSel]->GetY() + ddYdZ[iSel] * (pHit->GetZ() - (pTrig[iSel]->GetZ()))),
2817 2.))
2818 > 0.5 * fdCaldXdYMax)
2819 continue; // refine position selection cut in cosmic measurement
2820 dTcor[iSel] = 0.; // precaution
2821 if (dTRef != 0.
2822 && TMath::Abs(dTRef - dTTrig[iSel]) < fdDelTofMax) { // correct times for DelTof - velocity spread
2823 if (iLink == 0) { // do calculations only once (at 1. digi entry) // interpolate!
2824 // calculate spatial distance to trigger hit
2825 /*
2826 dDist=TMath::Sqrt(TMath::Power(pHit->GetX()-pTrig[iSel]->GetX(),2.)
2827 +TMath::Power(pHit->GetY()-pTrig[iSel]->GetY(),2.)
2828 +TMath::Power(pHit->GetZ()-pTrig[iSel]->GetZ(),2.));
2829 */
2830 // determine correction value
2831 //if(fiBeamRefAddr != iDetId) // do not do this for reference counter itself
2832 if (fTRefMode < 11) // do not do this for trigger counter itself
2833 {
2834 Double_t dTentry = dTRef - dTTrig[iSel] + fdDelTofMax;
2835 Int_t iBx = dTentry / 2. / fdDelTofMax * nbClDelTofBinX;
2836 if (iBx < 0) iBx = 0;
2837 if (iBx > nbClDelTofBinX - 1) iBx = nbClDelTofBinX - 1;
2838 Double_t dBinWidth = 2. * fdDelTofMax / nbClDelTofBinX;
2839 Double_t dDTentry = dTentry - ((Double_t) iBx) * dBinWidth;
2840 Int_t iBx1 = 0;
2841 dDTentry < 0 ? iBx1 = iBx - 1 : iBx1 = iBx + 1;
2842 Double_t w0 = 1. - TMath::Abs(dDTentry) / dBinWidth;
2843 Double_t w1 = 1. - w0;
2844 if (iBx1 < 0) iBx1 = 0;
2845 if (iBx1 > nbClDelTofBinX - 1) iBx1 = nbClDelTofBinX - 1;
2846 dDelTof = fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] * w0
2847 + fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx1][iSel] * w1;
2848 //dDelTof *= dDist; // has to be consistent with fhTRpcCluDelTof filling
2849 LOG(debug1) << Form(" DelTof for SmT %d, Sm %d, R %d, T %d, dTRef "
2850 "%6.1f, Bx %d, Bx1 %d, DTe %6.1f -> DelT %6.1f",
2851 iSmType, iSm, iRpc, iSel, dTRef - dTTrig[iSel], iBx, iBx1, dDTentry, dDelTof);
2852 }
2853 dTTcor[iSel] = dDelTof * dZsign[iSel];
2854 dTcor[iSel] = pHit->GetTime() - dDelTof - dTTrig[iSel];
2855 // Double_t dAvTot=0.5*(pDig0->GetTot()+pDig1->GetTot()); (VF) not used
2856 } // if(iLink==0)
2857 if (dTcor[iSel] == 0.) continue;
2858 LOG(debug) << Form(" TRpcCluWalk for Ev %d, Link %d(%d), Sel %d, TSR %d%d%d, "
2859 "Ch %d,%d, S %d,%d T %f, DelTof %6.1f, W-ent: %6.0f,%6.0f",
2860 fiNevtBuild, iLink, (Int_t) digiMatch->GetNofLinks(), iSel, iSmType, iSm, iRpc,
2861 iCh0, iCh1, iS0, iS1, dTTrig[iSel], dDelTof,
2862 fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->GetEntries(),
2863 fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->GetEntries());
2864
2865 if (fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->GetEntries()
2866 != fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->GetEntries())
2867 LOG(error) << Form(" Inconsistent walk histograms -> debugging "
2868 "necessary ... for %d, %d, %d, %d, %d, %d, %d ",
2869 fiNevtBuild, iDetIndx, iSel, iCh0, iCh1, iS0, iS1);
2870
2871 LOG(debug1) << Form(
2872 " TRpcCluWalk values side %d: %f, %f, side %d: %f, %f ", iS0, pDig0->GetTot(),
2873 pDig0->GetTime()
2874 + ((1. - 2. * pDig0->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc))
2875 - dTTcor[iSel] - dTTrig[iSel],
2876 iS1, pDig1->GetTot(),
2877 pDig1->GetTime()
2878 + ((1. - 2. * pDig1->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc))
2879 - dTTcor[iSel] - dTTrig[iSel]);
2880
2881 fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->Fill(
2882 pDig0->GetTot(),
2883 //(pDig0->GetTime()+((1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2884 // dTcor[iSel]+(1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2885 dTcor[iSel]);
2886 fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->Fill(
2887 pDig1->GetTot(),
2888 //(pDig1->GetTime()+((1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2889 //dTcor[iSel]+(1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2890 dTcor[iSel]);
2891
2892 fhTRpcCluWalk2[iDetIndx][iSel]->Fill(pDigS0->GetTot(), pDigS1->GetTot(), dTcor[iSel]);
2893 fhTRpcCluQ2DT[iDetIndx][iSel]->Fill(pDigS0->GetTot(), pDigS1->GetTot(),
2894 pDigS0->GetTime() - pDigS1->GetTime());
2895
2896 fhTRpcCluAvWalk[iDetIndx][iSel]->Fill(
2897 pDig0->GetTot(),
2898 //(pDig0->GetTime()+((1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2899 //dTcor[iSel]+(1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2900 dTcor[iSel]);
2901 fhTRpcCluAvWalk[iDetIndx][iSel]->Fill(
2902 pDig1->GetTot(),
2903 //(pDig1->GetTime()+((1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
2904 //dTcor[iSel]+(1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
2905 dTcor[iSel]);
2906
2907 if (iLink == 0) { // Fill histo only once (for 1. digi entry)
2908 //fhTRpcCluDelTof[iDetIndx][iSel]->Fill(dTRef-dTTrig[iSel],dTcor[iSel]/dDist);
2909 fhTRpcCluDelTof[iDetIndx][iSel]->Fill(dTRef - dTTrig[iSel], dTcor[iSel]);
2910 fhTSmCluTOff[iSmType][iSel]->Fill((Double_t)(iSm * iNbRpc + iRpc), dTcor[iSel]);
2911 fhTSmCluTRun[iSmType][iSel]->Fill(fdEvent, dTcor[iSel]);
2912 if (iDetId
2913 != (pTrig[iSel]->GetAddress()
2914 & DetMask)) { // transform matched hit-pair back into detector frame
2915 hitpos[0] = pHit->GetX() - dzscal * pTrig[iSel]->GetX() + fChannelInfo->GetX();
2916 hitpos[1] = pHit->GetY() - dzscal * pTrig[iSel]->GetY() + fChannelInfo->GetY();
2917 hitpos[2] = pHit->GetZ();
2918 gGeoManager->MasterToLocal(hitpos,
2919 hitpos_local); // transform into local frame
2920 fhRpcCluDelMatPos[iDetIndx]->Fill((Double_t) iCh, hitpos_local[1]);
2921 fhRpcCluDelMatTOff[iDetIndx]->Fill((Double_t) iCh,
2922 (pHit->GetTime() - dTTrig[iSel]) - dTTcor[iSel]);
2923 }
2924 } // iLink==0 condition end
2925 } // position condition end
2926 } // Match condition end
2927 } // closing of selector loop
2928 } // digi index range check condition end
2929 else {
2930 LOG(error) << "CbmTofEventClusterizer::FillHistos: invalid digi index " << iDetIndx << " digi0,1" << iDigInd0
2931 << ", " << iDigInd1
2932 << " - max:"
2933 // << fTofCalDigisColl->GetEntriesFast()
2934 << fTofCalDigiVec->size()
2935 // << " in event " << XXX
2936 ;
2937 }
2938 } // iLink digi loop end;
2939
2940 if (1 < dNstrips) {
2941 // Double_t dVar=dMeanTimeSquared/dNstrips - TMath::Power(pHit->GetTime(),2);
2942 Double_t dVar = dMeanTimeSquared / (dNstrips - 1);
2943 //if(dVar<0.) dVar=0.;
2944 Double_t dTrms = TMath::Sqrt(dVar);
2945 LOG(debug) << Form(" Trms for Tofhit %d in iDetIndx %d, Ch %d from "
2946 "%3.0f strips: %6.3f ns",
2947 iHitInd, iDetIndx, iCh, dNstrips, dTrms);
2948 fhRpcCluTrms[iDetIndx]->Fill((Double_t) iCh, dTrms);
2949 pHit->SetTimeError(dTrms);
2950 }
2951
2952 LOG(debug1) << " Fill Time of iDetIndx " << iDetIndx << ", hitAddr "
2953 << Form(" %08x, y = %5.2f", pHit->GetAddress(), hitpos_local[1]) << " for |y| <"
2954 << fhRpcCluPosition[iDetIndx]->GetYaxis()->GetXmax()
2955 << Form(", TRef %8.3f, BSel %d %d", dTRef, (Int_t) BSel[0], (Int_t) BSel[1]);
2956
2957 if (TMath::Abs(hitpos_local[1]) < (fhRpcCluPosition[iDetIndx]->GetYaxis()->GetXmax())) {
2958 if (dTRef != 0. && fTRefHits == 1) {
2959 fhRpcCluTOff[iDetIndx]->Fill((Double_t) iCh, pHit->GetTime() - dTRef);
2960 fhSmCluTOff[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), pHit->GetTime() - dTRef);
2961
2962 for (Int_t iSel = 0; iSel < iNSel; iSel++)
2963 if (BSel[iSel]) {
2964 LOG(debug1) << " TRpcCluTOff " << iDetIndx << ", Sel " << iSel
2965 << Form(", Dt %7.3f, LHsize %lu ", pHit->GetTime() - dTTrig[iSel],
2966 fvLastHits[iSmType][iSm][iRpc][iCh].size());
2967 if (pHit->GetAddress() == pTrig[iSel]->GetAddress()) continue;
2968
2969 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
2970 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
2971 itL--;
2972 for (size_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
2973 itL--;
2974 LOG(debug1) << Form(" %f,", pHit->GetTime() - (*itL)->GetTime());
2975 }
2976 }
2977 // fill Time Offset histograms without velocity spread (DelTof) correction
2978 if (pBeamRef != NULL)
2979 if (TMath::Abs(pBeamRef->GetTime() - pTrig[iSel]->GetTime()) < fdDelTofMax) {
2980 // if(TMath::Abs(pBeamRef->GetTime()-pTrig[iSel]->GetTime()) < fhTRpcCluTOff[iIndexDut][iSel]->GetYaxis()->GetXmax()) {
2981 /*
2982 if( iSmType==fiBeamRefType ||
2983 TMath::Sqrt(TMath::Power(pHit->GetX()-dzscal*pTrig[iSel]->GetX(),2.)
2984 +TMath::Power(pHit->GetY()-dzscal*pTrig[iSel]->GetY(),2.))<fdCaldXdYMax
2985 * fhTRpcCluTOff[iIndexDut][iSel]->GetYaxis()->GetXmax())
2986 */
2987 if (digiMatch->GetNofLinks() > 0) {
2988 fhTRpcCluTOff[iDetIndx][iSel]->Fill((Double_t) iCh,
2989 pHit->GetTime()
2990 - dTTrig[iSel]); // -dTTcor[iSel] only valid for matches
2991 fhTRpcCluTofOff[iDetIndx][iSel]->Fill((Double_t) iCh,
2992 pHit->GetTime()
2993 - dTTrig[iSel]); // valid for beam experiments
2994 // pHit->GetTime()-pBeamRef->GetTime()); // shift cluster time to beamcounter time
2995 // pHit->GetTime()-pBeamRef->GetTime()-fdToDAv*pTrig[iSel]->GetR());// valid for beam experiments
2996 }
2997 }
2998 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
2999 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
3000 itL--;
3001 for (Int_t iH = 0; iH < 1; iH++) { // use only last hit
3002 // for(Int_t iH=0; iH<fvLastHits[iSmType][iSm][iRpc][iCh].size()-1; iH++){//fill for all memorized hits
3003 itL--;
3004 Double_t dTsinceLast = pHit->GetTime() - (*itL)->GetTime();
3005 if (dTsinceLast > fdMemoryTime)
3006 LOG(fatal) << Form("Invalid Time since last hit on channel "
3007 "TSRC %d%d%d%d: %f > %f",
3008 iSmType, iSm, iRpc, iCh, dTsinceLast, fdMemoryTime);
3009
3010 fhTRpcCluTOffDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(dTsinceLast),
3011 pHit->GetTime() - dTTrig[iSel]);
3012 fhTRpcCluMemMulDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(dTsinceLast),
3013 fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1);
3014 }
3015 }
3016 }
3017 }
3018 }
3019 } // iHitInd hit loop end
3020
3021 if (false)
3022 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
3023 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
3024 LOG(debug1) << "CbmTofEventClusterizer::FillHistos: "
3025 << Form(" %3d %3d %3lu ", iSmType, iRpc, fviClusterSize[iSmType][iRpc].size());
3026
3027 for (UInt_t uCluster = 0; uCluster < fviClusterSize[iSmType][iRpc].size(); uCluster++) {
3028 LOG(debug2) << "CbmTofEventClusterizer::FillHistos: " << Form(" %3d %3d %3d ", iSmType, iRpc, uCluster);
3029
3030 fhClusterSize->Fill(fviClusterSize[iSmType][iRpc][uCluster]);
3031 fhClusterSizeType->Fill(fviClusterSize[iSmType][iRpc][uCluster],
3032 40 * iSmType + iRpc); //FIXME - hardwired constant
3033 if (kFALSE) // kTRUE == fDigiBdfPar->ClustUseTrackId() )
3034 {
3035 fhTrackMul->Fill(fviTrkMul[iSmType][iRpc][uCluster]);
3036 fhClusterSizeMulti->Fill(fviClusterSize[iSmType][iRpc][uCluster], fviTrkMul[iSmType][iRpc][uCluster]);
3037 if (1 == fviTrkMul[iSmType][iRpc][uCluster])
3038 fhTrk1MulPos->Fill(fvdX[iSmType][iRpc][uCluster], fvdY[iSmType][iRpc][uCluster]);
3039 if (1 < fviTrkMul[iSmType][iRpc][uCluster])
3040 fhHiTrkMulPos->Fill(fvdX[iSmType][iRpc][uCluster], fvdY[iSmType][iRpc][uCluster]);
3041 fhAllTrkMulPos->Fill(fvdX[iSmType][iRpc][uCluster], fvdY[iSmType][iRpc][uCluster]);
3042 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
3043 if (kFALSE) // 1 == fviTrkMul[iSmType][iRpc][uCluster] )
3044 {
3045 fhClustSizeDifX->Fill(fviClusterSize[iSmType][iRpc][uCluster], fvdDifX[iSmType][iRpc][uCluster]);
3046 fhClustSizeDifY->Fill(fviClusterSize[iSmType][iRpc][uCluster], fvdDifY[iSmType][iRpc][uCluster]);
3047 if (1 == fviClusterSize[iSmType][iRpc][uCluster]) {
3048 fhChDifDifX->Fill(fvdDifCh[iSmType][iRpc][uCluster], fvdDifX[iSmType][iRpc][uCluster]);
3049 fhChDifDifY->Fill(fvdDifCh[iSmType][iRpc][uCluster], fvdDifY[iSmType][iRpc][uCluster]);
3050 }
3051 }
3052 } // for( UInt_t uCluster = 0; uCluster < fviClusterSize[iSmType][iRpc].size(); uCluster++ )
3053 fviClusterSize[iSmType][iRpc].clear();
3054 fviTrkMul[iSmType][iRpc].clear();
3055 fvdX[iSmType][iRpc].clear();
3056 fvdY[iSmType][iRpc].clear();
3057 fvdDifX[iSmType][iRpc].clear();
3058 fvdDifY[iSmType][iRpc].clear();
3059 fvdDifCh[iSmType][iRpc].clear();
3060 } // for( Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc( iSmType); iRpc++ )
3061 }
3063 } // if(0<iNbTofHits) end
3064
3065 return kTRUE;
3066}
3067
3069{
3070 if (fDutId < 0) return kTRUE;
3072 TFile* oldFile = gFile;
3073 TDirectory* oldDir = gDirectory;
3074 TFile* fHist;
3075 fHist = new TFile(fOutHstFileName, "RECREATE");
3076 fHist->cd();
3077 Double_t dTBeamRefMean = 0.; // weighted mean of all BeamRef counter channels
3078 //Double_t dTBeamRefWidth = 0;
3079 Double_t dTBeamRefW = 0.;
3080 LOG(info) << "WriteHistos with CalSel " << fCalSel << ", Mode " << fCalMode << ", TRefMode " << fTRefMode;
3081
3082 for (Int_t iFindT0 = 0; iFindT0 < 2; iFindT0++)
3083 for (Int_t iDetIndx = 0; iDetIndx < fDigiBdfPar->GetNbDet(); iDetIndx++) {
3084 if (NULL == fhRpcCluMul[iDetIndx]) continue;
3085
3086 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
3087
3088 if (iFindT0 == 0 && fiBeamRefAddr != (iUniqueId & SelMask)) continue;
3089
3090 Int_t iSmAddr = iUniqueId & SelMask;
3091 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
3092 Int_t iSm = CbmTofAddress::GetSmId(iUniqueId);
3093 Int_t iRpc = CbmTofAddress::GetRpcId(iUniqueId);
3095
3096 Int_t iNent = 0;
3097 if (fCalSel > -1) {
3098 if (NULL == fhTRpcCluAvWalk[iDetIndx][fCalSel]) continue;
3099 iNent = (Int_t) fhTRpcCluAvWalk[iDetIndx][fCalSel]->GetEntries();
3100 }
3101 else {
3102 if (NULL == fhRpcCluAvWalk[iDetIndx]) continue;
3103 iNent = (Int_t) fhRpcCluAvWalk[iDetIndx]->GetEntries();
3104 }
3105 if (0 == iNent) {
3106 LOG(debug) << "WriteHistos: No entries in Walk histos for "
3107 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc;
3108 // continue;
3109 }
3110
3111 // if(-1<fCalSmAddr && fcalType != iSmAddr) continue;
3112 TH2* htempPos = NULL;
3113 TProfile* htempPos_pfx = NULL;
3114 TH1* htempPos_py = NULL;
3115 TProfile* htempTOff_pfx = NULL;
3116 TH1* htempTOff_px = NULL;
3117 TProfile* hAvPos_pfx = NULL;
3118 TProfile* hAvTOff_pfx = NULL;
3119 TH2* htempTOff = NULL;
3120 TH2* htempTot = NULL;
3121 TProfile* htempTot_pfx = NULL;
3122 TH1* htempTot_Mean = NULL;
3123 TH1* htempTot_Off = NULL;
3124
3125 if (-1 < fCalSel) {
3126 htempPos = fhRpcCluPosition[iDetIndx]; // use untriggered distributions for position
3127 htempPos_pfx = fhRpcCluPosition[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluPosition[iDetIndx]->GetNbinsY());
3128 //htempPos = fhTRpcCluPosition[iDetIndx][fCalSel];
3129 //htempPos_pfx = fhTRpcCluPosition[iDetIndx][fCalSel]->ProfileX("_pfx",1,fhTRpcCluPosition[iDetIndx][fCalSel]->GetNbinsY());
3130 htempTOff = fhTRpcCluTOff[iDetIndx][fCalSel];
3131 if (fIdMode == 1) htempTOff = fhTRpcCluTofOff[iDetIndx][fCalSel]; //DEV! for init_calib_all
3132 htempTOff_pfx = htempTOff->ProfileX("_pfx", 1, fhTRpcCluTOff[iDetIndx][fCalSel]->GetNbinsY());
3133 htempTOff_px = htempTOff->ProjectionX("_px", 1, fhTRpcCluTOff[iDetIndx][fCalSel]->GetNbinsY());
3134 for (Int_t iCh = 0; iCh < htempTOff->GetNbinsX(); iCh++) { // use peak value to prevent out of update range
3135 TH1* htempTOff_py = htempTOff->ProjectionY("_py", iCh + 1, iCh + 1);
3136 Double_t Ymax = htempTOff_py->GetMaximum();
3137 if (Ymax > 0.) {
3138 Int_t iBmax = htempTOff_py->GetMaximumBin();
3139 Double_t dTOffmax = htempTOff_py->GetXaxis()->GetBinCenter(iBmax);
3140 if (TMath::Abs(dTOffmax) > 0.3 * htempTOff_py->GetXaxis()->GetXmax()) {
3141 LOG(debug) << "Use Maximum of TOff in ch " << iCh << " of histo " << htempTOff->GetName() << ": "
3142 << dTOffmax << ", " << htempTOff_py->GetXaxis()->GetXmax() << " instead of "
3143 << htempTOff_pfx->GetBinContent(iCh + 1);
3144 htempTOff_pfx->SetBinContent(iCh + 1, dTOffmax);
3145 htempTOff_pfx->SetBinEntries(iCh + 1, 1);
3146 }
3147 }
3148 }
3149 htempTot = fhTRpcCluTot[iDetIndx][fCalSel];
3150 htempTot_pfx =
3151 fhTRpcCluTot[iDetIndx][fCalSel]->ProfileX("_pfx", 1, fhTRpcCluTot[iDetIndx][fCalSel]->GetNbinsY());
3152 hAvPos_pfx =
3153 fhTSmCluPosition[iSmType][fCalSel]->ProfileX("_pfx", 1, fhTSmCluPosition[iSmType][fCalSel]->GetNbinsY());
3154 hAvTOff_pfx =
3155 fhTSmCluTOff[iSmType][fCalSel]->ProfileX("_pfx", 1, fhTSmCluTOff[iSmType][fCalSel]->GetNbinsY(), "s");
3156 }
3157 else // all triggers
3158 {
3159 htempPos = fhRpcCluPosition[iDetIndx];
3160 htempTot = fhRpcCluTot[iDetIndx];
3161 htempTot_pfx = fhRpcCluTot[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluTot[iDetIndx]->GetNbinsY());
3162 hAvPos_pfx = fhSmCluPosition[iSmType]->ProfileX("_pfx", 1, fhSmCluPosition[iSmType]->GetNbinsY());
3163 hAvTOff_pfx = fhSmCluTOff[iSmType]->ProfileX("_pfx", 1, fhSmCluTOff[iSmType]->GetNbinsY());
3164 switch (fCalSel) {
3165 case -1: // take corrections from untriggered distributions
3166 htempPos = fhRpcCluPosition[iDetIndx];
3167 htempPos_pfx = fhRpcCluPosition[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluPosition[iDetIndx]->GetNbinsY());
3168 htempTOff = fhRpcCluTOff[iDetIndx];
3169 htempTOff_pfx = fhRpcCluTOff[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluTOff[iDetIndx]->GetNbinsY(), "s");
3170 htempTOff_px = fhRpcCluTOff[iDetIndx]->ProjectionX("_px", 1, fhRpcCluTOff[iDetIndx]->GetNbinsY());
3171 break;
3172
3173 case -2: //take corrections from Cluster deviations
3174 htempPos = fhRpcCluDelPos[iDetIndx];
3175 htempPos_pfx = fhRpcCluDelPos[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelPos[iDetIndx]->GetNbinsY());
3176 htempTOff = fhRpcCluDelTOff[iDetIndx];
3177 htempTOff_pfx = fhRpcCluDelTOff[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelTOff[iDetIndx]->GetNbinsY());
3178 htempTOff_px = fhRpcCluDelTOff[iDetIndx]->ProjectionX("_px", 1, fhRpcCluDelTOff[iDetIndx]->GetNbinsY());
3179 break;
3180
3181 case -3: // take corrections from deviations to matched trigger hit
3182 htempPos_pfx = fhRpcCluDelMatPos[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelMatPos[iDetIndx]->GetNbinsY());
3183 // htempTOff = fhRpcCluDelMatTOff[iDetIndx]; // -> Comment to remove warning because set but never used
3184 htempTOff_pfx =
3185 fhRpcCluDelMatTOff[iDetIndx]->ProfileX("_pfx", 1, fhRpcCluDelMatTOff[iDetIndx]->GetNbinsY());
3186 htempTOff_px =
3187 fhRpcCluDelMatTOff[iDetIndx]->ProjectionX("_px", 1, fhRpcCluDelMatTOff[iDetIndx]->GetNbinsY());
3188 break;
3189
3190 case -4: // shift all detectors without match requirement to beam counter times
3191 {
3192 Int_t iCalSel = 0;
3193 htempPos_pfx = fhTRpcCluPosition[iDetIndx][iCalSel]->ProfileX(
3194 "_pfx", 1, fhTRpcCluPosition[iDetIndx][iCalSel]->GetNbinsY());
3195 htempTOff_pfx = fhTRpcCluTOff[iDetIndx][iCalSel]->ProfileX(
3196 "_pfx", 1, fhTRpcCluTofOff[iDetIndx][iCalSel]->GetNbinsY(), "s");
3197 htempTOff_px = fhTRpcCluTofOff[iDetIndx][iCalSel]->ProjectionX(
3198 "_px", 1, fhTRpcCluTofOff[iDetIndx][iCalSel]->GetNbinsY());
3199 } break;
3200
3201 case -5: // shift all detectors without match requirement to beam counter times
3202 {
3203 Int_t iCalSel = 1;
3204 htempPos_pfx = fhTRpcCluPosition[iDetIndx][iCalSel]->ProfileX(
3205 "_pfx", 1, fhTRpcCluPosition[iDetIndx][iCalSel]->GetNbinsY());
3206 htempTOff_pfx = fhTRpcCluTOff[iDetIndx][iCalSel]->ProfileX(
3207 "_pfx", 1, fhTRpcCluTofOff[iDetIndx][iCalSel]->GetNbinsY(), "s");
3208 htempTOff_px = fhTRpcCluTofOff[iDetIndx][iCalSel]->ProjectionX(
3209 "_px", 1, fhTRpcCluTofOff[iDetIndx][iCalSel]->GetNbinsY());
3210 } break;
3211 }
3212 }
3213
3214 if (NULL == htempPos_pfx) {
3215 LOG(debug) << "WriteHistos: Projections not available, continue ";
3216 continue;
3217 }
3218
3219 htempTot_Mean = htempTot_pfx->ProjectionX("_Mean");
3220 htempTot_Off = htempTot_pfx->ProjectionX("_Off");
3221
3222 htempPos_pfx->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx", iSmType, iSm, iRpc));
3223 htempTOff_pfx->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx", iSmType, iSm, iRpc));
3224 htempTot_pfx->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_pfx", iSmType, iSm, iRpc));
3225 htempTot_Mean->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Mean", iSmType, iSm, iRpc));
3226 htempTot_Off->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Off", iSmType, iSm, iRpc));
3227 hAvPos_pfx->SetName(Form("cl_CorSmT%01d_Pos_pfx", iSmType));
3228 hAvTOff_pfx->SetName(Form("cl_CorSmT%01d_TOff_pfx", iSmType));
3229
3230
3231 if (iFindT0 == 0) { // action not yet done, determine mean of Ref
3232 if (fiBeamRefAddr == (iUniqueId & SelMask)) {
3233 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3234 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
3235 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
3236 Double_t dWCh = ((TH1*) htempTOff_px)->GetBinContent(iCh + 1);
3237 if (0 < dWCh) {
3238 Double_t dW = dTBeamRefW;
3239 dTBeamRefMean *= dW;
3240 //dTBeamRefWidth *= dW;
3241 dTBeamRefW += dWCh;
3242 if (dWCh > WalkNHmin) {
3243 TH1* hTy = (TH1*) htempTOff->ProjectionY(Form("%s_py%d", htempTOff->GetName(), iCh), iCh + 1, iCh + 1);
3244 Double_t dFMean = hTy->GetBinCenter(hTy->GetMaximumBin());
3245 Double_t dFLim = 1.; // CAUTION, fixed numeric value
3246 Double_t dBinSize = hTy->GetBinWidth(1);
3247 dFLim = TMath::Max(dFLim, 10. * dBinSize);
3248 //LOG(info) << "FitC " << hTy->GetName()
3249 // << Form(" TSRC %d%d%d%d with %8.2f %8.2f ", iSmType, iSm, iRpc, iCh, dFMean, dFLim);
3250 //TVirtualFitter* pFitter=TVirtualFitter::GetFitter();
3251 //if (NULL != pFitter) pFitter->Clear();
3252 TF1* mgaus = new TF1("mgaus", "gaus", dFMean - dFLim, dFMean + dFLim);
3253 mgaus->SetParameters(dWCh * 0.5, dFMean, dFLim * 0.5);
3254 TFitResultPtr fRes = hTy->Fit("mgaus", "SQM", "", dFMean - dFLim, dFMean + dFLim);
3255 //if(iSmType==9 && iSm==0 && iRpc==0 && iCh==10) // select specific channel
3256 if (!gMinuit->fCstatu.Contains("OK") && !gMinuit->fCstatu.Contains("CONVERGED")) {
3257 LOG(info) << "CalibC (ch ignored) " << gMinuit->fCstatu
3258 << Form(" TSRC %d%d%d%d gaus %8.2f %8.2f %8.2f ", iSmType, iSm, iRpc, iCh,
3259 fRes->Parameter(0), fRes->Parameter(1), fRes->Parameter(2));
3260 dTBeamRefW -= dWCh;
3261 dWCh = 0.;
3262 }
3263 else {
3264 if (fRes->Parameter(2) < 2.) {
3265 dTBeamRefMean += fRes->Parameter(1) * dWCh; // consider for mean
3266 //dTBeamRefWidth += fRes->Parameter(2) * dWCh; //calculate width
3267 }
3268 else {
3269 dTBeamRefMean += ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1) * dWCh;
3270 //dTBeamRefWidth += ((TProfile*) htempTOff_pfx)->GetBinError(iCh + 1) * dWCh;
3271 }
3272 }
3273 }
3274 else {
3275 dTBeamRefMean += ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1) * dWCh;
3276 //dTBeamRefWidth += ((TProfile*) htempTOff_pfx)->GetBinError(iCh + 1) * dWCh;
3277 }
3278 dTBeamRefMean += fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] * dWCh; // enforce <offset>=0
3279 if (dTBeamRefW > 0) {
3280 dTBeamRefMean /= dTBeamRefW;
3281 //dTBeamRefWidth /= dTBeamRefW;
3282 }
3283 } // dWCh > 0
3284 if (htempTOff_px->GetBinContent(iCh + 1) > 0.)
3285 //if(iSmType==9 && iSm==0 && iRpc==0 && iCh==10) // select specific channel
3286 LOG(info) << Form("CalibA %d,%2d,%2d: TSRC %d%d%d%d, hits %6.0f , "
3287 "TAV %8.3f, TBeamRefMean %8.3f ",
3288 fCalMode, fCalSel, fTRefMode, iSmType, iSm, iRpc, iCh,
3289 htempTOff_px->GetBinContent(iCh + 1),
3290 ((TProfile*) hAvTOff_pfx)->GetBinContent(iSm * iNbRpc + iRpc + 1), dTBeamRefMean);
3291 // TMean-=((TProfile *)hAvTOff_pfx)->GetBinContent(iSm*iNbRpc+iRpc+1);
3292 continue; // look for next beam counter channel
3293 }
3294 } // beam reference counter end
3295 break; // skip calibration for iFindT0==0
3296 }
3297
3298 assert(iFindT0 == 1);
3299
3300 switch (fCalMode % 10) {
3301 case 0: { // Initialize
3302 htempTot_Off->Reset(); // prepare TotOffset histo
3303 TH1* hbins[200];
3304 Int_t nbins = htempTot->GetNbinsX();
3305 for (int i = 0; i < nbins; i++) {
3306 hbins[i] = htempTot->ProjectionY(Form("bin%d", i + 1), i + 1, i + 1);
3307 /* Double_t Ymax=hbins[i]->GetMaximum();*/
3308 Int_t iBmax = hbins[i]->GetMaximumBin();
3309 TAxis* xaxis = hbins[i]->GetXaxis();
3310 Double_t Xmax = xaxis->GetBinCenter(iBmax);
3311 Double_t XOff = Xmax - fTotPreRange;
3312 XOff = (Double_t)(Int_t) XOff;
3313 if (XOff < 0) XOff = 0;
3314 htempTot_Off->SetBinContent(i + 1, XOff);
3315 Double_t Xmean = htempTot_Mean->GetBinContent(i + 1);
3316 if (Xmean < XOff) {
3317 LOG(warning) << "Inconsistent Tot numbers for "
3318 << Form("SmT%01d_sm%03d_rpc%03d bin%d: mean %f, Off %f", iSmType, iSm, iRpc, i, Xmean, XOff);
3319 }
3320 htempTot_Mean->SetBinContent(i + 1, (Xmean - XOff));
3321 if (htempTot_Mean->GetBinContent(i + 1) != (Xmean - XOff))
3322 LOG(warning) << "Tot numbers not stored properly for "
3323 << Form("SmT%01d_sm%03d_rpc%03d bin%d: mean %f, target %f", iSmType, iSm, iRpc, i,
3324 htempTot_Mean->GetBinContent(i + 1), Xmean - XOff);
3325 }
3326 htempPos_pfx->Write();
3327 htempTOff_pfx->Write();
3328 // htempTot_pfx->Write();
3329 htempTot_Mean->Write();
3330 htempTot_Off->Write();
3331 } break;
3332
3333 case 1: //save offsets, update walks
3334 {
3335 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3336 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
3337 LOG(debug) << "WriteHistos: restore Offsets and Gains and save Walk for "
3338 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc
3339 << " and calSmAddr = " << Form(" 0x%08x ", TMath::Abs(fCalSmAddr));
3340 htempPos_pfx->Reset(); //reset to restore means of original histos
3341 htempTOff_pfx->Reset();
3342 htempTot_Mean->Reset();
3343 htempTot_Off->Reset();
3344 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
3345 Double_t YMean =
3346 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
3347 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3348 Double_t TMean =
3349 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3350 htempPos_pfx->Fill(iCh, YMean);
3351 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
3352 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got "
3353 << htempPos_pfx->GetBinContent(iCh) << "," << htempPos_pfx->GetBinContent(iCh + 1) << ","
3354 << htempPos_pfx->GetBinContent(iCh + 2) << ", expected " << YMean;
3355 }
3356 htempTOff_pfx->Fill(iCh, TMean);
3357
3358 for (Int_t iSide = 0; iSide < 2; iSide++) {
3359 htempTot_Mean->SetBinContent(
3360 iCh * 2 + 1 + iSide,
3361 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]); //nh +1 empirical(?)
3362 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3363 }
3364 }
3365
3366 LOG(debug1) << " Offset, gain restoring done ... ";
3367 htempPos_pfx->Write();
3368 htempTOff_pfx->Write();
3369 // htempTot_pfx->Write();
3370 htempTot_Mean->Write();
3371 htempTot_Off->Write();
3372
3373 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3374 // Store DelTof corrections
3375 TDirectory* curdir = gDirectory;
3376 gROOT->cd(); //
3377 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
3378 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3379 gDirectory->cd(curdir->GetPath());
3380 if (NULL != hCorDelTof) {
3381 TH1D* hCorDelTofout = (TH1D*) hCorDelTof->Clone(
3382 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3383 hCorDelTofout->Write();
3384 }
3385 else {
3386 LOG(debug) << " No CorDelTof histo "
3387 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
3388 }
3389 }
3390
3391 if ((fCalSmAddr < 0 && TMath::Abs(fCalSmAddr) != iSmAddr)
3392 || fCalSmAddr == iSmAddr) // select detectors for determination of walk correction
3393 {
3394
3395 LOG(debug) << "WriteHistos: restore Offsets and Gains and update Walk for "
3396 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc << " with "
3397 << fDigiBdfPar->GetNbChan(iSmType, iRpc) << " channels";
3398 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++) {
3399 TH2* h2tmp0;
3400 TH2* h2tmp1;
3401 if (!fEnableAvWalk) {
3402 if (-1 < fCalSel) {
3403 h2tmp0 = fhTRpcCluWalk[iDetIndx][fCalSel][iCh][0];
3404 h2tmp1 = fhTRpcCluWalk[iDetIndx][fCalSel][iCh][1];
3405 }
3406 else { // take correction from deviation within clusters
3407 h2tmp0 = fhRpcCluWalk[iDetIndx][iCh][0];
3408 h2tmp1 = fhRpcCluWalk[iDetIndx][iCh][1];
3409 }
3410 }
3411 else { // go for averages (low statistics)
3412 if (-1 < fCalSel) {
3413 h2tmp0 = fhTRpcCluAvWalk[iDetIndx][fCalSel];
3414 h2tmp1 = fhTRpcCluAvWalk[iDetIndx][fCalSel];
3415 }
3416 else { // take correction from deviation within clusters
3417 h2tmp0 = fhRpcCluAvWalk[iDetIndx];
3418 h2tmp1 = fhRpcCluAvWalk[iDetIndx];
3419 }
3420 }
3421 if (NULL == h2tmp0) {
3422 LOG(debug) << Form("WriteHistos: Walk histo not available for "
3423 "SmT %d, Sm %d, Rpc %d, Ch %d",
3424 iSmType, iSm, iRpc, iCh);
3425 continue;
3426 }
3427 Int_t iNEntries = h2tmp0->GetEntries();
3428 if (iCh == 0) // condition to print message only once
3429 LOG(debug) << Form(" Update Walk correction for SmT %d, Sm %d, "
3430 "Rpc %d, Ch %d, Sel%d: Entries %d",
3431 iSmType, iSm, iRpc, iCh, fCalSel, iNEntries);
3432
3433 // h2tmp0->Write();
3434 // h2tmp1->Write();
3435 if (-1 < iNEntries) { // always done
3436 TProfile* htmp0 = h2tmp0->ProfileX("_pfx", 1, h2tmp0->GetNbinsY());
3437 TProfile* htmp1 = h2tmp1->ProfileX("_pfx", 1, h2tmp1->GetNbinsY());
3438 TH1D* h1tmp0 = h2tmp0->ProjectionX("_px", 1, h2tmp0->GetNbinsY());
3439 TH1D* h1tmp1 = h2tmp1->ProjectionX("_px", 1, h2tmp1->GetNbinsY());
3440 TH1D* h1ytmp0 = h2tmp0->ProjectionY("_py", 1,
3441 nbClWalkBinX); // preserve means
3442 TH1D* h1ytmp1 = h2tmp1->ProjectionY("_py", 1, nbClWalkBinX);
3443 Double_t dWMean0 = h1ytmp0->GetMean();
3444 Double_t dWMean1 = h1ytmp1->GetMean();
3445 Double_t dWMean = 0.5 * (dWMean0 + dWMean1);
3446 Int_t iWalkUpd = 2; // Walk update mode flag
3447 //if(5==iSmType || 8==iSmType || 2==iSmType) iWalkUpd=0; // keep both sides consistent for diamonds and pads
3448 if (5 == iSmType || 8 == iSmType)
3449 iWalkUpd = 0; // keep both sides consistent for diamonds and pads (Cern2016)
3450 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
3451 switch (iWalkUpd) {
3452 case 0:
3453 if (h1tmp0->GetBinContent(iWx + 1) > WalkNHmin && h1tmp1->GetBinContent(iWx + 1) > WalkNHmin) {
3454 // preserve y - position (difference) on average
3455 Double_t dWcor =
3456 (((TProfile*) htmp0)->GetBinContent(iWx + 1) + ((TProfile*) htmp1)->GetBinContent(iWx + 1))
3457 * 0.5;
3458 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] += dWcor - dWMean;
3459 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx] += dWcor - dWMean;
3460 LOG(debug) << Form("Walk for TSR %d%d%d%d Tot %d set to %f", iSmType, iSm, iRpc, iCh, iWx,
3461 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3462 }
3463 break;
3464 case 1:
3465 if (h1tmp0->GetBinContent(iWx + 1) > WalkNHmin && h1tmp1->GetBinContent(iWx + 1) > WalkNHmin) {
3466 Double_t dWcor0 = ((TProfile*) htmp0)->GetBinContent(iWx + 1) - dWMean0;
3467 Double_t dWcor1 = ((TProfile*) htmp1)->GetBinContent(iWx + 1) - dWMean1;
3468 Double_t dWcor = 0.5 * (dWcor0 + dWcor1);
3469 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] += dWcor; //-dWMean0;
3470 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx] += dWcor; //-dWMean1;
3471
3472 if (iCh == 0 && iSmType == 9 && iSm == 0 && h1tmp0->GetBinContent(iWx + 1) > WalkNHmin)
3473 LOG(debug) << "Update Walk Sm = " << iSm << "(" << iNbRpc << "), Rpc " << iRpc << ", Bin "
3474 << iWx << ", " << h1tmp0->GetBinContent(iWx + 1)
3475 << " cts: " << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] << " + "
3476 << ((TProfile*) htmp0)->GetBinContent(iWx + 1) << " - " << dWMean0 << " -> "
3477 << dWcor - dWMean0
3478 << ", S1: " << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx] << " + "
3479 << ((TProfile*) htmp1)->GetBinContent(iWx + 1) << " - " << dWMean1 << " -> "
3480 << dWcor - dWMean1;
3481 }
3482 break;
3483 case 2:
3484 if (h1tmp0->GetBinContent(iWx + 1) > WalkNHmin && h1tmp1->GetBinContent(iWx + 1) > WalkNHmin) {
3485 Double_t dWcor0 = ((TProfile*) htmp0)->GetBinContent(iWx + 1) - dWMean0;
3486 Double_t dWcor1 = ((TProfile*) htmp1)->GetBinContent(iWx + 1) - dWMean1;
3487 //Double_t dWcor = 0.5*(dWcor0 + dWcor1);
3488 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx] += dWcor0;
3489 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx] += dWcor1;
3490 }
3491 break;
3492
3493 default:;
3494 }
3495 }
3496 h1tmp0->Reset();
3497 h1tmp1->Reset();
3498 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
3499 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3500 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
3501 Int_t iTry = 3;
3502 while (iTry-- > 0
3503 && h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
3504 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3505 }
3506 if (iTry == 0)
3507 LOG(error) << "writing not successful for " << h1tmp0->GetName() << ", attempts left: " << iTry
3508 << ", iWx " << iWx << ", got " << h1tmp0->GetBinContent(iWx + 1) << ", expected "
3509 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
3510 iTry = 3;
3511 while (iTry-- > 0
3512 && h1tmp1->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]) {
3513 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
3514 }
3515 if (iTry == 0)
3516 LOG(error) << "writing not successful for " << h1tmp1->GetName() << ", attempts left: " << iTry
3517 << ", iWx " << iWx << ", got " << h1tmp1->GetBinContent(iWx + 1) << ", expected "
3518 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx];
3519 }
3520
3521 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
3522 h1tmp0->Smooth(iNWalkSmooth);
3523 h1tmp0->Write();
3524 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
3525 h1tmp1->Smooth(iNWalkSmooth);
3526 h1tmp1->Write();
3527 }
3528 }
3529 }
3530 else { // preserve whatever is there for fCalSmAddr !
3531 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++) // restore old values
3532 {
3533 // TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3534 // TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3535 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
3536 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
3537 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
3538 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3539 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
3540 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
3541 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
3542 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
3543 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
3544 }
3545 }
3546 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
3547 // htmp0->Write();
3548 h1tmp0->Write();
3549 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
3550 // htmp1->Write();
3551 h1tmp1->Write();
3552 }
3553 }
3554 } break;
3555
3556 case 2: //update time offsets from positions and times with Sm averages, save walks and DELTOF
3557 {
3558 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3559 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
3560
3561 if ((fCalSmAddr < 0) || (fCalSmAddr != iSmAddr)) { // select detectors for updating offsets
3562 LOG(debug) << "WriteHistos: (case 2) update Offsets and keep Gains, "
3563 "Walk and DELTOF for "
3564 << Form(" 0x%08x ", TMath::Abs(fCalSmAddr)) << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc "
3565 << iRpc;
3566 Int_t iB = iSm * iNbRpc + iRpc;
3567 Double_t dVscal = 1.;
3568 if (0) //NULL != fhSmCluSvel[iSmType])
3569 dVscal = fhSmCluSvel[iSmType]->GetBinContent(iSm * iNbRpc + iRpc + 1);
3570 if (dVscal == 0.) dVscal = 1.;
3571
3572 Double_t YMean = ((TProfile*) hAvPos_pfx)->GetBinContent(iB + 1); //nh +1 empirical(?)
3573 htempPos_py = htempPos->ProjectionY(Form("%s_py", htempPos->GetName()), 1, iNbCh);
3574 if (htempPos_py->GetEntries() > fdYFitMin && fPosYMaxScal < 1.1) {
3575 LOG(debug1) << Form("Determine YMean in %s by fit to %d entries", htempPos->GetName(),
3576 (Int_t) htempPos_py->GetEntries());
3577 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, 0);
3578 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
3579 fChannelInfo = fDigiPar->GetCell(iChId);
3580 if (NULL == fChannelInfo) {
3581 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
3582 continue;
3583 }
3584 fit_ybox(htempPos_py, fChannelInfo->GetSizey());
3585 TF1* ff = htempPos_py->GetFunction("YBox");
3586 if (NULL != ff) {
3587 LOG(info) << "FRes YBox " << htempPos_py->GetEntries() << " entries in TSR " << iSmType << iSm << iRpc
3588 << ", chi2 " << ff->GetChisquare() / ff->GetNDF()
3589 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos "
3590 "res %5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
3591 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1), 2. * ff->GetParError(1),
3592 ff->GetParameter(2), ff->GetParError(2), ff->GetParameter(3), ff->GetParError(3));
3593
3594 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey() < 0.2
3595 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.2) {
3596 if (TMath::Abs(ff->GetParameter(3) - YMean) < 0.5 * fChannelInfo->GetSizey()) {
3597 YMean = ff->GetParameter(3);
3598 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
3599 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV);
3600 }
3601 }
3602 }
3603 }
3604
3605 TH1* hAvTOff_py = fhSmCluTOff[iSmType]->ProjectionY("_py", iB + 1, iB + 1);
3606 Double_t Ymax = hAvTOff_py->GetMaximum();
3607 Double_t dTOffmax = 0.;
3608 if (Ymax > 0.) {
3609 Int_t iBmax = hAvTOff_py->GetMaximumBin();
3610 dTOffmax = hAvTOff_py->GetXaxis()->GetBinCenter(iBmax);
3611 }
3612 Double_t TMean = ((TProfile*) hAvTOff_pfx)->GetBinContent(iB + 1);
3613 if (TMath::Abs(dTOffmax - TMean) > 2. * TMean) {
3614 TMean = dTOffmax;
3615 LOG(debug) << "Use peak position for TOff of TSR " << iSmType << iSm << iRpc << ", B= " << iB << ": "
3616 << TMean;
3617 }
3618 Double_t TWidth = ((TProfile*) hAvTOff_pfx)->GetBinError(iB + 1);
3619 Double_t dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
3620
3621 if (fiBeamRefAddr == (iUniqueId & SelMask)) TMean = 0.; // don't shift reference counter
3622 LOG(debug) << Form("<ICor> Correct TSR %d%d%d by TMean=%8.2f, "
3623 "TYOff=%8.2f, TWidth=%8.2f, ",
3624 iSmType, iSm, iRpc, TMean, dTYOff, TWidth);
3625
3626 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // update Offset and Gain
3627 {
3628 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
3629 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
3630
3631 LOG(debug) << "FillCalHist:"
3632 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh << ": YMean "
3633 << YMean << ", TMean " << TMean << " -> "
3634 << Form(" %f, %f, %f, %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
3635 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
3636 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
3637 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
3638 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
3639 }
3640 htempPos_pfx->Reset(); //reset to store new values
3641 htempTOff_pfx->Reset();
3642 htempTot_Mean->Reset();
3643 htempTot_Off->Reset();
3644 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
3645 {
3646 Double_t YMean =
3647 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
3648 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3649 Double_t TMean =
3650 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
3651 htempPos_pfx->Fill(iCh, YMean);
3652 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
3653 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got "
3654 << htempPos_pfx->GetBinContent(iCh) << "," << htempPos_pfx->GetBinContent(iCh + 1) << ","
3655 << htempPos_pfx->GetBinContent(iCh + 2) << ", expected " << YMean;
3656 }
3657 htempTOff_pfx->Fill(iCh, TMean);
3658
3659 for (Int_t iSide = 0; iSide < 2; iSide++) {
3660 htempTot_Mean->SetBinContent(
3661 iCh * 2 + 1 + iSide,
3662 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]); //nh +1 empirical(?)
3663 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3664 }
3665 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
3666
3667 LOG(debug1) << " Updating done ... write to file ";
3668 htempPos_pfx->Write();
3669 htempTOff_pfx->Write();
3670 // htempTot_pfx->Write();
3671 htempTot_Mean->Write();
3672 htempTot_Off->Write();
3673
3674 // store old DELTOF histos
3675 LOG(debug) << " Copy old DelTof histos from " << gDirectory->GetName() << " to file ";
3676
3677 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3678 // Store DelTof corrections
3679 TDirectory* curdir = gDirectory;
3680 gROOT->cd(); //
3681 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
3682 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3683 gDirectory->cd(curdir->GetPath());
3684 if (NULL != hCorDelTof) {
3685 TH1D* hCorDelTofout = (TH1D*) hCorDelTof->Clone(
3686 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
3687 hCorDelTofout->Write();
3688 }
3689 else {
3690 LOG(debug) << " No CorDelTof histo "
3691 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
3692 }
3693 }
3694
3695 // store walk histos
3696 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
3697 {
3698 // TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3699 // TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
3700 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
3701 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
3702 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
3703 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
3704 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
3705 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
3706 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
3707 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
3708 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
3709 }
3710 }
3711 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
3712 // htmp0->Write();
3713 h1tmp0->Write();
3714 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
3715 // htmp1->Write();
3716 h1tmp1->Write();
3717 }
3718 } break;
3719
3720 case 3: //update offsets, gains, save walks and DELTOF
3721 {
3722 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3723 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
3724 if ((fCalSmAddr < 0) || (fCalSmAddr != iSmAddr)) { // select detectors for updating offsets
3725 LOG(info) << "Write (calMode==3): update Offsets and Gains, keep Walk and DelTof for "
3726 << Form("Addr 0x%08x ", TMath::Abs(fCalSmAddr)) << "TSR " << iSmType << iSm << iRpc << " with "
3727 << iNbCh << " channels "
3728 << ", using selector " << fCalSel << ", " << iFindT0 << " and TRefMode " << fTRefMode << ", TRef "
3729 << dTBeamRefMean;
3730
3731 Double_t dVscal = 1.;
3732 Double_t dVW = 1.;
3733 if (0) // NULL != fhSmCluSvel[iSmType])
3734 {
3735 dVscal = fhSmCluSvel[iSmType]->GetBinContent(iSm * iNbRpc + iRpc + 1);
3736 if (dVscal == 0.) dVscal = 1.;
3737 dVW = fhSmCluSvel[iSmType]->GetBinEffectiveEntries(iSm * iNbRpc + iRpc + 1);
3738 dVW *= 50.; //(Double_t)iNbCh;
3739 if (dVW < 0.1) dVW = 0.1;
3740 }
3741
3742 Double_t dYMeanAv = 0.;
3743 Double_t dYMeanFit = 0.;
3744 Double_t dYLenFit = 0.;
3745 Double_t YMean = 0.;
3746 Double_t dYShift = 0;
3747
3748 if (fCalMode / 10 >= 5 && fCalSel > -1) {
3749 // determine average values
3750 htempPos_py = htempPos->ProjectionY(Form("%s_py", htempPos->GetName()), 1, iNbCh);
3751
3752 if (htempPos_py->GetEntries() > fdYFitMin && fPosYMaxScal < 1.1 && iSmType != 5 && iSmType != 8) {
3753 dYMeanAv = htempPos_py->GetMean();
3754 LOG(debug1) << Form("Determine YMeanAv in %s by fit to %d entries", htempPos->GetName(),
3755 (Int_t) htempPos_py->GetEntries());
3756 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, 0);
3757 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
3758 fChannelInfo = fDigiPar->GetCell(iChId);
3759 if (NULL == fChannelInfo) {
3760 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
3761 continue;
3762 }
3763 fit_ybox(htempPos_py, fChannelInfo->GetSizey());
3764 TF1* ff = htempPos_py->GetFunction("YBox");
3765 if (gMinuit->fCstatu.Contains("OK") || gMinuit->fCstatu.Contains("CONVERGED")) {
3766 //if (NULL != ff) {
3767 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey() < 0.2
3768 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.2) {
3769 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
3770 LOG(info) << "FAvRes YBox " << htempPos_py->GetEntries() << " entries in TSR " << iSmType << iSm
3771 << iRpc << ", stat: " << gMinuit->fCstatu
3772 << Form(", chi2 %6.2f, striplen (%5.2f): "
3773 "%7.2f+/-%5.2f, pos res "
3774 "%5.2f+/-%5.2f at y_cen = %5.2f+/-%5.2f",
3775 ff->GetChisquare() / ff->GetNDF(), fChannelInfo->GetSizey(),
3776 2. * ff->GetParameter(1), 2. * ff->GetParError(1), ff->GetParameter(2),
3777 ff->GetParError(2), ff->GetParameter(3), ff->GetParError(3));
3778 if (TMath::Abs(ff->GetParameter(3) - dYMeanAv) < 0.5 * fChannelInfo->GetSizey()) {
3779 dYMeanFit = ff->GetParameter(3);
3780 dYLenFit = 2. * ff->GetParameter(1);
3781 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV, dVW);
3782 for (Int_t iPar = 0; iPar < 4; iPar++)
3783 fhSmCluFpar[iSmType][iPar]->Fill((Double_t)(iSm * iNbRpc + iRpc), ff->GetParameter(2 + iPar));
3784 }
3785 }
3786 else {
3787 LOG(info) << "FAvBad YBox " << htempPos_py->GetEntries() << " entries in " << iSmType << iSm << iRpc
3788 << ", chi2 " << ff->GetChisquare()
3789 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos res "
3790 "%5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
3791 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1),
3792 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2),
3793 ff->GetParameter(3), ff->GetParError(3));
3794 }
3795 }
3796 else {
3797 LOG(info) << "FAvFailed for TSR " << iSmType << iSm << iRpc << " with " << gMinuit->fCstatu;
3798 }
3799 }
3800 dYShift = dYMeanFit - dYMeanAv;
3801 LOG(debug) << Form("CalibY for TSR %d%d%d: DY %5.2f, Fit %5.2f, Av %5.2f ", iSmType, iSm, iRpc, dYShift,
3802 dYMeanFit, dYMeanAv);
3803 } // fCalMode/10 > 5 end
3804
3805 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // update Offset and Gain
3806 {
3807 Double_t dTYOff = 0;
3808 if (fCalSel >= 0) {
3809 YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1); //set default
3810 YMean += dYShift;
3811
3812 if (fPosYMaxScal < 1.1 && iSmType != 5 && iSmType != 8) { //disable by adding "-" sign
3813 htempPos_py = htempPos->ProjectionY(Form("%s_py%02d", htempPos->GetName(), iCh), iCh + 1, iCh + 1);
3814 if (htempPos_py->GetEntries() > fdYFitMin) {
3815 LOG(debug1) << Form("Determine YMean in %s of channel %d by "
3816 "length fit with %6.3f to %d entries",
3817 htempPos->GetName(), iCh, dYLenFit, (Int_t) htempPos_py->GetEntries());
3818 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
3819 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
3820 fChannelInfo = fDigiPar->GetCell(iChId);
3821 if (NULL == fChannelInfo) {
3822 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
3823 continue;
3824 }
3825 Double_t fp[4] = {1., 3 * 0.}; // initialize fit parameter
3826 if (0)
3827 for (Int_t iPar = 2; iPar < 4; iPar++)
3828 if (NULL != fhSmCluFpar[iSmType][iPar])
3829 fp[iPar] = fhSmCluFpar[iSmType][iPar]->GetBinContent(iSm * iNbRpc + iRpc + 1);
3830 //LOG(info) << Form("Call yFit with %6.3f, %6.3f, %6.3f, %6.3f",fp[0],fp[1],fp[2],fp[3])
3831 // ;
3832 Double_t* fpp = &fp[0];
3833 fit_ybox(htempPos_py, dYLenFit, fpp);
3834 TF1* ff = htempPos_py->GetFunction("YBox");
3835 if (NULL != ff) {
3836 LOG(debug1) << Form("FitPar1 %6.3f Err %6.3f, Par3 %6.3f Err %6.3f ", ff->GetParameter(1),
3837 ff->GetParError(1), ff->GetParameter(3), ff->GetParError(3));
3838 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey()
3839 < 0.1
3840 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.05) {
3841 if (TMath::Abs(ff->GetParameter(3) - dYMeanFit) < 0.5 * fChannelInfo->GetSizey()) {
3842 YMean = ff->GetParameter(3);
3843 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
3844 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV, dVW);
3845 LOG(info) << "FRes YBox " << htempPos_py->GetEntries() << " entries in TSRC " << iSmType
3846 << iSm << iRpc << iCh << ", chi2 " << ff->GetChisquare()
3847 << Form(", striplen (%5.2f), %4.2f -> %4.2f, "
3848 "%4.1f: %7.2f+/-%5.2f, pos res "
3849 "%5.2f+/-%5.2f at y_cen = %5.2f+/-%5.2f",
3850 fChannelInfo->GetSizey(), dVscal, dV, dVW, 2. * ff->GetParameter(1),
3851 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2),
3852 ff->GetParameter(3), ff->GetParError(3));
3853
3854 for (Int_t iPar = 0; iPar < 4; iPar++)
3855 fhSmCluFpar[iSmType][iPar]->Fill((Double_t)(iSm * iNbRpc + iRpc),
3856 ff->GetParameter(2 + iPar));
3857 }
3858 }
3859 else {
3860 YMean = dYMeanFit; // no new info available
3861 LOG(info) << "FBad YBox " << htempPos_py->GetEntries() << " entries in TSRC " << iSmType << iSm
3862 << iRpc << iCh << ", chi2 " << ff->GetChisquare()
3863 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos "
3864 "res %5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
3865 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1),
3866 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2),
3867 ff->GetParameter(3), ff->GetParError(3));
3868 }
3869 }
3870 }
3871 } // ybox - fit end
3872 dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
3873 }
3874 else { // use deviation from cluster / ext. reference ...
3875 dTYOff =
3876 ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
3877 // better: find dominant peak in histo and fit gaus
3878 if (kTRUE) { //iSmType != 5 && iSmType != 8 ) { // fit gaussian around most abundant bin
3879 TH1* hTy = (TH1*) htempPos->ProjectionY(Form("%s_py%d", htempPos->GetName(), iCh), iCh + 1, iCh + 1);
3880 if (hTy->GetEntries() > WalkNHmin) {
3881 Double_t dNPeak = hTy->GetBinContent(hTy->GetMaximumBin());
3882 if (dNPeak > WalkNHmin * 0.5) {
3883 Double_t dFMean = hTy->GetBinCenter(hTy->GetMaximumBin());
3884 Double_t dFLim = 2.0; // CAUTION, fixed numeric value
3885 Double_t dBinSize = hTy->GetBinWidth(1);
3886 dFLim = TMath::Max(dFLim, 5. * dBinSize);
3887 TFitResultPtr fRes = hTy->Fit("gaus", "SQM", "", dFMean - dFLim, dFMean + dFLim);
3888
3889 if (fRes != 0 && (gMinuit->fCstatu.Contains("OK") || gMinuit->fCstatu.Contains("CONVERGED"))) {
3890 if (TMath::Abs(dTYOff - fRes->Parameter(1)) / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) > 1.)
3891 LOG(warn) << "CalibY "
3892 << Form("TSRC %d%d%d%d gaus %8.2f %8.2f %8.2f for TM %8.2f, YM %6.2f", iSmType, iSm,
3893 iRpc, iCh, fRes->Parameter(0), fRes->Parameter(1), fRes->Parameter(2),
3894 dTYOff, YMean);
3895 dTYOff =
3896 fRes->Parameter(1) / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc); //overwrite mean of profile
3897 }
3898 else {
3899 LOG(info) << "CalibY3BAD " << hTy->GetName()
3900 << Form(" TSRC %d%d%d%d, stat: %s", iSmType, iSm, iRpc, iCh, gMinuit->fCstatu.Data());
3901 }
3902 }
3903 if (iSmType == 0 && iSm == 2 && iRpc == 0 && iCh == 10) // select specific channel
3904 LOG(info) << "CalibY3 "
3905 << Form("TSRC %d%d%d%d TY %8.2f, %8.2f, YM %6.2f", iSmType, iSm, iRpc, iCh,
3906 ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1)
3907 / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc),
3908 dTYOff, YMean);
3909 }
3910 }
3911
3912 if (iSmType == 0 && iSm == 2 && iRpc == 0 && iCh == 10) // select specific channel
3913 LOG(info) << "CalibYP " << Form("%s TY %8.3f, YM %6.3f ", htempPos->GetName(), dTYOff, YMean);
3914 }
3915 Double_t TMean = ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1);
3916 if (kTRUE && fIdMode == 0) { // fit gaussian around most abundant bin
3917 TH1* hTy = (TH1*) htempTOff->ProjectionY(Form("%s_py%d", htempTOff->GetName(), iCh), iCh + 1, iCh + 1);
3918 if (hTy->GetEntries() > WalkNHmin) {
3919 Double_t dNPeak = hTy->GetBinContent(hTy->GetMaximumBin());
3920 if (dNPeak > WalkNHmin * 0.5) {
3921 Double_t dFMean = hTy->GetBinCenter(hTy->GetMaximumBin());
3922 Double_t dFLim = 2.0; // CAUTION, fixed numeric value
3923 Double_t dBinSize = hTy->GetBinWidth(1);
3924 dFLim = TMath::Max(dFLim, 10. * dBinSize);
3925 TFitResultPtr fRes = hTy->Fit("gaus", "SQM", "", dFMean - dFLim, dFMean + dFLim);
3926 //if (fRes == 0 )
3927 if (gMinuit->fCstatu.Contains("OK") || gMinuit->fCstatu.Contains("CONVERGED")) {
3928 //if (TMath::Abs(TMean - fRes->Parameter(1)) > 1.)
3929 if (iSmType == 5)
3930 LOG(info) << "CalibF "
3931 << Form("TSRC %d%d%d%d, %s gaus %8.2f %8.2f %8.2f for "
3932 "TM %8.2f, TRef %6.2f",
3933 iSmType, iSm, iRpc, iCh, htempTOff->GetName(), fRes->Parameter(0),
3934 fRes->Parameter(1), fRes->Parameter(2), TMean, dTBeamRefMean);
3935 TMean = fRes->Parameter(1); //overwrite mean
3936 }
3937 }
3938 }
3939 }
3940
3941 if (fiBeamRefAddr == (iUniqueId & SelMask)) {
3942 LOG(info) << Form("CalibR TSRC %d%d%d%d: ", iSmType, iSm, iRpc, iCh) << "TM " << TMean << ", Ref "
3943 << dTBeamRefMean;
3944 TMean -= dTBeamRefMean; //do not shift T0 on average
3945 }
3946
3947 if (htempTOff_px->GetBinContent(iCh + 1) > WalkNHmin) {
3948 Double_t dOff0 = fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
3949 Double_t dOff1 = fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1];
3950 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
3951 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
3952 //if(iSmType==0 && iSm==4 && iRpc==2 && iCh==26)
3953 //if (iSmType==0 && iSm==1 && iRpc == 1)
3954 //if(iSmType==0 && iSm==2 && iRpc==0 && iCh==10) // select specific channel
3955 if (iSmType == 5)
3956 LOG(info) << Form("CalibB %d,%2d,%2d: TSRC %d%d%d%d, hits %6.0f, YM %6.3f"
3957 ", dTY %6.3f, TM %8.3f %8.3f, Off %8.3f,%8.3f -> %8.3f,%8.3f ",
3958 fCalMode, fCalSel, fTRefMode, iSmType, iSm, iRpc, iCh,
3959 htempTOff_px->GetBinContent(iCh + 1), YMean, dTYOff, TMean, dTBeamRefMean, dOff0,
3960 dOff1, fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
3961 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
3962 }
3963 /*
3964 Double_t TotMean=((TProfile *)htempTot_pfx)->GetBinContent(iCh+1);
3965 if(0.001 < TotMean){
3966 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][0] *= fdTTotMean / TotMean;
3967 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1] *= fdTTotMean / TotMean;
3968 }
3969 */
3970 if (fCalMode < 90) // keep digi TOT calibration in last step
3971 for (Int_t iSide = 0; iSide < 2; iSide++) {
3972 Int_t ib = iCh * 2 + 1 + iSide;
3973 TH1* hbin = htempTot->ProjectionY(Form("%s_bin%d", htempTot->GetName(), ib), ib, ib);
3974 if (100 > hbin->GetEntries()) continue; //request min number of entries
3975 /* Double_t Ymax=hbin->GetMaximum();*/
3976 Int_t iBmax = hbin->GetMaximumBin();
3977 TAxis* xaxis = hbin->GetXaxis();
3978 Double_t Xmax = xaxis->GetBinCenter(iBmax) / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide];
3979 Double_t XOff = Xmax - fTotPreRange;
3980 if (0) { //TMath::Abs(XOff - fvCPTotOff[iSmType][iSm*iNbRpc+iRpc][iCh][iSide])>100){
3981 LOG(warning) << "XOff changed for "
3982 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: XOff %f, old %f", iSmType, iSm, iRpc, iSide,
3983 XOff, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
3984 }
3985 // Double_t TotMean=htempTot_Mean->GetBinContent(ib);
3986 Double_t TotMean = hbin->GetMean();
3987 Double_t dCtsTot = hbin->GetEntries();
3988 if (dCtsTot > WalkNHmin) {
3989 if (iBmax == 0) {
3990 if (hbin->GetBinContent(hbin->GetNbinsX() > 0))
3991 TotMean = xaxis->GetBinCenter(hbin->GetNbinsX() - 1);
3992 LOG(info) << "TotInvalid " << hbin->GetName() << ": " << TotMean;
3993 }
3994 double dFMean = hbin->GetBinCenter(iBmax);
3995 double dFLim = dFMean * 0.5; // CAUTION, hardcoded parameter
3996 LOG(info) << Form("FitTot TSRC %d%d%d%2d: Mean %6.2f, Width %6.2f ", iSmType, iSm, iRpc, ib,
3997 dFMean, dFLim);
3998 if (dFMean > 2.) {
3999 TFitResultPtr fRes = hbin->Fit("gaus", "SQM", "", dFMean - dFLim, dFMean + dFLim);
4000 if (gMinuit->fCstatu.Contains("OK") || gMinuit->fCstatu.Contains("CONVERGED")) {
4001 TotMean = fRes->Parameter(1); //overwrite mean
4002 }
4003 else {
4004 TotMean = dFMean;
4005 LOG(warn) << "TotFitFail " << hbin->GetName() << ": " << TotMean << ", wid " << dFLim << ", "
4006 << gMinuit->fCstatu;
4007 }
4008 }
4009 else {
4010 TotMean = dFMean;
4011 if (TotMean < 0.2)
4012 //if(hbin->GetBinContent(hbin->GetNbinsX()) > 0 )
4013 TotMean = xaxis->GetBinCenter(hbin->GetNbinsX() - 1);
4014 LOG(warn) << "TotooR " << hbin->GetName() << ": " << TotMean << ", gain "
4015 << fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] << ", ovfl "
4016 << hbin->GetBinContent(hbin->GetNbinsX());
4017 }
4018 }
4019 if (15 == iSmType) {
4020 LOG(warning) << "Gain for "
4021 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: TotMean %f, prof %f, "
4022 "gain %f, modg %f ",
4023 iSmType, iSm, iRpc, iSide, TotMean, htempTot_Mean->GetBinContent(ib),
4024 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide], fdTTotMean / TotMean);
4025 }
4026 if (0.001 < TotMean) {
4027 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] *= fdTTotMean / TotMean;
4028 }
4029 }
4030 if (5 == iSmType
4031 && fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]
4032 != fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]) { // diamond
4033 LOG(warning) << "CbmTofEventClusterizer::FillCalHist:"
4034 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh << ": YMean "
4035 << YMean << ", TMean " << TMean << " -> "
4036 << Form(" %f %f %f %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
4037 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
4038 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
4039 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4040 Double_t dTOff =
4041 0.5
4042 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4043 /*
4044 Double_t dGain = 0.5
4045 * (fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0]
4046 + fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4047 */
4048 Double_t dGain0 = fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0];
4049 Double_t dGain1 = fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1];
4050 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dTOff;
4051 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dTOff;
4052 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dGain0;
4053 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dGain1;
4054 } // diamond warning end
4055 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
4056 } // iSmType selection condition
4057
4058 htempPos_pfx->Reset(); //reset to store new values
4059 htempTOff_pfx->Reset();
4060 htempTot_Mean->Reset();
4061 htempTot_Off->Reset();
4062
4063 Double_t TOff0_mean = 0.;
4064 Double_t TOff1_mean = 0.;
4065 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // determine means
4066 {
4067 TOff0_mean += fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
4068 TOff1_mean += fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1];
4069 }
4070 TOff0_mean /= (Double_t) iNbCh;
4071 TOff1_mean /= (Double_t) iNbCh;
4072
4073 const Double_t TMaxDev = TMath::Max(20., htempTOff->GetYaxis()->GetXmax());
4074 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // remove outlyers
4075 {
4076 if (TMath::Abs(TOff0_mean - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]) > TMaxDev) {
4077 LOG(warn) << Form("TSRC0 %d%d%d%d limit %8.3f %8.3f %8.3f ", iSmType, iSm, iRpc, iCh,
4078 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0], TOff0_mean, TMaxDev);
4079 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] = TOff0_mean;
4080 }
4081 if (TMath::Abs(TOff1_mean - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]) > TMaxDev) {
4082 LOG(warn) << Form("TSRC1 %d%d%d%d limit %8.3f %8.3f %8.3f", iSmType, iSm, iRpc, iCh,
4083 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1], TOff1_mean, TMaxDev);
4084 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = TOff1_mean;
4085 }
4086 }
4087
4088 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
4089 {
4090 Double_t YMean =
4091 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
4092 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
4093 Double_t TMean =
4094 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
4095 htempPos_pfx->Fill(iCh, YMean);
4096 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
4097 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got "
4098 << htempPos_pfx->GetBinContent(iCh) << "," << htempPos_pfx->GetBinContent(iCh + 1) << ","
4099 << htempPos_pfx->GetBinContent(iCh + 2) << ", expected " << YMean;
4100 }
4101 htempTOff_pfx->Fill(iCh, TMean);
4102 if (iSmType == 9 && iSm == 0 && iRpc == 0 && iCh == 10) // select specific channel
4103 LOG(info) << Form("CalibU %d,%2d,%2d: TSRC %d%d%d%d, hits %6.0f, YM %6.3f"
4104 ", TM %8.3f, OffM %8.3f,%8.3f ",
4105 fCalMode, fCalSel, fTRefMode, iSmType, iSm, iRpc, iCh,
4106 htempTOff_px->GetBinContent(iCh + 1), YMean, TMean, TOff0_mean, TOff1_mean);
4107
4108 for (Int_t iSide = 0; iSide < 2; iSide++) {
4109 htempTot_Mean->SetBinContent(iCh * 2 + 1 + iSide,
4110 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
4111 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
4112 }
4113 // htempTot_pfx->Fill(iCh,fdTTotMean/fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1]);
4114 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
4115
4116 LOG(debug1) << " Updating done ... write to file ";
4117 htempPos_pfx->Write();
4118 htempTOff_pfx->Write();
4119 // htempTot_pfx->Write();
4120 htempTot_Mean->Write();
4121 htempTot_Off->Write();
4122
4123 // store old DELTOF histos
4124 LOG(debug) << " Copy old DelTof histos from " << gDirectory->GetName() << " to file ";
4125
4126 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
4127 // Store DelTof corrections
4128 TDirectory* curdir = gDirectory;
4129 gROOT->cd(); //
4130 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
4131 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
4132 gDirectory->cd(curdir->GetPath());
4133 if (NULL != hCorDelTof) {
4134 TH1D* hCorDelTofout = (TH1D*) hCorDelTof->Clone(
4135 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
4136 hCorDelTofout->Write();
4137 }
4138 else {
4139 LOG(debug) << " No CorDelTof histo "
4140 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
4141 }
4142 }
4143
4144 LOG(debug) << " Store old walk histos to file ";
4145 // store walk histos
4146 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // restore old values
4147 {
4148 if (NULL == fhRpcCluWalk[iDetIndx][iCh][0]) break;
4149 // TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
4150 // TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
4151 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
4152 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
4153 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
4154 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
4155 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
4156 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
4157 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
4158 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
4159 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
4160 }
4161 }
4162 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
4163 // htmp0->Write();
4164 h1tmp0->Write();
4165 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
4166 // htmp1->Write();
4167 h1tmp1->Write();
4168 }
4169 } break;
4170 case 4: //update DelTof, save offsets, gains and walks
4171 {
4172 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
4173 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
4174 LOG(debug) << "WriteHistos: restore Offsets, Gains and Walk, save DelTof for "
4175 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc;
4176 htempPos_pfx->Reset(); //reset to restore mean of original histos
4177 htempTOff_pfx->Reset();
4178 htempTot_Mean->Reset();
4179 htempTot_Off->Reset();
4180 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
4181 Double_t YMean =
4182 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
4183 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
4184 Double_t TMean =
4185 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
4186 htempPos_pfx->Fill(iCh, YMean);
4187 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
4188 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got "
4189 << htempPos_pfx->GetBinContent(iCh) << "," << htempPos_pfx->GetBinContent(iCh + 1) << ","
4190 << htempPos_pfx->GetBinContent(iCh + 2) << ", expected " << YMean;
4191 }
4192 htempTOff_pfx->Fill(iCh, TMean);
4193
4194 for (Int_t iSide = 0; iSide < 2; iSide++) {
4195 htempTot_Mean->SetBinContent(
4196 iCh * 2 + 1 + iSide,
4197 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]); //nh +1 empirical(?)
4198 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
4199 }
4200 }
4201
4202 LOG(debug1) << " Restoring of Offsets and Gains done ... ";
4203 htempPos_pfx->Write();
4204 htempTOff_pfx->Write();
4205 // htempTot_pfx->Write();
4206 htempTot_Mean->Write();
4207 htempTot_Off->Write();
4208
4209 // restore walk histos
4210 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // restore old values
4211 {
4212 if (NULL == fhRpcCluWalk[iDetIndx][iCh][0]) break;
4213 // TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
4214 // TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
4215 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
4216 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
4217 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
4218 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
4219 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
4220 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
4221 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
4222 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
4223 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
4224 }
4225 }
4226 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
4227 // htmp0->Write();
4228 h1tmp0->Write();
4229 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
4230 // htmp1->Write();
4231 h1tmp1->Write();
4232 }
4233
4234 // generate/update DelTof corrections
4235 if ((fCalSmAddr < 0 && -fCalSmAddr != iSmAddr)
4236 || (fCalSmAddr == iSmAddr)) // select detectors for determination of DelTof correction
4237 {
4238 if (fiBeamRefAddr == (iSmAddr & SelMask)) continue; // no DelTof correction for Diamonds
4239
4240 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
4241 TH2* h2tmp = fhTRpcCluDelTof[iDetIndx][iSel];
4242 if (NULL == h2tmp) {
4243 LOG(debug) << Form("WriteHistos: histo not available for SmT %d, Sm %d, Rpc %d", iSmType, iSm, iRpc);
4244 break;
4245 }
4246 Int_t iNEntries = h2tmp->GetEntries();
4247
4248 // h2tmp->Write();
4249 TProfile* htmp = h2tmp->ProfileX("_pfx", 1, h2tmp->GetNbinsY());
4250 TH1D* h1tmp = h2tmp->ProjectionX("_px", 1, h2tmp->GetNbinsY());
4251 /* TH1D *h1ytmp = h2tmp->ProjectionY("_py",1,h2tmp->GetNbinsX());*/
4252 Double_t dDelMean =
4253 0.; //h1ytmp->GetMean();// inspect normalization, interferes with mode 3 for diamonds, nh, 10.01.2015 (?)
4254 Double_t dNEntriesSum = 0.;
4255 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
4256 Double_t dNEntries = h1tmp->GetBinContent(iBx + 1);
4257 if (dNEntries > WalkNHmin) // modify, request sufficient # of entries
4258 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] += ((TProfile*) htmp)->GetBinContent(iBx + 1);
4259 dDelMean += fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] * dNEntries;
4260 dNEntriesSum += dNEntries;
4261 }
4262 dDelMean /= dNEntriesSum;
4263
4264 LOG(debug) << Form(" Update DelTof correction for SmT %d, Sm %d, "
4265 "Rpc %d, Sel%d: Entries %d, Mean shift %6.1f",
4266 iSmType, iSm, iRpc, iSel, iNEntries, dDelMean);
4267
4268 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
4269 h1tmp->SetBinContent(iBx + 1, fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] - dDelMean);
4270 //h1tmp->SetBinContent(iBx+1,fvCPDelTof[iSmType][iSm*iNbRpc+iRpc][iBx][iSel]);
4271 }
4272 h1tmp->SetName(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
4273 h1tmp->Write();
4274 }
4275 }
4276 else { // copy existing histograms
4277 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
4278 // Store DelTof corrections
4279 TDirectory* curdir = gDirectory;
4280 gROOT->cd(); //
4281 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
4282 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
4283 gDirectory->cd(curdir->GetPath());
4284 if (NULL != hCorDelTof) {
4285 TH1D* hCorDelTofout = (TH1D*) hCorDelTof->Clone(
4286 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
4287 LOG(debug) << " Save existing CorDelTof histo "
4288 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
4289 hCorDelTofout->Write();
4290 }
4291 else {
4292 LOG(debug) << " No CorDelTof histo "
4293 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
4294 }
4295 }
4296 }
4297 } break;
4298
4299 case 5: //update offsets (from positions only), gains, save walks and DELTOF
4300 {
4301 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
4302 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
4303 Int_t iYCalMode = 0; // FIXME hardcoded option
4304 if ((fCalSmAddr < 0) || (fCalSmAddr != iSmAddr)) { // select detectors for updating offsets
4305 LOG(debug) << "WriteHistos (calMode==5): update Offsets and Gains, "
4306 "keep Walk and DelTof for "
4307 << "Smtype" << iSmType << ", Sm " << iSm << ", Rpc " << iRpc << " with " << iNbCh << " channels "
4308 << " using selector " << fCalSel;
4309 // Y treatment copied from case 3 - keep it consistent -> new method
4310 Double_t dVscal = 1.;
4311 Double_t dVW = 1.;
4312 if (0) // NULL != fhSmCluSvel[iSmType])
4313 {
4314 dVscal = fhSmCluSvel[iSmType]->GetBinContent(iSm * iNbRpc + iRpc + 1);
4315 if (dVscal == 0.) dVscal = 1.;
4316 dVW = fhSmCluSvel[iSmType]->GetBinEffectiveEntries(iSm * iNbRpc + iRpc + 1);
4317 dVW *= 50.; //(Double_t)iNbCh;
4318 if (dVW < 0.1) dVW = 0.1;
4319 }
4320 Double_t dYShift = 0;
4321 Double_t dYMeanAv = 0.;
4322 Double_t dYMeanFit = 0.;
4323 Double_t dYLenFit = 0.;
4324 Double_t YMean = 0.;
4325 if (fCalSel >= 0) {
4326 // determine average values
4327 htempPos_py = htempPos->ProjectionY(Form("%s_py", htempPos->GetName()), 1, iNbCh);
4328
4329 if (htempPos_py->GetEntries() > fdYFitMin && fPosYMaxScal < 1.1) {
4330 dYMeanAv = htempPos_py->GetMean();
4331 LOG(debug1) << Form("Determine YMeanAv in %s by fit to %d entries", htempPos->GetName(),
4332 (Int_t) htempPos_py->GetEntries());
4333 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, 0);
4334 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
4335 fChannelInfo = fDigiPar->GetCell(iChId);
4336 if (NULL == fChannelInfo) {
4337 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
4338 continue;
4339 }
4340 switch (iYCalMode) {
4341 case 0: {
4342 fit_ybox(htempPos_py, fChannelInfo->GetSizey());
4343 TF1* ff = htempPos_py->GetFunction("YBox");
4344 if (NULL != ff && (gMinuit->fCstatu.Contains("OK") || gMinuit->fCstatu.Contains("CONVERGED"))) {
4345 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey()
4346 < 0.05
4347 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.2) {
4348 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
4349 LOG(info) << "FAvRes YBox " << htempPos_py->GetEntries() << " entries in TSR " << iSmType << iSm
4350 << iRpc << ", stat: " << gMinuit->fCstatu
4351 << Form(", chi2 %6.2f, striplen (%5.2f): "
4352 "%7.2f+/-%5.2f, pos res "
4353 "%5.2f+/-%5.2f at y_cen = %5.2f+/-%5.2f",
4354 ff->GetChisquare() / ff->GetNDF(), fChannelInfo->GetSizey(),
4355 2. * ff->GetParameter(1), 2. * ff->GetParError(1), ff->GetParameter(2),
4356 ff->GetParError(2), ff->GetParameter(3), ff->GetParError(3));
4357 if (TMath::Abs(ff->GetParameter(3) - dYMeanAv) < 0.5 * fChannelInfo->GetSizey()) {
4358 dYMeanFit = ff->GetParameter(3);
4359 dYLenFit = 2. * ff->GetParameter(1);
4360 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV, dVW);
4361 for (Int_t iPar = 0; iPar < 4; iPar++)
4362 fhSmCluFpar[iSmType][iPar]->Fill((Double_t)(iSm * iNbRpc + iRpc),
4363 ff->GetParameter(2 + iPar));
4364 }
4365 }
4366 else {
4367 LOG(info) << "FAvBad YBox " << htempPos_py->GetEntries() << " entries in " << iSmType << iSm
4368 << iRpc << ", chi2 " << ff->GetChisquare() << ", stat: " << gMinuit->fCstatu
4369 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos res "
4370 "%5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
4371 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1),
4372 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2),
4373 ff->GetParameter(3), ff->GetParError(3));
4374 }
4375 }
4376 else {
4377 LOG(info) << "FAvFailed for TSR " << iSmType << iSm << iRpc << ", status: " << gMinuit->fCstatu
4378 << " of " << htempPos->GetName();
4379 }
4380 dYShift = dYMeanFit - dYMeanAv;
4381 LOG(debug) << Form("CalibY for TSR %d%d%d: DY %5.2f, Fit %5.2f, Av %5.2f ", iSmType, iSm, iRpc,
4382 dYShift, dYMeanFit, dYMeanAv);
4383 } break;
4384 case 1: {
4385 double dThr = 10.;
4386 double* dRes = find_yedges((const char*) (htempPos_py->GetName()), dThr, fChannelInfo->GetSizey());
4387 LOG(debug) << Form("EdgeY for %s, TSR %d%d%d: DY %5.2f, Len %5.2f, Size %5.2f ",
4388 htempPos_py->GetName(), iSmType, iSm, iRpc, dRes[1], dRes[0],
4390
4391 if (TMath::Abs(dRes[0] - fChannelInfo->GetSizey()) / fChannelInfo->GetSizey() < 0.1) {
4392 dYShift = dRes[1];
4393 }
4394 } break;
4395 }
4396 }
4397 }
4398
4399 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // update Offset and Gain
4400 {
4401 Double_t dTYOff = 0;
4402 Double_t TMean = 0.;
4403 if (fCalSel >= 0) {
4404 //YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1); //set default
4405 YMean = dYShift;
4406
4407 if (fPosYMaxScal < 1.1) { //disable by adding "-" sign
4408 htempPos_py = htempPos->ProjectionY(Form("%s_py%02d", htempPos->GetName(), iCh), iCh + 1, iCh + 1);
4409 if (htempPos_py->GetEntries() > fdYFitMin) {
4410 LOG(info) << Form("Determine YMean in %s of channel %d by length fit with %6.3f to %d entries",
4411 htempPos->GetName(), iCh, dYLenFit, (Int_t) htempPos_py->GetEntries());
4412 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
4413 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
4414 fChannelInfo = fDigiPar->GetCell(iChId);
4415 if (NULL == fChannelInfo) {
4416 LOG(warning) << Form("invalid ChannelInfo for 0x%08x", iChId);
4417 continue;
4418 }
4419
4420 switch (iYCalMode) {
4421 case 0: {
4422 Double_t fp[4] = {1., 3 * 0.}; // initialize fit parameter
4423 if (0)
4424 for (Int_t iPar = 2; iPar < 4; iPar++)
4425 if (NULL != fhSmCluFpar[iSmType][iPar])
4426 fp[iPar] = fhSmCluFpar[iSmType][iPar]->GetBinContent(iSm * iNbRpc + iRpc + 1);
4427 //LOG(info) << Form("Call yFit with %6.3f, %6.3f, %6.3f, %6.3f",fp[0],fp[1],fp[2],fp[3])
4428 // ;
4429 Double_t* fpp = &fp[0];
4430 fit_ybox(htempPos_py, dYLenFit, fpp);
4431 TF1* ff = htempPos_py->GetFunction("YBox");
4432 if (NULL != ff) {
4433 LOG(debug1) << "FStat: " << gMinuit->fCstatu
4434 << Form(", FPar1 %6.3f Err %6.3f, Par3 %6.3f Err %6.3f ", ff->GetParameter(1),
4435 ff->GetParError(1), ff->GetParameter(3), ff->GetParError(3));
4436 if (TMath::Abs(fChannelInfo->GetSizey() - 2. * ff->GetParameter(1)) / fChannelInfo->GetSizey()
4437 < 0.05
4438 && TMath::Abs(ff->GetParError(1) / ff->GetParameter(1)) < 0.05) {
4439 if (TMath::Abs(ff->GetParameter(3) - dYMeanFit) < 0.5 * fChannelInfo->GetSizey()) {
4440 YMean = ff->GetParameter(3);
4441 Double_t dV = dVscal * fChannelInfo->GetSizey() / (2. * ff->GetParameter(1));
4442 fhSmCluSvel[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), dV, dVW);
4443 LOG(info) << "FRes YBox " << htempPos_py->GetEntries() << " entries in TSRC " << iSmType
4444 << iSm << iRpc << iCh << ", chi2 " << ff->GetChisquare()
4445 << Form(", striplen (%5.2f), %4.2f -> %4.2f, "
4446 "%4.1f: %7.2f+/-%5.2f, pos res "
4447 "%5.2f+/-%5.2f at y_cen = %5.2f+/-%5.2f",
4448 fChannelInfo->GetSizey(), dVscal, dV, dVW, 2. * ff->GetParameter(1),
4449 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2),
4450 ff->GetParameter(3), ff->GetParError(3));
4451
4452 for (Int_t iPar = 0; iPar < 4; iPar++)
4453 fhSmCluFpar[iSmType][iPar]->Fill((Double_t)(iSm * iNbRpc + iRpc),
4454 ff->GetParameter(2 + iPar));
4455 }
4456 }
4457 else {
4458 YMean = dYMeanFit; // no new info available
4459 LOG(info) << "FBad YBox " << htempPos_py->GetEntries() << " entries in TSRC " << iSmType
4460 << iSm << iRpc << iCh << ", chi2 " << ff->GetChisquare()
4461 << Form(", striplen (%5.2f), %4.2f: %7.2f +/- %5.2f, pos "
4462 "res %5.2f +/- %5.2f at y_cen = %5.2f +/- %5.2f",
4463 fChannelInfo->GetSizey(), dVscal, 2. * ff->GetParameter(1),
4464 2. * ff->GetParError(1), ff->GetParameter(2), ff->GetParError(2),
4465 ff->GetParameter(3), ff->GetParError(3));
4466 }
4467 }
4468 } break;
4469
4470 case 1: {
4471 // calculate threshold
4472 double dXrange = 2 * htempPos_py->GetXaxis()->GetXmax();
4473 double dNbinsX = htempPos_py->GetNbinsX();
4474 double dEntries =
4475 htempPos_py->Integral(htempPos_py->GetXaxis()->GetXmin(), htempPos_py->GetXaxis()->GetXmax());
4476 double dBinWidth = dXrange / dNbinsX;
4477 double dNbinFillExpect = fChannelInfo->GetSizey() / dBinWidth;
4478 double dCtsPerBin = dEntries / dNbinFillExpect;
4479 double dThr = dCtsPerBin / 10.;
4480 if (dThr < 1.) {
4481 LOG(warn) << "Few entries in " << htempPos_py->GetName() << ": " << dEntries << ", "
4482 << htempPos_py->GetEntries() << " -> thr " << dThr;
4483 dThr = 1.;
4484 }
4485 double* dRes =
4486 find_yedges((const char*) (htempPos_py->GetName()), dThr, fChannelInfo->GetSizey());
4487 LOG(info) << Form(
4488 "EdgeY Thr %4.1f, TSRC %d%d%d%02d: DY %5.2f, Len %5.2f, Size %5.2f: dev %6.3f ", dThr,
4489 iSmType, iSm, iRpc, iCh, dRes[1], dRes[0], fChannelInfo->GetSizey(),
4490 (dRes[0] - fChannelInfo->GetSizey()) / fChannelInfo->GetSizey());
4491 if (TMath::Abs(dRes[0] - fChannelInfo->GetSizey()) / fChannelInfo->GetSizey() < 0.1) {
4492 YMean = dRes[1];
4493 }
4494 } break;
4495 } // switch end
4496 } // ybox - fit end
4497 dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
4498 }
4499 }
4500 else { // use deviation from cluster / ext. reference ...
4501 dTYOff =
4502 ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
4503 // better: find dominant peak in histo and fit gaus
4504 if (iSmType != 5 && iSmType != 8) { // fit gaussian around most abundant bin
4505 TH1* hTy = (TH1*) htempPos->ProjectionY(Form("%s_py%d", htempPos->GetName(), iCh), iCh + 1, iCh + 1);
4506 if (hTy->GetEntries() > WalkNHmin) {
4507 Double_t dNPeak = hTy->GetBinContent(hTy->GetMaximumBin());
4508 if (dNPeak > WalkNHmin * 0.5) {
4509 Double_t dFMean = hTy->GetBinCenter(hTy->GetMaximumBin());
4510 Double_t dFLim = 2.0; // CAUTION, fixed numeric value
4511 Double_t dBinSize = hTy->GetBinWidth(1);
4512 dFLim = TMath::Max(dFLim, 5. * dBinSize);
4513 TFitResultPtr fRes = hTy->Fit("gaus", "SQM", "", dFMean - dFLim, dFMean + dFLim);
4514 if (fRes == 0 && (gMinuit->fCstatu.Contains("OK") || gMinuit->fCstatu.Contains("CONVERGED"))) {
4515
4516 if (TMath::Abs(dTYOff - fRes->Parameter(1)) / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) > 1.)
4517 LOG(warn) << "CalibY5 "
4518 << Form("TSRC %d%d%d%d gaus %8.2f %8.2f %8.2f for TM %8.2f, YM %6.2f", iSmType, iSm,
4519 iRpc, iCh, fRes->Parameter(0), fRes->Parameter(1), fRes->Parameter(2),
4520 dTYOff, YMean);
4521 dTYOff =
4522 fRes->Parameter(1) / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc); //overwrite mean of profile
4523 }
4524 else {
4525 LOG(info) << "CalibY5BAD "
4526 << Form("TSRC %d%d%d%d, stat: %s for %s", iSmType, iSm, iRpc, iCh,
4527 gMinuit->fCstatu.Data(), htempPos->GetName());
4528 }
4529 }
4530 }
4531 }
4532 TMean = 0.;
4533 if (kTRUE) { // fit gaussian around most abundant bin
4534 TH1* hTy =
4535 (TH1*) htempTOff->ProjectionY(Form("%s_py%d", htempTOff->GetName(), iCh), iCh + 1, iCh + 1);
4536 if (hTy->GetEntries() > WalkNHmin) {
4537 Double_t dNPeak = hTy->GetBinContent(hTy->GetMaximumBin());
4538 if (dNPeak > WalkNHmin * 0.5) {
4539 Double_t dFMean = hTy->GetBinCenter(hTy->GetMaximumBin());
4540 Double_t dFLim = 0.5; // CAUTION, fixed numeric value
4541 Double_t dBinSize = hTy->GetBinWidth(1);
4542 dFLim = TMath::Max(dFLim, 5. * dBinSize);
4543 TFitResultPtr fRes = hTy->Fit("gaus", "SQM", "", dFMean - dFLim, dFMean + dFLim);
4544 if (fRes == 0 && (gMinuit->fCstatu.Contains("OK") || gMinuit->fCstatu.Contains("CONVERGED"))) {
4545 if (TMath::Abs(TMean - fRes->Parameter(1)) > 0.6)
4546 LOG(debug) << "CalibF5 "
4547 << Form("TSRC %d%d%d%d gaus %8.2f %8.2f %8.2f for "
4548 "TM %8.2f, YM %6.2f",
4549 iSmType, iSm, iRpc, iCh, fRes->Parameter(0), fRes->Parameter(1),
4550 fRes->Parameter(2), TMean, YMean);
4551 TMean = fRes->Parameter(1); //overwrite mean
4552 }
4553 else {
4554 LOG(info) << "CalibF5BAD "
4555 << Form("TSRC %d%d%d%d, stat: %s for %s", iSmType, iSm, iRpc, iCh,
4556 gMinuit->fCstatu.Data(), htempTOff->GetName());
4557 }
4558 }
4559 }
4560 }
4561 }
4562
4563 if (htempTOff_px->GetBinContent(iCh + 1) > WalkNHmin) {
4564 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
4565 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
4566 }
4567 if (iSmType == 9 && iSm == 0 && iRpc == 0 && iCh == 10) // select specific channel
4568 LOG(info) << Form("Calib: TSRC %d%d%d%d, hits %6.0f, TY %8.3f, TM %8.3f -> new Off %8.0f,%8.0f ",
4569 iSmType, iSm, iRpc, iCh, htempTOff_px->GetBinContent(iCh + 1), dTYOff, TMean,
4570 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
4571 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4572
4573 /*
4574 Double_t TotMean=((TProfile *)htempTot_pfx)->GetBinContent(iCh+1); //nh +1 empirical(!)
4575 if(0.001 < TotMean){
4576 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][0] *= fdTTotMean / TotMean;
4577 fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1] *= fdTTotMean / TotMean;
4578 }
4579 */
4580
4581 if (fCalMode < 90) // keep digi TOT calibration in last step
4582 for (Int_t iSide = 0; iSide < 2; iSide++) {
4583 Int_t ib = iCh * 2 + 1 + iSide;
4584 TH1* hbin = htempTot->ProjectionY(Form("bin%d", ib), ib, ib);
4585 if (100 > hbin->GetEntries()) continue; //request min number of entries
4586 /* Double_t Ymax=hbin->GetMaximum();*/
4587 Int_t iBmax = hbin->GetMaximumBin();
4588 TAxis* xaxis = hbin->GetXaxis();
4589 Double_t Xmax = xaxis->GetBinCenter(iBmax) / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide];
4590 Double_t XOff = Xmax - fTotPreRange;
4591 if (0) { //TMath::Abs(XOff - fvCPTotOff[iSmType][iSm*iNbRpc+iRpc][iCh][iSide])>100){
4592 LOG(warning) << "XOff changed for "
4593 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: XOff %f, old %f", iSmType, iSm, iRpc, iSide,
4594 XOff, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
4595 }
4596 // Double_t TotMean=htempTot_Mean->GetBinContent(ib);
4597 Double_t TotMean = hbin->GetMean();
4598 if (15 == iSmType) {
4599 LOG(warning) << "Gain for "
4600 << Form("SmT%01d_sm%03d_rpc%03d_Side%d: TotMean %f, prof %f, "
4601 "gain %f, modg %f ",
4602 iSmType, iSm, iRpc, iSide, TotMean, htempTot_Mean->GetBinContent(ib),
4603 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide], fdTTotMean / TotMean);
4604 }
4605 if (0.001 < TotMean) {
4606 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] *= fdTTotMean / TotMean;
4607 }
4608 }
4609 if (5 == iSmType
4610 && fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]
4611 != fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]) { // diamond
4612 LOG(warning) << "CbmTofEventClusterizer::FillCalHist:"
4613 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh << ": YMean "
4614 << YMean << ", TMean " << TMean << " -> "
4615 << Form(" %f %f %f %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
4616 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
4617 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
4618 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4619 Double_t dTOff =
4620 0.5
4621 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4622 Double_t dGain = 0.5
4623 * (fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0]
4624 + fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
4625 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dTOff;
4626 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dTOff;
4627 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0] = dGain;
4628 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1] = dGain;
4629 } // diamond warning end
4630 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
4631 } // iSmType selection condition
4632
4633 htempPos_pfx->Reset(); //reset to store new values
4634 htempTOff_pfx->Reset();
4635 htempTot_Mean->Reset();
4636 htempTot_Off->Reset();
4637 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // store new values
4638 {
4639 Double_t YMean =
4640 fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * 0.5
4641 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] - fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
4642 Double_t TMean =
4643 0.5 * (fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] + fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0]);
4644 htempPos_pfx->Fill(iCh, YMean);
4645 if (((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1) != YMean) {
4646 LOG(error) << "WriteHistos: restore unsuccessful! ch " << iCh << " got "
4647 << htempPos_pfx->GetBinContent(iCh) << "," << htempPos_pfx->GetBinContent(iCh + 1) << ","
4648 << htempPos_pfx->GetBinContent(iCh + 2) << ", expected " << YMean;
4649 }
4650 htempTOff_pfx->Fill(iCh, TMean);
4651
4652 for (Int_t iSide = 0; iSide < 2; iSide++) {
4653 htempTot_Mean->SetBinContent(iCh * 2 + 1 + iSide,
4654 fdTTotMean / fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
4655 htempTot_Off->SetBinContent(iCh * 2 + 1 + iSide, fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide]);
4656 }
4657 // htempTot_pfx->Fill(iCh,fdTTotMean/fvCPTotGain[iSmType][iSm*iNbRpc+iRpc][iCh][1]);
4658 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
4659
4660 LOG(debug1) << " Updating done ... write to file ";
4661 htempPos_pfx->Write();
4662 htempTOff_pfx->Write();
4663 // htempTot_pfx->Write();
4664 htempTot_Mean->Write();
4665 htempTot_Off->Write();
4666
4667 // store old DELTOF histos
4668 LOG(debug) << " Copy old DelTof histos from " << gDirectory->GetName() << " to file ";
4669
4670 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
4671 // Store DelTof corrections
4672 TDirectory* curdir = gDirectory;
4673 gROOT->cd(); //
4674 TH1D* hCorDelTof = (TH1D*) gDirectory->FindObjectAny(
4675 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
4676 gDirectory->cd(curdir->GetPath());
4677 if (NULL != hCorDelTof) {
4678 TH1D* hCorDelTofout = (TH1D*) hCorDelTof->Clone(
4679 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
4680 hCorDelTofout->Write();
4681 }
4682 else {
4683 LOG(debug) << " No CorDelTof histo "
4684 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel);
4685 }
4686 }
4687
4688 LOG(debug) << " Store old walk histos to file ";
4689 // store walk histos
4690 for (Int_t iCh = 0; iCh < iNbCh; iCh++) // restore old values
4691 {
4692 if (NULL == fhRpcCluWalk[iDetIndx][iCh][0]) break;
4693 // TProfile *htmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
4694 // TProfile *htmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProfileX("_pfx",1,nbClWalkBinY); (VF) not used
4695 TH1D* h1tmp0 = fhRpcCluWalk[iDetIndx][iCh][0]->ProjectionX("_px", 1, nbClWalkBinY);
4696 TH1D* h1tmp1 = fhRpcCluWalk[iDetIndx][iCh][1]->ProjectionX("_px", 1, nbClWalkBinY);
4697 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
4698 h1tmp0->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]);
4699 h1tmp1->SetBinContent(iWx + 1, fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iWx]);
4700 if (h1tmp0->GetBinContent(iWx + 1) != fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx]) {
4701 LOG(error) << "WriteHistos: restore unsuccessful! iWx " << iWx << " got "
4702 << h1tmp0->GetBinContent(iWx + 1) << ", expected "
4703 << fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iWx];
4704 }
4705 }
4706 h1tmp0->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
4707 // htmp0->Write();
4708 h1tmp0->Write();
4709 h1tmp1->SetName(Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
4710 // htmp1->Write();
4711 h1tmp1->Write();
4712 }
4713 } break;
4714
4715 default: LOG(debug) << "WriteHistos: update mode " << fCalMode << " not yet implemented";
4716 }
4717 }
4718
4719 // fhCluMulCorDutSel->Write();
4720
4721 // fhDigSpacDifClust->Write();
4722 // fhDigTimeDifClust->Write();
4723 // fhDigDistClust->Write();
4724
4725 // fhClustSizeDifX->Write();
4726 // fhClustSizeDifY->Write();
4727
4728 // fhChDifDifX->Write();
4729 // fhChDifDifY->Write();
4730
4731 // fhNbSameSide->Write();
4732 // fhNbDigiPerChan->Write();
4733
4734 // fhHitsPerTracks->Write();
4735 if (kFALSE == fDigiBdfPar->ClustUseTrackId())
4736 // fhPtsPerHit->Write();
4737 // fhTimeResSingHits->Write();
4738 // fhTimeResSingHitsB->Write();
4739 // fhTimePtVsHits->Write();
4740 // fhClusterSize->Write();
4741 // fhClusterSizeType->Write();
4742 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
4743 // fhTrackMul->Write();
4744 // fhClusterSizeMulti->Write();
4745 // fhTrk1MulPos->Write();
4746 // fhHiTrkMulPos->Write();
4747 // fhAllTrkMulPos->Write();
4748 // fhMultiTrkProbPos->Divide( fhHiTrkMulPos, fhAllTrkMulPos);
4749 // fhMultiTrkProbPos->Scale( 100.0 );
4750 // fhMultiTrkProbPos->Write();
4751 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
4752
4753 for (Int_t iS = 0; iS < fDigiBdfPar->GetNbSmTypes(); iS++) {
4754 if (NULL == fhSmCluPosition[iS]) continue;
4755 // fhSmCluPosition[iS]->Write();
4756 // fhSmCluTOff[iS]->Write();
4757 fhSmCluSvel[iS]->Write();
4758 for (Int_t iPar = 0; iPar < 4; iPar++)
4759 fhSmCluFpar[iS][iPar]->Write();
4760
4761 for (Int_t iSel = 0; iSel < iNSel; iSel++) { // Loop over selectors
4762 // fhTSmCluPosition[iS][iSel]->Write();
4763 // fhTSmCluTOff[iS][iSel]->Write();
4764 // fhTSmCluTRun[iS][iSel]->Write();
4765 }
4766 }
4767
4769 gFile = oldFile;
4770 gDirectory = oldDir;
4771
4772 fHist->Close();
4773
4774 return kTRUE;
4775}
4777{
4778 delete fhClustBuildTime;
4779 delete fhHitsPerTracks;
4780 delete fhPtsPerHit;
4781 delete fhTimeResSingHits;
4782 delete fhTimeResSingHitsB;
4783 delete fhTimePtVsHits;
4784 delete fhClusterSize;
4785 delete fhClusterSizeType;
4786
4787 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
4788 delete fhTrackMul;
4789 delete fhClusterSizeMulti;
4790 delete fhTrk1MulPos;
4791 delete fhHiTrkMulPos;
4792 delete fhAllTrkMulPos;
4793 delete fhMultiTrkProbPos;
4794 }
4795 delete fhDigSpacDifClust;
4796 delete fhDigTimeDifClust;
4797 delete fhDigDistClust;
4798
4799 delete fhClustSizeDifX;
4800 delete fhClustSizeDifY;
4801
4802 delete fhChDifDifX;
4803 delete fhChDifDifY;
4804
4805 delete fhNbSameSide;
4806 delete fhNbDigiPerChan;
4807
4808 return kTRUE;
4809}
4810/************************************************************************************/
4812{
4813 Int_t iMess = 0;
4814 //gGeoManager->SetTopVolume( gGeoManager->FindVolumeFast("tof_v14a") );
4815 gGeoManager->CdTop();
4816
4817 // if(NULL == fTofDigisColl) {
4818 if (fTofDigiVec.empty()) {
4819 LOG(info) << " No RawDigis defined ! Check! ";
4820 return kFALSE;
4821 }
4822 fiNevtBuild++;
4823
4824 LOG(debug) << "Build clusters from "
4825 // <<fTofDigisColl->GetEntriesFast()<<" digis in event "<<fiNevtBuild;
4826 << fTofDigiVec.size() << " digis in event " << fiNevtBuild;
4827
4828 fTRefHits = 0.;
4829
4830 Int_t iNbTofDigi = fTofDigiVec.size();
4831 //Int_t iNbTofDigi = fTofDigisColl->GetEntriesFast();
4832 if (iNbTofDigi > 100000) {
4833 LOG(warning) << "Too many TOF digis in event " << fiNevtBuild;
4834 return kFALSE;
4835 }
4837 // Duplicate type "5" - digis
4838 // Int_t iNbDigi=iNbTofDigi;
4839 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
4840 CbmTofDigi* pDigi = &(fTofDigiVec.at(iDigInd));
4841 //CbmTofDigi *pDigi = (CbmTofDigi*) fTofDigisColl->At( iDigInd );
4842 if (pDigi->GetType() == 5) { // || pDigi->GetType() == 8) {
4843 if (pDigi->GetSide() == 1) {
4844 bAddBeamCounterSideDigi = kFALSE; // disable for current data set
4845 LOG(info) << "Start counter digi duplication disabled";
4846 break;
4847 }
4848 fTofDigiVec.push_back(CbmTofDigi(*pDigi));
4849 CbmTofDigi* pDigiN = &(fTofDigiVec.back());
4850 // CbmTofDigi *pDigiN = new((*fTofDigisColl)[iNbDigi++]) CbmTofDigi( *pDigi );
4851 pDigiN->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi->GetChannel(), (0 == pDigi->GetSide()) ? 1 : 0,
4852 pDigi->GetType());
4853 LOG(debug) << "Duplicated digi " << fTofDigiVec.size() << " with address 0x" << std::hex
4854 << pDigiN->GetAddress();
4855
4856 if (NULL != fTofDigiPointMatches) { // copy MC Match Object
4857 const CbmMatch digiMatch = (CbmMatch) fTofDigiPointMatches->at(iDigInd);
4858 ((std::vector<CbmMatch>*) fTofDigiPointMatches)->push_back((CbmMatch) digiMatch);
4859 }
4860 }
4861 }
4862 iNbTofDigi = fTofDigiVec.size();
4863 }
4864
4865 if (kTRUE) {
4866 for (UInt_t iDetIndx = 0; iDetIndx < fvTimeFirstDigi.size(); iDetIndx++)
4867 for (UInt_t iCh = 0; iCh < fvTimeFirstDigi[iDetIndx].size(); iCh++) {
4868 fvTimeFirstDigi[iDetIndx][iCh] = 0.;
4869 fvMulDigi[iDetIndx][iCh] = 0.;
4870 }
4871
4872 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
4873 //CbmTofDigi *pDigi = (CbmTofDigi*) fTofDigisColl->At( iDigInd );
4874 CbmTofDigi* pDigi = &(fTofDigiVec.at(iDigInd));
4875 Int_t iDetIndx = fDigiBdfPar->GetDetInd(pDigi->GetAddress() & DetMask);
4876
4877 LOG(debug) << "RawDigi" << iDigInd << " " << pDigi << Form(" Address : 0x%08x ", pDigi->GetAddress()) << " TSRCS "
4878 << pDigi->GetType() << pDigi->GetSm() << pDigi->GetRpc() << pDigi->GetChannel() << pDigi->GetSide()
4879 << ", DetIndx " << iDetIndx << " : " << pDigi->ToString()
4880 // <<" Time "<<pDigi->GetTime()
4881 // <<" Tot " <<pDigi->GetTot()
4882 ;
4883
4884 if (fDigiBdfPar->GetNbDet() - 1 < iDetIndx || iDetIndx < 0) {
4885 LOG(debug) << Form(" Wrong DetIndx %d >< %d ", iDetIndx, fDigiBdfPar->GetNbDet());
4886 break;
4887 }
4888
4889 CbmTofDigi* pDigi2Min = NULL;
4890 Double_t dTDifMin = dDoubleMax;
4891
4892 if (fDutId > -1) {
4893 if (fhRpcDigiCor.size() > 0) {
4894 if (NULL == fhRpcDigiCor[iDetIndx]) {
4895 if (100 < iMess++)
4896 LOG(warning) << Form(" DigiCor Histo for DetIndx %d derived from 0x%08x not found", iDetIndx,
4897 pDigi->GetAddress());
4898 continue;
4899 }
4900 }
4901 else
4902 break;
4903
4904 if (fdStartAnalysisTime > 0) {
4905 Double_t dTimeAna = (pDigi->GetTime() + dTsStartTime - fdStartAnalysisTime) / 1.E9;
4906 fhRpcDigiRate[iDetIndx]->Fill(dTimeAna, 1. / fhRpcDigiRate[iDetIndx]->GetBinWidth(1));
4907 }
4908
4909 size_t iDigiCh = pDigi->GetChannel() * 2 + pDigi->GetSide();
4910 if (iDigiCh < fvTimeLastDigi[iDetIndx].size()) {
4911 if (fvTimeLastDigi[iDetIndx][iDigiCh] > 0) {
4912 if (kTRUE) { // fdStartAna10s > 0.) {
4913 //Double_t dTimeAna10s = (pDigi->GetTime() - fdStartAna10s) / 1.E9;
4914 //if (dTimeAna10s < fdSpillDuration)
4915 fhRpcDigiDTLD[iDetIndx]->Fill(iDigiCh, (pDigi->GetTime() - fvTimeLastDigi[iDetIndx][iDigiCh]));
4916 }
4917 }
4918 fvTimeLastDigi[iDetIndx][iDigiCh] = pDigi->GetTime();
4919
4920 if (fvTimeFirstDigi[iDetIndx][iDigiCh] != 0.) {
4921 fhRpcDigiDTFD[iDetIndx]->Fill(iDigiCh, (pDigi->GetTime() - fvTimeFirstDigi[iDetIndx][iDigiCh]));
4922 fvMulDigi[iDetIndx][iDigiCh]++;
4923 }
4924 else {
4925 fvTimeFirstDigi[iDetIndx][iDigiCh] = pDigi->GetTime();
4926 fvMulDigi[iDetIndx][iDigiCh]++;
4927 }
4928 }
4929
4930 // for (Int_t iDigI2 =iDigInd+1; iDigI2<iNbTofDigi;iDigI2++){
4931 for (Int_t iDigI2 = 0; iDigI2 < iNbTofDigi; iDigI2++) {
4932 CbmTofDigi* pDigi2 = &(fTofDigiVec.at(iDigI2));
4933 // CbmTofDigi *pDigi2 = (CbmTofDigi*) fTofDigisColl->At( iDigI2 );
4934 // Fill digi correlation histogram per counter
4935 if (iDetIndx == fDigiBdfPar->GetDetInd(pDigi2->GetAddress())) {
4936 if (0. == pDigi->GetSide() && 1. == pDigi2->GetSide()) {
4937 fhRpcDigiCor[iDetIndx]->Fill(pDigi->GetChannel(), pDigi2->GetChannel());
4938 }
4939 else {
4940 if (1. == pDigi->GetSide() && 0. == pDigi2->GetSide()) {
4941 fhRpcDigiCor[iDetIndx]->Fill(pDigi2->GetChannel(), pDigi->GetChannel());
4942 }
4943 }
4944 if (pDigi->GetSide() != pDigi2->GetSide()) {
4945 if (pDigi->GetChannel() == pDigi2->GetChannel()) {
4946 Double_t dTDif = TMath::Abs(pDigi->GetTime() - pDigi2->GetTime());
4947 if (dTDif < dTDifMin) {
4948 dTDifMin = dTDif;
4949 pDigi2Min = pDigi2;
4950 }
4951 }
4952 else if (TMath::Abs(pDigi->GetChannel() - pDigi2->GetChannel())
4953 == 1) { // opposite side missing, neighbouring channel has hit on opposite side // FIXME
4954 // check that same side digi of neighbouring channel is absent
4955 Int_t iDigI3 = 0;
4956 for (; iDigI3 < iNbTofDigi; iDigI3++) {
4957 CbmTofDigi* pDigi3 = &(fTofDigiVec.at(iDigI3));
4958 // CbmTofDigi *pDigi3 = (CbmTofDigi*) fTofDigisColl->At( iDigI3 );
4959 if (pDigi3->GetSide() == pDigi->GetSide() && pDigi2->GetChannel() == pDigi3->GetChannel()) break;
4960 }
4961 if (iDigI3 == iNbTofDigi) // same side neighbour did not fire
4962 {
4963 Int_t iCorMode = 0; // Missing hit correction mode
4964 switch (iCorMode) {
4965 case 0: // no action
4966 break;
4967 case 1: // shift found hit
4968 LOG(debug2) << Form("shift channel %d%d%d%d%d and ", (Int_t) pDigi->GetType(),
4969 (Int_t) pDigi->GetSm(), (Int_t) pDigi->GetRpc(), (Int_t) pDigi->GetChannel(),
4970 (Int_t) pDigi->GetSide())
4971 << Form(" %d%d%d%d%d ", (Int_t) pDigi2->GetType(), (Int_t) pDigi2->GetSm(),
4972 (Int_t) pDigi2->GetRpc(), (Int_t) pDigi2->GetChannel(),
4973 (Int_t) pDigi2->GetSide());
4974 //if(pDigi->GetTime() < pDigi2->GetTime())
4975 if (pDigi->GetSide() == 0)
4976 pDigi2->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi->GetChannel(), 1 - pDigi->GetSide(),
4977 pDigi->GetType());
4978 else
4979 pDigi->SetAddress(pDigi2->GetSm(), pDigi2->GetRpc(), pDigi2->GetChannel(),
4980 1 - pDigi2->GetSide(), pDigi2->GetType());
4981
4982 LOG(debug2) << Form("resultchannel %d%d%d%d%d and ", (Int_t) pDigi->GetType(),
4983 (Int_t) pDigi->GetSm(), (Int_t) pDigi->GetRpc(), (Int_t) pDigi->GetChannel(),
4984 (Int_t) pDigi->GetSide())
4985 << Form(" %d%d%d%d%d ", (Int_t) pDigi2->GetType(), (Int_t) pDigi2->GetSm(),
4986 (Int_t) pDigi2->GetRpc(), (Int_t) pDigi2->GetChannel(),
4987 (Int_t) pDigi2->GetSide());
4988 break;
4989 case 2: // insert missing hits
4990 fTofDigiVec.push_back(CbmTofDigi(*pDigi));
4991 CbmTofDigi* pDigiN = &(fTofDigiVec.back());
4992 // CbmTofDigi *pDigiN = new((*fTofDigisColl)[iNbTofDigi++]) CbmTofDigi( *pDigi );
4993 pDigiN->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi2->GetChannel(), pDigi->GetSide(),
4994 pDigi->GetType());
4995 pDigiN->SetTot(pDigi2->GetTot());
4996
4997 fTofDigiVec.push_back(CbmTofDigi(*pDigi2));
4998 CbmTofDigi* pDigiN2 = &(fTofDigiVec.back());
4999 // CbmTofDigi *pDigiN2 = new((*fTofDigisColl)[iNbTofDigi++]) CbmTofDigi( *pDigi2 );
5000 pDigiN2->SetAddress(pDigi2->GetSm(), pDigi2->GetRpc(), pDigi->GetChannel(), pDigi2->GetSide(),
5001 pDigi2->GetType());
5002 pDigiN2->SetTot(pDigi->GetTot());
5003
5004 break;
5005 }
5006 }
5007 }
5008 }
5009 }
5010 }
5011 }
5012
5013 if (pDigi2Min != NULL) {
5014 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, pDigi->GetType(), pDigi->GetSm(), pDigi->GetRpc(), 0,
5015 pDigi->GetChannel());
5016 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
5017 fChannelInfo = fDigiPar->GetCell(iChId);
5018 if (NULL == fChannelInfo) {
5019 LOG(warning) << Form("BuildClusters: invalid ChannelInfo for 0x%08x", iChId);
5020 continue;
5021 }
5022 if (fDigiBdfPar->GetSigVel(pDigi->GetType(), pDigi->GetSm(), pDigi->GetRpc()) * dTDifMin * 0.5
5024 //check consistency
5025 if (8 == pDigi->GetType() || 5 == pDigi->GetType()) {
5026 if (pDigi->GetTime() != pDigi2Min->GetTime()) {
5027 if (fiMsgCnt-- > 0) {
5028 LOG(warning) << " BuildClusters: Inconsistent duplicated digis in event " << fiNevtBuild
5029 << ", Ind: " << iDigInd; // << "CTyp: " << pDigi->GetCounterType;
5030 LOG(warning) << " " << pDigi->ToString();
5031 LOG(warning) << " " << pDigi2Min->ToString();
5032 }
5033 pDigi2Min->SetTot(pDigi->GetTot());
5034 pDigi2Min->SetTime(pDigi->GetTime());
5035 }
5036 }
5037
5038 // average ToTs! temporary fix, FIXME
5039 /*
5040 Double_t dAvTot=0.5*(pDigi->GetTot()+pDigi2Min->GetTot());
5041 pDigi->SetTot(dAvTot);
5042 pDigi2Min->SetTot(dAvTot);
5043 LOG(debug)<<" BuildClusters: TDif "<<dTDifMin<<", Average Tot "<<dAvTot;
5044 LOG(debug)<<" "<<pDigi->ToString() ;
5045 LOG(debug)<<" "<<pDigi2Min->ToString() ;
5046 */
5047 }
5048 }
5049 }
5050 for (UInt_t iDetIndx = 0; iDetIndx < fvTimeFirstDigi.size(); iDetIndx++)
5051 for (UInt_t iCh = 0; iCh < fvTimeFirstDigi[iDetIndx].size(); iCh++) {
5052 if (fvTimeFirstDigi[iDetIndx][iCh] != 0.) fhRpcDigiDTMul[iDetIndx]->Fill(iCh, fvMulDigi[iDetIndx][iCh]);
5053 }
5054 } // kTRUE end
5055
5056 // Calibrate RawDigis
5057 if (kTRUE) {
5058 CbmTofDigi* pDigi;
5059 // CbmTofDigi *pCalDigi=NULL; (VF) not used
5060 CalibRawDigis();
5061
5062 // Then loop over the digis array and store the Digis in separate vectors for
5063 // each RPC modules
5064
5065 // iNbTofDigi = fTofCalDigisColl->GetEntriesFast();
5066 iNbTofDigi = fTofCalDigiVec->size();
5067 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
5068 // pDigi = (CbmTofDigi*) fTofCalDigisColl->At( iDigInd );
5069 pDigi = &(fTofCalDigiVec->at(iDigInd));
5070 LOG(debug1) << "AC " // After Calibration
5071 << Form("0x%08x", pDigi->GetAddress()) << " TSRC " << pDigi->GetType() << pDigi->GetSm()
5072 << pDigi->GetRpc() << Form("%2d", (Int_t) pDigi->GetChannel()) << " " << pDigi->GetSide() << " "
5073 << Form("%f", pDigi->GetTime()) << " " << pDigi->GetTot();
5074
5075 if (fDigiBdfPar->GetNbSmTypes() > pDigi->GetType() // prevent crash due to misconfiguration
5076 && fDigiBdfPar->GetNbSm(pDigi->GetType()) > pDigi->GetSm()
5077 && fDigiBdfPar->GetNbRpc(pDigi->GetType()) > pDigi->GetRpc()
5078 && fDigiBdfPar->GetNbChan(pDigi->GetType(), pDigi->GetRpc()) > pDigi->GetChannel()) {
5079 fStorDigi[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType()) + pDigi->GetRpc()]
5080 [pDigi->GetChannel()]
5081 .push_back(pDigi);
5082 fStorDigiInd[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType()) + pDigi->GetRpc()]
5083 [pDigi->GetChannel()]
5084 .push_back(iDigInd);
5085 }
5086 else {
5087 if (fiNbSkip2 < 20) {
5088 LOG(info) << "Skip2 Digi "
5089 << " Type " << pDigi->GetType() << " " << fDigiBdfPar->GetNbSmTypes() << " Sm " << pDigi->GetSm()
5090 << " " << fDigiBdfPar->GetNbSm(pDigi->GetType()) << " Rpc " << pDigi->GetRpc() << " "
5091 << fDigiBdfPar->GetNbRpc(pDigi->GetType()) << " Ch " << pDigi->GetChannel() << " "
5092 << fDigiBdfPar->GetNbChan(pDigi->GetType(), 0);
5093 }
5094 ++fiNbSkip2;
5095 }
5096 } // for( Int_t iDigInd = 0; iDigInd < nTofDigi; iDigInd++ )
5097
5098 // inspect digi array
5099 if (fDutId > -1) {
5100 Int_t iNbDet = fDigiBdfPar->GetNbDet();
5101 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
5102 Int_t iDetId = fviDetId[iDetIndx];
5103 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
5104 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
5105 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
5106 Int_t iNbStrips = fDigiBdfPar->GetNbChan(iSmType, iRpc);
5107 for (Int_t iStrip = 0; iStrip < iNbStrips; iStrip++) {
5108 Int_t iDigiMul = fStorDigi[iSmType][iSm * fDigiBdfPar->GetNbRpc(iSmType) + iRpc][iStrip].size();
5109 //LOG(info)<<"Inspect TSRC "<<iSmType<<iSm<<iRpc<<iStrip<<" with "<<iNbStrips<<" strips: Mul "<<iDigiMul;
5110 if (iDigiMul > 0) {
5111 fhRpcDigiMul[iDetIndx]->Fill(iStrip, iDigiMul);
5112 if (iDigiMul == 1) {
5113 fhRpcDigiStatus[iDetIndx]->Fill(iStrip, 0);
5114 if (iStrip > 0)
5115 if (fStorDigi[iSmType][iSm * fDigiBdfPar->GetNbRpc(iSmType) + iRpc][iStrip - 1].size() > 1) {
5116 fhRpcDigiStatus[iDetIndx]->Fill(iStrip, 1);
5117 if (TMath::Abs(
5118 fStorDigi[iSmType][iSm * fDigiBdfPar->GetNbRpc(iSmType) + iRpc][iStrip][0]->GetTime()
5119 - fStorDigi[iSmType][iSm * fDigiBdfPar->GetNbRpc(iSmType) + iRpc][iStrip - 1][0]->GetTime())
5120 < fMaxTimeDist)
5121 fhRpcDigiStatus[iDetIndx]->Fill(iStrip, 3);
5122 }
5123 if (iStrip < iNbStrips - 2) {
5124 if (fStorDigi[iSmType][iSm * fDigiBdfPar->GetNbRpc(iSmType) + iRpc][iStrip + 1].size() > 1) {
5125 fhRpcDigiStatus[iDetIndx]->Fill(iStrip, 2);
5126 if (TMath::Abs(
5127 fStorDigi[iSmType][iSm * fDigiBdfPar->GetNbRpc(iSmType) + iRpc][iStrip][0]->GetTime()
5128 - fStorDigi[iSmType][iSm * fDigiBdfPar->GetNbRpc(iSmType) + iRpc][iStrip + 1][0]->GetTime())
5129 < fMaxTimeDist)
5130 fhRpcDigiStatus[iDetIndx]->Fill(iStrip, 4);
5131 }
5132 }
5133 }
5134 }
5135 }
5136 }
5137 }
5138
5139 BuildHits();
5140 CalibHits();
5141 } // if( kTRUE ) obsolete )
5142
5143 return kTRUE;
5144}
5145
5147{
5148 // Merge clusters from neigbouring Rpc within a (Super)Module
5149 if (NULL == fTofHitsColl) {
5150 LOG(info) << " No Hits defined ! Check! ";
5151 return kFALSE;
5152 }
5153 // inspect hits
5154 for (Int_t iHitInd = 0; iHitInd < fTofHitsColl->GetEntriesFast(); iHitInd++) {
5155 CbmTofHit* pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
5156 if (NULL == pHit) continue;
5157
5158 Int_t iDetId = (pHit->GetAddress() & DetMask);
5159 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
5160 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
5161 if (iSmType != 5 && iSmType != 8) continue; // only merge diamonds and Pad
5162 LOG(debug) << "MergeClusters: in SmT " << iSmType << " for " << iNbRpc << " Rpcs";
5163
5164 if (iNbRpc > 1) { // check for possible mergers
5165 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
5166 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
5167 Int_t iChId = pHit->GetAddress();
5168 fChannelInfo = fDigiPar->GetCell(iChId);
5170 LOG(debug) << "MergeClusters: Check for mergers in "
5171 << Form(" SmT %d, Sm %d, Rpc %d, Ch %d - hit %d", iSmType, iSm, iRpc, iCh, iHitInd);
5172 for (Int_t iHitInd2 = iHitInd + 1; iHitInd2 < fTofHitsColl->GetEntriesFast(); iHitInd2++) {
5173 CbmTofHit* pHit2 = (CbmTofHit*) fTofHitsColl->At(iHitInd2);
5174 if (NULL == pHit2) continue;
5175 Int_t iDetId2 = (pHit2->GetAddress() & DetMask);
5176 Int_t iSmType2 = CbmTofAddress::GetSmType(iDetId2);
5177 if (iSmType2 == iSmType) {
5178 Int_t iSm2 = CbmTofAddress::GetSmId(iDetId2);
5179 if (iSm2 == iSm || iSmType == 5) {
5180 Int_t iRpc2 = CbmTofAddress::GetRpcId(iDetId2);
5181 if (TMath::Abs(iRpc - iRpc2) == 1 || iSm2 != iSm) { // Found neighbour
5182 Int_t iChId2 = pHit2->GetAddress();
5183 // CbmTofCell *fChannelInfo2 = fDigiPar->GetCell( iChId2 ); (VF) not used
5184 Int_t iCh2 = CbmTofAddress::GetChannelId(iChId2);
5185 Double_t xPos = pHit->GetX();
5186 Double_t yPos = pHit->GetY();
5187 Double_t tof = pHit->GetTime();
5188 Double_t xPos2 = pHit2->GetX();
5189 Double_t yPos2 = pHit2->GetY();
5190 Double_t tof2 = pHit2->GetTime();
5191 LOG(debug) << "MergeClusters: Found hit in neighbour "
5192 << Form(" SmT %d, Sm %d, Rpc %d, Ch %d - hit %d", iSmType2, iSm2, iRpc2, iCh2, iHitInd2)
5193 << Form(" DX %6.1f, DY %6.1f, DT %6.1f", xPos - xPos2, yPos - yPos2, tof - tof2);
5194
5195 if (TMath::Abs(xPos - xPos2) < fdCaldXdYMax * 2. && TMath::Abs(yPos - yPos2) < fdCaldXdYMax * 2.
5196 && TMath::Abs(tof - tof2) < fMaxTimeDist) {
5197
5198 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
5199 Double_t dTot = 0;
5200 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
5201 CbmLink L0 = digiMatch->GetLink(iLink);
5202 UInt_t iDigInd0 = L0.GetIndex();
5203 UInt_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex();
5204 // if (iDigInd0 < fTofCalDigisColl->GetEntriesFast() && iDigInd1 < fTofCalDigisColl->GetEntriesFast()){
5205 if (iDigInd0 < fTofCalDigiVec->size() && iDigInd1 < fTofCalDigiVec->size()) {
5206 // CbmTofDigi *pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
5207 // CbmTofDigi *pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
5208 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
5209 CbmTofDigi* pDig1 = &(fTofCalDigiVec->at(iDigInd1));
5210 dTot += pDig0->GetTot();
5211 dTot += pDig1->GetTot();
5212 }
5213 }
5214
5215 CbmMatch* digiMatch2 = (CbmMatch*) fTofDigiMatchColl->At(iHitInd2);
5216 Double_t dTot2 = 0;
5217 for (Int_t iLink = 0; iLink < digiMatch2->GetNofLinks(); iLink += 2) { // loop over digis
5218 CbmLink L0 = digiMatch2->GetLink(iLink);
5219 UInt_t iDigInd0 = L0.GetIndex();
5220 UInt_t iDigInd1 = (digiMatch2->GetLink(iLink + 1)).GetIndex();
5221 // if (iDigInd0 < fTofCalDigisColl->GetEntriesFast() && iDigInd1 < fTofCalDigisColl->GetEntriesFast()){
5222 if (iDigInd0 < fTofCalDigiVec->size() && iDigInd1 < fTofCalDigiVec->size()) {
5223 // CbmTofDigi *pDig0 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd0));
5224 // CbmTofDigi *pDig1 = (CbmTofDigi*) (fTofCalDigisColl->At(iDigInd1));
5225 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
5226 CbmTofDigi* pDig1 = &(fTofCalDigiVec->at(iDigInd1));
5227 dTot2 += pDig0->GetTot();
5228 dTot2 += pDig1->GetTot();
5229 digiMatch->AddLink(CbmLink(pDig0->GetTot(), iDigInd0, fiOutputTreeEntry, fiFileIndex));
5230 digiMatch->AddLink(CbmLink(pDig1->GetTot(), iDigInd1, fiOutputTreeEntry, fiFileIndex));
5231 }
5232 }
5233 LOG(debug) << "MergeClusters: Found merger in neighbour "
5234 << Form(" SmT %d, Sm %d, Rpc %d, Ch %d - hit %d(%d)", iSmType2, iSm2, iRpc2, iCh2, iHitInd2,
5235 fTofHitsColl->GetEntriesFast())
5236 << Form(" DX %6.1f, DY %6.1f, DT %6.1f", xPos - xPos2, yPos - yPos2, tof - tof2)
5237 << Form(" Tots %6.1f - %6.1f", dTot, dTot2);
5238 Double_t dTotSum = dTot + dTot2;
5239 Double_t dxPosM = (xPos * dTot + xPos2 * dTot2) / dTotSum;
5240 Double_t dyPosM = (yPos * dTot + yPos2 * dTot2) / dTotSum;
5241 Double_t dtofM = (tof * dTot + tof2 * dTot2) / dTotSum;
5242 pHit->SetX(dxPosM);
5243 pHit->SetY(dyPosM);
5244 pHit->SetTime(dtofM);
5245
5246 // remove merged hit at iHitInd2 and update digiMatch
5247
5248 fTofHitsColl->RemoveAt(iHitInd2);
5249 fTofDigiMatchColl->RemoveAt(iHitInd2);
5250 fTofDigiMatchColl->Compress();
5251 fTofHitsColl->Compress();
5252 LOG(debug) << "MergeClusters: Compress TClonesArrays to " << fTofHitsColl->GetEntriesFast() << ", "
5253 << fTofDigiMatchColl->GetEntriesFast();
5254 /*
5255 for(Int_t i=iHitInd2; i<fTofHitsColl->GetEntriesFast(); i++){ // update RefLinks
5256 CbmTofHit *pHiti = (CbmTofHit*) fTofHitsColl->At( i );
5257 pHiti->SetRefId(i);
5258 }
5259 */
5260 //check merged hit (cluster)
5261 //pHit->Print();
5262 }
5263 }
5264 }
5265 }
5266 }
5267 }
5268 }
5269 return kTRUE;
5270}
5271
5272static Double_t f1_xboxe(double* x, double* par)
5273{
5274 double xx = x[0];
5275 double wx = 1. - par[4] * TMath::Power(xx + par[5], 2);
5276 double xboxe = par[0] * 0.25 * (1. + TMath::Erf((xx + par[1] - par[3]) / par[2]))
5277 * (1. + TMath::Erf((-xx + par[1] + par[3]) / par[2]));
5278 return xboxe * wx;
5279}
5280
5282{
5283 TH1* h1;
5284 h1 = (TH1*) gROOT->FindObjectAny(hname);
5285 if (NULL != h1) {
5286 fit_ybox(h1, 0.);
5287 }
5288}
5289
5290void CbmTofEventClusterizer::fit_ybox(TH1* h1, Double_t ysize)
5291{
5292 Double_t* fpar = NULL;
5293 fit_ybox(h1, ysize, fpar);
5294}
5295
5296void CbmTofEventClusterizer::fit_ybox(TH1* h1, Double_t ysize, Double_t* fpar = NULL)
5297{
5298 TAxis* xaxis = h1->GetXaxis();
5299 Double_t Ymin = xaxis->GetXmin();
5300 Double_t Ymax = xaxis->GetXmax();
5301 TF1* f1 = new TF1("YBox", f1_xboxe, Ymin, Ymax, 6);
5302 Double_t yini = (h1->GetMaximum() + h1->GetMinimum()) * 0.5;
5303 Double_t dLini = Ymax * 0.75;
5304 Double_t dLerr = 0.;
5305 if (ysize != 0.) {
5306 dLini = ysize * 0.5;
5307 dLerr = dLini * 0.05;
5308 }
5309 f1->SetParameters(yini, dLini, 2., -1., 0., 0.);
5310 if (dLerr > 0.) f1->SetParLimits(1, dLini - dLerr, dLini + dLerr);
5311 f1->SetParLimits(2, 0.2, 3.);
5312 f1->SetParLimits(3, -3., 3.);
5313 f1->SetParLimits(5, -50., 50.);
5314 if (fpar != NULL) {
5315 f1->SetParLimits(1, ysize * 0.5, ysize * 0.5);
5316 Double_t fp[4];
5317 for (Int_t i = 0; i < 4; i++)
5318 fp[i] = *fpar++;
5319 for (Int_t i = 0; i < 4; i++)
5320 f1->SetParameter(2 + i, fp[i]);
5321 LOG(debug) << "Ini Fpar for " << h1->GetName() << " with "
5322 << Form(" %6.3f %6.3f %6.3f %6.3f ", fp[0], fp[1], fp[2], fp[3]);
5323 }
5324 h1->Fit("YBox", "QM0");
5325
5326 double res[10];
5327 double err[10];
5328 res[9] = f1->GetChisquare();
5329
5330 for (int i = 0; i < 6; i++) {
5331 res[i] = f1->GetParameter(i);
5332 err[i] = f1->GetParError(i);
5333 //cout << " FPar "<< i << ": " << res[i] << ", " << err[i] << endl;
5334 }
5335 LOG(debug) << "YBox Fit of " << h1->GetName() << " ended with chi2 = " << res[9]
5336 << Form(", strip length %7.2f +/- %5.2f, position resolution "
5337 "%7.2f +/- %5.2f at y_cen = %7.2f +/- %5.2f",
5338 2. * res[1], 2. * err[1], res[2], err[2], res[3], err[3]);
5339}
5340
5342{
5343 if (fvLastHits.size() != static_cast<size_t>(fDigiBdfPar->GetNbSmTypes()))
5344 LOG(fatal) << Form("Inconsistent LH Smtype size %lu, %d ", fvLastHits.size(), fDigiBdfPar->GetNbSmTypes());
5345
5346 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
5347 if (fvLastHits[iSmType].size() != static_cast<size_t>(fDigiBdfPar->GetNbSm(iSmType)))
5348 LOG(fatal) << Form("Inconsistent LH Sm size %lu, %d T %d", fvLastHits[iSmType].size(),
5349 fDigiBdfPar->GetNbSm(iSmType), iSmType);
5350 for (Int_t iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); iSm++) {
5351 if (fvLastHits[iSmType][iSm].size() != static_cast<size_t>(fDigiBdfPar->GetNbRpc(iSmType)))
5352 LOG(fatal) << Form("Inconsistent LH Rpc size %lu, %d TS %d%d ", fvLastHits[iSmType][iSm].size(),
5353 fDigiBdfPar->GetNbRpc(iSmType), iSmType, iSm);
5354 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
5355 if (fvLastHits[iSmType][iSm][iRpc].size() != static_cast<size_t>(fDigiBdfPar->GetNbChan(iSmType, iRpc)))
5356 LOG(fatal) << Form("Inconsistent LH RpcChannel size %lu, %d TSR %d%d%d ",
5357 fvLastHits[iSmType][iSm][iRpc].size(), fDigiBdfPar->GetNbChan(iSmType, iRpc), iSmType, iSm,
5358 iRpc);
5359 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++)
5360 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 0) {
5361 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
5362 Int_t iAddr = fTofId->SetDetectorInfo(xDetInfo);
5363 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != iAddr)
5364 LOG(fatal) << Form("Inconsistent address for Ev %8.0f in list of size %lu for "
5365 "TSRC %d%d%d%d: 0x%08x, time %f",
5366 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
5367 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
5368 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
5369 }
5370 }
5371 }
5372 }
5373 LOG(debug) << Form("LH check passed for event %8.0f", fdEvent);
5374}
5375
5377{
5378 if (fvLastHits.size() != static_cast<size_t>(fDigiBdfPar->GetNbSmTypes()))
5379 LOG(fatal) << Form("Inconsistent LH Smtype size %lu, %d ", fvLastHits.size(), fDigiBdfPar->GetNbSmTypes());
5380 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
5381 if (fvLastHits[iSmType].size() != static_cast<size_t>(fDigiBdfPar->GetNbSm(iSmType)))
5382 LOG(fatal) << Form("Inconsistent LH Sm size %lu, %d T %d", fvLastHits[iSmType].size(),
5383 fDigiBdfPar->GetNbSm(iSmType), iSmType);
5384 for (Int_t iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); iSm++) {
5385 if (fvLastHits[iSmType][iSm].size() != static_cast<size_t>(fDigiBdfPar->GetNbRpc(iSmType)))
5386 LOG(fatal) << Form("Inconsistent LH Rpc size %lu, %d TS %d%d ", fvLastHits[iSmType][iSm].size(),
5387 fDigiBdfPar->GetNbRpc(iSmType), iSmType, iSm);
5388 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
5389 if (fvLastHits[iSmType][iSm][iRpc].size() != static_cast<size_t>(fDigiBdfPar->GetNbChan(iSmType, iRpc)))
5390 LOG(fatal) << Form("Inconsistent LH RpcChannel size %lu, %d TSR %d%d%d ",
5391 fvLastHits[iSmType][iSm][iRpc].size(), fDigiBdfPar->GetNbChan(iSmType, iRpc), iSmType, iSm,
5392 iRpc);
5393 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++)
5394 while (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 0) {
5395 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
5396 Int_t iAddr = fTofId->SetDetectorInfo(xDetInfo);
5397 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != iAddr)
5398 LOG(fatal) << Form("Inconsistent address for Ev %8.0f in list of size %lu for "
5399 "TSRC %d%d%d%d: 0x%08x, time %f",
5400 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
5401 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
5402 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
5403 fvLastHits[iSmType][iSm][iRpc][iCh].front()->Delete();
5404 fvLastHits[iSmType][iSm][iRpc][iCh].pop_front();
5405 }
5406 }
5407 }
5408 }
5409 LOG(info) << Form("LH cleaning done after %8.0f events", fdEvent);
5410}
5411
5412Bool_t CbmTofEventClusterizer::AddNextChan(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iLastChan, Double_t dLastPosX,
5413 Double_t dLastPosY, Double_t dLastTime, Double_t dLastTotS)
5414{
5415 // Int_t iNbSm = fDigiBdfPar->GetNbSm( iSmType); (VF) not used
5416 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
5417 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
5418 // Int_t iChType = fDigiBdfPar->GetChanType( iSmType, iRpc ); (VF) not used
5419 Int_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType);
5420 Int_t iDetIndx = fDetIdIndexMap[iDetId]; // Detector Index
5421
5422 Int_t iCh = iLastChan + 1;
5423 Int_t iChId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType);
5424
5425 while (fvDeadStrips[iDetIndx] & (1 << iCh)) {
5426 LOG(debug) << "Skip channel " << iCh << " of detector " << Form("0x%08x", iDetId);
5427 iCh++;
5428 iLastChan++;
5429 if (iCh >= iNbCh) return kFALSE;
5430 }
5431 LOG(debug1) << Form("Inspect channel TSRC %d%d%d%d at time %f, pos %f, size ", iSmType, iSm, iRpc, iCh, dLastTime,
5432 dLastPosY)
5433 << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
5434 if (iCh == iNbCh) return kFALSE;
5435 if (0 == fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) return kFALSE;
5436 if (0 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size())
5437 if (fDutId > -1) fhNbDigiPerChan->Fill(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size());
5438 if (1 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
5439 Bool_t AddedHit = kFALSE;
5440 for (size_t i1 = 0; i1 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size() - 1; i1++) {
5441 if (AddedHit) break;
5442 size_t i2 = i1 + 1;
5443 while (!AddedHit && i2 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
5444 LOG(debug1) << "check digi pair " << i1 << "," << i2 << " with size "
5445 << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
5446
5447 if ((fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i1])->GetSide()
5448 == (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i2])->GetSide()) {
5449 i2++;
5450 continue;
5451 } // endif same side
5452 // 2 Digis, both sides present
5453 CbmTofDigi* xDigiA = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i1];
5454 CbmTofDigi* xDigiB = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i2];
5455 Double_t dTime = 0.5 * (xDigiA->GetTime() + xDigiB->GetTime());
5456 if (TMath::Abs(dTime - dLastTime) < fdMaxTimeDist) {
5457 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
5458 iChId = fTofId->SetDetectorInfo(xDetInfo);
5459 fChannelInfo = fDigiPar->GetCell(iChId);
5460 if (iChId == 0x13800036) {
5461 const double local[3] = {3 * 0};
5462 double global[3];
5463 fCellIdGeoMap[iChId]->GetMatrix()->LocalToMaster(local, global);
5464 LOG(info) << "GeoTest1: " << global[0] << ", " << global[1] << ", " << global[2];
5465 }
5466 //gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ()); //needed, why?
5467 if (iChId == 0x13800036) {
5468 TGeoHMatrix* pMatrix = gGeoManager->GetCurrentMatrix();
5469 const double local[3] = {3 * 0};
5470 double global[3];
5471 pMatrix->LocalToMaster(local, global);
5472 LOG(info) << "GeoTest2: " << global[0] << ", " << global[1] << ", " << global[2];
5473 if (fiNbHits == 10) LOG(fatal) << " for inspection";
5474 }
5475 Double_t dTimeDif = xDigiA->GetTime() - xDigiB->GetTime();
5476 Double_t dPosY = 0.;
5477 if (1 == xDigiA->GetSide())
5478 dPosY = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
5479 else
5480 dPosY = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
5481
5482 if (TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist) { // append digi pair to current cluster
5483
5484 Double_t dNClHits = (Double_t)(vDigiIndRef.size() / 2);
5485 Double_t dPosX = ((Double_t)(-iNbCh / 2 + iCh) + 0.5) * fChannelInfo->GetSizex();
5486 Double_t dTotS = xDigiA->GetTot() + xDigiB->GetTot();
5487 Double_t dNewTotS = (dLastTotS + dTotS);
5488 dLastPosX = (dLastPosX * dLastTotS + dPosX * dTotS) / dNewTotS;
5489 dLastPosY = (dLastPosY * dLastTotS + dPosY * dTotS) / dNewTotS;
5490 dLastTime = (dLastTime * dLastTotS + dTime * dTotS) / dNewTotS;
5491 dLastTotS = dNewTotS;
5492 // attach selected digis from pool
5493 Int_t Ind1 = fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][i1];
5494 Int_t Ind2 = fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][i2];
5495 vDigiIndRef.push_back(Ind1);
5496 vDigiIndRef.push_back(Ind2);
5497 // remove selected digis from pool
5498 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin()
5499 + i1);
5500 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5501 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + i1);
5502
5503 std::vector<int>::iterator it;
5504 it = find(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin(),
5505 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].end(), Ind2);
5506 if (it != fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].end()) {
5507 auto ipos = it - fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin();
5508 LOG(debug1) << "Found i2 " << i2 << " with Ind2 " << Ind2 << " at position " << ipos;
5509 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin()
5510 + ipos);
5511 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5512 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + ipos);
5513 }
5514 else {
5515 LOG(fatal) << " Did not find i2 " << i2 << " with Ind2 " << Ind2;
5516 }
5517
5518 //if(iCh == iNbCh-1) break; //Last strip reached
5519 if (iCh != (iNbCh - 1)
5520 && AddNextChan(iSmType, iSm, iRpc, iCh, dLastPosX, dLastPosY, dLastTime, dLastTotS)) {
5521 LOG(debug1) << "Added Strip " << iCh << " to cluster of size " << dNClHits;
5522 return kTRUE; // signal hit was already added
5523 }
5524 AddedHit = kTRUE;
5525 } //TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist
5526 } //TMath::Abs(dTime-dLastTime)<fdMaxTimeDist)
5527 i2++;
5528 } // while(i2 < fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size()-1 )
5529 } // end for i1
5530 } // end if size
5531 Double_t hitpos_local[3] = {3 * 0.};
5532 hitpos_local[0] = dLastPosX;
5533 hitpos_local[1] = dLastPosY;
5534 hitpos_local[2] = 0.;
5535 /*
5536 if( 5 == iSmType || 8 == iSmType) { // for PAD counters
5537 hitpos_local[0] = (gRandom->Rndm()-0.5)*fChannelInfo->GetSizex()*0.5;
5538 hitpos_local[1] = (gRandom->Rndm()-0.5)*fChannelInfo->GetSizey()*0.5;
5539 }
5540 */
5541 Double_t hitpos[3] = {3 * 0.};
5542 Int_t iChm = floor(dLastPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
5543 if (iChm < 0) iChm = 0;
5544 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
5545 iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
5546
5547 if (5 != iSmType) { // Diamond beam counter always at (0,0,0)
5548 fCellIdGeoMap[iDetId]->GetMatrix()->LocalToMaster(hitpos_local, hitpos);
5549 /*TGeoNode* cNode = */ // gGeoManager->GetCurrentNode();
5550 /*TGeoHMatrix* cMatrix = */ // gGeoManager->GetCurrentMatrix();
5551 //gGeoManager->LocalToMaster(hitpos_local, hitpos);
5552 }
5553 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
5554 TVector3 hitPosErr(0.5, 0.5, 0.5); // FIXME including positioning uncertainty
5555
5556
5557 Int_t iNbChanInHit = vDigiIndRef.size() / 2;
5558
5559 TString cstr = "Save A-Hit ";
5560 cstr += Form(" %3d %3d 0x%08x %3d 0x%08x %8.2f %6.2f", // %3d %3d
5561 fiNbHits, iNbChanInHit, iDetId, iLastChan,
5562 0, //vPtsRef.size(),vPtsRef[0])
5563 dLastTime, dLastPosY);
5564 cstr += Form(", DigiSize: %lu ", vDigiIndRef.size());
5565 cstr += ", DigiInds: ";
5566
5567 fviClusterMul[iSmType][iSm][iRpc]++;
5568
5569 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
5570 cstr += Form(" %d (M,%d)", vDigiIndRef.at(i), fviClusterMul[iSmType][iSm][iRpc]);
5571 }
5572 LOG(debug) << cstr;
5573
5574 CbmTofHit* pHit = new CbmTofHit(iDetId, hitPos,
5575 hitPosErr, //local detector coordinates
5576 fiNbHits, // this number is used as reference!!
5577 dLastTime,
5578 vDigiIndRef.size(), // number of linked digis = 2*CluSize
5579 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
5580 Int_t(dLastTotS * 10.)); //channel -> Tot
5581 pHit->SetTimeError(dTimeRes);
5582
5583 LOG(debug) << Form("TofHit %d has time %f, sum %f, in TS %f, TS %f ", fiNbHits, pHit->GetTime(),
5584 dLastTime + dTsStartTime, dLastTime, dTsStartTime);
5585
5586 // output hit
5587 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
5588
5589 if (fdMemoryTime > 0.) { // memorize hit
5590 LH_store(iSmType, iSm, iRpc, iChm, pHit);
5591 }
5592 else {
5593 pHit->Delete();
5594 }
5595 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
5596 for (size_t i = 0; i < vDigiIndRef.size(); i++) {
5597 Double_t dTot = (fTofCalDigiVec->at(vDigiIndRef.at(i))).GetTot();
5598 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
5599 }
5600 fiNbHits++;
5601 vDigiIndRef.clear();
5602
5603 return kTRUE;
5604}
5605
5607{
5608
5609 if (fvLastHits[iSmType][iSm][iRpc][iChm].size() == 0)
5610 fvLastHits[iSmType][iSm][iRpc][iChm].push_back(pHit);
5611 else {
5612 Double_t dLastTime = pHit->GetTime();
5613 if (dLastTime >= fvLastHits[iSmType][iSm][iRpc][iChm].back()->GetTime()) {
5614 fvLastHits[iSmType][iSm][iRpc][iChm].push_back(pHit);
5615 LOG(debug) << Form(" Store LH from Ev %8.0f for TSRC %d%d%d%d, size %lu, addr 0x%08x, "
5616 "time %f, dt %f",
5617 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
5618 pHit->GetAddress(), dLastTime,
5619 dLastTime - fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime());
5620 }
5621 else {
5622 if (dLastTime
5623 >= fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime()) { // hit has to be inserted in the proper place
5624 std::list<CbmTofHit*>::iterator it;
5625 for (it = fvLastHits[iSmType][iSm][iRpc][iChm].begin(); it != fvLastHits[iSmType][iSm][iRpc][iChm].end(); ++it)
5626 if ((*it)->GetTime() > dLastTime) break;
5627 fvLastHits[iSmType][iSm][iRpc][iChm].insert(--it, pHit);
5628 Double_t deltaTime = dLastTime - (*it)->GetTime();
5629 LOG(debug) << Form("Hit inserted into LH from Ev %8.0f for TSRC "
5630 "%d%d%d%d, size %lu, addr 0x%08x, delta time %f ",
5631 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
5632 pHit->GetAddress(), deltaTime);
5633 }
5634 else { // this hit is first
5635 Double_t deltaTime = dLastTime - fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime();
5636 LOG(debug) << Form("first LH from Ev %8.0f for TSRC %d%d%d%d, size "
5637 "%lu, addr 0x%08x, delta time %f ",
5638 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
5639 pHit->GetAddress(), deltaTime);
5640 if (deltaTime == 0.) {
5641 // remove hit, otherwise double entry?
5642 pHit->Delete();
5643 }
5644 else {
5645 fvLastHits[iSmType][iSm][iRpc][iChm].push_front(pHit);
5646 }
5647 }
5648 }
5649 }
5650}
5651
5653{
5654 // Then build clusters inside each RPC module
5655 // Assume only 0 or 1 Digi per channel/side in each event
5656 // Use simplest method possible, scan direction independent:
5657 // a) Loop over channels in the RPC starting from 0
5658 // * If strips
5659 // i) Loop over Digis to check if both ends of the channel have a Digi
5660 // ii) Reconstruct a mean channel time and a mean position
5661 // + If a Hit is currently filled & the mean position (space, time) is less than XXX from last channel position
5662 // iii) Add the mean channel time and the mean position to the ones of the hit
5663 // + else
5664 // iii) Use nb of strips in cluster to cal. the hit mean time and pos (charge/tot weighting)
5665 // iv) Save the hit
5666 // v) Start a new hit with current channel
5667 // * else (pads)
5668 // i) Loop over Digis to find if this channel fired
5669 // ii) FIXME: either scan all other channels to check for matching Digis or have more than 1 hit open
5670 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
5671 // Hit variables
5672 Double_t dWeightedTime = 0.0;
5673 Double_t dWeightedPosX = 0.0;
5674 Double_t dWeightedPosY = 0.0;
5675 Double_t dWeightedPosZ = 0.0;
5676 Double_t dWeightsSum = 0.0;
5677 //vPtsRef.clear();
5678 vDigiIndRef.clear();
5679 // CbmTofCell *fTrafoCell=NULL; (VF) not used
5680 // Int_t iTrafoCell=-1; (VF) not used
5681 Int_t iNbChanInHit = 0;
5682 // Last Channel Temp variables
5683 Int_t iLastChan = -1;
5684 Double_t dLastPosX = 0.0; // -> Comment to remove warning because set but never used
5685 Double_t dLastPosY = 0.0;
5686 Double_t dLastTime = 0.0;
5687 // Channel Temp variables
5688 Double_t dPosX = 0.0;
5689 Double_t dPosY = 0.0;
5690 Double_t dPosZ = 0.0;
5691 Double_t dTime = 0.0;
5692 Double_t dTimeDif = 0.0;
5693 Double_t dTotS = 0.0;
5694 fiNbSameSide = 0;
5695 if (kTRUE) {
5696 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
5697 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
5698 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
5699 for (Int_t iSm = 0; iSm < iNbSm; iSm++)
5700 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
5701 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
5702 Int_t iChType = fDigiBdfPar->GetChanType(iSmType, iRpc);
5703 LOG(debug2) << "RPC - Loop " << Form(" %3d %3d %3d %3d ", iSmType, iSm, iRpc, iChType);
5704 fviClusterMul[iSmType][iSm][iRpc] = 0;
5705 Int_t iChId = 0;
5706 Int_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType);
5707 ;
5708 Int_t iDetIndx = fDetIdIndexMap[iDetId]; // Detector Index
5709 if (0 == iChType) {
5710 // Don't spread clusters over RPCs!!!
5711 dWeightedTime = 0.0;
5712 dWeightedPosX = 0.0;
5713 dWeightedPosY = 0.0;
5714 dWeightedPosZ = 0.0;
5715 dWeightsSum = 0.0;
5716 iNbChanInHit = 0;
5717 //vPtsRef.clear();
5718 // For safety reinitialize everything
5719 iLastChan = -1;
5720 // dLastPosX = 0.0; // -> Comment to remove warning because set but never used
5721 dLastPosY = 0.0;
5722 dLastTime = 0.0;
5723 LOG(debug2) << "ChanOrient "
5724 << Form(" %3d %3d %3d %3d %3d ", iSmType, iSm, iRpc, fDigiBdfPar->GetChanOrient(iSmType, iRpc),
5725 iNbCh);
5726
5727 if (0) { //1 == fDigiBdfPar->GetChanOrient(iSmType, iRpc)) { // option disabled, used in Calibrator
5728 // Horizontal strips => X comes from left right time difference
5729 } // if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
5730 else { // Vertical strips => Y comes from bottom top time difference
5731 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
5732 LOG(debug3) << "VDigisize "
5733 << Form(" T %3d Sm %3d R %3d Ch %3d Size %3lu ", iSmType, iSm, iRpc, iCh,
5734 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size());
5735 if (0 == fStorDigi[iSmType][iSm * iNbRpc + iRpc].size()) continue;
5736 if (fvDeadStrips[iDetIndx] & (1 << iCh)) continue; // skip over dead channels
5737 if (0 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size())
5738 if (fDutId > -1) fhNbDigiPerChan->Fill(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size());
5739
5740 while (1 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
5741
5742 while ((fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetSide()
5743 == (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetSide()) {
5744 // Not one Digi of each end!
5745 fiNbSameSide++;
5746 if (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size() > 2) {
5747 LOG(debug) << "SameSide Digis! on TSRC " << iSmType << iSm << iRpc << iCh << ", Times: "
5748 << Form("%f", (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()) << ", "
5749 << Form("%f", (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime())
5750 << ", DeltaT "
5751 << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
5752 - (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
5753 << ", array size: " << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
5754 if (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetSide()
5755 == fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetSide()) {
5756 LOG(debug) << "3 consecutive SameSide Digis! on TSRC " << iSmType << iSm << iRpc << iCh
5757 << ", Times: " << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
5758 << ", " << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
5759 << ", DeltaT "
5760 << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
5761 - (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
5762 << ", array size: " << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
5763 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5764 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5765 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5766 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5767 }
5768 else {
5769 if (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetTime()
5770 - fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetTime()
5771 > fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetTime()
5772 - fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1]->GetTime()) {
5773 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5774 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5775 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5776 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5777 }
5778 else {
5779 LOG(debug) << Form("Ev %8.0f, digis not properly time ordered, TSRCS "
5780 "%d%d%d%d%d ",
5781 fdEvent, iSmType, iSm, iRpc, iCh,
5782 (Int_t) fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetSide());
5783 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5784 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1);
5785 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5786 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1);
5787 }
5788 }
5789 }
5790 else {
5791 LOG(debug2) << "SameSide Erase fStor entries(d) " << iSmType << ", SR " << iSm * iNbRpc + iRpc
5792 << ", Ch" << iCh;
5793 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5794 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5795 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5796 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5797 }
5798 if (2 > fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) break;
5799 continue;
5800 } // same condition side end
5801
5802 LOG(debug2) << "digis processing for "
5803 << Form(" SmT %3d Sm %3d Rpc %3d Ch %3d # %3lu ", iSmType, iSm, iRpc, iCh,
5804 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size());
5805 if (2 > fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
5806 LOG(debug) << Form("Leaving digi processing for TSRC %d%d%d%d, size %3lu", iSmType, iSm, iRpc, iCh,
5807 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size());
5808 break;
5809 }
5810 /* Int_t iLastChId = iChId; // Save Last hit channel*/
5811
5812 // 2 Digis = both sides present
5813 //CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
5814 //iChId = fTofId->SetDetectorInfo(xDetInfo);
5815 iChId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType);
5816 /*
5817 LOG(debug1) << Form(" TSRC %d%d%d%d size %3lu ", iSmType, iSm, iRpc, iCh,
5818 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size())
5819 << Form(" ChId: 0x%08x 0x%08x ", iChId, iUCellId);
5820 */
5821 fChannelInfo = fDigiPar->GetCell(iChId);
5822
5823 if (NULL == fChannelInfo) {
5824 LOG(error) << "CbmTofEventClusterizer::BuildClusters: no geometry info! "
5825 << Form(" %3d %3d %3d %3d 0x%08x", iSmType, iSm, iRpc, iCh, iChId);
5826 break;
5827 }
5828
5829 //TGeoNode* fNode = // prepare local->global trafo
5830 //gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ()); //needed for position spectra, why?
5831 if (iChId == 0x13800036) {
5832 const double local[3] = {3 * 0};
5833 double global[3];
5834 fCellIdGeoMap[iChId]->GetMatrix()->LocalToMaster(local, global);
5835 LOG(info) << "GeoTest3: " << global[0] << ", " << global[1] << ", " << global[2];
5836 } /*
5837 LOG(debug2) << Form(" Node at (%6.1f,%6.1f,%6.1f) : %p", fChannelInfo->GetX(), fChannelInfo->GetY(),
5838 fChannelInfo->GetZ(), fNode);
5839 // fNode->Print();
5840 */
5841 CbmTofDigi* xDigiA = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0];
5842 CbmTofDigi* xDigiB = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1];
5843
5844 LOG(debug2) << " " << xDigiA->ToString();
5845 LOG(debug2) << " " << xDigiB->ToString();
5846
5847 dTimeDif = (xDigiA->GetTime() - xDigiB->GetTime());
5848 if ((5 == iSmType || 8 == iSmType) && dTimeDif != 0.) {
5849 // FIXME -> Overflow treatment in calib/tdc/TMbsCalibTdcTof.cxx
5850 LOG(error) << "BuildHits: Pad hit in TSRC " << iSmType << iSm << iRpc << iCh << " inconsistent, "
5851 << "t " << xDigiA->GetTime() << ", " << xDigiB->GetTime() << " -> " << dTimeDif
5852 << ", Tot " << xDigiA->GetTot() << ", " << xDigiB->GetTot();
5853 LOG(debug) << " " << xDigiA->ToString();
5854 LOG(debug) << " " << xDigiB->ToString();
5855 }
5856 if (1 == xDigiA->GetSide())
5857 // 0 is the top side, 1 is the bottom side
5858 dPosY = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
5859 else
5860 // 0 is the bottom side, 1 is the top side
5861 dPosY = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
5862
5863 while (TMath::Abs(dPosY) > fChannelInfo->GetSizey() * fPosYMaxScal
5864 && fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size() > 2) {
5865 LOG(debug) << "Hit candidate outside correlation window, check for "
5866 "better possible digis, "
5867 << " mul " << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
5868
5869 CbmTofDigi* xDigiC = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2];
5870 Double_t dPosYN = 0.;
5871 Double_t dTimeDifN = 0;
5872 if (xDigiC->GetSide() == xDigiA->GetSide())
5873 dTimeDifN = xDigiC->GetTime() - xDigiB->GetTime();
5874 else
5875 dTimeDifN = xDigiA->GetTime() - xDigiC->GetTime();
5876
5877 if (1 == xDigiA->GetSide())
5878 dPosYN = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDifN * 0.5;
5879 else
5880 dPosYN = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDifN * 0.5;
5881
5882 if (TMath::Abs(dPosYN) < TMath::Abs(dPosY)) {
5883 LOG(debug) << "Replace digi on side " << xDigiC->GetSide() << ", yPosNext " << dPosYN
5884 << " old: " << dPosY;
5885 dTimeDif = dTimeDifN;
5886 dPosY = dPosYN;
5887 if (xDigiC->GetSide() == xDigiA->GetSide()) {
5888 xDigiA = xDigiC;
5889 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5890 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5891 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5892 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5893 }
5894 else {
5895 xDigiB = xDigiC;
5896 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5897 ++(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1));
5898 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5899 ++(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1));
5900 }
5901 }
5902 else
5903 break;
5904 } //while loop end
5905
5906 if (xDigiA->GetSide() == xDigiB->GetSide()) {
5907 LOG(fatal) << "Wrong combinations of digis " << fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]
5908 << "," << fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1];
5909 }
5910
5911 if (TMath::Abs(dPosY) > fChannelInfo->GetSizey() * fPosYMaxScal) { // remove both digis
5912 LOG(debug1) << "Remove digis on TSRC " << iSmType << iSm << iRpc << iCh << " with dPosY " << dPosY
5913 << " > " << fChannelInfo->GetSizey();
5914 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5915 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5916 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5917 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5918 continue;
5919 }
5920 // The "Strip" time is the mean time between each end
5921 dTime = 0.5 * (xDigiA->GetTime() + xDigiB->GetTime());
5922
5923 // Weight is the total charge => sum of both ends ToT
5924 dTotS = xDigiA->GetTot() + xDigiB->GetTot();
5925
5926 // use local coordinates, (0,0,0) is in the center of counter ?
5927 //dPosX = ((Double_t)(-iNbCh / 2 + iCh) + 0.5) * fChannelInfo->GetSizex();
5928 dPosX = ((-(double) iNbCh / 2. + (double) iCh) + 0.5) * fChannelInfo->GetSizex();
5929 dPosZ = 0.;
5930
5931 LOG(debug1) << "NbChanInHit "
5932 << Form(" %3d %3d %3d %3d %3d 0x%p %1.0f Time %f PosX %f "
5933 "PosY %f Svel %f ",
5934 iNbChanInHit, iSmType, iRpc, iCh, iLastChan, xDigiA, xDigiA->GetSide(), dTime,
5935 dPosX, dPosY, fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc))
5936 // << Form( ", Offs %f, %f ",fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][0],
5937 // fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][1])
5938 ;
5939
5940 // Now check if a hit/cluster is already started
5941 if (0 < iNbChanInHit) {
5942 if (iLastChan == iCh - 1) {
5943 if (fDutId > -1) {
5944 fhDigTimeDifClust->Fill(dTime - dLastTime);
5945 fhDigSpacDifClust->Fill(dPosY - dLastPosY);
5946 fhDigDistClust->Fill(dPosY - dLastPosY, dTime - dLastTime);
5947 }
5948 }
5949 // if( iLastChan == iCh - 1 )
5950 // a cluster is already started => check distance in space/time
5951 // For simplicity, just check along strip direction for now
5952 // and break cluster when a not fired strip is found
5953 if (TMath::Abs(dTime - dLastTime) < fdMaxTimeDist && iLastChan == iCh - 1
5954 && TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist) {
5955 // Add to cluster/hit
5956 dWeightedTime += dTime * dTotS;
5957 dWeightedPosX += dPosX * dTotS;
5958 dWeightedPosY += dPosY * dTotS;
5959 dWeightedPosZ += dPosZ * dTotS;
5960 dWeightsSum += dTotS;
5961 iNbChanInHit += 1;
5962
5963 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
5964 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
5965
5966 LOG(debug1) << " Add Digi and erase fStor entries(a): NbChanInHit " << iNbChanInHit << ", "
5967 << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch" << iCh;
5968
5969 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5970 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5971 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5972 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5973 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5974 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5975 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
5976 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
5977
5978 } // if current Digis compatible with last fired chan
5979 else {
5980 // Save Hit
5981 dWeightedTime /= dWeightsSum;
5982 dWeightedPosX /= dWeightsSum;
5983 dWeightedPosY /= dWeightsSum;
5984 dWeightedPosZ /= dWeightsSum;
5985 // TVector3 hitPosLocal(dWeightedPosX, dWeightedPosY, dWeightedPosZ);
5986 //TVector3 hitPos;
5987 Double_t hitpos_local[3];
5988 hitpos_local[0] = dWeightedPosX;
5989 hitpos_local[1] = dWeightedPosY;
5990 hitpos_local[2] = dWeightedPosZ;
5991 /*
5992 if( 5 == iSmType || 8 == iSmType) { // for PAD counters
5993 hitpos_local[0] = (gRandom->Rndm()-0.5)*fChannelInfo->GetSizex();
5994 hitpos_local[1] = (gRandom->Rndm()-0.5)*fChannelInfo->GetSizey();
5995 }
5996 */
5997 Double_t hitpos[3] = {3 * 0.};
5998 if (5 != iSmType) {
5999 fCellIdGeoMap[iChId]->GetMatrix()->LocalToMaster(hitpos_local, hitpos);
6000 /*TGeoNode* cNode =*/ //gGeoManager->GetCurrentNode();
6001 /*TGeoHMatrix* cMatrix =*/ //gGeoManager->GetCurrentMatrix();
6002 //cNode->Print();
6003 //cMatrix->Print();
6004 //gGeoManager->LocalToMaster(hitpos_local, hitpos);
6005 }
6006 LOG(debug1) << Form(" LocalToMaster: (%6.1f,%6.1f,%6.1f) "
6007 "->(%6.1f,%6.1f,%6.1f)",
6008 hitpos_local[0], hitpos_local[1], hitpos_local[2], hitpos[0], hitpos[1],
6009 hitpos[2]);
6010
6011 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
6012
6013 // Simple errors, not properly done at all for now
6014 // Right way of doing it should take into account the weight distribution
6015 // and real system time resolution
6016 TVector3 hitPosErr(0.5, 0.5, 0.5); // including positioning uncertainty
6017 /*
6018 TVector3 hitPosErr( fChannelInfo->GetSizex()/TMath::Sqrt(12.0), // Single strips approximation
6019 0.5, // Use generic value
6020 1.);
6021
6022 */
6023 //fDigiBdfPar->GetFeeTimeRes() * fDigiBdfPar->GetSigVel(iSmType,iRpc), // Use the electronics resolution
6024 //fDigiBdfPar->GetNbGaps( iSmType, iRpc)*
6025 //fDigiBdfPar->GetGapSize( iSmType, iRpc)/ //10.0 / // Change gap size in cm
6026 //TMath::Sqrt(12.0) ); // Use full RPC thickness as "Channel" Z size
6027 // Int_t iDetId = vPtsRef[0]->GetDetectorID();// detID = pt->GetDetectorID() <= from TofPoint
6028 // calc mean ch from dPosX=((Double_t)(-iNbCh/2 + iCh)+0.5)*fChannelInfo->GetSizex();
6029 Int_t iChm = floor(dWeightedPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
6030 if (iChm < 0) iChm = 0;
6031 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
6032 iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
6033 Int_t iRefId = 0; // Index of the correspondng TofPoint
6034 // if(NULL != fTofPointsColl) {
6035 //iRefId = fTofPointsColl->IndexOf( vPtsRef[0] );
6036 //}
6037 TString sRef = "";
6038 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
6039 sRef += Form(" %d, (M%d)", vDigiIndRef.at(i), fviClusterMul[iSmType][iSm][iRpc]);
6040 }
6041 LOG(debug) << "Save Hit "
6042 << Form(" %3d %3d 0x%08x %3d %3d %3d %f %f", fiNbHits, iNbChanInHit, iDetId, iChm,
6043 iLastChan, iRefId, dWeightedTime, dWeightedPosY)
6044 << ", DigiSize: " << vDigiIndRef.size() << ", DigiInds: " << sRef;
6045
6046 fviClusterMul[iSmType][iSm][iRpc]++;
6047
6048 if (vDigiIndRef.size() < 2) {
6049 LOG(warning) << "Digi refs for Hit " << fiNbHits << ": vDigiIndRef.size()";
6050 }
6051 if (fiNbHits > 0) {
6052 CbmTofHit* pHitL = (CbmTofHit*) fTofHitsColl->At(fiNbHits - 1);
6053 if (NULL != pHitL)
6054 if (iDetId == pHitL->GetAddress() && dWeightedTime == pHitL->GetTime()) {
6055 LOG(debug) << "Store Hit twice? "
6056 << " fiNbHits " << fiNbHits << ", "
6057 << Form("0x%08x, MatchCollSize %d, IndRefSize %lu ", iDetId,
6058 fTofDigiMatchColl->GetEntriesFast(), vDigiIndRef.size());
6059
6060 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
6061 if (vDigiIndRef.at(i) < (Int_t) fTofCalDigiVec->size()) {
6062 CbmTofDigi* pDigiC = &(fTofCalDigiVec->at(vDigiIndRef.at(i)));
6063 LOG(debug) << " Digi " << i << " " << pDigiC->ToString();
6064 }
6065 else {
6066 LOG(fatal)
6067 << "Insufficient CalDigiVec size for i " << i << ", Ind " << vDigiIndRef.at(i);
6068 }
6069 }
6070
6071 if (NULL == fTofDigiMatchColl) assert("No DigiMatchColl");
6072 CbmMatch* digiMatchL = NULL;
6073 if (fTofDigiMatchColl->GetEntriesFast() >= fiNbHits - 1) {
6074 digiMatchL = (CbmMatch*) fTofDigiMatchColl->At(fiNbHits - 1);
6075 }
6076 else {
6077 LOG(fatal) << "DigiMatchColl has insufficient size "
6078 << fTofDigiMatchColl->GetEntriesFast();
6079 }
6080
6081 if (NULL != digiMatchL)
6082 for (Int_t i = 0; i < digiMatchL->GetNofLinks(); i++) {
6083 CbmLink L0 = digiMatchL->GetLink(i);
6084 LOG(debug) << "report link " << i << "(" << digiMatchL->GetNofLinks() << "), ind "
6085 << L0.GetIndex();
6086 Int_t iDigIndL = L0.GetIndex();
6087 if (iDigIndL >= (Int_t) vDigiIndRef.size()) {
6088 //if (iDetId != fiBeamRefAddr) {
6089 LOG(warn) << Form("Invalid DigiRefInd for det 0x%08x", iDetId);
6090 break;
6091 //}
6092 }
6093 if (vDigiIndRef.at(iDigIndL) >= (Int_t) fTofCalDigiVec->size()) {
6094 LOG(warn) << "Invalid CalDigiInd";
6095 continue;
6096 }
6097 CbmTofDigi* pDigiC = &(fTofCalDigiVec->at(vDigiIndRef.at(iDigIndL)));
6098 LOG(debug) << " DigiL " << pDigiC->ToString();
6099 }
6100 else {
6101 LOG(warn) << "Invalid digMatch Link at Index " << fiNbHits - 1;
6102 }
6103 }
6104 LOG(debug) << "Current HitsColl length " << fTofHitsColl->GetEntriesFast();
6105 }
6106 CbmTofHit* pHit =
6107 new CbmTofHit(iDetId, hitPos,
6108 hitPosErr, //local detector coordinates
6109 fiNbHits, // this number is used as reference!!
6110 dWeightedTime,
6111 vDigiIndRef.size(), // number of linked digis = 2*CluSize
6112 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
6113 Int_t(dWeightsSum * 10.)); //channel -> Tot
6114 pHit->SetTimeError(dTimeRes);
6115
6116 //0) ; //channel
6117 // output hit
6118 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
6119 // memorize hit
6120 if (fdMemoryTime > 0.) {
6121 LH_store(iSmType, iSm, iRpc, iChm, pHit);
6122 }
6123 else {
6124 pHit->Delete();
6125 }
6126
6127 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
6128 for (size_t i = 0; i < vDigiIndRef.size(); i++) {
6129 Double_t dTot = (fTofCalDigiVec->at(vDigiIndRef.at(i))).GetTot();
6130 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
6131 }
6132
6133 fiNbHits++;
6134 // For Histogramming, vectors are cleared in FillHistos!
6135 /*
6136 fviClusterSize[iSmType][iRpc].push_back(iNbChanInHit);
6137 //fviTrkMul[iSmType][iRpc].push_back( vPtsRef.size() );
6138 fvdX[iSmType][iRpc].push_back(dWeightedPosX);
6139 fvdY[iSmType][iRpc].push_back(dWeightedPosY);
6140 // no TofPoint available for data!
6141 fvdDifX[iSmType][iRpc].push_back( vPtsRef[0]->GetX() - dWeightedPosX);
6142 fvdDifY[iSmType][iRpc].push_back( vPtsRef[0]->GetY() - dWeightedPosY);
6143 fvdDifCh[iSmType][iRpc].push_back( fGeoHandler->GetCell( vPtsRef[0]->GetDetectorID() ) -1 -iLastChan );
6144 */
6145 //vPtsRef.clear();
6146 vDigiIndRef.clear();
6147
6148 // Start a new hit
6149 dWeightedTime = dTime * dTotS;
6150 dWeightedPosX = dPosX * dTotS;
6151 dWeightedPosY = dPosY * dTotS;
6152 dWeightedPosZ = dPosZ * dTotS;
6153 dWeightsSum = dTotS;
6154 iNbChanInHit = 1;
6155 // Save pointer on CbmTofPoint
6156 // vPtsRef.push_back( (CbmTofPoint*)(xDigiA->GetLinks()) );
6157 // Save next digi address
6158 LOG(debug2) << " Next fStor Digi " << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch" << iCh
6159 << ", Dig0 " << (fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]) << ", Dig1 "
6160 << (fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]);
6161
6162 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
6163 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
6164 LOG(debug2) << " Erase fStor entries(b) " << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch"
6165 << iCh;
6166 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6167 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6168 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6169 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6170 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6171 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6172 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6173 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6174
6175 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
6176 // if( ((CbmTofPoint*)(xDigiA->GetLinks()))->GetTrackID() !=
6177 // ((CbmTofPoint*)(xDigiB->GetLinks()))->GetTrackID() )
6178 // if other side come from a different Track,
6179 // also save the pointer on CbmTofPoint
6180 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
6181 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
6182 //else if( xDigiA->GetLinks() != xDigiB->GetLinks() )
6183 // if other side come from a different TofPoint,
6184 // also save the pointer on CbmTofPoint
6185 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
6186 } // else of if current Digis compatible with last fired chan
6187 } // if( 0 < iNbChanInHit)
6188 else {
6189 LOG(debug) << Form("1.Hit on TSRC %d%d%d%d, time: %f, PosY %f, Tdif %f ", iSmType, iSm, iRpc, iCh,
6190 dTime, dPosY, dTimeDif);
6191
6192 // first fired strip in this RPC
6193 dWeightedTime = dTime * dTotS;
6194 dWeightedPosX = dPosX * dTotS;
6195 dWeightedPosY = dPosY * dTotS;
6196 dWeightedPosZ = dPosZ * dTotS;
6197 dWeightsSum = dTotS;
6198 iNbChanInHit = 1;
6199 // Save pointer on CbmTofPoint
6200 //if(NULL != fTofPointsColl)
6201 // vPtsRef.push_back( (CbmTofPoint*)(xDigiA->GetLinks()) );
6202 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
6203 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
6204
6205 LOG(debug2) << " Erase fStor entries(c) " << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch"
6206 << iCh;
6207 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6208 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6209 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6210 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6211 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6212 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6213 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
6214 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
6215
6216 if (kTRUE == fDigiBdfPar->ClustUseTrackId()) {
6217 // if( ((CbmTofPoint*)(xDigiA->GetLinks()))->GetTrackID() !=
6218 // ((CbmTofPoint*)(xDigiB->GetLinks()))->GetTrackID() )
6219 // if other side come from a different Track,
6220 // also save the pointer on CbmTofPoint
6221 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
6222 } // if( kTRUE == fDigiBdfPar->ClustUseTrackId() )
6223 // else if( xDigiA->GetLinks() != xDigiB->GetLinks() )
6224 // if other side come from a different TofPoint,
6225 // also save the pointer on CbmTofPoint
6226 // vPtsRef.push_back( (CbmTofPoint*)(xDigiB->GetLinks()) );
6227 } // else of if( 0 < iNbChanInHit)
6228 iLastChan = iCh;
6229 dLastPosX = dPosX;
6230 dLastPosY = dPosY;
6231 dLastTime = dTime;
6232 if (AddNextChan(iSmType, iSm, iRpc, iLastChan, dLastPosX, dLastPosY, dLastTime, dWeightsSum)) {
6233 iNbChanInHit = 0; // cluster already stored
6234 }
6235 } // while( 1 < fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size() )
6236 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].clear();
6237 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].clear();
6238 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
6239 LOG(debug2) << "finished V-RPC"
6240 << Form(" %3d %3d %3d %d %f %fx", iSmType, iSm, iRpc, fTofHitsColl->GetEntriesFast(),
6241 dLastPosX, dLastPosY);
6242 } // else of if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
6243 } // if( 0 == iChType)
6244 else {
6245 LOG(error) << "=> Cluster building "
6246 << "from digis to hits not implemented for pads, Sm type " << iSmType << " Rpc " << iRpc;
6247 return kFALSE;
6248 } // else of if( 0 == iChType)
6249
6250 // Now check if another hit/cluster is started
6251 // and save it if it's the case
6252 if (0 < iNbChanInHit) {
6253 LOG(debug1) << "Process cluster " << iNbChanInHit;
6254
6255 // Check orientation to properly assign errors
6256 if (0) { // 1 == fDigiBdfPar->GetChanOrient(iSmType, iRpc)) { //option disabled, LRF fixed
6257 LOG(debug1) << "H-Hit ";
6258 } // if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
6259 else {
6260 LOG(debug2) << "V-Hit ";
6261 // Save Hit
6262 dWeightedTime /= dWeightsSum;
6263 dWeightedPosX /= dWeightsSum;
6264 dWeightedPosY /= dWeightsSum;
6265 dWeightedPosZ /= dWeightsSum;
6266 //TVector3 hitPos(dWeightedPosX, dWeightedPosY, dWeightedPosZ);
6267
6268 Double_t hitpos_local[3] = {3 * 0.};
6269 hitpos_local[0] = dWeightedPosX;
6270 hitpos_local[1] = dWeightedPosY;
6271 hitpos_local[2] = dWeightedPosZ;
6272 /*
6273 if( 5 == iSmType || 8 == iSmType) { // for PAD counters
6274 hitpos_local[0] = (gRandom->Rndm()-0.5)*fChannelInfo->GetSizex();
6275 hitpos_local[1] = (gRandom->Rndm()-0.5)*fChannelInfo->GetSizey();
6276 }
6277 */
6278 Double_t hitpos[3] = {3 * 0.};
6279 if (5 != iSmType) {
6280 fCellIdGeoMap[iChId]->GetMatrix()->LocalToMaster(hitpos_local, hitpos);
6281 /*TGeoNode* cNode=*/ //gGeoManager->GetCurrentNode();
6282 /*TGeoHMatrix* cMatrix =*/ //gGeoManager->GetCurrentMatrix();
6283 //cNode->Print();
6284 //cMatrix->Print();
6285 //gGeoManager->LocalToMaster(hitpos_local, hitpos);
6286 }
6287 LOG(debug1) << Form(" LocalToMaster for V-node: "
6288 "(%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)",
6289 hitpos_local[0], hitpos_local[1], hitpos_local[2], hitpos[0], hitpos[1], hitpos[2]);
6290
6291 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
6292 // Event errors, not properly done at all for now
6293 // Right way of doing it should take into account the weight distribution
6294 // and real system time resolution
6295 TVector3 hitPosErr(0.5, 0.5, 0.5); // including positioning uncertainty
6296 /*
6297 TVector3 hitPosErr( fChannelInfo->GetSizex()/TMath::Sqrt(12.0), // Single strips approximation
6298 0.5, // Use generic value
6299 1.);
6300 */
6301 // fDigiBdfPar->GetFeeTimeRes() * fDigiBdfPar->GetSigVel(iSmType,iRpc), // Use the electronics resolution
6302 // fDigiBdfPar->GetNbGaps( iSmType, iRpc)*
6303 // fDigiBdfPar->GetGapSize( iSmType, iRpc)/10.0 / // Change gap size in cm
6304 // TMath::Sqrt(12.0) ); // Use full RPC thickness as "Channel" Z size
6305 // cout<<"a "<<vPtsRef.size()<<endl;
6306 // cout<<"b "<<vPtsRef[0]<<endl;
6307 // cout<<"c "<<vPtsRef[0]->GetDetectorID()<<endl;
6308 // Int_t iDetId = vPtsRef[0]->GetDetectorID();// detID = pt->GetDetectorID() <= from TofPoint
6309 // Int_t iDetId = iChId;
6310 Int_t iChm = floor(dWeightedPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
6311 if (iChm < 0) iChm = 0;
6312 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
6313 iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
6314 //Int_t iRefId = 0; // Index of the correspondng TofPoint
6315 //if(NULL != fTofPointsColl) iRefId = fTofPointsColl->IndexOf( vPtsRef[0] );
6316 TString cstr = "Save V-Hit ";
6317 cstr += Form(" %3d %3d 0x%08x TSR %d%d%d Ch %2d %8.2f %6.2f", // %3d %3d
6318 fiNbHits, iNbChanInHit, iDetId, iSmType, iSm, iRpc, iChm, dWeightedTime, dWeightedPosY);
6319
6320 cstr += Form(", DigiSize: %lu (%3lu)", vDigiIndRef.size(), fTofCalDigiVec->size());
6321 cstr += ", DigiInds: ";
6322
6323 fviClusterMul[iSmType][iSm][iRpc]++;
6324
6325 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
6326 cstr += Form(" %3d (M,%2d)", vDigiIndRef.at(i), fviClusterMul[iSmType][iSm][iRpc]);
6327 }
6328 LOG(debug) << cstr;
6329
6330 if (vDigiIndRef.size() < 2) {
6331 LOG(warning) << "Digi refs for Hit " << fiNbHits << ": vDigiIndRef.size()";
6332 }
6333 if (fiNbHits > 0) {
6334 CbmTofHit* pHitL = (CbmTofHit*) fTofHitsColl->At(fiNbHits - 1);
6335 if (NULL != pHitL)
6336 if (iDetId == pHitL->GetAddress() && dWeightedTime == pHitL->GetTime())
6337 LOG(debug) << "Store Hit twice? "
6338 << " fiNbHits " << fiNbHits << ", " << Form("0x%08x", iDetId);
6339 }
6340
6341 CbmTofHit* pHit = new CbmTofHit(iDetId, hitPos,
6342 hitPosErr, //local detector coordinates
6343 fiNbHits, // this number is used as reference!!
6344 dWeightedTime,
6345 vDigiIndRef.size(), // number of linked digis = 2*CluSize
6346 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
6347 Int_t(dWeightsSum * 10.)); //channel -> Tot
6348 pHit->SetTimeError(dTimeRes);
6349 // 0) ; //channel
6350 // vDigiIndRef);
6351 // output hit
6352 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
6353 // memorize hit
6354 if (fdMemoryTime > 0.) {
6355 LH_store(iSmType, iSm, iRpc, iChm, pHit);
6356 }
6357 else {
6358 pHit->Delete();
6359 }
6360
6361 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
6362
6363 for (size_t i = 0; i < vDigiIndRef.size(); i++) {
6364 Double_t dTot = fTofCalDigiVec->at(vDigiIndRef.at(i)).GetTot();
6365 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
6366 }
6367
6368 fiNbHits++;
6369 // For Histogramming
6370 /*
6371 fviClusterSize[iSmType][iRpc].push_back(iNbChanInHit);
6372 //fviTrkMul[iSmType][iRpc].push_back( vPtsRef.size() );
6373 fvdX[iSmType][iRpc].push_back(dWeightedPosX);
6374 fvdY[iSmType][iRpc].push_back(dWeightedPosY);
6375 fvdDifX[iSmType][iRpc].push_back( vPtsRef[0]->GetX() - dWeightedPosX);
6376 fvdDifY[iSmType][iRpc].push_back( vPtsRef[0]->GetY() - dWeightedPosY);
6377 fvdDifCh[iSmType][iRpc].push_back( fGeoHandler->GetCell( vPtsRef[0]->GetDetectorID() ) -1 -iLastChan );
6378 */
6379 //vPtsRef.clear();
6380 vDigiIndRef.clear();
6381 } // else of if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
6382 } // if( 0 < iNbChanInHit)
6383 LOG(debug2) << " Fini-A " << Form(" %3d %3d %3d M%3d", iSmType, iSm, iRpc, fviClusterMul[iSmType][iSm][iRpc]);
6384 } // for each sm/rpc pair
6385 LOG(debug2) << " Fini-B " << Form(" %3d ", iSmType);
6386 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
6387 }
6388 return kTRUE;
6389}
6390
6392{
6393 CbmTofDigi* pDigi;
6394 CbmTofDigi* pCalDigi = NULL;
6395 Int_t iDigIndCal = -1;
6396 // channel deadtime map
6397 std::map<Int_t, Double_t> mChannelDeadTime;
6398
6399 Int_t iNbTofDigi = fTofDigiVec.size();
6400 //Int_t iNbTofDigi = fTofDigisColl->GetEntriesFast();
6401 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
6402 pDigi = &(fTofDigiVec.at(iDigInd));
6403 //pDigi = (CbmTofDigi*) fTofDigisColl->At( iDigInd );
6404
6405 if (fbSwapChannelSides && 5 != pDigi->GetType() && 8 != pDigi->GetType()) {
6406 pDigi->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi->GetChannel(), (0 == pDigi->GetSide()) ? 1 : 0,
6407 pDigi->GetType());
6408 }
6409
6410 Int_t iAddr = pDigi->GetAddress();
6411
6412 LOG(debug1) << "BC " // Before Calibration
6413 << Form("0x%08x", pDigi->GetAddress()) << " TSRC " << pDigi->GetType() << pDigi->GetSm()
6414 << pDigi->GetRpc() << Form("%2d", (Int_t) pDigi->GetChannel()) << " " << pDigi->GetSide() << " "
6415 << Form("%f", pDigi->GetTime()) << " " << pDigi->GetTot();
6416 /*
6417 if (pDigi->GetType() == 5
6418 || pDigi->GetType()
6419 == 8) // for Pad counters generate fake digi to mockup a strip
6420 if (pDigi->GetSide() == 1)
6421 continue; // skip one side to avoid double entries
6422 */
6423 Bool_t bValid = kTRUE;
6424 std::map<Int_t, Double_t>::iterator it;
6425 it = mChannelDeadTime.find(iAddr);
6426 if (it != mChannelDeadTime.end()) {
6427 LOG(debug1) << "CCT found valid ChannelDeadtime entry " << mChannelDeadTime[iAddr] << ", DeltaT "
6428 << pDigi->GetTime() - mChannelDeadTime[iAddr];
6429 if ((bValid = (pDigi->GetTime() > mChannelDeadTime[iAddr] + fdChannelDeadtime))) {
6430
6431 // pCalDigi = new((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi( *pDigi );
6432 fTofCalDigiVec->push_back(CbmTofDigi(*pDigi));
6433 pCalDigi = &(fTofCalDigiVec->back());
6434 iDigIndCal++;
6435 }
6436 }
6437 else {
6438 fTofCalDigiVec->push_back(CbmTofDigi(*pDigi));
6439 pCalDigi = &(fTofCalDigiVec->back());
6440 iDigIndCal++;
6441 // pCalDigi = new((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi( *pDigi );
6442 }
6443 mChannelDeadTime[iAddr] = pDigi->GetTime();
6444 if (!bValid) continue;
6445
6446 LOG(debug1) << "DC " // After deadtime check. before Calibration
6447 << Form("0x%08x", pDigi->GetAddress()) << " TSRC " << pDigi->GetType() << pDigi->GetSm()
6448 << pDigi->GetRpc() << Form("%2d", (Int_t) pDigi->GetChannel()) << " " << pDigi->GetSide() << " "
6449 << Form("%f", pDigi->GetTime()) << " " << pDigi->GetTot();
6450
6451 if (fbPs2Ns) {
6452 pCalDigi->SetTime(pCalDigi->GetTime() / 1000.); // for backward compatibility
6453 pCalDigi->SetTot(pCalDigi->GetTot() / 1000.); // for backward compatibility
6454 }
6455
6456 if (fDigiBdfPar->GetNbSmTypes() > pDigi->GetType() // prevent crash due to misconfiguration
6457 && fDigiBdfPar->GetNbSm(pDigi->GetType()) > pDigi->GetSm()
6458 && fDigiBdfPar->GetNbRpc(pDigi->GetType()) > pDigi->GetRpc()
6459 && fDigiBdfPar->GetNbChan(pDigi->GetType(), pDigi->GetRpc()) > pDigi->GetChannel()) {
6460
6461 LOG(debug2) << " CluCal-Init: " << pDigi->ToString();
6462 // apply calibration vectors
6463 pCalDigi->SetTime(pCalDigi->GetTime() - // calibrate Digi Time
6464 fvCPTOff[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
6465 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()]);
6466 LOG(debug2) << " CluCal-TOff: " << pCalDigi->ToString();
6467
6468 Double_t dTot = pCalDigi->GetTot() // + fRndm->Uniform(0, 1) // subtract Offset
6469 - fvCPTotOff[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
6470 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()];
6471 if (dTot < 0.001) dTot = 0.001;
6472 pCalDigi->SetTot(dTot * // calibrate Digi ToT
6473 fvCPTotGain[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
6474 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()]);
6475
6476 // walk correction
6477 Double_t dTotBinSize = (fdTOTMax - fdTOTMin) / nbClWalkBinX;
6478 Int_t iWx = (Int_t)((pCalDigi->GetTot() - fdTOTMin) / dTotBinSize);
6479 // LOG(info)<<"Wx: "<<pCalDigi->GetTot()<<" "<<fdTOTMin<<" "<<fdTOTMax<<" "<<dTotBinSize<<" "<<iWx;
6480 if (0 > iWx) iWx = 0;
6481 if (iWx >= nbClWalkBinX) iWx = nbClWalkBinX - 1;
6482 Double_t dDTot = (pCalDigi->GetTot() - fdTOTMin) / dTotBinSize - (Double_t) iWx - 0.5;
6483 Double_t dWT =
6484 fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6485 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx];
6486 if (dDTot > 0) { // linear interpolation to next bin
6487 if (iWx < nbClWalkBinX - 1) { // linear interpolation to next bin
6488
6489 dWT +=
6490 dDTot
6491 * (fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6492 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx + 1]
6493 - fvCPWalk[pCalDigi->GetType()]
6494 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
6495 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]); //memory leak???
6496 }
6497 }
6498 else // dDTot < 0, linear interpolation to next bin
6499 {
6500 if (0 < iWx) { // linear interpolation to next bin
6501 dWT -=
6502 dDTot
6503 * (fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6504 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx - 1]
6505 - fvCPWalk[pCalDigi->GetType()]
6506 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
6507 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]); //memory leak???
6508 }
6509 }
6510
6511 pCalDigi->SetTime(pCalDigi->GetTime() - dWT); // calibrate Digi Time
6512 LOG(debug2) << " CluCal-Walk: " << pCalDigi->ToString();
6513
6514 if (
6515 0) { //pCalDigi->GetType()==0 && pCalDigi->GetSm()==0 && pCalDigi->GetRpc()==2 && pCalDigi->GetChannel()==15 ){
6516 LOG(info)
6517 << "CalDigi " << Form("%02d TSRCS ", iDigIndCal) << pCalDigi->GetType() << pCalDigi->GetSm()
6518 << pCalDigi->GetRpc() << Form("%02d", Int_t(pCalDigi->GetChannel())) << pCalDigi->GetSide()
6519 << Form(", T %15.3f", pCalDigi->GetTime()) << ", Tot " << pCalDigi->GetTot() << ", TotGain "
6520 << fvCPTotGain[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6521 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()]
6522 << ", TotOff "
6523 << fvCPTotOff[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6524 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()]
6525 << ", Walk " << iWx << ": "
6526 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6527 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx];
6528
6529 LOG(info)
6530 << " dDTot " << dDTot << " BinSize: " << dTotBinSize << ", CPWalk "
6531 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6532 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx - 1]
6533 << ", "
6534 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6535 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]
6536 << ", "
6537 << fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
6538 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx + 1]
6539 << " -> dWT = " << dWT;
6540 }
6541 }
6542 else {
6543 if (fiNbSkip1 < 20) {
6544 LOG(info) << "Skip1 Digi "
6545 << " Type " << pDigi->GetType() << " " << fDigiBdfPar->GetNbSmTypes() << " Sm " << pDigi->GetSm()
6546 << " " << fDigiBdfPar->GetNbSm(pDigi->GetType()) << " Rpc " << pDigi->GetRpc() << " "
6547 << fDigiBdfPar->GetNbRpc(pDigi->GetType()) << " Ch " << pDigi->GetChannel() << " "
6548 << fDigiBdfPar->GetNbChan(pDigi->GetType(), 0);
6549 }
6550 ++fiNbSkip1;
6551 }
6552
6553 if (0) // (bAddBeamCounterSideDigi)
6554 if (pCalDigi->GetType() == 5
6555 || pCalDigi->GetType() == 8) { // for Pad counters generate fake digi to mockup a strip
6556 LOG(debug) << "add Pad counter 2. Side digi for 0x" << std::hex << pCalDigi->GetAddress();
6557 fTofCalDigiVec->push_back(CbmTofDigi(*pCalDigi));
6558 CbmTofDigi* pCalDigi2 = &(fTofCalDigiVec->back());
6559 iDigIndCal++;
6560 // CbmTofDigi *pCalDigi2 = new((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi( *pCalDigi );
6561 if (pCalDigi->GetSide() == 0)
6562 pCalDigi2->SetAddress(pCalDigi->GetSm(), pCalDigi->GetRpc(), pCalDigi->GetChannel(), 1, pCalDigi->GetType());
6563 else
6564 pCalDigi2->SetAddress(pCalDigi->GetSm(), pCalDigi->GetRpc(), pCalDigi->GetChannel(), 0, pCalDigi->GetType());
6565 }
6566
6567 } // for( Int_t iDigInd = 0; iDigInd < nTofDigi; iDigInd++ )
6568
6569 // iNbTofDigi = fTofCalDigisColl->GetEntriesFast(); // update because of added duplicted digis
6570 iNbTofDigi = fTofCalDigiVec->size(); // update because of added duplicated digis
6571 //if(fTofCalDigisColl->IsSortable())
6572 // LOG(debug)<<"CbmTofEventClusterizer::BuildClusters: Sort "<<fTofCalDigisColl->GetEntriesFast()<<" calibrated digis ";
6573 LOG(debug) << "CbmTofEventClusterizer::BuildClusters: Sort " << fTofCalDigiVec->size() << " calibrated digis ";
6574 if (iNbTofDigi > 1) {
6575 std::vector<CbmTofDigi>* tTofCalDigiVec = nullptr;
6576 if (NULL != fTofDigiPointMatches) { // temporary copy
6577 tTofCalDigiVec = new std::vector<CbmTofDigi>(*fTofCalDigiVec);
6578 }
6579
6580 //fTofCalDigisColl->Sort(iNbTofDigi); // Time order again, in case modified by the calibration
6582 std::sort(fTofCalDigiVec->begin(), fTofCalDigiVec->end(),
6583 [](const CbmTofDigi& a, const CbmTofDigi& b) -> bool { return a.GetTime() < b.GetTime(); });
6584 // std::sort(fTofCalDigiVec->begin(), fTofCalDigiVec->end());
6585 // if(!fTofCalDigisColl->IsSorted()){
6586 // if ( ! std::is_sorted(fTofCalDigiVec->begin(), fTofCalDigiVec->end()))
6587 if (!std::is_sorted(fTofCalDigiVec->begin(), fTofCalDigiVec->end(),
6588 [](const CbmTofDigi& a, const CbmTofDigi& b) -> bool { return a.GetTime() < b.GetTime(); }))
6589 LOG(warning) << "CbmTofEventClusterizer::BuildClusters: Sorting not successful ";
6590
6591 if (NULL != fTofDigiPointMatches) { // generate updated MC point Match Collection
6592 UInt_t iDigiOrg = 0;
6593 //LOG(info)<<Form("Fill MC Point Matches for %3lu, %3lu digis ",fTofCalDigiVec->size(),tTofCalDigiVec->size());
6594 for (UInt_t iDigi = 0; iDigi < fTofCalDigiVec->size(); iDigi++) {
6595 // find original Digi
6596 CbmTofDigi* outDigi = &(fTofCalDigiVec->at(iDigi));
6597 Bool_t bFound = kFALSE;
6598 while (!bFound) {
6599 for (; iDigiOrg < tTofCalDigiVec->size(); iDigiOrg++) {
6600 CbmTofDigi* orgDigi = &(tTofCalDigiVec->at(iDigiOrg));
6601 if (outDigi->GetAddress() == orgDigi->GetAddress()) {
6602 CbmMatch digiMatch = (CbmMatch) fTofDigiPointMatches->at(iDigiOrg);
6603 ((std::vector<CbmMatch>*) fTofDigiPointMatchesOut)->push_back((CbmMatch) digiMatch);
6604 LOG(debug) << Form("Copy MC Point Match for 0x%08x, time %8.2f from %3d to %3d ", orgDigi->GetAddress(),
6605 outDigi->GetTime(), iDigiOrg, iDigi);
6606 bFound = kTRUE;
6607 break;
6608 }
6609 if (iDigiOrg == tTofCalDigiVec->size() - 1) iDigiOrg = 0;
6610 }
6611 }
6612 }
6613 delete tTofCalDigiVec; // cleanup temporary vector
6614 }
6615
6616 if (fair::Logger::Logging(fair::Severity::debug)) {
6617 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
6618 pCalDigi = &(fTofCalDigiVec->at(iDigInd));
6619 LOG(info) << "SortedCalDigi " << Form("%02d TSRCS ", iDigInd) << pCalDigi->GetType() << pCalDigi->GetSm()
6620 << pCalDigi->GetRpc() << Form("%02d", Int_t(pCalDigi->GetChannel())) << pCalDigi->GetSide()
6621 << Form(", T %15.3f", pCalDigi->GetTime());
6622 }
6623 }
6624 }
6625
6626 return kTRUE;
6627}
6628
6630{
6631 if (fvDeadStrips.size() < static_cast<size_t>(iDet + 1)) fvDeadStrips.resize(iDet + 1);
6632 fvDeadStrips[iDet] = ival;
6633}
6634
6635double* CbmTofEventClusterizer::find_yedges(const char* hname, double dThr, double dLen)
6636{
6637 TH1* h1;
6638 h1 = (TH1*) gROOT->FindObjectAny(hname);
6639 static double dRes[2] = {2 * 0.};
6640 if (NULL != h1) {
6641 double dMean = 0.;
6642 double dLength = 0.;
6643 double dLev = 0.5 * dThr;
6644 double dValid = 0.;
6645 for (int iLev = 0; iLev < 4; iLev++) {
6646 dLev *= 2.;
6647 double xLow = -1000.;
6648 double xHigh = -1000.;
6649 int iBl = -1;
6650 int iBh = -1;
6651 for (int iBin = 0; iBin < h1->GetNbinsX(); iBin++) {
6652 if (iBl < 0 && h1->GetBinContent(iBin) > dLev && h1->GetBinContent(iBin + 1) > dLev
6653 && h1->GetBinContent(iBin + 2) > dLev) {
6654 iBl = iBin;
6655 xLow = h1->GetBinCenter(iBin);
6656 break;
6657 }
6658 }
6659 if (iBl > -1) {
6660 for (int iBin = h1->GetNbinsX() - 1; iBin > 3; iBin--) {
6661 if (iBh < 0 && h1->GetBinContent(iBin) > dLev && h1->GetBinContent(iBin - 1) > dLev
6662 && h1->GetBinContent(iBin - 2) > dLev) {
6663 iBh = iBin;
6664 xHigh = h1->GetBinCenter(iBin);
6665 break;
6666 }
6667 }
6668 }
6669 double xLength = (xHigh - xLow);
6670 double xMean = 0.5 * (xHigh + xLow);
6671 if (TMath::Abs(xLength - dLen) / dLen < 0.1) {
6672 dLength = (dLength * dValid + xLength) / (dValid + 1);
6673 dMean = (dMean * dValid + xMean) / (dValid + 1);
6674 dValid++;
6675 }
6676 } // for loop end
6677 if (dValid == 0) {
6678 LOG(warn) << " No valid yEdge with thr " << dThr << " for " << h1->GetName();
6679 }
6680 dRes[0] = dLength;
6681 dRes[1] = dMean;
6682 }
6683 else {
6684 LOG(error) << "find_yedges: histo not found " << hname;
6685 }
6686
6687 return dRes;
6688}
6689
6691{
6692 if (fiHitStart + iHitInd > fTofHitsCollOut->GetEntriesFast()) {
6693 LOG(fatal) << "Invalid Hit index " << iHitInd << ", " << fiHitStart << ", " << fTofHitsCollOut->GetEntriesFast();
6694 }
6695 return (CbmTofHit*) fTofHitsCollOut->At(fiHitStart + iHitInd);
6696}
6697
6699{
6700 if (fiHitStart + iHitInd > fTofDigiMatchCollOut->GetEntriesFast()) {
6701 LOG(fatal) << "Invalid Hit index " << iHitInd << ", " << fiHitStart << ", "
6702 << fTofDigiMatchCollOut->GetEntriesFast();
6703 }
6704 return (CbmMatch*) fTofDigiMatchCollOut->At(fiHitStart + iHitInd);
6705}
6706
6708{
6709 if (idx > fTofDigiMatchCollOut->GetEntriesFast()) {
6710 LOG(fatal) << "Invalid Hit index " << idx << ", " << fTofDigiMatchCollOut->GetEntriesFast();
6711 }
6712 return (CbmMatch*) fTofDigiMatchCollOut->At(idx);
6713}
6714
6716{
6717 Int_t iChId = pHit->GetAddress();
6718 Double_t hitpos[3];
6719 Double_t hitpos_local[3] = {3 * 0.};
6720 hitpos[0] = pHit->GetX();
6721 hitpos[1] = pHit->GetY();
6722 hitpos[2] = pHit->GetZ();
6723 fChannelInfo = fDigiPar->GetCell(iChId);
6725 if (NULL == fChannelInfo) {
6726 LOG(fatal) << "Invalid Channel Pointer for ChId " << Form(" 0x%08x ", iChId) << ", Ch " << iCh;
6727 }
6728 //gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
6729 /*
6730 gGeoManager->MasterToLocal(hitpos,hitpos_local); // transform into local frame
6731 */
6732 fCellIdGeoMap[iChId]->GetMatrix()->MasterToLocal(hitpos, hitpos_local);
6733 return hitpos_local[0];
6734}
6735
6737{
6738 Int_t iChId = pHit->GetAddress();
6739 Double_t hitpos[3];
6740 Double_t hitpos_local[3] = {3 * 0.};
6741 hitpos[0] = pHit->GetX();
6742 hitpos[1] = pHit->GetY();
6743 hitpos[2] = pHit->GetZ();
6744 fChannelInfo = fDigiPar->GetCell(iChId);
6746 if (NULL == fChannelInfo) {
6747 LOG(fatal) << "Invalid Channel Pointer for ChId " << Form(" 0x%08x ", iChId) << ", Ch " << iCh;
6748 }
6749 //gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
6750 /*
6751 gGeoManager->MasterToLocal(hitpos,hitpos_local); // transform into local frame
6752 */
6753 fCellIdGeoMap[iChId]->GetMatrix()->MasterToLocal(hitpos, hitpos_local);
6754 return hitpos_local[1];
6755}
6756
6757void CbmTofEventClusterizer::MasterToLocal(const int iChId, const double* global, double* local)
6758{
6759 fCellIdGeoMap[iChId]->GetMatrix()->MasterToLocal(global, local);
6760}
6761
6762static int iLogCal = 0;
6764{
6765 // correct Y position dependence of arrival time
6766 for (Int_t iHitInd = 0; iHitInd < fTofHitsColl->GetEntriesFast(); iHitInd++) {
6767 CbmTofHit* pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
6768 if (NULL == pHit) continue;
6769
6770 Int_t iDetId = (pHit->GetAddress() & DetMask);
6771 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
6772 if (iSmType == 5 || iSmType == 8) continue; //Diamond or Pads
6773 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
6774 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
6775 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
6776 int iRpcInd = iSm * iNbRpc + iRpc;
6777
6778 double dY = GetLocalY(pHit);
6779 double fdYRange = fvCPTOffYRange[iSmType][iRpcInd];
6780 LOG(debug) << "TSR " << iSmType << iSm << iRpc << ": Y " << dY << ", " << fdYRange;
6781 if (fdYRange == 0) continue;
6782
6783 double fdBinDy = fvCPTOffYBinWidth[iSmType][iRpcInd];
6784 double dBin = (dY + fdYRange) / fdBinDy;
6785 int iBin = floor(dBin);
6786 int iBin1 = ceil(dBin);
6787 double dRes = dBin - iBin;
6788 //interpolate
6789 double dTcor = fvCPTOffY[iSmType][iSm * iNbRpc + iRpc][iBin];
6790 dTcor += dRes * (fvCPTOffY[iSmType][iSm * iNbRpc + iRpc][iBin1] - fvCPTOffY[iSmType][iSm * iNbRpc + iRpc][iBin]);
6791 if (iLogCal < 10) {
6792 iLogCal++;
6793 LOG(info) << "TSR " << iSmType << iSm << iRpc << ": Y " << dY << ", B " << dBin << ", " << iBin << ", " << iBin1
6794 << ", " << dRes << ", TcorY " << dTcor;
6795 }
6796
6797 pHit->SetTime(pHit->GetTime() - dTcor);
6798 }
6799 return kTRUE;
6800}
@ kTof
Time-of-flight Detector.
CbmTofDigi * pRef
static Int_t iIndexDut
static FairRootManager * rootMgr
static Int_t iMess
static Int_t SelMask
static Int_t iNbTs
static TFile * fHist
TClonesArray * fTofHitsColl
TClonesArray * fEventsColl
const Int_t DetMask
static Double_t fdMemoryTime
CbmDigiManager * fDigiMan
static Double_t dTLEvt
std::vector< TH1 * > hSvel
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 Int_t iNbTs
std::vector< CbmTofDigi > * fT0DigiVec
static double dTsStartTime
static Int_t iNSpill
const Double_t fdSpillBreak
const Double_t dTimeRes
static Double_t f1_xboxe(double *x, double *par)
const Double_t fdSpillDuration
static double dTsStartTimeLast
static Double_t fdStartAna10s
static Int_t iIndexDut
static Double_t dTLEvt
static TRandom3 * fRndm
static int iLogCal
static Int_t SelMask
static Bool_t bAddBeamCounterSideDigi
static int fiHitStart
@ k14a
std::vector< Int_t > vDigiIndRef
static constexpr size_t size()
Definition KfSimdPseudo.h:2
int Int_t
bool Bool_t
Data class for a signal in the t-zero detector.
Definition CbmBmonDigi.h:31
static Int_t GetNofDigis(ECbmModuleId systemId)
static Bool_t IsPresent(ECbmModuleId systemId)
Presence of a digi branch.
InitStatus Init()
Initialisation.
const Digi * Get(Int_t index) const
Get a digi object.
static CbmDigiManager * Instance()
Static instance.
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
size_t GetNofData() const
Definition CbmEvent.cxx:58
int32_t GetNumber() const
Definition CbmEvent.h:121
uint32_t GetIndex(ECbmDataType type, uint32_t iData) const
Definition CbmEvent.cxx:42
void AddData(ECbmDataType type, uint32_t index)
Definition CbmEvent.cxx:33
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
Bookkeeping of time-slice content.
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)
contains filling and updating of calibration histos
void FillCalHist(CbmTofHit *pHit, Int_t iOpt, CbmEvent *pEvent=NULL)
void FillHitCalHist(CbmTofHit *pHit, Int_t iOpt, CbmEvent *pEvent=NULL, TClonesArray *tHitColl=NULL)
Bool_t UpdateCalHist(Int_t iOpt)
Double_t GetSizey() const
Definition CbmTofCell.h:40
Double_t GetY() const
Definition CbmTofCell.h:36
Double_t GetSizex() const
Definition CbmTofCell.h:39
Double_t GetX() const
Definition CbmTofCell.h:35
Double_t GetZ() const
Definition CbmTofCell.h:37
virtual InitStatus Init()
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)
TGeoNode * GetNode(Int_t iCell)
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:161
std::string ToString() const
void SetTot(double tot)
Definition CbmTofDigi.h:169
double GetChannel() const
Channel .
Definition CbmTofDigi.h:157
int32_t GetAddress() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:113
double GetSm() const
Sm.
Definition CbmTofDigi.h:145
double GetTime() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:132
double GetType() const
Sm Type .
Definition CbmTofDigi.h:149
double GetRpc() const
Detector aka Module aka RPC .
Definition CbmTofDigi.h:153
double GetTot() const
Alias for GetCharge.
Definition CbmTofDigi.h:141
void SetAddress(int32_t address)
Definition CbmTofDigi.h:166
void SetTime(double time)
Definition CbmTofDigi.h:168
std::vector< UInt_t > fvDeadStrips
std::vector< std::vector< TH2 * > > fhTRpcCludXdY
Bool_t RegisterOutputs()
Create and register output TClonesArray of Tof Hits.
std::vector< CbmTofDigi > * fTofCalDigiVecOut
std::vector< std::vector< TH3 * > > fhTRpcCluQ2DT
std::vector< Int_t > fviDetId
virtual void ExecEvent(Option_t *option, CbmEvent *tEvent=NULL)
Bool_t RegisterInputs()
Recover pointer on input TClonesArray: TofPoints, TofDigis...
std::vector< TH2 * > fhSmCluTOff
std::vector< TH2 * > fhRpcDigiCor
const CbmTimeSlice * fTimeSlice
std::vector< TH2 * > fhRpcDigiTotDiff
static CbmTofEventClusterizer * fInstance
T0 Digis.
void MasterToLocal(const Int_t CellId, const Double_t *master, Double_t *local)
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTotGain
std::vector< std::vector< TH2 * > > fhTRpcCluAvWalk
std::vector< TProfile * > fhRpcCluPositionEvol
const std::vector< CbmMatch > * fTofDigiPointMatches
std::vector< TH1 * > fhRpcDTLastHits_CluSize
virtual ~CbmTofEventClusterizer()
Destructor.
std::vector< std::vector< std::vector< std::vector< TH2 * > > > > fhTRpcCluWalk
std::vector< TProfile * > fhRpcCluTimeEvol
void SetDeadStrips(Int_t iDet, UInt_t ival)
std::vector< std::vector< TH2 * > > fhTRpcCluPosition
CbmDigiManager * fDigiMan
TOF Digis.
Bool_t LoadGeometry()
Load the geometry: for now just resizing the Digis temporary vectors.
std::vector< std::vector< std::vector< Double_t > > > fvCPTOffY
std::vector< TH1 * > fhRpcDigiRate
std::vector< CbmTofDigi > fTofDigiVec
std::vector< std::vector< TH2 * > > fhTSmCluPosition
Bool_t BuildClusters()
Build clusters out of ToF Digis and store the resulting info in a TofHit.
std::vector< TH2 * > fhRpcDigiMul
std::vector< TH2 * > fhRpcCluDelMatPos
std::vector< TH2 * > fhRpcCluDelTOff
std::vector< std::vector< TH2 * > > fhTRpcCluTotDTLastHits
std::vector< std::vector< Double_t > > fvTimeFirstDigi
std::vector< std::vector< TH2 * > > fhTRpcCluDelTof
std::vector< TH1 * > fhRpcCluRate
std::vector< TH2 * > fhRpcCluTot
std::map< UInt_t, UInt_t > fDetIdIndexMap
std::vector< std::vector< TProfile * > > fhSmCluFpar
Bool_t InitCalibParameter()
Initialize other parameters not included in parameter classes.
std::vector< std::vector< std::vector< std::vector< std::list< CbmTofHit * > > > > > fvLastHits
std::vector< std::vector< TH1 * > > fhTRpcCluMul
const CbmTsEventHeader * fTsHeader
CbmTofCalibrator * fTofCalibrator
virtual void fit_ybox(const char *hname)
std::vector< std::vector< std::vector< std::vector< std::vector< Double_t > > > > > fvCPWalk
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTotOff
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTOff
std::vector< std::vector< std::vector< Double_t > > > fvdDifX
std::vector< std::vector< TH2 * > > fhTSmCluTOff
std::vector< CbmTofDigi > * fTofCalDigiVec
Bool_t InitParameters()
Initialize other parameters not included in parameter classes.
std::vector< TH1 * > fhRpcCluRate10s
virtual void Exec(Option_t *option)
Inherited from FairTask.
std::vector< std::vector< TH2 * > > fhTRpcCluSizeDTLastHits
std::vector< TH2 * > fhRpcCluSize
virtual void LH_store(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iChm, CbmTofHit *pHit)
std::vector< std::vector< std::vector< Double_t > > > fvdDifY
std::vector< TH2 * > fhRpcCluDelMatTOff
std::vector< TH2 * > fhRpcDigiTotMap
std::vector< TH2 * > fhRpcDigiDTFD
std::vector< std::vector< std::vector< Int_t > > > fviClusterMul
std::vector< std::vector< std::vector< Int_t > > > fviTrkMul
std::vector< std::vector< TH2 * > > fhTRpcCluTOffDTLastHits
virtual Bool_t AddNextChan(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iLastChan, Double_t dLastPosX, Double_t dLastPosY, Double_t dLastTime, Double_t dLastTot)
std::vector< std::vector< TH2 * > > fhTRpcCluTOff
Bool_t DeleteGeometry()
Delete the geometry related arrays: for now just clearing the Digis temporary vectors.
std::vector< std::vector< TH2 * > > fhTRpcCluTofOff
CbmTofHit * GetHitPointer(int iHit)
std::vector< std::vector< Double_t > > fvCPTOffYRange
double GetLocalX(CbmTofHit *pHit)
std::vector< TH2 * > fhRpcDigiTotRight
std::vector< std::vector< TH3 * > > fhTRpcCluWalk2
std::vector< std::vector< std::vector< TH2 * > > > fhRpcCluWalk
virtual InitStatus Init()
Inherited from FairTask.
std::vector< TH2 * > fhRpcCluPos
std::vector< std::vector< std::vector< Double_t > > > fvdDifCh
virtual void Finish()
Inherited from FairTask.
std::map< UInt_t, TGeoPhysicalNode * > fCellIdGeoMap
std::vector< CbmMatch > * fTofDigiPointMatchesOut
CbmMatch * GetMatchPointer(int iHit)
TClonesArray * fTofHitsCollOut
// Calibrated TOF Digis
std::vector< TH1 * > fhRpcCluMul
CbmMatch * GetMatchIndexPointer(int idx)
std::vector< TH2 * > fhRpcDigiStatus
std::vector< std::vector< TH2 * > > fhTRpcCluMemMulDTLastHits
std::vector< TH2 * > fhRpcCluDelPos
std::vector< TH2 * > fhRpcCluTOff
virtual void SetParContainers()
Inherited from FairTask.
std::vector< std::vector< TH2 * > > fhTRpcCluTot
std::vector< std::vector< std::vector< std::vector< Int_t > > > > fStorDigiInd
std::vector< TH1 * > fhRpcDTLastHits
std::vector< std::vector< std::vector< Int_t > > > fviClusterSize
std::vector< std::vector< TH2 * > > fhTRpcCluSize
std::vector< TH2 * > fhRpcCluAvLnWalk
TClonesArray * fTofHitsColl
// Calibrated TOF Digis
std::vector< TH2 * > fhRpcCluTrms
std::vector< TH2 * > fhSmCluPosition
std::vector< std::vector< std::vector< Double_t > > > fvdY
Bool_t FillHistos(CbmEvent *tEvent)
std::vector< TH2 * > fhRpcCluAvWalk
std::vector< std::vector< TH2 * > > fhTRpcCluQASY
std::vector< Int_t > vDigiIndRef
std::vector< std::vector< std::vector< Double_t > > > fvdX
std::vector< TProfile * > fhSmCluSvel
std::vector< TH2 * > fhRpcDigiTotLeft
std::vector< std::vector< Double_t > > fvCPTOffYBinWidth
std::vector< TH2 * > fhRpcDigiDTMul
std::vector< TH2 * > fhRpcCluPosition
std::vector< std::vector< Double_t > > fvMulDigi
std::vector< std::vector< std::vector< std::vector< CbmTofDigi * > > > > fStorDigi
std::vector< TH2 * > fhRpcDigiDTLD
virtual double * find_yedges(const char *hname, Double_t dThr, Double_t dLen)
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPDelTof
std::vector< TH1 * > fhRpcDTLastHits_Tot
std::vector< std::vector< TH2 * > > fhTSmCluTRun
std::vector< std::vector< Double_t > > fvTimeLastDigi
double GetLocalY(CbmTofHit *pHit)
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)
uint64_t GetTsStartTime() const
UInt_t GetTriggerPattern() const
Definition TTrbHeader.h:34
Double_t f1_xboxe(double *x, double *par)
Definition fit_ybox.h:6