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