1 package org.lcsim.recon.util;
2
3
4
5
6
7 import hep.physics.vec.BasicHep3Vector;
8 import hep.physics.vec.Hep3Vector;
9
10 import java.io.PrintStream;
11 import java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
14 import java.util.Map;
15
16 import org.lcsim.detector.material.BetheBlochCalculator;
17 import org.lcsim.detector.material.IMaterial;
18 import org.lcsim.detector.material.IMaterialStore;
19 import org.lcsim.detector.material.MaterialStore;
20 import org.lcsim.geometry.Calorimeter;
21 import org.lcsim.geometry.Detector;
22 import org.lcsim.geometry.IDDecoder;
23 import org.lcsim.geometry.compact.Subdetector;
24 import org.lcsim.geometry.layer.Layer;
25 import org.lcsim.geometry.layer.LayerSlice;
26 import org.lcsim.geometry.subdetector.AbstractPolyhedraCalorimeter;
27 import org.lcsim.geometry.subdetector.CylindricalBarrelCalorimeter;
28 import org.lcsim.geometry.subdetector.CylindricalEndcapCalorimeter;
29 import org.lcsim.geometry.subdetector.EcalBarrel;
30 import org.lcsim.geometry.subdetector.PolyhedraBarrelCalorimeter;
31 import org.lcsim.geometry.subdetector.PolyhedraBarrelCalorimeter2;
32 import org.lcsim.geometry.subdetector.PolyhedraEndcapCalorimeter;
33 import org.lcsim.geometry.subdetector.PolyhedraEndcapCalorimeter2;
34
35 public class CalorimeterInformation
36 {
37 static CalorimeterInformation theCalorimeterInformation;
38 private final boolean debug = true;
39 private int ncal = 0;
40 private List<Subdetector> sublist;
41 private Subdetector[] subdetector;
42 private IDDecoder[] idd;
43 private String[] subtype;
44 private String[] name;
45 private String[] collname;
46 private String[] digicollname;
47 private int[] sysid;
48 private int[] nlayers;
49 private int[] nsides;
50 private double[] rmin;
51 private double[] rmax;
52 private double[] zmin;
53 private double[] zmax;
54 private List[] de;
55 private List[] nrad;
56 private List[] nlam;
57 private Map<Calorimeter.CalorimeterType,Integer> indexmap;
58 private int index;
59 private BetheBlochCalculator bbc;
60 private IMaterialStore ms;
61 public CalorimeterInformation()
62 {
63 theCalorimeterInformation = this;
64 }
65 public static CalorimeterInformation instance()
66 {
67 return theCalorimeterInformation;
68 }
69
70
71
72
73 protected void init(Detector d)
74 {
75 bbc = new BetheBlochCalculator();
76 ms = MaterialStore.getInstance();
77 sublist = new ArrayList<Subdetector>();
78 for(Subdetector s:d.getSubdetectors().values())
79 {
80 if(s.isCalorimeter())
81 {
82 if(s.getReadout() == null)
83 {
84 if (debug)
85 System.out.println("Subdetector "+s.getName()+" isCalorimeter but has null Readout");
86 }
87 else
88 {
89 sublist.add( s );
90 if (debug)
91 System.out.println("Adding subdetector "+s.getName());
92 }
93 }
94 }
95 ncal = sublist.size();
96 subdetector = new Subdetector[ncal];
97 idd = new IDDecoder[ncal];
98 subtype = new String[ncal];
99 name = new String[ncal];
100 collname = new String[ncal];
101 digicollname = new String[ncal];
102 sysid = new int[ncal];
103 nlayers = new int[ncal];
104 nsides = new int[ncal];
105 rmin = new double[ncal];
106 rmax = new double[ncal];
107 zmin = new double[ncal];
108 zmax = new double[ncal];
109 de = new List[ncal];
110 nrad = new List[ncal];
111 nlam = new List[ncal];
112 indexmap = new HashMap<Calorimeter.CalorimeterType,Integer>();
113 Hep3Vector p = new BasicHep3Vector(0.,0.,100.);
114 Map<String,Double> dedxmap = new HashMap<String,Double>();
115 for(int i=0;i<ncal;i++)
116 {
117 Subdetector s = sublist.get(i);
118 subdetector[i] = s;
119 name[i] = s.getName();
120 sysid[i] = s.getSystemID();
121 nlayers[i] = s.getLayering().getNumberOfLayers();
122 Calorimeter c = (Calorimeter) s;
123 indexmap.put(c.getCalorimeterType(),i);
124 idd[i] = subdetector[i].getIDDecoder();
125 if(idd[i] == null)System.out.println("null IDDecoder for subdector "+subdetector[i].getName());
126 collname[i] = subdetector[i].getReadout().getName();
127 digicollname[i] = new String(collname[i]).replace("Hits","DigiHits");
128 nrad[i] = new ArrayList<Double>();
129 nlam[i] = new ArrayList<Double>();
130 de[i] = new ArrayList<Double>();
131 for(int j=0;j<nlayers[i];j++)
132 {
133 Layer layer = s.getLayering().getLayer(j);
134 double xrad = 0.;
135 double xlam = 0.;
136 double xde = 0.;
137 for(LayerSlice slice:layer.getSlices())
138 {
139 IMaterial m = ms.get(slice.getMaterial().getName());
140 double dedx;
141 if(dedxmap.containsKey(slice.getMaterial().getName()))dedx = dedxmap.get(slice.getMaterial().getName()).doubleValue();
142 else
143 {
144 dedx = bbc.computeBetheBloch(m, p, 105., 1., .01)/10000.;
145 dedxmap.put(slice.getMaterial().getName(),new Double(dedx));
146 }
147 double dx = slice.getThickness();
148 xrad += dx/m.getRadiationLengthWithDensity();
149 xlam += dx/m.getNuclearInteractionLengthWithDensity();
150 xde += dx*dedx;
151 }
152 nrad[i].add(new Double(xrad/10.));
153 nlam[i].add(new Double(xlam/10.));
154 de[i].add(new Double(xde));
155 }
156 nsides[i] = 1;
157 if(s.isBarrel())
158 {
159 if(s instanceof CylindricalBarrelCalorimeter)
160 {
161 subtype[i] = "CylindricalBarrelCalorimeter";
162 CylindricalBarrelCalorimeter b = (CylindricalBarrelCalorimeter) s;
163 rmin[i] = b.getInnerRadius();
164 rmax[i] = b.getOuterRadius();
165 zmin[i] = b.getInnerZ();
166 zmax[i] = b.getOuterZ();
167 }
168 else if(s instanceof PolyhedraBarrelCalorimeter)
169 {
170 subtype[i] = "PolyhedraBarrelCalorimeter";
171 PolyhedraBarrelCalorimeter b = (PolyhedraBarrelCalorimeter) s;
172 rmin[i] = b.getInnerRadius();
173 rmax[i] = b.getOuterRadius();
174 zmin[i] = b.getInnerZ();
175 zmax[i] = b.getOuterZ();
176 nsides[i] = ((AbstractPolyhedraCalorimeter) s).getNumberOfSides();
177 }
178 else if(s instanceof PolyhedraBarrelCalorimeter2)
179 {
180 subtype[i] = "PolyhedraBarrelCalorimeter";
181 PolyhedraBarrelCalorimeter2 b = (PolyhedraBarrelCalorimeter2) s;
182 rmin[i] = b.getInnerRadius();
183 rmax[i] = b.getOuterRadius();
184 zmin[i] = b.getInnerZ();
185 zmax[i] = b.getOuterZ();
186 nsides[i] = ((AbstractPolyhedraCalorimeter) s).getNumberOfSides();
187 }
188 else if(s instanceof EcalBarrel)
189 {
190 subtype[i] = "EcalBarrel";
191 EcalBarrel b = (EcalBarrel) s;
192 rmin[i] = b.getInnerRadius();
193 rmax[i] = b.getOuterRadius();
194 zmin[i] = b.getInnerZ();
195 zmax[i] = b.getOuterZ();
196 nsides[i] = ((AbstractPolyhedraCalorimeter) s).getNumberOfSides();
197 }
198 else
199 {
200 System.out.println("Barrel calorimeter "+name[i]+" is unknown type");
201 subtype[i] = "unknown";
202 }
203 }
204 else if(c.isEndcap())
205 {
206 if(s instanceof CylindricalEndcapCalorimeter)
207 {
208 subtype[i] = "CylindricalEndcapCalorimeter";
209 CylindricalEndcapCalorimeter e = (CylindricalEndcapCalorimeter) s;
210 rmin[i] = e.getInnerRadius();
211 rmax[i] = e.getOuterRadius();
212 zmin[i] = e.getInnerZ();
213 zmax[i] = e.getOuterZ();
214 }
215 else if(s instanceof PolyhedraEndcapCalorimeter)
216 {
217 subtype[i] = "PolyhedraEndcapCalorimeter";
218 PolyhedraEndcapCalorimeter e = (PolyhedraEndcapCalorimeter) s;
219 rmin[i] = e.getInnerRadius();
220 rmax[i] = e.getOuterRadius();
221 zmin[i] = e.getInnerZ();
222 zmax[i] = e.getOuterZ();
223 nsides[i] = ((AbstractPolyhedraCalorimeter) s).getNumberOfSides();
224 }
225 else if(s instanceof PolyhedraEndcapCalorimeter2)
226 {
227 subtype[i] = "PolyhedraEndcapCalorimeter2";
228 PolyhedraEndcapCalorimeter2 e = (PolyhedraEndcapCalorimeter2) s;
229 rmin[i] = e.getInnerRadius();
230 rmax[i] = e.getOuterRadius();
231 zmin[i] = e.getInnerZ();
232 zmax[i] = e.getOuterZ();
233 nsides[i] = ((AbstractPolyhedraCalorimeter) s).getNumberOfSides();
234 }
235 else
236 {
237 System.out.println("Endcap calorimeter "+name[i]+" is unknown type");
238 subtype[i] = "unknown";
239
240 }
241 }
242 else
243 {
244 System.out.println("Calorimeter "+name[i]+" is not barrel or endcap: Information lost");
245 subtype[i] = "unknown";
246 }
247 }
248
249 if (debug)
250 printOut(System.out);
251 }
252
253
254
255
256
257 public Subdetector getSubdetector(String s)
258 {
259 return getSubdetector(Calorimeter.CalorimeterType.fromString(s));
260 }
261
262
263
264
265
266
267 public Subdetector getSubdetector(Calorimeter.CalorimeterType s)
268 {
269 Integer ind = indexmap.get(s);
270 if(ind == null)
271 {
272 System.out.println("Type "+s+" did not map to a CalorimeterType");
273 return null;
274 }
275 index = ind.intValue();
276 return subdetector[index];
277 }
278
279
280
281
282
283 public IDDecoder getIDDecoder(String s)
284 {
285 return getIDDecoder(Calorimeter.CalorimeterType.fromString(s));
286 }
287
288
289
290
291
292
293 public IDDecoder getIDDecoder(Calorimeter.CalorimeterType s)
294 {
295 Integer ind = indexmap.get(s);
296 if(ind == null)
297 {
298 System.out.println("Type "+s+" did not map to a CalorimeterType");
299 return null;
300 }
301 index = ind.intValue();
302 return idd[index];
303 }
304
305
306
307
308
309 public String getName(String s)
310 {
311 return getName(Calorimeter.CalorimeterType.fromString(s));
312 }
313
314
315
316
317
318
319 public String getName(Calorimeter.CalorimeterType s)
320 {
321 Integer ind = indexmap.get(s);
322 if(ind == null)
323 {
324 System.out.println("Type "+s+" did not map to a CalorimeterType");
325 return null;
326 }
327 index = ind.intValue();
328 return name[index];
329 }
330
331
332
333
334
335 public String getCollectionName(String s)
336 {
337 return getCollectionName(Calorimeter.CalorimeterType.fromString(s));
338 }
339
340
341
342
343
344
345 public String getCollectionName(Calorimeter.CalorimeterType s)
346 {
347 Integer ind = indexmap.get(s);
348 if(ind == null)
349 {
350 System.out.println("Type "+s+" did not map to a CalorimeterType");
351 return null;
352 }
353 index = ind.intValue();
354 return collname[index];
355 }
356
357
358
359
360
361 public String getDigiCollectionName(String s)
362 {
363 return getDigiCollectionName(Calorimeter.CalorimeterType.fromString(s));
364 }
365
366
367
368
369
370
371 public String getDigiCollectionName(Calorimeter.CalorimeterType s)
372 {
373 Integer ind = indexmap.get(s);
374 if(ind == null)
375 {
376 System.out.println("Type "+s+" did not map to a CalorimeterType");
377 return null;
378 }
379 index = ind.intValue();
380 return digicollname[index];
381 }
382
383
384
385
386
387 public String getCalorimeterType(String s)
388 {
389 return getCalorimeterType(Calorimeter.CalorimeterType.fromString(s));
390 }
391
392
393
394
395
396
397 public String getCalorimeterType(Calorimeter.CalorimeterType s)
398 {
399 Integer ind = indexmap.get(s);
400 if(ind == null)
401 {
402 System.out.println("Type "+s+" did not map to a CalorimeterType");
403 return null;
404 }
405 index = ind.intValue();
406 return subtype[index];
407 }
408
409
410
411
412
413 public int getSystemID(String s)
414 {
415 return getSystemID(Calorimeter.CalorimeterType.fromString(s));
416 }
417
418
419
420
421
422
423 public int getSystemID(Calorimeter.CalorimeterType s)
424 {
425 Integer ind = indexmap.get(s);
426 if(ind == null)
427 {
428 System.out.println("Type "+s+" did not map to a CalorimeterType");
429 return -1;
430 }
431 index = ind.intValue();
432 return sysid[index];
433 }
434
435
436
437
438
439 public int getNLayers(String s)
440 {
441 return getNLayers(Calorimeter.CalorimeterType.fromString(s));
442 }
443
444
445
446
447
448
449 public int getNLayers(Calorimeter.CalorimeterType s)
450 {
451 Integer ind = indexmap.get(s);
452 if(ind == null)
453 {
454 System.out.println("Type "+s+" did not map to a CalorimeterType");
455 return -1;
456 }
457 index = ind.intValue();
458 return nlayers[index];
459 }
460
461
462
463
464
465 public int getNSides(String s)
466 {
467 return getNSides(Calorimeter.CalorimeterType.fromString(s));
468 }
469
470
471
472
473
474
475 public int getNSides(Calorimeter.CalorimeterType s)
476 {
477 Integer ind = indexmap.get(s);
478 if(ind == null)
479 {
480 System.out.println("Type "+s+" did not map to a CalorimeterType");
481 return -1;
482 }
483 index = ind.intValue();
484 return nsides[index];
485 }
486
487
488
489
490
491 public double getRMax(String s)
492 {
493 return getRMax(Calorimeter.CalorimeterType.fromString(s));
494 }
495
496
497
498
499
500
501 public double getRMax(Calorimeter.CalorimeterType s)
502 {
503 Integer ind = indexmap.get(s);
504 if(ind == null)
505 {
506 System.out.println("Type "+s+" did not map to a CalorimeterType");
507 return -1.;
508 }
509 index = ind.intValue();
510 return rmax[index];
511 }
512
513
514
515
516
517 public double getRMin(String s)
518 {
519 return getRMin(Calorimeter.CalorimeterType.fromString(s));
520 }
521
522
523
524
525
526
527 public double getRMin(Calorimeter.CalorimeterType s)
528 {
529 Integer ind = indexmap.get(s);
530 if(ind == null)
531 {
532 System.out.println("Type "+s+" did not map to a CalorimeterType");
533 return -1.;
534 }
535 index = ind.intValue();
536 return rmin[index];
537 }
538
539
540
541
542
543 public double getZMin(String s)
544 {
545 return getZMin(Calorimeter.CalorimeterType.fromString(s));
546 }
547
548
549
550
551
552
553 public double getZMin(Calorimeter.CalorimeterType s)
554 {
555 Integer ind = indexmap.get(s);
556 if(ind == null)
557 {
558 System.out.println("Type "+s+" did not map to a CalorimeterType");
559 return -1.;
560 }
561 index = ind.intValue();
562 return zmin[index];
563 }
564
565
566
567
568
569 public double getZMax(String s)
570 {
571 return getZMax(Calorimeter.CalorimeterType.fromString(s));
572 }
573
574
575
576
577
578
579 public double getZMax(Calorimeter.CalorimeterType s)
580 {
581 Integer ind = indexmap.get(s);
582 if(ind == null)
583 {
584 System.out.println("Type "+s+" did not map to a CalorimeterType");
585 return -1.;
586 }
587 index = ind.intValue();
588 return zmax[index];
589 }
590
591
592
593
594
595
596 public List<Double> getMeanDe(String s)
597 {
598 return getMeanDe(Calorimeter.CalorimeterType.fromString(s));
599 }
600
601
602
603
604
605
606
607 public List<Double> getMeanDe(Calorimeter.CalorimeterType s)
608 {
609 Integer ind = indexmap.get(s);
610 if(ind == null)
611 {
612 System.out.println("Type "+s+" did not map to a CalorimeterType");
613 return null;
614 }
615 index = ind.intValue();
616 return de[index];
617 }
618
619
620
621
622
623
624 public List<Double> getNRad(String s)
625 {
626 return getNRad(Calorimeter.CalorimeterType.fromString(s));
627 }
628
629
630
631
632
633
634
635 public List<Double> getNRad(Calorimeter.CalorimeterType s)
636 {
637 Integer ind = indexmap.get(s);
638 if(ind == null)
639 {
640 System.out.println("Type "+s+" did not map to a CalorimeterType");
641 return null;
642 }
643 index = ind.intValue();
644 return nrad[index];
645 }
646
647
648
649
650
651
652 public List<Double> getNLam(String s)
653 {
654 return getNLam(Calorimeter.CalorimeterType.fromString(s));
655 }
656
657
658
659
660
661
662
663 public List<Double> getNLam(Calorimeter.CalorimeterType s)
664 {
665 Integer ind = indexmap.get(s);
666 if(ind == null)
667 {
668 System.out.println("Type "+s+" did not map to a CalorimeterType");
669 return null;
670 }
671 index = ind.intValue();
672 return nlam[index];
673 }
674
675
676
677
678
679
680
681 public double getMeanDe(String s, int l)
682 {
683 return getMeanDe(Calorimeter.CalorimeterType.fromString(s),l);
684 }
685
686
687
688
689
690
691
692
693 public double getMeanDe(Calorimeter.CalorimeterType s, int l)
694 {
695 List<Double> t = getMeanDe(s);
696 if( (l < 0)||(l >= t.size()) )
697 {
698 System.out.println("Layer "+l+" out of range for "+s);
699 return 0.;
700 }
701 return t.get(l).doubleValue();
702 }
703
704
705
706
707
708
709
710 public double getNRad(String s, int l)
711 {
712 return getNRad(Calorimeter.CalorimeterType.fromString(s),l);
713 }
714
715
716
717
718
719
720
721
722 public double getNRad(Calorimeter.CalorimeterType s, int l)
723 {
724 List<Double> t = getNRad(s);
725 if( (l < 0)||(l >= t.size()) )
726 {
727 System.out.println("Layer "+l+" out of range for "+s);
728 return 0.;
729 }
730 return t.get(l).doubleValue();
731 }
732
733
734
735
736
737
738
739 public double getNLam(String s, int l)
740 {
741 return getNLam(Calorimeter.CalorimeterType.fromString(s),l);
742 }
743
744
745
746
747
748
749
750
751 public double getNLam(Calorimeter.CalorimeterType s, int l)
752 {
753 List<Double> t = getNLam(s);
754 if( (l < 0)||(l >= t.size()) )
755 {
756 System.out.println("Layer "+l+" out of range for "+s);
757 return 0.;
758 }
759 return t.get(l).doubleValue();
760 }
761
762 public void printOut(PrintStream ps)
763 {
764 ps.println();
765 ps.println("---- CalorimeterInformation ----");
766 ps.println();
767 for ( int i = 0; i < ncal; i++)
768 {
769 Calorimeter cal = (Calorimeter)sublist.get(i);
770 ps.println(cal.getCalorimeterType().toString() + " : " + cal.getName());
771
772
773
774
775
776
777
778
779
780 ps.println(" rmin = " + rmin[i]);
781 ps.println(" rmax = " + rmax[i]);
782 ps.println(" zmin = " + zmin[i]);
783 ps.println(" zmax = " + zmax[i]);
784 ps.println();
785 }
786 }
787 }