CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Stage2Layer2TauAlgorithmFirmwareImp1.cc
Go to the documentation of this file.
1 
10 
13 
14 
16  params_(params)
17 {
18 
20 }
21 
22 
24 
25 
26 }
27 
28 
29 void l1t::Stage2Layer2TauAlgorithmFirmwareImp1::processEvent(const std::vector<l1t::CaloCluster> & clusters,
30  const std::vector<l1t::CaloTower>& towers,
31  std::vector<l1t::Tau> & taus) {
32 
33  merging(clusters, towers, taus);
34 
35 }
36 
37 
38 // FIXME: to be organized better
39 void l1t::Stage2Layer2TauAlgorithmFirmwareImp1::merging(const std::vector<l1t::CaloCluster>& clusters, const std::vector<l1t::CaloTower>& towers, std::vector<l1t::Tau>& taus){
40  //std::cout<<"--------------- NEW EVENT -----------------------------\n";
41  //std::cout<<"---------------------------------------------------------\n";
42  // navigator
43  l1t::CaloStage2Nav caloNav;
44 
45  // Temp copy of clusters (needed to set merging flags)
46  std::vector<l1t::CaloCluster> tmpClusters(clusters);
47  // First loop: setting merging flags
48  for ( auto itr = tmpClusters.begin(); itr != tmpClusters.end(); ++itr ) {
49  if( itr->isValid() ){
50  l1t::CaloCluster& mainCluster = *itr;
51  int iEta = mainCluster.hwEta();
52  int iPhi = mainCluster.hwPhi();
53  int iEtaP = caloNav.offsetIEta(iEta, 1);
54  int iEtaM = caloNav.offsetIEta(iEta, -1);
55  int iPhiP2 = caloNav.offsetIPhi(iPhi, 2);
56  int iPhiP3 = caloNav.offsetIPhi(iPhi, 3);
57  int iPhiM2 = caloNav.offsetIPhi(iPhi, -2);
58  int iPhiM3 = caloNav.offsetIPhi(iPhi, -3);
59 
60 
61  const l1t::CaloCluster& clusterN2 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiM2);
62  const l1t::CaloCluster& clusterN3 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiM3);
63  const l1t::CaloCluster& clusterN2W = l1t::CaloTools::getCluster(tmpClusters, iEtaM, iPhiM2);
64  const l1t::CaloCluster& clusterN2E = l1t::CaloTools::getCluster(tmpClusters, iEtaP, iPhiM2);
65  const l1t::CaloCluster& clusterS2 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiP2);
66  const l1t::CaloCluster& clusterS3 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiP3);
67  const l1t::CaloCluster& clusterS2W = l1t::CaloTools::getCluster(tmpClusters, iEtaM, iPhiP2);
68  const l1t::CaloCluster& clusterS2E = l1t::CaloTools::getCluster(tmpClusters, iEtaP, iPhiP2);
69 
70  std::list<l1t::CaloCluster> satellites;
71  if(clusterN2 .isValid()) satellites.push_back(clusterN2);
72  if(clusterN3 .isValid()) satellites.push_back(clusterN3);
73  if(clusterN2W.isValid()) satellites.push_back(clusterN2W);
74  if(clusterN2E.isValid()) satellites.push_back(clusterN2E);
75  if(clusterS2 .isValid()) satellites.push_back(clusterS2);
76  if(clusterS3 .isValid()) satellites.push_back(clusterS3);
77  if(clusterS2W.isValid()) satellites.push_back(clusterS2W);
78  if(clusterS2E.isValid()) satellites.push_back(clusterS2E);
79 
80  if(satellites.size()>0) {
81  satellites.sort();
82  const l1t::CaloCluster& secondaryCluster = satellites.back();
83 
84  if(secondaryCluster>mainCluster) {
85  // is secondary
86  mainCluster.setClusterFlag(CaloCluster::IS_SECONDARY, true);
87  // to be merged up or down?
88  if(secondaryCluster.hwPhi()==iPhiP2 || secondaryCluster.hwPhi()==iPhiP3) {
89  mainCluster.setClusterFlag(CaloCluster::MERGE_UPDOWN, true); // 1 (down)
90  }
91  else if(secondaryCluster.hwPhi()==iPhiM2 || secondaryCluster.hwPhi()==iPhiM3) {
92  mainCluster.setClusterFlag(CaloCluster::MERGE_UPDOWN, false); // 0 (up)
93  }
94  // to be merged left or right?
95  if(secondaryCluster.hwEta()==iEtaP) {
96  mainCluster.setClusterFlag(CaloCluster::MERGE_LEFTRIGHT, true); // 1 (right)
97  }
98  else if(secondaryCluster.hwEta()==iEta || secondaryCluster.hwEta()==iEtaM) {
99  mainCluster.setClusterFlag(CaloCluster::MERGE_LEFTRIGHT, false); // 0 (left)
100  }
101  }
102  else {
103  // is main cluster
104  mainCluster.setClusterFlag(CaloCluster::IS_SECONDARY, false);
105  // to be merged up or down?
106  if(secondaryCluster.hwPhi()==iPhiP2 || secondaryCluster.hwPhi()==iPhiP3) {
107  mainCluster.setClusterFlag(CaloCluster::MERGE_UPDOWN, true); // 1 (down)
108  }
109  else if(secondaryCluster.hwPhi()==iPhiM2 || secondaryCluster.hwPhi()==iPhiM3) {
110  mainCluster.setClusterFlag(CaloCluster::MERGE_UPDOWN, false); // 0 (up)
111  }
112  // to be merged left or right?
113  if(secondaryCluster.hwEta()==iEtaP) {
114  mainCluster.setClusterFlag(CaloCluster::MERGE_LEFTRIGHT, true); // 1 (right)
115  }
116  else if(secondaryCluster.hwEta()==iEta || secondaryCluster.hwEta()==iEtaM) {
117  mainCluster.setClusterFlag(CaloCluster::MERGE_LEFTRIGHT, false); // 0 (left)
118  }
119  }
120  }
121  }
122  }
123 
124  // Second loop: do the actual merging based on merging flags
125  for ( auto itr = tmpClusters.begin(); itr != tmpClusters.end(); ++itr ) {
126  if( itr->isValid() ){
127  l1t::CaloCluster& mainCluster = *itr;
128  int iEta = mainCluster.hwEta();
129  int iPhi = mainCluster.hwPhi();
130 
131  // physical eta/phi
132  double eta = 0.;
133  double phi = 0.;
134  double seedEta = CaloTools::towerEta(mainCluster.hwEta());
135  double seedEtaSize = CaloTools::towerEtaSize(mainCluster.hwEta());
136  double seedPhi = CaloTools::towerPhi(mainCluster.hwEta(), mainCluster.hwPhi());
137  double seedPhiSize = CaloTools::towerPhiSize(mainCluster.hwEta());
138  if (mainCluster.fgEta()==0) eta = seedEta; // center
139  else if(mainCluster.fgEta()==2) eta = seedEta + seedEtaSize*0.25; // center + 1/4
140  else if(mainCluster.fgEta()==1) eta = seedEta - seedEtaSize*0.25; // center - 1/4
141  if (mainCluster.fgPhi()==0) phi = seedPhi; // center
142  else if(mainCluster.fgPhi()==2) phi = seedPhi + seedPhiSize*0.25; // center + 1/4
143  else if(mainCluster.fgPhi()==1) phi = seedPhi - seedPhiSize*0.25; // center - 1/4
144 
145 
146  int iEtaP = caloNav.offsetIEta(iEta, 1);
147  int iEtaM = caloNav.offsetIEta(iEta, -1);
148  int iPhiP = caloNav.offsetIPhi(iPhi, 1);
149  int iPhiM = caloNav.offsetIPhi(iPhi, -1);
150  int iPhiP2 = caloNav.offsetIPhi(iPhi, 2);
151  int iPhiP3 = caloNav.offsetIPhi(iPhi, 3);
152  int iPhiM2 = caloNav.offsetIPhi(iPhi, -2);
153  int iPhiM3 = caloNav.offsetIPhi(iPhi, -3);
154 
155  const l1t::CaloCluster& clusterN2 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiM2);
156  const l1t::CaloCluster& clusterN3 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiM3);
157  const l1t::CaloCluster& clusterN2W = l1t::CaloTools::getCluster(tmpClusters, iEtaM, iPhiM2);
158  const l1t::CaloCluster& clusterN2E = l1t::CaloTools::getCluster(tmpClusters, iEtaP, iPhiM2);
159  const l1t::CaloCluster& clusterS2 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiP2);
160  const l1t::CaloCluster& clusterS3 = l1t::CaloTools::getCluster(tmpClusters, iEta, iPhiP3);
161  const l1t::CaloCluster& clusterS2W = l1t::CaloTools::getCluster(tmpClusters, iEtaM, iPhiP2);
162  const l1t::CaloCluster& clusterS2E = l1t::CaloTools::getCluster(tmpClusters, iEtaP, iPhiP2);
163 
164  std::list<l1t::CaloCluster> satellites;
165  if(clusterN2 .isValid()) satellites.push_back(clusterN2);
166  if(clusterN3 .isValid()) satellites.push_back(clusterN3);
167  if(clusterN2W.isValid()) satellites.push_back(clusterN2W);
168  if(clusterN2E.isValid()) satellites.push_back(clusterN2E);
169  if(clusterS2 .isValid()) satellites.push_back(clusterS2);
170  if(clusterS3 .isValid()) satellites.push_back(clusterS3);
171  if(clusterS2W.isValid()) satellites.push_back(clusterS2W);
172  if(clusterS2E.isValid()) satellites.push_back(clusterS2E);
173 
174  // neighbour exists
175  if(satellites.size()>0) {
176  satellites.sort();
177  const l1t::CaloCluster& secondaryCluster = satellites.back();
178  // this is the most energetic cluster
179  // merge with the secondary cluster if it is not merged to an other one
180  if(mainCluster>secondaryCluster) {
181  bool canBeMerged = true;
182  bool mergeUp = (secondaryCluster.hwPhi()==iPhiM2 || secondaryCluster.hwPhi()==iPhiM3);
183  bool mergeLeft = (secondaryCluster.hwEta()==iEtaM);
184  bool mergeRight = (secondaryCluster.hwEta()==iEtaP);
185 
186  if(mergeUp && !secondaryCluster.checkClusterFlag(CaloCluster::MERGE_UPDOWN)) canBeMerged = false;
187  if(!mergeUp && secondaryCluster.checkClusterFlag(CaloCluster::MERGE_UPDOWN)) canBeMerged = false;
188  if(mergeLeft && !secondaryCluster.checkClusterFlag(CaloCluster::MERGE_LEFTRIGHT)) canBeMerged = false;
189  if(mergeRight && secondaryCluster.checkClusterFlag(CaloCluster::MERGE_LEFTRIGHT)) canBeMerged = false;
190  if(canBeMerged) {
191  double calibPt = calibratedPt(mainCluster.hwPtEm()+secondaryCluster.hwPtEm(), mainCluster.hwPtHad()+secondaryCluster.hwPtHad(), mainCluster.hwEta());
192  math::PtEtaPhiMLorentzVector p4(calibPt, eta, phi, 0.);
193  l1t::Tau tau( p4, mainCluster.hwPt()+secondaryCluster.hwPt(), mainCluster.hwEta(), mainCluster.hwPhi(), 0);
194  taus.push_back(tau);
195 
196  //std::cout << "===================== IS MERGED ========================" << std::endl;
197 
198 
199  int hwFootPrint=0;
200  int hwEtSum=0;
201 
202  //std::cout << "taus.back().pt(): " << taus.back().pt() << std::endl;
204 
206  // SumEt in (ieta,iphi) = 5x9 centered in the cluster.Eta+1, cluster.Phi+1
207  hwEtSum = CaloTools::calHwEtSum(iEtaP,iPhiP,towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
208  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
209 
211 
212  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta to ieta=cluster.Eta+1
213  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,0,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
214  }
216  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are from ieta=cluster.Eta-1 to ieta=cluster.Eta+1
217  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
218  }
220  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are from ieta=cluster.Eta to ieta=cluster.Eta+2
221  hwFootPrint = CaloTools::calHwEtSum(iEtaP,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
222 
223  }
224  if(!mainCluster.checkClusterFlag(CaloCluster::TRIM_LEFT) && !secondaryCluster.checkClusterFlag(CaloCluster::TRIM_LEFT)){
225  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are from ieta=cluster.Eta-1 to ieta=cluster.Eta+1
226  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
227  }
228  }
230  // SumEt in (ieta,iphi) = 5x9 centered in the cluster.Eta-1, cluster.Phi+1
231  hwEtSum = CaloTools::calHwEtSum(iEtaM,iPhiP,towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
232  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
234  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are from ieta=cluster.Eta-1 to ieta=cluster.Eta+1
235  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
236  }
238  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta-1 && ieta=cluster.Eta
239  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,0,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
240  }
242  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
243  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
244  }
245  if(!mainCluster.checkClusterFlag(CaloCluster::TRIM_LEFT) && !secondaryCluster.checkClusterFlag(CaloCluster::TRIM_LEFT)){
246  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-2 to ieta=cluster.Eta
247  hwFootPrint = CaloTools::calHwEtSum(iEtaM,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
248  }
249  }
251  // SumEt in (ieta,iphi) = 5x9 centered in the cluster.Eta, cluster.Phi+1
252  hwEtSum = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
253  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
254 
256  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
257  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
258  }
260  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
261  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
262  }
264  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta && ieta=cluster.Eta+1
265  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,0,+1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
266  }
267  if(!mainCluster.checkClusterFlag(CaloCluster::TRIM_LEFT) && !secondaryCluster.checkClusterFlag(CaloCluster::TRIM_LEFT)){
268  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta-1 && ieta=cluster.Eta
269  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiP,towers,-1,0,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
270  }
271  }
272  }
274 
276  // SumEt in (ieta,iphi) = 5x9 centered in the cluster.Eta+1, cluster.Phi-1
277  hwEtSum = CaloTools::calHwEtSum(iEtaM,iPhiP,towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
278  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
279 
281  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta && ieta=cluster.Eta+1
282  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,0,+1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
283  }
285  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
286  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
287  }
289  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta to ieta=cluster.Eta+2
290  hwFootPrint = CaloTools::calHwEtSum(iEtaP,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
291  }
292  if(!mainCluster.checkClusterFlag(CaloCluster::TRIM_LEFT) && !secondaryCluster.checkClusterFlag(CaloCluster::TRIM_LEFT)){
293  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
294  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
295  }
296  }
298  // SumEt in (ieta,iphi) = 5x9 centered in the cluster.Eta-1, cluster.Phi-1
299  hwEtSum = CaloTools::calHwEtSum(iEtaM,iPhiM,towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
300  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
301 
303  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
304  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
305  }
307  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta-1 && ieta=cluster.Eta
308  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,0,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
309  }
311  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
312  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
313  }
314  if(!mainCluster.checkClusterFlag(CaloCluster::TRIM_LEFT) && !secondaryCluster.checkClusterFlag(CaloCluster::TRIM_LEFT)){
315  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-2 to ieta=cluster.Eta
316  hwFootPrint = CaloTools::calHwEtSum(iEtaM,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
317  }
318  }
320  // SumEt in (ieta,iphi) = 5x9 centered in the cluster.Eta, cluster.Phi-1 or Phi-2
321  hwEtSum = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
322  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
323 
325  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
326  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
327  }
329  //Evaluation of the tau footprint of a size 3x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta+1
330  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
331  }
333  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta to ieta=cluster.Eta+1
334  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,0,+1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
335  }
336  if(!mainCluster.checkClusterFlag(CaloCluster::TRIM_LEFT) && !secondaryCluster.checkClusterFlag(CaloCluster::TRIM_LEFT)){
337  //Evaluation of the tau footprint of a size 2x5, the slices in ieta are ieta=cluster.Eta-1 to ieta=cluster.Eta
338  hwFootPrint = CaloTools::calHwEtSum(iEta,iPhiM,towers,-1,0,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
339  }
340  }
341  }
342  int isolBit = 0;
343 
344  int nrTowers = CaloTools::calNrTowers(-1*params_->tauPUSParam(1),params_->tauPUSParam(1),1,72,towers,1,999,CaloTools::CALO);
345  unsigned int lutAddress = isoLutIndex(calibPt, nrTowers);
346 
347  isolBit = hwEtSum-hwFootPrint <= (params_->tauIsolationLUT()->data(lutAddress));
348  taus.back().setHwIso(isolBit);
349 
350  }
351  else {
352  double calibPt = calibratedPt(mainCluster.hwPtEm(), mainCluster.hwPtHad(), mainCluster.hwEta());
353  math::PtEtaPhiMLorentzVector p4(calibPt, eta, phi, 0.);
354  l1t::Tau tau( p4, mainCluster.hwPt(), mainCluster.hwEta(), mainCluster.hwPhi(), 0);
355  taus.push_back(tau);
356  //std::cout<<" Make tau, No merging\n";
357 
358  // Isolation part
359  int hwEtSum = CaloTools::calHwEtSum(mainCluster.hwEta(),mainCluster.hwPhi(),towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
360  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
361 
362  int hwFootPrint = isoCalTauHwFootPrint(mainCluster,towers);
363 
364  int isolBit = 0;
365  int nrTowers = CaloTools::calNrTowers(-1*params_->tauPUSParam(1),params_->tauPUSParam(1),1,72,towers,1,999,CaloTools::CALO);
366  unsigned int lutAddress = isoLutIndex(calibPt, nrTowers);
367 
368  isolBit = hwEtSum-hwFootPrint <= params_->tauIsolationLUT()->data(lutAddress);
369  taus.back().setHwIso(isolBit);
370  }
371  }
372  else {
373  bool canBeKept = false;
374  bool mergeUp = (secondaryCluster.hwPhi()==iPhiM2 || secondaryCluster.hwPhi()==iPhiM3);
375  bool mergeLeft = (secondaryCluster.hwEta()==iEtaM);
376  bool mergeRight = (secondaryCluster.hwEta()==iEtaP);
377 
378  if(mergeUp && !secondaryCluster.checkClusterFlag(CaloCluster::MERGE_UPDOWN)) canBeKept = true;
379  if(!mergeUp && secondaryCluster.checkClusterFlag(CaloCluster::MERGE_UPDOWN)) canBeKept = true;
380  if(mergeLeft && !secondaryCluster.checkClusterFlag(CaloCluster::MERGE_LEFTRIGHT)) canBeKept = true;
381  if(mergeRight && secondaryCluster.checkClusterFlag(CaloCluster::MERGE_LEFTRIGHT)) canBeKept = true;
382  if(canBeKept) {
383  double calibPt = calibratedPt(mainCluster.hwPtEm(), mainCluster.hwPtHad(), mainCluster.hwEta());
384  math::PtEtaPhiMLorentzVector p4(calibPt, eta, phi, 0.);
385  l1t::Tau tau( p4, mainCluster.hwPt(), mainCluster.hwEta(), mainCluster.hwPhi(), 0);
386  taus.push_back(tau);
387  //std::cout<<" Make tau, No merging\n";
388 
389  // Isolation part
390  int hwEtSum = CaloTools::calHwEtSum(mainCluster.hwEta(),mainCluster.hwPhi(),towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
391  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
392 
393  int hwFootPrint = isoCalTauHwFootPrint(mainCluster,towers);
394 
395  int isolBit = 0;
396  int nrTowers = CaloTools::calNrTowers(-1*params_->tauPUSParam(1),params_->tauPUSParam(1),1,72,towers,1,999,CaloTools::CALO);
397  unsigned int lutAddress = isoLutIndex(calibPt, nrTowers);
398 
399  isolBit = hwEtSum-hwFootPrint <= params_->tauIsolationLUT()->data(lutAddress);
400  taus.back().setHwIso(isolBit);
401 
402  }
403  }
404  }
405  else {
406  double calibPt = calibratedPt(mainCluster.hwPtEm(), mainCluster.hwPtHad(), mainCluster.hwEta());
407  math::PtEtaPhiMLorentzVector p4(calibPt, eta, phi, 0.);
408  l1t::Tau tau( p4, mainCluster.hwPt(), mainCluster.hwEta(), mainCluster.hwPhi(), 0);
409  taus.push_back(tau);
410  //std::cout<<" Make tau, No merging\n";
411 
412  // Isolation part
413  int hwEtSum = CaloTools::calHwEtSum(mainCluster.hwEta(),mainCluster.hwPhi(),towers,-1*params_->tauIsoAreaNrTowersEta(),params_->tauIsoAreaNrTowersEta(),
414  -1*params_->tauIsoAreaNrTowersPhi(),params_->tauIsoAreaNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
415 
416  int hwFootPrint = isoCalTauHwFootPrint(mainCluster,towers);
417 
418  int isolBit = 0;
419  int nrTowers = CaloTools::calNrTowers(-1*params_->tauPUSParam(1),params_->tauPUSParam(1),1,72,towers,1,999,CaloTools::CALO);
420  unsigned int lutAddress = isoLutIndex(calibPt, nrTowers);
421 
422  isolBit = hwEtSum-hwFootPrint <= params_->tauIsolationLUT()->data(lutAddress);
423  taus.back().setHwIso(isolBit);
424 
425  }
426  }
427  }
428 }
429 
430 
431 //calculates the footprint of the tau in hardware values
433 {
434  int iEta=clus.hwEta();
435  int iPhi=clus.hwPhi();
436  int totHwFootPrint = CaloTools::calHwEtSum(iEta,iPhi,towers,-1,1,-1*params_->tauIsoVetoNrTowersPhi(),params_->tauIsoVetoNrTowersPhi(),params_->tauPUSParam(2),CaloTools::CALO);
437  return totHwFootPrint;
438 }
439 
440 
441 
442 
444 {
445  float minScale = 0.;
446  float maxScale = 2.;
447  float minScaleEta = 0.5;
448  float maxScaleEta = 1.5;
449  offsetBarrelEH_ = 0.5;
450  offsetBarrelH_ = 1.5;
451  offsetEndcapsEH_ = 0.;
452  offsetEndcapsH_ = 1.5;
453 
454  // In the combined calibration LUT, upper 3-bits are used as LUT index:
455  // (0=BarrelA, 1=BarrelB, 2=BarrelC, 3=EndCapA, 4=EndCapA, 5=EndCapA, 6=Eta)
456  enum {LUT_UPPER = 3};
457  enum {LUT_OFFSET = 0x80};
458  l1t::LUT* lut = params_->tauCalibrationLUT();
459  unsigned int size = (1 << lut->nrBitsData());
460  unsigned int nBins = (1 << (lut->nrBitsAddress() - LUT_UPPER));
461 
462 
463  std::vector<float> emptyCoeff;
464  emptyCoeff.resize(nBins,0.);
465  float binSize = (maxScale-minScale)/(float)size;
466  for(unsigned iLut=0; iLut < 6; ++iLut ) {
467  coefficients_.push_back(emptyCoeff);
468  for(unsigned addr=0;addr<nBins;addr++) {
469  float y = (float)lut->data(iLut*LUT_OFFSET + addr);
470  coefficients_[iLut][addr] = minScale + binSize*y;
471  }
472  }
473 
474  size = (1 << lut->nrBitsData());
475  nBins = (1 << 6); // can't auto-extract this now due to combined LUT.
476 
477  emptyCoeff.resize(nBins,0.);
478  binSize = (maxScaleEta-minScaleEta)/(float)size;
479  coefficients_.push_back(emptyCoeff);
480  for(unsigned addr=0;addr<nBins;addr++) {
481  float y = (float)lut->data(6*LUT_OFFSET + addr);
482  coefficients_.back()[addr] = minScaleEta + binSize*y;
483  }
484 
485 }
486 
487 
488 double l1t::Stage2Layer2TauAlgorithmFirmwareImp1::calibratedPt(int hwPtEm, int hwPtHad, int ieta)
489 {
490  // ET calibration
491  bool barrel = (ieta<=17);
492  unsigned int nBins = coefficients_[0].size();
493  double e = (double)hwPtEm*params_->tauLsb();
494  double h = (double)hwPtHad*params_->tauLsb();
495  double calibPt = 0.;
496  int ilutOffset = (barrel) ? 0: 3;
497  unsigned int ibin=(unsigned int)(floor(e+h));
498  if (ibin >= nBins -1) ibin = nBins-1;
499  if(e>0.) {
500  double offset = (barrel) ? offsetBarrelEH_ : offsetEndcapsEH_;
501  calibPt = e*coefficients_[ilutOffset][ibin] + h*coefficients_[1+ilutOffset][ibin] + offset;
502  }
503  else {
504  double offset = (barrel) ? offsetBarrelH_ : offsetEndcapsH_;
505  calibPt = h*coefficients_[2+ilutOffset][ibin]+offset;
506  }
507 
508  // eta calibration
509  if(ieta<-28) ieta=-28;
510  if(ieta>28) ieta=28;
511  ibin = (ieta>0 ? ieta+27 : ieta+28);
512  calibPt *= coefficients_.back()[ibin];
513 
514  return calibPt;
515 }
516 
517 // LUT FORMAT: N=1024 (10 bit) blocks for each value of nrTowers
518 // Each one of this blocks has a substructure of N=256 (8 bit) for the energy value
519 unsigned int l1t::Stage2Layer2TauAlgorithmFirmwareImp1::isoLutIndex(int Et, unsigned int nrTowers)
520 {
521  const unsigned int kTowerGranularity=params_->tauPUSParam(0);
522  unsigned int nrTowersNormed = nrTowers/kTowerGranularity;
523 
524  if (nrTowersNormed > 1023) nrTowersNormed = 1023; // 10 bits for towers
525  int kTowerOffs = 256*nrTowersNormed;
526 
527  if (Et > 255) Et = 255; // 8 bit for E
528 
529  return (kTowerOffs + Et);
530 }
static float towerEta(int ieta)
Definition: CaloTools.cc:141
int hwPtEm() const
Definition: CaloCluster.cc:76
static float towerPhi(int ieta, int iphi)
Definition: CaloTools.cc:149
int fgPhi() const
Definition: CaloCluster.cc:96
unsigned int isoLutIndex(int Et, unsigned int nrTowers)
Definition: Tau.h:13
static int offsetIEta(int iEta, int offset)
Definition: CaloStage2Nav.h:43
bool isValid() const
Definition: CaloCluster.cc:71
static float towerEtaSize(int ieta)
Definition: CaloTools.cc:154
static int calHwEtSum(int iEta, int iPhi, const std::vector< l1t::CaloTower > &towers, int localEtaMin, int localEtaMax, int localPhiMin, int localPhiMax, SubDet etMode=CALO)
Definition: CaloTools.cc:81
virtual void processEvent(const std::vector< CaloCluster > &clusters, const std::vector< CaloTower > &towers, std::vector< Tau > &taus)
int hwPhi() const
Definition: L1Candidate.cc:79
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
bool checkClusterFlag(ClusterFlag flag) const
Definition: CaloCluster.cc:66
unsigned int nrBitsData() const
Definition: LUT.h:51
static int offsetIPhi(int iPhi, int offset)
Definition: CaloStage2Nav.h:32
static size_t calNrTowers(int iEtaMin, int iEtaMax, int iPhiMin, int iPhiMax, const std::vector< l1t::CaloTower > &towers, int minHwEt, int maxHwEt, SubDet etMode=CALO)
Definition: CaloTools.cc:110
double p4[4]
Definition: TauolaWrapper.h:92
double calibratedPt(int hwPtEm, int hwPtHad, int ieta)
static const l1t::CaloCluster & getCluster(const std::vector< l1t::CaloCluster > &clusters, int iEta, int iPhi)
Definition: CaloTools.cc:32
int isoCalTauHwFootPrint(const l1t::CaloCluster &, const std::vector< l1t::CaloTower > &)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
tuple lut
Definition: lumiPlot.py:244
int hwEta() const
Definition: L1Candidate.cc:74
unsigned int nrBitsAddress() const
Definition: LUT.h:50
void merging(const std::vector< l1t::CaloCluster > &clusters, const std::vector< l1t::CaloTower > &towers, std::vector< l1t::Tau > &taus)
static float towerPhiSize(int ieta)
Definition: CaloTools.cc:161
Definition: LUT.h:29
int hwPt() const
Definition: L1Candidate.cc:69
int hwPtHad() const
Definition: CaloCluster.cc:81
Geom::Phi< T > phi() const
int data(unsigned int address) const
Definition: LUT.h:46
tuple size
Write out results.
void setClusterFlag(ClusterFlag flag, bool val=true)
Definition: CaloCluster.cc:19
int fgEta() const
Definition: CaloCluster.cc:91