ModTypeRPD.cc 36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
//
// Michael Phipps
// For an explanation of the hierarchy scheme see: https://twiki.cern.ch/twiki/bin/view/Atlas/ZdcSimulation#Geometry_Implementation_Develope

#include "ModTypeRPD.hh"
30
#include "FiberSD.hh"
31

32

33
34
35
36
37
38
39
40
#include "G4GeometryManager.hh"
#include "G4SolidStore.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4LogicalBorderSurface.hh"
#include "G4LogicalSkinSurface.hh"
#include "G4OpticalSurface.hh"
#include "G4MaterialTable.hh"
41
42
#include "G4UserLimits.hh"

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

#include "G4RunManager.hh"
#include "G4SDManager.hh"

#include "G4NistManager.hh"
#include "G4CSGSolid.hh"
#include "G4Box.hh"
#include "G4Para.hh"
#include "G4Tubs.hh"
#include "G4Cons.hh"
#include "G4Orb.hh"
#include "G4Sphere.hh"
#include "G4Trd.hh"
#include "G4LogicalVolume.hh"
#include "G4PVPlacement.hh"
#include "G4SystemOfUnits.hh"
#include "G4VisAttributes.hh"
#include "G4Colour.hh"

#include <iostream>
#include <stdio.h>

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

67
ModTypeRPD::ModTypeRPD(const int cn, G4LogicalVolume* mother, G4ThreeVector* pos )
68
69
  : m_modNum( cn ),  m_pos( pos ), m_fiberDiam(new G4ThreeVector(.6,.68,.73)),
  m_logicMother( mother )
70
71
72
{
	materials = Materials::getInstance();
}
73
74
75

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

