CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicGenFilterHelix.cc
Go to the documentation of this file.
1 //
3 // Original Author: Gero FLUCKE
4 // Created: Mon Mar 5 16:32:01 CET 2007
5 
7 
8 // user include files
11 
14 
16 
19 
23 
24 
28 
29 #include <TMath.h>
30 #include <TH1.h> // include checker: don't touch!
31 #include <TH2.h> // include checker: don't touch!
32 
33 #include <utility> // for std::pair
34 #include <string>
35 
36 
37 //
38 // constructors and destructor
39 //
40 
43  : theIds(cfg.getParameter<std::vector<int> >("pdgIds")),
44  theCharges(cfg.getParameter<std::vector<int> >("charges")),
45  thePropagatorName(cfg.getParameter<std::string>("propagator")),
46  theMinP2(cfg.getParameter<double>("minP")*cfg.getParameter<double>("minP")),
47  theMinPt2(cfg.getParameter<double>("minPt")*cfg.getParameter<double>("minPt")),
48  theDoMonitor(cfg.getUntrackedParameter<bool>("doMonitor"))
49 {
50  theSrcToken = consumes<edm::HepMCProduct>(cfg.getParameter<edm::InputTag>("src"));
51 
52  if (theIds.size() != theCharges.size()) {
53  throw cms::Exception("BadConfig") << "CosmicGenFilterHelix: "
54  << "'pdgIds' and 'charges' need same length.";
55  }
56  Surface::Scalar radius = cfg.getParameter<double>("radius");
57  Surface::Scalar maxZ = cfg.getParameter<double>("maxZ");
58  Surface::Scalar minZ = cfg.getParameter<double>("minZ");
59 
60  if (maxZ < minZ) {
61  throw cms::Exception("BadConfig") << "CosmicGenFilterHelix: maxZ (" << maxZ
62  << ") smaller than minZ (" << minZ << ").";
63  }
64 
65  const Surface::RotationType dummyRot;
66  theTargetCylinder = Cylinder::build(Surface::PositionType(0.,0.,0.), dummyRot, radius);
67  theTargetPlaneMin = Plane::build(Surface::PositionType(0.,0.,minZ), dummyRot);
68  theTargetPlaneMax = Plane::build(Surface::PositionType(0.,0.,maxZ), dummyRot);
69 }
70 
73 {
74 }
75 
76 
77 //
78 // member functions
79 //
80 
83 {
85  iEvent.getByToken(theSrcToken, hepMCEvt);
86  const HepMC::GenEvent *mCEvt = hepMCEvt->GetEvent();
87  const MagneticField *bField = this->getMagneticField(iSetup); // should be fast (?)
88  const Propagator *propagator = this->getPropagator(iSetup);
89 
90  ++theNumTotal;
91  bool result = false;
92  for (HepMC::GenEvent::particle_const_iterator iPart = mCEvt->particles_begin(),
93  endPart = mCEvt->particles_end(); iPart != endPart; ++iPart) {
94  int charge = 0; // there is no method providing charge in GenParticle :-(
95  if ((*iPart)->status() != 1) continue; // look only at stable particles
96  if (!this->charge((*iPart)->pdg_id(), charge)) continue;
97 
98  // Get the position and momentum
99  const HepMC::ThreeVector hepVertex((*iPart)->production_vertex()->point3d());
100  const GlobalPoint vert(hepVertex.x()/10., hepVertex.y()/10., hepVertex.z()/10.); // to cm
101  const HepMC::FourVector hepMomentum((*iPart)->momentum());
102  const GlobalVector mom(hepMomentum.x(), hepMomentum.y(), hepMomentum.z());
103 
104  if (theDoMonitor) this->monitorStart(vert, mom, charge, theHistsBefore);
105 
106  if (this->propagateToCutCylinder(vert, mom, charge, bField, propagator)) {
107  result = true;
108  }
109  }
110 
111  if (result) ++theNumPass;
112  return result;
113 }
114 
115 //_________________________________________________________________________________________________
117  const GlobalVector &momStart,
118  int charge, const MagneticField *field,
119  const Propagator *propagator)
120 {
121  typedef std::pair<TrajectoryStateOnSurface, double> TsosPath;
122 
123  const FreeTrajectoryState fts(GlobalTrajectoryParameters(vertStart, momStart, charge, field));
124 
125  bool result = true;
126  TsosPath aTsosPath(propagator->propagateWithPath(fts, *theTargetCylinder));
127  if (!aTsosPath.first.isValid()) {
128  result = false;
129  } else if (aTsosPath.first.globalPosition().z() < theTargetPlaneMin->position().z()) {
130  // If on cylinder, but outside minimum z, try minimum z-plane:
131  // (Would it be possible to miss radius on plane, but reach cylinder afterwards in z-range?
132  // No, at least not in B-field parallel to z-axis which is cylinder axis.)
133  aTsosPath = propagator->propagateWithPath(fts, *theTargetPlaneMin);
134  if (!aTsosPath.first.isValid()
135  || aTsosPath.first.globalPosition().perp() > theTargetCylinder->radius()) {
136  result = false;
137  }
138  } else if (aTsosPath.first.globalPosition().z() > theTargetPlaneMax->position().z()) {
139  // Analog for outside maximum z:
140  aTsosPath = propagator->propagateWithPath(fts, *theTargetPlaneMax);
141  if (!aTsosPath.first.isValid()
142  || aTsosPath.first.globalPosition().perp() > theTargetCylinder->radius()) {
143  result = false;
144  }
145  }
146 
147  if (result) {
148  const GlobalVector momEnd(aTsosPath.first.globalMomentum());
149  if (momEnd.perp2() < theMinPt2 || momEnd.mag2() < theMinP2) {
150  result = false;
151  } else if (theDoMonitor) {
152  const GlobalPoint vertEnd(aTsosPath.first.globalPosition());
153  this->monitorStart(vertStart, momStart, charge, theHistsAfter);
154  this->monitorEnd(vertEnd, momEnd, vertStart, momStart, aTsosPath.second, theHistsAfter);
155  }
156  }
157 
158  return result;
159 }
160 
161 
162 // ------------ method called once each job just before starting event loop ------------
164 {
165  if (theDoMonitor) {
166  this->createHistsStart("start", theHistsBefore);
167  this->createHistsStart("startAfter", theHistsAfter);
168  // must be after the line above: hist indices are static in monitorStart(...)
169  this->createHistsEnd("end", theHistsAfter);
170  }
171 
172  theNumTotal = theNumPass = 0;
173 }
174 
176 void CosmicGenFilterHelix::createHistsStart(const char *dirName, TObjArray &hists)
177 {
179  TFileDirectory fd(fs->mkdir(dirName, dirName));
180 
181  hists.Add(fd.make<TH1F>("momentumP", "|p(#mu^{+})| (start);|p| [GeV]",100, 0., 1000.));
182  hists.Add(fd.make<TH1F>("momentumM", "|p(#mu^{-})| (start);|p| [GeV]",100, 0., 1000.));
183  hists.Add(fd.make<TH1F>("momentum2", "|p(#mu)| (start);|p| [GeV]",100, 0., 25.));
184  const int kNumBins = 50;
185  double pBinsLog[kNumBins+1] = {0.}; // fully initialised with 0.
186  this->equidistLogBins(pBinsLog, kNumBins, 1., 4000.);
187  hists.Add(fd.make<TH1F>("momentumLog", "|p(#mu)| (start);|p| [GeV]", kNumBins, pBinsLog));
188  hists.Add(fd.make<TH1F>("phi", "start p_{#phi(#mu)};#phi", 100, -TMath::Pi(), TMath::Pi()));
189  hists.Add(fd.make<TH1F>("cosPhi", "cos(p_{#phi(#mu)}) (start);cos(#phi)", 100, -1., 1.));
190  hists.Add(fd.make<TH1F>("phiXz", "start p_{#phi_{xz}(#mu)};#phi_{xz}",
191  100, -TMath::Pi(), TMath::Pi()));
192  hists.Add(fd.make<TH1F>("theta", "#theta(#mu) (start);#theta", 100, 0., TMath::Pi()));
193  hists.Add(fd.make<TH1F>("thetaY", "#theta_{y}(#mu) (start);#theta_{y}", 100,0.,TMath::Pi()/2.));
194 
195  hists.Add(fd.make<TH2F>("momVsPhi", "|p(#mu)| vs #phi (start);#phi;|p| [GeV]",
196  50, -TMath::Pi(), TMath::Pi(), 50, 1.5, 1000.));
197  hists.Add(fd.make<TH2F>("momVsTheta", "|p(#mu)| vs #theta (start);#theta;|p| [GeV]",
198  50, 0., TMath::Pi(), 50, 1.5, 1000.));
199  hists.Add(fd.make<TH2F>("momVsThetaY", "|p(#mu)| vs #theta_{y} (start);#theta_{y};|p| [GeV]",
200  50, 0., TMath::Pi()/2., 50, 1.5, 1000.));
201  hists.Add(fd.make<TH2F>("momVsZ", "|p(#mu)| vs z (start);z [cm];|p| [GeV]",
202  50, -1600., 1600., 50, 1.5, 1000.));
203  hists.Add(fd.make<TH2F>("thetaVsZ", "#theta vs z (start);z [cm];#theta",
204  50, -1600., 1600., 50, 0., TMath::Pi()));
205  hists.Add(fd.make<TH2F>("thetaYvsZ", "#theta_{y} vs z (start);z [cm];#theta",
206  50, -1600., 1600., 50, 0., TMath::PiOver2()));
207  hists.Add(fd.make<TH2F>("yVsThetaY", "#theta_{y}(#mu) vs y (start);#theta_{y};y [cm]",
208  50, 0., TMath::Pi()/2., 50, -1000., 1000.));
209  hists.Add(fd.make<TH2F>("yVsThetaYnoR", "#theta_{y}(#mu) vs y (start, barrel);#theta_{y};y [cm]",
210  50, 0., TMath::Pi()/2., 50, -1000., 1000.));
211 
212  hists.Add(fd.make<TH1F>("radius", "start radius;r [cm]", 100, 0., 1000.));
213  hists.Add(fd.make<TH1F>("z", "start z;z [cm]", 100, -1600., 1600.));
214  hists.Add(fd.make<TH2F>("xyPlane", "start xy;x [cm];y [cm]", 50, -1000., 1000.,
215  50, -1000., 1000.));
216  hists.Add(fd.make<TH2F>("rzPlane",
217  "start rz (y < 0 #Rightarrow r_{#pm} = -r);z [cm];r_{#pm} [cm]",
218  50, -1600., 1600., 50, -1000., 1000.));
219 }
220 
222 void CosmicGenFilterHelix::createHistsEnd(const char *dirName, TObjArray &hists)
223 {
225  TFileDirectory fd(fs->mkdir(dirName, dirName));
226 
227  const int kNumBins = 50;
228  double pBinsLog[kNumBins+1] = {0.}; // fully initialised with 0.
229  this->equidistLogBins(pBinsLog, kNumBins, 1., 4000.);
230 
231  // take care: hist names must differ from those in createHistsStart!
232  hists.Add(fd.make<TH1F>("pathEnd", "path until cylinder;s [cm]", 100, 0., 2000.));
233  hists.Add(fd.make<TH1F>("momEnd", "|p_{end}|;p [GeV]", 100, 0., 1000.));
234  hists.Add(fd.make<TH1F>("momEndLog", "|p_{end}|;p [GeV]", kNumBins, pBinsLog));
235  hists.Add(fd.make<TH1F>("ptEnd", "p_{t} (end);p_{t} [GeV]", 100, 0., 750.));
236  hists.Add(fd.make<TH1F>("ptEndLog", "p_{t} (end);p_{t} [GeV]", kNumBins, pBinsLog));
237  hists.Add(fd.make<TH1F>("phiXzEnd", "#phi_{xz} (end);#phi_{xz}", 100,-TMath::Pi(),TMath::Pi()));
238  hists.Add(fd.make<TH1F>("thetaYEnd","#theta_{y} (end);#theta_{y}", 100, 0., TMath::Pi()));
239 
240  hists.Add(fd.make<TH1F>("momStartEnd", "|p_{start}|-|p_{end}|;#Deltap [GeV]",100,0.,15.));
241  hists.Add(fd.make<TH1F>("momStartEndRel", "(p_{start}-p_{end})/p_{start};#Deltap_{rel}",
242  100,.0,1.));
243  hists.Add(fd.make<TH1F>("phiXzStartEnd", "#phi_{xz,start}-#phi_{xz,end};#Delta#phi_{xz}",
244  100,-1.,1.));
245  hists.Add(fd.make<TH1F>("thetaYStartEnd","#theta_{y,start}-#theta_{y,end};#Delta#theta_{y}",
246  100,-1.,1.));
247 
248  hists.Add(fd.make<TH2F>("phiXzStartVsEnd",
249  "#phi_{xz} start vs end;#phi_{xz}^{end};#phi_{xz}^{start}",
250  50, -TMath::Pi(), TMath::Pi(), 50, -TMath::Pi(), TMath::Pi()));
251  hists.Add(fd.make<TH2F>("thetaYStartVsEnd",
252  "#theta_{y} start vs end;#theta_{y}^{end};#theta_{y}^{start}",
253  50, 0., TMath::Pi(), 50, 0., TMath::Pi()/2.));
254 
255  hists.Add(fd.make<TH2F>("momStartEndRelVsZ",
256  "(p_{start}-p_{end})/p_{start} vs z_{start};z [cm];#Deltap_{rel}",
257  50, -1600., 1600., 50,.0,.8));
258  hists.Add(fd.make<TH2F>("phiXzStartEndVsZ",
259  "#phi_{xz,start}-#phi_{xz,end} vs z_{start};z [cm];#Delta#phi_{xz}",
260  50, -1600., 1600., 50,-1., 1.));
261  hists.Add(fd.make<TH2F>("thetaYStartEndVsZ",
262  "#theta_{y,start}-#theta_{y,end} vs z_{start};z [cm];#Delta#theta_{y}",
263  50, -1600., 1600., 50,-.5,.5));
264  hists.Add(fd.make<TH2F>("momStartEndRelVsP",
265  "(p_{start}-p_{end})/p_{start} vs p_{start};p [GeV];#Deltap_{rel}",
266  kNumBins, pBinsLog, 50, .0, .8));
267  hists.Add(fd.make<TH2F>("phiXzStartEndVsP",
268  "#phi_{xz,start}-#phi_{xz,end} vs |p|_{start};p [GeV];#Delta#phi_{xz}",
269  kNumBins, pBinsLog, 100,-1.5, 1.5));
270  hists.Add(fd.make<TH2F>("thetaYStartEndVsP",
271  "#theta_{y,start}-#theta_{y,end} vs |p|_{start};p [GeV];#Delta#theta_{y}",
272  kNumBins, pBinsLog, 100,-1.,1.));
273 
274  const double maxR = theTargetCylinder->radius() * 1.1;
275  hists.Add(fd.make<TH1F>("radiusEnd", "end radius;r [cm]", 100, 0., maxR));
276  double minZ = theTargetPlaneMin->position().z();
277  minZ -= TMath::Abs(minZ) * 0.1;
278  double maxZ = theTargetPlaneMax->position().z();
279  maxZ += TMath::Abs(maxZ) * 0.1;
280  hists.Add(fd.make<TH1F>("zEnd", "end z;z [cm]", 100, minZ, maxZ));
281  hists.Add(fd.make<TH1F>("zDiff", "z_{start}-z_{end};#Deltaz [cm]", 100, -1000., 1000.));
282  hists.Add(fd.make<TH2F>("xyPlaneEnd", "end xy;x [cm];y [cm]", 100, -maxR, maxR, 100,-maxR,maxR));
283 
284  hists.Add(fd.make<TH2F>("rzPlaneEnd", "end rz (y<0 #Rightarrow r_{#pm}=-r);z [cm];r_{#pm} [cm]",
285  50, minZ, maxZ, 50, -maxR, maxR));
286  hists.Add(fd.make<TH2F>("thetaVsZend", "#theta vs z (end);z [cm];#theta",
287  50, minZ, maxZ, 50, 0., TMath::Pi()));
288 }
289 
290 // ------------ method called once each job just after ending the event loop ------------
292 {
293  const char *border = "////////////////////////////////////////////////////////";
294  const char *line = "\n// ";
295  edm::LogInfo("Filter") << "@SUB=CosmicGenFilterHelix::endJob"
296  << border << line
297  << theNumPass << " events out of " << theNumTotal
298  << ", i.e. " << theNumPass*100./theNumTotal << "%, "
299  << "reached target cylinder,"
300  << line << "defined by r < "
301  << theTargetCylinder->radius() << " cm and "
302  << theTargetPlaneMin->position().z() << " < z < "
303  << theTargetPlaneMax->position().z() << " cm."
304  << line << "Minimal required (transverse) momentum was "
305  << TMath::Sqrt(theMinP2) << " (" << TMath::Sqrt(theMinPt2) << ") GeV."
306  << "\n" << border;
307 }
308 
310 bool CosmicGenFilterHelix::charge(int id, int &charge) const
311 {
312  std::vector<int>::const_iterator iC = theCharges.begin();
313  for (std::vector<int>::const_iterator i = theIds.begin(), end = theIds.end(); i != end;
314  ++i,++iC) {
315  if (*i == id) {
316  charge = *iC;
317  return true;
318  }
319  }
320 
321  return false;
322 }
323 
324 //_________________________________________________________________________________________________
326 {
328  setup.get<IdealMagneticFieldRecord>().get(fieldHandle);
329 
330  return fieldHandle.product();
331 }
332 
333 //_________________________________________________________________________________________________
335 {
336  edm::ESHandle<Propagator> propHandle;
337  setup.get<TrackingComponentsRecord>().get(thePropagatorName, propHandle);
338 
339  const Propagator *prop = propHandle.product();
340  if (!dynamic_cast<const SteppingHelixPropagator*>(prop)) {
341  edm::LogWarning("BadConfig") << "@SUB=CosmicGenFilterHelix::getPropagator"
342  << "Not a SteppingHelixPropagator!";
343 
344  }
345  return prop;
346 }
347 
348 //_________________________________________________________________________________________________
350  int charge, TObjArray &hists)
351 {
352  const double scalarMom = mom.mag();
353  const double phi = mom.phi();
354  const double phiXz = TMath::ATan2(mom.z(), mom.x());
355  const double theta = mom.theta();
356  const double thetaY = TMath::ATan2(TMath::Sqrt(mom.x()*mom.x()+mom.z()*mom.z()), -mom.y());
357 
358  const double z = vert.z();
359  const double r = vert.perp();
360 
361  const static int iMomP = hists.IndexOf(hists.FindObject("momentumP"));
362  const static int iMomM = hists.IndexOf(hists.FindObject("momentumM"));
363  if (charge > 0) static_cast<TH1*>(hists[iMomP])->Fill(scalarMom);
364  else static_cast<TH1*>(hists[iMomM])->Fill(scalarMom);
365  const static int iMom2 = hists.IndexOf(hists.FindObject("momentum2"));
366  static_cast<TH1*>(hists[iMom2])->Fill(scalarMom);
367  const static int iMomLog = hists.IndexOf(hists.FindObject("momentumLog"));
368  static_cast<TH1*>(hists[iMomLog])->Fill(scalarMom);
369  const static int iPhi = hists.IndexOf(hists.FindObject("phi"));
370  static_cast<TH1*>(hists[iPhi])->Fill(phi);
371  const static int iCosPhi = hists.IndexOf(hists.FindObject("cosPhi"));
372  static_cast<TH1*>(hists[iCosPhi])->Fill(TMath::Cos(phi));
373  const static int iPhiXz = hists.IndexOf(hists.FindObject("phiXz"));
374  static_cast<TH1*>(hists[iPhiXz])->Fill(phiXz);
375  const static int iTheta = hists.IndexOf(hists.FindObject("theta"));
376  static_cast<TH1*>(hists[iTheta])->Fill(theta);
377  const static int iThetaY = hists.IndexOf(hists.FindObject("thetaY"));
378  static_cast<TH1*>(hists[iThetaY])->Fill(thetaY);
379 
380  const static int iMomVsTheta = hists.IndexOf(hists.FindObject("momVsTheta"));
381  static_cast<TH2*>(hists[iMomVsTheta])->Fill(theta, scalarMom);
382  const static int iMomVsThetaY = hists.IndexOf(hists.FindObject("momVsThetaY"));
383  static_cast<TH2*>(hists[iMomVsThetaY])->Fill(thetaY, scalarMom);
384  const static int iMomVsPhi = hists.IndexOf(hists.FindObject("momVsPhi"));
385  static_cast<TH2*>(hists[iMomVsPhi])->Fill(phi, scalarMom);
386  const static int iMomVsZ = hists.IndexOf(hists.FindObject("momVsZ"));
387  static_cast<TH2*>(hists[iMomVsZ])->Fill(z, scalarMom);
388  const static int iThetaVsZ = hists.IndexOf(hists.FindObject("thetaVsZ"));
389  static_cast<TH2*>(hists[iThetaVsZ])->Fill(z, theta);
390  const static int iThetaYvsZ = hists.IndexOf(hists.FindObject("thetaYvsZ"));
391  static_cast<TH2*>(hists[iThetaYvsZ])->Fill(z, thetaY);
392  const static int iYvsThetaY = hists.IndexOf(hists.FindObject("yVsThetaY"));
393  static_cast<TH2*>(hists[iYvsThetaY])->Fill(thetaY, vert.y());
394  const static int iYvsThetaYnoR = hists.IndexOf(hists.FindObject("yVsThetaYnoR"));
395  if (z > -1400. && z < 1400.) {
396  static_cast<TH2*>(hists[iYvsThetaYnoR])->Fill(thetaY, vert.y());
397  }
398 
399  const static int iRadius = hists.IndexOf(hists.FindObject("radius"));
400  static_cast<TH1*>(hists[iRadius])->Fill(r);
401  const static int iZ = hists.IndexOf(hists.FindObject("z"));
402  static_cast<TH1*>(hists[iZ])->Fill(z);
403  const static int iXy = hists.IndexOf(hists.FindObject("xyPlane"));
404  static_cast<TH1*>(hists[iXy])->Fill(vert.x(), vert.y());
405  const static int iRz = hists.IndexOf(hists.FindObject("rzPlane"));
406  static_cast<TH1*>(hists[iRz])->Fill(z, (vert.y() > 0 ? r : -r));
407 }
408 
409 //_________________________________________________________________________________________________
410 void CosmicGenFilterHelix::monitorEnd(const GlobalPoint &endVert, const GlobalVector &endMom,
411  const GlobalPoint &vert, const GlobalVector &mom,
412  double path, TObjArray &hists)
413 {
414  const double scalarMomStart = mom.mag();
415  const double phiXzStart = TMath::ATan2(mom.z(), mom.x());
416  const double thetaYStart = TMath::ATan2(TMath::Sqrt(mom.x()*mom.x()+mom.z()*mom.z()), -mom.y());
417  const double scalarMomEnd = endMom.mag();
418  const double ptEnd = endMom.perp();
419  const double phiXzEnd = TMath::ATan2(endMom.z(), endMom.x());
420  const double thetaYEnd = TMath::ATan2(TMath::Sqrt(endMom.x()*endMom.x()+endMom.z()*endMom.z()),
421  -endMom.y());
422  const double thetaEnd = endMom.theta();
423 
424  const double diffMomRel = (scalarMomStart-scalarMomEnd)/scalarMomStart;
425 
426  const double zEnd = endVert.z();
427  const double rEnd = endVert.perp();
428  const double diffZ = zEnd - vert.z();
429 
430  const static int iPathEnd = hists.IndexOf(hists.FindObject("pathEnd"));
431  static_cast<TH1*>(hists[iPathEnd])->Fill(path);
432  const static int iMomEnd = hists.IndexOf(hists.FindObject("momEnd"));
433  static_cast<TH1*>(hists[iMomEnd])->Fill(scalarMomEnd);
434  const static int iMomEndLog = hists.IndexOf(hists.FindObject("momEndLog"));
435  static_cast<TH1*>(hists[iMomEndLog])->Fill(scalarMomEnd);
436  const static int iPtEnd = hists.IndexOf(hists.FindObject("ptEnd"));
437  static_cast<TH1*>(hists[iPtEnd])->Fill(ptEnd);
438  const static int iPtEndLog = hists.IndexOf(hists.FindObject("ptEndLog"));
439  static_cast<TH1*>(hists[iPtEndLog])->Fill(ptEnd);
440  const static int iPhiXzEnd = hists.IndexOf(hists.FindObject("phiXzEnd"));
441  static_cast<TH1*>(hists[iPhiXzEnd])->Fill(phiXzEnd);
442  const static int iThetaYEnd = hists.IndexOf(hists.FindObject("thetaYEnd"));
443  static_cast<TH1*>(hists[iThetaYEnd])->Fill(thetaYEnd);
444 
445  const static int iMomStartEnd = hists.IndexOf(hists.FindObject("momStartEnd"));
446  static_cast<TH1*>(hists[iMomStartEnd])->Fill(scalarMomStart-scalarMomEnd);
447  const static int iMomStartEndRel = hists.IndexOf(hists.FindObject("momStartEndRel"));
448  static_cast<TH1*>(hists[iMomStartEndRel])->Fill(diffMomRel);
449  const static int iPhiStartEnd = hists.IndexOf(hists.FindObject("phiXzStartEnd"));
450  static_cast<TH1*>(hists[iPhiStartEnd])->Fill(phiXzStart-phiXzEnd);
451  const static int iThetaStartEnd = hists.IndexOf(hists.FindObject("thetaYStartEnd"));
452  static_cast<TH1*>(hists[iThetaStartEnd])->Fill(thetaYStart-thetaYEnd);
453 
454  const static int iPhiStartVsEnd = hists.IndexOf(hists.FindObject("phiXzStartVsEnd"));
455  static_cast<TH2*>(hists[iPhiStartVsEnd])->Fill(phiXzEnd, phiXzStart);
456  const static int iThetaStartVsEnd = hists.IndexOf(hists.FindObject("thetaYStartVsEnd"));
457  static_cast<TH2*>(hists[iThetaStartVsEnd])->Fill(thetaYEnd, thetaYStart);
458 
459  const static int iMomStartEndRelVsZ = hists.IndexOf(hists.FindObject("momStartEndRelVsZ"));
460  static_cast<TH2*>(hists[iMomStartEndRelVsZ])->Fill(vert.z(), diffMomRel);
461  const static int iPhiStartEndVsZ = hists.IndexOf(hists.FindObject("phiXzStartEndVsZ"));
462  static_cast<TH2*>(hists[iPhiStartEndVsZ])->Fill(vert.z(), phiXzStart-phiXzEnd);
463  const static int iThetaStartEndVsZ = hists.IndexOf(hists.FindObject("thetaYStartEndVsZ"));
464  static_cast<TH2*>(hists[iThetaStartEndVsZ])->Fill(vert.z(), thetaYStart-thetaYEnd);
465  const static int iMomStartEndRelVsP = hists.IndexOf(hists.FindObject("momStartEndRelVsP"));
466  static_cast<TH2*>(hists[iMomStartEndRelVsP])->Fill(scalarMomStart, diffMomRel);
467  const static int iPhiStartEndVsP = hists.IndexOf(hists.FindObject("phiXzStartEndVsP"));
468  static_cast<TH2*>(hists[iPhiStartEndVsP])->Fill(scalarMomStart, phiXzStart-phiXzEnd);
469  const static int iThetaStartEndVsP = hists.IndexOf(hists.FindObject("thetaYStartEndVsP"));
470  static_cast<TH2*>(hists[iThetaStartEndVsP])->Fill(scalarMomStart, thetaYStart-thetaYEnd);
471 
472  const static int iRadiusEnd = hists.IndexOf(hists.FindObject("radiusEnd"));
473  static_cast<TH1*>(hists[iRadiusEnd])->Fill(rEnd);
474  const static int iZend = hists.IndexOf(hists.FindObject("zEnd"));
475  static_cast<TH1*>(hists[iZend])->Fill(zEnd);
476  const static int iZdiff = hists.IndexOf(hists.FindObject("zDiff"));
477  static_cast<TH1*>(hists[iZdiff])->Fill(diffZ);
478  const static int iXyPlaneEnd = hists.IndexOf(hists.FindObject("xyPlaneEnd"));
479  static_cast<TH1*>(hists[iXyPlaneEnd])->Fill(endVert.x(), endVert.y());
480  const static int iRzPlaneEnd = hists.IndexOf(hists.FindObject("rzPlaneEnd"));
481  static_cast<TH1*>(hists[iRzPlaneEnd])->Fill(zEnd, (endVert.y() > 0 ? rEnd : -rEnd));
482  const static int iThetaVsZend = hists.IndexOf(hists.FindObject("thetaVsZend"));
483  static_cast<TH2*>(hists[iThetaVsZend])->Fill(zEnd, thetaEnd);
484 }
485 
486 //_________________________________________________________________________________________________
487 bool CosmicGenFilterHelix::equidistLogBins(double* bins, int nBins,
488  double first, double last) const
489 {
490  // Filling 'bins' with borders of 'nBins' bins between 'first' and 'last'
491  // that are equidistant when viewed in log scale,
492  // so 'bins' must have length nBins+1;
493  // If 'first', 'last' or 'nBins' are not positive, failure is reported.
494 
495  if (nBins < 1 || first <= 0. || last <= 0.) return false;
496 
497  bins[0] = first;
498  bins[nBins] = last;
499  const double firstLog = TMath::Log10(bins[0]);
500  const double lastLog = TMath::Log10(bins[nBins]);
501  for (int i = 1; i < nBins; ++i) {
502  bins[i] = TMath::Power(10., firstLog + i*(lastLog-firstLog)/(nBins));
503  }
504 
505  return true;
506 }
ESHandle< MagneticField > fieldHandle
Cylinder::ConstCylinderPointer theTargetCylinder
minimal transverse^2 momentum after propagation to cylinder
const double Pi
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
unsigned int theNumPass
for final statistics: all seen events
tuple cfg
Definition: looper.py:293
T perp() const
Definition: PV3DBase.h:72
Plane::ConstPlanePointer theTargetPlaneMax
plane closing cylinder at &#39;negative&#39; side
const double theMinPt2
minimal momentum^2 after propagation to cylinder
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
const std::vector< int > theIds
const Propagator * getPropagator(const edm::EventSetup &setup) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
TObjArray theHistsAfter
hists of properties from generator
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:63
void createHistsStart(const char *dirName, TObjArray &hists)
for final statistics: events with track reaching target
const MagneticField * getMagneticField(const edm::EventSetup &setup) const
provide magnetic field from Event Setup
bool propagateToCutCylinder(const GlobalPoint &vertStart, const GlobalVector &momStart, int charge, const MagneticField *field, const Propagator *propagator)
actually propagate to the defined cylinder
edm::EDGetTokenT< edm::HepMCProduct > theSrcToken
void monitorEnd(const GlobalPoint &endVert, const GlobalVector &endMom, const GlobalPoint &vert, const GlobalVector &mom, double path, TObjArray &hists)
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
CosmicGenFilterHelix(const edm::ParameterSet &config)
static CylinderPointer build(const PositionType &pos, const RotationType &rot, Scalar radius, Bounds *bounds=0)
Definition: Cylinder.h:51
int iEvent
Definition: GenABIO.cc:230
T mag() const
Definition: PV3DBase.h:67
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual bool filter(edm::Event &event, const edm::EventSetup &eventSetup)
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
T Abs(T a)
Definition: MathUtil.h:49
tuple fd
Definition: ztee.py:136
#define end
Definition: vmac.h:37
const std::vector< int > theCharges
requested Ids
virtual std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &, const Surface &) const final
Definition: Propagator.cc:15
bool equidistLogBins(double *bins, int nBins, double first, double last) const
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
void createHistsEnd(const char *dirName, TObjArray &hists)
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
TObjArray theHistsBefore
whether or not to fill monitor hists (needs TFileService)
bool charge(int id, int &charge) const
true if ID selected, return by value its charge
void monitorStart(const GlobalPoint &vert, const GlobalVector &mom, int charge, TObjArray &hists)
const std::string thePropagatorName
charges, parallel to theIds
T x() const
Definition: PV3DBase.h:62
Plane::ConstPlanePointer theTargetPlaneMin
target cylinder, around z-axis
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
unsigned int theNumTotal
plane closing cylinder at &#39;positive&#39; side