CMS 3D CMS Logo

Tracker_OldtoNewConverter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Tracker_OldtoNewConverter.cc
4 // Class: Tracker_OldtoNewConverter
5 //
13 //
14 // Original Author: Nhan Tran
15 // Created: Mon Jul 16m 16:56:34 CDT 2007
16 // $Id: Tracker_OldtoNewConverter.cc,v 1.2 2010/01/04 18:24:37 mussgill Exp $
17 //
18 //
19 
20 // system include files
24 
25 
26 #include <algorithm>
27 #include "TTree.h"
28 #include "TFile.h"
29 
31 
32 
33 #include <fstream>
34 #include <iostream>
35 
36 //
37 // class decleration
38 //
39 
41 public:
44 
45 
46 private:
47  virtual void beginJob() override;
48  virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override;
49  virtual void endJob() override ;
50 
51  void createMap();
52  void addBranches();
53 
54  // ----------member data ---------------------------
55 
61 
62  std::map< uint32_t, uint32_t > theMap;
63 
64  TFile* m_inputTFile;
65  TFile* m_outputTFile;
66  TTree* m_inputTree;
67  TTree* m_outputTree;
68 
69 
70  uint32_t rawid_i, rawid_f;
71  //int rawid_i, rawid_f;
72  double x_i, y_i, z_i, a_i, b_i, c_i;
73  double x_f, y_f, z_f, a_f, b_f, c_f;
74 
75 
76 };
77 
78 //
79 // constants, enums and typedefs
80 //
81 
82 //
83 // static data member definitions
84 //
85 
86 //
87 // constructors and destructor
88 //
91  rawid_i(0), rawid_f(0),
92  x_i(0.), y_i(0.), z_i(0.), a_i(0.), b_i(0.), c_i(0.),
93  x_f(0.), y_f(0.), z_f(0.), a_f(0.), b_f(0.), c_f(0.)
94 {
95  m_conversionType = iConfig.getUntrackedParameter< std::string > ("conversionType");
96  m_inputFile = iConfig.getUntrackedParameter< std::string > ("inputFile");
97  m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
98  m_textFile = iConfig.getUntrackedParameter< std::string > ("textFile");
99  m_treeName = iConfig.getUntrackedParameter< std::string > ("treeName");
100 }
101 
102 
104 {}
105 
106 
107 //
108 // member functions
109 //
110 
111 // ------------ method called to for each event ------------
113 {}
114 
115 
116 // ------------ method called once each job just before starting event loop ------------
118 {
119 
120  m_inputTFile = new TFile(m_inputFile.c_str());
121  m_outputTFile = new TFile(m_outputFile.c_str(),"RECREATE");
122 
123  m_inputTree = (TTree*) m_inputTFile->Get(m_treeName.c_str());
124  m_outputTree = new TTree(m_treeName.c_str(), m_treeName.c_str());
125 
126  createMap();
127  addBranches();
128 
129  uint32_t nEntries = m_inputTree->GetEntries();
130  uint32_t iter = 0;
131  for (uint32_t i = 0; i < nEntries; ++i){
132  m_inputTree->GetEntry(i);
133  std::map< uint32_t, uint32_t >::const_iterator it = theMap.find(rawid_i);
134 
135  if (it == theMap.end()){
136  edm::LogInfo("ERROR") << "Error: couldn't find rawId: " << rawid_i;
137  iter++;
138  }
139  else{
140  rawid_f = (it)->second;
141  x_f = x_i;
142  y_f = y_i;
143  z_f = z_i;
144  a_f = a_i;
145  b_f = b_i;
146  c_f = c_i;
147  m_outputTree->Fill();
148  }
149 
150  }
151  edm::LogInfo("errors") << "Couldn't find: " << iter;
152  m_outputTFile->cd();
153  m_outputTree->Write();
154  m_outputTFile->Close();
155 }
156 
157 
158 
160 
161  std::ifstream myfile( m_textFile.c_str() );
162  if (!myfile.is_open())
163  throw cms::Exception("FileAccess") << "Unable to open input text file";
164 
165  uint32_t oldid;
166  uint32_t newid;
167 
168  uint32_t ctr = 0;
169  while( !myfile.eof() && myfile.good() ){
170 
171  myfile >> oldid >> newid;
172 
173  //depends on conversion type: OldtoNew or NewtoOld
174  std::pair< uint32_t, uint32_t > pairType;
175  if (m_conversionType == "OldtoNew") {pairType.first = oldid; pairType.second = newid;}
176  if (m_conversionType == "NewtoOld") {pairType.first = newid; pairType.second = oldid;}
177 
178 
179  theMap.insert( pairType );
180 
181  if (myfile.fail()) break;
182 
183  ctr++;
184  }
185  edm::LogInfo("Check") << ctr << " alignables read.";
186 }
187 
189 
190  m_inputTree->SetBranchAddress("rawid", &rawid_i);
191  m_inputTree->SetBranchAddress("x", &x_i);
192  m_inputTree->SetBranchAddress("y", &y_i);
193  m_inputTree->SetBranchAddress("z", &z_i);
194  m_inputTree->SetBranchAddress("alpha", &a_i);
195  m_inputTree->SetBranchAddress("beta", &b_i);
196  m_inputTree->SetBranchAddress("gamma", &c_i);
197 
198  m_outputTree->Branch("rawid", &rawid_f, "rawid/I");
199  m_outputTree->Branch("x", &x_f, "x/D");
200  m_outputTree->Branch("y", &y_f, "y/D");
201  m_outputTree->Branch("z", &z_f, "z/D");
202  m_outputTree->Branch("alpha", &a_f, "alpha/D");
203  m_outputTree->Branch("beta", &b_f, "beta/D");
204  m_outputTree->Branch("gamma", &c_f, "gamma/D");
205 
206 }
207 
208 
209 // ------------ method called once each job just after ending the event loop ------------
211 }
212 
213 
214 
215 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:230
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override
Tracker_OldtoNewConverter(const edm::ParameterSet &)
std::map< uint32_t, uint32_t > theMap