76
77
78
ModTypeRPD::ModTypeRPD(const int cn, ModTypeRPD* right)
  : m_modNum( cn )
{
79
80
	m_pos 						 = new G4ThreeVector(*right->m_pos);
	m_fiberDiam 			 = new G4ThreeVector(*right->m_fiberDiam);
81
82
83
	m_HousingThickness = right->m_HousingThickness;
	m_fiberPitch 			 = right->m_fiberPitch;
	m_tileSize 				 = right->m_tileSize;
84
85
86
87
88
	m_minWallThickness = right->m_minWallThickness;
  m_detType 				 = right->m_detType;
  OPTICAL 					 = right->OPTICAL;
  CHECK_OVERLAPS 		 = right->CHECK_OVERLAPS;
	materials					 = right->materials;
89
90
91
92
93
	m_logicMother 		 = right->m_logicMother;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

94
ModTypeRPD::ModTypeRPD()
95
96
97
98
99
  : m_modNum( 0 ), m_pos(new G4ThreeVector(0.,0.,0.)), m_fiberDiam(new G4ThreeVector(.6,.68,.73)),
   m_logicMother(NULL)
{
  materials = Materials::getInstance();
}
100
101
102
103
104
105
106
107
108
109

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

ModTypeRPD::~ModTypeRPD()
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void ModTypeRPD::Construct(){
  DefineMaterials();
110
111
112
113

	if(m_detType == "cms"){
		ConstructCMSDetector();
	}else {
114
		ConstructPanFluteDetector();
115
	}
116
117
118
119
120
121
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void ModTypeRPD::DefineMaterials()
{
122
  //----------------------------------------------
123
124
125
  // Define Materials
  //----------------------------------------------

126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	//Quartz
	m_matQuartz = materials->pQuartz;

	//Aluminum
	m_Al = materials->Al;

	//Air
	m_Air = materials->Air;

	//Polyethylene/Clad
	m_Poly = materials->Polyethylene;

	//Optical Grease
	m_Grease = materials->Grease;

	//Wavelength Shifter/Fiber
	m_PMMA = materials->PMMA;


145
146
147
148
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

149
void ModTypeRPD::ConstructPanFluteDetector()
150
151
152
153
154
155
{
	//retrieve RPD parameters
	float fiber_diam 	= m_fiberDiam->x(); // Just core for now

	char name[256];

156
  G4Colour colors[4] = { G4Colour::Cyan(),  G4Colour::Red(), G4Colour::Green(), G4Colour::Magenta() };
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

	int n_rows = 4;
	int n_columns = 4;
	int n_cycles_per_tile = (m_tileSize/fiber_diam)/n_rows;   //Divide to round down to a whole number
	int n_fibers_per_tile = n_cycles_per_tile*2*n_rows;  //The pattern will be repeated twice per tile

	//If you asked for a
	if(.707*m_minWallThickness < fiber_diam){
		m_minWallThickness = 1.414*fiber_diam;
		std::cout << "Minimum wall thickness entered is too small!!!" << std::endl;
		std::cout << "Using " << m_minWallThickness << "mm instead" << std::endl;
	}
	// If the remaining space in x leaves less than 1mm for each wall, remove a cycle and calculate
	// the new wall thickness
	calculate_wall_thickness:
	float wall_thickness = ((m_tileSize - n_fibers_per_tile*fiber_diam)/n_fibers_per_tile)*mm;
	if( wall_thickness < m_minWallThickness*mm ){
		--n_cycles_per_tile;
		n_fibers_per_tile = n_cycles_per_tile*n_rows;
		goto calculate_wall_thickness;
	}

	// Distance on center of fibers
	float pitch = wall_thickness + fiber_diam;
	// Distance in X and Z from one fiber to another diagonally from it
	float offset = pitch/2;
	// Will be filled with fiber height for each row
	float fiber_height;
	// Distance from the top of the RPD area of interest to the readout
	float distance_to_readout = 0*mm;
	// Thickness of the readout puck
	float readout_thickness = 0.1*mm;
	// Positions of the current fiber for pattern1 and pattern2
	float posx1, posz1, posy, posx2, posz2;
	// Count the number of fibers as we go along
	m_PFrpd_cnt = 0;
193
194
195
196
197
198
  // Width (x) of the RPD housing
  float housingWidth = n_columns*m_tileSize + 2*m_HousingThickness;
  // Height (y) of the RPD housing
  float housingHeight = n_rows*m_tileSize + m_HousingThickness;
  // Depth (z) of the RPD housing
  float housingDepth = (n_rows + 0.5)*m_fiberPitch + fiber_diam + 2*m_HousingThickness;
199
200
201
202
203
204

	//create some rotation matrices
	G4RotationMatrix* stripRotation = new G4RotationMatrix();
	stripRotation->rotateX(90.*deg);
	G4RotationMatrix* nullRotation = new G4RotationMatrix();

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  // Construct the housing
  m_PFrpd_housing = new G4Box( "RPDHousing", housingWidth*mm/2.0, housingHeight*mm/2.0, housingDepth*mm/2.0 );

  m_PFrpd_housingLogical = new G4LogicalVolume(m_PFrpd_housing, m_Al, "Housing_Logical");

  sprintf(name,"RPD%d_Case_Physical", m_modNum);
  m_PFrpd_housingPhysical =
    new G4PVPlacement(nullRotation,
                      G4ThreeVector(m_pos->x(),m_pos->y() - m_HousingThickness/2.0, m_pos->z() ),
                      m_PFrpd_housingLogical,
                      name,
                      m_logicMother,
                      false,
                      m_modNum,
                      CHECK_OVERLAPS);

  m_PFrpd_housingLogical->SetVisAttributes(G4Colour(1.0,1.0,1.0,0.7));//G4Colour(1.0,0.0,0.0,0.3)

223
224
225
226
227
228
229
230
231
	// The SD caps that will go on the fibers. Each fiber will get a separate SD,
	// so we wait to create the logical volume in the loop
	m_PFdetec = new G4Tubs( "m_PFdetec",
													0.0*mm,
													(fiber_diam/2.0)*mm,
													(readout_thickness/2.0)*mm ,
													0.0*deg,
													360.0*deg);

232
233
234
235
236
237
238
239
  m_PFdetecLogical =
    new G4LogicalVolume(m_PFdetec,
                        m_matQuartz,
                        "m_PFdetec_log");
  m_PFdetecLogical->SetVisAttributes(G4Colour(0.0,6.0,4.0,0.3));//G4Colour(1.0,0.0,0.0,0.3)


  // Loop over rows
240
241
242
	for(int row = 0; row < n_rows; row++){
		fiber_height = m_tileSize*(row+1) + distance_to_readout;

243
		// The fiber solid and logical volume. One length for each row
244
245
246
247
248
249
250
251
		sprintf(name,"m_PFrpd_%d", row);
		m_PFrpd[row] = new G4Tubs(name,
														0.0*mm,
														(fiber_diam/2.0)*mm,
														fiber_height*mm/2.0 ,
														0.0*deg,
														360.0*deg);

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
    sprintf(name,"m_PFrpd_log_%d",row);
    m_PFrpdLogical[row] =
      new G4LogicalVolume(m_PFrpd[row],
                          m_matQuartz,
                          name);
    m_PFrpdLogical[row]->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,10*ms));

	  m_PFrpdLogical[row]->SetVisAttributes( colors[row] );

		// Rectangular fiber channels. One length for each row
		sprintf(name,"m_PFchannel_%d", row);
		m_PFrpd_channel[row] =
      new G4Box( name,
                 (1.1*fiber_diam/2.0)*mm,
                 (1.1*fiber_diam/2.0)*mm,
                 fiber_height*mm/2.0);

		sprintf(name,"m_PFchannel_log_%d",row);
		m_PFrpd_channelLogical[row] = new G4LogicalVolume(m_PFrpd_channel[row],m_Air,name);

		m_PFrpd_channelLogical[row]->SetVisAttributes( G4Colour(0.0,0.0,1.0,0.1) );// G4Colour(0.0,0.0,1.0,0.1) or G4VisAttributes::Invisible
273
274
275
276
277
278
279
280
281
282
283

		for(int col = 0; col < n_columns; col++){
			//Now we're in the realm of working on a single tile
			//we have to cycle through the two patterns until the tile
			//is filled in X
			for(int cycle = 0; cycle < n_cycles_per_tile; cycle++){

				for(int fiber = 0; fiber < n_columns; fiber++){
					// !!!!!!!Position calculations assume an even number of rows and columns!!!!!!! //////

					//Start at RPD center + tile width* number of tiles + cycle number * cycle width + stack number in cycle * pitch
284
					posx1 = m_tileSize*((n_columns/2) - col ) - (cycle*n_columns*pitch) - fiber*pitch - pitch/4;  //ARIC ADDED - pitch/4
285
286
287
					posx2 = posx1 - offset;

					//Start at Z center - half the stack depth + moving front to back and looping back to front
288
289
					posz1 = - pitch*(n_columns-0.5)/2 + pitch*((row + fiber	  )%4);
					posz2 = - pitch*(n_columns-0.5)/2 + pitch*((row + fiber + 2)%4) + offset; //Pattern is offset by 2
290
291

					//Start at RPDY center + distance to bottom of top tile + half the fiber height
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
					posy = ((n_rows/2 - 1) - row)*m_tileSize + fiber_height/2 + m_HousingThickness/2;


          //----------------------- Place the fiber channels -----------------------//
          sprintf(name,"m_PFchannel_pyhs_%d_%d_%d_%d_0",row,col,cycle,fiber);
          m_PFrpd_channelPhysical[m_PFrpd_cnt] =
            new G4PVPlacement(stripRotation,
                              G4ThreeVector(posx1*mm, posy*mm, posz1*mm),
                              m_PFrpd_channelLogical[row],
                              name,
                              m_PFrpd_housingLogical,
                              false,
                              m_PFrpd_cnt,
                              CHECK_OVERLAPS);

          sprintf(name,"m_PFchannel_pyhs_%d_%d_%d_%d_1",row,col,cycle,fiber);
          m_PFrpd_channelPhysical[m_PFrpd_cnt+1] =
            new G4PVPlacement(stripRotation,
                              G4ThreeVector(posx2*mm, posy*mm, posz2*mm),
                              m_PFrpd_channelLogical[row],
                              name,
                              m_PFrpd_housingLogical,
                              false,
                              m_PFrpd_cnt+1,
                              CHECK_OVERLAPS);
317
318
319
320
321
322
323

					//----------------------- Place the rods -----------------------//

					sprintf(name,"m_PFrpd_pyhs_%d_%d_%d_%d_0",row,col,cycle,fiber);
					m_PFrpdPhysical[m_PFrpd_cnt] =
						new G4PVPlacement(stripRotation,
															G4ThreeVector(posx1*mm, posy*mm, posz1*mm),
324
															m_PFrpdLogical[row],
325
															name,
326
															m_PFrpd_housingLogical,
327
328
329
330
331
332
333
334
															false,
															m_PFrpd_cnt,
															CHECK_OVERLAPS);

					sprintf(name,"m_PFrpd_pyhs_%d_%d_%d_%d_1",row,col,cycle,fiber);
					m_PFrpdPhysical[m_PFrpd_cnt+1] =
						new G4PVPlacement(stripRotation,
															G4ThreeVector(posx2*mm, posy*mm, posz2*mm),
335
															m_PFrpdLogical[row],
336
															name,
337
															m_PFrpd_housingLogical,
338
339
340
341
															false,
															m_PFrpd_cnt+1,
															CHECK_OVERLAPS);

342
					//----------------------- Place the photodector volumes -----------------------//
343
344
345

					sprintf(name,"photo_det_phys_%d_%d_%d_%d_0",row,col,cycle,fiber);
					m_PFdetecPhysical[m_PFrpd_cnt] =
346
347
348
						new G4PVPlacement(stripRotation,
															G4ThreeVector( posx1*mm, 2.0*m_tileSize*mm + m_HousingThickness/2.0, posz1*mm ),
															m_PFdetecLogical,
349
															name,
350
															m_PFrpd_housingLogical,
351
352
353
354
355
356
															false,
															m_PFrpd_cnt,
															CHECK_OVERLAPS);

					sprintf(name,"photo_det_phys_%d_%d_%d_%d_1",row,col,cycle,fiber);
					m_PFdetecPhysical[m_PFrpd_cnt+1] =
357
358
359
						new G4PVPlacement(stripRotation,
															G4ThreeVector(posx2*mm, 2.0*m_tileSize*mm + m_HousingThickness/2.0, posz2*mm),
															m_PFdetecLogical,
360
															name,
361
															m_PFrpd_housingLogical,
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
															false,
															m_PFrpd_cnt+1,
															CHECK_OVERLAPS);

					m_PFrpd_cnt++;
					m_PFrpd_cnt++;

				}//end fiber
			}//end cycle
		}//end column
	}//end row


	//----------------------------------------------
	// SD and Scoring Volumes
	//----------------------------------------------


	G4SDManager* SDman = G4SDManager::GetSDMpointer();

	//Note one SD object for each module
	char fiberSDname[256];
384
	sprintf( fiberSDname, "RPD%d_SD", m_modNum);
385
386
387
388

	FiberSD* aFiberSD = new FiberSD( fiberSDname, m_modNum, OPTICAL );
	aFiberSD->HistInitialize();
	SDman->AddNewDetector( aFiberSD );
389
  for(int i = 0; i < n_rows; i++){
390
391
	   m_PFrpdLogical[i]->SetSensitiveDetector( aFiberSD );
   }
392
393
394
395
396

	std::cout << "Prototype RPD construction finished: SD name " << fiberSDname << std::endl;

}

397
398
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

399
void ModTypeRPD::ConstructCMSDetector()
400
{
401
402
	bool test_tile = false;

403
	if(test_tile){
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
		for(int i =0;i<8;i++){
		rpd_comp[i]=false;
		}
	}
	else for(int i =0;i<8;i++){
		rpd_comp[i]=true;
		}

	// RPD components
	bool tile_flag = rpd_comp[0];				// quartz tiles
	bool fiber_flag = rpd_comp[1];			// readout fibers
	bool cladding_flag = rpd_comp[2];		// fiber cladding
	bool grease_flag = rpd_comp[3];			// optical grease
	bool foil_flag = rpd_comp[4];				// aluminum foil
	bool fr_bck_flag = rpd_comp[5]; 		// front and back aluminum casing
	bool vertical_flag = rpd_comp[6]; 	// veritcal aluminum dividers
	bool air_detec_flag = rpd_comp[7];	// photo detectors

422

423

424
	//retrieve RPD parameters
425
426
427
428
429
430
  float tileX 		= 20;
  float tileY 		= 20;
  float tileZ 		= 20;
  float halfX_gap 	= (1.58/2)*mm;
	float fiber_diam 	= 1*mm;
	float foil_thickness 	= 0.016*mm;
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447


	//manually create some RPD parameters
	float halfY_gap 	= (2.5*foil_thickness/2)*mm;
	float hole_center_offset = 0.05;
	float case_thickness = 0.9*2.0*halfX_gap;
	float core_diam;
	float grease_offset;
	if(grease_flag) grease_offset = 0.05;
	else grease_offset = 0.0;

	if(cladding_flag) core_diam = 0.970*(fiber_diam)*mm;
	else 							core_diam = (fiber_diam)*mm;

	float fiberHeightY[4];
	float foilHeightY[4];

448
  char name[256];
449
450
451
452
453
454
455

	//create some rotation matrices
	G4RotationMatrix* stripRotation = new G4RotationMatrix();
	stripRotation->rotateX(90.*deg);
	G4RotationMatrix* nullRotation = new G4RotationMatrix();

  // Option to switch on/off checking of volumes overlaps
456

457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476

	//create tile that has 4 holes to be used repeatedly later
  m_tile_no_fiber_hole = new G4Box("tile_no_hole",(tileX/2)*mm, (tileY/2)*mm, (tileZ/2)*mm);
	m_fiber_subtract = new G4Tubs( "fiber_sub",
						0.0*mm,
						((fiber_diam/2.0)+ grease_offset )*mm, //1mm diameter
						tileY*mm ,
						0.0*deg,
						360.0*deg);

	m_tile = new G4SubtractionSolid("tile",m_tile_no_fiber_hole,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 1*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset)*mm));
  m_tile = new G4SubtractionSolid("tile",m_tile,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 2*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset )*mm));
	m_tile = new G4SubtractionSolid("tile",m_tile,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 3*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset )*mm));
	m_tile = new G4SubtractionSolid("tile",m_tile,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 4*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset )*mm));


  m_tileLogical	 = new G4LogicalVolume(m_tile, m_matQuartz, "tile_Logical");

  G4VisAttributes* quartzColor  = new G4VisAttributes(  G4Colour::Cyan());//
	//quartzColor->SetForceSolid(true);
