File indexing completed on 2024-04-06 12:08:45
0001 #include <Riostream.h>
0002 #include <TDirectory.h>
0003 #include <TFile.h>
0004 #include <TKey.h>
0005 #include <TH1.h>
0006 #include <TXMLEngine.h>
0007
0008 #include <string>
0009 #include <vector>
0010 #include <map>
0011
0012 bool goToDir(TDirectory* top_dir, string dname);
0013 void findHistoParameters(TDirectory* top_dir, vector<string>& names, string& tag,
0014 TXMLEngine* xml_engine,XMLNodePointer_t& mainnode);
0015
0016 void sistrip_extract_dataquality(string fname) {
0017
0018 TFile* file = new TFile(fname.c_str());
0019 if (!file || !file->IsOpen()) return;
0020
0021 TDirectory* topDir = dynamic_cast<TDirectory*>( file->Get("DQMData"));
0022 goToDir(topDir, "SiStrip");
0023 TDirectory* stripDir = gDirectory;
0024
0025 TIter next(stripDir->GetListOfKeys());
0026 TKey *key;
0027 while ( (key = dynamic_cast<TKey*>(next())) ) {
0028 string clName(key->GetClassName());
0029 if (clName == "TDirectoryFile") {
0030 TDirectory *curr_dir = dynamic_cast<TDirectory*>(key->ReadObj());
0031 string name = curr_dir->GetName();
0032 if (name == "Run summary"){
0033 curr_dir->cd();
0034 break;
0035 }
0036 }
0037 }
0038 TDirectory* rsDir = gDirectory;
0039
0040
0041 TXMLEngine* xml = new TXMLEngine;
0042
0043 XMLNodePointer_t mainnode = xml->NewChild(0, 0, "main");
0044
0045 vector<string> hnames;
0046 string tag;
0047
0048 tag = "Tracks";
0049 hnames.push_back("Tracks/NumberOfTracks_CKFTk");
0050 hnames.push_back("Tracks/NumberOfRecHitsPerTrack_CKFTk");
0051 findHistoParameters(rsDir, hnames, tag, xml, mainnode);
0052
0053 hnames.clear();
0054 tag = "TEC";
0055 hnames.push_back("MechanicalView/TEC/Summary_TotalNumberOfClusters_OnTrack_in_TEC");
0056 hnames.push_back("MechanicalView/TEC/Summary_TotalNumberOfClusters_OffTrack_in_TEC");
0057 hnames.push_back("MechanicalView/TEC/Summary_ClusterStoNCorr_OnTrack_in_TEC");
0058 hnames.push_back("MechanicalView/TEC/Summary_ClusterCharge_OffTrack_in_TEC");
0059 findHistoParameters(rsDir, hnames, tag, xml, mainnode);
0060
0061 hnames.clear();
0062 tag = "TIB";
0063 hnames.push_back("MechanicalView/TIB/Summary_TotalNumberOfClusters_OnTrack_in_TIB");
0064 hnames.push_back("MechanicalView/TIB/Summary_TotalNumberOfClusters_OffTrack_in_TIB");
0065 hnames.push_back("MechanicalView/TIB/Summary_ClusterCharge_OffTrack_in_TIB");
0066 hnames.push_back("MechanicalView/TIB/Summary_ClusterStoNCorr_OnTrack_in_TIB");
0067 findHistoParameters(rsDir, hnames, tag, xml, mainnode);
0068
0069 hnames.clear();
0070 tag = "TOB";
0071 hnames.push_back("MechanicalView/TOB/Summary_TotalNumberOfClusters_OnTrack_in_TOB");
0072 hnames.push_back("MechanicalView/TOB/Summary_TotalNumberOfClusters_OffTrack_in_TOB");
0073 hnames.push_back("MechanicalView/TOB/Summary_ClusterStoNCorr_OnTrack_in_TOB");
0074 hnames.push_back("MechanicalView/TOB/Summary_ClusterCharge_OffTrack_in_TOB");
0075 findHistoParameters(rsDir, hnames, tag, xml, mainnode);
0076
0077 hnames.clear();
0078 tag = "TID";
0079 hnames.push_back("MechanicalView/TID/Summary_TotalNumberOfClusters_OffTrack_in_TID");
0080 hnames.push_back("MechanicalView/TID/Summary_TotalNumberOfClusters_OnTrack_in_TID");
0081 hnames.push_back("MechanicalView/TID/Summary_ClusterStoNCorr_OnTrack_in_TID");
0082 hnames.push_back("MechanicalView/TID/Summary_ClusterCharge_OffTrack_in_TID");
0083 findHistoParameters(rsDir, hnames, tag, xml, mainnode);
0084
0085
0086 file->Close();
0087
0088
0089 XMLDocPointer_t xmldoc = xml->NewDoc();
0090 xml->DocSetRootElement(xmldoc, mainnode);
0091
0092
0093 xml->SaveDoc(xmldoc, "sistrip_report.xml");
0094
0095
0096 xml->FreeDoc(xmldoc);
0097 delete xml;
0098 }
0099
0100 void findHistoParameters(TDirectory* top_dir,vector<string>& hnames, string& tag,
0101 TXMLEngine* xml_engine, XMLNodePointer_t& mainnode){
0102 char mval[10];
0103 char rval[10];
0104 string dir_name = top_dir->GetTitle();
0105 cout << " ======================= " << tag << " ======================= " << endl;
0106
0107 for (vector<string>::iterator it = hnames.begin(); it != hnames.end(); it++) {
0108 TH1* th1 = dynamic_cast<TH1*>(gDirectory->Get((*it).c_str()));
0109 if (th1) {
0110 sprintf(mval,"%.2f",th1->GetMean());
0111 sprintf(rval,"%.2f",th1->GetRMS());
0112 XMLNodePointer_t child = xml_engine->NewChild(mainnode, 0, tag.c_str());
0113 xml_engine->NewAttr(child, 0, "Name", th1->GetName());
0114 xml_engine->NewAttr(child, 0, "Mean", mval);
0115 xml_engine->NewAttr(child, 0, "RMS", rval);
0116 cout << th1->GetName() << " Mean " << mval << " RMS " << rval << endl;
0117 }
0118 }
0119 cout << endl;
0120 }
0121 bool goToDir(TDirectory* top_dir, string dname){
0122 string dir_name = top_dir->GetTitle();
0123 if (dir_name == dname) {
0124 return true;
0125 } else {
0126 TIter next(top_dir->GetListOfKeys());
0127 TKey *key;
0128 while ( (key = dynamic_cast<TKey*>(next())) ) {
0129 string clName(key->GetClassName());
0130 if (clName == "TDirectoryFile") {
0131 TDirectory *curr_dir = dynamic_cast<TDirectory*>(key->ReadObj());
0132 string name = curr_dir->GetName();
0133 if (name == "Reference") continue;
0134 curr_dir->cd();
0135 if (goToDir(curr_dir, dname)) return true;
0136 curr_dir->cd("..");
0137 }
0138 }
0139 }
0140 return false;
0141 }