CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

PileupInformation Class Reference

#include <PileupInformation.h>

Inheritance diagram for PileupInformation:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 PileupInformation (const edm::ParameterSet &)

Private Types

typedef std::map
< EncodedEventId, unsigned int > 
EncodedEventIdToIndex
typedef std::map< int, int > myindex

Private Member Functions

void produce (edm::Event &, const edm::EventSetup &)

Private Attributes

edm::ParameterSet conf_
double distanceCut_
myindex event_index_
std::string MessageCategory_
std::vector< int > ntrks_highpT
std::vector< int > ntrks_lowpT
double pTcut_1_
double pTcut_2_
std::string simHitLabel_
std::auto_ptr< MixCollection
< SimTrack > > 
simTracks_
std::auto_ptr< MixCollection
< SimVertex > > 
simVertexes_
std::vector< float > sumpT_highpT
std::vector< float > sumpT_lowpT
edm::InputTag trackingTruth_
double volumeRadius_
double volumeZ_
std::vector< float > zpositions

Detailed Description

Definition at line 29 of file PileupInformation.h.


Member Typedef Documentation

typedef std::map<EncodedEventId, unsigned int> PileupInformation::EncodedEventIdToIndex [private]

Definition at line 42 of file PileupInformation.h.

typedef std::map< int, int > PileupInformation::myindex [private]

Definition at line 43 of file PileupInformation.h.


Constructor & Destructor Documentation

PileupInformation::PileupInformation ( const edm::ParameterSet config) [explicit]

Definition at line 20 of file PileupInformation.cc.

References distanceCut_, edm::ParameterSet::getParameter(), MessageCategory_, pTcut_1_, pTcut_2_, simHitLabel_, trackingTruth_, volumeRadius_, and volumeZ_.

{
    // Initialize global parameters

    pTcut_1_                = 0.1;
    pTcut_2_                = 0.5; // defaults                                                       
    distanceCut_            = config.getParameter<double>("vertexDistanceCut");
    volumeRadius_           = config.getParameter<double>("volumeRadius");
    volumeZ_                = config.getParameter<double>("volumeZ");
    pTcut_1_                = config.getParameter<double>("pTcut_1");
    pTcut_2_                = config.getParameter<double>("pTcut_2");

    trackingTruth_  = config.getParameter<std::string>("TrackingParticlesLabel");

    simHitLabel_            = config.getParameter<std::string>("simHitLabel");

    MessageCategory_       = "PileupInformation";

    edm::LogInfo (MessageCategory_) << "Setting up PileupInformation";
    edm::LogInfo (MessageCategory_) << "Vertex distance cut set to " << distanceCut_  << " mm";
    edm::LogInfo (MessageCategory_) << "Volume radius set to "       << volumeRadius_ << " mm";
    edm::LogInfo (MessageCategory_) << "Volume Z      set to "       << volumeZ_      << " mm";
    edm::LogInfo (MessageCategory_) << "Lower pT Threshold set to "       << pTcut_1_      << " GeV";
    edm::LogInfo (MessageCategory_) << "Upper pT Threshold set to "       << pTcut_2_      << " GeV";


    produces< std::vector<PileupSummaryInfo> >();
    //produces<PileupSummaryInfo>();
}

Member Function Documentation

void PileupInformation::produce ( edm::Event event,
const edm::EventSetup setup 
) [private, virtual]

Implements edm::EDProducer.

Definition at line 51 of file PileupInformation.cc.

References EncodedEventId::bunchCrossing(), ExpressReco_HICollisions_FallBack::BunchCrossings, event_index_, PileupMixingContent::getMix_bunchCrossing(), PileupMixingContent::getMix_Ninteractions(), getHLTprescales::index, ntrks_highpT, ntrks_lowpT, edm::Handle< T >::product(), pTcut_1_, pTcut_2_, simHitLabel_, simVertexes_, mathSSE::sqrt(), sumpT_highpT, sumpT_lowpT, trackingTruth_, and zpositions.