477
478
	m_tileLogical->SetVisAttributes( quartzColor );

479
	int cn = 0, cn_fiber = 0;
480

481
482
483
	float RPD_centerX = m_pos->getX();
	float RPD_centerY = m_pos->getY();
	float RPD_centerZ = m_pos->getZ();
484

485
486
	float RPD_startX = RPD_centerX + 3*halfX_gap + 1.5*tileX;
	float RPD_startY = RPD_centerY + 3*halfY_gap + 1.5*tileY;
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546


//positioning variables
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

float factor1 = 1.5;
float hole_shift		= grease_offset + hole_center_offset;

float tileZcenter[4];
for(int i=0; i < 4; i++){
	tileZcenter[i] = RPD_centerZ + (i * (factor1*fiber_diam + foil_thickness) );
}
float fiberZcenter[4];
for(int i=0; i < 4; i++){
	fiberZcenter[i] = tileZcenter[i] + tileZ/2.0 - fiber_diam/2.0 - hole_shift;
}

float foil_gap = (fiberZcenter[1]-(fiber_diam/2.0)) - (fiberZcenter[0] + (fiber_diam/2.0));

float foilZcenter[4];
for(int i=0; i < 4; i++){
	foilZcenter[i] = fiberZcenter[i] + fiber_diam/2.0 + foil_gap/2.0;
}

