CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Calibration/HcalCalibAlgos/plugins/HcalCorrPFCalculation.cc

Go to the documentation of this file.
00001 // $Id: HcalCorrPFCalculation.cc,v 1.18 2010/02/23 13:47:42 fabiocos Exp $
00002 
00003 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00004 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDAnalyzer.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00013 #include "DataFormats/HcalRecHit/interface/HcalSourcePositionData.h"
00014 #include "FWCore/Framework/interface/Selector.h"
00015 #include <DataFormats/EcalDetId/interface/EBDetId.h>
00016 #include <DataFormats/EcalDetId/interface/EEDetId.h>
00017 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00018 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
00019 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00020 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00021 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00022 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00023 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00024 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00025 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00026 #include "CondFormats/HcalObjects/interface/HcalRespCorrs.h"
00027 #include "CondFormats/DataRecord/interface/HcalRespCorrsRcd.h"
00028 #include "CondFormats/HcalObjects/interface/HcalPFCorrs.h"
00029 #include "CondFormats/DataRecord/interface/HcalPFCorrsRcd.h"
00030 #include "MagneticField/Engine/interface/MagneticField.h"
00031 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00032 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00033 #include "DataFormats/GeometrySurface/interface/PlaneBuilder.h"
00034 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
00035 #include "DataFormats/GeometrySurface/interface/Plane.h"
00036 #include "TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
00037 #include "FWCore/ServiceRegistry/interface/Service.h"
00038 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00039 #include "Calibration/HcalCalibAlgos/src/MaxHit_struct.h"
00040 
00041 #include "TROOT.h"
00042 #include "TFile.h"
00043 #include "TTree.h"
00044 #include "TProfile.h"
00045 
00046 using namespace edm;
00047 using namespace std;
00048 using namespace reco;
00049 
00050 class HcalCorrPFCalculation : public edm::EDAnalyzer {
00051  public:
00052   HcalCorrPFCalculation(edm::ParameterSet const& conf);
00053   ~HcalCorrPFCalculation();
00054   virtual void analyze(edm::Event const& ev, edm::EventSetup const& c);
00055   virtual void beginJob() ;
00056   virtual void endJob() ;
00057  private:
00058   double getDistInPlaneSimple(const GlobalPoint caloPoint, const GlobalPoint rechitPoint);
00059   
00060   double RecalibFactor(HcalDetId id);
00061 
00062   bool        Respcorr_;
00063   bool        PFcorr_;
00064   bool        Conecorr_;
00065   double        radius_;
00066 
00067   double energyECALmip;
00068 
00069   Bool_t doHF;
00070   Bool_t AddRecalib;
00071   int nevtot;
00072 
00073   const HcalRespCorrs* respRecalib;
00074   const HcalPFCorrs* pfRecalib;
00075 
00076   SteppingHelixPropagator* stepPropF;
00077   MagneticField *theMagField;
00078 
00079   edm::Service<TFileService> fs;
00080 
00081   TProfile *nCells, *nCellsNoise, *enHcal, *enHcalNoise;
00082   TH1F *enEcalB, *enEcalE;
00083   TTree *pfTree;
00084   TFile *rootFile;
00085 
00086   TrackDetectorAssociator trackAssociator_;
00087   TrackAssociatorParameters parameters_;
00088   double taECALCone_;
00089   double taHCALCone_;
00090 
00091   const CaloGeometry* geo;
00092 
00093   Float_t xTrkEcal;
00094   Float_t yTrkEcal;
00095   Float_t zTrkEcal;
00096 
00097   Float_t xTrkHcal;
00098   Float_t yTrkHcal;
00099   Float_t zTrkHcal;
00100 
00101   double eEcalCone, eHcalCone, eHcalConeNoise;
00102   // int numrechitsEcal = 0;
00103   
00104   int UsedCells, UsedCellsNoise;
00105 
00106   //  Float_t etaTrack, phiTrack;
00107   Int_t  iPhi, iEta;
00108       
00109 };
00110 
00111 
00112 HcalCorrPFCalculation::HcalCorrPFCalculation(edm::ParameterSet const& conf) {
00113 
00114   //  outputFile_ = conf.getUntrackedParameter<std::string>("outputFile", "myfile.root");
00115   
00116     Respcorr_        = conf.getUntrackedParameter<bool>("RespcorrAdd", false);
00117   PFcorr_        = conf.getUntrackedParameter<bool>("PFcorrAdd", false);
00118   Conecorr_        = conf.getUntrackedParameter<bool>("ConeCorrAdd", true);
00119   radius_       = conf.getUntrackedParameter<double>("ConeRadiusCm", 40.);
00120   energyECALmip = conf.getParameter<double>("energyECALmip");
00121 
00122   edm::ParameterSet parameters = conf.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
00123   parameters_.loadParameters( parameters );
00124   trackAssociator_.useDefaultPropagator();
00125 
00126   taECALCone_=conf.getUntrackedParameter<double>("TrackAssociatorECALCone",0.5);
00127   taHCALCone_=conf.getUntrackedParameter<double>("TrackAssociatorHCALCone",0.6);
00128 
00129 }
00130 
00131 double HcalCorrPFCalculation::getDistInPlaneSimple(const GlobalPoint caloPoint,
00132                             const GlobalPoint rechitPoint)
00133 {
00134 
00135   // Simplified version of getDistInPlane
00136   // Assume track direction is origin -> point of hcal intersection
00137 
00138   const GlobalVector caloIntersectVector(caloPoint.x(),
00139                                          caloPoint.y(),
00140                                          caloPoint.z());
00141 
00142   const GlobalVector caloIntersectUnitVector = caloIntersectVector.unit();
00143 
00144   const GlobalVector rechitVector(rechitPoint.x(),
00145                                   rechitPoint.y(),
00146                                   rechitPoint.z());
00147 
00148   const GlobalVector rechitUnitVector = rechitVector.unit();
00149   double dotprod = caloIntersectUnitVector.dot(rechitUnitVector);
00150   double rechitdist = caloIntersectVector.mag()/dotprod;
00151 
00152 
00153   const GlobalVector effectiveRechitVector = rechitdist*rechitUnitVector;
00154   const GlobalPoint effectiveRechitPoint(effectiveRechitVector.x(),
00155                                          effectiveRechitVector.y(),
00156                                          effectiveRechitVector.z());
00157 
00158 
00159   GlobalVector distance_vector = effectiveRechitPoint-caloPoint;
00160 
00161   if (dotprod > 0.)
00162   {
00163     return distance_vector.mag();
00164   }
00165   else
00166   {
00167     return 999999.;
00168   }
00169 }
00170 
00171 double  HcalCorrPFCalculation::RecalibFactor(HcalDetId id)
00172 {
00173   Float_t resprecal = 1.;
00174   Float_t pfrecal = 1.;
00175   if(AddRecalib) {
00176     if(Respcorr_) resprecal = respRecalib -> getValues(id)->getValue();
00177     if(PFcorr_)   pfrecal = pfRecalib   -> getValues(id)->getValue();
00178   }
00179   Float_t factor = resprecal*pfrecal;
00180   return factor;
00181 }
00182 
00183 HcalCorrPFCalculation::~HcalCorrPFCalculation() {
00184 
00185   
00186 }
00187 
00188 void HcalCorrPFCalculation::analyze(edm::Event const& ev, edm::EventSetup const& c) {
00189 
00190   AddRecalib=kFALSE;
00191 
00192   try{
00193 
00194     edm::ESHandle <HcalRespCorrs> recalibCorrs;
00195     c.get<HcalRespCorrsRcd>().get("recalibrate",recalibCorrs);
00196     respRecalib = recalibCorrs.product();
00197 
00198     edm::ESHandle <HcalPFCorrs> pfCorrs;
00199     c.get<HcalPFCorrsRcd>().get("recalibrate",pfCorrs);
00200     pfRecalib = pfCorrs.product();
00201 
00202     AddRecalib = kTRUE;;
00203     // LogMessage("CalibConstants")<<"   OK ";
00204 
00205   }catch(const cms::Exception & e) {
00206     LogWarning("CalibConstants")<<"   Not Found!! ";
00207   }
00208 
00209 
00210   
00211     edm::ESHandle<CaloGeometry> pG;
00212     c.get<CaloGeometryRecord>().get(pG);
00213     geo = pG.product();
00214     
00215     parameters_.useEcal = true;
00216     parameters_.useHcal = true;
00217     parameters_.useCalo = false;
00218     parameters_.useMuon = false;
00219     parameters_.dREcal = taECALCone_;
00220     parameters_.dRHcal = taHCALCone_;    
00221 
00222     
00223   //  double eta_bin[42]={0.,.087,.174,.261,.348,.435,.522,.609,.696,.783,
00224   //.870,.957,1.044,1.131,1.218,1.305,1.392,1.479,1.566,1.653,1.740,1.830,1.930,2.043,2.172,
00225   //2.322,2.500,2.650,2.853,3.000,3.139,3.314,3.489,3.664,3.839,4.013,4.191,4.363,4.538,4.716,4.889,5.191};
00226   
00227   // MC info 
00228   double phi_MC = -999999.;  // phi of initial particle from HepMC
00229   double eta_MC = -999999.;  // eta of initial particle from HepMC
00230   double mom_MC = 50.;  // P of initial particle from HepMC
00231   bool MC = false;
00232   
00233   // MC information
00234   
00235     
00236   edm::Handle<edm::HepMCProduct> evtMC;
00237   //  ev.getByLabel("VtxSmeared",evtMC);
00238   ev.getByLabel("generator",evtMC);
00239   if (!evtMC.isValid()) 
00240     {
00241       std::cout << "no HepMCProduct found" << std::endl;    
00242     } 
00243   else 
00244     {
00245       MC=true;
00246       //    std::cout << "*** source HepMCProduct found"<< std::endl;
00247     }  
00248   
00249   // MC particle with highest pt is taken as a direction reference  
00250   double maxPt = -99999.;
00251   int npart    = 0;
00252   
00253   GlobalPoint pos (0,0,0);
00254   
00255   HepMC::GenEvent * myGenEvent = new  HepMC::GenEvent(*(evtMC->GetEvent()));
00256   for ( HepMC::GenEvent::particle_iterator p = myGenEvent->particles_begin();
00257         p != myGenEvent->particles_end(); ++p ) 
00258     {
00259       double phip = (*p)->momentum().phi();
00260       double etap = (*p)->momentum().eta();
00261       double pt  = (*p)->momentum().perp();
00262       mom_MC = (*p)->momentum().rho();
00263       if(pt > maxPt) { npart++; maxPt = pt; phi_MC = phip; eta_MC = etap; }
00264       GlobalVector mom ((*p)->momentum().x(),(*p)->momentum().y(),(*p)->momentum().z());
00265       int charge = -1;
00266       
00267       if(abs((*p)->pdg_id())==211) charge = (*p)->pdg_id()/abs((*p)->pdg_id()); // pions only !!!
00268       else continue;
00269       
00270       const FreeTrajectoryState *freetrajectorystate_ =
00271         new FreeTrajectoryState(pos, mom ,charge , &(*theMagField));
00272       
00273       TrackDetMatchInfo info = trackAssociator_.associate(ev, c, *freetrajectorystate_ , parameters_);
00274       // TrackDetMatchInfo info = trackAssociator_.associate(iEvent, iSetup,trackAssociator_.getFreeTrajectoryState(iSetup, *trit), parameters_);
00275 
00276       float etahcal=info.trkGlobPosAtHcal.eta();
00277       float phihcal=info.trkGlobPosAtHcal.phi();
00278 
00279       float etaecal=info.trkGlobPosAtEcal.eta();
00280       //    float phiecal=info.trkGlobPosAtEcal.phi();
00281       
00282       
00283       xTrkEcal=info.trkGlobPosAtEcal.x();
00284       yTrkEcal=info.trkGlobPosAtEcal.y();
00285       zTrkEcal=info.trkGlobPosAtEcal.z();
00286       
00287       xTrkHcal=info.trkGlobPosAtHcal.x();
00288       yTrkHcal=info.trkGlobPosAtHcal.y();
00289       zTrkHcal=info.trkGlobPosAtHcal.z();
00290       
00291       GlobalPoint gPointHcal(xTrkHcal,yTrkHcal,zTrkHcal);
00292       
00293       GlobalPoint gPointEcal(xTrkEcal,yTrkEcal,zTrkEcal);
00294       
00295       if (etahcal>2.6) doHF = kTRUE;
00296    
00297       
00298       
00299       edm::Handle<HBHERecHitCollection> hbhe;
00300       ev.getByType(hbhe);
00301       const HBHERecHitCollection Hithbhe = *(hbhe.product());
00302       
00303       edm::Handle<HFRecHitCollection> hfcoll;
00304       ev.getByType(hfcoll);
00305       const HFRecHitCollection Hithf = *(hfcoll.product());
00306       
00307       
00308       edm::Handle<HORecHitCollection> hocoll;
00309       ev.getByType(hocoll);
00310       const HORecHitCollection Hitho = *(hocoll.product());
00311       
00312       
00313       edm::Handle<EERecHitCollection> ecalEE;
00314       ev.getByLabel("ecalRecHit","EcalRecHitsEE",ecalEE);
00315       const EERecHitCollection HitecalEE = *(ecalEE.product());
00316 
00317       edm::Handle<EBRecHitCollection> ecalEB;
00318       ev.getByLabel("ecalRecHit","EcalRecHitsEB",ecalEB);
00319       const EBRecHitCollection HitecalEB = *(ecalEB.product());
00320       
00321       
00322       
00323       // energy in ECAL
00324       eEcalCone   = 0.;
00325       // int numrechitsEcal = 0;
00326       
00327       //Hcal:
00328       eHcalCone = 0.;
00329       eHcalConeNoise = 0.;
00330       UsedCells = 0;
00331       UsedCellsNoise = 0;
00332       
00333 
00334       Int_t iphitrue = -10;
00335       Int_t ietatrue = 100;
00336       
00337       if (etahcal<1.392) 
00338         {
00339           const CaloSubdetectorGeometry* gHB = geo->getSubdetectorGeometry(DetId::Hcal,HcalBarrel);
00340           //    const GlobalPoint tempPoint(newx, newy, newz);
00341           //const DetId tempId = gHB->getClosestCell(tempPoint);
00342           const HcalDetId tempId = gHB->getClosestCell(gPointHcal);
00343           ietatrue = tempId.ieta();
00344           iphitrue = tempId.iphi();
00345         }
00346       
00347       if (etahcal>1.392 &&  etahcal<3.0) 
00348         {
00349           const CaloSubdetectorGeometry* gHE = geo->getSubdetectorGeometry(DetId::Hcal,HcalEndcap);
00350           const HcalDetId tempId = gHE->getClosestCell(gPointHcal);
00351           ietatrue = tempId.ieta();
00352           iphitrue = tempId.iphi();
00353         }
00354       
00355       if (etahcal>3.0 &&  etahcal<5.0) 
00356         {
00357           const CaloSubdetectorGeometry* gHF = geo->getSubdetectorGeometry(DetId::Hcal,HcalForward);
00358           const HcalDetId tempId = gHF->getClosestCell(gPointHcal);
00359           ietatrue = tempId.ieta();
00360           iphitrue = tempId.iphi();
00361         }
00362       
00363       //Calculate Ecal energy:      
00364       for (EBRecHitCollection::const_iterator ehit=HitecalEB.begin(); ehit!=HitecalEB.end(); ehit++)    
00365         {
00366           
00367           GlobalPoint pos = geo->getPosition(ehit->detid());
00368           float dr =  getDistInPlaneSimple(gPointEcal,pos);
00369           if (dr < 10.) eEcalCone += ehit->energy();
00370         }
00371 
00372       for (EERecHitCollection::const_iterator ehit=HitecalEE.begin(); ehit!=HitecalEE.end(); ehit++)    
00373         {
00374           
00375           GlobalPoint pos = geo->getPosition(ehit->detid());
00376           float dr =  getDistInPlaneSimple(gPointEcal,pos);
00377           if (dr < 10.) eEcalCone += ehit->energy();
00378         }
00379       if(abs(etaecal)<1.5) enEcalB -> Fill(eEcalCone); 
00380       if(abs(etaecal)>1.5 && abs(etaecal)<3.1) enEcalE -> Fill(eEcalCone); 
00381 
00382 
00383       MaxHit_struct MaxHit;
00384 
00385       MaxHit.hitenergy=-100.;
00386 
00387 
00388       Float_t recal = 1.0;
00389 
00390 
00391       for (HBHERecHitCollection::const_iterator hhit=Hithbhe.begin(); hhit!=Hithbhe.end(); hhit++) 
00392         { 
00393         
00394           recal = RecalibFactor(hhit->detid());
00395           //cout<<"recal: "<<recal<<endl;
00396 
00397           GlobalPoint pos = geo->getPosition(hhit->detid());
00398           float phihit = pos.phi();
00399           float etahit = pos.eta();
00400           
00401           int iphihit  = (hhit->id()).iphi();
00402           int ietahit  = (hhit->id()).ieta();
00403           int depthhit = (hhit->id()).depth();
00404           float enehit = hhit->energy()* recal;
00405 
00406           //Set noise RecHit opposite to track hits
00407           int  iphihitNoise = iphihit >36 ? iphihit-36 : iphihit+36;
00408           int ietahitNoise  = ietahit;
00409           int depthhitNoise = depthhit;
00410           
00411           double dphi = fabs(phihcal - phihit); 
00412           if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
00413           double deta = fabs(etahcal - etahit); 
00414           double dr = sqrt(dphi*dphi + deta*deta);
00415           
00416           //dr =  getDistInPlaneSimple(gPointHcal,pos);
00417 
00418           if(dr<0.5) 
00419             {
00420               
00421               for (HBHERecHitCollection::const_iterator hhit2=Hithbhe.begin(); hhit2!=Hithbhe.end(); hhit2++) 
00422                 {
00423                   int iphihit2  = (hhit2->id()).iphi();
00424                   int ietahit2  = (hhit2->id()).ieta();
00425                   int depthhit2 = (hhit2->id()).depth();
00426                   float enehit2 = hhit2->energy() * recal;
00427                   
00428                   if (iphihit==iphihit2 && ietahit==ietahit2  && depthhit!=depthhit2)  enehit = enehit+enehit2;
00429                 
00430                 }                 
00431               
00432               //Find a Hit with Maximum Energy
00433               
00434               if(enehit > MaxHit.hitenergy) 
00435                 {
00436                   MaxHit.hitenergy =  enehit;
00437                   MaxHit.ietahitm   = (hhit->id()).ieta();
00438                   MaxHit.iphihitm   = (hhit->id()).iphi();
00439                   MaxHit.dr   = dr;
00440                   //MaxHit.depthhit  = (hhit->id()).depth();
00441                   MaxHit.depthhit  = 1;
00442                 }
00443             }
00444           
00445           if(dr<radius_ && enehit>0.01) 
00446             {
00447               eHcalCone += enehit;          
00448               UsedCells++;
00449 
00450               // cout<<"track: ieta "<<ietahit<<" iphi: "<<iphihit<<" depth: "<<depthhit<<" energydepos: "<<enehit<<endl;
00451               
00452               for (HBHERecHitCollection::const_iterator hhit2=Hithbhe.begin(); hhit2!=Hithbhe.end(); hhit2++) 
00453                 {
00454                   recal = RecalibFactor(hhit2->detid());
00455                   int iphihit2 = (hhit2->id()).iphi();
00456                   int ietahit2 = (hhit2->id()).ieta();
00457                   int depthhit2 = (hhit2->id()).depth();
00458                   float enehit2 = hhit2->energy()* recal;       
00459                   
00460                   if (iphihitNoise == iphihit2 && ietahitNoise == ietahit2 && depthhitNoise == depthhit2 && enehit2>0.01)
00461                     {
00462                       
00463                       eHcalConeNoise += hhit2->energy()*recal;
00464                       UsedCellsNoise++;
00465                       //cout<<"Noise: ieta "<<ietahit2<<" iphi: "<<iphihit2<<" depth: "<<depthhit2<<" energydepos: "<<enehit2<<endl;
00466                     }
00467                 }
00468             }
00469         } //end of all HBHE hits cycle
00470       
00471       if(doHF){
00472         for (HFRecHitCollection::const_iterator hhit=Hithf.begin(); hhit!=Hithf.end(); hhit++) 
00473         {
00474 
00475           recal = RecalibFactor(hhit->detid());
00476 
00477           GlobalPoint pos = geo->getPosition(hhit->detid());
00478           float phihit = pos.phi();
00479           float etahit = pos.eta();
00480           
00481           int iphihit  = (hhit->id()).iphi();
00482           int ietahit  = (hhit->id()).ieta();
00483           int depthhit = (hhit->id()).depth();
00484           float enehit = hhit->energy()* recal;
00485 
00486           //Set noise RecHit opposite to track hits
00487           int  iphihitNoise = iphihit >36 ? iphihit-36 : iphihit+36;
00488           int ietahitNoise  = ietahit;
00489           int depthhitNoise = depthhit;
00490           
00491           
00492           double dphi = fabs(phihcal - phihit); 
00493           if(dphi > 4.*atan(1.)) dphi = 8.*atan(1.) - dphi;
00494           double deta = fabs(etahcal - etahit); 
00495           double dr = sqrt(dphi*dphi + deta*deta);
00496           
00497           dr =  getDistInPlaneSimple(gPointHcal,pos);
00498           
00499 
00500           if(dr<60.) 
00501             {
00502               //Find a Hit with Maximum Energy
00503               
00504               if(enehit > MaxHit.hitenergy) 
00505                 {
00506                   MaxHit.hitenergy =  enehit;
00507                   MaxHit.ietahitm   = (hhit->id()).ieta();
00508                   MaxHit.iphihitm   = (hhit->id()).iphi();
00509                   MaxHit.dr   = dr;
00510                   MaxHit.depthhit  = 1;
00511                 }
00512             }
00513           
00514           if(dr<radius_ && enehit>0.01) 
00515             {
00516               
00517               eHcalCone += enehit;          
00518               UsedCells++;
00519               
00520               for (HFRecHitCollection::const_iterator hhit2=Hithf.begin(); hhit2!=Hithf.end(); hhit2++) 
00521                 {
00522                   recal = RecalibFactor(hhit2->detid());
00523 
00524                   int iphihit2 = (hhit2->id()).iphi();
00525                   int ietahit2 = (hhit2->id()).ieta();
00526                   int depthhit2 = (hhit2->id()).depth();
00527                   float enehit2 = hhit2->energy()* recal;       
00528                   
00529                   if (iphihitNoise == iphihit2 && ietahitNoise == ietahit2 && depthhitNoise == depthhit2 && enehit2>0.01)
00530                     {
00531                       eHcalConeNoise += hhit2->energy()*recal;
00532                       UsedCellsNoise++;
00533                     }
00534                 }
00535               
00536             }
00537         } //end of all HF hits cycle
00538       } //end of doHF
00539 
00540       int dieta_M_P = 100;
00541       int diphi_M_P = 100;
00542       if(MaxHit.ietahitm*ietatrue>0) {dieta_M_P = abs (MaxHit.ietahitm-ietatrue);}
00543       if(MaxHit.ietahitm*ietatrue<0) {dieta_M_P = abs(MaxHit.ietahitm-ietatrue)-1;}
00544       diphi_M_P = abs(MaxHit.iphihitm-iphitrue);
00545       diphi_M_P =  diphi_M_P>36 ? 72-diphi_M_P : diphi_M_P; 
00546 
00547       float iDr = sqrt(diphi_M_P*diphi_M_P+dieta_M_P*dieta_M_P);
00548 
00549       
00550       Bool_t passCuts = kFALSE;
00551       //passCuts=kTRUE; 
00552       if(eEcalCone < energyECALmip && iDr<2.) passCuts = kTRUE;
00553       
00554       if(passCuts)
00555         {
00556           enHcal -> Fill(ietatrue,  eHcalCone);
00557           nCells -> Fill(ietatrue,  UsedCells);
00558           enHcalNoise -> Fill(ietatrue,  eHcalConeNoise);
00559           nCellsNoise -> Fill(ietatrue,  UsedCellsNoise); 
00560 
00561           iEta = ietatrue;
00562           iPhi = iphitrue;
00563 
00564           pfTree->Fill();
00565         }
00566     }
00567 }
00568 
00569 void HcalCorrPFCalculation::beginJob(){
00570   
00571   // TProfile *nCells, *nCellsNoise, *en, *enNoise;
00572   //TFile *rootFile;
00573   
00574   //rootFile = new TFile(outputFile_.c_str(),"RECREATE");
00575   
00576   
00577   nCells = fs->make<TProfile>("nCells", "nCells", 83, -41.5, 41.5); 
00578   nCellsNoise = fs->make<TProfile>("nCellsNoise", "nCellsNoise", 83, -41.5, 41.5); 
00579   
00580   enHcal = fs->make<TProfile>("enHcal", "enHcal", 83, -41.5, 41.5); 
00581   enHcalNoise =  fs->make<TProfile>("enHcalNoise", "enHcalNoise", 83, -41.5, 41.5); 
00582   
00583   enEcalB = fs->make<TH1F>("enEcalB", "enEcalB", 500, -5,50); 
00584   enEcalE = fs->make<TH1F>("enEcalE", "enEcalE", 500, -5,50); 
00585 
00586  pfTree = new TTree("pfTree", "Tree for pf info");
00587 
00588  pfTree->Branch("eEcalCone", &eEcalCone, "eEcalCone/F");
00589  pfTree->Branch("eHcalCone", &eHcalCone, "eHcalCone/F");
00590  pfTree->Branch("eHcalConeNoise", &eHcalConeNoise, "eHcalConeNoise/F");
00591 
00592  pfTree->Branch("UsedCellsNoise", &UsedCellsNoise, "UsedCellsNoise/I");
00593  pfTree->Branch("UsedCells", &UsedCells, "UsedCells/I");
00594 
00595  
00596  // pfTree->Branch("etaTrack", &etaTrack, "etaTrack/F");
00597  //pfTree->Branch("phiTrack", &phiTrack, "phiTrack/F");
00598  
00599  pfTree->Branch("iEta", &iEta, "iEta/I");
00600  pfTree->Branch("iPhi", &iPhi, "iPhi/I");
00601  
00602 
00603 }
00604 void HcalCorrPFCalculation::endJob() 
00605 {
00606 
00607   /*
00608   nCells -> Write();
00609   nCellsNoise -> Write();
00610   enHcal -> Write();
00611   enHcalNoise -> Write();
00612   
00613   enEcalB -> Write();
00614   enEcalE -> Write();
00615 
00616   rootFile->Close();
00617   */
00618 }
00619 
00620 
00621 #include "FWCore/PluginManager/interface/ModuleDef.h"
00622 #include "FWCore/Framework/interface/MakerMacros.h"
00623 
00624 
00625 //define this as a plug-in
00626 DEFINE_FWK_MODULE(HcalCorrPFCalculation);