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