90 srcEnergyDepositMapMuPlus_(cfg.getParameter<edm::InputTag>(
"srcEnergyDepositMapMuPlus")),
91 srcEnergyDepositMapMuMinus_(cfg.getParameter<edm::InputTag>(
"srcEnergyDepositMapMuMinus"))
94 if ( todoList.size() == 0 ) {
96 <<
"Empty to-do list !!\n";
102 <<
"Invalid Configuration parameter 'typeEnergyDepositMap' = " << typeEnergyDepositMap_string <<
" !!\n";
104 for ( edm::VParameterSet::const_iterator todoItem = todoList.begin();
105 todoItem != todoList.end(); ++todoItem ) {
116 <<
"Invalid Configuration parameter 'muonEnSutractionMode' = " << muonEnSutractionMode_string <<
" !!\n";
121 if ( instanceLabel1 != instanceLabel2 ) {
123 <<
"Mismatch in Instance labels for collection 1 = " << instanceLabel1 <<
" and 2 = " << instanceLabel2 <<
" !!\n";
128 produces<RecHitCollection>(instanceLabel1);
129 std::string instanceLabel_removedEnergyMuMinus =
"removedEnergyMuMinus";
130 if ( instanceLabel1 !=
"" ) instanceLabel_removedEnergyMuMinus.append(
"#").append(instanceLabel1);
131 produces<double>(instanceLabel_removedEnergyMuMinus.data());
132 std::string instanceLabel_removedEnergyMuPlus =
"removedEnergyMuPlus";
133 if ( instanceLabel1 !=
"" ) instanceLabel_removedEnergyMuPlus.append(
"#").append(instanceLabel1);
134 produces<double>(instanceLabel_removedEnergyMuPlus.data());
141 template <
typename T>
149 double getCorrection(uint32_t rawDetId,
const std::map<uint32_t, float>& energyDepositMap)
151 double correction = 0.;
152 std::map<uint32_t, float>::const_iterator energyDepositEntry = energyDepositMap.find(rawDetId);
153 if ( energyDepositEntry != energyDepositMap.end() ) {
154 correction = energyDepositEntry->second;
160 template <
typename T>
166 evt.
getByLabel(srcEnergyDepositMapMuPlus_, energyDepositMapMuPlus);
168 evt.
getByLabel(srcEnergyDepositMapMuMinus_, energyDepositMapMuMinus);
170 for (
typename std::vector<todoListEntryType>::const_iterator todoItem = todoList_.begin();
171 todoItem != todoList_.end(); ++todoItem ) {
173 evt.
getByLabel(todoItem->srcRecHitCollection1_, recHitCollection1);
175 evt.
getByLabel(todoItem->srcRecHitCollection2_, recHitCollection2);
177 std::cout <<
"recHitCollection(input1 = " << todoItem->srcRecHitCollection1_.label() <<
":" << todoItem->srcRecHitCollection1_.instance() <<
":" << todoItem->srcRecHitCollection1_.process() <<
"):"
178 <<
" #entries = " << recHitCollection1->size() << std::endl;
179 std::cout <<
"recHitCollection(input2 = " << todoItem->srcRecHitCollection2_.label() <<
":" << todoItem->srcRecHitCollection2_.instance() <<
":" << todoItem->srcRecHitCollection2_.process() <<
"):"
180 <<
" #entries = " << recHitCollection2->size() << std::endl;
183 mixedRecHitInfos_.
clear();
184 updateRecHitInfos(*recHitCollection1, 0);
185 updateRecHitInfos(*recHitCollection2, 1);
187 std::auto_ptr<RecHitCollection> recHitCollection_output(
new RecHitCollection());
188 std::auto_ptr<double> removedEnergyMuPlus(
new double(0.));
189 std::auto_ptr<double> removedEnergyMuMinus(
new double(0.));
191 double muPlusEnergySum = 0.;
192 double muMinusEnergySum = 0.;
194 for (
typename detIdToMixedRecHitInfoMap::iterator mixedRecHitInfo = mixedRecHitInfos_.begin();
195 mixedRecHitInfo != mixedRecHitInfos_.end(); ++mixedRecHitInfo ) {
196 uint32_t rawDetId = mixedRecHitInfo->second.rawDetId_;
198 double muPlusEnergyDeposit = getCorrection(rawDetId, *energyDepositMapMuPlus);
199 double muMinusEnergyDeposit = getCorrection(rawDetId, *energyDepositMapMuMinus);
200 double muonEnergyDeposit = muPlusEnergyDeposit + muMinusEnergyDeposit;
202 muPlusEnergySum += muPlusEnergyDeposit;
203 muMinusEnergySum += muMinusEnergyDeposit;
205 if ( muonEnergyDeposit > 0. ) {
206 if ( verbosity_ )
std::cout <<
"removing muon energy: detId = " << rawDetId <<
", subtracted = " << muonEnergyDeposit << std::endl;
207 if ( mixedRecHitInfo->second.isRecHit1_ && todoItem->muonEnSutractionMode_ == todoListEntryType::kSubtractFromCollection1BeforeMixing ) {
208 if ( todoItem->killNegEnergyBeforeMixing1_ && mixedRecHitInfo->second.energy1_ < muonEnergyDeposit ) {
209 if ( verbosity_ )
std::cout <<
"--> killing recHit1: detId = " << rawDetId <<
", energy = " << (mixedRecHitInfo->second.energy1_ - muonEnergyDeposit) << std::endl;
210 (*removedEnergyMuPlus) += ((mixedRecHitInfo->second.energy1_/muonEnergyDeposit)*muPlusEnergyDeposit);
211 (*removedEnergyMuMinus) += ((mixedRecHitInfo->second.energy1_/muonEnergyDeposit)*muMinusEnergyDeposit);
212 mixedRecHitInfo->second.energy1_ = 0.;
213 mixedRecHitInfo->second.isRecHit1_ =
false;
215 (*removedEnergyMuPlus) += muPlusEnergyDeposit;
216 (*removedEnergyMuMinus) += muMinusEnergyDeposit;
217 mixedRecHitInfo->second.energy1_ -= muonEnergyDeposit;
220 if ( mixedRecHitInfo->second.isRecHit2_ && todoItem->muonEnSutractionMode_ == todoListEntryType::kSubtractFromCollection2BeforeMixing ) {
221 if ( todoItem->killNegEnergyBeforeMixing2_ && mixedRecHitInfo->second.energy2_ < muonEnergyDeposit ) {
222 if ( verbosity_ )
std::cout <<
"--> killing recHit2: detId = " << rawDetId <<
", energy = " << (mixedRecHitInfo->second.energy2_ - muonEnergyDeposit) << std::endl;
223 (*removedEnergyMuPlus) += ((mixedRecHitInfo->second.energy2_/muonEnergyDeposit)*muPlusEnergyDeposit);
224 (*removedEnergyMuMinus) += ((mixedRecHitInfo->second.energy2_/muonEnergyDeposit)*muMinusEnergyDeposit);
225 mixedRecHitInfo->second.energy2_ = 0.;
226 mixedRecHitInfo->second.isRecHit2_ =
false;
228 (*removedEnergyMuPlus) += muPlusEnergyDeposit;
229 (*removedEnergyMuMinus) += muMinusEnergyDeposit;
230 mixedRecHitInfo->second.energy2_ -= muonEnergyDeposit;
235 mixedRecHitInfo->second.energySum_ = 0.;
236 mixedRecHitInfo->second.isRecHitSum_ =
false;
237 if ( mixedRecHitInfo->second.isRecHit1_ ) {
238 mixedRecHitInfo->second.energySum_ += mixedRecHitInfo->second.energy1_;
239 mixedRecHitInfo->second.isRecHitSum_ =
true;
241 if ( mixedRecHitInfo->second.isRecHit2_ ) {
242 mixedRecHitInfo->second.energySum_ += mixedRecHitInfo->second.energy2_;
243 mixedRecHitInfo->second.isRecHitSum_ =
true;
245 if ( muonEnergyDeposit > 0. ) {
246 if ( mixedRecHitInfo->second.isRecHitSum_ && todoItem->muonEnSutractionMode_ == todoListEntryType::kSubtractAfterMixing ) {
247 if ( todoItem->killNegEnergyAfterMixing_ && mixedRecHitInfo->second.energySum_ < muonEnergyDeposit ) {
248 if ( verbosity_ )
std::cout <<
"--> killing recHitSum: detId = " << rawDetId <<
", energy = " << (mixedRecHitInfo->second.energySum_ - muonEnergyDeposit) << std::endl;
249 (*removedEnergyMuPlus) += ((mixedRecHitInfo->second.energySum_/muonEnergyDeposit)*muPlusEnergyDeposit);
250 (*removedEnergyMuMinus) += ((mixedRecHitInfo->second.energySum_/muonEnergyDeposit)*muMinusEnergyDeposit);
251 mixedRecHitInfo->second.energySum_ = 0.;
252 mixedRecHitInfo->second.isRecHitSum_ =
false;
254 (*removedEnergyMuPlus) += muPlusEnergyDeposit;
255 (*removedEnergyMuMinus) += muMinusEnergyDeposit;
256 mixedRecHitInfo->second.energySum_ -= muonEnergyDeposit;
261 if ( mixedRecHitInfo->second.isRecHitSum_ ) {
263 if ( muonEnergyDeposit > 1.
e-3 )
std::cout <<
"--> adding recHitSum (cleaned): detId = " << rawDetId <<
", energy = " << mixedRecHitInfo->second.energySum_ << std::endl;
264 else std::cout <<
"--> adding recHitSum (uncleaned): detId = " << rawDetId <<
", energy = " << mixedRecHitInfo->second.energySum_ << std::endl;
266 recHitCollection_output->push_back(buildRecHit(mixedRecHitInfo->second));
271 std::cout <<
" mu+: sum(EnergyDeposits) = " << muPlusEnergySum <<
" (removed = " << (*removedEnergyMuPlus) <<
")" << std::endl;
272 std::cout <<
" mu-: sum(EnergyDeposits) = " << muMinusEnergySum <<
" (removed = " << (*removedEnergyMuMinus) <<
")" << std::endl;
273 std::cout <<
"recHitCollection(output = " <<
moduleLabel_ <<
":" << todoItem->srcRecHitCollection1_.instance() <<
"): #entries = " << recHitCollection_output->size() << std::endl;
276 std::string instanceLabel = todoItem->srcRecHitCollection1_.instance();
277 evt.
put(recHitCollection_output, instanceLabel);
278 std::string instanceLabel_removedEnergyMuMinus =
"removedEnergyMuMinus";
279 if ( instanceLabel !=
"" ) instanceLabel_removedEnergyMuMinus.append(
"#").append(instanceLabel);
280 evt.
put(removedEnergyMuMinus, instanceLabel_removedEnergyMuMinus.data());
281 std::string instanceLabel_removedEnergyMuPlus =
"removedEnergyMuPlus";
282 if ( instanceLabel !=
"" ) instanceLabel_removedEnergyMuPlus.append(
"#").append(instanceLabel);
283 evt.
put(removedEnergyMuPlus, instanceLabel_removedEnergyMuPlus.data());
287 template <
typename T>
291 recHit != recHitCollection.
end(); ++recHit ) {
292 uint32_t rawDetId = recHit->detid().rawId();
294 bool isNewRecHit = (mixedRecHitInfos_.find(rawDetId) == mixedRecHitInfos_.end());
306 mixedRecHitInfos_.insert(std::pair<uint32_t, CaloRecHitMixer_mixedRecHitInfoType>(rawDetId, mixedRecHitInfo));
309 typename detIdToMixedRecHitInfoMap::iterator mixedRecHitInfo = mixedRecHitInfos_.find(rawDetId);
310 assert(mixedRecHitInfo != mixedRecHitInfos_.end());
313 if ( isNewRecHit )
std::cout <<
"creating new recHit: detId = " << rawDetId <<
", energy = " << recHit->energy() << std::endl;
314 else std::cout <<
"merging recHits: detId = " << rawDetId <<
", total energy = " << (mixedRecHitInfo->second.energy1_ + mixedRecHitInfo->second.energy2_)
315 <<
" (added = " << recHit->energy() <<
")" << std::endl;
319 mixedRecHitInfo->second.energy1_ = recHit->energy();
320 mixedRecHitInfo->second.isRecHit1_ =
true;
321 mixedRecHitInfo->second.recHit1_ = &(*recHit);
322 }
else if ( idx == 1 ) {
323 mixedRecHitInfo->second.energy2_ = recHit->energy();
324 mixedRecHitInfo->second.isRecHit2_ =
true;
325 mixedRecHitInfo->second.recHit2_ = &(*recHit);
T getParameter(std::string const &) const
edm::InputTag srcRecHitCollection1_
const CaloRecHit * recHit1_
const CaloRecHit * recHit2_
int typeEnergyDepositMap_
CaloRecHitMixer(const edm::ParameterSet &)
std::vector< ParameterSet > VParameterSet
bool killNegEnergyBeforeMixing1_
detIdToMixedRecHitInfoMap mixedRecHitInfos_
std::vector< T >::const_iterator const_iterator
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::InputTag srcEnergyDepositMapMuPlus_
std::map< uint32_t, float > detIdToFloatMap
bool killNegEnergyAfterMixing_
edm::InputTag srcEnergyDepositMapMuMinus_
virtual void produce(edm::Event &, const edm::EventSetup &)
int muonEnSutractionMode_
void updateRecHitInfos(const RecHitCollection &, int)
std::vector< todoListEntryType > todoList_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
edm::SortedCollection< T > RecHitCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
std::map< uint32_t, CaloRecHitMixer_mixedRecHitInfoType > detIdToMixedRecHitInfoMap
const_iterator end() const
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
edm::InputTag srcRecHitCollection2_
T buildRecHit(const CaloRecHitMixer_mixedRecHitInfoType &)
bool killNegEnergyBeforeMixing2_
const_iterator begin() const