CbmRoot
Loading...
Searching...
No Matches
CbmMuchSegmentSector.cxx
Go to the documentation of this file.
1/* Copyright (C) 2012-2021 Petersburg Nuclear Physics Institute named by B.P.Konstantinov of National Research Centre "Kurchatov Institute", Gatchina
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Evgeny Kryshen [committer], Florian Uhlig */
4
14
15#include "CbmGeoMuchPar.h" // for CbmGeoMuchPar
16#include "CbmMuchAddress.h" // for CbmMuchAddress
17#include "CbmMuchLayer.h" // for CbmMuchLayer
18#include "CbmMuchLayerSide.h" // for CbmMuchLayerSide
19#include "CbmMuchModule.h" // for CbmMuchModule
20#include "CbmMuchModuleGemRadial.h" // for CbmMuchModuleGemRadial
21#include "CbmMuchSectorRadial.h" // for CbmMuchSectorRadial
22#include "CbmMuchStation.h" // for CbmMuchStation
23
24#include <FairRuntimeDb.h> // for FairRuntimeDb
25#include <FairTask.h> // for FairTask, InitStatus, kSUCCESS
26#include <Logger.h> // for LOG
27
28#include <TArc.h> // for TArc
29#include <TCanvas.h> // for TCanvas
30#include <TFile.h> // for TFile, gFile
31#include <TMath.h> // for DegToRad, ASin
32#include <TObjArray.h> // for TObjArray
33#include <TSystem.h> // for TSystem, gSystem
34#include <TVector3.h> // for TVector3
35
36#include <vector> // for vector
37
38#include <math.h> // for sqrt
39#include <stdio.h> // for printf, fprintf, fclose
40#include <string.h> // for strcat, strlen, strncpy
41
42using std::ifstream;
43using std::string;
44using std::vector;
45
46// ----- Default constructor -------------------------------------------
48 : FairTask()
49 , fGeoPar(nullptr)
50 , fNStations(0)
51 , fFlag(0)
52 , fStations(nullptr)
53 , fInputFileName()
54 , fDigiFileName()
55 , fNRegions()
56 , fRadii()
57 , fAngles()
58 , fSecLx()
59 , fSecLy()
60 , fNChannels()
61 , fNCols()
62 , fNRows()
63 , fDebug(0)
64{
65}
66// -------------------------------------------------------------------------
67
68// ----- Standard constructor ------------------------------------------
69CbmMuchSegmentSector::CbmMuchSegmentSector(TString inputFileName, TString digiFileName, Int_t flag)
70 : FairTask()
71 , fGeoPar(nullptr)
72 , fNStations(0)
73 , fFlag(flag)
74 , fStations(nullptr)
75 , fInputFileName(inputFileName.Data())
76 , fDigiFileName(digiFileName.Data())
77 , fNRegions()
78 , fRadii()
79 , fAngles()
80 , fSecLx()
81 , fSecLy()
82 , fNChannels()
83 , fNCols()
84 , fNRows()
85 , fDebug(0)
86{
87}
88// -------------------------------------------------------------------------
89
90// ----- Destructor ----------------------------------------------------
92// -------------------------------------------------------------------------
93
94// ----- Private method SetParContainers --------------------------------
96{
97 // Get runtime database
98 FairRuntimeDb* db = FairRuntimeDb::instance();
99 if (!db) Fatal("Init", "No runtime database");
100 fGeoPar = (CbmGeoMuchPar*) db->getContainer("CbmGeoMuchPar");
101}
102// -------------------------------------------------------------------------
103
104// ----- Private method Init ---------------------------------------------
106{
107 printf("\n============================= Inputs segmentation parameters "
108 "================================\n");
110 printf("\n==================================================================="
111 "============================\n");
112
113 // Get MUCH geometry parameter container
115 // LOG(info)<<" Stations = "<<fStations->GetEntriesFast()<<" "<<fNStations;
116 if (!fStations) Fatal("Init", "No input array of MUCH stations.");
117 if (fStations->GetEntriesFast() != fNStations) Fatal("Init", "Incorrect number of stations.");
118
119 if (fDebug) {
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]);
124 }
125 }
126
127 // Segment MuCh
128 SegmentMuch();
129 return kSUCCESS;
130}
131// -------------------------------------------------------------------------
132
133// ----- Public method SegmentMuch --------------------------------------
135{
136 for (Int_t iStation = 0; iStation < fStations->GetEntriesFast(); ++iStation) {
137 CbmMuchStation* station = (CbmMuchStation*) fStations->At(iStation);
138
139 Int_t nLayers = station->GetNLayers();
140 for (Int_t iLayer = 0; iLayer < nLayers; ++iLayer) {
141 CbmMuchLayer* layer = station->GetLayer(iLayer);
142 if (!layer) Fatal("SegmentMuch", "Incomplete layers array.");
143 // Segment layer sides
144 printf("Layer=%d SideF Sectors=%i\n", iLayer, SegmentLayerSide(layer->GetSideF()));
145 printf("Layer=%d SideB Sectors=%i\n", iLayer, SegmentLayerSide(layer->GetSideB()));
146 }
147 printf("Station %i segmented\n", iStation + 1);
148 }
149
151 TFile* oldFile = gFile;
152 TDirectory* oldDir = gDirectory;
153
154 // Save parameters
155 TFile* f = new TFile(fDigiFileName, "RECREATE");
156 fStations->Write("stations", 1);
157
158 f->Close();
160 gFile = oldFile;
161 gDirectory = oldDir;
162
164}
165// -------------------------------------------------------------------------
166
167// ----- Private method SegmentLayerSide --------------------------------
169{
170 if (!layerSide) Fatal("SegmentLayerSide", "Incomplete layer sides array.");
171 Int_t nModules = layerSide->GetNModules();
172 // LOG(info)<<" Total Modules "<< nModules;
173 Int_t nSectors = 0;
174 for (Int_t iModule = 0; iModule < nModules; iModule++) {
175 CbmMuchModule* module = layerSide->GetModule(iModule);
176 if (module->GetDetectorType() != 3 && module->GetDetectorType() != 4)
177 continue;
178 // if(module->GetDetectorType()!=3) continue;
180 if (nModules > 0) nSectors += SegmentModule(mod, true); // Module design
181 else
182 nSectors += SegmentModule(mod, false); // Monolithic design
183 }
184 return nSectors;
185}
186// -------------------------------------------------------------------------
187
188// ----- Private method SegmentSector -----------------------------------
190{
191 Int_t detectorId = module->GetDetectorId();
192 Int_t iStation = CbmMuchAddress::GetStationIndex(detectorId);
193 Int_t iModule = CbmMuchAddress::GetModuleIndex(detectorId);
194 Int_t iLayer = CbmMuchAddress::GetLayerIndex(detectorId);
195 Int_t iSide = CbmMuchAddress::GetLayerSideIndex(detectorId);
196 CbmMuchStation* station = (CbmMuchStation*) fStations->At(iStation);
197 Double_t rMin = 0.0, rMax = 0.0, r0 = 0.0;
198 Double_t phi0 = 0.0;
199 if (fFlag == 0) {
200 rMin = station->GetRmin();
201 rMax = station->GetRmax();
202 r0 = module->GetPosition().Perp();
203 phi0 = module->GetPosition().Phi();
204 }
205
206 else {
207 //============For mini cbm=================================
208 rMin = 18.4654; // Ajit+OS -> rMin for Mv2 module
209 rMax = 97.2187; // Ajit+OS -> rMax for Mv2 module
210 r0 = 58.46; // Ajit+OS -> r0 for Mv2 module
211 phi0 =
212 258.50
213 * TMath::
214 DegToRad(); // Ajit+OS -> rotaion angle for segmented geomtery such that we don't need to rotate point - only translation is needed
215 }
216 Double_t dx1 = module->GetDx1();
217 Double_t dx2 = module->GetDx2();
218 Double_t dy = module->GetDy();
219
220 //LOG(info)<<" station # "<<iStation<<" Layer No. "<<iLayer<<" Side # "<<iSide<<" Module # "<<iModule<<" rmin "<<rMin<<" rmax "<<rMax<<" phi "<<phi0<<" r0 "<<r0<<" dx1 "<<dx1<<" dx2 "<<dx2<<" dy "<<dy;
221
222 Double_t t = 2 * dy / (dx2 - dx1);
223 Double_t b = (r0 - dy) - t * dx1;
224 Double_t b2 = b * b;
225 Double_t bt = b * t;
226 Double_t a = t * t + 1;
227
228 Double_t r1 = rMin;
229 Double_t r2 = rMin;
230 if (fDebug) printf("Debug: %i %i %i %i\n", iStation, iLayer, iSide, iModule);
231 Int_t iSector = 0;
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);
237 // Int_t nPads = 2*Int_t(phiMax/angle)+2;
238 // if (iStation==0 && iLayer==0 && iSide==0 && iModule==0) printf("Sector: %f-%f %i phiMax=%f\n",r1,r2,nPads,phiMax);
239 // LOG(info)<<" sector "<<iSector<< " pad size "<<r2-r1;
240 module->AddSector(new CbmMuchSectorRadial(detectorId, iSector, r1, r2, phi0 - dphi, phi0 + dphi));
241 //LOG(info)<<"r1 "<<r1<<" r2 "<<r2;
242 r1 = r2;
243 iSector++;
244 }
245 }
246 if (fDebug) printf(" Sectors = %i\n", iSector);
247 return iSector;
248}
249// -------------------------------------------------------------------------
250
251
252// -------------------------------------------------------------------------
254{
255 ifstream infile;
256 infile.open(fInputFileName);
257 if (!infile) { Fatal("ReadInputFile", "Error: Cannot open the input file."); }
258
259 Int_t index;
260 string str;
261 vector<string> strs;
262
263 // Set number of stations
264 OmitDummyLines(infile, str);
265 strs = Split(str, ' ');
266 index = strs.size() - 1;
267 Int_t nStations;
268 StrToNum(strs.at(index), nStations);
269 fNStations = nStations;
270 printf("Number of stations: \t%i", fNStations);
271
272 // Set number of regions
273 OmitDummyLines(infile, str);
274 strs = Split(str, ' ');
275 printf("\nNumber of regions: ");
276 for (Int_t iStation = 0; iStation < fNStations; ++iStation) {
277 index = strs.size() - fNStations + iStation;
278 Int_t nRegions;
279 StrToNum(strs.at(index), nRegions);
280 fNRegions[iStation] = nRegions;
281 fRadii[iStation].resize(nRegions);
282 fAngles[iStation].resize(nRegions);
283 printf("\t%i", fNRegions[iStation]);
284 }
285
286 for (Int_t iStation = 0; iStation < fNStations; ++iStation) {
287 // Set region radii
288 OmitDummyLines(infile, str);
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;
294 StrToNum(strs.at(index), fRadii[iStation][iRegion]);
295 printf("\t%4.2f", fRadii[iStation][iRegion]);
296 }
297 // Set pad angles
298 OmitDummyLines(infile, str);
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;
303 StrToNum(strs.at(index), fAngles[iStation][iRegion]);
304 printf("\t%4.2f", fAngles[iStation][iRegion]);
305 }
306 }
307 printf("\n");
308 infile.close();
309}
310
312{
313 // Change file extension
314 char txtfile[100];
315 Int_t length = strlen(fDigiFileName);
316 Int_t iChar;
317 for (iChar = length - 1; iChar >= 0; --iChar) {
318 if (fDigiFileName[iChar] == '.') break;
319 }
320 strncpy(txtfile, fDigiFileName, iChar + 1);
321 txtfile[iChar + 1] = '\0';
322 strcat(txtfile, "txt");
323
324 FILE* outfile;
325 outfile = fopen(txtfile, "w");
326 /*
327 Int_t colors[] = {kGreen, kMagenta, kCyan, kRed, kBlue, kYellow, kTeal,
328 kPink, kAzure, kOrange, kViolet, kSpring,
329 kGreen+2, kMagenta+2, kCyan+2, kRed+2, kBlue+2, kYellow+2, kTeal+2,
330 kPink+2, kAzure+2, kOrange+2, kViolet+2, kSpring+2,
331 kGreen+4, kMagenta+4, kCyan+4, kRed+4, kBlue+4, kYellow+4, kTeal+4,
332 kPink+4, kAzure+4, kOrange+4, kViolet+4, kSpring+4};
333*/
334 for (Int_t iStation = 0; iStation < fStations->GetEntriesFast(); ++iStation) {
335 fprintf(outfile, "=================================================================="
336 "=========\n");
337 fprintf(outfile, "Station %i\n", iStation + 1);
338 fprintf(outfile, "Sector size, cm Sector position, cm Number of pads Side "
339 "Pad size, cm\n");
340 fprintf(outfile, "------------------------------------------------------------------"
341 "----------\n");
342 TCanvas* c1 = new TCanvas(Form("station%i", iStation + 1), Form("station%i", iStation + 1), 1000, 1000);
343 c1->SetFillColor(0);
344 c1->Range(-200, -200, 200, 200);
345 c1->Range(-270, -270, 270, 270);
346 c1->Range(-50, -50, 50, 50);
347 CbmMuchStation* station = (CbmMuchStation*) fStations->At(iStation);
348 CbmMuchLayer* layer = station->GetLayer(0);
349 for (Int_t iSide = 1; iSide >= 0; iSide--) {
350 CbmMuchLayerSide* layerSide = layer->GetSide(iSide);
351 for (Int_t iModule = 0; iModule < layerSide->GetNModules(); ++iModule) {
352 CbmMuchModule* mod = layerSide->GetModule(iModule);
353 mod->SetFillStyle(0);
354 // mod->Draw();
355 if (mod->GetDetectorType() != 3 && mod->GetDetectorType() != 4) continue;
356 LOG(info) << "Det SEgmentation: " << mod->GetDetectorType() << " Station " << iStation;
357 // if(mod->GetDetectorType() != 3) continue;
359 for (Int_t iSector = 0; iSector < module->GetNSectors(); ++iSector) {
360 CbmMuchSectorRadial* sector = (CbmMuchSectorRadial*) module->GetSectorByIndex(iSector);
361 sector->AddPads();
362 sector->DrawPads();
363 } // sectors
364 } // modules
365 } // sides
366
367 // Draw a hole
368 TArc* holeArc = new TArc(0., 0., station->GetRmin());
369 // TArc* holeArc = new TArc(0.,0.,rMin);
370 holeArc->Draw();
371
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);
377 arc->Draw();
378 }
379
380 if (fDebug) {
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));
383 }
384
385 } //stations
386 fclose(outfile);
387}
388
389
390//double x0 = -a*c/(a*a+b*b), y0 = -b*c/(a*a+b*b);
391//if (c*c > r*r*(a*a+b*b)+EPS)
392// puts ("no points");
393//else {
394// double d = r*r - c*c/(a*a+b*b);
395// double mult = sqrt (d / (a*a+b*b));
396// double ax,ay,bx,by;
397// ax = x0 + b * mult;
398// bx = x0 - b * mult;
399// ay = y0 - a * mult;
400// by = y0 + a * mult;
401//}
402
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
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)
Double_t GetRmin() const
CbmMuchLayer * GetLayer(Int_t iLayer) const
Double_t GetRmax() const
Int_t GetNLayers() const