CMS 3D CMS Logo

FastL1Region.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    FastL1CaloSim
00004 // Class:      FastL1Region
00005 // 
00013 //
00014 // Original Author:  Chi Nhan Nguyen
00015 //         Created:  Mon Feb 19 13:25:24 CST 2007
00016 // $Id: FastL1Region.cc,v 1.21 2008/05/27 16:45:16 heltsley Exp $
00017 //
00018 
00019 // No BitInfos for release versions
00020 
00021 #include "FastSimulation/L1CaloTriggerProducer/interface/FastL1Region.h"
00022 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00023 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00024 
00025 FastL1Region::FastL1Region() 
00026 {
00027   Towers = CaloTowerCollection(16);
00028 
00029   jetE = 0.;
00030   jetEt = 0.;
00031 
00032   id = 999;
00033   ieta = 999;
00034   iphi = 999;
00035 
00036   tauBit = false;
00037   quietBit = false;
00038   mipBit = false;
00039   for(int i=0;i<16;i++) {
00040     hcfgBit[i] = false;
00041     fgBit[i] = false;
00042     hOeBit[i] = false;
00043     for (int j=0;j<25;j++) {
00044       EMCrystalEnergy[i][j] = 0. ; // 16x25 Crystals
00045     }
00046   }
00047 
00048   // default values
00049   Config.EMSeedEnThreshold = 2.;
00050   Config.EMActiveLevel = 3.;
00051   Config.HadActiveLevel = 3.;
00052   Config.noTauVetoLevel = 10000.;       
00053   Config.hOeThreshold = 0.05;
00054   Config.FGEBThreshold = 0.8;
00055   Config.noFGThreshold = 50.;
00056   Config.FGEEThreshold = 0.8;
00057   Config.MuonNoiseLevel = 2.;
00058   Config.EMNoiseLevel = 2.;
00059   Config.HadNoiseLevel = 2.;
00060   Config.QuietRegionThreshold = 2.;  
00061   Config.JetSeedEtThreshold = 2.;  
00062   Config.CrystalEBThreshold = 0.09;
00063   Config.CrystalEEThreshold = 0.45;
00064 
00065   Config.TowerEMLSB = 1.;
00066   Config.TowerHadLSB = 1.;
00067   Config.EMLSB = 1.;
00068   Config.JetLSB = 1.;
00069 
00070   Config.TowerEBThreshold = 0.2;
00071   Config.TowerEEThreshold = 0.45;
00072   Config.TowerHBThreshold = 0.9;
00073   Config.TowerHEThreshold = 1.4;
00074 
00075   Config.TowerEBScale = 1.0;
00076   Config.TowerEEScale = 1.0;
00077   Config.TowerHBScale = 1.0;
00078   Config.TowerHEScale = 1.0;
00079 
00080   //Config.EmInputs;
00081   //Config.xTowerInput;
00082 
00083 }
00084 
00085 
00086 FastL1Region::~FastL1Region() 
00087 {
00088 }
00089 
00090 
00091 void
00092 FastL1Region::SetParameters(FastL1Config iconfig) 
00093 { 
00094   Config = iconfig;
00095 }
00096 
00097 void 
00098 FastL1Region::SetRegionEnergy()
00099 {
00100   sumE = CalcSumE();
00101   sumEt = CalcSumEt();
00102 }
00103 
00104 void 
00105 FastL1Region::SetRegionBits(edm::Event const& e,bool bitinfo)
00106 {
00107   SetTauBit(e,bitinfo);
00108   SetQuietBit();
00109   SetMIPBit();
00110 }
00111 
00112 void 
00113 FastL1Region::SetTowerBits()
00114 {
00115   SetFGBit();
00116   SetHOEBit();
00117   SetHCFGBit();
00118 }
00119 
00120 //
00121 void
00122 FastL1Region::FillEMCrystals(const CaloTowerConstituentsMap* theTowerConstituentsMap,
00123                              const CaloTopology* calotopo,
00124                              const CaloGeometry* cGeom,
00125                              const EcalRecHitCollection* ec0,
00126                              const EcalRecHitCollection* ec1,
00127                              FastL1RegionMap* m_RMap) 
00128 {
00129   //std::vector< std::pair <std::string,std::string> > la;
00130   //la.resize(2);
00132   //la[0].first = "ecalRecHit";
00133   //la[0].second = "EcalRecHitsEB";
00135   //la[1].first = "ecalRecHit";
00136   //la[1].second = "EcalRecHitsEE";
00137 
00138 
00139   double ethres = Config.CrystalEBThreshold;
00140 
00141   // EB
00142   //e.getByLabel(la[0].first,la[0].second,ec);
00143   //e.getByLabel(Config.EmInputs.at(0),ec);
00144 
00145   ethres = Config.CrystalEBThreshold;
00146   for(EcalRecHitCollection::const_iterator ecItr = ec0->begin();
00147       ecItr != ec0->end(); ++ecItr) {
00148     //CaloRecHit recHit = (CaloRecHit)(*ecItr);
00149     if (ecItr->energy()<ethres) continue;
00150 
00151     EBDetId detId = ecItr->detid();
00152 
00153     int hiphi = detId.tower_iphi();
00154     int hieta = detId.tower_ieta();
00155     int eieta = detId.ieta();
00156     int eiphi = detId.iphi();
00157     int crIeta = 999;
00158     if (hieta>0)
00159       crIeta = (eieta-1)%5;
00160     else
00161       crIeta = 4 + (eieta+1)%5;
00162     int crIphi = (eiphi - 1)%5;
00163     
00164     //const GlobalPoint gP = cGeom->getPosition(detId);
00165 
00166     //CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
00167     // loop over towers
00168     for(int i=0;i<16;i++) {
00169       //int hiphi = m_RMap->convertFromECal_to_HCal_iphi(detId.tower_iphi());
00170       //int hiphi = m_RMap->convertFromHCal_to_ECal_iphi(detId.tower_iphi());
00171       int hiphi = detId.tower_iphi();
00172       if ( !Towers[i].id().iphi()==hiphi ||  !Towers[i].id().ieta()==hieta ) continue;
00173       EMCrystalEnergy[i][crIeta + 5*crIphi] = ecItr->energy();
00174     }  
00175   }
00176   
00177   // After having filled crsystal info set all veto bits
00178   SetTowerBits();
00179  
00180   // EE FG bits are filled here!!!
00181   //e.getByLabel(la[1].first,la[1].second,ec);
00182 
00183   if (GetiEta()==4 || GetiEta()==5 ||  GetiEta()==6 ||  
00184       GetiEta()==15 || GetiEta()==16 || GetiEta()==17 ) {
00185     
00186     //e.getByLabel(Config.EmInputs.at(1),ec);
00187     ethres = Config.CrystalEEThreshold;
00188     double towerEnergy[16];
00189     // loop over towers
00190     for(int i=0;i<16;i++) {
00191       fgBit[i] = false; // re-iniate
00192             
00193       //if (Towers[i].hadEt()>Config.HadNoiseLevel && Towers[i].emEt()>Config.EMNoiseLevel ) {
00194       if (Towers[i].emEt()>=Config.EMNoiseLevel ) {
00195       //if (Towers[i].emEnergy()>Config.EMNoiseLevel ) {
00196         //towerEnergy[i]  = Towers[i].hadEt() + Towers[i].emEt(); 
00197         towerEnergy[i]  = Towers[i].hadEnergy() + Towers[i].emEnergy(); 
00198       } else {
00199         fgBit[i] = false;
00200         continue;
00201       }
00202 
00203       // EB/EE transition area: unset fg bits
00204       // if (std::abs(Towers[i].id().ieta())==16 || std::abs(Towers[i].id().ieta())==17) {
00205       // fgBit[i] = false;
00206       // continue;
00207       // }
00208       if (Towers[i].emEt()>Config.noFGThreshold) {
00209         fgBit[i] = false;
00210         continue;
00211       }
00212       
00213       //CaloRecHit maxRecHit;
00214       //CaloRecHit maxRecHit2;
00215       double maxRecHit=-1.;
00216       double maxRecHit2=-1.;
00217       DetId maxDetId;
00218 
00219       double max2En = 0.;
00220       
00221       for(EcalRecHitCollection::const_iterator ecItr = ec1->begin();
00222           ecItr != ec1->end(); ++ecItr) {
00223         //CaloRecHit recHit = (CaloRecHit)(*ecItr);
00224         if (ecItr->energy()<ethres) continue;
00225         
00226         EEDetId detId = ecItr->detid();
00227         
00228         CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
00229         //int hiphi = m_RMap->convertFromECal_to_HCal_iphi(towerDetId.iphi());
00230         int hiphi = towerDetId.iphi();
00231         if (Towers[i].id().iphi()==hiphi && 
00232             Towers[i].id().ieta()==towerDetId.ieta() ) {        
00233           if (maxRecHit<ecItr->energy()) {
00234             maxRecHit = ecItr->energy();
00235             maxDetId = detId;
00236           }     
00237         }
00238       } 
00239 
00240       std::vector<DetId> westV = calotopo->west(maxDetId);
00241       std::vector<DetId> eastV = calotopo->east(maxDetId);
00242       std::vector<DetId> southV = calotopo->south(maxDetId);
00243       std::vector<DetId> northV = calotopo->north(maxDetId);
00244       for(EcalRecHitCollection::const_iterator ecItr = ec1->begin();
00245           ecItr != ec1->end(); ++ecItr) {
00246         //CaloRecHit recHit = (CaloRecHit)(*ecItr);
00247         if (ecItr->energy()<ethres) continue;
00248         
00249         EEDetId detId = ecItr->detid();
00250         
00251         CaloTowerDetId towerDetId = theTowerConstituentsMap->towerOf(detId);
00252         //int hiphi = m_RMap->convertFromECal_to_HCal_iphi(towerDetId.iphi());
00253         int hiphi = towerDetId.iphi();
00254         if (Towers[i].id().iphi()==hiphi && 
00255             Towers[i].id().ieta()==towerDetId.ieta() ) {
00256           if ( 
00257               (!westV.empty() && detId==westV[0]) || 
00258               (!eastV.empty() && detId==eastV[0]) || 
00259               (!northV.empty() && detId==northV[0]) || 
00260               (!southV.empty() && detId==southV[0]) 
00261               ) {
00262             if (maxRecHit2<ecItr->energy()) {
00263               maxRecHit2 = ecItr->energy();
00264             }   
00265             max2En += ecItr->energy();
00266           }
00267         }
00268       }  
00269       
00270       double eeThres = Config.FGEEThreshold;
00271       //double totE = maxRecHit.energy() + max2En;
00272       double totE = maxRecHit + maxRecHit2;
00273       if (towerEnergy[i]>(Config.TowerEEThreshold)) {
00274         //double totE = maxRecHit.energy() + maxRecHit2.energy();
00275         //if (totE/towerEnergy[i]<Config.FGEBThreshold) fgBit[i] = true;    
00276         if (totE/towerEnergy[i]<eeThres) fgBit[i] = true;    
00277       }
00278             
00279     }
00280   }
00281    
00282  
00283 }
00284 
00285 //
00286 void
00287 FastL1Region::FillTowerZero(const CaloTower& t, int& tid) 
00288 {
00289   Towers[tid] = CaloTower(t);
00290   //std::cout<<"--- "<<Towers[tid].emEt()<<" "<<Towers[tid].hadEt()<<std::endl;
00291 }
00292 
00293 void
00294 FastL1Region::FillTower(const CaloTower& t, int& tid) 
00295 {
00296   double EThres = 0.;
00297   double HThres = 0.;
00298   double EBthres = Config.TowerEBThreshold;
00299   double HBthres = Config.TowerHBThreshold;
00300   double EEthres = Config.TowerEEThreshold;
00301   double HEthres = Config.TowerHEThreshold;
00302   
00303   if(std::abs(t.eta())<2.322) {
00304     EThres = EBthres;
00305   } else {
00306     EThres = EEthres;
00307   }
00308   if(std::abs(t.eta())<2.322) {
00309     HThres = HBthres;
00310   } else {
00311     HThres = HEthres;
00312   }
00313 
00314   double upperThres = 1024.;
00315   double emet = RCTEnergyTrunc(t.emEt(),Config.TowerEMLSB,upperThres);
00316   double hadet = RCTEnergyTrunc(t.hadEt(),Config.TowerHadLSB,upperThres);
00317   //double eme = RCTEnergyTrunc(t.emEnergy(),Config.TowerEMLSB,upperThres);
00318   //double hade = RCTEnergyTrunc(t.hadEnergy(),Config.TowerHadLSB,upperThres);
00319 
00320   if ( emet<EThres) emet = 0.;
00321   if ( hadet<HThres) hadet = 0.;
00322   //if ( eme<EThres) emet = 0.;
00323   //if ( hade<HThres) hadet = 0.;
00324  
00325   //Towers[tid] = CaloTower(t);
00326   //Towers[tid] = CaloTower(t.id(),t.momentum(),emet,hadet,t.outerEt(),0,0);
00327   // New Dataformat in 2_1_X
00328   GlobalPoint emPosition,hadPosition;
00329   double theta = 2.*atan(exp(-t.eta()));
00330   Towers[tid] = CaloTower(t.id(),emet/sin(theta),hadet/sin(theta),t.outerEt(),0,0,t.p4(),emPosition,hadPosition);
00331 }
00332 
00333 
00334 //
00335 void
00336 FastL1Region::FillTower_Scaled(const CaloTower& t, int& tid, bool doRCTTrunc) 
00337 {
00338 
00339   double EThres = 0.;
00340   double HThres = 0.;
00341   double EBthres = Config.TowerEBThreshold;
00342   double HBthres = Config.TowerHBThreshold;
00343   double EEthres = Config.TowerEEThreshold;
00344   double HEthres = Config.TowerHEThreshold;
00345   
00346   if(std::abs(t.eta())<2.322) {
00347     EThres = EBthres;
00348   } else {
00349     EThres = EEthres;
00350   }
00351   if(std::abs(t.eta())<2.322) {
00352     HThres = HBthres;
00353   } else {
00354     HThres = HEthres;
00355   }
00356 
00357   double emScale = 1.0;
00358   double hadScale = 1.0;
00359   //double outerScale = 1.0;
00360 
00361   if (std::abs(t.eta()>1.3050) && std::abs(t.eta())<3.0) {
00362     hadScale = Config.TowerHEScale;
00363     emScale = Config.TowerEEScale;
00364   }
00365   if (std::abs(t.eta()<1.3050)) {
00366     hadScale = Config.TowerHBScale;
00367     emScale = Config.TowerEBScale;
00368   }
00369 
00370   double emet = emScale * t.emEt();
00371   double hadet = hadScale * t.hadEt();
00372   double eme = emScale * t.emEnergy();
00373   double hade = hadScale * t.hadEnergy();
00374 
00375   if (doRCTTrunc) {
00376     double upperThres = 1024.;
00377     emet = RCTEnergyTrunc(emet,Config.TowerEMLSB,upperThres);
00378     hadet = RCTEnergyTrunc(hadet,Config.TowerHadLSB,upperThres);
00379     eme = RCTEnergyTrunc(eme,Config.TowerEMLSB,upperThres);
00380     hade = RCTEnergyTrunc(hade,Config.TowerHadLSB,upperThres);
00381   }
00382   if ( emet<EThres) emet = 0.;
00383   if ( hadet<HThres) hadet = 0.;
00384   //if ( eme<EThres) emet = 0.;
00385   //if ( hade<HThres) hadet = 0.;
00386 
00387   /* 
00388   if (t.emEt()>0. || t.hadEt()>0.) {
00389     std::cout<<"+++ "
00390              <<t.emEt()<<" "<<t.hadEt()<<" "
00391              <<t.eta()<<" "<<t.phi()<<" "
00392              <<std::endl;
00393   }
00394   */
00395 
00396   //Towers[tid] = CaloTower(t);
00397   //Towers[tid] = CaloTower(t.id(),t.momentum(),emet,hadet,0.,0,0);
00398   // New Dataformat in 2_1_X
00399   GlobalPoint emPosition,hadPosition;
00400   double theta = 2.*atan(exp(-t.eta()));
00401   Towers[tid] = CaloTower(t.id(),emet/sin(theta),hadet/sin(theta),t.outerEt(),0,0,t.p4(),emPosition,hadPosition);
00402 
00403 }
00404 
00405 void 
00406 FastL1Region::SetHOEBit()
00407 {
00408   double fracThres = Config.hOeThreshold;
00409 
00410   for (int i=0; i<16; i++) {
00411     //if (Towers[i].hadEt()>Config.HadNoiseLevel && Towers[i].emEt()>Config.EMNoiseLevel ) {
00412     if (Towers[i].hadEnergy()>Config.HadNoiseLevel && Towers[i].emEnergy()>Config.EMNoiseLevel ) {
00413       if((Towers[i].hadEt()/Towers[i].emEt()) > fracThres) {
00414         hOeBit[i] = true;
00415       }
00416     }
00417   }
00418 }
00419 
00420 void 
00421 FastL1Region::SetQuietBit()
00422 {
00423   if (SumEt()<Config.QuietRegionThreshold)
00424     quietBit = true;
00425 }
00426 
00427 void 
00428 FastL1Region::SetHCFGBit()
00429 {
00430   // temporary: check definition 
00431   // if (Tower->hadEt>100GeV) hcfgBit = true; ????
00432   //for (int i=0; i<16; i++) {
00433   //}
00434 }
00435 
00436 void 
00437 FastL1Region::SetMIPBit()
00438 {
00439   if (quietBit)
00440   for (int i=0; i<16; i++) {
00441     if (hcfgBit) {
00442       mipBit = true;
00443       return;
00444     }
00445   }
00446 }
00447 
00448 void 
00449 FastL1Region::SetFGBit(int twrid,bool FGBIT)
00450 {
00451   fgBit[twrid] = FGBIT;
00452 }
00453 void 
00454 FastL1Region::SetHCFGBit(int twrid,bool FGBIT)
00455 {
00456   ;
00457 }
00458 void 
00459 FastL1Region::SetHOEBit(int twrid,bool FGBIT)
00460 {
00461   hOeBit[twrid] = FGBIT;
00462 }
00463 
00464 void 
00465 FastL1Region::SetFGBit()
00466 {
00467   double ratioCut = Config.FGEBThreshold;
00468 
00469   double stripEnergy[16][5];
00470   double duostripEnergy[16][4];
00471   double towerEnergy[16];
00472 
00473   if (GetiEta()>=7 && GetiEta()<=14) {
00474     //Barrel
00475     for (int i=0; i<16; i++) {
00476       //if (Towers[i].hadEt()>Config.HadNoiseLevel && Towers[i].emEt()>Config.EMNoiseLevel ) {
00477       if (Towers[i].emEt()>Config.EMNoiseLevel ) {
00478         //towerEnergy[i]  = Towers[i].hadEt() + Towers[i].emEt(); 
00479         towerEnergy[i]  = Towers[i].hadEnergy() + Towers[i].emEnergy(); 
00480       } else {
00481         fgBit[i] = false;
00482         continue;
00483       }
00484 
00485       // EB/EE transition area: unset fg bits
00486       //if (std::abs(Towers[i].id().ieta())==16 || std::abs(Towers[i].id().ieta())==17) {
00487       //fgBit[i] = false;
00488       //continue;
00489       //}
00490       if (Towers[i].emEt()>Config.noFGThreshold) {
00491         fgBit[i] = false;
00492         continue;
00493       }
00494 
00495       bool fgflag = false;
00496         for (int j=0; j<5; j++) {
00497         stripEnergy[i][j] = EMCrystalEnergy[i][j] + EMCrystalEnergy[i][j+5] + EMCrystalEnergy[i][j+10] + 
00498           EMCrystalEnergy[i][j+15] + EMCrystalEnergy[i][j+20];
00499       }
00500       for (int j=0; j<4; j++) {
00501         duostripEnergy[i][j] = stripEnergy[i][j] + stripEnergy[i][j+1];
00502         if (towerEnergy[i]>(Config.TowerEBThreshold)) {
00503           //std::cout<<duostripEnergy[i][j]<<" |"<<towerEnergy[i]<<" |"<<duostripEnergy[i][j]/towerEnergy[i]<<std::endl;
00504           if ( (duostripEnergy[i][j] / towerEnergy[i]) > ratioCut) {
00505             fgflag = true;
00506           } 
00507           //std::cout<<duostripEnergy[i][j]<<" | "<<towerEnergy[i]<<": "<<duostripEnergy[i][j]/towerEnergy[i]<<std::endl;       
00508         }
00509       }
00510 
00511       if (fgflag) { 
00512         fgBit[i] = false;
00513       } else {
00514         fgBit[i] = true;
00515       }
00516       //std::cout<<GetiEta()<<" | "<<i<<": "<<fgBit[i]<<std::endl;
00517       //std::cout<<"********************************************"<<std::endl;
00518     }
00519   } else {
00520     // Endcap FG bit is already filled in fillEMCrystals()!!! 
00521   }
00522   
00523 }
00524 
00525 
00526 void 
00527 FastL1Region::SetTauBit(edm::Event const& iEvent, bool bitinfo)
00528 {
00529   float emThres = Config.EMActiveLevel;
00530   float hadThres = Config.HadActiveLevel;
00531 
00532   // init pattern containers
00533   unsigned emEtaPat = 0;
00534   unsigned emPhiPat = 0;
00535   unsigned hadEtaPat = 0;
00536   unsigned hadPhiPat = 0;
00537   unsigned one = 1;
00538 
00539 
00540   // fill hits as bit pattern
00541   for (int i=0; i<16; i++) {
00542     if(Towers[i].emEt() > emThres) {
00543       emEtaPat |= (one << (unsigned)(i%4));
00544       emPhiPat |= (one << (unsigned)(i/4));
00545     }
00546 
00547     if( Towers[i].hadEt() > hadThres) {
00548       hadEtaPat |= (one << (unsigned)(i%4));
00549       hadPhiPat |= (one << (unsigned)(i/4));
00550     }
00551 
00552   }
00553 
00554   // Patterns with two or less contiguous bits set are passed
00555   // rest are vetoed; 5=0101;7=0111;9=1001;10=1010;11=1011;13=1101;14=1110;15=1111
00556   //  --- Alternate patterns
00557   //  --- 9=1001;15=1111
00558   static std::vector<unsigned> vetoPatterns;
00559   if(vetoPatterns.size() == 0) {
00560     vetoPatterns.push_back(5);
00561     vetoPatterns.push_back(7);
00562     vetoPatterns.push_back(9);
00563     vetoPatterns.push_back(10);
00564     vetoPatterns.push_back(11);
00565     vetoPatterns.push_back(13);
00566     vetoPatterns.push_back(14);
00567     vetoPatterns.push_back(15);
00568   }
00569 
00570 
00571   for(std::vector<unsigned>::iterator i = vetoPatterns.begin();
00572       i != vetoPatterns.end();  i++) {
00573     unsigned etaPattern = emEtaPat | hadEtaPat;
00574     unsigned phiPattern = emPhiPat | hadPhiPat;
00575 
00576     /*
00577     //  em pattern
00578     if(emEtaPat == *i || emPhiPat == *i) {
00579       BitInfo.EmTauVeto = true;
00580     }
00581     //  had pattern
00582     if(hadEtaPat == *i || hadPhiPat == *i) {
00583       BitInfo.HadTauVeto = true;
00584     }
00585     */
00586 
00587     if(etaPattern == *i || phiPattern == *i) // combined pattern
00588       //if(emEtaPat == *i || emPhiPat == *i || hadEtaPat == *i || hadPhiPat == *i)
00589       {
00590         tauBit = true;
00591 if (bitinfo) BitInfo.setTauVeto( true);
00592         
00593         return;
00594       }  
00595     
00596   }
00597 
00598   tauBit = false;
00599   
00600 }
00601 
00602 
00603 
00604 
00605 double 
00606 FastL1Region::CalcSumEt()
00607 {
00608   double sumet=0;
00609   for (int i=0; i<16; i++) {
00610     sumet += Towers[i].emEt();
00611     sumet += Towers[i].hadEt();
00612   }
00613 
00614   return sumet;
00615 }
00616 
00617 double 
00618 FastL1Region::CalcSumE()
00619 {
00620   double sume=0;
00621   for (int i=0; i<16; i++) {
00622     sume += Towers[i].emEnergy();
00623     sume += Towers[i].hadEnergy();
00624 
00625   }
00626   return sume;
00627 }
00628 
00629 
00630 std::pair<double, double>
00631 FastL1Region::getRegionCenterEtaPhi(const edm::EventSetup& c)
00632 {
00633   edm::ESHandle<CaloGeometry> cGeom; 
00634   c.get<CaloGeometryRecord>().get(cGeom);    
00635 
00636   const GlobalPoint gP1 = cGeom->getPosition(Towers[5].id());
00637   //const GlobalPoint gP2 = cGeom->getPosition(Towers[6].id());
00638   //const GlobalPoint gP3 = cGeom->getPosition(Towers[10].id());
00639 
00640   double eta = gP1.eta();  
00641   double phi = gP1.phi();
00642   
00643   return std::pair<double, double>(eta, phi);
00644 }
00645 
00646 
00647 // test filling of FastL1Region
00648 void 
00649 FastL1Region::Dump()
00650 {
00651 
00652   // test tower filling:
00653   /*
00654   CaloTowerCollection::const_iterator t;
00655   int count = 0;
00656   for (t=Towers.begin(); t!=Towers.end(); t++) {
00657     std::cout << count << ") " << t->energy() << " | " << t->eta()  << " | " << t->phi() << std::endl;
00658     count++;
00659   }
00660   std::cout << std::endl;
00661   */
00662 
00663   // test region neighbours:
00664   std::cout << this->GetNWId() << " "  << this->GetNorthId() << " "  << this->GetNEId() << std::endl;
00665   std::cout << this->GetWestId() << " "  << this->GetId() << " "  << this->GetEastId() << std::endl;
00666   std::cout << this->GetSWId() << " "  << this->GetSouthId() << " "  << this->GetSEId() << std::endl;
00667   std::cout << std::endl;
00668 
00669 }
00670 
00671 int 
00672 FastL1Region::GetNorthId() 
00673 { if (iphi != 17) return ((iphi+1)*22 + ieta); else return ieta; }
00674 
00675 
00676 int 
00677 FastL1Region::GetSouthId() 
00678 { if (iphi != 0) return ((iphi-1)*22 + ieta); else return (17*22 + ieta); }
00679 
00680 int 
00681 FastL1Region::GetWestId() 
00682 { if (ieta != 0) return (iphi*22 + ieta-1); else return 999; }
00683 
00684 int 
00685 FastL1Region::GetEastId() 
00686 { if (ieta != 21) return (iphi*22 + ieta+1); else return 999; }
00687   
00688 int 
00689 FastL1Region::GetNWId() 
00690 { 
00691   if (ieta != 0) {
00692     if (iphi != 17) 
00693       return ((iphi+1)*22 + ieta-1); 
00694     else
00695       return (ieta-1);  
00696   } else {
00697     return 999; 
00698   }
00699 }
00700 
00701 int 
00702 FastL1Region::GetSWId() 
00703 { 
00704   if (ieta != 0) {
00705     if (iphi != 0) 
00706       return ((iphi-1)*22 + ieta-1); 
00707     else
00708       return (17*22 + ieta-1);  
00709   } else {
00710     return 999; 
00711   }
00712 }
00713 
00714 int FastL1Region::GetNEId() 
00715 { 
00716   if (ieta != 21) {
00717     if (iphi != 17) 
00718       return ((iphi+1)*22 + ieta+1); 
00719     else
00720       return (ieta+1);  
00721   } else {
00722     return 999; 
00723   }
00724 }
00725 
00726 int 
00727 FastL1Region::GetSEId() 
00728 { 
00729   if (ieta != 21) {
00730     if (iphi != 0) 
00731       return ((iphi-1)*22 + ieta+1); 
00732     else
00733       return (17*22 + ieta+1);  
00734   } else {
00735     return 999; 
00736   }
00737 }
00738 
00739 double 
00740 corrJetEt(double et, double eta)
00741 {
00742   return corrJetEt1(et,eta);
00743   //return corrJetEt2(et,eta);
00744 }
00745 
00746 
00747 // Jet Calibration from CMSSW_1_3_0
00748 double 
00749 corrJetEt2(double et, double eta)
00750 {
00751   const int NUMBER_ETA_VALUES = 11;
00752   std::vector< std::vector<float> > m_calibFunc;
00753 
00754   m_calibFunc.resize(NUMBER_ETA_VALUES);
00755 
00756   // still fill manually 
00757   m_calibFunc.at(0).push_back(1);
00758   m_calibFunc.at(0).push_back(1);
00759   m_calibFunc.at(0).push_back(2);
00760 
00761   m_calibFunc.at(1).push_back(1);
00762   m_calibFunc.at(1).push_back(2);
00763   m_calibFunc.at(1).push_back(2);
00764 
00765   m_calibFunc.at(2).push_back(2);
00766   m_calibFunc.at(2).push_back(2);
00767   m_calibFunc.at(2).push_back(2);
00768   m_calibFunc.at(2).push_back(2);
00769   m_calibFunc.at(2).push_back(3);
00770   m_calibFunc.at(2).push_back(3);
00771 
00772   m_calibFunc.at(3).push_back(1);
00773   m_calibFunc.at(3).push_back(1);
00774   m_calibFunc.at(3).push_back(3);
00775 
00776   m_calibFunc.at(4).push_back(1);
00777   m_calibFunc.at(4).push_back(3);
00778   m_calibFunc.at(4).push_back(3);
00779   m_calibFunc.at(4).push_back(6);
00780   m_calibFunc.at(4).push_back(6);
00781   m_calibFunc.at(4).push_back(6);
00782   m_calibFunc.at(4).push_back(6);
00783   m_calibFunc.at(4).push_back(6);
00784 
00785   m_calibFunc.at(5).push_back(3);
00786   m_calibFunc.at(5).push_back(3);
00787   m_calibFunc.at(5).push_back(3);
00788 
00789   m_calibFunc.at(6).push_back(1);
00790   m_calibFunc.at(6).push_back(1);
00791   m_calibFunc.at(6).push_back(4);
00792 
00793   m_calibFunc.at(7).push_back(1);
00794   m_calibFunc.at(7).push_back(4);
00795   m_calibFunc.at(7).push_back(4);
00796 
00797   m_calibFunc.at(8).push_back(4);
00798   m_calibFunc.at(8).push_back(4);
00799   m_calibFunc.at(8).push_back(4);
00800   m_calibFunc.at(8).push_back(1);
00801   m_calibFunc.at(8).push_back(1);
00802   m_calibFunc.at(8).push_back(1);
00803 
00804   m_calibFunc.at(9).push_back(1);
00805   m_calibFunc.at(9).push_back(1);
00806   m_calibFunc.at(9).push_back(5);
00807 
00808   m_calibFunc.at(10).push_back(1);
00809   m_calibFunc.at(10).push_back(5);
00810   m_calibFunc.at(10).push_back(5);
00811 
00812 
00813   double etabin[12] = { 0.0, 0.348, 0.696, 1.044, 1.392, 1.74, 2.172, 3.0,
00814                         3.33, 3.839, 4.439, 5.115};
00815   int BinID = 0;
00816   for(int i = 0; i < 11; i++){
00817     if(std::abs(eta) >= etabin[i] && eta < etabin[i+1])
00818       BinID = i;
00819   }
00820 
00821   double corrEt = 0;
00822   for (unsigned i=0; i<m_calibFunc.at(BinID).size();i++){
00823     corrEt += m_calibFunc.at(BinID).at(i)*pow(et,(int)i); 
00824   }
00825   
00826   uint16_t jetEtOut = (uint16_t)corrEt;
00827   
00828   if(jetEtOut < 1024) {
00829     return (double)jetEtOut;
00830   }
00831   return (double)1023;
00832 
00833 }
00834 
00835 // Jet Calibration from Frederick(Helsinki), Monika/Creighton (Wisconsin)
00836 double 
00837 corrJetEt1(double et, double eta)
00838 {
00839   double etabin[23] = {-5.115, -4.439, -3.839, -3.33, 
00840                         -3.0, -2.172, -1.74, -1.392, -1.044, -0.696, -0.348, 
00841                         0.0, 0.348, 0.696, 1.044, 1.392, 1.74, 2.172, 3.0,
00842                         3.33, 3.839, 4.439, 5.115};
00843 
00844   int BinID = 0;
00845       
00846   double domainbin_L[22] = {6.52223337753073373e+00,6.64347505748981959e+00,6.78054870174118296e+00,6.75191887554567405e+00,
00847                             6.60891660595437802e+00,6.57813476381055473e+00,6.96764764481347232e+00,6.77192746888150943e+00,
00848                             7.16209661824076260e+00,7.09640803784948027e+00,7.29886808171882517e+00,7.29883431473330546e+00,
00849                             7.24561741344293875e+00,7.05381822724987995e+00,6.52340799679028827e+00,6.96091042775473401e+00,
00850                             6.69803071767842262e+00,7.79138848427964259e+00,6.78565437835616603e+00,6.71201461174192904e+00,
00851                             6.60832257380386334e+00,6.54875448717649267e+00};
00852 
00853   double domainbin_U[22] = {8.90225568813317558e+00,1.24483653543590922e+01,1.32037091554958987e+01,1.70036104608977681e+01,
00854                             3.54325008263432011e+01,4.28758696753095450e+01,4.73079850563588025e+01,4.74182802251108981e+01,
00855                             4.62509826468679748e+01,5.02198002212212913e+01,4.69817029938948352e+01,4.77263481299233732e+01,
00856                             4.86083837976362076e+01,4.80105593452927337e+01,5.11550616006504200e+01,4.90703092811585861e+01,
00857                             4.11879629179572788e+01,3.21820720507165845e+01,1.71844078553560529e+01,1.33158534849654764e+01,
00858                             1.43586396719878149e+01,1.08629843894704248e+01};
00859 
00860   double A[22] = {2.03682,-4.36824,-4.45258,-6.76524,-22.5984,-24.5289,-24.0313,-22.1896,-21.7818,-22.9882,-20.3321,
00861                   -21.0595,-22.1007,-22.658,-23.6898,-24.8888,-23.3246,-21.5343,-6.41221,-4.58952,-3.17222,0.637666};
00862 
00863   double B[22] = {0.226303,0.683099,0.704578,0.704623,0.825928,0.80086,0.766475,0.726059,0.760964,0.792227,0.789188,0.795219,
00864                   0.781097,0.768022,0.740101,0.774782,0.788106,0.814502,0.686877,0.709556,0.628581,0.317453};
00865   
00866   double C[22] = {0.00409083,0.000235995,8.22958e-05,2.47567e-05,0.000127995,0.000132914,0.000133342,0.000133035,0.000125993,
00867                   8.25968e-05,9.94442e-05,9.11652e-05,0.000109351,0.000115883,0.00011112,0.000122559,0.00015868,0.000152601,
00868                   0.000112927,6.29999e-05,0.000741798,0.00274605};
00869 
00870   double D[22] = {8.24022,7.55916,7.16448,6.31577,5.96339,5.31203,5.35456,4.95243,5.34809,4.93339,5.05723,5.08575,5.18643,5.15202,
00871                   4.48249,5.2734,5.51785,8.00182,6.21742,6.96692,7.22975,8.12257};
00872   
00873   double E[22] = {-0.343598,-0.294067,-0.22529,-0.0718625,0.004164,0.081987,0.124964,0.15006,0.145201,0.182151,0.187525,0.184763,
00874                   0.170689,0.155268,0.174603,0.133432,0.0719798,-0.0921457,-0.0525274,-0.208415,-0.253542,-0.318476};
00875 
00876   double F[22] = {0.0171799,0.0202499,0.0186897,0.0115477,0.00603883,0.00446235,0.00363449,0.00318894,0.00361997,0.00341508,
00877                   0.00366392,0.0036545,0.00352303,0.00349116,0.00294891,0.00353187,0.00460384,0.00711028,0.0109351,0.0182924,
00878                   0.01914,0.0161094};
00879 
00880   for(int i = 0; i < 22; i++){
00881     if(eta > etabin[i] && eta <= etabin[i+1])
00882       BinID = i;
00883   }
00884 
00885   if(et >= domainbin_U[BinID]){
00886     return 2*(et-A[BinID])/(B[BinID]+sqrt(B[BinID]*B[BinID]-4*A[BinID]*C[BinID]+4*et*C[BinID]));
00887   }
00888   else if(et > domainbin_L[BinID]){
00889     return 2*(et-D[BinID])/(E[BinID]+sqrt(E[BinID]*E[BinID]-4*D[BinID]*F[BinID]+4*et*F[BinID]));
00890   }
00891   else return et;
00892 }
00893 
00894 
00895 // EM correction from ORCA for cmsim 133
00896 double 
00897 //corrEmEt(double et, double eta) {
00898 corrEmEt(double et, int eta) {
00899 
00900 
00901   const int nscales = 32;
00902   /*
00903   const int nscales = 27;
00904   double etalimit[nscales] = { 0.0,0.087,0.174,0.261,0.348,0.435,0.522,0.609,0.696,0.783,0.870,0.957,
00905                           1.044,1.131,1.218,1.305,1.392,1.479,1.566,1.653,1.740,1.830,1.930,
00906                           2.043,2.172,2.322,2.500};
00907   */
00908 
00909   double scfactor[nscales] = { 
00910     1.00,1.01,1.02,1.02,1.02,1.06,1.04,1.04,1.05,1.09,1.10,1.10,1.15,
00911     1.20,1.27,1.29,1.32,1.52,1.52,1.48,1.40,1.32,1.26,1.21,1.17,1.15, 
00912     1.15,1.15,1.15,1.15,1.15,1.15};
00913 
00914   /*
00915   double scale=1.;
00916   for (int i=0;i<nscales;i++) {
00917     if (std::abs(eta)<etalimit[i]) {
00918       scale = scfactor[i];
00919     }
00920   }
00921     return (scale*et);
00922   */
00923 
00924   if (eta>=0 && eta <=28)
00925     return (scfactor[eta]*et);
00926   else
00927     return et;
00928 }
00929 
00930 
00931 // Rounding the Et info for simulating the regional Et resolution
00932 double 
00933 RCTEnergyTrunc(double et, double LSB, double thres) {
00934 
00935   //return et;
00936   if (et>=thres) return thres;
00937 
00938   //et += LSB/2.;
00939   //double ret = (int)(et / LSB) * LSB + LSB;
00940   int iEt = (int)(et / LSB);
00941   double ret =  (double)iEt * LSB;
00942 
00943   return ret;
00944 }
00945 
00946 
00947 double 
00948 GCTEnergyTrunc(double et, double LSB, bool doEM) {
00949 
00950   //return et;
00951 
00952   //double L1CaloEmEtScaleLSB = LSB;
00953   //double L1CaloRegionEtScaleLSB = LSB;
00954 
00955   //if (et>0.) et += LSB/2.; // round up
00956 
00957   double L1CaloEmThresholds[64] = { 
00958     0.,     1.,     2.,     3.,     4.,     5.,     6.,     7.,     8.,     9., 
00959     10.,    11.,    12.,    13.,    14.,    15.,    16.,    17.,    18.,    19., 
00960     20.,    21.,    22.,    23.,    24.,    25.,    26.,    27.,    28.,    29., 
00961     30.,    31.,    32.,    33.,    34.,    35.,    36.,    37.,    38.,    39., 
00962     40.,    41.,    42.,    43.,    44.,    45.,    46.,    47.,    48.,    49.,
00963     50.,    51.,    52.,    53.,    54.,    55.,    56.,    57.,    58.,    59., 
00964     60.,    61.,    62.,    63.
00965   };
00966  
00967   double L1CaloJetThresholds[64] = {       
00968     0.,     10.,    12.,    14.,    15.,    18.,    20.,    22.,    24.,    25.,
00969     28.,    30.,    32.,    35.,    37.,    40.,    45.,    50.,    55.,    60.,    
00970     65.,    70.,    75.,    80.,    85.,    90.,    100.,   110.,   120.,   125.,   
00971     130.,   140.,   150.,   160.,   170.,   175.,   180.,   190.,   200.,   215.,   
00972     225.,   235.,   250.,   275.,   300.,   325.,   350.,   375.,   400.,   425.,   
00973     450.,   475.,   500.,   525.,   550.,   575.,   600.,   625.,   650.,   675.,   
00974     700.,   725.,   750.,   775.
00975   };
00976   
00977 
00978 
00979   double L1CaloThresholds[64];
00980   if (doEM) {
00981     for (int i=0;i<64;i++)
00982       L1CaloThresholds[i] = L1CaloEmThresholds[i];
00983   } else {
00984     for (int i=0;i<64;i++)
00985       L1CaloThresholds[i] = L1CaloJetThresholds[i];
00986   }
00987 
00988 
00989   double ret = 0.;
00990   for (int i=63;i>0;i--) {
00991     if (et>=(L1CaloThresholds[i])) {
00992       if (i==63) {
00993         ret = L1CaloThresholds[63];
00994       } else {
00995         /*
00996         double minL = std::abs(et - L1CaloThresholds[i]); 
00997         double minU = std::abs(et - L1CaloThresholds[i+1]); 
00998         if (minL<minU)
00999           ret = L1CaloThresholds[i];
01000         else
01001           ret = L1CaloThresholds[i+1];
01002         */
01003         /*
01004         if (doEM) {
01005           ret = L1CaloThresholds[i];
01006         } else {
01007           ret = L1CaloThresholds[i+1];
01008         }
01009         */
01010         ret = L1CaloThresholds[i];
01011       }
01012       break;
01013     }
01014   }
01015   return ret;
01016 }
01017 
01018 
01019 

Generated on Tue Jun 9 17:35:09 2009 for CMSSW by  doxygen 1.5.4