CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTPGAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Class: EcalTPGAnalyzer
4 //
5 //
6 // Original Author: Pascal Paganini
7 //
8 //
9 
10 
11 // system include files
12 #include <memory>
13 #include <utility>
14 
15 // user include files
19 
23 
26 
32 
42 
43 #include "EcalTPGAnalyzer.h"
44 
45 #include <TMath.h>
46 #include <sstream>
47 
48 using namespace edm;
50 
52 {
53  tpCollection_ = iConfig.getParameter<edm::InputTag>("TPCollection") ;
54  tpEmulatorCollection_ = iConfig.getParameter<edm::InputTag>("TPEmulatorCollection") ;
55  digiCollectionEB_ = iConfig.getParameter<edm::InputTag>("DigiCollectionEB") ;
56  digiCollectionEE_ = iConfig.getParameter<edm::InputTag>("DigiCollectionEE") ;
57  gtRecordCollectionTag_ = iConfig.getParameter<std::string>("GTRecordCollection") ;
58 
59  allowTP_ = iConfig.getParameter<bool>("ReadTriggerPrimitives");
60  useEE_ = iConfig.getParameter<bool>("UseEndCap");
61  print_ = iConfig.getParameter<bool>("Print");
62 
63  // file
64  file_ = new TFile("ECALTPGtree.root","RECREATE");
65  file_->cd() ;
66 
67  // tree
68  tree_ = new TTree( "EcalTPGAnalysis","EcalTPGAnalysis" );
69 
70  tree_->Branch("runNb",&treeVariables_.runNb,"runNb/i"); //
71  tree_->Branch("evtNb",&treeVariables_.evtNb,"evtNb/i"); //
72  tree_->Branch("bxNb",&treeVariables_.bxNb,"bxNb/i"); //
73  tree_->Branch("orbitNb",&treeVariables_.orbitNb,"orbitNb/i"); //
74  tree_->Branch("nbOfActiveTriggers",&treeVariables_.nbOfActiveTriggers,"nbOfActiveTriggers/i"); //
75  tree_->Branch("activeTriggers",treeVariables_.activeTriggers,"activeTriggers[nbOfActiveTriggers]/I"); //
76 
77  tree_->Branch("nbOfTowers",&treeVariables_.nbOfTowers,"nbOfTowers/i"); //
78  tree_->Branch("ieta", treeVariables_.ieta,"ieta[nbOfTowers]/I");//
79  tree_->Branch("iphi", treeVariables_.iphi,"iphi[nbOfTowers]/I");//
80  tree_->Branch("nbOfXtals", treeVariables_.nbOfXtals,"nbOfXtals[nbOfTowers]/I");//
81  tree_->Branch("rawTPData", treeVariables_.rawTPData,"rawTPData[nbOfTowers]/I");//
82  tree_->Branch("rawTPEmul1", treeVariables_.rawTPEmul1,"rawTPEmul1[nbOfTowers]/I");//
83  tree_->Branch("rawTPEmul2", treeVariables_.rawTPEmul2,"rawTPEmul2[nbOfTowers]/I");//
84  tree_->Branch("rawTPEmul3", treeVariables_.rawTPEmul3,"rawTPEmul3[nbOfTowers]/I");//
85  tree_->Branch("rawTPEmul4", treeVariables_.rawTPEmul4,"rawTPEmul4[nbOfTowers]/I");//
86  tree_->Branch("rawTPEmul5", treeVariables_.rawTPEmul5,"rawTPEmul5[nbOfTowers]/I");//
87  tree_->Branch("eRec", treeVariables_.eRec,"eRec[nbOfTowers]/F");//
88 }
89 
90 
92 {
93  file_->cd();
94  tree_->Write();
95  file_->Close();
96 }
97 
98 void EcalTPGAnalyzer::beginRun(edm::Run const &, edm::EventSetup const & evtSetup)
99 {
100  // geometry
101  ESHandle<CaloGeometry> theGeometry;
102  ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle, theBarrelGeometry_handle;
103 
104  evtSetup.get<CaloGeometryRecord>().get( theGeometry );
105  evtSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap",theEndcapGeometry_handle);
106  evtSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
107 
108  evtSetup.get<IdealGeometryRecord>().get(eTTmap_);
109  theEndcapGeometry_ = &(*theEndcapGeometry_handle);
110  theBarrelGeometry_ = &(*theBarrelGeometry_handle);
111 }
112 
113 
115 {
116 
117 
118  using namespace edm;
119  using namespace std;
120 
121  if (print_) std::cout<<"==========="<<iEvent.id()<<std::endl ;
122 
123 
124  map<EcalTrigTowerDetId, towerEner> mapTower ;
125  map<EcalTrigTowerDetId, towerEner>::iterator itTT ;
126 
127 
128 
130  // get Evts info
132 
133  treeVariables_.runNb = iEvent.id().run() ;
134  treeVariables_.evtNb = iEvent.id().event() ;
135  treeVariables_.bxNb = iEvent.bunchCrossing() ;
136  treeVariables_.orbitNb = iEvent.orbitNumber() ;
137 
138 
140  // get L1 info
142 
144  iEvent.getByLabel( edm::InputTag(gtRecordCollectionTag_), gtRecord);
145  DecisionWord dWord = gtRecord->decisionWord(); // this will get the decision word *before* masking disabled bits
146 
148  iSetup.get< L1GtTriggerMaskAlgoTrigRcd >().get( l1GtTmAlgo );
149  std::vector<unsigned int> triggerMaskAlgoTrig = l1GtTmAlgo.product()->gtTriggerMask();
150 
151  // apply masks on algo
152  int iDaq = 0;
153  int iBit = -1;
154  treeVariables_.nbOfActiveTriggers = 0 ;
155  for (std::vector<bool>::iterator itBit = dWord.begin(); itBit != dWord.end(); ++itBit) {
156  iBit++;
157  int maskBit = triggerMaskAlgoTrig[iBit] & (1 << iDaq);
158  if (maskBit) *itBit = false;
159  if (*itBit) {
160  treeVariables_.activeTriggers[treeVariables_.nbOfActiveTriggers] = iBit ;
161  treeVariables_.nbOfActiveTriggers++ ;
162  }
163  }
164 
165 
166 
167 
168 
170  // Get TP data
172 
174  iEvent.getByLabel(tpCollection_,tp);
175  if (print_) std::cout<<"TP collection size="<<tp.product()->size()<<std::endl ;
176 
177  for (unsigned int i=0;i<tp.product()->size();i++) {
178  EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
179  const EcalTrigTowerDetId TPtowid= d.id();
180  towerEner tE ;
181  tE.iphi_ = TPtowid.iphi() ;
182  tE.ieta_ = TPtowid.ieta() ;
183  tE.tpgADC_ = d[0].raw() ;
184  mapTower[TPtowid] = tE ;
185  }
186 
187 
188 
190  // Get Emulators TP
192 
194  iEvent.getByLabel(tpEmulatorCollection_, tpEmul);
195  if (print_) std::cout<<"TPEmulator collection size="<<tpEmul.product()->size()<<std::endl ;
196 
197  for (unsigned int i=0;i<tpEmul.product()->size();i++) {
198  EcalTriggerPrimitiveDigi d = (*(tpEmul.product()))[i];
199  const EcalTrigTowerDetId TPtowid= d.id();
200  itTT = mapTower.find(TPtowid) ;
201  if (itTT != mapTower.end())
202  for (int j=0 ; j<5 ; j++) (itTT->second).tpgEmul_[j] = d[j].raw() ;
203  }
204 
205 
206 
208  // Get nb of crystals read out
210 
211  // Get EB xtal digi inputs
213  iEvent.getByLabel(digiCollectionEB_, digiEB);
214 
215  for (unsigned int i=0;i<digiEB.product()->size();i++) {
216  const EBDataFrame & df = (*(digiEB.product()))[i];
217  const EBDetId & id = df.id();
218  const EcalTrigTowerDetId towid = id.tower();
219  itTT = mapTower.find(towid) ;
220  if (itTT != mapTower.end()) (itTT->second).nbXtal_++ ;
221  }
222 
223  if (useEE_) {
224  // Get EE xtal digi inputs
226  iEvent.getByLabel(digiCollectionEE_, digiEE);
227  for (unsigned int i=0;i<digiEE.product()->size();i++) {
228  const EEDataFrame & df = (*(digiEE.product()))[i];
229  const EEDetId & id = df.id();
230  const EcalTrigTowerDetId towid = (*eTTmap_).towerOf(id);
231  itTT = mapTower.find(towid) ;
232  if (itTT != mapTower.end()) (itTT->second).nbXtal_++ ;
233  }
234  }
235 
237  // Get rechits
239 
240  //... to be completed
241 
242 
243 
244 
245 
247  // fill tree
249 
250  treeVariables_.nbOfTowers = mapTower.size() ;
251  int towerNb = 0 ;
252  for (itTT = mapTower.begin() ; itTT != mapTower.end() ; ++itTT) {
253  treeVariables_.ieta[towerNb] = (itTT->second).ieta_ ;
254  treeVariables_.iphi[towerNb] = (itTT->second).iphi_ ;
255  treeVariables_.nbOfXtals[towerNb] = (itTT->second).nbXtal_ ;
256  treeVariables_.rawTPData[towerNb] = (itTT->second).tpgADC_ ;
257  treeVariables_.rawTPEmul1[towerNb] = (itTT->second).tpgEmul_[0] ;
258  treeVariables_.rawTPEmul2[towerNb] = (itTT->second).tpgEmul_[1] ;
259  treeVariables_.rawTPEmul3[towerNb] = (itTT->second).tpgEmul_[2] ;
260  treeVariables_.rawTPEmul4[towerNb] = (itTT->second).tpgEmul_[3] ;
261  treeVariables_.rawTPEmul5[towerNb] = (itTT->second).tpgEmul_[4] ;
262  treeVariables_.eRec[towerNb] = (itTT->second).eRec_ ;
263  towerNb++ ;
264  }
265 
266  tree_->Fill() ;
267 
268 }
269 
270 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
int i
Definition: DBlmapReader.cc:9
key_type id() const
Definition: EBDataFrame.h:31
virtual void beginRun(edm::Run const &, edm::EventSetup const &)
int bunchCrossing() const
Definition: EventBase.h:62
int ieta() const
get the tower ieta
int iEvent
Definition: GenABIO.cc:230
std::ostream & print_(std::ostream &os, value_type const &hash)
Definition: Hash.cc:106
std::vector< bool > DecisionWord
typedefs
int j
Definition: DBlmapReader.cc:9
int orbitNumber() const
Definition: EventBase.h:63
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
key_type id() const
Definition: EEDataFrame.h:28
virtual void analyze(edm::Event const &, edm::EventSetup const &)
int iphi() const
get the tower iphi
const EcalTrigTowerDetId & id() const
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
edm::EventID id() const
Definition: EventBase.h:56
tuple cout
Definition: gather_cfg.py:121
EcalTPGAnalyzer(const edm::ParameterSet &)
Definition: Run.h:41