001
002
003
004
005
006
007
008
009
010 #include "CaloClusterCorrection/CaloFillRectangularCluster.h"
011 #include "CaloUtils/CaloLayerCalculator.h"
012 #include "CaloEvent/CaloCell.h"
013 #include "CaloDetDescr/CaloDetDescrElement.h"
014 #include "CaloDetDescr/CaloDetDescriptor.h"
015 #include "CaloDetDescr/CaloPhiRange.h"
016 #include "GeoModelSvc/IGeoModelSvc.h"
017
018 #include "GaudiKernel/MsgStream.h"
019
020 #include "StoreGate/StoreGate.h"
021 #include "StoreGate/StoreGateSvc.h"
022 #include "CaloEvent/CaloCellContainer.h"
023 #include "CaloUtils/CaloCellList.h"
024 #include "AthenaKernel/errorcheck.h"
025 #include <algorithm>
026
027
028 namespace CaloClusterCorr {
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050 void etaphi_range (double eta,
051 double phi,
052 CaloCell_ID::CaloSample sampling,
053 double& deta,
054 double& dphi)
055 {
056 static CaloPhiRange range;
057 deta = 0;
058 dphi = 0;
059
060
061 const CaloDetDescrManager* dd_man = CaloDetDescrManager::instance();
062 CaloDetDescrElement* elt = dd_man->get_element (sampling, eta, phi);
063 if (!elt) return;
064
065
066 const double eps = 0.001;
067
068
069 CaloDetDescrElement* elt_l = dd_man->get_element
070 (sampling,
071 eta - elt->deta() - eps,
072 phi);
073 double deta_l = 0;
074 if (elt_l)
075 deta_l = std::abs (eta - elt_l->eta()) + eps;
076
077
078 CaloDetDescrElement* elt_r = dd_man->get_element
079 (sampling,
080 eta + elt->deta() + eps,
081 phi);
082 double deta_r = 0;
083 if (elt_r)
084 deta_r = std::abs (eta - elt_r->eta()) + eps;
085
086
087 deta = 2 * std::max (deta_r, deta_l);
088
089
090
091
092
093
094
095 elt_l = dd_man->get_element
096 (sampling,
097 eta - elt->deta() - eps,
098 range.fix (phi - elt->dphi() - eps));
099 double dphi_l = 0;
100 if (elt_l)
101 dphi_l = std::abs (range.fix (phi - elt_l->phi())) + eps;
102
103
104 elt_r = dd_man->get_element
105 (sampling,
106 eta + elt->deta() + eps,
107 range.fix (phi - elt->dphi() - eps));
108 double dphi_r = 0;
109 if (elt_r)
110 dphi_r = std::abs (range.fix (phi - elt_r->phi())) + eps;
111
112
113 dphi = 2 * std::max (dphi_l, dphi_r);
114 }
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131 class SamplingHelper
132 {
133 public:
134
135
136
137
138
139 SamplingHelper (CaloClusterCorrection& parent,
140 CaloCluster* cluster);
141
142
143
144 virtual ~SamplingHelper() {}
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165 virtual void
166 calculate (double eta,
167 double phi,
168 double deta,
169 double dphi,
170 CaloSampling::CaloSample sampling,
171 bool dofill = false) = 0;
172
173
174
175 virtual const CaloCell* max_et_cell() const = 0;
176
177
178 virtual bool empty() const = 0;
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195 void
196 calculate_cluster (double eta,
197 double phi,
198 double deta,
199 double dphi,
200 CaloSampling::CaloSample sampling);
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229 void
230 calculate_and_set (double eta,
231 double phi,
232 double deta,
233 double dphi,
234 double fallback_eta,
235 double fallback_phi,
236 CaloSampling::CaloSample sampling,
237 bool allow_badpos = false);
238
239
240
241 CaloCluster* cluster() const;
242
243
244 double etam() const;
245
246
247 double phim() const;
248
249
250 double etamax() const;
251
252
253 double phimax() const;
254
255
256 protected:
257
258 CaloLayerCalculator m_calc;
259
260
261 CaloClusterCorrection& m_parent;
262
263
264 CaloCluster* m_cluster;
265
266
267 double m_etam;
268
269
270 double m_phim;
271 };
272
273
274
275
276
277
278
279 SamplingHelper::SamplingHelper (CaloClusterCorrection& parent,
280 CaloCluster* cluster)
281 : m_parent (parent),
282 m_cluster (cluster)
283 {
284 }
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313 void
314 SamplingHelper::calculate_and_set
315 (double eta,
316 double phi,
317 double deta,
318 double dphi,
319 double fallback_eta,
320 double fallback_phi,
321 CaloSampling::CaloSample sampling,
322 bool allow_badpos)
323 {
324 calculate (eta, phi, deta, dphi, sampling, true);
325 if (!allow_badpos) {
326 if (m_etam == -999) m_etam = fallback_eta;
327 if (m_phim == -999) m_phim = fallback_phi;
328 }
329 m_parent.setsample (m_cluster,
330 sampling,
331 m_calc.em(),
332 m_etam,
333 m_phim,
334 m_calc.emax(),
335 m_calc.etamax(),
336 m_calc.phimax(),
337 m_calc.etas(),
338 m_calc.phis());
339 if (allow_badpos) {
340 if (m_etam == -999) m_etam = fallback_eta;
341 if (m_phim == -999) m_phim = fallback_phi;
342 }
343 }
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360 void
361 SamplingHelper::calculate_cluster
362 (double eta,
363 double phi,
364 double deta,
365 double dphi,
366 CaloSampling::CaloSample sampling)
367 {
368 m_calc.fill (m_cluster->begin(), m_cluster->end(),
369 eta, phi, deta, dphi, sampling);
370 m_etam = m_calc.etam();
371 m_phim = m_calc.phim();
372 }
373
374
375
376 inline
377 CaloCluster* SamplingHelper::cluster() const
378 {
379 return m_cluster;
380 }
381
382
383
384 inline
385 double SamplingHelper::etam() const
386 {
387 return m_etam;
388 }
389
390
391
392 inline
393 double SamplingHelper::phim() const
394 {
395 return m_phim;
396 }
397
398
399
400 inline
401 double SamplingHelper::etamax() const
402 {
403 return m_calc.etamax();
404 }
405
406
407
408 inline
409 double SamplingHelper::phimax() const
410 {
411 return m_calc.phimax();
412 }
413
414
415
416
417
418
419
420
421
422 struct et_compare_larem_only
423 {
424 bool operator() (const CaloCell* a, const CaloCell* b);
425 static double et (const CaloCell* cell);
426 };
427
428
429 bool et_compare_larem_only::operator() (const CaloCell* a,
430 const CaloCell* b)
431 {
432 return et(a) < et(b);
433 }
434
435
436 double et_compare_larem_only::et (const CaloCell* cell)
437 {
438 double et = cell->et();
439 if (cell->caloDDE()->getSubCalo() != CaloCell_ID::LAREM)
440 et -= 1000*GeV;
441 return et;
442 }
443
444
445
446
447
448
449
450
451 class SamplingHelper_CaloCellList
452 : public SamplingHelper
453 {
454 public:
455
456
457
458
459
460
461
462 SamplingHelper_CaloCellList (CaloClusterCorrection& parent,
463 CaloCluster* cluster,
464 const CaloCellList& list,
465 const CaloCellContainer* cell_container);
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484 virtual void
485 calculate (double eta,
486 double phi,
487 double deta,
488 double dphi,
489 CaloSampling::CaloSample sampling,
490 bool dofill = false);
491
492
493
494 virtual const CaloCell* max_et_cell() const;
495
496
497 virtual bool empty() const;
498
499
500 private:
501
502 const CaloCellList& m_list;
503
504
505 const CaloCellContainer* m_cell_container;
506 };
507
508
509
510
511
512
513
514
515
516 SamplingHelper_CaloCellList::SamplingHelper_CaloCellList
517 (CaloClusterCorrection& parent,
518 CaloCluster* cluster,
519 const CaloCellList& list,
520 const CaloCellContainer* cell_container)
521 : SamplingHelper (parent, cluster),
522 m_list (list),
523 m_cell_container (cell_container)
524 {
525 }
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544 void
545 SamplingHelper_CaloCellList::calculate
546 (double eta,
547 double phi,
548 double deta,
549 double dphi,
550 CaloSampling::CaloSample sampling,
551 bool dofill)
552 {
553 m_calc.fill (m_list.begin(), m_list.end(),
554 eta, phi, deta, dphi, sampling,
555 dofill ? m_cluster : 0,
556 m_cell_container);
557 m_etam = m_calc.etam();
558 m_phim = m_calc.phim();
559 }
560
561
562
563 const CaloCell* SamplingHelper_CaloCellList::max_et_cell() const
564 {
565 return *std::max_element (m_list.begin(), m_list.end(),
566 et_compare_larem_only());
567 }
568
569
570
571 bool SamplingHelper_CaloCellList::empty() const
572 {
573 return m_list.begin() == m_list.end();
574 }
575
576
577
578
579
580
581
582
583 class SamplingHelper_Cluster
584 : public SamplingHelper
585 {
586 public:
587
588
589
590
591
592 SamplingHelper_Cluster (CaloClusterCorrection& parent,
593 CaloCluster* cluster);
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610 virtual void
611 calculate (double eta,
612 double phi,
613 double deta,
614 double dphi,
615 CaloSampling::CaloSample sampling,
616 bool dofill = false);
617
618
619 virtual const CaloCell* max_et_cell() const;
620
621
622 virtual bool empty() const;
623 };
624
625
626
627
628
629
630
631 SamplingHelper_Cluster::SamplingHelper_Cluster (CaloClusterCorrection& parent,
632 CaloCluster* cluster)
633 : SamplingHelper (parent, cluster)
634 {
635 }
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653 void
654 SamplingHelper_Cluster::calculate
655 (double eta,
656 double phi,
657 double deta,
658 double dphi,
659 CaloSampling::CaloSample sampling,
660 bool )
661 {
662 calculate_cluster (eta, phi, deta, dphi, sampling);
663 }
664
665
666
667 const CaloCell* SamplingHelper_Cluster::max_et_cell() const
668 {
669 return *std::max_element(m_cluster->begin(), m_cluster->end(),
670 et_compare_larem_only());
671 }
672
673
674
675 bool SamplingHelper_Cluster::empty() const
676 {
677 return m_cluster->begin() == m_cluster->end();
678 }
679
680
681 }
682
683
684
685
686
687
688
689
690
691
692
693 CaloFillRectangularCluster::CaloFillRectangularCluster
694 (const std::string& type,
695 const std::string& name,
696 const IInterface* parent)
697 : CaloClusterCorrection(type, name, parent)
698 {
699
700 declareProperty("eta_size", m_neta = 5);
701 declareProperty("phi_size", m_nphi = 5);
702 declareProperty("fill_cluster", m_fill_cluster = true);
703 declareProperty("cells_name", m_cellsName = "AllCalo");
704 }
705
706
707
708
709
710
711
712 StatusCode CaloFillRectangularCluster::initialize()
713 {
714
715 CHECK( CaloClusterCorrection::initialize() );
716
717
718 CHECK( service("StoreGateSvc", m_storeGate) );
719 MsgStream log(msgSvc(),name());
720
721 StoreGateSvc* detStore;
722 if (service("DetectorStore", detStore).isFailure()) {
723 log << MSG::ERROR << "Unable to access DetectoreStore" << endreq ;
724 return StatusCode::FAILURE;
725 }
726
727 const IGeoModelSvc *geoModel=0;
728 StatusCode sc = service("GeoModelSvc", geoModel);
729 if(sc.isFailure())
730 {
731 log << MSG::ERROR << "Could not locate GeoModelSvc" << endreq;
732 return sc;
733 }
734
735
736 int dummyInt=0;
737 std::list<std::string> dummyList;
738
739 if (geoModel->geoInitialized())
740 {
741 return geoInit(dummyInt,dummyList);
742 }
743 else
744 {
745 sc = detStore->regFcn(&IGeoModelSvc::geoInit,
746 geoModel,
747 &CaloFillRectangularCluster::geoInit,this);
748 if(sc.isFailure())
749 {
750 log << MSG::ERROR << "Could not register geoInit callback" << endreq;
751 return sc;
752 }
753 }
754 return sc;
755 }
756
757 StatusCode
758 CaloFillRectangularCluster::geoInit(IOVSVC_CALLBACK_ARGS)
759 {
760
761 {
762 const CaloDetDescrManager* dd_man = CaloDetDescrManager::instance();
763 CaloDetDescrElement* elt = dd_man->get_element (CaloCell_ID::EMB2,
764 0.001,
765 0.001);
766 if (elt) {
767 m_detas2 = elt->deta();
768 m_dphis2 = elt->dphi();
769 }
770 else {
771
772
773
774
775 m_detas2 = 0.025;
776 m_dphis2 = M_PI/128.;
777 }
778 }
779
780
781 m_deta0 = m_detas2*m_neta;
782 m_dphi0 = m_dphis2*4;
783
784 if (m_nphi >= 7)
785 m_dphi0 = m_dphi0*2;
786 else
787 m_dphi0 = m_dphi0*1.5;
788
789 m_deta1 = m_deta0;
790 m_dphi1 = m_dphi0;
791
792 m_deta2 = m_detas2*m_neta;
793 m_dphi2 = m_dphis2*m_nphi;
794
795 m_deta3 = (2*m_detas2)*(0.5 + (m_neta/2.));
796 m_dphi3 = m_dphi2;
797
798 return StatusCode::SUCCESS;
799 }
800
801
802
803
804
805
806
807
808
809 void
810 CaloFillRectangularCluster::makeCorrection1(CaloClusterCorr::SamplingHelper&
811 helper,
812 double eta,
813 double phi,
814 const CaloSampling::CaloSample
815 samplings[4])
816 {
817
818 helper.calculate_and_set (eta, phi, m_deta2, m_dphi2, eta, phi,
819 samplings[2], true);
820 double eta2 = helper.etam();
821 double phi2 = helper.phim();
822
823
824 helper.calculate_and_set (eta2, phi2, m_deta1, m_dphi1, eta2, phi2,
825 samplings[1]);
826 double eta1 = helper.etam();
827 double phi1 = helper.phim();
828
829
830
831 CaloCell_ID::CaloSample xsample;
832 if (samplings[1] == CaloSampling::EMB1)
833 xsample = CaloCell_ID::EMB1;
834 else
835 xsample = CaloCell_ID::EME1;
836
837
838 double detastr, dphistr;
839 CaloClusterCorr::etaphi_range (helper.etamax(), helper.phimax(),
840 xsample,
841 detastr, dphistr);
842
843 if (detastr > 0 && dphistr > 0) {
844 helper.calculate_cluster (helper.etamax(), helper.phimax(),
845 detastr, dphistr, samplings[1]);
846
847 if (helper.etam()!=-999.) {
848 eta1 = helper.etam();
849 helper.cluster()->seteta(samplings[1], eta1);
850 }
851 }
852
853
854 helper.calculate_and_set (eta1, phi2, m_deta0, m_dphi0, eta1, phi1,
855 samplings[0]);
856
857
858 helper.calculate_and_set (eta2, phi2, m_deta3, m_dphi3, eta2, phi2,
859 samplings[3]);
860 }
861
862
863
864
865
866
867 void
868 CaloFillRectangularCluster::makeCorrection2 (CaloClusterCorr::SamplingHelper&
869 helper)
870 {
871
872
873 if (helper.empty())
874 return;
875
876
877 CaloCluster* cluster = helper.cluster();
878 double eta, phi;
879 const CaloCell* cell_max = helper.max_et_cell();
880 get_seed (cluster, cell_max, eta, phi);
881 double aeta = fabs(eta);
882
883
884 int neta = cluster->getClusterEtaSize();
885 int nphi = cluster->getClusterPhiSize();
886
887 if (m_neta != neta || m_nphi != nphi) {
888 unsigned int oldSize = cluster->getClusterSize();
889 unsigned int newSize = oldSize;
890 switch(oldSize) {
891 case CaloCluster::SW_softe:
892 break;
893 case CaloCluster::SW_55ele:
894 case CaloCluster::SW_35ele:
895 case CaloCluster::SW_37ele:
896 if (m_neta==5 && m_nphi==5) newSize=CaloCluster::SW_55ele;
897 if (m_neta==3 && m_nphi==5) newSize=CaloCluster::SW_35ele;
898 if (m_neta==3 && m_nphi==7) newSize=CaloCluster::SW_37ele;
899 if (m_neta==7 && m_nphi==11) newSize=CaloCluster::SW_7_11;
900 break;
901 case CaloCluster::SW_55gam:
902 case CaloCluster::SW_35gam:
903 case CaloCluster::SW_37gam:
904 if (m_neta==5 && m_nphi==5) newSize=CaloCluster::SW_55gam;
905 if (m_neta==3 && m_nphi==5) newSize=CaloCluster::SW_35gam;
906 if (m_neta==3 && m_nphi==7) newSize=CaloCluster::SW_37gam;
907 if (m_neta==7 && m_nphi==11) newSize=CaloCluster::SW_7_11;
908 break;
909 case CaloCluster::SW_55Econv:
910 case CaloCluster::SW_35Econv:
911 case CaloCluster::SW_37Econv:
912 if (m_neta==5 && m_nphi==5) newSize=CaloCluster::SW_55Econv;
913 if (m_neta==3 && m_nphi==5) newSize=CaloCluster::SW_35Econv;
914 if (m_neta==3 && m_nphi==7) newSize=CaloCluster::SW_37Econv;
915 if (m_neta==7 && m_nphi==11) newSize=CaloCluster::SW_7_11;
916 break;
917 default:
918 if (m_neta==5 && m_nphi==5) newSize=CaloCluster::SW_55ele;
919 if (m_neta==3 && m_nphi==5) newSize=CaloCluster::SW_35ele;
920 if (m_neta==3 && m_nphi==7) newSize=CaloCluster::SW_37ele;
921 if (m_neta==7 && m_nphi==11) newSize=CaloCluster::SW_7_11;
922 break;
923 }
924 cluster->setClusterSize(newSize);
925 }
926
927
928 static const CaloSampling::CaloSample samplings_b[4] =
929 { CaloSampling::PreSamplerB, CaloSampling::EMB1,
930 CaloSampling::EMB2, CaloSampling::EMB3 };
931 static const CaloSampling::CaloSample samplings_e[4] =
932 { CaloSampling::PreSamplerE, CaloSampling::EME1,
933 CaloSampling::EME2, CaloSampling::EME3 };
934
935
936
937
938
939
940 if (aeta < 1.6) {
941 cluster->setBarrel (true);
942 makeCorrection1 (helper, eta, phi, samplings_b);
943 }
944
945
946 if (aeta > 1.3) {
947 cluster->setEndcap (true);
948 makeCorrection1 (helper, eta, phi, samplings_e);
949 }
950
951
952
953 if (aeta >= 1.3 && aeta < 1.6){
954 cluster->setEndcap (true);
955 cluster->setBarrel (true);
956 }
957
958 if (aeta >= 1.6){
959 cluster->setEndcap (true);
960 cluster->setBarrel (false);
961 }
962
963
964 double cl_ene = 0;
965 for(int i=0; i<4; i++ ){
966 cl_ene += cluster->eSample(samplings_b[i]);
967 cl_ene += cluster->eSample(samplings_e[i]);
968 }
969 cluster->setE(cl_ene);
970
971 }
972
973
974
975
976
977
978 void CaloFillRectangularCluster::makeCorrection(CaloCluster* cluster)
979 {
980 MsgStream log( msgSvc(), name() );
981 log << MSG::DEBUG << "Executing CaloFillRectangularCluster" << endreq;
982
983 if (m_fill_cluster) {
984
985
986 cluster->removeCells();
987
988
989 const CaloCellContainer* cell_container = 0;
990 if ( ! m_storeGate->retrieve (cell_container, m_cellsName).isSuccess()) {
991 REPORT_ERROR(StatusCode::FAILURE)
992 << "Can't retrieve cell container " << m_cellsName;
993 return;
994 }
995
996
997 double eta = cluster->eta0();
998 double phi = cluster->phi0();
999 static CaloPhiRange range;
1000 phi = range.fix (phi);
1001
1002
1003
1004
1005 CaloCellList cell_list(cell_container);
1006 cell_list.select(eta,phi,m_detas2*(m_neta+5),m_dphis2*(m_nphi+5));
1007
1008
1009 CaloClusterCorr::SamplingHelper_CaloCellList helper (*this,
1010 cluster,
1011 cell_list,
1012 cell_container);
1013 makeCorrection2 (helper);
1014 }
1015 else {
1016
1017 CaloClusterCorr::SamplingHelper_Cluster helper (*this, cluster);
1018 makeCorrection2 (helper);
1019 }
1020 }
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034 void CaloFillRectangularCluster::get_seed (const CaloCluster* cluster,
1035 const CaloCell* max_et_cell,
1036 double& eta,
1037 double& phi)
1038 {
1039
1040
1041
1042
1043 static CaloPhiRange range;
1044 const CaloDetDescrElement* elt = max_et_cell->caloDDE();
1045 double phi_shift = elt->phi()-elt->phi_raw();
1046 double eta_shift = elt->eta()-elt->eta_raw();
1047 eta = cluster->eta0()+eta_shift;
1048 phi = range.fix(cluster->phi0()+phi_shift);
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071 if ((elt->is_lar_em_endcap_inner() &&
1072 std::abs(elt->eta_raw()) - elt->deta() <
1073 elt->descriptor()->calo_eta_min()) ||
1074 (elt->is_lar_em_endcap_outer() &&
1075 std::abs(elt->eta_raw()) + elt->deta() >
1076 elt->descriptor()->calo_eta_max()))
1077 {
1078
1079 if (std::abs (eta - elt->eta()) > m_deta2/2) {
1080
1081 eta = elt->eta();
1082 }
1083 }
1084 }
Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems |
This page was automatically generated by the
LXR engine.
|
|