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 <cmath> // for sqrt
37#include <cstdio> // for printf, fprintf, fclose
38#include <cstring> // for strcat, strlen, strncpy
39#include <vector> // for vector
40
41using std::ifstream;
42using std::string;
43using std::vector;
44
45// ----- Default constructor -------------------------------------------
47 : FairTask()
48 , fGeoPar(nullptr)
49 , fNStations(0)
50 , fFlag(0)
51 , fStations(nullptr)
54 , fNRegions()
55 , fRadii()
56 , fAngles()
57 , fSecLx()
58 , fSecLy()
59 , fNChannels()
60 , fNCols()
61 , fNRows()
62 , fDebug(0)
63{
64}
65// -------------------------------------------------------------------------
66
67// ----- Standard constructor ------------------------------------------
68CbmMuchSegmentSector::CbmMuchSegmentSector(TString inputFileName, TString digiFileName, Int_t flag)
69 : FairTask()
70 , fGeoPar(nullptr)
71 , fNStations(0)
72 , fFlag(flag)
73 , fStations(nullptr)
74 , fInputFileName(inputFileName.Data())
75 , fDigiFileName(digiFileName.Data())
76 , fNRegions()
77 , fRadii()
78 , fAngles()
79 , fSecLx()
80 , fSecLy()
81 , fNChannels()
82 , fNCols()
83 , fNRows()
84 , fDebug(0)
85{
86}
87// -------------------------------------------------------------------------
88
89// ----- Destructor ----------------------------------------------------
91// -------------------------------------------------------------------------
92
93// ----- Private method SetParContainers --------------------------------
95{
96 // Get runtime database
97 FairRuntimeDb* db = FairRuntimeDb::instance();
98 if (!db) Fatal("Init", "No runtime database");
99 fGeoPar = (CbmGeoMuchPar*) db->getContainer("CbmGeoMuchPar");
100}
101// -------------------------------------------------------------------------
102
103// ----- Private method Init ---------------------------------------------
105{
106 printf("\n============================= Inputs segmentation parameters "
107 "================================\n");
109 printf("\n==================================================================="
110 "============================\n");
111
112 // Get MUCH geometry parameter container
113 fStations = fGeoPar->GetStations();
114 // LOG(info)<<" Stations = "<<fStations->GetEntriesFast()<<" "<<fNStations;
115 if (!fStations) Fatal("Init", "No input array of MUCH stations.");
116 if (fStations->GetEntriesFast() != fNStations) Fatal("Init", "Incorrect number of stations.");
117
118 if (fDebug) {
119 for (Int_t iStation = 0; iStation < fNStations; ++iStation) {
120 printf("Station %i\n", iStation + 1);
121 for (Int_t iRegion = 0; iRegion < fNRegions[iStation]; ++iRegion)
122 printf(" Region %i: fAngles=%4.1f\n", iRegion + 1, fAngles[iStation][iRegion]);
123 }
124 }
125
126 // Segment MuCh
127 SegmentMuch();
128 return kSUCCESS;
129}
130// -------------------------------------------------------------------------
131
132// ----- Public method SegmentMuch --------------------------------------
134{
135 for (Int_t iStation = 0; iStation < fStations->GetEntriesFast(); ++iStation) {
136 CbmMuchStation* station = (CbmMuchStation*) fStations->At(iStation);
137
138 Int_t nLayers = station->GetNLayers();
139 for (Int_t iLayer = 0; iLayer < nLayers; ++iLayer) {
140 CbmMuchLayer* layer = station->GetLayer(iLayer);
141 if (!layer) Fatal("SegmentMuch", "Incomplete layers array.");
142 // Segment layer sides
143 printf("Layer=%d SideF Sectors=%i\n", iLayer, SegmentLayerSide(layer->GetSideF()));
144 printf("Layer=%d SideB Sectors=%i\n", iLayer, SegmentLayerSide(layer->GetSideB()));
145 }
146 printf("Station %i segmented\n", iStation + 1);
147 }
148
150 TFile* oldFile = gFile;
151 TDirectory* oldDir = gDirectory;
152
153 // Save parameters
154 TFile* f = new TFile(fDigiFileName, "RECREATE");
155 fStations->Write("stations", 1);
156
157 f->Close();
159 gFile = oldFile;
160 gDirectory = oldDir;
161
163}
164// -------------------------------------------------------------------------
165
166// ----- Private method SegmentLayerSide --------------------------------
168{
169 if (!layerSide) Fatal("SegmentLayerSide", "Incomplete layer sides array.");
170 Int_t nModules = layerSide->GetNModules();
171 // LOG(info)<<" Total Modules "<< nModules;
172 Int_t nSectors = 0;
173 for (Int_t iModule = 0; iModule < nModules; iModule++) {
174 CbmMuchModule* module = layerSide->GetModule(iModule);
175 if (module->GetDetectorType() != 3 && module->GetDetectorType() != 4)
176 continue;
177 // if(module->GetDetectorType()!=3) continue;
179 if (nModules > 0) nSectors += SegmentModule(mod, true); // Module design
180 else
181 nSectors += SegmentModule(mod, false); // Monolithic design
182 }
183 return nSectors;
184}
185// -------------------------------------------------------------------------
186
187// ----- Private method SegmentSector -----------------------------------
189{
190 Int_t detectorId = module->GetDetectorId();
191 Int_t iStation = CbmMuchAddress::GetStationIndex(detectorId);
192 Int_t iModule = CbmMuchAddress::GetModuleIndex(detectorId);
193 Int_t iLayer = CbmMuchAddress::GetLayerIndex(detectorId);
194 Int_t iSide = CbmMuchAddress::GetLayerSideIndex(detectorId);
195 CbmMuchStation* station = (CbmMuchStation*) fStations->At(iStation);
196 Double_t rMin = 0.0, rMax = 0.0, r0 = 0.0;
197 Double_t phi0 = 0.0;
198 if (fFlag == 0) {
199 rMin = station->GetRmin();
200 rMax = station->GetRmax();
201 r0 = module->GetPosition().Perp();
202 phi0 = module->GetPosition().Phi();
203 }
204
205 else {
206 //============For mini cbm=================================
207 rMin = 18.4654; // Ajit+OS -> rMin for Mv2 module
208 rMax = 97.2187; // Ajit+OS -> rMax for Mv2 module
209 r0 = 58.46; // Ajit+OS -> r0 for Mv2 module
210 phi0 =
211 258.50
212 * TMath::
213 DegToRad(); // Ajit+OS -> rotaion angle for segmented geomtery such that we don't need to rotate point - only translation is needed
214 }
215 Double_t dx1 = module->GetDx1();
216 Double_t dx2 = module->GetDx2();
217 Double_t dy = module->GetDy();
218
219 //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;
220
221 Double_t t = 2 * dy / (dx2 - dx1);
222 Double_t b = (r0 - dy) - t * dx1;
223 Double_t b2 = b * b;
224 Double_t bt = b * t;
225 Double_t a = t * t + 1;
226
227 Double_t r1 = rMin;
228 Double_t r2 = rMin;
229 if (fDebug) printf("Debug: %i %i %i %i\n", iStation, iLayer, iSide, iModule);
230 Int_t iSector = 0;
231 for (Int_t i = 0; i < fNRegions[iStation]; i++) {
232 Double_t angle = fAngles[iStation][i] * TMath::DegToRad();
233 while (r2 < fRadii[iStation][i] && r2 < rMax) {
234 r2 = r1 + r1 * angle;
235 Double_t dphi = TMath::ASin((-bt + sqrt(a * r2 * r2 - b2)) / a / r2);
236 // Int_t nPads = 2*Int_t(phiMax/angle)+2;
237 // if (iStation==0 && iLayer==0 && iSide==0 && iModule==0) printf("Sector: %f-%f %i phiMax=%f\n",r1,r2,nPads,phiMax);
238 // LOG(info)<<" sector "<<iSector<< " pad size "<<r2-r1;
239 module->AddSector(new CbmMuchSectorRadial(detectorId, iSector, r1, r2, phi0 - dphi, phi0 + dphi));
240 //LOG(info)<<"r1 "<<r1<<" r2 "<<r2;
241 r1 = r2;
242 iSector++;
243 }
244 }
245 if (fDebug) printf(" Sectors = %i\n", iSector);
246 return iSector;
247}
248// -------------------------------------------------------------------------
249
250
251// -------------------------------------------------------------------------
253{
254 ifstream infile;
255 infile.open(fInputFileName);
256 if (!infile) { Fatal("ReadInputFile", "Error: Cannot open the input file."); }
257
258 Int_t index;
259 string str;
260 vector<string> strs;
261
262 // Set number of stations
263 OmitDummyLines(infile, str);
264 strs = Split(str, ' ');
265 index = strs.size() - 1;
266 Int_t nStations;
267 StrToNum(strs.at(index), nStations);
268 fNStations = nStations;
269 printf("Number of stations: \t%i", fNStations);
270
271 // Set number of regions
272 OmitDummyLines(infile, str);
273 strs = Split(str, ' ');
274 printf("\nNumber of regions: ");
275 for (Int_t iStation = 0; iStation < fNStations; ++iStation) {
276 index = strs.size() - fNStations + iStation;
277 Int_t nRegions;
278 StrToNum(strs.at(index), nRegions);
279 fNRegions[iStation] = nRegions;
280 fRadii[iStation].resize(nRegions);
281 fAngles[iStation].resize(nRegions);
282 printf("\t%i", fNRegions[iStation]);
283 }
284
285 for (Int_t iStation = 0; iStation < fNStations; ++iStation) {
286 // Set region radii
287 OmitDummyLines(infile, str);
288 strs = Split(str, ' ');
289 printf("\nStation %i", iStation + 1);
290 printf("\n Region radii [cm]: ");
291 for (Int_t iRegion = 0; iRegion < fNRegions[iStation]; ++iRegion) {
292 index = strs.size() - fNRegions[iStation] + iRegion;
293 StrToNum(strs.at(index), fRadii[iStation][iRegion]);
294 printf("\t%4.2f", fRadii[iStation][iRegion]);
295 }
296 // Set pad angles
297 OmitDummyLines(infile, str);
298 strs = Split(str, ' ');
299 printf("\n Pad angles [deg]: ");
300 for (Int_t iRegion = 0; iRegion < fNRegions[iStation]; ++iRegion) {
301 index = strs.size() - fNRegions[iStation] + iRegion;
302 StrToNum(strs.at(index), fAngles[iStation][iRegion]);
303 printf("\t%4.2f", fAngles[iStation][iRegion]);
304 }
305 }
306 printf("\n");
307 infile.close();
308}
309
311{
312 // Change file extension
313 char txtfile[100];
314 Int_t length = strlen(fDigiFileName);
315 Int_t iChar;
316 for (iChar = length - 1; iChar >= 0; --iChar) {
317 if (fDigiFileName[iChar] == '.') break;
318 }
319 strncpy(txtfile, fDigiFileName, iChar + 1);
320 txtfile[iChar + 1] = '\0';
321 strcat(txtfile, "txt");
322
323 FILE* outfile;
324 outfile = fopen(txtfile, "w");
325 /*
326 Int_t colors[] = {kGreen, kMagenta, kCyan, kRed, kBlue, kYellow, kTeal,
327 kPink, kAzure, kOrange, kViolet, kSpring,
328 kGreen+2, kMagenta+2, kCyan+2, kRed+2, kBlue+2, kYellow+2, kTeal+2,
329 kPink+2, kAzure+2, kOrange+2, kViolet+2, kSpring+2,
330 kGreen+4, kMagenta+4, kCyan+4, kRed+4, kBlue+4, kYellow+4, kTeal+4,
331 kPink+4, kAzure+4, kOrange+4, kViolet+4, kSpring+4};
332*/
333 for (Int_t iStation = 0; iStation < fStations->GetEntriesFast(); ++iStation) {
334 fprintf(outfile, "=================================================================="
335 "=========\n");
336 fprintf(outfile, "Station %i\n", iStation + 1);
337 fprintf(outfile, "Sector size, cm Sector position, cm Number of pads Side "
338 "Pad size, cm\n");
339 fprintf(outfile, "------------------------------------------------------------------"
340 "----------\n");
341 TCanvas* c1 = new TCanvas(Form("station%i", iStation + 1), Form("station%i", iStation + 1), 1000, 1000);
342 c1->SetFillColor(0);
343 c1->Range(-200, -200, 200, 200);
344 c1->Range(-270, -270, 270, 270);
345 c1->Range(-50, -50, 50, 50);
346 CbmMuchStation* station = (CbmMuchStation*) fStations->At(iStation);
347 CbmMuchLayer* layer = station->GetLayer(0);
348 for (Int_t iSide = 1; iSide >= 0; iSide--) {
349 CbmMuchLayerSide* layerSide = layer->GetSide(iSide);
350 for (Int_t iModule = 0; iModule < layerSide->GetNModules(); ++iModule) {
351 CbmMuchModule* mod = layerSide->GetModule(iModule);
352 mod->SetFillStyle(0);
353 // mod->Draw();
354 if (mod->GetDetectorType() != 3 && mod->GetDetectorType() != 4) continue;
355 LOG(info) << "Det SEgmentation: " << mod->GetDetectorType() << " Station " << iStation;
356 // if(mod->GetDetectorType() != 3) continue;
358 for (Int_t iSector = 0; iSector < module->GetNSectors(); ++iSector) {
359 CbmMuchSectorRadial* sector = (CbmMuchSectorRadial*) module->GetSectorByIndex(iSector);
360 sector->AddPads();
361 sector->DrawPads();
362 } // sectors
363 } // modules
364 } // sides
365
366 // Draw a hole
367 TArc* holeArc = new TArc(0., 0., station->GetRmin());
368 // TArc* holeArc = new TArc(0.,0.,rMin);
369 holeArc->Draw();
370
371 for (Int_t iRegion = 0; iRegion < fNRegions[iStation]; ++iRegion) {
372 TArc* arc = new TArc(0., 0., fRadii[iStation].at(iRegion));
373 arc->SetLineColor(kBlack);
374 arc->SetLineWidth(2);
375 arc->SetFillStyle(0);
376 arc->Draw();
377 }
378
379 if (fDebug) {
380 c1->Print(Form("%s/station%i.eps", gSystem->DirName(fDigiFileName), iStation + 1));
381 c1->Print(Form("%s/station%i.png", gSystem->DirName(fDigiFileName), iStation + 1));
382 }
383
384 } //stations
385 fclose(outfile);
386}
387
388
389//double x0 = -a*c/(a*a+b*b), y0 = -b*c/(a*a+b*b);
390//if (c*c > r*r*(a*a+b*b)+EPS)
391// puts ("no points");
392//else {
393// double d = r*r - c*c/(a*a+b*b);
394// double mult = sqrt (d / (a*a+b*b));
395// double ax,ay,bx,by;
396// ax = x0 + b * mult;
397// bx = x0 - b * mult;
398// ay = y0 - a * mult;
399// by = y0 + a * mult;
400//}
401
ClassImp(CbmConverterManager)
friend fvec sqrt(const fvec &a)
int Int_t
bool Bool_t
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::map< Int_t, std::vector< Double_t > > fSecLy
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
std::map< Int_t, std::vector< Int_t > > fNCols
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)
std::map< Int_t, std::vector< Int_t > > fNRows
std::map< Int_t, Int_t > fNChannels
std::map< Int_t, std::vector< Double_t > > fSecLx
Int_t SegmentLayerSide(CbmMuchLayerSide *layerSide)
Double_t GetRmin() const
CbmMuchLayer * GetLayer(Int_t iLayer) const
Double_t GetRmax() const
Int_t GetNLayers() const
Class to handle QA-objects in the online reconstruction.
Definition QaData.h:27