Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/SimpleCalorimeter.cc

    r341014c r7da1826  
    1717 */
    1818
     19
    1920/** \class SimpleCalorimeter
    2021 *
     
    3233#include "classes/DelphesFormula.h"
    3334
     35#include "ExRootAnalysis/ExRootResult.h"
     36#include "ExRootAnalysis/ExRootFilter.h"
    3437#include "ExRootAnalysis/ExRootClassifier.h"
    35 #include "ExRootAnalysis/ExRootFilter.h"
    36 #include "ExRootAnalysis/ExRootResult.h"
    37 
     38
     39#include "TMath.h"
     40#include "TString.h"
     41#include "TFormula.h"
     42#include "TRandom3.h"
     43#include "TObjArray.h"
    3844#include "TDatabasePDG.h"
    39 #include "TFormula.h"
    4045#include "TLorentzVector.h"
    41 #include "TMath.h"
    42 #include "TObjArray.h"
    43 #include "TRandom3.h"
    44 #include "TString.h"
    4546
    4647#include <algorithm>
     48#include <stdexcept>
    4749#include <iostream>
    4850#include <sstream>
    49 #include <stdexcept>
    5051
    5152using namespace std;
     
    5758  fItParticleInputArray(0), fItTrackInputArray(0)
    5859{
    59 
     60 
    6061  fResolutionFormula = new DelphesFormula;
    6162  fTowerTrackArray = new TObjArray;
    6263  fItTowerTrackArray = fTowerTrackArray->MakeIterator();
     64 
    6365}
    6466
     
    6769SimpleCalorimeter::~SimpleCalorimeter()
    6870{
    69 
     71 
    7072  if(fResolutionFormula) delete fResolutionFormula;
    7173  if(fTowerTrackArray) delete fTowerTrackArray;
    7274  if(fItTowerTrackArray) delete fItTowerTrackArray;
     75 
    7376}
    7477
     
    8184  Double_t fraction;
    8285  TBinMap::iterator itEtaBin;
    83   set<Double_t>::iterator itPhiBin;
    84   vector<Double_t> *phiBins;
     86  set< Double_t >::iterator itPhiBin;
     87  vector< Double_t > *phiBins;
    8588
    8689  // read eta and phi bins
     
    9093  fEtaBins.clear();
    9194  fPhiBins.clear();
    92   for(i = 0; i < size / 2; ++i)
    93   {
    94     paramEtaBins = param[i * 2];
     95  for(i = 0; i < size/2; ++i)
     96  {
     97    paramEtaBins = param[i*2];
    9598    sizeEtaBins = paramEtaBins.GetSize();
    96     paramPhiBins = param[i * 2 + 1];
     99    paramPhiBins = param[i*2 + 1];
    97100    sizePhiBins = paramPhiBins.GetSize();
    98101
     
    111114  {
    112115    fEtaBins.push_back(itEtaBin->first);
    113     phiBins = new vector<double>(itEtaBin->second.size());
     116    phiBins = new vector< double >(itEtaBin->second.size());
    114117    fPhiBins.push_back(phiBins);
    115118    phiBins->clear();
     
    128131  fFractionMap[0] = 1.0;
    129132
    130   for(i = 0; i < size / 2; ++i)
    131   {
    132     paramFractions = param[i * 2 + 1];
     133  for(i = 0; i < size/2; ++i)
     134  {
     135    paramFractions = param[i*2 + 1];
    133136    fraction = paramFractions[0].GetDouble();
    134     fFractionMap[param[i * 2].GetInt()] = fraction;
     137    fFractionMap[param[i*2].GetInt()] = fraction;
    135138  }
    136139
     
    167170void SimpleCalorimeter::Finish()
    168171{
    169   vector<vector<Double_t> *>::iterator itPhiBin;
     172  vector< vector< Double_t >* >::iterator itPhiBin;
    170173  if(fItParticleInputArray) delete fItParticleInputArray;
    171174  if(fItTrackInputArray) delete fItTrackInputArray;
     
    194197  TFractionMap::iterator itFractionMap;
    195198
    196   vector<Double_t>::iterator itEtaBin;
    197   vector<Double_t>::iterator itPhiBin;
    198   vector<Double_t> *phiBins;
    199 
    200   vector<Long64_t>::iterator itTowerHits;
     199  vector< Double_t >::iterator itEtaBin;
     200  vector< Double_t >::iterator itPhiBin;
     201  vector< Double_t > *phiBins;
     202
     203  vector< Long64_t >::iterator itTowerHits;
    201204
    202205  DelphesFactory *factory = GetFactory();
     
    208211  fItParticleInputArray->Reset();
    209212  number = -1;
    210   while((particle = static_cast<Candidate *>(fItParticleInputArray->Next())))
     213  while((particle = static_cast<Candidate*>(fItParticleInputArray->Next())))
    211214  {
    212215    const TLorentzVector &particlePosition = particle->Position;
     
    251254  fItTrackInputArray->Reset();
    252255  number = -1;
    253   while((track = static_cast<Candidate *>(fItTrackInputArray->Next())))
     256  while((track = static_cast<Candidate*>(fItTrackInputArray->Next())))
    254257  {
    255258    const TLorentzVector &trackPosition = track->Position;
     
    300303    towerHit = (*itTowerHits);
    301304    flags = (towerHit >> 24) & 0x00000000000000FFLL;
    302     number = (towerHit)&0x0000000000FFFFFFLL;
     305    number = (towerHit) & 0x0000000000FFFFFFLL;
    303306    hitEtaPhi = towerHit >> 32;
    304307
     
    321324
    322325      // calculate eta and phi of the tower's center
    323       fTowerEta = 0.5 * (fEtaBins[etaBin - 1] + fEtaBins[etaBin]);
    324       fTowerPhi = 0.5 * ((*phiBins)[phiBin - 1] + (*phiBins)[phiBin]);
     326      fTowerEta = 0.5*(fEtaBins[etaBin - 1] + fEtaBins[etaBin]);
     327      fTowerPhi = 0.5*((*phiBins)[phiBin - 1] + (*phiBins)[phiBin]);
    325328
    326329      fTowerEdges[0] = fEtaBins[etaBin - 1];
     
    343346
    344347      fTowerTrackArray->Clear();
    345     }
     348     }
    346349
    347350    // check for track hits
     
    350353      ++fTowerTrackHits;
    351354
    352       track = static_cast<Candidate *>(fTrackInputArray->At(number));
     355      track = static_cast<Candidate*>(fTrackInputArray->At(number));
    353356      momentum = track->Momentum;
    354357      position = track->Position;
     
    356359      energy = momentum.E() * fTrackFractions[number];
    357360
    358       fTrackTime += TMath::Sqrt(energy) * position.T();
     361      fTrackTime += TMath::Sqrt(energy)*position.T();
    359362      fTrackTimeWeight += TMath::Sqrt(energy);
    360363
    361364      if(fTrackFractions[number] > 1.0E-9)
    362365      {
    363 
    364         // compute total charged energy
    365         fTrackEnergy += energy;
    366         sigma = fResolutionFormula->Eval(0.0, fTowerEta, 0.0, momentum.E());
    367         if(sigma / momentum.E() < track->TrackResolution)
    368           energyGuess = energy;
    369         else
    370           energyGuess = momentum.E();
    371 
    372         fTrackSigma += ((track->TrackResolution) * energyGuess) * ((track->TrackResolution) * energyGuess);
    373         fTowerTrackArray->Add(track);
     366             
     367       // compute total charged energy   
     368       fTrackEnergy += energy;
     369       sigma = fResolutionFormula->Eval(0.0, fTowerEta, 0.0, momentum.E());
     370       if(sigma/momentum.E() < track->TrackResolution) energyGuess = energy;
     371       else energyGuess = momentum.E();
     372
     373       fTrackSigma += ((track->TrackResolution)*energyGuess)*((track->TrackResolution)*energyGuess);
     374       fTowerTrackArray->Add(track);
    374375      }
    375 
     376       
    376377      else
    377378      {
     
    385386    if(flags & 2) ++fTowerPhotonHits;
    386387
    387     particle = static_cast<Candidate *>(fParticleInputArray->At(number));
     388    particle = static_cast<Candidate*>(fParticleInputArray->At(number));
    388389    momentum = particle->Momentum;
    389390    position = particle->Position;
     
    394395    fTowerEnergy += energy;
    395396
    396     fTowerTime += energy * position.T();
     397    fTowerTime += energy*position.T();
    397398    fTowerTimeWeight += energy;
    398399
     
    409410{
    410411  Candidate *tower, *track, *mother;
    411   Double_t energy, neutralEnergy, pt, eta, phi;
     412  Double_t energy,neutralEnergy, pt, eta, phi;
    412413  Double_t sigma, neutralSigma;
    413414  Double_t time;
    414 
     415   
    415416  Double_t weightTrack, weightCalo, bestEnergyEstimate, rescaleFactor;
    416417
     
    424425  energy = LogNormal(fTowerEnergy, sigma);
    425426
    426   time = (fTowerTimeWeight < 1.0E-09) ? 0.0 : fTowerTime / fTowerTimeWeight;
     427  time = (fTowerTimeWeight < 1.0E-09 ) ? 0.0 : fTowerTime/fTowerTimeWeight;
    427428
    428429  sigma = fResolutionFormula->Eval(0.0, fTowerEta, 0.0, energy);
    429430
    430   if(energy < fEnergyMin || energy < fEnergySignificanceMin * sigma) energy = 0.0;
     431  if(energy < fEnergyMin || energy < fEnergySignificanceMin*sigma) energy = 0.0;
     432
    431433
    432434  if(fSmearTowerCenter)
     
    457459  if(energy > 0.0) fTowerOutputArray->Add(fTower);
    458460
     461 
    459462  // e-flow candidates
    460463
    461464  //compute neutral excess
    462 
     465 
    463466  fTrackSigma = TMath::Sqrt(fTrackSigma);
    464   neutralEnergy = max((energy - fTrackEnergy), 0.0);
    465 
     467  neutralEnergy = max( (energy - fTrackEnergy) , 0.0);
     468 
    466469  //compute sigma_trk total
    467   neutralSigma = neutralEnergy / TMath::Sqrt(fTrackSigma * fTrackSigma + sigma * sigma);
    468 
     470  neutralSigma = neutralEnergy / TMath::Sqrt(fTrackSigma*fTrackSigma+ sigma*sigma);
     471   
    469472  // if neutral excess is significant, simply create neutral Eflow tower and clone each track into eflowtrack
    470473  if(neutralEnergy > fEnergyMin && neutralSigma > fEnergySignificanceMin)
    471474  {
    472475    // create new photon tower
    473     tower = static_cast<Candidate *>(fTower->Clone());
     476    tower = static_cast<Candidate*>(fTower->Clone());
    474477    pt = neutralEnergy / TMath::CosH(eta);
    475478
     
    477480    tower->Ehad = (fIsEcal) ? 0 : neutralEnergy;
    478481    tower->PID = (fIsEcal) ? 22 : 0;
    479 
     482 
    480483    tower->Momentum.SetPtEtaPhiE(pt, eta, phi, neutralEnergy);
    481484    fEFlowTowerOutputArray->Add(tower);
    482 
     485   
    483486    fItTowerTrackArray->Reset();
    484     while((track = static_cast<Candidate *>(fItTowerTrackArray->Next())))
     487    while((track = static_cast<Candidate*>(fItTowerTrackArray->Next())))
    485488    {
    486489      mother = track;
    487       track = static_cast<Candidate *>(track->Clone());
     490      track = static_cast<Candidate*>(track->Clone());
    488491      track->AddCandidate(mother);
    489492
     
    491494    }
    492495  }
    493 
     496   
    494497  // if neutral excess is not significant, rescale eflow tracks, such that the total charged equals the best measurement given by the calorimeter and tracking
    495   else if(fTrackEnergy > 0.0)
    496   {
    497     weightTrack = (fTrackSigma > 0.0) ? 1 / (fTrackSigma * fTrackSigma) : 0.0;
    498     weightCalo = (sigma > 0.0) ? 1 / (sigma * sigma) : 0.0;
    499 
    500     bestEnergyEstimate = (weightTrack * fTrackEnergy + weightCalo * energy) / (weightTrack + weightCalo);
    501     rescaleFactor = bestEnergyEstimate / fTrackEnergy;
    502 
     498  else if (fTrackEnergy > 0.0)
     499  {
     500    weightTrack = (fTrackSigma > 0.0) ? 1 / (fTrackSigma*fTrackSigma) : 0.0;
     501    weightCalo  = (sigma > 0.0) ? 1 / (sigma*sigma) : 0.0;
     502 
     503    bestEnergyEstimate = (weightTrack*fTrackEnergy + weightCalo*energy) / (weightTrack + weightCalo);
     504    rescaleFactor = bestEnergyEstimate/fTrackEnergy;
     505   
    503506    fItTowerTrackArray->Reset();
    504     while((track = static_cast<Candidate *>(fItTowerTrackArray->Next())))
     507    while((track = static_cast<Candidate*>(fItTowerTrackArray->Next())))
    505508    {
    506509      mother = track;
    507       track = static_cast<Candidate *>(track->Clone());
     510      track = static_cast<Candidate*>(track->Clone());
    508511      track->AddCandidate(mother);
    509512
     
    513516    }
    514517  }
     518   
     519 }
     520
     521//------------------------------------------------------------------------------
     522
     523Double_t SimpleCalorimeter::LogNormal(Double_t mean, Double_t sigma)
     524{
     525  Double_t a, b;
     526
     527  if(mean > 0.0)
     528  {
     529    b = TMath::Sqrt(TMath::Log((1.0 + (sigma*sigma)/(mean*mean))));
     530    a = TMath::Log(mean) - 0.5*b*b;
     531
     532    return TMath::Exp(a + b*gRandom->Gaus(0.0, 1.0));
     533  }
     534  else
     535  {
     536    return 0.0;
     537  }
    515538}
    516 
    517 //------------------------------------------------------------------------------
    518 
    519 Double_t SimpleCalorimeter::LogNormal(Double_t mean, Double_t sigma)
    520 {
    521   Double_t a, b;
    522 
    523   if(mean > 0.0)
    524   {
    525     b = TMath::Sqrt(TMath::Log((1.0 + (sigma * sigma) / (mean * mean))));
    526     a = TMath::Log(mean) - 0.5 * b * b;
    527 
    528     return TMath::Exp(a + b * gRandom->Gaus(0.0, 1.0));
    529   }
    530   else
    531   {
    532     return 0.0;
    533   }
    534 }
Note: See TracChangeset for help on using the changeset viewer.