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