float final_foil_pos = foilZcenter[3]+foil_thickness/2.0;
float assembly_midZ = RPD_centerZ + (final_foil_pos - (RPD_centerZ + (tileZ/2.0)))/2.0;
float half_Z_length = final_foil_pos-assembly_midZ;


int fiber_cnt=0;

//create fibers/cladding/grease with correct lengths
for(int k=0;k<4;k++) {
	fiberHeightY[k]=((k+1)*tileY)+(k*2*halfY_gap);

	sprintf(name,"fiber_a %d", k);
	m_fiber[k] 		= new G4Tubs( name,
						0.0*mm,
						(core_diam/2.0)*mm, //1mm diameter
						fiberHeightY[k]*mm/2.0 ,
						0.0*deg,
						360.0*deg);
if(grease_flag){
	sprintf(name,"fibergrease_a %d", k);
  m_fibergrease[k] 		= new G4Tubs( name,
						(fiber_diam/2.0)*mm,
						((fiber_diam+grease_offset)/2.0)*mm,
						fiberHeightY[k]*mm/2.0 ,
						0.0*deg,
						360.0*deg);
					}

if(cladding_flag){
	sprintf(name,"fiberclad_a %d", k);
	m_fiberclad[k] 		= new G4Tubs( name,
							(core_diam/2.0)*mm,
							((fiber_diam)/2.0)*mm,
							fiberHeightY[k]*mm/2.0 ,
							0.0*deg,
547
							360.0*deg);
548
549
550
551
552
553
554
555
556
						}

if(grease_flag){
	sprintf(name,"fibergreaseLogical_a %d", k);

	m_fibergreaseLogical[k] 	= new G4LogicalVolume(m_fibergrease[k]
						,m_Grease,//m_Poly
						name);
	m_fibergreaseLogical[k]->SetVisAttributes( G4Colour(1,1,1,0.3) );//G4VisAttributes::Invisible
557
	}
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

if(cladding_flag){
	sprintf(name,"fibercladLogical_a %d", k);

	m_fibercladLogical[k] 	= new G4LogicalVolume(m_fiberclad[k]
						,m_Poly,//m_Poly
						name);
	m_fibercladLogical[k]->SetVisAttributes( G4Colour(1,0,0,0.2));//G4VisAttributes::Invisible
	}
}

