CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalRawToRecHitProducer.cc
Go to the documentation of this file.
3 
5 {
6  lsourceTag_=iConfig.getParameter<edm::InputTag>("lazyGetterTag");
7  sourceTag_=iConfig.getParameter<edm::InputTag>("sourceTag");
8 
9  splitOutput_=iConfig.getParameter<bool>("splitOutput");
10  if (splitOutput_){
11  EBrechitCollection_=iConfig.getParameter<std::string>("EBrechitCollection");
12  EErechitCollection_=iConfig.getParameter<std::string>("EErechitCollection");
13  produces<EBRecHitCollection>(EBrechitCollection_);
14  produces<EERecHitCollection>(EErechitCollection_);
15  LogDebug("EcalRawToRecHit|Producer")<<"ready to create rechits from lazy getter: "<<lsourceTag_
16  <<"\n using region ref from: "<<sourceTag_
17  <<"\n splitting in two collections"
18  <<"\n EB instance: "<<EBrechitCollection_
19  <<"\n EE instance: "<<EErechitCollection_;
20  }
21  else{
22  rechitCollection_=iConfig.getParameter<std::string>("rechitCollection");
23  produces<EcalRecHitCollection>(rechitCollection_);
24  LogDebug("EcalRawToRecHit|Producer")<<"ready to create rechits from lazy getter: "<<lsourceTag_
25  <<"\n using region ref from: "<<sourceTag_
26  <<"\n not splitting the output collection.";
27  }
28 
29  cleaningAlgo_=0;
30  if (iConfig.exists("cleaningConfig")){
31  const edm::ParameterSet & cleaning=iConfig.getParameter<edm::ParameterSet>("cleaningConfig");
32  if (!cleaning.empty())
33  cleaningAlgo_ = new EcalCleaningAlgo(cleaning);
34  }
35 }
36 
37 
39 {
40  if (cleaningAlgo_) delete cleaningAlgo_;
41 }
42 
43 
44 //
45 // member functions
46 //
47 
48 // ------------ method called to produce the data ------------
49 void
51 {
52  using namespace edm;
53 
54 // MyWatcher watcher("Producer");
55 // LogDebug("EcalRawToRecHit|Producer")<<watcher.lap();
56 
57  //retrieve a lazygetter
59  iEvent.getByLabel(lsourceTag_, lgetter);
60  LogDebug("EcalRawToRecHit|Producer")<<"lazy getter retreived from: "<<lsourceTag_<<(lgetter.failedToGet()?" not valid ":"valid") ;
61 // <<watcher.lap();
62 
63  //retrieve a refgetter
65  iEvent.getByLabel(sourceTag_ ,rgetter);
66  LogDebug("EcalRawToRecHit|Producer")<<"ref getter retreived from: "<<sourceTag_<<(rgetter.failedToGet()?" not valid ":"valid");
67 // <<watcher.lap();
68 
69 
70  if (splitOutput_){
71  //prepare the output collection
72  std::auto_ptr<EBRecHitCollection> EBrechits( new EBRecHitCollection );
73  std::auto_ptr<EERecHitCollection> EErechits( new EERecHitCollection );
74  //loop the refgetter
75  unsigned int iR=0;
76  EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin();
77  EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end();
78  for (;iRegion!=iRegionEnd;++iRegion){
79  LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR;
80 //<<watcher.lap();
81  std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
82  std::vector<EcalRecHit>::const_iterator iRecHitEnd =lgetter->begin_record()+iRegion->finish();
83  for (;iRecHit!=iRecHitEnd;iRecHit++){
84  DetId detid =iRecHit->id();
85  //split barrel and endcap
86  int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps
87  LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum;
88  if (EcalNum==1) EBrechits->push_back(*iRecHit);
89  else if (EcalNum==2) EErechits->push_back(*iRecHit);
90  else {
91  edm::LogError("IncorrectRecHit")<<" a subdetid is not recognized. recHit on :"<< iRecHit->id().rawId()
92  <<" is lost.";
93  }//subdetid
94  }//loop over things in region
95  LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done";
96 // <<watcher.lap();
97  }//loop over regions
98 
99  LogDebug("EcalRawToRecHit|Producer")<<EBrechits->size()<<" EB recHits to be put with instance: "<<EBrechitCollection_
100  <<"\n"<<EErechits->size()<<" EE recHits to be put with instance: "<<EErechitCollection_ ;
101 // << watcher.lap();
102 
103  // cleaning of anomalous signals, aka spikes
104  // only doable once we have a "global" collection of hits
105  if (cleaningAlgo_){
106  EBrechits->sort();
107  EErechits->sort();
108  cleaningAlgo_->setFlags(*EBrechits);
109  cleaningAlgo_->setFlags(*EErechits);
110  }
111 
112  iEvent.put(EBrechits, EBrechitCollection_);
113  iEvent.put(EErechits, EErechitCollection_);
114  LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded.";
115 // << watcher.lap();
116  }
117  else{
118  //prepare the output collection
119  std::auto_ptr< EcalRecHitCollection > rechits( new EcalRecHitCollection);
120  //loop the refgetter
121  unsigned int iR=0;
122  EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin();
123  EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end();
124  for (;iRegion!=iRegionEnd;++iRegion){
125  LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR ;
126 //<<watcher.lap();
127  std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
128  std::vector<EcalRecHit>::const_iterator iRecHitEnd=lgetter->begin_record()+iRegion->finish();
129  for (;iRecHit!=iRecHitEnd;iRecHit++){
130  LogDebug("EcalRawToRecHit|Producer")<<"dereferencing rechit ref.";
131  DetId detid =iRecHit->id();
132  int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps
133  LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum;
134  rechits->push_back(*iRecHit);
135  }//loop over things in region
136  LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done" ;
137 //<<watcher.lap();
138  }//loop over regions
139 
140  if (cleaningAlgo_){
141  rechits->sort();
142  cleaningAlgo_->setFlags(*rechits);
143  }
144  LogDebug("EcalRawToRecHit|Producer")<<rechits->size()<<" rechits to be put." ;
145 //<< watcher.lap();
146  iEvent.put(rechits,rechitCollection_);
147  LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded." ;
148 // << watcher.lap();
149  }
150 
151 }
152 
#define LogDebug(id)
T getParameter(std::string const &) const
bool empty() const
Definition: ParameterSet.h:219
virtual void produce(edm::Event &, const edm::EventSetup &)
bool exists(std::string const &parameterName) const
checks if a parameter exists
int iEvent
Definition: GenABIO.cc:243
EcalRawToRecHitProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
EcalCleaningAlgo * cleaningAlgo_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
Definition: DetId.h:20
boost::indirect_iterator< typename collection_type::const_iterator > const_iterator
Definition: RefGetter.h:25
void setFlags(EcalRecHitCollection &rhs)