CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalChannelKiller.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalChannelKiller
4 // Class: EcalChannelKiller
5 //
13 //
14 // Original Author: Georgios Daskalakis
15 // Created: Tue Apr 24 17:21:31 CEST 2007
16 // $Id: EcalChannelKiller.cc,v 1.8 2012/01/10 18:22:10 eulisse Exp $
17 //
18 //
19 
20 
21 
22 
23 // Geometry
30 
31 // Reconstruction Classes
35 
36 
38 
39 #include <string>
40 #include <cstdio>
41 using namespace cms;
42 using namespace std;
43 
44 
45 //
46 // constructors and destructor
47 //
49 {
50 
51  hitProducer_ = ps.getParameter<std::string>("hitProducer");
52  hitCollection_ = ps.getParameter<std::string>("hitCollection");
53  reducedHitCollection_ = ps.getParameter<std::string>("reducedHitCollection");
54  DeadChannelFileName_ = ps.getParameter<std::string>("DeadChannelsFile");
55 
56  produces< EcalRecHitCollection >(reducedHitCollection_);
57 
58 
59 }
60 
61 
63 {
64 
65  // do anything here that needs to be done at desctruction time
66  // (e.g. close files, deallocate resources etc.)
67 
68 }
69 
70 
71 //
72 // member functions
73 //
74 
75 // ------------ method called to produce the data ------------
76 void
78 {
79  using namespace edm;
80 
81  // get the hit collection from the event:
83  iEvent.getByLabel(hitProducer_, hitCollection_, rhcHandle);
84  if (!(rhcHandle.isValid()))
85  {
86  // std::cout << "could not get a handle on the EcalRecHitCollection!" << std::endl;
87  return;
88  }
89  const EcalRecHitCollection* hit_collection = rhcHandle.product();
90 
91  int nRed = 0;
92 
93  // create an auto_ptr to a EcalRecHitCollection, copy the RecHits into it and put in the Event:
94  std::auto_ptr< EcalRecHitCollection > redCollection(new EcalRecHitCollection);
95 
96 
97  for(EcalRecHitCollection::const_iterator it = hit_collection->begin(); it != hit_collection->end(); ++it) {
98 
99  double NewEnergy =it->energy();
100  bool ItIsDead=false;
101  //Dead Cells are read from text files
102  std::vector<EBDetId>::const_iterator DeadCell;
103  for(DeadCell=ChannelsDeadID.begin();DeadCell<ChannelsDeadID.end();DeadCell++){
104  if(it->detid()==*DeadCell){
105  ItIsDead=true;
106  NewEnergy =0.;
107  nRed++;
108 
109  }
110  }//End looping on vector of Dead Cells
111 
112  // Make a new RecHit
113  //
114  // TODO what will be the it->time() for D.C. ?
115  // Could we use it for "correction" identification?
116  //
117  if(!ItIsDead){
118  EcalRecHit NewHit(it->id(),NewEnergy,it->time());
119  redCollection->push_back( NewHit );
120  }
121  }
122  // std::cout << "total # hits: " << nTot << " #hits with E = " << 0 << " GeV : " << nRed << std::endl;
123 
124  iEvent.put(redCollection, reducedHitCollection_);
125 
126 }
127 
128 
129 
130 
131 // ------------ method called once each job just before starting event loop ------------
132 void
134 {
135 
136  //Open the DeadChannel file, read it.
137  FILE* DeadCha;
138  printf("Dead Channels FILE: %s\n",DeadChannelFileName_.c_str());
139  DeadCha = fopen(DeadChannelFileName_.c_str(),"r");
140 
141  int fileStatus=0;
142  int ieta=-10000;
143  int iphi=-10000;
144  while(fileStatus != EOF) {
145  fileStatus = fscanf(DeadCha,"%d %d\n",&ieta,&iphi);
146  // std::cout<<" ieta "<<ieta<<" iphi "<<iphi<<std::endl;
147  if(ieta==-10000||iphi==-10000){/*std::cout << "Problem reading Dead Channels file "<<std::endl;*/break;}
148  EBDetId cell(ieta,iphi);
149  ChannelsDeadID.push_back(cell);
150  } //end while
151  fclose(DeadCha);
152  // std::cout<<" Read "<<ChannelsDeadID.size()<<" dead channels "<<std::endl;
153 
154 }
155 
156 
157 
158 // ------------ method called once each job just after ending the event loop ------------
159 void
161 }
162 
163 //define this as a plug-in
T getParameter(std::string const &) const
DEFINE_FWK_MODULE(TauMET)
std::vector< EcalRecHit >::const_iterator const_iterator
virtual void endJob()
virtual void beginJob()
int iEvent
Definition: GenABIO.cc:243
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
virtual void produce(edm::Event &, const edm::EventSetup &)
EcalChannelKiller(const edm::ParameterSet &)