for(int i=0;i<4;i++) {
	for(int j=0;j<4;j++) {
		for(int k=0;k<4;k++) {
				sprintf(name,"fiberLogical_%d_%d_%d",k,j,i);

						m_fiberLogical[fiber_cnt] 	= new G4LogicalVolume(m_fiber[k]
											,m_PMMA,
											name);
						m_fiberLogical[fiber_cnt]->SetVisAttributes( G4Colour(0.0,0.0,1.0,0.2) );

						m_fiberLogical[fiber_cnt]->SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,10*ms));

							fiber_cnt++;
					}
				}
			}

// create alum containment

//create foil sections
for(int k=0;k<4;k++) {
foilHeightY[k]=(2*(k+1)-2) * halfY_gap + (k+1)*tileY;
sprintf(name,"foil_V %d", k);

m_foilV[k] 		= new G4Box(name,(tileX/2.0)*mm, (foilHeightY[k]/2.0)*mm, (0.75*foil_thickness/2.0)*mm);//

sprintf(name,"foilVlog %d", k);

m_foilVLogical[k] 	= new G4LogicalVolume(m_foilV[k]
					,m_Al,
					name);
m_foilVLogical[k]->SetVisAttributes(G4Colour(0.9,0.0,0.0,0.4));//G4VisAttributes::Invisible
}


m_foilVfront 		= new G4Box("m_foilVfront",(tileX/2.0)*mm, (tileY/2.0)*mm, (0.75*foil_thickness/2.0)*mm);//
m_foilVfrontLogical 	= new G4LogicalVolume(m_foilVfront
				,m_Al,
				"foilVfrntlog");
m_foilVfrontLogical->SetVisAttributes( G4Colour(0.9,0.0,0.0,0.4) );//


m_foilH 			= new G4Box("foil_H",(tileX/2.0)*mm, (0.75*foil_thickness/2.0)*mm, ((tileZ+(foil_gap)-hole_center_offset)/2.0) *mm) ;// foil/2.0
m_foilHLogical 	= new G4LogicalVolume(m_foilH
				,m_Al,
				"foil_H_log");
m_foilHLogical->SetVisAttributes( G4Colour(0.9,0.0,0.0,0.4));//


m_foilHtop 			= new G4Box("foil_H_top",(tileX/2.0)*mm, (0.75*foil_thickness/2.0)*mm, ((tileZ)/2.0) *mm) ;//+(foil_gap)-hole_center_offset
m_foilHtop_hole = new G4SubtractionSolid("foil_H_top_hole",m_foilHtop,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 1*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset)*mm));
m_foilHtop_hole = new G4SubtractionSolid("foil_H_top_hole",m_foilHtop_hole,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 2*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset )*mm));
m_foilHtop_hole = new G4SubtractionSolid("foil_H_top_hole",m_foilHtop_hole,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 3*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset )*mm));
m_foilHtop_hole = new G4SubtractionSolid("foil_H_top_hole",m_foilHtop_hole,m_fiber_subtract,stripRotation, G4ThreeVector(( tileX/2.0 - 4*(tileX/5)  )*mm,0,(tileZ/2.0 - fiber_diam/2.0 - grease_offset - hole_center_offset )*mm));

m_foilHtopLogical 	= new G4LogicalVolume(m_foilHtop_hole
				,m_Al,
				"foil_Htop_log");
m_foilHtopLogical->SetVisAttributes(  G4Colour(0.9,0.0,0.0,0.4) );//

//create alum case pieces

//vertical dividers
m_AlcaseV 			= new G4Box("case_V",(case_thickness/2.0)*mm, ((fiberHeightY[3]+case_thickness)/2.0)*mm, ((final_foil_pos)-(RPD_centerZ-(tileZ/2.0))+case_thickness)/2.0 *mm );
m_AlcaseVLogical 	= new G4LogicalVolume(m_AlcaseV
					,m_Al,
					"case_V_log");
