void MakeSTRUCTZeroMisAlignment(){ // Create TClonesArray of zero misalignment objects for all STRUCTures // (presently this includes only FRAME) // const char* macroname = "MakeSTRUCTZeroMisAlignment.C"; TClonesArray *array = new TClonesArray("IlcAlignObjParams",20); Int_t iIndex=0; //let all modules have index=0 in a layer with no LUT IlcGeomManager::ELayerID iLayer = IlcGeomManager::kInvalidLayer; UShort_t dvoluid = IlcGeomManager::LayerToVolUID(iLayer,iIndex); //dummy vol id const char* basepath ="ILCM_1/B077_1/BSEGMO"; TString segmpath; for(Int_t sm=0; sm<18; sm++){ segmpath=basepath; segmpath+=sm; segmpath+="_1"; cout<<segmpath.Data()<<endl; new((*array)[sm]) IlcAlignObjParams(segmpath.Data(),dvoluid,0.,0.,0.,0.,0.,0.,kTRUE); } if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){ // save on file const char* filename = "STRUCTzeroMisalignment.root"; TFile f(filename,"RECREATE"); if(!f){ Error(macroname,"cannot open file for output\n"); return; } Info(macroname,"Saving alignment objects in %s", filename); f.cd(); f.WriteObject(array,"STRUCTAlignObjs","kSingleKey"); f.Close(); }else{ // save in CDB storage TString Storage = gSystem->Getenv("STORAGE"); if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) { Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()); return; } Info(macroname,"Saving alignment objects in CDB storage %s",Storage.Data()); IlcCDBManager* cdb = IlcCDBManager::Instance(); IlcCDBStorage* storage = cdb->GetStorage(Storage.Data()); if(!storage){ Error(macroname,"Unable to open storage %s\n",Storage.Data()); return; } IlcCDBMetaData* md = new IlcCDBMetaData(); md->SetResponsible("Grosso Raffaele"); md->SetComment("Zero misalignment for STRUCT: presently includes objects for FRAME"); md->SetIlcRootVersion(gSystem->Getenv("ARVERSION")); IlcCDBId id("GRP/Align/Data",0,IlcCDBRunRange::Infinity()); storage->Put(array,id,md); } array->Delete(); }
void KVGeoImport::AddLayer(KVDetector *det, TGeoVolume *vol) { // Add an absorber layer to the detector // Volumes representing 'active' layers in detectors must have names // which begin with "ACTIVE_" TString vnom = vol->GetName(); // exclude dead zone layers if(vnom.BeginsWith("DEADZONE")) return; TGeoMaterial* material = vol->GetMaterial(); KVIonRangeTableMaterial* irmat = fRangeTable->GetMaterial(material); if(!irmat){ Warning("AddLayer", "Unknown material %s/%s used in layer %s of detector %s", material->GetName(), material->GetTitle(), vol->GetName(), det->GetName()); return; } TGeoBBox* sh = dynamic_cast<TGeoBBox*>(vol->GetShape()); if(!sh) { Warning("AddLayer", "Unknown shape class %s used in layer %s of detector %s", vol->GetShape()->ClassName(), vol->GetName(), det->GetName()); return; // just in case - for now, all shapes derive from TGeoBBox... } Double_t width = 2.*sh->GetDZ(); // thickness in centimetres KVMaterial* absorber; if( irmat->IsGas() ){ Double_t p = material->GetPressure(); Double_t T = material->GetTemperature(); absorber = new KVMaterial(irmat->GetType(), width, p, T); } else absorber = new KVMaterial(irmat->GetType(), width); det->AddAbsorber(absorber); if(vnom.BeginsWith("ACTIVE_")) det->SetActiveLayer( det->GetListOfAbsorbers()->GetEntries()-1 ); }
//_________________________________________________________________ Char_t KVCaloBase::GetValueType(Int_t i) const { // Returns type of value depending on name: // Zsum I // Asum I // Eksum D // Qsum D // Msum I // Aneu I // Qneu D // Mneu I // Qini D // Temp D // Exci D // Ekneu D // Zpart I // Apart I // Ekpart D // Qpart D // Mpart I // Zfrag I // Afrag I // Ekfrag D // Qfrag D // Mfrag I TString name = GetValueName(i); if(name.BeginsWith("E")||name.BeginsWith("Q")||name.BeginsWith("T")) return 'D'; else return 'I'; };
void ilceve_init(const TString& cdburi = "local://$ILC_ROOT/OCDB", const TString& path = ".", Int_t event=0, const Text_t* esdfile = 0, const Text_t* aodfile = 0, const Text_t* rawfile = 0, Bool_t assert_runloader = kFALSE, Bool_t assert_esd = kFALSE, Bool_t assert_aod = kFALSE, Bool_t assert_raw = kFALSE) { if (cdburi.IsNull() && ! IlcCDBManager::Instance()->IsDefaultStorageSet()) { gEnv->SetValue("Root.Stacktrace", "no"); Fatal("ilceve_init.C", "OCDB path MUST be specified as the first argument."); } Info("ilceve_init", "Adding standard macros."); TString hack = gSystem->pwd(); // Problem with TGFileBrowser cding ilceve_init_import_macros(); gSystem->cd(hack); TEveUtil::AssertMacro("VizDB_scan.C"); gSystem->ProcessEvents(); IlcEveEventManager::SetESDFileName(esdfile); IlcEveEventManager::SetRawFileName(rawfile); IlcEveEventManager::SetCdbUri(cdburi); IlcEveEventManager::SetAssertElements(assert_runloader, assert_esd, assert_aod, assert_raw); // Open event if (path.BeginsWith("alien:") || ! cdburi.BeginsWith("local:")) { if (gGrid != 0) { Info("ilceve_init", "TGrid already initializied. Skiping checks and initialization."); } else { Info("ilceve_init", "AliEn requested - connecting."); if (gSystem->Getenv("GSHELL_ROOT") == 0) { Error("ilceve_init", "AliEn environment not initialized. Aborting."); gSystem->Exit(1); } if (TGrid::Connect("alien") == 0) { Error("ilceve_init", "TGrid::Connect() failed. Aborting."); gSystem->Exit(1); } } } Info("ilceve_init", "Opening event %d from '%s' ...", event, path.Data()); TString name("Event"); // CINT has trouble with direct "Event". new IlcEveEventManager(name, path, event); gEve->AddEvent(IlcEveEventManager::GetMaster()); }
/** * Create our tasks. This uses the interpreter to make the object. * * @param mgr */ void CreateTasks(AliAnalysisManager* mgr) { Info("CreateTasks", "Loading code"); fRailway->LoadSource("FixPaths.C"); fRailway->LoadSource("AliAODSimpleHeader.C"); fRailway->LoadSource("AliAODTracklet.C"); fRailway->LoadSource("AliTrackletWeights.C"); fRailway->LoadSource("AliTrackletAODUtils.C"); fRailway->LoadSource("AliTrackletAODdNdeta.C"); // --- Create the task using interpreter ------------------------- Bool_t mc = fOptions.Has("mc"); if (!mc) mc = fRailway->IsMC(); Long_t ret = gROOT->ProcessLine(Form("AliTrackletAODdNdeta::Create(%d,\"%s\")",mc, fOptions.AsString("reweigh"))); AliAnalysisTaskSE* task = reinterpret_cast<AliAnalysisTaskSE*>(ret); if (!task) return; // --- Figure out the trigger options ---------------------------- TString trg = fOptions.Get("trig"); trg.ToUpper(); UInt_t sel = AliVEvent::kINT7; if (trg.EqualTo("MB")) sel = AliVEvent::kMB; else if (trg.EqualTo("V0AND")) sel = AliVEvent::kINT7; else if (trg.EqualTo("V0OR")) sel = AliVEvent::kCINT5; else if (trg.EqualTo("ANY")) sel = AliVEvent::kAny; task->SelectCollisionCandidates(sel); // --- Figure out calculation mode ------------------------------- TString calc = fOptions.Get("reweigh-calc"); calc.ToUpper(); UChar_t mcal = 0; if (calc.BeginsWith("PROD")) mcal = 0; else if (calc.BeginsWith("SQ")) mcal = 1; else if (calc.BeginsWith("SUM")) mcal = 2; else if (calc.BeginsWith("AV")) mcal = 3; // --- Set various options on task ------------------------------- const char* defCent = DefaultCentBins(); FromOption(task, "CentralityMethod","cent", "V0M"); FromOption(task, "CentralityAxis", "cent-bins", defCent); FromOption(task, "AbsMinCent", "abs-min-cent", -1.); FromOption(task, "MaxNTracklet", "max-ntracklet", 6000.); FromOption(task, "EtaAxis", "eta-bins", "r16:2"); FromOption(task, "IPzAxis", "ipz-bins", "u15"); FromOption(task, "DeltaCut", "delta-cut", 1.5); FromOption(task, "TailDelta", "tail-delta", 5.); FromOption(task, "TailMaximum", "tail-max", -1); FromOption(task, "MaxDelta", "max-delta", 25.); FromOption(task, "DPhiShift", "dphi-shift", 0.0045); FromOption(task, "ShiftedDPhiCut", "shifted-dphi-cut",-1.); FromOption(task, "WeightMask", "reweigh-mask", 0xFF); FromOption(task, "WeightVeto", "reweigh-veto", 0x0); SetOnTask (task, "WeightCalc", mcal); FromOption(task, "WeightInverse", "reweigh-inv", false); task->Print(""); }
void scalebins(const char* patORpfx, Double_t scale) { TRegexp reg(patORpfx, kFALSE); TList* list = gDirectory->GetList() ; TIterator* iter = list->MakeIterator(); TObject* obj = 0; while (obj = iter->Next()) { if (! obj->InheritsFrom(TH1::Class())) continue; TString name = obj->GetName(); if (TString(patORpfx).MaybeRegexp()) { if (TString(obj->GetName()).Index(reg) < 0 ) continue; } else if (! name.BeginsWith(patORpfx)) continue; Double_t binWidth, binContent, binError, newBinContent, newBinError; for (Int_t i = 1; i <= ((TH1*)obj)->GetNbinsX(); ++i) { binWidth = ((TH1*)obj)->GetBinWidth(i); binContent = ((TH1*)obj)->GetBinContent(i); binError = ((TH1*)obj)->GetBinError(i); newBinContent = (binContent*scale)/binWidth; newBinError = (binError*scale)/binWidth; ((TH1*)obj)->SetBinContent(i, newBinContent); ((TH1*)obj)->SetBinError(i, newBinContent); // Rename y axis with scale } } }
void yaxis(const char* patORpfx, const char* title) { TRegexp reg(patORpfx, kFALSE); TList* list = gDirectory->GetList() ; TIterator* iter = list->MakeIterator(); TObject* obj = 0; while (obj = iter->Next()) { if (! (obj->InheritsFrom(TH1::Class()) || obj->InheritsFrom(THStack::Class()))) continue; TString name = obj->GetName(); if (TString(patORpfx).MaybeRegexp()) { if (TString(obj->GetName()).Index(reg) < 0 ) continue; } else if (! name.BeginsWith(patORpfx)) continue; if (obj->InheritsFrom(TH1::Class())) ((TH1*)obj)->GetYaxis()->SetTitle(title); if (obj->InheritsFrom(THStack::Class())) { ((THStack*)obj)->Draw(); ((THStack*)obj)->GetYaxis()->SetTitle(title); } } }
Bool_t KVDMS::IsContainer(TString& line) const { // 'line' is a line in a directory listing // This method should return kTRUE if the line corresponds to a container return (line.BeginsWith("C-")); }
void scaleToRate(const char* collectionName, double rateFactor) { TRegexp reg(collectionName, kTRUE); // gDirectory->ls(); TList* list = gDirectory->GetList() ; TIterator* iter = list->MakeIterator(); TObject* obj = 0; while (obj = iter->Next()) { if (! obj->InheritsFrom(TH1::Class())) { // cout << "bugger" << endl; continue; } TString name = obj->GetName(); cout << "Testing name: " << name << " against " << collectionName << endl; if (TString(collectionName).MaybeRegexp()) { cout << "we have a possible match" << endl; cout << "Trying to match to " << TString(obj->GetName()) << endl; if (TString(obj->GetName()).Index(reg) < 0 ) { cout << "failure here. Argument returns " << TString(obj->GetName()).Index(reg) << endl; continue; } } else if (! name.BeginsWith(collectionName)) continue; cout << "We're trying to scale" << name << endl; ((TH1*)obj)->Scale(rateFactor); } }
/** * Get the method identifier * * @param method Method * * @return Method identifier */ static UInt_t MethodId(TString& method) { struct Method { UInt_t id; TString name; }; const Method methods[] = { {RooUnfold::kNone, "None"}, {RooUnfold::kBayes, "Bayes"}, {RooUnfold::kSVD, "SVD"}, {RooUnfold::kBinByBin,"BinByBin"}, {RooUnfold::kTUnfold, "TUnfold"}, {RooUnfold::kInvert, "Invert"}, {RooUnfold::kDagostini,"Dagostini"}, {0xDeadBeef, "unknown"} }; const Method* pMethod = methods; while (pMethod->id != 0xDeadBeef) { if (method.BeginsWith(pMethod->name, TString::kIgnoreCase)) { method = pMethod->name; break; } pMethod++; } if (pMethod->id == 0xDeadBeef) Error("MethodId", "Unknown unfolding method: %s", method.Data()); return pMethod->id; }
void FinishBatch(TString sInput="", TString sOutput="ARHist"){ // Stuff to do at the end of an analysis run // Here all spectra are saved to disk printf("Events: %d Events Accepted: %d\n", gAN->GetNEvent(), gAN->GetNEvAnalysed() ); printf("End-of-Run macro executing\n"); TString sDir = gAR->GetTreeDir(); TString sFile; if (gAR->IsOnline()) sFile = gAR->GetFileName(); else sFile = gAR->GetTreeFile()->GetName(); while(sFile.Contains("/")) sFile.Remove(0,1+sFile.Index("/")); sFile.ReplaceAll(".dat",".root"); if(sInput.Length() && sFile.BeginsWith(sInput)) sFile.Remove(0,sInput.Length()); else sFile.Prepend("_"); sFile.Prepend(sOutput); sFile.Prepend(sDir); // Save histograms to file and close it TFile f(sFile, "recreate"); if( !f ){ printf("Open file %s for histogram save FAILED!!\n",sFile.Data()); return; } gROOT->GetList()->Write(); f.Close(); printf("All histograms saved to %s\n",sFile.Data()); if (!(gAR->IsOnline())) gSystem->Exit(0); }
void KVDMSDataRepository::DeleteFile(KVDataSet*ds, const Char_t * datatype, const Char_t * filename, Bool_t confirm) { //Delete repository file [datasetdir]/[datatypedir]/[filename] // //By default (confirm=kTRUE) we ask for confirmation before deleting. //Set confirm=kFALSE to delete without confirmation (DANGER!!!) TString path, tmp; AssignAndDelete(path, gSystem->ConcatFileName(fAccessroot.Data(), ds->GetDataPathSubdir())); AssignAndDelete(tmp, gSystem->ConcatFileName(path.Data(), ds->GetDataTypeSubdir(datatype))); AssignAndDelete(path, gSystem->ConcatFileName(tmp.Data(), filename)); TString cmd; cout << "Deleting file from repository: " << filename << endl; if (confirm) { cout << "Are you sure you want to delete this file permanently ? (y/n)" << endl; TString answer; cin >> answer; answer.ToUpper(); if (!answer.BeginsWith("Y")) { cout << "File not deleted" << endl; return; } } fDMS->forcedelete(path.Data()); }
Bool_t SETUP_LoadLibraries(const TString &libs) { // Loads a list of colon-separated libraries. Returns kTRUE on success, kFALSE // if at least one library couldn't load properly. Does not check for double // loads (but ROOT does). TString l; Ssiz_t from; while ( libs.Tokenize(l, from, ":") ) { if (l.IsNull()) continue; if (!l.BeginsWith("lib")) l.Prepend("lib"); if (l.EndsWith(".so")) l.Remove(l.Length()-3, l.Length()); ::Info(gMessTag.Data(), ">> Loading library %s...", l.Data()); if (gSystem->Load(l.Data()) < 0) { ::Error(gMessTag.Data(), "Error loading %s, aborting", l.Data()); return kFALSE; // failure } } return kTRUE; // success return 0; }
void GausBF::Print(Option_t *option) const { TString sopt = option; sopt.ToLower(); if (sopt == "dump") { for (Int_t i = 0; i < Ns1*Ns9*Np; i++) { cout << Form(" %10.3e,", _par[i]); if (i%6 == 5) cout << endl; } cout << endl; } if (sopt.BeginsWith("p")) { TString ss = sopt(1, 2); if (ss.IsDigit()) { Int_t ip = ss.Atoi(); if (0 <= ip && ip < Np) for (Int_t i = 0; i < Ns1; i++) { for (Int_t j = 0; j < Ns9; j++) { AMSPoint p1 = GetP1(i); AMSPoint p9 = GetP9(j); cout << Form("%3d %3d %6.2f %6.2f %7.2f %7.2f %10.3e", i, j, p1.x(), p1.y(), p9.x(), p9.y(), _par[(i*Ns9+j)*Np+ip]) << endl; } } } } }
Bool_t KVAvailableRunsFile::CheckAvailable(Int_t run) { //Look for a given run number in the file //If run not found, returns kFALSE //If available runs file does not exist, Update() is called to create it. //does runlist exist ? if (!OpenAvailableRunsFile()) { Error("CheckAvailable", "Error opening available runs file"); return kFALSE; } //loop over lines in runlist file //look for line beginning with 'run|' Bool_t found = kFALSE; TString line; line.ReadLine(fRunlist); while (fRunlist.good()) { if (line.BeginsWith(Form("%d|", run))) { CloseAvailableRunsFile(); return kTRUE; } line.ReadLine(fRunlist); } CloseAvailableRunsFile(); return found; }
//____________________________________________ TChain* MakeChainLST(const char* filename) { // Create the chain TChain* chain = new TChain("esdTree"); if(!filename){ chain->Add(Form("%s/AliESDs.root", gSystem->pwd())); return chain; } // read ESD files from the input list. FILE *fp(NULL); if(!(fp = fopen(filename, "rt"))){ Error("run::MakeChainLST()", Form("Input list \"%s\" not readable", filename)); return NULL; } TString esdFile; while(esdFile.Gets(fp)){ if (!esdFile.Contains("root")) continue; // protection if(esdFile.BeginsWith("alien://") && !gGrid){ if(gSystem->Load("libNetx.so")<0) return NULL; if(gSystem->Load("libRAliEn.so")<0) return NULL; TGrid::Connect("alien://"); } chain->Add(esdFile.Data()); } fclose(fp); return chain; }
void Correlation::Get2DHist(TString var1, TString var2) { TCanvas* c = new TCanvas("c","",700,700); t_host->Draw(var1+".value:"+var2+".value","","colz"); TH2F* h2 = (TH2F*) t_host->GetHistogram(); // returns the last drawn histogram double correlation = h2->GetCorrelationFactor(); results[var1][var2] = correlation; if((var1.BeginsWith("A")==1 || var1.BeginsWith("R")==1)) { if(observables.empty()) observables.push_back(var1); else if(observables.back()!=var1) observables.push_back(var1); } if((var1.BeginsWith("A")==1 || var1.BeginsWith("R")==1) && (var2.BeginsWith("A")==1 || var2.BeginsWith("R")==1)) { c->SaveAs("correlations/"+var1+"_"+var2+".pdf"); } delete h2; delete c; }
void normalize(const char* patORpfx) { TRegexp reg(patORpfx, kFALSE); TList* list = gDirectory->GetList() ; TIterator* iter = list->MakeIterator(); TObject* obj = 0; while (obj = iter->Next()) { if (! obj->InheritsFrom(TH1::Class())) continue; TString name = obj->GetName(); if (TString(patORpfx).MaybeRegexp()) { if (TString(obj->GetName()).Index(reg) < 0 ) continue; } else if (! name.BeginsWith(patORpfx)) continue; Double_t integral = 0; if (obj->InheritsFrom(TH2::Class())) integral = ((TH2*)obj)->Integral(); else integral = ((TH1*)obj)->Integral(); if (integral) { ((TH1*)obj)->Sumw2(); ((TH1*)obj)->Scale(1./integral); } } }
/** * Compare results * * @param argv Commmand line parameters * * @relates Compare * @ingroup pwglf_forward_tracklets */ void CompareResults(const char** argv) { TString newFile; TString oldFile; TString newTit(""); TString oldTit(""); const char** ptr = argv; while ((*ptr)) { TString argi = *ptr; ptr++; if (argi.Contains("help")) { Printf("Usage: CompareResults AFILE BFILE [ATITLTE [BTITLE]]"); return; } if (argi.Contains("CompareResults.C")) continue; if (argi.BeginsWith("-")) continue; if (argi.EndsWith(".root")) { if (newFile.IsNull()) newFile = argi; else oldFile = argi; } else { if (newTit.IsNull()) newTit = argi; else oldTit = argi; } } if (newTit.IsNull()) newTit = "New"; if (oldTit.IsNull()) oldTit = "Old"; CompareResults(newFile, oldFile, newTit, oldTit); }
IonisationChamberv::IonisationChamberv(LogFile* Log) { #ifdef DEBUG cout << "IonisationChamberv::Constructor" << endl; #endif Ready = kFALSE; L = Log; NbChio = gEnv->GetValue("VAMOS.NbIC", -1); if (NbChio < 0) { cout << "Not Reading VAMOS.NbIC in IonisationChamberv Class" << endl; } //energy Raw E_Raw = new UShort_t[NbChio]; E_Raw_Nr = new UShort_t[NbChio]; IcRaw = new Int_t[NbChio]; DetChio = new Int_t [NbChio]; //Calibration coeff a = new Float_t[NbChio]; b = new Float_t[NbChio]; Vnorm = new Float_t[NbChio]; //energy Calibrated E = new Float_t[NbChio]; InitSavedQuantities(); Init(); Rnd = new Random; ifstream inf; Int_t num = 0; Float_t dummy1, dummy2, dummy3; TString sline; if (!gDataSet->OpenDataSetFile("IonisationChamber.cal", inf)) { cout << "Could not open the calibration file IonisationChamber.cal !" << endl; return; } else { cout << "Reading IonisationChamber.cal" << endl; while (!inf.eof()) { sline.ReadLine(inf); if (!inf.eof()) { if (!sline.BeginsWith("#")) { sscanf(sline.Data(), "%d %f %f %f", &num, &dummy1, &dummy2, &dummy3); a[num] = dummy1; b[num] = dummy2; Vnorm[num] = dummy3; } } } } inf.close(); Ready = kTRUE; }
void KVAvailableRunsFile::GetRunInfos(Int_t run, KVList * dates, KVList * files) { //Look for a given run number in the file, and read the file's modification date/time and filename //These informations are stored in the two TList as TObjString objects (these objects belong to the //lists and will be deleted by them). //We do not stop at the first run found, but continue until the end of the file, adding //informations for every occurence of the run in the file. //If available runs file does not exist, Update() is called to create it. //does runlist exist ? if (!OpenAvailableRunsFile()) { Error("GetRunInfos", "Error opening available runs file"); return; } //clear lists - delete objects dates->Delete(); files->Delete(); //loop over lines in fRunlist file //look for line beginning with 'run|' TString line; line.ReadLine(fRunlist); while (fRunlist.good()) { if (line.BeginsWith(Form("%d|", run))) { //found it TObjArray *toks = line.Tokenize('|'); // split into fields // check date is not identical to a previous entry // i.e. there are spurious duplicate entries TObjString* rundate = (TObjString*)toks->At(1)->Clone(); if(dates->FindObject(rundate->GetName())){ delete toks; delete rundate; line.ReadLine(fRunlist); continue; } //add date string dates->Add(toks->At(1)->Clone()); //backwards compatibility //an old available_runs file will not have the filename field //in this case we assume that the name of the file is given by the //dataset's base file name (i.e. with no date/time suffix) if (toks->GetEntries() > 2) { files->Add(toks->At(2)->Clone()); } else { files-> Add(new TObjString(fDataSet-> GetBaseFileName(GetDataType(), run))); } delete toks; } line.ReadLine(fRunlist); } CloseAvailableRunsFile(); }
void drawsame(const char* canvasName, const char* patORpfx,Option_t* drawOption = "") { // cout << "testing this method" << endl; TRegexp reg(patORpfx, kFALSE); TList* list = gDirectory->GetList() ; // cout << "this bleeping directory has " << gDirectory->GetNkeys() << "things in it" << endl; TIterator* iter = list->MakeIterator(); TObject* obj = 0; TObject* canvas = 0; Bool_t makeCanvas = false; canvas = gROOT->GetListOfCanvases()->FindObject(canvasName); //If canvas does not exist, remember to create it // cout << "found our canvas" << endl; if (! canvas) makeCanvas = true; while (obj = iter->Next()) { // cout << "We have an object" << endl; if (! obj->InheritsFrom(TH1::Class())) continue; TString name = obj->GetName(); // cout << "Testing object of name " << name << endl; // if (TString(patORpfx).MaybeRegexp()) { THIS BASICALLY ADDS IT IF IT HAS A BLEEPING PULSE if (TString(name).Contains(patORpfx)) { // cout << "possible match" << endl; if (TString(obj->GetName()).Index(reg) < 0 ) { // cout << "not a match here" << endl; continue; } else if (! name.BeginsWith(patORpfx)) { // cout << "mismatched beginning" << endl; continue; } if (makeCanvas) { canvas = new TCanvas(canvasName, canvasName); makeCanvas = false; } ((TH1*)obj)->UseCurrentStyle(); ((TCanvas*)canvas)->cd(); if (!((TCanvas*)canvas)->GetListOfPrimitives()->GetEntries()) { // cout << "Drawing with non-same option" << endl; ((TH1*)obj)->Draw(Form("%s", drawOption)); } else { // cout << "Drawing with the same option" << endl; ((TH1*)obj)->Draw(Form("SAME%s", drawOption)); } } } hist::colors((TCanvas*)canvas); }
void runTree(char* dir="hist_pAu2", char* filter="16142010", unsigned int neventsIn = 0){ // If nEvents is negative, reset to the maximum possible value for an Int_t if( neventsIn <= 0 ) neventsIn = 1<<31-1; TSystemDirectory DIR(dir, dir); TList *files = DIR.GetListOfFiles(); TChain* trees = new TChain(); int nfile=0; if (files) { TSystemFile *file; TString fname; TIter next(files); while ((file=(TSystemFile*)next())) { fname = file->GetName(); if (!file->IsDirectory() && fname.BeginsWith(filter) && fname.EndsWith("tree.root")) { cout << Form("Adding %s/%s to TChain",dir,fname.Data())<<endl; trees->AddFile(Form("%s/%s/dipi0",dir,fname.Data())); nfile++; } } } cout << Form("%d files added",nfile) << endl; // load the shared libraries std::cout << "***** Loading libraries *****" << endl; LoadLibs(); // Create the analysis chain analysisChain = new StChain("dipi0Chain"); //cout << "Constructing StFmsDbMaker" << endl; //StFmsDbMaker* fmsDbMkr = new StFmsDbMaker( "fmsDb" ); //fmsDbMkrName = fgtDbMkr->GetName(); gSystem->Load("StFmsDiPi0"); StFmsDiPi0* dipi0=new StFmsDiPi0; TString filenameDiPi0(Form("%s/%s.dipi0.root",dir,filter)); cout << "DiPi0 outfile name = " << filenameDiPi0.Data()<<endl; dipi0->setFileName(filenameDiPi0.Data()); dipi0->setReadTree(trees); analysisChain->Init(); Int_t ierr = kStOK; // err flag Int_t nevents = 0; // cumulative number of events in for( ; nevents < neventsIn && !ierr; ++nevents ){ if(nevents%10000==0) cout <<"event: "<< nevents <<endl; analysisChain->Clear(); ierr = analysisChain->Make(); } analysisChain->Finish(); analysisChain->Delete(); return; };
void takeDirectlyFromMC(TFile* fin, TFile* fout, TString gentype) { TList* listOfDirs = fin->GetListOfKeys(); for (auto k : *listOfDirs) { TString srname = k->GetName(); if (!srname.Contains("sr")) continue; if (srname.Contains("base") || srname.Contains("incl") || srname.Contains("sb")) continue; if (gentype == "_1lepW" && !srname.EndsWith("2") && !srname.EndsWith("3")) continue; auto indir = (TDirectoryFile*) fin->Get(srname); auto outdir = (TDirectory*) fout->mkdir(srname); auto hlist = indir->GetListOfKeys(); for (auto h : *hlist) { TString hname = h->GetName(); if (!hname.BeginsWith("h_metbins" + gentype)) continue; TH1D* hin = (TH1D*) indir->Get(hname); outdir->cd(); TH1D* hout = (TH1D*) hin->Clone(TString(hname).ReplaceAll(gentype, "")); for (int i = 1; i <= hout->GetNbinsX(); ++i) { // zero out negative yields if (hout->GetBinContent(i) < 0) { hout->SetBinContent(i, 0); hout->SetBinError(i, 0); } } hout->Write(); if (yearSeparateSyst && (hname.EndsWith("Up") || hname.EndsWith("Dn"))) { for (int i = 1; i < 4; ++i) { TH1D* hcen_yi = (TH1D*) fbkgs[i]->Get(srname+"/h_metbins"+gentype); TH1D* hsys_yi = (TH1D*) fbkgs[i]->Get(srname+"/"+hname); if (hsys_yi && !hcen_yi) { cout << "Find " << srname+"/"+hname << " from " << fbkgs[i]->GetName() << " but not hcen " << srname+"/h_metbins"+gentype << " Should not happen?" << endl; } TH1D* hout_yi = (TH1D*) fin->Get(srname+"/h_metbins"+gentype)->Clone(TString(hname).Insert(hname.Length()-2, Form("%d", 15+i)).ReplaceAll(gentype, "")); if (hcen_yi) hout_yi->Add(hcen_yi, -1); if (hsys_yi) hout_yi->Add(hsys_yi); hout_yi->Write(); } } } if (!outdir->Get("h_metbins")) { cout << "Didn't find yield hist for " << gentype << " in " << fin->GetName() << ":" << srname << "/. Faking a 0 one!" << endl; outdir->cd(); // Get the MET binning from h_metbins, which shall always exist, and then set all bins to 0 TH1D* hout = (TH1D*) fin->Get(srname + "/h_metbins")->Clone("h_metbins"); for (int i = 1; i <= hout->GetNbinsX(); ++i) { hout->SetBinContent(i, 0); hout->SetBinError(i, 0); } hout->Write(); } } }
TGeoVolume* KVGeoNavigator::GetCurrentDetectorNameAndVolume(KVString& detector_name, Bool_t& multilayer) { // Returns the name of the current detector (if we are inside a detector) // and whether it is a multilayer or simple detector. // Returns 0x0 if we are not inside a detector volume. // // N.B. the returned volume corresponds to the *whole* detector (even if it has several layers). // For a multilayer detector, GetCurrentVolume() returns the volume for the current layer. // // See ExtractDetectorNameFromPath(KVString&) for details on detector name formatting. // Info("GetCurrentDetectorNameAndVolume","now i am in %s on node %s with path %s and matrix:", // fCurrentVolume->GetName(),fCurrentNode->GetName(),fCurrentPath.Data()); // fCurrentMatrix.Print(); multilayer = kFALSE; fCurrentDetectorNode = 0; TString volNom = GetCurrentVolume()->GetName(); TGeoVolume* detector_volume = 0; if (volNom.BeginsWith("DET_")) { // simple detector fCurrentDetectorNode = GetCurrentNode(); detector_volume = GetCurrentVolume(); } else { // have we hit 1 layer of a multilayer detector? TGeoVolume* mother_vol = GetCurrentNode()->GetMotherVolume(); if (mother_vol) { TString mom = mother_vol->GetName(); if (mom.BeginsWith("DET_")) { // it *is* a multilayer detector (youpi! :-) if (fMotherNode) { // this is the node corresponding to the whole detector, fCurrentDetectorNode = fMotherNode; detector_volume = mother_vol; multilayer = kTRUE; } } } } if (detector_volume) ExtractDetectorNameFromPath(detector_name); return detector_volume; }
void MakeMFTZeroMisAlignment(TString Storage = "alien://folder=/alice/cern.ch/user/a/auras/OCDB/") { // Create TClonesArray of zero misalignment objects for MFT const char* macroname = "MakeMFTZeroMisAlignment.C"; TClonesArray *array = new TClonesArray("AliAlignObjParams",10); TClonesArray &alobj = *array; Double_t dx=0, dy=0, dz=0, dpsi=0, dtheta=0, dphi=0; Int_t iIndex=0; AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,iIndex); TString MFT("MFT"); new (alobj[0]) AliAlignObjParams(MFT.Data(), volid, dx, dy, dz, dpsi, dtheta, dphi, kTRUE); // save in CDB storage if(!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) { Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()); return; } Info(macroname,"Saving alignment objects in CDB storage %s", Storage.Data()); AliCDBManager* cdb = AliCDBManager::Instance(); AliCDBStorage* storage = cdb->GetStorage(Storage.Data()); if(!storage){ Error(macroname,"Unable to open storage %s\n",Storage.Data()); return; } AliCDBMetaData* md = new AliCDBMetaData(); md->SetResponsible("Antonio Uras"); md->SetComment("Alignment objects for MFT zero-misalignment"); md->SetAliRootVersion(gROOT->GetVersion()); AliCDBId id("MFT/Align/Data",0,AliCDBRunRange::Infinity()); storage->Put(array,id,md); array->Delete(); }
//________________________________________________________________________________ TChain* CreateChainTXT(const char* inpData) { const char* chName="esdTree"; TChain* chain = new TChain(chName); // TString inpDtStr = inpData; if (inpDtStr.EndsWith(".root")) { chain->AddFile(inpData); } else { // ifstream inpf(inpData); if (!inpf.good()) { printf("Failed on input filename %s\n",inpData); return kFALSE; } // TString flName; flName.ReadLine(inpf); while ( !flName.IsNull() ) { flName = flName.Strip(TString::kBoth,' '); if (flName.BeginsWith("//") || flName.BeginsWith("#")) {flName.ReadLine(inpf); continue;} flName = flName.Strip(TString::kBoth,','); flName = flName.Strip(TString::kBoth,'"'); if (flName.EndsWith("Barrel.root")) barrelFlag = kTRUE; printf("Adding %s\n",flName.Data()); chain->AddFile(flName.Data()); flName.ReadLine(inpf); } } // int n = chain->GetEntries(); if (n<1) { printf("Obtained chain is empty\n"); return kFALSE; } printf("Created chain with %d entries in %d trees from %s\n",chain->GetEntries(),chain->GetNtrees(),inpData); return chain; }
int currentUnits( TH1& h1 ) { TString ss( h1.GetYaxis()->GetTitle() ); ss.ReplaceAll ("_{T}", "_%@#"); // otherwise it messes up the reg. exp. // all backslashes are doubled, to get by the compiler string parsing, leaving \[ for TRegexp --> literal [s & ]s int iOpenBracket = ss.Index (TRegexp ("\\[[^\\]]*\\][^\\[\\]]*$"));// That is, the start of the last square brackets int iCloseBracket = ss.Last(']'); // no need for quotes with char if( iOpenBracket < 0 || iCloseBracket <= iOpenBracket ) { // can't find units return -666; } // parse input units TString inputUnits = ss( 1+iOpenBracket, -1 + iCloseBracket - iOpenBracket); int curPrefix = 0; if( inputUnits.BeginsWith( "m" ) ) curPrefix = -3; if( inputUnits.BeginsWith( "#mu" ) ) curPrefix = -6; if( inputUnits.BeginsWith( "n" ) ) curPrefix = -9; if( inputUnits.BeginsWith( "p" ) ) curPrefix = -12; if( inputUnits.BeginsWith( "f" ) ) curPrefix = -15; if( inputUnits.BeginsWith( "k" ) ) curPrefix = 3; return curPrefix; }
//_____________________________________________________________________________ THaCut::EvalMode THaCut::ParsePrefix( TString& expr ) { // Parse the given expression for a mode prefix (e.g. "OR:") // and return its value. If the expression does not have a mode prefix, // return the default kAND (=0). // The expression is expected to have all whitespace removed. // If the prefix was found, it is stripped from the expression. // If a mode prefix seems to be present, but is not found in // the defined modes, return kModeErr. const EvalMode kDefaultMode = kOR; const char* const here = "THaCut"; struct ModeDef_t { const char* prefix; EvalMode mode; }; const ModeDef_t mode_defs[] = { { "OR", kOR }, { "ANY", kOR }, { "AND", kAND }, { "ALL", kAND }, { "XOR", kXOR }, { "ONE", kXOR }, { "ONEOF", kXOR }, { 0, kModeErr } }; Ssiz_t colon = expr.Index(":"); if( colon == kNPOS ) return kDefaultMode; const ModeDef_t* def = mode_defs; while( def->prefix ) { if( expr.BeginsWith(def->prefix) && static_cast<Ssiz_t>(strlen(def->prefix)) == colon ) { expr.Remove(0,colon+1); break; } ++def; } EvalMode mode = def->mode; if( mode == kModeErr ) { TString prefix = expr(0,colon); Error(here, "Unknown prefix %s", prefix.Data() ); } else if( expr.Length() == 0 ) { Error(here, "expression may not be empty"); mode = kModeErr; } if( mode == kModeErr ) SetBit(kError); return mode; }
void get_filenames(vector<TString> &names, const char *dirname=".", const char *ext=".root", const char *prefix = "uhh2") { TSystemDirectory dir(dirname, dirname); TList *files = dir.GetListOfFiles(); if (files) { TSystemFile *file; TString fname; TIter next(files); while ((file=(TSystemFile*)next())) { fname = file->GetName(); if (!file->IsDirectory() && fname.EndsWith(ext) && fname.BeginsWith(prefix)) { names.push_back(TString(fname.Data())); } } } }