CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReconstructerFP420.cc
Go to the documentation of this file.
1 // File: ReconstructerFP420.cc
3 // Date: 11.2007
4 // Description: ReconstructerFP420 for FP420
5 // Modifications:
7 #include <memory>
8 #include <string>
16 
20 
21 //#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
22 //#include "HepMC/GenEvent.h"
23 
24 #include <iostream>
25 using namespace std;
26 
27 //
28 namespace cms
29 {
30  ReconstructerFP420::ReconstructerFP420(const edm::ParameterSet& conf):conf_(conf) {
31 
32  edm::LogInfo ("ReconstructerFP420 ") <<"Enter the FP420 Reco constructer";
33 
34 
35  verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
36  if (verbosity > 0) {
37  std::cout << "Constructor of ReconstructerFP420" << std::endl;
38  }
39 
40 
41  std::string alias ( conf.getParameter<std::string>("@module_label") );
42 
43  produces<RecoCollectionFP420>().setBranchAlias( alias );
44 
45  trackerContainers.clear();
46  trackerContainers = conf.getParameter<std::vector<std::string> >("ROUList");
47  VtxFlag = conf.getParameter<int>("VtxFlagGenRec");
48  m_genReadoutName = conf.getParameter<string>("genReadoutName");
49 
50 
51  // Initialization:
53 
54  }
55 
56  // Virtual destructor needed.
58  if (verbosity > 0) {
59  std::cout << "ReconstructerFP420:delete FP420RecoMain" << std::endl;
60  }
61  delete sFP420RecoMain_;
62  }
63 
64  //Get at the beginning
66  if (verbosity > 0) {
67  std::cout << "ReconstructerFP420:BeginJob method " << std::endl;
68  }
69  }
70 
71 
73  {
74  // beginJob;
75  // be lazy and include the appropriate namespaces
76  using namespace edm;
77  using namespace std;
78 
79  // Get input
80 
81  // Vtx info:
82 
83  // define GEN Vtx of Signal
84  double vtxGenX = 0.;
85  double vtxGenY = 0.;
86  double vtxGenZ = 0.;
87 
88  /*
89  if(VtxFlag == 1) {
90 
91  Handle<HepMCProduct> EvtHandle;
92  try{
93  iEvent.getByLabel(m_genReadoutName,EvtHandle);
94  }catch(const Exception&){
95  if(verbosity>0){
96  std::cout << "no HepMCProduct found"<< std::endl;
97  }
98  }
99 
100  const HepMC::GenEvent* evt = EvtHandle->GetEvent() ;
101  HepMC::GenParticle* proton1 = 0;
102  HepMC::GenParticle* proton2 = 0;
103  double partmomcut=4000.;
104  double pz1max = 0.;
105  double pz2min = 0.;
106  for ( HepMC::GenEvent::particle_const_iterator p = evt->particles_begin(); p != evt->particles_end(); ++p ) {
108  double pz = (*p)->momentum().pz();
109  // if (((*p)->pdg_id() == ipdgproton)&&((*p)->status() == 1)&&(pz > partmomcut)){
110  if( pz > partmomcut){
111  if(pz > pz1max){
112  proton1 = *p;pz1max=pz;
113  }
114  }
115  // else if(( (*p)->pdg_id() == ipdgproton)&&((*p)->status() == 1)&&(pz < -1.*partmomcut)) {
116  else if(pz < -1.*partmomcut) {
117  if(pz < pz2min){
118  proton2 = *p;pz2min=pz;
119  }
120  }
121 
122  }// for
123  if(proton1 && !proton2){
124  vtxGenX = (proton1)->production_vertex()->position().x();
125  vtxGenY = (proton1)->production_vertex()->position().y();
126  vtxGenZ = (proton1)->production_vertex()->position().z();
127  }
128  else if(proton2 && !proton1){
129  vtxGenX = (proton2)->production_vertex()->position().x();
130  vtxGenY = (proton2)->production_vertex()->position().y();
131  vtxGenZ = (proton2)->production_vertex()->position().z();
132  }
133  else if(proton1 && proton2){
134  if(abs((proton1)->momentum().pz()) >= abs((proton2)->momentum().pz()) ) {
135  vtxGenX = (proton1)->production_vertex()->position().x();
136  vtxGenY = (proton1)->production_vertex()->position().y();
137  vtxGenZ = (proton1)->production_vertex()->position().z();
138  }
139  else {
140  vtxGenX = (proton2)->production_vertex()->position().x();
141  vtxGenY = (proton2)->production_vertex()->position().y();
142  vtxGenZ = (proton2)->production_vertex()->position().z();
143  }
144  }
145  }// if(VtxFlag == 1
146 
147 */
148 
149  double VtxX = 0.;
150  double VtxY = 0.;
151  double VtxZ = 0.;
152  if(VtxFlag == 1) {
153  VtxX = vtxGenX;// mm
154  VtxY = vtxGenY;// mm
155  VtxZ = vtxGenZ;// mm
156  }
157 
158 
159 
160 
161  // track collection:
162  //A
163  // edm::Handle<ClusterCollectionFP420> icf_simhit;
164  /*
165  Handle<ClusterCollectionFP420> cf_simhit;
166  std::vector<const ClusterCollectionFP420 *> cf_simhitvec;
167  for(uint32_t i = 0; i< trackerContainers.size();i++){
168  iEvent.getByLabel( trackerContainers[i], cf_simhit);
169  cf_simhitvec.push_back(cf_simhit.product()); }
170  std::auto_ptr<ClusterCollectionFP420 > input(new DigiCollectionFP420(cf_simhitvec));
171  */
172 
173  //B
174 
176  iEvent.getByLabel( trackerContainers[0] , input);
177 
178 
179 
180 
181  // Step C: create empty output collection
182  std::auto_ptr<RecoCollectionFP420> toutput(new RecoCollectionFP420);
183 
184 
185 
186  // put zero to container info from the beginning (important! because not any detID is updated with coming of new event !!!!!!
187  // clean info of container from previous event
188 
189  std::vector<RecoFP420> collector;
190  collector.clear();
192  inputRange.first = collector.begin();
193  inputRange.second = collector.end();
194 
195  unsigned int detID = 0;
196  toutput->putclear(inputRange,detID);
197 
198  unsigned int StID = 1;
199  toutput->putclear(inputRange,StID);
200  StID = 2;
201  toutput->putclear(inputRange,StID);
202 
203 
204  // !!!!!!
205  // if we want to keep Reco container/Collection for one event ---> uncomment the line below and vice versa
206  toutput->clear(); //container_.clear() --> start from the beginning of the container
207 
208  // RUN now: !!!!!!
209  // startFP420RecoMain_.run(input, toutput);
210  sFP420RecoMain_->run(input, toutput, VtxX, VtxY, VtxZ);
211  // std::cout <<"======= ReconstructerFP420: end of produce " << endl;
212 
213  // Step D: write output to file
214  if (verbosity > 0) {
215  std::cout << "ReconstructerFP420: iEvent.put(toutput)" << std::endl;
216  }
217  iEvent.put(toutput);
218  if (verbosity > 0) {
219  std::cout << "ReconstructerFP420: iEvent.put(toutput) DONE" << std::endl;
220  }
221  }//produce
222 
223 } // namespace cms
224 
225 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
inputRange
Get input source.
std::pair< ContainerIterator, ContainerIterator > Range
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
FP420RecoMain * sFP420RecoMain_
void run(edm::Handle< TrackCollectionFP420 > &input, std::auto_ptr< RecoCollectionFP420 > &toutput, double VtxX, double VtxY, double VtxZ)
Runs the algorithm.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple conf
Definition: dbtoconf.py:185
virtual void produce(edm::Event &e, const edm::EventSetup &c)
tuple cout
Definition: gather_cfg.py:121