コード例 #1
0
ファイル: TaskBuzzer.C プロジェクト: alisw/AliRoot
//________________________________________________________________________________
TChain* CreateChain(const char *xmlfile, const char *type)
{
// Create a chain using url's from xml file
   TString treename = type;
   treename.ToLower();
   treename += "Tree";
   printf("***************************************\n");
   printf("    Getting chain of trees %s\n", treename.Data());
   printf("***************************************\n");
   TGridCollection *coll = gGrid->OpenCollection(xmlfile);
   if (!coll) {
      ::Error("CreateChain", "Cannot create an AliEn collection from %s", xmlfile);
      return NULL;
   }
   TChain *chain = new TChain(treename);
   coll->Reset();
   while (coll->Next()) {
      chain->Add(coll->GetTURL(""));
   }
   if (!chain->GetNtrees()) {
      ::Error("CreateChain", "No tree found from collection %s", xmlfile);
      return NULL;
   }
   return chain;
}
コード例 #2
0
ファイル: runNorm.C プロジェクト: ktf/AliPhysics
//______________________________________________________________________________
TChain* CreateChainFromCollection(const char *xmlfile)
{
  // Create a chain from the collection of tags.
  TAlienCollection* coll = TAlienCollection::Open(xmlfile);
  if (!coll) {
    ::Error("CreateChainFromTags", "Cannot create an AliEn collection from %s", xmlfile);
    return NULL;
  }
  
  TGridResult* tagResult = coll->GetGridResult("",kFALSE,kFALSE);
  AliTagAnalysis *tagAna = new AliTagAnalysis("ESD");
  tagAna->ChainGridTags(tagResult);
  
  AliRunTagCuts      *runCuts = new AliRunTagCuts();
  AliLHCTagCuts      *lhcCuts = new AliLHCTagCuts();
  AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
  AliEventTagCuts    *evCuts  = new AliEventTagCuts();
  
  // Check if the cuts configuration file was provided
  if (!gSystem->AccessPathName("ConfigureCuts.C")) {
    gROOT->LoadMacro("ConfigureCuts.C");
    ConfigureCuts(runCuts, lhcCuts, detCuts, evCuts);
  }
  
  TChain *chain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evCuts);
  if (!chain || !chain->GetNtrees()) return NULL;
  chain->ls();
  return chain;
}
コード例 #3
0
ファイル: runNorm.C プロジェクト: ktf/AliPhysics
//______________________________________________________________________________
TChain* CreateChainFromAODFile(const char *rootfile, Bool_t isESD)
{
  // Create a chain using the root file.
  TChain* chain = 0;
  if ( !isESD) chain = new TChain("aodTree");
  else chain = new TChain("esdTree");
  chain->Add(rootfile);
  if (!chain->GetNtrees()) return NULL;
  chain->ls();
  return chain;
}
コード例 #4
0
ファイル: runGloAlgTask.C プロジェクト: shahor02/align
//________________________________________________________________________________
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;
}
コード例 #5
0
ファイル: runNorm.C プロジェクト: ktf/AliPhysics
//______________________________________________________________________________
TChain* CreateChainFromESDList(const char *esdList)
{
  // Create a chain using tags from the run list.
  TChain* chain = new TChain("esdTree");
  ifstream inFile(esdList);
  TString inFileName;
  if (inFile.is_open()) {
    while (! inFile.eof() ) {
      inFileName.ReadLine(inFile,kFALSE);
      if(!inFileName.EndsWith(".root")) continue;
      chain->Add(inFileName.Data());
    }
  }
  inFile.close();
  if (!chain->GetNtrees()) return NULL;
  chain->ls();
  return chain;
}
コード例 #6
0
ファイル: runGloAlgTask.C プロジェクト: shahor02/align
//________________________________________________________________________________
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;
}
コード例 #7
0
	void GetNfiles() { fChain->GetNtrees(); }