{

  std::auto_ptr<std::vector<PileupSummaryInfo> > PSIVector(new std::vector<PileupSummaryInfo>);

  edm::Handle< PileupMixingContent > MixingPileup;  // Get True pileup information from MixingModule
  event.getByLabel("mix", MixingPileup);

  std::vector<int> BunchCrossings;
  std::vector<int> Interactions_Xing;

  const PileupMixingContent* MixInfo = MixingPileup.product();

  if(MixInfo) {  // extract information - way easier than counting vertices

    const std::vector<int> bunchCrossing = MixInfo->getMix_bunchCrossing();
    const std::vector<int> interactions = MixInfo->getMix_Ninteractions();

    for(int ib=0; ib<(int)bunchCrossing.size(); ++ib){
      //      std::cout << " bcr, nint " << bunchCrossing[ib] << " " << interactions[ib] << std::endl;
      BunchCrossings.push_back(bunchCrossing[ib]);
      Interactions_Xing.push_back(interactions[ib]);
    }
  }
  else{ //If no Mixing Truth, work with SimVertices  (probably should throw an exception, but...)

    // Collect all the simvertex from the crossing frame                                            
    edm::Handle<CrossingFrame<SimVertex> > cfSimVertexes;
    event.getByLabel("mix", simHitLabel_, cfSimVertexes);

    // Create a mix collection from one simvertex collection                                        
    simVertexes_ = std::auto_ptr<MixCollection<SimVertex> >( new MixCollection<SimVertex>(cfSimVertexes.product()) );

    int index = 0;
    // Solution to the problem of not having vertexId
    //    bool FirstL = true;
    EncodedEventIdToIndex vertexId;
    EncodedEventId oldEventId;
    unsigned int oldVertexId = 0;
    int oldBX = -1000;
    int oldEvent = 0;

    std::vector<int> BunchCrossings2;
    std::list<int> Interactions_Xing2;


    // Loop for finding repeated vertexId (vertexId problem hack)                                   
    for (MixCollection<SimVertex>::MixItr iterator = simVertexes_->begin(); iterator != simVertexes_->end(); ++iterator, ++index)
      {
        //      std::cout << " SimVtx eventid, vertexid " << iterator->eventId().event() << " " << iterator->eventId().bunchCrossing() << std::endl;
        if (!index || iterator->eventId() != oldEventId)
          {
            if(iterator->eventId().bunchCrossing()==0 && iterator->eventId().event()==0){
              continue;
            }
            if(iterator->eventId().bunchCrossing() != oldBX) {
              BunchCrossings2.push_back(iterator->eventId().bunchCrossing());
              Interactions_Xing2.push_back(iterator->eventId().event());
              oldBX = iterator->eventId().bunchCrossing();
              oldEvent = iterator->eventId().event();
            }
            else { Interactions_Xing2.pop_back();
              Interactions_Xing2.push_back(iterator->eventId().event());
              oldEvent = iterator->eventId().event();
            }


            oldEventId = iterator->eventId();
            oldVertexId = iterator->vertexId();
            continue;
          }

      }

    std::vector<int>::iterator viter;
    std::list<int>::iterator liter = Interactions_Xing2.begin();

    for(viter = BunchCrossings2.begin(); viter != BunchCrossings2.end(); ++viter, ++liter){
      //std::cout << " bcr, nint from VTX " << (*viter) << " " << (*liter) << std::endl;
      BunchCrossings.push_back((*viter));
      Interactions_Xing.push_back((*liter));
    }
  } // end of look at SimVertices


  //Now, get information on valid particles that look like they could be in the tracking volume

  edm::Handle<TrackingParticleCollection> mergedPH;
  edm::Handle<TrackingVertexCollection>   mergedVH;

  event.getByLabel(trackingTruth_, mergedPH);
  event.getByLabel(trackingTruth_, mergedVH);


  zpositions.clear();
  sumpT_lowpT.clear();
  sumpT_highpT.clear();
  ntrks_lowpT.clear();
  ntrks_highpT.clear();
  event_index_.clear();

  int lastEvent = 0; // zero is the true MC hard-scatter event

  int lastBunchCrossing = 0; // 0 is the true bunch crossing, should always come first.

  TrackingVertexCollection::const_iterator iVtx;
  TrackingVertexCollection::const_iterator iVtxTest = mergedVH->begin();
  TrackingParticleCollection::const_iterator iTrackTest = mergedPH->begin();

  int nminb_vtx = 0;
  //  bool First = true;
  //  bool flag_new = false;

  std::vector<int>::iterator BXIter;
  std::vector<int>::iterator InteractionsIter = Interactions_Xing.begin();

  // loop over the bunch crossings and interactions we have extracted 

  for( BXIter = BunchCrossings.begin(); BXIter != BunchCrossings.end(); ++BXIter, ++InteractionsIter) {

    //std::cout << "looking for BX: " << (*BXIter) << std::endl;

    for (iVtx = iVtxTest; iVtx != mergedVH->end(); ++iVtx) {     

      if(iVtx->eventId().bunchCrossing() == (*BXIter) ) { // found first vertex in this bunch crossing

        if(iVtx->eventId().event() != lastEvent) {

          //std::cout << "BX,event " << iVtx->eventId().bunchCrossing() << " " << iVtx->eventId().event() << std::endl;

             float zpos = 0.;
             zpos = iVtx->position().z();
             zpositions.push_back(zpos);  //save z position of each vertex
             sumpT_lowpT.push_back(0.);
             sumpT_highpT.push_back(0.);
             ntrks_lowpT.push_back(0);
             ntrks_highpT.push_back(0);

             lastEvent = iVtx->eventId().event();
             iVtxTest = --iVtx; // just for security

             // turns out events aren't sequential... save map of indices

             event_index_.insert(myindex::value_type(lastEvent,nminb_vtx));
             
             ++nminb_vtx;

             continue;
        }
      }
    }
    
    // next loop over tracks to get information

    for (TrackingParticleCollection::const_iterator iTrack = iTrackTest; iTrack != mergedPH->end(); ++iTrack)
      {
        bool FoundTrk = false;

        float zpos=0.;

        if(iTrack->eventId().bunchCrossing() == (*BXIter) && iTrack->eventId().event() > 0 )
          {
            FoundTrk = true;
            int correct_index = event_index_[iTrack->eventId().event()];

            //std::cout << " track index, correct index " << iTrack->eventId().event() << " " << correct_index << std::endl;

            zpos = zpositions[correct_index];
            if(iTrack->matchedHit()>0) {
              if(fabs(iTrack->parentVertex()->position().z()-zpos)<0.1) {  //make sure track really comes from this vertex
                //std::cout << *iTrack << std::endl;                                              
                float Tpx = iTrack->p4().px();
                float Tpy = iTrack->p4().py();
                float TpT = sqrt(Tpx*Tpx + Tpy*Tpy);
                if( TpT>pTcut_1_ ) {
                  sumpT_lowpT[correct_index]+=TpT;
                  ++ntrks_lowpT[correct_index];
                }
                if( TpT>pTcut_2_ ){
                  sumpT_highpT[correct_index]+=TpT;
                  ++ntrks_highpT[correct_index];
                }
              }
            }
          }
        else{
          if(FoundTrk) {

            iTrackTest = --iTrack;  // reset so we can start over next time
            --iTrackTest;  // just to be sure
            break;
          }
        
        }
        
      } // end of track loop

        // now that we have all of the track information for a given bunch crossing, 
        // make PileupSummary for this one and move on

        //        std::cout << "Making PSI for bunch " << lastBunchCrossing << std::endl;

        PileupSummaryInfo       PSI_bunch = PileupSummaryInfo(
                                                              (*InteractionsIter),
                                                              zpositions,
                                                              sumpT_lowpT,
                                                              sumpT_highpT,
                                                              ntrks_lowpT,
                                                              ntrks_highpT,
                                                              (*BXIter)
                                                              );

        //std::cout << " " << std::endl;
        //std::cout << "Adding Bunch Crossing, nint " << (*BXIter) << " " <<  (*InteractionsIter) << std::endl;
 
        // for(int iv = 0; iv<nminb_vtx; ++iv){
            
          //  std::cout << "Z position " << zpositions[iv] << std::endl;
          //  std::cout << "ntrks_lowpT " << ntrks_lowpT[iv] << std::endl;
          //  std::cout << "sumpT_lowpT " << sumpT_lowpT[iv] << std::endl;
          //  std::cout << "ntrks_highpT " << ntrks_highpT[iv] << std::endl;
          //  std::cout << "sumpT_highpT " << sumpT_highpT[iv] << std::endl;
          // }

        PSIVector->push_back(PSI_bunch);

        lastBunchCrossing = iVtx->eventId().bunchCrossing();

        event_index_.clear();
        zpositions.clear();
        sumpT_lowpT.clear();
        sumpT_highpT.clear();
        ntrks_lowpT.clear();
        ntrks_highpT.clear();
        nminb_vtx = 0;
        lastEvent=0;


  } // end of loop over bunch crossings

  // put our vector of PileupSummaryInfo objects into the event.

  event.put(PSIVector);


}

