BOSS 6.6.4.p01
BESIII Offline Software System
Loading...
Searching...
No Matches
EventDisplay/BesVisLib/BesVisLib-00-04-03/src/EmcROOTGeo.cxx
Go to the documentation of this file.
1//$id$
2/*
3 * 2004/11/29 Zhengyun You Peking University
4 * Emc Geometry General for EventDisplay
5 *
6 * 2004/12/11 Zhengyun You Peking University
7 * named from EmcGeo to EmcROOTGeo
8 * inherit from class SubDetectorROOTGeo
9 *
10 * 2005/04/04 Zhengyun You Peking University
11 * Emc End geometry added
12 */
13
14using namespace std;
15
16#include <string>
17#include <fstream>
18#include <iostream>
19#include <sstream>
20#include <vector>
21#include <iomanip>
22
23#include <TGeoManager.h>
24#include <TGeoArb8.h>
25#include <TMath.h>
26
28#include "Identifier/EmcID.h"
29#include "BesVisLib/BesEvent.h"
30#include "BesVisLib/BesView.h"
32
33
36{
37 // Default constructor.
38 m_kPhiEc = 96;
39 m_kThetaEc = 6;
40 m_kSectorEc = 16;
41 m_kNbEc = 35;
42 m_kRealNbEc = 30;
43
44 for (int part = 0; part < m_kPart; part++) {
45 for (int phi = 0; phi < m_kPhiBr; phi++) {
46 m_NodePhi[part][phi] = 0;
47 for (int theta = 0; theta < m_kThetaBr; theta++) {
48 m_NodeTheta[part][phi][theta] = 0;
49 m_NodeTheta2[part][phi][theta] = 0;
50 m_PhysicalCrystal[part][phi][theta] = 0;
51 m_PhysicalCrystal2[part][phi][theta] = 0;
52 m_Emc2DCrystal[part][phi][theta] = 0;
53 }
54 }
55 }
56 m_PhyNodeOrgArray = new TObjArray();
57
58 m_EmcColor = 4;
59 m_partColor = 4;
60 m_phiColor = 4;
61 m_thetaColor = 4;
62 m_brCrystalColor = 4;
63 m_ecCrystalColor = 7;
64}
65
67{ }
68
69void
70EmcROOTGeo::InitFromGDML( const char *gdmlFile, const char *setupName )
71{
72 m_ROOTGeoInit = 2;
73
74 ReadGdml(gdmlFile, setupName);
75 SetNode();
76}
77
78void
79EmcROOTGeo::InitFromROOT( TGeoVolume *vol )
80{
81 m_ROOTGeoInit = 1;
82
83 SetVolumeEmc(vol);
84 SetNode();
85}
86
87void
89{
90 if (m_ROOTGeoInit != 1 && m_ROOTGeoInit != 2) {
91 cout << "EmcROOTGeo::Init2DGeometry, ROOT Geometry not Initialized yet!" << endl;
92 return;
93 }
94 m_2DGeoInit = 1;
95
96 Double_t local[3] = {0.0, 0.0, 0.0};
97 Double_t master[3] = {0.0, 0.0, 0.0};
98 //Int_t nPoints = 8;
99 //Double_t P[300] = {0.0};
100 //Double_t center[3] = {0.0, 0.0, 0.0};
101 TString name;
102 TString title;
103
104 // Emc crystals
105 for (int part = 0; part < GetPartNb(); part++) {
106 for (int theta = 0; theta < GetThetaNb(part); theta++) {
107 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
108 TGeoPhysicalNode *phyNode = 0;
109 phyNode = GetPhysicalCrystal(part, phi, theta);
110 if (part == 1) name = TString("Barrel");
111 else {
112 if (part == 0) name = TString("EastEc");
113 else if (part == 2) name = TString("WestEc");
114 }
115 name = TString("Emc Part");
116 name += part;
117 name += " Theta";
118 if (part == 1) name += m_kThetaBr - 1 - theta;
119 else name += theta;
120 name += " Phi";
121 name += phi;
122
123 char data[100];
124 sprintf(data, "Emc part %i, #theta %i, #phi %i", part, theta, phi);
125 title = TString( data );
126
127 TGeoArb8 *crystalShape = (TGeoArb8*)phyNode->GetShape();
128 Double_t *localArb8Point, masterArb8Point[24*2];
129 localArb8Point = crystalShape->GetVertices();
130 for (Int_t i = 0; i < 8; i++) {
131 local[0] = localArb8Point[2*i];
132 local[1] = localArb8Point[2*i+1];
133 if (i < 4) local[2] = crystalShape->GetDz() * (-1.0);
134 else local[2] = crystalShape->GetDz();
135
136 phyNode->GetMatrix(-1*phyNode->GetLevel())->LocalToMaster(local, &master[0]);
137 // transform to top
138 for (Int_t j = 0; j < 3; j++) {
139 masterArb8Point[3*i+j] = master[j];
140 }
141 }
142
143 TGeoPhysicalNode *phyNode2 = 0;
144 phyNode2 = GetPhysicalCrystal2(part, phi, theta);
145 if (phyNode2 != 0) {
146 crystalShape = (TGeoArb8*)phyNode2->GetShape();
147 localArb8Point = crystalShape->GetVertices();
148 for (Int_t i = 0; i < 8; i++) {
149 local[0] = localArb8Point[2*i];
150 local[1] = localArb8Point[2*i+1];
151 if (i < 4) local[2] = crystalShape->GetDz() * (-1.0);
152 else local[2] = crystalShape->GetDz();
153 phyNode2->GetMatrix(-1*phyNode->GetLevel())
154 ->LocalToMaster(local, &master[0]); // transform to top
155 for (Int_t j = 0; j < 3; j++) {
156 masterArb8Point[24+3*i+j] = master[j];
157 }
158 }
159 }
160
161 if (phyNode2 == 0)
162 m_Emc2DCrystal[part][phi][theta] =
163 new Emc2DCrystal(name, title, 8, &masterArb8Point[0], part, theta);
164 else
165 m_Emc2DCrystal[part][phi][theta] =
166 new Emc2DCrystal(name, title, 16, &masterArb8Point[0], part, theta);
167 }
168 }
169 }
170}
171
172void
174{
175 // Set NodePhi
176 if (m_ROOTGeoInit == 2) { // from GDML
177
178 m_Emc = GetTopVolume();
179 if (!m_Emc) std::cout << "m_Emc = 0" << std::endl;
180
181 }
182 else if (m_ROOTGeoInit == 1) { // from ROOT object
183
184 for (int part = 0; part < m_kPart; part++) {
185 int ipart = 0;
186 if (part == 1) ipart = 2;
187 if (part == 0) ipart = 1;
188
189 m_NodePart[part] = m_Emc->GetNode(ipart);
190
191 if (part == 1) {
192 for (int phi = 0; phi < m_kPhiBr; phi++) {
193 int iphi = 0;
194 iphi = 308 - phi;
195
196 m_NodePhi[part][phi] = GetPart(part)->GetVolume()->GetNode(iphi);
197 }
198 }
199 else {
200 int endphilist[16]= {15,7,14,6,13,12,11,10,9,8,5,4,3,2,1,0};
201 int endphipos[16] = {15,14,13,12,11,10,3,1,9,8,7,6,5,4,2,0};
202 //pos of phi in endworld
203 for (int sector = 0; sector < m_kSectorEc; sector++) {
204 m_NodePhi[part][sector] =
205 GetPart(part)->GetVolume()->GetNode(endphipos[sector]);
206 }
207 }
208 }
209 }
210
211 // Set NodeTheta
212 for (int phi = 0; phi < m_kPhiBr; phi++) {
213 int theta=0;
214 for (int idaughter = 0; idaughter< GetPhi(1, phi)->GetNdaughters(); idaughter++) {
215 TString name = GetPhi(1, phi)->GetDaughter(idaughter)->GetName();
216 if (name.Contains("logicalBSCCasing")){
217
218 m_NodeTheta[1][phi][theta] = GetPhi(1, phi)->GetDaughter(idaughter);
219 theta++;
220 }
221 }
222 }
223
224 for (int part = 0; part < m_kPart; part++) {
225 if (part == 1) continue;
226 for (int sector = 0; sector < m_kSectorEc; sector++) {
227 for (int nb = 0; nb < m_kNbEc; nb++) {
228 int theta, phi;
229 if (nb < m_kRealNbEc) {
230 ComputeThetaPhi(part, sector, nb, theta, phi);
231 m_NodeTheta[part][phi][theta] = GetPhi(part, sector)->GetDaughter(nb);
232// std::cout << part << " sector " << sector << " nb " << nb
233// << " phi " << phi << " theta " << theta
234// << " name " << m_NodeTheta[part][phi][theta]->GetName() << std::endl;
235 }
236 else {
237 ComputeThetaPhi(part, sector, ComputeEndCopyNb(nb), theta, phi);
238 m_NodeTheta2[part][phi][theta] = GetPhi(part, sector)->GetDaughter(nb);
239// std::cout << "Additional " << part << " sector " << sector << " nb " << nb
240// << " phi " << phi << " theta " << theta
241// << " name " << m_NodeTheta2[part][phi][theta]->GetName() << std::endl;
242 }
243 }
244 }
245 }
246
247 //std::cout << "EmcROOTGeo::SetNode, end of set node" << std::endl;
248}
249
250void
252{
253
254 //-------------------------------------------------------------
255 //Barrel
256 //GetLogicalVolume
257 TGeoVolume *logicRear,*logicOrgGlass,*logicRearCasing,*logicAlPlate,*logicPD,*logicPreAmpBox,*logicAirInPABox,*logicHangingPlate,*logicWaterPipe;
258 TGeoVolume *logicCable,*logicOCGirder,*logicSupportBar,*logicSupportBar1,*logicEndRing,*logicGear,*logicTaperRing1,*logicTaperRing2,*logicTaperRing3;
259
260
261 logicRear = GetLogicalVolume("logicalRearBox");
262 logicOrgGlass = GetLogicalVolume("logicalOrganicGlass");
263 logicRearCasing = GetLogicalVolume("logicalRearCasing");
264 logicAlPlate = GetLogicalVolume("logicalAlPlate");
265 logicPD = GetLogicalVolume("logicalPD");
266 logicPreAmpBox = GetLogicalVolume("logicalPreAmpBox");
267 logicAirInPABox = GetLogicalVolume("logicalAirInPABox");
268 logicHangingPlate = GetLogicalVolume("logicalHangingPlate");
269 logicWaterPipe = GetLogicalVolume("logicalWaterPipe");
270
271 for (int i = 0; i < 44; i++){
272
273 std::ostringstream osnameBSCCable1;
274 osnameBSCCable1 << "logicalBSCCable_1_"<<i;
275 logicCable = GetLogicalVolume( osnameBSCCable1.str() );
276 if (logicCable)
277 logicCable->SetVisibility(0);
278
279 std::ostringstream osnameBSCCable2;
280 osnameBSCCable2 << "logicalBSCCable_2_"<<i;
281 logicCable = GetLogicalVolume( osnameBSCCable2.str() );
282 if (logicCable)
283 logicCable->SetVisibility(0);
284
285 std::ostringstream osnameOCGirder1;
286 osnameOCGirder1 <<"logicalOpenningCutGirder_1_"<<i;
287 logicOCGirder = GetLogicalVolume( osnameOCGirder1.str() );
288 if (logicOCGirder)
289 logicOCGirder->SetVisibility(0);
290
291 std::ostringstream osnameOCGirder2;
292 osnameOCGirder2 <<"logicalOpenningCutGirder_2_"<<i;
293 logicOCGirder = GetLogicalVolume( osnameOCGirder2.str() );
294 if (logicOCGirder)
295 logicOCGirder->SetVisibility(0);
296
297 std::ostringstream osnameOCGirder3;
298 osnameOCGirder3 <<"logicalOpenningCutGirder_3_"<<i;
299 logicOCGirder = GetLogicalVolume( osnameOCGirder3.str() );
300 if (logicOCGirder)
301 logicOCGirder->SetVisibility(0);
302
303 std::ostringstream osnameOCGirder4;
304 osnameOCGirder4 <<"logicalOpenningCutGirder_4_"<<i;
305 logicOCGirder = GetLogicalVolume( osnameOCGirder4.str() );
306 if (logicOCGirder)
307 logicOCGirder->SetVisibility(0);
308 }
309
310 //-------------------------------------------------------------
311 //Support system
312 logicSupportBar = GetLogicalVolume("logicalSupportBar0");
313 logicSupportBar1 = GetLogicalVolume("logicalSupportBar1");
314 logicEndRing = GetLogicalVolume("logicalEndRing");
315 logicGear = GetLogicalVolume("logicalGear");
316 logicTaperRing1 = GetLogicalVolume("logicalTaperRing1");
317 logicTaperRing2 = GetLogicalVolume("logicalTaperRing2");
318 logicTaperRing3 = GetLogicalVolume("logicalTaperRing3");
319
320 if (logicRear)
321 logicRear->SetVisibility(0);
322 if (logicOrgGlass)
323 logicOrgGlass->SetVisibility(0);
324 if (logicRearCasing)
325 logicRearCasing->SetVisibility(0);
326 if (logicAlPlate)
327 logicAlPlate->SetVisibility(0);
328 if (logicPD)
329 logicPD->SetVisibility(0);
330 if (logicPreAmpBox)
331 logicPreAmpBox->SetVisibility(0);
332 if (logicAirInPABox)
333 logicAirInPABox->SetVisibility(0);
334 if (logicHangingPlate)
335 logicHangingPlate->SetVisibility(0);
336 if (logicWaterPipe)
337 logicWaterPipe->SetVisibility(0);
338 if (logicGear)
339 logicGear->SetVisibility(0);
340 if (logicTaperRing1)
341 logicTaperRing1->SetVisibility(0);
342 if (logicTaperRing2)
343 logicTaperRing2->SetVisibility(0);
344 if (logicTaperRing3)
345 logicTaperRing3->SetVisibility(0);
346 if (logicSupportBar)
347 logicSupportBar->SetVisibility(0);
348 if (logicSupportBar1)
349 logicSupportBar1->SetVisibility(0);
350 if (logicEndRing)
351 logicEndRing->SetVisibility(0);
352}
353
354void
356{
357
359
360
361 //std::cout << "begin of set defaultvis" << std::endl;
362 m_Emc->SetLineColor(m_EmcColor);
363 m_Emc->SetVisibility(0);
364
365 for (int part = 0; part < m_kPart-1; part++) {
366 GetVolumePart(part)->SetLineColor(m_partColor);
367 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
368 for (int phi = 0; phi < nPhi; phi++) {
369 GetVolumePhi(part, phi)->SetLineColor(m_phiColor);
370 GetVolumePhi(part, phi)->SetVisibility(0);
371 }
372 if (part == 1) {
373 for (int theta = 0; theta < m_kThetaBr; theta++) {
374 GetVolumeTheta(part, 0, theta)->SetLineColor(m_thetaColor);
375 GetVolumeTheta(part, 0, theta)->SetVisibility(0);
376 GetVolumeCrystal(part, 0, theta)->SetLineColor(m_brCrystalColor);
377 GetVolumeCrystal(part, 0, theta)->SetVisibility(0);
378 }
379 }
380 else if (part == 0) {
381 int iPhi[3] = {0,1,2};
382 for (int i = 0; i < 3; i++) {
383 int phi = iPhi[i];
384 int nTheta = (part == 1 ? m_kThetaBr : m_kNbEc);
385 for (int theta = 0; theta < nTheta; theta++) {
386 GetVolumeTheta(part, phi, theta)->SetLineColor(m_thetaColor);
387 GetVolumeTheta(part, phi, theta)->SetVisibility(0);
388 GetVolumeCrystal(part, phi, theta)->SetLineColor(m_ecCrystalColor);
389 GetVolumeCrystal(part, phi, theta)->SetVisibility(0);
390 }
391 }
392 }
393 }
394
395 // phi and sector
396 for (int part = 0; part < m_kPart; part++) {
397 GetPart(part)->SetVisibility(0);
398 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
399 for (int phi = 0; phi < nPhi; phi++) {
400 GetPhi(part, phi)->SetVisibility(0);
401 }
402 }
403
404 // theta with real phi
405 for (int part = 0; part < m_kPart; part++) {
406 for (int theta = 0; theta < GetThetaNb(part); theta++) {
407 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
408 //cout << "part " << part << " theta " << theta << " phi " << phi << endl;
409 TGeoNode *nodeTheta = GetTheta(part, phi, theta);
410 if (nodeTheta) nodeTheta->SetVisibility(0);
411 TGeoNode *nodeCrystal = GetCrystal(part, phi, theta);
412 if (nodeCrystal) nodeCrystal->SetVisibility(0);
413
414 TGeoNode *nodeTheta2 = GetTheta2(part, phi, theta);
415 if (nodeTheta2) nodeTheta2->SetVisibility(0);
416 TGeoNode *nodeCrystal2 = GetCrystal2(part, phi, theta);
417 if (nodeCrystal2) nodeCrystal2->SetVisibility(0);
418 }
419 }
420 }
421 //std::cout << "end of set defaultvis" << std::endl;
422
423}
424
425void
427{
428
430
431
432 //std::cout << "begin of set defaultvis" << std::endl;
433 m_Emc->SetLineColor(m_EmcColor);
434 m_Emc->SetVisibility(0);
435
436 for (int part = 0; part < m_kPart-1; part++) {
437 GetVolumePart(part)->SetLineColor(m_partColor);
438 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
439 for (int phi = 0; phi < nPhi; phi++) {
440 GetVolumePhi(part, phi)->SetLineColor(m_phiColor);
441 GetVolumePhi(part, phi)->SetVisibility(1);
442 }
443 if (part == 1) {
444 for (int theta = 0; theta < m_kThetaBr; theta++) {
445 GetVolumeTheta(part, 0, theta)->SetLineColor(m_thetaColor);
446 GetVolumeTheta(part, 0, theta)->SetVisibility(1);
447 GetVolumeCrystal(part, 0, theta)->SetLineColor(m_brCrystalColor);
448 GetVolumeCrystal(part, 0, theta)->SetVisibility(1);
449 }
450 }
451 else if (part == 0) {
452 int iPhi[3] = {0,1,2};
453 for (int i = 0; i < 3; i++) {
454 int phi = iPhi[i];
455 int nTheta = (part == 1 ? m_kThetaBr : m_kNbEc);
456 for (int theta = 0; theta < nTheta; theta++) {
457 GetVolumeTheta(part, phi, theta)->SetLineColor(m_thetaColor);
458 GetVolumeTheta(part, phi, theta)->SetVisibility(1);
459 GetVolumeCrystal(part, phi, theta)->SetLineColor(m_ecCrystalColor);
460 GetVolumeCrystal(part, phi, theta)->SetVisibility(1);
461 }
462 }
463 }
464 }
465
466 // phi and sector
467 for (int part = 0; part < m_kPart; part++) {
468 GetPart(part)->SetVisibility(1);
469 int nPhi = (part == 1 ? m_kPhiBr : m_kSectorEc);
470 for (int phi = 0; phi < nPhi; phi++) {
471 GetPhi(part, phi)->SetVisibility(1);
472 }
473 }
474
475 // theta with real phi
476 for (int part = 0; part < m_kPart; part++) {
477 for (int theta = 0; theta < GetThetaNb(part); theta++) {
478 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
479 //cout << "part " << part << " theta " << theta << " phi " << phi << endl;
480 TGeoNode *nodeTheta = GetTheta(part, phi, theta);
481 if (nodeTheta) nodeTheta->SetVisibility(1);
482 TGeoNode *nodeCrystal = GetCrystal(part, phi, theta);
483 if (nodeCrystal) nodeCrystal->SetVisibility(1);
484
485 TGeoNode *nodeTheta2 = GetTheta2(part, phi, theta);
486 if (nodeTheta2) nodeTheta2->SetVisibility(1);
487 TGeoNode *nodeCrystal2 = GetCrystal2(part, phi, theta);
488 if (nodeCrystal2) nodeCrystal2->SetVisibility(1);
489 }
490 }
491 }
492 //std::cout << "end of set defaultvis" << std::endl;
493
494}
495
496void
498{
499 /*
500 for (int part = 0; part < m_kPart; part++) {
501 GetPart(part)->SetVisibility(0);
502 int nPhi = (part == 1 ? m_kPhiBr : m_kPhiEc);
503 for (int phi = 0; phi < nPhi; phi++) {
504 GetPhi(part, phi)->SetVisibility(0);
505 int nTheta = (part == 1 ? m_kThetaBr : m_kThetaEc);
506 for (int theta = 0; theta < nTheta; theta++) {
507 GetTheta(part, phi, theta)->SetVisibility(0);
508 if ( (part == 1 && (phi >= 0 && phi < nPhi/4)) ||
509 (part != 1) ) {
510 GetCrystal(part, phi, theta)->SetVisibility(1);
511 }
512 else {
513 GetCrystal(part, phi, theta)->SetVisibility(0);
514 }
515 }
516 }
517 }
518
519
520 for (int phi = GetPhiNb(1)/4; phi < GetPhiNb(1); phi++) {
521 for (int theta = 0; theta < GetThetaNb(1); theta++) {
522 GetPhysicalCrystal(1, phi, theta)->SetVisibility(1);
523 }
524 }
525
526 for (int theta = 0; theta < GetThetaNb(0); theta++) {
527 for (int i = 0; i < 3; i++) {
528 GetPhysicalCrystal(0, i, theta)->SetVisibility(1);
529 }
530 for (int i = 7; i < 16; i++) {
531 GetPhysicalCrystal(0, i, theta)->SetVisibility(1);
532 }
533 for (int i = 0; i < 7; i++) {
534 GetPhysicalCrystal(2, i, theta)->SetVisibility(1);
535 }
536 for (int i = 11; i < 16; i++) {
537 GetPhysicalCrystal(2, i, theta)->SetVisibility(1);
538 }
539 }
540 */
541}
542
543void
545{
546 /*
547 for (int theta = 0; theta < GetThetaNb(1); theta++) {
548 for (int phi = 0; phi < GetPhiNb(1); phi++) {
549 if (phi >= GetPhiNb(1)/4 && phi < GetPhiNb(1)*3/4) {
550 GetPhysicalCrystal(1, phi, theta)->SetVisibility(0);
551 }
552 else {
553 GetPhysicalCrystal(1, phi, theta)->SetVisibility(1);
554 }
555 }
556 }
557
558 for (int theta = 0; theta < GetThetaNb(0); theta++) {
559 for (int i = 0; i < 16; i++) {
560 if (i >= 7 && i <= 14) {
561 GetPhysicalCrystal(0, i, theta)->SetVisibility(0);
562 }
563 else {
564 GetPhysicalCrystal(0, i, theta)->SetVisibility(1);
565 }
566 }
567 }
568
569 for (int theta = 0; theta < GetThetaNb(2); theta++) {
570 for (int i = 0; i < 16; i++) {
571 if ((i >= 0 && i < 7) || i == 15) {
572 GetPhysicalCrystal(2, i, theta)->SetVisibility(0);
573 }
574 else {
575 GetPhysicalCrystal(2, i, theta)->SetVisibility(1);
576 }
577 }
578 }
579 */
580}
581
582void
584{
585 /*
586 for (int theta = 0; theta < GetThetaNb(1); theta++) {
587 for (int phi = 0; phi < GetPhiNb(1); phi++) {
588 GetPhysicalCrystal(1, phi, theta)->SetVisibility(1);
589 }
590 }
591 */
592}
593
594void
596{
597 if (gGeoManager == 0) std::cout << "Create gGeoManager first" << std::endl;
598 TGeoNode *bes = gGeoManager->GetTopNode();
599 std::cout << "Emc m_childNo " << m_childNo << std::endl;
600 TGeoNode *emc = bes->GetDaughter(2); //2->0
601
602 // Barrel
603 int part = 1;
604 TGeoNode *nodePart = GetPart(part);
605 for (int phi = 0; phi < GetPhiNb(part, 0); phi++) {
606 TGeoNode *nodePhi = GetPhi(part, phi);
607 for (int theta = 0; theta < GetThetaNb(part); theta++) {
608 TGeoNode *nodeTheta = GetTheta(part, phi, theta);
609 TGeoNode *nodeCrystal = GetCrystal(part, phi, theta);
610 m_PhysicalCrystal[part][phi][theta] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
611 TString("/") + emc->GetName() +
612 TString("/") + nodePart->GetName() +
613 TString("/") + nodePhi->GetName() +
614 TString("/") + nodeTheta->GetName() +
615 TString("/") + nodeCrystal->GetName() );
616 m_PhysicalCrystal[part][phi][theta]->SetVisibility(0);
617 m_PhysicalCrystal[part][phi][theta]->SetIsVolAtt(kFALSE);
618 m_PhysicalCrystal[part][phi][theta]->SetLineColor(m_brCrystalColor);
619
620 }
621 }
622
623 // EC
624 for (part = 0; part < m_kPart; part++) {
625 if (part == 1) continue;
626 nodePart = GetPart(part);
627 for (int sector = 0; sector < m_kSectorEc; sector++) {
628 TGeoNode *nodeSector = GetPhi(part, sector);
629 for (int nb = 0; nb < m_kNbEc; nb++) {
630 TGeoNode *nodeNb = nodeSector->GetDaughter(nb);
631 TGeoNode *nodeCrystal = nodeNb->GetDaughter(0);
632
633 int theta, phi;
634 if (nb < m_kRealNbEc) {
635 ComputeThetaPhi(part, sector, nb, theta, phi);
636 m_PhysicalCrystal[part][phi][theta] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
637 TString("/") + emc->GetName() +
638 TString("/") + nodePart->GetName() +
639 TString("/") + nodeSector->GetName() +
640 TString("/") + nodeNb->GetName() +
641 TString("/") + nodeCrystal->GetName() );
642 m_PhysicalCrystal[part][phi][theta]->SetVisibility(0);
643 m_PhysicalCrystal[part][phi][theta]->SetIsVolAtt(kFALSE);
644 m_PhysicalCrystal[part][phi][theta]->SetLineColor(m_ecCrystalColor);
645 //std::cout << part << " " << phi << " " << theta << " " << m_PhysicalCrystal[part][phi][theta]->GetName() << std::endl;
646 }
647 else {
648 ComputeThetaPhi(part, sector, ComputeEndCopyNb(nb), theta, phi);
649 m_PhysicalCrystal2[part][phi][theta] = gGeoManager->MakePhysicalNode( TString("/") + bes->GetName() +
650 TString("/") + emc->GetName() +
651 TString("/") + nodePart->GetName() +
652 TString("/") + nodeSector->GetName() +
653 TString("/") + nodeNb->GetName() +
654 TString("/") + nodeCrystal->GetName() );
655 m_PhysicalCrystal2[part][phi][theta]->SetVisibility(0);
656 m_PhysicalCrystal2[part][phi][theta]->SetIsVolAtt(kFALSE);
657 m_PhysicalCrystal2[part][phi][theta]->SetLineColor(m_ecCrystalColor);
658 //std::cout << "Additional " << part << " " << phi << " " << theta << " " << m_PhysicalCrystal2[part][phi][theta]->GetName() << std::endl;
659 }
660 }
661 }
662 }
663
664 SetDetector();
665}
666
667/*
668void
669EmcROOTGeo::SetPhysicalDefaultVis()
670{
671 for (int part = 0; part < m_kPart; part++) {
672 for (int theta = 0; theta < GetThetaNb(part); theta++) {
673 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
674 TGeoPhysicalNode *phyCrystal = GetPhysicalCrystal(part, phi, theta);
675 TGeoPhysicalNode *phyCrystal2 = GetPhysicalCrystal2(part, phi, theta);
676 if (part == 1) {
677 if (phyCrystal) {
678 phyCrystal->SetIsVolAtt(kFALSE);
679 phyCrystal->SetLineColor(m_brCrystalColor);
680 }
681 }
682 else {
683 if (phyCrystal) {
684 phyCrystal->SetIsVolAtt(kFALSE);
685 phyCrystal->SetLineColor(m_ecCrystalColor);
686 }
687 if (phyCrystal2) {
688 phyCrystal2->SetIsVolAtt(kFALSE);
689 phyCrystal2->SetLineColor(m_ecCrystalColor);
690 }
691 }
692 }
693 }
694 }
695 //std::cout << "end of set defaultvis" << std::endl;
696}
697*/
698
699void
701{
702 BesView *view = 0;
703 if (gPad) view = (BesView*)gPad->GetView();
704 //if (view) cout << "viewVisFull3DEmc " << view->GetVisFull3DEmc() << endl;
705
706 m_DetectorsArray->Clear();
707
708 // Barrel
709 int part = 1;
710 for (int theta = 0; theta < GetThetaNb(part); theta++) {
711 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
712 TGeoPhysicalNode *phyNode = GetPhysicalCrystal(part, phi, theta);
713 if (phyNode) {
714 phyNode->SetVisibility(0); // set all invisible before set any visible
715 if ( phi >= 0 && phi < m_kPhiBr*4/4
716 //|| (theta == 0 || theta == 43) && phi >= m_kPhiBr/4 || phi == 0
717 ) {
718 m_DetectorsArray->Add( phyNode );
719 }
720 else if (view && view->GetVisFull3DEmc()) {
721 m_DetectorsArray->Add( phyNode );
722 }
723 }
724 }
725 }
726
727 // End cap
728 for (int part = 0; part < m_kPart; part++) {
729 if (part == 1) continue;
730 for (int theta = 0; theta < GetThetaNb(part); theta++) {
731 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
732 TGeoPhysicalNode *phyNode = GetPhysicalCrystal(part, phi, theta);
733 if (phyNode) {
734 phyNode->SetVisibility(0); // set all invisible before set any visible
735 if (part == 2 && phi <= GetPhiNb(part, theta)||
736 part == 0 && phi <= GetPhiNb(part, theta) ) {
737 m_DetectorsArray->Add( phyNode );
738 }
739 else if (view && view->GetVisFull3DEmc()) {
740 m_DetectorsArray->Add( phyNode );
741 }
742 }
743
744 phyNode = 0;
745 phyNode = GetPhysicalCrystal2(part, phi, theta);
746 if (phyNode) {
747 phyNode->SetVisibility(0); // set all invisible before set any visible
748 if (part == 2 && phi <= GetPhiNb(part, theta)||
749 part == 0 && phi <= GetPhiNb(part, theta) ) {
750 m_DetectorsArray->Add( phyNode );
751 }
752 else if (view && view->GetVisFull3DEmc()) {
753 m_DetectorsArray->Add( phyNode );
754 }
755 }
756 }
757 }
758 }
759
760 //std::cout << "EmcROOTGeo::SetDetector(), end of set detector " << std::endl;
761}
762
763void
765{
766 // set previous event hits to default vis
767 //cout << "m_HitsArray->GetEntries(): " << m_HitsArray->GetEntries() << endl;
768 //cout << "m_PhyNodeOrgArray->GetEntries(): " << m_PhyNodeOrgArray->GetEntries() << endl;
769 //cout << "m_2DHitsArray->GetEntries(): " << m_2DHitsArray->GetEntries() << endl;
770 for (int i = 0; i < m_HitsArray->GetEntries(); i++) {
771 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)m_HitsArray->At(i);
772 //cout << phyNode->GetName() << endl;
773 int color = m_brCrystalColor;
774 int part = GetPart(phyNode);
775 if (part == 0 || part == 2)
776 color = m_ecCrystalColor;
777
778 phyNode->SetLineColor(color);
779 phyNode->SetVisibility(0);
780
781 RestorePhyNode(phyNode, (TGeoNode*)m_PhyNodeOrgArray->At(i));
782 }
783 m_PhyNodeOrgArray->Clear("C");
784 m_HitsArray->Clear("C");
785
786 // set previous event 2D hits info to default
787 for (int i = 0; i < m_2DHitsArray->GetEntries(); i++) {
788 Emc2DCrystal *aCrystal = (Emc2DCrystal*)m_2DHitsArray->At(i);
789 aCrystal->ClearInfo();
790 aCrystal->AddInfo(aCrystal->GetTitle());
791 aCrystal->CloseInfo();
792 }
793 m_2DHitsArray->Clear("C");
794
795 // set new hits
796 if (gEvent) m_EmcDigiCol = gEvent->GetEmcDigiCol();
797
798 for (int i = 0; i < m_EmcDigiCol->GetEntries(); i++) {
799 TEmcDigi *aEmcDigi = (TEmcDigi*)m_EmcDigiCol->At(i);
800 Identifier aEmcID( aEmcDigi->getIntId() );
801 int part = EmcID::barrel_ec( aEmcID );
802 int theta = EmcID::theta_module( aEmcID );
803 int phi = EmcID::phi_module( aEmcID );
804
805 Double_t charge = RawDataUtil::EmcCharge(aEmcDigi->getMeasure(),
806 aEmcDigi->getChargeChannel());
807 Double_t time = RawDataUtil::EmcTime(aEmcDigi->getTimeChannel());
808
809 TGeoPhysicalNode *phyNode = 0;
810 phyNode = GetPhysicalCrystal( part, phi, theta );
811 if (phyNode) {
812 m_PhyNodeOrgArray->Add ( phyNode->GetNode() );
813
814 //Double_t *P; // = new Double_t[16];
815 //TGeoArb8 *oldArb8 = (TGeoArb8*)phyNode->GetShape();
816 //P = oldArb8->GetVertices();
817 //TGeoArb8 *newArb8 = new TGeoArb8(charge, &P[0]);
818
819 //TGeoTranslation *newmat =
820 // new TGeoTranslation(0.0, 0.0, oldArb8->GetDz()+newArb8->GetDz());
821 //newmat->RegisterYourself();
822
823 //Align(phyNode, newmat, newArb8);
824
825 //m_HitsArray->Add( phyNode );
826 ////delete newArb8;
827 ////delete newmat;
828 }
829
830 phyNode = GetPhysicalCrystal2( part, phi, theta );
831 if (phyNode) {
832 m_PhyNodeOrgArray->Add ( phyNode->GetNode() );
833
834 //Double_t *P; // = new Double_t[16];
835 //TGeoArb8 *oldArb8 = (TGeoArb8*)phyNode->GetShape();
836 //P = oldArb8->GetVertices();
837 //TGeoArb8 *newArb8 = new TGeoArb8(charge, &P[0]);
838
839 //TGeoTranslation *newmat =
840 // new TGeoTranslation(0.0, 0.0, oldArb8->GetDz()+newArb8->GetDz());
841 //newmat->RegisterYourself();
842
843 //Align(phyNode, newmat, newArb8);
844
845 //m_HitsArray->Add( phyNode );
846 ////delete newArb8;
847 ////delete newmat;
848 }
849
850 Emc2DCrystal *aCrystal = 0;
851 aCrystal = m_Emc2DCrystal[part][phi][theta];
852 if (aCrystal) {
853 aCrystal->ClearInfo();
854 aCrystal->AddInfo(aCrystal->GetTitle());
855
856 char data[100];
857 sprintf(data, "time = %-.3f ns, charge = %-.3f MeV", time, charge);
858 aCrystal->AddInfo( TString(data) );
859 sprintf(data, "Fired");
860 aCrystal->AddInfo( TString(data) );
861
862 aCrystal->CloseInfo();
863
864 m_2DHitsArray->Add(aCrystal);
865 }
866 }
867}
868
869void
871{
872 BesView *view = 0;
873 if (gPad) view = (BesView*)gPad->GetView();
874
875 for (int i = 0; i < m_DetectorsArray->GetEntries(); i++) {
876 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)m_DetectorsArray->At(i);
877 phyNode->SetVisibility(0);
878 if (view && view->GetVisEmcGlobal()) {
879 int part = GetPart(phyNode);
880 if (part == 0 && view->GetVisEmcEast() ||
881 part == 1 && view->GetVisEmcBarrel() ||
882 part == 2 && view->GetVisEmcWest() )
883 phyNode->SetVisibility(1);
884 }
885 }
886}
887
888void
890{
891 BesView *view = 0;
892 if (gPad) view = (BesView*)gPad->GetView();
893
894 for (int i = 0; i < m_HitsArray->GetEntries(); i++) {
895 TGeoPhysicalNode *phyNode = (TGeoPhysicalNode*)m_HitsArray->At(i);
896 if (view && view->GetVisEmcHitsGlobal()) {
897 int part = GetPart(phyNode);
898 if (part == 0 && view->GetVisEmcHitsEast() ||
899 part == 1 && view->GetVisEmcHitsBarrel() ||
900 part == 2 && view->GetVisEmcHitsWest() ) {
901 phyNode->SetVisibility(1);
902 phyNode->SetLineColor(kMagenta);
903 continue;
904 }
905 }
906 phyNode->SetVisibility(0);
907 }
908}
909
910int
912{
913 int part = m_kPart;
914
915 return part;
916}
917
918int
919EmcROOTGeo::GetThetaNb(int part) // real theta number
920{
921 int thetaNb = m_kThetaBr;
922 if (part != 1) thetaNb = m_kThetaEc;
923
924 return thetaNb;;
925}
926
927int
928EmcROOTGeo::GetPhiNb(int part, int theta) // real phi number
929{
930 int phiNb = m_kPhiBr;
931 if (part != 1) {
932 if (theta < 2) phiNb = 4*m_kSectorEc;
933 else if (theta >= 2 && theta < 4) phiNb = 5*m_kSectorEc;
934 else if (theta >= 4 && theta < m_kThetaEc) phiNb = 6*m_kSectorEc;
935 }
936
937 return phiNb;
938}
939
940TGeoVolume*
942{
943 // only part0 and part1 logical volume.
944 std::stringstream osname;
945 if (part != 1) osname <<"logicalEndWorld";
946 else osname <<"logicalBSCWorld";
947
948 //osname << "logical" << "Emc" << "Part" << part;
949 if (part == 0 || part == 1) {
950 return GetLogicalVolume( osname.str() );
951 }
952 else {
953 std::cout << "No volume " << osname.str() << std::endl;
954 return 0;
955 }
956}
957
958TGeoVolume*
959EmcROOTGeo::GetVolumePhi( int part, int phi )
960{
961 // only part0phi0-15, part1phi0-119
962 std::stringstream osname;
963 //osname << "logical" << "Emc" << "Part" << part << "Phi" << phi;
964 if (part == 1) osname << "logicalBSCPhi" ;
965 else{
966 if (phi == 15 || phi == 7) osname << "logicalEndPhi2" ;
967 else if (phi == 14 || phi == 6) osname << "logicalEndPhi1" ;
968 else osname << "logicalEndPhi0" ;
969 }
970
971
972 if ( (part == 0 && phi >= 0 && phi < 16) ||
973 (part == 1 && phi >= 0 && phi < 120) ) {
974 return GetLogicalVolume( osname.str() );
975 }
976 else {
977 std::cout << "No volume " << osname.str() << std::endl;
978 return 0;
979 }
980}
981
982TGeoVolume*
983EmcROOTGeo::GetVolumeTheta( int part, int phi, int theta )
984{
985 // part0phi0theta0-34, part0phi6theta0-34, part0phi7theta0-34
986 // part1theta0-43
987 std::stringstream osname;
988 if (part == 1 && theta >= 0 && theta < 44) {
989 //osname << "logical" << "Emc" << "Part" << part << "Theta" << theta;
990 osname << "logicalBSCCasing" << theta;
991 return GetLogicalVolume( osname.str() );
992 }
993 else if ( part != 1 && theta >= 0 && theta < 35 &&
994 (phi < 3) ) {
995 //osname << "logical" << "Emc" << "Part" << part << "Phi" << phi << "Theta" << theta;
996 osname << "logicalEndCasing_" << phi << "_" << theta;
997 return GetLogicalVolume( osname.str() );
998 }
999 else {
1000 std::cout << "No volume " << osname.str() << std::endl;
1001 return 0;
1002 }
1003}
1004
1005TGeoVolume*
1006EmcROOTGeo::GetVolumeCrystal( int part, int phi, int theta )
1007{
1008 // part0phi0theta0-34, part0phi6theta0-34, part0phi8theta0-34, part0phi7theta0-34
1009 // part1theta0-43
1010 std::stringstream osname;
1011 if (part == 1 && theta >= 0 && theta < 44) {
1012 //osname << "logical" << "Emc" << "Part" << part << "Theta" << theta << "Crystal";
1013 osname << "logicalCrystal";
1014 return GetLogicalVolume( osname.str() );
1015 }
1016 else if ( part == 0 && theta >= 0 && theta < 35 &&
1017 (phi < 3) ) {
1018 //osname << "logical" << "Emc" << "Part" << part << "Phi" << phi << "Theta" << theta << "Crystal";
1019 osname << "logicalEndCrystal_" << phi << "_" << theta;
1020 return GetLogicalVolume( osname.str() );
1021 }
1022 else {
1023 std::cout << "No volume " << osname.str() << std::endl;
1024 return 0;
1025 }
1026}
1027
1028TGeoNode*
1029EmcROOTGeo::GetPart( int part )
1030{
1031 if (m_ROOTGeoInit == 2) { // from GDML
1032 std::stringstream osname;
1033 //osname << "pv_" << "logical" << "Emc" << "Part" << (part == 2 ? (part -2) : part) << "_" << part;
1034 if (part == 1) osname <<"pv_logicalBSCWorld_2";
1035 if (part == 0) osname <<"pv_logicalEndWorld_1";
1036 if (part == 2) osname <<"pv_logicalEndWorld_0";
1037
1038 return GetNode( osname.str() );
1039 }
1040 else if (m_ROOTGeoInit == 1) { // from ROOT object
1041 if (m_NodePart[part] != 0) {
1042 return m_NodePart[part];
1043 }
1044 else {
1045 std::cout << "Node: " << "Part" << part << " not found" << std::endl;
1046 return 0;
1047 }
1048 }
1049
1050 return 0;
1051}
1052
1053TGeoNode*
1054EmcROOTGeo::GetPhi( int part, int phi ) // in EC, sector in fact
1055{
1056 if (m_ROOTGeoInit == 2) { // from GDML
1057 int endphilist[16]= {15,7,14,6,13,12,11,10,9,8,5,4,3,2,1,0};
1058 int endphipos[16] = {15,14,13,12,11,10,3,1,9,8,7,6,5,4,2,0}; //pos of phi in endworld
1059
1060 int realphi=0;
1061 if (phi==15||phi==7) realphi = 2;
1062 if (phi==14||phi==6) realphi = 1;
1063
1064 std::stringstream osname;
1065 //osname << "pv_" << "logical" << "Emc" << "Part" << (part == 2 ? (part -2) : part) << "Phi" << phi << "_" << phi;
1066 if (part == 1) osname << "pv_logicalBSCPhi" << "_" << 308-phi;
1067 else osname <<"pv_logicalEndPhi"<<realphi<<"_" <<endphipos[phi];
1068 return GetNode( osname.str() );
1069 }
1070 else if (m_ROOTGeoInit == 1) { // from ROOT object
1071 if (m_NodePhi[part][phi] != 0) {
1072 return m_NodePhi[part][phi];
1073 }
1074 else {
1075 std::cout << "Node: " << "Part" << part << "Phi" << phi << " not found" << std::endl;
1076 return 0;
1077 }
1078 }
1079
1080 return 0;
1081}
1082
1083TGeoNode*
1084EmcROOTGeo::GetTheta( int part, int phi, int theta ) // real phi, theta
1085{
1086 if (m_NodeTheta[part][phi][theta] != 0) {
1087 return m_NodeTheta[part][phi][theta];
1088 }
1089 else {
1090 std::cout << "Node: " << "Part" << part << "Phi" << phi << "Theta" << theta << " not found" << std::endl;
1091 return 0;
1092 }
1093}
1094
1095TGeoNode*
1096EmcROOTGeo::GetTheta2( int part, int phi, int theta ) // real phi, theta
1097{
1098 if (m_NodeTheta2[part][phi][theta] != 0) {
1099 return m_NodeTheta2[part][phi][theta];
1100 }
1101 else {
1102 return 0;
1103 }
1104}
1105
1106TGeoNode*
1107EmcROOTGeo::GetCrystal( int part, int phi, int theta ) // real phi, theta
1108{
1109 // in fact, br only 44 crystal nodes;
1110 return GetTheta(part, phi, theta)->GetDaughter(0);
1111}
1112
1113TGeoNode*
1114EmcROOTGeo::GetCrystal2( int part, int phi, int theta ) // real phi, theta
1115{
1116 // in fact, br only 44 crystal nodes;
1117 if (GetTheta2(part, phi, theta) == 0) return 0;
1118 else return GetTheta2(part, phi, theta)->GetDaughter(0);
1119}
1120
1121TGeoPhysicalNode*
1122EmcROOTGeo::GetPhysicalCrystal( int part, int phi, int theta ) // real phi, theta
1123{
1124 if (m_PhysicalCrystal[part][phi][theta] != 0) {
1125 return m_PhysicalCrystal[part][phi][theta];
1126 }
1127 else {
1128 std::cout << "PhysicalNode: " << "Part" << part << "Phi" << phi << "Theta" << theta << " not found" << std::endl;
1129 return 0;
1130 }
1131}
1132
1133TGeoPhysicalNode*
1134EmcROOTGeo::GetPhysicalCrystal2( int part, int phi, int theta ) // real phi, theta
1135{
1136 return m_PhysicalCrystal2[part][phi][theta];
1137}
1138
1139bool
1140EmcROOTGeo::HasTwoNodes( int part, int phi, int theta )
1141{
1142 if (part == 1) return false;
1143 else return true;
1144}
1145
1146
1147void
1148EmcROOTGeo::ComputeThetaPhi( int id, int sector, int nb, int &CryNumberTheta, int &CryNumberPhi)
1149{
1150 if ((sector>=0)&&(sector<3))
1151 sector+=16;
1152 if ((sector!=7)&&(sector!=15))
1153 {
1154 if ((nb>=0)&&(nb<4))
1155 {
1156 CryNumberTheta = 0;
1157 CryNumberPhi = (sector-3)*4+nb;
1158 }
1159 else if ((nb>=4)&&(nb<8))
1160 {
1161 CryNumberTheta = 1;
1162 CryNumberPhi = (sector-3)*4+nb-4;
1163 }
1164 else if ((nb>=8)&&(nb<13))
1165 {
1166 CryNumberTheta = 2;
1167 CryNumberPhi = (sector-3)*5+nb-8;
1168 }
1169 else if ((nb>=13)&&(nb<18))
1170 {
1171 CryNumberTheta = 3;
1172 CryNumberPhi = (sector-3)*5+nb-13;
1173 }
1174 else if ((nb>=18)&&(nb<24))
1175 {
1176 CryNumberTheta = 4;
1177 CryNumberPhi = (sector-3)*6+nb-18;
1178 }
1179 else if ((nb>=24)&&(nb<30))
1180 {
1181 CryNumberTheta = 5;
1182 CryNumberPhi = (sector-3)*6+nb-24;
1183 }
1184 }
1185 else// if((sector=7)||(sector==15))
1186 {
1187 if ((nb>=0)&&(nb<4))
1188 {
1189 CryNumberTheta = 0;
1190 CryNumberPhi = (sector-3)*4+3-nb;
1191 }
1192 else if ((nb>=4)&&(nb<8))
1193 {
1194 CryNumberTheta = 1;
1195 CryNumberPhi = (sector-3)*4+7-nb;
1196 }
1197 else if ((nb>=8)&&(nb<13))
1198 {
1199 CryNumberTheta = 2;
1200 CryNumberPhi = (sector-3)*5+12-nb;
1201 }
1202 else if ((nb>=13)&&(nb<18))
1203 {
1204 CryNumberTheta = 3;
1205 CryNumberPhi = (sector-3)*5+17-nb;
1206 }
1207 else if ((nb>=18)&&(nb<24))
1208 {
1209 CryNumberTheta = 4;
1210 CryNumberPhi = (sector-3)*6+23-nb;
1211 }
1212 else if ((nb>=24)&&(nb<30))
1213 {
1214 CryNumberTheta = 5;
1215 CryNumberPhi = (sector-3)*6+29-nb;
1216 }
1217 }
1218
1219 if (id==2)
1220 {
1221 switch (CryNumberTheta)
1222 {
1223 case 0:
1224 if (CryNumberPhi<32)
1225 CryNumberPhi = 31-CryNumberPhi;
1226 else
1227 CryNumberPhi = 95-CryNumberPhi;
1228 break;
1229 case 1:
1230 if (CryNumberPhi<32)
1231 CryNumberPhi = 31-CryNumberPhi;
1232 else
1233 CryNumberPhi = 95-CryNumberPhi;
1234 break;
1235 case 2:
1236 if (CryNumberPhi<40)
1237 CryNumberPhi = 39-CryNumberPhi;
1238 else
1239 CryNumberPhi = 119-CryNumberPhi;
1240 break;
1241 case 3:
1242 if (CryNumberPhi<40)
1243 CryNumberPhi = 39-CryNumberPhi;
1244 else
1245 CryNumberPhi = 119-CryNumberPhi;
1246 break;
1247 case 4:
1248 if (CryNumberPhi<48)
1249 CryNumberPhi = 47-CryNumberPhi;
1250 else
1251 CryNumberPhi = 143-CryNumberPhi;
1252 break;
1253 case 5:
1254 if (CryNumberPhi<48)
1255 CryNumberPhi = 47-CryNumberPhi;
1256 else
1257 CryNumberPhi = 143-CryNumberPhi;
1258 default:
1259 ;
1260 }
1261 }
1262}
1263
1264int
1266{
1267 int copyNb;
1268 switch (num){
1269 case 30:
1270 copyNb = 5;
1271 break;
1272 case 31:
1273 copyNb = 6;
1274 break;
1275 case 32:
1276 copyNb = 14;
1277 break;
1278 case 33:
1279 copyNb = 15;
1280 break;
1281 case 34:
1282 copyNb = 16;
1283 break;
1284 default:
1285 copyNb = num;
1286 break;
1287 }
1288 return copyNb;
1289}
1290
1292EmcROOTGeo::Get2DCrystal( Int_t part, Int_t phi, Int_t theta )
1293{
1294 if (m_Emc2DCrystal[part][phi][theta]) return m_Emc2DCrystal[part][phi][theta];
1295 else return 0;
1296}
1297
1298int
1299EmcROOTGeo::GetPart(TGeoPhysicalNode* phyNode)
1300{
1301 for (int part = 0; part < GetPartNb(); part++) {
1302 for (int theta = 0; theta < GetThetaNb(part); theta++) {
1303 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
1304 if (phyNode == GetPhysicalCrystal(part, phi, theta)) {
1305 //cout << "EmcROOTGeo::GetPart()" << part << endl;
1306 return part;
1307 }
1308 if (phyNode == GetPhysicalCrystal2(part, phi, theta)) {
1309 //cout << "EmcROOTGeo::GetPart()" << part << endl;
1310 return part;
1311 }
1312 }
1313 }
1314 }
1315
1316 cout << "EmcROOTGeo::GetPart, this crystal physical node does not exist!" << endl;
1317 return -1;
1318}
1319
1320void
1321EmcROOTGeo::Draw(Option_t *option)
1322{
1323 TString opt = option;
1324 opt.ToUpper();
1325
1326 if (!m_2DGeoInit) cout << "EmcROOTGeo::Draw2D(), 2D Geometry not initialized!" << endl;
1327 BesView *view = (BesView*)gPad->GetView();
1328 if (!view) cout << "EmcROOTGeo::Draw(), BesView not found" << endl;
1329
1330 if (view->GetVisEmcGlobal()) { // EmcVisGlobal
1331 TString crystalOpt;
1332
1333 //if (opt.Contains("XY")) {
1334 // west part drawn first usually
1335 for (Int_t part = GetPartNb()-1; part >= 0; part--) {
1336 for (int theta = 0; theta < GetThetaNb(part); theta++) {
1337 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
1338
1339 if (m_Emc2DCrystal[part][phi][theta]) {
1340 //cout << "part " << part << " layer " << layer << " crystal " << crystal << endl;
1341 m_Emc2DCrystal[part][phi][theta]->SetFired(false);
1342 if ( (part == 0 && view->GetVisEmcEast()) ||
1343 (part == 1 && view->GetVisEmcBarrel()) ||
1344 (part == 2 && view->GetVisEmcWest()) )
1345 m_Emc2DCrystal[part][phi][theta]->Draw(crystalOpt);
1346 }
1347 }
1348 }
1349 }
1350 }
1351}
1352
1353void
1354EmcROOTGeo::DrawHits(Option_t *option)
1355{
1356 // cout << "EmcROOTGeo::DrawHits" << endl;
1357 BesView *view = (BesView*)gPad->GetView();
1358 if (!view) cout << "EmcROOTGeo::DrawHits(), BesView not found" << endl;
1359
1360 //cout << "VisEmcHitsGlobal " << view->GetVisEmcHitsGlobal() << endl;
1361 //cout << "VisEmcHitsEast " << view->GetVisEmcHitsEast() << endl;
1362 //cout << "VisEmcHitsBarrel " << view->GetVisEmcHitsBarrel() << endl;
1363 //cout << "VisEmcHitsWest " << view->GetVisEmcHitsWest() << endl;
1364
1365 if (view->GetVisEmcHitsGlobal()) {
1366
1367 // reset time and charge to zero
1368 for (Int_t part = GetPartNb()-1; part >= 0; part--) {
1369 for (int theta = 0; theta < GetThetaNb(part); theta++) {
1370 for (int phi = 0; phi < GetPhiNb(part, theta); phi++) {
1371 if (m_Emc2DCrystal[part][phi][theta]) {
1372 m_Emc2DCrystal[part][phi][theta]->ResetTimeCharge();
1373 //m_Emc2DCrystal[part][phi][theta]->ClearInfo();
1374 }
1375 }
1376 }
1377 }
1378
1379 if (m_EmcDigiCol) {
1380 for (int i = 0; i < m_EmcDigiCol->GetEntries(); i++) {
1381 TEmcDigi *aEmcDigi = (TEmcDigi*)m_EmcDigiCol->At(i);
1382
1383 //cout << aEmcDigi->getIntId() << endl;
1384 Identifier aEmcID( aEmcDigi->getIntId() );
1385 int part = EmcID::barrel_ec( aEmcID );
1386 int theta = EmcID::theta_module( aEmcID );
1387 int phi = EmcID::phi_module( aEmcID );
1388
1389 Emc2DCrystal *aCrystal = 0;
1390 aCrystal = m_Emc2DCrystal[part][phi][theta];
1391
1392 //Double_t charge = Double_t(aEmcDigi->getChargeChannel()) / EMC_CHARGE_FACTOR;
1393 Double_t charge = RawDataUtil::EmcCharge(aEmcDigi->getMeasure(),
1394 aEmcDigi->getChargeChannel());
1395 aCrystal->SetCharge(charge);
1396 //cout << "charge " << aCrystal->GetCharge() << endl;
1397
1398 if (aCrystal&&charge > 5) {
1399 if ( (part == 0 && view->GetVisEmcHitsEast()) ||
1400 (part == 1 && view->GetVisEmcHitsBarrel()) ||
1401 (part == 2 && view->GetVisEmcHitsWest()) ) {
1402 aCrystal->SetFired(true);
1403 aCrystal->Draw();
1404 }
1405 }
1406 }
1407 }
1408 }
1409}
1410
1411void EmcROOTGeo::Align(TGeoPhysicalNode *phyNode, TGeoMatrix *newmat, TGeoShape *newshape, Bool_t check)
1412{
1413 //phyNode->Align(newmat, newshape, check);
1414
1415 if (!newmat && !newshape) return;
1416 TGeoNode *node = phyNode->GetNode();
1417
1418 Int_t fLevel=phyNode->GetLevel();
1419 TGeoNode *nnode = 0;
1420 TGeoVolume *vm = phyNode->GetVolume(fLevel-2);
1421 // fLevel-2 is good for Emc geometry, use fLevel-1 if I want to use it in TofROOTGeo
1422 TGeoVolume *vd = 0;
1423
1424 TGeoNode *nodeArray[30];
1425 TString orgName = phyNode->GetName();
1426 Int_t i,id;
1427 if (!phyNode->IsAligned()) {
1428 for (i=0; i<=fLevel-2; i++) {
1429 nodeArray[i] = phyNode->GetNode(i);
1430 }
1431
1432 // fLevel-2 is good for Emc geometry,
1433 // in ROOT::TGeoPhysicalNode::Align,
1434 // it starts from 0, so some nodes were lost.
1435 for (i=fLevel-2; i<fLevel; i++) {
1436 // Get daughter node and its id inside vm
1437 node = phyNode->GetNode(i+1);
1438 id = vm->GetIndex(node);
1439
1440 if (id < 0) {
1441 //printf("cannot align node %s",phyNode->GetNode(i+1)->GetName());
1442 return;
1443 }
1444 // Clone daughter volume and node
1445 vd = node->GetVolume()->CloneVolume();
1446 nnode = node->MakeCopyNode();
1447 // Correct pointers to mother and volume
1448 nnode->SetName(node->GetName());
1449 nnode->SetVolume(vd);
1450 nnode->SetMotherVolume(vm);
1451 // Decouple old node from mother volume and connect new one
1452 vm->GetNodes()->RemoveAt(id);
1453 vm->GetNodes()->AddAt(nnode,id);
1454 nodeArray[i+1] = nnode;
1455 vm = vd;
1456 }
1457 } else {
1458 nnode = phyNode->GetNode();
1459 }
1460
1461 TString name;
1462 for (Int_t j = 0; j < phyNode->GetLevel()+1; j++) {
1463 name += "/";
1464 name += nodeArray[j]->GetName();
1465 }
1466 //phyNode->SetPath(name);
1467 phyNode->SetName(name);
1468 phyNode->Refresh();
1469
1470 // Now nnode is a cloned node of the one that need to be aligned
1471 TGeoNodeMatrix *aligned = (TGeoNodeMatrix*)nnode;
1472 vm = nnode->GetMotherVolume();
1473 vd = nnode->GetVolume();
1474 if (newmat) {
1475 // Register matrix and make it the active one
1476 if (!newmat->IsRegistered()) newmat->RegisterYourself();
1477 aligned->SetMatrix(newmat);
1478 // Update the global matrix for the aligned node
1479 TGeoHMatrix *global = phyNode->GetMatrix();
1480 TGeoHMatrix *up = phyNode->GetMatrix(fLevel-1);
1481 *global = up;
1482 global->Multiply(newmat);
1483 }
1484 // Change the shape for the aligned node
1485 if (newshape) vd->SetShape(newshape);
1486 // Now we have to re-voxelize the mother volume
1487 vm->SetVoxelFinder(0);
1488 vm->Voxelize("ALL");
1489 vm->FindOverlaps();
1490 // Eventually check for overlaps
1491 if (check) vm->CheckOverlaps();
1492 //phyNode->SetAligned(kTRUE);
1493}
1494
1495void EmcROOTGeo::RestorePhyNode(TGeoPhysicalNode *phyNode, TGeoNode *node)
1496{
1497 Align(phyNode, node->GetMatrix(), node->GetVolume()->GetShape());
1498}
R__EXTERN BesEvent * gEvent
Definition: BesEvent.h:278
const int nPhi
TTree * data
Double_t time
const TObjArray * GetEmcDigiCol() const
Definition: BesEvent.h:78
Bool_t GetVisEmcBarrel()
Definition: BesView.h:118
Bool_t GetVisEmcHitsBarrel()
Definition: BesView.h:182
Bool_t GetVisEmcHitsGlobal()
Definition: BesView.h:180
Bool_t GetVisEmcGlobal()
Definition: BesView.h:116
Bool_t GetVisEmcWest()
Definition: BesView.h:119
Bool_t GetVisEmcHitsWest()
Definition: BesView.h:183
Bool_t GetVisFull3DEmc()
Definition: BesView.h:144
Bool_t GetVisEmcEast()
Definition: BesView.h:117
Bool_t GetVisEmcHitsEast()
Definition: BesView.h:181
virtual void SetFired(bool status=true)
Definition: Emc2DCrystal.h:31
virtual void CloseInfo()
virtual void ResetTimeCharge()
Definition: Emc2DCrystal.h:43
virtual void Draw(Option_t *option="")
virtual void AddInfo(TString info)
Definition: Emc2DCrystal.h:35
virtual void ClearInfo()
virtual void SetCharge(Double_t charge)
Definition: Emc2DCrystal.h:40
static unsigned int barrel_ec(const Identifier &id)
Values of different levels (failure returns 0)
Definition: EmcID.cxx:38
static unsigned int theta_module(const Identifier &id)
Definition: EmcID.cxx:43
static unsigned int phi_module(const Identifier &id)
Definition: EmcID.cxx:48
TGeoVolume * GetVolumeCrystal(int part, int phi, int theta)
Get crystal volume;.
int ComputeEndCopyNb(int num)
Compute copyNb, copyNb 5,6,14,15,16 corresponding to two volume.
void SetVisEmcDetector()
Set Emc detector visibility;.
TGeoNode * GetCrystal(int part, int phi, int theta)
Get crystal one;.
TGeoVolume * GetVolumeTheta(int part, int phi, int theta)
Get theta volume;.
TGeoNode * GetTheta(int part, int phi, int theta)
Get theta node;.
TGeoVolume * GetVolumePart(int part)
Get part volume;.
TGeoNode * GetCrystal2(int part, int phi, int theta)
Get crystal2 one;.
void Align(TGeoPhysicalNode *phyNode, TGeoMatrix *newmat=0, TGeoShape *newshape=0, Bool_t check=kFALSE)
Align a physical node, change its position and shape.
void ComputeThetaPhi(int id, int sector, int nb, int &CryNumberTheta, int &CryNumberPhi)
Compute theta, phi from sector, nb.
Emc2DCrystal * Get2DCrystal(Int_t part, Int_t phi, Int_t theta)
Get Emc2DCrystal;.
TGeoPhysicalNode * GetPhysicalCrystal2(int part, int phi, int theta)
Get crystal physical node2; EC nb 5,6,14,15,16 in any sector has two physicalNode.
int GetPhiNb(int part)
Get number of phi on part;.
void InitFromROOT(TGeoVolume *vol)
Initialize ROOTGeo from TGeoVolume logicalEmc.
TGeoVolume * GetVolumePhi(int part, int phi)
Get phi volume;
void InitFromGDML(const char *gdmlFile, const char *setupName)
Initialize ROOTGeo from GDML.
void SetPhysicalNode()
Set the pointers to the physical nodes;.
void SetVolumeAppendInVis()
Set default visual attributes;.
void SetNode()
Set the pointers to theirs nodes;.
int GetThetaNb(int part)
Get number of theta on part;.
bool HasTwoNodes(int part, int phi, int theta)
Whether this id is combined of two nodes.
TGeoNode * GetPhi(int part, int phi)
Get phi node;.
void RestorePhyNode(TGeoPhysicalNode *phyNode, TGeoNode *node)
Restore the physical node to original shape.
TGeoPhysicalNode * GetPhysicalCrystal(int part, int phi, int theta)
Get crystal physical node;.
TGeoNode * GetTheta2(int part, int phi, int theta)
Get theta2 node;.
void SetDetector()
Set default physical node attributes;.
void SetVolumeEmc(TGeoVolume *vol)
Set Emc volume, while initializing from ROOT;.
void SetVolumeDefaultVis()
Set default visual attributes;.
void SetHits()
Set all physicalNodes corresponding to digiCol;.
static double EmcTime(int timeChannel)
Definition: RawDataUtil.h:14
static double EmcCharge(int measure, int chargeChannel)
Definition: RawDataUtil.h:17
TGeoNode * GetNode(const std::string &nn)
Get a node(physical volume) by name;.
TGeoVolume * GetLogicalVolume(const std::string &vn)
Get a logical volume by name;.
void ReadGdml(const char *gdmlFile, const char *setupName)
Initialize the instance of ROOTGeo.
UInt_t getMeasure() const
Definition: TEmcDigi.cxx:37
UInt_t getIntId() const
Definition: TRawData.cxx:50
UInt_t getChargeChannel() const
Definition: TRawData.cxx:60
UInt_t getTimeChannel() const
Definition: TRawData.cxx:55
int num[96]
Definition: ranlxd.c:373