21 #include <FairRootManager.h>
22 #include <FairRuntimeDb.h>
28 #include <TClonesArray.h>
33 #include <TMathBase.h>
34 #include <TObjArray.h>
74 , fDigiFileName(digiFileName)
99 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
100 fSigmaXmin.at(iStation) = sigmaXmin[iStation];
101 fSigmaYmin.at(iStation) = sigmaYmin[iStation];
105 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
106 fSigmaXmax.at(iStation) = sigmaXmax[iStation];
107 fSigmaYmax.at(iStation) = sigmaYmax[iStation];
112 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
120 FairRuntimeDb* db = FairRuntimeDb::instance();
121 if (!db) Fatal(
"SetParContainers",
"No runtime database");
130 FairRootManager* fManager = FairRootManager::Instance();
131 fPoints = (TClonesArray*) fManager->GetObject(
"MuchPoint");
135 if (!
fStations) Fatal(
"Init",
"No input array of MUCH stations.");
137 Fatal(
"Init",
"Incorrect number of stations set.");
144 Form(
"hStation%i",
i + 1), Form(
"Station %i",
i + 1), 110, 0, 220);
158 printf(
"Event: %i\n",
fEvents);
160 gStyle->SetOptStat(0);
161 for (Int_t iPoint = 0; iPoint <
fPoints->GetEntriesFast(); iPoint++) {
163 if (!point)
continue;
172 assert(iStation >= 0 && iStation <
fNStations);
173 if (iLayer)
continue;
175 point->Position(
pos);
184 TH1D* hNorm =
new TH1D(
"hNorm",
"", 110, 0, 220);
185 Double_t binSize = 2.;
186 for (Int_t l = 0; l < 100; l++) {
187 Double_t R1 = l * binSize;
188 Double_t R2 = (l + 1) * binSize;
189 Double_t s =
TMath::Pi() * (R2 * R2 - R1 * R1);
190 hNorm->SetBinContent(l + 1, s *
fEvents);
197 TCanvas* c1 =
new TCanvas(
198 Form(
"cStation%i",
i + 1), Form(
"Station %i",
i + 1), 10, 10, 500, 500);
200 c1->SetLeftMargin(0.12);
201 c1->SetRightMargin(0.08);
202 TF1* f1 =
new TF1(
"f1",
"exp([0] + [1]*x)");
203 f1->SetParameter(0, 0.5);
204 f1->SetParameter(1, -0.1);
206 Double_t exp0 =
h->GetFunction(
"f1")->GetParameter(0);
207 Double_t exp1 =
h->GetFunction(
"f1")->GetParameter(1);
208 fExp0.push_back(exp0);
209 fExp1.push_back(exp1);
213 Form(
"%s/hd_station%i.eps", gSystem->DirName(
fDigiFileName),
i + 1));
215 Form(
"%s/hd_station%i.png", gSystem->DirName(
fDigiFileName),
i + 1));
223 for (Int_t iLayer = 0; iLayer < nLayers; iLayer++) {
225 if (!layer) Fatal(
"Init",
"Incomplete layers array.");
230 printf(
"Station%i segmented\n",
i + 1);
234 TFile* oldfile = gFile;
250 if (!layerSide) Fatal(
"Init",
"Incomplete layer sides array.");
252 for (Int_t iModule = 0; iModule < nModules; iModule++) {
264 TVector3 modSize = module->
GetSize();
265 Double_t modLx = modSize.X();
266 Double_t modLy = modSize.Y();
267 Double_t modLz = modSize.Z();
269 Double_t modX = modPosition.X();
270 Double_t modY = modPosition.Y();
271 Double_t modZ = modPosition.Z();
273 Bool_t result = modLx > modLy;
274 Int_t iRatio = (result) ? (Int_t)((modLx + 1e-3) / modLy)
275 : (Int_t)((modLy + 1e-3) / modLx);
277 Double_t secLx = (result) ? modLx / iRatio : modLx;
278 Double_t secLy = (result) ? modLy : modLy / iRatio;
279 for (Int_t
i = 0;
i < iRatio;
i++) {
280 Double_t secX = (result) ? modX - modLx / 2. + (
i + 0.5) * secLx : modX;
281 Double_t secY = (result) ? modY : modY - modLy / 2. + (
i + 0.5) * secLy;
284 TVector3 sectorPosition(secX, secY, modZ);
285 TVector3 sectorSize(secLx, secLy, modLz);
287 detectorId, iSector, sectorPosition, sectorSize, 8, 16);
296 TVector3 secSize = sector->
GetSize();
303 Double_t secLx = secSize.X();
304 Double_t secLy = secSize.Y();
305 Double_t secLz = secSize.Z();
306 Double_t secX = secPosition.X();
307 Double_t secY = secPosition.Y();
308 Double_t secZ = secPosition.Z();
318 if (result1 || result2) {
322 Double_t rMax = station->
GetRmax();
333 Double_t newSecX, newSecY, newSecLx, newSecLy;
334 Bool_t equal = TMath::Abs(secLx - secLy) < 1e-5;
335 Bool_t res = secLx > secLy;
336 TVector3 position, size;
337 if (result1 && result2) {
338 if (equal) { res = kTRUE; }
339 for (Int_t
i = 0;
i < 2; ++
i) {
343 newSecLx = res ? secLx / 2. : secLx;
344 newSecLy = res ? secLy : secLy / 2.;
345 newSecX = res ? secX + (
i - 0.5) * newSecLx : secX;
346 newSecY = res ? secY : secY + (
i - 0.5) * newSecLy;
347 position.SetXYZ(newSecX, newSecY, secZ);
348 size.SetXYZ(newSecLx, newSecLy, secLz);
351 detectorId, iSector, position, size, 8, 16));
353 }
else if (result1 || result2) {
354 for (Int_t
i = 0;
i < 2;
i++) {
358 newSecLx = result1 ? secLx / 2. : secLx;
359 newSecLy = result1 ? secLy : secLy / 2;
360 newSecX = result1 ? secX + (
i - 0.5) * newSecLx : secX;
361 newSecY = result1 ? secY : secY + (
i - 0.5) * newSecLy;
362 position.SetXYZ(newSecX, newSecY, secZ);
363 size.SetXYZ(newSecLx, newSecLy, secLz);
366 detectorId, iSector, position, size, 8, 16));
374 Double_t secLx = sector->
GetSize()[0];
375 Double_t secLy = sector->
GetSize()[1];
379 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.)
380 + (secY + secLy / 2.) * (secY + secLy / 2.));
381 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.)
382 + (secY + secLy / 2.) * (secY + secLy / 2.));
383 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.)
384 + (secY - secLy / 2.) * (secY - secLy / 2.));
385 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.)
386 + (secY - secLy / 2.) * (secY - secLy / 2.));
388 Double_t uR = (ulR < urR) ? ulR : urR;
389 Double_t bR = (blR < brR) ? blR : brR;
390 Double_t R = (uR < bR) ? uR : bR;
400 if (sigma > sigmaMin && sigma / 2. < sigmaMin)
return false;
401 if (sigma > sigmaMax)
return true;
403 Double_t hitDensity =
exp(
fExp0.at(iStation) +
fExp1.at(iStation) * R);
404 Double_t occupancyMax =
406 Double_t sPad = secLx * secLy / 128.;
410 * TMath::Log2(sPad));
412 Double_t occupancy = hitDensity * sPad * nPads;
413 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.)
426 + (secY + secLy / 2.) * (secY + secLy / 2.));
427 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.)
428 + (secY + secLy / 2.) * (secY + secLy / 2.));
429 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.)
430 + (secY - secLy / 2.) * (secY - secLy / 2.));
431 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.)
432 + (secY - secLy / 2.) * (secY - secLy / 2.));
434 Double_t uR = (ulR < urR) ? ulR : urR;
435 Double_t bR = (blR < brR) ? blR : brR;
436 Double_t R = (uR < bR) ? uR : bR;
446 if (sigma > sigmaMin && sigma / 2. < sigmaMin)
return false;
447 if (sigma > sigmaMax)
return true;
449 Double_t hitDensity =
exp(
fExp0.at(iStation) +
fExp1.at(iStation) * R);
450 Double_t occupancyMax =
452 Double_t sPad = secLx * secLy / 128.;
456 * TMath::Log2(sPad));
457 Double_t occupancy = hitDensity * sPad * nPads;
458 if (occupancy > occupancyMax)
return true;
467 if (radius < 0)
return 0;
469 Int_t intersects = 0;
471 Double_t secLx = sector->
GetSize()[0];
472 Double_t secLy = sector->
GetSize()[1];
476 Double_t ulR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.)
477 + (secY + secLy / 2.) * (secY + secLy / 2.));
478 Double_t urR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.)
479 + (secY + secLy / 2.) * (secY + secLy / 2.));
480 Double_t blR = TMath::Sqrt((secX - secLx / 2.) * (secX - secLx / 2.)
481 + (secY - secLy / 2.) * (secY - secLy / 2.));
482 Double_t brR = TMath::Sqrt((secX + secLx / 2.) * (secX + secLx / 2.)
483 + (secY - secLy / 2.) * (secY - secLy / 2.));
485 if (ulR < radius) intersects++;
486 if (urR < radius) intersects++;
487 if (blR < radius) intersects++;
488 if (brR < radius) intersects++;
490 if (intersects == 4)
return 2;
499 printf(
"Segmentation written to file %s\n",
fDigiFileName.Data());
500 Int_t nTotSectors = 0;
501 Int_t nTotChannels = 0;
503 Int_t nTotStraws = 0;
504 printf(
"====================================================================="
505 "============================\n");
506 for (Int_t iStation = 0; iStation <
fStations->GetEntries(); ++iStation) {
516 if (!station)
continue;
517 for (Int_t iLayer = 0; iLayer < station->
GetNLayers(); ++iLayer) {
519 if (!layer)
continue;
520 for (Int_t iSide = 0; iSide < 2; ++iSide) {
523 for (Int_t iModule = 0; iModule < side->
GetNModules(); ++iModule) {
529 if (!module)
continue;
532 for (Int_t iSector = 0; iSector < module->
GetNSectors();
536 if (!sector)
continue;
537 Double_t padLx = sector->
GetPadDx();
538 Double_t padLy = sector->
GetPadDy();
539 if (padLx > padMaxLx) padMaxLx = padLx;
540 if (padLx < padMinLx) padMinLx = padLx;
541 if (padLy > padMaxLy) padMaxLy = padLy;
542 if (padLy < padMinLy) padMinLy = padLy;
554 printf(
"Station %i:\n", iStation + 1);
555 printf(
" GEM modules: %i\n", nGems);
557 printf(
" Sectors: %i, Pads: %i, Min.Pad size:%3.2fx%3.2f, Max.Pad "
558 "size:%3.2fx%3.2f\n",
565 printf(
" Straw modules: %i\n", nStraws);
566 nTotSectors += nSectors;
567 nTotChannels += nChannels;
569 nTotStraws += nStraws;
571 printf(
"---------------------------------------------------------------------"
572 "----------------------------\n");
573 printf(
" Summary: \n GEM modules: %i\n Sectors: %i, Pads: %i\n "
574 "Straw modules: %i\n",
579 printf(
"====================================================================="
580 "============================\n");
585 Int_t startIndex = digifile.size() - 4;
586 string txtfile = digifile.erase(startIndex, 4);
587 txtfile.append(
"txt");
589 outfile = fopen(txtfile.c_str(),
"w");
596 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
599 for (Int_t iSide = 1; iSide >= 0; iSide--) {
601 for (Int_t iModule = 0; iModule < side->
GetNModules(); ++iModule) {
605 for (Int_t iSector = 0; iSector < module->
GetNSectors(); ++iSector) {
608 if (sector->
GetSize()[0] < secMinLx) secMinLx = sector->
GetSize()[0];
609 if (sector->
GetSize()[1] < secMinLy) secMinLy = sector->
GetSize()[1];
615 for (Int_t iStation = 0; iStation <
fStations->GetEntriesFast(); ++iStation) {
617 "=================================================================="
619 fprintf(outfile,
"Station %i\n", iStation + 1);
621 "Sector size, cm Sector position, cm Number of pads Side "
624 "------------------------------------------------------------------"
626 TCanvas* c1 =
new TCanvas(Form(
"station%i", iStation + 1),
627 Form(
"station%i", iStation + 1),
631 c1->Range(-250, -250, 250, 250);
634 for (Int_t iSide = 1; iSide >= 0; iSide--) {
636 for (Int_t iModule = 0; iModule < layerSide->
GetNModules(); ++iModule) {
638 mod->SetFillStyle(0);
642 for (Int_t iSector = 0; iSector < module->
GetNSectors(); ++iSector) {
652 const char* side = iSide ?
"Back" :
"Front";
654 "%-4.2fx%-10.2f %-6.2fx%-12.2f %-14i %-5s ",
667 TArc* arc =
new TArc(0., 0., station->
GetRmin());
671 Form(
"%s/station%i.eps", gSystem->DirName(
fDigiFileName), iStation + 1));
673 Form(
"%s/station%i.png", gSystem->DirName(
fDigiFileName), iStation + 1));