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  lgetter->setEvent(iEvent);
82  std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
83  std::vector<EcalRecHit>::const_iterator iRecHitEnd =lgetter->begin_record()+iRegion->finish();
84  for (;iRecHit!=iRecHitEnd;iRecHit++){
85  DetId detid =iRecHit->id();
86  //split barrel and endcap
87  int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps
88  LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum;
89  if (EcalNum==1) EBrechits->push_back(*iRecHit);
90  else if (EcalNum==2) EErechits->push_back(*iRecHit);
91  else {
92  edm::LogError("IncorrectRecHit")<<" a subdetid is not recognized. recHit on :"<< iRecHit->id().rawId()
93  <<" is lost.";
94  }//subdetid
95  }//loop over things in region
96  LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done";
97 // <<watcher.lap();
98  }//loop over regions
99 
100  LogDebug("EcalRawToRecHit|Producer")<<EBrechits->size()<<" EB recHits to be put with instance: "<<EBrechitCollection_
101  <<"\n"<<EErechits->size()<<" EE recHits to be put with instance: "<<EErechitCollection_ ;
102 // << watcher.lap();
103 
104  // cleaning of anomalous signals, aka spikes
105  // only doable once we have a "global" collection of hits
106  if (cleaningAlgo_){
107  EBrechits->sort();
108  EErechits->sort();
109  cleaningAlgo_->setFlags(*EBrechits);
110  cleaningAlgo_->setFlags(*EErechits);
111  }
112 
113  iEvent.put(EBrechits, EBrechitCollection_);
114  iEvent.put(EErechits, EErechitCollection_);
115  LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded.";
116 // << watcher.lap();
117  }
118  else{
119  //prepare the output collection
120  std::auto_ptr< EcalRecHitCollection > rechits( new EcalRecHitCollection);
121  //loop the refgetter
122  unsigned int iR=0;
123  EcalRecHitRefGetter::const_iterator iRegion=rgetter->begin();
124  EcalRecHitRefGetter::const_iterator iRegionEnd=rgetter->end();
125  for (;iRegion!=iRegionEnd;++iRegion){
126  LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR ;
127 //<<watcher.lap();
128  lgetter->setEvent(iEvent);
129  std::vector<EcalRecHit>::const_iterator iRecHit=lgetter->begin_record()+iRegion->start();
130  std::vector<EcalRecHit>::const_iterator iRecHitEnd=lgetter->begin_record()+iRegion->finish();
131  for (;iRecHit!=iRecHitEnd;iRecHit++){
132  LogDebug("EcalRawToRecHit|Producer")<<"dereferencing rechit ref.";
133  DetId detid =iRecHit->id();
134  int EcalNum=detid.subdetId(); //1 stands for Barrel, 2 for endcaps
135  LogDebug("EcalRawToRecHit|Producer")<<"subdetId is: "<<EcalNum;
136  rechits->push_back(*iRecHit);
137  }//loop over things in region
138  LogDebug("EcalRawToRecHit|Producer")<<"looping over refgetter region: "<<iR++<<" done" ;
139 //<<watcher.lap();
140  }//loop over regions
141 
142  if (cleaningAlgo_){
143  rechits->sort();
144  cleaningAlgo_->setFlags(*rechits);
145  }
146  LogDebug("EcalRawToRecHit|Producer")<<rechits->size()<<" rechits to be put." ;
147 //<< watcher.lap();
148  iEvent.put(rechits,rechitCollection_);
149  LogDebug("EcalRawToRecHit|Producer")<<"collections uploaded." ;
150 // << watcher.lap();
151  }
152 
153 }
154 
#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:94
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:361
Definition: DetId.h:20
boost::indirect_iterator< typename collection_type::const_iterator > const_iterator
Definition: RefGetter.h:25
void setFlags(EcalRecHitCollection &rhs)