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