TChain * GetAnalysisChain(const char * incollection){ // Builds a chain of esd files // incollection can be // - a single root file // - an xml collection of files on alien // - a ASCII containing a list of local root files TChain* analysisChain = 0; // chain analysisChain = new TChain("esdTree"); if (TString(incollection).Contains(".root")){ analysisChain->Add(incollection); } else if (TString(incollection).Contains("xml")){ TGrid::Connect("alien://"); TAlienCollection * coll = TAlienCollection::Open (incollection); while(coll->Next()){ analysisChain->Add(TString("alien://")+coll->GetLFN()); } } else { ifstream file_collect(incollection); TString line; while (line.ReadLine(file_collect) ) { analysisChain->Add(line.Data()); } } analysisChain->GetListOfFiles()->Print(); return analysisChain; }
//_________________________________________________________________________________________________ TChain* CreateChainFromXML (const char *xmlFileName, const char *treeName, Int_t nread, Int_t nskip) { // // Create a TChain with all required files listed into an XML collection. // Necessary to run analysis in AliEn jobs. // --- // Arguments: // - xmlFileName = input list // - treeName = "esdTree" or "aodTree" // - nread = how many files to read (0 = all) // - nskip = how many files to skip from beginning // // if nread argument is 0, it is disabled if (nread == 0) nread = 1000000000; // initialize output object TChain *chain = new TChain(treeName); // initialize the AliEn collection TAlienCollection *myCollection = TAlienCollection::Open(xmlFileName); if (!myCollection) { Error("CreateChainFromXML", "Cannot create an AliEn collection from %s", xmlFileName); return 0x0; } // loop on collection myCollection->Reset(); while (myCollection->Next()) { // skip until reached required number of offset if (nskip > 0) {--nskip; continue;} // stop if required number of read files is reached // otherwise update the counter if (nread <= 0) break; nread--; // recovery file and add it Info("CreateChainFromXML", Form("Adding: %s", myCollection->GetTURL(""))); chain->Add(myCollection->GetTURL("")); } return chain; }
//________________________________________________________________________________ TChain* CreateChainXML(const char *xmlfile) { // Create a chain using url's from xml file TString filename; Int_t run = 0; TString treename = "esdTree"; printf("***************************************\n"); printf(" Getting chain of trees %s\n", treename.Data()); printf("***************************************\n"); TAlienCollection *coll = TAlienCollection::Open(xmlfile); if (!coll) { ::Error("CreateChain", "Cannot create an AliEn collection from %s", xmlfile); return NULL; } AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); TChain *chain = new TChain(treename); coll->Reset(); while (coll->Next()) { filename = coll->GetTURL(); if (filename.EndsWith("Barrel.root")) barrelFlag = kTRUE; if (mgr) { Int_t nrun = AliAnalysisManager::GetRunFromAlienPath(filename); if (nrun && nrun != run) { printf("### Run number detected from chain: %d\n", nrun); mgr->SetRunFromPath(nrun); run = nrun; } } chain->Add(filename); } if (!chain->GetNtrees()) { ::Error("CreateChain", "No tree found from collection %s", xmlfile); return NULL; } printf("Created chain with %d entries in %d trees from %s\n",chain->GetEntries(),chain->GetNtrees(),xmlfile); return chain; }
// macro principale che fa il loop sugli eventi e scrive il file Bool_t CheckESD(const char *lista="wn.xml",Bool_t kGRID=1) //per prendere dalla grid; //Bool_t CheckESD(const char *lista="lista",Bool_t kGRID=0) // da locale { char name[300]; Int_t ifile = 0; Int_t nmaxfile = 200000000; // to limit the number of ESD files //T->Branch("nevento",&nevento,"nevento/I"); T->Branch("kTOFout",&TOFout,"kTOFout/I"); T->Branch("ncluster",&ncluster,"ncluster/I"); T->Branch("tempo",tempo,"tempo[ncluster]/F"); if(isMC) T->Branch("pdg",&pdg,"pdg/I"); if(isMC) T->Branch("gtime",>ime,"gtime/F"); if(isMC) T->Branch("DXtrue",&dxt,"DXtrue/F"); if(isMC) T->Branch("DZtrue",&dzt,"DZtrue/F"); T->Branch("DeltaX",DeltaX,"DeltaX[ncluster]/F"); T->Branch("DeltaZ",DeltaZ,"DeltaZ[ncluster]/F"); T->Branch("exp_time_el",exp_time_el,"exp_time_el[ncluster]/F"); T->Branch("exp_time_mu",exp_time_mu,"exp_time_mu[ncluster]/F"); T->Branch("exp_time_pi",exp_time_pi,"exp_time_pi[ncluster]/F"); T->Branch("exp_time_ka",exp_time_ka,"exp_time_ka[ncluster]/F"); T->Branch("exp_time_pr",exp_time_pr,"exp_time_pr[ncluster]/F"); T->Branch("L",L,"L[ncluster]/F"); T->Branch("TOT",tot,"TOT[ncluster]/F"); T->Branch("ChannelTOF",ChannelTOF,"ChannelTOF[ncluster]/I"); T->Branch("impulso",&impulso,"impulso/F"); T->Branch("impulso_trasv",&impulso_trasv,"impulso_trasv/F"); T->Branch("res",res,"res[3]/F"); T->Branch("charge",&charge,"charge/I"); T->Branch("phi",&phi,"phi/F"); T->Branch("eta",&eta,"eta/F"); T->Branch("phiExt",&phiExt,"phiExt/F"); T->Branch("etaExt",&etaExt,"etaExt/F"); T->Branch("secPhi",&secAngle,"secPhi/F"); T->Branch("cval",cval,"cval[5]/F"); T->Branch("mism",&mism,"mism/I"); T->Branch("ntofcl",&ntofcl,"ntofcl/I"); T->Branch("dedx",&dedx,"dedx/F"); T->Branch("StartTime",&StartTime,"StartTime/F"); T->Branch("StartTimeRes",&StartTimeRes,"StartTimeRes/F"); T->Branch("rTOF",&rTOFused,"rTOF/F"); if(isMC) T->Branch("InteractionTime",&interactiontime,"InteractionTime/F"); T->Branch("tempoTrig",&timetrig,"tempoTrig/F"); if(! kGRID){ FILE *fin = fopen (lista,"r"); while(fscanf(fin,"%s",name)==1 && ifile < nmaxfile){ CheckSingle(name,kGRID),ifile++; printf("file %i done\n",ifile); system("date"); } fclose(fin); } else{ TGrid::Connect("alien://"); TAlienCollection *myCollection = (TAlienCollection *) TAlienCollection::Open(lista); if (!myCollection) { Error("CheckESD.C", Form("Cannot create an AliEn collection from %s", lista)); return 1; } myCollection->Reset(); while (myCollection->Next() && ifile < nmaxfile){ CheckSingle(myCollection->GetTURL("")),ifile++; printf("file %i done\n",ifile); system("date"); } } fotree->cd(); T->Write(); //scrivo tree fotree->Close(); }
void raw2treeGrid_collection() { // reading RAW data from test LCS // filling histograms // fillinf tree // gROOT->LoadMacro("loadlibs.C"); // loadlibs(); Int_t allData[220][5]; TGrid::Connect("alien://"); TTree *fT0OutTree=new TTree("t0tree","None here"); TAlienCollection *collnum = TAlienCollection::Open("wn.xml"); Int_t numrun; collnum->Reset(); collnum->Next(); TString buf_runnum; TString buf_path = collnum->GetTURL() ; for(int i=0; i<buf_path.Length();i++) { if(buf_path(i,4)=="/raw") { buf_runnum = buf_path(i-6,6); numrun = buf_runnum.Atoi(); break; } } TString names[220]; Int_t chvalue[220], meanchvalue[220]; AliT0LookUpKey* lookkey= new AliT0LookUpKey(); AliT0LookUpValue* lookvalue= new AliT0LookUpValue(); AliCDBManager * man = AliCDBManager::Instance(); man->SetDefaultStorage("raw://"); man->SetRun(numrun); AliT0Parameters *fParam = AliT0Parameters::Instance(); fParam->Init(); TMap *lookup = fParam->GetMapLookup(); TMapIter *iter = new TMapIter(lookup); for( Int_t iline=0; iline<212; iline++) { lookvalue = ( AliT0LookUpValue*) iter->Next(); lookkey = (AliT0LookUpKey*) lookup->GetValue((TObject*)lookvalue); if(lookkey){ Int_t key=lookkey->GetKey(); names[key]=lookkey->GetChannelName(); fT0OutTree->Branch(Form("%s",names[key].Data()), &chvalue[key]); } else {printf(" no such value %i \n", iline);} } Float_t meanCFD[24], meanQT1[24]; for (int ich=0; ich<24; ich++) { meanCFD[ich] = fParam->GetCFD(ich); meanQT1[ich] = fParam->GetQT1(ich); } Float_t meanOrA = fParam->GetMeanOrA(); Float_t meanOrC = fParam->GetMeanOrC(); Float_t meanTVDC = fParam->GetMeanVertex(); //new QTC Float_t qt01mean[28] = {18712.5, 18487.5, 18487.5, 18537.5, 18562.5, 18462.5, 18537.5, 18537.5, 18537.5, 18587.5, 18587.5, 18512.5, 18512.5, 18512.5, 18487.5, 18562.5, 18537.5, 18512.5, 18537.5, 18537.5, 18512.5, 18587.5, 18562.5, 18512.5, 18358, 18350, 18374, 18362}; Float_t qt11mean[28] = {18705, 18495, 18465, 18555, 18555, 18435, 18525, 18525, 18525, 18585, 18585, 18495, 18495, 18525, 18465, 18555, 18525, 18495, 18555, 18495, 18495, 18585, 18585, 18495, 18358, 18350, 18374, 18362}; Int_t ind[26]; for (int iii=0; iii<12; iii++) ind[iii]=25; for (int iii=12; iii<24; iii++) ind[iii]=57; UInt_t event; fT0OutTree->Branch("event", &event); ULong64_t triggerMask; fT0OutTree->Branch("triggers", &triggerMask); TAlienCollection *coll = TAlienCollection::Open("wn.xml"); coll->Reset(); AliRawReader *reader; while (coll->Next()) { TString fFileName=coll->GetTURL(); //READ DATA // TString fFileName=Form("alien:///alice/data/2015/LHC15i/000%i/raw/15000%i028.%i.root", numrun, numrun, chunk); reader = new AliRawReaderRoot(fFileName); if(!reader) continue; reader = new AliRawReaderRoot(fFileName); if(!reader) continue; // reader->LoadEquipmentIdsMap("T0map.txt"); reader->RequireHeader(kTRUE); for (Int_t i0=0; i0<220; i0++) { chvalue[i0] = 0; for (Int_t j0=0; j0<5; j0++) allData[i0][j0]=0; } AliT0RawReader *start = new AliT0RawReader(reader); while (reader->NextEvent()) { start->Next(); for (Int_t ii=0; ii<211; ii++) { chvalue[ii] = 0; for (Int_t iHit=0; iHit<5; iHit++) { allData[ii][iHit]= start->GetData(ii,iHit); // if(allData[ii][iHit]>0) cout<<ii<<" "<<allData[ii][iHit]<<endl; } } const UInt_t type =reader->GetType(); if(type != 7) continue; triggerMask = reader->GetClassMask(); for (Int_t iHit=0; iHit<5; iHit++) { if( allData[50][iHit]>meanTVDC-800 && allData[50][iHit]<meanTVDC+800) { chvalue[50]=allData[50][iHit]; break; } } for (Int_t in=0; in<24; in++) { for (Int_t iHit=0; iHit<5; iHit++) //old QTC C side { if (allData[2*in+ind[in]+1][iHit] > meanQT1[in]-800 && allData[2*in+ind[in]+1][iHit] < meanQT1[in]+800 ) { chvalue[2*in+ind[in]+1] = allData[2*in+ind[in]+1][iHit]; break; } } for (Int_t iHit=0; iHit<5; iHit++) //old QTC A side { if( (allData[2*in+ind[in]][iHit] > chvalue[2*in+ind[in]+1]) && chvalue[2*in+ind[in]+1]>0) { chvalue[2*in+ind[in]] = allData[2*in+ind[in]][iHit]; // printf("index %i pmt %i QTC old start %i stop %i \n", // 2*in+ind[in], in, // chvalue[2*in+ind[in]+1], chvalue[2*in+ind[in]]); break; } } } for (Int_t in=0; in<12; in++) { chvalue[in+68+1] = allData[in+68+1][0] ; chvalue[in+12+1] = allData[in+12+1][0] ; for (Int_t iHit=0; iHit<5; iHit++) //CFD C side { if(allData[in+1][iHit] > meanCFD[in]-800 && allData[in+1][iHit] < meanCFD[in]+800) { chvalue[in+1] = allData[in+1][iHit] ; break; } } for (Int_t iHit=0; iHit<5; iHit++) //CFD A side { if(allData[in+1+56][iHit]>0) if(allData[in+1+56][iHit] > meanCFD[in+12]-800 && allData[in+1+56][iHit] < meanCFD[in+12]+800) { chvalue[in+1+56] = allData[in+56+1][iHit] ; break; } } } // new QTC Int_t pmt; for (Int_t ik=0; ik<106; ik+=4) { if (ik<48) pmt=ik/4; if (ik>47 && ik<52) pmt= 24; if (ik>51 && ik<56) pmt= 25; if(ik>55) pmt=(ik-8)/4; for(Int_t iHt = 0; iHt<5; iHt++) { if(allData[107+ik+1][iHt] > (qt01mean[pmt]-800) && allData[107+ik+1][iHt] < (qt01mean[pmt]+800) ) { chvalue[107+ik+1] = allData[107+ik+1][iHt]; // printf("start newQTC 00 ik %i iHt %i pmt %i QT00 %i QT01 %i \n", ik, iHt, pmt, allData[107+ik][iHt], allData[107+ik+1][iHt]); break; } } for(Int_t iHt = 0; iHt<5; iHt++) { if(allData[107+ik][iHt]>chvalue[107+ik+1] && chvalue[107+ik+1]>0) { chvalue[107+ik]=allData[107+ik][iHt] ; // printf("stop newQTC 00 ik %i iHt %i pmt %i QT00 %i QT01 %i \n", ik, iHt, pmt, allData[107+ik][iHt], allData[107+ik+1][iHt]); break; } } for(Int_t iHt = 0; iHt<5; iHt++) { if( allData[107+ik+3][iHt] > (qt11mean[pmt]-800) && allData[107+ik+3][iHt] < (qt11mean[pmt]+800) ) { chvalue[107+ik+3] = allData[107+ik+3][iHt]; break; } } for(Int_t iHt = 0; iHt<5; iHt++) { if( allData[107+ik+2][iHt] > chvalue[107+ik+3]&& chvalue[107+ik+3]>0 ) { chvalue[107+ik+2] = allData[107+ik+2][iHt]; // printf(" newQTC 11 ik %i iHt %i pmt %i QT10 %i QT11 %i \n", ik, iHt, pmt, allData[107+ik+2][iHt], allData[107+ik+3][iHt]); break; } } } //end new QTC // Or for(Int_t iHt = 0; iHt<5; iHt++) { if(allData[51][iHt]>meanOrA-800 && allData[51][iHt]<meanOrA+800) { chvalue[51]=allData[51][iHt]; break; } } for(Int_t iHt = 0; iHt<5; iHt++) { if(allData[52][iHt]>meanOrC-800 && allData[52][iHt]<meanOrC+800) { chvalue[52]=allData[52][iHt]; break; } } event++; if(chvalue[50]>0) fT0OutTree->Fill(); } //event start->Delete(); } reader->Delete(); TFile *hist = new TFile("T0RAWtree.root","RECREATE"); hist->cd(); fT0OutTree ->Write(); }
void runTask(Float_t etamax=0.5,const char * incollection = 0, const char * outfile = "dndeta.root", Bool_t skipNorm = kFALSE) { // for running with root only gSystem->Load("libTree"); gSystem->Load("libGeom"); gSystem->Load("libVMC"); gSystem->Load("libSTEERBase"); gSystem->Load("libESD"); gSystem->Load("libAOD"); // load analysis framework gSystem->Load("libANALYSIS"); gSystem->Load("libANALYSISalice"); TChain * chain = new TChain ("TE"); if (incollection == 0) { chain->Add("galice.root"); } else if (TString(incollection).Contains("xml")){ TGrid::Connect("alien://"); TAlienCollection * coll = TAlienCollection::Open (incollection); while(coll->Next()){ chain->Add(TString("alien://")+coll->GetLFN()); } } else { ifstream file_collect(incollection); TString line; while (line.ReadLine(file_collect) ) { chain->Add(line.Data()); } } chain->GetListOfFiles()->Print(); // for includes use either global setting in $HOME/.rootrc // ACLiC.IncludePaths: -I$(ALICE_ROOT)/include // or in each macro gSystem->AddIncludePath("-I$ALICE_ROOT/include"); // Create the analysis manager AliAnalysisManager *mgr = new AliAnalysisManager("dNdeta"); AliVEventHandler* esdH = new AliESDInputHandler; ((AliESDInputHandler*)esdH)->SetReadFriends(kFALSE); mgr->SetInputEventHandler(esdH); // Create tasks gROOT->LoadMacro("AliAnalysisTaskdNdetaMC.cxx++g"); AliAnalysisTask *task1 = new AliAnalysisTaskdNdetaMC("TaskdNdeta"); ((AliAnalysisTaskdNdetaMC*)task1)->SetEtaMax(etamax); if (skipNorm) ((AliAnalysisTaskdNdetaMC*)task1)->SkipNormalization(); // Enable MC event handler AliMCEventHandler* handler = new AliMCEventHandler; handler->SetReadTR(kFALSE); mgr->SetMCtruthEventHandler(handler); // Add tasks mgr->AddTask(task1); // Create containers for input/output AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer(); AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("coutput", TList::Class(), AliAnalysisManager::kOutputContainer, outfile); // Connect input/output mgr->ConnectInput(task1, 0, cinput); mgr->ConnectOutput(task1, 1, coutput1); // Enable debug printouts mgr->SetDebugLevel(0); if (!mgr->InitAnalysis()) return; mgr->PrintStatus(); mgr->StartAnalysis("local", chain); }