m_AlcaseVLogical->SetVisAttributes( G4Colour(0.0,0.0,0.9,0.4));

//front and back plate
m_Alcase 			= new G4Box("case_fr_bck",((4*tileX+8*halfX_gap+case_thickness)/2.0)*mm, ((fiberHeightY[3]+case_thickness)/2.0)*mm, ((0.99*case_thickness)/2.0)*mm );
m_AlcaseLogical 	= new G4LogicalVolume(m_Alcase
					,m_Al,
					"case_fr_bck_log");
m_AlcaseLogical->SetVisAttributes( G4Colour(0.0,0.0,0.9,0.4));//


///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
// if Optical is turned on we need to build air detector above each fibers

650
if ( OPTICAL ){
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685

float air_detect_thickness = 0.1;
float correction = 0.0;

m_air_detect = new G4Tubs( "air_detect",
					0.0*mm,
					((core_diam/2.0)-correction)*mm,
					((air_detect_thickness/2.0))*mm ,
					0.0*deg,
					360.0*deg);


int air_detecT_cnt = 0;
for(int i=0;i<4;i++) {
	for(int j=0;j<4;j++) {
		for(int k=0;k<4;k++) {
			sprintf(name,"photo_detect_log_%d_%d_%d",i, j, k);
			m_air_detect_Logical[air_detecT_cnt]	 = new G4LogicalVolume(m_air_detect, m_PMMA, name);
			m_air_detect_Logical[air_detecT_cnt]->SetVisAttributes( G4Colour(0.0,1.0,0.0,5.0) );

			//sprintf(name,"photo_detect %d", k);
			sprintf(name,"photo_detect_phys_%d_%d_%d",i, j, k);//comment

			if(air_detec_flag){

			m_air_detectPhysical[air_detecT_cnt]		  = new G4PVPlacement(
					nullRotation,
					G4ThreeVector(( 0.0 ) *mm ,
									 ( 0.0 ) 	 *mm ,
									 (fiberHeightY[k]/2 - (air_detect_thickness/2.0) - correction)*mm),
					m_air_detect_Logical[air_detecT_cnt],
					name,
					m_fiberLogical[air_detecT_cnt],
					false,
					air_detecT_cnt,
686
					CHECK_OVERLAPS);
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716



					air_detecT_cnt++;

				}
			}
		}
	}
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

//place vertical dividers
for(int k=0;k<5;k++) {

	sprintf(name,"case_V %d", k);

	if(vertical_flag){
		m_AlcaseVPhysical[k] = new G4PVPlacement(
						nullRotation,
						G4ThreeVector((( 	(RPD_startX + tileX/2.0) + halfX_gap  ) - k*(2*halfX_gap+tileX)  ) 	*mm ,
													 (RPD_centerY )   	*mm ,
													 (assembly_midZ )			*mm),
						m_AlcaseVLogical,
						name,
						m_logicMother,
						false,
						k,
717
						CHECK_OVERLAPS);
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
						}
}
//place front/back plate
for(int k=0;k<2;k++) {

	sprintf(name,"case_fr_bck %d", k);

	if(fr_bck_flag){
		m_AlcasePhysical[k] = new G4PVPlacement(
						nullRotation,
						G4ThreeVector(  (RPD_centerX) 	*mm ,
														(RPD_centerY)   	*mm ,
													 (assembly_midZ - half_Z_length - case_thickness + 2.0*k*(half_Z_length+case_thickness) )			*mm),
						m_AlcaseLogical,
						name,
						m_logicMother,
						false,
						k,
736
						CHECK_OVERLAPS);
737
738
739
740
741
742
743
744
745
746
747
					}
}
//place tiles, fibers, foil
  for(int j=0;j<4;j++) {
    for(int i=0;i<4;i++) {



		if(tile_flag){
			sprintf(name,"tilephys_%d_%d", i,j);
    	m_tilePhysical[i][j] = new G4PVPlacement(
748
							nullRotation,
749
750
751
							G4ThreeVector( ( 	RPD_startX - (i*( tileX+(2*halfX_gap) ) ) )  	*mm ,
										   			( 	RPD_startY - (j*( tileY+(2*halfY_gap) ) ) )	*mm ,
											 					tileZcenter[j] *mm),
752
753
754
755
756
							m_tileLogical,
							name,
							m_logicMother,
							false,
							cn,
757
							CHECK_OVERLAPS);
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
						}



			if(foil_flag){
				sprintf(name,"foil_V_%d_%d",  i,j);
				m_foilVPhysical[i][j] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector( ( 	RPD_startX - (j*( tileX+(2*halfX_gap) ) ) )  	*mm ,
											   		   ( RPD_startY + tileY/2 - (fiberHeightY[i]/2)  ) 		*mm ,
												 			 ( foilZcenter[i]) *mm),
								m_foilVLogical[i],
								name,
								m_logicMother,
								false,
								cn,
774
								CHECK_OVERLAPS);
775
776
777
778
779
780
781
782
783
784
785
786
787

			sprintf(name,"foil_V_front_%d_%d",  i,j);

				m_foilVfrontPhysical[i][j] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector( ( 	RPD_startX - (i*( tileX+(2*halfX_gap) ) ) )  	*mm ,
											   		  ( 	RPD_startY - (j*( tileY+(2*halfY_gap) ) ) ) 		*mm ,
												 			 ( tileZcenter[j] - tileZ/2.0 -foil_gap/2.0) *mm),//fiberZcenter[i] + fiber_diam/2.0 + foil_gap/2.0;
								m_foilVfrontLogical,
								name,
								m_logicMother,
								false,
								cn,
788
								CHECK_OVERLAPS);
789
790
791
792
793
794
795
796
797
798
799
800
801
802


			sprintf(name,"foil_H_%d_%d", i,j);

				m_foilHPhysical[i][j] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector( ( 	RPD_startX - (j*( tileX+(2*halfX_gap) ) ) )  	*mm ,
											   		   ( RPD_startY + tileY/2 + 1.3*halfY_gap - (i+1) * (tileY + 2 * halfY_gap ))   		*mm ,
												 			 (tileZcenter[i]  - hole_center_offset/2.0)			*mm),
								m_foilHLogical,
								name,
								m_logicMother,
								false,
								i,
803
								CHECK_OVERLAPS);
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818

			if(i==0){

			sprintf(name,"foil_H_top_%d", j);

				m_foilHtopPhysical[j] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector( ( 	RPD_startX - (j*( tileX+(2*halfX_gap) ) ) )  	*mm ,
											   		   (RPD_startY + tileY/2 + 1.5*foil_thickness)   		*mm ,
												 			 (tileZcenter[0] *mm)),
								m_foilHtopLogical,
								name,
								m_logicMother,
								false,
								j,
819
								CHECK_OVERLAPS);
820
821
822
823
824
825
826
							}
				}

		for(int k=0;k<4;k++) {
			if(fiber_flag){
				sprintf(name,"fiberphys_%d_%d_%d",i, j, k);
				m_fiberPhysical[cn_fiber]		  = new G4PVPlacement(
827
							stripRotation,
828
							G4ThreeVector( ( RPD_startX - (j*( tileX+(2*halfX_gap) ) ) ) + (tileX/2) - ((i+1)*tileX/5) *mm ,
829
										   ( RPD_startY + tileY/2 - (fiberHeightY[k]/2)  )	 *mm ,
830
831
832
833
834
835
											 (fiberZcenter[k]) *mm),
							m_fiberLogical[cn_fiber],
							name,
							m_logicMother,
							false,
							cn_fiber,
836
							CHECK_OVERLAPS);
837
838
839
840
841
842
843
844
845
						}
			if(cladding_flag){
				sprintf(name,"cladphys_%d_%d_%d",i, j, k);
				m_fibercladPhysical[cn_fiber]		  = new G4PVPlacement(
							stripRotation,
							G4ThreeVector( ( RPD_startX - (j*( tileX+(2*halfX_gap) ) ) ) + (tileX/2) - ((i+1)*tileX/5) *mm ,
												( RPD_startY + tileY/2 - (fiberHeightY[k]/2)  )	 *mm ,
												(fiberZcenter[k]) *mm),
							m_fibercladLogical[k],
846
847
848
849
							name,
							m_logicMother,
							false,
							cn_fiber,
850
							CHECK_OVERLAPS);
851
852
853
854
855
856
857
858
859
860
861
862
863
						}
			if(grease_flag){
				sprintf(name,"greasephys_%d_%d_%d",i, j, k);
				m_fibergreasePhysical[cn_fiber]		  = new G4PVPlacement(
							stripRotation,
							G4ThreeVector( ( RPD_startX - (j*( tileX+(2*halfX_gap) ) ) ) + (tileX/2) - ((i+1)*tileX/5) *mm ,
													( RPD_startY + tileY/2 - (fiberHeightY[k]/2)  )	 *mm ,
													(fiberZcenter[k]) *mm),
							m_fibergreaseLogical[k],
							name,
							m_logicMother,
							false,
							cn_fiber,
864
							CHECK_OVERLAPS);
865
866
									}

867
868
869
							cn_fiber++;
		}

