CbmRoot
Loading...
Searching...
No Matches
CbmDeviceHitBuilderTof.cxx
Go to the documentation of this file.
1/* Copyright (C) 2018-2021 PI-UHd, GSI
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Norbert Herrmann [committer] */
4
13
14// CBM Classes and includes
15#include "CbmDigiManager.h"
16
17// TOF Classes and includes
18#include "CbmMatch.h"
19#include "CbmTofAddress.h" // in cbmdata/tof
20#include "CbmTofCell.h" // in tof/TofData
22#include "CbmTofCreateDigiPar.h" // in tof/TofTools
23#include "CbmTofDetectorId_v12b.h" // in cbmdata/tof
24#include "CbmTofDetectorId_v14a.h" // in cbmdata/tof
25#include "CbmTofDetectorId_v21a.h" // in cbmdata/tof
26#include "CbmTofDigi.h" // in cbmdata/tof
27#include "CbmTofDigiBdfPar.h" // in tof/TofParam
28#include "CbmTofDigiPar.h" // in tof/TofParam
29#include "CbmTofGeoHandler.h" // in tof/TofTools
30#include "CbmTofHit.h" // in cbmdata/tof
31#include "CbmTofPoint.h" // in cbmdata/tof
32
33#include "FairEventHeader.h"
34#include "FairFileHeader.h"
35#include "FairGeoParSet.h"
36#include "FairMQLogger.h"
37#include "FairMQProgOptions.h" // device->fConfig
38#include "FairRootFileSink.h"
39#include "FairRootManager.h"
40#include "FairRunOnline.h"
41#include "FairRuntimeDb.h"
42#include "FairSource.h"
43
44// ROOT Classes and includes
45#include "TClonesArray.h"
46#include "TDirectory.h"
47#include "TF1.h"
48#include "TF2.h"
49#include "TGeoManager.h"
50#include "TH1.h"
51#include "TH2.h"
52#include "TLine.h"
53#include "TMath.h"
54#include "TMinuit.h"
55#include "TProfile.h"
56#include "TROOT.h"
57#include "TRandom3.h"
58#include "TVector3.h"
59
60#include <boost/archive/binary_iarchive.hpp>
61#include <boost/archive/binary_oarchive.hpp>
62#include <boost/serialization/vector.hpp>
63
64#include <chrono>
65#include <iomanip>
66#include <stdexcept>
67#include <string>
68#include <thread> // this_thread::sleep_for
69struct InitTaskError : std::runtime_error {
70 using std::runtime_error::runtime_error;
71};
72
73using namespace std;
74
75// Constants definitions
76static Int_t iMess = 0;
77static Int_t iIndexDut = 0;
78static Double_t StartAnalysisTime = 0.;
79//const Double_t cLight = 29.9792; // in cm/ns
80static FairRootManager* rootMgr = NULL;
81static Int_t iRunId = 1;
82static Int_t SelMask = DetMask;
83static Double_t dTstart = 0.;
84static Double_t dTmax = 0.;
85
89
91 : fNumMessages(0)
92 , fGeoMan(NULL)
93 , fGeoHandler(new CbmTofGeoHandler())
94 , fTofId(NULL)
95 , fDigiPar(NULL)
96 , fChannelInfo(NULL)
97 , fDigiBdfPar(NULL)
98 , fiNDigiIn(0)
99 , fvDigiIn()
100 , fEventHeader()
101 , fEvtHeader(NULL)
102 , fTofHitsColl(NULL)
103 , fTofDigiMatchColl(NULL)
104 , fTofHitsCollOut(NULL)
105 , fTofDigiMatchCollOut(NULL)
106 , fiNbHits(0)
107 , fiNevtBuild(0)
108 , fiMsgCnt(100)
109 , fdTOTMax(50.)
110 , fdTOTMin(0.)
111 , fdTTotMean(2.)
112 , fdMaxTimeDist(0.)
113 , fdMaxSpaceDist(0.)
114 , fdEvent(0)
115 , fiMaxEvent(-1)
116 , fiRunId(111)
117 , fiOutputTreeEntry(0)
118 , fiFileIndex(0)
119 , fStorDigi()
120 , fStorDigiInd()
121 , vDigiIndRef()
122 , fviClusterMul()
123 , fviClusterSize()
124 , fviTrkMul()
125 , fvdX()
126 , fvdY()
127 , fvdDifX()
128 , fvdDifY()
129 , fvdDifCh()
130 , fvCPDelTof()
131 , fvCPTOff()
132 , fvCPTotGain()
133 , fvCPTotOff()
134 , fvCPWalk()
135 , fvLastHits()
136 , fvDeadStrips()
137 , fvPulserOffset()
138 , fvPulserTimes()
139 , fhEvDetMul(NULL)
140 , fhEvDigiMul(NULL)
141 , fhEvRateIn(NULL)
142 , fhEvRateOut(NULL)
143 , fhPulMul(NULL)
144 , fhDigiTdif(NULL)
145 , fhPulserTimesRaw()
146 , fhPulserTimeRawEvo()
147 , fhPulserTimesCor()
148 , fhDigiTimesRaw()
149 , fhDigiTimesCor()
150 , fhRpcDigiTot()
151 , fhRpcDigiCor()
152 , fhRpcCluMul()
153 , fhRpcCluRate()
154 , fhRpcCluPosition()
155 , fhRpcCluDelPos()
156 , fhRpcCluDelMatPos()
157 , fhRpcCluTOff()
158 , fhRpcCluDelTOff()
159 , fhRpcCluDelMatTOff()
160 , fhRpcCluTrms()
161 , fhRpcCluTot()
162 , fhRpcCluSize()
163 , fhRpcCluAvWalk()
164 , fhRpcCluAvLnWalk()
165 , fhRpcCluWalk()
166 , fhSmCluPosition()
167 , fhSmCluTOff()
168 , fhSmCluSvel()
169 , fhSmCluFpar()
170 , fhRpcDTLastHits()
171 , fhRpcDTLastHits_Tot()
172 , fhRpcDTLastHits_CluSize()
173 , fhTRpcCluMul()
174 , fhTRpcCluPosition()
175 , fhTRpcCluTOff()
176 , fhTRpcCluTot()
177 , fhTRpcCluSize()
178 , fhTRpcCluAvWalk()
179 , fhTRpcCluDelTof()
180 , fhTRpcCludXdY()
181 , fhTRpcCluWalk()
182 , fhTSmCluPosition()
183 , fhTSmCluTOff()
184 , fhTSmCluTRun()
185 , fhTRpcCluTOffDTLastHits()
186 , fhTRpcCluTotDTLastHits()
187 , fhTRpcCluSizeDTLastHits()
188 , fhTRpcCluMemMulDTLastHits()
189 , fhSeldT()
190 , dTRef(0.)
191 , fCalMode(0)
192 , fdCaldXdYMax(0.)
193 , fiCluMulMax(0)
194 , fTRefMode(0)
195 , fTRefHits(0)
196 , fDutId(0)
197 , fDutSm(0)
198 , fDutRpc(0)
199 , fDutAddr(0)
200 , fSelId(0)
201 , fSelSm(0)
202 , fSelRpc(0)
203 , fSelAddr(0)
204 , fSel2Id(0)
205 , fSel2Sm(0)
206 , fSel2Rpc(0)
207 , fSel2Addr(0)
208 , fiMode(0)
209 , fiPulserMode(0)
210 , fiPulMulMin(0)
211 , fiPulDetRef(0)
212 , fiPulTotMin(0)
213 , fiPulTotMax(1000)
214 , fDetIdIndexMap()
215 , fviDetId()
216 , fPosYMaxScal(0.)
217 , fTRefDifMax(0.)
218 , fTotMax(0.)
219 , fTotMin(0.)
220 , fTotMean(0.)
221 , fdDelTofMax(60.)
222 , fMaxTimeDist(0.)
223 , fdChannelDeadtime(0.)
224 , fdMemoryTime(0.)
225 , fEnableMatchPosScaling(kTRUE)
226 , fbPs2Ns(kFALSE)
227 , fCalParFileName("")
228 , fOutHstFileName("")
229 , fOutRootFileName("")
230 , fCalParFile(NULL)
231 , fOutRootFile(NULL)
232{
233}
234
236{
237 if (NULL != fOutRootFile) {
238 LOG(info) << "Finally close root file " << fOutRootFile->GetName();
239 fOutRootFile->cd();
240 rootMgr->LastFill();
241 rootMgr->Write();
243 fOutRootFile->Write();
244 fOutRootFile->Close();
245 }
246}
247
249try {
250 // Get the information about created channels from the device
251 // Check if the defined channels from the topology (by name)
252 // are in the list of channels which are possible/allowed
253 // for the device
254 // The idea is to check at initilization if the devices are
255 // properly connected. For the time beeing this is done with a
256 // nameing convention. It is not avoided that someone sends other
257 // data on this channel.
258 int noChannel = fChannels.size();
259 LOG(info) << "Number of defined input channels: " << noChannel;
260 for (auto const& entry : fChannels) {
261 LOG(info) << "Channel name: " << entry.first;
262 if (!IsChannelNameAllowed(entry.first)) throw InitTaskError("Channel name does not match.");
263 if (entry.first != "syscmd") OnData(entry.first, &CbmDeviceHitBuilderTof::HandleData);
264 else
265 OnData(entry.first, &CbmDeviceHitBuilderTof::HandleMessage);
266 }
269 LoadGeometry();
271}
272catch (InitTaskError& e) {
273 LOG(error) << e.what();
274 ChangeState(fair::mq::Transition::ErrorFound);
275}
276
278{
279 for (auto const& entry : fAllowedChannels) {
280 std::size_t pos1 = channelName.find(entry);
281 if (pos1 != std::string::npos) {
282 const vector<std::string>::const_iterator pos =
283 std::find(fAllowedChannels.begin(), fAllowedChannels.end(), entry);
284 const vector<std::string>::size_type idx = pos - fAllowedChannels.begin();
285 LOG(info) << "Found " << entry << " in " << channelName;
286 LOG(info) << "Channel name " << channelName << " found in list of allowed channel names at position " << idx;
287 return true;
288 }
289 }
290 LOG(info) << "Channel name " << channelName << " not found in list of allowed channel names.";
291 LOG(error) << "Stop device.";
292 return false;
293}
294
296{
297 LOG(info) << "Init work space for CbmDeviceHitBuilderTof.";
298 fOutRootFileName = fConfig->GetValue<string>("OutRootFile");
299 fiMaxEvent = fConfig->GetValue<int64_t>("MaxEvent");
300 LOG(info) << "Max number of events to be processed: " << fiMaxEvent;
301 fiRunId = fConfig->GetValue<int64_t>("RunId");
302 fiMode = fConfig->GetValue<int64_t>("Mode");
303 fiPulserMode = fConfig->GetValue<int64_t>("PulserMode");
304 fiPulMulMin = fConfig->GetValue<uint64_t>("PulMulMin");
305 fiPulDetRef = fConfig->GetValue<uint64_t>("PulDetRef");
306 fiPulTotMin = fConfig->GetValue<uint64_t>("PulTotMin");
307 fiPulTotMax = fConfig->GetValue<uint64_t>("PulTotMax");
308 dTmax = (Double_t) fConfig->GetValue<uint64_t>("ReqTint");
309
310 //fTofCalDigisColl = new TClonesArray("CbmTofDigi", 100);
311 //fTofCalDigisCollOut = new TClonesArray("CbmTofDigi", 100);
312 fTofCalDigiVec = new std::vector<CbmTofDigi>();
313
314 fTofHitsColl = new TClonesArray("CbmTofHit", 100);
315 fTofHitsCollOut = new TClonesArray("CbmTofHit", 100);
316 fTofDigiMatchColl = new TClonesArray("CbmMatch", 100);
317 fTofDigiMatchCollOut = new TClonesArray("CbmMatch", 100);
318
319 /*
320 fDigiMan = CbmDigiManager::Instance();
321 fDigiMan->Init();
322 if (!fDigiMan->IsPresent(ECbmModuleId::kTof)) {
323 LOG(error) << "HitBuilder: No digi input!";
324 //return kFALSE;
325 }
326 */
327 if (fOutRootFileName != "") { // prepare root output
328
329 FairRunOnline* fRun = new FairRunOnline(0);
330 rootMgr = FairRootManager::Instance();
331 //fOutRootFile = rootMgr->OpenOutFile(fOutRootFileName);
332 if (rootMgr->InitSink()) {
333 fRun->SetSink(new FairRootFileSink(fOutRootFileName));
334 fOutRootFile = rootMgr->GetOutFile();
335 if (NULL == fOutRootFile) LOG(fatal) << "could not open root file";
336 }
337 else
338 LOG(fatal) << "could not init Sink";
339 }
340
341 // steering variables
342 fDutId = fConfig->GetValue<uint64_t>("DutType");
343 fDutSm = fConfig->GetValue<uint64_t>("DutSm");
344 fDutRpc = fConfig->GetValue<uint64_t>("DutRpc");
345
346 fSelId = fConfig->GetValue<uint64_t>("SelType");
347 fSelSm = fConfig->GetValue<uint64_t>("SelSm");
348 fSelRpc = fConfig->GetValue<uint64_t>("SelRpc");
349
350 fSel2Id = fConfig->GetValue<uint64_t>("Sel2Type");
351 fSel2Sm = fConfig->GetValue<uint64_t>("Sel2Sm");
352 fSel2Rpc = fConfig->GetValue<uint64_t>("Sel2Rpc");
353
354 fiBeamRefType = fConfig->GetValue<uint64_t>("BRefType");
355 fiBeamRefSm = fConfig->GetValue<uint64_t>("BRefSm");
356 fiBeamRefDet = fConfig->GetValue<uint64_t>("BRefDet");
357
358 return kTRUE;
359}
360
362{
363 if (NULL != fOutRootFile) {
364 LOG(info) << "Init Root Output to " << fOutRootFile->GetName();
365
366 /*
367 fFileHeader->SetRunId(iRunId);
368 rootMgr->WriteFileHeader(fFileHeader);
369 */
370 rootMgr->InitSink();
371 fEvtHeader = new FairEventHeader();
372 fEvtHeader->SetRunId(iRunId);
373 rootMgr->Register("EventHeader.", "Event", fEvtHeader, kTRUE);
374 auto source = rootMgr->GetSource();
375 if (source) { source->FillEventHeader(fEvtHeader); }
376
377 // rootMgr->Register("CbmTofDigi", "Tof raw Digi", fTofCalDigisColl, kTRUE);
378 // fOutRootFile->cd();
379 // rootMgr->RegisterAny("TofCalDigi", fTofCalDigiVec, kTRUE);
380 rootMgr->RegisterAny("TofDigi", fTofCalDigiVec, kTRUE);
381
382 TTree* outTree = new TTree(FairRootManager::GetTreeName(), "/cbmout", 99);
383 LOG(info) << "define Tree " << outTree->GetName();
384 //rootMgr->TruncateBranchNames(outTree, "cbmout");
385 //rootMgr->SetOutTree(outTree);
386 rootMgr->GetSink()->SetOutTree(outTree);
387 rootMgr->WriteFolder();
388 LOG(info) << "Initialized outTree with rootMgr at " << rootMgr;
389 /*
391 TFile* oldFile = gFile;
392 TDirectory* oldDir = gDirectory;
393 fOutRootFile = new TFile(fOutRootFileName,"recreate");
394 fRootEvent = new TTree("CbmEvent","Cbm Event");
395 fRootEvent->Branch("CbmDigi",fTofCalDigisColl);
396 LOG(info)<<"Open Root Output file " << fOutRootFileName;
397 fRootEvent->Write();
399 gFile = oldFile;
400 gDirectory = oldDir;
401 */
402 }
403 return kTRUE;
404}
405
406
408{
409 LOG(info) << "Init parameter containers for CbmDeviceHitBuilderTof.";
410
411 FairRuntimeDb* fRtdb = FairRuntimeDb::instance();
412 if (NULL == fRtdb) LOG(error) << "No FairRuntimeDb found";
413
414 // NewSimpleMessage creates a copy of the data and takes care of its destruction (after the transfer takes place).
415 // Should only be used for small data because of the cost of an additional copy
416
417 // Int_t fiRunId=1535700811; // from *geo*.par.root file
418 Int_t NSet = 3;
419 std::string parSet[NSet];
420 parSet[0] = "CbmTofDigiPar";
421 parSet[1] = "CbmTofDigiBdfPar";
422 parSet[2] = "FairGeoParSet";
423 std::string Channel = "parameters";
424
425 Bool_t isSimulation = kFALSE;
426 Int_t iGeoVersion;
427 FairParSet* cont;
428
429 for (Int_t iSet = 1; iSet < NSet; iSet++) {
430 std::string message = parSet[iSet] + "," + to_string(fiRunId);
431 LOG(info) << "Requesting parameter container, sending message: " << message;
432
433 FairMQMessagePtr req(NewSimpleMessage(message));
434 //FairMQMessagePtr req(NewSimpleMessage( "CbmTofDigiBdfPar,111" )); //original format
435 FairMQMessagePtr rep(NewMessage());
436 CbmTofCreateDigiPar* tofDigiPar = NULL;
437
438 if (Send(req, Channel) > 0) {
439 if (Receive(rep, Channel) >= 0) {
440 if (rep->GetSize() != 0) {
441 CbmMqTMessage tmsg(rep->GetData(), rep->GetSize());
442 switch (iSet) {
443 case 0:
444 fDigiPar = static_cast<CbmTofDigiPar*>(tmsg.ReadObject(tmsg.GetClass()));
445 //fDigiPar->print();
446 break;
447 case 1:
448 fDigiBdfPar = static_cast<CbmTofDigiBdfPar*>(tmsg.ReadObject(tmsg.GetClass()));
449 //fDigiBdfPar->print();
450 LOG(info) << "Calib data file: " << fDigiBdfPar->GetCalibFileName();
453
455 fdMaxTimeDist = fMaxTimeDist; // modify default
457 * 0.5; // cut consistently on positions (with default signal velocity)
458 }
459
460 break;
461 case 2: // Geometry container
462 cont = static_cast<FairParSet*>(tmsg.ReadObject(tmsg.GetClass()));
463 cont->init();
464 cont->Print();
465 //fRtdb->InitContainer(parSet[iSet]);
466 if (NULL == fGeoMan) fGeoMan = (TGeoManager*) ((FairGeoParSet*) cont)->GetGeometry(); //crashes
467 LOG(info) << "GeoMan: " << fGeoMan << " " << gGeoManager;
468 iGeoVersion = fGeoHandler->Init(isSimulation);
469 if (k21a > iGeoVersion) {
470 LOG(error) << "Incompatible geometry !!!";
471 ChangeState(fair::mq::Transition::Stop);
472 }
473 switch (iGeoVersion) {
474 case k14a: fTofId = new CbmTofDetectorId_v14a(); break;
475 case k21a: fTofId = new CbmTofDetectorId_v21a(); break;
476 }
477 if (NULL == fDigiPar) {
478 if (NULL == fRtdb) {
479 LOG(info) << "Instantiate FairRunDb";
480 fRtdb = FairRuntimeDb::instance();
481 assert(fRtdb);
482 }
483 // create digitization parameters from geometry file
484 tofDigiPar = new CbmTofCreateDigiPar("TOF Digi Producer", "TOF task");
485 LOG(info) << "Create DigiPar ";
486 tofDigiPar->Init();
487 fDigiPar = (CbmTofDigiPar*) (fRtdb->getContainer("CbmTofDigiPar"));
488 if (NULL == fDigiPar) {
489 LOG(error) << "CbmTofEventClusterizer::InitParameters => Could not obtain CbmTofDigiPar";
490 return kFALSE;
491 }
492 }
493 gGeoManager->Export("HitBuilder.geo.root");
494 break;
495
496 case 3: // Calib
497 break;
498 default: LOG(warn) << "Parameter Set " << iSet << " not implemented ";
499 }
500 LOG(info) << "Received parameter from server:";
501 }
502 else {
503 LOG(warn) << "Received empty reply. Parameter not available";
504 }
505 }
506 }
507 }
508 Bool_t initOK = ReInitContainers();
509
511
512 if (!InitCalibParameter()) return kFALSE; // ChangeState(PAUSE); // for debugging
513
517 if (fiBeamRefType > -1) {
518 if (fiBeamRefDet > -1) {
520 }
521 else {
524 }
525 }
526 else
527 fiBeamRefAddr = -1;
528
530 LOG(info) << Form("Use Dut 0x%08x, Sel 0x%08x, Sel2 0x%08x, BRef 0x%08x", fDutAddr, fSelAddr, fSel2Addr,
532 return initOK;
533}
534
536{
537 LOG(info) << "ReInit parameter containers for CbmDeviceHitBuilderTof.";
538
539 return kTRUE;
540}
541
542// handler is called whenever a message arrives on "data", with a reference to the message and a sub-channel index (here 0)
543//bool CbmDeviceHitBuilderTof::HandleData(FairMQMessagePtr& msg, int /*index*/)
544bool CbmDeviceHitBuilderTof::HandleData(FairMQParts& parts, int /*index*/)
545{
546 // Don't do anything with the data
547 // Maybe add an message counter which counts the incomming messages and add
548 // an output
549 fNumMessages++;
550 LOG(debug) << "Received message " << fNumMessages << " with " << parts.Size() << " parts"
551 << ", size0: " << parts.At(0)->GetSize();
552
553 std::string msgStrE(static_cast<char*>(parts.At(0)->GetData()), (parts.At(0))->GetSize());
554 std::istringstream issE(msgStrE);
555 boost::archive::binary_iarchive inputArchiveE(issE);
556 inputArchiveE >> fEventHeader;
557 LOG(debug) << "EventHeader: " << fEventHeader[0] << " " << fEventHeader[1] << " " << fEventHeader[2] << " "
558 << fEventHeader[3] << " " << fEventHeader[4];
559
560 fiNDigiIn = 0;
561 // LOG(debug) << "Received message # "<< fNumMessages
562 // << " with size " << msg->GetSize()<<" at "<< msg->GetData();
563
564 //std::string msgStr(static_cast<char*>(msg->GetData()), msg->GetSize());
565 std::string msgStr(static_cast<char*>(parts.At(1)->GetData()), (parts.At(1))->GetSize());
566 std::istringstream iss(msgStr);
567 boost::archive::binary_iarchive inputArchive(iss);
568
569 std::vector<CbmTofDigi*> vdigi;
570 inputArchive >> vdigi;
571
572 /* ---- for debugging ----------------
573 int *pData = static_cast <int *>(msg->GetData());
574 for (int iData=0; iData<msg->GetSize()/NBytes; iData++) {
575 LOG(info) << Form(" ind %d, poi %p, data: 0x%08x",iData,pData,*pData++);
576 }
577 */
578
579 //vector descriptor and data separated -> transfer of vectors does not work reliably
580 //std::vector<CbmTofDigi>* vdigi = static_cast<std::vector<CbmTofDigi>*>(msg->GetData());
581 // (*vdigi).resize(fiNDigiIn);
582 LOG(debug) << "vdigi vector at " << vdigi.data() << " with size " << vdigi.size();
583
584 for (UInt_t iDigi = 0; iDigi < vdigi.size(); iDigi++) {
585 LOG(debug) << "#" << iDigi << " " << vdigi[iDigi]->ToString();
586 }
587
588 /*
589 const Int_t iNDigiIn=100;
590 std::array<CbmTofDigi,iNDigiIn> *aTofDigi = static_cast<std::array<CbmTofDigi,iNDigiIn>*>(msg->GetData());
591 for (int iDigi=0; iDigi<fiNDigiIn; iDigi++) {
592 LOG(info) << "#" << iDigi << " " <<(*aTofDigi)[iDigi].ToString();
593 }
594
595
596 pDigiIn=static_cast<CbmTofDigi*> (msg->GetData());
597 CbmTofDigi* pDigi=pDigiIn;
598 CbmTofDigi aTofDigi[fiNDigiIn];
599
600
601 for (int iDigi=0; iDigi<fiNDigiIn; iDigi++) {
602 //aTofDigi[iDigi] = *pDigi++;
603 aTofDigi[iDigi] = *pDigi;
604 fvDigiIn[iDigi] = *pDigi;
605 LOG(info) << "#" << iDigi << " at "<<pDigi<< " " <<aTofDigi[iDigi].ToString();
606 // LOG(info) << "#" << iDigi << " at "<<pDigi<< " " <<pDigi->ToString(); // does not work ???
607 pDigi++;
608 }
609 */
610
611 fiNDigiIn = vdigi.size();
612 fvDigiIn.resize(fiNDigiIn);
613 for (int iDigi = 0; iDigi < fiNDigiIn; iDigi++) {
614 fvDigiIn[iDigi] = *vdigi[iDigi];
615
616 // Remap Digis for v21a_cosmicHD
617 if (1) {
618 int iSmType = 8;
619 int iSm = -1;
620 int iRpc = 0;
621 int iDetId = 0;
622 CbmTofDigi* pDigi = &fvDigiIn[iDigi];
623
624 if (pDigi->GetType() == 6 && pDigi->GetRpc() == 1) {
625 switch ((int) (pDigi->GetChannel() * 2 + pDigi->GetSide())) {
626 case 62: //800
627 iSm = 0;
628 break;
629 case 46: //810
630 iSm = 1;
631 break;
632 case 22: //820
633 iSm = 2;
634 break;
635 case 2: //830
636 iSm = 3;
637 break;
638 default:;
639 }
640 if (iSm > -1) {
641 iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType);
642 pDigi->SetAddress(iDetId);
643 }
644 }
645 } //remapping end
646
647 delete vdigi[iDigi];
648 }
649 vdigi.clear();
650
651 // for( Int_t i = 0; i < fTofCalDigisColl->GetEntriesFast(); i++ ) ((CbmTofDigi*) fTofCalDigisColl->At(i))->Delete();
652 // fTofCalDigisColl->Clear("C");
653
654 // for( Int_t i = 0; i < fTofHitsColl->GetEntriesFast(); i++ ) ((CbmTofHit*) fTofHitsColl->At(i))->Delete();
655 fTofHitsColl->Clear("C");
656 //fTofHitsColl->Delete(); // Are the elements deleted?
657 //fTofHitsColl = new TClonesArray("CbmTofHit",100);
658
659 //for( Int_t i = 0; i < fTofDigiMatchColl->GetEntriesFast(); i++ ) ((CbmMatch*) fTofDigiMatchColl->At(i))->Delete();
660 fTofDigiMatchColl->Clear("C");
661
662 fiNbHits = 0;
663 if (fNumMessages % 10000 == 0) LOG(info) << "Processed " << fNumMessages << " messages";
664 if (fEventHeader.size() > 3) {
665 fhPulMul->Fill((Double_t) fEventHeader[3]);
666 if (fEventHeader[3] > 0) {
667 //LOG(debug) << "Pulser event found, Mul "<< fEventHeader[3];
668 if (!MonitorPulser()) return kFALSE;
669 return kTRUE; // separate events from pulser
670 }
671 }
672
673 LOG(debug) << " Process msg " << fNumMessages << " at evt " << fdEvent << ", PulMode " << fiPulserMode;
674
675 if (fiPulserMode > 0) { // don't process events without valid pulser correction
676 if (fvPulserTimes[fiPulDetRef][0].size() == 0) return kTRUE;
677 }
678
679 fdEvent++;
680 fhEvDetMul->Fill((Double_t) fEventHeader[1]);
681 fhEvDigiMul->Fill(fiNDigiIn);
682 if (fiNDigiIn > 0) {
683 if (dTstart == 0) {
684 dTstart = fvDigiIn[0].GetTime() + fEventHeader[4];
685 LOG(info) << "Start time set to " << dTstart / 1.E9 << " sec ";
686 }
687 fhEvRateIn->Fill((fvDigiIn[0].GetTime() + fEventHeader[4] - dTstart) / 1.E9);
688 }
689 if (!InspectRawDigis()) return kFALSE;
690
691 if (fiPulserMode > 0)
692 if (!ApplyPulserCorrection()) return kFALSE;
693
694 if (!BuildClusters()) return kFALSE;
695 //if(!MergeClusters()) return kFALSE;
696
697 if (NULL != fOutRootFile) { // CbmEvent output to root file
698 fEvtHeader->SetEventTime((double) fEventHeader[4]);
699 auto source = rootMgr->GetSource();
700 if (source) { source->FillEventHeader(fEvtHeader); }
701 //LOG(info) << "Fill WriteOutBuffer with rootMgr at " << rootMgr;
702 fOutRootFile->cd();
703 rootMgr->Fill();
704 rootMgr->StoreWriteoutBufferData(rootMgr->GetEventTime());
705 fhEvRateOut->Fill((fvDigiIn[0].GetTime() + fEventHeader[4] - dTstart) / 1.E9);
706 //rootMgr->StoreAllWriteoutBufferData();
707 rootMgr->DeleteOldWriteoutBufferData();
708 if ((Int_t) fdEvent == fiMaxEvent) {
709 rootMgr->Write();
711 fOutRootFile->Close();
712 LOG(info) << "File closed after " << fdEvent << " events. ";
713 ChangeState(fair::mq::Transition::Stop);
714 }
715 }
716 if (!FillHistos()) return kTRUE; // event not selected for histogramming, skip sending it
717 //if(!SendHits()) return kFALSE;
718 if (!SendAll()) return kFALSE;
719
720 return kTRUE;
721}
722
723/************************************************************************************/
724
725bool CbmDeviceHitBuilderTof::HandleMessage(FairMQMessagePtr& msg, int /*index*/)
726{
727 const char* cmd = (char*) (msg->GetData());
728 const char cmda[4] = {*cmd};
729 LOG(info) << "Handle message " << cmd << ", " << cmd[0];
730 //LOG(info) << "Current State: " << fair::mq::StateMachine::GetCurrentStateName();
731
732 // only one implemented so far "Stop"
733 if (NULL != fOutRootFile) {
734 LOG(info) << "Close root file " << fOutRootFile->GetName();
735 fOutRootFile->cd();
736 rootMgr->LastFill();
737 rootMgr->Write();
739 fOutRootFile->Write();
740 fOutRootFile->Close();
741 }
742
743 if (strcmp(cmda, "STOP")) {
744 LOG(info) << "STOP";
745 /* Invalid syntax
746 ChangeState(internal_READY);
747 LOG(info) << "Current State: " << FairMQStateMachine::GetCurrentStateName();
748 ChangeState(internal_DEVICE_READY);
749 LOG(info) << "Current State: " << FairMQStateMachine::GetCurrentStateName();
750 ChangeState(internal_IDLE);
751 LOG(info) << "Current State: " << FairMQStateMachine::GetCurrentStateName();
752 ChangeState(END);
753 LOG(info) << "Current State: " << FairMQStateMachine::GetCurrentStateName();
754 */
755 ChangeState(fair::mq::Transition::Stop);
756 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
757 ChangeState(fair::mq::Transition::End);
758 }
759
760 return true;
761}
762
763/************************************************************************************/
765{
766 // dimension and initialize calib parameter
767 // Int_t iNbDet = fDigiBdfPar->GetNbDet();
768 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
769
770 fTotMean = 1.;
771 fCalMode = -1;
772
773 if (fTotMean != 0.) fdTTotMean = fTotMean; // adjust target mean for TTT
774
775 fvCPTOff.resize(iNbSmTypes);
776 fvCPTotGain.resize(iNbSmTypes);
777 fvCPTotOff.resize(iNbSmTypes);
778 fvCPWalk.resize(iNbSmTypes);
779 fvCPDelTof.resize(iNbSmTypes);
780 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
781 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
782 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
783 fvCPTOff[iSmType].resize(iNbSm * iNbRpc);
784 fvCPTotGain[iSmType].resize(iNbSm * iNbRpc);
785 fvCPTotOff[iSmType].resize(iNbSm * iNbRpc);
786 fvCPWalk[iSmType].resize(iNbSm * iNbRpc);
787 fvCPDelTof[iSmType].resize(iNbSm * iNbRpc);
788 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
789 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
790 //LOG(info)<<Form(" fvCPDelTof resize for SmT %d, R %d, B %d ",iSmType,iNbSm*iNbRpc,nbClDelTofBinX);
791 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc].resize(nbClDelTofBinX);
792 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
793 // LOG(info)<<Form(" fvCPDelTof for SmT %d, R %d, B %d",iSmType,iSm*iNbRpc+iRpc,iBx);
794 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx].resize(iNSel);
795 for (Int_t iSel = 0; iSel < iNSel; iSel++)
796 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] = 0.; // initialize
797 }
798
799 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc);
800 fvCPTOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
801 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
802 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
803 fvCPWalk[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
804 Int_t nbSide = 2 - fDigiBdfPar->GetChanType(iSmType, iRpc);
805 for (Int_t iCh = 0; iCh < iNbChan; iCh++) {
806 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
807 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
808 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
809 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh].resize(nbSide);
810 for (Int_t iSide = 0; iSide < nbSide; iSide++) {
811 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.; //initialize
812 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 1.; //initialize
813 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = 0.; //initialize
814 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide].resize(nbClWalkBinX);
815 for (Int_t iWx = 0; iWx < nbClWalkBinX; iWx++) {
816 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][iSide][iWx] = 0.;
817 }
818 }
819 }
820 }
821 }
822 }
823 LOG(info) << "defaults set";
824
826 // <= To prevent histos from being sucked in by the param file of the TRootManager!
827 TFile* oldFile = gFile;
828 TDirectory* oldDir = gDirectory;
829
830 if (0 < fCalMode) {
832 LOG(info) << "InitCalibParameter: read histos from "
833 << "file " << fCalParFileName;
834
835 // read parameter from histos
836 if (fCalParFileName.IsNull()) return kTRUE;
837
838 fCalParFile = new TFile(fCalParFileName, "");
839 if (NULL == fCalParFile) {
840 LOG(error) << "InitCalibParameter: "
841 << "file " << fCalParFileName << " does not exist!";
842 ChangeState(fair::mq::Transition::Stop);
843 }
844 /*
845 gDirectory->Print();
846 fCalParFile->cd();
847 fCalParFile->ls();
848 */
849 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
850 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
851 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
852 TProfile* hSvel = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Svel", iSmType));
853
854 // copy Histo to memory
855 TDirectory* curdir = gDirectory;
856 if (NULL != hSvel) {
857 gDirectory->cd(oldDir->GetPath());
858 //TProfile *hSvelmem =
859 //(TProfile*) hSvel->Clone();
860 gDirectory->cd(curdir->GetPath());
861 }
862 else {
863 LOG(info) << "Svel histogram not found for module type " << iSmType;
864 }
865
866 for (Int_t iPar = 0; iPar < 4; iPar++) {
867 TProfile* hFparcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Fpar%1d", iSmType, iPar));
868 if (NULL != hFparcur) {
869 gDirectory->cd(oldDir->GetPath());
870 //TProfile *hFparmem =
871 //(TProfile*) hFparcur->Clone();
872 gDirectory->cd(curdir->GetPath());
873 }
874 }
875
876 for (Int_t iSm = 0; iSm < iNbSm; iSm++)
877 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
878 // update default parameter
879 if (NULL != hSvel) {
880 Double_t Vscal = 1.; //hSvel->GetBinContent(iSm*iNbRpc+iRpc+1);
881 if (Vscal == 0.) Vscal = 1.;
882 fDigiBdfPar->SetSigVel(iSmType, iSm, iRpc, fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * Vscal);
883 LOG(info) << "Modify " << iSmType << iSm << iRpc << " Svel by " << Vscal << " to "
884 << fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
885 }
886 TH2F* htempPos_pfx =
887 (TH2F*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Pos_pfx", iSmType, iSm, iRpc));
888 TH2F* htempTOff_pfx =
889 (TH2F*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_TOff_pfx", iSmType, iSm, iRpc));
890 TH1D* htempTot_Mean =
891 (TH1D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Mean", iSmType, iSm, iRpc));
892 TH1D* htempTot_Off =
893 (TH1D*) gDirectory->FindObjectAny(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Tot_Off", iSmType, iSm, iRpc));
894 if (NULL != htempPos_pfx && NULL != htempTOff_pfx && NULL != htempTot_Mean && NULL != htempTot_Off) {
895 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
896 Int_t iNbinTot = htempTot_Mean->GetNbinsX();
897 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
898 Double_t YMean = ((TProfile*) htempPos_pfx)->GetBinContent(iCh + 1); //nh +1 empirical(?)
899 Double_t TMean = ((TProfile*) htempTOff_pfx)->GetBinContent(iCh + 1);
900 //Double_t dTYOff=YMean/fDigiBdfPar->GetSignalSpeed() ;
901 Double_t dTYOff = YMean / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
902 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0] += -dTYOff + TMean;
903 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] += +dTYOff + TMean;
904
905 for (Int_t iSide = 0; iSide < 2; iSide++) {
906 Double_t TotMean = htempTot_Mean->GetBinContent(iCh * 2 + 1 + iSide); //nh +1 empirical(?)
907 if (0.001 < TotMean) { fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] *= fdTTotMean / TotMean; }
908 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][iSide] = htempTot_Off->GetBinContent(iCh * 2 + 1 + iSide);
909 }
910
911 if (5 == iSmType || 8 == iSmType) {
912 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
913 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0];
914 fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][1] = fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh][0];
915 }
916
917 LOG(debug) << "InitCalibParameter:"
918 << " SmT " << iSmType << " Sm " << iSm << " Rpc " << iRpc << " Ch " << iCh
919 << Form(": YMean %f, TMean %f", YMean, TMean) << " -> "
920 << Form(" %f, %f, %f, %f ", fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][0],
921 fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh][1],
922 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][0],
923 fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh][1])
924 << ", NbinTot " << iNbinTot;
925 TH1D* htempWalk0 = (TH1D*) gDirectory->FindObjectAny(
926 Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S0_Walk_px", iSmType, iSm, iRpc, iCh));
927 TH1D* htempWalk1 = (TH1D*) gDirectory->FindObjectAny(
928 Form("Cor_SmT%01d_sm%03d_rpc%03d_Ch%03d_S1_Walk_px", iSmType, iSm, iRpc, iCh));
929 if (NULL != htempWalk0 && NULL != htempWalk1) { // reinitialize Walk array
930 LOG(debug) << "Initialize Walk correction for "
931 << Form(" SmT%01d_sm%03d_rpc%03d_Ch%03d", iSmType, iSm, iRpc, iCh);
932 if (htempWalk0->GetNbinsX() != nbClWalkBinX)
933 LOG(error) << "InitCalibParameter: Inconsistent Walk histograms";
934 for (Int_t iBin = 0; iBin < nbClWalkBinX; iBin++) {
935 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin] = htempWalk0->GetBinContent(iBin + 1);
936 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin] = htempWalk1->GetBinContent(iBin + 1);
937 //LOG(debug)<<Form(" SmT%01d_sm%03d_rpc%03d_Ch%03d bin %d walk %f ",iSmType, iSm, iRpc, iCh, iBin,
938 // fvCPWalk[iSmType][iSm*iNbRpc+iRpc][iCh][0][iBin]);
939 if (5 == iSmType || 8 == iSmType) { // Pad structure
940 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][1][iBin] =
941 fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh][0][iBin];
942 }
943 }
944 }
945 }
946 }
947 else {
948 LOG(warn) << " Calibration histos " << Form("cl_SmT%01d_sm%03d_rpc%03d_XXX", iSmType, iSm, iRpc)
949 << " not found. ";
950 }
951 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
952 TH1D* htmpDelTof = (TH1D*) gDirectory->FindObjectAny(
953 Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
954 if (NULL == htmpDelTof) {
955 LOG(debug) << " Histos " << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel)
956 << " not found. ";
957 continue;
958 }
959 LOG(debug) << " Load DelTof from histos "
960 << Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel) << ".";
961 for (Int_t iBx = 0; iBx < nbClDelTofBinX; iBx++) {
962 fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] += htmpDelTof->GetBinContent(iBx + 1);
963 }
964
965 // copy Histo to memory
966 // TDirectory * curdir = gDirectory;
967 gDirectory->cd(oldDir->GetPath());
968 TH1D* h1DelTof =
969 (TH1D*) htmpDelTof->Clone(Form("cl_CorSmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSm, iRpc, iSel));
970
971 LOG(debug) << " copy histo " << h1DelTof->GetName() << " to directory " << oldDir->GetName();
972 gDirectory->cd(curdir->GetPath());
973 }
974 }
975 }
976 }
977 // fCalParFile->Delete();
979 // <= To prevent histos from being sucked in by the param file of the TRootManager!
980 gFile = oldFile;
981 gDirectory = oldDir;
982
983 LOG(info) << "InitCalibParameter: initialization done";
984 return kTRUE;
985}
986
987static TH2F* fhBucDigiCor = NULL;
988/************************************************************************************/
989// Histogram definitions
991{
992 TDirectory* oldir = gDirectory; // <= To prevent histos from being sucked in by the param file of the TRootManager!
993 gROOT->cd(); // <= To prevent histos from being sucked in by the param file of the TRootManager !
994 // process event header info
995 fhEvDetMul = new TH1F("hEvDetMul", "Detector multiplicity of Selector; Mul", 50, 0, 50);
996 fhEvDigiMul = new TH1F("hEvDigiMul", "Digi multiplicity of Selector; Mul", 1000, 0, 10000);
997 fhEvRateIn = new TH1F("hEvRateIn", "Incoming Event rate; time (s); rate (Hz)", 10000, 0, 10000);
998 fhEvRateOut = new TH1F("hEvRateOut", "Outgoing Event rate; time (s); rate (Hz)", 10000, 0, 10000);
999 fhPulMul = new TH1F("hPulMul", "Pulser multiplicity; Mul", 110, 0, 110);
1000 fhDigiTdif = new TH1F("hDigiTdif", "Digi time difference; #Deltat ns)", 8000, -20, 20);
1001
1002 Int_t iNDet = 0;
1003 dTmax *= 2; // cover full range of selector
1004
1005 for (Int_t iModTyp = 0; iModTyp < 10; iModTyp++)
1006 iNDet += fDigiBdfPar->GetNbSm(iModTyp) * fDigiBdfPar->GetNbRpc(iModTyp);
1007
1008 fhPulserTimesRaw = new TH2F(Form("hPulserTimesRaw"), Form("Pulser Times uncorrected; Det# []; t - t0 [ns]"),
1009 iNDet * 2, 0, iNDet * 2, 999, -dTmax, dTmax);
1010
1011 fhPulserTimeRawEvo.resize(iNDet * 2);
1012 for (Int_t iDetSide = 0; iDetSide < iNDet * 2; iDetSide++) {
1013 fhPulserTimeRawEvo[iDetSide] = new TProfile(
1014 Form("hPulserTimeRawEvo_%d", iDetSide),
1015 Form("Raw Pulser TimeEvolution %d; PulserEvent# ; DeltaT [ns] ", iDetSide), 1000, 0., 1.E5, -dTmax, dTmax);
1016 }
1017
1018 fhPulserTimesCor = new TH2F(Form("hPulserTimesCor"), Form("Pulser Times corrected; Det# []; t - t0 [ns]"), iNDet * 2,
1019 0, iNDet * 2, 999, -10., 10.);
1020
1021 fhDigiTimesRaw = new TH2F(Form("hDigiTimesRaw"), Form("Digi Times uncorrected; Det# []; t - t0 [ns]"), iNDet * 2, 0,
1022 iNDet * 2, 999, -dTmax, dTmax);
1023
1024 fhDigiTimesCor = new TH2F(Form("hDigiTimesCor"), Form("Digi Times corrected; Det# []; t - t0 [ns]"), iNDet * 2, 0,
1025 iNDet * 2, 999, -dTmax, dTmax);
1026
1027 fhBucDigiCor = new TH2F(Form("hBucDigiCor"), Form("Buc Digi Correlation; ch1 []; ch2 []"), 128, 0, 128, 128, 0, 128);
1028
1029 Int_t iNbDet = fDigiBdfPar->GetNbDet();
1030 fDetIdIndexMap.clear();
1031 fhRpcDigiTot.resize(iNbDet);
1032 fhRpcDigiCor.resize(iNbDet);
1033 fviDetId.resize(iNbDet);
1034 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1035 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1036 fDetIdIndexMap[iUniqueId] = iDetIndx;
1037 fviDetId[iDetIndx] = iUniqueId;
1038 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1039 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1040 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1041 LOG(info) << "Index map entry " << iDetIndx << ": TSR " << iSmType << iSmId << iRpcId
1042 << Form(", addr 0x%08x", iUniqueId);
1043
1044 fhRpcDigiTot[iDetIndx] = new TH2F(
1045 Form("hDigiTot_SmT%01d_sm%03d_rpc%03d", iSmType, iSmId, iRpcId),
1046 Form("Digi Tot of Rpc #%03d in Sm %03d of type %d; digi 0; digi 1", iRpcId, iSmId, iSmType),
1047 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 256, 0, 256);
1048
1049 fhRpcDigiCor[iDetIndx] =
1050 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DigiCor", iSmType, iSmId, iRpcId),
1051 Form("Digi Correlation of Rpc #%03d in Sm %03d of type %d; digi 0; digi 1", iRpcId, iSmId, iSmType),
1052 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId),
1053 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1054 }
1055
1056 if (0 == fiMode) return; // no cluster histograms needed
1057
1058 // Sm related distributions
1066
1067 for (Int_t iS = 0; iS < fDigiBdfPar->GetNbSmTypes(); iS++) {
1068 Double_t YSCAL = 50.;
1069 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1070
1071 Int_t iUCellId(0);
1072 fChannelInfo = NULL;
1073
1074 // Cover the case that the geometry file does not contain the module
1075 // indexed with 0 of a certain module type BUT modules with higher indices.
1076 for (Int_t iSM = 0; iSM < fDigiBdfPar->GetNbSm(iS); iSM++) {
1077 iUCellId = CbmTofAddress::GetUniqueAddress(iSM, 0, 0, 0, iS);
1078 fChannelInfo = fDigiPar->GetCell(iUCellId);
1079
1080 // Retrieve geometry information from the first module of a certain
1081 // module type that is found in the geometry file.
1082 if (NULL != fChannelInfo) { break; }
1083 }
1084
1085 if (NULL == fChannelInfo) {
1086 LOG(warn) << "No DigiPar for SmType " << Form("%d, 0x%08x", iS, iUCellId);
1087 continue;
1088 }
1089 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1090
1091 fhSmCluPosition[iS] =
1092 new TH2F(Form("cl_SmT%01d_Pos", iS), Form("Clu position of SmType %d; Sm+Rpc# []; ypos [cm]", iS),
1093 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1094 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -YDMAX, YDMAX);
1095
1096 Double_t TSumMax = 1.E3;
1097 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1098 fhSmCluTOff[iS] =
1099 new TH2F(Form("cl_SmT%01d_TOff", iS), Form("Clu TimeZero in SmType %d; Sm+Rpc# []; TOff [ns]", iS),
1100 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1101 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -TSumMax, TSumMax);
1102
1103 TProfile* hSvelcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Svel", iS));
1104 if (NULL == hSvelcur) {
1105 fhSmCluSvel[iS] =
1106 new TProfile(Form("cl_SmT%01d_Svel", iS), Form("Clu Svel in SmType %d; Sm+Rpc# []; v/v_{nominal} ", iS),
1107 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1108 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0.8, 1.2);
1109 fhSmCluSvel[iS]->Sumw2();
1110 }
1111 else
1112 fhSmCluSvel[iS] = (TProfile*) hSvelcur->Clone();
1113
1114 fhSmCluFpar[iS].resize(4);
1115 for (Int_t iPar = 0; iPar < 4; iPar++) {
1116 TProfile* hFparcur = (TProfile*) gDirectory->FindObjectAny(Form("cl_SmT%01d_Fpar%1d", iS, iPar));
1117 if (NULL == hFparcur) {
1118 LOG(info) << "Histo " << Form("cl_SmT%01d_Fpar%1d", iS, iPar) << " not found, recreate ...";
1119 fhSmCluFpar[iS][iPar] = new TProfile(Form("cl_SmT%01d_Fpar%1d", iS, iPar),
1120 Form("Clu Fpar %d in SmType %d; Sm+Rpc# []; value ", iPar, iS),
1121 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1123 }
1124 else
1125 fhSmCluFpar[iS][iPar] = (TProfile*) hFparcur->Clone();
1126 }
1127
1128 fhTSmCluPosition[iS].resize(iNSel);
1129 fhTSmCluTOff[iS].resize(iNSel);
1130 fhTSmCluTRun[iS].resize(iNSel);
1131 for (Int_t iSel = 0; iSel < iNSel; iSel++) { // Loop over selectors
1132 fhTSmCluPosition[iS][iSel] = new TH2F(Form("cl_TSmT%01d_Sel%02d_Pos", iS, iSel),
1133 Form("Clu position of SmType %d under Selector %02d; Sm+Rpc# "
1134 "[]; ypos [cm]",
1135 iS, iSel),
1136 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1137 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -YDMAX, YDMAX);
1138 fhTSmCluTOff[iS][iSel] = new TH2F(Form("cl_TSmT%01d_Sel%02d_TOff", iS, iSel),
1139 Form("Clu TimeZero in SmType %d under Selector %02d; Sm+Rpc# "
1140 "[]; TOff [ns]",
1141 iS, iSel),
1142 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 0,
1143 fDigiBdfPar->GetNbSm(iS) * fDigiBdfPar->GetNbRpc(iS), 99, -TSumMax, TSumMax);
1144 fhTSmCluTRun[iS][iSel] = new TH2F(Form("cl_TSmT%01d_Sel%02d_TRun", iS, iSel),
1145 Form("Clu TimeZero in SmType %d under Selector %02d; Event# "
1146 "[]; TMean [ns]",
1147 iS, iSel),
1148 100, 0, MaxNbEvent, 99, -TSumMax, TSumMax);
1149 }
1150 }
1151
1152 // RPC related distributions
1153 LOG(info) << " Define Clusterizer histos for " << iNbDet << " detectors ";
1154
1155 fhRpcCluMul.resize(iNbDet);
1156 fhRpcCluRate.resize(iNbDet);
1157 fhRpcCluPosition.resize(iNbDet);
1158 fhRpcCluDelPos.resize(iNbDet);
1159 fhRpcCluDelMatPos.resize(iNbDet);
1160 fhRpcCluTOff.resize(iNbDet);
1161 fhRpcCluDelTOff.resize(iNbDet);
1162 fhRpcCluDelMatTOff.resize(iNbDet);
1163 fhRpcCluTrms.resize(iNbDet);
1164 fhRpcCluTot.resize(iNbDet);
1165 fhRpcCluSize.resize(iNbDet);
1166 fhRpcCluAvWalk.resize(iNbDet);
1167 fhRpcCluAvLnWalk.resize(iNbDet);
1168 fhRpcCluWalk.resize(iNbDet);
1169 fhRpcDTLastHits.resize(iNbDet);
1170 fhRpcDTLastHits_Tot.resize(iNbDet);
1171 fhRpcDTLastHits_CluSize.resize(iNbDet);
1172
1173
1174 if (fTotMax != 0.) fdTOTMax = fTotMax;
1175 if (fTotMin != 0.) fdTOTMin = fTotMin;
1176
1177 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1178 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1179 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1180 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1181 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1182 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, 0, 0, iSmType);
1183 fChannelInfo = fDigiPar->GetCell(iUCellId);
1184 if (NULL == fChannelInfo) {
1185 LOG(warn) << "No DigiPar for Det " << Form("0x%08x", iUCellId);
1186 continue;
1187 }
1188 LOG(info) << "DetIndx " << iDetIndx << ", SmType " << iSmType << ", SmId " << iSmId << ", RpcId " << iRpcId
1189 << " => UniqueId " << Form("(0x%08x, 0x%08x)", iUniqueId, iUCellId) << ", dx " << fChannelInfo->GetSizex()
1190 << ", dy " << fChannelInfo->GetSizey() << Form(" ChPoi: %p ", fChannelInfo) << ", nbCh "
1191 << fDigiBdfPar->GetNbChan(iSmType, 0);
1192
1193 // check access to all channel infos
1194 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1195 Int_t iCCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, iCh, 0, iSmType);
1196 fChannelInfo = fDigiPar->GetCell(iCCellId);
1197 if (NULL == fChannelInfo) LOG(warn) << Form("missing ChannelInfo for ch %d addr 0x%08x", iCh, iCCellId);
1198 }
1199
1200 fChannelInfo = fDigiPar->GetCell(iUCellId);
1201
1202 fhRpcCluMul[iDetIndx] =
1203 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_Mul", iSmType, iSmId, iRpcId),
1204 Form("Clu multiplicity of Rpc #%03d in Sm %03d of type %d; M []; Cnts", iRpcId, iSmId, iSmType),
1205 2. + 2. * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, 2. + 2. * fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1206
1207 fhRpcCluRate[iDetIndx] =
1208 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_rate", iSmType, iSmId, iRpcId),
1209 Form("Clu rate of Rpc #%03d in Sm %03d of type %d; Time (s); Rate (Hz)", iRpcId, iSmId, iSmType), 3600.,
1210 0., 3600.);
1211
1212 fhRpcDTLastHits[iDetIndx] = new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_DTLastHits", iSmType, iSmId, iRpcId),
1213 Form("Clu #DeltaT to last hits of Rpc #%03d in Sm %03d of type %d; log( "
1214 "#DeltaT (ns)); counts",
1215 iRpcId, iSmId, iSmType),
1216 100., 0., 10.);
1217
1218 fhRpcDTLastHits_Tot[iDetIndx] = new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot_DTLH", iSmType, iSmId, iRpcId),
1219 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d; log(#DeltaT (ns)); TOT "
1220 "[ns]",
1221 iRpcId, iSmId, iSmType),
1222 100, 0., 10., 100, fdTOTMin, 4. * fdTOTMax);
1223
1224 fhRpcDTLastHits_CluSize[iDetIndx] = new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_CluSize_DTLH", iSmType, iSmId, iRpcId),
1225 Form("Clu Size of Rpc #%03d in Sm %03d of type %d; log(#DeltaT (ns)); "
1226 "CluSize []",
1227 iRpcId, iSmId, iSmType),
1228 100, 0., 10., 16, 0.5, 16.5);
1229
1230 Double_t YSCAL = 50.;
1231 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1232 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1233 fhRpcCluPosition[iDetIndx] =
1234 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Pos", iSmType, iSmId, iRpcId),
1235 Form("Clu position of Rpc #%03d in Sm %03d of type %d; Strip []; ypos [cm]", iRpcId, iSmId, iSmType),
1236 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -YDMAX, YDMAX);
1237
1238 fhRpcCluDelPos[iDetIndx] =
1239 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelPos", iSmType, iSmId, iRpcId),
1240 Form("Clu position difference of Rpc #%03d in Sm %03d of type "
1241 "%d; Strip []; #Deltaypos(clu) [cm]",
1242 iRpcId, iSmId, iSmType),
1243 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -10., 10.);
1244
1245 fhRpcCluDelMatPos[iDetIndx] =
1246 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelMatPos", iSmType, iSmId, iRpcId),
1247 Form("Matched Clu position difference of Rpc #%03d in Sm %03d of type "
1248 "%d; Strip []; #Deltaypos(mat) [cm]",
1249 iRpcId, iSmId, iSmType),
1250 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -5., 5.);
1251
1252 Double_t TSumMax = 1.E3;
1253 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1254 fhRpcCluTOff[iDetIndx] = new TH2F(
1255 Form("cl_SmT%01d_sm%03d_rpc%03d_TOff", iSmType, iSmId, iRpcId),
1256 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d; Strip []; TOff [ns]", iRpcId, iSmId, iSmType),
1257 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -TSumMax, TSumMax);
1258
1259 fhRpcCluDelTOff[iDetIndx] =
1260 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelTOff", iSmType, iSmId, iRpcId),
1261 Form("Clu TimeZero Difference of Rpc #%03d in Sm %03d of type %d; Strip "
1262 "[]; #DeltaTOff(clu) [ns]",
1263 iRpcId, iSmId, iSmType),
1264 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -0.6, 0.6);
1265
1266 fhRpcCluDelMatTOff[iDetIndx] =
1267 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_DelMatTOff", iSmType, iSmId, iRpcId),
1268 Form("Clu TimeZero Difference of Rpc #%03d in Sm %03d of type %d; Strip "
1269 "[]; #DeltaTOff(mat) [ns]",
1270 iRpcId, iSmId, iSmType),
1271 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -0.6, 0.6);
1272
1273 fhRpcCluTrms[iDetIndx] =
1274 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Trms", iSmType, iSmId, iRpcId),
1275 Form("Clu Time RMS of Rpc #%03d in Sm %03d of type %d; Strip []; Trms [ns]", iRpcId, iSmId, iSmType),
1276 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, 0., 0.5);
1277
1278 fhRpcCluTot[iDetIndx] =
1279 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Tot", iSmType, iSmId, iRpcId),
1280 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d; StripSide []; TOT [ns]", iRpcId, iSmId, iSmType),
1281 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, 2 * fDigiBdfPar->GetNbChan(iSmType, iRpcId), 100,
1283
1284 fhRpcCluSize[iDetIndx] =
1285 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Size", iSmType, iSmId, iRpcId),
1286 Form("Clu size of Rpc #%03d in Sm %03d of type %d; Strip []; size [strips]", iRpcId, iSmId, iSmType),
1287 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 16, 0.5, 16.5);
1288
1289 // Walk histos
1290 fhRpcCluAvWalk[iDetIndx] = new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_AvWalk", iSmType, iSmId, iRpcId),
1291 Form("Walk in SmT%01d_sm%03d_rpc%03d_AvWalk", iSmType, iSmId, iRpcId),
1292 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1293
1294 fhRpcCluAvLnWalk[iDetIndx] =
1295 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_AvLnWalk", iSmType, iSmId, iRpcId),
1296 Form("Walk in SmT%01d_sm%03d_rpc%03d_AvLnWalk", iSmType, iSmId, iRpcId), nbClWalkBinX,
1297 TMath::Log10(fdTOTMax / 50.), TMath::Log10(fdTOTMax), nbClWalkBinY, -TSumMax, TSumMax);
1298
1299 fhRpcCluWalk[iDetIndx].resize(fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1300 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1301 fhRpcCluWalk[iDetIndx][iCh].resize(2);
1302 for (Int_t iSide = 0; iSide < 2; iSide++) {
1303 fhRpcCluWalk[iDetIndx][iCh][iSide] =
1304 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk", iSmType, iSmId, iRpcId, iCh, iSide),
1305 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Walk", iSmType, iSmId, iRpcId, iCh, iSide),
1306 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1307 }
1308 /*
1309 (fhRpcCluWalk[iDetIndx]).push_back( hTemp );
1310 */
1311 }
1312 }
1313
1314 // Trigger selected histograms
1315 if (0 < iNSel) {
1316
1317 fhSeldT.resize(iNSel);
1318 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1319 fhSeldT[iSel] = new TH2F(Form("cl_dt_Sel%02d", iSel), Form("Selector time %02d; dT [ns]", iSel), 99,
1320 -fdDelTofMax * 10., fdDelTofMax * 10., 16, -0.5, 15.5);
1321 }
1322
1323 fhTRpcCluMul.resize(iNbDet);
1324 fhTRpcCluPosition.resize(iNbDet);
1325 fhTRpcCluTOff.resize(iNbDet);
1326 fhTRpcCluTot.resize(iNbDet);
1327 fhTRpcCluSize.resize(iNbDet);
1328 fhTRpcCluAvWalk.resize(iNbDet);
1329 fhTRpcCluDelTof.resize(iNbDet);
1330 fhTRpcCludXdY.resize(iNbDet);
1331 fhTRpcCluWalk.resize(iNbDet);
1332 fhTRpcCluTOffDTLastHits.resize(iNbDet);
1333 fhTRpcCluTotDTLastHits.resize(iNbDet);
1334 fhTRpcCluSizeDTLastHits.resize(iNbDet);
1335 fhTRpcCluMemMulDTLastHits.resize(iNbDet);
1336
1337 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
1338 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
1339 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
1340 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
1341 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
1342 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, 0, 0, iSmType);
1343 fChannelInfo = fDigiPar->GetCell(iUCellId);
1344 if (NULL == fChannelInfo) {
1345 LOG(warn) << "No DigiPar for Det " << Form("0x%08x", iUCellId);
1346 continue;
1347 }
1348 LOG(debug) << "DetIndx " << iDetIndx << ", SmType " << iSmType << ", SmId " << iSmId << ", RpcId " << iRpcId
1349 << " => UniqueId " << Form("(0x%08x, 0x%08x)", iUniqueId, iUCellId) << ", dx "
1350 << fChannelInfo->GetSizex() << ", dy " << fChannelInfo->GetSizey() << Form(" poi: 0x%p ", fChannelInfo)
1351 << ", nbCh " << fDigiBdfPar->GetNbChan(iSmType, iRpcId);
1352
1353 fhTRpcCluMul[iDetIndx].resize(iNSel);
1354 fhTRpcCluPosition[iDetIndx].resize(iNSel);
1355 fhTRpcCluTOff[iDetIndx].resize(iNSel);
1356 fhTRpcCluTot[iDetIndx].resize(iNSel);
1357 fhTRpcCluSize[iDetIndx].resize(iNSel);
1358 fhTRpcCluAvWalk[iDetIndx].resize(iNSel);
1359 fhTRpcCluDelTof[iDetIndx].resize(iNSel);
1360 fhTRpcCludXdY[iDetIndx].resize(iNSel);
1361 fhTRpcCluWalk[iDetIndx].resize(iNSel);
1362 fhTRpcCluTOffDTLastHits[iDetIndx].resize(iNSel);
1363 fhTRpcCluTotDTLastHits[iDetIndx].resize(iNSel);
1364 fhTRpcCluSizeDTLastHits[iDetIndx].resize(iNSel);
1365 fhTRpcCluMemMulDTLastHits[iDetIndx].resize(iNSel);
1366
1367 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
1368 fhTRpcCluMul[iDetIndx][iSel] =
1369 new TH1F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Mul", iSmType, iSmId, iRpcId, iSel),
1370 Form("Clu multiplicity of Rpc #%03d in Sm %03d of type %d "
1371 "under Selector %02d; M []; cnts",
1372 iRpcId, iSmId, iSmType, iSel),
1373 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0., fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1374
1375 if (NULL == fhTRpcCluMul[iDetIndx][iSel]) LOG(error) << " Histo not generated !";
1376
1377 Double_t YSCAL = 50.;
1378 if (fPosYMaxScal != 0.) YSCAL = fPosYMaxScal;
1379 Double_t YDMAX = TMath::Max(2., fChannelInfo->GetSizey()) * YSCAL;
1380 fhTRpcCluPosition[iDetIndx][iSel] = new TH2F(
1381 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Pos", iSmType, iSmId, iRpcId, iSel),
1382 Form("Clu position of Rpc #%03d in Sm %03d of type %d under "
1383 "Selector %02d; Strip []; ypos [cm]",
1384 iRpcId, iSmId, iSmType, iSel),
1385 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 100, -YDMAX, YDMAX);
1386
1387 Double_t TSumMax = 1.E4;
1388 if (fTRefDifMax != 0.) TSumMax = fTRefDifMax;
1389 fhTRpcCluTOff[iDetIndx][iSel] = new TH2F(
1390 Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_TOff", iSmType, iSmId, iRpcId, iSel),
1391 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d under "
1392 "Selector %02d; Strip []; TOff [ns]",
1393 iRpcId, iSmId, iSmType, iSel),
1394 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 99, -TSumMax, TSumMax);
1395
1396 if (fTotMax != 0.) fdTOTMax = fTotMax;
1397 fhTRpcCluTot[iDetIndx][iSel] =
1398 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Tot", iSmType, iSmId, iRpcId, iSel),
1399 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d under "
1400 "Selector %02d; StripSide []; TOT [ns]",
1401 iRpcId, iSmId, iSmType, iSel),
1402 fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId) * 2, 100,
1404
1405 fhTRpcCluSize[iDetIndx][iSel] =
1406 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Size", iSmType, iSmId, iRpcId, iSel),
1407 Form("Clu size of Rpc #%03d in Sm %03d of type %d under "
1408 "Selector %02d; Strip []; size [strips]",
1409 iRpcId, iSmId, iSmType, iSel),
1410 fDigiBdfPar->GetNbChan(iSmType, iRpcId), 0, fDigiBdfPar->GetNbChan(iSmType, iRpcId), 16, 0.5, 16.5);
1411
1412 // Walk histos
1413 fhTRpcCluAvWalk[iDetIndx][iSel] =
1414 new TH2D(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_AvWalk", iSmType, iSmId, iRpcId, iSel),
1415 Form("Walk in SmT%01d_sm%03d_rpc%03d_Sel%02d_AvWalk; TOT; T-TSel", iSmType, iSmId, iRpcId, iSel),
1416 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1417
1418 // Tof Histos
1419 fhTRpcCluDelTof[iDetIndx][iSel] =
1420 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof", iSmType, iSmId, iRpcId, iSel),
1421 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_DelTof; TRef-TSel; T-TSel", iSmType, iSmId, iRpcId, iSel),
1422 nbClDelTofBinX, -fdDelTofMax, fdDelTofMax, nbClDelTofBinY, -TSumMax, TSumMax);
1423
1424 // Position deviation histos
1425 fhTRpcCludXdY[iDetIndx][iSel] =
1426 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_dXdY", iSmType, iSmId, iRpcId, iSel),
1427 Form("SmT%01d_sm%03d_rpc%03d_Sel%02d_dXdY; #Delta x [cm]; "
1428 "#Delta y [cm];",
1429 iSmType, iSmId, iRpcId, iSel),
1431
1432 fhTRpcCluWalk[iDetIndx][iSel].resize(fDigiBdfPar->GetNbChan(iSmType, iRpcId));
1433 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpcId); iCh++) {
1434 fhTRpcCluWalk[iDetIndx][iSel][iCh].resize(2);
1435 for (Int_t iSide = 0; iSide < 2; iSide++) {
1436 fhTRpcCluWalk[iDetIndx][iSel][iCh][iSide] = new TH2D(
1437 Form("cl_SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Sel%02d_Walk", iSmType, iSmId, iRpcId, iCh, iSide, iSel),
1438 Form("Walk in SmT%01d_sm%03d_rpc%03d_Ch%03d_S%01d_Sel%02d_Walk", iSmType, iSmId, iRpcId, iCh, iSide,
1439 iSel),
1440 nbClWalkBinX, fdTOTMin, fdTOTMax, nbClWalkBinY, -TSumMax, TSumMax);
1441 }
1442 }
1443
1444 fhTRpcCluTOffDTLastHits[iDetIndx][iSel] =
1445 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_TOff_DTLH", iSmType, iSmId, iRpcId, iSel),
1446 Form("Clu TimeZero of Rpc #%03d in Sm %03d of type %d under "
1447 "Selector %02d; log(#DeltaT (ns)); TOff [ns]",
1448 iRpcId, iSmId, iSmType, iSel),
1449 100, 0., 10., 99, -TSumMax, TSumMax);
1450
1451 fhTRpcCluTotDTLastHits[iDetIndx][iSel] =
1452 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Tot_DTLH", iSmType, iSmId, iRpcId, iSel),
1453 Form("Clu Tot of Rpc #%03d in Sm %03d of type %d under "
1454 "Selector %02d; log(#DeltaT (ns)); TOT [ns]",
1455 iRpcId, iSmId, iSmType, iSel),
1456 100, 0., 10., 100, fdTOTMin, fdTOTMax);
1457
1458 fhTRpcCluSizeDTLastHits[iDetIndx][iSel] =
1459 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_Size_DTLH", iSmType, iSmId, iRpcId, iSel),
1460 Form("Clu size of Rpc #%03d in Sm %03d of type %d under "
1461 "Selector %02d; log(#DeltaT (ns)); size [strips]",
1462 iRpcId, iSmId, iSmType, iSel),
1463 100, 0., 10., 10, 0.5, 10.5);
1464
1465 fhTRpcCluMemMulDTLastHits[iDetIndx][iSel] =
1466 new TH2F(Form("cl_SmT%01d_sm%03d_rpc%03d_Sel%02d_MemMul_DTLH", iSmType, iSmId, iRpcId, iSel),
1467 Form("Clu Memorized Multiplicity of Rpc #%03d in Sm %03d of type %d "
1468 "under Selector %02d; log(#DeltaT (ns)); TOff [ns]",
1469 iRpcId, iSmId, iSmType, iSel),
1470 100, 0., 10., 10, 0, 10);
1471 }
1472 }
1473 }
1474
1475 gDirectory->cd(oldir->GetPath()); // <= To prevent histos from being sucked in by the param file of the TRootManager!
1476
1477 return;
1478}
1479/************************************************************************************/
1481{
1482 TList* tHistoList(NULL);
1483 tHistoList = gROOT->GetList();
1484
1485 TIter next(tHistoList);
1486 // Write histogramms to the file
1487 fOutRootFile->cd();
1488 {
1489 TH1* h;
1490 TObject* obj;
1491 while ((obj = (TObject*) next())) {
1492 if (obj->InheritsFrom(TH1::Class())) {
1493 h = (TH1*) obj;
1494 // cout << "Write histo " << h->GetTitle() << endl;
1495 h->Write();
1496 }
1497 }
1498 }
1499}
1500
1501/************************************************************************************/
1503{
1504 fiNevtBuild++;
1505 if (!CalibRawDigis()) return kFALSE;
1506 if (0 == fiMode) return kTRUE; // no customer yet
1507 if (!FillDigiStor()) return kFALSE;
1508 if (!BuildHits()) return kFALSE;
1509 return kTRUE;
1510}
1511
1512/************************************************************************************/
1514{
1515 Int_t iNbTofDigi = fiNDigiIn;
1516 pRef = NULL;
1517 for (Int_t iDigInd = 0; iDigInd < fiNDigiIn; iDigInd++) {
1518 CbmTofDigi* pDigi = &fvDigiIn[iDigInd];
1519 //LOG(debug)<<iDigInd<<" "<<pDigi;
1520 Int_t iAddr = pDigi->GetAddress() & DetMask;
1521 Int_t iDetIndx = fDigiBdfPar->GetDetInd(iAddr);
1522 /*
1523 LOG(info)<<iDigInd
1524 //<<Form(" Address : 0x%08x ",pDigi->GetAddress())
1525 <<Form(" TSRCS %d%d%d%02d%d ", (int)pDigi->GetType(),
1526 (int)pDigi->GetSm(),(int)pDigi->GetRpc(),(int)pDigi->GetChannel(),(int)pDigi->GetSide())
1527 <<" : " << Form("Ind %2d, T %15.3f, Tot %5.1f",iDetIndx,pDigi->GetTime(),pDigi->GetTot());
1528 */
1529
1530 if (fiBeamRefAddr < 0 || iAddr == fiBeamRefAddr) {
1531 //LOG(debug) << Form("Ref digi found for 0x%08x, Mask 0x%08x ", fiBeamRefAddr, DetMask);
1532 if (NULL == pRef) pRef = pDigi;
1533 else {
1534 if (pDigi->GetTime() < pRef->GetTime()) pRef = pDigi;
1535 }
1536 }
1537
1538 if (fDigiBdfPar->GetNbDet() - 1 < iDetIndx || iDetIndx < 0) {
1539 LOG(warn) << Form(" Wrong DetIndx %d >< %d,0 ", iDetIndx, fDigiBdfPar->GetNbDet());
1540 break;
1541 }
1542
1543 fhRpcDigiTot[iDetIndx]->Fill(2 * pDigi->GetChannel() + pDigi->GetSide(), pDigi->GetTot());
1544
1545 if (NULL == fhRpcDigiCor[iDetIndx]) {
1546 if (100 < iMess++)
1547 LOG(warn) << Form(" DigiCor Histo for DetIndx %d derived from 0x%08x not found", iDetIndx,
1548 pDigi->GetAddress());
1549 continue;
1550 }
1551
1552 Double_t dTDifMin = dDoubleMax;
1553 CbmTofDigi* pDigi2Min = NULL;
1554 // for (Int_t iDigI2 =iDigInd+1; iDigI2<iNbTofDigi;iDigI2++){
1555 for (Int_t iDigI2 = 0; iDigI2 < iNbTofDigi; iDigI2++) {
1556 CbmTofDigi* pDigi2 = &fvDigiIn[iDigI2];
1557 if (pDigi != pDigi2) { fhDigiTdif->Fill(pDigi->GetTime() - pDigi2->GetTime()); }
1558 if (pDigi->GetAddress() != pDigi2->GetAddress())
1559 if (pDigi->GetType() == 6 && pDigi2->GetType() == 6)
1560 fhBucDigiCor->Fill(pDigi->GetRpc() * 64 + pDigi->GetChannel() * 2 + pDigi->GetSide(),
1561 pDigi2->GetRpc() * 64 + pDigi2->GetChannel() * 2 + pDigi2->GetSide());
1562
1563 if (iDetIndx == fDigiBdfPar->GetDetInd(pDigi2->GetAddress())) {
1564 /*
1565 LOG(info) <<" Correlate DetIndx "<<iDetIndx
1566 <<Form(", TSRCS %d%d%d%02d%d ", (int)pDigi->GetType(),
1567 (int)pDigi->GetSm(),(int)pDigi->GetRpc(),(int)pDigi->GetChannel(),(int)pDigi->GetSide())
1568 <<Form(" with %d%d%d%02d%d ", (int)pDigi2->GetType(),
1569 (int)pDigi2->GetSm(),(int)pDigi2->GetRpc(),(int)pDigi2->GetChannel(),(int)pDigi2->GetSide());
1570 */
1571 if (0. == pDigi->GetSide() && 1. == pDigi2->GetSide()) {
1572 fhRpcDigiCor[iDetIndx]->Fill(pDigi->GetChannel(), pDigi2->GetChannel());
1573 }
1574 else {
1575 if (1. == pDigi->GetSide() && 0. == pDigi2->GetSide()) {
1576 fhRpcDigiCor[iDetIndx]->Fill(pDigi2->GetChannel(), pDigi->GetChannel());
1577 }
1578 }
1579 if (pDigi->GetSide() != pDigi2->GetSide()) {
1580 if (pDigi->GetChannel() == pDigi2->GetChannel()) {
1581 Double_t dTDif = TMath::Abs(pDigi->GetTime() - pDigi2->GetTime());
1582 if (dTDif < dTDifMin) {
1583 dTDifMin = dTDif;
1584 pDigi2Min = pDigi2;
1585 //LOG(debug) << "Digi2 found at "<<iDigI2<<" with TDif = "<<dTDifMin<<" ns";
1586 }
1587 }
1588 else if (TMath::Abs(pDigi->GetChannel() - pDigi2->GetChannel())
1589 == 1) { // opposite side missing, neighbouring channel has hit on opposite side // FIXME
1590 // check that same side digi of neighbouring channel is absent
1591 Int_t iDigI3 = 0;
1592 for (; iDigI3 < iNbTofDigi; iDigI3++) {
1593 CbmTofDigi* pDigi3 = &fvDigiIn[iDigI3];
1594 if (pDigi3->GetSide() == pDigi->GetSide() && pDigi2->GetChannel() == pDigi3->GetChannel()) break;
1595 }
1596 if (iDigI3 == iNbTofDigi) { // same side neighbour did not fire
1597 Int_t iCorMode = 0; // Missing hit correction mode
1598 switch (iCorMode) {
1599 case 0: // no action
1600 break;
1601 case 1: // shift found hit
1602 LOG(debug) << Form("shift channel %d%d%d%d%d and ", (Int_t) pDigi->GetType(), (Int_t) pDigi->GetSm(),
1603 (Int_t) pDigi->GetRpc(), (Int_t) pDigi->GetChannel(), (Int_t) pDigi->GetSide())
1604 << Form(" %d%d%d%d%d ", (Int_t) pDigi2->GetType(), (Int_t) pDigi2->GetSm(),
1605 (Int_t) pDigi2->GetRpc(), (Int_t) pDigi2->GetChannel(), (Int_t) pDigi2->GetSide());
1606 //if(pDigi->GetTime() < pDigi2->GetTime())
1607 if (pDigi->GetSide() == 0)
1608 pDigi2->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi->GetChannel(), 1 - pDigi->GetSide(),
1609 pDigi->GetType());
1610 else
1611 pDigi->SetAddress(pDigi2->GetSm(), pDigi2->GetRpc(), pDigi2->GetChannel(), 1 - pDigi2->GetSide(),
1612 pDigi2->GetType());
1613
1614 LOG(debug) << Form("resultchannel %d%d%d%d%d and ", (Int_t) pDigi->GetType(), (Int_t) pDigi->GetSm(),
1615 (Int_t) pDigi->GetRpc(), (Int_t) pDigi->GetChannel(), (Int_t) pDigi->GetSide())
1616 << Form(" %d%d%d%d%d ", (Int_t) pDigi2->GetType(), (Int_t) pDigi2->GetSm(),
1617 (Int_t) pDigi2->GetRpc(), (Int_t) pDigi2->GetChannel(), (Int_t) pDigi2->GetSide());
1618 break;
1619 case 2: // insert missing hits
1620 CbmTofDigi* pDigiN = new CbmTofDigi(*pDigi);
1621 pDigiN->SetAddress(pDigi->GetSm(), pDigi->GetRpc(), pDigi2->GetChannel(), pDigi->GetSide(),
1622 pDigi->GetType());
1623 pDigiN->SetTot(pDigi2->GetTot());
1624 fvDigiIn.push_back(*pDigiN);
1625
1626 CbmTofDigi* pDigiN2 = new CbmTofDigi(*pDigi2);
1627 pDigiN2->SetAddress(pDigi2->GetSm(), pDigi2->GetRpc(), pDigi->GetChannel(), pDigi2->GetSide(),
1628 pDigi2->GetType());
1629 pDigiN2->SetTot(pDigi->GetTot());
1630 fvDigiIn.push_back(*pDigiN2);
1631
1632 break;
1633 }
1634 }
1635 }
1636 }
1637 }
1638 }
1639 if (pDigi2Min != NULL) {
1640 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, pDigi->GetType(), pDigi->GetSm(), pDigi->GetRpc(), 0,
1641 pDigi->GetChannel());
1642 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
1643 fChannelInfo = fDigiPar->GetCell(iChId);
1644 if (NULL == fChannelInfo) {
1645 LOG(warn) << Form("Invalid ChannelInfo for 0x%08x, 0x%08x", iChId, pDigi2Min->GetAddress()) << " TSRC "
1646 << pDigi->GetType() << pDigi->GetSm() << pDigi->GetRpc() << pDigi->GetChannel();
1647 continue;
1648 }
1649 if (fDigiBdfPar->GetSigVel(pDigi->GetType(), pDigi->GetSm(), pDigi->GetRpc()) * dTDifMin * 0.5
1651 //check consistency
1652 if (8 == pDigi->GetType() || 5 == pDigi->GetType()) {
1653 if (pDigi->GetTime() != pDigi2Min->GetTime()) {
1654 if (fiMsgCnt-- > 0) {
1655 LOG(warn) << "Inconsistent duplicated digis in event " << fiNevtBuild << ", Ind: " << iDigInd;
1656 LOG(warn) << " " << pDigi->ToString();
1657 LOG(warn) << " " << pDigi2Min->ToString();
1658 }
1659 pDigi2Min->SetTot(pDigi->GetTot());
1660 pDigi2Min->SetTime(pDigi->GetTime());
1661 }
1662 }
1663 }
1664 }
1665 }
1666
1667 if (NULL != pRef) {
1668 // LOG(debug) << Form("pRef from 0x%08x ",pRef->GetAddress());
1669
1670 for (Int_t iDigInd = 0; iDigInd < fiNDigiIn; iDigInd++) {
1671 CbmTofDigi* pDigi = &fvDigiIn[iDigInd];
1672 Int_t iAddr = pDigi->GetAddress() & DetMask;
1673 Int_t iDet = fDetIdIndexMap[iAddr]; // Detector Index
1674 Int_t iSide = pDigi->GetSide();
1675 fhDigiTimesRaw->Fill(iDet * 2 + iSide, pDigi->GetTime() - pRef->GetTime());
1676 }
1677 }
1678 return kTRUE;
1679}
1680
1681/************************************************************************************/
1683{
1684 CbmTofDigi* pDigi;
1685 CbmTofDigi* pCalDigi = NULL;
1686 Int_t iDigIndCal = -1;
1687 // channel deadtime map
1688 std::map<Int_t, Double_t> mChannelDeadTime;
1689 fTofCalDigiVec->clear();
1690
1691 Int_t iNbTofDigi = fvDigiIn.size();
1692 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
1693 pDigi = (CbmTofDigi*) &fvDigiIn[iDigInd];
1694 Int_t iAddr = pDigi->GetAddress();
1695 /*
1696 LOG(debug)<<"BC " // Before Calibration
1697 <<Form("0x%08x",pDigi->GetAddress())<<" TSRC "
1698 <<pDigi->GetType()
1699 <<pDigi->GetSm()
1700 <<pDigi->GetRpc()
1701 <<Form("%2d",(Int_t)pDigi->GetChannel())<<" "
1702 <<pDigi->GetSide()<<" "
1703 <<Form("%f",pDigi->GetTime())<<" "
1704 <<pDigi->GetTot();
1705 */
1706 if (pDigi->GetType() == 5 || pDigi->GetType() == 8) // for Pad counters generate fake digi to mockup a strip
1707 if (pDigi->GetSide() == 1) continue; // skip one side to avoid double entries
1708
1709 Bool_t bValid = kTRUE;
1710 std::map<Int_t, Double_t>::iterator it;
1711 it = mChannelDeadTime.find(iAddr);
1712 if (it != mChannelDeadTime.end()) {
1713 /*
1714 LOG(debug)<<"CCT found valid ChannelDeadtime entry "<<mChannelDeadTime[iAddr]
1715 <<", DeltaT "<<pDigi->GetTime()-mChannelDeadTime[iAddr];
1716 */
1717 if ((bValid = (pDigi->GetTime() > mChannelDeadTime[iAddr] + fdChannelDeadtime))) {
1718 // pCalDigi =
1719 // new ((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi(*pDigi);
1720 fTofCalDigiVec->push_back(CbmTofDigi(*pDigi));
1721 pCalDigi = &(fTofCalDigiVec->back());
1722 iDigIndCal++;
1723 }
1724 }
1725 else {
1726 // pCalDigi = new ((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi(*pDigi);
1727 fTofCalDigiVec->push_back(CbmTofDigi(*pDigi));
1728 pCalDigi = &(fTofCalDigiVec->back());
1729 iDigIndCal++;
1730 }
1731 mChannelDeadTime[iAddr] = pDigi->GetTime();
1732 if (!bValid) continue;
1733 if (pRef != NULL)
1734 if (pDigi == pRef) pRefCal = pCalDigi;
1735 /*
1736 LOG(debug)<<"DC " // After deadtime check. before Calibration
1737 <<Form("0x%08x",pDigi->GetAddress())<<" TSRC "
1738 <<pDigi->GetType()
1739 <<pDigi->GetSm()
1740 <<pDigi->GetRpc()
1741 <<Form("%2d",(Int_t)pDigi->GetChannel())<<" "
1742 <<pDigi->GetSide()<<" "
1743 <<Form("%f",pDigi->GetTime())<<" "
1744 <<pDigi->GetTot();
1745 */
1746
1747 if (fbPs2Ns) {
1748 pCalDigi->SetTime(pCalDigi->GetTime() / 1000.); // for backward compatibility
1749 pCalDigi->SetTot(pCalDigi->GetTot() / 1000.); // for backward compatibility
1750 }
1751 if (fDigiBdfPar->GetNbSmTypes() > pDigi->GetType() // prevent crash due to misconfiguration
1752 && fDigiBdfPar->GetNbSm(pDigi->GetType()) > pDigi->GetSm()
1753 && fDigiBdfPar->GetNbRpc(pDigi->GetType()) > pDigi->GetRpc()
1754 && fDigiBdfPar->GetNbChan(pDigi->GetType(), pDigi->GetRpc()) > pDigi->GetChannel()) {
1755 // apply calibration vectors
1756 pCalDigi->SetTime(pCalDigi->GetTime() - // calibrate Digi Time
1757 fvCPTOff[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
1758 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()]);
1759 // LOG(debug)<<" CluCal-TOff: "<<pCalDigi->ToString();
1760
1761 Double_t dTot = pCalDigi->GetTot() - // subtract Offset
1762 fvCPTotOff[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
1763 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()];
1764 if (dTot < 0.001) dTot = 0.001;
1765 pCalDigi->SetTot(dTot * // calibrate Digi ToT
1766 fvCPTotGain[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType())
1767 + pDigi->GetRpc()][pDigi->GetChannel()][pDigi->GetSide()]);
1768
1769 // walk correction
1770 Double_t dTotBinSize = (fdTOTMax - fdTOTMin) / nbClWalkBinX;
1771 Int_t iWx = (Int_t)((pCalDigi->GetTot() - fdTOTMin) / dTotBinSize);
1772 if (0 > iWx) iWx = 0;
1773 if (iWx >= nbClWalkBinX) iWx = nbClWalkBinX - 1;
1774 Double_t dDTot = (pCalDigi->GetTot() - fdTOTMin) / dTotBinSize - (Double_t) iWx - 0.5;
1775 Double_t dWT =
1776 fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
1777 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx];
1778 if (dDTot > 0) { // linear interpolation to next bin
1779 if (iWx < nbClWalkBinX - 1) { // linear interpolation to next bin
1780
1781 dWT +=
1782 dDTot
1783 * (fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
1784 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx + 1]
1785 - fvCPWalk[pCalDigi->GetType()]
1786 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
1787 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]); //memory leak???
1788 }
1789 }
1790 else // dDTot < 0, linear interpolation to next bin
1791 {
1792 if (0 < iWx) { // linear interpolation to next bin
1793 dWT -=
1794 dDTot
1795 * (fvCPWalk[pCalDigi->GetType()][pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType())
1796 + pCalDigi->GetRpc()][pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx - 1]
1797 - fvCPWalk[pCalDigi->GetType()]
1798 [pCalDigi->GetSm() * fDigiBdfPar->GetNbRpc(pCalDigi->GetType()) + pCalDigi->GetRpc()]
1799 [pCalDigi->GetChannel()][pCalDigi->GetSide()][iWx]); //memory leak???
1800 }
1801 }
1802 pCalDigi->SetTime(pCalDigi->GetTime() - dWT); // calibrate Digi Time
1803 // LOG(debug)<<" CluCal-Walk: "<<pCalDigi->ToString();
1804 }
1805 else {
1806 LOG(info) << "Skip1 Digi "
1807 << " Type " << pDigi->GetType() << " " << fDigiBdfPar->GetNbSmTypes() << " Sm " << pDigi->GetSm() << " "
1808 << fDigiBdfPar->GetNbSm(pDigi->GetType()) << " Rpc " << pDigi->GetRpc() << " "
1809 << fDigiBdfPar->GetNbRpc(pDigi->GetType()) << " Ch " << pDigi->GetChannel() << " "
1810 << fDigiBdfPar->GetNbChan(pDigi->GetType(), 0);
1811 }
1812 if (pCalDigi->GetType() == 5
1813 || pCalDigi->GetType() == 8) { // for Pad counters generate fake digi to mockup a strip
1814 //CbmTofDigi* pCalDigi2 =
1815 // new ((*fTofCalDigisColl)[++iDigIndCal]) CbmTofDigi(*pCalDigi);
1816 fTofCalDigiVec->push_back(CbmTofDigi(*pCalDigi));
1817 CbmTofDigi* pCalDigi2 = &(fTofCalDigiVec->back());
1818 iDigIndCal++;
1819 if (pCalDigi->GetSide() == 0)
1820 pCalDigi2->SetAddress(pCalDigi->GetSm(), pCalDigi->GetRpc(), pCalDigi->GetChannel(), 1, pCalDigi->GetType());
1821 else
1822 pCalDigi2->SetAddress(pCalDigi->GetSm(), pCalDigi->GetRpc(), pCalDigi->GetChannel(), 0, pCalDigi->GetType());
1823 }
1824 } // for( Int_t iDigInd = 0; iDigInd < nTofDigi; iDigInd++ )
1825
1826 iNbTofDigi = fTofCalDigiVec->size();
1827 // fTofCalDigisColl->GetEntriesFast(); // update because of added duplicted digis
1828 LOG(debug) << "CbmTofHitBuilder: Sort " << fTofCalDigiVec->size() << " calibrated digis ";
1829 if (iNbTofDigi > 1) {
1830 // fTofCalDigisColl->Sort(iNbTofDigi); // Time order again, in case modified by the calibration
1832 std::sort(fTofCalDigiVec->begin(), fTofCalDigiVec->end(),
1833 [](const CbmTofDigi& a, const CbmTofDigi& b) -> bool { return a.GetTime() < b.GetTime(); });
1834 // std::sort(fTofCalDigiVec->begin(), fTofCalDigiVec->end());
1835 // if(!fTofCalDigisColl->IsSorted()){
1836 // if ( ! std::is_sorted(fTofCalDigiVec->begin(), fTofCalDigiVec->end()))
1837 if (!std::is_sorted(fTofCalDigiVec->begin(), fTofCalDigiVec->end(),
1838 [](const CbmTofDigi& a, const CbmTofDigi& b) -> bool { return a.GetTime() < b.GetTime(); }))
1839 LOG(warning) << "CbmTofHitBuilder: Digi sorting not successful ";
1840 }
1841
1842 if (NULL != pRef) {
1843 // LOG(debug) << Form("pRef from 0x%08x ",pRef->GetAddress());
1844
1845 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
1846 // pDigi = (CbmTofDigi*) fTofCalDigisColl->At(iDigInd);
1847 pDigi = &(fTofCalDigiVec->at(iDigInd));
1848 Int_t iAddr = pDigi->GetAddress() & DetMask;
1849 Int_t iDet = fDetIdIndexMap[iAddr]; // Detector Index
1850 Int_t iSide = pDigi->GetSide();
1851 fhDigiTimesCor->Fill(iDet * 2 + iSide, pDigi->GetTime() - pRefCal->GetTime());
1852 }
1853 }
1854 return kTRUE;
1855}
1856
1857/************************************************************************************/
1859{
1860 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
1861 // Hit variables
1862 Double_t dWeightedTime = 0.0;
1863 Double_t dWeightedPosX = 0.0;
1864 Double_t dWeightedPosY = 0.0;
1865 Double_t dWeightedPosZ = 0.0;
1866 Double_t dWeightsSum = 0.0;
1867 //vPtsRef.clear();
1868 vDigiIndRef.clear();
1869 //CbmTofCell *fTrafoCell=NULL;
1870 //Int_t iTrafoCell=-1;
1871 Int_t iNbChanInHit = 0;
1872 // Last Channel Temp variables
1873 Int_t iLastChan = -1;
1874 Double_t dLastPosX = 0.0; // -> Comment to remove warning because set but never used
1875 Double_t dLastPosY = 0.0;
1876 Double_t dLastTime = 0.0;
1877 // Channel Temp variables
1878 Double_t dPosX = 0.0;
1879 Double_t dPosY = 0.0;
1880 Double_t dPosZ = 0.0;
1881 Double_t dTime = 0.0;
1882 Double_t dTimeDif = 0.0;
1883 Double_t dTotS = 0.0;
1884 Int_t fiNbSameSide = 0;
1885
1886 // gGeoManager->SetTopVolume( gGeoManager->FindVolumeFast("tof_v14a") );
1887 gGeoManager->SetTopVolume(gGeoManager->FindVolumeFast("cave"));
1888 gGeoManager->CdTop();
1889
1890 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
1891 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
1892 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
1893 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
1894 for (Int_t iSm = 0; iSm < iNbSm; iSm++)
1895 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
1896 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
1897 Int_t iChType = fDigiBdfPar->GetChanType(iSmType, iRpc);
1898 /*
1899 LOG(debug)<<"RPC - Loop "
1900 << Form(" %3d %3d %3d %3d ",iSmType,iSm,iRpc,iChType);
1901 */
1902 fviClusterMul[iSmType][iSm][iRpc] = 0;
1903 Int_t iChId = 0;
1904 Int_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType);
1905 ;
1906 Int_t iDetIndx = fDetIdIndexMap[iDetId]; // Detector Index
1907 if (0 == iChType) {
1908 // Don't spread clusters over RPCs!!!
1909 dWeightedTime = 0.0;
1910 dWeightedPosX = 0.0;
1911 dWeightedPosY = 0.0;
1912 dWeightedPosZ = 0.0;
1913 dWeightsSum = 0.0;
1914 iNbChanInHit = 0;
1915 //vPtsRef.clear();
1916 // For safety reinitialize everything
1917 iLastChan = -1;
1918 // dLastPosX = 0.0; // -> Comment to remove warning because set but never used
1919 dLastPosY = 0.0;
1920 dLastTime = 0.0;
1921 //LOG(debug2)<<"ChanOrient "
1922 // << Form(" %3d %3d %3d %3d %3d ",iSmType,iSm,iRpc,fDigiBdfPar->GetChanOrient( iSmType, iRpc ),iNbCh);
1923
1924 if (1 == fDigiBdfPar->GetChanOrient(iSmType, iRpc)) {
1925 // Horizontal strips => X comes from left right time difference
1926 } // if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
1927 else { // Vertical strips => Y comes from bottom top time difference
1928 for (Int_t iCh = 0; iCh < iNbCh; iCh++) {
1929 //LOG(debug3)<<"VDigisize "
1930 // << Form(" T %3d Sm %3d R %3d Ch %3d Size %3lu ",
1931 // iSmType,iSm,iRpc,iCh,fStorStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size());
1932 if (0 == fStorDigi[iSmType][iSm * iNbRpc + iRpc].size()) continue;
1933 if (fvDeadStrips[iDetIndx] & (1 << iCh)) continue; // skip over dead channels
1934 //if( 0 < fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size() )
1935 // fhNbDigiPerChan->Fill( fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size() );
1936
1937 while (1 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
1938
1939 while ((fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetSide()
1940 == (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetSide()) {
1941 // Not one Digi of each end!
1942 fiNbSameSide++;
1943 if (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size() > 2) {
1944 LOG(debug) << "SameSide Digis! on TSRC " << iSmType << iSm << iRpc << iCh << ", Times: "
1945 << Form("%f", (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()) << ", "
1946 << Form("%f", (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime())
1947 << ", DeltaT "
1948 << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
1949 - (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
1950 << ", array size: " << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
1951 if (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetSide()
1952 == fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetSide()) {
1953 LOG(debug) << "3 consecutive SameSide Digis! on TSRC " << iSmType << iSm << iRpc << iCh
1954 << ", Times: " << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
1955 << ", " << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
1956 << ", DeltaT "
1957 << (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1])->GetTime()
1958 - (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0])->GetTime()
1959 << ", array size: " << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
1960 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1961 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
1962 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1963 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
1964 }
1965 else {
1966 if (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetTime()
1967 - fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetTime()
1968 > fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2]->GetTime()
1969 - fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1]->GetTime()) {
1970 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1971 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
1972 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1973 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
1974 }
1975 else {
1976 LOG(debug) << Form("Ev %8.0f, digis not properly time ordered, TSRCS "
1977 "%d%d%d%d%d ",
1978 fdEvent, iSmType, iSm, iRpc, iCh,
1979 (Int_t) fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0]->GetSide());
1980 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1981 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1);
1982 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1983 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1);
1984 }
1985 }
1986 }
1987 else {
1988 LOG(debug) << "SameSide Erase fStor entries(d) " << iSmType << ", SR " << iSm * iNbRpc + iRpc
1989 << ", Ch" << iCh;
1990 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1991 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
1992 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
1993 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
1994 }
1995 if (2 > fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) break;
1996 continue;
1997 } // same condition side end
1998 LOG(debug) << "digis processing for "
1999 << Form(" SmT %3d Sm %3d Rpc %3d Ch %3d # %3lu ", iSmType, iSm, iRpc, iCh,
2000 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size());
2001 if (2 > fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
2002 LOG(debug) << Form("Leaving digi processing for TSRC %d%d%d%d, size %3lu", iSmType, iSm, iRpc, iCh,
2003 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size());
2004 break;
2005 }
2006 /* Int_t iLastChId = iChId; // Save Last hit channel*/
2007
2008 // 2 Digis = both sides present
2009 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
2010 iChId = fTofId->SetDetectorInfo(xDetInfo);
2011 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType);
2012 LOG(debug) << Form("TSRC %d%d%d%d size %3lu ", iSmType, iSm, iRpc, iCh,
2013 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size())
2014 << Form(" ChId: 0x%08x 0x%08x ", iChId, iUCellId);
2015 fChannelInfo = fDigiPar->GetCell(iChId);
2016
2017 if (NULL == fChannelInfo) {
2018 LOG(error) << "BuildHits: no geometry info! "
2019 << Form(" %3d %3d %3d %3d 0x%08x 0x%08x ", iSmType, iSm, iRpc, iCh, iChId, iUCellId);
2020 break;
2021 }
2022
2023 TGeoNode* fNode = // prepare local->global trafo
2024 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
2025 // fNode->Print();
2026 if (NULL == fNode) { // Transformation matrix not available !!!??? - Check
2027 LOG(error) << Form("Node at (%6.1f,%6.1f,%6.1f) : %p", fChannelInfo->GetX(), fChannelInfo->GetY(),
2028 fChannelInfo->GetZ(), fNode);
2029 ChangeState(fair::mq::Transition::Stop);
2030 }
2031
2032 CbmTofDigi* xDigiA = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][0];
2033 CbmTofDigi* xDigiB = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][1];
2034
2035 dTimeDif = (xDigiA->GetTime() - xDigiB->GetTime());
2036 if (5 == iSmType && dTimeDif != 0.) {
2037 // FIXME -> Overflow treatment in calib/tdc/TMbsCalibTdcTof.cxx
2038 LOG(debug) << "BuildHits: Diamond hit in " << iSm << " with inconsistent digits "
2039 << xDigiA->GetTime() << ", " << xDigiB->GetTime() << " -> " << dTimeDif;
2040 /*
2041 LOG(debug) << " "<<xDigiA->ToString();
2042 LOG(debug) << " "<<xDigiB->ToString();
2043 */
2044 }
2045 if (1 == xDigiA->GetSide())
2046 // 0 is the top side, 1 is the bottom side
2047 dPosY = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
2048 else
2049 // 0 is the bottom side, 1 is the top side
2050 dPosY = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
2051
2052 if (TMath::Abs(dPosY) > fChannelInfo->GetSizey()
2053 && fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size() > 2) {
2054 LOG(debug) << "Hit candidate outside correlation window, check for "
2055 "better possible digis, "
2056 << " mul " << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
2057
2058 CbmTofDigi* xDigiC = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][2];
2059 Double_t dPosYN = 0.;
2060 Double_t dTimeDifN = 0;
2061 if (xDigiC->GetSide() == xDigiA->GetSide()) dTimeDifN = xDigiC->GetTime() - xDigiB->GetTime();
2062 else
2063 dTimeDifN = xDigiA->GetTime() - xDigiC->GetTime();
2064
2065 if (1 == xDigiA->GetSide()) dPosYN = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDifN * 0.5;
2066 else
2067 dPosYN = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDifN * 0.5;
2068
2069 if (TMath::Abs(dPosYN) < TMath::Abs(dPosY)) {
2070 LOG(debug) << "Replace digi on side " << xDigiC->GetSide() << ", yPosNext " << dPosYN
2071 << " old: " << dPosY;
2072 dTimeDif = dTimeDifN;
2073 dPosY = dPosYN;
2074 if (xDigiC->GetSide() == xDigiA->GetSide()) {
2075 xDigiA = xDigiC;
2076 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2077 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2078 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2079 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2080 }
2081 else {
2082 xDigiB = xDigiC;
2083 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2084 ++(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1));
2085 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2086 ++(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + 1));
2087 }
2088 }
2089 }
2090 if (xDigiA->GetSide() == xDigiB->GetSide()) {
2091 LOG(error) << "Wrong combinations of digis " << fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]
2092 << "," << fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1];
2093 }
2094 // The "Strip" time is the mean time between each end
2095 dTime = 0.5 * (xDigiA->GetTime() + xDigiB->GetTime());
2096
2097 // Weight is the total charge => sum of both ends ToT
2098 dTotS = xDigiA->GetTot() + xDigiB->GetTot();
2099
2100 // use local coordinates, (0,0,0) is in the center of counter ?
2101 dPosX = ((Double_t)(-iNbCh / 2 + iCh) + 0.5) * fChannelInfo->GetSizex();
2102 dPosZ = 0.;
2103
2104 /*
2105 LOG(debug)
2106 <<"NbChanInHit "
2107 << Form(" %3d %3d %3d %3d %3d 0x%p %1.0f Time %f PosX %f PosY %f Svel %f ",
2108 iNbChanInHit,iSmType,iRpc,iCh,iLastChan,xDigiA,xDigiA->GetSide(),
2109 dTime,dPosX,dPosY,fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))
2110 // << Form( ", Offs %f, %f ",fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][0],
2111 // fvCPTOff[iSmType][iSm*iNbRpc+iRpc][iCh][1])
2112 ;
2113 */
2114 // Now check if a hit/cluster is already started
2115 if (0 < iNbChanInHit) {
2116 if (iLastChan == iCh - 1) {
2117 /*
2118 fhDigTimeDifClust->Fill( dTime - dLastTime );
2119 fhDigSpacDifClust->Fill( dPosY - dLastPosY );
2120 fhDigDistClust->Fill( dPosY - dLastPosY,
2121 dTime - dLastTime );
2122 */
2123 }
2124 // if( iLastChan == iCh - 1 )
2125 // a cluster is already started => check distance in space/time
2126 // For simplicity, just check along strip direction for now
2127 // and break cluster when a not fired strip is found
2128 if (TMath::Abs(dTime - dLastTime) < fdMaxTimeDist && iLastChan == iCh - 1
2129 && TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist) {
2130 // Add to cluster/hit
2131 dWeightedTime += dTime * dTotS;
2132 dWeightedPosX += dPosX * dTotS;
2133 dWeightedPosY += dPosY * dTotS;
2134 dWeightedPosZ += dPosZ * dTotS;
2135 dWeightsSum += dTotS;
2136 iNbChanInHit += 1;
2137
2138 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
2139 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
2140
2141 LOG(debug) << " Add Digi and erase fStor entries(a): NbChanInHit " << iNbChanInHit << ", "
2142 << iSmType << ", SR " << iSm * iNbRpc + iRpc << ", Ch" << iCh;
2143
2144 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2145 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2146 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2147 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2148 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2149 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2150 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2151 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2152
2153 } // if current Digis compatible with last fired chan
2154 else {
2155 // Save Hit
2156 dWeightedTime /= dWeightsSum;
2157 dWeightedPosX /= dWeightsSum;
2158 dWeightedPosY /= dWeightsSum;
2159 dWeightedPosZ /= dWeightsSum;
2160 // TVector3 hitPosLocal(dWeightedPosX, dWeightedPosY, dWeightedPosZ);
2161 //TVector3 hitPos;
2162 Double_t hitpos_local[3];
2163 hitpos_local[0] = dWeightedPosX;
2164 hitpos_local[1] = dWeightedPosY;
2165 hitpos_local[2] = dWeightedPosZ;
2166
2167 Double_t hitpos[3];
2168 //TGeoNode* cNode =
2169 gGeoManager->GetCurrentNode();
2170 /*TGeoHMatrix* cMatrix =*/gGeoManager->GetCurrentMatrix();
2171 //cNode->Print();
2172 //cMatrix->Print();
2173 gGeoManager->LocalToMaster(hitpos_local, hitpos);
2174 /*
2175 LOG(debug)<<
2176 Form("LocalToMaster for node %p: (%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)",
2177 cNode, hitpos_local[0], hitpos_local[1], hitpos_local[2],
2178 hitpos[0], hitpos[1], hitpos[2]);
2179 */
2180 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
2181
2182 // Simple errors, not properly done at all for now
2183 // Right way of doing it should take into account the weight distribution
2184 // and real system time resolution
2185 TVector3 hitPosErr(0.5, 0.5, 0.5); // including positioning uncertainty
2186 /*
2187 TVector3 hitPosErr( fChannelInfo->GetSizex()/TMath::Sqrt(12.0), // Single strips approximation
2188 0.5, // Use generic value
2189 1.);
2190
2191 */
2192 //fDigiBdfPar->GetFeeTimeRes() * fDigiBdfPar->GetSigVel(iSmType,iRpc), // Use the electronics resolution
2193 //fDigiBdfPar->GetNbGaps( iSmType, iRpc)*
2194 //fDigiBdfPar->GetGapSize( iSmType, iRpc)/ //10.0 / // Change gap size in cm
2195 //TMath::Sqrt(12.0) ); // Use full RPC thickness as "Channel" Z size
2196
2197 // Int_t iDetId = vPtsRef[0]->GetDetectorID();// detID = pt->GetDetectorID() <= from TofPoint
2198 // calc mean ch from dPosX=((Double_t)(-iNbCh/2 + iCh)+0.5)*fChannelInfo->GetSizex();
2199
2200 Int_t iChm = floor(dWeightedPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
2201 if (iChm < 0) iChm = 0;
2202 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
2203 iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
2204 //Int_t iRefId = 0; // Index of the correspondng TofPoint
2205 // if(NULL != fTofPointsColl) {
2206 //iRefId = fTofPointsColl->IndexOf( vPtsRef[0] );
2207 //}
2208 /*
2209 LOG(debug)<<"Save Hit "
2210 << Form(" %3d %3d 0x%08x %3d %3d %3d %f %f",
2211 fiNbHits,iNbChanInHit,iDetId,iChm,iLastChan,iRefId,
2212 dWeightedTime,dWeightedPosY)
2213 <<", DigiSize: "<<vDigiIndRef.size()
2214 <<", DigiInds: ";
2215 for (UInt_t i=0; i<vDigiIndRef.size();i++){
2216 LOG(debug)<<" "<<vDigiIndRef.at(i)<<"(M"<<fviClusterMul[iSmType][iSm][iRpc]<<")";
2217 }
2218 */
2219
2220 fviClusterMul[iSmType][iSm][iRpc]++;
2221 if (vDigiIndRef.size() < 2) {
2222 LOG(warn) << "Digi refs for Hit " << fiNbHits << ": " << vDigiIndRef.size();
2223 }
2224 if (fiNbHits > 0) {
2225 CbmTofHit* pHitL = (CbmTofHit*) fTofHitsColl->At(fiNbHits - 1);
2226 if (iDetId == pHitL->GetAddress() && dWeightedTime == pHitL->GetTime()) {
2227 LOG(debug) << "Store Hit twice? "
2228 << " fiNbHits " << fiNbHits << ", " << Form("0x%08x", iDetId);
2229 }
2230 }
2231 CbmTofHit* pHit =
2232 new CbmTofHit(iDetId, hitPos,
2233 hitPosErr, //local detector coordinates
2234 fiNbHits, // this number is used as reference!!
2235 dWeightedTime,
2236 vDigiIndRef.size(), // number of linked digis = 2*CluSize
2237 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
2238 Int_t(dWeightsSum * 10.)); //channel -> Tot
2239 //0) ; //channel
2240 // output hit
2241 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
2242 // memorize hit
2243 if (fdMemoryTime > 0.) { LH_store(iSmType, iSm, iRpc, iChm, pHit); }
2244 else {
2245 pHit->Delete();
2246 }
2247 /*
2248 new((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
2249 CbmMatch* digiMatch = (CbmMatch *)fTofDigiMatchColl->At(fiNbHits);
2250 */
2251 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
2252 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
2253 Double_t dTot = ((CbmTofDigi*) (&(fTofCalDigiVec->at(vDigiIndRef.at(i)))))->GetTot();
2254 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
2255 }
2256
2257 fiNbHits++;
2258 // For Histogramming
2259 fviClusterSize[iSmType][iRpc].push_back(iNbChanInHit);
2260 //fviTrkMul[iSmType][iRpc].push_back( vPtsRef.size() );
2261 fvdX[iSmType][iRpc].push_back(dWeightedPosX);
2262 fvdY[iSmType][iRpc].push_back(dWeightedPosY);
2263 /* no TofPoint available for data!
2264 fvdDifX[iSmType][iRpc].push_back( vPtsRef[0]->GetX() - dWeightedPosX);
2265 fvdDifY[iSmType][iRpc].push_back( vPtsRef[0]->GetY() - dWeightedPosY);
2266 fvdDifCh[iSmType][iRpc].push_back( fGeoHandler->GetCell( vPtsRef[0]->GetDetectorID() ) -1 -iLastChan );
2267 */
2268 //vPtsRef.clear();
2269 vDigiIndRef.clear();
2270
2271 // Start a new hit
2272 dWeightedTime = dTime * dTotS;
2273 dWeightedPosX = dPosX * dTotS;
2274 dWeightedPosY = dPosY * dTotS;
2275 dWeightedPosZ = dPosZ * dTotS;
2276 dWeightsSum = dTotS;
2277 iNbChanInHit = 1;
2278 // Save pointer on CbmTofPoint
2279 // vPtsRef.push_back( (CbmTofPoint*)(xDigiA->GetLinks()) );
2280 // Save next digi address
2281
2282 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
2283 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
2284 //LOG(debug2)<<"Erase fStor entries(b) "<<iSmType<<", SR "<<iSm*iNbRpc+iRpc<<", Ch"<<iCh;
2285
2286 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2287 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2288 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2289 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2290 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2291 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2292 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2293 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2294 } // else of if current Digis compatible with last fired chan
2295 } // if( 0 < iNbChanInHit)
2296 else {
2297 LOG(debug) << Form("1.Hit on channel %d, time: %f, PosY %f", iCh, dTime, dPosY);
2298
2299 // first fired strip in this RPC
2300 dWeightedTime = dTime * dTotS;
2301 dWeightedPosX = dPosX * dTotS;
2302 dWeightedPosY = dPosY * dTotS;
2303 dWeightedPosZ = dPosZ * dTotS;
2304 dWeightsSum = dTotS;
2305 iNbChanInHit = 1;
2306 // Save pointer on CbmTofPoint
2307 //if(NULL != fTofPointsColl)
2308 // vPtsRef.push_back( (CbmTofPoint*)(xDigiA->GetLinks()) );
2309 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][0]));
2310 vDigiIndRef.push_back((Int_t)(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][1]));
2311
2312 //LOG(debug)<<"Erase fStor entries(c) "<<iSmType<<", SR "<<iSm*iNbRpc+iRpc<<", Ch"<<iCh;
2313
2314 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2315 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2316 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2317 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2318 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2319 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2320 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2321 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin());
2322
2323 } // else of if( 0 < iNbChanInHit)
2324 iLastChan = iCh;
2325 dLastPosX = dPosX;
2326 dLastPosY = dPosY;
2327 dLastTime = dTime;
2328 if (AddNextChan(iSmType, iSm, iRpc, iLastChan, dLastPosX, dLastPosY, dLastTime, dWeightsSum)) {
2329 iNbChanInHit = 0; // cluster already stored
2330 }
2331 } // while( 1 < fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size() )
2332 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].clear();
2333 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].clear();
2334 } // for( Int_t iCh = 0; iCh < iNbCh; iCh++ )
2335 //LOG(debug2)<<"finished V-RPC"
2336 // << Form(" %3d %3d %3d %d %f %fx",iSmType,iSm,iRpc,fTofHitsColl->GetEntriesFast(),dLastPosX,dLastPosY);
2337 } // else of if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
2338 } // if( 0 == iChType)
2339 else {
2340 LOG(error) << "=> Cluster building "
2341 << "from digis to hits not implemented for pads, Sm type " << iSmType << " Rpc " << iRpc;
2342 return kFALSE;
2343 } // else of if( 0 == iChType)
2344
2345 // Now check if another hit/cluster is started
2346 // and save it if it's the case
2347 if (0 < iNbChanInHit) {
2348 /*
2349 LOG(debug)<<"Process cluster "
2350 <<iNbChanInHit;
2351 */
2352 // Check orientation to properly assign errors
2353 if (1 == fDigiBdfPar->GetChanOrient(iSmType, iRpc)) {
2354 // LOG(debug1)<<"H-Hit ";
2355 } // if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
2356 else {
2357 //LOG(debug2)<<"V-Hit ";
2358 // Save Hit
2359 dWeightedTime /= dWeightsSum;
2360 dWeightedPosX /= dWeightsSum;
2361 dWeightedPosY /= dWeightsSum;
2362 dWeightedPosZ /= dWeightsSum;
2363 //TVector3 hitPos(dWeightedPosX, dWeightedPosY, dWeightedPosZ);
2364
2365 Double_t hitpos_local[3] = {3 * 0.};
2366 hitpos_local[0] = dWeightedPosX;
2367 hitpos_local[1] = dWeightedPosY;
2368 hitpos_local[2] = dWeightedPosZ;
2369
2370 Double_t hitpos[3];
2371 //TGeoNode* cNode=
2372 gGeoManager->GetCurrentNode();
2373 /*TGeoHMatrix* cMatrix =*/gGeoManager->GetCurrentMatrix();
2374 //cNode->Print();
2375 //cMatrix->Print();
2376
2377 gGeoManager->LocalToMaster(hitpos_local, hitpos);
2378 /*
2379 LOG(debug)<<
2380 Form(" LocalToMaster for V-node %p: (%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)",
2381 cNode, hitpos_local[0], hitpos_local[1], hitpos_local[2],
2382 hitpos[0], hitpos[1], hitpos[2])
2383 ;
2384 */
2385 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
2386 // Event errors, not properly done at all for now
2387 // Right way of doing it should take into account the weight distribution
2388 // and real system time resolution
2389 TVector3 hitPosErr(0.5, 0.5, 0.5); // including positioning uncertainty
2390 /*
2391 TVector3 hitPosErr( fChannelInfo->GetSizex()/TMath::Sqrt(12.0), // Single strips approximation
2392 0.5, // Use generic value
2393 1.);
2394 */
2395 Int_t iChm = floor(dWeightedPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
2396 if (iChm < 0) iChm = 0;
2397 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
2398 iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
2399 //Int_t iRefId = 0; // Index of the correspondng TofPoint
2400 //if(NULL != fTofPointsColl) iRefId = fTofPointsColl->IndexOf( vPtsRef[0] );
2401 /*
2402 LOG(debug)<<"Save V-Hit "
2403 << Form(" %3d %3d 0x%08x %3d 0x%08x", // %3d %3d
2404 fiNbHits,iNbChanInHit,iDetId,iLastChan,iRefId) //vPtsRef.size(),vPtsRef[0])
2405 // dWeightedTime,dWeightedPosY)
2406 <<", DigiSize: "<<vDigiIndRef.size();
2407 for (UInt_t i=0; i<vDigiIndRef.size();i++){
2408 LOG(debug)<<"DigiIndRef "<<i<<" "<<vDigiIndRef.at(i)<<"(M"<<fviClusterMul[iSmType][iSm][iRpc]<<")";
2409 }
2410 */
2411 fviClusterMul[iSmType][iSm][iRpc]++;
2412 if (vDigiIndRef.size() < 2) {
2413 LOG(warn) << "Digi refs for Hit " << fiNbHits << ": " << vDigiIndRef.size();
2414 }
2415 if (fiNbHits > 0) {
2416 CbmTofHit* pHitL = (CbmTofHit*) fTofHitsColl->At(fiNbHits - 1);
2417 if (iDetId == pHitL->GetAddress() && dWeightedTime == pHitL->GetTime())
2418 LOG(debug) << "Store Hit twice? "
2419 << " fiNbHits " << fiNbHits << ", " << Form("0x%08x", iDetId);
2420 }
2421
2422 CbmTofHit* pHit = new CbmTofHit(iDetId, hitPos,
2423 hitPosErr, //local detector coordinates
2424 fiNbHits, // this number is used as reference!!
2425 dWeightedTime,
2426 vDigiIndRef.size(), // number of linked digis = 2*CluSize
2427 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
2428 Int_t(dWeightsSum * 10.)); //channel -> Tot
2429 // 0) ; //channel
2430 // vDigiIndRef);
2431 // output hit
2432 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
2433 // memorize hit
2434 if (fdMemoryTime > 0.) { LH_store(iSmType, iSm, iRpc, iChm, pHit); }
2435 else {
2436 pHit->Delete();
2437 }
2438 /*
2439 new((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
2440 CbmMatch* digiMatch = (CbmMatch *)fTofDigiMatchColl->At(fiNbHits);
2441 */
2442 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
2443 for (UInt_t i = 0; i < vDigiIndRef.size(); i++) {
2444 Double_t dTot = ((CbmTofDigi*) (&(fTofCalDigiVec->at(vDigiIndRef.at(i)))))->GetTot();
2445 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
2446 }
2447
2448 fiNbHits++;
2449 // For Histogramming
2450 fviClusterSize[iSmType][iRpc].push_back(iNbChanInHit);
2451 //fviTrkMul[iSmType][iRpc].push_back( vPtsRef.size() );
2452 fvdX[iSmType][iRpc].push_back(dWeightedPosX);
2453 fvdY[iSmType][iRpc].push_back(dWeightedPosY);
2454 /*
2455 fvdDifX[iSmType][iRpc].push_back( vPtsRef[0]->GetX() - dWeightedPosX);
2456 fvdDifY[iSmType][iRpc].push_back( vPtsRef[0]->GetY() - dWeightedPosY);
2457 fvdDifCh[iSmType][iRpc].push_back( fGeoHandler->GetCell( vPtsRef[0]->GetDetectorID() ) -1 -iLastChan );
2458 */
2459 //vPtsRef.clear();
2460 vDigiIndRef.clear();
2461 } // else of if( 1 == fDigiBdfPar->GetChanOrient( iSmType, iRpc ) )
2462 } // if( 0 < iNbChanInHit)
2463 } // for each sm/rpc pair
2464 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
2465 }
2466
2467 return kTRUE;
2468}
2469
2470/************************************************************************************/
2472
2473void CbmDeviceHitBuilderTof::LH_store(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iChm, CbmTofHit* pHit)
2474{
2475
2476 if (fvLastHits[iSmType][iSm][iRpc][iChm].size() == 0) fvLastHits[iSmType][iSm][iRpc][iChm].push_back(pHit);
2477 else {
2478 Double_t dLastTime = pHit->GetTime();
2479 if (dLastTime >= fvLastHits[iSmType][iSm][iRpc][iChm].back()->GetTime()) {
2480 fvLastHits[iSmType][iSm][iRpc][iChm].push_back(pHit);
2481 LOG(debug) << Form(" Store LH from Ev %8.0f for TSRC %d%d%d%d, size %lu, addr 0x%08x, "
2482 "time %f, dt %f",
2483 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
2484 pHit->GetAddress(), dLastTime,
2485 dLastTime - fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime());
2486 }
2487 else {
2488 if (dLastTime
2489 >= fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime()) { // hit has to be inserted in the proper place
2490 std::list<CbmTofHit*>::iterator it;
2491 for (it = fvLastHits[iSmType][iSm][iRpc][iChm].begin(); it != fvLastHits[iSmType][iSm][iRpc][iChm].end(); ++it)
2492 if ((*it)->GetTime() > dLastTime) break;
2493 fvLastHits[iSmType][iSm][iRpc][iChm].insert(--it, pHit);
2494 Double_t deltaTime = dLastTime - (*it)->GetTime();
2495 LOG(debug) << Form("Hit inserted into LH from Ev %8.0f for TSRC "
2496 "%d%d%d%d, size %lu, addr 0x%08x, delta time %f ",
2497 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
2498 pHit->GetAddress(), deltaTime);
2499 }
2500 else { // this hit is first
2501 Double_t deltaTime = dLastTime - fvLastHits[iSmType][iSm][iRpc][iChm].front()->GetTime();
2502 LOG(debug) << Form("first LH from Ev %8.0f for TSRC %d%d%d%d, size "
2503 "%lu, addr 0x%08x, delta time %f ",
2504 fdEvent, iSmType, iSm, iRpc, iChm, fvLastHits[iSmType][iSm][iRpc][iChm].size(),
2505 pHit->GetAddress(), deltaTime);
2506 if (deltaTime == 0.) {
2507 // remove hit, otherwise double entry?
2508 pHit->Delete();
2509 }
2510 else {
2511 fvLastHits[iSmType][iSm][iRpc][iChm].push_front(pHit);
2512 }
2513 }
2514 }
2515 }
2516}
2517
2519{
2520 if ((Int_t) fvLastHits.size() != fDigiBdfPar->GetNbSmTypes())
2521 LOG(error) << Form("Inconsistent LH Smtype size %lu, %d ", fvLastHits.size(), fDigiBdfPar->GetNbSmTypes());
2522
2523 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
2524 if ((Int_t) fvLastHits[iSmType].size() != fDigiBdfPar->GetNbSm(iSmType))
2525 LOG(error) << Form("Inconsistent LH Sm size %lu, %d T %d", fvLastHits[iSmType].size(),
2526 fDigiBdfPar->GetNbSm(iSmType), iSmType);
2527 for (Int_t iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); iSm++) {
2528 if ((Int_t) fvLastHits[iSmType][iSm].size() != fDigiBdfPar->GetNbRpc(iSmType))
2529 LOG(error) << Form("Inconsistent LH Rpc size %lu, %d TS %d%d ", fvLastHits[iSmType][iSm].size(),
2530 fDigiBdfPar->GetNbRpc(iSmType), iSmType, iSm);
2531 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
2532 if ((Int_t) fvLastHits[iSmType][iSm][iRpc].size() != fDigiBdfPar->GetNbChan(iSmType, iRpc))
2533 LOG(error) << Form("Inconsistent LH RpcChannel size %lu, %d TSR %d%d%d ",
2534 fvLastHits[iSmType][iSm][iRpc].size(), fDigiBdfPar->GetNbChan(iSmType, iRpc), iSmType, iSm,
2535 iRpc);
2536 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++)
2537 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 0) {
2538 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
2539 Int_t iAddr = fTofId->SetDetectorInfo(xDetInfo);
2540 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != iAddr)
2541 LOG(error) << Form("Inconsistent address for Ev %8.0f in list of size %lu for "
2542 "TSRC %d%d%d%d: 0x%08x, time %f",
2543 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
2544 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
2545 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
2546 }
2547 }
2548 }
2549 }
2550 LOG(debug) << Form("LH check passed for event %8.0f", fdEvent);
2551}
2552
2554{
2555 if ((Int_t) fvLastHits.size() != fDigiBdfPar->GetNbSmTypes())
2556 LOG(error) << Form("Inconsistent LH Smtype size %lu, %d ", fvLastHits.size(), fDigiBdfPar->GetNbSmTypes());
2557 for (Int_t iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); iSmType++) {
2558 if ((Int_t) fvLastHits[iSmType].size() != fDigiBdfPar->GetNbSm(iSmType))
2559 LOG(error) << Form("Inconsistent LH Sm size %lu, %d T %d", fvLastHits[iSmType].size(),
2560 fDigiBdfPar->GetNbSm(iSmType), iSmType);
2561 for (Int_t iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); iSm++) {
2562 if ((Int_t) fvLastHits[iSmType][iSm].size() != fDigiBdfPar->GetNbRpc(iSmType))
2563 LOG(error) << Form("Inconsistent LH Rpc size %lu, %d TS %d%d ", fvLastHits[iSmType][iSm].size(),
2564 fDigiBdfPar->GetNbRpc(iSmType), iSmType, iSm);
2565 for (Int_t iRpc = 0; iRpc < fDigiBdfPar->GetNbRpc(iSmType); iRpc++) {
2566 if ((Int_t) fvLastHits[iSmType][iSm][iRpc].size() != fDigiBdfPar->GetNbChan(iSmType, iRpc))
2567 LOG(error) << Form("Inconsistent LH RpcChannel size %lu, %d TSR %d%d%d ",
2568 fvLastHits[iSmType][iSm][iRpc].size(), fDigiBdfPar->GetNbChan(iSmType, iRpc), iSmType, iSm,
2569 iRpc);
2570 for (Int_t iCh = 0; iCh < fDigiBdfPar->GetNbChan(iSmType, iRpc); iCh++)
2571 while (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 0) {
2572 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
2573 Int_t iAddr = fTofId->SetDetectorInfo(xDetInfo);
2574 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != iAddr)
2575 LOG(error) << Form("Inconsistent address for Ev %8.0f in list of size %lu for "
2576 "TSRC %d%d%d%d: 0x%08x, time %f",
2577 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
2578 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
2579 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
2580 fvLastHits[iSmType][iSm][iRpc][iCh].front()->Delete();
2581 fvLastHits[iSmType][iSm][iRpc][iCh].pop_front();
2582 }
2583 }
2584 }
2585 }
2586 LOG(info) << Form("LH cleaning done after %8.0f events", fdEvent);
2587}
2588
2589Bool_t CbmDeviceHitBuilderTof::AddNextChan(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iLastChan, Double_t dLastPosX,
2590 Double_t dLastPosY, Double_t dLastTime, Double_t dLastTotS)
2591{
2592 //Int_t iNbSm = fDigiBdfPar->GetNbSm( iSmType);
2593 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
2594 Int_t iNbCh = fDigiBdfPar->GetNbChan(iSmType, iRpc);
2595 // Int_t iChType = fDigiBdfPar->GetChanType( iSmType, iRpc );
2596
2597 Int_t iCh = iLastChan + 1;
2598 LOG(debug) << Form("Inspect channel TSRC %d%d%d%d at time %f, pos %f, size ", iSmType, iSm, iRpc, iCh, dLastTime,
2599 dLastPosY)
2600 << fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size();
2601 if (iCh == iNbCh) return kFALSE;
2602 if (0 == fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) return kFALSE;
2603 //if( 0 < fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size() )
2604 // fhNbDigiPerChan->Fill( fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size() );
2605 if (1 < fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
2606 Bool_t AddedHit = kFALSE;
2607 for (Int_t i1 = 0; i1 < (Int_t) fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size() - 1; i1++) {
2608 if (AddedHit) break;
2609 Int_t i2 = i1 + 1;
2610 while (!AddedHit && i2 < (Int_t) fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].size()) {
2611 // LOG(debug)<<"check digi pair "<<i1<<","<<i2<<" with size "<<fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size();
2612
2613 if ((fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i1])->GetSide()
2614 == (fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i2])->GetSide()) {
2615 i2++;
2616 continue;
2617 } // endif same side
2618 // 2 Digis, both sides present
2619 CbmTofDigi* xDigiA = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i1];
2620 CbmTofDigi* xDigiB = fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh][i2];
2621 Double_t dTime = 0.5 * (xDigiA->GetTime() + xDigiB->GetTime());
2622 if (TMath::Abs(dTime - dLastTime) < fdMaxTimeDist) {
2623 CbmTofDetectorInfo xDetInfo(ECbmModuleId::kTof, iSmType, iSm, iRpc, 0, iCh);
2624 Int_t iChId = fTofId->SetDetectorInfo(xDetInfo);
2625 fChannelInfo = fDigiPar->GetCell(iChId);
2626 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
2627
2628 Double_t dTimeDif = xDigiA->GetTime() - xDigiB->GetTime();
2629 Double_t dPosY = 0.;
2630 if (1 == xDigiA->GetSide()) dPosY = fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
2631 else
2632 dPosY = -fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc) * dTimeDif * 0.5;
2633
2634 if (TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist) { // append digi pair to current cluster
2635
2636 Double_t dNClHits = (Double_t)(vDigiIndRef.size() / 2);
2637 Double_t dPosX = ((Double_t)(-iNbCh / 2 + iCh) + 0.5) * fChannelInfo->GetSizex();
2638 Double_t dTotS = xDigiA->GetTot() + xDigiB->GetTot();
2639 Double_t dNewTotS = (dLastTotS + dTotS);
2640 dLastPosX = (dLastPosX * dLastTotS + dPosX * dTotS) / dNewTotS;
2641 dLastPosY = (dLastPosY * dLastTotS + dPosY * dTotS) / dNewTotS;
2642 dLastTime = (dLastTime * dLastTotS + dTime * dTotS) / dNewTotS;
2643 dLastTotS = dNewTotS;
2644 // attach selected digis from pool
2645 Int_t Ind1 = fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][i1];
2646 Int_t Ind2 = fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh][i2];
2647 vDigiIndRef.push_back(Ind1);
2648 vDigiIndRef.push_back(Ind2);
2649 // remove selected digis from pool
2650 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin()
2651 + i1);
2652 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2653 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + i1);
2654
2655 std::vector<int>::iterator it;
2656 it = find(fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin(),
2657 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].end(), Ind2);
2658 if (it != fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].end()) {
2659 auto ipos = it - fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin();
2660 LOG(debug) << "Found i2 " << i2 << " with Ind2 " << Ind2 << " at position " << ipos;
2661 fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].erase(fStorDigi[iSmType][iSm * iNbRpc + iRpc][iCh].begin()
2662 + ipos);
2663 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].erase(
2664 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc][iCh].begin() + ipos);
2665 }
2666 else {
2667 LOG(error) << " Did not find i2 " << i2 << " with Ind2 " << Ind2;
2668 }
2669
2670 //if(iCh == iNbCh-1) break; //Last strip reached
2671 if (iCh != (iNbCh - 1)
2672 && AddNextChan(iSmType, iSm, iRpc, iCh, dLastPosX, dLastPosY, dLastTime, dLastTotS)) {
2673 LOG(debug) << "Added Strip " << iCh << " to cluster of size " << dNClHits;
2674 return kTRUE; // signal hit was already added
2675 }
2676 AddedHit = kTRUE;
2677 } //TMath::Abs(dPosY - dLastPosY) < fdMaxSpaceDist
2678 } //TMath::Abs(dTime-dLastTime)<fdMaxTimeDist)
2679 i2++;
2680 } // while(i2 < fStorDigi[iSmType][iSm*iNbRpc+iRpc][iCh].size()-1 )
2681 } // end for i1
2682 } // end if size
2683 Double_t hitpos_local[3] = {3 * 0.};
2684 hitpos_local[0] = dLastPosX;
2685 hitpos_local[1] = dLastPosY;
2686 hitpos_local[2] = 0.;
2687 Double_t hitpos[3];
2688
2689 TGeoNode* cNode = gGeoManager->GetCurrentNode();
2690 if (NULL == cNode) { // Transformation matrix not available !!!??? - Check
2691 LOG(error) << Form("Node at (%6.1f,%6.1f,%6.1f) : %p", fChannelInfo->GetX(), fChannelInfo->GetY(),
2692 fChannelInfo->GetZ(), cNode);
2693 ChangeState(fair::mq::Transition::Stop);
2694 }
2695
2696 /*TGeoHMatrix* cMatrix = */ gGeoManager->GetCurrentMatrix();
2697 gGeoManager->LocalToMaster(hitpos_local, hitpos);
2698 TVector3 hitPos(hitpos[0], hitpos[1], hitpos[2]);
2699 TVector3 hitPosErr(0.5, 0.5, 0.5); // FIXME including positioning uncertainty
2700 Int_t iChm = floor(dLastPosX / fChannelInfo->GetSizex()) + iNbCh / 2;
2701 if (iChm < 0) iChm = 0;
2702 if (iChm > iNbCh - 1) iChm = iNbCh - 1;
2703 Int_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iChm, 0, iSmType);
2704
2705 // Int_t iNbChanInHit=vDigiIndRef.size()/2;
2706 fviClusterMul[iSmType][iSm][iRpc]++;
2707 /*
2708 LOG(debug)<<"Save A-Hit "
2709 << Form("%2d %2d 0x%08x %3d t %f, y %f ",
2710 fiNbHits,iNbChanInHit,iDetId,iLastChan,dLastTime,dLastPosY)
2711 <<", DigiSize: "<<vDigiIndRef.size();
2712 for (UInt_t i=0; i<vDigiIndRef.size();i++){
2713 LOG(debug)<<"DigiIndRef "<<i<<" "<<vDigiIndRef.at(i)<<"(M"<<fviClusterMul[iSmType][iSm][iRpc]<<")";
2714 }
2715 */
2716 CbmTofHit* pHit = new CbmTofHit(iDetId, hitPos,
2717 hitPosErr, //local detector coordinates
2718 fiNbHits, // this number is used as reference!!
2719 dLastTime,
2720 vDigiIndRef.size(), // number of linked digis = 2*CluSize
2721 //vPtsRef.size(), // flag = number of TofPoints generating the cluster
2722 Int_t(dLastTotS * 10.)); //channel -> Tot
2723 // output hit
2724 new ((*fTofHitsColl)[fiNbHits]) CbmTofHit(*pHit);
2725 if (fdMemoryTime > 0.) { // memorize hit
2726 LH_store(iSmType, iSm, iRpc, iChm, pHit);
2727 }
2728 else {
2729 pHit->Delete();
2730 }
2731 CbmMatch* digiMatch = new ((*fTofDigiMatchColl)[fiNbHits]) CbmMatch();
2732 for (Int_t i = 0; i < (Int_t) vDigiIndRef.size(); i++) {
2733 Double_t dTot = ((CbmTofDigi*) (&(fTofCalDigiVec->at(vDigiIndRef.at(i)))))->GetTot();
2734 digiMatch->AddLink(CbmLink(dTot, vDigiIndRef.at(i), fiOutputTreeEntry, fiFileIndex));
2735 }
2736 fiNbHits++;
2737 vDigiIndRef.clear();
2738
2739 return kTRUE;
2740}
2741
2742static Double_t f1_xboxe(double* x, double* par)
2743{
2744 double xx = x[0];
2745 double wx = 1. - par[4] * TMath::Power(xx + par[5], 2);
2746 double xboxe = par[0] * 0.25 * (1. + TMath::Erf((xx + par[1] - par[3]) / par[2]))
2747 * (1. + TMath::Erf((-xx + par[1] + par[3]) / par[2]));
2748 return xboxe * wx;
2749}
2750
2752{
2753 TH1* h1;
2754 h1 = (TH1*) gROOT->FindObjectAny(hname);
2755 if (NULL != h1) { fit_ybox(h1, 0.); }
2756}
2757
2758void CbmDeviceHitBuilderTof::fit_ybox(TH1* h1, Double_t ysize)
2759{
2760 Double_t* fpar = NULL;
2761 fit_ybox(h1, ysize, fpar);
2762}
2763
2764void CbmDeviceHitBuilderTof::fit_ybox(TH1* h1, Double_t ysize, Double_t* fpar = NULL)
2765{
2766 TAxis* xaxis = h1->GetXaxis();
2767 Double_t Ymin = xaxis->GetXmin();
2768 Double_t Ymax = xaxis->GetXmax();
2769 TF1* f1 = new TF1("YBox", f1_xboxe, Ymin, Ymax, 6);
2770 Double_t yini = (h1->GetMaximum() + h1->GetMinimum()) * 0.5;
2771 if (ysize == 0.) ysize = Ymax * 0.8;
2772 f1->SetParameters(yini, ysize * 0.5, 1., 0., 0., 0.);
2773 // f1->SetParLimits(1,ysize*0.8,ysize*1.2);
2774 f1->SetParLimits(2, 0.2, 3.);
2775 f1->SetParLimits(3, -4., 4.);
2776 if (fpar != NULL) {
2777 Double_t fp[4];
2778 for (Int_t i = 0; i < 4; i++)
2779 fp[i] = *fpar++;
2780 for (Int_t i = 0; i < 4; i++)
2781 f1->SetParameter(2 + i, fp[i]);
2782 LOG(debug) << "Ini Fpar for " << h1->GetName() << " with "
2783 << Form(" %6.3f %6.3f %6.3f %6.3f ", fp[0], fp[1], fp[2], fp[3]);
2784 }
2785
2786 h1->Fit("YBox", "Q");
2787
2788 double res[10];
2789 double err[10];
2790 res[9] = f1->GetChisquare();
2791
2792 for (int i = 0; i < 6; i++) {
2793 res[i] = f1->GetParameter(i);
2794 err[i] = f1->GetParError(i);
2795 //cout << " FPar "<< i << ": " << res[i] << ", " << err[i] << endl;
2796 }
2797 LOG(debug) << "YBox Fit of " << h1->GetName() << " ended with chi2 = " << res[9]
2798 << Form(", strip length %7.2f +/- %5.2f, position resolution "
2799 "%7.2f +/- %5.2f at y_cen = %7.2f +/- %5.2f",
2800 2. * res[1], 2. * err[1], res[2], err[2], res[3], err[3]);
2801}
2802
2804{
2805 LOG(info) << "LoadGeometry starting for " << fDigiBdfPar->GetNbDet() << " described detectors, "
2806 << fDigiPar->GetNrOfModules() << " geometrically known modules ";
2807
2808 //gGeoManager->Export("HitBuilder.loadgeo.root"); // write current status to file
2809
2810 Int_t iNrOfCells = fDigiPar->GetNrOfModules();
2811 LOG(info) << "Digi Parameter container contains " << iNrOfCells << " cells.";
2812
2813 for (Int_t icell = 0; icell < iNrOfCells; ++icell) {
2814
2815 Int_t cellId = fDigiPar->GetCellId(icell); // cellId is assigned in CbmTofCreateDigiPar
2816 fChannelInfo = fDigiPar->GetCell(cellId);
2817
2818 Int_t smtype = fGeoHandler->GetSMType(cellId);
2819 Int_t smodule = fGeoHandler->GetSModule(cellId);
2820 Int_t module = fGeoHandler->GetCounter(cellId);
2821 Int_t cell = fGeoHandler->GetCell(cellId);
2822
2823 Double_t x = fChannelInfo->GetX();
2824 Double_t y = fChannelInfo->GetY();
2825 Double_t z = fChannelInfo->GetZ();
2826 Double_t dx = fChannelInfo->GetSizex();
2827 Double_t dy = fChannelInfo->GetSizey();
2828 LOG(debug) << "-I- InitPar " << icell << " Id: " << Form("0x%08x", cellId) << " " << cell << " tmcs: " << smtype
2829 << " " << smodule << " " << module << " " << cell << " x=" << Form("%6.2f", x)
2830 << " y=" << Form("%6.2f", y) << " z=" << Form("%6.2f", z) << " dx=" << dx << " dy=" << dy;
2831
2832 TGeoNode* fNode = // prepare local->global trafo
2833 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
2834
2835 if (NULL == fNode) { // Transformation matrix not available !!!??? - Check
2836 LOG(error) << Form("Node at (%6.1f,%6.1f,%6.1f) : %p", fChannelInfo->GetX(), fChannelInfo->GetY(),
2837 fChannelInfo->GetZ(), fNode);
2838 ChangeState(fair::mq::Transition::Stop);
2839 }
2840 if (icell == 0) {
2841 TGeoHMatrix* cMatrix = gGeoManager->GetCurrentMatrix();
2842 //cNode->Print();
2843 cMatrix->Print();
2844 }
2845 }
2846
2847 Int_t iNbDet = fDigiBdfPar->GetNbDet();
2848 fvDeadStrips.resize(iNbDet);
2849 fvPulserOffset.resize(iNbDet);
2850 fvPulserTimes.resize(iNbDet);
2851
2852 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
2853 Int_t iUniqueId = fDigiBdfPar->GetDetUId(iDetIndx);
2854 Int_t iSmType = CbmTofAddress::GetSmType(iUniqueId);
2855 Int_t iSmId = CbmTofAddress::GetSmId(iUniqueId);
2856 Int_t iRpcId = CbmTofAddress::GetRpcId(iUniqueId);
2857 LOG(info) << " DetIndx " << iDetIndx << "(" << iNbDet << "), SmType " << iSmType << ", SmId " << iSmId << ", RpcId "
2858 << iRpcId << " => UniqueId " << Form("0x%08x ", iUniqueId)
2859 << Form(" Svel %6.6f, DeadStrips 0x%08x ", fDigiBdfPar->GetSigVel(iSmType, iSmId, iRpcId),
2860 fvDeadStrips[iDetIndx]);
2861
2862 Int_t iCell = -1;
2863 while (kTRUE) {
2864 Int_t iUCellId = CbmTofAddress::GetUniqueAddress(iSmId, iRpcId, ++iCell, 0, iSmType);
2865 fChannelInfo = fDigiPar->GetCell(iUCellId);
2866 if (NULL == fChannelInfo) break;
2867 }
2868
2869 fvPulserOffset[iDetIndx].resize(2); // provide vector for both sides
2870 for (Int_t i = 0; i < 2; i++)
2871 fvPulserOffset[iDetIndx][i] = 0.; // initialize
2872 fvPulserTimes[iDetIndx].resize(2); // provide vector for both sides
2873 }
2874
2875 // return kTRUE;
2876
2877 Int_t iNbSmTypes = fDigiBdfPar->GetNbSmTypes();
2878
2879 if (kTRUE == fDigiBdfPar->UseExpandedDigi()) {
2880 fStorDigi.resize(iNbSmTypes);
2881 fStorDigiInd.resize(iNbSmTypes);
2882 fviClusterSize.resize(iNbSmTypes);
2883 fviTrkMul.resize(iNbSmTypes);
2884 fvdX.resize(iNbSmTypes);
2885 fvdY.resize(iNbSmTypes);
2886 fvdDifX.resize(iNbSmTypes);
2887 fvdDifY.resize(iNbSmTypes);
2888 fvdDifCh.resize(iNbSmTypes);
2889 fviClusterMul.resize(iNbSmTypes);
2890 fvLastHits.resize(iNbSmTypes);
2891
2892 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
2893 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
2894 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
2895 fStorDigi[iSmType].resize(iNbSm * iNbRpc);
2896 fStorDigiInd[iSmType].resize(iNbSm * iNbRpc);
2897 fviClusterSize[iSmType].resize(iNbRpc);
2898 fviTrkMul[iSmType].resize(iNbRpc);
2899 fvdX[iSmType].resize(iNbRpc);
2900 fvdY[iSmType].resize(iNbRpc);
2901 fvdDifX[iSmType].resize(iNbRpc);
2902 fvdDifY[iSmType].resize(iNbRpc);
2903 fvdDifCh[iSmType].resize(iNbRpc);
2904 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
2905 fviClusterMul[iSmType].resize(iNbSm);
2906 fvLastHits[iSmType].resize(iNbSm);
2907 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
2908 fviClusterMul[iSmType][iSm].resize(iNbRpc);
2909 fvLastHits[iSmType][iSm].resize(iNbRpc);
2910 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc);
2911 if (iNbChan == 0) {
2912 LOG(warn) << "LoadGeometry: StoreDigi without channels "
2913 << Form("SmTy %3d, Sm %3d, NbRpc %3d, Rpc, %3d ", iSmType, iSm, iNbRpc, iRpc);
2914 }
2915 fStorDigi[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
2916 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
2917 fvLastHits[iSmType][iSm][iRpc].resize(iNbChan);
2918 } // for( Int_t iRpc = 0; iRpc < iNbRpc; iRpc++ )
2919 } // for( Int_t iSm = 0; iSm < iNbSm; iSm++ )
2920 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
2921 } // if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
2922 else {
2923 fStorDigi.resize(iNbSmTypes);
2924 fStorDigiInd.resize(iNbSmTypes);
2925 fviClusterSize.resize(iNbSmTypes);
2926 fviTrkMul.resize(iNbSmTypes);
2927 fvdX.resize(iNbSmTypes);
2928 fvdY.resize(iNbSmTypes);
2929 fvdDifX.resize(iNbSmTypes);
2930 fvdDifY.resize(iNbSmTypes);
2931 fvdDifCh.resize(iNbSmTypes);
2932 for (Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) {
2933 Int_t iNbSm = fDigiBdfPar->GetNbSm(iSmType);
2934 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
2935 fStorDigi[iSmType].resize(iNbSm * iNbRpc);
2936 fStorDigiInd[iSmType].resize(iNbSm * iNbRpc);
2937 fviClusterSize[iSmType].resize(iNbRpc);
2938 fviTrkMul[iSmType].resize(iNbRpc);
2939 fvdX[iSmType].resize(iNbRpc);
2940 fvdY[iSmType].resize(iNbRpc);
2941 fvdDifX[iSmType].resize(iNbRpc);
2942 fvdDifY[iSmType].resize(iNbRpc);
2943 fvdDifCh[iSmType].resize(iNbRpc);
2944 for (Int_t iSm = 0; iSm < iNbSm; iSm++) {
2945 for (Int_t iRpc = 0; iRpc < iNbRpc; iRpc++) {
2946 Int_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc);
2947 fStorDigi[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
2948 fStorDigiInd[iSmType][iSm * iNbRpc + iRpc].resize(iNbChan);
2949 } // for( Int_t iRpc = 0; iRpc < iNbRpc; iRpc++ )
2950 } // for( Int_t iSm = 0; iSm < iNbSm; iSm++ )
2951 } // for( Int_t iSmType = 0; iSmType < iNbSmTypes; iSmType++ )
2952 } // else of if( kTRUE == fDigiBdfPar->UseExpandedDigi() )
2953 return kTRUE;
2954}
2955
2957{
2958
2959 // Loop over the digis array and store the Digis in separate vectors for
2960 // each RPC modules
2961
2962 CbmTofDigi* pDigi;
2963
2964 Int_t iNbTofDigi = (Int_t) fTofCalDigiVec->size();
2965 //fTofCalDigisColl->GetEntriesFast();
2966 for (Int_t iDigInd = 0; iDigInd < iNbTofDigi; iDigInd++) {
2967 //pDigi = (CbmTofDigi*) fTofCalDigisColl->At(iDigInd);
2968 pDigi = &(fTofCalDigiVec->at(iDigInd));
2969
2970 /*
2971 LOG(info)<<"AC " // After Calibration
2972 <<Form("0x%08x",pDigi->GetAddress())<<" TSRC "
2973 <<pDigi->GetType()
2974 <<pDigi->GetSm()
2975 <<pDigi->GetRpc()
2976 <<Form("%2d",(Int_t)pDigi->GetChannel())<<" "
2977 <<pDigi->GetSide()<<" "
2978 <<Form("%f",pDigi->GetTime())<<" "
2979 <<pDigi->GetTot();
2980 */
2981 if (fDigiBdfPar->GetNbSmTypes() > pDigi->GetType() // prevent crash due to misconfiguration
2982 && fDigiBdfPar->GetNbSm(pDigi->GetType()) > pDigi->GetSm()
2983 && fDigiBdfPar->GetNbRpc(pDigi->GetType()) > pDigi->GetRpc()
2984 && fDigiBdfPar->GetNbChan(pDigi->GetType(), pDigi->GetRpc()) > pDigi->GetChannel()) {
2985 fStorDigi[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType()) + pDigi->GetRpc()]
2986 [pDigi->GetChannel()]
2987 .push_back(pDigi);
2988 fStorDigiInd[pDigi->GetType()][pDigi->GetSm() * fDigiBdfPar->GetNbRpc(pDigi->GetType()) + pDigi->GetRpc()]
2989 [pDigi->GetChannel()]
2990 .push_back(iDigInd);
2991 }
2992 else {
2993 LOG(info) << "Skip2 Digi "
2994 << " Type " << pDigi->GetType() << " " << fDigiBdfPar->GetNbSmTypes() << " Sm " << pDigi->GetSm() << " "
2995 << fDigiBdfPar->GetNbSm(pDigi->GetType()) << " Rpc " << pDigi->GetRpc() << " "
2996 << fDigiBdfPar->GetNbRpc(pDigi->GetType()) << " Ch " << pDigi->GetChannel() << " "
2997 << fDigiBdfPar->GetNbChan(pDigi->GetType(), 0);
2998 }
2999 } // for( Int_t iDigInd = 0; iDigInd < nTofDigi; iDigInd++ )
3000 return kTRUE;
3001}
3002
3004{
3005 //Output Log
3006 for (Int_t iHit = 0; iHit < fiNbHits; iHit++) {
3007 CbmTofHit* pHit = (CbmTofHit*) fTofHitsColl->At(iHit);
3008 LOG(debug) << Form("Found Hit %d, addr 0x%08x, X %6.2f, Y %6.2f Z %6.2f T %6.2f CLS %d", iHit, pHit->GetAddress(),
3009 pHit->GetX(), pHit->GetY(), pHit->GetZ(), pHit->GetTime(), pHit->GetFlag());
3010 }
3011 // prepare output hit vector
3012 std::vector<CbmTofHit*> vhit;
3013 vhit.resize(fiNbHits);
3014 for (Int_t iHit = 0; iHit < fiNbHits; iHit++) {
3015 CbmTofHit* pHit = (CbmTofHit*) fTofHitsColl->At(iHit);
3016 vhit[iHit] = pHit;
3017 }
3018
3019 // prepare output string streams
3020 std::stringstream ossE;
3021 boost::archive::binary_oarchive oaE(ossE);
3022 oaE << fEventHeader;
3023 std::string* strMsgE = new std::string(ossE.str());
3024
3025 std::stringstream oss;
3026 boost::archive::binary_oarchive oa(oss);
3027 oa << vhit;
3028 std::string* strMsg = new std::string(oss.str());
3029
3030 FairMQParts parts;
3031 parts.AddPart(NewMessage(
3032 const_cast<char*>(strMsgE->c_str()), // data
3033 strMsgE->length(), // size
3034 [](void*, void* object) { delete static_cast<std::string*>(object); },
3035 strMsgE)); // object that manages the data
3036
3037 parts.AddPart(NewMessage(
3038 const_cast<char*>(strMsg->c_str()), // data
3039 strMsg->length(), // size
3040 [](void*, void* object) { delete static_cast<std::string*>(object); },
3041 strMsg)); // object that manages the data
3042
3043 if (Send(parts, "tofhits")) {
3044 LOG(error) << "Problem sending data ";
3045 return false;
3046 }
3047
3048 return kTRUE;
3049}
3050
3051Bool_t CbmDeviceHitBuilderTof::SendAll() { return kTRUE; }
3052
3054{
3055 Int_t iNbTofHits = fTofHitsColl->GetEntriesFast();
3056 CbmTofHit* pHit;
3057 //gGeoManager->SetTopVolume( gGeoManager->FindVolumeFast("tof_v14a") );
3058 gGeoManager->CdTop();
3059
3060 if (0 < iNbTofHits) {
3061 Bool_t BSel[iNSel];
3062 Double_t dTTrig[iNSel];
3063 CbmTofHit* pTrig[iNSel];
3064 Double_t ddXdZ[iNSel];
3065 Double_t ddYdZ[iNSel];
3066 Double_t dSel2dXdYMin[iNSel];
3067
3068 Int_t iBeamRefMul = 0;
3069 Int_t iBeamAddRefMul = 0;
3070
3071 if (0 < iNSel) { // check software triggers
3072
3073 LOG(debug) << "FillHistos() for " << iNSel << " triggers"
3074 << ", Dut " << fDutId << fDutSm << fDutRpc << Form(", 0x%08x", fDutAddr) << ", Sel " << fSelId
3075 << fSelSm << fSelRpc << Form(", 0x%08x", fSelAddr) << ", Sel2 " << fSel2Id << fSel2Sm << fSel2Rpc
3076 << Form(", 0x%08x", fSel2Addr);
3077 /*
3078 LOG(debug) <<"FillHistos: Muls: "
3079 <<fviClusterMul[fDutId][fDutSm][fDutRpc]
3080 <<", "<<fviClusterMul[fSelId][fSelSm][fSelRpc]
3081 ;
3082 */
3083 // monitor multiplicities
3084 Int_t iNbDet = fDigiBdfPar->GetNbDet();
3085 for (Int_t iDetIndx = 0; iDetIndx < iNbDet; iDetIndx++) {
3086 Int_t iDetId = fviDetId[iDetIndx];
3087 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
3088 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
3089 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
3090 //LOG(info) << Form(" indx %d, Id 0x%08x, TSR %d %d %d", iDetIndx, iDetId, iSmType, iSm, iRpc)
3091 // ;
3092 if (NULL != fhRpcCluMul[iDetIndx]) fhRpcCluMul[iDetIndx]->Fill(fviClusterMul[iSmType][iSm][iRpc]); //
3093 }
3094
3095 // do input distributions first
3096 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
3097 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
3098 if (NULL == pHit) continue;
3099 if (StartAnalysisTime == 0.) {
3100 StartAnalysisTime = pHit->GetTime();
3101 LOG(info) << "StartAnalysisTime set to " << StartAnalysisTime << " ns. ";
3102 }
3103 Int_t iDetId = (pHit->GetAddress() & DetMask);
3104 std::map<UInt_t, UInt_t>::iterator it = fDetIdIndexMap.find(iDetId);
3105 if (it == fDetIdIndexMap.end()) continue; // continue for invalid detector index
3106 Int_t iDetIndx = it->second; //fDetIdIndexMap[iDetId];
3107
3108 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
3109 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
3110 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
3111 Int_t iCh = CbmTofAddress::GetChannelId(pHit->GetAddress());
3112
3113 Double_t dTimeAna = (pHit->GetTime() - StartAnalysisTime) / 1.E9;
3114 //LOG(debug)<<"TimeAna "<<StartAnalysisTime<<", "<< pHit->GetTime()<<", "<<dTimeAna;
3115 fhRpcCluRate[iDetIndx]->Fill(dTimeAna);
3116
3117 if (fdMemoryTime > 0. && fvLastHits[iSmType][iSm][iRpc][iCh].size() == 0)
3118 LOG(error) << Form(" <E> hit not stored in memory for TSRC %d%d%d%d", iSmType, iSm, iRpc, iCh);
3119 //CheckLHMemory();
3120
3121 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for outdated hits
3122 //std::list<CbmTofHit *>::iterator it0=fvLastHits[iSmType][iSm][iRpc][iCh].begin();
3123 //std::list<CbmTofHit *>::iterator itL=fvLastHits[iSmType][iSm][iRpc][iCh].end();
3124 //CbmTofHit* pH0 = *it0;
3125 //CbmTofHit* pHL = *(--itL);
3126 CbmTofHit* pH0 = fvLastHits[iSmType][iSm][iRpc][iCh].front();
3127 CbmTofHit* pHL = fvLastHits[iSmType][iSm][iRpc][iCh].back();
3128 if (pH0->GetTime() > pHL->GetTime())
3129 LOG(warn) << Form("Invalid time ordering in ev %8.0f in list of "
3130 "size %lu for TSRC %d%d%d%d: Delta t %f ",
3131 fdEvent, fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
3132 pHL->GetTime() - pH0->GetTime());
3133 //while( (*((std::list<CbmTofHit *>::iterator) fvLastHits[iSmType][iSm][iRpc][iCh].begin()))->GetTime()+fdMemoryTime < pHit->GetTime()
3134 while (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 2.
3135 || fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime() + fdMemoryTime < pHit->GetTime()) {
3136 LOG(debug) << " pop from list size " << fvLastHits[iSmType][iSm][iRpc][iCh].size()
3137 << Form(" outdated hits for ev %8.0f in TSRC %d%d%d%d", fdEvent, iSmType, iSm, iRpc, iCh)
3138 << Form(" with tHit - tLast %f ",
3139 pHit->GetTime() - fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime())
3140 //(*((std::list<CbmTofHit *>::iterator) fvLastHits[iSmType][iSm][iRpc][iCh].begin()))->GetTime())
3141 ;
3142 if (fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress() != pHit->GetAddress())
3143 LOG(error) << Form("Inconsistent address in list of size %lu for TSRC %d%d%d%d: "
3144 "0x%08x, time %f",
3145 fvLastHits[iSmType][iSm][iRpc][iCh].size(), iSmType, iSm, iRpc, iCh,
3146 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetAddress(),
3147 fvLastHits[iSmType][iSm][iRpc][iCh].front()->GetTime());
3148 fvLastHits[iSmType][iSm][iRpc][iCh].front()->Delete();
3149 fvLastHits[iSmType][iSm][iRpc][iCh].pop_front();
3150 }
3151 } //fvLastHits[iSmType][iSm][iRpc][iCh].size()>1)
3152
3153 // plot remaining time difference to previous hits
3154 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
3155 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
3156 Double_t dTotSum = 0.;
3157 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
3158 CbmLink L0 = digiMatch->GetLink(iLink);
3159 Int_t iDigInd0 = L0.GetIndex();
3160 Int_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex();
3161 CbmTofDigi* pDig0 = (CbmTofDigi*) (&(fTofCalDigiVec->at(iDigInd0)));
3162 CbmTofDigi* pDig1 = (CbmTofDigi*) (&(fTofCalDigiVec->at(iDigInd1)));
3163 dTotSum += pDig0->GetTot() + pDig1->GetTot();
3164 }
3165
3166 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
3167 itL--;
3168 for (UInt_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
3169 itL--;
3170 fhRpcDTLastHits[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()));
3171 fhRpcDTLastHits_CluSize[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
3172 digiMatch->GetNofLinks() / 2.);
3173 fhRpcDTLastHits_Tot[iDetIndx]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()), dTotSum);
3174 }
3175 }
3176 } // iHitInd loop end
3177
3178 // do reference first
3179 dTRef = dDoubleMax;
3180 fTRefHits = 0;
3181 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
3182 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
3183 if (NULL == pHit) continue;
3184 Int_t iDetId = (pHit->GetAddress() & DetMask);
3185
3186 if (fiBeamRefAddr == iDetId) {
3188 // Check Tot
3189 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
3190 Double_t TotSum = 0.;
3191 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
3192 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
3193 Int_t iDigInd0 = L0.GetIndex();
3194 if (iDigInd0 < (Int_t) fTofCalDigiVec->size()) {
3195 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
3196 TotSum += pDig0->GetTot();
3197 }
3198 }
3199 TotSum /= (0.5 * digiMatch->GetNofLinks());
3200 if (TotSum > fhRpcCluTot[iIndexDut]->GetYaxis()->GetXmax()) continue; // ignore too large clusters
3201
3202 fTRefHits = 1;
3203 if (pHit->GetTime() < dTRef) { dTRef = pHit->GetTime(); }
3204 iBeamRefMul++;
3205 }
3206 else { //additional reference type multiplicity
3207 if (fiBeamRefType == CbmTofAddress::GetSmType(iDetId)) iBeamAddRefMul++;
3208 }
3209 }
3210 LOG(debug) << "FillHistos: BRefMul: " << iBeamRefMul << ", " << iBeamAddRefMul;
3211 if (iBeamRefMul == 0) return kFALSE; // don't fill histos without reference time
3212 if (iBeamAddRefMul < fiBeamAddRefMul) return kFALSE; // ask for confirmation by other beam counters
3213
3214 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3215 BSel[iSel] = kFALSE;
3216 pTrig[iSel] = NULL;
3217 Int_t iDutMul = 0;
3218 Int_t iRefMul = 0;
3219 Int_t iR0 = 0;
3220 Int_t iRl = 0;
3221 ddXdZ[iSel] = 0.;
3222 ddYdZ[iSel] = 0.;
3223 dSel2dXdYMin[iSel] = 1.E300;
3224
3225 switch (iSel) {
3226 case 0: // Detector under Test (Dut) && Diamonds,BeamRef
3227 iRl = fviClusterMul[fDutId][fDutSm].size();
3228 if (fDutRpc > -1) {
3229 iR0 = fDutRpc;
3230 iRl = fDutRpc + 1;
3231 }
3232 for (Int_t iRpc = iR0; iRpc < iRl; iRpc++)
3233 iDutMul += fviClusterMul[fDutId][fDutSm][iRpc];
3234 LOG(debug) << "Selector 0: DutMul " << fviClusterMul[fDutId][fDutSm][fDutRpc] << ", " << iDutMul
3235 << ", BRefMul " << iBeamRefMul << " TRef: " << dTRef << ", BeamAddRefMul " << iBeamAddRefMul
3236 << ", " << fiBeamAddRefMul;
3237 if (iDutMul > 0 && iDutMul < fiCluMulMax) {
3238 dTTrig[iSel] = dDoubleMax;
3239 // LOG(debug1)<<"Found selector 0, NbHits "<<iNbTofHits;
3240 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
3241 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
3242 if (NULL == pHit) continue;
3243 Int_t iDetId = (pHit->GetAddress() & DetMask);
3244 // LOG(debug1)<<Form(" Det 0x%08x, Dut 0x%08x, T %f, TTrig %f",
3245 // iDetId, fDutAddr, pHit->GetTime(), dTTrig[iSel])
3246 // ;
3247 //if( fDutId == CbmTofAddress::GetSmType( iDetId ))
3248 if (fDutAddr == iDetId) {
3249 if (pHit->GetTime() < dTTrig[iSel]) {
3250 dTTrig[iSel] = pHit->GetTime();
3251 pTrig[iSel] = pHit;
3252 BSel[iSel] = kTRUE;
3253 }
3254 }
3255 }
3256 LOG(debug) << Form("Found selector 0 with mul %d from 0x%08x at %f ", iDutMul, pTrig[iSel]->GetAddress(),
3257 dTTrig[iSel]);
3258 }
3259 break;
3260
3261 case 1: // MRef & BRef
3262 iRl = fviClusterMul[fSelId][fSelSm].size();
3263 if (fSelRpc > -1) {
3264 iR0 = fSelRpc;
3265 iRl = fSelRpc + 1;
3266 }
3267 for (Int_t iRpc = iR0; iRpc < iRl; iRpc++)
3268 iRefMul += fviClusterMul[fSelId][fSelSm][iRpc];
3269 LOG(debug) << "FillHistos(): selector 1: RefMul " << fviClusterMul[fSelId][fSelSm][fSelRpc] << ", "
3270 << iRefMul << ", BRefMul " << iBeamRefMul;
3271 if (iRefMul > 0 && iRefMul < fiCluMulMax) {
3272 // LOG(debug1)<<"FillHistos(): Found selector 1";
3273 dTTrig[iSel] = dDoubleMax;
3274 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
3275 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
3276 if (NULL == pHit) continue;
3277
3278 Int_t iDetId = (pHit->GetAddress() & DetMask);
3279 if (fSelAddr == iDetId) {
3280 if (pHit->GetTime() < dTTrig[iSel]) {
3281 dTTrig[iSel] = pHit->GetTime();
3282 pTrig[iSel] = pHit;
3283 BSel[iSel] = kTRUE;
3284 }
3285 }
3286 }
3287 LOG(debug) << Form("Found selector 1 with mul %d from 0x%08x at %f ", iRefMul, pTrig[iSel]->GetAddress(),
3288 dTTrig[iSel]);
3289 }
3290 break;
3291
3292 default: LOG(info) << "FillHistos: selection not implemented " << iSel; ;
3293 } // switch end
3294 if (fTRefMode > 10) { dTTrig[iSel] = dTRef; }
3295 } // iSel - loop end
3296
3297 if (fSel2Id > 0) { // confirm selector by independent match
3298 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3299 if (BSel[iSel]) {
3300 BSel[iSel] = kFALSE;
3303 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
3304 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
3305 if (NULL == pHit) continue;
3306 Int_t iDetId = (pHit->GetAddress() & DetMask);
3307 if (fSel2Addr == iDetId) {
3308 Double_t dzscal = 1.;
3309 if (fEnableMatchPosScaling) dzscal = pHit->GetZ() / pTrig[iSel]->GetZ();
3310 Double_t dSEl2dXdz = (pHit->GetX() - pTrig[iSel]->GetX()) / (pHit->GetZ() - pTrig[iSel]->GetZ());
3311 Double_t dSEl2dYdz = (pHit->GetY() - pTrig[iSel]->GetY()) / (pHit->GetZ() - pTrig[iSel]->GetZ());
3312
3313 if (TMath::Sqrt(TMath::Power(pHit->GetX() - dzscal * pTrig[iSel]->GetX(), 2.)
3314 + TMath::Power(pHit->GetY() - dzscal * pTrig[iSel]->GetY(), 2.))
3315 < fdCaldXdYMax) {
3316 BSel[iSel] = kTRUE;
3317 Double_t dX2Y2 = TMath::Sqrt(dSEl2dXdz * dSEl2dXdz + dSEl2dYdz * dSEl2dYdz);
3318 if (dX2Y2 < dSel2dXdYMin[iSel]) {
3319 ddXdZ[iSel] = dSEl2dXdz;
3320 ddYdZ[iSel] = dSEl2dYdz;
3321 dSel2dXdYMin[iSel] = dX2Y2;
3322 }
3323 break;
3324 }
3325 }
3326 }
3327 } // BSel condition end
3328 } // iSel lopp end
3329 } // Sel2Id condition end
3330 UInt_t uTriggerPattern = 1;
3331
3332 for (Int_t iSel = 0; iSel < iNSel; iSel++)
3333 if (BSel[iSel]) {
3334 uTriggerPattern |= (0x1 << (iSel * 3 + CbmTofAddress::GetRpcId(pTrig[iSel]->GetAddress() & DetMask)));
3335 }
3336
3337 for (Int_t iSel = 0; iSel < iNSel; iSel++) {
3338 if (BSel[iSel]) {
3339 if (dTRef != 0. && fTRefHits > 0) {
3340 for (UInt_t uChannel = 0; uChannel < 16; uChannel++) {
3341 if (uTriggerPattern & (0x1 << uChannel)) { fhSeldT[iSel]->Fill(dTTrig[iSel] - dTRef, uChannel); }
3342 }
3343 }
3344 }
3345 }
3346 } // 0<iNSel software triffer check end
3347
3348 for (Int_t iHitInd = 0; iHitInd < iNbTofHits; iHitInd++) {
3349 pHit = (CbmTofHit*) fTofHitsColl->At(iHitInd);
3350 if (NULL == pHit) continue;
3351
3352 Int_t iDetId = (pHit->GetAddress() & DetMask);
3353 std::map<UInt_t, UInt_t>::iterator it = fDetIdIndexMap.find(iDetId);
3354 if (it == fDetIdIndexMap.end()) continue; // continue for invalid detector index
3355 Int_t iDetIndx = it->second; //fDetIdIndexMap[iDetId];
3356
3357 Int_t iSmType = CbmTofAddress::GetSmType(iDetId);
3358 Int_t iSm = CbmTofAddress::GetSmId(iDetId);
3359 Int_t iRpc = CbmTofAddress::GetRpcId(iDetId);
3360 Int_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType);
3361 if (-1 < fviClusterMul[iSmType][iSm][iRpc]) {
3362 for (Int_t iSel = 0; iSel < iNSel; iSel++)
3363 if (BSel[iSel]) {
3364 Double_t w = fviClusterMul[iSmType][iSm][iRpc];
3365 if (w == 0.) w = 1.;
3366 else
3367 w = 1. / w;
3368 fhTRpcCluMul[iDetIndx][iSel]->Fill(fviClusterMul[iSmType][iSm][iRpc], w);
3369 }
3370 }
3371
3372 if (fviClusterMul[iSmType][iSm][iRpc] > fiCluMulMax) continue; // skip this event
3373 if (iBeamRefMul == 0) break;
3374
3375 Int_t iChId = pHit->GetAddress();
3376 fChannelInfo = fDigiPar->GetCell(iChId);
3377 Int_t iCh = CbmTofAddress::GetChannelId(iChId);
3378 if (NULL == fChannelInfo) {
3379 LOG(error) << "Invalid Channel Pointer for ChId " << Form(" 0x%08x ", iChId) << ", Ch " << iCh;
3380 continue;
3381 }
3382 /*TGeoNode *fNode=*/ // prepare global->local trafo
3383 gGeoManager->FindNode(fChannelInfo->GetX(), fChannelInfo->GetY(), fChannelInfo->GetZ());
3384 /*
3385 LOG(debug1)<<"Hit info: "
3386 <<Form(" 0x%08x %d %f %f %f %f %f %d",iChId,iCh,
3387 pHit->GetX(),pHit->GetY(),pHit->GetTime(),fChannelInfo->GetX(),fChannelInfo->GetY(), iHitInd )
3388 ;
3389 */
3390 Double_t hitpos[3];
3391 hitpos[0] = pHit->GetX();
3392 hitpos[1] = pHit->GetY();
3393 hitpos[2] = pHit->GetZ();
3394 Double_t hitpos_local[3];
3395 //TGeoNode* cNode=
3396 gGeoManager->GetCurrentNode();
3397 gGeoManager->MasterToLocal(hitpos, hitpos_local);
3398 /*
3399 LOG(debug1)<< Form(" MasterToLocal for %d, %d%d%d, node %p: (%6.1f,%6.1f,%6.1f) ->(%6.1f,%6.1f,%6.1f)",
3400 iDetIndx, iSmType, iSm, iRpc,
3401 cNode, hitpos[0], hitpos[1], hitpos[2],
3402 hitpos_local[0], hitpos_local[1], hitpos_local[2])
3403 ;
3404 */
3405 fhRpcCluPosition[iDetIndx]->Fill((Double_t) iCh, hitpos_local[1]); //pHit->GetY()-fChannelInfo->GetY());
3406 fhSmCluPosition[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), hitpos_local[1]);
3407
3408 for (Int_t iSel = 0; iSel < iNSel; iSel++)
3409 if (BSel[iSel]) {
3410 fhTRpcCluPosition[iDetIndx][iSel]->Fill((Double_t) iCh,
3411 hitpos_local[1]); //pHit->GetY()-fChannelInfo->GetY());
3412 fhTSmCluPosition[iSmType][iSel]->Fill((Double_t)(iSm * iNbRpc + iRpc), hitpos_local[1]);
3413 }
3414
3415 if (TMath::Abs(hitpos_local[1]) > fChannelInfo->GetSizey() * fPosYMaxScal) continue;
3416 /*
3417 LOG(debug1)<<" TofDigiMatchColl entries:"
3418 <<fTofDigiMatchColl->GetEntriesFast()
3419 ;
3420 */
3421 if (iHitInd > fTofDigiMatchColl->GetEntriesFast()) {
3422 LOG(error) << " Inconsistent DigiMatches for Hitind " << iHitInd
3423 << ", TClonesArraySize: " << fTofDigiMatchColl->GetEntriesFast();
3424 }
3425 CbmMatch* digiMatch = (CbmMatch*) fTofDigiMatchColl->At(iHitInd);
3426 /*
3427 LOG(debug1)<<" got "
3428 <<digiMatch->GetNofLinks()<< " matches for iCh "<<iCh<<" at iHitInd "<<iHitInd
3429 ;
3430 */
3431 fhRpcCluSize[iDetIndx]->Fill((Double_t) iCh, digiMatch->GetNofLinks() / 2.);
3432
3433 for (Int_t iSel = 0; iSel < iNSel; iSel++)
3434 if (BSel[iSel]) {
3435 fhTRpcCluSize[iDetIndx][iSel]->Fill((Double_t) iCh, digiMatch->GetNofLinks() / 2.);
3436 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
3437 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
3438 itL--;
3439 for (UInt_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
3440 itL--;
3441 fhTRpcCluSizeDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
3442 digiMatch->GetNofLinks() / 2.);
3443 }
3444 }
3445 }
3446
3447 Double_t TotSum = 0.;
3448 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink++) { // loop over digis
3449 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
3450 Int_t iDigInd0 = L0.GetIndex();
3451 if (iDigInd0 < (Int_t) fTofCalDigiVec->size()) {
3452 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
3453 TotSum += pDig0->GetTot();
3454 }
3455 }
3456 Double_t dMeanTimeSquared = 0.;
3457 Double_t dNstrips = 0.;
3458
3459 Double_t dDelTof = 0.;
3460 Double_t dTcor[iNSel];
3461 Double_t dTTcor[iNSel];
3462 Double_t dZsign[iNSel];
3463 Double_t dzscal = 1.;
3464 //Double_t dDist=0.;
3465
3466 for (Int_t iLink = 0; iLink < digiMatch->GetNofLinks(); iLink += 2) { // loop over digis
3467 CbmLink L0 = digiMatch->GetLink(iLink); //vDigish.at(ivDigInd);
3468 Int_t iDigInd0 = L0.GetIndex();
3469 Int_t iDigInd1 = (digiMatch->GetLink(iLink + 1)).GetIndex(); //vDigish.at(ivDigInd+1);
3470 //LOG(debug1)<<" " << iDigInd0<<", "<<iDigInd1;
3471
3472 if (iDigInd0 < (Int_t) fTofCalDigiVec->size() && iDigInd1 < (Int_t) fTofCalDigiVec->size()) {
3473 CbmTofDigi* pDig0 = &(fTofCalDigiVec->at(iDigInd0));
3474 CbmTofDigi* pDig1 = &(fTofCalDigiVec->at(iDigInd1));
3475 if ((Int_t) pDig0->GetType() != iSmType) {
3476 LOG(error) << Form(" Wrong Digi SmType for Tofhit %d in iDetIndx "
3477 "%d, Ch %d with %3.0f strips at Indx %d, %d",
3478 iHitInd, iDetIndx, iCh, dNstrips, iDigInd0, iDigInd1);
3479 }
3480 /*
3481 LOG(debug1)<<" fhRpcCluTot: Digi 0 "<<iDigInd0<<": Ch "<<pDig0->GetChannel()<<", Side "<<pDig0->GetSide()
3482 <<", StripSide "<<(Double_t)iCh*2.+pDig0->GetSide()
3483 <<" Digi 1 "<<iDigInd1<<": Ch "<<pDig1->GetChannel()<<", Side "<<pDig1->GetSide()
3484 <<" , StripSide "<<(Double_t)iCh*2.+pDig1->GetSide()
3485 <<", Tot0 " << pDig0->GetTot() <<", Tot1 "<<pDig1->GetTot();
3486 */
3487 fhRpcCluTot[iDetIndx]->Fill(pDig0->GetChannel() * 2. + pDig0->GetSide(), pDig0->GetTot());
3488 fhRpcCluTot[iDetIndx]->Fill(pDig1->GetChannel() * 2. + pDig1->GetSide(), pDig1->GetTot());
3489
3490 Int_t iCh0 = pDig0->GetChannel();
3491 Int_t iCh1 = pDig1->GetChannel();
3492 Int_t iS0 = pDig0->GetSide();
3493 Int_t iS1 = pDig1->GetSide();
3494 if (iCh0 != iCh1 || iS0 == iS1) {
3495 LOG(error) << Form(" MT2 for Tofhit %d in iDetIndx %d, Ch %d from %3.0f strips: ", iHitInd, iDetIndx, iCh,
3496 dNstrips)
3497 << Form(" Dig0: Ind %d, Ch %d, Side %d, T: %6.1f ", iDigInd0, iCh0, iS0, pDig0->GetTime())
3498 << Form(" Dig1: Ind %d, Ch %d, Side %d, T: %6.1f ", iDigInd1, iCh1, iS1, pDig1->GetTime());
3499 continue;
3500 }
3501
3502 if (0 > iCh0 || fDigiBdfPar->GetNbChan(iSmType, iRpc) <= iCh0) {
3503 LOG(error) << Form(" Wrong Digi for Tofhit %d in iDetIndx %d, Ch %d at Indx %d, %d "
3504 "from %3.0f strips: %d, %d, %d, %d",
3505 iHitInd, iDetIndx, iCh, iDigInd0, iDigInd1, dNstrips, iCh0, iCh1, iS0, iS1);
3506 continue;
3507 }
3508
3509 if (digiMatch->GetNofLinks() > 2) //&& digiMatch->GetNofLinks()<8 ) // FIXME: hardcoded limits on CluSize
3510 {
3511 dNstrips += 1.;
3512 dMeanTimeSquared += TMath::Power(0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime(), 2);
3513 // fhRpcCluAvWalk[iDetIndx]->Fill(0.5*(pDig0->GetTot()+pDig1->GetTot()),
3514 // 0.5*(pDig0->GetTime()+pDig1->GetTime())-pHit->GetTime());
3515 fhRpcCluAvLnWalk[iDetIndx]->Fill(TMath::Log10(0.5 * (pDig0->GetTot() + pDig1->GetTot())),
3516 0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime());
3517
3518 Double_t dTotWeigth = (pDig0->GetTot() + pDig1->GetTot()) / TotSum;
3519 Double_t dCorWeigth = 1. - dTotWeigth;
3520
3521 fhRpcCluDelTOff[iDetIndx]->Fill(
3522 pDig0->GetChannel(), dCorWeigth * (0.5 * (pDig0->GetTime() + pDig1->GetTime()) - pHit->GetTime()));
3523
3524 Double_t dDelPos = 0.5 * (pDig0->GetTime() - pDig1->GetTime()) * fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc);
3525 if (0 == pDig0->GetSide()) dDelPos *= -1.;
3526 fhRpcCluDelPos[iDetIndx]->Fill(pDig0->GetChannel(), dCorWeigth * (dDelPos - hitpos_local[1]));
3527
3528 fhRpcCluWalk[iDetIndx][iCh0][iS0]->Fill(
3529 pDig0->GetTot(),
3530 pDig0->GetTime()
3531 - (pHit->GetTime()
3532 - (1. - 2. * pDig0->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
3533 fhRpcCluWalk[iDetIndx][iCh1][iS1]->Fill(
3534 pDig1->GetTot(),
3535 pDig1->GetTime()
3536 - (pHit->GetTime()
3537 - (1. - 2. * pDig1->GetSide()) * hitpos_local[1] / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
3538
3539 fhRpcCluAvWalk[iDetIndx]->Fill(pDig0->GetTot(), pDig0->GetTime()
3540 - (pHit->GetTime()
3541 - (1. - 2. * pDig0->GetSide()) * hitpos_local[1]
3542 / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
3543 fhRpcCluAvWalk[iDetIndx]->Fill(pDig1->GetTot(), pDig1->GetTime()
3544 - (pHit->GetTime()
3545 - (1. - 2. * pDig1->GetSide()) * hitpos_local[1]
3546 / fDigiBdfPar->GetSigVel(iSmType, iSm, iRpc)));
3547 } // end of Clustersize > 1 condition
3548 /*
3549 LOG(debug1)<<" fhTRpcCluTot: Digi 0 "<<iDigInd0<<": Ch "<<pDig0->GetChannel()<<", Side "<<pDig0->GetSide()
3550 <<", StripSide "<<(Double_t)iCh*2.+pDig0->GetSide()
3551 <<" Digi 1 "<<iDigInd1<<": Ch "<<pDig1->GetChannel()<<", Side "<<pDig1->GetSide()
3552 <<", StripSide "<<(Double_t)iCh*2.+pDig1->GetSide()
3553 ;
3554 */
3555 for (Int_t iSel = 0; iSel < iNSel; iSel++)
3556 if (BSel[iSel]) {
3557 if (NULL == pHit || NULL == pTrig[iSel]) {
3558 LOG(info) << " invalid pHit, iSel " << iSel << ", iDetIndx " << iDetIndx;
3559 break;
3560 }
3561 if (pHit->GetAddress() == pTrig[iSel]->GetAddress()) continue;
3562
3563 fhTRpcCluTot[iDetIndx][iSel]->Fill(pDig0->GetChannel() * 2. + pDig0->GetSide(), pDig0->GetTot());
3564 fhTRpcCluTot[iDetIndx][iSel]->Fill(pDig1->GetChannel() * 2. + pDig1->GetSide(), pDig1->GetTot());
3565 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
3566 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
3567 itL--;
3568 for (UInt_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
3569 itL--;
3570 fhTRpcCluTotDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
3571 pDig0->GetTot());
3572 fhTRpcCluTotDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(pHit->GetTime() - (*itL)->GetTime()),
3573 pDig1->GetTot());
3574 }
3575 }
3576 if (iLink == 0) { // Fill histo only once (for 1. digi entry)
3577 if (fEnableMatchPosScaling) dzscal = pHit->GetZ() / pTrig[iSel]->GetZ();
3578 fhTRpcCludXdY[iDetIndx][iSel]->Fill(pHit->GetX() - dzscal * pTrig[iSel]->GetX(),
3579 pHit->GetY() - dzscal * pTrig[iSel]->GetY());
3580 dZsign[iSel] = 1.;
3581 if (pHit->GetZ() < pTrig[iSel]->GetZ()) dZsign[iSel] = -1.;
3582 }
3583 // look for geometrical match with selector hit
3584 //if( iSmType==fiBeamRefType // to get entries in diamond/BeamRef histos
3585 if (iSmType == 5 // FIXME, to get entries in diamond histos
3586 || TMath::Sqrt(TMath::Power(pHit->GetX() - dzscal * pTrig[iSel]->GetX(), 2.)
3587 + TMath::Power(pHit->GetY() - dzscal * pTrig[iSel]->GetY(), 2.))
3588 < fdCaldXdYMax) {
3589 if (!fEnableMatchPosScaling && dSel2dXdYMin[iSel] < 1.E300)
3590 if (TMath::Sqrt(
3591 TMath::Power(pHit->GetX()
3592 - (pTrig[iSel]->GetX() + ddXdZ[iSel] * (pHit->GetZ() - (pTrig[iSel]->GetZ()))),
3593 2.)
3594 + TMath::Power(pHit->GetY()
3595 - (pTrig[iSel]->GetY() + ddYdZ[iSel] * (pHit->GetZ() - (pTrig[iSel]->GetZ()))),
3596 2.))
3597 > 0.5 * fdCaldXdYMax)
3598 continue; // refine position selection cut in cosmic measurement
3599 dTcor[iSel] = 0.; // precaution
3600 if (dTRef != 0.
3601 && TMath::Abs(dTRef - dTTrig[iSel]) < fdDelTofMax) { // correct times for DelTof - velocity spread
3602 if (iLink == 0) { // do calculations only once (at 1. digi entry) // interpolate!
3603 // calculate spatial distance to trigger hit
3604 /*
3605 dDist=TMath::Sqrt(TMath::Power(pHit->GetX()-pTrig[iSel]->GetX(),2.)
3606 +TMath::Power(pHit->GetY()-pTrig[iSel]->GetY(),2.)
3607 +TMath::Power(pHit->GetZ()-pTrig[iSel]->GetZ(),2.));
3608 */
3609 // determine correction value
3610 //if(fiBeamRefAddr != iDetId) // do not do this for reference counter itself
3611 if (fTRefMode < 11) // do not do this for trigger counter itself
3612 {
3613 Double_t dTentry = dTRef - dTTrig[iSel] + fdDelTofMax;
3614 Int_t iBx = dTentry / 2. / fdDelTofMax * nbClDelTofBinX;
3615 if (iBx < 0) iBx = 0;
3616 if (iBx > nbClDelTofBinX - 1) iBx = nbClDelTofBinX - 1;
3617 Double_t dBinWidth = 2. * fdDelTofMax / nbClDelTofBinX;
3618 Double_t dDTentry = dTentry - ((Double_t) iBx) * dBinWidth;
3619 Int_t iBx1 = 0;
3620 dDTentry < 0 ? iBx1 = iBx - 1 : iBx1 = iBx + 1;
3621 Double_t w0 = 1. - TMath::Abs(dDTentry) / dBinWidth;
3622 Double_t w1 = 1. - w0;
3623 if (iBx1 < 0) iBx1 = 0;
3624 if (iBx1 > nbClDelTofBinX - 1) iBx1 = nbClDelTofBinX - 1;
3625 dDelTof = fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx][iSel] * w0
3626 + fvCPDelTof[iSmType][iSm * iNbRpc + iRpc][iBx1][iSel] * w1;
3627 //dDelTof *= dDist; // has to be consistent with fhTRpcCluDelTof filling
3628 /*
3629 LOG(debug1)<<Form(" DelTof for SmT %d, Sm %d, R %d, T %d, dTRef %6.1f, Bx %d, Bx1 %d, DTe %6.1f -> DelT %6.1f",
3630 iSmType, iSm, iRpc, iSel, dTRef-dTTrig[iSel], iBx, iBx1, dDTentry, dDelTof)
3631 ;
3632 */
3633 }
3634 dTTcor[iSel] = dDelTof * dZsign[iSel];
3635 dTcor[iSel] = pHit->GetTime() - dDelTof - dTTrig[iSel];
3636 // Double_t dAvTot=0.5*(pDig0->GetTot()+pDig1->GetTot());
3637 } // if(iLink==0)
3638
3639 LOG(debug) << Form(" TRpcCluWalk for Ev %d, Link %d(%d), Sel %d, TSR %d%d%d, "
3640 "Ch %d,%d, S %d,%d T %f, DelTof %6.1f, W-ent: %6.0f,%6.0f",
3641 fiNevtBuild, iLink, (Int_t) digiMatch->GetNofLinks(), iSel, iSmType, iSm, iRpc,
3642 iCh0, iCh1, iS0, iS1, dTTrig[iSel], dDelTof,
3643 fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->GetEntries(),
3644 fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->GetEntries());
3645
3646 if (fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->GetEntries()
3647 != fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->GetEntries())
3648 LOG(error) << Form(" Inconsistent walk histograms -> debugging "
3649 "necessary ... for %d, %d, %d, %d, %d, %d, %d ",
3650 fiNevtBuild, iDetIndx, iSel, iCh0, iCh1, iS0, iS1);
3651 /*
3652 LOG(debug1)<<Form(" TRpcCluWalk values side %d: %f, %f, side %d: %f, %f ",
3653 iS0,pDig0->GetTot(),pDig0->GetTime()
3654 +((1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTcor[iSel]-dTTrig[iSel],
3655 iS1,pDig1->GetTot(),pDig1->GetTime()
3656 +((1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTcor[iSel]-dTTrig[iSel])
3657 ;
3658 */
3659 fhTRpcCluWalk[iDetIndx][iSel][iCh0][iS0]->Fill(
3660 pDig0->GetTot(),
3661 //(pDig0->GetTime()+((1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
3662 //dTcor[iSel]+(1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
3663 dTcor[iSel]);
3664 fhTRpcCluWalk[iDetIndx][iSel][iCh1][iS1]->Fill(
3665 pDig1->GetTot(),
3666 //(pDig1->GetTime()+((1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
3667 //dTcor[iSel]+(1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
3668 dTcor[iSel]);
3669
3670 fhTRpcCluAvWalk[iDetIndx][iSel]->Fill(
3671 pDig0->GetTot(),
3672 //(pDig0->GetTime()+((1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
3673 //dTcor[iSel]+(1.-2.*pDig0->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
3674 dTcor[iSel]);
3675 fhTRpcCluAvWalk[iDetIndx][iSel]->Fill(
3676 pDig1->GetTot(),
3677 //(pDig1->GetTime()+((1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc))-dTTrig[iSel])-dTTcor[iSel]);
3678 //dTcor[iSel]+(1.-2.*pDig1->GetSide())*hitpos_local[1]/fDigiBdfPar->GetSigVel(iSmType,iSm,iRpc));
3679 dTcor[iSel]);
3680
3681 if (iLink == 0) { // Fill histo only once (for 1. digi entry)
3682 //fhTRpcCluDelTof[iDetIndx][iSel]->Fill(dTRef-dTTrig[iSel],dTcor[iSel]/dDist);
3683 fhTRpcCluDelTof[iDetIndx][iSel]->Fill(dTRef - dTTrig[iSel], dTcor[iSel]);
3684 fhTSmCluTOff[iSmType][iSel]->Fill((Double_t)(iSm * iNbRpc + iRpc), dTcor[iSel]);
3685 fhTSmCluTRun[iSmType][iSel]->Fill(fdEvent, dTcor[iSel]);
3686 if (iDetId
3687 != (pTrig[iSel]->GetAddress()
3688 & DetMask)) { // transform matched hit-pair back into detector frame
3689 hitpos[0] = pHit->GetX() - dzscal * pTrig[iSel]->GetX() + fChannelInfo->GetX();
3690 hitpos[1] = pHit->GetY() - dzscal * pTrig[iSel]->GetY() + fChannelInfo->GetY();
3691 hitpos[2] = pHit->GetZ();
3692 gGeoManager->MasterToLocal(hitpos, hitpos_local); // transform into local frame
3693 fhRpcCluDelMatPos[iDetIndx]->Fill((Double_t) iCh, hitpos_local[1]);
3694 fhRpcCluDelMatTOff[iDetIndx]->Fill((Double_t) iCh,
3695 (pHit->GetTime() - dTTrig[iSel]) - dTTcor[iSel]);
3696 }
3697 } // iLink==0 condition end
3698 } // position condition end
3699 } // Match condition end
3700 } // closing of selector loop
3701 }
3702 else {
3703 LOG(error) << "FillHistos: invalid digi index " << iDetIndx << " digi0,1" << iDigInd0 << ", " << iDigInd1
3704 << " - max:" << fTofCalDigiVec->size()
3705 // << " in event " << XXX
3706 ;
3707 }
3708 } // iLink digi loop end;
3709 if (1 < dNstrips) {
3710 // Double_t dVar=dMeanTimeSquared/dNstrips - TMath::Power(pHit->GetTime(),2);
3711 Double_t dVar = dMeanTimeSquared / (dNstrips - 1);
3712 //if(dVar<0.) dVar=0.;
3713 Double_t dTrms = TMath::Sqrt(dVar);
3714 LOG(debug) << Form(" Trms for Tofhit %d in iDetIndx %d, Ch %d from "
3715 "%3.0f strips: %6.3f ns",
3716 iHitInd, iDetIndx, iCh, dNstrips, dTrms);
3717 fhRpcCluTrms[iDetIndx]->Fill((Double_t) iCh, dTrms);
3718 pHit->SetTimeError(dTrms);
3719 }
3720 /*
3721 LOG(debug1)<<" Fill Time of iDetIndx "<<iDetIndx<<", hitAddr "
3722 <<Form(" %08x, y = %5.2f",pHit->GetAddress(),hitpos_local[1])
3723 <<" for |y| <"
3724 <<fhRpcCluPosition[iDetIndx]->GetYaxis()->GetXmax()
3725 ;
3726 */
3727 if (TMath::Abs(hitpos_local[1]) < (fhRpcCluPosition[iDetIndx]->GetYaxis()->GetXmax())) {
3728 if (dTRef != 0. && fTRefHits == 1) {
3729 fhRpcCluTOff[iDetIndx]->Fill((Double_t) iCh, pHit->GetTime() - dTRef);
3730 fhSmCluTOff[iSmType]->Fill((Double_t)(iSm * iNbRpc + iRpc), pHit->GetTime() - dTRef);
3731
3732 for (Int_t iSel = 0; iSel < iNSel; iSel++)
3733 if (BSel[iSel]) {
3734 /*
3735 LOG(debug1)<<" TRpcCluTOff "<< iDetIndx <<", Sel "<< iSel
3736 <<Form(", Dt %7.3f, LHsize %lu ",
3737 pHit->GetTime()-dTTrig[iSel],fvLastHits[iSmType][iSm][iRpc][iCh].size());
3738 */
3739 if (pHit->GetAddress() == pTrig[iSel]->GetAddress()) continue;
3740
3741 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
3742 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
3743 itL--;
3744 for (UInt_t iH = 0; iH < fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1; iH++) {
3745 itL--;
3746 //LOG(debug1)<<Form(" %f,",pHit->GetTime()-(*itL)->GetTime());
3747 }
3748 }
3749
3750 // fill Time Offset histograms without velocity spread (DelTof) correction
3751 fhTRpcCluTOff[iDetIndx][iSel]->Fill((Double_t) iCh,
3752 pHit->GetTime()
3753 - dTTrig[iSel]); // -dTTcor[iSel] only valid for matches
3754 if (fvLastHits[iSmType][iSm][iRpc][iCh].size() > 1) { // check for previous hits in memory time interval
3755 std::list<CbmTofHit*>::iterator itL = fvLastHits[iSmType][iSm][iRpc][iCh].end();
3756 itL--;
3757 for (Int_t iH = 0; iH < 1; iH++) { // use only last hit
3758 // for(Int_t iH=0; iH<fvLastHits[iSmType][iSm][iRpc][iCh].size()-1; iH++){//fill for all memorized hits
3759 itL--;
3760 Double_t dTsinceLast = pHit->GetTime() - (*itL)->GetTime();
3761 if (dTsinceLast > fdMemoryTime)
3762 LOG(error) << Form("Invalid Time since last hit on channel "
3763 "TSRC %d%d%d%d: %f > %f",
3764 iSmType, iSm, iRpc, iCh, dTsinceLast, fdMemoryTime);
3765
3766 fhTRpcCluTOffDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(dTsinceLast),
3767 pHit->GetTime() - dTTrig[iSel]);
3768 fhTRpcCluMemMulDTLastHits[iDetIndx][iSel]->Fill(TMath::Log10(dTsinceLast),
3769 fvLastHits[iSmType][iSm][iRpc][iCh].size() - 1);
3770 }
3771 }
3772 }
3773 }
3774 }
3775 }
3776 }
3777 return kTRUE;
3778}
3779
3780static Int_t iNPulserFound = 0;
3782{
3783 iNPulserFound++;
3784 const Int_t iDet0 = fiPulDetRef; // Define reference detector
3785 const Double_t Tlim = 0.5;
3786 Int_t iDigi0 = -1;
3787 switch (fiPulserMode) {
3788 case 1: // mcbm :
3789 if ((UInt_t) fiNDigiIn != fiPulMulMin * 2 + 2) { // 2 * working RPCs + 1 Diamond
3790 LOG(debug) << "Incomplete or distorted pulser event " << iNPulserFound << " with " << fiNDigiIn
3791 << " digis instead of " << fiPulMulMin * 2 + 2;
3792 if ((UInt_t) fiNDigiIn < fiPulMulMin * 2) return kTRUE;
3793 }
3794 break;
3795 case 2: // micro CBM cosmic
3796 if ((UInt_t) fiNDigiIn < fiPulMulMin * 2) return kTRUE;
3797 break;
3798 ;
3799 default:;
3800 }
3801
3802 for (Int_t iDigi = 0; iDigi < (Int_t) fiNDigiIn; iDigi++) {
3803 Int_t iCh = fvDigiIn[iDigi].GetChannel();
3804 if (iCh != 0 && iCh != 31) continue;
3805
3806 Int_t iAddr = fvDigiIn[iDigi].GetAddress() & DetMask;
3807 Int_t iDet = fDetIdIndexMap[iAddr];
3808 if (iDet == iDet0) {
3809 Int_t iSide = fvDigiIn[iDigi].GetSide();
3810 if (iSide == 1) { // for pulser mode 1
3811 iDigi0 = iDigi;
3812 break;
3813 }
3814 }
3815 }
3816
3817 if (iDigi0 == -1) {
3818 LOG(debug) << Form("Pulser reference %d not found in pulser event %d of mul %d, return", iDet0, iNPulserFound,
3819 fiNDigiIn);
3820 return kTRUE;
3821 }
3822
3823 if (fvPulserTimes[iDet0][0].size() > 0)
3824 LOG(debug) << fiNDigiIn << " pulser digis with ref in "
3825 << Form("0x%08x at %d with deltaT %12.3f", fvDigiIn[iDigi0].GetAddress(), iDigi0,
3826 fvDigiIn[iDigi0].GetTime() - fvPulserTimes[iDet0][0].back());
3827
3828 for (Int_t iDigi = 0; iDigi < fiNDigiIn; iDigi++) {
3829 Int_t iCh = fvDigiIn[iDigi].GetChannel();
3830
3831 Int_t iDetIndx = fDigiBdfPar->GetDetInd(fvDigiIn[iDigi].GetAddress() & DetMask);
3832 fhRpcDigiTot[iDetIndx]->Fill(2 * iCh + fvDigiIn[iDigi].GetSide(), fvDigiIn[iDigi].GetTot());
3833
3834 Int_t iAddr = fvDigiIn[iDigi].GetAddress() & DetMask;
3835 Int_t iDet = fDetIdIndexMap[iAddr];
3836 Int_t iSide = fvDigiIn[iDigi].GetSide();
3837
3838 switch (fiPulserMode) {
3839 case 0:
3840 case 1: // mCBM
3841 if (fvDigiIn[iDigi].GetType() != 5) {
3842 if (iCh != 0 && iCh != 31) continue;
3843 if (fvDigiIn[iDigi].GetTot() > fiPulTotMax || fvDigiIn[iDigi].GetTot() < fiPulTotMin) continue;
3844 }
3845 else {
3846 LOG(debug) << "Found PulHit of Type 5 in Ch " << iCh;
3847 // if (iCh == 5) iSide=1; // Special case for diamond, pulser for channels 5-8 in channel 5, stored as side 1
3848 // if (iCh !=0 && iCh != 5) continue;
3849 if (iCh > 39) iSide = 1; // Special case for diamond in Mar2019
3850 if (iCh != 0 && iCh != 40) continue;
3851 }
3852 break;
3853
3854 case 2:
3855 if (fvDigiIn[iDigi].GetType() == 8) // ceramic RPC
3856 if (fvDigiIn[iDigi].GetRpc() != 7) continue;
3857 if (iCh != 0 && iCh != 31) continue;
3858 break;
3859 }
3860
3861 if (fvPulserTimes[iDet][iSide].size() == (UInt_t) NPulserTimes) fvPulserTimes[iDet][iSide].pop_front();
3862 if (iDet == iDet0 && 1 == iSide) {
3863 // check consistency of latest hit
3864 if (fvPulserTimes[iDet][iSide].size() > 1) {
3865 Double_t TDif = (fvPulserTimes[iDet][iSide].back() - fvPulserTimes[iDet][iSide].front())
3866 / (fvPulserTimes[iDet][iSide].size() - 1);
3867 if (TMath::Abs(fvDigiIn[iDigi].GetTime() - fvPulserTimes[iDet][iSide].back() - TDif)
3868 > 1.E3) { // probably due to parallel processing
3869
3870 // action, reset
3871 fvPulserTimes[iDet][iSide].clear();
3872 }
3873 else {
3874 if (TMath::Abs(fvDigiIn[iDigi].GetTime() - fvPulserTimes[iDet][iSide].back() - TDif) > 10.) {
3875 LOG(info) << Form("Unexpected Pulser Time for event %d, pulser %d: "
3876 "%15.1f instead %15.1f, TDif: %10.1f != %10.1f",
3877 (int) fdEvent, iNPulserFound, fvDigiIn[iDigi].GetTime(),
3878 fvPulserTimes[iDet][iSide].back() + TDif,
3879 fvDigiIn[iDigi].GetTime() - fvPulserTimes[iDet][iSide].back(), TDif);
3880 // append dummy entry
3881 fvPulserTimes[iDet][iSide].push_back((Double_t)(fvPulserTimes[iDet][iSide].back() + TDif));
3882 continue;
3883 }
3884 }
3885 }
3886 // append new entry
3887 fvPulserTimes[iDet][iSide].push_back((Double_t)(fvDigiIn[iDigi].GetTime()));
3888 }
3889 else {
3890 Double_t dDeltaT0 = (Double_t)(fvDigiIn[iDigi].GetTime() - fvDigiIn[iDigi0].GetTime());
3891
3892 // check consistency of latest hit
3893 if (fvPulserOffset[iDet][iSide] != 0.)
3894 if (TMath::Abs(dDeltaT0 - fvPulserOffset[iDet][iSide]) > Tlim) {
3895 LOG(info) << "Unexpected pulser offset at ev " << fdEvent << ", pulcnt " << iNPulserFound << " for Det "
3896 << iDet << Form(", addr 0x%08x", iAddr) << ", side " << iSide << ": "
3897 << dDeltaT0 - fvPulserOffset[iDet][iSide] << " ( " << fvPulserTimes[iDet][iSide].size() << " ) ";
3898 fvPulserTimes[iDet][iSide].clear();
3899 // skip this event
3900 // continue;
3901 }
3902
3903 // fill monitoring histo
3904 if (fvPulserOffset[iDet][iSide] != 0.) {
3905 fhPulserTimesRaw->Fill(iDet * 2 + iSide, dDeltaT0 - fvPulserOffset[iDet][iSide]);
3906 fhPulserTimeRawEvo[iDet * 2 + iSide]->Fill(iNPulserFound, dDeltaT0 - fvPulserOffset[iDet][iSide]);
3907 }
3908 // append new entry
3909 fvPulserTimes[iDet][iSide].push_back(dDeltaT0);
3910 }
3911 }
3912
3913 for (Int_t iDet = 0; iDet < (Int_t) fvPulserTimes.size(); iDet++) {
3914 for (Int_t iSide = 0; iSide < 2; iSide++) {
3915 if (iDet == iDet0 && iSide == 1) continue; // skip reference counter
3916 if (fvPulserTimes[iDet][iSide].size() > 0) {
3917 Double_t Tmean = 0.;
3918 std::list<Double_t>::iterator it;
3919 for (it = fvPulserTimes[iDet][iSide].begin(); it != fvPulserTimes[iDet][iSide].end(); ++it)
3920 Tmean += *it;
3921 Tmean /= fvPulserTimes[iDet][iSide].size();
3922
3923 if (TMath::Abs(Tmean - fvPulserOffset[iDet][iSide]) > Tlim)
3924 LOG(debug) << "New pulser offset at ev " << fdEvent << ", pulcnt " << iNPulserFound << " for Det " << iDet
3925 << ", side " << iSide << ": " << Tmean << " ( " << fvPulserTimes[iDet][iSide].size() << " ) ";
3926
3927 fvPulserOffset[iDet][iSide] = Tmean;
3928 }
3929 }
3930 }
3931
3932 for (Int_t iDigi = 0; iDigi < fiNDigiIn; iDigi++) {
3933
3934 Int_t iCh = fvDigiIn[iDigi].GetChannel();
3935 Int_t iAddr = fvDigiIn[iDigi].GetAddress() & DetMask;
3936 Int_t iDet = fDetIdIndexMap[iAddr];
3937 Int_t iSide = fvDigiIn[iDigi].GetSide();
3938
3939 switch (fiPulserMode) {
3940 case 1:
3941 if (fvDigiIn[iDigi].GetType() != 5) {
3942 if (iCh != 0 && iCh != 31) continue;
3943 }
3944 else {
3945 //if (iCh == 5) iSide=1; // Special case for diamond, pulser for channels 5-8 in channel 5, stored as side 1
3946 if (iCh > 39) iSide = 1; // Special case for diamond in Mar2019
3947 // if(iCh !=0 && iCh != 5) continue;
3948 if (iCh != 0 && iCh != 40) continue;
3949 }
3950 break;
3951 case 2:
3952 if (fvDigiIn[iDigi].GetType() == 8) // ceramic RPC
3953 if (fvDigiIn[iDigi].GetRpc() != 7) continue;
3954 if (iCh != 0 && iCh != 31) continue;
3955 break;
3956 }
3957
3958 Double_t dDeltaT0 =
3959 (Double_t)(fvDigiIn[iDigi].GetTime() - fvDigiIn[iDigi0].GetTime()) - fvPulserOffset[iDet][iSide];
3960
3961 // fill monitoring histo
3962 fhPulserTimesCor->Fill(iDet * 2 + iSide, dDeltaT0);
3963 }
3964 return kTRUE;
3965}
3966
3968{
3969 for (Int_t iDigi = 0; iDigi < fiNDigiIn; iDigi++) {
3970 Int_t iAddr = fvDigiIn[iDigi].GetAddress() & DetMask;
3971 Int_t iDet = fDetIdIndexMap[iAddr];
3972 Int_t iSide = fvDigiIn[iDigi].GetSide();
3973 switch (fiPulserMode) {
3974 case 1: // diamond has pulser in ch 0 and 5
3975 if (5 == fvDigiIn[iDigi].GetType()) {
3976 continue; // no pulser correction for diamond, mapping to be resolved
3977 Int_t iCh = fvDigiIn[iDigi].GetChannel();
3978 if (iCh > 4) iSide = 1;
3979 }
3980 break;
3981 case 2: // correct all cer pads by same rpc/side 0
3982 if (8 == fvDigiIn[iDigi].GetType() || 5 == fvDigiIn[iDigi].GetType()) {
3983 const Int_t iRefAddr = 0x00078006;
3984 iDet = fDetIdIndexMap[iRefAddr];
3985 }
3986 break;
3987 }
3988 fvDigiIn[iDigi].SetTime(fvDigiIn[iDigi].GetTime() - fvPulserOffset[iDet][iSide]);
3989 }
3990 return kTRUE;
3991}
@ kTof
Time-of-flight Detector.
static Double_t StartAnalysisTime
static TH2F * fhBucDigiCor
static Double_t f1_xboxe(double *x, double *par)
CbmTofDigi * pRef
CbmTofDigi * pRefCal
CbmDigiManager * fDigiMan
static Int_t iRunId
static Int_t iIndexDut
static Double_t dTstart
static FairRootManager * rootMgr
static Int_t iNPulserFound
static Double_t dTmax
static Int_t iMess
static Int_t SelMask
TClonesArray * fTofHitsColl
static Double_t StartAnalysisTime
const Int_t DetMask
static Double_t fdMemoryTime
std::vector< TH1 * > hSvel
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
@ k21a
@ k14a
std::vector< Int_t > vDigiIndRef
static constexpr size_t size()
Definition KfSimdPseudo.h:2
Generates beam ions for transport simulation.
std::vector< std::vector< std::vector< std::vector< CbmTofDigi * > > > > fStorDigi
std::vector< TH1 * > fhRpcDTLastHits_CluSize
std::vector< std::string > fAllowedChannels
std::vector< std::vector< std::vector< Double_t > > > fvdDifCh
std::vector< std::vector< std::vector< Double_t > > > fvdX
std::vector< TH2 * > fhRpcCluAvWalk
std::vector< TH2 * > fhRpcCluTrms
std::vector< TH2 * > fhRpcCluPosition
std::vector< std::vector< TH2 * > > fhTRpcCluPosition
std::vector< CbmTofDigi > fvDigiIn
std::vector< TH2 * > fhRpcCluDelMatPos
std::vector< Int_t > vDigiIndRef
std::vector< TH2 * > fhRpcCluDelTOff
std::vector< std::vector< TH2 * > > fhTRpcCluTotDTLastHits
std::vector< TH2 * > fhRpcDigiTot
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< TH2 * > fhSmCluTOff
std::map< UInt_t, UInt_t > fDetIdIndexMap
std::vector< TH2 * > fhRpcDigiCor
std::vector< std::vector< std::vector< Int_t > > > fviClusterMul
std::vector< TH2 * > fhRpcCluAvLnWalk
std::vector< TH2 * > fhRpcCluTot
std::vector< TH2 * > fhSmCluPosition
std::vector< TProfile * > fhPulserTimeRawEvo
std::vector< TH2 * > fhRpcCluSize
bool HandleMessage(FairMQMessagePtr &, int)
std::vector< std::vector< TProfile * > > fhSmCluFpar
bool HandleData(FairMQParts &, int)
std::vector< std::vector< std::vector< Double_t > > > fvdDifX
std::vector< std::vector< TH2 * > > fhTRpcCluSizeDTLastHits
Bool_t IsChannelNameAllowed(std::string channelName)
std::vector< std::vector< std::vector< std::vector< Int_t > > > > fStorDigiInd
std::vector< std::vector< TH2 * > > fhTRpcCluAvWalk
std::vector< TH1 * > fhRpcDTLastHits_Tot
std::vector< std::vector< std::vector< Int_t > > > fviClusterSize
std::vector< std::vector< TH1 * > > fhTRpcCluMul
std::vector< CbmTofDigi > * fTofCalDigiVec
std::vector< std::vector< TH2 * > > fhTRpcCluTOff
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTOff
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTotGain
std::vector< std::vector< TH2 * > > fhTSmCluPosition
std::vector< std::vector< TH2 * > > fhTRpcCluTot
std::vector< std::vector< std::vector< Double_t > > > fvdY
std::vector< std::vector< std::vector< Double_t > > > fvdDifY
std::vector< uint64_t > fEventHeader
std::vector< std::vector< TH2 * > > fhTRpcCludXdY
std::vector< std::vector< TH2 * > > fhTRpcCluMemMulDTLastHits
std::vector< std::vector< TH2 * > > fhTSmCluTRun
virtual void LH_store(Int_t iSmType, Int_t iSm, Int_t iRpc, Int_t iChm, CbmTofHit *pHit)
virtual void fit_ybox(const char *hname)
std::vector< std::vector< TH2 * > > fhTRpcCluDelTof
std::vector< TProfile * > fhSmCluSvel
std::vector< TH1 * > fhRpcCluRate
std::vector< std::vector< std::vector< std::vector< TH2 * > > > > fhTRpcCluWalk
std::vector< std::vector< std::list< Double_t > > > fvPulserTimes
std::vector< std::vector< std::vector< TH2 * > > > fhRpcCluWalk
std::vector< std::vector< TH2 * > > fhTRpcCluSize
std::vector< std::vector< TH2 * > > fhTSmCluTOff
std::vector< TH2 * > fhRpcCluDelMatTOff
std::vector< std::vector< std::vector< std::vector< std::list< CbmTofHit * > > > > > fvLastHits
std::vector< std::vector< std::vector< std::vector< std::vector< Double_t > > > > > fvCPWalk
std::vector< std::vector< TH2 * > > fhTRpcCluTOffDTLastHits
std::vector< std::vector< std::vector< Int_t > > > fviTrkMul
std::vector< std::vector< Double_t > > fvPulserOffset
std::vector< TH2 * > fhRpcCluTOff
std::vector< TH2 * > fhRpcCluDelPos
std::vector< TH1 * > fhRpcDTLastHits
std::vector< TH1 * > fhRpcCluMul
std::vector< Int_t > fviDetId
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPDelTof
std::vector< Int_t > fvDeadStrips
std::vector< std::vector< std::vector< std::vector< Double_t > > > > fvCPTotOff
CbmDigiManager.
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
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
double GetY() const
Definition CbmPixelHit.h:74
double GetX() const
Definition CbmPixelHit.h:73
static uint32_t GetUniqueAddress(uint32_t Sm, uint32_t Rpc, uint32_t Channel, uint32_t Side=0, uint32_t SmType=0, uint32_t RpcType=0)
static int32_t GetSmId(uint32_t address)
static int32_t GetRpcId(uint32_t address)
static int32_t GetSmType(uint32_t address)
static int32_t GetChannelId(uint32_t address)
Double_t GetSizey() const
Definition CbmTofCell.h:40
Double_t GetY() const
Definition CbmTofCell.h:36
Double_t GetSizex() const
Definition CbmTofCell.h:39
Double_t GetX() const
Definition CbmTofCell.h:35
Double_t GetZ() const
Definition CbmTofCell.h:37
virtual 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)
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)
TString GetCalibFileName() const
Double_t GetSignalSpeed() const
Double_t GetSigVel(Int_t iSmType, Int_t iSm, Int_t iRpc) const
CbmTofCell * GetCell(Int_t i)
Int_t GetNrOfModules()
Int_t GetCellId(Int_t i)
Data class for expanded digital TOF information.
Definition CbmTofDigi.h:47
double GetSide() const
Channel Side.
Definition CbmTofDigi.h:160
std::string ToString() const
void SetTot(double tot)
Definition CbmTofDigi.h:166
double GetChannel() const
Channel .
Definition CbmTofDigi.h:156
int32_t GetAddress() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:112
double GetSm() const
Sm.
Definition CbmTofDigi.h:144
double GetTime() const
Inherited from CbmDigi.
Definition CbmTofDigi.h:131
double GetType() const
Sm Type .
Definition CbmTofDigi.h:148
double GetRpc() const
Detector aka Module aka RPC .
Definition CbmTofDigi.h:152
double GetTot() const
Alias for GetCharge.
Definition CbmTofDigi.h:140
void SetAddress(int32_t address)
Definition CbmTofDigi.h:163
void SetTime(double time)
Definition CbmTofDigi.h:165
Int_t GetCell(Int_t uniqueId)
Int_t Init(Bool_t isSimulation=kFALSE)
Int_t GetSModule(Int_t uniqueId)
Int_t GetCounter(Int_t uniqueId)
Int_t GetSMType(Int_t uniqueId)
int32_t GetFlag() const
Definition CbmTofHit.h:75
Double_t f1_xboxe(double *x, double *par)
Definition fit_ybox.h:6
Hash for CbmL1LinkKey.