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