870
			//
aricct2's avatar
aricct2 committed
871
872
873
874
875
876
877
878
879
880
881
882
      // std::cout  << std:: endl << "tilex = "
			// 	<<  RPD_startX - (i*( tileX+(2*halfX_gap) ) )
			// 	<< ", tiley = "
			// 	<<  RPD_startY - (j*( tileY+(2*halfY_gap) ) )
			// 	<< ", tilez = "
			// 	<< tileZcenter[j]
			// 	<< ", ("
			// 	<< i
			// 	<< ","
			// 	<< j
			// 	<< ")"
			// 	<< std::endl << std::endl;
883
884
885


      cn++;
886
    }
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// TEST SETUP
if(test_tile){
		float testtileY = 100;
		float testtileZ = 50;
		float testgreaseY = 30;
		float testgreaseZ = 2.5;
		float testPDY = 2.5;
		float testcoreZ = 5;
		float testblckZ 	= 15;
		float offsetZ 	= testtileZ/2+testblckZ/2;
		float offsetY 	= 5;

	  m_test_tile 		= new G4Box("test_tile",(100/2)*mm, (testtileY/2)*mm, (testtileZ/2)*mm);
		m_test_alum 		= new G4Box("test_alum",(100/2)*mm, (testtileY/2)*mm, (testblckZ/2)*mm);
		m_test_wls 			= new G4Box("test_wls",(100/2)*mm, (testgreaseY/2)*mm, (testcoreZ/2)*mm);
		m_test_PD 			= new G4Box("test_PD",(100/2)*mm, (testPDY/2)*mm, (testcoreZ/2)*mm);
		m_test_clad 		= new G4Box("test_clad",(100/2)*mm, (testgreaseY/2)*mm, (testgreaseZ/2)*mm);
		m_test_grease 	= new G4Box("test_grease",(100/2)*mm, (testgreaseY/2)*mm, (testgreaseZ/2)*mm);
		m_test_block 		= new G4Box("test_blck1",(100/2)*mm, ((testgreaseY)/2)*mm, (testblckZ/2)*mm);


		m_test_tileLogical	 = new G4LogicalVolume(m_test_tile, m_matQuartz, "testtile_Logical");
		m_test_alumLogical	 = new G4LogicalVolume(m_test_alum, m_Al, "testalum_Logical");
		m_test_wlsLogical	 = new G4LogicalVolume(m_test_wls, m_PMMA, "testwls_Logical");
		m_test_PDLogical	 = new G4LogicalVolume(m_test_PD, m_PMMA, "testPD_Logical");
		m_test_cladLogical	 = new G4LogicalVolume(m_test_clad, m_Poly, "testclad_Logical");
		m_test_greaseLogical	 = new G4LogicalVolume(m_test_grease, m_Grease, "testgrease_Logical");
		m_test_blockLogical	 = new G4LogicalVolume(m_test_block, m_Al, "testblck_Logical");

		m_test_tileLogical->SetVisAttributes( G4Colour(0.0,1.0,0.0,0.3) );
		m_test_alumLogical->SetVisAttributes( G4Colour(0.8,0.0,0.0,0.3) );
		m_test_wlsLogical->SetVisAttributes( G4Colour(0.0,0.0,1.0,0.3) );
		m_test_PDLogical->SetVisAttributes( G4Colour(0.0,0.0,1.0,0.3) );
		m_test_cladLogical->SetVisAttributes( G4Colour(0.3,0.5,0.0,0.3) );
		m_test_greaseLogical->SetVisAttributes( G4Colour(0.0,0.6,0.8,0.3) );
		m_test_blockLogical->SetVisAttributes( G4Colour(0.8,0.0,0.0,0.3) );

		m_test_tilePhysical = new G4PVPlacement(
						nullRotation,
						G4ThreeVector(( 0.0  ) 	*mm ,
													 (0.0 )   	*mm ,
													 (assembly_midZ)			*mm),
						m_test_tileLogical,
						"testtilephys",
						m_logicMother,
						false,
						1,
940
						CHECK_OVERLAPS);
941
942
943
944
945
946
947
948
949
950
951

		m_test_greasePhysical[0] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector(( 0.0  ) 	*mm ,
															 (testtileY/2 + testgreaseY/2 - offsetY)   	*mm ,
															 (assembly_midZ - testcoreZ/2 - 1.5*testgreaseZ +offsetZ)			*mm),
								m_test_greaseLogical,
								"testgrease1phys",
								m_logicMother,
								false,
								0,
952
								CHECK_OVERLAPS);
