25#include <FairRootManager.h>
26#include <FairRuntimeDb.h>
32#include <TClonesArray.h>
110 fSigmaXmin.at(iStation) = sigmaXmin[iStation];
111 fSigmaYmin.at(iStation) = sigmaYmin[iStation];
117 fSigmaXmax.at(iStation) = sigmaXmax[iStation];
118 fSigmaYmax.at(iStation) = sigmaYmax[iStation];
133 FairRuntimeDb* db = FairRuntimeDb::instance();
134 if (!db) Fatal(
"SetParContainers",
"No runtime database");
144 FairRootManager* fManager = FairRootManager::Instance();
145 fPoints = (TClonesArray*) fManager->GetObject(
"MuchPoint");
149 if (!
fStations) Fatal(
"Init",
"No input array of MUCH stations.");
150 if (
fNStations !=
fStations->GetEntriesFast()) Fatal(
"Init",
"Incorrect number of stations set.");
156 fHistHitDensity[i] =
new TH1D(Form(
"hStation%i", i + 1), Form(
"Station %i", i + 1), 110, 0, 220);
171 printf(
"Event: %i\n",
fEvents);
173 gStyle->SetOptStat(0);
174 for (
Int_t iPoint = 0; iPoint <
fPoints->GetEntriesFast(); iPoint++) {
176 if (!point)
continue;
185 assert(iStation >= 0 && iStation <
fNStations);
186 if (iLayer)
continue;
188 point->Position(
pos);
198 TH1D* hNorm =
new TH1D(
"hNorm",
"", 110, 0, 220);
199 Double_t binSize = 2.;
200 for (
Int_t l = 0; l < 100; l++) {
201 Double_t R1 = l * binSize;
202 Double_t R2 = (l + 1) * binSize;
203 Double_t s = TMath::Pi() * (R2 * R2 - R1 * R1);
204 hNorm->SetBinContent(l + 1, s *
fEvents);
211 TCanvas* c1 =
new TCanvas(Form(
"cStation%i", i + 1), Form(
"Station %i", i + 1), 10, 10, 500, 500);
213 c1->SetLeftMargin(0.12);
214 c1->SetRightMargin(0.08);
215 TF1* f1 =
new TF1(
"f1",
"exp([0] + [1]*x)");
216 f1->SetParameter(0, 0.5);
217 f1->SetParameter(1, -0.1);
219 Double_t exp0 =
h->GetFunction(
"f1")->GetParameter(0);
220 Double_t exp1 =
h->GetFunction(
"f1")->GetParameter(1);
221 fExp0.push_back(exp0);
222 fExp1.push_back(exp1);
225 c1->Print(Form(
"%s/hd_station%i.eps", gSystem->DirName(
fDigiFileName), i + 1));
226 c1->Print(Form(
"%s/hd_station%i.png", gSystem->DirName(
fDigiFileName), i + 1));
234 for (
Int_t iLayer = 0; iLayer < nLayers; iLayer++) {
236 if (!layer) Fatal(
"Init",
"Incomplete layers array.");
241 printf(
"Station%i segmented\n", i + 1);
245 TFile* oldFile = gFile;
246 TDirectory* oldDir = gDirectory;
267 if (!layerSide) Fatal(
"Init",
"Incomplete layer sides array.");
269 for (
Int_t iModule = 0; iModule < nModules; iModule++) {
282 TVector3 modSize =
module->GetSize();
283 Double_t modLx = modSize.X();
284 Double_t modLy = modSize.Y();
285 Double_t modLz = modSize.Z();
286 TVector3 modPosition =
module->GetPosition();
287 Double_t modX = modPosition.X();
288 Double_t modY = modPosition.Y();
289 Double_t modZ = modPosition.Z();
291 Bool_t result = modLx > modLy;
292 Int_t iRatio = (result) ? (
Int_t)((modLx + 1e-3) / modLy) : (
Int_t)((modLy + 1e-3) / modLx);
293 Int_t detectorId =
module->GetDetectorId();
294 Double_t secLx = (result) ? modLx / iRatio : modLx;
295 Double_t secLy = (result) ? modLy : modLy / iRatio;
296 for (
Int_t i = 0; i < iRatio; i++) {
297 Double_t secX = (result) ? modX - modLx / 2. + (i + 0.5) * secLx : modX;
298 Double_t secY = (result) ? modY : modY - modLy / 2. + (i + 0.5) * secLy;
299 Int_t iSector =
module->GetNSectors();
301 TVector3 sectorPosition(secX, secY, modZ);
302 TVector3 sectorSize(secLx, secLy, modLz);
313 TVector3 secSize = sector->
GetSize();
315 Int_t detectorId =
module->GetDetectorId();
320 Double_t secLx = secSize.X();
321 Double_t secLy = secSize.Y();
322 Double_t secLz = secSize.Z();
323 Double_t secX = secPosition.X();
324 Double_t secY = secPosition.Y();
325 Double_t secZ = secPosition.Z();
335 if (result1 || result2) {
delete sector; }
338 Double_t rMax = station->
GetRmax();
343 module->AddSector(sector);
348 Double_t newSecX, newSecY, newSecLx, newSecLy;
349 Bool_t equal = TMath::Abs(secLx - secLy) < 1e-5;
350 Bool_t res = secLx > secLy;
351 TVector3 position,
size;
352 if (result1 && result2) {
353 if (equal) { res = kTRUE; }
354 for (
Int_t i = 0; i < 2; ++i) {
355 iSector =
module->GetNSectors();
356 newSecLx = res ? secLx / 2. : secLx;
357 newSecLy = res ? secLy : secLy / 2.;
358 newSecX = res ? secX + (i - 0.5) * newSecLx : secX;
359 newSecY = res ? secY : secY + (i - 0.5) * newSecLy;
360 position.SetXYZ(newSecX, newSecY, secZ);
361 size.SetXYZ(newSecLx, newSecLy, secLz);
365 else if (result1 || result2) {
366 for (
Int_t i = 0; i < 2; i++) {
367 iSector =
module->GetNSectors();
368 newSecLx = result1 ? secLx / 2. : secLx;
369 newSecLy = result1 ? secLy : secLy / 2;
370 newSecX = result1 ? secX + (i - 0.5) * newSecLx : secX;
371 newSecY = result1 ? secY : secY + (i - 0.5) * newSecLy;
372 position.SetXYZ(newSecX, newSecY, secZ);
373 size.SetXYZ(newSecLx, newSecLy, secLz);
383 Double_t secLx = sector->
GetSize()[0];
384 Double_t secLy = sector->
GetSize()[1];
388 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
389 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
390 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
391 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
393 Double_t uR = (ulR < urR) ? ulR : urR;
394 Double_t bR = (blR < brR) ? blR : brR;
395 Double_t R = (uR < bR) ? uR : bR;
403 if (sigma > sigmaMin && sigma / 2. < sigmaMin)
return false;
404 if (sigma > sigmaMax)
return true;
406 Double_t hitDensity =
exp(
fExp0.at(iStation) +
fExp1.at(iStation) * R);
408 Double_t sPad = secLx * secLy / 128.;
409 Double_t nPads = (1.354 - 0.304 * TMath::Log2(sPad));
411 Double_t occupancy = hitDensity * sPad * nPads;
412 if (occupancy > occupancyMax)
return true;
420 Double_t secLx = sector->
GetSize()[0];
421 Double_t secLy = sector->
GetSize()[1];
425 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
426 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
427 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
428 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
430 Double_t uR = (ulR < urR) ? ulR : urR;
431 Double_t bR = (blR < brR) ? blR : brR;
432 Double_t R = (uR < bR) ? uR : bR;
440 if (sigma > sigmaMin && sigma / 2. < sigmaMin)
return false;
441 if (sigma > sigmaMax)
return true;
443 Double_t hitDensity =
exp(
fExp0.at(iStation) +
fExp1.at(iStation) * R);
445 Double_t sPad = secLx * secLy / 128.;
446 Double_t nPads = (1.354 - 0.304 * TMath::Log2(sPad));
447 Double_t occupancy = hitDensity * sPad * nPads;
448 if (occupancy > occupancyMax)
return true;
457 if (radius < 0)
return 0;
459 Int_t intersects = 0;
461 Double_t secLx = sector->
GetSize()[0];
462 Double_t secLy = sector->
GetSize()[1];
466 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
467 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
468 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
469 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
471 if (ulR < radius) intersects++;
472 if (urR < radius) intersects++;
473 if (blR < radius) intersects++;
474 if (brR < radius) intersects++;
476 if (intersects == 4)
return 2;
477 if (intersects)
return 1;
485 printf(
"Segmentation written to file %s\n",
fDigiFileName.Data());
486 Int_t nTotSectors = 0;
487 Int_t nTotChannels = 0;
489 Int_t nTotStraws = 0;
490 printf(
"====================================================================="
491 "============================\n");
492 for (
Int_t iStation = 0; iStation <
fStations->GetEntriesFast(); ++iStation) {
498 Double_t padMaxLx = std::numeric_limits<Double_t>::min();
499 Double_t padMinLx = std::numeric_limits<Double_t>::max();
500 Double_t padMaxLy = std::numeric_limits<Double_t>::min();
501 Double_t padMinLy = std::numeric_limits<Double_t>::max();
502 if (!station)
continue;
505 if (!layer)
continue;
506 for (
Int_t iSide = 0; iSide < 2; ++iSide) {
515 if (!module)
continue;
517 nSectors +=
module->GetNSectors();
520 if (!sector)
continue;
521 Double_t padLx = sector->
GetPadDx();
522 Double_t padLy = sector->
GetPadDy();
523 if (padLx > padMaxLx) padMaxLx = padLx;
524 if (padLx < padMinLx) padMinLx = padLx;
525 if (padLy > padMaxLy) padMaxLy = padLy;
526 if (padLy < padMinLy) padMinLy = padLy;
538 printf(
"Station %i:\n", iStation + 1);
539 printf(
" GEM modules: %i\n", nGems);
541 printf(
" Sectors: %i, Pads: %i, Min.Pad size:%3.2fx%3.2f, Max.Pad "
542 "size:%3.2fx%3.2f\n",
543 nSectors, nChannels, padMinLx, padMinLy, padMaxLx, padMaxLy);
544 printf(
" Straw modules: %i\n", nStraws);
545 nTotSectors += nSectors;
546 nTotChannels += nChannels;
548 nTotStraws += nStraws;
550 printf(
"---------------------------------------------------------------------"
551 "----------------------------\n");
552 printf(
" Summary: \n GEM modules: %i\n Sectors: %i, Pads: %i\n "
553 "Straw modules: %i\n",
554 nTotGems, nTotSectors, nTotChannels, nTotStraws);
555 printf(
"====================================================================="
556 "============================\n");
562 Int_t startIndex = digifile.size() - 4;
563 string txtfile = digifile.erase(startIndex, 4);
564 txtfile.append(
"txt");
566 outfile = fopen(txtfile.c_str(),
"w");
571 Double_t secMinLx = std::numeric_limits<Double_t>::max();
572 Double_t secMinLy = std::numeric_limits<Double_t>::max();
576 for (
Int_t iSide = 1; iSide >= 0; iSide--) {
584 if (sector->
GetSize()[0] < secMinLx) secMinLx = sector->
GetSize()[0];
585 if (sector->
GetSize()[1] < secMinLy) secMinLy = sector->
GetSize()[1];
591 for (
Int_t iStation = 0; iStation <
fStations->GetEntriesFast(); ++iStation) {
592 fprintf(outfile,
"=================================================================="
594 fprintf(outfile,
"Station %i\n", iStation + 1);
595 fprintf(outfile,
"Sector size, cm Sector position, cm Number of pads Side "
597 fprintf(outfile,
"------------------------------------------------------------------"
599 TCanvas* c1 =
new TCanvas(Form(
"station%i", iStation + 1), Form(
"station%i", iStation + 1), 800, 800);
601 c1->Range(-250, -250, 250, 250);
604 for (
Int_t iSide = 1; iSide >= 0; iSide--) {
608 mod->SetFillStyle(0);
621 const char* side = iSide ?
"Back" :
"Front";
622 fprintf(outfile,
"%-4.2fx%-10.2f %-6.2fx%-12.2f %-14i %-5s ", sector->
GetSize()[0],
631 TArc* arc =
new TArc(0., 0., station->
GetRmin());
634 c1->Print(Form(
"%s/station%i.eps", gSystem->DirName(
fDigiFileName), iStation + 1));
635 c1->Print(Form(
"%s/station%i.png", gSystem->DirName(
fDigiFileName), iStation + 1));
ClassImp(CbmConverterManager)
friend fvec exp(const fvec &a)
static constexpr size_t size()
static int32_t GetModuleIndex(int32_t address)
static int32_t GetLayerIndex(int32_t address)
static int32_t GetLayerSideIndex(int32_t address)
static int32_t GetStationIndex(int32_t address)
Int_t GetNModules() const
CbmMuchModule * GetModule(Int_t iModule) const
CbmMuchLayerSide * GetSide(Bool_t side)
CbmMuchLayerSide * GetSideF()
CbmMuchLayerSide * GetSideB()
Int_t GetNSectors() const
CbmMuchSector * GetSector(Int_t address)
Double_t GetCutRadius() const
Int_t GetDetectorType() const
Double_t GetSigmaY() const
Double_t GetPadDx() const
Double_t GetPadDy() const
TVector3 GetPosition() const
Double_t GetSigmaX() const
UInt_t GetAddress() const
Int_t GetNChannels() const
virtual ~CbmMuchSegmentAuto()
virtual void Exec(Option_t *option)
std::vector< Double_t > fSigmaXmax
Bool_t ShouldSegmentByY(CbmMuchSectorRectangular *sector)
void SetOccupancyMax(Double_t *occupancyMax)
std::vector< Double_t > fSigmaYmax
virtual void SetParContainers()
void SegmentSector(CbmMuchModuleGem *module, CbmMuchSectorRectangular *sector)
Int_t IntersectsRad(CbmMuchSectorRectangular *sector, Double_t radius)
std::vector< Double_t > fExp0
std::vector< Double_t > fExp1
void SetNStations(Int_t nStations)
std::vector< Double_t > fSigmaYmin
void SegmentModule(CbmMuchModuleGem *module)
Bool_t ShouldSegmentByX(CbmMuchSectorRectangular *sector)
void InitLayerSide(CbmMuchLayerSide *layerSide)
std::vector< Double_t > fOccupancyMax
void Print(Option_t *="") const
void SetSigmaMin(Double_t *sigmaXmin, Double_t *sigmaYmin)
virtual InitStatus Init()
virtual void FinishTask()
void SetSigmaMax(Double_t *sigmaXmax, Double_t *sigmaYmax)
std::vector< Double_t > fSigmaXmin
CbmMuchLayer * GetLayer(Int_t iLayer) const
Data class with information on a STS local track.