CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CTPPSProtonReconstructionValidator.cc
Go to the documentation of this file.
1 /****************************************************************************
2  * Authors:
3  * Jan Kašpar
4  ****************************************************************************/
5 
11 
14 
16 
19 
23 
24 #include "TFile.h"
25 #include "TH1D.h"
26 
27 #include <map>
28 #include <string>
29 
30 //----------------------------------------------------------------------------------------------------
31 
33 public:
35 
36 private:
37  void analyze(const edm::Event&, const edm::EventSetup&) override;
38  void endJob() override;
39 
42  double chiSqCut_;
44 
45  struct RPPlots {
46  std::unique_ptr<TH1D> h_de_x, h_de_y;
48  : h_de_x(new TH1D("", ";#Deltax (mm)", 1000, -1., +1.)),
49  h_de_y(new TH1D("", ";#Deltay (mm)", 1000, -1., +1.)) {}
50 
51  void fill(double de_x, double de_y) {
52  h_de_x->Fill(de_x);
53  h_de_y->Fill(de_y);
54  }
55 
56  void write() const {
57  h_de_x->Write("h_de_x");
58  h_de_y->Write("h_de_y");
59  }
60  };
61 
62  std::map<unsigned int, RPPlots> rp_plots_;
63 };
64 
65 //----------------------------------------------------------------------------------------------------
66 
67 using namespace std;
68 using namespace edm;
69 
70 //----------------------------------------------------------------------------------------------------
71 
73  : tokenRecoProtons_(consumes<reco::ForwardProtonCollection>(iConfig.getParameter<edm::InputTag>("tagRecoProtons"))),
74  opticsESToken_(esConsumes()),
75  chiSqCut_(iConfig.getParameter<double>("chiSqCut")),
76  outputFile_(iConfig.getParameter<string>("outputFile")) {}
77 
78 //----------------------------------------------------------------------------------------------------
79 
81  // get conditions
82  const auto& opticalFunctions = iSetup.getData(opticsESToken_);
83 
84  // stop if conditions invalid
85  if (opticalFunctions.empty())
86  return;
87 
88  // get input
90  iEvent.getByToken(tokenRecoProtons_, hRecoProtons);
91 
92  // process tracks
93  for (const auto& pr : *hRecoProtons) {
94  if (!pr.validFit())
95  continue;
96 
97  if (pr.chi2() > chiSqCut_)
98  continue;
99 
100  for (const auto& tr : pr.contributingLocalTracks()) {
101  CTPPSDetId rpId(tr->rpId());
102  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
103 
104  // skip other than tracking RPs
105  if (rpId.subdetId() != CTPPSDetId::sdTrackingStrip && rpId.subdetId() != CTPPSDetId::sdTrackingPixel)
106  continue;
107 
108  // try to get optics for the RP
109  if (opticalFunctions.count(rpId) == 0)
110  continue;
111  const auto& func = opticalFunctions.at(rpId);
112 
113  // do propagation
114  LHCInterpolatedOpticalFunctionsSet::Kinematics k_in_beam = {0., 0., 0., 0., 0.};
116  func.transport(k_in_beam, k_out_beam);
117 
119  -pr.vx(), -pr.thetaX(), pr.vy(), pr.thetaY(), pr.xi()}; // conversions: CMS --> LHC convention
121  func.transport(k_in, k_out);
122 
123  // fill plots
124  const double de_x = (k_out.x - k_out_beam.x) * 10. - tr->x(); // conversions: cm --> mm
125  const double de_y = (k_out.y - k_out_beam.y) * 10. - tr->y(); // conversions: cm --> mm
126 
127  rp_plots_[rpDecId].fill(de_x, de_y);
128  }
129  }
130 }
131 
132 //----------------------------------------------------------------------------------------------------
133 
135  auto f_out = std::make_unique<TFile>(outputFile_.c_str(), "recreate");
136 
137  for (const auto& p : rp_plots_) {
138  gDirectory = f_out->mkdir(Form("%u", p.first));
139  p.second.write();
140  }
141 }
142 
143 //----------------------------------------------------------------------------------------------------
144 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< reco::ForwardProtonCollection > tokenRecoProtons_
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
bool getData(T &iHolder) const
Definition: EventSetup.h:122
int iEvent
Definition: GenABIO.cc:224
edm::ESGetToken< LHCInterpolatedOpticalFunctionsSetCollection, CTPPSInterpolatedOpticsRcd > opticsESToken_
uint32_t arm() const
Definition: CTPPSDetId.h:51
void analyze(const edm::Event &, const edm::EventSetup &) override
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283