Fork me on GitHub

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • classes/DelphesHepMC3Reader.cc

    rb4786d3 ra26a130  
    5656DelphesHepMC3Reader::DelphesHepMC3Reader() :
    5757  fInputFile(0), fBuffer(0), fPDG(0),
    58   fVertexCounter(-1), fParticleCounter(-1)
     58  fVertexCounter(-2), fParticleCounter(-1)
    5959{
    6060  fBuffer = new char[kBufferSize];
     
    8181void DelphesHepMC3Reader::Clear()
    8282{
    83   fWeight.clear();
     83  fWeights.clear();
    8484  fMomentumCoefficient = 1.0;
    8585  fPositionCoefficient = 1.0;
    86   fVertexCounter = -1;
     86  fVertexCounter = -2;
    8787  fParticleCounter = -1;
    88   fVertexMap.clear();
     88  fVertices.clear();
     89  fParticles.clear();
     90  fInVertexMap.clear();
     91  fOutVertexMap.clear();
     92  fMotherMap.clear();
    8993  fDaughterMap.clear();
    9094}
     
    9498bool DelphesHepMC3Reader::EventReady()
    9599{
    96   return (fParticleCounter == 0);
     100  return (fVertexCounter == -1) && (fParticleCounter == 0);
    97101}
    98102
     
    119123    Clear();
    120124
    121     fX = 0.0;
    122     fY = 0.0;
    123     fZ = 0.0;
    124     fT = 0.0;
    125 
    126125    rc = bufferStream.ReadInt(fEventNumber)
    127126      && bufferStream.ReadInt(fVertexCounter)
     
    168167    while(bufferStream.ReadDbl(weight))
    169168    {
    170       fWeight.push_back(weight);
     169      fWeights.push_back(weight);
    171170    }
    172171  }
     
    257256  else if(key == 'V')
    258257  {
     258    fParticles.clear();
     259
    259260    fX = 0.0;
    260261    fY = 0.0;
     
    262263    fT = 0.0;
    263264
    264     fM1 = 0;
    265     fM2 = 0;
    266 
    267265    rc = bufferStream.ReadInt(fVertexCode)
    268266      && bufferStream.ReadInt(fVertexStatus);
     
    286284    while(bufferStream.ReadInt(code))
    287285    {
    288       if(code < fM1 || fM1 == 0) fM1 = code;
    289       if(code > fM2) fM2 = code;
    290       fVertexMap[code] = fVertexCode;
    291     }
    292 
    293     if(fM1 == fM2) fM2 = 0;
     286      fParticles.push_back(code);
     287      bufferStream.FindChr(',');
     288    }
    294289
    295290    if(bufferStream.FindChr('@'))
     
    307302      }
    308303    }
     304
     305    AnalyzeVertex(factory, fVertexCode);
    309306  }
    310307  else if(key == 'P' && fParticleCounter > 0)
     
    329326    }
    330327
    331     itDaughterMap = fDaughterMap.find(fOutVertexCode);
    332     if(itDaughterMap == fDaughterMap.end())
    333     {
    334       fDaughterMap[fOutVertexCode] = make_pair(fParticleCode, fParticleCode);
    335     }
    336     else
    337     {
    338       itDaughterMap->second.second = fParticleCode;
    339     }
    340 
    341     AnalyzeParticle(factory, allParticleOutputArray,
    342       stableParticleOutputArray, partonOutputArray);
     328    AnalyzeParticle(factory);
    343329  }
    344330
    345331  if(EventReady())
    346332  {
    347     FinalizeParticles(allParticleOutputArray);
     333    FinalizeParticles(allParticleOutputArray, stableParticleOutputArray, partonOutputArray);
    348334  }
    349335
     
    363349  element->ProcessID = fProcessID;
    364350  element->MPI = fMPI;
    365   element->Weight = fWeight.size() > 0 ? fWeight[0] : 1.0;
     351  element->Weight = fWeights.size() > 0 ? fWeights[0] : 1.0;
    366352  element->CrossSection = fCrossSection;
    367353  element->CrossSectionError = fCrossSectionError;
     
    387373{
    388374  Weight *element;
    389   vector<double>::const_iterator itWeight;
    390 
    391   for(itWeight = fWeight.begin(); itWeight != fWeight.end(); ++itWeight)
     375  vector<double>::const_iterator itWeights;
     376
     377  for(itWeights = fWeights.begin(); itWeights != fWeights.end(); ++itWeights)
    392378  {
    393379    element = static_cast<Weight *>(branch->NewEntry());
    394380
    395     element->Weight = *itWeight;
    396   }
    397 }
    398 
    399 //---------------------------------------------------------------------------
    400 
    401 void DelphesHepMC3Reader::AnalyzeParticle(DelphesFactory *factory,
    402   TObjArray *allParticleOutputArray,
     381    element->Weight = *itWeights;
     382  }
     383}
     384
     385//---------------------------------------------------------------------------
     386
     387void DelphesHepMC3Reader::AnalyzeVertex(DelphesFactory *factory, int code, Candidate *candidate)
     388{
     389  int index;
     390  TLorentzVector *position;
     391  TObjArray *array;
     392  vector<int>::iterator itParticle;
     393  map<int, int>::iterator itVertexMap;
     394
     395  itVertexMap = fOutVertexMap.find(code);
     396  if(itVertexMap == fOutVertexMap.end())
     397  {
     398    --fVertexCounter;
     399
     400    index = fVertices.size();
     401    fOutVertexMap[code] = index;
     402    if(candidate && code > 0) fInVertexMap[code] = index;
     403
     404    position = factory->New<TLorentzVector>();
     405    array = factory->NewArray();
     406    position->SetXYZT(0.0, 0.0, 0.0, 0.0);
     407    fVertices.push_back(make_pair(position, array));
     408  }
     409  else
     410  {
     411    index = itVertexMap->second;
     412    position = fVertices[index].first;
     413    array = fVertices[index].second;
     414  }
     415
     416  if(candidate)
     417  {
     418    array->Add(candidate);
     419  }
     420  else
     421  {
     422    position->SetXYZT(fX, fY, fZ, fT);
     423    for(itParticle = fParticles.begin(); itParticle != fParticles.end(); ++itParticle)
     424    {
     425      fInVertexMap[*itParticle] = index;
     426    }
     427  }
     428}
     429
     430//---------------------------------------------------------------------------
     431
     432void DelphesHepMC3Reader::AnalyzeParticle(DelphesFactory *factory)
     433{
     434  Candidate *candidate;
     435
     436  candidate = factory->NewCandidate();
     437
     438  candidate->PID = fPID;
     439
     440  candidate->Status = fParticleStatus;
     441
     442  candidate->Mass = fMass;
     443
     444  candidate->Momentum.SetPxPyPzE(fPx, fPy, fPz, fE);
     445
     446  candidate->D1 = fParticleCode;
     447
     448  AnalyzeVertex(factory, fOutVertexCode, candidate);
     449}
     450
     451//---------------------------------------------------------------------------
     452
     453void DelphesHepMC3Reader::FinalizeParticles(TObjArray *allParticleOutputArray,
    403454  TObjArray *stableParticleOutputArray,
    404455  TObjArray *partonOutputArray)
    405456{
     457  TLorentzVector *position;
     458  TObjArray *array;
    406459  Candidate *candidate;
    407460  TParticlePDG *pdgParticle;
    408461  int pdgCode;
    409 
    410   candidate = factory->NewCandidate();
    411 
    412   candidate->PID = fPID;
    413   pdgCode = TMath::Abs(candidate->PID);
    414 
    415   candidate->Status = fParticleStatus;
    416 
    417   pdgParticle = fPDG->GetParticle(fPID);
    418   candidate->Charge = pdgParticle ? int(pdgParticle->Charge() / 3.0) : -999;
    419   candidate->Mass = fMass;
    420 
    421   candidate->Momentum.SetPxPyPzE(fPx, fPy, fPz, fE);
    422   if(fMomentumCoefficient != 1.0)
    423   {
    424     candidate->Momentum *= fMomentumCoefficient;
    425   }
    426 
    427   candidate->Position.SetXYZT(fX, fY, fZ, fT);
    428   if(fPositionCoefficient != 1.0)
    429   {
    430     candidate->Position *= fPositionCoefficient;
    431   }
    432 
    433   candidate->D1 = -1;
    434   candidate->D2 = -1;
    435 
    436   if(fOutVertexCode < 0)
    437   {
    438     candidate->M1 = fM1 - 1;
    439     candidate->M2 = fM2 - 1;
    440   }
    441   else
    442   {
    443     candidate->M1 = fOutVertexCode - 1;
    444     candidate->M2 = -1;
    445   }
    446 
    447   allParticleOutputArray->Add(candidate);
    448 
    449   if(!pdgParticle) return;
    450 
    451   if(fParticleStatus == 1)
    452   {
    453     stableParticleOutputArray->Add(candidate);
    454   }
    455   else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
    456   {
    457     partonOutputArray->Add(candidate);
    458   }
    459 }
    460 
    461 //---------------------------------------------------------------------------
    462 
    463 void DelphesHepMC3Reader::FinalizeParticles(TObjArray *allParticleOutputArray)
    464 {
    465   Candidate *candidate;
    466462  map<int, int >::iterator itVertexMap;
     463  map<int, pair<int, int> >::iterator itMotherMap;
    467464  map<int, pair<int, int> >::iterator itDaughterMap;
    468   int i, index;
     465  int i, j, code, counter;
     466
     467  counter = 0;
     468  for(i = 0; i < fVertices.size(); ++i)
     469  {
     470    position = fVertices[i].first;
     471    array = fVertices[i].second;
     472
     473    for(j = 0; j < array->GetEntriesFast(); ++j)
     474    {
     475      candidate = static_cast<Candidate *>(array->At(j));
     476
     477      candidate->Position = *position;
     478      if(fPositionCoefficient != 1.0)
     479      {
     480        candidate->Position *= fPositionCoefficient;
     481      }
     482
     483      if(fMomentumCoefficient != 1.0)
     484      {
     485        candidate->Momentum *= fMomentumCoefficient;
     486      }
     487
     488      candidate->M1 = i;
     489
     490      itDaughterMap = fDaughterMap.find(i);
     491      if(itDaughterMap == fDaughterMap.end())
     492      {
     493        fDaughterMap[i] = make_pair(counter, counter);
     494      }
     495      else
     496      {
     497        itDaughterMap->second.second = counter;
     498      }
     499
     500      code = candidate->D1;
     501
     502      itVertexMap = fInVertexMap.find(code);
     503      if(itVertexMap == fInVertexMap.end())
     504      {
     505        candidate->D1 = -1;
     506      }
     507      else
     508      {
     509        code = itVertexMap->second;
     510
     511        candidate->D1 = code;
     512
     513        itMotherMap = fMotherMap.find(code);
     514        if(itMotherMap == fMotherMap.end())
     515        {
     516          fMotherMap[code] = make_pair(counter, -1);
     517        }
     518        else
     519        {
     520          itMotherMap->second.second = counter;
     521        }
     522      }
     523
     524      allParticleOutputArray->Add(candidate);
     525
     526      ++counter;
     527
     528      pdgParticle = fPDG->GetParticle(candidate->PID);
     529
     530      candidate->Charge = pdgParticle ? int(pdgParticle->Charge() / 3.0) : -999;
     531
     532      if(!pdgParticle) continue;
     533
     534      pdgCode = TMath::Abs(candidate->PID);
     535
     536      if(candidate->Status == 1)
     537      {
     538        stableParticleOutputArray->Add(candidate);
     539      }
     540      else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
     541      {
     542        partonOutputArray->Add(candidate);
     543      }
     544    }
     545  }
    469546
    470547  for(i = 0; i < allParticleOutputArray->GetEntriesFast(); ++i)
     
    472549    candidate = static_cast<Candidate *>(allParticleOutputArray->At(i));
    473550
    474     index = i + 1;
    475 
    476     itVertexMap = fVertexMap.find(index);
    477     if(itVertexMap != fVertexMap.end())
    478     {
    479       index = itVertexMap->second;
    480     }
    481 
    482     itDaughterMap = fDaughterMap.find(index);
    483     if(itDaughterMap == fDaughterMap.end())
     551    itMotherMap = fMotherMap.find(candidate->M1);
     552    if(itMotherMap == fMotherMap.end())
     553    {
     554      candidate->M1 = -1;
     555      candidate->M2 = -1;
     556    }
     557    else
     558    {
     559      candidate->M1 = itMotherMap->second.first;
     560      candidate->M2 = itMotherMap->second.second;
     561    }
     562
     563    if(candidate->D1 < 0)
    484564    {
    485565      candidate->D1 = -1;
     
    488568    else
    489569    {
    490       candidate->D1 = itDaughterMap->second.first - 1;
    491       candidate->D2 = itDaughterMap->second.second - 1;
    492     }
    493   }
    494 }
    495 
    496 //---------------------------------------------------------------------------
     570      itDaughterMap = fDaughterMap.find(candidate->D1);
     571      if(itDaughterMap == fDaughterMap.end())
     572      {
     573        candidate->D1 = -1;
     574        candidate->D2 = -1;
     575      }
     576      else
     577      {
     578        candidate->D1 = itDaughterMap->second.first;
     579        candidate->D2 = itDaughterMap->second.second;
     580      }
     581    }
     582  }
     583}
     584
     585//---------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.