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