ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerSuperClusters.cc
Revision: 1.13
Committed: Sun Sep 19 23:47:53 2010 UTC (14 years, 7 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e
Changes since 1.12: +6 -4 lines
Log Message:
Avoid dereferencing basic cluster ptrs if map is not available

File Contents

# User Rev Content
1 bendavid 1.13 // $Id: FillerSuperClusters.cc,v 1.12 2010/08/18 01:36:11 bendavid Exp $
2 sixie 1.1
3     #include "MitProd/TreeFiller/interface/FillerSuperClusters.h"
4     #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
5     #include "DataFormats/EgammaReco/interface/SuperCluster.h"
6     #include "MitAna/DataTree/interface/BasicCluster.h"
7 loizides 1.5 #include "MitAna/DataTree/interface/SuperClusterCol.h"
8 sixie 1.1 #include "MitAna/DataTree/interface/Names.h"
9 loizides 1.5 #include "MitProd/ObjectService/interface/ObjectService.h"
10 sixie 1.10 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
11 sixie 1.1
12     using namespace std;
13     using namespace edm;
14     using namespace mithep;
15    
16     //--------------------------------------------------------------------------------------------------
17     FillerSuperClusters::FillerSuperClusters(const ParameterSet &cfg, const char *name, bool active) :
18     BaseFiller(cfg,name,active),
19     edmName_(Conf().getUntrackedParameter<string>("edmName","hybridSuperClusters")),
20     mitName_(Conf().getUntrackedParameter<string>("mitName","SuperClusters")),
21     basicClusterMapName_(Conf().getUntrackedParameter<string>("basicClusterMapName",
22     "BasicClusterMap")),
23 bendavid 1.11 caloTowerDetIdMapName_(Conf().getUntrackedParameter<string>("caloTowerDetIdMapName",
24     "CaloTowerDetIdMap")),
25 sixie 1.1 superClusterMapName_(Conf().getUntrackedParameter<string>("superClusterMapName",
26     "SuperClusterMap")),
27 bendavid 1.2 superClusterIdMapName_(Conf().getUntrackedParameter<string>("superClusterIdMapName",
28 loizides 1.7 "SuperClusterIdMap")),
29 sixie 1.10 caloTowerName_(Conf().getUntrackedParameter<string>("caloTowerName","towerMaker")),
30 sixie 1.1 basicClusterMap_(0),
31 bendavid 1.11 caloTowerDetIdMap_(0),
32 sixie 1.1 superClusters_(new mithep::SuperClusterArr(25)),
33 bendavid 1.2 superClusterMap_(new mithep::SuperClusterMap),
34     superClusterIdMap_(new mithep::SuperClusterIdMap)
35 sixie 1.1 {
36     // Constructor.
37     }
38    
39     //--------------------------------------------------------------------------------------------------
40     FillerSuperClusters::~FillerSuperClusters()
41     {
42     // Destructor.
43    
44     delete superClusters_;
45     delete superClusterMap_;
46 bendavid 1.2 delete superClusterIdMap_;
47 sixie 1.1 }
48    
49     //--------------------------------------------------------------------------------------------------
50 bendavid 1.9 void FillerSuperClusters::BookDataBlock(TreeWriter &tws)
51 sixie 1.1 {
52 loizides 1.4 // Add super cluster branch to tree and get pointers to maps.
53    
54     tws.AddBranch(mitName_,&superClusters_);
55     OS()->add<SuperClusterArr>(superClusters_,mitName_);
56    
57     if (!basicClusterMapName_.empty()) {
58     basicClusterMap_ = OS()->get<BasicClusterMap>(basicClusterMapName_);
59     if (basicClusterMap_)
60     AddBranchDep(mitName_,basicClusterMap_->GetBrName());
61     }
62 sixie 1.1
63 bendavid 1.11 if (!caloTowerDetIdMapName_.empty()) {
64     caloTowerDetIdMap_ = OS()->get<CaloTowerDetIdMap>(caloTowerDetIdMapName_);
65     if (caloTowerDetIdMap_)
66     AddBranchDep(mitName_,caloTowerDetIdMap_->GetBrName());
67     }
68    
69 loizides 1.4 if (!superClusterMapName_.empty()) {
70     superClusterMap_->SetBrName(mitName_);
71     OS()->add<SuperClusterMap>(superClusterMap_,superClusterMapName_);
72     }
73     if (!superClusterIdMapName_.empty()) {
74     superClusterIdMap_->SetBrName(mitName_);
75     OS()->add<SuperClusterIdMap>(superClusterIdMap_,superClusterIdMapName_);
76     }
77 sixie 1.1 }
78    
79     //--------------------------------------------------------------------------------------------------
80     void FillerSuperClusters::FillDataBlock(const edm::Event &event,
81 loizides 1.4 const edm::EventSetup &setup)
82 sixie 1.1 {
83 loizides 1.4 // Fill the collection.
84    
85 bendavid 1.3 superClusters_->Delete();
86 sixie 1.1 superClusterMap_->Reset();
87 bendavid 1.2 superClusterIdMap_->Reset();
88 sixie 1.1
89     Handle<reco::SuperClusterCollection> hSuperClusterProduct;
90     GetProduct(edmName_, hSuperClusterProduct, event);
91 sixie 1.10
92     Handle<CaloTowerCollection> hCaloTowerProduct;
93     GetProduct(caloTowerName_, hCaloTowerProduct, event);
94    
95 sixie 1.1 superClusterMap_->SetEdmProductId(hSuperClusterProduct.id().id());
96     const reco::SuperClusterCollection inSuperClusters = *(hSuperClusterProduct.product());
97    
98     // loop through all super clusters
99     for (reco::SuperClusterCollection::const_iterator inSC = inSuperClusters.begin();
100     inSC != inSuperClusters.end(); ++inSC) {
101    
102     mithep::SuperCluster *outSC = superClusters_->Allocate();
103     new (outSC) mithep::SuperCluster();
104    
105     outSC->SetXYZ(inSC->x(),inSC->y(),inSC->z());
106     outSC->SetEnergy(inSC->energy());
107     outSC->SetRawEnergy(inSC->rawEnergy());
108     outSC->SetPreshowerEnergy(inSC->preshowerEnergy());
109     outSC->SetPhiWidth(inSC->phiWidth());
110     outSC->SetEtaWidth(inSC->etaWidth());
111    
112 sixie 1.10 //Compute Hadronic Energy behind the supercluster (within DR < 0.15)
113     EgammaTowerIsolation towerIsoDepth1(0.15,0.,0.,1,hCaloTowerProduct.product()) ;
114     EgammaTowerIsolation towerIsoDepth2(0.15,0.,0.,2,hCaloTowerProduct.product()) ;
115     outSC->SetHcalDepth1Energy(towerIsoDepth1.getTowerESum(&(*inSC)));
116     outSC->SetHcalDepth2Energy(towerIsoDepth2.getTowerESum(&(*inSC)));
117    
118 loizides 1.4 // set the seed
119 sixie 1.1 if (basicClusterMap_ && inSC->seed().isNonnull())
120     outSC->SetSeed(basicClusterMap_->GetMit(inSC->seed()));
121    
122 loizides 1.4 // add basic clusters that belong to this super cluster
123 bendavid 1.13 if (basicClusterMap_) {
124     for(reco::CaloCluster_iterator bc = inSC->clustersBegin(); bc != inSC->clustersEnd(); ++bc) {
125     if (bc->isNonnull())
126     outSC->AddCluster(basicClusterMap_->GetMit(*bc));
127     }
128 sixie 1.1 }
129    
130 bendavid 1.11 //add super cluster det ids to the id map and also fill supercluster-calotower associations
131 bendavid 1.6 const std::vector< std::pair<DetId, float> > &pairs = inSC->hitsAndFractions();
132     for (std::vector< std::pair<DetId, float> >::const_iterator ipair = pairs.begin();
133     ipair < pairs.end(); ++ipair) {
134 bendavid 1.2
135 bendavid 1.6 const DetId &ihit = ipair->first;
136 bendavid 1.11
137     if (caloTowerDetIdMap_) {
138     if (caloTowerDetIdMap_->HasMit(ihit)) {
139 bendavid 1.12 const mithep::CaloTower *matchedTower = caloTowerDetIdMap_->GetMit(ihit);
140     if (!outSC->HasTower(matchedTower)) {
141     outSC->AddTower(matchedTower);
142     }
143 bendavid 1.11 }
144     }
145    
146 bendavid 1.6 superClusterIdMap_->Add(ihit,outSC);
147 bendavid 1.2 }
148 bendavid 1.11
149    
150     // add super cluster to the map
151     reco::SuperClusterRef theRef(hSuperClusterProduct, inSC-inSuperClusters.begin());
152     superClusterMap_->Add(theRef, outSC);
153    
154 sixie 1.1 }
155     superClusters_->Trim();
156     }