Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-19 23:20:33

0001 #!/usr/bin/env python
0002 
0003 import ROOT as r
0004 import argparse
0005 import sys
0006 import os
0007 
0008 def classname_to_type(cname): return "const " + cname.strip()
0009 
0010 if __name__ == "__main__":
0011 
0012     parser = argparse.ArgumentParser()
0013     parser.add_argument("filename", help="comma separated list of name(s) of file(s) to make classfile on")
0014     parser.add_argument("-t", "--tree", help="treename (default: Events)", default="Events")
0015     parser.add_argument("-n", "--namespace", help="namespace (default: tas)", default="tas")
0016     parser.add_argument("-o", "--objectname", help="objectname (default: cms3)", default="cms3")
0017     parser.add_argument("-c", "--classname", help="classname (default: CMS3)", default="CMS3")
0018     parser.add_argument("-l", "--looper", help="make a looper as well", default=False, action="store_true")
0019     args = parser.parse_args()
0020 
0021     fnames_in = args.filename.split(',')
0022     treename = args.tree
0023     classname = args.classname
0024     objectname = args.objectname
0025     namespace = args.namespace
0026     make_looper = args.looper
0027 
0028     ##
0029     ## create a unique list of branches
0030     ##
0031     names = set()
0032     aliases = r.TList()
0033     branches = r.TList()
0034     fs = []
0035     trees = []
0036 
0037     haveHLTInfo = False
0038     haveHLT8E29Info = False    
0039     haveL1Info = False
0040     haveTauIDInfo = False
0041     haveBtagInfo = False    
0042     
0043     for name in fnames_in:
0044         f = r.TFile(name)
0045         tree = f.Get(treename)
0046         fs.append(f)
0047         trees.append(tree)
0048         temp_aliases = trees[-1].GetListOfAliases()
0049         temp_branches = trees[-1].GetListOfBranches()
0050         
0051         if temp_aliases:
0052             for ala in temp_aliases:
0053                 alias = ala.GetName()
0054                 if alias not in names:
0055                     names.add(alias)
0056                     aliases.Add(ala)
0057                     branches.Add(trees[-1].GetBranch(trees[-1].GetAlias(alias)))
0058                 if "hlt_trigNames" in alias: haveHLTInfo = True
0059                 if "hlt8e29_trigNames" in alias: haveHLT8E29Info = True
0060                 if "l1_trigNames" in alias: haveL1Info = True
0061                 if "taus_pf_IDnames" in alias: haveTauIDInfo = True
0062                 if "pfjets_bDiscriminatorNames" in alias: haveBtagInfo = True
0063         else:
0064             for br in temp_branches:
0065                 branches.Add(br)
0066 
0067             
0068     if make_looper and (os.path.isfile("ScanChain.C") or os.path.isfile("doAll.C")):
0069         print(">>> Hey, you already have a looper here! I will be a bro and not overwrite them. Delete 'em if you want to regenerate 'em.")
0070         make_looper = False
0071 
0072     if make_looper:
0073         print(">>> Making looper")
0074         print(">>> Checking out cmstas/Software")
0075         os.system("[[ -d Software/ ]] || git clone https://github.com/cmstas/Software")
0076 
0077         buff = ""
0078         buff += "{\n"
0079         buff += "    gSystem->Exec(\"mkdir -p plots\");\n\n"
0080         buff += "    gROOT->ProcessLine(\".L Software/dataMCplotMaker/dataMCplotMaker.cc+\");\n"
0081         buff += "    gROOT->ProcessLine(\".L %s.cc+\");\n" % classname
0082         buff += "    gROOT->ProcessLine(\".L ScanChain.C+\");\n\n"
0083         buff += "    TChain *ch = new TChain(\"%s\");\n" % treename
0084         buff += "    ch->Add(\"%s\");\n\n" % fnames_in[0]
0085         buff += "    ScanChain(ch);\n\n"
0086         buff += "}\n\n"
0087         with open("doAll.C", "w") as fhout: fhout.write(buff)
0088 
0089         buff = ""
0090         buff += "#pragma GCC diagnostic ignored \"-Wsign-compare\"\n"
0091         buff += "#include \"Software/dataMCplotMaker/dataMCplotMaker.h\"\n\n"
0092         buff += "#include \"TFile.h\"\n"
0093         buff += "#include \"TTree.h\"\n"
0094         buff += "#include \"TCut.h\"\n"
0095         buff += "#include \"TColor.h\"\n"
0096         buff += "#include \"TCanvas.h\"\n"
0097         buff += "#include \"TH2F.h\"\n"
0098         buff += "#include \"TH1.h\"\n"
0099         buff += "#include \"TChain.h\"\n\n"
0100         buff += "#include \"%s.h\"\n\n" % classname
0101         buff += "using namespace std;\n"
0102         buff += "using namespace tas;\n\n"
0103         buff += "int ScanChain(TChain *ch){\n\n"
0104         buff += "    TH1F * h_met = new TH1F(\"met\", \"met\", 50, 0, 300);\n\n"
0105         buff += "    int nEventsTotal = 0;\n"
0106         buff += "    int nEventsChain = ch->GetEntries();\n\n"
0107         buff += "    TFile *currentFile = 0;\n"
0108         buff += "    TObjArray *listOfFiles = ch->GetListOfFiles();\n"
0109         buff += "    TIter fileIter(listOfFiles);\n\n"
0110         buff += "    while ( (currentFile = (TFile*)fileIter.Next()) ) { \n\n"
0111         buff += "        TFile *file = new TFile( currentFile->GetTitle() );\n"
0112         buff += "        TTree *tree = (TTree*)file->Get(\"%s\");\n" % treename
0113         buff += "        %s.Init(tree);\n\n" % objectname
0114         buff += "        TString filename(currentFile->GetTitle());\n\n"
0115         buff += "        for( unsigned int event = 0; event < tree->GetEntriesFast(); ++event) {\n\n"
0116         buff += "            %s.GetEntry(event);\n" % objectname
0117         buff += "            nEventsTotal++;\n\n"
0118         buff += "            %s::progress(nEventsTotal, nEventsChain);\n\n" % classname
0119         buff += "            h_met->Fill(evt_pfmet());\n\n"
0120         buff += "        }//event loop\n\n"
0121         buff += "        delete file;\n"
0122         buff += "    }//file loop\n\n"
0123         buff += "    TString comt = \" --outOfFrame --lumi 1.0 --type Simulation --darkColorLines --legendCounts --legendRight -0.05  --outputName plots/\";\n"
0124         buff += "    std::string com = comt.Data();\n"
0125         buff += "    TH1F * empty = new TH1F(\"\",\"\",1,0,1);\n\n"
0126         buff += "    dataMCplotMaker(empty,{h_met} ,{\"t#bar{t}\"},\"MET\",\"\",com+\"h_met.pdf --isLinear\");\n\n"
0127         buff += "    return 0;\n\n"
0128         buff += "}\n\n"
0129         with open("ScanChain.C", "w") as fhout: fhout.write(buff)
0130 
0131     d_bname_to_info = {}
0132 
0133     # cuts = ["filtcscBeamHalo2015","evtevent","evtlumiBlock","evtbsp4","hltprescales","hltbits","hlttrigNames","musp4","evtpfmet","muschi2","ak8jets_pfcandIndicies","hlt_prescales"]
0134     cuts = ["lep1_p4","lep2_p4"]
0135     isCMS3 = False
0136     have_aliases = False
0137     for branch in branches:
0138         bname = branch.GetName()
0139         cname = branch.GetClassName()
0140         btitle = branch.GetTitle()
0141         
0142         if bname in ["EventSelections", "BranchListIndexes", "EventAuxiliary", "EventProductProvenance"]: continue
0143         # if not any([cut in bname for cut in cuts]): continue
0144 
0145         # sometimes root is stupid and gives no class name, so must infer it from btitle (stuff like "btag_up/F")
0146         if not cname:
0147             if btitle.endswith("/i"): cname = "unsigned int"
0148             elif btitle.endswith("/l"): cname = "unsigned long long"
0149             elif btitle.endswith("/F"): cname = "float"
0150             elif btitle.endswith("/I"): cname = "int"
0151             elif btitle.endswith("/O"): cname = "bool"
0152             elif btitle.endswith("/D"): cname = "double"
0153 
0154         typ = cname[:]
0155 
0156         if "edm::TriggerResults" in cname:
0157             continue
0158 
0159         if "edm::Wrapper" in cname:
0160             isCMS3 = True
0161             typ = cname.replace("edm::Wrapper<","")[:-1]
0162         typ = classname_to_type(typ)
0163 
0164         if "musp4" in bname: print(bname)
0165         
0166         d_bname_to_info[bname] = {
0167                 "class": cname,
0168                 "alias": bname.replace(".",""),
0169                 "type": typ,
0170                 }        
0171         
0172     if len(aliases):
0173         have_aliases = True
0174         for iala, ala in enumerate(aliases):
0175             alias = ala.GetName()
0176             for tree in trees:
0177                 if tree.GetBranch(tree.GetAlias(alias)):
0178                     branch = tree.GetBranch(tree.GetAlias(alias))
0179                     break
0180             # branchname = branch.GetName().replace("obj","")
0181             branchname = branch.GetName()
0182             if branchname not in d_bname_to_info: continue
0183             d_bname_to_info[branchname]["alias"] = alias.replace(".","")
0184 
0185 
0186     buff = ""
0187 
0188     ########################################
0189     ################ ***.h ################
0190     ########################################
0191     buff += '// -*- C++ -*-\n'
0192     buff += '#ifndef %s_H\n' % classname
0193     buff += '#define %s_H\n' % classname
0194     buff += '#include "Math/LorentzVector.h"\n'
0195     buff += '#include "Math/Point3D.h"\n'
0196     buff += '#include "TMath.h"\n'
0197     buff += '#include "TBranch.h"\n'
0198     buff += '#include "TTree.h"\n'
0199     buff += '#include "TH1F.h"\n'
0200     buff += '#include "TFile.h"\n'
0201     buff += '#include "TBits.h"\n'
0202     buff += '#include <vector>\n'
0203     buff += '#include <unistd.h>\n'
0204     buff += 'typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;\n\n'
0205 
0206     buff += '// Generated with file: %s\n\n' % fnames_in[0]
0207     buff += 'using namespace std;\n'
0208     buff += 'class %s {\n' % classname
0209     buff += 'private:\n'
0210     buff += 'protected:\n'
0211     buff += '  unsigned int index;\n'
0212     for bname in d_bname_to_info:        
0213         alias = d_bname_to_info[bname]["alias"]
0214         typ = d_bname_to_info[bname]["type"]
0215         cname = d_bname_to_info[bname]["class"]
0216         needpointer = "vector<" in typ or "LorentzVector" in typ
0217         buff += '  %s %s%s_;\n' % (typ.replace("const","").strip(),"*" if needpointer else "",alias)
0218         buff += '  TBranch *%s_branch;\n' % (alias)
0219         buff += '  bool %s_isLoaded;\n' % (alias)
0220     buff += 'public:\n'
0221     buff += '  void Init(TTree *tree);\n'
0222     buff += '  void GetEntry(unsigned int idx);\n'
0223     buff += '  void LoadAllBranches();\n'
0224     for bname in d_bname_to_info:
0225         alias = d_bname_to_info[bname]["alias"]
0226         typ = d_bname_to_info[bname]["type"]
0227         buff += '  %s &%s();\n' % (typ, alias)
0228     if haveHLTInfo:
0229         buff += "  bool passHLTTrigger(TString trigName);\n"
0230     if haveHLT8E29Info:
0231         buff += "  bool passHLT8E29Trigger(TString trigName);\n"
0232     if haveL1Info:
0233         buff += "  bool passL1Trigger(TString trigName);\n"
0234     if haveTauIDInfo:
0235         buff += "  float passTauID(TString idName, unsigned int tauIndex);\n"
0236     if haveBtagInfo:
0237         buff += "  float getbtagvalue(TString bDiscriminatorName, unsigned int jetIndex);\n" 
0238     buff += "  static void progress( int nEventsTotal, int nEventsChain );\n"
0239     buff += '};\n\n'
0240 
0241     buff += "#ifndef __CINT__\n"
0242     buff += "extern %s %s;\n" % (classname, objectname)
0243     buff += "#endif\n"
0244     buff += "\n"
0245     buff += "namespace %s {\n" % (namespace)
0246     buff += "\n"
0247     for bname in d_bname_to_info:
0248         alias = d_bname_to_info[bname]["alias"]
0249         typ = d_bname_to_info[bname]["type"]
0250         buff += "  %s &%s();\n" % (typ, alias)
0251     if haveHLTInfo:
0252         buff += "  bool passHLTTrigger(TString trigName);\n"
0253     if haveHLT8E29Info:
0254         buff += "  bool passHLT8E29Trigger(TString trigName);\n"
0255     if haveL1Info:
0256         buff += "  bool passL1Trigger(TString trigName);\n"
0257     if haveTauIDInfo:
0258         buff += "  float passTauID(TString idName, unsigned int tauIndex);\n"
0259     if haveBtagInfo:
0260         buff += "  float getbtagvalue(TString bDiscriminatorName, unsigned int jetIndex);\n" 
0261     buff += "}\n"
0262     buff += "#endif\n"
0263 
0264     with open("%s.h" % classname, "w") as fhout:
0265         fhout.write(buff)
0266 
0267     print(">>> Saved %s.h" % (classname))
0268 
0269     ########################################
0270     ############### ***.cc ################
0271     ########################################
0272 
0273     buff = ""
0274     buff += '#include "%s.h"\n' % classname
0275     buff += "%s %s;\n\n" % (classname, objectname)
0276     buff += "void %s::Init(TTree *tree) {\n" % (classname)
0277 
0278     ## NOTE Do this twice. First time we consider branches for which we don't want to have SetMakeClass of 1
0279     for bname in d_bname_to_info:
0280         alias = d_bname_to_info[bname]["alias"]
0281         cname = d_bname_to_info[bname]["class"]
0282         if not(("TBits" in cname or "LorentzVector" in cname) and not "vector<vector" in cname): continue # NOTE
0283         buff += '  %s_branch = 0;\n' % (alias)
0284         if have_aliases:
0285             buff += '  if (tree->GetAlias("%s") != 0) {\n' % (alias)
0286             buff += '    %s_branch = tree->GetBranch(tree->GetAlias("%s"));\n' % (alias, alias)
0287         else:
0288             buff += '  if (tree->GetBranch("%s") != 0) {\n' % (alias)
0289             buff += '    %s_branch = tree->GetBranch("%s");\n' % (alias, alias)
0290         buff += '    if (%s_branch) { %s_branch->SetAddress(&%s_); }\n' % (alias, alias, alias)
0291         buff += '  }\n'
0292 
0293     buff += "  tree->SetMakeClass(1);\n"
0294     for bname in d_bname_to_info:
0295         alias = d_bname_to_info[bname]["alias"]
0296         cname = d_bname_to_info[bname]["class"]
0297         if ("TBits" in cname or "LorentzVector" in cname) and not "vector<vector" in cname: continue # NOTE
0298         buff += '  %s_branch = 0;\n' % (alias)
0299         if have_aliases:
0300             buff += '  if (tree->GetAlias("%s") != 0) {\n' % (alias)
0301             buff += '    %s_branch = tree->GetBranch(tree->GetAlias("%s"));\n' % (alias, alias)
0302         else:
0303             buff += '  if (tree->GetBranch("%s") != 0) {\n' % (alias)
0304             buff += '    %s_branch = tree->GetBranch("%s");\n' % (alias, alias)
0305         buff += '    if (%s_branch) { %s_branch->SetAddress(&%s_); }\n' % (alias, alias, alias)
0306         buff += '  }\n'
0307 
0308     buff += '  tree->SetMakeClass(0);\n'
0309     buff += "}\n"
0310 
0311     buff += "void %s::GetEntry(unsigned int idx) {\n" % classname
0312     buff += "  index = idx;\n"
0313     for bname in d_bname_to_info:
0314         alias = d_bname_to_info[bname]["alias"]
0315         buff += '  %s_isLoaded = false;\n' % (alias)
0316     buff += "}\n"
0317 
0318     buff += "void %s::LoadAllBranches() {\n" % classname
0319     for bname in d_bname_to_info:
0320         alias = d_bname_to_info[bname]["alias"]
0321         buff += '  if (%s_branch != 0) %s();\n' % (alias, alias)
0322     buff += "}\n"
0323     
0324     for bname in d_bname_to_info:
0325         alias = d_bname_to_info[bname]["alias"]
0326         typ = d_bname_to_info[bname]["type"]
0327         cname = d_bname_to_info[bname]["class"]
0328         needpointer = "vector<" in typ or "LorentzVector" in typ
0329         buff += "%s &%s::%s() {\n" % (typ, classname, alias)
0330         buff += "  if (not %s_isLoaded) {\n" % (alias)
0331         buff += "    if (%s_branch != 0) {\n" % (alias)
0332         buff += "      %s_branch->GetEntry(index);\n" % (alias)
0333         buff += "    } else {\n"
0334         buff += '      printf("branch %s_branch does not exist!\\n");\n' % (alias)
0335         buff += "      exit(1);\n"
0336         buff += "    }\n"
0337         buff += "    %s_isLoaded = true;\n" % (alias)
0338         buff += "  }\n"
0339         buff += "  return %s%s_;\n" % ("*" if needpointer else "", alias)
0340         buff += "}\n"
0341 
0342     if haveHLTInfo:
0343         buff += "bool %s::passHLTTrigger(TString trigName) {\n" % (classname)
0344         buff += "  int trigIndex;\n"
0345         buff += "  std::vector<TString>::const_iterator begin_it = hlt_trigNames().begin();\n"
0346         buff += "  std::vector<TString>::const_iterator end_it = hlt_trigNames().end();\n"
0347         buff += "  std::vector<TString>::const_iterator found_it = std::find(begin_it, end_it, trigName);\n"
0348         buff += "  if (found_it != end_it)\n"
0349         buff += "    trigIndex = found_it - begin_it;\n"
0350         buff += "  else {\n"
0351         buff += "    std::cout << \"Cannot find trigger \" << trigName << std::endl;\n"
0352         buff += "    return 0;\n"
0353         buff += "  }\n"
0354         buff += "  return hlt_bits().TestBitNumber(trigIndex);\n"
0355         buff += "}\n"
0356 
0357     if haveHLT8E29Info:
0358         buff += "bool %s::passHLT8E29Trigger(TString trigName) {\n" % (classname)
0359         buff += "  int trigIndex;\n"
0360         buff += "  std::vector<TString>::const_iterator begin_it = hlt8e29_trigNames().begin()\n;"
0361         buff += "  std::vector<TString>::const_iterator end_it = hlt8e29_trigNames().end();\n"
0362         buff += "  std::vector<TString>::const_iterator found_it = std::find(begin_it, end_it, trigName);\n"
0363         buff += "  if (found_it != end_it)\n"
0364         buff += "    trigIndex = found_it - begin_it;\n"
0365         buff += "  else {\n"
0366         buff += "    std::cout << \"Cannot find trigger \" << trigName << std::endl;\n"
0367         buff += "    return 0;\n"
0368         buff += "  }\n"
0369         buff += "  return hlt8e29_bits().TestBitNumber(trigIndex);\n"
0370         buff += "}\n"
0371 
0372     if haveL1Info:
0373         buff += "bool %s::passL1Trigger(TString trigName) {\n" % (classname)
0374         buff += "  int trigIndex;\n"
0375         buff += "  std::vector<TString>::const_iterator begin_it = l1_trigNames().begin();\n"
0376         buff += "  std::vector<TString>::const_iterator end_it = l1_trigNames().end();\n"
0377         buff += "  std::vector<TString>::const_iterator found_it = std::find(begin_it, end_it, trigName);\n"
0378         buff += "  if (found_it != end_it)\n"
0379         buff += "    trigIndex = found_it - begin_it;\n"
0380         buff += "  else {\n"
0381         buff += "    std::cout << \"Cannot find trigger \" << trigName << std::endl;\n"
0382         buff += "    return 0;\n"
0383         buff += "  }\n"
0384         list_of_aliases = []
0385         for iala, ala in enaliases:
0386             alias = ala.GetName()
0387             if "l1_bits" not in alias: continue
0388             for tree in trees:
0389                 if tree.GetBranch(tree.GetAlias(alias)):
0390                     branch = tree.GetBranch(tree.GetAlias(alias))
0391                     break
0392             name_of_class = branch.GetClassName()
0393             if "int" not in name_of_class: continue
0394             list_of_aliases.append(alias)
0395         for iala, ala in enumerate(sorted(list_of_aliases)):
0396             if iala == 0:
0397                 buff += "  if (trigIndex <= 31) {\n"
0398                 buff += "    unsigned int bitmask = 1;\n"
0399                 buff += "    bitmask <<= trigIndex;\n"
0400                 buff += "    return %s() & bitmask;\n" % (ala)
0401                 buff += "  }\n"
0402             else:
0403                 buff += "  if (trigIndex >= %d && trigIndex <= %d) {\n" % (32*iala, 32+iala+31)
0404                 buff += "    unsigned int bitmask = 1;\n"
0405                 buff += "    bitmask <<= (trigIndex - %d);\n" % (32*iala)
0406                 buff += "    return %s() & bitmask;\n" % (ala)
0407                 buff += "  }\n"                
0408         buff += "  return 0;\n"        
0409         buff += "}\n"
0410 
0411     if haveTauIDInfo:
0412         buff += "float %s::passTauID(TString idName, unsigned int tauIndex) {\n" % (classname)
0413         buff += "  int idIndex;\n"
0414         buff += "  std::vector<TString>::const_iterator begin_it = taus_pf_IDnames().begin();\n"
0415         buff += "  std::vector<TString>::const_iterator end_it = taus_pf_IDnames().end();\n"
0416         buff += "  std::vector<TString>::const_iterator found_it = std::find(begin_it, end_it, idName);\n"
0417         buff += "  if (found_it != end_it)\n"
0418         buff += "    idIndex = found_it - begin_it;\n"
0419         buff += "  else {\n"
0420         buff += "    std::cout << \"Cannot find tau ID \" << idName << std::endl;\n"
0421         buff += "    return 0;\n"
0422         buff += "  }\n"
0423         buff += "  if (tauIndex < taus_pf_IDs().size())\n"
0424         buff += "    return taus_pf_IDs().at(tauIndex).at(idIndex);\n"
0425         buff += "  else {\n"
0426         buff += "    std::cout << \"Cannot find tau # \" << tauIndex << std::endl;\n"
0427         buff += "    return 0;\n"
0428         buff += "  }\n"
0429         buff += "}\n"        
0430 
0431     if haveBtagInfo:
0432         buff += "float %s::getbtagvalue(TString bDiscriminatorName, unsigned int jetIndex) {\n" % (classname)
0433         buff += "  size_t bDiscriminatorIndex;\n"
0434         buff += "  std::vector<TString>::const_iterator begin_it = pfjets_bDiscriminatorNames().begin();\n"
0435         buff += "  std::vector<TString>::const_iterator end_it = pfjets_bDiscriminatorNames().end();\n"
0436         buff += "  std::vector<TString>::const_iterator found_it = std::find(begin_it, end_it, bDiscriminatorName);\n"
0437         buff += "  if (found_it != end_it)\n"
0438         buff += "    bDiscriminatorIndex = found_it - begin_it;\n"
0439         buff += "  else {\n"
0440         buff += "    std::cout << \"Cannot find b-discriminator \" << bDiscriminatorName << std::endl;\n"
0441         buff += "    return 0;\n"
0442         buff += "  }\n"
0443         buff += "  if (jetIndex < pfjets_bDiscriminators().size())\n"
0444         buff += "    return pfjets_bDiscriminators().at(jetIndex).at(bDiscriminatorIndex);\n"
0445         buff += "  else {\n"
0446         buff += "    std::cout << \"Cannot find jet # \" << jetIndex << std::endl;\n"
0447         buff += "    return 0;\n"        
0448         buff += "  }\n"
0449         buff += "}\n"        
0450         
0451     buff += "void %s::progress( int nEventsTotal, int nEventsChain ){\n" % (classname)
0452     buff += "  int period = 1000;\n"
0453     buff += "  if(nEventsTotal%1000 == 0) {\n"
0454     buff += "    if (isatty(1)) {\n"
0455     buff += "      if( ( nEventsChain - nEventsTotal ) > period ){\n"
0456     buff += "        float frac = (float)nEventsTotal/(nEventsChain*0.01);\n"
0457     buff += "        printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"\n"
0458     buff += "               \"\\033[0m\\033[32m <---\\033[0m\\015\", frac);\n"
0459     buff += "        fflush(stdout);\n"
0460     buff += "      }\n"
0461     buff += "      else {\n"
0462     buff += "        printf(\"\\015\\033[32m ---> \\033[1m\\033[31m%4.1f%%\"\n"
0463     buff += "               \"\\033[0m\\033[32m <---\\033[0m\\015\", 100.);\n"
0464     buff += "        cout << endl;\n"
0465     buff += "      }\n"
0466     buff += "    }\n"
0467     buff += "  }\n"
0468     buff += "}\n"
0469 
0470     buff += "namespace %s {\n" % (namespace)
0471     for bname in d_bname_to_info:
0472         alias = d_bname_to_info[bname]["alias"]
0473         typ = d_bname_to_info[bname]["type"]
0474         buff += "  %s &%s() { return %s.%s(); }\n" % (typ, alias, objectname, alias)
0475     if haveHLTInfo:
0476         buff += "  bool passHLTTrigger(TString trigName) { return %s.passHLTTrigger(trigName); }\n" % (objectname)
0477     if haveHLT8E29Info:
0478         buff += "  bool passHLT8E29Trigger(TString trigName) { return %s.passHLT8E29Trigger(trigName); }\n" % (objectname)
0479     if haveL1Info:
0480         buff += "  bool passL1Trigger(TString trigName) { return %s.passL1Trigger(trigName); }\n" % (objectname)
0481     if haveTauIDInfo:
0482         buff += "  float passTauID(TString idName, unsigned int tauIndex) { return %s.passTauID(idName, tauIndex); }\n" % (objectname)
0483     if haveBtagInfo:
0484         buff += "  float getbtagvalue(TString bDiscriminatorName, unsigned int jetIndex) { return %s.getbtagvalue(bDiscriminatorName, jetIndex); }\n" % (objectname)
0485     buff += "}\n"
0486 
0487     with open("%s.cc" % classname, "w") as fhout:
0488         fhout.write(buff)
0489     print(">>> Saved %s.cc" % (classname))
0490 
0491 
0492