//--- Print all created canvasses --- void printAllCanvases(const char* folder="plots") { TSeqCollection * sc = dynamic_cast<TSeqCollection*>(gROOT->GetListOfCanvases()); for (int i =0; i<sc->GetSize(); ++i) { TCanvas * c = dynamic_cast<TCanvas*>(sc->At(i)); TString cname(c->GetName()); printf("Canvas: %s/%s.gif\n",folder,cname.Data()); c->Print(Form("%s/%s.gif",folder,cname.Data())); } }
void SelectCanvas() { notDeleted = kTRUE; toolcanvas->cd(); Double_t buttonheight = 50; TSeqCollection *li = gROOT->GetListOfCanvases(); Int_t nentries = li->GetEntries(); Int_t count=0; if (nentries==1) return; toolcanvas->GetListOfPrimitives()->Remove(enlarge); toolcanvas->SetWindowSize(toolw,nentries*buttonheight); toolcanvas->Modified(); toolcanvas->Update(); pt1->SetY1NDC(1.0-1.0/nentries); pt1->Draw(); toolcanvas->Update(); b = new TObjArray(nentries-1); for (Int_t i=0; i<nentries; i++) { if (strcmp(li->At(i)->GetName(),"tools")!=0) { b->Add(new TButton(li->At(i)->GetName(),Form("Pick(%i);",i),0,(1-(count+1.)/nentries),1,(1-(count+2.)/nentries))); b->At(count)->Draw(); count++; } } toolcanvas->Modified(); toolcanvas->Update(); }
//------------------------------------------------------------------------------------------------- void makeHeaderFile(TFile *f, const string& treeName, bool paranoid, const string& Classname, const string& nameSpace, const string& objName) { headerf << "// -*- C++ -*-" << endl; headerf << "#ifndef " << Classname << "_H" << endl; headerf << "#define " << Classname << "_H" << endl; headerf << "#include \"Math/LorentzVector.h\"" << endl; headerf << "#include \"Math/Point3D.h\"" << endl; headerf << "#include \"TMath.h\"" << endl; headerf << "#include \"TBranch.h\"" << endl; headerf << "#include \"TTree.h\"" << endl; headerf << "#include \"TH1F.h\"" << endl; headerf << "#include \"TFile.h\"" << endl; headerf << "#include \"TBits.h\"" << endl; headerf << "#include <vector>" << endl; headerf << "#include <unistd.h>" << endl; headerf << "typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;" << endl << endl; if (paranoid) headerf << "#define PARANOIA" << endl << endl; headerf << "using namespace std; " << endl; headerf << "class " << Classname << " {" << endl; headerf << "private: " << endl; headerf << "protected: " << endl; headerf << "\tunsigned int index;" << endl; // TTree *ev = (TTree*)f->Get("Events"); TList* list_of_keys = f->GetListOfKeys(); std::string tree_name = ""; if (treeName.empty()) { unsigned int ntrees = 0; for (unsigned int idx = 0; idx < (unsigned int)list_of_keys->GetSize(); idx++) { const char* obj_name = list_of_keys->At(idx)->GetName(); TObject* obj = f->Get(obj_name); if (obj->InheritsFrom("TTree")) { ++ntrees; tree_name = obj_name; } } if (ntrees == 0) { std::cout << "Did not find a tree. Exiting." << std::endl; return; } if (ntrees > 1) { std::cout << "Found more than one tree. Please specify a tree to use." << std::endl; return; } } else tree_name = treeName; TTree *ev = (TTree*)f->Get(tree_name.c_str()); TSeqCollection *fullarray = ev->GetListOfAliases(); bool have_aliases = true; if (!fullarray) { have_aliases = false; fullarray = ev->GetListOfBranches(); } // if (have_aliases && fullarray->GetSize() != ev->GetListOfBranches()->GetSize()) { // std::cout << "Tree has " << fullarray->GetSize() << " aliases and " << ev->GetListOfBranches()->GetSize() << " branches. Exiting." << std::endl; // return; // } TList *aliasarray = new TList(); for(Int_t i = 0; i < fullarray->GetEntries(); ++i) { TString aliasname(fullarray->At(i)->GetName()); // TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); TBranch *branch = 0; if (have_aliases) branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); else branch = (TBranch*)fullarray->At(i); TString branchname(branch->GetName()); TString branchtitle(branch->GetTitle()); TString branchclass(branch->GetClassName()); if(!branchname.BeginsWith("int") && !branchname.BeginsWith("uint") && !branchname.BeginsWith("bool") && !branchname.BeginsWith("float") && !branchname.BeginsWith("double") && !branchtitle.EndsWith("/F") && !branchtitle.EndsWith("/I") && !branchtitle.EndsWith("/i") && !branchtitle.EndsWith("/O") && !branchtitle.BeginsWith("TString") && !branchtitle.BeginsWith("TBits") && !branchclass.Contains("LorentzVector") && !branchclass.Contains("int") && !branchclass.Contains("uint") && !branchclass.Contains("bool") && !branchclass.Contains("float") && !branchclass.Contains("double") && !branchclass.Contains("TString")) continue; // if (branchclass.Contains("TString")) // { // std::cout << "Adding branch " << branchtitle.Data() << " to list." << std::endl; // std::cout.flush(); // } aliasarray->Add(fullarray->At(i)); } for(Int_t i = 0; i< aliasarray->GetEntries(); ++i) { //Class name is blank for a int of float TString aliasname(aliasarray->At(i)->GetName()); // TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); TBranch *branch = 0; if (have_aliases) branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); else branch = (TBranch*)aliasarray->At(i); TString classname = branch->GetClassName(); TString title = branch->GetTitle(); if ( classname.Contains("vector") ) { if(classname.Contains("edm::Wrapper<") ) { classname = classname(0,classname.Length()-2); classname.ReplaceAll("edm::Wrapper<",""); headerf << "\t" << classname << " " << aliasname << "_;" << endl; } //else if (classname.Contains("TString") || classname.Contains("vector<float>")) { else if (classname.Contains("TString")) { headerf << "\t" << classname << " " << aliasname << "_;" << endl; } else { headerf << "\t" << classname << " *" << aliasname << "_;" << endl; } } else { if(classname != "" ) { //LorentzVector if(classname.Contains("edm::Wrapper<") ) { classname = classname(0,classname.Length()-1); classname.ReplaceAll("edm::Wrapper<",""); headerf << "\t" << classname << " " << aliasname << "_;" << endl; } //else if (classname.Contains("TString") || classname.Contains("vector<float>")) { else if (classname.Contains("TString")) { headerf << "\t" << classname << " " << aliasname << "_;" << endl; } else { headerf << "\t" << classname << " *" << aliasname << "_;" << endl; } } else { if(title.EndsWith("/i")) headerf << "\tunsigned int" << "\t" << aliasname << "_;" << endl; if(title.EndsWith("/F")) headerf << "\tfloat" << "\t" << aliasname << "_;" << endl; if(title.EndsWith("/I")) headerf << "\tint" << "\t" << aliasname << "_;" << endl; if(title.EndsWith("/O")) headerf << "\tbool" << "\t" << aliasname << "_;" << endl; } } headerf << "\tTBranch *" << Form("%s_branch",aliasname.Data()) << ";" << endl; headerf << "\tbool " << Form("%s_isLoaded",aliasname.Data()) << ";" << endl; } headerf << "public: " << endl; headerf << "void Init(TTree *tree) {" << endl; // SetBranchAddresses for LorentzVectors // TBits also needs SetMakeClass(0)... for(Int_t i = 0; i< aliasarray->GetEntries(); i++) { TString aliasname(aliasarray->At(i)->GetName()); // TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); TBranch *branch = 0; if (have_aliases) branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); else branch = (TBranch*)aliasarray->At(i); TString classname = branch->GetClassName(); TString branch_ptr = Form("%s_branch",aliasname.Data()); if ( !classname.Contains("vector<vector") ) { if ( classname.Contains("Lorentz") || classname.Contains("PositionVector") || classname.Contains("TBits")) { headerf << "\t" << Form("%s_branch",aliasname.Data()) << " = 0;" << endl; if (have_aliases) { headerf << "\t" << "if (tree->GetAlias(\"" << aliasname << "\") != 0) {" << endl; headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(tree->GetAlias(\"" << aliasname << "\"));" << endl; //headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; headerf << Form("\t\tif (%s) {%s->SetAddress(&%s_);}\n\t}", branch_ptr.Data(), branch_ptr.Data(), aliasname.Data()) << endl; } else { headerf << "\t" << "if (tree->GetBranch(\"" << aliasname << "\") != 0) {" << endl; headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(\"" << aliasname << "\");" << endl; //headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; headerf << Form("\t\tif (%s) {%s->SetAddress(&%s_);}\n\t}", branch_ptr.Data(), branch_ptr.Data(), aliasname.Data()) << endl; } } } } // SetBranchAddresses for everything else headerf << " tree->SetMakeClass(1);" << endl; for(Int_t i = 0; i< aliasarray->GetEntries(); i++) { TString aliasname(aliasarray->At(i)->GetName()); // TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); TBranch *branch = 0; if (have_aliases) branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); else branch = (TBranch*)aliasarray->At(i); TString classname = branch->GetClassName(); TString branch_ptr = Form("%s_branch",aliasname.Data()); if ( ! (classname.Contains("Lorentz") || classname.Contains("PositionVector") || classname.Contains("TBits")) || classname.Contains("vector<vector") ) { headerf << "\t" << Form("%s_branch",aliasname.Data()) << " = 0;" << endl; if (have_aliases) { headerf << "\t" << "if (tree->GetAlias(\"" << aliasname << "\") != 0) {" << endl; headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(tree->GetAlias(\"" << aliasname << "\"));" << endl; //headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; headerf << Form("\t\tif (%s) {%s->SetAddress(&%s_);}\n\t}", branch_ptr.Data(), branch_ptr.Data(), aliasname.Data()) << endl; } else { headerf << "\t" << "if (tree->GetBranch(\"" << aliasname << "\") != 0) {" << endl; headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << " = tree->GetBranch(\"" << aliasname << "\");" << endl; //headerf << "\t\t" << Form("%s_branch",aliasname.Data()) << "->SetAddress(&" << aliasname << "_);" << endl << "\t}" << endl; headerf << Form("\t\tif (%s) {%s->SetAddress(&%s_);}\n\t}", branch_ptr.Data(), branch_ptr.Data(), aliasname.Data()) << endl; } } } headerf << " tree->SetMakeClass(0);" << endl; headerf << "}" << endl; // GetEntry headerf << "void GetEntry(unsigned int idx) " << endl; headerf << "\t// this only marks branches as not loaded, saving a lot of time" << endl << "\t{" << endl; headerf << "\t\tindex = idx;" << endl; for(Int_t i = 0; i< aliasarray->GetEntries(); i++) { TString aliasname(aliasarray->At(i)->GetName()); headerf << "\t\t" << Form("%s_isLoaded",aliasname.Data()) << " = false;" << endl; } headerf << "\t}" << endl << endl; // LoadAllBranches headerf << "void LoadAllBranches() " << endl; headerf << "\t// load all branches" << endl << "{" << endl; for(Int_t i = 0; i< aliasarray->GetEntries(); i++) { TString aliasname(aliasarray->At(i)->GetName()); headerf << "\t" << "if (" << aliasname.Data() << "_branch != 0) " << Form("%s();",aliasname.Data()) << endl; } headerf << "}" << endl << endl; // accessor functions for (Int_t i = 0; i< aliasarray->GetEntries(); i++) { TString aliasname(aliasarray->At(i)->GetName()); // TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); TBranch *branch = 0; if (have_aliases) branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); else branch = (TBranch*)aliasarray->At(i); TString classname = branch->GetClassName(); TString title = branch->GetTitle(); bool isSkimmedNtuple = false; if(!classname.Contains("edm::Wrapper<") && (classname.Contains("vector") || classname.Contains("LorentzVector") ) ) isSkimmedNtuple = true; if ( classname.Contains("vector") ) { if(classname.Contains("edm::Wrapper<") ) { classname = classname(0,classname.Length()-2); classname.ReplaceAll("edm::Wrapper<",""); } headerf << "\tconst " << classname << " &" << aliasname << "()" << endl; } else { if(classname.Contains("edm::Wrapper<") ) { classname = classname(0,classname.Length()-1); classname.ReplaceAll("edm::Wrapper<",""); } if(classname != "" ) { headerf << "\t" << classname << " &" << aliasname << "()" << endl; } else { if(title.EndsWith("/i")) headerf << "\tunsigned int &" << aliasname << "()" << endl; if(title.EndsWith("/F")) headerf << "\tfloat &" << aliasname << "()" << endl; if(title.EndsWith("/I")) headerf << "\tint &" << aliasname << "()" << endl; if(title.EndsWith("/O")) headerf << "\tbool &" << "\t" << aliasname << "()" << endl; } } aliasname = aliasarray->At(i)->GetName(); headerf << "\t{" << endl; headerf << "\t\t" << "if (not " << Form("%s_isLoaded) {",aliasname.Data()) << endl; headerf << "\t\t\t" << "if (" << Form("%s_branch",aliasname.Data()) << " != 0) {" << endl; headerf << "\t\t\t\t" << Form("%s_branch",aliasname.Data()) << "->GetEntry(index);" << endl; if (paranoid) { headerf << "\t\t\t\t#ifdef PARANOIA" << endl; if (classname == "vector<vector<float> >") { if(isSkimmedNtuple) { headerf << "\t\t\t\t" << "for (vector<vector<float> >::const_iterator i = " << aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; } else { headerf << "\t\t\t\t" << "for (vector<vector<float> >::const_iterator i = " << aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; } headerf << "\t\t\t\t\t" << "for (vector<float>::const_iterator j = i->begin(); " "j != i->end(); ++j) {" << endl; headerf << "\t\t\t\t\t\t" << "if (not isfinite(*j)) {" << endl; headerf << "\t\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " contains a bad float: %f\\n\", *j);" << endl << "\t\t\t\t\t\t\t" << "exit(1);" << endl; headerf << "\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}" << endl; } else if (classname == "vector<float>") { if(isSkimmedNtuple) { headerf << "\t\t\t\t" << "for (vector<float>::const_iterator i = " << aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; } else { headerf << "\t\t\t\t" << "for (vector<float>::const_iterator i = " << aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; } headerf << "\t\t\t\t\t" << "if (not isfinite(*i)) {" << endl; headerf << "\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " contains a bad float: %f\\n\", *i);" << endl << "\t\t\t\t\t\t" << "exit(1);" << endl; headerf << "\t\t\t\t\t}\n\t\t\t\t}" << endl; } else if (classname == "float") { headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_)) {" << endl; headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " contains a bad float: %f\\n\", " << aliasname << "_);" << endl << "\t\t\t\t\t" << "exit(1);" << endl; headerf << "\t\t\t\t}" << endl; } else if (classname.BeginsWith("vector<vector<ROOT::Math::LorentzVector")) { if(isSkimmedNtuple) { headerf << "\t\t\t\t" << "for (" << classname.Data() <<"::const_iterator i = " << aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; } else { headerf << "\t\t\t\t" << "for (" << classname.Data() <<"::const_iterator i = " << aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; } // this is a slightly hacky way to get rid of the outer vector< > ... std::string str = classname.Data() + 7; str[str.length() - 2] = 0; headerf << "\t\t\t\t\t" << "for (" << str.c_str() << "::const_iterator j = i->begin(); " "j != i->end(); ++j) {" << endl; headerf << "\t\t\t\t\t\t" << "int e;" << endl; headerf << "\t\t\t\t\t\t" << "frexp(j->pt(), &e);" << endl; headerf << "\t\t\t\t\t\t" << "if (not isfinite(j->pt()) || e > 30) {" << endl; headerf << "\t\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " contains a bad float: %f\\n\", j->pt());" << endl << "\t\t\t\t\t\t\t" << "exit(1);" << endl; headerf << "\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}" << endl; } else if (classname.BeginsWith("vector<ROOT::Math::LorentzVector")) { if(isSkimmedNtuple) { headerf << "\t\t\t\t" << "for (" << classname.Data() << "::const_iterator i = " << aliasname << "_->begin(); i != "<< aliasname << "_->end(); ++i) {" << endl; } else { headerf << "\t\t\t\t" << "for (" << classname.Data() << "::const_iterator i = " << aliasname << "_.begin(); i != "<< aliasname << "_.end(); ++i) {" << endl; } headerf << "\t\t\t\t\t" << "int e;" << endl; headerf << "\t\t\t\t\t" << "frexp(i->pt(), &e);" << endl; headerf << "\t\t\t\t\t" << "if (not isfinite(i->pt()) || e > 30) {" << endl; headerf << "\t\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " contains a bad float: %f\\n\", i->pt());" << endl << "\t\t\t\t\t\t" << "exit(1);" << endl; headerf << "\t\t\t\t\t}\n\t\t\t\t}" << endl; } else if (classname.BeginsWith("ROOT::Math::LorentzVector")) { headerf << "\t\t\t\t" << "int e;" << endl; if(isSkimmedNtuple) { headerf << "\t\t\t\t" << "frexp(" << aliasname << "_->pt(), &e);" << endl; headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_->pt()) || e > 30) {" << endl; headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " contains a bad float: %f\\n\", " << aliasname << "_->pt());" << endl << "\t\t\t\t\t" << "exit(1);" << endl; } else { headerf << "\t\t\t\t" << "frexp(" << aliasname << "_.pt(), &e);" << endl; headerf << "\t\t\t\t" << "if (not isfinite(" << aliasname << "_.pt()) || e > 30) {" << endl; headerf << "\t\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " contains a bad float: %f\\n\", " << aliasname << "_.pt());" << endl << "\t\t\t\t\t" << "exit(1);" << endl; } headerf << "\t\t\t\t}" << endl; } headerf << "\t\t\t\t#endif // #ifdef PARANOIA" << endl; } headerf << "\t\t\t" << "} else { " << endl; headerf << "\t\t\t\t" << "printf(\"branch " << Form("%s_branch",aliasname.Data()) << " does not exist!\\n\");" << endl; headerf << "\t\t\t\t" << "exit(1);" << endl << "\t\t\t}" << endl; headerf << "\t\t\t" << Form("%s_isLoaded",aliasname.Data()) << " = true;" << endl; headerf << "\t\t" << "}" << endl; if(isSkimmedNtuple) { headerf << "\t\t" << "return *" << aliasname << "_;" << endl << "\t}" << endl; } else if(classname.Contains("vector<TString>") || classname.Contains("vector<float>")) { headerf << "\t\t" << "return " << aliasname << "_;" << endl << "\t}" << endl; } else if(classname == "TString") { headerf << "\t\t" << "return *" << aliasname << "_;" << endl << "\t}" << endl; } else { headerf << "\t\t" << "return " << aliasname << "_;" << endl << "\t}" << endl; } } bool haveHLTInfo = false; bool haveL1Info = false; bool haveHLT8E29Info = false; for(int i = 0; i < aliasarray->GetEntries(); i++) { TString aliasname(aliasarray->At(i)->GetName()); if(aliasname=="hlt_trigNames") haveHLTInfo = true; if(aliasname=="l1_trigNames") haveL1Info = true; if(aliasname=="hlt8e29_trigNames") haveHLT8E29Info = true; } if(haveHLTInfo) { //functions to return whether or not trigger fired - HLT headerf << "\t" << "bool passHLTTrigger(TString trigName) {" << endl; headerf << "\t\t" << "int trigIndx;" << endl; headerf << "\t\t" << "vector<TString>::const_iterator begin_it = hlt_trigNames().begin();" << endl; headerf << "\t\t" << "vector<TString>::const_iterator end_it = hlt_trigNames().end();" << endl; headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; headerf << "\t\t" << "if(found_it != end_it)" << endl; headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; headerf << "\t\t" << "else {" << endl; headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; headerf << "\t\t\t" << "return 0;" << endl; headerf << "\t\t" << "}" << endl << endl; headerf << "\t" << "return hlt_bits().TestBitNumber(trigIndx);" << endl; headerf << "\t" << "}" << endl; }//if(haveHLTInfo) if(haveHLT8E29Info) { //functions to return whether or not trigger fired - HLT headerf << "\t" << "bool passHLT8E29Trigger(TString trigName) {" << endl; headerf << "\t\t" << "int trigIndx;" << endl; headerf << "\t\t" << "vector<TString>::const_iterator begin_it = hlt8e29_trigNames().begin();" << endl; headerf << "\t\t" << "vector<TString>::const_iterator end_it = hlt8e29_trigNames().end();" << endl; headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; headerf << "\t\t" << "if(found_it != end_it)" << endl; headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; headerf << "\t\t" << "else {" << endl; headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; headerf << "\t\t\t" << "return 0;" << endl; headerf << "\t\t" << "}" << endl << endl; headerf << "\t" << "return hlt8e29_bits().TestBitNumber(trigIndx);" << endl; headerf << "\t" << "}" << endl; }//if(haveHLT8E29Info) if(haveL1Info) { //functions to return whether or not trigger fired - L1 headerf << "\t" << "bool passL1Trigger(TString trigName) {" << endl; headerf << "\t\t" << "int trigIndx;" << endl; headerf << "\t\t" << "vector<TString>::const_iterator begin_it = l1_trigNames().begin();" << endl; headerf << "\t\t" << "vector<TString>::const_iterator end_it = l1_trigNames().end();" << endl; headerf << "\t\t" << "vector<TString>::const_iterator found_it = find(begin_it, end_it, trigName);" << endl; headerf << "\t\t" << "if(found_it != end_it)" << endl; headerf << "\t\t\t" << "trigIndx = found_it - begin_it;" << endl; headerf << "\t\t" << "else {" << endl; headerf << "\t\t\t" << "cout << \"Cannot find Trigger \" << trigName << endl; " << endl; headerf << "\t\t\t" << "return 0;" << endl; headerf << "\t\t" << "}" << endl << endl; //get the list of branches that hold the L1 bitmasks //store in a set 'cause its automatically sorted set<TString> s_L1bitmasks; for(int j = 0; j < aliasarray->GetEntries(); j++) { TString aliasname(aliasarray->At(j)->GetName()); // TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); TBranch *branch = 0; if (have_aliases) branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); else branch = (TBranch*)aliasarray->At(j); TString classname = branch->GetClassName(); if(aliasname.Contains("l1_bits") && classname.Contains("int")) { s_L1bitmasks.insert(aliasname); } } int i = 0; for(set<TString>::const_iterator s_it = s_L1bitmasks.begin(); s_it != s_L1bitmasks.end(); s_it++, i++) { if(i==0) { headerf << "\t\t" << "if(trigIndx <= 31) {" << endl; headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; headerf << "\t\t\t" << "bitmask <<= trigIndx;" << endl; headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; headerf << "\t\t" << "}" << endl; continue; } headerf << "\t\t" << "if(trigIndx >= " << Form("%d && trigIndx <= %d", 32*i, 32*i+31) << ") {" << endl; headerf << "\t\t\t" << "unsigned int bitmask = 1;" << endl; headerf << "\t\t\t" << "bitmask <<= (trigIndx - " << Form("%d",32*i) << "); " << endl; headerf << "\t\t\t" << "return " << *s_it << "() & bitmask;" << endl; headerf << "\t\t" << "}" << endl; } headerf << "\t" << "return 0;" << endl; headerf << "\t" << "}" << endl; }//if(haveL1Info) headerf << endl; headerf << " static void progress( int nEventsTotal, int nEventsChain ){" << endl; headerf << " int period = 1000;" << endl; headerf << " if(nEventsTotal%1000 == 0) {" << endl; headerf << " // xterm magic from L. Vacavant and A. Cerri" << endl; headerf << " if (isatty(1)) {" << endl; headerf << " if( ( nEventsChain - nEventsTotal ) > period ){" << endl; headerf << " float frac = (float)nEventsTotal/(nEventsChain*0.01);" << endl; headerf << " printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"" << endl; headerf << " \"\\033[0m\\033[32m <---\\033[0m\\015\", frac);" << endl; headerf << " fflush(stdout);" << endl; headerf << " }" << endl; headerf << " else {" << endl; headerf << " printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"" << endl; headerf << " \"\\033[0m\\033[32m <---\\033[0m\\015\", 100.);" << endl; headerf << " cout << endl;" << endl; headerf << " }" << endl; headerf << " }" << endl; headerf << " }" << endl; headerf << " }" << endl; headerf << " " << endl; headerf << "};" << endl << endl; headerf << "#ifndef __CINT__" << endl; headerf << "extern " << Classname << " " << objName << ";" << endl; headerf << "#endif" << endl << endl; // Create namespace that can be used to access the extern'd cms2 // object methods without having to type cms2. everywhere. // Does not include cms2.Init and cms2.GetEntry because I think // it is healthy to leave those methods as they are headerf << "namespace " << nameSpace << " {" << endl; implf << "namespace " << nameSpace << " {" << endl; for (Int_t i = 0; i< aliasarray->GetEntries(); i++) { TString aliasname(aliasarray->At(i)->GetName()); // TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); TBranch *branch = 0; if (have_aliases) branch = ev->GetBranch(ev->GetAlias(aliasname.Data())); else branch = (TBranch*)aliasarray->At(i); TString classname = branch->GetClassName(); TString title = branch->GetTitle(); if ( classname.Contains("vector") ) { if(classname.Contains("edm::Wrapper") ) { classname = classname(0,classname.Length()-2); classname.ReplaceAll("edm::Wrapper<",""); } headerf << "\tconst " << classname << " &" << aliasname << "()"; implf << "\tconst " << classname << " &" << aliasname << "()"; } else { if(classname.Contains("edm::Wrapper<") ) { classname = classname(0,classname.Length()-1); classname.ReplaceAll("edm::Wrapper<",""); } if(classname != "" ) { headerf << "\tconst " << classname << " &" << aliasname << "()"; implf << "\tconst " << classname << " &" << aliasname << "()"; } else { if(title.EndsWith("/i")){ headerf << "\tconst unsigned int &" << aliasname << "()"; implf << "\tconst unsigned int &" << aliasname << "()"; } if(title.EndsWith("/F")){ headerf << "\tconst float &" << aliasname << "()"; implf << "\tconst float &" << aliasname << "()"; } if(title.EndsWith("/I")){ headerf << "\tconst int &" << aliasname << "()"; implf << "\tconst int &" << aliasname << "()"; } if(title.EndsWith("/O")){ headerf << "\tconst bool &" << aliasname << "()"; implf << "\tconst bool &" << aliasname << "()"; } } } headerf << ";" << endl; implf << " { return " << objName << "." << aliasname << "(); }" << endl; } if(haveHLTInfo) { //functions to return whether or not trigger fired - HLT headerf << "\t" << "bool passHLTTrigger(TString trigName);" << endl; implf << "\t" << "bool passHLTTrigger(TString trigName) { return " << objName << ".passHLTTrigger(trigName); }" << endl; }//if(haveHLTInfo) if(haveHLT8E29Info) { //functions to return whether or not trigger fired - HLT headerf << "\t" << "bool passHLT8E29Trigger(TString trigName);" << endl; implf << "\t" << "bool passHLT8E29Trigger(TString trigName) { return " << objName << ".passHLT8E29Trigger(trigName); }" << endl; }//if(haveHLT8E29Info) if(haveL1Info) { //functions to return whether or not trigger fired - L1 headerf << "\t" << "bool passL1Trigger(TString trigName);" << endl; implf << "\t" << "bool passL1Trigger(TString trigName) { return " << objName << ".passL1Trigger(trigName); }" << endl; }//if(haveL1Info) }
void printCalibStat(Int_t run, const char * fname, TTreeSRedirector * pcstream){ // // Dump the statistical information about all histograms in the calibration files // into the statistical tree, print on the screen (log files) as well // // // 1. Default dump for all histograms // Information to dump: // stat =Entries, Mean, MeanError, RMS, MaxBin // Branch naming convention: // <detName>_<hisName><statName> // // 2. Detector statistical information - to be implemented by expert // - First version implemented by MI // // TFile *fin = TFile::Open(fname); if (!fin) return; const Double_t kMaxHis=10000; TList * keyList = fin->GetListOfKeys(); Int_t nkeys=keyList->GetEntries(); Double_t *hisEntries = new Double_t[kMaxHis]; Double_t *hisMean = new Double_t[kMaxHis]; Double_t *hisMeanError = new Double_t[kMaxHis]; Double_t *hisRMS = new Double_t[kMaxHis]; Double_t *hisMaxBin = new Double_t[kMaxHis]; Int_t counter=0; if (pcstream) (*pcstream)<<"calibStatAll"<<"run="<<run; for (Int_t ikey=0; ikey<nkeys; ikey++){ TObject * object = fin->Get(keyList->At(ikey)->GetName()); if (!object) continue; if (object->InheritsFrom("TCollection")==0) continue; TSeqCollection *collection = (TSeqCollection*)object; Int_t nentries= collection->GetEntries(); for (Int_t ihis=0; ihis<nentries; ihis++){ TObject * ohis = collection->At(ihis); if (!ohis) continue; if (ohis->InheritsFrom("TH1")==0) continue; TH1* phis = (TH1*)ohis; hisEntries[counter]=phis->GetEntries(); Int_t idim=1; if (ohis->InheritsFrom("TH2")) idim=2; if (ohis->InheritsFrom("TH3")) idim=3; hisMean[counter]=phis->GetMean(idim); hisMeanError[counter]=phis->GetMeanError(idim); hisRMS[counter]=phis->GetRMS(idim); hisMaxBin[counter]=phis->GetBinCenter(phis->GetMaximumBin()); if (pcstream) (*pcstream)<<"calibStatAll"<< Form("%s_%sEntries=",keyList->At(ikey)->GetName(), phis->GetName())<<hisEntries[counter]<< Form("%s_%sMean=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMean[counter]<< Form("%s_%sMeanError=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMeanError[counter]<< Form("%s_%sRMS=",keyList->At(ikey)->GetName(), phis->GetName())<<hisRMS[counter]<< Form("%s_%sMaxBin=",keyList->At(ikey)->GetName(), phis->GetName())<<hisMaxBin[counter]; //printf("Histo:\t%s_%s\t%f\t%d\n",keyList->At(ikey)->GetName(), phis->GetName(), hisEntries[counter],idim); counter++; } delete object; } // // Expert dump example (MI first iteration): // // 0.) TOF dump // Int_t tofEvents=0; Int_t tofTracks=0; TList * TOFCalib = (TList*)fin->Get("TOFHistos"); if (TOFCalib) { TH1 *histoEvents = (TH1*)TOFCalib->FindObject("hHistoVertexTimestamp"); TH1 *histoTracks = (TH1*)TOFCalib->FindObject("hHistoDeltatTimestamp"); if (histoEvents && histoTracks){ tofEvents = TMath::Nint(histoEvents->GetEntries()); tofTracks = TMath::Nint(histoTracks->GetEntries()); } delete TOFCalib; } printf("Monalisa TOFevents\t%d\n",tofEvents); if (pcstream) (*pcstream)<<"calibStatAll"<<"TOFevents="<<tofEvents; printf("Monalisa TOFtracks\t%d\n",tofTracks); if (pcstream) (*pcstream)<<"calibStatAll"<<"TOFtracks="<<tofTracks; // // 1.) TPC dump - usefull events/tracks for the calibration // Int_t tpcEvents=0; Int_t tpcTracks=0; TObject* obj = dynamic_cast<TObject*>(fin->Get("TPCCalib")); TObjArray* array = dynamic_cast<TObjArray*>(obj); TDirectory* dir = dynamic_cast<TDirectory*>(obj); AliTPCcalibTime * calibTime = NULL; if (dir) { calibTime = dynamic_cast<AliTPCcalibTime*>(dir->Get("calibTime")); } else if (array){ calibTime = (AliTPCcalibTime *)array->FindObject("calibTime"); } if (calibTime) { tpcEvents = TMath::Nint(calibTime->GetTPCVertexHisto(0)->GetEntries()); tpcTracks = TMath::Nint(calibTime->GetResHistoTPCITS(0)->GetEntries()); } printf("Monalisa TPCevents\t%d\n",tpcEvents); if (pcstream) (*pcstream)<<"calibStatAll"<<"TPCevents="<<tpcEvents; printf("Monalisa TPCtracks\t%d\n",tpcTracks); if (pcstream) (*pcstream)<<"calibStatAll"<<"TPCtracks="<<tpcTracks; // // 2. TRD dump // Int_t trdEvents=0; Int_t trdTracks=0; TList * TRDCalib = (TList*)fin->Get("TRDCalib"); if (TRDCalib) { TH1 *histoEvents = (TH1*)TRDCalib->FindObject("NEventsInput_AliTRDCalibTask"); TH1 *histoTracks = (TH1*)TRDCalib->FindObject("AbsoluteGain_AliTRDCalibTask"); if (histoEvents && histoTracks){ trdEvents= TMath::Nint(histoEvents->GetEntries()); trdTracks= TMath::Nint(histoTracks->GetEntries()); } delete TRDCalib; } printf("Monalisa TRDevents\t%d\n",trdEvents); if (pcstream) (*pcstream)<<"calibStatAll"<<"TRDevents="<<trdEvents; printf("Monalisa TRDtracks\t%d\n",trdTracks); if (pcstream) (*pcstream)<<"calibStatAll"<<"TRDtracks="<<trdTracks; // // 3. T0 dump // Int_t T0Events=0; TList * T0Calib = (TList*)fin->Get("T0Calib"); if (T0Calib) { TH1 *histoEvents = (TH1*) T0Calib->FindObject("fTzeroORAplusORC"); if (histoEvents){ T0Events= TMath::Nint(histoEvents->GetEntries()); } delete T0Calib; } printf("Monalisa T0events\t%d\n",T0Events); if (pcstream) (*pcstream)<<"calibStatAll"<<"T0events="<<T0Events; // // 4. Mean vertex - dump // Not present in CPass1 /* Int_t meanVertexEvents=0; TList * meanVertexCalib = (TList*)fin->Get("MeanVertex"); if (meanVertexCalib) { TH1 *histoEvents = (TH1*) meanVertexCalib->FindObject("hTRKVertexX"); if (histoEvents){ meanVertexEvents = TMath::Nint(histoEvents->GetEntries()); } delete meanVertexCalib; } printf("Monalisa MeanVertexevents\t%d\n",meanVertexEvents); if (pcstream) (*pcstream)<<"calibStatAll"<<"MeanVertexevents="<<meanVertexEvents; */ // // 5. SDD dump // Int_t sddEvents=0; Int_t sddTracks=0; TList * SDDCalib = (TList*)fin->Get("clistSDDCalib"); if (SDDCalib) { TH1 *histoEvents = (TH1*) SDDCalib->FindObject("hNEvents"); if (histoEvents ){ sddEvents = TMath::Nint(histoEvents->GetBinContent(4)); sddTracks = TMath::Nint(histoEvents->GetBinContent(5)); } delete SDDCalib; } printf("Monalisa SDDevents\t%d\n",sddEvents); if (pcstream) (*pcstream)<<"calibStatAll"<<"SDDevents="<<sddEvents; printf("Monalisa SDDtracks\t%d\n",sddTracks); if (pcstream) (*pcstream)<<"calibStatAll"<<"SDDtracks="<<sddTracks; // // 6. AD dump // Int_t adEvents=0; TDirectory *adDir = (TDirectory*)fin->Get("ADCalib"); if (adDir) { TList *adList = (TList*) adDir->Get("ADCalibListHist"); if (adList) { TH2* adHistInt0 = (TH2*) adList->FindObject("hCh00_bc10_int0"); if (adHistInt0) adEvents += TMath::Nint(adHistInt0->GetEntries()); TH2* adHistInt1 = (TH2*) adList->FindObject("hCh00_bc10_int1"); if (adHistInt1) adEvents += TMath::Nint(adHistInt1->GetEntries()); delete adList; } } printf("Monalisa ADevents\t%d\n",adEvents); if (pcstream) (*pcstream)<<"calibStatAll"<<"ADevents="<<adEvents; // if (pcstream) (*pcstream)<<"calibStatAll"<<"\n"; delete fin; }