コード例 #8
0
//
// Main analyzer
//
void HCALCheckRun(TString rootfile, TString outfile, int maxevents=-1, int option=2) 
{ 

   cout << "[Hcal analyzer] Running option " << option << " for " << endl; 

   // fit pannel display option
   gStyle->SetOptFit(1011);

   //
   // Get the tree from the PFG ntuple 
   //
   TChain *ch = new TChain("hcalTupleTree/tree");

   std::string filename(rootfile);
   std::string::size_type idx;
   idx = filename.rfind('.');
   std::string extension = filename.substr(idx+1);
   std::string line;
   
   if(idx != std::string::npos && extension=="txt")
     {
       std::cout << rootfile << " " << extension << std::endl;
       std::ifstream in(rootfile);
       while (std::getline(in, line)) {     // Process line
	 if (line.size()>0) ch->Add(line.c_str());
       }
     }
   else
     {
       // No extension found
       ch->Add(rootfile);
     }

   printf("%d;\n",ch->GetNtrees());
   printf("%lld;\n",ch->GetEntries());

   TTreeReader     fReader(ch);  //!the tree reader

   //
   // Set up TTreeReader's
   // -- use MakeSelector of root
   //
   // Readers to access the data (delete the ones you do not need).

   // if (isMC){
   // TTreeReaderArray<double> GenParEta = {fReader, "GenParEta"};
   // TTreeReaderArray<double> GenParM = {fReader, "GenParM"};
   // TTreeReaderArray<double> GenParPhi = {fReader, "GenParPhi"};
   // TTreeReaderArray<double> GenParPt = {fReader, "GenParPt"};
   // }   
   TTreeReaderArray<vector<double>> QIE11DigiFC = {fReader, "QIE11DigiFC"};
   TTreeReaderArray<float> HBHEDigiEta = {fReader, "HBHEDigiEta"};
   TTreeReaderArray<float> HBHEDigiPhi = {fReader, "HBHEDigiPhi"};
   TTreeReaderArray<float> HBHEDigiRecEnergy = {fReader, "HBHEDigiRecEnergy"};
   TTreeReaderArray<float> HBHEDigiRecTime = {fReader, "HBHEDigiRecTime"};
   TTreeReaderArray<float> HBHERecHitEnergy = {fReader, "HBHERecHitEnergy"};
   TTreeReaderArray<float> HBHERecHitEta = {fReader, "HBHERecHitEta"};
   TTreeReaderArray<float> HBHERecHitPhi = {fReader, "HBHERecHitPhi"};
   TTreeReaderArray<float> HBHERecHitTime = {fReader, "HBHERecHitTime"};
   TTreeReaderArray<float> HFDigiEta = {fReader, "HFDigiEta"};
   TTreeReaderArray<float> HFDigiPhi = {fReader, "HFDigiPhi"};
   TTreeReaderArray<float> HFDigiRecEnergy = {fReader, "HFDigiRecEnergy"};
   TTreeReaderArray<float> HFDigiRecTime = {fReader, "HFDigiRecTime"};
   TTreeReaderArray<float> HODigiEta = {fReader, "HODigiEta"};
   TTreeReaderArray<float> HODigiPhi = {fReader, "HODigiPhi"};
   TTreeReaderArray<float> HODigiRecEnergy = {fReader, "HODigiRecEnergy"};
   TTreeReaderArray<float> HODigiRecTime = {fReader, "HODigiRecTime"};

   // TTreeReaderArray<float> HcalSimHitsEnergy = {fReader, "HcalSimHitsEnergy"};
   // TTreeReaderArray<float> HcalSimHitsEta = {fReader, "HcalSimHitsEta"};
   // TTreeReaderArray<float> HcalSimHitsPhi = {fReader, "HcalSimHitsPhi"};
   // TTreeReaderArray<float> HcalSimHitsPosx = {fReader, "HcalSimHitsPosx"};
   // TTreeReaderArray<float> HcalSimHitsPosy = {fReader, "HcalSimHitsPosy"};
   // TTreeReaderArray<float> HcalSimHitsPosz = {fReader, "HcalSimHitsPosz"};
   // TTreeReaderArray<float> HcalSimHitsTime = {fReader, "HcalSimHitsTime"};
   // TTreeReaderArray<float> HcalSimHitsTimeTOF = {fReader, "HcalSimHitsTimeTOF"};
   // if (isMC){
   //    TTreeReaderArray<float> HcalSimHitsEnergy = {fReader, "HcalSimHitsEnergy"};
   //    TTreeReaderArray<float> HcalSimHitsEta = {fReader, "HcalSimHitsEta"};
   //    TTreeReaderArray<float> HcalSimHitsPhi = {fReader, "HcalSimHitsPhi"};
   //    TTreeReaderArray<float> HcalSimHitsPosx = {fReader, "HcalSimHitsPosx"};
   //    TTreeReaderArray<float> HcalSimHitsPosy = {fReader, "HcalSimHitsPosy"};
   //    TTreeReaderArray<float> HcalSimHitsPosz = {fReader, "HcalSimHitsPosz"};
   //    TTreeReaderArray<float> HcalSimHitsTime = {fReader, "HcalSimHitsTime"};
   //    TTreeReaderArray<float> HcalSimHitsTimeTOF = {fReader, "HcalSimHitsTimeTOF"};
   // }
   TTreeReaderArray<vector<float>> HBHEDigiAllFC = {fReader, "HBHEDigiAllFC"};
   TTreeReaderArray<vector<float>> HBHEDigiEnergy = {fReader, "HBHEDigiEnergy"};
   TTreeReaderArray<vector<float>> HBHEDigiFC = {fReader, "HBHEDigiFC"};
   TTreeReaderArray<vector<float>> HBHEDigiGain = {fReader, "HBHEDigiGain"};
   TTreeReaderArray<vector<float>> HBHEDigiNomFC = {fReader, "HBHEDigiNomFC"};
   TTreeReaderArray<vector<float>> HBHEDigiPedFC = {fReader, "HBHEDigiPedFC"};
   TTreeReaderArray<vector<float>> HBHEDigiRCGain = {fReader, "HBHEDigiRCGain"};
   TTreeReaderArray<vector<float>> HFDigiAllFC = {fReader, "HFDigiAllFC"};
   TTreeReaderArray<vector<float>> HFDigiEnergy = {fReader, "HFDigiEnergy"};
   TTreeReaderArray<vector<float>> HFDigiFC = {fReader, "HFDigiFC"};
   TTreeReaderArray<vector<float>> HFDigiGain = {fReader, "HFDigiGain"};
   TTreeReaderArray<vector<float>> HFDigiNomFC = {fReader, "HFDigiNomFC"};
   TTreeReaderArray<vector<float>> HFDigiPedFC = {fReader, "HFDigiPedFC"};
   TTreeReaderArray<vector<float>> HFDigiRCGain = {fReader, "HFDigiRCGain"};
   TTreeReaderArray<vector<float>> HODigiAllFC = {fReader, "HODigiAllFC"};
   TTreeReaderArray<vector<float>> HODigiEnergy = {fReader, "HODigiEnergy"};
   TTreeReaderArray<vector<float>> HODigiFC = {fReader, "HODigiFC"};
   TTreeReaderArray<vector<float>> HODigiGain = {fReader, "HODigiGain"};
   TTreeReaderArray<vector<float>> HODigiNomFC = {fReader, "HODigiNomFC"};
   TTreeReaderArray<vector<float>> HODigiPedFC = {fReader, "HODigiPedFC"};
   TTreeReaderArray<vector<float>> HODigiRCGain = {fReader, "HODigiRCGain"};
   TTreeReaderValue<Int_t> laserType = {fReader, "laserType"};
   if (isMC){
     TTreeReaderArray<int> GenParPdgId = {fReader, "GenParPdgId"};
     TTreeReaderArray<int> GenParStatus = {fReader, "GenParStatus"};
   }
   TTreeReaderArray<int> HBHEDigiDepth = {fReader, "HBHEDigiDepth"};
   TTreeReaderArray<int> HBHEDigiElectronicsID = {fReader, "HBHEDigiElectronicsID"};
   TTreeReaderArray<int> HBHEDigiFiberIdleOffset = {fReader, "HBHEDigiFiberIdleOffset"};
   TTreeReaderArray<int> HBHEDigiIEta = {fReader, "HBHEDigiIEta"};
   TTreeReaderArray<int> HBHEDigiIPhi = {fReader, "HBHEDigiIPhi"};
   TTreeReaderArray<int> HBHEDigiPresamples = {fReader, "HBHEDigiPresamples"};
   TTreeReaderArray<int> HBHEDigiRawID = {fReader, "HBHEDigiRawID"};
   TTreeReaderArray<int> HBHEDigiSOI = {fReader, "HBHEDigiSOI"};
   TTreeReaderArray<int> HBHEDigiSize = {fReader, "HBHEDigiSize"};
   TTreeReaderArray<int> HBHEDigiSubdet = {fReader, "HBHEDigiSubdet"};
   TTreeReaderArray<int> HBHERecHitAux = {fReader, "HBHERecHitAux"};
   TTreeReaderArray<int> HBHERecHitDepth = {fReader, "HBHERecHitDepth"};
   TTreeReaderArray<int> HBHERecHitFlags = {fReader, "HBHERecHitFlags"};
   TTreeReaderArray<int> HBHERecHitHPDid = {fReader, "HBHERecHitHPDid"};
   TTreeReaderArray<int> HBHERecHitIEta = {fReader, "HBHERecHitIEta"};
   TTreeReaderArray<int> HBHERecHitIPhi = {fReader, "HBHERecHitIPhi"};
   TTreeReaderArray<int> HBHERecHitRBXid = {fReader, "HBHERecHitRBXid"};
   TTreeReaderArray<int> HFDigiDepth = {fReader, "HFDigiDepth"};
   TTreeReaderArray<int> HFDigiElectronicsID = {fReader, "HFDigiElectronicsID"};
   TTreeReaderArray<int> HFDigiFiberIdleOffset = {fReader, "HFDigiFiberIdleOffset"};
   TTreeReaderArray<int> HFDigiIEta = {fReader, "HFDigiIEta"};
   TTreeReaderArray<int> HFDigiIPhi = {fReader, "HFDigiIPhi"};
   TTreeReaderArray<int> HFDigiPresamples = {fReader, "HFDigiPresamples"};
   TTreeReaderArray<int> HFDigiRawID = {fReader, "HFDigiRawID"};
   TTreeReaderArray<int> HFDigiSOI = {fReader, "HFDigiSOI"};
   TTreeReaderArray<int> HFDigiSize = {fReader, "HFDigiSize"};
   TTreeReaderArray<int> HFDigiSubdet = {fReader, "HFDigiSubdet"};
   TTreeReaderArray<int> HODigiDepth = {fReader, "HODigiDepth"};
   TTreeReaderArray<int> HODigiElectronicsID = {fReader, "HODigiElectronicsID"};
   TTreeReaderArray<int> HODigiFiberIdleOffset = {fReader, "HODigiFiberIdleOffset"};
   TTreeReaderArray<int> HODigiIEta = {fReader, "HODigiIEta"};
   TTreeReaderArray<int> HODigiIPhi = {fReader, "HODigiIPhi"};
   TTreeReaderArray<int> HODigiPresamples = {fReader, "HODigiPresamples"};
   TTreeReaderArray<int> HODigiRawID = {fReader, "HODigiRawID"};
   TTreeReaderArray<int> HODigiSOI = {fReader, "HODigiSOI"};
   TTreeReaderArray<int> HODigiSize = {fReader, "HODigiSize"};
   TTreeReaderArray<int> HODigiSubdet = {fReader, "HODigiSubdet"};

   // if (isMC){
   //   TTreeReaderArray<int> HcalSimHitsDepth = {fReader, "HcalSimHitsDepth"};
   //   TTreeReaderArray<int> HcalSimHitsIeta = {fReader, "HcalSimHitsIeta"};
   //   TTreeReaderArray<int> HcalSimHitsIndex = {fReader, "HcalSimHitsIndex"};
   //   TTreeReaderArray<int> HcalSimHitsIphi = {fReader, "HcalSimHitsIphi"};
   //   TTreeReaderArray<int> HcalSimHitsSubdet = {fReader, "HcalSimHitsSubdet"};
   // }
   TTreeReaderArray<int> QIE11DigiCapIDError = {fReader, "QIE11DigiCapIDError"};
   TTreeReaderArray<int> QIE11DigiDepth = {fReader, "QIE11DigiDepth"};
   TTreeReaderArray<int> QIE11DigiFlags = {fReader, "QIE11DigiFlags"};
   TTreeReaderArray<int> QIE11DigiIEta = {fReader, "QIE11DigiIEta"};
   TTreeReaderArray<int> QIE11DigiIPhi = {fReader, "QIE11DigiIPhi"};
   TTreeReaderArray<int> QIE11DigiLinkError = {fReader, "QIE11DigiLinkError"};
   TTreeReaderArray<int> QIE11DigiRawID = {fReader, "QIE11DigiRawID"};
   TTreeReaderArray<int> QIE11DigiSOI = {fReader, "QIE11DigiSOI"};
   TTreeReaderArray<int> QIE11DigiSubdet = {fReader, "QIE11DigiSubdet"};
   TTreeReaderArray<vector<int>> HBHEDigiADC = {fReader, "HBHEDigiADC"};
   TTreeReaderArray<vector<int>> HBHEDigiCapID = {fReader, "HBHEDigiCapID"};
   TTreeReaderArray<vector<int>> HBHEDigiDV = {fReader, "HBHEDigiDV"};
   TTreeReaderArray<vector<int>> HBHEDigiER = {fReader, "HBHEDigiER"};
   TTreeReaderArray<vector<int>> HBHEDigiFiber = {fReader, "HBHEDigiFiber"};
   TTreeReaderArray<vector<int>> HBHEDigiFiberChan = {fReader, "HBHEDigiFiberChan"};
   TTreeReaderArray<vector<int>> HBHEDigiLADC = {fReader, "HBHEDigiLADC"};
   TTreeReaderArray<vector<int>> HBHEDigiRaw = {fReader, "HBHEDigiRaw"};
   TTreeReaderArray<vector<int>> HFDigiADC = {fReader, "HFDigiADC"};
   TTreeReaderArray<vector<int>> HFDigiCapID = {fReader, "HFDigiCapID"};
   TTreeReaderArray<vector<int>> HFDigiDV = {fReader, "HFDigiDV"};
   TTreeReaderArray<vector<int>> HFDigiER = {fReader, "HFDigiER"};
   TTreeReaderArray<vector<int>> HFDigiFiber = {fReader, "HFDigiFiber"};
   TTreeReaderArray<vector<int>> HFDigiFiberChan = {fReader, "HFDigiFiberChan"};
   TTreeReaderArray<vector<int>> HFDigiLADC = {fReader, "HFDigiLADC"};
   TTreeReaderArray<vector<int>> HFDigiRaw = {fReader, "HFDigiRaw"};
   TTreeReaderArray<vector<int>> HODigiADC = {fReader, "HODigiADC"};
   TTreeReaderArray<vector<int>> HODigiCapID = {fReader, "HODigiCapID"};
   TTreeReaderArray<vector<int>> HODigiDV = {fReader, "HODigiDV"};
   TTreeReaderArray<vector<int>> HODigiER = {fReader, "HODigiER"};
   TTreeReaderArray<vector<int>> HODigiFiber = {fReader, "HODigiFiber"};
   TTreeReaderArray<vector<int>> HODigiFiberChan = {fReader, "HODigiFiberChan"};
   TTreeReaderArray<vector<int>> HODigiLADC = {fReader, "HODigiLADC"};
   TTreeReaderArray<vector<int>> HODigiRaw = {fReader, "HODigiRaw"};
   TTreeReaderArray<vector<int>> QIE11DigiADC = {fReader, "QIE11DigiADC"};
   TTreeReaderArray<vector<int>> QIE11DigiCapID = {fReader, "QIE11DigiCapID"};
   TTreeReaderArray<vector<int>> QIE11DigiTDC = {fReader, "QIE11DigiTDC"};
   TTreeReaderValue<UInt_t> bx = {fReader, "bx"};
   TTreeReaderValue<UInt_t> event = {fReader, "event"};
   TTreeReaderValue<UInt_t> ls = {fReader, "ls"};
   TTreeReaderValue<UInt_t> orbit = {fReader, "orbit"};
   TTreeReaderValue<UInt_t> run = {fReader, "run"};

   //
   // Define histograms to fill
   //
   TList *v_hist = new TList();
   
   TH1F *h_RecHitEtGenPt = new TH1F("h_RecHitEtGenPt","h_RecHitEtGenPt",100,0.,2.);
   v_hist->Add(h_RecHitEtGenPt);
   v_hist->FindObject("h_RecHitEtGenPt")->Print();

   bookHistograms(v_hist); // most of histograms booked here
   
   //
   // Loop over entries
   //
   unsigned int nentries = (Int_t)ch->GetEntries();
   cout << "[Hcal analyzer] The number of entries is: " << nentries << endl;

   //---------------------------------------------------------------------------------------------------------
   // main event loop
   //---------------------------------------------------------------------------------------------------------

   int ievent=0;
   while (fReader.Next()) {
     
     // Progress indicator 
     ievent++;
     if(ievent%1000==0) cout << "[HCAL analyzer] Processed " << ievent << " out of " << nentries << " events" << endl; 
     if (maxevents>0 && ievent>maxevents) break;

     if (*run>=315361){ // very loosely defining 2018 data period
       if ( (*run>=315361) && (*run<=315366) && (*bx!=823) && (*bx!=2608) ) continue; // fill 6621, if not bx=823 or 2608, skip events
       if ( (*run>=315420) && (*run<=315420) && (*bx!=823) && (*bx!=2608) ) continue; // fill 6624
     }
     
     //std::cout << *event << std::endl;
	
     //--------------------
     // Loop over pions
     //------------------
     // if (isMC){
     // for (int iGenPar = 0, nGenPar =  GenParPt.GetSize(); iGenPar < nGenPar; ++iGenPar) {
     //   //std::cout << GenParPdgId[iGenPar] << std::endl;
     //   TLorentzVector TLVPion; TLVPion.SetPtEtaPhiM(GenParPt[iGenPar],GenParEta[iGenPar],GenParPhi[iGenPar],GenParM[iGenPar]);
     //   //TLVPion.Print();
     //   //if (fabs(TLVPion.Eta())<1.8 || fabs(TLVPion.Eta())>2.4) continue;
       
     //   // Loop over HBHERecHits
     //   double SumEt=0.;
     //   for (int irc = 0, nrc =  HBHERecHitEnergy.GetSize(); irc < nrc; ++irc) {
     // 	 TLorentzVector TLVRecHit; 
     // 	 double RecHitPt=HBHERecHitEnergy[irc]/cosh(HBHERecHitEta[irc]); //p=E for rechits
     // 	 TLVRecHit.SetPtEtaPhiE(RecHitPt,HBHERecHitEta[irc],HBHERecHitPhi[irc],HBHERecHitEnergy[irc]);	  
     // 	 double dR=TLVRecHit.DeltaR(TLVPion);
     // 	 if (dR<0.3) SumEt+=TLVRecHit.Pt();	  
     //   }
     //   //std::cout << SumEt/TLVPion.Pt() <<std::endl;
     //   h_RecHitEtGenPt->Fill( SumEt/TLVPion.Pt());
     // }// Loop over pions ends	
     // }

     //--------------------
     // Loop over digis 
     //--------------------
     for (int idigi = 0, ndigi =  HBHEDigiFC.GetSize(); idigi < ndigi; ++idigi) {
       int SOI=HBHEDigiSOI[idigi];

       //
       // Define SOI charge fraction
       //
       double v_ampl=0.;
       double fbinSOI = HBHEDigiFC[idigi][SOI];
       for (int iTS = SOI, nTS = HBHEDigiFC[idigi].size(); iTS < nTS; iTS++) v_ampl += HBHEDigiFC[idigi][iTS];
       double fbinPS = v_ampl - fbinSOI;
       if (v_ampl>0.){
	 fbinSOI /= v_ampl;
	 fbinPS /= v_ampl;
       }

       std::string strtmp;
       std::string subdet_="HB";
       
       // 
       if (v_ampl>30.){ // Amplitude selection

	 strtmp = "HcalDigiTask_SOI_frac_" + subdet_;
	 fill1D(v_hist, strtmp, fbinSOI);
	 strtmp = "HcalDigiTask_postSOI_frac_" + subdet_;
	 fill1D(v_hist, strtmp, fbinPS);
	 
       } // v_ampl threshold

     }

     //--------------------
     // Loop over digis 
     //--------------------
     for (int idigi = 0, ndigi =  QIE11DigiFC.GetSize(); idigi < ndigi; ++idigi) {
       int SOI=QIE11DigiSOI[idigi];

       int ieta=QIE11DigiIEta[idigi];
       int iphi=QIE11DigiIPhi[idigi];
       int depth=QIE11DigiDepth[idigi];
       
       //
       // Define SOI charge fraction
       //
       double v_ampl=0.;
       double fbinSOI = QIE11DigiFC[idigi][SOI];
       for (int iTS = SOI, nTS = QIE11DigiFC[idigi].size(); iTS < nTS; iTS++) v_ampl += QIE11DigiFC[idigi][iTS];
       double fbinPS = v_ampl - fbinSOI;
       if (v_ampl>0.){
	 fbinSOI /= v_ampl;
	 fbinPS /= v_ampl;
       }

       bool goodtest = true; // define this much ealier so that we can use it at different locations
       double chargeSOI = QIE11DigiFC[idigi][SOI];
       for (int iTS = SOI, nTS = QIE11DigiFC[idigi].size(); iTS < nTS; iTS++){
	 if (QIE11DigiFC[idigi][iTS]>chargeSOI) goodtest = false;
       }

       std::string strtmp;
       std::string subdet_="HE";
       
       // 
       if (v_ampl>300.){ // Amplitude selection

	 strtmp = "HcalDigiTask_SOI_frac_" + subdet_;
	 fill1D(v_hist, strtmp, fbinSOI);
	 strtmp = "HcalDigiTask_postSOI_frac_" + subdet_;
	 fill1D(v_hist, strtmp, fbinPS);
	 // 
	 //KH starts
	 if (v_ampl > 1000.) {
	   strtmp = "HcalDigiTask_SOI_frac_1000_" + subdet_;
	   fill1D(v_hist, strtmp, fbinSOI);
	   strtmp = "HcalDigiTask_postSOI_frac_1000_" + subdet_;
	   fill1D(v_hist, strtmp, fbinPS);
	 }
	 // 
	 if (v_ampl > 2000.) {
	   strtmp = "HcalDigiTask_SOI_frac_2000_" + subdet_;
	   fill1D(v_hist, strtmp, fbinSOI);
	   strtmp = "HcalDigiTask_postSOI_frac_2000_" + subdet_;
	   fill1D(v_hist, strtmp, fbinPS);
	 }
	 // 
	 if (v_ampl > 6000.) {
	   strtmp = "HcalDigiTask_SOI_frac_6000_" + subdet_;
	   fill1D(v_hist, strtmp, fbinSOI);
	   strtmp = "HcalDigiTask_postSOI_frac_6000_" + subdet_;
	   fill1D(v_hist, strtmp, fbinPS);
	 }

	 // Another test
	 // goodtest=true; if (fbinSOI<0.1) goodtest=false;
	 if (goodtest) fill1D(v_hist,"HcalDigiTask_Charge_Prompt_HE", v_ampl);  // total charge for SOI-lastTS
	 else          fill1D(v_hist,"HcalDigiTask_Charge_Delayed_HE", v_ampl); // total charge for SOI-lastTS

	 if (goodtest) fill1D(v_hist,"HcalDigiTask_SOI_frac_pass_HE", fbinSOI);
	 else          fill1D(v_hist,"HcalDigiTask_SOI_frac_fail_HE", fbinSOI);
	 
	 double aveSimTime=0.;
	 double sumSimHitE=0.;
	 
	 // if (isMC){
	 // for (int isim = 0, nsim =  HcalSimHitsEnergy.GetSize(); isim < nsim; ++isim) {
	   
	 //   int ieta_sim=HcalSimHitsIeta[isim];
	 //   int iphi_sim=HcalSimHitsIphi[isim];
	 //   int depth_sim=HcalSimHitsDepth[isim];
	 //   double ttime=HcalSimHitsTime[isim];
	 //   double ten=HcalSimHitsEnergy[isim];
	     
	 //   if (ieta==ieta_sim && iphi==iphi_sim && depth==depth_sim){
	 //     if (ttime<135.){  // simhits beyond 135 ns won't contribute to digis
	 //       aveSimTime += ten*ttime; // KH
	 //       sumSimHitE += ten; // KH	     
	 //     }	            
	 //   }

	 // }  // loop over simhits
	 // }  // isMC

	 // aveSimTime /= sumSimHitE; //KH
	 if (goodtest) fill1D(v_hist,"Simhit_AveTime_PromptHits_HE", aveSimTime);
	 else          fill1D(v_hist,"Simhit_AveTime_DelayedHits_HE", aveSimTime);
	 
       } // v_ampl threshold
       
     } // Loop over HE digis    
     
   }   // Event loop ends
   //---------------------------------------------------------------------------------------------------------
   // main event loop ends
   //---------------------------------------------------------------------------------------------------------

   // output file for histograms
   TFile file_out(outfile,"RECREATE");
   
   h_RecHitEtGenPt->Fit("gaus");
   //h_RecHitEtGenPt->Write();
   v_hist->Write();
   
   file_out.ls();
   file_out.Close();

}