CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PileupInformation.cc
Go to the documentation of this file.
1 // File: PileupInformation.cc
2 // Description: adds pileup information object to event
3 // Author: Mike Hildreth
4 //
5 // Adds a vector of PileupSummaryInfo objects to the event.
6 // One for each bunch crossing.
7 //
8 //--------------------------------------------
9 
13 
17 
19 
20 
22 {
23  // Initialize global parameters
24 
25  pTcut_1_ = 0.1;
26  pTcut_2_ = 0.5; // defaults
27  distanceCut_ = config.getParameter<double>("vertexDistanceCut");
28  volumeRadius_ = config.getParameter<double>("volumeRadius");
29  volumeZ_ = config.getParameter<double>("volumeZ");
30  pTcut_1_ = config.getParameter<double>("pTcut_1");
31  pTcut_2_ = config.getParameter<double>("pTcut_2");
32 
33  PileupInfoLabel_ = consumes<PileupMixingContent>(config.getParameter<edm::InputTag>("PileupMixingLabel"));
34 
35  LookAtTrackingTruth_ = config.getUntrackedParameter<bool>("doTrackTruth");
36 
37  trackingTruthT_ = mayConsume<TrackingParticleCollection>(config.getParameter<edm::InputTag>("TrackingParticlesLabel"));
38  trackingTruthV_ = mayConsume<TrackingVertexCollection>(config.getParameter<edm::InputTag>("TrackingParticlesLabel"));
39 
40  MessageCategory_ = "PileupInformation";
41 
42  edm::LogInfo (MessageCategory_) << "Setting up PileupInformation";
43  edm::LogInfo (MessageCategory_) << "Vertex distance cut set to " << distanceCut_ << " mm";
44  edm::LogInfo (MessageCategory_) << "Volume radius set to " << volumeRadius_ << " mm";
45  edm::LogInfo (MessageCategory_) << "Volume Z set to " << volumeZ_ << " mm";
46  edm::LogInfo (MessageCategory_) << "Lower pT Threshold set to " << pTcut_1_ << " GeV";
47  edm::LogInfo (MessageCategory_) << "Upper pT Threshold set to " << pTcut_2_ << " GeV";
48 
49 
50  produces< std::vector<PileupSummaryInfo> >();
51  //produces<PileupSummaryInfo>();
52 }
53 
54 
56 {
57 
58  std::auto_ptr<std::vector<PileupSummaryInfo> > PSIVector(new std::vector<PileupSummaryInfo>);
59 
60  edm::Handle< PileupMixingContent > MixingPileup; // Get True pileup information from MixingModule
61  event.getByToken(PileupInfoLabel_, MixingPileup);
62 
63  std::vector<int> BunchCrossings;
64  std::vector<int> Interactions_Xing;
65  std::vector<float> TrueInteractions_Xing;
66 
67  const PileupMixingContent* MixInfo = MixingPileup.product();
68 
69  if(MixInfo) { // extract information - way easier than counting vertices
70 
71  const std::vector<int> bunchCrossing = MixInfo->getMix_bunchCrossing();
72  const std::vector<int> interactions = MixInfo->getMix_Ninteractions();
73  const std::vector<float> TrueInteractions = MixInfo->getMix_TrueInteractions();
74 
75 
76  for(int ib=0; ib<(int)bunchCrossing.size(); ++ib){
77  // std::cout << " bcr, nint " << bunchCrossing[ib] << " " << interactions[ib] << std::endl;
78  BunchCrossings.push_back(bunchCrossing[ib]);
79  Interactions_Xing.push_back(interactions[ib]);
80  TrueInteractions_Xing.push_back(TrueInteractions[ib]);
81  }
82  }
83  else{ // have to throw an exception..
84 
85  throw cms::Exception("PileupInformation") << " PileupMixingContent is missing from the event.\n"
86  "There must be some breakdown in the Simulation Chain.\n"
87  "You must run the MixingModule before calling this routine.";
88  // end of cut
147  }
148 
149  //Now, get information on valid particles that look like they could be in the tracking volume
150 
151 
152  zpositions.clear();
153  sumpT_lowpT.clear();
154  sumpT_highpT.clear();
155  ntrks_lowpT.clear();
156  ntrks_highpT.clear();
157  event_index_.clear();
158 
159  int lastEvent = 0; // zero is the true MC hard-scatter event
160 
161  // int lastBunchCrossing = 0; // 0 is the true bunch crossing, should always come first.
162 
163  bool HaveTrackingParticles = false;
164 
167 
168  TrackingVertexCollection::const_iterator iVtx;
169  TrackingVertexCollection::const_iterator iVtxTest;
170  TrackingParticleCollection::const_iterator iTrackTest;
171 
172  if( LookAtTrackingTruth_ ){
173 
174  if(event.getByToken(trackingTruthT_, mergedPH) && event.getByToken(trackingTruthV_, mergedVH)) {
175 
176  HaveTrackingParticles = true;
177 
178  iVtxTest = mergedVH->begin();
179  iTrackTest = mergedPH->begin();
180  }
181 
182  }
183 
184  int nminb_vtx = 0;
185  // bool First = true;
186  // bool flag_new = false;
187 
188  std::vector<int>::iterator BXIter;
189  std::vector<int>::iterator InteractionsIter = Interactions_Xing.begin();
190  std::vector<float>::iterator TInteractionsIter = TrueInteractions_Xing.begin();
191 
192  // loop over the bunch crossings and interactions we have extracted
193 
194  for( BXIter = BunchCrossings.begin(); BXIter != BunchCrossings.end(); ++BXIter, ++InteractionsIter, ++TInteractionsIter) {
195 
196  //std::cout << "looking for BX: " << (*BXIter) << std::endl;
197 
198  if(HaveTrackingParticles) { // leave open the option of not producing TrackingParticles and just keeping # interactions
199 
200  for (iVtx = iVtxTest; iVtx != mergedVH->end(); ++iVtx) {
201 
202  if(iVtx->eventId().bunchCrossing() == (*BXIter) ) { // found first vertex in this bunch crossing
203 
204  if(iVtx->eventId().event() != lastEvent) {
205 
206  //std::cout << "BX,event " << iVtx->eventId().bunchCrossing() << " " << iVtx->eventId().event() << std::endl;
207 
208  float zpos = 0.;
209  zpos = iVtx->position().z();
210  zpositions.push_back(zpos); //save z position of each vertex
211  sumpT_lowpT.push_back(0.);
212  sumpT_highpT.push_back(0.);
213  ntrks_lowpT.push_back(0);
214  ntrks_highpT.push_back(0);
215 
216  lastEvent = iVtx->eventId().event();
217  iVtxTest = --iVtx; // just for security
218 
219  // turns out events aren't sequential... save map of indices
220 
221  event_index_.insert(myindex::value_type(lastEvent,nminb_vtx));
222 
223  ++nminb_vtx;
224 
225  continue;
226  }
227  }
228  }
229 
230  // next loop over tracks to get information
231 
232  for (TrackingParticleCollection::const_iterator iTrack = iTrackTest; iTrack != mergedPH->end(); ++iTrack)
233  {
234  bool FoundTrk = false;
235 
236  float zpos=0.;
237 
238  if(iTrack->eventId().bunchCrossing() == (*BXIter) && iTrack->eventId().event() > 0 )
239  {
240  FoundTrk = true;
241  int correct_index = event_index_[iTrack->eventId().event()];
242 
243  //std::cout << " track index, correct index " << iTrack->eventId().event() << " " << correct_index << std::endl;
244 
245  zpos = zpositions[correct_index];
246  if(iTrack->matchedHit()>0) {
247  if(fabs(iTrack->parentVertex()->position().z()-zpos)<0.1) { //make sure track really comes from this vertex
248  //std::cout << *iTrack << std::endl;
249  float Tpx = iTrack->p4().px();
250  float Tpy = iTrack->p4().py();
251  float TpT = sqrt(Tpx*Tpx + Tpy*Tpy);
252  if( TpT>pTcut_1_ ) {
253  sumpT_lowpT[correct_index]+=TpT;
254  ++ntrks_lowpT[correct_index];
255  }
256  if( TpT>pTcut_2_ ){
257  sumpT_highpT[correct_index]+=TpT;
258  ++ntrks_highpT[correct_index];
259  }
260  }
261  }
262  }
263  else{
264  if(FoundTrk) {
265 
266  iTrackTest = --iTrack; // reset so we can start over next time
267  --iTrackTest; // just to be sure
268  break;
269  }
270 
271  }
272 
273  } // end of track loop
274 
275  } // end of check that we have TrackingParticles to begin with...
276 
277 
278  // now that we have all of the track information for a given bunch crossing,
279  // make PileupSummary for this one and move on
280 
281  // std::cout << "Making PSI for bunch " << lastBunchCrossing << std::endl;
282 
283  if(!HaveTrackingParticles) { // stick in one value so we don't have empty vectors
284 
285  zpositions.push_back(-999.);
286  sumpT_lowpT.push_back(0.);
287  sumpT_highpT.push_back(0.);
288  ntrks_lowpT.push_back(0);
289  ntrks_highpT.push_back(0);
290 
291  }
292 
294  (*InteractionsIter),
295  zpositions,
296  sumpT_lowpT,
297  sumpT_highpT,
298  ntrks_lowpT,
299  ntrks_highpT,
300  (*BXIter),
301  (*TInteractionsIter)
302  );
303 
304  //std::cout << " " << std::endl;
305  //std::cout << "Adding Bunch Crossing, nint " << (*BXIter) << " " << (*InteractionsIter) << std::endl;
306 
307  //for(int iv = 0; iv<(*InteractionsIter); ++iv){
308 
309  // std::cout << "Z position " << zpositions[iv] << std::endl;
310  // std::cout << "ntrks_lowpT " << ntrks_lowpT[iv] << std::endl;
311  // std::cout << "sumpT_lowpT " << sumpT_lowpT[iv] << std::endl;
312  // std::cout << "ntrks_highpT " << ntrks_highpT[iv] << std::endl;
313  // std::cout << "sumpT_highpT " << sumpT_highpT[iv] << std::endl;
314  //}
315 
316  PSIVector->push_back(PSI_bunch);
317 
318  // if(HaveTrackingParticles) lastBunchCrossing = iVtx->eventId().bunchCrossing();
319 
320  event_index_.clear();
321  zpositions.clear();
322  sumpT_lowpT.clear();
323  sumpT_highpT.clear();
324  ntrks_lowpT.clear();
325  ntrks_highpT.clear();
326  nminb_vtx = 0;
327  lastEvent=0;
328 
329 
330  } // end of loop over bunch crossings
331 
332  // put our vector of PileupSummaryInfo objects into the event.
333 
334  event.put(PSIVector);
335 
336 
337 }
338 
339 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< PileupMixingContent > PileupInfoLabel_
int ib
Definition: cuy.py:660
std::string MessageCategory_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
const std::vector< float > & getMix_TrueInteractions() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::vector< int > & getMix_bunchCrossing() const
PileupInformation(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &)
const std::vector< int > & getMix_Ninteractions() const
T sqrt(T t)
Definition: SSEVec.h:48
std::vector< float > sumpT_highpT
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Container::value_type value_type
std::vector< float > zpositions
std::vector< int > ntrks_lowpT
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< TrackingParticleCollection > trackingTruthT_
std::vector< float > sumpT_lowpT
edm::EDGetTokenT< TrackingVertexCollection > trackingTruthV_
std::vector< int > ntrks_highpT
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")