CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DQMGenericTnPClient.cc
Go to the documentation of this file.
11 
13 
14 #include<TString.h>
15 #include<TPRegexp.h>
16 
17 using namespace edm;
18 using namespace dqmTnP;
19 using namespace std;
20 
21 
22 typedef std::vector<std::string> vstring;
23 
25  public:
27  virtual ~DQMGenericTnPClient();
28  virtual void analyze(const edm::Event& event, const edm::EventSetup& eventSetup) override {};
29  virtual void endRun(const edm::Run &run, const edm::EventSetup &setup) override;
30  void calculateEfficiency(std::string dirName, const ParameterSet& pset);
31  void findAllSubdirectories (std::string dir, std::set<std::string> * myList, TString pattern);
32  private:
34  TFile * plots;
37  bool verbose;
41 };
42 
44  subDirs( pset.getUntrackedParameter<vstring>("subDirs", vstring()) ),
45  myDQMrootFolder( pset.getUntrackedParameter<std::string>("MyDQMrootFolder", "") ),
46  verbose( pset.getUntrackedParameter<bool>("Verbose",false) ),
47  efficiencies( pset.getUntrackedParameter<VParameterSet>("Efficiencies") )
48 {
49  TString savePlotsInRootFileName = pset.getUntrackedParameter<string>("SavePlotsInRootFileName","");
50  plots = savePlotsInRootFileName!="" ? new TFile(savePlotsInRootFileName,"recreate") : 0;
53 }
54 
56 
57  TPRegexp metacharacters("[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]");
58 
60  if( !dqmStore ){
61  LogError("DQMGenericTnPClient")<<"Could not find DQMStore service\n";
62  return;
63  }
64  dqmStore->setCurrentFolder(myDQMrootFolder);
65 
66  set<std::string> subDirSet;
67 
68  if (myDQMrootFolder != "")
69  subDirSet.insert(myDQMrootFolder);
70  else {
71  for(vstring::const_iterator iSubDir = subDirs.begin();
72  iSubDir != subDirs.end(); ++iSubDir) {
73  std::string subDir = *iSubDir;
74  if ( subDir[subDir.size()-1] == '/' ) subDir.erase(subDir.size()-1);
75  if ( TString(subDir).Contains(metacharacters) ) {
76  const string::size_type shiftPos = subDir.rfind('/');
77  const string searchPath = subDir.substr(0, shiftPos);
78  const string pattern = subDir.substr(shiftPos + 1, subDir.length());
79  findAllSubdirectories (searchPath, &subDirSet, pattern);
80  }
81  else {
82  subDirSet.insert(subDir);
83  }
84  }
85  }
86 
87  for(set<string>::const_iterator iSubDir = subDirSet.begin();
88  iSubDir != subDirSet.end(); ++iSubDir) {
89  const string& dirName = *iSubDir;
90  for(VParameterSet::const_iterator pset = efficiencies.begin();
91  pset != efficiencies.end(); ++pset) {
92  calculateEfficiency(dirName, *pset);
93  }
94  }
95 
96 }
97 
99  //get hold of numerator and denominator histograms
100  string allMEname = dirName+"/"+pset.getUntrackedParameter<string>("DenominatorMEname");
101  string passMEname = dirName+"/"+pset.getUntrackedParameter<string>("NumeratorMEname");
102  MonitorElement *allME = dqmStore->get(allMEname);
103  MonitorElement *passME = dqmStore->get(passMEname);
104  if(allME==0 || passME==0){
105  LogDebug("DQMGenericTnPClient")<<"Could not find MEs: "<<allMEname<<" or "<<passMEname<<endl;
106  return;
107  }
108  TH1 *all = allME->getTH1();
109  TH1 *pass = passME->getTH1();
110  //setup the fitter
111  string fitFunction = pset.getUntrackedParameter<string>("FitFunction");
112  AbstractFitter *fitter = 0;
113  if(fitFunction=="GaussianPlusLinear"){
114  GPLfitter->setup(
115  pset.getUntrackedParameter<double>("ExpectedMean"),
116  pset.getUntrackedParameter<double>("FitRangeLow"),
117  pset.getUntrackedParameter<double>("FitRangeHigh"),
118  pset.getUntrackedParameter<double>("ExpectedSigma")
119  );
120  fitter = GPLfitter;
121  }else if(fitFunction=="VoigtianPlusExponential"){
122  VPEfitter->setup(
123  pset.getUntrackedParameter<double>("ExpectedMean"),
124  pset.getUntrackedParameter<double>("FitRangeLow"),
125  pset.getUntrackedParameter<double>("FitRangeHigh"),
126  pset.getUntrackedParameter<double>("ExpectedSigma"),
127  pset.getUntrackedParameter<double>("FixedWidth")
128  );
129  fitter = VPEfitter;
130  }else{
131  LogError("DQMGenericTnPClient")<<"Fit function: "<<fitFunction<<" does not exist"<<endl;
132  return;
133  }
134  //check dimensions
135  int dimensions = all->GetDimension();
136  int massDimension = pset.getUntrackedParameter<int>("MassDimension");
137  if(massDimension>dimensions){
138  LogError("DQMGenericTnPClient")<<"Monitoring Element "<<allMEname<<" has smaller dimension than "<<massDimension<<endl;
139  return;
140  }
141  //figure out directory and efficiency names
142  string effName = pset.getUntrackedParameter<string>("EfficiencyMEname");
143  string effDir = dirName;
144  string::size_type slashPos = effName.rfind('/');
145  if ( string::npos != slashPos ) {
146  effDir += "/"+effName.substr(0, slashPos);
147  effName.erase(0, slashPos+1);
148  }
149  dqmStore->setCurrentFolder(effDir);
150  TString prefix(effDir.c_str());
151  prefix.ReplaceAll('/','_');
152  //calculate and book efficiency
153  if(dimensions==2){
154  TProfile* eff = 0;
155  TProfile* effChi2 = 0;
156  TString error = fitter->calculateEfficiency((TH2*)pass, (TH2*)all, massDimension, eff, effChi2, plots?prefix+effName.c_str():"");
157  if(error!=""){
158  LogError("DQMGenericTnPClient")<<error<<endl;
159  return;
160  }
161  dqmStore->bookProfile(effName,eff);
162  dqmStore->bookProfile(effName+"Chi2",effChi2);
163  delete eff;
164  delete effChi2;
165  }else if(dimensions==3){
166  TProfile2D* eff = 0;
167  TProfile2D* effChi2 = 0;
168  TString error = fitter->calculateEfficiency((TH3*)pass, (TH3*)all, massDimension, eff, effChi2, plots?prefix+effName.c_str():"");
169  if(error!=""){
170  LogError("DQMGenericTnPClient")<<error<<endl;
171  return;
172  }
173  dqmStore->bookProfile2D(effName,eff);
174  dqmStore->bookProfile2D(effName+"Chi2",effChi2);
175  delete eff;
176  delete effChi2;
177  }
178 }
179 
181  delete GPLfitter;
182  if(plots){
183  plots->Close();
184  }
185 }
186 
187 void DQMGenericTnPClient::findAllSubdirectories (std::string dir, std::set<std::string> * myList, TString pattern = "") {
188  if (!dqmStore->dirExists(dir)) {
189  LogError("DQMGenericTnPClient") << " DQMGenericTnPClient::findAllSubdirectories ==> Missing folder " << dir << " !!!";
190  return;
191  }
192  TPRegexp nonPerlWildcard("\\w\\*|^\\*");
193  if (pattern != "") {
194  if (pattern.Contains(nonPerlWildcard)) pattern.ReplaceAll("*",".*");
195  TPRegexp regexp(pattern);
196  dqmStore->cd(dir);
197  vector <string> foundDirs = dqmStore->getSubdirs();
198  for(vector<string>::const_iterator iDir = foundDirs.begin();
199  iDir != foundDirs.end(); ++iDir) {
200  TString dirName = iDir->substr(iDir->rfind('/') + 1, iDir->length());
201  if (dirName.Contains(regexp))
202  findAllSubdirectories ( *iDir, myList);
203  }
204  }
205  else if (dqmStore->dirExists(dir)){
206  myList->insert(dir);
207  dqmStore->cd(dir);
208  findAllSubdirectories (dir, myList, "*");
209  } else {
210 
211  LogInfo ("DQMGenericClient") << "Trying to find sub-directories of " << dir
212  << " failed because " << dir << " does not exist";
213 
214  }
215  return;
216 }
217 
218 
219 //define this as a plug-in
#define LogDebug(id)
T getUntrackedParameter(std::string const &, T const &) const
GaussianPlusLinearFitter * GPLfitter
vector< string > vstring
Definition: ExoticaDQM.cc:86
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
virtual void endRun(const edm::Run &run, const edm::EventSetup &setup) override
TPRegexp metacharacters("[\\^\\$\\.\\*\\+\\?\\|\\(\\)\\{\\}\\[\\]]")
void setup(double expectedMean_, double massLow, double massHigh, double expectedSigma_)
list pattern
Definition: chain.py:104
uint16_t size_type
void setup(double expectedMean_, double massLow, double massHigh, double expectedSigma_, double width_)
DQMGenericTnPClient(const edm::ParameterSet &pset)
VoigtianPlusExponentialFitter * VPEfitter
TH1 * getTH1(void) const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
TPRegexp nonPerlWildcard("\\w\\*|^\\*")
void calculateEfficiency(std::string dirName, const ParameterSet &pset)
dbl *** dir
Definition: mlp_gen.cc:35
volatile std::atomic< bool > shutdown_flag false
const VParameterSet efficiencies
virtual void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
std::vector< std::string > vstring
Definition: Schedule.cc:354
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:41
void findAllSubdirectories(std::string dir, std::set< std::string > *myList, TString pattern)