CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/HLTriggerOffline/Higgs/src/HLTHiggsSubAnalysis.cc

Go to the documentation of this file.
00001 
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 #include "DataFormats/Common/interface/Handle.h"
00011 
00012 #include "HLTriggerOffline/Higgs/interface/HLTHiggsSubAnalysis.h"
00013 #include "HLTriggerOffline/Higgs/src/EVTColContainer.cc"
00014 #include "HLTriggerOffline/Higgs/src/MatchStruct.cc"
00015 
00016 #include "FWCore/Common/interface/TriggerNames.h"
00017 
00018 #include "TPRegexp.h"
00019 #include "TString.h"
00020 
00021 #include "DataFormats/Common/interface/TriggerResults.h"
00022 #include "FWCore/Common/interface/TriggerNames.h"
00023 
00024 #include "HLTriggerOffline/Higgs/interface/HLTHiggsSubAnalysis.h"
00025 #include "HLTriggerOffline/Higgs/src/MatchStruct.cc"
00026 
00027 #include "TPRegexp.h"
00028 #include "TString.h"
00029 
00030 #include<set>
00031 #include<algorithm>
00032 
00033 
00034 HLTHiggsSubAnalysis::HLTHiggsSubAnalysis(const edm::ParameterSet & pset,
00035                 const std::string & analysisname) :
00036         _pset(pset),
00037         _analysisname(analysisname),
00038         _minCandidates(0),
00039         _hltProcessName(pset.getParameter<std::string>("hltProcessName")),
00040         _genParticleLabel(pset.getParameter<std::string>("genParticleLabel")),
00041         _parametersEta(pset.getParameter<std::vector<double> >("parametersEta")),
00042         _parametersPhi(pset.getParameter<std::vector<double> >("parametersPhi")),
00043         _parametersTurnOn(pset.getParameter<std::vector<double> >("parametersTurnOn")),
00044         _recMuonSelector(0),
00045         _recElecSelector(0),
00046         _recCaloMETSelector(0),
00047         _recPFTauSelector(0),
00048         _recPhotonSelector(0),
00049         _recTrackSelector(0),
00050         _dbe(0)
00051 {
00052         // Specific parameters for this analysis
00053         edm::ParameterSet anpset = pset.getParameter<edm::ParameterSet>(analysisname);
00054         // Collections labels (but genparticles already initialized) 
00055         // initializing _recLabels data member)
00056         this->bookobjects( anpset );
00057 
00058         // Generic objects: Initialization of cuts
00059         for(std::map<unsigned int,std::string>::const_iterator it = _recLabels.begin();
00060                         it != _recLabels.end(); ++it)
00061         {
00062                 const std::string objStr = EVTColContainer::getTypeString(it->first);
00063                 _genCut[it->first] = pset.getParameter<std::string>( std::string(objStr+"_genCut").c_str() );
00064                 _recCut[it->first] = pset.getParameter<std::string>( std::string(objStr+"_recCut").c_str() );
00065                 _cutMinPt[it->first] = pset.getParameter<double>( std::string(objStr+"_cutMinPt").c_str() );
00066                 _cutMaxEta[it->first] = pset.getParameter<double>( std::string(objStr+"_cutMaxEta").c_str() );
00067         }
00068 
00069         //--- Updating parameters if has to be modified for this particular specific analysis
00070         for(std::map<unsigned int,std::string>::const_iterator it = _recLabels.begin();
00071                         it != _recLabels.end(); ++it)
00072         {
00073                 const std::string objStr = EVTColContainer::getTypeString(it->first);
00074                 try
00075                 {
00076                         _genCut[it->first] = anpset.getUntrackedParameter<std::string>( std::string(objStr+"_genCut").c_str() ); 
00077                 }
00078                 catch(edm::Exception)
00079                 {
00080                 }
00081                 try
00082                 {
00083                         _recCut[it->first] = anpset.getUntrackedParameter<std::string>( std::string(objStr+"_recCut").c_str() );
00084                 }
00085                 catch(edm::Exception)
00086                 {
00087                 }
00088                 try
00089                 {
00090                         _cutMinPt[it->first] = anpset.getUntrackedParameter<double>( std::string(objStr+"_cutMinPt").c_str() );
00091                 }
00092                 catch(edm::Exception)
00093                 {
00094                 }
00095                 try
00096                 {
00097                         _cutMaxEta[it->first] = anpset.getUntrackedParameter<double>( std::string(objStr+"_cutMaxEta").c_str() );
00098                 }
00099                 catch(edm::Exception)
00100                 {
00101                 }
00102         }
00103         
00104         _hltPathsToCheck = anpset.getParameter<std::vector<std::string> >("hltPathsToCheck");
00105         _minCandidates = anpset.getParameter<unsigned int>("minCandidates");
00106 
00107         _dbe = edm::Service<DQMStore>().operator->();
00108         _dbe->setVerbose(0);
00109 }
00110 
00111 HLTHiggsSubAnalysis::~HLTHiggsSubAnalysis()
00112 {
00113         for(std::map<unsigned int,StringCutObjectSelector<reco::GenParticle>* >::iterator it = _genSelectorMap.begin();
00114                         it != _genSelectorMap.end(); ++it)
00115         {
00116                 if( it->second != 0)
00117                 {
00118                         delete it->second;
00119                         it->second =0;
00120                 }
00121         }
00122         if( _recMuonSelector != 0)
00123         {
00124                 delete _recMuonSelector;
00125                 _recMuonSelector =0;
00126         }
00127         if( _recElecSelector != 0)
00128         {
00129                 delete _recElecSelector;
00130                 _recElecSelector =0;
00131         }
00132         if( _recPhotonSelector != 0)
00133         {
00134                 delete _recPhotonSelector;
00135                 _recPhotonSelector =0;
00136         }
00137         if( _recCaloMETSelector != 0)
00138         {
00139                 delete _recCaloMETSelector;
00140                 _recCaloMETSelector =0;
00141         }
00142         if( _recPFTauSelector != 0)
00143         {
00144                 delete _recPFTauSelector;
00145                 _recPFTauSelector =0;
00146         }
00147         if( _recTrackSelector != 0)
00148         {
00149                 delete _recTrackSelector;
00150                 _recTrackSelector =0;
00151         }
00152 }
00153 
00154 
00155 void HLTHiggsSubAnalysis::beginJob() 
00156 {
00157 }
00158 
00159 
00160 
00161 void HLTHiggsSubAnalysis::beginRun(const edm::Run & iRun, const edm::EventSetup & iSetup)
00162 {
00163         std::string baseDir = "HLT/Higgs/"+_analysisname+"/";
00164         _dbe->setCurrentFolder(baseDir);
00165 
00166         // Initialize the confighlt
00167         bool changedConfig;
00168         if(!_hltConfig.init(iRun,iSetup,_hltProcessName,changedConfig))
00169         {
00170                 edm::LogError("HiggsValidations") << "HLTHiggsSubAnalysis::beginRun: "
00171                         << "Initializtion of HLTConfigProvider failed!!";
00172         }
00173 
00174 
00175         // Parse the input paths to get them if there are in the table 
00176         // and associate them the last filter of the path (in order to extract the
00177         _hltPaths.clear();
00178         for(size_t i = 0; i < _hltPathsToCheck.size(); ++i)
00179         {
00180                 bool found = false;
00181                 TPRegexp pattern(_hltPathsToCheck[i]);
00182                 for(size_t j = 0 ; j < _hltConfig.triggerNames().size(); ++j)
00183                 {
00184                         std::string thetriggername = _hltConfig.triggerNames()[j];
00185                         if(TString(thetriggername).Contains(pattern))
00186                         {
00187                                 _hltPaths.insert(thetriggername);
00188                                 found = true;
00189                         }
00190                 }
00191                 if( ! found )
00192                 {
00193                         edm::LogWarning("HiggsValidations") << "HLTHiggsSubAnalysis::beginRun, In "
00194                                 << _analysisname << " subfolder NOT found the path: '" 
00195                                 << _hltPathsToCheck[i] << "*'" ;
00196                 }
00197         }
00198 
00199         LogTrace("HiggsValidation") << "SubAnalysis: " << _analysisname 
00200                 << "\nHLT Trigger Paths found >>>"; 
00201         // Initialize the plotters (analysers for each trigger path)
00202         _analyzers.clear();
00203         for(std::set<std::string>::iterator iPath = _hltPaths.begin(); 
00204                         iPath != _hltPaths.end(); ++iPath) 
00205         {
00206                 // Avoiding the dependence of the version number for
00207                 // the trigger paths
00208                 std::string path = * iPath;
00209                 std::string shortpath = path;
00210                 if(path.rfind("_v") < path.length())
00211                 {
00212                         shortpath = path.substr(0, path.rfind("_v"));
00213                 }
00214                 _shortpath2long[shortpath] = path;
00215 
00216                 // Objects needed by the HLT path
00217                 const std::vector<unsigned int> objsNeedHLT = this->getObjectsType(shortpath);
00218                 // Sanity check: the object needed by a trigger path should be
00219                 // introduced by the user via config python (_recLabels datamember)
00220                 std::vector<unsigned int> userInstantiate;
00221                 for(std::map<unsigned int,std::string>::iterator it = _recLabels.begin() ; 
00222                                 it != _recLabels.end(); ++it)
00223                 {
00224                         userInstantiate.push_back(it->first);
00225                 }
00226                 for(std::vector<unsigned int>::const_iterator it = objsNeedHLT.begin(); it != objsNeedHLT.end(); 
00227                                 ++it)
00228                 {
00229                         if( std::find(userInstantiate.begin(),userInstantiate.end(), *it) == 
00230                                         userInstantiate.end() )
00231                         {
00232                                 edm::LogError("HiggsValidation") << "In HLTHiggsSubAnalysis::beginRun, " 
00233                                         << "Incoherence found in the python configuration file!!\nThe SubAnalysis '" 
00234                                         << _analysisname << "' has been asked to evaluate the trigger path '"
00235                                         << shortpath << "' (found it in 'hltPathsToCheck') BUT this path"
00236                                         << " needs a '" << EVTColContainer::getTypeString(*it) 
00237                                         << "' which has not been instantiate ('recVariableLabels'" 
00238                                         << ")" ;
00239                                 exit(-1);
00240                         }
00241                 }
00242                 LogTrace("HiggsValidation") << " --- " << shortpath;
00243                 
00244                 // the hlt path, the objects (elec,muons,photons,...)
00245                 // needed to evaluate the path are the argumens of the plotter
00246                 HLTHiggsPlotter analyzer(_pset, shortpath,objsNeedHLT, _dbe);
00247                 _analyzers.push_back(analyzer);
00248         }
00249 
00250         // Call the beginRun (which books all the path dependent histograms)
00251         for(std::vector<HLTHiggsPlotter>::iterator it = _analyzers.begin(); 
00252                         it != _analyzers.end(); ++it) 
00253         {
00254                 it->beginRun(iRun, iSetup);
00255         }
00256 
00257         // Book the gen/reco analysis-dependent histograms (denominators)
00258         for(std::map<unsigned int,std::string>::const_iterator it = _recLabels.begin();
00259                         it != _recLabels.end(); ++it)
00260         {
00261                 const std::string objStr = EVTColContainer::getTypeString(it->first);
00262                 std::vector<std::string> sources(2);
00263                 sources[0] = "gen";
00264                 sources[1] = "rec";
00265           
00266                 for(size_t i = 0; i < sources.size(); i++) 
00267                 {
00268                         std::string source = sources[i];
00269                         bookHist(source, objStr, "Eta");
00270                         bookHist(source, objStr, "Phi");
00271                         bookHist(source, objStr, "MaxPt1");
00272                         bookHist(source, objStr, "MaxPt2");
00273                 }
00274         }
00275 }
00276 
00277 
00278 
00279 void HLTHiggsSubAnalysis::analyze(const edm::Event & iEvent, const edm::EventSetup & iSetup, 
00280                 EVTColContainer * cols)
00281 {
00282         // Initialize the collection (the ones which hasn't been initialiazed yet)
00283         this->initobjects(iEvent,cols);
00284         // utility map
00285         std::map<unsigned int,std::string> u2str;
00286         u2str[GEN]="gen";
00287         u2str[RECO]="rec";
00288 
00289         // Extract the match structure containing the gen/reco candidates (electron, muons,...)
00290         // common to all the SubAnalysis
00291         //---- Generation
00292         // Make each good gen object into the base cand for a MatchStruct
00293         std::vector<MatchStruct> * matches = new std::vector<MatchStruct>;
00294 //      bool alreadyMu = false;
00295         for(std::map<unsigned int,std::string>::iterator it = _recLabels.begin();
00296                         it != _recLabels.end(); ++it)
00297         {
00298                 // Avoiding the TkMu and Mu case
00299 /*              if( alreadyMu )
00300                 {
00301                         continue;
00302                 }*/
00303                 // Initialize selectors when first event
00304                 if(!_genSelectorMap[it->first]) 
00305                 {
00306                         _genSelectorMap[it->first] = new StringCutObjectSelector<reco::GenParticle>(_genCut[it->first]);
00307                 }
00308 
00309                 for(size_t i = 0; i < cols->genParticles->size(); ++i)
00310                 {
00311                         if(_genSelectorMap[it->first]->operator()(cols->genParticles->at(i)))
00312                         {
00313                                 matches->push_back(MatchStruct(&cols->genParticles->at(i),it->first));
00314                         }
00315                 }
00316 /*              if( it->first == EVTColContainer::MUON || it->first == EVTColContainer::TRACK )
00317                 {
00318                         alreadyMu = true;
00319                 }*/
00320         }
00321         // Sort the MatchStructs by pT for later filling of turn-on curve
00322         std::sort(matches->begin(), matches->end(), matchesByDescendingPt());
00323         
00324         // Map to reference the source (gen/reco) with the recoCandidates
00325         std::map<unsigned int,std::vector<MatchStruct> > sourceMatchMap;  // To be a pointer to delete
00326         // --- Storing the generating candidates
00327         sourceMatchMap[GEN] = *matches;
00328         
00329         // Reuse the vector
00330         matches->clear();
00331         // --- same for RECO objects
00332         // Extraction of the objects candidates 
00333         for(std::map<unsigned int,std::string>::iterator it = _recLabels.begin();
00334                         it != _recLabels.end(); ++it)
00335         {
00336                 // Reco selectors (the function takes into account if it was instantiated 
00337                 // before or not
00338                 this->InitSelector(it->first);
00339                 // -- Storing the matches 
00340                 this->insertcandidates(it->first,cols,matches);
00341         }
00342         // Sort the MatchStructs by pT for later filling of turn-on curve
00343         std::sort(matches->begin(), matches->end(), matchesByDescendingPt());
00344         // --- Storing the reco candidates
00345         sourceMatchMap[RECO] = *matches;
00346         // --- All the objects are in place
00347         delete matches;  
00348         
00349         // -- Trigger Results
00350         const edm::TriggerNames trigNames = iEvent.triggerNames(*(cols->triggerResults));
00351 
00352         // Filling the histograms if pass the minimum amount of candidates needed by the analysis:
00353         // GEN + RECO CASE in the same loop
00354         for(std::map<unsigned int,std::vector<MatchStruct> >::iterator it = sourceMatchMap.begin(); 
00355                         it != sourceMatchMap.end(); ++it)
00356         {
00357                 // it->first: gen/reco   it->second: matches (std::vector<MatchStruc>)
00358                 if( it->second.size() < _minCandidates )   // FIXME: A bug is potentially here: what about the mixed channels?
00359                 {
00360                         continue;
00361                 }
00362                 
00363                 // Filling the gen/reco objects (eff-denominators): 
00364                 // Just the first two different ones, if there are more
00365                 std::map<unsigned int,int> * countobjects = new std::map<unsigned int,int>;
00366                 // Initializing the count of the used object
00367                 for(std::map<unsigned int,std::string>::iterator co = _recLabels.begin();
00368                                 co != _recLabels.end(); ++co)
00369                 {
00370                         countobjects->insert(std::pair<unsigned int,int>(co->first,0));
00371                 }
00372                 int counttotal = 0;
00373                 const int totalobjectssize2 = 2*countobjects->size();
00374                 for(size_t j = 0; j < it->second.size(); ++j)
00375                 {
00376                         const unsigned int objType = it->second[j].objType;
00377                         const std::string objTypeStr = EVTColContainer::getTypeString(objType);
00378 
00379                         float pt  = (it->second)[j].pt; 
00380                         float eta = (it->second)[j].eta;
00381                         float phi = (it->second)[j].phi;
00382                         
00383                         this->fillHist(u2str[it->first],objTypeStr,"Eta",eta);
00384                         this->fillHist(u2str[it->first],objTypeStr,"Phi",phi);
00385                         if( (*countobjects)[objType] == 0 )
00386                         {
00387                                 this->fillHist(u2str[it->first],objTypeStr,"MaxPt1",pt);
00388                                 // Filled the high pt ...
00389                                 ++((*countobjects)[objType]);
00390                                 ++counttotal;
00391                         }
00392                         else if( (*countobjects)[objType] == 1  )
00393                         {
00394                                 this->fillHist(u2str[it->first],objTypeStr,"MaxPt2",pt);
00395                                 // Filled the second high pt ...
00396                                 ++((*countobjects)[objType]);
00397                                 ++counttotal;
00398                         }
00399                         else
00400                         {
00401                                 // Already the minimum two objects has been filled, get out...
00402                                 if( counttotal == totalobjectssize2 )
00403                                 {
00404                                         break;
00405                                 }
00406                         }                               
00407                 }
00408                 delete countobjects;
00409         
00410                 // Calling to the plotters analysis (where the evaluation of the different trigger paths are done)
00411                 const std::string source = u2str[it->first];
00412                 for(std::vector<HLTHiggsPlotter>::iterator an = _analyzers.begin();
00413                                 an != _analyzers.end(); ++an)
00414                 {
00415                         const std::string hltPath = _shortpath2long[an->gethltpath()];
00416                         const bool ispassTrigger =  cols->triggerResults->accept(trigNames.triggerIndex(hltPath));
00417                         an->analyze(ispassTrigger,source,it->second);
00418                 }
00419         }
00420 }
00421 
00422 // Return the objects (muons,electrons,photons,...) needed by a hlt path. 
00423 const std::vector<unsigned int> HLTHiggsSubAnalysis::getObjectsType(const std::string & hltPath) const
00424 {
00425         static const unsigned int objSize = 5; //6;
00426         static const unsigned int objtriggernames[] = { EVTColContainer::MUON, 
00427                 EVTColContainer::ELEC, 
00428                 EVTColContainer::PHOTON,
00429 //              EVTColContainer::TRACK,  // Note is tracker muon
00430                 EVTColContainer::PFTAU,
00431                 EVTColContainer::CALOMET
00432         };
00433 
00434         std::set<unsigned int> objsType;
00435         // The object to deal has to be entered via the config .py
00436         for(unsigned int i = 0; i < objSize; ++i)
00437         {
00438                 std::string objTypeStr = EVTColContainer::getTypeString( objtriggernames[i] );
00439                 // Check if it is needed this object for this trigger
00440                 if( ! TString(hltPath).Contains(objTypeStr) )
00441                 {
00442                         continue;
00443                 }
00444 
00445                 objsType.insert(objtriggernames[i]);
00446         }
00447 
00448         return std::vector<unsigned int>(objsType.begin(),objsType.end());
00449 }
00450 
00451 
00452 // Booking the maps: recLabels and genParticle selectors
00453 void HLTHiggsSubAnalysis::bookobjects( const edm::ParameterSet & anpset )
00454 {
00455         if( anpset.exists("recMuonLabel") )
00456         {
00457                 _recLabels[EVTColContainer::MUON] = anpset.getParameter<std::string>("recMuonLabel");
00458                 _genSelectorMap[EVTColContainer::MUON] = 0 ;
00459         }
00460         if( anpset.exists("recElecLabel") )
00461         {
00462                 _recLabels[EVTColContainer::ELEC] = anpset.getParameter<std::string>("recElecLabel");
00463                 _genSelectorMap[EVTColContainer::ELEC] = 0 ;
00464         }
00465         if( anpset.exists("recPhotonLabel") )
00466         {
00467                 _recLabels[EVTColContainer::PHOTON] = anpset.getParameter<std::string>("recPhotonLabel");
00468                 _genSelectorMap[EVTColContainer::PHOTON] = 0 ;
00469         }
00470         if( anpset.exists("recCaloMETLabel") )
00471         {
00472                 _recLabels[EVTColContainer::CALOMET] = anpset.getParameter<std::string>("recCaloMETLabel");
00473                 _genSelectorMap[EVTColContainer::CALOMET] = 0 ;
00474         }
00475         if( anpset.exists("recPFTauLabel") )
00476         {
00477                 _recLabels[EVTColContainer::PFTAU] = anpset.getParameter<std::string>("recPFTauLabel");
00478                 _genSelectorMap[EVTColContainer::PFTAU] = 0 ;
00479         }
00480         /*if( anpset.exists("recTrackLabel") )
00481         {
00482                 _recLabels[EVTColContainer::TRACK] = anpset.getParameter<std::string>("recTrackLabel");
00483                 _genSelectorMap[EVTColContainer::TRACK] = 0 ;
00484         }*/
00485 
00486         if( _recLabels.size() < 1 )
00487         {
00488                 edm::LogError("HiggsValidation") << "HLTHiggsSubAnalysis::bookobjects, " 
00489                 << "Not included any object (recMuonLabel, recElecLabel, ...)  "
00490                 << "in the analysis " << _analysisname;
00491                 return;
00492         }
00493 }
00494 
00495 void HLTHiggsSubAnalysis::initobjects(const edm::Event & iEvent, EVTColContainer * col)
00496 {
00497         /*if( col != 0 && col->isAllInit() )
00498         {
00499                 // Already init, not needed to do nothing
00500                 return;
00501         }*/
00502         if( ! col->isCommonInit() )
00503         {
00504                 // TO BE DEPRECATED AS we don't need it anymore.
00505                 // There is no match with HLT candidates... Use, then TriggerResults
00506                 /*edm::Handle<trigger::TriggerEventWithRefs> rawTEH;
00507                 iEvent.getByLabel("hltTriggerSummaryRAW",rawTEH);
00508                 if(rawTEH.failedToGet())
00509                 {
00510                         edm::LogError("HiggsValidation") << "HLTHiggsSubAnalysis::initobjecst, "
00511                                 << "No trigger summary found"; 
00512                         return;
00513                 }
00514                 col->rawTriggerEvent = rawTEH.product();*/
00515                 // END-- TO BE DEPRECATED
00516         
00517                 // extract the trigger results (path info, pass,...)
00518                 edm::Handle<edm::TriggerResults> trigResults;
00519                 edm::InputTag trigResultsTag("TriggerResults","",_hltProcessName);
00520                 iEvent.getByLabel(trigResultsTag,trigResults);
00521                 if( trigResults.isValid() )
00522                 {
00523                         col->triggerResults = trigResults.product();
00524                 }
00525 
00526                 // GenParticle collection if is there
00527                 edm::Handle<reco::GenParticleCollection> genPart;
00528                 iEvent.getByLabel(_genParticleLabel,genPart);
00529                 if( genPart.isValid() )
00530                 {
00531                         col->genParticles = genPart.product();
00532                 }
00533         }
00534                 
00535         for(std::map<unsigned int,std::string>::iterator it = _recLabels.begin(); 
00536                         it != _recLabels.end(); ++it)
00537         {
00538                 if( it->first == EVTColContainer::MUON )
00539                 {
00540                         edm::Handle<reco::MuonCollection> theHandle;
00541                         iEvent.getByLabel(it->second, theHandle);
00542                         col->set(theHandle.product());
00543                 }
00544                 else if( it->first == EVTColContainer::ELEC )
00545                 {
00546                         edm::Handle<reco::GsfElectronCollection> theHandle;
00547                         iEvent.getByLabel(it->second, theHandle);
00548                         col->set(theHandle.product());
00549                 }
00550                 else if( it->first == EVTColContainer::PHOTON )
00551                 {
00552                         edm::Handle<reco::PhotonCollection> theHandle;
00553                         iEvent.getByLabel(it->second, theHandle);
00554                         col->set(theHandle.product());
00555                 }
00556                 else if( it->first == EVTColContainer::CALOMET )
00557                 {
00558                         edm::Handle<reco::CaloMETCollection> theHandle;
00559                         iEvent.getByLabel(it->second, theHandle);
00560                         col->set(theHandle.product());
00561                 }
00562                 else if( it->first == EVTColContainer::PFTAU )
00563                 {
00564                         edm::Handle<reco::PFTauCollection> theHandle;
00565                         iEvent.getByLabel(it->second, theHandle);
00566                         col->set(theHandle.product());
00567                 }
00568 /*              else if( it->first == EVTColContainer::TRACK )
00569                 {
00570                         edm::Handle<reco::TrackCollection> theHandle;
00571                         iEvent.getByLabel(it->second, theHandle);
00572                         col->set(theHandle.product());
00573                 }*/
00574                 else
00575                 {
00576                         edm::LogError("HiggsValidation") << "HLTHiggsSubAnalysis::initobjects " 
00577                                 << " NOT IMPLEMENTED (yet) ERROR: '" << it->second << "'";
00578                         //return; ??
00579                 }
00580         }
00581 }
00582 
00583 void HLTHiggsSubAnalysis::bookHist(const std::string & source, 
00584                 const std::string & objType, const std::string & variable)
00585 {
00586         std::string sourceUpper = source; 
00587         sourceUpper[0] = std::toupper(sourceUpper[0]);
00588         std::string name = source + objType + variable ;
00589         TH1F * h = 0;
00590 
00591         if(variable.find("MaxPt") != std::string::npos) 
00592         {
00593                 std::string desc = (variable == "MaxPt1") ? "Leading" : "Next-to-Leading";
00594                 std::string title = "pT of " + desc + " " + sourceUpper + " " + objType;
00595                 const size_t nBins = _parametersTurnOn.size() - 1;
00596                 float * edges = new float[nBins + 1];
00597                 for(size_t i = 0; i < nBins + 1; i++)
00598                 {
00599                         edges[i] = _parametersTurnOn[i];
00600                 }
00601                 h = new TH1F(name.c_str(), title.c_str(), nBins, edges);
00602                 delete edges;
00603         }
00604         else 
00605         {
00606                 std::string symbol = (variable == "Eta") ? "#eta" : "#phi";
00607                 std::string title  = symbol + " of " + sourceUpper + " " + objType;
00608                 std::vector<double> params = (variable == "Eta") ? _parametersEta : _parametersPhi;
00609 
00610                 int    nBins = (int)params[0];
00611                 double min   = params[1];
00612                 double max   = params[2];
00613                 h = new TH1F(name.c_str(), title.c_str(), nBins, min, max);
00614         }
00615         h->Sumw2();
00616         _elements[name] = _dbe->book1D(name, h);
00617         delete h;
00618 }
00619 
00620 void HLTHiggsSubAnalysis::fillHist(const std::string & source, 
00621                 const std::string & objType, const std::string & variable, const float & value )
00622 {
00623         std::string sourceUpper = source; 
00624         sourceUpper[0] = toupper(sourceUpper[0]);
00625         std::string name = source + objType + variable ;
00626 
00627         _elements[name]->Fill(value);
00628 }
00629 
00630 
00631 
00632 // Initialize the selectors
00633 void HLTHiggsSubAnalysis::InitSelector(const unsigned int & objtype)
00634 {       
00635         if( objtype == EVTColContainer::MUON && _recMuonSelector == 0 )
00636         {
00637                 _recMuonSelector = new StringCutObjectSelector<reco::Muon>(_recCut[objtype]);
00638         }
00639         else if( objtype == EVTColContainer::ELEC && _recElecSelector == 0)
00640         {
00641                 _recElecSelector = new StringCutObjectSelector<reco::GsfElectron>(_recCut[objtype]);
00642         }
00643         else if( objtype == EVTColContainer::PHOTON && _recPhotonSelector == 0)
00644         {
00645                 _recPhotonSelector = new StringCutObjectSelector<reco::Photon>(_recCut[objtype]);
00646         }
00647         else if( objtype == EVTColContainer::CALOMET && _recCaloMETSelector == 0)
00648         {
00649                 _recCaloMETSelector = new StringCutObjectSelector<reco::CaloMET>(_recCut[objtype]);
00650         }
00651         else if( objtype == EVTColContainer::PFTAU && _recPFTauSelector == 0 )
00652         {
00653                 _recPFTauSelector = new StringCutObjectSelector<reco::PFTau>(_recCut[objtype]);
00654         }
00655         /*else if( objtype == EVTColContainer::TRACK && _recTrackSelector == 0)
00656         {
00657                 _recTrackSelector = new StringCutObjectSelector<reco::Track>(_recCut[objtype]);
00658         }*/
00659 /*      else
00660         {
00661 FIXME: ERROR NO IMPLEMENTADO
00662         }*/
00663 }
00664 
00665 void HLTHiggsSubAnalysis::insertcandidates(const unsigned int & objType, const EVTColContainer * cols, 
00666                 std::vector<MatchStruct> * matches)
00667 {
00668         if( objType == EVTColContainer::MUON )
00669         {
00670                 for(size_t i = 0; i < cols->muons->size(); i++)
00671                 {
00672                         if(_recMuonSelector->operator()(cols->muons->at(i)))
00673                         {
00674                                 matches->push_back(MatchStruct(&cols->muons->at(i),objType));
00675                         }
00676                 }
00677         }
00678         else if( objType == EVTColContainer::ELEC )
00679         {
00680                 for(size_t i = 0; i < cols->electrons->size(); i++)
00681                 {
00682                         if(_recElecSelector->operator()(cols->electrons->at(i)))
00683                         {
00684                                 matches->push_back(MatchStruct(&cols->electrons->at(i),objType));
00685                         }
00686                 }
00687         }
00688         else if( objType == EVTColContainer::PHOTON )
00689         {
00690                 for(size_t i = 0; i < cols->photons->size(); i++)
00691                 {
00692                         if(_recPhotonSelector->operator()(cols->photons->at(i)))
00693                         {
00694                                 matches->push_back(MatchStruct(&cols->photons->at(i),objType));
00695                         }
00696                 }
00697         }
00698         else if( objType == EVTColContainer::CALOMET )
00699         {
00700                 for(size_t i = 0; i < cols->caloMETs->size(); i++)
00701                 {
00702                         if(_recCaloMETSelector->operator()(cols->caloMETs->at(i)))
00703                         {
00704                                 matches->push_back(MatchStruct(&cols->caloMETs->at(i),objType));
00705                         }
00706                 }
00707         }
00708         else if( objType == EVTColContainer::PFTAU )
00709         {
00710                 for(size_t i = 0; i < cols->pfTaus->size(); i++)
00711                 {
00712                         if(_recPFTauSelector->operator()(cols->pfTaus->at(i)))
00713                         {
00714                                 matches->push_back(MatchStruct(&cols->pfTaus->at(i),objType));
00715                         }
00716                 }
00717         }
00718         /*else if( objType == EVTColContainer::TRACK )
00719         {
00720                 for(size_t i = 0; i < cols->tracks->size(); i++)
00721                 {
00722                         if(_recTrackSelector->operator()(cols->tracks->at(i)))
00723                         {
00724                                 matches->push_back(MatchStruct(&cols->tracks->at(i),objType));
00725                         }
00726                 }
00727         }*/
00728         /*
00729         else FIXME: Control errores
00730         {
00731         }
00732         */
00733 }