24#include <FairRuntimeDb.h>
75 , fInputFileName(inputFileName.Data())
76 , fDigiFileName(digiFileName.Data())
98 FairRuntimeDb* db = FairRuntimeDb::instance();
99 if (!db) Fatal(
"Init",
"No runtime database");
107 printf(
"\n============================= Inputs segmentation parameters "
108 "================================\n");
110 printf(
"\n==================================================================="
111 "============================\n");
116 if (!
fStations) Fatal(
"Init",
"No input array of MUCH stations.");
117 if (
fStations->GetEntriesFast() !=
fNStations) Fatal(
"Init",
"Incorrect number of stations.");
120 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
121 printf(
"Station %i\n", iStation + 1);
122 for (Int_t iRegion = 0; iRegion <
fNRegions[iStation]; ++iRegion)
123 printf(
" Region %i: fAngles=%4.1f\n", iRegion + 1,
fAngles[iStation][iRegion]);
136 for (Int_t iStation = 0; iStation <
fStations->GetEntriesFast(); ++iStation) {
140 for (Int_t iLayer = 0; iLayer < nLayers; ++iLayer) {
142 if (!layer) Fatal(
"SegmentMuch",
"Incomplete layers array.");
147 printf(
"Station %i segmented\n", iStation + 1);
151 TFile* oldFile = gFile;
152 TDirectory* oldDir = gDirectory;
170 if (!layerSide) Fatal(
"SegmentLayerSide",
"Incomplete layer sides array.");
174 for (Int_t iModule = 0; iModule < nModules; iModule++) {
191 Int_t detectorId =
module->GetDetectorId();
197 Double_t rMin = 0.0, rMax = 0.0, r0 = 0.0;
202 r0 =
module->GetPosition().Perp();
203 phi0 =
module->GetPosition().Phi();
216 Double_t dx1 =
module->GetDx1();
217 Double_t dx2 =
module->GetDx2();
218 Double_t dy =
module->GetDy();
222 Double_t t = 2 * dy / (dx2 - dx1);
223 Double_t b = (r0 - dy) - t * dx1;
226 Double_t a = t * t + 1;
230 if (
fDebug) printf(
"Debug: %i %i %i %i\n", iStation, iLayer, iSide, iModule);
232 for (Int_t i = 0; i <
fNRegions[iStation]; i++) {
233 Double_t angle =
fAngles[iStation][i] * TMath::DegToRad();
234 while (r2 <
fRadii[iStation][i] && r2 < rMax) {
235 r2 = r1 + r1 * angle;
236 Double_t dphi = TMath::ASin((-bt +
sqrt(a * r2 * r2 - b2)) / a / r2);
240 module->AddSector(new CbmMuchSectorRadial(detectorId, iSector, r1, r2, phi0 - dphi, phi0 + dphi));
246 if (
fDebug) printf(
" Sectors = %i\n", iSector);
257 if (!infile) { Fatal(
"ReadInputFile",
"Error: Cannot open the input file."); }
265 strs =
Split(str,
' ');
266 index = strs.size() - 1;
268 StrToNum(strs.at(index), nStations);
270 printf(
"Number of stations: \t%i",
fNStations);
274 strs =
Split(str,
' ');
275 printf(
"\nNumber of regions: ");
276 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
281 fRadii[iStation].resize(nRegions);
282 fAngles[iStation].resize(nRegions);
286 for (Int_t iStation = 0; iStation <
fNStations; ++iStation) {
289 strs =
Split(str,
' ');
290 printf(
"\nStation %i", iStation + 1);
291 printf(
"\n Region radii [cm]: ");
292 for (Int_t iRegion = 0; iRegion <
fNRegions[iStation]; ++iRegion) {
293 index = strs.size() -
fNRegions[iStation] + iRegion;
295 printf(
"\t%4.2f",
fRadii[iStation][iRegion]);
299 strs =
Split(str,
' ');
300 printf(
"\n Pad angles [deg]: ");
301 for (Int_t iRegion = 0; iRegion <
fNRegions[iStation]; ++iRegion) {
302 index = strs.size() -
fNRegions[iStation] + iRegion;
304 printf(
"\t%4.2f",
fAngles[iStation][iRegion]);
317 for (iChar = length - 1; iChar >= 0; --iChar) {
321 txtfile[iChar + 1] =
'\0';
322 strcat(txtfile,
"txt");
325 outfile = fopen(txtfile,
"w");
334 for (Int_t iStation = 0; iStation <
fStations->GetEntriesFast(); ++iStation) {
335 fprintf(outfile,
"=================================================================="
337 fprintf(outfile,
"Station %i\n", iStation + 1);
338 fprintf(outfile,
"Sector size, cm Sector position, cm Number of pads Side "
340 fprintf(outfile,
"------------------------------------------------------------------"
342 TCanvas* c1 =
new TCanvas(Form(
"station%i", iStation + 1), Form(
"station%i", iStation + 1), 1000, 1000);
344 c1->Range(-200, -200, 200, 200);
345 c1->Range(-270, -270, 270, 270);
346 c1->Range(-50, -50, 50, 50);
349 for (Int_t iSide = 1; iSide >= 0; iSide--) {
351 for (Int_t iModule = 0; iModule < layerSide->
GetNModules(); ++iModule) {
353 mod->SetFillStyle(0);
356 LOG(info) <<
"Det SEgmentation: " << mod->
GetDetectorType() <<
" Station " << iStation;
359 for (Int_t iSector = 0; iSector < module->
GetNSectors(); ++iSector) {
368 TArc* holeArc =
new TArc(0., 0., station->
GetRmin());
372 for (Int_t iRegion = 0; iRegion <
fNRegions[iStation]; ++iRegion) {
373 TArc* arc =
new TArc(0., 0.,
fRadii[iStation].at(iRegion));
374 arc->SetLineColor(kBlack);
375 arc->SetLineWidth(2);
376 arc->SetFillStyle(0);
381 c1->Print(Form(
"%s/station%i.eps", gSystem->DirName(
fDigiFileName), iStation + 1));
382 c1->Print(Form(
"%s/station%i.png", gSystem->DirName(
fDigiFileName), iStation + 1));
ClassImp(CbmConverterManager)
friend fvec sqrt(const fvec &a)
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()
CbmMuchSector * GetSectorByIndex(Int_t iSector)
Int_t GetNSectors() const
Int_t GetDetectorType() const
virtual void SetParContainers()
virtual ~CbmMuchSegmentSector()
std::vector< std::string > & Split(const std::string &s, char delim, std::vector< std::string > &elems)
void StrToNum(std::string &str, T &number)
std::map< Int_t, std::vector< Double_t > > fAngles
virtual InitStatus Init()
std::map< Int_t, std::vector< Double_t > > fRadii
std::map< Int_t, Int_t > fNRegions
void OmitDummyLines(std::ifstream &infile, std::string &str)
Int_t SegmentModule(CbmMuchModuleGemRadial *module, Bool_t useModuleDesign)
Int_t SegmentLayerSide(CbmMuchLayerSide *layerSide)
CbmMuchLayer * GetLayer(Int_t iLayer) const