CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalDeadChannelRecoveryProducers.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalDeadChannelRecoveryProducers
4 // Class: EcalDeadChannelRecoveryProducers
5 //
13 //
14 // Original Author: Georgios Daskalakis
15 // Created: Thu Apr 12 17:01:03 CEST 2007
16 // $Id: EcalDeadChannelRecoveryProducers.cc,v 1.7 2011/05/22 23:08:19 eulisse Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 
25 
26 // Geometry
30 
31 // Reconstruction Classes
35 
38 
39 
40 #include <string>
41 #include <cstdio>
42 
43 using namespace cms;
44 using namespace std;
45 
46 
47 
48 //
49 // constants, enums and typedefs
50 //
51 
52 //
53 // static data member definitions
54 //
55 
56 //
57 // constructors and destructor
58 //
60 {
61 
62  //now do what ever other initialization is needed
63  CorrectDeadCells_ = ps.getParameter<bool>("CorrectDeadCells");
64  CorrectionMethod_ = ps.getParameter<std::string>("CorrectionMethod");
65  hitProducer_ = ps.getParameter<std::string>("hitProducer");
66  hitCollection_ = ps.getParameter<std::string>("hitCollection");
67  reducedHitCollection_ = ps.getParameter<std::string>("reducedHitCollection");
68  DeadChannelFileName_ = ps.getParameter<std::string>("DeadChannelsFile");
69  Sum8GeVThreshold_= ps.getParameter<double>("Sum8GeVThreshold");
70 
71  produces< EcalRecHitCollection >(reducedHitCollection_);
72 }
73 
74 
76 {
77 
78  // do anything here that needs to be done at desctruction time
79  // (e.g. close files, deallocate resources etc.)
80 
81 }
82 
83 
84 //
85 // member functions
86 //
87 
88 // ------------ method called to produce the data ------------
89 void
91 {
92  using namespace edm;
93 
94  edm::ESHandle<CaloTopology> theCaloTopology;
95  iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
96 
97  // get the hit collection from the event:
99  evt.getByLabel(hitProducer_, hitCollection_, rhcHandle);
100  if (!(rhcHandle.isValid()))
101  {
102  std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
103  return;
104  }
105  const EcalRecHitCollection* hit_collection = rhcHandle.product();
106 
107  // create an auto_ptr to a EcalRecHitCollection, copy the RecHits into it and put it in the Event:
108  std::auto_ptr< EcalRecHitCollection > redCollection(new EcalRecHitCollection);
109 
110  EcalDeadChannelRecoveryAlgos *DeadChannelCorrector = new EcalDeadChannelRecoveryAlgos(theCaloTopology.product());
111 
112  //Dead Cells are read from a text file
113  std::vector<EBDetId>::const_iterator DeadCell;
114 
115  //
116  //This should work only if we REMOVE the DC RecHit from the reduced RecHit collection
117  //
118  for(EcalRecHitCollection::const_iterator it = hit_collection->begin(); it != hit_collection->end(); ++it) {
119  std::vector<EBDetId>::const_iterator CheckDead = ChannelsDeadID.begin();
120  bool OverADeadRecHit=false;
121  while(CheckDead<ChannelsDeadID.end()){
122  if(it->detid()==*CheckDead){OverADeadRecHit=true;break;}
123  CheckDead++;
124  }
125  if(!OverADeadRecHit)redCollection->push_back( *it );
126  }
127  for(DeadCell=ChannelsDeadID.begin();DeadCell<ChannelsDeadID.end();DeadCell++){
128  EcalRecHit NewRecHit = DeadChannelCorrector->Correct(*DeadCell,hit_collection,CorrectionMethod_,Sum8GeVThreshold_);
129  redCollection->push_back( NewRecHit );
130  }
131 
132 
133 
134 
135  delete DeadChannelCorrector ;
136 
137  evt.put(redCollection, reducedHitCollection_);
138 
139 }
140 
141 
142 
143 // ------------ method called once each job just before starting event loop ------------
144 void
146 {
147  FILE* DeadCha;
148  printf("Dead Channels FILE: %s\n",DeadChannelFileName_.c_str());
149  DeadCha = fopen(DeadChannelFileName_.c_str(),"r");
150 
151  int fileStatus=0;
152  int ieta=-10000;
153  int iphi=-10000;
154  while(fileStatus != EOF) {
155  fileStatus = fscanf(DeadCha,"%d %d\n",&ieta,&iphi);
156  // std::cout<<" ieta "<<ieta<<" iphi "<<iphi<<std::endl;
157  if(ieta==-10000||iphi==-10000){std::cout << "Problem reading Dead Channels file "<<std::endl;break;}
158  EBDetId cell(ieta,iphi);
159  ChannelsDeadID.push_back(cell);
160  } //end while
161  fclose(DeadCha);
162  // std::cout<<" Read "<<ChannelsDeadID.size()<<" dead channels "<<std::endl;
163 
164 }
165 
166 // ------------ method called once each job just after ending the event loop ------------
167 void
169 }
170 
171 //define this as a plug-in
T getParameter(std::string const &) const
DEFINE_FWK_MODULE(TauMET)
std::vector< EcalRecHit >::const_iterator const_iterator
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
EcalDeadChannelRecoveryProducers(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:55
tuple cout
Definition: gather_cfg.py:121
virtual void produce(edm::Event &, const edm::EventSetup &)