HackAnalysis  2
fillPileUp.h
1 #pragma once
2 
3 #include <cassert>
4 #include <cstdlib>
5 #include <cstddef>
6 #include <type_traits>
7 
8 #include <random>
9 #include <cfloat> // for DBL_MAX
10 
11 //#include "time.h"
12 #include <chrono>
13 #include <sstream>
14 #include <string>
15 #include "heputil.h"
16 #include "include/gzstream.h"
17 
18 
19 
20 
21 
22 inline HEP::P4 readvec(std::istringstream &ss)
23 {
24  double x,y,z,t;
25  if(! (ss >> x >> y >> z >> t))
26  {
27  return HEP::P4(0.0,0.0,0.0,0.0);
28  }
29  else
30  {
31  return HEP::P4(x,y,z,t);
32  }
33 
34 
35 }
36 
37 inline void ReadPileupFile(const string & minbiasfile,std::vector<HEP::PileupEvent*> *pileups, int max_events=-1)
38 {
39  GZ::igzstream ss;
40  ss.open("minbias.dat.gz");
41 
42  bool FoundEvent=false;
43  std::string line;
44  //std::stringstream line;
45  int nevents=0;
46  HEP::PileupEvent* new_event;
47  while (std::getline(ss, line)) {
48  //while (std::getline(ss, line,' ')) {
49  // std::string P_type;
50  // line >> P_type;
51 
52  // std::cout << P_type << std::endl;
53  //std::cout << line << std::endl;
54  std::istringstream data(line);
55  std::string Ptype;
56  data >> Ptype;
57  if(Ptype[0] == 'E')
58  {
59 
60  if(nevents > 0)
61  {
62 
63  pileups->push_back(new_event);
64  }
65  else
66  {
67  FoundEvent=true;
68  }
69 
70  if((max_events>0) && (nevents > max_events))
71  {
72  ss.close();
73  return;
74  }
75 
76  new_event = new HEP::PileupEvent;
77  new_event->clear();
78  nevents++;
79 
80  continue;
81  }
82  if(!FoundEvent) continue;
83 
84 
85 
86  int pid,chargeType;
87 
88  if(! (data >> pid)) continue;
89  if(! (data >> chargeType)) continue;
90 
91 
92  HEP::P4 mom=readvec(data);
93  HEP::P4 prod=readvec(data);
94  HEP::P4 dec=readvec(data);
95  HEP::Particle* new_particle = new HEP::Particle(mom,pid);
96  new_particle->set_prod(prod);
97  new_particle->set_3Q(chargeType);
98 
99  if(dec.p2() > 0.0001)
100  {
101  new_particle->set_decay(dec);
102  }
103  if(Ptype.compare("P") == 0)
104  {
105  new_event->add_particle(new_particle);
106 
107  }
108  else if(Ptype.compare("CH") ==0)
109  {
110  new_event->add_charged_hadron(new_particle);
111 
112  }
113  else if(Ptype.compare("NH")==0)
114  {
115  new_event->add_neutral_hadron(mom);
116  delete new_particle;
117  }
118  else
119  {
120  std::cout << "Could not read line starting " << Ptype <<std::endl;
121  delete new_particle;
122  continue;
123  }
124 
125 
126  }
127  ss.close();
128 
129  // add the last event!
130  if(FoundEvent)
131  {
132  pileups->push_back(new_event);
133  }
134 
135 
136 }
137 
A 4-momentum class for vectors.
Definition: Vectors.h:45
double p2() const
Get E^2.
Definition: Vectors.h:441
Definition: Particle.h:24
Definition: heputil.h:98