Member Data Documentation

Definition at line 40 of file PileupInformation.h.

Definition at line 53 of file PileupInformation.h.

Referenced by PileupInformation().

Definition at line 44 of file PileupInformation.h.

Referenced by produce().

std::string PileupInformation::MessageCategory_ [private]

Definition at line 61 of file PileupInformation.h.

Referenced by PileupInformation().

std::vector<int> PileupInformation::ntrks_highpT [private]

Definition at line 50 of file PileupInformation.h.

Referenced by produce().

std::vector<int> PileupInformation::ntrks_lowpT [private]

Definition at line 49 of file PileupInformation.h.

Referenced by produce().

double PileupInformation::pTcut_1_ [private]

Definition at line 56 of file PileupInformation.h.

Referenced by PileupInformation(), and produce().

double PileupInformation::pTcut_2_ [private]

Definition at line 57 of file PileupInformation.h.

Referenced by PileupInformation(), and produce().

std::string PileupInformation::simHitLabel_ [private]

Definition at line 62 of file PileupInformation.h.

Referenced by PileupInformation(), and produce().

Definition at line 63 of file PileupInformation.h.

Definition at line 64 of file PileupInformation.h.

Referenced by produce().

std::vector<float> PileupInformation::sumpT_highpT [private]

Definition at line 48 of file PileupInformation.h.

Referenced by produce().

std::vector<float> PileupInformation::sumpT_lowpT [private]

Definition at line 47 of file PileupInformation.h.

Referenced by produce().

Definition at line 59 of file PileupInformation.h.

Referenced by PileupInformation(), and produce().

Definition at line 54 of file PileupInformation.h.

Referenced by PileupInformation().

double PileupInformation::volumeZ_ [private]

Definition at line 55 of file PileupInformation.h.

Referenced by PileupInformation().

std::vector<float> PileupInformation::zpositions [private]

Definition at line 46 of file PileupInformation.h.

Referenced by produce().