953
954
955
956
957
958
959
960
961
962
963

		m_test_greasePhysical[1] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector(( 0.0  ) 	*mm ,
															 (testtileY/2 + testgreaseY/2- offsetY )   	*mm ,
															 (assembly_midZ + testcoreZ/2 + 1.5*testgreaseZ+offsetZ )			*mm),
								m_test_greaseLogical,
								"testgrease2phys",
								m_logicMother,
								false,
								1,
964
								CHECK_OVERLAPS);
965
966
967
968
969
970
971
972
973
974
975

		m_test_cladPhysical[0] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector(( 0.0  ) 	*mm ,
															 (testtileY/2 + testgreaseY/2- offsetY )   	*mm ,
															 (assembly_midZ - testcoreZ/2 - testgreaseZ/2+offsetZ )			*mm),
								m_test_cladLogical,
								"testclad1phys",
								m_logicMother,
								false,
								0,
976
								CHECK_OVERLAPS);
977
978
979
980
981
982
983
984
985
986
987

		m_test_cladPhysical[1] = new G4PVPlacement(
								nullRotation,
								G4ThreeVector(( 0.0  ) 	*mm ,
															 (testtileY/2 + testgreaseY/2- offsetY )   	*mm ,
															 (assembly_midZ+ testcoreZ/2 + testgreaseZ/2+offsetZ )			*mm),
								m_test_cladLogical,
								"testclad2phys",
								m_logicMother,
								false,
								1,
988
								CHECK_OVERLAPS);
989
990
991
992
993
994
995
996
997
998
999

		m_test_wlsPhysical = new G4PVPlacement(
							nullRotation,
							G4ThreeVector(( 0.0  ) 	*mm ,
														 (testtileY/2 + testgreaseY/2- offsetY )   	*mm,
														 (assembly_midZ + offsetZ)			*mm),
							m_test_wlsLogical,
							"testtilewls",
							m_logicMother,
							false,
							1,
1000
							CHECK_OVERLAPS);
For faster browsing, not all history is shown. View entire blame