CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/RecoLocalCalo/HcalRecAlgos/src/HcalHFStatusBitFromRecHits.cc

Go to the documentation of this file.
00001 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalHFStatusBitFromRecHits.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "Geometry/HcalTowerAlgo/src/HcalHardcodeGeometryData.h" // for eta bounds
00004 
00005 #include <algorithm> // for "max"
00006 #include <cmath>
00007 #include <iostream>
00008 using namespace std;
00009 
00010 HcalHFStatusBitFromRecHits::HcalHFStatusBitFromRecHits()
00011 {
00012   // use simple values in default constructor
00013   long_HFlongshortratio_   = 0.99;
00014   short_HFlongshortratio_  = 0.99;
00015   long_thresholdET_    = 0.5; // default energy requirement
00016   short_thresholdET_   = 0.5;
00017   long_thresholdEnergy_ = 100;
00018   short_thresholdEnergy_ = 100;
00019 }
00020 
00021 HcalHFStatusBitFromRecHits::HcalHFStatusBitFromRecHits(double shortR, double shortET, double shortE,
00022                                                        double longR, double longET, double longE)
00023 {
00024   long_HFlongshortratio_   = longR; 
00025   short_HFlongshortratio_  = shortR;
00026   long_thresholdET_        = longET;
00027   short_thresholdET_       = shortET;
00028   long_thresholdEnergy_    = longE;
00029   short_thresholdEnergy_   = shortE;
00030 }
00031 
00032 HcalHFStatusBitFromRecHits::~HcalHFStatusBitFromRecHits(){}
00033 
00034 void HcalHFStatusBitFromRecHits::hfSetFlagFromRecHits(HFRecHitCollection& rec, 
00035                                                       HcalChannelQuality* myqual, 
00036                                                       const HcalSeverityLevelComputer* mySeverity)
00037 {
00038   // Compares energies from long & short fibers
00039   int status;
00040   float en, en2;
00041   int ieta, iphi, depth;
00042   float ratio; // ratio of (L-S)/(L+S) energy magnitudes
00043   double coshEta;
00044 
00045   // Is there a faster way to do this than a double loop?
00046   for (HFRecHitCollection::iterator iHF=rec.begin(); iHF!=rec.end();++iHF)
00047     {
00048       // skip cells that have already been tagged -- shouldn't happen in current algorithm
00049       //if (iHF->flagField(HcalCaloFlagLabels::HFLongShort, HcalCaloFlagLabels::HFLongShort+1)) continue;
00050 
00051       ieta =iHF->id().ieta();  // int between 29-41
00052       // eta = average value between cell eta bounds
00053       coshEta=fabs(cosh(0.5*(theHFEtaBounds[abs(ieta)-29]+theHFEtaBounds[abs(ieta)-28])));
00054 
00055       status=0; // status bit for rechit
00056 
00057       en2=-999; // dummy starting value for partner energy
00058       depth=iHF->id().depth();
00059       en=iHF->energy(); // energy of current rechit
00060 
00061       if (depth==1) // check long fiber
00062         {
00063           if (en<1.2) continue;  // never flag long rechits < 1.2 GeV
00064           if (long_thresholdEnergy_>0. && en<long_thresholdEnergy_) continue;
00065           if (long_thresholdET_>0. && en<long_thresholdET_*coshEta) continue;
00066         }
00067 
00068       else if (depth==2) // check short fiber
00069         {
00070           if (en<1.8) continue;  // never flag short rechits < 1.8 GeV
00071           if (short_thresholdEnergy_>0. && en<short_thresholdEnergy_) continue;
00072           if (short_thresholdET_>0. && en<short_thresholdET_*coshEta) continue;
00073         }
00074       
00075       iphi =iHF->id().iphi();
00076 
00077       // Check for cells whose partners have been excluded from the rechit collections
00078       // Such cells will not get flagged (since we can't make an L vs. S comparison)
00079 
00080       HcalDetId partner(HcalForward, ieta, iphi, 3-depth); // if depth=1, 3-depth =2, and vice versa
00081       DetId detpartner=DetId(partner);
00082       const HcalChannelStatus* partnerstatus=myqual->getValues(detpartner.rawId());
00083       if (mySeverity->dropChannel(partnerstatus->getValue() ) ) continue;  // partner was dropped; don't set flag
00084 
00085       // inner loop will find 'partner' channel (same ieta, iphi, different depth)
00086       for (HFRecHitCollection::iterator iHF2=rec.begin(); iHF2!=rec.end();++iHF2)
00087         {
00088           if (iHF2->id().ieta()!=ieta) continue; // require ieta match
00089           if (iHF2->id().iphi()!=iphi) continue; // require iphi match
00090           if (iHF2->id().depth()==depth) continue;  // require short/long combo
00091 
00092           en2=iHF2->energy(); 
00093 
00094           /* 
00095              We used to use absolute values of energies for ratios, but I don't think we want to do this any more.
00096              For example, for a threshold of 0.995, if en=50 and en2=0, the flag would be set.
00097              But if en=50 and en2<-0.125, the threshold would not be set if using the absolute values.
00098              I don't think we want to have a range of en2 below which the flag is not set.
00099              This does mean that we need to be careful not to set the en energy threshold too low,
00100              so as to not falsely flag fluctuations (en=2, en2=-0.01, for example), but we should never be setting our
00101              thresholds that low.
00102           */
00103           
00104           ratio = (en - en2)/(en + en2);
00105           
00106           if (depth==1 && ratio>long_HFlongshortratio_)
00107             status=1;
00108           else if (depth==2 && ratio>short_HFlongshortratio_)
00109             status=1;
00110           break; // once partner channel found, break out of loop
00111         } // inner loop
00112 
00113       // Consider the case where only one depth present
00114       if (en2==-999) // outer rechit has already passed energy, ET thresholds above; no partner cell means this looks like isolated energy in one channel -- flag it!
00115         status=1;
00116 
00117       // flag rechit as potential PMT window hit
00118       if (status==1) 
00119         iHF->setFlagField(status,HcalCaloFlagLabels::HFLongShort, 1);
00120     } // outer loop
00121   return;
00122 } // void HcalHFStatusBitFromRecHits::hfSetFlagFromRecHits(...)