/*
* Delphes: a framework for fast simulation of a generic collider experiment
* Copyright (C) 2012-2014 Universite catholique de Louvain (UCL), Belgium
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/** \class TrackPileUpSubtractor
*
* Subtract pile-up contribution from tracks.
*
* \author P. Demin - UCL, Louvain-la-Neuve
*
*/
#include "modules/TrackPileUpSubtractor.h"
#include "classes/DelphesClasses.h"
#include "classes/DelphesFactory.h"
#include "classes/DelphesFormula.h"
#include "ExRootAnalysis/ExRootClassifier.h"
#include "ExRootAnalysis/ExRootFilter.h"
#include "ExRootAnalysis/ExRootResult.h"
#include "TDatabasePDG.h"
#include "TFormula.h"
#include "TLorentzVector.h"
#include "TMath.h"
#include "TObjArray.h"
#include "TRandom3.h"
#include "TString.h"
#include
#include
#include
#include
using namespace std;
//------------------------------------------------------------------------------
TrackPileUpSubtractor::TrackPileUpSubtractor() :
fFormula(0)
{
fFormula = new DelphesFormula;
}
//------------------------------------------------------------------------------
TrackPileUpSubtractor::~TrackPileUpSubtractor()
{
if(fFormula) delete fFormula;
}
//------------------------------------------------------------------------------
void TrackPileUpSubtractor::Init()
{
// import input array
fVertexInputArray = ImportArray(GetString("VertexInputArray", "PileUpMerger/vertices"));
fItVertexInputArray = fVertexInputArray->MakeIterator();
// read resolution formula in m
fFormula->Compile(GetString("ZVertexResolution", "0.001"));
fPTMin = GetDouble("PTMin", 0.);
// import arrays with output from other modules
ExRootConfParam param = GetParam("InputArray");
Long_t i, size;
const TObjArray *array;
TIterator *iterator;
size = param.GetSize();
for(i = 0; i < size / 2; ++i)
{
array = ImportArray(param[i * 2].GetString());
iterator = array->MakeIterator();
fInputMap[iterator] = ExportArray(param[i * 2 + 1].GetString());
}
}
//------------------------------------------------------------------------------
void TrackPileUpSubtractor::Finish()
{
map::iterator itInputMap;
TIterator *iterator;
for(itInputMap = fInputMap.begin(); itInputMap != fInputMap.end(); ++itInputMap)
{
iterator = itInputMap->first;
if(iterator) delete iterator;
}
if(fItVertexInputArray) delete fItVertexInputArray;
}
//------------------------------------------------------------------------------
void TrackPileUpSubtractor::Process()
{
Candidate *candidate, *particle, *particleTest;
map::iterator itInputMap;
TIterator *iterator;
TObjArray *array;
Double_t z, zvtx = 0;
Double_t pt, eta, phi, e;
Double_t sumPT2 = 0;
Double_t sumSquare = 0;
int counter = 0;
Double_t tempPTSquare = 0;
Double_t tempZVertex = 0;
// find z position of primary vertex
cout << " ---------- NEW EVENT --------- " << endl;
fItVertexInputArray->Reset();
cout << " NUMBER OF VERTICES : " << fVertexInputArray->GetEntriesFast() << endl;
while((candidate = static_cast(fItVertexInputArray->Next())))
{
cout << " ---------- NEW VERTEX --------- " << candidate->IsPU << endl;
tempZVertex = candidate->Position.Z();
tempPTSquare = candidate->SumPT2;
if(tempPTSquare > sumSquare)
{
sumSquare = tempPTSquare;
zvtx = tempZVertex;
cout << " Sum Square : " << sumSquare << " Z of Vertex : " << zvtx << " Is PileUp : " << candidate->IsPU << endl;
}
/*
for(int i = 0; i < candidate->GetCandidates()->GetEntriesFast(); i++)
{
particleTest = static_cast(candidate->GetCandidates()->At(i));
TLorentzVector &candidateMomentumNew = particleTest->Momentum;
if(candidateMomentumNew.Pt() > 1.0)
sumSquare += (candidateMomentumNew.Pt()*candidateMomentumNew.Pt());
cout << candidateMomentumNew.Pt() << " " << candidate->SumPT2 << " counter : " << candidate->GetCandidates()->GetEntriesFast() << endl;
}
*/
}
// loop over all input arrays
for(itInputMap = fInputMap.begin(); itInputMap != fInputMap.end(); ++itInputMap)
{
iterator = itInputMap->first;
array = itInputMap->second;
// loop over all candidates
iterator->Reset();
while((candidate = static_cast(iterator->Next())))
{
particle = static_cast(candidate->GetCandidates()->At(0));
const TLorentzVector &candidateMomentum = candidate->Momentum;
eta = candidateMomentum.Eta();
pt = candidateMomentum.Pt();
phi = candidateMomentum.Phi();
e = candidateMomentum.E();
z = candidate->Position.Z();
counter ++;
//sum = pt*pt;
if(pt > 1.0)
sumPT2 += pt*pt;
// apply pile-up subtraction
// assume perfect pile-up subtraction for tracks outside fZVertexResolution
// cout << particle->IsRecoPU << " ParticleSumSquare : " << sumPT2 << " VertexResult : " << sumSquare << " Added SumSquare : " << zvtx << endl;
//cout << pt << " " << candidate->IsPU << " " << TMath::Abs(z - zvtx) << " " << sumPT2 << " " << sumPT2 << endl;
if(particle->Charge != 0 && TMath::Abs(z - zvtx) > fFormula->Eval(pt, eta, phi, e) * 1.0e3)
{
candidate->IsRecoPU = 1;
//cout << TMath::Abs(z - zvtx) << " " << fFormula->Eval(pt, eta, phi, e) * 1.0e3 << endl;
}
else
{
candidate->IsRecoPU = 0;
if(candidate->Momentum.Pt() > fPTMin) array->Add(candidate);
}
}
}
}