CMS 3D CMS Logo

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