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