91 srcEnergyDepositMapMuPlus_(cfg.getParameter<edm::
InputTag>(
"srcEnergyDepositMapMuPlus")),
92 srcEnergyDepositMapMuMinus_(cfg.getParameter<edm::
InputTag>(
"srcEnergyDepositMapMuMinus"))
95 if ( todoList.size() == 0 ) {
97 <<
"Empty to-do list !!\n";
103 <<
"Invalid Configuration parameter 'typeEnergyDepositMap' = " << typeEnergyDepositMap_string <<
" !!\n";
105 for ( edm::VParameterSet::const_iterator todoItem = todoList.begin();
106 todoItem != todoList.end(); ++todoItem ) {
117 <<
"Invalid Configuration parameter 'muonEnSutractionMode' = " << muonEnSutractionMode_string <<
" !!\n";
122 if ( instanceLabel1 != instanceLabel2 ) {
124 <<
"Mismatch in Instance labels for collection 1 = " << instanceLabel1 <<
" and 2 = " << instanceLabel2 <<
" !!\n";
129 produces<RecHitCollection>(instanceLabel1);
130 std::string instanceLabel_removedEnergyMuMinus =
"removedEnergyMuMinus";
131 if ( instanceLabel1 !=
"" ) instanceLabel_removedEnergyMuMinus.append(
"#").append(instanceLabel1);
132 produces<double>(instanceLabel_removedEnergyMuMinus.data());
133 std::string instanceLabel_removedEnergyMuPlus =
"removedEnergyMuPlus";
134 if ( instanceLabel1 !=
"" ) instanceLabel_removedEnergyMuPlus.append(
"#").append(instanceLabel1);
135 produces<double>(instanceLabel_removedEnergyMuPlus.data());
142 template <
typename T>
150 double getCorrection(uint32_t rawDetId,
const std::map<uint32_t, float>& energyDepositMap)
152 double correction = 0.;
153 std::map<uint32_t, float>::const_iterator energyDepositEntry = energyDepositMap.find(rawDetId);
154 if ( energyDepositEntry != energyDepositMap.end() ) {
155 correction = energyDepositEntry->second;
161 template <
typename T>
167 evt.
getByLabel(srcEnergyDepositMapMuPlus_, energyDepositMapMuPlus);
169 evt.
getByLabel(srcEnergyDepositMapMuMinus_, energyDepositMapMuMinus);
171 for (
typename std::vector<todoListEntryType>::const_iterator todoItem = todoList_.begin();
172 todoItem != todoList_.end(); ++todoItem ) {
174 evt.
getByLabel(todoItem->srcRecHitCollection1_, recHitCollection1);
176 evt.
getByLabel(todoItem->srcRecHitCollection2_, recHitCollection2);
178 std::cout <<
"recHitCollection(input1 = " << todoItem->srcRecHitCollection1_.label() <<
":" << todoItem->srcRecHitCollection1_.instance() <<
":" << todoItem->srcRecHitCollection1_.process() <<
"):"
179 <<
" #entries = " << recHitCollection1->size() << std::endl;
180 std::cout <<
"recHitCollection(input2 = " << todoItem->srcRecHitCollection2_.label() <<
":" << todoItem->srcRecHitCollection2_.instance() <<
":" << todoItem->srcRecHitCollection2_.process() <<
"):"
181 <<
" #entries = " << recHitCollection2->size() << std::endl;
184 mixedRecHitInfos_.
clear();
185 updateRecHitInfos(*recHitCollection1, 0);
186 updateRecHitInfos(*recHitCollection2, 1);
188 std::auto_ptr<RecHitCollection> recHitCollection_output(
new RecHitCollection());
189 std::auto_ptr<double> removedEnergyMuPlus(
new double(0.));
190 std::auto_ptr<double> removedEnergyMuMinus(
new double(0.));
192 double muPlusEnergySum = 0.;
193 double muMinusEnergySum = 0.;
195 for (
typename detIdToMixedRecHitInfoMap::iterator mixedRecHitInfo = mixedRecHitInfos_.begin();
196 mixedRecHitInfo != mixedRecHitInfos_.end(); ++mixedRecHitInfo ) {
197 uint32_t rawDetId = mixedRecHitInfo->second.rawDetId_;
199 double muPlusEnergyDeposit = getCorrection(rawDetId, *energyDepositMapMuPlus);
200 double muMinusEnergyDeposit = getCorrection(rawDetId, *energyDepositMapMuMinus);
201 double muonEnergyDeposit = muPlusEnergyDeposit + muMinusEnergyDeposit;
203 muPlusEnergySum += muPlusEnergyDeposit;
204 muMinusEnergySum += muMinusEnergyDeposit;
206 if ( muonEnergyDeposit > 0. ) {
207 if ( verbosity_ )
std::cout <<
"removing muon energy: detId = " << rawDetId <<
", subtracted = " << muonEnergyDeposit << std::endl;
208 if ( mixedRecHitInfo->second.isRecHit1_ && todoItem->muonEnSutractionMode_ == todoListEntryType::kSubtractFromCollection1BeforeMixing ) {
209 if ( todoItem->killNegEnergyBeforeMixing1_ && mixedRecHitInfo->second.energy1_ < muonEnergyDeposit ) {
210 if ( verbosity_ )
std::cout <<
"--> killing recHit1: detId = " << rawDetId <<
", energy = " << (mixedRecHitInfo->second.energy1_ - muonEnergyDeposit) << std::endl;
211 (*removedEnergyMuPlus) += ((mixedRecHitInfo->second.energy1_/muonEnergyDeposit)*muPlusEnergyDeposit);
212 (*removedEnergyMuMinus) += ((mixedRecHitInfo->second.energy1_/muonEnergyDeposit)*muMinusEnergyDeposit);
213 mixedRecHitInfo->second.energy1_ = 0.;
214 mixedRecHitInfo->second.isRecHit1_ =
false;
216 (*removedEnergyMuPlus) += muPlusEnergyDeposit;
217 (*removedEnergyMuMinus) += muMinusEnergyDeposit;
218 mixedRecHitInfo->second.energy1_ -= muonEnergyDeposit;
221 if ( mixedRecHitInfo->second.isRecHit2_ && todoItem->muonEnSutractionMode_ == todoListEntryType::kSubtractFromCollection2BeforeMixing ) {
222 if ( todoItem->killNegEnergyBeforeMixing2_ && mixedRecHitInfo->second.energy2_ < muonEnergyDeposit ) {
223 if ( verbosity_ )
std::cout <<
"--> killing recHit2: detId = " << rawDetId <<
", energy = " << (mixedRecHitInfo->second.energy2_ - muonEnergyDeposit) << std::endl;
224 (*removedEnergyMuPlus) += ((mixedRecHitInfo->second.energy2_/muonEnergyDeposit)*muPlusEnergyDeposit);
225 (*removedEnergyMuMinus) += ((mixedRecHitInfo->second.energy2_/muonEnergyDeposit)*muMinusEnergyDeposit);
226 mixedRecHitInfo->second.energy2_ = 0.;
227 mixedRecHitInfo->second.isRecHit2_ =
false;
229 (*removedEnergyMuPlus) += muPlusEnergyDeposit;
230 (*removedEnergyMuMinus) += muMinusEnergyDeposit;
231 mixedRecHitInfo->second.energy2_ -= muonEnergyDeposit;
236 mixedRecHitInfo->second.energySum_ = 0.;
237 mixedRecHitInfo->second.isRecHitSum_ =
false;
238 if ( mixedRecHitInfo->second.isRecHit1_ ) {
239 mixedRecHitInfo->second.energySum_ += mixedRecHitInfo->second.energy1_;
240 mixedRecHitInfo->second.isRecHitSum_ =
true;
242 if ( mixedRecHitInfo->second.isRecHit2_ ) {
243 mixedRecHitInfo->second.energySum_ += mixedRecHitInfo->second.energy2_;
244 mixedRecHitInfo->second.isRecHitSum_ =
true;
246 if ( muonEnergyDeposit > 0. ) {
247 if ( mixedRecHitInfo->second.isRecHitSum_ && todoItem->muonEnSutractionMode_ == todoListEntryType::kSubtractAfterMixing ) {
248 if ( todoItem->killNegEnergyAfterMixing_ && mixedRecHitInfo->second.energySum_ < muonEnergyDeposit ) {
249 if ( verbosity_ )
std::cout <<
"--> killing recHitSum: detId = " << rawDetId <<
", energy = " << (mixedRecHitInfo->second.energySum_ - muonEnergyDeposit) << std::endl;
250 (*removedEnergyMuPlus) += ((mixedRecHitInfo->second.energySum_/muonEnergyDeposit)*muPlusEnergyDeposit);
251 (*removedEnergyMuMinus) += ((mixedRecHitInfo->second.energySum_/muonEnergyDeposit)*muMinusEnergyDeposit);
252 mixedRecHitInfo->second.energySum_ = 0.;
253 mixedRecHitInfo->second.isRecHitSum_ =
false;
255 (*removedEnergyMuPlus) += muPlusEnergyDeposit;
256 (*removedEnergyMuMinus) += muMinusEnergyDeposit;
257 mixedRecHitInfo->second.energySum_ -= muonEnergyDeposit;
262 if ( mixedRecHitInfo->second.isRecHitSum_ ) {
264 if ( muonEnergyDeposit > 1.
e-3 )
std::cout <<
"--> adding recHitSum (cleaned): detId = " << rawDetId <<
", energy = " << mixedRecHitInfo->second.energySum_ << std::endl;
265 else std::cout <<
"--> adding recHitSum (uncleaned): detId = " << rawDetId <<
", energy = " << mixedRecHitInfo->second.energySum_ << std::endl;
267 recHitCollection_output->push_back(buildRecHit(mixedRecHitInfo->second));
272 std::cout <<
" mu+: sum(EnergyDeposits) = " << muPlusEnergySum <<
" (removed = " << (*removedEnergyMuPlus) <<
")" << std::endl;
273 std::cout <<
" mu-: sum(EnergyDeposits) = " << muMinusEnergySum <<
" (removed = " << (*removedEnergyMuMinus) <<
")" << std::endl;
274 std::cout <<
"recHitCollection(output = " <<
moduleLabel_ <<
":" << todoItem->srcRecHitCollection1_.instance() <<
"): #entries = " << recHitCollection_output->size() << std::endl;
277 std::string instanceLabel = todoItem->srcRecHitCollection1_.instance();
278 evt.
put(recHitCollection_output, instanceLabel);
279 std::string instanceLabel_removedEnergyMuMinus =
"removedEnergyMuMinus";
280 if ( instanceLabel !=
"" ) instanceLabel_removedEnergyMuMinus.append(
"#").append(instanceLabel);
281 evt.
put(removedEnergyMuMinus, instanceLabel_removedEnergyMuMinus.data());
282 std::string instanceLabel_removedEnergyMuPlus =
"removedEnergyMuPlus";
283 if ( instanceLabel !=
"" ) instanceLabel_removedEnergyMuPlus.append(
"#").append(instanceLabel);
284 evt.
put(removedEnergyMuPlus, instanceLabel_removedEnergyMuPlus.data());
288 template <
typename T>
292 recHit != recHitCollection.
end(); ++recHit ) {
293 uint32_t rawDetId = recHit->detid().rawId();
295 bool isNewRecHit = (mixedRecHitInfos_.find(rawDetId) == mixedRecHitInfos_.end());
310 typename detIdToMixedRecHitInfoMap::iterator mixedRecHitInfo = mixedRecHitInfos_.find(rawDetId);
311 assert(mixedRecHitInfo != mixedRecHitInfos_.end());
314 if ( isNewRecHit )
std::cout <<
"creating new recHit: detId = " << rawDetId <<
", energy = " << recHit->energy() << std::endl;
315 else std::cout <<
"merging recHits: detId = " << rawDetId <<
", total energy = " << (mixedRecHitInfo->second.energy1_ + mixedRecHitInfo->second.energy2_)
316 <<
" (added = " << recHit->energy() <<
")" << std::endl;
320 mixedRecHitInfo->second.energy1_ = recHit->energy();
321 mixedRecHitInfo->second.isRecHit1_ =
true;
322 mixedRecHitInfo->second.recHit1_ = &(*recHit);
323 }
else if ( idx == 1 ) {
324 mixedRecHitInfo->second.energy2_ = recHit->energy();
325 mixedRecHitInfo->second.isRecHit2_ =
true;
326 mixedRecHitInfo->second.recHit2_ = &(*recHit);
T getParameter(std::string const &) const
edm::InputTag srcRecHitCollection1_
T buildRecHit(const CaloRecHitMixer_mixedRecHitInfoType< T > &)
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
const_iterator end() const
std::map< uint32_t, CaloRecHitMixer_mixedRecHitInfoType< T > > detIdToMixedRecHitInfoMap
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
edm::InputTag srcRecHitCollection2_
bool killNegEnergyBeforeMixing2_
const_iterator begin() const