CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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

Public Member Functions

 PileupInformation (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

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
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

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_.

21 {
22  // Initialize global parameters
23 
24  pTcut_1_ = 0.1;
25  pTcut_2_ = 0.5; // defaults
26  distanceCut_ = config.getParameter<double>("vertexDistanceCut");
27  volumeRadius_ = config.getParameter<double>("volumeRadius");
28  volumeZ_ = config.getParameter<double>("volumeZ");
29  pTcut_1_ = config.getParameter<double>("pTcut_1");
30  pTcut_2_ = config.getParameter<double>("pTcut_2");
31 
32  trackingTruth_ = config.getParameter<std::string>("TrackingParticlesLabel");
33 
34  simHitLabel_ = config.getParameter<std::string>("simHitLabel");
35 
36  MessageCategory_ = "PileupInformation";
37 
38  edm::LogInfo (MessageCategory_) << "Setting up PileupInformation";
39  edm::LogInfo (MessageCategory_) << "Vertex distance cut set to " << distanceCut_ << " mm";
40  edm::LogInfo (MessageCategory_) << "Volume radius set to " << volumeRadius_ << " mm";
41  edm::LogInfo (MessageCategory_) << "Volume Z set to " << volumeZ_ << " mm";
42  edm::LogInfo (MessageCategory_) << "Lower pT Threshold set to " << pTcut_1_ << " GeV";
43  edm::LogInfo (MessageCategory_) << "Upper pT Threshold set to " << pTcut_2_ << " GeV";
44 
45 
46  produces< std::vector<PileupSummaryInfo> >();
47  //produces<PileupSummaryInfo>();
48 }
T getParameter(std::string const &) const
std::string MessageCategory_
edm::InputTag trackingTruth_
std::string simHitLabel_

Member Function Documentation

void PileupInformation::produce ( edm::Event event,
const edm::EventSetup setup 
)
privatevirtual

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.

52 {
53 
54  std::auto_ptr<std::vector<PileupSummaryInfo> > PSIVector(new std::vector<PileupSummaryInfo>);
55 
56  edm::Handle< PileupMixingContent > MixingPileup; // Get True pileup information from MixingModule
57  event.getByLabel("mix", MixingPileup);
58 
59  std::vector<int> BunchCrossings;
60  std::vector<int> Interactions_Xing;
61 
62  const PileupMixingContent* MixInfo = MixingPileup.product();
63 
64  if(MixInfo) { // extract information - way easier than counting vertices
65 
66  const std::vector<int> bunchCrossing = MixInfo->getMix_bunchCrossing();
67  const std::vector<int> interactions = MixInfo->getMix_Ninteractions();
68 
69  for(int ib=0; ib<(int)bunchCrossing.size(); ++ib){
70  // std::cout << " bcr, nint " << bunchCrossing[ib] << " " << interactions[ib] << std::endl;
71  BunchCrossings.push_back(bunchCrossing[ib]);
72  Interactions_Xing.push_back(interactions[ib]);
73  }
74  }
75  else{ //If no Mixing Truth, work with SimVertices (probably should throw an exception, but...)
76 
77  // Collect all the simvertex from the crossing frame
79  event.getByLabel("mix", simHitLabel_, cfSimVertexes);
80 
81  // Create a mix collection from one simvertex collection
82  simVertexes_ = std::auto_ptr<MixCollection<SimVertex> >( new MixCollection<SimVertex>(cfSimVertexes.product()) );
83 
84  int index = 0;
85  // Solution to the problem of not having vertexId
86  // bool FirstL = true;
87  EncodedEventIdToIndex vertexId;
88  EncodedEventId oldEventId;
89  unsigned int oldVertexId = 0;
90  int oldBX = -1000;
91  int oldEvent = 0;
92 
93  std::vector<int> BunchCrossings2;
94  std::list<int> Interactions_Xing2;
95 
96 
97  // Loop for finding repeated vertexId (vertexId problem hack)
98  for (MixCollection<SimVertex>::MixItr iterator = simVertexes_->begin(); iterator != simVertexes_->end(); ++iterator, ++index)
99  {
100  // std::cout << " SimVtx eventid, vertexid " << iterator->eventId().event() << " " << iterator->eventId().bunchCrossing() << std::endl;
101  if (!index || iterator->eventId() != oldEventId)
102  {
103  if(iterator->eventId().bunchCrossing()==0 && iterator->eventId().event()==0){
104  continue;
105  }
106  if(iterator->eventId().bunchCrossing() != oldBX) {
107  BunchCrossings2.push_back(iterator->eventId().bunchCrossing());
108  Interactions_Xing2.push_back(iterator->eventId().event());
109  oldBX = iterator->eventId().bunchCrossing();
110  oldEvent = iterator->eventId().event();
111  }
112  else { Interactions_Xing2.pop_back();
113  Interactions_Xing2.push_back(iterator->eventId().event());
114  oldEvent = iterator->eventId().event();
115  }
116 
117 
118  oldEventId = iterator->eventId();
119  oldVertexId = iterator->vertexId();
120  continue;
121  }
122 
123  }
124 
125  std::vector<int>::iterator viter;
126  std::list<int>::iterator liter = Interactions_Xing2.begin();
127 
128  for(viter = BunchCrossings2.begin(); viter != BunchCrossings2.end(); ++viter, ++liter){
129  //std::cout << " bcr, nint from VTX " << (*viter) << " " << (*liter) << std::endl;
130  BunchCrossings.push_back((*viter));
131  Interactions_Xing.push_back((*liter));
132  }
133  } // end of look at SimVertices
134 
135 
136  //Now, get information on valid particles that look like they could be in the tracking volume
137 
140 
141  event.getByLabel(trackingTruth_, mergedPH);
142  event.getByLabel(trackingTruth_, mergedVH);
143 
144 
145  zpositions.clear();
146  sumpT_lowpT.clear();
147  sumpT_highpT.clear();
148  ntrks_lowpT.clear();
149  ntrks_highpT.clear();
150  event_index_.clear();
151 
152  int lastEvent = 0; // zero is the true MC hard-scatter event
153 
154  int lastBunchCrossing = 0; // 0 is the true bunch crossing, should always come first.
155 
156  TrackingVertexCollection::const_iterator iVtx;
157  TrackingVertexCollection::const_iterator iVtxTest = mergedVH->begin();
158  TrackingParticleCollection::const_iterator iTrackTest = mergedPH->begin();
159 
160  int nminb_vtx = 0;
161  // bool First = true;
162  // bool flag_new = false;
163 
164  std::vector<int>::iterator BXIter;
165  std::vector<int>::iterator InteractionsIter = Interactions_Xing.begin();
166 
167  // loop over the bunch crossings and interactions we have extracted
168 
169  for( BXIter = BunchCrossings.begin(); BXIter != BunchCrossings.end(); ++BXIter, ++InteractionsIter) {
170 
171  //std::cout << "looking for BX: " << (*BXIter) << std::endl;
172 
173  for (iVtx = iVtxTest; iVtx != mergedVH->end(); ++iVtx) {
174 
175  if(iVtx->eventId().bunchCrossing() == (*BXIter) ) { // found first vertex in this bunch crossing
176 
177  if(iVtx->eventId().event() != lastEvent) {
178 
179  //std::cout << "BX,event " << iVtx->eventId().bunchCrossing() << " " << iVtx->eventId().event() << std::endl;
180 
181  float zpos = 0.;
182  zpos = iVtx->position().z();
183  zpositions.push_back(zpos); //save z position of each vertex
184  sumpT_lowpT.push_back(0.);
185  sumpT_highpT.push_back(0.);
186  ntrks_lowpT.push_back(0);
187  ntrks_highpT.push_back(0);
188 
189  lastEvent = iVtx->eventId().event();
190  iVtxTest = --iVtx; // just for security
191 
192  // turns out events aren't sequential... save map of indices
193 
194  event_index_.insert(myindex::value_type(lastEvent,nminb_vtx));
195 
196  ++nminb_vtx;
197 
198  continue;
199  }
200  }
201  }
202 
203  // next loop over tracks to get information
204 
205  for (TrackingParticleCollection::const_iterator iTrack = iTrackTest; iTrack != mergedPH->end(); ++iTrack)
206  {
207  bool FoundTrk = false;
208 
209  float zpos=0.;
210 
211  if(iTrack->eventId().bunchCrossing() == (*BXIter) && iTrack->eventId().event() > 0 )
212  {
213  FoundTrk = true;
214  int correct_index = event_index_[iTrack->eventId().event()];
215 
216  //std::cout << " track index, correct index " << iTrack->eventId().event() << " " << correct_index << std::endl;
217 
218  zpos = zpositions[correct_index];
219  if(iTrack->matchedHit()>0) {
220  if(fabs(iTrack->parentVertex()->position().z()-zpos)<0.1) { //make sure track really comes from this vertex
221  //std::cout << *iTrack << std::endl;
222  float Tpx = iTrack->p4().px();
223  float Tpy = iTrack->p4().py();
224  float TpT = sqrt(Tpx*Tpx + Tpy*Tpy);
225  if( TpT>pTcut_1_ ) {
226  sumpT_lowpT[correct_index]+=TpT;
227  ++ntrks_lowpT[correct_index];
228  }
229  if( TpT>pTcut_2_ ){
230  sumpT_highpT[correct_index]+=TpT;
231  ++ntrks_highpT[correct_index];
232  }
233  }
234  }
235  }
236  else{
237  if(FoundTrk) {
238 
239  iTrackTest = --iTrack; // reset so we can start over next time
240  --iTrackTest; // just to be sure
241  break;
242  }
243 
244  }
245 
246  } // end of track loop
247 
248  // now that we have all of the track information for a given bunch crossing,
249  // make PileupSummary for this one and move on
250 
251  // std::cout << "Making PSI for bunch " << lastBunchCrossing << std::endl;
252 
254  (*InteractionsIter),
255  zpositions,
256  sumpT_lowpT,
257  sumpT_highpT,
258  ntrks_lowpT,
259  ntrks_highpT,
260  (*BXIter)
261  );
262 
263  //std::cout << " " << std::endl;
264  //std::cout << "Adding Bunch Crossing, nint " << (*BXIter) << " " << (*InteractionsIter) << std::endl;
265 
266  // for(int iv = 0; iv<nminb_vtx; ++iv){
267 
268  // std::cout << "Z position " << zpositions[iv] << std::endl;
269  // std::cout << "ntrks_lowpT " << ntrks_lowpT[iv] << std::endl;
270  // std::cout << "sumpT_lowpT " << sumpT_lowpT[iv] << std::endl;
271  // std::cout << "ntrks_highpT " << ntrks_highpT[iv] << std::endl;
272  // std::cout << "sumpT_highpT " << sumpT_highpT[iv] << std::endl;
273  // }
274 
275  PSIVector->push_back(PSI_bunch);
276 
277  lastBunchCrossing = iVtx->eventId().bunchCrossing();
278 
279  event_index_.clear();
280  zpositions.clear();
281  sumpT_lowpT.clear();
282  sumpT_highpT.clear();
283  ntrks_lowpT.clear();
284  ntrks_highpT.clear();
285  nminb_vtx = 0;
286  lastEvent=0;
287 
288 
289  } // end of loop over bunch crossings
290 
291  // put our vector of PileupSummaryInfo objects into the event.
292 
293  event.put(PSIVector);
294 
295 
296 }
const std::vector< int > & getMix_bunchCrossing() const
std::map< EncodedEventId, unsigned int > EncodedEventIdToIndex
Container::value_type value_type
const std::vector< int > & getMix_Ninteractions() const
T sqrt(T t)
Definition: SSEVec.h:28
int bunchCrossing() const
get the detector field from this detid
std::vector< float > sumpT_highpT
std::vector< float > zpositions
std::auto_ptr< MixCollection< SimVertex > > simVertexes_
std::vector< int > ntrks_lowpT
T const * product() const
Definition: Handle.h:74
std::vector< float > sumpT_lowpT
edm::InputTag trackingTruth_
std::vector< int > ntrks_highpT
std::string simHitLabel_

Member Data Documentation

edm::ParameterSet PileupInformation::conf_
private

Definition at line 40 of file PileupInformation.h.

double PileupInformation::distanceCut_
private

Definition at line 53 of file PileupInformation.h.

Referenced by PileupInformation().

myindex PileupInformation::event_index_
private

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().

std::auto_ptr<MixCollection<SimTrack> > PileupInformation::simTracks_
private

Definition at line 63 of file PileupInformation.h.

std::auto_ptr<MixCollection<SimVertex> > PileupInformation::simVertexes_
private

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().

edm::InputTag PileupInformation::trackingTruth_
private

Definition at line 59 of file PileupInformation.h.

Referenced by PileupInformation(), and produce().

double PileupInformation::volumeRadius_
private

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().