CbmRoot
Loading...
Searching...
No Matches
CbmMvdSensorDigiToHitTask.cxx
Go to the documentation of this file.
1/* Copyright (C) 2019-2020 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andreas Redelbach [committer] */
4
6
7#include "TArrayD.h"
8#include "TClonesArray.h"
9#include "TGeoManager.h"
10#include "TGeoTube.h"
11#include "TObjArray.h"
12#include "TRefArray.h"
13
14#include <Logger.h>
15
16#include <TMatrixD.h>
17
18#include <cstring>
19
20using std::map;
21using std::pair;
22using std::vector;
23
24//Initialize Variables
25Int_t dth_fAdcSteps(-1);
26Int_t dth_fAddress(0);
27Float_t dth_fAdcStepSize(-1.);
28std::vector<TH1F*> dth_fPixelChargeHistos;
30
31
32const constexpr Int_t fCounter(0);
33// const constexpr Float_t fSigmaNoise(15.); //unused
34const float dth_fSeedThreshold = 1.;
35const float dth_fNeighThreshold = 1.;
36
37// const constexpr Bool_t inputSet(kFALSE); //unused
38std::map<std::pair<Int_t, Int_t>, Int_t> dth_ftempPixelMap;
39
40// const constexpr Bool_t fAddNoise(kFALSE); //unused
41
42
43//2 bigger becuase we are also checking -1 and (range + 1) usually 576, 1152
44const constexpr int pixelRows = 578;
45const constexpr int pixelCols = 1154;
46
48std::vector<std::pair<short, short>> dth_clusterArray;
49std::vector<std::pair<short, short>> dth_coordArray;
50std::vector<int> dth_refIDArray;
51
52//Hitfinder Variables:
53// const constexpr Int_t fGausArrayLimit = 5000; //unused
54
55
56TVector3 pos;
57TVector3 dpos;
58Double_t lab[3];
59Double_t numeratorX;
60Double_t numeratorY;
61Double_t denominator;
62Int_t xIndex;
63Int_t yIndex;
64Double_t x, y;
65Int_t xIndex0;
66Int_t yIndex0;
67int ID = 0;
68int counter = 0;
69UInt_t shape = 0;
70
71
72// ----- Default constructor -------------------------------------------
74// -------------------------------------------------------------------------
75
76// -------------------------------------------------------------------------
84// -------------------------------------------------------------------------
85
86// -------------------------------------------------------------------------
89 , fAdcDynamic(200)
90 , fAdcOffset(0)
91 , fAdcBits(1)
92 , fDigiMap()
93 , fDigiMapIt()
94 , fVerbose(iVerbose)
95 ,
96
97 //HitFinder Variables
98 fSigmaNoise(15.)
99 , fHitPosX(0.)
100 , fHitPosY(0.)
101 , fHitPosZ(0.)
102 , fHitPosErrX(0.0005)
103 , fHitPosErrY(0.0005)
104 , fHitPosErrZ(0.0)
105
106{
107 fPluginIDNumber = 500;
108}
109// -------------------------------------------------------------------------
110
111// ----- Virtual private method Init ----------------------------------
113{
114
115
116 fInputBuffer = new TClonesArray("CbmMvdDigi", 100);
117 fOutputBuffer = new TClonesArray("CbmMvdHit", 100);
118
119 dth_fAdcSteps = (Int_t) TMath::Power(2, fAdcBits);
121 fSensor = mysensor;
123
124 std::memset(dth_grid, 0, sizeof(dth_grid));
125
126 initialized = kTRUE;
127}
128// -------------------------------------------------------------------------
129
130// ----- Virtual public method Reinit ----------------------------------
132{
133 LOG(info) << "CbmMvdSensorDigiToHitTask::ReInt---------------";
134 return kTRUE;
135}
136// -------------------------------------------------------------------------
137
138// ----- Virtual public method ExecChain --------------
140// -------------------------------------------------------------------------
141
142// ----- Public method Exec --------------
144{
145 int nDigis = fInputBuffer->GetEntriesFast();
146 if (nDigis > 0) {
147
148 fOutputBuffer->Delete();
149 inputSet = kFALSE;
150 short iDigi = 0;
151
152 CbmMvdDigi* digi = (CbmMvdDigi*) fInputBuffer->At(iDigi);
153
154 if (!digi) {
155 LOG(error) << "CbmMvdSensorFindHitTask - Fatal: No Digits found in this event.";
156 }
157
158
159 dth_clusterArray.reserve(nDigis);
160 dth_coordArray.reserve(nDigis);
161 dth_refIDArray.reserve(nDigis);
162
163 for (Int_t k = 0; k < nDigis; k++) {
164 digi = (CbmMvdDigi*) fInputBuffer->At(k);
165
166 if (digi->GetRefId() < 0) {
167 LOG(fatal) << "RefID of this digi is -1 this should not happend ";
168 }
169
170 //apply fNeighThreshold
171 Float_t curr_digi_charge = digi->GetCharge();
172
173 short dth_current_digi_X = digi->GetPixelX();
174 short dth_current_digi_Y = digi->GetPixelY();
175 dth_coordArray.emplace_back(std::make_pair(dth_current_digi_X, dth_current_digi_Y));
176
177 if (GetAdcCharge(curr_digi_charge) >= dth_fNeighThreshold) {
178 //puts index into dth_grid.
179 dth_grid[dth_current_digi_X + 1][dth_current_digi_Y + 1] = curr_digi_charge;
180 }
181 }
182
183
184 /*___________________________________________________________________________________________________
185 ___________________________________________________________________________________________________*/
186 for (auto& curr_coord : dth_coordArray) {
187
188 auto& dth_current_digi_X = curr_coord.first;
189 auto& dth_current_digi_Y = curr_coord.second;
190
191
192 auto& root_digi_pos_charge = dth_grid[dth_current_digi_X + 1][dth_current_digi_Y + 1];
193
194 if (GetAdcCharge(root_digi_pos_charge) >= dth_fSeedThreshold) {
195
196 pos = {0, 0, 0};
197 dpos = {0, 0, 0};
198 numeratorX = 0;
199 numeratorY = 0;
200 denominator = 0;
201 counter = 0;
202 shape = 0;
203
204 //"-1" has nothing todo with the incremented Grid-Size
205 xIndex0 = dth_current_digi_X - 1;
206 yIndex0 = dth_current_digi_Y - 1;
207
208 //setting Values for HitfinderCalculation to default.
209 /*___________________________________________________________________________________________________
210 ___________________________________________________________________________________________________*/
211
212 dth_clusterArray.clear();
213 dth_clusterArray.emplace_back(curr_coord);
214
215 //Calculating Median für the first Element
216 lab[0] = 0;
217 lab[1] = 0;
218 lab[2] = 0;
219
220 shape += TMath::Power(2, (4 * (dth_current_digi_Y - 1 - yIndex0 + 3)) + (dth_current_digi_X - 1 - xIndex0));
221 //shape &= 1 << ((4*(dth_current_digi_Y - 1 - yIndex0+3))+(dth_current_digi_X - 1 - xIndex0)) ;
222 fSensor->PixelToTop((dth_current_digi_X - 1), (dth_current_digi_Y - 1), lab);
223
224 numeratorX += lab[0] * root_digi_pos_charge;
225 numeratorY += lab[1] * root_digi_pos_charge;
226 denominator += root_digi_pos_charge;
227
228
229 root_digi_pos_charge = 0;
230 /*___________________________________________________________________________________________________
231 ___________________________________________________________________________________________________*/
232 for (unsigned short i = 0; i < dth_clusterArray.size(); i++) {
233
234 auto& index = dth_clusterArray[i];
235
236
237 auto checkNeighbour = [&](short channelX, short channelY) {
238 auto& curr_digi_pos_charge = dth_grid[channelX + 1][channelY + 1];
239
240 if (curr_digi_pos_charge != 0) {
241
242 //Calculatin Median
243 lab[0] = 0;
244 lab[1] = 0;
245 lab[2] = 0;
246
247 if (counter <= 3) {
248 shape += TMath::Power(2, (4 * (channelY - 1 - yIndex0 + 3)) + (channelX - 1 - xIndex0));
249 //shape &= 1 << ((4*(channelY - 1 - yIndex0+3))+(channelX - 1 - xIndex0)) ;
250 }
251
252 fSensor->PixelToTop((channelX - 1), (channelY - 1), lab);
253
254 numeratorX += lab[0] * curr_digi_pos_charge;
255 numeratorY += lab[1] * curr_digi_pos_charge;
256 denominator += curr_digi_pos_charge;
257 counter++;
258
259 //Saving current Digi in ClusterArray
260 dth_clusterArray.emplace_back(std::make_pair(channelX, channelY));
261
262 //Marking Digi in Grid as used/not relevant anymore
263 curr_digi_pos_charge = 0;
264 }
265 };
266
267 short channelX = index.first;
268 short channelY = index.second;
269
270 checkNeighbour(channelX + 1, channelY);
271 checkNeighbour(channelX - 1, channelY);
272 checkNeighbour(channelX, channelY + 1);
273 checkNeighbour(channelX, channelY - 1);
274 }
275
276
277 //Compute Center of Gravity
278 //__________________________________________________________________________________________
279
280 Double_t layerPosZ = fSensor->GetZ();
281 Double_t sigmaIn[3], sigmaOut[3], shiftIn[3], shiftOut[3];
282
283 //Calculate x,y coordinates of the pixel in the laboratory ref frame
284 if (denominator != 0) {
287 fHitPosZ = layerPosZ;
288 }
289 else {
290 fHitPosX = 0;
291 fHitPosY = 0;
292 fHitPosZ = 0;
293 }
294
295
296 if (dth_clusterArray.size() > 4) {
297 shape = 0;
298 }
299
300
301 //_________________________________________________________________________________________
302 switch (shape) {
303 case 12288: {
304 sigmaIn[0] = 0.00053;
305 sigmaIn[1] = 0.00063;
306 sigmaIn[2] = 0.;
307 shiftIn[0] = -0.00000;
308 shiftIn[1] = -0.00001;
309 shiftIn[2] = 0.;
310 break;
311 }
312 case 208896: {
313 sigmaIn[0] = 0.00035;
314 sigmaIn[1] = 0.00036;
315 sigmaIn[2] = 0.;
316 shiftIn[0] = -0.00000;
317 shiftIn[1] = -0.00002;
318 shiftIn[2] = 0.;
319 break;
320 }
321 case 69632: {
322 sigmaIn[0] = 0.00028;
323 sigmaIn[1] = 0.00028;
324 sigmaIn[2] = 0.;
325 shiftIn[0] = -0.00000;
326 shiftIn[1] = -0.00002;
327 shiftIn[2] = 0.;
328 break;
329 }
330 case 28672: {
331 sigmaIn[0] = 0.00028;
332 sigmaIn[1] = 0.00039;
333 sigmaIn[2] = 0.;
334 shiftIn[0] = -0.00000;
335 shiftIn[1] = -0.00001;
336 shiftIn[2] = 0.;
337 break;
338 }
339 case 143360: {
340 sigmaIn[0] = 0.00024;
341 sigmaIn[1] = 0.00022;
342 sigmaIn[2] = 0.;
343 shiftIn[0] = +0.00020;
344 shiftIn[1] = +0.00008;
345 shiftIn[2] = 0.;
346 break;
347 }
348 case 200704: {
349 sigmaIn[0] = 0.00024;
350 sigmaIn[1] = 0.00022;
351 sigmaIn[2] = 0.;
352 shiftIn[0] = -0.00020;
353 shiftIn[1] = -0.00011;
354 shiftIn[2] = 0.;
355 break;
356 }
357 case 77824: {
358 sigmaIn[0] = 0.00024;
359 sigmaIn[1] = 0.00022;
360 sigmaIn[2] = 0.;
361 shiftIn[0] = -0.00020;
362 shiftIn[1] = +0.00008;
363 shiftIn[2] = 0.;
364 break;
365 }
366 case 12800: {
367 sigmaIn[0] = 0.00024;
368 sigmaIn[1] = 0.00022;
369 sigmaIn[2] = 0.;
370 shiftIn[0] = +0.00020;
371 shiftIn[1] = -0.00011;
372 shiftIn[2] = 0.;
373 break;
374 }
375 case 4096: {
376 sigmaIn[0] = 0.00027;
377 sigmaIn[1] = 0.00092;
378 sigmaIn[2] = 0.;
379 shiftIn[0] = +0.00002;
380 shiftIn[1] = +0.00004;
381 shiftIn[2] = 0.;
382 break;
383 }
384 default: {
385 sigmaIn[0] = 0.00036;
386 sigmaIn[1] = 0.00044;
387 sigmaIn[2] = 0.;
388 shiftIn[0] = -0.00000;
389 shiftIn[1] = -0.00002;
390 shiftIn[2] = 0.;
391 }
392 }
393 //_________________________________________________________________________________________
394
395 // Consider Sensor Orientation
396
397 TGeoHMatrix* RecoMatrix = fSensor->GetRecoMatrix();
398 TGeoHMatrix RotMatrix;
399 RotMatrix.SetRotation(RecoMatrix->GetRotationMatrix());
400
401 RotMatrix.LocalToMaster(sigmaIn, sigmaOut);
402 RotMatrix.LocalToMaster(shiftIn, shiftOut);
403
404 fHitPosX += shiftOut[0];
405 fHitPosY += shiftOut[1];
406 fHitPosZ += shiftOut[2];
407
408 // pos = center of gravity (labframe), dpos uncertainty LOG(info)<<setw(10)<<setprecision(2)<< VolumeShape->GetDX();
409 pos.SetXYZ(fHitPosX, fHitPosY, fHitPosZ);
410 dpos.SetXYZ(TMath::Abs(sigmaOut[0]), TMath::Abs(sigmaOut[1]), TMath::Abs(sigmaOut[2]));
411
412 //Create Hit
413 //__________________________________________________________________________________________
414
415 Int_t indexX, indexY;
416
417 Double_t local[2];
418 local[0] = pos.X();
419 local[1] = pos.Y();
420
421 fSensor->TopToPixel(local, indexX, indexY);
422 Int_t nHits = fOutputBuffer->GetEntriesFast();
423
424 new ((*fOutputBuffer)[nHits]) CbmMvdHit(fSensor->GetStationNr(), pos, dpos, indexX, indexY, ID, 0);
425 CbmMvdHit* currentHit = (CbmMvdHit*) fOutputBuffer->At(nHits);
426 currentHit->SetTime(fSensor->GetCurrentEventTime());
427 currentHit->SetTimeError(fSensor->GetIntegrationtime() / 2);
428 currentHit->SetRefId(ID);
429 ID++;
430 }
431 }
432
433 // Int_t nHits = fOutputBuffer->GetEntriesFast();
434
435 dth_clusterArray.clear();
436 fInputBuffer->Delete();
437 dth_coordArray.clear();
438 }
439}
440
441
442//--------------------------------------------------------------------------
443
444
445// -------------------------------------------------------------------------
447{
448 int adcCharge;
449
450 if (curr_charge < fAdcOffset) {
451 return 0;
452 };
453
454 adcCharge = int((curr_charge - fAdcOffset) / dth_fAdcStepSize);
455
456 if (adcCharge > dth_fAdcSteps - 1) {
457 return dth_fAdcSteps - 1;
458 }
459 else {
460 return adcCharge;
461 }
462}
463
464
465//--------------------------------------------------------------------------
467{
468 if (fShowDebugHistos) {
469 LOG(info) << "============================================================";
470 LOG(info) << GetName() << "::Finish: Total events skipped: " << fCounter;
471 LOG(info) << "============================================================";
472 LOG(info) << "Parameters used";
473 LOG(info) << "Gaussian noise [electrons] : " << fSigmaNoise;
474 LOG(info) << "Noise simulated [Bool] : " << fAddNoise;
475 LOG(info) << "Threshold seed [ADC] : " << dth_fSeedThreshold;
476 LOG(info) << "Threshold neighbours [ADC] : " << dth_fNeighThreshold;
477 LOG(info) << "ADC - Bits : " << fAdcBits;
478 LOG(info) << "ADC - Dynamic [electrons] : " << fAdcDynamic;
479 LOG(info) << "ADC - Offset [electrons] : " << fAdcOffset;
480 LOG(info) << "============================================================";
481
482
483 TH1F* histo;
484 TH2F* clusterShapeHistogram;
485 TCanvas* canvas2 = new TCanvas("HitFinderCharge", "HitFinderCharge");
486 canvas2->Divide(2, 2);
487 canvas2->cd(1);
488 if (fChargeArraySize <= 7) {
489 clusterShapeHistogram = new TH2F("MvdClusterShape", "MvdClusterShape", fChargeArraySize, 0, fChargeArraySize,
491 for (Int_t i = 0; i < fChargeArraySize * fChargeArraySize; i++) {
492 histo = dth_fPixelChargeHistos[i];
493 Float_t curr_charge = histo->GetMean();
494 //LOG(debug) <<i << " Charge " << charge << " xCluster: " << i%fChargeArraySize << " yCluster: " << i/fChargeArraySize;
495 //histo->Fit("landau");
496 //TF1* fitFunction= histo->GetFunction("landau");
497 //Double_t MPV=fitFunction->GetParameter(1);
498 clusterShapeHistogram->Fill(i % fChargeArraySize, i / fChargeArraySize, curr_charge);
499 }
500 }
501 clusterShapeHistogram->Draw("Lego2");
502 canvas2->cd(2);
503 histo = dth_fPixelChargeHistos[50];
504 histo->Draw();
505 canvas2->cd(3);
506 histo = dth_fPixelChargeHistos[51];
507 histo->Draw();
508 canvas2->cd(4);
509 //fFullClusterHisto->Draw();
510 }
511}
512//--------------------------------------------------------------------------
ClassImp(CbmConverterManager)
std::vector< int > dth_refIDArray
std::vector< TH1F * > dth_fPixelChargeHistos
std::vector< std::pair< short, short > > dth_clusterArray
std::map< std::pair< Int_t, Int_t >, Int_t > dth_ftempPixelMap
Double_t denominator
TVector3 dpos
std::vector< TH1F * > dth_fTotalChargeInNpixelsArray
std::vector< std::pair< short, short > > dth_coordArray
const float dth_fNeighThreshold
Int_t dth_fAdcSteps(-1)
Float_t dth_fAdcStepSize(-1.)
Double_t numeratorY
const constexpr int pixelCols
Int_t dth_fAddress(0)
Double_t lab[3]
const float dth_fSeedThreshold
const constexpr int pixelRows
Double_t numeratorX
Float_t dth_grid[pixelCols][pixelRows]
const constexpr Int_t fCounter(0)
void SetTimeError(double error)
Definition CbmHit.h:91
void SetRefId(int32_t refId)
Definition CbmHit.h:82
void SetTime(double time)
Definition CbmHit.h:85
int32_t GetPixelY()
int32_t GetPixelX()
double GetCharge() const
Definition CbmMvdDigi.h:47
int32_t GetRefId() const
Definition CbmMvdDigi.h:61
void InitTask(CbmMvdSensor *mySensor)
virtual const char * GetName() const
CbmMvdSensor * fSensor
TClonesArray * fOutputBuffer
TClonesArray * fInputBuffer
void PixelToTop(Int_t pixelNumberX, Int_t pixelNumberY, Double_t *lab)
Int_t GetSensorNr() const
Double_t GetCurrentEventTime() const
TGeoHMatrix * GetRecoMatrix()
Double_t GetIntegrationtime() const
Double_t GetZ() const
Int_t GetStationNr() const
void TopToPixel(Double_t *lab, Int_t &pixelNumberX, Int_t &pixelNumberY)