25#include <FairRootManager.h>
26#include <FairRuntimeDb.h>
32#include <TClonesArray.h>
81 , fDigiFileName(digiFileName)
110 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
111 fSigmaXmin.at(iStation) = sigmaXmin[iStation];
112 fSigmaYmin.at(iStation) = sigmaYmin[iStation];
117 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
118 fSigmaXmax.at(iStation) = sigmaXmax[iStation];
119 fSigmaYmax.at(iStation) = sigmaYmax[iStation];
125 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
134 FairRuntimeDb* db = FairRuntimeDb::instance();
135 if (!db) Fatal(
"SetParContainers",
"No runtime database");
145 FairRootManager* fManager = FairRootManager::Instance();
146 fPoints = (TClonesArray*) fManager->GetObject(
"MuchPoint");
150 if (!
fStations) Fatal(
"Init",
"No input array of MUCH stations.");
151 if (
fNStations !=
fStations->GetEntriesFast()) Fatal(
"Init",
"Incorrect number of stations set.");
157 fHistHitDensity[i] =
new TH1D(Form(
"hStation%i", i + 1), Form(
"Station %i", i + 1), 110, 0, 220);
172 printf(
"Event: %i\n",
fEvents);
174 gStyle->SetOptStat(0);
175 for (Int_t iPoint = 0; iPoint <
fPoints->GetEntriesFast(); iPoint++) {
177 if (!point)
continue;
186 assert(iStation >= 0 && iStation <
fNStations);
187 if (iLayer)
continue;
189 point->Position(
pos);
199 TH1D* hNorm =
new TH1D(
"hNorm",
"", 110, 0, 220);
200 Double_t binSize = 2.;
201 for (Int_t l = 0; l < 100; l++) {
202 Double_t R1 = l * binSize;
203 Double_t R2 = (l + 1) * binSize;
204 Double_t s = TMath::Pi() * (R2 * R2 - R1 * R1);
205 hNorm->SetBinContent(l + 1, s *
fEvents);
212 TCanvas* c1 =
new TCanvas(Form(
"cStation%i", i + 1), Form(
"Station %i", i + 1), 10, 10, 500, 500);
214 c1->SetLeftMargin(0.12);
215 c1->SetRightMargin(0.08);
216 TF1* f1 =
new TF1(
"f1",
"exp([0] + [1]*x)");
217 f1->SetParameter(0, 0.5);
218 f1->SetParameter(1, -0.1);
220 Double_t exp0 =
h->GetFunction(
"f1")->GetParameter(0);
221 Double_t exp1 =
h->GetFunction(
"f1")->GetParameter(1);
222 fExp0.push_back(exp0);
223 fExp1.push_back(exp1);
226 c1->Print(Form(
"%s/hd_station%i.eps", gSystem->DirName(
fDigiFileName), i + 1));
227 c1->Print(Form(
"%s/hd_station%i.png", gSystem->DirName(
fDigiFileName), i + 1));
235 for (Int_t iLayer = 0; iLayer < nLayers; iLayer++) {
237 if (!layer) Fatal(
"Init",
"Incomplete layers array.");
242 printf(
"Station%i segmented\n", i + 1);
246 TFile* oldFile = gFile;
247 TDirectory* oldDir = gDirectory;
268 if (!layerSide) Fatal(
"Init",
"Incomplete layer sides array.");
270 for (Int_t iModule = 0; iModule < nModules; iModule++) {
283 TVector3 modSize =
module->GetSize();
284 Double_t modLx = modSize.X();
285 Double_t modLy = modSize.Y();
286 Double_t modLz = modSize.Z();
287 TVector3 modPosition =
module->GetPosition();
288 Double_t modX = modPosition.X();
289 Double_t modY = modPosition.Y();
290 Double_t modZ = modPosition.Z();
292 Bool_t result = modLx > modLy;
293 Int_t iRatio = (result) ? (Int_t)((modLx + 1e-3) / modLy) : (Int_t)((modLy + 1e-3) / modLx);
294 Int_t detectorId =
module->GetDetectorId();
295 Double_t secLx = (result) ? modLx / iRatio : modLx;
296 Double_t secLy = (result) ? modLy : modLy / iRatio;
297 for (Int_t i = 0; i < iRatio; i++) {
298 Double_t secX = (result) ? modX - modLx / 2. + (i + 0.5) * secLx : modX;
299 Double_t secY = (result) ? modY : modY - modLy / 2. + (i + 0.5) * secLy;
300 Int_t iSector =
module->GetNSectors();
302 TVector3 sectorPosition(secX, secY, modZ);
303 TVector3 sectorSize(secLx, secLy, modLz);
314 TVector3 secSize = sector->
GetSize();
316 Int_t detectorId =
module->GetDetectorId();
321 Double_t secLx = secSize.X();
322 Double_t secLy = secSize.Y();
323 Double_t secLz = secSize.Z();
324 Double_t secX = secPosition.X();
325 Double_t secY = secPosition.Y();
326 Double_t secZ = secPosition.Z();
336 if (result1 || result2) {
delete sector; }
339 Double_t rMax = station->
GetRmax();
344 module->AddSector(sector);
349 Double_t newSecX, newSecY, newSecLx, newSecLy;
350 Bool_t equal = TMath::Abs(secLx - secLy) < 1e-5;
351 Bool_t res = secLx > secLy;
352 TVector3 position,
size;
353 if (result1 && result2) {
354 if (equal) { res = kTRUE; }
355 for (Int_t i = 0; i < 2; ++i) {
356 iSector =
module->GetNSectors();
357 newSecLx = res ? secLx / 2. : secLx;
358 newSecLy = res ? secLy : secLy / 2.;
359 newSecX = res ? secX + (i - 0.5) * newSecLx : secX;
360 newSecY = res ? secY : secY + (i - 0.5) * newSecLy;
361 position.SetXYZ(newSecX, newSecY, secZ);
362 size.SetXYZ(newSecLx, newSecLy, secLz);
366 else if (result1 || result2) {
367 for (Int_t i = 0; i < 2; i++) {
368 iSector =
module->GetNSectors();
369 newSecLx = result1 ? secLx / 2. : secLx;
370 newSecLy = result1 ? secLy : secLy / 2;
371 newSecX = result1 ? secX + (i - 0.5) * newSecLx : secX;
372 newSecY = result1 ? secY : secY + (i - 0.5) * newSecLy;
373 position.SetXYZ(newSecX, newSecY, secZ);
374 size.SetXYZ(newSecLx, newSecLy, secLz);
384 Double_t secLx = sector->
GetSize()[0];
385 Double_t secLy = sector->
GetSize()[1];
389 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
390 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
391 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
392 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
394 Double_t uR = (ulR < urR) ? ulR : urR;
395 Double_t bR = (blR < brR) ? blR : brR;
396 Double_t R = (uR < bR) ? uR : bR;
404 if (sigma > sigmaMin && sigma / 2. < sigmaMin)
return false;
405 if (sigma > sigmaMax)
return true;
407 Double_t hitDensity =
exp(
fExp0.at(iStation) +
fExp1.at(iStation) * R);
409 Double_t sPad = secLx * secLy / 128.;
410 Double_t nPads = (1.354 - 0.304 * TMath::Log2(sPad));
412 Double_t occupancy = hitDensity * sPad * nPads;
413 if (occupancy > occupancyMax)
return true;
421 Double_t secLx = sector->
GetSize()[0];
422 Double_t secLy = sector->
GetSize()[1];
426 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
427 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
428 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
429 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
431 Double_t uR = (ulR < urR) ? ulR : urR;
432 Double_t bR = (blR < brR) ? blR : brR;
433 Double_t R = (uR < bR) ? uR : bR;
441 if (sigma > sigmaMin && sigma / 2. < sigmaMin)
return false;
442 if (sigma > sigmaMax)
return true;
444 Double_t hitDensity =
exp(
fExp0.at(iStation) +
fExp1.at(iStation) * R);
446 Double_t sPad = secLx * secLy / 128.;
447 Double_t nPads = (1.354 - 0.304 * TMath::Log2(sPad));
448 Double_t occupancy = hitDensity * sPad * nPads;
449 if (occupancy > occupancyMax)
return true;
458 if (radius < 0)
return 0;
460 Int_t intersects = 0;
462 Double_t secLx = sector->
GetSize()[0];
463 Double_t secLy = sector->
GetSize()[1];
467 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
468 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY + secLy / 2.) * (secY + secLy / 2.));
469 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
470 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.) + (secY - secLy / 2.) * (secY - secLy / 2.));
472 if (ulR < radius) intersects++;
473 if (urR < radius) intersects++;
474 if (blR < radius) intersects++;
475 if (brR < radius) intersects++;
477 if (intersects == 4)
return 2;
478 if (intersects)
return 1;
486 printf(
"Segmentation written to file %s\n",
fDigiFileName.Data());
487 Int_t nTotSectors = 0;
488 Int_t nTotChannels = 0;
490 Int_t nTotStraws = 0;
491 printf(
"====================================================================="
492 "============================\n");
493 for (Int_t iStation = 0; iStation <
fStations->GetEntriesFast(); ++iStation) {
499 Double_t padMaxLx = std::numeric_limits<Double_t>::min();
500 Double_t padMinLx = std::numeric_limits<Double_t>::max();
501 Double_t padMaxLy = std::numeric_limits<Double_t>::min();
502 Double_t padMinLy = std::numeric_limits<Double_t>::max();
503 if (!station)
continue;
504 for (Int_t iLayer = 0; iLayer < station->
GetNLayers(); ++iLayer) {
506 if (!layer)
continue;
507 for (Int_t iSide = 0; iSide < 2; ++iSide) {
510 for (Int_t iModule = 0; iModule < side->
GetNModules(); ++iModule) {
516 if (!module)
continue;
518 nSectors +=
module->GetNSectors();
519 for (Int_t iSector = 0; iSector < module->
GetNSectors(); ++iSector) {
521 if (!sector)
continue;
522 Double_t padLx = sector->
GetPadDx();
523 Double_t padLy = sector->
GetPadDy();
524 if (padLx > padMaxLx) padMaxLx = padLx;
525 if (padLx < padMinLx) padMinLx = padLx;
526 if (padLy > padMaxLy) padMaxLy = padLy;
527 if (padLy < padMinLy) padMinLy = padLy;
539 printf(
"Station %i:\n", iStation + 1);
540 printf(
" GEM modules: %i\n", nGems);
542 printf(
" Sectors: %i, Pads: %i, Min.Pad size:%3.2fx%3.2f, Max.Pad "
543 "size:%3.2fx%3.2f\n",
544 nSectors, nChannels, padMinLx, padMinLy, padMaxLx, padMaxLy);
545 printf(
" Straw modules: %i\n", nStraws);
546 nTotSectors += nSectors;
547 nTotChannels += nChannels;
549 nTotStraws += nStraws;
551 printf(
"---------------------------------------------------------------------"
552 "----------------------------\n");
553 printf(
" Summary: \n GEM modules: %i\n Sectors: %i, Pads: %i\n "
554 "Straw modules: %i\n",
555 nTotGems, nTotSectors, nTotChannels, nTotStraws);
556 printf(
"====================================================================="
557 "============================\n");
563 Int_t startIndex = digifile.size() - 4;
564 string txtfile = digifile.erase(startIndex, 4);
565 txtfile.append(
"txt");
567 outfile = fopen(txtfile.c_str(),
"w");
572 Double_t secMinLx = std::numeric_limits<Double_t>::max();
573 Double_t secMinLy = std::numeric_limits<Double_t>::max();
574 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
577 for (Int_t iSide = 1; iSide >= 0; iSide--) {
579 for (Int_t iModule = 0; iModule < side->
GetNModules(); ++iModule) {
583 for (Int_t iSector = 0; iSector < module->
GetNSectors(); ++iSector) {
585 if (sector->
GetSize()[0] < secMinLx) secMinLx = sector->
GetSize()[0];
586 if (sector->
GetSize()[1] < secMinLy) secMinLy = sector->
GetSize()[1];
592 for (Int_t iStation = 0; iStation <
fStations->GetEntriesFast(); ++iStation) {
593 fprintf(outfile,
"=================================================================="
595 fprintf(outfile,
"Station %i\n", iStation + 1);
596 fprintf(outfile,
"Sector size, cm Sector position, cm Number of pads Side "
598 fprintf(outfile,
"------------------------------------------------------------------"
600 TCanvas* c1 =
new TCanvas(Form(
"station%i", iStation + 1), Form(
"station%i", iStation + 1), 800, 800);
602 c1->Range(-250, -250, 250, 250);
605 for (Int_t iSide = 1; iSide >= 0; iSide--) {
607 for (Int_t iModule = 0; iModule < layerSide->
GetNModules(); ++iModule) {
609 mod->SetFillStyle(0);
613 for (Int_t iSector = 0; iSector < module->
GetNSectors(); ++iSector) {
622 const char* side = iSide ?
"Back" :
"Front";
623 fprintf(outfile,
"%-4.2fx%-10.2f %-6.2fx%-12.2f %-14i %-5s ", sector->
GetSize()[0],
632 TArc* arc =
new TArc(0., 0., station->
GetRmin());
635 c1->Print(Form(
"%s/station%i.eps", gSystem->DirName(
fDigiFileName), iStation + 1));
636 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()
TObjArray * GetStations()
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.